@docx-editor.dev/core 2.2.0 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/automation.cjs +1 -1
- package/dist/automation.js +1 -1
- package/dist/binding.cjs +1 -1
- package/dist/binding.js +1 -1
- package/dist/{chunk-LVZSKP2F.js → chunk-2QPRJAHK.js} +1 -1
- package/dist/{chunk-EUTHPVTG.cjs → chunk-3JENXX7Q.cjs} +1 -1
- package/dist/{chunk-FJCBZ5BL.cjs → chunk-5WEA7SIG.cjs} +4 -4
- package/dist/{chunk-T2LVH6D3.cjs → chunk-73X5I53C.cjs} +1 -1
- package/dist/{chunk-NCGKMEKU.js → chunk-7D2CP2J7.js} +1 -1
- package/dist/{chunk-CY47CFM5.cjs → chunk-C3YJR64Q.cjs} +5 -5
- package/dist/{chunk-C24AINST.js → chunk-EWRKYYUA.js} +1 -1
- package/dist/{chunk-KZ5HPHW6.cjs → chunk-GLHPDILJ.cjs} +1 -1
- package/dist/{chunk-QVGTZUEV.js → chunk-PD4BVZW5.js} +1 -1
- package/dist/{chunk-MO7GAUO7.js → chunk-PEIEVTWR.js} +1 -1
- package/dist/chunk-QIFQTG57.cjs +10 -0
- package/dist/chunk-RFO2O56I.js +10 -0
- package/dist/{chunk-VXEF32A5.cjs → chunk-SAUKKJWZ.cjs} +7 -7
- package/dist/{chunk-PFTVNFMI.js → chunk-WKZR6YPE.js} +1 -1
- package/dist/editor.cjs +1 -1
- package/dist/editor.d.cts +3 -3
- package/dist/editor.d.ts +3 -3
- package/dist/editor.js +1 -1
- package/dist/{index-gvw4VGE9.d.ts → index-BWiuzoVN.d.ts} +1 -1
- package/dist/{index-CiEakUbq.d.cts → index-Beyo2mTa.d.cts} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/layout.cjs +1 -1
- package/dist/layout.d.cts +2 -2
- package/dist/layout.d.ts +2 -2
- package/dist/layout.js +1 -1
- package/dist/output.cjs +1 -1
- package/dist/output.js +1 -1
- package/dist/{review-reads-CsoXSvUg.d.ts → review-reads-CMAqdMnE.d.ts} +1 -1
- package/dist/{review-reads-qW0jvdF1.d.cts → review-reads-D3r3tnoo.d.cts} +1 -1
- package/dist/store.cjs +1 -1
- package/dist/store.d.cts +1 -1
- package/dist/store.d.ts +1 -1
- package/dist/store.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-5OSFUHGF.js +0 -10
- package/dist/chunk-UAOJHPQ4.cjs +0 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var chunkUAOJHPQ4_cjs=require('./chunk-UAOJHPQ4.cjs');var Nt=Object.freeze(["default","first","even"]),it=Object.freeze({kind:"body"});function _(r){switch(r.kind){case "body":return "body";case "note":return `note:${r.noteKind}:${String(r.noteId)}`;default:return `${r.kind}:${String(r.sectionIndex)}:${r.variant}`}}function Ke(r){if(typeof r!="object"||r===null)return false;let e=r;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&&Nt.includes(e.variant)}var Fo=["getDocument","getBody","getParagraphs","getSpanParagraphs","getText","getSpanText","getParagraphId","search","getFont","getParagraphFormat","getStyle","getSections","getPageSetup","getFurniture","getNotes","getNoteBody","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","getContentControlPlaceholderShown","getContentControlTemporary","getContentControlText","getContentControlParagraphs","getContentControlRange"],Mn=["insertText","replaceSpan","insertParagraph","splitParagraph","deleteParagraph","selectSpan","setFont","setParagraphFormat","setStyle","setPageSetup","deleteNote","setListLevel","insertListParagraph","setHyperlink","setCommentResolved","replyToComment","acceptRevision","rejectRevision","acceptAllRevisions","rejectAllRevisions","setContentControlValue","setContentControlProperties","deleteContentControl","insertContentControlText","insertContentControl","insertCustomNode"],En=["deleteNote","setCommentResolved","replyToComment","insertCustomNode"],_n=new Set(En);function We(r){return _n.has(r.op)}var Fn=new Set(Mn);function $t(r){return Fn.has(r.op)}function Bn(){let r=globalThis.crypto,e=r?.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 s=e.call(r,new Uint8Array(16)),a="";for(let l of s)a+=l.toString(16).padStart(2,"0");return a}function jn(r){return typeof r=="object"&&r!==null&&"kind"in r&&"ref"in r}function ze(){let r=new Map,e=new Map,s=new Map,a=new Map,l=Bn(),u=null,h=(m,k)=>{let f=(a.get(m)??0)+1;a.set(m,f);let g=`${m}:${l}:${String(f)}`;return r.set(g,k),Object.freeze({kind:m,ref:g})},b=(m,k,f)=>{let g=`${m}\0${k}`,R=s.get(g);if(R)return Object.freeze({kind:m,ref:R});let A=h(m,f);return s.set(g,A.ref),A};return {document(){return u??=h("document",{kind:"document"}),u},body(m){return b("body",_(m),{kind:"body",story:m})},paragraph(m,k){let f=e.get(m);if(f)return Object.freeze({kind:"paragraph",ref:f});let g=h("paragraph",{kind:"paragraph",paragraphId:m,story:k});return e.set(m,g.ref),g},section(m){return b("section",String(m),{kind:"section",index:m})},note(m,k){return b("note",`${m}:${String(k)}`,{kind:"note",noteKind:m,noteId:k})},comment(m,k){return b("comment",`${_(k)}\0${m}`,{kind:"comment",commentId:m,story:k})},revision(m,k){return b("revision",`${_(k)}\0${m}`,{kind:"revision",revisionId:m,story:k})},bookmark(m,k){return b("bookmark",`${_(k)}\0${m}`,{kind:"bookmark",name:m,story:k})},list(m,k){return b("list",`${_(k)}\0${m}`,{kind:"list",numId:m,story:k})},contentControl(m,k){return b("contentControl",`${_(k)}\0${m}`,{kind:"contentControl",nodeId:m,story:k})},retarget(m,k){let f=e.get(m);if(!f||m===k)return;let g=r.get(f);!g||g.kind!=="paragraph"||(e.delete(m),r.set(f,{kind:"paragraph",paragraphId:k,story:g.story}),e.has(k)||e.set(k,f));},resolve(m,k){if(!jn(m)||m.kind!==k||typeof m.ref!="string")return null;let f=r.get(m.ref);return !f||f.kind!==k?null:f}}}var Kn=255,Wn=Object.freeze({nameOf:()=>null,idOf:()=>null,defaultId:null,present:false});function De(r){let e=chunkUAOJHPQ4_cjs.Gc(r);if(!e)return Wn;let s=new Map,a=new Map,l=null;for(let u of chunkUAOJHPQ4_cjs.Fc(e).values())if(u.type==="paragraph"){if(s.set(u.styleId,u.name),u.name!==null){let h=u.name.trim().toLowerCase();a.has(h)||a.set(h,u.styleId);}u.isDefault&&l===null&&(l=u.styleId);}return Object.freeze({nameOf:u=>s.get(u)??null,idOf:u=>a.get(u.trim().toLowerCase())??null,defaultId:l,present:true})}function Ht(r,e,s){let a=chunkUAOJHPQ4_cjs.Ea(r,e);if(!a||a.kind!=="paragraph")return null;let l=zn(chunkUAOJHPQ4_cjs.Ld(chunkUAOJHPQ4_cjs.Jd(a),"pStyle"));return l!==null?s.nameOf(l):s.defaultId===null?null:s.nameOf(s.defaultId)}function zn(r){if(!r)return null;for(let e of r.attributes)if(e.localName==="val")return e.value;return null}function Lt(r,e){if(typeof r!="string"||r.trim().length===0)return {ok:false,detail:"style: not a name"};if(r.length>Kn)return {ok:false,detail:"style: name too long"};if(!chunkUAOJHPQ4_cjs.W(r))return {ok:false,detail:"style: not valid XML text"};if(!e.present)return {ok:false,detail:"style: this document defines no styles"};let s=e.idOf(r);return s===null?{ok:false,detail:"style: this document defines no paragraph style with that name"}:{ok:true,styleId:s}}var $e=20,Dn=31680,Vn=1999,$n=Object.freeze({bold:null,italic:null,name:null,size:null,color:null});function U(r,e){if(!r)return null;for(let s of r.attributes)if(s.localName===e)return s.value;return null}function Ut(r){if(!r)return null;let e=U(r,"val");if(e===null)return true;let s=e.trim().toLowerCase();return !(s==="0"||s==="false"||s==="off"||s==="none")}function Un(r){if(r===null)return null;let e=r.trim();return /^[0-9a-fA-F]{6}$/.test(e)?`#${e.toUpperCase()}`:null}function Xn(r){if(r===null)return null;let e=Number(r.trim());return !Number.isFinite(e)||e<=0?null:e/2}function ct(r){if(r===null)return null;let e=Number(r.trim());return Number.isFinite(e)?e/$e:null}function bt(r){if(r.length===0)return null;let e=r[0];if(e===null)return null;for(let s of r)if(s!==e)return null;return e}function Ue(r,e){let s=[];for(let a of e)for(let l of chunkUAOJHPQ4_cjs._f(r,a.paragraphId,a.start,a.end))s.push(chunkUAOJHPQ4_cjs.Kd(l));return s.length===0?$n:{bold:bt(s.map(a=>Ut(chunkUAOJHPQ4_cjs.Ld(a,"b")))),italic:bt(s.map(a=>Ut(chunkUAOJHPQ4_cjs.Ld(a,"i")))),name:bt(s.map(a=>{let l=chunkUAOJHPQ4_cjs.Ld(a,"rFonts"),u=U(l,"ascii");return u===null||u.length===0?null:u})),size:bt(s.map(a=>Xn(U(chunkUAOJHPQ4_cjs.Ld(a,"sz"),"val")))),color:bt(s.map(a=>Un(U(chunkUAOJHPQ4_cjs.Ld(a,"color"),"val"))))}}var Yn=Object.freeze({left:"Left",start:"Left",center:"Centered",right:"Right",end:"Right",both:"Justified",distribute:"Justified"}),Gn=Object.freeze({Left:"left",Centered:"center",Right:"right",Justified:"both"});function Jn(r){let e=U(chunkUAOJHPQ4_cjs.Ld(r,"jc"),"val");return e===null?"Unknown":Yn[e.trim().toLowerCase()]??"Unknown"}function Xe(r,e,s){let a=chunkUAOJHPQ4_cjs.Ea(r,e);if(!a||a.kind!=="paragraph")return null;let l=chunkUAOJHPQ4_cjs.Jd(a),u=chunkUAOJHPQ4_cjs.Ld(l,"spacing"),h=chunkUAOJHPQ4_cjs.Ld(l,"ind");return {alignment:Jn(l),style:Ht(r,e,s),firstLineIndent:Qn(h),leftIndent:ct(U(h,"left")??U(h,"start")),rightIndent:ct(U(h,"right")??U(h,"end")),lineSpacing:ct(U(u,"line")),spaceBefore:ct(U(u,"before")),spaceAfter:ct(U(u,"after")),widowControl:Ut(chunkUAOJHPQ4_cjs.Ld(l,"widowControl"))}}function Qn(r){let e=ct(U(r,"firstLine"));if(e!==null)return e;let s=ct(U(r,"hanging"));return s===null?null:-s}function Mt(r,e){if(typeof r!="number"||!Number.isFinite(r))return {ok:false,detail:`${e}: not a measurement`};let s=Math.round(r*$e);return Math.abs(s)>Dn?{ok:false,detail:`${e}: out of range`}:{ok:true,value:s}}function Ye(r){let e=[];if(r.bold!==void 0){if(typeof r.bold!="boolean")return {ok:false,detail:"bold: not a boolean"};e.push({localName:"b",...r.bold?{}:{attributes:{val:"0"}}});}if(r.italic!==void 0){if(typeof r.italic!="boolean")return {ok:false,detail:"italic: not a boolean"};e.push({localName:"i",...r.italic?{}:{attributes:{val:"0"}}});}if(r.name!==void 0){let s=r.name;if(typeof s!="string"||s.length===0||s.length>128)return {ok:false,detail:"name: not a font name"};if(!chunkUAOJHPQ4_cjs.W(s))return {ok:false,detail:"name: not valid XML text"};e.push({localName:"rFonts",attributes:{ascii:s,hAnsi:s,cs:s}});}if(r.size!==void 0){let s=r.size;if(typeof s!="number"||!Number.isFinite(s)||s<=0)return {ok:false,detail:"size: not a positive number of points"};let a=Math.round(s*2);if(a<1||a>Vn)return {ok:false,detail:"size: out of range"};e.push({localName:"sz",attributes:{val:String(a)}}),e.push({localName:"szCs",attributes:{val:String(a)}});}if(r.color!==void 0){let s=r.color;if(typeof s!="string"||!/^#[0-9a-fA-F]{6}$/.test(s.trim()))return {ok:false,detail:"color: not a #RRGGBB triplet"};e.push({localName:"color",attributes:{val:s.trim().slice(1).toUpperCase()}});}return e.length===0?{ok:false,detail:"no formatting was asked for"}:{ok:true,value:e}}function Ge(r,e,s,a){let l=chunkUAOJHPQ4_cjs.Ea(r,e);if(!l||l.kind!=="paragraph")return {ok:false,detail:"not a paragraph"};let u=chunkUAOJHPQ4_cjs.Jd(l),h=[];if(s.style!==void 0){let A=Lt(s.style,a);if(!A.ok)return {ok:false,detail:A.detail};h.push({localName:"pStyle",attributes:{val:A.styleId}});}if(s.alignment!==void 0){let A=Gn[s.alignment];if(A===void 0)return {ok:false,detail:`alignment: ${String(s.alignment)}`};h.push({localName:"jc",attributes:{val:A}});}let b=chunkUAOJHPQ4_cjs.Ld(u,"ind"),m=Ve(b),k=false;if(s.firstLineIndent!==void 0){let A=Mt(s.firstLineIndent,"firstLineIndent");if(!A.ok)return A;delete m.firstLine,delete m.hanging,A.value<0?m.hanging=String(-A.value):m.firstLine=String(A.value),k=true;}for(let[A,T,O]of [["leftIndent","left","start"],["rightIndent","right","end"]]){let H=s[A];if(H===void 0)continue;let L=Mt(H,A);if(!L.ok)return L;delete m[O],m[T]=String(L.value),k=true;}k&&h.push({localName:"ind",attributes:m});let f=chunkUAOJHPQ4_cjs.Ld(u,"spacing"),g=Ve(f),R=false;for(let[A,T]of [["spaceBefore","before"],["spaceAfter","after"]]){let O=s[A];if(O===void 0)continue;let H=Mt(O,A);if(!H.ok)return H;if(H.value<0)return {ok:false,detail:`${A}: out of range`};g[T]=String(H.value),R=true;}if(s.lineSpacing!==void 0){let A=Mt(s.lineSpacing,"lineSpacing");if(!A.ok)return A;if(A.value<=0)return {ok:false,detail:"lineSpacing: out of range"};g.line=String(A.value),g.lineRule??="auto",R=true;}if(R&&h.push({localName:"spacing",attributes:g}),s.widowControl!==void 0){if(typeof s.widowControl!="boolean")return {ok:false,detail:"widowControl: not a boolean"};h.push({localName:"widowControl",...s.widowControl?{}:{attributes:{val:"0"}}});}return h.length===0?{ok:false,detail:"no formatting was asked for"}:{ok:true,value:chunkUAOJHPQ4_cjs.Wf(chunkUAOJHPQ4_cjs.Uf(r,e),h)}}function Ve(r){let e=Object.create(null);if(!r)return e;for(let s of r.attributes)e[s.localName]=s.value;return e}var Je=20,Zn=63360;function rt(r){return Math.round(r/Je*100)/100}function qn(r,e){if(typeof r!="number"||!Number.isFinite(r))return null;let s=Math.round(r*Je);return s>Zn||s<0||s===0&&!e?null:s}var to=[["pageWidth","pageWidthTwips",false],["pageHeight","pageHeightTwips",false],["topMargin","marginTopTwips",true],["rightMargin","marginRightTwips",true],["bottomMargin","marginBottomTwips",true],["leftMargin","marginLeftTwips",true]];function Qe(r){if(typeof r!="object"||r===null)return {ok:false,reason:"that is not a page setup",detail:"not-an-object"};let e=r,s={},a=0;for(let[u,h,b]of to){let m=e[u];if(m===void 0)continue;let k=qn(m,b);if(k===null)return {ok:false,reason:`that is not a value for ${u}`,detail:String(m)};s[h]=k,a+=1;}let l=e.orientation;if(l!==void 0){if(l!=="portrait"&&l!=="landscape")return {ok:false,reason:"that is not an orientation",detail:String(l)};s.orientation=l,a+=1;}return a===0?{ok:false,reason:"that page setup names nothing to write",detail:"empty"}:{ok:true,value:s}}function eo(r){let e=chunkUAOJHPQ4_cjs.gf(r),s=e.widthTwips>e.heightTwips?"landscape":"portrait";return Object.freeze({pageWidth:rt(e.widthTwips),pageHeight:rt(e.heightTwips),orientation:s,topMargin:rt(e.topTwips),rightMargin:rt(e.rightTwips),bottomMargin:rt(e.bottomTwips),leftMargin:rt(e.leftTwips),headerDistance:rt(e.headerTwips),footerDistance:rt(e.footerTwips),gutter:rt(e.gutterTwips)})}function no(r,e){if(!e)return null;let s=null,a=(l,u,h)=>{if(s!==null||l.kind==="textValue"||h>64)return;let b=l.kind==="paragraph"?l.id:u;if(l.id===e.id){s=b;return}for(let m of l.children)a(m,b,h+1);};return a(r.root,null,0),s}function Ze(r,e,s){let a=chunkUAOJHPQ4_cjs.Rb(e.root);return Object.freeze(a.map((l,u)=>{let h=s[u];return Object.freeze({index:u,markParagraphId:no(e,l),pageSetup:eo(l),titlePage:h?.titlePage??false,evenAndOddHeaders:h?.evenAndOddHeaders??false})}))}var Yt="\r",oo=Object.freeze({nameOf:()=>null,idOf:()=>null,defaultId:null,present:false}),ro=Object.freeze([]),ao=Object.freeze([]),qe=Object.freeze([]),so=Object.freeze({package:null,body:null,story:()=>null,storyOf:()=>null,sections:()=>ao,furniture:()=>qe,noteIds:()=>Object.freeze([]),styles:()=>oo});function io(r){return r.kind==="textValue"?ro:Object.freeze(r.children.filter(e=>e.kind!=="textValue").map(e=>{let s=[];chunkUAOJHPQ4_cjs.Be([e],s,0);let a=e.kind==="paragraph"?"paragraph":e.kind==="table"?"table":"other",l=e.kind==="paragraph"&&chunkUAOJHPQ4_cjs.Ld(chunkUAOJHPQ4_cjs.Jd(e),"sectPr")!==void 0;return Object.freeze({id:e.id,kind:a,paragraphIds:Object.freeze(s.map(u=>u.id)),removable:a!=="other"&&!l})}))}function Xt(r,e,s,a,l){let u=chunkUAOJHPQ4_cjs.Ae(a),h=Object.freeze(u.map(g=>g.id)),b=new Map,m=new Map;u.forEach((g,R)=>{b.set(g.id,R),m.set(g.id,g);});let k=new Map,f=g=>{if(!b.has(g))return null;let R=k.get(g);if(R!==void 0)return R;let A=chunkUAOJHPQ4_cjs.xf(e,g)??"";return k.set(g,A),A};return {story:r,part:e,root:a,scope:s,paragraphIds:h,blocks:io(a),has:g=>b.has(g),indexOf:g=>b.get(g)??-1,paragraph(g){let R=m.get(g);return R?{nodeId:g,paraId:chunkUAOJHPQ4_cjs.Jc(R),text:f(g)??""}:null},node:g=>m.get(g)??null,paragraphText:f,text:()=>h.map(g=>f(g)??"").join(Yt),styles:l}}function tn(r){let e=r.parts.get(r.mainDocumentPart);if(!e)return so;let s,a=()=>s??=De(r),l,u=()=>l??=chunkUAOJHPQ4_cjs.Sb(r),h,b=new Map,m=A=>{let T=u()[A.sectionIndex];return T?(A.kind==="header"?T.headers:T.footers).get(A.variant)??null:null},k=A=>{if(A.kind==="body"){let O=chunkUAOJHPQ4_cjs.ze(e);return O?Xt(A,e,{kind:"body"},O,a):null}if(A.kind==="note"){let O=chunkUAOJHPQ4_cjs.Td(r,A.noteKind);if(!O)return null;let H=chunkUAOJHPQ4_cjs.vd(O.root,A.noteId);return !H||!chunkUAOJHPQ4_cjs.ld(H)?null:Xt(A,O,{kind:"notesPart",noteKind:A.noteKind},H,a)}let T=m(A);return T?Xt(A,T.part,{kind:"headerFooter",rId:T.rId},T.part.root,a):null},f=A=>{let T=_(A);if(b.has(T))return b.get(T)??null;let O=k(A);return b.set(T,O),O},g=A=>{if(f(it)?.has(A))return it;for(let[O]of u().entries())for(let H of ["header","footer"])for(let L of Nt){let j={kind:H,sectionIndex:O,variant:L};if(f(j)?.has(A))return j}for(let O of ["footnote","endnote"])for(let H of R(O)){let L={kind:"note",noteKind:O,noteId:H};if(f(L)?.has(A))return L}return null},R=A=>{let T=chunkUAOJHPQ4_cjs.Td(r,A);if(!T)return lo;let O=[];for(let H of chunkUAOJHPQ4_cjs.ud(T.root)){if(!chunkUAOJHPQ4_cjs.ld(H))continue;let L=chunkUAOJHPQ4_cjs.jd(H);L!==null&&O.push(L);}return Object.freeze(O)};return {package:r,get body(){return f(it)},story:f,storyOf:g,sections:()=>h??=Ze(r,e,u()),furniture(A){let T=u()[A];if(!T)return qe;let O=[];for(let H of ["header","footer"]){let L=H==="header"?T.headers:T.footers;for(let j of Nt){let Q=L.get(j);Q&&O.push(Object.freeze({kind:H,variant:j,declared:!Q.inherited}));}}return Object.freeze(O)},noteIds:R,styles:a}}var lo=Object.freeze([]);function q(r,e){return {ok:false,code:r,detail:e}}function tt(r){return {ok:true,value:r}}function $(r,e,s,a){let l=s.resolve(r,e);if(!l||l.kind!=="body"&&l.kind!=="paragraph")return q("invalid-handle",`not-a-${e}-handle`);let u=a.story(l.story);return u?tt(u):q("invalid-handle",`no-such-story:${_(l.story)}`)}function G(r,e,s){let a=e.resolve(r,"paragraph");if(!a||a.kind!=="paragraph")return q("invalid-handle","not-a-paragraph-handle");let l=s.story(a.story);if(!l)return q("invalid-handle",`no-such-story:${_(a.story)}`);let u=l.indexOf(a.paragraphId);return u<0?q("invalid-handle","paragraph-not-in-body"):tt({story:a.story,paragraphId:a.paragraphId,index:u,offset:0})}function uo(r,e,s){let a=G(r.paragraph,e,s);if(!a.ok)return a;let u=(s.story(a.value.story)?.paragraphText(a.value.paragraphId)??"").length,{offset:h}=r;return !Number.isInteger(h)||h<0||h>u?q("invalid-offset",`offset ${String(h)} outside 0..${String(u)}`):tt({...a.value,offset:h})}function mt(r,e,s){if("paragraph"in r){if(!("at"in r))return uo(r,e,s);let b=G(r.paragraph,e,s);if(!b.ok||r.at==="start")return b;let k=(s.story(b.value.story)?.paragraphText(b.value.paragraphId)??"").length;return tt({...b.value,offset:k})}let a=$(r.body,"body",e,s);if(!a.ok)return a;let l=a.value.paragraphIds;if(l.length===0)return q("invalid-offset","empty-story");if(r.at==="start")return tt({story:a.value.story,paragraphId:l[0],index:0,offset:0});let u=l.length-1,h=l[u];return tt({story:a.value.story,paragraphId:h,index:u,offset:(a.value.paragraphText(h)??"").length})}function co(r,e){return r.index<e.index||r.index===e.index&&r.offset<=e.offset}function po(r){let e=r.paragraphIds;if(e.length===0)return null;let s=e.length-1,a=e[s];return {start:{story:r.story,paragraphId:e[0],index:0,offset:0},end:{story:r.story,paragraphId:a,index:s,offset:(r.paragraphText(a)??"").length}}}function W(r,e,s){if("body"in r){let u=$(r.body,"body",e,s);return u.ok?tt(po(u.value)):u}if("paragraph"in r){let u=G(r.paragraph,e,s);if(!u.ok)return u;let b=(s.story(u.value.story)?.paragraphText(u.value.paragraphId)??"").length;return tt({start:u.value,end:{...u.value,offset:b}})}let a=mt(r.start,e,s);if(!a.ok)return a;let l=mt(r.end,e,s);return l.ok?_(a.value.story)!==_(l.value.story)?q("invalid-handle","span-crosses-stories"):co(a.value,l.value)?tt({start:a.value,end:l.value}):q("invalid-offset","span-start-after-end"):l}function at(r,e,s){if("body"in r)return $(r.body,"body",e,s);if("paragraph"in r)return $(r.paragraph,"paragraph",e,s);let a=r.start;return "paragraph"in a?$(a.paragraph,"paragraph",e,s):$(a.body,"body",e,s)}function Et(r,e,s){if("paragraph"in r)return G(r.paragraph,e,s);let a=$(r.body,"body",e,s);if(!a.ok)return a;let l=a.value.paragraphIds;if(l.length===0)return q("invalid-offset","empty-story");let u=r.at==="first"?0:l.length-1;return tt({story:a.value.story,paragraphId:l[u],index:u,offset:0})}function et(r,e){return r?e.paragraphIds.slice(r.start.index,r.end.index+1):[]}function Gt(r,e){if(!r)return [];let s=et(r,e),a=s.length-1;return s.map((l,u)=>{let h=(e.paragraphText(l)??"").length,b=u===0?r.start.offset:0,m=u===a?r.end.offset:h;return {paragraphId:l,start:b,end:m,whole:b===0&&m===h}})}function en(r,e,s){if(!r)return "";let a=et(r,e);return a.length===1?(e.paragraphText(r.start.paragraphId)??"").slice(r.start.offset,r.end.offset):a.map((l,u)=>{let h=e.paragraphText(l)??"";return u===0?h.slice(r.start.offset):u===a.length-1?h.slice(0,r.end.offset):h}).join(s)}function Jt(r,e){return {start:{paragraph:e.paragraph(r.start.paragraphId,r.start.story),offset:r.start.offset},end:{paragraph:e.paragraph(r.end.paragraphId,r.end.story),offset:r.end.offset}}}var mo=256,nn=1e4;function Qt(r,e){if(r.kind!=="textValue"){for(let s of r.attributes)if(s.namespaceUri===chunkUAOJHPQ4_cjs.la&&s.localName===e)return s.value}}function fo(r){return r.startsWith("_")}function Zt(r){let e=new Map,s=[],a=new Set;for(let l of r.paragraphIds){let u=r.node(l);if(u?.kind!=="paragraph")continue;let h=chunkUAOJHPQ4_cjs.Nd(u),b=m=>{if(m.kind!=="textValue"){if(m.kind==="bookmarkStart"){if(s.length>=nn||e.size>=nn)return;let k=Qt(m,"id"),f=Qt(m,"name");if(k===void 0||f===void 0||f.length===0||f.length>mo||fo(f)||a.has(f)||e.has(k))return;let g=h.spanOf(m)?.start??0;e.set(k,{name:f,start:{paragraphId:l,offset:g}});return}if(m.kind==="bookmarkEnd"){let k=Qt(m,"id");if(k===void 0)return;let f=e.get(k);if(!f)return;e.delete(k),a.add(f.name);let g=h.spanOf(m)?.start??0;s.push(Object.freeze({name:f.name,start:f.start,end:{paragraphId:l,offset:g}}));return}for(let k of m.children)b(k);}};for(let m of u.children)b(m);}return Object.freeze(s)}function qt(r,e){return Zt(r).find(s=>s.name===e)??null}function on(r,e){let s=r.node(e);if(s?.kind!=="paragraph")return Object.freeze([]);let a=chunkUAOJHPQ4_cjs.Nd(s),l=[],u=(h,b)=>{if(!(h.kind==="textValue"||b>32)){if(chunkUAOJHPQ4_cjs.Qa(h)){let m=a.spanOf(h);m&&l.push(Object.freeze({id:h.id,paragraphId:e,start:m.start,end:m.end}));return}for(let m of h.children)u(m,b+1);}};for(let h of s.children)u(h,0);return Object.freeze(l)}function rn(r,e,s){let a=chunkUAOJHPQ4_cjs.Ta(s,l=>chunkUAOJHPQ4_cjs.Sc(r,e,l));if(a.kind==="external")return a.href;if(a.kind==="internal"){let l=chunkUAOJHPQ4_cjs.Ra(s);return l===void 0||l.length===0?null:`#${l}`}return null}var ft=8;function an(r){if(!r||r.kind==="textValue")return null;for(let e of r.attributes)if(e.namespaceUri===chunkUAOJHPQ4_cjs.la&&e.localName==="val")return e.value;return null}function sn(r){let e=chunkUAOJHPQ4_cjs.Ld(chunkUAOJHPQ4_cjs.Jd(r),"numPr");if(!e)return null;let s=an(chunkUAOJHPQ4_cjs.Ld(e,"numId"));if(s===null||!/^\d{1,10}$/.test(s)||s==="0")return null;let a=an(chunkUAOJHPQ4_cjs.Ld(e,"ilvl")),l=a===null?0:Number(a);return !Number.isInteger(l)||l<0||l>ft?null:{numId:s,level:l}}function _t(r){let e=new Map;for(let s of r.paragraphIds){let a=r.node(s);if(!a)continue;let l=sn(a);if(!l)continue;let u=e.get(l.numId);u?u.push(s):e.set(l.numId,[s]);}return Object.freeze([...e].map(([s,a])=>Object.freeze({numId:s,paragraphIds:Object.freeze(a)})))}function It(r,e){let s=r.node(e);return s?sn(s):null}var go={insert:"Insert",delete:"Delete",replace:"Replace",moveFrom:"MovedFrom",moveTo:"MovedTo",format:"Property",paragraphMark:"ParagraphProperty"};function yo(r){return r.kind==="note"}function ho(r,e){return e.length===0?!yo(r.story):e.every(s=>r.has(s.start.paragraphId))}function te(r){let e=[];for(let s of chunkUAOJHPQ4_cjs.dg(r.part)){if(s.readOnly||s.revisionKind==="structural"||!ho(r,s.ranges))continue;let a=go[s.revisionKind];a!==void 0&&e.push(Object.freeze({id:s.id,type:a,author:s.author,date:s.date??"",item:s}));}return Object.freeze(e)}function ko(r,e){let s=r;for(let a=0;s!==void 0&&a<=64;a+=1){if(s.parentId===void 0)return s.range!==null;s=e.get(s.parentId);}return false}var Ao=Object.freeze({items:Object.freeze([]),roots:Object.freeze([]),byId:()=>null,textOf:()=>""});function dn(r,e){let s=r.parts.get(chunkUAOJHPQ4_cjs.Gf(r,e.part.name));if(!s)return Ao;let a=r.parts.get(chunkUAOJHPQ4_cjs.Hf(r,e.part.name)),l=chunkUAOJHPQ4_cjs.Ee(s),u=a?chunkUAOJHPQ4_cjs.Fe(a):new Map,h=chunkUAOJHPQ4_cjs.De(e.part).filter(g=>e.has(g.start.paragraphId)),b=chunkUAOJHPQ4_cjs.eg(l,h,u),m=new Map(b.map(g=>[g.id,g])),k=b.filter(g=>ko(g,m)),f=new Map(k.map(g=>[g.id,g]));return Object.freeze({items:Object.freeze(k),roots:Object.freeze(k.filter(g=>g.parentId===void 0)),byId:g=>f.get(g)??null,textOf:g=>{let R=f.get(g);return R?chunkUAOJHPQ4_cjs.bg(R.comment):""}})}var vo=1e4;function ln(r,e){let s=[],a=e.kind==="contentControl"?chunkUAOJHPQ4_cjs.ke(e):e;if(!a)return s;for(let l of chunkUAOJHPQ4_cjs.oe(a))if(!(l.ancestors.length>0)){if(s.length>=vo)break;s.push(mn(r,l.node));}return s}function un(r,e){for(let s of chunkUAOJHPQ4_cjs.oe(r.root))if(s.node.id===e)return mn(r,s.node);return null}function cn(r,e){for(let s of chunkUAOJHPQ4_cjs.oe(r.root))if(s.node.id===e)return s.node;return null}function ee(r,e){let s=fn(e);if(s.length>0){let a=s[0],l=s[s.length-1],u=r.paragraphText(l);return u===null||!r.has(a)?null:{start:{paragraphId:a,offset:0},end:{paragraphId:l,offset:u.length}}}for(let a of r.paragraphIds){let l=r.node(a);if(!l||l.kind!=="paragraph"||!l.children.some(h=>h.id===e.id))continue;let u=chunkUAOJHPQ4_cjs.Nd(l).spanOf(e);return u?{start:{paragraphId:a,offset:u.start},end:{paragraphId:a,offset:u.end}}:null}return null}function pn(r){return chunkUAOJHPQ4_cjs.qe(r)}function mn(r,e){return {nodeId:e.id,properties:chunkUAOJHPQ4_cjs.me(e),lock:chunkUAOJHPQ4_cjs.yf(r.part,e.id),paragraphIds:fn(e)}}function fn(r){let e=chunkUAOJHPQ4_cjs.ke(r);if(!e)return [];let s=[];return chunkUAOJHPQ4_cjs.Be(e.children,s,0),s.map(a=>a.id)}var bo=new Set(["unlocked","sdtLocked","contentLocked","sdtContentLocked"]),Io=4096,gn=64;function yn(r){if(r===void 0)return {ok:true,value:null};if(typeof r!="object"||r===null)return {ok:false,field:"payload"};let e=r;for(let s of ["namespaceUri","rootLocalName","nodeId"]){let a=e[s];if(typeof a!="string"||a.length===0||a.length>Io)return {ok:false,field:s}}return typeof e.label!="string"||e.label.length>chunkUAOJHPQ4_cjs.Jf?{ok:false,field:"label"}:typeof e.data!="string"||e.data.length===0||e.data.length>chunkUAOJHPQ4_cjs.If?{ok:false,field:"data"}:{ok:true,value:{namespaceUri:e.namespaceUri,rootLocalName:e.rootLocalName,nodeId:e.nodeId,label:e.label,data:e.data}}}function hn(r){let e=r.at!==void 0,s=r.span!==void 0;return e===s?{message:"a custom node goes at a position or over a span, not both",detail:e?"at+span":"no-place"}:typeof r.tag!="string"||r.tag.length===0?{message:"a custom node carries its identity in its tag",detail:"tag"}:r.tag.length>gn?{message:`w:tag caps at ${String(gn)} characters; a longer payload belongs in the store`,detail:"tag"}:typeof r.text!="string"||r.text.length===0?{message:"a custom node shows some text",detail:"text"}:r.lock!==void 0&&!bo.has(r.lock)?{message:"that is not a lock",detail:String(r.lock)}:null}function kn(r,e,s,a){return {paragraphId:e.paragraphId,offset:e.offset,...s.offset>e.offset?{replaceUntil:s.offset}:{},tag:r.tag,text:r.text,...r.title===void 0?{}:{alias:r.title},...r.lock===void 0||r.lock==="unlocked"?{}:{lock:r.lock},...a===null?{}:{payload:a}}}function An(r,e,s){if(r.span){let l=W(r.span,e,s);return l.ok?l.value?l.value.start.paragraphId!==l.value.end.paragraphId?{code:"unsupported-content",message:"a custom node wraps text inside one paragraph",detail:"multi-paragraph"}:{range:l.value}:{code:"invalid-offset",message:"that story holds nothing to wrap",detail:"empty-story"}:{code:l.code,message:"that span is not a place",detail:l.detail}}let a=mt(r.at,e,s);return a.ok?{range:{start:a.value,end:a.value}}:{code:a.code,message:"that is not a place",detail:a.detail}}var xt=/[\r\n\v\f\u2028\u2029]/,xo=16,So=64,vn=/\s/;function Ro(r,e,s){return Object.freeze(s===void 0?{code:r,message:e}:{code:r,message:e,detail:s})}function d(r,e,s){return {ok:false,error:Ro(r,e,s)}}var F=Object.freeze({kind:"applied"});function I(r){return {ok:true,kind:"query",value:r}}function bn(r){let e=r.kind==="contentControl"?chunkUAOJHPQ4_cjs.ke(r):r;return e?chunkUAOJHPQ4_cjs.oe(e).map(s=>s.node):[]}var Co=new Set(["unlocked","sdtLocked","contentLocked","sdtContentLocked"]),Oo=new Set(["whole","content","start","end","before","after"]),Po=new Set(["richText","plainText","dropDownList","comboBox","date"]),wo=4096;function To(r){let e=(l,u)=>({ok:false,code:"unsupported-content",message:l,detail:u});if(typeof r!="object"||r===null||!("kind"in r))return e("a control value states its kind","value");let s=r,a=s.kind;if(a==="text"||a==="listItem"){let l=a==="text"?s.text:s.value;return typeof l!="string"?e("that value is not a string",String(a)):l.length>wo?e("that value is too long",String(l.length)):{ok:true,value:a==="text"?{kind:"text",text:l}:{kind:"listItem",value:l}}}if(a==="checkbox"){let l=s.checked;return typeof l!="boolean"?e("a checkbox is checked or not","checked"):{ok:true,value:{kind:"checkbox",checked:l}}}if(a==="date"){let l=s.iso;return typeof l!="string"?e("a date is an ISO-8601 string","iso"):l.length>64?e("that is not a date",String(l.length)):{ok:true,value:{kind:"date",iso:l}}}return e("that is not a value any control accepts",String(a))}function No(r,e){let s=[],a=0;for(;a<r.length;){let l=null;for(let u of e){let h=r.indexOf(u,a);h<0||(!l||h<l.start||h===l.start&&u.length>l.length)&&(l={start:h,length:u.length});}if(!l)break;s.push(l),a=l.start+l.length;}return s}function Ho(r,e,s){let a=e[s]?.markParagraphId??null;if(a!==null)return a;let l=r.paragraphIds,u=l[l.length-1];return u===void 0||new Set(e.map(b=>b.markParagraphId).filter(b=>b!==null)).has(u)?null:u}function Lo(r,e){for(let s of [r.start,r.end]){let a=e.paragraphText(s.paragraphId);if(a===null||s.offset>a.length)return false}return true}function Mo(r,e,s){let a=e,l=s;for(;a<l&&vn.test(r[a]);)a+=1;for(;l>a&&vn.test(r[l-1]);)l-=1;return [a,l]}function In(r){let{handles:e,capabilities:s}=r,a=r.reads,l=new Map,u=o=>{let t=_(o.story),n=l.get(t);if(n)return n;let i=new Map,c=o.paragraphIds.map(y=>{let v={id:y};return i.set(y,v),v}),p={reads:o,order:c,slotById:i,created:[],restructured:new Set,touched:new Set,formatted:new Set,selected:new Set,retargets:[]};return l.set(t,p),p},h=[],b=false,m=false,k=null,f=o=>k===null?(k=o,null):k===o?null:d("conflicting-operations","one batch writes into one story",`${_(k.reads.story)} then ${_(o.reads.story)}`),g=o=>{let t=a.package;return t===null?null:dn(t,o)},R=o=>{let t=e.resolve(o,"comment");if(!t||t.kind!=="comment")return {ok:false,planned:d("invalid-handle","that handle does not name a comment","comment")};let n=a.story(t.story);if(!n)return {ok:false,planned:d("invalid-handle","that story is not in this document")};let c=g(n)?.byId(t.commentId)??null;return c?{ok:true,reads:n,item:c}:{ok:false,planned:d("invalid-handle","this document no longer holds that comment",t.commentId)}},A=o=>{let t=e.resolve(o,"revision");if(!t||t.kind!=="revision")return {ok:false,planned:d("invalid-handle","that handle does not name a tracked change","revision")};let n=a.story(t.story);if(!n)return {ok:false,planned:d("invalid-handle","that story is not in this document")};let i=te(n).find(c=>c.id===t.revisionId)??null;return i?{ok:true,reads:n,item:i}:{ok:false,planned:d("invalid-handle","this document no longer holds that tracked change",t.revisionId)}},T=(o,t)=>{let n=o.paragraphText(t.start.paragraphId),i=o.paragraphText(t.end.paragraphId);if(n===null||i===null)return null;let c={story:o.story,paragraphId:t.start.paragraphId,index:o.indexOf(t.start.paragraphId),offset:Math.min(t.start.offset,n.length)},p={story:o.story,paragraphId:t.end.paragraphId,index:o.indexOf(t.end.paragraphId),offset:Math.min(t.end.offset,i.length)};return M({start:c,end:p})},O=(o,t)=>o.order.indexOf(t),H=(o,t)=>o.selected.has(t)?d("conflicting-operations","this batch selects a paragraph it also edits",t):null,L=(o,t)=>{let n=H(o,t);return n||(o.restructured.has(t)||o.touched.has(t)?d("conflicting-operations","another operation in this batch already changes that paragraph",t):(o.restructured.add(t),o.touched.add(t),null))},j=(o,t)=>{let n=H(o,t);return n||(o.restructured.has(t)?d("conflicting-operations","another operation in this batch restructures that paragraph",t):(o.touched.add(t),null))},Q=(o,t,n)=>{let i=`${n}:${t}`;if(o.formatted.has(i))return d("conflicting-operations","another operation in this batch already writes that formatting",t);let c=j(o,t);return c||(o.formatted.add(i),null)},dt=(o,t)=>{let n={id:null};return o.order.splice(t,0,n),o.created.push(n),n},M=o=>Jt(o,e),X=o=>o===null?null:a.story(o.start.story),St=(o,t,n,i)=>{if(i?.matchWildcards===true)return d("unsupported-capability","wildcard search is not implemented","matchWildcards");if(i?.ignorePunct===true)return d("unsupported-capability","ignoring punctuation is not implemented","ignorePunct");if(i?.ignoreSpace===true)return d("unsupported-capability","ignoring whitespace is not implemented","ignoreSpace");if(!chunkUAOJHPQ4_cjs.pg(n))return d("unsupported-content","that is not a query this host will scan for","text");let c=i?.limit;if(c!==void 0&&(!Number.isInteger(c)||c<0))return d("invalid-offset","limit must be a non-negative integer",String(c));let p=Math.min(c??2e3,2e3),y=[],v=et(t,o),x=v.length-1;for(let[P,w]of v.entries()){if(p<=0)break;let E=o.paragraphText(w)??"",C=chunkUAOJHPQ4_cjs.qg(E,n,p,{matchCase:i?.matchCase===true,wholeWord:i?.matchWholeWord===true,...P===0&&t?{from:t.start.offset}:{},...P===x&&t?{to:t.end.offset}:{}});for(let S of C.matches){let V=e.paragraph(w,o.story);y.push({start:{paragraph:V,offset:S.start},end:{paragraph:V,offset:S.start+S.length}});}p-=C.matches.length;}return I({kind:"spans",spans:y})},gt=(o,t,n)=>{if(typeof n!="string")return d("unsupported-content","insertText needs text","text");if(xt.test(n))return d("unsupported-content","text carrying a paragraph mark is not written by this host","paragraph-mark-in-text");let i=f(o);if(i)return i;let c=j(o,t.paragraphId);if(c)return c;let p=n.length===0?[]:[{op:"insertText",paragraphId:t.paragraphId,offset:t.offset,text:n}],y=()=>({kind:"span",span:M({start:t,end:{...t,offset:t.offset+n.length}})});return {ok:true,kind:"command",ops:p,story:o.reads.story,answer:y}},Rt=(o,t,n)=>{let i=o.reads;if(typeof n!="string")return d("unsupported-content","replaceSpan needs text","text");if(xt.test(n))return d("unsupported-content","text carrying a paragraph mark is not written by this host","paragraph-mark-in-text");let c=et(t,i),p=t.start.paragraphId,y=[],v=f(o);if(v)return v;if(c.length===1){let w=j(o,p);if(w)return w;t.end.offset>t.start.offset&&y.push({op:"deleteText",paragraphId:p,start:t.start.offset,end:t.end.offset});}else {for(let C of c){let S=L(o,C);if(S)return S}let w=t.end.paragraphId,E=(i.paragraphText(p)??"").length;t.start.offset<E&&y.push({op:"deleteText",paragraphId:p,start:t.start.offset,end:E}),t.end.offset>0&&y.push({op:"deleteText",paragraphId:w,start:0,end:t.end.offset});for(let C of c.slice(1,-1))y.push({op:"deleteBlock",blockId:C});y.push({op:"joinParagraphs",firstId:p,secondId:w});for(let C of c.slice(1)){let S=o.slotById.get(C);S&&o.order.splice(O(o,S),1);}}n.length>0&&y.push({op:"insertText",paragraphId:p,offset:t.start.offset,text:n});let x={...t.start,paragraphId:p},P=()=>({kind:"span",span:M({start:x,end:{...x,offset:x.offset+n.length}})});return {ok:true,kind:"command",ops:y,story:o.reads.story,answer:P}},ne=(o,t)=>{let n=o.reads;if(typeof t!="string")return d("unsupported-content","replaceSpan needs text","text");if(xt.test(t))return d("unsupported-content","text carrying a paragraph mark is not written by this host","paragraph-mark-in-text");let i=n.blocks,c=i.filter(S=>S.removable),p=i.filter(S=>!S.removable).flatMap(S=>S.paragraphIds),y=p.length===0?c.find(S=>S.kind==="paragraph"):void 0;if(!y&&p.length===0)return d("invalid-offset","that story holds no paragraph this host can write into","no-top-level-paragraph");let v=f(o);if(v)return v;for(let S of n.paragraphIds){let V=L(o,S);if(V)return V}let x=[],P=(y?[y.id]:[...p]).sort((S,V)=>n.indexOf(S)-n.indexOf(V)),w=P[0];for(let S of P){let V=(n.paragraphText(S)??"").length;V>0&&x.push({op:"deleteText",paragraphId:S,start:0,end:V});}for(let S of c)S.id!==y?.id&&x.push({op:"deleteBlock",blockId:S.id});t.length>0&&x.push({op:"insertText",paragraphId:w,offset:0,text:t});for(let S of c)if(S.id!==y?.id)for(let V of S.paragraphIds){let Ct=o.slotById.get(V);Ct&&o.order.splice(O(o,Ct),1);}let E={story:n.story,paragraphId:w,index:n.indexOf(w),offset:0},C=()=>({kind:"span",span:M({start:E,end:{...E,offset:t.length}})});return {ok:true,kind:"command",ops:x,story:n.story,answer:C}},N=(o,t,n,i)=>{let c=o.reads;if(typeof i!="string")return d("unsupported-content","insertParagraph needs text","text");if(xt.test(i))return d("unsupported-content","a paragraph mark inside a paragraph\u2019s text is not written by this host","paragraph-mark-in-text");let p=f(o);if(p)return p;let y=L(o,t.paragraphId);if(y)return y;let v=o.slotById.get(t.paragraphId);if(!v)return d("invalid-handle","that paragraph is not in the body");let x=(c.paragraphText(t.paragraphId)??"").length,P=[];n==="after"?(i.length>0&&P.push({op:"insertText",paragraphId:t.paragraphId,offset:x,text:i}),P.push({op:"splitParagraph",paragraphId:t.paragraphId,offset:x})):(i.length>0&&P.push({op:"insertText",paragraphId:t.paragraphId,offset:0,text:i}),P.push({op:"splitParagraph",paragraphId:t.paragraphId,offset:i.length}));let w=dt(o,O(o,v)+1);n==="before"&&o.retargets.push({from:t.paragraphId,slot:w});let E=()=>{let C=n==="after"?w.id:t.paragraphId;return C===null?F:{kind:"handle",handle:e.paragraph(C,c.story)}};return {ok:true,kind:"command",ops:P,story:c.story,answer:E}},K=(o,t,n,i,c)=>{let p=o.reads;if(!Array.isArray(n)||n.length===0)return d("unsupported-content","split needs at least one delimiter","delimiters");if(n.length>xo)return d("unsupported-content","too many delimiters",String(n.length));for(let z of n){if(typeof z!="string"||z.length===0)return d("unsupported-content","a delimiter must be a non-empty string","delimiters");if(z.length>So)return d("unsupported-content","that delimiter is too long","delimiters")}let y=f(o);if(y)return y;let v=L(o,t.paragraphId);if(v)return v;let x=o.slotById.get(t.paragraphId);if(!x)return d("invalid-handle","that paragraph is not in the body");let P=p.paragraphText(t.paragraphId)??"",w=No(P,n),E=[],C=[],S=[];if(w.length===0)S.push(P);else if(i){for(let D of [...w].reverse())E.push({op:"deleteText",paragraphId:t.paragraphId,start:D.start,end:D.start+D.length});let z=0,st=0;for(let D of w){let jt=D.start-z;C.push(jt),S.push(P.slice(st,D.start)),st=D.start+D.length,z+=D.length;}S.push(P.slice(st));}else {let z=0;for(let st of w){let D=st.start+st.length;C.push(D),S.push(P.slice(z,D)),z=D;}S.push(P.slice(z));}C.length>0&&E.push({op:"splitParagraphMany",paragraphId:t.paragraphId,offsets:C});let V=[x];for(let z=0;z<C.length;z+=1)V.push(dt(o,O(o,x)+1+z));let Ct=z=>{let st=z.story(p.story),D=[];return V.forEach((jt,Nn)=>{let Kt=jt.id;if(Kt===null)return;let Wt=st?.paragraphText(Kt)??S[Nn]??"",[Hn,Ln]=c?Mo(Wt,0,Wt.length):[0,Wt.length],re=e.paragraph(Kt,p.story);D.push({start:{paragraph:re,offset:Hn},end:{paragraph:re,offset:Ln}});}),{kind:"spans",spans:D}};return {ok:true,kind:"command",ops:E,story:p.story,answer:Ct}},nt=(o,t)=>{let n=f(o);if(n)return n;let i=L(o,t.paragraphId);if(i)return i;let c=o.slotById.get(t.paragraphId);return c&&o.order.splice(O(o,c),1),{ok:true,kind:"command",ops:[{op:"deleteBlock",blockId:t.paragraphId}],story:o.reads.story,answer:()=>F}},yt=(o,t,n)=>{let i=o.reads,c=i.part,p=f(o);if(p)return p;let y=Ye(n??{});if(!y.ok)return d("unsupported-content","that is not formatting this host writes",y.detail);let v=[];for(let x of Gt(t,i)){if(x.end<=x.start&&!x.whole)continue;let P=Q(o,x.paragraphId,"runs");if(P)return P;for(let w of chunkUAOJHPQ4_cjs.Zf(c,x.paragraphId,x.start,x.end,y.value))v.push({op:"setRunProperties",paragraphId:x.paragraphId,start:w.start,end:w.end,properties:w.properties,...w.targetRunIds?{targetRunIds:w.targetRunIds}:{}});x.whole&&v.push({op:"setParagraphMarkProperties",paragraphId:x.paragraphId,properties:chunkUAOJHPQ4_cjs.Wf(chunkUAOJHPQ4_cjs.Vf(c,x.paragraphId),y.value)});}return v.length===0?d("invalid-offset","that range covers no characters to format","collapsed-range"):{ok:true,kind:"command",ops:v,story:i.story,answer:()=>F}},lt=(o,t,n)=>{let i=o.reads,c=i.part,p=f(o);if(p)return p;let y=Lt(n,i.styles());if(!y.ok)return d("unsupported-content","that is not a style this document has",y.detail);let v={localName:"pStyle",attributes:{val:y.styleId}},x=[];for(let P of et(t,i)){let w=Q(o,P,"paragraph");if(w)return w;x.push({op:"setParagraphProperties",paragraphId:P,properties:chunkUAOJHPQ4_cjs.Wf(chunkUAOJHPQ4_cjs.Uf(c,P),v)});}return x.length===0?d("invalid-offset","that story holds no paragraph to style","empty-story"):{ok:true,kind:"command",ops:x,story:i.story,answer:()=>F}},xn=(o,t,n)=>{let i=o.reads,c=i.part,p=f(o);if(p)return p;let y=Ge(c,t.paragraphId,n??{},i.styles());if(!y.ok)return d("unsupported-content","that is not paragraph formatting this host writes",y.detail);let v=Q(o,t.paragraphId,"paragraph");return v||{ok:true,kind:"command",ops:[{op:"setParagraphProperties",paragraphId:t.paragraphId,properties:y.value}],story:i.story,answer:()=>F}},Sn=(o,t)=>{let n=a.body;if(!n)return d("document-unavailable","this host holds no document right now");let i=a.sections();if(!i[o])return d("invalid-handle","that section is not in this document");let p=Qe(t);if(!p.ok)return d("unsupported-content",p.reason,p.detail);let y=Ho(n,i,o);if(y===null)return d("unsupported-content","that section holds no paragraph to address it by","no-anchor");let v=u(n),x=f(v);return x||{ok:true,kind:"command",ops:[{op:"setSectionProperties",...p.value,anchorParagraphId:y}],story:it,answer:()=>F}},Rn=(o,t)=>({ok:true,kind:"command",ops:[{op:"deleteNote",noteKind:o,noteId:t}],story:it,lifecycle:true,answer:()=>F}),Ft=o=>{let t=e.resolve(o,"list");if(!t||t.kind!=="list")return d("invalid-handle","that handle does not name a list","list");let n=a.story(t.story);if(!n)return d("invalid-handle","that story is not in this document");let i=_t(n).find(c=>c.numId===t.numId);return i?{ok:true,plan:u(n),list:i}:d("invalid-handle","this story numbers nothing with that list",t.numId)},Bt=o=>{if(typeof o!="object"||o===null)return d("invalid-handle","that is not a scope a control lives in","scope");let t=o;if("body"in o){let n=$(t.body,"body",e,a);return n.ok?{reads:n.value,node:n.value.root}:d(n.code,"that handle does not name a body",n.detail)}if("contentControl"in o){let n=Z(t.contentControl);return "control"in n?{reads:n.reads,node:n.node}:n}return d("invalid-handle","that is not a scope a control lives in","scope")},Z=o=>{let t=e.resolve(o,"contentControl");if(!t||t.kind!=="contentControl")return d("invalid-handle","that handle does not name a content control","contentControl");let n=a.story(t.story);if(!n)return d("invalid-handle","that story is not in this document");let i=un(n,t.nodeId),c=cn(n,t.nodeId);return !i||!c?d("invalid-handle","this document no longer holds that content control"):{reads:n,control:i,node:c}},Cn=(o,t,n)=>{if(!Number.isInteger(n)||n<0||n>ft)return d("invalid-offset",`a list level is 0 to ${String(ft)}`,String(n));if(!It(o.reads,t))return d("unsupported-content","that paragraph is not in a list",t);let i=f(o);if(i)return i;let c=Q(o,t,"paragraph");return c||{ok:true,kind:"command",ops:[{op:"setListLevel",paragraphId:t,level:n}],story:o.reads.story,answer:()=>F}},On=(o,t,n,i)=>{if(n!=="start"&&n!=="end")return d("unknown-operation","a list takes an item at its start or its end",String(n));let c=o.reads,p=n==="start"?t.paragraphIds[0]:t.paragraphIds[t.paragraphIds.length-1];if(p===void 0)return d("invalid-handle","that list holds no paragraph");let y={story:c.story,paragraphId:p,index:c.indexOf(p)};return N(o,y,n==="start"?"before":"after",i)},oe=(o,t)=>{if(t.start.paragraphId!==t.end.paragraphId)return null;for(let n of on(o,t.start.paragraphId))if(n.start<=t.start.offset&&n.end>=t.end.offset)return n;return null},Pn=(o,t,n)=>{if(typeof n!="string")return d("unsupported-content","a hyperlink target is a string","target");let i=o.reads,c=oe(i,t),p=t.start.paragraphId===t.end.paragraphId&&t.start.offset===t.end.offset;if(n.length===0){if(!c)return d("unsupported-content","that text is not a link","no-link");let C=f(o);if(C)return C;let S=j(o,c.paragraphId);return S||{ok:true,kind:"command",ops:[{op:"removeHyperlink",linkId:c.id}],story:i.story,answer:()=>F}}let y={},v=null;if(n.startsWith("#")){let C=n.slice(1);if(C.length===0||!qt(i,C))return d("unsupported-content","this document declares no such bookmark",n);y={anchor:C};}else {if(chunkUAOJHPQ4_cjs.Qc(n)===null)return d("unsupported-content","this engine will not author that target","target");v=n;}let x=f(o);if(x)return x;let P=C=>v===null?{ok:true,kind:"command",ops:[C(y)],story:i.story,answer:()=>F}:{ok:true,kind:"command",ops:[],relate:{url:v,ops:S=>[C({relationshipId:S})]},story:i.story,answer:()=>F};if(c){let C=j(o,c.paragraphId);return C||P(S=>({op:"setHyperlinkTarget",linkId:c.id,...S}))}if(p)return d("unsupported-content","a link with no text has nothing to click","collapsed");if(t.start.paragraphId!==t.end.paragraphId)return d("unsupported-content","a link lives inside one paragraph","crosses-paragraph-mark");let w=j(o,t.start.paragraphId);if(w)return w;let E=i.styles().idOf("hyperlink");return P(C=>({op:"insertHyperlink",paragraphId:t.start.paragraphId,start:t.start.offset,end:t.end.offset,...C,...E===null?{}:{styleId:E}}))},wn=(o,t,n)=>{let i=o.reads;if(!s.selection||!r.select)return d("unsupported-capability","this host has no reader to move","selection");if(n!=="select"&&n!=="start"&&n!=="end")return d("unknown-operation","that is not a selection mode",String(n));let c=et(t,i);for(let p of c)if(o.touched.has(p))return d("conflicting-operations","this batch edits a paragraph the selection covers",p);for(let p of c)o.selected.add(p);return h.push({range:t,mode:n}),{ok:true,kind:"command",ops:[],story:i.story,answer:()=>F}},Tn=o=>{switch(o.op){case "getDocument":return I({kind:"handle",handle:e.document()});case "getBody":return e.resolve(o.document,"document")?a.body?I({kind:"handle",handle:e.body(it)}):d("document-unavailable","this host holds no document right now"):d("invalid-handle","that handle does not name a document","document");case "getParagraphs":{let t=$(o.body,"body",e,a);return t.ok?I({kind:"handles",handles:t.value.paragraphIds.map(n=>e.paragraph(n,t.value.story))}):d(t.code,"that handle does not name a body",t.detail)}case "getSpanParagraphs":{let t=W(o.span,e,a);if(!t.ok)return d(t.code,"that span is not a place",t.detail);let n=at(o.span,e,a);return n.ok?I({kind:"handles",handles:et(t.value,n.value).map(i=>e.paragraph(i,n.value.story))}):d(n.code,"that span is not a place",n.detail)}case "getText":{if(e.resolve(o.target,"body")){let c=$(o.target,"body",e,a);return c.ok?I({kind:"text",text:c.value.text()}):d(c.code,"that handle does not name a body",c.detail)}let n=G(o.target,e,a);if(!n.ok)return d(n.code,"that handle does not name a body or a paragraph",n.detail);let i=a.story(n.value.story);return I({kind:"text",text:i?.paragraphText(n.value.paragraphId)??""})}case "getSpanText":{let t=W(o.span,e,a);if(!t.ok)return d(t.code,"that span is not a place",t.detail);let n=at(o.span,e,a);return n.ok?I({kind:"text",text:en(t.value,n.value,Yt)}):d(n.code,"that span is not a place",n.detail)}case "getParagraphId":{let t=G(o.paragraph,e,a);if(!t.ok)return d(t.code,"that handle does not name a paragraph",t.detail);let i=a.story(t.value.story)?.paragraph(t.value.paragraphId);return I({kind:"text",text:i?.paraId??""})}case "search":{let t=W(o.scope,e,a);if(!t.ok)return d(t.code,"that is not a scope to search",t.detail);let n=at(o.scope,e,a);return n.ok?St(n.value,t.value,o.text,o.options):d(n.code,"that is not a scope to search",n.detail)}case "insertText":{let t=mt(o.at,e,a);if(!t.ok)return d(t.code,"that is not a place to insert at",t.detail);let n=a.story(t.value.story);return n?gt(u(n),t.value,o.text):d("invalid-handle","that story is not in this document")}case "replaceSpan":{if("body"in o.span){let i=$(o.span.body,"body",e,a);return i.ok?ne(u(i.value),o.text):d(i.code,"that handle does not name a body",i.detail)}let t=W(o.span,e,a);if(!t.ok)return d(t.code,"that span is not a place",t.detail);if(!t.value)return d("invalid-offset","that story holds no paragraph to write into","empty-story");let n=X(t.value);return n?Rt(u(n),t.value,o.text):d("invalid-handle","that story is not in this document")}case "insertParagraph":{let t=Et(o.anchor,e,a);if(!t.ok)return d(t.code,"that is not a paragraph to insert beside",t.detail);if(o.where!=="before"&&o.where!=="after")return d("unknown-operation","that is not a place to insert",String(o.where));let n=a.story(t.value.story);return n?N(u(n),t.value,o.where,o.text):d("invalid-handle","that story is not in this document")}case "splitParagraph":{let t=G(o.paragraph,e,a);if(!t.ok)return d(t.code,"that handle does not name a paragraph",t.detail);let n=a.story(t.value.story);return n?K(u(n),t.value,o.delimiters,o.trimDelimiters===true,o.trimSpacing===true):d("invalid-handle","that story is not in this document")}case "getFont":{let t=W(o.span,e,a);if(!t.ok)return d(t.code,"that span is not a place",t.detail);let n=at(o.span,e,a);return n.ok?I({kind:"font",font:Ue(n.value.part,Gt(t.value,n.value))}):d(n.code,"that span is not a place",n.detail)}case "setFont":{let t=W(o.span,e,a);if(!t.ok)return d(t.code,"that span is not a place",t.detail);if(!t.value)return d("invalid-offset","that story holds no paragraph to format","empty-story");let n=X(t.value);return n?yt(u(n),t.value,o.font):d("invalid-handle","that story is not in this document")}case "getStyle":{let t=W(o.span,e,a);if(!t.ok)return d(t.code,"that span is not a place",t.detail);let n=at(o.span,e,a);if(!n.ok)return d(n.code,"that span is not a place",n.detail);let i=n.value.part,c=n.value.styles(),p=et(t.value,n.value).map(v=>Ht(i,v,c)),y=p.length>0&&p.every(v=>v!==null&&v===p[0])?p[0]:null;return I({kind:"style",name:y})}case "setStyle":{let t=W(o.span,e,a);if(!t.ok)return d(t.code,"that span is not a place",t.detail);if(!t.value)return d("invalid-offset","that story holds no paragraph to style","empty-story");let n=X(t.value);return n?lt(u(n),t.value,o.name):d("invalid-handle","that story is not in this document")}case "getParagraphFormat":{let t=Et(o.paragraph,e,a);if(!t.ok)return d(t.code,"that is not a paragraph",t.detail);let n=a.story(t.value.story);if(!n)return d("document-unavailable","this host holds no document right now");let i=Xe(n.part,t.value.paragraphId,n.styles());return i?I({kind:"paragraphFormat",format:i}):d("invalid-handle","that handle does not name a paragraph")}case "setParagraphFormat":{let t=Et(o.paragraph,e,a);if(!t.ok)return d(t.code,"that is not a paragraph",t.detail);let n=a.story(t.value.story);return n?xn(u(n),t.value,o.format):d("invalid-handle","that story is not in this document")}case "deleteParagraph":{let t=G(o.paragraph,e,a);if(!t.ok)return d(t.code,"that handle does not name a paragraph",t.detail);let n=a.story(t.value.story);return n?nt(u(n),t.value):d("invalid-handle","that story is not in this document")}case "getSections":return e.resolve(o.document,"document")?I({kind:"handles",handles:a.sections().map(t=>e.section(t.index))}):d("invalid-handle","that handle does not name a document","document");case "getPageSetup":{let t=e.resolve(o.section,"section");if(!t||t.kind!=="section")return d("invalid-handle","that handle does not name a section","section");let n=a.sections()[t.index];return n?I({kind:"pageSetup",setup:n.pageSetup}):d("invalid-handle","that section is not in this document")}case "setPageSetup":{let t=e.resolve(o.section,"section");return !t||t.kind!=="section"?d("invalid-handle","that handle does not name a section","section"):Sn(t.index,o.setup)}case "getFurniture":{let t=e.resolve(o.section,"section");if(!t||t.kind!=="section")return d("invalid-handle","that handle does not name a section","section");if(o.kind!=="header"&&o.kind!=="footer")return d("unknown-operation","that is not furniture",String(o.kind));let n={kind:o.kind,sectionIndex:t.index,variant:o.variant};return Ke(n)?a.story(n)?I({kind:"handle",handle:e.body(n)}):d("invalid-handle","this document declares no such header or footer",_(n)):d("unknown-operation","that is not a furniture variant",String(o.variant))}case "getNotes":{if(!e.resolve(o.document,"document"))return d("invalid-handle","that handle does not name a document","document");if(o.noteKind!=="footnote"&&o.noteKind!=="endnote")return d("unknown-operation","that is not a kind of note",String(o.noteKind));let t=o.noteKind;return I({kind:"handles",handles:a.noteIds(t).map(n=>e.note(t,n))})}case "getNoteBody":{let t=e.resolve(o.note,"note");if(!t||t.kind!=="note")return d("invalid-handle","that handle does not name a note","note");let n={kind:"note",noteKind:t.noteKind,noteId:t.noteId};return a.story(n)?I({kind:"handle",handle:e.body(n)}):d("invalid-handle","that note is not in this document",_(n))}case "getNoteKind":{let t=e.resolve(o.note,"note");return !t||t.kind!=="note"?d("invalid-handle","that handle does not name a note","note"):I({kind:"text",text:t.noteKind})}case "deleteNote":{let t=e.resolve(o.note,"note");return !t||t.kind!=="note"?d("invalid-handle","that handle does not name a note","note"):a.noteIds(t.noteKind).includes(t.noteId)?Rn(t.noteKind,t.noteId):d("invalid-handle","that note is not in this document")}case "getLists":{let t=$(o.body,"body",e,a);return t.ok?I({kind:"handles",handles:_t(t.value).map(n=>e.list(n.numId,t.value.story))}):d(t.code,"that handle does not name a body",t.detail)}case "getListId":{let t=Ft(o.list);return "list"in t?I({kind:"number",value:Number(t.list.numId)}):t}case "getListById":{let t=$(o.body,"body",e,a);if(!t.ok)return d(t.code,"that handle does not name a body",t.detail);if(!Number.isInteger(o.id)||o.id<=0)return d("unsupported-content","a list is numbered from one",String(o.id));let n=String(o.id),i=_t(t.value).find(c=>c.numId===n);return i?I({kind:"handle",handle:e.list(i.numId,t.value.story)}):d("invalid-handle","no list in that story carries that number",n)}case "getListParagraphs":{let t=Ft(o.list);if(!("list"in t))return t;let n=o.level;if(n!==void 0&&(!Number.isInteger(n)||n<0||n>ft))return d("invalid-offset",`a list level is 0 to ${String(ft)}`,String(n));let i=t.plan.reads,c=n===void 0?t.list.paragraphIds:t.list.paragraphIds.filter(p=>It(i,p)?.level===n);return I({kind:"handles",handles:c.map(p=>e.paragraph(p,i.story))})}case "getParagraphList":{let t=G(o.paragraph,e,a);if(!t.ok)return d(t.code,"that handle does not name a paragraph",t.detail);let n=a.story(t.value.story);if(!n)return d("invalid-handle","that story is not in this document");let i=It(n,t.value.paragraphId);return i?I({kind:"handle",handle:e.list(i.numId,n.story)}):d("unsupported-content","that paragraph is not in a list",t.value.paragraphId)}case "getListLevel":{let t=G(o.paragraph,e,a);if(!t.ok)return d(t.code,"that handle does not name a paragraph",t.detail);let n=a.story(t.value.story);if(!n)return d("invalid-handle","that story is not in this document");let i=It(n,t.value.paragraphId);return i?I({kind:"number",value:i.level}):d("unsupported-content","that paragraph is not in a list",t.value.paragraphId)}case "setListLevel":{let t=G(o.paragraph,e,a);if(!t.ok)return d(t.code,"that handle does not name a paragraph",t.detail);let n=a.story(t.value.story);return n?Cn(u(n),t.value.paragraphId,o.level):d("invalid-handle","that story is not in this document")}case "insertListParagraph":{let t=Ft(o.list);return "list"in t?On(t.plan,t.list,o.where,o.text):t}case "getHyperlink":{let t=W(o.span,e,a);if(!t.ok)return d(t.code,"that span is not a place",t.detail);let n=at(o.span,e,a);if(!n.ok)return d(n.code,"that span is not a place",n.detail);let i=a.package;if(!i||!t.value)return I({kind:"text",text:""});let c=oe(n.value,t.value);if(!c)return I({kind:"text",text:""});let p=chunkUAOJHPQ4_cjs.Ea(n.value.part,c.id),y=p?rn(i,n.value.part.name,p):null;return I({kind:"text",text:y??""})}case "setHyperlink":{let t=W(o.span,e,a);if(!t.ok)return d(t.code,"that span is not a place",t.detail);if(!t.value)return d("invalid-offset","that story holds no text to link","empty-story");let n=X(t.value);return n?Pn(u(n),t.value,o.target):d("invalid-handle","that story is not in this document")}case "getBookmarks":{let t=W(o.scope,e,a);if(!t.ok)return d(t.code,"that span is not a place",t.detail);let n=at(o.scope,e,a);if(!n.ok)return d(n.code,"that span is not a place",n.detail);let i=n.value,c=t.value,p=c===null?null:new Set(et(c,i)),y=Zt(i).filter(v=>{if(!p||!p.has(v.start.paragraphId)&&!p.has(v.end.paragraphId)||c===null)return false;let x=v.start.paragraphId===c.end.paragraphId&&v.start.offset>c.end.offset,P=v.end.paragraphId===c.start.paragraphId&&v.end.offset<c.start.offset;return !x&&!P});return I({kind:"handles",handles:y.map(v=>e.bookmark(v.name,i.story))})}case "getBookmarkName":{let t=e.resolve(o.bookmark,"bookmark");return !t||t.kind!=="bookmark"?d("invalid-handle","that handle does not name a bookmark","bookmark"):I({kind:"text",text:t.name})}case "getBookmarkRange":{let t=e.resolve(o.bookmark,"bookmark");if(!t||t.kind!=="bookmark")return d("invalid-handle","that handle does not name a bookmark","bookmark");let n=a.story(t.story);if(!n)return d("invalid-handle","that story is not in this document");let i=qt(n,t.name);if(!i)return d("invalid-handle","this document no longer declares that bookmark",t.name);let c={story:n.story,paragraphId:i.start.paragraphId,index:n.indexOf(i.start.paragraphId),offset:i.start.offset},p={story:n.story,paragraphId:i.end.paragraphId,index:n.indexOf(i.end.paragraphId),offset:i.end.offset};return I({kind:"span",span:M({start:c,end:p})})}case "getComments":{let t=W(o.scope,e,a);if(!t.ok)return d(t.code,"that scope is not a place",t.detail);let n=at(o.scope,e,a);if(!n.ok)return d(n.code,"that scope names no story",n.detail);let i=n.value,c=g(i);if(!c)return d("document-unavailable","this host holds no document");let p=t.value,y=c.roots.filter(v=>{if(!p)return true;let x=v.range;if(!x)return false;let P=i.indexOf(x.start.paragraphId),w=i.indexOf(x.end.paragraphId),E=i.indexOf(p.start.paragraphId),C=i.indexOf(p.end.paragraphId);return w<E||P>C?false:w===E&&P===E&&C===E?x.end.offset>p.start.offset&&x.start.offset<p.end.offset:true});return I({kind:"handles",handles:y.map(v=>e.comment(v.id,i.story))})}case "getCommentReplies":{let t=R(o.comment);return t.ok?I({kind:"handles",handles:t.item.replyIds.map(n=>e.comment(n,t.reads.story))}):t.planned}case "getCommentId":{let t=R(o.comment);return t.ok?I({kind:"text",text:t.item.id}):t.planned}case "getCommentAuthor":{let t=R(o.comment);return t.ok?I({kind:"text",text:t.item.comment.author}):t.planned}case "getCommentDate":{let t=R(o.comment);return t.ok?I({kind:"text",text:t.item.comment.date??""}):t.planned}case "getCommentText":{let t=R(o.comment);if(!t.ok)return t.planned;let n=g(t.reads);return I({kind:"text",text:n?.textOf(t.item.id)??""})}case "getCommentRange":{let t=R(o.comment);if(!t.ok)return t.planned;let n=t.item.range;if(!n||t.item.orphaned)return d("invalid-handle","that comment has no range in this document");let i=T(t.reads,n);return i?I({kind:"span",span:i}):d("invalid-handle","that comment\u2019s range is no longer in the story")}case "getCommentResolved":{let t=R(o.comment);return t.ok?I({kind:"flag",value:t.item.resolved}):t.planned}case "setCommentResolved":{let t=R(o.comment);if(!t.ok)return t.planned;if(typeof o.resolved!="boolean")return d("unsupported-content","resolved is a yes or a no",String(o.resolved));let n=f(u(t.reads));return n||{ok:true,kind:"commentWrite",write:{kind:"resolve",commentId:t.item.id,resolved:o.resolved},story:t.reads.story,answer:()=>F}}case "replyToComment":{let t=R(o.comment);if(!t.ok)return t.planned;if(typeof o.author!="string"||o.author.trim().length===0)return d("unsupported-content","a comment records who wrote it","author");if(typeof o.text!="string"||o.text.length===0)return d("unsupported-content","a reply says something","text");if(xt.test(o.text))return d("unsupported-content","a reply is one paragraph in this slice","text");let n=t.item.range;if(!n||t.item.orphaned)return d("invalid-handle","that comment has no range to reply over");let i=f(u(t.reads));if(i)return i;let c=t.reads.story;return {ok:true,kind:"commentWrite",write:{kind:"reply",parentCommentId:t.item.id,anchor:{paragraphId:n.start.paragraphId,start:n.start.offset,end:n.end.offset,...n.end.paragraphId===n.start.paragraphId?{}:{endParagraphId:n.end.paragraphId}},text:o.text,author:o.author,...typeof o.date=="string"?{date:o.date}:{}},story:t.reads.story,answer:(p,y)=>y===void 0?F:{kind:"handle",handle:e.comment(y,c)}}}case "getRevisions":{let t=$(o.body,"body",e,a);if(!t.ok)return d(t.code,"that handle does not name a body",t.detail);let n=t.value;return I({kind:"handles",handles:te(n).map(i=>e.revision(i.id,n.story))})}case "getRevisionType":{let t=A(o.revision);return t.ok?I({kind:"text",text:t.item.type}):t.planned}case "getRevisionAuthor":{let t=A(o.revision);return t.ok?I({kind:"text",text:t.item.author}):t.planned}case "getRevisionDate":{let t=A(o.revision);return t.ok?I({kind:"text",text:t.item.date}):t.planned}case "getRevisionRange":{let t=A(o.revision);if(!t.ok)return t.planned;let[n]=t.item.item.ranges;if(!n)return d("invalid-handle","that change covers no characters");let i=T(t.reads,n);return i?I({kind:"span",span:i}):d("invalid-handle","that change\u2019s range is no longer in the story")}case "acceptRevision":case "rejectRevision":{let t=A(o.revision);if(!t.ok)return t.planned;let n=u(t.reads),i=f(n);if(i)return i;let c=o.op==="acceptRevision";return {ok:true,kind:"command",story:t.reads.story,ops:t.item.item.addresses.map(p=>c?{op:"acceptRevision",revision:p}:{op:"rejectRevision",revision:p}),answer:()=>F}}case "acceptAllRevisions":case "rejectAllRevisions":{if(!e.resolve(o.document,"document"))return d("invalid-handle","that handle does not name a document","document");let t=a.body;if(!t)return d("document-unavailable","this host holds no document");let n=u(t),i=f(n);return i||{ok:true,kind:"command",story:t.story,ops:[o.op==="acceptAllRevisions"?{op:"acceptAllRevisions"}:{op:"rejectAllRevisions"}],answer:()=>F}}case "selectSpan":{let t=W(o.span,e,a);if(!t.ok)return d(t.code,"that span is not a place",t.detail);if(!t.value)return d("invalid-offset","that story holds no paragraph to select","empty-story");let n=X(t.value);return n?wn(u(n),t.value,o.mode):d("invalid-handle","that story is not in this document")}case "getContentControls":{let t=Bt(o.scope);return "reads"in t?I({kind:"handles",handles:ln(t.reads,t.node).map(n=>e.contentControl(n.nodeId,t.reads.story))}):t}case "getContentControlById":{let t=Bt(o.scope);if(!("reads"in t))return t;if(!Number.isInteger(o.id))return d("unsupported-content","a control id is a whole number",String(o.id));let n=bn(t.node).find(i=>chunkUAOJHPQ4_cjs.me(i).id===o.id);return n?I({kind:"handle",handle:e.contentControl(n.id,t.reads.story)}):d("invalid-handle","no control in that scope carries that id",String(o.id))}case "getContentControlsByTag":case "getContentControlsByTitle":{let t=Bt(o.scope);if(!("reads"in t))return t;let n=o.op==="getContentControlsByTag"?o.tag:o.title;if(typeof n!="string"||n.length===0)return d("unsupported-content","a tag or title to match is required",o.op);let i=bn(t.node).filter(c=>{let p=chunkUAOJHPQ4_cjs.me(c);return o.op==="getContentControlsByTag"?p.tag===n:p.alias===n});return I({kind:"handles",handles:i.map(c=>e.contentControl(c.id,t.reads.story))})}case "getContentControlTag":case "getContentControlTitle":case "getContentControlFileId":case "getContentControlSubtype":case "getContentControlLock":{let t=Z(o.contentControl);if(!("control"in t))return t;let n=t.control.properties;if(o.op==="getContentControlLock")return I({kind:"text",text:t.control.lock});if(o.op==="getContentControlSubtype")return I({kind:"text",text:n.type});if(o.op==="getContentControlFileId")return I({kind:"text",text:n.id===void 0?"":String(n.id)});let i=o.op==="getContentControlTag"?n.tag:n.alias;return I({kind:"text",text:i??""})}case "getContentControlPlaceholderShown":case "getContentControlTemporary":{let t=Z(o.contentControl);return "control"in t?I({kind:"flag",value:o.op==="getContentControlPlaceholderShown"?t.control.properties.showingPlaceholder:t.control.properties.temporary}):t}case "getContentControlText":{let t=Z(o.contentControl);return "control"in t?I({kind:"text",text:pn(t.node)}):t}case "getContentControlParagraphs":{let t=Z(o.contentControl);return "control"in t?I({kind:"handles",handles:t.control.paragraphIds.map(n=>e.paragraph(n,t.reads.story))}):t}case "getContentControlRange":{let t=Z(o.contentControl);if(!("control"in t))return t;let n=o.location??"whole";if(!Oo.has(n))return d("unsupported-content","that is not a place in a control",n);let i=ee(t.reads,t.node);if(!i)return d("unsupported-content","that control holds nothing addressable","empty");let c=n==="start"||n==="before"?i.start:i.end,p=n!=="whole"&&n!=="content",y=v=>({story:t.reads.story,paragraphId:v.paragraphId,index:t.reads.indexOf(v.paragraphId),offset:v.offset});return I({kind:"span",span:Jt(p?{start:y(c),end:y(c)}:{start:y(i.start),end:y(i.end)},e)})}case "setContentControlValue":{let t=Z(o.contentControl);if(!("control"in t))return t;let n=To(o.value);if(!n.ok)return d(n.code,n.message,n.detail);let i=u(t.reads),c=f(i);return c||{ok:true,kind:"command",story:t.reads.story,ops:[{op:"setContentControlValue",controlId:t.control.nodeId,value:n.value}],answer:()=>F}}case "setContentControlProperties":{let t=Z(o.contentControl);if(!("control"in t))return t;if(o.tag===void 0&&o.title===void 0&&o.lock===void 0)return d("unsupported-content","nothing to write","no-properties");if(o.lock!==void 0&&!Co.has(o.lock))return d("unsupported-content","that is not a lock this schema declares",o.lock);let n=u(t.reads),i=f(n);return i||{ok:true,kind:"command",story:t.reads.story,ops:[{op:"setContentControlProperties",controlId:t.control.nodeId,...o.tag===void 0?{}:{tag:o.tag},...o.title===void 0?{}:{alias:o.title},...o.lock===void 0?{}:{lock:o.lock}}],answer:()=>F}}case "insertContentControlText":{let t=Z(o.contentControl);if(!("control"in t))return t;if(typeof o.text!="string")return d("unsupported-content","text is required","text");if(o.at!=="replace"&&o.at!=="start"&&o.at!=="end")return d("unsupported-content","that is not a place to insert at",String(o.at));let n=u(t.reads),i=f(n);if(i)return i;let c=ee(t.reads,t.node);if(!c)return d("unsupported-content","that control holds nothing addressable","empty");let p=o.at==="end"?c.end:c.start,y=()=>({kind:"span",span:M({start:{story:t.reads.story,paragraphId:p.paragraphId,index:t.reads.indexOf(p.paragraphId),offset:p.offset},end:{story:t.reads.story,paragraphId:p.paragraphId,index:t.reads.indexOf(p.paragraphId),offset:p.offset+o.text.length}})});return o.at==="replace"?{ok:true,kind:"command",story:t.reads.story,ops:[{op:"setContentControlValue",controlId:t.control.nodeId,value:{kind:"text",text:o.text}}],answer:y}:{ok:true,kind:"command",story:t.reads.story,ops:o.text.length===0?[]:[{op:"insertText",paragraphId:p.paragraphId,offset:p.offset,text:o.text,inside:t.node.id}],answer:y}}case "deleteContentControl":{let t=Z(o.contentControl);if(!("control"in t))return t;if(typeof o.keepContent!="boolean")return d("unsupported-content","keepContent is required","keepContent");let n=u(t.reads),i=f(n);return i||{ok:true,kind:"command",story:t.reads.story,ops:[{op:"removeContentControl",controlId:t.control.nodeId,keepContent:o.keepContent}],answer:()=>F}}case "insertContentControl":{let t=W(o.span,e,a);if(!t.ok)return d(t.code,"that span is not a place",t.detail);if(!t.value)return d("invalid-offset","that story holds nothing to wrap","empty-story");let n=X(t.value);if(!n)return d("invalid-handle","that story is not in this document");let i=t.value;if(i.start.paragraphId!==i.end.paragraphId)return d("unsupported-content","wrapping several paragraphs in one control is not supported here","multi-paragraph");if(!Po.has(o.subtype))return d("unsupported-content","that control type cannot be inserted",o.subtype);let c=u(n),p=f(c);return p||{ok:true,kind:"command",story:n.story,ops:[{op:"insertContentControl",paragraphId:i.start.paragraphId,start:i.start.offset,end:i.end.offset,type:o.subtype,...o.tag===void 0?{}:{tag:o.tag},...o.title===void 0?{}:{alias:o.title}}],answer:()=>F}}case "insertCustomNode":{let t=hn(o);if(t)return d("unsupported-content",t.message,t.detail);let n=yn(o.payload);if(!n.ok)return d("unsupported-content","that payload cannot be written",n.field);let i=An(o,e,a);if("code"in i)return d(i.code,i.message,i.detail);let{start:c,end:p}=i.range,y=X(i.range);if(!y)return d("invalid-handle","that story is not in this document");let v=f(u(y));return v||{ok:true,kind:"customNodeWrite",story:y.story,write:kn(o,c,p,n.value),answer:()=>F}}default:return d("unknown-operation","this host does not implement that operation",String(o.op))}};return {plan(o){let t=We(o);if(t&&b||m&&$t(o))return d("conflicting-operations","that command commits on its own and cannot share a batch",o.op);let n=Tn(o);return n.ok&&$t(o)&&(b=true,t&&(m=true)),n},get hasCommands(){return b},get writeScope(){return k?.reads.scope??null},settle(o){let t=k;if(t){let n=o.story(t.reads.story);if(!n)return {ok:false,detail:`the story this batch wrote is gone: ${_(t.reads.story)}`};let i=new Set(t.reads.paragraphIds),c=n.paragraphIds.filter(y=>!i.has(y));if(c.length!==t.created.length)return {ok:false,detail:`planned ${String(t.created.length)} new paragraphs, the transaction made ${String(c.length)}`};t.order.filter(y=>y.id===null).forEach((y,v)=>{y.id=c[v]??null;});for(let y of t.retargets)y.slot.id&&e.retarget(y.from,y.slot.id);}for(let n of h){let i=o.story(n.range.start.story);!i||!Lo(n.range,i)||r.select?.(n.range,n.mode);}return {ok:true}}}}var Eo=Object.freeze({status:"skipped"});function Y(r,e,s){return Object.freeze(s===void 0?{code:r,message:e}:{code:r,message:e,detail:s})}function J(r,e,s,a){return {ok:false,results:r.map((l,u)=>u===e?{status:"error",error:s}:Eo),revision:a,changed:false}}function oa(r){let{port:e}=r,s=Object.freeze({...r.capabilities}),a=ze(),l=new Set,u=false,h=null,b=s.events?e.subscribe(()=>{if(u)return;let f=Object.freeze({revision:e.revision()});for(let g of [...l])g(f);}):()=>{},m=f=>{if(h&&h.pkg===f)return h.value;let g=tn(f);return h={pkg:f,value:g},g};return {capabilities:s,revision:()=>e.revision(),execute:f=>{let g=Array.isArray(f?.operations)?f.operations:[],R=e.revision();if(u)return J(g,0,Y("disposed","this host was disposed"),R);if(!s.document)return J(g,0,Y("unsupported-capability","this host has no document","document"),R);let A=e.currentPackage();if(!A)return J(g,0,Y("document-unavailable","this host holds no document right now"),R);if(f.expectedRevision!==void 0&&f.expectedRevision!==R)return J(g,0,Y("stale-revision","the document moved since that revision",`expected ${String(f.expectedRevision)}, at ${R}`),R);let T=In({handles:a,reads:m(A),capabilities:s,...e.select?{select:e.select.bind(e)}:{}}),O=[],H=[],L=null,j=null,Q,dt=null,M=-1;for(let N=0;N<g.length;N+=1){let K=T.plan(g[N]);if(!K.ok)return J(g,N,K.error,R);if(O.push(K),K.kind==="command")if(M<0&&(M=N),K.lifecycle)L=K.ops[0]??null;else if(K.relate){let nt=K.relate;H.push(yt=>{let lt=yt(nt.url);return lt===null?null:nt.ops(lt)});}else {let{ops:nt}=K;H.push(()=>nt);}else K.kind==="commentWrite"?(M<0&&(M=N),j={write:K.write,scope:T.writeScope??{kind:"body"}}):K.kind==="customNodeWrite"&&(M<0&&(M=N),dt={write:K.write,scope:T.writeScope??{kind:"body"}});}let X=false;if(j){let N=e.applyCommentWrite(j.write,j.scope);if(!N.ok)return J(g,M<0?0:M,Y("transaction-refused","the document store refused the comment write",N.reason),R);X=N.changed,Q=N.commentId;}if(dt){let N=e.applyCustomNodeWrite(dt.write,dt.scope);if(!N.ok)return J(g,M<0?0:M,Y("transaction-refused","the document store refused the custom-node write",N.reason),R);X=N.changed;}if(L){let N=e.applyLifecycle(L);if(!N.ok)return J(g,M<0?0:M,Y("transaction-refused","the document store refused the transaction",N.reason),R);X=N.changed;}if(H.length>0){let N=e.apply(K=>{let nt=[];for(let yt of H){let lt=yt(K);if(lt===null)return null;nt.push(...lt);}return nt},T.writeScope??{kind:"body"});if(!N.ok)return J(g,M<0?0:M,Y("transaction-refused","the document store refused the transaction",N.reason),R);X=N.changed;}let St=e.currentPackage();if(!St)return J(g,0,Y("document-unavailable","this host holds no document right now"),R);let gt=m(St),Rt=T.settle(gt);return Rt.ok?{ok:true,results:O.map(N=>({status:"ok",value:N.kind==="query"?N.value:N.kind==="customNodeWrite"?N.answer(gt):N.answer(gt,Q)})),revision:e.revision(),changed:X}:J(g,M<0?0:M,Y("transaction-refused","the transaction did not produce the document the batch planned",Rt.detail),e.revision())},save(){if(u)return {ok:false,error:Y("disposed","this host was disposed")};if(!s.save)return {ok:false,error:Y("unsupported-capability","this host cannot save","save")};let f=e.save();return f?{ok:true,bytes:f}:{ok:false,error:Y("document-unavailable","this host holds no document right now")}},subscribe(f){return u||!s.events?()=>{}:(l.add(f),()=>{l.delete(f);})},dispose(){u||(u=true,l.clear(),b(),e.dispose(),h=null);}}}exports.a=Nt;exports.b=Fo;exports.c=Mn;exports.d=En;exports.e=We;exports.f=$t;exports.g=oa;
|
|
1
|
+
'use strict';var chunkQIFQTG57_cjs=require('./chunk-QIFQTG57.cjs');var Nt=Object.freeze(["default","first","even"]),it=Object.freeze({kind:"body"});function _(r){switch(r.kind){case "body":return "body";case "note":return `note:${r.noteKind}:${String(r.noteId)}`;default:return `${r.kind}:${String(r.sectionIndex)}:${r.variant}`}}function Ke(r){if(typeof r!="object"||r===null)return false;let e=r;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&&Nt.includes(e.variant)}var Fo=["getDocument","getBody","getParagraphs","getSpanParagraphs","getText","getSpanText","getParagraphId","search","getFont","getParagraphFormat","getStyle","getSections","getPageSetup","getFurniture","getNotes","getNoteBody","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","getContentControlPlaceholderShown","getContentControlTemporary","getContentControlText","getContentControlParagraphs","getContentControlRange"],Mn=["insertText","replaceSpan","insertParagraph","splitParagraph","deleteParagraph","selectSpan","setFont","setParagraphFormat","setStyle","setPageSetup","deleteNote","setListLevel","insertListParagraph","setHyperlink","setCommentResolved","replyToComment","acceptRevision","rejectRevision","acceptAllRevisions","rejectAllRevisions","setContentControlValue","setContentControlProperties","deleteContentControl","insertContentControlText","insertContentControl","insertCustomNode"],En=["deleteNote","setCommentResolved","replyToComment","insertCustomNode"],_n=new Set(En);function We(r){return _n.has(r.op)}var Fn=new Set(Mn);function $t(r){return Fn.has(r.op)}function Bn(){let r=globalThis.crypto,e=r?.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 s=e.call(r,new Uint8Array(16)),a="";for(let l of s)a+=l.toString(16).padStart(2,"0");return a}function jn(r){return typeof r=="object"&&r!==null&&"kind"in r&&"ref"in r}function ze(){let r=new Map,e=new Map,s=new Map,a=new Map,l=Bn(),u=null,h=(m,k)=>{let f=(a.get(m)??0)+1;a.set(m,f);let g=`${m}:${l}:${String(f)}`;return r.set(g,k),Object.freeze({kind:m,ref:g})},b=(m,k,f)=>{let g=`${m}\0${k}`,R=s.get(g);if(R)return Object.freeze({kind:m,ref:R});let A=h(m,f);return s.set(g,A.ref),A};return {document(){return u??=h("document",{kind:"document"}),u},body(m){return b("body",_(m),{kind:"body",story:m})},paragraph(m,k){let f=e.get(m);if(f)return Object.freeze({kind:"paragraph",ref:f});let g=h("paragraph",{kind:"paragraph",paragraphId:m,story:k});return e.set(m,g.ref),g},section(m){return b("section",String(m),{kind:"section",index:m})},note(m,k){return b("note",`${m}:${String(k)}`,{kind:"note",noteKind:m,noteId:k})},comment(m,k){return b("comment",`${_(k)}\0${m}`,{kind:"comment",commentId:m,story:k})},revision(m,k){return b("revision",`${_(k)}\0${m}`,{kind:"revision",revisionId:m,story:k})},bookmark(m,k){return b("bookmark",`${_(k)}\0${m}`,{kind:"bookmark",name:m,story:k})},list(m,k){return b("list",`${_(k)}\0${m}`,{kind:"list",numId:m,story:k})},contentControl(m,k){return b("contentControl",`${_(k)}\0${m}`,{kind:"contentControl",nodeId:m,story:k})},retarget(m,k){let f=e.get(m);if(!f||m===k)return;let g=r.get(f);!g||g.kind!=="paragraph"||(e.delete(m),r.set(f,{kind:"paragraph",paragraphId:k,story:g.story}),e.has(k)||e.set(k,f));},resolve(m,k){if(!jn(m)||m.kind!==k||typeof m.ref!="string")return null;let f=r.get(m.ref);return !f||f.kind!==k?null:f}}}var Kn=255,Wn=Object.freeze({nameOf:()=>null,idOf:()=>null,defaultId:null,present:false});function De(r){let e=chunkQIFQTG57_cjs.Gc(r);if(!e)return Wn;let s=new Map,a=new Map,l=null;for(let u of chunkQIFQTG57_cjs.Fc(e).values())if(u.type==="paragraph"){if(s.set(u.styleId,u.name),u.name!==null){let h=u.name.trim().toLowerCase();a.has(h)||a.set(h,u.styleId);}u.isDefault&&l===null&&(l=u.styleId);}return Object.freeze({nameOf:u=>s.get(u)??null,idOf:u=>a.get(u.trim().toLowerCase())??null,defaultId:l,present:true})}function Ht(r,e,s){let a=chunkQIFQTG57_cjs.Ea(r,e);if(!a||a.kind!=="paragraph")return null;let l=zn(chunkQIFQTG57_cjs.Ld(chunkQIFQTG57_cjs.Jd(a),"pStyle"));return l!==null?s.nameOf(l):s.defaultId===null?null:s.nameOf(s.defaultId)}function zn(r){if(!r)return null;for(let e of r.attributes)if(e.localName==="val")return e.value;return null}function Lt(r,e){if(typeof r!="string"||r.trim().length===0)return {ok:false,detail:"style: not a name"};if(r.length>Kn)return {ok:false,detail:"style: name too long"};if(!chunkQIFQTG57_cjs.W(r))return {ok:false,detail:"style: not valid XML text"};if(!e.present)return {ok:false,detail:"style: this document defines no styles"};let s=e.idOf(r);return s===null?{ok:false,detail:"style: this document defines no paragraph style with that name"}:{ok:true,styleId:s}}var $e=20,Dn=31680,Vn=1999,$n=Object.freeze({bold:null,italic:null,name:null,size:null,color:null});function U(r,e){if(!r)return null;for(let s of r.attributes)if(s.localName===e)return s.value;return null}function Ut(r){if(!r)return null;let e=U(r,"val");if(e===null)return true;let s=e.trim().toLowerCase();return !(s==="0"||s==="false"||s==="off"||s==="none")}function Un(r){if(r===null)return null;let e=r.trim();return /^[0-9a-fA-F]{6}$/.test(e)?`#${e.toUpperCase()}`:null}function Xn(r){if(r===null)return null;let e=Number(r.trim());return !Number.isFinite(e)||e<=0?null:e/2}function ct(r){if(r===null)return null;let e=Number(r.trim());return Number.isFinite(e)?e/$e:null}function bt(r){if(r.length===0)return null;let e=r[0];if(e===null)return null;for(let s of r)if(s!==e)return null;return e}function Ue(r,e){let s=[];for(let a of e)for(let l of chunkQIFQTG57_cjs._f(r,a.paragraphId,a.start,a.end))s.push(chunkQIFQTG57_cjs.Kd(l));return s.length===0?$n:{bold:bt(s.map(a=>Ut(chunkQIFQTG57_cjs.Ld(a,"b")))),italic:bt(s.map(a=>Ut(chunkQIFQTG57_cjs.Ld(a,"i")))),name:bt(s.map(a=>{let l=chunkQIFQTG57_cjs.Ld(a,"rFonts"),u=U(l,"ascii");return u===null||u.length===0?null:u})),size:bt(s.map(a=>Xn(U(chunkQIFQTG57_cjs.Ld(a,"sz"),"val")))),color:bt(s.map(a=>Un(U(chunkQIFQTG57_cjs.Ld(a,"color"),"val"))))}}var Yn=Object.freeze({left:"Left",start:"Left",center:"Centered",right:"Right",end:"Right",both:"Justified",distribute:"Justified"}),Gn=Object.freeze({Left:"left",Centered:"center",Right:"right",Justified:"both"});function Jn(r){let e=U(chunkQIFQTG57_cjs.Ld(r,"jc"),"val");return e===null?"Unknown":Yn[e.trim().toLowerCase()]??"Unknown"}function Xe(r,e,s){let a=chunkQIFQTG57_cjs.Ea(r,e);if(!a||a.kind!=="paragraph")return null;let l=chunkQIFQTG57_cjs.Jd(a),u=chunkQIFQTG57_cjs.Ld(l,"spacing"),h=chunkQIFQTG57_cjs.Ld(l,"ind");return {alignment:Jn(l),style:Ht(r,e,s),firstLineIndent:Qn(h),leftIndent:ct(U(h,"left")??U(h,"start")),rightIndent:ct(U(h,"right")??U(h,"end")),lineSpacing:ct(U(u,"line")),spaceBefore:ct(U(u,"before")),spaceAfter:ct(U(u,"after")),widowControl:Ut(chunkQIFQTG57_cjs.Ld(l,"widowControl"))}}function Qn(r){let e=ct(U(r,"firstLine"));if(e!==null)return e;let s=ct(U(r,"hanging"));return s===null?null:-s}function Mt(r,e){if(typeof r!="number"||!Number.isFinite(r))return {ok:false,detail:`${e}: not a measurement`};let s=Math.round(r*$e);return Math.abs(s)>Dn?{ok:false,detail:`${e}: out of range`}:{ok:true,value:s}}function Ye(r){let e=[];if(r.bold!==void 0){if(typeof r.bold!="boolean")return {ok:false,detail:"bold: not a boolean"};e.push({localName:"b",...r.bold?{}:{attributes:{val:"0"}}});}if(r.italic!==void 0){if(typeof r.italic!="boolean")return {ok:false,detail:"italic: not a boolean"};e.push({localName:"i",...r.italic?{}:{attributes:{val:"0"}}});}if(r.name!==void 0){let s=r.name;if(typeof s!="string"||s.length===0||s.length>128)return {ok:false,detail:"name: not a font name"};if(!chunkQIFQTG57_cjs.W(s))return {ok:false,detail:"name: not valid XML text"};e.push({localName:"rFonts",attributes:{ascii:s,hAnsi:s,cs:s}});}if(r.size!==void 0){let s=r.size;if(typeof s!="number"||!Number.isFinite(s)||s<=0)return {ok:false,detail:"size: not a positive number of points"};let a=Math.round(s*2);if(a<1||a>Vn)return {ok:false,detail:"size: out of range"};e.push({localName:"sz",attributes:{val:String(a)}}),e.push({localName:"szCs",attributes:{val:String(a)}});}if(r.color!==void 0){let s=r.color;if(typeof s!="string"||!/^#[0-9a-fA-F]{6}$/.test(s.trim()))return {ok:false,detail:"color: not a #RRGGBB triplet"};e.push({localName:"color",attributes:{val:s.trim().slice(1).toUpperCase()}});}return e.length===0?{ok:false,detail:"no formatting was asked for"}:{ok:true,value:e}}function Ge(r,e,s,a){let l=chunkQIFQTG57_cjs.Ea(r,e);if(!l||l.kind!=="paragraph")return {ok:false,detail:"not a paragraph"};let u=chunkQIFQTG57_cjs.Jd(l),h=[];if(s.style!==void 0){let A=Lt(s.style,a);if(!A.ok)return {ok:false,detail:A.detail};h.push({localName:"pStyle",attributes:{val:A.styleId}});}if(s.alignment!==void 0){let A=Gn[s.alignment];if(A===void 0)return {ok:false,detail:`alignment: ${String(s.alignment)}`};h.push({localName:"jc",attributes:{val:A}});}let b=chunkQIFQTG57_cjs.Ld(u,"ind"),m=Ve(b),k=false;if(s.firstLineIndent!==void 0){let A=Mt(s.firstLineIndent,"firstLineIndent");if(!A.ok)return A;delete m.firstLine,delete m.hanging,A.value<0?m.hanging=String(-A.value):m.firstLine=String(A.value),k=true;}for(let[A,T,O]of [["leftIndent","left","start"],["rightIndent","right","end"]]){let H=s[A];if(H===void 0)continue;let L=Mt(H,A);if(!L.ok)return L;delete m[O],m[T]=String(L.value),k=true;}k&&h.push({localName:"ind",attributes:m});let f=chunkQIFQTG57_cjs.Ld(u,"spacing"),g=Ve(f),R=false;for(let[A,T]of [["spaceBefore","before"],["spaceAfter","after"]]){let O=s[A];if(O===void 0)continue;let H=Mt(O,A);if(!H.ok)return H;if(H.value<0)return {ok:false,detail:`${A}: out of range`};g[T]=String(H.value),R=true;}if(s.lineSpacing!==void 0){let A=Mt(s.lineSpacing,"lineSpacing");if(!A.ok)return A;if(A.value<=0)return {ok:false,detail:"lineSpacing: out of range"};g.line=String(A.value),g.lineRule??="auto",R=true;}if(R&&h.push({localName:"spacing",attributes:g}),s.widowControl!==void 0){if(typeof s.widowControl!="boolean")return {ok:false,detail:"widowControl: not a boolean"};h.push({localName:"widowControl",...s.widowControl?{}:{attributes:{val:"0"}}});}return h.length===0?{ok:false,detail:"no formatting was asked for"}:{ok:true,value:chunkQIFQTG57_cjs.Wf(chunkQIFQTG57_cjs.Uf(r,e),h)}}function Ve(r){let e=Object.create(null);if(!r)return e;for(let s of r.attributes)e[s.localName]=s.value;return e}var Je=20,Zn=63360;function rt(r){return Math.round(r/Je*100)/100}function qn(r,e){if(typeof r!="number"||!Number.isFinite(r))return null;let s=Math.round(r*Je);return s>Zn||s<0||s===0&&!e?null:s}var to=[["pageWidth","pageWidthTwips",false],["pageHeight","pageHeightTwips",false],["topMargin","marginTopTwips",true],["rightMargin","marginRightTwips",true],["bottomMargin","marginBottomTwips",true],["leftMargin","marginLeftTwips",true]];function Qe(r){if(typeof r!="object"||r===null)return {ok:false,reason:"that is not a page setup",detail:"not-an-object"};let e=r,s={},a=0;for(let[u,h,b]of to){let m=e[u];if(m===void 0)continue;let k=qn(m,b);if(k===null)return {ok:false,reason:`that is not a value for ${u}`,detail:String(m)};s[h]=k,a+=1;}let l=e.orientation;if(l!==void 0){if(l!=="portrait"&&l!=="landscape")return {ok:false,reason:"that is not an orientation",detail:String(l)};s.orientation=l,a+=1;}return a===0?{ok:false,reason:"that page setup names nothing to write",detail:"empty"}:{ok:true,value:s}}function eo(r){let e=chunkQIFQTG57_cjs.gf(r),s=e.widthTwips>e.heightTwips?"landscape":"portrait";return Object.freeze({pageWidth:rt(e.widthTwips),pageHeight:rt(e.heightTwips),orientation:s,topMargin:rt(e.topTwips),rightMargin:rt(e.rightTwips),bottomMargin:rt(e.bottomTwips),leftMargin:rt(e.leftTwips),headerDistance:rt(e.headerTwips),footerDistance:rt(e.footerTwips),gutter:rt(e.gutterTwips)})}function no(r,e){if(!e)return null;let s=null,a=(l,u,h)=>{if(s!==null||l.kind==="textValue"||h>64)return;let b=l.kind==="paragraph"?l.id:u;if(l.id===e.id){s=b;return}for(let m of l.children)a(m,b,h+1);};return a(r.root,null,0),s}function Ze(r,e,s){let a=chunkQIFQTG57_cjs.Rb(e.root);return Object.freeze(a.map((l,u)=>{let h=s[u];return Object.freeze({index:u,markParagraphId:no(e,l),pageSetup:eo(l),titlePage:h?.titlePage??false,evenAndOddHeaders:h?.evenAndOddHeaders??false})}))}var Yt="\r",oo=Object.freeze({nameOf:()=>null,idOf:()=>null,defaultId:null,present:false}),ro=Object.freeze([]),ao=Object.freeze([]),qe=Object.freeze([]),so=Object.freeze({package:null,body:null,story:()=>null,storyOf:()=>null,sections:()=>ao,furniture:()=>qe,noteIds:()=>Object.freeze([]),styles:()=>oo});function io(r){return r.kind==="textValue"?ro:Object.freeze(r.children.filter(e=>e.kind!=="textValue").map(e=>{let s=[];chunkQIFQTG57_cjs.Be([e],s,0);let a=e.kind==="paragraph"?"paragraph":e.kind==="table"?"table":"other",l=e.kind==="paragraph"&&chunkQIFQTG57_cjs.Ld(chunkQIFQTG57_cjs.Jd(e),"sectPr")!==void 0;return Object.freeze({id:e.id,kind:a,paragraphIds:Object.freeze(s.map(u=>u.id)),removable:a!=="other"&&!l})}))}function Xt(r,e,s,a,l){let u=chunkQIFQTG57_cjs.Ae(a),h=Object.freeze(u.map(g=>g.id)),b=new Map,m=new Map;u.forEach((g,R)=>{b.set(g.id,R),m.set(g.id,g);});let k=new Map,f=g=>{if(!b.has(g))return null;let R=k.get(g);if(R!==void 0)return R;let A=chunkQIFQTG57_cjs.xf(e,g)??"";return k.set(g,A),A};return {story:r,part:e,root:a,scope:s,paragraphIds:h,blocks:io(a),has:g=>b.has(g),indexOf:g=>b.get(g)??-1,paragraph(g){let R=m.get(g);return R?{nodeId:g,paraId:chunkQIFQTG57_cjs.Jc(R),text:f(g)??""}:null},node:g=>m.get(g)??null,paragraphText:f,text:()=>h.map(g=>f(g)??"").join(Yt),styles:l}}function tn(r){let e=r.parts.get(r.mainDocumentPart);if(!e)return so;let s,a=()=>s??=De(r),l,u=()=>l??=chunkQIFQTG57_cjs.Sb(r),h,b=new Map,m=A=>{let T=u()[A.sectionIndex];return T?(A.kind==="header"?T.headers:T.footers).get(A.variant)??null:null},k=A=>{if(A.kind==="body"){let O=chunkQIFQTG57_cjs.ze(e);return O?Xt(A,e,{kind:"body"},O,a):null}if(A.kind==="note"){let O=chunkQIFQTG57_cjs.Td(r,A.noteKind);if(!O)return null;let H=chunkQIFQTG57_cjs.vd(O.root,A.noteId);return !H||!chunkQIFQTG57_cjs.ld(H)?null:Xt(A,O,{kind:"notesPart",noteKind:A.noteKind},H,a)}let T=m(A);return T?Xt(A,T.part,{kind:"headerFooter",rId:T.rId},T.part.root,a):null},f=A=>{let T=_(A);if(b.has(T))return b.get(T)??null;let O=k(A);return b.set(T,O),O},g=A=>{if(f(it)?.has(A))return it;for(let[O]of u().entries())for(let H of ["header","footer"])for(let L of Nt){let j={kind:H,sectionIndex:O,variant:L};if(f(j)?.has(A))return j}for(let O of ["footnote","endnote"])for(let H of R(O)){let L={kind:"note",noteKind:O,noteId:H};if(f(L)?.has(A))return L}return null},R=A=>{let T=chunkQIFQTG57_cjs.Td(r,A);if(!T)return lo;let O=[];for(let H of chunkQIFQTG57_cjs.ud(T.root)){if(!chunkQIFQTG57_cjs.ld(H))continue;let L=chunkQIFQTG57_cjs.jd(H);L!==null&&O.push(L);}return Object.freeze(O)};return {package:r,get body(){return f(it)},story:f,storyOf:g,sections:()=>h??=Ze(r,e,u()),furniture(A){let T=u()[A];if(!T)return qe;let O=[];for(let H of ["header","footer"]){let L=H==="header"?T.headers:T.footers;for(let j of Nt){let Q=L.get(j);Q&&O.push(Object.freeze({kind:H,variant:j,declared:!Q.inherited}));}}return Object.freeze(O)},noteIds:R,styles:a}}var lo=Object.freeze([]);function q(r,e){return {ok:false,code:r,detail:e}}function tt(r){return {ok:true,value:r}}function $(r,e,s,a){let l=s.resolve(r,e);if(!l||l.kind!=="body"&&l.kind!=="paragraph")return q("invalid-handle",`not-a-${e}-handle`);let u=a.story(l.story);return u?tt(u):q("invalid-handle",`no-such-story:${_(l.story)}`)}function G(r,e,s){let a=e.resolve(r,"paragraph");if(!a||a.kind!=="paragraph")return q("invalid-handle","not-a-paragraph-handle");let l=s.story(a.story);if(!l)return q("invalid-handle",`no-such-story:${_(a.story)}`);let u=l.indexOf(a.paragraphId);return u<0?q("invalid-handle","paragraph-not-in-body"):tt({story:a.story,paragraphId:a.paragraphId,index:u,offset:0})}function uo(r,e,s){let a=G(r.paragraph,e,s);if(!a.ok)return a;let u=(s.story(a.value.story)?.paragraphText(a.value.paragraphId)??"").length,{offset:h}=r;return !Number.isInteger(h)||h<0||h>u?q("invalid-offset",`offset ${String(h)} outside 0..${String(u)}`):tt({...a.value,offset:h})}function mt(r,e,s){if("paragraph"in r){if(!("at"in r))return uo(r,e,s);let b=G(r.paragraph,e,s);if(!b.ok||r.at==="start")return b;let k=(s.story(b.value.story)?.paragraphText(b.value.paragraphId)??"").length;return tt({...b.value,offset:k})}let a=$(r.body,"body",e,s);if(!a.ok)return a;let l=a.value.paragraphIds;if(l.length===0)return q("invalid-offset","empty-story");if(r.at==="start")return tt({story:a.value.story,paragraphId:l[0],index:0,offset:0});let u=l.length-1,h=l[u];return tt({story:a.value.story,paragraphId:h,index:u,offset:(a.value.paragraphText(h)??"").length})}function co(r,e){return r.index<e.index||r.index===e.index&&r.offset<=e.offset}function po(r){let e=r.paragraphIds;if(e.length===0)return null;let s=e.length-1,a=e[s];return {start:{story:r.story,paragraphId:e[0],index:0,offset:0},end:{story:r.story,paragraphId:a,index:s,offset:(r.paragraphText(a)??"").length}}}function W(r,e,s){if("body"in r){let u=$(r.body,"body",e,s);return u.ok?tt(po(u.value)):u}if("paragraph"in r){let u=G(r.paragraph,e,s);if(!u.ok)return u;let b=(s.story(u.value.story)?.paragraphText(u.value.paragraphId)??"").length;return tt({start:u.value,end:{...u.value,offset:b}})}let a=mt(r.start,e,s);if(!a.ok)return a;let l=mt(r.end,e,s);return l.ok?_(a.value.story)!==_(l.value.story)?q("invalid-handle","span-crosses-stories"):co(a.value,l.value)?tt({start:a.value,end:l.value}):q("invalid-offset","span-start-after-end"):l}function at(r,e,s){if("body"in r)return $(r.body,"body",e,s);if("paragraph"in r)return $(r.paragraph,"paragraph",e,s);let a=r.start;return "paragraph"in a?$(a.paragraph,"paragraph",e,s):$(a.body,"body",e,s)}function Et(r,e,s){if("paragraph"in r)return G(r.paragraph,e,s);let a=$(r.body,"body",e,s);if(!a.ok)return a;let l=a.value.paragraphIds;if(l.length===0)return q("invalid-offset","empty-story");let u=r.at==="first"?0:l.length-1;return tt({story:a.value.story,paragraphId:l[u],index:u,offset:0})}function et(r,e){return r?e.paragraphIds.slice(r.start.index,r.end.index+1):[]}function Gt(r,e){if(!r)return [];let s=et(r,e),a=s.length-1;return s.map((l,u)=>{let h=(e.paragraphText(l)??"").length,b=u===0?r.start.offset:0,m=u===a?r.end.offset:h;return {paragraphId:l,start:b,end:m,whole:b===0&&m===h}})}function en(r,e,s){if(!r)return "";let a=et(r,e);return a.length===1?(e.paragraphText(r.start.paragraphId)??"").slice(r.start.offset,r.end.offset):a.map((l,u)=>{let h=e.paragraphText(l)??"";return u===0?h.slice(r.start.offset):u===a.length-1?h.slice(0,r.end.offset):h}).join(s)}function Jt(r,e){return {start:{paragraph:e.paragraph(r.start.paragraphId,r.start.story),offset:r.start.offset},end:{paragraph:e.paragraph(r.end.paragraphId,r.end.story),offset:r.end.offset}}}var mo=256,nn=1e4;function Qt(r,e){if(r.kind!=="textValue"){for(let s of r.attributes)if(s.namespaceUri===chunkQIFQTG57_cjs.la&&s.localName===e)return s.value}}function fo(r){return r.startsWith("_")}function Zt(r){let e=new Map,s=[],a=new Set;for(let l of r.paragraphIds){let u=r.node(l);if(u?.kind!=="paragraph")continue;let h=chunkQIFQTG57_cjs.Nd(u),b=m=>{if(m.kind!=="textValue"){if(m.kind==="bookmarkStart"){if(s.length>=nn||e.size>=nn)return;let k=Qt(m,"id"),f=Qt(m,"name");if(k===void 0||f===void 0||f.length===0||f.length>mo||fo(f)||a.has(f)||e.has(k))return;let g=h.spanOf(m)?.start??0;e.set(k,{name:f,start:{paragraphId:l,offset:g}});return}if(m.kind==="bookmarkEnd"){let k=Qt(m,"id");if(k===void 0)return;let f=e.get(k);if(!f)return;e.delete(k),a.add(f.name);let g=h.spanOf(m)?.start??0;s.push(Object.freeze({name:f.name,start:f.start,end:{paragraphId:l,offset:g}}));return}for(let k of m.children)b(k);}};for(let m of u.children)b(m);}return Object.freeze(s)}function qt(r,e){return Zt(r).find(s=>s.name===e)??null}function on(r,e){let s=r.node(e);if(s?.kind!=="paragraph")return Object.freeze([]);let a=chunkQIFQTG57_cjs.Nd(s),l=[],u=(h,b)=>{if(!(h.kind==="textValue"||b>32)){if(chunkQIFQTG57_cjs.Qa(h)){let m=a.spanOf(h);m&&l.push(Object.freeze({id:h.id,paragraphId:e,start:m.start,end:m.end}));return}for(let m of h.children)u(m,b+1);}};for(let h of s.children)u(h,0);return Object.freeze(l)}function rn(r,e,s){let a=chunkQIFQTG57_cjs.Ta(s,l=>chunkQIFQTG57_cjs.Sc(r,e,l));if(a.kind==="external")return a.href;if(a.kind==="internal"){let l=chunkQIFQTG57_cjs.Ra(s);return l===void 0||l.length===0?null:`#${l}`}return null}var ft=8;function an(r){if(!r||r.kind==="textValue")return null;for(let e of r.attributes)if(e.namespaceUri===chunkQIFQTG57_cjs.la&&e.localName==="val")return e.value;return null}function sn(r){let e=chunkQIFQTG57_cjs.Ld(chunkQIFQTG57_cjs.Jd(r),"numPr");if(!e)return null;let s=an(chunkQIFQTG57_cjs.Ld(e,"numId"));if(s===null||!/^\d{1,10}$/.test(s)||s==="0")return null;let a=an(chunkQIFQTG57_cjs.Ld(e,"ilvl")),l=a===null?0:Number(a);return !Number.isInteger(l)||l<0||l>ft?null:{numId:s,level:l}}function _t(r){let e=new Map;for(let s of r.paragraphIds){let a=r.node(s);if(!a)continue;let l=sn(a);if(!l)continue;let u=e.get(l.numId);u?u.push(s):e.set(l.numId,[s]);}return Object.freeze([...e].map(([s,a])=>Object.freeze({numId:s,paragraphIds:Object.freeze(a)})))}function It(r,e){let s=r.node(e);return s?sn(s):null}var go={insert:"Insert",delete:"Delete",replace:"Replace",moveFrom:"MovedFrom",moveTo:"MovedTo",format:"Property",paragraphMark:"ParagraphProperty"};function yo(r){return r.kind==="note"}function ho(r,e){return e.length===0?!yo(r.story):e.every(s=>r.has(s.start.paragraphId))}function te(r){let e=[];for(let s of chunkQIFQTG57_cjs.dg(r.part)){if(s.readOnly||s.revisionKind==="structural"||!ho(r,s.ranges))continue;let a=go[s.revisionKind];a!==void 0&&e.push(Object.freeze({id:s.id,type:a,author:s.author,date:s.date??"",item:s}));}return Object.freeze(e)}function ko(r,e){let s=r;for(let a=0;s!==void 0&&a<=64;a+=1){if(s.parentId===void 0)return s.range!==null;s=e.get(s.parentId);}return false}var Ao=Object.freeze({items:Object.freeze([]),roots:Object.freeze([]),byId:()=>null,textOf:()=>""});function dn(r,e){let s=r.parts.get(chunkQIFQTG57_cjs.Gf(r,e.part.name));if(!s)return Ao;let a=r.parts.get(chunkQIFQTG57_cjs.Hf(r,e.part.name)),l=chunkQIFQTG57_cjs.Ee(s),u=a?chunkQIFQTG57_cjs.Fe(a):new Map,h=chunkQIFQTG57_cjs.De(e.part).filter(g=>e.has(g.start.paragraphId)),b=chunkQIFQTG57_cjs.eg(l,h,u),m=new Map(b.map(g=>[g.id,g])),k=b.filter(g=>ko(g,m)),f=new Map(k.map(g=>[g.id,g]));return Object.freeze({items:Object.freeze(k),roots:Object.freeze(k.filter(g=>g.parentId===void 0)),byId:g=>f.get(g)??null,textOf:g=>{let R=f.get(g);return R?chunkQIFQTG57_cjs.bg(R.comment):""}})}var vo=1e4;function ln(r,e){let s=[],a=e.kind==="contentControl"?chunkQIFQTG57_cjs.ke(e):e;if(!a)return s;for(let l of chunkQIFQTG57_cjs.oe(a))if(!(l.ancestors.length>0)){if(s.length>=vo)break;s.push(mn(r,l.node));}return s}function un(r,e){for(let s of chunkQIFQTG57_cjs.oe(r.root))if(s.node.id===e)return mn(r,s.node);return null}function cn(r,e){for(let s of chunkQIFQTG57_cjs.oe(r.root))if(s.node.id===e)return s.node;return null}function ee(r,e){let s=fn(e);if(s.length>0){let a=s[0],l=s[s.length-1],u=r.paragraphText(l);return u===null||!r.has(a)?null:{start:{paragraphId:a,offset:0},end:{paragraphId:l,offset:u.length}}}for(let a of r.paragraphIds){let l=r.node(a);if(!l||l.kind!=="paragraph"||!l.children.some(h=>h.id===e.id))continue;let u=chunkQIFQTG57_cjs.Nd(l).spanOf(e);return u?{start:{paragraphId:a,offset:u.start},end:{paragraphId:a,offset:u.end}}:null}return null}function pn(r){return chunkQIFQTG57_cjs.qe(r)}function mn(r,e){return {nodeId:e.id,properties:chunkQIFQTG57_cjs.me(e),lock:chunkQIFQTG57_cjs.yf(r.part,e.id),paragraphIds:fn(e)}}function fn(r){let e=chunkQIFQTG57_cjs.ke(r);if(!e)return [];let s=[];return chunkQIFQTG57_cjs.Be(e.children,s,0),s.map(a=>a.id)}var bo=new Set(["unlocked","sdtLocked","contentLocked","sdtContentLocked"]),Io=4096,gn=64;function yn(r){if(r===void 0)return {ok:true,value:null};if(typeof r!="object"||r===null)return {ok:false,field:"payload"};let e=r;for(let s of ["namespaceUri","rootLocalName","nodeId"]){let a=e[s];if(typeof a!="string"||a.length===0||a.length>Io)return {ok:false,field:s}}return typeof e.label!="string"||e.label.length>chunkQIFQTG57_cjs.Jf?{ok:false,field:"label"}:typeof e.data!="string"||e.data.length===0||e.data.length>chunkQIFQTG57_cjs.If?{ok:false,field:"data"}:{ok:true,value:{namespaceUri:e.namespaceUri,rootLocalName:e.rootLocalName,nodeId:e.nodeId,label:e.label,data:e.data}}}function hn(r){let e=r.at!==void 0,s=r.span!==void 0;return e===s?{message:"a custom node goes at a position or over a span, not both",detail:e?"at+span":"no-place"}:typeof r.tag!="string"||r.tag.length===0?{message:"a custom node carries its identity in its tag",detail:"tag"}:r.tag.length>gn?{message:`w:tag caps at ${String(gn)} characters; a longer payload belongs in the store`,detail:"tag"}:typeof r.text!="string"||r.text.length===0?{message:"a custom node shows some text",detail:"text"}:r.lock!==void 0&&!bo.has(r.lock)?{message:"that is not a lock",detail:String(r.lock)}:null}function kn(r,e,s,a){return {paragraphId:e.paragraphId,offset:e.offset,...s.offset>e.offset?{replaceUntil:s.offset}:{},tag:r.tag,text:r.text,...r.title===void 0?{}:{alias:r.title},...r.lock===void 0||r.lock==="unlocked"?{}:{lock:r.lock},...a===null?{}:{payload:a}}}function An(r,e,s){if(r.span){let l=W(r.span,e,s);return l.ok?l.value?l.value.start.paragraphId!==l.value.end.paragraphId?{code:"unsupported-content",message:"a custom node wraps text inside one paragraph",detail:"multi-paragraph"}:{range:l.value}:{code:"invalid-offset",message:"that story holds nothing to wrap",detail:"empty-story"}:{code:l.code,message:"that span is not a place",detail:l.detail}}let a=mt(r.at,e,s);return a.ok?{range:{start:a.value,end:a.value}}:{code:a.code,message:"that is not a place",detail:a.detail}}var xt=/[\r\n\v\f\u2028\u2029]/,xo=16,So=64,vn=/\s/;function Ro(r,e,s){return Object.freeze(s===void 0?{code:r,message:e}:{code:r,message:e,detail:s})}function d(r,e,s){return {ok:false,error:Ro(r,e,s)}}var F=Object.freeze({kind:"applied"});function I(r){return {ok:true,kind:"query",value:r}}function bn(r){let e=r.kind==="contentControl"?chunkQIFQTG57_cjs.ke(r):r;return e?chunkQIFQTG57_cjs.oe(e).map(s=>s.node):[]}var Co=new Set(["unlocked","sdtLocked","contentLocked","sdtContentLocked"]),Oo=new Set(["whole","content","start","end","before","after"]),Po=new Set(["richText","plainText","dropDownList","comboBox","date"]),wo=4096;function To(r){let e=(l,u)=>({ok:false,code:"unsupported-content",message:l,detail:u});if(typeof r!="object"||r===null||!("kind"in r))return e("a control value states its kind","value");let s=r,a=s.kind;if(a==="text"||a==="listItem"){let l=a==="text"?s.text:s.value;return typeof l!="string"?e("that value is not a string",String(a)):l.length>wo?e("that value is too long",String(l.length)):{ok:true,value:a==="text"?{kind:"text",text:l}:{kind:"listItem",value:l}}}if(a==="checkbox"){let l=s.checked;return typeof l!="boolean"?e("a checkbox is checked or not","checked"):{ok:true,value:{kind:"checkbox",checked:l}}}if(a==="date"){let l=s.iso;return typeof l!="string"?e("a date is an ISO-8601 string","iso"):l.length>64?e("that is not a date",String(l.length)):{ok:true,value:{kind:"date",iso:l}}}return e("that is not a value any control accepts",String(a))}function No(r,e){let s=[],a=0;for(;a<r.length;){let l=null;for(let u of e){let h=r.indexOf(u,a);h<0||(!l||h<l.start||h===l.start&&u.length>l.length)&&(l={start:h,length:u.length});}if(!l)break;s.push(l),a=l.start+l.length;}return s}function Ho(r,e,s){let a=e[s]?.markParagraphId??null;if(a!==null)return a;let l=r.paragraphIds,u=l[l.length-1];return u===void 0||new Set(e.map(b=>b.markParagraphId).filter(b=>b!==null)).has(u)?null:u}function Lo(r,e){for(let s of [r.start,r.end]){let a=e.paragraphText(s.paragraphId);if(a===null||s.offset>a.length)return false}return true}function Mo(r,e,s){let a=e,l=s;for(;a<l&&vn.test(r[a]);)a+=1;for(;l>a&&vn.test(r[l-1]);)l-=1;return [a,l]}function In(r){let{handles:e,capabilities:s}=r,a=r.reads,l=new Map,u=o=>{let t=_(o.story),n=l.get(t);if(n)return n;let i=new Map,c=o.paragraphIds.map(y=>{let v={id:y};return i.set(y,v),v}),p={reads:o,order:c,slotById:i,created:[],restructured:new Set,touched:new Set,formatted:new Set,selected:new Set,retargets:[]};return l.set(t,p),p},h=[],b=false,m=false,k=null,f=o=>k===null?(k=o,null):k===o?null:d("conflicting-operations","one batch writes into one story",`${_(k.reads.story)} then ${_(o.reads.story)}`),g=o=>{let t=a.package;return t===null?null:dn(t,o)},R=o=>{let t=e.resolve(o,"comment");if(!t||t.kind!=="comment")return {ok:false,planned:d("invalid-handle","that handle does not name a comment","comment")};let n=a.story(t.story);if(!n)return {ok:false,planned:d("invalid-handle","that story is not in this document")};let c=g(n)?.byId(t.commentId)??null;return c?{ok:true,reads:n,item:c}:{ok:false,planned:d("invalid-handle","this document no longer holds that comment",t.commentId)}},A=o=>{let t=e.resolve(o,"revision");if(!t||t.kind!=="revision")return {ok:false,planned:d("invalid-handle","that handle does not name a tracked change","revision")};let n=a.story(t.story);if(!n)return {ok:false,planned:d("invalid-handle","that story is not in this document")};let i=te(n).find(c=>c.id===t.revisionId)??null;return i?{ok:true,reads:n,item:i}:{ok:false,planned:d("invalid-handle","this document no longer holds that tracked change",t.revisionId)}},T=(o,t)=>{let n=o.paragraphText(t.start.paragraphId),i=o.paragraphText(t.end.paragraphId);if(n===null||i===null)return null;let c={story:o.story,paragraphId:t.start.paragraphId,index:o.indexOf(t.start.paragraphId),offset:Math.min(t.start.offset,n.length)},p={story:o.story,paragraphId:t.end.paragraphId,index:o.indexOf(t.end.paragraphId),offset:Math.min(t.end.offset,i.length)};return M({start:c,end:p})},O=(o,t)=>o.order.indexOf(t),H=(o,t)=>o.selected.has(t)?d("conflicting-operations","this batch selects a paragraph it also edits",t):null,L=(o,t)=>{let n=H(o,t);return n||(o.restructured.has(t)||o.touched.has(t)?d("conflicting-operations","another operation in this batch already changes that paragraph",t):(o.restructured.add(t),o.touched.add(t),null))},j=(o,t)=>{let n=H(o,t);return n||(o.restructured.has(t)?d("conflicting-operations","another operation in this batch restructures that paragraph",t):(o.touched.add(t),null))},Q=(o,t,n)=>{let i=`${n}:${t}`;if(o.formatted.has(i))return d("conflicting-operations","another operation in this batch already writes that formatting",t);let c=j(o,t);return c||(o.formatted.add(i),null)},dt=(o,t)=>{let n={id:null};return o.order.splice(t,0,n),o.created.push(n),n},M=o=>Jt(o,e),X=o=>o===null?null:a.story(o.start.story),St=(o,t,n,i)=>{if(i?.matchWildcards===true)return d("unsupported-capability","wildcard search is not implemented","matchWildcards");if(i?.ignorePunct===true)return d("unsupported-capability","ignoring punctuation is not implemented","ignorePunct");if(i?.ignoreSpace===true)return d("unsupported-capability","ignoring whitespace is not implemented","ignoreSpace");if(!chunkQIFQTG57_cjs.pg(n))return d("unsupported-content","that is not a query this host will scan for","text");let c=i?.limit;if(c!==void 0&&(!Number.isInteger(c)||c<0))return d("invalid-offset","limit must be a non-negative integer",String(c));let p=Math.min(c??2e3,2e3),y=[],v=et(t,o),x=v.length-1;for(let[P,w]of v.entries()){if(p<=0)break;let E=o.paragraphText(w)??"",C=chunkQIFQTG57_cjs.qg(E,n,p,{matchCase:i?.matchCase===true,wholeWord:i?.matchWholeWord===true,...P===0&&t?{from:t.start.offset}:{},...P===x&&t?{to:t.end.offset}:{}});for(let S of C.matches){let V=e.paragraph(w,o.story);y.push({start:{paragraph:V,offset:S.start},end:{paragraph:V,offset:S.start+S.length}});}p-=C.matches.length;}return I({kind:"spans",spans:y})},gt=(o,t,n)=>{if(typeof n!="string")return d("unsupported-content","insertText needs text","text");if(xt.test(n))return d("unsupported-content","text carrying a paragraph mark is not written by this host","paragraph-mark-in-text");let i=f(o);if(i)return i;let c=j(o,t.paragraphId);if(c)return c;let p=n.length===0?[]:[{op:"insertText",paragraphId:t.paragraphId,offset:t.offset,text:n}],y=()=>({kind:"span",span:M({start:t,end:{...t,offset:t.offset+n.length}})});return {ok:true,kind:"command",ops:p,story:o.reads.story,answer:y}},Rt=(o,t,n)=>{let i=o.reads;if(typeof n!="string")return d("unsupported-content","replaceSpan needs text","text");if(xt.test(n))return d("unsupported-content","text carrying a paragraph mark is not written by this host","paragraph-mark-in-text");let c=et(t,i),p=t.start.paragraphId,y=[],v=f(o);if(v)return v;if(c.length===1){let w=j(o,p);if(w)return w;t.end.offset>t.start.offset&&y.push({op:"deleteText",paragraphId:p,start:t.start.offset,end:t.end.offset});}else {for(let C of c){let S=L(o,C);if(S)return S}let w=t.end.paragraphId,E=(i.paragraphText(p)??"").length;t.start.offset<E&&y.push({op:"deleteText",paragraphId:p,start:t.start.offset,end:E}),t.end.offset>0&&y.push({op:"deleteText",paragraphId:w,start:0,end:t.end.offset});for(let C of c.slice(1,-1))y.push({op:"deleteBlock",blockId:C});y.push({op:"joinParagraphs",firstId:p,secondId:w});for(let C of c.slice(1)){let S=o.slotById.get(C);S&&o.order.splice(O(o,S),1);}}n.length>0&&y.push({op:"insertText",paragraphId:p,offset:t.start.offset,text:n});let x={...t.start,paragraphId:p},P=()=>({kind:"span",span:M({start:x,end:{...x,offset:x.offset+n.length}})});return {ok:true,kind:"command",ops:y,story:o.reads.story,answer:P}},ne=(o,t)=>{let n=o.reads;if(typeof t!="string")return d("unsupported-content","replaceSpan needs text","text");if(xt.test(t))return d("unsupported-content","text carrying a paragraph mark is not written by this host","paragraph-mark-in-text");let i=n.blocks,c=i.filter(S=>S.removable),p=i.filter(S=>!S.removable).flatMap(S=>S.paragraphIds),y=p.length===0?c.find(S=>S.kind==="paragraph"):void 0;if(!y&&p.length===0)return d("invalid-offset","that story holds no paragraph this host can write into","no-top-level-paragraph");let v=f(o);if(v)return v;for(let S of n.paragraphIds){let V=L(o,S);if(V)return V}let x=[],P=(y?[y.id]:[...p]).sort((S,V)=>n.indexOf(S)-n.indexOf(V)),w=P[0];for(let S of P){let V=(n.paragraphText(S)??"").length;V>0&&x.push({op:"deleteText",paragraphId:S,start:0,end:V});}for(let S of c)S.id!==y?.id&&x.push({op:"deleteBlock",blockId:S.id});t.length>0&&x.push({op:"insertText",paragraphId:w,offset:0,text:t});for(let S of c)if(S.id!==y?.id)for(let V of S.paragraphIds){let Ct=o.slotById.get(V);Ct&&o.order.splice(O(o,Ct),1);}let E={story:n.story,paragraphId:w,index:n.indexOf(w),offset:0},C=()=>({kind:"span",span:M({start:E,end:{...E,offset:t.length}})});return {ok:true,kind:"command",ops:x,story:n.story,answer:C}},N=(o,t,n,i)=>{let c=o.reads;if(typeof i!="string")return d("unsupported-content","insertParagraph needs text","text");if(xt.test(i))return d("unsupported-content","a paragraph mark inside a paragraph\u2019s text is not written by this host","paragraph-mark-in-text");let p=f(o);if(p)return p;let y=L(o,t.paragraphId);if(y)return y;let v=o.slotById.get(t.paragraphId);if(!v)return d("invalid-handle","that paragraph is not in the body");let x=(c.paragraphText(t.paragraphId)??"").length,P=[];n==="after"?(i.length>0&&P.push({op:"insertText",paragraphId:t.paragraphId,offset:x,text:i}),P.push({op:"splitParagraph",paragraphId:t.paragraphId,offset:x})):(i.length>0&&P.push({op:"insertText",paragraphId:t.paragraphId,offset:0,text:i}),P.push({op:"splitParagraph",paragraphId:t.paragraphId,offset:i.length}));let w=dt(o,O(o,v)+1);n==="before"&&o.retargets.push({from:t.paragraphId,slot:w});let E=()=>{let C=n==="after"?w.id:t.paragraphId;return C===null?F:{kind:"handle",handle:e.paragraph(C,c.story)}};return {ok:true,kind:"command",ops:P,story:c.story,answer:E}},K=(o,t,n,i,c)=>{let p=o.reads;if(!Array.isArray(n)||n.length===0)return d("unsupported-content","split needs at least one delimiter","delimiters");if(n.length>xo)return d("unsupported-content","too many delimiters",String(n.length));for(let z of n){if(typeof z!="string"||z.length===0)return d("unsupported-content","a delimiter must be a non-empty string","delimiters");if(z.length>So)return d("unsupported-content","that delimiter is too long","delimiters")}let y=f(o);if(y)return y;let v=L(o,t.paragraphId);if(v)return v;let x=o.slotById.get(t.paragraphId);if(!x)return d("invalid-handle","that paragraph is not in the body");let P=p.paragraphText(t.paragraphId)??"",w=No(P,n),E=[],C=[],S=[];if(w.length===0)S.push(P);else if(i){for(let D of [...w].reverse())E.push({op:"deleteText",paragraphId:t.paragraphId,start:D.start,end:D.start+D.length});let z=0,st=0;for(let D of w){let jt=D.start-z;C.push(jt),S.push(P.slice(st,D.start)),st=D.start+D.length,z+=D.length;}S.push(P.slice(st));}else {let z=0;for(let st of w){let D=st.start+st.length;C.push(D),S.push(P.slice(z,D)),z=D;}S.push(P.slice(z));}C.length>0&&E.push({op:"splitParagraphMany",paragraphId:t.paragraphId,offsets:C});let V=[x];for(let z=0;z<C.length;z+=1)V.push(dt(o,O(o,x)+1+z));let Ct=z=>{let st=z.story(p.story),D=[];return V.forEach((jt,Nn)=>{let Kt=jt.id;if(Kt===null)return;let Wt=st?.paragraphText(Kt)??S[Nn]??"",[Hn,Ln]=c?Mo(Wt,0,Wt.length):[0,Wt.length],re=e.paragraph(Kt,p.story);D.push({start:{paragraph:re,offset:Hn},end:{paragraph:re,offset:Ln}});}),{kind:"spans",spans:D}};return {ok:true,kind:"command",ops:E,story:p.story,answer:Ct}},nt=(o,t)=>{let n=f(o);if(n)return n;let i=L(o,t.paragraphId);if(i)return i;let c=o.slotById.get(t.paragraphId);return c&&o.order.splice(O(o,c),1),{ok:true,kind:"command",ops:[{op:"deleteBlock",blockId:t.paragraphId}],story:o.reads.story,answer:()=>F}},yt=(o,t,n)=>{let i=o.reads,c=i.part,p=f(o);if(p)return p;let y=Ye(n??{});if(!y.ok)return d("unsupported-content","that is not formatting this host writes",y.detail);let v=[];for(let x of Gt(t,i)){if(x.end<=x.start&&!x.whole)continue;let P=Q(o,x.paragraphId,"runs");if(P)return P;for(let w of chunkQIFQTG57_cjs.Zf(c,x.paragraphId,x.start,x.end,y.value))v.push({op:"setRunProperties",paragraphId:x.paragraphId,start:w.start,end:w.end,properties:w.properties,...w.targetRunIds?{targetRunIds:w.targetRunIds}:{}});x.whole&&v.push({op:"setParagraphMarkProperties",paragraphId:x.paragraphId,properties:chunkQIFQTG57_cjs.Wf(chunkQIFQTG57_cjs.Vf(c,x.paragraphId),y.value)});}return v.length===0?d("invalid-offset","that range covers no characters to format","collapsed-range"):{ok:true,kind:"command",ops:v,story:i.story,answer:()=>F}},lt=(o,t,n)=>{let i=o.reads,c=i.part,p=f(o);if(p)return p;let y=Lt(n,i.styles());if(!y.ok)return d("unsupported-content","that is not a style this document has",y.detail);let v={localName:"pStyle",attributes:{val:y.styleId}},x=[];for(let P of et(t,i)){let w=Q(o,P,"paragraph");if(w)return w;x.push({op:"setParagraphProperties",paragraphId:P,properties:chunkQIFQTG57_cjs.Wf(chunkQIFQTG57_cjs.Uf(c,P),v)});}return x.length===0?d("invalid-offset","that story holds no paragraph to style","empty-story"):{ok:true,kind:"command",ops:x,story:i.story,answer:()=>F}},xn=(o,t,n)=>{let i=o.reads,c=i.part,p=f(o);if(p)return p;let y=Ge(c,t.paragraphId,n??{},i.styles());if(!y.ok)return d("unsupported-content","that is not paragraph formatting this host writes",y.detail);let v=Q(o,t.paragraphId,"paragraph");return v||{ok:true,kind:"command",ops:[{op:"setParagraphProperties",paragraphId:t.paragraphId,properties:y.value}],story:i.story,answer:()=>F}},Sn=(o,t)=>{let n=a.body;if(!n)return d("document-unavailable","this host holds no document right now");let i=a.sections();if(!i[o])return d("invalid-handle","that section is not in this document");let p=Qe(t);if(!p.ok)return d("unsupported-content",p.reason,p.detail);let y=Ho(n,i,o);if(y===null)return d("unsupported-content","that section holds no paragraph to address it by","no-anchor");let v=u(n),x=f(v);return x||{ok:true,kind:"command",ops:[{op:"setSectionProperties",...p.value,anchorParagraphId:y}],story:it,answer:()=>F}},Rn=(o,t)=>({ok:true,kind:"command",ops:[{op:"deleteNote",noteKind:o,noteId:t}],story:it,lifecycle:true,answer:()=>F}),Ft=o=>{let t=e.resolve(o,"list");if(!t||t.kind!=="list")return d("invalid-handle","that handle does not name a list","list");let n=a.story(t.story);if(!n)return d("invalid-handle","that story is not in this document");let i=_t(n).find(c=>c.numId===t.numId);return i?{ok:true,plan:u(n),list:i}:d("invalid-handle","this story numbers nothing with that list",t.numId)},Bt=o=>{if(typeof o!="object"||o===null)return d("invalid-handle","that is not a scope a control lives in","scope");let t=o;if("body"in o){let n=$(t.body,"body",e,a);return n.ok?{reads:n.value,node:n.value.root}:d(n.code,"that handle does not name a body",n.detail)}if("contentControl"in o){let n=Z(t.contentControl);return "control"in n?{reads:n.reads,node:n.node}:n}return d("invalid-handle","that is not a scope a control lives in","scope")},Z=o=>{let t=e.resolve(o,"contentControl");if(!t||t.kind!=="contentControl")return d("invalid-handle","that handle does not name a content control","contentControl");let n=a.story(t.story);if(!n)return d("invalid-handle","that story is not in this document");let i=un(n,t.nodeId),c=cn(n,t.nodeId);return !i||!c?d("invalid-handle","this document no longer holds that content control"):{reads:n,control:i,node:c}},Cn=(o,t,n)=>{if(!Number.isInteger(n)||n<0||n>ft)return d("invalid-offset",`a list level is 0 to ${String(ft)}`,String(n));if(!It(o.reads,t))return d("unsupported-content","that paragraph is not in a list",t);let i=f(o);if(i)return i;let c=Q(o,t,"paragraph");return c||{ok:true,kind:"command",ops:[{op:"setListLevel",paragraphId:t,level:n}],story:o.reads.story,answer:()=>F}},On=(o,t,n,i)=>{if(n!=="start"&&n!=="end")return d("unknown-operation","a list takes an item at its start or its end",String(n));let c=o.reads,p=n==="start"?t.paragraphIds[0]:t.paragraphIds[t.paragraphIds.length-1];if(p===void 0)return d("invalid-handle","that list holds no paragraph");let y={story:c.story,paragraphId:p,index:c.indexOf(p)};return N(o,y,n==="start"?"before":"after",i)},oe=(o,t)=>{if(t.start.paragraphId!==t.end.paragraphId)return null;for(let n of on(o,t.start.paragraphId))if(n.start<=t.start.offset&&n.end>=t.end.offset)return n;return null},Pn=(o,t,n)=>{if(typeof n!="string")return d("unsupported-content","a hyperlink target is a string","target");let i=o.reads,c=oe(i,t),p=t.start.paragraphId===t.end.paragraphId&&t.start.offset===t.end.offset;if(n.length===0){if(!c)return d("unsupported-content","that text is not a link","no-link");let C=f(o);if(C)return C;let S=j(o,c.paragraphId);return S||{ok:true,kind:"command",ops:[{op:"removeHyperlink",linkId:c.id}],story:i.story,answer:()=>F}}let y={},v=null;if(n.startsWith("#")){let C=n.slice(1);if(C.length===0||!qt(i,C))return d("unsupported-content","this document declares no such bookmark",n);y={anchor:C};}else {if(chunkQIFQTG57_cjs.Qc(n)===null)return d("unsupported-content","this engine will not author that target","target");v=n;}let x=f(o);if(x)return x;let P=C=>v===null?{ok:true,kind:"command",ops:[C(y)],story:i.story,answer:()=>F}:{ok:true,kind:"command",ops:[],relate:{url:v,ops:S=>[C({relationshipId:S})]},story:i.story,answer:()=>F};if(c){let C=j(o,c.paragraphId);return C||P(S=>({op:"setHyperlinkTarget",linkId:c.id,...S}))}if(p)return d("unsupported-content","a link with no text has nothing to click","collapsed");if(t.start.paragraphId!==t.end.paragraphId)return d("unsupported-content","a link lives inside one paragraph","crosses-paragraph-mark");let w=j(o,t.start.paragraphId);if(w)return w;let E=i.styles().idOf("hyperlink");return P(C=>({op:"insertHyperlink",paragraphId:t.start.paragraphId,start:t.start.offset,end:t.end.offset,...C,...E===null?{}:{styleId:E}}))},wn=(o,t,n)=>{let i=o.reads;if(!s.selection||!r.select)return d("unsupported-capability","this host has no reader to move","selection");if(n!=="select"&&n!=="start"&&n!=="end")return d("unknown-operation","that is not a selection mode",String(n));let c=et(t,i);for(let p of c)if(o.touched.has(p))return d("conflicting-operations","this batch edits a paragraph the selection covers",p);for(let p of c)o.selected.add(p);return h.push({range:t,mode:n}),{ok:true,kind:"command",ops:[],story:i.story,answer:()=>F}},Tn=o=>{switch(o.op){case "getDocument":return I({kind:"handle",handle:e.document()});case "getBody":return e.resolve(o.document,"document")?a.body?I({kind:"handle",handle:e.body(it)}):d("document-unavailable","this host holds no document right now"):d("invalid-handle","that handle does not name a document","document");case "getParagraphs":{let t=$(o.body,"body",e,a);return t.ok?I({kind:"handles",handles:t.value.paragraphIds.map(n=>e.paragraph(n,t.value.story))}):d(t.code,"that handle does not name a body",t.detail)}case "getSpanParagraphs":{let t=W(o.span,e,a);if(!t.ok)return d(t.code,"that span is not a place",t.detail);let n=at(o.span,e,a);return n.ok?I({kind:"handles",handles:et(t.value,n.value).map(i=>e.paragraph(i,n.value.story))}):d(n.code,"that span is not a place",n.detail)}case "getText":{if(e.resolve(o.target,"body")){let c=$(o.target,"body",e,a);return c.ok?I({kind:"text",text:c.value.text()}):d(c.code,"that handle does not name a body",c.detail)}let n=G(o.target,e,a);if(!n.ok)return d(n.code,"that handle does not name a body or a paragraph",n.detail);let i=a.story(n.value.story);return I({kind:"text",text:i?.paragraphText(n.value.paragraphId)??""})}case "getSpanText":{let t=W(o.span,e,a);if(!t.ok)return d(t.code,"that span is not a place",t.detail);let n=at(o.span,e,a);return n.ok?I({kind:"text",text:en(t.value,n.value,Yt)}):d(n.code,"that span is not a place",n.detail)}case "getParagraphId":{let t=G(o.paragraph,e,a);if(!t.ok)return d(t.code,"that handle does not name a paragraph",t.detail);let i=a.story(t.value.story)?.paragraph(t.value.paragraphId);return I({kind:"text",text:i?.paraId??""})}case "search":{let t=W(o.scope,e,a);if(!t.ok)return d(t.code,"that is not a scope to search",t.detail);let n=at(o.scope,e,a);return n.ok?St(n.value,t.value,o.text,o.options):d(n.code,"that is not a scope to search",n.detail)}case "insertText":{let t=mt(o.at,e,a);if(!t.ok)return d(t.code,"that is not a place to insert at",t.detail);let n=a.story(t.value.story);return n?gt(u(n),t.value,o.text):d("invalid-handle","that story is not in this document")}case "replaceSpan":{if("body"in o.span){let i=$(o.span.body,"body",e,a);return i.ok?ne(u(i.value),o.text):d(i.code,"that handle does not name a body",i.detail)}let t=W(o.span,e,a);if(!t.ok)return d(t.code,"that span is not a place",t.detail);if(!t.value)return d("invalid-offset","that story holds no paragraph to write into","empty-story");let n=X(t.value);return n?Rt(u(n),t.value,o.text):d("invalid-handle","that story is not in this document")}case "insertParagraph":{let t=Et(o.anchor,e,a);if(!t.ok)return d(t.code,"that is not a paragraph to insert beside",t.detail);if(o.where!=="before"&&o.where!=="after")return d("unknown-operation","that is not a place to insert",String(o.where));let n=a.story(t.value.story);return n?N(u(n),t.value,o.where,o.text):d("invalid-handle","that story is not in this document")}case "splitParagraph":{let t=G(o.paragraph,e,a);if(!t.ok)return d(t.code,"that handle does not name a paragraph",t.detail);let n=a.story(t.value.story);return n?K(u(n),t.value,o.delimiters,o.trimDelimiters===true,o.trimSpacing===true):d("invalid-handle","that story is not in this document")}case "getFont":{let t=W(o.span,e,a);if(!t.ok)return d(t.code,"that span is not a place",t.detail);let n=at(o.span,e,a);return n.ok?I({kind:"font",font:Ue(n.value.part,Gt(t.value,n.value))}):d(n.code,"that span is not a place",n.detail)}case "setFont":{let t=W(o.span,e,a);if(!t.ok)return d(t.code,"that span is not a place",t.detail);if(!t.value)return d("invalid-offset","that story holds no paragraph to format","empty-story");let n=X(t.value);return n?yt(u(n),t.value,o.font):d("invalid-handle","that story is not in this document")}case "getStyle":{let t=W(o.span,e,a);if(!t.ok)return d(t.code,"that span is not a place",t.detail);let n=at(o.span,e,a);if(!n.ok)return d(n.code,"that span is not a place",n.detail);let i=n.value.part,c=n.value.styles(),p=et(t.value,n.value).map(v=>Ht(i,v,c)),y=p.length>0&&p.every(v=>v!==null&&v===p[0])?p[0]:null;return I({kind:"style",name:y})}case "setStyle":{let t=W(o.span,e,a);if(!t.ok)return d(t.code,"that span is not a place",t.detail);if(!t.value)return d("invalid-offset","that story holds no paragraph to style","empty-story");let n=X(t.value);return n?lt(u(n),t.value,o.name):d("invalid-handle","that story is not in this document")}case "getParagraphFormat":{let t=Et(o.paragraph,e,a);if(!t.ok)return d(t.code,"that is not a paragraph",t.detail);let n=a.story(t.value.story);if(!n)return d("document-unavailable","this host holds no document right now");let i=Xe(n.part,t.value.paragraphId,n.styles());return i?I({kind:"paragraphFormat",format:i}):d("invalid-handle","that handle does not name a paragraph")}case "setParagraphFormat":{let t=Et(o.paragraph,e,a);if(!t.ok)return d(t.code,"that is not a paragraph",t.detail);let n=a.story(t.value.story);return n?xn(u(n),t.value,o.format):d("invalid-handle","that story is not in this document")}case "deleteParagraph":{let t=G(o.paragraph,e,a);if(!t.ok)return d(t.code,"that handle does not name a paragraph",t.detail);let n=a.story(t.value.story);return n?nt(u(n),t.value):d("invalid-handle","that story is not in this document")}case "getSections":return e.resolve(o.document,"document")?I({kind:"handles",handles:a.sections().map(t=>e.section(t.index))}):d("invalid-handle","that handle does not name a document","document");case "getPageSetup":{let t=e.resolve(o.section,"section");if(!t||t.kind!=="section")return d("invalid-handle","that handle does not name a section","section");let n=a.sections()[t.index];return n?I({kind:"pageSetup",setup:n.pageSetup}):d("invalid-handle","that section is not in this document")}case "setPageSetup":{let t=e.resolve(o.section,"section");return !t||t.kind!=="section"?d("invalid-handle","that handle does not name a section","section"):Sn(t.index,o.setup)}case "getFurniture":{let t=e.resolve(o.section,"section");if(!t||t.kind!=="section")return d("invalid-handle","that handle does not name a section","section");if(o.kind!=="header"&&o.kind!=="footer")return d("unknown-operation","that is not furniture",String(o.kind));let n={kind:o.kind,sectionIndex:t.index,variant:o.variant};return Ke(n)?a.story(n)?I({kind:"handle",handle:e.body(n)}):d("invalid-handle","this document declares no such header or footer",_(n)):d("unknown-operation","that is not a furniture variant",String(o.variant))}case "getNotes":{if(!e.resolve(o.document,"document"))return d("invalid-handle","that handle does not name a document","document");if(o.noteKind!=="footnote"&&o.noteKind!=="endnote")return d("unknown-operation","that is not a kind of note",String(o.noteKind));let t=o.noteKind;return I({kind:"handles",handles:a.noteIds(t).map(n=>e.note(t,n))})}case "getNoteBody":{let t=e.resolve(o.note,"note");if(!t||t.kind!=="note")return d("invalid-handle","that handle does not name a note","note");let n={kind:"note",noteKind:t.noteKind,noteId:t.noteId};return a.story(n)?I({kind:"handle",handle:e.body(n)}):d("invalid-handle","that note is not in this document",_(n))}case "getNoteKind":{let t=e.resolve(o.note,"note");return !t||t.kind!=="note"?d("invalid-handle","that handle does not name a note","note"):I({kind:"text",text:t.noteKind})}case "deleteNote":{let t=e.resolve(o.note,"note");return !t||t.kind!=="note"?d("invalid-handle","that handle does not name a note","note"):a.noteIds(t.noteKind).includes(t.noteId)?Rn(t.noteKind,t.noteId):d("invalid-handle","that note is not in this document")}case "getLists":{let t=$(o.body,"body",e,a);return t.ok?I({kind:"handles",handles:_t(t.value).map(n=>e.list(n.numId,t.value.story))}):d(t.code,"that handle does not name a body",t.detail)}case "getListId":{let t=Ft(o.list);return "list"in t?I({kind:"number",value:Number(t.list.numId)}):t}case "getListById":{let t=$(o.body,"body",e,a);if(!t.ok)return d(t.code,"that handle does not name a body",t.detail);if(!Number.isInteger(o.id)||o.id<=0)return d("unsupported-content","a list is numbered from one",String(o.id));let n=String(o.id),i=_t(t.value).find(c=>c.numId===n);return i?I({kind:"handle",handle:e.list(i.numId,t.value.story)}):d("invalid-handle","no list in that story carries that number",n)}case "getListParagraphs":{let t=Ft(o.list);if(!("list"in t))return t;let n=o.level;if(n!==void 0&&(!Number.isInteger(n)||n<0||n>ft))return d("invalid-offset",`a list level is 0 to ${String(ft)}`,String(n));let i=t.plan.reads,c=n===void 0?t.list.paragraphIds:t.list.paragraphIds.filter(p=>It(i,p)?.level===n);return I({kind:"handles",handles:c.map(p=>e.paragraph(p,i.story))})}case "getParagraphList":{let t=G(o.paragraph,e,a);if(!t.ok)return d(t.code,"that handle does not name a paragraph",t.detail);let n=a.story(t.value.story);if(!n)return d("invalid-handle","that story is not in this document");let i=It(n,t.value.paragraphId);return i?I({kind:"handle",handle:e.list(i.numId,n.story)}):d("unsupported-content","that paragraph is not in a list",t.value.paragraphId)}case "getListLevel":{let t=G(o.paragraph,e,a);if(!t.ok)return d(t.code,"that handle does not name a paragraph",t.detail);let n=a.story(t.value.story);if(!n)return d("invalid-handle","that story is not in this document");let i=It(n,t.value.paragraphId);return i?I({kind:"number",value:i.level}):d("unsupported-content","that paragraph is not in a list",t.value.paragraphId)}case "setListLevel":{let t=G(o.paragraph,e,a);if(!t.ok)return d(t.code,"that handle does not name a paragraph",t.detail);let n=a.story(t.value.story);return n?Cn(u(n),t.value.paragraphId,o.level):d("invalid-handle","that story is not in this document")}case "insertListParagraph":{let t=Ft(o.list);return "list"in t?On(t.plan,t.list,o.where,o.text):t}case "getHyperlink":{let t=W(o.span,e,a);if(!t.ok)return d(t.code,"that span is not a place",t.detail);let n=at(o.span,e,a);if(!n.ok)return d(n.code,"that span is not a place",n.detail);let i=a.package;if(!i||!t.value)return I({kind:"text",text:""});let c=oe(n.value,t.value);if(!c)return I({kind:"text",text:""});let p=chunkQIFQTG57_cjs.Ea(n.value.part,c.id),y=p?rn(i,n.value.part.name,p):null;return I({kind:"text",text:y??""})}case "setHyperlink":{let t=W(o.span,e,a);if(!t.ok)return d(t.code,"that span is not a place",t.detail);if(!t.value)return d("invalid-offset","that story holds no text to link","empty-story");let n=X(t.value);return n?Pn(u(n),t.value,o.target):d("invalid-handle","that story is not in this document")}case "getBookmarks":{let t=W(o.scope,e,a);if(!t.ok)return d(t.code,"that span is not a place",t.detail);let n=at(o.scope,e,a);if(!n.ok)return d(n.code,"that span is not a place",n.detail);let i=n.value,c=t.value,p=c===null?null:new Set(et(c,i)),y=Zt(i).filter(v=>{if(!p||!p.has(v.start.paragraphId)&&!p.has(v.end.paragraphId)||c===null)return false;let x=v.start.paragraphId===c.end.paragraphId&&v.start.offset>c.end.offset,P=v.end.paragraphId===c.start.paragraphId&&v.end.offset<c.start.offset;return !x&&!P});return I({kind:"handles",handles:y.map(v=>e.bookmark(v.name,i.story))})}case "getBookmarkName":{let t=e.resolve(o.bookmark,"bookmark");return !t||t.kind!=="bookmark"?d("invalid-handle","that handle does not name a bookmark","bookmark"):I({kind:"text",text:t.name})}case "getBookmarkRange":{let t=e.resolve(o.bookmark,"bookmark");if(!t||t.kind!=="bookmark")return d("invalid-handle","that handle does not name a bookmark","bookmark");let n=a.story(t.story);if(!n)return d("invalid-handle","that story is not in this document");let i=qt(n,t.name);if(!i)return d("invalid-handle","this document no longer declares that bookmark",t.name);let c={story:n.story,paragraphId:i.start.paragraphId,index:n.indexOf(i.start.paragraphId),offset:i.start.offset},p={story:n.story,paragraphId:i.end.paragraphId,index:n.indexOf(i.end.paragraphId),offset:i.end.offset};return I({kind:"span",span:M({start:c,end:p})})}case "getComments":{let t=W(o.scope,e,a);if(!t.ok)return d(t.code,"that scope is not a place",t.detail);let n=at(o.scope,e,a);if(!n.ok)return d(n.code,"that scope names no story",n.detail);let i=n.value,c=g(i);if(!c)return d("document-unavailable","this host holds no document");let p=t.value,y=c.roots.filter(v=>{if(!p)return true;let x=v.range;if(!x)return false;let P=i.indexOf(x.start.paragraphId),w=i.indexOf(x.end.paragraphId),E=i.indexOf(p.start.paragraphId),C=i.indexOf(p.end.paragraphId);return w<E||P>C?false:w===E&&P===E&&C===E?x.end.offset>p.start.offset&&x.start.offset<p.end.offset:true});return I({kind:"handles",handles:y.map(v=>e.comment(v.id,i.story))})}case "getCommentReplies":{let t=R(o.comment);return t.ok?I({kind:"handles",handles:t.item.replyIds.map(n=>e.comment(n,t.reads.story))}):t.planned}case "getCommentId":{let t=R(o.comment);return t.ok?I({kind:"text",text:t.item.id}):t.planned}case "getCommentAuthor":{let t=R(o.comment);return t.ok?I({kind:"text",text:t.item.comment.author}):t.planned}case "getCommentDate":{let t=R(o.comment);return t.ok?I({kind:"text",text:t.item.comment.date??""}):t.planned}case "getCommentText":{let t=R(o.comment);if(!t.ok)return t.planned;let n=g(t.reads);return I({kind:"text",text:n?.textOf(t.item.id)??""})}case "getCommentRange":{let t=R(o.comment);if(!t.ok)return t.planned;let n=t.item.range;if(!n||t.item.orphaned)return d("invalid-handle","that comment has no range in this document");let i=T(t.reads,n);return i?I({kind:"span",span:i}):d("invalid-handle","that comment\u2019s range is no longer in the story")}case "getCommentResolved":{let t=R(o.comment);return t.ok?I({kind:"flag",value:t.item.resolved}):t.planned}case "setCommentResolved":{let t=R(o.comment);if(!t.ok)return t.planned;if(typeof o.resolved!="boolean")return d("unsupported-content","resolved is a yes or a no",String(o.resolved));let n=f(u(t.reads));return n||{ok:true,kind:"commentWrite",write:{kind:"resolve",commentId:t.item.id,resolved:o.resolved},story:t.reads.story,answer:()=>F}}case "replyToComment":{let t=R(o.comment);if(!t.ok)return t.planned;if(typeof o.author!="string"||o.author.trim().length===0)return d("unsupported-content","a comment records who wrote it","author");if(typeof o.text!="string"||o.text.length===0)return d("unsupported-content","a reply says something","text");if(xt.test(o.text))return d("unsupported-content","a reply is one paragraph in this slice","text");let n=t.item.range;if(!n||t.item.orphaned)return d("invalid-handle","that comment has no range to reply over");let i=f(u(t.reads));if(i)return i;let c=t.reads.story;return {ok:true,kind:"commentWrite",write:{kind:"reply",parentCommentId:t.item.id,anchor:{paragraphId:n.start.paragraphId,start:n.start.offset,end:n.end.offset,...n.end.paragraphId===n.start.paragraphId?{}:{endParagraphId:n.end.paragraphId}},text:o.text,author:o.author,...typeof o.date=="string"?{date:o.date}:{}},story:t.reads.story,answer:(p,y)=>y===void 0?F:{kind:"handle",handle:e.comment(y,c)}}}case "getRevisions":{let t=$(o.body,"body",e,a);if(!t.ok)return d(t.code,"that handle does not name a body",t.detail);let n=t.value;return I({kind:"handles",handles:te(n).map(i=>e.revision(i.id,n.story))})}case "getRevisionType":{let t=A(o.revision);return t.ok?I({kind:"text",text:t.item.type}):t.planned}case "getRevisionAuthor":{let t=A(o.revision);return t.ok?I({kind:"text",text:t.item.author}):t.planned}case "getRevisionDate":{let t=A(o.revision);return t.ok?I({kind:"text",text:t.item.date}):t.planned}case "getRevisionRange":{let t=A(o.revision);if(!t.ok)return t.planned;let[n]=t.item.item.ranges;if(!n)return d("invalid-handle","that change covers no characters");let i=T(t.reads,n);return i?I({kind:"span",span:i}):d("invalid-handle","that change\u2019s range is no longer in the story")}case "acceptRevision":case "rejectRevision":{let t=A(o.revision);if(!t.ok)return t.planned;let n=u(t.reads),i=f(n);if(i)return i;let c=o.op==="acceptRevision";return {ok:true,kind:"command",story:t.reads.story,ops:t.item.item.addresses.map(p=>c?{op:"acceptRevision",revision:p}:{op:"rejectRevision",revision:p}),answer:()=>F}}case "acceptAllRevisions":case "rejectAllRevisions":{if(!e.resolve(o.document,"document"))return d("invalid-handle","that handle does not name a document","document");let t=a.body;if(!t)return d("document-unavailable","this host holds no document");let n=u(t),i=f(n);return i||{ok:true,kind:"command",story:t.story,ops:[o.op==="acceptAllRevisions"?{op:"acceptAllRevisions"}:{op:"rejectAllRevisions"}],answer:()=>F}}case "selectSpan":{let t=W(o.span,e,a);if(!t.ok)return d(t.code,"that span is not a place",t.detail);if(!t.value)return d("invalid-offset","that story holds no paragraph to select","empty-story");let n=X(t.value);return n?wn(u(n),t.value,o.mode):d("invalid-handle","that story is not in this document")}case "getContentControls":{let t=Bt(o.scope);return "reads"in t?I({kind:"handles",handles:ln(t.reads,t.node).map(n=>e.contentControl(n.nodeId,t.reads.story))}):t}case "getContentControlById":{let t=Bt(o.scope);if(!("reads"in t))return t;if(!Number.isInteger(o.id))return d("unsupported-content","a control id is a whole number",String(o.id));let n=bn(t.node).find(i=>chunkQIFQTG57_cjs.me(i).id===o.id);return n?I({kind:"handle",handle:e.contentControl(n.id,t.reads.story)}):d("invalid-handle","no control in that scope carries that id",String(o.id))}case "getContentControlsByTag":case "getContentControlsByTitle":{let t=Bt(o.scope);if(!("reads"in t))return t;let n=o.op==="getContentControlsByTag"?o.tag:o.title;if(typeof n!="string"||n.length===0)return d("unsupported-content","a tag or title to match is required",o.op);let i=bn(t.node).filter(c=>{let p=chunkQIFQTG57_cjs.me(c);return o.op==="getContentControlsByTag"?p.tag===n:p.alias===n});return I({kind:"handles",handles:i.map(c=>e.contentControl(c.id,t.reads.story))})}case "getContentControlTag":case "getContentControlTitle":case "getContentControlFileId":case "getContentControlSubtype":case "getContentControlLock":{let t=Z(o.contentControl);if(!("control"in t))return t;let n=t.control.properties;if(o.op==="getContentControlLock")return I({kind:"text",text:t.control.lock});if(o.op==="getContentControlSubtype")return I({kind:"text",text:n.type});if(o.op==="getContentControlFileId")return I({kind:"text",text:n.id===void 0?"":String(n.id)});let i=o.op==="getContentControlTag"?n.tag:n.alias;return I({kind:"text",text:i??""})}case "getContentControlPlaceholderShown":case "getContentControlTemporary":{let t=Z(o.contentControl);return "control"in t?I({kind:"flag",value:o.op==="getContentControlPlaceholderShown"?t.control.properties.showingPlaceholder:t.control.properties.temporary}):t}case "getContentControlText":{let t=Z(o.contentControl);return "control"in t?I({kind:"text",text:pn(t.node)}):t}case "getContentControlParagraphs":{let t=Z(o.contentControl);return "control"in t?I({kind:"handles",handles:t.control.paragraphIds.map(n=>e.paragraph(n,t.reads.story))}):t}case "getContentControlRange":{let t=Z(o.contentControl);if(!("control"in t))return t;let n=o.location??"whole";if(!Oo.has(n))return d("unsupported-content","that is not a place in a control",n);let i=ee(t.reads,t.node);if(!i)return d("unsupported-content","that control holds nothing addressable","empty");let c=n==="start"||n==="before"?i.start:i.end,p=n!=="whole"&&n!=="content",y=v=>({story:t.reads.story,paragraphId:v.paragraphId,index:t.reads.indexOf(v.paragraphId),offset:v.offset});return I({kind:"span",span:Jt(p?{start:y(c),end:y(c)}:{start:y(i.start),end:y(i.end)},e)})}case "setContentControlValue":{let t=Z(o.contentControl);if(!("control"in t))return t;let n=To(o.value);if(!n.ok)return d(n.code,n.message,n.detail);let i=u(t.reads),c=f(i);return c||{ok:true,kind:"command",story:t.reads.story,ops:[{op:"setContentControlValue",controlId:t.control.nodeId,value:n.value}],answer:()=>F}}case "setContentControlProperties":{let t=Z(o.contentControl);if(!("control"in t))return t;if(o.tag===void 0&&o.title===void 0&&o.lock===void 0)return d("unsupported-content","nothing to write","no-properties");if(o.lock!==void 0&&!Co.has(o.lock))return d("unsupported-content","that is not a lock this schema declares",o.lock);let n=u(t.reads),i=f(n);return i||{ok:true,kind:"command",story:t.reads.story,ops:[{op:"setContentControlProperties",controlId:t.control.nodeId,...o.tag===void 0?{}:{tag:o.tag},...o.title===void 0?{}:{alias:o.title},...o.lock===void 0?{}:{lock:o.lock}}],answer:()=>F}}case "insertContentControlText":{let t=Z(o.contentControl);if(!("control"in t))return t;if(typeof o.text!="string")return d("unsupported-content","text is required","text");if(o.at!=="replace"&&o.at!=="start"&&o.at!=="end")return d("unsupported-content","that is not a place to insert at",String(o.at));let n=u(t.reads),i=f(n);if(i)return i;let c=ee(t.reads,t.node);if(!c)return d("unsupported-content","that control holds nothing addressable","empty");let p=o.at==="end"?c.end:c.start,y=()=>({kind:"span",span:M({start:{story:t.reads.story,paragraphId:p.paragraphId,index:t.reads.indexOf(p.paragraphId),offset:p.offset},end:{story:t.reads.story,paragraphId:p.paragraphId,index:t.reads.indexOf(p.paragraphId),offset:p.offset+o.text.length}})});return o.at==="replace"?{ok:true,kind:"command",story:t.reads.story,ops:[{op:"setContentControlValue",controlId:t.control.nodeId,value:{kind:"text",text:o.text}}],answer:y}:{ok:true,kind:"command",story:t.reads.story,ops:o.text.length===0?[]:[{op:"insertText",paragraphId:p.paragraphId,offset:p.offset,text:o.text,inside:t.node.id}],answer:y}}case "deleteContentControl":{let t=Z(o.contentControl);if(!("control"in t))return t;if(typeof o.keepContent!="boolean")return d("unsupported-content","keepContent is required","keepContent");let n=u(t.reads),i=f(n);return i||{ok:true,kind:"command",story:t.reads.story,ops:[{op:"removeContentControl",controlId:t.control.nodeId,keepContent:o.keepContent}],answer:()=>F}}case "insertContentControl":{let t=W(o.span,e,a);if(!t.ok)return d(t.code,"that span is not a place",t.detail);if(!t.value)return d("invalid-offset","that story holds nothing to wrap","empty-story");let n=X(t.value);if(!n)return d("invalid-handle","that story is not in this document");let i=t.value;if(i.start.paragraphId!==i.end.paragraphId)return d("unsupported-content","wrapping several paragraphs in one control is not supported here","multi-paragraph");if(!Po.has(o.subtype))return d("unsupported-content","that control type cannot be inserted",o.subtype);let c=u(n),p=f(c);return p||{ok:true,kind:"command",story:n.story,ops:[{op:"insertContentControl",paragraphId:i.start.paragraphId,start:i.start.offset,end:i.end.offset,type:o.subtype,...o.tag===void 0?{}:{tag:o.tag},...o.title===void 0?{}:{alias:o.title}}],answer:()=>F}}case "insertCustomNode":{let t=hn(o);if(t)return d("unsupported-content",t.message,t.detail);let n=yn(o.payload);if(!n.ok)return d("unsupported-content","that payload cannot be written",n.field);let i=An(o,e,a);if("code"in i)return d(i.code,i.message,i.detail);let{start:c,end:p}=i.range,y=X(i.range);if(!y)return d("invalid-handle","that story is not in this document");let v=f(u(y));return v||{ok:true,kind:"customNodeWrite",story:y.story,write:kn(o,c,p,n.value),answer:()=>F}}default:return d("unknown-operation","this host does not implement that operation",String(o.op))}};return {plan(o){let t=We(o);if(t&&b||m&&$t(o))return d("conflicting-operations","that command commits on its own and cannot share a batch",o.op);let n=Tn(o);return n.ok&&$t(o)&&(b=true,t&&(m=true)),n},get hasCommands(){return b},get writeScope(){return k?.reads.scope??null},settle(o){let t=k;if(t){let n=o.story(t.reads.story);if(!n)return {ok:false,detail:`the story this batch wrote is gone: ${_(t.reads.story)}`};let i=new Set(t.reads.paragraphIds),c=n.paragraphIds.filter(y=>!i.has(y));if(c.length!==t.created.length)return {ok:false,detail:`planned ${String(t.created.length)} new paragraphs, the transaction made ${String(c.length)}`};t.order.filter(y=>y.id===null).forEach((y,v)=>{y.id=c[v]??null;});for(let y of t.retargets)y.slot.id&&e.retarget(y.from,y.slot.id);}for(let n of h){let i=o.story(n.range.start.story);!i||!Lo(n.range,i)||r.select?.(n.range,n.mode);}return {ok:true}}}}var Eo=Object.freeze({status:"skipped"});function Y(r,e,s){return Object.freeze(s===void 0?{code:r,message:e}:{code:r,message:e,detail:s})}function J(r,e,s,a){return {ok:false,results:r.map((l,u)=>u===e?{status:"error",error:s}:Eo),revision:a,changed:false}}function oa(r){let{port:e}=r,s=Object.freeze({...r.capabilities}),a=ze(),l=new Set,u=false,h=null,b=s.events?e.subscribe(()=>{if(u)return;let f=Object.freeze({revision:e.revision()});for(let g of [...l])g(f);}):()=>{},m=f=>{if(h&&h.pkg===f)return h.value;let g=tn(f);return h={pkg:f,value:g},g};return {capabilities:s,revision:()=>e.revision(),execute:f=>{let g=Array.isArray(f?.operations)?f.operations:[],R=e.revision();if(u)return J(g,0,Y("disposed","this host was disposed"),R);if(!s.document)return J(g,0,Y("unsupported-capability","this host has no document","document"),R);let A=e.currentPackage();if(!A)return J(g,0,Y("document-unavailable","this host holds no document right now"),R);if(f.expectedRevision!==void 0&&f.expectedRevision!==R)return J(g,0,Y("stale-revision","the document moved since that revision",`expected ${String(f.expectedRevision)}, at ${R}`),R);let T=In({handles:a,reads:m(A),capabilities:s,...e.select?{select:e.select.bind(e)}:{}}),O=[],H=[],L=null,j=null,Q,dt=null,M=-1;for(let N=0;N<g.length;N+=1){let K=T.plan(g[N]);if(!K.ok)return J(g,N,K.error,R);if(O.push(K),K.kind==="command")if(M<0&&(M=N),K.lifecycle)L=K.ops[0]??null;else if(K.relate){let nt=K.relate;H.push(yt=>{let lt=yt(nt.url);return lt===null?null:nt.ops(lt)});}else {let{ops:nt}=K;H.push(()=>nt);}else K.kind==="commentWrite"?(M<0&&(M=N),j={write:K.write,scope:T.writeScope??{kind:"body"}}):K.kind==="customNodeWrite"&&(M<0&&(M=N),dt={write:K.write,scope:T.writeScope??{kind:"body"}});}let X=false;if(j){let N=e.applyCommentWrite(j.write,j.scope);if(!N.ok)return J(g,M<0?0:M,Y("transaction-refused","the document store refused the comment write",N.reason),R);X=N.changed,Q=N.commentId;}if(dt){let N=e.applyCustomNodeWrite(dt.write,dt.scope);if(!N.ok)return J(g,M<0?0:M,Y("transaction-refused","the document store refused the custom-node write",N.reason),R);X=N.changed;}if(L){let N=e.applyLifecycle(L);if(!N.ok)return J(g,M<0?0:M,Y("transaction-refused","the document store refused the transaction",N.reason),R);X=N.changed;}if(H.length>0){let N=e.apply(K=>{let nt=[];for(let yt of H){let lt=yt(K);if(lt===null)return null;nt.push(...lt);}return nt},T.writeScope??{kind:"body"});if(!N.ok)return J(g,M<0?0:M,Y("transaction-refused","the document store refused the transaction",N.reason),R);X=N.changed;}let St=e.currentPackage();if(!St)return J(g,0,Y("document-unavailable","this host holds no document right now"),R);let gt=m(St),Rt=T.settle(gt);return Rt.ok?{ok:true,results:O.map(N=>({status:"ok",value:N.kind==="query"?N.value:N.kind==="customNodeWrite"?N.answer(gt):N.answer(gt,Q)})),revision:e.revision(),changed:X}:J(g,M<0?0:M,Y("transaction-refused","the transaction did not produce the document the batch planned",Rt.detail),e.revision())},save(){if(u)return {ok:false,error:Y("disposed","this host was disposed")};if(!s.save)return {ok:false,error:Y("unsupported-capability","this host cannot save","save")};let f=e.save();return f?{ok:true,bytes:f}:{ok:false,error:Y("document-unavailable","this host holds no document right now")}},subscribe(f){return u||!s.events?()=>{}:(l.add(f),()=>{l.delete(f);})},dispose(){u||(u=true,l.clear(),b(),e.dispose(),h=null);}}}exports.a=Nt;exports.b=Fo;exports.c=Mn;exports.d=En;exports.e=We;exports.f=$t;exports.g=oa;
|