@docx-editor.dev/editor-api 2.15.1 → 2.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import {createServerAutomationHost}from'@docx-editor.dev/core/automation';var wt=Object.freeze({PropertyNotLoaded:"the property has not been loaded. Call load(...) and await context.sync() before reading it.",ValueNotLoaded:"the result has not been filled in yet. Await context.sync() before reading it.",InvalidObjectPath:"the object cannot be addressed. An object an item accessor answered is usable after the next await context.sync(); an object whose run has ended is released for good, unless context.trackedObjects.add(...) kept it.",ObjectInUse:"the object still belongs to a run that has not finished. Await that run before passing the object to another one.",InvalidArgument:"the argument is not one this API accepts.",ItemNotFound:"the collection has no such item.",NotSupported:"this document host does not support that operation.",NotImplemented:"this version does not implement that yet.",ConflictingChanges:"two changes in this batch affect the same paragraph. Split them across two context.sync() calls.",InvalidRequestContext:"the request context has finished. Start another run to continue.",RuntimeDisposed:"the runtime has been disposed.",StaleDocument:"the document changed after this context read it, so nothing was applied.",DocumentUnavailable:"the document is not available right now.",GeneralException:"the document could not complete the request."}),u=class extends Error{code;target;expectedRevision;actualRevision;constructor(t){let e=t.target?`${wt[t.code]} (${t.target})`:wt[t.code];super(e),this.name="DocxEditorError",this.code=t.code,t.target!==void 0&&(this.target=t.target),t.expectedRevision!==void 0&&(this.expectedRevision=t.expectedRevision),t.actualRevision!==void 0&&(this.actualRevision=t.actualRevision);}};function oe(n){return n instanceof u?true:typeof n=="object"&&n!==null&&n.name==="DocxEditorError"&&typeof n.code=="string"}function a(n){throw new u(n)}var B=Symbol("docx-editor.runtime.internals"),mt=Symbol("docx-editor.runtime.release"),gt=Symbol("docx-editor.runtime.rebind");function H(n){return n[B]}var ne=new Set(["select","expand","top","skip"]),re=/^[A-Za-z][A-Za-z0-9]*$/;function Tt(n,t){if(n===void 0)return [];let e=typeof n=="string"?n.split(",").map(r=>r.trim()):Array.isArray(n)?n.map(r=>typeof r=="string"?r.trim():r):a({code:"InvalidArgument",target:t}),o=[];for(let r of e)(typeof r!="string"||!re.test(r))&&a({code:"InvalidArgument",target:t}),o.includes(r)||o.push(r);return o.length===0&&a({code:"InvalidArgument",target:t}),o}function Et(n,t){return (typeof n!="number"||!Number.isInteger(n)||n<0)&&a({code:"InvalidArgument",target:t}),n}function ie(n,t){n===void 0||Array.isArray(n)&&n.length===0||a({code:"InvalidArgument",target:t});}function qt(n,t){if(n===void 0)return {select:[]};if(typeof n=="string"||Array.isArray(n))return {select:Tt(n,t)};(typeof n!="object"||n===null)&&a({code:"InvalidArgument",target:t});let e=n;for(let o of Object.keys(e))ne.has(o)||a({code:"InvalidArgument",target:`${t}.${o}`});return ie(e.expand,`${t}.expand`),{select:Tt(e.select,`${t}.select`),...e.top===void 0?{}:{top:Et(e.top,`${t}.top`)},...e.skip===void 0?{}:{skip:Et(e.skip,`${t}.skip`)}}}var T=class{#t;#e;#o;#n;#r=new Map;constructor(t,e,o={}){this.#t=t,this.#e=t[B],this.#o=e,this.#n=o.nullable===true,this.#e.register(this);}get context(){return this.#t}get isNullObject(){return this.#o.isReleased&&a({code:"InvalidObjectPath",target:this.#o.label}),this.#n?(this.#o.isPending&&a({code:"PropertyNotLoaded",target:`${this.#o.label}.isNullObject`}),this.#o.isNull):false}load(t){return this.requireAddressable(),this.onLoad(qt(t,this.#o.label)),this}get path(){return this.#o}get internals(){return this.#e}handle(){return this.#o.handle()}requireAddressable(){this.#o.isAddressable||a({code:"InvalidObjectPath",target:this.#o.label}),this.#e.assertUsable(this.#o.label);}enqueue(t){this.requireAddressable(),this.#e.queue.push(t);}loadedProperty(t){return this.#o.isReleased&&!this.#r.has(t)&&a({code:"InvalidObjectPath",target:this.#o.label}),this.#r.has(t)||a({code:"PropertyNotLoaded",target:`${this.#o.label}.${t}`}),this.#r.get(t)}hasLoadedProperty(t){return this.#r.has(t)}setLoadedProperty(t,e){this.#r.set(t,e);}[mt](){this.#o.release();}[gt](t){this.#t=t,this.#e=t[B];}};var Rt=class n{#t=false;#e;#o;constructor(t){this.#o=t;}get value(){return this.#t||a({code:"ValueNotLoaded",target:this.#o}),this.#e}get isLoaded(){return this.#t}static create(t){let e=new n(t);return {result:e,fill(o){e.#t=true,e.#e=o;}}}};function R(n){return new u({code:"GeneralException",target:n})}function y(n,t){if(n.kind!=="text")throw R(t);return n.text}function f(n,t){if(n.kind!=="handle")throw R(t);return n.handle}function P(n,t){if(n.kind!=="handles")throw R(t);return n.handles}function x(n,t){if(n.kind!=="span")throw R(t);return n.span}function ft(n,t){if(n.kind!=="spans")throw R(t);return n.spans}function Pt(n,t){if(n.kind!=="font")throw R(t);return n.font}function St(n,t){if(n.kind!=="paragraphFormat")throw R(t);return n.format}function at(n,t){if(n.kind!=="style")throw R(t);return n.name}function bt(n,t){if(n.kind!=="number")throw R(t);return n.value}function M(n,t){if(n.kind!=="flag")throw R(t);return n.value}function kt(n,t){if(n.kind!=="pageSetup")throw R(t);return n.setup}function C(n,t){if(n.kind!=="applied")throw R(t)}var l=class n{label;#t;#e;constructor(t,e,o=null){this.label=t,this.#t=e,this.#e=o;}static of(t,e){return new n(t,{status:"resolved",address:{kind:"handle",handle:e}})}static ofSpan(t,e){return new n(t,{status:"resolved",address:{kind:"span",span:e}})}static pending(t){return new n(t,{status:"pending"})}static derived(t,e){return new n(t,{status:"pending"},e)}get state(){return this.#e?this.#e.state:this.#t}get isAddressable(){return this.state.status==="resolved"}get isPending(){return this.state.status==="pending"}get isNull(){return this.state.status==="null"}get isReleased(){return this.state.status==="released"}address(){let t=this.state;if(t.status==="resolved")return t.address;a({code:"InvalidObjectPath",target:this.label});}handle(){let t=this.address();return t.kind!=="handle"&&a({code:"InvalidObjectPath",target:this.label}),t.handle}span(){let t=this.address();return t.kind!=="span"&&a({code:"InvalidObjectPath",target:this.label}),t.span}resolveTo(t){this.#o({kind:"handle",handle:t});}resolveToSpan(t){this.#o({kind:"span",span:t});}resolveNull(){this.#t.status!=="released"&&(this.#t={status:"null"});}release(){this.#e||(this.#t={status:"released"});}#o(t){this.#t.status!=="released"&&(this.#t={status:"resolved",address:t});}};function Nt(n){let t=[],e=false,o=false;for(let r of n)t.push(r.plan()),r.sort==="write"?o=true:e=true;return {operations:t,hasRead:e,hasWrite:o}}var ae=Object.freeze({"stale-revision":"StaleDocument","invalid-handle":"InvalidObjectPath","invalid-offset":"InvalidArgument","unsupported-capability":"NotSupported",disposed:"RuntimeDisposed","transaction-refused":"GeneralException","unknown-operation":"NotSupported","unsupported-content":"InvalidArgument","unsupported-revision":"NotImplemented","ambiguous-document":"GeneralException","conflicting-operations":"ConflictingChanges","document-unavailable":"DocumentUnavailable"});function yt(n,t={}){let e=ae[n.code]??"GeneralException",o=e==="StaleDocument";return new u({code:e,...t.target===void 0?{}:{target:t.target},...o&&t.expectedRevision!==void 0?{expectedRevision:t.expectedRevision}:{},...o&&t.actualRevision!==void 0?{actualRevision:t.actualRevision}:{}})}function $t(n,t,e){for(let o=0;o<n.results.length;o+=1){let r=n.results[o];if(r?.status!=="error")continue;let i=t[o]?.label;return yt(r.error,{...i===void 0?{}:{target:i},...e===void 0?{}:{expectedRevision:e},actualRevision:n.revision})}return new u({code:"GeneralException"})}function Dt(n,t){if(t.results.length!==n.length)throw new u({code:"GeneralException"});for(let e=0;e<n.length;e+=1){let o=t.results[e],r=n[e];if(o.status!=="ok")throw new u({code:"GeneralException",target:r.label});r.settle(o.value);}}var xt=class{#t=[];get size(){return this.#t.length}get pending(){return this.#t}push(t){this.#t.push(t);}take(){let t=this.#t;return this.#t=[],t}clear(){this.#t=[];}};function Ft(n,t){if(Array.isArray(n)){for(let e of n)t(e);return}t(n);}var st=class{#t;#e;constructor(t,e){this.#t=t,this.#e=e;}add(t){this.#t.assertUsable(),Ft(t,e=>{this.#o(e),this.#t.track(e);});}remove(t){this.#t.assertUsable(),Ft(t,e=>{this.#o(e),this.#t.untrack(e);});}#o(t){this.#e(t)||a({code:"InvalidObjectPath"});}};var dt=class n{#t;#e=new xt;#o=new Set;#n=new Set;#r;#s;#i;#a=false;#d=null;constructor(t){this.#t=t,this.#r={host:t.host,capabilities:t.capabilities,...t.author===void 0?{}:{author:t.author},revisionTextView:t.revisionTextView,queue:this.#e,session:t.id,roots:()=>t.roots(),assertUsable:e=>{this.#t.assertLive(e),this.#a&&a({code:"InvalidRequestContext",...e===void 0?{}:{target:e}});},isFinished:()=>this.#a,readRevision:()=>this.#d,register:e=>{this.#o.add(e);},track:e=>{this.#n.add(e);},untrack:e=>{this.#n.delete(e);},isTracked:e=>this.#n.has(e),disown:e=>{this.#o.delete(e),this.#n.delete(e);}},this.#s=new st(this.#r,e=>this.#o.has(e));}get document(){return this.#r.assertUsable("document"),this.#i??=this.#t.openDocument(this),this.#i}get capabilities(){return this.#t.capabilities}get trackedObjects(){return this.#s}async sync(){this.#r.assertUsable();let t=this.#e.take();if(t.length===0)return;let e=Nt(t),r=e.hasWrite&&this.#d!==null?this.#d:void 0,i={operations:e.operations,...r===void 0?{}:{expectedRevision:r}},s=this.#t.host.execute(i);if(!s.ok)throw $t(s,t,r);Dt(t,s),(e.hasRead||e.hasWrite)&&(this.#d=s.revision);}get[B](){return this.#r}static begin(t){let e=new n(t);return {context:e,adopt(o){for(let r of o)e.#l(r);},finish(){e.#p();}}}#l(t){let e=t.context;if(e===this)return;let o=e[B];if(o.session!==this.#t.id)throw new u({code:"InvalidObjectPath"});if(!o.isFinished())throw new u({code:"ObjectInUse"});if(!o.isTracked(t))throw new u({code:"InvalidObjectPath"});let r=o.readRevision();o.disown(t),t[gt](this),this.#o.add(t),this.#n.add(t),r!==null&&this.#c(r);}#c(t){this.#d=this.#d===null?t:Math.min(this.#d,t);}#p(){if(!this.#a){this.#a=true,this.#e.clear();for(let t of this.#o)this.#n.has(t)||t[mt]();this.#o.clear();}}};function lt(n,t,e){if(n.select.length===0)return t;for(let o of n.select)t.includes(o)||a({code:"InvalidArgument",target:`${e}.${o}`});return n.select}var Q=class extends T{#t;#e=[];constructor(t,e){super(t,e);}get items(){return this.loadedProperty("items")}fill(t,e){this.setLoadedProperty("items",this.#n(t,e,0,void 0)),this.#t={value:t,label:e};let o=this.#e.splice(0,this.#e.length);for(let r of o)this.#o(r,t);}onLoad(t){lt(t,["items"],this.path.label);let e=this.listing();if(!e)return;let o=`${this.path.label}.items`,r=t.skip??0,i=t.top;this.enqueue({sort:"read",label:o,plan:()=>e,settle:s=>{this.setLoadedProperty("items",this.#n(s,o,r,i));}});}edge(t,e,o){let r=`${this.path.label}.${e}()`,i=this.promised(r,o),s=this.listing();if(!s){let d={edge:t,target:r,nullable:o,item:i};return this.#t?this.#o(d,this.#t.value):this.#e.push(d),i}return this.enqueue({sort:"read",label:r,plan:()=>s,settle:d=>{this.#o({edge:t,target:r,nullable:o,item:i},d);}}),i}#o(t,e){let{edge:o,target:r,nullable:i,item:s}=t,d=this.size(e,r);if(d===0){i||a({code:"ItemNotFound",target:r}),s.hydrateNull();return}let c=this.addressAt(e,r,o==="first"?0:d-1);c||a({code:"ItemNotFound",target:r}),s.hydrateAddress(c);}#n(t,e,o,r){let i=this.size(t,e),s=r===void 0?i:Math.min(i,o+r),d=[];for(let c=o;c<s;c+=1){let g=this.addressAt(t,e,c);g&&d.push(this.itemAt(`${e}[${String(c)}]`,g));}return d}},b=class extends Q{size(t,e){return P(t,e).length}addressAt(t,e,o){let r=P(t,e)[o];return r?{kind:"handle",handle:r}:void 0}};var se=["Replace","Start","End"],de=["Start","End"],le=["Replace","Start","End"],ce=["Before","After"],pe=["Replace","Start","End","Before","After"],he=["Select","Start","End"];function X(n,t,e){return (typeof n!="string"||!t.includes(n))&&a({code:"InvalidArgument",target:e}),n}var Bt=(n,t)=>X(n,se,t),Ht=(n,t)=>X(n,de,t),Mt=(n,t)=>X(n,le,t),Vt=(n,t)=>X(n,ce,t),It=(n,t)=>X(n,pe,t),Ct=(n,t)=>n===void 0?"Select":X(n,he,t);function A(n,t){return typeof n!="string"&&a({code:"InvalidArgument",target:t}),/[\r\n\v\f\u2028\u2029]/.test(n)&&a({code:"InvalidArgument",target:t}),n}var p=class extends T{revisionTextView(){return H(this.context).revisionTextView}loadTextInto(t,e){let o=`${this.path.label}.${t}`;this.enqueue({sort:"read",label:o,plan:e,settle:r=>{this.setLoadedProperty(t,y(r,o));}});}command(t,e){let o=`${this.path.label}.${t}`;this.enqueue({sort:"write",label:o,plan:e,settle:r=>C(r,o)});}commandDiscarding(t,e){let o=`${this.path.label}.${t}`;this.enqueue({sort:"write",label:o,plan:e,settle:()=>{}});}commandAnswering(t,e,o){this.enqueue({sort:"write",label:t,plan:e,settle:o});}read(t,e,o){this.enqueue({sort:"read",label:t,plan:e,settle:o});}selection(t,e){return lt(t,e,this.path.label)}onLoad(t){this.selection(t,[]);}};var ue=8,L=class n extends p{#t;static at(t,e,o){return o.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new n(t,l.of(e,o.handle),false)}static promised(t,e,o){return new n(t,l.pending(e),o)}constructor(t,e,o){super(t,e,{nullable:o});}hydrateAddress(t){t.kind==="handle"?this.path.resolveTo(t.handle):this.path.resolveNull();}hydrateNull(){this.path.resolveNull();}get id(){return this.loadedProperty("id")}get paragraphs(){return this.#t??=v.overListing(this.context,`${this.path.label}.paragraphs`,this.path,()=>({op:"getListParagraphs",list:this.#e()})),this.#t}getLevelParagraphs(t){let e=`${this.path.label}.getLevelParagraphs`,o=Wt(t,e),r=this.#e();return v.overListing(this.context,e,this.path,()=>({op:"getListParagraphs",list:r,level:o}))}insertParagraph(t,e){let o=`${this.path.label}.insertParagraph`,r=A(t,o);e!=="Start"&&e!=="End"&&e!=="Before"&&e!=="After"&&a({code:"InvalidArgument",target:o});let i=this.#e(),s=O.promised(this.context,o,false);return this.commandAnswering(o,()=>({op:"insertListParagraph",list:i,where:e==="Start"||e==="Before"?"start":"end",text:r}),d=>{s.hydrateAddress({kind:"handle",handle:f(d,o)});}),s}onLoad(t){if(!this.selection(t,["id"]).includes("id"))return;let e=`${this.path.label}.id`,o=this.#e();this.read(e,()=>({op:"getListId",list:o}),r=>{this.setLoadedProperty("id",bt(r,e));});}#e(){return this.requireAddressable(),this.path.handle()}},K=class n extends b{#t;static of(t,e,o,r){return new n(t,l.derived(e,o),r)}constructor(t,e,o){super(t,e),this.#t=o;}getFirst(){return this.edge("first","getFirst",false)}getById(t){let e=`${this.path.label}.getById`,o=me(t,e),r=this.#t,i=L.promised(this.context,e,false);return this.enqueue({sort:"read",label:e,plan:()=>({op:"getListById",body:r,id:o}),settle:s=>{i.hydrateAddress({kind:"handle",handle:f(s,e)});}}),i}listing(){return {op:"getLists",body:this.#t}}itemAt(t,e){return L.at(this.context,t,e)}promised(t,e){return L.promised(this.context,t,e)}},Z=class n extends p{static of(t,e,o){return new n(t,l.derived(e,o))}constructor(t,e){super(t,e);}get level(){return this.loadedProperty("level")}set level(t){let e=`${this.path.label}.level`,o=Wt(t,e),r=this.#t();this.commandAnswering(e,()=>({op:"setListLevel",paragraph:r,level:o}),i=>{C(i,e);});}onLoad(t){if(!this.selection(t,["level"]).includes("level"))return;let e=`${this.path.label}.level`,o=this.#t();this.read(e,()=>({op:"getListLevel",paragraph:o}),r=>{this.setLoadedProperty("level",bt(r,e));});}#t(){this.requireAddressable();let t=this.path.address();return t.kind!=="handle"&&a({code:"InvalidObjectPath",target:this.path.label}),t.handle}};function Wt(n,t){return (!Number.isInteger(n)||n<0||n>ue)&&a({code:"InvalidArgument",target:t}),n}function me(n,t){return (!Number.isInteger(n)||n<=0)&&a({code:"InvalidArgument",target:t}),n}function E(n,t){let e=n.address();return t==="span"?(e.kind!=="span"&&a({code:"InvalidObjectPath",target:n.label}),{start:e.span.start,end:e.span.end}):(e.kind!=="handle"&&a({code:"InvalidObjectPath",target:n.label}),t==="body"?{body:e.handle}:{paragraph:e.handle})}function Y(n,t){return (typeof n!="string"||n.trim().length===0||n.length>255)&&a({code:"InvalidArgument",target:t}),n}var ge=["bold","italic","color","name","size"],k=class n extends p{#t;#e;static of(t,e,o,r){return new n(t,l.derived(e,o),r)}constructor(t,e,o){super(t,e),this.#t=o;}get bold(){return this.loadedProperty("bold")}set bold(t){this.#o("bold",Ut(t,`${this.path.label}.bold`));}get italic(){return this.loadedProperty("italic")}set italic(t){this.#o("italic",Ut(t,`${this.path.label}.italic`));}get color(){return this.loadedProperty("color")}set color(t){this.#o("color",zt(t,`${this.path.label}.color`));}get name(){return this.loadedProperty("name")}set name(t){this.#o("name",zt(t,`${this.path.label}.name`));}get size(){return this.loadedProperty("size")}set size(t){this.#o("size",fe(t,`${this.path.label}.size`));}onLoad(t){let e=this.selection(t,ge);if(e.length===0)return;let o=`${this.path.label}.font`;this.read(o,()=>({op:"getFont",span:this.#n()}),r=>{let i=Pt(r,o);for(let s of e)this.setLoadedProperty(s,i[s]);});}#o(t,e){if(this.requireAddressable(),this.#e){this.#e[t]=e;return}let o={[t]:e};this.#e=o;let r=`${this.path.label}.${t}`;this.commandAnswering(this.path.label,()=>(this.#e=void 0,{op:"setFont",span:this.#n(),font:o}),i=>{C(i,r);});}#n(){return this.requireAddressable(),E(this.path,this.#t)}};function Ut(n,t){return typeof n!="boolean"&&a({code:"InvalidArgument",target:t}),n}function fe(n,t){return (typeof n!="number"||!Number.isFinite(n))&&a({code:"InvalidArgument",target:t}),n}function zt(n,t){return (typeof n!="string"||n.length===0)&&a({code:"InvalidArgument",target:t}),n}var be=16,O=class n extends p{#t;#e;#o;#n;static at(t,e,o){return o.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new n(t,l.of(e,o.handle),false)}static promised(t,e,o){return new n(t,l.pending(e),o)}constructor(t,e,o){super(t,e,{nullable:o});}hydrateAddress(t){t.kind==="handle"?this.path.resolveTo(t.handle):this.path.resolveNull();}hydrateNull(){this.path.resolveNull();}get text(){return this.loadedProperty("text")}get uniqueLocalId(){return this.loadedProperty("uniqueLocalId")}get style(){return this.loadedProperty("style")}set style(t){this.#r("style",Y(t,`${this.path.label}.style`));}get font(){return this.#t??=k.of(this.context,`${this.path.label}.font`,this.path,"paragraph"),this.#t}get alignment(){return this.loadedProperty("alignment")}set alignment(t){this.#r("alignment",xe(t,`${this.path.label}.alignment`));}get firstLineIndent(){return this.loadedProperty("firstLineIndent")}set firstLineIndent(t){this.#r("firstLineIndent",J(t,`${this.path.label}.firstLineIndent`));}get leftIndent(){return this.loadedProperty("leftIndent")}set leftIndent(t){this.#r("leftIndent",J(t,`${this.path.label}.leftIndent`));}get rightIndent(){return this.loadedProperty("rightIndent")}set rightIndent(t){this.#r("rightIndent",J(t,`${this.path.label}.rightIndent`));}get lineSpacing(){return this.loadedProperty("lineSpacing")}set lineSpacing(t){this.#r("lineSpacing",J(t,`${this.path.label}.lineSpacing`));}get spaceBefore(){return this.loadedProperty("spaceBefore")}set spaceBefore(t){this.#r("spaceBefore",J(t,`${this.path.label}.spaceBefore`));}get spaceAfter(){return this.loadedProperty("spaceAfter")}set spaceAfter(t){this.#r("spaceAfter",J(t,`${this.path.label}.spaceAfter`));}get list(){return this.#e??=this.#s(`${this.path.label}.list`),this.#e}get listItem(){return this.#o??=Z.of(this.context,`${this.path.label}.listItem`,this.path),this.#o}clear(){let t=this.#i();this.commandDiscarding("clear",()=>({op:"replaceSpan",span:{paragraph:t},text:""}));}delete(){let t=this.#i();this.command("delete",()=>({op:"deleteParagraph",paragraph:t}));}insertText(t,e){let o=`${this.path.label}.insertText`,r=A(t,o),i=Mt(e,o),s=this.#i(),d=m.promised(this.context,o,false);return this.commandAnswering(o,()=>i==="Replace"?{op:"replaceSpan",span:{paragraph:s},text:r}:{op:"insertText",at:{paragraph:s,at:i==="Start"?"start":"end"},text:r},c=>{d.hydrateAddress({kind:"span",span:x(c,o)});}),d}insertParagraph(t,e){let o=`${this.path.label}.insertParagraph`,r=A(t,o),i=Vt(e,o),s=this.#i(),d=n.promised(this.context,o,false);return this.commandAnswering(o,()=>({op:"insertParagraph",anchor:{paragraph:s},where:i==="Before"?"before":"after",text:r}),c=>{c.kind!=="handle"&&a({code:"GeneralException",target:o}),d.hydrateAddress({kind:"handle",handle:c.handle});}),d}split(t,e,o){let r=`${this.path.label}.split`,i=Ce(t,r),s=Qt(e,`${r}.trimDelimiters`),d=Qt(o,`${r}.trimSpacing`),c=this.#i(),g=I.answered(this.context,r,this.path);return this.commandAnswering(r,()=>({op:"splitParagraph",paragraph:c,delimiters:i,...s?{trimDelimiters:true}:{},...d?{trimSpacing:true}:{}}),j=>{g.fill(j,r);}),g}onLoad(t){let e=this.selection(t,["text","uniqueLocalId",...Gt]),o=this.#i();e.includes("text")&&this.loadTextInto("text",()=>({op:"getText",target:o,projection:this.revisionTextView()})),e.includes("uniqueLocalId")&&this.loadTextInto("uniqueLocalId",()=>({op:"getParagraphId",paragraph:o}));let r=Gt.filter(s=>e.includes(s));if(r.length===0)return;let i=`${this.path.label}.paragraphFormat`;this.read(i,()=>({op:"getParagraphFormat",paragraph:{paragraph:o}}),s=>{let d=St(s,i);for(let c of r)this.setLoadedProperty(c,d[c]);});}#r(t,e){if(this.requireAddressable(),this.#n){this.#n[t]=e;return}let o={[t]:e};this.#n=o;let r=this.#i(),i=`${this.path.label}.${t}`;this.commandAnswering(`${this.path.label}.paragraphFormat`,()=>(this.#n=void 0,{op:"setParagraphFormat",paragraph:{paragraph:r},format:o}),s=>{C(s,i);});}#s(t){let e=this.#i(),o=L.promised(this.context,t,false);return this.read(t,()=>({op:"getParagraphList",paragraph:e}),r=>{o.hydrateAddress({kind:"handle",handle:f(r,t)});}),o}#i(){return this.requireAddressable(),this.path.handle()}},Gt=["style","alignment","firstLineIndent","leftIndent","rightIndent","lineSpacing","spaceBefore","spaceAfter"],ye=["Left","Centered","Right","Justified"];function xe(n,t){return ye.includes(n)||a({code:"InvalidArgument",target:t}),n}function J(n,t){return (typeof n!="number"||!Number.isFinite(n))&&a({code:"InvalidArgument",target:t}),n}function Ce(n,t){(!Array.isArray(n)||n.length===0||n.length>be)&&a({code:"InvalidArgument",target:t});for(let e of n)(typeof e!="string"||e.length===0)&&a({code:"InvalidArgument",target:t});return [...n]}function Qt(n,t){return n!==void 0&&typeof n!="boolean"&&a({code:"InvalidArgument",target:t}),n===true}var v=class n extends Q{#t;static of(t,e,o){return new n(t,l.derived(e,o),null)}static overListing(t,e,o,r){return new n(t,l.derived(e,o),r)}constructor(t,e,o){super(t,e),this.#t=o;}getFirst(){return this.edge("first","getFirst",false)}getLast(){return this.edge("last","getLast",false)}getFirstOrNullObject(){return this.edge("first","getFirstOrNullObject",true)}getLastOrNullObject(){return this.edge("last","getLastOrNullObject",true)}listing(){if(this.#t)return this.#t();let t=this.path.address();return t.kind==="handle"?{op:"getParagraphs",body:t.handle}:{op:"getSpanParagraphs",span:t.span}}size(t,e){return P(t,e).length}addressAt(t,e,o){let r=P(t,e)[o];return r?{kind:"handle",handle:r}:void 0}itemAt(t,e){return O.at(this.context,t,e)}promised(t,e){return O.promised(this.context,t,e)}},I=class n extends Q{#t;static of(t,e,o,r){return new n(t,l.derived(e,o),r)}static answered(t,e,o){return new n(t,l.derived(e,o),null)}constructor(t,e,o){super(t,e),this.#t=o;}getFirst(){return this.edge("first","getFirst",false)}getLast(){return this.edge("last","getLast",false)}getFirstOrNullObject(){return this.edge("first","getFirstOrNullObject",true)}listing(){return this.#t?this.#t():null}size(t,e){return ft(t,e).length}addressAt(t,e,o){let r=ft(t,e)[o];return r?{kind:"span",span:r}:void 0}itemAt(t,e){return m.at(this.context,t,e)}promised(t,e){return m.promised(this.context,t,e)}};function Ae(n,t){return t<1||t>12?0:t===2?n%4===0&&n%100!==0||n%400===0?29:28:t===4||t===6||t===9||t===11?30:31}function Xt(n){if(n.length===0)return null;let t=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,9}))?(Z|[+-]\d{2}:\d{2})$/.exec(n.trim());if(!t)return null;let e=Number(t[1]),o=Number(t[2]),r=Number(t[3]),i=Ae(e,o);if(e===0||i===0||r<1||r>i)return null;let s=Number(t[4]),d=Number(t[5]),c=Number(t[6]);if(s>23||d>59||c>59)return null;let g=t[7],j=g===void 0?0:Number(g.padEnd(3,"0").slice(0,3));if(Number.isNaN(j))return null;let z=`${t[1]}-${t[2]}-${t[3]}T${t[4]}:${t[5]}:${t[6]}.${String(j).padStart(3,"0")}Z`,ht=Date.parse(z);if(Number.isNaN(ht))return null;let h=t[8];if(h==="Z")return new Date(ht);let F=Number(h.slice(1,3)),G=Number(h.slice(4,6));if(G>59||F>14||F===14&&G!==0)return null;let Ot=h[0]==="+"?1:-1,ut=new Date(ht-Ot*(F*36e5+G*6e4));return Number.isNaN(ut.getTime())?null:ut}var At=class extends p{hydrateAddress(t){t.kind==="handle"?this.path.resolveTo(t.handle):this.path.resolveNull();}hydrateNull(){this.path.resolveNull();}get authorName(){return this.loadedProperty("authorName")}get creationDate(){return this.loadedProperty("creationDate")}get id(){return this.loadedProperty("id")}get text(){return this.loadedProperty("text")}delete(){let t=this.commentHandle();this.command("delete",()=>({op:"deleteComment",comment:t}));}loadCommentFields(t,e){let o=this.selection(t,["authorName","creationDate","id","text",...e]),r=this.commentHandle();if(o.includes("authorName")&&this.loadTextInto("authorName",()=>({op:"getCommentAuthor",comment:r})),o.includes("text")&&this.loadTextInto("text",()=>({op:"getCommentText",comment:r})),o.includes("id")&&this.loadTextInto("id",()=>({op:"getCommentId",comment:r})),o.includes("creationDate")){let s=`${this.path.label}.creationDate`;this.read(s,()=>({op:"getCommentDate",comment:r}),d=>{this.setLoadedProperty("creationDate",Xt(y(d,s)));});}if(!o.includes("resolved"))return;let i=`${this.path.label}.resolved`;this.read(i,()=>({op:"getCommentResolved",comment:r}),s=>{this.setLoadedProperty("resolved",M(s,i));});}commentHandle(){return this.requireAddressable(),this.path.handle()}},V=class n extends At{static at(t,e,o){return o.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new n(t,l.of(e,o.handle),false)}static promised(t,e,o){return new n(t,l.pending(e),o)}constructor(t,e,o){super(t,e,{nullable:o});}onLoad(t){this.loadCommentFields(t,[]);}},ct=class n extends b{#t;static of(t,e,o,r){return new n(t,l.derived(e,o),r)}constructor(t,e,o){super(t,e),this.#t=o;}getFirst(){return this.edge("first","getFirst",false)}listing(){return this.#t()}itemAt(t,e){return V.at(this.context,t,e)}promised(t,e){return V.promised(this.context,t,e)}},q=class n extends At{#t;static at(t,e,o){return o.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new n(t,l.of(e,o.handle),false)}static promised(t,e,o){return new n(t,l.pending(e),o)}constructor(t,e,o){super(t,e,{nullable:o});}get resolved(){return this.loadedProperty("resolved")}set resolved(t){let e=`${this.path.label}.resolved`;typeof t!="boolean"&&a({code:"InvalidArgument",target:e});let o=this.commentHandle();this.commandAnswering(e,()=>({op:"setCommentResolved",comment:o,resolved:t}),r=>{C(r,e);});}get replies(){return this.#t??=ct.of(this.context,`${this.path.label}.replies`,this.path,()=>({op:"getCommentReplies",comment:this.commentHandle()})),this.#t}getRange(){let t=`${this.path.label}.getRange`,e=this.commentHandle(),o=m.promised(this.context,t,false);return this.read(t,()=>({op:"getCommentRange",comment:e}),r=>{o.hydrateAddress({kind:"span",span:x(r,t)});}),o}reply(t){let e=`${this.path.label}.reply`;(typeof t!="string"||t.length===0)&&a({code:"InvalidArgument",target:e});let o=this.internals.author;(typeof o!="string"||o.trim().length===0)&&a({code:"NotSupported",target:e});let r=this.commentHandle(),i=V.promised(this.context,e,false);return this.commandAnswering(e,()=>({op:"replyToComment",comment:r,text:t,author:o}),s=>{i.hydrateAddress({kind:"handle",handle:f(s,e)});}),i}onLoad(t){this.loadCommentFields(t,["resolved"]);}},N=class n extends b{#t;static of(t,e,o,r){return new n(t,l.derived(e,o),r)}constructor(t,e,o){super(t,e),this.#t=o;}getFirst(){return this.edge("first","getFirst",false)}listing(){return this.#t()}itemAt(t,e){return q.at(this.context,t,e)}promised(t,e){return q.promised(this.context,t,e)}},_=class n extends p{static at(t,e,o){return o.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new n(t,l.of(e,o.handle),false)}static promised(t,e,o){return new n(t,l.pending(e),o)}constructor(t,e,o){super(t,e,{nullable:o});}hydrateAddress(t){t.kind==="handle"?this.path.resolveTo(t.handle):this.path.resolveNull();}hydrateNull(){this.path.resolveNull();}get author(){return this.loadedProperty("author")}get date(){return this.loadedProperty("date")}get type(){return this.loadedProperty("type")}get range(){let t=`${this.path.label}.range`,e=this.#t(),o=m.promised(this.context,t,false);return this.read(t,()=>({op:"getRevisionRange",revision:e}),r=>{o.hydrateAddress({kind:"span",span:x(r,t)});}),o}accept(){let t=this.#t();this.command("accept",()=>({op:"acceptRevision",revision:t}));}reject(){let t=this.#t();this.command("reject",()=>({op:"rejectRevision",revision:t}));}onLoad(t){let e=this.selection(t,["author","date","type"]),o=this.#t();if(e.includes("author")&&this.loadTextInto("author",()=>({op:"getRevisionAuthor",revision:o})),e.includes("type")&&this.loadTextInto("type",()=>({op:"getRevisionType",revision:o})),!e.includes("date"))return;let r=`${this.path.label}.date`;this.read(r,()=>({op:"getRevisionDate",revision:o}),i=>{this.setLoadedProperty("date",Xt(y(i,r)));});}#t(){return this.requireAddressable(),this.path.handle()}},$=class n extends b{#t;static of(t,e,o,r){return new n(t,l.derived(e,o),r)}constructor(t,e,o){super(t,e),this.#t=o;}acceptAll(){let t=this.#t;this.commandOn("acceptAll",()=>({op:"acceptAllRevisions",body:t}));}rejectAll(){let t=this.#t;this.commandOn("rejectAll",()=>({op:"rejectAllRevisions",body:t}));}listing(){return {op:"getRevisions",body:this.#t}}itemAt(t,e){return _.at(this.context,t,e)}promised(t,e){return _.promised(this.context,t,e)}commandOn(t,e){let o=`${this.path.label}.${t}`;this.enqueue({sort:"write",label:o,plan:e,settle:r=>{C(r,o);}});}};var ve=new Set(["matchCase","matchWholeWord","ignorePunct","ignoreSpace","matchWildcards"]);function vt(n,t){if(n===void 0)return;typeof n!="object"&&a({code:"InvalidArgument",target:t});for(let[o,r]of Object.entries(n))ve.has(o)||a({code:"InvalidArgument",target:`${t}.${o}`}),r!==void 0&&typeof r!="boolean"&&a({code:"InvalidArgument",target:`${t}.${o}`});let e={...n.matchCase===void 0?{}:{matchCase:n.matchCase},...n.matchWholeWord===void 0?{}:{matchWholeWord:n.matchWholeWord},...n.ignorePunct===void 0?{}:{ignorePunct:n.ignorePunct},...n.ignoreSpace===void 0?{}:{ignoreSpace:n.ignoreSpace},...n.matchWildcards===void 0?{}:{matchWildcards:n.matchWildcards}};return Object.keys(e).length===0?void 0:e}var m=class n extends p{#t;#e;#o;static at(t,e,o){return o.kind!=="span"&&a({code:"InvalidObjectPath",target:e}),new n(t,l.ofSpan(e,o.span),false)}static promised(t,e,o){return new n(t,l.pending(e),o)}constructor(t,e,o){super(t,e,{nullable:o});}hydrateAddress(t){t.kind==="span"?this.path.resolveToSpan(t.span):this.path.resolveNull();}hydrateNull(){this.path.resolveNull();}get text(){return this.loadedProperty("text")}get font(){return this.#e??=k.of(this.context,`${this.path.label}.font`,this.path,"span"),this.#e}get paragraphs(){return this.#t??=v.of(this.context,`${this.path.label}.paragraphs`,this.path),this.#t}get style(){return this.loadedProperty("style")}set style(t){let e=`${this.path.label}.style`,o=Y(t,e);this.requireAddressable(),this.command("style",()=>({op:"setStyle",span:E(this.path,"span"),name:o}));}get hyperlink(){return this.loadedProperty("hyperlink")}set hyperlink(t){let e=`${this.path.label}.hyperlink`;(typeof t!="string"||t.length>2048)&&a({code:"InvalidArgument",target:e});let o=this.#n();this.command("hyperlink",()=>({op:"setHyperlink",span:o,target:t}));}get bookmarks(){let t=this.#n();return this.#o??=D.of(this.context,`${this.path.label}.bookmarks`,this.path,()=>({op:"getBookmarks",scope:{start:t.start,end:t.end}})),this.#o}search(t,e){let o=`${this.path.label}.search`;typeof t!="string"&&a({code:"InvalidArgument",target:o});let r=vt(e,o),i=this.#n();return I.of(this.context,o,this.path,()=>({op:"search",scope:i,text:t,options:{...r??{},projection:this.revisionTextView()}}))}insertText(t,e){let o=`${this.path.label}.insertText`,r=A(t,o),i=It(e,o),s=this.#n(),d=n.promised(this.context,o,false);return this.commandAnswering(o,()=>i==="Replace"?{op:"replaceSpan",span:s,text:r}:{op:"insertText",at:i==="Start"||i==="Before"?s.start:s.end,text:r},c=>{d.hydrateAddress({kind:"span",span:x(c,o)});}),d}insertComment(t){let e=`${this.path.label}.insertComment`;(typeof t!="string"||t.length===0)&&a({code:"InvalidArgument",target:e});let o=this.internals.author;(typeof o!="string"||o.trim().length===0)&&a({code:"NotSupported",target:e});let r=this.#n(),i=q.promised(this.context,e,false);return this.commandAnswering(e,()=>({op:"insertComment",span:r,text:t,author:o}),s=>{s.kind!=="handle"&&a({code:"GeneralException",target:e}),i.hydrateAddress(s);}),i}insertParagraph(t,e){let o=`${this.path.label}.insertParagraph`,r=A(t,o),i=It(e,o);i!=="Before"&&i!=="After"&&a({code:"InvalidArgument",target:o});let s=this.#n(),d=i==="Before"?s.start.paragraph:s.end.paragraph,c=O.promised(this.context,o,false);return this.commandAnswering(o,()=>({op:"insertParagraph",anchor:{paragraph:d},where:i==="Before"?"before":"after",text:r}),g=>{g.kind!=="handle"&&a({code:"GeneralException",target:o}),c.hydrateAddress({kind:"handle",handle:g.handle});}),c}select(t){let e=`${this.path.label}.select`,o=Ct(t,e);this.requireAddressable(),this.internals.capabilities.selection||a({code:"NotSupported",target:e});let r=this.#n();this.command("select",()=>({op:"selectSpan",span:r,mode:o==="Select"?"select":o==="Start"?"start":"end"}));}onLoad(t){let e=this.selection(t,["text","style","hyperlink"]);if(e.includes("hyperlink")){let r=this.#n();this.loadTextInto("hyperlink",()=>({op:"getHyperlink",span:r}));}if(e.includes("text")){let r=this.#n(),i=`${this.path.label}.text`;this.read(i,()=>({op:"getSpanText",span:r,projection:this.revisionTextView()}),s=>{this.setLoadedProperty("text",y(s,i));});}if(!e.includes("style"))return;let o=`${this.path.label}.style`;this.requireAddressable(),this.read(o,()=>({op:"getStyle",span:E(this.path,"span")}),r=>{this.setLoadedProperty("style",at(r,o));});}#n(){return this.requireAddressable(),this.path.span()}};var tt=class n extends p{#t;static at(t,e,o){return o.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new n(t,l.of(e,o.handle),false)}static promised(t,e,o){return new n(t,l.pending(e),o)}constructor(t,e,o){super(t,e,{nullable:o});}hydrateAddress(t){t.kind==="handle"?this.path.resolveTo(t.handle):this.path.resolveNull();}hydrateNull(){this.path.resolveNull();}get name(){return this.loadedProperty("name")}get range(){return this.#t??=this.#e(`${this.path.label}.range`),this.#t}select(t){let e=`${this.path.label}.select`,o=Ct(t,e);this.requireAddressable(),this.internals.capabilities.selection||a({code:"NotSupported",target:e});let r=this.#o();this.command("select",()=>({op:"selectBookmark",bookmark:r,mode:o==="Select"?"select":o==="Start"?"start":"end"}));}onLoad(t){if(!this.selection(t,["name"]).includes("name"))return;let e=`${this.path.label}.name`,o=this.#o();this.read(e,()=>({op:"getBookmarkName",bookmark:o}),r=>{this.setLoadedProperty("name",y(r,e));});}#e(t){let e=this.#o(),o=m.promised(this.context,t,false);return this.read(t,()=>({op:"getBookmarkRange",bookmark:e}),r=>{o.hydrateAddress({kind:"span",span:x(r,t)});}),o}#o(){return this.requireAddressable(),this.path.handle()}},D=class n extends b{#t;static of(t,e,o,r){return new n(t,l.derived(e,o),r)}constructor(t,e,o){super(t,e),this.#t=o;}listing(){return this.#t()}itemAt(t,e){return tt.at(this.context,t,e)}promised(t,e){return tt.promised(this.context,t,e)}};var Zt=4096,W=class n extends p{#t=new Map;#e;#o;static at(t,e,o){return o.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new n(t,l.of(e,o.handle),false)}static promised(t,e,o){return new n(t,l.pending(e),o)}constructor(t,e,o){super(t,e,{nullable:o});}hydrateAddress(t){t.kind==="handle"?this.path.resolveTo(t.handle):this.path.resolveNull();}hydrateNull(){this.path.resolveNull();}get id(){return this.loadedProperty("id")}get tag(){return this.loadedProperty("tag")}set tag(t){this.#r("tag",{tag:jt(t,`${this.path.label}.tag`)});}get title(){return this.loadedProperty("title")}set title(t){this.#r("title",{title:jt(t,`${this.path.label}.title`)});}get subtype(){return this.loadedProperty("subtype")}get isBound(){return this.loadedProperty("isBound")}get cannotDelete(){let t=this.loadedProperty("lock");return t==="sdtLocked"||t==="sdtContentLocked"}set cannotDelete(t){this.#s(t,this.cannotEdit,`${this.path.label}.cannotDelete`);}get cannotEdit(){let t=this.loadedProperty("lock");return t==="contentLocked"||t==="sdtContentLocked"}set cannotEdit(t){this.#s(this.cannotDelete,t,`${this.path.label}.cannotEdit`);}get placeholderShown(){return this.loadedProperty("placeholderShown")}get temporary(){return this.loadedProperty("temporary")}get text(){return this.loadedProperty("text")}get paragraphs(){return this.#e??=v.overListing(this.context,`${this.path.label}.paragraphs`,this.path,()=>({op:"getContentControlParagraphs",contentControl:this.#i()})),this.#e}get contentControls(){return this.#o??=w.of(this.context,`${this.path.label}.contentControls`,this.path,{contentControl:this.#i()}),this.#o}getRange(t){let e=`${this.path.label}.getRange`,o=Oe(t??"Whole",e),r=this.#t.get(o);if(r)return r;let i=this.#n(e,o);return this.#t.set(o,i),i}setValue(t){let e=`${this.path.label}.setValue`,o=Re(t,e),r=this.#i();this.command("setValue",()=>({op:"setContentControlValue",contentControl:r,value:o}));}insertText(t,e){let o=`${this.path.label}.insertText`,r=A(t,o),i=e==="Replace"?"replace":e==="Start"?"start":e==="End"?"end":a({code:"InvalidArgument",target:o}),s=this.#i(),d=m.promised(this.context,o,false);return this.commandAnswering(o,()=>({op:"insertContentControlText",contentControl:s,text:r,at:i}),c=>{d.hydrateAddress({kind:"span",span:x(c,o)});}),d}delete(t){let e=`${this.path.label}.delete`;typeof t!="boolean"&&a({code:"InvalidArgument",target:e});let o=this.#i();this.command("delete",()=>({op:"deleteContentControl",contentControl:o,keepContent:t}));}onLoad(t){let e=this.selection(t,["id","tag","title","subtype","isBound","text","cannotDelete","cannotEdit","placeholderShown","temporary"]),o=this.#i();if(e.includes("id")&&this.loadTextInto("id",()=>({op:"getContentControlFileId",contentControl:o})),e.includes("tag")&&this.loadTextInto("tag",()=>({op:"getContentControlTag",contentControl:o})),e.includes("title")&&this.loadTextInto("title",()=>({op:"getContentControlTitle",contentControl:o})),e.includes("subtype")&&this.loadTextInto("subtype",()=>({op:"getContentControlSubtype",contentControl:o})),e.includes("isBound")){let i=`${this.path.label}.isBound`;this.read(i,()=>({op:"getContentControlIsBound",contentControl:o}),s=>{this.setLoadedProperty("isBound",M(s,i));});}if(e.includes("text")&&this.loadTextInto("text",()=>({op:"getContentControlText",contentControl:o,projection:this.revisionTextView()})),e.includes("cannotDelete")||e.includes("cannotEdit")){let i=`${this.path.label}.lock`;this.read(i,()=>({op:"getContentControlLock",contentControl:o}),s=>{this.setLoadedProperty("lock",y(s,i));});}if(e.includes("placeholderShown")){let i=`${this.path.label}.placeholderShown`;this.read(i,()=>({op:"getContentControlPlaceholderShown",contentControl:o}),s=>{this.setLoadedProperty("placeholderShown",M(s,i));});}if(!e.includes("temporary"))return;let r=`${this.path.label}.temporary`;this.read(r,()=>({op:"getContentControlTemporary",contentControl:o}),i=>{this.setLoadedProperty("temporary",M(i,r));});}#n(t,e){let o=this.#i(),r=m.promised(this.context,t,false);return this.read(t,()=>({op:"getContentControlRange",contentControl:o,location:e}),i=>{r.hydrateAddress({kind:"span",span:x(i,t)});}),r}#r(t,e){let o=this.#i();this.command(t,()=>({op:"setContentControlProperties",contentControl:o,...e}));}#s(t,e,o){(typeof t!="boolean"||typeof e!="boolean")&&a({code:"InvalidArgument",target:o});let r=t&&e?"sdtContentLocked":t?"sdtLocked":e?"contentLocked":"unlocked",i=this.#i();this.command(o,()=>({op:"setContentControlProperties",contentControl:i,lock:r}));}#i(){return this.requireAddressable(),this.path.handle()}},w=class n extends b{#t;#e;static of(t,e,o,r){return new n(t,l.derived(e,o),r,()=>({op:"getContentControls",scope:r}))}constructor(t,e,o,r){super(t,e),this.#t=o,this.#e=r;}getFirst(){return this.edge("first","getFirst",false)}getFirstOrNullObject(){return this.edge("first","getFirstOrNullObject",true)}getById(t){let e=`${this.path.label}.getById`;Number.isInteger(t)||a({code:"InvalidArgument",target:e});let o=this.#t,r=W.promised(this.context,e,false);return this.enqueue({sort:"read",label:e,plan:()=>({op:"getContentControlById",scope:o,id:t}),settle:i=>{r.hydrateAddress({kind:"handle",handle:f(i,e)});}}),r}getByTag(t){let e=`${this.path.label}.getByTag`,o=Kt(t,e),r=this.#t;return new n(this.context,l.derived(e,this.path),r,()=>({op:"getContentControlsByTag",scope:r,tag:o}))}getByTitle(t){let e=`${this.path.label}.getByTitle`,o=Kt(t,e),r=this.#t;return new n(this.context,l.derived(e,this.path),r,()=>({op:"getContentControlsByTitle",scope:r,title:o}))}listing(){return this.#e()}itemAt(t,e){return W.at(this.context,t,e)}promised(t,e){return W.promised(this.context,t,e)}};function jt(n,t){return (typeof n!="string"||n.length>Zt)&&a({code:"InvalidArgument",target:t}),n}function Kt(n,t){let e=jt(n,t);return e.length===0&&a({code:"InvalidArgument",target:t}),e}function Oe(n,t){switch(n){case "Whole":return "whole";case "Content":return "content";case "Start":return "start";case "End":return "end";case "Before":return "before";case "After":return "after";default:return a({code:"InvalidArgument",target:t})}}function Re(n,t){(typeof n!="object"||n===null)&&a({code:"InvalidArgument",target:t});let e=n;if(e.kind==="text"||e.kind==="listItem"){let o=e.kind==="text"?e.text:e.value;return (typeof o!="string"||o.length>Zt)&&a({code:"InvalidArgument",target:t}),e.kind==="text"?{kind:"text",text:o}:{kind:"listItem",value:o}}if(e.kind==="checkbox")return typeof e.checked!="boolean"&&a({code:"InvalidArgument",target:t}),{kind:"checkbox",checked:e.checked};if(e.kind==="date")return (typeof e.iso!="string"||e.iso.length>64)&&a({code:"InvalidArgument",target:t}),{kind:"date",iso:e.iso};a({code:"InvalidArgument",target:t});}var S=class n extends p{#t;#e;#o;#n;#r;#s;static main(t,e){return new n(t,l.of(e,H(t).roots().body))}static promisedStory(t,e){return new n(t,l.pending(e))}hydrateAddress(t){t.kind==="handle"?this.path.resolveTo(t.handle):this.path.resolveNull();}constructor(t,e){super(t,e);}get text(){return this.loadedProperty("text")}get paragraphs(){return this.#t??=this.paragraphsUnder(`${this.path.label}.paragraphs`),this.#t}get bookmarks(){let t=this.#a();return this.#e??=D.of(this.context,`${this.path.label}.bookmarks`,this.path,()=>({op:"getBookmarks",scope:{body:t}})),this.#e}get font(){return this.#o??=k.of(this.context,`${this.path.label}.font`,this.path,"body"),this.#o}paragraphsUnder(t){return v.of(this.context,t,this.path)}get style(){return this.loadedProperty("style")}set style(t){let e=`${this.path.label}.style`,o=Y(t,e);this.requireAddressable(),this.command("style",()=>({op:"setStyle",span:E(this.path,"body"),name:o}));}get lists(){return this.#n??=K.of(this.context,`${this.path.label}.lists`,this.path,this.#a()),this.#n}get contentControls(){return this.#r??=w.of(this.context,`${this.path.label}.contentControls`,this.path,{body:this.#a()}),this.#r}getComments(){let t=`${this.path.label}.getComments`,e=this.#a();return N.of(this.context,t,this.path,()=>({op:"getComments",scope:{body:e}}))}get revisions(){return this.#s??=$.of(this.context,`${this.path.label}.revisions`,this.path,this.#a()),this.#s}search(t,e){let o=`${this.path.label}.search`;typeof t!="string"&&a({code:"InvalidArgument",target:o});let r=vt(e,o),i=this.#a();return I.of(this.context,o,this.path,()=>({op:"search",scope:{body:i},text:t,options:{...r??{},projection:this.revisionTextView()}}))}clear(){let t=this.#a();this.commandDiscarding("clear",()=>({op:"replaceSpan",span:{body:t},text:""}));}insertText(t,e){let o=`${this.path.label}.insertText`,r=A(t,o),i=Bt(e,o),s=this.#a(),d=m.promised(this.context,o,false);return this.commandAnswering(o,()=>i==="Replace"?{op:"replaceSpan",span:{body:s},text:r}:{op:"insertText",at:{body:s,at:i==="Start"?"start":"end"},text:r},c=>{d.hydrateAddress({kind:"span",span:x(c,o)});}),d}insertParagraph(t,e){let o=`${this.path.label}.insertParagraph`,r=A(t,o),i=Ht(e,o),s=this.#a(),d=O.promised(this.context,o,false);return this.commandAnswering(o,()=>({op:"insertParagraph",anchor:{body:s,at:i==="Start"?"first":"last"},where:i==="Start"?"before":"after",text:r}),c=>{c.kind!=="handle"&&a({code:"GeneralException",target:o}),d.hydrateAddress({kind:"handle",handle:c.handle});}),d}onLoad(t){let e=this.selection(t,["text","style"]);if(e.includes("text")){let o=this.#a();this.loadTextInto("text",()=>({op:"getText",target:o,projection:this.revisionTextView()}));}e.includes("style")&&this.#i();}#i(){let t=`${this.path.label}.style`;this.requireAddressable(),this.read(t,()=>({op:"getStyle",span:E(this.path,"body")}),e=>{this.setLoadedProperty("style",at(e,t));});}#a(){return this.requireAddressable(),this.path.handle()}};function Pe(n){return n==="endnote"?"Endnote":"Footnote"}var et=class n extends p{#t;static at(t,e,o){return o.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new n(t,l.of(e,o.handle),false)}static promised(t,e,o){return new n(t,l.pending(e),o)}constructor(t,e,o){super(t,e,{nullable:o});}hydrateAddress(t){t.kind==="handle"?this.path.resolveTo(t.handle):this.path.resolveNull();}hydrateNull(){this.path.resolveNull();}get type(){return this.loadedProperty("type")}get text(){return this.loadedProperty("text")}get body(){if(this.#t)return this.#t;let t=`${this.path.label}.body`,e=this.#e(),o=S.promisedStory(this.context,t);return this.read(t,()=>({op:"getNoteBody",note:e}),r=>{o.hydrateAddress({kind:"handle",handle:f(r,t)});}),this.#t=o,o}delete(){let t=this.#e();this.command("delete",()=>({op:"deleteNote",note:t}));}getNext(){let t=`${this.path.label}.getNext`,e=this.#e(),o=n.promised(this.context,t,false),r=this.internals.roots().document,i=`${t}.type`,s="footnote";return this.read(i,()=>({op:"getNoteKind",note:e}),d=>{s=y(d,i)==="endnote"?"endnote":"footnote";}),this.read(t,()=>({op:"getNotes",document:r,noteKind:s}),d=>{let c=P(d,t),g=c.findIndex(z=>z.ref===e.ref),j=g<0?void 0:c[g+1];j||a({code:"ItemNotFound",target:t}),o.hydrateAddress({kind:"handle",handle:j});}),o}onLoad(t){let e=this.selection(t,["text","type"]);if(e.includes("text")){let o=this.#e();this.loadTextInto("text",()=>({op:"getNoteText",note:o,projection:this.revisionTextView()}));}if(e.includes("type")){let o=`${this.path.label}.type`,r=this.#e();this.read(o,()=>({op:"getNoteKind",note:r}),i=>{this.setLoadedProperty("type",Pe(y(i,o)));});}}#e(){return this.requireAddressable(),this.path.handle()}},U=class n extends b{#t;static of(t,e,o,r){return new n(t,l.derived(e,o),r)}constructor(t,e,o){super(t,e),this.#t=o;}getFirst(){return this.edge("first","getFirst",false)}listing(){return this.#t()}itemAt(t,e){return et.at(this.context,t,e)}promised(t,e){return et.promised(this.context,t,e)}};var Se=Object.freeze({Primary:"default",FirstPage:"first",EvenPages:"even"}),ke=["pageWidth","pageHeight","orientation","topMargin","rightMargin","bottomMargin","leftMargin"],pt=class n extends p{#t;static of(t,e,o){return new n(t,l.derived(e,o))}constructor(t,e){super(t,e);}get pageWidth(){return this.loadedProperty("pageWidth")}set pageWidth(t){this.#e("pageWidth",ot(t,`${this.path.label}.pageWidth`));}get pageHeight(){return this.loadedProperty("pageHeight")}set pageHeight(t){this.#e("pageHeight",ot(t,`${this.path.label}.pageHeight`));}get orientation(){return this.loadedProperty("orientation")}set orientation(t){let e=`${this.path.label}.orientation`;t!=="Portrait"&&t!=="Landscape"&&a({code:"InvalidArgument",target:e}),this.#e("orientation",t==="Portrait"?"portrait":"landscape");}get topMargin(){return this.loadedProperty("topMargin")}set topMargin(t){this.#e("topMargin",ot(t,`${this.path.label}.topMargin`));}get bottomMargin(){return this.loadedProperty("bottomMargin")}set bottomMargin(t){this.#e("bottomMargin",ot(t,`${this.path.label}.bottomMargin`));}get leftMargin(){return this.loadedProperty("leftMargin")}set leftMargin(t){this.#e("leftMargin",ot(t,`${this.path.label}.leftMargin`));}get rightMargin(){return this.loadedProperty("rightMargin")}set rightMargin(t){this.#e("rightMargin",ot(t,`${this.path.label}.rightMargin`));}onLoad(t){let e=this.selection(t,ke);if(e.length===0)return;let o=`${this.path.label}.pageSetup`,r=this.#o();this.read(o,()=>({op:"getPageSetup",section:r}),i=>{let s=kt(i,o);for(let d of e)this.setLoadedProperty(d,d==="orientation"?s.orientation==="landscape"?"Landscape":"Portrait":s[d]);});}#e(t,e){if(this.requireAddressable(),this.#t){this.#t[t]=e;return}let o={[t]:e};this.#t=o;let r=this.#o(),i=`${this.path.label}.${t}`;this.commandAnswering(`${this.path.label}.pageSetup`,()=>(this.#t=void 0,{op:"setPageSetup",section:r,setup:o}),s=>{C(s,i);});}#o(){this.requireAddressable();let t=this.path.address();return t.kind!=="handle"&&a({code:"InvalidObjectPath",target:this.path.label}),t.handle}},nt=class n extends p{#t;#e;static at(t,e,o){return o.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new n(t,l.of(e,o.handle),false)}static promised(t,e,o){return new n(t,l.pending(e),o)}constructor(t,e,o){super(t,e,{nullable:o});}hydrateAddress(t){t.kind==="handle"?this.path.resolveTo(t.handle):this.path.resolveNull();}hydrateNull(){this.path.resolveNull();}get body(){return this.#e??=S.main(this.context,`${this.path.label}.body`),this.#e}get pageSetup(){return this.#t??=pt.of(this.context,`${this.path.label}.pageSetup`,this.path),this.#t}getHeader(t){return this.#o("header",t,"getHeader")}getFooter(t){return this.#o("footer",t,"getFooter")}getNext(){let t=`${this.path.label}.getNext`,e=this.#n(),o=n.promised(this.context,t,false),r=this.internals.roots().document;return this.read(t,()=>({op:"getSections",document:r}),i=>{let s=P(i,t),d=s.findIndex(g=>g.ref===e.ref),c=d<0?void 0:s[d+1];c||a({code:"ItemNotFound",target:t}),o.hydrateAddress({kind:"handle",handle:c});}),o}onLoad(t){this.selection(t,[]);}#o(t,e,o){let r=`${this.path.label}.${o}`,i=Se[e];i===void 0&&a({code:"InvalidArgument",target:r});let s=this.#n(),d=S.promisedStory(this.context,r);return this.read(r,()=>({op:"getFurniture",section:s,kind:t,variant:i}),c=>{d.hydrateAddress({kind:"handle",handle:f(c,r)});}),d}#n(){return this.requireAddressable(),this.path.handle()}},rt=class n extends b{#t;static of(t,e,o,r){return new n(t,l.derived(e,o),r)}constructor(t,e,o){super(t,e),this.#t=o;}getFirst(){return this.edge("first","getFirst",false)}listing(){return this.#t()}itemAt(t,e){return nt.at(this.context,t,e)}promised(t,e){return nt.promised(this.context,t,e)}};function ot(n,t){return (typeof n!="number"||!Number.isFinite(n)||n<0)&&a({code:"InvalidArgument",target:t}),n}var it=class n extends p{#t;#e;#o;#n;#r;#s;#i;#a;static open(t){return new n(t)}constructor(t){super(t,l.of("document",H(t).roots().document));}get body(){return this.#t??=S.main(this.context,"document.body"),this.#t}get paragraphs(){return this.#e??=this.body.paragraphsUnder("document.paragraphs"),this.#e}get sections(){let t=this.path.handle();return this.#o??=rt.of(this.context,"document.sections",this.path,()=>({op:"getSections",document:t})),this.#o}get contentControls(){return this.#s??=w.of(this.context,"document.contentControls",this.path,{body:this.internals.roots().body}),this.#s}get comments(){return this.#n??=N.of(this.context,"document.comments",this.path,()=>({op:"getComments",scope:{body:this.internals.roots().body}})),this.#n}get revisions(){return this.#r??=$.of(this.context,"document.revisions",this.path,this.internals.roots().body),this.#r}get footnotes(){let t=this.path.handle();return this.#i??=U.of(this.context,"document.footnotes",this.path,()=>({op:"getNotes",document:t,noteKind:"footnote"})),this.#i}get endnotes(){let t=this.path.handle();return this.#a??=U.of(this.context,"document.endnotes",this.path,()=>({op:"getNotes",document:t,noteKind:"endnote"})),this.#a}onLoad(t){this.selection(t,[]);}};function Jt(n){let t=n.host,e=Object.freeze({...t.capabilities,save:n.save&&t.capabilities.save}),o=typeof n.author=="string"&&n.author.trim().length>0?n.author:void 0,r=n.revisionTextView??"allMarkup";r!=="allMarkup"&&r!=="original"&&a({code:"InvalidArgument",target:"revisionTextView"});let i=false,s=null,d=h=>{i&&a({code:"RuntimeDisposed",...h===void 0?{}:{target:h}});},c=()=>{if(s)return s;d("document");let h=Yt(t.execute({operations:[{op:"getDocument"}]}),"document"),F=Yt(t.execute({operations:[{op:"getBody",document:h}]}),"document.body");return s={document:h,body:F},s},g={host:t,capabilities:e,...o===void 0?{}:{author:o},revisionTextView:r,id:{},roots:c,assertLive:d,openDocument:h=>it.open(h)};try{c();}catch{s=null;}async function j(h,F){d();let G=typeof h=="function"?h:F,Ot=typeof h=="function"?[]:Array.isArray(h)?h:[h];typeof G!="function"&&a({code:"InvalidArgument",target:"run"});let{context:ut,adopt:te,finish:ee}=dt.begin(g);try{return te(Ot),await G(ut)}finally{ee();}}let z={capabilities:e,run:j,dispose(){i||(i=true,s=null,t.dispose());}};return n.save?{...z,async save(){d("save"),e.save||a({code:"NotSupported",target:"save"});let h=t.save();if(!h.ok)throw yt(h.error,{target:"save"});return h.bytes}}:z}function Yt(n,t){let e=n.results[0];if(e?.status==="error")throw yt(e.error,{target:t});if(e?.status!=="ok")throw new u({code:"GeneralException",target:t});return f(e.value,t)}function je(n){if(n){for(let t of n)if(t.collaboration)return t.collaboration}}async function Lt(n,t={}){let e=je(t.modules),o=createServerAutomationHost(n,{...t.limits===void 0?{}:{limits:t.limits},...e===void 0?{}:{collaborationModel:e}});return o.ok||a({code:"InvalidArgument",target:"createServer"}),Jt({host:o.host,save:true,...t.author===void 0?{}:{author:t.author},...t.revisionTextView===void 0?{}:{revisionTextView:t.revisionTextView}})}function _t(n,t,e={}){return Lt(n,{...e,modules:[...e.modules??[],{id:"collaboration",collaboration:{session:t}}]})}var Tr=Object.freeze({createServer:Lt,createCollaborative:_t});export{S as Body,tt as Bookmark,D as BookmarkCollection,T as ClientObject,Rt as ClientResult,q as Comment,N as CommentCollection,V as CommentReply,ct as CommentReplyCollection,W as ContentControl,w as ContentControlCollection,it as Document,Tr as DocxEditor,u as DocxEditorError,k as Font,L as List,K as ListCollection,Z as ListItem,et as NoteItem,U as NoteItemCollection,pt as PageSetup,O as Paragraph,v as ParagraphCollection,m as Range,I as RangeCollection,dt as RequestContext,_ as Revision,$ as RevisionCollection,nt as Section,rt as SectionCollection,st as TrackedObjects,oe as isDocxEditorError};
1
+ import {createServerAutomationHost}from'@docx-editor.dev/core/automation';var wt=Object.freeze({PropertyNotLoaded:"the property has not been loaded. Call load(...) and await context.sync() before reading it.",ValueNotLoaded:"the result has not been filled in yet. Await context.sync() before reading it.",InvalidObjectPath:"the object cannot be addressed. An object an item accessor answered is usable after the next await context.sync(); an object whose run has ended is released for good, unless context.trackedObjects.add(...) kept it.",ObjectInUse:"the object still belongs to a run that has not finished. Await that run before passing the object to another one.",InvalidArgument:"the argument is not one this API accepts.",ResourceLimitExceeded:"the document exceeds a supported resource limit.",ItemNotFound:"the collection has no such item.",NotSupported:"this document host does not support that operation.",NotImplemented:"this version does not implement that yet.",ConflictingChanges:"two changes in this batch affect the same paragraph. Split them across two context.sync() calls.",InvalidRequestContext:"the request context has finished. Start another run to continue.",RuntimeDisposed:"the runtime has been disposed.",StaleDocument:"the document changed after this context read it, so nothing was applied.",DocumentUnavailable:"the document is not available right now.",GeneralException:"the document could not complete the request."}),u=class extends Error{code;limit;target;expectedRevision;actualRevision;constructor(t){let e=t.target?`${wt[t.code]} (${t.target})`:wt[t.code];super(e),this.name="DocxEditorError",this.code=t.code,t.limit!==void 0&&(this.limit=t.limit),t.target!==void 0&&(this.target=t.target),t.expectedRevision!==void 0&&(this.expectedRevision=t.expectedRevision),t.actualRevision!==void 0&&(this.actualRevision=t.actualRevision);}};function oe(n){return n instanceof u?true:typeof n=="object"&&n!==null&&n.name==="DocxEditorError"&&typeof n.code=="string"}function a(n){throw new u(n)}var F=Symbol("docx-editor.runtime.internals"),mt=Symbol("docx-editor.runtime.release"),gt=Symbol("docx-editor.runtime.rebind");function H(n){return n[F]}var ne=new Set(["select","expand","top","skip"]),re=/^[A-Za-z][A-Za-z0-9]*$/;function Tt(n,t){if(n===void 0)return [];let e=typeof n=="string"?n.split(",").map(r=>r.trim()):Array.isArray(n)?n.map(r=>typeof r=="string"?r.trim():r):a({code:"InvalidArgument",target:t}),o=[];for(let r of e)(typeof r!="string"||!re.test(r))&&a({code:"InvalidArgument",target:t}),o.includes(r)||o.push(r);return o.length===0&&a({code:"InvalidArgument",target:t}),o}function Et(n,t){return (typeof n!="number"||!Number.isInteger(n)||n<0)&&a({code:"InvalidArgument",target:t}),n}function ie(n,t){n===void 0||Array.isArray(n)&&n.length===0||a({code:"InvalidArgument",target:t});}function Nt(n,t){if(n===void 0)return {select:[]};if(typeof n=="string"||Array.isArray(n))return {select:Tt(n,t)};(typeof n!="object"||n===null)&&a({code:"InvalidArgument",target:t});let e=n;for(let o of Object.keys(e))ne.has(o)||a({code:"InvalidArgument",target:`${t}.${o}`});return ie(e.expand,`${t}.expand`),{select:Tt(e.select,`${t}.select`),...e.top===void 0?{}:{top:Et(e.top,`${t}.top`)},...e.skip===void 0?{}:{skip:Et(e.skip,`${t}.skip`)}}}var T=class{#t;#e;#o;#n;#r=new Map;constructor(t,e,o={}){this.#t=t,this.#e=t[F],this.#o=e,this.#n=o.nullable===true,this.#e.register(this);}get context(){return this.#t}get isNullObject(){return this.#o.isReleased&&a({code:"InvalidObjectPath",target:this.#o.label}),this.#n?(this.#o.isPending&&a({code:"PropertyNotLoaded",target:`${this.#o.label}.isNullObject`}),this.#o.isNull):false}load(t){return this.requireAddressable(),this.onLoad(Nt(t,this.#o.label)),this}get path(){return this.#o}get internals(){return this.#e}handle(){return this.#o.handle()}requireAddressable(){this.#o.isAddressable||a({code:"InvalidObjectPath",target:this.#o.label}),this.#e.assertUsable(this.#o.label);}enqueue(t){this.requireAddressable(),this.#e.queue.push(t);}loadedProperty(t){return this.#o.isReleased&&!this.#r.has(t)&&a({code:"InvalidObjectPath",target:this.#o.label}),this.#r.has(t)||a({code:"PropertyNotLoaded",target:`${this.#o.label}.${t}`}),this.#r.get(t)}hasLoadedProperty(t){return this.#r.has(t)}setLoadedProperty(t,e){this.#r.set(t,e);}[mt](){this.#o.release();}[gt](t){this.#t=t,this.#e=t[F];}};var Ot=class n{#t=false;#e;#o;constructor(t){this.#o=t;}get value(){return this.#t||a({code:"ValueNotLoaded",target:this.#o}),this.#e}get isLoaded(){return this.#t}static create(t){let e=new n(t);return {result:e,fill(o){e.#t=true,e.#e=o;}}}};function O(n){return new u({code:"GeneralException",target:n})}function b(n,t){if(n.kind!=="text")throw O(t);return n.text}function f(n,t){if(n.kind!=="handle")throw O(t);return n.handle}function P(n,t){if(n.kind!=="handles")throw O(t);return n.handles}function x(n,t){if(n.kind!=="span")throw O(t);return n.span}function ft(n,t){if(n.kind!=="spans")throw O(t);return n.spans}function Pt(n,t){if(n.kind!=="font")throw O(t);return n.font}function kt(n,t){if(n.kind!=="paragraphFormat")throw O(t);return n.format}function at(n,t){if(n.kind!=="style")throw O(t);return n.name}function yt(n,t){if(n.kind!=="number")throw O(t);return n.value}function M(n,t){if(n.kind!=="flag")throw O(t);return n.value}function It(n,t){if(n.kind!=="pageSetup")throw O(t);return n.setup}function C(n,t){if(n.kind!=="applied")throw O(t)}var l=class n{label;#t;#e;constructor(t,e,o=null){this.label=t,this.#t=e,this.#e=o;}static of(t,e){return new n(t,{status:"resolved",address:{kind:"handle",handle:e}})}static ofSpan(t,e){return new n(t,{status:"resolved",address:{kind:"span",span:e}})}static pending(t){return new n(t,{status:"pending"})}static derived(t,e){return new n(t,{status:"pending"},e)}get state(){return this.#e?this.#e.state:this.#t}get isAddressable(){return this.state.status==="resolved"}get isPending(){return this.state.status==="pending"}get isNull(){return this.state.status==="null"}get isReleased(){return this.state.status==="released"}address(){let t=this.state;if(t.status==="resolved")return t.address;a({code:"InvalidObjectPath",target:this.label});}handle(){let t=this.address();return t.kind!=="handle"&&a({code:"InvalidObjectPath",target:this.label}),t.handle}span(){let t=this.address();return t.kind!=="span"&&a({code:"InvalidObjectPath",target:this.label}),t.span}resolveTo(t){this.#o({kind:"handle",handle:t});}resolveToSpan(t){this.#o({kind:"span",span:t});}resolveNull(){this.#t.status!=="released"&&(this.#t={status:"null"});}release(){this.#e||(this.#t={status:"released"});}#o(t){this.#t.status!=="released"&&(this.#t={status:"resolved",address:t});}};function qt(n){let t=[],e=false,o=false;for(let r of n)t.push(r.plan()),r.sort==="write"?o=true:e=true;return {operations:t,hasRead:e,hasWrite:o}}var ae=Object.freeze({"stale-revision":"StaleDocument","invalid-handle":"InvalidObjectPath","invalid-offset":"InvalidArgument","unsupported-capability":"NotSupported",disposed:"RuntimeDisposed","transaction-refused":"GeneralException","unknown-operation":"NotSupported","unsupported-content":"InvalidArgument","unsupported-revision":"NotImplemented","ambiguous-document":"GeneralException","conflicting-operations":"ConflictingChanges","document-unavailable":"DocumentUnavailable"});function bt(n,t={}){let e=ae[n.code]??"GeneralException",o=e==="StaleDocument";return new u({code:e,...t.target===void 0?{}:{target:t.target},...o&&t.expectedRevision!==void 0?{expectedRevision:t.expectedRevision}:{},...o&&t.actualRevision!==void 0?{actualRevision:t.actualRevision}:{}})}function $t(n,t,e){for(let o=0;o<n.results.length;o+=1){let r=n.results[o];if(r?.status!=="error")continue;let i=t[o]?.label;return bt(r.error,{...i===void 0?{}:{target:i},...e===void 0?{}:{expectedRevision:e},actualRevision:n.revision})}return new u({code:"GeneralException"})}function Dt(n,t){if(t.results.length!==n.length)throw new u({code:"GeneralException"});for(let e=0;e<n.length;e+=1){let o=t.results[e],r=n[e];if(o.status!=="ok")throw new u({code:"GeneralException",target:r.label});r.settle(o.value);}}var xt=class{#t=[];get size(){return this.#t.length}get pending(){return this.#t}push(t){this.#t.push(t);}take(){let t=this.#t;return this.#t=[],t}clear(){this.#t=[];}};function Bt(n,t){if(Array.isArray(n)){for(let e of n)t(e);return}t(n);}var st=class{#t;#e;constructor(t,e){this.#t=t,this.#e=e;}add(t){this.#t.assertUsable(),Bt(t,e=>{this.#o(e),this.#t.track(e);});}remove(t){this.#t.assertUsable(),Bt(t,e=>{this.#o(e),this.#t.untrack(e);});}#o(t){this.#e(t)||a({code:"InvalidObjectPath"});}};var dt=class n{#t;#e=new xt;#o=new Set;#n=new Set;#r;#s;#i;#a=false;#d=null;constructor(t){this.#t=t,this.#r={host:t.host,capabilities:t.capabilities,...t.author===void 0?{}:{author:t.author},revisionTextView:t.revisionTextView,queue:this.#e,session:t.id,roots:()=>t.roots(),assertUsable:e=>{this.#t.assertLive(e),this.#a&&a({code:"InvalidRequestContext",...e===void 0?{}:{target:e}});},isFinished:()=>this.#a,readRevision:()=>this.#d,register:e=>{this.#o.add(e);},track:e=>{this.#n.add(e);},untrack:e=>{this.#n.delete(e);},isTracked:e=>this.#n.has(e),disown:e=>{this.#o.delete(e),this.#n.delete(e);}},this.#s=new st(this.#r,e=>this.#o.has(e));}get document(){return this.#r.assertUsable("document"),this.#i??=this.#t.openDocument(this),this.#i}get capabilities(){return this.#t.capabilities}get trackedObjects(){return this.#s}async sync(){this.#r.assertUsable();let t=this.#e.take();if(t.length===0)return;let e=qt(t),r=e.hasWrite&&this.#d!==null?this.#d:void 0,i={operations:e.operations,...r===void 0?{}:{expectedRevision:r}},s=this.#t.host.execute(i);if(!s.ok)throw $t(s,t,r);Dt(t,s),(e.hasRead||e.hasWrite)&&(this.#d=s.revision);}get[F](){return this.#r}static begin(t){let e=new n(t);return {context:e,adopt(o){for(let r of o)e.#l(r);},finish(){e.#p();}}}#l(t){let e=t.context;if(e===this)return;let o=e[F];if(o.session!==this.#t.id)throw new u({code:"InvalidObjectPath"});if(!o.isFinished())throw new u({code:"ObjectInUse"});if(!o.isTracked(t))throw new u({code:"InvalidObjectPath"});let r=o.readRevision();o.disown(t),t[gt](this),this.#o.add(t),this.#n.add(t),r!==null&&this.#c(r);}#c(t){this.#d=this.#d===null?t:Math.min(this.#d,t);}#p(){if(!this.#a){this.#a=true,this.#e.clear();for(let t of this.#o)this.#n.has(t)||t[mt]();this.#o.clear();}}};function lt(n,t,e){if(n.select.length===0)return t;for(let o of n.select)t.includes(o)||a({code:"InvalidArgument",target:`${e}.${o}`});return n.select}var Q=class extends T{#t;#e=[];constructor(t,e){super(t,e);}get items(){return this.loadedProperty("items")}fill(t,e){this.setLoadedProperty("items",this.#n(t,e,0,void 0)),this.#t={value:t,label:e};let o=this.#e.splice(0,this.#e.length);for(let r of o)this.#o(r,t);}onLoad(t){lt(t,["items"],this.path.label);let e=this.listing();if(!e)return;let o=`${this.path.label}.items`,r=t.skip??0,i=t.top;this.enqueue({sort:"read",label:o,plan:()=>e,settle:s=>{this.setLoadedProperty("items",this.#n(s,o,r,i));}});}edge(t,e,o){let r=`${this.path.label}.${e}()`,i=this.promised(r,o),s=this.listing();if(!s){let d={edge:t,target:r,nullable:o,item:i};return this.#t?this.#o(d,this.#t.value):this.#e.push(d),i}return this.enqueue({sort:"read",label:r,plan:()=>s,settle:d=>{this.#o({edge:t,target:r,nullable:o,item:i},d);}}),i}#o(t,e){let{edge:o,target:r,nullable:i,item:s}=t,d=this.size(e,r);if(d===0){i||a({code:"ItemNotFound",target:r}),s.hydrateNull();return}let c=this.addressAt(e,r,o==="first"?0:d-1);c||a({code:"ItemNotFound",target:r}),s.hydrateAddress(c);}#n(t,e,o,r){let i=this.size(t,e),s=r===void 0?i:Math.min(i,o+r),d=[];for(let c=o;c<s;c+=1){let g=this.addressAt(t,e,c);g&&d.push(this.itemAt(`${e}[${String(c)}]`,g));}return d}},y=class extends Q{size(t,e){return P(t,e).length}addressAt(t,e,o){let r=P(t,e)[o];return r?{kind:"handle",handle:r}:void 0}};var se=["Replace","Start","End"],de=["Start","End"],le=["Replace","Start","End"],ce=["Before","After"],pe=["Replace","Start","End","Before","After"],he=["Select","Start","End"];function X(n,t,e){return (typeof n!="string"||!t.includes(n))&&a({code:"InvalidArgument",target:e}),n}var Ft=(n,t)=>X(n,se,t),Ht=(n,t)=>X(n,de,t),Mt=(n,t)=>X(n,le,t),Vt=(n,t)=>X(n,ce,t),St=(n,t)=>X(n,pe,t),Ct=(n,t)=>n===void 0?"Select":X(n,he,t);function A(n,t){return typeof n!="string"&&a({code:"InvalidArgument",target:t}),/[\r\n\v\f\u2028\u2029]/.test(n)&&a({code:"InvalidArgument",target:t}),n}var p=class extends T{revisionTextView(){return H(this.context).revisionTextView}loadTextInto(t,e){let o=`${this.path.label}.${t}`;this.enqueue({sort:"read",label:o,plan:e,settle:r=>{this.setLoadedProperty(t,b(r,o));}});}command(t,e){let o=`${this.path.label}.${t}`;this.enqueue({sort:"write",label:o,plan:e,settle:r=>C(r,o)});}commandDiscarding(t,e){let o=`${this.path.label}.${t}`;this.enqueue({sort:"write",label:o,plan:e,settle:()=>{}});}commandAnswering(t,e,o){this.enqueue({sort:"write",label:t,plan:e,settle:o});}read(t,e,o){this.enqueue({sort:"read",label:t,plan:e,settle:o});}selection(t,e){return lt(t,e,this.path.label)}onLoad(t){this.selection(t,[]);}};var ue=8,j=class n extends p{#t;static at(t,e,o){return o.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new n(t,l.of(e,o.handle),false)}static promised(t,e,o){return new n(t,l.pending(e),o)}constructor(t,e,o){super(t,e,{nullable:o});}hydrateAddress(t){t.kind==="handle"?this.path.resolveTo(t.handle):this.path.resolveNull();}hydrateNull(){this.path.resolveNull();}get id(){return this.loadedProperty("id")}get paragraphs(){return this.#t??=v.overListing(this.context,`${this.path.label}.paragraphs`,this.path,()=>({op:"getListParagraphs",list:this.#e()})),this.#t}getLevelParagraphs(t){let e=`${this.path.label}.getLevelParagraphs`,o=Wt(t,e),r=this.#e();return v.overListing(this.context,e,this.path,()=>({op:"getListParagraphs",list:r,level:o}))}insertParagraph(t,e){let o=`${this.path.label}.insertParagraph`,r=A(t,o);e!=="Start"&&e!=="End"&&e!=="Before"&&e!=="After"&&a({code:"InvalidArgument",target:o});let i=this.#e(),s=R.promised(this.context,o,false);return this.commandAnswering(o,()=>({op:"insertListParagraph",list:i,where:e==="Start"||e==="Before"?"start":"end",text:r}),d=>{s.hydrateAddress({kind:"handle",handle:f(d,o)});}),s}onLoad(t){if(!this.selection(t,["id"]).includes("id"))return;let e=`${this.path.label}.id`,o=this.#e();this.read(e,()=>({op:"getListId",list:o}),r=>{this.setLoadedProperty("id",yt(r,e));});}#e(){return this.requireAddressable(),this.path.handle()}},K=class n extends y{#t;static of(t,e,o,r){return new n(t,l.derived(e,o),r)}constructor(t,e,o){super(t,e),this.#t=o;}getFirst(){return this.edge("first","getFirst",false)}getById(t){let e=`${this.path.label}.getById`,o=me(t,e),r=this.#t,i=j.promised(this.context,e,false);return this.enqueue({sort:"read",label:e,plan:()=>({op:"getListById",body:r,id:o}),settle:s=>{i.hydrateAddress({kind:"handle",handle:f(s,e)});}}),i}listing(){return {op:"getLists",body:this.#t}}itemAt(t,e){return j.at(this.context,t,e)}promised(t,e){return j.promised(this.context,t,e)}},Z=class n extends p{static of(t,e,o){return new n(t,l.derived(e,o))}constructor(t,e){super(t,e);}get level(){return this.loadedProperty("level")}set level(t){let e=`${this.path.label}.level`,o=Wt(t,e),r=this.#t();this.commandAnswering(e,()=>({op:"setListLevel",paragraph:r,level:o}),i=>{C(i,e);});}onLoad(t){if(!this.selection(t,["level"]).includes("level"))return;let e=`${this.path.label}.level`,o=this.#t();this.read(e,()=>({op:"getListLevel",paragraph:o}),r=>{this.setLoadedProperty("level",yt(r,e));});}#t(){this.requireAddressable();let t=this.path.address();return t.kind!=="handle"&&a({code:"InvalidObjectPath",target:this.path.label}),t.handle}};function Wt(n,t){return (!Number.isInteger(n)||n<0||n>ue)&&a({code:"InvalidArgument",target:t}),n}function me(n,t){return (!Number.isInteger(n)||n<=0)&&a({code:"InvalidArgument",target:t}),n}function E(n,t){let e=n.address();return t==="span"?(e.kind!=="span"&&a({code:"InvalidObjectPath",target:n.label}),{start:e.span.start,end:e.span.end}):(e.kind!=="handle"&&a({code:"InvalidObjectPath",target:n.label}),t==="body"?{body:e.handle}:{paragraph:e.handle})}function Y(n,t){return (typeof n!="string"||n.trim().length===0||n.length>255)&&a({code:"InvalidArgument",target:t}),n}var ge=["bold","italic","color","name","size"],I=class n extends p{#t;#e;static of(t,e,o,r){return new n(t,l.derived(e,o),r)}constructor(t,e,o){super(t,e),this.#t=o;}get bold(){return this.loadedProperty("bold")}set bold(t){this.#o("bold",zt(t,`${this.path.label}.bold`));}get italic(){return this.loadedProperty("italic")}set italic(t){this.#o("italic",zt(t,`${this.path.label}.italic`));}get color(){return this.loadedProperty("color")}set color(t){this.#o("color",Ut(t,`${this.path.label}.color`));}get name(){return this.loadedProperty("name")}set name(t){this.#o("name",Ut(t,`${this.path.label}.name`));}get size(){return this.loadedProperty("size")}set size(t){this.#o("size",fe(t,`${this.path.label}.size`));}onLoad(t){let e=this.selection(t,ge);if(e.length===0)return;let o=`${this.path.label}.font`;this.read(o,()=>({op:"getFont",span:this.#n()}),r=>{let i=Pt(r,o);for(let s of e)this.setLoadedProperty(s,i[s]);});}#o(t,e){if(this.requireAddressable(),this.#e){this.#e[t]=e;return}let o={[t]:e};this.#e=o;let r=`${this.path.label}.${t}`;this.commandAnswering(this.path.label,()=>(this.#e=void 0,{op:"setFont",span:this.#n(),font:o}),i=>{C(i,r);});}#n(){return this.requireAddressable(),E(this.path,this.#t)}};function zt(n,t){return typeof n!="boolean"&&a({code:"InvalidArgument",target:t}),n}function fe(n,t){return (typeof n!="number"||!Number.isFinite(n))&&a({code:"InvalidArgument",target:t}),n}function Ut(n,t){return (typeof n!="string"||n.length===0)&&a({code:"InvalidArgument",target:t}),n}var ye=16,R=class n extends p{#t;#e;#o;#n;static at(t,e,o){return o.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new n(t,l.of(e,o.handle),false)}static promised(t,e,o){return new n(t,l.pending(e),o)}constructor(t,e,o){super(t,e,{nullable:o});}hydrateAddress(t){t.kind==="handle"?this.path.resolveTo(t.handle):this.path.resolveNull();}hydrateNull(){this.path.resolveNull();}get text(){return this.loadedProperty("text")}get uniqueLocalId(){return this.loadedProperty("uniqueLocalId")}get style(){return this.loadedProperty("style")}set style(t){this.#r("style",Y(t,`${this.path.label}.style`));}get font(){return this.#t??=I.of(this.context,`${this.path.label}.font`,this.path,"paragraph"),this.#t}get alignment(){return this.loadedProperty("alignment")}set alignment(t){this.#r("alignment",xe(t,`${this.path.label}.alignment`));}get firstLineIndent(){return this.loadedProperty("firstLineIndent")}set firstLineIndent(t){this.#r("firstLineIndent",J(t,`${this.path.label}.firstLineIndent`));}get leftIndent(){return this.loadedProperty("leftIndent")}set leftIndent(t){this.#r("leftIndent",J(t,`${this.path.label}.leftIndent`));}get rightIndent(){return this.loadedProperty("rightIndent")}set rightIndent(t){this.#r("rightIndent",J(t,`${this.path.label}.rightIndent`));}get lineSpacing(){return this.loadedProperty("lineSpacing")}set lineSpacing(t){this.#r("lineSpacing",J(t,`${this.path.label}.lineSpacing`));}get spaceBefore(){return this.loadedProperty("spaceBefore")}set spaceBefore(t){this.#r("spaceBefore",J(t,`${this.path.label}.spaceBefore`));}get spaceAfter(){return this.loadedProperty("spaceAfter")}set spaceAfter(t){this.#r("spaceAfter",J(t,`${this.path.label}.spaceAfter`));}get list(){return this.#e??=this.#s(`${this.path.label}.list`),this.#e}get listItem(){return this.#o??=Z.of(this.context,`${this.path.label}.listItem`,this.path),this.#o}clear(){let t=this.#i();this.commandDiscarding("clear",()=>({op:"replaceSpan",span:{paragraph:t},text:""}));}delete(){let t=this.#i();this.command("delete",()=>({op:"deleteParagraph",paragraph:t}));}insertText(t,e){let o=`${this.path.label}.insertText`,r=A(t,o),i=Mt(e,o),s=this.#i(),d=m.promised(this.context,o,false);return this.commandAnswering(o,()=>i==="Replace"?{op:"replaceSpan",span:{paragraph:s},text:r}:{op:"insertText",at:{paragraph:s,at:i==="Start"?"start":"end"},text:r},c=>{d.hydrateAddress({kind:"span",span:x(c,o)});}),d}insertParagraph(t,e){let o=`${this.path.label}.insertParagraph`,r=A(t,o),i=Vt(e,o),s=this.#i(),d=n.promised(this.context,o,false);return this.commandAnswering(o,()=>({op:"insertParagraph",anchor:{paragraph:s},where:i==="Before"?"before":"after",text:r}),c=>{c.kind!=="handle"&&a({code:"GeneralException",target:o}),d.hydrateAddress({kind:"handle",handle:c.handle});}),d}split(t,e,o){let r=`${this.path.label}.split`,i=Ce(t,r),s=Qt(e,`${r}.trimDelimiters`),d=Qt(o,`${r}.trimSpacing`),c=this.#i(),g=S.answered(this.context,r,this.path);return this.commandAnswering(r,()=>({op:"splitParagraph",paragraph:c,delimiters:i,...s?{trimDelimiters:true}:{},...d?{trimSpacing:true}:{}}),L=>{g.fill(L,r);}),g}onLoad(t){let e=this.selection(t,["text","uniqueLocalId",...Gt]),o=this.#i();e.includes("text")&&this.loadTextInto("text",()=>({op:"getText",target:o,projection:this.revisionTextView()})),e.includes("uniqueLocalId")&&this.loadTextInto("uniqueLocalId",()=>({op:"getParagraphId",paragraph:o}));let r=Gt.filter(s=>e.includes(s));if(r.length===0)return;let i=`${this.path.label}.paragraphFormat`;this.read(i,()=>({op:"getParagraphFormat",paragraph:{paragraph:o}}),s=>{let d=kt(s,i);for(let c of r)this.setLoadedProperty(c,d[c]);});}#r(t,e){if(this.requireAddressable(),this.#n){this.#n[t]=e;return}let o={[t]:e};this.#n=o;let r=this.#i(),i=`${this.path.label}.${t}`;this.commandAnswering(`${this.path.label}.paragraphFormat`,()=>(this.#n=void 0,{op:"setParagraphFormat",paragraph:{paragraph:r},format:o}),s=>{C(s,i);});}#s(t){let e=this.#i(),o=j.promised(this.context,t,false);return this.read(t,()=>({op:"getParagraphList",paragraph:e}),r=>{o.hydrateAddress({kind:"handle",handle:f(r,t)});}),o}#i(){return this.requireAddressable(),this.path.handle()}},Gt=["style","alignment","firstLineIndent","leftIndent","rightIndent","lineSpacing","spaceBefore","spaceAfter"],be=["Left","Centered","Right","Justified"];function xe(n,t){return be.includes(n)||a({code:"InvalidArgument",target:t}),n}function J(n,t){return (typeof n!="number"||!Number.isFinite(n))&&a({code:"InvalidArgument",target:t}),n}function Ce(n,t){(!Array.isArray(n)||n.length===0||n.length>ye)&&a({code:"InvalidArgument",target:t});for(let e of n)(typeof e!="string"||e.length===0)&&a({code:"InvalidArgument",target:t});return [...n]}function Qt(n,t){return n!==void 0&&typeof n!="boolean"&&a({code:"InvalidArgument",target:t}),n===true}var v=class n extends Q{#t;static of(t,e,o){return new n(t,l.derived(e,o),null)}static overListing(t,e,o,r){return new n(t,l.derived(e,o),r)}constructor(t,e,o){super(t,e),this.#t=o;}getFirst(){return this.edge("first","getFirst",false)}getLast(){return this.edge("last","getLast",false)}getFirstOrNullObject(){return this.edge("first","getFirstOrNullObject",true)}getLastOrNullObject(){return this.edge("last","getLastOrNullObject",true)}listing(){if(this.#t)return this.#t();let t=this.path.address();return t.kind==="handle"?{op:"getParagraphs",body:t.handle}:{op:"getSpanParagraphs",span:t.span}}size(t,e){return P(t,e).length}addressAt(t,e,o){let r=P(t,e)[o];return r?{kind:"handle",handle:r}:void 0}itemAt(t,e){return R.at(this.context,t,e)}promised(t,e){return R.promised(this.context,t,e)}},S=class n extends Q{#t;static of(t,e,o,r){return new n(t,l.derived(e,o),r)}static answered(t,e,o){return new n(t,l.derived(e,o),null)}constructor(t,e,o){super(t,e),this.#t=o;}getFirst(){return this.edge("first","getFirst",false)}getLast(){return this.edge("last","getLast",false)}getFirstOrNullObject(){return this.edge("first","getFirstOrNullObject",true)}listing(){return this.#t?this.#t():null}size(t,e){return ft(t,e).length}addressAt(t,e,o){let r=ft(t,e)[o];return r?{kind:"span",span:r}:void 0}itemAt(t,e){return m.at(this.context,t,e)}promised(t,e){return m.promised(this.context,t,e)}};function Ae(n,t){return t<1||t>12?0:t===2?n%4===0&&n%100!==0||n%400===0?29:28:t===4||t===6||t===9||t===11?30:31}function Xt(n){if(n.length===0)return null;let t=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,9}))?(Z|[+-]\d{2}:\d{2})$/.exec(n.trim());if(!t)return null;let e=Number(t[1]),o=Number(t[2]),r=Number(t[3]),i=Ae(e,o);if(e===0||i===0||r<1||r>i)return null;let s=Number(t[4]),d=Number(t[5]),c=Number(t[6]);if(s>23||d>59||c>59)return null;let g=t[7],L=g===void 0?0:Number(g.padEnd(3,"0").slice(0,3));if(Number.isNaN(L))return null;let U=`${t[1]}-${t[2]}-${t[3]}T${t[4]}:${t[5]}:${t[6]}.${String(L).padStart(3,"0")}Z`,ht=Date.parse(U);if(Number.isNaN(ht))return null;let h=t[8];if(h==="Z")return new Date(ht);let B=Number(h.slice(1,3)),G=Number(h.slice(4,6));if(G>59||B>14||B===14&&G!==0)return null;let Rt=h[0]==="+"?1:-1,ut=new Date(ht-Rt*(B*36e5+G*6e4));return Number.isNaN(ut.getTime())?null:ut}var At=class extends p{hydrateAddress(t){t.kind==="handle"?this.path.resolveTo(t.handle):this.path.resolveNull();}hydrateNull(){this.path.resolveNull();}get authorName(){return this.loadedProperty("authorName")}get creationDate(){return this.loadedProperty("creationDate")}get id(){return this.loadedProperty("id")}get text(){return this.loadedProperty("text")}delete(){let t=this.commentHandle();this.command("delete",()=>({op:"deleteComment",comment:t}));}loadCommentFields(t,e){let o=this.selection(t,["authorName","creationDate","id","text",...e]),r=this.commentHandle();if(o.includes("authorName")&&this.loadTextInto("authorName",()=>({op:"getCommentAuthor",comment:r})),o.includes("text")&&this.loadTextInto("text",()=>({op:"getCommentText",comment:r})),o.includes("id")&&this.loadTextInto("id",()=>({op:"getCommentId",comment:r})),o.includes("creationDate")){let s=`${this.path.label}.creationDate`;this.read(s,()=>({op:"getCommentDate",comment:r}),d=>{this.setLoadedProperty("creationDate",Xt(b(d,s)));});}if(!o.includes("resolved"))return;let i=`${this.path.label}.resolved`;this.read(i,()=>({op:"getCommentResolved",comment:r}),s=>{this.setLoadedProperty("resolved",M(s,i));});}commentHandle(){return this.requireAddressable(),this.path.handle()}},V=class n extends At{static at(t,e,o){return o.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new n(t,l.of(e,o.handle),false)}static promised(t,e,o){return new n(t,l.pending(e),o)}constructor(t,e,o){super(t,e,{nullable:o});}onLoad(t){this.loadCommentFields(t,[]);}},ct=class n extends y{#t;static of(t,e,o,r){return new n(t,l.derived(e,o),r)}constructor(t,e,o){super(t,e),this.#t=o;}getFirst(){return this.edge("first","getFirst",false)}listing(){return this.#t()}itemAt(t,e){return V.at(this.context,t,e)}promised(t,e){return V.promised(this.context,t,e)}},N=class n extends At{#t;static at(t,e,o){return o.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new n(t,l.of(e,o.handle),false)}static promised(t,e,o){return new n(t,l.pending(e),o)}constructor(t,e,o){super(t,e,{nullable:o});}get resolved(){return this.loadedProperty("resolved")}set resolved(t){let e=`${this.path.label}.resolved`;typeof t!="boolean"&&a({code:"InvalidArgument",target:e});let o=this.commentHandle();this.commandAnswering(e,()=>({op:"setCommentResolved",comment:o,resolved:t}),r=>{C(r,e);});}get replies(){return this.#t??=ct.of(this.context,`${this.path.label}.replies`,this.path,()=>({op:"getCommentReplies",comment:this.commentHandle()})),this.#t}getRange(){let t=`${this.path.label}.getRange`,e=this.commentHandle(),o=m.promised(this.context,t,false);return this.read(t,()=>({op:"getCommentRange",comment:e}),r=>{o.hydrateAddress({kind:"span",span:x(r,t)});}),o}reply(t){let e=`${this.path.label}.reply`;(typeof t!="string"||t.length===0)&&a({code:"InvalidArgument",target:e});let o=this.internals.author;(typeof o!="string"||o.trim().length===0)&&a({code:"NotSupported",target:e});let r=this.commentHandle(),i=V.promised(this.context,e,false);return this.commandAnswering(e,()=>({op:"replyToComment",comment:r,text:t,author:o}),s=>{i.hydrateAddress({kind:"handle",handle:f(s,e)});}),i}onLoad(t){this.loadCommentFields(t,["resolved"]);}},q=class n extends y{#t;static of(t,e,o,r){return new n(t,l.derived(e,o),r)}constructor(t,e,o){super(t,e),this.#t=o;}getFirst(){return this.edge("first","getFirst",false)}listing(){return this.#t()}itemAt(t,e){return N.at(this.context,t,e)}promised(t,e){return N.promised(this.context,t,e)}},_=class n extends p{static at(t,e,o){return o.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new n(t,l.of(e,o.handle),false)}static promised(t,e,o){return new n(t,l.pending(e),o)}constructor(t,e,o){super(t,e,{nullable:o});}hydrateAddress(t){t.kind==="handle"?this.path.resolveTo(t.handle):this.path.resolveNull();}hydrateNull(){this.path.resolveNull();}get author(){return this.loadedProperty("author")}get date(){return this.loadedProperty("date")}get type(){return this.loadedProperty("type")}get range(){let t=`${this.path.label}.range`,e=this.#t(),o=m.promised(this.context,t,false);return this.read(t,()=>({op:"getRevisionRange",revision:e}),r=>{o.hydrateAddress({kind:"span",span:x(r,t)});}),o}accept(){let t=this.#t();this.command("accept",()=>({op:"acceptRevision",revision:t}));}reject(){let t=this.#t();this.command("reject",()=>({op:"rejectRevision",revision:t}));}onLoad(t){let e=this.selection(t,["author","date","type"]),o=this.#t();if(e.includes("author")&&this.loadTextInto("author",()=>({op:"getRevisionAuthor",revision:o})),e.includes("type")&&this.loadTextInto("type",()=>({op:"getRevisionType",revision:o})),!e.includes("date"))return;let r=`${this.path.label}.date`;this.read(r,()=>({op:"getRevisionDate",revision:o}),i=>{this.setLoadedProperty("date",Xt(b(i,r)));});}#t(){return this.requireAddressable(),this.path.handle()}},$=class n extends y{#t;static of(t,e,o,r){return new n(t,l.derived(e,o),r)}constructor(t,e,o){super(t,e),this.#t=o;}acceptAll(){let t=this.#t;this.commandOn("acceptAll",()=>({op:"acceptAllRevisions",body:t}));}rejectAll(){let t=this.#t;this.commandOn("rejectAll",()=>({op:"rejectAllRevisions",body:t}));}listing(){return {op:"getRevisions",body:this.#t}}itemAt(t,e){return _.at(this.context,t,e)}promised(t,e){return _.promised(this.context,t,e)}commandOn(t,e){let o=`${this.path.label}.${t}`;this.enqueue({sort:"write",label:o,plan:e,settle:r=>{C(r,o);}});}};var ve=new Set(["matchCase","matchWholeWord","ignorePunct","ignoreSpace","matchWildcards"]);function vt(n,t){if(n===void 0)return;typeof n!="object"&&a({code:"InvalidArgument",target:t});for(let[o,r]of Object.entries(n))ve.has(o)||a({code:"InvalidArgument",target:`${t}.${o}`}),r!==void 0&&typeof r!="boolean"&&a({code:"InvalidArgument",target:`${t}.${o}`});let e={...n.matchCase===void 0?{}:{matchCase:n.matchCase},...n.matchWholeWord===void 0?{}:{matchWholeWord:n.matchWholeWord},...n.ignorePunct===void 0?{}:{ignorePunct:n.ignorePunct},...n.ignoreSpace===void 0?{}:{ignoreSpace:n.ignoreSpace},...n.matchWildcards===void 0?{}:{matchWildcards:n.matchWildcards}};return Object.keys(e).length===0?void 0:e}var m=class n extends p{#t;#e;#o;static at(t,e,o){return o.kind!=="span"&&a({code:"InvalidObjectPath",target:e}),new n(t,l.ofSpan(e,o.span),false)}static promised(t,e,o){return new n(t,l.pending(e),o)}constructor(t,e,o){super(t,e,{nullable:o});}hydrateAddress(t){t.kind==="span"?this.path.resolveToSpan(t.span):this.path.resolveNull();}hydrateNull(){this.path.resolveNull();}get text(){return this.loadedProperty("text")}get font(){return this.#e??=I.of(this.context,`${this.path.label}.font`,this.path,"span"),this.#e}get paragraphs(){return this.#t??=v.of(this.context,`${this.path.label}.paragraphs`,this.path),this.#t}get style(){return this.loadedProperty("style")}set style(t){let e=`${this.path.label}.style`,o=Y(t,e);this.requireAddressable(),this.command("style",()=>({op:"setStyle",span:E(this.path,"span"),name:o}));}get hyperlink(){return this.loadedProperty("hyperlink")}set hyperlink(t){let e=`${this.path.label}.hyperlink`;(typeof t!="string"||t.length>2048)&&a({code:"InvalidArgument",target:e});let o=this.#n();this.command("hyperlink",()=>({op:"setHyperlink",span:o,target:t}));}get bookmarks(){let t=this.#n();return this.#o??=D.of(this.context,`${this.path.label}.bookmarks`,this.path,()=>({op:"getBookmarks",scope:{start:t.start,end:t.end}})),this.#o}search(t,e){let o=`${this.path.label}.search`;typeof t!="string"&&a({code:"InvalidArgument",target:o});let r=vt(e,o),i=this.#n();return S.of(this.context,o,this.path,()=>({op:"search",scope:i,text:t,options:{...r??{},projection:this.revisionTextView()}}))}insertText(t,e){let o=`${this.path.label}.insertText`,r=A(t,o),i=St(e,o),s=this.#n(),d=n.promised(this.context,o,false);return this.commandAnswering(o,()=>i==="Replace"?{op:"replaceSpan",span:s,text:r}:{op:"insertText",at:i==="Start"||i==="Before"?s.start:s.end,text:r},c=>{d.hydrateAddress({kind:"span",span:x(c,o)});}),d}delete(){let t=this.#n();this.commandDiscarding("delete",()=>({op:"replaceSpan",span:t,text:""}));}clear(){let t=this.#n();this.commandDiscarding("clear",()=>({op:"replaceSpan",span:t,text:""}));}insertComment(t){let e=`${this.path.label}.insertComment`;(typeof t!="string"||t.length===0)&&a({code:"InvalidArgument",target:e});let o=this.internals.author;(typeof o!="string"||o.trim().length===0)&&a({code:"NotSupported",target:e});let r=this.#n(),i=N.promised(this.context,e,false);return this.commandAnswering(e,()=>({op:"insertComment",span:r,text:t,author:o}),s=>{s.kind!=="handle"&&a({code:"GeneralException",target:e}),i.hydrateAddress(s);}),i}insertParagraph(t,e){let o=`${this.path.label}.insertParagraph`,r=A(t,o),i=St(e,o);i!=="Before"&&i!=="After"&&a({code:"InvalidArgument",target:o});let s=this.#n(),d=i==="Before"?s.start.paragraph:s.end.paragraph,c=R.promised(this.context,o,false);return this.commandAnswering(o,()=>({op:"insertParagraph",anchor:{paragraph:d},where:i==="Before"?"before":"after",text:r}),g=>{g.kind!=="handle"&&a({code:"GeneralException",target:o}),c.hydrateAddress({kind:"handle",handle:g.handle});}),c}select(t){let e=`${this.path.label}.select`,o=Ct(t,e);this.requireAddressable(),this.internals.capabilities.selection||a({code:"NotSupported",target:e});let r=this.#n();this.command("select",()=>({op:"selectSpan",span:r,mode:o==="Select"?"select":o==="Start"?"start":"end"}));}onLoad(t){let e=this.selection(t,["text","style","hyperlink"]);if(e.includes("hyperlink")){let r=this.#n();this.loadTextInto("hyperlink",()=>({op:"getHyperlink",span:r}));}if(e.includes("text")){let r=this.#n(),i=`${this.path.label}.text`;this.read(i,()=>({op:"getSpanText",span:r,projection:this.revisionTextView()}),s=>{this.setLoadedProperty("text",b(s,i));});}if(!e.includes("style"))return;let o=`${this.path.label}.style`;this.requireAddressable(),this.read(o,()=>({op:"getStyle",span:E(this.path,"span")}),r=>{this.setLoadedProperty("style",at(r,o));});}#n(){return this.requireAddressable(),this.path.span()}};var tt=class n extends p{#t;static at(t,e,o){return o.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new n(t,l.of(e,o.handle),false)}static promised(t,e,o){return new n(t,l.pending(e),o)}constructor(t,e,o){super(t,e,{nullable:o});}hydrateAddress(t){t.kind==="handle"?this.path.resolveTo(t.handle):this.path.resolveNull();}hydrateNull(){this.path.resolveNull();}get name(){return this.loadedProperty("name")}get range(){return this.#t??=this.#e(`${this.path.label}.range`),this.#t}select(t){let e=`${this.path.label}.select`,o=Ct(t,e);this.requireAddressable(),this.internals.capabilities.selection||a({code:"NotSupported",target:e});let r=this.#o();this.command("select",()=>({op:"selectBookmark",bookmark:r,mode:o==="Select"?"select":o==="Start"?"start":"end"}));}onLoad(t){if(!this.selection(t,["name"]).includes("name"))return;let e=`${this.path.label}.name`,o=this.#o();this.read(e,()=>({op:"getBookmarkName",bookmark:o}),r=>{this.setLoadedProperty("name",b(r,e));});}#e(t){let e=this.#o(),o=m.promised(this.context,t,false);return this.read(t,()=>({op:"getBookmarkRange",bookmark:e}),r=>{o.hydrateAddress({kind:"span",span:x(r,t)});}),o}#o(){return this.requireAddressable(),this.path.handle()}},D=class n extends y{#t;static of(t,e,o,r){return new n(t,l.derived(e,o),r)}constructor(t,e,o){super(t,e),this.#t=o;}listing(){return this.#t()}itemAt(t,e){return tt.at(this.context,t,e)}promised(t,e){return tt.promised(this.context,t,e)}};var Zt=4096,W=class n extends p{#t=new Map;#e;#o;static at(t,e,o){return o.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new n(t,l.of(e,o.handle),false)}static promised(t,e,o){return new n(t,l.pending(e),o)}constructor(t,e,o){super(t,e,{nullable:o});}hydrateAddress(t){t.kind==="handle"?this.path.resolveTo(t.handle):this.path.resolveNull();}hydrateNull(){this.path.resolveNull();}get id(){return this.loadedProperty("id")}get tag(){return this.loadedProperty("tag")}set tag(t){this.#r("tag",{tag:Lt(t,`${this.path.label}.tag`)});}get title(){return this.loadedProperty("title")}set title(t){this.#r("title",{title:Lt(t,`${this.path.label}.title`)});}get subtype(){return this.loadedProperty("subtype")}get isBound(){return this.loadedProperty("isBound")}get cannotDelete(){let t=this.loadedProperty("lock");return t==="sdtLocked"||t==="sdtContentLocked"}set cannotDelete(t){this.#s(t,this.cannotEdit,`${this.path.label}.cannotDelete`);}get cannotEdit(){let t=this.loadedProperty("lock");return t==="contentLocked"||t==="sdtContentLocked"}set cannotEdit(t){this.#s(this.cannotDelete,t,`${this.path.label}.cannotEdit`);}get placeholderShown(){return this.loadedProperty("placeholderShown")}get temporary(){return this.loadedProperty("temporary")}get text(){return this.loadedProperty("text")}get paragraphs(){return this.#e??=v.overListing(this.context,`${this.path.label}.paragraphs`,this.path,()=>({op:"getContentControlParagraphs",contentControl:this.#i()})),this.#e}get contentControls(){return this.#o??=w.of(this.context,`${this.path.label}.contentControls`,this.path,{contentControl:this.#i()}),this.#o}getRange(t){let e=`${this.path.label}.getRange`,o=Re(t??"Whole",e),r=this.#t.get(o);if(r)return r;let i=this.#n(e,o);return this.#t.set(o,i),i}setValue(t){let e=`${this.path.label}.setValue`,o=Oe(t,e),r=this.#i();this.command("setValue",()=>({op:"setContentControlValue",contentControl:r,value:o}));}insertText(t,e){let o=`${this.path.label}.insertText`,r=A(t,o),i=e==="Replace"?"replace":e==="Start"?"start":e==="End"?"end":a({code:"InvalidArgument",target:o}),s=this.#i(),d=m.promised(this.context,o,false);return this.commandAnswering(o,()=>({op:"insertContentControlText",contentControl:s,text:r,at:i}),c=>{d.hydrateAddress({kind:"span",span:x(c,o)});}),d}delete(t){let e=`${this.path.label}.delete`;typeof t!="boolean"&&a({code:"InvalidArgument",target:e});let o=this.#i();this.command("delete",()=>({op:"deleteContentControl",contentControl:o,keepContent:t}));}onLoad(t){let e=this.selection(t,["id","tag","title","subtype","isBound","text","cannotDelete","cannotEdit","placeholderShown","temporary"]),o=this.#i();if(e.includes("id")&&this.loadTextInto("id",()=>({op:"getContentControlFileId",contentControl:o})),e.includes("tag")&&this.loadTextInto("tag",()=>({op:"getContentControlTag",contentControl:o})),e.includes("title")&&this.loadTextInto("title",()=>({op:"getContentControlTitle",contentControl:o})),e.includes("subtype")&&this.loadTextInto("subtype",()=>({op:"getContentControlSubtype",contentControl:o})),e.includes("isBound")){let i=`${this.path.label}.isBound`;this.read(i,()=>({op:"getContentControlIsBound",contentControl:o}),s=>{this.setLoadedProperty("isBound",M(s,i));});}if(e.includes("text")&&this.loadTextInto("text",()=>({op:"getContentControlText",contentControl:o,projection:this.revisionTextView()})),e.includes("cannotDelete")||e.includes("cannotEdit")){let i=`${this.path.label}.lock`;this.read(i,()=>({op:"getContentControlLock",contentControl:o}),s=>{this.setLoadedProperty("lock",b(s,i));});}if(e.includes("placeholderShown")){let i=`${this.path.label}.placeholderShown`;this.read(i,()=>({op:"getContentControlPlaceholderShown",contentControl:o}),s=>{this.setLoadedProperty("placeholderShown",M(s,i));});}if(!e.includes("temporary"))return;let r=`${this.path.label}.temporary`;this.read(r,()=>({op:"getContentControlTemporary",contentControl:o}),i=>{this.setLoadedProperty("temporary",M(i,r));});}#n(t,e){let o=this.#i(),r=m.promised(this.context,t,false);return this.read(t,()=>({op:"getContentControlRange",contentControl:o,location:e}),i=>{r.hydrateAddress({kind:"span",span:x(i,t)});}),r}#r(t,e){let o=this.#i();this.command(t,()=>({op:"setContentControlProperties",contentControl:o,...e}));}#s(t,e,o){(typeof t!="boolean"||typeof e!="boolean")&&a({code:"InvalidArgument",target:o});let r=t&&e?"sdtContentLocked":t?"sdtLocked":e?"contentLocked":"unlocked",i=this.#i();this.command(o,()=>({op:"setContentControlProperties",contentControl:i,lock:r}));}#i(){return this.requireAddressable(),this.path.handle()}},w=class n extends y{#t;#e;static of(t,e,o,r){return new n(t,l.derived(e,o),r,()=>({op:"getContentControls",scope:r}))}constructor(t,e,o,r){super(t,e),this.#t=o,this.#e=r;}getFirst(){return this.edge("first","getFirst",false)}getFirstOrNullObject(){return this.edge("first","getFirstOrNullObject",true)}getById(t){let e=`${this.path.label}.getById`;Number.isInteger(t)||a({code:"InvalidArgument",target:e});let o=this.#t,r=W.promised(this.context,e,false);return this.enqueue({sort:"read",label:e,plan:()=>({op:"getContentControlById",scope:o,id:t}),settle:i=>{r.hydrateAddress({kind:"handle",handle:f(i,e)});}}),r}getByTag(t){let e=`${this.path.label}.getByTag`,o=Kt(t,e),r=this.#t;return new n(this.context,l.derived(e,this.path),r,()=>({op:"getContentControlsByTag",scope:r,tag:o}))}getByTitle(t){let e=`${this.path.label}.getByTitle`,o=Kt(t,e),r=this.#t;return new n(this.context,l.derived(e,this.path),r,()=>({op:"getContentControlsByTitle",scope:r,title:o}))}listing(){return this.#e()}itemAt(t,e){return W.at(this.context,t,e)}promised(t,e){return W.promised(this.context,t,e)}};function Lt(n,t){return (typeof n!="string"||n.length>Zt)&&a({code:"InvalidArgument",target:t}),n}function Kt(n,t){let e=Lt(n,t);return e.length===0&&a({code:"InvalidArgument",target:t}),e}function Re(n,t){switch(n){case "Whole":return "whole";case "Content":return "content";case "Start":return "start";case "End":return "end";case "Before":return "before";case "After":return "after";default:return a({code:"InvalidArgument",target:t})}}function Oe(n,t){(typeof n!="object"||n===null)&&a({code:"InvalidArgument",target:t});let e=n;if(e.kind==="text"||e.kind==="listItem"){let o=e.kind==="text"?e.text:e.value;return (typeof o!="string"||o.length>Zt)&&a({code:"InvalidArgument",target:t}),e.kind==="text"?{kind:"text",text:o}:{kind:"listItem",value:o}}if(e.kind==="checkbox")return typeof e.checked!="boolean"&&a({code:"InvalidArgument",target:t}),{kind:"checkbox",checked:e.checked};if(e.kind==="date")return (typeof e.iso!="string"||e.iso.length>64)&&a({code:"InvalidArgument",target:t}),{kind:"date",iso:e.iso};a({code:"InvalidArgument",target:t});}var k=class n extends p{#t;#e;#o;#n;#r;#s;static main(t,e){return new n(t,l.of(e,H(t).roots().body))}static promisedStory(t,e){return new n(t,l.pending(e))}hydrateAddress(t){t.kind==="handle"?this.path.resolveTo(t.handle):this.path.resolveNull();}constructor(t,e){super(t,e);}get text(){return this.loadedProperty("text")}get paragraphs(){return this.#t??=this.paragraphsUnder(`${this.path.label}.paragraphs`),this.#t}get bookmarks(){let t=this.#a();return this.#e??=D.of(this.context,`${this.path.label}.bookmarks`,this.path,()=>({op:"getBookmarks",scope:{body:t}})),this.#e}get font(){return this.#o??=I.of(this.context,`${this.path.label}.font`,this.path,"body"),this.#o}paragraphsUnder(t){return v.of(this.context,t,this.path)}get style(){return this.loadedProperty("style")}set style(t){let e=`${this.path.label}.style`,o=Y(t,e);this.requireAddressable(),this.command("style",()=>({op:"setStyle",span:E(this.path,"body"),name:o}));}get lists(){return this.#n??=K.of(this.context,`${this.path.label}.lists`,this.path,this.#a()),this.#n}get contentControls(){return this.#r??=w.of(this.context,`${this.path.label}.contentControls`,this.path,{body:this.#a()}),this.#r}getComments(){let t=`${this.path.label}.getComments`,e=this.#a();return q.of(this.context,t,this.path,()=>({op:"getComments",scope:{body:e}}))}get revisions(){return this.#s??=$.of(this.context,`${this.path.label}.revisions`,this.path,this.#a()),this.#s}search(t,e){let o=`${this.path.label}.search`;typeof t!="string"&&a({code:"InvalidArgument",target:o});let r=vt(e,o),i=this.#a();return S.of(this.context,o,this.path,()=>({op:"search",scope:{body:i},text:t,options:{...r??{},projection:this.revisionTextView()}}))}clear(){let t=this.#a();this.commandDiscarding("clear",()=>({op:"replaceSpan",span:{body:t},text:""}));}insertText(t,e){let o=`${this.path.label}.insertText`,r=A(t,o),i=Ft(e,o),s=this.#a(),d=m.promised(this.context,o,false);return this.commandAnswering(o,()=>i==="Replace"?{op:"replaceSpan",span:{body:s},text:r}:{op:"insertText",at:{body:s,at:i==="Start"?"start":"end"},text:r},c=>{d.hydrateAddress({kind:"span",span:x(c,o)});}),d}insertParagraph(t,e){let o=`${this.path.label}.insertParagraph`,r=A(t,o),i=Ht(e,o),s=this.#a(),d=R.promised(this.context,o,false);return this.commandAnswering(o,()=>({op:"insertParagraph",anchor:{body:s,at:i==="Start"?"first":"last"},where:i==="Start"?"before":"after",text:r}),c=>{c.kind!=="handle"&&a({code:"GeneralException",target:o}),d.hydrateAddress({kind:"handle",handle:c.handle});}),d}onLoad(t){let e=this.selection(t,["text","style"]);if(e.includes("text")){let o=this.#a();this.loadTextInto("text",()=>({op:"getText",target:o,projection:this.revisionTextView()}));}e.includes("style")&&this.#i();}#i(){let t=`${this.path.label}.style`;this.requireAddressable(),this.read(t,()=>({op:"getStyle",span:E(this.path,"body")}),e=>{this.setLoadedProperty("style",at(e,t));});}#a(){return this.requireAddressable(),this.path.handle()}};function Pe(n){return n==="endnote"?"Endnote":"Footnote"}var et=class n extends p{#t;static at(t,e,o){return o.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new n(t,l.of(e,o.handle),false)}static promised(t,e,o){return new n(t,l.pending(e),o)}constructor(t,e,o){super(t,e,{nullable:o});}hydrateAddress(t){t.kind==="handle"?this.path.resolveTo(t.handle):this.path.resolveNull();}hydrateNull(){this.path.resolveNull();}get type(){return this.loadedProperty("type")}get text(){return this.loadedProperty("text")}get body(){if(this.#t)return this.#t;let t=`${this.path.label}.body`,e=this.#e(),o=k.promisedStory(this.context,t);return this.read(t,()=>({op:"getNoteBody",note:e}),r=>{o.hydrateAddress({kind:"handle",handle:f(r,t)});}),this.#t=o,o}delete(){let t=this.#e();this.command("delete",()=>({op:"deleteNote",note:t}));}getNext(){let t=`${this.path.label}.getNext`,e=this.#e(),o=n.promised(this.context,t,false),r=this.internals.roots().document,i=`${t}.type`,s="footnote";return this.read(i,()=>({op:"getNoteKind",note:e}),d=>{s=b(d,i)==="endnote"?"endnote":"footnote";}),this.read(t,()=>({op:"getNotes",document:r,noteKind:s}),d=>{let c=P(d,t),g=c.findIndex(U=>U.ref===e.ref),L=g<0?void 0:c[g+1];L||a({code:"ItemNotFound",target:t}),o.hydrateAddress({kind:"handle",handle:L});}),o}onLoad(t){let e=this.selection(t,["text","type"]);if(e.includes("text")){let o=this.#e();this.loadTextInto("text",()=>({op:"getNoteText",note:o,projection:this.revisionTextView()}));}if(e.includes("type")){let o=`${this.path.label}.type`,r=this.#e();this.read(o,()=>({op:"getNoteKind",note:r}),i=>{this.setLoadedProperty("type",Pe(b(i,o)));});}}#e(){return this.requireAddressable(),this.path.handle()}},z=class n extends y{#t;static of(t,e,o,r){return new n(t,l.derived(e,o),r)}constructor(t,e,o){super(t,e),this.#t=o;}getFirst(){return this.edge("first","getFirst",false)}listing(){return this.#t()}itemAt(t,e){return et.at(this.context,t,e)}promised(t,e){return et.promised(this.context,t,e)}};var ke=Object.freeze({Primary:"default",FirstPage:"first",EvenPages:"even"}),Ie=["pageWidth","pageHeight","orientation","topMargin","rightMargin","bottomMargin","leftMargin"],pt=class n extends p{#t;static of(t,e,o){return new n(t,l.derived(e,o))}constructor(t,e){super(t,e);}get pageWidth(){return this.loadedProperty("pageWidth")}set pageWidth(t){this.#e("pageWidth",ot(t,`${this.path.label}.pageWidth`));}get pageHeight(){return this.loadedProperty("pageHeight")}set pageHeight(t){this.#e("pageHeight",ot(t,`${this.path.label}.pageHeight`));}get orientation(){return this.loadedProperty("orientation")}set orientation(t){let e=`${this.path.label}.orientation`;t!=="Portrait"&&t!=="Landscape"&&a({code:"InvalidArgument",target:e}),this.#e("orientation",t==="Portrait"?"portrait":"landscape");}get topMargin(){return this.loadedProperty("topMargin")}set topMargin(t){this.#e("topMargin",ot(t,`${this.path.label}.topMargin`));}get bottomMargin(){return this.loadedProperty("bottomMargin")}set bottomMargin(t){this.#e("bottomMargin",ot(t,`${this.path.label}.bottomMargin`));}get leftMargin(){return this.loadedProperty("leftMargin")}set leftMargin(t){this.#e("leftMargin",ot(t,`${this.path.label}.leftMargin`));}get rightMargin(){return this.loadedProperty("rightMargin")}set rightMargin(t){this.#e("rightMargin",ot(t,`${this.path.label}.rightMargin`));}onLoad(t){let e=this.selection(t,Ie);if(e.length===0)return;let o=`${this.path.label}.pageSetup`,r=this.#o();this.read(o,()=>({op:"getPageSetup",section:r}),i=>{let s=It(i,o);for(let d of e)this.setLoadedProperty(d,d==="orientation"?s.orientation==="landscape"?"Landscape":"Portrait":s[d]);});}#e(t,e){if(this.requireAddressable(),this.#t){this.#t[t]=e;return}let o={[t]:e};this.#t=o;let r=this.#o(),i=`${this.path.label}.${t}`;this.commandAnswering(`${this.path.label}.pageSetup`,()=>(this.#t=void 0,{op:"setPageSetup",section:r,setup:o}),s=>{C(s,i);});}#o(){this.requireAddressable();let t=this.path.address();return t.kind!=="handle"&&a({code:"InvalidObjectPath",target:this.path.label}),t.handle}},nt=class n extends p{#t;#e;static at(t,e,o){return o.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new n(t,l.of(e,o.handle),false)}static promised(t,e,o){return new n(t,l.pending(e),o)}constructor(t,e,o){super(t,e,{nullable:o});}hydrateAddress(t){t.kind==="handle"?this.path.resolveTo(t.handle):this.path.resolveNull();}hydrateNull(){this.path.resolveNull();}get body(){return this.#e??=k.main(this.context,`${this.path.label}.body`),this.#e}get pageSetup(){return this.#t??=pt.of(this.context,`${this.path.label}.pageSetup`,this.path),this.#t}getHeader(t){return this.#o("header",t,"getHeader")}getFooter(t){return this.#o("footer",t,"getFooter")}getNext(){let t=`${this.path.label}.getNext`,e=this.#n(),o=n.promised(this.context,t,false),r=this.internals.roots().document;return this.read(t,()=>({op:"getSections",document:r}),i=>{let s=P(i,t),d=s.findIndex(g=>g.ref===e.ref),c=d<0?void 0:s[d+1];c||a({code:"ItemNotFound",target:t}),o.hydrateAddress({kind:"handle",handle:c});}),o}onLoad(t){this.selection(t,[]);}#o(t,e,o){let r=`${this.path.label}.${o}`,i=ke[e];i===void 0&&a({code:"InvalidArgument",target:r});let s=this.#n(),d=k.promisedStory(this.context,r);return this.read(r,()=>({op:"getFurniture",section:s,kind:t,variant:i}),c=>{d.hydrateAddress({kind:"handle",handle:f(c,r)});}),d}#n(){return this.requireAddressable(),this.path.handle()}},rt=class n extends y{#t;static of(t,e,o,r){return new n(t,l.derived(e,o),r)}constructor(t,e,o){super(t,e),this.#t=o;}getFirst(){return this.edge("first","getFirst",false)}listing(){return this.#t()}itemAt(t,e){return nt.at(this.context,t,e)}promised(t,e){return nt.promised(this.context,t,e)}};function ot(n,t){return (typeof n!="number"||!Number.isFinite(n)||n<0)&&a({code:"InvalidArgument",target:t}),n}var it=class n extends p{#t;#e;#o;#n;#r;#s;#i;#a;static open(t){return new n(t)}constructor(t){super(t,l.of("document",H(t).roots().document));}get changeTrackingMode(){return this.loadedProperty("changeTrackingMode")}set changeTrackingMode(t){["Off","TrackAll","TrackMineOnly"].includes(t)||a({code:"InvalidArgument",target:"document.changeTrackingMode"});let e=this.internals.author;this.commandAnswering("document.changeTrackingMode",()=>({op:"setChangeTrackingMode",mode:t,...e===void 0?{}:{author:e}}),()=>this.setLoadedProperty("changeTrackingMode",t));}get body(){return this.#t??=k.main(this.context,"document.body"),this.#t}get paragraphs(){return this.#e??=this.body.paragraphsUnder("document.paragraphs"),this.#e}get sections(){let t=this.path.handle();return this.#o??=rt.of(this.context,"document.sections",this.path,()=>({op:"getSections",document:t})),this.#o}get contentControls(){return this.#s??=w.of(this.context,"document.contentControls",this.path,{body:this.internals.roots().body}),this.#s}get comments(){return this.#n??=q.of(this.context,"document.comments",this.path,()=>({op:"getComments",scope:{body:this.internals.roots().body}})),this.#n}get revisions(){return this.#r??=$.of(this.context,"document.revisions",this.path,this.internals.roots().body),this.#r}get footnotes(){let t=this.path.handle();return this.#i??=z.of(this.context,"document.footnotes",this.path,()=>({op:"getNotes",document:t,noteKind:"footnote"})),this.#i}get endnotes(){let t=this.path.handle();return this.#a??=z.of(this.context,"document.endnotes",this.path,()=>({op:"getNotes",document:t,noteKind:"endnote"})),this.#a}onLoad(t){if(t.select.length===0)return;this.selection(t,["changeTrackingMode"]).includes("changeTrackingMode")&&this.loadTextInto("changeTrackingMode",()=>({op:"getChangeTrackingMode"}));}};function Jt(n){let t=n.host,e=Object.freeze({...t.capabilities,save:n.save&&t.capabilities.save}),o=typeof n.author=="string"&&n.author.trim().length>0?n.author:void 0,r=n.revisionTextView??"allMarkup";r!=="allMarkup"&&r!=="original"&&a({code:"InvalidArgument",target:"revisionTextView"});let i=false,s=null,d=h=>{i&&a({code:"RuntimeDisposed",...h===void 0?{}:{target:h}});},c=()=>{if(s)return s;d("document");let h=Yt(t.execute({operations:[{op:"getDocument"}]}),"document"),B=Yt(t.execute({operations:[{op:"getBody",document:h}]}),"document.body");return s={document:h,body:B},s},g={host:t,capabilities:e,...o===void 0?{}:{author:o},revisionTextView:r,id:{},roots:c,assertLive:d,openDocument:h=>it.open(h)};try{c();}catch{s=null;}async function L(h,B){d();let G=typeof h=="function"?h:B,Rt=typeof h=="function"?[]:Array.isArray(h)?h:[h];typeof G!="function"&&a({code:"InvalidArgument",target:"run"});let{context:ut,adopt:te,finish:ee}=dt.begin(g);try{return te(Rt),await G(ut)}finally{ee();}}let U={capabilities:e,run:L,dispose(){i||(i=true,s=null,t.dispose());}};return n.save?{...U,async save(){d("save"),e.save||a({code:"NotSupported",target:"save"});let h=t.save();if(!h.ok)throw bt(h.error,{target:"save"});return h.bytes}}:U}function Yt(n,t){let e=n.results[0];if(e?.status==="error")throw bt(e.error,{target:t});if(e?.status!=="ok")throw new u({code:"GeneralException",target:t});return f(e.value,t)}function Le(n){if(n){for(let t of n)if(t.collaboration)return t.collaboration}}function je(n){let t=[n?.zip?.maxEntries,n?.zip?.maxTotalBytes,n?.xml?.maxBytes,n?.xml?.maxElements,n?.maxXmlParts,n?.maxRelationships],e=n?.zip?.maxRatio;(t.some(o=>o!==void 0&&(!Number.isInteger(o)||o<0))||e!==void 0&&(!Number.isFinite(e)||e<0))&&a({code:"InvalidArgument",target:"createServer"});}async function jt(n,t={}){je(t.limits);let e=Le(t.modules),o=createServerAutomationHost(n,{...t.limits===void 0?{}:{limits:t.limits},...e===void 0?{}:{collaborationModel:e}});if(!o.ok){let r={"too-many-entries":"zip.maxEntries","too-large":"xml.maxBytes","too-many-elements":"xml.maxElements","too-deep":"xml.maxDepth","too-many-xml-parts":"maxXmlParts","too-many-relationships":"maxRelationships"},i=o.limit??r[o.reason];a({code:i===void 0?"InvalidArgument":"ResourceLimitExceeded",target:"createServer",...i===void 0?{}:{limit:i}});}return Jt({host:o.host,save:true,...t.author===void 0?{}:{author:t.author},...t.revisionTextView===void 0?{}:{revisionTextView:t.revisionTextView}})}function _t(n,t,e={}){return jt(n,{...e,modules:[...e.modules??[],{id:"collaboration",collaboration:{session:t}}]})}var Er=Object.freeze({createServer:jt,createCollaborative:_t});export{k as Body,tt as Bookmark,D as BookmarkCollection,T as ClientObject,Ot as ClientResult,N as Comment,q as CommentCollection,V as CommentReply,ct as CommentReplyCollection,W as ContentControl,w as ContentControlCollection,it as Document,Er as DocxEditor,u as DocxEditorError,I as Font,j as List,K as ListCollection,Z as ListItem,et as NoteItem,z as NoteItemCollection,pt as PageSetup,R as Paragraph,v as ParagraphCollection,m as Range,S as RangeCollection,dt as RequestContext,_ as Revision,$ as RevisionCollection,nt as Section,rt as SectionCollection,st as TrackedObjects,oe as isDocxEditorError};
@@ -650,6 +650,13 @@ declare class Range extends ModelObject implements PromisedItem {
650
650
  search(searchText: string, options?: SearchOptions): RangeCollection;
651
651
  /**
652
652
  * Write text at or over this range. Answers the range the written text occupies.
653
+ * Await `context.sync()` before loading or addressing that returned range.
654
+ *
655
+ * With server `document.changeTrackingMode = 'TrackMineOnly'`, this creates a tracked text
656
+ * edit attributed to the runtime author. Tracked edits must stay within one paragraph and
657
+ * cannot touch pending revisions. Structural and formatting tracking are not supported.
658
+ * Empty text with `Replace` deletes the range; empty text at an insertion point is a no-op.
659
+ * Agent tools that intend a replacement should validate non-empty model output first.
653
660
  *
654
661
  * `Before`/`Start` and `After`/`End` land at the SAME position here, and the difference Word
655
662
  * draws between them — whether the new text becomes part of this range — has no meaning for a
@@ -657,6 +664,10 @@ declare class Range extends ModelObject implements PromisedItem {
657
664
  * gets back is a range naming the text that was written, in every case.
658
665
  */
659
666
  insertText(text: string, insertLocation: 'Replace' | 'Start' | 'End' | 'Before' | 'After'): Range;
667
+ /** Delete this range's content. TrackMineOnly preserves inline text as a pending deletion. */
668
+ delete(): void;
669
+ /** Clear this range's content, preserving the surrounding structure. */
670
+ clear(): void;
660
671
  /**
661
672
  * Create a top-level comment anchored to exactly this range.
662
673
  *
@@ -1250,6 +1261,8 @@ declare class SectionCollection extends HandleCollection<Section> {
1250
1261
  protected promised(label: string, nullable: boolean): Section & PromisedItem;
1251
1262
  }
1252
1263
 
1264
+ /** Office.js tracking mode names. TrackAll is recognized but currently refused. @public */
1265
+ type ChangeTrackingMode = 'Off' | 'TrackAll' | 'TrackMineOnly';
1253
1266
  /**
1254
1267
  * The document: the root every other object is reached from.
1255
1268
  *
@@ -1284,6 +1297,15 @@ declare class Document extends ModelObject {
1284
1297
  /** @internal One per request context; the context memoizes it. */
1285
1298
  static open(context: RequestContext): Document;
1286
1299
  private constructor();
1300
+ /**
1301
+ * Tracking for this server host. Load 'changeTrackingMode' explicitly before reading.
1302
+ * Document.load() keeps an empty default property set across hosts. Assignments take effect at sync.
1303
+ * TrackMineOnly tracks this runtime's inline text edits using its configured author.
1304
+ * TrackAll and browser-host mode control are not supported. Unsupported tracked mutation
1305
+ * kinds refuse; the setting is session-local and is not saved as a document-wide policy.
1306
+ */
1307
+ get changeTrackingMode(): ChangeTrackingMode;
1308
+ set changeTrackingMode(mode: ChangeTrackingMode);
1287
1309
  /**
1288
1310
  * The main story.
1289
1311
  *
@@ -1813,6 +1835,8 @@ type DocxEditorErrorCode =
1813
1835
  | 'ObjectInUse'
1814
1836
  /** An argument or load option this API does not accept. */
1815
1837
  | 'InvalidArgument'
1838
+ /** Opening the document exceeded a bounded reader resource limit. */
1839
+ | 'ResourceLimitExceeded'
1816
1840
  /** The collection has no such item — `getFirst()` on an empty one. */
1817
1841
  | 'ItemNotFound'
1818
1842
  /** The host cannot do this at all — a capability it reports false. */
@@ -1851,6 +1875,8 @@ type DocxEditorErrorCode =
1851
1875
  interface DocxEditorErrorInit {
1852
1876
  /** Which refusal this is. The stable thing to branch on. */
1853
1877
  readonly code: DocxEditorErrorCode;
1878
+ /** The resource limit exceeded while opening a document. */
1879
+ readonly limit?: 'zip.maxEntries' | 'zip.maxTotalBytes' | 'zip.maxRatio' | 'xml.maxBytes' | 'xml.maxElements' | 'xml.maxDepth' | 'maxXmlParts' | 'maxRelationships';
1854
1880
  /**
1855
1881
  * The consumer-facing path of the object or property involved — `document.body.text`, not a
1856
1882
  * handle. Omitted when there is nothing to name.
@@ -1879,8 +1905,8 @@ interface DocxEditorErrorInit {
1879
1905
  * try {
1880
1906
  * await context.sync();
1881
1907
  * } catch (error) {
1882
- * if (error instanceof DocxEditorError && error.code === 'StaleDocument') {
1883
- * // Re-read and retry: someone else changed the document first.
1908
+ * if (isDocxEditorError(error) && error.code === 'StaleDocument') {
1909
+ * // Re-read, re-anchor, and reconsider: someone else changed the document first.
1884
1910
  * }
1885
1911
  * }
1886
1912
  * ```
@@ -1890,6 +1916,8 @@ interface DocxEditorErrorInit {
1890
1916
  declare class DocxEditorError extends Error {
1891
1917
  /** Which refusal this is. Stable across versions; the thing to branch on. */
1892
1918
  readonly code: DocxEditorErrorCode;
1919
+ /** For `ResourceLimitExceeded`: the resource limit that prevented opening. */
1920
+ readonly limit?: DocxEditorErrorInit['limit'];
1893
1921
  /** Consumer-facing path of the object or property involved, when there is one to name. */
1894
1922
  readonly target?: string;
1895
1923
  /** For `StaleDocument`: the revision the context had read at. */
@@ -2030,10 +2058,13 @@ interface DocumentZipLimits {
2030
2058
  interface DocumentXmlLimits {
2031
2059
  /** Most bytes any one XML part may be. */
2032
2060
  readonly maxBytes: number;
2033
- /** Most elements any one XML part may contain. */
2061
+ /**
2062
+ * Most elements any one XML part may contain. Defaults to the engine budget
2063
+ * (10,000,000); callers may raise it up to the engine ceiling (50,000,000).
2064
+ */
2034
2065
  readonly maxElements?: number;
2035
2066
  }
2036
- /** Optional tighter limits applied while opening untrusted DOCX bytes. */
2067
+ /** Resource budgets applied while opening DOCX bytes, subject to engine ceilings. */
2037
2068
  interface DocumentLimits {
2038
2069
  /** Archive-level caps. */
2039
2070
  readonly zip?: DocumentZipLimits;
@@ -2048,10 +2079,9 @@ interface DocumentLimits {
2048
2079
  * How `DocxEditor.createServer` opens a document.
2049
2080
  *
2050
2081
  * Opening DOCX bytes is a bounded parse: decompression-ratio and size caps, part and relationship
2051
- * path validation, DTD- and entity-free XML. A refusal comes back as `InvalidArgument` rather
2052
- * than as a throw from inside a zip decoder, and says nothing about WHY — a caller opening files
2053
- * they did not author gets "not a document this API can open", so a probe cannot use the error to
2054
- * learn the reader's limits.
2082
+ * path validation, DTD- and entity-free XML. Malformed input returns `InvalidArgument`.
2083
+ * Resource refusals return `ResourceLimitExceeded`, with `limit` identifying the exceeded cap.
2084
+ * File-controlled details and internal parser messages are never included.
2055
2085
  *
2056
2086
  * The bounded parse is complete when this promise resolves. The runtime does not retain the
2057
2087
  * caller's `Uint8Array`, so the caller may reuse or transfer that input buffer afterward.
@@ -2065,17 +2095,18 @@ interface CreateServerOptions {
2065
2095
  */
2066
2096
  readonly modules?: readonly EditorModule[];
2067
2097
  /**
2068
- * Tighter budgets for the bounded reader — zip ratio, part count, XML depth.
2098
+ * Budgets for the bounded reader — archive size, part count, and XML elements.
2069
2099
  *
2070
- * Exposed because a server opening documents it did not author is exactly where a caller may
2071
- * want smaller limits than the defaults. Omitted means the engine's own defaults.
2100
+ * Omitted means the engine defaults. Lower budgets for untrusted input, or raise
2101
+ * `xml.maxElements` for larger documents when the host has sufficient memory.
2102
+ * Engine ceilings still apply.
2072
2103
  */
2073
2104
  readonly limits?: DocumentLimits;
2074
2105
  /**
2075
- * Who comments this runtime writes are recorded as.
2106
+ * Who comments and tracked text edits written by this runtime are recorded as.
2076
2107
  *
2077
- * Required to write one at all: `CT_TrackChange` makes `@w:author` mandatory and a server has no
2078
- * signed-in user, so a runtime opened without this refuses comment writes rather than putting a
2108
+ * Required for comment writes and `document.changeTrackingMode = 'TrackMineOnly'`: `CT_TrackChange` makes `@w:author` mandatory and a server has no
2109
+ * signed-in user, so a runtime opened without this refuses these operations rather than putting a
2079
2110
  * placeholder name into someone's document.
2080
2111
  */
2081
2112
  readonly author?: string;
@@ -2089,4 +2120,4 @@ interface CreateServerOptions {
2089
2120
  /** Options for {@link createCollaborative}. @public */
2090
2121
  type CreateCollaborativeOptions = CreateServerOptions;
2091
2122
 
2092
- export { type RevisionTextView as $, ListCollection as A, type BesideLocation as B, type CreateServerOptions as C, type DocxEditorServerRuntime as D, type EditorModule as E, Font as F, ListItem as G, type HeaderFooterType as H, type InsertLocation as I, type LoadOption as J, type LoadQueryOptions as K, List as L, NoteItemCollection as M, NoteItem as N, type NoteItemType as O, type PageOrientation as P, PageSetup as Q, Paragraph as R, type ParagraphAlignment as S, ParagraphCollection as T, type ParagraphInsertTextLocation as U, Range as V, RangeCollection as W, type RangeInsertTextLocation as X, RequestContext as Y, Revision as Z, RevisionCollection as _, type CreateCollaborativeOptions as a, type RevisionType as a0, type RunCallback as a1, type SearchOptions as a2, Section as a3, SectionCollection as a4, type SelectionMode as a5, TrackedObjects as a6, isDocxEditorError as a7, Body as b, type BodyInsertParagraphLocation as c, type BodyInsertTextLocation as d, Bookmark as e, BookmarkCollection as f, ClientObject as g, ClientResult as h, Comment as i, CommentCollection as j, CommentReply as k, CommentReplyCollection as l, ContentControl as m, ContentControlCollection as n, type ContentControlLockState as o, type ContentControlSubtype as p, type ContentControlValue as q, Document as r, type DocumentCapabilities as s, type DocumentLimits as t, type DocumentXmlLimits as u, type DocumentZipLimits as v, DocxEditorError as w, type DocxEditorErrorCode as x, type DocxEditorErrorInit as y, type DocxEditorRuntime as z };
2123
+ export { RevisionCollection as $, type DocxEditorRuntime as A, type BesideLocation as B, type CreateServerOptions as C, type DocxEditorServerRuntime as D, type EditorModule as E, Font as F, ListCollection as G, type HeaderFooterType as H, type InsertLocation as I, ListItem as J, type LoadOption as K, List as L, type LoadQueryOptions as M, NoteItem as N, NoteItemCollection as O, type NoteItemType as P, type PageOrientation as Q, PageSetup as R, Paragraph as S, type ParagraphAlignment as T, ParagraphCollection as U, type ParagraphInsertTextLocation as V, Range as W, RangeCollection as X, type RangeInsertTextLocation as Y, RequestContext as Z, Revision as _, type CreateCollaborativeOptions as a, type RevisionTextView as a0, type RevisionType as a1, type RunCallback as a2, type SearchOptions as a3, Section as a4, SectionCollection as a5, type SelectionMode as a6, TrackedObjects as a7, isDocxEditorError as a8, Body as b, type BodyInsertParagraphLocation as c, type BodyInsertTextLocation as d, Bookmark as e, BookmarkCollection as f, type ChangeTrackingMode as g, ClientObject as h, ClientResult as i, Comment as j, CommentCollection as k, CommentReply as l, CommentReplyCollection as m, ContentControl as n, ContentControlCollection as o, type ContentControlLockState as p, type ContentControlSubtype as q, type ContentControlValue as r, Document as s, type DocumentCapabilities as t, type DocumentLimits as u, type DocumentXmlLimits as v, type DocumentZipLimits as w, DocxEditorError as x, type DocxEditorErrorCode as y, type DocxEditorErrorInit as z };
@@ -650,6 +650,13 @@ declare class Range extends ModelObject implements PromisedItem {
650
650
  search(searchText: string, options?: SearchOptions): RangeCollection;
651
651
  /**
652
652
  * Write text at or over this range. Answers the range the written text occupies.
653
+ * Await `context.sync()` before loading or addressing that returned range.
654
+ *
655
+ * With server `document.changeTrackingMode = 'TrackMineOnly'`, this creates a tracked text
656
+ * edit attributed to the runtime author. Tracked edits must stay within one paragraph and
657
+ * cannot touch pending revisions. Structural and formatting tracking are not supported.
658
+ * Empty text with `Replace` deletes the range; empty text at an insertion point is a no-op.
659
+ * Agent tools that intend a replacement should validate non-empty model output first.
653
660
  *
654
661
  * `Before`/`Start` and `After`/`End` land at the SAME position here, and the difference Word
655
662
  * draws between them — whether the new text becomes part of this range — has no meaning for a
@@ -657,6 +664,10 @@ declare class Range extends ModelObject implements PromisedItem {
657
664
  * gets back is a range naming the text that was written, in every case.
658
665
  */
659
666
  insertText(text: string, insertLocation: 'Replace' | 'Start' | 'End' | 'Before' | 'After'): Range;
667
+ /** Delete this range's content. TrackMineOnly preserves inline text as a pending deletion. */
668
+ delete(): void;
669
+ /** Clear this range's content, preserving the surrounding structure. */
670
+ clear(): void;
660
671
  /**
661
672
  * Create a top-level comment anchored to exactly this range.
662
673
  *
@@ -1250,6 +1261,8 @@ declare class SectionCollection extends HandleCollection<Section> {
1250
1261
  protected promised(label: string, nullable: boolean): Section & PromisedItem;
1251
1262
  }
1252
1263
 
1264
+ /** Office.js tracking mode names. TrackAll is recognized but currently refused. @public */
1265
+ type ChangeTrackingMode = 'Off' | 'TrackAll' | 'TrackMineOnly';
1253
1266
  /**
1254
1267
  * The document: the root every other object is reached from.
1255
1268
  *
@@ -1284,6 +1297,15 @@ declare class Document extends ModelObject {
1284
1297
  /** @internal One per request context; the context memoizes it. */
1285
1298
  static open(context: RequestContext): Document;
1286
1299
  private constructor();
1300
+ /**
1301
+ * Tracking for this server host. Load 'changeTrackingMode' explicitly before reading.
1302
+ * Document.load() keeps an empty default property set across hosts. Assignments take effect at sync.
1303
+ * TrackMineOnly tracks this runtime's inline text edits using its configured author.
1304
+ * TrackAll and browser-host mode control are not supported. Unsupported tracked mutation
1305
+ * kinds refuse; the setting is session-local and is not saved as a document-wide policy.
1306
+ */
1307
+ get changeTrackingMode(): ChangeTrackingMode;
1308
+ set changeTrackingMode(mode: ChangeTrackingMode);
1287
1309
  /**
1288
1310
  * The main story.
1289
1311
  *
@@ -1813,6 +1835,8 @@ type DocxEditorErrorCode =
1813
1835
  | 'ObjectInUse'
1814
1836
  /** An argument or load option this API does not accept. */
1815
1837
  | 'InvalidArgument'
1838
+ /** Opening the document exceeded a bounded reader resource limit. */
1839
+ | 'ResourceLimitExceeded'
1816
1840
  /** The collection has no such item — `getFirst()` on an empty one. */
1817
1841
  | 'ItemNotFound'
1818
1842
  /** The host cannot do this at all — a capability it reports false. */
@@ -1851,6 +1875,8 @@ type DocxEditorErrorCode =
1851
1875
  interface DocxEditorErrorInit {
1852
1876
  /** Which refusal this is. The stable thing to branch on. */
1853
1877
  readonly code: DocxEditorErrorCode;
1878
+ /** The resource limit exceeded while opening a document. */
1879
+ readonly limit?: 'zip.maxEntries' | 'zip.maxTotalBytes' | 'zip.maxRatio' | 'xml.maxBytes' | 'xml.maxElements' | 'xml.maxDepth' | 'maxXmlParts' | 'maxRelationships';
1854
1880
  /**
1855
1881
  * The consumer-facing path of the object or property involved — `document.body.text`, not a
1856
1882
  * handle. Omitted when there is nothing to name.
@@ -1879,8 +1905,8 @@ interface DocxEditorErrorInit {
1879
1905
  * try {
1880
1906
  * await context.sync();
1881
1907
  * } catch (error) {
1882
- * if (error instanceof DocxEditorError && error.code === 'StaleDocument') {
1883
- * // Re-read and retry: someone else changed the document first.
1908
+ * if (isDocxEditorError(error) && error.code === 'StaleDocument') {
1909
+ * // Re-read, re-anchor, and reconsider: someone else changed the document first.
1884
1910
  * }
1885
1911
  * }
1886
1912
  * ```
@@ -1890,6 +1916,8 @@ interface DocxEditorErrorInit {
1890
1916
  declare class DocxEditorError extends Error {
1891
1917
  /** Which refusal this is. Stable across versions; the thing to branch on. */
1892
1918
  readonly code: DocxEditorErrorCode;
1919
+ /** For `ResourceLimitExceeded`: the resource limit that prevented opening. */
1920
+ readonly limit?: DocxEditorErrorInit['limit'];
1893
1921
  /** Consumer-facing path of the object or property involved, when there is one to name. */
1894
1922
  readonly target?: string;
1895
1923
  /** For `StaleDocument`: the revision the context had read at. */
@@ -2030,10 +2058,13 @@ interface DocumentZipLimits {
2030
2058
  interface DocumentXmlLimits {
2031
2059
  /** Most bytes any one XML part may be. */
2032
2060
  readonly maxBytes: number;
2033
- /** Most elements any one XML part may contain. */
2061
+ /**
2062
+ * Most elements any one XML part may contain. Defaults to the engine budget
2063
+ * (10,000,000); callers may raise it up to the engine ceiling (50,000,000).
2064
+ */
2034
2065
  readonly maxElements?: number;
2035
2066
  }
2036
- /** Optional tighter limits applied while opening untrusted DOCX bytes. */
2067
+ /** Resource budgets applied while opening DOCX bytes, subject to engine ceilings. */
2037
2068
  interface DocumentLimits {
2038
2069
  /** Archive-level caps. */
2039
2070
  readonly zip?: DocumentZipLimits;
@@ -2048,10 +2079,9 @@ interface DocumentLimits {
2048
2079
  * How `DocxEditor.createServer` opens a document.
2049
2080
  *
2050
2081
  * Opening DOCX bytes is a bounded parse: decompression-ratio and size caps, part and relationship
2051
- * path validation, DTD- and entity-free XML. A refusal comes back as `InvalidArgument` rather
2052
- * than as a throw from inside a zip decoder, and says nothing about WHY — a caller opening files
2053
- * they did not author gets "not a document this API can open", so a probe cannot use the error to
2054
- * learn the reader's limits.
2082
+ * path validation, DTD- and entity-free XML. Malformed input returns `InvalidArgument`.
2083
+ * Resource refusals return `ResourceLimitExceeded`, with `limit` identifying the exceeded cap.
2084
+ * File-controlled details and internal parser messages are never included.
2055
2085
  *
2056
2086
  * The bounded parse is complete when this promise resolves. The runtime does not retain the
2057
2087
  * caller's `Uint8Array`, so the caller may reuse or transfer that input buffer afterward.
@@ -2065,17 +2095,18 @@ interface CreateServerOptions {
2065
2095
  */
2066
2096
  readonly modules?: readonly EditorModule[];
2067
2097
  /**
2068
- * Tighter budgets for the bounded reader — zip ratio, part count, XML depth.
2098
+ * Budgets for the bounded reader — archive size, part count, and XML elements.
2069
2099
  *
2070
- * Exposed because a server opening documents it did not author is exactly where a caller may
2071
- * want smaller limits than the defaults. Omitted means the engine's own defaults.
2100
+ * Omitted means the engine defaults. Lower budgets for untrusted input, or raise
2101
+ * `xml.maxElements` for larger documents when the host has sufficient memory.
2102
+ * Engine ceilings still apply.
2072
2103
  */
2073
2104
  readonly limits?: DocumentLimits;
2074
2105
  /**
2075
- * Who comments this runtime writes are recorded as.
2106
+ * Who comments and tracked text edits written by this runtime are recorded as.
2076
2107
  *
2077
- * Required to write one at all: `CT_TrackChange` makes `@w:author` mandatory and a server has no
2078
- * signed-in user, so a runtime opened without this refuses comment writes rather than putting a
2108
+ * Required for comment writes and `document.changeTrackingMode = 'TrackMineOnly'`: `CT_TrackChange` makes `@w:author` mandatory and a server has no
2109
+ * signed-in user, so a runtime opened without this refuses these operations rather than putting a
2079
2110
  * placeholder name into someone's document.
2080
2111
  */
2081
2112
  readonly author?: string;
@@ -2089,4 +2120,4 @@ interface CreateServerOptions {
2089
2120
  /** Options for {@link createCollaborative}. @public */
2090
2121
  type CreateCollaborativeOptions = CreateServerOptions;
2091
2122
 
2092
- export { type RevisionTextView as $, ListCollection as A, type BesideLocation as B, type CreateServerOptions as C, type DocxEditorServerRuntime as D, type EditorModule as E, Font as F, ListItem as G, type HeaderFooterType as H, type InsertLocation as I, type LoadOption as J, type LoadQueryOptions as K, List as L, NoteItemCollection as M, NoteItem as N, type NoteItemType as O, type PageOrientation as P, PageSetup as Q, Paragraph as R, type ParagraphAlignment as S, ParagraphCollection as T, type ParagraphInsertTextLocation as U, Range as V, RangeCollection as W, type RangeInsertTextLocation as X, RequestContext as Y, Revision as Z, RevisionCollection as _, type CreateCollaborativeOptions as a, type RevisionType as a0, type RunCallback as a1, type SearchOptions as a2, Section as a3, SectionCollection as a4, type SelectionMode as a5, TrackedObjects as a6, isDocxEditorError as a7, Body as b, type BodyInsertParagraphLocation as c, type BodyInsertTextLocation as d, Bookmark as e, BookmarkCollection as f, ClientObject as g, ClientResult as h, Comment as i, CommentCollection as j, CommentReply as k, CommentReplyCollection as l, ContentControl as m, ContentControlCollection as n, type ContentControlLockState as o, type ContentControlSubtype as p, type ContentControlValue as q, Document as r, type DocumentCapabilities as s, type DocumentLimits as t, type DocumentXmlLimits as u, type DocumentZipLimits as v, DocxEditorError as w, type DocxEditorErrorCode as x, type DocxEditorErrorInit as y, type DocxEditorRuntime as z };
2123
+ export { RevisionCollection as $, type DocxEditorRuntime as A, type BesideLocation as B, type CreateServerOptions as C, type DocxEditorServerRuntime as D, type EditorModule as E, Font as F, ListCollection as G, type HeaderFooterType as H, type InsertLocation as I, ListItem as J, type LoadOption as K, List as L, type LoadQueryOptions as M, NoteItem as N, NoteItemCollection as O, type NoteItemType as P, type PageOrientation as Q, PageSetup as R, Paragraph as S, type ParagraphAlignment as T, ParagraphCollection as U, type ParagraphInsertTextLocation as V, Range as W, RangeCollection as X, type RangeInsertTextLocation as Y, RequestContext as Z, Revision as _, type CreateCollaborativeOptions as a, type RevisionTextView as a0, type RevisionType as a1, type RunCallback as a2, type SearchOptions as a3, Section as a4, SectionCollection as a5, type SelectionMode as a6, TrackedObjects as a7, isDocxEditorError as a8, Body as b, type BodyInsertParagraphLocation as c, type BodyInsertTextLocation as d, Bookmark as e, BookmarkCollection as f, type ChangeTrackingMode as g, ClientObject as h, ClientResult as i, Comment as j, CommentCollection as k, CommentReply as l, CommentReplyCollection as m, ContentControl as n, ContentControlCollection as o, type ContentControlLockState as p, type ContentControlSubtype as q, type ContentControlValue as r, Document as s, type DocumentCapabilities as t, type DocumentLimits as u, type DocumentXmlLimits as v, type DocumentZipLimits as w, DocxEditorError as x, type DocxEditorErrorCode as y, type DocxEditorErrorInit as z };