@docx-editor.dev/core 2.10.0 → 2.12.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.
Files changed (136) hide show
  1. package/dist/automation.cjs +1 -1
  2. package/dist/automation.d.cts +14 -5
  3. package/dist/automation.d.ts +14 -5
  4. package/dist/automation.js +1 -1
  5. package/dist/binding.cjs +1 -1
  6. package/dist/binding.d.cts +12 -11
  7. package/dist/binding.d.ts +12 -11
  8. package/dist/binding.js +1 -1
  9. package/dist/chunk-3JON7JMD.cjs +1 -0
  10. package/dist/chunk-5V6FNKBE.cjs +2 -0
  11. package/dist/chunk-6JIJOZDW.js +1 -0
  12. package/dist/chunk-BTQKU64Q.cjs +1 -0
  13. package/dist/chunk-BXRVGHTY.cjs +18 -0
  14. package/dist/chunk-BXTTPJSH.js +5 -0
  15. package/dist/chunk-D5EHDHYV.js +1 -0
  16. package/dist/{chunk-PSZH2VXP.js → chunk-GOEBQ26R.js} +1 -1
  17. package/dist/chunk-ILTZTY3K.cjs +10 -0
  18. package/dist/chunk-IUM7FZPA.js +2 -0
  19. package/dist/chunk-JWZG4QJ5.cjs +2 -0
  20. package/dist/chunk-JXZYDBKU.cjs +19 -0
  21. package/dist/chunk-KBOOIC2Q.js +19 -0
  22. package/dist/chunk-L6XZTLPS.js +10 -0
  23. package/dist/chunk-L7OR5TJK.cjs +5 -0
  24. package/dist/chunk-MHQNR2OU.js +2 -0
  25. package/dist/chunk-MLGPISGH.js +1 -0
  26. package/dist/chunk-NJXQABQU.js +18 -0
  27. package/dist/{chunk-YMYCPY5Y.cjs → chunk-OHJQ7GPZ.cjs} +1 -1
  28. package/dist/chunk-TKEGK4GQ.cjs +2 -0
  29. package/dist/chunk-VGFMPWND.js +2 -0
  30. package/dist/chunk-W77HJGYX.js +1 -0
  31. package/dist/chunk-XCFM3G5L.cjs +1 -0
  32. package/dist/chunk-ZKWRCLT2.cjs +1 -0
  33. package/dist/collaboration/replication.cjs +1 -0
  34. package/dist/collaboration/replication.d.cts +216 -0
  35. package/dist/collaboration/replication.d.ts +216 -0
  36. package/dist/collaboration/replication.js +1 -0
  37. package/dist/collaboration.cjs +1 -0
  38. package/dist/collaboration.d.cts +176 -0
  39. package/dist/collaboration.d.ts +176 -0
  40. package/dist/collaboration.js +1 -0
  41. package/dist/contracts/editor.cjs +1 -1
  42. package/dist/contracts/editor.d.cts +8 -9
  43. package/dist/contracts/editor.d.ts +8 -9
  44. package/dist/contracts/editor.js +1 -1
  45. package/dist/contracts/interaction.d.cts +8 -9
  46. package/dist/contracts/interaction.d.ts +8 -9
  47. package/dist/contracts/modules.cjs +1 -1
  48. package/dist/contracts/modules.d.cts +21 -8
  49. package/dist/contracts/modules.d.ts +21 -8
  50. package/dist/contracts/modules.js +1 -1
  51. package/dist/custom-node-writes-CcNeHH5C.d.ts +310 -0
  52. package/dist/custom-node-writes-D4rMJIES.d.cts +310 -0
  53. package/dist/document-properties-D6Ahr8D6.d.cts +28 -0
  54. package/dist/document-properties-D6Ahr8D6.d.ts +28 -0
  55. package/dist/{editor-CwzY2Hcg.d.cts → editor-B76SEMZw.d.cts} +145 -49
  56. package/dist/{editor-C0my6Uta.d.ts → editor-BcdsPdbY.d.ts} +145 -49
  57. package/dist/editor.cjs +1 -1
  58. package/dist/editor.css +1 -7299
  59. package/dist/editor.d.cts +60 -26
  60. package/dist/editor.d.ts +60 -26
  61. package/dist/editor.js +1 -1
  62. package/dist/failure-BnGjoXf0.d.cts +64 -0
  63. package/dist/failure-BnGjoXf0.d.ts +64 -0
  64. package/dist/{index-kID8Ymkp.d.ts → index-BYTvklN5.d.ts} +262 -81
  65. package/dist/{index-nLFwo_17.d.cts → index-CDGhPib1.d.cts} +262 -81
  66. package/dist/index.cjs +1 -1
  67. package/dist/index.d.cts +19 -18
  68. package/dist/index.d.ts +19 -18
  69. package/dist/index.js +1 -1
  70. package/dist/layout.cjs +1 -1
  71. package/dist/layout.d.cts +82 -53
  72. package/dist/layout.d.ts +82 -53
  73. package/dist/layout.js +1 -1
  74. package/dist/{note-properties-jvnw_DGG.d.ts → note-properties-Bx7rXruA.d.ts} +1 -1
  75. package/dist/{note-properties-CQlxjic_.d.cts → note-properties-zQ8w04en.d.cts} +1 -1
  76. package/dist/{omml-equation-Dd3mBep-.d.ts → omml-equation-69O1Pd8G.d.ts} +1 -1
  77. package/dist/{omml-equation-BD-LsmWE.d.cts → omml-equation-BmV51rim.d.cts} +1 -1
  78. package/dist/output.cjs +1 -1
  79. package/dist/output.d.cts +6 -8
  80. package/dist/output.d.ts +6 -8
  81. package/dist/output.js +1 -1
  82. package/dist/{protocol-C7ahrdUx.d.ts → protocol-DC7ueVuo.d.ts} +2 -2
  83. package/dist/{protocol-UuZOcOp7.d.cts → protocol-FTXtrAIT.d.cts} +2 -2
  84. package/dist/{review-items-Dw-8a6Ie.d.ts → review-items-B78OsJU2.d.ts} +1 -2
  85. package/dist/{review-items-CwixiHNe.d.cts → review-items-C-2WQdEb.d.cts} +1 -2
  86. package/dist/{review-reads-BqkiJTeR.d.cts → review-reads-CbBQlb-n.d.cts} +2 -2
  87. package/dist/{review-reads-C0u-IKEA.d.ts → review-reads-UexYBp-m.d.ts} +2 -2
  88. package/dist/{revision-projection-Cc4wz30g.d.cts → revision-projection-6u8lae9J.d.cts} +1 -1
  89. package/dist/{revision-projection-CILpvv4M.d.ts → revision-projection-B2v9U3qx.d.ts} +1 -1
  90. package/dist/{semantic-cell-selection-Utrf0lz7.d.ts → semantic-cell-selection-DsYz2Vg3.d.ts} +4 -4
  91. package/dist/{semantic-cell-selection-DT9x9WLf.d.cts → semantic-cell-selection-nEE7E3Z8.d.cts} +4 -4
  92. package/dist/{semantic-interaction-B6hFRQLy.d.ts → semantic-interaction-C00BpIyC.d.ts} +1 -1
  93. package/dist/{semantic-interaction-Z0xKQcB4.d.cts → semantic-interaction-DiOX0FIH.d.cts} +1 -1
  94. package/dist/{semantic-paint-CQEOC0Od.d.cts → semantic-paint-Cc11nrDL.d.cts} +2 -2
  95. package/dist/{semantic-paint-quke354p.d.ts → semantic-paint-ofuoBsYo.d.ts} +2 -2
  96. package/dist/{semantic-records-Do3-i5oB.d.ts → semantic-records-CRG1r6-a.d.cts} +5 -4
  97. package/dist/{semantic-records-CMakzQ1X.d.cts → semantic-records-CzI0ZEuR.d.ts} +5 -4
  98. package/dist/{shaped-measurer-BxwTUluj.d.ts → shaped-measurer-CkOGZQn9.d.ts} +1 -1
  99. package/dist/{shaped-measurer-DzRwWrL5.d.cts → shaped-measurer-CneACGcP.d.cts} +1 -1
  100. package/dist/store.cjs +1 -1
  101. package/dist/store.d.cts +81 -17
  102. package/dist/store.d.ts +81 -17
  103. package/dist/store.js +1 -1
  104. package/dist/{tree-op-types-DSJYmf5b.d.cts → tree-op-types-CA7qgAUF.d.cts} +1288 -18
  105. package/dist/{tree-op-types-BuOfCrkp.d.ts → tree-op-types-HKfUzt_-.d.ts} +1288 -18
  106. package/dist/{custom-node-writes-BvpWCnW8.d.ts → tree-package-fragment-Cz-v-0B3.d.cts} +107 -322
  107. package/dist/{custom-node-writes-Db8H6Z3n.d.cts → tree-package-fragment-oJZX_5iN.d.ts} +107 -322
  108. package/dist/{tree-session-contract-ByWx8eew.d.cts → tree-session-contract-BPDLrEPX.d.ts} +16 -10
  109. package/dist/{tree-session-contract-C1dfE9hy.d.ts → tree-session-contract-Cbl87xa8.d.cts} +16 -10
  110. package/dist/{tree-store-ASBtz7UB.d.ts → tree-store-B7hd6cEa.d.ts} +130 -25
  111. package/dist/{tree-store-CWOUMGN8.d.cts → tree-store-BenW0Mg_.d.cts} +130 -25
  112. package/package.json +14 -3
  113. package/dist/chunk-27APDXY2.js +0 -2
  114. package/dist/chunk-35MI6K7M.cjs +0 -10
  115. package/dist/chunk-4XL7SOWQ.cjs +0 -2
  116. package/dist/chunk-6K6QQVAZ.cjs +0 -18
  117. package/dist/chunk-7VQ7YLW3.cjs +0 -1
  118. package/dist/chunk-7ZJL5AEY.cjs +0 -1
  119. package/dist/chunk-C6LK2BYA.cjs +0 -2
  120. package/dist/chunk-GQQOL4PV.js +0 -1
  121. package/dist/chunk-HBEBUCRM.cjs +0 -5
  122. package/dist/chunk-LG5K46OM.js +0 -2
  123. package/dist/chunk-LWADHMVV.js +0 -5
  124. package/dist/chunk-N725IUO7.js +0 -18
  125. package/dist/chunk-N7DBENH4.js +0 -10
  126. package/dist/chunk-NVGFWMCO.js +0 -1
  127. package/dist/chunk-SYTWKJPJ.cjs +0 -18
  128. package/dist/chunk-YI6JXF7U.js +0 -18
  129. package/dist/hf-references-Dvk6De4Q.d.cts +0 -70
  130. package/dist/hf-references-z5Y4N1ab.d.ts +0 -70
  131. package/dist/note-nodes-BNCANoGN.d.ts +0 -108
  132. package/dist/note-nodes-DL-Au22P.d.cts +0 -108
  133. package/dist/ooxml-package-CdEy9ufK.d.cts +0 -1222
  134. package/dist/ooxml-package-CdEy9ufK.d.ts +0 -1222
  135. package/dist/tree-op-revision-attribution-CN06Xshv.d.cts +0 -24
  136. package/dist/tree-op-revision-attribution-CN06Xshv.d.ts +0 -24
@@ -1 +0,0 @@
1
- import {Ge,ya,wg,ge,td,wd,ud,Dd,Vb,Tb,qg,pg,$d,Ke,Ee,Ie,gg,hg,jg,ig,$c,Oa,bd,Ma,Xd,Zd,Gg,Eg,Mg,Lg,Og,Yd,O,hh,Rc,Qc,Ue,Gd,Nf,We,Cf,Zg,da,za,ng,og,_e,$e,Ze,_g,Xg,Hc,Fc,ih,Ve,Uc,La,Ic,Gc,_f}from'./chunk-N7DBENH4.js';var Bt=Object.freeze(["default","first","even"]),ct=Object.freeze({kind:"body"});function B(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 an(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&&Bt.includes(e.variant)}var fr=["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"],lo=["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"],uo=["deleteNote","insertComment","setCommentResolved","replyToComment","insertCustomNode"],co=new Set(uo);function Zt(n){return co.has(n.op)}var po=new Set(lo);function qt(n){return po.has(n.op)}function mo(){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 s=e.call(n,new Uint8Array(16)),a="";for(let i of s)a+=i.toString(16).padStart(2,"0");return a}function fo(n){return typeof n=="object"&&n!==null&&"kind"in n&&"ref"in n}function sn(){let n=new Map,e=new Map,s=new Map,a=new Map,i=mo(),u=null,c=(m,y)=>{let v=(a.get(m)??0)+1;a.set(m,v);let k=`${m}:${i}:${String(v)}`;return n.set(k,y),Object.freeze({kind:m,ref:k})},g=(m,y,v)=>{let k=`${m}\0${y}`,S=s.get(k);if(S)return Object.freeze({kind:m,ref:S});let A=c(m,v);return s.set(k,A.ref),A};return {document(){return u??=c("document",{kind:"document"}),u},body(m){return g("body",B(m),{kind:"body",story:m})},paragraph(m,y){let v=e.get(m);if(v)return Object.freeze({kind:"paragraph",ref:v});let k=c("paragraph",{kind:"paragraph",paragraphId:m,story:y});return e.set(m,k.ref),k},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",`${B(y)}\0${m}`,{kind:"comment",commentId:m,story:y})},revision(m,y){return g("revision",`${B(y)}\0${m}`,{kind:"revision",revisionId:m,story:y})},bookmark(m,y){return g("bookmark",`${B(y)}\0${m}`,{kind:"bookmark",name:m,story:y})},list(m,y){return g("list",`${B(y)}\0${m}`,{kind:"list",numId:m,story:y})},contentControl(m,y){return g("contentControl",`${B(y)}\0${m}`,{kind:"contentControl",nodeId:m,story:y})},retarget(m,y){let v=e.get(m);if(!v||m===y)return;let k=n.get(v);!k||k.kind!=="paragraph"||(e.delete(m),n.set(v,{kind:"paragraph",paragraphId:y,story:k.story}),e.has(y)||e.set(y,v));},resolve(m,y){if(!fo(m)||m.kind!==y||typeof m.ref!="string")return null;let v=n.get(m.ref);return !v||v.kind!==y?null:v}}}var yo=255,go=Object.freeze({nameOf:()=>null,idOf:()=>null,defaultId:null,present:false});function dn(n){let e=Rc(n);if(!e)return go;let s=new Map,a=new Map,i=null;for(let u of Qc(e).values())if(u.type==="paragraph"){if(s.set(u.styleId,u.name),u.name!==null){let c=u.name.trim().toLowerCase();a.has(c)||a.set(c,u.styleId);}u.isDefault&&i===null&&(i=u.styleId);}return Object.freeze({nameOf:u=>s.get(u)??null,idOf:u=>a.get(u.trim().toLowerCase())??null,defaultId:i,present:true})}function Ft(n,e,s){let a=ya(n,e);if(!a||a.kind!=="paragraph")return null;let i=ho(Zd(Xd(a),"pStyle"));return i!==null?s.nameOf(i):s.defaultId===null?null:s.nameOf(s.defaultId)}function ho(n){if(!n)return null;for(let e of n.attributes)if(e.localName==="val")return e.value;return null}function _t(n,e){if(typeof n!="string"||n.trim().length===0)return {ok:false,detail:"style: not a name"};if(n.length>yo)return {ok:false,detail:"style: name too long"};if(!O(n))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(n);return s===null?{ok:false,detail:"style: this document defines no paragraph style with that name"}:{ok:true,styleId:s}}var ko=31680,Ao=1999,vo=Object.freeze({bold:null,italic:null,name:null,size:null,color:null});function Y(n,e){if(!n)return null;for(let s of n.attributes)if(s.localName===e)return s.value;return null}function te(n){if(!n)return null;let e=Y(n,"val");if(e===null)return true;let s=e.trim().toLowerCase();return !(s==="0"||s==="false"||s==="off"||s==="none")}function bo(n){if(n===null)return null;let e=n.trim();return /^[0-9a-fA-F]{6}$/.test(e)?`#${e.toUpperCase()}`:null}function xo(n){if(n===null)return null;let e=Number(n.trim());return !Number.isFinite(e)||e<=0?null:e/2}function ft(n){if(n===null)return null;let e=Number(n.trim());return Number.isFinite(e)?Hc(Fc(e)):null}function Rt(n){if(n.length===0)return null;let e=n[0];if(e===null)return null;for(let s of n)if(s!==e)return null;return e}function un(n,e,s=wg){let a=[];for(let i of e)for(let u of Og(n,i.paragraphId,i.start,i.end,s))a.push(Yd(u));return a.length===0?vo:{bold:Rt(a.map(i=>te(Zd(i,"b")))),italic:Rt(a.map(i=>te(Zd(i,"i")))),name:Rt(a.map(i=>{let u=Zd(i,"rFonts"),c=Y(u,"ascii");return c===null||c.length===0?null:c})),size:Rt(a.map(i=>xo(Y(Zd(i,"sz"),"val")))),color:Rt(a.map(i=>bo(Y(Zd(i,"color"),"val"))))}}var Io=Object.freeze({left:"Left",start:"Left",center:"Centered",right:"Right",end:"Right",both:"Justified",distribute:"Justified"}),So=Object.freeze({Left:"left",Centered:"center",Right:"right",Justified:"both"});function Ro(n){let e=Y(Zd(n,"jc"),"val");return e===null?"Unknown":Io[e.trim().toLowerCase()]??"Unknown"}function cn(n,e,s){let a=ya(n,e);if(!a||a.kind!=="paragraph")return null;let i=Xd(a),u=Zd(i,"spacing"),c=Zd(i,"ind");return {alignment:Ro(i),style:Ft(n,e,s),firstLineIndent:Co(c),leftIndent:ft(Y(c,"left")??Y(c,"start")),rightIndent:ft(Y(c,"right")??Y(c,"end")),lineSpacing:ft(Y(u,"line")),spaceBefore:ft(Y(u,"before")),spaceAfter:ft(Y(u,"after")),widowControl:te(Zd(i,"widowControl"))}}function Co(n){let e=ft(Y(n,"hanging"));if(e!==null&&e>0)return -e;let s=ft(Y(n,"firstLine"));return s!==null?s:e===null?null:-e}function Dt(n,e){if(typeof n!="number"||!Number.isFinite(n))return {ok:false,detail:`${e}: not a measurement`};let s=Ic(Gc(n));return Math.abs(s)>ko?{ok:false,detail:`${e}: out of range`}:{ok:true,value:s}}function pn(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 s=n.name;if(typeof s!="string"||s.length===0||s.length>128)return {ok:false,detail:"name: not a font name"};if(!O(s))return {ok:false,detail:"name: not valid XML text"};e.push({localName:"rFonts",attributes:{ascii:s,hAnsi:s}});}if(n.size!==void 0){let s=n.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>Ao)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 s=n.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 mn(n,e,s,a){let i=ya(n,e);if(!i||i.kind!=="paragraph")return {ok:false,detail:"not a paragraph"};let u=Xd(i),c=[];if(s.style!==void 0){let A=_t(s.style,a);if(!A.ok)return {ok:false,detail:A.detail};c.push({localName:"pStyle",attributes:{val:A.styleId}});}if(s.alignment!==void 0){let A=So[s.alignment];if(A===void 0)return {ok:false,detail:`alignment: ${String(s.alignment)}`};c.push({localName:"jc",attributes:{val:A}});}let g=Zd(u,"ind"),m=ln(g),y=false;if(s.firstLineIndent!==void 0){let A=Dt(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),y=true;}for(let[A,b,C]of [["leftIndent","left","start"],["rightIndent","right","end"]]){let O=s[A];if(O===void 0)continue;let T=Dt(O,A);if(!T.ok)return T;delete m[C],m[b]=String(T.value),y=true;}y&&c.push({localName:"ind",attributes:m});let v=Zd(u,"spacing"),k=ln(v),S=false;for(let[A,b]of [["spaceBefore","before"],["spaceAfter","after"]]){let C=s[A];if(C===void 0)continue;let O=Dt(C,A);if(!O.ok)return O;if(O.value<0)return {ok:false,detail:`${A}: out of range`};k[b]=String(O.value),S=true;}if(s.lineSpacing!==void 0){let A=Dt(s.lineSpacing,"lineSpacing");if(!A.ok)return A;if(A.value<=0)return {ok:false,detail:"lineSpacing: out of range"};k.line=String(A.value),k.lineRule??="auto",S=true;}if(S&&c.push({localName:"spacing",attributes:k}),s.widowControl!==void 0){if(typeof s.widowControl!="boolean")return {ok:false,detail:"widowControl: not a boolean"};c.push({localName:"widowControl",...s.widowControl?{}:{attributes:{val:"0"}}});}return c.length===0?{ok:false,detail:"no formatting was asked for"}:{ok:true,value:Gg(Eg(n,e),c)}}function ln(n){let e=Object.create(null);if(!n)return e;for(let s of n.attributes)e[s.localName]=s.value;return e}function fn(){let n=false,e=false,s=false;return {conflict(a){let i=qt(a),u=Zt(a),c=a.op==="deleteComment";return u&&n||e&&i?{message:"that command commits on its own and cannot share a batch",detail:a.op}:c&&n&&!s||s&&i&&!c?{message:"comment deletions may share a batch only with other comment deletions",detail:a.op}:null},note(a){qt(a)&&(n=true,Zt(a)&&(e=true),a.op==="deleteComment"&&(s=true));},get hasCommands(){return n}}}var Po=63360;function lt(n){return Math.round(Hc(Fc(n))*100)/100}function Oo(n,e){if(typeof n!="number"||!Number.isFinite(n))return null;let s=Ic(Gc(n));return s>Po||s<0||s===0&&!e?null:s}var wo=[["pageWidth","pageWidthTwips",false],["pageHeight","pageHeightTwips",false],["topMargin","marginTopTwips",true],["rightMargin","marginRightTwips",true],["bottomMargin","marginBottomTwips",true],["leftMargin","marginLeftTwips",true]];function yn(n){if(typeof n!="object"||n===null)return {ok:false,reason:"that is not a page setup",detail:"not-an-object"};let e=n,s={},a=0;for(let[u,c,g]of wo){let m=e[u];if(m===void 0)continue;let y=Oo(m,g);if(y===null)return {ok:false,reason:`that is not a value for ${u}`,detail:String(m)};s[c]=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)};s.orientation=i,a+=1;}return a===0?{ok:false,reason:"that page setup names nothing to write",detail:"empty"}:{ok:true,value:s}}function To(n){let e=Nf(n),s=e.widthTwips>e.heightTwips?"landscape":"portrait";return Object.freeze({pageWidth:lt(e.widthTwips),pageHeight:lt(e.heightTwips),orientation:s,topMargin:lt(e.topTwips),rightMargin:lt(e.rightTwips),bottomMargin:lt(e.bottomTwips),leftMargin:lt(e.leftTwips),headerDistance:lt(e.headerTwips),footerDistance:lt(e.footerTwips),gutter:lt(e.gutterTwips)})}function No(n,e){if(!e)return null;let s=null,a=(i,u,c)=>{if(s!==null||i.kind==="textValue"||c>64)return;let g=i.kind==="paragraph"?i.id:u;if(i.id===e.id){s=g;return}for(let m of i.children)a(m,g,c+1);};return a(n.root,null,0),s}function gn(n,e,s){let a=Tb(e.root);return Object.freeze(a.map((i,u)=>{let c=s[u];return Object.freeze({index:u,markParagraphId:No(e,i),pageSetup:To(i),titlePage:c?.titlePage??false,evenAndOddHeaders:c?.evenAndOddHeaders??false})}))}function kn(n,e,s){if(s==="allMarkup")return hn(e);let a=Ho(n);if(a.length===0)return hn(e);let i=[],u=[],c=0,g=0;for(let m of a){if(c<m.start){let y=e.slice(c,m.start);i.push({projectedStart:g,projectedEnd:g+y.length,rawStart:c,rawEnd:m.start}),u.push(y),g+=y.length;}c=Math.max(c,m.end);}if(c<e.length){let m=e.slice(c);i.push({projectedStart:g,projectedEnd:g+m.length,rawStart:c,rawEnd:e.length}),u.push(m);}return An(u.join(""),i)}function hn(n){return An(n,n.length===0?[]:[{projectedStart:0,projectedEnd:n.length,rawStart:0,rawEnd:n.length}])}function An(n,e){return {text:n,projectedOffset(s){let a=0;for(let i of e)if(s<=i.rawStart||(a+=Math.max(0,Math.min(s,i.rawEnd)-i.rawStart),s<=i.rawEnd))return a;return a},rawRange(s,a){let i=e.find(c=>s>=c.projectedStart&&s<c.projectedEnd),u=e.find(c=>a>c.projectedStart&&a<=c.projectedEnd);return !i||!u||s>=a?null:{start:i.rawStart+s-i.projectedStart,end:u.rawStart+a-u.projectedStart}},sliceRaw(s,a){return s>=a?"":e.map(i=>{let u=Math.max(s,i.rawStart),c=Math.min(a,i.rawEnd);return u<c?n.slice(i.projectedStart+u-i.rawStart,i.projectedStart+c-i.rawStart):""}).join("")}}}function Ho(n){let e=$d(n),s=[],a=(u,c)=>{if(!(c>64||u.kind==="textValue")){if(u.kind==="revisionInsert"||u.kind==="revisionMoveTo"){let g=e.spanOf(u);g&&g.end>g.start&&s.push({start:g.start,end:g.end});return}for(let g of u.children)a(g,c+1);}};a(n,0),s.sort((u,c)=>u.start-c.start||c.end-u.end);let i=[];for(let u of s){let c=i[i.length-1];c&&u.start<=c.end?c.end=Math.max(c.end,u.end):i.push({...u});}return i}var ne="\r",jo=Object.freeze({nameOf:()=>null,idOf:()=>null,defaultId:null,present:false}),Mo=Object.freeze([]),Lo=Object.freeze([]),vn=Object.freeze([]),Eo=Object.freeze({package:null,body:null,story:()=>null,storyOf:()=>null,sections:()=>Lo,furniture:()=>vn,noteIds:()=>({ok:true,ids:xn}),styles:()=>jo});function Bo(n){return n.kind==="textValue"?Mo:Object.freeze(n.children.filter(e=>e.kind!=="textValue").map(e=>{let s=[];We([e],s,0);let a=e.kind==="paragraph"?"paragraph":e.kind==="table"?"table":"other",i=e.kind==="paragraph"&&Zd(Xd(e),"sectPr")!==void 0;return Object.freeze({id:e.id,kind:a,paragraphIds:Object.freeze(s.map(u=>u.id)),removable:a!=="other"&&!i})}))}function ee(n,e,s,a,i){let u=Ve(a),c=Object.freeze(u.map(A=>A.id)),g=new Map,m=new Map;u.forEach((A,b)=>{g.set(A.id,b),m.set(A.id,A);});let y=new Map,v=A=>{if(!g.has(A))return null;let b=y.get(A);if(b!==void 0)return b;let C=_f(e,A)??"";return y.set(A,C),C},k=new Map,S=(A,b="allMarkup")=>{let C=m.get(A);if(!C||C.kind!=="paragraph")return null;let O=`${A}:${b}`,T=k.get(O);if(T)return T;let L=kn(C,v(A)??"",b);return k.set(O,L),L};return {story:n,part:e,root:a,scope:s,paragraphIds:c,blocks:Bo(a),has:A=>g.has(A),indexOf:A=>g.get(A)??-1,paragraph(A){let b=m.get(A);return b?{nodeId:A,paraId:Uc(b),text:v(A)??""}:null},node:A=>m.get(A)??null,paragraphText:(A,b)=>S(A,b)?.text??null,projectedText:S,text:A=>c.map(b=>S(b,A)?.text??"").join(ne),styles:i}}function bn(n){let e=n.parts.get(n.mainDocumentPart);if(!e)return Eo;let s,a=()=>s??=dn(n),i,u=()=>i??=Vb(n),c,g=new Map,m=new Map,y=b=>{let C=m.get(b);if(C)return C;let O=ge(n,b);if(!O){let V={ok:true,ids:xn};return m.set(b,V),V}let T=[],L=new Set,F=new Set,J=0,X=false;for(let V of O.root.children){if(td(V)!==b)continue;if(J+=1,V.kind!=="note"){X=true;continue}if(!wd(V))continue;let nt=ud(V);if(nt===null){X=true;continue}L.has(nt)?F.add(nt):(L.add(nt),T.push(nt));}let M=J>Dd?{ok:false,reason:"truncated"}:X?{ok:false,reason:"malformed"}:F.size>0?{ok:false,reason:"duplicates",duplicateIds:Object.freeze([...F])}:{ok:true,ids:Object.freeze(T)};return m.set(b,M),M},v=b=>{let C=u()[b.sectionIndex];return C?(b.kind==="header"?C.headers:C.footers).get(b.variant)??null:null},k=b=>{if(b.kind==="body"){let O=Ue(e);return O?ee(b,e,{kind:"body"},O,a):null}if(b.kind==="note"){let O=y(b.noteKind);if(!O.ok||!O.ids.includes(b.noteId))return null;let T=ge(n,b.noteKind);if(!T)return null;let L=Gd(T.root,b.noteId);return !L||!wd(L)?null:ee(b,T,{kind:"notesPart",noteKind:b.noteKind},L,a)}let C=v(b);return C?ee(b,C.part,{kind:"headerFooter",rId:C.rId},C.part.root,a):null},S=b=>{let C=B(b);if(g.has(C))return g.get(C)??null;let O=k(b);return g.set(C,O),O};return {package:n,get body(){return S(ct)},story:S,storyOf:b=>{if(S(ct)?.has(b))return ct;for(let[O]of u().entries())for(let T of ["header","footer"])for(let L of Bt){let F={kind:T,sectionIndex:O,variant:L};if(S(F)?.has(b))return F}for(let O of ["footnote","endnote"]){let T=y(O);if(T.ok)for(let L of T.ids){let F={kind:"note",noteKind:O,noteId:L};if(S(F)?.has(b))return F}}return null},sections:()=>c??=gn(n,e,u()),furniture(b){let C=u()[b];if(!C)return vn;let O=[];for(let T of ["header","footer"]){let L=T==="header"?C.headers:C.footers;for(let F of Bt){let J=L.get(F);J&&O.push(Object.freeze({kind:T,variant:F,declared:!J.inherited}));}}return Object.freeze(O)},noteIds:y,styles:a}}var xn=Object.freeze([]);function rt(n,e){return {ok:false,code:n,detail:e}}function at(n){return {ok:true,value:n}}function K(n,e,s,a){let i=s.resolve(n,e);if(!i||i.kind!=="body"&&i.kind!=="paragraph")return rt("invalid-handle",`not-a-${e}-handle`);let u=a.story(i.story);return u?at(u):rt("invalid-handle",`no-such-story:${B(i.story)}`)}function Z(n,e,s){let a=e.resolve(n,"paragraph");if(!a||a.kind!=="paragraph")return rt("invalid-handle","not-a-paragraph-handle");let i=s.story(a.story);if(!i)return rt("invalid-handle",`no-such-story:${B(a.story)}`);let u=i.indexOf(a.paragraphId);return u<0?rt("invalid-handle","paragraph-not-in-body"):at({story:a.story,paragraphId:a.paragraphId,index:u,offset:0})}function Fo(n,e,s){let a=Z(n.paragraph,e,s);if(!a.ok)return a;let u=(s.story(a.value.story)?.paragraphText(a.value.paragraphId)??"").length,{offset:c}=n;return !Number.isInteger(c)||c<0||c>u?rt("invalid-offset",`offset ${String(c)} outside 0..${String(u)}`):at({...a.value,offset:c})}function kt(n,e,s){if("paragraph"in n){if(!("at"in n))return Fo(n,e,s);let g=Z(n.paragraph,e,s);if(!g.ok||n.at==="start")return g;let y=(s.story(g.value.story)?.paragraphText(g.value.paragraphId)??"").length;return at({...g.value,offset:y})}let a=K(n.body,"body",e,s);if(!a.ok)return a;let i=a.value.paragraphIds;if(i.length===0)return rt("invalid-offset","empty-story");if(n.at==="start")return at({story:a.value.story,paragraphId:i[0],index:0,offset:0});let u=i.length-1,c=i[u];return at({story:a.value.story,paragraphId:c,index:u,offset:(a.value.paragraphText(c)??"").length})}function _o(n,e){return n.index<e.index||n.index===e.index&&n.offset<=e.offset}function Do(n){let e=n.paragraphIds;if(e.length===0)return null;let s=e.length-1,a=e[s];return {start:{story:n.story,paragraphId:e[0],index:0,offset:0},end:{story:n.story,paragraphId:a,index:s,offset:(n.paragraphText(a)??"").length}}}function W(n,e,s){if("body"in n){let u=K(n.body,"body",e,s);return u.ok?at(Do(u.value)):u}if("paragraph"in n){let u=Z(n.paragraph,e,s);if(!u.ok)return u;let g=(s.story(u.value.story)?.paragraphText(u.value.paragraphId)??"").length;return at({start:u.value,end:{...u.value,offset:g}})}let a=kt(n.start,e,s);if(!a.ok)return a;let i=kt(n.end,e,s);return i.ok?B(a.value.story)!==B(i.value.story)?rt("invalid-handle","span-crosses-stories"):_o(a.value,i.value)?at({start:a.value,end:i.value}):rt("invalid-offset","span-start-after-end"):i}function q(n,e,s){if("body"in n)return K(n.body,"body",e,s);if("paragraph"in n)return K(n.paragraph,"paragraph",e,s);let a=n.start;return "paragraph"in a?K(a.paragraph,"paragraph",e,s):K(a.body,"body",e,s)}function Wt(n,e,s){if("paragraph"in n)return Z(n.paragraph,e,s);let a=K(n.body,"body",e,s);if(!a.ok)return a;let i=a.value.paragraphIds;if(i.length===0)return rt("invalid-offset","empty-story");let u=n.at==="first"?0:i.length-1;return at({story:a.value.story,paragraphId:i[u],index:u,offset:0})}function tt(n,e){return n?e.paragraphIds.slice(n.start.index,n.end.index+1):[]}function oe(n,e){if(!n)return [];let s=tt(n,e),a=s.length-1;return s.map((i,u)=>{let c=(e.paragraphText(i)??"").length,g=u===0?n.start.offset:0,m=u===a?n.end.offset:c;return {paragraphId:i,start:g,end:m,whole:g===0&&m===c}})}function In(n,e,s,a="allMarkup"){if(!n)return "";let i=tt(n,e);return i.length===1?e.projectedText(n.start.paragraphId,a)?.sliceRaw(n.start.offset,n.end.offset)??"":i.map((u,c)=>{let g=e.projectedText(u,a);if(!g)return "";let m=(e.paragraphText(u)??"").length;return c===0?g.sliceRaw(n.start.offset,m):c===i.length-1?g.sliceRaw(0,n.end.offset):g.text}).join(s)}function re(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 Wo=256,Sn=1e4;function ae(n,e){if(n.kind!=="textValue"){for(let s of n.attributes)if(s.namespaceUri===da&&s.localName===e)return s.value}}function zo(n){return n.startsWith("_")}function se(n){let e=new Map,s=[],a=new Set;for(let i of n.paragraphIds){let u=n.node(i);if(u?.kind!=="paragraph")continue;let c=$d(u),g=m=>{if(m.kind!=="textValue"){if(m.kind==="bookmarkStart"){if(s.length>=Sn||e.size>=Sn)return;let y=ae(m,"id"),v=ae(m,"name");if(y===void 0||v===void 0||v.length===0||v.length>Wo||zo(v)||a.has(v)||e.has(y))return;let k=c.spanOf(m)?.start??0;e.set(y,{name:v,start:{paragraphId:i,offset:k}});return}if(m.kind==="bookmarkEnd"){let y=ae(m,"id");if(y===void 0)return;let v=e.get(y);if(!v)return;e.delete(y),a.add(v.name);let k=c.spanOf(m)?.start??0;s.push(Object.freeze({name:v.name,start:v.start,end:{paragraphId:i,offset:k}}));return}for(let y of m.children)g(y);}};for(let m of u.children)g(m);}return Object.freeze(s)}function ie(n,e){return se(n).find(s=>s.name===e)??null}function Rn(n,e){let s=n.node(e);if(s?.kind!=="paragraph")return Object.freeze([]);let a=$d(s),i=[],u=(c,g)=>{if(!(c.kind==="textValue"||g>32)){if(La(c)){let m=a.spanOf(c);m&&i.push(Object.freeze({id:c.id,paragraphId:e,start:m.start,end:m.end}));return}for(let m of c.children)u(m,g+1);}};for(let c of s.children)u(c,0);return Object.freeze(i)}function Cn(n,e,s){let a=Oa(s,i=>bd(n,e,i));if(a.kind==="external")return a.href;if(a.kind==="internal"){let i=Ma(s);return i===void 0||i.length===0?null:`#${i}`}return null}var At=8;function Pn(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 On(n){let e=Zd(Xd(n),"numPr");if(!e)return null;let s=Pn(Zd(e,"numId"));if(s===null||!/^\d{1,10}$/.test(s)||s==="0")return null;let a=Pn(Zd(e,"ilvl")),i=a===null?0:Number(a);return !Number.isInteger(i)||i<0||i>At?null:{numId:s,level:i}}function zt(n){let e=new Map;for(let s of n.paragraphIds){let a=n.node(s);if(!a)continue;let i=On(a);if(!i)continue;let u=e.get(i.numId);u?u.push(s):e.set(i.numId,[s]);}return Object.freeze([...e].map(([s,a])=>Object.freeze({numId:s,paragraphIds:Object.freeze(a)})))}function Ct(n,e){let s=n.node(e);return s?On(s):null}function wn(n,e,s,a,i){let u=Math.min(i?.limit??2e3,2e3),c=[],g=tt(e,n),m=g.length-1;for(let[y,v]of g.entries()){if(u<=0)break;let k=n.projectedText(v,i?.projection??"allMarkup");if(!k)continue;let S=ih(k.text,a,u,{matchCase:i?.matchCase===true,wholeWord:i?.matchWholeWord===true,...y===0&&e?{from:k.projectedOffset(e.start.offset)}:{},...y===m&&e?{to:k.projectedOffset(e.end.offset)}:{}});for(let A of S.matches){let b=k.rawRange(A.start,A.start+A.length);if(!b)return {ok:false,paragraphId:v};if(y===0&&e&&b.start<e.start.offset||y===m&&e&&b.end>e.end.offset)continue;let C=s.paragraph(v,n.story);c.push({start:{paragraph:C,offset:b.start},end:{paragraph:C,offset:b.end}}),u-=1;}}return {ok:true,spans:c}}var Ko={insert:"Insert",delete:"Delete",replace:"Replace",moveFrom:"MovedFrom",moveTo:"MovedTo",format:"Property",paragraphMark:"ParagraphProperty"};function Vo(n){return n.kind==="note"}function $o(n,e){return e.length===0?!Vo(n.story):e.every(s=>n.has(s.start.paragraphId))}function Uo(n){return Object.freeze(Zg(n.part).filter(e=>$o(n,e.ranges)))}function de(n){let e=[];for(let s of Uo(n)){if(s.readOnly||s.revisionKind==="structural")continue;let a=Ko[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 Xo(n,e){let s=n;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 Yo=Object.freeze({items:Object.freeze([]),roots:Object.freeze([]),byId:()=>null,textOf:()=>""});function Tn(n,e){let s=n.parts.get(ng(n,e.part.name));if(!s)return Yo;let a=n.parts.get(og(n,e.part.name)),i=_e(s),u=a?$e(a):new Map,c=Ze(e.part).filter(k=>e.has(k.start.paragraphId)),g=_g(i,c,u),m=new Map(g.map(k=>[k.id,k])),y=g.filter(k=>Xo(k,m)),v=new Map(y.map(k=>[k.id,k]));return Object.freeze({items:Object.freeze(y),roots:Object.freeze(y.filter(k=>k.parentId===void 0)),byId:k=>v.get(k)??null,textOf:k=>{let S=v.get(k);return S?Xg(S.comment):""}})}function Nn(n,e,s){if("body"in n){let a=K(n.body,"body",e,s);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")?s.body?{ok:true,reads:s.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 Hn(n,e){let s=n.op==="acceptAllRevisions",a=e.story.kind==="note"?{scopeRootId:e.root.id}:{};return [s?{op:"acceptAllRevisions",...a}:{op:"rejectAllRevisions",...a}]}var Go=/[\r\n\u2028\u2029]/u,Mn=Object.freeze({kind:"applied"});function vt(n,e,s){return {ok:false,error:Object.freeze(s===void 0?{code:n,message:e}:{code:n,message:e,detail:s})}}function le(n,e){return vt("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 ue(n){return gg(n.author)?le("author",n.kind):hg(n.text)?le("text",n.kind):typeof n.text=="string"&&Go.test(n.text)?vt("unsupported-content",n.kind==="reply"?"a reply is one paragraph in this slice":"a comment is one paragraph in this slice","text"):jg(n.date)?le("date",n.kind):null}function ce(n){if(n===void 0)return;let e=ig(n);return e.ok?e.value:void 0}function jn(n,e){let s=ya(n.part,e);for(;s;){if(s.kind==="tableCell"||s.kind!=="textValue"&&s.namespaceUri===da&&s.localName==="tc")return s.id;s=za(n.part,s.id);}return null}function Ln(n,e,s,a){let i=ue({author:n.author,text:n.text,date:n.date,kind:"comment"});if(i)return i;let u=W(n.span,e,s);if(!u.ok)return vt(u.code,"that span is not a place",u.detail);if(u.value===null)return vt("invalid-handle","an empty story has no comment anchor");let c=q(n.span,e,s);if(!c.ok)return vt(c.code,"that span is not a place",c.detail);let g=u.value;if(jn(c.value,g.start.paragraphId)!==jn(c.value,g.end.paragraphId))return vt("unsupported-content","a comment range cannot cross a table-cell boundary");let m=a(c.value);if(m)return m;let y=ce(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:c.value.story,answer:(k,S)=>S===void 0?Mn:{kind:"handle",handle:e.comment(S,c.value.story)}}}function En(n,e,s){let a=s(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:()=>Mn}}var Jo=1e4;function Bn(n,e){let s=[],a=e.kind==="contentControl"?Ee(e):e;if(!a)return s;for(let i of Ie(a))if(!(i.ancestors.length>0)){if(s.length>=Jo)break;s.push(Wn(n,i.node));}return s}function Fn(n,e){for(let s of Ie(n.root))if(s.node.id===e)return Wn(n,s.node);return null}function _n(n,e){for(let s of Ie(n.root))if(s.node.id===e)return s.node;return null}function Kt(n,e){let s=zn(e);if(s.length>0){let a=s[0],i=s[s.length-1],u=n.paragraphText(i);return u===null||!n.has(a)?null:{start:{paragraphId:a,offset:0},end:{paragraphId:i,offset:u.length}}}for(let a of n.paragraphIds){let i=n.node(a);if(!i||i.kind!=="paragraph"||!i.children.some(c=>c.id===e.id))continue;let u=$d(i).spanOf(e);return u?{start:{paragraphId:a,offset:u.start},end:{paragraphId:a,offset:u.end}}:null}return null}function Dn(n,e,s="allMarkup"){if(s==="allMarkup")return Ke(e);let a=Kt(n,e);if(!a)return "";let i=n.indexOf(a.start.paragraphId),u=n.indexOf(a.end.paragraphId);if(i<0||u<i)return "";let c=[];for(let g=i;g<=u;g+=1){let m=n.paragraphIds[g],y=n.projectedText(m,s),v=n.paragraphText(m);if(!y||v===null)return "";c.push(y.sliceRaw(g===i?a.start.offset:0,g===u?a.end.offset:v.length));}return c.join("\r")}function Wn(n,e){return {nodeId:e.id,properties:Ge(e),lock:Cf(n.part,e.id),paragraphIds:zn(e)}}function zn(n){let e=Ee(n);if(!e)return [];let s=[];return We(e.children,s,0),s.map(a=>a.id)}var Qo=new Set(["unlocked","sdtLocked","contentLocked","sdtContentLocked"]),Zo=4096,Kn=64;function Vn(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 s of ["namespaceUri","rootLocalName","nodeId"]){let a=e[s];if(typeof a!="string"||a.length===0||a.length>Zo)return {ok:false,field:s}}return typeof e.label!="string"||e.label.length>qg?{ok:false,field:"label"}:typeof e.data!="string"||e.data.length===0||e.data.length>pg?{ok:false,field:"data"}:{ok:true,value:{namespaceUri:e.namespaceUri,rootLocalName:e.rootLocalName,nodeId:e.nodeId,label:e.label,data:e.data}}}function $n(n){let e=n.at!==void 0,s=n.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 n.tag!="string"||n.tag.length===0?{message:"a custom node carries its identity in its tag",detail:"tag"}:n.tag.length>Kn?{message:`w:tag caps at ${String(Kn)} 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&&!Qo.has(n.lock)?{message:"that is not a lock",detail:String(n.lock)}:null}function Un(n,e,s,a){return {paragraphId:e.paragraphId,offset:e.offset,...s.offset>e.offset?{replaceUntil:s.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 Xn(n,e,s){if(n.span){let i=W(n.span,e,s);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=kt(n.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 Pt=/[\r\n\v\f\u2028\u2029]/,qo=16,tr=64,Yn=/\s/;function er(n,e,s){return Object.freeze(s===void 0?{code:n,message:e}:{code:n,message:e,detail:s})}function l(n,e,s){return {ok:false,error:er(n,e,s)}}var E=Object.freeze({kind:"applied"});function I(n){return {ok:true,kind:"query",value:n}}function Gn(n){let e=n.kind==="contentControl"?Ee(n):n;return e?Ie(e).map(s=>s.node):[]}var nr=new Set(["unlocked","sdtLocked","contentLocked","sdtContentLocked"]),or=new Set(["whole","content","start","end","before","after"]),rr=new Set(["richText","plainText","dropDownList","comboBox","date"]),ar=4096;function sr(n){let e=(i,u)=>({ok:false,code:"unsupported-content",message:i,detail:u});if(typeof n!="object"||n===null||!("kind"in n))return e("a control value states its kind","value");let s=n,a=s.kind;if(a==="text"||a==="listItem"){let i=a==="text"?s.text:s.value;return typeof i!="string"?e("that value is not a string",String(a)):i.length>ar?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=s.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=s.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))}function ir(n,e){let s=[],a=0;for(;a<n.length;){let i=null;for(let u of e){let c=n.indexOf(u,a);c<0||(!i||c<i.start||c===i.start&&u.length>i.length)&&(i={start:c,length:u.length});}if(!i)break;s.push(i),a=i.start+i.length;}return s}function dr(n,e,s){let a=e[s]?.markParagraphId??null;if(a!==null)return a;let i=n.paragraphIds,u=i[i.length-1];return u===void 0||new Set(e.map(g=>g.markParagraphId).filter(g=>g!==null)).has(u)?null:u}function lr(n,e){for(let s of [n.start,n.end]){let a=e.paragraphText(s.paragraphId);if(a===null||s.offset>a.length)return false}return true}function ur(n,e,s){let a=e,i=s;for(;a<i&&Yn.test(n[a]);)a+=1;for(;i>a&&Yn.test(n[i-1]);)i-=1;return [a,i]}function Jn(n){let{handles:e,capabilities:s}=n,a=n.reads,i=new Map,u=o=>{let t=B(o.story),r=i.get(t);if(r)return r;let d=new Map,p=o.paragraphIds.map(h=>{let x={id:h};return d.set(h,x),x}),f={reads:o,order:p,slotById:d,created:[],restructured:new Set,touched:new Set,formatted:new Set,selected:new Set,retargets:[]};return i.set(t,f),f},c=[],g=fn(),m=null,y=o=>m===null?(m=o,null):m===o?null:l("conflicting-operations","one batch writes into one story",`${B(m.reads.story)} then ${B(o.reads.story)}`),v=o=>y(u(o)),k=o=>{let t=a.package;return t===null?null:Tn(t,o)},S=o=>{let t=e.resolve(o,"comment");if(!t||t.kind!=="comment")return {ok:false,planned:l("invalid-handle","that handle does not name a comment","comment")};let r=a.story(t.story);if(!r)return {ok:false,planned:l("invalid-handle","that story is not in this document")};let p=k(r)?.byId(t.commentId)??null;return p?{ok:true,reads:r,item:p}:{ok:false,planned:l("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:l("invalid-handle","that handle does not name a tracked change","revision")};let r=a.story(t.story);if(!r)return {ok:false,planned:l("invalid-handle","that story is not in this document")};let d=de(r).find(p=>p.id===t.revisionId)??null;return d?{ok:true,reads:r,item:d}:{ok:false,planned:l("invalid-handle","this document no longer holds that tracked change",t.revisionId)}},b=(o,t)=>{let r=o.paragraphText(t.start.paragraphId),d=o.paragraphText(t.end.paragraphId);if(r===null||d===null)return null;let p={story:o.story,paragraphId:t.start.paragraphId,index:o.indexOf(t.start.paragraphId),offset:Math.min(t.start.offset,r.length)},f={story:o.story,paragraphId:t.end.paragraphId,index:o.indexOf(t.end.paragraphId),offset:Math.min(t.end.offset,d.length)};return X({start:p,end:f})},C=(o,t)=>o.order.indexOf(t),O$1=(o,t)=>o.selected.has(t)?l("conflicting-operations","this batch selects a paragraph it also edits",t):null,T=(o,t)=>{let r=O$1(o,t);return r||(o.restructured.has(t)||o.touched.has(t)?l("conflicting-operations","another operation in this batch already changes that paragraph",t):(o.restructured.add(t),o.touched.add(t),null))},L=(o,t)=>{let r=O$1(o,t);return r||(o.restructured.has(t)?l("conflicting-operations","another operation in this batch restructures that paragraph",t):(o.touched.add(t),null))},F=(o,t,r)=>{let d=`${r}:${t}`;if(o.formatted.has(d))return l("conflicting-operations","another operation in this batch already writes that formatting",t);let p=L(o,t);return p||(o.formatted.add(d),null)},J=(o,t)=>{let r={id:null};return o.order.splice(t,0,r),o.created.push(r),r},X=o=>re(o,e),M=o=>o===null?null:a.story(o.start.story),V=o=>o===void 0||o==="allMarkup"||o==="original",nt=(o,t,r,d)=>{if(!V(d?.projection))return l("unsupported-content","unknown text projection","projection");if(d?.matchWildcards===true)return l("unsupported-capability","wildcard search is not implemented","matchWildcards");if(d?.ignorePunct===true)return l("unsupported-capability","ignoring punctuation is not implemented","ignorePunct");if(d?.ignoreSpace===true)return l("unsupported-capability","ignoring whitespace is not implemented","ignoreSpace");if(!hh(r))return l("unsupported-content","that is not a query this host will scan for","text");let p=d?.limit;if(p!==void 0&&(!Number.isInteger(p)||p<0))return l("invalid-offset","limit must be a non-negative integer",String(p));let f=wn(o,t,e,r,d);return f.ok?I({kind:"spans",spans:f.spans}):l("invalid-offset","projection mapping failed",f.paragraphId)},bt=(o,t,r)=>{if(typeof r!="string")return l("unsupported-content","insertText needs text","text");if(Pt.test(r))return l("unsupported-content","text carrying a paragraph mark is not written by this host","paragraph-mark-in-text");let d=y(o);if(d)return d;let p=L(o,t.paragraphId);if(p)return p;let f=r.length===0?[]:[{op:"insertText",paragraphId:t.paragraphId,offset:t.offset,text:r}],h=()=>({kind:"span",span:X({start:t,end:{...t,offset:t.offset+r.length}})});return {ok:true,kind:"command",ops:f,story:o.reads.story,answer:h}},Ot=(o,t,r)=>{let d=o.reads;if(typeof r!="string")return l("unsupported-content","replaceSpan needs text","text");if(Pt.test(r))return l("unsupported-content","text carrying a paragraph mark is not written by this host","paragraph-mark-in-text");let p=tt(t,d),f=t.start.paragraphId,h=[],x=y(o);if(x)return x;if(p.length===1){let j=L(o,f);if(j)return j;t.end.offset>t.start.offset&&h.push({op:"deleteText",paragraphId:f,start:t.start.offset,end:t.end.offset});}else {for(let w of p){let P=T(o,w);if(P)return P}let j=t.end.paragraphId,D=(d.paragraphText(f)??"").length;t.start.offset<D&&h.push({op:"deleteText",paragraphId:f,start:t.start.offset,end:D}),t.end.offset>0&&h.push({op:"deleteText",paragraphId:j,start:0,end:t.end.offset});for(let w of p.slice(1,-1))h.push({op:"deleteBlock",blockId:w});h.push({op:"joinParagraphs",firstId:f,secondId:j});for(let w of p.slice(1)){let P=o.slotById.get(w);P&&o.order.splice(C(o,P),1);}}r.length>0&&h.push({op:"insertText",paragraphId:f,offset:t.start.offset,text:r});let R={...t.start,paragraphId:f},H=()=>({kind:"span",span:X({start:R,end:{...R,offset:R.offset+r.length}})});return {ok:true,kind:"command",ops:h,story:o.reads.story,answer:H}},pe=(o,t)=>{let r=o.reads;if(typeof t!="string")return l("unsupported-content","replaceSpan needs text","text");if(Pt.test(t))return l("unsupported-content","text carrying a paragraph mark is not written by this host","paragraph-mark-in-text");let d=r.blocks,p=d.filter(P=>P.removable),f=d.filter(P=>!P.removable).flatMap(P=>P.paragraphIds),h=f.length===0?p.find(P=>P.kind==="paragraph"):void 0;if(!h&&f.length===0)return l("invalid-offset","that story holds no paragraph this host can write into","no-top-level-paragraph");let x=y(o);if(x)return x;for(let P of r.paragraphIds){let Q=T(o,P);if(Q)return Q}let R=[],H=(h?[h.id]:[...f]).sort((P,Q)=>r.indexOf(P)-r.indexOf(Q)),j=H[0];for(let P of H){let Q=(r.paragraphText(P)??"").length;Q>0&&R.push({op:"deleteText",paragraphId:P,start:0,end:Q});}for(let P of p)P.id!==h?.id&&R.push({op:"deleteBlock",blockId:P.id});t.length>0&&R.push({op:"insertText",paragraphId:j,offset:0,text:t});for(let P of p)if(P.id!==h?.id)for(let Q of P.paragraphIds){let wt=o.slotById.get(Q);wt&&o.order.splice(C(o,wt),1);}let D={story:r.story,paragraphId:j,index:r.indexOf(j),offset:0},w=()=>({kind:"span",span:X({start:D,end:{...D,offset:t.length}})});return {ok:true,kind:"command",ops:R,story:r.story,answer:w}},N=(o,t)=>{if(!Array.isArray(t)||t.length<1||t.length>1e4||t.some(d=>typeof d!="string"||Pt.test(d)||!O(d)))return l("unsupported-content","replaceStoryBlocks needs 1-10000 valid XML text strings without paragraph marks","paragraphs");let r=y(o);if(r)return r;for(let d of o.reads.paragraphIds){let p=T(o,d);if(p)return p}o.order.splice(0,o.order.length);for(let d=0;d<t.length;d+=1)J(o,d);return {ok:true,kind:"command",ops:[{op:"replaceStoryBlocks",storyRootId:o.reads.root.id,paragraphs:t}],story:o.reads.story,answer:()=>E}},z=(o,t,r,d)=>{let p=o.reads;if(typeof d!="string")return l("unsupported-content","insertParagraph needs text","text");if(Pt.test(d))return l("unsupported-content","a paragraph mark inside a paragraph\u2019s text is not written by this host","paragraph-mark-in-text");let f=y(o);if(f)return f;let h=T(o,t.paragraphId);if(h)return h;let x=o.slotById.get(t.paragraphId);if(!x)return l("invalid-handle","that paragraph is not in the body");let R=(p.paragraphText(t.paragraphId)??"").length,H=[];r==="after"?(d.length>0&&H.push({op:"insertText",paragraphId:t.paragraphId,offset:R,text:d}),H.push({op:"splitParagraph",paragraphId:t.paragraphId,offset:R})):(d.length>0&&H.push({op:"insertText",paragraphId:t.paragraphId,offset:0,text:d}),H.push({op:"splitParagraph",paragraphId:t.paragraphId,offset:d.length}));let j=J(o,C(o,x)+1);r==="before"&&o.retargets.push({from:t.paragraphId,slot:j});let D=()=>{let w=r==="after"?j.id:t.paragraphId;return w===null?E:{kind:"handle",handle:e.paragraph(w,p.story)}};return {ok:true,kind:"command",ops:H,story:p.story,answer:D}},st=(o,t,r,d,p)=>{let f=o.reads;if(!Array.isArray(r)||r.length===0)return l("unsupported-content","split needs at least one delimiter","delimiters");if(r.length>qo)return l("unsupported-content","too many delimiters",String(r.length));for(let $ of r){if(typeof $!="string"||$.length===0)return l("unsupported-content","a delimiter must be a non-empty string","delimiters");if($.length>tr)return l("unsupported-content","that delimiter is too long","delimiters")}let h=y(o);if(h)return h;let x=T(o,t.paragraphId);if(x)return x;let R=o.slotById.get(t.paragraphId);if(!R)return l("invalid-handle","that paragraph is not in the body");let H=f.paragraphText(t.paragraphId)??"",j=ir(H,r),D=[],w=[],P=[];if(j.length===0)P.push(H);else if(d){for(let U of [...j].reverse())D.push({op:"deleteText",paragraphId:t.paragraphId,start:U.start,end:U.start+U.length});let $=0,ut=0;for(let U of j){let Ut=U.start-$;w.push(Ut),P.push(H.slice(ut,U.start)),ut=U.start+U.length,$+=U.length;}P.push(H.slice(ut));}else {let $=0;for(let ut of j){let U=ut.start+ut.length;w.push(U),P.push(H.slice($,U)),$=U;}P.push(H.slice($));}w.length>0&&D.push({op:"splitParagraphMany",paragraphId:t.paragraphId,offsets:w});let Q=[R];for(let $=0;$<w.length;$+=1)Q.push(J(o,C(o,R)+1+$));let wt=$=>{let ut=$.story(f.story),U=[];return Q.forEach((Ut,ao)=>{let Xt=Ut.id;if(Xt===null)return;let Yt=ut?.paragraphText(Xt)??P[ao]??"",[so,io]=p?ur(Yt,0,Yt.length):[0,Yt.length],ge=e.paragraph(Xt,f.story);U.push({start:{paragraph:ge,offset:so},end:{paragraph:ge,offset:io}});}),{kind:"spans",spans:U}};return {ok:true,kind:"command",ops:D,story:f.story,answer:wt}},xt=(o,t)=>{let r=y(o);if(r)return r;let d=T(o,t.paragraphId);if(d)return d;let p=o.slotById.get(t.paragraphId);return p&&o.order.splice(C(o,p),1),{ok:true,kind:"command",ops:[{op:"deleteBlock",blockId:t.paragraphId}],story:o.reads.story,answer:()=>E}},pt=(o,t,r)=>{let d=o.reads,p=d.part,f=y(o);if(f)return f;let h=pn(r??{});if(!h.ok)return l("unsupported-content","that is not formatting this host writes",h.detail);let x=[];for(let R of oe(t,d)){if(R.end<=R.start&&!R.whole)continue;let H=F(o,R.paragraphId,"runs");if(H)return H;for(let j of Mg(p,R.paragraphId,R.start,R.end,h.value,n.displayMode))x.push({op:"setRunProperties",paragraphId:R.paragraphId,start:j.start,end:j.end,properties:j.properties,...j.targetRunIds?{targetRunIds:j.targetRunIds}:{}});R.whole&&x.push({op:"setParagraphMarkProperties",paragraphId:R.paragraphId,properties:Lg(p,R.paragraphId,h.value)});}return x.length===0?l("invalid-offset","that range covers no characters to format","collapsed-range"):{ok:true,kind:"command",ops:x,story:d.story,answer:()=>E}},Qn=(o,t,r)=>{let d=o.reads,p=d.part,f=y(o);if(f)return f;let h=_t(r,d.styles());if(!h.ok)return l("unsupported-content","that is not a style this document has",h.detail);let x={localName:"pStyle",attributes:{val:h.styleId}},R=[];for(let H of tt(t,d)){let j=F(o,H,"paragraph");if(j)return j;R.push({op:"setParagraphProperties",paragraphId:H,properties:Gg(Eg(p,H),x)});}return R.length===0?l("invalid-offset","that story holds no paragraph to style","empty-story"):{ok:true,kind:"command",ops:R,story:d.story,answer:()=>E}},Zn=(o,t,r)=>{let d=o.reads,p=d.part,f=y(o);if(f)return f;let h=mn(p,t.paragraphId,r??{},d.styles());if(!h.ok)return l("unsupported-content","that is not paragraph formatting this host writes",h.detail);let x=F(o,t.paragraphId,"paragraph");return x||{ok:true,kind:"command",ops:[{op:"setParagraphProperties",paragraphId:t.paragraphId,properties:h.value}],story:d.story,answer:()=>E}},qn=(o,t)=>{let r=a.body;if(!r)return l("document-unavailable","this host holds no document right now");let d=a.sections();if(!d[o])return l("invalid-handle","that section is not in this document");let f=yn(t);if(!f.ok)return l("unsupported-content",f.reason,f.detail);let h=dr(r,d,o);if(h===null)return l("unsupported-content","that section holds no paragraph to address it by","no-anchor");let x=u(r),R=y(x);return R||{ok:true,kind:"command",ops:[{op:"setSectionProperties",...f.value,anchorParagraphId:h}],story:ct,answer:()=>E}},to=(o,t)=>({ok:true,kind:"command",ops:[{op:"deleteNote",noteKind:o,noteId:t}],story:ct,lifecycle:true,answer:()=>E}),Vt=o=>{let t=e.resolve(o,"list");if(!t||t.kind!=="list")return l("invalid-handle","that handle does not name a list","list");let r=a.story(t.story);if(!r)return l("invalid-handle","that story is not in this document");let d=zt(r).find(p=>p.numId===t.numId);return d?{ok:true,plan:u(r),list:d}:l("invalid-handle","this story numbers nothing with that list",t.numId)},$t=o=>{if(typeof o!="object"||o===null)return l("invalid-handle","that is not a scope a control lives in","scope");let t=o;if("body"in o){let r=K(t.body,"body",e,a);return r.ok?{reads:r.value,node:r.value.root}:l(r.code,"that handle does not name a body",r.detail)}if("contentControl"in o){let r=ot(t.contentControl);return "control"in r?{reads:r.reads,node:r.node}:r}return l("invalid-handle","that is not a scope a control lives in","scope")},ot=o=>{let t=e.resolve(o,"contentControl");if(!t||t.kind!=="contentControl")return l("invalid-handle","that handle does not name a content control","contentControl");let r=a.story(t.story);if(!r)return l("invalid-handle","that story is not in this document");let d=Fn(r,t.nodeId),p=_n(r,t.nodeId);return !d||!p?l("invalid-handle","this document no longer holds that content control"):{reads:r,control:d,node:p}},eo=(o,t,r)=>{if(!Number.isInteger(r)||r<0||r>At)return l("invalid-offset",`a list level is 0 to ${String(At)}`,String(r));if(!Ct(o.reads,t))return l("unsupported-content","that paragraph is not in a list",t);let d=y(o);if(d)return d;let p=F(o,t,"paragraph");return p||{ok:true,kind:"command",ops:[{op:"setListLevel",paragraphId:t,level:r}],story:o.reads.story,answer:()=>E}},no=(o,t,r,d)=>{if(r!=="start"&&r!=="end")return l("unknown-operation","a list takes an item at its start or its end",String(r));let p=o.reads,f=r==="start"?t.paragraphIds[0]:t.paragraphIds[t.paragraphIds.length-1];if(f===void 0)return l("invalid-handle","that list holds no paragraph");let h={story:p.story,paragraphId:f,index:p.indexOf(f)};return z(o,h,r==="start"?"before":"after",d)},me=(o,t)=>{if(t.start.paragraphId!==t.end.paragraphId)return null;for(let r of Rn(o,t.start.paragraphId))if(r.start<=t.start.offset&&r.end>=t.end.offset)return r;return null},oo=(o,t,r)=>{if(typeof r!="string")return l("unsupported-content","a hyperlink target is a string","target");let d=o.reads,p=me(d,t),f=t.start.paragraphId===t.end.paragraphId&&t.start.offset===t.end.offset;if(r.length===0){if(!p)return l("unsupported-content","that text is not a link","no-link");let w=y(o);if(w)return w;let P=L(o,p.paragraphId);return P||{ok:true,kind:"command",ops:[{op:"removeHyperlink",linkId:p.id}],story:d.story,answer:()=>E}}let h={},x=null;if(r.startsWith("#")){let w=r.slice(1);if(w.length===0||!ie(d,w))return l("unsupported-content","this document declares no such bookmark",r);h={anchor:w};}else {if($c(r)===null)return l("unsupported-content","this engine will not author that target","target");x=r;}let R=y(o);if(R)return R;let H=w=>x===null?{ok:true,kind:"command",ops:[w(h)],story:d.story,answer:()=>E}:{ok:true,kind:"command",ops:[],relate:{url:x,ops:P=>[w({relationshipId:P})]},story:d.story,answer:()=>E};if(p){let w=L(o,p.paragraphId);return w||H(P=>({op:"setHyperlinkTarget",linkId:p.id,...P}))}if(f)return l("unsupported-content","a link with no text has nothing to click","collapsed");if(t.start.paragraphId!==t.end.paragraphId)return l("unsupported-content","a link lives inside one paragraph","crosses-paragraph-mark");let j=L(o,t.start.paragraphId);if(j)return j;let D=d.styles().idOf("hyperlink");return H(w=>({op:"insertHyperlink",paragraphId:t.start.paragraphId,start:t.start.offset,end:t.end.offset,...w,...D===null?{}:{styleId:D}}))},fe=(o,t,r)=>{let d=o.reads;if(!s.selection||!n.select)return l("unsupported-capability","this host has no reader to move","selection");if(r!=="select"&&r!=="start"&&r!=="end")return l("unknown-operation","that is not a selection mode",String(r));let p=tt(t,d);for(let f of p)if(o.touched.has(f))return l("conflicting-operations","this batch edits a paragraph the selection covers",f);for(let f of p)o.selected.add(f);return c.push({range:t,mode:r}),{ok:true,kind:"command",ops:[],story:d.story,answer:()=>E}},ye=o=>{let t=e.resolve(o,"bookmark");if(!t||t.kind!=="bookmark")return l("invalid-handle","that handle does not name a bookmark","bookmark");let r=a.story(t.story);if(!r)return l("invalid-handle","that story is not in this document");let d=ie(r,t.name);if(!d)return l("invalid-handle","this document no longer declares that bookmark",t.name);let p=f=>({story:r.story,paragraphId:f.paragraphId,index:r.indexOf(f.paragraphId),offset:f.offset});return {reads:r,range:{start:p(d.start),end:p(d.end)}}},ro=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(ct)}):l("document-unavailable","this host holds no document right now"):l("invalid-handle","that handle does not name a document","document");case "getParagraphs":{let t=K(o.body,"body",e,a);return t.ok?I({kind:"handles",handles:t.value.paragraphIds.map(r=>e.paragraph(r,t.value.story))}):l(t.code,"that handle does not name a body",t.detail)}case "getSpanParagraphs":{let t=W(o.span,e,a);if(!t.ok)return l(t.code,"that span is not a place",t.detail);let r=q(o.span,e,a);return r.ok?I({kind:"handles",handles:tt(t.value,r.value).map(d=>e.paragraph(d,r.value.story))}):l(r.code,"that span is not a place",r.detail)}case "getText":{if(!V(o.projection))return l("unsupported-content","unknown text projection","projection");if(e.resolve(o.target,"body")){let p=K(o.target,"body",e,a);return p.ok?I({kind:"text",text:p.value.text(o.projection??"allMarkup")}):l(p.code,"that handle does not name a body",p.detail)}let r=Z(o.target,e,a);if(!r.ok)return l(r.code,"that handle does not name a body or a paragraph",r.detail);let d=a.story(r.value.story);return I({kind:"text",text:d?.paragraphText(r.value.paragraphId,o.projection??"allMarkup")??""})}case "getSpanText":{if(!V(o.projection))return l("unsupported-content","unknown text projection","projection");let t=W(o.span,e,a);if(!t.ok)return l(t.code,"that span is not a place",t.detail);let r=q(o.span,e,a);return r.ok?I({kind:"text",text:In(t.value,r.value,ne,o.projection??"allMarkup")}):l(r.code,"that span is not a place",r.detail)}case "getParagraphId":{let t=Z(o.paragraph,e,a);if(!t.ok)return l(t.code,"that handle does not name a paragraph",t.detail);let d=a.story(t.value.story)?.paragraph(t.value.paragraphId);return I({kind:"text",text:d?.paraId??""})}case "search":{let t=W(o.scope,e,a);if(!t.ok)return l(t.code,"that is not a scope to search",t.detail);let r=q(o.scope,e,a);return r.ok?nt(r.value,t.value,o.text,o.options):l(r.code,"that is not a scope to search",r.detail)}case "insertText":{let t=kt(o.at,e,a);if(!t.ok)return l(t.code,"that is not a place to insert at",t.detail);let r=a.story(t.value.story);return r?bt(u(r),t.value,o.text):l("invalid-handle","that story is not in this document")}case "replaceSpan":{if("body"in o.span){let d=K(o.span.body,"body",e,a);return d.ok?pe(u(d.value),o.text):l(d.code,"that handle does not name a body",d.detail)}let t=W(o.span,e,a);if(!t.ok)return l(t.code,"that span is not a place",t.detail);if(!t.value)return l("invalid-offset","that story holds no paragraph to write into","empty-story");let r=M(t.value);return r?Ot(u(r),t.value,o.text):l("invalid-handle","that story is not in this document")}case "replaceStoryBlocks":{let t=K(o.body,"body",e,a);return t.ok?N(u(t.value),o.paragraphs):l(t.code,"that handle does not name a body",t.detail)}case "insertParagraph":{let t=Wt(o.anchor,e,a);if(!t.ok)return l(t.code,"that is not a paragraph to insert beside",t.detail);if(o.where!=="before"&&o.where!=="after")return l("unknown-operation","that is not a place to insert",String(o.where));let r=a.story(t.value.story);return r?z(u(r),t.value,o.where,o.text):l("invalid-handle","that story is not in this document")}case "splitParagraph":{let t=Z(o.paragraph,e,a);if(!t.ok)return l(t.code,"that handle does not name a paragraph",t.detail);let r=a.story(t.value.story);return r?st(u(r),t.value,o.delimiters,o.trimDelimiters===true,o.trimSpacing===true):l("invalid-handle","that story is not in this document")}case "getFont":{let t=W(o.span,e,a);if(!t.ok)return l(t.code,"that span is not a place",t.detail);let r=q(o.span,e,a);if(!r.ok)return l(r.code,"that span is not a place",r.detail);let d=oe(t.value,r.value);return I({kind:"font",font:un(r.value.part,d,n.displayMode)})}case "setFont":{let t=W(o.span,e,a);if(!t.ok)return l(t.code,"that span is not a place",t.detail);if(!t.value)return l("invalid-offset","that story holds no paragraph to format","empty-story");let r=M(t.value);return r?pt(u(r),t.value,o.font):l("invalid-handle","that story is not in this document")}case "getStyle":{let t=W(o.span,e,a);if(!t.ok)return l(t.code,"that span is not a place",t.detail);let r=q(o.span,e,a);if(!r.ok)return l(r.code,"that span is not a place",r.detail);let d=r.value.part,p=r.value.styles(),f=tt(t.value,r.value).map(x=>Ft(d,x,p)),h=f.length>0&&f.every(x=>x!==null&&x===f[0])?f[0]:null;return I({kind:"style",name:h})}case "setStyle":{let t=W(o.span,e,a);if(!t.ok)return l(t.code,"that span is not a place",t.detail);if(!t.value)return l("invalid-offset","that story holds no paragraph to style","empty-story");let r=M(t.value);return r?Qn(u(r),t.value,o.name):l("invalid-handle","that story is not in this document")}case "getParagraphFormat":{let t=Wt(o.paragraph,e,a);if(!t.ok)return l(t.code,"that is not a paragraph",t.detail);let r=a.story(t.value.story);if(!r)return l("document-unavailable","this host holds no document right now");let d=cn(r.part,t.value.paragraphId,r.styles());return d?I({kind:"paragraphFormat",format:d}):l("invalid-handle","that handle does not name a paragraph")}case "setParagraphFormat":{let t=Wt(o.paragraph,e,a);if(!t.ok)return l(t.code,"that is not a paragraph",t.detail);let r=a.story(t.value.story);return r?Zn(u(r),t.value,o.format):l("invalid-handle","that story is not in this document")}case "deleteParagraph":{let t=Z(o.paragraph,e,a);if(!t.ok)return l(t.code,"that handle does not name a paragraph",t.detail);let r=a.story(t.value.story);return r?xt(u(r),t.value):l("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))}):l("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 l("invalid-handle","that handle does not name a section","section");let r=a.sections()[t.index];return r?I({kind:"pageSetup",setup:r.pageSetup}):l("invalid-handle","that section is not in this document")}case "setPageSetup":{let t=e.resolve(o.section,"section");return !t||t.kind!=="section"?l("invalid-handle","that handle does not name a section","section"):qn(t.index,o.setup)}case "getFurniture":{let t=e.resolve(o.section,"section");if(!t||t.kind!=="section")return l("invalid-handle","that handle does not name a section","section");if(o.kind!=="header"&&o.kind!=="footer")return l("unknown-operation","that is not furniture",String(o.kind));let r={kind:o.kind,sectionIndex:t.index,variant:o.variant};return an(r)?a.story(r)?I({kind:"handle",handle:e.body(r)}):l("invalid-handle","this document declares no such header or footer",B(r)):l("unknown-operation","that is not a furniture variant",String(o.variant))}case "getNotes":{if(!e.resolve(o.document,"document"))return l("invalid-handle","that handle does not name a document","document");if(o.noteKind!=="footnote"&&o.noteKind!=="endnote")return l("unknown-operation","that is not a kind of note",String(o.noteKind));let t=o.noteKind,r=a.noteIds(t);return r.ok?I({kind:"handles",handles:r.ids.map(d=>e.note(t,d))}):l("ambiguous-document",`${t} identities are not completely and unambiguously enumerable`,r.reason==="duplicates"?r.duplicateIds.join(","):r.reason)}case "getNoteBody":case "getNoteText":{let t=e.resolve(o.note,"note");if(!t||t.kind!=="note")return l("invalid-handle","that handle does not name a note","note");let r=t,d=a.story(r);return d?o.op==="getNoteText"?I({kind:"text",text:d.text(o.projection)}):I({kind:"handle",handle:e.body(r)}):l("invalid-handle","that note is not in this document",B(r))}case "getNoteKind":{let t=e.resolve(o.note,"note");return !t||t.kind!=="note"?l("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");if(!t||t.kind!=="note")return l("invalid-handle","that handle does not name a note","note");let r=a.noteIds(t.noteKind);return r.ok?r.ids.includes(t.noteId)?to(t.noteKind,t.noteId):l("invalid-handle","that note is not in this document"):l("ambiguous-document",`${t.noteKind} identities are not completely and unambiguously enumerable`,r.reason==="duplicates"?r.duplicateIds.join(","):r.reason)}case "getLists":{let t=K(o.body,"body",e,a);return t.ok?I({kind:"handles",handles:zt(t.value).map(r=>e.list(r.numId,t.value.story))}):l(t.code,"that handle does not name a body",t.detail)}case "getListId":{let t=Vt(o.list);return "list"in t?I({kind:"number",value:Number(t.list.numId)}):t}case "getListById":{let t=K(o.body,"body",e,a);if(!t.ok)return l(t.code,"that handle does not name a body",t.detail);if(!Number.isInteger(o.id)||o.id<=0)return l("unsupported-content","a list is numbered from one",String(o.id));let r=String(o.id),d=zt(t.value).find(p=>p.numId===r);return d?I({kind:"handle",handle:e.list(d.numId,t.value.story)}):l("invalid-handle","no list in that story carries that number",r)}case "getListParagraphs":{let t=Vt(o.list);if(!("list"in t))return t;let r=o.level;if(r!==void 0&&(!Number.isInteger(r)||r<0||r>At))return l("invalid-offset",`a list level is 0 to ${String(At)}`,String(r));let d=t.plan.reads,p=r===void 0?t.list.paragraphIds:t.list.paragraphIds.filter(f=>Ct(d,f)?.level===r);return I({kind:"handles",handles:p.map(f=>e.paragraph(f,d.story))})}case "getParagraphList":{let t=Z(o.paragraph,e,a);if(!t.ok)return l(t.code,"that handle does not name a paragraph",t.detail);let r=a.story(t.value.story);if(!r)return l("invalid-handle","that story is not in this document");let d=Ct(r,t.value.paragraphId);return d?I({kind:"handle",handle:e.list(d.numId,r.story)}):l("unsupported-content","that paragraph is not in a list",t.value.paragraphId)}case "getListLevel":{let t=Z(o.paragraph,e,a);if(!t.ok)return l(t.code,"that handle does not name a paragraph",t.detail);let r=a.story(t.value.story);if(!r)return l("invalid-handle","that story is not in this document");let d=Ct(r,t.value.paragraphId);return d?I({kind:"number",value:d.level}):l("unsupported-content","that paragraph is not in a list",t.value.paragraphId)}case "setListLevel":{let t=Z(o.paragraph,e,a);if(!t.ok)return l(t.code,"that handle does not name a paragraph",t.detail);let r=a.story(t.value.story);return r?eo(u(r),t.value.paragraphId,o.level):l("invalid-handle","that story is not in this document")}case "insertListParagraph":{let t=Vt(o.list);return "list"in t?no(t.plan,t.list,o.where,o.text):t}case "getHyperlink":{let t=W(o.span,e,a);if(!t.ok)return l(t.code,"that span is not a place",t.detail);let r=q(o.span,e,a);if(!r.ok)return l(r.code,"that span is not a place",r.detail);let d=a.package;if(!d||!t.value)return I({kind:"text",text:""});let p=me(r.value,t.value);if(!p)return I({kind:"text",text:""});let f=ya(r.value.part,p.id),h=f?Cn(d,r.value.part.name,f):null;return I({kind:"text",text:h??""})}case "setHyperlink":{let t=W(o.span,e,a);if(!t.ok)return l(t.code,"that span is not a place",t.detail);if(!t.value)return l("invalid-offset","that story holds no text to link","empty-story");let r=M(t.value);return r?oo(u(r),t.value,o.target):l("invalid-handle","that story is not in this document")}case "getBookmarks":{let t=W(o.scope,e,a);if(!t.ok)return l(t.code,"that span is not a place",t.detail);let r=q(o.scope,e,a);if(!r.ok)return l(r.code,"that span is not a place",r.detail);let d=r.value,p=t.value,f=p===null?null:new Set(tt(p,d)),h=se(d).filter(x=>{if(!f||!f.has(x.start.paragraphId)&&!f.has(x.end.paragraphId)||p===null)return false;let R=x.start.paragraphId===p.end.paragraphId&&x.start.offset>p.end.offset,H=x.end.paragraphId===p.start.paragraphId&&x.end.offset<p.start.offset;return !R&&!H});return I({kind:"handles",handles:h.map(x=>e.bookmark(x.name,d.story))})}case "getBookmarkName":{let t=e.resolve(o.bookmark,"bookmark");return !t||t.kind!=="bookmark"?l("invalid-handle","that handle does not name a bookmark","bookmark"):I({kind:"text",text:t.name})}case "getBookmarkRange":{let t=ye(o.bookmark);return "reads"in t?I({kind:"span",span:X(t.range)}):t}case "getComments":{let t=W(o.scope,e,a);if(!t.ok)return l(t.code,"that scope is not a place",t.detail);let r=q(o.scope,e,a);if(!r.ok)return l(r.code,"that scope names no story",r.detail);let d=r.value,p=k(d);if(!p)return l("document-unavailable","this host holds no document");let f=t.value,h=p.roots.filter(x=>{if(!f)return true;let R=x.range;if(!R)return false;let H=d.indexOf(R.start.paragraphId),j=d.indexOf(R.end.paragraphId),D=d.indexOf(f.start.paragraphId),w=d.indexOf(f.end.paragraphId);return j<D||H>w?false:j===D&&H===D&&w===D?R.end.offset>f.start.offset&&R.start.offset<f.end.offset:true});return I({kind:"handles",handles:h.map(x=>e.comment(x.id,d.story))})}case "getCommentReplies":{let t=S(o.comment);return t.ok?I({kind:"handles",handles:t.item.replyIds.map(r=>e.comment(r,t.reads.story))}):t.planned}case "getCommentId":{let t=S(o.comment);return t.ok?I({kind:"text",text:t.item.id}):t.planned}case "getCommentAuthor":{let t=S(o.comment);return t.ok?I({kind:"text",text:t.item.comment.author}):t.planned}case "getCommentDate":{let t=S(o.comment);return t.ok?I({kind:"text",text:t.item.comment.date??""}):t.planned}case "getCommentText":{let t=S(o.comment);if(!t.ok)return t.planned;let r=k(t.reads);return I({kind:"text",text:r?.textOf(t.item.id)??""})}case "getCommentRange":{let t=S(o.comment);if(!t.ok)return t.planned;let r=t.item.range;if(!r||t.item.orphaned)return l("invalid-handle","that comment has no range in this document");let d=b(t.reads,r);return d?I({kind:"span",span:d}):l("invalid-handle","that comment\u2019s range is no longer in the story")}case "getCommentResolved":{let t=S(o.comment);return t.ok?I({kind:"flag",value:t.item.resolved}):t.planned}case "insertComment":return Ln(o,e,a,v);case "setCommentResolved":{let t=S(o.comment);if(!t.ok)return t.planned;if(typeof o.resolved!="boolean")return l("unsupported-content","resolved is a yes or a no",String(o.resolved));let r=y(u(t.reads));return r||{ok:true,kind:"commentWrite",write:{kind:"resolve",commentId:t.item.id,resolved:o.resolved},story:t.reads.story,answer:()=>E}}case "replyToComment":{let t=S(o.comment);if(!t.ok)return t.planned;let r=ue({author:o.author,text:o.text,date:o.date,kind:"reply"});if(r)return r;let d=t.item.range;if(!d||t.item.orphaned)return l("invalid-handle","that comment has no range to reply over");let p=y(u(t.reads));if(p)return p;let f=t.reads.story,h=ce(o.date);return {ok:true,kind:"commentWrite",write:{kind:"reply",parentCommentId:t.item.id,anchor:{paragraphId:d.start.paragraphId,start:d.start.offset,end:d.end.offset,...d.end.paragraphId===d.start.paragraphId?{}:{endParagraphId:d.end.paragraphId}},text:o.text,author:o.author,...h===void 0?{}:{date:h}},story:t.reads.story,answer:(x,R)=>R===void 0?E:{kind:"handle",handle:e.comment(R,f)}}}case "deleteComment":{let t=S(o.comment);return t.ok?En(t.item,t.reads,r=>y(u(r))):t.planned}case "getRevisions":{let t=K(o.body,"body",e,a);if(!t.ok)return l(t.code,"that handle does not name a body",t.detail);let r=t.value;return I({kind:"handles",handles:de(r).map(d=>e.revision(d.id,r.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[r]=t.item.item.ranges;if(!r)return l("invalid-handle","that change covers no characters");let d=b(t.reads,r);return d?I({kind:"span",span:d}):l("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 r=u(t.reads),d=y(r);if(d)return d;let p=o.op==="acceptRevision";return {ok:true,kind:"command",story:t.reads.story,ops:t.item.item.addresses.map(f=>p?{op:"acceptRevision",revision:f}:{op:"rejectRevision",revision:f}),answer:()=>E}}case "acceptAllRevisions":case "rejectAllRevisions":{let t=Nn(o,e,a);if(!t.ok)return l(t.code,t.message,t.detail);let r=u(t.reads),d=y(r);if(d)return d;let p=Hn(o,t.reads);return {ok:true,kind:"command",story:t.reads.story,ops:p,answer:()=>E}}case "selectSpan":{let t=W(o.span,e,a);if(!t.ok)return l(t.code,"that span is not a place",t.detail);if(!t.value)return l("invalid-offset","that story holds no paragraph to select","empty-story");let r=M(t.value);return r?fe(u(r),t.value,o.mode):l("invalid-handle","that story is not in this document")}case "selectBookmark":{let t=ye(o.bookmark);return "reads"in t?fe(u(t.reads),t.range,o.mode):t}case "getContentControls":{let t=$t(o.scope);return "reads"in t?I({kind:"handles",handles:Bn(t.reads,t.node).map(r=>e.contentControl(r.nodeId,t.reads.story))}):t}case "getContentControlById":{let t=$t(o.scope);if(!("reads"in t))return t;if(!Number.isInteger(o.id))return l("unsupported-content","a control id is a whole number",String(o.id));let r=Gn(t.node).find(d=>Ge(d).id===o.id);return r?I({kind:"handle",handle:e.contentControl(r.id,t.reads.story)}):l("invalid-handle","no control in that scope carries that id",String(o.id))}case "getContentControlsByTag":case "getContentControlsByTitle":{let t=$t(o.scope);if(!("reads"in t))return t;let r=o.op==="getContentControlsByTag"?o.tag:o.title;if(typeof r!="string"||r.length===0)return l("unsupported-content","a tag or title to match is required",o.op);let d=Gn(t.node).filter(p=>{let f=Ge(p);return o.op==="getContentControlsByTag"?f.tag===r:f.alias===r});return I({kind:"handles",handles:d.map(p=>e.contentControl(p.id,t.reads.story))})}case "getContentControlTag":case "getContentControlTitle":case "getContentControlFileId":case "getContentControlSubtype":case "getContentControlLock":{let t=ot(o.contentControl);if(!("control"in t))return t;let r=t.control.properties;if(o.op==="getContentControlLock")return I({kind:"text",text:t.control.lock});if(o.op==="getContentControlSubtype")return I({kind:"text",text:r.type});if(o.op==="getContentControlFileId")return I({kind:"text",text:r.id===void 0?"":String(r.id)});let d=o.op==="getContentControlTag"?r.tag:r.alias;return I({kind:"text",text:d??""})}case "getContentControlIsBound":case "getContentControlPlaceholderShown":case "getContentControlTemporary":{let t=ot(o.contentControl);if(!("control"in t))return t;let r=o.op==="getContentControlIsBound"?t.control.properties.dataBinding!==void 0:o.op==="getContentControlPlaceholderShown"?t.control.properties.showingPlaceholder:t.control.properties.temporary;return I({kind:"flag",value:r})}case "getContentControlText":{let t=ot(o.contentControl);return "control"in t?I({kind:"text",text:Dn(t.reads,t.node,o.projection)}):t}case "getContentControlParagraphs":{let t=ot(o.contentControl);return "control"in t?I({kind:"handles",handles:t.control.paragraphIds.map(r=>e.paragraph(r,t.reads.story))}):t}case "getContentControlRange":{let t=ot(o.contentControl);if(!("control"in t))return t;let r=o.location??"whole";if(!or.has(r))return l("unsupported-content","that is not a place in a control",r);let d=Kt(t.reads,t.node);if(!d)return l("unsupported-content","that control holds nothing addressable","empty");let p=r==="start"||r==="before"?d.start:d.end,f=r!=="whole"&&r!=="content",h=x=>({story:t.reads.story,paragraphId:x.paragraphId,index:t.reads.indexOf(x.paragraphId),offset:x.offset});return I({kind:"span",span:re(f?{start:h(p),end:h(p)}:{start:h(d.start),end:h(d.end)},e)})}case "setContentControlValue":{let t=ot(o.contentControl);if(!("control"in t))return t;let r=sr(o.value);if(!r.ok)return l(r.code,r.message,r.detail);let d=u(t.reads),p=y(d);return p||{ok:true,kind:"command",story:t.reads.story,ops:[{op:"setContentControlValue",controlId:t.control.nodeId,value:r.value}],answer:()=>E}}case "setContentControlProperties":{let t=ot(o.contentControl);if(!("control"in t))return t;if(o.tag===void 0&&o.title===void 0&&o.lock===void 0)return l("unsupported-content","nothing to write","no-properties");if(o.lock!==void 0&&!nr.has(o.lock))return l("unsupported-content","that is not a lock this schema declares",o.lock);let r=u(t.reads),d=y(r);return d||{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:()=>E}}case "insertContentControlText":{let t=ot(o.contentControl);if(!("control"in t))return t;if(typeof o.text!="string")return l("unsupported-content","text is required","text");if(o.at!=="replace"&&o.at!=="start"&&o.at!=="end")return l("unsupported-content","that is not a place to insert at",String(o.at));let r=u(t.reads),d=y(r);if(d)return d;let p=Kt(t.reads,t.node);if(!p)return l("unsupported-content","that control holds nothing addressable","empty");let f=o.at==="end"?p.end:p.start,h=()=>({kind:"span",span:X({start:{story:t.reads.story,paragraphId:f.paragraphId,index:t.reads.indexOf(f.paragraphId),offset:f.offset},end:{story:t.reads.story,paragraphId:f.paragraphId,index:t.reads.indexOf(f.paragraphId),offset:f.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:h}:{ok:true,kind:"command",story:t.reads.story,ops:o.text.length===0?[]:[{op:"insertText",paragraphId:f.paragraphId,offset:f.offset,text:o.text,inside:t.node.id}],answer:h}}case "deleteContentControl":{let t=ot(o.contentControl);if(!("control"in t))return t;if(typeof o.keepContent!="boolean")return l("unsupported-content","keepContent is required","keepContent");let r=u(t.reads),d=y(r);return d||{ok:true,kind:"command",story:t.reads.story,ops:[{op:"removeContentControl",controlId:t.control.nodeId,keepContent:o.keepContent}],answer:()=>E}}case "insertContentControl":{let t=W(o.span,e,a);if(!t.ok)return l(t.code,"that span is not a place",t.detail);if(!t.value)return l("invalid-offset","that story holds nothing to wrap","empty-story");let r=M(t.value);if(!r)return l("invalid-handle","that story is not in this document");let d=t.value;if(d.start.paragraphId!==d.end.paragraphId)return l("unsupported-content","wrapping several paragraphs in one control is not supported here","multi-paragraph");if(!rr.has(o.subtype))return l("unsupported-content","that control type cannot be inserted",o.subtype);let p=u(r),f=y(p);return f||{ok:true,kind:"command",story:r.story,ops:[{op:"insertContentControl",paragraphId:d.start.paragraphId,start:d.start.offset,end:d.end.offset,type:o.subtype,...o.tag===void 0?{}:{tag:o.tag},...o.title===void 0?{}:{alias:o.title}}],answer:()=>E}}case "insertCustomNode":{let t=$n(o);if(t)return l("unsupported-content",t.message,t.detail);let r=Vn(o.payload);if(!r.ok)return l("unsupported-content","that payload cannot be written",r.field);let d=Xn(o,e,a);if("code"in d)return l(d.code,d.message,d.detail);let{start:p,end:f}=d.range,h=M(d.range);if(!h)return l("invalid-handle","that story is not in this document");let x=y(u(h));return x||{ok:true,kind:"customNodeWrite",story:h.story,write:Un(o,p,f,r.value),answer:()=>E}}default:return l("unknown-operation","this host does not implement that operation",String(o.op))}};return {plan(o){let t=g.conflict(o);if(t)return l("conflicting-operations",t.message,t.detail);let r=ro(o);return r.ok&&g.note(o),r},get hasCommands(){return g.hasCommands},get writeScope(){return m?.reads.scope??null},settle(o){let t=m;if(t){let r=o.story(t.reads.story);if(!r)return {ok:false,detail:`the story this batch wrote is gone: ${B(t.reads.story)}`};let d=new Set(t.reads.paragraphIds),p=r.paragraphIds.filter(h=>!d.has(h));if(p.length!==t.created.length)return {ok:false,detail:`planned ${String(t.created.length)} new paragraphs, the transaction made ${String(p.length)}`};t.order.filter(h=>h.id===null).forEach((h,x)=>{h.id=p[x]??null;});for(let h of t.retargets)h.slot.id&&e.retarget(h.from,h.slot.id);}for(let r of c){let d=o.story(r.range.start.story);!d||!lr(r.range,d)||n.select?.(r.range,r.mode);}return {ok:true}}}}var cr=Object.freeze({status:"skipped"});function G(n,e,s){return Object.freeze(s===void 0?{code:n,message:e}:{code:n,message:e,detail:s})}function pr(n){let e=n==="unsupported-revision"||n.startsWith("unsupported-revision:");return G(e?"unsupported-revision":"transaction-refused",e?"that story contains a tracked change this engine cannot resolve":"the document store refused the transaction",n)}function et(n,e,s,a){return {ok:false,results:n.map((i,u)=>u===e?{status:"error",error:s}:cr),revision:a,changed:false}}function ns(n){let{port:e}=n,s=Object.freeze({...n.capabilities}),a=sn(),i=new Set,u=false,c=null,g=s.events?e.subscribe(()=>{if(u)return;let v=Object.freeze({revision:e.revision()});for(let k of [...i])k(v);}):()=>{},m=v=>{if(c&&c.pkg===v)return c.value;let k=bn(v);return c={pkg:v,value:k},k};return {capabilities:s,revision:()=>e.revision(),execute:v=>{let k=Array.isArray(v?.operations)?v.operations:[],S=e.revision();if(u)return et(k,0,G("disposed","this host was disposed"),S);if(!s.document)return et(k,0,G("unsupported-capability","this host has no document","document"),S);let A=e.currentPackage();if(!A)return et(k,0,G("document-unavailable","this host holds no document right now"),S);if(v.expectedRevision!==void 0&&v.expectedRevision!==S)return et(k,0,G("stale-revision","the document moved since that revision",`expected ${String(v.expectedRevision)}, at ${S}`),S);let b=Jn({handles:a,reads:m(A),capabilities:s,...e.revisionDisplayMode?{displayMode:e.revisionDisplayMode()}:{},...e.select?{select:e.select.bind(e)}:{}}),C=[],O=[],T=null,L=[],F=null,J,X=null,M=-1;for(let N=0;N<k.length;N+=1){let z=b.plan(k[N]);if(!z.ok)return et(k,N,z.error,S);if(C.push(z),z.kind==="command")if(M<0&&(M=N),z.lifecycle)T=z.ops[0]??null;else if(z.relate){let st=z.relate;O.push(xt=>{let pt=xt(st.url);return pt===null?null:st.ops(pt)});}else {let{ops:st}=z;O.push(()=>st);}else z.kind==="commentWrite"?(M<0&&(M=N),L.push(z.write),F=b.writeScope??{kind:"body"}):z.kind==="customNodeWrite"&&(M<0&&(M=N),X={write:z.write,scope:b.writeScope??{kind:"body"}});}let V=false;if(L.length>0){let N=e.applyCommentWrites(L,F??{kind:"body"});if(!N.ok)return et(k,M<0?0:M,G("transaction-refused","the document store refused the comment write",N.reason),S);V=N.changed,J=N.commentId;}if(X){let N=e.applyCustomNodeWrite(X.write,X.scope);if(!N.ok)return et(k,M<0?0:M,G("transaction-refused","the document store refused the custom-node write",N.reason),S);V=N.changed;}if(T){let N=e.applyLifecycle(T);if(!N.ok)return et(k,M<0?0:M,G("transaction-refused","the document store refused the transaction",N.reason),S);V=N.changed;}if(O.length>0){let N=e.apply(z=>{let st=[];for(let xt of O){let pt=xt(z);if(pt===null)return null;st.push(...pt);}return st},b.writeScope??{kind:"body"});if(!N.ok)return et(k,M<0?0:M,pr(N.reason),S);V=N.changed;}let nt=e.currentPackage();if(!nt)return et(k,0,G("document-unavailable","this host holds no document right now"),S);let bt=m(nt),Ot=b.settle(bt);return Ot.ok?{ok:true,results:C.map(N=>({status:"ok",value:N.kind==="query"?N.value:N.kind==="customNodeWrite"?N.answer(bt):N.answer(bt,J)})),revision:e.revision(),changed:V}:et(k,M<0?0:M,G("transaction-refused","the transaction did not produce the document the batch planned",Ot.detail),e.revision())},save(){if(u)return {ok:false,error:G("disposed","this host was disposed")};if(!s.save)return {ok:false,error:G("unsupported-capability","this host cannot save","save")};let v=e.save();return v?{ok:true,bytes:v}:{ok:false,error:G("document-unavailable","this host holds no document right now")}},subscribe(v){return u||!s.events?()=>{}:(i.add(v),()=>{i.delete(v);})},dispose(){u||(u=true,i.clear(),g(),e.dispose(),c=null);}}}export{Bt as a,fr as b,lo as c,uo as d,Zt as e,qt as f,ns as g};