@docx-editor.dev/core 2.15.0 → 2.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -15
- package/dist/automation.cjs +1 -1
- package/dist/automation.d.ts +11 -9
- package/dist/automation.js +1 -1
- package/dist/binding.cjs +1 -1
- package/dist/binding.d.ts +12 -16
- package/dist/binding.js +1 -1
- package/dist/{chunk-Q4AB7E4O.cjs → chunk-4MIFIUEV.cjs} +1 -1
- package/dist/chunk-66DTF4TD.cjs +2 -0
- package/dist/chunk-67U2OZS7.cjs +2 -0
- package/dist/chunk-6EGMDUL7.js +21 -0
- package/dist/chunk-ABXCIZVW.js +2 -0
- package/dist/chunk-AEIAYDCG.js +1 -0
- package/dist/{chunk-YL4Q5LZP.cjs → chunk-BPSGGVP5.cjs} +1 -1
- package/dist/chunk-CMV2MTDE.js +5 -0
- package/dist/chunk-DYPT6YDY.js +1 -0
- package/dist/chunk-EWV5JMJY.cjs +21 -0
- package/dist/chunk-FAD7DH6Q.cjs +1 -0
- package/dist/chunk-GHNTGVKG.cjs +11 -0
- package/dist/chunk-GQVKCK33.js +2 -0
- package/dist/chunk-I4ENGOOZ.js +1 -0
- package/dist/chunk-IZHDCQUC.js +20 -0
- package/dist/chunk-KEXMDQ2Z.js +1 -0
- package/dist/chunk-KQEUFAAG.cjs +20 -0
- package/dist/chunk-QVJO5FUR.js +11 -0
- package/dist/chunk-SIUUTE5M.js +2 -0
- package/dist/chunk-TDHR2QLH.cjs +1 -0
- package/dist/{chunk-PXKZUTHX.cjs → chunk-WGHVIB6B.cjs} +2 -2
- package/dist/chunk-XKQTITOJ.cjs +5 -0
- package/dist/{chunk-KXPVOPR5.js → chunk-YKDRBDI2.js} +1 -1
- package/dist/chunk-YRTRPSSA.cjs +1 -0
- package/dist/collaboration/replication.cjs +1 -1
- package/dist/collaboration/replication.d.ts +4 -4
- package/dist/collaboration/replication.js +1 -1
- package/dist/collaboration.d.ts +4 -4
- package/dist/contracts/editor.d.ts +9 -7
- package/dist/contracts/interaction.d.ts +73 -10
- package/dist/contracts/modules.d.ts +8 -8
- package/dist/{custom-node-writes-C9ArIlJh.d.ts → custom-node-writes-4WOL8JB_.d.ts} +2 -2
- package/dist/{editor-sRxrFJd8.d.ts → editor-PDx0fqSo.d.ts} +26 -125
- package/dist/editor-scope-DZJT4ukT.d.ts +53 -0
- package/dist/editor.cjs +1 -1
- package/dist/editor.css +1 -1
- package/dist/editor.d.ts +32 -26
- package/dist/editor.js +1 -1
- package/dist/export.cjs +2 -2
- package/dist/export.d.ts +24 -12
- package/dist/export.js +2 -2
- package/dist/{font-resolver-BYEHQGTw.d.ts → font-resolver-CdqOugwZ.d.ts} +2 -2
- package/dist/{headless-document-view-DELC4E5v.d.ts → headless-document-view-C9ONlGtf.d.ts} +2 -2
- package/dist/{hf-references-DTrHkktY.d.ts → hf-references-BZVHctVD.d.ts} +1 -1
- package/dist/{index-C3Gvq4jN.d.ts → index-BVb4a6O3.d.ts} +74 -28
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +20 -18
- package/dist/index.js +1 -1
- package/dist/{layout-shaping-DoGR5cf8.d.ts → layout-shaping-D_U5z-Qh.d.ts} +1 -1
- package/dist/layout.cjs +1 -1
- package/dist/layout.d.ts +270 -459
- package/dist/layout.js +1 -1
- package/dist/{note-properties-DSe8igrz.d.ts → note-properties-BosjbkGC.d.ts} +1 -1
- package/dist/{omml-equation-BpRmfDAf.d.ts → omml-equation-oLlbPpVy.d.ts} +1 -1
- package/dist/output.cjs +1 -1
- package/dist/output.d.ts +6 -6
- package/dist/output.js +1 -1
- package/dist/{protocol-DZzKxH5r.d.ts → protocol-CUsqt13U.d.ts} +28 -6
- package/dist/{review-items-DYRx187i.d.ts → review-items-kC-YI70C.d.ts} +1 -1
- package/dist/{review-reads-LbGUdNzn.d.ts → review-reads-DdvADsmp.d.ts} +8 -7
- package/dist/{revision-projection-DHRJH48u.d.ts → revision-projection-CN_DiOl_.d.ts} +1 -1
- package/dist/{semantic-cell-selection-BXVWCBYm.d.ts → semantic-cell-selection-BMrXDniV.d.ts} +4 -4
- package/dist/{semantic-interaction-DZsDmPg5.d.ts → semantic-interaction-NGeYzYCN.d.ts} +1 -1
- package/dist/{semantic-paint-f7SqN4oW.d.ts → semantic-paint-CM8F-8pH.d.ts} +2 -2
- package/dist/{semantic-records-EIdwId-a.d.ts → semantic-records-BreR44Ki.d.ts} +1231 -947
- package/dist/store.cjs +1 -1
- package/dist/store.d.ts +80 -20
- package/dist/store.js +1 -1
- package/dist/{tree-op-types-egdarvH_.d.ts → tree-op-types-C5rZzoAz.d.ts} +131 -53
- package/dist/{tree-package-fragment-DjkH4ESI.d.ts → tree-package-fragment-DDQHk8sv.d.ts} +3 -3
- package/dist/{tree-session-contract-CGOOgPjW.d.ts → tree-session-contract-dKgbKH9A.d.ts} +18 -8
- package/dist/{tree-store-DKJB0IcA.d.ts → tree-store-DU192chS.d.ts} +1 -1
- package/package.json +2 -2
- package/dist/chunk-24APKZAN.cjs +0 -11
- package/dist/chunk-2YH4MSHX.cjs +0 -2
- package/dist/chunk-5Y7AADI6.js +0 -1
- package/dist/chunk-AREFLNUP.js +0 -11
- package/dist/chunk-AS7YZNQE.cjs +0 -2
- package/dist/chunk-AVGCKH6A.cjs +0 -20
- package/dist/chunk-CDYVDQRI.cjs +0 -5
- package/dist/chunk-HOEWFH5U.cjs +0 -1
- package/dist/chunk-KFELX7CN.js +0 -2
- package/dist/chunk-LGFKIF4M.cjs +0 -1
- package/dist/chunk-M52QXFKI.js +0 -1
- package/dist/chunk-MNUKSXRO.js +0 -1
- package/dist/chunk-PBOIGBDO.js +0 -2
- package/dist/chunk-PMHGONET.cjs +0 -1
- package/dist/chunk-QJYH6AYD.js +0 -1
- package/dist/chunk-QRC37MWG.cjs +0 -20
- package/dist/chunk-RJSB6RJ7.js +0 -20
- package/dist/chunk-SB54HLFJ.js +0 -20
- package/dist/chunk-XCESLTJL.js +0 -2
- package/dist/chunk-Z4527AXR.js +0 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {b,c,a}from'./chunk-I4ENGOOZ.js';import {ba,V as V$1,U as U$1,H,I,K as K$1,J,la,ja,ra,qa,ta,Ra,Ia,P,Q as Q$1,Ja,Ga as Ga$1,ya}from'./chunk-GQVKCK33.js';import {O as O$1,Hc,Ga,Me,Lc,Fc,Jc,mf,$a,of,Za,He,Je,Ie as Ie$1,If,fd,id,gd,pd,Nd,Ld,Ad,Lh,lh,da,Ha,jg,kg,hg,We,Ue,ff,ef,yd,td,xh,Ya,Xe,Ve,zd,Eb,Nh}from'./chunk-QVJO5FUR.js';var Rr=["getChangeTrackingMode","getDocument","getBody","getParagraphs","getSpanParagraphs","getText","getSpanText","getParagraphId","search","getFont","getParagraphFormat","getStyle","getSections","getPageSetup","getFurniture","getNotes","getNoteBody","getNoteText","getNoteKind","getLists","getListId","getListById","getListParagraphs","getParagraphList","getListLevel","getHyperlink","getBookmarks","getBookmarkName","getBookmarkRange","getComments","getCommentReplies","getCommentId","getCommentAuthor","getCommentDate","getCommentText","getCommentRange","getCommentResolved","getRevisions","getRevisionType","getRevisionAuthor","getRevisionDate","getRevisionRange","getContentControls","getContentControlById","getContentControlsByTag","getContentControlsByTitle","getContentControlTag","getContentControlTitle","getContentControlFileId","getContentControlSubtype","getContentControlLock","getContentControlIsBound","getContentControlPlaceholderShown","getContentControlTemporary","getContentControlText","getContentControlParagraphs","getContentControlRange"],bo=["setChangeTrackingMode","proposeInsertion","proposeDeletion","proposeReplacement","insertText","replaceSpan","replaceStoryBlocks","insertParagraph","splitParagraph","deleteParagraph","selectSpan","selectBookmark","setFont","setParagraphFormat","setStyle","setPageSetup","deleteNote","setListLevel","insertListParagraph","setHyperlink","insertComment","setCommentResolved","replyToComment","deleteComment","acceptRevision","rejectRevision","acceptAllRevisions","rejectAllRevisions","setContentControlValue","setContentControlProperties","deleteContentControl","insertContentControlText","insertContentControl","insertCustomNode"],Io=["deleteNote","insertComment","setCommentResolved","replyToComment","insertCustomNode"],So=new Set(Io);function ce(n){return So.has(n.op)}var Ro=new Set(bo);function Lt(n){return Ro.has(n.op)}var Yt=Object.freeze(["default","first","even"]),yt=Object.freeze({kind:"body"});function K(n){switch(n.kind){case "body":return "body";case "note":return `note:${n.noteKind}:${String(n.noteId)}`;default:return `${n.kind}:${String(n.sectionIndex)}:${n.variant}`}}function hn(n){if(typeof n!="object"||n===null)return false;let e=n;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&&Yt.includes(e.variant)}function kn(n,e,r){let a=i=>({state:r,step:{ok:false,error:{code:"unsupported-capability",message:i,detail:"changeTrackingMode"}}});return n.op==="getChangeTrackingMode"||n.op==="setChangeTrackingMode"?e?n.op==="getChangeTrackingMode"?{state:r,step:{ok:true,kind:"query",value:{kind:"text",text:r.mode}}}:n.mode!=="Off"&&n.mode!=="TrackMineOnly"?a("TrackAll requires shared tracking enforcement for every peer and is not supported"):n.mode==="TrackMineOnly"&&(typeof n.author!="string"||!n.author.trim()||!O$1(n.author))?a("TrackMineOnly requires a non-empty XML-safe runtime author"):{state:{mode:n.mode,...n.mode==="TrackMineOnly"?{author:n.author.trim()}:{}},step:{ok:true,kind:"query",value:{kind:"applied"}}}:a("Office-shaped tracking mode is supported by server hosts only"):r.mode==="Off"||!Lt(n)||n.op==="insertText"||n.op==="replaceSpan"&&!("body"in n.span)||["insertComment","replyToComment","deleteComment","setCommentResolved","acceptRevision","rejectRevision","acceptAllRevisions","rejectAllRevisions","selectSpan","selectBookmark"].includes(n.op)?null:a(`${n.op} does not support TrackMineOnly; no permanent edit was applied`)}function Co(){let n=globalThis.crypto,e=n?.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 r=e.call(n,new Uint8Array(16)),a="";for(let i of r)a+=i.toString(16).padStart(2,"0");return a}function Oo(n){return typeof n=="object"&&n!==null&&"kind"in n&&"ref"in n}function An(){let n=new Map,e=new Map,r=new Map,a=new Map,i=Co(),l=null,f=(m,y)=>{let I=(a.get(m)??0)+1;a.set(m,I);let x=`${m}:${i}:${String(I)}`;return n.set(x,y),Object.freeze({kind:m,ref:x})},g=(m,y,I)=>{let x=`${m}\0${y}`,S=r.get(x);if(S)return Object.freeze({kind:m,ref:S});let k=f(m,I);return r.set(x,k.ref),k};return {document(){return l??=f("document",{kind:"document"}),l},body(m){return g("body",K(m),{kind:"body",story:m})},paragraph(m,y){let I=e.get(m);if(I)return Object.freeze({kind:"paragraph",ref:I});let x=f("paragraph",{kind:"paragraph",paragraphId:m,story:y});return e.set(m,x.ref),x},section(m){return g("section",String(m),{kind:"section",index:m})},note(m,y){return g("note",`${m}:${String(y)}`,{kind:"note",noteKind:m,noteId:y})},comment(m,y){return g("comment",`${K(y)}\0${m}`,{kind:"comment",commentId:m,story:y})},revision(m,y){return g("revision",`${K(y)}\0${m}`,{kind:"revision",revisionId:m,story:y})},bookmark(m,y){return g("bookmark",`${K(y)}\0${m}`,{kind:"bookmark",name:m,story:y})},list(m,y){return g("list",`${K(y)}\0${m}`,{kind:"list",numId:m,story:y})},contentControl(m,y){return g("contentControl",`${K(y)}\0${m}`,{kind:"contentControl",nodeId:m,story:y})},retarget(m,y){let I=e.get(m);if(!I||m===y)return;let x=n.get(I);!x||x.kind!=="paragraph"||(e.delete(m),n.set(I,{kind:"paragraph",paragraphId:y,story:x.story}),e.has(y)||e.set(y,I));},resolve(m,y){if(!Oo(m)||m.kind!==y||typeof m.ref!="string")return null;let I=n.get(m.ref);return !I||I.kind!==y?null:I}}}var Po=255,To=Object.freeze({nameOf:()=>null,idOf:()=>null,defaultId:null,present:false});function vn(n){let e=ff(n);if(!e)return To;let r=new Map,a=new Map,i=null;for(let l of ef(e).values())if(l.type==="paragraph"){if(r.set(l.styleId,l.name),l.name!==null){let f=l.name.trim().toLowerCase();a.has(f)||a.set(f,l.styleId);}l.isDefault&&i===null&&(i=l.styleId);}return Object.freeze({nameOf:l=>r.get(l)??null,idOf:l=>a.get(l.trim().toLowerCase())??null,defaultId:i,present:true})}function Gt(n,e,r){let a=Ga(n,e);if(!a||a.kind!=="paragraph")return null;let i=wo(Je(He(a),"pStyle"));return i!==null?r.nameOf(i):r.defaultId===null?null:r.nameOf(r.defaultId)}function wo(n){if(!n)return null;for(let e of n.attributes)if(e.localName==="val")return e.value;return null}function Jt(n,e){if(typeof n!="string"||n.trim().length===0)return {ok:false,detail:"style: not a name"};if(n.length>Po)return {ok:false,detail:"style: name too long"};if(!O$1(n))return {ok:false,detail:"style: not valid XML text"};if(!e.present)return {ok:false,detail:"style: this document defines no styles"};let r=e.idOf(n);return r===null?{ok:false,detail:"style: this document defines no paragraph style with that name"}:{ok:true,styleId:r}}var No=31680,Ho=1999,Mo=Object.freeze({bold:null,italic:null,name:null,size:null,color:null});function Q(n,e){if(!n)return null;for(let r of n.attributes)if(r.localName===e)return r.value;return null}function pe(n){if(!n)return null;let e=Q(n,"val");if(e===null)return true;let r=e.trim().toLowerCase();return !(r==="0"||r==="false"||r==="off"||r==="none")}function Lo(n){if(n===null)return null;let e=n.trim();return /^[0-9a-fA-F]{6}$/.test(e)?`#${e.toUpperCase()}`:null}function Eo(n){if(n===null)return null;let e=Number(n.trim());return !Number.isFinite(e)||e<=0?null:e/2}function vt(n){if(n===null)return null;let e=Number(n.trim());return Number.isFinite(e)?We(Ue(e)):null}function Et(n){if(n.length===0)return null;let e=n[0];if(e===null)return null;for(let r of n)if(r!==e)return null;return e}function bn(n,e,r=ba){let a=[];for(let i of e)for(let l of ta(n,i.paragraphId,i.start,i.end,r))a.push(Ie$1(l));return a.length===0?Mo:{bold:Et(a.map(i=>pe(Je(i,"b")))),italic:Et(a.map(i=>pe(Je(i,"i")))),name:Et(a.map(i=>{let l=Je(i,"rFonts"),f=Q(l,"ascii");return f===null||f.length===0?null:f})),size:Et(a.map(i=>Eo(Q(Je(i,"sz"),"val")))),color:Et(a.map(i=>Lo(Q(Je(i,"color"),"val"))))}}var jo=Object.freeze({left:"Left",start:"Left",center:"Centered",right:"Right",end:"Right",both:"Justified",distribute:"Justified"}),Bo=Object.freeze({Left:"left",Centered:"center",Right:"right",Justified:"both"});function _o(n){let e=Q(Je(n,"jc"),"val");return e===null?"Unknown":jo[e.trim().toLowerCase()]??"Unknown"}function In(n,e,r){let a=Ga(n,e);if(!a||a.kind!=="paragraph")return null;let i=He(a),l=Je(i,"spacing"),f=Je(i,"ind");return {alignment:_o(i),style:Gt(n,e,r),firstLineIndent:Fo(f),leftIndent:vt(Q(f,"left")??Q(f,"start")),rightIndent:vt(Q(f,"right")??Q(f,"end")),lineSpacing:vt(Q(l,"line")),spaceBefore:vt(Q(l,"before")),spaceAfter:vt(Q(l,"after")),widowControl:pe(Je(i,"widowControl"))}}function Fo(n){let e=vt(Q(n,"hanging"));if(e!==null&&e>0)return -e;let r=vt(Q(n,"firstLine"));return r!==null?r:e===null?null:-e}function Qt(n,e){if(typeof n!="number"||!Number.isFinite(n))return {ok:false,detail:`${e}: not a measurement`};let r=Xe(Ve(n));return Math.abs(r)>No?{ok:false,detail:`${e}: out of range`}:{ok:true,value:r}}function Sn(n){let e=[];if(n.bold!==void 0){if(typeof n.bold!="boolean")return {ok:false,detail:"bold: not a boolean"};e.push({localName:"b",...n.bold?{}:{attributes:{val:"0"}}});}if(n.italic!==void 0){if(typeof n.italic!="boolean")return {ok:false,detail:"italic: not a boolean"};e.push({localName:"i",...n.italic?{}:{attributes:{val:"0"}}});}if(n.name!==void 0){let r=n.name;if(typeof r!="string"||r.length===0||r.length>128)return {ok:false,detail:"name: not a font name"};if(!O$1(r))return {ok:false,detail:"name: not valid XML text"};e.push({localName:"rFonts",attributes:{ascii:r,hAnsi:r}});}if(n.size!==void 0){let r=n.size;if(typeof r!="number"||!Number.isFinite(r)||r<=0)return {ok:false,detail:"size: not a positive number of points"};let a=Math.round(r*2);if(a<1||a>Ho)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(n.color!==void 0){let r=n.color;if(typeof r!="string"||!/^#[0-9a-fA-F]{6}$/.test(r.trim()))return {ok:false,detail:"color: not a #RRGGBB triplet"};e.push({localName:"color",attributes:{val:r.trim().slice(1).toUpperCase()}});}return e.length===0?{ok:false,detail:"no formatting was asked for"}:{ok:true,value:e}}function Rn(n,e,r,a){let i=Ga(n,e);if(!i||i.kind!=="paragraph")return {ok:false,detail:"not a paragraph"};let l=He(i),f=[];if(r.style!==void 0){let k=Jt(r.style,a);if(!k.ok)return {ok:false,detail:k.detail};f.push({localName:"pStyle",attributes:{val:k.styleId}});}if(r.alignment!==void 0){let k=Bo[r.alignment];if(k===void 0)return {ok:false,detail:`alignment: ${String(r.alignment)}`};f.push({localName:"jc",attributes:{val:k}});}let g=Je(l,"ind"),m=xn(g),y=false;if(r.firstLineIndent!==void 0){let k=Qt(r.firstLineIndent,"firstLineIndent");if(!k.ok)return k;delete m.firstLine,delete m.hanging,k.value<0?m.hanging=String(-k.value):m.firstLine=String(k.value),y=true;}for(let[k,A,b]of [["leftIndent","left","start"],["rightIndent","right","end"]]){let C=r[k];if(C===void 0)continue;let w=Qt(C,k);if(!w.ok)return w;delete m[b],m[A]=String(w.value),y=true;}y&&f.push({localName:"ind",attributes:m});let I=Je(l,"spacing"),x=xn(I),S=false;for(let[k,A]of [["spaceBefore","before"],["spaceAfter","after"]]){let b=r[k];if(b===void 0)continue;let C=Qt(b,k);if(!C.ok)return C;if(C.value<0)return {ok:false,detail:`${k}: out of range`};x[A]=String(C.value),S=true;}if(r.lineSpacing!==void 0){let k=Qt(r.lineSpacing,"lineSpacing");if(!k.ok)return k;if(k.value<=0)return {ok:false,detail:"lineSpacing: out of range"};x.line=String(k.value),x.lineRule??="auto",S=true;}if(S&&f.push({localName:"spacing",attributes:x}),r.widowControl!==void 0){if(typeof r.widowControl!="boolean")return {ok:false,detail:"widowControl: not a boolean"};f.push({localName:"widowControl",...r.widowControl?{}:{attributes:{val:"0"}}});}return f.length===0?{ok:false,detail:"no formatting was asked for"}:{ok:true,value:la(ja(n,e),f)}}function xn(n){let e=Object.create(null);if(!n)return e;for(let r of n.attributes)e[r.localName]=r.value;return e}function Cn(){let n=false,e=false,r=false;return {conflict(a){let i=Lt(a),l=ce(a),f=a.op==="deleteComment";return l&&n||e&&i?{message:"that command commits on its own and cannot share a batch",detail:a.op}:f&&n&&!r||r&&i&&!f?{message:"comment deletions may share a batch only with other comment deletions",detail:a.op}:null},note(a){Lt(a)&&(n=true,ce(a)&&(e=true),a.op==="deleteComment"&&(r=true));},get hasCommands(){return n}}}var Do=63360;function mt(n){return Math.round(We(Ue(n))*100)/100}function Ko(n,e){if(typeof n!="number"||!Number.isFinite(n))return null;let r=Xe(Ve(n));return r>Do||r<0||r===0&&!e?null:r}var Vo=[["pageWidth","pageWidthTwips",false],["pageHeight","pageHeightTwips",false],["topMargin","marginTopTwips",true],["rightMargin","marginRightTwips",true],["bottomMargin","marginBottomTwips",true],["leftMargin","marginLeftTwips",true]];function On(n){if(typeof n!="object"||n===null)return {ok:false,reason:"that is not a page setup",detail:"not-an-object"};let e=n,r={},a=0;for(let[l,f,g]of Vo){let m=e[l];if(m===void 0)continue;let y=Ko(m,g);if(y===null)return {ok:false,reason:`that is not a value for ${l}`,detail:String(m)};r[f]=y,a+=1;}let i=e.orientation;if(i!==void 0){if(i!=="portrait"&&i!=="landscape")return {ok:false,reason:"that is not an orientation",detail:String(i)};r.orientation=i,a+=1;}return a===0?{ok:false,reason:"that page setup names nothing to write",detail:"empty"}:{ok:true,value:r}}function Wo(n){let e=xh(n),r=e.widthTwips>e.heightTwips?"landscape":"portrait";return Object.freeze({pageWidth:mt(e.widthTwips),pageHeight:mt(e.heightTwips),orientation:r,topMargin:mt(e.topTwips),rightMargin:mt(e.rightTwips),bottomMargin:mt(e.bottomTwips),leftMargin:mt(e.leftTwips),headerDistance:mt(e.headerTwips),footerDistance:mt(e.footerTwips),gutter:mt(e.gutterTwips)})}function zo(n,e){if(!e)return null;let r=null,a=(i,l,f)=>{if(r!==null||i.kind==="textValue"||f>64)return;let g=i.kind==="paragraph"?i.id:l;if(i.id===e.id){r=g;return}for(let m of i.children)a(m,g,f+1);};return a(n.root,null,0),r}function Pn(n,e,r){let a=Ld(e.root);return Object.freeze(a.map((i,l)=>{let f=r[l];return Object.freeze({index:l,markParagraphId:zo(e,i),pageSetup:Wo(i),titlePage:f?.titlePage??false,evenAndOddHeaders:f?.evenAndOddHeaders??false})}))}function Tn(n,e,r){return e>=r?null:{text:n.text.slice(e-n.rawStart,r-n.rawStart),rawStart:e,rawEnd:r}}function $o(n,e){let r=[],a=0;for(let i of n){for(;a<e.length&&e[a].end<=i.rawStart;)a+=1;let l=i.rawEnd-i.rawStart;if(i.text.length!==l){let m=e[a];(!m||m.start>=i.rawEnd)&&r.push(i);continue}let f=i.rawStart;for(;a<e.length;){let m=e[a];if(m.end<=f){a+=1;continue}if(m.start>=i.rawEnd)break;let y=Tn(i,f,Math.min(m.start,i.rawEnd));if(y&&r.push(y),f=Math.max(f,m.end),m.end<=i.rawEnd&&(a+=1),f>=i.rawEnd)break}let g=Tn(i,f,i.rawEnd);g&&r.push(g);}return r}function Zt(n,e,r){if(r==="model")return b(e);let a$1=c(n,e,r);if(r==="allMarkup")return a(a$1);let i=Uo(n);if(i.length===0)return a(a$1);let l=$o(a$1,i);return a(l)}function Uo(n){let e=Me(n),r=[],a=(l,f)=>{if(!(f>64||l.kind==="textValue")){if(l.kind==="revisionInsert"||l.kind==="revisionMoveTo"){let g=e.spanOf(l);g&&g.end>g.start&&r.push({start:g.start,end:g.end});return}for(let g of l.children)a(g,f+1);}};a(n,0),r.sort((l,f)=>l.start-f.start||f.end-l.end);let i=[];for(let l of r){let f=i[i.length-1];f&&l.start<=f.end?f.end=Math.max(f.end,l.end):i.push({...l});}return i}var fe="\r",Xo=Object.freeze({nameOf:()=>null,idOf:()=>null,defaultId:null,present:false}),Yo=Object.freeze([]),Go=Object.freeze([]),wn=Object.freeze([]),Jo=Object.freeze({package:null,body:null,story:()=>null,storyOf:()=>null,sections:()=>Go,furniture:()=>wn,noteIds:()=>({ok:true,ids:Hn}),styles:()=>Xo});function Qo(n){return n.kind==="textValue"?Yo:Object.freeze(n.children.filter(e=>e.kind!=="textValue").map(e=>{let r=[];Ad([e],r,0);let a=e.kind==="paragraph"?"paragraph":e.kind==="table"?"table":"other",i=e.kind==="paragraph"&&Je(He(e),"sectPr")!==void 0;return Object.freeze({id:e.id,kind:a,paragraphIds:Object.freeze(r.map(l=>l.id)),removable:a!=="other"&&!i})}))}function me(n,e,r,a,i){let l=zd(a),f=Object.freeze(l.map(k=>k.id)),g=new Map,m=new Map;l.forEach((k,A)=>{g.set(k.id,A),m.set(k.id,k);});let y=new Map,I=k=>{if(!g.has(k))return null;let A=y.get(k);if(A!==void 0)return A;let b=Nh(e,k)??"";return y.set(k,b),b},x=new Map,S=(k,A="allMarkup")=>{let b=m.get(k);if(!b||b.kind!=="paragraph")return null;let C=`${k}:${A}`,w=x.get(C);if(w)return w;let L=Zt(b,I(k)??"",A);return x.set(C,L),L};return {story:n,part:e,root:a,scope:r,paragraphIds:f,blocks:Qo(a),has:k=>g.has(k),indexOf:k=>g.get(k)??-1,paragraph(k){let A=m.get(k);return A?{nodeId:k,paraId:Eb(A),text:S(k)?.text??""}:null},node:k=>m.get(k)??null,rawText:I,paragraphText:(k,A)=>S(k,A)?.text??null,projectedText:S,text:k=>f.map(A=>S(A,k)?.text??"").join(fe),styles:i}}function Nn(n){let e=n.parts.get(n.mainDocumentPart);if(!e)return Jo;let r,a=()=>r??=vn(n),i,l=()=>i??=Nd(n),f,g=new Map,m=new Map,y=A=>{let b=m.get(A);if(b)return b;let C=If(n,A);if(!C){let X={ok:true,ids:Hn};return m.set(A,X),X}let w=[],L=new Set,_=new Set,z=0,B=false;for(let X of C.root.children){if(fd(X)!==A)continue;if(z+=1,X.kind!=="note"){B=true;continue}if(!id(X))continue;let it=gd(X);if(it===null){B=true;continue}L.has(it)?_.add(it):(L.add(it),w.push(it));}let G=z>pd?{ok:false,reason:"truncated"}:B?{ok:false,reason:"malformed"}:_.size>0?{ok:false,reason:"duplicates",duplicateIds:Object.freeze([..._])}:{ok:true,ids:Object.freeze(w)};return m.set(A,G),G},I=A=>{let b=l()[A.sectionIndex];return b?(A.kind==="header"?b.headers:b.footers).get(A.variant)??null:null},x=A=>{if(A.kind==="body"){let C=yd(e);return C?me(A,e,{kind:"body"},C,a):null}if(A.kind==="note"){let C=y(A.noteKind);if(!C.ok||!C.ids.includes(A.noteId))return null;let w=If(n,A.noteKind);if(!w)return null;let L=td(w.root,A.noteId);return !L||!id(L)?null:me(A,w,{kind:"notesPart",noteKind:A.noteKind},L,a)}let b=I(A);return b?me(A,b.part,{kind:"headerFooter",rId:b.rId},b.part.root,a):null},S=A=>{let b=K(A);if(g.has(b))return g.get(b)??null;let C=x(A);return g.set(b,C),C};return {package:n,get body(){return S(yt)},story:S,storyOf:A=>{if(S(yt)?.has(A))return yt;for(let[C]of l().entries())for(let w of ["header","footer"])for(let L of Yt){let _={kind:w,sectionIndex:C,variant:L};if(S(_)?.has(A))return _}for(let C of ["footnote","endnote"]){let w=y(C);if(w.ok)for(let L of w.ids){let _={kind:"note",noteKind:C,noteId:L};if(S(_)?.has(A))return _}}return null},sections:()=>f??=Pn(n,e,l()),furniture(A){let b=l()[A];if(!b)return wn;let C=[];for(let w of ["header","footer"]){let L=w==="header"?b.headers:b.footers;for(let _ of Yt){let z=L.get(_);z&&C.push(Object.freeze({kind:w,variant:_,declared:!z.inherited}));}}return Object.freeze(C)},noteIds:y,styles:a}}var Hn=Object.freeze([]);function lt(n,e){return {ok:false,code:n,detail:e}}function ut(n){return {ok:true,value:n}}function U(n,e,r,a){let i=r.resolve(n,e);if(!i||i.kind!=="body"&&i.kind!=="paragraph")return lt("invalid-handle",`not-a-${e}-handle`);let l=a.story(i.story);return l?ut(l):lt("invalid-handle",`no-such-story:${K(i.story)}`)}function et(n,e,r){let a=e.resolve(n,"paragraph");if(!a||a.kind!=="paragraph")return lt("invalid-handle","not-a-paragraph-handle");let i=r.story(a.story);if(!i)return lt("invalid-handle",`no-such-story:${K(a.story)}`);let l=i.indexOf(a.paragraphId);return l<0?lt("invalid-handle","paragraph-not-in-body"):ut({story:a.story,paragraphId:a.paragraphId,index:l,offset:0})}function Zo(n,e,r){let a=et(n.paragraph,e,r);if(!a.ok)return a;let l=(r.story(a.value.story)?.rawText(a.value.paragraphId)??"").length,{offset:f}=n;return !Number.isInteger(f)||f<0||f>l?lt("invalid-offset",`offset ${String(f)} outside 0..${String(l)}`):ut({...a.value,offset:f})}function Ct(n,e,r){if("paragraph"in n){if(!("at"in n))return Zo(n,e,r);let g=et(n.paragraph,e,r);if(!g.ok||n.at==="start")return g;let y=(r.story(g.value.story)?.rawText(g.value.paragraphId)??"").length;return ut({...g.value,offset:y})}let a=U(n.body,"body",e,r);if(!a.ok)return a;let i=a.value.paragraphIds;if(i.length===0)return lt("invalid-offset","empty-story");if(n.at==="start")return ut({story:a.value.story,paragraphId:i[0],index:0,offset:0});let l=i.length-1,f=i[l];return ut({story:a.value.story,paragraphId:f,index:l,offset:(a.value.rawText(f)??"").length})}function qo(n,e){return n.index<e.index||n.index===e.index&&n.offset<=e.offset}function tr(n){let e=n.paragraphIds;if(e.length===0)return null;let r=e.length-1,a=e[r];return {start:{story:n.story,paragraphId:e[0],index:0,offset:0},end:{story:n.story,paragraphId:a,index:r,offset:(n.rawText(a)??"").length}}}function V(n,e,r){if("body"in n){let l=U(n.body,"body",e,r);return l.ok?ut(tr(l.value)):l}if("paragraph"in n){let l=et(n.paragraph,e,r);if(!l.ok)return l;let g=(r.story(l.value.story)?.rawText(l.value.paragraphId)??"").length;return ut({start:l.value,end:{...l.value,offset:g}})}let a=Ct(n.start,e,r);if(!a.ok)return a;let i=Ct(n.end,e,r);return i.ok?K(a.value.story)!==K(i.value.story)?lt("invalid-handle","span-crosses-stories"):qo(a.value,i.value)?ut({start:a.value,end:i.value}):lt("invalid-offset","span-start-after-end"):i}function q(n,e,r){if("body"in n)return U(n.body,"body",e,r);if("paragraph"in n)return U(n.paragraph,"paragraph",e,r);let a=n.start;return "paragraph"in a?U(a.paragraph,"paragraph",e,r):U(a.body,"body",e,r)}function qt(n,e,r){if("paragraph"in n)return et(n.paragraph,e,r);let a=U(n.body,"body",e,r);if(!a.ok)return a;let i=a.value.paragraphIds;if(i.length===0)return lt("invalid-offset","empty-story");let l=n.at==="first"?0:i.length-1;return ut({story:a.value.story,paragraphId:i[l],index:l,offset:0})}function at(n,e){return n?e.paragraphIds.slice(n.start.index,n.end.index+1):[]}function ye(n,e){if(!n)return [];let r=at(n,e),a=r.length-1;return r.map((i,l)=>{let f=(e.rawText(i)??"").length,g=l===0?n.start.offset:0,m=l===a?n.end.offset:f;return {paragraphId:i,start:g,end:m,whole:g===0&&m===f}})}function Mn(n,e,r,a="allMarkup"){if(!n)return "";let i=at(n,e);return i.length===1?e.projectedText(n.start.paragraphId,a)?.sliceRaw(n.start.offset,n.end.offset)??"":i.map((l,f)=>{let g=e.projectedText(l,a);if(!g)return "";let m=(e.rawText(l)??"").length;return f===0?g.sliceRaw(n.start.offset,m):f===i.length-1?g.sliceRaw(0,n.end.offset):g.text}).join(r)}function jt(n,e){return {start:{paragraph:e.paragraph(n.start.paragraphId,n.start.story),offset:n.start.offset},end:{paragraph:e.paragraph(n.end.paragraphId,n.end.story),offset:n.end.offset}}}var er=256,Ln=1e4;function ge(n,e){if(n.kind!=="textValue"){for(let r of n.attributes)if(r.namespaceUri===da&&r.localName===e)return r.value}}function nr(n){return n.startsWith("_")}function he(n){let e=new Map,r=[],a=new Set;for(let i of n.paragraphIds){let l=n.node(i);if(l?.kind!=="paragraph")continue;let f=Me(l),g=m=>{if(m.kind!=="textValue"){if(m.kind==="bookmarkStart"){if(r.length>=Ln||e.size>=Ln)return;let y=ge(m,"id"),I=ge(m,"name");if(y===void 0||I===void 0||I.length===0||I.length>er||nr(I)||a.has(I)||e.has(y))return;let x=f.spanOf(m)?.start??0;e.set(y,{name:I,start:{paragraphId:i,offset:x}});return}if(m.kind==="bookmarkEnd"){let y=ge(m,"id");if(y===void 0)return;let I=e.get(y);if(!I)return;e.delete(y),a.add(I.name);let x=f.spanOf(m)?.start??0;r.push(Object.freeze({name:I.name,start:I.start,end:{paragraphId:i,offset:x}}));return}for(let y of m.children)g(y);}};for(let m of l.children)g(m);}return Object.freeze(r)}function ke(n,e){return he(n).find(r=>r.name===e)??null}function En(n,e){let r=n.node(e);if(r?.kind!=="paragraph")return Object.freeze([]);let a=Me(r),i=[],l=(f,g)=>{if(!(f.kind==="textValue"||g>32)){if(Ya(f)){let m=a.spanOf(f);m&&i.push(Object.freeze({id:f.id,paragraphId:e,start:m.start,end:m.end}));return}for(let m of f.children)l(m,g+1);}};for(let f of r.children)l(f,0);return Object.freeze(i)}function jn(n,e,r){let a=$a(r,i=>of(n,e,i));if(a.kind==="external")return a.href;if(a.kind==="internal"){let i=Za(r);return i===void 0||i.length===0?null:`#${i}`}return null}var Ot=8;function Bn(n){if(!n||n.kind==="textValue")return null;for(let e of n.attributes)if(e.namespaceUri===da&&e.localName==="val")return e.value;return null}function _n(n){let e=Je(He(n),"numPr");if(!e)return null;let r=Bn(Je(e,"numId"));if(r===null||!/^\d{1,10}$/.test(r)||r==="0")return null;let a=Bn(Je(e,"ilvl")),i=a===null?0:Number(a);return !Number.isInteger(i)||i<0||i>Ot?null:{numId:r,level:i}}function te(n){let e=new Map;for(let r of n.paragraphIds){let a=n.node(r);if(!a)continue;let i=_n(a);if(!i)continue;let l=e.get(i.numId);l?l.push(r):e.set(i.numId,[r]);}return Object.freeze([...e].map(([r,a])=>Object.freeze({numId:r,paragraphIds:Object.freeze(a)})))}function Bt(n,e){let r=n.node(e);return r?_n(r):null}function Fn(n,e,r,a,i){let l=Math.min(i?.limit??2e3,2e3),f=[],g=at(e,n),m=g.length-1;for(let[y,I]of g.entries()){if(l<=0)break;let x=n.projectedText(I,i?.projection??"allMarkup");if(!x)continue;let S=x.findOccurrences(a,l,{matchCase:i?.matchCase===true,wholeWord:i?.matchWholeWord===true,...y===0&&e?{from:x.projectedOffset(e.start.offset)}:{},...y===m&&e?{to:x.projectedOffset(e.end.offset)}:{}});for(let k of S.matches){if(y===0&&e&&k.rawStart<e.start.offset||y===m&&e&&k.rawEnd>e.end.offset)continue;let A=r.paragraph(I,n.story);f.push({start:{paragraph:A,offset:k.rawStart},end:{paragraph:A,offset:k.rawEnd}}),l-=1;}}return {ok:true,spans:f}}var or={insert:"Insert",delete:"Delete",replace:"Replace",moveFrom:"MovedFrom",moveTo:"MovedTo",format:"Property",paragraphMark:"ParagraphProperty"};function rr(n){return n.kind==="note"}function ar(n,e){return e.length===0?!rr(n.story):e.every(r=>n.has(r.start.paragraphId))}function sr(n){return Object.freeze(Ia(n.part).filter(e=>ar(n,e.ranges)))}function Ae(n){let e=[];for(let r of sr(n)){if(r.readOnly||r.revisionKind==="structural")continue;let a=or[r.revisionKind];a!==void 0&&e.push(Object.freeze({id:r.id,type:a,author:r.author,date:r.date??"",item:r}));}return Object.freeze(e)}function ir(n,e){let r=n;for(let a=0;r!==void 0&&a<=64;a+=1){if(r.parentId===void 0)return r.range!==null;r=e.get(r.parentId);}return false}var dr=Object.freeze({items:Object.freeze([]),roots:Object.freeze([]),byId:()=>null,textOf:()=>""});function Dn(n,e){let r=n.parts.get(P(n,e.part.name));if(!r)return dr;let a=n.parts.get(Q$1(n,e.part.name)),i=jg(r),l=a?kg(a):new Map,f=hg(e.part).filter(x=>e.has(x.start.paragraphId)),g=Ja(i,f,l),m=new Map(g.map(x=>[x.id,x])),y=g.filter(x=>ir(x,m)),I=new Map(y.map(x=>[x.id,x]));return Object.freeze({items:Object.freeze(y),roots:Object.freeze(y.filter(x=>x.parentId===void 0)),byId:x=>I.get(x)??null,textOf:x=>{let S=I.get(x);return S?Ga$1(S.comment):""}})}var lr=/[\r\n\v\f\u2028\u2029]/;function ee(n,e,r){return {code:n,message:e,detail:r}}function Kn(n,e=false){if(typeof n.author!="string"||!n.author.trim()||!O$1(n.author))return ee("unsupported-content","proposals need a non-empty XML-safe author","author");let r=n.op==="proposeInsertion";return !(n.op==="proposeDeletion")&&(typeof n.text!="string"||!e&&!n.text.length||lr.test(n.text)||!O$1(n.text))?ee("unsupported-content","proposals need non-empty inline XML-safe text","text"):r&&n.where!=="Before"&&n.where!=="After"?ee("unsupported-content","insertion needs Before or After","where"):null}function Vn(n,e,r,a){let i=Ia(n.part),l=new Set;if(i.some(g=>g.revisionKind==="structural"))for(let g=Ha(n.part,e);g!==null&&(l.add(g.id),g.id!==n.root.id);g=Ha(n.part,g.id));return i.some(g=>{if(g.revisionKind==="structural"){let m=ya(g),y=0;for(let I of m){let x=Ha(n.part,I),S=x&&Ha(n.part,x.id),k=S?.kind==="tableRow"?"trPr":S?.kind==="tableCell"?"tcPr":null;if(!(!S||!k||Je(S,k)?.id!==x?.id)){if(l.has(S.id))return true;y+=1;}}if(m.length>0&&y===m.length)return false}return g.ranges.some(m=>{let y=n.indexOf(m.start.paragraphId),I=n.indexOf(m.end.paragraphId),x=n.indexOf(e);if(y<0||I<0||x<y||x>I)return false;let S=x===y?m.start.offset:0,k=x===I?m.end.offset:1/0;return r<=k&&a>=S})})?ee("unsupported-revision","proposal touches or overlaps a pending revision","span"):null}function Wn(n,e,r,a,i){let l=(B,G,X)=>({ok:false,error:{code:B,message:G,...X===void 0?{}:{detail:X}}}),f=B=>jt(B,r),g=B=>({ok:true,kind:"query",value:B}),m=Kn(n,e);if(m)return {ok:false,error:m};let y=n.op==="proposeInsertion",I=n.op==="proposeDeletion",x=V(n.span,r,a);if(!x.ok)return l(x.code,"that span is not a place",x.detail);let S=x.value;if(!S||S.start.paragraphId!==S.end.paragraphId)return l("unsupported-content","proposals require a single paragraph range","span");if(!e&&!y&&S.start.offset===S.end.offset)return l("unsupported-content","deletion and replacement need a non-empty range","span");let k=q(n.span,r,a);if(!k.ok)return l(k.code,"that story is not a place",k.detail);let A=S.start.paragraphId,b=y&&n.where==="After"?S.end.offset:S.start.offset,C=y?b:S.end.offset;if(e&&!I&&b===C&&n.text==="")return g({kind:"span",span:f({start:S.start,end:S.start})});let w=Vn(k.value,A,b,C);if(w)return {ok:false,error:w};let L=i(k.value,A);if(L)return L;let _={author:n.author.trim(),date:new Date().toISOString()},z=[];return !y&&C>b&&z.push({op:"deleteText",paragraphId:A,start:b,end:C,revision:_}),!I&&n.text.length>0&&z.push({op:"insertText",paragraphId:A,offset:y?b:C,text:n.text,revision:_}),{ok:true,kind:"command",ops:z,story:k.value.story,answer:()=>{if(!e)return {kind:"applied"};let B={...S.start,offset:y?b:C};return {kind:"span",span:f({start:B,end:{...B,offset:B.offset+(I?0:n.text.length)}})}}}}function zn(n,e,r){if("body"in n){let a=U(n.body,"body",e,r);return a.ok?{ok:true,reads:a.value}:{ok:false,code:a.code,message:"that handle does not name a body",detail:a.detail}}return e.resolve(n.document,"document")?r.body?{ok:true,reads:r.body}:{ok:false,code:"document-unavailable",message:"this host holds no document"}:{ok:false,code:"invalid-handle",message:"that handle does not name a document",detail:"document"}}function $n(n,e){let r=n.op==="acceptAllRevisions",a=e.story.kind==="note"?{scopeRootId:e.root.id}:{};return [r?{op:"acceptAllRevisions",...a}:{op:"rejectAllRevisions",...a}]}var ur=/[\r\n\u2028\u2029]/u,Xn=Object.freeze({kind:"applied"});function Pt(n,e,r){return {ok:false,error:Object.freeze(r===void 0?{code:n,message:e}:{code:n,message:e,detail:r})}}function ve(n,e){return Pt("unsupported-content",n==="author"?"a comment records who wrote it":n==="date"?"a comment date must be a valid ISO-8601 instant":e==="reply"?"a reply says something":"a comment says something",n)}function xe(n){return H(n.author)?ve("author",n.kind):I(n.text)?ve("text",n.kind):typeof n.text=="string"&&ur.test(n.text)?Pt("unsupported-content",n.kind==="reply"?"a reply is one paragraph in this slice":"a comment is one paragraph in this slice","text"):K$1(n.date)?ve("date",n.kind):null}function be(n){if(n===void 0)return;let e=J(n);return e.ok?e.value:void 0}function Un(n,e){let r=Ga(n.part,e);for(;r;){if(r.kind==="tableCell"||r.kind!=="textValue"&&r.namespaceUri===da&&r.localName==="tc")return r.id;r=Ha(n.part,r.id);}return null}function Yn(n,e,r,a){let i=xe({author:n.author,text:n.text,date:n.date,kind:"comment"});if(i)return i;let l=V(n.span,e,r);if(!l.ok)return Pt(l.code,"that span is not a place",l.detail);if(l.value===null)return Pt("invalid-handle","an empty story has no comment anchor");let f=q(n.span,e,r);if(!f.ok)return Pt(f.code,"that span is not a place",f.detail);let g=l.value;if(Un(f.value,g.start.paragraphId)!==Un(f.value,g.end.paragraphId))return Pt("unsupported-content","a comment range cannot cross a table-cell boundary");let m=a(f.value);if(m)return m;let y=be(n.date);return {ok:true,kind:"commentWrite",write:{kind:"create",anchor:{paragraphId:g.start.paragraphId,start:g.start.offset,end:g.end.offset,...g.end.paragraphId===g.start.paragraphId?{}:{endParagraphId:g.end.paragraphId}},text:n.text,author:n.author,...y===void 0?{}:{date:y}},story:f.value.story,answer:(x,S)=>S===void 0?Xn:{kind:"handle",handle:e.comment(S,f.value.story)}}}function Gn(n,e,r){let a=r(e);if(a)return a;let i=e.story;return {ok:true,kind:"commentWrite",write:{kind:"delete",commentId:n.id,...n.parentId===void 0?{}:{parentCommentId:n.parentId},...i.kind==="note"?{noteId:i.noteId}:{}},story:i,answer:()=>Xn}}var cr=1e4;function Jn(n,e){let r=[],a=e.kind==="contentControl"?Fc(e):e;if(!a)return r;for(let i of Jc(a))if(!(i.ancestors.length>0)){if(r.length>=cr)break;r.push(eo(n,i.node));}return r}function Qn(n,e){for(let r of Jc(n.root))if(r.node.id===e)return eo(n,r.node);return null}function Zn(n,e){for(let r of Jc(n.root))if(r.node.id===e)return r.node;return null}function qn(n,e){for(let r of n.paragraphIds){let a=n.node(r);if(!(!a||a.kind!=="paragraph")&&Jc(a).some(i=>i.node.id===e))return a}return null}function ne(n,e){let r=no(e);if(r.length>0){let l=r[0],f=r[r.length-1],g=n.rawText(f);return g===null||!n.has(l)?null:{start:{paragraphId:l,offset:0},end:{paragraphId:f,offset:g.length}}}let a=qn(n,e.id);if(!a)return null;let i=Me(a).spanOf(e);return i?{start:{paragraphId:a.id,offset:i.start},end:{paragraphId:a.id,offset:i.end}}:null}function pr(n,e,r){let a=qn(n,e.id),i=Fc(e);if(!a||!i)return null;let l={...a,children:i.children},f=Lh(l);return Zt(l,f,r).text}function to(n,e,r="allMarkup"){if(r==="allMarkup")return Lc(e);let a=pr(n,e,r);if(a!==null)return a;let i=ne(n,e);if(!i)return "";let l=n.indexOf(i.start.paragraphId),f=n.indexOf(i.end.paragraphId);if(l<0||f<l)return "";let g=[];for(let m=l;m<=f;m+=1){let y=n.paragraphIds[m],I=n.projectedText(y,r),x=n.rawText(y);if(!I||x===null)return "";g.push(I.sliceRaw(m===l?i.start.offset:0,m===f?i.end.offset:x.length));}return g.join("\r")}function eo(n,e){return {nodeId:e.id,properties:Hc(e),lock:lh(n.part,e.id),paragraphIds:no(e)}}function no(n){let e=Fc(n);if(!e)return [];let r=[];return Ad(e.children,r,0),r.map(a=>a.id)}function Ie(n){let e=n.kind==="contentControl"?Fc(n):n;return e?Jc(e).map(r=>r.node):[]}var oo=new Set(["unlocked","sdtLocked","contentLocked","sdtContentLocked"]),ro=new Set(["whole","content","start","end","before","after"]),ao=new Set(["richText","plainText","dropDownList","comboBox","date"]),mr=4096;function so(n){let e=(i,l)=>({ok:false,code:"unsupported-content",message:i,detail:l});if(typeof n!="object"||n===null||!("kind"in n))return e("a control value states its kind","value");let r=n,a=r.kind;if(a==="text"||a==="listItem"){let i=a==="text"?r.text:r.value;return typeof i!="string"?e("that value is not a string",String(a)):i.length>mr?e("that value is too long",String(i.length)):{ok:true,value:a==="text"?{kind:"text",text:i}:{kind:"listItem",value:i}}}if(a==="checkbox"){let i=r.checked;return typeof i!="boolean"?e("a checkbox is checked or not","checked"):{ok:true,value:{kind:"checkbox",checked:i}}}if(a==="date"){let i=r.iso;return typeof i!="string"?e("a date is an ISO-8601 string","iso"):i.length>64?e("that is not a date",String(i.length)):{ok:true,value:{kind:"date",iso:i}}}return e("that is not a value any control accepts",String(a))}var fr=new Set(["unlocked","sdtLocked","contentLocked","sdtContentLocked"]),yr=4096,io=64;function lo(n){if(n===void 0)return {ok:true,value:null};if(typeof n!="object"||n===null)return {ok:false,field:"payload"};let e=n;for(let r of ["namespaceUri","rootLocalName","nodeId"]){let a=e[r];if(typeof a!="string"||a.length===0||a.length>yr)return {ok:false,field:r}}return typeof e.label!="string"||e.label.length>V$1?{ok:false,field:"label"}:typeof e.data!="string"||e.data.length===0||e.data.length>U$1?{ok:false,field:"data"}:{ok:true,value:{namespaceUri:e.namespaceUri,rootLocalName:e.rootLocalName,nodeId:e.nodeId,label:e.label,data:e.data}}}function uo(n){let e=n.at!==void 0,r=n.span!==void 0;return e===r?{message:"a custom node goes at a position or over a span, not both",detail:e?"at+span":"no-place"}:typeof n.tag!="string"||n.tag.length===0?{message:"a custom node carries its identity in its tag",detail:"tag"}:n.tag.length>io?{message:`w:tag caps at ${String(io)} characters; a longer payload belongs in the store`,detail:"tag"}:typeof n.text!="string"||n.text.length===0?{message:"a custom node shows some text",detail:"text"}:n.lock!==void 0&&!fr.has(n.lock)?{message:"that is not a lock",detail:String(n.lock)}:null}function co(n,e,r,a){return {paragraphId:e.paragraphId,offset:e.offset,...r.offset>e.offset?{replaceUntil:r.offset}:{},tag:n.tag,text:n.text,...n.title===void 0?{}:{alias:n.title},...n.lock===void 0||n.lock==="unlocked"?{}:{lock:n.lock},...a===null?{}:{payload:a}}}function po(n,e,r){if(n.span){let i=V(n.span,e,r);return i.ok?i.value?i.value.start.paragraphId!==i.value.end.paragraphId?{code:"unsupported-content",message:"a custom node wraps text inside one paragraph",detail:"multi-paragraph"}:{range:i.value}:{code:"invalid-offset",message:"that story holds nothing to wrap",detail:"empty-story"}:{code:i.code,message:"that span is not a place",detail:i.detail}}let a=Ct(n.at,e,r);return a.ok?{range:{start:a.value,end:a.value}}:{code:a.code,message:"that is not a place",detail:a.detail}}var _t=/[\r\n\v\f\u2028\u2029]/,gr=16,hr=64,mo=/\s/;function kr(n,e,r){return Object.freeze(r===void 0?{code:n,message:e}:{code:n,message:e,detail:r})}function d(n,e,r){return {ok:false,error:kr(n,e,r)}}var D=Object.freeze({kind:"applied"});function O(n){return {ok:true,kind:"query",value:n}}function Ar(n,e){let r=[],a=0;for(;a<n.length;){let i=null;for(let l of e){let f=n.indexOf(l,a);f<0||(!i||f<i.start||f===i.start&&l.length>i.length)&&(i={start:f,length:l.length});}if(!i)break;r.push(i),a=i.start+i.length;}return r}function vr(n,e,r){let a=e[r]?.markParagraphId??null;if(a!==null)return a;let i=n.paragraphIds,l=i[i.length-1];return l===void 0||new Set(e.map(g=>g.markParagraphId).filter(g=>g!==null)).has(l)?null:l}function xr(n,e){for(let r of [n.start,n.end]){let a=e.rawText(r.paragraphId);if(a===null||r.offset>a.length)return false}return true}function br(n,e,r){let a=e,i=r;for(;a<i&&mo.test(n[a]);)a+=1;for(;i>a&&mo.test(n[i-1]);)i-=1;return [a,i]}function fo(n){let{handles:e,capabilities:r}=n,a=n.reads,i=new Map,l=o=>{let u=K(o.story),p=i.get(u);if(p)return p;let t=new Map,s=o.paragraphIds.map(h=>{let v={id:h};return t.set(h,v),v}),c={reads:o,order:s,slotById:t,created:[],restructured:new Set,touched:new Set,formatted:new Set,selected:new Set,retargets:[]};return i.set(u,c),c},f=[],g=Cn(),m=null,y=o=>m===null?(m=o,null):m===o?null:d("conflicting-operations","one batch writes into one story",`${K(m.reads.story)} then ${K(o.reads.story)}`),I=o=>y(l(o)),x=o=>{let u=a.package;return u===null?null:Dn(u,o)},S=o=>{let u=e.resolve(o,"comment");if(!u||u.kind!=="comment")return {ok:false,planned:d("invalid-handle","that handle does not name a comment","comment")};let p=a.story(u.story);if(!p)return {ok:false,planned:d("invalid-handle","that story is not in this document")};let s=x(p)?.byId(u.commentId)??null;return s?{ok:true,reads:p,item:s}:{ok:false,planned:d("invalid-handle","this document no longer holds that comment",u.commentId)}},k=o=>{let u=e.resolve(o,"revision");if(!u||u.kind!=="revision")return {ok:false,planned:d("invalid-handle","that handle does not name a tracked change","revision")};let p=a.story(u.story);if(!p)return {ok:false,planned:d("invalid-handle","that story is not in this document")};let t=Ae(p).find(s=>s.id===u.revisionId)??null;return t?{ok:true,reads:p,item:t}:{ok:false,planned:d("invalid-handle","this document no longer holds that tracked change",u.revisionId)}},A=(o,u)=>{let p=o.rawText(u.start.paragraphId),t=o.rawText(u.end.paragraphId);if(p===null||t===null)return null;let s={story:o.story,paragraphId:u.start.paragraphId,index:o.indexOf(u.start.paragraphId),offset:Math.min(u.start.offset,p.length)},c={story:o.story,paragraphId:u.end.paragraphId,index:o.indexOf(u.end.paragraphId),offset:Math.min(u.end.offset,t.length)};return B({start:s,end:c})},b=(o,u)=>o.order.indexOf(u),C=(o,u)=>o.selected.has(u)?d("conflicting-operations","this batch selects a paragraph it also edits",u):null,w=(o,u)=>{let p=C(o,u);return p||(o.restructured.has(u)||o.touched.has(u)?d("conflicting-operations","another operation in this batch already changes that paragraph",u):(o.restructured.add(u),o.touched.add(u),null))},L=(o,u)=>{let p=C(o,u);return p||(o.restructured.has(u)?d("conflicting-operations","another operation in this batch restructures that paragraph",u):(o.touched.add(u),null))},_=(o,u,p)=>{let t=`${p}:${u}`;if(o.formatted.has(t))return d("conflicting-operations","another operation in this batch already writes that formatting",u);let s=L(o,u);return s||(o.formatted.add(t),null)},z=(o,u)=>{let p={id:null};return o.order.splice(u,0,p),o.created.push(p),p},B=o=>jt(o,e),G=o=>o===null?null:a.story(o.start.story),X=o=>o===void 0||o==="allMarkup"||o==="original"||o==="model",it=(o,u,p,t)=>{if(!X(t?.projection))return d("unsupported-content","unknown text projection","projection");if(t?.matchWildcards===true)return d("unsupported-capability","wildcard search is not implemented","matchWildcards");if(t?.ignorePunct===true)return d("unsupported-capability","ignoring punctuation is not implemented","ignorePunct");if(t?.ignoreSpace===true)return d("unsupported-capability","ignoring whitespace is not implemented","ignoreSpace");if(!Ra(p))return d("unsupported-content","that is not a query this host will scan for","text");let s=t?.limit;if(s!==void 0&&(!Number.isInteger(s)||s<0))return d("invalid-offset","limit must be a non-negative integer",String(s));let c=Fn(o,u,e,p,t);return O({kind:"spans",spans:c.spans})},xt=(o,u,p)=>{if(typeof p!="string")return d("unsupported-content","insertText needs text","text");if(_t.test(p))return d("unsupported-content","text carrying a paragraph mark is not written by this host","paragraph-mark-in-text");let t=y(o);if(t)return t;let s=L(o,u.paragraphId);if(s)return s;let c=p.length===0?[]:[{op:"insertText",paragraphId:u.paragraphId,offset:u.offset,text:p}],h=()=>({kind:"span",span:B({start:u,end:{...u,offset:u.offset+p.length}})});return {ok:true,kind:"command",ops:c,story:o.reads.story,answer:h}},$=(o,u,p)=>{let t=o.reads;if(typeof p!="string")return d("unsupported-content","replaceSpan needs text","text");if(_t.test(p))return d("unsupported-content","text carrying a paragraph mark is not written by this host","paragraph-mark-in-text");let s=at(u,t),c=u.start.paragraphId,h=[],v=y(o);if(v)return v;if(s.length===1){let j=L(o,c);if(j)return j;u.end.offset>u.start.offset&&h.push({op:"deleteText",paragraphId:c,start:u.start.offset,end:u.end.offset});}else {for(let E of s){let M=w(o,E);if(M)return M}let j=u.end.paragraphId,dt=(t.rawText(c)??"").length;u.start.offset<dt&&h.push({op:"deleteText",paragraphId:c,start:u.start.offset,end:dt}),u.end.offset>0&&h.push({op:"deleteText",paragraphId:j,start:0,end:u.end.offset});for(let E of s.slice(1,-1))h.push({op:"deleteBlock",blockId:E});h.push({op:"joinParagraphs",firstId:c,secondId:j});for(let E of s.slice(1)){let M=o.slotById.get(E);M&&o.order.splice(b(o,M),1);}}let R=s.length===1?u.end.offset:(t.rawText(c)??"").length,T=n.replacementLanding?.(c,u.start.offset,R)??u.start.offset;p.length>0&&h.push({op:"insertText",paragraphId:c,offset:T,text:p});let W={...u.start,paragraphId:c,offset:T},H=()=>({kind:"span",span:B({start:W,end:{...W,offset:W.offset+p.length}})});return {ok:true,kind:"command",ops:h,story:o.reads.story,answer:H}},bt=(o,u)=>{let p=o.reads;if(typeof u!="string")return d("unsupported-content","replaceSpan needs text","text");if(_t.test(u))return d("unsupported-content","text carrying a paragraph mark is not written by this host","paragraph-mark-in-text");let t=p.blocks,s=t.filter(E=>E.removable),c=t.filter(E=>!E.removable).flatMap(E=>E.paragraphIds),h=c.length===0?s.find(E=>E.kind==="paragraph"):void 0;if(!h&&c.length===0)return d("invalid-offset","that story holds no paragraph this host can write into","no-top-level-paragraph");let v=y(o);if(v)return v;for(let E of p.paragraphIds){let M=w(o,E);if(M)return M}let R=[],P=(h?[h.id]:[...c]).sort((E,M)=>p.indexOf(E)-p.indexOf(M)),T=P[0],W=(p.rawText(T)??"").length;for(let E of P){let M=(p.rawText(E)??"").length;M>0&&R.push({op:"deleteText",paragraphId:E,start:0,end:M});}for(let E of s)E.id!==h?.id&&R.push({op:"deleteBlock",blockId:E.id});let H=n.replacementLanding?.(T,0,W)??0;u.length>0&&R.push({op:"insertText",paragraphId:T,offset:H,text:u});for(let E of s)if(E.id!==h?.id)for(let M of E.paragraphIds){let ot=o.slotById.get(M);ot&&o.order.splice(b(o,ot),1);}let j={story:p.story,paragraphId:T,index:p.indexOf(T),offset:H},dt=()=>({kind:"span",span:B({start:j,end:{...j,offset:H+u.length}})});return {ok:true,kind:"command",ops:R,story:p.story,answer:dt}},gt=(o,u)=>{if(!Array.isArray(u)||u.length<1||u.length>1e4||u.some(t=>typeof t!="string"||_t.test(t)||!O$1(t)))return d("unsupported-content","replaceStoryBlocks needs 1-10000 valid XML text strings without paragraph marks","paragraphs");let p=y(o);if(p)return p;for(let t of o.reads.paragraphIds){let s=w(o,t);if(s)return s}o.order.splice(0,o.order.length);for(let t=0;t<u.length;t+=1)z(o,t);return {ok:true,kind:"command",ops:[{op:"replaceStoryBlocks",storyRootId:o.reads.root.id,paragraphs:u}],story:o.reads.story,answer:()=>D}},Tt=(o,u,p,t)=>{let s=o.reads;if(typeof t!="string")return d("unsupported-content","insertParagraph needs text","text");if(_t.test(t))return d("unsupported-content","a paragraph mark inside a paragraph\u2019s text is not written by this host","paragraph-mark-in-text");let c=y(o);if(c)return c;let h=w(o,u.paragraphId);if(h)return h;let v=o.slotById.get(u.paragraphId);if(!v)return d("invalid-handle","that paragraph is not in the body");let R=(s.rawText(u.paragraphId)??"").length,P=[];p==="after"?(t.length>0&&P.push({op:"insertText",paragraphId:u.paragraphId,offset:R,text:t}),P.push({op:"splitParagraph",paragraphId:u.paragraphId,offset:R})):(t.length>0&&P.push({op:"insertText",paragraphId:u.paragraphId,offset:0,text:t}),P.push({op:"splitParagraph",paragraphId:u.paragraphId,offset:t.length}));let T=z(o,b(o,v)+1);p==="before"&&o.retargets.push({from:u.paragraphId,slot:T});let W=()=>{let H=p==="after"?T.id:u.paragraphId;return H===null?D:{kind:"handle",handle:e.paragraph(H,s.story)}};return {ok:true,kind:"command",ops:P,story:s.story,answer:W}},wt=(o,u,p,t,s)=>{let c=o.reads;if(!Array.isArray(p)||p.length===0)return d("unsupported-content","split needs at least one delimiter","delimiters");if(p.length>gr)return d("unsupported-content","too many delimiters",String(p.length));for(let M of p){if(typeof M!="string"||M.length===0)return d("unsupported-content","a delimiter must be a non-empty string","delimiters");if(M.length>hr)return d("unsupported-content","that delimiter is too long","delimiters")}let h=y(o);if(h)return h;let v=w(o,u.paragraphId);if(v)return v;let R=o.slotById.get(u.paragraphId);if(!R)return d("invalid-handle","that paragraph is not in the body");let P=c.rawText(u.paragraphId)??"",T=Ar(P,p),W=[],H=[],j=[];if(T.length===0)j.push(P);else if(t){for(let J of [...T].reverse())W.push({op:"deleteText",paragraphId:u.paragraphId,start:J.start,end:J.start+J.length});let M=0,ot=0;for(let J of T){let oe=J.start-M;H.push(oe),j.push(P.slice(ot,J.start)),ot=J.start+J.length,M+=J.length;}j.push(P.slice(ot));}else {let M=0;for(let ot of T){let J=ot.start+ot.length;H.push(J),j.push(P.slice(M,J)),M=J;}j.push(P.slice(M));}H.length>0&&W.push({op:"splitParagraphMany",paragraphId:u.paragraphId,offsets:H});let dt=[R];for(let M=0;M<H.length;M+=1)dt.push(z(o,b(o,R)+1+M));let E=M=>{let ot=M.story(c.story),J=[];return dt.forEach((oe,Ao)=>{let re=oe.id;if(re===null)return;let ae=ot?.rawText(re)??j[Ao]??"",[vo,xo]=s?br(ae,0,ae.length):[0,ae.length],Pe=e.paragraph(re,c.story);J.push({start:{paragraph:Pe,offset:vo},end:{paragraph:Pe,offset:xo}});}),{kind:"spans",spans:J}};return {ok:true,kind:"command",ops:W,story:c.story,answer:E}},Ft=(o,u)=>{let p=y(o);if(p)return p;let t=w(o,u.paragraphId);if(t)return t;let s=o.slotById.get(u.paragraphId);return s&&o.order.splice(b(o,s),1),{ok:true,kind:"command",ops:[{op:"deleteBlock",blockId:u.paragraphId}],story:o.reads.story,answer:()=>D}},Se=(o,u,p)=>{let t=o.reads,s=t.part,c=y(o);if(c)return c;let h=Sn(p??{});if(!h.ok)return d("unsupported-content","that is not formatting this host writes",h.detail);let v=[];for(let R of ye(u,t)){if(R.end<=R.start&&!R.whole)continue;let P=_(o,R.paragraphId,"runs");if(P)return P;for(let T of ra(s,R.paragraphId,R.start,R.end,h.value,n.displayMode))v.push({op:"setRunProperties",paragraphId:R.paragraphId,start:T.start,end:T.end,properties:T.properties,...T.targetRunIds?{targetRunIds:T.targetRunIds}:{}});R.whole&&v.push({op:"setParagraphMarkProperties",paragraphId:R.paragraphId,properties:qa(s,R.paragraphId,h.value)});}return v.length===0?d("invalid-offset","that range covers no characters to format","collapsed-range"):{ok:true,kind:"command",ops:v,story:t.story,answer:()=>D}},N=(o,u,p)=>{let t=o.reads,s=t.part,c=y(o);if(c)return c;let h=Jt(p,t.styles());if(!h.ok)return d("unsupported-content","that is not a style this document has",h.detail);let v={localName:"pStyle",attributes:{val:h.styleId}},R=[];for(let P of at(u,t)){let T=_(o,P,"paragraph");if(T)return T;R.push({op:"setParagraphProperties",paragraphId:P,properties:la(ja(s,P),v)});}return R.length===0?d("invalid-offset","that story holds no paragraph to style","empty-story"):{ok:true,kind:"command",ops:R,story:t.story,answer:()=>D}},It=(o,u,p)=>{let t=o.reads,s=t.part,c=y(o);if(c)return c;let h=Rn(s,u.paragraphId,p??{},t.styles());if(!h.ok)return d("unsupported-content","that is not paragraph formatting this host writes",h.detail);let v=_(o,u.paragraphId,"paragraph");return v||{ok:true,kind:"command",ops:[{op:"setParagraphProperties",paragraphId:u.paragraphId,properties:h.value}],story:t.story,answer:()=>D}},ft=(o,u)=>{let p=a.body;if(!p)return d("document-unavailable","this host holds no document right now");let t=a.sections();if(!t[o])return d("invalid-handle","that section is not in this document");let c=On(u);if(!c.ok)return d("unsupported-content",c.reason,c.detail);let h=vr(p,t,o);if(h===null)return d("unsupported-content","that section holds no paragraph to address it by","no-anchor");let v=l(p),R=y(v);return R||{ok:true,kind:"command",ops:[{op:"setSectionProperties",...c.value,anchorParagraphId:h}],story:yt,answer:()=>D}},Y=(o,u)=>({ok:true,kind:"command",ops:[{op:"deleteNote",noteKind:o,noteId:u}],story:yt,lifecycle:true,answer:()=>D}),nt=o=>{let u=e.resolve(o,"list");if(!u||u.kind!=="list")return d("invalid-handle","that handle does not name a list","list");let p=a.story(u.story);if(!p)return d("invalid-handle","that story is not in this document");let t=te(p).find(s=>s.numId===u.numId);return t?{ok:true,plan:l(p),list:t}:d("invalid-handle","this story numbers nothing with that list",u.numId)},Nt=o=>{if(typeof o!="object"||o===null)return d("invalid-handle","that is not a scope a control lives in","scope");let u=o;if("body"in o){let p=U(u.body,"body",e,a);return p.ok?{reads:p.value,node:p.value.root}:d(p.code,"that handle does not name a body",p.detail)}if("contentControl"in o){let p=Z(u.contentControl);return "control"in p?{reads:p.reads,node:p.node}:p}return d("invalid-handle","that is not a scope a control lives in","scope")},Z=o=>{let u=e.resolve(o,"contentControl");if(!u||u.kind!=="contentControl")return d("invalid-handle","that handle does not name a content control","contentControl");let p=a.story(u.story);if(!p)return d("invalid-handle","that story is not in this document");let t=Qn(p,u.nodeId),s=Zn(p,u.nodeId);return !t||!s?d("invalid-handle","this document no longer holds that content control"):{reads:p,control:t,node:s}},yo=(o,u,p)=>{if(!Number.isInteger(p)||p<0||p>Ot)return d("invalid-offset",`a list level is 0 to ${String(Ot)}`,String(p));if(!Bt(o.reads,u))return d("unsupported-content","that paragraph is not in a list",u);let t=y(o);if(t)return t;let s=_(o,u,"paragraph");return s||{ok:true,kind:"command",ops:[{op:"setListLevel",paragraphId:u,level:p}],story:o.reads.story,answer:()=>D}},go=(o,u,p,t)=>{if(p!=="start"&&p!=="end")return d("unknown-operation","a list takes an item at its start or its end",String(p));let s=o.reads,c=p==="start"?u.paragraphIds[0]:u.paragraphIds[u.paragraphIds.length-1];if(c===void 0)return d("invalid-handle","that list holds no paragraph");let h={story:s.story,paragraphId:c,index:s.indexOf(c)};return Tt(o,h,p==="start"?"before":"after",t)},Re=(o,u)=>{if(u.start.paragraphId!==u.end.paragraphId)return null;for(let p of En(o,u.start.paragraphId))if(p.start<=u.start.offset&&p.end>=u.end.offset)return p;return null},ho=(o,u,p)=>{if(typeof p!="string")return d("unsupported-content","a hyperlink target is a string","target");let t=o.reads,s=Re(t,u),c=u.start.paragraphId===u.end.paragraphId&&u.start.offset===u.end.offset;if(p.length===0){if(!s)return d("unsupported-content","that text is not a link","no-link");let H=y(o);if(H)return H;let j=L(o,s.paragraphId);return j||{ok:true,kind:"command",ops:[{op:"removeHyperlink",linkId:s.id}],story:t.story,answer:()=>D}}let h={},v=null;if(p.startsWith("#")){let H=p.slice(1);if(H.length===0||!ke(t,H))return d("unsupported-content","this document declares no such bookmark",p);h={anchor:H};}else {if(mf(p)===null)return d("unsupported-content","this engine will not author that target","target");v=p;}let R=y(o);if(R)return R;let P=H=>v===null?{ok:true,kind:"command",ops:[H(h)],story:t.story,answer:()=>D}:{ok:true,kind:"command",ops:[],relate:{url:v,ops:j=>[H({relationshipId:j})]},story:t.story,answer:()=>D};if(s){let H=L(o,s.paragraphId);return H||P(j=>({op:"setHyperlinkTarget",linkId:s.id,...j}))}if(c)return d("unsupported-content","a link with no text has nothing to click","collapsed");if(u.start.paragraphId!==u.end.paragraphId)return d("unsupported-content","a link lives inside one paragraph","crosses-paragraph-mark");let T=L(o,u.start.paragraphId);if(T)return T;let W=t.styles().idOf("hyperlink");return P(H=>({op:"insertHyperlink",paragraphId:u.start.paragraphId,start:u.start.offset,end:u.end.offset,...H,...W===null?{}:{styleId:W}}))},Ce=(o,u,p)=>{let t=o.reads;if(!r.selection||!n.select)return d("unsupported-capability","this host has no reader to move","selection");if(p!=="select"&&p!=="start"&&p!=="end")return d("unknown-operation","that is not a selection mode",String(p));let s=at(u,t);for(let c of s)if(o.touched.has(c))return d("conflicting-operations","this batch edits a paragraph the selection covers",c);for(let c of s)o.selected.add(c);return f.push({range:u,mode:p}),{ok:true,kind:"command",ops:[],story:t.story,answer:()=>D}},Oe=o=>{let u=e.resolve(o,"bookmark");if(!u||u.kind!=="bookmark")return d("invalid-handle","that handle does not name a bookmark","bookmark");let p=a.story(u.story);if(!p)return d("invalid-handle","that story is not in this document");let t=ke(p,u.name);if(!t)return d("invalid-handle","this document no longer declares that bookmark",u.name);let s=c=>({story:p.story,paragraphId:c.paragraphId,index:p.indexOf(c.paragraphId),offset:c.offset});return {reads:p,range:{start:s(t.start),end:s(t.end)}}},ko=(o,u)=>{let p=u!==void 0;switch(p&&o.op==="insertText"?o={op:"proposeInsertion",span:{start:o.at,end:o.at},text:o.text,where:"Before",author:u}:p&&o.op==="replaceSpan"&&(o={op:"proposeReplacement",span:o.span,text:o.text,author:u}),o.op){case "getDocument":return O({kind:"handle",handle:e.document()});case "getBody":return e.resolve(o.document,"document")?a.body?O({kind:"handle",handle:e.body(yt)}):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=U(o.body,"body",e,a);return t.ok?O({kind:"handles",handles:t.value.paragraphIds.map(s=>e.paragraph(s,t.value.story))}):d(t.code,"that handle does not name a body",t.detail)}case "getSpanParagraphs":{let t=V(o.span,e,a);if(!t.ok)return d(t.code,"that span is not a place",t.detail);let s=q(o.span,e,a);return s.ok?O({kind:"handles",handles:at(t.value,s.value).map(c=>e.paragraph(c,s.value.story))}):d(s.code,"that span is not a place",s.detail)}case "getText":{if(!X(o.projection))return d("unsupported-content","unknown text projection","projection");if(e.resolve(o.target,"body")){let h=U(o.target,"body",e,a);return h.ok?O({kind:"text",text:h.value.text(o.projection??"allMarkup")}):d(h.code,"that handle does not name a body",h.detail)}let s=et(o.target,e,a);if(!s.ok)return d(s.code,"that handle does not name a body or a paragraph",s.detail);let c=a.story(s.value.story);return O({kind:"text",text:c?.paragraphText(s.value.paragraphId,o.projection??"allMarkup")??""})}case "getSpanText":{if(!X(o.projection))return d("unsupported-content","unknown text projection","projection");let t=V(o.span,e,a);if(!t.ok)return d(t.code,"that span is not a place",t.detail);let s=q(o.span,e,a);return s.ok?O({kind:"text",text:Mn(t.value,s.value,fe,o.projection??"allMarkup")}):d(s.code,"that span is not a place",s.detail)}case "getParagraphId":{let t=et(o.paragraph,e,a);if(!t.ok)return d(t.code,"that handle does not name a paragraph",t.detail);let c=a.story(t.value.story)?.paragraph(t.value.paragraphId);return O({kind:"text",text:c?.paraId??""})}case "search":{let t=V(o.scope,e,a);if(!t.ok)return d(t.code,"that is not a scope to search",t.detail);let s=q(o.scope,e,a);return s.ok?it(s.value,t.value,o.text,o.options):d(s.code,"that is not a scope to search",s.detail)}case "proposeInsertion":case "proposeDeletion":case "proposeReplacement":return Wn(o,p,e,a,(t,s)=>{let c=l(t);return y(c)??w(c,s)});case "insertText":{let t=Ct(o.at,e,a);if(!t.ok)return d(t.code,"that is not a place to insert at",t.detail);let s=a.story(t.value.story);return s?xt(l(s),t.value,o.text):d("invalid-handle","that story is not in this document")}case "replaceSpan":{if("body"in o.span){let c=U(o.span.body,"body",e,a);return c.ok?bt(l(c.value),o.text):d(c.code,"that handle does not name a body",c.detail)}let t=V(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 s=G(t.value);return s?$(l(s),t.value,o.text):d("invalid-handle","that story is not in this document")}case "replaceStoryBlocks":{let t=U(o.body,"body",e,a);return t.ok?gt(l(t.value),o.paragraphs):d(t.code,"that handle does not name a body",t.detail)}case "insertParagraph":{let t=qt(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 s=a.story(t.value.story);return s?Tt(l(s),t.value,o.where,o.text):d("invalid-handle","that story is not in this document")}case "splitParagraph":{let t=et(o.paragraph,e,a);if(!t.ok)return d(t.code,"that handle does not name a paragraph",t.detail);let s=a.story(t.value.story);return s?wt(l(s),t.value,o.delimiters,o.trimDelimiters===true,o.trimSpacing===true):d("invalid-handle","that story is not in this document")}case "getFont":{let t=V(o.span,e,a);if(!t.ok)return d(t.code,"that span is not a place",t.detail);let s=q(o.span,e,a);if(!s.ok)return d(s.code,"that span is not a place",s.detail);let c=ye(t.value,s.value);return O({kind:"font",font:bn(s.value.part,c,n.displayMode)})}case "setFont":{let t=V(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 s=G(t.value);return s?Se(l(s),t.value,o.font):d("invalid-handle","that story is not in this document")}case "getStyle":{let t=V(o.span,e,a);if(!t.ok)return d(t.code,"that span is not a place",t.detail);let s=q(o.span,e,a);if(!s.ok)return d(s.code,"that span is not a place",s.detail);let c=s.value.part,h=s.value.styles(),v=at(t.value,s.value).map(P=>Gt(c,P,h)),R=v.length>0&&v.every(P=>P!==null&&P===v[0])?v[0]:null;return O({kind:"style",name:R})}case "setStyle":{let t=V(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 s=G(t.value);return s?N(l(s),t.value,o.name):d("invalid-handle","that story is not in this document")}case "getParagraphFormat":{let t=qt(o.paragraph,e,a);if(!t.ok)return d(t.code,"that is not a paragraph",t.detail);let s=a.story(t.value.story);if(!s)return d("document-unavailable","this host holds no document right now");let c=In(s.part,t.value.paragraphId,s.styles());return c?O({kind:"paragraphFormat",format:c}):d("invalid-handle","that handle does not name a paragraph")}case "setParagraphFormat":{let t=qt(o.paragraph,e,a);if(!t.ok)return d(t.code,"that is not a paragraph",t.detail);let s=a.story(t.value.story);return s?It(l(s),t.value,o.format):d("invalid-handle","that story is not in this document")}case "deleteParagraph":{let t=et(o.paragraph,e,a);if(!t.ok)return d(t.code,"that handle does not name a paragraph",t.detail);let s=a.story(t.value.story);return s?Ft(l(s),t.value):d("invalid-handle","that story is not in this document")}case "getSections":return e.resolve(o.document,"document")?O({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 s=a.sections()[t.index];return s?O({kind:"pageSetup",setup:s.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"):ft(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 s={kind:o.kind,sectionIndex:t.index,variant:o.variant};return hn(s)?a.story(s)?O({kind:"handle",handle:e.body(s)}):d("invalid-handle","this document declares no such header or footer",K(s)):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,s=a.noteIds(t);return s.ok?O({kind:"handles",handles:s.ids.map(c=>e.note(t,c))}):d("ambiguous-document",`${t} identities are not completely and unambiguously enumerable`,s.reason==="duplicates"?s.duplicateIds.join(","):s.reason)}case "getNoteBody":case "getNoteText":{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 s=t,c=a.story(s);return c?o.op==="getNoteText"?O({kind:"text",text:c.text(o.projection)}):O({kind:"handle",handle:e.body(s)}):d("invalid-handle","that note is not in this document",K(s))}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"):O({kind:"text",text:t.noteKind})}case "deleteNote":{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 s=a.noteIds(t.noteKind);return s.ok?s.ids.includes(t.noteId)?Y(t.noteKind,t.noteId):d("invalid-handle","that note is not in this document"):d("ambiguous-document",`${t.noteKind} identities are not completely and unambiguously enumerable`,s.reason==="duplicates"?s.duplicateIds.join(","):s.reason)}case "getLists":{let t=U(o.body,"body",e,a);return t.ok?O({kind:"handles",handles:te(t.value).map(s=>e.list(s.numId,t.value.story))}):d(t.code,"that handle does not name a body",t.detail)}case "getListId":{let t=nt(o.list);return "list"in t?O({kind:"number",value:Number(t.list.numId)}):t}case "getListById":{let t=U(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 s=String(o.id),c=te(t.value).find(h=>h.numId===s);return c?O({kind:"handle",handle:e.list(c.numId,t.value.story)}):d("invalid-handle","no list in that story carries that number",s)}case "getListParagraphs":{let t=nt(o.list);if(!("list"in t))return t;let s=o.level;if(s!==void 0&&(!Number.isInteger(s)||s<0||s>Ot))return d("invalid-offset",`a list level is 0 to ${String(Ot)}`,String(s));let c=t.plan.reads,h=s===void 0?t.list.paragraphIds:t.list.paragraphIds.filter(v=>Bt(c,v)?.level===s);return O({kind:"handles",handles:h.map(v=>e.paragraph(v,c.story))})}case "getParagraphList":{let t=et(o.paragraph,e,a);if(!t.ok)return d(t.code,"that handle does not name a paragraph",t.detail);let s=a.story(t.value.story);if(!s)return d("invalid-handle","that story is not in this document");let c=Bt(s,t.value.paragraphId);return c?O({kind:"handle",handle:e.list(c.numId,s.story)}):d("unsupported-content","that paragraph is not in a list",t.value.paragraphId)}case "getListLevel":{let t=et(o.paragraph,e,a);if(!t.ok)return d(t.code,"that handle does not name a paragraph",t.detail);let s=a.story(t.value.story);if(!s)return d("invalid-handle","that story is not in this document");let c=Bt(s,t.value.paragraphId);return c?O({kind:"number",value:c.level}):d("unsupported-content","that paragraph is not in a list",t.value.paragraphId)}case "setListLevel":{let t=et(o.paragraph,e,a);if(!t.ok)return d(t.code,"that handle does not name a paragraph",t.detail);let s=a.story(t.value.story);return s?yo(l(s),t.value.paragraphId,o.level):d("invalid-handle","that story is not in this document")}case "insertListParagraph":{let t=nt(o.list);return "list"in t?go(t.plan,t.list,o.where,o.text):t}case "getHyperlink":{let t=V(o.span,e,a);if(!t.ok)return d(t.code,"that span is not a place",t.detail);let s=q(o.span,e,a);if(!s.ok)return d(s.code,"that span is not a place",s.detail);let c=a.package;if(!c||!t.value)return O({kind:"text",text:""});let h=Re(s.value,t.value);if(!h)return O({kind:"text",text:""});let v=Ga(s.value.part,h.id),R=v?jn(c,s.value.part.name,v):null;return O({kind:"text",text:R??""})}case "setHyperlink":{let t=V(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 s=G(t.value);return s?ho(l(s),t.value,o.target):d("invalid-handle","that story is not in this document")}case "getBookmarks":{let t=V(o.scope,e,a);if(!t.ok)return d(t.code,"that span is not a place",t.detail);let s=q(o.scope,e,a);if(!s.ok)return d(s.code,"that span is not a place",s.detail);let c=s.value,h=t.value,v=h===null?null:new Set(at(h,c)),R=he(c).filter(P=>{if(!v||!v.has(P.start.paragraphId)&&!v.has(P.end.paragraphId)||h===null)return false;let T=P.start.paragraphId===h.end.paragraphId&&P.start.offset>h.end.offset,W=P.end.paragraphId===h.start.paragraphId&&P.end.offset<h.start.offset;return !T&&!W});return O({kind:"handles",handles:R.map(P=>e.bookmark(P.name,c.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"):O({kind:"text",text:t.name})}case "getBookmarkRange":{let t=Oe(o.bookmark);return "reads"in t?O({kind:"span",span:B(t.range)}):t}case "getComments":{let t=V(o.scope,e,a);if(!t.ok)return d(t.code,"that scope is not a place",t.detail);let s=q(o.scope,e,a);if(!s.ok)return d(s.code,"that scope names no story",s.detail);let c=s.value,h=x(c);if(!h)return d("document-unavailable","this host holds no document");let v=t.value,R=h.roots.filter(P=>{if(!v)return true;let T=P.range;if(!T)return false;let W=c.indexOf(T.start.paragraphId),H=c.indexOf(T.end.paragraphId),j=c.indexOf(v.start.paragraphId),dt=c.indexOf(v.end.paragraphId);return H<j||W>dt?false:H===j&&W===j&&dt===j?T.end.offset>v.start.offset&&T.start.offset<v.end.offset:true});return O({kind:"handles",handles:R.map(P=>e.comment(P.id,c.story))})}case "getCommentReplies":{let t=S(o.comment);return t.ok?O({kind:"handles",handles:t.item.replyIds.map(s=>e.comment(s,t.reads.story))}):t.planned}case "getCommentId":{let t=S(o.comment);return t.ok?O({kind:"text",text:t.item.id}):t.planned}case "getCommentAuthor":{let t=S(o.comment);return t.ok?O({kind:"text",text:t.item.comment.author}):t.planned}case "getCommentDate":{let t=S(o.comment);return t.ok?O({kind:"text",text:t.item.comment.date??""}):t.planned}case "getCommentText":{let t=S(o.comment);if(!t.ok)return t.planned;let s=x(t.reads);return O({kind:"text",text:s?.textOf(t.item.id)??""})}case "getCommentRange":{let t=S(o.comment);if(!t.ok)return t.planned;let s=t.item.range;if(!s||t.item.orphaned)return d("invalid-handle","that comment has no range in this document");let c=A(t.reads,s);return c?O({kind:"span",span:c}):d("invalid-handle","that comment\u2019s range is no longer in the story")}case "getCommentResolved":{let t=S(o.comment);return t.ok?O({kind:"flag",value:t.item.resolved}):t.planned}case "insertComment":return Yn(o,e,a,I);case "setCommentResolved":{let t=S(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 s=y(l(t.reads));return s||{ok:true,kind:"commentWrite",write:{kind:"resolve",commentId:t.item.id,resolved:o.resolved},story:t.reads.story,answer:()=>D}}case "replyToComment":{let t=S(o.comment);if(!t.ok)return t.planned;let s=xe({author:o.author,text:o.text,date:o.date,kind:"reply"});if(s)return s;let c=t.item.range;if(!c||t.item.orphaned)return d("invalid-handle","that comment has no range to reply over");let h=y(l(t.reads));if(h)return h;let v=t.reads.story,R=be(o.date);return {ok:true,kind:"commentWrite",write:{kind:"reply",parentCommentId:t.item.id,anchor:{paragraphId:c.start.paragraphId,start:c.start.offset,end:c.end.offset,...c.end.paragraphId===c.start.paragraphId?{}:{endParagraphId:c.end.paragraphId}},text:o.text,author:o.author,...R===void 0?{}:{date:R}},story:t.reads.story,answer:(P,T)=>T===void 0?D:{kind:"handle",handle:e.comment(T,v)}}}case "deleteComment":{let t=S(o.comment);return t.ok?Gn(t.item,t.reads,s=>y(l(s))):t.planned}case "getRevisions":{let t=U(o.body,"body",e,a);if(!t.ok)return d(t.code,"that handle does not name a body",t.detail);let s=t.value;return O({kind:"handles",handles:Ae(s).map(c=>e.revision(c.id,s.story))})}case "getRevisionType":{let t=k(o.revision);return t.ok?O({kind:"text",text:t.item.type}):t.planned}case "getRevisionAuthor":{let t=k(o.revision);return t.ok?O({kind:"text",text:t.item.author}):t.planned}case "getRevisionDate":{let t=k(o.revision);return t.ok?O({kind:"text",text:t.item.date}):t.planned}case "getRevisionRange":{let t=k(o.revision);if(!t.ok)return t.planned;let[s]=t.item.item.ranges;if(!s)return d("invalid-handle","that change covers no characters");let c=A(t.reads,s);return c?O({kind:"span",span:c}):d("invalid-handle","that change\u2019s range is no longer in the story")}case "acceptRevision":case "rejectRevision":{let t=k(o.revision);if(!t.ok)return t.planned;let s=l(t.reads),c=y(s);if(c)return c;let h=o.op==="acceptRevision";return {ok:true,kind:"command",story:t.reads.story,ops:t.item.item.addresses.map(v=>h?{op:"acceptRevision",revision:v}:{op:"rejectRevision",revision:v}),answer:()=>D}}case "acceptAllRevisions":case "rejectAllRevisions":{let t=zn(o,e,a);if(!t.ok)return d(t.code,t.message,t.detail);let s=l(t.reads),c=y(s);if(c)return c;let h=$n(o,t.reads);return {ok:true,kind:"command",story:t.reads.story,ops:h,answer:()=>D}}case "selectSpan":{let t=V(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 s=G(t.value);return s?Ce(l(s),t.value,o.mode):d("invalid-handle","that story is not in this document")}case "selectBookmark":{let t=Oe(o.bookmark);return "reads"in t?Ce(l(t.reads),t.range,o.mode):t}case "getContentControls":{let t=Nt(o.scope);return "reads"in t?O({kind:"handles",handles:Jn(t.reads,t.node).map(s=>e.contentControl(s.nodeId,t.reads.story))}):t}case "getContentControlById":{let t=Nt(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 s=Ie(t.node).find(c=>Hc(c).id===o.id);return s?O({kind:"handle",handle:e.contentControl(s.id,t.reads.story)}):d("invalid-handle","no control in that scope carries that id",String(o.id))}case "getContentControlsByTag":case "getContentControlsByTitle":{let t=Nt(o.scope);if(!("reads"in t))return t;let s=o.op==="getContentControlsByTag"?o.tag:o.title;if(typeof s!="string"||s.length===0)return d("unsupported-content","a tag or title to match is required",o.op);let c=Ie(t.node).filter(h=>{let v=Hc(h);return o.op==="getContentControlsByTag"?v.tag===s:v.alias===s});return O({kind:"handles",handles:c.map(h=>e.contentControl(h.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 s=t.control.properties;if(o.op==="getContentControlLock")return O({kind:"text",text:t.control.lock});if(o.op==="getContentControlSubtype")return O({kind:"text",text:s.type});if(o.op==="getContentControlFileId")return O({kind:"text",text:s.id===void 0?"":String(s.id)});let c=o.op==="getContentControlTag"?s.tag:s.alias;return O({kind:"text",text:c??""})}case "getContentControlIsBound":case "getContentControlPlaceholderShown":case "getContentControlTemporary":{let t=Z(o.contentControl);if(!("control"in t))return t;let s=o.op==="getContentControlIsBound"?t.control.properties.dataBinding!==void 0:o.op==="getContentControlPlaceholderShown"?t.control.properties.showingPlaceholder:t.control.properties.temporary;return O({kind:"flag",value:s})}case "getContentControlText":{let t=Z(o.contentControl);return "control"in t?O({kind:"text",text:to(t.reads,t.node,o.projection)}):t}case "getContentControlParagraphs":{let t=Z(o.contentControl);return "control"in t?O({kind:"handles",handles:t.control.paragraphIds.map(s=>e.paragraph(s,t.reads.story))}):t}case "getContentControlRange":{let t=Z(o.contentControl);if(!("control"in t))return t;let s=o.location??"whole";if(!ro.has(s))return d("unsupported-content","that is not a place in a control",s);let c=ne(t.reads,t.node);if(!c)return d("unsupported-content","that control holds nothing addressable","empty");let h=s==="start"||s==="before"?c.start:c.end,v=s!=="whole"&&s!=="content",R=P=>({story:t.reads.story,paragraphId:P.paragraphId,index:t.reads.indexOf(P.paragraphId),offset:P.offset});return O({kind:"span",span:jt(v?{start:R(h),end:R(h)}:{start:R(c.start),end:R(c.end)},e)})}case "setContentControlValue":{let t=Z(o.contentControl);if(!("control"in t))return t;let s=so(o.value);if(!s.ok)return d(s.code,s.message,s.detail);let c=l(t.reads),h=y(c);return h||{ok:true,kind:"command",story:t.reads.story,ops:[{op:"setContentControlValue",controlId:t.control.nodeId,value:s.value}],answer:()=>D}}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&&!oo.has(o.lock))return d("unsupported-content","that is not a lock this schema declares",o.lock);let s=l(t.reads),c=y(s);return c||{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:()=>D}}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 s=l(t.reads),c=y(s);if(c)return c;let h=ne(t.reads,t.node);if(!h)return d("unsupported-content","that control holds nothing addressable","empty");let v=o.at==="end"?h.end:h.start,R=()=>({kind:"span",span:B({start:{story:t.reads.story,paragraphId:v.paragraphId,index:t.reads.indexOf(v.paragraphId),offset:v.offset},end:{story:t.reads.story,paragraphId:v.paragraphId,index:t.reads.indexOf(v.paragraphId),offset:v.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:R}:{ok:true,kind:"command",story:t.reads.story,ops:o.text.length===0?[]:[{op:"insertText",paragraphId:v.paragraphId,offset:v.offset,text:o.text,inside:t.node.id}],answer:R}}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 s=l(t.reads),c=y(s);return c||{ok:true,kind:"command",story:t.reads.story,ops:[{op:"removeContentControl",controlId:t.control.nodeId,keepContent:o.keepContent}],answer:()=>D}}case "insertContentControl":{let t=V(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 s=G(t.value);if(!s)return d("invalid-handle","that story is not in this document");let c=t.value;if(c.start.paragraphId!==c.end.paragraphId)return d("unsupported-content","wrapping several paragraphs in one control is not supported here","multi-paragraph");if(!ao.has(o.subtype))return d("unsupported-content","that control type cannot be inserted",o.subtype);let h=l(s),v=y(h);return v||{ok:true,kind:"command",story:s.story,ops:[{op:"insertContentControl",paragraphId:c.start.paragraphId,start:c.start.offset,end:c.end.offset,type:o.subtype,...o.tag===void 0?{}:{tag:o.tag},...o.title===void 0?{}:{alias:o.title}}],answer:()=>D}}case "insertCustomNode":{let t=uo(o);if(t)return d("unsupported-content",t.message,t.detail);let s=lo(o.payload);if(!s.ok)return d("unsupported-content","that payload cannot be written",s.field);let c=po(o,e,a);if("code"in c)return d(c.code,c.message,c.detail);let{start:h,end:v}=c.range,R=G(c.range);if(!R)return d("invalid-handle","that story is not in this document");let P=y(l(R));return P||{ok:true,kind:"customNodeWrite",story:R.story,write:co(o,h,v,s.value),answer:()=>D}}default:return d("unknown-operation","this host does not implement that operation",String(o.op))}};return {plan(o,u){let p=g.conflict(o);if(p)return d("conflicting-operations",p.message,p.detail);let t=ko(o,u);return t.ok&&g.note(o),t},get hasCommands(){return g.hasCommands},get writeScope(){return m?.reads.scope??null},settle(o){let u=m;if(u){let p=o.story(u.reads.story);if(!p)return {ok:false,detail:`the story this batch wrote is gone: ${K(u.reads.story)}`};let t=new Set(u.reads.paragraphIds),s=p.paragraphIds.filter(h=>!t.has(h));if(s.length!==u.created.length)return {ok:false,detail:`planned ${String(u.created.length)} new paragraphs, the transaction made ${String(s.length)}`};u.order.filter(h=>h.id===null).forEach((h,v)=>{h.id=s[v]??null;});for(let h of u.retargets)h.slot.id&&e.retarget(h.from,h.slot.id);}for(let p of f){let t=o.story(p.range.start.story);!t||!xr(p.range,t)||n.select?.(p.range,p.mode);}return {ok:true}}}}var Ir=Object.freeze({status:"skipped"});function tt(n,e,r){return Object.freeze(r===void 0?{code:n,message:e}:{code:n,message:e,detail:r})}function Sr(n){let e=n==="unsupported-revision"||n.startsWith("unsupported-revision:");return tt(e?"unsupported-revision":"transaction-refused",e?"that story contains a tracked change this engine cannot resolve":"the document store refused the transaction",n)}function st(n,e,r,a){return {ok:false,results:n.map((i,l)=>l===e?{status:"error",error:r}:Ir),revision:a,changed:false}}function js(n){let{port:e}=n,r=Object.freeze({...n.capabilities}),a=An(),i=new Set,l=false,f={mode:"Off"},g=0,m=null,y=null,I=r.events?e.subscribe(()=>{if(l)return;let A=Object.freeze({revision:e.revision()});if(g>0)m=A;else for(let b of [...i])b(A);}):()=>{},x=A=>{if(y&&y.pkg===A)return y.value;let b=Nn(A);return y={pkg:A,value:b},b},S=A=>{let b=Array.isArray(A?.operations)?A.operations:[],C=e.revision();if(l)return st(b,0,tt("disposed","this host was disposed"),C);if(!r.document)return st(b,0,tt("unsupported-capability","this host has no document","document"),C);let w=e.currentPackage();if(!w)return st(b,0,tt("document-unavailable","this host holds no document right now"),C);if(A.expectedRevision!==void 0&&A.expectedRevision!==C)return st(b,0,tt("stale-revision","the document moved since that revision",`expected ${String(A.expectedRevision)}, at ${C}`),C);let L=fo({handles:a,reads:x(w),capabilities:r,...e.revisionDisplayMode?{displayMode:e.revisionDisplayMode()}:{},...e.replacementLanding?{replacementLanding:e.replacementLanding.bind(e)}:{},...e.select?{select:e.select.bind(e)}:{}}),_=[],z=[],B=null,G=[],X=null,it,xt=null,$=-1,bt=f;for(let N=0;N<b.length;N+=1){let It=b[N],ft=kn(It,e.localChangeTracking===true,bt),Y=ft?.step??L.plan(It,bt.author);if(ft&&(bt=ft.state),!Y.ok)return st(b,N,Y.error,C);if(_.push(Y),Y.kind==="command")if($<0&&($=N),Y.lifecycle)B=Y.ops[0]??null;else if(Y.relate){let nt=Y.relate;z.push(Nt=>{let Z=Nt(nt.url);return Z===null?null:nt.ops(Z)});}else {let{ops:nt}=Y;z.push(()=>nt);}else Y.kind==="commentWrite"?($<0&&($=N),G.push(Y.write),X=L.writeScope??{kind:"body"}):Y.kind==="customNodeWrite"&&($<0&&($=N),xt={write:Y.write,scope:L.writeScope??{kind:"body"}});}let gt=false;if(G.length>0){let N=e.applyCommentWrites(G,X??{kind:"body"});if(!N.ok)return st(b,$<0?0:$,tt("transaction-refused","the document store refused the comment write",N.reason),C);gt=N.changed,it=N.commentId;}if(xt){let N=e.applyCustomNodeWrite(xt.write,xt.scope);if(!N.ok)return st(b,$<0?0:$,tt("transaction-refused","the document store refused the custom-node write",N.reason),C);gt=N.changed;}if(B){let N=e.applyLifecycle(B);if(!N.ok)return st(b,$<0?0:$,tt("transaction-refused","the document store refused the transaction",N.reason),C);gt=N.changed;}if(z.length>0){let N=e.apply(It=>{let ft=[];for(let Y of z){let nt=Y(It);if(nt===null)return null;ft.push(...nt);}return ft},L.writeScope??{kind:"body"});if(!N.ok)return st(b,$<0?0:$,Sr(N.reason),C);gt=N.changed;}let Tt=e.currentPackage();if(!Tt)return st(b,0,tt("document-unavailable","this host holds no document right now"),C);let wt=x(Tt),Ft=L.settle(wt);return Ft.ok?(f=bt,{ok:true,results:_.map(N=>({status:"ok",value:N.kind==="query"?N.value:N.kind==="customNodeWrite"?N.answer(wt):N.answer(wt,it)})),revision:e.revision(),changed:gt}):st(b,$<0?0:$,tt("transaction-refused","the transaction did not produce the document the batch planned",Ft.detail),e.revision())};return {capabilities:r,revision:()=>e.revision(),execute:A=>{g+=1;try{return S(A)}finally{if(g-=1,g===0&&m){let b=m;m=null;for(let C of [...i])C(b);}}},save(){if(l)return {ok:false,error:tt("disposed","this host was disposed")};if(!r.save)return {ok:false,error:tt("unsupported-capability","this host cannot save","save")};let A=e.save();return A?{ok:true,bytes:A}:{ok:false,error:tt("document-unavailable","this host holds no document right now")}},subscribe(A){return l||!r.events?()=>{}:(i.add(A),()=>{i.delete(A);})},dispose(){l||(l=true,i.clear(),I(),e.dispose(),y=null);}}}export{Rr as a,bo as b,Io as c,ce as d,Lt as e,Yt as f,js as g};
|