@docx-editor.dev/editor-api 2.16.2 → 2.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/OFFICE_JS_GUIDE.md +81 -21
- package/README.md +72 -78
- package/dist/browser.d.mts +2 -2
- package/dist/browser.d.ts +2 -2
- package/dist/browser.js +1 -1
- package/dist/browser.mjs +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{server-Dszoi8AN.d.mts → server-wsxDd90b.d.mts} +897 -420
- package/dist/{server-Dszoi8AN.d.ts → server-wsxDd90b.d.ts} +897 -420
- package/package.json +5 -2
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {createServerAutomationHost}from'@docx-editor.dev/core/automation';var wt=Object.freeze({PropertyNotLoaded:"the property has not been loaded. Call load(...) and await context.sync() before reading it.",ValueNotLoaded:"the result has not been filled in yet. Await context.sync() before reading it.",InvalidObjectPath:"the object cannot be addressed. An object an item accessor answered is usable after the next await context.sync(); an object whose run has ended is released for good, unless context.trackedObjects.add(...) kept it.",ObjectInUse:"the object still belongs to a run that has not finished. Await that run before passing the object to another one.",InvalidArgument:"the argument is not one this API accepts.",ResourceLimitExceeded:"the document exceeds a supported resource limit.",ItemNotFound:"the collection has no such item.",NotSupported:"this document host does not support that operation.",NotImplemented:"this version does not implement that yet.",ConflictingChanges:"two changes in this batch affect the same paragraph. Split them across two context.sync() calls.",InvalidRequestContext:"the request context has finished. Start another run to continue.",RuntimeDisposed:"the runtime has been disposed.",StaleDocument:"the document changed after this context read it, so nothing was applied.",DocumentUnavailable:"the document is not available right now.",GeneralException:"the document could not complete the request."}),u=class extends Error{code;limit;target;expectedRevision;actualRevision;constructor(t){let e=t.target?`${wt[t.code]} (${t.target})`:wt[t.code];super(e),this.name="DocxEditorError",this.code=t.code,t.limit!==void 0&&(this.limit=t.limit),t.target!==void 0&&(this.target=t.target),t.expectedRevision!==void 0&&(this.expectedRevision=t.expectedRevision),t.actualRevision!==void 0&&(this.actualRevision=t.actualRevision);}};function oe(n){return n instanceof u?true:typeof n=="object"&&n!==null&&n.name==="DocxEditorError"&&typeof n.code=="string"}function a(n){throw new u(n)}var F=Symbol("docx-editor.runtime.internals"),mt=Symbol("docx-editor.runtime.release"),gt=Symbol("docx-editor.runtime.rebind");function H(n){return n[F]}var ne=new Set(["select","expand","top","skip"]),re=/^[A-Za-z][A-Za-z0-9]*$/;function Tt(n,t){if(n===void 0)return [];let e=typeof n=="string"?n.split(",").map(r=>r.trim()):Array.isArray(n)?n.map(r=>typeof r=="string"?r.trim():r):a({code:"InvalidArgument",target:t}),o=[];for(let r of e)(typeof r!="string"||!re.test(r))&&a({code:"InvalidArgument",target:t}),o.includes(r)||o.push(r);return o.length===0&&a({code:"InvalidArgument",target:t}),o}function Et(n,t){return (typeof n!="number"||!Number.isInteger(n)||n<0)&&a({code:"InvalidArgument",target:t}),n}function ie(n,t){n===void 0||Array.isArray(n)&&n.length===0||a({code:"InvalidArgument",target:t});}function Nt(n,t){if(n===void 0)return {select:[]};if(typeof n=="string"||Array.isArray(n))return {select:Tt(n,t)};(typeof n!="object"||n===null)&&a({code:"InvalidArgument",target:t});let e=n;for(let o of Object.keys(e))ne.has(o)||a({code:"InvalidArgument",target:`${t}.${o}`});return ie(e.expand,`${t}.expand`),{select:Tt(e.select,`${t}.select`),...e.top===void 0?{}:{top:Et(e.top,`${t}.top`)},...e.skip===void 0?{}:{skip:Et(e.skip,`${t}.skip`)}}}var T=class{#t;#e;#o;#n;#r=new Map;constructor(t,e,o={}){this.#t=t,this.#e=t[F],this.#o=e,this.#n=o.nullable===true,this.#e.register(this);}get context(){return this.#t}get isNullObject(){return this.#o.isReleased&&a({code:"InvalidObjectPath",target:this.#o.label}),this.#n?(this.#o.isPending&&a({code:"PropertyNotLoaded",target:`${this.#o.label}.isNullObject`}),this.#o.isNull):false}load(t){return this.requireAddressable(),this.onLoad(Nt(t,this.#o.label)),this}get path(){return this.#o}get internals(){return this.#e}handle(){return this.#o.handle()}requireAddressable(){this.#o.isAddressable||a({code:"InvalidObjectPath",target:this.#o.label}),this.#e.assertUsable(this.#o.label);}enqueue(t){this.requireAddressable(),this.#e.queue.push(t);}loadedProperty(t){return this.#o.isReleased&&!this.#r.has(t)&&a({code:"InvalidObjectPath",target:this.#o.label}),this.#r.has(t)||a({code:"PropertyNotLoaded",target:`${this.#o.label}.${t}`}),this.#r.get(t)}hasLoadedProperty(t){return this.#r.has(t)}setLoadedProperty(t,e){this.#r.set(t,e);}[mt](){this.#o.release();}[gt](t){this.#t=t,this.#e=t[F];}};var Ot=class n{#t=false;#e;#o;constructor(t){this.#o=t;}get value(){return this.#t||a({code:"ValueNotLoaded",target:this.#o}),this.#e}get isLoaded(){return this.#t}static create(t){let e=new n(t);return {result:e,fill(o){e.#t=true,e.#e=o;}}}};function O(n){return new u({code:"GeneralException",target:n})}function b(n,t){if(n.kind!=="text")throw O(t);return n.text}function f(n,t){if(n.kind!=="handle")throw O(t);return n.handle}function P(n,t){if(n.kind!=="handles")throw O(t);return n.handles}function x(n,t){if(n.kind!=="span")throw O(t);return n.span}function ft(n,t){if(n.kind!=="spans")throw O(t);return n.spans}function Pt(n,t){if(n.kind!=="font")throw O(t);return n.font}function kt(n,t){if(n.kind!=="paragraphFormat")throw O(t);return n.format}function at(n,t){if(n.kind!=="style")throw O(t);return n.name}function yt(n,t){if(n.kind!=="number")throw O(t);return n.value}function M(n,t){if(n.kind!=="flag")throw O(t);return n.value}function It(n,t){if(n.kind!=="pageSetup")throw O(t);return n.setup}function C(n,t){if(n.kind!=="applied")throw O(t)}var l=class n{label;#t;#e;constructor(t,e,o=null){this.label=t,this.#t=e,this.#e=o;}static of(t,e){return new n(t,{status:"resolved",address:{kind:"handle",handle:e}})}static ofSpan(t,e){return new n(t,{status:"resolved",address:{kind:"span",span:e}})}static pending(t){return new n(t,{status:"pending"})}static derived(t,e){return new n(t,{status:"pending"},e)}get state(){return this.#e?this.#e.state:this.#t}get isAddressable(){return this.state.status==="resolved"}get isPending(){return this.state.status==="pending"}get isNull(){return this.state.status==="null"}get isReleased(){return this.state.status==="released"}address(){let t=this.state;if(t.status==="resolved")return t.address;a({code:"InvalidObjectPath",target:this.label});}handle(){let t=this.address();return t.kind!=="handle"&&a({code:"InvalidObjectPath",target:this.label}),t.handle}span(){let t=this.address();return t.kind!=="span"&&a({code:"InvalidObjectPath",target:this.label}),t.span}resolveTo(t){this.#o({kind:"handle",handle:t});}resolveToSpan(t){this.#o({kind:"span",span:t});}resolveNull(){this.#t.status!=="released"&&(this.#t={status:"null"});}release(){this.#e||(this.#t={status:"released"});}#o(t){this.#t.status!=="released"&&(this.#t={status:"resolved",address:t});}};function qt(n){let t=[],e=false,o=false;for(let r of n)t.push(r.plan()),r.sort==="write"?o=true:e=true;return {operations:t,hasRead:e,hasWrite:o}}var ae=Object.freeze({"stale-revision":"StaleDocument","invalid-handle":"InvalidObjectPath","invalid-offset":"InvalidArgument","unsupported-capability":"NotSupported",disposed:"RuntimeDisposed","transaction-refused":"GeneralException","unknown-operation":"NotSupported","unsupported-content":"InvalidArgument","unsupported-revision":"NotImplemented","ambiguous-document":"GeneralException","conflicting-operations":"ConflictingChanges","document-unavailable":"DocumentUnavailable"});function bt(n,t={}){let e=ae[n.code]??"GeneralException",o=e==="StaleDocument";return new u({code:e,...t.target===void 0?{}:{target:t.target},...o&&t.expectedRevision!==void 0?{expectedRevision:t.expectedRevision}:{},...o&&t.actualRevision!==void 0?{actualRevision:t.actualRevision}:{}})}function $t(n,t,e){for(let o=0;o<n.results.length;o+=1){let r=n.results[o];if(r?.status!=="error")continue;let i=t[o]?.label;return bt(r.error,{...i===void 0?{}:{target:i},...e===void 0?{}:{expectedRevision:e},actualRevision:n.revision})}return new u({code:"GeneralException"})}function Dt(n,t){if(t.results.length!==n.length)throw new u({code:"GeneralException"});for(let e=0;e<n.length;e+=1){let o=t.results[e],r=n[e];if(o.status!=="ok")throw new u({code:"GeneralException",target:r.label});r.settle(o.value);}}var xt=class{#t=[];get size(){return this.#t.length}get pending(){return this.#t}push(t){this.#t.push(t);}take(){let t=this.#t;return this.#t=[],t}clear(){this.#t=[];}};function Bt(n,t){if(Array.isArray(n)){for(let e of n)t(e);return}t(n);}var st=class{#t;#e;constructor(t,e){this.#t=t,this.#e=e;}add(t){this.#t.assertUsable(),Bt(t,e=>{this.#o(e),this.#t.track(e);});}remove(t){this.#t.assertUsable(),Bt(t,e=>{this.#o(e),this.#t.untrack(e);});}#o(t){this.#e(t)||a({code:"InvalidObjectPath"});}};var dt=class n{#t;#e=new xt;#o=new Set;#n=new Set;#r;#s;#i;#a=false;#d=null;constructor(t){this.#t=t,this.#r={host:t.host,capabilities:t.capabilities,...t.author===void 0?{}:{author:t.author},revisionTextView:t.revisionTextView,queue:this.#e,session:t.id,roots:()=>t.roots(),assertUsable:e=>{this.#t.assertLive(e),this.#a&&a({code:"InvalidRequestContext",...e===void 0?{}:{target:e}});},isFinished:()=>this.#a,readRevision:()=>this.#d,register:e=>{this.#o.add(e);},track:e=>{this.#n.add(e);},untrack:e=>{this.#n.delete(e);},isTracked:e=>this.#n.has(e),disown:e=>{this.#o.delete(e),this.#n.delete(e);}},this.#s=new st(this.#r,e=>this.#o.has(e));}get document(){return this.#r.assertUsable("document"),this.#i??=this.#t.openDocument(this),this.#i}get capabilities(){return this.#t.capabilities}get trackedObjects(){return this.#s}async sync(){this.#r.assertUsable();let t=this.#e.take();if(t.length===0)return;let e=qt(t),r=e.hasWrite&&this.#d!==null?this.#d:void 0,i={operations:e.operations,...r===void 0?{}:{expectedRevision:r}},s=this.#t.host.execute(i);if(!s.ok)throw $t(s,t,r);Dt(t,s),(e.hasRead||e.hasWrite)&&(this.#d=s.revision);}get[F](){return this.#r}static begin(t){let e=new n(t);return {context:e,adopt(o){for(let r of o)e.#l(r);},finish(){e.#p();}}}#l(t){let e=t.context;if(e===this)return;let o=e[F];if(o.session!==this.#t.id)throw new u({code:"InvalidObjectPath"});if(!o.isFinished())throw new u({code:"ObjectInUse"});if(!o.isTracked(t))throw new u({code:"InvalidObjectPath"});let r=o.readRevision();o.disown(t),t[gt](this),this.#o.add(t),this.#n.add(t),r!==null&&this.#c(r);}#c(t){this.#d=this.#d===null?t:Math.min(this.#d,t);}#p(){if(!this.#a){this.#a=true,this.#e.clear();for(let t of this.#o)this.#n.has(t)||t[mt]();this.#o.clear();}}};function lt(n,t,e){if(n.select.length===0)return t;for(let o of n.select)t.includes(o)||a({code:"InvalidArgument",target:`${e}.${o}`});return n.select}var Q=class extends T{#t;#e=[];constructor(t,e){super(t,e);}get items(){return this.loadedProperty("items")}fill(t,e){this.setLoadedProperty("items",this.#n(t,e,0,void 0)),this.#t={value:t,label:e};let o=this.#e.splice(0,this.#e.length);for(let r of o)this.#o(r,t);}onLoad(t){lt(t,["items"],this.path.label);let e=this.listing();if(!e)return;let o=`${this.path.label}.items`,r=t.skip??0,i=t.top;this.enqueue({sort:"read",label:o,plan:()=>e,settle:s=>{this.setLoadedProperty("items",this.#n(s,o,r,i));}});}edge(t,e,o){let r=`${this.path.label}.${e}()`,i=this.promised(r,o),s=this.listing();if(!s){let d={edge:t,target:r,nullable:o,item:i};return this.#t?this.#o(d,this.#t.value):this.#e.push(d),i}return this.enqueue({sort:"read",label:r,plan:()=>s,settle:d=>{this.#o({edge:t,target:r,nullable:o,item:i},d);}}),i}#o(t,e){let{edge:o,target:r,nullable:i,item:s}=t,d=this.size(e,r);if(d===0){i||a({code:"ItemNotFound",target:r}),s.hydrateNull();return}let c=this.addressAt(e,r,o==="first"?0:d-1);c||a({code:"ItemNotFound",target:r}),s.hydrateAddress(c);}#n(t,e,o,r){let i=this.size(t,e),s=r===void 0?i:Math.min(i,o+r),d=[];for(let c=o;c<s;c+=1){let g=this.addressAt(t,e,c);g&&d.push(this.itemAt(`${e}[${String(c)}]`,g));}return d}},y=class extends Q{size(t,e){return P(t,e).length}addressAt(t,e,o){let r=P(t,e)[o];return r?{kind:"handle",handle:r}:void 0}};var se=["Replace","Start","End"],de=["Start","End"],le=["Replace","Start","End"],ce=["Before","After"],pe=["Replace","Start","End","Before","After"],he=["Select","Start","End"];function X(n,t,e){return (typeof n!="string"||!t.includes(n))&&a({code:"InvalidArgument",target:e}),n}var Ft=(n,t)=>X(n,se,t),Ht=(n,t)=>X(n,de,t),Mt=(n,t)=>X(n,le,t),Vt=(n,t)=>X(n,ce,t),St=(n,t)=>X(n,pe,t),Ct=(n,t)=>n===void 0?"Select":X(n,he,t);function A(n,t){return typeof n!="string"&&a({code:"InvalidArgument",target:t}),/[\r\n\v\f\u2028\u2029]/.test(n)&&a({code:"InvalidArgument",target:t}),n}var p=class extends T{revisionTextView(){return H(this.context).revisionTextView}loadTextInto(t,e){let o=`${this.path.label}.${t}`;this.enqueue({sort:"read",label:o,plan:e,settle:r=>{this.setLoadedProperty(t,b(r,o));}});}command(t,e){let o=`${this.path.label}.${t}`;this.enqueue({sort:"write",label:o,plan:e,settle:r=>C(r,o)});}commandDiscarding(t,e){let o=`${this.path.label}.${t}`;this.enqueue({sort:"write",label:o,plan:e,settle:()=>{}});}commandAnswering(t,e,o){this.enqueue({sort:"write",label:t,plan:e,settle:o});}read(t,e,o){this.enqueue({sort:"read",label:t,plan:e,settle:o});}selection(t,e){return lt(t,e,this.path.label)}onLoad(t){this.selection(t,[]);}};var ue=8,j=class n extends p{#t;static at(t,e,o){return o.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new n(t,l.of(e,o.handle),false)}static promised(t,e,o){return new n(t,l.pending(e),o)}constructor(t,e,o){super(t,e,{nullable:o});}hydrateAddress(t){t.kind==="handle"?this.path.resolveTo(t.handle):this.path.resolveNull();}hydrateNull(){this.path.resolveNull();}get id(){return this.loadedProperty("id")}get paragraphs(){return this.#t??=v.overListing(this.context,`${this.path.label}.paragraphs`,this.path,()=>({op:"getListParagraphs",list:this.#e()})),this.#t}getLevelParagraphs(t){let e=`${this.path.label}.getLevelParagraphs`,o=Wt(t,e),r=this.#e();return v.overListing(this.context,e,this.path,()=>({op:"getListParagraphs",list:r,level:o}))}insertParagraph(t,e){let o=`${this.path.label}.insertParagraph`,r=A(t,o);e!=="Start"&&e!=="End"&&e!=="Before"&&e!=="After"&&a({code:"InvalidArgument",target:o});let i=this.#e(),s=R.promised(this.context,o,false);return this.commandAnswering(o,()=>({op:"insertListParagraph",list:i,where:e==="Start"||e==="Before"?"start":"end",text:r}),d=>{s.hydrateAddress({kind:"handle",handle:f(d,o)});}),s}onLoad(t){if(!this.selection(t,["id"]).includes("id"))return;let e=`${this.path.label}.id`,o=this.#e();this.read(e,()=>({op:"getListId",list:o}),r=>{this.setLoadedProperty("id",yt(r,e));});}#e(){return this.requireAddressable(),this.path.handle()}},K=class n extends y{#t;static of(t,e,o,r){return new n(t,l.derived(e,o),r)}constructor(t,e,o){super(t,e),this.#t=o;}getFirst(){return this.edge("first","getFirst",false)}getById(t){let e=`${this.path.label}.getById`,o=me(t,e),r=this.#t,i=j.promised(this.context,e,false);return this.enqueue({sort:"read",label:e,plan:()=>({op:"getListById",body:r,id:o}),settle:s=>{i.hydrateAddress({kind:"handle",handle:f(s,e)});}}),i}listing(){return {op:"getLists",body:this.#t}}itemAt(t,e){return j.at(this.context,t,e)}promised(t,e){return j.promised(this.context,t,e)}},Z=class n extends p{static of(t,e,o){return new n(t,l.derived(e,o))}constructor(t,e){super(t,e);}get level(){return this.loadedProperty("level")}set level(t){let e=`${this.path.label}.level`,o=Wt(t,e),r=this.#t();this.commandAnswering(e,()=>({op:"setListLevel",paragraph:r,level:o}),i=>{C(i,e);});}onLoad(t){if(!this.selection(t,["level"]).includes("level"))return;let e=`${this.path.label}.level`,o=this.#t();this.read(e,()=>({op:"getListLevel",paragraph:o}),r=>{this.setLoadedProperty("level",yt(r,e));});}#t(){this.requireAddressable();let t=this.path.address();return t.kind!=="handle"&&a({code:"InvalidObjectPath",target:this.path.label}),t.handle}};function Wt(n,t){return (!Number.isInteger(n)||n<0||n>ue)&&a({code:"InvalidArgument",target:t}),n}function me(n,t){return (!Number.isInteger(n)||n<=0)&&a({code:"InvalidArgument",target:t}),n}function E(n,t){let e=n.address();return t==="span"?(e.kind!=="span"&&a({code:"InvalidObjectPath",target:n.label}),{start:e.span.start,end:e.span.end}):(e.kind!=="handle"&&a({code:"InvalidObjectPath",target:n.label}),t==="body"?{body:e.handle}:{paragraph:e.handle})}function Y(n,t){return (typeof n!="string"||n.trim().length===0||n.length>255)&&a({code:"InvalidArgument",target:t}),n}var ge=["bold","italic","color","name","size"],I=class n extends p{#t;#e;static of(t,e,o,r){return new n(t,l.derived(e,o),r)}constructor(t,e,o){super(t,e),this.#t=o;}get bold(){return this.loadedProperty("bold")}set bold(t){this.#o("bold",zt(t,`${this.path.label}.bold`));}get italic(){return this.loadedProperty("italic")}set italic(t){this.#o("italic",zt(t,`${this.path.label}.italic`));}get color(){return this.loadedProperty("color")}set color(t){this.#o("color",Ut(t,`${this.path.label}.color`));}get name(){return this.loadedProperty("name")}set name(t){this.#o("name",Ut(t,`${this.path.label}.name`));}get size(){return this.loadedProperty("size")}set size(t){this.#o("size",fe(t,`${this.path.label}.size`));}onLoad(t){let e=this.selection(t,ge);if(e.length===0)return;let o=`${this.path.label}.font`;this.read(o,()=>({op:"getFont",span:this.#n()}),r=>{let i=Pt(r,o);for(let s of e)this.setLoadedProperty(s,i[s]);});}#o(t,e){if(this.requireAddressable(),this.#e){this.#e[t]=e;return}let o={[t]:e};this.#e=o;let r=`${this.path.label}.${t}`;this.commandAnswering(this.path.label,()=>(this.#e=void 0,{op:"setFont",span:this.#n(),font:o}),i=>{C(i,r);});}#n(){return this.requireAddressable(),E(this.path,this.#t)}};function zt(n,t){return typeof n!="boolean"&&a({code:"InvalidArgument",target:t}),n}function fe(n,t){return (typeof n!="number"||!Number.isFinite(n))&&a({code:"InvalidArgument",target:t}),n}function Ut(n,t){return (typeof n!="string"||n.length===0)&&a({code:"InvalidArgument",target:t}),n}var ye=16,R=class n extends p{#t;#e;#o;#n;static at(t,e,o){return o.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new n(t,l.of(e,o.handle),false)}static promised(t,e,o){return new n(t,l.pending(e),o)}constructor(t,e,o){super(t,e,{nullable:o});}hydrateAddress(t){t.kind==="handle"?this.path.resolveTo(t.handle):this.path.resolveNull();}hydrateNull(){this.path.resolveNull();}get text(){return this.loadedProperty("text")}get uniqueLocalId(){return this.loadedProperty("uniqueLocalId")}get style(){return this.loadedProperty("style")}set style(t){this.#r("style",Y(t,`${this.path.label}.style`));}get font(){return this.#t??=I.of(this.context,`${this.path.label}.font`,this.path,"paragraph"),this.#t}get alignment(){return this.loadedProperty("alignment")}set alignment(t){this.#r("alignment",xe(t,`${this.path.label}.alignment`));}get firstLineIndent(){return this.loadedProperty("firstLineIndent")}set firstLineIndent(t){this.#r("firstLineIndent",J(t,`${this.path.label}.firstLineIndent`));}get leftIndent(){return this.loadedProperty("leftIndent")}set leftIndent(t){this.#r("leftIndent",J(t,`${this.path.label}.leftIndent`));}get rightIndent(){return this.loadedProperty("rightIndent")}set rightIndent(t){this.#r("rightIndent",J(t,`${this.path.label}.rightIndent`));}get lineSpacing(){return this.loadedProperty("lineSpacing")}set lineSpacing(t){this.#r("lineSpacing",J(t,`${this.path.label}.lineSpacing`));}get spaceBefore(){return this.loadedProperty("spaceBefore")}set spaceBefore(t){this.#r("spaceBefore",J(t,`${this.path.label}.spaceBefore`));}get spaceAfter(){return this.loadedProperty("spaceAfter")}set spaceAfter(t){this.#r("spaceAfter",J(t,`${this.path.label}.spaceAfter`));}get list(){return this.#e??=this.#s(`${this.path.label}.list`),this.#e}get listItem(){return this.#o??=Z.of(this.context,`${this.path.label}.listItem`,this.path),this.#o}clear(){let t=this.#i();this.commandDiscarding("clear",()=>({op:"replaceSpan",span:{paragraph:t},text:""}));}delete(){let t=this.#i();this.command("delete",()=>({op:"deleteParagraph",paragraph:t}));}insertText(t,e){let o=`${this.path.label}.insertText`,r=A(t,o),i=Mt(e,o),s=this.#i(),d=m.promised(this.context,o,false);return this.commandAnswering(o,()=>i==="Replace"?{op:"replaceSpan",span:{paragraph:s},text:r}:{op:"insertText",at:{paragraph:s,at:i==="Start"?"start":"end"},text:r},c=>{d.hydrateAddress({kind:"span",span:x(c,o)});}),d}insertParagraph(t,e){let o=`${this.path.label}.insertParagraph`,r=A(t,o),i=Vt(e,o),s=this.#i(),d=n.promised(this.context,o,false);return this.commandAnswering(o,()=>({op:"insertParagraph",anchor:{paragraph:s},where:i==="Before"?"before":"after",text:r}),c=>{c.kind!=="handle"&&a({code:"GeneralException",target:o}),d.hydrateAddress({kind:"handle",handle:c.handle});}),d}split(t,e,o){let r=`${this.path.label}.split`,i=Ce(t,r),s=Qt(e,`${r}.trimDelimiters`),d=Qt(o,`${r}.trimSpacing`),c=this.#i(),g=S.answered(this.context,r,this.path);return this.commandAnswering(r,()=>({op:"splitParagraph",paragraph:c,delimiters:i,...s?{trimDelimiters:true}:{},...d?{trimSpacing:true}:{}}),L=>{g.fill(L,r);}),g}onLoad(t){let e=this.selection(t,["text","uniqueLocalId",...Gt]),o=this.#i();e.includes("text")&&this.loadTextInto("text",()=>({op:"getText",target:o,projection:this.revisionTextView()})),e.includes("uniqueLocalId")&&this.loadTextInto("uniqueLocalId",()=>({op:"getParagraphId",paragraph:o}));let r=Gt.filter(s=>e.includes(s));if(r.length===0)return;let i=`${this.path.label}.paragraphFormat`;this.read(i,()=>({op:"getParagraphFormat",paragraph:{paragraph:o}}),s=>{let d=kt(s,i);for(let c of r)this.setLoadedProperty(c,d[c]);});}#r(t,e){if(this.requireAddressable(),this.#n){this.#n[t]=e;return}let o={[t]:e};this.#n=o;let r=this.#i(),i=`${this.path.label}.${t}`;this.commandAnswering(`${this.path.label}.paragraphFormat`,()=>(this.#n=void 0,{op:"setParagraphFormat",paragraph:{paragraph:r},format:o}),s=>{C(s,i);});}#s(t){let e=this.#i(),o=j.promised(this.context,t,false);return this.read(t,()=>({op:"getParagraphList",paragraph:e}),r=>{o.hydrateAddress({kind:"handle",handle:f(r,t)});}),o}#i(){return this.requireAddressable(),this.path.handle()}},Gt=["style","alignment","firstLineIndent","leftIndent","rightIndent","lineSpacing","spaceBefore","spaceAfter"],be=["Left","Centered","Right","Justified"];function xe(n,t){return be.includes(n)||a({code:"InvalidArgument",target:t}),n}function J(n,t){return (typeof n!="number"||!Number.isFinite(n))&&a({code:"InvalidArgument",target:t}),n}function Ce(n,t){(!Array.isArray(n)||n.length===0||n.length>ye)&&a({code:"InvalidArgument",target:t});for(let e of n)(typeof e!="string"||e.length===0)&&a({code:"InvalidArgument",target:t});return [...n]}function Qt(n,t){return n!==void 0&&typeof n!="boolean"&&a({code:"InvalidArgument",target:t}),n===true}var v=class n extends Q{#t;static of(t,e,o){return new n(t,l.derived(e,o),null)}static overListing(t,e,o,r){return new n(t,l.derived(e,o),r)}constructor(t,e,o){super(t,e),this.#t=o;}getFirst(){return this.edge("first","getFirst",false)}getLast(){return this.edge("last","getLast",false)}getFirstOrNullObject(){return this.edge("first","getFirstOrNullObject",true)}getLastOrNullObject(){return this.edge("last","getLastOrNullObject",true)}listing(){if(this.#t)return this.#t();let t=this.path.address();return t.kind==="handle"?{op:"getParagraphs",body:t.handle}:{op:"getSpanParagraphs",span:t.span}}size(t,e){return P(t,e).length}addressAt(t,e,o){let r=P(t,e)[o];return r?{kind:"handle",handle:r}:void 0}itemAt(t,e){return R.at(this.context,t,e)}promised(t,e){return R.promised(this.context,t,e)}},S=class n extends Q{#t;static of(t,e,o,r){return new n(t,l.derived(e,o),r)}static answered(t,e,o){return new n(t,l.derived(e,o),null)}constructor(t,e,o){super(t,e),this.#t=o;}getFirst(){return this.edge("first","getFirst",false)}getLast(){return this.edge("last","getLast",false)}getFirstOrNullObject(){return this.edge("first","getFirstOrNullObject",true)}listing(){return this.#t?this.#t():null}size(t,e){return ft(t,e).length}addressAt(t,e,o){let r=ft(t,e)[o];return r?{kind:"span",span:r}:void 0}itemAt(t,e){return m.at(this.context,t,e)}promised(t,e){return m.promised(this.context,t,e)}};function Ae(n,t){return t<1||t>12?0:t===2?n%4===0&&n%100!==0||n%400===0?29:28:t===4||t===6||t===9||t===11?30:31}function Xt(n){if(n.length===0)return null;let t=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,9}))?(Z|[+-]\d{2}:\d{2})$/.exec(n.trim());if(!t)return null;let e=Number(t[1]),o=Number(t[2]),r=Number(t[3]),i=Ae(e,o);if(e===0||i===0||r<1||r>i)return null;let s=Number(t[4]),d=Number(t[5]),c=Number(t[6]);if(s>23||d>59||c>59)return null;let g=t[7],L=g===void 0?0:Number(g.padEnd(3,"0").slice(0,3));if(Number.isNaN(L))return null;let U=`${t[1]}-${t[2]}-${t[3]}T${t[4]}:${t[5]}:${t[6]}.${String(L).padStart(3,"0")}Z`,ht=Date.parse(U);if(Number.isNaN(ht))return null;let h=t[8];if(h==="Z")return new Date(ht);let B=Number(h.slice(1,3)),G=Number(h.slice(4,6));if(G>59||B>14||B===14&&G!==0)return null;let Rt=h[0]==="+"?1:-1,ut=new Date(ht-Rt*(B*36e5+G*6e4));return Number.isNaN(ut.getTime())?null:ut}var At=class extends p{hydrateAddress(t){t.kind==="handle"?this.path.resolveTo(t.handle):this.path.resolveNull();}hydrateNull(){this.path.resolveNull();}get authorName(){return this.loadedProperty("authorName")}get creationDate(){return this.loadedProperty("creationDate")}get id(){return this.loadedProperty("id")}get text(){return this.loadedProperty("text")}delete(){let t=this.commentHandle();this.command("delete",()=>({op:"deleteComment",comment:t}));}loadCommentFields(t,e){let o=this.selection(t,["authorName","creationDate","id","text",...e]),r=this.commentHandle();if(o.includes("authorName")&&this.loadTextInto("authorName",()=>({op:"getCommentAuthor",comment:r})),o.includes("text")&&this.loadTextInto("text",()=>({op:"getCommentText",comment:r})),o.includes("id")&&this.loadTextInto("id",()=>({op:"getCommentId",comment:r})),o.includes("creationDate")){let s=`${this.path.label}.creationDate`;this.read(s,()=>({op:"getCommentDate",comment:r}),d=>{this.setLoadedProperty("creationDate",Xt(b(d,s)));});}if(!o.includes("resolved"))return;let i=`${this.path.label}.resolved`;this.read(i,()=>({op:"getCommentResolved",comment:r}),s=>{this.setLoadedProperty("resolved",M(s,i));});}commentHandle(){return this.requireAddressable(),this.path.handle()}},V=class n extends At{static at(t,e,o){return o.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new n(t,l.of(e,o.handle),false)}static promised(t,e,o){return new n(t,l.pending(e),o)}constructor(t,e,o){super(t,e,{nullable:o});}onLoad(t){this.loadCommentFields(t,[]);}},ct=class n extends y{#t;static of(t,e,o,r){return new n(t,l.derived(e,o),r)}constructor(t,e,o){super(t,e),this.#t=o;}getFirst(){return this.edge("first","getFirst",false)}listing(){return this.#t()}itemAt(t,e){return V.at(this.context,t,e)}promised(t,e){return V.promised(this.context,t,e)}},N=class n extends At{#t;static at(t,e,o){return o.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new n(t,l.of(e,o.handle),false)}static promised(t,e,o){return new n(t,l.pending(e),o)}constructor(t,e,o){super(t,e,{nullable:o});}get resolved(){return this.loadedProperty("resolved")}set resolved(t){let e=`${this.path.label}.resolved`;typeof t!="boolean"&&a({code:"InvalidArgument",target:e});let o=this.commentHandle();this.commandAnswering(e,()=>({op:"setCommentResolved",comment:o,resolved:t}),r=>{C(r,e);});}get replies(){return this.#t??=ct.of(this.context,`${this.path.label}.replies`,this.path,()=>({op:"getCommentReplies",comment:this.commentHandle()})),this.#t}getRange(){let t=`${this.path.label}.getRange`,e=this.commentHandle(),o=m.promised(this.context,t,false);return this.read(t,()=>({op:"getCommentRange",comment:e}),r=>{o.hydrateAddress({kind:"span",span:x(r,t)});}),o}reply(t){let e=`${this.path.label}.reply`;(typeof t!="string"||t.length===0)&&a({code:"InvalidArgument",target:e});let o=this.internals.author;(typeof o!="string"||o.trim().length===0)&&a({code:"NotSupported",target:e});let r=this.commentHandle(),i=V.promised(this.context,e,false);return this.commandAnswering(e,()=>({op:"replyToComment",comment:r,text:t,author:o}),s=>{i.hydrateAddress({kind:"handle",handle:f(s,e)});}),i}onLoad(t){this.loadCommentFields(t,["resolved"]);}},q=class n extends y{#t;static of(t,e,o,r){return new n(t,l.derived(e,o),r)}constructor(t,e,o){super(t,e),this.#t=o;}getFirst(){return this.edge("first","getFirst",false)}listing(){return this.#t()}itemAt(t,e){return N.at(this.context,t,e)}promised(t,e){return N.promised(this.context,t,e)}},_=class n extends p{static at(t,e,o){return o.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new n(t,l.of(e,o.handle),false)}static promised(t,e,o){return new n(t,l.pending(e),o)}constructor(t,e,o){super(t,e,{nullable:o});}hydrateAddress(t){t.kind==="handle"?this.path.resolveTo(t.handle):this.path.resolveNull();}hydrateNull(){this.path.resolveNull();}get author(){return this.loadedProperty("author")}get date(){return this.loadedProperty("date")}get type(){return this.loadedProperty("type")}get range(){let t=`${this.path.label}.range`,e=this.#t(),o=m.promised(this.context,t,false);return this.read(t,()=>({op:"getRevisionRange",revision:e}),r=>{o.hydrateAddress({kind:"span",span:x(r,t)});}),o}accept(){let t=this.#t();this.command("accept",()=>({op:"acceptRevision",revision:t}));}reject(){let t=this.#t();this.command("reject",()=>({op:"rejectRevision",revision:t}));}onLoad(t){let e=this.selection(t,["author","date","type"]),o=this.#t();if(e.includes("author")&&this.loadTextInto("author",()=>({op:"getRevisionAuthor",revision:o})),e.includes("type")&&this.loadTextInto("type",()=>({op:"getRevisionType",revision:o})),!e.includes("date"))return;let r=`${this.path.label}.date`;this.read(r,()=>({op:"getRevisionDate",revision:o}),i=>{this.setLoadedProperty("date",Xt(b(i,r)));});}#t(){return this.requireAddressable(),this.path.handle()}},$=class n extends y{#t;static of(t,e,o,r){return new n(t,l.derived(e,o),r)}constructor(t,e,o){super(t,e),this.#t=o;}acceptAll(){let t=this.#t;this.commandOn("acceptAll",()=>({op:"acceptAllRevisions",body:t}));}rejectAll(){let t=this.#t;this.commandOn("rejectAll",()=>({op:"rejectAllRevisions",body:t}));}listing(){return {op:"getRevisions",body:this.#t}}itemAt(t,e){return _.at(this.context,t,e)}promised(t,e){return _.promised(this.context,t,e)}commandOn(t,e){let o=`${this.path.label}.${t}`;this.enqueue({sort:"write",label:o,plan:e,settle:r=>{C(r,o);}});}};var ve=new Set(["matchCase","matchWholeWord","ignorePunct","ignoreSpace","matchWildcards"]);function vt(n,t){if(n===void 0)return;typeof n!="object"&&a({code:"InvalidArgument",target:t});for(let[o,r]of Object.entries(n))ve.has(o)||a({code:"InvalidArgument",target:`${t}.${o}`}),r!==void 0&&typeof r!="boolean"&&a({code:"InvalidArgument",target:`${t}.${o}`});let e={...n.matchCase===void 0?{}:{matchCase:n.matchCase},...n.matchWholeWord===void 0?{}:{matchWholeWord:n.matchWholeWord},...n.ignorePunct===void 0?{}:{ignorePunct:n.ignorePunct},...n.ignoreSpace===void 0?{}:{ignoreSpace:n.ignoreSpace},...n.matchWildcards===void 0?{}:{matchWildcards:n.matchWildcards}};return Object.keys(e).length===0?void 0:e}var m=class n extends p{#t;#e;#o;static at(t,e,o){return o.kind!=="span"&&a({code:"InvalidObjectPath",target:e}),new n(t,l.ofSpan(e,o.span),false)}static promised(t,e,o){return new n(t,l.pending(e),o)}constructor(t,e,o){super(t,e,{nullable:o});}hydrateAddress(t){t.kind==="span"?this.path.resolveToSpan(t.span):this.path.resolveNull();}hydrateNull(){this.path.resolveNull();}get text(){return this.loadedProperty("text")}get font(){return this.#e??=I.of(this.context,`${this.path.label}.font`,this.path,"span"),this.#e}get paragraphs(){return this.#t??=v.of(this.context,`${this.path.label}.paragraphs`,this.path),this.#t}get style(){return this.loadedProperty("style")}set style(t){let e=`${this.path.label}.style`,o=Y(t,e);this.requireAddressable(),this.command("style",()=>({op:"setStyle",span:E(this.path,"span"),name:o}));}get hyperlink(){return this.loadedProperty("hyperlink")}set hyperlink(t){let e=`${this.path.label}.hyperlink`;(typeof t!="string"||t.length>2048)&&a({code:"InvalidArgument",target:e});let o=this.#n();this.command("hyperlink",()=>({op:"setHyperlink",span:o,target:t}));}get bookmarks(){let t=this.#n();return this.#o??=D.of(this.context,`${this.path.label}.bookmarks`,this.path,()=>({op:"getBookmarks",scope:{start:t.start,end:t.end}})),this.#o}search(t,e){let o=`${this.path.label}.search`;typeof t!="string"&&a({code:"InvalidArgument",target:o});let r=vt(e,o),i=this.#n();return S.of(this.context,o,this.path,()=>({op:"search",scope:i,text:t,options:{...r??{},projection:this.revisionTextView()}}))}insertText(t,e){let o=`${this.path.label}.insertText`,r=A(t,o),i=St(e,o),s=this.#n(),d=n.promised(this.context,o,false);return this.commandAnswering(o,()=>i==="Replace"?{op:"replaceSpan",span:s,text:r}:{op:"insertText",at:i==="Start"||i==="Before"?s.start:s.end,text:r},c=>{d.hydrateAddress({kind:"span",span:x(c,o)});}),d}delete(){let t=this.#n();this.commandDiscarding("delete",()=>({op:"replaceSpan",span:t,text:""}));}clear(){let t=this.#n();this.commandDiscarding("clear",()=>({op:"replaceSpan",span:t,text:""}));}insertComment(t){let e=`${this.path.label}.insertComment`;(typeof t!="string"||t.length===0)&&a({code:"InvalidArgument",target:e});let o=this.internals.author;(typeof o!="string"||o.trim().length===0)&&a({code:"NotSupported",target:e});let r=this.#n(),i=N.promised(this.context,e,false);return this.commandAnswering(e,()=>({op:"insertComment",span:r,text:t,author:o}),s=>{s.kind!=="handle"&&a({code:"GeneralException",target:e}),i.hydrateAddress(s);}),i}insertParagraph(t,e){let o=`${this.path.label}.insertParagraph`,r=A(t,o),i=St(e,o);i!=="Before"&&i!=="After"&&a({code:"InvalidArgument",target:o});let s=this.#n(),d=i==="Before"?s.start.paragraph:s.end.paragraph,c=R.promised(this.context,o,false);return this.commandAnswering(o,()=>({op:"insertParagraph",anchor:{paragraph:d},where:i==="Before"?"before":"after",text:r}),g=>{g.kind!=="handle"&&a({code:"GeneralException",target:o}),c.hydrateAddress({kind:"handle",handle:g.handle});}),c}select(t){let e=`${this.path.label}.select`,o=Ct(t,e);this.requireAddressable(),this.internals.capabilities.selection||a({code:"NotSupported",target:e});let r=this.#n();this.command("select",()=>({op:"selectSpan",span:r,mode:o==="Select"?"select":o==="Start"?"start":"end"}));}onLoad(t){let e=this.selection(t,["text","style","hyperlink"]);if(e.includes("hyperlink")){let r=this.#n();this.loadTextInto("hyperlink",()=>({op:"getHyperlink",span:r}));}if(e.includes("text")){let r=this.#n(),i=`${this.path.label}.text`;this.read(i,()=>({op:"getSpanText",span:r,projection:this.revisionTextView()}),s=>{this.setLoadedProperty("text",b(s,i));});}if(!e.includes("style"))return;let o=`${this.path.label}.style`;this.requireAddressable(),this.read(o,()=>({op:"getStyle",span:E(this.path,"span")}),r=>{this.setLoadedProperty("style",at(r,o));});}#n(){return this.requireAddressable(),this.path.span()}};var tt=class n extends p{#t;static at(t,e,o){return o.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new n(t,l.of(e,o.handle),false)}static promised(t,e,o){return new n(t,l.pending(e),o)}constructor(t,e,o){super(t,e,{nullable:o});}hydrateAddress(t){t.kind==="handle"?this.path.resolveTo(t.handle):this.path.resolveNull();}hydrateNull(){this.path.resolveNull();}get name(){return this.loadedProperty("name")}get range(){return this.#t??=this.#e(`${this.path.label}.range`),this.#t}select(t){let e=`${this.path.label}.select`,o=Ct(t,e);this.requireAddressable(),this.internals.capabilities.selection||a({code:"NotSupported",target:e});let r=this.#o();this.command("select",()=>({op:"selectBookmark",bookmark:r,mode:o==="Select"?"select":o==="Start"?"start":"end"}));}onLoad(t){if(!this.selection(t,["name"]).includes("name"))return;let e=`${this.path.label}.name`,o=this.#o();this.read(e,()=>({op:"getBookmarkName",bookmark:o}),r=>{this.setLoadedProperty("name",b(r,e));});}#e(t){let e=this.#o(),o=m.promised(this.context,t,false);return this.read(t,()=>({op:"getBookmarkRange",bookmark:e}),r=>{o.hydrateAddress({kind:"span",span:x(r,t)});}),o}#o(){return this.requireAddressable(),this.path.handle()}},D=class n extends y{#t;static of(t,e,o,r){return new n(t,l.derived(e,o),r)}constructor(t,e,o){super(t,e),this.#t=o;}listing(){return this.#t()}itemAt(t,e){return tt.at(this.context,t,e)}promised(t,e){return tt.promised(this.context,t,e)}};var Zt=4096,W=class n extends p{#t=new Map;#e;#o;static at(t,e,o){return o.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new n(t,l.of(e,o.handle),false)}static promised(t,e,o){return new n(t,l.pending(e),o)}constructor(t,e,o){super(t,e,{nullable:o});}hydrateAddress(t){t.kind==="handle"?this.path.resolveTo(t.handle):this.path.resolveNull();}hydrateNull(){this.path.resolveNull();}get id(){return this.loadedProperty("id")}get tag(){return this.loadedProperty("tag")}set tag(t){this.#r("tag",{tag:Lt(t,`${this.path.label}.tag`)});}get title(){return this.loadedProperty("title")}set title(t){this.#r("title",{title:Lt(t,`${this.path.label}.title`)});}get subtype(){return this.loadedProperty("subtype")}get isBound(){return this.loadedProperty("isBound")}get cannotDelete(){let t=this.loadedProperty("lock");return t==="sdtLocked"||t==="sdtContentLocked"}set cannotDelete(t){this.#s(t,this.cannotEdit,`${this.path.label}.cannotDelete`);}get cannotEdit(){let t=this.loadedProperty("lock");return t==="contentLocked"||t==="sdtContentLocked"}set cannotEdit(t){this.#s(this.cannotDelete,t,`${this.path.label}.cannotEdit`);}get placeholderShown(){return this.loadedProperty("placeholderShown")}get temporary(){return this.loadedProperty("temporary")}get text(){return this.loadedProperty("text")}get paragraphs(){return this.#e??=v.overListing(this.context,`${this.path.label}.paragraphs`,this.path,()=>({op:"getContentControlParagraphs",contentControl:this.#i()})),this.#e}get contentControls(){return this.#o??=w.of(this.context,`${this.path.label}.contentControls`,this.path,{contentControl:this.#i()}),this.#o}getRange(t){let e=`${this.path.label}.getRange`,o=Re(t??"Whole",e),r=this.#t.get(o);if(r)return r;let i=this.#n(e,o);return this.#t.set(o,i),i}setValue(t){let e=`${this.path.label}.setValue`,o=Oe(t,e),r=this.#i();this.command("setValue",()=>({op:"setContentControlValue",contentControl:r,value:o}));}insertText(t,e){let o=`${this.path.label}.insertText`,r=A(t,o),i=e==="Replace"?"replace":e==="Start"?"start":e==="End"?"end":a({code:"InvalidArgument",target:o}),s=this.#i(),d=m.promised(this.context,o,false);return this.commandAnswering(o,()=>({op:"insertContentControlText",contentControl:s,text:r,at:i}),c=>{d.hydrateAddress({kind:"span",span:x(c,o)});}),d}delete(t){let e=`${this.path.label}.delete`;typeof t!="boolean"&&a({code:"InvalidArgument",target:e});let o=this.#i();this.command("delete",()=>({op:"deleteContentControl",contentControl:o,keepContent:t}));}onLoad(t){let e=this.selection(t,["id","tag","title","subtype","isBound","text","cannotDelete","cannotEdit","placeholderShown","temporary"]),o=this.#i();if(e.includes("id")&&this.loadTextInto("id",()=>({op:"getContentControlFileId",contentControl:o})),e.includes("tag")&&this.loadTextInto("tag",()=>({op:"getContentControlTag",contentControl:o})),e.includes("title")&&this.loadTextInto("title",()=>({op:"getContentControlTitle",contentControl:o})),e.includes("subtype")&&this.loadTextInto("subtype",()=>({op:"getContentControlSubtype",contentControl:o})),e.includes("isBound")){let i=`${this.path.label}.isBound`;this.read(i,()=>({op:"getContentControlIsBound",contentControl:o}),s=>{this.setLoadedProperty("isBound",M(s,i));});}if(e.includes("text")&&this.loadTextInto("text",()=>({op:"getContentControlText",contentControl:o,projection:this.revisionTextView()})),e.includes("cannotDelete")||e.includes("cannotEdit")){let i=`${this.path.label}.lock`;this.read(i,()=>({op:"getContentControlLock",contentControl:o}),s=>{this.setLoadedProperty("lock",b(s,i));});}if(e.includes("placeholderShown")){let i=`${this.path.label}.placeholderShown`;this.read(i,()=>({op:"getContentControlPlaceholderShown",contentControl:o}),s=>{this.setLoadedProperty("placeholderShown",M(s,i));});}if(!e.includes("temporary"))return;let r=`${this.path.label}.temporary`;this.read(r,()=>({op:"getContentControlTemporary",contentControl:o}),i=>{this.setLoadedProperty("temporary",M(i,r));});}#n(t,e){let o=this.#i(),r=m.promised(this.context,t,false);return this.read(t,()=>({op:"getContentControlRange",contentControl:o,location:e}),i=>{r.hydrateAddress({kind:"span",span:x(i,t)});}),r}#r(t,e){let o=this.#i();this.command(t,()=>({op:"setContentControlProperties",contentControl:o,...e}));}#s(t,e,o){(typeof t!="boolean"||typeof e!="boolean")&&a({code:"InvalidArgument",target:o});let r=t&&e?"sdtContentLocked":t?"sdtLocked":e?"contentLocked":"unlocked",i=this.#i();this.command(o,()=>({op:"setContentControlProperties",contentControl:i,lock:r}));}#i(){return this.requireAddressable(),this.path.handle()}},w=class n extends y{#t;#e;static of(t,e,o,r){return new n(t,l.derived(e,o),r,()=>({op:"getContentControls",scope:r}))}constructor(t,e,o,r){super(t,e),this.#t=o,this.#e=r;}getFirst(){return this.edge("first","getFirst",false)}getFirstOrNullObject(){return this.edge("first","getFirstOrNullObject",true)}getById(t){let e=`${this.path.label}.getById`;Number.isInteger(t)||a({code:"InvalidArgument",target:e});let o=this.#t,r=W.promised(this.context,e,false);return this.enqueue({sort:"read",label:e,plan:()=>({op:"getContentControlById",scope:o,id:t}),settle:i=>{r.hydrateAddress({kind:"handle",handle:f(i,e)});}}),r}getByTag(t){let e=`${this.path.label}.getByTag`,o=Kt(t,e),r=this.#t;return new n(this.context,l.derived(e,this.path),r,()=>({op:"getContentControlsByTag",scope:r,tag:o}))}getByTitle(t){let e=`${this.path.label}.getByTitle`,o=Kt(t,e),r=this.#t;return new n(this.context,l.derived(e,this.path),r,()=>({op:"getContentControlsByTitle",scope:r,title:o}))}listing(){return this.#e()}itemAt(t,e){return W.at(this.context,t,e)}promised(t,e){return W.promised(this.context,t,e)}};function Lt(n,t){return (typeof n!="string"||n.length>Zt)&&a({code:"InvalidArgument",target:t}),n}function Kt(n,t){let e=Lt(n,t);return e.length===0&&a({code:"InvalidArgument",target:t}),e}function Re(n,t){switch(n){case "Whole":return "whole";case "Content":return "content";case "Start":return "start";case "End":return "end";case "Before":return "before";case "After":return "after";default:return a({code:"InvalidArgument",target:t})}}function Oe(n,t){(typeof n!="object"||n===null)&&a({code:"InvalidArgument",target:t});let e=n;if(e.kind==="text"||e.kind==="listItem"){let o=e.kind==="text"?e.text:e.value;return (typeof o!="string"||o.length>Zt)&&a({code:"InvalidArgument",target:t}),e.kind==="text"?{kind:"text",text:o}:{kind:"listItem",value:o}}if(e.kind==="checkbox")return typeof e.checked!="boolean"&&a({code:"InvalidArgument",target:t}),{kind:"checkbox",checked:e.checked};if(e.kind==="date")return (typeof e.iso!="string"||e.iso.length>64)&&a({code:"InvalidArgument",target:t}),{kind:"date",iso:e.iso};a({code:"InvalidArgument",target:t});}var k=class n extends p{#t;#e;#o;#n;#r;#s;static main(t,e){return new n(t,l.of(e,H(t).roots().body))}static promisedStory(t,e){return new n(t,l.pending(e))}hydrateAddress(t){t.kind==="handle"?this.path.resolveTo(t.handle):this.path.resolveNull();}constructor(t,e){super(t,e);}get text(){return this.loadedProperty("text")}get paragraphs(){return this.#t??=this.paragraphsUnder(`${this.path.label}.paragraphs`),this.#t}get bookmarks(){let t=this.#a();return this.#e??=D.of(this.context,`${this.path.label}.bookmarks`,this.path,()=>({op:"getBookmarks",scope:{body:t}})),this.#e}get font(){return this.#o??=I.of(this.context,`${this.path.label}.font`,this.path,"body"),this.#o}paragraphsUnder(t){return v.of(this.context,t,this.path)}get style(){return this.loadedProperty("style")}set style(t){let e=`${this.path.label}.style`,o=Y(t,e);this.requireAddressable(),this.command("style",()=>({op:"setStyle",span:E(this.path,"body"),name:o}));}get lists(){return this.#n??=K.of(this.context,`${this.path.label}.lists`,this.path,this.#a()),this.#n}get contentControls(){return this.#r??=w.of(this.context,`${this.path.label}.contentControls`,this.path,{body:this.#a()}),this.#r}getComments(){let t=`${this.path.label}.getComments`,e=this.#a();return q.of(this.context,t,this.path,()=>({op:"getComments",scope:{body:e}}))}get revisions(){return this.#s??=$.of(this.context,`${this.path.label}.revisions`,this.path,this.#a()),this.#s}search(t,e){let o=`${this.path.label}.search`;typeof t!="string"&&a({code:"InvalidArgument",target:o});let r=vt(e,o),i=this.#a();return S.of(this.context,o,this.path,()=>({op:"search",scope:{body:i},text:t,options:{...r??{},projection:this.revisionTextView()}}))}clear(){let t=this.#a();this.commandDiscarding("clear",()=>({op:"replaceSpan",span:{body:t},text:""}));}insertText(t,e){let o=`${this.path.label}.insertText`,r=A(t,o),i=Ft(e,o),s=this.#a(),d=m.promised(this.context,o,false);return this.commandAnswering(o,()=>i==="Replace"?{op:"replaceSpan",span:{body:s},text:r}:{op:"insertText",at:{body:s,at:i==="Start"?"start":"end"},text:r},c=>{d.hydrateAddress({kind:"span",span:x(c,o)});}),d}insertParagraph(t,e){let o=`${this.path.label}.insertParagraph`,r=A(t,o),i=Ht(e,o),s=this.#a(),d=R.promised(this.context,o,false);return this.commandAnswering(o,()=>({op:"insertParagraph",anchor:{body:s,at:i==="Start"?"first":"last"},where:i==="Start"?"before":"after",text:r}),c=>{c.kind!=="handle"&&a({code:"GeneralException",target:o}),d.hydrateAddress({kind:"handle",handle:c.handle});}),d}onLoad(t){let e=this.selection(t,["text","style"]);if(e.includes("text")){let o=this.#a();this.loadTextInto("text",()=>({op:"getText",target:o,projection:this.revisionTextView()}));}e.includes("style")&&this.#i();}#i(){let t=`${this.path.label}.style`;this.requireAddressable(),this.read(t,()=>({op:"getStyle",span:E(this.path,"body")}),e=>{this.setLoadedProperty("style",at(e,t));});}#a(){return this.requireAddressable(),this.path.handle()}};function Pe(n){return n==="endnote"?"Endnote":"Footnote"}var et=class n extends p{#t;static at(t,e,o){return o.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new n(t,l.of(e,o.handle),false)}static promised(t,e,o){return new n(t,l.pending(e),o)}constructor(t,e,o){super(t,e,{nullable:o});}hydrateAddress(t){t.kind==="handle"?this.path.resolveTo(t.handle):this.path.resolveNull();}hydrateNull(){this.path.resolveNull();}get type(){return this.loadedProperty("type")}get text(){return this.loadedProperty("text")}get body(){if(this.#t)return this.#t;let t=`${this.path.label}.body`,e=this.#e(),o=k.promisedStory(this.context,t);return this.read(t,()=>({op:"getNoteBody",note:e}),r=>{o.hydrateAddress({kind:"handle",handle:f(r,t)});}),this.#t=o,o}delete(){let t=this.#e();this.command("delete",()=>({op:"deleteNote",note:t}));}getNext(){let t=`${this.path.label}.getNext`,e=this.#e(),o=n.promised(this.context,t,false),r=this.internals.roots().document,i=`${t}.type`,s="footnote";return this.read(i,()=>({op:"getNoteKind",note:e}),d=>{s=b(d,i)==="endnote"?"endnote":"footnote";}),this.read(t,()=>({op:"getNotes",document:r,noteKind:s}),d=>{let c=P(d,t),g=c.findIndex(U=>U.ref===e.ref),L=g<0?void 0:c[g+1];L||a({code:"ItemNotFound",target:t}),o.hydrateAddress({kind:"handle",handle:L});}),o}onLoad(t){let e=this.selection(t,["text","type"]);if(e.includes("text")){let o=this.#e();this.loadTextInto("text",()=>({op:"getNoteText",note:o,projection:this.revisionTextView()}));}if(e.includes("type")){let o=`${this.path.label}.type`,r=this.#e();this.read(o,()=>({op:"getNoteKind",note:r}),i=>{this.setLoadedProperty("type",Pe(b(i,o)));});}}#e(){return this.requireAddressable(),this.path.handle()}},z=class n extends y{#t;static of(t,e,o,r){return new n(t,l.derived(e,o),r)}constructor(t,e,o){super(t,e),this.#t=o;}getFirst(){return this.edge("first","getFirst",false)}listing(){return this.#t()}itemAt(t,e){return et.at(this.context,t,e)}promised(t,e){return et.promised(this.context,t,e)}};var ke=Object.freeze({Primary:"default",FirstPage:"first",EvenPages:"even"}),Ie=["pageWidth","pageHeight","orientation","topMargin","rightMargin","bottomMargin","leftMargin"],pt=class n extends p{#t;static of(t,e,o){return new n(t,l.derived(e,o))}constructor(t,e){super(t,e);}get pageWidth(){return this.loadedProperty("pageWidth")}set pageWidth(t){this.#e("pageWidth",ot(t,`${this.path.label}.pageWidth`));}get pageHeight(){return this.loadedProperty("pageHeight")}set pageHeight(t){this.#e("pageHeight",ot(t,`${this.path.label}.pageHeight`));}get orientation(){return this.loadedProperty("orientation")}set orientation(t){let e=`${this.path.label}.orientation`;t!=="Portrait"&&t!=="Landscape"&&a({code:"InvalidArgument",target:e}),this.#e("orientation",t==="Portrait"?"portrait":"landscape");}get topMargin(){return this.loadedProperty("topMargin")}set topMargin(t){this.#e("topMargin",ot(t,`${this.path.label}.topMargin`));}get bottomMargin(){return this.loadedProperty("bottomMargin")}set bottomMargin(t){this.#e("bottomMargin",ot(t,`${this.path.label}.bottomMargin`));}get leftMargin(){return this.loadedProperty("leftMargin")}set leftMargin(t){this.#e("leftMargin",ot(t,`${this.path.label}.leftMargin`));}get rightMargin(){return this.loadedProperty("rightMargin")}set rightMargin(t){this.#e("rightMargin",ot(t,`${this.path.label}.rightMargin`));}onLoad(t){let e=this.selection(t,Ie);if(e.length===0)return;let o=`${this.path.label}.pageSetup`,r=this.#o();this.read(o,()=>({op:"getPageSetup",section:r}),i=>{let s=It(i,o);for(let d of e)this.setLoadedProperty(d,d==="orientation"?s.orientation==="landscape"?"Landscape":"Portrait":s[d]);});}#e(t,e){if(this.requireAddressable(),this.#t){this.#t[t]=e;return}let o={[t]:e};this.#t=o;let r=this.#o(),i=`${this.path.label}.${t}`;this.commandAnswering(`${this.path.label}.pageSetup`,()=>(this.#t=void 0,{op:"setPageSetup",section:r,setup:o}),s=>{C(s,i);});}#o(){this.requireAddressable();let t=this.path.address();return t.kind!=="handle"&&a({code:"InvalidObjectPath",target:this.path.label}),t.handle}},nt=class n extends p{#t;#e;static at(t,e,o){return o.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new n(t,l.of(e,o.handle),false)}static promised(t,e,o){return new n(t,l.pending(e),o)}constructor(t,e,o){super(t,e,{nullable:o});}hydrateAddress(t){t.kind==="handle"?this.path.resolveTo(t.handle):this.path.resolveNull();}hydrateNull(){this.path.resolveNull();}get body(){return this.#e??=k.main(this.context,`${this.path.label}.body`),this.#e}get pageSetup(){return this.#t??=pt.of(this.context,`${this.path.label}.pageSetup`,this.path),this.#t}getHeader(t){return this.#o("header",t,"getHeader")}getFooter(t){return this.#o("footer",t,"getFooter")}getNext(){let t=`${this.path.label}.getNext`,e=this.#n(),o=n.promised(this.context,t,false),r=this.internals.roots().document;return this.read(t,()=>({op:"getSections",document:r}),i=>{let s=P(i,t),d=s.findIndex(g=>g.ref===e.ref),c=d<0?void 0:s[d+1];c||a({code:"ItemNotFound",target:t}),o.hydrateAddress({kind:"handle",handle:c});}),o}onLoad(t){this.selection(t,[]);}#o(t,e,o){let r=`${this.path.label}.${o}`,i=ke[e];i===void 0&&a({code:"InvalidArgument",target:r});let s=this.#n(),d=k.promisedStory(this.context,r);return this.read(r,()=>({op:"getFurniture",section:s,kind:t,variant:i}),c=>{d.hydrateAddress({kind:"handle",handle:f(c,r)});}),d}#n(){return this.requireAddressable(),this.path.handle()}},rt=class n extends y{#t;static of(t,e,o,r){return new n(t,l.derived(e,o),r)}constructor(t,e,o){super(t,e),this.#t=o;}getFirst(){return this.edge("first","getFirst",false)}listing(){return this.#t()}itemAt(t,e){return nt.at(this.context,t,e)}promised(t,e){return nt.promised(this.context,t,e)}};function ot(n,t){return (typeof n!="number"||!Number.isFinite(n)||n<0)&&a({code:"InvalidArgument",target:t}),n}var it=class n extends p{#t;#e;#o;#n;#r;#s;#i;#a;static open(t){return new n(t)}constructor(t){super(t,l.of("document",H(t).roots().document));}get changeTrackingMode(){return this.loadedProperty("changeTrackingMode")}set changeTrackingMode(t){["Off","TrackAll","TrackMineOnly"].includes(t)||a({code:"InvalidArgument",target:"document.changeTrackingMode"});let e=this.internals.author;this.commandAnswering("document.changeTrackingMode",()=>({op:"setChangeTrackingMode",mode:t,...e===void 0?{}:{author:e}}),()=>this.setLoadedProperty("changeTrackingMode",t));}get body(){return this.#t??=k.main(this.context,"document.body"),this.#t}get paragraphs(){return this.#e??=this.body.paragraphsUnder("document.paragraphs"),this.#e}get sections(){let t=this.path.handle();return this.#o??=rt.of(this.context,"document.sections",this.path,()=>({op:"getSections",document:t})),this.#o}get contentControls(){return this.#s??=w.of(this.context,"document.contentControls",this.path,{body:this.internals.roots().body}),this.#s}get comments(){return this.#n??=q.of(this.context,"document.comments",this.path,()=>({op:"getComments",scope:{body:this.internals.roots().body}})),this.#n}get revisions(){return this.#r??=$.of(this.context,"document.revisions",this.path,this.internals.roots().body),this.#r}get footnotes(){let t=this.path.handle();return this.#i??=z.of(this.context,"document.footnotes",this.path,()=>({op:"getNotes",document:t,noteKind:"footnote"})),this.#i}get endnotes(){let t=this.path.handle();return this.#a??=z.of(this.context,"document.endnotes",this.path,()=>({op:"getNotes",document:t,noteKind:"endnote"})),this.#a}onLoad(t){if(t.select.length===0)return;this.selection(t,["changeTrackingMode"]).includes("changeTrackingMode")&&this.loadTextInto("changeTrackingMode",()=>({op:"getChangeTrackingMode"}));}};function Jt(n){let t=n.host,e=Object.freeze({...t.capabilities,save:n.save&&t.capabilities.save}),o=typeof n.author=="string"&&n.author.trim().length>0?n.author:void 0,r=n.revisionTextView??"allMarkup";r!=="allMarkup"&&r!=="original"&&a({code:"InvalidArgument",target:"revisionTextView"});let i=false,s=null,d=h=>{i&&a({code:"RuntimeDisposed",...h===void 0?{}:{target:h}});},c=()=>{if(s)return s;d("document");let h=Yt(t.execute({operations:[{op:"getDocument"}]}),"document"),B=Yt(t.execute({operations:[{op:"getBody",document:h}]}),"document.body");return s={document:h,body:B},s},g={host:t,capabilities:e,...o===void 0?{}:{author:o},revisionTextView:r,id:{},roots:c,assertLive:d,openDocument:h=>it.open(h)};try{c();}catch{s=null;}async function L(h,B){d();let G=typeof h=="function"?h:B,Rt=typeof h=="function"?[]:Array.isArray(h)?h:[h];typeof G!="function"&&a({code:"InvalidArgument",target:"run"});let{context:ut,adopt:te,finish:ee}=dt.begin(g);try{return te(Rt),await G(ut)}finally{ee();}}let U={capabilities:e,run:L,dispose(){i||(i=true,s=null,t.dispose());}};return n.save?{...U,async save(){d("save"),e.save||a({code:"NotSupported",target:"save"});let h=t.save();if(!h.ok)throw bt(h.error,{target:"save"});return h.bytes}}:U}function Yt(n,t){let e=n.results[0];if(e?.status==="error")throw bt(e.error,{target:t});if(e?.status!=="ok")throw new u({code:"GeneralException",target:t});return f(e.value,t)}function Le(n){if(n){for(let t of n)if(t.collaboration)return t.collaboration}}function je(n){let t=[n?.zip?.maxEntries,n?.zip?.maxTotalBytes,n?.xml?.maxBytes,n?.xml?.maxElements,n?.maxXmlParts,n?.maxRelationships],e=n?.zip?.maxRatio;(t.some(o=>o!==void 0&&(!Number.isInteger(o)||o<0))||e!==void 0&&(!Number.isFinite(e)||e<0))&&a({code:"InvalidArgument",target:"createServer"});}async function jt(n,t={}){je(t.limits);let e=Le(t.modules),o=createServerAutomationHost(n,{...t.limits===void 0?{}:{limits:t.limits},...e===void 0?{}:{collaborationModel:e}});if(!o.ok){let r={"too-many-entries":"zip.maxEntries","too-large":"xml.maxBytes","too-many-elements":"xml.maxElements","too-deep":"xml.maxDepth","too-many-xml-parts":"maxXmlParts","too-many-relationships":"maxRelationships"},i=o.limit??r[o.reason];a({code:i===void 0?"InvalidArgument":"ResourceLimitExceeded",target:"createServer",...i===void 0?{}:{limit:i}});}return Jt({host:o.host,save:true,...t.author===void 0?{}:{author:t.author},...t.revisionTextView===void 0?{}:{revisionTextView:t.revisionTextView}})}function _t(n,t,e={}){return jt(n,{...e,modules:[...e.modules??[],{id:"collaboration",collaboration:{session:t}}]})}var Er=Object.freeze({createServer:jt,createCollaborative:_t});export{k as Body,tt as Bookmark,D as BookmarkCollection,T as ClientObject,Ot as ClientResult,N as Comment,q as CommentCollection,V as CommentReply,ct as CommentReplyCollection,W as ContentControl,w as ContentControlCollection,it as Document,Er as DocxEditor,u as DocxEditorError,I as Font,j as List,K as ListCollection,Z as ListItem,et as NoteItem,z as NoteItemCollection,pt as PageSetup,R as Paragraph,v as ParagraphCollection,m as Range,S as RangeCollection,dt as RequestContext,_ as Revision,$ as RevisionCollection,nt as Section,rt as SectionCollection,st as TrackedObjects,oe as isDocxEditorError};
|
|
1
|
+
import {createServerAutomationHost,createAutomationPaginationProvider}from'@docx-editor.dev/core/automation';function de(o){return createAutomationPaginationProvider(o)}var le=Object.freeze({PropertyNotLoaded:"the property has not been loaded. Call load(...) and await context.sync() before reading it.",ValueNotLoaded:"the result has not been filled in yet. Await context.sync() before reading it.",InvalidObjectPath:"the object cannot be addressed. Await context.sync() after creating an object with an edit. Keep proxies within their run, or use context.trackedObjects.add(...) before the run ends.",ObjectInUse:"the object still belongs to a run that has not finished. Await that run before passing the object to another one.",InvalidArgument:"the argument is not one this API accepts.",ResourceLimitExceeded:"the document exceeds a supported resource limit.",ItemNotFound:"the collection has no such item.",NotSupported:"the operation or argument is outside this document or host\u2019s supported capabilities.",NotImplemented:"this version does not implement that yet.",ConflictingChanges:"these operations cannot share one atomic batch. Split them across separate 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."}),C=class extends Error{code;limit;target;expectedRevision;actualRevision;constructor(t){let e=t.target?`${le[t.code]} (${t.target})`:le[t.code];super(e),this.name="DocxEditorError",this.code=t.code,t.limit!==void 0&&(this.limit=t.limit),t.target!==void 0&&(this.target=t.target),t.expectedRevision!==void 0&&(this.expectedRevision=t.expectedRevision),t.actualRevision!==void 0&&(this.actualRevision=t.actualRevision);}};function Se(o){return o instanceof C?true:typeof o=="object"&&o!==null&&o.name==="DocxEditorError"&&typeof o.code=="string"}function a(o){throw new C(o)}var Y=Symbol("docx-editor.runtime.internals"),St=Symbol("docx-editor.runtime.release"),jt=Symbol("docx-editor.runtime.rebind");function J(o){return o[Y]}var je=new Set(["select","expand","top","skip"]),Te=/^[A-Za-z][A-Za-z0-9]*$/;function ce(o,t){if(o===void 0)return [];let e=typeof o=="string"?o.split(",").map(r=>r.trim()):Array.isArray(o)?o.map(r=>typeof r=="string"?r.trim():r):a({code:"InvalidArgument",target:t}),n=[];for(let r of e)(typeof r!="string"||!Te.test(r))&&a({code:"InvalidArgument",target:t}),n.includes(r)||n.push(r);return n.length===0&&a({code:"InvalidArgument",target:t}),n}function he(o,t){return (typeof o!="number"||!Number.isInteger(o)||o<0)&&a({code:"InvalidArgument",target:t}),o}function Ne(o,t){o===void 0||Array.isArray(o)&&o.length===0||a({code:"InvalidArgument",target:t});}function pe(o,t){if(o===void 0)return {select:[]};if(typeof o=="string"||Array.isArray(o))return {select:ce(o,t)};(typeof o!="object"||o===null)&&a({code:"InvalidArgument",target:t});let e=o;for(let n of Object.keys(e))je.has(n)||a({code:"InvalidArgument",target:`${t}.${n}`});return Ne(e.expand,`${t}.expand`),{select:ce(e.select,`${t}.select`),...e.top===void 0?{}:{top:he(e.top,`${t}.top`)},...e.skip===void 0?{}:{skip:he(e.skip,`${t}.skip`)}}}var B=class{#t;#n;#e;#o;#i=new Map;#s=false;constructor(t,e,n={}){this.#t=t,this.#n=t[Y],this.#e=e,this.#o=n.nullable===true,this.#n.register(this);}get context(){return this.#t}get isNullObject(){return this.#e.isReleased&&a({code:"InvalidObjectPath",target:this.#e.label}),this.#o?(this.#e.isPending&&a({code:"PropertyNotLoaded",target:`${this.#e.label}.isNullObject`}),this.#e.isNull):false}load(t){this.#s=true;try{return this.requireUsablePath(),this.onLoad(pe(t,this.#e.label)),this}finally{this.#s=false;}}get path(){return this.#e}get internals(){return this.#n}handle(){return this.#e.handle()}requireAddressable(){this.#e.isAddressable||a({code:"InvalidObjectPath",target:this.#e.label}),this.#n.assertUsable(this.#e.label);}requireUsablePath(){(this.#e.isReleased||this.#e.isNull&&!(this.#s&&this.#o))&&a({code:"InvalidObjectPath",target:this.#e.label}),this.#n.assertUsable(this.#e.label);}enqueue(t){this.requireUsablePath(),this.#n.queue.push({...t,dependencies:[...t.dependencies??[],this.#e],...this.#s&&this.#o&&t.sort==="read"?{nullableLoad:this.#e}:{}});}loadedProperty(t){return this.#e.isReleased&&!this.#i.has(t)&&a({code:"InvalidObjectPath",target:this.#e.label}),this.#i.has(t)||a({code:"PropertyNotLoaded",target:`${this.#e.label}.${t}`}),this.#i.get(t)}hasLoadedProperty(t){return this.#i.has(t)}setLoadedProperty(t,e){this.#i.set(t,e);}[St](){this.#e.release();}[jt](t){this.#t=t,this.#n=t[Y];}};var Ft=class o{#t=false;#n;#e;constructor(t){this.#e=t;}get value(){return this.#t||a({code:"ValueNotLoaded",target:this.#e}),this.#n}get isLoaded(){return this.#t}static create(t){let e=new o(t);return {result:e,fill(n){e.#t=true,e.#n=n;}}}};function S(o){return new C({code:"GeneralException",target:o})}function O(o,t){if(o.kind!=="text")throw S(t);return o.text}function u(o,t){if(o.kind!=="handle")throw S(t);return o.handle}function v(o,t){if(o.kind!=="handles")throw S(t);return o.handles}function P(o,t){if(o.kind!=="span")throw S(t);return o.span}function Tt(o,t){if(o.kind!=="spans")throw S(t);return o.spans}function Vt(o,t){if(o.kind!=="font")throw S(t);return o.font}function Wt(o,t){if(o.kind!=="paragraphFormat")throw S(t);return o.format}function xt(o,t){if(o.kind!=="style")throw S(t);return o.name}function Nt(o,t){if(o.kind!=="number")throw S(t);return o.value}function _(o,t){if(o.kind!=="flag")throw S(t);return o.value}function Ut(o,t){if(o.kind!=="pageSetup")throw S(t);return o.setup}function m(o,t){if(o.kind!=="applied")throw S(t)}var c=class o{label;#t;#n;constructor(t,e,n=null){this.label=t,this.#t=e,this.#n=n;}static of(t,e){return new o(t,{status:"resolved",address:{kind:"handle",handle:e}})}static ofSpan(t,e){return new o(t,{status:"resolved",address:{kind:"span",span:e}})}static pending(t){return new o(t,{status:"pending"})}static derived(t,e){return new o(t,{status:"pending"},e)}get state(){return this.#n?this.#n.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.#e({kind:"handle",handle:t});}resolveToSpan(t){this.#e({kind:"span",span:t});}resolveNull(){this.#t.status!=="released"&&(this.#t={status:"null"});}release(){this.#n||(this.#t={status:"released"});}#e(t){this.#t.status!=="released"&&(this.#t={status:"resolved",address:t});}};function ue(o){let t=[],e=false,n=false;for(let r of o)t.push(r.plan()),r.sort==="write"?n=true:e=true;return {operations:t,hasRead:e,hasWrite:n}}var Ee=Object.freeze({"stale-revision":"StaleDocument","invalid-handle":"InvalidObjectPath","invalid-offset":"InvalidArgument","unsupported-capability":"NotSupported",disposed:"RuntimeDisposed","transaction-refused":"GeneralException","unknown-operation":"NotSupported","unsupported-content":"InvalidArgument","unsupported-revision":"NotImplemented","ambiguous-document":"GeneralException","conflicting-operations":"ConflictingChanges","document-unavailable":"DocumentUnavailable"});function Et(o,t={}){let e=Ee[o.code]??"GeneralException",n=e==="StaleDocument";return new C({code:e,...t.target===void 0?{}:{target:t.target},...n&&t.expectedRevision!==void 0?{expectedRevision:t.expectedRevision}:{},...n&&t.actualRevision!==void 0?{actualRevision:t.actualRevision}:{}})}function Gt(o,t,e){for(let n=0;n<o.results.length;n+=1){let r=o.results[n];if(r?.status!=="error")continue;let i=t[n]?.label;return Et(r.error,{...i===void 0?{}:{target:i},...e===void 0?{}:{expectedRevision:e},actualRevision:o.revision})}return new C({code:"GeneralException"})}function zt(o,t){if(t.results.length!==o.length)throw new C({code:"GeneralException"});for(let e=0;e<o.length;e+=1){let n=t.results[e],r=o[e];if(n.status!=="ok")throw new C({code:"GeneralException",target:r.label});r.settle(n.value);}}var qt=class{#t=[];get size(){return this.#t.length}get pending(){return this.#t}push(t){this.#t.push(t);}take(){let t=this.#t;this.#t=[];for(let e of t)e.capture?.();return t}clear(){for(let t of this.#t)t.dispose?.();this.#t=[];}};function me(o,t){if(Array.isArray(o)){for(let e of o)t(e);return}t(o);}var Ct=class{#t;#n;constructor(t,e){this.#t=t,this.#n=e;}add(t){this.#t.assertUsable(),me(t,e=>{this.#e(e),this.#t.track(e);});}remove(t){this.#t.assertUsable(),me(t,e=>{this.#e(e),this.#t.untrack(e);});}#e(t){this.#n(t)||a({code:"InvalidObjectPath"});}};var At=class o{#t;#n=new qt;#e=new Set;#o=new Set;#i;#s;#r;#a=false;#l=null;#c=false;constructor(t){this.#t=t,this.#i={host:t.host,capabilities:t.capabilities,...t.author===void 0?{}:{author:t.author},revisionTextView:t.revisionTextView,queue:this.#n,session:t.id,roots:()=>t.roots(),assertUsable:e=>{this.#t.assertLive(e),this.#a&&a({code:"InvalidRequestContext",...e===void 0?{}:{target:e}});},isFinished:()=>this.#a,readRevision:()=>this.#l,register:e=>{this.#e.add(e);},track:e=>{this.#o.add(e);},untrack:e=>{this.#o.delete(e);},isTracked:e=>this.#o.has(e),disown:e=>{this.#e.delete(e),this.#o.delete(e);}},this.#s=new Ct(this.#i,e=>this.#e.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.#s}async sync(){this.#i.assertUsable(),this.#c&&a({code:"InvalidRequestContext"});let t=this.#n.take();if(t.length!==0){this.#c=true;try{let e=t.filter(s=>!s.nullableLoad?.isNull),n=t.some(s=>s.sort==="write"),r,i=s=>s.dependencies?.some(d=>!d.isAddressable)??false;for(;e.some(i);){r??=n&&this.#l!==null?this.#l:this.#t.host.revision();let s=e.filter(h=>h.sort==="read"&&!i(h));s.length===0&&a({code:"InvalidObjectPath",target:e.find(i)?.label}),await this.#d(s,r);let d=new Set(s);e=e.filter(h=>!d.has(h)&&!h.nullableLoad?.isNull);}if(e.length){let s=r??(n&&this.#l!==null?this.#l:void 0);await this.#d(e,s);}}finally{for(let e of t)e.dispose?.();this.#c=false;}}}async#d(t,e){let n=ue(t),r={operations:n.operations,...e===void 0?{}:{expectedRevision:e}};if(this.#t.host.prepare){let s={...r,expectedRevision:r.expectedRevision??this.#t.host.revision()};await this.#t.host.prepare(s);let d=this.#t.host.execute(s);if(!d.ok)throw Gt(d,t,s.expectedRevision);zt(t,d),this.#l=d.revision;return}let i=this.#t.host.execute(r);if(!i.ok)throw Gt(i,t,e);zt(t,i),(n.hasRead||n.hasWrite)&&(this.#l=i.revision);}get[Y](){return this.#i}static begin(t){let e=new o(t);return {context:e,adopt(n){for(let r of n)e.#h(r);},finish(){e.#u();}}}#h(t){let e=t.context;if(e===this)return;let n=e[Y];if(n.session!==this.#t.id)throw new C({code:"InvalidObjectPath"});if(!n.isFinished())throw new C({code:"ObjectInUse"});if(!n.isTracked(t))throw new C({code:"InvalidObjectPath"});let r=n.readRevision();n.disown(t),t[jt](this),this.#e.add(t),this.#o.add(t),r!==null&&this.#p(r);}#p(t){this.#l=this.#l===null?t:Math.min(this.#l,t);}#u(){if(!this.#a){this.#a=true,this.#n.clear();for(let t of this.#e)this.#o.has(t)||t[St]();this.#e.clear();}}};function vt(o,t,e){if(o.select.length===0)return t;for(let n of o.select)t.includes(n)||a({code:"InvalidArgument",target:`${e}.${n}`});return o.select}function R(o,t){let e=o.address();return t==="span"?(e.kind!=="span"&&a({code:"InvalidObjectPath",target:o.label}),{start:e.span.start,end:e.span.end}):(e.kind!=="handle"&&a({code:"InvalidObjectPath",target:o.label}),t==="body"?{body:e.handle}:{paragraph:e.handle})}function it(o,t){return (typeof o!="string"||o.trim().length===0||o.length>255)&&a({code:"InvalidArgument",target:t}),o}var p=class extends B{revisionTextView(){return J(this.context).revisionTextView}loadTextInto(t,e){let n=`${this.path.label}.${t}`;this.enqueue({sort:"read",label:n,plan:e,settle:r=>{this.setLoadedProperty(t,O(r,n));}});}command(t,e,n){let r=`${this.path.label}.${t}`;this.enqueue({sort:"write",label:r,plan:e,settle:i=>m(i,r),...n?{capture:n,dispose:n}:{}});}commandDiscarding(t,e){let n=`${this.path.label}.${t}`;this.enqueue({sort:"write",label:n,plan:e,settle:()=>{}});}commandAnswering(t,e,n,r){this.enqueue({sort:"write",label:t,plan:e,settle:n,...r?{capture:r,dispose:r}:{}});}read(t,e,n){this.enqueue({sort:"read",label:t,plan:e,settle:n});}selection(t,e){return vt(t,e,this.path.label)}onLoad(t){this.selection(t,[]);}};var T=class extends B{#t;#n=[];constructor(t,e){super(t,e);}get items(){return this.loadedProperty("items")}fill(t,e){this.setLoadedProperty("items",this.#o(t,e,0,void 0)),this.#t={value:t,label:e};let n=this.#n.splice(0,this.#n.length);for(let r of n)this.#e(r,t);}onLoad(t){vt(t,["items"],this.path.label);let e=this.path.isPending?void 0:this.listing();if(e===null)return;let n=`${this.path.label}.items`,r=t.skip??0,i=t.top;this.enqueue({sort:"read",label:n,plan:()=>{let s=e??this.listing();return s||a({code:"InvalidObjectPath",target:this.path.label}),s},settle:s=>{this.setLoadedProperty("items",this.#o(s,n,r,i));}});}edge(t,e,n){let r=`${this.path.label}.${e}()`,i=this.promised(r,n),s=this.path.isPending?void 0:this.listing();if(s===null){let d={edge:t,target:r,nullable:n,item:i};return this.#t?this.#e(d,this.#t.value):this.#n.push(d),i}return this.enqueue({sort:"read",label:r,plan:()=>{let d=s??this.listing();return d||a({code:"InvalidObjectPath",target:this.path.label}),d},settle:d=>{this.#e({edge:t,target:r,nullable:n,item:i},d);}}),i}#e(t,e){let{edge:n,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 h=this.addressAt(e,r,n==="first"?0:d-1);h||a({code:"ItemNotFound",target:r}),s.hydrateAddress(h);}#o(t,e,n,r){let i=this.size(t,e),s=r===void 0?i:Math.min(i,n+r),d=[];for(let h=n;h<s;h+=1){let A=this.addressAt(t,e,h);A&&d.push(this.itemAt(`${e}[${String(h)}]`,A));}return d}},x=class extends T{size(t,e){return v(t,e).length}addressAt(t,e,n){let r=v(t,e)[n];return r?{kind:"handle",handle:r}:void 0}};var H=class o extends p{#t;static at(t,e,n){return n.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new o(t,c.of(e,n.handle),false)}static promised(t,e,n){return new o(t,c.pending(e),n)}constructor(t,e,n){super(t,e,{nullable:n});}hydrateAddress(t){t.kind==="handle"?this.path.resolveTo(t.handle):this.path.resolveNull();}hydrateNull(){this.path.resolveNull();}get code(){return this.loadedProperty("code")}set code(t){if(this.requireUsablePath(),(typeof t!="string"||t.length===0)&&a({code:"InvalidArgument",target:`${this.path.label}.code`}),this.#t){this.#t.code=t;return}let e={code:t};this.#t=e,this.commandAnswering(this.path.label,()=>({op:"setFieldCode",field:this.#e(),code:e.code}),n=>m(n,this.path.label),()=>{this.#t===e&&(this.#t=void 0);});}delete(){this.#n("deleteField");}updateResult(){this.#n("updateFieldResult");}#n(t){this.requireUsablePath(),this.commandAnswering(this.path.label,()=>({op:t,field:this.#e()}),e=>m(e,this.path.label));}onLoad(t){this.selection(t,["code"]).length!==0&&this.read(this.path.label,()=>({op:"getField",field:this.#e()}),e=>{e.kind!=="field"&&a({code:"GeneralException",target:this.path.label}),this.setLoadedProperty("code",e.field.code);});}#e(){this.requireAddressable();let t=this.path.address();return t.kind!=="handle"&&a({code:"InvalidObjectPath",target:this.path.label}),t.handle}},M=class o extends T{#t;static of(t,e,n,r){return new o(t,c.derived(e,n),r)}constructor(t,e,n){super(t,e),this.#t=n;}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(){return {op:"getFields",span:R(this.path,this.#t)}}size(t,e){return v(t,e).length}addressAt(t,e,n){let r=v(t,e)[n];return r?{kind:"handle",handle:r}:void 0}itemAt(t,e){return H.at(this.context,t,e)}promised(t,e){return H.promised(this.context,t,e)}};var qe=["width","height","lockAspectRatio","altTextDescription"],F=class o extends p{#t;static at(t,e,n){return n.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new o(t,c.of(e,n.handle),false)}static promised(t,e,n){return new o(t,c.pending(e),n)}constructor(t,e,n){super(t,e,{nullable:n});}hydrateAddress(t){t.kind==="handle"?this.path.resolveTo(t.handle):this.path.resolveNull();}hydrateNull(){this.path.resolveNull();}get width(){return this.loadedProperty("width")}set width(t){this.#n("width",t);}get height(){return this.loadedProperty("height")}set height(t){this.#n("height",t);}get lockAspectRatio(){return this.loadedProperty("lockAspectRatio")}set lockAspectRatio(t){typeof t!="boolean"&&a({code:"InvalidArgument",target:`${this.path.label}.lockAspectRatio`}),this.#e({lockAspectRatio:t});}get altTextDescription(){return this.loadedProperty("altTextDescription")}set altTextDescription(t){typeof t!="string"&&a({code:"InvalidArgument",target:`${this.path.label}.altTextDescription`}),this.#e({altTextDescription:t});}delete(){let t=`${this.path.label}.delete`;this.commandAnswering(t,()=>({op:"deleteInlinePicture",picture:this.#o()}),e=>m(e,t));}onLoad(t){let e=this.selection(t,qe);e.length&&this.read(this.path.label,()=>({op:"getInlinePicture",picture:this.#o()}),n=>{n.kind!=="inlinePicture"&&a({code:"GeneralException",target:this.path.label});for(let r of e)this.setLoadedProperty(r,n.picture[r]);});}#n(t,e){(typeof e!="number"||!Number.isFinite(e)||e<=0)&&a({code:"InvalidArgument",target:`${this.path.label}.${t}`}),this.#e({[t]:e});}#e(t){if(this.requireUsablePath(),this.#t){Object.assign(this.#t,t);return}let e=t;this.#t=e,this.commandAnswering(this.path.label,()=>({op:"setInlinePicture",picture:this.#o(),properties:e}),n=>m(n,this.path.label),()=>{this.#t===e&&(this.#t=void 0);});}#o(){this.requireAddressable();let t=this.path.address();return t.kind!=="handle"&&a({code:"InvalidObjectPath",target:this.path.label}),t.handle}},V=class o extends T{#t;static of(t,e,n,r){return new o(t,c.derived(e,n),r)}constructor(t,e,n){super(t,e),this.#t=n;}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(){return {op:"getInlinePictures",span:R(this.path,this.#t)}}size(t,e){return v(t,e).length}addressAt(t,e,n){let r=v(t,e)[n];return r?{kind:"handle",handle:r}:void 0}itemAt(t,e){return F.at(this.context,t,e)}promised(t,e){return F.promised(this.context,t,e)}};function q(o,t,e=0){return (!Number.isInteger(o)||o<e)&&a({code:"InvalidArgument",target:t}),o}function Qt(o,t){return (!Array.isArray(o)||o.some(e=>!Array.isArray(e)||e.some(n=>typeof n!="string")))&&a({code:"InvalidArgument",target:t}),o.map(e=>[...e])}function ge(o,t){return o!=="Start"&&o!=="End"&&a({code:"InvalidArgument",target:t}),o==="Start"?"start":"end"}var W=class o extends p{#t;static at(t,e,n){return n.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new o(t,c.of(e,n.handle),false)}static promised(t,e,n=false){return new o(t,c.pending(e),n)}constructor(t,e,n){super(t,e,{nullable:n});}hydrateAddress(t){t.kind==="handle"?this.path.resolveTo(t.handle):this.path.resolveNull();}hydrateNull(){this.path.resolveNull();}get values(){return this.loadedProperty("values")}set values(t){let e=Qt(t,`${this.path.label}.values`);this.command("values",()=>({op:"updateTable",table:this.path.handle(),mutation:{kind:"values",values:e}}));}get style(){return this.loadedProperty("style")}set style(t){typeof t!="string"&&a({code:"InvalidArgument",target:`${this.path.label}.style`}),this.command("style",()=>({op:"updateTable",table:this.path.handle(),mutation:{kind:"properties",styleId:t}}));}get headerRowCount(){return this.loadedProperty("headerRowCount")}set headerRowCount(t){q(t,`${this.path.label}.headerRowCount`),this.command("headerRowCount",()=>({op:"updateTable",table:this.path.handle(),mutation:{kind:"properties",headerRowCount:t}}));}get rowCount(){return this.loadedProperty("rowCount")}get columnCount(){return this.loadedProperty("columnCount")}get rows(){return this.#t??=st.of(this.context,`${this.path.label}.rows`,this.path,()=>({op:"getTableRows",table:this.path.handle()}))}getCell(t,e){let n=`${this.path.label}.getCell`;q(t,n),q(e,n);let r=tt.promised(this.context,n);return this.read(n,()=>({op:"getTableCell",table:this.path.handle(),rowIndex:t,cellIndex:e}),i=>r.hydrateAddress({kind:"handle",handle:u(i,n)})),r}addRows(t,e,n){let r=`${this.path.label}.addRows`,i=ge(t,r);q(e,r,1);let s=n===void 0?void 0:Qt(n,r),d=st.of(this.context,r,this.path,()=>null);return this.commandAnswering(r,()=>({op:"updateTable",table:this.path.handle(),mutation:{kind:"addRows",location:i,count:e,...s?{values:s}:{}}}),h=>d.fill(h,r)),d}addColumns(t,e,n){let r=`${this.path.label}.addColumns`,i=ge(t,r);q(e,r,1);let s=n===void 0?void 0:Qt(n,r);this.command("addColumns",()=>({op:"updateTable",table:this.path.handle(),mutation:{kind:"addColumns",location:i,count:e,...s?{values:s}:{}}}));}deleteRows(t,e){e===void 0&&(e=1),q(t,this.path.label),q(e,this.path.label,1),this.command("deleteRows",()=>({op:"updateTable",table:this.path.handle(),mutation:{kind:"deleteRows",index:t,count:e}}));}deleteColumns(t,e){e===void 0&&(e=1),q(t,this.path.label),q(e,this.path.label,1),this.command("deleteColumns",()=>({op:"updateTable",table:this.path.handle(),mutation:{kind:"deleteColumns",index:t,count:e}}));}delete(){this.command("delete",()=>({op:"updateTable",table:this.path.handle(),mutation:{kind:"delete"}}));}onLoad(t){let e=this.selection(t,["values","style","headerRowCount","rowCount","columnCount"]);this.read(this.path.label,()=>({op:"getTable",table:this.path.handle()}),n=>{n.kind!=="table"&&a({code:"GeneralException",target:this.path.label});for(let r of e)this.setLoadedProperty(r,n.table[r]);});}},at=class o extends p{#t;static at(t,e,n){return n.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new o(t,c.of(e,n.handle),false)}static promised(t,e,n=false){return new o(t,c.pending(e),n)}constructor(t,e,n){super(t,e,{nullable:n});}hydrateAddress(t){t.kind==="handle"?this.path.resolveTo(t.handle):this.path.resolveNull();}hydrateNull(){this.path.resolveNull();}get cells(){return this.#t??=Pt.of(this.context,`${this.path.label}.cells`,this.path,()=>({op:"getTableCells",row:this.path.handle()}))}},tt=class o extends p{#t;static at(t,e,n){return n.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new o(t,c.of(e,n.handle),false)}static promised(t,e,n=false){return new o(t,c.pending(e),n)}constructor(t,e,n){super(t,e,{nullable:n});}hydrateAddress(t){t.kind==="handle"?this.path.resolveTo(t.handle):this.path.resolveNull();}hydrateNull(){this.path.resolveNull();}get body(){if(this.#t)return this.#t;let t=`${this.path.label}.body`,e=I.promisedStory(this.context,t);return this.read(t,()=>({op:"getTableCellBody",cell:this.path.handle()}),n=>e.hydrateAddress({kind:"handle",handle:u(n,t)})),this.#t=e,e}get value(){return this.loadedProperty("value")}set value(t){typeof t!="string"&&a({code:"InvalidArgument",target:`${this.path.label}.value`}),this.command("value",()=>({op:"updateTableCell",cell:this.path.handle(),properties:{value:t}}));}get columnWidth(){return this.loadedProperty("columnWidth")}set columnWidth(t){(typeof t!="number"||!Number.isFinite(t)||t<=0)&&a({code:"InvalidArgument",target:`${this.path.label}.columnWidth`}),this.command("columnWidth",()=>({op:"updateTableCell",cell:this.path.handle(),properties:{columnWidth:t}}));}get shadingColor(){return this.loadedProperty("shadingColor")}set shadingColor(t){typeof t!="string"&&a({code:"InvalidArgument",target:`${this.path.label}.shadingColor`}),this.command("shadingColor",()=>({op:"updateTableCell",cell:this.path.handle(),properties:{shadingColor:t}}));}get verticalAlignment(){return this.loadedProperty("verticalAlignment")}set verticalAlignment(t){t!=="Top"&&t!=="Center"&&t!=="Bottom"&&a({code:"InvalidArgument",target:`${this.path.label}.verticalAlignment`}),this.command("verticalAlignment",()=>({op:"updateTableCell",cell:this.path.handle(),properties:{verticalAlignment:t}}));}onLoad(t){let e=this.selection(t,["value","columnWidth","shadingColor","verticalAlignment"]);this.read(this.path.label,()=>({op:"getTableCellProperties",cell:this.path.handle()}),n=>{n.kind!=="tableCell"&&a({code:"GeneralException",target:this.path.label});for(let r of e)this.setLoadedProperty(r,n.cell[r]);});}},U=class o extends x{#t;static of(t,e,n,r){return new o(t,c.derived(e,n),r)}static over(t,e,n,r){return o.of(t,e,n,()=>({op:"getTables",scope:r()}))}constructor(t,e,n){super(t,e),this.#t=n;}getFirst(){return this.edge("first","getFirst",false)}getFirstOrNullObject(){return this.edge("first","getFirstOrNullObject",true)}listing(){return this.#t()}itemAt(t,e){return W.at(this.context,t,e)}promised(t,e){return W.promised(this.context,t,e)}},st=class o extends x{#t;static of(t,e,n,r){return new o(t,c.derived(e,n),r)}constructor(t,e,n){super(t,e),this.#t=n;}getFirst(){return this.edge("first","getFirst",false)}getFirstOrNullObject(){return this.edge("first","getFirstOrNullObject",true)}listing(){return this.#t()}itemAt(t,e){return at.at(this.context,t,e)}promised(t,e){return at.promised(this.context,t,e)}},Pt=class o extends x{#t;static of(t,e,n,r){return new o(t,c.derived(e,n),r)}constructor(t,e,n){super(t,e),this.#t=n;}getFirst(){return this.edge("first","getFirst",false)}getFirstOrNullObject(){return this.edge("first","getFirstOrNullObject",true)}listing(){return this.#t()}itemAt(t,e){return tt.at(this.context,t,e)}promised(t,e){return tt.promised(this.context,t,e)}};var Xt=(i=>(i.replace="Replace",i.start="Start",i.end="End",i.before="Before",i.after="After",i))(Xt||{}),Kt=(s=>(s.mixed="Mixed",s.unknown="Unknown",s.left="Left",s.centered="Centered",s.right="Right",s.justified="Justified",s))(Kt||{}),Zt=(e=>(e.portrait="Portrait",e.landscape="Landscape",e))(Zt||{}),Yt=(n=>(n.off="Off",n.trackAll="TrackAll",n.trackMineOnly="TrackMineOnly",n))(Yt||{}),Jt=(r=>(r.mixed="Mixed",r.top="Top",r.center="Center",r.bottom="Bottom",r))(Jt||{}),_t=(d=>(d.line="Line",d.page="Page",d.next="Next",d.sectionNext="SectionNext",d.sectionContinuous="SectionContinuous",d.sectionEven="SectionEven",d.sectionOdd="SectionOdd",d))(_t||{}),te=(y=>(y.unknown="Unknown",y.richText="RichText",y.plainText="PlainText",y.picture="Picture",y.buildingBlockGallery="BuildingBlockGallery",y.checkBox="CheckBox",y.comboBox="ComboBox",y.datePicker="DatePicker",y.dropDownList="DropDownList",y.group="Group",y.repeatingSection="RepeatingSection",y.plainTextInline="PlainTextInline",y.plainTextParagraph="PlainTextParagraph",y.richTextInline="RichTextInline",y.richTextParagraphs="RichTextParagraphs",y.richTextTable="RichTextTable",y.richTextTableCell="RichTextTableCell",y.richTextTableRow="RichTextTableRow",y))(te||{});var De=["Replace","Start","End"],$e=["Start","End"],Be=["Replace","Start","End"],He=["Before","After"],Me=["Replace","Start","End","Before","After"],Fe=["Select","Start","End"];function dt(o,t,e){return (typeof o!="string"||!t.includes(o))&&a({code:"InvalidArgument",target:e}),o}var fe=(o,t)=>dt(o,De,t),be=(o,t)=>dt(o,$e,t),ye=(o,t)=>dt(o,Be,t),xe=(o,t)=>dt(o,He,t),Ot=(o,t)=>dt(o,Me,t),Dt=(o,t)=>o===void 0?"Select":dt(o,Fe,t);function k(o,t){return typeof o!="string"&&a({code:"InvalidArgument",target:t}),/[\r\n\v\f\u2028\u2029]/.test(o)&&a({code:"InvalidArgument",target:t}),o}var Ve=8,ne=(d=>(d.custom="Custom",d.solid="Solid",d.hollow="Hollow",d.square="Square",d.diamonds="Diamonds",d.arrow="Arrow",d.checkmark="Checkmark",d))(ne||{}),oe=(s=>(s.none="None",s.arabic="Arabic",s.upperRoman="UpperRoman",s.lowerRoman="LowerRoman",s.upperLetter="UpperLetter",s.lowerLetter="LowerLetter",s))(oe||{}),j=class o extends p{#t;#n=new Map;static at(t,e,n){return n.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new o(t,c.of(e,n.handle),false)}static promised(t,e,n){return new o(t,c.pending(e),n)}constructor(t,e,n){super(t,e,{nullable:n});}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??=L.overListing(this.context,`${this.path.label}.paragraphs`,this.path,()=>({op:"getListParagraphs",list:this.#o()})),this.#t}getLevelParagraphs(t){let e=`${this.path.label}.getLevelParagraphs`,n=ee(t,e);return L.overListing(this.context,e,this.path,()=>({op:"getListParagraphs",list:this.#o(),level:n}))}insertParagraph(t,e){let n=`${this.path.label}.insertParagraph`,r=k(t,n);e!=="Start"&&e!=="End"&&e!=="Before"&&e!=="After"&&a({code:"InvalidArgument",target:n});let i=w.promised(this.context,n,false);return this.commandAnswering(n,()=>({op:"insertListParagraph",list:this.#o(),where:e==="Start"||e==="Before"?"start":"end",text:r}),s=>{i.hydrateAddress({kind:"handle",handle:u(s,n)});}),i}setLevelBullet(t,e,n,r){this.#e(t,{bullet:e,...n===void 0?{}:{charCode:n},...r===void 0?{}:{fontName:r}});}setLevelNumbering(t,e,n){this.#e(t,{numbering:e,...n===void 0?{}:{formatString:[...n]}});}setLevelStartingNumber(t,e){this.#e(t,{startingNumber:e});}setLevelIndents(t,e,n){this.#e(t,{textIndent:e,bulletNumberPictureIndent:n});}#e(t,e){let n=`${this.path.label}.levelFormat`,r=ee(t,n);this.requireUsablePath();let i=this.#n.get(r);if(i){Object.assign(i,e),"bullet"in e&&(delete i.numbering,delete i.formatString),"numbering"in e&&(delete i.bullet,delete i.charCode,delete i.fontName);return}let s={...e};this.#n.set(r,s),this.commandAnswering(n,()=>({op:"setListLevelFormat",list:this.#o(),level:r,format:s}),d=>{m(d,n);},()=>{this.#n.get(r)===s&&this.#n.delete(r);});}onLoad(t){if(!this.selection(t,["id"]).includes("id"))return;let e=`${this.path.label}.id`;this.read(e,()=>({op:"getListId",list:this.#o()}),n=>{this.setLoadedProperty("id",Nt(n,e));});}#o(){return this.requireAddressable(),this.path.handle()}},lt=class o extends x{#t;static of(t,e,n,r){return new o(t,c.derived(e,n),r)}constructor(t,e,n){super(t,e),this.#t=n;}getFirst(){return this.edge("first","getFirst",false)}getById(t){let e=`${this.path.label}.getById`,n=We(t,e),r=this.#t,i=j.promised(this.context,e,false);return this.enqueue({sort:"read",label:e,plan:()=>({op:"getListById",body:r,id:n}),settle:s=>{i.hydrateAddress({kind:"handle",handle:u(s,e)});}}),i}listing(){return {op:"getLists",body:this.#t}}itemAt(t,e){return j.at(this.context,t,e)}promised(t,e){return j.promised(this.context,t,e)}},ct=class o extends p{static of(t,e,n){return new o(t,c.derived(e,n))}constructor(t,e){super(t,e);}get level(){return this.loadedProperty("level")}set level(t){let e=`${this.path.label}.level`,n=ee(t,e);this.commandAnswering(e,()=>({op:"setListLevel",paragraph:this.#t(),level:n}),r=>{m(r,e);});}onLoad(t){if(!this.selection(t,["level"]).includes("level"))return;let e=`${this.path.label}.level`;this.read(e,()=>({op:"getListLevel",paragraph:this.#t()}),n=>{this.setLoadedProperty("level",Nt(n,e));});}#t(){this.requireAddressable();let t=this.path.address();return t.kind!=="handle"&&a({code:"InvalidObjectPath",target:this.path.label}),t.handle}};function ee(o,t){return (!Number.isInteger(o)||o<0||o>Ve)&&a({code:"InvalidArgument",target:t}),o}function We(o,t){return (!Number.isInteger(o)||o<=0)&&a({code:"InvalidArgument",target:t}),o}var re=(f=>(f.mixed="Mixed",f.none="None",f.hidden="Hidden",f.dotLine="DotLine",f.single="Single",f.word="Word",f.double="Double",f.thick="Thick",f.dotted="Dotted",f.dottedHeavy="DottedHeavy",f.dashLine="DashLine",f.dashLineHeavy="DashLineHeavy",f.dashLineLong="DashLineLong",f.dashLineLongHeavy="DashLineLongHeavy",f.dotDashLine="DotDashLine",f.dotDashLineHeavy="DotDashLineHeavy",f.twoDotDashLine="TwoDotDashLine",f.twoDotDashLineHeavy="TwoDotDashLineHeavy",f.wave="Wave",f.waveHeavy="WaveHeavy",f.waveDouble="WaveDouble",f))(re||{}),Ue=["bold","italic","color","name","size","underline","strikeThrough","highlightColor","subscript","superscript"],N=class o extends p{#t;#n;static of(t,e,n,r){return new o(t,c.derived(e,n),r)}constructor(t,e,n){super(t,e),this.#t=n;}get bold(){return this.loadedProperty("bold")}set bold(t){this.#e("bold",Rt(t,`${this.path.label}.bold`));}get italic(){return this.loadedProperty("italic")}set italic(t){this.#e("italic",Rt(t,`${this.path.label}.italic`));}get color(){return this.loadedProperty("color")}set color(t){this.#e("color",$t(t,`${this.path.label}.color`));}get name(){return this.loadedProperty("name")}set name(t){this.#e("name",$t(t,`${this.path.label}.name`));}get size(){return this.loadedProperty("size")}set size(t){this.#e("size",Ge(t,`${this.path.label}.size`));}get underline(){return this.loadedProperty("underline")}set underline(t){this.#e("underline",$t(t,`${this.path.label}.underline`));}get highlightColor(){return this.loadedProperty("highlightColor")}set highlightColor(t){this.#e("highlightColor",t===null?null:$t(t,`${this.path.label}.highlightColor`));}get strikeThrough(){return this.loadedProperty("strikeThrough")}set strikeThrough(t){this.#e("strikeThrough",Rt(t,`${this.path.label}.strikeThrough`));}get subscript(){return this.loadedProperty("subscript")}set subscript(t){this.#e("subscript",Rt(t,`${this.path.label}.subscript`));}get superscript(){return this.loadedProperty("superscript")}set superscript(t){this.#e("superscript",Rt(t,`${this.path.label}.superscript`));}onLoad(t){let e=this.selection(t,Ue);if(e.length===0)return;let n=`${this.path.label}.font`;this.read(n,()=>({op:"getFont",span:this.#o()}),r=>{let i=Vt(r,n);for(let s of e)this.setLoadedProperty(s,i[s]);});}#e(t,e){if(this.requireUsablePath(),this.#n){this.#n[t]=e,t==="subscript"&&e===true&&(this.#n.superscript=false),t==="superscript"&&e===true&&(this.#n.subscript=false);return}let n={[t]:e};t==="subscript"&&e===true&&(n.superscript=false),t==="superscript"&&e===true&&(n.subscript=false),this.#n=n;let r=`${this.path.label}.${t}`;this.commandAnswering(this.path.label,()=>({op:"setFont",span:this.#o(),font:n}),i=>{m(i,r);},()=>{this.#n===n&&(this.#n=void 0);});}#o(){return this.requireAddressable(),R(this.path,this.#t)}};function Rt(o,t){return typeof o!="boolean"&&a({code:"InvalidArgument",target:t}),o}function Ge(o,t){return (typeof o!="number"||!Number.isFinite(o))&&a({code:"InvalidArgument",target:t}),o}function $t(o,t){return (typeof o!="string"||o.length===0)&&a({code:"InvalidArgument",target:t}),o}var ze=16,w=class o extends p{#t;#n;#e;#o;static at(t,e,n){return n.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new o(t,c.of(e,n.handle),false)}static promised(t,e,n){return new o(t,c.pending(e),n)}constructor(t,e,n){super(t,e,{nullable:n});}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",it(t,`${this.path.label}.style`));}get font(){return this.#t??=N.of(this.context,`${this.path.label}.font`,this.path,"paragraph"),this.#t}get alignment(){return this.loadedProperty("alignment")}set alignment(t){this.#i("alignment",Xe(t,`${this.path.label}.alignment`));}get firstLineIndent(){return this.loadedProperty("firstLineIndent")}set firstLineIndent(t){this.#i("firstLineIndent",ht(t,`${this.path.label}.firstLineIndent`));}get leftIndent(){return this.loadedProperty("leftIndent")}set leftIndent(t){this.#i("leftIndent",ht(t,`${this.path.label}.leftIndent`));}get rightIndent(){return this.loadedProperty("rightIndent")}set rightIndent(t){this.#i("rightIndent",ht(t,`${this.path.label}.rightIndent`));}get lineSpacing(){return this.loadedProperty("lineSpacing")}set lineSpacing(t){this.#i("lineSpacing",ht(t,`${this.path.label}.lineSpacing`));}get spaceBefore(){return this.loadedProperty("spaceBefore")}set spaceBefore(t){this.#i("spaceBefore",ht(t,`${this.path.label}.spaceBefore`));}get spaceAfter(){return this.loadedProperty("spaceAfter")}set spaceAfter(t){this.#i("spaceAfter",ht(t,`${this.path.label}.spaceAfter`));}get list(){return this.#n??=this.#s(`${this.path.label}.list`),this.#n}getRange(t="Whole"){let e=`${this.path.label}.getRange`;["Whole","Content","Start","End","Before","After"].includes(t)||a({code:"InvalidArgument",target:e});let n=b.promised(this.context,e,false);return this.read(e,()=>({op:"getRange",span:{paragraph:this.#r()},location:t}),r=>{n.hydrateAddress({kind:"span",span:P(r,e)});}),n}startNewList(){let t=`${this.path.label}.startNewList`,e=j.promised(this.context,t,false);return this.commandAnswering(t,()=>({op:"startNewList",paragraph:this.#r()}),n=>{e.hydrateAddress({kind:"handle",handle:u(n,t)});}),e}attachToList(t,e){let n=`${this.path.label}.attachToList`;(!Number.isSafeInteger(t)||t<=0||!Number.isInteger(e)||e<0||e>8)&&a({code:"InvalidArgument",target:n});let r=j.promised(this.context,n,false);return this.commandAnswering(n,()=>({op:"attachToList",paragraph:this.#r(),listId:t,level:e}),i=>{r.hydrateAddress({kind:"handle",handle:u(i,n)});}),r}detachFromList(){let t=`${this.path.label}.detachFromList`;this.commandAnswering(t,()=>({op:"detachFromList",paragraph:this.#r()}),e=>{m(e,t);});}get listItem(){return this.#e??=ct.of(this.context,`${this.path.label}.listItem`,this.path),this.#e}clear(){this.commandDiscarding("clear",()=>({op:"replaceSpan",span:{paragraph:this.#r()},text:""}));}delete(){this.command("delete",()=>({op:"deleteParagraph",paragraph:this.#r()}));}insertText(t,e){let n=`${this.path.label}.insertText`,r=k(t,n),i=ye(e,n),s=b.promised(this.context,n,false);return this.commandAnswering(n,()=>i==="Replace"?{op:"replaceSpan",span:{paragraph:this.#r()},text:r}:{op:"insertText",at:{paragraph:this.#r(),at:i==="Start"?"start":"end"},text:r},d=>{s.hydrateAddress({kind:"span",span:P(d,n)});}),s}insertParagraph(t,e){let n=`${this.path.label}.insertParagraph`,r=k(t,n),i=xe(e,n),s=o.promised(this.context,n,false);return this.commandAnswering(n,()=>({op:"insertParagraph",anchor:{paragraph:this.#r()},where:i==="Before"?"before":"after",text:r}),d=>{d.kind!=="handle"&&a({code:"GeneralException",target:n}),s.hydrateAddress({kind:"handle",handle:d.handle});}),s}split(t,e,n){let r=`${this.path.label}.split`,i=Ke(t,r),s=Ae(e,`${r}.trimDelimiters`),d=Ae(n,`${r}.trimSpacing`),h=E.answered(this.context,r,this.path);return this.commandAnswering(r,()=>({op:"splitParagraph",paragraph:this.#r(),delimiters:i,...s?{trimDelimiters:true}:{},...d?{trimSpacing:true}:{}}),A=>{h.fill(A,r);}),h}onLoad(t){let e=this.selection(t,["text","uniqueLocalId",...Ce]);e.includes("text")&&this.loadTextInto("text",()=>({op:"getText",target:this.#r(),projection:this.revisionTextView()})),e.includes("uniqueLocalId")&&this.loadTextInto("uniqueLocalId",()=>({op:"getParagraphId",paragraph:this.#r()}));let n=Ce.filter(i=>e.includes(i));if(n.length===0)return;let r=`${this.path.label}.paragraphFormat`;this.read(r,()=>({op:"getParagraphFormat",paragraph:{paragraph:this.#r()}}),i=>{let s=Wt(i,r);for(let d of n)this.setLoadedProperty(d,s[d]);});}#i(t,e){if(this.requireUsablePath(),this.#o){this.#o[t]=e;return}let n={[t]:e};this.#o=n;let r=`${this.path.label}.${t}`;this.commandAnswering(`${this.path.label}.paragraphFormat`,()=>({op:"setParagraphFormat",paragraph:{paragraph:this.#r()},format:n}),i=>{m(i,r);},()=>{this.#o===n&&(this.#o=void 0);});}#s(t){let e=j.promised(this.context,t,false);return this.read(t,()=>({op:"getParagraphList",paragraph:this.#r()}),n=>{e.hydrateAddress({kind:"handle",handle:u(n,t)});}),e}#r(){return this.requireAddressable(),this.path.handle()}},Ce=["style","alignment","firstLineIndent","leftIndent","rightIndent","lineSpacing","spaceBefore","spaceAfter"],Qe=["Left","Centered","Right","Justified"];function Xe(o,t){return Qe.includes(o)||a({code:"InvalidArgument",target:t}),o}function ht(o,t){return (typeof o!="number"||!Number.isFinite(o))&&a({code:"InvalidArgument",target:t}),o}function Ke(o,t){(!Array.isArray(o)||o.length===0||o.length>ze)&&a({code:"InvalidArgument",target:t});for(let e of o)(typeof e!="string"||e.length===0)&&a({code:"InvalidArgument",target:t});return [...o]}function Ae(o,t){return o!==void 0&&typeof o!="boolean"&&a({code:"InvalidArgument",target:t}),o===true}var L=class o extends T{#t;static of(t,e,n){return new o(t,c.derived(e,n),null)}static overListing(t,e,n,r){return new o(t,c.derived(e,n),r)}constructor(t,e,n){super(t,e),this.#t=n;}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 v(t,e).length}addressAt(t,e,n){let r=v(t,e)[n];return r?{kind:"handle",handle:r}:void 0}itemAt(t,e){return w.at(this.context,t,e)}promised(t,e){return w.promised(this.context,t,e)}},E=class o extends T{#t;static of(t,e,n,r){return new o(t,c.derived(e,n),r)}static answered(t,e,n){return new o(t,c.derived(e,n),null)}constructor(t,e,n){super(t,e),this.#t=n;}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 Tt(t,e).length}addressAt(t,e,n){let r=Tt(t,e)[n];return r?{kind:"span",span:r}:void 0}itemAt(t,e){return b.at(this.context,t,e)}promised(t,e){return b.promised(this.context,t,e)}};var Pe=4096,D=class o extends p{#t;#n=new Map;#e;#o;static at(t,e,n){return n.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new o(t,c.of(e,n.handle),false)}static promised(t,e,n){return new o(t,c.pending(e),n)}constructor(t,e,n){super(t,e,{nullable:n});}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.#s("tag",{tag:ie(t,`${this.path.label}.tag`)});}get title(){return this.loadedProperty("title")}set title(t){this.#s("title",{title:ie(t,`${this.path.label}.title`)});}get subtype(){return this.loadedProperty("subtype")}get isBound(){return this.loadedProperty("isBound")}get cannotDelete(){let t=this.loadedProperty("lock");return t==="sdtLocked"||t==="sdtContentLocked"}set cannotDelete(t){this.#r("cannotDelete",t);}get cannotEdit(){let t=this.loadedProperty("lock");return t==="contentLocked"||t==="sdtContentLocked"}set cannotEdit(t){this.#r("cannotEdit",t);}get placeholderShown(){return this.loadedProperty("placeholderShown")}get temporary(){return this.loadedProperty("temporary")}get text(){return this.loadedProperty("text")}get paragraphs(){return this.#e??=L.overListing(this.context,`${this.path.label}.paragraphs`,this.path,()=>({op:"getContentControlParagraphs",contentControl:this.#a()})),this.#e}get contentControls(){return this.#o??=$.of(this.context,`${this.path.label}.contentControls`,this.path,{contentControl:this.#a()}),this.#o}getRange(t){let e=`${this.path.label}.getRange`,n=Ze(t??"Whole",e),r=this.#n.get(n);if(r)return r;let i=this.#i(e,n);return this.#n.set(n,i),i}setValue(t){let e=`${this.path.label}.setValue`,n=Ye(t,e);this.command("setValue",()=>({op:"setContentControlValue",contentControl:this.#a(),value:n}));}insertText(t,e){let n=`${this.path.label}.insertText`,r=k(t,n),i=e==="Replace"?"replace":e==="Start"?"start":e==="End"?"end":a({code:"InvalidArgument",target:n}),s=b.promised(this.context,n,false);return this.commandAnswering(n,()=>({op:"insertContentControlText",contentControl:this.#a(),text:r,at:i}),d=>{s.hydrateAddress({kind:"span",span:P(d,n)});}),s}delete(t){let e=`${this.path.label}.delete`;typeof t!="boolean"&&a({code:"InvalidArgument",target:e}),this.command("delete",()=>({op:"deleteContentControl",contentControl:this.#a(),keepContent:t}));}onLoad(t){let e=this.selection(t,["id","tag","title","subtype","isBound","text","cannotDelete","cannotEdit","placeholderShown","temporary"]);if(e.includes("id")&&this.loadTextInto("id",()=>({op:"getContentControlFileId",contentControl:this.#a()})),e.includes("tag")&&this.loadTextInto("tag",()=>({op:"getContentControlTag",contentControl:this.#a()})),e.includes("title")&&this.loadTextInto("title",()=>({op:"getContentControlTitle",contentControl:this.#a()})),e.includes("subtype")&&this.loadTextInto("subtype",()=>({op:"getContentControlSubtype",contentControl:this.#a()})),e.includes("isBound")){let r=`${this.path.label}.isBound`;this.read(r,()=>({op:"getContentControlIsBound",contentControl:this.#a()}),i=>{this.setLoadedProperty("isBound",_(i,r));});}if(e.includes("text")&&this.loadTextInto("text",()=>({op:"getContentControlText",contentControl:this.#a(),projection:this.revisionTextView()})),e.includes("cannotDelete")||e.includes("cannotEdit")){let r=`${this.path.label}.lock`;this.read(r,()=>({op:"getContentControlLock",contentControl:this.#a()}),i=>{this.setLoadedProperty("lock",O(i,r));});}if(e.includes("placeholderShown")){let r=`${this.path.label}.placeholderShown`;this.read(r,()=>({op:"getContentControlPlaceholderShown",contentControl:this.#a()}),i=>{this.setLoadedProperty("placeholderShown",_(i,r));});}if(!e.includes("temporary"))return;let n=`${this.path.label}.temporary`;this.read(n,()=>({op:"getContentControlTemporary",contentControl:this.#a()}),r=>{this.setLoadedProperty("temporary",_(r,n));});}#i(t,e){let n=b.promised(this.context,t,false);return this.read(t,()=>({op:"getContentControlRange",contentControl:this.#a(),location:e}),r=>{n.hydrateAddress({kind:"span",span:P(r,t)});}),n}#s(t,e){this.command(t,()=>({op:"setContentControlProperties",contentControl:this.#a(),...e}));}#r(t,e){let n=`${this.path.label}.${t}`;if(typeof e!="boolean"&&a({code:"InvalidArgument",target:n}),this.requireUsablePath(),this.#t){this.#t[t]=e;return}let r={[t]:e};this.#t=r,this.command(t,()=>({op:"setContentControlProperties",contentControl:this.#a(),...r}),()=>{this.#t===r&&(this.#t=void 0);});}#a(){return this.requireAddressable(),this.path.handle()}},$=class o extends x{#t;#n;static of(t,e,n,r){return new o(t,c.derived(e,n),r,()=>({op:"getContentControls",scope:r}))}constructor(t,e,n,r){super(t,e),this.#t=n,this.#n=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 n=this.#t,r=D.promised(this.context,e,false);return this.enqueue({sort:"read",label:e,plan:()=>({op:"getContentControlById",scope:n,id:t}),settle:i=>{r.hydrateAddress({kind:"handle",handle:u(i,e)});}}),r}getByTag(t){let e=`${this.path.label}.getByTag`,n=ve(t,e),r=this.#t;return new o(this.context,c.derived(e,this.path),r,()=>({op:"getContentControlsByTag",scope:r,tag:n}))}getByTitle(t){let e=`${this.path.label}.getByTitle`,n=ve(t,e),r=this.#t;return new o(this.context,c.derived(e,this.path),r,()=>({op:"getContentControlsByTitle",scope:r,title:n}))}listing(){return this.#n()}itemAt(t,e){return D.at(this.context,t,e)}promised(t,e){return D.promised(this.context,t,e)}};function ie(o,t){return (typeof o!="string"||o.length>Pe)&&a({code:"InvalidArgument",target:t}),o}function ve(o,t){let e=ie(o,t);return e.length===0&&a({code:"InvalidArgument",target:t}),e}function Ze(o,t){switch(o){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 Ye(o,t){(typeof o!="object"||o===null)&&a({code:"InvalidArgument",target:t});let e=o;if(e.kind==="text"||e.kind==="listItem"){let n=e.kind==="text"?e.text:e.value;return (typeof n!="string"||n.length>Pe)&&a({code:"InvalidArgument",target:t}),e.kind==="text"?{kind:"text",text:n}:{kind:"listItem",value:n}}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 Je(o,t){return t<1||t>12?0:t===2?o%4===0&&o%100!==0||o%400===0?29:28:t===4||t===6||t===9||t===11?30:31}function Oe(o){if(o.length===0)return null;let t=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,9}))?(Z|[+-]\d{2}:\d{2})$/.exec(o.trim());if(!t)return null;let e=Number(t[1]),n=Number(t[2]),r=Number(t[3]),i=Je(e,n);if(e===0||i===0||r<1||r>i)return null;let s=Number(t[4]),d=Number(t[5]),h=Number(t[6]);if(s>23||d>59||h>59)return null;let A=t[7],K=A===void 0?0:Number(A.padEnd(3,"0").slice(0,3));if(Number.isNaN(K))return null;let ot=`${t[1]}-${t[2]}-${t[3]}T${t[4]}:${t[5]}:${t[6]}.${String(K).padStart(3,"0")}Z`,Lt=Date.parse(ot);if(Number.isNaN(Lt))return null;let g=t[8];if(g==="Z")return new Date(Lt);let Z=Number(g.slice(1,3)),rt=Number(g.slice(4,6));if(rt>59||Z>14||Z===14&&rt!==0)return null;let Mt=g[0]==="+"?1:-1,wt=new Date(Lt-Mt*(Z*36e5+rt*6e4));return Number.isNaN(wt.getTime())?null:wt}var Bt=class extends p{hydrateAddress(t){t.kind==="handle"?this.path.resolveTo(t.handle):this.path.resolveNull();}hydrateNull(){this.path.resolveNull();}get authorName(){return this.loadedProperty("authorName")}get creationDate(){return this.loadedProperty("creationDate")}get id(){return this.loadedProperty("id")}get text(){return this.loadedProperty("text")}delete(){this.command("delete",()=>({op:"deleteComment",comment:this.commentHandle()}));}loadCommentFields(t,e){let n=this.selection(t,["authorName","creationDate","id","text",...e]);if(n.includes("authorName")&&this.loadTextInto("authorName",()=>({op:"getCommentAuthor",comment:this.commentHandle()})),n.includes("text")&&this.loadTextInto("text",()=>({op:"getCommentText",comment:this.commentHandle()})),n.includes("id")&&this.loadTextInto("id",()=>({op:"getCommentId",comment:this.commentHandle()})),n.includes("creationDate")){let i=`${this.path.label}.creationDate`;this.read(i,()=>({op:"getCommentDate",comment:this.commentHandle()}),s=>{this.setLoadedProperty("creationDate",Oe(O(s,i)));});}if(!n.includes("resolved"))return;let r=`${this.path.label}.resolved`;this.read(r,()=>({op:"getCommentResolved",comment:this.commentHandle()}),i=>{this.setLoadedProperty("resolved",_(i,r));});}commentHandle(){return this.requireAddressable(),this.path.handle()}},et=class o extends Bt{static at(t,e,n){return n.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new o(t,c.of(e,n.handle),false)}static promised(t,e,n){return new o(t,c.pending(e),n)}constructor(t,e,n){super(t,e,{nullable:n});}onLoad(t){this.loadCommentFields(t,[]);}},It=class o extends x{#t;static of(t,e,n,r){return new o(t,c.derived(e,n),r)}constructor(t,e,n){super(t,e),this.#t=n;}getFirst(){return this.edge("first","getFirst",false)}listing(){return this.#t()}itemAt(t,e){return et.at(this.context,t,e)}promised(t,e){return et.promised(this.context,t,e)}},G=class o extends Bt{#t;static at(t,e,n){return n.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new o(t,c.of(e,n.handle),false)}static promised(t,e,n){return new o(t,c.pending(e),n)}constructor(t,e,n){super(t,e,{nullable:n});}get resolved(){return this.loadedProperty("resolved")}set resolved(t){let e=`${this.path.label}.resolved`;typeof t!="boolean"&&a({code:"InvalidArgument",target:e}),this.commandAnswering(e,()=>({op:"setCommentResolved",comment:this.commentHandle(),resolved:t}),n=>{m(n,e);});}get replies(){return this.#t??=It.of(this.context,`${this.path.label}.replies`,this.path,()=>({op:"getCommentReplies",comment:this.commentHandle()})),this.#t}getRange(){let t=`${this.path.label}.getRange`,e=b.promised(this.context,t,false);return this.read(t,()=>({op:"getCommentRange",comment:this.commentHandle()}),n=>{e.hydrateAddress({kind:"span",span:P(n,t)});}),e}reply(t){let e=`${this.path.label}.reply`;(typeof t!="string"||t.length===0)&&a({code:"InvalidArgument",target:e});let n=this.internals.author;(typeof n!="string"||n.trim().length===0)&&a({code:"NotSupported",target:e});let r=et.promised(this.context,e,false);return this.commandAnswering(e,()=>({op:"replyToComment",comment:this.commentHandle(),text:t,author:n}),i=>{r.hydrateAddress({kind:"handle",handle:u(i,e)});}),r}onLoad(t){this.loadCommentFields(t,["resolved"]);}},z=class o extends x{#t;static of(t,e,n,r){return new o(t,c.derived(e,n),r)}constructor(t,e,n){super(t,e),this.#t=n;}getFirst(){return this.edge("first","getFirst",false)}listing(){return this.#t()}itemAt(t,e){return G.at(this.context,t,e)}promised(t,e){return G.promised(this.context,t,e)}},pt=class o extends p{static at(t,e,n){return n.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new o(t,c.of(e,n.handle),false)}static promised(t,e,n){return new o(t,c.pending(e),n)}constructor(t,e,n){super(t,e,{nullable:n});}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=b.promised(this.context,t,false);return this.read(t,()=>({op:"getRevisionRange",revision:this.#t()}),n=>{e.hydrateAddress({kind:"span",span:P(n,t)});}),e}accept(){this.command("accept",()=>({op:"acceptRevision",revision:this.#t()}));}reject(){this.command("reject",()=>({op:"rejectRevision",revision:this.#t()}));}onLoad(t){let e=this.selection(t,["author","date","type"]);if(e.includes("author")&&this.loadTextInto("author",()=>({op:"getRevisionAuthor",revision:this.#t()})),e.includes("type")&&this.loadTextInto("type",()=>({op:"getRevisionType",revision:this.#t()})),!e.includes("date"))return;let n=`${this.path.label}.date`;this.read(n,()=>({op:"getRevisionDate",revision:this.#t()}),r=>{this.setLoadedProperty("date",Oe(O(r,n)));});}#t(){return this.requireAddressable(),this.path.handle()}},Q=class o extends x{#t;static of(t,e,n,r){return new o(t,c.derived(e,n),r)}constructor(t,e,n){super(t,e),this.#t=n;}acceptAll(){let t=this.#t;this.commandOn("acceptAll",()=>({op:"acceptAllRevisions",body:t}));}rejectAll(){let t=this.#t;this.commandOn("rejectAll",()=>({op:"rejectAllRevisions",body:t}));}listing(){return {op:"getRevisions",body:this.#t}}itemAt(t,e){return pt.at(this.context,t,e)}promised(t,e){return pt.promised(this.context,t,e)}commandOn(t,e){let n=`${this.path.label}.${t}`;this.enqueue({sort:"write",label:n,plan:e,settle:r=>{m(r,n);}});}};var _e=new Set(["matchCase","matchWholeWord","ignorePunct","ignoreSpace","matchWildcards"]);function Ht(o,t){if(o===void 0)return;typeof o!="object"&&a({code:"InvalidArgument",target:t});for(let[n,r]of Object.entries(o))_e.has(n)||a({code:"InvalidArgument",target:`${t}.${n}`}),r!==void 0&&typeof r!="boolean"&&a({code:"InvalidArgument",target:`${t}.${n}`});let e={...o.matchCase===void 0?{}:{matchCase:o.matchCase},...o.matchWholeWord===void 0?{}:{matchWholeWord:o.matchWholeWord},...o.ignorePunct===void 0?{}:{ignorePunct:o.ignorePunct},...o.ignoreSpace===void 0?{}:{ignoreSpace:o.ignoreSpace},...o.matchWildcards===void 0?{}:{matchWildcards:o.matchWildcards}};return Object.keys(e).length===0?void 0:e}var b=class o extends p{#t;#n;#e;#o;#i;#s;static at(t,e,n){return n.kind!=="span"&&a({code:"InvalidObjectPath",target:e}),new o(t,c.ofSpan(e,n.span),false)}static promised(t,e,n){return new o(t,c.pending(e),n)}constructor(t,e,n){super(t,e,{nullable:n});}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.#i??=N.of(this.context,`${this.path.label}.font`,this.path,"span"),this.#i}get paragraphs(){return this.#o??=L.of(this.context,`${this.path.label}.paragraphs`,this.path),this.#o}get style(){return this.loadedProperty("style")}set style(t){let e=`${this.path.label}.style`,n=it(t,e);this.requireAddressable(),this.command("style",()=>({op:"setStyle",span:R(this.path,"span"),name:n}));}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}),this.requireUsablePath(),this.command("hyperlink",()=>({op:"setHyperlink",span:this.#r(),target:t}));}get bookmarks(){let t=this.#r();return this.#s??=X.of(this.context,`${this.path.label}.bookmarks`,this.path,()=>({op:"getBookmarks",scope:{start:t.start,end:t.end}})),this.#s}search(t,e){let n=`${this.path.label}.search`;typeof t!="string"&&a({code:"InvalidArgument",target:n});let r=Ht(e,n),i=this.#r();return E.of(this.context,n,this.path,()=>({op:"search",scope:i,text:t,options:{...r??{},projection:this.revisionTextView()}}))}insertText(t,e){let n=`${this.path.label}.insertText`,r=k(t,n),i=Ot(e,n);this.requireUsablePath();let s=o.promised(this.context,n,false);return this.commandAnswering(n,()=>{let d=this.#r();return i==="Replace"?{op:"replaceSpan",span:d,text:r}:{op:"insertText",at:i==="Start"||i==="Before"?d.start:d.end,text:r}},d=>{s.hydrateAddress({kind:"span",span:P(d,n)});}),s}delete(){this.requireUsablePath(),this.commandDiscarding("delete",()=>({op:"replaceSpan",span:this.#r(),text:""}));}clear(){let t=this.#r();this.commandDiscarding("clear",()=>({op:"replaceSpan",span:t,text:""}));}insertComment(t){let e=`${this.path.label}.insertComment`;(typeof t!="string"||t.length===0)&&a({code:"InvalidArgument",target:e});let n=this.internals.author;(typeof n!="string"||n.trim().length===0)&&a({code:"NotSupported",target:e});let r=G.promised(this.context,e,false);return this.commandAnswering(e,()=>({op:"insertComment",span:this.#r(),text:t,author:n}),i=>{i.kind!=="handle"&&a({code:"GeneralException",target:e}),r.hydrateAddress(i);}),r}insertContentControl(t){let e=`${this.path.label}.insertContentControl`,n=t??"RichText";n!=="RichText"&&n!=="PlainText"&&a({code:"NotSupported",target:e});let r=D.promised(this.context,e,false);return this.commandAnswering(e,()=>({op:"insertContentControl",span:this.#r(),subtype:n==="PlainText"?"plainText":"richText",returnHandle:true}),i=>{i.kind!=="handle"&&a({code:"GeneralException",target:e}),r.hydrateAddress(i);}),r}get tables(){return this.requireUsablePath(),this.#t??=U.over(this.context,`${this.path.label}.tables`,this.path,()=>R(this.path,"span"))}get fields(){return this.requireUsablePath(),this.#n??=M.of(this.context,`${this.path.label}.fields`,this.path,"span")}insertField(t,e,n,r){let i=`${this.path.label}.insertField`;(e!==void 0&&typeof e!="string"||n!==void 0&&typeof n!="string"||r!==void 0&&typeof r!="boolean")&&a({code:"InvalidArgument",target:i});let s=Ot(t,i);this.requireUsablePath();let d=H.promised(this.context,i,false);return this.commandAnswering(i,()=>({op:"insertField",span:this.#r(),location:s,...e===void 0?{}:{fieldType:e},...n===void 0?{}:{text:n},...r===void 0?{}:{removeFormatting:r}}),h=>d.hydrateAddress({kind:"handle",handle:u(h,i)})),d}get inlinePictures(){return this.requireUsablePath(),this.#e??=V.of(this.context,`${this.path.label}.inlinePictures`,this.path,"span")}insertInlinePictureFromBase64(t,e){let n=`${this.path.label}.insertInlinePictureFromBase64`;(typeof t!="string"||t.length===0)&&a({code:"InvalidArgument",target:n});let r=Ot(e,n);this.requireUsablePath();let i=F.promised(this.context,n,false);return this.commandAnswering(n,()=>({op:"insertInlinePicture",span:this.#r(),base64:t,location:r}),s=>{i.hydrateAddress({kind:"handle",handle:u(s,n)});}),i}insertBreak(t,e){let n=`${this.path.label}.insertBreak`;e!=="Before"&&e!=="After"&&a({code:"InvalidArgument",target:n});let r=e;this.requireUsablePath(),this.commandAnswering(n,()=>({op:"insertBreak",span:this.#r(),breakType:t,location:r}),i=>m(i,n));}insertTable(t,e,n,r){let i=`${this.path.label}.insertTable`;(!Number.isInteger(t)||!Number.isInteger(e)||t<1||e<1||!["Before","After"].includes(n))&&a({code:"InvalidArgument",target:i}),r!==void 0&&(!Array.isArray(r)||r.some(h=>!Array.isArray(h)||h.some(A=>typeof A!="string")))&&a({code:"InvalidArgument",target:i});let s=r?.map(h=>[...h]),d=W.promised(this.context,i);return this.commandAnswering(i,()=>({op:"insertTable",span:R(this.path,"span"),location:n,rowCount:t,columnCount:e,...s?{values:s}:{}}),h=>{h.kind!=="handle"&&a({code:"GeneralException",target:i}),d.hydrateAddress({kind:"handle",handle:h.handle});}),d}insertParagraph(t,e){let n=`${this.path.label}.insertParagraph`,r=k(t,n),i=Ot(e,n);i!=="Before"&&i!=="After"&&a({code:"InvalidArgument",target:n});let s=this.#r(),d=i==="Before"?s.start.paragraph:s.end.paragraph,h=w.promised(this.context,n,false);return this.commandAnswering(n,()=>({op:"insertParagraph",anchor:{paragraph:d},where:i==="Before"?"before":"after",text:r}),A=>{A.kind!=="handle"&&a({code:"GeneralException",target:n}),h.hydrateAddress({kind:"handle",handle:A.handle});}),h}select(t){let e=`${this.path.label}.select`,n=Dt(t,e);this.requireAddressable(),this.internals.capabilities.selection||a({code:"NotSupported",target:e});let r=this.#r();this.command("select",()=>({op:"selectSpan",span:r,mode:n==="Select"?"select":n==="Start"?"start":"end"}));}onLoad(t){let e=this.selection(t,["text","style","hyperlink"]);if(e.includes("hyperlink")&&this.loadTextInto("hyperlink",()=>({op:"getHyperlink",span:this.#r()})),e.includes("text")){let r=`${this.path.label}.text`;this.read(r,()=>({op:"getSpanText",span:this.#r(),projection:this.revisionTextView()}),i=>{this.setLoadedProperty("text",O(i,r));});}if(!e.includes("style"))return;let n=`${this.path.label}.style`;this.requireUsablePath(),this.read(n,()=>({op:"getStyle",span:R(this.path,"span")}),r=>{this.setLoadedProperty("style",xt(r,n));});}#r(){return this.requireAddressable(),this.path.span()}};var ut=class o extends p{#t;static at(t,e,n){return n.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new o(t,c.of(e,n.handle),false)}static promised(t,e,n){return new o(t,c.pending(e),n)}constructor(t,e,n){super(t,e,{nullable:n});}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.#n(`${this.path.label}.range`),this.#t}select(t){let e=`${this.path.label}.select`,n=Dt(t,e);this.requireUsablePath(),this.internals.capabilities.selection||a({code:"NotSupported",target:e}),this.command("select",()=>({op:"selectBookmark",bookmark:this.#e(),mode:n==="Select"?"select":n==="Start"?"start":"end"}));}onLoad(t){if(!this.selection(t,["name"]).includes("name"))return;let e=`${this.path.label}.name`;this.read(e,()=>({op:"getBookmarkName",bookmark:this.#e()}),n=>{this.setLoadedProperty("name",O(n,e));});}#n(t){let e=b.promised(this.context,t,false);return this.read(t,()=>({op:"getBookmarkRange",bookmark:this.#e()}),n=>{e.hydrateAddress({kind:"span",span:P(n,t)});}),e}#e(){return this.requireAddressable(),this.path.handle()}},X=class o extends x{#t;static of(t,e,n,r){return new o(t,c.derived(e,n),r)}constructor(t,e,n){super(t,e),this.#t=n;}listing(){return this.#t()}itemAt(t,e){return ut.at(this.context,t,e)}promised(t,e){return ut.promised(this.context,t,e)}};var I=class o extends p{#t;#n;#e;#o;#i;#s;#r;#a;#l;static main(t,e){return new o(t,c.of(e,J(t).roots().body))}static promisedStory(t,e){return new o(t,c.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.#o??=this.paragraphsUnder(`${this.path.label}.paragraphs`),this.#o}get bookmarks(){let t=this.#d();return this.#i??=X.of(this.context,`${this.path.label}.bookmarks`,this.path,()=>({op:"getBookmarks",scope:{body:t}})),this.#i}get font(){return this.#s??=N.of(this.context,`${this.path.label}.font`,this.path,"body"),this.#s}paragraphsUnder(t){return L.of(this.context,t,this.path)}get style(){return this.loadedProperty("style")}set style(t){let e=`${this.path.label}.style`,n=it(t,e);this.requireAddressable(),this.command("style",()=>({op:"setStyle",span:R(this.path,"body"),name:n}));}get lists(){return this.#r??=lt.of(this.context,`${this.path.label}.lists`,this.path,this.#d()),this.#r}get contentControls(){return this.#a??=$.of(this.context,`${this.path.label}.contentControls`,this.path,{body:this.#d()}),this.#a}getComments(){let t=`${this.path.label}.getComments`,e=this.#d();return z.of(this.context,t,this.path,()=>({op:"getComments",scope:{body:e}}))}get revisions(){return this.#l??=Q.of(this.context,`${this.path.label}.revisions`,this.path,this.#d()),this.#l}getRange(t="Whole"){let e=`${this.path.label}.getRange`;this.requireUsablePath();let n=b.promised(this.context,e,false);return this.read(e,()=>({op:"getRange",span:{body:this.path.handle()},location:t}),r=>{n.hydrateAddress({kind:"span",span:P(r,e)});}),n}search(t,e){let n=`${this.path.label}.search`;typeof t!="string"&&a({code:"InvalidArgument",target:n});let r=Ht(e,n),i=this.#d();return E.of(this.context,n,this.path,()=>({op:"search",scope:{body:i},text:t,options:{...r??{},projection:this.revisionTextView()}}))}clear(){let t=this.#d();this.commandDiscarding("clear",()=>({op:"replaceSpan",span:{body:t},text:""}));}insertText(t,e){let n=`${this.path.label}.insertText`,r=k(t,n),i=fe(e,n);this.requireUsablePath();let s=b.promised(this.context,n,false);return this.commandAnswering(n,()=>i==="Replace"?{op:"replaceSpan",span:{body:this.#d()},text:r}:{op:"insertText",at:{body:this.#d(),at:i==="Start"?"start":"end"},text:r},d=>{s.hydrateAddress({kind:"span",span:P(d,n)});}),s}insertParagraph(t,e){let n=`${this.path.label}.insertParagraph`,r=k(t,n),i=be(e,n),s=this.#d(),d=w.promised(this.context,n,false);return this.commandAnswering(n,()=>({op:"insertParagraph",anchor:{body:s,at:i==="Start"?"first":"last"},where:i==="Start"?"before":"after",text:r}),h=>{h.kind!=="handle"&&a({code:"GeneralException",target:n}),d.hydrateAddress({kind:"handle",handle:h.handle});}),d}onLoad(t){let e=this.selection(t,["text","style"]);e.includes("text")&&this.loadTextInto("text",()=>({op:"getText",target:this.#d(),projection:this.revisionTextView()})),e.includes("style")&&this.#c();}#c(){let t=`${this.path.label}.style`;this.requireUsablePath(),this.read(t,()=>({op:"getStyle",span:R(this.path,"body")}),e=>{this.setLoadedProperty("style",xt(e,t));});}get fields(){return this.requireUsablePath(),this.#n??=M.of(this.context,`${this.path.label}.fields`,this.path,"body")}get inlinePictures(){return this.requireUsablePath(),this.#e??=V.of(this.context,`${this.path.label}.inlinePictures`,this.path,"body")}get tables(){return this.requireUsablePath(),this.#t??=U.over(this.context,`${this.path.label}.tables`,this.path,()=>({body:this.#d()}))}#d(){return this.requireAddressable(),this.path.handle()}};function tn(o){return o==="endnote"?"Endnote":"Footnote"}var mt=class o extends p{#t;static at(t,e,n){return n.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new o(t,c.of(e,n.handle),false)}static promised(t,e,n){return new o(t,c.pending(e),n)}constructor(t,e,n){super(t,e,{nullable:n});}hydrateAddress(t){t.kind==="handle"?this.path.resolveTo(t.handle):this.path.resolveNull();}hydrateNull(){this.path.resolveNull();}get type(){return this.loadedProperty("type")}get text(){return this.loadedProperty("text")}get body(){if(this.#t)return this.#t;let t=`${this.path.label}.body`,e=I.promisedStory(this.context,t);return this.read(t,()=>({op:"getNoteBody",note:this.#n()}),n=>{e.hydrateAddress({kind:"handle",handle:u(n,t)});}),this.#t=e,e}delete(){this.command("delete",()=>({op:"deleteNote",note:this.#n()}));}getNext(){let t=`${this.path.label}.getNext`,e=o.promised(this.context,t,false),n=this.internals.roots().document,r=`${t}.type`,i="footnote",s=c.pending(r);return this.read(r,()=>({op:"getNoteKind",note:this.#n()}),d=>{i=O(d,r)==="endnote"?"endnote":"footnote",s.resolveTo(this.#n());}),this.enqueue({sort:"read",label:t,dependencies:[s],plan:()=>({op:"getNotes",document:n,noteKind:i}),settle:d=>{let h=v(d,t),A=h.findIndex(ot=>ot.ref===this.#n().ref),K=A<0?void 0:h[A+1];K||a({code:"ItemNotFound",target:t}),e.hydrateAddress({kind:"handle",handle:K});}}),e}onLoad(t){let e=this.selection(t,["text","type"]);if(e.includes("text")&&this.loadTextInto("text",()=>({op:"getNoteText",note:this.#n(),projection:this.revisionTextView()})),e.includes("type")){let n=`${this.path.label}.type`;this.read(n,()=>({op:"getNoteKind",note:this.#n()}),r=>{this.setLoadedProperty("type",tn(O(r,n)));});}}#n(){return this.requireAddressable(),this.path.handle()}},nt=class o extends x{#t;static of(t,e,n,r){return new o(t,c.derived(e,n),r)}constructor(t,e,n){super(t,e),this.#t=n;}getFirst(){return this.edge("first","getFirst",false)}listing(){return this.#t()}itemAt(t,e){return mt.at(this.context,t,e)}promised(t,e){return mt.promised(this.context,t,e)}};var en=Object.freeze({Primary:"default",FirstPage:"first",EvenPages:"even"}),nn=["pageWidth","pageHeight","orientation","topMargin","rightMargin","bottomMargin","leftMargin"],kt=class o extends p{#t;static of(t,e,n){return new o(t,c.derived(e,n))}constructor(t,e){super(t,e);}get pageWidth(){return this.loadedProperty("pageWidth")}set pageWidth(t){this.#n("pageWidth",gt(t,`${this.path.label}.pageWidth`));}get pageHeight(){return this.loadedProperty("pageHeight")}set pageHeight(t){this.#n("pageHeight",gt(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.#n("orientation",t==="Portrait"?"portrait":"landscape");}get topMargin(){return this.loadedProperty("topMargin")}set topMargin(t){this.#n("topMargin",gt(t,`${this.path.label}.topMargin`));}get bottomMargin(){return this.loadedProperty("bottomMargin")}set bottomMargin(t){this.#n("bottomMargin",gt(t,`${this.path.label}.bottomMargin`));}get leftMargin(){return this.loadedProperty("leftMargin")}set leftMargin(t){this.#n("leftMargin",gt(t,`${this.path.label}.leftMargin`));}get rightMargin(){return this.loadedProperty("rightMargin")}set rightMargin(t){this.#n("rightMargin",gt(t,`${this.path.label}.rightMargin`));}onLoad(t){let e=this.selection(t,nn);if(e.length===0)return;let n=`${this.path.label}.pageSetup`;this.read(n,()=>({op:"getPageSetup",section:this.#e()}),r=>{let i=Ut(r,n);for(let s of e)this.setLoadedProperty(s,s==="orientation"?i.orientation==="landscape"?"Landscape":"Portrait":i[s]);});}#n(t,e){if(this.requireUsablePath(),this.#t){this.#t[t]=e;return}let n={[t]:e};this.#t=n;let r=`${this.path.label}.${t}`;this.commandAnswering(`${this.path.label}.pageSetup`,()=>({op:"setPageSetup",section:this.#e(),setup:n}),i=>{m(i,r);},()=>{this.#t===n&&(this.#t=void 0);});}#e(){this.requireAddressable();let t=this.path.address();return t.kind!=="handle"&&a({code:"InvalidObjectPath",target:this.path.label}),t.handle}},ft=class o extends p{#t;#n;static at(t,e,n){return n.kind!=="handle"&&a({code:"InvalidObjectPath",target:e}),new o(t,c.of(e,n.handle),false)}static promised(t,e,n){return new o(t,c.pending(e),n)}constructor(t,e,n){super(t,e,{nullable:n});}hydrateAddress(t){t.kind==="handle"?this.path.resolveTo(t.handle):this.path.resolveNull();}hydrateNull(){this.path.resolveNull();}get body(){return this.#n??=I.main(this.context,`${this.path.label}.body`),this.#n}get pageSetup(){return this.#t??=kt.of(this.context,`${this.path.label}.pageSetup`,this.path),this.#t}getHeader(t){return this.#e("header",t,"getHeader")}getFooter(t){return this.#e("footer",t,"getFooter")}getNext(){let t=`${this.path.label}.getNext`,e=o.promised(this.context,t,false),n=this.internals.roots().document;return this.read(t,()=>({op:"getSections",document:n}),r=>{let i=v(r,t),s=i.findIndex(h=>h.ref===this.#o().ref),d=s<0?void 0:i[s+1];d||a({code:"ItemNotFound",target:t}),e.hydrateAddress({kind:"handle",handle:d});}),e}onLoad(t){this.selection(t,[]);}#e(t,e,n){let r=`${this.path.label}.${n}`,i=en[e];i===void 0&&a({code:"InvalidArgument",target:r});let s=I.promisedStory(this.context,r);return this.read(r,()=>({op:"getFurniture",section:this.#o(),kind:t,variant:i}),d=>{s.hydrateAddress({kind:"handle",handle:u(d,r)});}),s}#o(){return this.requireAddressable(),this.path.handle()}},bt=class o extends x{#t;static of(t,e,n,r){return new o(t,c.derived(e,n),r)}constructor(t,e,n){super(t,e),this.#t=n;}getFirst(){return this.edge("first","getFirst",false)}listing(){return this.#t()}itemAt(t,e){return ft.at(this.context,t,e)}promised(t,e){return ft.promised(this.context,t,e)}};function gt(o,t){return (typeof o!="number"||!Number.isFinite(o)||o<0)&&a({code:"InvalidArgument",target:t}),o}var yt=class o extends p{#t;#n;#e;#o;#i;#s;#r;#a;static open(t){return new o(t)}constructor(t){super(t,c.of("document",J(t).roots().document));}get changeTrackingMode(){return this.loadedProperty("changeTrackingMode")}set changeTrackingMode(t){["Off","TrackAll","TrackMineOnly"].includes(t)||a({code:"InvalidArgument",target:"document.changeTrackingMode"});let e=this.internals.author;this.commandAnswering("document.changeTrackingMode",()=>({op:"setChangeTrackingMode",mode:t,...e===void 0?{}:{author:e}}),()=>this.setLoadedProperty("changeTrackingMode",t));}get body(){return this.#t??=I.main(this.context,"document.body"),this.#t}get paragraphs(){return this.#n??=this.body.paragraphsUnder("document.paragraphs"),this.#n}get sections(){let t=this.path.handle();return this.#e??=bt.of(this.context,"document.sections",this.path,()=>({op:"getSections",document:t})),this.#e}get contentControls(){return this.#s??=$.of(this.context,"document.contentControls",this.path,{body:this.internals.roots().body}),this.#s}get comments(){return this.#o??=z.of(this.context,"document.comments",this.path,()=>({op:"getComments",scope:{body:this.internals.roots().body}})),this.#o}get revisions(){return this.#i??=Q.of(this.context,"document.revisions",this.path,this.internals.roots().body),this.#i}get footnotes(){let t=this.path.handle();return this.#r??=nt.of(this.context,"document.footnotes",this.path,()=>({op:"getNotes",document:t,noteKind:"footnote"})),this.#r}get endnotes(){let t=this.path.handle();return this.#a??=nt.of(this.context,"document.endnotes",this.path,()=>({op:"getNotes",document:t,noteKind:"endnote"})),this.#a}onLoad(t){if(t.select.length===0)return;this.selection(t,["changeTrackingMode"]).includes("changeTrackingMode")&&this.loadTextInto("changeTrackingMode",()=>({op:"getChangeTrackingMode"}));}};function Ie(o){let t=o.host,e=Object.freeze({...t.capabilities,save:o.save&&t.capabilities.save}),n=typeof o.author=="string"&&o.author.trim().length>0?o.author:void 0,r=o.revisionTextView??"allMarkup";r!=="allMarkup"&&r!=="original"&&a({code:"InvalidArgument",target:"revisionTextView"});let i=false,s=null,d=g=>{i&&a({code:"RuntimeDisposed",...g===void 0?{}:{target:g}});},h=()=>{if(s)return s;d("document");let g=Re(t.execute({operations:[{op:"getDocument"}]}),"document"),Z=Re(t.execute({operations:[{op:"getBody",document:g}]}),"document.body");return s={document:g,body:Z},s},A={host:t,capabilities:e,...n===void 0?{}:{author:n},revisionTextView:r,id:{},roots:h,assertLive:d,openDocument:g=>yt.open(g)};try{h();}catch{s=null;}async function K(g,Z){d();let rt=typeof g=="function"?g:Z,Mt=typeof g=="function"?[]:Array.isArray(g)?g:[g];typeof rt!="function"&&a({code:"InvalidArgument",target:"run"});let{context:wt,adopt:y,finish:Le}=At.begin(A);try{return y(Mt),await rt(wt)}finally{Le();}}let ot={capabilities:e,run:K,dispose(){i||(i=true,s=null,t.dispose());}};return o.save?{...ot,async save(){d("save"),e.save||a({code:"NotSupported",target:"save"});let g=t.save();if(!g.ok)throw Et(g.error,{target:"save"});return g.bytes}}:ot}function Re(o,t){let e=o.results[0];if(e?.status==="error")throw Et(e.error,{target:t});if(e?.status!=="ok")throw new C({code:"GeneralException",target:t});return u(e.value,t)}function rn(o){if(o){for(let t of o)if(t.collaboration)return t.collaboration}}function an(o){let t=[o?.zip?.maxEntries,o?.zip?.maxTotalBytes,o?.xml?.maxBytes,o?.xml?.maxElements,o?.maxXmlParts,o?.maxRelationships],e=o?.zip?.maxRatio;(t.some(n=>n!==void 0&&(!Number.isInteger(n)||n<0))||e!==void 0&&(!Number.isFinite(e)||e<0))&&a({code:"InvalidArgument",target:"createServer"});}async function ae(o,t={}){an(t.limits);let e=rn(t.modules),n=createServerAutomationHost(o,{...t.pagination?{pagination:de(t.pagination)}:{},...t.limits===void 0?{}:{limits:t.limits},...e===void 0?{}:{collaborationModel:e}});if(!n.ok){let r={"too-many-entries":"zip.maxEntries","too-large":"xml.maxBytes","too-many-elements":"xml.maxElements","too-deep":"xml.maxDepth","too-many-xml-parts":"maxXmlParts","too-many-relationships":"maxRelationships"},i=n.limit??r[n.reason];a({code:i===void 0?"InvalidArgument":"ResourceLimitExceeded",target:"createServer",...i===void 0?{}:{limit:i}});}return Ie({host:n.host,save:true,...t.author===void 0?{}:{author:t.author},...t.revisionTextView===void 0?{}:{revisionTextView:t.revisionTextView}})}function ke(o,t,e={}){return ae(o,{...e,modules:[...e.modules??[],{id:"collaboration",collaboration:{session:t}}]})}var se=(l=>(l.addin="Addin",l.addressBlock="AddressBlock",l.advance="Advance",l.ask="Ask",l.author="Author",l.autoText="AutoText",l.autoTextList="AutoTextList",l.barCode="BarCode",l.bibliography="Bibliography",l.bidiOutline="BidiOutline",l.citation="Citation",l.comments="Comments",l.compare="Compare",l.createDate="CreateDate",l.data="Data",l.database="Database",l.date="Date",l.displayBarcode="DisplayBarcode",l.docProperty="DocProperty",l.docVariable="DocVariable",l.editTime="EditTime",l.embedded="Embedded",l.empty="Empty",l.eq="EQ",l.expression="Expression",l.fileName="FileName",l.fileSize="FileSize",l.fillIn="FillIn",l.formCheckbox="FormCheckbox",l.formDropdown="FormDropdown",l.formText="FormText",l.gotoButton="GotoButton",l.greetingLine="GreetingLine",l.hyperlink="Hyperlink",l.if="If",l.import="Import",l.include="Include",l.includePicture="IncludePicture",l.includeText="IncludeText",l.index="Index",l.info="Info",l.keywords="Keywords",l.lastSavedBy="LastSavedBy",l.link="Link",l.listNum="ListNum",l.macroButton="MacroButton",l.mergeBarcode="MergeBarcode",l.mergeField="MergeField",l.mergeRec="MergeRec",l.mergeSeq="MergeSeq",l.next="Next",l.nextIf="NextIf",l.noteRef="NoteRef",l.numChars="NumChars",l.numPages="NumPages",l.numWords="NumWords",l.ocx="OCX",l.others="Others",l.page="Page",l.pageRef="PageRef",l.print="Print",l.printDate="PrintDate",l.private="Private",l.quote="Quote",l.rd="RD",l.ref="Ref",l.revNum="RevNum",l.saveDate="SaveDate",l.section="Section",l.sectionPages="SectionPages",l.seq="Seq",l.set="Set",l.shape="Shape",l.skipIf="SkipIf",l.styleRef="StyleRef",l.subject="Subject",l.subscriber="Subscriber",l.symbol="Symbol",l.ta="TA",l.tc="TC",l.template="Template",l.time="Time",l.title="Title",l.toa="TOA",l.toc="TOC",l.undefined="Undefined",l.userAddress="UserAddress",l.userInitials="UserInitials",l.userName="UserName",l.xe="XE",l))(se||{});var Mi=Object.freeze({createServer:ae,createCollaborative:ke});export{Kt as Alignment,I as Body,ut as Bookmark,X as BookmarkCollection,_t as BreakType,Yt as ChangeTrackingMode,B as ClientObject,Ft as ClientResult,G as Comment,z as CommentCollection,et as CommentReply,It as CommentReplyCollection,D as ContentControl,$ as ContentControlCollection,te as ContentControlType,yt as Document,Mi as DocxEditor,C as DocxEditorError,H as Field,M as FieldCollection,se as FieldType,N as Font,F as InlinePicture,V as InlinePictureCollection,Xt as InsertLocation,j as List,ne as ListBullet,lt as ListCollection,ct as ListItem,oe as ListNumbering,mt as NoteItem,nt as NoteItemCollection,Zt as PageOrientation,kt as PageSetup,w as Paragraph,L as ParagraphCollection,b as Range,E as RangeCollection,At as RequestContext,pt as Revision,Q as RevisionCollection,ft as Section,bt as SectionCollection,W as Table,tt as TableCell,Pt as TableCellCollection,U as TableCollection,at as TableRow,st as TableRowCollection,Ct as TrackedObjects,re as UnderlineType,Jt as VerticalAlignment,Se as isDocxEditorError};
|