@folijs/pdf 0.6.0 → 1.0.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/CHANGELOG.md +96 -0
- package/README.md +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/renderer.js +7 -7
- package/package.json +5 -4
package/dist/renderer.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
var foliPdfRenderer=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=class{expr;elements;matches=new Map;constructor(e,t){this.expr=e,this.elements=t}match(e){let t=e.join(`,`),r=this.matches.get(t);return r||(r=new n(this,e),this.matches.set(t,r)),r}close(e){let t=new Set;for(let n of e)for(t.add(n);n<this.elements.length&&this.elements[n]?.optional;)t.add(++n);return[...t].sort((e,t)=>e-t)}},n=class{program;states;next=new Map;validEnd;constructor(e,t){this.program=e,this.states=t,this.validEnd=t.includes(e.elements.length)}matchType(e){let t=this.next.get(e);if(t===void 0){let n=[];for(let t of this.states){let r=this.program.elements[t];r?.types.includes(e)&&n.push(r.repeat?t:t+1)}t=n.length?this.program.match(this.program.close(n)):null,this.next.set(e,t)}return t}matchFragment(e,t=0,n=e.childCount){let r=this;for(let i=t;r&&i<n;i++)r=r.matchType(e.child(i).type);return r}get nextTypes(){let e=[];for(let t of this.states)for(let n of this.program.elements[t]?.types??[])e.includes(n)||e.push(n);return e}get defaultType(){return this.nextTypes.find(e=>!e.isText&&!e.hasRequiredAttrs()&&e.contentMatch.validEnd)??null}findWrapping(e){let t=new Set,n=[{match:this,type:null,via:null}];for(;n.length;){let r=n.shift();if(r.match.matchType(e)){let e=[];for(let t=r;t?.type;t=t.via)e.push(t.type);return e.reverse()}for(let e of r.match.nextTypes){let i=r.match.matchType(e);e.isLeaf||e.hasRequiredAttrs()||t.has(e)||r.type&&!i?.validEnd||(t.add(e),n.push({match:e.contentMatch,type:e,via:r}))}}return null}get inlineContent(){return this.program.elements[0]?.types[0]?.isInline??!1}toString(){return this.program.expr}static compile(e,n){let i=new t(e,r(e,n)),a=i.elements.flatMap(e=>e.types).map(e=>e.isInline);if(a.some(e=>e!==a[0]))throw Error(`Content expression "${e}" mixes inline and block nodes`);return i.match(i.close([0]))}};function r(e,t){let n=e.match(/\w+|[()|*+?]|\S/g)??[],r=[],i=0,a=t=>{throw Error(`Invalid content expression "${e}": ${t}`)},o=e=>{if(e===void 0||!/^\w+$/.test(e))return a(`expected a name, got ${e}`);let n=t.filter(t=>t.name===e),r=n.length?n:t.filter(t=>t.groups.includes(e));return r.length?r:a(`no node type or group "${e}"`)};for(;i<n.length;){let e;if(n[i]===`(`){for(i++,e=o(n[i++]);n[i]===`|`;)i++,e=e.concat(o(n[i++]));n[i++]!==`)`&&a(`expected ")"`)}else e=o(n[i++]);let t=n[i];(t===`*`||t===`+`||t===`?`)&&i++,t===`+`&&r.push({types:e,optional:!1,repeat:!1}),r.push({types:e,optional:t===`*`||t===`+`||t===`?`,repeat:t===`*`||t===`+`})}return r}var i=class extends Error{name=`FoliDocumentError`},a=class extends Error{name=`ReplaceError`};function o(e,t){throw new i(`${e}: ${t}`)}var s=Object.freeze({});function c(e,t,n){for(let r of Object.keys(t??s))e&&Object.hasOwn(e,r)||o(`${n}.${r}`,`unknown attribute`);if(!e)return s;let r={};for(let[i,a]of Object.entries(e)){let e=t?.[i];e===void 0&&(`default`in a||o(`${n}.${i}`,`required attribute is missing`),e=a.default);let s=a.validate?.(e);s!==void 0&&o(`${n}.${i}`,s),r[i]=e}return r}function l(e,t){if(!e)return;let n;for(let[r,i]of Object.entries(e)){let e=t[r];`default`in i&&u(e,i.default)||(n??={},n[r]=e)}return n}function u(e,t){if(e===t)return!0;if(typeof e!=`object`||typeof t!=`object`||e===null||t===null||Array.isArray(e)!==Array.isArray(t))return!1;let n=Object.keys(e);return n.length===Object.keys(t).length&&n.every(n=>Object.hasOwn(t,n)&&u(e[n],t[n]))}var d=class e{type;attrs;static none=Object.freeze([]);constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,n=!1;for(let r=0;r<e.length;r++){let i=e[r];if(this.eq(i))return e;if(this.type.excludes(i.type))t??=e.slice(0,r);else{if(i.type.excludes(this.type))return e;!n&&i.type.rank>this.type.rank&&(t??=e.slice(0,r),t.push(this),n=!0),t?.push(i)}}return t??=e.slice(),n||t.push(this),t}removeFromSet(e){return this.isInSet(e)?e.filter(e=>!e.eq(this)):e}isInSet(e){return e.some(e=>e.eq(this))}eq(e){return this===e||this.type===e.type&&u(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name},t=l(this.type.spec.attrs,this.attrs);return t&&(e.attrs=t),e}static sameSet(e,t){return e===t||e.length===t.length&&e.every((e,n)=>e.eq(t[n]))}static setFrom(t){return t?t instanceof e?[t]:t.length<2?t:[...t].sort((e,t)=>e.type.rank-t.type.rank):e.none}},f=class e{content;size;static empty=new e([],0);constructor(e,t){this.content=e,this.size=t}static fromArray(t){if(!t.length)return e.empty;let n=[],r=0;for(let e of t){r+=e.nodeSize;let t=n[n.length-1];t?.isText&&e.isText&&d.sameSet(t.marks,e.marks)?n[n.length-1]=t.withText(t.textContent+e.textContent):n.push(e)}return new e(n,r)}static from(t){return t?t instanceof e?t:e.fromArray(Array.isArray(t)?t:[t]):e.empty}get childCount(){return this.content.length}get firstChild(){return this.content[0]??null}get lastChild(){return this.content[this.content.length-1]??null}child(e){let t=this.content[e];if(!t)throw RangeError(`Index ${e} out of range for fragment of ${this.childCount}`);return t}maybeChild(e){return this.content[e]??null}forEach(e){for(let t=0,n=0;t<this.content.length;t++){let r=this.content[t];e(r,n,t),n+=r.nodeSize}}nodesBetween(e,t,n,r=0,i=null){for(let a=0,o=0;o<t&&a<this.content.length;a++){let s=this.content[a],c=o+s.nodeSize;if(c>e&&n(s,r+o,i,a)!==!1&&s.content.size){let i=o+1;s.content.nodesBetween(Math.max(0,e-i),Math.min(s.content.size,t-i),n,r+i,s)}o=c}}textBetween(e,t,n=``,r=``){let i=``,a=!0;return this.nodesBetween(e,t,(o,s)=>{o.isTextblock?(a||(i+=n),a=!1):o.isText?i+=o.textContent.slice(Math.max(e,s)-s,t-s):o.isLeaf&&(i+=typeof r==`string`?r:r(o))}),i}append(t){return t.size?this.size?e.fromArray([...this.content,...t.content]):t:this}cut(t,n=this.size){if(t<=0&&n>=this.size)return this;if(t>=n)return e.empty;let r=[],i=0;for(let e=0,a=0;a<n;e++){let o=this.content[e],s=a+o.nodeSize;s>t&&((a<t||s>n)&&(o=o.isText?o.cut(Math.max(0,t-a),Math.min(o.nodeSize,n-a)):o.cut(Math.max(0,t-a-1),Math.min(o.content.size,n-a-1))),r.push(o),i+=o.nodeSize),a=s}return new e(r,i)}cutByIndex(t,n){return t===n?e.empty:t===0&&n===this.content.length?this:e.fromArray(this.content.slice(t,n))}replaceChild(t,n){let r=this.child(t);if(r===n)return this;let i=this.content.slice();return i[t]=n,new e(i,this.size-r.nodeSize+n.nodeSize)}findIndex(e){if(e===0)return{index:0,offset:0};if(e===this.size)return{index:this.content.length,offset:e};if(e<0||e>this.size)throw RangeError(`Position ${e} outside fragment`);for(let t=0,n=0;;t++){let r=n+this.content[t].nodeSize;if(r>e)return{index:t,offset:n};n=r}}eq(e){return this===e||this.content.length===e.content.length&&this.content.every((t,n)=>t.eq(e.content[n]))}toJSON(){return this.content.map(e=>e.toJSON())}toString(){return`<${this.content.join(`, `)}>`}};function p(e,t,n){if(n.openStart>e.depth)throw new a(`Inserted content is deeper than the insertion position`);if(e.depth-n.openStart!==t.depth-n.openEnd)throw new a(`Inconsistent open depths`);return m(e,t,n,0)}function m(e,t,n,r){let i=e.index(r),a=e.node(r);if(i===t.index(r)&&r<e.depth-n.openStart){let o=m(e,t,n,r+1);return a.copy(a.content.replaceChild(i,o))}if(!n.content.size)return x(a,_(e,t,r));if(!n.openStart&&!n.openEnd&&e.depth===r&&t.depth===r){let r=a.content;return x(a,r.cut(0,e.parentOffset).append(n.content).append(r.cut(t.parentOffset)))}let{start:o,end:s}=h(n,e);return x(a,g(e,o,s,t,r))}function h(e,t){let n=t.depth-e.openStart,r=t.node(n).copy(e.content);for(let e=n-1;e>=0;e--)r=t.node(e).copy(f.from(r));return{start:r.resolve(e.openStart+n),end:r.resolve(r.content.size-e.openEnd-n)}}function g(e,t,n,r,i){let a=e.depth>i?y(e,t,i+1):null,o=r.depth>i?y(n,r,i+1):null,s=[];return v(null,e,i,s),a&&o&&t.index(i)===n.index(i)?(b(a,o),s.push(x(a,g(e,t,n,r,i+1)))):(a&&s.push(x(a,_(e,t,i+1))),v(t,n,i,s),o&&s.push(x(o,_(n,r,i+1)))),v(r,null,i,s),f.fromArray(s)}function _(e,t,n){let r=[];if(v(null,e,n,r),e.depth>n){let i=y(e,t,n+1);r.push(x(i,_(e,t,n+1)))}return v(t,null,n,r),f.fromArray(r)}function v(e,t,n,r){let i=(t??e).node(n),a=0,o=t?t.index(n):i.childCount;e&&(a=e.index(n),e.depth>n?a++:e.textOffset&&(r.push(e.nodeAfter),a++));for(let e=a;e<o;e++)r.push(i.child(e));t&&t.depth===n&&t.textOffset&&r.push(t.nodeBefore)}function y(e,t,n){let r=e.node(n);return b(r,t.node(n)),r}function b(e,t){if(!t.type.compatibleContent(e.type))throw new a(`Cannot join ${t.type.name} onto ${e.type.name}`)}function x(e,t){if(!e.type.validContent(t))throw new a(`Invalid content for node ${e.type.name}`);return e.copy(t)}var S=class e{pos;nodes;indices;starts;parentOffset;textOffset;constructor(e,t,n,r,i,a){this.pos=e,this.nodes=t,this.indices=n,this.starts=r,this.parentOffset=i,this.textOffset=a}static resolve(t,n){if(!(n>=0&&n<=t.content.size)||!Number.isInteger(n))throw RangeError(`Position ${n} out of range 0..${t.content.size}`);let r=[],i=[],a=[],o=t,s=0,c=n;for(;;){let{index:t,offset:l}=o.content.findIndex(c);r.push(o),i.push(t),a.push(s);let u=c-l,d=o.content.maybeChild(t);if(u===0||!d)return new e(n,r,i,a,c,0);if(d.isText)return new e(n,r,i,a,c,u);o=d,s+=l+1,c=u-1}}get depth(){return this.nodes.length-1}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e=this.depth){return this.nodes[this.at(e)]}index(e=this.depth){return this.indices[this.at(e)]}indexAfter(e=this.depth){let t=this.at(e);return this.index(t)+(t===this.depth&&!this.textOffset?0:1)}start(e=this.depth){return this.starts[this.at(e)]}end(e=this.depth){let t=this.at(e);return this.start(t)+this.node(t).content.size}before(e=this.depth){if(e===this.depth+1)return this.pos;let t=this.at(e);if(!t)throw RangeError(`There is no position before the root node`);return this.start(t)-1}after(e=this.depth){if(e===this.depth+1)return this.pos;let t=this.at(e);if(!t)throw RangeError(`There is no position after the root node`);return this.end(t)+1}get nodeAfter(){let e=this.parent.maybeChild(this.index());return e?this.textOffset?e.cut(this.textOffset):e:null}get nodeBefore(){let e=this.index();return this.textOffset?this.parent.child(e).cut(0,this.textOffset):this.parent.maybeChild(e-1)}posAtIndex(e,t=this.depth){let n=this.node(t),r=this.start(t);for(let t=0;t<e;t++)r+=n.child(t).nodeSize;return r}sharedDepth(e){for(let t=this.depth;t>0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos<this.pos)return e.blockRange(this,t);let n=this.depth-(this.parent.inlineContent||this.pos===e.pos?1:0);for(let r=n;r>=0;r--)if(e.pos<=this.end(r)&&(!t||t(this.node(r))))return new C(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset===e.pos-e.parentOffset}toString(){return`${this.nodes.slice(1).map((e,t)=>`${e.type.name}_${this.indices[t]}`).join(`/`)}:${this.parentOffset}`}at(e){let t=e<0?this.depth+e:e;if(t<0||t>this.depth)throw RangeError(`Depth ${e} out of range`);return t}},C=class{$from;$to;depth;constructor(e,t,n){this.$from=e,this.$to=t,this.depth=n}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}},w=class e{content;openStart;openEnd;static empty=new e(f.empty,0,0);constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(t,n){let r=ee(this.content,t+this.openStart,n,{parent:null,level:0,onStart:!0,onEnd:!0,openStart:this.openStart,openEnd:this.openEnd});return r&&new e(r,this.openStart,this.openEnd)}removeBetween(t,n){return new e(te(this.content,t+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart===e.openStart&&this.openEnd===e.openEnd}toJSON(){return{content:this.content.toJSON(),openStart:this.openStart,openEnd:this.openEnd}}};function ee(e,t,n,r){let{index:i,offset:a}=e.findIndex(t),o=e.maybeChild(i);if(a===t||!o||o.isText){let i=e.cut(0,t).append(n).append(e.cut(t)),{parent:a,level:o}=r,s=r.onStart&&o<=r.openStart||r.onEnd&&o<=r.openEnd;return a&&!s&&!a.type.validContent(i)?null:i}let s=ee(o.content,t-a-1,n,{...r,parent:o,level:r.level+1,onStart:r.onStart&&i===0,onEnd:r.onEnd&&i===e.childCount-1});return s&&e.replaceChild(i,o.copy(s))}function te(e,t,n){let{index:r,offset:i}=e.findIndex(t),a=e.maybeChild(r),{index:o,offset:s}=e.findIndex(n);if(i===t||!a||a.isText){if(s!==n&&!e.child(o).isText)throw RangeError(`Removing a non-flat range`);return e.cut(0,t).append(e.cut(n))}if(r!==o)throw RangeError(`Removing a non-flat range`);return e.replaceChild(r,a.copy(te(a.content,t-i-1,n-i-1)))}var T=class e{type;attrs;content;marks;constructor(e,t,n,r){this.type=e,this.attrs=t,this.content=n,this.marks=r}get nodeSize(){return this.type.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}get isText(){return this.type.isText}get isInline(){return this.type.isInline}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}get inlineContent(){return this.type.inlineContent}get textContent(){return this.content.textBetween(0,this.content.size)}child(e){return this.content.child(e)}maybeChild(e){return this.content.maybeChild(e)}forEach(e){this.content.forEach(e)}nodesBetween(e,t,n){this.content.nodesBetween(e,t,n,0,this)}descendants(e){this.nodesBetween(0,this.content.size,e)}textBetween(e,t,n,r){return this.content.textBetween(e,t,n,r)}sameMarkup(e){return this.type===e.type&&u(this.attrs,e.attrs)&&d.sameSet(this.marks,e.marks)}eq(e){return this===e||this.sameMarkup(e)&&this.content.eq(e.content)}copy(t=f.empty){return t===this.content?this:new e(this.type,this.attrs,t,this.marks)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw RangeError(`Invalid content in ${this.type.name}`);return t}canReplace(e,t,n=f.empty,r=0,i=n.childCount){if(!this.contentMatchAt(e).matchFragment(n,r,i)?.matchFragment(this.content,t)?.validEnd)return!1;for(let e=r;e<i;e++)if(!this.type.allowsMarks(n.child(e).marks))return!1;return!0}canReplaceWith(e,t,n){return!!this.contentMatchAt(e).matchType(n)?.matchFragment(this.content,t)?.validEnd}mark(t){return d.sameSet(t,this.marks)?this:new e(this.type,this.attrs,this.content,t)}cut(e,t=this.content.size){return e===0&&t===this.content.size?this:this.copy(this.content.cut(e,t))}slice(e,t=this.content.size){if(e>t)throw RangeError(`Invalid range ${e}..${t}`);if(e===t)return w.empty;let n=this.resolve(e),r=this.resolve(t),i=n.sharedDepth(t),a=n.start(i);return new w(n.node(i).content.cut(n.pos-a,r.pos-a),n.depth-i,r.depth-i)}replace(e,t,n){if(e>t)throw RangeError(`Invalid range ${e}..${t}`);return p(this.resolve(e),this.resolve(t),n)}nodeAt(e){let t=this;for(;;){let{index:n,offset:r}=t.content.findIndex(e),i=t.content.maybeChild(n);if(!i)return null;if(r===e||i.isText)return i;t=i,e-=r+1}}resolve(e){return S.resolve(this,e)}check(){if(!this.type.validContent(this.content))throw new i(`Invalid content for node ${this.type.name}: ${this.content}`);this.content.forEach(e=>{e.check()})}toJSON(){let e={type:this.type.name},t=l(this.type.spec.attrs,this.attrs);return t&&(e.attrs=t),this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(e=>e.toJSON())),e}toString(){return this.content.size?`${this.type.name}(${this.content.content.join(`, `)})`:this.type.name}},E=class e extends T{text;constructor(e,t,n){if(super(e,s,f.empty,n),this.text=t,!t)throw RangeError(`Empty text nodes are not allowed`)}get nodeSize(){return this.text.length}get textContent(){return this.text}eq(e){return this===e||this.sameMarkup(e)&&this.text===e.text}mark(t){return d.sameSet(t,this.marks)?this:new e(this.type,this.text,t)}cut(e=0,t=this.text.length){return e===0&&t===this.text.length?this:this.withText(this.text.slice(e,t))}withText(t){return t===this.text?this:new e(this.type,t,this.marks)}toJSON(){let e={type:this.type.name,text:this.text};return this.marks.length&&(e.marks=this.marks.map(e=>e.toJSON())),e}toString(){let e=JSON.stringify(this.text);return this.marks.length?`${this.marks.map(e=>e.type.name).join(`+`)}${e}`:e}},D=[`type`,`attrs`,`content`,`text`,`marks`],O=[`type`,`attrs`],k=[`content`,`openStart`,`openEnd`],ne=class{name;schema;spec;groups;isText;isInline;isBlock;isLeaf;contentMatch;markSet;constructor(e,t,n){this.name=e,this.schema=t,this.spec=n,this.groups=n.group?n.group.split(` `):[],this.isText=e===`text`,this.isInline=this.isText||!!n.inline,this.isBlock=!this.isInline,this.isLeaf=!n.content}get inlineContent(){return this.contentMatch.inlineContent}get isTextblock(){return this.isBlock&&this.inlineContent}get isAtom(){return this.isLeaf||!!this.spec.atom}hasRequiredAttrs(){return Object.values(this.spec.attrs??{}).some(e=>!(`default`in e))}create(e,t,n){if(this.isText)throw RangeError(`Use Schema.text to create text nodes`);let r=f.from(t);return this.validContent(r)||o(this.name,`invalid content ${r}`),new T(this,c(this.spec.attrs,e??void 0,`${this.name}.attrs`),r,d.setFrom(n))}createOpen(e,t){if(this.isText)throw RangeError(`Use Schema.text to create text nodes`);return new T(this,c(this.spec.attrs,e??void 0,`${this.name}.attrs`),f.from(t),d.none)}validContent(e){return this.contentMatch.matchFragment(e)?.validEnd?e.content.every(e=>this.allowsMarks(e.marks)):!1}allowsMarkType(e){return this.markSet===null||this.markSet.includes(e)}allowsMarks(e){return this.markSet===null||e.every(e=>this.allowsMarkType(e.type))}compatibleContent(e){return this===e||!this.isLeaf&&!e.isLeaf&&this.inlineContent===e.inlineContent}checkContent(e,t){let n=this.contentMatch;e.forEach((e,r)=>{let i=n.matchType(e.type);i||o(`${t}.content[${r}]`,`${e.type.name} is not allowed here in ${this.name}`),this.allowsMarks(e.marks)||o(`${t}.content[${r}].marks`,`marks not allowed in ${this.name}`),n=i}),n.validEnd||o(`${t}.content`,`${this.name} content is incomplete (expected "${n}")`)}},re=class{name;schema;spec;rank;excluded;groups;instance;constructor(e,t,n,r){this.name=e,this.schema=t,this.spec=n,this.rank=r,this.groups=n.group?n.group.split(` `):[],this.instance=n.attrs?null:new d(this,s)}create(e){return this.instance&&!(e&&Object.keys(e).length)?this.instance:new d(this,c(this.spec.attrs,e??void 0,`${this.name}.attrs`))}get inclusive(){return this.spec.inclusive??!0}excludes(e){return this.excluded.includes(e)}isInSet(e){return e.find(e=>e.type===this)}removeFromSet(e){return this.isInSet(e)?e.filter(e=>e.type!==this):e}},ie=class{spec;nodes;marks;topNodeType;constructor(e){this.spec=e;let t=Object.create(null),r=Object.create(null);for(let[n,r]of Object.entries(e.nodes))t[n]=new ne(n,this,r);Object.entries(e.marks??{}).forEach(([e,t],n)=>{r[e]=new re(e,this,t,n)}),this.nodes=t,this.marks=r;let i=t.text;if(!i||i.spec.attrs||i.spec.content)throw Error("A schema needs a `text` node type without attrs or content");let a=t[e.topNode??`doc`];if(!a)throw Error(`Schema has no top node type "${e.topNode??`doc`}"`);this.topNodeType=a;let o=Object.values(t),s=Object.values(r);for(let e of o){e.contentMatch=n.compile(e.spec.content??``,o);let t=e.spec.marks??(e.inlineContent?`_`:``);e.markSet=t===`_`?null:A(s,t)}for(let e of s){let t=e.spec.excludes??e.name;e.excluded=t===`_`?s:A(s,t)}}nodeType(e){return this.nodes[e]}markType(e){return this.marks[e]}node(e,t,n,r){return this.resolveNodeType(e).create(t,n,r)}text(e,t){return new E(this.resolveNodeType(`text`),e,d.setFrom(t))}mark(e,t){if(typeof e!=`string`)return e.create(t);let n=this.marks[e];if(!n)throw RangeError(`Unknown mark type "${e}"`);return n.create(t)}nodeFromJSON(e,t=`$`){return this.parseNode(e,t,0,0)}markFromJSON(e,t=`$`){let n=j(e,t,O),r=typeof n.type==`string`?this.marks[n.type]:void 0;if(!r)return o(`${t}.type`,`unknown mark type ${JSON.stringify(n.type)}`);if(!r.spec.attrs)return n.attrs!==void 0&&o(`${t}.attrs`,`${r.name} has no attributes`),r.create();let i=n.attrs===void 0?void 0:j(n.attrs,`${t}.attrs`);return new d(r,c(r.spec.attrs,i,`${t}.attrs`))}sliceFromJSON(e,t=`$`){let n=j(e,t,k),r=ae(n.content,`${t}.content`),{openStart:i,openEnd:a}=n;oe(i)||o(`${t}.openStart`,`expected a non-negative integer`),oe(a)||o(`${t}.openEnd`,`expected a non-negative integer`),!r.length&&(i||a)&&o(t,`an empty slice cannot be open`);let s=r.map((e,n)=>this.parseNode(e,`${t}.content[${n}]`,n===0?i:0,n===r.length-1?a:0));return new w(f.fromArray(s),i,a)}parseNode(e,t,n,r,i=0){i>300&&o(t,`nodes nested deeper than 300 levels`);let a=j(e,t,D),s=typeof a.type==`string`?this.nodes[a.type]:void 0;if(!s)return o(`${t}.type`,`unknown node type ${JSON.stringify(a.type)}`);let l=a.marks===void 0?d.none:this.marksFromJSON(a.marks,`${t}.marks`);if((n||r)&&s.isLeaf&&o(t,`a leaf node cannot be open`),s.isText)return a.attrs!==void 0&&o(`${t}.attrs`,`text nodes have no attributes`),a.content!==void 0&&o(`${t}.content`,`text nodes have no content`),typeof a.text==`string`&&a.text||o(`${t}.text`,`text must be a non-empty string`),new E(s,a.text,l);a.text!==void 0&&o(`${t}.text`,`only text nodes have text`),a.attrs!==void 0&&!s.spec.attrs&&o(`${t}.attrs`,`${s.name} has no attributes`);let u=c(s.spec.attrs,a.attrs===void 0?void 0:j(a.attrs,`${t}.attrs`),`${t}.attrs`),p=[];if(a.content!==void 0){s.isLeaf&&o(`${t}.content`,`${s.name} cannot have content`);let e=ae(a.content,`${t}.content`);p=e.map((a,o)=>this.parseNode(a,`${t}.content[${o}]`,o===0?Math.max(n-1,0):0,o===e.length-1?Math.max(r-1,0):0,i+1))}return n||r?!p.length&&(n>1||r>1)&&o(`${t}.content`,`open depth exceeds the content`):s.checkContent(p,t),new T(s,u,f.fromArray(p),l)}marksFromJSON(e,t){let n=d.none;return ae(e,t).forEach((e,r)=>{let i=this.markFromJSON(e,`${t}[${r}]`),a=n.find(e=>e.type.excludes(i.type)||i.type.excludes(e.type));a&&o(`${t}[${r}]`,a.type===i.type?`duplicate mark`:`${i.type.name} cannot be combined with ${a.type.name}`),n=i.addToSet(n)}),n}resolveNodeType(e){if(typeof e!=`string`)return e;let t=this.nodes[e];if(!t)throw RangeError(`Unknown node type "${e}"`);return t}};function A(e,t){let n=[];for(let r of t.split(` `).filter(Boolean)){let t=e.filter(e=>e.name===r||e.groups.includes(r));if(!t.length)throw Error(`Unknown mark type or group "${r}"`);for(let e of t)n.includes(e)||n.push(e)}return n}function j(e,t,n){if((typeof e!=`object`||!e||Array.isArray(e))&&o(t,`expected an object`),n)for(let r of Object.keys(e))n.includes(r)||o(`${t}.${r}`,`unknown key`);return e}function ae(e,t){return Array.isArray(e)||o(t,`expected an array`),e}function oe(e){return typeof e==`number`&&Number.isInteger(e)&&e>=0}var M=[1,2,3,4,5,6],se=[`start`,`center`,`end`,`justify`],ce=[`http:`,`https:`,`mailto:`,`tel:`];function le(e){if(typeof e!=`string`||!e||e.length>8192||/[\u0000- \u007f-\u009f\\]/.test(e))return!1;let t=/^([a-zA-Z][a-zA-Z0-9+.-]*):/.exec(e);return!t||ce.includes(`${t[1]?.toLowerCase()}:`)}function ue(e){return e?.href===null||e?.href===void 0?typeof e?.anchor==`string`:le(e.href)}function N(e){return typeof e==`string`&&/^#[0-9a-f]{6}$/.test(e)}var de={default:`start`,validate:e=>se.includes(e)?void 0:`align must be one of ${se.join(`, `)}`},fe={validate:e=>N(e)?void 0:`color must be a lowercase #rrggbb value`},pe=new ie({nodes:{doc:{content:`block+`},paragraph:{group:`block`,content:`inline*`,attrs:{align:de}},heading:{group:`block`,content:`inline*`,attrs:{level:{validate:e=>M.includes(e)?void 0:`heading level must be an integer from 1 to 6`},align:de}},bulletList:{group:`block`,content:`listItem+`},orderedList:{group:`block`,content:`listItem+`,attrs:{start:{default:1,validate:e=>Number.isInteger(e)&&e>=0&&e<=99999?void 0:`start must be an integer from 0 to 99999`}}},listItem:{content:`paragraph block*`},horizontalRule:{group:`block`},text:{group:`inline`},hardBreak:{group:`inline`,inline:!0,selectable:!1},pageBreak:{group:`inline`,inline:!0,selectable:!1}},marks:{link:{attrs:{href:{validate:e=>le(e)?void 0:`href must be a relative URL or use http, https, mailto or tel`}},inclusive:!1},bold:{},italic:{},underline:{},strike:{},textColor:{attrs:{color:fe}},highlight:{attrs:{color:fe}}}}),me=2,he={1:e=>({...e,schemaVersion:2})},ge={pageSize:{A4:{width:210,height:297},Letter:{width:215.9,height:279.4}}.A4,margins:{top:25.4,right:25.4,bottom:25.4,left:25.4}};function _e(e){if(!be(e))throw new i(`Document must be an object`);let t=e.schemaVersion;if(!Number.isInteger(t)||t<1)throw new i(`Unsupported schemaVersion: ${String(t)}`);if(t>me)throw new i(`Unsupported schemaVersion: ${t} (this version of @folijs/core reads 1 to ${me}; the document was saved by a newer one)`);let n=e;for(let e=t;e<me;e++){let t=he[e];if(!t)throw new i(`No migration from schemaVersion ${e}`);n=t(n)}return{schemaVersion:me,settings:ye(n.settings),content:ve(n.content).toJSON()}}function ve(e,t=`content`){let n=pe.nodeFromJSON(e,t);if(n.type!==pe.topNodeType)throw new i(`${t}: root node must be of type "doc"`);if(n.marks.length)throw new i(`${t}.marks: doc cannot have marks`);return n}function ye(e){if(!be(e)||!be(e.pageSize)||!be(e.margins))throw new i(`settings.pageSize and settings.margins are required`);let{width:t,height:n}=e.pageSize,{top:r,right:a,bottom:o,left:s}=e.margins;if(!xe(t)||!xe(n))throw new i(`pageSize width/height must be positive numbers (mm)`);if(![r,a,o,s].every(Se))throw new i(`margins must be non-negative numbers (mm)`);let c={top:r,right:a,bottom:o,left:s};if(c.left+c.right>=t||c.top+c.bottom>=n)throw new i(`margins leave no content area on the page`);return{pageSize:{width:t,height:n},margins:c}}function be(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function xe(e){return typeof e==`number`&&Number.isFinite(e)&&e>0}function Se(e){return typeof e==`number`&&Number.isFinite(e)&&e>=0}var Ce=65536,we=(e,t)=>e+t*Ce,Te=e=>e%Ce,Ee=e=>(e-Te(e))/Ce,De=class e{ranges;inverted;static empty=new e([]);constructor(e,t=!1){this.ranges=e,this.inverted=t}mapResult(e,t=1,n){let r=0,i=this.inverted?2:1,a=this.inverted?1:2;for(let o=0;o<this.ranges.length;o+=3){let s=this.ranges[o]-(this.inverted?r:0);if(s>e)break;let c=this.ranges[o+i],l=this.ranges[o+a],u=s+c;if(e<=u){let i=c?e===s?-1:e===u?1:t:n?.[o/3]||t,a=e!==(t<0?s:u);return{pos:s+r+(i<0?0:l),deleted:e>s&&e<u,recover:a?we(o/3,e-s):null}}r+=l-c}return{pos:e+r,deleted:!1,recover:null}}map(e,t=1){return this.mapResult(e,t).pos}recover(e){let t=0,n=Te(e);if(!this.inverted)for(let e=0;e<n;e++)t+=this.ranges[e*3+2]-this.ranges[e*3+1];return this.ranges[n*3]+t+Ee(e)}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let r=0,i=0;r<this.ranges.length;r+=3){let a=this.ranges[r],o=a-(this.inverted?i:0),s=a+(this.inverted?0:i),c=this.ranges[r+t],l=this.ranges[r+n];e(o,o+c,s,s+l),i+=l-c}}sides(e){let t=[];return this.forEach((n,r)=>{t.push(e<=n?-1:+(e>=r))}),t}invert(){return new e(this.ranges,!this.inverted)}},Oe=class e{maps;mirror;from;to;constructor(e=[],t=new Map,n=0,r=e.length){this.maps=e,this.mirror=t,this.from=n,this.to=r}slice(t=0,n=this.maps.length){return new e(this.maps,this.mirror,t,n)}appendMap(e,t){this.to=this.maps.push(e),t!==void 0&&(this.mirror.set(this.maps.length-1,t),this.mirror.set(t,this.maps.length-1))}appendMapping(e){let t=this.maps.length;for(let n=e.from;n<e.to;n++){let r=e.getMirror(n);this.appendMap(e.maps[n],r!==void 0&&r<n&&r>=e.from?t+r-e.from:void 0)}}getMirror(e){return this.mirror.get(e)}map(e,t=1){return this.mapResult(e,t).pos}mapResult(e,t=1){let n=!1;for(let r=this.from;r<this.to;r++){let i=this.maps[r].mapResult(e,t);if(i.recover!==null){let t=this.getMirror(r);if(t!==void 0&&t>r&&t<this.to){r=t,e=this.maps[t].recover(i.recover);continue}}n||=i.deleted,e=i.pos}return{pos:e,deleted:n,recover:null}}},P=class e{doc;failed;constructor(e,t){this.doc=e,this.failed=t}static ok(t){return new e(t,null)}static fail(t){return new e(null,t)}static fromReplace(t,n,r,i){try{return e.ok(t.replace(n,r,i))}catch(t){if(t instanceof a||t instanceof RangeError)return e.fail(t.message);throw t}}},ke=class{getMap(){return De.empty}},Ae=class e extends ke{from;to;slice;structure;constructor(e,t,n,r=!1){super(),this.from=e,this.to=t,this.slice=n,this.structure=r}apply(e){return this.structure&&Me(e,this.from,this.to)?P.fail(`Structure replace would overwrite content`):P.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new De([this.from,this.to-this.from,this.slice.size])}invert(t){return new e(this.from,this.from+this.slice.size,t.slice(this.from,this.to))}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted?null:new e(n.pos,Math.max(n.pos,r.pos),this.slice,this.structure)}merge(t){if(!(t instanceof e)||t.structure||this.structure)return null;let n=(e,t)=>e.size+t.size===0?w.empty:new w(e.content.append(t.content),e.openStart,t.openEnd);return this.from+this.slice.size===t.from&&!this.slice.openEnd&&!t.slice.openStart?new e(this.from,this.to+(t.to-t.from),n(this.slice,t.slice)):t.to===this.from&&!this.slice.openStart&&!t.slice.openEnd?new e(t.from,this.to,n(t.slice,this.slice)):null}},je=class e extends ke{from;to;gapFrom;gapTo;slice;insert;structure;constructor(e,t,n,r,i,a,o=!1){super(),this.from=e,this.to=t,this.gapFrom=n,this.gapTo=r,this.slice=i,this.insert=a,this.structure=o}apply(e){if(this.from<0||this.from>this.gapFrom||this.gapFrom>this.gapTo||this.gapTo>this.to||this.to>e.content.size)return P.fail(`Invalid gap range ${this.from}..${this.to}`);if(this.structure&&(Me(e,this.from,this.gapFrom)||Me(e,this.gapTo,this.to)))return P.fail(`Structure gap-replace would overwrite content`);let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return P.fail(`Gap is not a flat range`);let n;try{n=this.slice.insertAt(this.insert,t.content)}catch(e){if(e instanceof RangeError)return P.fail(e.message);throw e}return n?P.fromReplace(e,this.from,this.to,n):P.fail(`Content does not fit in gap`)}getMap(){return new De([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(t){let n=this.gapTo-this.gapFrom;return new e(this.from,this.from+this.slice.size+n,this.from+this.insert,this.from+this.insert+n,t.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1),i=this.from===this.gapFrom?n.pos:t.map(this.gapFrom,-1),a=this.to===this.gapTo?r.pos:t.map(this.gapTo,1);return n.deleted&&r.deleted||i<n.pos||a>r.pos||this.gapTo>this.gapFrom&&a<=i?null:new e(n.pos,r.pos,i,a,this.slice,this.insert,this.structure)}};function Me(e,t,n){let r=e.resolve(t),i=n-t,a=r.depth;for(;i>0&&a>0&&r.indexAfter(a)===r.node(a).childCount;)a--,i--;if(i>0){let e=r.node(a).maybeChild(r.indexAfter(a));for(;i>0;){if(!e||e.isLeaf)return!0;e=e.firstChild,i--}}return!1}function Ne(e,t,n){let r=[];return e.forEach(e=>{let i=e.content.size?e.copy(Ne(e.content,t,e)):e;i.isInline&&(i=t(i,n)),r.push(i)}),f.fromArray(r)}var Pe=class extends ke{from;to;mark;constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){if(this.from>=this.to||this.from<0||this.to>e.content.size)return P.fail(`Invalid mark range ${this.from}..${this.to}`);let t=e.slice(this.from,this.to),n=e.resolve(this.from),r=n.node(n.sharedDepth(this.to)),i=Ne(t.content,(e,t)=>t.type.allowsMarkType(this.mark.type)?e.mark(this.change(e.marks)):e,r);return P.fromReplace(e,this.from,this.to,new w(i,t.openStart,t.openEnd))}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deleted&&n.deleted||t.pos>=n.pos?null:this.create(t.pos,n.pos)}},Fe=class e extends Pe{change(e){return this.mark.addToSet(e)}create(t,n){return new e(t,n,this.mark)}invert(){return new Ie(this.from,this.to,this.mark)}},Ie=class e extends Pe{change(e){return this.mark.removeFromSet(e)}create(t,n){return new e(t,n,this.mark)}invert(){return new Fe(this.from,this.to,this.mark)}},Le=class e extends ke{pos;type;attrs;marks;constructor(e,t,n,r){super(),this.pos=e,this.type=t,this.attrs=n,this.marks=r}apply(e){let t=this.pos>=0&&this.pos<e.content.size?e.nodeAt(this.pos):null;if(!t||t.isText)return P.fail(`No node at position ${this.pos}`);let n;try{n=this.type.create(this.attrs,t.content,this.marks??t.marks)}catch(e){if(e instanceof i)return P.fail(e.message);throw e}return P.fromReplace(e,this.pos,this.pos+t.nodeSize,new w(f.from(n),0,0))}invert(t){let n=t.nodeAt(this.pos);if(!n)throw RangeError(`No node at position ${this.pos}`);return new e(this.pos,n.type,n.attrs,n.marks)}map(t){let n=t.mapResult(this.pos,1),r=t.mapResult(this.pos+1,-1);return n.deleted||r.deleted||r.pos<=n.pos?null:new e(n.pos,this.type,this.attrs,this.marks)}};function Re(e,t,n){let r=[],i=0;if(e.forEach((e,a)=>{let o=t+a,s=i;for(;i<n.length&&n[i].pos<o+e.nodeSize;)i++;if(s===i){r.push(e);return}let c=n[s].pos===o?n[s]:void 0,l=n.slice(c?s+1:s,i),u=l.length?Re(e,o+1,l):e;if(c){if(u.isText)throw RangeError(`No node at position ${o}`);if(u=c.type.create(c.attrs,u.content,c.marks??u.marks),u.nodeSize!==e.nodeSize)throw RangeError(`Node markup must keep the node size`)}r.push(u)}),i<n.length)throw RangeError(`No node at position ${n[i]?.pos}`);let a=f.fromArray(r);if(!e.type.validContent(a))throw RangeError(`Invalid content for node ${e.type.name}`);return e.copy(a)}var ze=class e extends ke{steps;constructor(e){super(),this.steps=e}apply(e){for(let e=0;e<this.steps.length;e++){let t=this.steps[e].pos;if(t<0||e>0&&t<=this.steps[e-1].pos)return P.fail(`Unsorted or invalid node markup position ${t}`)}try{return P.ok(Re(e,0,this.steps))}catch(e){if(e instanceof i||e instanceof RangeError)return P.fail(e.message);throw e}}invert(t){let n=[],r=this.steps[this.steps.length-1];if(r&&t.nodesBetween(this.steps[0].pos,r.pos+1,(e,t)=>{this.steps[n.length]?.pos===t&&n.push(new Le(t,e.type,e.attrs,e.marks));let r=this.steps[n.length];return r!==void 0&&r.pos<t+e.nodeSize}),n.length!==this.steps.length)throw RangeError(`Node markup batch does not fit`);return new e(n)}map(t){let n=this.steps.map(e=>e.map(t)).filter(e=>e!==null);return n.length?new e(n):null}};function Be(e,t,n){let r={},a=e.type.spec.attrs??{};for(let i of Object.keys(t.spec.attrs??{}))n&&Object.hasOwn(n,i)?r[i]=n[i]:Object.hasOwn(a,i)&&(r[i]=e.attrs[i]);for(let e of Object.keys(n??{}))Object.hasOwn(r,e)||(r[e]=n?.[e]);try{return t.createOpen(r).attrs}catch(e){throw e instanceof i?new F(e.message):e}}var F=class extends Error{name=`TransformError`},Ve=class{current;steps=[];docs=[];mapping=new Oe;constructor(e){this.current=e}get doc(){return this.current}get before(){return this.docs[0]??this.doc}get docChanged(){return this.steps.length>0}step(e){let t=this.maybeStep(e);if(t.failed!==null)throw new F(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.doc&&this.addStep(e,t.doc),t}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.current=t}replace(e,t=e,n=w.empty){return e===t&&!n.size?this:this.step(new Ae(e,t,n))}delete(e,t){return this.replace(e,t)}insert(e,t){return this.replace(e,e,new w(f.from(t),0,0))}insertText(e,t,n=t,r){if(!e)return this.delete(t,n);let i=this.doc.type.schema.text(e,r);return this.replace(t,n,new w(f.from(i),0,0))}addMark(e,t,n){let r=[],i=[];this.doc.nodesBetween(e,t,(a,o,s)=>{if(!a.isInline||!s||!s.type.allowsMarkType(n.type))return;let c=n.addToSet(a.marks);if(c===a.marks)return;let l=Math.max(o,e),u=Math.min(o+a.nodeSize,t);for(let e of a.marks){if(e.isInSet(c))continue;let t=r[r.length-1];t&&t.to===l&&t.mark.eq(e)?t.to=u:r.push({from:l,to:u,mark:e})}let d=i[i.length-1];d&&d.to===l?d.to=u:i.push({from:l,to:u})});for(let e of r)this.step(new Ie(e.from,e.to,e.mark));for(let e of i)this.step(new Fe(e.from,e.to,n));return this}removeMark(e,t,n){let r=[],i=0;this.doc.nodesBetween(e,t,(a,o)=>{if(!a.isInline)return;i++;let s=n instanceof re?a.marks.filter(e=>e.type===n):n.isInSet(a.marks)?[n]:[],c=Math.min(o+a.nodeSize,t);for(let t of s){let n=r.find(e=>e.index===i-1&&e.mark.eq(t));n?(n.to=c,n.index=i):r.push({from:Math.max(o,e),to:c,mark:t,index:i})}});for(let e of r)this.step(new Ie(e.from,e.to,e.mark));return this}split(e,t=1,n){let r=this.doc.resolve(e);if(t<1||t>r.depth)throw new F(`Cannot split ${t} levels at ${e}`);let a=f.empty,o=f.empty;for(let e=r.depth,s=t-1;e>r.depth-t;e--,s--){a=f.from(r.node(e).copy(a));let t=n?.[s],c;try{c=t?t.type.createOpen(t.attrs,o):r.node(e).copy(o)}catch(e){throw e instanceof i?new F(e.message):e}o=f.from(c)}return this.step(new Ae(e,e,new w(a.append(o),t,t),!0))}join(e,t=1){let n=e>0&&e<this.doc.content.size?this.doc.resolve(e):null,r=n?.nodeBefore,i=n?.nodeAfter;if(!r||!i||r.isLeaf||i.isLeaf||n?.textOffset)throw new F(`Position ${e} is not between two joinable nodes`);return this.step(new Ae(e-t,e+t,w.empty,!0))}wrap(e,t){let n=f.empty;for(let e=t.length-1;e>=0;e--){let r=t[e];if(n.size&&!r.type.contentMatch.matchFragment(n)?.validEnd)throw new F(`${r.type.name} cannot hold the next wrapper`);n=f.from(r.type.createOpen(r.attrs,n))}let{start:r,end:i}=e;return this.step(new je(r,i,r,i,new w(n,0,0),t.length,!0))}lift(e,t){let{$from:n,$to:r,depth:i}=e,a=n.before(i+1),o=r.after(i+1),s=a,c=o,l=f.empty,u=0;for(let e=i,r=!1;e>t;e--)r||n.index(e)>0?(r=!0,l=f.from(n.node(e).copy(l)),u++):s--;let d=f.empty,p=0;for(let e=i,n=!1;e>t;e--)n||r.after(e+1)<r.end(e)?(n=!0,d=f.from(r.node(e).copy(d)),p++):c++;return this.step(new je(s,c,a,o,new w(l.append(d),u,p),l.size-u,!0))}setBlockType(e,t,n,r=null){let i=[];return this.doc.nodesBetween(e,t,(e,t)=>{if(!e.isTextblock)return;let a=Be(e,n,r);return e.type===n&&u(e.attrs,a)||i.push(new Le(t,n,a)),!1}),i.length?this.step(new ze(i)):this}setBlockAttrs(e,t,n){let r=[];return this.doc.nodesBetween(e,t,(e,t)=>{if(!e.isTextblock)return;let i=e.type.spec.attrs??{},a=Object.fromEntries(Object.entries(n).filter(([e])=>e in i));if(!Object.keys(a).length)return!1;let o={...e.attrs,...a};return u(e.attrs,o)||r.push(new Le(t,e.type,o)),!1}),r.length?this.step(new ze(r)):this}setNodeMarkup(e,t,n=null,r){return this.step(new Le(e,t,n,r))}};function I(e,t,n){let r=e.tr;try{n(r)}catch(e){if(e instanceof F)return!1;throw e}return!r.docChanged&&r.selection.eq(e.selection)&&r.storedMarks===e.storedMarks?!1:(t?.(r),!0)}var L=class e{$anchor;$head;constructor(e,t){this.$anchor=e,this.$head=t}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get $from(){return this.anchor<=this.head?this.$anchor:this.$head}get $to(){return this.anchor<=this.head?this.$head:this.$anchor}get from(){return this.$from.pos}get to(){return this.$to.pos}get empty(){return this.from===this.to}get ranges(){return[{from:this.from,to:this.to}]}eq(e){return e.constructor===this.constructor&&e.anchor===this.anchor&&e.head===this.head}static near(e,t=1){if(e.parent.inlineContent)return new R(e,e);let n=e.doc,r=He(n,e.pos,t)??He(n,e.pos,-t);return r===null?new Ge(n):R.create(n,r)}static atStart(t){return e.near(t.resolve(0),1)}static atEnd(t){return e.near(t.resolve(t.content.size),-1)}static kinds=new Map;static fromJSON(t,n){if(n.type===`all`)return new Ge(t);let r=e.kinds.get(n.type);if(r)return r(t,n);let i=e=>Math.max(0,Math.min(e,t.content.size));if(n.type===`node`){let r=t.resolve(i(n.anchor)),a=r.nodeAfter;return a&&!r.textOffset&&We.isSelectable(a)?new We(r):e.near(r)}return R.between(t.resolve(i(n.anchor)),t.resolve(i(n.head)))}};function He(e,t,n){let r=null;return e.descendants((e,i)=>{if(!e.isTextblock)return!0;let a=i+1,o=a+e.content.size;return n>0&&a>=t&&r===null&&(r=a),n<0&&o<=t&&(r=o),!1}),r}function Ue(e){if(!e.textOffset)return e;let t=e.parent.child(e.index()).text??``,n=t.charCodeAt(e.textOffset-1),r=t.charCodeAt(e.textOffset);return n>=55296&&n<=56319&&r>=56320&&r<=57343?e.doc.resolve(e.pos-1):e}var R=class e extends L{static create(t,n,r=n){return e.between(t.resolve(n),t.resolve(r))}static between(t,n){let r=n.pos>=t.pos?1:-1,i=n.parent.inlineContent?n:L.near(n,r).$head,a=t.parent.inlineContent?t:L.near(t,-r).$head;return!i.parent.inlineContent||!a.parent.inlineContent?L.near(n,r):new e(Ue(a),Ue(i))}map(t,n){let r=t.resolve(n.map(this.head));if(!r.parent.inlineContent)return L.near(r);let i=t.resolve(n.map(this.anchor));return new e(i.parent.inlineContent?i:r,r)}toJSON(){return{type:`text`,anchor:this.anchor,head:this.head}}},We=class e extends L{node;constructor(t){let n=t.nodeAfter;if(!n||t.textOffset||!e.isSelectable(n))throw RangeError(`No selectable node at position ${t.pos}`);super(t,t.doc.resolve(t.pos+n.nodeSize)),this.node=n}static create(t,n){return new e(t.resolve(n))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}map(t,n){let r=n.mapResult(this.anchor,1),i=n.mapResult(this.head,-1),a=t.resolve(r.pos),o=a.nodeAfter;return r.deleted||i.deleted||!o||a.textOffset||r.pos+o.nodeSize!==i.pos?L.near(a):e.isSelectable(o)?new e(a):L.near(a)}toJSON(){return{type:`node`,anchor:this.anchor,head:this.head}}},Ge=class e extends L{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}map(t){return new e(t)}toJSON(){return{type:`all`,anchor:this.anchor,head:this.head}}};function Ke(e){if(!e.parent.inlineContent)return d.none;if(e.textOffset)return e.parent.child(e.index()).marks;let t=e.nodeBefore,n=e.nodeAfter,r=t??n,i=t?n:null,a=r?.marks??d.none;for(let e of a)!e.type.inclusive&&!(i&&e.isInSet(i.marks))&&(a=e.removeFromSet(a));return a}var qe=[`section`,`revision`,`formatChange`,`attributes`],Je=new Set([`bookmarkStart`,`bookmarkEnd`,`commentStart`,`commentEnd`,`controlStart`,`controlEnd`]);function Ye(e,t,n,r=0){let i=e.doc.nodeAt(t);if(!i?.isTextblock||!Object.hasOwn(i.attrs,`revision`))return;let a=!1;if(i.content.cut(0,i.content.size-(n.content.size-r)).forEach(e=>{Je.has(e.type.name)||(a=!0)}),!a){(i.type!==n.type||JSON.stringify(i.attrs)!==JSON.stringify(n.attrs))&&e.setNodeMarkup(t,n.type,n.attrs);return}let o={...i.attrs},s=!1;for(let e of qe){let t=n.attrs[e]??null;JSON.stringify(o[e]??null)!==JSON.stringify(t)&&(o[e]=t,s=!0)}s&&e.setNodeMarkup(t,i.type,o)}var Xe=new Set([`insertion`,`deletion`,`formatChange`]);function Ze(e){return e.some(e=>Xe.has(e.type.name))?e.filter(e=>!Xe.has(e.type.name)):e}var Qe=class{name;constructor(e){this.name=e}getState(e){return e.pluginState(this)}},$e=class{spec;key;constructor(e){this.spec=e,this.key=e.key??new Qe(`plugin`)}},et=class extends Ve{time=Date.now();storedMarks;currentSelection;selectionStep=0;storedMarksSet=!1;meta=new Map;constructor(e){super(e.doc),this.currentSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.selectionStep<this.steps.length&&(this.currentSelection=this.currentSelection.map(this.doc,this.mapping.slice(this.selectionStep)),this.selectionStep=this.steps.length),this.currentSelection}setSelection(e){if(e.$anchor.doc!==this.doc)throw RangeError(`Selection is not in this document`);return this.currentSelection=e,this.selectionStep=this.steps.length,this}setStoredMarks(e){return this.storedMarks=e,this.storedMarksSet=!0,this}addStep(e,t){super.addStep(e,t),this.storedMarksSet||(this.storedMarks=null)}setMeta(e,t){return this.meta.set(e,t),this}getMeta(e){return this.meta.get(e)}copyMeta(e){for(let[t,n]of e.meta)this.meta.set(t,n);return this.time=e.time,this}get addToHistory(){return this.meta.get(`addToHistory`)!==!1}deleteSelection(){let e=this.selection;if(e.empty)return this;if(e instanceof Ge){let e=tt(this.doc.type.schema),t=this.doc.childCount===1?this.doc.firstChild:null;return(t?.type!==e||t.content.size!==0)&&this.replace(0,this.doc.content.size,new w(f.from(e.create()),0,0)),this.setSelection(L.atStart(this.doc))}let t=this.steps.length,{$from:n}=e,r=n.index();if(e instanceof We&&!n.parent.canReplace(r,r+1)){let t=n.parent.contentMatchAt(r).defaultType;if(!t?.isTextblock)throw new F(`The selected node cannot be deleted`);return this.replace(e.from,e.to,new w(f.from(t.create()),0,0)),this.setSelection(R.create(this.doc,e.from+1))}let{$to:i}=e,a=n.depth>0&&n.parent!==i.parent&&n.parent.isTextblock&&i.parent.isTextblock?i.parent:null;this.delete(e.from,e.to),a&&Ye(this,n.before(),a,i.parentOffset);let o=this.mapping.slice(t).map(e.from,-1);return this.setSelection(R.create(this.doc,o))}replaceSelection(e){this.deleteSelection();let t=this.selection.from,n=this.steps.length;this.replace(t,t,e);let r=this.mapping.slice(n).map(t,1);return this.setSelection(L.near(this.doc.resolve(r),-1))}};function tt(e){let t=Object.values(e.nodes).find(e=>e.isTextblock);if(!t)throw RangeError(`Schema has no textblock type`);return t}var nt=class e{doc;selection;storedMarks;plugins;fields;constructor(e,t,n,r,i){this.doc=e,this.selection=t,this.storedMarks=n,this.plugins=r,this.fields=i}static create(t){let n=new e(t.doc,t.selection??L.atStart(t.doc),t.storedMarks??null,t.plugins??[],new Map);for(let e of n.plugins)e.spec.state&&n.fields.set(e,e.spec.state.init(n));return n}get schema(){return this.doc.type.schema}get tr(){return new et(this)}pluginState(e){let t=this.plugins.find(t=>t.key===e);return t?this.fields.get(t):void 0}apply(e){return this.applyTransaction(e).state}withDocument(t,n){return new e(t,n,null,this.plugins,new Map(this.fields))}applyTransaction(e){if(!this.passesFilters(e))return{state:this,transactions:[]};let t=[e],n=this.applyInner(e),r=[];for(let i=0;;i++){if(i>100)throw RangeError(`appendTransaction did not settle after 100 rounds`);let a=!1;if(this.plugins.forEach((i,o)=>{let s=i.spec.appendTransaction;if(!s)return;let c=r[o]??{state:this,count:0},l=c.count<t.length?s(t.slice(c.count),c.state,n):null;l&&n.passesFilters(l,o)&&(l.setMeta(`appendedTransaction`,e),t.push(l),n=n.applyInner(l),a=!0),r[o]={state:n,count:t.length}}),!a)return{state:n,transactions:t}}}passesFilters(e,t=-1){return this.plugins.every((n,r)=>r===t||n.spec.filterTransaction?.(e,this)!==!1)}applyInner(t){if(t.before!==this.doc)throw RangeError(`Transaction was not created from this state`);let n=new e(t.doc,t.selection,t.storedMarks,this.plugins,new Map);for(let e of this.plugins){let r=e.spec.state;r&&n.fields.set(e,r.apply(t,this.fields.get(e),this,n))}return n}};function rt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var z=e=>typeof e==`boolean`?void 0:`must be true or false`,B=(e,t)=>n=>Number.isInteger(n)&&n>=e&&n<=t?void 0:`must be an integer from ${e} to ${t}`,V=(e=255)=>t=>typeof t==`string`&&t.length<=e?void 0:`must be a string of at most ${e} characters`,H=(e=255)=>t=>typeof t==`string`&&t.length>0&&t.length<=e?void 0:`must be a non-empty string of at most ${e} characters`,U=e=>t=>e.includes(t)?void 0:`must be one of ${e.join(`, `)}`,it=e=>typeof e==`string`&&/^[A-Za-z][A-Za-z0-9-]{0,63}$/.test(e)?void 0:`must be a Word token`,at=e=>typeof e==`string`&&/^([0-9A-Fa-f]{6}|auto)$/.test(e)?void 0:`must be RRGGBB or auto`,ot=e=>typeof e==`string`&&/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})?$/.test(e)?void 0:`must be an ISO 8601 date-time`,W=e=>typeof e==`string`&&e.length>0&&e.length<=16777216?void 0:`must be an XML string`,st=e=>{if(!rt(e))return`must be an object`;let t=Object.entries(e);if(t.length===0)return`must not be empty (use null)`;if(t.length>64)return`must have at most 64 attributes`;for(let[e,n]of t){if(!/^[A-Za-z_][\w.-]*(:[A-Za-z_][\w.-]*)?$/.test(e))return`${e} is not an attribute name`;if(typeof n!=`string`||n.length>65535)return`${e} must be a string`}},G=e=>t=>t===null?void 0:e(t),ct=(e,t=1e5)=>n=>{if(!Array.isArray(n))return`must be an array`;if(n.length>t)return`must have at most ${t} items`;for(let t=0;t<n.length;t++){let r=e(n[t]);if(r)return`[${t}] ${r}`}},K=(e,t=[],n=!1)=>r=>{if(!rt(r))return`must be an object`;let i=Object.keys(r);if(i.length===0&&!n)return`must not be empty (use null)`;for(let t of i){if(!Object.hasOwn(e,t))return`unknown key ${t}`;let n=e[t](r[t]);if(n)return`${t} ${n}`}for(let e of t)if(!Object.hasOwn(r,e))return`${e} is required`},lt=1440;function ut(e){return Math.round(e*lt/25.4)}function dt(e){return e*25.4/lt}function ft(e){let t=[],n=_t(e.content.content,{instances:t});return{schemaVersion:3,section:gt(e.settings),defaults:{paragraph:{spacing:{after:220,line:360,lineRule:`auto`}},run:[{type:`font`,attrs:{ascii:`Georgia`,hAnsi:`Georgia`,cs:`Georgia`}},{type:`fontSize`,attrs:{value:22,complexScript:22}}]},styles:structuredClone(Ct),numbering:{abstracts:structuredClone([Tt,Et]),instances:t},comments:[],content:{type:`doc`,content:n}}}var pt=720,mt=360;function ht(e){return Math.min(ut(e),31680)}function gt(e){let{width:t,height:n}=e.pageSize,{top:r,right:i,bottom:a,left:o}=e.margins;return{pageSize:{width:Math.max(ht(t),1),height:Math.max(ht(n),1),...t>n?{orientation:`landscape`}:{}},margins:{top:ht(r),right:ht(i),bottom:ht(a),left:ht(o)}}}function _t(e,t){let n=[];for(let r of e)r.type===`bulletList`||r.type===`orderedList`?vt(r,0,void 0,t,n):n.push(yt(r,{}));return n}function vt(e,t,n,r,i){let a=Math.min(t,8),o=e.type===`bulletList`?`bullet`:`number`,s=e.type===`orderedList`?e.attrs?.start??1:1,c=n!==void 0&&n.kind===o&&s===1&&t<=8&&!n.item.continued,l;c&&(l=n.id,n.item.continued=!0),l===void 0&&(l=r.instances.length+1,r.instances.push({id:l,abstract:o===`bullet`?Tt.id:Et.id,...o===`number`?{overrides:[{level:a,start:s}]}:{}}));for(let n of e.content){let[e,...s]=n.content,c={continued:!1};i.push(yt(e,{style:`ListParagraph`,numbering:{id:l,level:a}}));for(let e of s)if(e.type===`bulletList`||e.type===`orderedList`)vt(e,t+1,{id:l,kind:o,item:c},r,i);else{let t=e.type===`paragraph`||e.type===`horizontalRule`?{style:`ListParagraph`}:{};i.push(yt(e,{...t,indent:{left:pt*(a+1)}}))}}}function yt(e,t){if(e.type===`horizontalRule`)return{type:`paragraph`,attrs:{...t,borders:{bottom:{style:`single`,size:6,space:1,color:`auto`}}}};let n={...t};e.type===`heading`&&(n.style=`Heading${e.attrs.level}`);let r=e.attrs?.align;return r&&r!==`start`&&(n.justification=bt[r]),{type:`paragraph`,...Object.keys(n).length?{attrs:n}:{},...e.content?.length?{content:e.content.map(xt)}:{}}}var bt={center:`center`,end:`right`,justify:`both`};function xt(e){let t=e.marks?.flatMap(e=>e.type===`link`?[St(e),{type:`characterStyle`,attrs:{id:`Hyperlink`}}]:[St(e)]);return{...e,...t?.length?{marks:t}:{}}}function St(e){switch(e.type){case`link`:return{type:`link`,attrs:{href:e.attrs.href}};case`textColor`:return{type:`color`,attrs:{value:e.attrs.color.slice(1).toUpperCase()}};case`highlight`:return{type:`shading`,attrs:{pattern:`clear`,fill:e.attrs.color.slice(1).toUpperCase()}};default:return{type:e.type}}}var Ct=[{id:`Normal`,type:`paragraph`,name:`Normal`,isDefault:!0},...[32,28,26,24,22,22].map((e,t)=>({id:`Heading${t+1}`,type:`paragraph`,name:`heading ${t+1}`,basedOn:`Normal`,next:`Normal`,paragraph:{keepNext:!0,keepLines:!0,outlineLevel:t,spacing:{before:240,after:120}},run:[{type:`bold`},{type:`fontSize`,attrs:{value:e}}]})),{id:`ListParagraph`,type:`paragraph`,name:`List Paragraph`,basedOn:`Normal`,paragraph:{indent:{left:pt},contextualSpacing:!0}},{id:`DefaultParagraphFont`,type:`character`,name:`Default Paragraph Font`,isDefault:!0},{id:`Hyperlink`,type:`character`,name:`Hyperlink`,basedOn:`DefaultParagraphFont`,run:[{type:`color`,attrs:{value:`0563C1`,themeColor:`hyperlink`}},{type:`underline`}]}];function wt(e){return Array.from({length:9},(t,n)=>({level:n,start:1,format:e===`bullet`?`bullet`:`decimal`,text:e===`bullet`?[`•`,`◦`,`▪`][n%3]:`%${n+1}.`,justification:`left`,paragraph:{indent:{left:pt*(n+1),hanging:mt}}}))}var Tt={id:0,multiLevelType:`hybridMultilevel`,levels:wt(`bullet`)},Et={id:1,multiLevelType:`hybridMultilevel`,levels:wt(`number`)},Dt=31680,Ot=B(-31680,Dt),kt=B(0,Dt),At=B(-31680,Dt),jt=[`left`,`center`,`right`,`both`,`start`,`end`,`distribute`,`mediumKashida`,`highKashida`,`lowKashida`,`thaiDistribute`,`numTab`],Mt=[`auto`,`exact`,`atLeast`],Nt=[`left`,`center`,`right`,`decimal`,`bar`,`clear`,`num`,`start`,`end`],Pt=[`none`,`dot`,`hyphen`,`underscore`,`heavy`,`middleDot`],Ft=[`nextPage`,`continuous`,`evenPage`,`oddPage`,`nextColumn`],It=[`baseline`,`superscript`,`subscript`],Lt=[`black`,`blue`,`cyan`,`green`,`magenta`,`red`,`yellow`,`white`,`darkBlue`,`darkCyan`,`darkGreen`,`darkMagenta`,`darkRed`,`darkYellow`,`darkGray`,`lightGray`,`none`],Rt=[`majorAscii`,`majorHAnsi`,`majorEastAsia`,`majorBidi`,`minorAscii`,`minorHAnsi`,`minorEastAsia`,`minorBidi`],zt=K({style:it,size:B(0,96),space:B(0,31),color:at,themeColor:it},[`style`]),Bt=K({pattern:it,color:at,fill:at,themeFill:it},[`pattern`]),q=e=>({default:null,validate:G(e)}),Vt=B(0,2147483647),Ht={id:Vt,author:V(),date:G(ot)},Ut=K(Ht,[`id`,`author`]),Wt=K({position:U([`pageBottom`,`beneathText`,`sectEnd`,`docEnd`]),format:it,start:Vt,restart:U([`continuous`,`eachSect`,`eachPage`])}),Gt=45,Kt=e=>qt(e),qt=K({pageSize:K({width:B(1,Dt),height:B(1,Dt),orientation:U([`portrait`,`landscape`])}),margins:K({top:Ot,right:kt,bottom:Ot,left:kt,header:kt,footer:kt,gutter:kt}),type:U(Ft),titlePage:z,headers:K({default:H(),first:H(),even:H()}),footers:K({default:H(),first:H(),even:H()}),columns:K({count:B(1,Gt),space:kt,equalWidth:z,separator:z,widths:ct(K({width:kt,space:kt},[`width`]),Gt)}),pageNumbers:K({start:Vt,format:it}),footnotes:Wt,endnotes:Wt,change:K({...Ht,previous:Kt},[`id`,`author`,`previous`]),ext:W},[],!0),Jt=K({value:Ot,type:U([`auto`,`dxa`,`pct`,`nil`])},[`value`,`type`]),Yt=(e,t=[])=>K(Object.fromEntries([`top`,`left`,`bottom`,`right`,`start`,`end`,...t].map(t=>[t,e]))),Xt=1e3,Zt={style:q(H()),width:q(Jt),justification:q(U([`left`,`center`,`right`,`start`,`end`])),indent:q(Jt),layout:q(U([`fixed`,`autofit`])),borders:q(Yt(zt,[`insideH`,`insideV`])),cellMargins:q(Yt(Jt)),cellSpacing:q(Jt),shading:q(Bt),look:q(K({firstRow:z,lastRow:z,firstColumn:z,lastColumn:z,noHBand:z,noVBand:z})),rowBandSize:q(B(1,Xt)),columnBandSize:q(B(1,Xt)),ext:q(W)},Qt={height:q(K({value:kt,rule:U([`auto`,`exact`,`atLeast`])},[`value`])),cantSplit:q(z),header:q(z),gridBefore:q(B(1,Xt)),widthBefore:q(Jt),gridAfter:q(B(1,Xt)),widthAfter:q(Jt),ext:q(W)},$t={width:q(Jt),gridSpan:q(B(1,Xt)),vMerge:q(U([`restart`,`continue`])),borders:q(Yt(zt,[`insideH`,`insideV`,`tl2br`,`tr2bl`])),shading:q(Bt),margins:q(Yt(Jt)),verticalAlign:q(U([`top`,`center`,`bottom`,`both`])),textDirection:q(it),noWrap:q(z),ext:q(W)},en=e=>t=>{if(!rt(t))return`must be an object`;for(let[n,r]of Object.entries(t)){if(!Object.hasOwn(e,n))return`unknown key ${n}`;let t=r===null?`must not be null (leave it out)`:e[n].validate?.(r);if(t)return`${n} ${t}`}},tn=en(Zt),nn=en(Qt),rn=en($t),an=B(0,2147483647),on=B(-2147483648,2147483647),sn=K({horizontal:K({relativeTo:it,offset:on,align:it},[`relativeTo`]),vertical:K({relativeTo:it,offset:on,align:it},[`relativeTo`]),wrap:U([`square`,`tight`,`through`,`topAndBottom`,`behind`,`inFront`]),side:U([`bothSides`,`left`,`right`,`largest`]),distance:K({top:an,bottom:an,left:an,right:an}),allowOverlap:z,layoutInCell:z},[`horizontal`,`vertical`,`wrap`]),cn=[`characterStyle`,`bold`,`italic`,`underline`,`strike`,`doubleStrike`,`caps`,`smallCaps`,`hidden`,`font`,`fontSize`,`color`,`highlight`,`shading`,`verticalAlign`,`characterSpacing`],ln=e=>{if(!Array.isArray(e))return`must be an array of marks`;for(let t of e)if(!rt(t)||!cn.includes(t.type))return`${rt(t)?String(t.type):`a non-object`} is not a run property`;try{Sn.nodeFromJSON({type:`text`,text:`x`,marks:e});return}catch(e){return e.message}},un={style:q(H()),justification:q(U(jt)),indent:q(K({left:Ot,right:Ot,firstLine:kt,hanging:kt})),spacing:q(K({before:kt,after:kt,line:At,lineRule:U(Mt),beforeAutospacing:z,afterAutospacing:z})),keepNext:q(z),keepLines:q(z),widowControl:q(z),pageBreakBefore:q(z),contextualSpacing:q(z),outlineLevel:q(B(0,9)),numbering:q(K({id:Vt,level:B(0,8)})),tabs:q(ct(K({position:Ot,kind:U(Nt),leader:U(Pt)},[`position`,`kind`]),64)),borders:q(K({top:zt,bottom:zt,left:zt,right:zt,between:zt,bar:zt})),shading:q(Bt),markFormat:q(ln),ext:q(W)},dn=Object.keys(un),fn=e=>{if(!rt(e))return`must be an object`;for(let[t,n]of Object.entries(e)){if(!Object.hasOwn(un,t))return`unknown key ${t}`;let e=n===null?`must not be null (leave it out)`:un[t].validate?.(n);if(e)return`${t} ${e}`}},J=(e,t)=>t===void 0?{validate:e}:{default:t,validate:e},pn={attrs:{value:J(z,!0)}},mn={attrs:{value:J(G(z),!0),complexScript:J(G(z),null)}},hn={attrs:{id:J(Vt),author:J(V()),date:J(G(ot),null),move:J(G(H()),null),attributes:J(G(st),null)},inclusive:!1},gn={attributes:q(st)},_n={controls:q(e=>{let t=ct(H(),64)(e);if(t)return t;let n=e;return n.length?new Set(n).size===n.length?void 0:`must not repeat an id`:`must not be empty (use null)`})},vn={group:`inline`,inline:!0,selectable:!1},yn=J(G(H()),null),bn=J(G(U(Rt)),null),xn=e=>typeof e==`string`&&/^[0-9A-Fa-f]{2}$/.test(e)?void 0:`must be a hex byte`,Sn=new ie({nodes:{doc:{content:`block+`},paragraph:{group:`block`,content:`inline*`,attrs:{...un,..._n,section:q(Kt),revision:q(K({insertion:Ut,deletion:Ut})),formatChange:q(K({...Ht,previous:fn},[`id`,`author`,`previous`])),attributes:q(st)}},table:{group:`block`,content:`tableRow+`,attrs:{...Zt,..._n,grid:{default:[],validate:ct(kt,Xt)},gridExt:q(W)}},tableRow:{content:`tableCell+`,attrs:{...Qt,..._n,revision:q(K({insertion:Ut,deletion:Ut})),exceptions:q(tn),attributes:q(st)}},tableCell:{content:`block* paragraph`,attrs:{...$t,..._n}},opaqueBlock:{group:`block`,attrs:{xml:{validate:W},label:q(H()),..._n}},text:{group:`inline`},tab:{group:`inline`,inline:!0},hardBreak:{group:`inline`,inline:!0,selectable:!1,attrs:{clear:q(U([`none`,`left`,`right`,`all`]))}},pageBreak:{group:`inline`,inline:!0,selectable:!1},columnBreak:{group:`inline`,inline:!0,selectable:!1},bookmarkStart:{group:`inline`,inline:!0,selectable:!1,attrs:{id:{validate:Vt},name:{validate:V()},...gn}},bookmarkEnd:{group:`inline`,inline:!0,selectable:!1,attrs:{id:{validate:Vt},...gn}},commentStart:{group:`inline`,inline:!0,selectable:!1,attrs:{id:{validate:Vt},...gn}},commentEnd:{group:`inline`,inline:!0,selectable:!1,attrs:{id:{validate:Vt},...gn}},commentReference:{group:`inline`,inline:!0,attrs:{id:{validate:Vt},...gn}},fieldStart:{...vn,attrs:{dirty:q(z),locked:q(z),simple:q(z),ext:q(W)}},fieldCode:{...vn,attrs:{text:{validate:V(65535)},...gn}},fieldSeparator:{...vn,attrs:{ext:q(W)}},fieldEnd:{...vn,attrs:{ext:q(W)}},controlStart:{group:`inline`,inline:!0,selectable:!1,attrs:{id:{validate:H()}}},controlEnd:{group:`inline`,inline:!0,selectable:!1,attrs:{id:{validate:H()}}},noteReference:{group:`inline`,inline:!0,attrs:{story:{validate:H()},customMark:q(z),...gn}},noteMark:{group:`inline`,inline:!0,selectable:!1},picture:{group:`inline`,inline:!0,attrs:{resource:{validate:H()},width:{validate:an},height:{validate:an},alt:q(V(65535)),title:q(V(65535)),decorative:q(z),float:q(sn),ext:q(W)}},opaqueInline:{group:`inline`,inline:!0,attrs:{xml:{validate:W},label:q(H()),run:{default:!1,validate:z}}}},marks:{link:{attrs:{href:J(G(H(8192)),null),anchor:J(G(H()),null),tooltip:J(G(V(1024)),null),attributes:J(G(st),null)},inclusive:!1},insertion:hn,deletion:hn,characterStyle:{attrs:{id:J(H())}},bold:mn,italic:mn,underline:{attrs:{style:J(it,`single`),color:J(G(at),null)}},strike:pn,doubleStrike:pn,caps:pn,smallCaps:pn,hidden:pn,font:{attrs:{ascii:yn,hAnsi:yn,eastAsia:yn,cs:yn,asciiTheme:bn,hAnsiTheme:bn,eastAsiaTheme:bn,csTheme:bn,hint:J(G(U([`default`,`eastAsia`,`cs`])),null)}},fontSize:{attrs:{value:J(G(B(1,3276)),null),complexScript:J(G(B(1,3276)),null)}},color:{attrs:{value:J(at),themeColor:J(G(it),null),themeTint:J(G(xn),null),themeShade:J(G(xn),null)}},highlight:{attrs:{value:J(U(Lt))}},shading:{attrs:{pattern:J(it),color:J(at,`auto`),fill:J(at,`auto`)}},verticalAlign:{attrs:{value:J(U(It))}},characterSpacing:{attrs:{value:J(Ot)}},formatChange:{attrs:{id:J(Vt),author:J(V()),date:J(G(ot),null),previous:J(ln)}},runExt:{attrs:{xml:J(W)}}}}),Cn=[`wholeTable`,`band1Vert`,`band2Vert`,`band1Horz`,`band2Horz`,`firstCol`,`lastCol`,`firstRow`,`lastRow`,`nwCell`,`neCell`,`swCell`,`seCell`];function wn(e){return{...e,schemaVersion:4}}function Tn(e){return{...e,schemaVersion:5}}function En(e={type:`doc`,content:[{type:`paragraph`}]},t){let n=Tn(wn(ft({schemaVersion:2,settings:ge,content:{type:`doc`,content:[]}}))),r=n.section;return{...n,section:{...t,pageSize:{...r.pageSize,...t?.pageSize},margins:{...r.margins,...t?.margins}},content:e}}function Dn(e){if(!rt(e))throw new i(`Document must be an object`);let t=e.schemaVersion;if(t===1||t===2)return Dn(Tn(wn(ft(_e(e)))));if(t===3||t===4){t===3&&Object.hasOwn(e,`resources`)&&Y(`resources`,`unknown key (schema 4 and later)`);for(let t of Fn)Object.hasOwn(e,t)&&Y(t,`unknown key (schema 5 and later)`);let n=Dn({...e,schemaVersion:5}),r=Ln(n.section);r&&Y(`section`,`${r} is of schema 5 (the document says schema ${t})`);for(let[e,r]of[[`content`,n.content],...n.comments.map((e,t)=>[`comments[${t}].content`,{content:e.content}])]){let n=Rn(r,t);n&&Y(e,`${n.name} is a schema ${n.schema} node (the document says schema ${t})`)}return t===3&&n.styles.forEach((e,t)=>{for(let n of[`table`,`row`,`cell`,`conditions`])Object.hasOwn(e,n)&&Y(`styles[${t}]`,`unknown key ${n} (schema 4 and later)`)}),n}if(t!==5)throw new i(`Unsupported schemaVersion: ${String(t)} (this version of @folijs/core reads 1 to 5${Number.isInteger(t)&&t>5?`; the document was saved by a newer one`:``})`);for(let t of Object.keys(e))if(!zn.includes(t))throw new i(`${t}: unknown key`);Bn(`section`,e.section,Kt),Bn(`defaults`,e.defaults,K({paragraph:fn,run:ln,ext:W},[],!0)),Bn(`styles`,e.styles,ct(Wn)),Bn(`numbering`,e.numbering,K({abstracts:ct(nr),instances:ct(rr)},[`abstracts`,`instances`])),e.theme!==void 0&&Bn(`theme`,e.theme,ar),Bn(`comments`,e.comments,ct(or)),e.resources!==void 0&&Bn(`resources`,e.resources,Xn),e.stories!==void 0&&Bn(`stories`,e.stories,Qn),e.controls!==void 0&&Bn(`controls`,e.controls,$n),e.settings!==void 0&&Bn(`settings`,e.settings,er);let n=e.styles,r=e.comments;Vn(`styles`,n,e=>e.id,e=>e.basedOn,e=>`${e.id} is based on itself`),Vn(`comments`,r,e=>e.id,e=>e.parent,e=>`comment ${e.id} replies to itself`);let a=kn(e.content),o=Object.entries(e.stories??{}).map(([e,t])=>{let n=`stories[${JSON.stringify(e)}].content`,r=kn(t.content,n);return jn(r,t.kind,n),[e,{...structuredClone({...t,content:null}),content:On(r)}]}),s=structuredClone({section:e.section,defaults:e.defaults,styles:n,numbering:e.numbering,theme:e.theme,resources:e.resources,controls:e.controls,settings:e.settings});return{schemaVersion:5,section:s.section,defaults:s.defaults,styles:s.styles,numbering:s.numbering,...s.theme===void 0?{}:{theme:s.theme},comments:r.map((e,t)=>({...structuredClone({...e,content:[]}),content:Hn(e.content,`comments[${t}].content`).map(e=>(e.descendants(e=>(e.type.name===`noteReference`&&Y(`comments[${t}].content`,`a comment cannot hold a note reference`),!0)),On(e)))})),...s.resources===void 0?{}:{resources:s.resources},...e.stories===void 0?{}:{stories:Object.fromEntries(o)},...s.controls===void 0?{}:{controls:s.controls},...s.settings===void 0?{}:{settings:s.settings},content:On(a)}}var On=e=>structuredClone(e.toJSON());function kn(e,t=`content`,n=!1){let r=Sn.nodeFromJSON(e,t);return r.type!==Sn.topNodeType&&Y(t,`root node must be of type "doc"`),r.marks.length&&Y(`${t}.marks`,`doc cannot have marks`),An(r,t,!1,n),r}function An(e,t,n,r=!1){e.forEach((i,a,o)=>{let s=`${t}.content[${o}]`;if(i.type.name===`table`){let t=e.maybeChild(o+1);t?.type.name===`table`&&JSON.stringify(t.attrs.controls)===JSON.stringify(i.attrs.controls)&&Y(s,`a table cannot follow a table (Word would merge them): a paragraph goes between`),!t&&e.type.name===`doc`&&!r&&Y(s,`a table cannot end the document: a paragraph follows it, as in Word`),i.forEach((e,t,n)=>{e.forEach((e,t,r)=>{An(e,`${s}.content[${n}].content[${r}]`,!0)})})}else n&&i.type.name===`paragraph`&&(i.attrs.section&&Y(`${s}.attrs.section`,`a paragraph in a table cannot end a section`),i.forEach((e,t,n)=>{(e.type.name===`pageBreak`||e.type.name===`columnBreak`)&&Y(`${s}.content[${n}]`,`a ${e.type.name} cannot be in a table`)}))})}function jn(e,t,n){e.descendants(e=>{let r=e.type.name;return e.attrs.section&&Y(n,`a story cannot end a section`),r===`noteReference`&&Y(n,`a story cannot hold a note reference`),Mn.has(r)&&Y(n,`a ${t} cannot hold comments`),t!==`footnote`&&t!==`endnote`||r!==`pageBreak`&&r!==`columnBreak`||Y(n,`a note cannot hold a ${r}`),!0})}var Mn=new Set([`commentStart`,`commentEnd`,`commentReference`]),Nn=new Set([`table`,`tableRow`,`tableCell`,`picture`]),Pn=new Set([`fieldStart`,`fieldCode`,`fieldSeparator`,`fieldEnd`,`controlStart`,`controlEnd`,`noteReference`,`noteMark`]),Fn=[`stories`,`controls`,`settings`],In=[`columns`,`pageNumbers`,`footnotes`,`endnotes`];function Ln(e){return rt(e)?In.find(t=>Object.hasOwn(e,t)):void 0}function Rn(e,t){let n=[e];for(;n.length;){let e=n.pop();if(!rt(e))continue;let r=e.type;if(t<4&&Nn.has(r))return{name:r,schema:4};if(Pn.has(r))return{name:r,schema:5};let i=rt(e.attrs)?e.attrs:{};if(i.controls)return{name:`controls`,schema:5};let a=Ln(i.section);if(a)return{name:a,schema:5};if(Array.isArray(e.content))for(let t of e.content)n.push(t)}}var zn=[`schemaVersion`,`section`,`defaults`,`styles`,`numbering`,`theme`,`comments`,`resources`,`stories`,`controls`,`settings`,`content`];function Y(e,t){throw new i(`${e}: ${t}`)}function Bn(e,t,n){let r=n(t);r&&Y(e,r)}function Vn(e,t,n,r,i){let a=new Map;t.forEach((e,t)=>{a.has(n(e))||a.set(n(e),t)});let o=new Uint8Array(t.length);t.forEach((n,s)=>{let c=[],l=s;for(;l!==void 0&&o[l]===0;){o[l]=1,c.push(l);let e=r(t[l]);l=e===void 0?void 0:a.get(e)}l!==void 0&&o[l]===1&&Y(`${e}[${l}]`,i(t[l]));for(let e of c)o[e]=2})}function Hn(e,t){let n=kn({type:`doc`,content:e},t),r=[];return n.forEach(e=>{r.push(e)}),r}var Un=K({type:U(Cn.filter(e=>e!==`wholeTable`)),paragraph:fn,run:ln,table:tn,row:nn,cell:rn,ext:W},[`type`]),Wn=K({id:H(),type:U([`paragraph`,`character`,`table`,`numbering`]),name:V(),basedOn:H(),next:H(),link:H(),isDefault:z,paragraph:fn,run:ln,table:tn,row:nn,cell:rn,conditions:ct(Un,Cn.length),ext:W},[`id`,`type`]),Gn=new Set([`http:`,`https:`,`blob:`]);function Kn(e){try{return new URL(e,`https://base.invalid/`).protocol}catch{return``}}var qn=/^image\/[A-Za-z0-9][\w.+-]{0,126}$/,Jn=e=>{let t=K({contentType:e=>typeof e==`string`&&qn.test(e)?void 0:`must be an image media type`,size:B(0,2**53-1),part:H(1024),url:e=>H(8192)(e)??(Gn.has(Kn(e))?void 0:`must be relative, http(s) or blob`),data:e=>typeof e==`string`&&/^data:image\/[\w.+-]+[;,]/i.test(e)&&e.length<=67108864?void 0:`must be a data: URL of an image`},[`contentType`])(e);if(t)return t;let n=e;return n.part===void 0&&n.url===void 0&&n.data===void 0?`needs part, url or data`:void 0},Yn=(e,t)=>n=>{if(!rt(n))return`must be an object`;let r=Object.entries(n);if(r.length>1e5)return`must have at most 100000 ${t}s`;for(let[n,i]of r){let r=n===`__proto__`?`is not a ${t} key`:H()(n);if(r)return`${n.slice(0,64)} ${r}`;let a=e(i);if(a)return`${n} ${a}`}},Xn=Yn(Jn,`resource`),Zn=[`footnote`,`endnote`],Qn=Yn(e=>K({kind:U([`header`,`footer`,...Zn]),noteType:U([`normal`,`separator`,`continuationSeparator`,`continuationNotice`]),content:e=>rt(e)?void 0:`must be an object`,ext:W},[`kind`,`content`])(e)??(rt(e)&&e.noteType!==void 0&&!Zn.includes(e.kind)?`noteType is for notes`:void 0),`story`),$n=Yn(K({kind:U([`text`,`richText`,`dropDown`,`comboBox`,`date`,`checkbox`,`picture`,`repeating`,`repeatingItem`,`other`]),tag:V(),alias:V(),lock:U([`sdtLocked`,`contentLocked`,`sdtContentLocked`,`unlocked`]),items:ct(K({value:V(),display:V()},[`value`])),dateFormat:V(),date:V(),checked:z,checkedState:K({value:V(),font:V()},[`value`]),uncheckedState:K({value:V(),font:V()},[`value`]),multiLine:z,format:ln,noInsertDelete:z,deleted:z,placeholder:K({showing:z,docPart:V(),text:V(65535)},[],!0),binding:K({xpath:V(65535),storeItemId:V(),prefixMappings:V(65535)},[],!0),ext:W},[`kind`]),`control`),er=K({doNotUseHTMLParagraphAutoSpacing:z,evenAndOddHeaders:z,footnotes:Wt,endnotes:Wt},[],!0),tr=K({level:B(0,8),start:B(0,2147483647),format:it,text:V(),justification:U([`left`,`center`,`right`,`start`,`end`]),restart:B(0,9),legal:z,suffix:U([`tab`,`space`,`nothing`]),style:H(),paragraph:fn,run:ln,ext:W},[`level`]),nr=K({id:B(0,2147483647),multiLevelType:U([`singleLevel`,`multilevel`,`hybridMultilevel`]),levels:ct(tr,9),styleLink:H(),numStyleLink:H(),ext:W},[`id`,`levels`]),rr=K({id:B(1,2147483647),abstract:B(0,2147483647),overrides:ct(K({level:B(0,8),start:B(0,2147483647),definition:tr},[`level`]),9),ext:W},[`id`,`abstract`]),ir=K({latin:V(),eastAsia:V(),cs:V()},[`latin`]),ar=K({fonts:K({major:ir,minor:ir},[`major`,`minor`]),colors:e=>{if(!rt(e))return`must be an object`;for(let[t,n]of Object.entries(e)){if(!/^(dk[12]|lt[12]|accent[1-6]|hlink|folHlink)$/.test(t))return`unknown color ${t}`;let e=at(n);if(e)return`${t} ${e}`}}},[`fonts`,`colors`]),or=K({id:B(0,2147483647),author:V(),initials:V(9),date:ot,content:e=>Array.isArray(e)?void 0:`must be an array of blocks`,parent:B(0,2147483647),done:z,ext:W},[`id`,`author`,`content`]),sr=[`bold`,`boldCs`,`italic`,`italicCs`,`caps`,`smallCaps`,`strike`,`doubleStrike`,`hidden`],cr={bold:!1,boldCs:!1,italic:!1,italicCs:!1,caps:!1,smallCaps:!1,strike:!1,doubleStrike:!1,hidden:!1,underline:null,underlineColor:null,font:{ascii:null,hAnsi:null,eastAsia:null,cs:null},size:20,sizeCs:20,color:null,highlight:null,shading:null,verticalAlign:`baseline`,characterSpacing:0},lr={style:null,justification:null,indent:{left:0,right:0,firstLine:0,hanging:0},spacing:{before:0,after:0,line:null,lineRule:`auto`,beforeAutospacing:!1,afterAutospacing:!1},keepNext:!1,keepLines:!1,widowControl:!1,pageBreakBefore:!1,contextualSpacing:!1,outlineLevel:null,tabs:[],borders:null,shading:null,numbering:null},ur=new Set([`justification`,`keepNext`,`keepLines`,`widowControl`,`pageBreakBefore`,`contextualSpacing`,`outlineLevel`,`shading`]);function dr(e,t){if(!t)return;let{indent:n,spacing:r,numbering:i,borders:a,tabs:o}=t;if(n&&(n.firstLine!==void 0&&(e.indent.hanging=0),Object.assign(e.indent,n),e.indent.hanging&&(e.indent.firstLine=0)),r&&Object.assign(e.spacing,r),i&&(e.numbering={id:i.id??e.numbering?.id??0,level:i.level??e.numbering?.level}),a&&(e.borders={...e.borders,...a}),o){let t=new Map(e.tabs.map(e=>[e.position,e]));for(let e of o)e.kind===`clear`?t.delete(e.position):t.set(e.position,{position:e.position,kind:e.kind,leader:e.leader??null});e.tabs=[...t.values()].sort((e,t)=>e.position-t.position)}for(let[n,r]of Object.entries(t))ur.has(n)&&r!=null&&(e[n]=r)}function fr(e){return{...e,indent:{...e.indent},spacing:{...e.spacing},tabs:e.tabs.map(e=>({...e})),borders:e.borders?Object.fromEntries(Object.entries(e.borders).map(([e,t])=>[e,{...t}])):null,shading:e.shading?{...e.shading}:null,numbering:e.numbering?{...e.numbering}:null}}function pr(e){return{...e,font:{...e.font}}}function mr(e){let t={};for(let n of e??[]){let e=n.attrs??{},r=e.value===void 0||e.value;switch(n.type){case`bold`:case`italic`:{r!==null&&(t[n.type]=r);let i=e.complexScript;i!=null&&(t[n.type===`bold`?`boldCs`:`italicCs`]=i);break}case`caps`:case`smallCaps`:case`strike`:case`doubleStrike`:case`hidden`:r!==null&&(t[n.type]=r)}}return t}var hr={text1:`dk1`,background1:`lt1`,text2:`dk2`,background2:`lt2`,dark1:`dk1`,light1:`lt1`,dark2:`dk2`,light2:`lt2`,hyperlink:`hlink`,followedHyperlink:`folHlink`};function gr(e,t,n){for(let r of t??[]){let t=r.attrs??{};switch(r.type){case`underline`:{let n=t.style??`single`;e.underline=n===`none`?null:n,e.underlineColor=t.color??null;break}case`font`:for(let r of[`ascii`,`hAnsi`,`eastAsia`,`cs`]){let i=t[`${r}Theme`],a=i&&yr(n,i)||t[r];a&&(e.font[r]=a)}break;case`fontSize`:typeof t.value==`number`&&(e.size=t.value),typeof t.complexScript==`number`&&(e.sizeCs=t.complexScript);break;case`color`:{let r=(t.themeColor&&!t.themeTint&&!t.themeShade?n?.colors[hr[t.themeColor]??t.themeColor]:void 0)??t.value;e.color=r===void 0||r===`auto`?null:r.toUpperCase();break}case`highlight`:e.highlight=t.value===`none`?null:t.value;break;case`shading`:e.shading=t.fill===`auto`||t.fill===void 0?null:String(t.fill).toUpperCase();break;case`verticalAlign`:e.verticalAlign=t.value;break;case`characterSpacing`:e.characterSpacing=t.value}}}function _r(e,t,n){Object.assign(e,mr(t)),gr(e,t,n)}function vr(e,t,n){let r={};for(let i of t)Object.assign(r,mr(i)),gr(e,i,n);for(let t of sr)r[t]&&(e[t]=!e[t])}function yr(e,t){if(!e)return null;let n=t.startsWith(`major`)?e.fonts.major:e.fonts.minor,r=t.slice(5);return(r===`EastAsia`?n.eastAsia:r===`Bidi`?n.cs:n.latin)||null}function br(e,t){switch(t??`decimal`){case`none`:return``;case`decimalZero`:return e>=0&&e<10?`0${e}`:String(e);case`upperRoman`:return Cr(e);case`lowerRoman`:return Cr(e).toLowerCase();case`upperLetter`:return wr(e);case`lowerLetter`:return wr(e).toLowerCase();case`ordinal`:return Tr(e);case`chicago`:return xr(e);case`numberInDash`:return`- ${e} -`;default:return String(e)}}function xr(e){return e<1?String(e):[`*`,`†`,`‡`,`§`][(e-1)%4].repeat(Math.ceil(e/4))}var Sr=[[1e3,`M`],[900,`CM`],[500,`D`],[400,`CD`],[100,`C`],[90,`XC`],[50,`L`],[40,`XL`],[10,`X`],[9,`IX`],[5,`V`],[4,`IV`],[1,`I`]];function Cr(e){if(e<=0||e>=4e3)return String(e);let t=``,n=e;for(let[e,r]of Sr)for(;n>=e;n-=e)t+=r;return t}function wr(e){return e<=0||e>780?String(e):String.fromCharCode(65+(e-1)%26).repeat(Math.floor((e-1)/26)+1)}function Tr(e){let t=e%100;return`${e}${t>=11&&t<=13?`th`:[`th`,`st`,`nd`,`rd`][e%10]??`th`}`}var Er=new Set([`width`,`justification`,`indent`,`layout`,`borders`,`cellMargins`,`cellSpacing`,`shading`,`look`,`rowBandSize`,`columnBandSize`]),Dr=new Set([`borders`,`cellMargins`,`look`]);function Or(e,t){if(t)for(let[n,r]of Object.entries(t))r!=null&&Er.has(n)&&(e[n]=Dr.has(n)?{...e[n],...r}:r)}function kr(e){if(e)return e.type===`dxa`?e.value:0}function Ar(e,t){for(let n=e.length-1;n>=0;n--){let r=t(e[n]);if(r!=null)return r}}function jr(e,t,n=1,r=1){let i=[`wholeTable`],a=!!e.firstRow&&t.row===0,o=!!e.lastRow&&t.row===t.rows-1,s=!!e.firstColumn&&t.cell===0,c=!!e.lastColumn&&t.cell===t.cells-1;if(!e.noVBand&&!s&&!c){let n=t.cell-+!!e.firstColumn;i.push(Math.floor(n/r)%2==0?`band1Vert`:`band2Vert`)}if(!e.noHBand&&!a&&!o){let r=t.row-+!!e.firstRow;i.push(Math.floor(r/n)%2==0?`band1Horz`:`band2Horz`)}return s&&i.push(`firstCol`),c&&i.push(`lastCol`),a&&i.push(`firstRow`),o&&i.push(`lastRow`),a&&s&&i.push(`nwCell`),a&&c&&i.push(`neCell`),o&&s&&i.push(`swCell`),o&&c&&i.push(`seCell`),i}var Mr=class{#e=new Map;#t;#n;#r=new Map;#i=new Map;#a=new Map;#o=new Map;#s;#c=new Map;get addsParagraphSpacing(){return this.#n.settings?.doNotUseHTMLParagraphAutoSpacing===!0}constructor(e){this.#n=e;for(let t of e.styles)this.#e.has(t.id)||this.#e.set(t.id,t);for(let t of e.styles)t.type===`paragraph`&&t.isDefault&&(this.#t=t.id),t.type===`table`&&t.isDefault&&(this.#s=t.id);for(let t of e.numbering.instances)this.#a.has(t.id)||this.#a.set(t.id,t);for(let t of e.numbering.abstracts)this.#o.has(t.id)||this.#o.set(t.id,t)}#l(e,t){let n=[],r=new Set;for(let i=e;i!==void 0&&!r.has(i);){r.add(i);let e=this.#e.get(i);if(e?.type!==t)break;n.unshift(e),i=e.basedOn}return n}#u(e){let t=e?this.#l(e,`table`):[];return t.length?t:this.#l(this.#s,`table`)}#d(e,t){let n=JSON.stringify([e,t]),r=this.#c.get(n);if(r)return r;let i={key:n,paragraph:[],run:[],cell:[]},a=this.#u(e);for(let e of t)for(let t of a){let n=e===`wholeTable`?t:t.conditions?.find(t=>t.type===e);n?.paragraph&&i.paragraph.push(n.paragraph),n?.run&&i.run.push(n.run),n?.cell&&i.cell.push(n.cell)}return this.#c.set(n,i),i}table(e){let t=this.#u(e.style),n={};for(let e of t)Or(n,e.table);return Or(n,e),structuredClone({...n,style:t.at(-1)?.id??null})}cell(e,t,n,r){let i=this.table(e);Or(i,t.exceptions);let a=i,o=jr(a.look??{},r,a.rowBandSize,a.columnBandSize),s=[...this.#d(a.style,o).cell,n],c=Ar(s,e=>e.shading)?.fill??a.shading?.fill,l=a.borders??{},u=(e,t,n,r)=>Ar(s,n=>n.borders?.[e]??(t?n.borders?.[t]:void 0))??(r?l[e]??(t?l[t]:void 0):n),d={},f=[[`top`,null,l.insideH,r.row===0],[`bottom`,null,l.insideH,r.row===r.rows-1],[`left`,`start`,l.insideV,r.cell===0],[`right`,`end`,l.insideV,r.cell===r.cells-1]];for(let[e,t,n,r]of f){let i=u(e,t,n,r);i&&(d[e]={...i})}let p=(e,t)=>kr(Ar(s,n=>n.margins?.[e]??(t?n.margins?.[t]:void 0))??a.cellMargins?.[e]??(t?a.cellMargins?.[t]:void 0))??0;return{style:a.style,conditions:o,shading:c===void 0||c===`auto`?null:c.toUpperCase(),borders:d,margins:{top:p(`top`,null),bottom:p(`bottom`,null),left:p(`left`,`start`),right:p(`right`,`end`)},verticalAlign:Ar(s,e=>e.verticalAlign)??`top`}}#f(e,t){let n=JSON.stringify([t?.key??null,e??null]),r=this.#r.get(n);if(r)return r;let i=fr(lr),a=pr(cr);this.#p(i,a,t);let o=e===void 0?[]:this.#l(e,`paragraph`);o.length||(o=this.#l(this.#t,`paragraph`));for(let e of o)dr(i,e.paragraph);vr(a,o.map(e=>e.run??[]),this.#n.theme),i.style=o.at(-1)?.id??null;let s={paragraph:i,run:a,chain:o};return this.#r.set(n,s),s}#p(e,t,n){let{defaults:r,theme:i}=this.#n;dr(e,r.paragraph),t&&_r(t,r.run,i);for(let t of n?.paragraph??[])dr(e,t);if(t)for(let e of n?.run??[])_r(t,e,i)}paragraph(e,t){let{paragraph:n,run:r}=this.#m(e,t);return{paragraph:n,run:r}}#m(e,t){let n=e,r=t?this.#d(t.style,t.conditions):void 0,i=this.#f(n.style??void 0,r),a=fr(i.paragraph),o=n.numbering?.id!=null;n.numbering&&dr(a,{numbering:n.numbering});let s=this.#h(a);if(s?.level.paragraph){if(o)dr(a,s.level.paragraph);else{let e=fr(lr);this.#p(e,null,r),dr(e,s.level.paragraph);for(let t of i.chain)dr(e,t.paragraph);e.style=a.style,e.numbering=a.numbering,a=e}}let{style:c,numbering:l,...u}=n;dr(a,u);let d=s?{id:s.instance.id,level:s.index}:null;return{paragraph:{...fr(a),numbering:d},run:pr(i.run),level:s}}numberFormat(e){let t=this.#m(e).level;return t?t.level.format??`decimal`:null}run(e,t){let n=pr(e),r=t.find(e=>e.type===`characterStyle`)?.attrs?.id;if(r){let e=this.#i.get(r);e||(e=this.#l(r,`character`).map(e=>e.run??[]),this.#i.set(r,e)),vr(n,e,this.#n.theme)}return _r(n,t,this.#n.theme),n}#h(e){let t=e.numbering?.id,n=t?this.#a.get(t):void 0,r=n&&this.#_(n.abstract);if(!n||!r)return;let i=e.numbering?.level??r.levels.find(t=>t.style!==void 0&&t.style===e.style)?.level??0,a=this.#g(n,r,i);return a?{instance:n,abstract:r,index:i,level:a}:void 0}#g(e,t,n){return e.overrides?.find(e=>e.level===n)?.definition??t.levels.find(e=>e.level===n)}#_(e){let t=this.#o.get(e);for(let e=0;t?.numStyleLink&&e<8;e++){let e=this.#e.get(t.numStyleLink)?.paragraph?.numbering?.id,n=e?this.#a.get(e):void 0,r=n?this.#o.get(n.abstract):void 0;if(!r||r===t)break;t=r}return t}markers(e){let t=new Map,n=new Set;return e.map(e=>{let{run:r,level:i}=this.#m(e);if(!i)return null;let{instance:a,abstract:o,index:s,level:c}=i,l=t.get(o.id);l||(l=[],t.set(o.id,l));let u=e=>a.overrides?.find(t=>t.level===e)?.start??this.#g(a,o,e)?.start??0,d=`${a.id}:${s}`,f=a.overrides?.find(e=>e.level===s)?.start,p=l[s];f!==void 0&&!n.has(d)?(n.add(d),l[s]=f):l[s]=p===void 0?u(s):p+1;for(let e=s+1;e<9;e++){let t=this.#g(a,o,e)?.restart;(t===void 0||t!==0&&s<t)&&(l[e]=void 0)}let m=e=>e.replace(/%([1-9])/g,(e,t)=>{let n=Number(t)-1,r=c.legal?`decimal`:this.#g(a,o,n)?.format;return br(l[n]??u(n),r)}),h=m(c.text??``),g=pr(r);return _r(g,e.markFormat,this.#n.theme),_r(g,c.run,this.#n.theme),{text:h,plain:m((c.text??``).replace(/\p{L}+/gu,``)).trim(),suffix:c.suffix??`tab`,justification:c.justification??`left`,run:g,instance:a.id,abstract:o.id,level:s}})}},Nr=new Qe(`word`),Pr=class e extends ke{id;comment;previous;index;constructor(e,t,n,r){super(),this.id=e,this.comment=t,this.previous=n,this.index=r}apply(e){return P.ok(e)}invert(){return new e(this.id,this.previous,this.comment,this.index)}map(){return this}};function Fr(e,t){let n=e;for(let e of t){if(!(e instanceof Pr))continue;let t=n.findIndex(t=>t.id===e.id);if(e.previous===null!=t<0)continue;let r=t<0?n:[...n.slice(0,t),...n.slice(t+1)];if(!e.comment)n=r;else{let i=t<0?Math.min(e.index,r.length):t;n=[...r.slice(0,i),e.comment,...r.slice(i)]}}return n}function Ir(e,t,n){let r=Fr(t,e.steps),i=new Map(n.map(e=>[e.id,e]));for(let t of r)i.has(t.id)||(e.step(new Pr(t.id,null,t,r.indexOf(t))),r=Fr(r,e.steps.slice(-1)));return n.forEach((t,n)=>{let i=r.find(e=>e.id===t.id)??null;i===t||i&&JSON.stringify(i)===JSON.stringify(t)||(e.step(new Pr(t.id,t,i,n)),r=Fr(r,e.steps.slice(-1)))}),e}var Lr=class e extends ke{key;before;after;constructor(e,t,n){super(),this.key=e,this.before=t,this.after=n}apply(e){return P.ok(e)}invert(){return new e(this.key,this.after,this.before)}map(){return this}},Rr=class e extends ke{id;before;after;selectionBefore;selectionAfter;constructor(e,t,n,r=null,i=null){super(),this.id=e,this.before=t,this.after=n,this.selectionBefore=r,this.selectionAfter=i}apply(e){return P.ok(e)}invert(){return new e(this.id,this.after,this.before,this.selectionAfter,this.selectionBefore)}map(){return this}merge(t){return t.id!==this.id||!zr(this.after,t.before)?null:new e(this.id,this.before,t.after,this.selectionBefore,t.selectionAfter)}};function zr(e,t){return e===t||!e&&!t||!!e&&!!t&&e.kind===t.kind&&e.noteType===t.noteType&&e.ext===t.ext&&(e.doc===t.doc||e.doc.eq(t.doc))}function Br({doc:e,...t}){return{...t,content:e.toJSON()}}function Vr(e,t,n){let r=t;for(let t of n)t instanceof Lr&&t.key===e&&(r=t.after);return r}function Hr(e,t,n,r){let i=X(e)?.envelope;return i?t.step(new Lr(n,Vr(n,i[n],t.steps),r)):t}function Ur(e,t){let n=new Map,r=new Map;for(let i of t)if(i instanceof Lr){let t=i.key;if(!u(n.has(t)?n.get(t):e.envelope[t],i.before))return!1;n.set(t,i.after)}else if(i instanceof Rr){if(!zr(r.has(i.id)?r.get(i.id):e.stories.get(i.id)??null,i.before))return!1;r.set(i.id,i.after)}return!0}function Wr(e,t,n){let r=X(e)?.stories.get(n)??null;for(let e of t.steps)e instanceof Rr&&e.id===n&&(r=e.after);return r}var Gr=new Qe(`storyBody`),Kr=e=>Gr.getState(e)??null;function qr(e,t,n){let r=X(e),i=n?{...r,envelope:n}:r;return nt.create({doc:t,plugins:[Xr(i.envelope,i)]})}function Jr(e){let t=[...X(e)?.stories.values()??[]].map(e=>e.doc),n=Kr(e)?.state.doc;return(n?[n,...t]:t).filter(t=>t!==e.doc)}function Yr(e){return new Map(Object.entries(e.stories??{}).map(([e,{content:t,...n}])=>[e,{...n,doc:kn(t,`stories[${JSON.stringify(e)}].content`)}]))}function Xr(e,t){let n=`${Date.now().toString(36)}${Math.random().toString(36).slice(2)}`,r=t??{envelope:e,resolver:new Mr(e),stories:Yr(e),id:n};return new $e({key:Nr,state:{init:()=>r,apply:(e,t)=>{let n=e.getMeta(Qr);if(n)return n;let r=e.getMeta(Nr),i=Fr(t.envelope.comments,e.steps),a=r??t.envelope,o=Vr(`section`,a.section,e.steps),s=Vr(`settings`,t.envelope.settings,e.steps),c=Vr(`controls`,a.controls,e.steps),{stories:l}=t,u=t.envelope.stories;for(let t of e.steps){if(!(t instanceof Rr))continue;let e=new Map(l),n={...u};t.after?(e.set(t.id,t.after),n[t.id]=Br(t.after)):(e.delete(t.id),delete n[t.id]),l=e,u=n}if(!r&&i===t.envelope.comments&&o===a.section&&s===t.envelope.settings&&c===t.envelope.controls&&l===t.stories)return t;let{stories:d,settings:f,controls:p,...m}=a,h={...m,section:o,comments:i,...u&&Object.keys(u).length?{stories:u}:{},...s?{settings:s}:{},...c?{controls:c}:{}};return{envelope:h,resolver:r?new Mr(h):t.resolver,stories:l,id:t.id}}}})}function Zr(e,t){return e.setMeta(Nr,t)}var Qr=`adoptWordContext`,$r=(e,t)=>e.setMeta(Qr,t),ei=e=>e.getMeta(Nr);function X(e){return Nr.getState(e)??null}var ti=Object.fromEntries(qe.map(e=>[e,null]));function ni(e){let t;for(let n of e.styles)n.type===`paragraph`&&n.isDefault&&(t=n.id);return t}function ri(e,t,n){let r=t.attrs,i=Object.keys(ti).some(e=>r[e]!==null)?{...r,...ti}:null;if(!n)return{before:i,after:r};let a=r.style??ni(e.envelope),o=e.envelope.styles.find(e=>e.id===a)?.next;return o===void 0||o===a?{before:i,after:r}:{before:i,after:{...Object.fromEntries(Object.keys(ti).map(e=>[e,r[e]??null])),controls:r.controls,style:o}}}var ii={bold:e=>e.bold,italic:e=>e.italic,underline:e=>e.underline!==null,strike:e=>e.strike,doubleStrike:e=>e.doubleStrike,caps:e=>e.caps,smallCaps:e=>e.smallCaps,hidden:e=>e.hidden};function ai(e,t){return e!==null&&Object.hasOwn(ii,t.name)}function oi(e,t,n,r,i=!0){let{run:a}=e.resolver.paragraph(t.attrs),o=n.filter(e=>i||e.type!==r).map(e=>e.toJSON());return ii[r.name](e.resolver.run(a,o))}function si(e,t,n,r){let i=r?.attrs.complexScript??null,a=Object.hasOwn(e.spec.attrs??{},`complexScript`);return t===n?a&&i!==null?e.create({value:null,complexScript:i}):null:e.name===`underline`?e.create({style:t?`single`:`none`}):e.create(a?{value:t,complexScript:i}:{value:t})}function ci(e,t,n,r){let i=[];e.doc.nodesBetween(t,n,(e,t,n)=>{if(e.isInline&&n?.type.allowsMarkType(r))return fi.has(e.type.name)||i.push({node:e,pos:t,parent:n}),!1});let a=i.filter(e=>e.node.isText);return a.length?{all:i,judged:a}:{all:i,judged:i}}function li(e,t,n,r){let{selection:i}=t;if(r)return oi(e,i.$from.parent,r,n);let a=i.ranges.flatMap(e=>ci(t,e.from,e.to,n).judged);return a.length>0&&a.every(t=>oi(e,t.parent,t.node.marks,n))}function ui(e,t,n,r){let i=!oi(e,t,n,r),a=r.isInSet(n),o=a?a.removeFromSet(n):n,s=si(r,i,oi(e,t,n,r,!1),a);return s?s.addToSet(o):o}function di(e,t,n,r,i,a){return ci(t,n,r,i).all.map(({node:t,pos:o,parent:s})=>({from:Math.max(n,o),to:Math.min(r,o+t.nodeSize),mark:si(i,a,oi(e,s,t.marks,i,!1),i.isInSet(t.marks))}))}var fi=new Set([`bookmarkStart`,`bookmarkEnd`,`commentStart`,`commentEnd`,`controlStart`,`controlEnd`,`fieldStart`,`fieldCode`,`fieldSeparator`,`fieldEnd`,`noteMark`,`commentReference`]);function pi(e,t){return e!==null&&!!t&&fi.has(t.type.name)}function mi(e,t){return e!==null&&!!t&&(t.type.name===`opaqueInline`||t.type.name===`opaqueBlock`)}function hi(e,t){let n=e.doc.nodeAt(t);return n&&We.isSelectable(n)?We.create(e.doc,t):R.create(e.doc,t)}var gi=new WeakMap,_i=e=>e.marks.some(e=>e.type.name===`deletion`);function vi(e){let t=gi.get(e);if(t)return t;let n=[],r=[],i=e=>{let t=r[r.length-1];t&&e&&(t.field.separator===null?t.code+=e:(t.broke&&(t.text+=`\r`),t.broke=!1,t.text+=e))};if(e.descendants((e,t)=>{if(e.isTextblock){for(let e of r)e.field.separator!==null&&(e.broke=!0);return!0}if(!e.isInline)return!0;let a=r[r.length-1];switch(e.type.name){case`fieldStart`:r.push({code:``,text:``,broke:!1,field:{from:t,to:t,separator:null,codeEnd:t,resultFrom:t,resultTo:t,instruction:``,name:``,result:``,locked:e.attrs.locked===!0,deleted:_i(e),codeMarks:null,resultMarks:null,parent:a?.field??null,inCode:!!a&&a.field.separator===null}});break;case`fieldCode`:a?.field.separator===null&&(a.code+=String(e.attrs.text??``),a.field.codeMarks??=e.marks);break;case`fieldSeparator`:a?.field.separator===null&&(a.field.separator=t);break;case`fieldEnd`:{let e=r.pop();if(!e)break;let{field:a}=e;a.to=t+1,a.codeEnd=a.separator??t,a.resultFrom=a.separator===null?t:a.separator+1,a.resultTo=t,a.instruction=e.code.trim(),a.name=(/^\S*/.exec(a.instruction)?.[0]??``).toUpperCase(),a.result=e.text,n.push(a),i(e.text);let o=r[r.length-1]?.field;o&&o.separator!==null&&(o.resultMarks??=a.resultMarks);break}case`text`:_i(e)||(i(e.text??``),a&&a.field.separator!==null&&(a.field.resultMarks??=e.marks));break;case`tab`:_i(e)||i(` `);break;case`hardBreak`:_i(e)||i(`
|
|
2
|
-
`)}return!1}),n.sort((e,t)=>e.from-t.from),r.length){let e=new Set(r.map(e=>e.field));for(let t of n)t.parent&&e.has(t.parent)&&(t.parent=null,t.inCode=!1)}return gi.set(e,n),n}function yi(e,t){let n=null;for(let r of vi(e)){if(r.from>=t)break;t<r.to&&(n=r)}return n}function bi(e,t){let n=null;for(let r of vi(e)){if(r.from>t)break;t<r.to&&(n=r)}return n}var xi=e=>!!e&&Si.has(e.type.name),Si=new Set([`fieldStart`,`fieldCode`,`fieldSeparator`,`fieldEnd`]),Ci={hidden:new Set,braces:new Map,gone:!1},wi=new Set([...Si,`bookmarkStart`,`bookmarkEnd`,`commentStart`,`commentEnd`,`commentReference`,`controlStart`,`controlEnd`]);function Ti(e,t){let n=(e,t)=>e*65536+t,r=new Map,i=[];if(e.forEach((e,t)=>{e.forEach((e,a)=>{if(e===`fieldStart`)i.push({at:n(t,a),separator:null});else if(e===`fieldSeparator`){let e=i[i.length-1];e&&e.separator===null&&(e.separator=n(t,a))}else if(e===`fieldEnd`){let e=i.pop();if(!e)return;r.set(e.at,`start`),e.separator!==null&&r.set(e.separator,`separator`),r.set(n(t,a),`end`)}})}),!r.size)return e.map(()=>Ci);let a=[],o=0,s=0,c=()=>t?s>0:o>0;return e.map((e,i)=>{let l=new Set,u=new Map,d=c(),f=!1;e.forEach((e,d)=>{let p=r.get(n(i,d));p===`start`?(t&&!s&&u.set(d,`{`),a.push(`code`),o++):p===`separator`?(o--,t&&!s&&u.set(d,`}`),s++,a[a.length-1]=`result`):p===`end`?a.pop()===`code`?(o--,t&&!s&&u.set(d,`}`)):s--:c()?l.add(d):(!wi.has(e)||t&&e===`fieldCode`)&&(f=!0)});let p=d&&c()&&!f&&!u.size;return l.size||u.size||p?{hidden:l,braces:u,gone:p}:Ci})}var Ei=new Qe(`fields`),Di=e=>Ei.getState(Kr(e)?.state??e)===!0;function Oi(e,t,n){return t>e.from&&(n?t<e.to:t<=e.codeEnd)}function ki(e,t,n,r){let i=t;for(let t=!0;t;){t=!1;for(let a of e)Oi(a,i,r)&&(i=n?r||a.separator===null?a.to:a.separator+1:a.from,t=!0)}return i}function Ai(e,t,n){let r=t;for(let t=!0;t;){t=!1;for(let i of e){if(i.separator===null||r<i.resultFrom||r>i.resultTo)continue;let e=r===i.resultTo&&(r!==i.resultFrom||n);(e||r===i.resultFrom)&&(r=e?i.to:i.from,t=!0)}}return r}function ji(e,t,n){let r=Math.min(t,n),i=Math.max(t,n);if(e.resolve(r).parent!==e.resolve(i).parent)return!1;let a=!1;return e.nodesBetween(r,i,e=>(e.isInline&&!wi.has(e.type.name)&&(a=!0),!a)),!a}function Mi(e,t,n){let{selection:r,doc:i}=e;if(!(r instanceof R))return null;let a=vi(i);if(!a.length)return null;let o=Di(e),s=r.head>=t.head,c=ki(a,r.head,s,o);r.empty&&n&&!o&&(c=Ai(a,c,s));let l=r.empty?c:ki(a,r.anchor,r.anchor>r.head,o);n&&!r.empty&&(!t.empty&&ji(i,c,t.head)&&(c=t.head),ji(i,l,t.anchor)&&(l=t.anchor));let u=(e,t)=>t>e.from&&t<e.to;if(l!==c)for(let e=!0,n=0;e&&n<64;n++){e=!1;for(let n of a)if(!(n.deleted||u(n,l)===u(n,c))){if(e=!0,u(n,l))l=c>n.from?n.from:n.to;else{let[e,r]=l<=n.from?[n.to,n.from]:[n.from,n.to],a=l<=n.from?t.head>=e:t.head<=e;c=!ji(i,c,e)&&a?r:e}}}return l===r.anchor&&c===r.head?null:R.create(i,l,c)}function Ni(){return new $e({key:Ei,state:{init:()=>!1,apply:(e,t)=>e.getMeta(Ei)??t},appendTransaction(e,t,n){if(t.selection.eq(n.selection)&&t.doc===n.doc&&Di(t)===Di(n))return null;let r=Mi(n,t.selection,t.doc===n.doc);return r?n.tr.setSelection(r):null}})}var Pi=(e,t)=>R.create(e,t.from,t.to),Fi=new Qe(`history`),Ii=`historyOp`,Li=`closeHistory`,Ri=`joinHistory`,zi=`storyEdit`,Bi={done:[],undone:[],prevTime:0,prevRanges:null};function Vi({newGroupDelay:e=500,depth:t=100}={}){return new $e({key:Fi,state:{init:()=>Bi,apply(n,r,i){let a=n.getMeta(Fi);if(a)return a;if(!n.docChanged)return r;let o=n.getMeta(`appendedTransaction`),s=o?.getMeta(Ii),c=n.steps.map((e,t)=>e.invert(n.docs[t])).reverse();if(s){let e=s===`undo`?r.undone:r.done,t=e[e.length-1],a=t?[...e.slice(0,-1),{steps:Hi(c,t.steps),selection:t.selection}]:[...e,{steps:c,selection:i.selection.toJSON()}];return s===`undo`?{...r,undone:a,done:Ji(r.done,n.mapping,n.doc)}:{...r,done:a,undone:Ji(r.undone,n.mapping,n.doc)}}if(!n.addToHistory||o&&!o.addToHistory)return{done:Ji(r.done,n.mapping,n.doc),undone:Ji(r.undone,n.mapping,n.doc),prevTime:0,prevRanges:null};let l=r.done[r.done.length-1],u=n.getMeta(zi);return{done:(l!==void 0&&(o!==void 0||n.getMeta(`joinHistory`)===!0||!n.getMeta(`closeHistory`)&&n.time-r.prevTime<e&&(r.prevStory??null)===(u?.id??null)&&Ui(r.prevRanges,u?.tr??n))?[...r.done.slice(0,-1),{steps:Hi(c,l.steps),selection:l.selection}]:[...r.done,{steps:c,selection:i.selection.toJSON()}]).slice(-t),undone:[],prevTime:o?r.prevTime:n.getMeta(`closeHistory`)?0:n.time,prevRanges:o?Gi(r.prevRanges,n.mapping):Wi(u?.tr??n),prevStory:o?r.prevStory??null:u?.id??null}}}})}function Hi(e,t){let n=e[e.length-1],r=t[0],i=n instanceof Ae&&r||n instanceof Rr&&r instanceof Rr?n.merge(r):null;return i?[...e.slice(0,-1),i,...t.slice(1)]:[...e,...t]}function Ui(e,t){let n=t.mapping.maps[0];if(!e||!n)return!1;let r=!1;return n.forEach((t,n)=>{for(let i=0;i<e.length;i+=2)t<=e[i+1]&&n>=e[i]&&(r=!0)}),r}function Wi(e){let t=[];return e.mapping.maps.forEach((n,r)=>{let i=e.mapping.slice(r+1);n.forEach((e,n,r,a)=>{t.push(i.map(r,-1),i.map(a,1))})}),t}function Gi(e,t){return e&&e.map((e,n)=>t.map(e,n%2?1:-1))}var Ki=class{base;inverted=[];rebased=[];constructor(e){this.base=e}push(e,t){this.inverted.push(e.getMap().invert()),this.rebased.push(t?t.getMap():null)}map(e,t=1){return this.mapResult(e,t).pos}mapResult(e,t=1){let n=!1,r=0,i=!1,a=[];for(let o=this.inverted.length-1;o>=0;o--){a[o]=this.inverted[o].sides(e);let s=this.inverted[o].mapResult(e,t),c=this.rebased[o];if(s.recover!==null&&c){e=c.recover(s.recover),r=o+1,i=!0;break}n||=s.deleted,e=s.pos}if(!i){let r=this.base.mapResult(e,t);n||=r.deleted,e=r.pos}for(let i=r;i<this.rebased.length;i++){let r=this.rebased[i]?.mapResult(e,t,a[i]);r&&(n||=r.deleted,e=r.pos)}return{pos:e,deleted:n,recover:null}}};function qi(e,t){let n=e.anchor<=e.head?-1:1,r=e.anchor===e.head?-1:-n;return{...e,anchor:t.map(e.anchor,n),head:t.map(e.head,r)}}function Ji(e,t,n){let r=new Ki(t),i=n,a=[];for(let t=e.length-1;t>=0;t--){let n=e[t],o=[];for(let e of n.steps){let t=e.map(r),n=t?.apply(i),a=n?.doc?t:null;a&&n?.doc&&(i=n.doc,o.push(a)),r.push(e,a)}o.length&&a.unshift({steps:o,selection:qi(n.selection,r)})}return a}function Yi(e,t){if(t instanceof Fe||t instanceof Ie){if(t.from<0||t.to>e.doc.content.size||t.from>=t.to)return!1;try{return t instanceof Fe?e.addMark(t.from,t.to,t.mark):e.removeMark(t.from,t.to,t.mark),!0}catch(e){if(e instanceof F)return!1;throw e}}return e.maybeStep(t).failed===null}function Xi(e){let t=(n,r)=>{let i=Kr(n);if(i)return r?i.run(t):i.can(t);let a=Fi.getState(n),o=a&&(e?a.undone:a.done),s=o?.[o.length-1];if(!a||!o||!s)return!1;if(r){let t=n.tr,i=X(n);if(i&&!Ur(i,s.steps)){let n=o.slice(0,-1);return t.setMeta(Fi,{done:e?a.done:n,undone:e?n:a.undone,prevTime:0,prevRanges:null}),r(t),!0}let c=null;for(let e of s.steps){let n=c?e.map(c):e,r=n!==null&&Yi(t,n);!r&&!c&&(c=new Ki(new Oe)),c?.push(e,r?n:null)}let l=c?qi(s.selection,c):s.selection;t.setSelection(L.fromJSON(t.doc,l));let u={steps:t.steps.map((e,n)=>e.invert(t.docs[n])).reverse(),selection:n.selection.toJSON()},d=o.slice(0,-1),f=u.steps.length?[u]:[];t.setMeta(Fi,{done:e?[...a.done,...f]:d,undone:e?d:[...a.undone,...f],prevTime:0,prevRanges:null}),t.setMeta(Ii,e?`redo`:`undo`),r(t)}return!0};return t}var Zi=Xi(!1),Qi=Xi(!0),$i=e=>e.type.name===`table`;function ea(e){for(let t=e.depth;t>0;t--)if(e.node(t).type.name===`tableCell`)return t;return-1}function ta(e,t){return e.depth>t&&$i(e.node(t+1))?t+1:-1}function na(e,t,n){let r=e.doc,i=r.resolve(t),a=r.resolve(n),o=ea(i),s=ea(a);if(o<0&&s<0||o>=0&&s>=0&&i.before(o)===a.before(s))return!1;let c=i.sharedDepth(n),l=i.node(c).type.name;if(l===`table`||l===`tableRow`)return ia(e,t,n,i.before(c+1),a.after(c+1)),!0;let u=ta(a,c),d=ta(i,c);if(u<0&&d<0)return!1;let f=n;if(u>=0){let t=a.node(u),n=a.before(u),r=a.index(u);if(r===t.childCount-1)e.delete(n,n+t.nodeSize);else{let i=n+1;for(let e=0;e<=r;e++)i+=t.child(e).nodeSize;e.delete(n+1,i)}f=n}let p=t,m=null;if(d>=0){let e=i.node(d),t=i.before(d),n=t+e.nodeSize,r=i.index(d);if(r===0)m=[t,n];else{let i=t+1;for(let t=0;t<r;t++)i+=e.child(t).nodeSize;m=[i,n-1]}p=n}return p<f&&ra(e,p,f),m&&e.delete(m[0],m[1]),!0}function ra(e,t,n){let r=e.doc.resolve(t),i=e.doc.resolve(n),a=[],o=t,s=n;r.parent.inlineContent&&(a.push([t,r.end()]),o=r.after()),i.parent.inlineContent&&(a.push([i.start(),n]),s=i.before()),o<s&&a.push([o,s]);for(let[t,n]of a.sort((e,t)=>t[0]-e[0]))t<n&&e.delete(t,n)}function ia(e,t,n,r,i){let a=[];e.doc.nodesBetween(r,i,(e,o)=>{let s=o>=r&&o+e.nodeSize<=i;return e.type.name!==`tableCell`||!s||(o<n&&o+e.nodeSize>t&&a.push({pos:o,node:e}),!1)}),aa(e,a.map(e=>e.pos))}function aa(e,t){for(let n of[...t].sort((e,t)=>t-e)){let t=e.doc.nodeAt(n);if(t?.type.name!==`tableCell`)continue;let r=!0;if(t.forEach(e=>{e.type.name!==`paragraph`&&(r=!1)}),r){let r=n+2,i=n+t.nodeSize-2;r<i&&e.delete(r,i);continue}let i=t.type.schema.nodes.paragraph?.create();i&&e.replace(n+1,n+t.nodeSize-1,new w(f.from(i),0,0))}}function oa(e){let t=e.doc.type.schema.nodes.paragraph;if(!t)return;let n=[],r=(e,t)=>{let i=t;e.forEach((t,a,o)=>{if($i(t)){let a=e.maybeChild(o+1);(a?$i(a):e.type.name===`doc`)&&n.push(i+t.nodeSize);let s=i+1;t.forEach(e=>{let t=s+1;e.forEach(e=>{r(e,t+1),t+=e.nodeSize}),s+=e.nodeSize})}i+=t.nodeSize})};r(e.doc,0);for(let r of n.reverse())e.insert(r,t.create())}function sa(e){let t=e.selection.$head,n=ea(t);return n<0?null:{$pos:t,depth:n}}function ca(e,t){let n=[],r=t+1;return e.forEach(e=>{let t=r+1;e.forEach(e=>{e.attrs.vMerge!==`continue`&&n.push(t),t+=e.nodeSize}),r+=e.nodeSize}),n}function la(e,t){let n=e.doc.nodeAt(t),r=L.near(e.doc.resolve(t+1),1).from,i=L.near(e.doc.resolve(t+n.nodeSize-1),-1).to;e.setSelection(R.create(e.doc,r,Math.max(r,i)))}function ua(e){return(t,n)=>{let r=sa(t);if(!r)return!1;let{$pos:i,depth:a}=r,o=a-2,s=i.node(o),c=i.before(o),l=ca(s,c),u=l[l.indexOf(i.before(a))+e];if(u!==void 0){if(n){let e=t.tr;la(e,u),n(e)}return!0}if(e<0)return!0;let d=da(s.lastChild);if(!d)return!1;let f=c+s.nodeSize-1;return I(t,n,e=>{e.insert(f,d),e.setSelection(R.create(e.doc,f+3))})}}function da(e){let t=e.type.schema.nodes.paragraph;if(!t)return null;let n={...e.attrs,revision:null,header:null,attributes:null},r=Object.fromEntries(qe.map(e=>[e,null])),i=[];return e.forEach(e=>{let n=e.firstChild,a=n?.type===t?{...n.attrs,...r}:null;i.push(e.type.create({...e.attrs,vMerge:null},t.create(a)))}),e.type.create(n,i)}function fa(){return new $e({keymap:{Tab:ua(1),"Shift-Tab":ua(-1)}})}function pa(e,t){let n=[],r=new Map,i=t+1;return e.forEach((e,t,a)=>{let o=e.attrs.gridBefore??0,s=i+1;e.forEach(e=>{let t=e.attrs.gridSpan??1,i=r.get(o);if(e.attrs.vMerge===`continue`&&i&&i.row+i.rowSpan===a)i.rowSpan++;else{let i={pos:s,row:a,rowSpan:1,column:o,span:t};n.push(i),e.attrs.vMerge===`restart`?r.set(o,i):r.delete(o)}o+=t,s+=e.nodeSize}),i+=e.nodeSize}),n}var ma=class e extends L{cells;constructor(e,t){super(e,t),this.cells=_a(e,t)}static create(t,n,r=n){return new e(t.resolve(n),t.resolve(r))}static valid(e,t,n){let r=e.resolve(t),i=e.resolve(n);return r.nodeAfter?.type.name===`tableCell`&&i.nodeAfter?.type.name===`tableCell`&&r.depth===i.depth&&r.before(r.depth-1)===i.before(i.depth-1)}get from(){return this.cells[0]??this.anchor}get to(){let e=this.cells[this.cells.length-1]??this.head;return e+(this.$head.doc.nodeAt(e)?.nodeSize??0)}get empty(){return!1}get ranges(){let e=this.$head.doc;return this.cells.map(t=>({from:t+1,to:t+(e.nodeAt(t)?.nodeSize??2)-1}))}map(t,n){let r=n.mapResult(this.anchor,1),i=n.mapResult(this.head,1);return!r.deleted&&!i.deleted&&e.valid(t,r.pos,i.pos)?e.create(t,r.pos,i.pos):L.near(t.resolve(Math.min(i.pos,t.content.size)))}toJSON(){return{type:`cell`,anchor:this.anchor,head:this.head}}};function ha(e,t,n,r){let i=t+1;for(let t=0;t<e.childCount;t++){let a=e.child(t),o=a.attrs.gridBefore??0,s=i+1;for(let e=0;e<a.childCount;e++){let i=a.child(e);if(s===r)return ga(n,t,o);o+=i.attrs.gridSpan??1,s+=i.nodeSize}i+=a.nodeSize}}var ga=(e,t,n)=>e.find(e=>e.row<=t&&t<e.row+e.rowSpan&&e.column<=n&&n<e.column+e.span);function _a(e,t){let n=e.depth-1,r=e.node(n),i=e.before(n),a=pa(r,i),o=e=>a.find(t=>t.pos===e)??ha(r,i,a,e),s=o(e.pos),c=o(t.pos);if(!s||!c)return[e.pos];let l=Math.min(s.row,c.row),u=Math.max(s.row+s.rowSpan,c.row+c.rowSpan)-1,d=Math.min(s.column,c.column),f=Math.max(s.column+s.span,c.column+c.span)-1,p=e=>e.row<=u&&e.row+e.rowSpan-1>=l&&e.column<=f&&e.column+e.span-1>=d;for(let e=!0;e;){e=!1;for(let t of a){if(!p(t))continue;let n=[Math.min(l,t.row),Math.max(u,t.row+t.rowSpan-1),Math.min(d,t.column),Math.max(f,t.column+t.span-1)];(n[0]!==l||n[1]!==u||n[2]!==d||n[3]!==f)&&([l,u,d,f]=n,e=!0)}}return a.filter(p).map(e=>e.pos)}L.kinds.set(`cell`,(e,t)=>{let n=t=>Math.max(0,Math.min(t,e.content.size)),r=n(t.anchor),i=n(t.head);return ma.valid(e,r,i)?ma.create(e,r,i):L.near(e.resolve(i))});var va=e=>JSON.stringify(e??null);function ya(e){let t=[];for(let{from:n,to:r}of e.selection.ranges)e.doc.nodesBetween(n,r,(e,n)=>e.type.name!==`paragraph`||(t.push({node:e,pos:n}),!1));return t}function ba(e,t,n,r){let i=ya(e).flatMap(({node:e,pos:t})=>{let r=n(e);return r&&va(r)!==va(e.attrs)?[new Le(t,e.type,r)]:[]});return i.length?I(e,t,e=>{e.step(new ze(i)),r&&Zr(e,r)}):!1}function xa(e){let[t]=e;return t!==void 0&&e.every(e=>va(e)===va(t))?t:null}function Sa(e,t,n=`paragraph`){let r=t.toLowerCase();return e.envelope.styles.find(e=>e.type===n&&e.name?.toLowerCase()===r)?.id??null}function Ca(e,t=`paragraph`){let n=null;for(let r of e.envelope.styles)r.type===t&&r.isDefault&&(n=r.id);return n}var wa=e=>/^Heading[1-9]$/.test(e)?`heading ${e.slice(7)}`:e===`ListParagraph`?`List Paragraph`:null;function Ta(e,t){let n=Ca(e),r=n?{basedOn:n}:{},i=/^heading ([1-9])$/.exec(t)?.[1];if(i){let e=Number(i),a=e>=8?{value:`272727`,themeColor:`text1`,themeTint:`D8`}:{...[3,6,7].includes(e)?{value:`1F3763`,themeShade:`7F`}:{value:`2F5496`,themeShade:`BF`},themeColor:`accent1`},o=[32,26,24,0,0,0,0,21,21][e-1];return{id:`Heading${e}`,type:`paragraph`,name:t,...r,...n?{next:n}:{},paragraph:{keepNext:!0,keepLines:!0,spacing:{before:e===1?240:40,after:0},outlineLevel:e-1},run:[{type:`font`,attrs:{asciiTheme:`majorHAnsi`,eastAsiaTheme:`majorEastAsia`,hAnsiTheme:`majorHAnsi`,csTheme:`majorBidi`}},...[4,7,9].includes(e)?[{type:`italic`,attrs:{complexScript:!0}}]:[],{type:`color`,attrs:a},...o?[{type:`fontSize`,attrs:{value:o,complexScript:o}}]:[]]}}let a=/^toc ([1-9])$/.exec(t)?.[1];if(a){let i=e.envelope.defaults.run?.find(e=>e.type===`fontSize`)?.attrs?.value,o=(Number(a)-1)*(typeof i==`number`?i*10:220);return{id:`TOC${a}`,type:`paragraph`,name:t,...r,...n?{next:n}:{},paragraph:{spacing:{after:100},...o?{indent:{left:o}}:{}}}}if(t===`List Paragraph`)return{id:`ListParagraph`,type:`paragraph`,name:t,...r,paragraph:{indent:{left:720},contextualSpacing:!0}};if(t===`Table Grid`){let n={style:`single`,size:4,space:0,color:`auto`},r=Sa(e,`Normal Table`,`table`);return{id:`TableGrid`,type:`table`,name:t,...r?{basedOn:r}:{},paragraph:{spacing:{after:0,line:240,lineRule:`auto`}},table:{borders:{top:n,left:n,bottom:n,right:n,insideH:n,insideV:n}}}}let o=/^(foot|end)note (text|reference)$/.exec(t),s=/^(Foot|End)note Text Char$/.exec(t);if(o||s){let n=Ca(e,`character`),i=n?{basedOn:n}:{},a={type:`fontSize`,attrs:{value:20,complexScript:20}},c=(o?.[1]??s?.[1]??``).toLowerCase()===`foot`?`Footnote`:`Endnote`;return s?{id:`${c}TextChar`,type:`character`,name:t,...i,link:`${c}Text`,run:[a]}:o?.[2]===`reference`?{id:`${c}Reference`,type:`character`,name:t,...i,run:[{type:`verticalAlign`,attrs:{value:`superscript`}}]}:{id:`${c}Text`,type:`paragraph`,name:t,...r,link:`${c}TextChar`,paragraph:{spacing:{after:0,line:240,lineRule:`auto`}},run:[a]}}if(t===`Placeholder Text`){let n=Ca(e,`character`);return{id:`PlaceholderText`,type:`character`,name:t,...n?{basedOn:n}:{},run:[{type:`color`,attrs:{value:`666666`}}]}}if(t===`Hyperlink`){let n=Ca(e,`character`);return{id:`Hyperlink`,type:`character`,name:t,...n?{basedOn:n}:{},run:[{type:`color`,attrs:{value:`0563C1`,themeColor:`hyperlink`}},{type:`underline`,attrs:{style:`single`}}]}}return null}function Ea(e,t,n=`paragraph`){let{envelope:r}=e,i=Sa(e,t,n);if(i)return{id:i,envelope:r};let a=Ta(e,t);if(!a)return null;let o=new Set(r.styles.map(e=>e.id)),s=a.id;for(let e=1;o.has(s);e++)s=`${a.id}${e}`;return{id:s,envelope:{...r,styles:[...r.styles,{...a,id:s}]}}}function Da(e){return(t,n)=>{let r=X(t);if(!r)return!1;if(r.envelope.styles.some(t=>t.id===e&&t.type===`paragraph`))return ka(t,n,r,{id:e,envelope:r.envelope});let i=wa(e);return!!i&&Oa(i)(t,n)}}function Oa(e){return(t,n)=>{let r=X(t),i=r&&Ea(r,e);return!!i&&ka(t,n,r,i)}}function ka(e,t,n,r){let i=r.id===Ca(n)?null:r.id;return ba(e,t,e=>({...e.attrs,style:i}),r.envelope===n.envelope?void 0:r.envelope)}function Aa(e,t){let n=X(e),r=[];for(let{from:i,to:a}of e.selection.ranges)e.doc.nodesBetween(i,a,(e,i,a)=>{if(e.isInline&&a?.type.allowsMarkType(t))return pi(n,e)||r.push({node:e,pos:i,parent:a}),!1});return r}function ja(e,t,n,r){let{run:i}=e.resolver.paragraph(t.attrs);return e.resolver.run(i,n.filter(e=>e.type!==r).map(e=>e.toJSON()))}function Ma(e,t){return(n,r)=>{let i=X(n),a=n.schema.marks[e];if(!i||!a)return!1;let{selection:o}=n;if(o.empty&&o instanceof R){let{$from:e}=o;if(!e.parent.type.allowsMarkType(a))return!1;let s=n.storedMarks??Ke(e),c=t(a.isInSet(s),ja(i,e.parent,s,a),a),l=a.removeFromSet(s);return r?.(n.tr.setStoredMarks(c?c.addToSet(l):l)),!0}let s=Aa(n,a);return s.length?I(n,r,e=>{for(let{node:n,pos:r,parent:c}of s){let s=Math.max(o.from,r),l=Math.min(o.to,r+n.nodeSize),u=a.isInSet(n.marks),d=t(u,ja(i,c,n.marks,a),a);(d?u?.eq(d):!u)||(e.removeMark(s,l,a),d&&e.addMark(s,l,d))}}):!1}}var Na=e=>e.slice(1).toUpperCase(),Pa={black:`#000000`,blue:`#0000ff`,cyan:`#00ffff`,green:`#00ff00`,magenta:`#ff00ff`,red:`#ff0000`,yellow:`#ffff00`,white:`#ffffff`,darkBlue:`#000080`,darkCyan:`#008080`,darkGreen:`#008000`,darkMagenta:`#800080`,darkRed:`#800000`,darkYellow:`#808000`,darkGray:`#808080`,lightGray:`#c0c0c0`};function Fa(e){return Ma(`color`,(t,n,r)=>e===null?n.color===null?null:r.create({value:`auto`}):n.color===Na(e)?null:r.create({value:Na(e)}))}function Ia(e){return(t,n)=>{let r=e?Object.keys(Pa).find(t=>Pa[t]===e.toLowerCase()):void 0;if(e===null||r){let e=Ma(`highlight`,(e,t,n)=>r?t.highlight===r?null:n.create({value:r}):t.highlight===null?null:n.create({value:`none`}));return r?e(t,n):Ra(t,n,[e,Ma(`shading`,e=>e?.attrs.pattern===`clear`&&e.attrs.color===`auto`?null:e??null)])}return Ra(t,n,[La(`highlight`),Ma(`shading`,(t,n,r)=>r.create({pattern:`clear`,color:`auto`,fill:Na(e)}))])}}function La(e){return Ma(e,()=>null)}function Ra(e,t,n){let r=e,i=null;for(let e of n)e(r,e=>{if(!i)i=e;else{for(let t of e.steps)i.step(t);e.storedMarks!==r.storedMarks&&i.setStoredMarks(e.storedMarks)}r=r.apply(e)});return i?(t?.(i),!0):!1}var za={start:`left`,center:`center`,end:`right`,justify:`both`};function Ba(e){return e===null||e===`left`||e===`start`?`start`:e===`center`?`center`:e===`right`||e===`end`?`end`:e===`both`||e===`distribute`?`justify`:null}function Va(e,t,n,r,i){let a={...t.attrs,[n]:null},o=e.resolver.paragraph(a).paragraph;return i(o)?a:{...t.attrs,[n]:r}}function Ha(e){return(t,n)=>{let r=X(t);return r?ba(t,n,t=>Va(r,t,`justification`,za[e],t=>Ba(t.justification)===e)):!1}}var Ua=720;function Wa(e){return(t,n)=>{let r=X(t);return r?ba(t,n,t=>{let{paragraph:n}=r.resolver.paragraph(t.attrs);if(n.numbering){let{id:i}=n.numbering,a=n.numbering.level+e;if(a<0)return qa(r,t);let o=Za(r,i,a);if(!o)return null;let s=o.style;return s&&r.envelope.styles.some(e=>e.id===s)?{...t.attrs,style:s,numbering:t.attrs.numbering?{id:i,level:a}:null}:{...t.attrs,numbering:{id:i,level:a}}}let i=n.indent.left,a=e>0?(Math.floor(i/Ua)+1)*Ua:(Math.ceil(i/Ua)-1)*Ua;if(a<0||a>31680)return null;let o=t.attrs.indent??{};return{...t.attrs,indent:{...o,left:a}}}):!1}}function Ga(e,t){let n=e.resolver.numberFormat(t);return n===null||n===`none`?null:n===`bullet`?`bulletList`:`orderedList`}function Ka(e){let t=X(e);if(!t)return null;let n=ya(e).map(({node:e})=>Ga(t,e.attrs));return n.length?xa(n):null}function qa(e,t){let n={...t.attrs,numbering:null},r=e.resolver.paragraph(n).paragraph.numbering!==null,i=Sa(e,`List Paragraph`),a=i!==null&&t.attrs.style===i?null:t.attrs.style;return{...n,style:a,numbering:r?{id:0}:null}}function Ja(e){let t=[[``,`Symbol`],[`o`,`Courier New`],[``,`Wingdings`]],n=[`decimal`,`lowerLetter`,`lowerRoman`];return Array.from({length:9},(r,i)=>{let a={indent:{left:Ua*(i+1),hanging:360}};if(e===`bulletList`){let[e,n]=t[i%3];return{level:i,start:1,format:`bullet`,text:e,justification:`left`,paragraph:a,run:[{type:`font`,attrs:{ascii:n,hAnsi:n,hint:`default`}}]}}return{level:i,start:1,format:n[i%3],text:`%${i+1}.`,justification:i%3==2?`right`:`left`,paragraph:i%3==2?{indent:{left:Ua*(i+1),hanging:180}}:a}})}var Ya=e=>!e.styleLink&&!e.numStyleLink&&!e.levels.some(e=>e.style);function Xa(e,t){let{abstracts:n,instances:r}=e.envelope.numbering;return n.find(e=>e.id===r.find(e=>e.id===t)?.abstract)}function Za(e,t,n){return Xa(e,t)?.levels.find(e=>e.level===n)}function Qa(e,t){let n=Xa(e,t);return!!n&&Ya(n)}function $a(e,t){let{abstracts:n,instances:r}=e.numbering,i=e=>e.levels.find(e=>e.level===0)?.format,a=t===`bulletList`?r.find(e=>{let t=n.find(t=>t.id===e.abstract);return t&&Ya(t)&&i(t)===`bullet`&&!e.overrides?.length}):void 0;if(a)return{id:a.id,envelope:e};let o=e=>Math.max(0,...e)+1,s=n.find(e=>Ya(e)&&i(e)===(t===`bulletList`?`bullet`:`decimal`)),c=[];s||(s={id:Math.max(-1,...n.map(e=>e.id))+1,multiLevelType:`hybridMultilevel`,levels:Ja(t)},c.push(s));let l={id:o(r.map(e=>e.id)),abstract:s.id,...t===`orderedList`?{overrides:[{level:0,start:1}]}:{}};return{id:l.id,envelope:{...e,numbering:{abstracts:[...n,...c],instances:[...r,l]}}}}function eo(e){return(t,n)=>{let r=X(t);return!r||!ya(t).length?!1:Ka(t)===e?ba(t,n,e=>qa(r,e)):to(e)(t,n)}}function to(e){return(t,n)=>{let r=X(t);if(!r)return!1;let i=ya(t),a=i[0];if(!a)return!1;let o=a.pos>0?t.doc.resolve(a.pos).nodeBefore:null,s=o?.attrs.numbering?.id,c=Ca(r),l=e=>{let t=r.resolver.paragraph(e.attrs).paragraph.style;return t===c||t===null},u=i.some(({node:e})=>l(e))?Ea(r,`List Paragraph`):null,d=u?.id??null,f=u?.envelope??r.envelope,p;return s&&o&&Ga(r,o.attrs)===e&&Qa(r,s)?p=s:{id:p,envelope:f}=$a(f,e),ba(t,n,e=>{let t=r.resolver.paragraph(e.attrs).paragraph.numbering?.level??0,n=d&&l(e)?d:e.attrs.style;return{...e.attrs,style:n,numbering:{id:p,level:t}}},f===r.envelope?void 0:f)}}function no(e,t,n){let{selection:r}=e;if(!r.empty)return null;let{$from:i}=r;return i.parent.type.name!==`paragraph`||n&&i.parentOffset>0?null:t.resolver.paragraph(i.parent.attrs).paragraph.numbering?i.parent:null}var ro=(e,t)=>{let n=X(e);return!n||ya(e).length<2&&!no(e,n,!0)?!1:Wa(1)(e,t)},io=(e,t)=>{let n=X(e);return n?ya(e).some(({node:e})=>n.resolver.paragraph(e.attrs).paragraph.numbering)&&Wa(-1)(e,t):!1},ao=(e,t)=>{let n=X(e),r=n&&no(e,n,!0);return!n||!r||r.content.size?!1:Wa(-1)(e,t)},oo=(e,t)=>{let n=X(e),r=n&&no(e,n,!0);return!n||!r?!1:ba(e,t,e=>{let{indent:t}=n.resolver.paragraph(e.attrs).paragraph;return{...qa(n,e),indent:{left:t.left,right:t.right,firstLine:0}}})};function so(e,t,n,r){let i=X(t),a=t.schema.marks.characterStyle,o=i&&a&&Ea(i,`Hyperlink`,`character`);i&&a&&o&&(e.addMark(n,r,a.create({id:o.id})),o.envelope!==i.envelope&&Zr(e,o.envelope))}function co(e,t,n,r){let i=X(t),a=t.schema.marks.characterStyle,o=i&&Sa(i,`Hyperlink`,`character`);o&&a&&e.doc.nodesBetween(n,r,(t,i)=>{a.isInSet(t.marks)?.attrs.id===o&&e.removeMark(Math.max(n,i),Math.min(r,i+t.nodeSize),a)})}var lo=/^[^\s@/:]+@[^\s@/:]+\.\p{L}{2,}$/iu,uo=/^(?:www\.|(?:[\p{L}\p{N}-]+\.)+\p{L}{2,}(?:[:/?#]|$))/iu;function fo(e){let t=e.trim().replace(/\\/g,`/`).replace(/ /g,`%20`);return lo.test(t)?`mailto:${t}`:uo.test(t)?`https://${t}`:t}var po=e=>e.schema.marks.link;function mo(e,t){let n=e.parent;if(!n.inlineContent)return null;let r=e.index();for(let i of e.textOffset?[r]:[r-1,r]){let r=t.isInSet(n.maybeChild(i)?.marks??[]);if(!r)continue;let a=i,o=i+1;for(;a>0&&r.isInSet(n.child(a-1).marks);)a--;for(;o<n.childCount&&r.isInSet(n.child(o).marks);)o++;let s=e.start(),c=s;for(let e=0;e<o;e++){let t=n.child(e).nodeSize;e<a&&(s+=t),c+=t}return{from:s,to:c,mark:r}}return null}function ho(e,t){let{selection:n}=e;if(n.empty){let{parent:e}=n.$from;return e.inlineContent&&e.type.allowsMarkType(t)}let r=!1;for(let{from:i,to:a}of n.ranges)e.doc.nodesBetween(i,a,e=>(e.isTextblock&&e.type.allowsMarkType(t)&&(r=!0),!r));return r}function go(e,t){return(n,r)=>{let i=po(n),a=fo(e),o=t??a,{selection:s}=n;if(!i||!o||!le(a)||s instanceof ma||!(s instanceof Ge)&&!ho(n,i))return!1;let c=i.create({href:a});return I(n,r,e=>{let t=n.storedMarks??Ke(s.$from);e.deleteSelection();let r=e.selection.from,a=e.doc.resolve(r).parent;if(!a.inlineContent||!a.type.allowsMarkType(i))throw new F(`No link here`);let l=t.filter(e=>a.type.allowsMarkType(e.type));e.insertText(o,r,r,c.addToSet(l)),so(e,n,r,r+o.length),e.setSelection(R.create(e.doc,r+o.length))})}}function _o(e){return(t,n)=>{let r=po(t),i=fo(e);if(!r||!le(i)||!ho(t,r))return!1;let a=r.create({href:i}),{selection:o}=t;if(!o.empty)return I(t,n,e=>{for(let{from:n,to:r}of o.ranges)e.addMark(n,r,a),so(e,t,n,r)});let s=mo(o.$from,r);return s?I(t,n,e=>e.addMark(s.from,s.to,a)):go(i)(t,n)}}var vo=(e,t)=>{let n=po(e);if(!n)return!1;let{selection:r}=e,i=r.empty&&mo(r.$from,n),a=r.empty?i?[i]:[]:r.ranges;return a.length?I(e,t,t=>{for(let r of a)t.removeMark(r.from,r.to,n),co(t,e,r.from,r.to)}):!1},yo=`linkEditorRequest`,bo=(e,t)=>{let n=po(e);return!n||!ho(e,n)?!1:(t?.(e.tr.setMeta(yo,!0)),!0)},xo=new Qe(`track`),So=`untracked`,Co=`trackedDeletes`,wo=new Set([`bookmarkStart`,`bookmarkEnd`,`commentStart`,`commentEnd`,`controlStart`,`controlEnd`]),To=new Set(cn),Eo=new Set([`markFormat`,`ext`]),Do=dn.filter(e=>!Eo.has(e)),Oo=e=>Object.fromEntries(Do.filter(t=>e[t]!=null).map(t=>[t,e[t]])),ko=(e,t)=>Do.every(n=>u(e[n]??null,t[n]??null));function Ao(e){return new $e({key:xo,state:{init:()=>e,apply:(e,t)=>e.getMeta(xo)??t}})}function jo(e){return xo.getState(e)??null}var Mo=(e,t)=>e.setMeta(xo,t);function No(e,t){return(n,r)=>{let i=xo.getState(n);return!i||!n.schema.marks.insertion?!1:(r?.(n.tr.setMeta(xo,{...i,on:e,author:t??i.author})),!0)}}function Po(e){return(t,n)=>{let r=xo.getState(t);return!r||!t.schema.marks.insertion?!1:(n?.(t.tr.setMeta(xo,{...r,view:e})),!0)}}function Fo(){return new Date().toISOString().replace(/\.\d+Z$/,`Z`)}var Io=new Set([`insertion`,`deletion`,`formatChange`]);function Lo(e){let t=-1,n=e=>{let n=e?.id;typeof n==`number`&&n>t&&(t=n)};return e.descendants(e=>{for(let t of e.marks)Io.has(t.type.name)&&n(t.attrs);if(e.isTextblock){let t=e.attrs.revision;n(t?.insertion),n(t?.deletion),n(e.attrs.formatChange),n(e.attrs.section?.change)}return!0}),t}function Ro(e){let t=X(e)?.envelope,n=t?.comments??[],r=t?.section,i=-1,a=e=>{let t=e?.id;typeof t==`number`&&t>i&&(i=t)};a(r?.change);for(let t of[e.doc,...Jr(e)])i=Math.max(i,Lo(t));let o=e=>{if(Array.isArray(e))e.forEach(o);else if(e&&typeof e==`object`){let t=e;Io.has(t.type)&&a(t.attrs),t.type===`paragraph`&&a(t.attrs?.formatChange);let n=t.revision;n&&typeof n==`object`&&(a(n.insertion),a(n.deletion)),Object.values(t).forEach(o)}};return o(n.map(e=>e.content)),i}function zo(e){return Ro(e)+1}function Bo(e){let t=e.mapping.maps,n=[];t.forEach((r,i)=>{if(!r.ranges.length)return;let a=new Oe(t.slice(0,i).map(e=>e.invert()).reverse()),o=e.mapping.slice(i+1);r.forEach((e,t,r,i)=>{let s=a.map(e,-1),c=o.map(r,-1);n.push({a:s,b:Math.max(s,a.map(t,1)),c,d:Math.max(c,o.map(i,1))})})}),n.sort((e,t)=>e.a-t.a);let r=[];for(let e of n){let t=r[r.length-1];t&&e.a<=t.b?(t.b=Math.max(t.b,e.b),t.c=Math.min(t.c,e.c),t.d=Math.max(t.d,e.d)):r.push({...e})}return r}function Vo(e,t){let n=xo.getState(e),{insertion:r,deletion:i}=e.schema.marks;if(!n?.on||!r||!i||!t.docChanged||t.getMeta(`untracked`)||t.getMeta(`historyOp`)||!t.addToHistory)return t;try{return Ho(e,t,n.author,r,i)}catch(e){if(e instanceof F)return null;throw e}}function Ho(e,t,n,r,i){let a=e.tr.copyMeta(t);a.setMeta(Co,Bo(t).filter(e=>e.b>e.a).map(e=>[e.a,e.b]));let o=Fo(),s=-1,c=()=>(s<0&&(s=Math.max(Ro(e)+1,t.getMeta(`revisionFloor`)??0)),s++),l=(e,t)=>a.mapping.slice(e.step).map(e.pos,t),d=e=>({pos:e,step:a.steps.length}),f=[],p=[],m=[],h=[],g=(e,t,o)=>{let s=a.doc;for(let a of[s.resolve(t).nodeBefore,s.resolve(o).nodeAfter]){let t=a&&e.isInSet(a.marks),o=e===r?i:r;if(t&&t.attrs.author===n&&!o.isInSet(a.marks))return t}},_=e=>({id:e.attrs.id,author:n,date:e.attrs.date??o}),v=(e,t,s)=>{let u=a.doc,h=a.steps.length,v,y=()=>v??=g(i,e,t)??i.create({id:c(),author:n,date:o}),b=[],x=[],S=[],C=new Map,w=null,ee=!1,te=[];u.nodesBetween(e,t,(a,o)=>{if(a.isTextblock){let r=o+a.nodeSize,c=w??o,l=a.attrs.revision,m=e<r&&t>r||e<=o&&t>=r&&(s||!!u.resolve(r).nodeAfter);return m&&!l?.deletion&&l?.insertion?.author===n&&u.resolve(r).nodeAfter?.isTextblock?(b.push([r-1,r+1]),w===null&&(ee=!1,a.forEach((t,n)=>{!wo.has(t.type.name)&&!i.isInSet(t.marks)&&o+1+n<e&&(ee=!0)})),w=c,!0):(w!==null&&te.push({at:d(w),node:a,live:ee}),w=null,m&&p.push(d(c)),m&&!l?.deletion&&f.push({at:d(c),kind:`deletion`,revision:_(y())}),!0)}if(a.type.name===`tableRow`&&e<=o&&t>=o+a.nodeSize){let e=a.attrs.revision;if(e?.insertion?.author===n&&!e.deletion){let e=u.resolve(o).before();C.set(e,[...C.get(e)??[],[o,o+a.nodeSize]])}else e?.deletion||S.push({pos:o,node:a});return!1}if([`table`,`tableRow`,`tableCell`].includes(a.type.name))return!0;if(!a.isInline)throw new F(`This content cannot be deleted as a tracked change`);let c=Math.max(o,e),l=Math.min(o+a.nodeSize,t);if(c>=l||wo.has(a.type.name)||i.isInSet(a.marks))return!1;let m=r.isInSet(a.marks);return(m&&m.attrs.author===n?b:x).push([c,l]),!1});for(let[e,t]of C){let n=u.nodeAt(e);n&&t.length===n.childCount?b.push([e,e+n.nodeSize]):b.push(...t)}for(let[e,t]of Uo(x))a.addMark(e,t,y());for(let{pos:e,node:t}of S){let n=t.attrs.revision??{},r=_(y());a.step(new Le(e,t.type,{...t.attrs,revision:{...n,deletion:r}},t.marks))}for(let[e,t]of Uo(b).reverse())a.delete(e,t);for(let{at:e,node:t,live:r}of te){let i=l(e,1),s=a.doc.nodeAt(i);if(!s?.isTextblock)continue;if(!r){a.step(new Le(i,t.type,t.attrs,s.marks)),m.push(d(i));continue}let u={...s.attrs};for(let e of qe)u[e]=t.attrs[e]??null;let f=t.attrs.revision;!u.formatChange&&f?.insertion?.author!==n&&!ko(u,t.attrs)&&(u.formatChange={id:c(),author:n,date:o,previous:Oo(t.attrs)});let p=u.formatChange;p?.author===n&&ko(u,p.previous)&&(u.formatChange=null),a.step(new Le(i,s.type,u,s.marks)),m.push(d(i))}let T=a.mapping.slice(h);return{start:d(T.map(e,-1)),end:d(T.map(t,1))}},y=Bo(t),b=[];for(let s of[...y].reverse()){let l=t.doc.slice(s.c,s.d),u=l.content.firstChild,p=s.a===0&&s.b===e.doc.content.size&&!l.openStart&&l.content.childCount===1&&u?.isTextblock&&!u.content.size,{start:m,end:y}=s.a<s.b?v(s.a,s.b,l.size>0&&!p):{start:d(s.a),end:d(s.a)},x=null,S=y.pos;if(l.size&&!p){let e=a.doc.resolve(S).parent,t=g(r,S,S)??r.create({id:c(),author:n,date:o}),s=Wo(l.content,t,r,i);a.replace(S,S,new w(s,l.openStart,l.openEnd)),x=d(S);let u=l.size,p=[];a.doc.nodesBetween(S,S+u,(e,n)=>{if(e.type.name===`tableRow`&&n>=S&&n+e.nodeSize<=S+u&&p.push(n),!e.isTextblock)return!e.isInline;let r=n+e.nodeSize-1;return r>=S&&r<S+u&&f.push({at:d(n),kind:`insertion`,revision:_(t)}),!1});for(let e of p){let n=a.doc.nodeAt(e);if(!n)continue;let r=n.attrs.revision??{};r.insertion||a.step(new Le(e,n.type,{...n.attrs,revision:{...r,insertion:_(t)}},n.marks))}let m=a.doc.resolve(S+u);l.openEnd&&e.isTextblock&&m.parent.isTextblock&&m.depth>0&&h.push({at:d(m.before()),host:e})}b.unshift({range:s,start:m,end:y,inserted:x})}let x=(e,t)=>{let n=0;for(let{range:r,start:i,end:a,inserted:o}of b){let{a:s,b:c,c:u,d}=r;if(e<u)break;if(e<=d)return o?l(o,-1)+(e-u):u===d&&t<0?l(i,-1):l(a,1);n+=d-u-(c-s)}return a.mapping.map(e-n,t)},S=e.schema.marks.formatChange,C=e=>r.isInSet(e.marks)?.attrs.author===n,ee=e=>{if(!S||!To.has(e.mark.type.name))return;let t=[];a.doc.nodesBetween(e.from,e.to,(n,r)=>{if(!n.isInline)return!0;if(wo.has(n.type.name)||S.isInSet(n.marks)||C(n))return!1;let i=e.mark.isInSet(n.marks);if(e instanceof Fe?i:!i)return!1;let a=JSON.stringify(n.marks.filter(e=>To.has(e.type.name)).map(e=>e.toJSON())),o=Math.max(r,e.from),s=Math.min(r+n.nodeSize,e.to),c=t[t.length-1];return c&&c.to===o&&c.previous===a?c.to=s:t.push({from:o,to:s,previous:a}),!1});for(let{from:e,to:r,previous:i}of t){let t={id:c(),author:n,date:o,previous:JSON.parse(i)};a.addMark(e,r,S.create(t))}},te=e=>{let t=a.doc.nodeAt(e.pos),r=e.attrs;if(!t?.isTextblock||!r||t.type!==e.type||ko(t.attrs,r))return e;if(t.attrs.formatChange){if(u(r.formatChange??null,t.attrs.formatChange))return e;let n={...r,formatChange:t.attrs.formatChange};return new Le(e.pos,e.type,n,e.marks)}if(t.attrs.revision?.insertion?.author===n)return e;let i={id:c(),author:n,date:o,previous:Oo(t.attrs)};return new Le(e.pos,e.type,{...r,formatChange:i},e.marks)};t.steps.forEach((e,n)=>{if(e.getMap().ranges.length)return;let r=t.mapping.slice(n+1),i=e.map({map:(e,t=1)=>x(r.map(e,t),t),mapResult:(e,t=1)=>{let n=r.mapResult(e,t);return{pos:x(n.pos,t),deleted:n.deleted,recover:null}}}),o=new Set([...p,...m].map(e=>l(e,1)));if(i instanceof Le&&o.has(i.pos)&&(i=null),i instanceof ze){let e=i.steps.filter(e=>!o.has(e.pos));i=e.length?new ze(e):null}(i instanceof Fe||i instanceof Ie)&&ee(i),i instanceof Le&&(i=te(i)),i instanceof ze&&(i=new ze(i.steps.map(te))),i&&a.step(i)});for(let{at:e,host:t}of h){let r=l(e,1),i=a.doc.nodeAt(r),s=i?.attrs.revision;if(!i?.isTextblock||i.attrs.formatChange||s?.insertion?.author===n||ko(i.attrs,t.attrs))continue;let u={id:c(),author:n,date:o,previous:Oo(t.attrs)};a.step(new Le(r,i.type,{...i.attrs,formatChange:u},i.marks))}let T=new Set;for(let{at:e,kind:t,revision:n}of f){let r=l(e,1),i=a.doc.nodeAt(r);if(!i?.isTextblock||T.has(r*2+ +(t===`insertion`)))continue;T.add(r*2+ +(t===`insertion`));let o=i.attrs.revision??{},s=t===`insertion`?{insertion:n}:{...o,deletion:n};a.step(new Le(r,i.type,{...i.attrs,revision:s}))}let E=y.length===1?y[0]:void 0,D=e.selection.empty&&E!==void 0&&E.c===E.d&&e.selection.head===E.b?-1:1,O=t.selection,k=x(O.anchor,D),ne=x(O.head,D);return O instanceof We&&a.doc.nodeAt(k)?.type===O.node.type?a.setSelection(We.create(a.doc,k)):O instanceof R?a.setSelection(R.create(a.doc,k,ne)):O.toJSON().type===`cell`?a.setSelection(L.fromJSON(a.doc,{type:`cell`,anchor:k,head:ne})):a.setSelection(L.near(a.doc.resolve(ne))),t.storedMarks&&a.setStoredMarks(t.storedMarks.filter(e=>e.type!==r&&e.type!==i)),a}function Uo(e){let t=[];for(let[n,r]of[...e].sort((e,t)=>e[0]-t[0])){let e=t[t.length-1];e&&n<=e[1]?e[1]=Math.max(e[1],r):t.push([n,r])}return t}function Wo(e,t,n,r){let i=[];return e.forEach(e=>{if(e.isInline){if(wo.has(e.type.name))i.push(e);else{let a=e.marks.filter(e=>e.type!==n&&e.type!==r);i.push(e.mark(t.addToSet(a)))}return}let a=[`table`,`tableRow`,`tableCell`].includes(e.type.name);if(!e.isTextblock&&!a)throw new F(`This content cannot be inserted as a tracked change`);i.push(e.copy(Wo(e.content,t,n,r)))}),f.fromArray(i)}var Go={width:12240,height:15840,margin:1440},Ko=720;function qo(e){let{columns:t={}}=e,n=t.separator===!0,r=t.space??Ko,i=t.equalWidth===!1?t.widths:void 0;if(i?.length)return{widths:i.map(e=>e.width),gaps:i.slice(0,-1).map(e=>e.space??r),separator:n};let a=Math.max(t.count??1,1),o=Math.max((Jo(e)-r*(a-1))/a,1);return{widths:Array.from({length:a},()=>o),gaps:Array.from({length:a-1},()=>r),separator:n}}function Jo({pageSize:e,margins:t={}}){return(e?.width??Go.width)-(t.left??Go.margin)-(t.right??Go.margin)-(t.gutter??0)}function Yo(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0))}function Xo(e,t){let n=null;return e.forEach((e,r)=>{!n&&r+e.nodeSize>t&&e.attrs.section&&(n={pos:r,node:e})}),n}function Zo(e,t){let n=X(e)?.envelope.section??{};for(let e of t.steps)e instanceof Lr&&e.key===`section`&&(n=e.after);return n}function Qo(e,t,n,r){n?t.setNodeMarkup(n.pos,n.node.type,{...n.node.attrs,section:r}):Hr(e,t,`section`,r)}function $o(e,t,n,r){let i=Xo(t.doc,r),a=i?i.node.attrs.section:Zo(e,t),o=(e,t)=>e||t?{...t,...e}:void 0;Qo(e,t,i,Yo({...a,type:n.type,headers:o(a.headers,n.headers),footers:o(a.footers,n.footers)}))}var es={header:`headers`,footer:`footers`};function ts(e,t,n,r){for(let i=Math.min(t,e.length-1);i>=0;i--){let t=e[i]?.[es[n]]?.[r];if(t)return{id:t,section:i}}return null}function ns(e,t,n){return e.titlePage&&t.first?`first`:n&&t.number%2==0?`even`:`default`}function rs(e,t){let{change:n,...r}=e;return t||!n?r:Yo({...n.previous,headers:e.headers,footers:e.footers,ext:e.ext})}var is=`
|
|
3
|
-
`,as=new Intl.Segmenter(void 0,{granularity:`grapheme`}),os=new Intl.Segmenter(void 0,{granularity:`word`});function ss(e,t){return t===e.selection.head?e:e.apply(e.tr.setSelection(R.create(e.doc,t)))}function cs(e){let{selection:t}=e;return t.empty&&t instanceof R?t.$head:null}var ls=(e,t)=>!e.selection.empty&&I(e,t,e=>us(e));function us(e,t=!1){let n=e.selection;if(n instanceof ma){let r=n.anchor;aa(e,t?[r]:n.cells),e.setSelection(L.near(e.doc.resolve(e.mapping.map(r,1)+1),1));return}let{from:r,to:i}=n;na(e,r,i)?e.setSelection(L.near(e.doc.resolve(e.mapping.map(r,-1)),1)):e.deleteSelection(),oa(e)}function ds(e){return(t,n)=>{if(!e)return!1;let{selection:r}=t;return Cs(t)?ws(t,n,t.schema.text(e,t.storedMarks??[])):!(r instanceof Ge)&&!(r instanceof ma)&&!r.$from.parent.inlineContent?!1:I(t,n,n=>{let i=r instanceof ma?L.near(t.doc.resolve(r.anchor+1),1).$from:r.$from,a=t.storedMarks??(r.empty?Ke(i):i.nodeAfter?.marks??Ke(i));r.empty||us(n,!0);let o=n.selection.$from;if(!o.parent.inlineContent)throw new F(`No text where the selection was`);let s=Ze(a).filter(e=>o.parent.type.allowsMarkType(e.type));n.insertText(e,o.pos,o.pos,s),n.setSelection(R.create(n.doc,o.pos+e.length))})}}function fs(e,t,n=!1){let r=0;if(n&&t===`word`&&e.parent.forEach((t,n)=>{!t.isText&&n<e.parentOffset&&(r=n+t.nodeSize)}),r===e.parentOffset&&r>0)return 1;let i=e.parent.textBetween(r,e.parentOffset,``,is);if(t===`char`)return[...as.segment(i)].pop()?.segment.length??0;let a=[...os.segment(i)],o=0;for(;a.length&&!a[a.length-1]?.isWordLike;)o+=a.pop()?.segment.length??0;return o+(a.pop()?.segment.length??0)}function ps(e,t,n=!1){let r=e.parent.content.size;if(n&&t===`word`&&e.parent.forEach((t,n)=>{!t.isText&&n>=e.parentOffset&&n<r&&(r=n)}),r===e.parentOffset&&r<e.parent.content.size)return 1;let i=e.parent.textBetween(e.parentOffset,r,``,is),a=[...(t===`char`?as:os).segment(i)];if(t===`char`)return a[0]?.segment.length??0;let o=0;for(;a.length&&!a[0]?.isWordLike;)o+=a.shift()?.segment.length??0;return o+(a.shift()?.segment.length??0)}function ms(e){let t=jo(e);return t?.on===!0||(t?.view??`markup`)!==`markup`}var hs=e=>e.marks.some(e=>e.type.name===`deletion`);function gs(e,t,n,r){if(!xi(n))return!1;let i=bi(e.doc,r);return!i||i.deleted?!1:(t?.(e.tr.setSelection(Pi(e.doc,i))),!0)}function _s(e=`char`){return(t,n)=>{if(!t.selection.empty)return ls(t,n);let r=cs(t);if(!r)return!1;let i=X(t),a=ms(t),o=r;for(;o.parentOffset>0;){let e=o.nodeBefore;if(a&&e&&hs(e))o=t.doc.resolve(o.pos-e.nodeSize);else if(gs(t,n,e,o.pos-1))return!0;else if(pi(i,e))o=t.doc.resolve(o.pos-1);else break}if(o.parentOffset===0)return bs(ss(t,o.pos),n);if(mi(i,o.nodeBefore)){let e=o.nodeBefore;return n?.(t.tr.setSelection(hi(t,o.pos-e.nodeSize))),!0}let s=fs(o,e,i!==null);return I(t,n,e=>e.delete(o.pos-s,o.pos))}}function vs(e=`char`){return(t,n)=>{if(!t.selection.empty)return ls(t,n);let r=cs(t);if(!r)return!1;let i=X(t),a=ms(t),o=r;for(;o.parentOffset<o.parent.content.size;){let e=o.nodeAfter;if(a&&e&&hs(e))o=t.doc.resolve(o.pos+e.nodeSize);else if(gs(t,n,e,o.pos))return!0;else if(pi(i,e))o=t.doc.resolve(o.pos+1);else break}if(o.parentOffset===o.parent.content.size)return xs(ss(t,o.pos),n);if(mi(i,o.nodeAfter))return n?.(t.tr.setSelection(hi(t,o.pos))),!0;let s=ps(o,e,i!==null);return I(t,n,e=>e.delete(o.pos,o.pos+s))}}function ys(e,t,n,r){let i=n.attrs.section;i&&!jo(e)?.on&&$o(e,t,i,r)}var bs=(e,t)=>{let n=cs(e);if(!n?.parent.isTextblock||n.parentOffset>0||n.depth<1)return!1;let r=n.index(n.depth-1);if(r===0)return!1;let i=n.node(n.depth-1).child(r-1),a=n.before();return i.isTextblock?I(e,t,t=>{t.join(a),Ye(t,a-i.nodeSize,n.parent),ys(e,t,i,a-i.nodeSize)}):i.type.name===`table`?(t?.(e.tr.setSelection(L.near(e.doc.resolve(a-1),-1))),!0):mi(X(e),i)?(t?.(e.tr.setSelection(hi(e,a-i.nodeSize))),!0):!1},xs=(e,t)=>{let n=cs(e);if(!n?.parent.isTextblock||n.parentOffset<n.parent.content.size||n.depth<1)return!1;let r=n.node(n.depth-1).maybeChild(n.index(n.depth-1)+1);if(!r)return!1;let i=n.after();return r.isTextblock?I(e,t,t=>{t.join(i),Ye(t,n.before(),r),ys(e,t,n.parent,n.before())}):r.type.name===`table`?(t?.(e.tr.setSelection(L.near(e.doc.resolve(i+1),1))),!0):mi(X(e),r)?(t?.(e.tr.setSelection(hi(e,i))),!0):!1},Ss=(e,t)=>{let{selection:n}=e;return Cs(e)?I(e,t,t=>{t.insert(n.to,tt(e.schema).create()),t.setSelection(R.create(t.doc,n.to+1))}):!(n instanceof Ge)&&!n.$from.parent.isTextblock?!1:I(e,t,t=>{let r=e.storedMarks??Ke(n.$from);if(n.empty||us(t),!t.selection.$from.parent.inlineContent)throw new F(`No text where the selection was`);let i=t.selection.$from,a=i.parentOffset===i.parent.content.size,o=X(e);if(o&&i.parent.type.name===`paragraph`){let{before:e,after:n}=ri(o,i.parent,a);t.split(i.pos,1,[{type:i.parent.type,attrs:n}]),e&&t.setNodeMarkup(i.before(),i.parent.type,e)}else{let n=tt(e.schema);t.split(i.pos,1,a&&i.parent.type!==n?[{type:n}]:void 0)}t.setSelection(R.create(t.doc,i.pos+2)),r.length&&t.setStoredMarks(r)})};function Cs(e){let{selection:t}=e;return t instanceof We&&t.node.isBlock?t.node:null}function ws(e,t,n){let{from:r,to:i}=e.selection,a=tt(e.schema).create(null,n);return I(e,t,e=>{e.replace(r,i,new w(f.from(a),0,0)),e.setSelection(R.create(e.doc,r+1+n.nodeSize))})}function Ts(e,t,n){let r=e.resolve(t);for(;;){let t=n<0?r.nodeBefore:r.nodeAfter;if(t){let e=n<0?r.pos-t.nodeSize:r.pos;for(;!t.isTextblock&&!t.isLeaf;){let r=n<0?t.lastChild:t.firstChild;if(!r)return null;e=n<0?e+t.nodeSize-1-r.nodeSize:e+1,t=r}return{node:t,pos:e}}if(r.depth===0)return null;r=e.resolve(n<0?r.before():r.after())}}function Es(e,t){return(n,r)=>{let{selection:i,doc:a}=n;if(Cs(n)){let t=Ts(a,e<0?i.from:i.to,e);if(!t)return!0;let o=t.node.isTextblock?R.create(a,e<0?t.pos+t.node.nodeSize-1:t.pos+1):We.isSelectable(t.node)?We.create(a,t.pos):L.near(a.resolve(t.pos),e);return r?.(n.tr.setSelection(o)),!0}if(t===`none`||!i.empty||!(i instanceof R))return!1;let{$from:o}=i;if(!o.parent.isTextblock||o.depth<1)return!1;let s=e<0?o.parentOffset===0:o.parentOffset===o.parent.content.size;if(t===`char`&&!s)return!1;let c=Ts(a,e<0?o.before():o.after(),e);return!c||c.node.isTextblock||!We.isSelectable(c.node)?!1:(r?.(n.tr.setSelection(We.create(a,c.pos))),!0)}}var Ds=(e,t)=>As(`tab`,e,t),Os=(e,t)=>As(`hardBreak`,e,t),ks=(e,t)=>As(`pageBreak`,e,t);function As(e,...[t,n]){let r=t.schema.nodes[e],{selection:i}=t;return!r||!(i instanceof Ge)&&!i.$from.parent.inlineContent?!1:I(t,n,e=>{let n=t.storedMarks??Ke(i.$from);if(i.empty||us(e),!e.selection.$from.parent.inlineContent)throw new F(`No text where the selection was`);let a=e.selection.from;e.insert(a,r.create(null,null,Ze(n).filter(t=>e.doc.resolve(a).parent.type.allowsMarkType(t.type)))),e.setSelection(R.create(e.doc,a+1))})}var js=(e,t)=>(t?.(e.tr.setSelection(new Ge(e.doc))),!0);function Ms(e,t){return typeof t==`string`?e.schema.marks[t]:t}function Ns(e,t){let n=!0,r=!1;for(let{from:i,to:a}of e.selection.ranges)e.doc.nodesBetween(i,a,(e,i,a)=>{if(n&&e.isInline&&a?.type.allowsMarkType(t))return r=!0,t.isInSet(e.marks)||(n=!1),!1});return r&&n}function Ps(e,t){return(n,r)=>{let i=Ms(n,e);if(!i)return!1;let{selection:a}=n,o=cs(n);if(o){if(!o.parent.type.allowsMarkType(i))return!1;let e=n.storedMarks??Ke(o),a=X(n);if(a&&ai(a,i))return r?.(n.tr.setStoredMarks(ui(a,o.parent,e,i))),!0;let s=i.isInSet(e),c=s?null:Fs(i,t);return!s&&!c?!1:(r?.(n.tr.setStoredMarks(s?s.removeFromSet(e):c.addToSet(e))),!0)}let{ranges:s}=a,c=!1;for(let{from:e,to:t}of s)n.doc.nodesBetween(e,t,e=>(e.isTextblock&&e.type.allowsMarkType(i)&&(c=!0),!c));if(!c)return!1;let l=X(n);if(l&&ai(l,i)){let e=!li(l,n,i,null);return I(n,r,t=>{for(let{from:r,to:a}of s)for(let o of di(l,n,r,a,i,e))t.removeMark(o.from,o.to,i),o.mark&&t.addMark(o.from,o.to,o.mark)})}let u=Ns(n,i),d=u?null:Fs(i,t);return!u&&!d?!1:I(n,r,e=>{for(let{from:t,to:n}of s)u?e.removeMark(t,n,i):e.addMark(t,n,d)})}}function Fs(e,t){if(e.name===`link`&&!ue(t))return null;try{return e.create(t)}catch(e){if(e instanceof i)return null;throw e}}function Is(e,t){let n=Ms(e,t);if(!n)return!1;let r=cs(e),i=X(e);return i&&ai(i,n)?li(i,e,n,r?e.storedMarks??Ke(r):null):r?n.isInSet(e.storedMarks??Ke(r))!==void 0:Ns(e,n)}function Ls(e,t=null){return(n,r)=>{let i=X(n);if(!i)return!1;let a=typeof e==`string`?e:e.name;if(a===`heading`)return Oa(`heading ${String(t?.level??1)}`)(n,r);let o=a===`paragraph`?Ca(i):null;return o!==null&&Da(o)(n,r)}}function Rs(){return new $e({keymap:{Enter:Ss,"Shift-Enter":Os,"Mod-Enter":ks,Tab:Ds,Backspace:_s(),Delete:vs(),"Mod-b":Ps(`bold`),"Mod-i":Ps(`italic`),"Mod-u":Ps(`underline`),"Mod-k":bo,"Mod-a":js,ArrowLeft:Es(-1,`char`),ArrowRight:Es(1,`char`),ArrowUp:Es(-1,`none`),ArrowDown:Es(1,`none`),"Mod-z":Zi,"Mod-Shift-z":Qi,"Mod-y":Qi}})}var zs=new Set([`commentStart`,`commentEnd`,`commentReference`]);function Bs(e){return typeof e==`string`?e.split(/\r\n|\r|\n/).map(e=>e?{type:`paragraph`,content:[{type:`text`,text:e}]}:{type:`paragraph`}):structuredClone([...e])}var Vs=9,Hs=e=>e.initials===void 0?{}:{initials:e.initials.slice(0,Vs)};function Us(e){let t=new Set;return e.descendants(e=>{if(e.type.name===`opaqueBlock`||e.type.name===`opaqueInline`)for(let[,n]of String(e.attrs.xml).matchAll(/<\w+:comment(?:RangeStart|RangeEnd|Reference)\b[^>]*?\b\w+:id="(\d+)"/g))t.add(Number(n));return e.isBlock}),t}function Ws(e,t){let n=-1;for(let e of t)n=Math.max(n,e.id);e.descendants(e=>(zs.has(e.type.name)&&(n=Math.max(n,e.attrs.id)),e.isBlock));for(let t of Us(e))n=Math.max(n,t);return n+1}function Gs(e,t){let n=e.find(e=>e.id===t),r=new Set;for(;n?.parent!==void 0&&!r.has(n.id);){r.add(n.id);let t=n.parent;n=e.find(e=>e.id===t)}return n}function Ks(e){let t=new Map;return e.descendants((e,n)=>{if(!zs.has(e.type.name))return e.isBlock;let r=e.attrs.id,i=t.get(r)??{};return e.type.name===`commentStart`?i.start??=n:e.type.name===`commentEnd`?i.end??=n:i.reference??=n,t.set(r,i),!1}),t}var qs=e=>e.tr.setMeta(So,!0).setMeta(Li,!0),Js=(e,t)=>t.author??jo(e)?.author??`Author`;function Ys(e,t={}){return(n,r)=>{let i=X(n),{schema:a}=n,o={start:a.nodes.commentStart,end:a.nodes.commentEnd,reference:a.nodes.commentReference};if(!i||Kr(n)||!o.start||!o.end||!o.reference)return!1;let s=n.selection instanceof Ge,c=s?L.atStart(n.doc).$from:n.selection.$from,l=s?L.atEnd(n.doc).$to:n.selection.$to;if(!c.parent.inlineContent||!l.parent.inlineContent)return!1;if(r){let a=i.envelope.comments,s=Ws(n.doc,a),u=qs(n);u.insert(l.pos,[o.end.create({id:s}),o.reference.create({id:s})]),u.insert(c.pos,o.start.create({id:s})),u.setSelection(R.create(u.doc,c.pos+1,l.pos+1));let d={id:s,author:Js(n,t),...Hs(t),date:Fo(),content:Bs(e)};Ir(u,a,[...a,d]),r(u)}return!0}}function Xs(e,t,n={}){return(r,i)=>{let a=X(r),{schema:o}=r,s=a?.envelope.comments??[],c=Gs(s,e),l=Ks(r.doc),u=c&&l.get(c.id),{commentStart:d,commentEnd:f,commentReference:p}=o.nodes;if(!a||!c||!u||!d||!f||!p)return!1;if(i){let e=Ws(r.doc,s),a=qs(r),o=ec(s,c.id),u=e=>Math.max(...[...o].map(t=>l.get(t)?.[e]??-1)),m=u(`start`),h=u(`reference`);h>=0&&a.insert(h+1,[f.create({id:e}),p.create({id:e})]),m>=0&&a.insert(m+1,d.create({id:e}));let g={id:e,author:Js(r,n),...Hs(n),date:Fo(),content:Bs(t),parent:c.id};Ir(a,s,[...s,g]),i(a)}return!0}}function Zs(e,t){return(n,r)=>{let i=X(n)?.envelope.comments,a=i?.find(t=>t.id===e);if(!i||!a)return!1;if(r){let e=i.flatMap(e=>e===a?t(e,i):[e]);r(Ir(qs(n),i,e))}return!0}}var Qs=(e,t)=>Zs(e,e=>[{...e,content:Bs(t)}]);function $s(e,t=!0){return(n,r)=>{let i=X(n)?.envelope.comments??[],a=Gs(i,e);if(!a)return!1;if(r){let e=ec(i,a.id),o=i.map(n=>{if(!e.has(n.id))return n;let{done:r,...i}=n;return t?{...i,done:!0}:i});r(Ir(qs(n),i,o))}return!0}}function ec(e,t){let n=new Set([t]);for(let t=!0;t;){t=!1;for(let r of e)r.parent!==void 0&&n.has(r.parent)&&!n.has(r.id)&&(n.add(r.id),t=!0)}return n}function tc(e,t,n){let r=[];e.doc.descendants((e,t)=>(zs.has(e.type.name)&&n.has(e.attrs.id)&&r.push(t),e.isBlock));for(let t of r.reverse())e.delete(t,t+1);Ir(e,t,t.filter(e=>!n.has(e.id)))}function nc(e){let t=(n,r)=>{let i=Kr(n);if(i)return r?i.run(t):i.can(t);let a=X(n)?.envelope.comments??[],o=ec(a,e),s=Us(n.doc);if(!a.some(t=>t.id===e)||[...o].some(e=>s.has(e)))return!1;if(r){let e=qs(n);tc(e,a,o),r(e)}return!0};return t}var rc=(e,t)=>{let n=Kr(e);if(n)return t?n.run(rc):n.can(rc);let r=X(e)?.envelope.comments??[],i=Us(e.doc),a=new Set;for(let e of r){let t=Gs(r,e.id);if(t&&i.has(t.id))for(let e of ec(r,t.id))a.add(e);i.has(e.id)&&a.add(e.id)}let o=new Set(r.map(e=>e.id).filter(e=>!a.has(e)));if(!o.size)return!1;if(t){let n=qs(e);tc(n,r,o),t(n)}return!0},ic=new Qe(`comments`);function ac(e){return e.steps.some((t,n)=>{let r=!1;return t.getMap().forEach((t,i)=>{t<i&&e.docs[n].nodesBetween(t,i,e=>(e.type.name===`commentReference`&&(r=!0),!r))}),r})}function oc(){return new $e({key:ic,appendTransaction(e,t,n){let r=X(n)?.envelope.comments;if(!r?.length||!e.some(ac))return null;let i=Ks(t.doc),a=Ks(n.doc),o=new Set;for(let[e,t]of i)if(t.reference!==void 0&&a.get(e)?.reference===void 0)for(let t of ec(r,e))o.add(t);let s=[...o].filter(e=>r.some(t=>t.id===e));if(!s.length)return null;let c=n.tr.setMeta(So,!0);return tc(c,r,new Set(s)),c}})}var sc={SEQ:`rs`,TOC:`abcdflnopst`,MERGEFIELD:`bf`,REF:`d`},cc=`*@#`;function lc(e){let t=[],n=0;for(;n<e.length;)if(/\s/.test(e[n]))n++;else if(e[n]===`"`){let r=``;for(n++;n<e.length&&e[n]!==`"`;n++)e[n]===`\\`&&(e[n+1]===`"`||e[n+1]===`\\`)&&n++,r+=e[n];n++,t.push({value:r,quoted:!0})}else{let r=n;for(;n<e.length&&!/[\s"]/.test(e[n]);)n++;t.push({value:e.slice(r,n),quoted:!1})}return t}function uc(e){let t=lc(e),n=(t[0]?.value??``).toUpperCase(),r=cc+(sc[n]??``),i=[],a=new Map;for(let e=1;e<t.length;e++){let{value:n,quoted:o}=t[e];if(o||!n.startsWith(`\\`)||n.length<2){i.push(n);continue}let s=n[1].toLowerCase(),c=n.slice(2),l=t[e+1];!c&&r.includes(s)&&l&&(l.quoted||l.value[0]!==`\\`)&&(c=l.value,e++),a.set(s,[...a.get(s)??[],c])}return{name:n,args:i,switches:a}}var dc=`January February March April May June July August September October November December`.split(` `),fc=`Sunday Monday Tuesday Wednesday Thursday Friday Saturday`.split(` `),pc=(e,t=2)=>String(e).padStart(t,`0`);function mc(e,t){let n=e.getHours()%12||12,r={d:String(e.getDate()),dd:pc(e.getDate()),ddd:fc[e.getDay()].slice(0,3),dddd:fc[e.getDay()],M:String(e.getMonth()+1),MM:pc(e.getMonth()+1),MMM:dc[e.getMonth()].slice(0,3),MMMM:dc[e.getMonth()],yy:pc(e.getFullYear()%100),yyyy:String(e.getFullYear()),h:String(n),hh:pc(n),H:String(e.getHours()),HH:pc(e.getHours()),m:String(e.getMinutes()),mm:pc(e.getMinutes()),s:String(e.getSeconds()),ss:pc(e.getSeconds())},i=e.getHours()<12;return t.replace(/'([^']*)'|AM\/PM|am\/pm|A\/P|a\/p|d+|M+|y+|h+|H+|m+|s+/g,(e,t)=>t===void 0?e.includes(`/`)?i?e.split(`/`)[0]:e.split(`/`)[1]:r[e]??e:t)}function hc(e,t){let n=[``],r=!1;for(let e of t)e===`'`&&(r=!r),e===`;`&&!r?n.push(``):n[n.length-1]+=e;let i=e<0&&n[1]!==void 0,a=e===0&&n[2]!==void 0,o=i?n[1]:a?n[2]:n[0],s=[],c=[],l=[],u=[],d=!1,f=!1;r=!1;for(let e of o)if(e===`'`)r=!r;else if(r)s.push(e);else if(e==="`")return null;else if(e===`0`||e===`#`||e===`x`)(d?l:c).push({at:s.length,slot:e}),s.push(``);else if(e===`.`){if(d)return null;d=!0,s.push(`.`)}else if(e===`,`){if(d)return null;f=!0}else e===`+`||e===`-`?(u.push({at:s.length,sign:e}),s.push(``)):s.push(e);let p=Math.abs(e);if(!Number.isFinite(p)||p>=1e21)return null;let[m=``,h=``]=p.toFixed(Math.min(l.length,100)).split(`.`),g=h.padEnd(l.length,`0`),_=m===`0`?``:m,v=!_&&!/[1-9]/.test(g),y=_.length-1,b=0,x=e=>f&&b>0&&b%3==0&&e!==` `?`${e},`:e;for(let e=c.length-1;e>=0;e--,b++){let{at:t,slot:n}=c[e];s[t]=x(y>=0?_[y--]:n===`0`?`0`:` `)}let S=c[0],C=y>=0&&S?.slot===`x`;if(S&&S.slot!==`x`)for(;y>=0;y--,b++)s[S.at]=x(_[y])+s[S.at];l.forEach(({at:e,slot:t},n)=>{let r=g.slice(n),i=r[0];t===`0`||/[1-9]/.test(r)?s[e]=i:v&&n===0?s[e]=`0`:s[e]=t===`#`?` `:``});for(let{at:t,sign:n}of u)s[t]=v?` `:e<0?`-`:n===`+`?`+`:` `;if(e<0&&!i&&!v&&!u.length&&!C){let e=c.find(({slot:e})=>e!==`x`);e&&(s[e.at]=`-${s[e.at]}`)}return s.join(``)}var gc={ROMAN:`upperRoman`,roman:`lowerRoman`,ALPHABETIC:`upperLetter`,alphabetic:`lowerLetter`},_c={arabic:`decimal`,arabicdash:`numberInDash`,ordinal:`ordinal`},vc={upper:e=>e.toUpperCase(),lower:e=>e.toLowerCase(),firstcap:e=>e.charAt(0).toUpperCase()+e.slice(1),caps:e=>e.replace(/(^|\s)(\S)/g,(e,t,n)=>t+n.toUpperCase())},yc=new Set([`mergeformat`,`charformat`]);function bc(e,t,n){let r=typeof e==`number`?e:Number(e.trim().replace(/,/g,``)),i=String(e).trim()!==``&&Number.isFinite(r)?r:null,a=t.switches.get(`#`)?.[0],o=n,s=!1,c=[];for(let e of t.switches.get(`*`)??[]){let t=e.toLowerCase();if(yc.has(t))continue;let n=gc[e]??_c[t];if(n)o=n;else if(t===`hex`)s=!0;else if(vc[t])c.push(vc[t]);else return null}let l=String(e);if(i!==null&&a!==void 0){let e=hc(i,a);if(e===null)return null;l=e}else i!==null&&s?l=i.toString(16).toUpperCase():i!==null&&(o||typeof e==`number`)&&(l=br(i,o));for(let e of c)l=e(l);return l}var xc=()=>({updated:0,unchanged:0,rebuilt:0,skipped:[]}),Sc=new WeakMap;function Cc(e){let t=Sc.get(e);if(t)return t;let n=new Map,r=new Map;return e.descendants((e,t)=>{if(e.type.name===`bookmarkStart`)n.set(e.attrs.id,{name:String(e.attrs.name),from:t+1});else if(e.type.name===`bookmarkEnd`){let i=n.get(e.attrs.id),a=i?.name.toLowerCase();i&&a!==void 0&&!r.has(a)&&r.set(a,{...i,to:t})}return!e.isInline}),Sc.set(e,r),r}var wc=(e,t)=>Cc(e).get(t.toLowerCase());function Tc(e,t){let n=Cc(e),r=2e8;for(let{name:e}of n.values()){let i=e.toLowerCase().startsWith(t.toLowerCase())?Number(e.slice(t.length)):0;Number.isSafeInteger(i+1+n.size)&&(r=Math.max(r,i))}return()=>{let e;do e=`${t}${++r}`;while(n.has(e.toLowerCase()));return e}}var Ec=new WeakMap;function Dc(e,t){let n=Ec.get(e);if(!n){n=[];for(let{from:t,codeEnd:r}of vi(e)){let e=n[n.length-1];e&&t<e[1]?e[1]=Math.max(e[1],r):n.push([t,r])}Ec.set(e,n)}let r=0,i=n.length;for(;r<i;){let e=r+i>>1;n[e][1]<=t?r=e+1:i=e}let a=n[r];return!!a&&a[0]<=t}function Oc(e){let t=[];return e.descendants((e,n)=>(e.type.name===`paragraph`&&t.push({node:e,pos:n}),!e.isTextblock)),t}var kc=new Set([`insertion`,`deletion`,`formatChange`]),Ac=e=>e.filter(e=>!kc.has(e.type.name)),jc=e=>e.marks.some(e=>e.type.name===`deletion`);function Mc(e,t,n){let r=e.nodes,i=[];for(let a of t.split(/(\t|\r\n|\r|\n)/))a&&(a===` `?i.push(r.tab.create(null,null,n)):/^[\r\n]/.test(a)?i.push(r.hardBreak.create(null,null,n)):i.push(e.text(a,n)));return i}function Nc(e,t){return Ac(((t.switches.get(`*`)??[]).some(e=>e.toLowerCase()===`mergeformat`)?e.resultMarks:null)??e.codeMarks??[])}function Pc(e,t){let n=e.type.schema,r=[],i=n.nodes.hardBreak,a=null;return e.nodesBetween(t.from,t.to,(n,o,s)=>{if(!n.isInline)return!0;if(a&&s!==a&&r.push(i.create()),a=s,jc(n)||Dc(e,o))return!1;if(n.isText){let e=Math.max(t.from-o,0),i=Math.min(t.to-o,n.nodeSize);i>e&&r.push(n.cut(e,i).mark(Fc(n.marks)))}else[`tab`,`hardBreak`,`picture`].includes(n.type.name)&&r.push(n.mark(Fc(n.marks)));return!1}),r}var Fc=e=>Ac(e).filter(e=>e.type.name!==`link`),Ic=class{paragraphs;markers;lists=new Map;constructor(e,t){this.paragraphs=Oc(e),this.markers=t.resolver.markers(this.paragraphs.map(e=>e.node.attrs)),this.markers.forEach((e,t)=>{if(!e)return;let n=this.lists.get(e.instance);n?n.push(t):this.lists.set(e.instance,[t])})}lastOfList(e,t){let n=this.lists.get(e)??[],r=0,i=n.length;for(;r<i;){let e=r+i>>1;n[e]<=t?r=e+1:i=e}return n[r-1]??-1}indexAt(e){let t=0,n=this.paragraphs.length;for(;t<n;){let r=t+n>>1;this.paragraphs[r].pos<=e?t=r+1:n=r}let r=this.paragraphs[t-1];return r&&e<=r.pos+r.node.nodeSize?t-1:-1}marker(e){return this.markers[this.indexAt(e)]??null}chain(e){let t=[e],n=this.markers[e]?.level??0,r=this.markers[e]?.abstract;for(let i=e-1;i>=0&&n>0;i--){let e=this.markers[i];e?.abstract===r&&e&&e.level<n&&(t.unshift(i),n=e.level)}return t}number(e,t,n,r){let i=this.indexAt(e),a=this.markers[i];if(!a)return`0`;let o=e=>{let t=this.markers[e];return r?t.plain:t.text},s=t===`n`?[i]:this.chain(i);if(t===`r`){let e=this.lastOfList(a.instance,this.indexAt(n)),t=e<0?[]:this.chain(e),r=0;for(;r<s.length-1&&s[r]===t[r];)r++;s=s.slice(r)}let c=[];for(let e of s){let t=o(e),n=c[c.length-1]?.replace(/\.+$/,``);n&&t.startsWith(n)&&!/^\w/.test(t.slice(n.length))?c[c.length-1]=t:c.push(t)}return c.join(``).replace(/\.+$/,``)}},Lc=new Set([`PAGE`,`NUMPAGES`,`SECTIONPAGES`]),Rc=new Set([...Lc,`DATE`,`TIME`,`SEQ`,`MERGEFIELD`]),zc={PAGE:``,NUMPAGES:``,SECTIONPAGES:``,DATE:``,TIME:``,SEQ:`cnrsh`,MERGEFIELD:`bf`,REF:`hnrwpt`,PAGEREF:`hp`,TOC:`ohzutnbpwx`};function Bc(e,t){let n=t;for(let t=e.mapping.maps.length-1;t>=0;t--)n=e.mapping.maps[t].invert().map(n,1);return n}var Z=(e,t,n,r)=>{e.report.skipped.push({instruction:t.instruction,story:e.story,reason:n,...r?{detail:r}:{}})};function Vc(e,t,n){let{layout:r}=e.options;if(!r)return Z(e,t,`no-layout`),null;let i=r.pageAt(Bc(e.bodyTr,n));return i||Z(e,t,`no-layout`),i}function Hc(e,t){return Oc(e).flatMap(({node:e,pos:n})=>{let r=Uc(t,e);return r===null?[]:[{pos:n,level:r}]})}function Uc(e,t){let n=e.resolver.paragraph(t.attrs).paragraph.style,r=e.envelope.styles.find(e=>e.id===n)?.name??``,i=/^heading ([1-9])$/i.exec(r);return i?Number(i[1]):null}function Wc(e,t){let n=e.tr.doc,r=new Map,i=new Map,a=new Map,o=Hc(n,e.word);for(let e of t){if(e.name!==`SEQ`||e.deleted)continue;let{args:t,switches:s}=uc(e.instruction),c=(t[0]??``).toLowerCase(),l=a.get(c)??[];a.set(c,l);let u=i.get(c)??0,d=Number(s.get(`s`)?.[0]),f=l[l.length-1]?.pos??0;d&&o.some(t=>t.pos>=f&&t.pos<e.from&&t.level<=d)&&(u=0);let p=t[1]?wc(n,t[1]):void 0,m=[...s.keys()].find(e=>`cnr`.includes(e)),h=Number(s.get(`r`)?.[0]);p?u=[...l].reverse().find(e=>e.pos<p.from)?.value??0:m===`r`&&Number.isFinite(h)?u=h:m!==`c`&&u++,p||i.set(c,u),l.push({pos:e.from,value:u}),r.set(e,u)}return r}var Gc=(e,t)=>{if(Object.hasOwn(e,t))return{found:!0,value:e[t]};let n=t.toLowerCase(),r=Object.keys(e).find(e=>e.toLowerCase()===n);return r===void 0?{found:!1,value:void 0}:{found:!0,value:e[r]}},Kc=(e,t)=>e.from<t.from?`below`:`above`;function qc(e,t){let n=wc(e.tr.doc,t);if(n)return{mark:n,tree:e.tr.doc,inBody:e.story===null};let r=e.story===null?void 0:wc(e.bodyTr.doc,t);return r?{mark:r,tree:e.bodyTr.doc,inBody:!0}:null}function Jc(e,t){let{name:n,args:r,switches:i}=uc(t.instruction);if(Rc.has(n)||n===`PAGEREF`||n===`TOC`||i.has(`n`)||i.has(`r`)||i.has(`w`)||i.has(`p`))return;let a=n===`REF`?r[0]:lc(t.instruction)[0]?.value;return a?wc(e,a):void 0}function Yc(e,t,n){let r=vi(e),i=new Set([n]),a=[n];for(let n=a.pop();n;n=a.pop()){if(n.from<=t.from&&t.to<=n.to)return!0;let o=0,s=r.length;for(;o<s;){let e=o+s>>1;r[e].from<n.from?o=e+1:s=e}for(let t=o;t<r.length&&r[t].from<n.to;t++){let n=Jc(e,r[t]);n&&!i.has(n)&&(i.add(n),a.push(n))}}return!1}function Xc(e,t,n){let r=uc(t.instruction),{name:i,args:a,switches:o}=r,s=!Rc.has(i)&&i!==`REF`&&i!==`PAGEREF`,c=s?lc(t.instruction)[0]?.value:a[0],l=!Rc.has(i)&&c?qc(e,c):null;if(s&&!l)return Z(e,t,`unknown`),null;let u=zc[s?`REF`:i]??``;for(let n of o.keys())if(!cc.includes(n)&&!u.includes(n))return Z(e,t,`unsupported-switch`,`\\${n}`),null;let d=(n,i)=>{let a=bc(n,r,i);return a===null&&Z(e,t,`unsupported-switch`,`\\*`),a===null?null:{text:a}},{layout:f}=e.options;switch(i){case`PAGE`:case`SECTIONPAGES`:{let n=Vc(e,t,t.from);return n?i===`PAGE`?d(n.number,n.format):d(n.sectionPages):null}case`NUMPAGES`:return f||Z(e,t,`no-layout`),f?d(f.pages):null;case`DATE`:case`TIME`:{let t=o.get(`@`)?.[0]??(i===`DATE`?`M/d/yyyy`:`h:mm AM/PM`);return d(mc(e.options.now??new Date,t))}case`SEQ`:{let e=(o.get(`*`)??[]).some(e=>!yc.has(e.toLowerCase()));return o.has(`h`)&&!e?{text:``}:d(n.get(t)??0)}case`MERGEFIELD`:{let{data:n}=e.options;if(!n)return null;let i=a[0]??``,{found:s,value:c}=Gc(n,i);if(!s)return Z(e,t,`no-data`,i),null;let l=c??``,u=o.get(`@`)?.[0];c instanceof Date?l=u?mc(c,u):c.toISOString():u&&typeof c==`string`&&!Number.isNaN(Date.parse(c))&&(l=mc(new Date(c),u));let d=bc(typeof l==`number`?l:String(l),r);if(d===null)return Z(e,t,`unsupported-switch`,`\\*`),null;let f=o.get(`b`)?.[0]??``,p=o.get(`f`)?.[0]??``;return{text:d?`${f}${d}${p}`:``}}}if(!l)return Z(e,t,`missing-bookmark`,c),null;let{mark:p,tree:m,inBody:h}=l,g=o.has(`p`)&&m===e.tr.doc?Kc(t,p):null;if(i===`PAGEREF`){if(!h)return Z(e,t,`no-layout`,c),null;let n=Vc(e,t,p.from);if(!n)return null;let r=g&&e.story===null&&f?f.pageAt(Bc(e.bodyTr,t.from)):null;if(g&&r?.number===n.number)return{text:g};let i=d(n.number,n.format);return i&&o.has(`p`)?{text:`on page ${i.text}`}:i}let _=[`n`,`r`,`w`].find(e=>o.has(e));if(_){let n=e.numbers.get(m);n||(n=new Ic(m,e.word),e.numbers.set(m,n));let r=n.number(p.from,_,t.from,o.has(`t`));return d(g?`${r} ${g}`:r)}if(g)return d(g);if(m===e.tr.doc&&Yc(m,t,p))return Z(e,t,`self-reference`,c),null;let v=Pc(m,p),y=v.map(e=>e.isText?e.text:e.type.name===`tab`?` `:`
|
|
4
|
-
`).join(``),b=d(y);if(!b)return null;let x=!(o.get(`*`)??[]).some(e=>yc.has(e.toLowerCase()));return b.text===y&&x?{text:y,nodes:v}:b}function Zc(e,t,n){let{tr:r}=e;if(t.separator!==null){r.replace(t.resultFrom,t.resultTo,new w(f.fromArray([...n]),0,0));return}let i=Nc(t,uc(t.instruction)),a=r.doc.type.schema.nodes.fieldSeparator.create(null,null,i);r.insert(t.to-1,[a,...n])}function Qc(e,t){let{tr:n}=e,r=[...t].reverse();if(t.length<32||jo(e.state)?.on){for(let[t,n]of r)Zc(e,t,n);return}let i=Oc(n.doc),a=e=>{let t=0,n=i.length;for(;t<n;){let r=t+n>>1;i[r].pos<e?t=r+1:n=r}return i[t-1]},o=[],s,c=()=>{let e=s,[t]=o,r=o[o.length-1];if(e&&t&&r){let i=[...o].reverse(),a=r[0].resultFrom,s=t[0].resultTo,c=[];e.node.forEach((t,n)=>{let r=e.pos+1+n;r>=a&&r<s&&c.push({at:r,node:t})});let l=[],u=0;for(let[e,t]of i){for(;c[u]&&c[u].at<e.resultFrom;)l.push(c[u++].node);for(l.push(...t);c[u]&&c[u].at<e.resultTo;)u++}n.replace(a,s,new w(f.fromArray(l),0,0))}o=[],s=void 0};for(let t of r){let[n,r]=t,i=a(n.from);n.separator!==null&&i&&n.resultTo<i.pos+i.node.nodeSize?(i!==s&&c(),s=i,o.push(t)):(c(),Zc(e,n,r))}c()}var $c=new WeakMap;function el(e){let t=[],n=!1;for(let r=e;r;r=r.parent){let e=$c.get(r);if(e!==void 0){n=e;break}if(t.push(r),r.locked){n=!0;break}}for(let e of t)$c.set(e,n);return n}function tl(e){return vi(e).filter(e=>{if(e.name!==`TOC`)return!1;for(let t=e.parent;t;t=t.parent)if(t.name===`TOC`)return!1;return!0})}var nl=e=>e.inCode?0:Rc.has(e.name)?1:e.name===`TOC`?3:2;function rl(e){let{tr:t,report:n,story:r}=e,i=t.doc.type.schema,a=new Set,o=n=>{if(n.deleted||!e.picked(n)||r!==null&&Lc.has(n.name))return!1;if(!el(n))return!0;let i=Bc(t,n.from);return a.has(i)||Z(e,n,`locked`),a.add(i),!1};for(let r of[0,1,2]){let a=vi(t.doc);if(!a.length)return;let s=Wc(e,a),c=new Map;for(let t of a)if(nl(t)===r&&o(t))try{let r=Xc(e,t,s);if(!r)continue;if(r.text===t.result){n.unchanged++;continue}let a=Nc(t,uc(t.instruction));c.set(t,r.nodes??Mc(i,r.text,a)),n.updated++}catch(n){Z(e,t,`failed`,n.message)}let l=new Set;for(let e of a)e.parent&&(c.has(e.parent)||l.has(e.parent))&&l.add(e);Qc(e,[...c].filter(([e])=>!l.has(e)))}if(r!==null){for(let n of vi(t.doc))n.name===`TOC`&&o(n)&&Z(e,n,`unknown`,`in a story`);return}let s=tl(t.doc).length;for(let n=0;n<s;n++){let r=tl(t.doc)[n];if(r&&o(r)){if(!e.contents)Z(e,r,`untrackable`);else try{hl(e,n)}catch(t){Z(e,r,`failed`,t.message)}}}}var il=new WeakMap;function al(e){let t=il.get(e);return t||(t=vi(e).filter(e=>e.name===`TOC`),il.set(e,t)),t}function ol(e,t,{node:n,pos:r}){let{run:i}=t.resolver.paragraph(n.attrs),a=al(e),o=[],s=null;return n.forEach((n,c)=>{let l=r+1+c;a.some(e=>l>=e.from&&l<e.to)?s=null:(s||(s={title:``,from:l,to:l,bookmark:null},o.push(s)),s.to=l+n.nodeSize,n.type.name===`bookmarkStart`&&sl.test(String(n.attrs.name))&&(s.bookmark??=String(n.attrs.name)),jc(n)||Dc(e,l)||t.resolver.run(i,n.marks.map(e=>e.toJSON())).hidden||(n.isText?s.title+=n.text:n.type.name===`tab`?s.title+=` `:n.type.name===`hardBreak`&&(s.title+=` `)))}),o.map(e=>({...e,title:e.title.trim()})).filter(e=>e.title)}var sl=/^_Toc\d+$/,cl=e=>{let t=/(\d)\s*-\s*(\d)/.exec(e??``);return t?[Number(t[1]),Number(t[2])]:[1,9]};function ll(e,t){let n=e.envelope.styles.find(e=>e.id===t)?.name??``,r=/^heading ([1-9])$/i.exec(n);if(r)return Number(r[1]);let i=t?e.resolver.paragraph({style:t}).paragraph.outlineLevel:null;return i!==null&&i<9?i+1:null}function ul(e,t,{switches:n}){let r=n.has(`o`)||n.has(`u`)||n.has(`t`),[i,a]=cl(n.get(`o`)?.[0]),o=new Map,s=(n.get(`t`)?.[0]??``).split(/[,;]/).map(e=>e.trim());for(let e=0;e+1<s.length;e+=2)o.set(s[e].toLowerCase(),Number(s[e+1])||1);let c=n.has(`b`)?wc(e,n.get(`b`)?.[0]??``):null,l=Oc(e),u=t.resolver.markers(l.map(e=>e.node.attrs)),d=e=>e>=i&&e<=a,f=[];return l.forEach((i,a)=>{let{node:s,pos:l}=i;if(c&&(l+s.nodeSize<=c.from||l>=c.to))return;let p=t.resolver.paragraph(s.attrs).paragraph,m=t.envelope.styles.find(e=>e.id===p.style),h=o.get((m?.name??p.style??``).toLowerCase());if(h===void 0&&(n.has(`o`)||n.has(`u`)||!r)){let e=ll(t,p.style);e!==null&&d(e)&&(h=e)}let g=p.outlineLevel;if(h===void 0&&n.has(`u`)&&g!==null&&g<9&&d(g+1)&&(h=g+1),h===void 0)return;let _=u[a];for(let{title:n,from:r,to:a,bookmark:o}of ol(e,t,i))f.push({from:r,to:a,level:h,title:n,number:_?.text??``,numberGap:_?.suffix===`space`?` `:_?.suffix===`nothing`?``:` `,bookmark:o})}),f}function dl(e,t,n){let r;e.forEach((e,t)=>{!r&&t+e.nodeSize>n&&e.attrs.section&&(r=e.attrs.section)});let{pageSize:i,margins:a}=r??t.envelope.section;return(i?.width??12240)-(a?.left??1440)-(a?.right??1440)-(a?.gutter??0)}function fl(e,t,n){let r=t<n.from;return e.forEach((e,i)=>{let a=t+1+i;a>=n.from&&a<n.to&&!jc(e)&&(r||=!e.type.name.startsWith(`field`)||a===n.from)}),r}function pl(e,t){let n=[];return e.nodesBetween(t.from,t.to,(e,r)=>!e.isTextblock||(fl(e,r,t)&&r+1!==t.resultTo&&n.push(e.attrs.style??null),!1)),n}var ml=`No table of contents entries found.`;function hl(e,t){let{tr:n,word:r,report:i}=e,a=()=>tl(n.doc)[t],o=a(),s=uc(o.instruction),{switches:c}=s;for(let t of c.keys())if(!cc.includes(t)&&!zc.TOC.includes(t)){Z(e,o,`unsupported-switch`,`\\${t}`);return}let l=n.doc.type.schema,u=ul(n.doc,r,s),d=c.get(`p`)?.[0]||` `,p=cl(c.get(`n`)?.[0]),m=e=>c.has(`n`)&&e>=p[0]&&e<=p[1],{layout:h}=e.options,g=e=>{if(m(e.level)||!h)return``;let t=h.pageAt(Bc(n,e.from));return t?br(t.number,t.format):``},_=(e,t)=>(e.number?e.number+e.numberGap:``)+e.title+(m(e.level)?``:d+t),v=[],y=t=>{let n=Ea({envelope:e.envelope},`toc ${t}`);if(!n)throw new F(`No table of contents style`);return e.envelope=n.envelope,n.id};for(let e of u)v.push(y(e.level));let b=e=>h?e:e.replace(/\t[^\t\r]*(?=\r|$)/g,` `),x=n.doc.resolve(o.from).parentOffset===0,S=(x?``:`\r`)+u.map(e=>_(e,g(e))).join(`\r`),C=pl(n.doc,o).slice(+!x);if((u.length?b(S)===b(o.result):o.result===ml)&&(!u.length||v.every((e,t)=>C[t]===e))){i.unchanged++;return}i.updated++,i.rebuilt++;let ee=Tc(n.doc,`_Toc`),te=gl(e.state,n),T=l.nodes.bookmarkStart,E=l.nodes.bookmarkEnd,D=u.filter(e=>!e.bookmark),O=new Map(D.map(e=>[e,te++]));for(let e of D)e.bookmark=ee();for(let e of D.reverse()){let t=O.get(e);n.insert(e.to,E.create({id:t})),n.insert(e.from,T.create({id:t,name:e.bookmark}))}o=a();let k=c.has(`h`),ne=k&&Ea({envelope:e.envelope},`Hyperlink`,`character`);ne&&(e.envelope=ne.envelope);let re=dl(n.doc,r,o.from)-10,ie=n.doc.resolve(o.from);n.doc.resolve(o.resultTo);let A=ie.parent.attrs.controls??null,j=(e,t,n)=>l.nodes[e].create(t??null,null,n??[]),ae=u.map((t,n)=>{let r=k?[l.mark(`link`,{anchor:t.bookmark})]:[],i=ne?[...r,l.mark(`characterStyle`,{id:ne.id})]:r,a=[];t.number&&a.push(...Mc(l,t.number+t.numberGap,i)),a.push(...Mc(l,t.title,i)),m(t.level)||(a.push(...Mc(l,d,r)),a.push(j(`fieldStart`,null,r),j(`fieldCode`,{text:` PAGEREF ${t.bookmark} \\h `},r),j(`fieldSeparator`,null,r),...Mc(l,g(t),r),j(`fieldEnd`,null,r)));let o=e.envelope.styles.find(e=>e.id===v[n])?.paragraph?.tabs??[],s=[...t.number&&t.numberGap===` `&&!o.some(e=>e.kind!==`right`)?[{position:440*t.level,kind:`left`}]:[],...d===` `&&!o.some(e=>e.kind===`right`)?[{position:re,kind:`right`,leader:`dot`}]:[]];return l.nodes.paragraph.create({style:v[n],...s.length?{tabs:s}:{},...A?{controls:A}:{}},a)});if(h||i.skipped.push({instruction:o.instruction,story:null,reason:`no-layout`}),!ae.length){n.replace(o.resultFrom,o.resultTo,new w(f.from(l.text(ml)),0,0));return}if(o.separator===null){let e=o.codeMarks??[];n.insert(o.resultTo,j(`fieldSeparator`,null,Ac(e))),o=a()}let oe=e=>{let t=[];return n.doc.nodesBetween(o.from,o.resultTo,(n,r)=>!n.isTextblock||(r!==e&&(r>ie.before()||x)&&fl(n,r,o)&&t.push({node:n,pos:r}),!1)),t},M=n.doc.resolve(o.resultTo);M.parentOffset&&(M.before()!==ie.before()&&ae.length<=oe(M.before()).length?n.delete(M.start(),o.resultTo):n.split(o.resultTo),o=a());let se=n.doc.resolve(o.resultTo),ce=se.before(),le=se.parent,ue=oe(ce),N=le.attrs.section??null;n.doc.nodesBetween(o.from,o.resultTo,(e,t)=>(e.isTextblock&&t!==ce&&(N??=e.attrs.section??null),!e.isTextblock)),N!==(le.attrs.section??null)&&n.setNodeMarkup(ce,le.type,{...le.attrs,section:N}),ae.length>ue.length&&n.insert(ce,ae.slice(ue.length));for(let e=ue.length-1;e>=0;e--){let{node:t,pos:r}=ue[e],i=ae[e];if(!i){n.delete(r,r+t.nodeSize);continue}let a=r<o.from?o.resultFrom:r+1;n.replace(a,r+1+t.content.size,new w(i.content,0,0));let{revision:s,formatChange:c}=t.attrs;n.setNodeMarkup(r,t.type,{...i.attrs,revision:s,formatChange:c})}if(!x){let e=n.doc.resolve(o.from);o.resultFrom<e.end()&&n.delete(o.resultFrom,e.end()),e.parent.attrs.section&&n.setNodeMarkup(e.before(),e.parent.type,{...e.parent.attrs,section:null})}}function gl(e,t){let n=-1;for(let r of[t.doc,...Jr(e)])r.descendants(e=>(e.type.name.startsWith(`bookmark`)&&(n=Math.max(n,e.attrs.id)),!e.isInline));return n+1}function _l(e,t,n){let r=vi(e);if(t<n)return new Set(r.filter(e=>e.from<n&&e.to>t).map(e=>e.from));let i=yi(e,t)??r.find(e=>e.to===t||e.from===t)??null;return i?.parent?.name===`TOC`&&(i=i.parent),new Set(i?[i.from]:[])}function vl(e,t,n,r,i){let a=e.story(t);if(!a||!vi(n.doc).length)return;let{state:o}=a,s=o.tr.setMeta(xl,`fields`),{updated:c,unchanged:l}=r.report;if(rl({...r,state:o,tr:s,story:t,bodyTr:r.tr}),!s.docChanged)return;let u=Vo(o,s);if(!u){r.report.updated=c,r.report.unchanged=l,r.report.skipped.push({instruction:``,story:t,reason:`untrackable`});return}let d=o.applyTransaction(u).state;i.step(new Rr(t,n,{...n,doc:d.doc},o.selection.toJSON(),d.selection.toJSON()))}function yl(e,t){for(let[n,r]of X(e)?.stories??[])if(r.doc===t)return n;return``}function bl(e,t={}){let{state:n}=e,r=X(n);if(!r)return xc();let i=Kr(n)?.state,{only:a}=t,o=a&&typeof a!=`function`?_l(n.doc,a.from,a.to):null,s=e=>{let s=n.tr.setMeta(xl,`fields`),c={state:n,tr:s,word:r,story:null,bodyTr:s,options:t,report:xc(),envelope:r.envelope,numbers:new Map,contents:e,picked:e=>typeof a==`function`?a(e):!o||[e,e.parent?.name===`TOC`?e.parent:null].some(e=>e&&o.has(Bc(s,e.from)))};return i&&(c.story=yl(i,n.doc),c.bodyTr=i.tr),rl(c),{run:c,out:Vo(n,s)}},c=s(!0);c.out||(c=s(!1));let{run:l,out:u}=c;if(!u){let e=xc();return e.skipped.push({instruction:``,story:l.story,reason:`untrackable`}),e}if(!i&&!o)for(let[t,n]of r.stories)vl(e,t,n,l,u);return u.docChanged&&(l.envelope!==r.envelope&&Zr(u,l.envelope),u.setMeta(t.continues?Ri:Li,!0),e.dispatch(u.setMeta(So,!0))),l.report}var xl=`controlEdit`,Sl=new Set([`contentLocked`,`sdtContentLocked`]),Cl=new Set([`sdtLocked`,`sdtContentLocked`]),wl=new Set([`text`,`comboBox`,`date`]),Tl=new Set([`dropDown`,`checkbox`,`picture`]),El=new Set([`checkbox`,`picture`,`repeating`,`repeatingItem`,`other`]),Dl=new Set([`insertion`,`deletion`,`formatChange`]),Ol=new Set([`commentStart`,`commentEnd`,`commentReference`]),kl=e=>e?.type.name===`controlStart`||e?.type.name===`controlEnd`,Al=e=>e.marks.some(e=>e.type.name===`deletion`),jl={text:{docPart:`DefaultPlaceholder_-1854013440`,text:`Click or tap here to enter text.`},richText:{docPart:`DefaultPlaceholder_-1854013440`,text:`Click or tap here to enter text.`},dropDown:{docPart:`DefaultPlaceholder_-1854013438`,text:`Choose an item.`},comboBox:{docPart:`DefaultPlaceholder_-1854013438`,text:`Choose an item.`},date:{docPart:`DefaultPlaceholder_-1854013437`,text:`Click or tap to enter a date.`}},Ml=` `,Nl={value:`2612`,font:`MS Gothic`},Pl={value:`2610`,font:`MS Gothic`},Fl=e=>Sl.has(e.lock??``)||!!e.binding,Il=new WeakMap;function Ll(e,t){let n=t;for(let r=e.nodeAt(n);r;r=r.firstChild){if(r.isTextblock)return n+1;if(r.isLeaf)return t;n++}return t}function Rl(e,t){let n=t;for(let r=e.resolve(n).nodeBefore;r;r=r.lastChild){if(r.isTextblock)return n-1;if(r.isLeaf)return t;n--}return t}function zl(e){let t=Il.get(e);if(t)return t;let n=[],r=new Set,i=(e,t)=>{let i=[];e.forEach((e,a)=>{let o=e.attrs.id;if(e.type.name===`controlStart`)i.push({id:o,at:t+a});else if(e.type.name===`controlEnd`){let e=i.map(e=>e.id).lastIndexOf(o);if(e<0){r.add(o);return}let{at:s}=i.splice(e,1)[0],c=t+a;n.push({id:o,level:`inline`,from:s,to:c+1,contentFrom:s+1,contentTo:c})}});for(let{id:e}of i)r.add(e)},a=(t,r)=>{let o=new Map,s=[];t.forEach((e,t,n)=>{let c=r+t,l=c+e.nodeSize;for(let t of e.attrs.controls??[]){let r=o.get(t);if(r&&r.index===n-1){r.index=n,r.to=l;continue}let i=e.type.name,a={index:n,from:c,to:l,level:i===`tableRow`?`row`:i===`tableCell`?`cell`:`block`};o.set(t,a),s.push({id:t,run:a})}e.isTextblock?i(e,c+1):e.isLeaf||a(e,c+1)});for(let{id:t,run:r}of s)n.push({id:t,level:r.level,from:r.from,to:r.to,contentFrom:Ll(e,r.from),contentTo:Rl(e,r.to)})};a(e,0),n.sort((e,t)=>e.from-t.from||t.to-e.to);let o={ranges:n,unpaired:r};return Il.set(e,o),o}var Bl=e=>zl(e).ranges;function Vl(e,t){let n=null;for(let r of Bl(e)){if(r.from>=t)break;t<r.to&&(n=r)}return n}var Hl=(e,t)=>{let n=X(e)?.envelope.controls;return n&&Object.hasOwn(n,t)?n[t]:void 0};function Ul(e,t,n){if(t===n)return!0;let r=Math.min(t,n),i=Math.max(t,n);if(e.resolve(r).parent!==e.resolve(i).parent)return!1;let a=!0;return e.nodesBetween(r,i,e=>(e.isInline&&!kl(e)&&(a=!1),a)),a}function Wl(e,t,n,r){if(!t)return!1;let i=e=>Object.hasOwn(t,e)?t[e]:void 0,a=Bl(e);return a.some(e=>{let t=i(e.id);return!t||!Fl(t)||t.deleted||e.from>=Math.max(r,n+1)||n>=e.to?!1:!a.some(t=>{let a=i(t.id);return t!==e&&t.from>=e.from&&t.to<=e.to&&t.from<n&&r<t.to&&!!a&&!Fl(a)})})}var Gl=(e,t)=>t.level===`inline`?e.slice(t.from+1,t.to-1).content:e.slice(t.from,t.to).content;function Kl(e,t){let n=new Map;t.forEach((e,t)=>{let r=n.get(e.id);r?r.push(t):n.set(e.id,[t])});let r=new Map,i=new Map;for(let t of e){let e=r.get(t.id)??0;r.set(t.id,e+1);let a=n.get(t.id)?.[e];a!==void 0&&i.set(t,a)}return i}function ql(e,t){let n=Math.min(e.childCount,t.childCount),r=0,i=0;for(;r<n&&e.child(r)===t.child(r);)i+=e.child(r).nodeSize,r++;let a=i,o=e.content.size,s=t.content.size;for(let i=1;i<=n-r;i++){let n=e.child(e.childCount-i);if(n!==t.child(t.childCount-i))break;o-=n.nodeSize,s-=n.nodeSize}return{fromA:i,toA:o,fromB:a,toB:s}}function Jl(e,t){let n=e[t],r=[],i=-1;for(let a=t+1;a<e.length;a++){let t=e[a];if(t.from>=n.to)break;t.to>n.to||t.from<i||(r.push(t),i=t.to)}return r}function Yl(e,t,n,r){let[i,a]=t.level===`inline`?[t.from+1,t.to-1]:[t.from,t.to],o=e=>e.level===`inline`?e.contentFrom:e.from,s=e=>e.level===`inline`?e.contentTo:e.to,c=[],l=null,u=0,d=-1;return e.nodesBetween(i,a,(e,t)=>{for(;n[u]&&t>=s(n[u]);)u++;let i=n[u];if(i&&t>=o(i))return i.level!==`inline`&&d!==u&&(d=u,l=null,c.push(`[${i.id}]`)),!1;if(Ol.has(e.type.name))return!1;let a=JSON.stringify(e.marks.filter(e=>r||e.type.name===`insertion`||e.type.name===`deletion`).map(e=>e.toJSON()));if(e.isText)return l===a?c[c.length-1]+=e.text??``:c.push(`${a}:${e.text}`),l=a,!1;l=null;let f=r||e.isInline?JSON.stringify(e.attrs):``;return c.push(`<${e.type.name}${f}${a}>`),!0}),c.join(``)}var Xl=(e,t)=>t.some(([t,n])=>t<=e.contentFrom&&n>=e.contentTo&&(t<e.contentFrom||n>e.contentTo));function Zl(e,t){let n=[];return Gl(e,t).forEach(e=>{e.isInline?n.push(e):e.descendants(e=>(e.isInline&&n.push(e),!0))}),n}function Ql(e,t,n,r){if(t.level!==`inline`){let n=e.nodeAt(t.from);if(!(t.level===`cell`?n?.childCount===1&&n.firstChild?.isTextblock:n?.isTextblock&&n.nodeSize===t.to-t.from))return!1}let i=new Set(r.map(e=>e.type.name));return Zl(e,t).every(e=>e.isText||i.has(e.type.name)||Ol.has(e.type.name)||e.type.name===`hardBreak`&&n.multiLine===!0)}function $l(e,t){if(!e.docChanged||e.doc===t.doc||e.getMeta(`historyOp`))return!0;let n=X(t)?.envelope.controls;if(!n)return!0;let r=zl(t.doc);if(!r.ranges.length)return!0;let i=zl(e.doc),a=e.getMeta(xl),o=e.getMeta(`trackedDeletes`)??[],s=Kl(r.ranges,i.ranges),c=ql(t.doc,e.doc);for(let[l,u]of r.ranges.entries()){let d=Object.hasOwn(n,u.id)?n[u.id]:void 0;if(!d)continue;if(i.unpaired.has(u.id)&&!r.unpaired.has(u.id))return!1;let f=s.get(u);if(f===void 0){if(Cl.has(d.lock??``))return!1;continue}if(u.to<=c.fromA||u.from>=c.toA)continue;let p=i.ranges[f];if(Gl(t.doc,u).eq(Gl(e.doc,p)))continue;if(Xl(u,o)){if(Cl.has(d.lock??``))return!1;continue}if(a===`fields`||a===`accept`||a===`reject`)continue;let m=Fl(d);if(m||Tl.has(d.kind)&&!a){if(Yl(t.doc,u,Jl(r.ranges,l),m)!==Yl(e.doc,p,Jl(i.ranges,f),m))return!1}else if(wl.has(d.kind)&&!Ql(e.doc,p,d,Zl(t.doc,u)))return!1}return!0}function eu(e){return Sa(e,`Placeholder Text`,`character`)}var tu=e=>e.placeholder?.text??(e.placeholder?.docPart?.startsWith(`DefaultPlaceholder_`)?jl[e.kind]?.text??Ml:Ml);function nu(e,t,n){let r=tu(t);if(r===Ml)return{run:e.schema.text(r),envelope:n};let i=Ea({envelope:n},`Placeholder Text`,`character`),a=i&&e.schema.marks.characterStyle?.create({id:i.id});return{run:e.schema.text(r,a?[a]:[]),envelope:i?.envelope??n}}var ru=(e,t)=>t.mapping.map(e.contentFrom,1)>=t.mapping.map(e.contentTo,-1),iu=(e,t)=>(t.format??[]).map(t=>e.schema.markFromJSON(t));function au(e,t,n,r,i){e.doc.nodesBetween(t,n,(t,n)=>{if(!t.isText)return!0;let a=n+t.nodeSize,o=e=>!!r&&(e.type.name===`characterStyle`&&e.attrs.id===r||e.type.name===`runExt`&&String(e.attrs.xml).includes(`"${r}"`));for(let r of t.marks)o(r)&&e.removeMark(n,a,r);let s=t.marks.filter(e=>!o(e));for(let t of i)s.some(e=>e.type===t.type)||e.addMark(n,a,t);return!1})}function ou(e,t,n){let r=n.checkedState??Nl,i=n.uncheckedState??Pl,a=yu(e,t);if(a===Tu(r))return!0;if(a===Tu(i))return!1;for(let n of Zl(e,t)){let e=/:char="([0-9a-f]+)"/i.exec(String(n.attrs.xml??``))?.[1];if(!e||Al(n))continue;let t=Number.parseInt(e,16)&255;if(t===(Number.parseInt(r.value,16)&255))return!0;if(t===(Number.parseInt(i.value,16)&255))return!1}return null}function su(e){try{return[`long`,`short`].map(t=>{let n=new Intl.DateTimeFormat(e,{month:t,timeZone:`UTC`});return Array.from({length:12},(e,t)=>n.format(Date.UTC(2024,t,1)).toLowerCase().replace(/\.$/,``))})}catch{return null}}function cu(e,t){let n=su(e.ext&&/:lid\b[^>]*:val="([^"]+)"/.exec(e.ext)?.[1]||`en-US`)??[],r=[],i=(e.dateFormat??`d MMMM yyyy`).replace(/'[^']*'|d+|M+|y+|[Hhms]+|[AaPp]{2}|[.*+?^${}()|[\]\\/]/g,e=>e[0]===`'`?e.slice(1,-1).replace(/[.*+?^${}()|[\]\\]/g,`\\$&`):/^[.*+?^${}()|[\]\\/]$/.test(e)?`\\${e}`:e[0]===`d`&&e.length>2?`\\p{L}+\\.?`:((e[0]===`d`||e[0]===`y`||e[0]===`M`)&&r.push(e),e[0]===`M`&&e.length>2?`(\\p{L}+)\\.?`:e[0]===`d`||e[0]===`M`||e[0]===`y`?`(\\d+)`:`\\S+`)),a=RegExp(`^\\s*${i}\\s*$`,`iu`).exec(t);if(!a)return null;let[o,s,c]=[0,0,0];return r.forEach((e,t)=>{let r=a[t+1];if(e[0]===`d`)o=Number(r);else if(e[0]===`y`)c=Number(r)+(e.length<3?2e3:0);else if(e.length<3)s=Number(r);else{let e=r.toLowerCase();for(let t of n)t.includes(e)&&(s=t.indexOf(e)+1)}}),lu(c,s,o)}function lu(e,t,n){let r=new Date(Date.UTC(2e3,t-1,n));if(r.setUTCFullYear(e,t-1,n),r.getUTCMonth()!==t-1||r.getUTCDate()!==n)return null;let i=(e,t=2)=>String(e).padStart(t,`0`);return`${i(e,4)}-${i(t)}-${i(n)}T00:00:00Z`}function uu(e,t,n,r){let i=e=>e.marks.filter(e=>!Dl.has(e.type.name)),a=[];e.doc.nodesBetween(t,n,(e,t)=>(e.isText&&a.push({node:e,pos:t}),!0));let o=(e,t)=>e.length===t.length&&e.every(e=>t.some(t=>t.eq(e)));if(!a.length)return;let s=i(a[0].node);if(a.every(e=>o(i(e.node),s)))return;let c=a.map(e=>i(e.node)).find(e=>!r||!o(e,r))??s;for(let{node:t,pos:n}of a){let r=n+t.nodeSize;for(let a of i(t))c.some(e=>e.eq(a))||e.removeMark(n,r,a);for(let i of c)i.isInSet(t.marks)||e.addMark(n,r,i)}}function du(e,t,n,r){let i=X(r).envelope,a=i.controls,o=X(n)?.envelope.controls,s=Bl(n.doc),c=Bl(e.doc);if(!o||!s.length||!c.length)return a;let l=new Map;for(let[e,t]of Kl(s,c))l.set(c[t],e);let u=ql(n.doc,r.doc),d=new Oe(t.flatMap(e=>e.mapping.maps)),f=t.map(e=>e.getMeta(xl)).find(Boolean),p=f===`accept`||f===`reject`,m=t.flatMap(e=>e.getMeta(`trackedDeletes`)??[]),h=i,g={...a},_=!1,v=(e,t)=>{g[e]=t,_=!0},y=(t,n)=>{let i=nu(r,n,h);h=i.envelope,e.insert(e.mapping.map(t.contentFrom,-1),i.run),n.placeholder?.showing||v(t.id,{...n,placeholder:{...n.placeholder,showing:!0}})},b=t=>{if(t.level===`inline`){e.delete(e.mapping.map(t.to,-1)-1,e.mapping.map(t.to,-1));let n=e.mapping.map(t.from,1);e.delete(n,n+1)}else e.doc.nodesBetween(e.mapping.map(t.from,1),e.mapping.map(t.to,-1),(n,r)=>{let i=n.attrs.controls;if(i?.includes(t.id)){let a=i.filter(e=>e!==t.id);e.setNodeMarkup(r,n.type,{...n.attrs,controls:a.length?a:null})}return!0})};for(let t of[...c].reverse()){if(t.to<=u.fromB||t.from>=u.toB)continue;let i=Object.hasOwn(g,t.id)?g[t.id]:void 0,a=l.get(t);if(!i||!a||Gl(n.doc,a).eq(Gl(r.doc,t)))continue;if(Xl(a,m)){i.deleted||v(t.id,{...i,deleted:!0});continue}if(i.deleted&&p){let{deleted:n,...r}=i;if(f===`accept`&&!ru(t,e))continue;if(v(t.id,r),f===`accept`){b(t);continue}i=r}let s=o[t.id]?.placeholder?.showing===!0;if(s){let t=e.mapping.map(d.map(a.contentFrom,1),1),n=e.mapping.map(d.map(a.contentTo,-1),-1);t<n&&e.delete(t,n)}if(ru(t,e)&&!El.has(i.kind))y(t,i);else{if(s&&(au(e,e.mapping.map(t.contentFrom,-1),e.mapping.map(t.contentTo,1),eu({envelope:h}),iu(r,i)),i.placeholder?.showing&&(i={...i,placeholder:{...i.placeholder,showing:!1}},v(t.id,i))),i.kind===`checkbox`&&p){let e=ou(r.doc,t,i);e!==null&&e!==i.checked&&v(t.id,{...i,checked:e})}if(f!==`value`&&f!==`fields`){if(i.kind===`date`){let e=yu(r.doc,t);if(s||e!==yu(n.doc,a)){let{date:n,...r}=i,a=cu(i,e);a!==(n??null)&&v(t.id,a?{...r,date:a}:r)}}if(wl.has(i.kind)&&!s&&!p){let r=Zl(n.doc,a).find(e=>e.isText);uu(e,e.mapping.map(t.contentFrom,-1),e.mapping.map(t.contentTo,1),r?r.marks.filter(e=>!Dl.has(e.type.name)):null)}}}}return h!==i&&Zr(e,h),_?(Hr(r,e,`controls`,g),g):a}function fu(e,t,n,r,i){if(!(t instanceof R))return null;let a=Bl(e);if(!a.length)return null;let{anchor:o,head:s}=t,c=(e,t)=>e.from<t&&t<e.to;if(o!==s)for(let t=0,n=!0;n&&t<8;t++){n=!1;for(let t of a){if(t.level!==`inline`||c(t,o)===c(t,s))continue;n=!0;let r=c(t,o),i=r?s:o,a=i<=t.from?t.contentFrom:t.contentTo;Ul(e,i,a)?r?s=a:o=a:r?o=i<=t.from?t.to:t.from:s=i<=t.from?t.to:t.from}}let l=Math.min(o,s),u=Math.max(o,s),d=Vl(e,l),f=d&&Object.hasOwn(i,d.id)?i[d.id]:void 0;if(d&&f?.placeholder?.showing&&u<d.to&&d.contentFrom<d.contentTo){let{contentFrom:t,contentTo:i}=d,a=l===t&&u===i,c=r&&n.from===t&&n.to===i;if(l===u&&c&&(l===t||l===i)){if(d.level===`inline`)o=l===i?d.to:d.from,s=o;else return L.near(e.resolve(l===i?d.to:d.from),l===i?1:-1)}else a||(o=t,s=i)}return o===t.anchor&&s===t.head?null:R.create(e,o,s)}var pu=(e,t,n)=>(t?.(e.tr.setSelection(R.create(e.doc,n.contentFrom,n.contentTo))),!0),mu=e=>{let{from:t,to:n}=e.selection,r=Vl(e.doc,t);return r&&Hl(e,r.id)?.placeholder?.showing&&t===r.contentFrom&&n===r.contentTo?r:null},hu=e=>(t,n)=>{if(!X(t)?.envelope.controls)return!1;if(mu(t))return!0;let{selection:r,doc:i}=t;if(!r.empty||!(r instanceof R))return!1;let{$from:a}=r,o=e?a.nodeAfter:a.nodeBefore;if(kl(o)){if(o?.type.name!==(e?`controlStart`:`controlEnd`))return!0;let r=Vl(i,a.pos+(e?1:-1));return r?pu(t,n,r):!1}if(e?a.parentOffset<a.parent.content.size:a.parentOffset>0)return!1;let s=Bl(i).filter(e=>e.level!==`inline`);if(s.some(t=>(e?t.contentTo:t.contentFrom)===a.pos))return!0;let c=e?a.after():a.before(),l=s.find(t=>(e?t.from:t.to)===c);return l?pu(t,n,l):!1},gu=(e,t)=>{let n=Vl(e.doc,e.selection.from),r=n&&Hl(e,n.id);return!n||!r?!1:mu(e)?!0:wl.has(r.kind)?!r.multiLine||Os(e,t):n.level===`inline`},_u=(e,t)=>{let n=Vl(e.doc,e.selection.from),r=n&&Hl(e,n.id);return!n||r?.kind!==`checkbox`?!1:(Fu(n.id,!r.checked)(e,t),!0)};function vu(){return new $e({filterTransaction:$l,appendTransaction(e,t,n){let r=X(n)?.envelope.controls;if(!r)return null;let i=n.tr,a=t.doc!==n.doc&&!e.some(e=>e.getMeta(`historyOp`))?du(i,e,t,n):r,o=fu(i.doc,i.selection,t.selection,t.doc===n.doc,a);return o&&i.setSelection(o),i.steps.length||o?i:null},keymap:{Backspace:hu(!1),Delete:hu(!0),Enter:gu," ":_u}})}function yu(e,t){let n=``,r=0,i=e=>{if(e.isTextblock&&r++&&(n+=`
|
|
5
|
-
`),e.isInline){if(
|
|
6
|
-
`:e.type.name===`tab`&&(n+=` `)}else e.forEach(i)};return
|
|
7
|
-
`).flatMap((e,t)=>[...t?[r.nodes.hardBreak?.create(null,null,n)]:[],...e?[r.text(e,n)]:[]])}function Du(e,t,n){if(n.placeholder?.showing)return iu(e,n);let r=Zl(e.doc,t).find(e=>e.isText);return r?r.marks.filter(e=>!Dl.has(e.type.name)):[]}function Ou(e,t,n,r){if(!Au(e.doc,t)&&!(n.kind===`richText`&&ju(r)))return null;let i=Du(e,t,n),a=n;if(r===null||r===``)return n.kind===`checkbox`?null:{nodes:[],control:n};let o=t=>({nodes:Eu(e,t,i),control:a});switch(n.kind){case`text`:return typeof r==`string`?o(n.multiLine?r:r.replace(/\r\n?|\n/g,` `)):null;case`richText`:{if(typeof r==`string`)return o(r);if(typeof r!=`object`||r instanceof Date||!Array.isArray(r.content)||!Nu(e,t,r.content))return null;if(!r.content.length)return{nodes:[],control:n};if(t.level===`row`){let t=r.content.map(t=>e.schema.nodeFromJSON(t));return t.every(e=>e.type.name===`tableRow`)?{nodes:t,blocks:!0,control:a}:null}let i=r.content.every(t=>e.schema.nodes[t.type]?.isInline)?r.content.map(t=>e.schema.nodeFromJSON(t)):Mu(r.content);if(i.every(e=>e.isInline))return{nodes:i,control:a};if(t.level===`inline`){let e=i.length===1?i[0]:void 0;if(!e?.isTextblock)return null;let t=[];return e.forEach(e=>{t.push(e)}),{nodes:t,control:a}}return i.at(-1)?.type.name===`table`?null:{nodes:i,blocks:!0,control:a}}case`dropDown`:case`comboBox`:{if(typeof r!=`string`)return null;let e=n.items?.find(e=>e.value===r||e.display===r);return!e&&n.kind===`dropDown`?null:o(e?e.display??e.value:r)}case`date`:{let e=Cu(r);if(e)return{...o(wu(n,e)),control:{...a,date:e}};if(typeof r!=`string`)return null;let{date:t,...i}=a;return{...o(r),control:i}}case`checkbox`:{if(typeof r!=`boolean`)return null;let t=r?n.checkedState??Nl:n.uncheckedState??Pl,a=e.schema.marks.font,o=a&&t.font?Pu(a,t.font):null,s=i.filter(e=>e.type!==a);return{nodes:[e.schema.text(Tu(t),o?o.addToSet(s):i)],control:{...n,checked:r}}}default:return null}}function ku(e,t){let n=e.nodeAt(t.from)?.attrs.controls??[];return n.slice(0,n.indexOf(t.id)+1)}function Au(e,t){if(t.level===`inline`)return!0;if(t.level===`row`)return!1;let n=e.resolve(t.contentFrom),r=e.resolve(t.contentTo);return n.parent.isTextblock&&r.parent.isTextblock&&n.depth===r.depth&&n.node(n.depth-1)===r.node(r.depth-1)}var ju=e=>typeof e==`object`&&!!e&&`content`in e;function Mu(e){let t=[];return kn({type:`doc`,content:e},`content`,!0).forEach(e=>{t.push(e)}),t}function Nu(e,t,n){let r=X(e)?.envelope.controls??{},i=new Set(Bl(e.doc).filter(e=>e===t||e.from<t.from||e.to>t.to).map(e=>e.id)),a=e=>typeof e==`string`&&Object.hasOwn(r,e)&&!i.has(e),o=t.level===`inline`?[]:ku(e.doc,t),s=e.doc.resolve(t.contentFrom),c=!1;for(let e=s.depth;e>0;e--)c||=s.node(e).type.name===`tableCell`;let l=new Map,u=e=>{if(typeof e!=`object`||!e||typeof e.type!=`string`)return!1;let t=e.attrs;if(Ol.has(e.type)||e.type===`noteReference`||e.type===`noteMark`||c&&(e.type===`pageBreak`||e.type===`columnBreak`)||t?.section)return!1;if(e.type===`controlStart`||e.type===`controlEnd`){if(!a(t?.id))return!1;let n=t?.id;l.set(n,(l.get(n)??0)+(e.type===`controlStart`?1:-1))}let n=t?.controls;return n!=null&&!(Array.isArray(n)&&n.every(e=>o.includes(e)||a(e)))||e.marks?.some(e=>e.type===`link`&&!ue(e.attrs))?!1:e.content===void 0||Array.isArray(e.content)&&e.content.every(u)};return n.every(u)&&[...l.values()].every(e=>e===0)}function Pu(e,t){return e.create({ascii:t,hAnsi:t,eastAsia:t,...t===`MS Gothic`?{hint:`eastAsia`}:{}})}function Fu(e,t,n=!1){return(r,a)=>{let o=X(r);if(!o?.envelope.controls)return!1;let s=[];try{for(let n of Su(r,e)){let e=Hl(r,n.id);if(!e||Fl(e))continue;let i=Ou(r,n,e,t);i&&s.push({range:n,next:i})}}catch(e){if(e instanceof i)return!1;throw e}if(!s.length)return!1;let c=r.tr;c.setMeta(xl,`value`).setMeta(n?Ri:Li,!0);let l={...o.envelope.controls};try{for(let{range:e,next:t}of[...s].reverse())if(l[e.id]=t.control,t.blocks){let n=ku(r.doc,e),i=e.level===`cell`,a=t.nodes.map(e=>i?e:e.type.create({...e.attrs,controls:[...n,...(e.attrs.controls??[]).filter(e=>!n.includes(e))]},e.content,e.marks)),[o,s]=i?[e.from+1,e.to-1]:[e.from,e.to];c.replace(o,s,new w(f.fromArray(a),0,0))}else e.contentTo>e.contentFrom&&c.delete(e.contentFrom,e.contentTo),t.nodes.length&&c.insert(e.contentFrom,t.nodes)}catch(e){if(e instanceof F)return!1;throw e}Hr(r,c,`controls`,l);let u=Vo(r,c);return!u||!r.applyTransaction(u).transactions.length?!1:(a?.(c),!0)}}[...Ol];var Iu=Ha,Lu=e=>t=>{let n=t?.toLowerCase()??null;return n!==null&&!N(n)?()=>!1:e(n)},Ru=Lu(Fa),zu=Lu(Ia),Bu=to,Vu=eo,Hu=ao,Uu=ro,Wu=io,Gu=oo;function Ku(){return new $e({keymap:{Enter:Hu,Backspace:Gu,Tab:Uu,"Shift-Tab":Wu,"Mod-Shift-7":Vu(`orderedList`),"Mod-Shift-8":Vu(`bulletList`)}})}var qu={insertion:`insertion`,deletion:`deletion`,formatChange:`formatting`},Ju=new Set(cn);function Yu(e,t){let n=[],r=e.content.size;t?.change&&e.lastChild?.isTextblock&&n.push({kind:`sectionFormatting`,id:t.change.id,author:t.change.author,date:t.change.date??null,from:r-1,to:r,move:null});let i=e=>{let t=e.mark.attrs;n.push({kind:qu[e.mark.type.name],id:t.id,author:t.author,date:t.date??null,from:e.from,to:e.to,move:t.move??null})};return e.descendants((e,t)=>{if(e.type.name===`tableRow`){let r=e.attrs.revision;for(let[i,a]of[[`rowInsertion`,r?.insertion],[`rowDeletion`,r?.deletion]])a&&n.push({kind:i,id:a.id,author:a.author,date:a.date??null,from:t,to:t+e.nodeSize,move:null});return!0}if(!e.isTextblock)return!0;let r=e.attrs.formatChange;r&&n.push(Xu(`paragraphFormatting`,r,t,e));let a=e.attrs.section?.change;a&&n.push(Xu(`sectionFormatting`,a,t,e));let o=[];e.forEach((e,n)=>{let r=t+1+n,a=[];for(let t of e.marks){if(!qu[t.type.name])continue;let n=o.find(e=>e.to===r&&e.mark.eq(t));n&&(n.to=r+e.nodeSize),a.push(n??{mark:t,from:r,to:r+e.nodeSize})}for(let e of o)a.includes(e)||i(e);o=a});for(let e of o)i(e);let s=e.attrs.revision;return s?.insertion&&n.push(Xu(`paragraphInsertion`,s.insertion,t,e)),s?.deletion&&n.push(Xu(`paragraphDeletion`,s.deletion,t,e)),!1}),n.sort((e,t)=>e.from-t.from||e.to-t.to)}function Xu(e,t,n,r){let i=n+r.nodeSize;return{kind:e,id:t.id,author:t.author,date:t.date??null,from:e===`paragraphFormatting`?n+1:i-1,to:e===`paragraphFormatting`?i-1:i,move:null}}var Zu=new Set([`insertion`,`deletion`,`formatting`]),Qu=new Set([`bookmarkStart`,`bookmarkEnd`,`commentStart`,`commentEnd`,`controlStart`,`controlEnd`]);function $u(e,t,n,r,i={}){let a=Yu(e,t).filter(e=>!i.author||e.author===i.author),o;if(n===r){let e=a.filter(e=>e.from<=n&&n<=e.to),t=e.filter(e=>e.kind!==`paragraphFormatting`&&e.kind!==`sectionFormatting`);o=t.length?t:e}else o=a.filter(e=>e.from<r&&n<e.to).map(e=>Zu.has(e.kind)?{...e,from:Math.max(e.from,n),to:Math.min(e.to,r)}:e);let s=new Set(o.map(e=>e.move).filter(e=>e!==null)),c=a.filter(e=>e.move!==null&&s.has(e.move)&&!o.some(t=>t.id===e.id&&t.kind===e.kind));return[...o,...c]}function ed(e,t,n,r){let i=t.doc.type.schema,a=[],o=[],s=new Map,c=!1,l=[...n.filter(e=>e.kind===`sectionFormatting`),...n.filter(e=>e.kind!==`sectionFormatting`)];for(let n of l){let{kind:l,from:u,to:d}=n,f=i.marks[l===`formatting`?`formatChange`:l];switch(l){case`insertion`:case`deletion`:if(!f)break;l===`insertion`===r?nd(t,u,d,f.name,n.id):a.push([u,d]);break;case`formatting`:t.doc.nodesBetween(u,d,(e,a)=>{if(!e.isInline)return!0;let o=e.marks.find(e=>e.type.name===`formatChange`);if(!o||o.attrs.id!==n.id)return!1;let s=Math.max(a,u),c=Math.min(a+e.nodeSize,d);if(!r){for(let n of e.marks)Ju.has(n.type.name)&&t.removeMark(s,c,n);for(let e of o.attrs.previous)t.addMark(s,c,i.mark(e.type,e.attrs??null))}return t.removeMark(s,c,o),!1});break;case`paragraphFormatting`:{let e=t.doc.resolve(u).before(),n=t.doc.nodeAt(e);if(!n?.isTextblock)break;let i={...n.attrs,formatChange:null};if(!r){let e=n.attrs.formatChange.previous;for(let t of Do)i[t]=e[t]??null}t.setNodeMarkup(e,n.type,i);break}case`sectionFormatting`:{let i=t.doc.resolve(u).before(),a=t.doc.nodeAt(i),o=a?.attrs.section;a&&o?.change?.id===n.id?t.setNodeMarkup(i,a.type,{...a.attrs,section:rs(o,r)}):Hr(e,t,`section`,rs(Zo(e,t),r));break}case`rowInsertion`:case`rowDeletion`:{let e=t.doc.nodeAt(u);if(e?.type.name!==`tableRow`)break;if(l===`rowDeletion`===r){let e=t.doc.resolve(u).before();s.set(e,[...s.get(e)??[],[u,d]])}else{let n={...e.attrs.revision};delete n[l===`rowInsertion`?`insertion`:`deletion`];let r=Object.keys(n).length?n:null;t.setNodeMarkup(u,e.type,{...e.attrs,revision:r})}break}case`paragraphInsertion`:case`paragraphDeletion`:{let n=t.doc.resolve(u).before(),i=t.doc.nodeAt(n);if(!i?.isTextblock)break;let s={...i.attrs.revision},d=l===`paragraphDeletion`===r;delete s[l===`paragraphInsertion`?`insertion`:`deletion`];let f=Object.keys(s).length?s:null;t.setNodeMarkup(n,i.type,{...i.attrs,revision:f});let p=n+i.nodeSize,m=td(i,n+1,a),h=d&&!!t.doc.resolve(p).nodeAfter?.isTextblock,g=i.attrs.section;d&&g&&($o(e,t,g,p),h||t.setNodeMarkup(n,i.type,{...i.attrs,revision:f,section:null})),h?o.push({pos:p,keepFirst:r&&!m}):d&&!r&&(!i.content.size||m)&&t.doc.resolve(n).parent.childCount>1&&(a.push([n,p]),c=!0);break}}}for(let[e,n]of s){let r=t.doc.nodeAt(e);r&&n.length===r.childCount?a.push([e,e+r.nodeSize]):a.push(...n)}if(s.size||c){let e=a.filter(([e,t])=>!a.some(([n,r])=>n<e&&t<=r||n<=e&&t<r));a.length=0,a.push(...e)}let u=[...a.map(([e,n])=>({at:e,run:()=>t.delete(e,n)})),...o.filter(({pos:e})=>!(s.size||c)||!a.some(([t,n])=>t<e&&e<n)).map(({pos:e,keepFirst:n})=>({at:e-1,run:()=>rd(t,e,n)}))].sort((e,t)=>t.at-e.at);for(let e of u)e.run();oa(t)}function td(e,t,n){let r=!0;return e.forEach((e,i)=>{let a=t+i;Qu.has(e.type.name)||n.some(([t,n])=>t<=a&&a+e.nodeSize<=n)||(r=!1)}),r}function nd(e,t,n,r,i){e.doc.nodesBetween(t,n,(a,o)=>{if(!a.isInline)return!0;let s=a.marks.find(e=>e.type.name===r&&e.attrs.id===i);return s&&e.removeMark(Math.max(o,t),Math.min(o+a.nodeSize,n),s),!1})}function rd(e,t,n){let r=e.doc.resolve(t),i=r.nodeBefore,a=r.nodeAfter;if(!i?.isTextblock||!a?.isTextblock)return;let o=t-i.nodeSize;e.join(t);let s=n?{...i.attrs}:{...a.attrs};if(n)for(let e of qe)s[e]=a.attrs[e]??null;e.setNodeMarkup(o,i.type,s)}function id(e,t,n,r,i){let a=Wr(e,t,n);if(!a)return;let o=i===`insertion`?`paragraphInsertion`:`paragraphDeletion`,s=$u(a.doc,void 0,0,a.doc.content.size).filter(e=>e.kind===i||e.kind===o);if(!s.length)return;let c=qr(e,a.doc),l=c.tr;ed(c,l,s,r),t.step(new Rr(n,a,{...a,doc:l.doc}))}function ad(e,t,n,r=!1){let i=(a,o)=>{if(!a.schema.marks.insertion)return!1;let s=r?Kr(a):null;if(s)return o?s.run(i):s.can(i);let c=X(a)?.envelope.controls,l=t=>n=>n.kind.toLowerCase().includes(`deletion`)!==e||!Wl(t,c,n.from,n.to),u=new Set,d=t(a).flatMap(e=>$u(a.doc,X(a)?.envelope.section,e.from,e.to,n)).filter(l(a.doc)).filter(e=>{let t=`${e.kind} ${e.id} ${e.from} ${e.to}`;return!u.has(t)&&!!u.add(t)}),f=r?[...X(a)?.stories??[]].flatMap(([e,t])=>{let r=$u(t.doc,void 0,0,t.doc.content.size,n).filter(l(t.doc));return r.length?[{id:e,story:t,changes:r}]:[]}):[];if(!d.length&&!f.length)return!1;if(o){let t=a.tr.setMeta(So,!0).setMeta(Li,!0),n=e?`accept`:`reject`;t.setMeta(xl,n);let r=X(a)?.envelope,i=r;try{d.length&&ed(a,t,d,e);for(let{id:i,story:o,changes:s}of f){let c=nt.create({doc:o.doc,plugins:[...qr(a,o.doc,r).plugins,vu()]}),l=c.tr.setMeta(xl,n);ed(c,l,s,e);let u=c.applyTransaction(l).state;r=X(u)?.envelope,t.step(new Rr(i,o,{...o,doc:u.doc}))}r&&r!==i&&(r.styles!==i?.styles&&Zr(t,{...i,styles:r.styles}),r.controls!==i?.controls&&Hr(a,t,`controls`,r.controls))}catch(e){if(e instanceof F)return!1;throw e}o(t)}return!0};return i}var od=e=>e.selection.ranges,sd=e=>[{from:0,to:e.doc.content.size}],cd=ad(!0,od),ld=ad(!1,od),ud=e=>ad(!0,sd,e===void 0?{}:{author:e},!0),dd=e=>ad(!1,sd,e===void 0?{}:{author:e},!0);function fd(e){return(t,n)=>{let r=(jo(t)?.view??`markup`)!==`markup`,i=Yu(t.doc,X(t)?.envelope.section).filter(e=>!r||e.kind!==`deletion`&&e.kind!==`paragraphDeletion`),{from:a,to:o}=t.selection,s=e?i.find(e=>e.from>a||e.from===a&&e.to>o):[...i].reverse().find(e=>e.from<a||e.from===a&&e.to<o);if(!s)return!1;if(n){let e=s.kind===`paragraphInsertion`||s.kind===`paragraphDeletion`||s.kind===`sectionFormatting`?s.from:s.to;n(t.tr.setSelection(R.create(t.doc,s.from,e)))}return!0}}var pd=fd(!0),md=fd(!1),hd={footnote:`footnotes`,endnote:`endnotes`},gd={footnote:{position:`pageBottom`,format:`decimal`,start:1,restart:`continuous`},endnote:{position:`docEnd`,format:`lowerRoman`,start:1,restart:`continuous`}};function _d(e){return e.startsWith(`footnote:`)?`footnote`:e.startsWith(`endnote:`)?`endnote`:null}var vd=e=>(e?.kind===`footnote`||e?.kind===`endnote`)&&(e.noteType??`normal`)===`normal`;function yd(e,t,n){let r=hd[t];return{...gd[t],...e.settings?.[r],...n?.[r]}}var bd=[],xd=new WeakMap;function Sd(e){let t=xd.get(e);if(!t){let n=[];e.descendants((e,t)=>(e.type.name===`noteReference`&&n.push({story:String(e.attrs.story),offset:t+1,customMark:e.attrs.customMark===!0,insertion:e.marks.find(e=>e.type.name===`insertion`),deletion:e.marks.find(e=>e.type.name===`deletion`)}),!0)),t=n.length?n:bd,xd.set(e,t)}return t}function Cd(e,t,n={}){let r=[],i={footnote:{n:0,section:-1,page:void 0,start:1},endnote:{n:0,section:-1,page:void 0,start:1}},a=[];e.forEach(e=>{let t=e.attrs.section;t&&a.push(t)});let o=0;return e.forEach((e,s)=>{let c=a[o]??t.section;for(let a of Sd(e)){let e=_d(a.story);if(!e)continue;let l=s+a.offset,u=!!a.deletion,d={story:a.story,kind:e,pos:l,section:o,deleted:u,customMark:a.customMark};if(a.customMark||u&&n.hideDeleted){r.push({...d,text:``});continue}let f=yd(t,e,c),p=i[e],m=f.restart===`eachPage`?n.pageOf?.(l,a.story):void 0,h=p.section<0,g=p.section!==o;h||f.restart===`eachSect`&&g||f.restart===`eachPage`&&m!==void 0&&m!==p.page||g&&f.start!==p.start?p.n=f.start:p.n++,p.section=o,p.start=f.start,p.page=m,r.push({...d,text:br(p.n,f.format)})}e.attrs.section&&o++}),r}var wd=e=>new Map(e.map(e=>[e.story,e.text]));function Td(e,t,n,r){let i=qr(e,t.doc).tr,a=n.type.name,o={id:n.attrs.id,author:n.attrs.author,date:n.attrs.date};return t.doc.descendants((e,t)=>{if(e.isInline)return!Ed.has(e.type.name)&&!e.marks.some(e=>e.type.name===a)&&i.addMark(t,t+e.nodeSize,n),!1;if(e.isTextblock&&r){let n=e.attrs.revision??{};i.setNodeMarkup(t,e.type,{...e.attrs,revision:{...n,[a]:o}})}return!0}),{...t,doc:i.doc}}var Ed=new Set([`bookmarkStart`,`bookmarkEnd`,`commentStart`,`commentEnd`,`controlStart`,`controlEnd`]);function Dd(e){let t=new Map;return e.forEach(e=>{for(let n of Sd(e))t.set(n.story,n)}),t}function Od(){return new $e({appendTransaction(e,t,n){if(t.doc===n.doc||e.some(e=>e.getMeta(`historyOp`)))return null;let r=X(n);if(!r||![...r.stories.values()].some(vd))return null;let i=Dd(t.doc),a=Dd(n.doc),o=n.tr.setMeta(So,!0),s=-1,c=e=>(s<0&&(s=zo(n)),e.type.create({...e.attrs,id:s++}));for(let[e,t]of i){let r=Wr(n,o,e);if(!r||!vd(r))continue;let i=a.get(e);i?(i.deletion&&!t.deletion&&o.step(new Rr(e,r,Td(n,r,c(i.deletion),!0))),t.deletion&&!i.deletion&&id(n,o,e,!1,`deletion`),t.insertion&&!i.insertion&&id(n,o,e,!0,`insertion`)):o.step(new Rr(e,r,null))}for(let[e,t]of a){let r=Wr(n,o,e);!i.has(e)&&t.insertion&&r&&vd(r)&&o.step(new Rr(e,r,Td(n,r,c(t.insertion),!1)))}return o.steps.length?o:null}})}function kd(e,t,n,r,i,a){let o=t.stories.get(n),s=o;i.doc!==r.doc&&(s={...o,doc:i.doc},e.step(new Rr(n,o,s,r.selection.toJSON(),i.selection.toJSON())));let c=!1;for(let t of a){for(let n of t.steps)(n instanceof Pr||n instanceof Lr)&&e.step(n);c||=ei(t)!==void 0}if(c){let{numbering:n,styles:r,resources:a,controls:o}=X(i).envelope,{resources:s,controls:c,...l}=ei(e)??t.envelope;Zr(e,{...l,numbering:n,styles:r,...a?{resources:a}:{},...o?{controls:o}:{}})}return{after:s,patched:c}}var Ad=class{id;host;state;own=!1;alive=!0;listeners=new Set;constructor(e,t){this.id=e,this.host=t;let n=this.tree()?.doc;this.state=this.create(n)}tree(){return X(this.host.state)?.stories.get(this.id)}create(e){let{host:t,id:n}=this,r=X(t.state),a=r.stories.get(n)?.kind;return nt.create({doc:e,selection:L.atStart(e),plugins:[new $e({key:Gr,state:{init:()=>t,apply:()=>t}}),new $e({filterTransaction(e){if(!e.docChanged)return!0;try{return jn(e.doc,a,`story`),!0}catch(e){if(e instanceof i)return!1;throw e}}}),...t.plugins(r,jo(t.state))]})}notify(e){for(let t of this.listeners)t(this.state,e)}current(e){let t=X(this.host.state),n=jo(this.host.state);if(X(e)===t&&jo(e)===n)return e;let r=$r(e.tr,t);return n&&Mo(r,n),e.apply(r)}dispatch=e=>{if(!this.alive)return;let{host:t,id:n,state:r}=this,i=Vo(r,e);if(!i)return;let a=r.applyTransaction(i);if(!a.transactions.length)return;let o=a.state,s=t.state,c=X(s),l=c.stories.get(n),u=s.tr,{after:d,patched:f}=kd(u,c,n,r,o,a.transactions),p=jo(o),m=!!p&&p!==jo(r);if(m&&Mo(u,p),u.steps.length||f||m){u.setMeta(So,!0),u.setMeta(zi,{id:n,tr:i}),u.time=i.time,i.addToHistory||u.setMeta(`addToHistory`,!1),i.getMeta(`closeHistory`)&&u.setMeta(Li,!0),i.getMeta(`joinHistory`)&&u.setMeta(Ri,!0),this.own=!0;try{t.dispatch(u)}finally{this.own=!1}if(d!==l&&X(t.state)?.stories.get(n)!==d)return}this.state=this.current(o),this.notify(a.transactions)};sync(e){if(this.own)return;let t=this.tree();if(!t){this.retire();return}let{state:n}=this,r=null;for(let t of e)for(let e of t.steps)e instanceof Rr&&e.id===this.id&&(r=e.selectionAfter);if(t.doc!==n.doc){let e=r??n.selection.toJSON();this.state=this.current(n.withDocument(t.doc,L.fromJSON(t.doc,e))),this.notify([]);return}let i=this.current(n);i!==n&&(this.state=i,this.notify([]))}retire(){this.alive=!1}},jd={width:12240,height:15840,margin:1440};function Md(e){let t=e.margins??{};return{pageSize:{width:dt(e.pageSize?.width??jd.width),height:dt(e.pageSize?.height??jd.height)},margins:{top:dt(Math.abs(t.top??jd.margin)),right:dt(t.right??jd.margin),bottom:dt(Math.abs(t.bottom??jd.margin)),left:dt((t.left??jd.margin)+(t.gutter??0))}}}function Nd(e){let{content:t,...n}=Dn(e);return{doc:kn(t),settings:Md(n.section),envelope:n}}function Pd(e){let{dispatch:t}=e,n=n=>n(e.state(),t),r=()=>{let t=e.state(),n=[...(Kr(t)?null:X(t))?.stories??[]].filter(([,e])=>Bl(e.doc).length);return[{editor:i},...n.flatMap(([t])=>{let n=e.story(t);return n?[{editor:n,story:t}]:[]})]},i={get settings(){return e.settings()},get state(){return e.state()},dispatch:t,run:n,can:t=>t(e.state()),handleKey(n){let r=e.state();return r.plugins.some(e=>{let i=e.spec.keymap?.[n];return i?i(r,t):!1})},select(n,r=n){let i=e.state(),a=i.doc.content.size,o=e=>Math.max(0,Math.min(e,a));t(i.tr.setSelection(R.create(i.doc,o(n),o(r))))},commands:{insertText:e=>n(ds(e)),deleteSelection:()=>n(ls),deleteBackward:e=>n(_s(e)),deleteForward:e=>n(vs(e)),joinBackward:()=>n(bs),joinForward:()=>n(xs),splitBlock:()=>n(Ss),insertHardBreak:()=>n(Os),insertPageBreak:()=>n(ks),toggleMark:(e,t)=>n(Ps(e,t)),setBlockType:(e,t)=>n(Ls(e,t)),selectAll:()=>n(js),undo:()=>n(Zi),redo:()=>n(Qi),wrapInList:e=>n(Bu(e)),toggleList:e=>n(Vu(e)),indentListItem:()=>n(Uu),outdentListItem:()=>n(Wu),setLink:e=>n(_o(e)),removeLink:()=>n(vo),setAlign:e=>n(Iu(e)),setTextColor:e=>n(Ru(e)),setHighlight:e=>n(zu(e)),setTrackChanges:(e,t)=>n(No(e,t)),setReviewView:e=>n(Po(e)),acceptChange:()=>n(cd),rejectChange:()=>n(ld),acceptAllChanges:e=>n(ud(e)),rejectAllChanges:e=>n(dd(e)),nextChange:()=>n(pd),previousChange:()=>n(md),addComment:(e,t)=>n(Ys(e,t)),replyToComment:(e,t,r)=>n(Xs(e,t,r)),editComment:(e,t)=>n(Qs(e,t)),resolveComment:(e,t)=>n($s(e,t)),deleteComment:e=>n(nc(e)),deleteAllComments:()=>n(rc),setControlValue(e,t){let n=!1;for(let{editor:i}of r())i.run(Fu(e,t,n))&&(n=!0);return n}},controlValues:()=>r().flatMap(({editor:e,story:t})=>xu(e.state).map(e=>t?{...e,story:t}:e)),get trackingChanges(){return jo(e.state())?.on??!1},isMarkActive:t=>Is(e.state(),t),getDocument:e.getDocument,setDocument:e.setDocument,subscribe:e.subscribe,story:e.story,get storyView(){return e.views.current},set storyView(t){e.views.current=t},storyChanged:e.storyChanged,get navigation(){return e.views.navigation},set navigation(t){e.views.navigation=t}};return i}function Fd({document:e=En(),plugins:t=[],author:n=`Author`,trackChanges:r=!1,reviewView:i=`markup`}={}){let a=Nd(e),o={on:r,author:n,view:i},s=({envelope:e})=>[...t,Vi(),Xr(e),Ao(o),Ni(),vu(),oc(),Od(),fa(),Ku(),Rs()],c=nt.create({doc:a.doc,plugins:s(a)}),l=new Set,u={current:null,navigation:null},d=new Map,f=e=>{for(let t of l)t(c,e)},p=()=>f([]),m=e=>{let t=Vo(c,e);if(!t)return;let n=c.applyTransaction(t);if(c=n.state,n.transactions.length){for(let[e,{editing:t}]of d)t.sync(n.transactions),t.alive||d.delete(e);f(n.transactions)}},h=e=>e(c,m),g={section:a.envelope.section,settings:a.settings},_=()=>{let e=X(c)?.envelope.section??g.section;return e!==g.section&&(g={section:e,settings:Md(e)}),g.settings},v=()=>({...structuredClone(X(c)?.envelope??a.envelope),content:c.doc.toJSON()}),y=e=>{let n=new Ad(e,{get state(){return c},run:h,can:e=>e(c),dispatch:m,plugins:(e,n)=>[...t,Xr(e.envelope,e),Ao(n??o),Ni(),vu(),oc(),fa(),Ku(),Rs()]}),r=Pd({state:()=>n.state,dispatch:n.dispatch,settings:_,getDocument:()=>({...v(),content:n.state.doc.toJSON()}),setDocument(e){let{doc:t}=Nd(e),r=n.state.tr.replace(0,n.state.doc.content.size,new w(t.content,0,0));n.dispatch(r.setSelection(L.atStart(r.doc)))},subscribe(e){return n.listeners.add(e),()=>n.listeners.delete(e)},story:b,views:u,storyChanged:p});return d.set(e,{editing:n,editor:r}),r},b=e=>X(c)?.stories.has(e)?d.get(e)?.editor??y(e):null;return Pd({state:()=>c,dispatch:m,settings:_,getDocument:v,setDocument(e){o=jo(c)??o,a=Nd(e),c=nt.create({doc:a.doc,plugins:s(a)});for(let{editing:e}of d.values())e.retire();d.clear(),f([])},subscribe(e){return l.add(e),()=>l.delete(e)},story:b,views:u,storyChanged:p})}var Id=`data-page-break`,Ld=`data-column-break`,Q=96/1440,Rd=9525,zd=`data-foli-picture`;function Bd(e){let t=e?.data;if(t&&/^data:image\//i.test(t))return t;let n=e?.url;return n&&/^(https?|blob):/i.test(n)?n:void 0}function Vd(e,t,n){let r=String(e.resource??``),i=`${Number(e.width)/Rd}px`,a=`${Number(e.height)/Rd}px`,o=e.decorative===!0,s=String(e.alt??``),c=o?``:s||`Picture without alt text`,l=n?.(r),u;if(l){let e=t.createElement(`img`);e.src=l,e.alt=c,e.draggable=!1,e.referrerPolicy=`no-referrer`,u=e}else u=t.createElement(`span`),u.setAttribute(`role`,`img`),c?u.setAttribute(`aria-label`,c):u.setAttribute(`aria-hidden`,`true`),u.style.boxSizing=`border-box`,u.style.border=`1px dashed GrayText`;u.setAttribute(zd,r),!s&&!o&&(u.dataset.foliNoAlt=``),e.title&&(u.title=String(e.title));let d=u.style;return d.display=l?`inline`:`inline-block`,d.verticalAlign=`baseline`,d.maxWidth=`none`,d.maxHeight=`none`,d.width=i,d.height=a,u}var Hd=`data-foli-float`;function Ud(e){let t=e?.margins??{},n=e?.pageSize?.width??12240,r=e?.pageSize?.height??15840,i=(t.left??1440)+(t.gutter??0),a=Math.abs(t.top??1440);return{pageWidth:n*Q,pageHeight:r*Q,marginLeft:i*Q,marginTop:a*Q,textWidth:(n-i-(t.right??1440))*Q,textHeight:(r-a-Math.abs(t.bottom??1440))*Q}}function Wd(e,t){let n=t.pageWidth-t.marginLeft-t.textWidth;switch(e){case`page`:return[0,t.pageWidth];case`leftMargin`:case`insideMargin`:return[0,t.marginLeft];case`rightMargin`:case`outsideMargin`:return[t.marginLeft+t.textWidth,n];default:return[t.marginLeft,t.textWidth]}}function Gd(e,t){let n=t.pageHeight-t.marginTop-t.textHeight;switch(e){case`page`:return[0,t.pageHeight];case`topMargin`:case`insideMargin`:return[0,t.marginTop];case`bottomMargin`:case`outsideMargin`:return[t.pageHeight-n,n];default:return[t.marginTop,t.textHeight]}}function Kd(e,[t,n],r){if(typeof e.offset==`number`)return t+e.offset/Rd;let{align:i}=e;return i===`right`||i===`bottom`||i===`outside`?t+n-r:i===`center`?t+(n-r)/2:t}function qd(e,t,n){return Kd(e,Wd(e.relativeTo,n),t)-n.marginLeft}function Jd(e,t,n){return e.relativeTo===`paragraph`||e.relativeTo===`line`?{paragraph:typeof e.offset==`number`?e.offset/Rd:0}:{page:Kd(e,Gd(e.relativeTo,n),t)}}function Yd(e,t,n,r){let i=e.float,a=Number(e.width)/Rd,o=Number(e.height)/Rd,s=e=>(i.distance?.[e]??0)/Rd,c=Vd(e,t,n);c.style.display=`block`;let l=t.createElement(`span`);l.setAttribute(Hd,i.wrap),l.append(c);let u=l.style;u.display=`block`;let d=qd(i.horizontal,a,r),f=Jd(i.vertical,o,r);if(i.wrap===`behind`||i.wrap===`inFront`)return u.position=`absolute`,u.zIndex=i.wrap===`behind`?`-1`:`1`,u.left=`${r.marginLeft+d}px`,f.page===void 0?u.marginTop=`${f.paragraph}px`:u.top=`${f.page}px`,{nodes:[l],holder:l};let p=s(`top`),m=(f.paragraph??0)-p,h=t.createElement(`span`);if(h.setAttribute(`aria-hidden`,`true`),h.style.width=`0`,h.style.height=`${Math.max(0,m)}px`,u.marginTop=`${p+Math.min(0,m)}px`,u.marginBottom=`${s(`bottom`)}px`,i.wrap===`topAndBottom`)return h.style.float=`left`,u.float=`left`,u.clear=`both`,u.width=`100%`,c.style.marginLeft=`${d}px`,{nodes:[h,l],holder:l};let g=i.side===`left`||i.side!==`right`&&d+a/2>r.textWidth/2,_=g?`right`:`left`;return h.style.float=_,u.float=_,u.clear=_,g?(u.marginRight=`${r.textWidth-d-a}px`,u.marginLeft=`${s(`left`)}px`):(u.marginLeft=`${d}px`,u.marginRight=`${s(`right`)}px`),{nodes:[h,l],holder:l}}var Xd=[`#B5082E`,`#1F5FAD`,`#2E7D32`,`#8E24AA`,`#A64B00`,`#00737F`,`#AD1457`,`#5D4037`];function Zd(e){let t=0;for(let n of e)t=t*31+(n.codePointAt(0)??0)>>>0;return Xd[t%Xd.length]}function Qd(e,t,n,r,i){let a=e.createElement(t?`ins`:`del`),o=r?`, ${r.slice(0,10)}`:``;return a.title=`${t?`Inserted`:`Deleted`} by ${n||`an unknown author`}${o}`,i===`markup`?(a.style.color=Zd(n),a.style.textDecorationLine=t?`underline`:`line-through`):(a.style.textDecorationLine=`none`,t||(a.style.display=`none`)),a}var $d=`data-foli-note-ref`,ef=`data-foli-note-number`,tf=192;function nf(e,t){if(!e||![e,...e.getElementsByTagName(`*`)].some(e=>e.localName===`separator`||e.localName===`continuationSeparator`))return null;let n=t.createElement(`span`);n.dataset.foliSeparator=``;let{style:r}=n;return r.display=`inline-block`,r.width=`${tf}px`,r.maxWidth=`100%`,r.height=`0`,r.borderTop=`1px solid #000`,r.verticalAlign=`middle`,n}function rf(e,t){return n=>{let r=e&&Object.hasOwn(e,n)?e[n]:void 0;if(!r)return;let i=t?.(n,r);return i===void 0?Bd(r):i||void 0}}var af={calibri:[`Carlito`],cambria:[`Caladea`],arial:[`Liberation Sans`,`Arimo`],"times new roman":[`Liberation Serif`,`Tinos`],"courier new":[`Liberation Mono`,`Cousine`],georgia:[`Gelasio`]},of=new Set([`cambria`,`times new roman`,`georgia`,`garamond`,`book antiqua`]),sf=new Set([`courier new`,`consolas`,`courier`]);function cf(e){let t=e??`Times New Roman`,n=t.toLowerCase(),r=of.has(n)?`serif`:sf.has(n)?`monospace`:`sans-serif`,i=e=>`"${e.replace(/["\\]/g,``)}"`;return[t,...Object.hasOwn(af,n)?af[n]:[]].map(i).concat(r).join(`, `)}var lf={black:`#000000`,blue:`#0000FF`,cyan:`#00FFFF`,green:`#00FF00`,magenta:`#FF00FF`,red:`#FF0000`,yellow:`#FFFF00`,white:`#FFFFFF`,darkBlue:`#000080`,darkCyan:`#008080`,darkGreen:`#008000`,darkMagenta:`#800080`,darkRed:`#800000`,darkYellow:`#808000`,darkGray:`#808080`,lightGray:`#C0C0C0`},uf={double:`double`,dotted:`dotted`,dottedHeavy:`dotted`,dash:`dashed`,dashedHeavy:`dashed`,dashLong:`dashed`,wave:`wavy`,wavyHeavy:`wavy`,wavyDouble:`wavy`},df={left:`left`,start:`left`,right:`right`,end:`right`,center:`center`,both:`justify`,distribute:`justify`},ff={double:`double`,dotted:`dotted`,dashed:`dashed`,dashSmallGap:`dashed`,none:`none`,nil:`none`},pf=e=>e.font.ascii??e.font.hAnsi;function mf(e,t,n){let r=t.size/2*(96/72),{line:i,lineRule:a}=e.spacing;return i===null?String(n):a===`exact`?`${i*Q}px`:a===`atLeast`?`${Math.max(i*Q,n*r)}px`:String(n*i/240)}function hf(e,t,n){let{style:r}=e;r.fontFamily=cf(pf(t)),r.fontSize=`${t.size/2}pt`,r.lineHeight=n,r.fontWeight=t.bold?`700`:`400`,r.fontStyle=t.italic?`italic`:`normal`;let i=[];t.underline&&i.push(`underline`),(t.strike||t.doubleStrike)&&i.push(`line-through`),i.length&&(r.textDecorationLine=i.join(` `),t.doubleStrike||t.underline===`double`?r.textDecorationStyle=`double`:t.underline&&uf[t.underline]&&(r.textDecorationStyle=uf[t.underline]),t.underlineColor&&t.underlineColor!==`auto`&&(r.textDecorationColor=`#${t.underlineColor}`)),t.caps&&(r.textTransform=`uppercase`),t.smallCaps&&(r.fontVariant=`small-caps`),t.color&&(r.color=`#${t.color}`);let a=t.highlight?lf[t.highlight]:t.shading&&`#${t.shading}`;a&&(r.backgroundColor=a),t.verticalAlign!==`baseline`&&(r.verticalAlign=t.verticalAlign===`superscript`?`super`:`sub`,r.fontSize=`${t.size/2*(2/3)}pt`,r.lineHeight=`0`),t.characterSpacing&&(r.letterSpacing=`${t.characterSpacing*Q}px`),t.hidden&&(r.display=`none`)}function gf(e,t){let{style:n}=e;n.margin=`0`,n.whiteSpace=`pre-wrap`,n.overflowWrap=`break-word`,n.tabSize=`${720*Q}px`;let{left:r,right:i,firstLine:a,hanging:o}=t.indent;n.paddingLeft=`${r*Q}px`,n.paddingRight=`${i*Q}px`,n.textIndent=`${(a-o)*Q}px`;let s=t.justification&&df[t.justification];s&&(n.textAlign=s),t.shading?.fill&&t.shading.fill!==`auto`&&(n.backgroundColor=`#${t.shading.fill}`);for(let[e,r]of Object.entries(t.borders??{})){if(!r||e===`between`||e===`bar`)continue;let t=ff[r.style]??`solid`,i=t===`none`?0:Math.max((r.size??4)/8*(96/72),1),a=r.color&&r.color!==`auto`?`#${r.color}`:`currentColor`;n.setProperty(`border-${e}`,`${i}px ${t} ${a}`),n.setProperty(`padding-${e}`,`${(r.space??0)*96/72}px`)}}var _f=new Set([`txbxContent`,`Fallback`]);function vf(e){let t=``;for(let n of e.children)_f.has(n.localName)||(n.localName===`t`?t+=n.textContent:n.localName===`tab`?t+=` `:t+=vf(n));return t}function yf(e,t){let n=[];for(let r of e.children)t.has(r.localName)?n.push(r):_f.has(r.localName)||n.push(...yf(r,t));return n}var bf=new Set([`p`]),xf=new Set([`r`]),Sf=new Set([`tr`]),Cf=new Set([`tc`]),wf=new Set([`p`,`tbl`]);function Tf(e,t){let n=t.defaultView;if(!n?.DOMParser)return null;let r=new Set;for(let t of e.matchAll(/<\/?([A-Za-z_][\w.-]*):|\s([A-Za-z_][\w.-]*):[\w.-]+\s*=/g)){let e=t[1]??t[2];e&&e!==`xml`&&e!==`xmlns`&&r.add(e)}let i=[...r].map(e=>` xmlns:${e}="urn:foli:${e}"`).join(``),a=new n.DOMParser().parseFromString(`<foli${i}>${e}</foli>`,`application/xml`),o=a.documentElement;return o.localName!==`foli`||a.getElementsByTagName(`parsererror`).length?null:o.firstElementChild}function Ef(e,t,n={}){let r=n.review??`markup`,i=n.fieldCodes===!0,a=new Map,o=e=>{let t=a.get(e);return t===void 0&&(t=n.lineRatio?.(e)??1.2,a.set(e,t)),t},s=n.resolver??new Mr(e),c=rf(e.resources,n.resource),l=Ud(e.section),u=e.content.content??[],d=e=>e.attrs??{},f=e=>{let t=u[e],n=t&&d(t).revision;return r!==`markup`&&t?.type===`paragraph`&&!!n?.deletion&&u[e+1]?.type===`paragraph`},p=s.markers(u.map((e,t)=>e.type===`paragraph`&&!f(t-1)?d(e):{numbering:{id:0}})),m=[],h=Ti(u.map(Of),i),g=null,_=new Set;return u.forEach((e,a)=>{if(e.type!==`paragraph`){m.push(Rf(e,a,s,t,o,c,l,i,n.notes));return}let u=d(e),v=h[a];if(f(a)){let t=g??{nodes:[],inline:[],display:Df};g={nodes:[...t.nodes,a],inline:[...t.inline,...e.content??[]],display:kf(t.display,t.inline.length,v)};return}let y=g??{nodes:[],inline:[],display:Df};g=null;let b=kf(y.display,y.inline.length,v),{paragraph:x,run:S}=s.paragraph(u),C=t.createElement(Nf(x));gf(C,x);let w=s.run(S,u.markFormat??[]);hf(C,w,mf(x,w,o(cf(pf(w)))));let ee=p[a],te=y.nodes[0],T=te===void 0?ee:p[te]??null;T&&C.append(If(T,x,t,o));let E=[...y.inline,...e.content??[]];if(Lf(C,E,S,x,{resolver:s,doc:t,review:r,comments:_,ratio:o,image:c,geometry:l,codes:i,display:b,notes:n.notes}),b.gone&&(C.style.display=`none`),Af(E,e=>e.type,e=>!!e.attrs?.float))for(let e of C.querySelectorAll(`[${zd}]`))e.style.verticalAlign=`bottom`;let D=C.lastChild,O=D?.nodeName===`BR`;(O&&!D?.hasAttribute(`data-page-break`)||!O&&!C.textContent)&&C.append(t.createElement(`br`));let k=e=>e*Q,{before:ne,after:re}=x.spacing,ie=x.spacing.beforeAutospacing?280:ne,A=x.spacing.afterAutospacing?280:re;m.push({element:C,nodes:[...y.nodes,a],before:b.gone?0:k(ie),after:b.gone?0:k(A),keepNext:x.keepNext,keepLines:x.keepLines,pageBreakBefore:x.pageBreakBefore,section:u.section??null}),C.dataset.style=x.style??``,x.contextualSpacing&&(C.dataset.contextual=``)}),Pf(m,s.addsParagraphSpacing),m}var Df=Ti([[]],!1)[0],Of=e=>e.type===`paragraph`?(e.content??[]).map(e=>e.type):[];function kf(e,t,n){return t?{hidden:new Set([...e.hidden,...[...n.hidden].map(e=>e+t)]),braces:new Map([...e.braces,...[...n.braces].map(([e,n])=>[e+t,n])]),gone:e.gone&&n.gone}:n}function Af(e,t,n){let r=!1;for(let i of e){let e=t(i);if(e===`picture`)r||=!n(i);else if(!jf.has(e))return!1}return r}var jf=new Set([`bookmarkStart`,`bookmarkEnd`,`commentStart`,`commentEnd`,`commentReference`,`controlStart`,`controlEnd`,`fieldStart`,`fieldCode`,`fieldSeparator`,`fieldEnd`]);function Mf(e,t,n){return n.addsParagraphSpacing?e+t:e}function Nf(e){let t=e.outlineLevel;return t!==null&&t>=0&&t<6?`h${t+1}`:`p`}function Pf(e,t){for(let n=1;n<e.length;n++){let r=e[n-1],i=e[n],a=r.element.dataset.style;if(a===void 0||a!==i.element.dataset.style)continue;let o=`contextual`in r.element.dataset;`contextual`in i.element.dataset?i.before=0:o&&!t&&(i.before=Math.max(0,i.before-r.after)),o&&(r.after=0)}}var Ff={"":`•`,"":`▪`,"":`◻`,"":`●`,"":`■`,"":`❑`,"":`◆`,"":`❖`,"":`➢`,"":`✓`};function If(e,t,n,r){let i=n.createElement(`span`);i.dataset.foliMarker=``,i.setAttribute(`aria-hidden`,`true`),hf(i,e.run,mf(t,e.run,r(cf(pf(e.run))))),i.textContent=e.text;let a=pf(e.run)?.toLowerCase(),o=a===`symbol`||a?.startsWith(`wingdings`)?Ff[e.text]:void 0;o&&(i.textContent=o,i.style.fontFamily=`sans-serif`);let s=t.indent.hanging*Q;return e.suffix===`tab`&&s>0?(i.style.display=`inline-block`,i.style.minWidth=`${s}px`,i.style.textIndent=`0`):e.suffix===`tab`?i.textContent+=` `:e.suffix===`space`&&(i.textContent+=` `),i}function Lf(e,t,n,r,i){let{resolver:a,doc:o,review:s,comments:c,ratio:l,image:u,codes:d,display:f}=i,p=[];for(let[m,h]of t.entries()){if(f.hidden.has(m))continue;let t=h.marks??[],g=t.some(e=>e.type===`insertion`),_=t.some(e=>e.type===`deletion`);if(_&&s!==`markup`)continue;let v=h.attrs??{};switch(h.type){case`commentStart`:c.add(v.id);continue;case`commentEnd`:c.delete(v.id);continue;case`commentReference`:{let t=o.createElement(`span`);t.dataset.foliCommentReference=String(v.id),e.append(t);continue}case`bookmarkStart`:{let t=o.createElement(`span`);t.dataset.foliBookmark=String(v.name??``),t.style.position=`absolute`,e.append(t);continue}case`bookmarkEnd`:case`controlStart`:case`controlEnd`:continue;case`picture`:v.float?p.push(...Yd(v,o,u,i.geometry).nodes):e.append(Vd(v,o,u));continue;case`hardBreak`:e.append(o.createElement(`br`));continue;case`columnBreak`:{let t=o.createElement(`br`);t.setAttribute(Ld,``),e.append(t);continue}case`pageBreak`:{let t=o.createElement(`br`);t.setAttribute(Id,``),e.append(t);continue}}let y=f.braces.get(m)??(d&&h.type===`fieldCode`?String(v.text):``),b;if(y)b=y;else if(h.type===`text`)b=h.text??``;else if(h.type===`tab`)b=` `;else if(h.type===`noteReference`)b=i.notes?.references?.get(String(v.story))??``;else if(h.type===`noteMark`)b=i.notes?.mark??``;else if(h.type===`opaqueInline`){let t=Tf(String(v.xml??``),o),n=nf(t,o);if(n){e.append(n);continue}if(b=t?vf(t):``,!b){let t=o.createElement(`span`);t.dataset.foliOpaque=String(v.label??``),e.append(t);continue}}else continue;let x=a.run(n,t),S=o.createElement(`span`);hf(S,x,mf(r,x,l(cf(pf(x))))),S.textContent=b,h.type===`noteReference`&&S.setAttribute($d,String(v.story)),(h.type===`noteReference`||h.type===`noteMark`)&&S.setAttribute(ef,``);let C=t.find(e=>e.type===`link`);if(C&&(S.dataset.href=String(C.attrs?.href??`#${String(C.attrs?.anchor)}`)),c.size&&(S.dataset.foliComments=[...c].join(` `),!x.highlight&&!x.shading&&(S.style.backgroundColor=`rgba(255, 213, 79, 0.35)`)),s===`markup`&&(g||_)){let e=t.find(e=>e.type===(_?`deletion`:`insertion`))?.attrs,n=String(e?.author??``),r=e?.date??null,i=Qd(o,!_,n,r,s);i.append(S),S=i}e.append(S)}e.prepend(...p)}function Rf(e,t,n,r,i,a,o=Ud(void 0),s=!1,c){let l=e.attrs??{},u=r.createElement(`div`);u.dataset.foliOpaque=String(l.label??``),u.style.margin=`0`,u.style.display=`flow-root`;let d=e.type===`table`?null:Tf(String(l.xml??``),r),f=0;if(e.type===`table`)u.append(Kf(e,n,r,i,a,o,s,c));else if(d?.localName===`tbl`)u.append(Wf(d,n,r,i));else if(d){let e=yf(d,bf),t=0;e.forEach((a,o)=>{let s=Bf(a,n,r,i,t);o<e.length-1?s.element.style.marginBottom=`${s.after}px`:f=s.after,t=s.after,u.append(s.element)})}return u.firstChild||(u.style.minHeight=`1em`,u.style.outline=`1px dashed #999`),{element:u,nodes:[t],before:0,after:f,keepNext:!1,keepLines:!1,pageBreakBefore:!1,section:null}}function zf(e,t,n=`val`){for(let r of e?.children??[])if(r.localName===t){for(let e of r.attributes)if(e.localName===n)return e.value}}function $(e,t){for(let n of e?.children??[])if(n.localName===t)return n}function Bf(e,t,n,r,i=0){let a=$(e,`pPr`),o=zf(a,`pStyle`),s=zf(a,`jc`),{paragraph:c,run:l}=t.paragraph({...o?{style:o}:{},...s?{justification:s}:{}}),u=n.createElement(Nf(c));gf(u,c),hf(u,l,mf(c,l,r(cf(pf(l)))));for(let i of yf(e,xf)){let e=vf(i),a=t.run(l,Vf($(i,`rPr`))),o=n.createElement(`span`);hf(o,a,mf(c,a,r(cf(pf(a))))),o.textContent=e,u.append(o)}u.textContent||u.append(n.createElement(`br`));let d=Mf(c.spacing.before*Q,i,t);return d&&(u.style.marginTop=`${d}px`),{element:u,after:c.spacing.after*Q}}function Vf(e){let t=[],n=t=>{let n=zf(e,t);return n===void 0||![`0`,`false`,`off`].includes(n)},r=zf(e,`rStyle`);r&&t.push({type:`characterStyle`,attrs:{id:r}});for(let[r,i]of[[`b`,`bold`],[`i`,`italic`],[`caps`,`caps`],[`smallCaps`,`smallCaps`],[`strike`,`strike`]])$(e,r)&&t.push({type:i,attrs:{value:n(r)}});let i=zf(e,`u`);i&&t.push({type:`underline`,attrs:{style:i}});let a=zf(e,`color`);a&&t.push({type:`color`,attrs:{value:a}});let o=Number(zf(e,`sz`));o>0&&t.push({type:`fontSize`,attrs:{value:o}});let s=zf(e,`highlight`);return s&&t.push({type:`highlight`,attrs:{value:s}}),t}function Hf(e){if(!e)return;let t=qf(e,`val`)??`single`;if(t===`nil`||t===`none`)return`none`;let n=Number(qf(e,`sz`)??4),r=qf(e,`color`),i=ff[t]??`solid`;return`${Math.max(n/8*(96/72),.5)}px ${i} ${r&&r!==`auto`?`#${r}`:`#000`}`}function Uf(e,t){let n={...t};for(let t of e?.children??[]){let e=t.localName===`start`?`left`:t.localName===`end`?`right`:t.localName,r=Number(qf(t,`w`));e in n&&Number.isFinite(r)&&(n[e]=r*Q)}return n}function Wf(e,t,n,r){let i=n.createElement(`table`),{style:a}=i;a.borderCollapse=`collapse`,a.tableLayout=`fixed`;let o=$(e,`tblPr`),s=$(o,`tblBorders`);for(let e of[`top`,`left`,`bottom`,`right`]){let t=Hf($(s,e));t&&a.setProperty(`border-${e}`,t)}let c=Uf($(o,`tblCellMar`),{top:0,bottom:0,left:108*Q,right:108*Q}),l=[...$(e,`tblGrid`)?.children??[]].filter(e=>e.localName===`gridCol`).map(e=>Number(qf(e,`w`))||0),u=l.reduce((e,t)=>e+t,0);u&&(a.width=`${u*Q}px`);let d=n.createElement(`colgroup`);for(let e of l){let t=n.createElement(`col`);t.style.width=`${e*Q}px`,d.append(t)}i.append(d);let f={horizontal:Hf($(s,`insideH`)),vertical:Hf($(s,`insideV`))},p=n.createElement(`tbody`);for(let i of yf(e,Sf)){let e=n.createElement(`tr`),a=$(i,`trPr`),o=zf(a,`tblHeader`);$(a,`tblHeader`)&&o!==`0`&&o!==`false`&&(e.dataset.foliHeader=``);let s=Uf($($(i,`tblPrEx`),`tblCellMar`),c);for(let a of yf(i,Cf)){let i=$(a,`tcPr`),o=n.createElement(`td`),c=Number(zf(i,`gridSpan`));c>1&&(o.colSpan=c);let l=zf(i,`shd`,`fill`);l&&l!==`auto`&&(o.style.backgroundColor=`#${l}`);let u=Uf($(i,`tcMar`),s);o.style.padding=`${u.top}px ${u.right}px ${u.bottom}px ${u.left}px`,o.style.verticalAlign=`top`,f.horizontal&&(o.style.borderTop=o.style.borderBottom=f.horizontal),f.vertical&&(o.style.borderLeft=o.style.borderRight=f.vertical);let d=$(i,`tcBorders`);for(let e of[`top`,`left`,`bottom`,`right`]){let t=Hf($(d,e));t&&o.style.setProperty(`border-${e}`,t)}if($(i,`vMerge`)&&zf(i,`vMerge`)!==`restart`){e.append(o);continue}let p=0;for(let e of yf(a,wf)){if(e.localName===`tbl`){o.append(Wf(e,t,n,r)),p=0;continue}let i=Bf(e,t,n,r,p);i.element.style.marginBottom=`${i.after}px`,p=i.after,o.append(i.element)}e.append(o)}p.append(e)}return i.append(p),i}function Gf(e){if(!e)return;if(e.style===`nil`||e.style===`none`)return`none`;let t=Math.max((e.size??4)/8*(96/72),.5),n=e.color&&e.color!==`auto`?`#${e.color}`:`#000`;return`${t}px ${ff[e.style??`single`]??`solid`} ${n}`}function Kf(e,t,n,r,i,a,o,s){let c=e.attrs??{},l=n.createElement(`table`);l.style.borderCollapse=`collapse`,l.style.tableLayout=`fixed`;let u=c.grid??[],d=u.reduce((e,t)=>e+t,0);d&&(l.style.width=`${d*Q}px`);let f=n.createElement(`colgroup`);for(let e of u){let t=n.createElement(`col`);t.style.width=`${e*Q}px`,f.append(t)}l.append(f);let p=n.createElement(`tbody`),m=e.content??[],h={resolver:t,doc:n,review:`markup`,comments:new Set,ratio:r,image:i,geometry:a,codes:o};return m.forEach((e,l)=>{let u=e.attrs??{},d=n.createElement(`tr`);u.header&&(d.dataset.foliHeader=``),u.cantSplit&&(d.dataset.foliCantSplit=``);let f=e.content??[];f.forEach((e,p)=>{let g=e.attrs??{},_=t.cell(c,u,g,{row:l,rows:m.length,cell:p,cells:f.length}),v=n.createElement(`td`),y=g.gridSpan;y&&y>1&&(v.colSpan=y),_.shading&&(v.style.backgroundColor=`#${_.shading}`);let b=_.margins;v.style.padding=`${b.top*Q}px ${b.right*Q}px ${b.bottom*Q}px ${b.left*Q}px`,v.style.verticalAlign=_.verticalAlign===`center`?`middle`:_.verticalAlign;for(let e of[`top`,`left`,`bottom`,`right`]){let t=Gf(_.borders[e]);t&&v.style.setProperty(`border-${e}`,t)}if(d.append(v),g.vMerge===`continue`)return;let x=0,S=e.content??[],C=Ti(S.map(Of),o);for(let[e,c]of S.entries()){if(c.type===`table`){v.append(Kf(c,t,n,r,i,a,o,s)),x=0;continue}if(c.type!==`paragraph`){v.append(Rf(c,0,t,n,r,i,a,o,s).element),x=0;continue}let{paragraph:l,run:u}=t.paragraph(c.attrs??{},_),d=n.createElement(Nf(l));d.dataset.foliCell=``,gf(d,l),hf(d,u,mf(l,u,r(cf(pf(u)))));let f=C[e];Lf(d,c.content??[],u,l,{...h,display:f,notes:s}),f.gone&&(d.style.display=`none`),d.textContent||d.append(n.createElement(`br`));let p=l.spacing.before*Q;d.style.marginTop=`${Mf(p,x,t)}px`,x=l.spacing.after*Q,d.style.marginBottom=`${x}px`,v.append(d)}}),p.append(d)}),l.append(p),l}function qf(e,t){for(let n of e.attributes)if(n.localName===t)return n.value}var Jf={orphans:2,widows:2},Yf=.5,Xf=e=>e?e.page*1e6+(e.band??0)*1e3+(e.column??0):0;function Zf(e,t,n=Jf,r){let i=r?Math.min(r.from,e.length,r.previous.fragments.length):0,a=t=>e[t]?.section?.balanced===!0,o=t=>e[t]?.section===e[t-1]?.section;for(;;)if(i>0&&e[i-1]?.keepWithNext)i--;else if(i>0&&i<e.length&&a(i)&&o(i))i--;else break;let s=r?r.previous.fragments.slice(0,i):[],c=r?r.previous.states.slice(0,i):[],l=r?r.previous.gaps.slice(0,i):[],u=r?.previous.states[i]?{...r.previous.states[i]}:{page:0,number:e[0]?.section?.pageStart??1,sectionPage:0,band:0,bandTop:0,lead:0,column:0,used:0,bandBottom:0,previousMargin:0,onPage:0,breakPending:!1,columnPending:!1,forcedPage:!0,owner:null,notes:0,noteParts:[],pageNotes:0,carry:[],reserves:{}},d=new Set,f=n.spacing===`word`,p=null,m=[],h=null,g=()=>`${u.page}|${u.band}`,_=()=>u.reserves[g()]??0,v=(e=!1)=>{u.page++,u.number++,u.band=0,u.bandTop=0,u.lead=0,u.column=0,u.used=0,u.bandBottom=0,u.onPage=0,u.forcedPage=e,u.owner=null,u.notes=0,u.noteParts=[],u.pageNotes=0,Object.keys(u.reserves).length&&(u.reserves=Object.fromEntries(Object.entries(u.reserves).filter(([e])=>Number.parseInt(e,10)>=u.page)))},y=(e,t=!1)=>{u.column+1>=(e.section?.columns??1)?v(t):(u.bandBottom=Math.max(u.bandBottom,u.used),u.column++,u.used=0,u.lead=0,u.onPage=0,u.forcedPage=t)},b=e=>x(e)-Math.max(u.notes,_()),x=e=>{let n=u.owner?.section??e.section,r=(n?n.box({index:u.page,number:u.number,first:u.owner?.first??u.page===u.sectionPage}).height:e.pageHeight??t)-u.bandTop-u.pageNotes;return p?.page===u.page?Math.min(r,p.height):r},S=(e,t,n)=>({id:e.id,page:u.page,...u.band?{band:u.band}:{},...u.column?{column:u.column}:{},fromLine:t,toLine:n}),C=(e,t,n)=>({id:e.id,page:u.page,...u.band?{band:u.band}:{},fromLine:t,toLine:n}),w=(e,t,n)=>{let r=e.lines(u.column),i=t?r[t-1]:0,a=t;for(;a<r.length&&r[a]-i<=n+Yf;)a++;return{to:a,height:a>t?r[a-1]-i:0,all:r.length}},ee=(e,t,n,r,i)=>{let a=e.lines(0),o=t?a[t-1]:0,s=i>1?0:ep(r,1),c=e=>a[e]-o,l=t;for(;l<a.length&&(i>1?ep([...r,c(l)],i):s+c(l))<=n+Yf;)l++;return{to:l,height:l>t?c(l-1):0,all:a.length}},te=e=>e.lines(0).at(-1)??0,T=e=>C(e,0,e.lines(0).length),E=(e,t=!1)=>{if(!u.carry.length||u.notes||u.onPage||!n.notes)return;let{continuation:r}=n.notes,i=e.section?.columns??1,a=te(r),o=x(e)-u.used-a,s=[],c=[],l=[];for(let e of u.carry){if(c.length){c.push(e);continue}let n=ee(e.note,e.from,o,l,i);n.to===e.from&&t&&!s.length&&(n=ee(e.note,e.from,D(e),l,1)),n.to>e.from&&(s.push(C(e.note,e.from,n.to)),l=[...l,n.height]),n.to<n.all&&c.push({note:e.note,from:n.to})}s.length&&(m.push(T(r),...s),u.notes=a+ep(l,i),u.noteParts=l,u.carry=c)},D=({note:e,from:t})=>{let n=e.lines(0);return n[t]-(t?n[t-1]:0)},O=e=>u.onPage>0||u.notes>0||u.bandTop>0||u.column+1<(e.section?.columns??1),k=(e,t)=>{let r=u.breakPending;u.breakPending=!1,u.columnPending=!1;let i=(u.notes>0||u.pageNotes>0)&&e.columns!==t?.columns,a=!t||e.samePage(t)&&!i;if(!r&&a&&e.start===`continuous`){u.owner??={section:t??e,first:u.page===u.sectionPage};let n=u.previousMargin;return u.bandTop+=Math.max(u.bandBottom,u.used)+n,u.lead=n,u.band++,u.column=0,u.used=0,u.bandBottom=0,u.onPage=0,u.forcedPage=!0,u.sectionPage=u.page,u.pageNotes+=u.notes,u.notes=0,u.noteParts=[],n}if(!r&&a&&e.start===`nextColumn`&&e.columns===t?.columns&&u.column+1<e.columns){y({section:e},!0);return}u.onPage||u.used||u.column||u.band?v(!0):u.forcedPage=!0;let o=t=>e.start===`oddPage`&&t%2==0||e.start===`evenPage`&&t%2==1;o(u.number)&&(e.pageStart===void 0||n.evenAndOddHeaders)&&v(!0),e.pageStart!==void 0&&(u.number=e.pageStart+ +!!o(e.pageStart)),u.sectionPage=u.page},ne=(e,t)=>{let n=ie(e,t);return e.endnotes?.length&&re(e,n),n},re=(e,t)=>{let n=u.onPage?u.previousMargin:0;for(let t of e.endnotes??[]){let r=0;for(;;){let i=t.lines(u.column);if(r>=i.length)break;let a=r?i[r-1]:0;E(e);let o=u.onPage?n??0:0,s=w(t,r,b(e)-u.used-o);if(s.to===r){if(O(e)){y(e);continue}s={...s,to:r+1,height:i[r]-a}}let c=S(t,r,s.to);c.end=!0,o&&(c.lead=o),m.push(c),n=void 0,u.used+=o+s.height,u.onPage++,r=s.to,r<i.length&&y(e)}}u.previousMargin=0;let r=t[t.length-1];r&&m.length&&(r.notes=[...r.notes??[],...m]),r&&(m=[])},ie=(t,r)=>{let i=e[r-1],a;r>0&&t.section&&i?.section!==t.section?a=k(t.section,i?.section):u.breakPending&&u.onPage?v(!0):u.columnPending?y(t,!0):d.has(r)&&u.onPage&&y(t),u.breakPending=!1,u.columnPending=!1;let o=u.page,s=(e,t)=>{let n={page:u.page,fromLine:e,toLine:t};return u.band&&(n.band=u.band),u.column&&(n.column=u.column),a!==void 0&&u.page===o&&(n.lead=a),a=void 0,m.length&&(n.notes=m,m=[]),n};if(t.sectionMark&&u.onPage)return l[r]=0,[{...s(0,1/0),mark:!0}];let c=u.previousMargin;u.previousMargin=t.marginBottom;let p=f&&n.addSpacing===!0,S=()=>u.onPage?p?c+t.marginTop:Math.max(c,t.marginTop):f&&!u.forcedPage?0:p?t.marginTop:Math.max(0,t.marginTop-u.lead),w=f?0:t.marginBottom,ne=t.breaksAfter?.(u.column)??[],re=t.columnBreaksAfter?.(u.column)??[],ie=ne.length+re.length>0,A=t.inColumn?.(u.column)??t,j=()=>{let e=new Map;for(let{line:n,note:r}of t.notes?.(u.column)??[])e.set(n,[...e.get(n)??[],r]);return e},ae=j();if(u.carry.length&&!u.onPage&&E(t),!ie&&!ae.size&&u.used+S()+A.height+w<=b(t)+Yf){let e=S();return l[r]=e,u.used+=e+A.height,u.onPage++,[s(0,1/0)]}let oe=A.lines(),M=oe.length,se=e=>new Set(e.filter(e=>e>=0&&e<M)),ce=se(ne),le=se(re),ue=[],N=0,de=0,fe=(e=!1)=>{if(!t.inColumn)return;let n=t.inColumn(u.column);if(n===A)return;let r=n.lines(),i=N?oe[N-1]/(A.height||1):0;if(A=n,oe=r,M=oe.length,ce=se(t.breaksAfter?.(u.column)??[]),le=se(t.columnBreaksAfter?.(u.column)??[]),N>0){let t=[...ce,...le].sort((e,t)=>e-t)[de-1],r=oe.findIndex(e=>e/(n.height||1)>i+1e-6);r<0&&(r=M-1),N=e&&t!==void 0?t+1:Math.max(r,1)}if(N>=M){let e=ue.at(-1);e&&(e.toLine=1/0)}};for(;N<M;){let e=N;for(;e<M&&!ce.has(e)&&!le.has(e);)e++;e=Math.min(e+1,M);let i=N?oe[N-1]:0,a=N===0?S():t.repeat??0;ae=j(),E(t);let o=x(t),c=M===1,d=(r,s=!1)=>{let l={notes:u.notes,parts:u.noteParts,carry:u.carry,pieces:[]};if(!ae.size||!n.notes)return l;let d=t.section?.columns??1;for(let f=N;f<r;f++)for(let r of ae.get(f)??[]){if(l.carry.length){l.carry=[...l.carry,{note:r,from:0}];continue}let{separator:p}=n.notes,m=!l.notes,v=m?te(p):l.notes-ep(l.parts,d),y=f+1;!t.anyLine&&!c&&(y=Math.max(y,N+n.orphans),M-y<n.widows&&(y=M),y=Math.min(y,e));let b=y===M?t.marginBottom:0,x=u.used+a+oe[y-1]-i+b,S=Math.max(x,d>1&&u.column?u.bandBottom:0),w=ee(r,0,o-S-v,l.parts,d);if(d>1&&u.column&&!s&&(!w.to||w.to<w.all&&S>x)){let e=r.lines(0),t=v+ep([...l.parts,e.at(-1)],d),n=v+ep([...l.parts,e[0]],d),i=t<o/2?t:n;i>_()+Yf&&i<o&&(h={key:g(),height:i})}if(!w.to){if(!s)return null;w=ee(r,0,D({note:r,from:0}),[],1)}m&&l.pieces.push(T(p)),l.pieces.push(C(r,0,w.to)),l.parts=[...l.parts,w.height],l.notes=v+ep(l.parts,d),w.to<w.all&&(l.carry=[{note:r,from:w.to}])}return l},f=N;for(;f<e;){let e=oe[f]-i+(f+1===M?w:0),t=d(f+1);if(!t||u.used+a+e+Math.max(t.notes,_())>o+Yf)break;f++}if(f<e&&f>N&&!t.anyLine){let r=Math.min(f,e-n.widows);r-N>=n.orphans?f=r:O(t)&&(f=N)}if(f===N){if(O(t)){y(t),fe();continue}f=N+1}let p=d(f,!0);p&&(u.notes=p.notes,u.noteParts=p.parts,u.carry=p.carry,m.push(...p.pieces)),N===0&&(l[r]=a),ue.push(s(N,f)),u.used+=a+oe[f-1]-i,u.onPage++,N=f;let b=ce.has(f-1),k=le.has(f-1);N<M?((b||k)&&de++,b?v():y(t,k),fe(b||k)):b?u.breakPending=!0:k&&(u.columnPending=!0)}let[pe]=ue;return ue.length===1&&pe&&!ie&&(pe.toLine=1/0),ue},A=new Map,j=(t,n)=>{let f=t;for(;f<n;){let n=r&&!p&&f>i&&!A.size&&r.previousIndex(f-1)>=0?r.previousIndex(f):-1,g=n>=0?r?.previous.states[n]:void 0;if(g&&!e[f-1]?.keepWithNext&&!(a(f)&&o(f))&&rp(g,u)){let e=r.previous;return s.length=f,c.length=f,l.length=f,s.push(...e.fragments.slice(n)),c.push(...e.states.slice(n,-1)),l.push(...e.gaps.slice(n)),{fragments:s,states:[...c,{...e.states.at(-1)}],gaps:l}}c[f]={...u};let _=ne(e[f],f);if(h){let{key:e,height:n}=h;h=null;let[r,i]=e.split(`|`).map(Number),a=f;for(;a>t&&s[a-1]?.some(e=>e.page===r&&(e.band??0)===i);)a--;let o=c[a];u={...o,reserves:{...o.reserves,[e]:n}},s.length=a,c.length=a,l.length=a,A.clear();for(let e of d)e>=a&&d.delete(e);m=[],f=a;continue}s[f]=_;let v=s[f-1],y=v!==void 0&&Xf(_[0])>Xf(v[v.length-1]),b=A.get(f);if(b&&(A.delete(f),y)){s.splice(b.first,s.length-b.first,...b.result),c.splice(b.first,c.length-b.first,...b.snapshots),l.splice(b.first,l.length-b.first,...b.gaps),u=b.state,f++;continue}if(y&&e[f-1]?.keepWithNext&&o(f)){let t=f-1;for(;t>0&&o(t)&&e[t-1]?.keepWithNext&&s[t-1]?.length===1&&Xf(s[t-1]?.[0])===Xf(s[t]?.[0]);)t--;let n=c[t];if(!d.has(t)&&n.onPage>0&&s[t]?.length===1){A.set(f,{first:t,result:s.slice(t),snapshots:c.slice(t),gaps:l.slice(t),state:{...u}}),d.add(t),u={...n},s.length=t,f=t;continue}}f++;let x=e[f-1]?.section;!p&&x?.balanced&&x.columns>1&&e[f]?.section!==x&&ae(f)}return null},ae=t=>{let n=e[t-1]?.section,r=t-1;for(;r>0&&e[r-1]?.section===n;)r--;let i=c[r],{page:a}=u,o=Math.max(u.bandBottom,u.used),l=o/n.columns-1,f=e=>{p={page:a,height:e},u={...i},s.length=r,c.length=r,A.clear();for(let e of d)e>=r&&d.delete(e);return j(r,t),u.page===a&&Math.max(u.used,u.bandBottom)<=e+Yf};for(;o-l>.5;){let e=(l+o)/2;f(e)?o=e:l=e}f(o)||f(1/0),p=null};return j(i,e.length)||((()=>{let t=s[s.length-1],n=t?.[t.length-1],r=e[e.length-1];if(!t||!n||!r||!u.carry.length&&!n.notes?.some(e=>e.tail))return;let i=u;for(u={...u};u.carry.length;)v(),E(r,!0);let a=[...(n.notes??[]).filter(e=>!e.tail),...m.map(e=>({...e,tail:!0}))];m=[],u=i,s[s.length-1]=[...t.slice(0,-1),{...n,notes:a}]})(),{fragments:s,states:[...c.slice(0,e.length),{...u}],gaps:l.slice(0,e.length)})}function Qf(e,t){let n=[],r=[],i=new Set,a=new Map;t.fragments.forEach((o,s)=>{let c=e[s]?.section,l=t.states[s+1],u=a.get(c)??new Set;a.set(c,u);let d=[...o,...o.flatMap(e=>e.notes??[])];for(let{page:e}of d)u.add(e),n[e]||(r[e]=c,n[e]={index:e,number:l.number-(l.page-e),first:!i.has(c),section:c.index??0,sectionPages:0}),i.add(c)}),n.forEach((e,t)=>{e&&(e.sectionPages=a.get(r[t])?.size??0)});for(let e=n.length-1;e>=0;e--){let t=n[e+1];n[e]??={...t,index:e,number:t.number-1,first:!1,sectionPages:0}}return n}function $f(e,t){let n=e.reduce((e,t)=>e+t,0);if(t<=1||e.length<=1)return{height:n,columnOf:e.map(()=>0)};let r=n=>{let r=[],i=0,a=0,o=0;for(let t of e)a&&a+t>n+.01&&(i++,a=0),a+=t,o=Math.max(o,a),r.push(i);return i<t?{height:o,columnOf:r}:null},i=Math.max(...e,n/t),a=r(i);if(a)return a;let o=n;for(a=r(o);o-i>.25;){let e=(i+o)/2,t=r(e);t?(a=t,o=e):i=e}return a}var ep=(e,t)=>$f(e,t).height;function tp(e,t,n,r,i){for(let a=t.fragments.length-1;a>=0;a--)for(let o of t.fragments[a]??[])if(o.page===n&&(o.band??0)===r&&(o.column??0)===i)return e[a]?.marginBottom??0;return 0}var np=e=>e.fragments.flatMap(e=>e.flatMap(e=>e.notes??[]));function rp(e,t){return e.notes===t.notes&&JSON.stringify(e.reserves)===JSON.stringify(t.reserves)&&e.noteParts.length===t.noteParts.length&&e.noteParts.every((e,n)=>e===t.noteParts[n])&&e.pageNotes===t.pageNotes&&e.carry.length===t.carry.length&&e.carry.every((e,n)=>e.note.id===t.carry[n]?.note.id&&e.from===t.carry[n]?.from)&&e.page===t.page&&e.number===t.number&&e.sectionPage===t.sectionPage&&e.band===t.band&&e.bandTop===t.bandTop&&e.lead===t.lead&&e.column===t.column&&e.used===t.used&&e.bandBottom===t.bandBottom&&e.previousMargin===t.previousMargin&&e.onPage===t.onPage&&e.breakPending===t.breakPending&&e.columnPending===t.columnPending&&e.forcedPage===t.forcedPage&&e.owner===t.owner}var ip=`data-foli-sheet`;function ap(e,t,n,r){let i=n.every(e=>e.width===t.width&&e.height===t.height)?``:n.map(({width:t,height:n,index:i})=>{let a=`foli-${r}-${i}`;return`@page ${a}{size:${t} ${n};margin:0}${e}[${ip}="${i}"]{page:${a};height:${n}!important}`}).join(``);return`@media print{@page{size:${t.width} ${t.height};margin:0}${e}{height:${t.height}!important;margin-block:0!important;break-after:page;break-inside:avoid}${e}:last-child{break-after:auto}${i}}`}var op=`foli-band`,sp=`foli-column`;function cp(e){let{widths:t,gaps:n,separator:r}=qo(e);return{widths:t.map(e=>e*Q),gaps:n.map(e=>e*Q),separator:r}}function lp(e,t,n){if(e.className=op,e.style.display=`flex`,n.separator&&n.gaps.length){let t=0,r=n.gaps.map((e,r)=>(t+=n.widths[r]+e,t-e/2));e.style.backgroundImage=r.map(()=>`linear-gradient(#000,#000)`).join(`,`),e.style.backgroundRepeat=`no-repeat`,e.style.backgroundSize=r.map(()=>`1px 100%`).join(`,`),e.style.backgroundPosition=r.map(e=>`${e-.5}px 0`).join(`,`),e.style.printColorAdjust=`exact`}t.forEach((e,t)=>{e.className=sp,e.style.flex=`none`,e.style.display=`flow-root`,e.style.width=`${n.widths[t]}px`,e.style.marginRight=`${n.gaps[t]??0}px`})}function up(e,t){let n=e.createElement(`div`),r=t.widths.map(()=>e.createElement(`div`));return lp(n,r,t),n.append(...r),{band:n,columns:r}}var dp=`data-foli-page-field`,fp=`foli-region`,pp=`foli-region-content`,mp=720,hp=new Set([`PAGE`,`NUMPAGES`,`SECTIONPAGES`]),gp=new Map([[`roman`,`lowerRoman`],[`ROMAN`,`upperRoman`],[`alphabetic`,`lowerLetter`],[`ALPHABETIC`,`upperLetter`]]),_p=``,vp=/\uE000([\uE100-\uF8FF])/g;function yp(e){let t=e.trim().split(/\s+/)[0]?.toUpperCase()??``;if(!hp.has(t))return null;let n=/\\\*\s*(\S+)/.exec(e)?.[1];return{name:t,format:n?.toLowerCase()===`arabic`?`decimal`:gp.get(n??``)}}function bp(e,t,n){let r=e.name===`PAGE`?t.page:e.name===`NUMPAGES`?t.pages:t.sectionPages;return br(Number(r),e.format??(e.name===`PAGE`?n:void 0))}function xp(e,t){let n=[];for(let r=0;r<e.length;r++){let i=e[r];if(n.push(i),i.type!==`fieldStart`)continue;let a=1,o=-1,s=-1,c=``;for(let t=r+1;t<e.length&&s<0;t++){let n=e[t];n.type===`fieldStart`?a++:n.type===`fieldEnd`&&--a===0?s=t:a===1&&n.type===`fieldSeparator`&&o<0?o=t:a===1&&o<0&&n.type===`fieldCode`&&(c+=String(n.attrs?.text??``))}let l=s<0?null:yp(c);if(!l)continue;let u=o<0?s:o+1,d=e.slice(u,s).find(e=>e.type===`text`)??e[u-1];n.push(...e.slice(r+1,u)),n.push({type:`text`,text:_p+String.fromCharCode(57600+t.length),...d?.marks?{marks:d.marks}:{}}),t.push(l),n.push(e[s]),r=s}return n}function Sp(e,t){if(!e.content)return e;let n=e.type===`paragraph`?xp(e.content,t):e.content.map(e=>Sp(e,t));return{...e,content:n}}function Cp(e,t){let n=e.cloneNode(!0);if(!t.length)return n;let r=e.ownerDocument.createTreeWalker(n,NodeFilter.SHOW_TEXT);for(let e=r.nextNode();e;e=r.nextNode()){let n=e;n.data.replace(vp,``)===``&&n.data&&n.parentElement?.setAttribute(dp,``),n.data.includes(_p)&&(n.data=n.data.replace(vp,(e,n)=>t[n.charCodeAt(0)-57600]??``))}return n}function wp(e){let t=e.margins??{},n=t.top??1440,r=t.bottom??1440,i=(t.left??1440)+(t.gutter??0),a=t.right??1440,o=e.pageSize?.width??12240;return{top:Math.abs(n)*Q,bottom:Math.abs(r)*Q,pushesTop:n>=0,pushesBottom:r>=0,header:(t.header??mp)*Q,footer:(t.footer??mp)*Q,left:i*Q,right:a*Q,height:(e.pageSize?.height??15840)*Q,width:Math.max(o-i-a,1)*Q}}function Tp(e,t,n){let r=0;return e.forEach((e,i)=>{let a=i?n?r+e.before:Math.max(r,e.before):e.before;e.element.style.marginTop=`${a}px`,e.element.style.marginBottom=`0`,r=e.after,t.append(e.element)}),r}var Ep=class{doc;options;cache;pages=1;sectionPages=new Map;edges=[];flowed=[];document=null;sections=[];resolver=null;constructor(e,t,n){this.doc=e,this.options=t,this.cache=n}setDocument(e,t,n){this.document=e,this.sections=t,this.resolver=n,this.edges=[]}story(e){let t=this.document?.stories;return t&&Object.hasOwn(t,e)?t[e]:void 0}edgesAt(e){let t=this.edges[e];return t||(t=wp(this.sections[e]??{}),this.edges[e]=t),t}storyId(e,t,n){let r=this.sections[e];if(!r)return null;let i=ns(r,n,this.document?.settings?.evenAndOddHeaders===!0),a=ts(this.sections,e,t,i);return a&&this.story(a.id)?a.id:null}entry(e){let t=this.cache.get(e);if(!t){let n=[],r=Sp(e.content,n),i=this.doc.createElement(`div`);i.className=pp,i.style.paddingTop=`0.01px`;let a=Tp(Ef({...this.document,content:r},this.doc,{...this.options,...this.resolver?{resolver:this.resolver}:{}}),i,!!this.resolver?.addsParagraphSpacing);i.style.paddingBottom=`${a}px`,t={slots:n,template:i,after:a,drawn:new Map,heights:new Map},this.cache.set(e,t)}return t}valuesFor(e,t){return{page:String(t),pages:String(this.pages),sectionPages:String(this.sectionPages.get(e)??1)}}drawn(e,t,n){let r=this.entry(this.story(e)),i=this.edgesAt(t),a=this.valuesFor(t,n),o=this.sections[t]?.pageNumbers?.format,s=r.slots.map(e=>bp(e,a,o)),c=`${i.width}|${s.join(`|`)}`,l=r.drawn.get(c);if(!l){let e=null,t=()=>(e??=Cp(r.template,s),e),n=`${i.width}|${s.map(e=>/^\d*$/.test(e)?e.length:e).join(` `)}`,a=r.heights.get(n);a===void 0&&(a=this.measure(t(),i.width,r.after),r.heights.set(n,a)),l={height:a,get content(){return t()}},r.drawn.set(c,l)}return l}measure(e,t,n){let{style:r}=e;r.position=`absolute`,r.visibility=`hidden`,r.width=`${t}px`,this.options.measureIn().append(e);let i=e.lastElementChild,a=this.options.scale?.()??1,o=e.getBoundingClientRect().top,s=i?i.getBoundingClientRect().bottom:o;return e.remove(),r.position=``,r.visibility=``,r.width=``,(s-o)/a+n}heightOf(e,t,n){let r=this.storyId(e,t,n);return r?this.drawn(r,e,n.number).height:0}margins(e,t){let n=this.edgesAt(e),r=n.pushesTop?this.heightOf(e,`header`,t):0,i=n.pushesBottom?this.heightOf(e,`footer`,t):0;return{top:r?Math.max(n.top,n.header+r):n.top,bottom:i?Math.max(n.bottom,n.footer+i):n.bottom}}boxHeight(e,t){let{top:n,bottom:r}=this.margins(e,t);return this.edgesAt(e).height-n-r}settle(e){let t=()=>e.filter(e=>e.sectionPages).map(e=>this.boxHeight(e.section,e)).join(` `),n=t();this.flowed=e,this.pages=e.length,this.sectionPages=new Map;for(let t of e)t.sectionPages&&this.sectionPages.set(t.section,t.sectionPages);return t()!==n}key(){let e=[`header`,`footer`],t=this.sections.flatMap((t,n)=>e.flatMap(e=>[{first:!0,number:1},{first:!1,number:1},{first:!1,number:2}].map(t=>this.heightOf(n,e,{...t,index:0})))),n=this.flowed.filter(e=>e.sectionPages&&e.section<this.sections.length).flatMap(t=>e.map(e=>this.heightOf(t.section,e,t)));return[...t,`|`,...n].join(` `)}drawing(e,t,n){let r=this.storyId(e,t,n);return r?{id:r,content:this.drawn(r,e,n.number),story:this.story(r)}:null}element(e,t){let n=this.edgesAt(e),r=this.doc.createElement(`div`);r.className=`${fp} foli-${t}`,r.setAttribute(`contenteditable`,`false`);let{style:i}=r;return i.position=`absolute`,i.inset=`0`,i.boxSizing=`border-box`,i.pointerEvents=`none`,i.userSelect=`none`,i.setProperty(`-webkit-user-select`,`none`),i.paddingLeft=`${n.left}px`,i.paddingRight=`${n.right}px`,t===`header`?i.paddingTop=`${n.header}px`:(i.display=`flex`,i.flexDirection=`column`,i.justifyContent=`flex-end`,i.paddingBottom=`${n.footer}px`),r}},Dp=`data-foli-note`,Op=`foli-notes`;function kp(e){let t=e.getBoundingClientRect(),n=e.ownerDocument,r=n.createRange(),i=[],a=n.createTreeWalker(e,NodeFilter.SHOW_TEXT|NodeFilter.SHOW_ELEMENT);for(let e=a.nextNode();e;e=a.nextNode())if(e.nodeType===Node.TEXT_NODE){if(e.parentElement?.style.verticalAlign===`super`)continue;r.selectNodeContents(e);for(let e of r.getClientRects())i.push({rect:e,text:!0})}else e.nodeName===`BR`&&i.push({rect:e.getBoundingClientRect(),text:!1});i.sort((e,t)=>e.rect.top-t.rect.top);let o=[];for(let{rect:e,text:t}of i){if(e.height<=0)continue;let n=o[o.length-1];n&&e.top<(n.top+n.bottom)/2?t&&!n.text?Object.assign(n,{top:e.top,bottom:e.bottom,text:t}):t===n.text&&(n.top=Math.min(n.top,e.top),n.bottom=Math.max(n.bottom,e.bottom)):o.push({top:e.top,bottom:e.bottom,text:t})}let s=o.slice(1).map((e,n)=>(o[n].bottom+e.top)/2-t.top);return s.push(t.height),s}var Ap=e=>({kind:`footnote`,noteType:e,content:{type:`doc`,content:[{type:`paragraph`,attrs:{spacing:{after:0,line:240,lineRule:`auto`}},content:[{type:`opaqueInline`,attrs:{xml:`<w:r><w:${e}/></w:r>`,label:e}}]}]}}),jp=Ap(`separator`);function Mp(e){if((e.noteType??`normal`)===`normal`)return e.content;let t={before:0,after:0,line:240,lineRule:`auto`};return{...e.content,content:(e.content.content??[]).map(e=>e.type===`paragraph`?{...e,attrs:{...e.attrs,spacing:{...t}}}:e)}}var Np=Ap(`continuationSeparator`),Pp=0,Fp=class{doc;options;cache;document=null;sections=[];resolver=null;references=[];numbers=new Map;open=null;constructor(e,t,n){this.doc=e,this.options=t,this.cache=n}setDocument(e,t,n,r){this.document=e,this.sections=t,this.resolver=n,this.references=r,this.numbers=new Map(r.map(e=>[e.story,e.text]))}story(e){let t=this.document?.stories;return t&&Object.hasOwn(t,e)?t[e]:void 0}separator(e,t){let n=Object.entries(this.document?.stories??{}).find(([,n])=>n.kind===e&&n.noteType===t);return n?{id:n[0],story:n[1]}:{id:`${e}:${t}`,story:t===`separator`?jp:Np}}storyFor(e){return e===`footnote:separator`||e===`endnote:separator`?jp:e.endsWith(`:continuationSeparator`)?Np:this.story(e)}drawn(e,t){let n=this.storyFor(e),r=this.numbers.get(e)??``,i=this.cache.get(n);i||(i=new Map,this.cache.set(n,i));let a=`${r}|${t}`,o=i.get(a);if(!o){let e=this.doc.createElement(`div`);e.className=pp,e.style.paddingTop=`0.01px`;let s={...this.options,notes:{mark:r},...this.resolver?{resolver:this.resolver}:{}},c=Ef({...this.document,content:Mp(n)},this.doc,s),l=Tp(c,e,!!this.resolver?.addsParagraphSpacing),{style:u}=e;u.position=`absolute`,u.visibility=`hidden`,u.width=`${t}px`,this.options.measureIn().append(e);let d=this.options.scale?.()??1,f=e.getBoundingClientRect().top,p=c.flatMap(({element:e})=>{let t=(e.getBoundingClientRect().top-f)/d;return kp(e).map(e=>t+e/d)});e.remove(),u.position=``,u.visibility=``,u.width=``,p.length&&(p[p.length-1]=p.at(-1)+l),o={serial:++Pp,template:e,lines:p.length?p:[0]},i.set(a,o)}return o}linesOf(e,t){let{lines:n}=this.drawn(e,t);return e===this.open?[n.at(-1)]:n}flowNote(e,t){return{id:e,lines:n=>this.linesOf(e,t[n]??t[0])}}widths(e){return cp(this.sections[e]??{}).widths}footnote(e,t){return _d(e)===`footnote`&&this.numbers.has(e)&&this.story(e)?this.flowNote(e,this.widths(t)):null}flowRules(){if(!this.references.some(e=>e.kind===`footnote`&&this.story(e.story)))return;let e=this.widths(0);return{separator:this.flowNote(this.separator(`footnote`,`separator`).id,e),continuation:this.flowNote(this.separator(`footnote`,`continuationSeparator`).id,e)}}endnotes(){let e=new Map,t=Math.max(this.sections.length-1,0),n=this.document;if(!n)return e;let r=yd(n,`endnote`).position===`sectEnd`;for(let{story:n,kind:i,section:a}of this.references){if(i!==`endnote`||!this.story(n))continue;let o=r?a:t,s=e.get(o)??[this.flowNote(this.separator(`endnote`,`separator`).id,this.widths(o))];s.push(this.flowNote(n,this.widths(o))),e.set(o,s)}return e}key(){if(!this.references.length)return``;let e=this.references.filter(e=>this.story(e.story)).map(({story:e,section:t})=>{let n=this.linesOf(e,this.widths(t)[0]);return`${n.length}:${n.at(-1)}`});return`${this.open??``}|${e.join(` `)}`}groups(e,t){let n=new Map;for(let r of e){let e=r.band??0,i=r.column??0,a=t(r.page,e),o=this.sections[a],s=!!this.document&&this.widths(a).length===1&&yd(this.document,`footnote`,o).position===`beneathText`,c=!!r.end||s&&_d(r.id)===`footnote`,l=`${r.page}|${e}|${c?i:0}|${c}`,u=n.get(l);u||(u={page:r.page,band:e,column:i,inFlow:c,pieces:[],section:a},n.set(l,u)),u.pieces.push(r)}return[...n.values()]}widthOf(e){let t=this.widths(e.section);return t[e.column]??t[0]}pieceHeight(e,t){let n=this.linesOf(e.id,t),r=Math.min(e.toLine,n.length);return(e.lead??0)+(n[r-1]??0)-(e.fromLine?n[e.fromLine-1]??0:0)}arranged(e){let t=this.widthOf(e),n=e=>(this.storyFor(e.id)?.noteType??`normal`)!==`normal`,r=e.pieces.filter(n),i=e.pieces.filter(e=>!n(e)),a=e.inFlow?1:this.widths(e.section).length,{height:o,columnOf:s}=$f(i.map(e=>this.pieceHeight(e,t)),a);return{separators:r,notes:i,columnOf:s,columns:a,above:r.reduce((e,n)=>e+this.pieceHeight(n,t),0),height:o}}heightOf(e){let{above:t,height:n}=this.arranged(e);return t+n}keyOf(e){let t=this.widthOf(e);return e.pieces.map(e=>{let{serial:n}=this.drawn(e.id,t);return`${e.id}|${n}|${e.fromLine}|${e.toLine}|${e.lead??0}|${e.id===this.open}`}).join(`;`)}pieceElement(e,t){let n=this.widthOf(t),{lines:r,template:i}=this.drawn(e.id,n),a=this.doc.createElement(`div`);a.setAttribute(Dp,e.id),e.lead&&(a.style.marginTop=`${e.lead}px`);let o=i.cloneNode(!0);if(e.fromLine===0&&e.toLine>=r.length||e.id===this.open)return a.append(o),a;let s=e.fromLine?r[e.fromLine-1]:0,c=r[Math.min(e.toLine,r.length)-1];return a.style.overflow=`hidden`,a.style.height=`${c-s}px`,o.style.marginTop=`${-s}px`,e.fromLine&&o.setAttribute(`aria-hidden`,`true`),a.append(o),a}groupElement(e,t,n=t=>this.pieceElement(t,e),r=0){let i=this.doc.createElement(`div`);i.className=`${fp} ${Op}`,i.setAttribute(`contenteditable`,`false`);let{style:a}=i;a.userSelect=`none`,a.setProperty(`-webkit-user-select`,`none`),a.width=`${this.widthOf(e)}px`,r&&(a.marginTop=`${r}px`),t&&(a.position=`absolute`,a.left=`${t.left}px`,a.bottom=`${t.bottom}px`);let{separators:o,notes:s,columnOf:c,columns:l,above:u}=this.arranged(e);if(l===1)return i.append(...e.pieces.map(n)),i;let{widths:d,gaps:f}=cp(this.sections[e.section]??{});a.width=`auto`,a.display=`flex`,a.alignItems=`flex-start`;for(let e=0;e<l;e++){let t=this.doc.createElement(`div`);t.style.flex=`none`,t.style.width=`${d[e]}px`,t.style.marginRight=`${f[e]??0}px`,e?t.style.paddingTop=`${u}px`:t.append(...o.map(n)),t.append(...s.filter((t,n)=>c[n]===e).map(n)),i.append(t)}return i}footPlace(e,t){return{left:e.left,bottom:e.bottom+t}}stacked(e,t){let n=new Map;for(let r of t)r.page===e.page&&!r.inFlow&&r.band>e.band&&n.set(r.band,Math.max(n.get(r.band)??0,this.heightOf(r)));return[...n.values()].reduce((e,t)=>e+t,0)}},Ip=`foli-word-page`,Lp=`br[${Id}],br[${Ld}]`,Rp={width:12240,height:15840,margin:1440};function zp(e){let t=e.margins??{};return{width:(e.pageSize?.width??Rp.width)*Q,height:(e.pageSize?.height??Rp.height)*Q,top:Math.abs(t.top??Rp.margin)*Q,right:(t.right??Rp.margin)*Q,bottom:Math.abs(t.bottom??Rp.margin)*Q,left:((t.left??Rp.margin)+(t.gutter??0))*Q}}var Bp=(e,t)=>e.width===t.width&&e.height===t.height&&e.top===t.top&&e.bottom===t.bottom&&e.left===t.left&&e.right===t.right;function Vp(e,t){let n=e.createElement(`div`);n.className=Ip;let{style:r}=n;r.boxSizing=`border-box`,r.position=`relative`,r.isolation=`isolate`,r.width=`${t.width}px`,r.height=`${t.height}px`,r.padding=`${t.top}px ${t.right}px ${t.bottom}px ${t.left}px`,r.background=`#fff`,r.color=`#000`,r.overflow=`hidden`;let i=e.createElement(`div`);return i.style.display=`flow-root`,n.append(i),{page:n,body:i}}function Hp(e){return t=>{let n=e.ownerDocument.createElement(`div`),{style:r}=n;r.position=`absolute`,r.visibility=`hidden`,r.fontFamily=t,r.fontSize=`100px`,r.lineHeight=`normal`,r.whiteSpace=`nowrap`,n.textContent=`x`,e.append(n);let i=n.getBoundingClientRect().height;return n.remove(),i>0?i/100:1.2}}function Up(e,t,n){let r=e.querySelectorAll(`:scope > table > tbody > tr[data-foli-cant-split]`);if(!r.length)return t;let i=e.getBoundingClientRect().top,a=[...r].map(e=>{let t=e.getBoundingClientRect();return[t.top-i,t.bottom-i]}).filter(([e,t])=>t-e<=n);return t.filter(e=>!a.some(([t,n])=>e>t+.5&&e<n-.5))}function Wp(e){let t=0;for(let n of e.querySelectorAll(`:scope > table > tbody > tr`)){if(!n.dataset||!(`foliHeader`in n.dataset))break;t=n.getBoundingClientRect().bottom}return t?t-e.getBoundingClientRect().top:0}function Gp(e,t,n){let r=e.getBoundingClientRect().top;return[...e.querySelectorAll(`br[${n}]`)].map(e=>{let n=e.getBoundingClientRect().top-r,i=t.findIndex(e=>n<e);return i<0?t.length-1:i})}function Kp(e,t,n={}){let r=t.ownerDocument,i=e.stories?kn(e.content):null,a=(n.review??`markup`)!==`markup`,o=t=>i?Cd(i,e,{hideDeleted:a,...t?{pageOf:t}:{}}).filter(e=>!a||!e.deleted):[],s=o(),c=wd(s),l=Ef(e,r,{...n,lineRatio:Hp(t),notes:{references:c}}),u=[],d=[],f=Hp(t),p=new Ep(r,{...n,lineRatio:f,measureIn:()=>t},new WeakMap),m=new Mr(e);p.setDocument(e,d,m);let h=new Fp(r,{...n,lineRatio:f,measureIn:()=>t},new WeakMap),g=new Map,_=new Map,v=[],y=e=>{let n=zp(e),i=cp(e),a=d.length;d.push(e);let o={index:a,start:e.type??`nextPage`,columns:i.widths.length,pageStart:e.pageNumbers?.start,box:e=>({height:p.boxHeight(a,e)}),samePage:e=>Bp(n,g.get(e))};g.set(o,n);let{page:s,body:c}=Vp(r,n);s.style.position=`absolute`,s.style.visibility=`hidden`,s.style.height=`auto`;let l=r.createElement(`div`);l.style.display=`flow-root`,l.style.width=`${i.widths[0]}px`,c.append(l),t.append(s),l.append(...v.map(e=>e.element));let f={setup:e,geometry:n,columns:i,blocks:v,flow:o,measuring:s,column:l};for(let e of v)_.set(e,f);u.push(f),v=[]};for(let e of l)v.push(e),e.section&&y(e.section);(v.length||!u.length)&&y(e.section),h.setDocument(e,d,m,s),u.forEach((e,t)=>{let n=u[t+1];e.flow.balanced=!!n&&e.flow.columns>1&&n.setup.type===`continuous`&&Bp(e.geometry,n.geometry)});let b=new Map,x=(e,t)=>{let n=_.get(e),r=b.get(e)??new Map;b.set(e,r);let i=r.get(t);if(i)return i;let{column:a,geometry:o}=n,s=o.height-o.top-o.bottom,c=e=>{let n=a.style.width;a.style.width=`${t}px`;let r=e();return a.style.width=n,r},l=c(()=>e.element.getBoundingClientRect().height),u=!!e.element.querySelector(Lp),d=e.keepLines&&!u&&l<=s,f,p=()=>(f??=c(()=>Up(e.element,kp(e.element),s)),f),m={height:l,shown:p,lines:()=>d?[l]:p(),breaks:t=>c(()=>Gp(e.element,m.lines(),t)),references:()=>c(()=>{let t=e.element.getBoundingClientRect().top,n=m.lines();return[...e.element.querySelectorAll(`[${$d}]`)].map(e=>{let r=e.getBoundingClientRect().bottom-t,i=n.findIndex(e=>r<=e+1);return{story:e.getAttribute($d),line:i<0?n.length-1:i}})})};return r.set(t,m),m},S=(e,t)=>e.columns.widths[t.column??0],C=new Map;for(let e of l){let t=e.element.querySelectorAll(`[data-foli-cell]`);if(!t.length)continue;let n=e.element.getBoundingClientRect().top;C.set(e,[...t].map(e=>({top:e.getBoundingClientRect().top-n,text:e.textContent??``})))}let w=new Map,ee=h.endnotes(),te=(e,t)=>!l[t+1]||_.get(l[t+1])!==_.get(e),T=l.map((e,t)=>{let n=_.get(e),{widths:r}=n.columns,i=x(e,r[0]),a=e.element.querySelector(`tr`)?Wp(e.element):0;a&&w.set(e,a);let o=l[t+1],s=t=>!!e.element.querySelector(`br[${t}]`),c=s(Id),u=s(Ld),d=n.flow.index??0;return{notes:e.element.querySelector(`[data-foli-note-ref]`)?t=>x(e,r[t]).references().flatMap(({story:e,line:t})=>{let n=h.footnote(e,d);return n?[{line:t,note:n}]:[]}):void 0,endnotes:te(e,t)?ee.get(d):void 0,height:i.height,marginTop:e.before,marginBottom:e.after,repeat:a,anyLine:!!e.element.querySelector(`:scope > table`),keepWithNext:e.keepNext,section:n.flow,sectionMark:!!e.section&&!e.element.textContent&&!e.element.querySelector(`[data-foli-picture]`),lines:i.lines,inColumn:r.every(e=>e===r[0])?void 0:t=>x(e,r[t]),breaksAfter:(t=0)=>{let n=x(e,r[t]),i=c?n.breaks(Id):[];return o?.pageBreakBefore&&i.push(n.lines().length-1),i},columnBreaksAfter:(t=0)=>u?x(e,r[t]).breaks(Ld):[]}}),E={orphans:2,widows:2,spacing:`word`,addSpacing:e.settings?.doNotUseHTMLParagraphAutoSpacing===!0,evenAndOddHeaders:e.settings?.evenAndOddHeaders===!0,notes:h.flowRules()},D=Zf(T,0,E),O=Qf(T,D);for(let e=0;e<2&&p.settle(O);e++)D=Zf(T,0,E),O=Qf(T,D);if(d.some(t=>yd(e,`footnote`,t).restart===`eachPage`)){let t=new Map;for(let e of np(D))!e.fromLine&&!t.has(e.id)&&t.set(e.id,e.page);s=o((e,n)=>t.get(n));let n=wd(s);h.setDocument(e,d,m,s);for(let e of l)for(let t of e.element.querySelectorAll(`[${$d}]`))t.textContent=n.get(t.getAttribute(`data-foli-note-ref`))??``;D=Zf(T,0,E),O=Qf(T,D)}let{fragments:k,gaps:ne}=D,re=np(D);l.forEach((e,t)=>{let n=k[t]??[];if(n.length<2)return;let r=_.get(e);for(let t of n)x(e,S(r,t)).lines()});for(let e of u)e.measuring.remove();let ie=[];l.forEach((e,t)=>{for(let n of k[t]??[]){let t=ie[n.page]??[];ie[n.page]=t,t[n.band??0]??=_.get(e)}});let A=Math.max(1,ie.length,...re.map(e=>e.page+1)),j=[];for(let e=A-1;e>=0;e--)j[e]=ie[e]?.[0]??j[e+1]??u.at(-1);let ae=j.map((e,t)=>{let n=Vp(r,e.geometry);n.page.setAttribute(ip,String(e.flow.index??0));let i=O[t];if(!i?.sectionPages)return n;let{top:a,bottom:o}=p.margins(i.section,i);n.page.style.paddingTop=`${a}px`,n.page.style.paddingBottom=`${o}px`;for(let e of[`header`,`footer`]){let t=p.drawing(i.section,e,i);if(!t)continue;let r=p.element(i.section,e);r.append(t.content.content.cloneNode(!0)),n.page.append(r)}return n}),oe=new Map,M=(e,t)=>{let{body:n}=ae[e.page],i=ie[e.page]??[t];if(i.length===1&&t.flow.columns===1)return n;let a=e.band??0;for(let t=0;t<=a;t++){let a=`${e.page} ${t}`;if(oe.has(a))continue;let o=up(r,i[t].columns);oe.set(a,o),n.append(o.band)}let o=oe.get(`${e.page} ${a}`);return e.lead&&(o.band.style.marginTop=`${e.lead}px`),o.columns[e.column??0]},se=(e,t)=>(ie[e]?.[t]??j[e])?.flow.index??0,ce=e=>h.groups(e,se),le=ce(re).filter(e=>!e.inFlow),ue=new Map,N=[],de=[];l.forEach((e,t)=>{let n=_.get(e),i=k[t]??[],a=t=>x(e,S(n,t)).lines();i.forEach((o,s)=>{let c=M(o,n),l=e.element;if(i.length>1){let t=a(o),n=o.fromLine?t[o.fromLine-1]??0:0,i=o.toLine===1/0?t[t.length-1]??0:t[o.toLine-1]??0,c=r.createElement(`div`);c.style.overflow=`hidden`,c.style.height=`${i-n}px`;let u=s===0?e.element:e.element.cloneNode(!0);s>0&&u.setAttribute(`aria-hidden`,`true`),u.style.marginTop=`${-n}px`,c.append(u),l=c;let d=s>0?w.get(e)??0:0;if(d){let t=r.createElement(`div`);t.style.overflow=`hidden`,t.style.height=`${d}px`;let n=e.element.cloneNode(!0);n.setAttribute(`aria-hidden`,`true`),n.style.marginTop=`0`,t.append(n),l=r.createElement(`div`),l.append(t,c)}}o.mark&&(l.style.position=`absolute`),l.style.marginTop=`${o.fromLine===0?ne[t]??0:0}px`,c.append(l),N.push({page:o.page,nodes:s===0?e.nodes:null,mark:!!o.mark,lines:()=>(o.toLine===1/0?x(e,S(n,o)).shown().length:o.toLine)-o.fromLine})});for(let t of C.get(e)??[]){let e=i[0]?.page??0;for(let n of i){let r=n.fromLine?a(n)[n.fromLine-1]??0:0;t.top+.5>=r&&(e=n.page)}de.push({page:e,text:t.text})}let o=i[0];if(o)for(let t of e.nodes)ue.set(t,o.page)});for(let e of ce(re))e.inFlow&&M({page:e.page,band:e.band,column:e.column},u[e.section]).append(h.groupElement(e,null,void 0,e.pieces[0]?.end?0:tp(T,D,e.page,e.band,e.column)));for(let e of ce(re)){if(e.inFlow)continue;let{page:t}=ae[e.page],n=u[e.section],r=O[e.page],i=r?.sectionPages?p.margins(r.section,r).bottom:n.geometry.bottom,a=h.footPlace({left:n.geometry.left,bottom:i},h.stacked(e,le));t.append(h.groupElement(e,a))}let fe=ae.map(({page:e})=>(t.append(e),e)),pe=null,me=null,he={pages:O.length,pageAt:t=>{if(!me){let t=[];(i??kn(e.content)).forEach((e,n)=>{t.push(n)}),me=t}let n=me.length-1;for(;n>0&&me[n]>t;)n--;for(;n>0&&!ue.has(n);)n--;let r=O[ue.get(n)??-1];if(!r)return null;let a=d[r.section]?.pageNumbers?.format;return{number:r.number,sectionPages:r.sectionPages,format:a}}},ge=e=>`${e}px`;return{pages:fe,fieldLayout:he,printStyles:()=>{let e=u.at(-1).geometry;return ap(`.${Ip}`,{width:ge(e.width),height:ge(e.height)},u.map(({geometry:e,flow:t})=>({width:ge(e.width),height:ge(e.height),index:t.index??0})),`word`)},pageOf:e=>ue.get(e),lineOf:e=>{if(!pe){pe=new Map;let e=-1,t=1;for(let n of N){n.page!==e&&(e=n.page,t=1);for(let e of n.nodes??[])pe.set(e,n.mark?Math.max(t-1,1):t);n.mark||(t+=n.lines())}}return pe.get(e)},cellParagraphs:()=>de,destroy:()=>{for(let e of fe)e.remove()}}}var qp=new Set([`PAGE`,`NUMPAGES`,`SECTIONPAGES`,`PAGEREF`]);function Jp(e){let t=e.ownerDocument,n=new Map;for(let t of e.querySelectorAll(`[data-foli-bookmark]`)){let e=t.getAttribute(`data-foli-bookmark`)??``;e&&!n.has(e)&&!t.closest(`[aria-hidden]`)&&n.set(e,t)}let r=0;for(let i of e.querySelectorAll(`[data-href]`)){let e=i.dataset.href??``,a=null;if(e.startsWith(`#`)){let t=n.get(e.slice(1));t&&(t.id||=`foli-bookmark-${r++}`,a=`#${t.id}`)}else/^[a-z][a-z0-9+.-]*:/i.test(e)&&le(e)&&(a=e);if(!a)continue;let o=t.createElement(`a`);o.href=a,o.style.color=`inherit`,o.style.textDecoration=`none`,i.replaceWith(o),o.append(i)}}var Yp=1e4;async function Xp(e){let t=[...e.images].filter(e=>!e.complete),n;await Promise.race([Promise.all(t.map(e=>e.decode().catch(()=>null))),new Promise(e=>{n=setTimeout(e,Yp)})]),clearTimeout(n);for(let e of t)e.complete||e.removeAttribute(`src`)}async function Zp({document:e,images:t,review:n,styles:r}){let i=window.document,a=i.createElement(`style`);a.textContent=`html,body{margin:0;background:#fff}${r}`,i.head.append(a),await Promise.all([...i.fonts].map(e=>e.load().catch(()=>null)));let o=i.body,s=e=>t[e]??null,c=e=>Kp(e,o,{review:n,resource:s}),l=Dn(e),u=c(l),d=Fd({document:l}),f=bl(d,{layout:u.fieldLayout});if(f.updated){u.destroy(),u=c(d.getDocument());let e=bl(d,{layout:u.fieldLayout,only:e=>qp.has(e.name)});e.updated&&(u.destroy(),u=c(d.getDocument())),f.updated+=e.updated}Jp(o);let p=i.createElement(`style`);return p.textContent=u.printStyles(),i.head.append(p),await Xp(i),await i.fonts.ready,{pages:u.pages.length,fields:f}}return window.foliPdf={render:Zp},e.imagesLoaded=Xp,e})({});
|
|
1
|
+
var foliPdfRenderer=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=class{expr;elements;matches=new Map;constructor(e,t){this.expr=e,this.elements=t}match(e){let t=e.join(`,`),r=this.matches.get(t);return r||(r=new n(this,e),this.matches.set(t,r)),r}close(e){let t=new Set;for(let n of e)for(t.add(n);n<this.elements.length&&this.elements[n]?.optional;)t.add(++n);return[...t].sort((e,t)=>e-t)}},n=class{program;states;next=new Map;validEnd;constructor(e,t){this.program=e,this.states=t,this.validEnd=t.includes(e.elements.length)}matchType(e){let t=this.next.get(e);if(t===void 0){let n=[];for(let t of this.states){let r=this.program.elements[t];r?.types.includes(e)&&n.push(r.repeat?t:t+1)}t=n.length?this.program.match(this.program.close(n)):null,this.next.set(e,t)}return t}matchFragment(e,t=0,n=e.childCount){let r=this;for(let i=t;r&&i<n;i++)r=r.matchType(e.child(i).type);return r}get nextTypes(){let e=[];for(let t of this.states)for(let n of this.program.elements[t]?.types??[])e.includes(n)||e.push(n);return e}get defaultType(){return this.nextTypes.find(e=>!e.isText&&!e.hasRequiredAttrs()&&e.contentMatch.validEnd)??null}findWrapping(e){let t=new Set,n=[{match:this,type:null,via:null}];for(;n.length;){let r=n.shift();if(r.match.matchType(e)){let e=[];for(let t=r;t?.type;t=t.via)e.push(t.type);return e.reverse()}for(let e of r.match.nextTypes){let i=r.match.matchType(e);e.isLeaf||e.hasRequiredAttrs()||t.has(e)||r.type&&!i?.validEnd||(t.add(e),n.push({match:e.contentMatch,type:e,via:r}))}}return null}get inlineContent(){return this.program.elements[0]?.types[0]?.isInline??!1}toString(){return this.program.expr}static compile(e,n){let i=new t(e,r(e,n)),a=i.elements.flatMap(e=>e.types).map(e=>e.isInline);if(a.some(e=>e!==a[0]))throw Error(`Content expression "${e}" mixes inline and block nodes`);return i.match(i.close([0]))}};function r(e,t){let n=e.match(/\w+|[()|*+?]|\S/g)??[],r=[],i=0,a=t=>{throw Error(`Invalid content expression "${e}": ${t}`)},o=e=>{if(e===void 0||!/^\w+$/.test(e))return a(`expected a name, got ${e}`);let n=t.filter(t=>t.name===e),r=n.length?n:t.filter(t=>t.groups.includes(e));return r.length?r:a(`no node type or group "${e}"`)};for(;i<n.length;){let e;if(n[i]===`(`){for(i++,e=o(n[i++]);n[i]===`|`;)i++,e=e.concat(o(n[i++]));n[i++]!==`)`&&a(`expected ")"`)}else e=o(n[i++]);let t=n[i];(t===`*`||t===`+`||t===`?`)&&i++,t===`+`&&r.push({types:e,optional:!1,repeat:!1}),r.push({types:e,optional:t===`*`||t===`+`||t===`?`,repeat:t===`*`||t===`+`})}return r}var i=class extends Error{name=`FoliDocumentError`},a=class extends Error{name=`ReplaceError`};function o(e,t){throw new i(`${e}: ${t}`)}var s=Object.freeze({});function c(e,t,n){for(let r of Object.keys(t??s))e&&Object.hasOwn(e,r)||o(`${n}.${r}`,`unknown attribute`);if(!e)return s;let r={};for(let[i,a]of Object.entries(e)){let e=t?.[i];e===void 0&&(`default`in a||o(`${n}.${i}`,`required attribute is missing`),e=a.default);let s=a.validate?.(e);s!==void 0&&o(`${n}.${i}`,s),r[i]=e}return r}function l(e,t){if(!e)return;let n;for(let[r,i]of Object.entries(e)){let e=t[r];`default`in i&&u(e,i.default)||(n??={},n[r]=e)}return n}function u(e,t){if(e===t)return!0;if(typeof e!=`object`||typeof t!=`object`||e===null||t===null||Array.isArray(e)!==Array.isArray(t))return!1;let n=Object.keys(e);return n.length===Object.keys(t).length&&n.every(n=>Object.hasOwn(t,n)&&u(e[n],t[n]))}var d=class e{type;attrs;static none=Object.freeze([]);constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,n=!1;for(let r=0;r<e.length;r++){let i=e[r];if(this.eq(i))return e;if(this.type.excludes(i.type))t??=e.slice(0,r);else{if(i.type.excludes(this.type))return e;!n&&i.type.rank>this.type.rank&&(t??=e.slice(0,r),t.push(this),n=!0),t?.push(i)}}return t??=e.slice(),n||t.push(this),t}removeFromSet(e){return this.isInSet(e)?e.filter(e=>!e.eq(this)):e}isInSet(e){return e.some(e=>e.eq(this))}eq(e){return this===e||this.type===e.type&&u(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name},t=l(this.type.spec.attrs,this.attrs);return t&&(e.attrs=t),e}static sameSet(e,t){return e===t||e.length===t.length&&e.every((e,n)=>e.eq(t[n]))}static setFrom(t){return t?t instanceof e?[t]:t.length<2?t:[...t].sort((e,t)=>e.type.rank-t.type.rank):e.none}},f=class e{content;size;static empty=new e([],0);constructor(e,t){this.content=e,this.size=t}static fromArray(t){if(!t.length)return e.empty;let n=[],r=0;for(let e of t){r+=e.nodeSize;let t=n[n.length-1];t?.isText&&e.isText&&d.sameSet(t.marks,e.marks)?n[n.length-1]=t.withText(t.textContent+e.textContent):n.push(e)}return new e(n,r)}static from(t){return t?t instanceof e?t:e.fromArray(Array.isArray(t)?t:[t]):e.empty}get childCount(){return this.content.length}get firstChild(){return this.content[0]??null}get lastChild(){return this.content[this.content.length-1]??null}child(e){let t=this.content[e];if(!t)throw RangeError(`Index ${e} out of range for fragment of ${this.childCount}`);return t}maybeChild(e){return this.content[e]??null}forEach(e){for(let t=0,n=0;t<this.content.length;t++){let r=this.content[t];e(r,n,t),n+=r.nodeSize}}nodesBetween(e,t,n,r=0,i=null){for(let a=0,o=0;o<t&&a<this.content.length;a++){let s=this.content[a],c=o+s.nodeSize;if(c>e&&n(s,r+o,i,a)!==!1&&s.content.size){let i=o+1;s.content.nodesBetween(Math.max(0,e-i),Math.min(s.content.size,t-i),n,r+i,s)}o=c}}textBetween(e,t,n=``,r=``){let i=``,a=!0;return this.nodesBetween(e,t,(o,s)=>{o.isTextblock?(a||(i+=n),a=!1):o.isText?i+=o.textContent.slice(Math.max(e,s)-s,t-s):o.isLeaf&&(i+=typeof r==`string`?r:r(o))}),i}append(t){return t.size?this.size?e.fromArray([...this.content,...t.content]):t:this}cut(t,n=this.size){if(t<=0&&n>=this.size)return this;if(t>=n)return e.empty;let r=[],i=0;for(let e=0,a=0;a<n;e++){let o=this.content[e],s=a+o.nodeSize;s>t&&((a<t||s>n)&&(o=o.isText?o.cut(Math.max(0,t-a),Math.min(o.nodeSize,n-a)):o.cut(Math.max(0,t-a-1),Math.min(o.content.size,n-a-1))),r.push(o),i+=o.nodeSize),a=s}return new e(r,i)}cutByIndex(t,n){return t===n?e.empty:t===0&&n===this.content.length?this:e.fromArray(this.content.slice(t,n))}replaceChild(t,n){let r=this.child(t);if(r===n)return this;let i=this.content.slice();return i[t]=n,new e(i,this.size-r.nodeSize+n.nodeSize)}findIndex(e){if(e===0)return{index:0,offset:0};if(e===this.size)return{index:this.content.length,offset:e};if(e<0||e>this.size)throw RangeError(`Position ${e} outside fragment`);for(let t=0,n=0;;t++){let r=n+this.content[t].nodeSize;if(r>e)return{index:t,offset:n};n=r}}eq(e){return this===e||this.content.length===e.content.length&&this.content.every((t,n)=>t.eq(e.content[n]))}toJSON(){return this.content.map(e=>e.toJSON())}toString(){return`<${this.content.join(`, `)}>`}};function p(e,t,n){if(n.openStart>e.depth)throw new a(`Inserted content is deeper than the insertion position`);if(e.depth-n.openStart!==t.depth-n.openEnd)throw new a(`Inconsistent open depths`);return m(e,t,n,0)}function m(e,t,n,r){let i=e.index(r),a=e.node(r);if(i===t.index(r)&&r<e.depth-n.openStart){let o=m(e,t,n,r+1);return a.copy(a.content.replaceChild(i,o))}if(!n.content.size)return x(a,_(e,t,r));if(!n.openStart&&!n.openEnd&&e.depth===r&&t.depth===r){let r=a.content;return x(a,r.cut(0,e.parentOffset).append(n.content).append(r.cut(t.parentOffset)))}let{start:o,end:s}=h(n,e);return x(a,g(e,o,s,t,r))}function h(e,t){let n=t.depth-e.openStart,r=t.node(n).copy(e.content);for(let e=n-1;e>=0;e--)r=t.node(e).copy(f.from(r));return{start:r.resolve(e.openStart+n),end:r.resolve(r.content.size-e.openEnd-n)}}function g(e,t,n,r,i){let a=e.depth>i?y(e,t,i+1):null,o=r.depth>i?y(n,r,i+1):null,s=[];return v(null,e,i,s),a&&o&&t.index(i)===n.index(i)?(b(a,o),s.push(x(a,g(e,t,n,r,i+1)))):(a&&s.push(x(a,_(e,t,i+1))),v(t,n,i,s),o&&s.push(x(o,_(n,r,i+1)))),v(r,null,i,s),f.fromArray(s)}function _(e,t,n){let r=[];if(v(null,e,n,r),e.depth>n){let i=y(e,t,n+1);r.push(x(i,_(e,t,n+1)))}return v(t,null,n,r),f.fromArray(r)}function v(e,t,n,r){let i=(t??e).node(n),a=0,o=t?t.index(n):i.childCount;e&&(a=e.index(n),e.depth>n?a++:e.textOffset&&(r.push(e.nodeAfter),a++));for(let e=a;e<o;e++)r.push(i.child(e));t&&t.depth===n&&t.textOffset&&r.push(t.nodeBefore)}function y(e,t,n){let r=e.node(n);return b(r,t.node(n)),r}function b(e,t){if(!t.type.compatibleContent(e.type))throw new a(`Cannot join ${t.type.name} onto ${e.type.name}`)}function x(e,t){if(!e.type.validContent(t))throw new a(`Invalid content for node ${e.type.name}`);return e.copy(t)}var S=class e{pos;nodes;indices;starts;parentOffset;textOffset;constructor(e,t,n,r,i,a){this.pos=e,this.nodes=t,this.indices=n,this.starts=r,this.parentOffset=i,this.textOffset=a}static resolve(t,n){if(!(n>=0&&n<=t.content.size)||!Number.isInteger(n))throw RangeError(`Position ${n} out of range 0..${t.content.size}`);let r=[],i=[],a=[],o=t,s=0,c=n;for(;;){let{index:t,offset:l}=o.content.findIndex(c);r.push(o),i.push(t),a.push(s);let u=c-l,d=o.content.maybeChild(t);if(u===0||!d)return new e(n,r,i,a,c,0);if(d.isText)return new e(n,r,i,a,c,u);o=d,s+=l+1,c=u-1}}get depth(){return this.nodes.length-1}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e=this.depth){return this.nodes[this.at(e)]}index(e=this.depth){return this.indices[this.at(e)]}indexAfter(e=this.depth){let t=this.at(e);return this.index(t)+(t===this.depth&&!this.textOffset?0:1)}start(e=this.depth){return this.starts[this.at(e)]}end(e=this.depth){let t=this.at(e);return this.start(t)+this.node(t).content.size}before(e=this.depth){if(e===this.depth+1)return this.pos;let t=this.at(e);if(!t)throw RangeError(`There is no position before the root node`);return this.start(t)-1}after(e=this.depth){if(e===this.depth+1)return this.pos;let t=this.at(e);if(!t)throw RangeError(`There is no position after the root node`);return this.end(t)+1}get nodeAfter(){let e=this.parent.maybeChild(this.index());return e?this.textOffset?e.cut(this.textOffset):e:null}get nodeBefore(){let e=this.index();return this.textOffset?this.parent.child(e).cut(0,this.textOffset):this.parent.maybeChild(e-1)}posAtIndex(e,t=this.depth){let n=this.node(t),r=this.start(t);for(let t=0;t<e;t++)r+=n.child(t).nodeSize;return r}sharedDepth(e){for(let t=this.depth;t>0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos<this.pos)return e.blockRange(this,t);let n=this.depth-(this.parent.inlineContent||this.pos===e.pos?1:0);for(let r=n;r>=0;r--)if(e.pos<=this.end(r)&&(!t||t(this.node(r))))return new C(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset===e.pos-e.parentOffset}toString(){return`${this.nodes.slice(1).map((e,t)=>`${e.type.name}_${this.indices[t]}`).join(`/`)}:${this.parentOffset}`}at(e){let t=e<0?this.depth+e:e;if(t<0||t>this.depth)throw RangeError(`Depth ${e} out of range`);return t}},C=class{$from;$to;depth;constructor(e,t,n){this.$from=e,this.$to=t,this.depth=n}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}},w=class e{content;openStart;openEnd;static empty=new e(f.empty,0,0);constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(t,n){let r=ee(this.content,t+this.openStart,n,{parent:null,level:0,onStart:!0,onEnd:!0,openStart:this.openStart,openEnd:this.openEnd});return r&&new e(r,this.openStart,this.openEnd)}removeBetween(t,n){return new e(te(this.content,t+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart===e.openStart&&this.openEnd===e.openEnd}toJSON(){return{content:this.content.toJSON(),openStart:this.openStart,openEnd:this.openEnd}}};function ee(e,t,n,r){let{index:i,offset:a}=e.findIndex(t),o=e.maybeChild(i);if(a===t||!o||o.isText){let i=e.cut(0,t).append(n).append(e.cut(t)),{parent:a,level:o}=r,s=r.onStart&&o<=r.openStart||r.onEnd&&o<=r.openEnd;return a&&!s&&!a.type.validContent(i)?null:i}let s=ee(o.content,t-a-1,n,{...r,parent:o,level:r.level+1,onStart:r.onStart&&i===0,onEnd:r.onEnd&&i===e.childCount-1});return s&&e.replaceChild(i,o.copy(s))}function te(e,t,n){let{index:r,offset:i}=e.findIndex(t),a=e.maybeChild(r),{index:o,offset:s}=e.findIndex(n);if(i===t||!a||a.isText){if(s!==n&&!e.child(o).isText)throw RangeError(`Removing a non-flat range`);return e.cut(0,t).append(e.cut(n))}if(r!==o)throw RangeError(`Removing a non-flat range`);return e.replaceChild(r,a.copy(te(a.content,t-i-1,n-i-1)))}var T=class e{type;attrs;content;marks;constructor(e,t,n,r){this.type=e,this.attrs=t,this.content=n,this.marks=r}get nodeSize(){return this.type.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}get isText(){return this.type.isText}get isInline(){return this.type.isInline}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}get inlineContent(){return this.type.inlineContent}get textContent(){return this.content.textBetween(0,this.content.size)}child(e){return this.content.child(e)}maybeChild(e){return this.content.maybeChild(e)}forEach(e){this.content.forEach(e)}nodesBetween(e,t,n){this.content.nodesBetween(e,t,n,0,this)}descendants(e){this.nodesBetween(0,this.content.size,e)}textBetween(e,t,n,r){return this.content.textBetween(e,t,n,r)}sameMarkup(e){return this.type===e.type&&u(this.attrs,e.attrs)&&d.sameSet(this.marks,e.marks)}eq(e){return this===e||this.sameMarkup(e)&&this.content.eq(e.content)}copy(t=f.empty){return t===this.content?this:new e(this.type,this.attrs,t,this.marks)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw RangeError(`Invalid content in ${this.type.name}`);return t}canReplace(e,t,n=f.empty,r=0,i=n.childCount){if(!this.contentMatchAt(e).matchFragment(n,r,i)?.matchFragment(this.content,t)?.validEnd)return!1;for(let e=r;e<i;e++)if(!this.type.allowsMarks(n.child(e).marks))return!1;return!0}canReplaceWith(e,t,n){return!!this.contentMatchAt(e).matchType(n)?.matchFragment(this.content,t)?.validEnd}mark(t){return d.sameSet(t,this.marks)?this:new e(this.type,this.attrs,this.content,t)}cut(e,t=this.content.size){return e===0&&t===this.content.size?this:this.copy(this.content.cut(e,t))}slice(e,t=this.content.size){if(e>t)throw RangeError(`Invalid range ${e}..${t}`);if(e===t)return w.empty;let n=this.resolve(e),r=this.resolve(t),i=n.sharedDepth(t),a=n.start(i);return new w(n.node(i).content.cut(n.pos-a,r.pos-a),n.depth-i,r.depth-i)}replace(e,t,n){if(e>t)throw RangeError(`Invalid range ${e}..${t}`);return p(this.resolve(e),this.resolve(t),n)}nodeAt(e){let t=this;for(;;){let{index:n,offset:r}=t.content.findIndex(e),i=t.content.maybeChild(n);if(!i)return null;if(r===e||i.isText)return i;t=i,e-=r+1}}resolve(e){return S.resolve(this,e)}check(){if(!this.type.validContent(this.content))throw new i(`Invalid content for node ${this.type.name}: ${this.content}`);this.content.forEach(e=>{e.check()})}toJSON(){let e={type:this.type.name},t=l(this.type.spec.attrs,this.attrs);return t&&(e.attrs=t),this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(e=>e.toJSON())),e}toString(){return this.content.size?`${this.type.name}(${this.content.content.join(`, `)})`:this.type.name}},ne=class e extends T{text;constructor(e,t,n){if(super(e,s,f.empty,n),this.text=t,!t)throw RangeError(`Empty text nodes are not allowed`)}get nodeSize(){return this.text.length}get textContent(){return this.text}eq(e){return this===e||this.sameMarkup(e)&&this.text===e.text}mark(t){return d.sameSet(t,this.marks)?this:new e(this.type,this.text,t)}cut(e=0,t=this.text.length){return e===0&&t===this.text.length?this:this.withText(this.text.slice(e,t))}withText(t){return t===this.text?this:new e(this.type,t,this.marks)}toJSON(){let e={type:this.type.name,text:this.text};return this.marks.length&&(e.marks=this.marks.map(e=>e.toJSON())),e}toString(){let e=JSON.stringify(this.text);return this.marks.length?`${this.marks.map(e=>e.type.name).join(`+`)}${e}`:e}},E=[`type`,`attrs`,`content`,`text`,`marks`],D=[`type`,`attrs`],O=[`content`,`openStart`,`openEnd`],re=class{name;schema;spec;groups;isText;isInline;isBlock;isLeaf;contentMatch;markSet;constructor(e,t,n){this.name=e,this.schema=t,this.spec=n,this.groups=n.group?n.group.split(` `):[],this.isText=e===`text`,this.isInline=this.isText||!!n.inline,this.isBlock=!this.isInline,this.isLeaf=!n.content}get inlineContent(){return this.contentMatch.inlineContent}get isTextblock(){return this.isBlock&&this.inlineContent}get isAtom(){return this.isLeaf||!!this.spec.atom}hasRequiredAttrs(){return Object.values(this.spec.attrs??{}).some(e=>!(`default`in e))}create(e,t,n){if(this.isText)throw RangeError(`Use Schema.text to create text nodes`);let r=f.from(t);return this.validContent(r)||o(this.name,`invalid content ${r}`),new T(this,c(this.spec.attrs,e??void 0,`${this.name}.attrs`),r,d.setFrom(n))}createOpen(e,t){if(this.isText)throw RangeError(`Use Schema.text to create text nodes`);return new T(this,c(this.spec.attrs,e??void 0,`${this.name}.attrs`),f.from(t),d.none)}validContent(e){return this.contentMatch.matchFragment(e)?.validEnd?e.content.every(e=>this.allowsMarks(e.marks)):!1}allowsMarkType(e){return this.markSet===null||this.markSet.includes(e)}allowsMarks(e){return this.markSet===null||e.every(e=>this.allowsMarkType(e.type))}compatibleContent(e){return this===e||!this.isLeaf&&!e.isLeaf&&this.inlineContent===e.inlineContent}checkContent(e,t){let n=this.contentMatch;e.forEach((e,r)=>{let i=n.matchType(e.type);i||o(`${t}.content[${r}]`,`${e.type.name} is not allowed here in ${this.name}`),this.allowsMarks(e.marks)||o(`${t}.content[${r}].marks`,`marks not allowed in ${this.name}`),n=i}),n.validEnd||o(`${t}.content`,`${this.name} content is incomplete (expected "${n}")`)}},ie=class{name;schema;spec;rank;excluded;groups;instance;constructor(e,t,n,r){this.name=e,this.schema=t,this.spec=n,this.rank=r,this.groups=n.group?n.group.split(` `):[],this.instance=n.attrs?null:new d(this,s)}create(e){return this.instance&&!(e&&Object.keys(e).length)?this.instance:new d(this,c(this.spec.attrs,e??void 0,`${this.name}.attrs`))}get inclusive(){return this.spec.inclusive??!0}excludes(e){return this.excluded.includes(e)}isInSet(e){return e.find(e=>e.type===this)}removeFromSet(e){return this.isInSet(e)?e.filter(e=>e.type!==this):e}},ae=class{spec;nodes;marks;topNodeType;constructor(e){this.spec=e;let t=Object.create(null),r=Object.create(null);for(let[n,r]of Object.entries(e.nodes))t[n]=new re(n,this,r);Object.entries(e.marks??{}).forEach(([e,t],n)=>{r[e]=new ie(e,this,t,n)}),this.nodes=t,this.marks=r;let i=t.text;if(!i||i.spec.attrs||i.spec.content)throw Error("A schema needs a `text` node type without attrs or content");let a=t[e.topNode??`doc`];if(!a)throw Error(`Schema has no top node type "${e.topNode??`doc`}"`);this.topNodeType=a;let o=Object.values(t),s=Object.values(r);for(let e of o){e.contentMatch=n.compile(e.spec.content??``,o);let t=e.spec.marks??(e.inlineContent?`_`:``);e.markSet=t===`_`?null:k(s,t)}for(let e of s){let t=e.spec.excludes??e.name;e.excluded=t===`_`?s:k(s,t)}}nodeType(e){return this.nodes[e]}markType(e){return this.marks[e]}node(e,t,n,r){return this.resolveNodeType(e).create(t,n,r)}text(e,t){return new ne(this.resolveNodeType(`text`),e,d.setFrom(t))}mark(e,t){if(typeof e!=`string`)return e.create(t);let n=this.marks[e];if(!n)throw RangeError(`Unknown mark type "${e}"`);return n.create(t)}nodeFromJSON(e,t=`$`){return this.parseNode(e,t,0,0)}markFromJSON(e,t=`$`){let n=A(e,t,D),r=typeof n.type==`string`?this.marks[n.type]:void 0;if(!r)return o(`${t}.type`,`unknown mark type ${JSON.stringify(n.type)}`);if(!r.spec.attrs)return n.attrs!==void 0&&o(`${t}.attrs`,`${r.name} has no attributes`),r.create();let i=n.attrs===void 0?void 0:A(n.attrs,`${t}.attrs`);return new d(r,c(r.spec.attrs,i,`${t}.attrs`))}sliceFromJSON(e,t=`$`){let n=A(e,t,O),r=oe(n.content,`${t}.content`),{openStart:i,openEnd:a}=n;se(i)||o(`${t}.openStart`,`expected a non-negative integer`),se(a)||o(`${t}.openEnd`,`expected a non-negative integer`),!r.length&&(i||a)&&o(t,`an empty slice cannot be open`);let s=r.map((e,n)=>this.parseNode(e,`${t}.content[${n}]`,n===0?i:0,n===r.length-1?a:0));return new w(f.fromArray(s),i,a)}parseNode(e,t,n,r,i=0){i>300&&o(t,`nodes nested deeper than 300 levels`);let a=A(e,t,E),s=typeof a.type==`string`?this.nodes[a.type]:void 0;if(!s)return o(`${t}.type`,`unknown node type ${JSON.stringify(a.type)}`);let l=a.marks===void 0?d.none:this.marksFromJSON(a.marks,`${t}.marks`);if((n||r)&&s.isLeaf&&o(t,`a leaf node cannot be open`),s.isText)return a.attrs!==void 0&&o(`${t}.attrs`,`text nodes have no attributes`),a.content!==void 0&&o(`${t}.content`,`text nodes have no content`),typeof a.text==`string`&&a.text||o(`${t}.text`,`text must be a non-empty string`),new ne(s,a.text,l);a.text!==void 0&&o(`${t}.text`,`only text nodes have text`),a.attrs!==void 0&&!s.spec.attrs&&o(`${t}.attrs`,`${s.name} has no attributes`);let u=c(s.spec.attrs,a.attrs===void 0?void 0:A(a.attrs,`${t}.attrs`),`${t}.attrs`),p=[];if(a.content!==void 0){s.isLeaf&&o(`${t}.content`,`${s.name} cannot have content`);let e=oe(a.content,`${t}.content`);p=e.map((a,o)=>this.parseNode(a,`${t}.content[${o}]`,o===0?Math.max(n-1,0):0,o===e.length-1?Math.max(r-1,0):0,i+1))}return n||r?!p.length&&(n>1||r>1)&&o(`${t}.content`,`open depth exceeds the content`):s.checkContent(p,t),new T(s,u,f.fromArray(p),l)}marksFromJSON(e,t){let n=d.none;return oe(e,t).forEach((e,r)=>{let i=this.markFromJSON(e,`${t}[${r}]`),a=n.find(e=>e.type.excludes(i.type)||i.type.excludes(e.type));a&&o(`${t}[${r}]`,a.type===i.type?`duplicate mark`:`${i.type.name} cannot be combined with ${a.type.name}`),n=i.addToSet(n)}),n}resolveNodeType(e){if(typeof e!=`string`)return e;let t=this.nodes[e];if(!t)throw RangeError(`Unknown node type "${e}"`);return t}};function k(e,t){let n=[];for(let r of t.split(` `).filter(Boolean)){let t=e.filter(e=>e.name===r||e.groups.includes(r));if(!t.length)throw Error(`Unknown mark type or group "${r}"`);for(let e of t)n.includes(e)||n.push(e)}return n}function A(e,t,n){if((typeof e!=`object`||!e||Array.isArray(e))&&o(t,`expected an object`),n)for(let r of Object.keys(e))n.includes(r)||o(`${t}.${r}`,`unknown key`);return e}function oe(e,t){return Array.isArray(e)||o(t,`expected an array`),e}function se(e){return typeof e==`number`&&Number.isInteger(e)&&e>=0}var j=[1,2,3,4,5,6],ce=[`start`,`center`,`end`,`justify`],le=[`http:`,`https:`,`mailto:`,`tel:`];function ue(e){if(typeof e!=`string`||!e||e.length>8192||/[\u0000- \u007f-\u009f\\]/.test(e))return!1;let t=/^([a-zA-Z][a-zA-Z0-9+.-]*):/.exec(e);return!t||le.includes(`${t[1]?.toLowerCase()}:`)}function de(e){return e?.href===null||e?.href===void 0?typeof e?.anchor==`string`:ue(e.href)}function M(e){return typeof e==`string`&&/^#[0-9a-f]{6}$/.test(e)}var fe={default:`start`,validate:e=>ce.includes(e)?void 0:`align must be one of ${ce.join(`, `)}`},pe={validate:e=>M(e)?void 0:`color must be a lowercase #rrggbb value`},me=new ae({nodes:{doc:{content:`block+`},paragraph:{group:`block`,content:`inline*`,attrs:{align:fe}},heading:{group:`block`,content:`inline*`,attrs:{level:{validate:e=>j.includes(e)?void 0:`heading level must be an integer from 1 to 6`},align:fe}},bulletList:{group:`block`,content:`listItem+`},orderedList:{group:`block`,content:`listItem+`,attrs:{start:{default:1,validate:e=>Number.isInteger(e)&&e>=0&&e<=99999?void 0:`start must be an integer from 0 to 99999`}}},listItem:{content:`paragraph block*`},horizontalRule:{group:`block`},text:{group:`inline`},hardBreak:{group:`inline`,inline:!0,selectable:!1},pageBreak:{group:`inline`,inline:!0,selectable:!1}},marks:{link:{attrs:{href:{validate:e=>ue(e)?void 0:`href must be a relative URL or use http, https, mailto or tel`}},inclusive:!1},bold:{},italic:{},underline:{},strike:{},textColor:{attrs:{color:pe}},highlight:{attrs:{color:pe}}}}),he=2,ge={1:e=>({...e,schemaVersion:2})},_e={pageSize:{A4:{width:210,height:297},Letter:{width:215.9,height:279.4}}.A4,margins:{top:25.4,right:25.4,bottom:25.4,left:25.4}};function ve(e){if(!xe(e))throw new i(`Document must be an object`);let t=e.schemaVersion;if(!Number.isInteger(t)||t<1)throw new i(`Unsupported schemaVersion: ${String(t)}`);if(t>he)throw new i(`Unsupported schemaVersion: ${t} (this version of @folijs/core reads 1 to ${he}; the document was saved by a newer one)`);let n=e;for(let e=t;e<he;e++){let t=ge[e];if(!t)throw new i(`No migration from schemaVersion ${e}`);n=t(n)}return{schemaVersion:he,settings:be(n.settings),content:ye(n.content).toJSON()}}function ye(e,t=`content`){let n=me.nodeFromJSON(e,t);if(n.type!==me.topNodeType)throw new i(`${t}: root node must be of type "doc"`);if(n.marks.length)throw new i(`${t}.marks: doc cannot have marks`);return n}function be(e){if(!xe(e)||!xe(e.pageSize)||!xe(e.margins))throw new i(`settings.pageSize and settings.margins are required`);let{width:t,height:n}=e.pageSize,{top:r,right:a,bottom:o,left:s}=e.margins;if(!Se(t)||!Se(n))throw new i(`pageSize width/height must be positive numbers (mm)`);if(![r,a,o,s].every(Ce))throw new i(`margins must be non-negative numbers (mm)`);let c={top:r,right:a,bottom:o,left:s};if(c.left+c.right>=t||c.top+c.bottom>=n)throw new i(`margins leave no content area on the page`);return{pageSize:{width:t,height:n},margins:c}}function xe(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Se(e){return typeof e==`number`&&Number.isFinite(e)&&e>0}function Ce(e){return typeof e==`number`&&Number.isFinite(e)&&e>=0}var we=65536,Te=(e,t)=>e+t*we,Ee=e=>e%we,De=e=>(e-Ee(e))/we,Oe=class e{ranges;inverted;static empty=new e([]);constructor(e,t=!1){this.ranges=e,this.inverted=t}mapResult(e,t=1,n){let r=0,i=this.inverted?2:1,a=this.inverted?1:2;for(let o=0;o<this.ranges.length;o+=3){let s=this.ranges[o]-(this.inverted?r:0);if(s>e)break;let c=this.ranges[o+i],l=this.ranges[o+a],u=s+c;if(e<=u){let i=c?e===s?-1:e===u?1:t:n?.[o/3]||t,a=e!==(t<0?s:u);return{pos:s+r+(i<0?0:l),deleted:e>s&&e<u,recover:a?Te(o/3,e-s):null}}r+=l-c}return{pos:e+r,deleted:!1,recover:null}}map(e,t=1){return this.mapResult(e,t).pos}recover(e){let t=0,n=Ee(e);if(!this.inverted)for(let e=0;e<n;e++)t+=this.ranges[e*3+2]-this.ranges[e*3+1];return this.ranges[n*3]+t+De(e)}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let r=0,i=0;r<this.ranges.length;r+=3){let a=this.ranges[r],o=a-(this.inverted?i:0),s=a+(this.inverted?0:i),c=this.ranges[r+t],l=this.ranges[r+n];e(o,o+c,s,s+l),i+=l-c}}sides(e){let t=[];return this.forEach((n,r)=>{t.push(e<=n?-1:+(e>=r))}),t}invert(){return new e(this.ranges,!this.inverted)}},ke=class e{maps;mirror;from;to;constructor(e=[],t=new Map,n=0,r=e.length){this.maps=e,this.mirror=t,this.from=n,this.to=r}slice(t=0,n=this.maps.length){return new e(this.maps,this.mirror,t,n)}appendMap(e,t){this.to=this.maps.push(e),t!==void 0&&(this.mirror.set(this.maps.length-1,t),this.mirror.set(t,this.maps.length-1))}appendMapping(e){let t=this.maps.length;for(let n=e.from;n<e.to;n++){let r=e.getMirror(n);this.appendMap(e.maps[n],r!==void 0&&r<n&&r>=e.from?t+r-e.from:void 0)}}getMirror(e){return this.mirror.get(e)}map(e,t=1){return this.mapResult(e,t).pos}mapResult(e,t=1){let n=!1;for(let r=this.from;r<this.to;r++){let i=this.maps[r].mapResult(e,t);if(i.recover!==null){let t=this.getMirror(r);if(t!==void 0&&t>r&&t<this.to){r=t,e=this.maps[t].recover(i.recover);continue}}n||=i.deleted,e=i.pos}return{pos:e,deleted:n,recover:null}}},N=class e{doc;failed;constructor(e,t){this.doc=e,this.failed=t}static ok(t){return new e(t,null)}static fail(t){return new e(null,t)}static fromReplace(t,n,r,i){try{return e.ok(t.replace(n,r,i))}catch(t){if(t instanceof a||t instanceof RangeError)return e.fail(t.message);throw t}}},Ae=class{getMap(){return Oe.empty}},je=class e extends Ae{from;to;slice;structure;constructor(e,t,n,r=!1){super(),this.from=e,this.to=t,this.slice=n,this.structure=r}apply(e){return this.structure&&Ne(e,this.from,this.to)?N.fail(`Structure replace would overwrite content`):N.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new Oe([this.from,this.to-this.from,this.slice.size])}invert(t){return new e(this.from,this.from+this.slice.size,t.slice(this.from,this.to))}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted?null:new e(n.pos,Math.max(n.pos,r.pos),this.slice,this.structure)}merge(t){if(!(t instanceof e)||t.structure||this.structure)return null;let n=(e,t)=>e.size+t.size===0?w.empty:new w(e.content.append(t.content),e.openStart,t.openEnd);return this.from+this.slice.size===t.from&&!this.slice.openEnd&&!t.slice.openStart?new e(this.from,this.to+(t.to-t.from),n(this.slice,t.slice)):t.to===this.from&&!this.slice.openStart&&!t.slice.openEnd?new e(t.from,this.to,n(t.slice,this.slice)):null}},Me=class e extends Ae{from;to;gapFrom;gapTo;slice;insert;structure;constructor(e,t,n,r,i,a,o=!1){super(),this.from=e,this.to=t,this.gapFrom=n,this.gapTo=r,this.slice=i,this.insert=a,this.structure=o}apply(e){if(this.from<0||this.from>this.gapFrom||this.gapFrom>this.gapTo||this.gapTo>this.to||this.to>e.content.size)return N.fail(`Invalid gap range ${this.from}..${this.to}`);if(this.structure&&(Ne(e,this.from,this.gapFrom)||Ne(e,this.gapTo,this.to)))return N.fail(`Structure gap-replace would overwrite content`);let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return N.fail(`Gap is not a flat range`);let n;try{n=this.slice.insertAt(this.insert,t.content)}catch(e){if(e instanceof RangeError)return N.fail(e.message);throw e}return n?N.fromReplace(e,this.from,this.to,n):N.fail(`Content does not fit in gap`)}getMap(){return new Oe([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(t){let n=this.gapTo-this.gapFrom;return new e(this.from,this.from+this.slice.size+n,this.from+this.insert,this.from+this.insert+n,t.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1),i=this.from===this.gapFrom?n.pos:t.map(this.gapFrom,-1),a=this.to===this.gapTo?r.pos:t.map(this.gapTo,1);return n.deleted&&r.deleted||i<n.pos||a>r.pos||this.gapTo>this.gapFrom&&a<=i?null:new e(n.pos,r.pos,i,a,this.slice,this.insert,this.structure)}};function Ne(e,t,n){let r=e.resolve(t),i=n-t,a=r.depth;for(;i>0&&a>0&&r.indexAfter(a)===r.node(a).childCount;)a--,i--;if(i>0){let e=r.node(a).maybeChild(r.indexAfter(a));for(;i>0;){if(!e||e.isLeaf)return!0;e=e.firstChild,i--}}return!1}function Pe(e,t,n){let r=[];return e.forEach(e=>{let i=e.content.size?e.copy(Pe(e.content,t,e)):e;i.isInline&&(i=t(i,n)),r.push(i)}),f.fromArray(r)}var Fe=class extends Ae{from;to;mark;constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){if(this.from>=this.to||this.from<0||this.to>e.content.size)return N.fail(`Invalid mark range ${this.from}..${this.to}`);let t=e.slice(this.from,this.to),n=e.resolve(this.from),r=n.node(n.sharedDepth(this.to)),i=Pe(t.content,(e,t)=>t.type.allowsMarkType(this.mark.type)?e.mark(this.change(e.marks)):e,r);return N.fromReplace(e,this.from,this.to,new w(i,t.openStart,t.openEnd))}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deleted&&n.deleted||t.pos>=n.pos?null:this.create(t.pos,n.pos)}},Ie=class e extends Fe{change(e){return this.mark.addToSet(e)}create(t,n){return new e(t,n,this.mark)}invert(){return new Le(this.from,this.to,this.mark)}},Le=class e extends Fe{change(e){return this.mark.removeFromSet(e)}create(t,n){return new e(t,n,this.mark)}invert(){return new Ie(this.from,this.to,this.mark)}},Re=class e extends Ae{pos;type;attrs;marks;constructor(e,t,n,r){super(),this.pos=e,this.type=t,this.attrs=n,this.marks=r}apply(e){let t=this.pos>=0&&this.pos<e.content.size?e.nodeAt(this.pos):null;if(!t||t.isText)return N.fail(`No node at position ${this.pos}`);let n;try{n=this.type.create(this.attrs,t.content,this.marks??t.marks)}catch(e){if(e instanceof i)return N.fail(e.message);throw e}return N.fromReplace(e,this.pos,this.pos+t.nodeSize,new w(f.from(n),0,0))}invert(t){let n=t.nodeAt(this.pos);if(!n)throw RangeError(`No node at position ${this.pos}`);return new e(this.pos,n.type,n.attrs,n.marks)}map(t){let n=t.mapResult(this.pos,1),r=t.mapResult(this.pos+1,-1);return n.deleted||r.deleted||r.pos<=n.pos?null:new e(n.pos,this.type,this.attrs,this.marks)}};function ze(e,t,n){let r=[],i=0;if(e.forEach((e,a)=>{let o=t+a,s=i;for(;i<n.length&&n[i].pos<o+e.nodeSize;)i++;if(s===i){r.push(e);return}let c=n[s].pos===o?n[s]:void 0,l=n.slice(c?s+1:s,i),u=l.length?ze(e,o+1,l):e;if(c){if(u.isText)throw RangeError(`No node at position ${o}`);if(u=c.type.create(c.attrs,u.content,c.marks??u.marks),u.nodeSize!==e.nodeSize)throw RangeError(`Node markup must keep the node size`)}r.push(u)}),i<n.length)throw RangeError(`No node at position ${n[i]?.pos}`);let a=f.fromArray(r);if(!e.type.validContent(a))throw RangeError(`Invalid content for node ${e.type.name}`);return e.copy(a)}var Be=class e extends Ae{steps;constructor(e){super(),this.steps=e}apply(e){for(let e=0;e<this.steps.length;e++){let t=this.steps[e].pos;if(t<0||e>0&&t<=this.steps[e-1].pos)return N.fail(`Unsorted or invalid node markup position ${t}`)}try{return N.ok(ze(e,0,this.steps))}catch(e){if(e instanceof i||e instanceof RangeError)return N.fail(e.message);throw e}}invert(t){let n=[],r=this.steps[this.steps.length-1];if(r&&t.nodesBetween(this.steps[0].pos,r.pos+1,(e,t)=>{this.steps[n.length]?.pos===t&&n.push(new Re(t,e.type,e.attrs,e.marks));let r=this.steps[n.length];return r!==void 0&&r.pos<t+e.nodeSize}),n.length!==this.steps.length)throw RangeError(`Node markup batch does not fit`);return new e(n)}map(t){let n=this.steps.map(e=>e.map(t)).filter(e=>e!==null);return n.length?new e(n):null}};function Ve(e,t,n){let r={},a=e.type.spec.attrs??{};for(let i of Object.keys(t.spec.attrs??{}))n&&Object.hasOwn(n,i)?r[i]=n[i]:Object.hasOwn(a,i)&&(r[i]=e.attrs[i]);for(let e of Object.keys(n??{}))Object.hasOwn(r,e)||(r[e]=n?.[e]);try{return t.createOpen(r).attrs}catch(e){throw e instanceof i?new P(e.message):e}}var P=class extends Error{name=`TransformError`},He=class{current;steps=[];docs=[];mapping=new ke;constructor(e){this.current=e}get doc(){return this.current}get before(){return this.docs[0]??this.doc}get docChanged(){return this.steps.length>0}step(e){let t=this.maybeStep(e);if(t.failed!==null)throw new P(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.doc&&this.addStep(e,t.doc),t}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.current=t}replace(e,t=e,n=w.empty){return e===t&&!n.size?this:this.step(new je(e,t,n))}delete(e,t){return this.replace(e,t)}insert(e,t){return this.replace(e,e,new w(f.from(t),0,0))}insertText(e,t,n=t,r){if(!e)return this.delete(t,n);let i=this.doc.type.schema.text(e,r);return this.replace(t,n,new w(f.from(i),0,0))}addMark(e,t,n){let r=[],i=[];this.doc.nodesBetween(e,t,(a,o,s)=>{if(!a.isInline||!s||!s.type.allowsMarkType(n.type))return;let c=n.addToSet(a.marks);if(c===a.marks)return;let l=Math.max(o,e),u=Math.min(o+a.nodeSize,t);for(let e of a.marks){if(e.isInSet(c))continue;let t=r[r.length-1];t&&t.to===l&&t.mark.eq(e)?t.to=u:r.push({from:l,to:u,mark:e})}let d=i[i.length-1];d&&d.to===l?d.to=u:i.push({from:l,to:u})});for(let e of r)this.step(new Le(e.from,e.to,e.mark));for(let e of i)this.step(new Ie(e.from,e.to,n));return this}removeMark(e,t,n){let r=[],i=0;this.doc.nodesBetween(e,t,(a,o)=>{if(!a.isInline)return;i++;let s=n instanceof ie?a.marks.filter(e=>e.type===n):n.isInSet(a.marks)?[n]:[],c=Math.min(o+a.nodeSize,t);for(let t of s){let n=r.find(e=>e.index===i-1&&e.mark.eq(t));n?(n.to=c,n.index=i):r.push({from:Math.max(o,e),to:c,mark:t,index:i})}});for(let e of r)this.step(new Le(e.from,e.to,e.mark));return this}split(e,t=1,n){let r=this.doc.resolve(e);if(t<1||t>r.depth)throw new P(`Cannot split ${t} levels at ${e}`);let a=f.empty,o=f.empty;for(let e=r.depth,s=t-1;e>r.depth-t;e--,s--){a=f.from(r.node(e).copy(a));let t=n?.[s],c;try{c=t?t.type.createOpen(t.attrs,o):r.node(e).copy(o)}catch(e){throw e instanceof i?new P(e.message):e}o=f.from(c)}return this.step(new je(e,e,new w(a.append(o),t,t),!0))}join(e,t=1){let n=e>0&&e<this.doc.content.size?this.doc.resolve(e):null,r=n?.nodeBefore,i=n?.nodeAfter;if(!r||!i||r.isLeaf||i.isLeaf||n?.textOffset)throw new P(`Position ${e} is not between two joinable nodes`);return this.step(new je(e-t,e+t,w.empty,!0))}wrap(e,t){let n=f.empty;for(let e=t.length-1;e>=0;e--){let r=t[e];if(n.size&&!r.type.contentMatch.matchFragment(n)?.validEnd)throw new P(`${r.type.name} cannot hold the next wrapper`);n=f.from(r.type.createOpen(r.attrs,n))}let{start:r,end:i}=e;return this.step(new Me(r,i,r,i,new w(n,0,0),t.length,!0))}lift(e,t){let{$from:n,$to:r,depth:i}=e,a=n.before(i+1),o=r.after(i+1),s=a,c=o,l=f.empty,u=0;for(let e=i,r=!1;e>t;e--)r||n.index(e)>0?(r=!0,l=f.from(n.node(e).copy(l)),u++):s--;let d=f.empty,p=0;for(let e=i,n=!1;e>t;e--)n||r.after(e+1)<r.end(e)?(n=!0,d=f.from(r.node(e).copy(d)),p++):c++;return this.step(new Me(s,c,a,o,new w(l.append(d),u,p),l.size-u,!0))}setBlockType(e,t,n,r=null){let i=[];return this.doc.nodesBetween(e,t,(e,t)=>{if(!e.isTextblock)return;let a=Ve(e,n,r);return e.type===n&&u(e.attrs,a)||i.push(new Re(t,n,a)),!1}),i.length?this.step(new Be(i)):this}setBlockAttrs(e,t,n){let r=[];return this.doc.nodesBetween(e,t,(e,t)=>{if(!e.isTextblock)return;let i=e.type.spec.attrs??{},a=Object.fromEntries(Object.entries(n).filter(([e])=>e in i));if(!Object.keys(a).length)return!1;let o={...e.attrs,...a};return u(e.attrs,o)||r.push(new Re(t,e.type,o)),!1}),r.length?this.step(new Be(r)):this}setNodeMarkup(e,t,n=null,r){return this.step(new Re(e,t,n,r))}};function F(e,t,n){let r=e.tr;try{n(r)}catch(e){if(e instanceof P)return!1;throw e}return!r.docChanged&&r.selection.eq(e.selection)&&r.storedMarks===e.storedMarks?!1:(t?.(r),!0)}var I=class e{$anchor;$head;constructor(e,t){this.$anchor=e,this.$head=t}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get $from(){return this.anchor<=this.head?this.$anchor:this.$head}get $to(){return this.anchor<=this.head?this.$head:this.$anchor}get from(){return this.$from.pos}get to(){return this.$to.pos}get empty(){return this.from===this.to}get ranges(){return[{from:this.from,to:this.to}]}eq(e){return e.constructor===this.constructor&&e.anchor===this.anchor&&e.head===this.head}static near(e,t=1){if(e.parent.inlineContent)return new L(e,e);let n=e.doc,r=Ue(n,e.pos,t)??Ue(n,e.pos,-t);return r===null?new Ke(n):L.create(n,r)}static atStart(t){return e.near(t.resolve(0),1)}static atEnd(t){return e.near(t.resolve(t.content.size),-1)}static kinds=new Map;static fromJSON(t,n){if(n.type===`all`)return new Ke(t);let r=e.kinds.get(n.type);if(r)return r(t,n);let i=e=>Math.max(0,Math.min(e,t.content.size));if(n.type===`node`){let r=t.resolve(i(n.anchor)),a=r.nodeAfter;return a&&!r.textOffset&&Ge.isSelectable(a)?new Ge(r):e.near(r)}return L.between(t.resolve(i(n.anchor)),t.resolve(i(n.head)))}};function Ue(e,t,n){let r=null;return e.descendants((e,i)=>{if(!e.isTextblock)return!0;let a=i+1,o=a+e.content.size;return n>0&&a>=t&&r===null&&(r=a),n<0&&o<=t&&(r=o),!1}),r}function We(e){if(!e.textOffset)return e;let t=e.parent.child(e.index()).text??``,n=t.charCodeAt(e.textOffset-1),r=t.charCodeAt(e.textOffset);return n>=55296&&n<=56319&&r>=56320&&r<=57343?e.doc.resolve(e.pos-1):e}var L=class e extends I{static create(t,n,r=n){return e.between(t.resolve(n),t.resolve(r))}static between(t,n){let r=n.pos>=t.pos?1:-1,i=n.parent.inlineContent?n:I.near(n,r).$head,a=t.parent.inlineContent?t:I.near(t,-r).$head;return!i.parent.inlineContent||!a.parent.inlineContent?I.near(n,r):new e(We(a),We(i))}map(t,n){let r=t.resolve(n.map(this.head));if(!r.parent.inlineContent)return I.near(r);let i=t.resolve(n.map(this.anchor));return new e(i.parent.inlineContent?i:r,r)}toJSON(){return{type:`text`,anchor:this.anchor,head:this.head}}},Ge=class e extends I{node;constructor(t){let n=t.nodeAfter;if(!n||t.textOffset||!e.isSelectable(n))throw RangeError(`No selectable node at position ${t.pos}`);super(t,t.doc.resolve(t.pos+n.nodeSize)),this.node=n}static create(t,n){return new e(t.resolve(n))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}map(t,n){let r=n.mapResult(this.anchor,1),i=n.mapResult(this.head,-1),a=t.resolve(r.pos),o=a.nodeAfter;return r.deleted||i.deleted||!o||a.textOffset||r.pos+o.nodeSize!==i.pos?I.near(a):e.isSelectable(o)?new e(a):I.near(a)}toJSON(){return{type:`node`,anchor:this.anchor,head:this.head}}},Ke=class e extends I{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}map(t){return new e(t)}toJSON(){return{type:`all`,anchor:this.anchor,head:this.head}}};function qe(e){if(!e.parent.inlineContent)return d.none;if(e.textOffset)return e.parent.child(e.index()).marks;let t=e.nodeBefore,n=e.nodeAfter,r=t??n,i=t?n:null,a=r?.marks??d.none;for(let e of a)!e.type.inclusive&&!(i&&e.isInSet(i.marks))&&(a=e.removeFromSet(a));return a}var Je=[`section`,`revision`,`formatChange`,`attributes`],Ye=new Set([`bookmarkStart`,`bookmarkEnd`,`commentStart`,`commentEnd`,`controlStart`,`controlEnd`]);function Xe(e,t,n,r=0){let i=e.doc.nodeAt(t);if(!i?.isTextblock||!Object.hasOwn(i.attrs,`revision`))return;let a=!1;if(i.content.cut(0,i.content.size-(n.content.size-r)).forEach(e=>{Ye.has(e.type.name)||(a=!0)}),!a){(i.type!==n.type||JSON.stringify(i.attrs)!==JSON.stringify(n.attrs))&&e.setNodeMarkup(t,n.type,n.attrs);return}let o={...i.attrs},s=!1;for(let e of Je){let t=n.attrs[e]??null;JSON.stringify(o[e]??null)!==JSON.stringify(t)&&(o[e]=t,s=!0)}s&&e.setNodeMarkup(t,i.type,o)}var Ze=new Set([`insertion`,`deletion`,`formatChange`]);function Qe(e){return e.some(e=>Ze.has(e.type.name))?e.filter(e=>!Ze.has(e.type.name)):e}var $e=class{name;constructor(e){this.name=e}getState(e){return e.pluginState(this)}},et=class{spec;key;constructor(e){this.spec=e,this.key=e.key??new $e(`plugin`)}},tt=class extends He{time=Date.now();storedMarks;currentSelection;selectionStep=0;storedMarksSet=!1;meta=new Map;constructor(e){super(e.doc),this.currentSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.selectionStep<this.steps.length&&(this.currentSelection=this.currentSelection.map(this.doc,this.mapping.slice(this.selectionStep)),this.selectionStep=this.steps.length),this.currentSelection}setSelection(e){if(e.$anchor.doc!==this.doc)throw RangeError(`Selection is not in this document`);return this.currentSelection=e,this.selectionStep=this.steps.length,this}setStoredMarks(e){return this.storedMarks=e,this.storedMarksSet=!0,this}addStep(e,t){super.addStep(e,t),this.storedMarksSet||(this.storedMarks=null)}setMeta(e,t){return this.meta.set(e,t),this}getMeta(e){return this.meta.get(e)}copyMeta(e){for(let[t,n]of e.meta)this.meta.set(t,n);return this.time=e.time,this}get addToHistory(){return this.meta.get(`addToHistory`)!==!1}deleteSelection(){let e=this.selection;if(e.empty)return this;if(e instanceof Ke){let e=nt(this.doc.type.schema),t=this.doc.childCount===1?this.doc.firstChild:null;return(t?.type!==e||t.content.size!==0)&&this.replace(0,this.doc.content.size,new w(f.from(e.create()),0,0)),this.setSelection(I.atStart(this.doc))}let t=this.steps.length,{$from:n}=e,r=n.index();if(e instanceof Ge&&!n.parent.canReplace(r,r+1)){let t=n.parent.contentMatchAt(r).defaultType;if(!t?.isTextblock)throw new P(`The selected node cannot be deleted`);return this.replace(e.from,e.to,new w(f.from(t.create()),0,0)),this.setSelection(L.create(this.doc,e.from+1))}let{$to:i}=e,a=n.depth>0&&n.parent!==i.parent&&n.parent.isTextblock&&i.parent.isTextblock?i.parent:null;this.delete(e.from,e.to),a&&Xe(this,n.before(),a,i.parentOffset);let o=this.mapping.slice(t).map(e.from,-1);return this.setSelection(L.create(this.doc,o))}replaceSelection(e){this.deleteSelection();let t=this.selection.from,n=this.steps.length;this.replace(t,t,e);let r=this.mapping.slice(n).map(t,1);return this.setSelection(I.near(this.doc.resolve(r),-1))}};function nt(e){let t=Object.values(e.nodes).find(e=>e.isTextblock);if(!t)throw RangeError(`Schema has no textblock type`);return t}var rt=class e{doc;selection;storedMarks;plugins;fields;constructor(e,t,n,r,i){this.doc=e,this.selection=t,this.storedMarks=n,this.plugins=r,this.fields=i}static create(t){let n=new e(t.doc,t.selection??I.atStart(t.doc),t.storedMarks??null,t.plugins??[],new Map);for(let e of n.plugins)e.spec.state&&n.fields.set(e,e.spec.state.init(n));return n}get schema(){return this.doc.type.schema}get tr(){return new tt(this)}pluginState(e){let t=this.plugins.find(t=>t.key===e);return t?this.fields.get(t):void 0}apply(e){return this.applyTransaction(e).state}withDocument(t,n){return new e(t,n,null,this.plugins,new Map(this.fields))}applyTransaction(e){if(!this.passesFilters(e))return{state:this,transactions:[]};let t=[e],n=this.applyInner(e),r=[];for(let i=0;;i++){if(i>100)throw RangeError(`appendTransaction did not settle after 100 rounds`);let a=!1;if(this.plugins.forEach((i,o)=>{let s=i.spec.appendTransaction;if(!s)return;let c=r[o]??{state:this,count:0},l=c.count<t.length?s(t.slice(c.count),c.state,n):null;l&&n.passesFilters(l,o)&&(l.setMeta(`appendedTransaction`,e),t.push(l),n=n.applyInner(l),a=!0),r[o]={state:n,count:t.length}}),!a)return{state:n,transactions:t}}}passesFilters(e,t=-1){return this.plugins.every((n,r)=>r===t||n.spec.filterTransaction?.(e,this)!==!1)}applyInner(t){if(t.before!==this.doc)throw RangeError(`Transaction was not created from this state`);let n=new e(t.doc,t.selection,t.storedMarks,this.plugins,new Map);for(let e of this.plugins){let r=e.spec.state;r&&n.fields.set(e,r.apply(t,this.fields.get(e),this,n))}return n}};function R(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var z=e=>typeof e==`boolean`?void 0:`must be true or false`,B=(e,t)=>n=>Number.isInteger(n)&&n>=e&&n<=t?void 0:`must be an integer from ${e} to ${t}`,V=(e=255)=>t=>typeof t==`string`&&t.length<=e?void 0:`must be a string of at most ${e} characters`,H=(e=255)=>t=>typeof t==`string`&&t.length>0&&t.length<=e?void 0:`must be a non-empty string of at most ${e} characters`,U=e=>t=>e.includes(t)?void 0:`must be one of ${e.join(`, `)}`,it=e=>typeof e==`string`&&/^[A-Za-z][A-Za-z0-9-]{0,63}$/.test(e)?void 0:`must be a Word token`,at=e=>typeof e==`string`&&/^([0-9A-Fa-f]{6}|auto)$/.test(e)?void 0:`must be RRGGBB or auto`,ot=e=>typeof e==`string`&&/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})?$/.test(e)?void 0:`must be an ISO 8601 date-time`,W=e=>typeof e==`string`&&e.length>0&&e.length<=16777216?void 0:`must be an XML string`,st=e=>{if(!R(e))return`must be an object`;let t=Object.entries(e);if(t.length===0)return`must not be empty (use null)`;if(t.length>64)return`must have at most 64 attributes`;for(let[e,n]of t){if(!/^[A-Za-z_][\w.-]*(:[A-Za-z_][\w.-]*)?$/.test(e))return`${e} is not an attribute name`;if(typeof n!=`string`||n.length>65535)return`${e} must be a string`}},G=e=>t=>t===null?void 0:e(t),ct=(e,t=1e5)=>n=>{if(!Array.isArray(n))return`must be an array`;if(n.length>t)return`must have at most ${t} items`;for(let t=0;t<n.length;t++){let r=e(n[t]);if(r)return`[${t}] ${r}`}},K=(e,t=[],n=!1)=>r=>{if(!R(r))return`must be an object`;let i=Object.keys(r);if(i.length===0&&!n)return`must not be empty (use null)`;for(let t of i){if(!Object.hasOwn(e,t))return`unknown key ${t}`;let n=e[t](r[t]);if(n)return`${t} ${n}`}for(let e of t)if(!Object.hasOwn(r,e))return`${e} is required`},lt=31680,ut=B(-31680,lt),dt=B(0,lt),ft=B(-31680,lt),pt=[`left`,`center`,`right`,`both`,`start`,`end`,`distribute`,`mediumKashida`,`highKashida`,`lowKashida`,`thaiDistribute`,`numTab`],mt=[`auto`,`exact`,`atLeast`],ht=[`left`,`center`,`right`,`decimal`,`bar`,`clear`,`num`,`start`,`end`],gt=[`none`,`dot`,`hyphen`,`underscore`,`heavy`,`middleDot`],_t=[`nextPage`,`continuous`,`evenPage`,`oddPage`,`nextColumn`],vt=[`baseline`,`superscript`,`subscript`],yt=[`black`,`blue`,`cyan`,`green`,`magenta`,`red`,`yellow`,`white`,`darkBlue`,`darkCyan`,`darkGreen`,`darkMagenta`,`darkRed`,`darkYellow`,`darkGray`,`lightGray`,`none`],bt=[`majorAscii`,`majorHAnsi`,`majorEastAsia`,`majorBidi`,`minorAscii`,`minorHAnsi`,`minorEastAsia`,`minorBidi`],xt=K({style:it,size:B(0,96),space:B(0,31),color:at,themeColor:it},[`style`]),St=K({pattern:it,color:at,fill:at,themeFill:it},[`pattern`]),q=e=>({default:null,validate:G(e)}),Ct=B(0,2147483647),wt={id:Ct,author:V(),date:G(ot)},Tt=K(wt,[`id`,`author`]),Et=K({position:U([`pageBottom`,`beneathText`,`sectEnd`,`docEnd`]),format:it,start:Ct,restart:U([`continuous`,`eachSect`,`eachPage`])}),Dt=45,Ot=e=>kt(e),kt=K({pageSize:K({width:B(1,lt),height:B(1,lt),orientation:U([`portrait`,`landscape`])}),margins:K({top:ut,right:dt,bottom:ut,left:dt,header:dt,footer:dt,gutter:dt}),type:U(_t),titlePage:z,headers:K({default:H(),first:H(),even:H()}),footers:K({default:H(),first:H(),even:H()}),columns:K({count:B(1,Dt),space:dt,equalWidth:z,separator:z,widths:ct(K({width:dt,space:dt},[`width`]),Dt)}),pageNumbers:K({start:Ct,format:it}),footnotes:Et,endnotes:Et,change:K({...wt,previous:Ot},[`id`,`author`,`previous`]),ext:W},[],!0),At=K({value:ut,type:U([`auto`,`dxa`,`pct`,`nil`])},[`value`,`type`]),jt=(e,t=[])=>K(Object.fromEntries([`top`,`left`,`bottom`,`right`,`start`,`end`,...t].map(t=>[t,e]))),Mt=1e3,Nt={style:q(H()),width:q(At),justification:q(U([`left`,`center`,`right`,`start`,`end`])),indent:q(At),layout:q(U([`fixed`,`autofit`])),borders:q(jt(xt,[`insideH`,`insideV`])),cellMargins:q(jt(At)),cellSpacing:q(At),shading:q(St),look:q(K({firstRow:z,lastRow:z,firstColumn:z,lastColumn:z,noHBand:z,noVBand:z})),rowBandSize:q(B(1,Mt)),columnBandSize:q(B(1,Mt)),ext:q(W)},Pt={height:q(K({value:dt,rule:U([`auto`,`exact`,`atLeast`])},[`value`])),cantSplit:q(z),header:q(z),gridBefore:q(B(1,Mt)),widthBefore:q(At),gridAfter:q(B(1,Mt)),widthAfter:q(At),ext:q(W)},Ft={width:q(At),gridSpan:q(B(1,Mt)),vMerge:q(U([`restart`,`continue`])),borders:q(jt(xt,[`insideH`,`insideV`,`tl2br`,`tr2bl`])),shading:q(St),margins:q(jt(At)),verticalAlign:q(U([`top`,`center`,`bottom`,`both`])),textDirection:q(it),noWrap:q(z),ext:q(W)},It=e=>t=>{if(!R(t))return`must be an object`;for(let[n,r]of Object.entries(t)){if(!Object.hasOwn(e,n))return`unknown key ${n}`;let t=r===null?`must not be null (leave it out)`:e[n].validate?.(r);if(t)return`${n} ${t}`}},Lt=It(Nt),Rt=It(Pt),zt=It(Ft),Bt=B(0,2147483647),Vt=B(-2147483648,2147483647),Ht=K({horizontal:K({relativeTo:it,offset:Vt,align:it},[`relativeTo`]),vertical:K({relativeTo:it,offset:Vt,align:it},[`relativeTo`]),wrap:U([`square`,`tight`,`through`,`topAndBottom`,`behind`,`inFront`]),side:U([`bothSides`,`left`,`right`,`largest`]),distance:K({top:Bt,bottom:Bt,left:Bt,right:Bt}),allowOverlap:z,layoutInCell:z},[`horizontal`,`vertical`,`wrap`]),Ut=[`characterStyle`,`bold`,`italic`,`underline`,`strike`,`doubleStrike`,`caps`,`smallCaps`,`hidden`,`font`,`fontSize`,`color`,`highlight`,`shading`,`verticalAlign`,`characterSpacing`],Wt=e=>{if(!Array.isArray(e))return`must be an array of marks`;for(let t of e)if(!R(t)||!Ut.includes(t.type))return`${R(t)?String(t.type):`a non-object`} is not a run property`;try{ln.nodeFromJSON({type:`text`,text:`x`,marks:e});return}catch(e){return e.message}},Gt={style:q(H()),justification:q(U(pt)),indent:q(K({left:ut,right:ut,firstLine:dt,hanging:dt})),spacing:q(K({before:dt,after:dt,line:ft,lineRule:U(mt),beforeAutospacing:z,afterAutospacing:z})),keepNext:q(z),keepLines:q(z),widowControl:q(z),pageBreakBefore:q(z),contextualSpacing:q(z),outlineLevel:q(B(0,9)),numbering:q(K({id:Ct,level:B(0,8)})),tabs:q(ct(K({position:ut,kind:U(ht),leader:U(gt)},[`position`,`kind`]),64)),borders:q(K({top:xt,bottom:xt,left:xt,right:xt,between:xt,bar:xt})),shading:q(St),markFormat:q(Wt),ext:q(W)},Kt=Object.keys(Gt),qt=e=>{if(!R(e))return`must be an object`;for(let[t,n]of Object.entries(e)){if(!Object.hasOwn(Gt,t))return`unknown key ${t}`;let e=n===null?`must not be null (leave it out)`:Gt[t].validate?.(n);if(e)return`${t} ${e}`}},J=(e,t)=>t===void 0?{validate:e}:{default:t,validate:e},Jt={attrs:{value:J(z,!0)}},Yt={attrs:{value:J(G(z),!0),complexScript:J(G(z),null)}},Xt={attrs:{id:J(Ct),author:J(V()),date:J(G(ot),null),move:J(G(H()),null),attributes:J(G(st),null)},inclusive:!1},Zt={attributes:q(st)},Qt={controls:q(e=>{let t=ct(H(),64)(e);if(t)return t;let n=e;return n.length?new Set(n).size===n.length?void 0:`must not repeat an id`:`must not be empty (use null)`})},$t={group:`inline`,inline:!0,selectable:!1},en=J(G(H()),null),tn=J(G(U(bt)),null),nn=e=>typeof e==`string`&&/^[0-9A-Fa-f]{2}$/.test(e)?void 0:`must be a hex byte`,rn=/^[a-z0-9-]+:[a-z0-9-]+$/,an=65536;function on(e,t=0){return t>32?!1:e===null||typeof e==`string`||typeof e==`boolean`?!0:typeof e==`number`?Number.isFinite(e):Array.isArray(e)?e.every(e=>on(e,t+1)):R(e)&&Object.getPrototypeOf(e)===Object.prototype&&Object.values(e).every(e=>on(e,t+1))}var sn={type:{validate:e=>typeof e==`string`&&rn.test(e)?void 0:`must be a namespaced type`},attrs:q(e=>!R(e)||!on(e)?`must be a plain JSON object`:JSON.stringify(e).length<=an?void 0:`must be at most ${an} characters as JSON`)},cn={attrs:{...sn,text:q(V(65535))},text:e=>typeof e.text==`string`?e.text:`[${String(e.type)}]`},ln=new ae({nodes:{doc:{content:`block+`},paragraph:{group:`block`,content:`inline*`,attrs:{...Gt,...Qt,section:q(Ot),revision:q(K({insertion:Tt,deletion:Tt})),formatChange:q(K({...wt,previous:qt},[`id`,`author`,`previous`])),attributes:q(st)}},table:{group:`block`,content:`tableRow+`,attrs:{...Nt,...Qt,grid:{default:[],validate:ct(dt,Mt)},gridExt:q(W)}},tableRow:{content:`tableCell+`,attrs:{...Pt,...Qt,revision:q(K({insertion:Tt,deletion:Tt})),exceptions:q(Lt),attributes:q(st)}},tableCell:{content:`block* paragraph`,attrs:{...Ft,...Qt}},opaqueBlock:{group:`block`,attrs:{xml:{validate:W},label:q(H()),...Qt}},text:{group:`inline`},tab:{group:`inline`,inline:!0},hardBreak:{group:`inline`,inline:!0,selectable:!1,attrs:{clear:q(U([`none`,`left`,`right`,`all`]))}},pageBreak:{group:`inline`,inline:!0,selectable:!1},columnBreak:{group:`inline`,inline:!0,selectable:!1},bookmarkStart:{group:`inline`,inline:!0,selectable:!1,attrs:{id:{validate:Ct},name:{validate:V()},...Zt}},bookmarkEnd:{group:`inline`,inline:!0,selectable:!1,attrs:{id:{validate:Ct},...Zt}},commentStart:{group:`inline`,inline:!0,selectable:!1,attrs:{id:{validate:Ct},...Zt}},commentEnd:{group:`inline`,inline:!0,selectable:!1,attrs:{id:{validate:Ct},...Zt}},commentReference:{group:`inline`,inline:!0,attrs:{id:{validate:Ct},...Zt}},fieldStart:{...$t,attrs:{dirty:q(z),locked:q(z),simple:q(z),ext:q(W)}},fieldCode:{...$t,attrs:{text:{validate:V(65535)},...Zt}},fieldSeparator:{...$t,attrs:{ext:q(W)}},fieldEnd:{...$t,attrs:{ext:q(W)}},controlStart:{group:`inline`,inline:!0,selectable:!1,attrs:{id:{validate:H()}}},controlEnd:{group:`inline`,inline:!0,selectable:!1,attrs:{id:{validate:H()}}},noteReference:{group:`inline`,inline:!0,attrs:{story:{validate:H()},customMark:q(z),...Zt}},noteMark:{group:`inline`,inline:!0,selectable:!1},picture:{group:`inline`,inline:!0,attrs:{resource:{validate:H()},width:{validate:Bt},height:{validate:Bt},alt:q(V(65535)),title:q(V(65535)),decorative:q(z),float:q(Ht),ext:q(W)}},opaqueInline:{group:`inline`,inline:!0,attrs:{xml:{validate:W},label:q(H()),run:{default:!1,validate:z}}},foreignInline:{group:`inline`,inline:!0,...cn},foreignBlock:{group:`block`,...cn}},marks:{link:{attrs:{href:J(G(H(8192)),null),anchor:J(G(H()),null),tooltip:J(G(V(1024)),null),attributes:J(G(st),null)},inclusive:!1},insertion:Xt,deletion:Xt,characterStyle:{attrs:{id:J(H())}},bold:Yt,italic:Yt,underline:{attrs:{style:J(it,`single`),color:J(G(at),null)}},strike:Jt,doubleStrike:Jt,caps:Jt,smallCaps:Jt,hidden:Jt,font:{attrs:{ascii:en,hAnsi:en,eastAsia:en,cs:en,asciiTheme:tn,hAnsiTheme:tn,eastAsiaTheme:tn,csTheme:tn,hint:J(G(U([`default`,`eastAsia`,`cs`])),null)}},fontSize:{attrs:{value:J(G(B(1,3276)),null),complexScript:J(G(B(1,3276)),null)}},color:{attrs:{value:J(at),themeColor:J(G(it),null),themeTint:J(G(nn),null),themeShade:J(G(nn),null)}},highlight:{attrs:{value:J(U(yt))}},shading:{attrs:{pattern:J(it),color:J(at,`auto`),fill:J(at,`auto`)}},verticalAlign:{attrs:{value:J(U(vt))}},characterSpacing:{attrs:{value:J(ut)}},formatChange:{attrs:{id:J(Ct),author:J(V()),date:J(G(ot),null),previous:J(Wt)}},runExt:{attrs:{xml:J(W)}},foreign:{attrs:sn,excludes:``,inclusive:!1}}}),un=new WeakMap;function dn(e){if(!e?.length)return ln;let t=un.get(e);if(t)return t;let n={...ln.spec.nodes},r={...ln.spec.marks},i=(e,t,i)=>{if(!rn.test(t))throw RangeError(`${i}: ${t} is not a namespaced type (<namespace>:<name>)`);if(Object.hasOwn(n,t)||Object.hasOwn(r,t))throw RangeError(`${i}: ${t} is declared twice`);return e};for(let t of e){for(let[e,r]of Object.entries(t.nodes??{})){let a=r.inline?`inline`:`block`;if(r.content||r.group!==void 0&&r.group!==a)throw RangeError(`${t.name}: ${e} must be a leaf in the ${a} group`);if(typeof r.text!=`function`)throw RangeError(`${t.name}: ${e} needs text(attrs)`);i(n,e,t.name)[e]={...r,group:a}}for(let[e,n]of Object.entries(t.marks??{}))i(r,e,t.name)[e]=n}let a=new ae({nodes:n,marks:r});return un.set(e,a),a}var fn=Symbol.for(`foli.foreignText`),pn=e=>e[fn];function mn(e,t){return Object.defineProperty(e,fn,{value:t,configurable:!0}),e}var hn=new Set([`foreignInline`,`foreignBlock`]),gn=302;function _n(e,t){if(!Array.isArray(e))return e;let n;return e.forEach((r,i)=>{let a=r;if(R(r)&&typeof r.type==`string`){let e=R(r.attrs)?r.attrs:void 0;rn.test(r.type)&&!t.marks[r.type]?a={type:`foreign`,attrs:{type:r.type,attrs:r.attrs??null}}:r.type===`foreign`&&typeof e?.type==`string`&&rn.test(e.type)&&t.marks[e.type]&&(a={type:e.type,...R(e.attrs)?{attrs:e.attrs}:{}})}a!==r&&(n??=e.slice(),n[i]=a)}),n??e}function vn(e,t,n=!1,r=0){if(!R(e)||r>gn)return e;let i=e.type,a=_n(e.marks,t);if(typeof i==`string`&&rn.test(i)&&!t.nodes[i]){let t=pn(e);return{type:n?`foreignInline`:`foreignBlock`,attrs:{type:i,attrs:e.attrs??null,...t===void 0?{}:{text:t}},...a===void 0?{}:{marks:a}}}if(typeof i==`string`&&hn.has(i)&&R(e.attrs)){let n=e.attrs.type;if(typeof n==`string`&&rn.test(n)&&t.nodes[n]){let t=e.attrs.attrs;return{type:n,...R(t)?{attrs:t}:{},...a===void 0?{}:{marks:a}}}}let o=e.content;if(Array.isArray(o)){let e=o,n=typeof i==`string`?t.nodes[i]:void 0,a=n?n.inlineContent:!1,s;e.forEach((n,i)=>{let o=vn(n,t,a,r+1);o!==n&&(s??=e.slice(),s[i]=o)}),o=s??e}return o===e.content&&a===e.marks?e:{...e,content:o,marks:a}}var yn=e=>e.type===`foreign`&&e.attrs?{type:String(e.attrs.type),...R(e.attrs.attrs)?{attrs:e.attrs.attrs}:{}}:e;function bn(e){if(e.marks?.some(e=>e.type===`foreign`)&&(e.marks=e.marks.map(yn)),hn.has(e.type)&&e.attrs){let{type:t,attrs:n,text:r}=e.attrs,i={type:t,...R(n)?{attrs:n}:{}};return e.marks&&(i.marks=e.marks),typeof r==`string`?mn(i,r):i}return e.content&&=e.content.map(bn),e}var xn=1440;function Sn(e){return Math.round(e*xn/25.4)}function Cn(e){return e*25.4/xn}function wn(e){let t=[],n=kn(e.content.content,{instances:t});return{schemaVersion:3,section:On(e.settings),defaults:{paragraph:{spacing:{after:220,line:360,lineRule:`auto`}},run:[{type:`font`,attrs:{ascii:`Georgia`,hAnsi:`Georgia`,cs:`Georgia`}},{type:`fontSize`,attrs:{value:22,complexScript:22}}]},styles:structuredClone(Fn),numbering:{abstracts:structuredClone([Ln,Rn]),instances:t},comments:[],content:{type:`doc`,content:n}}}var Tn=720,En=360;function Dn(e){return Math.min(Sn(e),31680)}function On(e){let{width:t,height:n}=e.pageSize,{top:r,right:i,bottom:a,left:o}=e.margins;return{pageSize:{width:Math.max(Dn(t),1),height:Math.max(Dn(n),1),...t>n?{orientation:`landscape`}:{}},margins:{top:Dn(r),right:Dn(i),bottom:Dn(a),left:Dn(o)}}}function kn(e,t){let n=[];for(let r of e)r.type===`bulletList`||r.type===`orderedList`?An(r,0,void 0,t,n):n.push(jn(r,{}));return n}function An(e,t,n,r,i){let a=Math.min(t,8),o=e.type===`bulletList`?`bullet`:`number`,s=e.type===`orderedList`?e.attrs?.start??1:1,c=n!==void 0&&n.kind===o&&s===1&&t<=8&&!n.item.continued,l;c&&(l=n.id,n.item.continued=!0),l===void 0&&(l=r.instances.length+1,r.instances.push({id:l,abstract:o===`bullet`?Ln.id:Rn.id,...o===`number`?{overrides:[{level:a,start:s}]}:{}}));for(let n of e.content){let[e,...s]=n.content,c={continued:!1};i.push(jn(e,{style:`ListParagraph`,numbering:{id:l,level:a}}));for(let e of s)if(e.type===`bulletList`||e.type===`orderedList`)An(e,t+1,{id:l,kind:o,item:c},r,i);else{let t=e.type===`paragraph`||e.type===`horizontalRule`?{style:`ListParagraph`}:{};i.push(jn(e,{...t,indent:{left:Tn*(a+1)}}))}}}function jn(e,t){if(e.type===`horizontalRule`)return{type:`paragraph`,attrs:{...t,borders:{bottom:{style:`single`,size:6,space:1,color:`auto`}}}};let n={...t};e.type===`heading`&&(n.style=`Heading${e.attrs.level}`);let r=e.attrs?.align;return r&&r!==`start`&&(n.justification=Mn[r]),{type:`paragraph`,...Object.keys(n).length?{attrs:n}:{},...e.content?.length?{content:e.content.map(Nn)}:{}}}var Mn={center:`center`,end:`right`,justify:`both`};function Nn(e){let t=e.marks?.flatMap(e=>e.type===`link`?[Pn(e),{type:`characterStyle`,attrs:{id:`Hyperlink`}}]:[Pn(e)]);return{...e,...t?.length?{marks:t}:{}}}function Pn(e){switch(e.type){case`link`:return{type:`link`,attrs:{href:e.attrs.href}};case`textColor`:return{type:`color`,attrs:{value:e.attrs.color.slice(1).toUpperCase()}};case`highlight`:return{type:`shading`,attrs:{pattern:`clear`,fill:e.attrs.color.slice(1).toUpperCase()}};default:return{type:e.type}}}var Fn=[{id:`Normal`,type:`paragraph`,name:`Normal`,isDefault:!0},...[32,28,26,24,22,22].map((e,t)=>({id:`Heading${t+1}`,type:`paragraph`,name:`heading ${t+1}`,basedOn:`Normal`,next:`Normal`,paragraph:{keepNext:!0,keepLines:!0,outlineLevel:t,spacing:{before:240,after:120}},run:[{type:`bold`},{type:`fontSize`,attrs:{value:e}}]})),{id:`ListParagraph`,type:`paragraph`,name:`List Paragraph`,basedOn:`Normal`,paragraph:{indent:{left:Tn},contextualSpacing:!0}},{id:`DefaultParagraphFont`,type:`character`,name:`Default Paragraph Font`,isDefault:!0},{id:`Hyperlink`,type:`character`,name:`Hyperlink`,basedOn:`DefaultParagraphFont`,run:[{type:`color`,attrs:{value:`0563C1`,themeColor:`hyperlink`}},{type:`underline`}]}];function In(e){return Array.from({length:9},(t,n)=>({level:n,start:1,format:e===`bullet`?`bullet`:`decimal`,text:e===`bullet`?[`•`,`◦`,`▪`][n%3]:`%${n+1}.`,justification:`left`,paragraph:{indent:{left:Tn*(n+1),hanging:En}}}))}var Ln={id:0,multiLevelType:`hybridMultilevel`,levels:In(`bullet`)},Rn={id:1,multiLevelType:`hybridMultilevel`,levels:In(`number`)},zn=[`wholeTable`,`band1Vert`,`band2Vert`,`band1Horz`,`band2Horz`,`firstCol`,`lastCol`,`firstRow`,`lastRow`,`nwCell`,`neCell`,`swCell`,`seCell`];function Bn(e){return{...e,schemaVersion:4}}function Vn(e){return{...e,schemaVersion:5}}function Hn(e={type:`doc`,content:[{type:`paragraph`}]},t){let n=Vn(Bn(wn({schemaVersion:2,settings:_e,content:{type:`doc`,content:[]}}))),r=n.section;return{...n,section:{...t,pageSize:{...r.pageSize,...t?.pageSize},margins:{...r.margins,...t?.margins}},content:e}}function Un(e,t={}){if(!R(e))throw new i(`Document must be an object`);let n=e.schemaVersion;if(n===1||n===2)return Un(Vn(Bn(wn(ve(e)))),t);if(n===3||n===4){n===3&&Object.hasOwn(e,`resources`)&&Y(`resources`,`unknown key (schema 4 and later)`);for(let t of Zn)Object.hasOwn(e,t)&&Y(t,`unknown key (schema 5 and later)`);let r=Un({...e,schemaVersion:5},t),i=$n(r.section);i&&Y(`section`,`${i} is of schema 5 (the document says schema ${n})`);for(let[e,t]of[[`content`,r.content],...r.comments.map((e,t)=>[`comments[${t}].content`,{content:e.content}])]){let r=er(t,n);r&&Y(e,`${r.name} is a schema ${r.schema} node (the document says schema ${n})`)}return n===3&&r.styles.forEach((e,t)=>{for(let n of[`table`,`row`,`cell`,`conditions`])Object.hasOwn(e,n)&&Y(`styles[${t}]`,`unknown key ${n} (schema 4 and later)`)}),r}if(n!==5)throw new i(`Unsupported schemaVersion: ${String(n)} (this version of @folijs/core reads 1 to 5${Number.isInteger(n)&&n>5?`; the document was saved by a newer one`:``})`);for(let t of Object.keys(e))if(!tr.includes(t))throw new i(`${t}: unknown key`);nr(`section`,e.section,Ot),nr(`defaults`,e.defaults,K({paragraph:qt,run:Wt,ext:W},[],!0)),nr(`styles`,e.styles,ct(or)),nr(`numbering`,e.numbering,K({abstracts:ct(vr),instances:ct(yr)},[`abstracts`,`instances`])),e.theme!==void 0&&nr(`theme`,e.theme,xr),nr(`comments`,e.comments,ct(Sr)),e.resources!==void 0&&nr(`resources`,e.resources,fr),e.stories!==void 0&&nr(`stories`,e.stories,mr),e.controls!==void 0&&nr(`controls`,e.controls,hr),e.settings!==void 0&&nr(`settings`,e.settings,gr);let r=e.styles,a=e.comments;rr(`styles`,r,e=>e.id,e=>e.basedOn,e=>`${e.id} is based on itself`),rr(`comments`,a,e=>e.id,e=>e.parent,e=>`comment ${e.id} replies to itself`);let o=dn(t.extensions),s=Gn(e.content,{schema:o}),c=Object.entries(e.stories??{}).map(([e,t])=>{let n=`stories[${JSON.stringify(e)}].content`,r=Gn(t.content,{path:n,schema:o});return qn(r,t.kind,n),[e,{...structuredClone({...t,content:null}),content:Wn(r)}]}),l=structuredClone({section:e.section,defaults:e.defaults,styles:r,numbering:e.numbering,theme:e.theme,resources:e.resources,controls:e.controls,settings:e.settings});return{schemaVersion:5,section:l.section,defaults:l.defaults,styles:l.styles,numbering:l.numbering,...l.theme===void 0?{}:{theme:l.theme},comments:a.map((e,t)=>({...structuredClone({...e,content:[]}),content:ir(e.content,`comments[${t}].content`,o).map(e=>(e.descendants(e=>(e.type.name===`noteReference`&&Y(`comments[${t}].content`,`a comment cannot hold a note reference`),!0)),Wn(e)))})),...l.resources===void 0?{}:{resources:l.resources},...e.stories===void 0?{}:{stories:Object.fromEntries(c)},...l.controls===void 0?{}:{controls:l.controls},...l.settings===void 0?{}:{settings:l.settings},content:Wn(s)}}var Wn=e=>bn(structuredClone(e.toJSON()));function Gn(e,t={}){let{path:n=`content`,fragment:r=!1}=t,i=t.schema??dn(t.extensions),a=i.nodeFromJSON(vn(e,i),n);return a.type!==i.topNodeType&&Y(n,`root node must be of type "doc"`),a.marks.length&&Y(`${n}.marks`,`doc cannot have marks`),Kn(a,n,!1,r),a}function Kn(e,t,n,r=!1){e.forEach((i,a,o)=>{let s=`${t}.content[${o}]`;if(i.type.name===`table`){let t=e.maybeChild(o+1);t?.type.name===`table`&&JSON.stringify(t.attrs.controls)===JSON.stringify(i.attrs.controls)&&Y(s,`a table cannot follow a table (Word would merge them): a paragraph goes between`),!t&&e.type.name===`doc`&&!r&&Y(s,`a table cannot end the document: a paragraph follows it, as in Word`),i.forEach((e,t,n)=>{e.forEach((e,t,r)=>{Kn(e,`${s}.content[${n}].content[${r}]`,!0)})})}else n&&i.type.name===`paragraph`&&(i.attrs.section&&Y(`${s}.attrs.section`,`a paragraph in a table cannot end a section`),i.forEach((e,t,n)=>{(e.type.name===`pageBreak`||e.type.name===`columnBreak`)&&Y(`${s}.content[${n}]`,`a ${e.type.name} cannot be in a table`)}))})}function qn(e,t,n){e.descendants(e=>{let r=e.type.name;return e.attrs.section&&Y(n,`a story cannot end a section`),r===`noteReference`&&Y(n,`a story cannot hold a note reference`),Jn.has(r)&&Y(n,`a ${t} cannot hold comments`),t!==`footnote`&&t!==`endnote`||r!==`pageBreak`&&r!==`columnBreak`||Y(n,`a note cannot hold a ${r}`),!0})}var Jn=new Set([`commentStart`,`commentEnd`,`commentReference`]),Yn=new Set([`table`,`tableRow`,`tableCell`,`picture`]),Xn=new Set([`fieldStart`,`fieldCode`,`fieldSeparator`,`fieldEnd`,`controlStart`,`controlEnd`,`noteReference`,`noteMark`]),Zn=[`stories`,`controls`,`settings`],Qn=[`columns`,`pageNumbers`,`footnotes`,`endnotes`];function $n(e){return R(e)?Qn.find(t=>Object.hasOwn(e,t)):void 0}function er(e,t){let n=[e];for(;n.length;){let e=n.pop();if(!R(e))continue;let r=e.type;if(t<4&&Yn.has(r))return{name:r,schema:4};if(Xn.has(r))return{name:r,schema:5};let i=R(e.attrs)?e.attrs:{};if(i.controls)return{name:`controls`,schema:5};let a=$n(i.section);if(a)return{name:a,schema:5};if(Array.isArray(e.content))for(let t of e.content)n.push(t)}}var tr=[`schemaVersion`,`section`,`defaults`,`styles`,`numbering`,`theme`,`comments`,`resources`,`stories`,`controls`,`settings`,`content`];function Y(e,t){throw new i(`${e}: ${t}`)}function nr(e,t,n){let r=n(t);r&&Y(e,r)}function rr(e,t,n,r,i){let a=new Map;t.forEach((e,t)=>{a.has(n(e))||a.set(n(e),t)});let o=new Uint8Array(t.length);t.forEach((n,s)=>{let c=[],l=s;for(;l!==void 0&&o[l]===0;){o[l]=1,c.push(l);let e=r(t[l]);l=e===void 0?void 0:a.get(e)}l!==void 0&&o[l]===1&&Y(`${e}[${l}]`,i(t[l]));for(let e of c)o[e]=2})}function ir(e,t,n){let r=Gn({type:`doc`,content:e},{path:t,schema:n}),i=[];return r.forEach(e=>{i.push(e)}),i}var ar=K({type:U(zn.filter(e=>e!==`wholeTable`)),paragraph:qt,run:Wt,table:Lt,row:Rt,cell:zt,ext:W},[`type`]),or=K({id:H(),type:U([`paragraph`,`character`,`table`,`numbering`]),name:V(),basedOn:H(),next:H(),link:H(),isDefault:z,paragraph:qt,run:Wt,table:Lt,row:Rt,cell:zt,conditions:ct(ar,zn.length),ext:W},[`id`,`type`]),sr=new Set([`http:`,`https:`,`blob:`]);function cr(e){try{return new URL(e,`https://base.invalid/`).protocol}catch{return``}}var lr=/^image\/[A-Za-z0-9][\w.+-]{0,126}$/,ur=e=>{let t=K({contentType:e=>typeof e==`string`&&lr.test(e)?void 0:`must be an image media type`,size:B(0,2**53-1),part:H(1024),url:e=>H(8192)(e)??(sr.has(cr(e))?void 0:`must be relative, http(s) or blob`),data:e=>typeof e==`string`&&/^data:image\/[\w.+-]+[;,]/i.test(e)&&e.length<=67108864?void 0:`must be a data: URL of an image`},[`contentType`])(e);if(t)return t;let n=e;return n.part===void 0&&n.url===void 0&&n.data===void 0?`needs part, url or data`:void 0},dr=(e,t)=>n=>{if(!R(n))return`must be an object`;let r=Object.entries(n);if(r.length>1e5)return`must have at most 100000 ${t}s`;for(let[n,i]of r){let r=n===`__proto__`?`is not a ${t} key`:H()(n);if(r)return`${n.slice(0,64)} ${r}`;let a=e(i);if(a)return`${n} ${a}`}},fr=dr(ur,`resource`),pr=[`footnote`,`endnote`],mr=dr(e=>K({kind:U([`header`,`footer`,...pr]),noteType:U([`normal`,`separator`,`continuationSeparator`,`continuationNotice`]),content:e=>R(e)?void 0:`must be an object`,ext:W},[`kind`,`content`])(e)??(R(e)&&e.noteType!==void 0&&!pr.includes(e.kind)?`noteType is for notes`:void 0),`story`),hr=dr(K({kind:U([`text`,`richText`,`dropDown`,`comboBox`,`date`,`checkbox`,`picture`,`repeating`,`repeatingItem`,`other`]),tag:V(),alias:V(),lock:U([`sdtLocked`,`contentLocked`,`sdtContentLocked`,`unlocked`]),items:ct(K({value:V(),display:V()},[`value`])),dateFormat:V(),date:V(),checked:z,checkedState:K({value:V(),font:V()},[`value`]),uncheckedState:K({value:V(),font:V()},[`value`]),multiLine:z,format:Wt,noInsertDelete:z,deleted:z,placeholder:K({showing:z,docPart:V(),text:V(65535)},[],!0),binding:K({xpath:V(65535),storeItemId:V(),prefixMappings:V(65535)},[],!0),ext:W},[`kind`]),`control`),gr=K({doNotUseHTMLParagraphAutoSpacing:z,evenAndOddHeaders:z,footnotes:Et,endnotes:Et},[],!0),_r=K({level:B(0,8),start:B(0,2147483647),format:it,text:V(),justification:U([`left`,`center`,`right`,`start`,`end`]),restart:B(0,9),legal:z,suffix:U([`tab`,`space`,`nothing`]),style:H(),paragraph:qt,run:Wt,ext:W},[`level`]),vr=K({id:B(0,2147483647),multiLevelType:U([`singleLevel`,`multilevel`,`hybridMultilevel`]),levels:ct(_r,9),styleLink:H(),numStyleLink:H(),ext:W},[`id`,`levels`]),yr=K({id:B(1,2147483647),abstract:B(0,2147483647),overrides:ct(K({level:B(0,8),start:B(0,2147483647),definition:_r},[`level`]),9),ext:W},[`id`,`abstract`]),br=K({latin:V(),eastAsia:V(),cs:V()},[`latin`]),xr=K({fonts:K({major:br,minor:br},[`major`,`minor`]),colors:e=>{if(!R(e))return`must be an object`;for(let[t,n]of Object.entries(e)){if(!/^(dk[12]|lt[12]|accent[1-6]|hlink|folHlink)$/.test(t))return`unknown color ${t}`;let e=at(n);if(e)return`${t} ${e}`}}},[`fonts`,`colors`]),Sr=K({id:B(0,2147483647),author:V(),initials:V(9),date:ot,content:e=>Array.isArray(e)?void 0:`must be an array of blocks`,parent:B(0,2147483647),done:z,ext:W},[`id`,`author`,`content`]),Cr=[`bold`,`boldCs`,`italic`,`italicCs`,`caps`,`smallCaps`,`strike`,`doubleStrike`,`hidden`],wr={bold:!1,boldCs:!1,italic:!1,italicCs:!1,caps:!1,smallCaps:!1,strike:!1,doubleStrike:!1,hidden:!1,underline:null,underlineColor:null,font:{ascii:null,hAnsi:null,eastAsia:null,cs:null},size:20,sizeCs:20,color:null,highlight:null,shading:null,verticalAlign:`baseline`,characterSpacing:0},Tr={style:null,justification:null,indent:{left:0,right:0,firstLine:0,hanging:0},spacing:{before:0,after:0,line:null,lineRule:`auto`,beforeAutospacing:!1,afterAutospacing:!1},keepNext:!1,keepLines:!1,widowControl:!1,pageBreakBefore:!1,contextualSpacing:!1,outlineLevel:null,tabs:[],borders:null,shading:null,numbering:null},Er=new Set([`justification`,`keepNext`,`keepLines`,`widowControl`,`pageBreakBefore`,`contextualSpacing`,`outlineLevel`,`shading`]);function Dr(e,t){if(!t)return;let{indent:n,spacing:r,numbering:i,borders:a,tabs:o}=t;if(n&&(n.firstLine!==void 0&&(e.indent.hanging=0),Object.assign(e.indent,n),e.indent.hanging&&(e.indent.firstLine=0)),r&&Object.assign(e.spacing,r),i&&(e.numbering={id:i.id??e.numbering?.id??0,level:i.level??e.numbering?.level}),a&&(e.borders={...e.borders,...a}),o){let t=new Map(e.tabs.map(e=>[e.position,e]));for(let e of o)e.kind===`clear`?t.delete(e.position):t.set(e.position,{position:e.position,kind:e.kind,leader:e.leader??null});e.tabs=[...t.values()].sort((e,t)=>e.position-t.position)}for(let[n,r]of Object.entries(t))Er.has(n)&&r!=null&&(e[n]=r)}function Or(e){return{...e,indent:{...e.indent},spacing:{...e.spacing},tabs:e.tabs.map(e=>({...e})),borders:e.borders?Object.fromEntries(Object.entries(e.borders).map(([e,t])=>[e,{...t}])):null,shading:e.shading?{...e.shading}:null,numbering:e.numbering?{...e.numbering}:null}}function kr(e){return{...e,font:{...e.font}}}function Ar(e){let t={};for(let n of e??[]){let e=n.attrs??{},r=e.value===void 0||e.value;switch(n.type){case`bold`:case`italic`:{r!==null&&(t[n.type]=r);let i=e.complexScript;i!=null&&(t[n.type===`bold`?`boldCs`:`italicCs`]=i);break}case`caps`:case`smallCaps`:case`strike`:case`doubleStrike`:case`hidden`:r!==null&&(t[n.type]=r)}}return t}var jr={text1:`dk1`,background1:`lt1`,text2:`dk2`,background2:`lt2`,dark1:`dk1`,light1:`lt1`,dark2:`dk2`,light2:`lt2`,hyperlink:`hlink`,followedHyperlink:`folHlink`};function Mr(e,t,n){for(let r of t??[]){let t=r.attrs??{};switch(r.type){case`underline`:{let n=t.style??`single`;e.underline=n===`none`?null:n,e.underlineColor=t.color??null;break}case`font`:for(let r of[`ascii`,`hAnsi`,`eastAsia`,`cs`]){let i=t[`${r}Theme`],a=i&&Fr(n,i)||t[r];a&&(e.font[r]=a)}break;case`fontSize`:typeof t.value==`number`&&(e.size=t.value),typeof t.complexScript==`number`&&(e.sizeCs=t.complexScript);break;case`color`:{let r=(t.themeColor&&!t.themeTint&&!t.themeShade?n?.colors[jr[t.themeColor]??t.themeColor]:void 0)??t.value;e.color=r===void 0||r===`auto`?null:r.toUpperCase();break}case`highlight`:e.highlight=t.value===`none`?null:t.value;break;case`shading`:e.shading=t.fill===`auto`||t.fill===void 0?null:String(t.fill).toUpperCase();break;case`verticalAlign`:e.verticalAlign=t.value;break;case`characterSpacing`:e.characterSpacing=t.value}}}function Nr(e,t,n){Object.assign(e,Ar(t)),Mr(e,t,n)}function Pr(e,t,n){let r={};for(let i of t)Object.assign(r,Ar(i)),Mr(e,i,n);for(let t of Cr)r[t]&&(e[t]=!e[t])}function Fr(e,t){if(!e)return null;let n=t.startsWith(`major`)?e.fonts.major:e.fonts.minor,r=t.slice(5);return(r===`EastAsia`?n.eastAsia:r===`Bidi`?n.cs:n.latin)||null}function Ir(e,t){switch(t??`decimal`){case`none`:return``;case`decimalZero`:return e>=0&&e<10?`0${e}`:String(e);case`upperRoman`:return zr(e);case`lowerRoman`:return zr(e).toLowerCase();case`upperLetter`:return Br(e);case`lowerLetter`:return Br(e).toLowerCase();case`ordinal`:return Vr(e);case`chicago`:return Lr(e);case`numberInDash`:return`- ${e} -`;default:return String(e)}}function Lr(e){return e<1?String(e):[`*`,`†`,`‡`,`§`][(e-1)%4].repeat(Math.ceil(e/4))}var Rr=[[1e3,`M`],[900,`CM`],[500,`D`],[400,`CD`],[100,`C`],[90,`XC`],[50,`L`],[40,`XL`],[10,`X`],[9,`IX`],[5,`V`],[4,`IV`],[1,`I`]];function zr(e){if(e<=0||e>=4e3)return String(e);let t=``,n=e;for(let[e,r]of Rr)for(;n>=e;n-=e)t+=r;return t}function Br(e){return e<=0||e>780?String(e):String.fromCharCode(65+(e-1)%26).repeat(Math.floor((e-1)/26)+1)}function Vr(e){let t=e%100;return`${e}${t>=11&&t<=13?`th`:[`th`,`st`,`nd`,`rd`][e%10]??`th`}`}var Hr=new Set([`width`,`justification`,`indent`,`layout`,`borders`,`cellMargins`,`cellSpacing`,`shading`,`look`,`rowBandSize`,`columnBandSize`]),Ur=new Set([`borders`,`cellMargins`,`look`]);function Wr(e,t){if(t)for(let[n,r]of Object.entries(t))r!=null&&Hr.has(n)&&(e[n]=Ur.has(n)?{...e[n],...r}:r)}function Gr(e){if(e)return e.type===`dxa`?e.value:0}function Kr(e,t){for(let n=e.length-1;n>=0;n--){let r=t(e[n]);if(r!=null)return r}}function qr(e,t,n=1,r=1){let i=[`wholeTable`],a=!!e.firstRow&&t.row===0,o=!!e.lastRow&&t.row===t.rows-1,s=!!e.firstColumn&&t.cell===0,c=!!e.lastColumn&&t.cell===t.cells-1;if(!e.noVBand&&!s&&!c){let n=t.cell-+!!e.firstColumn;i.push(Math.floor(n/r)%2==0?`band1Vert`:`band2Vert`)}if(!e.noHBand&&!a&&!o){let r=t.row-+!!e.firstRow;i.push(Math.floor(r/n)%2==0?`band1Horz`:`band2Horz`)}return s&&i.push(`firstCol`),c&&i.push(`lastCol`),a&&i.push(`firstRow`),o&&i.push(`lastRow`),a&&s&&i.push(`nwCell`),a&&c&&i.push(`neCell`),o&&s&&i.push(`swCell`),o&&c&&i.push(`seCell`),i}var Jr=class{#e=new Map;#t;#n;#r=new Map;#i=new Map;#a=new Map;#o=new Map;#s;#c=new Map;get addsParagraphSpacing(){return this.#n.settings?.doNotUseHTMLParagraphAutoSpacing===!0}constructor(e){this.#n=e;for(let t of e.styles)this.#e.has(t.id)||this.#e.set(t.id,t);for(let t of e.styles)t.type===`paragraph`&&t.isDefault&&(this.#t=t.id),t.type===`table`&&t.isDefault&&(this.#s=t.id);for(let t of e.numbering.instances)this.#a.has(t.id)||this.#a.set(t.id,t);for(let t of e.numbering.abstracts)this.#o.has(t.id)||this.#o.set(t.id,t)}#l(e,t){let n=[],r=new Set;for(let i=e;i!==void 0&&!r.has(i);){r.add(i);let e=this.#e.get(i);if(e?.type!==t)break;n.unshift(e),i=e.basedOn}return n}#u(e){let t=e?this.#l(e,`table`):[];return t.length?t:this.#l(this.#s,`table`)}#d(e,t){let n=JSON.stringify([e,t]),r=this.#c.get(n);if(r)return r;let i={key:n,paragraph:[],run:[],cell:[]},a=this.#u(e);for(let e of t)for(let t of a){let n=e===`wholeTable`?t:t.conditions?.find(t=>t.type===e);n?.paragraph&&i.paragraph.push(n.paragraph),n?.run&&i.run.push(n.run),n?.cell&&i.cell.push(n.cell)}return this.#c.set(n,i),i}table(e){let t=this.#u(e.style),n={};for(let e of t)Wr(n,e.table);return Wr(n,e),structuredClone({...n,style:t.at(-1)?.id??null})}cell(e,t,n,r){let i=this.table(e);Wr(i,t.exceptions);let a=i,o=qr(a.look??{},r,a.rowBandSize,a.columnBandSize),s=[...this.#d(a.style,o).cell,n],c=Kr(s,e=>e.shading)?.fill??a.shading?.fill,l=a.borders??{},u=(e,t,n,r)=>Kr(s,n=>n.borders?.[e]??(t?n.borders?.[t]:void 0))??(r?l[e]??(t?l[t]:void 0):n),d={},f=[[`top`,null,l.insideH,r.row===0],[`bottom`,null,l.insideH,r.row===r.rows-1],[`left`,`start`,l.insideV,r.cell===0],[`right`,`end`,l.insideV,r.cell===r.cells-1]];for(let[e,t,n,r]of f){let i=u(e,t,n,r);i&&(d[e]={...i})}let p=(e,t)=>Gr(Kr(s,n=>n.margins?.[e]??(t?n.margins?.[t]:void 0))??a.cellMargins?.[e]??(t?a.cellMargins?.[t]:void 0))??0;return{style:a.style,conditions:o,shading:c===void 0||c===`auto`?null:c.toUpperCase(),borders:d,margins:{top:p(`top`,null),bottom:p(`bottom`,null),left:p(`left`,`start`),right:p(`right`,`end`)},verticalAlign:Kr(s,e=>e.verticalAlign)??`top`}}#f(e,t){let n=JSON.stringify([t?.key??null,e??null]),r=this.#r.get(n);if(r)return r;let i=Or(Tr),a=kr(wr);this.#p(i,a,t);let o=e===void 0?[]:this.#l(e,`paragraph`);o.length||(o=this.#l(this.#t,`paragraph`));for(let e of o)Dr(i,e.paragraph);Pr(a,o.map(e=>e.run??[]),this.#n.theme),i.style=o.at(-1)?.id??null;let s={paragraph:i,run:a,chain:o};return this.#r.set(n,s),s}#p(e,t,n){let{defaults:r,theme:i}=this.#n;Dr(e,r.paragraph),t&&Nr(t,r.run,i);for(let t of n?.paragraph??[])Dr(e,t);if(t)for(let e of n?.run??[])Nr(t,e,i)}paragraph(e,t){let{paragraph:n,run:r}=this.#m(e,t);return{paragraph:n,run:r}}#m(e,t){let n=e,r=t?this.#d(t.style,t.conditions):void 0,i=this.#f(n.style??void 0,r),a=Or(i.paragraph),o=n.numbering?.id!=null;n.numbering&&Dr(a,{numbering:n.numbering});let s=this.#h(a);if(s?.level.paragraph){if(o)Dr(a,s.level.paragraph);else{let e=Or(Tr);this.#p(e,null,r),Dr(e,s.level.paragraph);for(let t of i.chain)Dr(e,t.paragraph);e.style=a.style,e.numbering=a.numbering,a=e}}let{style:c,numbering:l,...u}=n;Dr(a,u);let d=s?{id:s.instance.id,level:s.index}:null;return{paragraph:{...Or(a),numbering:d},run:kr(i.run),level:s}}numberFormat(e){let t=this.#m(e).level;return t?t.level.format??`decimal`:null}run(e,t){let n=kr(e),r=t.find(e=>e.type===`characterStyle`)?.attrs?.id;if(r){let e=this.#i.get(r);e||(e=this.#l(r,`character`).map(e=>e.run??[]),this.#i.set(r,e)),Pr(n,e,this.#n.theme)}return Nr(n,t,this.#n.theme),n}#h(e){let t=e.numbering?.id,n=t?this.#a.get(t):void 0,r=n&&this.#_(n.abstract);if(!n||!r)return;let i=e.numbering?.level??r.levels.find(t=>t.style!==void 0&&t.style===e.style)?.level??0,a=this.#g(n,r,i);return a?{instance:n,abstract:r,index:i,level:a}:void 0}#g(e,t,n){return e.overrides?.find(e=>e.level===n)?.definition??t.levels.find(e=>e.level===n)}#_(e){let t=this.#o.get(e);for(let e=0;t?.numStyleLink&&e<8;e++){let e=this.#e.get(t.numStyleLink)?.paragraph?.numbering?.id,n=e?this.#a.get(e):void 0,r=n?this.#o.get(n.abstract):void 0;if(!r||r===t)break;t=r}return t}markers(e){let t=new Map,n=new Set;return e.map(e=>{let r=e.numbering,i=e.style??void 0;if(!(r?.id??this.#f(i).paragraph.numbering?.id))return null;let{run:a,level:o}=this.#m(e);if(!o)return null;let{instance:s,abstract:c,index:l,level:u}=o,d=t.get(c.id);d||(d=[],t.set(c.id,d));let f=e=>s.overrides?.find(t=>t.level===e)?.start??this.#g(s,c,e)?.start??0,p=`${s.id}:${l}`,m=s.overrides?.find(e=>e.level===l)?.start,h=d[l];m!==void 0&&!n.has(p)?(n.add(p),d[l]=m):d[l]=h===void 0?f(l):h+1;for(let e=l+1;e<9;e++){let t=this.#g(s,c,e)?.restart;(t===void 0||t!==0&&l<t)&&(d[e]=void 0)}let g=e=>e.replace(/%([1-9])/g,(e,t)=>{let n=Number(t)-1,r=u.legal?`decimal`:this.#g(s,c,n)?.format;return Ir(d[n]??f(n),r)}),_=g(u.text??``),v=kr(a);return Nr(v,e.markFormat,this.#n.theme),Nr(v,u.run,this.#n.theme),{text:_,plain:g((u.text??``).replace(/\p{L}+/gu,``)).trim(),suffix:u.suffix??`tab`,justification:u.justification??`left`,run:v,instance:s.id,abstract:c.id,level:l}})}};function Yr(e,t){let{stories:n,comments:r,...i}=structuredClone(e);return{...i,comments:r.map(e=>({...e,content:e.content.map(bn)})),...n&&{stories:Object.fromEntries(Object.entries(n).map(([e,t])=>[e,{...t,content:bn(t.content)}]))},content:bn(t.toJSON())}}var Xr=new $e(`word`),Zr=class e extends Ae{id;comment;previous;index;constructor(e,t,n,r){super(),this.id=e,this.comment=t,this.previous=n,this.index=r}apply(e){return N.ok(e)}invert(){return new e(this.id,this.previous,this.comment,this.index)}map(){return this}};function Qr(e,t){let n=e;for(let e of t){if(!(e instanceof Zr))continue;let t=n.findIndex(t=>t.id===e.id);if(e.previous===null!=t<0)continue;let r=t<0?n:[...n.slice(0,t),...n.slice(t+1)];if(!e.comment)n=r;else{let i=t<0?Math.min(e.index,r.length):t;n=[...r.slice(0,i),e.comment,...r.slice(i)]}}return n}function $r(e,t,n){let r=Qr(t,e.steps),i=new Map(n.map(e=>[e.id,e]));for(let t of r)i.has(t.id)||(e.step(new Zr(t.id,null,t,r.indexOf(t))),r=Qr(r,e.steps.slice(-1)));return n.forEach((t,n)=>{let i=r.find(e=>e.id===t.id)??null;i===t||i&&JSON.stringify(i)===JSON.stringify(t)||(e.step(new Zr(t.id,t,i,n)),r=Qr(r,e.steps.slice(-1)))}),e}var ei=class e extends Ae{key;before;after;constructor(e,t,n){super(),this.key=e,this.before=t,this.after=n}apply(e){return N.ok(e)}invert(){return new e(this.key,this.after,this.before)}map(){return this}},ti=class e extends Ae{id;before;after;selectionBefore;selectionAfter;constructor(e,t,n,r=null,i=null){super(),this.id=e,this.before=t,this.after=n,this.selectionBefore=r,this.selectionAfter=i}apply(e){return N.ok(e)}invert(){return new e(this.id,this.after,this.before,this.selectionAfter,this.selectionBefore)}map(){return this}merge(t){return t.id!==this.id||!ni(this.after,t.before)?null:new e(this.id,this.before,t.after,this.selectionBefore,t.selectionAfter)}};function ni(e,t){return e===t||!e&&!t||!!e&&!!t&&e.kind===t.kind&&e.noteType===t.noteType&&e.ext===t.ext&&(e.doc===t.doc||e.doc.eq(t.doc))}function ri({doc:e,...t}){return{...t,content:e.toJSON()}}function ii(e,t,n){let r=t;for(let t of n)t instanceof ei&&t.key===e&&(r=t.after);return r}function ai(e,t,n,r){let i=X(e)?.envelope;return i?t.step(new ei(n,ii(n,i[n],t.steps),r)):t}function oi(e,t){let n=new Map,r=new Map;for(let i of t)if(i instanceof ei){let t=i.key;if(!u(n.has(t)?n.get(t):e.envelope[t],i.before))return!1;n.set(t,i.after)}else if(i instanceof ti){if(!ni(r.has(i.id)?r.get(i.id):e.stories.get(i.id)??null,i.before))return!1;r.set(i.id,i.after)}return!0}function si(e,t,n){let r=X(e)?.stories.get(n)??null;for(let e of t.steps)e instanceof ti&&e.id===n&&(r=e.after);return r}var ci=new $e(`storyBody`),li=e=>ci.getState(e)??null;function ui(e,t,n){let r=X(e),i=n?{...r,envelope:n}:r;return rt.create({doc:t,plugins:[pi(i.envelope,i)]})}function di(e){let t=[...X(e)?.stories.values()??[]].map(e=>e.doc),n=li(e)?.state.doc;return(n?[n,...t]:t).filter(t=>t!==e.doc)}function fi(e,t){return new Map(Object.entries(e.stories??{}).map(([e,{content:n,...r}])=>[e,{...r,doc:Gn(n,{path:`stories[${JSON.stringify(e)}].content`,schema:t})}]))}function pi(e,t){let n=`${Date.now().toString(36)}${Math.random().toString(36).slice(2)}`;return new et({key:Xr,state:{init:r=>t??{envelope:e,resolver:new Jr(e),stories:fi(e,r.schema),id:n},apply:(e,t)=>{let n=e.getMeta(hi);if(n)return n;let r=e.getMeta(Xr),i=Qr(t.envelope.comments,e.steps),a=r??t.envelope,o=ii(`section`,a.section,e.steps),s=ii(`settings`,t.envelope.settings,e.steps),c=ii(`controls`,a.controls,e.steps),{stories:l}=t,u=t.envelope.stories;for(let t of e.steps){if(!(t instanceof ti))continue;let e=new Map(l),n={...u};t.after?(e.set(t.id,t.after),n[t.id]=ri(t.after)):(e.delete(t.id),delete n[t.id]),l=e,u=n}if(!r&&i===t.envelope.comments&&o===a.section&&s===t.envelope.settings&&c===t.envelope.controls&&l===t.stories)return t;let{stories:d,settings:f,controls:p,...m}=a,h={...m,section:o,comments:i,...u&&Object.keys(u).length?{stories:u}:{},...s?{settings:s}:{},...c?{controls:c}:{}};return{envelope:h,resolver:r?new Jr(h):t.resolver,stories:l,id:t.id}}}})}function mi(e,t){return e.setMeta(Xr,t)}var hi=`adoptWordContext`,gi=(e,t)=>e.setMeta(hi,t),_i=e=>e.getMeta(Xr);function X(e){return Xr.getState(e)??null}var vi=Object.fromEntries(Je.map(e=>[e,null]));function yi(e){let t;for(let n of e.styles)n.type===`paragraph`&&n.isDefault&&(t=n.id);return t}function bi(e,t,n){let r=t.attrs,i=Object.keys(vi).some(e=>r[e]!==null)?{...r,...vi}:null;if(!n)return{before:i,after:r};let a=r.style??yi(e.envelope),o=e.envelope.styles.find(e=>e.id===a)?.next;return o===void 0||o===a?{before:i,after:r}:{before:i,after:{...Object.fromEntries(Object.keys(vi).map(e=>[e,r[e]??null])),controls:r.controls,style:o}}}var xi={bold:e=>e.bold,italic:e=>e.italic,underline:e=>e.underline!==null,strike:e=>e.strike,doubleStrike:e=>e.doubleStrike,caps:e=>e.caps,smallCaps:e=>e.smallCaps,hidden:e=>e.hidden};function Si(e,t){return e!==null&&Object.hasOwn(xi,t.name)}function Ci(e,t,n,r,i=!0){let{run:a}=e.resolver.paragraph(t.attrs),o=n.filter(e=>i||e.type!==r).map(e=>e.toJSON());return xi[r.name](e.resolver.run(a,o))}function wi(e,t,n,r){let i=r?.attrs.complexScript??null,a=Object.hasOwn(e.spec.attrs??{},`complexScript`);return t===n?a&&i!==null?e.create({value:null,complexScript:i}):null:e.name===`underline`?e.create({style:t?`single`:`none`}):e.create(a?{value:t,complexScript:i}:{value:t})}function Ti(e,t,n,r){let i=[];e.doc.nodesBetween(t,n,(e,t,n)=>{if(e.isInline&&n?.type.allowsMarkType(r))return ki.has(e.type.name)||i.push({node:e,pos:t,parent:n}),!1});let a=i.filter(e=>e.node.isText);return a.length?{all:i,judged:a}:{all:i,judged:i}}function Ei(e,t,n,r){let{selection:i}=t;if(r)return Ci(e,i.$from.parent,r,n);let a=i.ranges.flatMap(e=>Ti(t,e.from,e.to,n).judged);return a.length>0&&a.every(t=>Ci(e,t.parent,t.node.marks,n))}function Di(e,t,n,r){let i=!Ci(e,t,n,r),a=r.isInSet(n),o=a?a.removeFromSet(n):n,s=wi(r,i,Ci(e,t,n,r,!1),a);return s?s.addToSet(o):o}function Oi(e,t,n,r,i,a){return Ti(t,n,r,i).all.map(({node:t,pos:o,parent:s})=>({from:Math.max(n,o),to:Math.min(r,o+t.nodeSize),mark:wi(i,a,Ci(e,s,t.marks,i,!1),i.isInSet(t.marks))}))}var ki=new Set([`bookmarkStart`,`bookmarkEnd`,`commentStart`,`commentEnd`,`controlStart`,`controlEnd`,`fieldStart`,`fieldCode`,`fieldSeparator`,`fieldEnd`,`noteMark`,`commentReference`]);function Ai(e,t){return e!==null&&!!t&&ki.has(t.type.name)}var ji=new Set([`opaqueInline`,`opaqueBlock`,`foreignInline`,`foreignBlock`]);function Mi(e,t){return e!==null&&!!t&&ji.has(t.type.name)}function Ni(e,t){let n=e.doc.nodeAt(t);return n&&Ge.isSelectable(n)?Ge.create(e.doc,t):L.create(e.doc,t)}var Pi=new WeakMap,Fi=e=>e.marks.some(e=>e.type.name===`deletion`);function Ii(e){let t=Pi.get(e);if(t)return t;let n=[],r=[],i=e=>{let t=r[r.length-1];t&&e&&(t.field.separator===null?t.code+=e:(t.broke&&(t.text+=`\r`),t.broke=!1,t.text+=e))};if(e.descendants((e,t)=>{if(e.isTextblock){for(let e of r)e.field.separator!==null&&(e.broke=!0);return!0}if(!e.isInline)return!0;let a=r[r.length-1];switch(e.type.name){case`fieldStart`:r.push({code:``,text:``,broke:!1,field:{from:t,to:t,separator:null,codeEnd:t,resultFrom:t,resultTo:t,instruction:``,name:``,result:``,locked:e.attrs.locked===!0,deleted:Fi(e),codeMarks:null,resultMarks:null,parent:a?.field??null,inCode:!!a&&a.field.separator===null}});break;case`fieldCode`:a?.field.separator===null&&(a.code+=String(e.attrs.text??``),a.field.codeMarks??=e.marks);break;case`fieldSeparator`:a?.field.separator===null&&(a.field.separator=t);break;case`fieldEnd`:{let e=r.pop();if(!e)break;let{field:a}=e;a.to=t+1,a.codeEnd=a.separator??t,a.resultFrom=a.separator===null?t:a.separator+1,a.resultTo=t,a.instruction=e.code.trim(),a.name=(/^\S*/.exec(a.instruction)?.[0]??``).toUpperCase(),a.result=e.text,n.push(a),i(e.text);let o=r[r.length-1]?.field;o&&o.separator!==null&&(o.resultMarks??=a.resultMarks);break}case`text`:Fi(e)||(i(e.text??``),a&&a.field.separator!==null&&(a.field.resultMarks??=e.marks));break;case`tab`:Fi(e)||i(` `);break;case`hardBreak`:Fi(e)||i(`
|
|
2
|
+
`)}return!1}),n.sort((e,t)=>e.from-t.from),r.length){let e=new Set(r.map(e=>e.field));for(let t of n)t.parent&&e.has(t.parent)&&(t.parent=null,t.inCode=!1)}return Pi.set(e,n),n}function Li(e,t){let n=null;for(let r of Ii(e)){if(r.from>=t)break;t<r.to&&(n=r)}return n}function Ri(e,t){let n=null;for(let r of Ii(e)){if(r.from>t)break;t<r.to&&(n=r)}return n}var zi=e=>!!e&&Bi.has(e.type.name),Bi=new Set([`fieldStart`,`fieldCode`,`fieldSeparator`,`fieldEnd`]),Vi={hidden:new Set,braces:new Map,gone:!1},Hi=new Set([...Bi,`bookmarkStart`,`bookmarkEnd`,`commentStart`,`commentEnd`,`commentReference`,`controlStart`,`controlEnd`]);function Ui(e,t){let n=(e,t)=>e*65536+t,r=new Map,i=[];if(e.forEach((e,t)=>{e.forEach((e,a)=>{if(e===`fieldStart`)i.push({at:n(t,a),separator:null});else if(e===`fieldSeparator`){let e=i[i.length-1];e&&e.separator===null&&(e.separator=n(t,a))}else if(e===`fieldEnd`){let e=i.pop();if(!e)return;r.set(e.at,`start`),e.separator!==null&&r.set(e.separator,`separator`),r.set(n(t,a),`end`)}})}),!r.size)return e.map(()=>Vi);let a=[],o=0,s=0,c=()=>t?s>0:o>0;return e.map((e,i)=>{let l=new Set,u=new Map,d=c(),f=!1;e.forEach((e,d)=>{let p=r.get(n(i,d));p===`start`?(t&&!s&&u.set(d,`{`),a.push(`code`),o++):p===`separator`?(o--,t&&!s&&u.set(d,`}`),s++,a[a.length-1]=`result`):p===`end`?a.pop()===`code`?(o--,t&&!s&&u.set(d,`}`)):s--:c()?l.add(d):(!Hi.has(e)||t&&e===`fieldCode`)&&(f=!0)});let p=d&&c()&&!f&&!u.size;return l.size||u.size||p?{hidden:l,braces:u,gone:p}:Vi})}var Wi=new $e(`fields`),Gi=e=>Wi.getState(li(e)?.state??e)===!0;function Ki(e,t,n){return t>e.from&&(n?t<e.to:t<=e.codeEnd)}function qi(e,t,n,r){let i=t;for(let t=!0;t;){t=!1;for(let a of e)Ki(a,i,r)&&(i=n?r||a.separator===null?a.to:a.separator+1:a.from,t=!0)}return i}function Ji(e,t,n){let r=t;for(let t=!0;t;){t=!1;for(let i of e){if(i.separator===null||r<i.resultFrom||r>i.resultTo)continue;let e=r===i.resultTo&&(r!==i.resultFrom||n);(e||r===i.resultFrom)&&(r=e?i.to:i.from,t=!0)}}return r}function Yi(e,t,n){let r=Math.min(t,n),i=Math.max(t,n);if(e.resolve(r).parent!==e.resolve(i).parent)return!1;let a=!1;return e.nodesBetween(r,i,e=>(e.isInline&&!Hi.has(e.type.name)&&(a=!0),!a)),!a}function Xi(e,t,n){let{selection:r,doc:i}=e;if(!(r instanceof L))return null;let a=Ii(i);if(!a.length)return null;let o=Gi(e),s=r.head>=t.head,c=qi(a,r.head,s,o);r.empty&&n&&!o&&(c=Ji(a,c,s));let l=r.empty?c:qi(a,r.anchor,r.anchor>r.head,o);n&&!r.empty&&(!t.empty&&Yi(i,c,t.head)&&(c=t.head),Yi(i,l,t.anchor)&&(l=t.anchor));let u=(e,t)=>t>e.from&&t<e.to;if(l!==c)for(let e=!0,n=0;e&&n<64;n++){e=!1;for(let n of a)if(!(n.deleted||u(n,l)===u(n,c))){if(e=!0,u(n,l))l=c>n.from?n.from:n.to;else{let[e,r]=l<=n.from?[n.to,n.from]:[n.from,n.to],a=l<=n.from?t.head>=e:t.head<=e;c=!Yi(i,c,e)&&a?r:e}}}return l===r.anchor&&c===r.head?null:L.create(i,l,c)}function Zi(){return new et({key:Wi,state:{init:()=>!1,apply:(e,t)=>e.getMeta(Wi)??t},appendTransaction(e,t,n){if(t.selection.eq(n.selection)&&t.doc===n.doc&&Gi(t)===Gi(n))return null;let r=Xi(n,t.selection,t.doc===n.doc);return r?n.tr.setSelection(r):null}})}var Qi=(e,t)=>L.create(e,t.from,t.to),$i=new $e(`history`),ea=`historyOp`,ta=`closeHistory`,na=`joinHistory`,ra=`storyEdit`,ia={done:[],undone:[],prevTime:0,prevRanges:null};function aa({newGroupDelay:e=500,depth:t=100}={}){return new et({key:$i,state:{init:()=>ia,apply(n,r,i){let a=n.getMeta($i);if(a)return a;if(!n.docChanged)return r;let o=n.getMeta(`appendedTransaction`),s=o?.getMeta(ea),c=n.steps.map((e,t)=>e.invert(n.docs[t])).reverse();if(s){let e=s===`undo`?r.undone:r.done,t=e[e.length-1],a=t?[...e.slice(0,-1),{steps:oa(c,t.steps),selection:t.selection}]:[...e,{steps:c,selection:i.selection.toJSON()}];return s===`undo`?{...r,undone:a,done:fa(r.done,n.mapping,n.doc)}:{...r,done:a,undone:fa(r.undone,n.mapping,n.doc)}}if(!n.addToHistory||o&&!o.addToHistory)return{done:fa(r.done,n.mapping,n.doc),undone:fa(r.undone,n.mapping,n.doc),prevTime:0,prevRanges:null};let l=r.done[r.done.length-1],u=n.getMeta(ra);return{done:(l!==void 0&&(o!==void 0||n.getMeta(`joinHistory`)===!0||!n.getMeta(`closeHistory`)&&n.time-r.prevTime<e&&(r.prevStory??null)===(u?.id??null)&&sa(r.prevRanges,u?.tr??n))?[...r.done.slice(0,-1),{steps:oa(c,l.steps),selection:l.selection}]:[...r.done,{steps:c,selection:i.selection.toJSON()}]).slice(-t),undone:[],prevTime:o?r.prevTime:n.getMeta(`closeHistory`)?0:n.time,prevRanges:o?la(r.prevRanges,n.mapping):ca(u?.tr??n),prevStory:o?r.prevStory??null:u?.id??null}}}})}function oa(e,t){let n=e[e.length-1],r=t[0],i=n instanceof je&&r||n instanceof ti&&r instanceof ti?n.merge(r):null;return i?[...e.slice(0,-1),i,...t.slice(1)]:[...e,...t]}function sa(e,t){let n=t.mapping.maps[0];if(!e||!n)return!1;let r=!1;return n.forEach((t,n)=>{for(let i=0;i<e.length;i+=2)t<=e[i+1]&&n>=e[i]&&(r=!0)}),r}function ca(e){let t=[];return e.mapping.maps.forEach((n,r)=>{let i=e.mapping.slice(r+1);n.forEach((e,n,r,a)=>{t.push(i.map(r,-1),i.map(a,1))})}),t}function la(e,t){return e&&e.map((e,n)=>t.map(e,n%2?1:-1))}var ua=class{base;inverted=[];rebased=[];constructor(e){this.base=e}push(e,t){this.inverted.push(e.getMap().invert()),this.rebased.push(t?t.getMap():null)}map(e,t=1){return this.mapResult(e,t).pos}mapResult(e,t=1){let n=!1,r=0,i=!1,a=[];for(let o=this.inverted.length-1;o>=0;o--){a[o]=this.inverted[o].sides(e);let s=this.inverted[o].mapResult(e,t),c=this.rebased[o];if(s.recover!==null&&c){e=c.recover(s.recover),r=o+1,i=!0;break}n||=s.deleted,e=s.pos}if(!i){let r=this.base.mapResult(e,t);n||=r.deleted,e=r.pos}for(let i=r;i<this.rebased.length;i++){let r=this.rebased[i]?.mapResult(e,t,a[i]);r&&(n||=r.deleted,e=r.pos)}return{pos:e,deleted:n,recover:null}}};function da(e,t){let n=e.anchor<=e.head?-1:1,r=e.anchor===e.head?-1:-n;return{...e,anchor:t.map(e.anchor,n),head:t.map(e.head,r)}}function fa(e,t,n){let r=new ua(t),i=n,a=[];for(let t=e.length-1;t>=0;t--){let n=e[t],o=[];for(let e of n.steps){let t=e.map(r),n=t?.apply(i),a=n?.doc?t:null;a&&n?.doc&&(i=n.doc,o.push(a)),r.push(e,a)}o.length&&a.unshift({steps:o,selection:da(n.selection,r)})}return a}function pa(e,t){if(t instanceof Ie||t instanceof Le){if(t.from<0||t.to>e.doc.content.size||t.from>=t.to)return!1;try{return t instanceof Ie?e.addMark(t.from,t.to,t.mark):e.removeMark(t.from,t.to,t.mark),!0}catch(e){if(e instanceof P)return!1;throw e}}return e.maybeStep(t).failed===null}function ma(e){let t=(n,r)=>{let i=li(n);if(i)return r?i.run(t):i.can(t);let a=$i.getState(n),o=a&&(e?a.undone:a.done),s=o?.[o.length-1];if(!a||!o||!s)return!1;if(r){let t=n.tr,i=X(n);if(i&&!oi(i,s.steps)){let n=o.slice(0,-1);return t.setMeta($i,{done:e?a.done:n,undone:e?n:a.undone,prevTime:0,prevRanges:null}),r(t),!0}let c=null;for(let e of s.steps){let n=c?e.map(c):e,r=n!==null&&pa(t,n);!r&&!c&&(c=new ua(new ke)),c?.push(e,r?n:null)}let l=c?da(s.selection,c):s.selection;t.setSelection(I.fromJSON(t.doc,l));let u={steps:t.steps.map((e,n)=>e.invert(t.docs[n])).reverse(),selection:n.selection.toJSON()},d=o.slice(0,-1),f=u.steps.length?[u]:[];t.setMeta($i,{done:e?[...a.done,...f]:d,undone:e?d:[...a.undone,...f],prevTime:0,prevRanges:null}),t.setMeta(ea,e?`redo`:`undo`),r(t)}return!0};return t}var ha=ma(!1),ga=ma(!0),_a=e=>e.type.name===`table`;function va(e){for(let t=e.depth;t>0;t--)if(e.node(t).type.name===`tableCell`)return t;return-1}function ya(e,t){return e.depth>t&&_a(e.node(t+1))?t+1:-1}function ba(e,t,n){let r=e.doc,i=r.resolve(t),a=r.resolve(n),o=va(i),s=va(a);if(o<0&&s<0||o>=0&&s>=0&&i.before(o)===a.before(s))return!1;let c=i.sharedDepth(n),l=i.node(c).type.name;if(l===`table`||l===`tableRow`)return Sa(e,t,n,i.before(c+1),a.after(c+1)),!0;let u=ya(a,c),d=ya(i,c);if(u<0&&d<0)return!1;let f=n;if(u>=0){let t=a.node(u),n=a.before(u),r=a.index(u);if(r===t.childCount-1)e.delete(n,n+t.nodeSize);else{let i=n+1;for(let e=0;e<=r;e++)i+=t.child(e).nodeSize;e.delete(n+1,i)}f=n}let p=t,m=null;if(d>=0){let e=i.node(d),t=i.before(d),n=t+e.nodeSize,r=i.index(d);if(r===0)m=[t,n];else{let i=t+1;for(let t=0;t<r;t++)i+=e.child(t).nodeSize;m=[i,n-1]}p=n}return p<f&&xa(e,p,f),m&&e.delete(m[0],m[1]),!0}function xa(e,t,n){let r=e.doc.resolve(t),i=e.doc.resolve(n),a=[],o=t,s=n;r.parent.inlineContent&&(a.push([t,r.end()]),o=r.after()),i.parent.inlineContent&&(a.push([i.start(),n]),s=i.before()),o<s&&a.push([o,s]);for(let[t,n]of a.sort((e,t)=>t[0]-e[0]))t<n&&e.delete(t,n)}function Sa(e,t,n,r,i){let a=[];e.doc.nodesBetween(r,i,(e,o)=>{let s=o>=r&&o+e.nodeSize<=i;return e.type.name!==`tableCell`||!s||(o<n&&o+e.nodeSize>t&&a.push({pos:o,node:e}),!1)}),Ca(e,a.map(e=>e.pos))}function Ca(e,t){for(let n of[...t].sort((e,t)=>t-e)){let t=e.doc.nodeAt(n);if(t?.type.name!==`tableCell`)continue;let r=!0;if(t.forEach(e=>{e.type.name!==`paragraph`&&(r=!1)}),r){let r=n+2,i=n+t.nodeSize-2;r<i&&e.delete(r,i);continue}let i=t.type.schema.nodes.paragraph?.create();i&&e.replace(n+1,n+t.nodeSize-1,new w(f.from(i),0,0))}}function wa(e){let t=e.doc.type.schema.nodes.paragraph;if(!t)return;let n=[],r=(e,t)=>{let i=t;e.forEach((t,a,o)=>{if(_a(t)){let a=e.maybeChild(o+1);(a?_a(a):e.type.name===`doc`)&&n.push(i+t.nodeSize);let s=i+1;t.forEach(e=>{let t=s+1;e.forEach(e=>{r(e,t+1),t+=e.nodeSize}),s+=e.nodeSize})}i+=t.nodeSize})};r(e.doc,0);for(let r of n.reverse())e.insert(r,t.create())}function Ta(e){let t=e.selection.$head,n=va(t);return n<0?null:{$pos:t,depth:n}}function Ea(e,t){let n=[],r=t+1;return e.forEach(e=>{let t=r+1;e.forEach(e=>{e.attrs.vMerge!==`continue`&&n.push(t),t+=e.nodeSize}),r+=e.nodeSize}),n}function Da(e,t){let n=e.doc.nodeAt(t),r=I.near(e.doc.resolve(t+1),1).from,i=I.near(e.doc.resolve(t+n.nodeSize-1),-1).to;e.setSelection(L.create(e.doc,r,Math.max(r,i)))}function Oa(e){return(t,n)=>{let r=Ta(t);if(!r)return!1;let{$pos:i,depth:a}=r,o=a-2,s=i.node(o),c=i.before(o),l=Ea(s,c),u=l[l.indexOf(i.before(a))+e];if(u!==void 0){if(n){let e=t.tr;Da(e,u),n(e)}return!0}if(e<0)return!0;let d=ka(s.lastChild);if(!d)return!1;let f=c+s.nodeSize-1;return F(t,n,e=>{e.insert(f,d),e.setSelection(L.create(e.doc,f+3))})}}function ka(e){let t=e.type.schema.nodes.paragraph;if(!t)return null;let n={...e.attrs,revision:null,header:null,attributes:null},r=Object.fromEntries(Je.map(e=>[e,null])),i=[];return e.forEach(e=>{let n=e.firstChild,a=n?.type===t?{...n.attrs,...r}:null;i.push(e.type.create({...e.attrs,vMerge:null},t.create(a)))}),e.type.create(n,i)}function Aa(){return new et({keymap:{Tab:Oa(1),"Shift-Tab":Oa(-1)}})}function ja(e,t){let n=[],r=new Map,i=t+1;return e.forEach((e,t,a)=>{let o=e.attrs.gridBefore??0,s=i+1;e.forEach(e=>{let t=e.attrs.gridSpan??1,i=r.get(o);if(e.attrs.vMerge===`continue`&&i&&i.row+i.rowSpan===a)i.rowSpan++;else{let i={pos:s,row:a,rowSpan:1,column:o,span:t};n.push(i),e.attrs.vMerge===`restart`?r.set(o,i):r.delete(o)}o+=t,s+=e.nodeSize}),i+=e.nodeSize}),n}var Ma=class e extends I{cells;constructor(e,t){super(e,t),this.cells=Fa(e,t)}static create(t,n,r=n){return new e(t.resolve(n),t.resolve(r))}static valid(e,t,n){let r=e.resolve(t),i=e.resolve(n);return r.nodeAfter?.type.name===`tableCell`&&i.nodeAfter?.type.name===`tableCell`&&r.depth===i.depth&&r.before(r.depth-1)===i.before(i.depth-1)}get from(){return this.cells[0]??this.anchor}get to(){let e=this.cells[this.cells.length-1]??this.head;return e+(this.$head.doc.nodeAt(e)?.nodeSize??0)}get empty(){return!1}get ranges(){let e=this.$head.doc;return this.cells.map(t=>({from:t+1,to:t+(e.nodeAt(t)?.nodeSize??2)-1}))}map(t,n){let r=n.mapResult(this.anchor,1),i=n.mapResult(this.head,1);return!r.deleted&&!i.deleted&&e.valid(t,r.pos,i.pos)?e.create(t,r.pos,i.pos):I.near(t.resolve(Math.min(i.pos,t.content.size)))}toJSON(){return{type:`cell`,anchor:this.anchor,head:this.head}}};function Na(e,t,n,r){let i=t+1;for(let t=0;t<e.childCount;t++){let a=e.child(t),o=a.attrs.gridBefore??0,s=i+1;for(let e=0;e<a.childCount;e++){let i=a.child(e);if(s===r)return Pa(n,t,o);o+=i.attrs.gridSpan??1,s+=i.nodeSize}i+=a.nodeSize}}var Pa=(e,t,n)=>e.find(e=>e.row<=t&&t<e.row+e.rowSpan&&e.column<=n&&n<e.column+e.span);function Fa(e,t){let n=e.depth-1,r=e.node(n),i=e.before(n),a=ja(r,i),o=e=>a.find(t=>t.pos===e)??Na(r,i,a,e),s=o(e.pos),c=o(t.pos);if(!s||!c)return[e.pos];let l=Math.min(s.row,c.row),u=Math.max(s.row+s.rowSpan,c.row+c.rowSpan)-1,d=Math.min(s.column,c.column),f=Math.max(s.column+s.span,c.column+c.span)-1,p=e=>e.row<=u&&e.row+e.rowSpan-1>=l&&e.column<=f&&e.column+e.span-1>=d;for(let e=!0;e;){e=!1;for(let t of a){if(!p(t))continue;let n=[Math.min(l,t.row),Math.max(u,t.row+t.rowSpan-1),Math.min(d,t.column),Math.max(f,t.column+t.span-1)];(n[0]!==l||n[1]!==u||n[2]!==d||n[3]!==f)&&([l,u,d,f]=n,e=!0)}}return a.filter(p).map(e=>e.pos)}I.kinds.set(`cell`,(e,t)=>{let n=t=>Math.max(0,Math.min(t,e.content.size)),r=n(t.anchor),i=n(t.head);return Ma.valid(e,r,i)?Ma.create(e,r,i):I.near(e.resolve(i))});var Ia=e=>JSON.stringify(e??null);function La(e){let t=[];for(let{from:n,to:r}of e.selection.ranges)e.doc.nodesBetween(n,r,(e,n)=>e.type.name!==`paragraph`||(t.push({node:e,pos:n}),!1));return t}function Ra(e,t,n,r){let i=La(e).flatMap(({node:e,pos:t})=>{let r=n(e);return r&&Ia(r)!==Ia(e.attrs)?[new Re(t,e.type,r)]:[]});return i.length?F(e,t,e=>{e.step(new Be(i)),r&&mi(e,r)}):!1}function za(e){let[t]=e;return t!==void 0&&e.every(e=>Ia(e)===Ia(t))?t:null}function Ba(e,t,n=`paragraph`){let r=t.toLowerCase();return e.envelope.styles.find(e=>e.type===n&&e.name?.toLowerCase()===r)?.id??null}function Va(e,t=`paragraph`){let n=null;for(let r of e.envelope.styles)r.type===t&&r.isDefault&&(n=r.id);return n}var Ha=e=>/^Heading[1-9]$/.test(e)?`heading ${e.slice(7)}`:e===`ListParagraph`?`List Paragraph`:null;function Ua(e,t){let n=Va(e),r=n?{basedOn:n}:{},i=/^heading ([1-9])$/.exec(t)?.[1];if(i){let e=Number(i),a=e>=8?{value:`272727`,themeColor:`text1`,themeTint:`D8`}:{...[3,6,7].includes(e)?{value:`1F3763`,themeShade:`7F`}:{value:`2F5496`,themeShade:`BF`},themeColor:`accent1`},o=[32,26,24,0,0,0,0,21,21][e-1];return{id:`Heading${e}`,type:`paragraph`,name:t,...r,...n?{next:n}:{},paragraph:{keepNext:!0,keepLines:!0,spacing:{before:e===1?240:40,after:0},outlineLevel:e-1},run:[{type:`font`,attrs:{asciiTheme:`majorHAnsi`,eastAsiaTheme:`majorEastAsia`,hAnsiTheme:`majorHAnsi`,csTheme:`majorBidi`}},...[4,7,9].includes(e)?[{type:`italic`,attrs:{complexScript:!0}}]:[],{type:`color`,attrs:a},...o?[{type:`fontSize`,attrs:{value:o,complexScript:o}}]:[]]}}let a=/^toc ([1-9])$/.exec(t)?.[1];if(a){let i=e.envelope.defaults.run?.find(e=>e.type===`fontSize`)?.attrs?.value,o=(Number(a)-1)*(typeof i==`number`?i*10:220);return{id:`TOC${a}`,type:`paragraph`,name:t,...r,...n?{next:n}:{},paragraph:{spacing:{after:100},...o?{indent:{left:o}}:{}}}}if(t===`List Paragraph`)return{id:`ListParagraph`,type:`paragraph`,name:t,...r,paragraph:{indent:{left:720},contextualSpacing:!0}};if(t===`Table Grid`){let n={style:`single`,size:4,space:0,color:`auto`},r=Ba(e,`Normal Table`,`table`);return{id:`TableGrid`,type:`table`,name:t,...r?{basedOn:r}:{},paragraph:{spacing:{after:0,line:240,lineRule:`auto`}},table:{borders:{top:n,left:n,bottom:n,right:n,insideH:n,insideV:n}}}}let o=/^(foot|end)note (text|reference)$/.exec(t),s=/^(Foot|End)note Text Char$/.exec(t);if(o||s){let n=Va(e,`character`),i=n?{basedOn:n}:{},a={type:`fontSize`,attrs:{value:20,complexScript:20}},c=(o?.[1]??s?.[1]??``).toLowerCase()===`foot`?`Footnote`:`Endnote`;return s?{id:`${c}TextChar`,type:`character`,name:t,...i,link:`${c}Text`,run:[a]}:o?.[2]===`reference`?{id:`${c}Reference`,type:`character`,name:t,...i,run:[{type:`verticalAlign`,attrs:{value:`superscript`}}]}:{id:`${c}Text`,type:`paragraph`,name:t,...r,link:`${c}TextChar`,paragraph:{spacing:{after:0,line:240,lineRule:`auto`}},run:[a]}}if(t===`Placeholder Text`){let n=Va(e,`character`);return{id:`PlaceholderText`,type:`character`,name:t,...n?{basedOn:n}:{},run:[{type:`color`,attrs:{value:`666666`}}]}}if(t===`Hyperlink`){let n=Va(e,`character`);return{id:`Hyperlink`,type:`character`,name:t,...n?{basedOn:n}:{},run:[{type:`color`,attrs:{value:`0563C1`,themeColor:`hyperlink`}},{type:`underline`,attrs:{style:`single`}}]}}return null}function Wa(e,t,n=`paragraph`){let{envelope:r}=e,i=Ba(e,t,n);if(i)return{id:i,envelope:r};let a=Ua(e,t);if(!a)return null;let o=new Set(r.styles.map(e=>e.id)),s=a.id;for(let e=1;o.has(s);e++)s=`${a.id}${e}`;return{id:s,envelope:{...r,styles:[...r.styles,{...a,id:s}]}}}function Ga(e){return(t,n)=>{let r=X(t);if(!r)return!1;if(r.envelope.styles.some(t=>t.id===e&&t.type===`paragraph`))return qa(t,n,r,{id:e,envelope:r.envelope});let i=Ha(e);return!!i&&Ka(i)(t,n)}}function Ka(e){return(t,n)=>{let r=X(t),i=r&&Wa(r,e);return!!i&&qa(t,n,r,i)}}function qa(e,t,n,r){let i=r.id===Va(n)?null:r.id;return Ra(e,t,e=>({...e.attrs,style:i}),r.envelope===n.envelope?void 0:r.envelope)}function Ja(e,t){let n=X(e),r=[];for(let{from:i,to:a}of e.selection.ranges)e.doc.nodesBetween(i,a,(e,i,a)=>{if(e.isInline&&a?.type.allowsMarkType(t))return Ai(n,e)||r.push({node:e,pos:i,parent:a}),!1});return r}function Ya(e,t,n,r){let{run:i}=e.resolver.paragraph(t.attrs);return e.resolver.run(i,n.filter(e=>e.type!==r).map(e=>e.toJSON()))}function Xa(e,t){return(n,r)=>{let i=X(n),a=n.schema.marks[e];if(!i||!a)return!1;let{selection:o}=n;if(o.empty&&o instanceof L){let{$from:e}=o;if(!e.parent.type.allowsMarkType(a))return!1;let s=n.storedMarks??qe(e),c=t(a.isInSet(s),Ya(i,e.parent,s,a),a),l=a.removeFromSet(s);return r?.(n.tr.setStoredMarks(c?c.addToSet(l):l)),!0}let s=Ja(n,a);return s.length?F(n,r,e=>{for(let{node:n,pos:r,parent:c}of s){let s=Math.max(o.from,r),l=Math.min(o.to,r+n.nodeSize),u=a.isInSet(n.marks),d=t(u,Ya(i,c,n.marks,a),a);(d?u?.eq(d):!u)||(e.removeMark(s,l,a),d&&e.addMark(s,l,d))}}):!1}}var Za=e=>e.slice(1).toUpperCase(),Qa={black:`#000000`,blue:`#0000ff`,cyan:`#00ffff`,green:`#00ff00`,magenta:`#ff00ff`,red:`#ff0000`,yellow:`#ffff00`,white:`#ffffff`,darkBlue:`#000080`,darkCyan:`#008080`,darkGreen:`#008000`,darkMagenta:`#800080`,darkRed:`#800000`,darkYellow:`#808000`,darkGray:`#808080`,lightGray:`#c0c0c0`};function $a(e){return Xa(`color`,(t,n,r)=>e===null?n.color===null?null:r.create({value:`auto`}):n.color===Za(e)?null:r.create({value:Za(e)}))}function eo(e){return(t,n)=>{let r=e?Object.keys(Qa).find(t=>Qa[t]===e.toLowerCase()):void 0;if(e===null||r){let e=Xa(`highlight`,(e,t,n)=>r?t.highlight===r?null:n.create({value:r}):t.highlight===null?null:n.create({value:`none`}));return r?e(t,n):no(t,n,[e,Xa(`shading`,e=>e?.attrs.pattern===`clear`&&e.attrs.color===`auto`?null:e??null)])}return no(t,n,[to(`highlight`),Xa(`shading`,(t,n,r)=>r.create({pattern:`clear`,color:`auto`,fill:Za(e)}))])}}function to(e){return Xa(e,()=>null)}function no(e,t,n){let r=e,i=null;for(let e of n)e(r,e=>{if(!i)i=e;else{for(let t of e.steps)i.step(t);e.storedMarks!==r.storedMarks&&i.setStoredMarks(e.storedMarks)}r=r.apply(e)});return i?(t?.(i),!0):!1}var ro={start:`left`,center:`center`,end:`right`,justify:`both`};function io(e){return e===null||e===`left`||e===`start`?`start`:e===`center`?`center`:e===`right`||e===`end`?`end`:e===`both`||e===`distribute`?`justify`:null}function ao(e,t,n,r,i){let a={...t.attrs,[n]:null},o=e.resolver.paragraph(a).paragraph;return i(o)?a:{...t.attrs,[n]:r}}function oo(e){return(t,n)=>{let r=X(t);return r?Ra(t,n,t=>ao(r,t,`justification`,ro[e],t=>io(t.justification)===e)):!1}}var so=720;function co(e){return(t,n)=>{let r=X(t);return r?Ra(t,n,t=>{let{paragraph:n}=r.resolver.paragraph(t.attrs);if(n.numbering){let{id:i}=n.numbering,a=n.numbering.level+e;if(a<0)return fo(r,t);let o=go(r,i,a);if(!o)return null;let s=o.style;return s&&r.envelope.styles.some(e=>e.id===s)?{...t.attrs,style:s,numbering:t.attrs.numbering?{id:i,level:a}:null}:{...t.attrs,numbering:{id:i,level:a}}}let i=n.indent.left,a=e>0?(Math.floor(i/so)+1)*so:(Math.ceil(i/so)-1)*so;if(a<0||a>31680)return null;let o=t.attrs.indent??{};return{...t.attrs,indent:{...o,left:a}}}):!1}}function lo(e,t){let n=e.resolver.numberFormat(t);return n===null||n===`none`?null:n===`bullet`?`bulletList`:`orderedList`}function uo(e){let t=X(e);if(!t)return null;let n=La(e).map(({node:e})=>lo(t,e.attrs));return n.length?za(n):null}function fo(e,t){let n={...t.attrs,numbering:null},r=e.resolver.paragraph(n).paragraph.numbering!==null,i=Ba(e,`List Paragraph`),a=i!==null&&t.attrs.style===i?null:t.attrs.style;return{...n,style:a,numbering:r?{id:0}:null}}function po(e){let t=[[``,`Symbol`],[`o`,`Courier New`],[``,`Wingdings`]],n=[`decimal`,`lowerLetter`,`lowerRoman`];return Array.from({length:9},(r,i)=>{let a={indent:{left:so*(i+1),hanging:360}};if(e===`bulletList`){let[e,n]=t[i%3];return{level:i,start:1,format:`bullet`,text:e,justification:`left`,paragraph:a,run:[{type:`font`,attrs:{ascii:n,hAnsi:n,hint:`default`}}]}}return{level:i,start:1,format:n[i%3],text:`%${i+1}.`,justification:i%3==2?`right`:`left`,paragraph:i%3==2?{indent:{left:so*(i+1),hanging:180}}:a}})}var mo=e=>!e.styleLink&&!e.numStyleLink&&!e.levels.some(e=>e.style);function ho(e,t){let{abstracts:n,instances:r}=e.envelope.numbering;return n.find(e=>e.id===r.find(e=>e.id===t)?.abstract)}function go(e,t,n){return ho(e,t)?.levels.find(e=>e.level===n)}function _o(e,t){let n=ho(e,t);return!!n&&mo(n)}function vo(e,t){let{abstracts:n,instances:r}=e.numbering,i=e=>e.levels.find(e=>e.level===0)?.format,a=t===`bulletList`?r.find(e=>{let t=n.find(t=>t.id===e.abstract);return t&&mo(t)&&i(t)===`bullet`&&!e.overrides?.length}):void 0;if(a)return{id:a.id,envelope:e};let o=e=>Math.max(0,...e)+1,s=n.find(e=>mo(e)&&i(e)===(t===`bulletList`?`bullet`:`decimal`)),c=[];s||(s={id:Math.max(-1,...n.map(e=>e.id))+1,multiLevelType:`hybridMultilevel`,levels:po(t)},c.push(s));let l={id:o(r.map(e=>e.id)),abstract:s.id,...t===`orderedList`?{overrides:[{level:0,start:1}]}:{}};return{id:l.id,envelope:{...e,numbering:{abstracts:[...n,...c],instances:[...r,l]}}}}function yo(e){return(t,n)=>{let r=X(t);return!r||!La(t).length?!1:uo(t)===e?Ra(t,n,e=>fo(r,e)):bo(e)(t,n)}}function bo(e){return(t,n)=>{let r=X(t);if(!r)return!1;let i=La(t),a=i[0];if(!a)return!1;let o=a.pos>0?t.doc.resolve(a.pos).nodeBefore:null,s=o?.attrs.numbering?.id,c=Va(r),l=e=>{let t=r.resolver.paragraph(e.attrs).paragraph.style;return t===c||t===null},u=i.some(({node:e})=>l(e))?Wa(r,`List Paragraph`):null,d=u?.id??null,f=u?.envelope??r.envelope,p;return s&&o&&lo(r,o.attrs)===e&&_o(r,s)?p=s:{id:p,envelope:f}=vo(f,e),Ra(t,n,e=>{let t=r.resolver.paragraph(e.attrs).paragraph.numbering?.level??0,n=d&&l(e)?d:e.attrs.style;return{...e.attrs,style:n,numbering:{id:p,level:t}}},f===r.envelope?void 0:f)}}function xo(e,t,n){let{selection:r}=e;if(!r.empty)return null;let{$from:i}=r;return i.parent.type.name!==`paragraph`||n&&i.parentOffset>0?null:t.resolver.paragraph(i.parent.attrs).paragraph.numbering?i.parent:null}var So=(e,t)=>{let n=X(e);return!n||La(e).length<2&&!xo(e,n,!0)?!1:co(1)(e,t)},Co=(e,t)=>{let n=X(e);return n?La(e).some(({node:e})=>n.resolver.paragraph(e.attrs).paragraph.numbering)&&co(-1)(e,t):!1},wo=(e,t)=>{let n=X(e),r=n&&xo(e,n,!0);return!n||!r||r.content.size?!1:co(-1)(e,t)},To=(e,t)=>{let n=X(e),r=n&&xo(e,n,!0);return!n||!r?!1:Ra(e,t,e=>{let{indent:t}=n.resolver.paragraph(e.attrs).paragraph;return{...fo(n,e),indent:{left:t.left,right:t.right,firstLine:0}}})};function Eo(e,t,n,r){let i=X(t),a=t.schema.marks.characterStyle,o=i&&a&&Wa(i,`Hyperlink`,`character`);i&&a&&o&&(e.addMark(n,r,a.create({id:o.id})),o.envelope!==i.envelope&&mi(e,o.envelope))}function Do(e,t,n,r){let i=X(t),a=t.schema.marks.characterStyle,o=i&&Ba(i,`Hyperlink`,`character`);o&&a&&e.doc.nodesBetween(n,r,(t,i)=>{a.isInSet(t.marks)?.attrs.id===o&&e.removeMark(Math.max(n,i),Math.min(r,i+t.nodeSize),a)})}var Oo=/^[^\s@/:]+@[^\s@/:]+\.\p{L}{2,}$/iu,ko=/^(?:www\.|(?:[\p{L}\p{N}-]+\.)+\p{L}{2,}(?:[:/?#]|$))/iu;function Ao(e){let t=e.trim().replace(/\\/g,`/`).replace(/ /g,`%20`);return Oo.test(t)?`mailto:${t}`:ko.test(t)?`https://${t}`:t}var jo=e=>e.schema.marks.link;function Mo(e,t){let n=e.parent;if(!n.inlineContent)return null;let r=e.index();for(let i of e.textOffset?[r]:[r-1,r]){let r=t.isInSet(n.maybeChild(i)?.marks??[]);if(!r)continue;let a=i,o=i+1;for(;a>0&&r.isInSet(n.child(a-1).marks);)a--;for(;o<n.childCount&&r.isInSet(n.child(o).marks);)o++;let s=e.start(),c=s;for(let e=0;e<o;e++){let t=n.child(e).nodeSize;e<a&&(s+=t),c+=t}return{from:s,to:c,mark:r}}return null}function No(e,t){let{selection:n}=e;if(n.empty){let{parent:e}=n.$from;return e.inlineContent&&e.type.allowsMarkType(t)}let r=!1;for(let{from:i,to:a}of n.ranges)e.doc.nodesBetween(i,a,e=>(e.isTextblock&&e.type.allowsMarkType(t)&&(r=!0),!r));return r}function Po(e,t){return(n,r)=>{let i=jo(n),a=Ao(e),o=t??a,{selection:s}=n;if(!i||!o||!ue(a)||s instanceof Ma||!(s instanceof Ke)&&!No(n,i))return!1;let c=i.create({href:a});return F(n,r,e=>{let t=n.storedMarks??qe(s.$from);e.deleteSelection();let r=e.selection.from,a=e.doc.resolve(r).parent;if(!a.inlineContent||!a.type.allowsMarkType(i))throw new P(`No link here`);let l=t.filter(e=>a.type.allowsMarkType(e.type));e.insertText(o,r,r,c.addToSet(l)),Eo(e,n,r,r+o.length),e.setSelection(L.create(e.doc,r+o.length))})}}function Fo(e){return(t,n)=>{let r=jo(t),i=Ao(e);if(!r||!ue(i)||!No(t,r))return!1;let a=r.create({href:i}),{selection:o}=t;if(!o.empty)return F(t,n,e=>{for(let{from:n,to:r}of o.ranges)e.addMark(n,r,a),Eo(e,t,n,r)});let s=Mo(o.$from,r);return s?F(t,n,e=>e.addMark(s.from,s.to,a)):Po(i)(t,n)}}var Io=(e,t)=>{let n=jo(e);if(!n)return!1;let{selection:r}=e,i=r.empty&&Mo(r.$from,n),a=r.empty?i?[i]:[]:r.ranges;return a.length?F(e,t,t=>{for(let r of a)t.removeMark(r.from,r.to,n),Do(t,e,r.from,r.to)}):!1},Lo=`linkEditorRequest`,Ro=(e,t)=>{let n=jo(e);return!n||!No(e,n)?!1:(t?.(e.tr.setMeta(Lo,!0)),!0)},zo=new $e(`track`),Bo=`untracked`,Vo=`trackedDeletes`,Ho=new Set([`bookmarkStart`,`bookmarkEnd`,`commentStart`,`commentEnd`,`controlStart`,`controlEnd`]),Uo=new Set(Ut),Wo=new Set([`markFormat`,`ext`]),Go=Kt.filter(e=>!Wo.has(e)),Ko=e=>Object.fromEntries(Go.filter(t=>e[t]!=null).map(t=>[t,e[t]])),qo=(e,t)=>Go.every(n=>u(e[n]??null,t[n]??null));function Jo(e){return new et({key:zo,state:{init:()=>e,apply:(e,t)=>e.getMeta(zo)??t}})}function Yo(e){return zo.getState(e)??null}var Xo=(e,t)=>e.setMeta(zo,t);function Zo(e,t){return(n,r)=>{let i=zo.getState(n);return!i||!n.schema.marks.insertion?!1:(r?.(n.tr.setMeta(zo,{...i,on:e,author:t??i.author})),!0)}}function Qo(e){return(t,n)=>{let r=zo.getState(t);return!r||!t.schema.marks.insertion?!1:(n?.(t.tr.setMeta(zo,{...r,view:e})),!0)}}function $o(){return new Date().toISOString().replace(/\.\d+Z$/,`Z`)}var es=new Set([`insertion`,`deletion`,`formatChange`]);function ts(e){let t=-1,n=e=>{let n=e?.id;typeof n==`number`&&n>t&&(t=n)};return e.descendants(e=>{for(let t of e.marks)es.has(t.type.name)&&n(t.attrs);if(e.isTextblock){let t=e.attrs.revision;n(t?.insertion),n(t?.deletion),n(e.attrs.formatChange),n(e.attrs.section?.change)}return!0}),t}function ns(e){let t=X(e)?.envelope,n=t?.comments??[],r=t?.section,i=-1,a=e=>{let t=e?.id;typeof t==`number`&&t>i&&(i=t)};a(r?.change);for(let t of[e.doc,...di(e)])i=Math.max(i,ts(t));let o=e=>{if(Array.isArray(e))e.forEach(o);else if(e&&typeof e==`object`){let t=e;es.has(t.type)&&a(t.attrs),t.type===`paragraph`&&a(t.attrs?.formatChange);let n=t.revision;n&&typeof n==`object`&&(a(n.insertion),a(n.deletion)),Object.values(t).forEach(o)}};return o(n.map(e=>e.content)),i}function rs(e){return ns(e)+1}function is(e){let t=e.mapping.maps,n=[];t.forEach((r,i)=>{if(!r.ranges.length)return;let a=new ke(t.slice(0,i).map(e=>e.invert()).reverse()),o=e.mapping.slice(i+1);r.forEach((e,t,r,i)=>{let s=a.map(e,-1),c=o.map(r,-1);n.push({a:s,b:Math.max(s,a.map(t,1)),c,d:Math.max(c,o.map(i,1))})})}),n.sort((e,t)=>e.a-t.a);let r=[];for(let e of n){let t=r[r.length-1];t&&e.a<=t.b?(t.b=Math.max(t.b,e.b),t.c=Math.min(t.c,e.c),t.d=Math.max(t.d,e.d)):r.push({...e})}return r}function as(e,t){let n=zo.getState(e),{insertion:r,deletion:i}=e.schema.marks;if(!n?.on||!r||!i||!t.docChanged||t.getMeta(`untracked`)||t.getMeta(`historyOp`)||!t.addToHistory)return t;try{return os(e,t,n.author,r,i)}catch(e){if(e instanceof P)return null;throw e}}function os(e,t,n,r,i){let a=e.tr.copyMeta(t);a.setMeta(Vo,is(t).filter(e=>e.b>e.a).map(e=>[e.a,e.b]));let o=$o(),s=-1,c=()=>(s<0&&(s=Math.max(ns(e)+1,t.getMeta(`revisionFloor`)??0)),s++),l=(e,t)=>a.mapping.slice(e.step).map(e.pos,t),d=e=>({pos:e,step:a.steps.length}),f=[],p=[],m=[],h=[],g=(e,t,o)=>{let s=a.doc;for(let a of[s.resolve(t).nodeBefore,s.resolve(o).nodeAfter]){let t=a&&e.isInSet(a.marks),o=e===r?i:r;if(t&&t.attrs.author===n&&!o.isInSet(a.marks))return t}},_=e=>({id:e.attrs.id,author:n,date:e.attrs.date??o}),v=(e,t,s)=>{let u=a.doc,h=a.steps.length,v,y=()=>v??=g(i,e,t)??i.create({id:c(),author:n,date:o}),b=[],x=[],S=[],C=new Map,w=null,ee=!1,te=[];u.nodesBetween(e,t,(a,o)=>{if(a.isTextblock){let r=o+a.nodeSize,c=w??o,l=a.attrs.revision,m=e<r&&t>r||e<=o&&t>=r&&(s||!!u.resolve(r).nodeAfter);return m&&!l?.deletion&&l?.insertion?.author===n&&u.resolve(r).nodeAfter?.isTextblock?(b.push([r-1,r+1]),w===null&&(ee=!1,a.forEach((t,n)=>{!Ho.has(t.type.name)&&!i.isInSet(t.marks)&&o+1+n<e&&(ee=!0)})),w=c,!0):(w!==null&&te.push({at:d(w),node:a,live:ee}),w=null,m&&p.push(d(c)),m&&!l?.deletion&&f.push({at:d(c),kind:`deletion`,revision:_(y())}),!0)}if(a.type.name===`tableRow`&&e<=o&&t>=o+a.nodeSize){let e=a.attrs.revision;if(e?.insertion?.author===n&&!e.deletion){let e=u.resolve(o).before();C.set(e,[...C.get(e)??[],[o,o+a.nodeSize]])}else e?.deletion||S.push({pos:o,node:a});return!1}if([`table`,`tableRow`,`tableCell`].includes(a.type.name))return!0;if(!a.isInline)throw new P(`This content cannot be deleted as a tracked change`);let c=Math.max(o,e),l=Math.min(o+a.nodeSize,t);if(c>=l||Ho.has(a.type.name)||i.isInSet(a.marks))return!1;let m=r.isInSet(a.marks);return(m&&m.attrs.author===n?b:x).push([c,l]),!1});for(let[e,t]of C){let n=u.nodeAt(e);n&&t.length===n.childCount?b.push([e,e+n.nodeSize]):b.push(...t)}for(let[e,t]of ss(x))a.addMark(e,t,y());for(let{pos:e,node:t}of S){let n=t.attrs.revision??{},r=_(y());a.step(new Re(e,t.type,{...t.attrs,revision:{...n,deletion:r}},t.marks))}for(let[e,t]of ss(b).reverse())a.delete(e,t);for(let{at:e,node:t,live:r}of te){let i=l(e,1),s=a.doc.nodeAt(i);if(!s?.isTextblock)continue;if(!r){a.step(new Re(i,t.type,t.attrs,s.marks)),m.push(d(i));continue}let u={...s.attrs};for(let e of Je)u[e]=t.attrs[e]??null;let f=t.attrs.revision;!u.formatChange&&f?.insertion?.author!==n&&!qo(u,t.attrs)&&(u.formatChange={id:c(),author:n,date:o,previous:Ko(t.attrs)});let p=u.formatChange;p?.author===n&&qo(u,p.previous)&&(u.formatChange=null),a.step(new Re(i,s.type,u,s.marks)),m.push(d(i))}let T=a.mapping.slice(h);return{start:d(T.map(e,-1)),end:d(T.map(t,1))}},y=is(t),b=[];for(let s of[...y].reverse()){let l=t.doc.slice(s.c,s.d),u=l.content.firstChild,p=s.a===0&&s.b===e.doc.content.size&&!l.openStart&&l.content.childCount===1&&u?.isTextblock&&!u.content.size,{start:m,end:y}=s.a<s.b?v(s.a,s.b,l.size>0&&!p):{start:d(s.a),end:d(s.a)},x=null,S=y.pos;if(l.size&&!p){let e=a.doc.resolve(S).parent,t=g(r,S,S)??r.create({id:c(),author:n,date:o}),s=cs(l.content,t,r,i);a.replace(S,S,new w(s,l.openStart,l.openEnd)),x=d(S);let u=l.size,p=[];a.doc.nodesBetween(S,S+u,(e,n)=>{if(e.type.name===`tableRow`&&n>=S&&n+e.nodeSize<=S+u&&p.push(n),!e.isTextblock)return!e.isInline;let r=n+e.nodeSize-1;return r>=S&&r<S+u&&f.push({at:d(n),kind:`insertion`,revision:_(t)}),!1});for(let e of p){let n=a.doc.nodeAt(e);if(!n)continue;let r=n.attrs.revision??{};r.insertion||a.step(new Re(e,n.type,{...n.attrs,revision:{...r,insertion:_(t)}},n.marks))}let m=a.doc.resolve(S+u);l.openEnd&&e.isTextblock&&m.parent.isTextblock&&m.depth>0&&h.push({at:d(m.before()),host:e})}b.unshift({range:s,start:m,end:y,inserted:x})}let x=(e,t)=>{let n=0;for(let{range:r,start:i,end:a,inserted:o}of b){let{a:s,b:c,c:u,d}=r;if(e<u)break;if(e<=d)return o?l(o,-1)+(e-u):u===d&&t<0?l(i,-1):l(a,1);n+=d-u-(c-s)}return a.mapping.map(e-n,t)},S=e.schema.marks.formatChange,C=e=>r.isInSet(e.marks)?.attrs.author===n,ee=e=>{if(!S||!Uo.has(e.mark.type.name))return;let t=[];a.doc.nodesBetween(e.from,e.to,(n,r)=>{if(!n.isInline)return!0;if(Ho.has(n.type.name)||S.isInSet(n.marks)||C(n))return!1;let i=e.mark.isInSet(n.marks);if(e instanceof Ie?i:!i)return!1;let a=JSON.stringify(n.marks.filter(e=>Uo.has(e.type.name)).map(e=>e.toJSON())),o=Math.max(r,e.from),s=Math.min(r+n.nodeSize,e.to),c=t[t.length-1];return c&&c.to===o&&c.previous===a?c.to=s:t.push({from:o,to:s,previous:a}),!1});for(let{from:e,to:r,previous:i}of t){let t={id:c(),author:n,date:o,previous:JSON.parse(i)};a.addMark(e,r,S.create(t))}},te=e=>{let t=a.doc.nodeAt(e.pos),r=e.attrs;if(!t?.isTextblock||!r||t.type!==e.type||qo(t.attrs,r))return e;if(t.attrs.formatChange){if(u(r.formatChange??null,t.attrs.formatChange))return e;let n={...r,formatChange:t.attrs.formatChange};return new Re(e.pos,e.type,n,e.marks)}if(t.attrs.revision?.insertion?.author===n)return e;let i={id:c(),author:n,date:o,previous:Ko(t.attrs)};return new Re(e.pos,e.type,{...r,formatChange:i},e.marks)};t.steps.forEach((e,n)=>{if(e.getMap().ranges.length)return;let r=t.mapping.slice(n+1),i=e.map({map:(e,t=1)=>x(r.map(e,t),t),mapResult:(e,t=1)=>{let n=r.mapResult(e,t);return{pos:x(n.pos,t),deleted:n.deleted,recover:null}}}),o=new Set([...p,...m].map(e=>l(e,1)));if(i instanceof Re&&o.has(i.pos)&&(i=null),i instanceof Be){let e=i.steps.filter(e=>!o.has(e.pos));i=e.length?new Be(e):null}(i instanceof Ie||i instanceof Le)&&ee(i),i instanceof Re&&(i=te(i)),i instanceof Be&&(i=new Be(i.steps.map(te))),i&&a.step(i)});for(let{at:e,host:t}of h){let r=l(e,1),i=a.doc.nodeAt(r),s=i?.attrs.revision;if(!i?.isTextblock||i.attrs.formatChange||s?.insertion?.author===n||qo(i.attrs,t.attrs))continue;let u={id:c(),author:n,date:o,previous:Ko(t.attrs)};a.step(new Re(r,i.type,{...i.attrs,formatChange:u},i.marks))}let T=new Set;for(let{at:e,kind:t,revision:n}of f){let r=l(e,1),i=a.doc.nodeAt(r);if(!i?.isTextblock||T.has(r*2+ +(t===`insertion`)))continue;T.add(r*2+ +(t===`insertion`));let o=i.attrs.revision??{},s=t===`insertion`?{insertion:n}:{...o,deletion:n};a.step(new Re(r,i.type,{...i.attrs,revision:s}))}let ne=y.length===1?y[0]:void 0,E=e.selection.empty&&ne!==void 0&&ne.c===ne.d&&e.selection.head===ne.b?-1:1,D=t.selection,O=x(D.anchor,E),re=x(D.head,E);return D instanceof Ge&&a.doc.nodeAt(O)?.type===D.node.type?a.setSelection(Ge.create(a.doc,O)):D instanceof L?a.setSelection(L.create(a.doc,O,re)):D.toJSON().type===`cell`?a.setSelection(I.fromJSON(a.doc,{type:`cell`,anchor:O,head:re})):a.setSelection(I.near(a.doc.resolve(re))),t.storedMarks&&a.setStoredMarks(t.storedMarks.filter(e=>e.type!==r&&e.type!==i)),a}function ss(e){let t=[];for(let[n,r]of[...e].sort((e,t)=>e[0]-t[0])){let e=t[t.length-1];e&&n<=e[1]?e[1]=Math.max(e[1],r):t.push([n,r])}return t}function cs(e,t,n,r){let i=[];return e.forEach(e=>{if(e.isInline){if(Ho.has(e.type.name))i.push(e);else{let a=e.marks.filter(e=>e.type!==n&&e.type!==r);i.push(e.mark(t.addToSet(a)))}return}let a=[`table`,`tableRow`,`tableCell`].includes(e.type.name);if(!e.isTextblock&&!a)throw new P(`This content cannot be inserted as a tracked change`);i.push(e.copy(cs(e.content,t,n,r)))}),f.fromArray(i)}var ls={width:12240,height:15840,margin:1440},us=720;function ds(e){let{columns:t={}}=e,n=t.separator===!0,r=t.space??us,i=t.equalWidth===!1?t.widths:void 0;if(i?.length)return{widths:i.map(e=>e.width),gaps:i.slice(0,-1).map(e=>e.space??r),separator:n};let a=Math.max(t.count??1,1),o=Math.max((fs(e)-r*(a-1))/a,1);return{widths:Array.from({length:a},()=>o),gaps:Array.from({length:a-1},()=>r),separator:n}}function fs({pageSize:e,margins:t={}}){return(e?.width??ls.width)-(t.left??ls.margin)-(t.right??ls.margin)-(t.gutter??0)}function ps(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0))}function ms(e,t){let n=null;return e.forEach((e,r)=>{!n&&r+e.nodeSize>t&&e.attrs.section&&(n={pos:r,node:e})}),n}function hs(e,t){let n=X(e)?.envelope.section??{};for(let e of t.steps)e instanceof ei&&e.key===`section`&&(n=e.after);return n}function gs(e,t,n,r){n?t.setNodeMarkup(n.pos,n.node.type,{...n.node.attrs,section:r}):ai(e,t,`section`,r)}function _s(e,t,n,r){let i=ms(t.doc,r),a=i?i.node.attrs.section:hs(e,t),o=(e,t)=>e||t?{...t,...e}:void 0;gs(e,t,i,ps({...a,type:n.type,headers:o(a.headers,n.headers),footers:o(a.footers,n.footers)}))}var vs={header:`headers`,footer:`footers`};function ys(e,t,n,r){for(let i=Math.min(t,e.length-1);i>=0;i--){let t=e[i]?.[vs[n]]?.[r];if(t)return{id:t,section:i}}return null}function bs(e,t,n){return e.titlePage&&t.first?`first`:n&&t.number%2==0?`even`:`default`}function xs(e,t){let{change:n,...r}=e;return t||!n?r:ps({...n.previous,headers:e.headers,footers:e.footers,ext:e.ext})}var Ss=`
|
|
3
|
+
`,Cs=new Intl.Segmenter(void 0,{granularity:`grapheme`}),ws=new Intl.Segmenter(void 0,{granularity:`word`});function Ts(e,t){return t===e.selection.head?e:e.apply(e.tr.setSelection(L.create(e.doc,t)))}function Es(e){let{selection:t}=e;return t.empty&&t instanceof L?t.$head:null}var Ds=(e,t)=>!e.selection.empty&&F(e,t,e=>Os(e));function Os(e,t=!1){let n=e.selection;if(n instanceof Ma){let r=n.anchor;Ca(e,t?[r]:n.cells),e.setSelection(I.near(e.doc.resolve(e.mapping.map(r,1)+1),1));return}let{from:r,to:i}=n;ba(e,r,i)?e.setSelection(I.near(e.doc.resolve(e.mapping.map(r,-1)),1)):e.deleteSelection(),wa(e)}function ks(e){return(t,n)=>{if(!e)return!1;let{selection:r}=t;return Vs(t)?Hs(t,n,t.schema.text(e,t.storedMarks??[])):!(r instanceof Ke)&&!(r instanceof Ma)&&!r.$from.parent.inlineContent?!1:F(t,n,n=>{let i=r instanceof Ma?I.near(t.doc.resolve(r.anchor+1),1).$from:r.$from,a=t.storedMarks??(r.empty?qe(i):i.nodeAfter?.marks??qe(i));r.empty||Os(n,!0);let o=n.selection.$from;if(!o.parent.inlineContent)throw new P(`No text where the selection was`);let s=Qe(a).filter(e=>o.parent.type.allowsMarkType(e.type));n.insertText(e,o.pos,o.pos,s),n.setSelection(L.create(n.doc,o.pos+e.length))})}}function As(e,t,n=!1){let r=0;if(n&&t===`word`&&e.parent.forEach((t,n)=>{!t.isText&&n<e.parentOffset&&(r=n+t.nodeSize)}),r===e.parentOffset&&r>0)return 1;let i=e.parent.textBetween(r,e.parentOffset,``,Ss);if(t===`char`)return[...Cs.segment(i)].pop()?.segment.length??0;let a=[...ws.segment(i)],o=0;for(;a.length&&!a[a.length-1]?.isWordLike;)o+=a.pop()?.segment.length??0;return o+(a.pop()?.segment.length??0)}function js(e,t,n=!1){let r=e.parent.content.size;if(n&&t===`word`&&e.parent.forEach((t,n)=>{!t.isText&&n>=e.parentOffset&&n<r&&(r=n)}),r===e.parentOffset&&r<e.parent.content.size)return 1;let i=e.parent.textBetween(e.parentOffset,r,``,Ss),a=[...(t===`char`?Cs:ws).segment(i)];if(t===`char`)return a[0]?.segment.length??0;let o=0;for(;a.length&&!a[0]?.isWordLike;)o+=a.shift()?.segment.length??0;return o+(a.shift()?.segment.length??0)}function Ms(e){let t=Yo(e);return t?.on===!0||(t?.view??`markup`)!==`markup`}var Ns=e=>e.marks.some(e=>e.type.name===`deletion`);function Ps(e,t,n,r){if(!zi(n))return!1;let i=Ri(e.doc,r);return!i||i.deleted?!1:(t?.(e.tr.setSelection(Qi(e.doc,i))),!0)}function Fs(e=`char`){return(t,n)=>{if(!t.selection.empty)return Ds(t,n);let r=Es(t);if(!r)return!1;let i=X(t),a=Ms(t),o=r;for(;o.parentOffset>0;){let e=o.nodeBefore;if(a&&e&&Ns(e))o=t.doc.resolve(o.pos-e.nodeSize);else if(Ps(t,n,e,o.pos-1))return!0;else if(Ai(i,e))o=t.doc.resolve(o.pos-1);else break}if(o.parentOffset===0)return Rs(Ts(t,o.pos),n);if(Mi(i,o.nodeBefore)){let e=o.nodeBefore;return n?.(t.tr.setSelection(Ni(t,o.pos-e.nodeSize))),!0}let s=As(o,e,i!==null);return F(t,n,e=>e.delete(o.pos-s,o.pos))}}function Is(e=`char`){return(t,n)=>{if(!t.selection.empty)return Ds(t,n);let r=Es(t);if(!r)return!1;let i=X(t),a=Ms(t),o=r;for(;o.parentOffset<o.parent.content.size;){let e=o.nodeAfter;if(a&&e&&Ns(e))o=t.doc.resolve(o.pos+e.nodeSize);else if(Ps(t,n,e,o.pos))return!0;else if(Ai(i,e))o=t.doc.resolve(o.pos+1);else break}if(o.parentOffset===o.parent.content.size)return zs(Ts(t,o.pos),n);if(Mi(i,o.nodeAfter))return n?.(t.tr.setSelection(Ni(t,o.pos))),!0;let s=js(o,e,i!==null);return F(t,n,e=>e.delete(o.pos,o.pos+s))}}function Ls(e,t,n,r){let i=n.attrs.section;i&&!Yo(e)?.on&&_s(e,t,i,r)}var Rs=(e,t)=>{let n=Es(e);if(!n?.parent.isTextblock||n.parentOffset>0||n.depth<1)return!1;let r=n.index(n.depth-1);if(r===0)return!1;let i=n.node(n.depth-1).child(r-1),a=n.before();return i.isTextblock?F(e,t,t=>{t.join(a),Xe(t,a-i.nodeSize,n.parent),Ls(e,t,i,a-i.nodeSize)}):i.type.name===`table`?(t?.(e.tr.setSelection(I.near(e.doc.resolve(a-1),-1))),!0):Mi(X(e),i)?(t?.(e.tr.setSelection(Ni(e,a-i.nodeSize))),!0):!1},zs=(e,t)=>{let n=Es(e);if(!n?.parent.isTextblock||n.parentOffset<n.parent.content.size||n.depth<1)return!1;let r=n.node(n.depth-1).maybeChild(n.index(n.depth-1)+1);if(!r)return!1;let i=n.after();return r.isTextblock?F(e,t,t=>{t.join(i),Xe(t,n.before(),r),Ls(e,t,n.parent,n.before())}):r.type.name===`table`?(t?.(e.tr.setSelection(I.near(e.doc.resolve(i+1),1))),!0):Mi(X(e),r)?(t?.(e.tr.setSelection(Ni(e,i))),!0):!1},Bs=(e,t)=>{let{selection:n}=e;return Vs(e)?F(e,t,t=>{t.insert(n.to,nt(e.schema).create()),t.setSelection(L.create(t.doc,n.to+1))}):!(n instanceof Ke)&&!n.$from.parent.isTextblock?!1:F(e,t,t=>{let r=e.storedMarks??qe(n.$from);if(n.empty||Os(t),!t.selection.$from.parent.inlineContent)throw new P(`No text where the selection was`);let i=t.selection.$from,a=i.parentOffset===i.parent.content.size,o=X(e);if(o&&i.parent.type.name===`paragraph`){let{before:e,after:n}=bi(o,i.parent,a);t.split(i.pos,1,[{type:i.parent.type,attrs:n}]),e&&t.setNodeMarkup(i.before(),i.parent.type,e)}else{let n=nt(e.schema);t.split(i.pos,1,a&&i.parent.type!==n?[{type:n}]:void 0)}t.setSelection(L.create(t.doc,i.pos+2)),r.length&&t.setStoredMarks(r)})};function Vs(e){let{selection:t}=e;return t instanceof Ge&&t.node.isBlock?t.node:null}function Hs(e,t,n){let{from:r,to:i}=e.selection,a=nt(e.schema).create(null,n);return F(e,t,e=>{e.replace(r,i,new w(f.from(a),0,0)),e.setSelection(L.create(e.doc,r+1+n.nodeSize))})}function Us(e,t,n){let r=e.resolve(t);for(;;){let t=n<0?r.nodeBefore:r.nodeAfter;if(t){let e=n<0?r.pos-t.nodeSize:r.pos;for(;!t.isTextblock&&!t.isLeaf;){let r=n<0?t.lastChild:t.firstChild;if(!r)return null;e=n<0?e+t.nodeSize-1-r.nodeSize:e+1,t=r}return{node:t,pos:e}}if(r.depth===0)return null;r=e.resolve(n<0?r.before():r.after())}}function Ws(e,t){return(n,r)=>{let{selection:i,doc:a}=n;if(Vs(n)){let t=Us(a,e<0?i.from:i.to,e);if(!t)return!0;let o=t.node.isTextblock?L.create(a,e<0?t.pos+t.node.nodeSize-1:t.pos+1):Ge.isSelectable(t.node)?Ge.create(a,t.pos):I.near(a.resolve(t.pos),e);return r?.(n.tr.setSelection(o)),!0}if(t===`none`||!i.empty||!(i instanceof L))return!1;let{$from:o}=i;if(!o.parent.isTextblock||o.depth<1)return!1;let s=e<0?o.parentOffset===0:o.parentOffset===o.parent.content.size;if(t===`char`&&!s)return!1;let c=Us(a,e<0?o.before():o.after(),e);return!c||c.node.isTextblock||!Ge.isSelectable(c.node)?!1:(r?.(n.tr.setSelection(Ge.create(a,c.pos))),!0)}}var Gs=(e,t)=>Js(`tab`,e,t),Ks=(e,t)=>Js(`hardBreak`,e,t),qs=(e,t)=>Js(`pageBreak`,e,t);function Js(e,...[t,n]){let r=t.schema.nodes[e],{selection:i}=t;return!r||!(i instanceof Ke)&&!i.$from.parent.inlineContent?!1:F(t,n,e=>{let n=t.storedMarks??qe(i.$from);if(i.empty||Os(e),!e.selection.$from.parent.inlineContent)throw new P(`No text where the selection was`);let a=e.selection.from;e.insert(a,r.create(null,null,Qe(n).filter(t=>e.doc.resolve(a).parent.type.allowsMarkType(t.type)))),e.setSelection(L.create(e.doc,a+1))})}var Ys=(e,t)=>(t?.(e.tr.setSelection(new Ke(e.doc))),!0);function Xs(e,t){return typeof t==`string`?e.schema.marks[t]:t}function Zs(e,t){let n=!0,r=!1;for(let{from:i,to:a}of e.selection.ranges)e.doc.nodesBetween(i,a,(e,i,a)=>{if(n&&e.isInline&&a?.type.allowsMarkType(t))return r=!0,t.isInSet(e.marks)||(n=!1),!1});return r&&n}function Qs(e,t){return(n,r)=>{let i=Xs(n,e);if(!i)return!1;let{selection:a}=n,o=Es(n);if(o){if(!o.parent.type.allowsMarkType(i))return!1;let e=n.storedMarks??qe(o),a=X(n);if(a&&Si(a,i))return r?.(n.tr.setStoredMarks(Di(a,o.parent,e,i))),!0;let s=i.isInSet(e),c=s?null:$s(i,t);return!s&&!c?!1:(r?.(n.tr.setStoredMarks(s?s.removeFromSet(e):c.addToSet(e))),!0)}let{ranges:s}=a,c=!1;for(let{from:e,to:t}of s)n.doc.nodesBetween(e,t,e=>(e.isTextblock&&e.type.allowsMarkType(i)&&(c=!0),!c));if(!c)return!1;let l=X(n);if(l&&Si(l,i)){let e=!Ei(l,n,i,null);return F(n,r,t=>{for(let{from:r,to:a}of s)for(let o of Oi(l,n,r,a,i,e))t.removeMark(o.from,o.to,i),o.mark&&t.addMark(o.from,o.to,o.mark)})}let u=Zs(n,i),d=u?null:$s(i,t);return!u&&!d?!1:F(n,r,e=>{for(let{from:t,to:n}of s)u?e.removeMark(t,n,i):e.addMark(t,n,d)})}}function $s(e,t){if(e.name===`link`&&!de(t))return null;try{return e.create(t)}catch(e){if(e instanceof i)return null;throw e}}function ec(e,t){let n=Xs(e,t);if(!n)return!1;let r=Es(e),i=X(e);return i&&Si(i,n)?Ei(i,e,n,r?e.storedMarks??qe(r):null):r?n.isInSet(e.storedMarks??qe(r))!==void 0:Zs(e,n)}function tc(e,t=null){return(n,r)=>{let i=X(n);if(!i)return!1;let a=typeof e==`string`?e:e.name;if(a===`heading`)return Ka(`heading ${String(t?.level??1)}`)(n,r);let o=a===`paragraph`?Va(i):null;return o!==null&&Ga(o)(n,r)}}function nc(){return new et({keymap:{Enter:Bs,"Shift-Enter":Ks,"Mod-Enter":qs,Tab:Gs,Backspace:Fs(),Delete:Is(),"Mod-b":Qs(`bold`),"Mod-i":Qs(`italic`),"Mod-u":Qs(`underline`),"Mod-k":Ro,"Mod-a":Ys,ArrowLeft:Ws(-1,`char`),ArrowRight:Ws(1,`char`),ArrowUp:Ws(-1,`none`),ArrowDown:Ws(1,`none`),"Mod-z":ha,"Mod-Shift-z":ga,"Mod-y":ga}})}var rc=new Set([`commentStart`,`commentEnd`,`commentReference`]);function ic(e){return typeof e==`string`?e.split(/\r\n|\r|\n/).map(e=>e?{type:`paragraph`,content:[{type:`text`,text:e}]}:{type:`paragraph`}):structuredClone([...e])}var ac=9,oc=e=>e.initials===void 0?{}:{initials:e.initials.slice(0,ac)};function sc(e){let t=new Set;return e.descendants(e=>{if(e.type.name===`opaqueBlock`||e.type.name===`opaqueInline`)for(let[,n]of String(e.attrs.xml).matchAll(/<\w+:comment(?:RangeStart|RangeEnd|Reference)\b[^>]*?\b\w+:id="(\d+)"/g))t.add(Number(n));return e.isBlock}),t}function cc(e,t){let n=-1;for(let e of t)n=Math.max(n,e.id);e.descendants(e=>(rc.has(e.type.name)&&(n=Math.max(n,e.attrs.id)),e.isBlock));for(let t of sc(e))n=Math.max(n,t);return n+1}function lc(e,t){let n=e.find(e=>e.id===t),r=new Set;for(;n?.parent!==void 0&&!r.has(n.id);){r.add(n.id);let t=n.parent;n=e.find(e=>e.id===t)}return n}function uc(e){let t=new Map;return e.descendants((e,n)=>{if(!rc.has(e.type.name))return e.isBlock;let r=e.attrs.id,i=t.get(r)??{};return e.type.name===`commentStart`?i.start??=n:e.type.name===`commentEnd`?i.end??=n:i.reference??=n,t.set(r,i),!1}),t}var dc=e=>e.tr.setMeta(Bo,!0).setMeta(ta,!0),fc=(e,t)=>t.author??Yo(e)?.author??`Author`;function pc(e,t={}){return(n,r)=>{let i=X(n),{schema:a}=n,o={start:a.nodes.commentStart,end:a.nodes.commentEnd,reference:a.nodes.commentReference};if(!i||li(n)||!o.start||!o.end||!o.reference)return!1;let s=n.selection instanceof Ke,c=s?I.atStart(n.doc).$from:n.selection.$from,l=s?I.atEnd(n.doc).$to:n.selection.$to;if(!c.parent.inlineContent||!l.parent.inlineContent)return!1;if(r){let a=i.envelope.comments,s=cc(n.doc,a),u=dc(n);u.insert(l.pos,[o.end.create({id:s}),o.reference.create({id:s})]),u.insert(c.pos,o.start.create({id:s})),u.setSelection(L.create(u.doc,c.pos+1,l.pos+1));let d={id:s,author:fc(n,t),...oc(t),date:$o(),content:ic(e)};$r(u,a,[...a,d]),r(u)}return!0}}function mc(e,t,n={}){return(r,i)=>{let a=X(r),{schema:o}=r,s=a?.envelope.comments??[],c=lc(s,e),l=uc(r.doc),u=c&&l.get(c.id),{commentStart:d,commentEnd:f,commentReference:p}=o.nodes;if(!a||!c||!u||!d||!f||!p)return!1;if(i){let e=cc(r.doc,s),a=dc(r),o=vc(s,c.id),u=e=>Math.max(...[...o].map(t=>l.get(t)?.[e]??-1)),m=u(`start`),h=u(`reference`);h>=0&&a.insert(h+1,[f.create({id:e}),p.create({id:e})]),m>=0&&a.insert(m+1,d.create({id:e}));let g={id:e,author:fc(r,n),...oc(n),date:$o(),content:ic(t),parent:c.id};$r(a,s,[...s,g]),i(a)}return!0}}function hc(e,t){return(n,r)=>{let i=X(n)?.envelope.comments,a=i?.find(t=>t.id===e);if(!i||!a)return!1;if(r){let e=i.flatMap(e=>e===a?t(e,i):[e]);r($r(dc(n),i,e))}return!0}}var gc=(e,t)=>hc(e,e=>[{...e,content:ic(t)}]);function _c(e,t=!0){return(n,r)=>{let i=X(n)?.envelope.comments??[],a=lc(i,e);if(!a)return!1;if(r){let e=vc(i,a.id),o=i.map(n=>{if(!e.has(n.id))return n;let{done:r,...i}=n;return t?{...i,done:!0}:i});r($r(dc(n),i,o))}return!0}}function vc(e,t){let n=new Set([t]);for(let t=!0;t;){t=!1;for(let r of e)r.parent!==void 0&&n.has(r.parent)&&!n.has(r.id)&&(n.add(r.id),t=!0)}return n}function yc(e,t,n){let r=[];e.doc.descendants((e,t)=>(rc.has(e.type.name)&&n.has(e.attrs.id)&&r.push(t),e.isBlock));for(let t of r.reverse())e.delete(t,t+1);$r(e,t,t.filter(e=>!n.has(e.id)))}function bc(e){let t=(n,r)=>{let i=li(n);if(i)return r?i.run(t):i.can(t);let a=X(n)?.envelope.comments??[],o=vc(a,e),s=sc(n.doc);if(!a.some(t=>t.id===e)||[...o].some(e=>s.has(e)))return!1;if(r){let e=dc(n);yc(e,a,o),r(e)}return!0};return t}var xc=(e,t)=>{let n=li(e);if(n)return t?n.run(xc):n.can(xc);let r=X(e)?.envelope.comments??[],i=sc(e.doc),a=new Set;for(let e of r){let t=lc(r,e.id);if(t&&i.has(t.id))for(let e of vc(r,t.id))a.add(e);i.has(e.id)&&a.add(e.id)}let o=new Set(r.map(e=>e.id).filter(e=>!a.has(e)));if(!o.size)return!1;if(t){let n=dc(e);yc(n,r,o),t(n)}return!0},Sc=new $e(`comments`);function Cc(e){return e.steps.some((t,n)=>{let r=!1;return t.getMap().forEach((t,i)=>{t<i&&e.docs[n].nodesBetween(t,i,e=>(e.type.name===`commentReference`&&(r=!0),!r))}),r})}function wc(){return new et({key:Sc,appendTransaction(e,t,n){let r=X(n)?.envelope.comments;if(!r?.length||!e.some(Cc))return null;let i=uc(t.doc),a=uc(n.doc),o=new Set;for(let[e,t]of i)if(t.reference!==void 0&&a.get(e)?.reference===void 0)for(let t of vc(r,e))o.add(t);let s=[...o].filter(e=>r.some(t=>t.id===e));if(!s.length)return null;let c=n.tr.setMeta(Bo,!0);return yc(c,r,new Set(s)),c}})}var Tc={SEQ:`rs`,TOC:`abcdflnopst`,MERGEFIELD:`bf`,REF:`d`},Ec=`*@#`;function Dc(e){let t=[],n=0;for(;n<e.length;)if(/\s/.test(e[n]))n++;else if(e[n]===`"`){let r=``;for(n++;n<e.length&&e[n]!==`"`;n++)e[n]===`\\`&&(e[n+1]===`"`||e[n+1]===`\\`)&&n++,r+=e[n];n++,t.push({value:r,quoted:!0})}else{let r=n;for(;n<e.length&&!/[\s"]/.test(e[n]);)n++;t.push({value:e.slice(r,n),quoted:!1})}return t}function Oc(e){let t=Dc(e),n=(t[0]?.value??``).toUpperCase(),r=Ec+(Tc[n]??``),i=[],a=new Map;for(let e=1;e<t.length;e++){let{value:n,quoted:o}=t[e];if(o||!n.startsWith(`\\`)||n.length<2){i.push(n);continue}let s=n[1].toLowerCase(),c=n.slice(2),l=t[e+1];!c&&r.includes(s)&&l&&(l.quoted||l.value[0]!==`\\`)&&(c=l.value,e++),a.set(s,[...a.get(s)??[],c])}return{name:n,args:i,switches:a}}var kc=`January February March April May June July August September October November December`.split(` `),Ac=`Sunday Monday Tuesday Wednesday Thursday Friday Saturday`.split(` `),jc=(e,t=2)=>String(e).padStart(t,`0`);function Mc(e,t){let n=e.getHours()%12||12,r={d:String(e.getDate()),dd:jc(e.getDate()),ddd:Ac[e.getDay()].slice(0,3),dddd:Ac[e.getDay()],M:String(e.getMonth()+1),MM:jc(e.getMonth()+1),MMM:kc[e.getMonth()].slice(0,3),MMMM:kc[e.getMonth()],yy:jc(e.getFullYear()%100),yyyy:String(e.getFullYear()),h:String(n),hh:jc(n),H:String(e.getHours()),HH:jc(e.getHours()),m:String(e.getMinutes()),mm:jc(e.getMinutes()),s:String(e.getSeconds()),ss:jc(e.getSeconds())},i=e.getHours()<12;return t.replace(/'([^']*)'|AM\/PM|am\/pm|A\/P|a\/p|d+|M+|y+|h+|H+|m+|s+/g,(e,t)=>t===void 0?e.includes(`/`)?i?e.split(`/`)[0]:e.split(`/`)[1]:r[e]??e:t)}function Nc(e,t){let n=[``],r=!1;for(let e of t)e===`'`&&(r=!r),e===`;`&&!r?n.push(``):n[n.length-1]+=e;let i=e<0&&n[1]!==void 0,a=e===0&&n[2]!==void 0,o=i?n[1]:a?n[2]:n[0],s=[],c=[],l=[],u=[],d=!1,f=!1;r=!1;for(let e of o)if(e===`'`)r=!r;else if(r)s.push(e);else if(e==="`")return null;else if(e===`0`||e===`#`||e===`x`)(d?l:c).push({at:s.length,slot:e}),s.push(``);else if(e===`.`){if(d)return null;d=!0,s.push(`.`)}else if(e===`,`){if(d)return null;f=!0}else e===`+`||e===`-`?(u.push({at:s.length,sign:e}),s.push(``)):s.push(e);let p=Math.abs(e);if(!Number.isFinite(p)||p>=1e21)return null;let[m=``,h=``]=p.toFixed(Math.min(l.length,100)).split(`.`),g=h.padEnd(l.length,`0`),_=m===`0`?``:m,v=!_&&!/[1-9]/.test(g),y=_.length-1,b=0,x=e=>f&&b>0&&b%3==0&&e!==` `?`${e},`:e;for(let e=c.length-1;e>=0;e--,b++){let{at:t,slot:n}=c[e];s[t]=x(y>=0?_[y--]:n===`0`?`0`:` `)}let S=c[0],C=y>=0&&S?.slot===`x`;if(S&&S.slot!==`x`)for(;y>=0;y--,b++)s[S.at]=x(_[y])+s[S.at];l.forEach(({at:e,slot:t},n)=>{let r=g.slice(n),i=r[0];t===`0`||/[1-9]/.test(r)?s[e]=i:v&&n===0?s[e]=`0`:s[e]=t===`#`?` `:``});for(let{at:t,sign:n}of u)s[t]=v?` `:e<0?`-`:n===`+`?`+`:` `;if(e<0&&!i&&!v&&!u.length&&!C){let e=c.find(({slot:e})=>e!==`x`);e&&(s[e.at]=`-${s[e.at]}`)}return s.join(``)}var Pc={ROMAN:`upperRoman`,roman:`lowerRoman`,ALPHABETIC:`upperLetter`,alphabetic:`lowerLetter`},Fc={arabic:`decimal`,arabicdash:`numberInDash`,ordinal:`ordinal`},Ic={upper:e=>e.toUpperCase(),lower:e=>e.toLowerCase(),firstcap:e=>e.charAt(0).toUpperCase()+e.slice(1),caps:e=>e.replace(/(^|\s)(\S)/g,(e,t,n)=>t+n.toUpperCase())},Lc=new Set([`mergeformat`,`charformat`]);function Rc(e,t,n){let r=typeof e==`number`?e:Number(e.trim().replace(/,/g,``)),i=String(e).trim()!==``&&Number.isFinite(r)?r:null,a=t.switches.get(`#`)?.[0],o=n,s=!1,c=[];for(let e of t.switches.get(`*`)??[]){let t=e.toLowerCase();if(Lc.has(t))continue;let n=Pc[e]??Fc[t];if(n)o=n;else if(t===`hex`)s=!0;else if(Ic[t])c.push(Ic[t]);else return null}let l=String(e);if(i!==null&&a!==void 0){let e=Nc(i,a);if(e===null)return null;l=e}else i!==null&&s?l=i.toString(16).toUpperCase():i!==null&&(o||typeof e==`number`)&&(l=Ir(i,o));for(let e of c)l=e(l);return l}var zc=()=>({updated:0,unchanged:0,rebuilt:0,skipped:[]}),Bc=new WeakMap;function Vc(e){let t=Bc.get(e);if(t)return t;let n=new Map,r=new Map;return e.descendants((e,t)=>{if(e.type.name===`bookmarkStart`)n.set(e.attrs.id,{name:String(e.attrs.name),from:t+1});else if(e.type.name===`bookmarkEnd`){let i=n.get(e.attrs.id),a=i?.name.toLowerCase();i&&a!==void 0&&!r.has(a)&&r.set(a,{...i,to:t})}return!e.isInline}),Bc.set(e,r),r}var Hc=(e,t)=>Vc(e).get(t.toLowerCase());function Uc(e,t){let n=Vc(e),r=2e8;for(let{name:e}of n.values()){let i=e.toLowerCase().startsWith(t.toLowerCase())?Number(e.slice(t.length)):0;Number.isSafeInteger(i+1+n.size)&&(r=Math.max(r,i))}return()=>{let e;do e=`${t}${++r}`;while(n.has(e.toLowerCase()));return e}}var Wc=new WeakMap;function Gc(e,t){let n=Wc.get(e);if(!n){n=[];for(let{from:t,codeEnd:r}of Ii(e)){let e=n[n.length-1];e&&t<e[1]?e[1]=Math.max(e[1],r):n.push([t,r])}Wc.set(e,n)}let r=0,i=n.length;for(;r<i;){let e=r+i>>1;n[e][1]<=t?r=e+1:i=e}let a=n[r];return!!a&&a[0]<=t}function Kc(e){let t=[];return e.descendants((e,n)=>(e.type.name===`paragraph`&&t.push({node:e,pos:n}),!e.isTextblock)),t}var qc=new Set([`insertion`,`deletion`,`formatChange`]),Jc=e=>e.filter(e=>!qc.has(e.type.name)),Yc=e=>e.marks.some(e=>e.type.name===`deletion`);function Xc(e,t,n){let r=e.nodes,i=[];for(let a of t.split(/(\t|\r\n|\r|\n)/))a&&(a===` `?i.push(r.tab.create(null,null,n)):/^[\r\n]/.test(a)?i.push(r.hardBreak.create(null,null,n)):i.push(e.text(a,n)));return i}function Zc(e,t){return Jc(((t.switches.get(`*`)??[]).some(e=>e.toLowerCase()===`mergeformat`)?e.resultMarks:null)??e.codeMarks??[])}function Qc(e,t){let n=e.type.schema,r=[],i=n.nodes.hardBreak,a=null;return e.nodesBetween(t.from,t.to,(n,o,s)=>{if(!n.isInline)return!0;if(a&&s!==a&&r.push(i.create()),a=s,Yc(n)||Gc(e,o))return!1;if(n.isText){let e=Math.max(t.from-o,0),i=Math.min(t.to-o,n.nodeSize);i>e&&r.push(n.cut(e,i).mark($c(n.marks)))}else[`tab`,`hardBreak`,`picture`].includes(n.type.name)&&r.push(n.mark($c(n.marks)));return!1}),r}var $c=e=>Jc(e).filter(e=>e.type.name!==`link`),el=class{paragraphs;markers;lists=new Map;constructor(e,t){this.paragraphs=Kc(e),this.markers=t.resolver.markers(this.paragraphs.map(e=>e.node.attrs)),this.markers.forEach((e,t)=>{if(!e)return;let n=this.lists.get(e.instance);n?n.push(t):this.lists.set(e.instance,[t])})}lastOfList(e,t){let n=this.lists.get(e)??[],r=0,i=n.length;for(;r<i;){let e=r+i>>1;n[e]<=t?r=e+1:i=e}return n[r-1]??-1}indexAt(e){let t=0,n=this.paragraphs.length;for(;t<n;){let r=t+n>>1;this.paragraphs[r].pos<=e?t=r+1:n=r}let r=this.paragraphs[t-1];return r&&e<=r.pos+r.node.nodeSize?t-1:-1}marker(e){return this.markers[this.indexAt(e)]??null}chain(e){let t=[e],n=this.markers[e]?.level??0,r=this.markers[e]?.abstract;for(let i=e-1;i>=0&&n>0;i--){let e=this.markers[i];e?.abstract===r&&e&&e.level<n&&(t.unshift(i),n=e.level)}return t}number(e,t,n,r){let i=this.indexAt(e),a=this.markers[i];if(!a)return`0`;let o=e=>{let t=this.markers[e];return r?t.plain:t.text},s=t===`n`?[i]:this.chain(i);if(t===`r`){let e=this.lastOfList(a.instance,this.indexAt(n)),t=e<0?[]:this.chain(e),r=0;for(;r<s.length-1&&s[r]===t[r];)r++;s=s.slice(r)}let c=[];for(let e of s){let t=o(e),n=c[c.length-1]?.replace(/\.+$/,``);n&&t.startsWith(n)&&!/^\w/.test(t.slice(n.length))?c[c.length-1]=t:c.push(t)}return c.join(``).replace(/\.+$/,``)}},tl=new Set([`PAGE`,`NUMPAGES`,`SECTIONPAGES`]),nl=new Set([...tl,`DATE`,`TIME`,`SEQ`,`MERGEFIELD`]),rl={PAGE:``,NUMPAGES:``,SECTIONPAGES:``,DATE:``,TIME:``,SEQ:`cnrsh`,MERGEFIELD:`bf`,REF:`hnrwpt`,PAGEREF:`hp`,TOC:`ohzutnbpwx`};function il(e,t){let n=t;for(let t=e.mapping.maps.length-1;t>=0;t--)n=e.mapping.maps[t].invert().map(n,1);return n}var Z=(e,t,n,r)=>{e.report.skipped.push({instruction:t.instruction,story:e.story,reason:n,...r?{detail:r}:{}})};function al(e,t,n){let{layout:r}=e.options;if(!r)return Z(e,t,`no-layout`),null;let i=r.pageAt(il(e.bodyTr,n));return i||Z(e,t,`no-layout`),i}function ol(e,t){return Kc(e).flatMap(({node:e,pos:n})=>{let r=sl(t,e);return r===null?[]:[{pos:n,level:r}]})}function sl(e,t){let n=e.resolver.paragraph(t.attrs).paragraph.style,r=e.envelope.styles.find(e=>e.id===n)?.name??``,i=/^heading ([1-9])$/i.exec(r);return i?Number(i[1]):null}function cl(e,t){let n=e.tr.doc,r=new Map,i=new Map,a=new Map,o=ol(n,e.word);for(let e of t){if(e.name!==`SEQ`||e.deleted)continue;let{args:t,switches:s}=Oc(e.instruction),c=(t[0]??``).toLowerCase(),l=a.get(c)??[];a.set(c,l);let u=i.get(c)??0,d=Number(s.get(`s`)?.[0]),f=l[l.length-1]?.pos??0;d&&o.some(t=>t.pos>=f&&t.pos<e.from&&t.level<=d)&&(u=0);let p=t[1]?Hc(n,t[1]):void 0,m=[...s.keys()].find(e=>`cnr`.includes(e)),h=Number(s.get(`r`)?.[0]);p?u=[...l].reverse().find(e=>e.pos<p.from)?.value??0:m===`r`&&Number.isFinite(h)?u=h:m!==`c`&&u++,p||i.set(c,u),l.push({pos:e.from,value:u}),r.set(e,u)}return r}var ll=(e,t)=>{if(Object.hasOwn(e,t))return{found:!0,value:e[t]};let n=t.toLowerCase(),r=Object.keys(e).find(e=>e.toLowerCase()===n);return r===void 0?{found:!1,value:void 0}:{found:!0,value:e[r]}},ul=(e,t)=>e.from<t.from?`below`:`above`;function dl(e,t){let n=Hc(e.tr.doc,t);if(n)return{mark:n,tree:e.tr.doc,inBody:e.story===null};let r=e.story===null?void 0:Hc(e.bodyTr.doc,t);return r?{mark:r,tree:e.bodyTr.doc,inBody:!0}:null}function fl(e,t){let{name:n,args:r,switches:i}=Oc(t.instruction);if(nl.has(n)||n===`PAGEREF`||n===`TOC`||i.has(`n`)||i.has(`r`)||i.has(`w`)||i.has(`p`))return;let a=n===`REF`?r[0]:Dc(t.instruction)[0]?.value;return a?Hc(e,a):void 0}function pl(e,t,n){let r=Ii(e),i=new Set([n]),a=[n];for(let n=a.pop();n;n=a.pop()){if(n.from<=t.from&&t.to<=n.to)return!0;let o=0,s=r.length;for(;o<s;){let e=o+s>>1;r[e].from<n.from?o=e+1:s=e}for(let t=o;t<r.length&&r[t].from<n.to;t++){let n=fl(e,r[t]);n&&!i.has(n)&&(i.add(n),a.push(n))}}return!1}function ml(e,t,n){let r=Oc(t.instruction),{name:i,args:a,switches:o}=r,s=!nl.has(i)&&i!==`REF`&&i!==`PAGEREF`,c=s?Dc(t.instruction)[0]?.value:a[0],l=!nl.has(i)&&c?dl(e,c):null;if(s&&!l)return Z(e,t,`unknown`),null;let u=rl[s?`REF`:i]??``;for(let n of o.keys())if(!Ec.includes(n)&&!u.includes(n))return Z(e,t,`unsupported-switch`,`\\${n}`),null;let d=(n,i)=>{let a=Rc(n,r,i);return a===null&&Z(e,t,`unsupported-switch`,`\\*`),a===null?null:{text:a}},{layout:f}=e.options;switch(i){case`PAGE`:case`SECTIONPAGES`:{let n=al(e,t,t.from);return n?i===`PAGE`?d(n.number,n.format):d(n.sectionPages):null}case`NUMPAGES`:return f||Z(e,t,`no-layout`),f?d(f.pages):null;case`DATE`:case`TIME`:{let t=o.get(`@`)?.[0]??(i===`DATE`?`M/d/yyyy`:`h:mm AM/PM`);return d(Mc(e.options.now??new Date,t))}case`SEQ`:{let e=(o.get(`*`)??[]).some(e=>!Lc.has(e.toLowerCase()));return o.has(`h`)&&!e?{text:``}:d(n.get(t)??0)}case`MERGEFIELD`:{let{data:n}=e.options;if(!n)return null;let i=a[0]??``,{found:s,value:c}=ll(n,i);if(!s)return Z(e,t,`no-data`,i),null;let l=c??``,u=o.get(`@`)?.[0];c instanceof Date?l=u?Mc(c,u):c.toISOString():u&&typeof c==`string`&&!Number.isNaN(Date.parse(c))&&(l=Mc(new Date(c),u));let d=Rc(typeof l==`number`?l:String(l),r);if(d===null)return Z(e,t,`unsupported-switch`,`\\*`),null;let f=o.get(`b`)?.[0]??``,p=o.get(`f`)?.[0]??``;return{text:d?`${f}${d}${p}`:``}}}if(!l)return Z(e,t,`missing-bookmark`,c),null;let{mark:p,tree:m,inBody:h}=l,g=o.has(`p`)&&m===e.tr.doc?ul(t,p):null;if(i===`PAGEREF`){if(!h)return Z(e,t,`no-layout`,c),null;let n=al(e,t,p.from);if(!n)return null;let r=g&&e.story===null&&f?f.pageAt(il(e.bodyTr,t.from)):null;if(g&&r?.number===n.number)return{text:g};let i=d(n.number,n.format);return i&&o.has(`p`)?{text:`on page ${i.text}`}:i}let _=[`n`,`r`,`w`].find(e=>o.has(e));if(_){let n=e.numbers.get(m);n||(n=new el(m,e.word),e.numbers.set(m,n));let r=n.number(p.from,_,t.from,o.has(`t`));return d(g?`${r} ${g}`:r)}if(g)return d(g);if(m===e.tr.doc&&pl(m,t,p))return Z(e,t,`self-reference`,c),null;let v=Qc(m,p),y=v.map(e=>e.isText?e.text:e.type.name===`tab`?` `:`
|
|
4
|
+
`).join(``),b=d(y);if(!b)return null;let x=!(o.get(`*`)??[]).some(e=>Lc.has(e.toLowerCase()));return b.text===y&&x?{text:y,nodes:v}:b}function hl(e,t,n){let{tr:r}=e;if(t.separator!==null){r.replace(t.resultFrom,t.resultTo,new w(f.fromArray([...n]),0,0));return}let i=Zc(t,Oc(t.instruction)),a=r.doc.type.schema.nodes.fieldSeparator.create(null,null,i);r.insert(t.to-1,[a,...n])}function gl(e,t){let{tr:n}=e,r=[...t].reverse();if(t.length<32||Yo(e.state)?.on){for(let[t,n]of r)hl(e,t,n);return}let i=Kc(n.doc),a=e=>{let t=0,n=i.length;for(;t<n;){let r=t+n>>1;i[r].pos<e?t=r+1:n=r}return i[t-1]},o=[],s,c=()=>{let e=s,[t]=o,r=o[o.length-1];if(e&&t&&r){let i=[...o].reverse(),a=r[0].resultFrom,s=t[0].resultTo,c=[];e.node.forEach((t,n)=>{let r=e.pos+1+n;r>=a&&r<s&&c.push({at:r,node:t})});let l=[],u=0;for(let[e,t]of i){for(;c[u]&&c[u].at<e.resultFrom;)l.push(c[u++].node);for(l.push(...t);c[u]&&c[u].at<e.resultTo;)u++}n.replace(a,s,new w(f.fromArray(l),0,0))}o=[],s=void 0};for(let t of r){let[n,r]=t,i=a(n.from);n.separator!==null&&i&&n.resultTo<i.pos+i.node.nodeSize?(i!==s&&c(),s=i,o.push(t)):(c(),hl(e,n,r))}c()}var _l=new WeakMap;function vl(e){let t=[],n=!1;for(let r=e;r;r=r.parent){let e=_l.get(r);if(e!==void 0){n=e;break}if(t.push(r),r.locked){n=!0;break}}for(let e of t)_l.set(e,n);return n}function yl(e){return Ii(e).filter(e=>{if(e.name!==`TOC`)return!1;for(let t=e.parent;t;t=t.parent)if(t.name===`TOC`)return!1;return!0})}var bl=e=>e.inCode?0:nl.has(e.name)?1:e.name===`TOC`?3:2;function xl(e){let{tr:t,report:n,story:r}=e,i=t.doc.type.schema,a=new Set,o=n=>{if(n.deleted||!e.picked(n)||r!==null&&tl.has(n.name))return!1;if(!vl(n))return!0;let i=il(t,n.from);return a.has(i)||Z(e,n,`locked`),a.add(i),!1};for(let r of[0,1,2]){let a=Ii(t.doc);if(!a.length)return;let s=cl(e,a),c=new Map;for(let t of a)if(bl(t)===r&&o(t))try{let r=ml(e,t,s);if(!r)continue;if(r.text===t.result){n.unchanged++;continue}let a=Zc(t,Oc(t.instruction));c.set(t,r.nodes??Xc(i,r.text,a)),n.updated++}catch(n){Z(e,t,`failed`,n.message)}let l=new Set;for(let e of a)e.parent&&(c.has(e.parent)||l.has(e.parent))&&l.add(e);gl(e,[...c].filter(([e])=>!l.has(e)))}if(r!==null){for(let n of Ii(t.doc))n.name===`TOC`&&o(n)&&Z(e,n,`unknown`,`in a story`);return}let s=yl(t.doc).length;for(let n=0;n<s;n++){let r=yl(t.doc)[n];if(r&&o(r)){if(!e.contents)Z(e,r,`untrackable`);else try{Nl(e,n)}catch(t){Z(e,r,`failed`,t.message)}}}}var Sl=new WeakMap;function Cl(e){let t=Sl.get(e);return t||(t=Ii(e).filter(e=>e.name===`TOC`),Sl.set(e,t)),t}function wl(e,t,{node:n,pos:r}){let{run:i}=t.resolver.paragraph(n.attrs),a=Cl(e),o=[],s=null;return n.forEach((n,c)=>{let l=r+1+c;a.some(e=>l>=e.from&&l<e.to)?s=null:(s||(s={title:``,from:l,to:l,bookmark:null},o.push(s)),s.to=l+n.nodeSize,n.type.name===`bookmarkStart`&&Tl.test(String(n.attrs.name))&&(s.bookmark??=String(n.attrs.name)),Yc(n)||Gc(e,l)||t.resolver.run(i,n.marks.map(e=>e.toJSON())).hidden||(n.isText?s.title+=n.text:n.type.name===`tab`?s.title+=` `:n.type.name===`hardBreak`&&(s.title+=` `)))}),o.map(e=>({...e,title:e.title.trim()})).filter(e=>e.title)}var Tl=/^_Toc\d+$/,El=e=>{let t=/(\d)\s*-\s*(\d)/.exec(e??``);return t?[Number(t[1]),Number(t[2])]:[1,9]};function Dl(e,t){let n=e.envelope.styles.find(e=>e.id===t)?.name??``,r=/^heading ([1-9])$/i.exec(n);if(r)return Number(r[1]);let i=t?e.resolver.paragraph({style:t}).paragraph.outlineLevel:null;return i!==null&&i<9?i+1:null}function Ol(e,t,{switches:n}){let r=n.has(`o`)||n.has(`u`)||n.has(`t`),[i,a]=El(n.get(`o`)?.[0]),o=new Map,s=(n.get(`t`)?.[0]??``).split(/[,;]/).map(e=>e.trim());for(let e=0;e+1<s.length;e+=2)o.set(s[e].toLowerCase(),Number(s[e+1])||1);let c=n.has(`b`)?Hc(e,n.get(`b`)?.[0]??``):null,l=Kc(e),u=t.resolver.markers(l.map(e=>e.node.attrs)),d=e=>e>=i&&e<=a,f=[];return l.forEach((i,a)=>{let{node:s,pos:l}=i;if(c&&(l+s.nodeSize<=c.from||l>=c.to))return;let p=t.resolver.paragraph(s.attrs).paragraph,m=t.envelope.styles.find(e=>e.id===p.style),h=o.get((m?.name??p.style??``).toLowerCase());if(h===void 0&&(n.has(`o`)||n.has(`u`)||!r)){let e=Dl(t,p.style);e!==null&&d(e)&&(h=e)}let g=p.outlineLevel;if(h===void 0&&n.has(`u`)&&g!==null&&g<9&&d(g+1)&&(h=g+1),h===void 0)return;let _=u[a];for(let{title:n,from:r,to:a,bookmark:o}of wl(e,t,i))f.push({from:r,to:a,level:h,title:n,number:_?.text??``,numberGap:_?.suffix===`space`?` `:_?.suffix===`nothing`?``:` `,bookmark:o})}),f}function kl(e,t,n){let r;e.forEach((e,t)=>{!r&&t+e.nodeSize>n&&e.attrs.section&&(r=e.attrs.section)});let{pageSize:i,margins:a}=r??t.envelope.section;return(i?.width??12240)-(a?.left??1440)-(a?.right??1440)-(a?.gutter??0)}function Al(e,t,n){let r=t<n.from;return e.forEach((e,i)=>{let a=t+1+i;a>=n.from&&a<n.to&&!Yc(e)&&(r||=!e.type.name.startsWith(`field`)||a===n.from)}),r}function jl(e,t){let n=[];return e.nodesBetween(t.from,t.to,(e,r)=>!e.isTextblock||(Al(e,r,t)&&r+1!==t.resultTo&&n.push(e.attrs.style??null),!1)),n}var Ml=`No table of contents entries found.`;function Nl(e,t){let{tr:n,word:r,report:i}=e,a=()=>yl(n.doc)[t],o=a(),s=Oc(o.instruction),{switches:c}=s;for(let t of c.keys())if(!Ec.includes(t)&&!rl.TOC.includes(t)){Z(e,o,`unsupported-switch`,`\\${t}`);return}let l=n.doc.type.schema,u=Ol(n.doc,r,s),d=c.get(`p`)?.[0]||` `,p=El(c.get(`n`)?.[0]),m=e=>c.has(`n`)&&e>=p[0]&&e<=p[1],{layout:h}=e.options,g=e=>{if(m(e.level)||!h)return``;let t=h.pageAt(il(n,e.from));return t?Ir(t.number,t.format):``},_=(e,t)=>(e.number?e.number+e.numberGap:``)+e.title+(m(e.level)?``:d+t),v=[],y=t=>{let n=Wa({envelope:e.envelope},`toc ${t}`);if(!n)throw new P(`No table of contents style`);return e.envelope=n.envelope,n.id};for(let e of u)v.push(y(e.level));let b=e=>h?e:e.replace(/\t[^\t\r]*(?=\r|$)/g,` `),x=n.doc.resolve(o.from).parentOffset===0,S=(x?``:`\r`)+u.map(e=>_(e,g(e))).join(`\r`),C=jl(n.doc,o).slice(+!x);if((u.length?b(S)===b(o.result):o.result===Ml)&&(!u.length||v.every((e,t)=>C[t]===e))){i.unchanged++;return}i.updated++,i.rebuilt++;let ee=Uc(n.doc,`_Toc`),te=Pl(e.state,n),T=l.nodes.bookmarkStart,ne=l.nodes.bookmarkEnd,E=u.filter(e=>!e.bookmark),D=new Map(E.map(e=>[e,te++]));for(let e of E)e.bookmark=ee();for(let e of E.reverse()){let t=D.get(e);n.insert(e.to,ne.create({id:t})),n.insert(e.from,T.create({id:t,name:e.bookmark}))}o=a();let O=c.has(`h`),re=O&&Wa({envelope:e.envelope},`Hyperlink`,`character`);re&&(e.envelope=re.envelope);let ie=kl(n.doc,r,o.from)-10,ae=n.doc.resolve(o.from);n.doc.resolve(o.resultTo);let k=ae.parent.attrs.controls??null,A=(e,t,n)=>l.nodes[e].create(t??null,null,n??[]),oe=u.map((t,n)=>{let r=O?[l.mark(`link`,{anchor:t.bookmark})]:[],i=re?[...r,l.mark(`characterStyle`,{id:re.id})]:r,a=[];t.number&&a.push(...Xc(l,t.number+t.numberGap,i)),a.push(...Xc(l,t.title,i)),m(t.level)||(a.push(...Xc(l,d,r)),a.push(A(`fieldStart`,null,r),A(`fieldCode`,{text:` PAGEREF ${t.bookmark} \\h `},r),A(`fieldSeparator`,null,r),...Xc(l,g(t),r),A(`fieldEnd`,null,r)));let o=e.envelope.styles.find(e=>e.id===v[n])?.paragraph?.tabs??[],s=[...t.number&&t.numberGap===` `&&!o.some(e=>e.kind!==`right`)?[{position:440*t.level,kind:`left`}]:[],...d===` `&&!o.some(e=>e.kind===`right`)?[{position:ie,kind:`right`,leader:`dot`}]:[]];return l.nodes.paragraph.create({style:v[n],...s.length?{tabs:s}:{},...k?{controls:k}:{}},a)});if(h||i.skipped.push({instruction:o.instruction,story:null,reason:`no-layout`}),!oe.length){n.replace(o.resultFrom,o.resultTo,new w(f.from(l.text(Ml)),0,0));return}if(o.separator===null){let e=o.codeMarks??[];n.insert(o.resultTo,A(`fieldSeparator`,null,Jc(e))),o=a()}let se=e=>{let t=[];return n.doc.nodesBetween(o.from,o.resultTo,(n,r)=>!n.isTextblock||(r!==e&&(r>ae.before()||x)&&Al(n,r,o)&&t.push({node:n,pos:r}),!1)),t},j=n.doc.resolve(o.resultTo);j.parentOffset&&(j.before()!==ae.before()&&oe.length<=se(j.before()).length?n.delete(j.start(),o.resultTo):n.split(o.resultTo),o=a());let ce=n.doc.resolve(o.resultTo),le=ce.before(),ue=ce.parent,de=se(le),M=ue.attrs.section??null;n.doc.nodesBetween(o.from,o.resultTo,(e,t)=>(e.isTextblock&&t!==le&&(M??=e.attrs.section??null),!e.isTextblock)),M!==(ue.attrs.section??null)&&n.setNodeMarkup(le,ue.type,{...ue.attrs,section:M}),oe.length>de.length&&n.insert(le,oe.slice(de.length));for(let e=de.length-1;e>=0;e--){let{node:t,pos:r}=de[e],i=oe[e];if(!i){n.delete(r,r+t.nodeSize);continue}let a=r<o.from?o.resultFrom:r+1;n.replace(a,r+1+t.content.size,new w(i.content,0,0));let{revision:s,formatChange:c}=t.attrs;n.setNodeMarkup(r,t.type,{...i.attrs,revision:s,formatChange:c})}if(!x){let e=n.doc.resolve(o.from);o.resultFrom<e.end()&&n.delete(o.resultFrom,e.end()),e.parent.attrs.section&&n.setNodeMarkup(e.before(),e.parent.type,{...e.parent.attrs,section:null})}}function Pl(e,t){let n=-1;for(let r of[t.doc,...di(e)])r.descendants(e=>(e.type.name.startsWith(`bookmark`)&&(n=Math.max(n,e.attrs.id)),!e.isInline));return n+1}function Fl(e,t,n){let r=Ii(e);if(t<n)return new Set(r.filter(e=>e.from<n&&e.to>t).map(e=>e.from));let i=Li(e,t)??r.find(e=>e.to===t||e.from===t)??null;return i?.parent?.name===`TOC`&&(i=i.parent),new Set(i?[i.from]:[])}function Il(e,t,n,r,i){let a=e.story(t);if(!a||!Ii(n.doc).length)return;let{state:o}=a,s=o.tr.setMeta(zl,`fields`),{updated:c,unchanged:l}=r.report;if(xl({...r,state:o,tr:s,story:t,bodyTr:r.tr}),!s.docChanged)return;let u=as(o,s);if(!u){r.report.updated=c,r.report.unchanged=l,r.report.skipped.push({instruction:``,story:t,reason:`untrackable`});return}let d=o.applyTransaction(u).state;i.step(new ti(t,n,{...n,doc:d.doc},o.selection.toJSON(),d.selection.toJSON()))}function Ll(e,t){for(let[n,r]of X(e)?.stories??[])if(r.doc===t)return n;return``}function Rl(e,t={}){let{state:n}=e,r=X(n);if(!r)return zc();let i=li(n)?.state,{only:a}=t,o=a&&typeof a!=`function`?Fl(n.doc,a.from,a.to):null,s=e=>{let s=n.tr.setMeta(zl,`fields`),c={state:n,tr:s,word:r,story:null,bodyTr:s,options:t,report:zc(),envelope:r.envelope,numbers:new Map,contents:e,picked:e=>typeof a==`function`?a(e):!o||[e,e.parent?.name===`TOC`?e.parent:null].some(e=>e&&o.has(il(s,e.from)))};return i&&(c.story=Ll(i,n.doc),c.bodyTr=i.tr),xl(c),{run:c,out:as(n,s)}},c=s(!0);c.out||(c=s(!1));let{run:l,out:u}=c;if(!u){let e=zc();return e.skipped.push({instruction:``,story:l.story,reason:`untrackable`}),e}if(!i&&!o)for(let[t,n]of r.stories)Il(e,t,n,l,u);return u.docChanged&&(l.envelope!==r.envelope&&mi(u,l.envelope),u.setMeta(t.continues?na:ta,!0),e.dispatch(u.setMeta(Bo,!0))),l.report}var zl=`controlEdit`,Bl=new Set([`contentLocked`,`sdtContentLocked`]),Vl=new Set([`sdtLocked`,`sdtContentLocked`]),Hl=new Set([`text`,`comboBox`,`date`]),Ul=new Set([`dropDown`,`checkbox`,`picture`]),Wl=new Set([`checkbox`,`picture`,`repeating`,`repeatingItem`,`other`]),Gl=new Set([`insertion`,`deletion`,`formatChange`]),Kl=new Set([`commentStart`,`commentEnd`,`commentReference`]),ql=e=>e?.type.name===`controlStart`||e?.type.name===`controlEnd`,Jl=e=>e.marks.some(e=>e.type.name===`deletion`),Yl={text:{docPart:`DefaultPlaceholder_-1854013440`,text:`Click or tap here to enter text.`},richText:{docPart:`DefaultPlaceholder_-1854013440`,text:`Click or tap here to enter text.`},dropDown:{docPart:`DefaultPlaceholder_-1854013438`,text:`Choose an item.`},comboBox:{docPart:`DefaultPlaceholder_-1854013438`,text:`Choose an item.`},date:{docPart:`DefaultPlaceholder_-1854013437`,text:`Click or tap to enter a date.`}},Xl=` `,Zl={value:`2612`,font:`MS Gothic`},Ql={value:`2610`,font:`MS Gothic`},$l=e=>Bl.has(e.lock??``)||!!e.binding,eu=new WeakMap;function tu(e,t){let n=t;for(let r=e.nodeAt(n);r;r=r.firstChild){if(r.isTextblock)return n+1;if(r.isLeaf)return t;n++}return t}function nu(e,t){let n=t;for(let r=e.resolve(n).nodeBefore;r;r=r.lastChild){if(r.isTextblock)return n-1;if(r.isLeaf)return t;n--}return t}function ru(e){let t=eu.get(e);if(t)return t;let n=[],r=new Set,i=(e,t)=>{let i=[];e.forEach((e,a)=>{let o=e.attrs.id;if(e.type.name===`controlStart`)i.push({id:o,at:t+a});else if(e.type.name===`controlEnd`){let e=i.map(e=>e.id).lastIndexOf(o);if(e<0){r.add(o);return}let{at:s}=i.splice(e,1)[0],c=t+a;n.push({id:o,level:`inline`,from:s,to:c+1,contentFrom:s+1,contentTo:c})}});for(let{id:e}of i)r.add(e)},a=(t,r)=>{let o=new Map,s=[];t.forEach((e,t,n)=>{let c=r+t,l=c+e.nodeSize;for(let t of e.attrs.controls??[]){let r=o.get(t);if(r&&r.index===n-1){r.index=n,r.to=l;continue}let i=e.type.name,a={index:n,from:c,to:l,level:i===`tableRow`?`row`:i===`tableCell`?`cell`:`block`};o.set(t,a),s.push({id:t,run:a})}e.isTextblock?i(e,c+1):e.isLeaf||a(e,c+1)});for(let{id:t,run:r}of s)n.push({id:t,level:r.level,from:r.from,to:r.to,contentFrom:tu(e,r.from),contentTo:nu(e,r.to)})};a(e,0),n.sort((e,t)=>e.from-t.from||t.to-e.to);let o={ranges:n,unpaired:r};return eu.set(e,o),o}var iu=e=>ru(e).ranges;function au(e,t){let n=null;for(let r of iu(e)){if(r.from>=t)break;t<r.to&&(n=r)}return n}var ou=(e,t)=>{let n=X(e)?.envelope.controls;return n&&Object.hasOwn(n,t)?n[t]:void 0};function su(e,t,n){if(t===n)return!0;let r=Math.min(t,n),i=Math.max(t,n);if(e.resolve(r).parent!==e.resolve(i).parent)return!1;let a=!0;return e.nodesBetween(r,i,e=>(e.isInline&&!ql(e)&&(a=!1),a)),a}function cu(e,t,n,r){if(!t)return!1;let i=e=>Object.hasOwn(t,e)?t[e]:void 0,a=iu(e);return a.some(e=>{let t=i(e.id);return!t||!$l(t)||t.deleted||e.from>=Math.max(r,n+1)||n>=e.to?!1:!a.some(t=>{let a=i(t.id);return t!==e&&t.from>=e.from&&t.to<=e.to&&t.from<n&&r<t.to&&!!a&&!$l(a)})})}var lu=(e,t)=>t.level===`inline`?e.slice(t.from+1,t.to-1).content:e.slice(t.from,t.to).content;function uu(e,t){let n=new Map;t.forEach((e,t)=>{let r=n.get(e.id);r?r.push(t):n.set(e.id,[t])});let r=new Map,i=new Map;for(let t of e){let e=r.get(t.id)??0;r.set(t.id,e+1);let a=n.get(t.id)?.[e];a!==void 0&&i.set(t,a)}return i}function du(e,t){let n=Math.min(e.childCount,t.childCount),r=0,i=0;for(;r<n&&e.child(r)===t.child(r);)i+=e.child(r).nodeSize,r++;let a=i,o=e.content.size,s=t.content.size;for(let i=1;i<=n-r;i++){let n=e.child(e.childCount-i);if(n!==t.child(t.childCount-i))break;o-=n.nodeSize,s-=n.nodeSize}return{fromA:i,toA:o,fromB:a,toB:s}}function fu(e,t){let n=e[t],r=[],i=-1;for(let a=t+1;a<e.length;a++){let t=e[a];if(t.from>=n.to)break;t.to>n.to||t.from<i||(r.push(t),i=t.to)}return r}function pu(e,t,n,r){let[i,a]=t.level===`inline`?[t.from+1,t.to-1]:[t.from,t.to],o=e=>e.level===`inline`?e.contentFrom:e.from,s=e=>e.level===`inline`?e.contentTo:e.to,c=[],l=null,u=0,d=-1;return e.nodesBetween(i,a,(e,t)=>{for(;n[u]&&t>=s(n[u]);)u++;let i=n[u];if(i&&t>=o(i))return i.level!==`inline`&&d!==u&&(d=u,l=null,c.push(`[${i.id}]`)),!1;if(Kl.has(e.type.name))return!1;let a=JSON.stringify(e.marks.filter(e=>r||e.type.name===`insertion`||e.type.name===`deletion`).map(e=>e.toJSON()));if(e.isText)return l===a?c[c.length-1]+=e.text??``:c.push(`${a}:${e.text}`),l=a,!1;l=null;let f=r||e.isInline?JSON.stringify(e.attrs):``;return c.push(`<${e.type.name}${f}${a}>`),!0}),c.join(``)}var mu=(e,t)=>t.some(([t,n])=>t<=e.contentFrom&&n>=e.contentTo&&(t<e.contentFrom||n>e.contentTo));function hu(e,t){let n=[];return lu(e,t).forEach(e=>{e.isInline?n.push(e):e.descendants(e=>(e.isInline&&n.push(e),!0))}),n}function gu(e,t,n,r){if(t.level!==`inline`){let n=e.nodeAt(t.from);if(!(t.level===`cell`?n?.childCount===1&&n.firstChild?.isTextblock:n?.isTextblock&&n.nodeSize===t.to-t.from))return!1}let i=new Set(r.map(e=>e.type.name));return hu(e,t).every(e=>e.isText||i.has(e.type.name)||Kl.has(e.type.name)||e.type.name===`hardBreak`&&n.multiLine===!0)}function _u(e,t){if(!e.docChanged||e.doc===t.doc||e.getMeta(`historyOp`))return!0;let n=X(t)?.envelope.controls;if(!n)return!0;let r=ru(t.doc);if(!r.ranges.length)return!0;let i=ru(e.doc),a=e.getMeta(zl),o=e.getMeta(`trackedDeletes`)??[],s=uu(r.ranges,i.ranges),c=du(t.doc,e.doc);for(let[l,u]of r.ranges.entries()){let d=Object.hasOwn(n,u.id)?n[u.id]:void 0;if(!d)continue;if(i.unpaired.has(u.id)&&!r.unpaired.has(u.id))return!1;let f=s.get(u);if(f===void 0){if(Vl.has(d.lock??``))return!1;continue}if(u.to<=c.fromA||u.from>=c.toA)continue;let p=i.ranges[f];if(lu(t.doc,u).eq(lu(e.doc,p)))continue;if(mu(u,o)){if(Vl.has(d.lock??``))return!1;continue}if(a===`fields`||a===`accept`||a===`reject`)continue;let m=$l(d);if(m||Ul.has(d.kind)&&!a){if(pu(t.doc,u,fu(r.ranges,l),m)!==pu(e.doc,p,fu(i.ranges,f),m))return!1}else if(Hl.has(d.kind)&&!gu(e.doc,p,d,hu(t.doc,u)))return!1}return!0}function vu(e){return Ba(e,`Placeholder Text`,`character`)}var yu=e=>e.placeholder?.text??(e.placeholder?.docPart?.startsWith(`DefaultPlaceholder_`)?Yl[e.kind]?.text??Xl:Xl);function bu(e,t,n){let r=yu(t);if(r===Xl)return{run:e.schema.text(r),envelope:n};let i=Wa({envelope:n},`Placeholder Text`,`character`),a=i&&e.schema.marks.characterStyle?.create({id:i.id});return{run:e.schema.text(r,a?[a]:[]),envelope:i?.envelope??n}}var xu=(e,t)=>t.mapping.map(e.contentFrom,1)>=t.mapping.map(e.contentTo,-1),Su=(e,t)=>(t.format??[]).map(t=>e.schema.markFromJSON(t));function Cu(e,t,n,r,i){e.doc.nodesBetween(t,n,(t,n)=>{if(!t.isText)return!0;let a=n+t.nodeSize,o=e=>!!r&&(e.type.name===`characterStyle`&&e.attrs.id===r||e.type.name===`runExt`&&String(e.attrs.xml).includes(`"${r}"`));for(let r of t.marks)o(r)&&e.removeMark(n,a,r);let s=t.marks.filter(e=>!o(e));for(let t of i)s.some(e=>e.type===t.type)||e.addMark(n,a,t);return!1})}function wu(e,t,n){let r=n.checkedState??Zl,i=n.uncheckedState??Ql,a=Lu(e,t);if(a===Uu(r))return!0;if(a===Uu(i))return!1;for(let n of hu(e,t)){let e=/:char="([0-9a-f]+)"/i.exec(String(n.attrs.xml??``))?.[1];if(!e||Jl(n))continue;let t=Number.parseInt(e,16)&255;if(t===(Number.parseInt(r.value,16)&255))return!0;if(t===(Number.parseInt(i.value,16)&255))return!1}return null}function Tu(e){try{return[`long`,`short`].map(t=>{let n=new Intl.DateTimeFormat(e,{month:t,timeZone:`UTC`});return Array.from({length:12},(e,t)=>n.format(Date.UTC(2024,t,1)).toLowerCase().replace(/\.$/,``))})}catch{return null}}function Eu(e,t){let n=Tu(e.ext&&/:lid\b[^>]*:val="([^"]+)"/.exec(e.ext)?.[1]||`en-US`)??[],r=[],i=(e.dateFormat??`d MMMM yyyy`).replace(/'[^']*'|d+|M+|y+|[Hhms]+|[AaPp]{2}|[.*+?^${}()|[\]\\/]/g,e=>e[0]===`'`?e.slice(1,-1).replace(/[.*+?^${}()|[\]\\]/g,`\\$&`):/^[.*+?^${}()|[\]\\/]$/.test(e)?`\\${e}`:e[0]===`d`&&e.length>2?`\\p{L}+\\.?`:((e[0]===`d`||e[0]===`y`||e[0]===`M`)&&r.push(e),e[0]===`M`&&e.length>2?`(\\p{L}+)\\.?`:e[0]===`d`||e[0]===`M`||e[0]===`y`?`(\\d+)`:`\\S+`)),a=RegExp(`^\\s*${i}\\s*$`,`iu`).exec(t);if(!a)return null;let[o,s,c]=[0,0,0];return r.forEach((e,t)=>{let r=a[t+1];if(e[0]===`d`)o=Number(r);else if(e[0]===`y`)c=Number(r)+(e.length<3?2e3:0);else if(e.length<3)s=Number(r);else{let e=r.toLowerCase();for(let t of n)t.includes(e)&&(s=t.indexOf(e)+1)}}),Du(c,s,o)}function Du(e,t,n){let r=new Date(Date.UTC(2e3,t-1,n));if(r.setUTCFullYear(e,t-1,n),r.getUTCMonth()!==t-1||r.getUTCDate()!==n)return null;let i=(e,t=2)=>String(e).padStart(t,`0`);return`${i(e,4)}-${i(t)}-${i(n)}T00:00:00Z`}function Ou(e,t,n,r){let i=e=>e.marks.filter(e=>!Gl.has(e.type.name)),a=[];e.doc.nodesBetween(t,n,(e,t)=>(e.isText&&a.push({node:e,pos:t}),!0));let o=(e,t)=>e.length===t.length&&e.every(e=>t.some(t=>t.eq(e)));if(!a.length)return;let s=i(a[0].node);if(a.every(e=>o(i(e.node),s)))return;let c=a.map(e=>i(e.node)).find(e=>!r||!o(e,r))??s;for(let{node:t,pos:n}of a){let r=n+t.nodeSize;for(let a of i(t))c.some(e=>e.eq(a))||e.removeMark(n,r,a);for(let i of c)i.isInSet(t.marks)||e.addMark(n,r,i)}}function ku(e,t,n,r){let i=X(r).envelope,a=i.controls,o=X(n)?.envelope.controls,s=iu(n.doc),c=iu(e.doc);if(!o||!s.length||!c.length)return a;let l=new Map;for(let[e,t]of uu(s,c))l.set(c[t],e);let u=du(n.doc,r.doc),d=new ke(t.flatMap(e=>e.mapping.maps)),f=t.map(e=>e.getMeta(zl)).find(Boolean),p=f===`accept`||f===`reject`,m=t.flatMap(e=>e.getMeta(`trackedDeletes`)??[]),h=i,g={...a},_=!1,v=(e,t)=>{g[e]=t,_=!0},y=(t,n)=>{let i=bu(r,n,h);h=i.envelope,e.insert(e.mapping.map(t.contentFrom,-1),i.run),n.placeholder?.showing||v(t.id,{...n,placeholder:{...n.placeholder,showing:!0}})},b=t=>{if(t.level===`inline`){e.delete(e.mapping.map(t.to,-1)-1,e.mapping.map(t.to,-1));let n=e.mapping.map(t.from,1);e.delete(n,n+1)}else e.doc.nodesBetween(e.mapping.map(t.from,1),e.mapping.map(t.to,-1),(n,r)=>{let i=n.attrs.controls;if(i?.includes(t.id)){let a=i.filter(e=>e!==t.id);e.setNodeMarkup(r,n.type,{...n.attrs,controls:a.length?a:null})}return!0})};for(let t of[...c].reverse()){if(t.to<=u.fromB||t.from>=u.toB)continue;let i=Object.hasOwn(g,t.id)?g[t.id]:void 0,a=l.get(t);if(!i||!a||lu(n.doc,a).eq(lu(r.doc,t)))continue;if(mu(a,m)){i.deleted||v(t.id,{...i,deleted:!0});continue}if(i.deleted&&p){let{deleted:n,...r}=i;if(f===`accept`&&!xu(t,e))continue;if(v(t.id,r),f===`accept`){b(t);continue}i=r}let s=o[t.id]?.placeholder?.showing===!0;if(s){let t=e.mapping.map(d.map(a.contentFrom,1),1),n=e.mapping.map(d.map(a.contentTo,-1),-1);t<n&&e.delete(t,n)}if(xu(t,e)&&!Wl.has(i.kind))y(t,i);else{if(s&&(Cu(e,e.mapping.map(t.contentFrom,-1),e.mapping.map(t.contentTo,1),vu({envelope:h}),Su(r,i)),i.placeholder?.showing&&(i={...i,placeholder:{...i.placeholder,showing:!1}},v(t.id,i))),i.kind===`checkbox`&&p){let e=wu(r.doc,t,i);e!==null&&e!==i.checked&&v(t.id,{...i,checked:e})}if(f!==`value`&&f!==`fields`){if(i.kind===`date`){let e=Lu(r.doc,t);if(s||e!==Lu(n.doc,a)){let{date:n,...r}=i,a=Eu(i,e);a!==(n??null)&&v(t.id,a?{...r,date:a}:r)}}if(Hl.has(i.kind)&&!s&&!p){let r=hu(n.doc,a).find(e=>e.isText);Ou(e,e.mapping.map(t.contentFrom,-1),e.mapping.map(t.contentTo,1),r?r.marks.filter(e=>!Gl.has(e.type.name)):null)}}}}return h!==i&&mi(e,h),_?(ai(r,e,`controls`,g),g):a}function Au(e,t,n,r,i){if(!(t instanceof L))return null;let a=iu(e);if(!a.length)return null;let{anchor:o,head:s}=t,c=(e,t)=>e.from<t&&t<e.to;if(o!==s)for(let t=0,n=!0;n&&t<8;t++){n=!1;for(let t of a){if(t.level!==`inline`||c(t,o)===c(t,s))continue;n=!0;let r=c(t,o),i=r?s:o,a=i<=t.from?t.contentFrom:t.contentTo;su(e,i,a)?r?s=a:o=a:r?o=i<=t.from?t.to:t.from:s=i<=t.from?t.to:t.from}}let l=Math.min(o,s),u=Math.max(o,s),d=au(e,l),f=d&&Object.hasOwn(i,d.id)?i[d.id]:void 0;if(d&&f?.placeholder?.showing&&u<d.to&&d.contentFrom<d.contentTo){let{contentFrom:t,contentTo:i}=d,a=l===t&&u===i,c=r&&n.from===t&&n.to===i;if(l===u&&c&&(l===t||l===i)){if(d.level===`inline`)o=l===i?d.to:d.from,s=o;else return I.near(e.resolve(l===i?d.to:d.from),l===i?1:-1)}else a||(o=t,s=i)}return o===t.anchor&&s===t.head?null:L.create(e,o,s)}var ju=(e,t,n)=>(t?.(e.tr.setSelection(L.create(e.doc,n.contentFrom,n.contentTo))),!0),Mu=e=>{let{from:t,to:n}=e.selection,r=au(e.doc,t);return r&&ou(e,r.id)?.placeholder?.showing&&t===r.contentFrom&&n===r.contentTo?r:null},Nu=e=>(t,n)=>{if(!X(t)?.envelope.controls)return!1;if(Mu(t))return!0;let{selection:r,doc:i}=t;if(!r.empty||!(r instanceof L))return!1;let{$from:a}=r,o=e?a.nodeAfter:a.nodeBefore;if(ql(o)){if(o?.type.name!==(e?`controlStart`:`controlEnd`))return!0;let r=au(i,a.pos+(e?1:-1));return r?ju(t,n,r):!1}if(e?a.parentOffset<a.parent.content.size:a.parentOffset>0)return!1;let s=iu(i).filter(e=>e.level!==`inline`);if(s.some(t=>(e?t.contentTo:t.contentFrom)===a.pos))return!0;let c=e?a.after():a.before(),l=s.find(t=>(e?t.from:t.to)===c);return l?ju(t,n,l):!1},Pu=(e,t)=>{let n=au(e.doc,e.selection.from),r=n&&ou(e,n.id);return!n||!r?!1:Mu(e)?!0:Hl.has(r.kind)?!r.multiLine||Ks(e,t):n.level===`inline`},Fu=(e,t)=>{let n=au(e.doc,e.selection.from),r=n&&ou(e,n.id);return!n||r?.kind!==`checkbox`?!1:($u(n.id,!r.checked)(e,t),!0)};function Iu(){return new et({filterTransaction:_u,appendTransaction(e,t,n){let r=X(n)?.envelope.controls;if(!r)return null;let i=n.tr,a=t.doc!==n.doc&&!e.some(e=>e.getMeta(`historyOp`))?ku(i,e,t,n):r,o=Au(i.doc,i.selection,t.selection,t.doc===n.doc,a);return o&&i.setSelection(o),i.steps.length||o?i:null},keymap:{Backspace:Nu(!1),Delete:Nu(!0),Enter:Pu," ":Fu}})}function Lu(e,t){let n=``,r=0,i=e=>{if(e.isTextblock&&r++&&(n+=`
|
|
5
|
+
`),e.isInline){if(Jl(e))return;e.isText?n+=e.text:e.type.name===`hardBreak`?n+=`
|
|
6
|
+
`:e.type.name===`tab`&&(n+=` `)}else e.forEach(i)};return lu(e,t).forEach(i),n}var Ru=(e,t)=>e.items?.find(e=>(e.display??e.value)===t);function zu(e){let t=new Set,n=[];for(let r of iu(e.doc)){let i=ou(e,r.id);if(!i||t.has(r.id))continue;t.add(r.id);let a=i.placeholder?.showing===!0,o=a?``:Lu(e.doc,r),s=a?null:o;i.kind===`checkbox`?s=i.checked===!0:a?s=null:i.kind===`dropDown`||i.kind===`comboBox`?s=Ru(i,o)?.value??o:i.kind===`date`?s=i.date?.slice(0,10)??o:[`text`,`richText`].includes(i.kind)||(s=null),n.push({id:r.id,kind:i.kind,...i.tag===void 0?{}:{tag:i.tag},...i.alias===void 0?{}:{title:i.alias},showingPlaceholder:a,text:o,value:s,...i.kind===`richText`&&!a?{content:(r.level===`cell`?e.doc.slice(r.from+1,r.to-1).content:lu(e.doc,r)).toJSON().map(bn)}:{}})}return n}function Bu(e,t){let n=iu(e.doc),r=n.filter(e=>e.id===t);return r.length?r:n.filter(n=>ou(e,n.id)?.tag===t)}function Vu(e){if(e instanceof Date)return Number.isNaN(e.getTime())?null:Du(e.getFullYear(),e.getMonth()+1,e.getDate());let t=typeof e==`string`?/^(\d{4})-(\d{2})-(\d{2})/.exec(e):null;return t?Du(Number(t[1]),Number(t[2]),Number(t[3])):null}function Hu(e,t){let[n,r,i]=t.slice(0,10).split(`-`).map(Number);return Mc(new Date(n,r-1,i),e.dateFormat??`d MMMM yyyy`)}function Uu(e){let t=/^[0-9a-f]{1,6}$/i.test(e.value)?Number.parseInt(e.value,16):-1;return t>=0&&t<=1114111&&(t<55296||t>57343)?String.fromCodePoint(t):`☐`}function Wu(e,t,n){let{schema:r}=e;return t.split(`
|
|
7
|
+
`).flatMap((e,t)=>[...t?[r.nodes.hardBreak?.create(null,null,n)]:[],...e?[r.text(e,n)]:[]])}function Gu(e,t,n){if(n.placeholder?.showing)return Su(e,n);let r=hu(e.doc,t).find(e=>e.isText);return r?r.marks.filter(e=>!Gl.has(e.type.name)):[]}function Ku(e,t,n,r){if(!Ju(e.doc,t)&&!(n.kind===`richText`&&Yu(r)))return null;let i=Gu(e,t,n),a=n;if(r===null||r===``)return n.kind===`checkbox`?null:{nodes:[],control:n};let o=t=>({nodes:Wu(e,t,i),control:a});switch(n.kind){case`text`:return typeof r==`string`?o(n.multiLine?r:r.replace(/\r\n?|\n/g,` `)):null;case`richText`:{if(typeof r==`string`)return o(r);if(typeof r!=`object`||r instanceof Date||!Array.isArray(r.content)||!Zu(e,t,r.content))return null;if(!r.content.length)return{nodes:[],control:n};if(t.level===`row`){let t=r.content.map(t=>e.schema.nodeFromJSON(t));return t.every(e=>e.type.name===`tableRow`)?{nodes:t,blocks:!0,control:a}:null}let i=r.content.every(t=>e.schema.nodes[t.type]?.isInline)?r.content.map(t=>e.schema.nodeFromJSON(t)):Xu(e,r.content);if(i.every(e=>e.isInline))return{nodes:i,control:a};if(t.level===`inline`){let e=i.length===1?i[0]:void 0;if(!e?.isTextblock)return null;let t=[];return e.forEach(e=>{t.push(e)}),{nodes:t,control:a}}return i.at(-1)?.type.name===`table`?null:{nodes:i,blocks:!0,control:a}}case`dropDown`:case`comboBox`:{if(typeof r!=`string`)return null;let e=n.items?.find(e=>e.value===r||e.display===r);return!e&&n.kind===`dropDown`?null:o(e?e.display??e.value:r)}case`date`:{let e=Vu(r);if(e)return{...o(Hu(n,e)),control:{...a,date:e}};if(typeof r!=`string`)return null;let{date:t,...i}=a;return{...o(r),control:i}}case`checkbox`:{if(typeof r!=`boolean`)return null;let t=r?n.checkedState??Zl:n.uncheckedState??Ql,a=e.schema.marks.font,o=a&&t.font?Qu(a,t.font):null,s=i.filter(e=>e.type!==a);return{nodes:[e.schema.text(Uu(t),o?o.addToSet(s):i)],control:{...n,checked:r}}}default:return null}}function qu(e,t){let n=e.nodeAt(t.from)?.attrs.controls??[];return n.slice(0,n.indexOf(t.id)+1)}function Ju(e,t){if(t.level===`inline`)return!0;if(t.level===`row`)return!1;let n=e.resolve(t.contentFrom),r=e.resolve(t.contentTo);return n.parent.isTextblock&&r.parent.isTextblock&&n.depth===r.depth&&n.node(n.depth-1)===r.node(r.depth-1)}var Yu=e=>typeof e==`object`&&!!e&&`content`in e;function Xu(e,t){let n=[];return Gn({type:`doc`,content:t},{fragment:!0,schema:e.schema}).forEach(e=>{n.push(e)}),n}function Zu(e,t,n){let r=X(e)?.envelope.controls??{},i=new Set(iu(e.doc).filter(e=>e===t||e.from<t.from||e.to>t.to).map(e=>e.id)),a=e=>typeof e==`string`&&Object.hasOwn(r,e)&&!i.has(e),o=t.level===`inline`?[]:qu(e.doc,t),s=e.doc.resolve(t.contentFrom),c=!1;for(let e=s.depth;e>0;e--)c||=s.node(e).type.name===`tableCell`;let l=new Map,u=e=>{if(typeof e!=`object`||!e||typeof e.type!=`string`)return!1;let t=e.attrs;if(Kl.has(e.type)||e.type===`noteReference`||e.type===`noteMark`||c&&(e.type===`pageBreak`||e.type===`columnBreak`)||t?.section)return!1;if(e.type===`controlStart`||e.type===`controlEnd`){if(!a(t?.id))return!1;let n=t?.id;l.set(n,(l.get(n)??0)+(e.type===`controlStart`?1:-1))}let n=t?.controls;return n!=null&&!(Array.isArray(n)&&n.every(e=>o.includes(e)||a(e)))||e.marks?.some(e=>e.type===`link`&&!de(e.attrs))?!1:e.content===void 0||Array.isArray(e.content)&&e.content.every(u)};return n.every(u)&&[...l.values()].every(e=>e===0)}function Qu(e,t){return e.create({ascii:t,hAnsi:t,eastAsia:t,...t===`MS Gothic`?{hint:`eastAsia`}:{}})}function $u(e,t,n=!1){return(r,a)=>{let o=X(r);if(!o?.envelope.controls)return!1;let s=[];try{for(let n of Bu(r,e)){let e=ou(r,n.id);if(!e||$l(e))continue;let i=Ku(r,n,e,t);i&&s.push({range:n,next:i})}}catch(e){if(e instanceof i)return!1;throw e}if(!s.length)return!1;let c=r.tr;c.setMeta(zl,`value`).setMeta(n?na:ta,!0);let l={...o.envelope.controls};try{for(let{range:e,next:t}of[...s].reverse())if(l[e.id]=t.control,t.blocks){let n=qu(r.doc,e),i=e.level===`cell`,a=t.nodes.map(e=>i?e:e.type.create({...e.attrs,controls:[...n,...(e.attrs.controls??[]).filter(e=>!n.includes(e))]},e.content,e.marks)),[o,s]=i?[e.from+1,e.to-1]:[e.from,e.to];c.replace(o,s,new w(f.fromArray(a),0,0))}else e.contentTo>e.contentFrom&&c.delete(e.contentFrom,e.contentTo),t.nodes.length&&c.insert(e.contentFrom,t.nodes)}catch(e){if(e instanceof P)return!1;throw e}ai(r,c,`controls`,l);let u=as(r,c);return!u||!r.applyTransaction(u).transactions.length?!1:(a?.(c),!0)}}[...Kl];var ed=oo,td=e=>t=>{let n=t?.toLowerCase()??null;return n!==null&&!M(n)?()=>!1:e(n)},nd=td($a),rd=td(eo),id=bo,ad=yo,od=wo,sd=So,cd=Co,ld=To;function ud(){return new et({keymap:{Enter:od,Backspace:ld,Tab:sd,"Shift-Tab":cd,"Mod-Shift-7":ad(`orderedList`),"Mod-Shift-8":ad(`bulletList`)}})}var dd={insertion:`insertion`,deletion:`deletion`,formatChange:`formatting`},fd=new Set(Ut);function pd(e,t){let n=[],r=e.content.size;t?.change&&e.lastChild?.isTextblock&&n.push({kind:`sectionFormatting`,id:t.change.id,author:t.change.author,date:t.change.date??null,from:r-1,to:r,move:null});let i=e=>{let t=e.mark.attrs;n.push({kind:dd[e.mark.type.name],id:t.id,author:t.author,date:t.date??null,from:e.from,to:e.to,move:t.move??null})};return e.descendants((e,t)=>{if(e.type.name===`tableRow`){let r=e.attrs.revision;for(let[i,a]of[[`rowInsertion`,r?.insertion],[`rowDeletion`,r?.deletion]])a&&n.push({kind:i,id:a.id,author:a.author,date:a.date??null,from:t,to:t+e.nodeSize,move:null});return!0}if(!e.isTextblock)return!0;let r=e.attrs.formatChange;r&&n.push(md(`paragraphFormatting`,r,t,e));let a=e.attrs.section?.change;a&&n.push(md(`sectionFormatting`,a,t,e));let o=[];e.forEach((e,n)=>{let r=t+1+n,a=[];for(let t of e.marks){if(!dd[t.type.name])continue;let n=o.find(e=>e.to===r&&e.mark.eq(t));n&&(n.to=r+e.nodeSize),a.push(n??{mark:t,from:r,to:r+e.nodeSize})}for(let e of o)a.includes(e)||i(e);o=a});for(let e of o)i(e);let s=e.attrs.revision;return s?.insertion&&n.push(md(`paragraphInsertion`,s.insertion,t,e)),s?.deletion&&n.push(md(`paragraphDeletion`,s.deletion,t,e)),!1}),n.sort((e,t)=>e.from-t.from||e.to-t.to)}function md(e,t,n,r){let i=n+r.nodeSize;return{kind:e,id:t.id,author:t.author,date:t.date??null,from:e===`paragraphFormatting`?n+1:i-1,to:e===`paragraphFormatting`?i-1:i,move:null}}var hd=new Set([`insertion`,`deletion`,`formatting`]),gd=new Set([`bookmarkStart`,`bookmarkEnd`,`commentStart`,`commentEnd`,`controlStart`,`controlEnd`]);function _d(e,t,n,r,i={}){let a=pd(e,t).filter(e=>!i.author||e.author===i.author),o;if(n===r){let e=a.filter(e=>e.from<=n&&n<=e.to),t=e.filter(e=>e.kind!==`paragraphFormatting`&&e.kind!==`sectionFormatting`);o=t.length?t:e}else o=a.filter(e=>e.from<r&&n<e.to).map(e=>hd.has(e.kind)?{...e,from:Math.max(e.from,n),to:Math.min(e.to,r)}:e);let s=new Set(o.map(e=>e.move).filter(e=>e!==null)),c=a.filter(e=>e.move!==null&&s.has(e.move)&&!o.some(t=>t.id===e.id&&t.kind===e.kind));return[...o,...c]}function vd(e,t,n,r){let i=t.doc.type.schema,a=[],o=[],s=new Map,c=!1,l=[...n.filter(e=>e.kind===`sectionFormatting`),...n.filter(e=>e.kind!==`sectionFormatting`)];for(let n of l){let{kind:l,from:u,to:d}=n,f=i.marks[l===`formatting`?`formatChange`:l];switch(l){case`insertion`:case`deletion`:if(!f)break;l===`insertion`===r?bd(t,u,d,f.name,n.id):a.push([u,d]);break;case`formatting`:t.doc.nodesBetween(u,d,(e,a)=>{if(!e.isInline)return!0;let o=e.marks.find(e=>e.type.name===`formatChange`);if(!o||o.attrs.id!==n.id)return!1;let s=Math.max(a,u),c=Math.min(a+e.nodeSize,d);if(!r){for(let n of e.marks)fd.has(n.type.name)&&t.removeMark(s,c,n);for(let e of o.attrs.previous)t.addMark(s,c,i.mark(e.type,e.attrs??null))}return t.removeMark(s,c,o),!1});break;case`paragraphFormatting`:{let e=t.doc.resolve(u).before(),n=t.doc.nodeAt(e);if(!n?.isTextblock)break;let i={...n.attrs,formatChange:null};if(!r){let e=n.attrs.formatChange.previous;for(let t of Go)i[t]=e[t]??null}t.setNodeMarkup(e,n.type,i);break}case`sectionFormatting`:{let i=t.doc.resolve(u).before(),a=t.doc.nodeAt(i),o=a?.attrs.section;a&&o?.change?.id===n.id?t.setNodeMarkup(i,a.type,{...a.attrs,section:xs(o,r)}):ai(e,t,`section`,xs(hs(e,t),r));break}case`rowInsertion`:case`rowDeletion`:{let e=t.doc.nodeAt(u);if(e?.type.name!==`tableRow`)break;if(l===`rowDeletion`===r){let e=t.doc.resolve(u).before();s.set(e,[...s.get(e)??[],[u,d]])}else{let n={...e.attrs.revision};delete n[l===`rowInsertion`?`insertion`:`deletion`];let r=Object.keys(n).length?n:null;t.setNodeMarkup(u,e.type,{...e.attrs,revision:r})}break}case`paragraphInsertion`:case`paragraphDeletion`:{let n=t.doc.resolve(u).before(),i=t.doc.nodeAt(n);if(!i?.isTextblock)break;let s={...i.attrs.revision},d=l===`paragraphDeletion`===r;delete s[l===`paragraphInsertion`?`insertion`:`deletion`];let f=Object.keys(s).length?s:null;t.setNodeMarkup(n,i.type,{...i.attrs,revision:f});let p=n+i.nodeSize,m=yd(i,n+1,a),h=d&&!!t.doc.resolve(p).nodeAfter?.isTextblock,g=i.attrs.section;d&&g&&(_s(e,t,g,p),h||t.setNodeMarkup(n,i.type,{...i.attrs,revision:f,section:null})),h?o.push({pos:p,keepFirst:r&&!m}):d&&!r&&(!i.content.size||m)&&t.doc.resolve(n).parent.childCount>1&&(a.push([n,p]),c=!0);break}}}for(let[e,n]of s){let r=t.doc.nodeAt(e);r&&n.length===r.childCount?a.push([e,e+r.nodeSize]):a.push(...n)}if(s.size||c){let e=a.filter(([e,t])=>!a.some(([n,r])=>n<e&&t<=r||n<=e&&t<r));a.length=0,a.push(...e)}let u=[...a.map(([e,n])=>({at:e,run:()=>t.delete(e,n)})),...o.filter(({pos:e})=>!(s.size||c)||!a.some(([t,n])=>t<e&&e<n)).map(({pos:e,keepFirst:n})=>({at:e-1,run:()=>xd(t,e,n)}))].sort((e,t)=>t.at-e.at);for(let e of u)e.run();wa(t)}function yd(e,t,n){let r=!0;return e.forEach((e,i)=>{let a=t+i;gd.has(e.type.name)||n.some(([t,n])=>t<=a&&a+e.nodeSize<=n)||(r=!1)}),r}function bd(e,t,n,r,i){e.doc.nodesBetween(t,n,(a,o)=>{if(!a.isInline)return!0;let s=a.marks.find(e=>e.type.name===r&&e.attrs.id===i);return s&&e.removeMark(Math.max(o,t),Math.min(o+a.nodeSize,n),s),!1})}function xd(e,t,n){let r=e.doc.resolve(t),i=r.nodeBefore,a=r.nodeAfter;if(!i?.isTextblock||!a?.isTextblock)return;let o=t-i.nodeSize;e.join(t);let s=n?{...i.attrs}:{...a.attrs};if(n)for(let e of Je)s[e]=a.attrs[e]??null;e.setNodeMarkup(o,i.type,s)}function Sd(e,t,n,r,i){let a=si(e,t,n);if(!a)return;let o=i===`insertion`?`paragraphInsertion`:`paragraphDeletion`,s=_d(a.doc,void 0,0,a.doc.content.size).filter(e=>e.kind===i||e.kind===o);if(!s.length)return;let c=ui(e,a.doc),l=c.tr;vd(c,l,s,r),t.step(new ti(n,a,{...a,doc:l.doc}))}function Cd(e,t,n,r=!1){let i=(a,o)=>{if(!a.schema.marks.insertion)return!1;let s=r?li(a):null;if(s)return o?s.run(i):s.can(i);let c=X(a)?.envelope.controls,l=t=>n=>n.kind.toLowerCase().includes(`deletion`)!==e||!cu(t,c,n.from,n.to),u=new Set,d=t(a).flatMap(e=>_d(a.doc,X(a)?.envelope.section,e.from,e.to,n)).filter(l(a.doc)).filter(e=>{let t=`${e.kind} ${e.id} ${e.from} ${e.to}`;return!u.has(t)&&!!u.add(t)}),f=r?[...X(a)?.stories??[]].flatMap(([e,t])=>{let r=_d(t.doc,void 0,0,t.doc.content.size,n).filter(l(t.doc));return r.length?[{id:e,story:t,changes:r}]:[]}):[];if(!d.length&&!f.length)return!1;if(o){let t=a.tr.setMeta(Bo,!0).setMeta(ta,!0),n=e?`accept`:`reject`;t.setMeta(zl,n);let r=X(a)?.envelope,i=r;try{d.length&&vd(a,t,d,e);for(let{id:i,story:o,changes:s}of f){let c=rt.create({doc:o.doc,plugins:[...ui(a,o.doc,r).plugins,Iu()]}),l=c.tr.setMeta(zl,n);vd(c,l,s,e);let u=c.applyTransaction(l).state;r=X(u)?.envelope,t.step(new ti(i,o,{...o,doc:u.doc}))}r&&r!==i&&(r.styles!==i?.styles&&mi(t,{...i,styles:r.styles}),r.controls!==i?.controls&&ai(a,t,`controls`,r.controls))}catch(e){if(e instanceof P)return!1;throw e}o(t)}return!0};return i}var wd=e=>e.selection.ranges,Td=e=>[{from:0,to:e.doc.content.size}],Ed=Cd(!0,wd),Dd=Cd(!1,wd),Od=e=>Cd(!0,Td,e===void 0?{}:{author:e},!0),kd=e=>Cd(!1,Td,e===void 0?{}:{author:e},!0);function Ad(e){return(t,n)=>{let r=(Yo(t)?.view??`markup`)!==`markup`,i=pd(t.doc,X(t)?.envelope.section).filter(e=>!r||e.kind!==`deletion`&&e.kind!==`paragraphDeletion`),{from:a,to:o}=t.selection,s=e?i.find(e=>e.from>a||e.from===a&&e.to>o):[...i].reverse().find(e=>e.from<a||e.from===a&&e.to<o);if(!s)return!1;if(n){let e=s.kind===`paragraphInsertion`||s.kind===`paragraphDeletion`||s.kind===`sectionFormatting`?s.from:s.to;n(t.tr.setSelection(L.create(t.doc,s.from,e)))}return!0}}var jd=Ad(!0),Md=Ad(!1),Nd={footnote:`footnotes`,endnote:`endnotes`},Pd={footnote:{position:`pageBottom`,format:`decimal`,start:1,restart:`continuous`},endnote:{position:`docEnd`,format:`lowerRoman`,start:1,restart:`continuous`}};function Fd(e){return e.startsWith(`footnote:`)?`footnote`:e.startsWith(`endnote:`)?`endnote`:null}var Id=e=>(e?.kind===`footnote`||e?.kind===`endnote`)&&(e.noteType??`normal`)===`normal`;function Ld(e,t,n){let r=Nd[t];return{...Pd[t],...e.settings?.[r],...n?.[r]}}var Rd=[],zd=new WeakMap;function Bd(e){let t=zd.get(e);if(!t){let n=[];e.descendants((e,t)=>(e.type.name===`noteReference`&&n.push({story:String(e.attrs.story),offset:t+1,customMark:e.attrs.customMark===!0,insertion:e.marks.find(e=>e.type.name===`insertion`),deletion:e.marks.find(e=>e.type.name===`deletion`)}),!0)),t=n.length?n:Rd,zd.set(e,t)}return t}function Vd(e,t,n={}){let r=[],i={footnote:{n:0,section:-1,page:void 0,start:1},endnote:{n:0,section:-1,page:void 0,start:1}},a=[];e.forEach(e=>{let t=e.attrs.section;t&&a.push(t)});let o=0;return e.forEach((e,s)=>{let c=a[o]??t.section;for(let a of Bd(e)){let e=Fd(a.story);if(!e)continue;let l=s+a.offset,u=!!a.deletion,d={story:a.story,kind:e,pos:l,section:o,deleted:u,customMark:a.customMark};if(a.customMark||u&&n.hideDeleted){r.push({...d,text:``});continue}let f=Ld(t,e,c),p=i[e],m=f.restart===`eachPage`?n.pageOf?.(l,a.story):void 0,h=p.section<0,g=p.section!==o;h||f.restart===`eachSect`&&g||f.restart===`eachPage`&&m!==void 0&&m!==p.page||g&&f.start!==p.start?p.n=f.start:p.n++,p.section=o,p.start=f.start,p.page=m,r.push({...d,text:Ir(p.n,f.format)})}e.attrs.section&&o++}),r}var Hd=e=>new Map(e.map(e=>[e.story,e.text]));function Ud(e,t,n,r){let i=ui(e,t.doc).tr,a=n.type.name,o={id:n.attrs.id,author:n.attrs.author,date:n.attrs.date};return t.doc.descendants((e,t)=>{if(e.isInline)return!Wd.has(e.type.name)&&!e.marks.some(e=>e.type.name===a)&&i.addMark(t,t+e.nodeSize,n),!1;if(e.isTextblock&&r){let n=e.attrs.revision??{};i.setNodeMarkup(t,e.type,{...e.attrs,revision:{...n,[a]:o}})}return!0}),{...t,doc:i.doc}}var Wd=new Set([`bookmarkStart`,`bookmarkEnd`,`commentStart`,`commentEnd`,`controlStart`,`controlEnd`]);function Gd(e){let t=new Map;return e.forEach(e=>{for(let n of Bd(e))t.set(n.story,n)}),t}function Kd(){return new et({appendTransaction(e,t,n){if(t.doc===n.doc||e.some(e=>e.getMeta(`historyOp`)))return null;let r=X(n);if(!r||![...r.stories.values()].some(Id))return null;let i=Gd(t.doc),a=Gd(n.doc),o=n.tr.setMeta(Bo,!0),s=-1,c=e=>(s<0&&(s=rs(n)),e.type.create({...e.attrs,id:s++}));for(let[e,t]of i){let r=si(n,o,e);if(!r||!Id(r))continue;let i=a.get(e);i?(i.deletion&&!t.deletion&&o.step(new ti(e,r,Ud(n,r,c(i.deletion),!0))),t.deletion&&!i.deletion&&Sd(n,o,e,!1,`deletion`),t.insertion&&!i.insertion&&Sd(n,o,e,!0,`insertion`)):o.step(new ti(e,r,null))}for(let[e,t]of a){let r=si(n,o,e);!i.has(e)&&t.insertion&&r&&Id(r)&&o.step(new ti(e,r,Ud(n,r,c(t.insertion),!1)))}return o.steps.length?o:null}})}function qd(e,t,n){try{e(t,n)}catch(e){console.error(`Foli: an editor listener failed`,e)}}function Jd(e,t,n,r,i,a){let o=t.stories.get(n),s=o;i.doc!==r.doc&&(s={...o,doc:i.doc},e.step(new ti(n,o,s,r.selection.toJSON(),i.selection.toJSON())));let c=!1;for(let t of a){for(let n of t.steps)(n instanceof Zr||n instanceof ei)&&e.step(n);c||=_i(t)!==void 0}if(c){let{numbering:n,styles:r,resources:a,controls:o}=X(i).envelope,{resources:s,controls:c,...l}=_i(e)??t.envelope;mi(e,{...l,numbering:n,styles:r,...a?{resources:a}:{},...o?{controls:o}:{}})}return{after:s,patched:c}}var Yd=class{id;host;state;own=!1;alive=!0;listeners=new Set;constructor(e,t){this.id=e,this.host=t;let n=this.tree()?.doc;this.state=this.create(n)}tree(){return X(this.host.state)?.stories.get(this.id)}create(e){let{host:t,id:n}=this,r=X(t.state),a=r.stories.get(n)?.kind;return rt.create({doc:e,selection:I.atStart(e),plugins:[new et({key:ci,state:{init:()=>t,apply:()=>t}}),new et({filterTransaction(e){if(!e.docChanged)return!0;try{return qn(e.doc,a,`story`),!0}catch(e){if(e instanceof i)return!1;throw e}}}),...t.plugins(r,Yo(t.state))]})}notify(e){for(let t of this.listeners)qd(t,this.state,e)}current(e){let t=X(this.host.state),n=Yo(this.host.state);if(X(e)===t&&Yo(e)===n)return e;let r=gi(e.tr,t);return n&&Xo(r,n),e.apply(r)}dispatch=e=>{if(!this.alive)return;let{host:t,id:n,state:r}=this,i=as(r,e);if(!i)return;let a=r.applyTransaction(i);if(!a.transactions.length)return;let o=a.state,s=t.state,c=X(s),l=c.stories.get(n),u=s.tr,{after:d,patched:f}=Jd(u,c,n,r,o,a.transactions),p=Yo(o),m=!!p&&p!==Yo(r);if(m&&Xo(u,p),u.steps.length||f||m){u.setMeta(Bo,!0),u.setMeta(ra,{id:n,tr:i}),u.time=i.time,i.addToHistory||u.setMeta(`addToHistory`,!1),i.getMeta(`closeHistory`)&&u.setMeta(ta,!0),i.getMeta(`joinHistory`)&&u.setMeta(na,!0),this.own=!0;try{t.dispatch(u)}finally{this.own=!1}if(d!==l&&X(t.state)?.stories.get(n)!==d)return}this.state=this.current(o),this.notify(a.transactions)};sync(e){if(this.own)return;let t=this.tree();if(!t){this.retire();return}let{state:n}=this,r=null;for(let t of e)for(let e of t.steps)e instanceof ti&&e.id===this.id&&(r=e.selectionAfter);if(t.doc!==n.doc){let e=r??n.selection.toJSON();this.state=this.current(n.withDocument(t.doc,I.fromJSON(t.doc,e))),this.notify([]);return}let i=this.current(n);i!==n&&(this.state=i,this.notify([]))}retire(){this.alive=!1}},Xd={width:12240,height:15840,margin:1440};function Zd(e){let t=e.margins??{};return{pageSize:{width:Cn(e.pageSize?.width??Xd.width),height:Cn(e.pageSize?.height??Xd.height)},margins:{top:Cn(Math.abs(t.top??Xd.margin)),right:Cn(t.right??Xd.margin),bottom:Cn(Math.abs(t.bottom??Xd.margin)),left:Cn((t.left??Xd.margin)+(t.gutter??0))}}}function Qd(e,t,n){let{content:r,...i}=Un(e,{extensions:t});return{doc:Gn(r,{schema:n}),settings:Zd(i.section),envelope:i}}function $d(e){let{dispatch:t}=e,n=n=>n(e.state(),t),r=()=>{let t=e.state(),n=[...(li(t)?null:X(t))?.stories??[]].filter(([,e])=>iu(e.doc).length);return[{editor:a},...n.flatMap(([t])=>{let n=e.story(t);return n?[{editor:n,story:t}]:[]})]},i=ef(e.plugins,{insertText:e=>ks(e),deleteSelection:()=>Ds,deleteBackward:e=>Fs(e),deleteForward:e=>Is(e),joinBackward:()=>Rs,joinForward:()=>zs,splitBlock:()=>Bs,insertHardBreak:()=>Ks,insertPageBreak:()=>qs,toggleMark:(e,t)=>Qs(e,t),setBlockType:(e,t)=>tc(e,t),selectAll:()=>Ys,undo:()=>ha,redo:()=>ga,wrapInList:e=>id(e),toggleList:e=>ad(e),indentListItem:()=>sd,outdentListItem:()=>cd,setLink:e=>Fo(e),removeLink:()=>Io,setAlign:e=>ed(e),setTextColor:e=>nd(e),setHighlight:e=>rd(e),setTrackChanges:(e,t)=>Zo(e,t),setReviewView:e=>Qo(e),acceptChange:()=>Ed,rejectChange:()=>Dd,acceptAllChanges:e=>Od(e),rejectAllChanges:e=>kd(e),nextChange:()=>jd,previousChange:()=>Md,addComment:(e,t)=>pc(e,t),replyToComment:(e,t,n)=>mc(e,t,n),editComment:(e,t)=>gc(e,t),resolveComment:(e,t)=>_c(e,t),deleteComment:e=>bc(e),deleteAllComments:()=>xc,setControlValue:(e,t)=>(n,i)=>{let a=!1;for(let{editor:n}of r())(i?n.run($u(e,t,a)):n.can($u(e,t,a)))&&(a=!0);return a}}),a={get settings(){return e.settings()},get state(){return e.state()},dispatch:t,run:n,can:t=>t(e.state()),handleKey(n){let r=e.state();return r.plugins.some(e=>{let i=e.spec.keymap?.[n];return i?i(r,t):!1})},select(n,r=n){let i=e.state(),a=i.doc.content.size,o=e=>Math.max(0,Math.min(e,a));t(i.tr.setSelection(L.create(i.doc,o(n),o(r))))},commands:tf(i,n),controlValues:()=>r().flatMap(({editor:e,story:t})=>zu(e.state).map(e=>t?{...e,story:t}:e)),get trackingChanges(){return Yo(e.state())?.on??!1},isMarkActive:t=>ec(e.state(),t),getDocument:e.getDocument,setDocument:e.setDocument,subscribe:e.subscribe,story:e.story,get storyView(){return e.views.current},set storyView(t){e.views.current=t},storyChanged:e.storyChanged,extensions:e.extensions,get navigation(){return e.views.navigation},set navigation(t){e.views.navigation=t}};return nf.set(a,i),a}function ef(e,t){let n={...t};for(let t of e)for(let[e,r]of Object.entries(t.spec.commands??{})){if(Object.hasOwn(n,e))throw RangeError(`Command "${e}" is already defined: plugin commands need names of their own`);if(typeof r!=`function`)throw TypeError(`Command "${e}" is not a function returning a command`);Object.defineProperty(n,e,{value:r,enumerable:!0})}return n}function tf(e,t){let n={};for(let[r,i]of Object.entries(e))Object.defineProperty(n,r,{value:(...e)=>t(i(...e)),enumerable:!0});return n}var nf=new WeakMap,rf=new $e(`viewKeys`);function af({document:e=Hn(),plugins:t=[],extensions:n=[],author:r=`Author`,trackChanges:i=!1,reviewView:a=`markup`}={}){let o=dn(n),s=[...t,...n.flatMap(e=>e.plugins??[])],c=e=>Qd(e,n,o),l=c(e),u={on:i,author:r,view:a},d=({envelope:e})=>[...s,new et({key:rf}),aa(),pi(e),Jo(u),Zi(),Iu(),wc(),Kd(),Aa(),ud(),nc()],f=rt.create({doc:l.doc,plugins:d(l)}),p=new Set,m={current:null,navigation:null},h=new Map,g=e=>{for(let t of p)qd(t,f,e)},_=()=>g([]),v=e=>{let t=as(f,e);if(!t)return;let n=f.applyTransaction(t);if(f=n.state,n.transactions.length){for(let[e,{editing:t}]of h)t.sync(n.transactions),t.alive||h.delete(e);g(n.transactions)}},y=e=>e(f,v),b={section:l.envelope.section,settings:l.settings},x=()=>{let e=X(f)?.envelope.section??b.section;return e!==b.section&&(b={section:e,settings:Zd(e)}),b.settings},S=()=>Yr(X(f)?.envelope??l.envelope,f.doc),C=e=>{let t=new Yd(e,{get state(){return f},run:y,can:e=>e(f),dispatch:v,plugins:(e,t)=>[...s,new et({key:rf}),pi(e.envelope,e),Jo(t??u),Zi(),Iu(),wc(),Aa(),ud(),nc()]}),r=$d({state:()=>t.state,dispatch:t.dispatch,settings:x,getDocument:()=>({...S(),content:bn(t.state.doc.toJSON())}),setDocument(e){let{doc:n}=c(e),r=t.state.tr.replace(0,t.state.doc.content.size,new w(n.content,0,0));t.dispatch(r.setSelection(I.atStart(r.doc)))},subscribe(e){return t.listeners.add(e),()=>t.listeners.delete(e)},story:ee,views:m,storyChanged:_,extensions:n,plugins:s});return h.set(e,{editing:t,editor:r}),r},ee=e=>X(f)?.stories.has(e)?h.get(e)?.editor??C(e):null;return $d({state:()=>f,dispatch:v,settings:x,getDocument:S,setDocument(e){u=Yo(f)??u,l=c(e),f=rt.create({doc:l.doc,plugins:d(l)});for(let{editing:e}of h.values())e.retire();h.clear(),g([])},subscribe(e){return p.add(e),()=>p.delete(e)},story:ee,views:m,storyChanged:_,extensions:n,plugins:s})}var of=`data-page-break`,sf=`data-column-break`,Q=96/1440,cf=9525,lf=`data-foli-picture`;function uf(e){let t=e?.data;if(t&&/^data:image\//i.test(t))return t;let n=e?.url;return n&&/^(https?|blob):/i.test(n)?n:void 0}function df(e,t,n){let r=String(e.resource??``),i=`${Number(e.width)/cf}px`,a=`${Number(e.height)/cf}px`,o=e.decorative===!0,s=String(e.alt??``),c=o?``:s||`Picture without alt text`,l=n?.(r),u;if(l){let e=t.createElement(`img`);e.src=l,e.alt=c,e.draggable=!1,e.referrerPolicy=`no-referrer`,u=e}else u=t.createElement(`span`),u.setAttribute(`role`,`img`),c?u.setAttribute(`aria-label`,c):u.setAttribute(`aria-hidden`,`true`),u.style.boxSizing=`border-box`,u.style.border=`1px dashed GrayText`;u.setAttribute(lf,r),!s&&!o&&(u.dataset.foliNoAlt=``),e.title&&(u.title=String(e.title));let d=u.style;return d.display=l?`inline`:`inline-block`,d.verticalAlign=`baseline`,d.maxWidth=`none`,d.maxHeight=`none`,d.width=i,d.height=a,u}var ff=`data-foli-float`;function pf(e){let t=e?.margins??{},n=e?.pageSize?.width??12240,r=e?.pageSize?.height??15840,i=(t.left??1440)+(t.gutter??0),a=Math.abs(t.top??1440);return{pageWidth:n*Q,pageHeight:r*Q,marginLeft:i*Q,marginTop:a*Q,textWidth:(n-i-(t.right??1440))*Q,textHeight:(r-a-Math.abs(t.bottom??1440))*Q}}function mf(e,t){let n=t.pageWidth-t.marginLeft-t.textWidth;switch(e){case`page`:return[0,t.pageWidth];case`leftMargin`:case`insideMargin`:return[0,t.marginLeft];case`rightMargin`:case`outsideMargin`:return[t.marginLeft+t.textWidth,n];default:return[t.marginLeft,t.textWidth]}}function hf(e,t){let n=t.pageHeight-t.marginTop-t.textHeight;switch(e){case`page`:return[0,t.pageHeight];case`topMargin`:case`insideMargin`:return[0,t.marginTop];case`bottomMargin`:case`outsideMargin`:return[t.pageHeight-n,n];default:return[t.marginTop,t.textHeight]}}function gf(e,[t,n],r){if(typeof e.offset==`number`)return t+e.offset/cf;let{align:i}=e;return i===`right`||i===`bottom`||i===`outside`?t+n-r:i===`center`?t+(n-r)/2:t}function _f(e,t,n){return gf(e,mf(e.relativeTo,n),t)-n.marginLeft}function vf(e,t,n){return e.relativeTo===`paragraph`||e.relativeTo===`line`?{paragraph:typeof e.offset==`number`?e.offset/cf:0}:{page:gf(e,hf(e.relativeTo,n),t)}}function yf(e,t,n,r){let i=e.float,a=Number(e.width)/cf,o=Number(e.height)/cf,s=e=>(i.distance?.[e]??0)/cf,c=df(e,t,n);c.style.display=`block`;let l=t.createElement(`span`);l.setAttribute(ff,i.wrap),l.append(c);let u=l.style;u.display=`block`;let d=_f(i.horizontal,a,r),f=vf(i.vertical,o,r);if(i.wrap===`behind`||i.wrap===`inFront`)return u.position=`absolute`,u.zIndex=i.wrap===`behind`?`-1`:`1`,u.left=`${r.marginLeft+d}px`,f.page===void 0?u.marginTop=`${f.paragraph}px`:u.top=`${f.page}px`,{nodes:[l],holder:l};let p=s(`top`),m=(f.paragraph??0)-p,h=t.createElement(`span`);if(h.setAttribute(`aria-hidden`,`true`),h.style.width=`0`,h.style.height=`${Math.max(0,m)}px`,u.marginTop=`${p+Math.min(0,m)}px`,u.marginBottom=`${s(`bottom`)}px`,i.wrap===`topAndBottom`)return h.style.float=`left`,u.float=`left`,u.clear=`both`,u.width=`100%`,c.style.marginLeft=`${d}px`,{nodes:[h,l],holder:l};let g=i.side===`left`||i.side!==`right`&&d+a/2>r.textWidth/2,_=g?`right`:`left`;return h.style.float=_,u.float=_,u.clear=_,g?(u.marginRight=`${r.textWidth-d-a}px`,u.marginLeft=`${s(`left`)}px`):(u.marginLeft=`${d}px`,u.marginRight=`${s(`right`)}px`),{nodes:[h,l],holder:l}}var bf=[`#B5082E`,`#1F5FAD`,`#2E7D32`,`#8E24AA`,`#A64B00`,`#00737F`,`#AD1457`,`#5D4037`];function xf(e){let t=0;for(let n of e)t=t*31+(n.codePointAt(0)??0)>>>0;return bf[t%bf.length]}function Sf(e,t,n,r,i){let a=e.createElement(t?`ins`:`del`),o=r?`, ${r.slice(0,10)}`:``;return a.title=`${t?`Inserted`:`Deleted`} by ${n||`an unknown author`}${o}`,i===`markup`?(a.style.color=xf(n),a.style.textDecorationLine=t?`underline`:`line-through`):(a.style.textDecorationLine=`none`,t||(a.style.display=`none`)),a}var Cf=`data-foli-note-ref`,wf=`data-foli-note-number`,Tf=192;function Ef(e,t){if(!e||![e,...e.getElementsByTagName(`*`)].some(e=>e.localName===`separator`||e.localName===`continuationSeparator`))return null;let n=t.createElement(`span`);n.dataset.foliSeparator=``;let{style:r}=n;return r.display=`inline-block`,r.width=`${Tf}px`,r.maxWidth=`100%`,r.height=`0`,r.borderTop=`1px solid #000`,r.verticalAlign=`middle`,n}function Df(e,t){return n=>{let r=e&&Object.hasOwn(e,n)?e[n]:void 0;if(!r)return;let i=t?.(n,r);return i===void 0?uf(r):i||void 0}}var Of={calibri:[`Carlito`],cambria:[`Caladea`],arial:[`Liberation Sans`,`Arimo`],"times new roman":[`Liberation Serif`,`Tinos`],"courier new":[`Liberation Mono`,`Cousine`],georgia:[`Gelasio`]},kf=new Set([`cambria`,`times new roman`,`georgia`,`garamond`,`book antiqua`]),Af=new Set([`courier new`,`consolas`,`courier`]);function jf(e){let t=e??`Times New Roman`,n=t.toLowerCase(),r=kf.has(n)?`serif`:Af.has(n)?`monospace`:`sans-serif`,i=e=>`"${e.replace(/["\\]/g,``)}"`;return[t,...Object.hasOwn(Of,n)?Of[n]:[]].map(i).concat(r).join(`, `)}var Mf={black:`#000000`,blue:`#0000FF`,cyan:`#00FFFF`,green:`#00FF00`,magenta:`#FF00FF`,red:`#FF0000`,yellow:`#FFFF00`,white:`#FFFFFF`,darkBlue:`#000080`,darkCyan:`#008080`,darkGreen:`#008000`,darkMagenta:`#800080`,darkRed:`#800000`,darkYellow:`#808000`,darkGray:`#808080`,lightGray:`#C0C0C0`},Nf={double:`double`,dotted:`dotted`,dottedHeavy:`dotted`,dash:`dashed`,dashedHeavy:`dashed`,dashLong:`dashed`,wave:`wavy`,wavyHeavy:`wavy`,wavyDouble:`wavy`},Pf={left:`left`,start:`left`,right:`right`,end:`right`,center:`center`,both:`justify`,distribute:`justify`},Ff={double:`double`,dotted:`dotted`,dashed:`dashed`,dashSmallGap:`dashed`,none:`none`,nil:`none`},If=e=>e.font.ascii??e.font.hAnsi;function Lf(e,t,n){let r=t.size/2*(96/72),{line:i,lineRule:a}=e.spacing;return i===null?String(n):a===`exact`?`${i*Q}px`:a===`atLeast`?`${Math.max(i*Q,n*r)}px`:String(n*i/240)}function Rf(e,t,n){let{style:r}=e;r.fontFamily=jf(If(t)),r.fontSize=`${t.size/2}pt`,r.lineHeight=n,r.fontWeight=t.bold?`700`:`400`,r.fontStyle=t.italic?`italic`:`normal`;let i=[];t.underline&&i.push(`underline`),(t.strike||t.doubleStrike)&&i.push(`line-through`),i.length&&(r.textDecorationLine=i.join(` `),t.doubleStrike||t.underline===`double`?r.textDecorationStyle=`double`:t.underline&&Nf[t.underline]&&(r.textDecorationStyle=Nf[t.underline]),t.underlineColor&&t.underlineColor!==`auto`&&(r.textDecorationColor=`#${t.underlineColor}`)),t.caps&&(r.textTransform=`uppercase`),t.smallCaps&&(r.fontVariant=`small-caps`),t.color&&(r.color=`#${t.color}`);let a=t.highlight?Mf[t.highlight]:t.shading&&`#${t.shading}`;a&&(r.backgroundColor=a),t.verticalAlign!==`baseline`&&(r.verticalAlign=t.verticalAlign===`superscript`?`super`:`sub`,r.fontSize=`${t.size/2*(2/3)}pt`,r.lineHeight=`0`),t.characterSpacing&&(r.letterSpacing=`${t.characterSpacing*Q}px`),t.hidden&&(r.display=`none`)}function zf(e,t){let{style:n}=e;n.margin=`0`,n.whiteSpace=`pre-wrap`,n.overflowWrap=`break-word`,n.tabSize=`${720*Q}px`;let{left:r,right:i,firstLine:a,hanging:o}=t.indent;n.paddingLeft=`${r*Q}px`,n.paddingRight=`${i*Q}px`,n.textIndent=`${(a-o)*Q}px`;let s=t.justification&&Pf[t.justification];s&&(n.textAlign=s),t.shading?.fill&&t.shading.fill!==`auto`&&(n.backgroundColor=`#${t.shading.fill}`);for(let[e,r]of Object.entries(t.borders??{})){if(!r||e===`between`||e===`bar`)continue;let t=Ff[r.style]??`solid`,i=t===`none`?0:Math.max((r.size??4)/8*(96/72),1),a=r.color&&r.color!==`auto`?`#${r.color}`:`currentColor`;n.setProperty(`border-${e}`,`${i}px ${t} ${a}`),n.setProperty(`padding-${e}`,`${(r.space??0)*96/72}px`)}}var Bf=new Set([`txbxContent`,`Fallback`]);function Vf(e){let t=``;for(let n of e.children)Bf.has(n.localName)||(n.localName===`t`?t+=n.textContent:n.localName===`tab`?t+=` `:t+=Vf(n));return t}function Hf(e,t){let n=[];for(let r of e.children)t.has(r.localName)?n.push(r):Bf.has(r.localName)||n.push(...Hf(r,t));return n}var Uf=new Set([`p`]),Wf=new Set([`r`]),Gf=new Set([`tr`]),Kf=new Set([`tc`]),qf=new Set([`p`,`tbl`]);function Jf(e,t){let n=t.defaultView;if(!n?.DOMParser)return null;let r=new Set;for(let t of e.matchAll(/<\/?([A-Za-z_][\w.-]*):|\s([A-Za-z_][\w.-]*):[\w.-]+\s*=/g)){let e=t[1]??t[2];e&&e!==`xml`&&e!==`xmlns`&&r.add(e)}let i=[...r].map(e=>` xmlns:${e}="urn:foli:${e}"`).join(``),a=new n.DOMParser().parseFromString(`<foli${i}>${e}</foli>`,`application/xml`),o=a.documentElement;return o.localName!==`foli`||a.getElementsByTagName(`parsererror`).length?null:o.firstElementChild}function Yf(e,t,n={}){let r=n.review??`markup`,i=n.fieldCodes===!0,a=new Map,o=e=>{let t=a.get(e);return t===void 0&&(t=n.lineRatio?.(e)??1.2,a.set(e,t)),t},s=n.resolver??new Jr(e),c=Df(e.resources,n.resource),l=pf(e.section),u=e.content.content??[],d=e=>e.attrs??{},f=e=>{let t=u[e],n=t&&d(t).revision;return r!==`markup`&&t?.type===`paragraph`&&!!n?.deletion&&u[e+1]?.type===`paragraph`},p=s.markers(u.map((e,t)=>e.type===`paragraph`&&!f(t-1)?d(e):{numbering:{id:0}})),m=[],h=Ui(u.map(Zf),i),g=null,_=new Set;return u.forEach((e,a)=>{if(e.type!==`paragraph`){m.push(sp(e,a,s,t,o,c,l,i,n.notes));return}let u=d(e),v=h[a];if(f(a)){let t=g??{nodes:[],inline:[],display:Xf};g={nodes:[...t.nodes,a],inline:[...t.inline,...e.content??[]],display:Qf(t.display,t.inline.length,v)};return}let y=g??{nodes:[],inline:[],display:Xf};g=null;let b=Qf(y.display,y.inline.length,v),{paragraph:x,run:S}=s.paragraph(u),C=t.createElement(np(x));zf(C,x);let w=s.run(S,u.markFormat??[]);Rf(C,w,Lf(x,w,o(jf(If(w)))));let ee=p[a],te=y.nodes[0],T=te===void 0?ee:p[te]??null;T&&C.append(ap(T,x,t,o));let ne=[...y.inline,...e.content??[]];if(op(C,ne,S,x,{resolver:s,doc:t,review:r,comments:_,ratio:o,image:c,geometry:l,codes:i,display:b,notes:n.notes}),b.gone&&(C.style.display=`none`),$f(ne,e=>e.type,e=>!!e.attrs?.float))for(let e of C.querySelectorAll(`[${lf}]`))e.style.verticalAlign=`bottom`;let E=C.lastChild,D=E?.nodeName===`BR`;(D&&!E?.hasAttribute(`data-page-break`)||!D&&!C.textContent)&&C.append(t.createElement(`br`));let O=e=>e*Q,{before:re,after:ie}=x.spacing,ae=x.spacing.beforeAutospacing?280:re,k=x.spacing.afterAutospacing?280:ie;m.push({element:C,nodes:[...y.nodes,a],before:b.gone?0:O(ae),after:b.gone?0:O(k),keepNext:x.keepNext,keepLines:x.keepLines,pageBreakBefore:x.pageBreakBefore,section:u.section??null}),C.dataset.style=x.style??``,x.contextualSpacing&&(C.dataset.contextual=``)}),rp(m,s.addsParagraphSpacing),m}var Xf=Ui([[]],!1)[0],Zf=e=>e.type===`paragraph`?(e.content??[]).map(e=>e.type):[];function Qf(e,t,n){return t?{hidden:new Set([...e.hidden,...[...n.hidden].map(e=>e+t)]),braces:new Map([...e.braces,...[...n.braces].map(([e,n])=>[e+t,n])]),gone:e.gone&&n.gone}:n}function $f(e,t,n){let r=!1;for(let i of e){let e=t(i);if(e===`picture`)r||=!n(i);else if(!ep.has(e))return!1}return r}var ep=new Set([`bookmarkStart`,`bookmarkEnd`,`commentStart`,`commentEnd`,`commentReference`,`controlStart`,`controlEnd`,`fieldStart`,`fieldCode`,`fieldSeparator`,`fieldEnd`]);function tp(e,t,n){return n.addsParagraphSpacing?e+t:e}function np(e){let t=e.outlineLevel;return t!==null&&t>=0&&t<6?`h${t+1}`:`p`}function rp(e,t){for(let n=1;n<e.length;n++){let r=e[n-1],i=e[n],a=r.element.dataset.style;if(a===void 0||a!==i.element.dataset.style)continue;let o=`contextual`in r.element.dataset;`contextual`in i.element.dataset?i.before=0:o&&!t&&(i.before=Math.max(0,i.before-r.after)),o&&(r.after=0)}}var ip={"":`•`,"":`▪`,"":`◻`,"":`●`,"":`■`,"":`❑`,"":`◆`,"":`❖`,"":`➢`,"":`✓`};function ap(e,t,n,r){let i=n.createElement(`span`);i.dataset.foliMarker=``,i.setAttribute(`aria-hidden`,`true`),Rf(i,e.run,Lf(t,e.run,r(jf(If(e.run))))),i.textContent=e.text;let a=If(e.run)?.toLowerCase(),o=a===`symbol`||a?.startsWith(`wingdings`)?ip[e.text]:void 0;o&&(i.textContent=o,i.style.fontFamily=`sans-serif`);let s=t.indent.hanging*Q;return e.suffix===`tab`&&s>0?(i.style.display=`inline-block`,i.style.minWidth=`${s}px`,i.style.textIndent=`0`):e.suffix===`tab`?i.textContent+=` `:e.suffix===`space`&&(i.textContent+=` `),i}function op(e,t,n,r,i){let{resolver:a,doc:o,review:s,comments:c,ratio:l,image:u,codes:d,display:f}=i,p=[];for(let[m,h]of t.entries()){if(f.hidden.has(m))continue;let t=h.marks??[],g=t.some(e=>e.type===`insertion`),_=t.some(e=>e.type===`deletion`);if(_&&s!==`markup`)continue;let v=h.attrs??{};switch(h.type){case`commentStart`:c.add(v.id);continue;case`commentEnd`:c.delete(v.id);continue;case`commentReference`:{let t=o.createElement(`span`);t.dataset.foliCommentReference=String(v.id),e.append(t);continue}case`bookmarkStart`:{let t=o.createElement(`span`);t.dataset.foliBookmark=String(v.name??``),t.style.position=`absolute`,e.append(t);continue}case`bookmarkEnd`:case`controlStart`:case`controlEnd`:continue;case`picture`:v.float?p.push(...yf(v,o,u,i.geometry).nodes):e.append(df(v,o,u));continue;case`hardBreak`:e.append(o.createElement(`br`));continue;case`columnBreak`:{let t=o.createElement(`br`);t.setAttribute(sf,``),e.append(t);continue}case`pageBreak`:{let t=o.createElement(`br`);t.setAttribute(of,``),e.append(t);continue}}let y=f.braces.get(m)??(d&&h.type===`fieldCode`?String(v.text):``),b;if(y)b=y;else if(h.type===`text`)b=h.text??``;else if(h.type===`tab`)b=` `;else if(h.type===`noteReference`)b=i.notes?.references?.get(String(v.story))??``;else if(h.type===`noteMark`)b=i.notes?.mark??``;else if(rn.test(h.type))b=pn(h)??`[${h.type}]`;else if(h.type===`opaqueInline`){let t=Jf(String(v.xml??``),o),n=Ef(t,o);if(n){e.append(n);continue}if(b=t?Vf(t):``,!b){let t=o.createElement(`span`);t.dataset.foliOpaque=String(v.label??``),e.append(t);continue}}else continue;let x=a.run(n,t),S=o.createElement(`span`);Rf(S,x,Lf(r,x,l(jf(If(x))))),S.textContent=b,h.type===`noteReference`&&S.setAttribute(Cf,String(v.story)),(h.type===`noteReference`||h.type===`noteMark`)&&S.setAttribute(wf,``);let C=t.find(e=>e.type===`link`);if(C&&(S.dataset.href=String(C.attrs?.href??`#${String(C.attrs?.anchor)}`)),c.size&&(S.dataset.foliComments=[...c].join(` `),!x.highlight&&!x.shading&&(S.style.backgroundColor=`rgba(255, 213, 79, 0.35)`)),s===`markup`&&(g||_)){let e=t.find(e=>e.type===(_?`deletion`:`insertion`))?.attrs,n=String(e?.author??``),r=e?.date??null,i=Sf(o,!_,n,r,s);i.append(S),S=i}e.append(S)}e.prepend(...p)}function sp(e,t,n,r,i,a,o=pf(void 0),s=!1,c){let l=e.attrs??{},u=r.createElement(`div`);u.dataset.foliOpaque=String(l.label??``),u.style.margin=`0`,u.style.display=`flow-root`;let d=e.type===`table`?null:Jf(String(l.xml??``),r),f=0;if(e.type===`table`)u.append(hp(e,n,r,i,a,o,s,c));else if(d?.localName===`tbl`)u.append(pp(d,n,r,i));else if(d){let e=Hf(d,Uf),t=0;e.forEach((a,o)=>{let s=lp(a,n,r,i,t);o<e.length-1?s.element.style.marginBottom=`${s.after}px`:f=s.after,t=s.after,u.append(s.element)})}return u.firstChild||(u.style.minHeight=`1em`,u.style.outline=`1px dashed #999`),{element:u,nodes:[t],before:0,after:f,keepNext:!1,keepLines:!1,pageBreakBefore:!1,section:null}}function cp(e,t,n=`val`){for(let r of e?.children??[])if(r.localName===t){for(let e of r.attributes)if(e.localName===n)return e.value}}function $(e,t){for(let n of e?.children??[])if(n.localName===t)return n}function lp(e,t,n,r,i=0){let a=$(e,`pPr`),o=cp(a,`pStyle`),s=cp(a,`jc`),{paragraph:c,run:l}=t.paragraph({...o?{style:o}:{},...s?{justification:s}:{}}),u=n.createElement(np(c));zf(u,c),Rf(u,l,Lf(c,l,r(jf(If(l)))));for(let i of Hf(e,Wf)){let e=Vf(i),a=t.run(l,up($(i,`rPr`))),o=n.createElement(`span`);Rf(o,a,Lf(c,a,r(jf(If(a))))),o.textContent=e,u.append(o)}u.textContent||u.append(n.createElement(`br`));let d=tp(c.spacing.before*Q,i,t);return d&&(u.style.marginTop=`${d}px`),{element:u,after:c.spacing.after*Q}}function up(e){let t=[],n=t=>{let n=cp(e,t);return n===void 0||![`0`,`false`,`off`].includes(n)},r=cp(e,`rStyle`);r&&t.push({type:`characterStyle`,attrs:{id:r}});for(let[r,i]of[[`b`,`bold`],[`i`,`italic`],[`caps`,`caps`],[`smallCaps`,`smallCaps`],[`strike`,`strike`]])$(e,r)&&t.push({type:i,attrs:{value:n(r)}});let i=cp(e,`u`);i&&t.push({type:`underline`,attrs:{style:i}});let a=cp(e,`color`);a&&t.push({type:`color`,attrs:{value:a}});let o=Number(cp(e,`sz`));o>0&&t.push({type:`fontSize`,attrs:{value:o}});let s=cp(e,`highlight`);return s&&t.push({type:`highlight`,attrs:{value:s}}),t}function dp(e){if(!e)return;let t=gp(e,`val`)??`single`;if(t===`nil`||t===`none`)return`none`;let n=Number(gp(e,`sz`)??4),r=gp(e,`color`),i=Ff[t]??`solid`;return`${Math.max(n/8*(96/72),.5)}px ${i} ${r&&r!==`auto`?`#${r}`:`#000`}`}function fp(e,t){let n={...t};for(let t of e?.children??[]){let e=t.localName===`start`?`left`:t.localName===`end`?`right`:t.localName,r=Number(gp(t,`w`));e in n&&Number.isFinite(r)&&(n[e]=r*Q)}return n}function pp(e,t,n,r){let i=n.createElement(`table`),{style:a}=i;a.borderCollapse=`collapse`,a.tableLayout=`fixed`;let o=$(e,`tblPr`),s=$(o,`tblBorders`);for(let e of[`top`,`left`,`bottom`,`right`]){let t=dp($(s,e));t&&a.setProperty(`border-${e}`,t)}let c=fp($(o,`tblCellMar`),{top:0,bottom:0,left:108*Q,right:108*Q}),l=[...$(e,`tblGrid`)?.children??[]].filter(e=>e.localName===`gridCol`).map(e=>Number(gp(e,`w`))||0),u=l.reduce((e,t)=>e+t,0);u&&(a.width=`${u*Q}px`);let d=n.createElement(`colgroup`);for(let e of l){let t=n.createElement(`col`);t.style.width=`${e*Q}px`,d.append(t)}i.append(d);let f={horizontal:dp($(s,`insideH`)),vertical:dp($(s,`insideV`))},p=n.createElement(`tbody`);for(let i of Hf(e,Gf)){let e=n.createElement(`tr`),a=$(i,`trPr`),o=cp(a,`tblHeader`);$(a,`tblHeader`)&&o!==`0`&&o!==`false`&&(e.dataset.foliHeader=``);let s=fp($($(i,`tblPrEx`),`tblCellMar`),c);for(let a of Hf(i,Kf)){let i=$(a,`tcPr`),o=n.createElement(`td`),c=Number(cp(i,`gridSpan`));c>1&&(o.colSpan=c);let l=cp(i,`shd`,`fill`);l&&l!==`auto`&&(o.style.backgroundColor=`#${l}`);let u=fp($(i,`tcMar`),s);o.style.padding=`${u.top}px ${u.right}px ${u.bottom}px ${u.left}px`,o.style.verticalAlign=`top`,f.horizontal&&(o.style.borderTop=o.style.borderBottom=f.horizontal),f.vertical&&(o.style.borderLeft=o.style.borderRight=f.vertical);let d=$(i,`tcBorders`);for(let e of[`top`,`left`,`bottom`,`right`]){let t=dp($(d,e));t&&o.style.setProperty(`border-${e}`,t)}if($(i,`vMerge`)&&cp(i,`vMerge`)!==`restart`){e.append(o);continue}let p=0;for(let e of Hf(a,qf)){if(e.localName===`tbl`){o.append(pp(e,t,n,r)),p=0;continue}let i=lp(e,t,n,r,p);i.element.style.marginBottom=`${i.after}px`,p=i.after,o.append(i.element)}e.append(o)}p.append(e)}return i.append(p),i}function mp(e){if(!e)return;if(e.style===`nil`||e.style===`none`)return`none`;let t=Math.max((e.size??4)/8*(96/72),.5),n=e.color&&e.color!==`auto`?`#${e.color}`:`#000`;return`${t}px ${Ff[e.style??`single`]??`solid`} ${n}`}function hp(e,t,n,r,i,a,o,s){let c=e.attrs??{},l=n.createElement(`table`);l.style.borderCollapse=`collapse`,l.style.tableLayout=`fixed`;let u=c.grid??[],d=u.reduce((e,t)=>e+t,0);d&&(l.style.width=`${d*Q}px`);let f=n.createElement(`colgroup`);for(let e of u){let t=n.createElement(`col`);t.style.width=`${e*Q}px`,f.append(t)}l.append(f);let p=n.createElement(`tbody`),m=e.content??[],h={resolver:t,doc:n,review:`markup`,comments:new Set,ratio:r,image:i,geometry:a,codes:o};return m.forEach((e,l)=>{let u=e.attrs??{},d=n.createElement(`tr`);u.header&&(d.dataset.foliHeader=``),u.cantSplit&&(d.dataset.foliCantSplit=``);let f=e.content??[];f.forEach((e,p)=>{let g=e.attrs??{},_=t.cell(c,u,g,{row:l,rows:m.length,cell:p,cells:f.length}),v=n.createElement(`td`),y=g.gridSpan;y&&y>1&&(v.colSpan=y),_.shading&&(v.style.backgroundColor=`#${_.shading}`);let b=_.margins;v.style.padding=`${b.top*Q}px ${b.right*Q}px ${b.bottom*Q}px ${b.left*Q}px`,v.style.verticalAlign=_.verticalAlign===`center`?`middle`:_.verticalAlign;for(let e of[`top`,`left`,`bottom`,`right`]){let t=mp(_.borders[e]);t&&v.style.setProperty(`border-${e}`,t)}if(d.append(v),g.vMerge===`continue`)return;let x=0,S=e.content??[],C=Ui(S.map(Zf),o);for(let[e,c]of S.entries()){if(c.type===`table`){v.append(hp(c,t,n,r,i,a,o,s)),x=0;continue}if(c.type!==`paragraph`){v.append(sp(c,0,t,n,r,i,a,o,s).element),x=0;continue}let{paragraph:l,run:u}=t.paragraph(c.attrs??{},_),d=n.createElement(np(l));d.dataset.foliCell=``,zf(d,l),Rf(d,u,Lf(l,u,r(jf(If(u)))));let f=C[e];op(d,c.content??[],u,l,{...h,display:f,notes:s}),f.gone&&(d.style.display=`none`),d.textContent||d.append(n.createElement(`br`));let p=l.spacing.before*Q;d.style.marginTop=`${tp(p,x,t)}px`,x=l.spacing.after*Q,d.style.marginBottom=`${x}px`,v.append(d)}}),p.append(d)}),l.append(p),l}function gp(e,t){for(let n of e.attributes)if(n.localName===t)return n.value}var _p={orphans:2,widows:2},vp=.5,yp=e=>e?e.page*1e6+(e.band??0)*1e3+(e.column??0):0;function bp(e,t,n=_p,r){let i=r?Math.min(r.from,e.length,r.previous.fragments.length):0,a=t=>e[t]?.section?.balanced===!0,o=t=>e[t]?.section===e[t-1]?.section;for(;;)if(i>0&&e[i-1]?.keepWithNext)i--;else if(i>0&&i<e.length&&a(i)&&o(i))i--;else break;let s=r?r.previous.fragments.slice(0,i):[],c=r?r.previous.states.slice(0,i):[],l=r?r.previous.gaps.slice(0,i):[],u=r?.previous.states[i]?{...r.previous.states[i]}:{page:0,number:e[0]?.section?.pageStart??1,sectionPage:0,band:0,bandTop:0,lead:0,column:0,used:0,bandBottom:0,previousMargin:0,onPage:0,breakPending:!1,columnPending:!1,forcedPage:!0,owner:null,notes:0,noteParts:[],pageNotes:0,carry:[],reserves:{}},d=new Set,f=n.spacing===`word`,p=null,m=[],h=null,g=()=>`${u.page}|${u.band}`,_=()=>u.reserves[g()]??0,v=(e=!1)=>{u.page++,u.number++,u.band=0,u.bandTop=0,u.lead=0,u.column=0,u.used=0,u.bandBottom=0,u.onPage=0,u.forcedPage=e,u.owner=null,u.notes=0,u.noteParts=[],u.pageNotes=0,Object.keys(u.reserves).length&&(u.reserves=Object.fromEntries(Object.entries(u.reserves).filter(([e])=>Number.parseInt(e,10)>=u.page)))},y=(e,t=!1)=>{u.column+1>=(e.section?.columns??1)?v(t):(u.bandBottom=Math.max(u.bandBottom,u.used),u.column++,u.used=0,u.lead=0,u.onPage=0,u.forcedPage=t)},b=e=>x(e)-Math.max(u.notes,_()),x=e=>{let n=u.owner?.section??e.section,r=(n?n.box({index:u.page,number:u.number,first:u.owner?.first??u.page===u.sectionPage}).height:e.pageHeight??t)-u.bandTop-u.pageNotes;return p?.page===u.page?Math.min(r,p.height):r},S=(e,t,n)=>({id:e.id,page:u.page,...u.band?{band:u.band}:{},...u.column?{column:u.column}:{},fromLine:t,toLine:n}),C=(e,t,n)=>({id:e.id,page:u.page,...u.band?{band:u.band}:{},fromLine:t,toLine:n}),w=(e,t,n)=>{let r=e.lines(u.column),i=t?r[t-1]:0,a=t;for(;a<r.length&&r[a]-i<=n+vp;)a++;return{to:a,height:a>t?r[a-1]-i:0,all:r.length}},ee=(e,t,n,r,i)=>{let a=e.lines(0),o=t?a[t-1]:0,s=i>1?0:Cp(r,1),c=e=>a[e]-o,l=t;for(;l<a.length&&(i>1?Cp([...r,c(l)],i):s+c(l))<=n+vp;)l++;return{to:l,height:l>t?c(l-1):0,all:a.length}},te=e=>e.lines(0).at(-1)??0,T=e=>C(e,0,e.lines(0).length),ne=(e,t=!1)=>{if(!u.carry.length||u.notes||u.onPage||!n.notes)return;let{continuation:r}=n.notes,i=e.section?.columns??1,a=te(r),o=x(e)-u.used-a,s=[],c=[],l=[];for(let e of u.carry){if(c.length){c.push(e);continue}let n=ee(e.note,e.from,o,l,i);n.to===e.from&&t&&!s.length&&(n=ee(e.note,e.from,E(e),l,1)),n.to>e.from&&(s.push(C(e.note,e.from,n.to)),l=[...l,n.height]),n.to<n.all&&c.push({note:e.note,from:n.to})}s.length&&(m.push(T(r),...s),u.notes=a+Cp(l,i),u.noteParts=l,u.carry=c)},E=({note:e,from:t})=>{let n=e.lines(0);return n[t]-(t?n[t-1]:0)},D=e=>u.onPage>0||u.notes>0||u.bandTop>0||u.column+1<(e.section?.columns??1),O=(e,t)=>{let r=u.breakPending;u.breakPending=!1,u.columnPending=!1;let i=(u.notes>0||u.pageNotes>0)&&e.columns!==t?.columns,a=!t||e.samePage(t)&&!i;if(!r&&a&&e.start===`continuous`){u.owner??={section:t??e,first:u.page===u.sectionPage};let n=u.previousMargin;return u.bandTop+=Math.max(u.bandBottom,u.used)+n,u.lead=n,u.band++,u.column=0,u.used=0,u.bandBottom=0,u.onPage=0,u.forcedPage=!0,u.sectionPage=u.page,u.pageNotes+=u.notes,u.notes=0,u.noteParts=[],n}if(!r&&a&&e.start===`nextColumn`&&e.columns===t?.columns&&u.column+1<e.columns){y({section:e},!0);return}u.onPage||u.used||u.column||u.band?v(!0):u.forcedPage=!0;let o=t=>e.start===`oddPage`&&t%2==0||e.start===`evenPage`&&t%2==1;o(u.number)&&(e.pageStart===void 0||n.evenAndOddHeaders)&&v(!0),e.pageStart!==void 0&&(u.number=e.pageStart+ +!!o(e.pageStart)),u.sectionPage=u.page},re=(e,t)=>{let n=ae(e,t);return e.endnotes?.length&&ie(e,n),n},ie=(e,t)=>{let n=u.onPage?u.previousMargin:0;for(let t of e.endnotes??[]){let r=0;for(;;){let i=t.lines(u.column);if(r>=i.length)break;let a=r?i[r-1]:0;ne(e);let o=u.onPage?n??0:0,s=w(t,r,b(e)-u.used-o);if(s.to===r){if(D(e)){y(e);continue}s={...s,to:r+1,height:i[r]-a}}let c=S(t,r,s.to);c.end=!0,o&&(c.lead=o),m.push(c),n=void 0,u.used+=o+s.height,u.onPage++,r=s.to,r<i.length&&y(e)}}u.previousMargin=0;let r=t[t.length-1];r&&m.length&&(r.notes=[...r.notes??[],...m]),r&&(m=[])},ae=(t,r)=>{let i=e[r-1],a;r>0&&t.section&&i?.section!==t.section?a=O(t.section,i?.section):u.breakPending&&u.onPage?v(!0):u.columnPending?y(t,!0):d.has(r)&&u.onPage&&y(t),u.breakPending=!1,u.columnPending=!1;let o=u.page,s=(e,t)=>{let n={page:u.page,fromLine:e,toLine:t};return u.band&&(n.band=u.band),u.column&&(n.column=u.column),a!==void 0&&u.page===o&&(n.lead=a),a=void 0,m.length&&(n.notes=m,m=[]),n};if(t.sectionMark&&u.onPage)return l[r]=0,[{...s(0,1/0),mark:!0}];let c=u.previousMargin;u.previousMargin=t.marginBottom;let p=f&&n.addSpacing===!0,S=()=>u.onPage?p?c+t.marginTop:Math.max(c,t.marginTop):f&&!u.forcedPage?0:p?t.marginTop:Math.max(0,t.marginTop-u.lead),w=f?0:t.marginBottom,re=t.breaksAfter?.(u.column)??[],ie=t.columnBreaksAfter?.(u.column)??[],ae=re.length+ie.length>0,k=t.inColumn?.(u.column)??t,A=()=>{let e=new Map;for(let{line:n,note:r}of t.notes?.(u.column)??[])e.set(n,[...e.get(n)??[],r]);return e},oe=A();if(u.carry.length&&!u.onPage&&ne(t),!ae&&!oe.size&&u.used+S()+k.height+w<=b(t)+vp){let e=S();return l[r]=e,u.used+=e+k.height,u.onPage++,[s(0,1/0)]}let se=k.lines(),j=se.length,ce=e=>new Set(e.filter(e=>e>=0&&e<j)),le=ce(re),ue=ce(ie),de=[],M=0,fe=0,pe=(e=!1)=>{if(!t.inColumn)return;let n=t.inColumn(u.column);if(n===k)return;let r=n.lines(),i=M?se[M-1]/(k.height||1):0;if(k=n,se=r,j=se.length,le=ce(t.breaksAfter?.(u.column)??[]),ue=ce(t.columnBreaksAfter?.(u.column)??[]),M>0){let t=[...le,...ue].sort((e,t)=>e-t)[fe-1],r=se.findIndex(e=>e/(n.height||1)>i+1e-6);r<0&&(r=j-1),M=e&&t!==void 0?t+1:Math.max(r,1)}if(M>=j){let e=de.at(-1);e&&(e.toLine=1/0)}};for(;M<j;){let e=M;for(;e<j&&!le.has(e)&&!ue.has(e);)e++;e=Math.min(e+1,j);let i=M?se[M-1]:0,a=M===0?S():t.repeat??0;oe=A(),ne(t);let o=x(t),c=j===1,d=(r,s=!1)=>{let l={notes:u.notes,parts:u.noteParts,carry:u.carry,pieces:[]};if(!oe.size||!n.notes)return l;let d=t.section?.columns??1;for(let f=M;f<r;f++)for(let r of oe.get(f)??[]){if(l.carry.length){l.carry=[...l.carry,{note:r,from:0}];continue}let{separator:p}=n.notes,m=!l.notes,v=m?te(p):l.notes-Cp(l.parts,d),y=f+1;!t.anyLine&&!c&&(y=Math.max(y,M+n.orphans),j-y<n.widows&&(y=j),y=Math.min(y,e));let b=y===j?t.marginBottom:0,x=u.used+a+se[y-1]-i+b,S=Math.max(x,d>1&&u.column?u.bandBottom:0),w=ee(r,0,o-S-v,l.parts,d);if(d>1&&u.column&&!s&&(!w.to||w.to<w.all&&S>x)){let e=r.lines(0),t=v+Cp([...l.parts,e.at(-1)],d),n=v+Cp([...l.parts,e[0]],d),i=t<o/2?t:n;i>_()+vp&&i<o&&(h={key:g(),height:i})}if(!w.to){if(!s)return null;w=ee(r,0,E({note:r,from:0}),[],1)}m&&l.pieces.push(T(p)),l.pieces.push(C(r,0,w.to)),l.parts=[...l.parts,w.height],l.notes=v+Cp(l.parts,d),w.to<w.all&&(l.carry=[{note:r,from:w.to}])}return l},f=M;for(;f<e;){let e=se[f]-i+(f+1===j?w:0),t=d(f+1);if(!t||u.used+a+e+Math.max(t.notes,_())>o+vp)break;f++}if(f<e&&f>M&&!t.anyLine){let r=Math.min(f,e-n.widows);r-M>=n.orphans?f=r:D(t)&&(f=M)}if(f===M){if(D(t)){y(t),pe();continue}f=M+1}let p=d(f,!0);p&&(u.notes=p.notes,u.noteParts=p.parts,u.carry=p.carry,m.push(...p.pieces)),M===0&&(l[r]=a),de.push(s(M,f)),u.used+=a+se[f-1]-i,u.onPage++,M=f;let b=le.has(f-1),O=ue.has(f-1);M<j?((b||O)&&fe++,b?v():y(t,O),pe(b||O)):b?u.breakPending=!0:O&&(u.columnPending=!0)}let[me]=de;return de.length===1&&me&&!ae&&(me.toLine=1/0),de},k=new Map,A=(t,n)=>{let f=t;for(;f<n;){let n=r&&!p&&f>i&&!k.size&&r.previousIndex(f-1)>=0?r.previousIndex(f):-1,g=n>=0?r?.previous.states[n]:void 0;if(g&&!e[f-1]?.keepWithNext&&!(a(f)&&o(f))&&Ep(g,u)){let e=r.previous;return s.length=f,c.length=f,l.length=f,s.push(...e.fragments.slice(n)),c.push(...e.states.slice(n,-1)),l.push(...e.gaps.slice(n)),{fragments:s,states:[...c,{...e.states.at(-1)}],gaps:l}}c[f]={...u};let _=re(e[f],f);if(h){let{key:e,height:n}=h;h=null;let[r,i]=e.split(`|`).map(Number),a=f;for(;a>t&&s[a-1]?.some(e=>e.page===r&&(e.band??0)===i);)a--;let o=c[a];u={...o,reserves:{...o.reserves,[e]:n}},s.length=a,c.length=a,l.length=a,k.clear();for(let e of d)e>=a&&d.delete(e);m=[],f=a;continue}s[f]=_;let v=s[f-1],y=v!==void 0&&yp(_[0])>yp(v[v.length-1]),b=k.get(f);if(b&&(k.delete(f),y)){s.splice(b.first,s.length-b.first,...b.result),c.splice(b.first,c.length-b.first,...b.snapshots),l.splice(b.first,l.length-b.first,...b.gaps),u=b.state,f++;continue}if(y&&e[f-1]?.keepWithNext&&o(f)){let t=f-1;for(;t>0&&o(t)&&e[t-1]?.keepWithNext&&s[t-1]?.length===1&&yp(s[t-1]?.[0])===yp(s[t]?.[0]);)t--;let n=c[t];if(!d.has(t)&&n.onPage>0&&s[t]?.length===1){k.set(f,{first:t,result:s.slice(t),snapshots:c.slice(t),gaps:l.slice(t),state:{...u}}),d.add(t),u={...n},s.length=t,f=t;continue}}f++;let x=e[f-1]?.section;!p&&x?.balanced&&x.columns>1&&e[f]?.section!==x&&oe(f)}return null},oe=t=>{let n=e[t-1]?.section,r=t-1;for(;r>0&&e[r-1]?.section===n;)r--;let i=c[r],{page:a}=u,o=Math.max(u.bandBottom,u.used),l=o/n.columns-1,f=e=>{p={page:a,height:e},u={...i},s.length=r,c.length=r,k.clear();for(let e of d)e>=r&&d.delete(e);return A(r,t),u.page===a&&Math.max(u.used,u.bandBottom)<=e+vp};for(;o-l>.5;){let e=(l+o)/2;f(e)?o=e:l=e}f(o)||f(1/0),p=null};return A(i,e.length)||((()=>{let t=s[s.length-1],n=t?.[t.length-1],r=e[e.length-1];if(!t||!n||!r||!u.carry.length&&!n.notes?.some(e=>e.tail))return;let i=u;for(u={...u};u.carry.length;)v(),ne(r,!0);let a=[...(n.notes??[]).filter(e=>!e.tail),...m.map(e=>({...e,tail:!0}))];m=[],u=i,s[s.length-1]=[...t.slice(0,-1),{...n,notes:a}]})(),{fragments:s,states:[...c.slice(0,e.length),{...u}],gaps:l.slice(0,e.length)})}function xp(e,t){let n=[],r=[],i=new Set,a=new Map;t.fragments.forEach((o,s)=>{let c=e[s]?.section,l=t.states[s+1],u=a.get(c)??new Set;a.set(c,u);let d=[...o,...o.flatMap(e=>e.notes??[])];for(let{page:e}of d)u.add(e),n[e]||(r[e]=c,n[e]={index:e,number:l.number-(l.page-e),first:!i.has(c),section:c.index??0,sectionPages:0}),i.add(c)}),n.forEach((e,t)=>{e&&(e.sectionPages=a.get(r[t])?.size??0)});for(let e=n.length-1;e>=0;e--){let t=n[e+1];n[e]??={...t,index:e,number:t.number-1,first:!1,sectionPages:0}}return n}function Sp(e,t){let n=e.reduce((e,t)=>e+t,0);if(t<=1||e.length<=1)return{height:n,columnOf:e.map(()=>0)};let r=n=>{let r=[],i=0,a=0,o=0;for(let t of e)a&&a+t>n+.01&&(i++,a=0),a+=t,o=Math.max(o,a),r.push(i);return i<t?{height:o,columnOf:r}:null},i=Math.max(...e,n/t),a=r(i);if(a)return a;let o=n;for(a=r(o);o-i>.25;){let e=(i+o)/2,t=r(e);t?(a=t,o=e):i=e}return a}var Cp=(e,t)=>Sp(e,t).height;function wp(e,t,n,r,i){for(let a=t.fragments.length-1;a>=0;a--)for(let o of t.fragments[a]??[])if(o.page===n&&(o.band??0)===r&&(o.column??0)===i)return e[a]?.marginBottom??0;return 0}var Tp=e=>e.fragments.flatMap(e=>e.flatMap(e=>e.notes??[]));function Ep(e,t){return e.notes===t.notes&&JSON.stringify(e.reserves)===JSON.stringify(t.reserves)&&e.noteParts.length===t.noteParts.length&&e.noteParts.every((e,n)=>e===t.noteParts[n])&&e.pageNotes===t.pageNotes&&e.carry.length===t.carry.length&&e.carry.every((e,n)=>e.note.id===t.carry[n]?.note.id&&e.from===t.carry[n]?.from)&&e.page===t.page&&e.number===t.number&&e.sectionPage===t.sectionPage&&e.band===t.band&&e.bandTop===t.bandTop&&e.lead===t.lead&&e.column===t.column&&e.used===t.used&&e.bandBottom===t.bandBottom&&e.previousMargin===t.previousMargin&&e.onPage===t.onPage&&e.breakPending===t.breakPending&&e.columnPending===t.columnPending&&e.forcedPage===t.forcedPage&&e.owner===t.owner}var Dp=`data-foli-sheet`;function Op(e,t,n,r){let i=n.every(e=>e.width===t.width&&e.height===t.height)?``:n.map(({width:t,height:n,index:i})=>{let a=`foli-${r}-${i}`;return`@page ${a}{size:${t} ${n};margin:0}${e}[${Dp}="${i}"]{page:${a};height:${n}!important}`}).join(``);return`@media print{@page{size:${t.width} ${t.height};margin:0}${e}{height:${t.height}!important;margin-block:0!important;break-after:page;break-inside:avoid}${e}:last-child{break-after:auto}${i}}`}var kp=`foli-band`,Ap=`foli-column`;function jp(e){let{widths:t,gaps:n,separator:r}=ds(e);return{widths:t.map(e=>e*Q),gaps:n.map(e=>e*Q),separator:r}}function Mp(e,t,n){if(e.className=kp,e.style.display=`flex`,n.separator&&n.gaps.length){let t=0,r=n.gaps.map((e,r)=>(t+=n.widths[r]+e,t-e/2));e.style.backgroundImage=r.map(()=>`linear-gradient(#000,#000)`).join(`,`),e.style.backgroundRepeat=`no-repeat`,e.style.backgroundSize=r.map(()=>`1px 100%`).join(`,`),e.style.backgroundPosition=r.map(e=>`${e-.5}px 0`).join(`,`),e.style.printColorAdjust=`exact`}t.forEach((e,t)=>{e.className=Ap,e.style.flex=`none`,e.style.display=`flow-root`,e.style.width=`${n.widths[t]}px`,e.style.marginRight=`${n.gaps[t]??0}px`})}function Np(e,t){let n=e.createElement(`div`),r=t.widths.map(()=>e.createElement(`div`));return Mp(n,r,t),n.append(...r),{band:n,columns:r}}var Pp=`data-foli-page-field`,Fp=`foli-region`,Ip=`foli-region-content`,Lp=720,Rp=new Set([`PAGE`,`NUMPAGES`,`SECTIONPAGES`]),zp=new Map([[`roman`,`lowerRoman`],[`ROMAN`,`upperRoman`],[`alphabetic`,`lowerLetter`],[`ALPHABETIC`,`upperLetter`]]),Bp=``,Vp=/\uE000([\uE100-\uF8FF])/g;function Hp(e){let t=e.trim().split(/\s+/)[0]?.toUpperCase()??``;if(!Rp.has(t))return null;let n=/\\\*\s*(\S+)/.exec(e)?.[1];return{name:t,format:n?.toLowerCase()===`arabic`?`decimal`:zp.get(n??``)}}function Up(e,t,n){let r=e.name===`PAGE`?t.page:e.name===`NUMPAGES`?t.pages:t.sectionPages;return Ir(Number(r),e.format??(e.name===`PAGE`?n:void 0))}function Wp(e,t){let n=[];for(let r=0;r<e.length;r++){let i=e[r];if(n.push(i),i.type!==`fieldStart`)continue;let a=1,o=-1,s=-1,c=``;for(let t=r+1;t<e.length&&s<0;t++){let n=e[t];n.type===`fieldStart`?a++:n.type===`fieldEnd`&&--a===0?s=t:a===1&&n.type===`fieldSeparator`&&o<0?o=t:a===1&&o<0&&n.type===`fieldCode`&&(c+=String(n.attrs?.text??``))}let l=s<0?null:Hp(c);if(!l)continue;let u=o<0?s:o+1,d=e.slice(u,s).find(e=>e.type===`text`)??e[u-1];n.push(...e.slice(r+1,u)),n.push({type:`text`,text:Bp+String.fromCharCode(57600+t.length),...d?.marks?{marks:d.marks}:{}}),t.push(l),n.push(e[s]),r=s}return n}function Gp(e,t){if(!e.content)return e;let n=e.type===`paragraph`?Wp(e.content,t):e.content.map(e=>Gp(e,t));return{...e,content:n}}function Kp(e,t){let n=e.cloneNode(!0);if(!t.length)return n;let r=e.ownerDocument.createTreeWalker(n,NodeFilter.SHOW_TEXT);for(let e=r.nextNode();e;e=r.nextNode()){let n=e;n.data.replace(Vp,``)===``&&n.data&&n.parentElement?.setAttribute(Pp,``),n.data.includes(Bp)&&(n.data=n.data.replace(Vp,(e,n)=>t[n.charCodeAt(0)-57600]??``))}return n}function qp(e){let t=e.margins??{},n=t.top??1440,r=t.bottom??1440,i=(t.left??1440)+(t.gutter??0),a=t.right??1440,o=e.pageSize?.width??12240;return{top:Math.abs(n)*Q,bottom:Math.abs(r)*Q,pushesTop:n>=0,pushesBottom:r>=0,header:(t.header??Lp)*Q,footer:(t.footer??Lp)*Q,left:i*Q,right:a*Q,height:(e.pageSize?.height??15840)*Q,width:Math.max(o-i-a,1)*Q}}function Jp(e,t,n){let r=0;return e.forEach((e,i)=>{let a=i?n?r+e.before:Math.max(r,e.before):e.before;e.element.style.marginTop=`${a}px`,e.element.style.marginBottom=`0`,r=e.after,t.append(e.element)}),r}var Yp=class{doc;options;cache;pages=1;sectionPages=new Map;edges=[];flowed=[];document=null;sections=[];resolver=null;constructor(e,t,n){this.doc=e,this.options=t,this.cache=n}setDocument(e,t,n){this.document=e,this.sections=t,this.resolver=n,this.edges=[]}story(e){let t=this.document?.stories;return t&&Object.hasOwn(t,e)?t[e]:void 0}edgesAt(e){let t=this.edges[e];return t||(t=qp(this.sections[e]??{}),this.edges[e]=t),t}storyId(e,t,n){let r=this.sections[e];if(!r)return null;let i=bs(r,n,this.document?.settings?.evenAndOddHeaders===!0),a=ys(this.sections,e,t,i);return a&&this.story(a.id)?a.id:null}entry(e){let t=this.cache.get(e);if(!t){let n=[],r=Gp(e.content,n),i=this.doc.createElement(`div`);i.className=Ip,i.style.paddingTop=`0.01px`;let a=Jp(Yf({...this.document,content:r},this.doc,{...this.options,...this.resolver?{resolver:this.resolver}:{}}),i,!!this.resolver?.addsParagraphSpacing);i.style.paddingBottom=`${a}px`,t={slots:n,template:i,after:a,drawn:new Map,heights:new Map},this.cache.set(e,t)}return t}valuesFor(e,t){return{page:String(t),pages:String(this.pages),sectionPages:String(this.sectionPages.get(e)??1)}}drawn(e,t,n){let r=this.entry(this.story(e)),i=this.edgesAt(t),a=this.valuesFor(t,n),o=this.sections[t]?.pageNumbers?.format,s=r.slots.map(e=>Up(e,a,o)),c=`${i.width}|${s.join(`|`)}`,l=r.drawn.get(c);if(!l){let e=null,t=()=>(e??=Kp(r.template,s),e),n=`${i.width}|${s.map(e=>/^\d*$/.test(e)?e.length:e).join(` `)}`,a=r.heights.get(n);a===void 0&&(a=this.measure(t(),i.width,r.after),r.heights.set(n,a)),l={height:a,get content(){return t()}},r.drawn.set(c,l)}return l}measure(e,t,n){let{style:r}=e;r.position=`absolute`,r.visibility=`hidden`,r.width=`${t}px`,this.options.measureIn().append(e);let i=e.lastElementChild,a=this.options.scale?.()??1,o=e.getBoundingClientRect().top,s=i?i.getBoundingClientRect().bottom:o;return e.remove(),r.position=``,r.visibility=``,r.width=``,(s-o)/a+n}heightOf(e,t,n){let r=this.storyId(e,t,n);return r?this.drawn(r,e,n.number).height:0}margins(e,t){let n=this.edgesAt(e),r=n.pushesTop?this.heightOf(e,`header`,t):0,i=n.pushesBottom?this.heightOf(e,`footer`,t):0;return{top:r?Math.max(n.top,n.header+r):n.top,bottom:i?Math.max(n.bottom,n.footer+i):n.bottom}}boxHeight(e,t){let{top:n,bottom:r}=this.margins(e,t);return this.edgesAt(e).height-n-r}settle(e){let t=()=>e.filter(e=>e.sectionPages).map(e=>this.boxHeight(e.section,e)).join(` `),n=t();this.flowed=e,this.pages=e.length,this.sectionPages=new Map;for(let t of e)t.sectionPages&&this.sectionPages.set(t.section,t.sectionPages);return t()!==n}key(){let e=[`header`,`footer`],t=this.sections.flatMap((t,n)=>e.flatMap(e=>[{first:!0,number:1},{first:!1,number:1},{first:!1,number:2}].map(t=>this.heightOf(n,e,{...t,index:0})))),n=this.flowed.filter(e=>e.sectionPages&&e.section<this.sections.length).flatMap(t=>e.map(e=>this.heightOf(t.section,e,t)));return[...t,`|`,...n].join(` `)}drawing(e,t,n){let r=this.storyId(e,t,n);return r?{id:r,content:this.drawn(r,e,n.number),story:this.story(r)}:null}element(e,t){let n=this.edgesAt(e),r=this.doc.createElement(`div`);r.className=`${Fp} foli-${t}`,r.setAttribute(`contenteditable`,`false`);let{style:i}=r;return i.position=`absolute`,i.inset=`0`,i.boxSizing=`border-box`,i.pointerEvents=`none`,i.userSelect=`none`,i.setProperty(`-webkit-user-select`,`none`),i.paddingLeft=`${n.left}px`,i.paddingRight=`${n.right}px`,t===`header`?i.paddingTop=`${n.header}px`:(i.display=`flex`,i.flexDirection=`column`,i.justifyContent=`flex-end`,i.paddingBottom=`${n.footer}px`),r}},Xp=`data-foli-note`,Zp=`foli-notes`;function Qp(e){let t=e.getBoundingClientRect(),n=e.ownerDocument,r=n.createRange(),i=[],a=n.createTreeWalker(e,NodeFilter.SHOW_TEXT|NodeFilter.SHOW_ELEMENT);for(let e=a.nextNode();e;e=a.nextNode())if(e.nodeType===Node.TEXT_NODE){if(e.parentElement?.style.verticalAlign===`super`)continue;r.selectNodeContents(e);for(let e of r.getClientRects())i.push({rect:e,text:!0})}else e.nodeName===`BR`&&i.push({rect:e.getBoundingClientRect(),text:!1});i.sort((e,t)=>e.rect.top-t.rect.top);let o=[];for(let{rect:e,text:t}of i){if(e.height<=0)continue;let n=o[o.length-1];n&&e.top<(n.top+n.bottom)/2?t&&!n.text?Object.assign(n,{top:e.top,bottom:e.bottom,text:t}):t===n.text&&(n.top=Math.min(n.top,e.top),n.bottom=Math.max(n.bottom,e.bottom)):o.push({top:e.top,bottom:e.bottom,text:t})}let s=o.slice(1).map((e,n)=>(o[n].bottom+e.top)/2-t.top);return s.push(t.height),s}var $p=e=>({kind:`footnote`,noteType:e,content:{type:`doc`,content:[{type:`paragraph`,attrs:{spacing:{after:0,line:240,lineRule:`auto`}},content:[{type:`opaqueInline`,attrs:{xml:`<w:r><w:${e}/></w:r>`,label:e}}]}]}}),em=$p(`separator`);function tm(e){if((e.noteType??`normal`)===`normal`)return e.content;let t={before:0,after:0,line:240,lineRule:`auto`};return{...e.content,content:(e.content.content??[]).map(e=>e.type===`paragraph`?{...e,attrs:{...e.attrs,spacing:{...t}}}:e)}}var nm=$p(`continuationSeparator`),rm=0,im=class{doc;options;cache;document=null;sections=[];resolver=null;references=[];numbers=new Map;open=null;constructor(e,t,n){this.doc=e,this.options=t,this.cache=n}setDocument(e,t,n,r){this.document=e,this.sections=t,this.resolver=n,this.references=r,this.numbers=new Map(r.map(e=>[e.story,e.text]))}story(e){let t=this.document?.stories;return t&&Object.hasOwn(t,e)?t[e]:void 0}separator(e,t){let n=Object.entries(this.document?.stories??{}).find(([,n])=>n.kind===e&&n.noteType===t);return n?{id:n[0],story:n[1]}:{id:`${e}:${t}`,story:t===`separator`?em:nm}}storyFor(e){return e===`footnote:separator`||e===`endnote:separator`?em:e.endsWith(`:continuationSeparator`)?nm:this.story(e)}drawn(e,t){let n=this.storyFor(e),r=this.numbers.get(e)??``,i=this.cache.get(n);i||(i=new Map,this.cache.set(n,i));let a=`${r}|${t}`,o=i.get(a);if(!o){let e=this.doc.createElement(`div`);e.className=Ip,e.style.paddingTop=`0.01px`;let s={...this.options,notes:{mark:r},...this.resolver?{resolver:this.resolver}:{}},c=Yf({...this.document,content:tm(n)},this.doc,s),l=Jp(c,e,!!this.resolver?.addsParagraphSpacing),{style:u}=e;u.position=`absolute`,u.visibility=`hidden`,u.width=`${t}px`,this.options.measureIn().append(e);let d=this.options.scale?.()??1,f=e.getBoundingClientRect().top,p=c.flatMap(({element:e})=>{let t=(e.getBoundingClientRect().top-f)/d;return Qp(e).map(e=>t+e/d)});e.remove(),u.position=``,u.visibility=``,u.width=``,p.length&&(p[p.length-1]=p.at(-1)+l),o={serial:++rm,template:e,lines:p.length?p:[0]},i.set(a,o)}return o}linesOf(e,t){let{lines:n}=this.drawn(e,t);return e===this.open?[n.at(-1)]:n}flowNote(e,t){return{id:e,lines:n=>this.linesOf(e,t[n]??t[0])}}widths(e){return jp(this.sections[e]??{}).widths}footnote(e,t){return Fd(e)===`footnote`&&this.numbers.has(e)&&this.story(e)?this.flowNote(e,this.widths(t)):null}flowRules(){if(!this.references.some(e=>e.kind===`footnote`&&this.story(e.story)))return;let e=this.widths(0);return{separator:this.flowNote(this.separator(`footnote`,`separator`).id,e),continuation:this.flowNote(this.separator(`footnote`,`continuationSeparator`).id,e)}}endnotes(){let e=new Map,t=Math.max(this.sections.length-1,0),n=this.document;if(!n)return e;let r=Ld(n,`endnote`).position===`sectEnd`;for(let{story:n,kind:i,section:a}of this.references){if(i!==`endnote`||!this.story(n))continue;let o=r?a:t,s=e.get(o)??[this.flowNote(this.separator(`endnote`,`separator`).id,this.widths(o))];s.push(this.flowNote(n,this.widths(o))),e.set(o,s)}return e}key(){if(!this.references.length)return``;let e=this.references.filter(e=>this.story(e.story)).map(({story:e,section:t})=>{let n=this.linesOf(e,this.widths(t)[0]);return`${n.length}:${n.at(-1)}`});return`${this.open??``}|${e.join(` `)}`}groups(e,t){let n=new Map;for(let r of e){let e=r.band??0,i=r.column??0,a=t(r.page,e),o=this.sections[a],s=!!this.document&&this.widths(a).length===1&&Ld(this.document,`footnote`,o).position===`beneathText`,c=!!r.end||s&&Fd(r.id)===`footnote`,l=`${r.page}|${e}|${c?i:0}|${c}`,u=n.get(l);u||(u={page:r.page,band:e,column:i,inFlow:c,pieces:[],section:a},n.set(l,u)),u.pieces.push(r)}return[...n.values()]}widthOf(e){let t=this.widths(e.section);return t[e.column]??t[0]}pieceHeight(e,t){let n=this.linesOf(e.id,t),r=Math.min(e.toLine,n.length);return(e.lead??0)+(n[r-1]??0)-(e.fromLine?n[e.fromLine-1]??0:0)}arranged(e){let t=this.widthOf(e),n=e=>(this.storyFor(e.id)?.noteType??`normal`)!==`normal`,r=e.pieces.filter(n),i=e.pieces.filter(e=>!n(e)),a=e.inFlow?1:this.widths(e.section).length,{height:o,columnOf:s}=Sp(i.map(e=>this.pieceHeight(e,t)),a);return{separators:r,notes:i,columnOf:s,columns:a,above:r.reduce((e,n)=>e+this.pieceHeight(n,t),0),height:o}}heightOf(e){let{above:t,height:n}=this.arranged(e);return t+n}keyOf(e){let t=this.widthOf(e);return e.pieces.map(e=>{let{serial:n}=this.drawn(e.id,t);return`${e.id}|${n}|${e.fromLine}|${e.toLine}|${e.lead??0}|${e.id===this.open}`}).join(`;`)}pieceElement(e,t){let n=this.widthOf(t),{lines:r,template:i}=this.drawn(e.id,n),a=this.doc.createElement(`div`);a.setAttribute(Xp,e.id),e.lead&&(a.style.marginTop=`${e.lead}px`);let o=i.cloneNode(!0);if(e.fromLine===0&&e.toLine>=r.length||e.id===this.open)return a.append(o),a;let s=e.fromLine?r[e.fromLine-1]:0,c=r[Math.min(e.toLine,r.length)-1];return a.style.overflow=`hidden`,a.style.height=`${c-s}px`,o.style.marginTop=`${-s}px`,e.fromLine&&o.setAttribute(`aria-hidden`,`true`),a.append(o),a}groupElement(e,t,n=t=>this.pieceElement(t,e),r=0){let i=this.doc.createElement(`div`);i.className=`${Fp} ${Zp}`,i.setAttribute(`contenteditable`,`false`);let{style:a}=i;a.userSelect=`none`,a.setProperty(`-webkit-user-select`,`none`),a.width=`${this.widthOf(e)}px`,r&&(a.marginTop=`${r}px`),t&&(a.position=`absolute`,a.left=`${t.left}px`,a.bottom=`${t.bottom}px`);let{separators:o,notes:s,columnOf:c,columns:l,above:u}=this.arranged(e);if(l===1)return i.append(...e.pieces.map(n)),i;let{widths:d,gaps:f}=jp(this.sections[e.section]??{});a.width=`auto`,a.display=`flex`,a.alignItems=`flex-start`;for(let e=0;e<l;e++){let t=this.doc.createElement(`div`);t.style.flex=`none`,t.style.width=`${d[e]}px`,t.style.marginRight=`${f[e]??0}px`,e?t.style.paddingTop=`${u}px`:t.append(...o.map(n)),t.append(...s.filter((t,n)=>c[n]===e).map(n)),i.append(t)}return i}footPlace(e,t){return{left:e.left,bottom:e.bottom+t}}stacked(e,t){let n=new Map;for(let r of t)r.page===e.page&&!r.inFlow&&r.band>e.band&&n.set(r.band,Math.max(n.get(r.band)??0,this.heightOf(r)));return[...n.values()].reduce((e,t)=>e+t,0)}},am=`foli-word-page`,om=`br[${of}],br[${sf}]`,sm={width:12240,height:15840,margin:1440};function cm(e){let t=e.margins??{};return{width:(e.pageSize?.width??sm.width)*Q,height:(e.pageSize?.height??sm.height)*Q,top:Math.abs(t.top??sm.margin)*Q,right:(t.right??sm.margin)*Q,bottom:Math.abs(t.bottom??sm.margin)*Q,left:((t.left??sm.margin)+(t.gutter??0))*Q}}var lm=(e,t)=>e.width===t.width&&e.height===t.height&&e.top===t.top&&e.bottom===t.bottom&&e.left===t.left&&e.right===t.right;function um(e,t){let n=e.createElement(`div`);n.className=am;let{style:r}=n;r.boxSizing=`border-box`,r.position=`relative`,r.isolation=`isolate`,r.width=`${t.width}px`,r.height=`${t.height}px`,r.padding=`${t.top}px ${t.right}px ${t.bottom}px ${t.left}px`,r.background=`#fff`,r.color=`#000`,r.overflow=`hidden`;let i=e.createElement(`div`);return i.style.display=`flow-root`,n.append(i),{page:n,body:i}}function dm(e){return t=>{let n=e.ownerDocument.createElement(`div`),{style:r}=n;r.position=`absolute`,r.visibility=`hidden`,r.fontFamily=t,r.fontSize=`100px`,r.lineHeight=`normal`,r.whiteSpace=`nowrap`,n.textContent=`x`,e.append(n);let i=n.getBoundingClientRect().height;return n.remove(),i>0?i/100:1.2}}function fm(e,t,n){let r=e.querySelectorAll(`:scope > table > tbody > tr[data-foli-cant-split]`);if(!r.length)return t;let i=e.getBoundingClientRect().top,a=[...r].map(e=>{let t=e.getBoundingClientRect();return[t.top-i,t.bottom-i]}).filter(([e,t])=>t-e<=n);return t.filter(e=>!a.some(([t,n])=>e>t+.5&&e<n-.5))}function pm(e){let t=0;for(let n of e.querySelectorAll(`:scope > table > tbody > tr`)){if(!n.dataset||!(`foliHeader`in n.dataset))break;t=n.getBoundingClientRect().bottom}return t?t-e.getBoundingClientRect().top:0}function mm(e,t,n){let r=e.getBoundingClientRect().top;return[...e.querySelectorAll(`br[${n}]`)].map(e=>{let n=e.getBoundingClientRect().top-r,i=t.findIndex(e=>n<e);return i<0?t.length-1:i})}function hm(e,t,n={}){let r=t.ownerDocument,i=e.stories?Gn(e.content):null,a=(n.review??`markup`)!==`markup`,o=t=>i?Vd(i,e,{hideDeleted:a,...t?{pageOf:t}:{}}).filter(e=>!a||!e.deleted):[],s=o(),c=Hd(s),l=Yf(e,r,{...n,lineRatio:dm(t),notes:{references:c}}),u=[],d=[],f=dm(t),p=new Yp(r,{...n,lineRatio:f,measureIn:()=>t},new WeakMap),m=new Jr(e);p.setDocument(e,d,m);let h=new im(r,{...n,lineRatio:f,measureIn:()=>t},new WeakMap),g=new Map,_=new Map,v=[],y=e=>{let n=cm(e),i=jp(e),a=d.length;d.push(e);let o={index:a,start:e.type??`nextPage`,columns:i.widths.length,pageStart:e.pageNumbers?.start,box:e=>({height:p.boxHeight(a,e)}),samePage:e=>lm(n,g.get(e))};g.set(o,n);let{page:s,body:c}=um(r,n);s.style.position=`absolute`,s.style.visibility=`hidden`,s.style.height=`auto`;let l=r.createElement(`div`);l.style.display=`flow-root`,l.style.width=`${i.widths[0]}px`,c.append(l),t.append(s),l.append(...v.map(e=>e.element));let f={setup:e,geometry:n,columns:i,blocks:v,flow:o,measuring:s,column:l};for(let e of v)_.set(e,f);u.push(f),v=[]};for(let e of l)v.push(e),e.section&&y(e.section);(v.length||!u.length)&&y(e.section),h.setDocument(e,d,m,s),u.forEach((e,t)=>{let n=u[t+1];e.flow.balanced=!!n&&e.flow.columns>1&&n.setup.type===`continuous`&&lm(e.geometry,n.geometry)});let b=new Map,x=(e,t)=>{let n=_.get(e),r=b.get(e)??new Map;b.set(e,r);let i=r.get(t);if(i)return i;let{column:a,geometry:o}=n,s=o.height-o.top-o.bottom,c=e=>{let n=a.style.width;a.style.width=`${t}px`;let r=e();return a.style.width=n,r},l=c(()=>e.element.getBoundingClientRect().height),u=!!e.element.querySelector(om),d=e.keepLines&&!u&&l<=s,f,p=()=>(f??=c(()=>fm(e.element,Qp(e.element),s)),f),m={height:l,shown:p,lines:()=>d?[l]:p(),breaks:t=>c(()=>mm(e.element,m.lines(),t)),references:()=>c(()=>{let t=e.element.getBoundingClientRect().top,n=m.lines();return[...e.element.querySelectorAll(`[${Cf}]`)].map(e=>{let r=e.getBoundingClientRect().bottom-t,i=n.findIndex(e=>r<=e+1);return{story:e.getAttribute(Cf),line:i<0?n.length-1:i}})})};return r.set(t,m),m},S=(e,t)=>e.columns.widths[t.column??0],C=new Map;for(let e of l){let t=e.element.querySelectorAll(`[data-foli-cell]`);if(!t.length)continue;let n=e.element.getBoundingClientRect().top;C.set(e,[...t].map(e=>({top:e.getBoundingClientRect().top-n,text:e.textContent??``})))}let w=new Map,ee=h.endnotes(),te=(e,t)=>!l[t+1]||_.get(l[t+1])!==_.get(e),T=l.map((e,t)=>{let n=_.get(e),{widths:r}=n.columns,i=x(e,r[0]),a=e.element.querySelector(`tr`)?pm(e.element):0;a&&w.set(e,a);let o=l[t+1],s=t=>!!e.element.querySelector(`br[${t}]`),c=s(of),u=s(sf),d=n.flow.index??0;return{notes:e.element.querySelector(`[data-foli-note-ref]`)?t=>x(e,r[t]).references().flatMap(({story:e,line:t})=>{let n=h.footnote(e,d);return n?[{line:t,note:n}]:[]}):void 0,endnotes:te(e,t)?ee.get(d):void 0,height:i.height,marginTop:e.before,marginBottom:e.after,repeat:a,anyLine:!!e.element.querySelector(`:scope > table`),keepWithNext:e.keepNext,section:n.flow,sectionMark:!!e.section&&!e.element.textContent&&!e.element.querySelector(`[data-foli-picture]`),lines:i.lines,inColumn:r.every(e=>e===r[0])?void 0:t=>x(e,r[t]),breaksAfter:(t=0)=>{let n=x(e,r[t]),i=c?n.breaks(of):[];return o?.pageBreakBefore&&i.push(n.lines().length-1),i},columnBreaksAfter:(t=0)=>u?x(e,r[t]).breaks(sf):[]}}),ne={orphans:2,widows:2,spacing:`word`,addSpacing:e.settings?.doNotUseHTMLParagraphAutoSpacing===!0,evenAndOddHeaders:e.settings?.evenAndOddHeaders===!0,notes:h.flowRules()},E=bp(T,0,ne),D=xp(T,E);for(let e=0;e<2&&p.settle(D);e++)E=bp(T,0,ne),D=xp(T,E);if(d.some(t=>Ld(e,`footnote`,t).restart===`eachPage`)){let t=new Map;for(let e of Tp(E))!e.fromLine&&!t.has(e.id)&&t.set(e.id,e.page);s=o((e,n)=>t.get(n));let n=Hd(s);h.setDocument(e,d,m,s);for(let e of l)for(let t of e.element.querySelectorAll(`[${Cf}]`))t.textContent=n.get(t.getAttribute(`data-foli-note-ref`))??``;E=bp(T,0,ne),D=xp(T,E)}let{fragments:O,gaps:re}=E,ie=Tp(E);l.forEach((e,t)=>{let n=O[t]??[];if(n.length<2)return;let r=_.get(e);for(let t of n)x(e,S(r,t)).lines()});for(let e of u)e.measuring.remove();let ae=[];l.forEach((e,t)=>{for(let n of O[t]??[]){let t=ae[n.page]??[];ae[n.page]=t,t[n.band??0]??=_.get(e)}});let k=Math.max(1,ae.length,...ie.map(e=>e.page+1)),A=[];for(let e=k-1;e>=0;e--)A[e]=ae[e]?.[0]??A[e+1]??u.at(-1);let oe=A.map((e,t)=>{let n=um(r,e.geometry);n.page.setAttribute(Dp,String(e.flow.index??0));let i=D[t];if(!i?.sectionPages)return n;let{top:a,bottom:o}=p.margins(i.section,i);n.page.style.paddingTop=`${a}px`,n.page.style.paddingBottom=`${o}px`;for(let e of[`header`,`footer`]){let t=p.drawing(i.section,e,i);if(!t)continue;let r=p.element(i.section,e);r.append(t.content.content.cloneNode(!0)),n.page.append(r)}return n}),se=new Map,j=(e,t)=>{let{body:n}=oe[e.page],i=ae[e.page]??[t];if(i.length===1&&t.flow.columns===1)return n;let a=e.band??0;for(let t=0;t<=a;t++){let a=`${e.page} ${t}`;if(se.has(a))continue;let o=Np(r,i[t].columns);se.set(a,o),n.append(o.band)}let o=se.get(`${e.page} ${a}`);return e.lead&&(o.band.style.marginTop=`${e.lead}px`),o.columns[e.column??0]},ce=(e,t)=>(ae[e]?.[t]??A[e])?.flow.index??0,le=e=>h.groups(e,ce),ue=le(ie).filter(e=>!e.inFlow),de=new Map,M=[],fe=[];l.forEach((e,t)=>{let n=_.get(e),i=O[t]??[],a=t=>x(e,S(n,t)).lines();i.forEach((o,s)=>{let c=j(o,n),l=e.element;if(i.length>1){let t=a(o),n=o.fromLine?t[o.fromLine-1]??0:0,i=o.toLine===1/0?t[t.length-1]??0:t[o.toLine-1]??0,c=r.createElement(`div`);c.style.overflow=`hidden`,c.style.height=`${i-n}px`;let u=s===0?e.element:e.element.cloneNode(!0);s>0&&u.setAttribute(`aria-hidden`,`true`),u.style.marginTop=`${-n}px`,c.append(u),l=c;let d=s>0?w.get(e)??0:0;if(d){let t=r.createElement(`div`);t.style.overflow=`hidden`,t.style.height=`${d}px`;let n=e.element.cloneNode(!0);n.setAttribute(`aria-hidden`,`true`),n.style.marginTop=`0`,t.append(n),l=r.createElement(`div`),l.append(t,c)}}o.mark&&(l.style.position=`absolute`),l.style.marginTop=`${o.fromLine===0?re[t]??0:0}px`,c.append(l),M.push({page:o.page,nodes:s===0?e.nodes:null,mark:!!o.mark,lines:()=>(o.toLine===1/0?x(e,S(n,o)).shown().length:o.toLine)-o.fromLine})});for(let t of C.get(e)??[]){let e=i[0]?.page??0;for(let n of i){let r=n.fromLine?a(n)[n.fromLine-1]??0:0;t.top+.5>=r&&(e=n.page)}fe.push({page:e,text:t.text})}let o=i[0];if(o)for(let t of e.nodes)de.set(t,o.page)});for(let e of le(ie))e.inFlow&&j({page:e.page,band:e.band,column:e.column},u[e.section]).append(h.groupElement(e,null,void 0,e.pieces[0]?.end?0:wp(T,E,e.page,e.band,e.column)));for(let e of le(ie)){if(e.inFlow)continue;let{page:t}=oe[e.page],n=u[e.section],r=D[e.page],i=r?.sectionPages?p.margins(r.section,r).bottom:n.geometry.bottom,a=h.footPlace({left:n.geometry.left,bottom:i},h.stacked(e,ue));t.append(h.groupElement(e,a))}let pe=oe.map(({page:e})=>(t.append(e),e)),me=null,he=null,ge={pages:D.length,pageAt:t=>{if(!he){let t=[];(i??Gn(e.content)).forEach((e,n)=>{t.push(n)}),he=t}let n=he.length-1;for(;n>0&&he[n]>t;)n--;for(;n>0&&!de.has(n);)n--;let r=D[de.get(n)??-1];if(!r)return null;let a=d[r.section]?.pageNumbers?.format;return{number:r.number,sectionPages:r.sectionPages,format:a}}},_e=e=>`${e}px`;return{pages:pe,fieldLayout:ge,printStyles:()=>{let e=u.at(-1).geometry;return Op(`.${am}`,{width:_e(e.width),height:_e(e.height)},u.map(({geometry:e,flow:t})=>({width:_e(e.width),height:_e(e.height),index:t.index??0})),`word`)},pageOf:e=>de.get(e),lineOf:e=>{if(!me){me=new Map;let e=-1,t=1;for(let n of M){n.page!==e&&(e=n.page,t=1);for(let e of n.nodes??[])me.set(e,n.mark?Math.max(t-1,1):t);n.mark||(t+=n.lines())}}return me.get(e)},cellParagraphs:()=>fe,destroy:()=>{for(let e of pe)e.remove()}}}var gm=new Set([`PAGE`,`NUMPAGES`,`SECTIONPAGES`,`PAGEREF`]);function _m(e){let t=e.ownerDocument,n=new Map;for(let t of e.querySelectorAll(`[data-foli-bookmark]`)){let e=t.getAttribute(`data-foli-bookmark`)??``;e&&!n.has(e)&&!t.closest(`[aria-hidden]`)&&n.set(e,t)}let r=0;for(let i of e.querySelectorAll(`[data-href]`)){let e=i.dataset.href??``,a=null;if(e.startsWith(`#`)){let t=n.get(e.slice(1));t&&(t.id||=`foli-bookmark-${r++}`,a=`#${t.id}`)}else/^[a-z][a-z0-9+.-]*:/i.test(e)&&ue(e)&&(a=e);if(!a)continue;let o=t.createElement(`a`);o.href=a,o.style.color=`inherit`,o.style.textDecoration=`none`,i.replaceWith(o),o.append(i)}}var vm=1e4;async function ym(e){let t=[...e.images].filter(e=>!e.complete),n;await Promise.race([Promise.all(t.map(e=>e.decode().catch(()=>null))),new Promise(e=>{n=setTimeout(e,vm)})]),clearTimeout(n);for(let e of t)e.complete||e.removeAttribute(`src`)}async function bm({document:e,images:t,review:n,styles:r}){let i=window.document,a=i.createElement(`style`);a.textContent=`html,body{margin:0;background:#fff}${r}`,i.head.append(a),await Promise.all([...i.fonts].map(e=>e.load().catch(()=>null)));let o=i.body,s=e=>t[e]??null,c=e=>hm(e,o,{review:n,resource:s}),l=Un(e),u=c(l),d=af({document:l}),f=Rl(d,{layout:u.fieldLayout});if(f.updated){u.destroy(),u=c(d.getDocument());let e=Rl(d,{layout:u.fieldLayout,only:e=>gm.has(e.name)});e.updated&&(u.destroy(),u=c(d.getDocument())),f.updated+=e.updated}_m(o);let p=i.createElement(`style`);return p.textContent=u.printStyles(),i.head.append(p),await ym(i),await i.fonts.ready,{pages:u.pages.length,fields:f}}return window.foliPdf={render:bm},e.imagesLoaded=ym,e})({});
|