@docx-editor.dev/editor-api 0.0.1-placeholder → 2.0.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.
@@ -0,0 +1 @@
1
+ import {createBrowserAutomationHost}from'@docx-editor.dev/core/editor';import {createServerAutomationHost}from'@docx-editor.dev/core/automation';var Lt=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 is no longer usable. Objects are released when their run ends unless context.trackedObjects.add(...) kept them.",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?`${Lt[t.code]} (${t.target})`:Lt[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 ee(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 D=Symbol("docx-editor.runtime.internals"),lt=Symbol("docx-editor.runtime.release"),ct=Symbol("docx-editor.runtime.rebind");function ot(n){return n[D]}var oe=new Set(["select","expand","top","skip"]),ne=/^[A-Za-z][A-Za-z0-9]*$/;function At(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"||!ne.test(r))&&a({code:"InvalidArgument",target:t}),o.includes(r)||o.push(r);return o.length===0&&a({code:"InvalidArgument",target:t}),o}function jt(n,t){return (typeof n!="number"||!Number.isInteger(n)||n<0)&&a({code:"InvalidArgument",target:t}),n}function wt(n,t){if(n===void 0)return {select:[],expand:[]};if(typeof n=="string"||Array.isArray(n))return {select:At(n,t),expand:[]};(typeof n!="object"||n===null)&&a({code:"InvalidArgument",target:t});let e=n;for(let o of Object.keys(e))oe.has(o)||a({code:"InvalidArgument",target:`${t}.${o}`});return {select:At(e.select,`${t}.select`),expand:At(e.expand,`${t}.expand`),...e.top===void 0?{}:{top:jt(e.top,`${t}.top`)},...e.skip===void 0?{}:{skip:jt(e.skip,`${t}.skip`)}}}var w=class{#t;#e;#o;#n;#i=new Map;constructor(t,e,o={}){this.#t=t,this.#e=t[D],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(wt(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.#i.has(t)&&a({code:"InvalidObjectPath",target:this.#o.label}),this.#i.has(t)||a({code:"PropertyNotLoaded",target:`${this.#o.label}.${t}`}),this.#i.get(t)}hasLoadedProperty(t){return this.#i.has(t)}setLoadedProperty(t,e){this.#i.set(t,e);}[lt](){this.#o.release();}[ct](t){this.#t=t,this.#e=t[D];}};var Ct=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 x(n,t){if(n.kind!=="text")throw O(t);return n.text}function g(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 f(n,t){if(n.kind!=="span")throw O(t);return n.span}function pt(n,t){if(n.kind!=="spans")throw O(t);return n.spans}function vt(n,t){if(n.kind!=="font")throw O(t);return n.font}function Rt(n,t){if(n.kind!=="paragraphFormat")throw O(t);return n.format}function nt(n,t){if(n.kind!=="style")throw O(t);return n.name}function ht(n,t){if(n.kind!=="number")throw O(t);return n.value}function B(n,t){if(n.kind!=="flag")throw O(t);return n.value}function Ot(n,t){if(n.kind!=="pageSetup")throw O(t);return n.setup}function A(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 Et(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 re=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","conflicting-operations":"ConflictingChanges","document-unavailable":"DocumentUnavailable"});function ut(n,t={}){let e=re[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 Tt(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 ut(r.error,{...i===void 0?{}:{target:i},...e===void 0?{}:{expectedRevision:e},actualRevision:n.revision})}return new u({code:"GeneralException"})}function qt(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 mt=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 Nt(n,t){if(Array.isArray(n)){for(let e of n)t(e);return}t(n);}var rt=class{#t;#e;constructor(t,e){this.#t=t,this.#e=e;}add(t){this.#t.assertUsable(),Nt(t,e=>{this.#o(e),this.#t.track(e);});}remove(t){this.#t.assertUsable(),Nt(t,e=>{this.#o(e),this.#t.untrack(e);});}#o(t){this.#e(t)||a({code:"InvalidObjectPath"});}};var it=class n{#t;#e=new mt;#o=new Set;#n=new Set;#i;#a;#r;#s=false;#d=null;constructor(t){this.#t=t,this.#i={host:t.host,capabilities:t.capabilities,...t.author===void 0?{}:{author:t.author},queue:this.#e,session:t.id,roots:()=>t.roots(),assertUsable:e=>{this.#t.assertLive(e),this.#s&&a({code:"InvalidRequestContext",...e===void 0?{}:{target:e}});},isFinished:()=>this.#s,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.#a=new rt(this.#i,e=>this.#o.has(e));}get document(){return this.#i.assertUsable("document"),this.#r??=this.#t.openDocument(this),this.#r}get capabilities(){return this.#t.capabilities}get trackedObjects(){return this.#a}async sync(){this.#i.assertUsable();let t=this.#e.take();if(t.length===0)return;let e=Et(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 Tt(s,t,r);qt(t,s),(e.hasRead||e.hasWrite)&&(this.#d=s.revision);}get[D](){return this.#i}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[D];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[ct](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.#s){this.#s=true,this.#e.clear();for(let t of this.#o)this.#n.has(t)||t[lt]();this.#o.clear();}}};function at(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 M=class extends w{#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){at(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 b=this.addressAt(t,e,c);b&&d.push(this.itemAt(`${e}[${String(c)}]`,b));}return d}},y=class extends M{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 ie=["Replace","Start","End"],ae=["Start","End"],se=["Replace","Start","End"],de=["Before","After"],le=["Replace","Start","End","Before","After"],ce=["Select","Start","End"];function V(n,t,e){return (typeof n!="string"||!t.includes(n))&&a({code:"InvalidArgument",target:e}),n}var Dt=(n,t)=>V(n,ie,t),$t=(n,t)=>V(n,ae,t),Ft=(n,t)=>V(n,se,t),Ht=(n,t)=>V(n,de,t),Pt=(n,t)=>V(n,le,t),gt=(n,t)=>n===void 0?"Select":V(n,ce,t);function C(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 w{loadTextInto(t,e){let o=`${this.path.label}.${t}`;this.enqueue({sort:"read",label:o,plan:e,settle:r=>{this.setLoadedProperty(t,x(r,o));}});}command(t,e){let o=`${this.path.label}.${t}`;this.enqueue({sort:"write",label:o,plan:e,settle:r=>A(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 at(t,e,this.path.label)}onLoad(t){this.selection(t,[]);}};var pe=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=Bt(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=C(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:g(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",ht(r,e));});}#e(){return this.requireAddressable(),this.path.handle()}},W=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=he(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:g(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)}},U=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=Bt(t,e),r=this.#t();this.commandAnswering(e,()=>({op:"setListLevel",paragraph:r,level:o}),i=>{A(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",ht(r,e));});}#t(){this.requireAddressable();let t=this.path.address();return t.kind!=="handle"&&a({code:"InvalidObjectPath",target:this.path.label}),t.handle}};function Bt(n,t){return (!Number.isInteger(n)||n<0||n>pe)&&a({code:"InvalidArgument",target:t}),n}function he(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 z(n,t){return (typeof n!="string"||n.trim().length===0||n.length>255)&&a({code:"InvalidArgument",target:t}),n}var ue=["bold","italic","color","name","size"],S=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",Mt(t,`${this.path.label}.bold`));}get italic(){return this.loadedProperty("italic")}set italic(t){this.#o("italic",Mt(t,`${this.path.label}.italic`));}get color(){return this.loadedProperty("color")}set color(t){this.#o("color",Vt(t,`${this.path.label}.color`));}get name(){return this.loadedProperty("name")}set name(t){this.#o("name",Vt(t,`${this.path.label}.name`));}get size(){return this.loadedProperty("size")}set size(t){this.#o("size",me(t,`${this.path.label}.size`));}onLoad(t){let e=this.selection(t,ue);if(e.length===0)return;let o=`${this.path.label}.font`;this.read(o,()=>({op:"getFont",span:this.#n()}),r=>{let i=vt(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=>{A(i,r);});}#n(){return this.requireAddressable(),E(this.path,this.#t)}};function Mt(n,t){return typeof n!="boolean"&&a({code:"InvalidArgument",target:t}),n}function me(n,t){return (typeof n!="number"||!Number.isFinite(n))&&a({code:"InvalidArgument",target:t}),n}function Vt(n,t){return (typeof n!="string"||n.length===0)&&a({code:"InvalidArgument",target:t}),n}var G=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=gt(t,e);this.requireAddressable(),this.internals.capabilities.selection||a({code:"NotSupported",target:e});let r=this.#o(),i=h.promised(this.context,e,false);this.read(`${e}.range`,()=>({op:"getBookmarkRange",bookmark:r}),s=>{i.hydrateAddress({kind:"span",span:f(s,e)});}),i.select(o);}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",x(r,e));});}#e(t){let e=this.#o(),o=h.promised(this.context,t,false);return this.read(t,()=>({op:"getBookmarkRange",bookmark:e}),r=>{o.hydrateAddress({kind:"span",span:f(r,t)});}),o}#o(){return this.requireAddressable(),this.path.handle()}},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;}listing(){return this.#t()}itemAt(t,e){return G.at(this.context,t,e)}promised(t,e){return G.promised(this.context,t,e)}};var ge=new Set(["matchCase","matchWholeWord","ignorePunct","ignoreSpace","matchWildcards"]);function ft(n,t){if(n===void 0)return;typeof n!="object"&&a({code:"InvalidArgument",target:t});for(let[o,r]of Object.entries(n))ge.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 h=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??=S.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=z(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??=Q.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=ft(e,o),i=this.#n();return k.of(this.context,o,this.path,()=>({op:"search",scope:i,text:t,...r===void 0?{}:{options:r}}))}insertText(t,e){let o=`${this.path.label}.insertText`,r=C(t,o),i=Pt(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:f(c,o)});}),d}insertParagraph(t,e){let o=`${this.path.label}.insertParagraph`,r=C(t,o),i=Pt(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}),b=>{b.kind!=="handle"&&a({code:"GeneralException",target:o}),c.hydrateAddress({kind:"handle",handle:b.handle});}),c}select(t){let e=`${this.path.label}.select`,o=gt(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}),s=>{this.setLoadedProperty("text",x(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",nt(r,o));});}#n(){return this.requireAddressable(),this.path.span()}};var fe=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.#i("style",z(t,`${this.path.label}.style`));}get font(){return this.#t??=S.of(this.context,`${this.path.label}.font`,this.path,"paragraph"),this.#t}get alignment(){return this.loadedProperty("alignment")}set alignment(t){this.#i("alignment",be(t,`${this.path.label}.alignment`));}get firstLineIndent(){return this.loadedProperty("firstLineIndent")}set firstLineIndent(t){this.#i("firstLineIndent",X(t,`${this.path.label}.firstLineIndent`));}get leftIndent(){return this.loadedProperty("leftIndent")}set leftIndent(t){this.#i("leftIndent",X(t,`${this.path.label}.leftIndent`));}get rightIndent(){return this.loadedProperty("rightIndent")}set rightIndent(t){this.#i("rightIndent",X(t,`${this.path.label}.rightIndent`));}get lineSpacing(){return this.loadedProperty("lineSpacing")}set lineSpacing(t){this.#i("lineSpacing",X(t,`${this.path.label}.lineSpacing`));}get spaceBefore(){return this.loadedProperty("spaceBefore")}set spaceBefore(t){this.#i("spaceBefore",X(t,`${this.path.label}.spaceBefore`));}get spaceAfter(){return this.loadedProperty("spaceAfter")}set spaceAfter(t){this.#i("spaceAfter",X(t,`${this.path.label}.spaceAfter`));}get list(){return this.#e??=this.#a(`${this.path.label}.list`),this.#e}get listItem(){return this.#o??=U.of(this.context,`${this.path.label}.listItem`,this.path),this.#o}clear(){let t=this.#r();this.commandDiscarding("clear",()=>({op:"replaceSpan",span:{paragraph:t},text:""}));}delete(){let t=this.#r();this.command("delete",()=>({op:"deleteParagraph",paragraph:t}));}insertText(t,e){let o=`${this.path.label}.insertText`,r=C(t,o),i=Ft(e,o),s=this.#r(),d=h.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:f(c,o)});}),d}insertParagraph(t,e){let o=`${this.path.label}.insertParagraph`,r=C(t,o),i=Ht(e,o),s=this.#r(),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=xe(t,r),s=Ut(e,`${r}.trimDelimiters`),d=Ut(o,`${r}.trimSpacing`),c=this.#r(),b=k.answered(this.context,r,this.path);return this.commandAnswering(r,()=>({op:"splitParagraph",paragraph:c,delimiters:i,...s?{trimDelimiters:true}:{},...d?{trimSpacing:true}:{}}),N=>{b.fill(N,r);}),b}onLoad(t){let e=this.selection(t,["text","uniqueLocalId",...Wt]),o=this.#r();e.includes("text")&&this.loadTextInto("text",()=>({op:"getText",target:o})),e.includes("uniqueLocalId")&&this.loadTextInto("uniqueLocalId",()=>({op:"getParagraphId",paragraph:o}));let r=Wt.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=Rt(s,i);for(let c of r)this.setLoadedProperty(c,d[c]);});}#i(t,e){if(this.requireAddressable(),this.#n){this.#n[t]=e;return}let o={[t]:e};this.#n=o;let r=this.#r(),i=`${this.path.label}.${t}`;this.commandAnswering(`${this.path.label}.paragraphFormat`,()=>(this.#n=void 0,{op:"setParagraphFormat",paragraph:{paragraph:r},format:o}),s=>{A(s,i);});}#a(t){let e=this.#r(),o=L.promised(this.context,t,false);return this.read(t,()=>({op:"getParagraphList",paragraph:e}),r=>{o.hydrateAddress({kind:"handle",handle:g(r,t)});}),o}#r(){return this.requireAddressable(),this.path.handle()}},Wt=["style","alignment","firstLineIndent","leftIndent","rightIndent","lineSpacing","spaceBefore","spaceAfter"],ye=["Left","Centered","Right","Justified"];function be(n,t){return ye.includes(n)||a({code:"InvalidArgument",target:t}),n}function X(n,t){return (typeof n!="number"||!Number.isFinite(n))&&a({code:"InvalidArgument",target:t}),n}function xe(n,t){(!Array.isArray(n)||n.length===0||n.length>fe)&&a({code:"InvalidArgument",target:t});for(let e of n)(typeof e!="string"||e.length===0)&&a({code:"InvalidArgument",target:t});return [...n]}function Ut(n,t){return n!==void 0&&typeof n!="boolean"&&a({code:"InvalidArgument",target:t}),n===true}var v=class n extends M{#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)}},k=class n extends M{#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 pt(t,e).length}addressAt(t,e,o){let r=pt(t,e)[o];return r?{kind:"span",span:r}:void 0}itemAt(t,e){return h.at(this.context,t,e)}promised(t,e){return h.promised(this.context,t,e)}};var Gt=4096,$=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.#i("tag",{tag:It(t,`${this.path.label}.tag`)});}get title(){return this.loadedProperty("title")}set title(t){this.#i("title",{title:It(t,`${this.path.label}.title`)});}get subtype(){return this.loadedProperty("subtype")}get cannotDelete(){let t=this.loadedProperty("lock");return t==="sdtLocked"||t==="sdtContentLocked"}set cannotDelete(t){this.#a(t,this.cannotEdit,`${this.path.label}.cannotDelete`);}get cannotEdit(){let t=this.loadedProperty("lock");return t==="contentLocked"||t==="sdtContentLocked"}set cannotEdit(t){this.#a(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.#r()})),this.#e}get contentControls(){return this.#o??=j.of(this.context,`${this.path.label}.contentControls`,this.path,{contentControl:this.#r()}),this.#o}getRange(t){let e=`${this.path.label}.getRange`,o=Ae(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=Ce(t,e),r=this.#r();this.command("setValue",()=>({op:"setContentControlValue",contentControl:r,value:o}));}insertText(t,e){let o=`${this.path.label}.insertText`,r=C(t,o),i=e==="Replace"?"replace":e==="Start"?"start":e==="End"?"end":a({code:"InvalidArgument",target:o}),s=this.#r(),d=h.promised(this.context,o,false);return this.commandAnswering(o,()=>({op:"insertContentControlText",contentControl:s,text:r,at:i}),c=>{d.hydrateAddress({kind:"span",span:f(c,o)});}),d}delete(t){let e=`${this.path.label}.delete`;typeof t!="boolean"&&a({code:"InvalidArgument",target:e});let o=this.#r();this.command("delete",()=>({op:"deleteContentControl",contentControl:o,keepContent:t}));}onLoad(t){let e=this.selection(t,["id","tag","title","subtype","text","cannotDelete","cannotEdit","placeholderShown","temporary"]),o=this.#r();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("text")&&this.loadTextInto("text",()=>({op:"getContentControlText",contentControl:o})),e.includes("cannotDelete")||e.includes("cannotEdit")){let i=`${this.path.label}.lock`;this.read(i,()=>({op:"getContentControlLock",contentControl:o}),s=>{this.setLoadedProperty("lock",x(s,i));});}if(e.includes("placeholderShown")){let i=`${this.path.label}.placeholderShown`;this.read(i,()=>({op:"getContentControlPlaceholderShown",contentControl:o}),s=>{this.setLoadedProperty("placeholderShown",B(s,i));});}if(!e.includes("temporary"))return;let r=`${this.path.label}.temporary`;this.read(r,()=>({op:"getContentControlTemporary",contentControl:o}),i=>{this.setLoadedProperty("temporary",B(i,r));});}#n(t,e){let o=this.#r(),r=h.promised(this.context,t,false);return this.read(t,()=>({op:"getContentControlRange",contentControl:o,location:e}),i=>{r.hydrateAddress({kind:"span",span:f(i,t)});}),r}#i(t,e){let o=this.#r();this.command(t,()=>({op:"setContentControlProperties",contentControl:o,...e}));}#a(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.#r();this.command(o,()=>({op:"setContentControlProperties",contentControl:i,lock:r}));}#r(){return this.requireAddressable(),this.path.handle()}},j=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=$.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:g(i,e)});}}),r}getByTag(t){let e=`${this.path.label}.getByTag`,o=zt(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=zt(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 $.at(this.context,t,e)}promised(t,e){return $.promised(this.context,t,e)}};function It(n,t){return (typeof n!="string"||n.length>Gt)&&a({code:"InvalidArgument",target:t}),n}function zt(n,t){let e=It(n,t);return e.length===0&&a({code:"InvalidArgument",target:t}),e}function Ae(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 Ce(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>Gt)&&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});}function Qt(n){if(n.length===0)return null;let t=new Date(n);return Number.isNaN(t.getTime())?null:t}var yt=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")}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",Qt(x(d,s)));});}if(!o.includes("resolved"))return;let i=`${this.path.label}.resolved`;this.read(i,()=>({op:"getCommentResolved",comment:r}),s=>{this.setLoadedProperty("resolved",B(s,i));});}commentHandle(){return this.requireAddressable(),this.path.handle()}},F=class n extends yt{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,[]);}},st=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 F.at(this.context,t,e)}promised(t,e){return F.promised(this.context,t,e)}},K=class n extends yt{#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=>{A(r,e);});}get replies(){return this.#t??=st.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=h.promised(this.context,t,false);return this.read(t,()=>({op:"getCommentRange",comment:e}),r=>{o.hydrateAddress({kind:"span",span:f(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=F.promised(this.context,e,false);return this.commandAnswering(e,()=>({op:"replyToComment",comment:r,text:t,author:o}),s=>{i.hydrateAddress({kind:"handle",handle:g(s,e)});}),i}onLoad(t){this.loadCommentFields(t,["resolved"]);}},T=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 K.at(this.context,t,e)}promised(t,e){return K.promised(this.context,t,e)}},Y=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=h.promised(this.context,t,false);return this.read(t,()=>({op:"getRevisionRange",revision:e}),r=>{o.hydrateAddress({kind:"span",span:f(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",Qt(x(i,r)));});}#t(){return this.requireAddressable(),this.path.handle()}},q=class n extends y{#t;#e;static of(t,e,o,r,i){return new n(t,l.derived(e,o),r,i)}constructor(t,e,o,r){super(t,e),this.#t=o,this.#e=r;}acceptAll(){let t=this.#e;this.commandOn("acceptAll",()=>({op:"acceptAllRevisions",document:t}));}rejectAll(){let t=this.#e;this.commandOn("rejectAll",()=>({op:"rejectAllRevisions",document:t}));}listing(){return {op:"getRevisions",body:this.#t}}itemAt(t,e){return Y.at(this.context,t,e)}promised(t,e){return Y.promised(this.context,t,e)}commandOn(t,e){let o=`${this.path.label}.${t}`;this.enqueue({sort:"write",label:o,plan:e,settle:r=>{A(r,o);}});}};var I=class n extends p{#t;#e;#o;#n;#i;static main(t,e){return new n(t,l.of(e,ot(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 font(){return this.#e??=S.of(this.context,`${this.path.label}.font`,this.path,"body"),this.#e}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=z(t,e);this.requireAddressable(),this.command("style",()=>({op:"setStyle",span:E(this.path,"body"),name:o}));}get lists(){return this.#o??=W.of(this.context,`${this.path.label}.lists`,this.path,this.#r()),this.#o}get contentControls(){return this.#n??=j.of(this.context,`${this.path.label}.contentControls`,this.path,{body:this.#r()}),this.#n}getComments(){let t=`${this.path.label}.getComments`,e=this.#r();return T.of(this.context,t,this.path,()=>({op:"getComments",scope:{body:e}}))}get revisions(){return this.#i??=q.of(this.context,`${this.path.label}.revisions`,this.path,this.#r(),this.internals.roots().document),this.#i}search(t,e){let o=`${this.path.label}.search`;typeof t!="string"&&a({code:"InvalidArgument",target:o});let r=ft(e,o),i=this.#r();return k.of(this.context,o,this.path,()=>({op:"search",scope:{body:i},text:t,...r===void 0?{}:{options:r}}))}clear(){let t=this.#r();this.commandDiscarding("clear",()=>({op:"replaceSpan",span:{body:t},text:""}));}insertText(t,e){let o=`${this.path.label}.insertText`,r=C(t,o),i=Dt(e,o),s=this.#r(),d=h.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:f(c,o)});}),d}insertParagraph(t,e){let o=`${this.path.label}.insertParagraph`,r=C(t,o),i=$t(e,o),s=this.#r(),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.#r();this.loadTextInto("text",()=>({op:"getText",target:o}));}e.includes("style")&&this.#a();}#a(){let t=`${this.path.label}.style`;this.requireAddressable(),this.read(t,()=>({op:"getStyle",span:E(this.path,"body")}),e=>{this.setLoadedProperty("style",nt(e,t));});}#r(){return this.requireAddressable(),this.path.handle()}};function ve(n){return n==="endnote"?"Endnote":"Footnote"}var Z=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 body(){if(this.#t)return this.#t;let t=`${this.path.label}.body`,e=this.#e(),o=I.promisedStory(this.context,t);return this.read(t,()=>({op:"getNoteBody",note:e}),r=>{o.hydrateAddress({kind:"handle",handle:g(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=x(d,i)==="endnote"?"endnote":"footnote";}),this.read(t,()=>({op:"getNotes",document:r,noteKind:s}),d=>{let c=P(d,t),b=c.findIndex(St=>St.ref===e.ref),N=b<0?void 0:c[b+1];N||a({code:"ItemNotFound",target:t}),o.hydrateAddress({kind:"handle",handle:N});}),o}onLoad(t){if(!this.selection(t,["type"]).includes("type"))return;let e=`${this.path.label}.type`,o=this.#e();this.read(e,()=>({op:"getNoteKind",note:o}),r=>{this.setLoadedProperty("type",ve(x(r,e)));});}#e(){return this.requireAddressable(),this.path.handle()}},H=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 Z.at(this.context,t,e)}promised(t,e){return Z.promised(this.context,t,e)}};var Re=Object.freeze({Primary:"default",FirstPage:"first",EvenPages:"even"}),Oe=["pageWidth","pageHeight","orientation","topMargin","rightMargin","bottomMargin","leftMargin"],dt=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",J(t,`${this.path.label}.pageWidth`));}get pageHeight(){return this.loadedProperty("pageHeight")}set pageHeight(t){this.#e("pageHeight",J(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",J(t,`${this.path.label}.topMargin`));}get bottomMargin(){return this.loadedProperty("bottomMargin")}set bottomMargin(t){this.#e("bottomMargin",J(t,`${this.path.label}.bottomMargin`));}get leftMargin(){return this.loadedProperty("leftMargin")}set leftMargin(t){this.#e("leftMargin",J(t,`${this.path.label}.leftMargin`));}get rightMargin(){return this.loadedProperty("rightMargin")}set rightMargin(t){this.#e("rightMargin",J(t,`${this.path.label}.rightMargin`));}onLoad(t){let e=this.selection(t,Oe);if(e.length===0)return;let o=`${this.path.label}.pageSetup`,r=this.#o();this.read(o,()=>({op:"getPageSetup",section:r}),i=>{let s=Ot(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=>{A(s,i);});}#o(){this.requireAddressable();let t=this.path.address();return t.kind!=="handle"&&a({code:"InvalidObjectPath",target:this.path.label}),t.handle}},_=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??=I.main(this.context,`${this.path.label}.body`),this.#e}get pageSetup(){return this.#t??=dt.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(b=>b.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=Re[e];i===void 0&&a({code:"InvalidArgument",target:r});let s=this.#n(),d=I.promisedStory(this.context,r);return this.read(r,()=>({op:"getFurniture",section:s,kind:t,variant:i}),c=>{d.hydrateAddress({kind:"handle",handle:g(c,r)});}),d}#n(){return this.requireAddressable(),this.path.handle()}},tt=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 _.at(this.context,t,e)}promised(t,e){return _.promised(this.context,t,e)}};function J(n,t){return (typeof n!="number"||!Number.isFinite(n)||n<0)&&a({code:"InvalidArgument",target:t}),n}var et=class n extends p{#t;#e;#o;#n;#i;#a;#r;#s;static open(t){return new n(t)}constructor(t){super(t,l.of("document",ot(t).roots().document));}get body(){return this.#t??=I.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??=tt.of(this.context,"document.sections",this.path,()=>({op:"getSections",document:t})),this.#o}get contentControls(){return this.#a??=j.of(this.context,"document.contentControls",this.path,{body:this.internals.roots().body}),this.#a}get comments(){return this.#n??=T.of(this.context,"document.comments",this.path,()=>({op:"getComments",scope:{body:this.internals.roots().body}})),this.#n}get revisions(){return this.#i??=q.of(this.context,"document.revisions",this.path,this.internals.roots().body,this.path.handle()),this.#i}get footnotes(){let t=this.path.handle();return this.#r??=H.of(this.context,"document.footnotes",this.path,()=>({op:"getNotes",document:t,noteKind:"footnote"})),this.#r}get endnotes(){let t=this.path.handle();return this.#s??=H.of(this.context,"document.endnotes",this.path,()=>({op:"getNotes",document:t,noteKind:"endnote"})),this.#s}onLoad(t){this.selection(t,[]);}};function bt(n){let t=n.host,e=t.capabilities,o=typeof n.author=="string"&&n.author.trim().length>0?n.author:void 0,r=false,i=null,s=m=>{r&&a({code:"RuntimeDisposed",...m===void 0?{}:{target:m}});},d=()=>{if(i)return i;s("document");let m=Xt(t.execute({operations:[{op:"getDocument"}]}),"document"),xt=Xt(t.execute({operations:[{op:"getBody",document:m}]}),"document.body");return i={document:m,body:xt},i},c={host:t,capabilities:e,...o===void 0?{}:{author:o},id:{},roots:d,assertLive:s,openDocument:m=>et.open(m)};try{d();}catch{i=null;}async function b(m,xt){s();let kt=typeof m=="function"?m:xt,Zt=typeof m=="function"?[]:Array.isArray(m)?m:[m];typeof kt!="function"&&a({code:"InvalidArgument",target:"run"});let{context:Jt,adopt:_t,finish:te}=it.begin(c);try{return _t(Zt),await kt(Jt)}finally{te();}}let N={capabilities:e,run:b,dispose(){r||(r=true,i=null,t.dispose());}};return n.save?{...N,async save(){s("save"),e.save||a({code:"NotSupported",target:"save"});let m=t.save();if(!m.ok)throw ut(m.error,{target:"save"});return m.bytes}}:N}function Xt(n,t){let e=n.results[0];if(e?.status==="error")throw ut(e.error,{target:t});if(e?.status!=="ok")throw new u({code:"GeneralException",target:t});return g(e.value,t)}function Kt(n){return bt({host:createBrowserAutomationHost(n),save:false})}async function Yt(n,t={}){let e=createServerAutomationHost(n,{...t.limits===void 0?{}:{limits:t.limits}});return e.ok||a({code:"InvalidArgument",target:"createServer"}),bt({host:e.host,save:true,...t.author===void 0?{}:{author:t.author}})}var wr=Object.freeze({createBrowser:Kt,createServer:Yt});export{I as Body,G as Bookmark,Q as BookmarkCollection,w as ClientObject,Ct as ClientResult,K as Comment,T as CommentCollection,F as CommentReply,st as CommentReplyCollection,$ as ContentControl,j as ContentControlCollection,et as Document,wr as DocxEditor,u as DocxEditorError,S as Font,L as List,W as ListCollection,U as ListItem,Z as NoteItem,H as NoteItemCollection,dt as PageSetup,R as Paragraph,v as ParagraphCollection,h as Range,k as RangeCollection,it as RequestContext,Y as Revision,q as RevisionCollection,_ as Section,tt as SectionCollection,rt as TrackedObjects,ee as isDocxEditorError};
@@ -0,0 +1,157 @@
1
+
2
+ /**
3
+ * Document automation for DOCX: a batching object model over the DocxEditor engine.
4
+ *
5
+ * Work is described against proxy objects and nothing reaches the document until
6
+ * `context.sync()`, which sends one ordered batch and either applies all of it or none of it.
7
+ * Reading a property nobody asked for is an error rather than a silent `undefined`.
8
+ *
9
+ * This entry needs no browser. It opens DOCX bytes, drives them, and saves them back, so a
10
+ * server, a worker or a build script can import the package name and get the whole API.
11
+ *
12
+ * @example Read and edit a document on a server
13
+ * ```ts
14
+ * import { DocxEditor } from '@docx-editor.dev/editor-api';
15
+ *
16
+ * const runtime = await DocxEditor.createServer(bytes, { author: 'Payroll bot' });
17
+ * try {
18
+ * await runtime.run(async (context) => {
19
+ * const paragraphs = context.document.body.paragraphs;
20
+ * paragraphs.load('text');
21
+ * await context.sync();
22
+ *
23
+ * for (const paragraph of paragraphs.items) {
24
+ * if (paragraph.text.includes('{{name}}')) paragraph.insertText('Ada', 'Replace');
25
+ * }
26
+ * await context.sync();
27
+ * });
28
+ * const edited = await runtime.save();
29
+ * } finally {
30
+ * runtime.dispose();
31
+ * }
32
+ * ```
33
+ *
34
+ * @example Drive an editor a reader already has open
35
+ * ```ts
36
+ * // `createBrowser` lives one subpath along, because reaching a live editor means
37
+ * // reaching the painted engine. A consumer holding bytes should not pay for that.
38
+ * import { DocxEditor } from '@docx-editor.dev/editor-api/browser';
39
+ *
40
+ * const runtime = DocxEditor.createBrowser(editor);
41
+ * await runtime.run(async (context) => {
42
+ * const heading = context.document.body.paragraphs.getFirstOrNullObject();
43
+ * heading.load('text');
44
+ * await context.sync();
45
+ *
46
+ * if (!heading.isNullObject) heading.font.bold = true;
47
+ * await context.sync();
48
+ * });
49
+ * ```
50
+ *
51
+ * This is a DocxEditor-owned API whose shape is compatible with a documented subset of Word's
52
+ * JavaScript object model. It is not Office.js, it does not run in an Office add-in host, and it
53
+ * depends on no Microsoft package: every type in this surface is independently authored here.
54
+ *
55
+ * @packageDocumentation
56
+ * @public
57
+ */
58
+ import { C as CreateServerOptions, D as DocxEditorServerRuntime } from './server-C96AzKaT.mjs';
59
+ export { B as BesideLocation, a as Body, b as BodyInsertParagraphLocation, c as BodyInsertTextLocation, d as Bookmark, e as BookmarkCollection, f as ClientObject, g as ClientResult, h as Comment, i as CommentCollection, j as CommentReply, k as CommentReplyCollection, l as ContentControl, m as ContentControlCollection, n as ContentControlLockState, o as ContentControlSubtype, p as ContentControlValue, q as Document, r as DocumentCapabilities, s as DocumentLimits, t as DocumentXmlLimits, u as DocumentZipLimits, v as DocxEditorError, w as DocxEditorErrorCode, x as DocxEditorErrorInit, y as DocxEditorRuntime, F as Font, H as HeaderFooterType, I as InsertLocation, L as List, z as ListCollection, A as ListItem, E as LoadOption, G as LoadQueryOptions, N as NoteItem, J as NoteItemCollection, K as NoteItemType, P as PageOrientation, M as PageSetup, O as Paragraph, Q as ParagraphAlignment, R as ParagraphCollection, S as ParagraphInsertTextLocation, T as Range, U as RangeCollection, V as RangeInsertTextLocation, W as RequestContext, X as Revision, Y as RevisionCollection, Z as RevisionType, _ as RunCallback, $ as SearchOptions, a0 as Section, a1 as SectionCollection, a2 as SelectionMode, a3 as TrackedObjects, a4 as isDocxEditorError } from './server-C96AzKaT.mjs';
60
+ import '@docx-editor.dev/core/automation';
61
+
62
+ /**
63
+ * Document automation for DOCX: a batching object model over the DocxEditor engine.
64
+ *
65
+ * Work is described against proxy objects and nothing reaches the document until
66
+ * `context.sync()`, which sends one ordered batch and either applies all of it or none of it.
67
+ * Reading a property nobody asked for is an error rather than a silent `undefined`.
68
+ *
69
+ * This entry needs no browser. It opens DOCX bytes, drives them, and saves them back, so a
70
+ * server, a worker or a build script can import the package name and get the whole API.
71
+ *
72
+ * @example Read and edit a document on a server
73
+ * ```ts
74
+ * import { DocxEditor } from '@docx-editor.dev/editor-api';
75
+ *
76
+ * const runtime = await DocxEditor.createServer(bytes, { author: 'Payroll bot' });
77
+ * try {
78
+ * await runtime.run(async (context) => {
79
+ * const paragraphs = context.document.body.paragraphs;
80
+ * paragraphs.load('text');
81
+ * await context.sync();
82
+ *
83
+ * for (const paragraph of paragraphs.items) {
84
+ * if (paragraph.text.includes('{{name}}')) paragraph.insertText('Ada', 'Replace');
85
+ * }
86
+ * await context.sync();
87
+ * });
88
+ * const edited = await runtime.save();
89
+ * } finally {
90
+ * runtime.dispose();
91
+ * }
92
+ * ```
93
+ *
94
+ * @example Drive an editor a reader already has open
95
+ * ```ts
96
+ * // `createBrowser` lives one subpath along, because reaching a live editor means
97
+ * // reaching the painted engine. A consumer holding bytes should not pay for that.
98
+ * import { DocxEditor } from '@docx-editor.dev/editor-api/browser';
99
+ *
100
+ * const runtime = DocxEditor.createBrowser(editor);
101
+ * await runtime.run(async (context) => {
102
+ * const heading = context.document.body.paragraphs.getFirstOrNullObject();
103
+ * heading.load('text');
104
+ * await context.sync();
105
+ *
106
+ * if (!heading.isNullObject) heading.font.bold = true;
107
+ * await context.sync();
108
+ * });
109
+ * ```
110
+ *
111
+ * This is a DocxEditor-owned API whose shape is compatible with a documented subset of Word's
112
+ * JavaScript object model. It is not Office.js, it does not run in an Office add-in host, and it
113
+ * depends on no Microsoft package: every type in this surface is independently authored here.
114
+ *
115
+ * @packageDocumentation
116
+ * @public
117
+ */
118
+
119
+ /**
120
+ * The entry point, as much of it as works without an editor.
121
+ *
122
+ * An object rather than a TypeScript `namespace`: a namespace with runtime members is a
123
+ * declaration-merging construct that does not survive being re-exported through a bundler as
124
+ * predictably, and `DocxEditor.createServer` reads the same either way.
125
+ *
126
+ * Import from `@docx-editor.dev/editor-api/browser` for the same namespace plus `createBrowser`.
127
+ *
128
+ * @public
129
+ */
130
+ interface DocxEditorNamespace {
131
+ /** A runtime over DOCX bytes. Additionally offers `save()`. */
132
+ createServer(bytes: Uint8Array, options?: CreateServerOptions): Promise<DocxEditorServerRuntime>;
133
+ }
134
+ /**
135
+ * The entry point: open a document and get a runtime to work against.
136
+ *
137
+ * Import from `@docx-editor.dev/editor-api/browser` for the same namespace plus `createBrowser`,
138
+ * which borrows a live editor instead of owning bytes.
139
+ *
140
+ * @example
141
+ * ```ts
142
+ * import { DocxEditor } from '@docx-editor.dev/editor-api';
143
+ *
144
+ * const runtime = await DocxEditor.createServer(bytes, { author: 'Payroll bot' });
145
+ * await runtime.run(async (context) => {
146
+ * const body = context.document.body;
147
+ * body.load('text');
148
+ * await context.sync();
149
+ * });
150
+ * const saved = await runtime.save();
151
+ * ```
152
+ *
153
+ * @public
154
+ */
155
+ declare const DocxEditor: DocxEditorNamespace;
156
+
157
+ export { CreateServerOptions, DocxEditor, type DocxEditorNamespace, DocxEditorServerRuntime };
@@ -0,0 +1,157 @@
1
+
2
+ /**
3
+ * Document automation for DOCX: a batching object model over the DocxEditor engine.
4
+ *
5
+ * Work is described against proxy objects and nothing reaches the document until
6
+ * `context.sync()`, which sends one ordered batch and either applies all of it or none of it.
7
+ * Reading a property nobody asked for is an error rather than a silent `undefined`.
8
+ *
9
+ * This entry needs no browser. It opens DOCX bytes, drives them, and saves them back, so a
10
+ * server, a worker or a build script can import the package name and get the whole API.
11
+ *
12
+ * @example Read and edit a document on a server
13
+ * ```ts
14
+ * import { DocxEditor } from '@docx-editor.dev/editor-api';
15
+ *
16
+ * const runtime = await DocxEditor.createServer(bytes, { author: 'Payroll bot' });
17
+ * try {
18
+ * await runtime.run(async (context) => {
19
+ * const paragraphs = context.document.body.paragraphs;
20
+ * paragraphs.load('text');
21
+ * await context.sync();
22
+ *
23
+ * for (const paragraph of paragraphs.items) {
24
+ * if (paragraph.text.includes('{{name}}')) paragraph.insertText('Ada', 'Replace');
25
+ * }
26
+ * await context.sync();
27
+ * });
28
+ * const edited = await runtime.save();
29
+ * } finally {
30
+ * runtime.dispose();
31
+ * }
32
+ * ```
33
+ *
34
+ * @example Drive an editor a reader already has open
35
+ * ```ts
36
+ * // `createBrowser` lives one subpath along, because reaching a live editor means
37
+ * // reaching the painted engine. A consumer holding bytes should not pay for that.
38
+ * import { DocxEditor } from '@docx-editor.dev/editor-api/browser';
39
+ *
40
+ * const runtime = DocxEditor.createBrowser(editor);
41
+ * await runtime.run(async (context) => {
42
+ * const heading = context.document.body.paragraphs.getFirstOrNullObject();
43
+ * heading.load('text');
44
+ * await context.sync();
45
+ *
46
+ * if (!heading.isNullObject) heading.font.bold = true;
47
+ * await context.sync();
48
+ * });
49
+ * ```
50
+ *
51
+ * This is a DocxEditor-owned API whose shape is compatible with a documented subset of Word's
52
+ * JavaScript object model. It is not Office.js, it does not run in an Office add-in host, and it
53
+ * depends on no Microsoft package: every type in this surface is independently authored here.
54
+ *
55
+ * @packageDocumentation
56
+ * @public
57
+ */
58
+ import { C as CreateServerOptions, D as DocxEditorServerRuntime } from './server-C96AzKaT.js';
59
+ export { B as BesideLocation, a as Body, b as BodyInsertParagraphLocation, c as BodyInsertTextLocation, d as Bookmark, e as BookmarkCollection, f as ClientObject, g as ClientResult, h as Comment, i as CommentCollection, j as CommentReply, k as CommentReplyCollection, l as ContentControl, m as ContentControlCollection, n as ContentControlLockState, o as ContentControlSubtype, p as ContentControlValue, q as Document, r as DocumentCapabilities, s as DocumentLimits, t as DocumentXmlLimits, u as DocumentZipLimits, v as DocxEditorError, w as DocxEditorErrorCode, x as DocxEditorErrorInit, y as DocxEditorRuntime, F as Font, H as HeaderFooterType, I as InsertLocation, L as List, z as ListCollection, A as ListItem, E as LoadOption, G as LoadQueryOptions, N as NoteItem, J as NoteItemCollection, K as NoteItemType, P as PageOrientation, M as PageSetup, O as Paragraph, Q as ParagraphAlignment, R as ParagraphCollection, S as ParagraphInsertTextLocation, T as Range, U as RangeCollection, V as RangeInsertTextLocation, W as RequestContext, X as Revision, Y as RevisionCollection, Z as RevisionType, _ as RunCallback, $ as SearchOptions, a0 as Section, a1 as SectionCollection, a2 as SelectionMode, a3 as TrackedObjects, a4 as isDocxEditorError } from './server-C96AzKaT.js';
60
+ import '@docx-editor.dev/core/automation';
61
+
62
+ /**
63
+ * Document automation for DOCX: a batching object model over the DocxEditor engine.
64
+ *
65
+ * Work is described against proxy objects and nothing reaches the document until
66
+ * `context.sync()`, which sends one ordered batch and either applies all of it or none of it.
67
+ * Reading a property nobody asked for is an error rather than a silent `undefined`.
68
+ *
69
+ * This entry needs no browser. It opens DOCX bytes, drives them, and saves them back, so a
70
+ * server, a worker or a build script can import the package name and get the whole API.
71
+ *
72
+ * @example Read and edit a document on a server
73
+ * ```ts
74
+ * import { DocxEditor } from '@docx-editor.dev/editor-api';
75
+ *
76
+ * const runtime = await DocxEditor.createServer(bytes, { author: 'Payroll bot' });
77
+ * try {
78
+ * await runtime.run(async (context) => {
79
+ * const paragraphs = context.document.body.paragraphs;
80
+ * paragraphs.load('text');
81
+ * await context.sync();
82
+ *
83
+ * for (const paragraph of paragraphs.items) {
84
+ * if (paragraph.text.includes('{{name}}')) paragraph.insertText('Ada', 'Replace');
85
+ * }
86
+ * await context.sync();
87
+ * });
88
+ * const edited = await runtime.save();
89
+ * } finally {
90
+ * runtime.dispose();
91
+ * }
92
+ * ```
93
+ *
94
+ * @example Drive an editor a reader already has open
95
+ * ```ts
96
+ * // `createBrowser` lives one subpath along, because reaching a live editor means
97
+ * // reaching the painted engine. A consumer holding bytes should not pay for that.
98
+ * import { DocxEditor } from '@docx-editor.dev/editor-api/browser';
99
+ *
100
+ * const runtime = DocxEditor.createBrowser(editor);
101
+ * await runtime.run(async (context) => {
102
+ * const heading = context.document.body.paragraphs.getFirstOrNullObject();
103
+ * heading.load('text');
104
+ * await context.sync();
105
+ *
106
+ * if (!heading.isNullObject) heading.font.bold = true;
107
+ * await context.sync();
108
+ * });
109
+ * ```
110
+ *
111
+ * This is a DocxEditor-owned API whose shape is compatible with a documented subset of Word's
112
+ * JavaScript object model. It is not Office.js, it does not run in an Office add-in host, and it
113
+ * depends on no Microsoft package: every type in this surface is independently authored here.
114
+ *
115
+ * @packageDocumentation
116
+ * @public
117
+ */
118
+
119
+ /**
120
+ * The entry point, as much of it as works without an editor.
121
+ *
122
+ * An object rather than a TypeScript `namespace`: a namespace with runtime members is a
123
+ * declaration-merging construct that does not survive being re-exported through a bundler as
124
+ * predictably, and `DocxEditor.createServer` reads the same either way.
125
+ *
126
+ * Import from `@docx-editor.dev/editor-api/browser` for the same namespace plus `createBrowser`.
127
+ *
128
+ * @public
129
+ */
130
+ interface DocxEditorNamespace {
131
+ /** A runtime over DOCX bytes. Additionally offers `save()`. */
132
+ createServer(bytes: Uint8Array, options?: CreateServerOptions): Promise<DocxEditorServerRuntime>;
133
+ }
134
+ /**
135
+ * The entry point: open a document and get a runtime to work against.
136
+ *
137
+ * Import from `@docx-editor.dev/editor-api/browser` for the same namespace plus `createBrowser`,
138
+ * which borrows a live editor instead of owning bytes.
139
+ *
140
+ * @example
141
+ * ```ts
142
+ * import { DocxEditor } from '@docx-editor.dev/editor-api';
143
+ *
144
+ * const runtime = await DocxEditor.createServer(bytes, { author: 'Payroll bot' });
145
+ * await runtime.run(async (context) => {
146
+ * const body = context.document.body;
147
+ * body.load('text');
148
+ * await context.sync();
149
+ * });
150
+ * const saved = await runtime.save();
151
+ * ```
152
+ *
153
+ * @public
154
+ */
155
+ declare const DocxEditor: DocxEditorNamespace;
156
+
157
+ export { CreateServerOptions, DocxEditor, type DocxEditorNamespace, DocxEditorServerRuntime };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ 'use strict';var automation=require('@docx-editor.dev/core/automation');var kt=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 is no longer usable. Objects are released when their run ends unless context.trackedObjects.add(...) kept them.",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?`${kt[t.code]} (${t.target})`:kt[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 te(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 $=Symbol("docx-editor.runtime.internals"),lt=Symbol("docx-editor.runtime.release"),ct=Symbol("docx-editor.runtime.rebind");function ot(n){return n[$]}var ee=new Set(["select","expand","top","skip"]),oe=/^[A-Za-z][A-Za-z0-9]*$/;function xt(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"||!oe.test(r))&&a({code:"InvalidArgument",target:t}),o.includes(r)||o.push(r);return o.length===0&&a({code:"InvalidArgument",target:t}),o}function Lt(n,t){return (typeof n!="number"||!Number.isInteger(n)||n<0)&&a({code:"InvalidArgument",target:t}),n}function jt(n,t){if(n===void 0)return {select:[],expand:[]};if(typeof n=="string"||Array.isArray(n))return {select:xt(n,t),expand:[]};(typeof n!="object"||n===null)&&a({code:"InvalidArgument",target:t});let e=n;for(let o of Object.keys(e))ee.has(o)||a({code:"InvalidArgument",target:`${t}.${o}`});return {select:xt(e.select,`${t}.select`),expand:xt(e.expand,`${t}.expand`),...e.top===void 0?{}:{top:Lt(e.top,`${t}.top`)},...e.skip===void 0?{}:{skip:Lt(e.skip,`${t}.skip`)}}}var w=class{#t;#e;#o;#n;#i=new Map;constructor(t,e,o={}){this.#t=t,this.#e=t[$],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(jt(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.#i.has(t)&&a({code:"InvalidObjectPath",target:this.#o.label}),this.#i.has(t)||a({code:"PropertyNotLoaded",target:`${this.#o.label}.${t}`}),this.#i.get(t)}hasLoadedProperty(t){return this.#i.has(t)}setLoadedProperty(t,e){this.#i.set(t,e);}[lt](){this.#o.release();}[ct](t){this.#t=t,this.#e=t[$];}};var At=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 x(n,t){if(n.kind!=="text")throw R(t);return n.text}function g(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 f(n,t){if(n.kind!=="span")throw R(t);return n.span}function pt(n,t){if(n.kind!=="spans")throw R(t);return n.spans}function Ct(n,t){if(n.kind!=="font")throw R(t);return n.font}function vt(n,t){if(n.kind!=="paragraphFormat")throw R(t);return n.format}function nt(n,t){if(n.kind!=="style")throw R(t);return n.name}function ht(n,t){if(n.kind!=="number")throw R(t);return n.value}function B(n,t){if(n.kind!=="flag")throw R(t);return n.value}function Ot(n,t){if(n.kind!=="pageSetup")throw R(t);return n.setup}function A(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 wt(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 ne=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","conflicting-operations":"ConflictingChanges","document-unavailable":"DocumentUnavailable"});function ut(n,t={}){let e=ne[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 Tt(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 ut(r.error,{...i===void 0?{}:{target:i},...e===void 0?{}:{expectedRevision:e},actualRevision:n.revision})}return new u({code:"GeneralException"})}function Et(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 mt=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 qt(n,t){if(Array.isArray(n)){for(let e of n)t(e);return}t(n);}var rt=class{#t;#e;constructor(t,e){this.#t=t,this.#e=e;}add(t){this.#t.assertUsable(),qt(t,e=>{this.#o(e),this.#t.track(e);});}remove(t){this.#t.assertUsable(),qt(t,e=>{this.#o(e),this.#t.untrack(e);});}#o(t){this.#e(t)||a({code:"InvalidObjectPath"});}};var it=class n{#t;#e=new mt;#o=new Set;#n=new Set;#i;#a;#r;#s=false;#d=null;constructor(t){this.#t=t,this.#i={host:t.host,capabilities:t.capabilities,...t.author===void 0?{}:{author:t.author},queue:this.#e,session:t.id,roots:()=>t.roots(),assertUsable:e=>{this.#t.assertLive(e),this.#s&&a({code:"InvalidRequestContext",...e===void 0?{}:{target:e}});},isFinished:()=>this.#s,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.#a=new rt(this.#i,e=>this.#o.has(e));}get document(){return this.#i.assertUsable("document"),this.#r??=this.#t.openDocument(this),this.#r}get capabilities(){return this.#t.capabilities}get trackedObjects(){return this.#a}async sync(){this.#i.assertUsable();let t=this.#e.take();if(t.length===0)return;let e=wt(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 Tt(s,t,r);Et(t,s),(e.hasRead||e.hasWrite)&&(this.#d=s.revision);}get[$](){return this.#i}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[$];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[ct](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.#s){this.#s=true,this.#e.clear();for(let t of this.#o)this.#n.has(t)||t[lt]();this.#o.clear();}}};function at(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 M=class extends w{#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){at(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 b=this.addressAt(t,e,c);b&&d.push(this.itemAt(`${e}[${String(c)}]`,b));}return d}},y=class extends M{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 re=["Replace","Start","End"],ie=["Start","End"],ae=["Replace","Start","End"],se=["Before","After"],de=["Replace","Start","End","Before","After"],le=["Select","Start","End"];function V(n,t,e){return (typeof n!="string"||!t.includes(n))&&a({code:"InvalidArgument",target:e}),n}var Nt=(n,t)=>V(n,re,t),$t=(n,t)=>V(n,ie,t),Dt=(n,t)=>V(n,ae,t),Ft=(n,t)=>V(n,se,t),Rt=(n,t)=>V(n,de,t),gt=(n,t)=>n===void 0?"Select":V(n,le,t);function C(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 w{loadTextInto(t,e){let o=`${this.path.label}.${t}`;this.enqueue({sort:"read",label:o,plan:e,settle:r=>{this.setLoadedProperty(t,x(r,o));}});}command(t,e){let o=`${this.path.label}.${t}`;this.enqueue({sort:"write",label:o,plan:e,settle:r=>A(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 at(t,e,this.path.label)}onLoad(t){this.selection(t,[]);}};var ce=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=Ht(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=C(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:g(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",ht(r,e));});}#e(){return this.requireAddressable(),this.path.handle()}},W=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=pe(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:g(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)}},U=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=Ht(t,e),r=this.#t();this.commandAnswering(e,()=>({op:"setListLevel",paragraph:r,level:o}),i=>{A(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",ht(r,e));});}#t(){this.requireAddressable();let t=this.path.address();return t.kind!=="handle"&&a({code:"InvalidObjectPath",target:this.path.label}),t.handle}};function Ht(n,t){return (!Number.isInteger(n)||n<0||n>ce)&&a({code:"InvalidArgument",target:t}),n}function pe(n,t){return (!Number.isInteger(n)||n<=0)&&a({code:"InvalidArgument",target:t}),n}function T(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 z(n,t){return (typeof n!="string"||n.trim().length===0||n.length>255)&&a({code:"InvalidArgument",target:t}),n}var he=["bold","italic","color","name","size"],S=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",Bt(t,`${this.path.label}.bold`));}get italic(){return this.loadedProperty("italic")}set italic(t){this.#o("italic",Bt(t,`${this.path.label}.italic`));}get color(){return this.loadedProperty("color")}set color(t){this.#o("color",Mt(t,`${this.path.label}.color`));}get name(){return this.loadedProperty("name")}set name(t){this.#o("name",Mt(t,`${this.path.label}.name`));}get size(){return this.loadedProperty("size")}set size(t){this.#o("size",ue(t,`${this.path.label}.size`));}onLoad(t){let e=this.selection(t,he);if(e.length===0)return;let o=`${this.path.label}.font`;this.read(o,()=>({op:"getFont",span:this.#n()}),r=>{let i=Ct(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=>{A(i,r);});}#n(){return this.requireAddressable(),T(this.path,this.#t)}};function Bt(n,t){return typeof n!="boolean"&&a({code:"InvalidArgument",target:t}),n}function ue(n,t){return (typeof n!="number"||!Number.isFinite(n))&&a({code:"InvalidArgument",target:t}),n}function Mt(n,t){return (typeof n!="string"||n.length===0)&&a({code:"InvalidArgument",target:t}),n}var G=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=gt(t,e);this.requireAddressable(),this.internals.capabilities.selection||a({code:"NotSupported",target:e});let r=this.#o(),i=h.promised(this.context,e,false);this.read(`${e}.range`,()=>({op:"getBookmarkRange",bookmark:r}),s=>{i.hydrateAddress({kind:"span",span:f(s,e)});}),i.select(o);}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",x(r,e));});}#e(t){let e=this.#o(),o=h.promised(this.context,t,false);return this.read(t,()=>({op:"getBookmarkRange",bookmark:e}),r=>{o.hydrateAddress({kind:"span",span:f(r,t)});}),o}#o(){return this.requireAddressable(),this.path.handle()}},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;}listing(){return this.#t()}itemAt(t,e){return G.at(this.context,t,e)}promised(t,e){return G.promised(this.context,t,e)}};var me=new Set(["matchCase","matchWholeWord","ignorePunct","ignoreSpace","matchWildcards"]);function ft(n,t){if(n===void 0)return;typeof n!="object"&&a({code:"InvalidArgument",target:t});for(let[o,r]of Object.entries(n))me.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 h=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??=S.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=z(t,e);this.requireAddressable(),this.command("style",()=>({op:"setStyle",span:T(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??=Q.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=ft(e,o),i=this.#n();return k.of(this.context,o,this.path,()=>({op:"search",scope:i,text:t,...r===void 0?{}:{options:r}}))}insertText(t,e){let o=`${this.path.label}.insertText`,r=C(t,o),i=Rt(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:f(c,o)});}),d}insertParagraph(t,e){let o=`${this.path.label}.insertParagraph`,r=C(t,o),i=Rt(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}),b=>{b.kind!=="handle"&&a({code:"GeneralException",target:o}),c.hydrateAddress({kind:"handle",handle:b.handle});}),c}select(t){let e=`${this.path.label}.select`,o=gt(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}),s=>{this.setLoadedProperty("text",x(s,i));});}if(!e.includes("style"))return;let o=`${this.path.label}.style`;this.requireAddressable(),this.read(o,()=>({op:"getStyle",span:T(this.path,"span")}),r=>{this.setLoadedProperty("style",nt(r,o));});}#n(){return this.requireAddressable(),this.path.span()}};var ge=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.#i("style",z(t,`${this.path.label}.style`));}get font(){return this.#t??=S.of(this.context,`${this.path.label}.font`,this.path,"paragraph"),this.#t}get alignment(){return this.loadedProperty("alignment")}set alignment(t){this.#i("alignment",ye(t,`${this.path.label}.alignment`));}get firstLineIndent(){return this.loadedProperty("firstLineIndent")}set firstLineIndent(t){this.#i("firstLineIndent",X(t,`${this.path.label}.firstLineIndent`));}get leftIndent(){return this.loadedProperty("leftIndent")}set leftIndent(t){this.#i("leftIndent",X(t,`${this.path.label}.leftIndent`));}get rightIndent(){return this.loadedProperty("rightIndent")}set rightIndent(t){this.#i("rightIndent",X(t,`${this.path.label}.rightIndent`));}get lineSpacing(){return this.loadedProperty("lineSpacing")}set lineSpacing(t){this.#i("lineSpacing",X(t,`${this.path.label}.lineSpacing`));}get spaceBefore(){return this.loadedProperty("spaceBefore")}set spaceBefore(t){this.#i("spaceBefore",X(t,`${this.path.label}.spaceBefore`));}get spaceAfter(){return this.loadedProperty("spaceAfter")}set spaceAfter(t){this.#i("spaceAfter",X(t,`${this.path.label}.spaceAfter`));}get list(){return this.#e??=this.#a(`${this.path.label}.list`),this.#e}get listItem(){return this.#o??=U.of(this.context,`${this.path.label}.listItem`,this.path),this.#o}clear(){let t=this.#r();this.commandDiscarding("clear",()=>({op:"replaceSpan",span:{paragraph:t},text:""}));}delete(){let t=this.#r();this.command("delete",()=>({op:"deleteParagraph",paragraph:t}));}insertText(t,e){let o=`${this.path.label}.insertText`,r=C(t,o),i=Dt(e,o),s=this.#r(),d=h.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:f(c,o)});}),d}insertParagraph(t,e){let o=`${this.path.label}.insertParagraph`,r=C(t,o),i=Ft(e,o),s=this.#r(),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=be(t,r),s=Wt(e,`${r}.trimDelimiters`),d=Wt(o,`${r}.trimSpacing`),c=this.#r(),b=k.answered(this.context,r,this.path);return this.commandAnswering(r,()=>({op:"splitParagraph",paragraph:c,delimiters:i,...s?{trimDelimiters:true}:{},...d?{trimSpacing:true}:{}}),N=>{b.fill(N,r);}),b}onLoad(t){let e=this.selection(t,["text","uniqueLocalId",...Vt]),o=this.#r();e.includes("text")&&this.loadTextInto("text",()=>({op:"getText",target:o})),e.includes("uniqueLocalId")&&this.loadTextInto("uniqueLocalId",()=>({op:"getParagraphId",paragraph:o}));let r=Vt.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=vt(s,i);for(let c of r)this.setLoadedProperty(c,d[c]);});}#i(t,e){if(this.requireAddressable(),this.#n){this.#n[t]=e;return}let o={[t]:e};this.#n=o;let r=this.#r(),i=`${this.path.label}.${t}`;this.commandAnswering(`${this.path.label}.paragraphFormat`,()=>(this.#n=void 0,{op:"setParagraphFormat",paragraph:{paragraph:r},format:o}),s=>{A(s,i);});}#a(t){let e=this.#r(),o=L.promised(this.context,t,false);return this.read(t,()=>({op:"getParagraphList",paragraph:e}),r=>{o.hydrateAddress({kind:"handle",handle:g(r,t)});}),o}#r(){return this.requireAddressable(),this.path.handle()}},Vt=["style","alignment","firstLineIndent","leftIndent","rightIndent","lineSpacing","spaceBefore","spaceAfter"],fe=["Left","Centered","Right","Justified"];function ye(n,t){return fe.includes(n)||a({code:"InvalidArgument",target:t}),n}function X(n,t){return (typeof n!="number"||!Number.isFinite(n))&&a({code:"InvalidArgument",target:t}),n}function be(n,t){(!Array.isArray(n)||n.length===0||n.length>ge)&&a({code:"InvalidArgument",target:t});for(let e of n)(typeof e!="string"||e.length===0)&&a({code:"InvalidArgument",target:t});return [...n]}function Wt(n,t){return n!==void 0&&typeof n!="boolean"&&a({code:"InvalidArgument",target:t}),n===true}var v=class n extends M{#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)}},k=class n extends M{#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 pt(t,e).length}addressAt(t,e,o){let r=pt(t,e)[o];return r?{kind:"span",span:r}:void 0}itemAt(t,e){return h.at(this.context,t,e)}promised(t,e){return h.promised(this.context,t,e)}};var zt=4096,D=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.#i("tag",{tag:Pt(t,`${this.path.label}.tag`)});}get title(){return this.loadedProperty("title")}set title(t){this.#i("title",{title:Pt(t,`${this.path.label}.title`)});}get subtype(){return this.loadedProperty("subtype")}get cannotDelete(){let t=this.loadedProperty("lock");return t==="sdtLocked"||t==="sdtContentLocked"}set cannotDelete(t){this.#a(t,this.cannotEdit,`${this.path.label}.cannotDelete`);}get cannotEdit(){let t=this.loadedProperty("lock");return t==="contentLocked"||t==="sdtContentLocked"}set cannotEdit(t){this.#a(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.#r()})),this.#e}get contentControls(){return this.#o??=j.of(this.context,`${this.path.label}.contentControls`,this.path,{contentControl:this.#r()}),this.#o}getRange(t){let e=`${this.path.label}.getRange`,o=xe(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=Ae(t,e),r=this.#r();this.command("setValue",()=>({op:"setContentControlValue",contentControl:r,value:o}));}insertText(t,e){let o=`${this.path.label}.insertText`,r=C(t,o),i=e==="Replace"?"replace":e==="Start"?"start":e==="End"?"end":a({code:"InvalidArgument",target:o}),s=this.#r(),d=h.promised(this.context,o,false);return this.commandAnswering(o,()=>({op:"insertContentControlText",contentControl:s,text:r,at:i}),c=>{d.hydrateAddress({kind:"span",span:f(c,o)});}),d}delete(t){let e=`${this.path.label}.delete`;typeof t!="boolean"&&a({code:"InvalidArgument",target:e});let o=this.#r();this.command("delete",()=>({op:"deleteContentControl",contentControl:o,keepContent:t}));}onLoad(t){let e=this.selection(t,["id","tag","title","subtype","text","cannotDelete","cannotEdit","placeholderShown","temporary"]),o=this.#r();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("text")&&this.loadTextInto("text",()=>({op:"getContentControlText",contentControl:o})),e.includes("cannotDelete")||e.includes("cannotEdit")){let i=`${this.path.label}.lock`;this.read(i,()=>({op:"getContentControlLock",contentControl:o}),s=>{this.setLoadedProperty("lock",x(s,i));});}if(e.includes("placeholderShown")){let i=`${this.path.label}.placeholderShown`;this.read(i,()=>({op:"getContentControlPlaceholderShown",contentControl:o}),s=>{this.setLoadedProperty("placeholderShown",B(s,i));});}if(!e.includes("temporary"))return;let r=`${this.path.label}.temporary`;this.read(r,()=>({op:"getContentControlTemporary",contentControl:o}),i=>{this.setLoadedProperty("temporary",B(i,r));});}#n(t,e){let o=this.#r(),r=h.promised(this.context,t,false);return this.read(t,()=>({op:"getContentControlRange",contentControl:o,location:e}),i=>{r.hydrateAddress({kind:"span",span:f(i,t)});}),r}#i(t,e){let o=this.#r();this.command(t,()=>({op:"setContentControlProperties",contentControl:o,...e}));}#a(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.#r();this.command(o,()=>({op:"setContentControlProperties",contentControl:i,lock:r}));}#r(){return this.requireAddressable(),this.path.handle()}},j=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=D.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:g(i,e)});}}),r}getByTag(t){let e=`${this.path.label}.getByTag`,o=Ut(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=Ut(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 D.at(this.context,t,e)}promised(t,e){return D.promised(this.context,t,e)}};function Pt(n,t){return (typeof n!="string"||n.length>zt)&&a({code:"InvalidArgument",target:t}),n}function Ut(n,t){let e=Pt(n,t);return e.length===0&&a({code:"InvalidArgument",target:t}),e}function xe(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 Ae(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});}function Gt(n){if(n.length===0)return null;let t=new Date(n);return Number.isNaN(t.getTime())?null:t}var yt=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")}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",Gt(x(d,s)));});}if(!o.includes("resolved"))return;let i=`${this.path.label}.resolved`;this.read(i,()=>({op:"getCommentResolved",comment:r}),s=>{this.setLoadedProperty("resolved",B(s,i));});}commentHandle(){return this.requireAddressable(),this.path.handle()}},F=class n extends yt{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,[]);}},st=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 F.at(this.context,t,e)}promised(t,e){return F.promised(this.context,t,e)}},K=class n extends yt{#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=>{A(r,e);});}get replies(){return this.#t??=st.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=h.promised(this.context,t,false);return this.read(t,()=>({op:"getCommentRange",comment:e}),r=>{o.hydrateAddress({kind:"span",span:f(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=F.promised(this.context,e,false);return this.commandAnswering(e,()=>({op:"replyToComment",comment:r,text:t,author:o}),s=>{i.hydrateAddress({kind:"handle",handle:g(s,e)});}),i}onLoad(t){this.loadCommentFields(t,["resolved"]);}},E=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 K.at(this.context,t,e)}promised(t,e){return K.promised(this.context,t,e)}},Y=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=h.promised(this.context,t,false);return this.read(t,()=>({op:"getRevisionRange",revision:e}),r=>{o.hydrateAddress({kind:"span",span:f(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",Gt(x(i,r)));});}#t(){return this.requireAddressable(),this.path.handle()}},q=class n extends y{#t;#e;static of(t,e,o,r,i){return new n(t,l.derived(e,o),r,i)}constructor(t,e,o,r){super(t,e),this.#t=o,this.#e=r;}acceptAll(){let t=this.#e;this.commandOn("acceptAll",()=>({op:"acceptAllRevisions",document:t}));}rejectAll(){let t=this.#e;this.commandOn("rejectAll",()=>({op:"rejectAllRevisions",document:t}));}listing(){return {op:"getRevisions",body:this.#t}}itemAt(t,e){return Y.at(this.context,t,e)}promised(t,e){return Y.promised(this.context,t,e)}commandOn(t,e){let o=`${this.path.label}.${t}`;this.enqueue({sort:"write",label:o,plan:e,settle:r=>{A(r,o);}});}};var I=class n extends p{#t;#e;#o;#n;#i;static main(t,e){return new n(t,l.of(e,ot(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 font(){return this.#e??=S.of(this.context,`${this.path.label}.font`,this.path,"body"),this.#e}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=z(t,e);this.requireAddressable(),this.command("style",()=>({op:"setStyle",span:T(this.path,"body"),name:o}));}get lists(){return this.#o??=W.of(this.context,`${this.path.label}.lists`,this.path,this.#r()),this.#o}get contentControls(){return this.#n??=j.of(this.context,`${this.path.label}.contentControls`,this.path,{body:this.#r()}),this.#n}getComments(){let t=`${this.path.label}.getComments`,e=this.#r();return E.of(this.context,t,this.path,()=>({op:"getComments",scope:{body:e}}))}get revisions(){return this.#i??=q.of(this.context,`${this.path.label}.revisions`,this.path,this.#r(),this.internals.roots().document),this.#i}search(t,e){let o=`${this.path.label}.search`;typeof t!="string"&&a({code:"InvalidArgument",target:o});let r=ft(e,o),i=this.#r();return k.of(this.context,o,this.path,()=>({op:"search",scope:{body:i},text:t,...r===void 0?{}:{options:r}}))}clear(){let t=this.#r();this.commandDiscarding("clear",()=>({op:"replaceSpan",span:{body:t},text:""}));}insertText(t,e){let o=`${this.path.label}.insertText`,r=C(t,o),i=Nt(e,o),s=this.#r(),d=h.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:f(c,o)});}),d}insertParagraph(t,e){let o=`${this.path.label}.insertParagraph`,r=C(t,o),i=$t(e,o),s=this.#r(),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.#r();this.loadTextInto("text",()=>({op:"getText",target:o}));}e.includes("style")&&this.#a();}#a(){let t=`${this.path.label}.style`;this.requireAddressable(),this.read(t,()=>({op:"getStyle",span:T(this.path,"body")}),e=>{this.setLoadedProperty("style",nt(e,t));});}#r(){return this.requireAddressable(),this.path.handle()}};function Ce(n){return n==="endnote"?"Endnote":"Footnote"}var Z=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 body(){if(this.#t)return this.#t;let t=`${this.path.label}.body`,e=this.#e(),o=I.promisedStory(this.context,t);return this.read(t,()=>({op:"getNoteBody",note:e}),r=>{o.hydrateAddress({kind:"handle",handle:g(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=x(d,i)==="endnote"?"endnote":"footnote";}),this.read(t,()=>({op:"getNotes",document:r,noteKind:s}),d=>{let c=P(d,t),b=c.findIndex(It=>It.ref===e.ref),N=b<0?void 0:c[b+1];N||a({code:"ItemNotFound",target:t}),o.hydrateAddress({kind:"handle",handle:N});}),o}onLoad(t){if(!this.selection(t,["type"]).includes("type"))return;let e=`${this.path.label}.type`,o=this.#e();this.read(e,()=>({op:"getNoteKind",note:o}),r=>{this.setLoadedProperty("type",Ce(x(r,e)));});}#e(){return this.requireAddressable(),this.path.handle()}},H=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 Z.at(this.context,t,e)}promised(t,e){return Z.promised(this.context,t,e)}};var ve=Object.freeze({Primary:"default",FirstPage:"first",EvenPages:"even"}),Oe=["pageWidth","pageHeight","orientation","topMargin","rightMargin","bottomMargin","leftMargin"],dt=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",J(t,`${this.path.label}.pageWidth`));}get pageHeight(){return this.loadedProperty("pageHeight")}set pageHeight(t){this.#e("pageHeight",J(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",J(t,`${this.path.label}.topMargin`));}get bottomMargin(){return this.loadedProperty("bottomMargin")}set bottomMargin(t){this.#e("bottomMargin",J(t,`${this.path.label}.bottomMargin`));}get leftMargin(){return this.loadedProperty("leftMargin")}set leftMargin(t){this.#e("leftMargin",J(t,`${this.path.label}.leftMargin`));}get rightMargin(){return this.loadedProperty("rightMargin")}set rightMargin(t){this.#e("rightMargin",J(t,`${this.path.label}.rightMargin`));}onLoad(t){let e=this.selection(t,Oe);if(e.length===0)return;let o=`${this.path.label}.pageSetup`,r=this.#o();this.read(o,()=>({op:"getPageSetup",section:r}),i=>{let s=Ot(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=>{A(s,i);});}#o(){this.requireAddressable();let t=this.path.address();return t.kind!=="handle"&&a({code:"InvalidObjectPath",target:this.path.label}),t.handle}},_=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??=I.main(this.context,`${this.path.label}.body`),this.#e}get pageSetup(){return this.#t??=dt.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(b=>b.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=ve[e];i===void 0&&a({code:"InvalidArgument",target:r});let s=this.#n(),d=I.promisedStory(this.context,r);return this.read(r,()=>({op:"getFurniture",section:s,kind:t,variant:i}),c=>{d.hydrateAddress({kind:"handle",handle:g(c,r)});}),d}#n(){return this.requireAddressable(),this.path.handle()}},tt=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 _.at(this.context,t,e)}promised(t,e){return _.promised(this.context,t,e)}};function J(n,t){return (typeof n!="number"||!Number.isFinite(n)||n<0)&&a({code:"InvalidArgument",target:t}),n}var et=class n extends p{#t;#e;#o;#n;#i;#a;#r;#s;static open(t){return new n(t)}constructor(t){super(t,l.of("document",ot(t).roots().document));}get body(){return this.#t??=I.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??=tt.of(this.context,"document.sections",this.path,()=>({op:"getSections",document:t})),this.#o}get contentControls(){return this.#a??=j.of(this.context,"document.contentControls",this.path,{body:this.internals.roots().body}),this.#a}get comments(){return this.#n??=E.of(this.context,"document.comments",this.path,()=>({op:"getComments",scope:{body:this.internals.roots().body}})),this.#n}get revisions(){return this.#i??=q.of(this.context,"document.revisions",this.path,this.internals.roots().body,this.path.handle()),this.#i}get footnotes(){let t=this.path.handle();return this.#r??=H.of(this.context,"document.footnotes",this.path,()=>({op:"getNotes",document:t,noteKind:"footnote"})),this.#r}get endnotes(){let t=this.path.handle();return this.#s??=H.of(this.context,"document.endnotes",this.path,()=>({op:"getNotes",document:t,noteKind:"endnote"})),this.#s}onLoad(t){this.selection(t,[]);}};function Xt(n){let t=n.host,e=t.capabilities,o=typeof n.author=="string"&&n.author.trim().length>0?n.author:void 0,r=false,i=null,s=m=>{r&&a({code:"RuntimeDisposed",...m===void 0?{}:{target:m}});},d=()=>{if(i)return i;s("document");let m=Qt(t.execute({operations:[{op:"getDocument"}]}),"document"),bt=Qt(t.execute({operations:[{op:"getBody",document:m}]}),"document.body");return i={document:m,body:bt},i},c={host:t,capabilities:e,...o===void 0?{}:{author:o},id:{},roots:d,assertLive:s,openDocument:m=>et.open(m)};try{d();}catch{i=null;}async function b(m,bt){s();let St=typeof m=="function"?m:bt,Yt=typeof m=="function"?[]:Array.isArray(m)?m:[m];typeof St!="function"&&a({code:"InvalidArgument",target:"run"});let{context:Zt,adopt:Jt,finish:_t}=it.begin(c);try{return Jt(Yt),await St(Zt)}finally{_t();}}let N={capabilities:e,run:b,dispose(){r||(r=true,i=null,t.dispose());}};return n.save?{...N,async save(){s("save"),e.save||a({code:"NotSupported",target:"save"});let m=t.save();if(!m.ok)throw ut(m.error,{target:"save"});return m.bytes}}:N}function Qt(n,t){let e=n.results[0];if(e?.status==="error")throw ut(e.error,{target:t});if(e?.status!=="ok")throw new u({code:"GeneralException",target:t});return g(e.value,t)}async function Kt(n,t={}){let e=automation.createServerAutomationHost(n,{...t.limits===void 0?{}:{limits:t.limits}});return e.ok||a({code:"InvalidArgument",target:"createServer"}),Xt({host:e.host,save:true,...t.author===void 0?{}:{author:t.author}})}var Pr=Object.freeze({createServer:Kt});exports.Body=I;exports.Bookmark=G;exports.BookmarkCollection=Q;exports.ClientObject=w;exports.ClientResult=At;exports.Comment=K;exports.CommentCollection=E;exports.CommentReply=F;exports.CommentReplyCollection=st;exports.ContentControl=D;exports.ContentControlCollection=j;exports.Document=et;exports.DocxEditor=Pr;exports.DocxEditorError=u;exports.Font=S;exports.List=L;exports.ListCollection=W;exports.ListItem=U;exports.NoteItem=Z;exports.NoteItemCollection=H;exports.PageSetup=dt;exports.Paragraph=O;exports.ParagraphCollection=v;exports.Range=h;exports.RangeCollection=k;exports.RequestContext=it;exports.Revision=Y;exports.RevisionCollection=q;exports.Section=_;exports.SectionCollection=tt;exports.TrackedObjects=rt;exports.isDocxEditorError=te;