@docx-editor.dev/pro 2.38.0 → 2.39.0-canary.20261118032846.sha-764bd09
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-4UYICEW4.cjs +11 -0
- package/dist/{chunk-CNQG7JPW.js → chunk-5OK2UOME.js} +1 -1
- package/dist/chunk-6WITPFTY.js +11 -0
- package/dist/{chunk-664SJBNS.js → chunk-KQ4A2C2I.js} +10 -10
- package/dist/{chunk-HMIXD27V.js → chunk-QVYUMMPG.js} +1 -1
- package/dist/{chunk-VW2UA4EW.cjs → chunk-UEIXRTAG.cjs} +1 -1
- package/dist/{chunk-KPF2TI6O.cjs → chunk-UZT77RTY.cjs} +1 -1
- package/dist/{chunk-35PECGD2.cjs → chunk-XLGO5HZY.cjs} +10 -10
- package/dist/collaboration/hocuspocus.cjs +1 -1
- package/dist/collaboration/hocuspocus.js +1 -1
- package/dist/collaboration/index.cjs +2 -2
- package/dist/collaboration/index.js +1 -1
- package/dist/collaboration/webrtc.cjs +1 -1
- package/dist/collaboration/webrtc.js +1 -1
- package/dist/{document-session-UQQ5J2K4.js → document-session-34MWMPX2.js} +1 -1
- package/dist/{document-session-O4SGT36R.cjs → document-session-V36OWTGE.cjs} +1 -1
- package/dist/drawing/index.cjs +1 -1
- package/dist/drawing/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/react/index.cjs +2 -2
- package/dist/react/index.js +2 -2
- package/dist/vue/index.cjs +2 -2
- package/dist/vue/index.js +1 -1
- package/package.json +4 -4
- package/dist/chunk-A4FYA5OD.cjs +0 -11
- package/dist/chunk-EPSDX3UA.js +0 -11
|
@@ -3,14 +3,14 @@ Copyright (c) 2026 Eigenpal, Inc. All rights reserved.
|
|
|
3
3
|
Licensed under the EigenPal Pro Evaluation License 1.0. See LICENSE.md in this package.
|
|
4
4
|
Production use requires a commercial agreement: licensing@eigenpal.com
|
|
5
5
|
*/
|
|
6
|
-
import*as z from'yjs';import {XML_NAMESPACE_URI,WML_NAMESPACE_URI,partNameKey,readOoxmlPackage,refreshBoundContent,isStoryPart,normalizeParagraphIdentity,withPart,TreePackageStore,writeOoxmlPackage,writeOoxmlPackageKeepingRevisionIds,isDangerousKey,normalizePartName,relsPartNameFor,CUSTOM_XML_PROPS_TYPE,resolveInternalTarget,DATASTORE_NAMESPACE_URI,CUSTOM_XML_REL,CUSTOM_XML_PROPS_REL,resolveContentType,isRangeMarkerKind,buildRelationshipSet,resolveRelationship,ORIGIN_IDS,segmentsOf}from'@docx-editor.dev/core/store';import {reportHistoryGroup,isJournalOutsideUndo,historyGroupOfJournal,registerUndoHistoryPosition,mapOffsetAcrossText}from'@docx-editor.dev/core/collaboration/replication';import {createCollaborationStatusTracker,safeParticipantColor}from'@docx-editor.dev/core/collaboration';import {sha256FontBytes}from'@docx-editor.dev/core/layout';function
|
|
7
|
-
Collaboration upgrade required. Save local changes and use a compatible app version, or upgrade the saved room. See ${af}#upgrade-saved-rooms`:i);this.code=n;this.detail=o;this.name="CollaborationSchemaError";}code;detail};var It=Object.freeze({protocolVersion:1,sharedSchemaVersion:5,repairVersion:4,canonicalModelVersion:1});function wr(t){let e=t!==null&&typeof t=="object"&&!Array.isArray(t)?t:{};for(let n of Object.keys(It)){let o=It[n],r=Object.hasOwn(e,n)?e[n]:void 0;if(r===o)continue;let i=r===void 0?"missing":typeof r=="number"&&Number.isSafeInteger(r)?String(r):"invalid";return {code:n==="protocolVersion"?"protocol-version-mismatch":"schema-version-mismatch",detail:`${n}: expected ${o}, received ${i}`}}return null}function Ob(t){let e=wr(t);if(e)throw new N(e.code,e.detail)}var lf=It.protocolVersion,df=It.sharedSchemaVersion,cf=It.repairVersion,uf=It.canonicalModelVersion,kr="docx-package-meta-v1",mn="docx-package-nodes-v1",ff="docx-package-parts-v1",pf="docx-package-rels-v1",hf="docx-package-overrides-v1",gf="docx-package-defaults-v1",mf="docx-package-binaries-v1",yf="docx-package-namespaces-v1",bf="docx-package-attributes-v1",If="docx-package-bindings-v1",Vn="s",Jn="b",Pe="t",xt="children",me="deleted",ue="replacedBy",St="undone",yn="splitFrom",wt="splitLineage";var ge="",zs="-",$s=Object.freeze({kind:"docx-package-bootstrap"}),vr=Object.freeze({kind:"docx-package-journal"});function kt(t){return t.kind==="textValue"}function $(t){return !kt(t)}var xf=Object.freeze(new Set(["missing-node","child-id-not-in-registry","cycle"])),Sf=200;function vt(t){let e=new Map;for(let n of t)xf.has(n.code)&&e.set(n.code,(e.get(n.code)??0)+1);return e.size===0?null:[...e].sort(([n],[o])=>n<o?-1:n>o?1:0).map(([n,o])=>`${n}=${o}`).join(",").slice(0,Sf)}function Ws(t){return {meta:t.getMap(kr),nodes:t.getMap(mn),parts:t.getMap(ff),relationships:t.getMap(pf),overrides:t.getMap(hf),defaults:t.getMap(gf),binaries:t.getMap(mf),namespaces:t.getMap(yf),attributes:t.getMap(bf),bindings:t.getMap(If)}}var Ks=[["http://schemas.openxmlformats.org/wordprocessingml/2006/main","w"],["http://schemas.openxmlformats.org/officeDocument/2006/relationships","r"],["http://schemas.openxmlformats.org/package/2006/relationships","pr"],["http://schemas.openxmlformats.org/package/2006/content-types","ct"],["http://www.w3.org/XML/1998/namespace","xml"],["http://www.w3.org/2000/xmlns/","xmlns"],["http://schemas.openxmlformats.org/drawingml/2006/main","a"],["http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing","wp"],["http://schemas.openxmlformats.org/drawingml/2006/picture","pic"],["http://schemas.openxmlformats.org/officeDocument/2006/math","m"],["http://schemas.openxmlformats.org/markup-compatibility/2006","mc"],["http://schemas.microsoft.com/office/word/2010/wordml","w14"],["http://schemas.microsoft.com/office/word/2012/wordml","w15"],["http://schemas.microsoft.com/office/word/2015/wordml/symex","w16se"],["http://schemas.microsoft.com/office/word/2016/wordml/cid","w16cid"],["http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument","od"],["http://schemas.openxmlformats.org/officeDocument/2006/extended-properties","ep"],["http://schemas.openxmlformats.org/package/2006/metadata/core-properties","cp"],["http://purl.org/dc/elements/1.1/","dc"],["http://purl.org/dc/terms/","dcterms"],["http://www.w3.org/2001/XMLSchema-instance","xsi"],["http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes","vt"],["http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas","wpc"],["http://schemas.microsoft.com/office/word/2010/wordprocessingGroup","wpg"],["http://schemas.microsoft.com/office/word/2010/wordprocessingInk","wpi"],["http://schemas.microsoft.com/office/word/2010/wordprocessingShape","wps"],["http://schemas.openxmlformats.org/drawingml/2006/chart","c"],["http://schemas.openxmlformats.org/schemaLibrary/2006/main","sl"]],wf=new Map(Ks),kf=new Map(Ks.map(([t,e])=>[e,t]));function vf(t){let e=0xcbf29ce484222325n,n=0x100000001b3n;for(let o=0;o<t.length;o+=1)e^=BigInt(t.charCodeAt(o)),e=e*n&0xffffffffffffffffn;return e.toString(16).padStart(16,"0")}function Lt(t){return t.length===0?zs:wf.get(t)??`n${vf(t)}`}function zt(t,e,n){let o=Lt(e);return e.length===0||O(o)||Re(e,n)||t.get(o)!==e&&t.set(o,e),o}function Rt(t,e){if(e===zs||O(e))return "";let n=t.get(e);return typeof n=="string"?n:kf.get(e)??""}function Lr(t,e,n,o){return `${t}${ge}${e}${ge}${n}${ge}${o}`}function Lf(t){let e=t.split(ge);return {kind:e[0]||"generic",namespaceId:e[1]??"",localName:e[2]??"",prefix:e[3]??""}}function Ge(t){let e=t.has(Vn)?t.get(Vn):t.get(Jn);return Lf(typeof e=="string"?e:"")}function Rr(t,e,n){return `${t}${ge}${e}${ge}${n}`}function bn(t){let e=t.split(ge);if(e.length!==3)return null;let n=e[0],o=e[1],r=e[2];return n.length===0||r.length===0?null:{logicalId:n,namespaceId:o,localName:r}}function Or(t,e){return `${t}${ge}${e}`}function Ot(t){let e=t.split(ge);if(e.length!==2)return null;let n=e[0],o=e[1];return n.length===0?null:{logicalId:n,prefix:o}}function Vs(t,e){return `${t}${ge}${e}`}function Js(t){let e=t.indexOf(ge);return e<0?{prefix:"",value:t}:{prefix:t.slice(0,e),value:t.slice(e+1)}}function Hs(t){let e=new z.Map,n=Lr(t.kind,t.namespaceId,t.localName,t.prefix??"");e.set(Jn,n);let o=new z.Array;return t.childIds&&t.childIds.length>0&&o.push([...t.childIds]),e.set(xt,o),e}function Hn(t){let e=new z.Map;return e.set(Pe,new z.Text(t)),e}function Xs(t,e,n){let o=new z.Map;return o.set("id",t),o.set("rootId",e),o.set("contentType",n),o}function Gs(t){let e=new z.Map;return e.set("ownerPart",t.ownerPart),e.set("id",t.id),e.set("type",t.type),e.set("rawTarget",t.rawTarget),e.set("targetMode",t.targetMode),e.set("order",t.order),e}function qs(t){let e=new z.Map;return e.set("digest",t.digest),e.set("size",t.size),e.set("mediaType",t.mediaType),e.set("storageKey",t.storageKey),e}function Xn(t){return wr({protocolVersion:t.get("protocolVersion"),sharedSchemaVersion:t.get("sharedSchemaVersion"),repairVersion:t.get("repairVersion"),canonicalModelVersion:t.get("canonicalModelVersion")})}function Qs(t){t.set("protocolVersion",lf),t.set("sharedSchemaVersion",df),t.set("repairVersion",cf),t.set("canonicalModelVersion",uf),t.set("initialized",true);}function Zs(t,e){let n=_e(t,e);return n!==void 0&&n.deleted}function $t(t){return xr(t)!==null}var js=new WeakMap,Rf={origins:new Set,fields:new Set,listed:new Set};function Er(t){let e=xr(t);if(e===null)return Rf;let n=js.get(e);if(n)return n;let o=new Set,r=new Set,i=new Set;try{for(let a of z.decodeUpdateV2(e).structs)if(a instanceof z.Item&&(a.origin&&o.add(`${a.origin.client}:${a.origin.clock}`),a.parent instanceof z.ID&&a.parentSub!==null&&r.add(`${a.parent.client}:${a.parent.clock}:${a.parentSub}`),a.parentSub===null&&a.content instanceof z.ContentAny))for(let l of a.content.arr)typeof l=="string"&&i.add(l);}catch{}let s={origins:o,fields:r,listed:i};return js.set(e,s),s}function ea(t,e){if(t.has(e)||t.doc===null)return false;let n=Kn(t);return n!==null&&Er(t.doc).fields.has(`${n.client}:${n.clock}:${e}`)}function ta(t,e){return $t(t)&&Er(t).listed.has(e)}function Cr(t,e){if(t.has(e)||t.doc===null||!$t(t.doc))return false;let n=_e(t,e);if(n===void 0||!n.deleted)return false;let o={client:n.id.client,clock:n.id.clock+Math.max(1,n.length)-1};return Er(t.doc).origins.has(`${o.client}:${o.clock}`)}function _(t){return t instanceof z.Map}function ie(t){if(!_(t))return null;let e=t.get(xt);return e instanceof z.Array?e:null}function Wt(t){return _(t)&&t.get(Pe)instanceof z.Text}function Ae(t){return _(t)&&t.get(me)===true}function Gn(t){return _(t)&&t.get(St)===true}function qn(t){return Tr(t,ue)}function Tr(t,e){if(!_(t))return null;let n=t.get(e);return typeof n=="string"&&n.length>0?n:null}function na(t,e){let n=o=>{let r=t.get(o);return _(r)?_e(r,ue)?.id??{client:0,clock:0}:{client:0,clock:0}};return [...e??[]].sort((o,r)=>{let i=n(o),s=n(r);return i.clock-s.clock||i.client-s.client||(o<r?-1:o>r?1:0)})}function In(t){return Tr(t,yn)}function Et(t){return Tr(t,wt)??In(t)}function ra(t,e){let n=t.get(e);if(!_(n))return null;if(Wt(n)){let o=n.get(Pe);return {isText:true,textLength:o instanceof z.Text?o.length:0,children:[]}}return {isText:false,textLength:0,children:ie(n)?.toArray()??[]}}function ia(t,e){let n=t.get(e);return _(n)?Wt(n)?"textValue":Ge(n).kind:null}function Qn(t,e){if(t.length!==e.length)return false;for(let n=0;n<t.length;n+=1)if(t[n]!==e[n])return false;return true}function sa(t,e,n,o,r){let i=Ge(e);return {logicalId:t,kind:i.kind,namespaceUri:Rt(n.namespaces,i.namespaceId),localName:i.localName,prefix:i.prefix.length>0?i.prefix:void 0,attributes:o,bindings:r,childIds:ie(e)?.toArray()??[]}}function aa(t){let e=Kn(t);return e&&Ys(e.client,e.clock)}function la(t){return typeof t=="string"?t:""}function G(t){return String(t)}function Pr(t){return !O(t)}function da(t){t.forEach(e=>{if(_(e)&&(e.has("parent")||e.has("parentId")))throw new Error("registry record must not replicate a parent field")});}function De(t){return {id:t.id,kind:t.kind,namespaceUri:t.namespaceUri,localName:t.localName,namespaceBindings:t.namespaceBindings,attributes:t.attributes,children:t.children,...t.prefix===void 0?{}:{prefix:t.prefix}}}function qe(t,e,n=t.id){return {...t,id:n,children:e}}function ca(t){return t.kind!=="textValue"}function ua(t){return t.filter(ca)}function Kt(t){if(!ca(t))throw new Error(`expected an element, found text node ${t.id}`);return t}function Zn(t,e,n,o=[]){return Object.freeze(De({id:t,kind:e,namespaceUri:WML_NAMESPACE_URI,localName:n,prefix:"w",namespaceBindings:Object.freeze([]),attributes:Object.freeze([...o]),children:Object.freeze([])}))}function eo(t){return De({id:t,kind:"generic",namespaceUri:"",localName:"",namespaceBindings:[],attributes:[],children:[]})}function Vt(t,e){return {id:t,kind:"textValue",value:e}}function Jt(t){return t}var Cf=new Set(["t","delText","instrText","delInstrText"]),Tf=new Set(["hyperlink","ins","del","moveFrom","moveTo","sdt","sdtContent","fldSimple","smartTag","customXml","dir","bdo"]),Mf=new Set(["sdtPr","sdtEndPr","smartTagPr","customXmlPr","fldData"]);function Ar(t,e){return t.kind!=="textValue"&&t.namespaceUri===WML_NAMESPACE_URI&&e.has(t.localName)}function Ht(t,e=[]){return qe(t,e)}function Pf(t){return Ar(t,Cf)&&t.children.every(e=>e.kind==="textValue")}function xn(t){let e=[],n=[],o={run:null,runProperties:null,properties:[],text:null,textValueId:null,wrap:[]},r=(a,l)=>{let d=a.children.find(f=>f.kind==="runProperties"),c={...o,run:Ht(a),runProperties:d?Ht(d):null,properties:d?ua(d.children):[],wrap:l},u=0;for(let f of a.children)if(f!==d)if(u+=1,Pf(f)){let p=f.children.map(g=>g.kind==="textValue"?g.value:"").join(""),h={...c,text:Ht(f),textValueId:f.children[0]?.id??null};p.length===0&&e.push({kind:"anchor",attributes:h});for(let g=0;g<p.length;g+=1)e.push({kind:"char",value:p[g],attributes:h});}else e.push({kind:"embed",node:f,attributes:c});u===0&&e.push({kind:"anchor",attributes:c});},i=(a,l)=>{for(let d of a)if(d.kind==="run")r(d,l);else if(Ar(d,Tf)){let c=d.children.filter(p=>Ar(p,Mf)),u=[...l,Ht(d,c)],f=d.children.filter(p=>!c.includes(p));f.length===0&&e.push({kind:"anchor",attributes:{...o,wrap:u}}),i(f,u);}else e.push({kind:"embed",node:d,attributes:{...o,wrap:l}});},s=[];for(let a of t.children)a.kind==="paragraphProperties"?n.push(a):s.push(a);return i(s,[]),{shell:Ht(t,n),items:e}}function to(t){return {shell:t,children:[...t.children],openRun:null,openText:null}}function Af(t){return t.runSignature!==void 0?t.runSignature:[t.run.id,t.runProperties?.id??"",...t.properties.map(e=>e.id)].join("")}function fa(t){let e=to(t.shell),n=[e],o=s=>{let a=s.openText;a&&(a.value.length>0&&a.builder.children.push(Vt(a.valueId,a.value)),s.openText=null);},r=s=>{s.openRun&&o(s.openRun.builder),s.openRun=null;};for(let s of t.items){let{wrap:a}=s.attributes,l=s.attributes.wrapSignatures,d=(h,g)=>l?h.signature===l[g]:h.shell.id===a[g].id,c=1;for(;c<n.length&&c-1<a.length&&d(n[c],c-1);)c+=1;for(;n.length>c;)r(n[n.length-1]),n.pop();for(let h=c-1;h<a.length;h+=1){let g=n[n.length-1];r(g);let m=to(a[h]);m.signature=l?.[h],g.children.push(m),n.push(m);}let u=n[n.length-1];if(!s.attributes.run){r(u),s.kind==="embed"&&u.children.push(s.node);continue}let f=Af(s.attributes);if(u.openRun?.key!==f){r(u);let h=to(s.attributes.run);s.attributes.runProperties&&h.children.push(Ht(s.attributes.runProperties,s.attributes.properties)),u.children.push(h),u.openRun={key:f,builder:h};}let p=u.openRun.builder;if(s.kind==="embed"){o(p),p.children.push(s.node);continue}if(s.attributes.text){if(p.openText?.key!==s.attributes.text.id){o(p);let h=to(s.attributes.text);p.children.push(h),p.openText={key:s.attributes.text.id,builder:h,valueId:s.attributes.textValueId??`${s.attributes.text.id}/value`,value:""};}s.kind==="char"&&(p.openText.value+=s.value);}}for(;n.length>0;)r(n.pop());let i=s=>"shell"in s?Object.freeze(qe(s.shell,Object.freeze(s.children.map(i)))):s;return Kt(i(e))}var Yr={kind:"run",localName:"r"},no={kind:"runProperties",localName:"rPr"},_r={kind:"text",localName:"t"},oo=32768,$e=24;function pa(t,e=0){if(e>$e)return 1/0;if(!se(t))return 1;let n=t.c,o=1;if(Array.isArray(n))for(let r of n)o+=pa(r,e+1);return o}var Be=class extends Error{constructor(n,o){super(`shared text value refused (${n}): ${o}`);this.code=n;this.detail=o;}code;detail};function Br(t,e,n=0){if(n===0&&pa(t)>oo)return "too-many-nodes";if(n>$e)return "tree-too-deep";if(!se(t))return "invalid-string";for(let[r,i]of Object.entries(t))if(r==="v"&&typeof i=="string"){if(i.length>e.maxTextLength)return "text-too-long"}else if(typeof i=="string"&&i.length>e.maxStringLength)return "invalid-string";for(let r of ["a","b"]){let i=t[r];if(Array.isArray(i)){if(i.length>e.maxAttributes)return "too-many-attributes";for(let s of i)if(Array.isArray(s))for(let a of s){if(typeof a=="string"&&a.length>e.maxStringLength)return "invalid-string";if(typeof a=="string"&&O(a))return "prototype-key"}}}for(let r of ["l","k","p"]){let i=t[r];if(typeof i=="string"&&O(i))return "prototype-key"}let o=t.c;if(Array.isArray(o)){if(o.length>e.maxChildren)return "too-many-children";for(let r of o){let i=Br(r,e,n+1);if(i!=="invalid-string"||Sn(r,e))return i}}return "invalid-string"}function Sn(t,e){return typeof t=="string"?t.length>e.maxStringLength:Array.isArray(t)?t.some(n=>Sn(n,e)):se(t)?Object.entries(t).some(([n,o])=>n==="v"?false:Sn(o,e)):false}var ha=new Map([["","#"],[XML_NAMESPACE_URI,"#x"],["http://schemas.microsoft.com/office/word/2010/wordml","#w14"],["http://schemas.microsoft.com/office/word/2012/wordml","#w15"],["http://schemas.openxmlformats.org/officeDocument/2006/relationships","#r"],["http://schemas.openxmlformats.org/officeDocument/2006/math","#m"],["http://schemas.openxmlformats.org/markup-compatibility/2006","#mc"]]),Df=new Map([...ha].map(([t,e])=>[e,t]));function wn(t){return t===WML_NAMESPACE_URI?"":ha.get(t)??t}function kn(t){return t===""?WML_NAMESPACE_URI:t.startsWith("#")?Df.get(t)??null:t}function ro(t){if(t===WML_NAMESPACE_URI)return "w";if(t===XML_NAMESPACE_URI)return "xml"}var Dr=/^(.*:)(\d{1,15})$/;function vn(t,e){if(t===e)return "=";if(e.length>0&&t.startsWith(e))return `^${t.slice(e.length)}`;let n=Dr.exec(t),o=Dr.exec(e);return n&&o&&n[1]===o[1]?`+${Number(n[2])-Number(o[2])}`:/^[=^+!]/.test(t)?`!${t}`:t}function Gt(t,e,n){if(typeof t!="string"||t.length>n.maxStringLength)return null;let o;if(t==="=")o=e;else if(t.startsWith("^"))o=e+t.slice(1);else if(t.startsWith("+")){let r=Number(t.slice(1)),i=Dr.exec(e),s=i?Number(i[2])+r:NaN;o=i&&Number.isSafeInteger(s)&&s>=0?`${i[1]}${s}`:null;}else t.startsWith("!")?o=t.slice(1):o=t;return !o||o.length>n.maxStringLength||O(o)?null:o}function ga(t,e,n,o){return t===XML_NAMESPACE_URI&&e==="space"&&n==="xml"&&(o==="default"||o==="preserve")?"xmlSpace":t===WML_NAMESPACE_URI&&e==="val"?"wmlVal":"genericExtension"}function Nf(t){let e=[t.localName,t.value],n=t.prefix,o=ga(t.namespaceUri,t.localName,n,t.value),r=[wn(t.namespaceUri),n===ro(t.namespaceUri)?"":n??null,t.kind===o?"":t.kind];for(;r.length>0&&r[r.length-1]==="";)r.pop();return [...e,...r]}function qt(t,e,n){if(t.kind==="textValue")return {v:t.value};let o={},r=e?.localName;t.localName!==r&&(o.l=t.localName);let i=wn(t.namespaceUri);i!==""&&(o.n=i);let s=e&&t.localName===e.localName&&t.namespaceUri===WML_NAMESPACE_URI?e.kind:"generic";return t.kind!==s&&(o.k=t.kind),t.prefix!==ro(t.namespaceUri)&&(o.p=t.prefix??""),t.attributes.length>0&&(o.a=t.attributes.map(Nf)),t.namespaceBindings.length>0&&(o.b=t.namespaceBindings.map(a=>[a.prefix,wn(a.namespaceUri)])),n&&t.children.length>0&&(o.c=t.children.map(a=>qt(a,null,true))),o}function se(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function ze(t,e){return typeof t=="string"&&t.length<=e.maxStringLength}function Yf(t,e){if(t===void 0)return Object.freeze([]);if(!Array.isArray(t)||t.length>e.maxAttributes)return null;let n=[];for(let o of t){if(!Array.isArray(o)||o.length<2||o.length>5)return null;let[r,i,s="",a="",l=""]=o;if(!ze(r,e)||O(r)||!ze(i,e)||!ze(s,e))return null;let d=kn(s);if(d===null||a!==null&&!ze(a,e))return null;let c=a===""?ro(d):a??void 0;if(c!==void 0&&O(c)||!ze(l,e))return null;let u=l||ga(d,r,c,i);if(u!=="xmlSpace"&&u!=="wmlVal"&&u!=="genericExtension")return null;n.push(Object.freeze({kind:u,namespaceUri:d,localName:r,...c===void 0?{}:{prefix:c},value:i}));}return Object.freeze(n)}function _f(t,e){if(t===void 0)return Object.freeze([]);if(!Array.isArray(t)||t.length>e.maxAttributes)return null;let n=[];for(let o of t){if(!Array.isArray(o)||o.length!==2)return null;let[r,i]=o;if(!ze(r,e)||!ze(i,e)||O(r))return null;let s=kn(i);if(s===null)return null;n.push(Object.freeze({prefix:r,namespaceUri:s}));}return Object.freeze(n)}function Qt(t,e,n,o,r,i){if(r.nodes+=1,r.nodes>oo||i>$e||!se(t))return null;if(typeof t.v=="string"&&t.l===void 0&&t.k===void 0)return t.v.length>o.maxTextLength?null:Object.freeze(Vt(e,t.v));let s=t.l??n?.localName;if(!ze(s,o)||O(s))return null;let a=t.n??"";if(!ze(a,o))return null;let l=kn(a);if(l===null)return null;let d=n&&s===n.localName&&l===WML_NAMESPACE_URI?n.kind:"generic",c=t.k??d;if(!ze(c,o)||O(c))return null;let u=ro(l);if(t.p!==void 0){if(!ze(t.p,o)||O(t.p))return null;u=t.p===""?void 0:t.p;}let f=Yf(t.a,o),p=_f(t.b,o);if(!f||!p)return null;let h=t.c??[];if(!Array.isArray(h)||h.length>o.maxChildren)return null;let g=[];for(let m=0;m<h.length;m+=1){let w=Qt(h[m],`${e}~${m}`,null,o,r,i+1);if(!w)return null;g.push(w);}return Object.freeze(De({id:e,kind:c,namespaceUri:l,localName:s,namespaceBindings:p,attributes:f,children:Object.freeze(g),...u===void 0?{}:{prefix:u}}))}var de="v:",xe="b",so=512,xa=2**31,Bf=new Set(["ins","del","moveFrom","moveTo"]);function io(t){return t.namespaceUri===WML_NAMESPACE_URI&&Bf.has(t.localName)}var Uf=new Set(["hyperlink","fldSimple"]);function Sa(t){return t.namespaceUri===WML_NAMESPACE_URI&&Uf.has(t.localName)}function On(t,e,n,o={}){return {i:vn(t.id,e),...qt(t,n,false),...o}}function Ur(t,e){return On(t,e,null,{c:t.children.map(n=>qt(n,null,true))})}function wa(t,e,n){let o=[],r=new Set,i=t.map(a=>{let l=vn(a.id,e),d=r.has(l)?`!${a.id}`:l;return r.add(d),d}),s=0;return t.forEach((a,l)=>{if(!io(a)){let d=i.filter((u,f)=>f>l&&io(t[f])),c=Sa(a)?i.filter((u,f)=>f<l&&io(t[f])):[];o.push({wrapper:a,inside:d,outside:c});return}s+=1,n[`${de}${i[l]}`]=JSON.stringify({e:{...Ur(a,e),i:i[l]},d:s});}),o}function Fr(t,e,n,o="r"){let r=new Set,i=se(t)?t[o]:void 0;if(!Array.isArray(i))return r;for(let s of i.slice(0,$e)){let a=Gt(s,n,e);a!==null&&r.add(a);}return r}function fe(t){if(typeof t=="string")try{return JSON.parse(t)}catch{return}}var Ff=65536,ma=4096;function Ln(t){let e=new Set;if(typeof t!="string"||t.length>so*(ma+3))return e;let n=fe(t);if(!Array.isArray(n))return e;for(let o of n.slice(0,so))typeof o!="string"||o.length>ma||O(o)||e.add(`${de}${o}`);return e}function jf(t){let e=Ln(t[xe]);return Object.keys(t).filter(n=>n.startsWith(de)&&!O(n)&&!e.has(n)).sort()}var zf=null;function $f(t){return typeof t=="number"&&Number.isSafeInteger(t)&&t>=1&&t<=xa}function Wf(t,e,n,o){if(typeof e!="string"||e.length>Ff)return null;let r=fe(e);if(!se(r)||!se(r.e))return null;let i=r.d;if(!$f(i))return null;let{i:s,...a}=r.e,l=Gt(s,o,n);if(l===null)return null;let d=Qt(a,l,zf,n,{nodes:0},0);return !d||d.kind==="textValue"||!io(d)?null:{key:t,shell:d,encodedId:s,order:i,content:JSON.stringify(a),signature:JSON.stringify(a)}}function Rn(t,e,n){let o=[];for(let r of jf(t)){let i=Wf(r,t[r],e,n);if(i&&o.push(i),o.length===$e)break}return o.sort(Kf)}function Kf(t,e){return t.order-e.order||(t.key<e.key?-1:t.key>e.key?1:0)}function ka(t,e){let n=[...t];for(let o of e.slice(0,Math.max(0,$e-t.length))){let r=0,i=null;for(let a=n.length-1;a>=0;a-=1)if(n[a].inside?.has(o.shell.id)){r=a+1,i=n[a].shell.id;break}let s=n.some(a=>a.outside?.has(o.shell.id));for(let a=n.length-1;a>=r&&!s;a-=1)if(n[a].anchor===void 0&&Sa(n[a].shell)){r=a+1,i=n[a].shell.id;break}for(;r<n.length&&n[r].anchor===i;)r+=1;n.some(a=>a.shell.id===o.shell.id)||n.splice(r,0,{shell:o.shell,signature:o.signature,anchor:i});}return n.map(({shell:o,signature:r})=>({shell:o,signature:r}))}function Vf(t,e){let n=new Set,o=[],r=new Map;for(let i of e){let s=t.find(a=>!n.has(a)&&a.content===i.content);s?(n.add(s),r.set(i.encodedId,s.encodedId)):o.push(i);}return {kept:n,added:o,renamed:r}}function jr(t){let e={};for(let n of Object.keys(t))!n.startsWith(de)&&n!==xe&&(e[n]=t[n]);return e}function ao(t){for(let e of Object.keys(t))if(e.startsWith(de)||e===xe)return true;return false}function Jf(t,e,n){if(t===e)return true;let o=fe(t??"[]"),r=fe(e??"[]");return !Array.isArray(o)||!Array.isArray(r)||o.length!==r.length?false:o.every((i,s)=>{let a=r[s];if(!se(i)||!se(a))return false;let{r:l,...d}=i,{r:c,...u}=a;if(JSON.stringify(d)!==JSON.stringify(u))return false;let f=p=>(Array.isArray(p)?p:[]).filter(h=>n.has(h)).sort();return JSON.stringify(f(l))===JSON.stringify(f(c))})}function Hf(t,e){let n=JSON.parse(t);return JSON.stringify({...n,d:e})}function Xf(t,e){if(t===void 0||![...e].some(([o,r])=>o!==r))return t;let n=fe(t);return Array.isArray(n)?JSON.stringify(n.map(o=>se(o)&&Array.isArray(o.r)?{...o,r:o.r.map(r=>typeof r=="string"?e.get(r)??r:r)}:o)):t}function ya(t){return JSON.stringify([...t].map(e=>e.slice(de.length)).sort())}function zr(t,e,n,o,r){if(!ao(t))return e;let i=Rn(t,o,r),s=Rn(e,o,r),a=jr(e);for(let m of Object.keys(t))m.startsWith(de)&&(a[m]=t[m]);let l=Ln(t[xe]),{kept:d,added:c,renamed:u}=Vf(i,s);for(let m of i)d.has(m)||(n?l.add(m.key):delete a[m.key]);let f=Xf(a.w,u);f!==void 0&&(a.w=f);let p=new Set([...d].map(m=>m.encodedId).concat(c.map(m=>m.encodedId)));Jf(t.w,a.w,p)&&(t.w===void 0?delete a.w:a.w=t.w);let h=i.reduce((m,w)=>Math.max(m,w.order),0),g=false;for(let m of c)h=Math.min(h+1,xa),a[m.key]=Hf(e[m.key],h),g=l.delete(m.key)||g;if(!n&&!g)return t[xe]!==void 0&&(a[xe]=t[xe]),a;if(l.size>so){let m=[...l].sort();for(let w of m.slice(so))l.delete(w),delete a[w];}if(l.size>0){let m=ya(l);a[xe]=t[xe]!==void 0&&ya(Ln(t[xe]))===m?t[xe]:m;}return a}var ba=new WeakMap,Gf=4096;function qf(t){let e=[];for(let n of Object.keys(t).sort())(n.startsWith(de)||n===xe)&&e.push(JSON.stringify([n,t[n]]));return e.join(",")}function $r(t,e,n){if(!ao(t))return "[]";let o=ba.get(e);o||ba.set(e,o=new Map);let r=`${n}\0${qf(t)}`,i=o.get(r);if(i!==void 0)return i;let s=Rn(t,e,n),a=JSON.stringify(s.map(l=>l.content));return o.size>=Gf&&o.clear(),o.set(r,a),a}var ae="inline",Wr="r",Zt="rp",Ea="t",Ca="w",Kr="p:";function Vr(t){return t.kind!=="embed"?{a:1}:t.attributes.run?{n:t.node.id,r:1}:{n:t.node.id}}function ep(t){let e=new Map;return t.map(n=>{let o=wn(n.namespaceUri),r=`${Kr}${o===""?"":`${o}|`}${n.localName}`,i=(e.get(r)??0)+1;return e.set(r,i),i===1?r:`${r}#${i}`})}function Ta(t){let e=t.slice(Kr.length).replace(/#\d+$/,""),n=e.indexOf("|"),o=kn(n<0?"":e.slice(0,n)),r=n<0?e:e.slice(n+1);return o===null||r.length===0?null:{namespaceUri:o,localName:r}}function Ct(t,e,n){let o={},r=t.run;if(r&&(o[Wr]=JSON.stringify(On(r,e,Yr))),r&&t.runProperties){let s=ep(t.properties);o[Zt]=JSON.stringify(On(t.runProperties,e,no,{o:s})),t.properties.forEach((a,l)=>{let d={kind:"generic",localName:a.localName};o[s[l]]=JSON.stringify(qt(a,d,true));});}if(t.text){let s=t.text.id,a=t.textValueId??`${s}~v`,l=a===`${s}~v`?{}:{v:vn(a,s)};o[Ea]=JSON.stringify(On(t.text,e,_r,l));}if(t.wrap.length>$e)throw new Be("tree-too-deep",`${t.wrap.length} nested wrappers`);let i=wa(t.wrap,e,o);return i.length>0&&(o[Ca]=JSON.stringify(i.map(({wrapper:s,inside:a,outside:l})=>({...Ur(s,e),...a.length>0?{r:a}:{},...l.length>0?{x:l}:{}})))),Object.values(o).some(s=>tp(s,n))&&op(t,o,e,n),o}function tp(t,e){let n=Math.min(e.maxStringLength,e.maxAttributes,e.maxChildren,e.maxTextLength,oo);if(t.length>n||np.test(t))return true;let o=0;for(let r=0;r<t.length;r+=1){let i=t.charCodeAt(r);if(i===123||i===91){if(o+=1,o>2*$e+2)return true}else (i===125||i===93)&&(o-=1);}return false}var np=/__proto__|constructor|prototype/;function op(t,e,n,o){let r=Ne(e,o,n);if(!((e[Zt]===void 0||En(fe(e[Zt]),n,no,o)!==null)&&r.run===null==(t.run===null)&&r.properties.length===(t.run?t.properties.length:0)&&r.text===null==(t.text===null)&&r.wrap.length===t.wrap.length)){for(let[s,a]of Object.entries(e)){let l=fe(a),d=Array.isArray(l)?l:[l];for(let c of d){let u=Br(c,o);if(u!=="invalid-string"||Sn(c,o))throw new Be(u,`${s} of an item in ${n}`)}}throw new Be("invalid-string",`an item in ${n}`)}}function Ma(t,e,n){let o=[],r=null,i=()=>{r&&o.push({insert:r.text,attributes:r.attributes}),r=null;};for(let s of t){let a=Ct(s.attributes,e,n);if(s.kind==="char"){let l=ve(a);r&&r.signature===l?r.text+=s.value:(i(),r={text:s.value,attributes:a,signature:l});continue}i(),o.push({insert:Vr(s),attributes:a});}return i(),o}function ve(t){if(!t)return "";let e=Object.keys(t).sort().map(n=>{let o=t[n];return typeof o=="string"?[n,o]:[n,null,typeof o]});return e.length===0?"":JSON.stringify(e)}function En(t,e,n,o,r=false){if(!se(t))return null;let i=Gt(t.i,e,o);if(!i)return null;let{i:s,v:a,o:l,c:d,...c}=t,u=Qt(r?{...c,c:d}:c,i,n,o,{nodes:0},0);return !u||u.kind==="textValue"?null:{shell:u,data:t}}var va=["rStyle","rFonts","b","bCs","i","iCs","caps","smallCaps","strike","dstrike","outline","shadow","emboss","imprint","noProof","snapToGrid","vanish","webHidden","color","spacing","w","kern","position","sz","szCs","highlight","u","effect","bdr","shd","fitText","vertAlign","rtl","cs","em","lang","eastAsianLayout","specVanish","oMath","rPrChange"];function La(t){let e=Ta(t),n=e?.namespaceUri===WML_NAMESPACE_URI?va.indexOf(e.localName):-1;return n<0?va.length-1:n}function rp(t,e){return La(t)-La(e)||(t<e?-1:t>e?1:0)}function ip(t){return Zn(t,"runProperties","rPr")}var Ra=new WeakMap,sp=4096;function Ne(t,e,n){let o=JSON.stringify([n,ve(t)]),r=Ra.get(e);r||Ra.set(e,r=new Map);let i=r.get(o);if(i)return i;let s=ap(t??{},e,n);return r.size>=sp&&r.clear(),r.set(o,s),s}function ap(t,e,n){let o=En(fe(t[Wr]),n,Yr,e),r=o?En(fe(t[Zt]),n,no,e):null,i=[],s=[],a=o?Object.keys(t).filter(b=>b.startsWith(Kr)).sort().slice(0,e.maxChildren):[],l={nodes:0},d=r?.shell??(o&&a.length>0?ip(`${o.shell.id}~rPr`):null);if(o&&d){let b=Array.isArray(r?.data.o)?r.data.o:[],x=a.every(L=>b.includes(L))?b.filter(L=>typeof L=="string"&&a.includes(L)):[...a].sort(rp);for(let L of x){let k=Ta(L);if(!k||O(L))continue;let y=Qt(fe(t[L]),`${d.id}~${L}`,{kind:"generic",localName:k.localName},e,l,0);y&&y.kind!=="textValue"&&(i.push(y),s.push(L));}}let c=fe(t[Ea]),u=En(c,n,_r,e),f=u?(se(c)&&c.v!==void 0?Gt(c.v,u.shell.id,e):null)??`${u.shell.id}~v`:null,p=fe(t[Ca]),h=[];if(Array.isArray(p)&&p.length<=$e)for(let b of p){let x=En(b,n,null,e,true);if(!x)break;let{r:L,x:k,...y}=b;h.push({shell:x.shell,signature:JSON.stringify(y),inside:Fr(b,e,n),outside:Fr(b,e,n,"x")});}let g=ka(h,Rn(t,e,n)),m=g.map(b=>b.shell),w=g.map(b=>b.signature),I=o?JSON.stringify([t[Wr],typeof t[Zt]=="string"?t[Zt]:"",...s.map(b=>[b,t[b]])]):void 0;return Object.freeze({run:o?.shell??null,runProperties:i.length>0||r?d:null,properties:Object.freeze(i),text:u?.shell??null,textValueId:f,wrap:Object.freeze(m),...I!==void 0?{runSignature:I}:{},wrapSignatures:Object.freeze(w)})}function Jr(t,e,n,o,r={}){let i=[],s=[],a=c=>{for(let u of c.entries){for(let f of u.slot?.before??[])a(f);u.item&&(i.push(u.item),s.push(u.placement),u.item.kind==="char"&&r.onCharacter?.(u.character??null));for(let f of u.slot?.after??[])a(f);}},l=(c,u=false)=>{let f=r.following?.at.get(c);for(let p of (u?f?.before:f?.after)??[])a(p);};for(let c of r.following?.atStart??[])a(c);let d=0;for(let c of t){let u=Ne(c.attributes,n,o);if(typeof c.insert=="string"){for(let h=0;h<c.insert.length;h+=1,d+=1)if(!r.hidden?.has(d)){if(l(d,true),i.push({kind:"char",value:c.insert[h],attributes:u}),s.push(void 0),r.onCharacter){let g=r.characters?.items[d];r.onCharacter(g===void 0?null:{item:g,identity:r.characters?.ids[d]??null});}l(d);}continue}if(d+=1,r.hidden?.has(d-1)||!se(c.insert))continue;if(c.insert.a===1){i.push({kind:"anchor",attributes:u}),s.push(void 0);continue}let f=c.insert.n;if(typeof f!="string"||O(f))continue;let p=e(f);p&&(i.push({kind:"embed",node:p,attributes:u}),s.push(c.insert.r===1));}for(let c of r.following?.atEnd??[])a(c);return up(i,s,o,r.onRepair)}function Pa(t,e,n=o=>o){let o=new Set,r=(i,s)=>{if(e.has(i.id))return i;let l=s!==null&&i.id.startsWith(s.from)&&(i.id[s.from.length]==="~"||i.id[s.from.length]==="/")?`${s.to}${i.id.slice(s.from.length)}`:i===t?i.id:n(i.id);if(o.has(l)){let f=2;for(;o.has(`${l}~${f}`);)f+=1;l=`${l}~${f}`;}if(o.add(l),i.kind==="textValue")return l===i.id?i:Object.freeze({...i,id:l});let d=l===i.id?null:{from:i.id,to:l},c=i.children.map(f=>r(f,d));return d===null&&c.every((f,p)=>f===i.children[p])?i:Object.freeze(qe(i,Object.freeze(c),l))};return Kt(r(t,null))}function lp(t,e){return t.kind==="char"||t.kind==="embed"&&e===true}function Oa(t){return t.kind==="char"}function dp(t){return Object.freeze({run:null,runProperties:null,properties:Object.freeze([]),text:null,textValueId:null,wrap:t.wrap,...t.wrapSignatures?{wrapSignatures:t.wrapSignatures}:{}})}function cp(t,e,n){return Object.freeze({...t,run:e?.run??n,runProperties:e?.runProperties??null,properties:e?.properties??Object.freeze([]),...e?.runSignature!==void 0?{runSignature:e.runSignature}:{}})}function up(t,e,n,o){let r=(d,c)=>lp(d,e[c])&&!d.attributes.run||d.kind==="embed"&&e[c]===false&&d.attributes.run!==null||Oa(d)&&d.attributes.run!==null&&!d.attributes.text;if(!t.some(r))return t;o?.();let i=(d,c)=>{for(let u=1;u<t.length;u+=1){let f=t[d-u];if(f&&c(f,d-u))return f;let p=t[d+u];if(p&&c(p,d+u))return p;if(!f&&!p)break}return null},s=(d,c)=>d.attributes.run!==null&&!(d.kind==="embed"&&e[c]===false),a=Zn(`${n}~r`,"run","r"),l=[];return t.forEach((d,c)=>{if(!r(d,c)){l.push(d);return}let u=t[c-1];if(d.kind==="char"&&u?.kind==="char"&&pp(d.value)&&fp(u.value)){l.push({...d,attributes:l[l.length-1].attributes});return}let f=d.attributes;if(d.kind==="embed"&&e[c]===false){l.push({...d,attributes:dp(f)});return}if(!f.run){let p=i(c,s);f=cp(f,p?.attributes??null,a);}if(Oa(d)&&!f.text){let p=f.run,h=i(c,g=>g.kind==="char"&&g.attributes.run?.id===p.id&&!!g.attributes.text);f=Object.freeze({...f,text:h?.attributes.text??Zn(`${p.id}~t`,"text","t",[Object.freeze({kind:"xmlSpace",namespaceUri:XML_NAMESPACE_URI,localName:"space",prefix:"xml",value:"preserve"})]),textValueId:h?.attributes.textValueId??null});}l.push({...d,attributes:f});}),l}function fp(t){let e=t.charCodeAt(0);return t.length===1&&e>=55296&&e<=56319}function pp(t){let e=t.charCodeAt(0);return t.length===1&&e>=56320&&e<=57343}var hp=8;function lo(t){let e=new Map;t.identities.ids.forEach((c,u)=>{c&&!t.hidden.has(u)&&!e.has(c)&&e.set(c,u);});let n=new Map;for(let c of t.incoming)c.identities.forEach((u,f)=>{u&&!n.has(u)&&n.set(u,{piece:c,index:f});});let o=new Map;for(let c of t.incoming){if(e.has(c.after))continue;let u=n.get(c.after);u&&u.piece!==c&&o.set(c,gp(c,u,t));}let r=c=>{let u=c;for(let f=0;f<=hp;f+=1){let p=o.get(u);if(!p)return true;u=p.piece;}return false};for(;;){let c=t.incoming.find(u=>o.has(u)&&!r(u));if(!c)break;o.delete(c);}let i=new Map,s=new Map,a=[],l=[],d=(c,u)=>{let f=c.get(u);return f||(f={before:[],after:[]},c.set(u,f)),f};for(let c of t.incoming){if(c.atStart){l.push(c);continue}let u=e.get(c.after),f=o.get(c),p=null;if(u!==void 0)p=d(i,u);else if(f){let h=s.get(f.piece);h||(h=new Map,s.set(f.piece,h)),p=d(h,f.index);}p?c.before?p.before.push(c):p.after.push(c):a.push(c);}return {atPosition:i,inside:s,atEnd:a,atStart:l}}function gp(t,e,n){if(t.before)return e;let{positions:o,items:r}=e.piece,{items:i,origins:s}=n.identities,a=r[e.index];if(a===void 0||i[o[e.index]]!==a)return e;let l=u=>jt(a,u),d=new Set,c=e.index;for(let u=c+1;u<o.length;u+=1){let f=r[u],p=o[u],h=i[p]===f?s[p]:null;if(!(h===a&&!l(f))&&!(h!==null&&d.has(h)))break;d.add(f),c=u;}return {piece:e.piece,index:c}}var Gr="docx-text-deletions-v1",mp=/^d(\d{1,16}):(\d{1,16})$/,yp=/^(\d{1,16}):(\d{1,16}):(\d{1,16})$/,Hr=4096,bp=1<<20;function co(t){let e=Number(t);return Number.isSafeInteger(e)?e:null}function Ip(t,e){let n=mp.exec(t);if(!n||typeof e!="string")return null;let o=co(n[1]);if(o===null)return null;let r=[];for(let i of e.split(";")){if(r.length>=Hr)return null;let s=yp.exec(i);if(!s)return null;let a=co(s[1]),l=co(s[2]),d=co(s[3]);if(a===null||l===null||d===null||d<1||d>bp)return null;r.push({client:a,from:l,to:l+d});}return r.length===0?null:{client:o,runs:r}}var en=class t{starts=[];ends=[];static of(e){let n=new t,o=[...e].sort((r,i)=>r.from-i.from);for(let{from:r,to:i}of o){let s=n.ends.length-1;s>=0&&r<=n.ends[s]?n.ends[s]=Math.max(n.ends[s],i):(n.starts.push(r),n.ends.push(i));}return n}add(e,n){let o=0,r=this.starts.length;for(;o<r;){let l=o+r>>1;this.ends[l]<e?o=l+1:r=l;}let i=o,s=e,a=n;for(;i<this.starts.length&&this.starts[i]<=n;)s=Math.min(s,this.starts[i]),a=Math.max(a,this.ends[i]),i+=1;this.starts.splice(o,i-o,s),this.ends.splice(o,i-o,a);}has(e){let n=0,o=this.starts.length-1;for(;n<=o;){let r=n+o>>1;if(this.starts[r]>e)o=r-1;else if(this.ends[r]<=e)n=r+1;else return true}return false}},Xr=class{constructor(e,n){this.doc=e;this.map=n;n.forEach((o,r)=>this.refresh(r,o));}doc;map;byKey=new Map;keysByClient=new Map;characters=new Map;stale=new Set;listeners=new Set;subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}isDeleted(e,n){return this.stale.has(e)&&(this.stale.delete(e),this.reindex(e)),this.characters.get(e)?.has(n)??false}record(e){let n=[];for(let o=0;o<e.length;o+=Hr){let r=e.slice(o,o+Hr).map(s=>`${s.client}:${s.from}:${s.to-s.from}`).join(";"),i=`d${this.doc.clientID}:${z.getState(this.doc.store,this.doc.clientID)}`;this.map.set(i,r),this.refresh(i,r),n.push(i);}return n}withdraw(e){let n=`d${this.doc.clientID}:`;for(let o of e)!o.startsWith(n)||!this.map.has(o)||this.map.delete(o);}refreshKeys(e){let n=[];for(let o of e){if(o===null)continue;let r=this.byKey.get(o)??[];this.refresh(o,this.map.get(o));let i=this.byKey.get(o)??[];for(let s of r)n.push(s);for(let s of i)n.push(s);}if(n.length!==0)for(let o of this.listeners)o(n);}refresh(e,n){let o=this.byKey.get(e);this.byKey.delete(e);let r=Ip(e,n),i=r?_e(this.map,e):void 0,s=r!==null&&(!i||i.id.client===r.client);if(s&&this.byKey.set(e,r.runs),o){let a=new Set(o.map(l=>l.client));for(let l of a)this.keysByClient.get(l)?.delete(e);s&&this.list(e,r.runs);for(let l of s?r.runs:[])a.add(l.client);for(let l of a)this.stale.add(l);}else if(s){this.list(e,r.runs);for(let a of r.runs){if(this.stale.has(a.client))continue;let l=this.characters.get(a.client);l||this.characters.set(a.client,l=new en),l.add(a.from,a.to);}}}list(e,n){for(let o of n){let r=this.keysByClient.get(o.client);r||this.keysByClient.set(o.client,r=new Set),r.add(e);}}reindex(e){let n=this.keysByClient.get(e);if(!n||n.size===0){this.keysByClient.delete(e),this.characters.delete(e);return}let o=[];for(let r of n)for(let i of this.byKey.get(r)??[])i.client===e&&o.push(i);this.characters.set(e,en.of(o));}},Aa=new WeakMap;function Qe(t){let e=Aa.get(t);if(e)return e;let n=t.getMap(Gr),o=new Xr(t,n);return t.on("beforeObserverCalls",r=>{let i=Ft(r,n);i&&o.refreshKeys(i);}),Aa.set(t,o),e=o,e}function Na(t){let e=t.flatMap(o=>ke(o)??[]).sort((o,r)=>o.client-r.client||o.clock-r.clock),n=[];for(let{client:o,clock:r}of e){let i=n[n.length-1];i&&i.client===o&&r<=i.to?i.to=Math.max(i.to,r+1):n.push({client:o,from:r,to:r+1});}return n}var Zr="docx-text-decisions-v1",xp=/^a(\d{1,16}):(\d{1,16})$/,Sp=/^(\d{1,16}):(\d{1,16}):(\d{1,16})$/,qr=4096,wp=1<<20,kp=4096;function uo(t){let e=Number(t);return Number.isSafeInteger(e)?e:null}function vp(t,e){let n=xp.exec(t);if(!n||typeof e!="string")return null;let o=uo(n[1]);if(o===null)return null;let r=e.indexOf(`
|
|
8
|
-
`);if(r<0)return null;let i=e.slice(0,r);if(!i.startsWith(de)||i.length>
|
|
9
|
-
${n.slice(r,r+
|
|
10
|
-
`),I=p.get(w);return I||p.set(w,I=Cp(i(),m)),I},g=(m,w)=>{let I=n.at(-1);I&&u===w?I.insert=I.insert+m:(f(m,w),u=w);};for(let m=be(t);m;m=m.right){if(m.deleted)continue;let w=m.content;if(w instanceof z.ContentFormat){w.value===null?delete o[w.key]:o[w.key]=w.value,po(w.value)!==null&&(s=true),r=null,d=null,p=new Map;continue}let{client:I,clock:b}=m.id,x=l&&c().length>0?l:null;if(w instanceof z.ContentString){let L=w.str;if(!s&&!x){g(L,i());continue}for(let k=0;k<L.length;){let y=s?Ua(i(),I,b+k):null,v=x?za(x,c(),I,b+k):null,E=x?k+1:Ep(i(),I,b+k,b+L.length)-b,P=$a(y,v);g(L.slice(k,E),P?h(P):i()),k=E;}continue}if(w instanceof z.ContentEmbed||w instanceof z.ContentType){let L=s?Ua(i(),I,b):null,k=x?za(x,c(),I,b):null,y=$a(L,k);f(w.getContent()[0],y?h(y):{...i()});}}return {ops:n,leftOut:e}}function Mp(t,e,n,o,r,i){let s=Mt(t);if(!r)return Jr(s,e,n,o);let a=r.shown(t);(a.hidden.size>0||a.incoming.length>0)&&r.noteDrift();let l=new Map;for(let h of a.incoming){let g=l.get(h.source)??new Set;for(let m of h.positions)g.add(m);l.set(h.source,g);}let d=new Map;for(let[h,g]of l)d.set(h,Pp(r.textOf(h),h,g,e,n));let c=lo(a),u=h=>{let g=d.get(h.source),m=c.inside.get(h),w=[];return h.positions.forEach((I,b)=>{let x=g.get(I),L=m?.get(b);if(!x&&!L)return;let k=h.items[b];w.push({item:x?.item,placement:x?.placement,...L?{slot:f(L)}:{},...k!==void 0?{character:{item:k,identity:h.identities[b]??null}}:{}});}),{entries:w}},f=h=>({before:h.before.map(u),after:h.after.map(u)}),p=new Map;for(let[h,g]of c.atPosition)p.set(h,f(g));return Jr(s,e,n,o,{hidden:a.hidden,following:{at:p,atEnd:c.atEnd.map(u),atStart:c.atStart.map(u)},onRepair:()=>r.noteDrift(),...i?{onCharacter:i,characters:{items:a.identities.items,ids:a.identities.ids}}:{}})}function Pp(t,e,n,o,r){let i=new Map;if(!t)return i;let s=0;for(let a of Mt(t)){let l=typeof a.insert=="string"?a.insert.length:1;if(typeof a.insert=="string"){let d=null;for(let c=0;c<l;c+=1)n.has(s+c)&&(d??=Ne(a.attributes,r,e),i.set(s+c,{item:{kind:"char",value:a.insert[c],attributes:d},placement:void 0}));}else if(n.has(s)){let d=a.insert,c=d?.n,u=typeof c=="string"&&!O(c)?o(c):null;u&&i.set(s,{item:{kind:"embed",node:u,attributes:Ne(a.attributes,r,e)},placement:d?.r===1});}s+=l;}return i}function Ze(t,e,n,o,r,i){let s=new Set,a=new Set,l=Mp(e,f=>{if(r&&!r.showsEmbed(f))return r.noteDrift(),null;let p=r?.lineageOf?.(f)??null;if(p!==null&&p!==f){if(a.has(p)||r.listed?.(p))return r.noteDrift(),null;a.add(p);}let h=n(f);return h&&s.add(f),h},o,t,r,i),d=De({id:t,kind:"paragraph",namespaceUri:WML_NAMESPACE_URI,localName:"p",namespaceBindings:[],attributes:[],children:[]}),c=fa({shell:d,items:l}),u=Pa(c,s,r?f=>r.shownId(f):void 0);return r&&u!==c&&r.noteDrift(),u.children}function ho(t,e){let n=new z.Text;t.set(ae,n);let o=0;for(let r of e)typeof r.insert=="string"?(n.insert(o,r.insert,{...r.attributes}),o+=r.insert.length):(n.insertEmbed(o,r.insert,{...r.attributes}),o+=1);return n}function Ja(t,e){if(t.length===0)return e;let n=new Map(t.map(o=>[o.id,o]));return e.map(o=>{let r=n.get(o.id);return r&&Ha(r,o)?r:o})}function Ha(t,e){return t===e?true:t.id!==e.id||t.kind!==e.kind?false:t.kind==="textValue"||e.kind==="textValue"?t.kind==="textValue"&&e.kind==="textValue"&&t.value===e.value:t.namespaceUri===e.namespaceUri&&t.localName===e.localName&&t.prefix===e.prefix&&ni(t.attributes,e.attributes,(n,o)=>n.kind===o.kind&&n.namespaceUri===o.namespaceUri&&n.localName===o.localName&&n.prefix===o.prefix&&n.value===o.value)&&ni(t.namespaceBindings,e.namespaceBindings,(n,o)=>n.prefix===o.prefix&&n.namespaceUri===o.namespaceUri)&&ni(t.children,e.children,Ha)}function ni(t,e,n){return t.length===e.length&&t.every((o,r)=>n(o,e[r]))}var qa=new Map(Object.entries({paragraph:["paragraphProperties"],run:["runProperties"],paragraphProperties:["runProperties"],table:["tableProperties","tableGrid"],anchoredDrawing:["drawingSimplePos","drawingPositionH","drawingPositionV","drawingExtent","drawingEffectExtent","drawingDocPr","drawingGraphicFramePr","drawingGraphic","drawingSizeRelH","drawingSizeRelV"],inlineDrawing:["drawingExtent","drawingEffectExtent","drawingDocPr","drawingGraphicFramePr","drawingGraphic"]})),Qa=new Set(["drawingWrapNone","drawingWrapSquare","drawingWrapTight","drawingWrapThrough","drawingWrapTopBottom"]),Za=new Map([["inlineDrawing",new Set(["drawingSimplePos","drawingPositionH","drawingPositionV","drawingSizeRelH","drawingSizeRelV",...Qa])]]),oi="http://schemas.openxmlformats.org/drawingml/2006/main",Ap=new Set([oi,"http://schemas.microsoft.com/office/word/2010/wordprocessingShape","http://schemas.openxmlformats.org/drawingml/2006/picture"]),Dp=new Set(["noFill","solidFill","gradFill","blipFill","pattFill","grpFill"]),Np=new Set(["noFill","solidFill","gradFill","pattFill"]),Yp=new Set(["prstGeom","custGeom"]),_p=new Set(["prstDash","custDash"]),Bp=new Set(["round","bevel","miter"]),el=new Map([["shapeProperties",new Set(["xfrm","ln","effectLst","effectDag","scene3d","sp3d","extLst"])],["lineProperties",new Set(["headEnd","tailEnd","extLst"])]]);function Up(t,e,n){return t!=="generic"?t:n==="spPr"&&Ap.has(e??"")?"shapeProperties":n==="ln"&&e===oi?"lineProperties":t}function tl(t){return t===null||typeof t=="string"?t:Up(t.kind,t.namespaceUri,t.localName)}function tn(t,e){return t.kind==="generic"&&t.namespaceUri===oi&&e.has(t.localName)?t.localName:null}var Fp=new Set(["choice:position"]),nl=new Map(Object.entries({drawing:t=>t.kind==="anchoredDrawing"||t.kind==="inlineDrawing"?"choice:placement":null,drawingPositionH:()=>"choice:position",drawingPositionV:()=>"choice:position",anchoredDrawing:t=>Qa.has(t.kind)?"choice:wrap":null,shapeProperties:t=>tn(t,Dp)?"choice:fill":tn(t,Yp)?"choice:geometry":null,lineProperties:t=>tn(t,Np)?"choice:fill":tn(t,_p)?"choice:dash":tn(t,Bp)?"choice:join":null})),Xa={paragraph:"paragraphProperties",run:"runProperties"},jp=new Set(["sectPr","pPrChange"]);function ri(t){return t.kind==="generic"&&t.namespaceUri===WML_NAMESPACE_URI&&jp.has(t.localName)}var ol=new Set(["paragraphProperties","runProperties","tableProperties"]);function zp(t,e){if(qa.get(t)?.includes(e.kind))return `kind:${e.kind}`;let n=nl.get(t)?.(e);if(n)return n;let o=el.get(t),r=o?tn(e,o):null;return r?`a:${r}`:ol.has(t)&&e.kind==="generic"&&e.namespaceUri===WML_NAMESPACE_URI?`wml:${e.localName}`:null}function ii(t){let e=tl(t);return e!==null&&(qa.has(e)||nl.has(e)||Za.has(e)||el.has(e)||ol.has(e))}function go(t,e,n){let o=tl(t);if(o===null||!ii(o))return null;let r=new Map,i=new Set,s=[],a=Za.get(o),l=new Set,d=-1;for(let I=0;I<e.length;I+=1){let b=e[I];if(i.has(b))continue;i.add(b);let x=n(b);if(s[I]=x,!x)continue;if(a?.has(x.kind)){l.add(I);continue}d<0&&(d=I);let L=zp(o,x);if(L===null)continue;let k=r.get(L);k?k.push(I):r.set(L,[I]);}let c=new Map;for(let[I,b]of r){if(b.length<2||b.every(k=>Ve(e[k])===null))continue;let x=Fp.has(I)?b.find(k=>s[k]?.empty!==true)??b[0]:b[0],L=b.filter(k=>k!==x);for(let k of L)l.add(k);c.set(x,L);}let u=Xa[o]?`kind:${Xa[o]}`:null,f=u?r.get(u)?.[0]:void 0,p=f!==void 0&&d!==f,h=o==="paragraphProperties"?r.get("kind:runProperties")?.[0]:void 0,g=-1;if(h!==void 0)for(let I=h+1;I<e.length;I+=1){let b=s[I];b&&!l.has(I)&&!ri(b)&&(g=I);}if(l.size===0&&!p&&g<0)return null;let m=new Set;for(let I of l)m.add(e[I]);let w=[];p&&w.push(f);for(let I=0;I<e.length;I+=1)l.has(I)||m.has(e[I])||p&&I===f||g>=0&&I===h||(w.push(I),I===g&&w.push(h));return {order:w,companions:c}}function $p(t,e,n){return go(t,e,n)?.order??null}function et(t,e){if(O(e)||t.isTombstoned(e))return null;let n=t.schema.nodes.get(e);if(!_(n))return null;let o=Ge(n);return {kind:o.kind,namespaceUri:Rt(t.schema.namespaces,o.namespaceId),localName:o.localName,...ie(n)?.length===0?{empty:true}:{}}}function rl(t,e,n){let o=$p(t,e,n);if(!o)return {shown:e,hidden:[]};let r=o.map(s=>e[s]),i=new Set(r);return {shown:r,hidden:e.filter(s=>!i.has(s))}}var si=new Set(["paragraphProperties","runProperties","tableProperties"]);function il(t,e,n){let o=go(t,e,n);if(!o)return {shown:e,hidden:[],merges:null};let r=o.order.map(s=>e[s]),i=new Set(r);return {shown:r,hidden:e.filter(s=>!i.has(s)),merges:Wp(o,e,n)}}function Wp(t,e,n){let o=null;for(let[r,i]of t.companions){let s=n(e[r]);!s||!si.has(s.kind)||(o??=new Map,o.set(e[r],i.map(a=>e[a])));}return o}function Kp(t,e){let n=et(t,e);return n?n.kind==="paragraphProperties"||n.kind==="runProperties"?n.kind:n.kind==="generic"&&n.localName==="ins"?"ins":null:null}var Vp={paragraph:"paragraphProperties",paragraphProperties:"runProperties",runProperties:"ins"};function di(t,e,n){let o=t.record(e);return !o||!$(o)?[]:o.childIds.filter(r=>t.showsAsChild(r)&&Kp(t,r)===n)}function ai(t,e,n,o){return di(t,e,n).filter(r=>!o.has(r))}function Jp(t,e,n){let o=t.record(e);if(!o||!$(o))return false;let r=o.childIds.filter(i=>t.showsAsChild(i));return r.length===1&&r[0]===n}function Hp(t,e,n){let o=[],r=e;for(let a of ["paragraphProperties","runProperties","ins"]){let l=di(t,r,a),d=l.filter(u=>Ve(u)===n),c=d.length===1?d[0]:l.length===1?l[0]:null;if(!c)return null;o.push({node:c,from:r,level:a}),r=c;}let i=o[2];if(Ve(i.node)!==n)return null;let s=i;for(let a=1;a>=0;a-=1){let l=o[a];if(Ve(l.node)!==n||!Jp(t,l.node,o[a+1].node))break;s=l;}return s}function Xp(t,e,n,o,r){let{node:i,from:s,level:a}=e,l=n;for(a!=="paragraphProperties"&&(l=ai(t,n,"paragraphProperties",o)[0],l&&a==="ins"&&(l=ai(t,l,"runProperties",o)[0]));l;){let d=ai(t,l,a,o);if(d.length===0){r.push({node:i,from:s,to:l,first:a!=="runProperties"});return}if(a==="ins")return;let c=Vp[a],u=di(t,i,c);if(u.length!==1)return;s=i,i=u[0],l=d[0],a=c;}}function Gp(t,e){let n=[],o=e.source;for(let s of e.shown){let a=e.before.get(s),l=Ve(s);if(a&&l&&a!==o){let d=Hp(t,a,l);d&&n.push({proposal:d,target:o});}o=s;}let r=new Set(n.map(({proposal:s})=>s.node)),i=[];for(let{proposal:s,target:a}of n)Xp(t,s,a,r,i);return i}var li=class{constructor(e){this.registry=e;}registry;moves=[];key="";hidden=new Map;added=new Map;refresh(e,n){let o=[];for(let s of n)for(let a of e.splitSiblings.groupsOf(s))o.push(...Gp(e,a));let r=o.map(s=>`${s.node}>${s.to}`).join(";");if(r===this.key)return [];let i=new Set;for(let s of [...this.moves,...o])i.add(s.from),i.add(s.to);this.moves=o,this.key=r,this.hidden.clear(),this.added.clear();for(let s of o){let a=this.hidden.get(s.from);a||this.hidden.set(s.from,a=new Set),a.add(s.node);let l=this.added.get(s.to)??[];l.push(s),this.added.set(s.to,l);}return [...i]}movedOut(e,n){return this.hidden.get(e)?.has(n)??false}shownChildIds(e,n){let o=this.hidden.get(e),r=this.added.get(e);if(!o&&!r)return [...n];let i=o?n.filter(d=>!o.has(d)):[...n],s=(r??[]).filter(d=>d.first&&!i.includes(d.node)),a=(r??[]).filter(d=>!d.first&&!i.includes(d.node)),l=ci(this.registry,i);return [...s.map(d=>d.node),...i.slice(0,l),...a.map(d=>d.node),...i.slice(l)]}movesAt(e){return this.moves.filter(n=>n.from===e||n.to===e)}};function ci(t,e){let n=e.findIndex(o=>{let r=et(t,o);return r!==null&&ri(r)});return n<0?e.length:n}var sl=new WeakMap;function at(t){let e=sl.get(t);return e||sl.set(t,e=new li(t)),e}function al(t,e){let n=t.splitSiblings.takeChanged();n.length>0&&t.inline.orderChanged();for(let r of n)e.add(r);let o=new Set(t.splitSiblings.parentsWithRuns());for(let r of e){let i=t.parentOf(r);i&&o.add(i);}for(let r of at(t).refresh(t,o))e.add(r);}var qp=new Set(["run","runProperties"]),Qp=new Set(["t","delText","instrText","delInstrText"]),fl=new Set(["hyperlink","ins","del","moveFrom","moveTo","sdt","sdtContent","fldSimple","smartTag","customXml","dir","bdo"]);function pl(t){return qp.has(t.kind)?true:t.namespaceUri===WML_NAMESPACE_URI&&(Qp.has(t.localName)||fl.has(t.localName))}function dl(t,e){let n=t.prefix===void 0?{}:{prefix:t.prefix};return t.namespaceUri===XML_NAMESPACE_URI&&t.localName==="space"&&t.prefix==="xml"&&(e==="default"||e==="preserve")?{kind:"xmlSpace",namespaceUri:XML_NAMESPACE_URI,localName:"space",prefix:"xml",value:e}:t.namespaceUri===WML_NAMESPACE_URI&&t.localName==="val"?{kind:"wmlVal",namespaceUri:WML_NAMESPACE_URI,localName:"val",...n,value:e}:{kind:"genericExtension",namespaceUri:t.namespaceUri,localName:t.localName,...n,value:e}}function cl(t){return t.replace(/(~\d+)+$/,"")}var ui=class{nodes=new Map;refusal=null;refuse(e,n){return this.refusal??={code:e,detail:n},false}described=new Set;add(e,n,o){let r=U(e),i=o.has(r),s={id:r,kind:e.kind,namespaceUri:e.kind==="textValue"?"":e.namespaceUri,localName:e.kind==="textValue"?"":e.localName,...e.kind!=="textValue"&&e.prefix!==void 0?{prefix:e.prefix}:{},attributes:e.kind==="textValue"?[]:[...e.attributes],bindings:e.kind==="textValue"?[]:[...e.namespaceBindings],children:[],value:e.kind==="textValue"?e.value:null,parent:n,opaque:i,block:false,paragraph:false};if(this.nodes.set(r,s),!(e.kind==="textValue"||i))for(let a of e.children)s.children.push(U(a)),this.add(a,r,o);}placeholder(e,n){let o=this.nodes.get(e);if(o)return o;let r={id:e,kind:n,namespaceUri:"",localName:"",attributes:[],bindings:[],children:[],value:null,parent:null,opaque:true,block:false,paragraph:false};return this.nodes.set(e,r),r}detach(e){let n=this.nodes.get(e);if(!n||n.parent===null)return;let o=this.nodes.get(n.parent);if(o){let r=o.children.indexOf(e);r>=0&&o.children.splice(r,1);}n.parent=null;}open(e){let n=this.nodes.get(e);return n!==void 0&&!n.opaque&&!this.insideOpaque(n)}insideOpaque(e){let n=e.parent;for(let o=0;n!==null&&o<256;o+=1){let r=this.nodes.get(n);if(!r)return false;if(r.opaque)return true;n=r.parent;}return false}region(e){let n=[],o=this.nodes.get(e);for(let i=0;o&&i<256&&(n.push(o),!o.paragraph);i+=1)o=o.parent===null?void 0:this.nodes.get(o.parent);let r=n[n.length-1];if(!r?.paragraph)return null;for(let i=n.length-2;i>=0;i-=1){let s=n[i];if(s.block||s.opaque)return {paragraph:r.id,inline:false};if(!(s.kind==="textValue"||pl(s)||n[i+1].kind==="runProperties"||Zp(n,i)))return {paragraph:r.id,inline:false}}return {paragraph:r.id,inline:true}}detachedRoot(e){let n=this.nodes.get(e);for(let o=0;n.parent!==null&&o<256;o+=1){let r=this.nodes.get(n.parent);if(!r)break;n=r;}return n}toTree(e,n=new Set){n.add(e);let o=this.nodes.get(e);return o.kind==="textValue"?Vt(cl(o.id),o.value??""):De({id:o.paragraph||o.opaque?o.id:cl(o.id),kind:o.kind,namespaceUri:o.namespaceUri,localName:o.localName,namespaceBindings:o.bindings,attributes:o.attributes,children:o.opaque?[]:this.childTrees(o,n),...o.prefix===void 0?{}:{prefix:o.prefix}})}childTrees(e,n){let o=[];for(let r of e.children)this.nodes.get(r)?.parent!==e.id||n.has(r)||o.push(this.toTree(r,n));return o}};function Zp(t,e){for(let n=e;n<t.length-1;n+=1){let o=t[n],r=t[n+1];if(r.kind==="runProperties")return true;if(r.namespaceUri===WML_NAMESPACE_URI&&fl.has(r.localName))return o.namespaceUri===WML_NAMESPACE_URI&&/Pr$|^fldData$/.test(o.localName)}return false}function ul(t){switch(t.kind){case "putNode":return [t.descriptor.logicalId];case "spliceText":case "setAttribute":case "setNamespaceBinding":return [t.logicalId];case "spliceChildren":return [t.parentLogicalId,...t.childLogicalIds];case "moveNode":return [t.logicalId,t.destinationParentLogicalId];default:return []}}function mo(t,e,n=()=>null){let o=e.map(Jt),r=new Map;for(let I of o)I.kind==="putNode"&&r.set(I.descriptor.logicalId,I);let i=I=>t.inline.textOf(I)||r.get(I)?.descriptor.kind==="paragraph"||t.kindOf(I)==="paragraph"&&!oh(t,I)?I:t.inline.owner(I),s=new Set;for(let I of o)for(let b of ul(I)){let x=i(b);x&&s.add(x);}if(s.size===0)return {passThrough:[...o],plan:null};let a=I=>{let b=new ui,x=new Set;for(let L of I){let k=t.inline.textOf(L),y=b.placeholder(L,"paragraph");y.opaque=false,y.paragraph=true,y.kind="paragraph",y.namespaceUri=WML_NAMESPACE_URI,y.localName="p";let v=t.record(L),E=v&&"childIds"in v?v.childIds:[],{shown:P}=rl("paragraph",at(t).shownChildIds(L,E),Y=>et(t,Y));for(let Y of P){let V=b.placeholder(Y,t.kindOf(Y)??"generic");V.block=true,V.parent=L,y.children.push(Y);}if(!k)continue;let j=new Set,K=Y=>{if(!t.showsAsChild(Y))return null;let V=n(Y);return V!==null&&V!==L||j.has(Y)?null:(j.add(Y),eo(Y))};for(let Y of Ze(L,k,K,t.limits,t.inline.viewOf(L)))b.add(Y,L,j),y.children.push(U(Y));for(let Y of j){x.add(Y);let V=b.nodes.get(Y);V&&(V.kind=t.kindOf(Y)??"generic");}}return {scratch:b,embedsBefore:x}},{scratch:l,embedsBefore:d}=a(s),c=o.flatMap(I=>ul(I)).filter(I=>!l.nodes.has(I)&&!r.has(I)&&!t.hasNode(I));if(c.length>0){let I=new Set(s);for(let b of rh(t,new Set(c)))I.add(b);if(I.size>s.size){for(let b of I)s.add(b);({scratch:l,embedsBefore:d}=a(s));}}let u=[],f=new Map;for(let I of o){let b=eh(l,I,t);if(b&&f.set(u.length,b),u.push(th(l,I,t)),l.refusal)return {passThrough:[...o],plan:null,refusal:l.refusal}}let p=[];o.forEach((I,b)=>{let x=f.get(b);x?p.push(x):(!u[b]||!nh(l,I))&&p.push(I);});let h=[...s].filter(I=>l.nodes.get(I)?.paragraph).map(I=>({id:I,after:Kt(l.toTree(I))})),[g,...m]=o,w=m.length===0&&g?.kind==="spliceText"&&g.deleteCount===0?{textValueId:g.logicalId,utf16Start:g.utf16Start}:void 0;return {passThrough:p,plan:{paragraphs:h,embedsBefore:d,...w?{typed:w}:{}}}}function eh(t,e,n){if(e.kind!=="spliceChildren")return null;let o=t.nodes.get(e.parentLogicalId);if(!o?.paragraph)return null;let r=c=>{let u=t.nodes.get(c);return u?u.block||u.kind==="paragraphProperties":n.kindOf(c)==="paragraphProperties"},i=o.children.filter(c=>t.nodes.get(c)?.parent===o.id),a=o.children.slice(e.start,e.start+e.deleteCount).filter(c=>t.nodes.get(c)?.block).length,l=e.childLogicalIds.filter(r);if(a===0&&l.length===0)return null;let d=o.children.slice(0,e.start).filter(c=>i.includes(c)&&t.nodes.get(c)?.block).length;return {...e,start:d,deleteCount:a,childLogicalIds:l}}function th(t,e,n){switch(e.kind){case "putNode":{let{descriptor:o}=e;if(O(o.logicalId))return t.refuse("invalid-logical-id",o.logicalId);if(o.kind!=="textValue"&&(O(o.qname.localName)||o.qname.prefix!==void 0&&O(o.qname.prefix)))return t.refuse("prototype-key",o.logicalId);let r=t.nodes.get(o.logicalId);if(o.kind==="textValue"){if(r&&t.described.add(o.logicalId),!r){let s=t.placeholder(o.logicalId,"textValue");s.opaque=false,s.value="";}return true}let i=r??t.placeholder(o.logicalId,o.kind);return r||(i.opaque=false),r?.opaque?false:(i.kind=o.kind,i.namespaceUri=o.qname.namespaceUri,i.localName=o.qname.localName,o.qname.prefix!==void 0&&(i.prefix=o.qname.prefix),o.kind==="paragraph"&&!n.hasNode(o.logicalId)&&(i.paragraph=true),true)}case "spliceText":{let o=t.nodes.get(e.logicalId);return !o||o.value===null||!t.open(e.logicalId)?false:!Number.isSafeInteger(e.utf16Start)||!Number.isSafeInteger(e.deleteCount)||e.utf16Start<0||e.deleteCount<0||e.utf16Start+e.deleteCount>o.value.length?t.refuse("invalid-bound",e.logicalId):o.value.length-e.deleteCount+e.insert.length>n.limits.maxTextLength?t.refuse("text-too-long",e.logicalId):(t.described.delete(e.logicalId)&&e.utf16Start===0&&e.deleteCount===0&&e.insert.length>0&&e.insert===o.value||(o.value=o.value.slice(0,e.utf16Start)+e.insert+o.value.slice(e.utf16Start+e.deleteCount)),true)}case "setAttribute":{let o=t.nodes.get(e.logicalId);if(!o||o.paragraph||!t.open(e.logicalId))return false;if(O(e.qname.localName)||e.qname.prefix!==void 0&&O(e.qname.prefix))return t.refuse("prototype-key",e.logicalId);let r=o.attributes.findIndex(i=>i.namespaceUri===e.qname.namespaceUri&&i.localName===e.qname.localName);return e.value===null?r>=0&&o.attributes.splice(r,1):r>=0?o.attributes[r]=dl(e.qname,e.value):o.attributes.push(dl(e.qname,e.value)),true}case "setNamespaceBinding":{let o=t.nodes.get(e.logicalId);if(!o||o.paragraph||!t.open(e.logicalId))return false;if(O(e.prefix))return t.refuse("prototype-key",e.logicalId);let r=o.bindings.findIndex(i=>i.prefix===e.prefix);return e.uri===null?r>=0&&o.bindings.splice(r,1):r>=0?o.bindings[r]={prefix:e.prefix,namespaceUri:e.uri}:o.bindings.push({prefix:e.prefix,namespaceUri:e.uri}),true}case "spliceChildren":{if(!t.open(e.parentLogicalId)){for(let a of e.childLogicalIds){let l=t.nodes.get(a);l&&(l.parent=e.parentLogicalId,l.outside=true);}return false}let o=t.nodes.get(e.parentLogicalId);if(!Number.isSafeInteger(e.start)||!Number.isSafeInteger(e.deleteCount)||e.start<0||e.deleteCount<0||e.start+e.deleteCount>o.children.length)return t.refuse("invalid-bound",e.parentLogicalId);if(o.children.length-e.deleteCount+e.childLogicalIds.length>n.limits.maxChildren)return t.refuse("too-many-children",e.parentLogicalId);let r=e.childLogicalIds.find(a=>O(a));if(r!==void 0)return t.refuse("invalid-logical-id",r);let i=o.children.splice(e.start,e.deleteCount);for(let a of i){let l=t.nodes.get(a);l?.parent===o.id&&(l.parent=null);}let s=[];for(let a of e.childLogicalIds){let l=n.kindOf(a);if(!t.nodes.has(a)&&(l===null||!n.hasNode(a)))return t.refuse("unknown-logical-id",a);let d=t.nodes.get(a)??t.placeholder(a,l);d.parent=o.id,d.outside=false,o.paragraph&&d.kind==="paragraphProperties"&&(d.block=true),s.push(a);}return o.children.splice(e.start,0,...s),true}case "moveNode":{let o=t.open(e.destinationParentLogicalId),r=t.nodes.get(e.logicalId)?.parent!=null;if(!o&&!r)return false;let i=n.kindOf(e.logicalId);if(!t.nodes.has(e.logicalId)&&(i===null||!n.hasNode(e.logicalId)))return t.refuse("unknown-logical-id",e.logicalId);let s=t.nodes.get(e.logicalId)??t.placeholder(e.logicalId,i);if(t.detach(e.logicalId),s.outside=!o,o){let a=t.nodes.get(e.destinationParentLogicalId);s.parent=a.id,a.children.splice(Math.max(0,Math.min(e.destinationIndex,a.children.length)),0,e.logicalId);}return o}default:return false}}function nh(t,e){let n=o=>{let r=t.region(o);if(r)return r.inline;let i=t.nodes.get(o);if(!i||i.opaque||i.paragraph)return false;let s=t.detachedRoot(o);return !s.outside&&(s.kind==="textValue"||pl(s))};switch(e.kind){case "putNode":{let o=e.descriptor.logicalId,r=t.nodes.get(o);return !r||r.paragraph||r.opaque?false:n(o)}case "spliceText":case "setAttribute":case "setNamespaceBinding":return n(e.logicalId);case "spliceChildren":return t.nodes.get(e.parentLogicalId)?.paragraph===true||n(e.parentLogicalId);case "moveNode":return t.nodes.get(e.destinationParentLogicalId)?.paragraph===true||n(e.destinationParentLogicalId);default:return false}}function oh(t,e){let n=t.record(e);return !n||!("childIds"in n)?true:n.childIds.some(o=>t.kindOf(o)==="run")}function rh(t,e){let n=new Set,o=new Set(e),r=i=>i.some(s=>o.delete(U(s))||s.kind!=="textValue"&&r(s.children));return t.schema.nodes.forEach((i,s)=>{if(o.size===0)return;let a=G(s),l=t.inline.textOf(a);if(!l||t.inline.isDeletedParagraph(a))return;let d=t.inline.viewOf(a);r(Ze(a,l,()=>null,t.limits,d))&&n.add(a);}),n}var sh=new Set(["proofErr","permStart","permEnd"]);function fi(t,e,n){return t==="bookmarkStart"||t==="bookmarkEnd"||isRangeMarkerKind(t)?true:t==="generic"&&n&&sh.has(e)}var ah=Lt(WML_NAMESPACE_URI);function pi(t){if(!_(t))return false;let e=Ge(t);return fi(e.kind,e.localName,e.namespaceId===ah)}function gl(t){return pi(t)?Et(t):null}function hl(t){let e=n=>t.find(o=>o.namespaceUri===WML_NAMESPACE_URI&&o.localName===n)?.value??null;return [e("id"),e("name")]}function lh(t){let e=new Map,n=[...t];for(;n.length>0;){let o=n.pop();if(o.kind!=="textValue"){e.set(o.id,o);for(let r of o.children)n.push(r);}}return e}function ml(t,e,n,o,r){if(n.size===0||e.length===0)return;let i=new Map;for(let a of e){let l=t.record(a);if(!l||!$(l)||l.childIds.length>0||!fi(l.kind,l.localName,l.namespaceUri===WML_NAMESPACE_URI))continue;let d=JSON.stringify([l.kind,l.localName,...hl(l.attributes)]),c=i.get(d)??[];c.push(a),i.set(d,c);}if(i.size===0)return;let s=lh(r);for(let a of n){if(!o.has(a))continue;let l=s.get(a);if(!l||!fi(l.kind,l.localName,l.namespaceUri===WML_NAMESPACE_URI))continue;let d=JSON.stringify([l.kind,l.localName,...hl(l.attributes)]),c=i.get(d)?.shift();if(c===void 0)continue;let u=t.schema.nodes.get(a);if(!_(u))continue;let f=t.splitLineageOf(c)??c;u.set(yn,f),u.set(wt,f);}}var dh=new Set(["tableRow","tableCell"]);function yl(t,e,n){let o=new Map,r=a=>e.reinserted.has(a)&&!e.unlistedAtEnd.has(a),i=[],s=new Set;for(let a of e.removed){let l=t.kindOf(a);if(!(l===null||l==="paragraph"||dh.has(l))&&!(r(a)||!t.isTombstoned(a))){s.add(a);for(let d of n.get(a)??[])i.push(d);}}for(;i.length>0;){let a=i.pop();if(s.has(a)||r(a)||t.isTombstoned(a))continue;if(s.add(a),t.kindOf(a)==="paragraph"){if(ch(t,a,s))continue;let c=uh(t,a);c.length>0&&o.set(a,c);continue}let d=t.nodeShape(a);if(d&&!d.isText)for(let c of d.children)i.push(c);}return o}function ch(t,e,n){return t.listingParents(e).some(o=>!n.has(o)&&!t.isTombstoned(o))}function uh(t,e){let n=t.inline.textOf(e);if(!n)return [];let o=t.inline.viewOf(e).shown(n),r=[];o.identities.ids.forEach((i,s)=>{i&&!o.hidden.has(s)&&r.push(i);});for(let i of o.incoming)for(let s of i.identities)s&&r.push(s);return r}var lt="o",fh=/^(\^?)(\d{1,16}:\d{1,16})$/,tt="-";function xl(t){if(t===tt)return {identity:tt,before:false};let e=typeof t=="string"?fh.exec(t):null;return e?{identity:e[2],before:e[1]==="^"}:null}function gi(t,e,n,o,r){let i={...o};delete i[lt];let s=Ut(t,e,n,i);s&&Le(t.doc).markCopy("move",s.id.client,s.id.clock,n.length,r);}function bl(t,e,n){let o=[],r=[],i="",s=()=>{r.length>0&&o.push({paragraph:e,indexes:r,value:i}),r=[],i="";};for(let a of t.steps){if(a.op!==n){a.op!==(n==="del"?"ins":"del")&&s();continue}let l=a.op==="del"?a.before:a.after,d=a.op==="del"?t.before[l]:t.after[l];if(typeof d.insert!="string"){s();continue}r.push(l),i+=d.insert;}return s(),o}function ph(t,e){let n=e.from+e.length;return (e.from===0||t[e.from-1])&&(n===t.length||t[n])}var hh=1<<20,Il=1<<24;function hi(t,e,n,o,r,i,s=false){let a=e(t),l=o.get(t),d=null;for(let c of n){if(c.paragraph===t.paragraph!==s||!r(c.paragraph,t.paragraph))continue;let u=e(c),f=o.get(c),p=u.length*a.length;if(p>hh)continue;if(p>i.cells)return d;i.cells-=p;let h=new Uint32Array(a.length+1);for(let g=1;g<=u.length;g+=1){let m=new Uint32Array(a.length+1);for(let w=1;w<=a.length;w+=1){if(f[g-1]||l[w-1]||u[g-1]!==a[w-1])continue;let I=h[w-1]+1;m[w]=I,I>(d?.length??0)&&(d={source:c,from:g-I,to:w-I,length:I});}h=m;}}return d}function Sl(t,e,n,o=()=>"",r=()=>""){let i=new Set,s=t.flatMap((y,v)=>bl(y,v,"del"));if(s.length===0)return i;let a=t.flatMap((y,v)=>bl(y,v,"ins")),l=new Set(s),d={cells:Il},c=new Map,u=y=>v=>{let E=l.has(v),P=`${y}:${v.paragraph}:${v.indexes[0]}:${E}`,j=c.get(P);if(!j){let K=t[v.paragraph];j=v.indexes.map(Y=>{let V=E?K.before[Y]:K.after[Y],q=V.insert;return y?`${q}\0${o(V,v.paragraph)}`:q}),c.set(P,j);}return j},f=new Map;for(let y of [...s,...a])f.set(y,y.indexes.map(()=>false));let p=t.map((y,v)=>r(v)),h=(y,v)=>p[y]===""||p[v]===""||p[y]===p[v],g=(y,v)=>{for(let E=0;E<v.length;E+=1)f.get(v.source)[v.from+E]=true,f.get(y)[v.to+E]=true;mh(t,y,v,e,n,i);};for(let y of a){let v=s.find(E=>E.paragraph!==y.paragraph&&h(E.paragraph,y.paragraph)&&E.value===y.value&&!f.get(E).some(Boolean));v&&g(y,{source:v,from:0,to:0,length:y.indexes.length});}let m=a.filter(y=>t[y.paragraph].before.length===0),w=y=>{let v={cells:Il};for(let E of m.length===0?[]:s)if(!f.get(E).some(Boolean))for(let{run:P,from:j}of gh(E,m,f,h,v,y))g(P,{source:E,from:j,to:0,length:P.indexes.length});};w(false);for(let y of a)for(let v=hi(y,u(true),s,f,h,d);v;)g(y,v),v=hi(y,u(true),s,f,h,d);w(true);let I=new Map;for(let y of a)I.set(y.paragraph,[...I.get(y.paragraph)??[],y]);let b=new Set(s.filter(y=>(I.get(y.paragraph)??[]).some(v=>v.value.includes(y.value)))),x=s.filter(y=>!b.has(y)),L=(y,v,E)=>{for(;;){let P=hi(v,u(false),y,f,h,d,E);if(!P||!ph(f.get(P.source),P))break;g(v,P);}};for(let y of a)L(x,y,false);let k=new Map;for(let y of b)k.set(y.paragraph,[...k.get(y.paragraph)??[],y]);for(let y of a){let v=k.get(y.paragraph);v&&L(v,y,true);}return i}function gh(t,e,n,o,r,i){let s=(a,l)=>{if(a.value.length===0||a.paragraph===t.paragraph||!o(t.paragraph,a.paragraph)||n.get(a).some(Boolean))return -1;let d=i?t.value.length:a.value.length;return r.cells<d?-1:(r.cells-=d,i?t.value.indexOf(a.value,l):t.value.startsWith(a.value,l)?l:-1)};for(let a=0;a<e.length;a+=1){if(s(e[a],0)<0)continue;let l=[],d=0,c=0;for(let f=a;f<e.length&&d<t.value.length;f+=1){let p=e[f],h=s(p,d);if(h<0)break;l.push({run:p,from:h}),d=h+p.value.length,c+=p.value.length;}if(i?c*2>t.value.length:c===t.value.length&&l.length>1)return l}return []}function mh(t,e,n,o,r,i){let s=t[n.source.paragraph],a=c=>{let u=s.before[n.source.indexes[n.from+c]];return u?.position===void 0?null:s.identities[u.position]??null},l=t[e.paragraph],d=null;for(let c=0;c<n.length;c+=1){let u=e.indexes[n.to+c],f=a(c);f&&i.add(f);let p=c>0?l.after[e.indexes[n.to+c-1]]:null,h=p!==null&&r(p)===r(l.after[u]);(!d||!h||!jt(a(c-1),f))&&(d=f),d&&(l.after[u]=o(l.after[u],d));}}var yh="docx-text-marks-v1",bh={move:"o",restore:"u",follow:"f"},El=/^([ouf])(\d{1,16}):(\d{1,16})$/,Ih=/^(\d{1,16}):(\d{1,16}):(\d{1,16})$/,xh=/^(\d{1,16})\|(.{1,40})$/,yi=16,wl=1<<20,kl=4096;function vl(t,e){let n=0,o=t.length;for(;n<o;){let r=n+o>>1;t[r].firstClock<=e?n=r+1:o=r;}return n}function Ll(t,e,n){return `${bh[t]}${e}:${n}`}function Je(t){let e=Number(t);return Number.isSafeInteger(e)?e:null}function Sh(t,e){let n=El.exec(t);if(!n||typeof e!="string")return null;let o=n[1]==="o"?"move":n[1]==="u"?"restore":"follow",r=Je(n[2]),i=Je(n[3]);if(r===null||i===null)return null;if(o==="follow"){let u=xh.exec(e),f=u?Je(u[1]):null,p=u?xl(u[2]):null;return f===null||f<1||f>wl||!p?null:{kind:o,client:r,span:{key:t,client:r,firstClock:i,length:f,origin:null,follow:p}}}let s=Ih.exec(e),a=s?Je(s[1]):null,l=s?Je(s[2]):null,d=s?Je(s[3]):null;return a===null||l===null||d===null||d<1||d>wl?null:{kind:o,client:r,span:{key:t,client:r,firstClock:i,length:d,origin:{client:a,clock:l,insertClient:r,firstClock:i,length:d},follow:null}}}var wh={origin:()=>null,follow:()=>null,followStart:()=>null},mi=class{constructor(e,n){this.doc=e;this.map=n;n.forEach((o,r)=>this.refresh(r,o));}doc;map;spans={move:new Map,restore:new Map,follow:new Map};byKey=new Map;dependents=new Map;listeners=new Set;textsOfClients=new Map;subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}origin(e,n,o){return this.find(e,n,o)?.origin??null}follow(e,n){return this.find("follow",e,n)?.follow??null}followStart(e,n){return this.find("follow",e,n)?.firstClock??null}markCopy(e,n,o,r,i){this.write(Ll(e,n,o),`${i}:${r}`);}markFollow(e,n,o,r){this.write(Ll("follow",e,n),`${o}|${r}`);}refreshKeys(e){let n=[];for(let r of e){if(r===null)continue;let i=this.byKey.get(r)?.span.length??0;this.refresh(r,this.map.get(r));let s=this.byKey.get(r)?.span.length??0,a=El.exec(r),l=a?Je(a[2]):null,d=a?Je(a[3]):null;l===null||d===null||n.push({client:l,from:d,to:d+Math.max(i,s,1)});}let o=this.textsReading(n);if(!(o!=="all"&&o.size===0))for(let r of this.listeners)r(o);}textsReading(e){let n=new Set,o=new Set,r=new Set,i=()=>{for(let a of r)for(let l of this.textsOfClient(a))n.add(l);return n},s=e;for(let a=0;a<=yi&&s.length>0;a+=1){let l=[];for(let d of s)r.add(d.client);for(let d of s){let c=`${d.client}:${d.from}:${d.to}`;if(!o.has(c)){if(o.size>=kl)return this.withDependents(r,i);o.add(c);for(let u=d.from,f=0;u<d.to;f+=1){if(f>=kl)return this.withDependents(r,i);let p=H(this.doc,{client:d.client,clock:u});if(!p)break;p.parent instanceof z.Text&&n.add(p.parent),u=p.id.clock+p.length;}for(let u of this.dependents.get(d.client)??[]){let f=kh(u,d);f&&l.push(f);}}}s=l;}return n}withDependents(e,n){let o=[...e];for(;o.length>0;){let r=o.pop();for(let i of this.dependents.get(r)??[])e.has(i.client)||(e.add(i.client),o.push(i.client));}return n()}textsOfClient(e){let n=z.getState(this.doc.store,e),o=this.textsOfClients.get(e);if(o?.state===n)return o.texts;let r=new Set;for(let i of this.doc.store.clients.get(e)??[]){let s=i instanceof z.Item?i.parent:null;s instanceof z.Text&&r.add(s);}return this.textsOfClients.set(e,{state:n,texts:r}),r}write(e,n){this.map.get(e)!==n&&(this.map.set(e,n),this.refresh(e,n));}refresh(e,n){this.remove(e);let o=Sh(e,n);if(!o)return;let r=_e(this.map,e);if(r&&r.id.client!==o.client)return;let i=this.spans[o.kind].get(o.client)??[];i.splice(vl(i,o.span.firstClock),0,o.span),this.spans[o.kind].set(o.client,i),this.byKey.set(e,{kind:o.kind,span:o.span});let s=Rl(o.span);if(s!==null){let a=this.dependents.get(s)??new Set;a.add(o.span),this.dependents.set(s,a);}}remove(e){let n=this.byKey.get(e);if(!n)return;this.byKey.delete(e);let o=this.spans[n.kind].get(n.span.client);if(o){for(let i=vl(o,n.span.firstClock)-1;i>=0&&o[i].firstClock===n.span.firstClock;i-=1)if(o[i]===n.span){o.splice(i,1);break}}let r=Rl(n.span);r!==null&&this.dependents.get(r)?.delete(n.span);}find(e,n,o){let r=this.spans[e].get(n);if(!r)return null;let i=0,s=r.length-1,a=null;for(;i<=s;){let l=i+s>>1,d=r[l];d.firstClock<=o?(a=d,i=l+1):s=l-1;}return a&&o<a.firstClock+a.length?a:null}};function Rl(t){if(t.origin)return t.origin.client;let e=t.follow?.identity,n=e?.indexOf(":")??-1;return n>0?Je(e.slice(0,n)):null}function kh(t,e){if(t.origin){let r=Math.max(e.from,t.origin.clock),i=Math.min(e.to,t.origin.clock+t.length);if(r>=i)return null;let s=t.firstClock-t.origin.clock;return {client:t.client,from:r+s,to:i+s}}let n=t.follow.identity,o=Je(n.slice(n.indexOf(":")+1));return o===null||o<e.from||o>=e.to?null:{client:t.client,from:t.firstClock,to:t.firstClock+t.length}}var Ol=new WeakMap;function Le(t){let e=Ol.get(t);if(e)return e;let n=t.getMap(yh),o=new mi(t,n);return t.on("beforeObserverCalls",r=>{let i=Ft(r,n);i&&o.refreshKeys(i);}),Ol.set(t,o),e=o,e}function dt(t){return t.doc?Le(t.doc):wh}function Bl(t,e,n){let o=[],r=0;for(let i of Mt(t)){let s=i.attributes??{},a=n?$r(s,n.limits,n.paragraphId):"";if(typeof i.insert=="string"){let l=Si(s);for(let d=0;d<i.insert.length;d+=1,r+=1){if(e?.has(r))continue;let c=`c${i.insert[d]}`;o.push({key:c,strong:`${c}\0${l}`,insert:i.insert[d],attributes:s,position:r,trail:a});}}else {if(r+=1,e?.has(r-1))continue;let l=i.insert,d=typeof l.n=="string"?`e${l.r===1?"r":""}${l.n}`:jl(s,a);o.push({key:d,strong:d,insert:l,attributes:s,position:r-1,trail:a});}}return o}function Ul(t,e){let n=xn(t).items;for(let o=0;o<n.length;o+=1){let r=n[o];if(r.kind==="char"&&r.attributes.textValueId===e.textValueId)return o+e.utf16Start}}function Io(t,e){let n=t.id,o=new Map;return xn(t).items.map(r=>{let i=o.get(r.attributes);if(!i){let d=Ct(r.attributes,n,e);i={attributes:d,trail:$r(d,e,n)},o.set(r.attributes,i);}let{attributes:s,trail:a}=i;if(r.kind==="char"){let d=`c${r.value}`,c=`${d}\0${Si(s)}`;return {key:d,strong:c,insert:r.value,attributes:s,trail:a}}if(r.kind==="embed"){let d=Vr(r),c=`e${"r"in d?"r":""}${r.node.id}`;return {key:c,strong:c,insert:d,attributes:s,trail:a}}let l=jl(s,a);return {key:l,strong:l,insert:{a:1},attributes:s,trail:a}})}var Fl=1<<20;function jl(t,e){return `a${ve(jr(t))}${e}`}function Si(t){return t.t??""}function zl(t,e,n=true,o){let r=Ml(t),i=Ml(e);if(r===null&&i===null)return Pl(t,e,n,o);let s=r?.starts??null,a=i?.starts??null,l=(c,u,f)=>{if(c===null)return [u];let p=c[u];return (u+1<c.length?c[u+1]:f)-p===2?[p,p+1]:[p]},d=[];for(let c of Pl(r?.tokens??t,i?.tokens??e,n))if(c.op==="del")for(let u of l(s,c.before,t.length))d.push({op:"del",before:u});else if(c.op==="ins")for(let u of l(a,c.after,e.length))d.push({op:"ins",after:u});else {let u=l(s,c.before,t.length),f=l(a,c.after,e.length);u.forEach((p,h)=>d.push({op:"eq",before:p,after:f[h]}));}return d}var Cl=t=>{if(t===void 0||typeof t.insert!="string")return false;let e=t.insert.charCodeAt(0);return e>=55296&&e<=56319},Tl=t=>{if(t===void 0||typeof t.insert!="string")return false;let e=t.insert.charCodeAt(0);return e>=56320&&e<=57343};function Ml(t){let e=false;for(let r=0;r+1<t.length&&!e;r+=1)e=Cl(t[r])&&Tl(t[r+1]);if(!e)return null;let n=[],o=[];for(let r=0;r<t.length;r+=1){let i=t[r],s=t[r+1];o.push(r);let a=s!==void 0&&(i.position===void 0||s.position===i.position+1);if(Cl(i)&&Tl(s)&&a){let l=`${i.insert}${s.insert}`,d=`c${l}`;n.push({...i,key:d,strong:`${d}\0${Si(i.attributes)}`,insert:l}),r+=1;}else n.push(i);}return {tokens:n,starts:o}}function Pl(t,e,n,o){let r=n?Lh(t,e,o):null;if(r)return r;let i=xi(t,e,false),s=xi(t,e,true),a=Ii(t,e,i),l=Ii(t,e,s),[d,c]=[bi(a),bi(l)],u=c!==d?c>d?l:a:Dl(l)<Dl(a)?l:a,f=Math.max(d,c);if(f<Math.min(t.length,e.length)&&vh(u,t,e)){let p=xi(t,e,false,false);for(let h of [i,s,p]){let g=Ii(t,e,h,true),m=bi(g);m>f&&([u,f]=[g,m]);}}return Ch(Mh(u,e),t)}function vh(t,e,n){let o=new Set;for(let r of t)r.op==="del"&&o.add(e[r.before].key);if(o.size===0)return false;for(let r of t)if(r.op==="ins"&&o.has(n[r.after].key))return true;return false}function Lh(t,e,n){let o=e.length-t.length;if(o<=0)return null;if(n!==void 0&&Rh(t,e,n,o))return Al(t.length,n,o);let r=0;for(;r<t.length&&t[r].strong===e[r].strong;)r+=1;let i=0;for(;i<t.length-r&&t[t.length-1-i].strong===e[e.length-1-i].strong;)i+=1;if(r+i!==t.length)return null;let s=e[r],a=e[r+o-1],l=r>0?t[r-1]:null;return l&&l.key===a.key&&l.strong!==a.strong||r<t.length&&t[r].key===s.key?null:Al(t.length,r,o)}function Rh(t,e,n,o){if(!Number.isSafeInteger(n)||n<0||n>t.length)return false;for(let r=0;r<n;r+=1)if(t[r].strong!==e[r].strong)return false;for(let r=n;r<t.length;r+=1)if(t[r].strong!==e[r+o].strong)return false;return true}function Al(t,e,n){let o=[];for(let r=0;r<e;r+=1)o.push({op:"eq",before:r,after:r});for(let r=e;r<e+n;r+=1)o.push({op:"ins",after:r});for(let r=e;r<t;r+=1)o.push({op:"eq",before:r,after:r+n});return o}function Oh(t){if(!Oe(t)||typeof t.insert!="string"||t.insert.length!==1)return false;let e=t.insert.charCodeAt(0);return e>=32&&(e<55296||e>57343)}var Eh=16;function Ch(t,e){let n=new Map;for(let o=0;o<Eh;o+=1){let r=[];for(let d of t){let c=r[r.length-1];c&&c[0].op==="eq"==(d.op==="eq")?c.push(d):r.push([d]);}let i=d=>{if(!d||d[0].op==="eq")return 0;let c=0;for(let u of d)u.op==="ins"&&(c+=1);return Math.max(c,d.length-c)},s=(d,c)=>d!==void 0&&d.some(u=>{if(u.op!=="del")return false;let f=e[u.before];return !Nh(f)&&c.has(f.trail??"")}),a=false,l=[];if(r.forEach((d,c)=>{let u=new Set(d.map(p=>p.op==="eq"?e[p.before].trail??"":""));if(!(d[0].op==="eq"&&d.length<=i(r[c-1])&&d.length<=i(r[c+1])&&(s(r[c-1],u)||s(r[c+1],u))&&d.every(p=>p.op==="eq"&&Oh(e[p.before])))){for(let p of d)l.push(p);return}a=true;for(let p of d)p.op==="eq"&&l.push({op:"del",before:p.before});for(let p of d)p.op==="eq"&&(l.push({op:"ins",after:p.after}),n.set(p.after,p.before));}),t=l,!a)break}return Th(t,n)}function Th(t,e){if(e.size===0)return t;let n=new Map;for(let[r,i]of e)n.set(i,r);let o=[];for(let r=0;r<t.length;){let i=t[r];if(i.op==="eq"){o.push(i),r+=1;continue}let s=r;for(;s<t.length&&t[s].op!=="eq";)s+=1;let a=t.slice(r,s);if(r=s,a.some(l=>l.op==="ins"&&!e.has(l.after))){o.push(...a);continue}for(let l of a){if(l.op!=="del")continue;let d=n.get(l.before);o.push(d===void 0?l:{op:"eq",before:l.before,after:d});}}return o}function Mh(t,e){for(let n=1;n<t.length;n+=1){let o=t[n];if(o.op!=="eq"||t[n-1].op!=="ins")continue;let r=n+1;for(;r<t.length&&t[r].op==="ins";)r+=1;let i=t[r-1];r===n+1||i.op!=="ins"||e[i.after].key===e[o.after].key&&t.splice(n,r-n,{op:"ins",after:o.after},...t.slice(n+1,r-1),{op:"eq",before:o.before,after:i.after});}return t}function Dl(t){let e=0,n=false;for(let o of t)o.op!=="eq"&&!n&&(e+=1),n=o.op!=="eq";return e}function Oe(t){return t.key.startsWith("c")}function Ph(t,e,n,o,r,i){let s=e,a=r,l=0;for(;;){for(;s<n&&!Oe(t[s]);)s+=1;for(;a<i&&!Oe(o[a]);)a+=1;if(s===n||a===i)return s===n&&a===i&&l>0;if(t[s].key!==o[a].key)return false;l+=1,s+=1,a+=1;}}var Ah=/"l":"del(Text|InstrText)"/,Dh=/\\"l\\":\\"(del|moveFrom)\\"/;function Nh(t){let e=t.attributes.t;return typeof e=="string"&&Ah.test(e)?true:t.trail!==void 0&&Dh.test(t.trail)}function bi(t){let e=0;for(let n of t)n.op==="eq"&&(e+=1);return e}function Ii(t,e,n,o=false){let r=[],i=0,s=0;for(let[a,l]of [...n,[t.length,e.length]]){let d=Nl(t,e,i,a,s,l,false),c=Yl(d,t,e);if(c.inRevision<c.equal){let g=Nl(t,e,i,a,s,l,true),m=Yl(g,t,e);m.equal>=c.equal&&m.inRevision>c.inRevision&&(d=g);}for(let g of d.head)r.push(g);let u=d.tail;({i,j:s}=d);let{bEnd:f,aEnd:p}=d;if(Ph(t,i,f,e,s,p))for(;i<f||s<p;)i<f&&s<p&&Oe(t[i])&&Oe(e[s])?(r.push({op:"eq",before:i,after:s}),i+=1,s+=1):i<f&&!Oe(t[i])?(r.push({op:"del",before:i}),i+=1):(r.push({op:"ins",after:s}),s+=1);let h=o?Yh(t,i,f,e,s,p):null;if(h){for(let g of h)r.push(g);i=f,s=p;}for(;i<f;i+=1)r.push({op:"del",before:i});for(;s<p;s+=1)r.push({op:"ins",after:s});for(let g of u)r.push(g);i=a,s=l,i<t.length&&s<e.length&&(r.push({op:"eq",before:i,after:s}),i+=1,s+=1);}return r}function Yh(t,e,n,o,r,i){if(r===i||i-r>=n-e)return null;let s=null,a=()=>{if(s)return s;s=new Map;for(let c=e;c<n;c+=1){let{key:u}=t[c],f=t[c].trail??"",p=s.get(u);p||s.set(u,p=new Map);let h=p.get(f);h||p.set(f,h=[]),h.push(c);}return s},l=c=>{let u=[],f=e;for(let p=r;p<i;p+=1){let h=o[p],g=-1;if(c){let m=h.trail??"";for(let[w,I]of a().get(h.key)??[]){if(!Mn(w,m))continue;let b=_h(I,f);b>=0&&(g<0||b<g)&&(g=b);}}for(let m=f;g<0&&m<n;m+=1)t[m].key===h.key&&(g=m);if(g<0)return null;for(;f<g;f+=1)u.push({op:"del",before:f});u.push({op:"eq",before:g,after:p}),f=g+1;}for(;f<n;f+=1)u.push({op:"del",before:f});return u};return ((i-r)*(n-e)<=Fl?l(true):null)??l(false)}function _h(t,e){let n=0,o=t.length;for(;n<o;){let r=n+o>>1;t[r]<e?n=r+1:o=r;}return n<t.length?t[n]:-1}function Nl(t,e,n,o,r,i,s){let a=[],l=[],d=()=>{for(;;)if(n<o&&r<i&&t[n].key===e[r].key)a.push({op:"eq",before:n,after:r}),n+=1,r+=1;else if(n<o&&r<i&&!Oe(t[n])&&Oe(e[r]))a.push({op:"del",before:n}),n+=1;else if(n<o&&r<i&&Oe(t[n])&&!Oe(e[r]))a.push({op:"ins",after:r}),r+=1;else break},c=()=>{for(;;)if(o>n&&i>r&&t[o-1].key===e[i-1].key)o-=1,i-=1,l.unshift({op:"eq",before:o,after:i});else if(o>n&&i>r&&!Oe(t[o-1])&&Oe(e[i-1]))o-=1,l.unshift({op:"del",before:o});else if(o>n&&i>r&&Oe(t[o-1])&&!Oe(e[i-1]))i-=1,l.unshift({op:"ins",after:i});else break};return s?(c(),d()):(d(),c()),{head:a,tail:l,i:n,j:r,bEnd:o,aEnd:i}}function Yl(t,e,n){let o=0,r=0,i=null,s=null,a=false;for(let l of [t.head,t.tail])for(let d of l){if(d.op!=="eq")continue;o+=1;let c=e[d.before].trail??"",u=n[d.after].trail??"";if(c===u){r+=1;continue}(c!==i||u!==s)&&(a=Mn(c,u),i=c,s=u),a&&(r+=1);}return {equal:o,inRevision:r}}function Mn(t,e){if(t===e)return true;let n=bo.get(e);n===void 0&&(bo.size>=_l&&bo.clear(),bo.set(e,n=new Map));let o=n.get(t);if(o!==void 0)return o;let r=new Set(JSON.parse(e||"[]").map(s=>JSON.stringify(s))),i=JSON.parse(t||"[]").every(s=>r.has(JSON.stringify(s)));return n.size>=_l&&n.clear(),n.set(t,i),i}var _l=1024,bo=new Map;function xi(t,e,n,o=true){let r=[],i=(f,p,h)=>t[p]?.strong===h.strong&&!Mn(t[f].trail??"",h.trail??"")&&Mn(t[p].trail??"",h.trail??""),s=0;for(;s<t.length&&s<e.length&&t[s].strong===e[s].strong&&!i(s,s+1,e[s]);)r.push([s,s]),s+=1;let a=t.length,l=e.length,d=[];for(;a>s&&l>s&&t[a-1].strong===e[l-1].strong&&!(a-2>=s&&i(a-1,a-2,e[l-1]));)a-=1,l-=1,d.unshift([a,l]);let c=a-s,u=l-s;if(o&&c>0&&u>0&&c*u<=Fl){let f=u+1,p=new Uint32Array((c+1)*f),h=new Array(c),g=new Array(u);for(let b=0;b<c;b+=1)h[b]=t[s+b].strong;for(let b=0;b<u;b+=1)g[b]=e[s+b].strong;let m=(b,x)=>h[b]===g[x];for(let b=c-1;b>=0;b-=1){let x=h[b],L=b*f,k=L+f;for(let y=u-1;y>=0;y-=1){let v=p[k+y],E=p[L+y+1];p[L+y]=x===g[y]?p[k+y+1]+1:v>E?v:E;}}let w=0,I=0;for(;w<c&&I<u;){let b=()=>p[(w+1)*f+I]!==p[w*f+I]||Mn(t[s+w].trail??"",e[s+I].trail??"");if(m(w,I))b()&&(r.push([s+w,s+I]),I+=1),w+=1;else {let x=p[(w+1)*f+I],L=p[w*f+I+1];x>L||x===L&&!n?w+=1:I+=1;}}}for(let f of d)r.push(f);return r}function $l(t,e){let n=null;for(let o of Object.keys(t))o in e||((n??={})[o]=null);for(let o of Object.keys(e))t[o]!==e[o]&&((n??={})[o]=e[o]);return n}var ki=64;function vi(t,e,n){for(let o=0;o<yi;o+=1){let r=t.origin("move",e,n)??t.origin("restore",e,n);if(!r)break;let i=r.client,s=r.clock+n-r.firstClock;if(i===e&&s===n)break;e=i,n=s;}return [e,n]}function Wl(t,e){let n=ke(e);return n?Li(t,n.client,n.clock):e}function Li(t,e,n){let[o,r]=vi(t,e,n);return `${o}:${r}`}function ot(t,e,n){return Li(dt(t),e.id.client,e.id.clock+n)}function wi(t,e){return e===t.id.clock?t.origin:{client:t.id.client,clock:e-1}}function Bh(t,e,n){let o=[],r=e.left;if(r&&e.origin&&!r.deleted&&!(r.content instanceof z.ContentFormat)&&r.id.client===e.origin.client&&r.id.clock+r.length-1===e.origin.clock)return {live:n(r,e.origin.clock),deleted:o};let i=e.origin;for(let s=0;i&&s<ki;s+=1){let a=H(t,i);if(!a)break;if(!a.deleted){if(a.content instanceof z.ContentFormat){i=wi(a,i.clock);continue}return {live:n(a,i.clock),deleted:o}}let l=n(a,i.clock);l&&o.push(l),i=wi(a,i.clock);}return {live:null,deleted:o}}function Uh(t,e,n){let o=e.rightOrigin;for(let r=0;o&&r<ki;r+=1){let i=H(t,o);if(!i)return null;if(i.deleted||!(i.content instanceof z.ContentFormat))return n(i,o.clock);o=i.rightOrigin;}return null}function Kl(t,e,n){return e.deleted||e.content instanceof z.ContentString?Li(t,e.id.client,n):null}function Se(t,e){return t.moved[e]===true||t.restored[e]===true}function Fh(t,e,n){let[o,r]=vi(e,n.id.client,n.id.clock),i=t.doc;return i&&H(i,{client:o,clock:r})?.parent===t?[o,r]:null}function jh(t,[e,n],o){return !o||o.identity===tt||t.followStart(e,n)===n?o:{identity:`${e}:${n-1}`,before:false}}function zh(t,e,n){return e?e.identity===tt||e.before?[]:[Wl(t,e.identity)]:[...n.deleted,...n.live===null?[]:[n.live]]}function on(t){let e=be(t),n=dt(t),o=[],r=[],i=[],s=[],a=[],l=[],d=[],c=[],u=t.doc?Qe(t.doc):null,f=[],p=[],h=[],g=[],m=false,w=t.doc,I=(b,x)=>Kl(n,b,x);for(let b=e;b;b=b.right){if(b.deleted||!b.countable)continue;let x=b.content instanceof z.ContentString,L=x||b.content instanceof z.ContentEmbed,k=A=>x&&n.origin("move",b.id.client,A)!==null,y=A=>x&&!k(A)&&n.origin("restore",b.id.client,A)!==null,v=y(b.id.clock),E=k(b.id.clock)||v,P=v?Fh(t,n,b):null,j=L&&(!E||P!==null),K=P?n.follow(...P):null,Y=L?P?jh(n,P,K):n.follow(b.id.client,b.id.clock):null,V=Y&&Y.identity!==tt?{...Y,identity:Wl(n,Y.identity)}:Y,q=w?Bh(w,b,I):{live:null,deleted:[]},ee=null;if(j&&V&&(q.deleted.length>0||q.live===null)?ee=[V]:j&&q.deleted.length>0&&(ee=q.deleted.map(A=>({identity:A,before:false}))),ee&&(m=true),L&&!E&&!Y&&q.live===null&&w){let A=Uh(w,b,I);A&&(ee=[...ee??[],{identity:A,before:true}]);}let ne=E?zh(n,K,q):null;for(let A=0;A<b.length;A+=1){if(s.push(`${b.id.client}:${b.id.clock+A}`),a.push(A>0?`${b.id.client}:${b.id.clock+A-1}`:b.origin?`${b.origin.client}:${b.origin.clock}`:null),x){let[J,he]=vi(n,b.id.client,b.id.clock+A);o.push(`${J}:${he}`),r.push(J),i.push(he);}else o.push(null),r.push(-1),i.push(-1);l.push(k(b.id.clock+A)),d.push(y(b.id.clock+A)),c.push(x&&u!==null&&u.isDeleted(r[r.length-1],i[i.length-1])),p.push(A===0),h.push(A===0?q.live:null),g.push(A===0?ne:null),f.push(A===0?ee:null);}}return {ids:o,clients:r,clocks:i,items:s,origins:a,moved:l,restored:d,deleted:c,anchors:f,hasAnchors:m,starts:p,lefts:h,copiedAfter:g}}function Ri(t,e,n){let o=t.doc;if(!o)return false;let r=dt(t),i=e.origin;for(let s=0;i&&s<ki;s+=1){let a=H(o,i);if(!a)return false;let l=Kl(r,a,i.clock);if(l!==null&&n(l))return true;i=wi(a,i.clock);}return false}var ct="splitPoints",$h=/^\d{1,16}:\d{1,16}$/,Wh=/^\d{1,16}:\d{1,16}\+?$/;function Kh(t){if(!t)return null;let e=null;for(let n=be(t);n;n=n.right)!n.deleted&&typeof n.content.str=="string"&&(e=n);return e?ot(t,e,e.length-1):null}function Jl(t,e){if(!t||!e)return Kh(t);let{ids:n}=e.identities;for(let o=n.length-1;o>=0;o-=1)if(!e.hidden.has(o)&&n[o])return n[o];return null}function Hl(t){let e=t?.get(ct);return typeof e=="string"&&e.length<=4096?e.split(`
|
|
11
|
-
`):null}function An(t){let e=
|
|
12
|
-
`)}function Vh(t,e,n){let o=0,r=t._start;for(;r;r=r.right)if(!(r.deleted||!r.countable)){if(r===e){let i=r.content.getContent().indexOf(n);return i<0?-1:o+i}o+=r.length;}return -1}var Pn=new WeakSet,So=new WeakMap,Xl=(t,e)=>{let n=t.content.getContent().indexOf(e);return n<0?null:`${t.id.client}:${t.id.clock+n}`};function Gl(t){t&&Pn.add(t);}function ql(){Pn=new WeakSet,So=new WeakMap;}function Ql(t,e,n,o,r,i=()=>false){if(!n)return;let s=null;for(let a of o){let l=t(a);if(!l)continue;let d=null,c=null;for(let m of r)if(!m.deleted&&(d=Xl(m,a))){c=m;break}if(!d||!c)continue;let u=Pn.has(l)&&!So.has(l);if(u&&So.set(l,d),u&&l.has(ct)){Pn.delete(l);continue}s??=n.toArray();let f=Vh(n,c,a),p=f>0?s[f-1]:void 0;if(!u&&(p===void 0||!i(p)))continue;let h=ut(p===void 0?void 0:t(p)),g=u&&p!==void 0?e(p):null;g&&(h=[...h,{source:p,at:`${g}+`}]),h.length>0&&l.set(ct,wo(h,d));}}function Zl(t,e,n,o,r){if(!e||o<=0)return;let i=[],s=new Set,a=0,l=e._start;for(;l&&a<n+o;l=l.right){if(l.deleted||!l.countable)continue;let u=Math.max(n-a,0),f=Math.min(n+o-a,l.length);for(let p=u;p<f;p+=1)i.push({item:l,at:p});u===0&&f===l.length&&s.add(l),a+=l.length;}let d=(u,f)=>u.content.getContent()[f],c=(u,f)=>!i.some(p=>p.item===u&&p.at===f);for(let{item:u,at:f}of i){let p=d(u,f);if(!r(p))continue;let h=ut(t(p));if(h.length===0)continue;let g=u,m=f+1;for(;m<u.length&&!c(u,m);)m+=1;if(m>=u.length){let k=[u];for(g=u.right;g;g=g.right)if(!(g.deleted&&!k.some(y=>xo(g.origin,y)))){if(!k.some(y=>xo(g.origin,y))){g=null;break}if(!g.deleted&&!s.has(g))break;k.push(g);}if(!g)continue;for(m=0;m<g.length&&!c(g,m);)m+=1;if(m>=g.length)continue}let w=d(g,m),I=t(w),b=I?`${g.id.client}:${g.id.clock+m}`:null;if(!I||!b)continue;let x=An(I),L=x&&xo(x,g)?ut(I):[];L.some(k=>k.source===h.at(-1).source)||I.set(ct,wo([...h,...L],b));}}function ed(t,e,n){for(let o of it(t,n))if(!(o.deleted||!(o.parent instanceof z.Array))&&o.content instanceof z.ContentAny)for(let r of o.content.getContent()){if(typeof r!="string")continue;let i=r,s=e(i),a=An(s);if(!s||!a||xo(a,o))continue;let l=H(t,a);for(let c=0;l&&l!==o&&l.redone&&c<64;c+=1)l=H(t,l.redone);let d=l===o?Xl(o,i):null;d&&s.set(ct,wo(ut(s),d));}}function xo(t,e){return t!==null&&t.client===e.id.client&&t.clock>=e.id.clock&&t.clock<e.id.clock+e.length}function Oi(t,e){for(let n=t.length-1;n>=0;n-=1)if(t[n].source===e)return t[n].at;return null}function td(t){for(let e of t){if(e.before.length>0)continue;let n=e.after.find(o=>o.attributes[lt])?.attributes[lt];if(n&&$h.test(n))for(let o of t){if(o===e||!o.identities.includes(n))continue;let r=ut(o.record),i=So.get(e.record);if(!i||!Pn.delete(e.record))break;e.record.set(ct,wo([...r,{source:o.id,at:n}],i));break}}}function Jh(t){for(let e of Object.keys(t))if(e.startsWith(de)&&t[e]===null)return true;return false}function nd(t,e,n,o,r){let i=new Array(e.length).fill(null),s=false;for(let l of o){if(l.op==="del"&&(i[l.before]="del"),l.op!=="eq")continue;let d=r(e[l.before].attributes,n[l.after].attributes);!d||!Jh(d)||(i[l.before]=d,s=true);}if(!s)return;let a=0;for(;a<i.length;){if(i[a]!=="del"){a+=1;continue}let l=a;for(;l<i.length&&i[l]==="del";)l+=1;let d=a>0?i[a-1]:null,c=l<i.length?i[l]:null,u=d&&d!=="del"?d:c&&c!=="del"?c:null;if(u){let f={...Tt(u)};for(let h=a;h<l;h+=1)for(let g of Object.keys(e[h].attributes))(g.startsWith(de)||g===xe)&&(f[g]=null);let p=a;for(let h=a+1;h<=l;h+=1){if(h<l&&e[h].position===e[h-1].position+1)continue;let g=e[p].position;t.format(g,e[h-1].position-g+1,f),p=h;}}a=l;}}function Ti(t){let e=[],n=null;return t.ids.forEach((o,r)=>{if(o===null||t.deleted[r])return;let i=t.clients[r],s=t.clocks[r],a=t.moved[r]?"move":t.restored[r]?"restore":"original";if(n&&n.client===i&&n.end===s&&n.kind===a){n.end+=1;return}n&&e.push(n),n={client:i,start:s,end:s+1,kind:a};}),n&&e.push(n),e}var Ei=class{constructor(e){this.bound=e;}bound;entries=[];add(e){this.entries.splice(this.firstAtOrAfter(e.run.start),0,e);}remove(e){for(let n=this.firstAtOrAfter(e.run.start);n<this.entries.length;n+=1){let o=this.entries[n];if(o.run.start!==e.run.start)break;if(o.paragraph===e.paragraph&&o.run.end===e.run.end)return this.entries.splice(n,1),true}return false}collect(e,n,o){for(let r=this.firstAtOrAfter(n)-1;r>=0;r-=1){let i=this.entries[r];if(i.run.start+this.bound<=e)break;i.run.end>e&&o.push(i);}}firstAtOrAfter(e){let n=0,o=this.entries.length;for(;n<o;){let r=n+o>>1;this.entries[r].run.start<e?n=r+1:o=r;}return n}},Ci=class{classes=new Map;add(e){let n=od(e.run.end-e.run.start),o=this.classes.get(n);o||this.classes.set(n,o=new Ei(2**(n+1))),o.add(e);}remove(e){let n=od(e.run.end-e.run.start),o=this.classes.get(n);o?.remove(e)&&o.entries.length===0&&this.classes.delete(n);}overlapping(e,n){let o=[];for(let r of this.classes.values())r.collect(e,n,o);return o}};function od(t){return t<=1?0:31-Math.clz32(t)}var Dn=class{runsOf=new Map;tables={original:new Map,move:new Map,restore:new Map};update(e,n){let o=this.runsOf.get(e)??[],r=u=>`${u.client}:${u.start}:${u.end}:${u.kind}`,i=u=>{let f=new Map;for(let p of u){let h=f.get(r(p));h?h.push(p):f.set(r(p),[p]);}return f},s=i(o),a=i(n),l=new Set,d=[],c=u=>{for(let f of Object.values(this.tables))for(let p of f.get(u.client)?.overlapping(u.start,u.end)??[])p.paragraph!==e&&l.add(p.paragraph);};for(let[u,f]of s)for(let p of f.slice(a.get(u)?.length??0))this.tables[p.kind].get(p.client)?.remove({run:p,paragraph:e}),d.push(p),p.kind!=="original"&&c(p);for(let[u,f]of a)for(let p of f.slice(s.get(u)?.length??0)){let h=this.tables[p.kind],g=h.get(p.client);g||(g=new Ci,h.set(p.client,g)),g.add({run:p,paragraph:e}),d.push(p),p.kind!=="original"&&c(p);}return n.length>0?this.runsOf.set(e,[...n]):this.runsOf.delete(e),{affected:l,changed:d}}overlapping(e,n,o,r){return this.tables[e].get(n)?.overlapping(o,r)??[]}hasCopies(e){return this.tables.move.has(e)||this.tables.restore.has(e)}holdersOf(e,n,o){return (this.tables[e].get(n)?.overlapping(o,o+1)??[]).map(r=>r.paragraph)}holders(e,n){return ["original","move","restore"].flatMap(o=>this.holdersOf(o,e,n))}contested(){let e=new Set,n=[];for(let[o,r]of this.runsOf)for(let i of r){if(i.kind==="original")continue;let s=false;for(let a of ["move","restore"])for(let l of this.overlapping(a,i.client,i.start,i.end))l.paragraph!==o&&(s=true,e.add(o),e.add(l.paragraph));s&&n.push(i);}return {paragraphs:e,runs:n}}clear(){this.runsOf.clear();for(let e of Object.values(this.tables))e.clear();}};var rd=4096;function id(t,e){let n=ke(e),o=n?H(t,n):null,r=o?.parent;if(!o||!(r instanceof z.Text))return null;for(let i=r._item;i;i=i.parent instanceof z.AbstractType?i.parent._item:null)if(i.deleted)return null;return {item:o,text:r}}function Hh(t){let e=new Map,n=0;for(let o=be(t);o;o=o.right)for(let r=0;r<o.length;r+=1,n+=1){let i=ot(t,o,r);e.has(i)||e.set(i,n);}return e}function Xh(t,e){let n=dt(t);for(let o=be(t);o;o=o.right)for(let r=0;r<o.length;r+=1){if(!n.origin("move",o.id.client,o.id.clock+r))continue;let i=e.get(ot(t,o,r));if(i!==void 0)return i}return null}var ko=class{constructor(e,n){this.textOf=e;this.order=n;}textOf;order;places=new Map;keys=new Map;sourceSegments(e,n,o,r){let i=this.textOf(e)?.doc,s=[],a=o+r;for(let l=o;l<a;){let d=null;try{d=i&&l<z.getState(i.store,n)?z.getItem(i.store,z.createID(n,l)):null;}catch{d=null;}let c=d?Math.min(a,d.id.clock+d.length):a,u=d&&i?id(i,`${n}:${l}`)?.text??null:null,f=s.at(-1);f&&f.source===u?f.end=c-o:s.push({start:l-o,end:c-o,source:u}),l=Math.max(c,l+1);}return s}sourceOf(e,n){let o=this.textOf(e)?.doc;return (o&&id(o,n)?.text)??null}compare(e,n,o){if(e===n)return 0;if(o){let r=this.keyOf(e,o),i=this.keyOf(n,o);if(r!==i)return r===null?-1:i===null?1:r-i}return this.order(e,n)}lastOf(e,n,o){let r=o&&e.length>1?this.sourceOf(e[0],n):null,i=null;for(let s of e)(i===null||this.compare(s,i,r)>0)&&(i=s);return i}forget(e){this.keys.delete(e);let n=this.textOf(e);n&&this.places.delete(n);}clear(){this.keys.clear(),this.places.clear();}keyOf(e,n){let o=this.places.get(n);o||(this.places.size>=rd&&this.places.clear(),o=Hh(n),this.places.set(n,o));let r=this.keys.get(e),i=r?.get(n);if(i&&i.places===o)return i.key;let s=this.textOf(e),a=s?Xh(s,o):null;return r||(this.keys.size>=rd&&this.keys.clear(),r=new Map,this.keys.set(e,r)),r.set(n,{places:o,key:a}),a}};var sd=new Set,Gh=64;function ad(t){let e=new Set;return t.ids.forEach((n,o)=>{n!==null&&Se(t,o)&&e.add(n);}),e}function qh(t){let e=Ti(t).map(o=>({...o,kind:"original"})),n=o=>{let r=ke(o);r&&e.push({client:r.client,start:r.clock,end:r.clock+1,kind:"original"});};for(let o of t.anchors)for(let r of o??[])n(r.identity);for(let o of t.copiedAfter)for(let r of o??[])n(r);return e}function Mi(t,e){if(t.positions.every((r,i)=>e.items[r]===t.items[i]))return [...t.positions];let o=new Map;return e.items.forEach((r,i)=>o.set(r,i)),t.items.flatMap(r=>{let i=o.get(r);return i===void 0?[]:[i]})}function Qh(t,e,n,o){if(o.size===0)return [];let{ids:r}=e,i=new Set;r.forEach((l,d)=>{l!==null&&!n.has(d)&&i.add(l);});let s=[];for(let l=1;l<r.length;l+=1){let d=r[l-1];if(n.has(l)||!o.has(l-1)||!d||!i.has(d))continue;let c=[];for(let u=l;u<r.length&&!n.has(u);u+=1)c.push(u);s.push({source:t,after:d,before:false,positions:c,identities:c.map(u=>r[u]??null),items:c.map(u=>e.items[u])}),l+=c.length;}let a=new Set;for(let l of s)for(let d of l.positions)a.add(d);for(let l=0;l<r.length;l+=1){if(!e.starts[l]||n.has(l)||a.has(l))continue;let d=e.anchors[l]?.find(f=>f.before);if(!d||!i.has(d.identity))continue;let c=l+1;for(;c<r.length&&!e.starts[c]&&!n.has(c);)c+=1;if(c>=r.length||!o.has(c)||r[c]!==d.identity)continue;let u=[];for(let f=l;f<c;f+=1)u.push(f);for(let f of u)a.add(f);s.push({source:t,after:d.identity,before:true,positions:u,identities:u.map(f=>r[f]??null),items:u.map(f=>e.items[f])});}for(let l of s)for(let d of l.positions)n.add(d);return s}var vo=class{constructor(e,n,o,r,i,s=()=>null){this.textOf=e;this.isDeleted=n;this.viewsChanged=r;this.originalParagraph=i;this.undoneInto=s;this.holders=new ko(e,o);}textOf;isDeleted;viewsChanged;originalParagraph;undoneInto;index=new Dn;sources=new Set;outgoingOf=new Map;incomingOf=new Map;targetsOf=new Map;followingCopiesOf=new Map;followingCopies=new Map;dependencies=new Dn;pending=new Set;ownChanges=new Set;readsOtherSources=new Set;followingIdsOf=new Map;joinedFrom=new Map;typedAnchored=new Map;typedOf=new Map;typedStale=new Set;typedBuilt=false;identities=new Map;recent=new Set;holders;paragraphChanged(e){let n=this.textOf(e),o=this.isDeleted(e);this.invalidate(e);let r=n?this.identitiesOf(e,n):null,{affected:i,changed:s}=this.index.update(e,r&&!o?Ti(r):[]),a=this.sources.has(e),l=!!n&&!!r&&(o?n.length>0:r.hasAnchors);l?this.sources.add(e):this.sources.delete(e),this.identities.has(e)&&this.touch(e);for(let d of s)for(let c of this.dependencies.overlapping("original",d.client,d.start,d.end))this.pending.add(c.paragraph);(a||l)&&(this.pending.add(e),this.ownChanges.add(e));for(let d of this.joinedFrom.get(e)??[])this.pending.add(d);for(let d of this.targetsOf.get(e)??[])i.add(d);return i.delete(e),i}settle(){if(this.pending.size===0)return;for(let r of this.readsOtherSources)this.sources.has(r)&&this.pending.add(r);this.readsOtherSources.clear();let e=[...this.pending],n=[...this.ownChanges];this.pending.clear(),this.ownChanges.clear();let o=this.relocate(e);for(let r of n)for(let i of this.targetsOf.get(r)??[])o.add(i);o.size>0&&this.viewsChanged(o);}shown(e,n){this.settle();let o=this.identitiesOf(e,n),r=new Set,i=new Set,s=new Set,{clients:a,clocks:l}=o,d=ad(o);for(let p=0;p<a.length;){let h=p+1;for(;h<a.length&&a[h]===a[p]&&l[h]===l[h-1]+1&&o.moved[h]===o.moved[p]&&o.restored[h]===o.restored[p];)h+=1;let g=a[p],m=Se(o,p);if(g>=0){let w=x=>this.index.overlapping(x,g,l[p],l[h-1]+1).filter(L=>L.paragraph!==e),I=w("move"),b=w("restore");if(I.length>0||b.length>0||m){let x=l[p],L=m?e:null,k=this.coverage("move",I,g,x,h-p,L),y=this.coverage("restore",b,g,x,h-p,L);for(let v=p;v<h;v+=1){let E=v-p,P={move:k.any[E]>0,laterMove:k.later[E]>0,restore:y.any[E]>0,laterRestore:y.later[E]>0};this.hides(o,v,P,i,s)&&r.add(v);}}if(!m&&d.size>0)for(let x=p;x<h;x+=1)d.has(o.ids[x])&&r.add(x);}p=h;}let c=this.outgoingOf.get(e);if(c)for(let p of Mi(c,o))r.add(p);this.followingCopies.size>0&&o.ids.forEach((p,h)=>{p===null||Se(o,h)||this.followingCopies.has(p)&&r.add(h);}),o.deleted.forEach((p,h)=>{p&&r.add(h);});let u=Qh(e,o,r,s),f=this.distinctIncoming(e,o,r);return {identities:o,hidden:r,incoming:u.length>0?[...f,...u]:f}}distinctIncoming(e,n,o){let r=this.incomingOf.get(e)??[];if(r.length===0)return r;let i=new Set;n.ids.forEach((a,l)=>{a!==null&&!o.has(l)&&i.add(a);});let s=[];for(let a of r){let l=a.positions.flatMap((d,c)=>{let u=a.identities[c]??null;return u!==null&&i.has(u)?[]:(u!==null&&i.add(u),[c])});l.length===a.positions.length?s.push(a):l.length>0&&s.push({...a,positions:l.map(d=>a.positions[d]),identities:l.map(d=>a.identities[d]??null),items:l.map(d=>a.items[d])});}return s}hides(e,n,o,r,i){let s=e.ids[n],a=false;return Se(e,n)&&r.has(s)&&i.add(n),e.moved[n]?a=r.has(s)||o.laterMove:e.restored[n]?a=r.has(s)||o.move||o.laterRestore:a=o.move||o.restore,Se(e,n)&&r.add(s),a}coverage(e,n,o,r,i,s){let a=new Int32Array(i+1),l=new Int32Array(i+1),d=s!==null&&e==="move"&&n.length>0?this.holders.sourceSegments(s,o,r,i):[{start:0,end:i,source:null}];for(let c of n){let u=Math.max(c.run.start,r)-r,f=Math.min(c.run.end,r+i)-r;if(!(u>=f)&&(a[u]+=1,a[f]-=1,s!==null))for(let p of d){let h=Math.max(u,p.start),g=Math.min(f,p.end);h>=g||this.holders.compare(c.paragraph,s,p.source)>0&&(l[h]+=1,l[g]-=1);}}for(let c=1;c<=i;c+=1)a[c]+=a[c-1],l[c]+=l[c-1];return {any:a,later:l}}holdersOf(e){let n=ke(e);return n?this.index.holders(n.client,n.clock):[]}holdsCopyIn(e,n,o){return this.index.hasCopies(e)?this.index.overlapping("move",e,n,o).length>0||this.index.overlapping("restore",e,n,o).length>0:false}shownMovedCopy(e){let n=ke(e);if(!n||!this.index.hasCopies(n.client))return null;let o=this.index.holdersOf("move",n.client,n.clock);return this.holders.lastOf(o,e,true)}shownCopy(e){let n=ke(e);if(!n)return null;let{client:o,clock:r}=n;return this.index.hasCopies(o)?this.holders.lastOf(this.index.holdersOf("move",o,r),e,true)??this.holders.lastOf(this.index.holdersOf("restore",o,r),e,false):null}orderChanged(){let{paragraphs:e,runs:n}=this.index.contested();for(let o of n)for(let r of this.dependencies.overlapping("original",o.client,o.start,o.end))this.pending.add(r.paragraph);return e}targetsFor(e){return this.settle(),this.targetsOf.get(e)??sd}placedTargetsFor(e){return this.targetsOf.get(e)??sd}invalidate(e){this.identities.delete(e),this.holders.forget(e),this.recent.delete(e),this.typedStale.add(e);}identitiesOf(e,n){let o=this.identities.get(e);if(o?.text===n)return this.touch(e),o.identities;let r=on(n);return this.identities.set(e,{text:n,identities:r}),this.touch(e),r}touch(e){if(this.recent.delete(e),this.sources.has(e)||(this.recent.add(e),this.recent.size<=Gh))return;let n=this.recent.values().next().value;this.recent.delete(n),this.identities.delete(n);}clear(){this.identities.clear(),this.holders.clear(),this.recent.clear(),this.index.clear(),this.sources.clear(),this.outgoingOf.clear(),this.incomingOf.clear(),this.targetsOf.clear(),this.followingCopiesOf.clear(),this.followingCopies.clear(),this.dependencies.clear(),this.pending.clear(),this.ownChanges.clear(),this.joinedFrom.clear(),this.typedAnchored.clear(),this.typedOf.clear(),this.typedStale.clear(),this.typedBuilt=false;}relocate(e){this.followingIdsOf.clear();let n=new Set;for(let d of e)for(let c of this.targetsOf.get(d)??[])n.add(c);let o=new Map;for(let d of n)o.set(d,JSON.stringify(this.incomingOf.get(d)??[]));let r=new Map;for(let d of e)r.set(d,JSON.stringify(this.outgoingOf.get(d)?.positions??[]));let i=new Set(e);for(let d of n){let c=(this.incomingOf.get(d)??[]).filter(u=>!i.has(u.source));c.length>0?this.incomingOf.set(d,c):this.incomingOf.delete(d);}let s=new Map,a=d=>{s.has(d)||s.set(d,this.followingCopies.has(d));};for(let d of e){this.targetsOf.delete(d),this.outgoingOf.delete(d);for(let p of this.followingCopiesOf.get(d)??[])a(p),this.countFollowingCopy(p,-1);this.followingCopiesOf.delete(d);let c=this.sources.has(d)?this.textOf(d):null,u=c?this.identitiesOf(d,c):null;if(this.dependencies.update(d,u?qh(u):[]),!u)continue;let f=new Map;for(let p of this.followingOf(d,u)){let h=p.target??this.shownCopy(p.after),g=this.incomingOf.get(h)??[];g.push(p),this.incomingOf.set(h,g);let m=this.targetsOf.get(d)??new Set;m.add(h),this.targetsOf.set(d,m),p.positions.forEach((w,I)=>{let b=p.identities[I]??null;if(f.set(w,b),b===null||!Se(u,w))return;let x=this.followingCopiesOf.get(d)??new Set;x.has(b)||(x.add(b),this.followingCopiesOf.set(d,x),a(b),this.countFollowingCopy(b,1));}),o.has(h)||o.set(h,"[]");}if(f.size>0&&!this.isDeleted(d)){let p=[...f.keys()].sort((h,g)=>h-g);this.outgoingOf.set(d,{positions:p,identities:p.map(h=>f.get(h)??null),items:p.map(h=>u.items[h])});}}for(let d of o.keys())this.incomingOf.get(d)?.sort((c,u)=>(c.source<u.source?-1:c.source>u.source?1:0)||c.positions[0]-u.positions[0]);let l=new Set;for(let[d,c]of r)JSON.stringify(this.outgoingOf.get(d)?.positions??[])!==c&&l.add(d);for(let[d,c]of o)JSON.stringify(this.incomingOf.get(d)??[])!==c&&l.add(d);for(let[d,c]of s)if(c!==this.followingCopies.has(d))for(let u of this.holdersOf(d))l.add(u);return l}countFollowingCopy(e,n){let o=(this.followingCopies.get(e)??0)+n;o>0?this.followingCopies.set(e,o):this.followingCopies.delete(e);}followingOf(e,n){let o=[],r=null,i=ad(n),s=null,a=l=>(s||(s=new Set,n.ids.forEach((d,c)=>{d&&n.moved[c]&&!n.restored[c]&&s.add(d);})),s.has(l));for(let l=0;l<n.ids.length;l+=1){let d=n.ids[l]??null,c=Se(n,l),u=d===null?null:this.shownCopy(d),f=u!==null&&!(u===e&&n.restored[l]&&!a(d));if(n.deleted[l]||d!==null&&(f||!c&&i.has(d))){r=null;continue}let p=!this.isDeleted(e),h=r!==null&&(!n.starts[l]||l>0&&n.lefts[l]===n.ids[l-1]),g=this.leadingAnchor(e,p,n.anchors[l])??(p||h?void 0:this.movedAfter(e,n,l));if(g){r={source:e,after:g.identity,before:g.before,...g.target?{target:g.target}:{},...g.atStart?{atStart:true}:{},positions:[l],identities:[d],items:[n.items[l]]},o.push(r);continue}if(r&&h){r.positions.push(l),r.identities.push(d),r.items.push(n.items[l]);continue}r=null;}return o}typedSources(){if(!this.typedBuilt){this.typedBuilt=true;for(let e of this.sources)this.typedStale.add(e);}for(let e of this.typedStale)this.readTyped(e);return this.typedStale.clear(),this.typedAnchored}readTyped(e){for(let s of this.typedOf.get(e)??[]){let a=(this.typedAnchored.get(s)??[]).filter(l=>l.source!==e);a.length>0?this.typedAnchored.set(s,a):this.typedAnchored.delete(s);}this.typedOf.delete(e);let n=this.sources.has(e)?this.textOf(e):null;if(!n)return;let o=this.identitiesOf(e,n),r=new Set,i=null;o.ids.forEach((s,a)=>{if(o.starts[a]&&(i=o.anchors[a]??null),!s||Se(o,a)||!i)return;let l=this.typedAnchored.get(s)??[];l.push({source:e,anchors:i}),this.typedAnchored.set(s,l),r.add(s);}),r.size>0&&this.typedOf.set(e,[...r]);}follows(e){let n=!this.isDeleted(e.source);return this.leadingAnchor(e.source,n,e.anchors)!==void 0}followsOutOf(e,n){if(this.isDeleted(e)||!this.sources.has(e))return false;let o=this.followingIdsOf.get(e);if(!o){let r=this.textOf(e),i=new Set;if(r)for(let s of this.followingOf(e,this.identitiesOf(e,r)))for(let a of s.identities)a&&i.add(a);o=i,this.followingIdsOf.set(e,o);}return o.has(n)}leadingAnchor(e,n,o){for(let r of o??[]){if(r.before&&n)continue;let i=this.shownCopy(r.identity);if(i!==null){if(i!==e)return r;if(this.shownMovedCopy(r.identity)===e)return}}}movedAfter(e,n,o){let r=n.ids[o];if(!r)return;let i=this.holdersOf(r);if(!Se(n,o)&&i.length>0||(this.readsOtherSources.add(e),(this.typedSources().get(r)??[]).some(d=>d.source!==e&&this.follows(d)))||i.some(d=>d!==e&&this.followsOutOf(d,r)))return;for(let d of n.copiedAfter[o]??[]){let c=this.shownCopy(d);if(c!==null&&c!==e)return {identity:d,before:false}}if(n.moved[o]){let d=this.originalParagraph(r);if(d!==null&&d!==e&&!this.isDeleted(d))return {identity:r,before:false,target:d}}let a=this.undoneInto(e);if(a===null||a.paragraph===e)return;let l=this.joinedFrom.get(a.paragraph)??new Set;if(l.add(e),this.joinedFrom.set(a.paragraph,l),!this.isDeleted(a.paragraph))return {identity:r,before:false,target:a.paragraph,...a.atStart?{atStart:true}:{}}}};function Zh(t,e){let n=[],o=0;for(let r of e){let i=r.op==="eq"?"eq":"change",s=n[n.length-1];s&&s.kind===i?s.steps.push(r):n.push({kind:i,steps:[r],after:o}),r.op==="eq"&&(o=t[r.before].position+1);}return n}function eg(t,e){let n=[];for(let o of t){let r=n[n.length-1];r&&e(r[r.length-1])===e(o)?r.push(o):n.push([o]);}return n}function Pi(t,e){if(!t)return null;if(e>0){let o=t.ids[e-1];return o&&Se(t,e-1)?o:null}let n=t.ids[0];return n&&Se(t,0)?`^${n}`:null}function Ai(t,e,n,o,r,i){let s=Ut(t,e,n,o);!r||!s||!Ri(t,s,i)||Le(t.doc).markFollow(s.id.client,s.id.clock,n.length,ld(r,e));}function ld(t,e){return e>0?t.ids[e-1]??tt:t.ids[0]?`^${t.ids[0]}`:tt}function tg(t,e,n,o,r,i){let s=Ut(t,e,n,o);if(!s)return;let a=r??(i&&Ri(t,s,i.hasShownCopy)?ld(i.identities,e):null);a&&Le(t.doc).markFollow(s.id.client,s.id.clock,1,a);}function Di(t,e,n,o,r){let i=Ut(t,e,n,o);i&&Le(t.doc).markFollow(i.id.client,i.id.clock,n.length,r);}function dd(t){let e=[];for(let n of t.toDelta()){let o=n.attributes??{},r=typeof n.insert=="string"?n.insert.length:1;for(let i=0;i<r;i+=1)e.push(o);}return e}function ng(t,e,n,o,r,i,s){let a=Zh(e,o),l=null,d=f=>f<=0?{}:(l??=dd(t),l[f-1]??{}),c=new Map,u=(f,p)=>{let h=c.get(f);h||c.set(f,h=new Map);let g=h.get(p);if(g===void 0){let m=$l(f,s(f,p,false));g=m&&{changes:m,key:JSON.stringify(m),from:ve(f)},h.set(p,g);}return g};nd(t,e,n,o,(f,p)=>u(f,p)?.changes??null);for(let f=a.length-1;f>=0;f-=1){let p=a[f];if(p.kind==="eq"){let L=[];for(let y of p.steps){let v=u(e[y.before].attributes,n[y.after].attributes);v&&L.push({...v,position:e[y.before].position});}let k=[];for(let y of L){let v=k[k.length-1],E=v?.[v.length-1];E&&E.position+1===y.position&&E.from===y.from&&E.key===y.key?v.push(y):k.push([y]);}for(let y=k.length-1;y>=0;y-=1){let v=k[y],E=r?Ka(v[0].changes,v.map(({position:P})=>{let[j,K]=(r.items[P]??"-1:-1").split(":");return {client:Number(j),clock:Number(K)}})):v[0].changes;Ba(t,E,r?.items,v);}continue}let h=p.steps.filter(L=>L.op==="del").map(L=>e[L.before].position),g=p.steps.filter(L=>L.op==="ins").map(L=>n[L.after]),m=h.length>0?h[0]:p.after,w=Pi(r,m),I=0,b=d(m);for(let L of eg(g,k=>typeof k.insert=="string"?`c${ve(k.attributes)}`:`e${I++}`)){let k={...L[0],attributes:Tt(s(b,L[0].attributes,true))};if(b=k.attributes,typeof k.insert!="string"){let E=r&&m===(h.length>0?h[0]:p.after)?{identities:r,hasShownCopy:i}:null;tg(t,m,k.insert,k.attributes,w,E),w=null,m+=1;continue}let y=L.map(E=>E.insert).join(""),v=k.attributes[lt];v?gi(t,m,y,k.attributes,v):w?Di(t,m,y,k.attributes,w):m===(h.length>0?h[0]:p.after)?Ai(t,m,y,k.attributes,r,i):t.insert(m,y,{...k.attributes}),w=null,m+=y.length;}let x=m-(h.length>0?h[0]:p.after);for(let L=h.length-1;L>=0;){let k=L;for(;k>0&&h[k-1]+1===h[k];)k-=1;Cs(t,h[k]+x,L-k+1),L=k-1;}}}function og(t,e,n){let r=t.inline.viewOf(e).shown(n);if(r.incoming.length===0)return {sources:[],wrote:false};let{ids:i}=r.identities,s=lo(r),a=new Map(r.incoming.map((x,L)=>[x,L])),l=[];for(let[x,L]of s.atPosition)for(let k of [...L.before,...L.after])l.push({following:k,order:a.get(k),at:x});for(let x of s.atEnd)l.push({following:x,order:a.get(x),at:i.length,atEnd:true});for(let x of s.atStart)l.push({following:x,order:a.get(x),at:-1,atEnd:true});let d=(x,L)=>L.at-x.at||(x.atEnd?0:Number(x.following.before))-(L.atEnd?0:Number(L.following.before))||L.order-x.order;l.sort(d);let c=new Set,u=new Set,f=false,p=[],h=x=>x-p.filter(L=>L<x).length,g=new Map,m=(x,L)=>{let k=g.get(x);return k||(k={identities:on(L),delta:Mt(L)},g.set(x,k)),k},w=(x,L)=>{let k=new Map,y=t.inline.textOf(x.source);if(!y)return {positions:[],landed:k};let{identities:v,delta:E}=m(x.source,y),P=Mi(x,v),j=v.ids,K=new Set(P),Y=[],V=0;for(let A of E){let J=typeof A.insert=="string"?A.insert.length:1,he=null,D=()=>he??=Ct(Ne(A.attributes,t.limits,x.source),e,t.limits);if(typeof A.insert=="string")for(let T=0;T<J;T+=1)K.has(V+T)&&Y.push({kind:"char",value:A.insert[T],attributes:{...D()},identity:j[V+T]??null,position:V+T});else if(K.has(V)&&A.insert!==null&&typeof A.insert=="object"){let T=Ms(y,V);T&&Y.push({kind:"embed",embed:A.insert,attributes:{...D()},item:T,position:V});}V+=J;}let q=[];for(let A of Y){let J=q[q.length-1],he=J?.[J.length-1];A.kind==="char"&&he?.kind==="char"&&ve(he.attributes)===ve(A.attributes)&&jt(he.identity,A.identity)?J.push(A):q.push([A]);}let ee=L,ne=(A,J)=>Tt(zr(A>0?dd(n)[A-1]??{}:{},J,true,t.limits,e));for(let A of q){let J=A[0];if(J.kind==="embed"){let T=y===n?Ps(n,J.item):null;As(y,J.item),g.delete(x.source),u.add(x.source),T!==null&&(p.push(T),T<ee&&(ee-=1)),n.insertEmbed(ee,J.embed,{...ne(ee,J.attributes)}),k.set(J.position,ee),ee+=1;continue}let he=A.map(T=>T.kind==="char"?T.value:"").join(""),D=ne(ee,J.attributes);J.identity?gi(n,ee,he,D,J.identity):n.insert(ee,he,D),A.forEach((T,S)=>k.set(T.position,ee+S)),ee+=he.length;}return g.delete(e),c.add(x.source),q.length>0&&(f=true),{positions:P,landed:k}},I=[],b=(x,L)=>{let k=s.inside.get(x);if(!k)return;let y=[];for(let[v,E]of k){let P=L.positions[v],j=P===void 0?void 0:L.landed.get(P);for(let K of [...E.before,...E.after])j===void 0?I.push(K):y.push({following:K,order:a.get(K),at:j});}y.sort(d);for(let v of y){let E=v.following.before?v.at:v.at+1;b(v.following,w(v.following,E));}};for(let x of l){let L=x.atEnd?Math.max(x.at,0):x.following.before?x.at:x.at+1;b(x.following,w(x.following,h(L)));}for(let x of I)b(x,w(x,n.length));for(let x of u)t.inline.follow.invalidate(x);return t.inline.follow.invalidate(e),t.inline.noteDrift(),{sources:[...c],wrote:f}}function Ni(t){let e=new Set;for(let n of t.steps){if(n.op!=="del")continue;let o=t.before[n.before].position,r=o===void 0?null:t.identities[o];r&&e.add(r);}return e}function rg(t){let e=new Set;for(let o of t)for(let r of Ni(o))e.add(r);if(e.size===0)return [];let n=[];for(let o of t){if(!o.text||o.hidden.size===0)continue;let r=[...o.hidden].filter(s=>{let a=o.identities[s];return a!=null&&e.has(a)});if(r.length===0)continue;let i=o.shownIdentities;n.push({write:o,ids:br(o.text,r),originals:r.map(s=>i&&!i.moved[s]&&!i.restored[s]?o.identities[s]??null:null)});}return n}function Yi(t,e){return t===null||!e.has(t)}function ig(t,e,n){let o=new Set,r=new Set(e.map(s=>s.id));for(let s of e)for(let a of Ni(s))o.add(a);if(o.size===0)return;let i=new Set;for(let s of o)for(let a of t.inline.follow.holdersOf(s))r.has(a)||i.add(a);for(let s of i){let a=t.inline.textOf(s);if(!a)continue;let l=on(a),d=l.ids.flatMap((c,u)=>{if(!c||!o.has(c))return [];let f=Se(l,u);return Yi(f?null:c,n)?[u]:[]});d.length!==0&&(Wn(a,d),t.inline.follow.invalidate(s),t.inline.noteDrift());}}function cd(t,e){let n=new Set,o=new Map,r=new Set;for(let l of e){let d=t.inline.textOf(l);if(!d||!t.isTombstoned(l))continue;let c=t.inline.viewOf(l).shown(d),u=0;for(let p of d.toDelta()){if(typeof p.insert=="string"){u+=p.insert.length;continue}let h=p.insert?.n;typeof h=="string"&&!c.hidden.has(u)&&r.add(h),u+=1;}let f=[];c.identities.ids.forEach((p,h)=>{!p||c.hidden.has(h)||(f.push(p),Se(c.identities,h)&&n.add(p));});for(let p of c.incoming)for(let h of p.identities)h&&f.push(h);f.length>0&&o.set(l,f);}let i=[];if(n.size===0)return {held:i,shown:o,embeds:r};let s=new Set(e),a=new Set;for(let l of n)for(let d of t.inline.follow.holdersOf(l))s.has(d)||a.add(d);for(let l of a){let d=t.inline.textOf(l);if(!d)continue;let c=on(d),u=[],f=[];c.ids.forEach((p,h)=>{!p||!n.has(p)||(Se(c,h)?u.push(h):f.push(h));}),f.length>0&&i.push({holder:l,text:d,items:br(d,f),identities:f.map(p=>c.ids[p])}),u.length!==0&&(Wn(d,u),t.inline.follow.invalidate(l),t.inline.noteDrift());}return {held:i,shown:o,embeds:r}}function ud(t,e,n,o){let r=new Set(n);for(let i of e){if(o.embedded.has(i)||O(i))continue;let s=i;[...t.inline.holdersOf(s)].some(a=>!r.has(a))||!t.hasNode(s)||t.isTombstoned(s)||t.listingParents(s).length===0&&t.tombstone(s);}}function fd(t,e,n){let o=new Set(e.deleted);for(let i of n.values())for(let s of i)o.add(s);let r=Na([...o].filter(i=>!e.copied.has(i)));r.length>0&&Qe(t.doc).record(r);}function pd(t,e,n){for(let{holder:o,text:r,items:i,identities:s}of e){let a=i.filter((l,d)=>Yi(s[d],n));a.length!==0&&(Ir(r,a),t.inline.follow.invalidate(o),t.inline.noteDrift());}}function hd(t,e,n=new Map,o=new Set){let r=e.typed,i=new Set,s=[],a=new Set;for(let f=0,p=true;p&&f<=e.paragraphs.length;f+=1){p=false;for(let{id:h}of e.paragraphs){let g=t.inline.textOf(h);if(!g)continue;let{sources:m,wrote:w}=og(t,h,g);w&&(p=true);for(let I of m)I===h||o.has(I)||t.inline.isDeletedParagraph(I)&&a.add(I);}}for(let{id:f,after:p}of e.paragraphs){let h=t.schema.nodes.get(f);if(!h||a.has(f))continue;let g=n.get(f)??Io(p,t.limits),m=t.isTombstoned(f);for(let x of g){if(m)break;typeof x.insert!="string"&&"n"in x.insert&&i.add(x.insert.n);}let w=t.inline.textOf(f),I=w?t.inline.viewOf(f).shown(w):null,b=w?Bl(w,I?.hidden,{limits:t.limits,paragraphId:f}):[];s.push({id:f,record:h,text:w,before:b,after:g,steps:zl(b,g,true,r&&Ul(p,r)),identities:I?.identities.ids??[],shownIdentities:I?.identities??null,hidden:I?.hidden??new Set});}let l=rg(s),d=Sl(s,(f,p)=>({...f,attributes:{...f.attributes,[lt]:p}}),f=>{let{[lt]:p,...h}=f.attributes;return ve(h)},(f,p)=>Ne(f.attributes,t.limits,s[p].id).text?.id??"",f=>sg(t,s[f].id));td(s);for(let f of s){let p=f.text??ho(f.record,[]);ng(p,f.before,f.after,f.steps,f.shownIdentities,h=>t.inline.follow.shownCopy(h)!==null,(h,g,m)=>zr(h,g,m,t.limits,f.id)),t.inline.follow.invalidate(f.id);}for(let{write:f,ids:p,originals:h}of l){let g=p.filter((m,w)=>Yi(h[w],d));!f.text||g.length===0||(Ir(f.text,g),t.inline.follow.invalidate(f.id),t.inline.noteDrift());}ig(t,s,d);let c=new Set(e.paragraphs.map(f=>f.id));for(let f of e.embedsBefore)i.has(f)||[...t.inline.holdersOf(f)].some(p=>!c.has(p))||t.hasNode(f)&&!t.isTombstoned(f)&&t.listingParents(f).length===0&&t.tombstone(f);let u=new Set;for(let f of s)for(let p of Ni(f))u.add(p);return {copied:d,deleted:u,embedded:i}}function sg(t,e){if(t.parentOf(e)===null)return "";let n=e;for(let o=0;o<t.limits.maxTreeDepth;o+=1){let r=t.parentOf(n);if(r===null)return n;n=r;}return n}var gd=new WeakMap,dg=4096;function yd(t,e){if(e.effects.length!==1)return null;let n=e.effects[0];if(n.kind!=="spliceText"||n.deleteCount!==0||!cg(n.insert)||t.hasUnobservedWrites()||Ke(t.doc))return null;let o=t.inline.owner(n.logicalId);if(o===null)return null;let r=t.inline.textOf(o);if(!r||t.inline.sharesIds(o))return null;let i=t.inline.viewOf(o),s=i.shown(r);if(s.hidden.size>0||s.incoming.length>0)return null;let a=ti(r);if(a.leftOut)return null;let l=a.ops,d=0,c=-1,u=0,f=null,p=new Set,h=new Set;for(let x of l){let L=x.attributes??{};if(!ug(t,o,L))return null;let k=Ne(L,t.limits,o);if(typeof x.insert=="string"&&(!k.run||!k.text))return null;let y=new Set;for(let E of [k.run?.id,k.runProperties?.id,k.text?.id,k.textValueId,...k.wrap.map(P=>P.id)])if(E){if(p.has(E)&&!h.has(E))return null;y.add(E),p.add(E);}h=y;let v=typeof x.insert=="string"?x.insert.length:1;if(typeof x.insert=="string"&&k.textValueId!==null&&i.shownId(k.textValueId)===n.logicalId){if(c<0)c=d;else if(c+u!==d)return null;if(f&&ve(f)!==ve(L))return null;f??=L,u+=v;}d+=v;}if(!f||!Number.isSafeInteger(n.utf16Start)||n.utf16Start<0||n.utf16Start>u||u+n.insert.length>t.limits.maxTextLength)return null;let g=c+n.utf16Start,m=g>0?md(l,g-1):null,w=g<d?md(l,g):null,I=n.insert[0],b=n.insert[n.insert.length-1];return w&&w.key===`c${I}`||m&&m.key===`c${b}`&&m.element!==(f.t??"")||m?.highSurrogate||m?.revisions&&m.element!==(f.t??"")?null:{paragraphId:o,text:r,length:r.length,position:g,value:n.insert,attributes:Tt(f),identities:s.identities}}function bd(t,e){if(e.text.length!==e.length)return false;let n=Pi(e.identities,e.position);return n?Di(e.text,e.position,e.value,e.attributes,n):Ai(e.text,e.position,e.value,e.attributes,e.identities,o=>t.inline.follow.shownCopy(o)!==null),t.inline.follow.invalidate(e.paragraphId),true}function cg(t){if(t.length===0)return false;for(let e=0;e<t.length;e+=1){let n=t.charCodeAt(e);if(n<32||n>=55296&&n<=57343)return false}return true}function ug(t,e,n){let o=ve(n),r=JSON.stringify([e,o]),i=gd.get(t.limits);i||gd.set(t.limits,i=new Map);let s=i.get(r);if(s!==void 0)return s;let a;try{let l=Ne(n,t.limits,e);a=ve(Ct(l,e,t.limits))===o;}catch(l){if(!(l instanceof Be))throw l;a=false;}return i.size>=dg&&i.clear(),i.set(r,a),a}function md(t,e){let n=0;for(let o of t){let r=typeof o.insert=="string"?o.insert.length:1;if(e<n+r){let i=ao(o.attributes??{});if(typeof o.insert!="string")return {key:"embed",element:"",highSurrogate:false,revisions:i};let s=o.insert.charCodeAt(e-n);return {key:`c${o.insert[e-n]}`,element:o.attributes?.t??"",highSurrogate:s>=55296&&s<=56319,revisions:i}}n+=r;}return null}function _i(t,e){let n=[],o=[{id:e,depth:0}],r=new Set,i=0;for(;o.length>0;){let{id:s,depth:a}=o.pop();if(r.has(s)||a>t.limits.maxTreeDepth)return null;r.add(s);let l=t.record(s);if(!l)return null;if(kt(l)){let d=t.projectedTextValue(s)??l.value;if(i+=d.length,i>t.limits.maxTextLength)return null;n.push({id:s,value:d});}else if($(l)&&!l.kind.endsWith("Properties"))for(let d=l.childIds.length-1;d>=0;d-=1)o.push({id:l.childIds[d],depth:a+1});}return n}function sn(t,e,n){let o=_i(t,e),r=[];if(!o||o.length===0)return false;for(let l of n){let d=_i(t,l);if(!d)return false;for(let c of d)r.push(c);}if(o.map(l=>l.value).join("")!==r.map(l=>l.value).join(""))return false;let i=[],s=0,a=0;for(let l of r){for(;s<o.length-1&&a===o[s].value.length;)s+=1,a=0;let d=o[s];if(!d||a+l.value.length>d.value.length)return false;l.id!==d.id&&i.push({product:l.id,source:d.id,start:a,end:a+l.value.length}),a+=l.value.length;}for(let l of i)t.registerSplitText(l.product,l.source,l.start,l.end);return true}function Lo(t,e,n){return t!=="run"&&t!=="text"?null:e.filter(o=>n(o)===t)}function Id(t,e,n,o){for(let{removedId:r,runs:i}of e){let s=n.filter(a=>!i.includes(a));for(let a=1;a<=Math.min(s.length,fg);a+=1){let l=s.slice(0,a);if(sn(t,r,[...i,...l])){o(r,l);break}}}}var fg=8;function Bi(t,e){return (_i(t,e)??[]).some(n=>t.splitTextPending(n.id))}var At=class{constructor(e){this.registry=e;}registry;touched=new Map;created=new Set;has(e){return this.created.has(e)||this.touched.has(e)||this.registry.hasNode(e)}node(e){let n=this.touched.get(e);if(n)return n;let o=this.registry.nodeShape(e);return o?(this.touched.set(e,o),o):null}putNode(e){this.node(e.logicalId)||(this.created.add(e.logicalId),this.touched.set(e.logicalId,{isText:e.kind==="textValue",textLength:0,children:[]}));}spliceText(e,n,o){let r=this.node(e);r&&(r.textLength=Math.max(0,r.textLength-n)+o);}spliceChildren(e,n,o,r){let i=this.node(e);i&&i.children.splice(n,o,...r);}moveNode(e,n,o){for(let s of this.listersOf(e)){let a=this.node(s);if(a)for(let l=a.children.length-1;l>=0;l-=1)a.children[l]===e&&a.children.splice(l,1);}let r=this.node(n);if(!r)return;let i=Math.min(o,r.children.length);r.children.splice(i,0,e);}listersOf(e){let n=new Set(this.registry.listingParents(e)),o=this.registry.parentOf(e);o!==null&&n.add(o);for(let[r,i]of this.touched)i.children.includes(e)&&n.add(r);return n}};function Nn(t,e){switch(e.kind){case "putNode":t.putNode(e.descriptor);return;case "spliceText":t.spliceText(e.logicalId,e.deleteCount,e.insert.length);return;case "spliceChildren":t.spliceChildren(e.parentLogicalId,e.start,e.deleteCount,e.childLogicalIds);return;case "moveNode":t.moveNode(e.logicalId,e.destinationParentLogicalId,e.destinationIndex);return;default:return}}function ft(t,e){return O(e)||e.length===0?{ok:false,code:"prototype-key",detail:e}:t.has(e)?null:{ok:false,code:"unknown-logical-id",detail:e}}function pg(t,e,n){if(O(e.logicalId)||e.logicalId.length===0)return {ok:false,code:"invalid-logical-id",detail:e.logicalId};let o=n.node(e.logicalId);return o&&o.isText!==(e.kind==="textValue")?{ok:false,code:"invalid-bound",detail:`node class ${e.logicalId}`}:e.kind==="textValue"?null:O(e.qname.localName)?{ok:false,code:"prototype-key",detail:e.qname.localName}:Re(e.qname.namespaceUri,t.limits.maxStringLength)?{ok:false,code:"invalid-string"}:null}function Ro(t,e,n){switch(e.kind){case "putNode":return pg(t,e.descriptor,n);case "spliceText":{let o=ft(n,e.logicalId);if(o)return o;if(!Number.isSafeInteger(e.utf16Start)||!Number.isSafeInteger(e.deleteCount)||e.utf16Start<0||e.deleteCount<0)return {ok:false,code:"invalid-bound"};if(e.insert.length>t.limits.maxTextLength)return {ok:false,code:"text-too-long"};let r=n.node(e.logicalId);if(r&&r.isText){if(e.utf16Start+e.deleteCount>r.textLength)return {ok:false,code:"invalid-bound",detail:e.logicalId};if(r.textLength-e.deleteCount+e.insert.length>t.limits.maxTextLength)return {ok:false,code:"text-too-long"}}else if(r)return {ok:false,code:"invalid-bound",detail:e.logicalId};return null}case "setAttribute":{let o=ft(n,e.logicalId);return o||(O(e.qname.localName)?{ok:false,code:"prototype-key",detail:e.qname.localName}:Re(e.qname.namespaceUri,t.limits.maxStringLength)?{ok:false,code:"invalid-string"}:e.value!==null&&e.value.length>t.limits.maxStringLength?{ok:false,code:"invalid-string"}:null)}case "setNamespaceBinding":{let o=ft(n,e.logicalId);return o||(O(e.prefix)?{ok:false,code:"prototype-key"}:e.uri!==null&&Re(e.uri,t.limits.maxStringLength)?{ok:false,code:"invalid-string"}:null)}case "spliceChildren":{let o=ft(n,e.parentLogicalId);if(o)return o;if(!Number.isSafeInteger(e.start)||!Number.isSafeInteger(e.deleteCount)||e.start<0||e.deleteCount<0)return {ok:false,code:"invalid-bound"};if(e.childLogicalIds.length>t.limits.maxChildren)return {ok:false,code:"too-many-children"};for(let i of e.childLogicalIds){let s=ft(n,i);if(s)return s}let r=n.node(e.parentLogicalId);if(r&&!r.isText){if(e.start+e.deleteCount>r.children.length&&!vd(t,e,r.children.length))return {ok:false,code:"invalid-bound",detail:e.parentLogicalId};if(r.children.length-e.deleteCount+e.childLogicalIds.length>t.limits.maxChildren)return {ok:false,code:"too-many-children"}}else if(r)return {ok:false,code:"invalid-bound",detail:e.parentLogicalId};return null}case "moveNode":{let o=ft(n,e.logicalId);if(o)return o;let r=ft(n,e.destinationParentLogicalId);return r||(!Number.isSafeInteger(e.destinationIndex)||e.destinationIndex<0?{ok:false,code:"invalid-bound"}:null)}case "putXmlPart":{let o=Ie(e.name);if(o)return {ok:false,code:o,detail:e.name};let r=ft(n,e.rootLogicalId);return r||(t.partCount()>=t.limits.maxParts?{ok:false,code:"too-many-parts"}:null)}case "deleteXmlPart":{let o=Ie(e.name);return o?{ok:false,code:o,detail:e.name}:null}case "putRelationship":{if(e.record.ownerPart!=="/"){let o=Ie(e.owner);if(o)return {ok:false,code:o}}return O(e.record.id)?{ok:false,code:"prototype-key"}:t.relationshipCount()>=t.limits.maxRelationships?{ok:false,code:"too-many-relationships"}:null}case "deleteRelationship":return O(e.relationshipId)?{ok:false,code:"prototype-key"}:null;case "putContentTypeOverride":{let o=Ie(e.partName);return o?{ok:false,code:o}:Re(e.mediaType,t.limits.maxMediaTypeLength)?{ok:false,code:"invalid-string"}:null}case "deleteContentTypeOverride":{let o=Ie(e.partName);return o?{ok:false,code:o}:null}case "putBinary":{let o=Fs(e.descriptor);return o?{ok:false,code:o}:null}case "deleteBinary":return O(e.storageKey)?{ok:false,code:"prototype-key"}:null;default:return {ok:false,code:"invalid-bound"}}}function hg(t){let e=[];for(let n=0;n<t.length;n+=1){let o=t[n],r=t[n+1];if(o.kind==="spliceText"&&o.deleteCount>0&&o.insert.length===0&&r?.kind==="spliceText"&&r.logicalId===o.logicalId&&r.utf16Start===o.utf16Start&&r.deleteCount===0&&!yt(o)&&!yt(r)){e.push({...o,insert:r.insert}),n+=1;continue}e.push(o);}return e}function gg(t,e,n){switch(e.kind){case "putNode":e.descriptor.kind==="textValue"?t.hasNode(e.descriptor.logicalId)||t.putText(e.descriptor.logicalId,""):t.hasNode(e.descriptor.logicalId)?t.updateElementShell(e.descriptor.logicalId,{kind:e.descriptor.kind,namespaceUri:e.descriptor.qname.namespaceUri,localName:e.descriptor.qname.localName,prefix:e.descriptor.qname.prefix}):(t.putElement({logicalId:e.descriptor.logicalId,kind:e.descriptor.kind,namespaceUri:e.descriptor.qname.namespaceUri,localName:e.descriptor.qname.localName,prefix:e.descriptor.qname.prefix,attributes:[],bindings:[]}),e.descriptor.kind==="paragraph"&&Gl(t.schema.nodes.get(e.descriptor.logicalId)));return;case "spliceText":if(n.has(e.logicalId)&&e.utf16Start===0&&e.deleteCount===0&&t.textOf(e.logicalId).toString()===e.insert)return;let o=yt(e);t.spliceText(o?.logicalId??e.logicalId,o?.utf16Start??e.utf16Start,e.deleteCount,e.insert);return;case "setAttribute":t.setAttribute(e.logicalId,e.qname,e.value);return;case "setNamespaceBinding":t.setNamespaceBinding(e.logicalId,e.prefix,e.uri);return;case "spliceChildren":{let r=t.record(e.parentLogicalId),i=r&&"childIds"in r?r.childIds.length:e.start,s=ie(t.schema.nodes.get(e.parentLogicalId)),a=d=>t.splitSiblings.ranksOf(e.parentLogicalId)?.has(d)??false;Zl(d=>t.schema.nodes.get(d),s,e.start,e.deleteCount,a);let l=z.getState(t.doc.store,t.doc.clientID);t.spliceChildren(e.parentLogicalId,vd(t,e,i)?i:e.start,e.deleteCount,e.childLogicalIds),Ql(d=>t.schema.nodes.get(d),d=>{let c=t.inline.textOf(d);return Jl(c,c?t.inline.viewOf(d).shown(c):null)},s,e.childLogicalIds,[...it(t.doc,l)].filter(d=>d.parent===s),a);return}case "moveNode":t.moveNode(e.logicalId,e.destinationParentLogicalId,e.destinationIndex);return;case "putXmlPart":t.putXmlPart({name:e.name,id:e.name,rootLogicalId:e.rootLogicalId,contentType:"application/xml"});return;case "deleteXmlPart":t.deleteXmlPart(e.name);return;case "putRelationship":t.putRelationship({...e.record,ownerPart:e.owner});return;case "deleteRelationship":t.deleteRelationship(e.owner,e.relationshipId);return;case "putContentTypeOverride":t.putContentTypeOverride(e.partName,e.mediaType);return;case "deleteContentTypeOverride":t.deleteContentTypeOverride(e.partName);return;case "putBinary":t.putBinary(e.descriptor);return;case "deleteBinary":t.deleteBinary(e.storageKey);return}}function mg(t,e){let n=t.kindOf(e);return n!==null&&!n.endsWith("Properties")}function yg(t,e,n,o){let r=new Set((n.get(e)??[]).filter(i=>mg(t,i)));if(r.size!==0){for(let i of o)if(!(i.kind!=="spliceChildren"||i.parentLogicalId===e)&&i.childLogicalIds.some(s=>r.has(s)))return i.parentLogicalId}}function bg(t,e){let n=new At(t),o=[],r=new Set,i=new Set,s=new Set,a=new Set,l=new Map;for(let d of e){let c=Ro(t,d,n);if(c)return c;if(d.kind==="spliceChildren"){let u=d.deleteCount>0?n.node(d.parentLogicalId):null;if(u&&!u.isText){let f=d.start+d.deleteCount;for(let p=d.start;p<f;p+=1){let h=u.children[p];if(h!==void 0&&(o.push(h),i.add(h),d.childLogicalIds.length>0)){let g=l.get(d)??[];g.push(h),l.set(d,g);}}}for(let f of d.childLogicalIds)r.add(f),i.delete(f);}else d.kind==="moveNode"?(r.add(d.logicalId),i.delete(d.logicalId)):d.kind==="putNode"&&(a.add(d.descriptor.logicalId),d.descriptor.kind==="textValue"&&s.add(d.descriptor.logicalId));Nn(n,d);}return {removed:o,reinserted:r,unlistedAtEnd:i,mintedText:s,mintedNodes:a,replacementsByEffect:l}}function Ig(t){let e=0;for(let n of t)n.kind==="putNode"&&(e+=1);return e}function Ui(t,e,n,o){if(o){let c=false;return t.doc.transact(()=>{t.noteWrite(),c=bd(t,o);},vr),c?{ok:true}:{ok:false,code:"invalid-bound",detail:"typed text changed",transient:true}}let r=n,i=e;if(r===void 0){let c=mo(t,e.effects);if(c.refusal)return {ok:false,...c.refusal};r=c.plan,r&&(i={...e,effects:c.passThrough});}let s=i.effects.map(Jt);if(t.nodeCount()+Ig(s)>t.limits.maxNodes)return {ok:false,code:"too-many-nodes"};let a=bg(t,s);if("ok"in a)return a;for(let c of a.replacementsByEffect.values())for(let u of c)if(t.kindOf(u)==="run"&&Bi(t,u))return {ok:false,code:"invalid-bound",detail:`split of pending text in ${u}`,transient:true};let l=r?.paragraphs.find(({id:c})=>t.inline.textOf(c)===null&&wd(t,c));if(l)return {ok:false,code:"invalid-bound",detail:`pending text of paragraph ${l.id}`,transient:true};let d;try{d=new Map(r?.paragraphs.map(({id:c,after:u})=>[c,Io(u,t.limits)]));}catch(c){if(!(c instanceof Be))throw c;return {ok:false,code:c.code,detail:c.detail}}try{xg(t,s,a,r,d);}finally{ql();}return {ok:true}}function xg(t,e,n,o,r){t.doc.transact(()=>{t.noteWrite();let i=Lg(t,n.removed),s=[],a=[];for(let u of hg(e))if(gg(t,u,n.mintedText),u.kind==="spliceChildren"){if(n.mintedNodes.has(u.parentLogicalId))for(let f of u.childLogicalIds)n.mintedNodes.has(f)&&t.kindOf(f)==="run"&&a.push(f);if(t.kindOf(u.parentLogicalId)==="comment"){let f=(n.replacementsByEffect.get(u)??[]).filter(g=>t.kindOf(g)==="paragraph"),p=u.childLogicalIds.filter(g=>t.kindOf(g)==="paragraph"),h=f[f.length-1];h&&p.length>0&&t.recordRunSplit(h,h,p);}vg(t,n,n.replacementsByEffect.get(u)??[],u.childLogicalIds,s);}Id(t,s,a,(u,f)=>{t.recordRunSplit(kd(t,u,n.reinserted),u,f);}),kg(t,e,n,i);let l=cd(t,n.removed),d=yl(t,n,i),c=o?hd(t,o,r,new Set(n.removed)):{copied:new Set,deleted:new Set,embedded:new Set};ml(t,n.removed,c.embedded,n.mintedNodes,o?.paragraphs.map(({after:u})=>u)??[]),pd(t,l.held,c.copied),fd(t,c,new Map([...l.shown,...d])),ud(t,l.embeds,n.removed,c);},vr);}function Sg(t,e){let n=t.inline.textOf(e);if(n===null&&wd(t,e)||n!==null&&wg(t,e,n))return true;let o=t.record(e);return (o&&"childIds"in o?o.childIds:[]).some(i=>t.kindOf(i)==="run"&&Bi(t,i))}function Sd(t,e){let n=t.kindOf(e)==="paragraph"?e:t.inline.owner(e)??t.parentOf(e);return n!==null&&Sg(t,n)}function wg(t,e,n){return $t(t.doc)?t.inline.viewOf(e).shown(n).incoming.some(o=>ta(t.doc,o.source)):false}function wd(t,e){let n=t.schema.nodes.get(e);return _(n)&&ea(n,ae)}function kg(t,e,n,o){if(n.removed.length===0)return;let r=new Set;for(let i of t.partEntries())r.add(i.rootLogicalId);for(let i of n.removed){if(n.reinserted.has(i)&&!n.unlistedAtEnd.has(i)||!t.hasNode(i)||t.isTombstoned(i)||r.has(i))continue;let s=yg(t,i,o,e);s&&t.unlistChildren(i,o.get(i)??[]),t.tombstone(i,s);}}function vg(t,e,n,o,r){for(let i of n){let s=t.kindOf(i);if(s!=="run"&&s!=="text"||e.reinserted.has(i)&&!e.mintedNodes.has(i))continue;let a=kd(t,i,e.reinserted);if(s==="text"){let d=Lo(s,o,c=>t.kindOf(c));if(d&&sn(t,i,d)){let c=o.filter(u=>e.mintedNodes.has(u));t.recordRunSplit(a,i,c);}continue}let l=o.filter(d=>t.kindOf(d)==="run");sn(t,i,l)||r.push({removedId:i,runs:l}),t.recordRunSplit(a,i,l);}}function kd(t,e,n){let o=e;for(let r=0;r<t.limits.maxTreeDepth&&n.has(o);r+=1){let i=t.splitOriginOf(o);if(i===null||i===o)break;o=i;}return o}function Lg(t,e){let n=new Map;for(let o of e){let r=t.nodeShape(o);r&&!r.isText&&n.set(o,r.children);}return n}function vd(t,e,n){return e.deleteCount===0&&e.start>n&&t.partEntries().some(o=>o.rootLogicalId===e.parentLogicalId)}var Ce="splitTextSource",Rg=Object.freeze({kind:"docx-package-restored-split-anchors"});function Ee(t,e){throw new N(t,e)}function Fi(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function Ld(t){return Fi(t)&&Object.keys(t).every(e=>e==="client"||e==="clock")&&Number.isSafeInteger(t.client)&&t.client>=0&&Number.isSafeInteger(t.clock)&&t.clock>=0}function Rd(t){return !Fi(t)||!Object.keys(t).every(e=>["type","item","assoc"].includes(e))||!Ld(t.type)||t.item!==void 0&&!Ld(t.item)||t.assoc!==0&&t.assoc!==-1?Ee("invalid-string",Ce):z.createRelativePositionFromJSON(t)}var Dt=class extends Error{},an=class{constructor(e,n,o){this.nodes=e;this.doc=n;this.limits=o;}nodes;doc;limits;sourceByAlias=new Map;aliasesBySource=new Map;pending=new Set;values=new Map;awaiting=new Set;lastEncoded=new Map;held=new Set;isPlain(e){return !this.sourceByAlias.has(e)&&!this.aliasesBySource.has(e)}register(e,n,o,r){let i=this.nodes.get(e);(!_(i)||!(i.get(Pe)instanceof z.Text))&&Ee("invalid-bound",e);let s=this.read(n),a=s===null?{sourceId:n,text:this.sourceText(n),start:0,end:this.sourceText(n).length}:this.resolve(s);(a.sourceId.length===0||a.sourceId.length>this.limits.maxStringLength||O(a.sourceId))&&Ee("invalid-string",n),(!Number.isSafeInteger(o)||!Number.isSafeInteger(r)||o<0||r<o||r>a.end-a.start||e===a.sourceId)&&Ee("invalid-bound",e);let l=(c,u)=>{if(s&&u==="end"&&c===a.end-a.start)return s.end;if(s&&c===0)return s.start;if(s&&c===a.end-a.start)return s.end;let f=a.start+c;return z.createRelativePositionFromTypeIndex(a.text,f,f===0&&u==="start"?-1:0)},d=JSON.stringify({sourceId:a.sourceId,start:z.relativePositionToJSON(l(o,"start")),end:z.relativePositionToJSON(l(r,"end"))});d.length>this.limits.maxStringLength&&Ee("invalid-string",e),i.set(Ce,d),this.indexExisting(e);}normalizeRestoredAnchors(){let e=new Map,n=r=>{let i=r.item;if(i===null)return r;let s=`${i.client}:${i.clock}:${r.assoc}`,a=e.get(s);if(a)return a;let l=f=>z.getState(this.doc.store,f.client)>f.clock?z.getItem(this.doc.store,f):null,d=i,c=l(d);for(;c instanceof z.Item&&c.redone!==null;)d=z.createID(c.redone.client,c.redone.clock+d.clock-c.id.clock),c=l(d);let u=c instanceof z.Item&&!c.deleted&&!z.compareIDs(i,d)?z.createRelativePositionFromJSON({...z.relativePositionToJSON(r),item:{client:d.client,clock:d.clock}}):r;return e.set(s,u),u},o=[];for(let r of this.sourceByAlias.keys()){let i=this.nodes.get(r);if(_(i)&&Cr(i,Ce))continue;let s=this.read(r);if(!s)continue;let a=n(s.start),l=n(s.end);if(z.compareRelativePositions(a,s.start)&&z.compareRelativePositions(l,s.end))continue;let d=JSON.stringify({sourceId:s.sourceId,start:z.relativePositionToJSON(a),end:z.relativePositionToJSON(l)});d.length>this.limits.maxStringLength&&Ee("invalid-string",r),o.push({id:r,encoded:d});}o.length!==0&&this.doc.transact(()=>{for(let{id:r,encoded:i}of o)this.nodes.get(r).set(Ce,i),this.indexExisting(r);},Rg);}sourceAliases(e){return [...this.aliasesBySource.get(e)??[]]}range(e){try{return this.resolveRange(e)}catch(n){if(n instanceof Dt)return null;throw n}}isPending(e){try{return this.resolveRange(e),!1}catch(n){if(n instanceof Dt)return true;throw n}}resolveRange(e){let n=this.read(e);return n===null?null:this.resolve(n)}value(e){let n=this.range(e);return n===null?null:n.text.toString().slice(n.start,n.end)}indexExisting(e){let n=null,o=false;try{n=this.read(e),n&&this.resolve(n);}catch{o=true;}let r=this.sourceByAlias.get(e);if(r!==void 0&&r!==n?.sourceId){let i=this.aliasesBySource.get(r);i?.delete(e),i?.size===0&&this.aliasesBySource.delete(r),this.sourceByAlias.delete(e);}if(n){this.sourceByAlias.set(e,n.sourceId);let i=this.aliasesBySource.get(n.sourceId)??new Set;i.add(e),this.aliasesBySource.set(n.sourceId,i);}(o||n||r!==void 0||this.values.has(e))&&this.pending.add(e);}noteChanged(e){this.indexExisting(e);for(let n of this.aliasesBySource.get(e)??[])this.pending.add(n);}reset(){this.sourceByAlias.clear(),this.aliasesBySource.clear();for(let e of this.values.keys())this.pending.add(e);this.nodes.forEach((e,n)=>this.indexExisting(n));}overlays(){let e=new Set,n=new Map;if(this.held.size>0&&!$t(this.doc)){for(let o of this.held)this.indexExisting(o);this.held.clear();}for(let o of this.pending){let r=null;try{r=this.resolveRange(o),this.awaiting.delete(o)&&e.add(o);}catch(s){if(!(s instanceof Dt))throw s;this.awaiting.has(o)||e.add(o),this.awaiting.add(o);}let i=null;if(r){let s=n.get(r.sourceId);s===void 0&&(s=r.text.toString(),n.set(r.sourceId,s)),i=s.slice(r.start,r.end);}i===null?this.values.delete(o)&&e.add(o):i!==this.values.get(o)&&(this.values.set(o,i),e.add(o));}return this.pending.clear(),{values:this.values,changedIds:e,awaiting:this.awaiting}}sourceText(e){let n=this.nodes.get(e),o=_(n)?n.get(Pe):null;return !(o instanceof z.Text)||o.doc!==this.doc||o.length>this.limits.maxTextLength?Ee("invalid-bound",e):o}read(e){let n=this.nodes.get(e);if(!_(n))return null;let o;if(Cr(n,Ce)){if(o=this.lastEncoded.get(e),o===void 0)throw new Dt(e);this.held.add(e);}else {if(!n.has(Ce))return null;o=n.get(Ce);}if(typeof o!="string"||o.length>this.limits.maxStringLength)return Ee("invalid-string",e);let r;try{r=JSON.parse(o);}catch{return Ee("invalid-string",e)}if(!Fi(r)||!Object.keys(r).every(s=>["sourceId","start","end"].includes(s))||typeof r.sourceId!="string"||r.sourceId.length===0||r.sourceId.length>this.limits.maxStringLength||O(r.sourceId)||r.sourceId===e)return Ee("invalid-string",e);if(!(n.get(Pe)instanceof z.Text))return Ee("invalid-bound",e);let i={sourceId:r.sourceId,start:Rd(r.start),end:Rd(r.end)};return this.lastEncoded.set(e,o),i}resolve(e){if(!this.nodes.has(e.sourceId)||[e.start,e.end].some(d=>d.item!==null&&z.getState(this.doc.store,d.item.client)<=d.item.clock))throw new Dt(e.sourceId);let n=this.nodes.get(e.sourceId);if(_(n)&&n.has(Ce))return Ee("invalid-bound",e.sourceId);let o=this.sourceText(e.sourceId),r=z.createRelativePositionFromTypeIndex(o,0).type;if(!r||[e.start,e.end].some(d=>d.type?.client!==r.client||d.type?.clock!==r.clock))return Ee("invalid-bound",e.sourceId);let i=z.createAbsolutePositionFromRelativePosition(e.start,this.doc,false),s=z.createAbsolutePositionFromRelativePosition(e.end,this.doc,false),a=e.start.item!==null&&z.getItem(this.doc.store,e.start.item).deleted,l=e.end.item!==null&&z.getItem(this.doc.store,e.end.item).deleted;return i===null||s===null||i.type!==o||s.type!==o||i.index<0||s.index>o.length?Ee("invalid-bound",e.sourceId):{sourceId:e.sourceId,text:o,start:i.index,end:Math.max(i.index,s.index),startAssoc:e.start.assoc,endAssoc:e.end.assoc,startAnchorDeleted:a,endAnchorDeleted:l}}};function Oo(t,e,n,o,r,i){if(!o||i.length===0)return null;let s=r===0&&o.startAssoc!==-1,a=r===o.end-o.start;if(!s&&!a)return null;let l=t.get(n)?.get(Ce);if(typeof l!="string")return null;let d=JSON.parse(l),c=z.createRelativePositionFromJSON(d.start),u=z.createRelativePositionFromJSON(d.end);if(a=a&&(s||u.item!==null&&z.getItem(o.text.doc.store,u.item).deleted),!s&&!a)return null;let f=[],p=o.text.doc.store,h=g=>{if(g.item===null||!z.getItem(p,g.item).deleted)return false;let m=z.createAbsolutePositionFromRelativePosition(g,o.text.doc,false);return m!==null&&m.type===o.text&&m.index===o.end};for(let g of e.sourceAliases(o.sourceId)){if(!e.range(g))continue;let m=t.get(g),w=m.get(Ce);if(typeof w!="string")continue;let I=JSON.parse(w),b=(k,y)=>{let v=z.createRelativePositionFromJSON(k);return s&&a&&z.compareRelativePositions(c,u)&&z.compareRelativePositions(v,c)?y==="start"?"after":"before":s&&z.compareRelativePositions(v,c)?"before":a&&z.compareRelativePositions(v,u)||a&&!s&&!(g===n&&y==="start")&&h(v)?"after":null},x=g===n&&s?"before":b(I.start,"start"),L=g===n&&a?"after":b(I.end,"end");(x||L)&&f.push({record:m,start:x,end:L});}return ()=>{let g=o.start+r,m=z.relativePositionToJSON(z.createRelativePositionFromTypeIndex(o.text,g,g===0&&o.startAssoc===-1?-1:0)),w=z.relativePositionToJSON(z.createRelativePositionFromTypeIndex(o.text,g+i.length,0));for(let I of f){let b=JSON.parse(I.record.get(Ce));I.start&&(b.start=I.start==="before"?m:w),I.end&&(b.end=I.end==="before"?m:w);let x=JSON.stringify(b);x!==I.record.get(Ce)&&I.record.set(Ce,x);}}}var Eo=class{constructor(e){this.nodes=e;}nodes;cachedLosers=null;invalidate(){this.cachedLosers=null;}runsBySplitOrigin=new Map;liveRootedOrigins=new Set;reset(){this.invalidate(),this.runsBySplitOrigin.clear(),this.liveRootedOrigins.clear();}record(e,n,o){this.invalidate();for(let r of o){if(r===e)continue;let i=this.nodes.get(r);_(i)&&(i.set(yn,e),i.set(wt,e),this.indexExisting(r));}}indexExisting(e){let n=this.nodes.get(e),o=Et(n);if(o===null||o===e||pi(n))return;this.invalidate();let r=this.runsBySplitOrigin.get(o)??new Set;r.add(e),this.runsBySplitOrigin.set(o,r),this.liveRootedOrigins.add(o);}productsOf(e){return [...this.runsBySplitOrigin.get(e)??[]].filter(n=>Et(this.nodes.get(n))===e)}loserRuns(e){if(this.cachedLosers)return this.cachedLosers;let n=new Set,o=new Set,r=i=>{let s=[i];for(;s.length>0;){let a=s.pop();if(!o.has(a)){o.add(a),e.isPresent(a)&&n.add(a);for(let l of this.productsOf(a))s.push(l);}}};for(let i of this.liveRootedOrigins){let s=this.productsOf(i),a=e.isPresent(i)?null:s.filter(l=>In(this.nodes.get(l))===i).map(l=>Ve(l)??"").sort()[0];for(let l of s)(Ve(l)??"")!==a&&r(l);}return this.cachedLosers=n,n}};function Co(t,e,n){let o=new Map;for(let a=0;a<t.length;a+=1){let l=t[a],d=n(l);if(d===null||d===l)continue;let c=o.get(d)??{loser:[],winner:[]};(e(l)?c.loser:c.winner).push(a),o.set(d,c);}let r=new Map;for(let{loser:a,winner:l}of o.values())a.length!==1||l.length!==1||a[0]>l[0]||r.set(l[0],a[0]);if(r.size===0)return null;let i=new Map;for(let[a,l]of r)i.set(l,a);let s=[];for(let a=0;a<t.length;a+=1){let l=i.get(a);l!==void 0&&s.push(l),r.has(a)||s.push(a);}return s}var Od=4096;function Td(t){let e=dt(t),n=[],o=0;for(let r=be(t);r&&o<Od;r=r.right)for(let i=0;i<r.length&&o<Od;i+=1)o+=1,e.origin("move",r.id.client,r.id.clock+i)&&n.push(ot(t,r,i));return n}function Og(t,e){let n=e[0];return n===void 0||t.length===0?false:t.indexOf(n)>0&&e.indexOf(t[0])<=0}function Nt(t,e){return t!==null&&t.client===e.id.client&&t.clock>=e.id.clock&&t.clock<e.id.clock+e.length}var Ed=t=>t?`${t.client}:${t.clock}`:"-",ji=t=>`${Ed(t.origin)} ${Ed(t.rightOrigin)}`;function Eg(t,e,n=[],o=()=>[],r=[],i=[]){let s=null,a=0,l=[],d=t.doc?.getMap(mn)??null,c=new Map,u=new Map;for(let g=be(t);g;g=g.right){if(!g.deleted)for(let w of g.content.getContent())u.has(w)||u.set(w,l.length);l.push(g);let m=ji(g);c.set(m,(c.get(m)??0)+1);}let f=g=>g.deleted||zi(d,g),p=new Map,h=g=>{let m=p.get(g);if(!m){let w=e(g);m=new Set(w?Td(w):[]),p.set(g,m);}return m};for(let g=0;g<l.length;){let m=l[g],w=ji(m);if(c.get(w)<2||!f(m)){g+=1;continue}let I=[{head:m,items:[m]}],b=g+1;for(;b<l.length;b+=1){let D=l[b],T=I.at(-1);if(ji(D)===w&&f(D))I.push({head:D,items:[D]});else if(T.items.some(S=>Nt(D.origin,S)))T.items.push(D);else break}if(I.length<2){g+=1;continue}let x=g,L=0,k=I.flatMap(D=>D.items),y=[];for(let D=g;D>1;){let T=l[D-1],S=k.find(C=>C.deleted&&Nt(T.rightOrigin,C));if(!S){if(!(!T.deleted&&y.some(M=>Nt(T.rightOrigin,M))&&!(T.origin&&m.origin&&z.compareIDs(T.origin,m.origin))))break;D-=1,y.unshift(T);continue}if(D-=1,T.deleted){k.push(T);continue}if(!T.origin||!m.origin||!z.compareIDs(T.origin,m.origin)){y.unshift(T);continue}if(!Cd(d,T,S))break;let R={head:T,items:[T]};for(let C of y)R.items.some(M=>Nt(C.origin,M))&&R.items.push(C);if(R.items.length!==y.length+1)break;y=[],I.unshift(R),L+=1,x=D;}for(let D of I)for(let T of D.items)if(!T.deleted)for(let S of T.content.getContent())n.push(S);let v=D=>D.flatMap(T=>T.items.filter(S=>!S.deleted).flatMap(S=>S.content.getContent())),E=v(I),P=new Set(I.slice(0,L).map(D=>D.head)),j=I.flatMap(D=>D.items.filter(T=>!T.deleted).flatMap(T=>T.content.getContent().map((S,R)=>R===0&&P.has(T)||Tg(d,S,T,R)))),K=[];for(let D of I)for(let T of D.items){if(T.deleted)continue;let S=T.content.getContent().length;for(let R=0;R<S;R+=1){let C=R>0?{client:T.id.client,clock:T.id.clock+R-1}:T.origin;K.push(C?`${C.client}:${C.clock}`:null);}}let Y=I.flatMap(D=>D.items.filter(T=>!T.deleted).flatMap(T=>T.content.getContent().map((S,R)=>R===0&&!P.has(T)&&k.some(C=>Nt(T.rightOrigin,C)&&!(C.deleted&&Cd(d,T,C)))))),V=I.flatMap((D,T)=>v([D]).map(()=>T)),q=Yg(I,e,t.doc,o,i,D=>P.has(D)||zi(d,D)),ne=new Set(E).size<E.length?null:Cg(E,j,Y,K,V,o,t.doc,i,h)??(q?v(q):null),A=ne??E,J=l[x-1];if(J&&!J.deleted&&Nt(m.origin,J)){let D=new Set(I.filter(R=>!R.head.deleted).map(R=>Yn(R.head))),T=J.content.getContent()[m.origin.clock-J.id.clock],S=new Map;for(let R of I){let C=T;for(let M of v([R]))S.set(M,C),C=M;}r.push({source:T,heads:A.filter(R=>D.has(R)),shown:A,before:S});}let he=ne!==null&&ne.some((D,T)=>E[T]!==D);he&&(a+=1,s??=new Map,ne.forEach((D,T)=>{(u.get(D)??x)>=x&&s.set(D,{group:a,rank:T});})),g=he?b:g+1;}return s}function Cg(t,e,n,o,r,i,s,a,l=()=>new Set){let d=[],c=[],u=b=>i(b).map(x=>`${x.source}@${x.at}`).join(`
|
|
13
|
-
`),f=b=>{if(!b||!s)return null;let[x,L]=b.split(":").map(Number),k=H(s,{client:x,clock:L});if(!k||k.deleted)return null;let y=k.content.getContent()[L-k.id.clock];return typeof y=="string"?u(y):null},p=b=>{if(!b||!s)return false;let[x,L]=b.split(":").map(Number);return H(s,{client:x,clock:L})?.deleted===true},h=new Map,g=new Set;for(let[b,x]of t.entries()){let L=u(x),k=L!==""&&f(o[b])===L,y=i(x).at(-1),v=y?.source,E=()=>{let V=y.at.replace(/\+$/,"");return t.every((q,ee)=>{if(q===x||q===v)return true;let ne=l(q);return !ne.has(V)&&(!e[ee]||ne.size>0)})},P=v!==void 0&&(g.has(v)||h.has(v)&&E()),j=b===0&&r[1]!==r[0],K=n[b]&&(j||r[b-1]===r[b]||!p(o[b]))?h.get(t[b-1]):e[b]&&!k&&!P?null:P?h.get(v):d.at(-1);if(K===void 0)return null;K&&g.add(x);let Y=K??[];K||(d.push(Y),c.push(r[b])),Y.push(x),h.set(x,Y);}if(d.length<2)return null;let m=d.map(b=>i(b[0])),w=new Map,I=b=>{let x=new Map;c.forEach((v,E)=>{x.has(v)||x.set(v,E);});let L=[...x.keys()].sort((v,E)=>b[x.get(v)]-b[x.get(E)]||v-E),k=new Map(L.map((v,E)=>[v,E])),y=d.map((v,E)=>E);return y.sort((v,E)=>b[v]-b[E]||k.get(c[v])-k.get(c[E])||v-E),y.flatMap(v=>d[v])};for(let b=m[0].length-1;b>=0;b-=1){let x=m[0][b].source,L=m.map(E=>Oi(E,x));if(L.some(E=>E===null))continue;let k=a.length,y=$i(s,m.map(E=>E.at(-1).at),w,a,false);if(y)return I(y);if(a.length>k)return null;let v=$i(s,L,w,a);return v?I(v):null}return null}function Cd(t,e,n){if(!t||e.deleted||!zi(t,e))return false;let o=_e(t,Yn(e));return o!==void 0&&o.id.client===n.id.client&&o.id.clock<n.id.clock}function zi(t,e){let n=t?.get(Yn(e));if(!(n instanceof z.Map))return false;let o=An(n);return o!==null&&Nt(o,e)}function Tg(t,e,n,o){let r=t?.get(e);if(!(r instanceof z.Map))return false;let i=An(r);return i!==null&&i.client===n.id.client&&i.clock===n.id.clock+o}function Yn(t){return t.content.getContent()[0]}function Md(t,e){let n=typeof t=="string"?e(t):null;return n?Td(n):[]}function Pd(t,e,n){let o=e?/^(\d+):(\d+)$/.exec(e):null;if(!o)return null;let r=Number(o[1]),i=Number(o[2]),s=H(t,{client:r,clock:i}),a=s?.parent;if(!s||!(a instanceof z.Text))return null;for(let c=a._item;c;c=c.parent instanceof z.AbstractType?c.parent._item:null)if(c.deleted)return null;let l=n.get(a);if(!l){l=new Map;let c=0;for(let u=be(a);u;u=u.right)l.set(`${u.id.client}:${u.id.clock}`,c),c+=u.length;n.set(a,l);}let d=l.get(`${s.id.client}:${s.id.clock}`);return d===void 0?null:{text:a,at:d+i-s.id.clock}}function Mg(t,e,n){for(let o of t.items){if(o.deleted)continue;if(!n(o))return [];let r=Md(Yn(o),e);if(r.length>0)return r}return []}function Pg(t,e,n,o){return n&&o&&n.text===o.text?n.at<o.at:Og(t,e)}function Ag(t,e,n){for(let o of t.items){if(o.deleted)continue;if(!n(o))return [];let r=e(Yn(o));if(r.length>0)return r}return []}function Ad(t,e){let[n,o]=e.split(":").map(Number);return o<z.getState(t.store,n)}function Dg(t,e,n,o,r){if(e===n)return null;let i=$i(t,[e,n],o,r);return i&&i[0]!==i[1]?i[0]<i[1]:null}function $i(t,e,n,o,r=true){if(!t)return null;let i=e.map(d=>({identity:d.endsWith("+")?d.slice(0,-1):d,after:d.endsWith("+")?.5:0})),s=i.map(({identity:d})=>d).filter(d=>!Ad(t,d));if(s.length>0)return o.push(...s),null;let a=i.map(({identity:d})=>Pd(t,d,n));if(a.every(d=>d&&d.text===a[0].text))return a.map((d,c)=>d.at+i[c].after);if(!r)return null;let l=i.map(({identity:d})=>d.split(":").map(Number));return l.every(([d])=>d===l[0][0])?l.map(([,d],c)=>d+i[c].after):null}function Ng(t,e,n,o,r){for(let i=e.length-1;i>=0;i-=1){let s=Oi(n,e[i].source);if(s!==null)return Dg(t,e[i].at,s,o,r)}return null}function Yg(t,e,n,o,r,i){let s=t.map(f=>Ag(f,o,i)),a=t.map(f=>Mg(f,e,i)),l=new Map,d=a.map(f=>n?Pd(n,f[0],l):null),c=t.map((f,p)=>p),u=false;for(let f=1;f<c.length;f+=1)for(let p=f;p>0;p-=1){let h=c[p],g=c[p-1];if(t[g].items.every(I=>I.deleted)){[c[p-1],c[p]]=[h,g];continue}if(!(Ng(n,s[h],s[g],l,r)??Pg(a[h],a[g],d[h],d[g])))break;[c[p-1],c[p]]=[h,g],u=true;}return u?c.map(f=>t[f]):null}var To=class{constructor(e,n,o){this.nodeOf=e;this.textOf=n;this.listingOf=o;}nodeOf;textOf;listingOf;built=new WeakMap;withRuns=new Set;grouped=new Set;recheck=new Map;readers=new Map;membersOf=new Map;ranksOf(e){return this.read(e)?.ranks??null}groupsOf(e){return this.read(e)?.groups??[]}parentsWithRuns(){for(let e of [...this.grouped])this.listingOf(e)||this.grouped.delete(e);return [...this.grouped]}shownChildren(e){return this.read(e)?.shown??this.listingOf(e)}takeChanged(){let e=[];for(let[n,o]of this.recheck){this.recheck.delete(n);let r=this.read(n)?.shown??this.listingOf(n);r&&(r.length!==o.length||r.some((i,s)=>o[s]!==i))&&e.push(n);}for(let n of [...this.withRuns]){let o=this.listingOf(n),r=o?this.built.get(o):void 0;if(!o||!r){this.withRuns.delete(n);continue}let i=this.nodeOf(n)?.doc??null,s=i!==null&&r.missing.some(d=>Ad(i,d)),a=r.waiting.length>0&&this.lengthsKey(r.waiting)!==r.lengths;if(!s&&!a)continue;let l=this.build(n,o);(!l||l.shown.some((d,c)=>r.shown[c]!==d))&&e.push(n);}return e}forget(e){let n=this.listingOf(e),o=n?this.built.get(n):void 0;!n||!o||(this.built.delete(n),this.recheck.has(e)||this.recheck.set(e,o.shown));}textChanged(e){for(let n of this.readers.get(e)??[])this.forget(n);}noteMembers(e,n){for(let o of this.membersOf.get(e)??[]){let r=this.readers.get(o);r?.delete(e),r?.size===0&&this.readers.delete(o);}if(n.length===0){this.membersOf.delete(e);return}this.membersOf.set(e,n);for(let o of n){let r=this.readers.get(o);r||this.readers.set(o,r=new Set),r.add(e);}}lengthsKey(e){return e.map(n=>this.textOf(n)?.length??-1).join(",")}read(e){let n=this.listingOf(e);return n&&this.built.get(n)||this.build(e,n)}build(e,n){let o=ie(this.nodeOf(e));if(!o||o.length<2)return null;let r=[],i=[],s=[],a=Eg(o,this.textOf,r,p=>ut(this.nodeOf(p)),i,s),l=n??o.toArray(),d=_n(l,a),c=d?d.map(p=>l[p]):l,u=r.filter(p=>ut(this.nodeOf(p)).length===0&&Md(p,this.textOf).length===0),f={ranks:a,shown:c,waiting:u,lengths:this.lengthsKey(u),groups:i,missing:s};return i.length>0?this.grouped.add(e):this.grouped.delete(e),n&&(this.built.set(n,f),this.noteMembers(e,r)),(u.length>0||s.length>0)&&n?this.withRuns.add(e):this.withRuns.delete(e),f}};function _n(t,e){if(!e)return null;let n=t.map((s,a)=>a),o=new Set,r=[];t.forEach((s,a)=>{o.has(s)||(o.add(s),r.push(a));});let i=false;for(let s=0;s<r.length;){let a=e.get(t[r[s]]),l=s+1;for(;a&&l<r.length&&e.get(t[r[l]])?.group===a.group;)l+=1;if(l-s>1){let d=r.slice(s,l);d.sort((c,u)=>e.get(t[c]).rank-e.get(t[u]).rank);for(let c=0;c<d.length;c+=1){let u=r[s+c];n[u]!==d[c]&&(i=true),n[u]=d[c];}}s=l;}return i?n:null}function Dd(t,e,n){if(n.keepBoundary&&t===n.start)return t;let o=t<=n.start?t:Math.max(n.start,t-n.deleted);return o<n.start||o===n.start&&e<0?o:o+n.inserted.length}var Wi=class{constructor(e,n){this.registry=e;this.raw=n;}registry;raw;ranges=new Map;histories=new Map;strings=new Map;actions=[];shadow=null;range(e){if(this.shadow){let o=this.shadow.sources.range(e);return o?{...o,revision:0}:null}if(!this.ranges.has(e)){let o=this.registry.splitTextRange(e);this.ranges.set(e,o?{...o,revision:0}:null);}let n=this.ranges.get(e);if(n){let o=this.histories.get(n.sourceId)??[];for(;n.revision<o.length;){let r=o[n.revision],i=(s,a)=>{let l=a<0?s-1:s;return l>=r.start&&l<r.start+r.deleted};if(n.startAnchorDeleted||n.endAnchorDeleted||r.ambiguousBoundary||i(n.start,n.startAssoc)||i(n.end,n.endAssoc)){this.ensureShadow();let s=this.shadow.sources.range(e);return s?{...s,revision:0}:null}n.start=Dd(n.start,n.startAssoc,r),n.end=Dd(n.end,n.endAssoc,r),n.revision+=1;}}return n}value(e){let n=this.range(e);if(n)return this.value(n.sourceId).slice(n.start,n.end);let o=this.strings.get(e);if(o===void 0){o=this.registry.hasNode(e)?this.registry.textOf(e).toString():"";for(let r of this.histories.get(e)??[])o=o.slice(0,r.start)+r.inserted+o.slice(r.start+r.deleted);this.strings.set(e,o);}return o}apply(e){let n=yt(e),o=n?this.range(n.logicalId):null,r={keepBoundary:n?.utf16Start===0&&o?.startAssoc!==-1&&e.insert.length>0,ambiguousBoundary:o!==null&&o.start===o.end&&e.insert.length>0,start:e.utf16Start,deleted:e.deleteCount,inserted:e.insert},i=this.histories.get(e.logicalId)??[];i.push(r),this.histories.set(e.logicalId,i);let s=this.strings.get(e.logicalId);s!==void 0&&this.strings.set(e.logicalId,s.slice(0,r.start)+r.inserted+s.slice(r.start+r.deleted));let a={kind:"splice",effect:e};this.actions.push(a),this.shadow&&this.replay(a);}register(e,n,o,r){let i=this.range(n),s=i?.sourceId??n,a=i?.start??0,l=i?i.end-i.start:this.raw.node(n)?.textLength??0,d=(p,h)=>i&&h==="end"&&p===l?{assoc:i.endAssoc,deleted:i.endAnchorDeleted}:i&&p===0?{assoc:i.startAssoc,deleted:i.startAnchorDeleted}:i&&p===l?{assoc:i.endAssoc,deleted:i.endAnchorDeleted}:{assoc:a+p===0&&h==="start"?-1:0,deleted:false},c=d(o,"start"),u=d(r,"end");this.ranges.set(e,{sourceId:s,start:a+o,end:a+r,startAssoc:c.assoc,endAssoc:u.assoc,startAnchorDeleted:c.deleted,endAnchorDeleted:u.deleted,revision:this.histories.get(s)?.length??0});let f={kind:"register",product:e,source:n,start:o,end:r};this.actions.push(f),this.shadow&&this.replay(f);}destroy(){this.shadow?.doc.destroy();}ensureShadow(){if(this.shadow)return;let e=new z.Doc({gc:false}),n=e.getMap(mn);this.shadow={doc:e,nodes:n,sources:new an(n,e,this.registry.limits)},z.applyUpdate(e,z.encodeStateAsUpdate(this.registry.doc)),e.clientID=this.registry.doc.clientID,this.shadow.sources.reset();for(let o of this.actions)this.replay(o);}replay(e){let n=this.shadow,o=u=>(n.nodes.has(u)||n.nodes.set(u,Hn("")),n.nodes.get(u).get(Pe));if(e.kind==="register"){o(e.product),n.sources.register(e.product,e.source,e.start,e.end);return}let{effect:r}=e,i=yt(r),s=i?n.sources.range(i.logicalId):null,a=s?.text??o(r.logicalId),l=i?.utf16Start??r.utf16Start,d=(s?.start??0)+l,c=Oo(n.nodes,n.sources,i?.logicalId??r.logicalId,s,l,r.insert);r.deleteCount>0&&a.delete(d,r.deleteCount),r.insert.length>0&&a.insert(d,r.insert),c?.();}},Ki=class extends At{constructor(n,o,r,i,s=()=>[],a=()=>null){super(n);this.shared=n;this.visibleIndexes=o;this.raw=r;this.text=i;this.mergedOf=s;this.shownOf=a;}shared;visibleIndexes;raw;text;mergedOf;shownOf;filtered=new Set;node(n){let o=super.node(n);if(o&&!this.filtered.has(n)){this.filtered.add(n);let r=[...this.shared.adoptedChildren(n),...this.mergedOf(n)].filter((a,l,d)=>!o.children.includes(a)&&d.indexOf(a)===l),i=r.length>0?[...o.children,...r]:o.children,s=at(this.shared).shownChildIds(n,i);o.children=this.shownOf(n)?.slice()??this.visibleIndexes(n,s).map(a=>s[a]);}if(o?.isText){let r=this.text.range(n);o.textLength=r?r.end-r.start:this.raw.node(n)?.textLength??o.textLength;}return o}},_g={shownPartChildren:()=>null,shownParentOf:()=>null};function Nd(t,e,n){let o=yd(t,e);return o?{ok:true,journal:{...e,effects:[]},plan:null,typed:o}:Bg(t,e,n)}function Bg(t,e,n=_g){let o=mo(t,e.effects,S=>n.shownParentOf(S));if(o.refusal)return {ok:false,...o.refusal};let i=(o.plan?{...e,effects:o.passThrough}:e).effects.map(Jt),s=t.replacementLoserRuns(),a=i.filter(S=>S.kind==="putNode").length;if(t.nodeCount()+a>t.limits.maxNodes)return {ok:false,code:"too-many-nodes"};let l=new Set,d=new Map,c=(S,R)=>{l.add(S);let C=d.get(S)??new Set;C.add(R),d.set(S,C);};for(let S of i){if(S.kind==="spliceChildren"){if(S.childLogicalIds.length>t.limits.maxChildren)return {ok:false,code:"too-many-children"};for(let R of S.childLogicalIds)c(R,S.parentLogicalId);}else S.kind==="moveNode"&&c(S.logicalId,S.destinationParentLogicalId);if(l.size>t.limits.maxNodes)return {ok:false,code:"too-many-nodes"}}let u=new At(t),f=new Wi(t,u),p=new Ki(t,(S,R)=>x(S,R),u,f,S=>ee(S),S=>n.shownPartChildren(S)),h=new Map,g=S=>h.get(S)?.kind??t.kindOf(S),m=S=>{let R=h.get(S);return R?R.kind==="textValue"?{kind:"textValue",namespaceUri:"",localName:""}:{kind:R.kind,namespaceUri:R.qname.namespaceUri,localName:R.qname.localName}:et(t,S)},w=new Map,I=(S,R)=>{let C=t.splitSiblings.ranksOf(S),M=w.get(S);if(!C||!M)return C;let B=new Map(C),Q=0;for(let X of R){let F=M.get(X),re=F===void 0||B.has(X)?void 0:B.get(F);re&&B.set(X,{group:re.group,rank:re.rank+(Q+=1)/1e6});}return B},b=(S,R)=>{let C=new Map,M=new Map,B=[],X=(s.size===0?null:Co(R,Z=>s.has(Z),Z=>t.splitLineageOf(Z)))??R.map((Z,te)=>te),F=_n(X.map(Z=>R[Z]),I(S,R));(F?F.map(Z=>X[Z]):X).forEach(Z=>{let te=R[Z];if(te===S||s.has(te))return;let Te=C.get(te);if(Te!==void 0){let Rs=M.get(Te)??[];Rs.push(Z),M.set(Te,Rs);return}let $n=l.has(te)?S:t.parentOf(te);$n!==null&&$n!==S&&t.listingParents(te).includes(S)||(C.set(te,Z),!(!h.has(te)&&!t.showsAsChild(te))&&B.push(Z));});let re=g(S),We=go(re==="generic"?m(S)??re:re,B.map(Z=>R[Z]),m);if(!We)return {positions:B,companions:new Map,repeats:M};let oe=new Map;for(let[Z,te]of We.companions)oe.set(B[Z],te.map(Te=>B[Te]));return {positions:We.order.map(Z=>B[Z]),companions:oe,repeats:M}},x=(S,R)=>b(S,R).positions,L=S=>S.some((R,C)=>C>0&&R<S[C-1]),k=(S,R,C,M)=>{let B=x(S,R),Q=B[C]??R.length,X=I(S,R),F=C>0?B[C-1]:void 0,re=B[C];if(X&&F!==void 0&&(X.has(R[F])||re!==void 0&&X.has(R[re]))){if(X.has(R[F])){let oe=w.get(S)??new Map;M.forEach((Z,te)=>oe.set(Z,te===0?R[F]:M[te-1])),w.set(S,oe);}return F+1}if(!L(B))return Q;let We=C>0?B[C-1]+1:0;for(let oe of [Q,We,R.length]){let Z=[...R.slice(0,oe),...M,...R.slice(oe)],te=x(S,Z).map(Te=>Z[Te]);if(M.every((Te,$n)=>te[C+$n]===Te))return oe}return Q},y=S=>{let R=[S],C=new Set;for(;R.length>0;){let M=R.pop();if(C.has(M))continue;C.add(M);let B=u.node(M);if(!(!B||B.isText)){for(let Q of B.children)if(!(l.has(Q)||t.parentOf(Q)!==M)){for(let X of t.listingParents(Q)){if(X===M)continue;let F=u.node(X),re=F&&!F.isText?F.children.indexOf(Q):-1;re<0||T({kind:"spliceChildren",parentLogicalId:X,start:re,deleteCount:1,childLogicalIds:[]});}R.push(Q);}}}},v=(S,R)=>{if(t.parentOf(S)===R)for(let C of t.listingParents(S)){if(C===R||d.get(S)?.has(C))continue;let M=u.node(C);if(!(!M||M.isText))for(let B=M.children.length-1;B>=0;B-=1)M.children[B]===S&&T({kind:"spliceChildren",parentLogicalId:C,start:B,deleteCount:1,childLogicalIds:[]});}},E=new Set,P=S=>{if(E.has(S))return;E.add(S);let R=n.shownPartChildren(S),C=u.node(S);if(!R||!C||C.isText)return;let M=C.children;if(R.length===M.length&&R.every((Q,X)=>M[X]===Q))return;for(let Q of R)if(!M.includes(Q))for(let X of t.listingParents(Q)){let F=u.node(X),re=F&&!F.isText?F.children.indexOf(Q):-1;re<0||X===S||T({kind:"spliceChildren",parentLogicalId:X,start:re,deleteCount:1,childLogicalIds:[]});}let B=M.filter(Q=>!R.includes(Q));T({kind:"spliceChildren",parentLogicalId:S,start:0,deleteCount:M.length,childLogicalIds:[...R,...B]});},j=new Set,K=S=>{for(let R of at(t).movesAt(S)){if(j.has(R.node))continue;j.add(R.node);let C=u.node(R.from),M=u.node(R.to);if(!C||C.isText||!M||M.isText)continue;let B=C.children.indexOf(R.node);B<0||M.children.includes(R.node)||(T({kind:"spliceChildren",parentLogicalId:R.from,start:B,deleteCount:1,childLogicalIds:[]}),T({kind:"spliceChildren",parentLogicalId:R.to,start:R.first?0:ci(t,M.children),deleteCount:0,childLogicalIds:[R.node]}));}},Y=new Set,V=S=>{if(Y.has(S))return;Y.add(S);let R=u.node(S);if(!R||R.isText)return;let C=t.adoptedChildren(S).filter(B=>!R.children.includes(B));if(C.length===0)return;for(let B of C)for(let Q of t.listingParents(B)){if(t.replacedByOf(Q)!==S)continue;let X=u.node(Q),F=X&&!X.isText?X.children.indexOf(B):-1;F<0||T({kind:"spliceChildren",parentLogicalId:Q,start:F,deleteCount:1,childLogicalIds:[]});}let M=x(S,R.children).length;T({kind:"spliceChildren",parentLogicalId:S,start:k(S,R.children,M,C),deleteCount:0,childLogicalIds:C});},q=S=>{if(!si.has(g(S)??""))return [];let R=t.parentOf(S),C=R?u.node(R):null;return !R||!C||C.isText?[]:(b(R,C.children).companions.get(C.children.indexOf(S))??[]).map(B=>C.children[B])},ee=S=>{let R=[];for(let C of q(S)){let M=u.node(C);M&&!M.isText&&R.push(...M.children);}return R},ne=new Set,A=S=>{if(ne.has(S))return;ne.add(S);let R=u.node(S);if(!R||R.isText)return;let C=[];for(let M of q(S)){let B=u.node(M);if(!B||B.isText||B.children.length===0)continue;let Q=[...B.children];T({kind:"spliceChildren",parentLogicalId:M,start:0,deleteCount:Q.length,childLogicalIds:[]});for(let X of Q)!R.children.includes(X)&&!C.includes(X)&&C.push(X);}C.length!==0&&T({kind:"spliceChildren",parentLogicalId:S,start:u.node(S).children.length,deleteCount:0,childLogicalIds:C});},J={limits:t.limits,projectedTextValue:S=>u.node(S)?.isText?f.value(S):null,registerSplitText:(S,R,C,M)=>f.register(S,R,C,M),splitTextPending:S=>t.splitTextPending(S),record:S=>{let R=u.node(S);if(!R)return null;if(R.isText)return {logicalId:S,kind:"textValue",value:f.value(S)};let C=h.get(S),M=C?null:t.record(S);return M&&M.kind!=="textValue"?{...M,childIds:R.children}:!C||C.kind==="textValue"?null:{logicalId:S,kind:C.kind,namespaceUri:C.qname.namespaceUri,localName:C.qname.localName,prefix:C.qname.prefix??"",attributes:[],bindings:[],childIds:R.children}}},he=[],D=null,T=S=>{if(D)return;let R=Ro(t,S,u);if(R&&!R.ok){D=R;return}he.push(S),Nn(u,S),S.kind==="spliceText"&&f.apply(S);};try{for(let S of i){let R=Ro(t,S,p);if(R&&!R.ok)return R;if(Nn(p,S),S.kind==="putNode"&&h.set(S.descriptor.logicalId,S.descriptor),S.kind==="spliceText"){let C=f.range(S.logicalId);T(C?Os({...S,logicalId:C.sourceId,utf16Start:C.start+S.utf16Start},{logicalId:S.logicalId,utf16Start:S.utf16Start}):S);}else if(S.kind==="spliceChildren"){P(S.parentLogicalId),K(S.parentLogicalId),V(S.parentLogicalId),A(S.parentLogicalId);let C=u.node(S.parentLogicalId);if(!C||C.isText)return {ok:!1,code:"invalid-bound"};let{positions:M,companions:B,repeats:Q}=b(S.parentLogicalId,C.children),X=M.slice(S.start,S.start+S.deleteCount).map(F=>C.children[F]);if(S.deleteCount===0){let F=S.childLogicalIds;T({...S,start:k(S.parentLogicalId,C.children,S.start,F)});}else {let F=M.slice(S.start,S.start+S.deleteCount),re=F.flatMap(oe=>[...B.get(oe)??[],...Q.get(oe)??[]]);if(re.length>0||L(M)){let oe=[...F,...re].sort((te,Te)=>Te-te);for(let te of oe)T({...S,start:te,deleteCount:1,childLogicalIds:[]});let Z=u.node(S.parentLogicalId);if(S.childLogicalIds.length>0&&Z&&!Z.isText){let te=S.childLogicalIds,Te=k(S.parentLogicalId,Z.children,S.start,te);T({...S,start:Te,deleteCount:0});}F.length=0;}let We=F.length;for(;We>0;){let oe=We-1;for(;oe>0&&F[oe-1]===F[oe]-1;)oe-=1;T({...S,start:F[oe],deleteCount:We-oe,childLogicalIds:oe===0?S.childLogicalIds:[]}),We=oe;}}if(!D)for(let F of X)v(F,S.parentLogicalId),l.has(F)||y(F);if(!D&&S.childLogicalIds.length>0)for(let F of X){if(l.has(F)&&!h.has(F))continue;let re=Lo(g(F),S.childLogicalIds,g);re&&sn(J,F,re);}}else if(S.kind==="moveNode"){P(S.destinationParentLogicalId),K(S.destinationParentLogicalId),V(S.destinationParentLogicalId),A(S.destinationParentLogicalId);let C=u.node(S.destinationParentLogicalId);if(!C||C.isText)return {ok:!1,code:"invalid-bound"};let M=C.children.filter(B=>B!==S.logicalId);T({...S,destinationIndex:k(S.destinationParentLogicalId,M,S.destinationIndex,[S.logicalId])});}else T(S);if(D)return D}return {ok:!0,journal:{effects:he},plan:o.plan}}finally{f.destroy();}}function Yd(t,e,n){if(!e.effects.some(a=>{let l=a.kind==="spliceChildren"?a.parentLogicalId:a.kind==="moveNode"?a.destinationParentLogicalId:null;return l!==null&&t.shownPartChildren(l)!==null}))return null;let r=t.current(),i=r.ok?vt(r.issues):null,s=r.ok?i?{code:"materialize-dropped-content",detail:i}:null:{code:r.code};return s?{failure:s,transient:n()}:null}function Vi(t,e,n){for(let o of e)n.push(o.id),!(o.kind==="textValue"||t.hasNode(U(o)))&&Vi(t,o.children,n);}function _d(t,e){if(!e)return false;let n=t.partEntries().find(o=>o.name==="/word/document.xml");for(let{id:o,after:r}of e.paragraphs){let i=t.inline.textOf(o);if(!i||t.isTombstoned(o)||n&&Fg(t,o)!==n.rootLogicalId)continue;let s=new Set,a=Ze(o,i,c=>s.has(c)||!t.showsAsChild(c)?null:(s.add(c),eo(c)),t.limits,t.inline.viewOf(o)),l=[];Vi(t,a,l);let d=[];if(Vi(t,r.children.filter(c=>c.kind==="textValue"||!Ug(t,c)),d),l.length!==d.length)return true;for(let c=0;c<l.length;c+=1)if(l[c]!==d[c])return true}return false}function Ug(t,e){return e.kind==="paragraphProperties"||t.hasNode(U(e))&&!t.inline.isEmbed(e.id)}function Fg(t,e){let n=e;for(let o=0;o<t.limits.maxTreeDepth;o+=1){let r=t.parentOf(n);if(r===null)return n;n=r;}return n}var dn=Symbol("docx-restore-marks");function Bd(t,e){let n=new Map;for(let r of it(t,e)){if(r.deleted||!(r.content instanceof z.ContentString))continue;let i=r.parent;if(!(i instanceof z.Text)||je(i)!==ae)continue;let s=n.get(i)??new Set;s.add(`${r.id.client}:${r.id.clock}`),n.set(i,s);}if(n.size===0)return;let o=Le(t);t.transact(()=>{for(let[r,i]of n)for(let s=be(r);s;s=s.right){if(!s.redone)continue;let a=`${s.redone.client}:${s.redone.clock}`;if(!i.has(a))continue;let l=H(t,s.redone);if(!l||l.deleted)continue;let d=ot(r,s,0);o.markCopy("restore",s.redone.client,s.redone.clock,s.length,d),o.origin("move",s.id.client,s.id.clock)!==null&&o.markCopy("move",s.redone.client,s.redone.clock,s.length,d);}},dn);}var Ji=new WeakMap,Hi=new WeakMap,Xi=new WeakMap;function Ud(t,e,n,o=null){if(e.size===0&&!o)return n();Ji.set(t.attributes,e),o&&Hi.set(t.attributes,o);try{return n()}finally{Ji.delete(t.attributes),Hi.delete(t.attributes);}}function Gi(t,e,n,o){let r=new Map,i=n?.insertions;for(let s of we(n?.deletions))for(let a=s.clock;a<s.clock+s.length;){let l=H(t,{client:s.client,clock:a});if(!l){a+=1;continue}if(a=l.id.clock+l.length,i&&z.isDeleted(i,l.id))continue;let d=l.parent;if(d!==e.attributes&&d!==e.bindings||l.parentSub===null||!(l.content instanceof z.ContentAny))continue;let c=l.content.getContent()[0];if(typeof c!="string")continue;let u=r.get(d)??new Map;u.set(l.parentSub,c),r.set(d,u);}if(r.size===0)return o();Xi.set(e.attributes,r);try{return o()}finally{Xi.delete(e.attributes);}}function jg(t,e){if(t.parentSub===null||t.deleted)return;let n=t.parent,o=Xi.get(e.attributes)?.get(n)?.get(t.parentSub);o===void 0||n._map.get(t.parentSub)!==t||n.set(t.parentSub,o);}function zg(t,e){if(!e||t.parentSub===null)return false;let n=t.parent;if(n!==e.attributes&&n!==e.bindings)return false;let o=Ji.get(e.attributes);if(!o)return false;let r=t.parentSub.indexOf(ge);return r>0&&o.has(t.parentSub.slice(0,r))}function $g(t){return t.content instanceof z.ContentType}function Fd(t,e){return n=>{let o=n.parent;if(o===null)return true;if(zg(n,e)||e&&Hi.get(e.attributes)?.(n)||(e&&(o===e.attributes||o===e.bindings)&&jg(n,e),o===t))return false;let r=Me(o);return r===null||r.parent!==t?true:n.parentSub===wt||n.parentSub===Jn?false:!$g(n)}}var Wg=Symbol("docx-tombstone-again");function $d(t,e,n){if(t.local){Vg(t,e);return}if(n.undoStack.length===0)return;let o=t.doc,r=new Map;z.iterateDeletedStructs(t,t.deleteSet,s=>{if(!(s instanceof z.Item))return;let a=s.parentSub===me;if(!a&&s.parentSub!==ue)return;let l=s.parent;if(!(l instanceof z.Map)||l._item?.parent!==e)return;let d=r.get(l);r.set(l,{deletion:a||d?.deletion===true});});let i=[];for(let[s,{deletion:a}]of r){let l=s.get(me);if(a&&l===void 0){let u=zd(s,o.clientID,n,me);if(u){let f=Qi(s,o.clientID,u.insertions);i.push({record:s,step:u,deletion:true,survivor:f});continue}}if(l!==true||s.get(ue)!==void 0)continue;let d=zd(s,o.clientID,n,ue),c=d?Qi(s,o.clientID,d.insertions):null;d&&c!==null&&i.push({record:s,step:d,deletion:false,survivor:c});}if(i.length!==0){o.transact(()=>{for(let{record:s,deletion:a,survivor:l}of i)Kd(s,a,l);},Wg);for(let{record:s,step:a,deletion:l,survivor:d}of i)Vd(a,s,l,d);}}var qi=new WeakMap,Kg=64,Wd=t=>`${t.client}:${t.clock}`;function Vg(t,e){for(let[n,o]of t.changed){if(!o.has(ue)||!(n instanceof z.Map)||n._item?.parent!==e)continue;let r=n,i=r._map.get(ue),s=r.get(ue);if(!i||i.deleted||i.id.client!==t.doc.clientID||typeof s!="string"||s.length===0)continue;let a=qi.get(r);a||qi.set(r,a=new Map),a.size>=Kg&&a.delete(a.keys().next().value),a.set(Wd(i.id),s);}}function Qi(t,e,n){if(Zi(t,e,ue))return null;let o=qi.get(t);if(!o)return null;for(let r=t._map.get(ue)??null;r;r=r.left)if(r.parentSub===ue&&!(r.id.client!==e||!r.deleted)&&z.isDeleted(n,r.id))return o.get(Wd(r.id))??null;return null}function Kd(t,e,n){e&&t.set(me,true),n!==null&&t.set(ue,n);}function Vd(t,e,n,o){n&&jd(t,e,me),o!==null&&jd(t,e,ue);}function jd(t,e,n){let o=e._map.get(n);if(!o)return;let r=z.createDeleteSet();r.clients.set(o.id.client,[{clock:o.id.clock,len:o.length}]),t.insertions=z.mergeDeleteSets([t.insertions,r]);}function Jd(t,e,n,o,r){let i=new Set,s=e instanceof z.Map?e:null;for(let l of o){let d=s?.get(l);d instanceof z.Map&&!Zi(d,t.clientID)&&i.add(d);}for(let l of we(n.deletions))for(let d=l.clock;d<l.clock+l.length;){let c=H(t,{client:l.client,clock:d});if(!c)break;if(d=c.id.clock+c.length,c.parentSub!==me||c.id.client!==t.clientID||!c.deleted||c.redone!==null)continue;let u=c.parent;!(u instanceof z.Map)||u._item?.parent!==e||Zi(u,t.clientID)||i.add(u);}if(i.size===0)return;let a=r();for(let l of i){let d=Qi(l,t.clientID,n.deletions);Kd(l,true,d),Vd(a,l,true,d);}}function zd(t,e,n,o){for(let r=t._map.get(o)??null;r;r=r.left){if(r.parentSub!==o||r.id.client!==e||!r.deleted)continue;let i=n.undoStack.find(s=>z.isDeleted(s.insertions,r.id));if(i)return i}return null}function Zi(t,e,n=me){let o=t._map.get(n);return !!o&&!o.deleted&&o.id.client===e}function Hd(t,e,n){let o=new Set;for(let r of we(n?.insertions))if(r.client===t.clientID)for(let i=r.clock;i<r.clock+r.length;){let s=H(t,{client:r.client,clock:i});if(!s)break;if(i=s.id.clock+s.length,s.parentSub!==me)continue;let a=s.parent;if(!(a instanceof z.Map)||a._item?.parent!==e)continue;let l=a._item?.parentSub??null;l!==null&&o.add(l);}return [...o]}var Po="undoneInto",Jg=512;function Xd(t){return _(t)&&t.get(ae)instanceof z.Text}function Gd(t){if(!_(t)||Ae(t))return null;let e=t.get(Po);if(typeof e!="string"||e.length>Jg)return null;let n=e.startsWith("^"),o=n?e.slice(1):e;return o.length>0?{paragraph:G(o),atStart:n}:null}function qd(t,e,n){let o=new Map;for(let r of we(n?.insertions))for(let i=r.clock;i<r.clock+r.length;){let s=H(t,{client:r.client,clock:i});if(!s)break;i=s.id.clock+s.length;let a=s.parent;if(s.deleted||!(a instanceof z.Array)||je(a)!==xt)continue;let l=Me(a)?.parent;if(!(l instanceof z.Map)||Me(l)?.parent!==e)continue;let d=o.get(a)??new Set;for(let c of s.content.getContent())typeof c=="string"&&Xd(e.get(c))&&d.add(G(c));d.size>0&&o.set(a,d);}return o}function Qd(t,e,n,o){let r=[];for(let[i,s]of qd(t,e,n)){let a=i.toArray(),l=f=>{let p=a[f],h=p===void 0?void 0:e.get(p);return p!==void 0&&Xd(h)&&!Ae(h)?p:null},d=[],c=null;a.forEach((f,p)=>{d.push(c),s.has(f)||(c=l(p));});let u=null;for(let f=a.length-1;f>=0;f-=1){let p=a[f];if(!s.has(p)){u=l(f);continue}let h=e.get(p),g=d[f]??(u===null?void 0:`^${u}`);h&&h.get(Po)!==g&&r.push({record:h,target:g});}}r.length!==0&&o(()=>{for(let{record:i,target:s}of r)s===void 0?i.delete(Po):i.set(Po,s);});}function Hg(t,e){let n=e.parent;if(!(n instanceof z.Text)||je(n)!==ae)return null;let o=Me(n)?.parent;return o instanceof z.Map&&Me(o)?.parent===t?o:null}function Zd(t,e,n){let o=new Set;for(let d of we(n?.deletions))for(let c=d.clock;c<d.clock+d.length;){let u=H(t,{client:d.client,clock:c});if(!u)break;c=u.id.clock+u.length;let f=Hg(e,u);f&&o.add(f);}if(o.size===0||[...o].some(d=>!Ae(d)))return null;let r=Le(t),i=d=>r.origin("move",d.id.client,d.id.clock)!==null,s=new Set,a=new Set;for(let d of qd(t,e,n).values())for(let c of d){let u=e.get(c)?.get(ae);if(u instanceof z.Text){for(let f=be(u);f;f=f.right)if(!(f.deleted||!i(f))){s.add(c),a.add(u);break}}}if(s.size===0)return null;let l=new Set([...s].map(d=>e.get(d)));return d=>{let c=d.parent;if(a.has(c))return i(d);if(l.has(c))return true;if(!(c instanceof z.Array)||je(c)!==xt)return false;let u=d.content.getContent();return u.length>0&&u.every(f=>s.has(f))}}var Xg=new Set(["comment","commentEx","footnote","endnote"]),ec="docx-undone-records";function Gg(t,e,n,o){let r=n?.meta,i=e==="undo"?o.filter(a=>{let l=t.record(a);return _(t.schema.nodes.get(a))&&!t.isTombstoned(a)&&!!l&&$(l)&&Xg.has(l.localName)}):[],s=e==="redo"?r?.get(ec)??[]:[];e==="undo"&&r?.set(ec,i),!(i.length===0&&s.length===0)&&t.doc.transact(()=>{for(let a of i)t.schema.nodes.get(a)?.set(St,true);for(let a of s){let l=t.schema.nodes.get(a);_(l)&&l.has(St)&&l.delete(St);}},dn);}var es="docx-copy-runs",tc="docx-hidden-copies",oc="docx-copies-only",nc="docx-own-deletes",ts="docx-undo-group";function ns(t){t.meta.set(ts,true);}function rc(t,e,n){t.normalizeRestoredSplitTextAnchors(),Bd(e,n),e.transact(()=>ed(e,o=>t.schema.nodes.get(o),n),dn);}function ic(t,e,n,o){let r=n==="undo"?e.undoStack:e.redoStack,i=n==="undo"?e.redoStack:e.undoStack,s=r[r.length-1],a=n==="undo"?om(t,s):Do(s,es)??[],l=i.length,d=n==="undo"?Hd(t.doc,t.schema.nodes,s):Do(s,nc)??[],c=s?.meta.get(oc)===true&&nm(s)===0,u=s?.meta.get(ts)===true;if(c||a.length>0&&rm(t,s))r.pop();else {let p=r.splice(0,u?r.length-1:tm(r));try{n==="undo"?(Qd(t.doc,t.schema.nodes,s,h=>t.doc.transact(h,dn)),Ud(t.schema,Zg(t,s),()=>Gi(t.doc,t.schema,s,()=>e.undo()),Zd(t.doc,t.schema.nodes,s))):Gi(t.doc,t.schema,s,()=>e.redo());}finally{if(p.length>0){let h=p.concat(r);r.length=0;for(let g of h)r.push(g);}}}let f=i.length>l?i[i.length-1]:void 0;t.doc.transact(()=>{if(o(),n==="redo"&&s&&Jd(t.doc,t.schema.nodes,s,d,()=>(f??=Ao(i),f)),n==="undo"&&d.length>0&&(f??=Ao(i),f.meta.set(nc,d)),n==="redo"){let p=Do(s,tc);p&&p.length>0&&Qe(t.doc).withdraw(p);}a.length>0&&(f??=Ao(i),f.meta.set(es,a),n==="undo"&&f.meta.set(tc,Qe(t.doc).record(a)));},dn),u&&(f??=Ao(i),ns(f)),Gg(t,n,n==="redo"?s:f,t.takeUnlisted()),e.stopCapturing();}function qg(t,e,n,o){let r=[];for(let i=n;i<o;){let s=t.origin("restore",e,i);if(s===null||s.client!==e){let d=s===null?o:Math.min(o,s.firstClock+s.length);r.push({client:e,from:i,to:d}),i=d;continue}let a=Math.min(o,s.firstClock+s.length),l=s.clock+(i-s.firstClock);r.push({client:s.client,from:l,to:l+(a-i)}),i=a;}return r}function Qg(t,e,n,o){for(let r=n;r<o;r+=1)if(t.shownCopy(`${e}:${r}`))return true;return false}function Zg(t,e){let n=new Set,o=t.schema.nodes;for(let r of we(e?.insertions))for(let i=r.clock;i<r.clock+r.length;){let s=H(t.doc,{client:r.client,clock:i});if(!s)break;s.parent===o&&s.parentSub!==null&&n.add(s.parentSub),i=s.id.clock+s.length;}return n}function em(t){return !(t.content instanceof z.ContentString)&&!(t.content instanceof z.ContentEmbed)?false:sc(t)}function sc(t){return t.content instanceof z.ContentFormat?false:t.parent instanceof z.Text&&t.parent._item?.parentSub===ae}function tm(t){for(let e=t.length-2;e>=0;e-=1)if(t[e].meta.get(ts)===true)return e+1;return 0}function nm(t){let e=t;return we(e.insertions).length+we(e.deletions).length}function om(t,e){let n=t.inline.follow,o=Le(t.doc),r=(Do(e,es)??[]).map(s=>({...s})),i=(s,a,l)=>{let d=r[r.length-1];d&&d.client===s&&d.to===a?d.to=l:r.push({client:s,from:a,to:l});};for(let s of we(e?.insertions)){let a=s.clock+s.length;for(let l=s.clock;l<a;){let d=H(t.doc,{client:s.client,clock:l}),c=d?Math.min(d.id.clock+d.length,a):l+1;if(d?.deleted||d&&!o.origin("restore",s.client,l)){let u=qg(o,s.client,l,c);if(!!d&&(d.deleted?sc(d):em(d))||u.some(p=>n.holdsCopyIn(p.client,p.from,p.to)&&Qg(n,p.client,p.from,p.to)))for(let p of u)i(p.client,p.from,p.to);}l=c;}}return r}function rm(t,e){if(!e)return false;let n=new Set(t.trackedTypes()),o=e;for(let[r,i]of [[we(o.deletions),true],[we(o.insertions),false]])for(let s of r)for(let a=s.clock;a<s.clock+s.length;){let l=H(t.doc,{client:s.client,clock:a});if(!l||im(l,n)&&(i||!l.deleted))return false;a=l.id.clock+l.length;}return true}function im(t,e){let n=t.parent;for(;n!==null;){if(e.has(n))return true;let o=n._item?.parent;n=o instanceof z.AbstractType?o:null;}return false}function Do(t,e){return t?.meta.get(e)}function Ao(t){let e={meta:new Map([[oc,true]])};return Object.assign(e,{insertions:z.createDeleteSet(),deletions:z.createDeleteSet()}),t.push(e),e}function ac(t,e,n){let o=t.trackedOrigins.delete(e);try{return n()}finally{o&&t.trackedOrigins.add(e);}}var No=class{constructor(e,n){this.undoManager=e;let o=r=>{this.capturing&&r.type==="undo"&&(this.gestureItem=r.stackItem,this.captured=true,this.pinned!==void 0&&ns(r.stackItem));};e.on("stack-item-added",o),e.on("stack-item-updated",o),n&&cm(n,e,()=>this.reset());}undoManager;previous;gestureItem;capturing=false;captured=false;pinned;capture(e,n){let o=this.pinned??e,r=this.previous;this.previous=o;let i=this.undoManager.undoStack,s=this.undoManager.captureTimeout;o===r&&o!==void 0&&i[i.length-1]===this.gestureItem?(this.undoManager.lastChange=Date.now(),this.undoManager.captureTimeout=Number.POSITIVE_INFINITY):((o!==r||o!==void 0)&&this.undoManager.stopCapturing(),this.gestureItem=void 0);let a=this.gestureItem;this.captured=false,this.capturing=o!==void 0;try{let l=n();return this.captured&&reportHistoryGroup(e,this.gestureItem===a?"extended":"started"),l}catch(l){throw this.refused(),l}finally{this.capturing=false,this.undoManager.captureTimeout=s;}}captureJournal(e,n,o){return isJournalOutsideUndo(e)?ac(this.undoManager,n,o):this.capture(historyGroupOfJournal(e),o)}reset(){this.previous=void 0,this.gestureItem=void 0;}refused(){this.pinned===void 0&&this.reset();}pin(e){this.undoManager.stopCapturing(),this.reset(),this.pinned=e;}unpin(){this.pinned=void 0,this.reset(),this.undoManager.stopCapturing();}};function cm(t,e,n){let o=new WeakMap,r=i=>{let s=o.get(i);return s||o.set(i,s={}),s};e.on("stack-item-popped",({stackItem:i,type:s})=>{let a=(s==="undo"?e.redoStack:e.undoStack).at(-1);a&&o.set(a,r(i));}),registerUndoHistoryPosition(t,{current:()=>{let i=e.undoStack.at(-1);return i?r(i):null},split:()=>{n(),e.stopCapturing(),e.clear(false,true);}});}function lc(t,e){let n=Le(t),o=Qe(t),r=Cn(t),i=null,s=u=>{if(!e.loading()){if(u==="all"||i==="all"){i="all";return}i??=new Set;for(let f of u)i.add(f);}},a=()=>{let u=i;if(i=null,u===null||e.loading())return;let f=e.inline.marksChanged(u==="all"?e.inline.allTexts():u);f.size>0&&e.changed(f);},l=n.subscribe(s),d=o.subscribe(u=>s(n.textsReading(u))),c=r.subscribe(u=>s(n.textsReading(u)));return t.on("beforeObserverCalls",a),()=>{l(),d(),c(),t.off("beforeObserverCalls",a);}}function dc(t,e){let n=[],o=e;for(let r=0;r<t.maxDepth;r+=1){let i=t.parentOf(o);if(i===void 0)break;n.push(t.childrenOf(i)?.indexOf(o)??-1),o=i;}return {root:o,indexes:n.reverse()}}function cc(t,e,n){if(e===n)return 0;let o=dc(t,e),r=dc(t,n);if(o.root===r.root){let i=Math.min(o.indexes.length,r.indexes.length);for(let s=0;s<i;s+=1){let a=o.indexes[s]-r.indexes[s];if(a!==0)return a}}return e<n?-1:1}var Yo=class{unlisted=new Set;marks=new Set;noteUnlisted(e){this.unlisted.add(e);}noteMarkChanged(e){this.marks.add(e);}takeUnlisted(e){let n=[...this.unlisted].filter(o=>!e(o));return this.unlisted.clear(),n}takeMarkChanges(){let e=[...this.marks];return this.marks.clear(),e}};function uc(t,e){let n=i=>{let s=new Set,a=false;for(let l of i){let d=l.path;if(d.length===0){for(let c of l.changes.keys.keys())s.add(G(c));a=true;continue}s.add(G(d[0])),l.target instanceof z.Array&&(a=true),l.target instanceof z.Map&&(l.changes.keys.has(me)||l.changes.keys.has(ue))&&(a=true);}(s.size>0||a)&&e({logicalIds:s,membershipChanged:a,packageChanged:false});},o=i=>{let s=new Set;for(let a of i.changes.keys.keys()){let l=bn(String(a))??Ot(String(a));!l||O(l.logicalId)||s.add(l.logicalId);}s.size>0&&e({logicalIds:s,membershipChanged:false,packageChanged:false});},r=()=>{e({logicalIds:new Set,membershipChanged:false,packageChanged:true});};return t.nodes.observeDeep(n),t.attributes.observe(o),t.bindings.observe(o),t.parts.observeDeep(r),t.relationships.observeDeep(r),t.overrides.observe(r),t.defaults.observe(r),t.binaries.observeDeep(r),()=>{t.nodes.unobserveDeep(n),t.attributes.unobserve(o),t.bindings.unobserve(o),t.parts.unobserveDeep(r),t.relationships.unobserveDeep(r),t.overrides.unobserve(r),t.defaults.unobserve(r),t.binaries.unobserveDeep(r);}}function fc(t,e){if(!t.hasNode(e)||t.isTombstoned(e))return false;let n=t.parentOf(e);if(n===null)return false;let o=t.record(n);return o!==null&&$(o)&&o.childIds.includes(e)}function Bo(t){return typeof t=="string"?t:""}function pc(t,e){return t<e?-1:t>e?1:0}function os(t,e){return `${t}${ge}${e}`}function fm(t){let e=t.indexOf(ge);return e<0?t:t.slice(0,e)}function hc(t){let e=[];return t.forEach((n,o)=>{!_(n)||O(o)||n.forEach(r=>{if(!_(r))return;let i=Bo(r.get("id")),s=Bo(r.get("type"));if(i.length===0||s.length===0)return;let a=Bo(r.get("ownerPart"))||fm(o);if(O(a))return;let l=r.get("order");e.push({ownerPart:a,id:i,type:s,rawTarget:Bo(r.get("rawTarget")),targetMode:r.get("targetMode")==="External"?"External":"Internal",order:typeof l=="number"&&Number.isSafeInteger(l)?l:0});});}),e.sort((n,o)=>n.order-o.order||pc(n.ownerPart,o.ownerPart)||pc(n.id,o.id)),e}function gc(t,e){return t.nodes.observeDeep(e.onNodeEvents),t.attributes.observe(e.onAttributeEvent),t.bindings.observe(e.onBindingEvent),t.relationships.observeDeep(e.onRelationshipChange),t.parts.observeDeep(e.onPartChange),()=>{t.nodes.unobserveDeep(e.onNodeEvents),t.attributes.unobserve(e.onAttributeEvent),t.bindings.unobserve(e.onBindingEvent),t.relationships.unobserveDeep(e.onRelationshipChange),t.parts.unobserveDeep(e.onPartChange);}}function pm(t,e){let n=Math.min(t.length,e.length);for(let o=0;o<n;o+=1){let r=t[o]-e[o];if(r!==0)return r}return t.length-e.length}function hm(t,e){let n=t.childrenSnapshot.get(e);return n||(ie(t.nodes.get(e))?.toArray()??[])}function gm(t,e){let n=t.nodes.get(e);return !_(n)||Ae(n)}var rs=class{constructor(e){this.ctx=e;}ctx;byParent=new Map;indexOf(e,n){let o=this.byParent.get(e);return o||(o=new Map,hm(this.ctx,e).forEach((r,i)=>{o.has(r)||o.set(r,i);}),this.byParent.set(e,o)),o.get(n)??-1}};function mm(t,e,n,o,r){let i=[],s=new Set,a=r,l;for(;;){if(s.has(a)||(s.add(a),gm(t,a)))return null;l=n.get(a);let u=t.parentIndex.get(a);if(l!==void 0){if(u!==void 0||o.has(a))return "fallback";break}if(u===void 0)return o.has(a)?"deferred":null;i.push(a),a=u;}let d=[l],c=a;for(let u=i.length-1;u>=0;u-=1){let f=i[u],p=e.indexOf(c,f);if(p<0)return null;d.push(p),c=f;}return d}function ym(t,e){let n=new Set(e);for(let l of n)t.parentIndex.delete(l);let o=new Map;t.partRoots.forEach((l,d)=>{o.has(l)||o.set(l,d);});let r=new rs(t),i=new Map,s=l=>{let d=i.get(l);if(d!==void 0)return d;let c=mm(t,r,o,n,l);return c!=="deferred"&&i.set(l,c),c},a=[...n];for(;a.length>0;){let l=[];for(let d of a){let c=null,u=false;for(let f of t.listings.get(d)??[]){if(f===d)continue;let p=s(f);if(p==="fallback")return false;if(p==="deferred"){u=true;continue}if(p===null)continue;let h=r.indexOf(f,d);if(h<0)continue;let g=[...p,h];(!c||pm(g,c.rank)<0)&&(c={rank:g,parent:f});}if(u){l.push(d);continue}c&&t.parentIndex.set(d,c.parent),n.delete(d);}if(l.length===a.length)return false;a=l;}return true}function is(t,e){let{nodes:n,parentIndex:o,childrenSnapshot:r,partRoots:i}=t;if(e)for(let s of e)o.delete(s);for(let s of i){let a=new Set,l=[{id:s,parent:null,exit:false}];for(;l.length>0;){let d=l.pop();if(d.exit){a.delete(d.id);continue}let c=d.id;if(d.parent!==null&&(e===null||e.has(c))&&(o.has(c)||o.set(c,d.parent)),a.has(c))continue;let u=n.get(c);if(!_(u)||Ae(u))continue;let f=r.get(c)??ie(u)?.toArray()??[];a.add(c),l.push({id:c,parent:null,exit:true});let p=new Set,h=[];for(let g of f)p.has(g)||g===c||(p.add(g),h.push(g));for(let g=h.length-1;g>=0;g-=1)l.push({id:h[g],parent:c,exit:false});}}}function mc(t,e){let n=[];for(let o of e){let r=t.listings.get(o);if(!r||r.size===0){t.parentIndex.delete(o);continue}if(r.size===1){t.parentIndex.set(o,[...r][0]);continue}n.push(o);}n.length!==0&&(ym(t,n)||is(t,new Set(n)));}function yc(t,e){return `${t}${ge}${e}`}function ss(t,e,n,o,r){if(O(n)||O(o.localName))return;let i=zt(t.namespaces,o.namespaceUri,e),s=Rr(n,i,o.localName);O(s)||t.attributes.set(s,Vs(o.prefix??"",r));}function bc(t,e,n,o){t.attributes.delete(Rr(e,Lt(n),o));}function as(t,e,n,o,r){if(O(n)||O(o))return;let i=zt(t.namespaces,r,e),s=Or(n,o);O(s)||t.bindings.set(s,i);}function Ic(t,e,n){t.bindings.delete(Or(e,n));}function xc(t,e,n,o,r,i){let{prefix:s,value:a}=Js(i),l=e.get(n);l||(l=new Map,e.set(n,l)),l.set(yc(o,r),{namespaceUri:Rt(t.namespaces,o),localName:r,prefix:s.length>0?s:void 0,value:a});}function bm(t,e,n,o){let r=t.get(e);r&&(r.delete(yc(n,o)),r.size===0&&t.delete(e));}function Sc(t,e,n,o,r){let i=e.get(n);i||(i=new Map,e.set(n,i)),i.set(o,{prefix:o,namespaceUri:Rt(t.namespaces,r)});}function Im(t,e,n){let o=t.get(e);o&&(o.delete(n),o.size===0&&t.delete(e));}function wc(t,e,n){for(let[o,r]of n.changes.keys){let i=bn(String(o));if(!i||O(i.logicalId)||O(i.localName))continue;if(r.action==="delete"){bm(e,i.logicalId,i.namespaceId,i.localName);continue}let s=t.attributes.get(String(o));typeof s=="string"&&xc(t,e,i.logicalId,i.namespaceId,i.localName,s);}}function kc(t,e,n){for(let[o,r]of n.changes.keys){let i=Ot(String(o));if(!i||O(i.logicalId)||O(i.prefix))continue;if(r.action==="delete"){Im(e,i.logicalId,i.prefix);continue}let s=t.bindings.get(String(o));typeof s=="string"&&Sc(t,e,i.logicalId,i.prefix,s);}}function vc(t,e,n){t.attributes.forEach((o,r)=>{if(typeof o!="string"||O(r))return;let i=bn(r);!i||O(i.logicalId)||O(i.localName)||xc(t,e,i.logicalId,i.namespaceId,i.localName,o);}),t.bindings.forEach((o,r)=>{if(typeof o!="string"||O(r))return;let i=Ot(r);!i||O(i.logicalId)||O(i.prefix)||Sc(t,n,i.logicalId,i.prefix,o);});}function ls(t,e,n){let o=t.listings.get(e)??new Set;o.add(n),t.listings.set(e,o);}function xm(t,e,n){let o=t.listings.get(e);o&&(o.delete(n),o.size===0&&t.listings.delete(e));}function Lc(t,e,n){let o=t.childrenSnapshot.get(e)??[];if(Qn(o,n))return [];let r=new Set(n),i=new Set(o),s=[];for(let a of o)r.has(a)||(xm(t,a,e),s.push(a));for(let a of n)i.has(a)||(ls(t,a,e),s.push(a));return t.childrenSnapshot.set(e,n),s}function Rc(t,e){if(!t||e.length===0)return;let n=new Map;for(let o of e)n.set(o,(n.get(o)??0)+1);for(let o=t.length-1;o>=0;o-=1){let r=t.get(o),i=n.get(r)??0;i!==0&&(n.set(r,i-1),t.delete(o,1));}}var Sm=1024,Uo=class{constructor(e,n){this.nodes=e;this.reads=n;}nodes;reads;adoptees=new Map;sources=new Map;survivorOf=new Map;reset(){this.adoptees=new Map,this.sources=new Map,this.survivorOf=new Map;}sync(e){let n=this.survivorOf.get(e);if(n!==void 0){this.survivorOf.delete(e);let i=this.sources.get(n);i&&(i.delete(e),i.size===0&&this.sources.delete(n));}let o=this.nodes.get(e),r=qn(o);if(n!==void 0&&n!==r&&this.recompute(n),r!==null){if(Ae(o)){let i=this.sources.get(r)??new Set;i.add(e),this.sources.set(r,i),this.survivorOf.set(e,r);}this.recompute(r);}}recomputeListerSurvivors(e){for(let n of this.reads.listersOf(e)){let o=this.survivorOf.get(n);o!==void 0&&this.recompute(o);}}isContentWitness(e){let n=this.reads.kindOf(e);return n!==null&&!n.endsWith("Properties")}recompute(e){let n=new Set,o=e;for(;o!==void 0&&!n.has(o)&&n.size<Sm;)n.add(o),this.recomputeOne(o),o=this.survivorOf.get(o);}recomputeOne(e){let n=[],o=new Set,r=na(this.nodes,this.sources.get(e));for(let i of r){let s=this.nodes.get(i);if(!s)continue;let a=ie(s)?.toArray()??[];for(let l of [...a,...this.adoptees.get(i)??[]])o.has(l)||this.reads.isTombstoned(l)||!this.nodes.has(l)||this.isContentWitness(l)&&(o.add(l),n.push(l));}n.length>0?this.adoptees.set(e,n):this.adoptees.delete(e);}};function Yt(t){let e=2166136261;for(let n=0;n<t.length;n+=1)e=Math.imul(e^t.charCodeAt(n),16777619)>>>0;return String(e).padStart(10,"0")}var wm=/^\d{10}$/,ds=class extends Set{heap=[];add(e){return this.has(e)||(super.add(e),this.heap&&this.push(e)),this}first(){let e=this.heap;for(;e.length>0&&!this.has(e[0]);)this.pop();return e[0]}push(e){let n=this.heap;n.push(e);for(let o=n.length-1;o>0;){let r=o-1>>1;if(n[r]<=n[o])break;[n[r],n[o]]=[n[o],n[r]],o=r;}}pop(){let e=this.heap,n=e.pop();if(e.length!==0){e[0]=n;for(let o=0;;){let r=2*o+1,i=r+1,s=o;if(r<e.length&&e[r]<e[s]&&(s=r),i<e.length&&e[i]<e[s]&&(s=i),s===o)break;[e[s],e[o]]=[e[o],e[s]],o=s;}}}};function un(t){return t.first()}function km(t){let e=[];for(let n of [t.run?.id,t.runProperties?.id,t.text?.id,t.textValueId,...t.wrap.map(o=>o.id)])n&&e.push(n);return e}var Fo=class{constructor(e,n,o,r,i=()=>{}){this.nodes=e;this.limits=n;this.isDeleted=o;this.textChanged=i;this.follow=new vo(s=>this.textOf(s),o,r,s=>this.noteOthers(s),s=>this.paragraphHolding(s),s=>Gd(this.nodes.get(s)));}nodes;limits;isDeleted;textChanged;holders=new Map;idsOf=new Map;embeds=new Set;affected=new Set;built=false;drift=false;follow;paragraphHolding(e){let n=ke(e),o=this.nodes.doc;if(!o||!n)return null;let{client:r,clock:i}=n,s=H(o,{client:r,clock:i})?.parent;if(!(s instanceof z.Text)||je(s)!==ae)return null;let a=Me(s)?.parent,l=a instanceof z.Map?je(a):null;if(l===null||O(l))return null;let d=G(l);return this.textOf(d)===s?d:null}isDeletedParagraph(e){return this.isDeleted(e)}textOf(e){let n=this.nodes.get(e);if(!_(n))return null;let o=n.get(ae);return o instanceof z.Text?o:null}owner(e){this.ensureBuilt();let n=e,o=null;for(let r=0;r<64;r+=1){let i=this.holders.get(n);if(i){if(o!==null){for(let d of i)if(Yt(d)===o)return d;for(let d of i)for(let c of this.follow.targetsFor(d))if(Yt(c)===o)return c;let l=this.paragraphTagged(o);if(l)return l}return un(i)}if(n!==e&&this.textOf(n))return n;let s=n.lastIndexOf("~");if(s<0)return null;let a=n.slice(s+1);o===null&&wm.test(a)&&(o=a),n=n.slice(0,s);}return null}paragraphTagged(e){for(let o of this.idsOf.keys())if(Yt(o)===e)return o;let n=null;return this.nodes.forEach((o,r)=>{n===null&&Yt(r)===e&&this.textOf(r)&&(n=r);}),n}holdersOf(e){return this.ensureBuilt(),this.holders.get(e)??new Set}shownId(e,n){if(this.ensureBuilt(),this.nodes.has(n))return `${n}~${Yt(e)}`;let o=this.holders.get(n);return o&&!o.has(e)?`${n}~${Yt(e)}`:!o||o.size<2||un(o)===e?n:`${n}~${Yt(e)}`}viewOf(e){return this.ensureBuilt(),{shownId:n=>this.shownId(e,n),noteDrift:()=>this.noteDrift(),showsEmbed:n=>{let o=this.holders.get(n);return !o||o.size<2||un(o)===e},shown:n=>this.follow.shown(e,n),textOf:n=>this.textOf(n),lineageOf:n=>gl(this.nodes.get(n)),listed:n=>!this.isDeleted(n)}}sharesIds(e){this.ensureBuilt();for(let n of this.idsOf.get(e)??[])if((this.holders.get(n)?.size??0)>1||!this.embeds.has(n)&&this.nodes.has(n))return true;return false}isEmbed(e){return this.ensureBuilt(),this.embeds.has(e)}noteDrift(){this.drift=true;}takeDrift(){this.follow.settle();let e=this.drift||this.affected.size>0;return this.drift=false,e}takeAffected(){if(this.follow.settle(),this.affected.size===0)return new Set;let e=new Set(this.affected);return this.affected.clear(),e}allTexts(){let e=new Set;return this.nodes.forEach((n,o)=>{let r=this.textOf(o);r&&e.add(r);}),e}marksChanged(e){let n=new Set;if(!this.built)return n;for(let o of e){if(je(o)!==ae)continue;let r=Me(o)?.parent,i=r instanceof z.Map?je(r):null;if(i===null||O(i))continue;let s=G(i);this.textOf(s)===o&&(this.follow.invalidate(s),this.paragraphChanged(s),n.add(s));}return n}paragraphChanged(e){if(this.textChanged(e),!this.built)return;let n=this.idsOf.get(e)??new Set,o=new Set,r=new Set,i=this.textOf(e);if(i)for(let s of i.toDelta()){if(typeof s.insert=="object"&&s.insert!==null){let a=s.insert.n;typeof a=="string"&&(o.add(a),r.add(a));}for(let a of km(Ne(s.attributes,this.limits,e)))o.add(a);}for(let s of n)o.has(s)||this.release(s,e);for(let s of o)n.has(s)||this.hold(s,e);for(let s of r)this.embeds.add(s);o.size>0?this.idsOf.set(e,o):this.idsOf.delete(e),this.noteOthers(this.follow.paragraphChanged(e));}noteOthers(e){for(let n of e)this.affected.add(n);e.size>0&&this.noteDrift();}orderChanged(){if(this.built)for(let e of this.follow.orderChanged())this.affected.add(e);}recordArrived(e){if(this.built)for(let n of this.holders.get(e)??[])this.holderAffected(n);}holderAffected(e){this.affected.add(e);for(let n of this.follow.placedTargetsFor(e))this.affected.add(n);}listingChanged(e){if(this.built){for(let n of this.holders.get(e)??[])this.holderAffected(n);this.textOf(e)&&(this.noteOthers(this.follow.paragraphChanged(e)),this.affected.add(e));}}hold(e,n){let o=this.holders.get(e);if(o||(o=new ds,this.holders.set(e,o)),o.size>0){let i=un(o);n<i&&this.affected.add(i);}let r=o.size<2;o.add(n),r&&this.holdersChanged(o);}release(e,n){let o=this.holders.get(e);if(!o)return;o.size<=2&&this.holdersChanged(o);let r=un(o)===n;if(o.delete(n),o.size===0){this.holders.delete(e),this.embeds.delete(e);return}r&&this.affected.add(un(o));}holdersChanged(e){for(let n of e)for(let o of this.follow.placedTargetsFor(n))e.has(o)||this.affected.add(o);}rebuild(){this.built=true,this.markShared(),this.follow.clear(),this.holders.clear(),this.idsOf.clear(),this.embeds.clear(),this.nodes.forEach((e,n)=>{_(e)&&e.get(ae)instanceof z.Text&&this.paragraphChanged(G(n));}),this.markShared();}ensureBuilt(){this.built||(this.rebuild(),this.follow.settle(),this.affected.clear());}markShared(){for(let e of this.holders.values())if(e.size>1)for(let n of e)this.affected.add(n);}};function fn(t){return typeof t=="string"?t:""}function Oc(t){let e=[];return t.forEach((n,o)=>{if(!_(n)||O(o))return;let r=fn(n.get("rootId"));r.length!==0&&e.push({name:o,id:fn(n.get("id")),rootLogicalId:r,contentType:fn(n.get("contentType"))});}),e.sort((n,o)=>n.name<o.name?-1:n.name>o.name?1:0),e}function Ec(t){let e=new Map;return t.forEach((n,o)=>{typeof n=="string"&&!O(o)&&e.set(partNameKey(o),n);}),e}function Cc(t){let e=new Map;return t.forEach((n,o)=>{typeof n=="string"&&!O(o)&&e.set(o,n);}),e}function Tc(t){let e=[];return t.forEach((n,o)=>{if(!_(n)||O(o))return;let r=fn(n.get("digest")),i=n.get("size"),s=fn(n.get("mediaType")),a=fn(n.get("storageKey"))||o;r.length===0||typeof i!="number"||e.push({digest:r,size:i,mediaType:s,storageKey:a});}),e}var cs="/word/numbering.xml",Lm="http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering";function Mc(t,e){let n=e.parent;if(n===t.bindings&&e.parentSub){let a=Ot(e.parentSub),l=a&&t.nodes.get(a.logicalId);if(l){let d=Ge(l);if(d.localName==="numbering"&&t.namespaces.get(d.namespaceId)==="http://schemas.openxmlformats.org/wordprocessingml/2006/main")return true}}if(n===t.overrides&&e.parentSub===cs||n===t.parts&&e.parentSub===cs)return true;let o=Me(n);if(o?.parent===t.parts&&o.parentSub===cs)return true;let r=a=>a instanceof z.Map&&a.get("type")===Lm,i=a=>a instanceof z.Map&&[...a.values()].some(r);return n===t.relationships?e.content.getContent().some(i):o?.parent===t.relationships?e.content.getContent().some(r):Me(o?.parent)?.parent===t.relationships&&r(n)}var rt=class{constructor(e,n){this.doc=e;this.stopKeepingMarkers=Es(e),this.schema=Ws(e),this.limits=Us(n),this.splitDedup=new Eo(this.schema.nodes),this.inline=new Fo(this.schema.nodes,this.limits,o=>this.isTombstoned(o)||!this.parentIndex.has(o),(o,r)=>cc({parentOf:i=>this.parentIndex.get(i),childrenOf:i=>this.splitSiblings.shownChildren(i),maxDepth:this.limits.maxTreeDepth},o,r),o=>this.splitSiblings.textChanged(o)),this.adoption=new Uo(this.schema.nodes,{kindOf:o=>this.kindOf(o),isTombstoned:o=>this.isTombstoned(o),listersOf:o=>this.listings.get(o)??[]}),this.splitTextSources=new an(this.schema.nodes,this.doc,this.limits),this.stopMarks=lc(e,{inline:this.inline,loading:()=>this.bulkLoad>0,changed:o=>{for(let r of this.markListeners)r(o);}}),this.stopObserving=gc(this.schema,{onNodeEvents:o=>{this.bulkLoad>0||this.applyChildArrayEvents(o);},onAttributeEvent:o=>{this.bulkLoad>0||this.applyAttributeMapEvent(o);},onBindingEvent:o=>{this.bulkLoad>0||this.applyBindingMapEvent(o);},onRelationshipChange:()=>{this.relationshipCountCache=-1;},onPartChange:()=>{this.partCountCache=-1;}});}doc;schema;limits;parentIndex=new Map;history=new Yo;contested=new Set;structureVersion=0;reparented=new Set;listings=new Map;childrenSnapshot=new Map;adoption;inline;splitSiblings=new To(e=>this.schema.nodes.get(e),e=>this.inline.textOf(e),e=>this.childrenSnapshot.get(e));stopMarks;stopKeepingMarkers;markListeners=new Set;attributesByNode=new Map;bindingsByNode=new Map;splitDedup;splitTextSources;bulkLoad=0;unobservedWrites=0;nodeCountCache=-1;pendingNodeAdds=0;relationshipCountCache=-1;partCountCache=-1;stopObserving;destroy(){this.stopObserving(),this.stopMarks(),this.stopKeepingMarkers();}beginBulkLoad(){this.bulkLoad+=1;}endBulkLoad(){this.bulkLoad=Math.max(0,this.bulkLoad-1),this.bulkLoad===0&&this.rebuildDerivedIndexes();}trackedTypes(){return [this.schema.meta,this.schema.nodes,this.schema.parts,this.schema.relationships,this.schema.overrides,this.schema.defaults,this.schema.binaries,this.schema.attributes,this.schema.bindings,this.doc.getMap(Gr),this.doc.getMap(Zr)]}undoDeleteFilter(){let e=Fd(this.schema.nodes,this.schema);return n=>!Mc(this.schema,n)&&e(n)}encodeSnapshot(){return z.encodeStateAsUpdate(this.doc)}encodeUpdate(e){return z.encodeStateAsUpdate(this.doc,e)}partEntries(){return Oc(this.schema.parts)}partCount(){return this.partCountCache<0&&(this.partCountCache=this.partEntries().length),this.partCountCache}relationshipCount(){return this.relationshipCountCache<0&&(this.relationshipCountCache=this.relationships().length),this.relationshipCountCache}mainDocumentPart(){return la(this.schema.meta.get("mainDocumentPart"))}record(e){if(O(e))return null;let n=this.schema.nodes.get(e);if(!_(n))return null;if(Wt(n)){let o=n.get(Pe),r=o instanceof z.Text?o.toString():"";return {logicalId:e,kind:"textValue",value:r}}return sa(e,n,this.schema,[...this.attributesByNode.get(e)?.values()??[]],[...this.bindingsByNode.get(e)?.values()??[]])}parentOf(e){return this.parentIndex.get(e)??this.inline.owner(e)}identityMeta(e){let n=this.schema.nodes.get(e);if(!n)return null;let o=this.record(e),r=o&&$(o)?o.attributes:[];return {logicalId:e,yjsItemKey:aa(n),wordFacingIds:_s(r)}}isTombstoned(e){return Ae(this.schema.nodes.get(e))}replacedByOf(e){return qn(this.schema.nodes.get(e))}adoptedChildren(e){return this.adoption.adoptees.get(e)??[]}adoptionIndex(){return this.adoption.adoptees}hasNamespace(e){return this.schema.namespaces.get(Lt(e))===e}noteWrite(){this.unobservedWrites+=1;}hasUnobservedWrites(){return this.unobservedWrites>0}listingParents(e){return [...this.listings.get(e)??[]]}allLogicalIds(){return [...this.schema.nodes.keys()].filter(Pr)}nodeCount(){return this.nodeCountCache<0&&(this.nodeCountCache=this.schema.nodes.size),this.nodeCountCache+this.pendingNodeAdds}nodeShape(e){return O(e)?null:ra(this.schema.nodes,e)}kindOf(e){return O(e)?null:ia(this.schema.nodes,e)}noteNodeWrite(e){this.schema.nodes.has(e)||(this.pendingNodeAdds+=1);}putElement(e){this.noteNodeWrite(e.logicalId);let n=zt(this.schema.namespaces,e.namespaceUri,this.limits.maxStringLength);this.schema.nodes.set(e.logicalId,Hs({logicalId:e.logicalId,kind:e.kind,namespaceUri:e.namespaceUri,namespaceId:n,localName:e.localName,prefix:e.prefix}));for(let o of e.attributes)ss(this.schema,this.limits.maxStringLength,e.logicalId,o,o.value);for(let o of e.bindings)as(this.schema,this.limits.maxStringLength,e.logicalId,o.prefix,o.namespaceUri);}updateElementShell(e,n){let o=this.require(e),r=zt(this.schema.namespaces,n.namespaceUri,this.limits.maxStringLength);o.set(Vn,Lr(n.kind,r,n.localName,n.prefix??""));}putText(e,n){this.noteNodeWrite(e),this.schema.nodes.set(e,Hn(n));}spliceText(e,n,o,r){let i=this.splitTextSources.range(e),s=Oo(this.schema.nodes,this.splitTextSources,e,i,n,r),a=i?.text??this.textOf(e),l=(i?.start??0)+n;i===null&&this.splitTextSources.isPlain(e)?(r.length>0&&a.insert(l,r),o>0&&a.delete(l+r.length,o)):(o>0&&a.delete(l,o),r.length>0&&a.insert(l,r)),s?.();}setAttribute(e,n,o){if(o===null){bc(this.schema,e,n.namespaceUri,n.localName);return}ss(this.schema,this.limits.maxStringLength,e,n,o);}setNamespaceBinding(e,n,o){if(o===null){Ic(this.schema,e,n);return}as(this.schema,this.limits.maxStringLength,e,n,o);}spliceChildren(e,n,o,r){let i=this.childArray(e);o>0&&i.delete(n,o),r.length>0&&i.insert(n,[...r]);}moveNode(e,n,o){this.unlinkFromAllParents(e);let r=this.childArray(n);r.insert(Math.max(0,Math.min(o,r.length)),[e]);}tombstone(e,n){this.unlinkFromAllParents(e);let o=this.require(e);o.set(me,true),n&&o.set(ue,n);}recordRunSplit(e,n,o){this.splitDedup.record(e,n,o);}splitOriginOf(e){return In(this.schema.nodes.get(e))}splitLineageOf(e){return Et(this.schema.nodes.get(e))}replacementLoserRuns(){return this.hasUnobservedWrites()&&this.splitDedup.invalidate(),this.splitDedup.loserRuns({isPresent:e=>fc(this,e)})}splitTextRange(e){return this.splitTextSources.range(e)}splitTextPending(e){return this.splitTextSources.isPending(e)}projectedTextValue(e){return this.splitTextSources.value(e)}registerSplitText(e,n,o,r){this.splitTextSources.register(e,n,o,r);}normalizeRestoredSplitTextAnchors(){this.splitTextSources.normalizeRestoredAnchors();}concurrentSplitTextOverlays(){return this.splitTextSources.overlays()}unlistChildren(e,n){let o=this.schema.nodes.get(e);Rc(o?ie(o):null,n);}putXmlPart(e){this.partCountCache=-1,this.schema.parts.set(e.name,Xs(e.id,e.rootLogicalId,e.contentType));}deleteXmlPart(e){this.partCountCache=-1,this.schema.parts.delete(e);}putRelationship(e){if(O(e.ownerPart)||O(e.id))return;this.relationshipCountCache=-1;let n=new z.Map;n.set(e.id,Gs(e)),this.schema.relationships.set(os(e.ownerPart,e.id),n);}deleteRelationship(e,n){this.relationshipCountCache=-1,this.schema.relationships.delete(os(e,n)),this.schema.relationships.get(e)?.delete(n);}putContentTypeOverride(e,n){this.schema.overrides.set(partNameKey(e),n);}deleteContentTypeOverride(e){this.schema.overrides.delete(partNameKey(e));}putContentTypeDefault(e,n){this.schema.defaults.set(e,n);}putBinary(e){this.schema.binaries.set(e.storageKey,qs(e));}deleteBinary(e){this.schema.binaries.delete(e);}relationships(){return hc(this.schema.relationships)}contentTypeOverrides(){return Ec(this.schema.overrides)}contentTypeDefaults(){return Cc(this.schema.defaults)}binaries(){return Tc(this.schema.binaries)}hasNode(e){return this.schema.nodes.has(e)}showsAsChild(e){let n=this.schema.nodes.get(e);return n===void 0||Ae(n)?false:!(Wt(n)&&this.splitTextPending(e))}observeDirty(e){let n=uc(this.schema,e),o=r=>e({logicalIds:r,membershipChanged:false,packageChanged:false});return this.markListeners.add(o),()=>{n(),this.markListeners.delete(o);}}rebuildDerivedIndexes(){this.unobservedWrites=0,this.nodeCountCache=-1,this.pendingNodeAdds=0,this.relationshipCountCache=-1,this.partCountCache=-1,this.parentIndex=new Map,this.listings=new Map,this.childrenSnapshot=new Map,this.adoption.reset(),this.attributesByNode=new Map,this.bindingsByNode=new Map,this.splitDedup.reset(),this.splitTextSources.reset(),this.schema.nodes.forEach((n,o)=>{if(!Pr(o))return;let r=ie(n);if(!r)return;let i=r.toArray();this.childrenSnapshot.set(o,i);for(let s of i)ls(this.listingIndex(),s,o);}),this.schema.nodes.forEach((n,o)=>{Ae(n)&&this.adoption.sync(G(o)),this.splitDedup.indexExisting(G(o));}),vc(this.schema,this.attributesByNode,this.bindingsByNode),is(this.placementContext(),null),this.contested=new Set;for(let[n,o]of this.listings)o.size>1&&this.contested.add(n);let e=new Set;for(let n of this.listings.keys())this.parentIndex.has(n)||e.add(n);e.size>0&&this.resolveParents(e),this.inline.rebuild();}assertNoParentFields(){da(this.schema.nodes);}applyChildArrayEvents(e){this.unobservedWrites=0,this.pendingNodeAdds=0;let n=new Set,o=false;for(let r of e){if(!(r.target instanceof z.Text)&&(r.path.length===0||r.target instanceof z.Array||r.target instanceof z.Map&&[...r.changes.keys.keys()].some(i=>["deleted","replacedBy","splitFrom","splitLineage","children"].includes(String(i))))&&this.splitDedup.invalidate(),r.path.length>0&&this.splitTextSources.noteChanged(G(r.path[0])),r.target instanceof z.Text&&r.path[1]===ae){this.inline.paragraphChanged(G(r.path[0]));continue}if(r.target instanceof z.Map&&r.path.length===1&&(r.changes.keys.has(ae)||r.changes.keys.has(me))&&this.inline.paragraphChanged(G(r.path[0])),r.path.length===0&&r.target instanceof z.Map){o=true;for(let[i,s]of r.changes.keys)if(this.nodeCountCache>=0&&s.action!=="update"&&(this.nodeCountCache+=s.action==="add"?1:-1),!O(String(i))){if(s.action==="delete"){this.inline.paragraphChanged(G(i));continue}this.splitDedup.indexExisting(G(i)),this.splitTextSources.noteChanged(G(i));for(let a of this.syncChildListings(G(i)))n.add(a);this.inline.paragraphChanged(G(i)),this.inline.recordArrived(G(i)),this.isTombstoned(G(i))&&this.adoption.sync(G(i)),this.adoption.recomputeListerSurvivors(G(i));}continue}if(r.target instanceof z.Map&&r.path.length===1){let i=G(r.path[0]),s=r.changes.keys;if(s.has(St)&&this.history.noteMarkChanged(i),(s.has("splitFrom")||s.has("splitLineage"))&&this.splitDedup.indexExisting(i),s.has(ct))for(let a of this.listings.get(i)??[])this.splitSiblings.forget(a);}if(r.target instanceof z.Array&&r.path.length>0){o=true;let i=G(r.path[0]);for(let s of this.syncChildListings(i,true))n.add(s);this.isTombstoned(i)&&this.adoption.sync(i);continue}if(r.target instanceof z.Map&&r.path.length===1&&(r.changes.keys.has(me)||r.changes.keys.has(ue))){o=true;let i=G(r.path[0]);this.adoption.sync(i),this.adoption.recomputeListerSurvivors(i);for(let s of this.childrenSnapshot.get(i)??[])n.add(s);}}if(o)for(let r of this.contested)n.add(r);n.size>0&&this.resolveParents(n),o&&(this.structureVersion+=1,this.inline.orderChanged());}takeUnlisted(){return this.history.takeUnlisted(e=>this.parentIndex.has(e))}takeReparented(){let e=[...this.reparented];return this.reparented.clear(),e}applyAttributeMapEvent(e){this.unobservedWrites=0,wc(this.schema,this.attributesByNode,e);}applyBindingMapEvent(e){this.unobservedWrites=0,kc(this.schema,this.bindingsByNode,e);}syncChildListings(e,n=false){n&&this.splitSiblings.forget(e);let o=this.schema.nodes.get(e),r=o?ie(o)?.toArray()??[]:[];return Lc(this.listingIndex(),e,r)}listingIndex(){return {listings:this.listings,childrenSnapshot:this.childrenSnapshot}}resolveParents(e){let n=new Map;for(let o of e)n.set(o,this.parentIndex.get(o));this.placeParents(e);for(let[o,r]of n){(this.listings.get(o)?.size??0)>1?this.contested.add(o):this.contested.delete(o);let i=this.parentIndex.get(o);i!==r&&(i===void 0!=(r===void 0)&&(this.inline.listingChanged(o),i===void 0&&this.history.noteUnlisted(o)),r!==void 0&&this.reparented.add(r),i!==void 0&&this.reparented.add(i));}}placeParents(e){mc(this.placementContext(),e);}placementContext(){return {nodes:this.schema.nodes,parentIndex:this.parentIndex,listings:this.listings,childrenSnapshot:this.childrenSnapshot,partRoots:this.partEntries().map(e=>e.rootLogicalId)}}unlinkFromAllParents(e){let n=[...this.listings.get(e)??[]];if(n.length===0){this.schema.nodes.forEach(o=>{let r=ie(o);r&&this.removeFromArray(r,e);});return}for(let o of n){let r=this.schema.nodes.get(o),i=r?ie(r):null;i&&this.removeFromArray(i,e);}}removeFromArray(e,n){for(let o=e.length-1;o>=0;o-=1)e.get(o)===n&&e.delete(o,1);}textOf(e){let n=this.require(e).get(Pe);if(!(n instanceof z.Text))throw new Error(`no text at ${e}`);return n}childArray(e){let n=this.require(e).get(xt);if(!(n instanceof z.Array))throw new Error(`no children at ${e}`);return n}require(e){let n=this.schema.nodes.get(e);if(!n)throw new Error(`registry node ${e} missing`);return n}};var jo=class{blobs=new Map;get(e){let n=this.blobs.get(e);return n?n.slice():null}put(e,n){this.blobs.set(e,n.slice());}};async function Rm(t){let e=await globalThis.crypto.subtle.digest("SHA-256",t.slice().buffer);return `sha256:${[...new Uint8Array(e)].map(n=>n.toString(16).padStart(2,"0")).join("")}`}function Ac(t){let e=t.binaryPart;return typeof e=="function"?e:null}function Dc(t,e){let n=[];for(let r of t)r.kind==="putBinary"&&n.push(r.descriptor);if(n.length===0)return null;if(!e)return {ok:false,failure:{code:"blob-read",detail:"binary-part-reader"}};let o=[];for(let r of n){let i=e(r.storageKey);if(!i)return {ok:false,failure:{code:"missing-local-blob",detail:r.storageKey}};o.push({digest:r.digest,bytes:i});}return {ok:true,payloads:o}}function Nc(t,e){for(let n of e)t.put(n.digest,n.bytes);}function Em(t){return t.attributes.map(e=>({namespaceUri:e.namespaceUri,localName:e.localName,prefix:e.prefix,value:e.value}))}function Cm(t){return t.namespaceBindings.map(e=>({prefix:e.prefix,namespaceUri:e.namespaceUri}))}function zo(t,e,n,o,r){if(o>t.limits.maxTreeDepth)return "tree-too-deep";if(O(e.id))return "prototype-key";if(r.nodes+=1,r.nodes>t.limits.maxNodes)return "too-many-nodes";if(e.kind==="textValue"){if(e.value.length>t.limits.maxTextLength)return "text-too-long";t.putText(U(e),e.value);}else {if(e.attributes.length>t.limits.maxAttributes)return "too-many-attributes";if(e.children.length>t.limits.maxChildren)return "too-many-children";if(Re(e.namespaceUri,t.limits.maxStringLength))return "invalid-string";for(let i of e.attributes){if(O(i.localName))return "prototype-key";if(Re(i.namespaceUri,t.limits.maxStringLength))return "invalid-string"}for(let i of e.namespaceBindings){if(O(i.prefix))return "prototype-key";if(Re(i.namespaceUri,t.limits.maxStringLength))return "invalid-string"}if(t.putElement({logicalId:U(e),kind:e.kind,namespaceUri:e.namespaceUri,localName:e.localName,prefix:e.prefix,attributes:Em(e),bindings:Cm(e)}),e.kind==="paragraph"){let i=Tm(t,e,o,r);if(i)return i}else for(let i of e.children){let s=zo(t,i,U(e),o+1,r);if(s)return s}}return n&&t.childArray(n).push([U(e)]),null}function Tm(t,e,n,o){let r=xn(e);for(let a of r.shell.children){let l=zo(t,a,U(e),n+1,o);if(l)return l}let i=0;for(let a of r.items){if(i+=1,a.kind!=="embed")continue;let l=zo(t,a.node,null,n+1,o);if(l)return l}if(i>t.limits.maxTextLength)return "text-too-long";let s=t.schema.nodes.get(e.id);if(!s)return null;try{ho(s,Ma(r.items,e.id,t.limits));}catch(a){if(a instanceof Be)return a.code;throw a}return null}async function Mm(t){let e=[],n=[];for(let[o,r]of t.partBytes){if(t.parts.has(o))continue;let s=t.contentTypes.overrides.get(o)??"application/octet-stream",a=Ie(o);if(a)return {ok:false,code:a};if(r.byteLength>bt.maxBlobBytes)return {ok:false,code:"blob-too-large"};let l=await Rm(r);n.push({digest:l,bytes:r}),e.push({digest:l,size:r.byteLength,mediaType:s,storageKey:o});}return {ok:true,descriptors:e,payloads:n}}async function $o(t,e,n=new jo){if(e.parts.size>t.limits.maxParts)return {ok:false,code:"too-many-parts"};let o=await Mm(e);if(!o.ok)return o;let r=null;t.beginBulkLoad();try{t.doc.transact(()=>{for(let a of o.payloads)n.put(a.digest,a.bytes);let i={nodes:0};for(let[a,l]of e.parts){let d=Ie(a);if(d){r=d;return}if(Re(l.contentType,t.limits.maxMediaTypeLength)){r="invalid-string";return}let c=zo(t,l.root,null,0,i);if(c){r=c;return}t.putXmlPart({name:a,id:l.id,rootLogicalId:U(l.root),contentType:l.contentType});}let s=0;for(let a of e.relationships.values())for(let l of a){if(s+=1,s>t.limits.maxRelationships){r="too-many-relationships";return}if(l.ownerPart!=="/"){let d=Ie(l.ownerPart);if(d){r=d;return}}if(O(l.id)){r="prototype-key";return}t.putRelationship({ownerPart:l.ownerPart,id:l.id,type:l.type,rawTarget:l.rawTarget,targetMode:l.targetMode,order:l.order});}for(let[a,l]of e.contentTypes.defaults){if(O(a)){r="prototype-key";return}t.putContentTypeDefault(a,l);}for(let[a,l]of e.contentTypes.overrides){let d=Ie(a);if(d){r=d;return}t.putContentTypeOverride(a,l);}for(let a of o.descriptors)t.putBinary(a);Qs(t.schema.meta),t.schema.meta.set("mainDocumentPart",e.mainDocumentPart);},$s);}finally{t.endBulkLoad();}return r?{ok:false,code:r}:{ok:true}}function Fe(t,e){return t.attributes.find(n=>n.localName===e)?.value}function fs(t){return t.kind==="textValue"?t.id:Fe(t,"id")??t.id}function Bn(t,e){if(t.length===e.length&&t.every((s,a)=>s===e[a]))return t;let n=0,o=Math.min(t.length,e.length);for(;n<o&&t[n]===e[n];)n+=1;let r=t.length,i=e.length;for(;r>n&&i>n&&t[r-1]===e[i-1];)r-=1,i-=1;return Object.freeze([...t.slice(0,n),...e.slice(n,i),...t.slice(r)])}function Bc(t,e){let n=t.root;if(n.children.length===e.length&&n.children.every((r,i)=>r===e[i]))return t;let o=Object.freeze(qe(n,Bn(n.children,e)));return Object.freeze({...t,root:o})}function Pm(t){if(t.namespaceUri===XML_NAMESPACE_URI&&t.localName==="space"){let e=t.value==="preserve"?"preserve":"default";return Object.freeze({kind:"xmlSpace",namespaceUri:XML_NAMESPACE_URI,localName:"space",prefix:"xml",value:e})}return t.namespaceUri===WML_NAMESPACE_URI&&t.localName==="val"?Object.freeze({kind:"wmlVal",namespaceUri:WML_NAMESPACE_URI,localName:"val",prefix:t.prefix,value:t.value}):Object.freeze({kind:"genericExtension",namespaceUri:t.namespaceUri,localName:t.localName,prefix:t.prefix,value:t.value})}function jc(t){}function $c(t,e){return Object.freeze({id:t,kind:"textValue",value:e})}function Bm(t,e){return t.namespaceBindings.length!==e.bindings.length?false:t.namespaceBindings.every((n,o)=>{let r=e.bindings[o];return n.prefix===r.prefix&&n.namespaceUri===r.namespaceUri})}function Um(t,e){return t.attributes.length!==e.attributes.length?false:t.attributes.every((n,o)=>{let r=e.attributes[o];return n.namespaceUri===r.namespaceUri&&n.localName===r.localName&&n.value===r.value&&n.prefix===(r.prefix?.length?r.prefix:void 0)})}function Wo(t,e,n){let o=n&&n.kind!=="textValue"?n:void 0;return Object.freeze(De({id:t.logicalId,kind:t.kind,namespaceUri:t.namespaceUri,localName:t.localName,...t.prefix===void 0?{}:{prefix:t.prefix},namespaceBindings:o&&Bm(o,t)?o.namespaceBindings:Object.freeze(t.bindings.map(r=>Object.freeze({...r}))),attributes:o&&Um(o,t)?o.attributes:Object.freeze(t.attributes.map(Pm)),children:e}))}function Wc(t,e){if(t.attributes.length!==e.attributes.length)return false;let n=new Map(e.attributes.map(o=>[`${o.namespaceUri}
|
|
6
|
+
import*as z from'yjs';import {XML_NAMESPACE_URI,WML_NAMESPACE_URI,partNameKey,readOoxmlPackage,refreshBoundContent,isStoryPart,normalizeParagraphIdentity,withPart,TreePackageStore,writeOoxmlPackage,writeOoxmlPackageKeepingRevisionIds,isDangerousKey,normalizePartName,relsPartNameFor,CUSTOM_XML_PROPS_TYPE,resolveInternalTarget,DATASTORE_NAMESPACE_URI,CUSTOM_XML_REL,CUSTOM_XML_PROPS_REL,resolveContentType,isRangeMarkerKind,buildRelationshipSet,resolveRelationship,ORIGIN_IDS,segmentsOf}from'@docx-editor.dev/core/store';import {reportHistoryGroup,isJournalOutsideUndo,historyGroupOfJournal,registerUndoHistoryPosition,mapOffsetAcrossText}from'@docx-editor.dev/core/collaboration/replication';import {createCollaborationStatusTracker,safeParticipantColor}from'@docx-editor.dev/core/collaboration';import {sha256FontBytes}from'@docx-editor.dev/core/layout';function Es(t,e){return {...t,projectedTarget:e}}function yt(t){return t.projectedTarget}function Cs(t){let e=n=>{n._needFormattingCleanup=false;};return t.on("afterTransaction",e),()=>t.off("afterTransaction",e)}function Ts(t,e,n){let o=t.doc;if(!o){t.delete(e,n);return}z.transact(o,r=>{let i=e,s=n;for(let a=t._start;a&&s>0;a=a.right){if(a.deleted||!a.countable)continue;if(i>=a.length){i-=a.length;continue}let l=a;i>0&&(l=z.getItemCleanStart(r,z.createID(a.id.client,a.id.clock+i)),i=0),s<l.length&&z.getItemCleanStart(r,z.createID(l.id.client,l.id.clock+s)),s-=l.length,l.delete(r),a=l;}}),t._searchMarker&&(t._searchMarker.length=0);}function Ms(t,e,n,o,r){let i=t.doc,s=new Set([...r].filter(a=>o[a]===null));if(!i||s.size===0||n<=0){t.format(e,n,{...o});return}z.transact(i,a=>{let l=[],d=0,c=false;for(let u=t._start;u;u=u.right){if(u.deleted)continue;if(u.countable){if(c||(d+=u.length,d>e+n))break;c=d===e+n;continue}let f=u.content;c&&f instanceof z.ContentFormat&&f.value===null&&s.has(f.key)&&l.push(u);}t.format(e,n,{...o});for(let u of l){if(!u.deleted)continue;let f=u.content.key,p=u.right,h=i.clientID;new z.Item(z.createID(h,z.getState(i.store,h)),u,u.lastId,p,p&&p.id,t,null,new z.ContentFormat(f,null)).integrate(a,0);}}),t._searchMarker&&(t._searchMarker.length=0);}function $n(t,e){let n=[...new Set(e)].filter(r=>r>=0).sort((r,i)=>r-i);if(n.length===0)return;let o=t.doc;if(!o){for(let r=n.length-1;r>=0;r-=1)t.delete(n[r],1);return}z.transact(o,r=>{let i=0,s=0;for(let a=t._start;a&&i<n.length;a=a.right){if(a.deleted||!a.countable)continue;let l=s+a.length,d=a,c=s;for(;i<n.length&&n[i]<l;){let u=n[i],f=u+1;for(i+=1;i<n.length&&n[i]===f&&f<l;)f+=1,i+=1;let p=d;u>c&&(p=z.getItemCleanStart(r,z.createID(d.id.client,d.id.clock+(u-c)))),f-u<p.length&&z.getItemCleanStart(r,z.createID(p.id.client,p.id.clock+(f-u))),p.delete(r),d=f<l?p.right:p,c=f;}a=d,s=l;}}),t._searchMarker&&(t._searchMarker.length=0);}function Ir(t,e){let n=[...new Set(e)].filter(s=>s>=0).sort((s,a)=>s-a),o=[],r=0,i=0;for(let s=t._start;s&&r<n.length;s=s.right){if(s.deleted||!s.countable)continue;let a=i+s.length;for(;r<n.length&&n[r]<a;r+=1)o.push({client:s.id.client,clock:s.id.clock+(n[r]-i)});i=a;}return o}function xr(t,e){if(e.length===0)return;let n=new Map;for(let{client:i,clock:s}of e){let a=n.get(i);a||n.set(i,a=new Set),a.add(s);}let o=[],r=0;for(let i=t._start;i;i=i.right){if(i.deleted||!i.countable)continue;let s=n.get(i.id.client);if(s)for(let a=0;a<i.length;a+=1)s.has(i.id.clock+a)&&o.push(r+a);r+=i.length;}$n(t,o);}function Ps(t,e){let n=0;for(let o=t._start;o;o=o.right)if(!(o.deleted||!o.countable)){if(n===e)return o.content instanceof z.ContentEmbed?o:null;if(n+=o.length,n>e)return null}return null}function As(t,e){let n=0;for(let o=t._start;o;o=o.right){if(o===e)return o.deleted?null:n;!o.deleted&&o.countable&&(n+=o.length);}return null}function Ds(t,e){let n=t.doc;!n||e.deleted||(z.transact(n,o=>e.delete(o)),t._searchMarker&&(t._searchMarker.length=0));}function be(t){return t._start}function H(t,e){let n;try{n=z.getItem(t.store,z.createID(e.client,e.clock));}catch{return null}return n instanceof z.Item?n:null}function*it(t,e){let n=t.clientID,o=z.getState(t.store,n);for(let r=e;r<o;){let i=z.getItem(t.store,z.createID(n,r));r=i.id.clock+i.length,i instanceof z.Item&&(yield i);}}function ef(t,e){for(let n of it(t,e))if(n.content instanceof z.ContentString)return n;return null}function Ft(t,e,n,o){let r=t.doc,i=r?z.getState(r.store,r.clientID):0;return typeof n=="string"?t.insert(e,n,{...o}):t.insertEmbed(e,n,{...o}),r?typeof n=="string"?ef(r,i):tf(r,i):null}function tf(t,e){for(let n of it(t,e))if(n.content instanceof z.ContentEmbed)return n;return null}function je(t){return t._item?.parentSub??null}function Me(t){return t instanceof z.AbstractType?t._item:null}function Kn(t){return t._item?.id??null}function _e(t,e){return t._map.get(e)}function Sr(t){return t.store.pendingStructs?.update??null}function Ve(t){return t.store.pendingStructs!==null||t.store.pendingDs!==null}function jt(t,e){for(let[n,o]of t.changed)if(n===e)return o;return null}function we(t){let e=t?.clients;if(!(e instanceof Map))return [];let n=[];for(let[o,r]of e)for(let i of r)n.push({client:o,clock:i.clock,length:i.len});return n}function U(t){return t.id}var nf=16,Ns=16,of=new Set(["paraId","textId","id","numId","bookmarkId"]);function Ys(t){let e="";for(let n of t)e+=n.toString(nf).padStart(2,"0");return e}function rf(t){let e=new Uint8Array(Ns);return globalThis.crypto.getRandomValues(e),Ys(e)}function wr(t){return /^[0-9a-f]{32}$/.test(t)}function sf(t,e){if(!wr(t))throw new Error("invalid replica identity");if(!Number.isSafeInteger(e)||e<0)throw new Error("invalid logical-id counter");return `lid:${t}:${e.toString(10)}`}function ke(t){let e=t.indexOf(":");if(e<=0)return null;let n=Number(t.slice(0,e)),o=Number(t.slice(e+1));return Number.isSafeInteger(n)&&Number.isSafeInteger(o)?{client:n,clock:o}:null}function zt(t,e){let n=t?ke(t):null,o=e?ke(e):null;return n!==null&&o!==null&&n.client===o.client&&n.clock+1===o.clock}function _s(t,e){return `yjs:${t}:${e}`}function ze(t){if(!t.startsWith("lid:"))return null;let e=t.slice(4,t.indexOf(":",4));return wr(e)?e:null}function Bs(t){let e=[];for(let n of t)of.has(n.localName)&&e.push(n.value);return e}var gn=class{replicaId;next=0;constructor(e){if(this.replicaId=e??rf(),!wr(this.replicaId))throw new Error("invalid replica identity")}take(){let e=sf(this.replicaId,this.next);return this.next+=1,e}get counter(){return this.next}};var bt=Object.freeze({maxNodes:2e5,maxTreeDepth:256,maxTextLength:1048576,maxAttributes:4096,maxChildren:1e5,maxParts:512,maxRelationships:1e4,maxBlobBytes:32*1024*1024,maxMediaTypeLength:256,maxStorageKeyLength:512,maxStringLength:4096}),lf=/^sha256:[0-9a-f]{64}$/;function Fs(t){return t?Object.freeze({...bt,...t}):bt}function E(t){return isDangerousKey(t)?"prototype-key":null}function Re(t,e){return typeof t!="string"||t.length>e?"invalid-string":isDangerousKey(t)?"prototype-key":null}function Ie(t){let e=E(t);if(e)return e;if(typeof t!="string"||t.length===0)return "unsafe-part-name";let n=normalizePartName(t);return !n.ok||n.partName!==t?"unsafe-part-name":null}function js(t){for(let e of Object.keys(t)){let n=E(e);if(n)return n}return !lf.test(t.digest)||!Number.isSafeInteger(t.size)||t.size<0?"invalid-blob-descriptor":t.size>bt.maxBlobBytes?"blob-too-large":Re(t.mediaType,bt.maxMediaTypeLength)||t.mediaType.length===0||Re(t.storageKey,bt.maxStorageKeyLength)||t.storageKey.length===0?"invalid-blob-descriptor":null}var df="https://www.docx-editor.dev/docs/2.x/pro/collaboration-versions",N=class extends Error{constructor(n,o){let r=n==="collaboration-format-mismatch"||n==="protocol-version-mismatch"||n==="schema-version-mismatch",i=o?`${n}: ${o}`:n;super(r?`${i}
|
|
7
|
+
Collaboration upgrade required. Save local changes and use a compatible app version, or upgrade the saved room. See ${df}#upgrade-saved-rooms`:i);this.code=n;this.detail=o;this.name="CollaborationSchemaError";}code;detail};var It=Object.freeze({protocolVersion:1,sharedSchemaVersion:5,repairVersion:5,canonicalModelVersion:1});function kr(t){let e=t!==null&&typeof t=="object"&&!Array.isArray(t)?t:{};for(let n of Object.keys(It)){let o=It[n],r=Object.hasOwn(e,n)?e[n]:void 0;if(r===o)continue;let i=r===void 0?"missing":typeof r=="number"&&Number.isSafeInteger(r)?String(r):"invalid";return {code:n==="protocolVersion"?"protocol-version-mismatch":"schema-version-mismatch",detail:`${n}: expected ${o}, received ${i}`}}return null}function Ab(t){let e=kr(t);if(e)throw new N(e.code,e.detail)}var cf=It.protocolVersion,uf=It.sharedSchemaVersion,ff=It.repairVersion,pf=It.canonicalModelVersion,vr="docx-package-meta-v1",mn="docx-package-nodes-v1",hf="docx-package-parts-v1",gf="docx-package-rels-v1",mf="docx-package-overrides-v1",yf="docx-package-defaults-v1",bf="docx-package-binaries-v1",If="docx-package-namespaces-v1",xf="docx-package-attributes-v1",Sf="docx-package-bindings-v1",Vn="s",Jn="b",Pe="t",xt="children",me="deleted",ue="replacedBy",St="undone",yn="splitFrom",wt="splitLineage";var ge="",Ws="-",$s=Object.freeze({kind:"docx-package-bootstrap"}),Lr=Object.freeze({kind:"docx-package-journal"});function kt(t){return t.kind==="textValue"}function W(t){return !kt(t)}var wf=Object.freeze(new Set(["missing-node","child-id-not-in-registry","cycle"])),kf=200;function vt(t){let e=new Map;for(let n of t)wf.has(n.code)&&e.set(n.code,(e.get(n.code)??0)+1);return e.size===0?null:[...e].sort(([n],[o])=>n<o?-1:n>o?1:0).map(([n,o])=>`${n}=${o}`).join(",").slice(0,kf)}function Ks(t){return {meta:t.getMap(vr),nodes:t.getMap(mn),parts:t.getMap(hf),relationships:t.getMap(gf),overrides:t.getMap(mf),defaults:t.getMap(yf),binaries:t.getMap(bf),namespaces:t.getMap(If),attributes:t.getMap(xf),bindings:t.getMap(Sf)}}var Vs=[["http://schemas.openxmlformats.org/wordprocessingml/2006/main","w"],["http://schemas.openxmlformats.org/officeDocument/2006/relationships","r"],["http://schemas.openxmlformats.org/package/2006/relationships","pr"],["http://schemas.openxmlformats.org/package/2006/content-types","ct"],["http://www.w3.org/XML/1998/namespace","xml"],["http://www.w3.org/2000/xmlns/","xmlns"],["http://schemas.openxmlformats.org/drawingml/2006/main","a"],["http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing","wp"],["http://schemas.openxmlformats.org/drawingml/2006/picture","pic"],["http://schemas.openxmlformats.org/officeDocument/2006/math","m"],["http://schemas.openxmlformats.org/markup-compatibility/2006","mc"],["http://schemas.microsoft.com/office/word/2010/wordml","w14"],["http://schemas.microsoft.com/office/word/2012/wordml","w15"],["http://schemas.microsoft.com/office/word/2015/wordml/symex","w16se"],["http://schemas.microsoft.com/office/word/2016/wordml/cid","w16cid"],["http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument","od"],["http://schemas.openxmlformats.org/officeDocument/2006/extended-properties","ep"],["http://schemas.openxmlformats.org/package/2006/metadata/core-properties","cp"],["http://purl.org/dc/elements/1.1/","dc"],["http://purl.org/dc/terms/","dcterms"],["http://www.w3.org/2001/XMLSchema-instance","xsi"],["http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes","vt"],["http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas","wpc"],["http://schemas.microsoft.com/office/word/2010/wordprocessingGroup","wpg"],["http://schemas.microsoft.com/office/word/2010/wordprocessingInk","wpi"],["http://schemas.microsoft.com/office/word/2010/wordprocessingShape","wps"],["http://schemas.openxmlformats.org/drawingml/2006/chart","c"],["http://schemas.openxmlformats.org/schemaLibrary/2006/main","sl"]],vf=new Map(Vs),Lf=new Map(Vs.map(([t,e])=>[e,t]));function Rf(t){let e=0xcbf29ce484222325n,n=0x100000001b3n;for(let o=0;o<t.length;o+=1)e^=BigInt(t.charCodeAt(o)),e=e*n&0xffffffffffffffffn;return e.toString(16).padStart(16,"0")}function Lt(t){return t.length===0?Ws:vf.get(t)??`n${Rf(t)}`}function Wt(t,e,n){let o=Lt(e);return e.length===0||E(o)||Re(e,n)||t.get(o)!==e&&t.set(o,e),o}function Rt(t,e){if(e===Ws||E(e))return "";let n=t.get(e);return typeof n=="string"?n:Lf.get(e)??""}function Rr(t,e,n,o){return `${t}${ge}${e}${ge}${n}${ge}${o}`}function Of(t){let e=t.split(ge);return {kind:e[0]||"generic",namespaceId:e[1]??"",localName:e[2]??"",prefix:e[3]??""}}function Ge(t){let e=t.has(Vn)?t.get(Vn):t.get(Jn);return Of(typeof e=="string"?e:"")}function Or(t,e,n){return `${t}${ge}${e}${ge}${n}`}function bn(t){let e=t.split(ge);if(e.length!==3)return null;let n=e[0],o=e[1],r=e[2];return n.length===0||r.length===0?null:{logicalId:n,namespaceId:o,localName:r}}function Er(t,e){return `${t}${ge}${e}`}function Ot(t){let e=t.split(ge);if(e.length!==2)return null;let n=e[0],o=e[1];return n.length===0?null:{logicalId:n,prefix:o}}function Js(t,e){return `${t}${ge}${e}`}function Hs(t){let e=t.indexOf(ge);return e<0?{prefix:"",value:t}:{prefix:t.slice(0,e),value:t.slice(e+1)}}function Xs(t){let e=new z.Map,n=Rr(t.kind,t.namespaceId,t.localName,t.prefix??"");e.set(Jn,n);let o=new z.Array;return t.childIds&&t.childIds.length>0&&o.push([...t.childIds]),e.set(xt,o),e}function Hn(t){let e=new z.Map;return e.set(Pe,new z.Text(t)),e}function Gs(t,e,n){let o=new z.Map;return o.set("id",t),o.set("rootId",e),o.set("contentType",n),o}function qs(t){let e=new z.Map;return e.set("ownerPart",t.ownerPart),e.set("id",t.id),e.set("type",t.type),e.set("rawTarget",t.rawTarget),e.set("targetMode",t.targetMode),e.set("order",t.order),e}function Qs(t){let e=new z.Map;return e.set("digest",t.digest),e.set("size",t.size),e.set("mediaType",t.mediaType),e.set("storageKey",t.storageKey),e}function Xn(t){return kr({protocolVersion:t.get("protocolVersion"),sharedSchemaVersion:t.get("sharedSchemaVersion"),repairVersion:t.get("repairVersion"),canonicalModelVersion:t.get("canonicalModelVersion")})}function Zs(t){t.set("protocolVersion",cf),t.set("sharedSchemaVersion",uf),t.set("repairVersion",ff),t.set("canonicalModelVersion",pf),t.set("initialized",true);}function ea(t,e){let n=_e(t,e);return n!==void 0&&n.deleted}function $t(t){return Sr(t)!==null}var zs=new WeakMap,Ef={origins:new Set,fields:new Set,listed:new Set};function Cr(t){let e=Sr(t);if(e===null)return Ef;let n=zs.get(e);if(n)return n;let o=new Set,r=new Set,i=new Set;try{for(let a of z.decodeUpdateV2(e).structs)if(a instanceof z.Item&&(a.origin&&o.add(`${a.origin.client}:${a.origin.clock}`),a.parent instanceof z.ID&&a.parentSub!==null&&r.add(`${a.parent.client}:${a.parent.clock}:${a.parentSub}`),a.parentSub===null&&a.content instanceof z.ContentAny))for(let l of a.content.arr)typeof l=="string"&&i.add(l);}catch{}let s={origins:o,fields:r,listed:i};return zs.set(e,s),s}function ta(t,e){if(t.has(e)||t.doc===null)return false;let n=Kn(t);return n!==null&&Cr(t.doc).fields.has(`${n.client}:${n.clock}:${e}`)}function na(t,e){return $t(t)&&Cr(t).listed.has(e)}function Tr(t,e){if(t.has(e)||t.doc===null||!$t(t.doc))return false;let n=_e(t,e);if(n===void 0||!n.deleted)return false;let o={client:n.id.client,clock:n.id.clock+Math.max(1,n.length)-1};return Cr(t.doc).origins.has(`${o.client}:${o.clock}`)}function _(t){return t instanceof z.Map}function ie(t){if(!_(t))return null;let e=t.get(xt);return e instanceof z.Array?e:null}function Kt(t){return _(t)&&t.get(Pe)instanceof z.Text}function Ae(t){return _(t)&&t.get(me)===true}function Gn(t){return _(t)&&t.get(St)===true}function qn(t){return Mr(t,ue)}function Mr(t,e){if(!_(t))return null;let n=t.get(e);return typeof n=="string"&&n.length>0?n:null}function oa(t,e){let n=o=>{let r=t.get(o);return _(r)?_e(r,ue)?.id??{client:0,clock:0}:{client:0,clock:0}};return [...e??[]].sort((o,r)=>{let i=n(o),s=n(r);return i.clock-s.clock||i.client-s.client||(o<r?-1:o>r?1:0)})}function In(t){return Mr(t,yn)}function Et(t){return Mr(t,wt)??In(t)}function ia(t,e){let n=t.get(e);if(!_(n))return null;if(Kt(n)){let o=n.get(Pe);return {isText:true,textLength:o instanceof z.Text?o.length:0,children:[]}}return {isText:false,textLength:0,children:ie(n)?.toArray()??[]}}function sa(t,e){let n=t.get(e);return _(n)?Kt(n)?"textValue":Ge(n).kind:null}function Qn(t,e){if(t.length!==e.length)return false;for(let n=0;n<t.length;n+=1)if(t[n]!==e[n])return false;return true}function aa(t,e,n,o,r){let i=Ge(e);return {logicalId:t,kind:i.kind,namespaceUri:Rt(n.namespaces,i.namespaceId),localName:i.localName,prefix:i.prefix.length>0?i.prefix:void 0,attributes:o,bindings:r,childIds:ie(e)?.toArray()??[]}}function la(t){let e=Kn(t);return e&&_s(e.client,e.clock)}function da(t){return typeof t=="string"?t:""}function G(t){return String(t)}function Ar(t){return !E(t)}function ca(t){t.forEach(e=>{if(_(e)&&(e.has("parent")||e.has("parentId")))throw new Error("registry record must not replicate a parent field")});}function De(t){return {id:t.id,kind:t.kind,namespaceUri:t.namespaceUri,localName:t.localName,namespaceBindings:t.namespaceBindings,attributes:t.attributes,children:t.children,...t.prefix===void 0?{}:{prefix:t.prefix}}}function qe(t,e,n=t.id){return {...t,id:n,children:e}}function ua(t){return t.kind!=="textValue"}function fa(t){return t.filter(ua)}function Vt(t){if(!ua(t))throw new Error(`expected an element, found text node ${t.id}`);return t}function Zn(t,e,n,o=[]){return Object.freeze(De({id:t,kind:e,namespaceUri:WML_NAMESPACE_URI,localName:n,prefix:"w",namespaceBindings:Object.freeze([]),attributes:Object.freeze([...o]),children:Object.freeze([])}))}function eo(t){return De({id:t,kind:"generic",namespaceUri:"",localName:"",namespaceBindings:[],attributes:[],children:[]})}function Jt(t,e){return {id:t,kind:"textValue",value:e}}function Ht(t){return t}var Mf=new Set(["t","delText","instrText","delInstrText"]),Pf=new Set(["hyperlink","ins","del","moveFrom","moveTo","sdt","sdtContent","fldSimple","smartTag","customXml","dir","bdo"]),Af=new Set(["sdtPr","sdtEndPr","smartTagPr","customXmlPr","fldData"]);function Dr(t,e){return t.kind!=="textValue"&&t.namespaceUri===WML_NAMESPACE_URI&&e.has(t.localName)}function Xt(t,e=[]){return qe(t,e)}function Df(t){return Dr(t,Mf)&&t.children.every(e=>e.kind==="textValue")}function xn(t){let e=[],n=[],o={run:null,runProperties:null,properties:[],text:null,textValueId:null,wrap:[]},r=(a,l)=>{let d=a.children.find(f=>f.kind==="runProperties"),c={...o,run:Xt(a),runProperties:d?Xt(d):null,properties:d?fa(d.children):[],wrap:l},u=0;for(let f of a.children)if(f!==d)if(u+=1,Df(f)){let p=f.children.map(g=>g.kind==="textValue"?g.value:"").join(""),h={...c,text:Xt(f),textValueId:f.children[0]?.id??null};p.length===0&&e.push({kind:"anchor",attributes:h});for(let g=0;g<p.length;g+=1)e.push({kind:"char",value:p[g],attributes:h});}else e.push({kind:"embed",node:f,attributes:c});u===0&&e.push({kind:"anchor",attributes:c});},i=(a,l)=>{for(let d of a)if(d.kind==="run")r(d,l);else if(Dr(d,Pf)){let c=d.children.filter(p=>Dr(p,Af)),u=[...l,Xt(d,c)],f=d.children.filter(p=>!c.includes(p));f.length===0&&e.push({kind:"anchor",attributes:{...o,wrap:u}}),i(f,u);}else e.push({kind:"embed",node:d,attributes:{...o,wrap:l}});},s=[];for(let a of t.children)a.kind==="paragraphProperties"?n.push(a):s.push(a);return i(s,[]),{shell:Xt(t,n),items:e}}function to(t){return {shell:t,children:[...t.children],openRun:null,openText:null}}function Nf(t){return t.runSignature!==void 0?t.runSignature:[t.run.id,t.runProperties?.id??"",...t.properties.map(e=>e.id)].join("")}function pa(t){let e=to(t.shell),n=[e],o=s=>{let a=s.openText;a&&(a.value.length>0&&a.builder.children.push(Jt(a.valueId,a.value)),s.openText=null);},r=s=>{s.openRun&&o(s.openRun.builder),s.openRun=null;};for(let s of t.items){let{wrap:a}=s.attributes,l=s.attributes.wrapSignatures,d=(h,g)=>l?h.signature===l[g]:h.shell.id===a[g].id,c=1;for(;c<n.length&&c-1<a.length&&d(n[c],c-1);)c+=1;for(;n.length>c;)r(n[n.length-1]),n.pop();for(let h=c-1;h<a.length;h+=1){let g=n[n.length-1];r(g);let y=to(a[h]);y.signature=l?.[h],g.children.push(y),n.push(y);}let u=n[n.length-1];if(!s.attributes.run){r(u),s.kind==="embed"&&u.children.push(s.node);continue}let f=Nf(s.attributes);if(u.openRun?.key!==f){r(u);let h=to(s.attributes.run);s.attributes.runProperties&&h.children.push(Xt(s.attributes.runProperties,s.attributes.properties)),u.children.push(h),u.openRun={key:f,builder:h};}let p=u.openRun.builder;if(s.kind==="embed"){o(p),p.children.push(s.node);continue}if(s.attributes.text){if(p.openText?.key!==s.attributes.text.id){o(p);let h=to(s.attributes.text);p.children.push(h),p.openText={key:s.attributes.text.id,builder:h,valueId:s.attributes.textValueId??`${s.attributes.text.id}/value`,value:""};}s.kind==="char"&&(p.openText.value+=s.value);}}for(;n.length>0;)r(n.pop());let i=s=>"shell"in s?Object.freeze(qe(s.shell,Object.freeze(s.children.map(i)))):s;return Vt(i(e))}var _r={kind:"run",localName:"r"},no={kind:"runProperties",localName:"rPr"},Br={kind:"text",localName:"t"},oo=32768,$e=24;function ha(t,e=0){if(e>$e)return 1/0;if(!se(t))return 1;let n=t.c,o=1;if(Array.isArray(n))for(let r of n)o+=ha(r,e+1);return o}var Be=class extends Error{constructor(n,o){super(`shared text value refused (${n}): ${o}`);this.code=n;this.detail=o;}code;detail};function Ur(t,e,n=0){if(n===0&&ha(t)>oo)return "too-many-nodes";if(n>$e)return "tree-too-deep";if(!se(t))return "invalid-string";for(let[r,i]of Object.entries(t))if(r==="v"&&typeof i=="string"){if(i.length>e.maxTextLength)return "text-too-long"}else if(typeof i=="string"&&i.length>e.maxStringLength)return "invalid-string";for(let r of ["a","b"]){let i=t[r];if(Array.isArray(i)){if(i.length>e.maxAttributes)return "too-many-attributes";for(let s of i)if(Array.isArray(s))for(let a of s){if(typeof a=="string"&&a.length>e.maxStringLength)return "invalid-string";if(typeof a=="string"&&E(a))return "prototype-key"}}}for(let r of ["l","k","p"]){let i=t[r];if(typeof i=="string"&&E(i))return "prototype-key"}let o=t.c;if(Array.isArray(o)){if(o.length>e.maxChildren)return "too-many-children";for(let r of o){let i=Ur(r,e,n+1);if(i!=="invalid-string"||Sn(r,e))return i}}return "invalid-string"}function Sn(t,e){return typeof t=="string"?t.length>e.maxStringLength:Array.isArray(t)?t.some(n=>Sn(n,e)):se(t)?Object.entries(t).some(([n,o])=>n==="v"?false:Sn(o,e)):false}var ga=new Map([["","#"],[XML_NAMESPACE_URI,"#x"],["http://schemas.microsoft.com/office/word/2010/wordml","#w14"],["http://schemas.microsoft.com/office/word/2012/wordml","#w15"],["http://schemas.openxmlformats.org/officeDocument/2006/relationships","#r"],["http://schemas.openxmlformats.org/officeDocument/2006/math","#m"],["http://schemas.openxmlformats.org/markup-compatibility/2006","#mc"]]),Yf=new Map([...ga].map(([t,e])=>[e,t]));function wn(t){return t===WML_NAMESPACE_URI?"":ga.get(t)??t}function kn(t){return t===""?WML_NAMESPACE_URI:t.startsWith("#")?Yf.get(t)??null:t}function ro(t){if(t===WML_NAMESPACE_URI)return "w";if(t===XML_NAMESPACE_URI)return "xml"}var Nr=/^(.*:)(\d{1,15})$/;function vn(t,e){if(t===e)return "=";if(e.length>0&&t.startsWith(e))return `^${t.slice(e.length)}`;let n=Nr.exec(t),o=Nr.exec(e);return n&&o&&n[1]===o[1]?`+${Number(n[2])-Number(o[2])}`:/^[=^+!]/.test(t)?`!${t}`:t}function qt(t,e,n){if(typeof t!="string"||t.length>n.maxStringLength)return null;let o;if(t==="=")o=e;else if(t.startsWith("^"))o=e+t.slice(1);else if(t.startsWith("+")){let r=Number(t.slice(1)),i=Nr.exec(e),s=i?Number(i[2])+r:NaN;o=i&&Number.isSafeInteger(s)&&s>=0?`${i[1]}${s}`:null;}else t.startsWith("!")?o=t.slice(1):o=t;return !o||o.length>n.maxStringLength||E(o)?null:o}function ma(t,e,n,o){return t===XML_NAMESPACE_URI&&e==="space"&&n==="xml"&&(o==="default"||o==="preserve")?"xmlSpace":t===WML_NAMESPACE_URI&&e==="val"?"wmlVal":"genericExtension"}function _f(t){let e=[t.localName,t.value],n=t.prefix,o=ma(t.namespaceUri,t.localName,n,t.value),r=[wn(t.namespaceUri),n===ro(t.namespaceUri)?"":n??null,t.kind===o?"":t.kind];for(;r.length>0&&r[r.length-1]==="";)r.pop();return [...e,...r]}function Qt(t,e,n){if(t.kind==="textValue")return {v:t.value};let o={},r=e?.localName;t.localName!==r&&(o.l=t.localName);let i=wn(t.namespaceUri);i!==""&&(o.n=i);let s=e&&t.localName===e.localName&&t.namespaceUri===WML_NAMESPACE_URI?e.kind:"generic";return t.kind!==s&&(o.k=t.kind),t.prefix!==ro(t.namespaceUri)&&(o.p=t.prefix??""),t.attributes.length>0&&(o.a=t.attributes.map(_f)),t.namespaceBindings.length>0&&(o.b=t.namespaceBindings.map(a=>[a.prefix,wn(a.namespaceUri)])),n&&t.children.length>0&&(o.c=t.children.map(a=>Qt(a,null,true))),o}function se(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function We(t,e){return typeof t=="string"&&t.length<=e.maxStringLength}function Bf(t,e){if(t===void 0)return Object.freeze([]);if(!Array.isArray(t)||t.length>e.maxAttributes)return null;let n=[];for(let o of t){if(!Array.isArray(o)||o.length<2||o.length>5)return null;let[r,i,s="",a="",l=""]=o;if(!We(r,e)||E(r)||!We(i,e)||!We(s,e))return null;let d=kn(s);if(d===null||a!==null&&!We(a,e))return null;let c=a===""?ro(d):a??void 0;if(c!==void 0&&E(c)||!We(l,e))return null;let u=l||ma(d,r,c,i);if(u!=="xmlSpace"&&u!=="wmlVal"&&u!=="genericExtension")return null;n.push(Object.freeze({kind:u,namespaceUri:d,localName:r,...c===void 0?{}:{prefix:c},value:i}));}return Object.freeze(n)}function Uf(t,e){if(t===void 0)return Object.freeze([]);if(!Array.isArray(t)||t.length>e.maxAttributes)return null;let n=[];for(let o of t){if(!Array.isArray(o)||o.length!==2)return null;let[r,i]=o;if(!We(r,e)||!We(i,e)||E(r))return null;let s=kn(i);if(s===null)return null;n.push(Object.freeze({prefix:r,namespaceUri:s}));}return Object.freeze(n)}function Zt(t,e,n,o,r,i){if(r.nodes+=1,r.nodes>oo||i>$e||!se(t))return null;if(typeof t.v=="string"&&t.l===void 0&&t.k===void 0)return t.v.length>o.maxTextLength?null:Object.freeze(Jt(e,t.v));let s=t.l??n?.localName;if(!We(s,o)||E(s))return null;let a=t.n??"";if(!We(a,o))return null;let l=kn(a);if(l===null)return null;let d=n&&s===n.localName&&l===WML_NAMESPACE_URI?n.kind:"generic",c=t.k??d;if(!We(c,o)||E(c))return null;let u=ro(l);if(t.p!==void 0){if(!We(t.p,o)||E(t.p))return null;u=t.p===""?void 0:t.p;}let f=Bf(t.a,o),p=Uf(t.b,o);if(!f||!p)return null;let h=t.c??[];if(!Array.isArray(h)||h.length>o.maxChildren)return null;let g=[];for(let y=0;y<h.length;y+=1){let w=Zt(h[y],`${e}~${y}`,null,o,r,i+1);if(!w)return null;g.push(w);}return Object.freeze(De({id:e,kind:c,namespaceUri:l,localName:s,namespaceBindings:p,attributes:f,children:Object.freeze(g),...u===void 0?{}:{prefix:u}}))}var de="v:",xe="b",so=512,Sa=2**31,Ff=new Set(["ins","del","moveFrom","moveTo"]);function io(t){return t.namespaceUri===WML_NAMESPACE_URI&&Ff.has(t.localName)}var jf=new Set(["hyperlink","fldSimple"]);function wa(t){return t.namespaceUri===WML_NAMESPACE_URI&&jf.has(t.localName)}function On(t,e,n,o={}){return {i:vn(t.id,e),...Qt(t,n,false),...o}}function Fr(t,e){return On(t,e,null,{c:t.children.map(n=>Qt(n,null,true))})}function ka(t,e,n){let o=[],r=new Set,i=t.map(a=>{let l=vn(a.id,e),d=r.has(l)?`!${a.id}`:l;return r.add(d),d}),s=0;return t.forEach((a,l)=>{if(!io(a)){let d=i.filter((u,f)=>f>l&&io(t[f])),c=wa(a)?i.filter((u,f)=>f<l&&io(t[f])):[];o.push({wrapper:a,inside:d,outside:c});return}s+=1,n[`${de}${i[l]}`]=JSON.stringify({e:{...Fr(a,e),i:i[l]},d:s});}),o}function jr(t,e,n,o="r"){let r=new Set,i=se(t)?t[o]:void 0;if(!Array.isArray(i))return r;for(let s of i.slice(0,$e)){let a=qt(s,n,e);a!==null&&r.add(a);}return r}function fe(t){if(typeof t=="string")try{return JSON.parse(t)}catch{return}}var zf=65536,ya=4096;function Ln(t){let e=new Set;if(typeof t!="string"||t.length>so*(ya+3))return e;let n=fe(t);if(!Array.isArray(n))return e;for(let o of n.slice(0,so))typeof o!="string"||o.length>ya||E(o)||e.add(`${de}${o}`);return e}function Wf(t){let e=Ln(t[xe]);return Object.keys(t).filter(n=>n.startsWith(de)&&!E(n)&&!e.has(n)).sort()}var $f=null;function Kf(t){return typeof t=="number"&&Number.isSafeInteger(t)&&t>=1&&t<=Sa}function Vf(t,e,n,o){if(typeof e!="string"||e.length>zf)return null;let r=fe(e);if(!se(r)||!se(r.e))return null;let i=r.d;if(!Kf(i))return null;let{i:s,...a}=r.e,l=qt(s,o,n);if(l===null)return null;let d=Zt(a,l,$f,n,{nodes:0},0);return !d||d.kind==="textValue"||!io(d)?null:{key:t,shell:d,encodedId:s,order:i,content:JSON.stringify(a),signature:JSON.stringify(a)}}function Rn(t,e,n){let o=[];for(let r of Wf(t)){let i=Vf(r,t[r],e,n);if(i&&o.push(i),o.length===$e)break}return o.sort(Jf)}function Jf(t,e){return t.order-e.order||(t.key<e.key?-1:t.key>e.key?1:0)}function va(t,e){let n=[...t];for(let o of e.slice(0,Math.max(0,$e-t.length))){let r=0,i=null;for(let a=n.length-1;a>=0;a-=1)if(n[a].inside?.has(o.shell.id)){r=a+1,i=n[a].shell.id;break}let s=n.some(a=>a.outside?.has(o.shell.id));for(let a=n.length-1;a>=r&&!s;a-=1)if(n[a].anchor===void 0&&wa(n[a].shell)){r=a+1,i=n[a].shell.id;break}for(;r<n.length&&n[r].anchor===i;)r+=1;n.some(a=>a.shell.id===o.shell.id)||n.splice(r,0,{shell:o.shell,signature:o.signature,anchor:i});}return n.map(({shell:o,signature:r})=>({shell:o,signature:r}))}function Hf(t,e){let n=new Set,o=[],r=new Map;for(let i of e){let s=t.find(a=>!n.has(a)&&a.content===i.content);s?(n.add(s),r.set(i.encodedId,s.encodedId)):o.push(i);}return {kept:n,added:o,renamed:r}}function zr(t){let e={};for(let n of Object.keys(t))!n.startsWith(de)&&n!==xe&&(e[n]=t[n]);return e}function ao(t){for(let e of Object.keys(t))if(e.startsWith(de)||e===xe)return true;return false}function Xf(t,e,n){if(t===e)return true;let o=fe(t??"[]"),r=fe(e??"[]");return !Array.isArray(o)||!Array.isArray(r)||o.length!==r.length?false:o.every((i,s)=>{let a=r[s];if(!se(i)||!se(a))return false;let{r:l,...d}=i,{r:c,...u}=a;if(JSON.stringify(d)!==JSON.stringify(u))return false;let f=p=>(Array.isArray(p)?p:[]).filter(h=>n.has(h)).sort();return JSON.stringify(f(l))===JSON.stringify(f(c))})}function Gf(t,e){let n=JSON.parse(t);return JSON.stringify({...n,d:e})}function qf(t,e){if(t===void 0||![...e].some(([o,r])=>o!==r))return t;let n=fe(t);return Array.isArray(n)?JSON.stringify(n.map(o=>se(o)&&Array.isArray(o.r)?{...o,r:o.r.map(r=>typeof r=="string"?e.get(r)??r:r)}:o)):t}function ba(t){return JSON.stringify([...t].map(e=>e.slice(de.length)).sort())}function Wr(t,e,n,o,r){if(!ao(t))return e;let i=Rn(t,o,r),s=Rn(e,o,r),a=zr(e);for(let y of Object.keys(t))y.startsWith(de)&&(a[y]=t[y]);let l=Ln(t[xe]),{kept:d,added:c,renamed:u}=Hf(i,s);for(let y of i)d.has(y)||(n?l.add(y.key):delete a[y.key]);let f=qf(a.w,u);f!==void 0&&(a.w=f);let p=new Set([...d].map(y=>y.encodedId).concat(c.map(y=>y.encodedId)));Xf(t.w,a.w,p)&&(t.w===void 0?delete a.w:a.w=t.w);let h=i.reduce((y,w)=>Math.max(y,w.order),0),g=false;for(let y of c)h=Math.min(h+1,Sa),a[y.key]=Gf(e[y.key],h),g=l.delete(y.key)||g;if(!n&&!g)return t[xe]!==void 0&&(a[xe]=t[xe]),a;if(l.size>so){let y=[...l].sort();for(let w of y.slice(so))l.delete(w),delete a[w];}if(l.size>0){let y=ba(l);a[xe]=t[xe]!==void 0&&ba(Ln(t[xe]))===y?t[xe]:y;}return a}var Ia=new WeakMap,Qf=4096;function Zf(t){let e=[];for(let n of Object.keys(t).sort())(n.startsWith(de)||n===xe)&&e.push(JSON.stringify([n,t[n]]));return e.join(",")}function $r(t,e,n){if(!ao(t))return "[]";let o=Ia.get(e);o||Ia.set(e,o=new Map);let r=`${n}\0${Zf(t)}`,i=o.get(r);if(i!==void 0)return i;let s=Rn(t,e,n),a=JSON.stringify(s.map(l=>l.content));return o.size>=Qf&&o.clear(),o.set(r,a),a}var ae="inline",Kr="r",en="rp",Ca="t",Ta="w",Vr="p:";function Jr(t){return t.kind!=="embed"?{a:1}:t.attributes.run?{n:t.node.id,r:1}:{n:t.node.id}}function np(t){let e=new Map;return t.map(n=>{let o=wn(n.namespaceUri),r=`${Vr}${o===""?"":`${o}|`}${n.localName}`,i=(e.get(r)??0)+1;return e.set(r,i),i===1?r:`${r}#${i}`})}function Ma(t){let e=t.slice(Vr.length).replace(/#\d+$/,""),n=e.indexOf("|"),o=kn(n<0?"":e.slice(0,n)),r=n<0?e:e.slice(n+1);return o===null||r.length===0?null:{namespaceUri:o,localName:r}}function Ct(t,e,n){let o={},r=t.run;if(r&&(o[Kr]=JSON.stringify(On(r,e,_r))),r&&t.runProperties){let s=np(t.properties);o[en]=JSON.stringify(On(t.runProperties,e,no,{o:s})),t.properties.forEach((a,l)=>{let d={kind:"generic",localName:a.localName};o[s[l]]=JSON.stringify(Qt(a,d,true));});}if(t.text){let s=t.text.id,a=t.textValueId??`${s}~v`,l=a===`${s}~v`?{}:{v:vn(a,s)};o[Ca]=JSON.stringify(On(t.text,e,Br,l));}if(t.wrap.length>$e)throw new Be("tree-too-deep",`${t.wrap.length} nested wrappers`);let i=ka(t.wrap,e,o);return i.length>0&&(o[Ta]=JSON.stringify(i.map(({wrapper:s,inside:a,outside:l})=>({...Fr(s,e),...a.length>0?{r:a}:{},...l.length>0?{x:l}:{}})))),Object.values(o).some(s=>op(s,n))&&ip(t,o,e,n),o}function op(t,e){let n=Math.min(e.maxStringLength,e.maxAttributes,e.maxChildren,e.maxTextLength,oo);if(t.length>n||rp.test(t))return true;let o=0;for(let r=0;r<t.length;r+=1){let i=t.charCodeAt(r);if(i===123||i===91){if(o+=1,o>2*$e+2)return true}else (i===125||i===93)&&(o-=1);}return false}var rp=/__proto__|constructor|prototype/;function ip(t,e,n,o){let r=Ne(e,o,n);if(!((e[en]===void 0||En(fe(e[en]),n,no,o)!==null)&&r.run===null==(t.run===null)&&r.properties.length===(t.run?t.properties.length:0)&&r.text===null==(t.text===null)&&r.wrap.length===t.wrap.length)){for(let[s,a]of Object.entries(e)){let l=fe(a),d=Array.isArray(l)?l:[l];for(let c of d){let u=Ur(c,o);if(u!=="invalid-string"||Sn(c,o))throw new Be(u,`${s} of an item in ${n}`)}}throw new Be("invalid-string",`an item in ${n}`)}}function Pa(t,e,n){let o=[],r=null,i=()=>{r&&o.push({insert:r.text,attributes:r.attributes}),r=null;};for(let s of t){let a=Ct(s.attributes,e,n);if(s.kind==="char"){let l=ve(a);r&&r.signature===l?r.text+=s.value:(i(),r={text:s.value,attributes:a,signature:l});continue}i(),o.push({insert:Jr(s),attributes:a});}return i(),o}function ve(t){if(!t)return "";let e=Object.keys(t).sort().map(n=>{let o=t[n];return typeof o=="string"?[n,o]:[n,null,typeof o]});return e.length===0?"":JSON.stringify(e)}function En(t,e,n,o,r=false){if(!se(t))return null;let i=qt(t.i,e,o);if(!i)return null;let{i:s,v:a,o:l,c:d,...c}=t,u=Zt(r?{...c,c:d}:c,i,n,o,{nodes:0},0);return !u||u.kind==="textValue"?null:{shell:u,data:t}}var La=["rStyle","rFonts","b","bCs","i","iCs","caps","smallCaps","strike","dstrike","outline","shadow","emboss","imprint","noProof","snapToGrid","vanish","webHidden","color","spacing","w","kern","position","sz","szCs","highlight","u","effect","bdr","shd","fitText","vertAlign","rtl","cs","em","lang","eastAsianLayout","specVanish","oMath","rPrChange"];function Ra(t){let e=Ma(t),n=e?.namespaceUri===WML_NAMESPACE_URI?La.indexOf(e.localName):-1;return n<0?La.length-1:n}function sp(t,e){return Ra(t)-Ra(e)||(t<e?-1:t>e?1:0)}function ap(t){return Zn(t,"runProperties","rPr")}var Oa=new WeakMap,lp=4096;function Ne(t,e,n){let o=JSON.stringify([n,ve(t)]),r=Oa.get(e);r||Oa.set(e,r=new Map);let i=r.get(o);if(i)return i;let s=dp(t??{},e,n);return r.size>=lp&&r.clear(),r.set(o,s),s}function dp(t,e,n){let o=En(fe(t[Kr]),n,_r,e),r=o?En(fe(t[en]),n,no,e):null,i=[],s=[],a=o?Object.keys(t).filter(I=>I.startsWith(Vr)).sort().slice(0,e.maxChildren):[],l={nodes:0},d=r?.shell??(o&&a.length>0?ap(`${o.shell.id}~rPr`):null);if(o&&d){let I=Array.isArray(r?.data.o)?r.data.o:[],b=a.every(v=>I.includes(v))?I.filter(v=>typeof v=="string"&&a.includes(v)):[...a].sort(sp);for(let v of b){let L=Ma(v);if(!L||E(v))continue;let m=Zt(fe(t[v]),`${d.id}~${v}`,{kind:"generic",localName:L.localName},e,l,0);m&&m.kind!=="textValue"&&(i.push(m),s.push(v));}}let c=fe(t[Ca]),u=En(c,n,Br,e),f=u?(se(c)&&c.v!==void 0?qt(c.v,u.shell.id,e):null)??`${u.shell.id}~v`:null,p=fe(t[Ta]),h=[];if(Array.isArray(p)&&p.length<=$e)for(let I of p){let b=En(I,n,null,e,true);if(!b)break;let{r:v,x:L,...m}=I;h.push({shell:b.shell,signature:JSON.stringify(m),inside:jr(I,e,n),outside:jr(I,e,n,"x")});}let g=va(h,Rn(t,e,n)),y=g.map(I=>I.shell),w=g.map(I=>I.signature),S=o?JSON.stringify([t[Kr],typeof t[en]=="string"?t[en]:"",...s.map(I=>[I,t[I]])]):void 0;return Object.freeze({run:o?.shell??null,runProperties:i.length>0||r?d:null,properties:Object.freeze(i),text:u?.shell??null,textValueId:f,wrap:Object.freeze(y),...S!==void 0?{runSignature:S}:{},wrapSignatures:Object.freeze(w)})}function Hr(t,e,n,o,r={}){let i=[],s=[],a=c=>{for(let u of c.entries){for(let f of u.slot?.before??[])a(f);u.item&&(i.push(u.item),s.push(u.placement),u.item.kind==="char"&&r.onCharacter?.(u.character??null));for(let f of u.slot?.after??[])a(f);}},l=(c,u=false)=>{let f=r.following?.at.get(c);for(let p of (u?f?.before:f?.after)??[])a(p);};for(let c of r.following?.atStart??[])a(c);let d=0;for(let c of t){let u=Ne(c.attributes,n,o);if(typeof c.insert=="string"){for(let h=0;h<c.insert.length;h+=1,d+=1)if(!r.hidden?.has(d)){if(l(d,true),i.push({kind:"char",value:c.insert[h],attributes:u}),s.push(void 0),r.onCharacter){let g=r.characters?.items[d];r.onCharacter(g===void 0?null:{item:g,identity:r.characters?.ids[d]??null});}l(d);}continue}if(d+=1,r.hidden?.has(d-1)||!se(c.insert))continue;if(c.insert.a===1){i.push({kind:"anchor",attributes:u}),s.push(void 0);continue}let f=c.insert.n;if(typeof f!="string"||E(f))continue;let p=e(f);p&&(i.push({kind:"embed",node:p,attributes:u}),s.push(c.insert.r===1));}for(let c of r.following?.atEnd??[])a(c);return pp(i,s,o,r.onRepair)}function Aa(t,e,n=o=>o){let o=new Set,r=(i,s)=>{if(e.has(i.id))return i;let l=s!==null&&i.id.startsWith(s.from)&&(i.id[s.from.length]==="~"||i.id[s.from.length]==="/")?`${s.to}${i.id.slice(s.from.length)}`:i===t?i.id:n(i.id);if(o.has(l)){let f=2;for(;o.has(`${l}~${f}`);)f+=1;l=`${l}~${f}`;}if(o.add(l),i.kind==="textValue")return l===i.id?i:Object.freeze({...i,id:l});let d=l===i.id?null:{from:i.id,to:l},c=i.children.map(f=>r(f,d));return d===null&&c.every((f,p)=>f===i.children[p])?i:Object.freeze(qe(i,Object.freeze(c),l))};return Vt(r(t,null))}function cp(t,e){return t.kind==="char"||t.kind==="embed"&&e===true}function Ea(t){return t.kind==="char"}function up(t){return Object.freeze({run:null,runProperties:null,properties:Object.freeze([]),text:null,textValueId:null,wrap:t.wrap,...t.wrapSignatures?{wrapSignatures:t.wrapSignatures}:{}})}function fp(t,e,n){return Object.freeze({...t,run:e?.run??n,runProperties:e?.runProperties??null,properties:e?.properties??Object.freeze([]),...e?.runSignature!==void 0?{runSignature:e.runSignature}:{}})}function pp(t,e,n,o){let r=(d,c)=>cp(d,e[c])&&!d.attributes.run||d.kind==="embed"&&e[c]===false&&d.attributes.run!==null||Ea(d)&&d.attributes.run!==null&&!d.attributes.text;if(!t.some(r))return t;o?.();let i=(d,c)=>{for(let u=1;u<t.length;u+=1){let f=t[d-u];if(f&&c(f,d-u))return f;let p=t[d+u];if(p&&c(p,d+u))return p;if(!f&&!p)break}return null},s=(d,c)=>d.attributes.run!==null&&!(d.kind==="embed"&&e[c]===false),a=Zn(`${n}~r`,"run","r"),l=[];return t.forEach((d,c)=>{if(!r(d,c)){l.push(d);return}let u=t[c-1];if(d.kind==="char"&&u?.kind==="char"&&gp(d.value)&&hp(u.value)){l.push({...d,attributes:l[l.length-1].attributes});return}let f=d.attributes;if(d.kind==="embed"&&e[c]===false){l.push({...d,attributes:up(f)});return}if(!f.run){let p=i(c,s);f=fp(f,p?.attributes??null,a);}if(Ea(d)&&!f.text){let p=f.run,h=i(c,g=>g.kind==="char"&&g.attributes.run?.id===p.id&&!!g.attributes.text);f=Object.freeze({...f,text:h?.attributes.text??Zn(`${p.id}~t`,"text","t",[Object.freeze({kind:"xmlSpace",namespaceUri:XML_NAMESPACE_URI,localName:"space",prefix:"xml",value:"preserve"})]),textValueId:h?.attributes.textValueId??null});}l.push({...d,attributes:f});}),l}function hp(t){let e=t.charCodeAt(0);return t.length===1&&e>=55296&&e<=56319}function gp(t){let e=t.charCodeAt(0);return t.length===1&&e>=56320&&e<=57343}var mp=8;function lo(t){let e=new Map;t.identities.ids.forEach((c,u)=>{c&&!t.hidden.has(u)&&!e.has(c)&&e.set(c,u);});let n=new Map;for(let c of t.incoming)c.identities.forEach((u,f)=>{u&&!n.has(u)&&n.set(u,{piece:c,index:f});});let o=new Map;for(let c of t.incoming){if(e.has(c.after))continue;let u=n.get(c.after);u&&u.piece!==c&&o.set(c,yp(c,u,t));}let r=c=>{let u=c;for(let f=0;f<=mp;f+=1){let p=o.get(u);if(!p)return true;u=p.piece;}return false};for(;;){let c=t.incoming.find(u=>o.has(u)&&!r(u));if(!c)break;o.delete(c);}let i=new Map,s=new Map,a=[],l=[],d=(c,u)=>{let f=c.get(u);return f||(f={before:[],after:[]},c.set(u,f)),f};for(let c of t.incoming){if(c.atStart){l.push(c);continue}let u=e.get(c.after),f=o.get(c),p=null;if(u!==void 0)p=d(i,u);else if(f){let h=s.get(f.piece);h||(h=new Map,s.set(f.piece,h)),p=d(h,f.index);}p?c.before?p.before.push(c):p.after.push(c):a.push(c);}return {atPosition:i,inside:s,atEnd:a,atStart:l}}function yp(t,e,n){if(t.before)return e;let{positions:o,items:r}=e.piece,{items:i,origins:s}=n.identities,a=r[e.index];if(a===void 0||i[o[e.index]]!==a)return e;let l=u=>zt(a,u),d=new Set,c=e.index;for(let u=c+1;u<o.length;u+=1){let f=r[u],p=o[u],h=i[p]===f?s[p]:null;if(!(h===a&&!l(f))&&!(h!==null&&d.has(h)))break;d.add(f),c=u;}return {piece:e.piece,index:c}}var qr="docx-text-deletions-v1",bp=/^d(\d{1,16}):(\d{1,16})$/,Ip=/^(\d{1,16}):(\d{1,16}):(\d{1,16})$/,Xr=4096,xp=1<<20;function co(t){let e=Number(t);return Number.isSafeInteger(e)?e:null}function Sp(t,e){let n=bp.exec(t);if(!n||typeof e!="string")return null;let o=co(n[1]);if(o===null)return null;let r=[];for(let i of e.split(";")){if(r.length>=Xr)return null;let s=Ip.exec(i);if(!s)return null;let a=co(s[1]),l=co(s[2]),d=co(s[3]);if(a===null||l===null||d===null||d<1||d>xp)return null;r.push({client:a,from:l,to:l+d});}return r.length===0?null:{client:o,runs:r}}var tn=class t{starts=[];ends=[];static of(e){let n=new t,o=[...e].sort((r,i)=>r.from-i.from);for(let{from:r,to:i}of o){let s=n.ends.length-1;s>=0&&r<=n.ends[s]?n.ends[s]=Math.max(n.ends[s],i):(n.starts.push(r),n.ends.push(i));}return n}add(e,n){let o=0,r=this.starts.length;for(;o<r;){let l=o+r>>1;this.ends[l]<e?o=l+1:r=l;}let i=o,s=e,a=n;for(;i<this.starts.length&&this.starts[i]<=n;)s=Math.min(s,this.starts[i]),a=Math.max(a,this.ends[i]),i+=1;this.starts.splice(o,i-o,s),this.ends.splice(o,i-o,a);}has(e){let n=0,o=this.starts.length-1;for(;n<=o;){let r=n+o>>1;if(this.starts[r]>e)o=r-1;else if(this.ends[r]<=e)n=r+1;else return true}return false}},Gr=class{constructor(e,n){this.doc=e;this.map=n;n.forEach((o,r)=>this.refresh(r,o));}doc;map;byKey=new Map;keysByClient=new Map;characters=new Map;stale=new Set;listeners=new Set;subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}isDeleted(e,n){return this.stale.has(e)&&(this.stale.delete(e),this.reindex(e)),this.characters.get(e)?.has(n)??false}record(e){let n=[];for(let o=0;o<e.length;o+=Xr){let r=e.slice(o,o+Xr).map(s=>`${s.client}:${s.from}:${s.to-s.from}`).join(";"),i=`d${this.doc.clientID}:${z.getState(this.doc.store,this.doc.clientID)}`;this.map.set(i,r),this.refresh(i,r),n.push(i);}return n}withdraw(e){let n=`d${this.doc.clientID}:`;for(let o of e)!o.startsWith(n)||!this.map.has(o)||this.map.delete(o);}refreshKeys(e){let n=[];for(let o of e){if(o===null)continue;let r=this.byKey.get(o)??[];this.refresh(o,this.map.get(o));let i=this.byKey.get(o)??[];for(let s of r)n.push(s);for(let s of i)n.push(s);}if(n.length!==0)for(let o of this.listeners)o(n);}refresh(e,n){let o=this.byKey.get(e);this.byKey.delete(e);let r=Sp(e,n),i=r?_e(this.map,e):void 0,s=r!==null&&(!i||i.id.client===r.client);if(s&&this.byKey.set(e,r.runs),o){let a=new Set(o.map(l=>l.client));for(let l of a)this.keysByClient.get(l)?.delete(e);s&&this.list(e,r.runs);for(let l of s?r.runs:[])a.add(l.client);for(let l of a)this.stale.add(l);}else if(s){this.list(e,r.runs);for(let a of r.runs){if(this.stale.has(a.client))continue;let l=this.characters.get(a.client);l||this.characters.set(a.client,l=new tn),l.add(a.from,a.to);}}}list(e,n){for(let o of n){let r=this.keysByClient.get(o.client);r||this.keysByClient.set(o.client,r=new Set),r.add(e);}}reindex(e){let n=this.keysByClient.get(e);if(!n||n.size===0){this.keysByClient.delete(e),this.characters.delete(e);return}let o=[];for(let r of n)for(let i of this.byKey.get(r)??[])i.client===e&&o.push(i);this.characters.set(e,tn.of(o));}},Da=new WeakMap;function Qe(t){let e=Da.get(t);if(e)return e;let n=t.getMap(qr),o=new Gr(t,n);return t.on("beforeObserverCalls",r=>{let i=jt(r,n);i&&o.refreshKeys(i);}),Da.set(t,o),e=o,e}function Ya(t){let e=t.flatMap(o=>ke(o)??[]).sort((o,r)=>o.client-r.client||o.clock-r.clock),n=[];for(let{client:o,clock:r}of e){let i=n[n.length-1];i&&i.client===o&&r<=i.to?i.to=Math.max(i.to,r+1):n.push({client:o,from:r,to:r+1});}return n}var ei="docx-text-decisions-v1",wp=/^a(\d{1,16}):(\d{1,16})$/,kp=/^(\d{1,16}):(\d{1,16}):(\d{1,16})$/,Qr=4096,vp=1<<20,Lp=4096;function uo(t){let e=Number(t);return Number.isSafeInteger(e)?e:null}function Rp(t,e){let n=wp.exec(t);if(!n||typeof e!="string")return null;let o=uo(n[1]);if(o===null)return null;let r=e.indexOf(`
|
|
8
|
+
`);if(r<0)return null;let i=e.slice(0,r);if(!i.startsWith(de)||i.length>Lp||E(i))return null;let s=[];for(let a of e.slice(r+1).split(";")){if(s.length>=Qr)return null;let l=kp.exec(a);if(!l)return null;let d=uo(l[1]),c=uo(l[2]),u=uo(l[3]);if(d===null||c===null||u===null||u<1||u>vp)return null;s.push({client:d,from:c,to:c+u});}return s.length===0?null:{client:o,revision:i,runs:s}}var Zr=class{constructor(e,n){this.doc=e;this.map=n;n.forEach((o,r)=>this.refresh(r,o));}doc;map;byKey=new Map;index=null;listeners=new Set;subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}names(e){return this.indexed().has(e)}get empty(){return this.byKey.size===0}decided(e,n,o){return this.indexed().get(e)?.get(n)?.has(o)??false}record(e,n){let o=[];for(let r=0;r<n.length;r+=Qr){let i=`${e}
|
|
9
|
+
${n.slice(r,r+Qr).map(a=>`${a.client}:${a.from}:${a.to-a.from}`).join(";")}`,s=`a${this.doc.clientID}:${z.getState(this.doc.store,this.doc.clientID)}`;this.map.set(s,i),this.refresh(s,i),o.push(s);}return o}refreshKeys(e){let n=[];for(let o of e)if(o!==null){for(let r of this.byKey.get(o)?.runs??[])n.push(r);this.refresh(o,this.map.get(o));for(let r of this.byKey.get(o)?.runs??[])n.push(r);}if(n.length!==0)for(let o of this.listeners)o(n);}refresh(e,n){let o=this.byKey.delete(e),r=Rp(e,n),i=r?_e(this.map,e):void 0,s=r!==null&&(!i||i.id.client===r.client);s&&this.byKey.set(e,r),(o||s)&&(this.index=null);}indexed(){if(this.index)return this.index;let e=new Map;for(let{revision:o,runs:r}of this.byKey.values()){let i=e.get(o);i||e.set(o,i=new Map);for(let s of r){let a=i.get(s.client);a||i.set(s.client,a=[]),a.push(s);}}let n=new Map;for(let[o,r]of e){let i=new Map;for(let[s,a]of r)i.set(s,tn.of(a));n.set(o,i);}return this.index=n,n}},_a=new WeakMap;function Cn(t){let e=_a.get(t);if(e)return e;let n=t.getMap(ei);e=new Zr(t,n);let o=e;return t.on("beforeObserverCalls",r=>{let i=jt(r,n);i&&o.refreshKeys(i);}),_a.set(t,e),e}function Ua(t,e,n,o){let r=new Set(Object.keys(e).filter(s=>s.startsWith(de)&&e[s]===null)),i=t.doc;if(i&&n&&r.size>0){let s=[];for(let{position:l}of o){let[d,c]=(n[l]??"").split(":").map(Number);if(!Number.isSafeInteger(d)||!Number.isSafeInteger(c)||d<0)continue;let u=s[s.length-1];u&&u.client===d&&u.to===c?s[s.length-1]={client:d,from:u.from,to:c+1}:s.push({client:d,from:c,to:c+1});}let a=Cn(i);if(s.length>0)for(let l of r)a.record(l,s);}Ms(t,o[0].position,o.length,e,r);}var Tn="s",Ka=256,Op=new Set(["del","moveFrom"]),Ep=/^\d{1,16}$/,fo=new Map,Cp=4096;function po(t){if(typeof t!="string"||!t.includes(`"${Tn}":`))return null;let e=fo.get(t);if(e!==void 0)return e;let n=null,o=fe(t),r=se(o)?o[Tn]:void 0;if(se(r)&&Object.keys(r).length<=Ka&&ti(o)){n=new Map;for(let[i,s]of Object.entries(r)){if(!Ep.test(i)||!Number.isSafeInteger(s)||s<0){n=null;break}n.set(Number(i),s);}}return fo.size>=Cp&&fo.clear(),fo.set(t,n),n}function ti(t){let e=typeof t=="string"?fe(t):t,n=se(e)?e.e:void 0;return se(n)&&n.n===void 0&&Op.has(n.l)}function Va(t,e){let n=null,o=null;for(let[r,i]of Object.entries(t)){if(!r.startsWith(de)||i===null||!ti(i))continue;let s=fe(i);if(s[Tn]===void 0){if(!o){let a=new Map;for(let{client:l,clock:d}of e)l<0||a.set(l,Math.max(a.get(l)??0,d+1));if(a.size===0||a.size>Ka)return {...t};o={};for(let l of [...a.keys()].sort((d,c)=>d-c))o[l]=a.get(l);}n??={...t},n[r]=JSON.stringify({...s,[Tn]:o});}}return n??{...t}}function Tt(t){let e=null,n=null;for(let[o,r]of Object.entries(t)){if(!o.startsWith(de)||po(r)===null||(n??=Ln(t[xe]),n.has(o)))continue;let{[Tn]:i,...s}=fe(r);e??={...t},e[o]=JSON.stringify(s);}return e??t}function Fa(t,e,n){let o=null;for(let r in t){if(!r.startsWith(de))continue;let i=po(t[r]);i&&n>=(i.get(e)??0)&&(o??=[]).push(r);}return o}function Tp(t,e,n,o){let r=o;for(let i in t){if(!i.startsWith(de))continue;let s=po(t[i])?.get(e)??0;s>n&&s<r&&(r=s);}return r}var ja="t",za={delText:{},delInstrText:{l:"instrText",k:"instrText"}};function Mp(t,e){let n={...t};for(let i of e)delete n[i];for(let i in n)if(i.startsWith(de)&&ti(n[i]))return n;let o=fe(n[ja]),r=se(o)&&typeof o.l=="string"&&Object.hasOwn(za,o.l)?za[o.l]:void 0;if(se(o)&&r&&o.n===void 0){let{l:i,k:s,...a}=o;n[ja]=JSON.stringify({...a,...r});}return n}function Wa(t,e,n,o){let r=null;for(let i of e)t.decided(i,n,o)&&(r??=[]).push(i);return r}function $a(t,e){return t?e?[...new Set([...t,...e])].sort():t:e}function Mt(t){return ni(t).ops}function ni(t){let e=false,n=[],o={},r=null,i=()=>r??={...o},s=false,a=t.doc?Cn(t.doc):null,l=a&&!a.empty?a:null,d=null,c=()=>{if(d)return d;d=[];for(let y in o)y.startsWith(de)&&l.names(y)&&d.push(y);return d},u=null,f=(y,w)=>{let S={insert:y};Object.keys(w).length>0&&(S.attributes=w),n.push(S),u=null;},p=new Map,h=y=>{e=true;let w=y.join(`
|
|
10
|
+
`),S=p.get(w);return S||p.set(w,S=Mp(i(),y)),S},g=(y,w)=>{let S=n.at(-1);S&&u===w?S.insert=S.insert+y:(f(y,w),u=w);};for(let y=be(t);y;y=y.right){if(y.deleted)continue;let w=y.content;if(w instanceof z.ContentFormat){w.value===null?delete o[w.key]:o[w.key]=w.value,po(w.value)!==null&&(s=true),r=null,d=null,p=new Map;continue}let{client:S,clock:I}=y.id,b=l&&c().length>0?l:null;if(w instanceof z.ContentString){let v=w.str;if(!s&&!b){g(v,i());continue}for(let L=0;L<v.length;){let m=s?Fa(i(),S,I+L):null,k=b?Wa(b,c(),S,I+L):null,O=b?L+1:Tp(i(),S,I+L,I+v.length)-I,P=$a(m,k);g(v.slice(L,O),P?h(P):i()),L=O;}continue}if(w instanceof z.ContentEmbed||w instanceof z.ContentType){let v=s?Fa(i(),S,I):null,L=b?Wa(b,c(),S,I):null,m=$a(v,L);f(w.getContent()[0],m?h(m):{...i()});}}return {ops:n,leftOut:e}}function Ap(t,e,n,o,r,i){let s=Mt(t);if(!r)return Hr(s,e,n,o);let a=r.shown(t);(a.hidden.size>0||a.incoming.length>0)&&r.noteDrift();let l=new Map;for(let h of a.incoming){let g=l.get(h.source)??new Set;for(let y of h.positions)g.add(y);l.set(h.source,g);}let d=new Map;for(let[h,g]of l)d.set(h,Dp(r.textOf(h),h,g,e,n));let c=lo(a),u=h=>{let g=d.get(h.source),y=c.inside.get(h),w=[];return h.positions.forEach((S,I)=>{let b=g.get(S),v=y?.get(I);if(!b&&!v)return;let L=h.items[I];w.push({item:b?.item,placement:b?.placement,...v?{slot:f(v)}:{},...L!==void 0?{character:{item:L,identity:h.identities[I]??null}}:{}});}),{entries:w}},f=h=>({before:h.before.map(u),after:h.after.map(u)}),p=new Map;for(let[h,g]of c.atPosition)p.set(h,f(g));return Hr(s,e,n,o,{hidden:a.hidden,following:{at:p,atEnd:c.atEnd.map(u),atStart:c.atStart.map(u)},onRepair:()=>r.noteDrift(),...i?{onCharacter:i,characters:{items:a.identities.items,ids:a.identities.ids}}:{}})}function Dp(t,e,n,o,r){let i=new Map;if(!t)return i;let s=0;for(let a of Mt(t)){let l=typeof a.insert=="string"?a.insert.length:1;if(typeof a.insert=="string"){let d=null;for(let c=0;c<l;c+=1)n.has(s+c)&&(d??=Ne(a.attributes,r,e),i.set(s+c,{item:{kind:"char",value:a.insert[c],attributes:d},placement:void 0}));}else if(n.has(s)){let d=a.insert,c=d?.n,u=typeof c=="string"&&!E(c)?o(c):null;u&&i.set(s,{item:{kind:"embed",node:u,attributes:Ne(a.attributes,r,e)},placement:d?.r===1});}s+=l;}return i}function Ze(t,e,n,o,r,i){let s=new Set,a=new Set,l=Ap(e,f=>{if(r&&!r.showsEmbed(f))return r.noteDrift(),null;let p=r?.lineageOf?.(f)??null;if(p!==null&&p!==f){if(a.has(p)||r.listed?.(p))return r.noteDrift(),null;a.add(p);}let h=n(f);return h&&s.add(f),h},o,t,r,i),d=De({id:t,kind:"paragraph",namespaceUri:WML_NAMESPACE_URI,localName:"p",namespaceBindings:[],attributes:[],children:[]}),c=pa({shell:d,items:l}),u=Aa(c,s,r?f=>r.shownId(f):void 0);return r&&u!==c&&r.noteDrift(),u.children}function ho(t,e){let n=new z.Text;t.set(ae,n);let o=0;for(let r of e)typeof r.insert=="string"?(n.insert(o,r.insert,{...r.attributes}),o+=r.insert.length):(n.insertEmbed(o,r.insert,{...r.attributes}),o+=1);return n}function Ha(t,e){if(t.length===0)return e;let n=new Map(t.map(o=>[o.id,o]));return e.map(o=>{let r=n.get(o.id);return r&&Xa(r,o)?r:o})}function Xa(t,e){return t===e?true:t.id!==e.id||t.kind!==e.kind?false:t.kind==="textValue"||e.kind==="textValue"?t.kind==="textValue"&&e.kind==="textValue"&&t.value===e.value:t.namespaceUri===e.namespaceUri&&t.localName===e.localName&&t.prefix===e.prefix&&oi(t.attributes,e.attributes,(n,o)=>n.kind===o.kind&&n.namespaceUri===o.namespaceUri&&n.localName===o.localName&&n.prefix===o.prefix&&n.value===o.value)&&oi(t.namespaceBindings,e.namespaceBindings,(n,o)=>n.prefix===o.prefix&&n.namespaceUri===o.namespaceUri)&&oi(t.children,e.children,Xa)}function oi(t,e,n){return t.length===e.length&&t.every((o,r)=>n(o,e[r]))}var qa=new Map(Object.entries({paragraph:["paragraphProperties"],run:["runProperties"],paragraphProperties:["runProperties"],table:["tableProperties","tableGrid"],anchoredDrawing:["drawingSimplePos","drawingPositionH","drawingPositionV","drawingExtent","drawingEffectExtent","drawingDocPr","drawingGraphicFramePr","drawingGraphic","drawingSizeRelH","drawingSizeRelV"],inlineDrawing:["drawingExtent","drawingEffectExtent","drawingDocPr","drawingGraphicFramePr","drawingGraphic"]})),Qa=new Set(["drawingWrapNone","drawingWrapSquare","drawingWrapTight","drawingWrapThrough","drawingWrapTopBottom"]),Za=new Map([["inlineDrawing",new Set(["drawingSimplePos","drawingPositionH","drawingPositionV","drawingSizeRelH","drawingSizeRelV",...Qa])]]),go="http://schemas.openxmlformats.org/drawingml/2006/main",el="http://schemas.microsoft.com/office/word/2010/wordprocessingShape",Np=new Set([go,el,"http://schemas.openxmlformats.org/drawingml/2006/picture"]),Yp=new Set(["noAutofit","normAutofit","spAutoFit"]),_p=new Set(["noFill","solidFill","gradFill","blipFill","pattFill","grpFill"]),Bp=new Set(["noFill","solidFill","gradFill","pattFill"]),Up=new Set(["prstGeom","custGeom"]),Fp=new Set(["prstDash","custDash"]),jp=new Set(["round","bevel","miter"]),tl=new Map([["shapeProperties",new Set(["xfrm","ln","effectLst","effectDag","scene3d","sp3d","extLst"])],["lineProperties",new Set(["headEnd","tailEnd","extLst"])]]),zp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing",Wp=new Map(Object.entries({anchor:"anchoredDrawing",inline:"inlineDrawing",simplePos:"drawingSimplePos",positionH:"drawingPositionH",positionV:"drawingPositionV",extent:"drawingExtent",effectExtent:"drawingEffectExtent",docPr:"drawingDocPr",cNvGraphicFramePr:"drawingGraphicFramePr",wrapNone:"drawingWrapNone",wrapSquare:"drawingWrapSquare",wrapTight:"drawingWrapTight",wrapThrough:"drawingWrapThrough",wrapTopAndBottom:"drawingWrapTopBottom"})),$p=new Set(["drawing","anchoredDrawing","inlineDrawing"]);function nl(t,e,n){return t!=="generic"||n===void 0?t:e===zp?Wp.get(n)??t:e===go&&n==="graphic"?"drawingGraphic":e===WML_NAMESPACE_URI&&n==="drawing"?"drawing":t}function Kp(t,e,n){if(t!=="generic")return t;let o=nl(t,e,n);return o!==t?o:n==="spPr"&&Np.has(e??"")?"shapeProperties":n==="ln"&&e===go?"lineProperties":n==="bodyPr"&&e===el?"bodyProperties":t}function ol(t){return t===null||typeof t=="string"?t:Kp(t.kind,t.namespaceUri,t.localName)}function Pt(t,e){return t.kind==="generic"&&t.namespaceUri===go&&e.has(t.localName)?t.localName:null}var Vp=new Set(["choice:position"]),rl=new Map(Object.entries({drawing:t=>t.kind==="anchoredDrawing"||t.kind==="inlineDrawing"?"choice:placement":null,drawingPositionH:()=>"choice:position",drawingPositionV:()=>"choice:position",anchoredDrawing:t=>Qa.has(t.kind)?"choice:wrap":null,shapeProperties:t=>Pt(t,_p)?"choice:fill":Pt(t,Up)?"choice:geometry":null,bodyProperties:t=>Pt(t,Yp)?"choice:autofit":null,lineProperties:t=>Pt(t,Bp)?"choice:fill":Pt(t,Fp)?"choice:dash":Pt(t,jp)?"choice:join":null})),Ga={paragraph:"paragraphProperties",run:"runProperties"},Jp=new Set(["sectPr","pPrChange"]);function ii(t){return t.kind==="generic"&&t.namespaceUri===WML_NAMESPACE_URI&&Jp.has(t.localName)}var il=new Set(["paragraphProperties","runProperties","tableProperties"]);function Hp(t,e){if(qa.get(t)?.includes(e.kind))return `kind:${e.kind}`;let n=rl.get(t)?.(e);if(n)return n;let o=tl.get(t),r=o?Pt(e,o):null;return r?`a:${r}`:il.has(t)&&e.kind==="generic"&&e.namespaceUri===WML_NAMESPACE_URI?`wml:${e.localName}`:null}function si(t){let e=ol(t);return e!==null&&(qa.has(e)||rl.has(e)||Za.has(e)||tl.has(e)||il.has(e))}function mo(t,e,n){let o=ol(t);if(o===null||!si(o))return null;let r=new Map,i=new Set,s=[],a=Za.get(o),l=$p.has(o),d=typeof t=="object"&&t?.kind==="generic",c=new Set,u=-1;for(let b=0;b<e.length;b+=1){let v=e[b];if(i.has(v))continue;i.add(v);let L=n(v),m=L&&l&&L.kind==="generic"?{...L,kind:nl(L.kind,L.namespaceUri,L.localName)}:L;if(s[b]=m,!m)continue;if(a?.has(m.kind)&&(!d||ze(v)!==null)){c.add(b);continue}u<0&&(u=b);let k=Hp(o,m);if(k===null)continue;let O=r.get(k);O?O.push(b):r.set(k,[b]);}let f=new Map;for(let[b,v]of r){if(v.length<2||v.every(k=>ze(e[k])===null))continue;let L=Vp.has(b)?v.find(k=>s[k]?.empty!==true)??v[0]:v[0],m=v.filter(k=>k!==L);for(let k of m)c.add(k);f.set(L,m);}let p=Ga[o]?`kind:${Ga[o]}`:null,h=p?r.get(p)?.[0]:void 0,g=h!==void 0&&u!==h,y=o==="paragraphProperties"?r.get("kind:runProperties")?.[0]:void 0,w=-1;if(y!==void 0)for(let b=y+1;b<e.length;b+=1){let v=s[b];v&&!c.has(b)&&!ii(v)&&(w=b);}if(c.size===0&&!g&&w<0)return null;let S=new Set;for(let b of c)S.add(e[b]);let I=[];g&&I.push(h);for(let b=0;b<e.length;b+=1)c.has(b)||S.has(e[b])||g&&b===h||w>=0&&b===y||(I.push(b),b===w&&I.push(y));return {order:I,companions:f}}function Xp(t,e,n){return mo(t,e,n)?.order??null}function et(t,e){if(E(e)||t.isTombstoned(e))return null;let n=t.schema.nodes.get(e);if(!_(n))return null;let o=Ge(n);return {kind:o.kind,namespaceUri:Rt(t.schema.namespaces,o.namespaceId),localName:o.localName,...ie(n)?.length===0?{empty:true}:{}}}function sl(t,e,n){let o=Xp(t,e,n);if(!o)return {shown:e,hidden:[]};let r=o.map(s=>e[s]),i=new Set(r);return {shown:r,hidden:e.filter(s=>!i.has(s))}}var ai=new Set(["paragraphProperties","runProperties","tableProperties"]);function al(t,e,n){let o=mo(t,e,n);if(!o)return {shown:e,hidden:[],merges:null};let r=o.order.map(s=>e[s]),i=new Set(r);return {shown:r,hidden:e.filter(s=>!i.has(s)),merges:Gp(o,e,n)}}function Gp(t,e,n){let o=null;for(let[r,i]of t.companions){let s=n(e[r]);!s||!ai.has(s.kind)||(o??=new Map,o.set(e[r],i.map(a=>e[a])));}return o}function qp(t,e){let n=et(t,e);return n?n.kind==="paragraphProperties"||n.kind==="runProperties"?n.kind:n.kind==="generic"&&n.localName==="ins"?"ins":null:null}var Qp={paragraph:"paragraphProperties",paragraphProperties:"runProperties",runProperties:"ins"};function ci(t,e,n){let o=t.record(e);return !o||!W(o)?[]:o.childIds.filter(r=>t.showsAsChild(r)&&qp(t,r)===n)}function li(t,e,n,o){return ci(t,e,n).filter(r=>!o.has(r))}function Zp(t,e,n){let o=t.record(e);if(!o||!W(o))return false;let r=o.childIds.filter(i=>t.showsAsChild(i));return r.length===1&&r[0]===n}function eh(t,e,n){let o=[],r=e;for(let a of ["paragraphProperties","runProperties","ins"]){let l=ci(t,r,a),d=l.filter(u=>ze(u)===n),c=d.length===1?d[0]:l.length===1?l[0]:null;if(!c)return null;o.push({node:c,from:r,level:a}),r=c;}let i=o[2];if(ze(i.node)!==n)return null;let s=i;for(let a=1;a>=0;a-=1){let l=o[a];if(ze(l.node)!==n||!Zp(t,l.node,o[a+1].node))break;s=l;}return s}function th(t,e,n,o,r){let{node:i,from:s,level:a}=e,l=n;for(a!=="paragraphProperties"&&(l=li(t,n,"paragraphProperties",o)[0],l&&a==="ins"&&(l=li(t,l,"runProperties",o)[0]));l;){let d=li(t,l,a,o);if(d.length===0){r.push({node:i,from:s,to:l,first:a!=="runProperties"});return}if(a==="ins")return;let c=Qp[a],u=ci(t,i,c);if(u.length!==1)return;s=i,i=u[0],l=d[0],a=c;}}function nh(t,e){let n=[],o=e.source;for(let s of e.shown){let a=e.before.get(s),l=ze(s);if(a&&l&&a!==o){let d=eh(t,a,l);d&&n.push({proposal:d,target:o});}o=s;}let r=new Set(n.map(({proposal:s})=>s.node)),i=[];for(let{proposal:s,target:a}of n)th(t,s,a,r,i);return i}var di=class{constructor(e){this.registry=e;}registry;moves=[];key="";hidden=new Map;added=new Map;refresh(e,n){let o=[];for(let s of n)for(let a of e.splitSiblings.groupsOf(s))o.push(...nh(e,a));let r=o.map(s=>`${s.node}>${s.to}`).join(";");if(r===this.key)return [];let i=new Set;for(let s of [...this.moves,...o])i.add(s.from),i.add(s.to);this.moves=o,this.key=r,this.hidden.clear(),this.added.clear();for(let s of o){let a=this.hidden.get(s.from);a||this.hidden.set(s.from,a=new Set),a.add(s.node);let l=this.added.get(s.to)??[];l.push(s),this.added.set(s.to,l);}return [...i]}movedOut(e,n){return this.hidden.get(e)?.has(n)??false}shownChildIds(e,n){let o=this.hidden.get(e),r=this.added.get(e);if(!o&&!r)return [...n];let i=o?n.filter(d=>!o.has(d)):[...n],s=(r??[]).filter(d=>d.first&&!i.includes(d.node)),a=(r??[]).filter(d=>!d.first&&!i.includes(d.node)),l=ui(this.registry,i);return [...s.map(d=>d.node),...i.slice(0,l),...a.map(d=>d.node),...i.slice(l)]}movesAt(e){return this.moves.filter(n=>n.from===e||n.to===e)}};function ui(t,e){let n=e.findIndex(o=>{let r=et(t,o);return r!==null&&ii(r)});return n<0?e.length:n}var ll=new WeakMap;function at(t){let e=ll.get(t);return e||ll.set(t,e=new di(t)),e}function dl(t,e){let n=t.splitSiblings.takeChanged();n.length>0&&t.inline.orderChanged();for(let r of n)e.add(r);let o=new Set(t.splitSiblings.parentsWithRuns());for(let r of e){let i=t.parentOf(r);i&&o.add(i);}for(let r of at(t).refresh(t,o))e.add(r);}var oh=new Set(["run","runProperties"]),rh=new Set(["t","delText","instrText","delInstrText"]),hl=new Set(["hyperlink","ins","del","moveFrom","moveTo","sdt","sdtContent","fldSimple","smartTag","customXml","dir","bdo"]);function gl(t){return oh.has(t.kind)?true:t.namespaceUri===WML_NAMESPACE_URI&&(rh.has(t.localName)||hl.has(t.localName))}function ul(t,e){let n=t.prefix===void 0?{}:{prefix:t.prefix};return t.namespaceUri===XML_NAMESPACE_URI&&t.localName==="space"&&t.prefix==="xml"&&(e==="default"||e==="preserve")?{kind:"xmlSpace",namespaceUri:XML_NAMESPACE_URI,localName:"space",prefix:"xml",value:e}:t.namespaceUri===WML_NAMESPACE_URI&&t.localName==="val"?{kind:"wmlVal",namespaceUri:WML_NAMESPACE_URI,localName:"val",...n,value:e}:{kind:"genericExtension",namespaceUri:t.namespaceUri,localName:t.localName,...n,value:e}}function fl(t){return t.replace(/(~\d+)+$/,"")}var fi=class{nodes=new Map;refusal=null;refuse(e,n){return this.refusal??={code:e,detail:n},false}described=new Set;add(e,n,o){let r=U(e),i=o.has(r),s={id:r,kind:e.kind,namespaceUri:e.kind==="textValue"?"":e.namespaceUri,localName:e.kind==="textValue"?"":e.localName,...e.kind!=="textValue"&&e.prefix!==void 0?{prefix:e.prefix}:{},attributes:e.kind==="textValue"?[]:[...e.attributes],bindings:e.kind==="textValue"?[]:[...e.namespaceBindings],children:[],value:e.kind==="textValue"?e.value:null,parent:n,opaque:i,block:false,paragraph:false};if(this.nodes.set(r,s),!(e.kind==="textValue"||i))for(let a of e.children)s.children.push(U(a)),this.add(a,r,o);}placeholder(e,n){let o=this.nodes.get(e);if(o)return o;let r={id:e,kind:n,namespaceUri:"",localName:"",attributes:[],bindings:[],children:[],value:null,parent:null,opaque:true,block:false,paragraph:false};return this.nodes.set(e,r),r}detach(e){let n=this.nodes.get(e);if(!n||n.parent===null)return;let o=this.nodes.get(n.parent);if(o){let r=o.children.indexOf(e);r>=0&&o.children.splice(r,1);}n.parent=null;}open(e){let n=this.nodes.get(e);return n!==void 0&&!n.opaque&&!this.insideOpaque(n)}insideOpaque(e){let n=e.parent;for(let o=0;n!==null&&o<256;o+=1){let r=this.nodes.get(n);if(!r)return false;if(r.opaque)return true;n=r.parent;}return false}region(e){let n=[],o=this.nodes.get(e);for(let i=0;o&&i<256&&(n.push(o),!o.paragraph);i+=1)o=o.parent===null?void 0:this.nodes.get(o.parent);let r=n[n.length-1];if(!r?.paragraph)return null;for(let i=n.length-2;i>=0;i-=1){let s=n[i];if(s.block||s.opaque)return {paragraph:r.id,inline:false};if(!(s.kind==="textValue"||gl(s)||n[i+1].kind==="runProperties"||ih(n,i)))return {paragraph:r.id,inline:false}}return {paragraph:r.id,inline:true}}detachedRoot(e){let n=this.nodes.get(e);for(let o=0;n.parent!==null&&o<256;o+=1){let r=this.nodes.get(n.parent);if(!r)break;n=r;}return n}toTree(e,n=new Set){n.add(e);let o=this.nodes.get(e);return o.kind==="textValue"?Jt(fl(o.id),o.value??""):De({id:o.paragraph||o.opaque?o.id:fl(o.id),kind:o.kind,namespaceUri:o.namespaceUri,localName:o.localName,namespaceBindings:o.bindings,attributes:o.attributes,children:o.opaque?[]:this.childTrees(o,n),...o.prefix===void 0?{}:{prefix:o.prefix}})}childTrees(e,n){let o=[];for(let r of e.children)this.nodes.get(r)?.parent!==e.id||n.has(r)||o.push(this.toTree(r,n));return o}};function ih(t,e){for(let n=e;n<t.length-1;n+=1){let o=t[n],r=t[n+1];if(r.kind==="runProperties")return true;if(r.namespaceUri===WML_NAMESPACE_URI&&hl.has(r.localName))return o.namespaceUri===WML_NAMESPACE_URI&&/Pr$|^fldData$/.test(o.localName)}return false}function pl(t){switch(t.kind){case "putNode":return [t.descriptor.logicalId];case "spliceText":case "setAttribute":case "setNamespaceBinding":return [t.logicalId];case "spliceChildren":return [t.parentLogicalId,...t.childLogicalIds];case "moveNode":return [t.logicalId,t.destinationParentLogicalId];default:return []}}function yo(t,e,n=()=>null){let o=e.map(Ht),r=new Map;for(let S of o)S.kind==="putNode"&&r.set(S.descriptor.logicalId,S);let i=S=>t.inline.textOf(S)||r.get(S)?.descriptor.kind==="paragraph"||t.kindOf(S)==="paragraph"&&!dh(t,S)?S:t.inline.owner(S),s=new Set;for(let S of o)for(let I of pl(S)){let b=i(I);b&&s.add(b);}if(s.size===0)return {passThrough:[...o],plan:null};let a=S=>{let I=new fi,b=new Set;for(let v of S){let L=t.inline.textOf(v),m=I.placeholder(v,"paragraph");m.opaque=false,m.paragraph=true,m.kind="paragraph",m.namespaceUri=WML_NAMESPACE_URI,m.localName="p";let k=t.record(v),O=k&&"childIds"in k?k.childIds:[],{shown:P}=sl("paragraph",at(t).shownChildIds(v,O),Y=>et(t,Y));for(let Y of P){let V=I.placeholder(Y,t.kindOf(Y)??"generic");V.block=true,V.parent=v,m.children.push(Y);}if(!L)continue;let j=new Set,K=Y=>{if(!t.showsAsChild(Y))return null;let V=n(Y);return V!==null&&V!==v||j.has(Y)?null:(j.add(Y),eo(Y))};for(let Y of Ze(v,L,K,t.limits,t.inline.viewOf(v)))I.add(Y,v,j),m.children.push(U(Y));for(let Y of j){b.add(Y);let V=I.nodes.get(Y);V&&(V.kind=t.kindOf(Y)??"generic");}}return {scratch:I,embedsBefore:b}},{scratch:l,embedsBefore:d}=a(s),c=o.flatMap(S=>pl(S)).filter(S=>!l.nodes.has(S)&&!r.has(S)&&!t.hasNode(S));if(c.length>0){let S=new Set(s);for(let I of ch(t,new Set(c)))S.add(I);if(S.size>s.size){for(let I of S)s.add(I);({scratch:l,embedsBefore:d}=a(s));}}let u=[],f=new Map;for(let S of o){let I=sh(l,S,t);if(I&&f.set(u.length,I),u.push(ah(l,S,t)),l.refusal)return {passThrough:[...o],plan:null,refusal:l.refusal}}let p=[];o.forEach((S,I)=>{let b=f.get(I);b?p.push(b):(!u[I]||!lh(l,S))&&p.push(S);});let h=[...s].filter(S=>l.nodes.get(S)?.paragraph).map(S=>({id:S,after:Vt(l.toTree(S))})),[g,...y]=o,w=y.length===0&&g?.kind==="spliceText"&&g.deleteCount===0?{textValueId:g.logicalId,utf16Start:g.utf16Start}:void 0;return {passThrough:p,plan:{paragraphs:h,embedsBefore:d,...w?{typed:w}:{}}}}function sh(t,e,n){if(e.kind!=="spliceChildren")return null;let o=t.nodes.get(e.parentLogicalId);if(!o?.paragraph)return null;let r=c=>{let u=t.nodes.get(c);return u?u.block||u.kind==="paragraphProperties":n.kindOf(c)==="paragraphProperties"},i=o.children.filter(c=>t.nodes.get(c)?.parent===o.id),a=o.children.slice(e.start,e.start+e.deleteCount).filter(c=>t.nodes.get(c)?.block).length,l=e.childLogicalIds.filter(r);if(a===0&&l.length===0)return null;let d=o.children.slice(0,e.start).filter(c=>i.includes(c)&&t.nodes.get(c)?.block).length;return {...e,start:d,deleteCount:a,childLogicalIds:l}}function ah(t,e,n){switch(e.kind){case "putNode":{let{descriptor:o}=e;if(E(o.logicalId))return t.refuse("invalid-logical-id",o.logicalId);if(o.kind!=="textValue"&&(E(o.qname.localName)||o.qname.prefix!==void 0&&E(o.qname.prefix)))return t.refuse("prototype-key",o.logicalId);let r=t.nodes.get(o.logicalId);if(o.kind==="textValue"){if(r&&t.described.add(o.logicalId),!r){let s=t.placeholder(o.logicalId,"textValue");s.opaque=false,s.value="";}return true}let i=r??t.placeholder(o.logicalId,o.kind);return r||(i.opaque=false),r?.opaque?false:(i.kind=o.kind,i.namespaceUri=o.qname.namespaceUri,i.localName=o.qname.localName,o.qname.prefix!==void 0&&(i.prefix=o.qname.prefix),o.kind==="paragraph"&&!n.hasNode(o.logicalId)&&(i.paragraph=true),true)}case "spliceText":{let o=t.nodes.get(e.logicalId);return !o||o.value===null||!t.open(e.logicalId)?false:!Number.isSafeInteger(e.utf16Start)||!Number.isSafeInteger(e.deleteCount)||e.utf16Start<0||e.deleteCount<0||e.utf16Start+e.deleteCount>o.value.length?t.refuse("invalid-bound",e.logicalId):o.value.length-e.deleteCount+e.insert.length>n.limits.maxTextLength?t.refuse("text-too-long",e.logicalId):(t.described.delete(e.logicalId)&&e.utf16Start===0&&e.deleteCount===0&&e.insert.length>0&&e.insert===o.value||(o.value=o.value.slice(0,e.utf16Start)+e.insert+o.value.slice(e.utf16Start+e.deleteCount)),true)}case "setAttribute":{let o=t.nodes.get(e.logicalId);if(!o||o.paragraph||!t.open(e.logicalId))return false;if(E(e.qname.localName)||e.qname.prefix!==void 0&&E(e.qname.prefix))return t.refuse("prototype-key",e.logicalId);let r=o.attributes.findIndex(i=>i.namespaceUri===e.qname.namespaceUri&&i.localName===e.qname.localName);return e.value===null?r>=0&&o.attributes.splice(r,1):r>=0?o.attributes[r]=ul(e.qname,e.value):o.attributes.push(ul(e.qname,e.value)),true}case "setNamespaceBinding":{let o=t.nodes.get(e.logicalId);if(!o||o.paragraph||!t.open(e.logicalId))return false;if(E(e.prefix))return t.refuse("prototype-key",e.logicalId);let r=o.bindings.findIndex(i=>i.prefix===e.prefix);return e.uri===null?r>=0&&o.bindings.splice(r,1):r>=0?o.bindings[r]={prefix:e.prefix,namespaceUri:e.uri}:o.bindings.push({prefix:e.prefix,namespaceUri:e.uri}),true}case "spliceChildren":{if(!t.open(e.parentLogicalId)){for(let a of e.childLogicalIds){let l=t.nodes.get(a);l&&(l.parent=e.parentLogicalId,l.outside=true);}return false}let o=t.nodes.get(e.parentLogicalId);if(!Number.isSafeInteger(e.start)||!Number.isSafeInteger(e.deleteCount)||e.start<0||e.deleteCount<0||e.start+e.deleteCount>o.children.length)return t.refuse("invalid-bound",e.parentLogicalId);if(o.children.length-e.deleteCount+e.childLogicalIds.length>n.limits.maxChildren)return t.refuse("too-many-children",e.parentLogicalId);let r=e.childLogicalIds.find(a=>E(a));if(r!==void 0)return t.refuse("invalid-logical-id",r);let i=o.children.splice(e.start,e.deleteCount);for(let a of i){let l=t.nodes.get(a);l?.parent===o.id&&(l.parent=null);}let s=[];for(let a of e.childLogicalIds){let l=n.kindOf(a);if(!t.nodes.has(a)&&(l===null||!n.hasNode(a)))return t.refuse("unknown-logical-id",a);let d=t.nodes.get(a)??t.placeholder(a,l);d.parent=o.id,d.outside=false,o.paragraph&&d.kind==="paragraphProperties"&&(d.block=true),s.push(a);}return o.children.splice(e.start,0,...s),true}case "moveNode":{let o=t.open(e.destinationParentLogicalId),r=t.nodes.get(e.logicalId)?.parent!=null;if(!o&&!r)return false;let i=n.kindOf(e.logicalId);if(!t.nodes.has(e.logicalId)&&(i===null||!n.hasNode(e.logicalId)))return t.refuse("unknown-logical-id",e.logicalId);let s=t.nodes.get(e.logicalId)??t.placeholder(e.logicalId,i);if(t.detach(e.logicalId),s.outside=!o,o){let a=t.nodes.get(e.destinationParentLogicalId);s.parent=a.id,a.children.splice(Math.max(0,Math.min(e.destinationIndex,a.children.length)),0,e.logicalId);}return o}default:return false}}function lh(t,e){let n=o=>{let r=t.region(o);if(r)return r.inline;let i=t.nodes.get(o);if(!i||i.opaque||i.paragraph)return false;let s=t.detachedRoot(o);return !s.outside&&(s.kind==="textValue"||gl(s))};switch(e.kind){case "putNode":{let o=e.descriptor.logicalId,r=t.nodes.get(o);return !r||r.paragraph||r.opaque?false:n(o)}case "spliceText":case "setAttribute":case "setNamespaceBinding":return n(e.logicalId);case "spliceChildren":return t.nodes.get(e.parentLogicalId)?.paragraph===true||n(e.parentLogicalId);case "moveNode":return t.nodes.get(e.destinationParentLogicalId)?.paragraph===true||n(e.destinationParentLogicalId);default:return false}}function dh(t,e){let n=t.record(e);return !n||!("childIds"in n)?true:n.childIds.some(o=>t.kindOf(o)==="run")}function ch(t,e){let n=new Set,o=new Set(e),r=i=>i.some(s=>o.delete(U(s))||s.kind!=="textValue"&&r(s.children));return t.schema.nodes.forEach((i,s)=>{if(o.size===0)return;let a=G(s),l=t.inline.textOf(a);if(!l||t.inline.isDeletedParagraph(a))return;let d=t.inline.viewOf(a);r(Ze(a,l,()=>null,t.limits,d))&&n.add(a);}),n}var fh=new Set(["proofErr","permStart","permEnd"]);function pi(t,e,n){return t==="bookmarkStart"||t==="bookmarkEnd"||isRangeMarkerKind(t)?true:t==="generic"&&n&&fh.has(e)}var ph=Lt(WML_NAMESPACE_URI);function hi(t){if(!_(t))return false;let e=Ge(t);return pi(e.kind,e.localName,e.namespaceId===ph)}function yl(t){return hi(t)?Et(t):null}function ml(t){let e=n=>t.find(o=>o.namespaceUri===WML_NAMESPACE_URI&&o.localName===n)?.value??null;return [e("id"),e("name")]}function hh(t){let e=new Map,n=[...t];for(;n.length>0;){let o=n.pop();if(o.kind!=="textValue"){e.set(o.id,o);for(let r of o.children)n.push(r);}}return e}function bl(t,e,n,o,r){if(n.size===0||e.length===0)return;let i=new Map;for(let a of e){let l=t.record(a);if(!l||!W(l)||l.childIds.length>0||!pi(l.kind,l.localName,l.namespaceUri===WML_NAMESPACE_URI))continue;let d=JSON.stringify([l.kind,l.localName,...ml(l.attributes)]),c=i.get(d)??[];c.push(a),i.set(d,c);}if(i.size===0)return;let s=hh(r);for(let a of n){if(!o.has(a))continue;let l=s.get(a);if(!l||!pi(l.kind,l.localName,l.namespaceUri===WML_NAMESPACE_URI))continue;let d=JSON.stringify([l.kind,l.localName,...ml(l.attributes)]),c=i.get(d)?.shift();if(c===void 0)continue;let u=t.schema.nodes.get(a);if(!_(u))continue;let f=t.splitLineageOf(c)??c;u.set(yn,f),u.set(wt,f);}}var gh=new Set(["tableRow","tableCell"]);function Il(t,e,n){let o=new Map,r=a=>e.reinserted.has(a)&&!e.unlistedAtEnd.has(a),i=[],s=new Set;for(let a of e.removed){let l=t.kindOf(a);if(!(l===null||l==="paragraph"||gh.has(l))&&!(r(a)||!t.isTombstoned(a))){s.add(a);for(let d of n.get(a)??[])i.push(d);}}for(;i.length>0;){let a=i.pop();if(s.has(a)||r(a)||t.isTombstoned(a))continue;if(s.add(a),t.kindOf(a)==="paragraph"){if(mh(t,a,s))continue;let c=yh(t,a);c.length>0&&o.set(a,c);continue}let d=t.nodeShape(a);if(d&&!d.isText)for(let c of d.children)i.push(c);}return o}function mh(t,e,n){return t.listingParents(e).some(o=>!n.has(o)&&!t.isTombstoned(o))}function yh(t,e){let n=t.inline.textOf(e);if(!n)return [];let o=t.inline.viewOf(e).shown(n),r=[];o.identities.ids.forEach((i,s)=>{i&&!o.hidden.has(s)&&r.push(i);});for(let i of o.incoming)for(let s of i.identities)s&&r.push(s);return r}var lt="o",bh=/^(\^?)(\d{1,16}:\d{1,16})$/,tt="-";function wl(t){if(t===tt)return {identity:tt,before:false};let e=typeof t=="string"?bh.exec(t):null;return e?{identity:e[2],before:e[1]==="^"}:null}function mi(t,e,n,o,r){let i={...o};delete i[lt];let s=Ft(t,e,n,i);s&&Le(t.doc).markCopy("move",s.id.client,s.id.clock,n.length,r);}function xl(t,e,n){let o=[],r=[],i="",s=()=>{r.length>0&&o.push({paragraph:e,indexes:r,value:i}),r=[],i="";};for(let a of t.steps){if(a.op!==n){a.op!==(n==="del"?"ins":"del")&&s();continue}let l=a.op==="del"?a.before:a.after,d=a.op==="del"?t.before[l]:t.after[l];if(typeof d.insert!="string"){s();continue}r.push(l),i+=d.insert;}return s(),o}function Ih(t,e){let n=e.from+e.length;return (e.from===0||t[e.from-1])&&(n===t.length||t[n])}var xh=1<<20,Sl=1<<24;function gi(t,e,n,o,r,i,s=false){let a=e(t),l=o.get(t),d=null;for(let c of n){if(c.paragraph===t.paragraph!==s||!r(c.paragraph,t.paragraph))continue;let u=e(c),f=o.get(c),p=u.length*a.length;if(p>xh)continue;if(p>i.cells)return d;i.cells-=p;let h=new Uint32Array(a.length+1);for(let g=1;g<=u.length;g+=1){let y=new Uint32Array(a.length+1);for(let w=1;w<=a.length;w+=1){if(f[g-1]||l[w-1]||u[g-1]!==a[w-1])continue;let S=h[w-1]+1;y[w]=S,S>(d?.length??0)&&(d={source:c,from:g-S,to:w-S,length:S});}h=y;}}return d}function kl(t,e,n,o=()=>"",r=()=>""){let i=new Set,s=t.flatMap((m,k)=>xl(m,k,"del"));if(s.length===0)return i;let a=t.flatMap((m,k)=>xl(m,k,"ins")),l=new Set(s),d={cells:Sl},c=new Map,u=m=>k=>{let O=l.has(k),P=`${m}:${k.paragraph}:${k.indexes[0]}:${O}`,j=c.get(P);if(!j){let K=t[k.paragraph];j=k.indexes.map(Y=>{let V=O?K.before[Y]:K.after[Y],q=V.insert;return m?`${q}\0${o(V,k.paragraph)}`:q}),c.set(P,j);}return j},f=new Map;for(let m of [...s,...a])f.set(m,m.indexes.map(()=>false));let p=t.map((m,k)=>r(k)),h=(m,k)=>p[m]===""||p[k]===""||p[m]===p[k],g=(m,k)=>{for(let O=0;O<k.length;O+=1)f.get(k.source)[k.from+O]=true,f.get(m)[k.to+O]=true;wh(t,m,k,e,n,i);};for(let m of a){let k=s.find(O=>O.paragraph!==m.paragraph&&h(O.paragraph,m.paragraph)&&O.value===m.value&&!f.get(O).some(Boolean));k&&g(m,{source:k,from:0,to:0,length:m.indexes.length});}let y=a.filter(m=>t[m.paragraph].before.length===0),w=m=>{let k={cells:Sl};for(let O of y.length===0?[]:s)if(!f.get(O).some(Boolean))for(let{run:P,from:j}of Sh(O,y,f,h,k,m))g(P,{source:O,from:j,to:0,length:P.indexes.length});};w(false);for(let m of a)for(let k=gi(m,u(true),s,f,h,d);k;)g(m,k),k=gi(m,u(true),s,f,h,d);w(true);let S=new Map;for(let m of a)S.set(m.paragraph,[...S.get(m.paragraph)??[],m]);let I=new Set(s.filter(m=>(S.get(m.paragraph)??[]).some(k=>k.value.includes(m.value)))),b=s.filter(m=>!I.has(m)),v=(m,k,O)=>{for(;;){let P=gi(k,u(false),m,f,h,d,O);if(!P||!Ih(f.get(P.source),P))break;g(k,P);}};for(let m of a)v(b,m,false);let L=new Map;for(let m of I)L.set(m.paragraph,[...L.get(m.paragraph)??[],m]);for(let m of a){let k=L.get(m.paragraph);k&&v(k,m,true);}return i}function Sh(t,e,n,o,r,i){let s=(a,l)=>{if(a.value.length===0||a.paragraph===t.paragraph||!o(t.paragraph,a.paragraph)||n.get(a).some(Boolean))return -1;let d=i?t.value.length:a.value.length;return r.cells<d?-1:(r.cells-=d,i?t.value.indexOf(a.value,l):t.value.startsWith(a.value,l)?l:-1)};for(let a=0;a<e.length;a+=1){if(s(e[a],0)<0)continue;let l=[],d=0,c=0;for(let f=a;f<e.length&&d<t.value.length;f+=1){let p=e[f],h=s(p,d);if(h<0)break;l.push({run:p,from:h}),d=h+p.value.length,c+=p.value.length;}if(i?c*2>t.value.length:c===t.value.length&&l.length>1)return l}return []}function wh(t,e,n,o,r,i){let s=t[n.source.paragraph],a=c=>{let u=s.before[n.source.indexes[n.from+c]];return u?.position===void 0?null:s.identities[u.position]??null},l=t[e.paragraph],d=null;for(let c=0;c<n.length;c+=1){let u=e.indexes[n.to+c],f=a(c);f&&i.add(f);let p=c>0?l.after[e.indexes[n.to+c-1]]:null,h=p!==null&&r(p)===r(l.after[u]);(!d||!h||!zt(a(c-1),f))&&(d=f),d&&(l.after[u]=o(l.after[u],d));}}var kh="docx-text-marks-v1",vh={move:"o",restore:"u",follow:"f"},Tl=/^([ouf])(\d{1,16}):(\d{1,16})$/,Lh=/^(\d{1,16}):(\d{1,16}):(\d{1,16})$/,Rh=/^(\d{1,16})\|(.{1,40})$/,bi=16,vl=1<<20,Ll=4096;function Rl(t,e){let n=0,o=t.length;for(;n<o;){let r=n+o>>1;t[r].firstClock<=e?n=r+1:o=r;}return n}function Ol(t,e,n){return `${vh[t]}${e}:${n}`}function Je(t){let e=Number(t);return Number.isSafeInteger(e)?e:null}function Oh(t,e){let n=Tl.exec(t);if(!n||typeof e!="string")return null;let o=n[1]==="o"?"move":n[1]==="u"?"restore":"follow",r=Je(n[2]),i=Je(n[3]);if(r===null||i===null)return null;if(o==="follow"){let u=Rh.exec(e),f=u?Je(u[1]):null,p=u?wl(u[2]):null;return f===null||f<1||f>vl||!p?null:{kind:o,client:r,span:{key:t,client:r,firstClock:i,length:f,origin:null,follow:p}}}let s=Lh.exec(e),a=s?Je(s[1]):null,l=s?Je(s[2]):null,d=s?Je(s[3]):null;return a===null||l===null||d===null||d<1||d>vl?null:{kind:o,client:r,span:{key:t,client:r,firstClock:i,length:d,origin:{client:a,clock:l,insertClient:r,firstClock:i,length:d},follow:null}}}var Eh={origin:()=>null,follow:()=>null,followStart:()=>null},yi=class{constructor(e,n){this.doc=e;this.map=n;n.forEach((o,r)=>this.refresh(r,o));}doc;map;spans={move:new Map,restore:new Map,follow:new Map};byKey=new Map;dependents=new Map;listeners=new Set;textsOfClients=new Map;subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}origin(e,n,o){return this.find(e,n,o)?.origin??null}follow(e,n){return this.find("follow",e,n)?.follow??null}followStart(e,n){return this.find("follow",e,n)?.firstClock??null}markCopy(e,n,o,r,i){this.write(Ol(e,n,o),`${i}:${r}`);}markFollow(e,n,o,r){this.write(Ol("follow",e,n),`${o}|${r}`);}refreshKeys(e){let n=[];for(let r of e){if(r===null)continue;let i=this.byKey.get(r)?.span.length??0;this.refresh(r,this.map.get(r));let s=this.byKey.get(r)?.span.length??0,a=Tl.exec(r),l=a?Je(a[2]):null,d=a?Je(a[3]):null;l===null||d===null||n.push({client:l,from:d,to:d+Math.max(i,s,1)});}let o=this.textsReading(n);if(!(o!=="all"&&o.size===0))for(let r of this.listeners)r(o);}textsReading(e){let n=new Set,o=new Set,r=new Set,i=()=>{for(let a of r)for(let l of this.textsOfClient(a))n.add(l);return n},s=e;for(let a=0;a<=bi&&s.length>0;a+=1){let l=[];for(let d of s)r.add(d.client);for(let d of s){let c=`${d.client}:${d.from}:${d.to}`;if(!o.has(c)){if(o.size>=Ll)return this.withDependents(r,i);o.add(c);for(let u=d.from,f=0;u<d.to;f+=1){if(f>=Ll)return this.withDependents(r,i);let p=H(this.doc,{client:d.client,clock:u});if(!p)break;p.parent instanceof z.Text&&n.add(p.parent),u=p.id.clock+p.length;}for(let u of this.dependents.get(d.client)??[]){let f=Ch(u,d);f&&l.push(f);}}}s=l;}return n}withDependents(e,n){let o=[...e];for(;o.length>0;){let r=o.pop();for(let i of this.dependents.get(r)??[])e.has(i.client)||(e.add(i.client),o.push(i.client));}return n()}textsOfClient(e){let n=z.getState(this.doc.store,e),o=this.textsOfClients.get(e);if(o?.state===n)return o.texts;let r=new Set;for(let i of this.doc.store.clients.get(e)??[]){let s=i instanceof z.Item?i.parent:null;s instanceof z.Text&&r.add(s);}return this.textsOfClients.set(e,{state:n,texts:r}),r}write(e,n){this.map.get(e)!==n&&(this.map.set(e,n),this.refresh(e,n));}refresh(e,n){this.remove(e);let o=Oh(e,n);if(!o)return;let r=_e(this.map,e);if(r&&r.id.client!==o.client)return;let i=this.spans[o.kind].get(o.client)??[];i.splice(Rl(i,o.span.firstClock),0,o.span),this.spans[o.kind].set(o.client,i),this.byKey.set(e,{kind:o.kind,span:o.span});let s=El(o.span);if(s!==null){let a=this.dependents.get(s)??new Set;a.add(o.span),this.dependents.set(s,a);}}remove(e){let n=this.byKey.get(e);if(!n)return;this.byKey.delete(e);let o=this.spans[n.kind].get(n.span.client);if(o){for(let i=Rl(o,n.span.firstClock)-1;i>=0&&o[i].firstClock===n.span.firstClock;i-=1)if(o[i]===n.span){o.splice(i,1);break}}let r=El(n.span);r!==null&&this.dependents.get(r)?.delete(n.span);}find(e,n,o){let r=this.spans[e].get(n);if(!r)return null;let i=0,s=r.length-1,a=null;for(;i<=s;){let l=i+s>>1,d=r[l];d.firstClock<=o?(a=d,i=l+1):s=l-1;}return a&&o<a.firstClock+a.length?a:null}};function El(t){if(t.origin)return t.origin.client;let e=t.follow?.identity,n=e?.indexOf(":")??-1;return n>0?Je(e.slice(0,n)):null}function Ch(t,e){if(t.origin){let r=Math.max(e.from,t.origin.clock),i=Math.min(e.to,t.origin.clock+t.length);if(r>=i)return null;let s=t.firstClock-t.origin.clock;return {client:t.client,from:r+s,to:i+s}}let n=t.follow.identity,o=Je(n.slice(n.indexOf(":")+1));return o===null||o<e.from||o>=e.to?null:{client:t.client,from:t.firstClock,to:t.firstClock+t.length}}var Cl=new WeakMap;function Le(t){let e=Cl.get(t);if(e)return e;let n=t.getMap(kh),o=new yi(t,n);return t.on("beforeObserverCalls",r=>{let i=jt(r,n);i&&o.refreshKeys(i);}),Cl.set(t,o),e=o,e}function dt(t){return t.doc?Le(t.doc):Eh}function Fl(t,e,n){let o=[],r=0;for(let i of Mt(t)){let s=i.attributes??{},a=n?$r(s,n.limits,n.paragraphId):"";if(typeof i.insert=="string"){let l=wi(s);for(let d=0;d<i.insert.length;d+=1,r+=1){if(e?.has(r))continue;let c=`c${i.insert[d]}`;o.push({key:c,strong:`${c}\0${l}`,insert:i.insert[d],attributes:s,position:r,trail:a});}}else {if(r+=1,e?.has(r-1))continue;let l=i.insert,d=typeof l.n=="string"?`e${l.r===1?"r":""}${l.n}`:Wl(s,a);o.push({key:d,strong:d,insert:l,attributes:s,position:r-1,trail:a});}}return o}function jl(t,e){let n=xn(t).items;for(let o=0;o<n.length;o+=1){let r=n[o];if(r.kind==="char"&&r.attributes.textValueId===e.textValueId)return o+e.utf16Start}}function xo(t,e){let n=t.id,o=new Map;return xn(t).items.map(r=>{let i=o.get(r.attributes);if(!i){let d=Ct(r.attributes,n,e);i={attributes:d,trail:$r(d,e,n)},o.set(r.attributes,i);}let{attributes:s,trail:a}=i;if(r.kind==="char"){let d=`c${r.value}`,c=`${d}\0${wi(s)}`;return {key:d,strong:c,insert:r.value,attributes:s,trail:a}}if(r.kind==="embed"){let d=Jr(r),c=`e${"r"in d?"r":""}${r.node.id}`;return {key:c,strong:c,insert:d,attributes:s,trail:a}}let l=Wl(s,a);return {key:l,strong:l,insert:{a:1},attributes:s,trail:a}})}var zl=1<<20;function Wl(t,e){return `a${ve(zr(t))}${e}`}function wi(t){return t.t??""}function $l(t,e,n=true,o){let r=Al(t),i=Al(e);if(r===null&&i===null)return Dl(t,e,n,o);let s=r?.starts??null,a=i?.starts??null,l=(c,u,f)=>{if(c===null)return [u];let p=c[u];return (u+1<c.length?c[u+1]:f)-p===2?[p,p+1]:[p]},d=[];for(let c of Dl(r?.tokens??t,i?.tokens??e,n))if(c.op==="del")for(let u of l(s,c.before,t.length))d.push({op:"del",before:u});else if(c.op==="ins")for(let u of l(a,c.after,e.length))d.push({op:"ins",after:u});else {let u=l(s,c.before,t.length),f=l(a,c.after,e.length);u.forEach((p,h)=>d.push({op:"eq",before:p,after:f[h]}));}return d}var Ml=t=>{if(t===void 0||typeof t.insert!="string")return false;let e=t.insert.charCodeAt(0);return e>=55296&&e<=56319},Pl=t=>{if(t===void 0||typeof t.insert!="string")return false;let e=t.insert.charCodeAt(0);return e>=56320&&e<=57343};function Al(t){let e=false;for(let r=0;r+1<t.length&&!e;r+=1)e=Ml(t[r])&&Pl(t[r+1]);if(!e)return null;let n=[],o=[];for(let r=0;r<t.length;r+=1){let i=t[r],s=t[r+1];o.push(r);let a=s!==void 0&&(i.position===void 0||s.position===i.position+1);if(Ml(i)&&Pl(s)&&a){let l=`${i.insert}${s.insert}`,d=`c${l}`;n.push({...i,key:d,strong:`${d}\0${wi(i.attributes)}`,insert:l}),r+=1;}else n.push(i);}return {tokens:n,starts:o}}function Dl(t,e,n,o){let r=n?Mh(t,e,o):null;if(r)return r;let i=Si(t,e,false),s=Si(t,e,true),a=xi(t,e,i),l=xi(t,e,s),[d,c]=[Ii(a),Ii(l)],u=c!==d?c>d?l:a:Yl(l)<Yl(a)?l:a,f=Math.max(d,c);if(f<Math.min(t.length,e.length)&&Th(u,t,e)){let p=Si(t,e,false,false);for(let h of [i,s,p]){let g=xi(t,e,h,true),y=Ii(g);y>f&&([u,f]=[g,y]);}}return Nh(_h(u,e),t)}function Th(t,e,n){let o=new Set;for(let r of t)r.op==="del"&&o.add(e[r.before].key);if(o.size===0)return false;for(let r of t)if(r.op==="ins"&&o.has(n[r.after].key))return true;return false}function Mh(t,e,n){let o=e.length-t.length;if(o<=0)return null;if(n!==void 0&&Ph(t,e,n,o))return Nl(t.length,n,o);let r=0;for(;r<t.length&&t[r].strong===e[r].strong;)r+=1;let i=0;for(;i<t.length-r&&t[t.length-1-i].strong===e[e.length-1-i].strong;)i+=1;if(r+i!==t.length)return null;let s=e[r],a=e[r+o-1],l=r>0?t[r-1]:null;return l&&l.key===a.key&&l.strong!==a.strong||r<t.length&&t[r].key===s.key?null:Nl(t.length,r,o)}function Ph(t,e,n,o){if(!Number.isSafeInteger(n)||n<0||n>t.length)return false;for(let r=0;r<n;r+=1)if(t[r].strong!==e[r].strong)return false;for(let r=n;r<t.length;r+=1)if(t[r].strong!==e[r+o].strong)return false;return true}function Nl(t,e,n){let o=[];for(let r=0;r<e;r+=1)o.push({op:"eq",before:r,after:r});for(let r=e;r<e+n;r+=1)o.push({op:"ins",after:r});for(let r=e;r<t;r+=1)o.push({op:"eq",before:r,after:r+n});return o}function Ah(t){if(!Oe(t)||typeof t.insert!="string"||t.insert.length!==1)return false;let e=t.insert.charCodeAt(0);return e>=32&&(e<55296||e>57343)}var Dh=16;function Nh(t,e){let n=new Map;for(let o=0;o<Dh;o+=1){let r=[];for(let d of t){let c=r[r.length-1];c&&c[0].op==="eq"==(d.op==="eq")?c.push(d):r.push([d]);}let i=d=>{if(!d||d[0].op==="eq")return 0;let c=0;for(let u of d)u.op==="ins"&&(c+=1);return Math.max(c,d.length-c)},s=(d,c)=>d!==void 0&&d.some(u=>{if(u.op!=="del")return false;let f=e[u.before];return !jh(f)&&c.has(f.trail??"")}),a=false,l=[];if(r.forEach((d,c)=>{let u=new Set(d.map(p=>p.op==="eq"?e[p.before].trail??"":""));if(!(d[0].op==="eq"&&d.length<=i(r[c-1])&&d.length<=i(r[c+1])&&(s(r[c-1],u)||s(r[c+1],u))&&d.every(p=>p.op==="eq"&&Ah(e[p.before])))){for(let p of d)l.push(p);return}a=true;for(let p of d)p.op==="eq"&&l.push({op:"del",before:p.before});for(let p of d)p.op==="eq"&&(l.push({op:"ins",after:p.after}),n.set(p.after,p.before));}),t=l,!a)break}return Yh(t,n)}function Yh(t,e){if(e.size===0)return t;let n=new Map;for(let[r,i]of e)n.set(i,r);let o=[];for(let r=0;r<t.length;){let i=t[r];if(i.op==="eq"){o.push(i),r+=1;continue}let s=r;for(;s<t.length&&t[s].op!=="eq";)s+=1;let a=t.slice(r,s);if(r=s,a.some(l=>l.op==="ins"&&!e.has(l.after))){o.push(...a);continue}for(let l of a){if(l.op!=="del")continue;let d=n.get(l.before);o.push(d===void 0?l:{op:"eq",before:l.before,after:d});}}return o}function _h(t,e){for(let n=1;n<t.length;n+=1){let o=t[n];if(o.op!=="eq"||t[n-1].op!=="ins")continue;let r=n+1;for(;r<t.length&&t[r].op==="ins";)r+=1;let i=t[r-1];r===n+1||i.op!=="ins"||e[i.after].key===e[o.after].key&&t.splice(n,r-n,{op:"ins",after:o.after},...t.slice(n+1,r-1),{op:"eq",before:o.before,after:i.after});}return t}function Yl(t){let e=0,n=false;for(let o of t)o.op!=="eq"&&!n&&(e+=1),n=o.op!=="eq";return e}function Oe(t){return t.key.startsWith("c")}function Bh(t,e,n,o,r,i){let s=e,a=r,l=0;for(;;){for(;s<n&&!Oe(t[s]);)s+=1;for(;a<i&&!Oe(o[a]);)a+=1;if(s===n||a===i)return s===n&&a===i&&l>0;if(t[s].key!==o[a].key)return false;l+=1,s+=1,a+=1;}}var Uh=/"l":"del(Text|InstrText)"/,Fh=/\\"l\\":\\"(del|moveFrom)\\"/;function jh(t){let e=t.attributes.t;return typeof e=="string"&&Uh.test(e)?true:t.trail!==void 0&&Fh.test(t.trail)}function Ii(t){let e=0;for(let n of t)n.op==="eq"&&(e+=1);return e}function xi(t,e,n,o=false){let r=[],i=0,s=0;for(let[a,l]of [...n,[t.length,e.length]]){let d=_l(t,e,i,a,s,l,false),c=Bl(d,t,e);if(c.inRevision<c.equal){let g=_l(t,e,i,a,s,l,true),y=Bl(g,t,e);y.equal>=c.equal&&y.inRevision>c.inRevision&&(d=g);}for(let g of d.head)r.push(g);let u=d.tail;({i,j:s}=d);let{bEnd:f,aEnd:p}=d;if(Bh(t,i,f,e,s,p))for(;i<f||s<p;)i<f&&s<p&&Oe(t[i])&&Oe(e[s])?(r.push({op:"eq",before:i,after:s}),i+=1,s+=1):i<f&&!Oe(t[i])?(r.push({op:"del",before:i}),i+=1):(r.push({op:"ins",after:s}),s+=1);let h=o?zh(t,i,f,e,s,p):null;if(h){for(let g of h)r.push(g);i=f,s=p;}for(;i<f;i+=1)r.push({op:"del",before:i});for(;s<p;s+=1)r.push({op:"ins",after:s});for(let g of u)r.push(g);i=a,s=l,i<t.length&&s<e.length&&(r.push({op:"eq",before:i,after:s}),i+=1,s+=1);}return r}function zh(t,e,n,o,r,i){if(r===i||i-r>=n-e)return null;let s=null,a=()=>{if(s)return s;s=new Map;for(let c=e;c<n;c+=1){let{key:u}=t[c],f=t[c].trail??"",p=s.get(u);p||s.set(u,p=new Map);let h=p.get(f);h||p.set(f,h=[]),h.push(c);}return s},l=c=>{let u=[],f=e;for(let p=r;p<i;p+=1){let h=o[p],g=-1;if(c){let y=h.trail??"";for(let[w,S]of a().get(h.key)??[]){if(!Mn(w,y))continue;let I=Wh(S,f);I>=0&&(g<0||I<g)&&(g=I);}}for(let y=f;g<0&&y<n;y+=1)t[y].key===h.key&&(g=y);if(g<0)return null;for(;f<g;f+=1)u.push({op:"del",before:f});u.push({op:"eq",before:g,after:p}),f=g+1;}for(;f<n;f+=1)u.push({op:"del",before:f});return u};return ((i-r)*(n-e)<=zl?l(true):null)??l(false)}function Wh(t,e){let n=0,o=t.length;for(;n<o;){let r=n+o>>1;t[r]<e?n=r+1:o=r;}return n<t.length?t[n]:-1}function _l(t,e,n,o,r,i,s){let a=[],l=[],d=()=>{for(;;)if(n<o&&r<i&&t[n].key===e[r].key)a.push({op:"eq",before:n,after:r}),n+=1,r+=1;else if(n<o&&r<i&&!Oe(t[n])&&Oe(e[r]))a.push({op:"del",before:n}),n+=1;else if(n<o&&r<i&&Oe(t[n])&&!Oe(e[r]))a.push({op:"ins",after:r}),r+=1;else break},c=()=>{for(;;)if(o>n&&i>r&&t[o-1].key===e[i-1].key)o-=1,i-=1,l.unshift({op:"eq",before:o,after:i});else if(o>n&&i>r&&!Oe(t[o-1])&&Oe(e[i-1]))o-=1,l.unshift({op:"del",before:o});else if(o>n&&i>r&&Oe(t[o-1])&&!Oe(e[i-1]))i-=1,l.unshift({op:"ins",after:i});else break};return s?(c(),d()):(d(),c()),{head:a,tail:l,i:n,j:r,bEnd:o,aEnd:i}}function Bl(t,e,n){let o=0,r=0,i=null,s=null,a=false;for(let l of [t.head,t.tail])for(let d of l){if(d.op!=="eq")continue;o+=1;let c=e[d.before].trail??"",u=n[d.after].trail??"";if(c===u){r+=1;continue}(c!==i||u!==s)&&(a=Mn(c,u),i=c,s=u),a&&(r+=1);}return {equal:o,inRevision:r}}function Mn(t,e){if(t===e)return true;let n=Io.get(e);n===void 0&&(Io.size>=Ul&&Io.clear(),Io.set(e,n=new Map));let o=n.get(t);if(o!==void 0)return o;let r=new Set(JSON.parse(e||"[]").map(s=>JSON.stringify(s))),i=JSON.parse(t||"[]").every(s=>r.has(JSON.stringify(s)));return n.size>=Ul&&n.clear(),n.set(t,i),i}var Ul=1024,Io=new Map;function Si(t,e,n,o=true){let r=[],i=(f,p,h)=>t[p]?.strong===h.strong&&!Mn(t[f].trail??"",h.trail??"")&&Mn(t[p].trail??"",h.trail??""),s=0;for(;s<t.length&&s<e.length&&t[s].strong===e[s].strong&&!i(s,s+1,e[s]);)r.push([s,s]),s+=1;let a=t.length,l=e.length,d=[];for(;a>s&&l>s&&t[a-1].strong===e[l-1].strong&&!(a-2>=s&&i(a-1,a-2,e[l-1]));)a-=1,l-=1,d.unshift([a,l]);let c=a-s,u=l-s;if(o&&c>0&&u>0&&c*u<=zl){let f=u+1,p=new Uint32Array((c+1)*f),h=new Array(c),g=new Array(u);for(let I=0;I<c;I+=1)h[I]=t[s+I].strong;for(let I=0;I<u;I+=1)g[I]=e[s+I].strong;let y=(I,b)=>h[I]===g[b];for(let I=c-1;I>=0;I-=1){let b=h[I],v=I*f,L=v+f;for(let m=u-1;m>=0;m-=1){let k=p[L+m],O=p[v+m+1];p[v+m]=b===g[m]?p[L+m+1]+1:k>O?k:O;}}let w=0,S=0;for(;w<c&&S<u;){let I=()=>p[(w+1)*f+S]!==p[w*f+S]||Mn(t[s+w].trail??"",e[s+S].trail??"");if(y(w,S))I()&&(r.push([s+w,s+S]),S+=1),w+=1;else {let b=p[(w+1)*f+S],v=p[w*f+S+1];b>v||b===v&&!n?w+=1:S+=1;}}}for(let f of d)r.push(f);return r}function Kl(t,e){let n=null;for(let o of Object.keys(t))o in e||((n??={})[o]=null);for(let o of Object.keys(e))t[o]!==e[o]&&((n??={})[o]=e[o]);return n}var vi=64;function Li(t,e,n){for(let o=0;o<bi;o+=1){let r=t.origin("move",e,n)??t.origin("restore",e,n);if(!r)break;let i=r.client,s=r.clock+n-r.firstClock;if(i===e&&s===n)break;e=i,n=s;}return [e,n]}function Vl(t,e){let n=ke(e);return n?Ri(t,n.client,n.clock):e}function Ri(t,e,n){let[o,r]=Li(t,e,n);return `${o}:${r}`}function ot(t,e,n){return Ri(dt(t),e.id.client,e.id.clock+n)}function ki(t,e){return e===t.id.clock?t.origin:{client:t.id.client,clock:e-1}}function $h(t,e,n){let o=[],r=e.left;if(r&&e.origin&&!r.deleted&&!(r.content instanceof z.ContentFormat)&&r.id.client===e.origin.client&&r.id.clock+r.length-1===e.origin.clock)return {live:n(r,e.origin.clock),deleted:o};let i=e.origin;for(let s=0;i&&s<vi;s+=1){let a=H(t,i);if(!a)break;if(!a.deleted){if(a.content instanceof z.ContentFormat){i=ki(a,i.clock);continue}return {live:n(a,i.clock),deleted:o}}let l=n(a,i.clock);l&&o.push(l),i=ki(a,i.clock);}return {live:null,deleted:o}}function Kh(t,e,n){let o=e.rightOrigin;for(let r=0;o&&r<vi;r+=1){let i=H(t,o);if(!i)return null;if(i.deleted||!(i.content instanceof z.ContentFormat))return n(i,o.clock);o=i.rightOrigin;}return null}function Jl(t,e,n){return e.deleted||e.content instanceof z.ContentString?Ri(t,e.id.client,n):null}function Se(t,e){return t.moved[e]===true||t.restored[e]===true}function Vh(t,e,n){let[o,r]=Li(e,n.id.client,n.id.clock),i=t.doc;return i&&H(i,{client:o,clock:r})?.parent===t?[o,r]:null}function Jh(t,[e,n],o){return !o||o.identity===tt||t.followStart(e,n)===n?o:{identity:`${e}:${n-1}`,before:false}}function Hh(t,e,n){return e?e.identity===tt||e.before?[]:[Vl(t,e.identity)]:[...n.deleted,...n.live===null?[]:[n.live]]}function on(t){let e=be(t),n=dt(t),o=[],r=[],i=[],s=[],a=[],l=[],d=[],c=[],u=t.doc?Qe(t.doc):null,f=[],p=[],h=[],g=[],y=false,w=t.doc,S=(I,b)=>Jl(n,I,b);for(let I=e;I;I=I.right){if(I.deleted||!I.countable)continue;let b=I.content instanceof z.ContentString,v=b||I.content instanceof z.ContentEmbed,L=A=>b&&n.origin("move",I.id.client,A)!==null,m=A=>b&&!L(A)&&n.origin("restore",I.id.client,A)!==null,k=m(I.id.clock),O=L(I.id.clock)||k,P=k?Vh(t,n,I):null,j=v&&(!O||P!==null),K=P?n.follow(...P):null,Y=v?P?Jh(n,P,K):n.follow(I.id.client,I.id.clock):null,V=Y&&Y.identity!==tt?{...Y,identity:Vl(n,Y.identity)}:Y,q=w?$h(w,I,S):{live:null,deleted:[]},ee=null;if(j&&V&&(q.deleted.length>0||q.live===null)?ee=[V]:j&&q.deleted.length>0&&(ee=q.deleted.map(A=>({identity:A,before:false}))),ee&&(y=true),v&&!O&&!Y&&q.live===null&&w){let A=Kh(w,I,S);A&&(ee=[...ee??[],{identity:A,before:true}]);}let ne=O?Hh(n,K,q):null;for(let A=0;A<I.length;A+=1){if(s.push(`${I.id.client}:${I.id.clock+A}`),a.push(A>0?`${I.id.client}:${I.id.clock+A-1}`:I.origin?`${I.origin.client}:${I.origin.clock}`:null),b){let[J,he]=Li(n,I.id.client,I.id.clock+A);o.push(`${J}:${he}`),r.push(J),i.push(he);}else o.push(null),r.push(-1),i.push(-1);l.push(L(I.id.clock+A)),d.push(m(I.id.clock+A)),c.push(b&&u!==null&&u.isDeleted(r[r.length-1],i[i.length-1])),p.push(A===0),h.push(A===0?q.live:null),g.push(A===0?ne:null),f.push(A===0?ee:null);}}return {ids:o,clients:r,clocks:i,items:s,origins:a,moved:l,restored:d,deleted:c,anchors:f,hasAnchors:y,starts:p,lefts:h,copiedAfter:g}}function Oi(t,e,n){let o=t.doc;if(!o)return false;let r=dt(t),i=e.origin;for(let s=0;i&&s<vi;s+=1){let a=H(o,i);if(!a)return false;let l=Jl(r,a,i.clock);if(l!==null&&n(l))return true;i=ki(a,i.clock);}return false}var ct="splitPoints",Xh=/^\d{1,16}:\d{1,16}$/,Gh=/^\d{1,16}:\d{1,16}\+?$/;function qh(t){if(!t)return null;let e=null;for(let n=be(t);n;n=n.right)!n.deleted&&typeof n.content.str=="string"&&(e=n);return e?ot(t,e,e.length-1):null}function Xl(t,e){if(!t||!e)return qh(t);let{ids:n}=e.identities;for(let o=n.length-1;o>=0;o-=1)if(!e.hidden.has(o)&&n[o])return n[o];return null}function Gl(t){let e=t?.get(ct);return typeof e=="string"&&e.length<=4096?e.split(`
|
|
11
|
+
`):null}function An(t){let e=Gl(t)?.[0],n=e?/^#(\d{1,16}):(\d{1,16})$/.exec(e):null;return n?z.createID(Number(n[1]),Number(n[2])):null}function ut(t){let e=Gl(t);if(!e)return [];let n=[];for(let o of e.filter(r=>!r.startsWith("#")).slice(-4)){let r=o.lastIndexOf("@"),i=o.slice(r+1);if(r<=0||!Gh.test(i))return [];n.push({source:o.slice(0,r),at:i});}return n}function ko(t,e){return [`#${e}`,...t.slice(-4).map(n=>`${n.source}@${n.at}`)].join(`
|
|
12
|
+
`)}function Qh(t,e,n){let o=0,r=t._start;for(;r;r=r.right)if(!(r.deleted||!r.countable)){if(r===e){let i=r.content.getContent().indexOf(n);return i<0?-1:o+i}o+=r.length;}return -1}var Pn=new WeakSet,wo=new WeakMap,ql=(t,e)=>{let n=t.content.getContent().indexOf(e);return n<0?null:`${t.id.client}:${t.id.clock+n}`};function Ql(t){t&&Pn.add(t);}function Zl(){Pn=new WeakSet,wo=new WeakMap;}function ed(t,e,n,o,r,i=()=>false){if(!n)return;let s=null;for(let a of o){let l=t(a);if(!l)continue;let d=null,c=null;for(let y of r)if(!y.deleted&&(d=ql(y,a))){c=y;break}if(!d||!c)continue;let u=Pn.has(l)&&!wo.has(l);if(u&&wo.set(l,d),u&&l.has(ct)){Pn.delete(l);continue}s??=n.toArray();let f=Qh(n,c,a),p=f>0?s[f-1]:void 0;if(!u&&(p===void 0||!i(p)))continue;let h=ut(p===void 0?void 0:t(p)),g=u&&p!==void 0?e(p):null;g&&(h=[...h,{source:p,at:`${g}+`}]),h.length>0&&l.set(ct,ko(h,d));}}function td(t,e,n,o,r){if(!e||o<=0)return;let i=[],s=new Set,a=0,l=e._start;for(;l&&a<n+o;l=l.right){if(l.deleted||!l.countable)continue;let u=Math.max(n-a,0),f=Math.min(n+o-a,l.length);for(let p=u;p<f;p+=1)i.push({item:l,at:p});u===0&&f===l.length&&s.add(l),a+=l.length;}let d=(u,f)=>u.content.getContent()[f],c=(u,f)=>!i.some(p=>p.item===u&&p.at===f);for(let{item:u,at:f}of i){let p=d(u,f);if(!r(p))continue;let h=ut(t(p));if(h.length===0)continue;let g=u,y=f+1;for(;y<u.length&&!c(u,y);)y+=1;if(y>=u.length){let L=[u];for(g=u.right;g;g=g.right)if(!(g.deleted&&!L.some(m=>So(g.origin,m)))){if(!L.some(m=>So(g.origin,m))){g=null;break}if(!g.deleted&&!s.has(g))break;L.push(g);}if(!g)continue;for(y=0;y<g.length&&!c(g,y);)y+=1;if(y>=g.length)continue}let w=d(g,y),S=t(w),I=S?`${g.id.client}:${g.id.clock+y}`:null;if(!S||!I)continue;let b=An(S),v=b&&So(b,g)?ut(S):[];v.some(L=>L.source===h.at(-1).source)||S.set(ct,ko([...h,...v],I));}}function nd(t,e,n){for(let o of it(t,n))if(!(o.deleted||!(o.parent instanceof z.Array))&&o.content instanceof z.ContentAny)for(let r of o.content.getContent()){if(typeof r!="string")continue;let i=r,s=e(i),a=An(s);if(!s||!a||So(a,o))continue;let l=H(t,a);for(let c=0;l&&l!==o&&l.redone&&c<64;c+=1)l=H(t,l.redone);let d=l===o?ql(o,i):null;d&&s.set(ct,ko(ut(s),d));}}function So(t,e){return t!==null&&t.client===e.id.client&&t.clock>=e.id.clock&&t.clock<e.id.clock+e.length}function Ei(t,e){for(let n=t.length-1;n>=0;n-=1)if(t[n].source===e)return t[n].at;return null}function od(t){for(let e of t){if(e.before.length>0)continue;let n=e.after.find(o=>o.attributes[lt])?.attributes[lt];if(n&&Xh.test(n))for(let o of t){if(o===e||!o.identities.includes(n))continue;let r=ut(o.record),i=wo.get(e.record);if(!i||!Pn.delete(e.record))break;e.record.set(ct,ko([...r,{source:o.id,at:n}],i));break}}}function Zh(t){for(let e of Object.keys(t))if(e.startsWith(de)&&t[e]===null)return true;return false}function rd(t,e,n,o,r){let i=new Array(e.length).fill(null),s=false;for(let l of o){if(l.op==="del"&&(i[l.before]="del"),l.op!=="eq")continue;let d=r(e[l.before].attributes,n[l.after].attributes);!d||!Zh(d)||(i[l.before]=d,s=true);}if(!s)return;let a=0;for(;a<i.length;){if(i[a]!=="del"){a+=1;continue}let l=a;for(;l<i.length&&i[l]==="del";)l+=1;let d=a>0?i[a-1]:null,c=l<i.length?i[l]:null,u=d&&d!=="del"?d:c&&c!=="del"?c:null;if(u){let f={...Tt(u)};for(let h=a;h<l;h+=1)for(let g of Object.keys(e[h].attributes))(g.startsWith(de)||g===xe)&&(f[g]=null);let p=a;for(let h=a+1;h<=l;h+=1){if(h<l&&e[h].position===e[h-1].position+1)continue;let g=e[p].position;t.format(g,e[h-1].position-g+1,f),p=h;}}a=l;}}function Mi(t){let e=[],n=null;return t.ids.forEach((o,r)=>{if(o===null||t.deleted[r])return;let i=t.clients[r],s=t.clocks[r],a=t.moved[r]?"move":t.restored[r]?"restore":"original";if(n&&n.client===i&&n.end===s&&n.kind===a){n.end+=1;return}n&&e.push(n),n={client:i,start:s,end:s+1,kind:a};}),n&&e.push(n),e}var Ci=class{constructor(e){this.bound=e;}bound;entries=[];add(e){this.entries.splice(this.firstAtOrAfter(e.run.start),0,e);}remove(e){for(let n=this.firstAtOrAfter(e.run.start);n<this.entries.length;n+=1){let o=this.entries[n];if(o.run.start!==e.run.start)break;if(o.paragraph===e.paragraph&&o.run.end===e.run.end)return this.entries.splice(n,1),true}return false}collect(e,n,o){for(let r=this.firstAtOrAfter(n)-1;r>=0;r-=1){let i=this.entries[r];if(i.run.start+this.bound<=e)break;i.run.end>e&&o.push(i);}}firstAtOrAfter(e){let n=0,o=this.entries.length;for(;n<o;){let r=n+o>>1;this.entries[r].run.start<e?n=r+1:o=r;}return n}},Ti=class{classes=new Map;add(e){let n=id(e.run.end-e.run.start),o=this.classes.get(n);o||this.classes.set(n,o=new Ci(2**(n+1))),o.add(e);}remove(e){let n=id(e.run.end-e.run.start),o=this.classes.get(n);o?.remove(e)&&o.entries.length===0&&this.classes.delete(n);}overlapping(e,n){let o=[];for(let r of this.classes.values())r.collect(e,n,o);return o}};function id(t){return t<=1?0:31-Math.clz32(t)}var Dn=class{runsOf=new Map;tables={original:new Map,move:new Map,restore:new Map};update(e,n){let o=this.runsOf.get(e)??[],r=u=>`${u.client}:${u.start}:${u.end}:${u.kind}`,i=u=>{let f=new Map;for(let p of u){let h=f.get(r(p));h?h.push(p):f.set(r(p),[p]);}return f},s=i(o),a=i(n),l=new Set,d=[],c=u=>{for(let f of Object.values(this.tables))for(let p of f.get(u.client)?.overlapping(u.start,u.end)??[])p.paragraph!==e&&l.add(p.paragraph);};for(let[u,f]of s)for(let p of f.slice(a.get(u)?.length??0))this.tables[p.kind].get(p.client)?.remove({run:p,paragraph:e}),d.push(p),p.kind!=="original"&&c(p);for(let[u,f]of a)for(let p of f.slice(s.get(u)?.length??0)){let h=this.tables[p.kind],g=h.get(p.client);g||(g=new Ti,h.set(p.client,g)),g.add({run:p,paragraph:e}),d.push(p),p.kind!=="original"&&c(p);}return n.length>0?this.runsOf.set(e,[...n]):this.runsOf.delete(e),{affected:l,changed:d}}overlapping(e,n,o,r){return this.tables[e].get(n)?.overlapping(o,r)??[]}hasCopies(e){return this.tables.move.has(e)||this.tables.restore.has(e)}holdersOf(e,n,o){return (this.tables[e].get(n)?.overlapping(o,o+1)??[]).map(r=>r.paragraph)}holders(e,n){return ["original","move","restore"].flatMap(o=>this.holdersOf(o,e,n))}contested(){let e=new Set,n=[];for(let[o,r]of this.runsOf)for(let i of r){if(i.kind==="original")continue;let s=false;for(let a of ["move","restore"])for(let l of this.overlapping(a,i.client,i.start,i.end))l.paragraph!==o&&(s=true,e.add(o),e.add(l.paragraph));s&&n.push(i);}return {paragraphs:e,runs:n}}clear(){this.runsOf.clear();for(let e of Object.values(this.tables))e.clear();}};var sd=4096;function ad(t,e){let n=ke(e),o=n?H(t,n):null,r=o?.parent;if(!o||!(r instanceof z.Text))return null;for(let i=r._item;i;i=i.parent instanceof z.AbstractType?i.parent._item:null)if(i.deleted)return null;return {item:o,text:r}}function eg(t){let e=new Map,n=0;for(let o=be(t);o;o=o.right)for(let r=0;r<o.length;r+=1,n+=1){let i=ot(t,o,r);e.has(i)||e.set(i,n);}return e}function tg(t,e){let n=dt(t);for(let o=be(t);o;o=o.right)for(let r=0;r<o.length;r+=1){if(!n.origin("move",o.id.client,o.id.clock+r))continue;let i=e.get(ot(t,o,r));if(i!==void 0)return i}return null}var vo=class{constructor(e,n){this.textOf=e;this.order=n;}textOf;order;places=new Map;keys=new Map;sourceSegments(e,n,o,r){let i=this.textOf(e)?.doc,s=[],a=o+r;for(let l=o;l<a;){let d=null;try{d=i&&l<z.getState(i.store,n)?z.getItem(i.store,z.createID(n,l)):null;}catch{d=null;}let c=d?Math.min(a,d.id.clock+d.length):a,u=d&&i?ad(i,`${n}:${l}`)?.text??null:null,f=s.at(-1);f&&f.source===u?f.end=c-o:s.push({start:l-o,end:c-o,source:u}),l=Math.max(c,l+1);}return s}sourceOf(e,n){let o=this.textOf(e)?.doc;return (o&&ad(o,n)?.text)??null}compare(e,n,o){if(e===n)return 0;if(o){let r=this.keyOf(e,o),i=this.keyOf(n,o);if(r!==i)return r===null?-1:i===null?1:r-i}return this.order(e,n)}lastOf(e,n,o){let r=o&&e.length>1?this.sourceOf(e[0],n):null,i=null;for(let s of e)(i===null||this.compare(s,i,r)>0)&&(i=s);return i}forget(e){this.keys.delete(e);let n=this.textOf(e);n&&this.places.delete(n);}clear(){this.keys.clear(),this.places.clear();}keyOf(e,n){let o=this.places.get(n);o||(this.places.size>=sd&&this.places.clear(),o=eg(n),this.places.set(n,o));let r=this.keys.get(e),i=r?.get(n);if(i&&i.places===o)return i.key;let s=this.textOf(e),a=s?tg(s,o):null;return r||(this.keys.size>=sd&&this.keys.clear(),r=new Map,this.keys.set(e,r)),r.set(n,{places:o,key:a}),a}};var ld=new Set,ng=64;function dd(t){let e=new Set;return t.ids.forEach((n,o)=>{n!==null&&Se(t,o)&&e.add(n);}),e}function og(t){let e=Mi(t).map(o=>({...o,kind:"original"})),n=o=>{let r=ke(o);r&&e.push({client:r.client,start:r.clock,end:r.clock+1,kind:"original"});};for(let o of t.anchors)for(let r of o??[])n(r.identity);for(let o of t.copiedAfter)for(let r of o??[])n(r);return e}function Pi(t,e){if(t.positions.every((r,i)=>e.items[r]===t.items[i]))return [...t.positions];let o=new Map;return e.items.forEach((r,i)=>o.set(r,i)),t.items.flatMap(r=>{let i=o.get(r);return i===void 0?[]:[i]})}function rg(t,e,n,o){if(o.size===0)return [];let{ids:r}=e,i=new Set;r.forEach((l,d)=>{l!==null&&!n.has(d)&&i.add(l);});let s=[];for(let l=1;l<r.length;l+=1){let d=r[l-1];if(n.has(l)||!o.has(l-1)||!d||!i.has(d))continue;let c=[];for(let u=l;u<r.length&&!n.has(u);u+=1)c.push(u);s.push({source:t,after:d,before:false,positions:c,identities:c.map(u=>r[u]??null),items:c.map(u=>e.items[u])}),l+=c.length;}let a=new Set;for(let l of s)for(let d of l.positions)a.add(d);for(let l=0;l<r.length;l+=1){if(!e.starts[l]||n.has(l)||a.has(l))continue;let d=e.anchors[l]?.find(f=>f.before);if(!d||!i.has(d.identity))continue;let c=l+1;for(;c<r.length&&!e.starts[c]&&!n.has(c);)c+=1;if(c>=r.length||!o.has(c)||r[c]!==d.identity)continue;let u=[];for(let f=l;f<c;f+=1)u.push(f);for(let f of u)a.add(f);s.push({source:t,after:d.identity,before:true,positions:u,identities:u.map(f=>r[f]??null),items:u.map(f=>e.items[f])});}for(let l of s)for(let d of l.positions)n.add(d);return s}var Lo=class{constructor(e,n,o,r,i,s=()=>null){this.textOf=e;this.isDeleted=n;this.viewsChanged=r;this.originalParagraph=i;this.undoneInto=s;this.holders=new vo(e,o);}textOf;isDeleted;viewsChanged;originalParagraph;undoneInto;index=new Dn;sources=new Set;outgoingOf=new Map;incomingOf=new Map;targetsOf=new Map;followingCopiesOf=new Map;followingCopies=new Map;dependencies=new Dn;pending=new Set;ownChanges=new Set;readsOtherSources=new Set;followingIdsOf=new Map;joinedFrom=new Map;typedAnchored=new Map;typedOf=new Map;typedStale=new Set;typedBuilt=false;identities=new Map;recent=new Set;holders;paragraphChanged(e){let n=this.textOf(e),o=this.isDeleted(e);this.invalidate(e);let r=n?this.identitiesOf(e,n):null,{affected:i,changed:s}=this.index.update(e,r&&!o?Mi(r):[]),a=this.sources.has(e),l=!!n&&!!r&&(o?n.length>0:r.hasAnchors);l?this.sources.add(e):this.sources.delete(e),this.identities.has(e)&&this.touch(e);for(let d of s)for(let c of this.dependencies.overlapping("original",d.client,d.start,d.end))this.pending.add(c.paragraph);(a||l)&&(this.pending.add(e),this.ownChanges.add(e));for(let d of this.joinedFrom.get(e)??[])this.pending.add(d);for(let d of this.targetsOf.get(e)??[])i.add(d);return i.delete(e),i}settle(){if(this.pending.size===0)return;for(let r of this.readsOtherSources)this.sources.has(r)&&this.pending.add(r);this.readsOtherSources.clear();let e=[...this.pending],n=[...this.ownChanges];this.pending.clear(),this.ownChanges.clear();let o=this.relocate(e);for(let r of n)for(let i of this.targetsOf.get(r)??[])o.add(i);o.size>0&&this.viewsChanged(o);}shown(e,n){this.settle();let o=this.identitiesOf(e,n),r=new Set,i=new Set,s=new Set,{clients:a,clocks:l}=o,d=dd(o);for(let p=0;p<a.length;){let h=p+1;for(;h<a.length&&a[h]===a[p]&&l[h]===l[h-1]+1&&o.moved[h]===o.moved[p]&&o.restored[h]===o.restored[p];)h+=1;let g=a[p],y=Se(o,p);if(g>=0){let w=b=>this.index.overlapping(b,g,l[p],l[h-1]+1).filter(v=>v.paragraph!==e),S=w("move"),I=w("restore");if(S.length>0||I.length>0||y){let b=l[p],v=y?e:null,L=this.coverage("move",S,g,b,h-p,v),m=this.coverage("restore",I,g,b,h-p,v);for(let k=p;k<h;k+=1){let O=k-p,P={move:L.any[O]>0,laterMove:L.later[O]>0,restore:m.any[O]>0,laterRestore:m.later[O]>0};this.hides(o,k,P,i,s)&&r.add(k);}}if(!y&&d.size>0)for(let b=p;b<h;b+=1)d.has(o.ids[b])&&r.add(b);}p=h;}let c=this.outgoingOf.get(e);if(c)for(let p of Pi(c,o))r.add(p);this.followingCopies.size>0&&o.ids.forEach((p,h)=>{p===null||Se(o,h)||this.followingCopies.has(p)&&r.add(h);}),o.deleted.forEach((p,h)=>{p&&r.add(h);});let u=rg(e,o,r,s),f=this.distinctIncoming(e,o,r);return {identities:o,hidden:r,incoming:u.length>0?[...f,...u]:f}}distinctIncoming(e,n,o){let r=this.incomingOf.get(e)??[];if(r.length===0)return r;let i=new Set;n.ids.forEach((a,l)=>{a!==null&&!o.has(l)&&i.add(a);});let s=[];for(let a of r){let l=a.positions.flatMap((d,c)=>{let u=a.identities[c]??null;return u!==null&&i.has(u)?[]:(u!==null&&i.add(u),[c])});l.length===a.positions.length?s.push(a):l.length>0&&s.push({...a,positions:l.map(d=>a.positions[d]),identities:l.map(d=>a.identities[d]??null),items:l.map(d=>a.items[d])});}return s}hides(e,n,o,r,i){let s=e.ids[n],a=false;return Se(e,n)&&r.has(s)&&i.add(n),e.moved[n]?a=r.has(s)||o.laterMove:e.restored[n]?a=r.has(s)||o.move||o.laterRestore:a=o.move||o.restore,Se(e,n)&&r.add(s),a}coverage(e,n,o,r,i,s){let a=new Int32Array(i+1),l=new Int32Array(i+1),d=s!==null&&e==="move"&&n.length>0?this.holders.sourceSegments(s,o,r,i):[{start:0,end:i,source:null}];for(let c of n){let u=Math.max(c.run.start,r)-r,f=Math.min(c.run.end,r+i)-r;if(!(u>=f)&&(a[u]+=1,a[f]-=1,s!==null))for(let p of d){let h=Math.max(u,p.start),g=Math.min(f,p.end);h>=g||this.holders.compare(c.paragraph,s,p.source)>0&&(l[h]+=1,l[g]-=1);}}for(let c=1;c<=i;c+=1)a[c]+=a[c-1],l[c]+=l[c-1];return {any:a,later:l}}holdersOf(e){let n=ke(e);return n?this.index.holders(n.client,n.clock):[]}holdsCopyIn(e,n,o){return this.index.hasCopies(e)?this.index.overlapping("move",e,n,o).length>0||this.index.overlapping("restore",e,n,o).length>0:false}shownMovedCopy(e){let n=ke(e);if(!n||!this.index.hasCopies(n.client))return null;let o=this.index.holdersOf("move",n.client,n.clock);return this.holders.lastOf(o,e,true)}shownCopy(e){let n=ke(e);if(!n)return null;let{client:o,clock:r}=n;return this.index.hasCopies(o)?this.holders.lastOf(this.index.holdersOf("move",o,r),e,true)??this.holders.lastOf(this.index.holdersOf("restore",o,r),e,false):null}orderChanged(){let{paragraphs:e,runs:n}=this.index.contested();for(let o of n)for(let r of this.dependencies.overlapping("original",o.client,o.start,o.end))this.pending.add(r.paragraph);return e}targetsFor(e){return this.settle(),this.targetsOf.get(e)??ld}placedTargetsFor(e){return this.targetsOf.get(e)??ld}invalidate(e){this.identities.delete(e),this.holders.forget(e),this.recent.delete(e),this.typedStale.add(e);}identitiesOf(e,n){let o=this.identities.get(e);if(o?.text===n)return this.touch(e),o.identities;let r=on(n);return this.identities.set(e,{text:n,identities:r}),this.touch(e),r}touch(e){if(this.recent.delete(e),this.sources.has(e)||(this.recent.add(e),this.recent.size<=ng))return;let n=this.recent.values().next().value;this.recent.delete(n),this.identities.delete(n);}clear(){this.identities.clear(),this.holders.clear(),this.recent.clear(),this.index.clear(),this.sources.clear(),this.outgoingOf.clear(),this.incomingOf.clear(),this.targetsOf.clear(),this.followingCopiesOf.clear(),this.followingCopies.clear(),this.dependencies.clear(),this.pending.clear(),this.ownChanges.clear(),this.joinedFrom.clear(),this.typedAnchored.clear(),this.typedOf.clear(),this.typedStale.clear(),this.typedBuilt=false;}relocate(e){this.followingIdsOf.clear();let n=new Set;for(let d of e)for(let c of this.targetsOf.get(d)??[])n.add(c);let o=new Map;for(let d of n)o.set(d,JSON.stringify(this.incomingOf.get(d)??[]));let r=new Map;for(let d of e)r.set(d,JSON.stringify(this.outgoingOf.get(d)?.positions??[]));let i=new Set(e);for(let d of n){let c=(this.incomingOf.get(d)??[]).filter(u=>!i.has(u.source));c.length>0?this.incomingOf.set(d,c):this.incomingOf.delete(d);}let s=new Map,a=d=>{s.has(d)||s.set(d,this.followingCopies.has(d));};for(let d of e){this.targetsOf.delete(d),this.outgoingOf.delete(d);for(let p of this.followingCopiesOf.get(d)??[])a(p),this.countFollowingCopy(p,-1);this.followingCopiesOf.delete(d);let c=this.sources.has(d)?this.textOf(d):null,u=c?this.identitiesOf(d,c):null;if(this.dependencies.update(d,u?og(u):[]),!u)continue;let f=new Map;for(let p of this.followingOf(d,u)){let h=p.target??this.shownCopy(p.after),g=this.incomingOf.get(h)??[];g.push(p),this.incomingOf.set(h,g);let y=this.targetsOf.get(d)??new Set;y.add(h),this.targetsOf.set(d,y),p.positions.forEach((w,S)=>{let I=p.identities[S]??null;if(f.set(w,I),I===null||!Se(u,w))return;let b=this.followingCopiesOf.get(d)??new Set;b.has(I)||(b.add(I),this.followingCopiesOf.set(d,b),a(I),this.countFollowingCopy(I,1));}),o.has(h)||o.set(h,"[]");}if(f.size>0&&!this.isDeleted(d)){let p=[...f.keys()].sort((h,g)=>h-g);this.outgoingOf.set(d,{positions:p,identities:p.map(h=>f.get(h)??null),items:p.map(h=>u.items[h])});}}for(let d of o.keys())this.incomingOf.get(d)?.sort((c,u)=>(c.source<u.source?-1:c.source>u.source?1:0)||c.positions[0]-u.positions[0]);let l=new Set;for(let[d,c]of r)JSON.stringify(this.outgoingOf.get(d)?.positions??[])!==c&&l.add(d);for(let[d,c]of o)JSON.stringify(this.incomingOf.get(d)??[])!==c&&l.add(d);for(let[d,c]of s)if(c!==this.followingCopies.has(d))for(let u of this.holdersOf(d))l.add(u);return l}countFollowingCopy(e,n){let o=(this.followingCopies.get(e)??0)+n;o>0?this.followingCopies.set(e,o):this.followingCopies.delete(e);}followingOf(e,n){let o=[],r=null,i=dd(n),s=null,a=l=>(s||(s=new Set,n.ids.forEach((d,c)=>{d&&n.moved[c]&&!n.restored[c]&&s.add(d);})),s.has(l));for(let l=0;l<n.ids.length;l+=1){let d=n.ids[l]??null,c=Se(n,l),u=d===null?null:this.shownCopy(d),f=u!==null&&!(u===e&&n.restored[l]&&!a(d));if(n.deleted[l]||d!==null&&(f||!c&&i.has(d))){r=null;continue}let p=!this.isDeleted(e),h=r!==null&&(!n.starts[l]||l>0&&n.lefts[l]===n.ids[l-1]),g=this.leadingAnchor(e,p,n.anchors[l])??(p||h?void 0:this.movedAfter(e,n,l));if(g){r={source:e,after:g.identity,before:g.before,...g.target?{target:g.target}:{},...g.atStart?{atStart:true}:{},positions:[l],identities:[d],items:[n.items[l]]},o.push(r);continue}if(r&&h){r.positions.push(l),r.identities.push(d),r.items.push(n.items[l]);continue}r=null;}return o}typedSources(){if(!this.typedBuilt){this.typedBuilt=true;for(let e of this.sources)this.typedStale.add(e);}for(let e of this.typedStale)this.readTyped(e);return this.typedStale.clear(),this.typedAnchored}readTyped(e){for(let s of this.typedOf.get(e)??[]){let a=(this.typedAnchored.get(s)??[]).filter(l=>l.source!==e);a.length>0?this.typedAnchored.set(s,a):this.typedAnchored.delete(s);}this.typedOf.delete(e);let n=this.sources.has(e)?this.textOf(e):null;if(!n)return;let o=this.identitiesOf(e,n),r=new Set,i=null;o.ids.forEach((s,a)=>{if(o.starts[a]&&(i=o.anchors[a]??null),!s||Se(o,a)||!i)return;let l=this.typedAnchored.get(s)??[];l.push({source:e,anchors:i}),this.typedAnchored.set(s,l),r.add(s);}),r.size>0&&this.typedOf.set(e,[...r]);}follows(e){let n=!this.isDeleted(e.source);return this.leadingAnchor(e.source,n,e.anchors)!==void 0}followsOutOf(e,n){if(this.isDeleted(e)||!this.sources.has(e))return false;let o=this.followingIdsOf.get(e);if(!o){let r=this.textOf(e),i=new Set;if(r)for(let s of this.followingOf(e,this.identitiesOf(e,r)))for(let a of s.identities)a&&i.add(a);o=i,this.followingIdsOf.set(e,o);}return o.has(n)}leadingAnchor(e,n,o){for(let r of o??[]){if(r.before&&n)continue;let i=this.shownCopy(r.identity);if(i!==null){if(i!==e)return r;if(this.shownMovedCopy(r.identity)===e)return}}}movedAfter(e,n,o){let r=n.ids[o];if(!r)return;let i=this.holdersOf(r);if(!Se(n,o)&&i.length>0||(this.readsOtherSources.add(e),(this.typedSources().get(r)??[]).some(d=>d.source!==e&&this.follows(d)))||i.some(d=>d!==e&&this.followsOutOf(d,r)))return;for(let d of n.copiedAfter[o]??[]){let c=this.shownCopy(d);if(c!==null&&c!==e)return {identity:d,before:false}}if(n.moved[o]){let d=this.originalParagraph(r);if(d!==null&&d!==e&&!this.isDeleted(d))return {identity:r,before:false,target:d}}let a=this.undoneInto(e);if(a===null||a.paragraph===e)return;let l=this.joinedFrom.get(a.paragraph)??new Set;if(l.add(e),this.joinedFrom.set(a.paragraph,l),!this.isDeleted(a.paragraph))return {identity:r,before:false,target:a.paragraph,...a.atStart?{atStart:true}:{}}}};function ig(t,e){let n=[],o=0;for(let r of e){let i=r.op==="eq"?"eq":"change",s=n[n.length-1];s&&s.kind===i?s.steps.push(r):n.push({kind:i,steps:[r],after:o}),r.op==="eq"&&(o=t[r.before].position+1);}return n}function sg(t,e){let n=[];for(let o of t){let r=n[n.length-1];r&&e(r[r.length-1])===e(o)?r.push(o):n.push([o]);}return n}function Ai(t,e){if(!t)return null;if(e>0){let o=t.ids[e-1];return o&&Se(t,e-1)?o:null}let n=t.ids[0];return n&&Se(t,0)?`^${n}`:null}function Di(t,e,n,o,r,i){let s=Ft(t,e,n,o);!r||!s||!Oi(t,s,i)||Le(t.doc).markFollow(s.id.client,s.id.clock,n.length,cd(r,e));}function cd(t,e){return e>0?t.ids[e-1]??tt:t.ids[0]?`^${t.ids[0]}`:tt}function ag(t,e,n,o,r,i){let s=Ft(t,e,n,o);if(!s)return;let a=r??(i&&Oi(t,s,i.hasShownCopy)?cd(i.identities,e):null);a&&Le(t.doc).markFollow(s.id.client,s.id.clock,1,a);}function Ni(t,e,n,o,r){let i=Ft(t,e,n,o);i&&Le(t.doc).markFollow(i.id.client,i.id.clock,n.length,r);}function ud(t){let e=[];for(let n of t.toDelta()){let o=n.attributes??{},r=typeof n.insert=="string"?n.insert.length:1;for(let i=0;i<r;i+=1)e.push(o);}return e}function lg(t,e,n,o,r,i,s){let a=ig(e,o),l=null,d=f=>f<=0?{}:(l??=ud(t),l[f-1]??{}),c=new Map,u=(f,p)=>{let h=c.get(f);h||c.set(f,h=new Map);let g=h.get(p);if(g===void 0){let y=Kl(f,s(f,p,false));g=y&&{changes:y,key:JSON.stringify(y),from:ve(f)},h.set(p,g);}return g};rd(t,e,n,o,(f,p)=>u(f,p)?.changes??null);for(let f=a.length-1;f>=0;f-=1){let p=a[f];if(p.kind==="eq"){let v=[];for(let m of p.steps){let k=u(e[m.before].attributes,n[m.after].attributes);k&&v.push({...k,position:e[m.before].position});}let L=[];for(let m of v){let k=L[L.length-1],O=k?.[k.length-1];O&&O.position+1===m.position&&O.from===m.from&&O.key===m.key?k.push(m):L.push([m]);}for(let m=L.length-1;m>=0;m-=1){let k=L[m],O=r?Va(k[0].changes,k.map(({position:P})=>{let[j,K]=(r.items[P]??"-1:-1").split(":");return {client:Number(j),clock:Number(K)}})):k[0].changes;Ua(t,O,r?.items,k);}continue}let h=p.steps.filter(v=>v.op==="del").map(v=>e[v.before].position),g=p.steps.filter(v=>v.op==="ins").map(v=>n[v.after]),y=h.length>0?h[0]:p.after,w=Ai(r,y),S=0,I=d(y);for(let v of sg(g,L=>typeof L.insert=="string"?`c${ve(L.attributes)}`:`e${S++}`)){let L={...v[0],attributes:Tt(s(I,v[0].attributes,true))};if(I=L.attributes,typeof L.insert!="string"){let O=r&&y===(h.length>0?h[0]:p.after)?{identities:r,hasShownCopy:i}:null;ag(t,y,L.insert,L.attributes,w,O),w=null,y+=1;continue}let m=v.map(O=>O.insert).join(""),k=L.attributes[lt];k?mi(t,y,m,L.attributes,k):w?Ni(t,y,m,L.attributes,w):y===(h.length>0?h[0]:p.after)?Di(t,y,m,L.attributes,r,i):t.insert(y,m,{...L.attributes}),w=null,y+=m.length;}let b=y-(h.length>0?h[0]:p.after);for(let v=h.length-1;v>=0;){let L=v;for(;L>0&&h[L-1]+1===h[L];)L-=1;Ts(t,h[L]+b,v-L+1),v=L-1;}}}function dg(t,e,n){let r=t.inline.viewOf(e).shown(n);if(r.incoming.length===0)return {sources:[],wrote:false};let{ids:i}=r.identities,s=lo(r),a=new Map(r.incoming.map((b,v)=>[b,v])),l=[];for(let[b,v]of s.atPosition)for(let L of [...v.before,...v.after])l.push({following:L,order:a.get(L),at:b});for(let b of s.atEnd)l.push({following:b,order:a.get(b),at:i.length,atEnd:true});for(let b of s.atStart)l.push({following:b,order:a.get(b),at:-1,atEnd:true});let d=(b,v)=>v.at-b.at||(b.atEnd?0:Number(b.following.before))-(v.atEnd?0:Number(v.following.before))||v.order-b.order;l.sort(d);let c=new Set,u=new Set,f=false,p=[],h=b=>b-p.filter(v=>v<b).length,g=new Map,y=(b,v)=>{let L=g.get(b);return L||(L={identities:on(v),delta:Mt(v)},g.set(b,L)),L},w=(b,v)=>{let L=new Map,m=t.inline.textOf(b.source);if(!m)return {positions:[],landed:L};let{identities:k,delta:O}=y(b.source,m),P=Pi(b,k),j=k.ids,K=new Set(P),Y=[],V=0;for(let A of O){let J=typeof A.insert=="string"?A.insert.length:1,he=null,D=()=>he??=Ct(Ne(A.attributes,t.limits,b.source),e,t.limits);if(typeof A.insert=="string")for(let T=0;T<J;T+=1)K.has(V+T)&&Y.push({kind:"char",value:A.insert[T],attributes:{...D()},identity:j[V+T]??null,position:V+T});else if(K.has(V)&&A.insert!==null&&typeof A.insert=="object"){let T=Ps(m,V);T&&Y.push({kind:"embed",embed:A.insert,attributes:{...D()},item:T,position:V});}V+=J;}let q=[];for(let A of Y){let J=q[q.length-1],he=J?.[J.length-1];A.kind==="char"&&he?.kind==="char"&&ve(he.attributes)===ve(A.attributes)&&zt(he.identity,A.identity)?J.push(A):q.push([A]);}let ee=v,ne=(A,J)=>Tt(Wr(A>0?ud(n)[A-1]??{}:{},J,true,t.limits,e));for(let A of q){let J=A[0];if(J.kind==="embed"){let T=m===n?As(n,J.item):null;Ds(m,J.item),g.delete(b.source),u.add(b.source),T!==null&&(p.push(T),T<ee&&(ee-=1)),n.insertEmbed(ee,J.embed,{...ne(ee,J.attributes)}),L.set(J.position,ee),ee+=1;continue}let he=A.map(T=>T.kind==="char"?T.value:"").join(""),D=ne(ee,J.attributes);J.identity?mi(n,ee,he,D,J.identity):n.insert(ee,he,D),A.forEach((T,x)=>L.set(T.position,ee+x)),ee+=he.length;}return g.delete(e),c.add(b.source),q.length>0&&(f=true),{positions:P,landed:L}},S=[],I=(b,v)=>{let L=s.inside.get(b);if(!L)return;let m=[];for(let[k,O]of L){let P=v.positions[k],j=P===void 0?void 0:v.landed.get(P);for(let K of [...O.before,...O.after])j===void 0?S.push(K):m.push({following:K,order:a.get(K),at:j});}m.sort(d);for(let k of m){let O=k.following.before?k.at:k.at+1;I(k.following,w(k.following,O));}};for(let b of l){let v=b.atEnd?Math.max(b.at,0):b.following.before?b.at:b.at+1;I(b.following,w(b.following,h(v)));}for(let b of S)I(b,w(b,n.length));for(let b of u)t.inline.follow.invalidate(b);return t.inline.follow.invalidate(e),t.inline.noteDrift(),{sources:[...c],wrote:f}}function Yi(t){let e=new Set;for(let n of t.steps){if(n.op!=="del")continue;let o=t.before[n.before].position,r=o===void 0?null:t.identities[o];r&&e.add(r);}return e}function cg(t){let e=new Set;for(let o of t)for(let r of Yi(o))e.add(r);if(e.size===0)return [];let n=[];for(let o of t){if(!o.text||o.hidden.size===0)continue;let r=[...o.hidden].filter(s=>{let a=o.identities[s];return a!=null&&e.has(a)});if(r.length===0)continue;let i=o.shownIdentities;n.push({write:o,ids:Ir(o.text,r),originals:r.map(s=>i&&!i.moved[s]&&!i.restored[s]?o.identities[s]??null:null)});}return n}function _i(t,e){return t===null||!e.has(t)}function ug(t,e,n){let o=new Set,r=new Set(e.map(s=>s.id));for(let s of e)for(let a of Yi(s))o.add(a);if(o.size===0)return;let i=new Set;for(let s of o)for(let a of t.inline.follow.holdersOf(s))r.has(a)||i.add(a);for(let s of i){let a=t.inline.textOf(s);if(!a)continue;let l=on(a),d=l.ids.flatMap((c,u)=>{if(!c||!o.has(c))return [];let f=Se(l,u);return _i(f?null:c,n)?[u]:[]});d.length!==0&&($n(a,d),t.inline.follow.invalidate(s),t.inline.noteDrift());}}function fd(t,e){let n=new Set,o=new Map,r=new Set;for(let l of e){let d=t.inline.textOf(l);if(!d||!t.isTombstoned(l))continue;let c=t.inline.viewOf(l).shown(d),u=0;for(let p of d.toDelta()){if(typeof p.insert=="string"){u+=p.insert.length;continue}let h=p.insert?.n;typeof h=="string"&&!c.hidden.has(u)&&r.add(h),u+=1;}let f=[];c.identities.ids.forEach((p,h)=>{!p||c.hidden.has(h)||(f.push(p),Se(c.identities,h)&&n.add(p));});for(let p of c.incoming)for(let h of p.identities)h&&f.push(h);f.length>0&&o.set(l,f);}let i=[];if(n.size===0)return {held:i,shown:o,embeds:r};let s=new Set(e),a=new Set;for(let l of n)for(let d of t.inline.follow.holdersOf(l))s.has(d)||a.add(d);for(let l of a){let d=t.inline.textOf(l);if(!d)continue;let c=on(d),u=[],f=[];c.ids.forEach((p,h)=>{!p||!n.has(p)||(Se(c,h)?u.push(h):f.push(h));}),f.length>0&&i.push({holder:l,text:d,items:Ir(d,f),identities:f.map(p=>c.ids[p])}),u.length!==0&&($n(d,u),t.inline.follow.invalidate(l),t.inline.noteDrift());}return {held:i,shown:o,embeds:r}}function pd(t,e,n,o){let r=new Set(n);for(let i of e){if(o.embedded.has(i)||E(i))continue;let s=i;[...t.inline.holdersOf(s)].some(a=>!r.has(a))||!t.hasNode(s)||t.isTombstoned(s)||t.listingParents(s).length===0&&t.tombstone(s);}}function hd(t,e,n){let o=new Set(e.deleted);for(let i of n.values())for(let s of i)o.add(s);let r=Ya([...o].filter(i=>!e.copied.has(i)));r.length>0&&Qe(t.doc).record(r);}function gd(t,e,n){for(let{holder:o,text:r,items:i,identities:s}of e){let a=i.filter((l,d)=>_i(s[d],n));a.length!==0&&(xr(r,a),t.inline.follow.invalidate(o),t.inline.noteDrift());}}function md(t,e,n=new Map,o=new Set){let r=e.typed,i=new Set,s=[],a=new Set;for(let f=0,p=true;p&&f<=e.paragraphs.length;f+=1){p=false;for(let{id:h}of e.paragraphs){let g=t.inline.textOf(h);if(!g)continue;let{sources:y,wrote:w}=dg(t,h,g);w&&(p=true);for(let S of y)S===h||o.has(S)||t.inline.isDeletedParagraph(S)&&a.add(S);}}for(let{id:f,after:p}of e.paragraphs){let h=t.schema.nodes.get(f);if(!h||a.has(f))continue;let g=n.get(f)??xo(p,t.limits),y=t.isTombstoned(f);for(let b of g){if(y)break;typeof b.insert!="string"&&"n"in b.insert&&i.add(b.insert.n);}let w=t.inline.textOf(f),S=w?t.inline.viewOf(f).shown(w):null,I=w?Fl(w,S?.hidden,{limits:t.limits,paragraphId:f}):[];s.push({id:f,record:h,text:w,before:I,after:g,steps:$l(I,g,true,r&&jl(p,r)),identities:S?.identities.ids??[],shownIdentities:S?.identities??null,hidden:S?.hidden??new Set});}let l=cg(s),d=kl(s,(f,p)=>({...f,attributes:{...f.attributes,[lt]:p}}),f=>{let{[lt]:p,...h}=f.attributes;return ve(h)},(f,p)=>Ne(f.attributes,t.limits,s[p].id).text?.id??"",f=>fg(t,s[f].id));od(s);for(let f of s){let p=f.text??ho(f.record,[]);lg(p,f.before,f.after,f.steps,f.shownIdentities,h=>t.inline.follow.shownCopy(h)!==null,(h,g,y)=>Wr(h,g,y,t.limits,f.id)),t.inline.follow.invalidate(f.id);}for(let{write:f,ids:p,originals:h}of l){let g=p.filter((y,w)=>_i(h[w],d));!f.text||g.length===0||(xr(f.text,g),t.inline.follow.invalidate(f.id),t.inline.noteDrift());}ug(t,s,d);let c=new Set(e.paragraphs.map(f=>f.id));for(let f of e.embedsBefore)i.has(f)||[...t.inline.holdersOf(f)].some(p=>!c.has(p))||t.hasNode(f)&&!t.isTombstoned(f)&&t.listingParents(f).length===0&&t.tombstone(f);let u=new Set;for(let f of s)for(let p of Yi(f))u.add(p);return {copied:d,deleted:u,embedded:i}}function fg(t,e){if(t.parentOf(e)===null)return "";let n=e;for(let o=0;o<t.limits.maxTreeDepth;o+=1){let r=t.parentOf(n);if(r===null)return n;n=r;}return n}var yd=new WeakMap,gg=4096;function Id(t,e){if(e.effects.length!==1)return null;let n=e.effects[0];if(n.kind!=="spliceText"||n.deleteCount!==0||!mg(n.insert)||t.hasUnobservedWrites()||Ve(t.doc))return null;let o=t.inline.owner(n.logicalId);if(o===null)return null;let r=t.inline.textOf(o);if(!r||t.inline.sharesIds(o))return null;let i=t.inline.viewOf(o),s=i.shown(r);if(s.hidden.size>0||s.incoming.length>0)return null;let a=ni(r);if(a.leftOut)return null;let l=a.ops,d=0,c=-1,u=0,f=null,p=new Set,h=new Set;for(let b of l){let v=b.attributes??{};if(!yg(t,o,v))return null;let L=Ne(v,t.limits,o);if(typeof b.insert=="string"&&(!L.run||!L.text))return null;let m=new Set;for(let O of [L.run?.id,L.runProperties?.id,L.text?.id,L.textValueId,...L.wrap.map(P=>P.id)])if(O){if(p.has(O)&&!h.has(O))return null;m.add(O),p.add(O);}h=m;let k=typeof b.insert=="string"?b.insert.length:1;if(typeof b.insert=="string"&&L.textValueId!==null&&i.shownId(L.textValueId)===n.logicalId){if(c<0)c=d;else if(c+u!==d)return null;if(f&&ve(f)!==ve(v))return null;f??=v,u+=k;}d+=k;}if(!f||!Number.isSafeInteger(n.utf16Start)||n.utf16Start<0||n.utf16Start>u||u+n.insert.length>t.limits.maxTextLength)return null;let g=c+n.utf16Start,y=g>0?bd(l,g-1):null,w=g<d?bd(l,g):null,S=n.insert[0],I=n.insert[n.insert.length-1];return w&&w.key===`c${S}`||y&&y.key===`c${I}`&&y.element!==(f.t??"")||y?.highSurrogate||y?.revisions&&y.element!==(f.t??"")?null:{paragraphId:o,text:r,length:r.length,position:g,value:n.insert,attributes:Tt(f),identities:s.identities}}function xd(t,e){if(e.text.length!==e.length)return false;let n=Ai(e.identities,e.position);return n?Ni(e.text,e.position,e.value,e.attributes,n):Di(e.text,e.position,e.value,e.attributes,e.identities,o=>t.inline.follow.shownCopy(o)!==null),t.inline.follow.invalidate(e.paragraphId),true}function mg(t){if(t.length===0)return false;for(let e=0;e<t.length;e+=1){let n=t.charCodeAt(e);if(n<32||n>=55296&&n<=57343)return false}return true}function yg(t,e,n){let o=ve(n),r=JSON.stringify([e,o]),i=yd.get(t.limits);i||yd.set(t.limits,i=new Map);let s=i.get(r);if(s!==void 0)return s;let a;try{let l=Ne(n,t.limits,e);a=ve(Ct(l,e,t.limits))===o;}catch(l){if(!(l instanceof Be))throw l;a=false;}return i.size>=gg&&i.clear(),i.set(r,a),a}function bd(t,e){let n=0;for(let o of t){let r=typeof o.insert=="string"?o.insert.length:1;if(e<n+r){let i=ao(o.attributes??{});if(typeof o.insert!="string")return {key:"embed",element:"",highSurrogate:false,revisions:i};let s=o.insert.charCodeAt(e-n);return {key:`c${o.insert[e-n]}`,element:o.attributes?.t??"",highSurrogate:s>=55296&&s<=56319,revisions:i}}n+=r;}return null}function Bi(t,e){let n=[],o=[{id:e,depth:0}],r=new Set,i=0;for(;o.length>0;){let{id:s,depth:a}=o.pop();if(r.has(s)||a>t.limits.maxTreeDepth)return null;r.add(s);let l=t.record(s);if(!l)return null;if(kt(l)){let d=t.projectedTextValue(s)??l.value;if(i+=d.length,i>t.limits.maxTextLength)return null;n.push({id:s,value:d});}else if(W(l)&&!l.kind.endsWith("Properties"))for(let d=l.childIds.length-1;d>=0;d-=1)o.push({id:l.childIds[d],depth:a+1});}return n}function sn(t,e,n){let o=Bi(t,e),r=[];if(!o||o.length===0)return false;for(let l of n){let d=Bi(t,l);if(!d)return false;for(let c of d)r.push(c);}if(o.map(l=>l.value).join("")!==r.map(l=>l.value).join(""))return false;let i=[],s=0,a=0;for(let l of r){for(;s<o.length-1&&a===o[s].value.length;)s+=1,a=0;let d=o[s];if(!d||a+l.value.length>d.value.length)return false;l.id!==d.id&&i.push({product:l.id,source:d.id,start:a,end:a+l.value.length}),a+=l.value.length;}for(let l of i)t.registerSplitText(l.product,l.source,l.start,l.end);return true}function Ro(t,e,n){return t!=="run"&&t!=="text"?null:e.filter(o=>n(o)===t)}function Sd(t,e,n,o){for(let{removedId:r,runs:i}of e){let s=n.filter(a=>!i.includes(a));for(let a=1;a<=Math.min(s.length,bg);a+=1){let l=s.slice(0,a);if(sn(t,r,[...i,...l])){o(r,l);break}}}}var bg=8;function Ui(t,e){return (Bi(t,e)??[]).some(n=>t.splitTextPending(n.id))}var Dt=class{constructor(e){this.registry=e;}registry;touched=new Map;created=new Set;has(e){return this.created.has(e)||this.touched.has(e)||this.registry.hasNode(e)}node(e){let n=this.touched.get(e);if(n)return n;let o=this.registry.nodeShape(e);return o?(this.touched.set(e,o),o):null}putNode(e){this.node(e.logicalId)||(this.created.add(e.logicalId),this.touched.set(e.logicalId,{isText:e.kind==="textValue",textLength:0,children:[]}));}spliceText(e,n,o){let r=this.node(e);r&&(r.textLength=Math.max(0,r.textLength-n)+o);}spliceChildren(e,n,o,r){let i=this.node(e);i&&i.children.splice(n,o,...r);}moveNode(e,n,o){for(let s of this.listersOf(e)){let a=this.node(s);if(a)for(let l=a.children.length-1;l>=0;l-=1)a.children[l]===e&&a.children.splice(l,1);}let r=this.node(n);if(!r)return;let i=Math.min(o,r.children.length);r.children.splice(i,0,e);}listersOf(e){let n=new Set(this.registry.listingParents(e)),o=this.registry.parentOf(e);o!==null&&n.add(o);for(let[r,i]of this.touched)i.children.includes(e)&&n.add(r);return n}};function Nn(t,e){switch(e.kind){case "putNode":t.putNode(e.descriptor);return;case "spliceText":t.spliceText(e.logicalId,e.deleteCount,e.insert.length);return;case "spliceChildren":t.spliceChildren(e.parentLogicalId,e.start,e.deleteCount,e.childLogicalIds);return;case "moveNode":t.moveNode(e.logicalId,e.destinationParentLogicalId,e.destinationIndex);return;default:return}}function ft(t,e){return E(e)||e.length===0?{ok:false,code:"prototype-key",detail:e}:t.has(e)?null:{ok:false,code:"unknown-logical-id",detail:e}}function Ig(t,e,n){if(E(e.logicalId)||e.logicalId.length===0)return {ok:false,code:"invalid-logical-id",detail:e.logicalId};let o=n.node(e.logicalId);return o&&o.isText!==(e.kind==="textValue")?{ok:false,code:"invalid-bound",detail:`node class ${e.logicalId}`}:e.kind==="textValue"?null:E(e.qname.localName)?{ok:false,code:"prototype-key",detail:e.qname.localName}:Re(e.qname.namespaceUri,t.limits.maxStringLength)?{ok:false,code:"invalid-string"}:null}function Oo(t,e,n){switch(e.kind){case "putNode":return Ig(t,e.descriptor,n);case "spliceText":{let o=ft(n,e.logicalId);if(o)return o;if(!Number.isSafeInteger(e.utf16Start)||!Number.isSafeInteger(e.deleteCount)||e.utf16Start<0||e.deleteCount<0)return {ok:false,code:"invalid-bound"};if(e.insert.length>t.limits.maxTextLength)return {ok:false,code:"text-too-long"};let r=n.node(e.logicalId);if(r&&r.isText){if(e.utf16Start+e.deleteCount>r.textLength)return {ok:false,code:"invalid-bound",detail:e.logicalId};if(r.textLength-e.deleteCount+e.insert.length>t.limits.maxTextLength)return {ok:false,code:"text-too-long"}}else if(r)return {ok:false,code:"invalid-bound",detail:e.logicalId};return null}case "setAttribute":{let o=ft(n,e.logicalId);return o||(E(e.qname.localName)?{ok:false,code:"prototype-key",detail:e.qname.localName}:Re(e.qname.namespaceUri,t.limits.maxStringLength)?{ok:false,code:"invalid-string"}:e.value!==null&&e.value.length>t.limits.maxStringLength?{ok:false,code:"invalid-string"}:null)}case "setNamespaceBinding":{let o=ft(n,e.logicalId);return o||(E(e.prefix)?{ok:false,code:"prototype-key"}:e.uri!==null&&Re(e.uri,t.limits.maxStringLength)?{ok:false,code:"invalid-string"}:null)}case "spliceChildren":{let o=ft(n,e.parentLogicalId);if(o)return o;if(!Number.isSafeInteger(e.start)||!Number.isSafeInteger(e.deleteCount)||e.start<0||e.deleteCount<0)return {ok:false,code:"invalid-bound"};if(e.childLogicalIds.length>t.limits.maxChildren)return {ok:false,code:"too-many-children"};for(let i of e.childLogicalIds){let s=ft(n,i);if(s)return s}let r=n.node(e.parentLogicalId);if(r&&!r.isText){if(e.start+e.deleteCount>r.children.length&&!Rd(t,e,r.children.length))return {ok:false,code:"invalid-bound",detail:e.parentLogicalId};if(r.children.length-e.deleteCount+e.childLogicalIds.length>t.limits.maxChildren)return {ok:false,code:"too-many-children"}}else if(r)return {ok:false,code:"invalid-bound",detail:e.parentLogicalId};return null}case "moveNode":{let o=ft(n,e.logicalId);if(o)return o;let r=ft(n,e.destinationParentLogicalId);return r||(!Number.isSafeInteger(e.destinationIndex)||e.destinationIndex<0?{ok:false,code:"invalid-bound"}:null)}case "putXmlPart":{let o=Ie(e.name);if(o)return {ok:false,code:o,detail:e.name};let r=ft(n,e.rootLogicalId);return r||(t.partCount()>=t.limits.maxParts?{ok:false,code:"too-many-parts"}:null)}case "deleteXmlPart":{let o=Ie(e.name);return o?{ok:false,code:o,detail:e.name}:null}case "putRelationship":{if(e.record.ownerPart!=="/"){let o=Ie(e.owner);if(o)return {ok:false,code:o}}return E(e.record.id)?{ok:false,code:"prototype-key"}:t.relationshipCount()>=t.limits.maxRelationships?{ok:false,code:"too-many-relationships"}:null}case "deleteRelationship":return E(e.relationshipId)?{ok:false,code:"prototype-key"}:null;case "putContentTypeOverride":{let o=Ie(e.partName);return o?{ok:false,code:o}:Re(e.mediaType,t.limits.maxMediaTypeLength)?{ok:false,code:"invalid-string"}:null}case "deleteContentTypeOverride":{let o=Ie(e.partName);return o?{ok:false,code:o}:null}case "putBinary":{let o=js(e.descriptor);return o?{ok:false,code:o}:null}case "deleteBinary":return E(e.storageKey)?{ok:false,code:"prototype-key"}:null;default:return {ok:false,code:"invalid-bound"}}}function xg(t){let e=[];for(let n=0;n<t.length;n+=1){let o=t[n],r=t[n+1];if(o.kind==="spliceText"&&o.deleteCount>0&&o.insert.length===0&&r?.kind==="spliceText"&&r.logicalId===o.logicalId&&r.utf16Start===o.utf16Start&&r.deleteCount===0&&!yt(o)&&!yt(r)){e.push({...o,insert:r.insert}),n+=1;continue}e.push(o);}return e}function Sg(t,e,n){switch(e.kind){case "putNode":e.descriptor.kind==="textValue"?t.hasNode(e.descriptor.logicalId)||t.putText(e.descriptor.logicalId,""):t.hasNode(e.descriptor.logicalId)?t.updateElementShell(e.descriptor.logicalId,{kind:e.descriptor.kind,namespaceUri:e.descriptor.qname.namespaceUri,localName:e.descriptor.qname.localName,prefix:e.descriptor.qname.prefix}):(t.putElement({logicalId:e.descriptor.logicalId,kind:e.descriptor.kind,namespaceUri:e.descriptor.qname.namespaceUri,localName:e.descriptor.qname.localName,prefix:e.descriptor.qname.prefix,attributes:[],bindings:[]}),e.descriptor.kind==="paragraph"&&Ql(t.schema.nodes.get(e.descriptor.logicalId)));return;case "spliceText":if(n.has(e.logicalId)&&e.utf16Start===0&&e.deleteCount===0&&t.textOf(e.logicalId).toString()===e.insert)return;let o=yt(e);t.spliceText(o?.logicalId??e.logicalId,o?.utf16Start??e.utf16Start,e.deleteCount,e.insert);return;case "setAttribute":t.setAttribute(e.logicalId,e.qname,e.value);return;case "setNamespaceBinding":t.setNamespaceBinding(e.logicalId,e.prefix,e.uri);return;case "spliceChildren":{let r=t.record(e.parentLogicalId),i=r&&"childIds"in r?r.childIds.length:e.start,s=ie(t.schema.nodes.get(e.parentLogicalId)),a=d=>t.splitSiblings.ranksOf(e.parentLogicalId)?.has(d)??false;td(d=>t.schema.nodes.get(d),s,e.start,e.deleteCount,a);let l=z.getState(t.doc.store,t.doc.clientID);t.spliceChildren(e.parentLogicalId,Rd(t,e,i)?i:e.start,e.deleteCount,e.childLogicalIds),ed(d=>t.schema.nodes.get(d),d=>{let c=t.inline.textOf(d);return Xl(c,c?t.inline.viewOf(d).shown(c):null)},s,e.childLogicalIds,[...it(t.doc,l)].filter(d=>d.parent===s),a);return}case "moveNode":t.moveNode(e.logicalId,e.destinationParentLogicalId,e.destinationIndex);return;case "putXmlPart":t.putXmlPart({name:e.name,id:e.name,rootLogicalId:e.rootLogicalId,contentType:"application/xml"});return;case "deleteXmlPart":t.deleteXmlPart(e.name);return;case "putRelationship":t.putRelationship({...e.record,ownerPart:e.owner});return;case "deleteRelationship":t.deleteRelationship(e.owner,e.relationshipId);return;case "putContentTypeOverride":t.putContentTypeOverride(e.partName,e.mediaType);return;case "deleteContentTypeOverride":t.deleteContentTypeOverride(e.partName);return;case "putBinary":t.putBinary(e.descriptor);return;case "deleteBinary":t.deleteBinary(e.storageKey);return}}function wg(t,e){let n=t.kindOf(e);return n!==null&&!n.endsWith("Properties")}function kg(t,e,n,o){let r=new Set((n.get(e)??[]).filter(i=>wg(t,i)));if(r.size!==0){for(let i of o)if(!(i.kind!=="spliceChildren"||i.parentLogicalId===e)&&i.childLogicalIds.some(s=>r.has(s)))return i.parentLogicalId}}function vg(t,e){let n=new Dt(t),o=[],r=new Set,i=new Set,s=new Set,a=new Set,l=new Map;for(let d of e){let c=Oo(t,d,n);if(c)return c;if(d.kind==="spliceChildren"){let u=d.deleteCount>0?n.node(d.parentLogicalId):null;if(u&&!u.isText){let f=d.start+d.deleteCount;for(let p=d.start;p<f;p+=1){let h=u.children[p];if(h!==void 0&&(o.push(h),i.add(h),d.childLogicalIds.length>0)){let g=l.get(d)??[];g.push(h),l.set(d,g);}}}for(let f of d.childLogicalIds)r.add(f),i.delete(f);}else d.kind==="moveNode"?(r.add(d.logicalId),i.delete(d.logicalId)):d.kind==="putNode"&&(a.add(d.descriptor.logicalId),d.descriptor.kind==="textValue"&&s.add(d.descriptor.logicalId));Nn(n,d);}return {removed:o,reinserted:r,unlistedAtEnd:i,mintedText:s,mintedNodes:a,replacementsByEffect:l}}function Lg(t){let e=0;for(let n of t)n.kind==="putNode"&&(e+=1);return e}function Fi(t,e,n,o){if(o){let c=false;return t.doc.transact(()=>{t.noteWrite(),c=xd(t,o);},Lr),c?{ok:true}:{ok:false,code:"invalid-bound",detail:"typed text changed",transient:true}}let r=n,i=e;if(r===void 0){let c=yo(t,e.effects);if(c.refusal)return {ok:false,...c.refusal};r=c.plan,r&&(i={...e,effects:c.passThrough});}let s=i.effects.map(Ht);if(t.nodeCount()+Lg(s)>t.limits.maxNodes)return {ok:false,code:"too-many-nodes"};let a=vg(t,s);if("ok"in a)return a;for(let c of a.replacementsByEffect.values())for(let u of c)if(t.kindOf(u)==="run"&&Ui(t,u))return {ok:false,code:"invalid-bound",detail:`split of pending text in ${u}`,transient:true};let l=r?.paragraphs.find(({id:c})=>t.inline.textOf(c)===null&&vd(t,c));if(l)return {ok:false,code:"invalid-bound",detail:`pending text of paragraph ${l.id}`,transient:true};let d;try{d=new Map(r?.paragraphs.map(({id:c,after:u})=>[c,xo(u,t.limits)]));}catch(c){if(!(c instanceof Be))throw c;return {ok:false,code:c.code,detail:c.detail}}try{Rg(t,s,a,r,d);}finally{Zl();}return {ok:true}}function Rg(t,e,n,o,r){t.doc.transact(()=>{t.noteWrite();let i=Mg(t,n.removed),s=[],a=[];for(let u of xg(e))if(Sg(t,u,n.mintedText),u.kind==="spliceChildren"){if(n.mintedNodes.has(u.parentLogicalId))for(let f of u.childLogicalIds)n.mintedNodes.has(f)&&t.kindOf(f)==="run"&&a.push(f);if(t.kindOf(u.parentLogicalId)==="comment"){let f=(n.replacementsByEffect.get(u)??[]).filter(g=>t.kindOf(g)==="paragraph"),p=u.childLogicalIds.filter(g=>t.kindOf(g)==="paragraph"),h=f[f.length-1];h&&p.length>0&&t.recordRunSplit(h,h,p);}Tg(t,n,n.replacementsByEffect.get(u)??[],u.childLogicalIds,s);}Sd(t,s,a,(u,f)=>{t.recordRunSplit(Ld(t,u,n.reinserted),u,f);}),Cg(t,e,n,i);let l=fd(t,n.removed),d=Il(t,n,i),c=o?md(t,o,r,new Set(n.removed)):{copied:new Set,deleted:new Set,embedded:new Set};bl(t,n.removed,c.embedded,n.mintedNodes,o?.paragraphs.map(({after:u})=>u)??[]),gd(t,l.held,c.copied),hd(t,c,new Map([...l.shown,...d])),pd(t,l.embeds,n.removed,c);},Lr);}function Og(t,e){let n=t.inline.textOf(e);if(n===null&&vd(t,e)||n!==null&&Eg(t,e,n))return true;let o=t.record(e);return (o&&"childIds"in o?o.childIds:[]).some(i=>t.kindOf(i)==="run"&&Ui(t,i))}function kd(t,e){let n=t.kindOf(e)==="paragraph"?e:t.inline.owner(e)??t.parentOf(e);return n!==null&&Og(t,n)}function Eg(t,e,n){return $t(t.doc)?t.inline.viewOf(e).shown(n).incoming.some(o=>na(t.doc,o.source)):false}function vd(t,e){let n=t.schema.nodes.get(e);return _(n)&&ta(n,ae)}function Cg(t,e,n,o){if(n.removed.length===0)return;let r=new Set;for(let i of t.partEntries())r.add(i.rootLogicalId);for(let i of n.removed){if(n.reinserted.has(i)&&!n.unlistedAtEnd.has(i)||!t.hasNode(i)||t.isTombstoned(i)||r.has(i))continue;let s=kg(t,i,o,e);s&&t.unlistChildren(i,o.get(i)??[]),t.tombstone(i,s);}}function Tg(t,e,n,o,r){for(let i of n){let s=t.kindOf(i);if(s!=="run"&&s!=="text"||e.reinserted.has(i)&&!e.mintedNodes.has(i))continue;let a=Ld(t,i,e.reinserted);if(s==="text"){let d=Ro(s,o,c=>t.kindOf(c));if(d&&sn(t,i,d)){let c=o.filter(u=>e.mintedNodes.has(u));t.recordRunSplit(a,i,c);}continue}let l=o.filter(d=>t.kindOf(d)==="run");sn(t,i,l)||r.push({removedId:i,runs:l}),t.recordRunSplit(a,i,l);}}function Ld(t,e,n){let o=e;for(let r=0;r<t.limits.maxTreeDepth&&n.has(o);r+=1){let i=t.splitOriginOf(o);if(i===null||i===o)break;o=i;}return o}function Mg(t,e){let n=new Map;for(let o of e){let r=t.nodeShape(o);r&&!r.isText&&n.set(o,r.children);}return n}function Rd(t,e,n){return e.deleteCount===0&&e.start>n&&t.partEntries().some(o=>o.rootLogicalId===e.parentLogicalId)}var Ce="splitTextSource",Pg=Object.freeze({kind:"docx-package-restored-split-anchors"});function Ee(t,e){throw new N(t,e)}function ji(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function Od(t){return ji(t)&&Object.keys(t).every(e=>e==="client"||e==="clock")&&Number.isSafeInteger(t.client)&&t.client>=0&&Number.isSafeInteger(t.clock)&&t.clock>=0}function Ed(t){return !ji(t)||!Object.keys(t).every(e=>["type","item","assoc"].includes(e))||!Od(t.type)||t.item!==void 0&&!Od(t.item)||t.assoc!==0&&t.assoc!==-1?Ee("invalid-string",Ce):z.createRelativePositionFromJSON(t)}var Nt=class extends Error{},an=class{constructor(e,n,o){this.nodes=e;this.doc=n;this.limits=o;}nodes;doc;limits;sourceByAlias=new Map;aliasesBySource=new Map;pending=new Set;values=new Map;awaiting=new Set;lastEncoded=new Map;held=new Set;isPlain(e){return !this.sourceByAlias.has(e)&&!this.aliasesBySource.has(e)}register(e,n,o,r){let i=this.nodes.get(e);(!_(i)||!(i.get(Pe)instanceof z.Text))&&Ee("invalid-bound",e);let s=this.read(n),a=s===null?{sourceId:n,text:this.sourceText(n),start:0,end:this.sourceText(n).length}:this.resolve(s);(a.sourceId.length===0||a.sourceId.length>this.limits.maxStringLength||E(a.sourceId))&&Ee("invalid-string",n),(!Number.isSafeInteger(o)||!Number.isSafeInteger(r)||o<0||r<o||r>a.end-a.start||e===a.sourceId)&&Ee("invalid-bound",e);let l=(c,u)=>{if(s&&u==="end"&&c===a.end-a.start)return s.end;if(s&&c===0)return s.start;if(s&&c===a.end-a.start)return s.end;let f=a.start+c;return z.createRelativePositionFromTypeIndex(a.text,f,f===0&&u==="start"?-1:0)},d=JSON.stringify({sourceId:a.sourceId,start:z.relativePositionToJSON(l(o,"start")),end:z.relativePositionToJSON(l(r,"end"))});d.length>this.limits.maxStringLength&&Ee("invalid-string",e),i.set(Ce,d),this.indexExisting(e);}normalizeRestoredAnchors(){let e=new Map,n=r=>{let i=r.item;if(i===null)return r;let s=`${i.client}:${i.clock}:${r.assoc}`,a=e.get(s);if(a)return a;let l=f=>z.getState(this.doc.store,f.client)>f.clock?z.getItem(this.doc.store,f):null,d=i,c=l(d);for(;c instanceof z.Item&&c.redone!==null;)d=z.createID(c.redone.client,c.redone.clock+d.clock-c.id.clock),c=l(d);let u=c instanceof z.Item&&!c.deleted&&!z.compareIDs(i,d)?z.createRelativePositionFromJSON({...z.relativePositionToJSON(r),item:{client:d.client,clock:d.clock}}):r;return e.set(s,u),u},o=[];for(let r of this.sourceByAlias.keys()){let i=this.nodes.get(r);if(_(i)&&Tr(i,Ce))continue;let s=this.read(r);if(!s)continue;let a=n(s.start),l=n(s.end);if(z.compareRelativePositions(a,s.start)&&z.compareRelativePositions(l,s.end))continue;let d=JSON.stringify({sourceId:s.sourceId,start:z.relativePositionToJSON(a),end:z.relativePositionToJSON(l)});d.length>this.limits.maxStringLength&&Ee("invalid-string",r),o.push({id:r,encoded:d});}o.length!==0&&this.doc.transact(()=>{for(let{id:r,encoded:i}of o)this.nodes.get(r).set(Ce,i),this.indexExisting(r);},Pg);}sourceAliases(e){return [...this.aliasesBySource.get(e)??[]]}range(e){try{return this.resolveRange(e)}catch(n){if(n instanceof Nt)return null;throw n}}isPending(e){try{return this.resolveRange(e),!1}catch(n){if(n instanceof Nt)return true;throw n}}resolveRange(e){let n=this.read(e);return n===null?null:this.resolve(n)}value(e){let n=this.range(e);return n===null?null:n.text.toString().slice(n.start,n.end)}indexExisting(e){let n=null,o=false;try{n=this.read(e),n&&this.resolve(n);}catch{o=true;}let r=this.sourceByAlias.get(e);if(r!==void 0&&r!==n?.sourceId){let i=this.aliasesBySource.get(r);i?.delete(e),i?.size===0&&this.aliasesBySource.delete(r),this.sourceByAlias.delete(e);}if(n){this.sourceByAlias.set(e,n.sourceId);let i=this.aliasesBySource.get(n.sourceId)??new Set;i.add(e),this.aliasesBySource.set(n.sourceId,i);}(o||n||r!==void 0||this.values.has(e))&&this.pending.add(e);}noteChanged(e){this.indexExisting(e);for(let n of this.aliasesBySource.get(e)??[])this.pending.add(n);}reset(){this.sourceByAlias.clear(),this.aliasesBySource.clear();for(let e of this.values.keys())this.pending.add(e);this.nodes.forEach((e,n)=>this.indexExisting(n));}overlays(){let e=new Set,n=new Map;if(this.held.size>0&&!$t(this.doc)){for(let o of this.held)this.indexExisting(o);this.held.clear();}for(let o of this.pending){let r=null;try{r=this.resolveRange(o),this.awaiting.delete(o)&&e.add(o);}catch(s){if(!(s instanceof Nt))throw s;this.awaiting.has(o)||e.add(o),this.awaiting.add(o);}let i=null;if(r){let s=n.get(r.sourceId);s===void 0&&(s=r.text.toString(),n.set(r.sourceId,s)),i=s.slice(r.start,r.end);}i===null?this.values.delete(o)&&e.add(o):i!==this.values.get(o)&&(this.values.set(o,i),e.add(o));}return this.pending.clear(),{values:this.values,changedIds:e,awaiting:this.awaiting}}sourceText(e){let n=this.nodes.get(e),o=_(n)?n.get(Pe):null;return !(o instanceof z.Text)||o.doc!==this.doc||o.length>this.limits.maxTextLength?Ee("invalid-bound",e):o}read(e){let n=this.nodes.get(e);if(!_(n))return null;let o;if(Tr(n,Ce)){if(o=this.lastEncoded.get(e),o===void 0)throw new Nt(e);this.held.add(e);}else {if(!n.has(Ce))return null;o=n.get(Ce);}if(typeof o!="string"||o.length>this.limits.maxStringLength)return Ee("invalid-string",e);let r;try{r=JSON.parse(o);}catch{return Ee("invalid-string",e)}if(!ji(r)||!Object.keys(r).every(s=>["sourceId","start","end"].includes(s))||typeof r.sourceId!="string"||r.sourceId.length===0||r.sourceId.length>this.limits.maxStringLength||E(r.sourceId)||r.sourceId===e)return Ee("invalid-string",e);if(!(n.get(Pe)instanceof z.Text))return Ee("invalid-bound",e);let i={sourceId:r.sourceId,start:Ed(r.start),end:Ed(r.end)};return this.lastEncoded.set(e,o),i}resolve(e){if(!this.nodes.has(e.sourceId)||[e.start,e.end].some(d=>d.item!==null&&z.getState(this.doc.store,d.item.client)<=d.item.clock))throw new Nt(e.sourceId);let n=this.nodes.get(e.sourceId);if(_(n)&&n.has(Ce))return Ee("invalid-bound",e.sourceId);let o=this.sourceText(e.sourceId),r=z.createRelativePositionFromTypeIndex(o,0).type;if(!r||[e.start,e.end].some(d=>d.type?.client!==r.client||d.type?.clock!==r.clock))return Ee("invalid-bound",e.sourceId);let i=z.createAbsolutePositionFromRelativePosition(e.start,this.doc,false),s=z.createAbsolutePositionFromRelativePosition(e.end,this.doc,false),a=e.start.item!==null&&z.getItem(this.doc.store,e.start.item).deleted,l=e.end.item!==null&&z.getItem(this.doc.store,e.end.item).deleted;return i===null||s===null||i.type!==o||s.type!==o||i.index<0||s.index>o.length?Ee("invalid-bound",e.sourceId):{sourceId:e.sourceId,text:o,start:i.index,end:Math.max(i.index,s.index),startAssoc:e.start.assoc,endAssoc:e.end.assoc,startAnchorDeleted:a,endAnchorDeleted:l}}};function Eo(t,e,n,o,r,i){if(!o||i.length===0)return null;let s=r===0&&o.startAssoc!==-1,a=r===o.end-o.start;if(!s&&!a)return null;let l=t.get(n)?.get(Ce);if(typeof l!="string")return null;let d=JSON.parse(l),c=z.createRelativePositionFromJSON(d.start),u=z.createRelativePositionFromJSON(d.end);if(a=a&&(s||u.item!==null&&z.getItem(o.text.doc.store,u.item).deleted),!s&&!a)return null;let f=[],p=o.text.doc.store,h=g=>{if(g.item===null||!z.getItem(p,g.item).deleted)return false;let y=z.createAbsolutePositionFromRelativePosition(g,o.text.doc,false);return y!==null&&y.type===o.text&&y.index===o.end};for(let g of e.sourceAliases(o.sourceId)){if(!e.range(g))continue;let y=t.get(g),w=y.get(Ce);if(typeof w!="string")continue;let S=JSON.parse(w),I=(L,m)=>{let k=z.createRelativePositionFromJSON(L);return s&&a&&z.compareRelativePositions(c,u)&&z.compareRelativePositions(k,c)?m==="start"?"after":"before":s&&z.compareRelativePositions(k,c)?"before":a&&z.compareRelativePositions(k,u)||a&&!s&&!(g===n&&m==="start")&&h(k)?"after":null},b=g===n&&s?"before":I(S.start,"start"),v=g===n&&a?"after":I(S.end,"end");(b||v)&&f.push({record:y,start:b,end:v});}return ()=>{let g=o.start+r,y=z.relativePositionToJSON(z.createRelativePositionFromTypeIndex(o.text,g,g===0&&o.startAssoc===-1?-1:0)),w=z.relativePositionToJSON(z.createRelativePositionFromTypeIndex(o.text,g+i.length,0));for(let S of f){let I=JSON.parse(S.record.get(Ce));S.start&&(I.start=S.start==="before"?y:w),S.end&&(I.end=S.end==="before"?y:w);let b=JSON.stringify(I);b!==S.record.get(Ce)&&S.record.set(Ce,b);}}}var Co=class{constructor(e){this.nodes=e;}nodes;cachedLosers=null;invalidate(){this.cachedLosers=null;}runsBySplitOrigin=new Map;liveRootedOrigins=new Set;reset(){this.invalidate(),this.runsBySplitOrigin.clear(),this.liveRootedOrigins.clear();}record(e,n,o){this.invalidate();for(let r of o){if(r===e)continue;let i=this.nodes.get(r);_(i)&&(i.set(yn,e),i.set(wt,e),this.indexExisting(r));}}indexExisting(e){let n=this.nodes.get(e),o=Et(n);if(o===null||o===e||hi(n))return;this.invalidate();let r=this.runsBySplitOrigin.get(o)??new Set;r.add(e),this.runsBySplitOrigin.set(o,r),this.liveRootedOrigins.add(o);}productsOf(e){return [...this.runsBySplitOrigin.get(e)??[]].filter(n=>Et(this.nodes.get(n))===e)}loserRuns(e){if(this.cachedLosers)return this.cachedLosers;let n=new Set,o=new Set,r=i=>{let s=[i];for(;s.length>0;){let a=s.pop();if(!o.has(a)){o.add(a),e.isPresent(a)&&n.add(a);for(let l of this.productsOf(a))s.push(l);}}};for(let i of this.liveRootedOrigins){let s=this.productsOf(i),a=e.isPresent(i)?null:s.filter(l=>In(this.nodes.get(l))===i).map(l=>ze(l)??"").sort()[0];for(let l of s)(ze(l)??"")!==a&&r(l);}return this.cachedLosers=n,n}};function To(t,e,n){let o=new Map;for(let a=0;a<t.length;a+=1){let l=t[a],d=n(l);if(d===null||d===l)continue;let c=o.get(d)??{loser:[],winner:[]};(e(l)?c.loser:c.winner).push(a),o.set(d,c);}let r=new Map;for(let{loser:a,winner:l}of o.values())a.length!==1||l.length!==1||a[0]>l[0]||r.set(l[0],a[0]);if(r.size===0)return null;let i=new Map;for(let[a,l]of r)i.set(l,a);let s=[];for(let a=0;a<t.length;a+=1){let l=i.get(a);l!==void 0&&s.push(l),r.has(a)||s.push(a);}return s}var Cd=4096;function Pd(t){let e=dt(t),n=[],o=0;for(let r=be(t);r&&o<Cd;r=r.right)for(let i=0;i<r.length&&o<Cd;i+=1)o+=1,e.origin("move",r.id.client,r.id.clock+i)&&n.push(ot(t,r,i));return n}function Ag(t,e){let n=e[0];return n===void 0||t.length===0?false:t.indexOf(n)>0&&e.indexOf(t[0])<=0}function Yt(t,e){return t!==null&&t.client===e.id.client&&t.clock>=e.id.clock&&t.clock<e.id.clock+e.length}var Td=t=>t?`${t.client}:${t.clock}`:"-",zi=t=>`${Td(t.origin)} ${Td(t.rightOrigin)}`;function Dg(t,e,n=[],o=()=>[],r=[],i=[]){let s=null,a=0,l=[],d=t.doc?.getMap(mn)??null,c=new Map,u=new Map;for(let g=be(t);g;g=g.right){if(!g.deleted)for(let w of g.content.getContent())u.has(w)||u.set(w,l.length);l.push(g);let y=zi(g);c.set(y,(c.get(y)??0)+1);}let f=g=>g.deleted||Wi(d,g),p=new Map,h=g=>{let y=p.get(g);if(!y){let w=e(g);y=new Set(w?Pd(w):[]),p.set(g,y);}return y};for(let g=0;g<l.length;){let y=l[g],w=zi(y);if(c.get(w)<2||!f(y)){g+=1;continue}let S=[{head:y,items:[y]}],I=g+1;for(;I<l.length;I+=1){let D=l[I],T=S.at(-1);if(zi(D)===w&&f(D))S.push({head:D,items:[D]});else if(T.items.some(x=>Yt(D.origin,x)))T.items.push(D);else break}if(S.length<2){g+=1;continue}let b=g,v=0,L=S.flatMap(D=>D.items),m=[];for(let D=g;D>1;){let T=l[D-1],x=L.find(C=>C.deleted&&Yt(T.rightOrigin,C));if(!x){if(!(!T.deleted&&m.some(M=>Yt(T.rightOrigin,M))&&!(T.origin&&y.origin&&z.compareIDs(T.origin,y.origin))))break;D-=1,m.unshift(T);continue}if(D-=1,T.deleted){L.push(T);continue}if(!T.origin||!y.origin||!z.compareIDs(T.origin,y.origin)){m.unshift(T);continue}if(!Md(d,T,x))break;let R={head:T,items:[T]};for(let C of m)R.items.some(M=>Yt(C.origin,M))&&R.items.push(C);if(R.items.length!==m.length+1)break;m=[],S.unshift(R),v+=1,b=D;}for(let D of S)for(let T of D.items)if(!T.deleted)for(let x of T.content.getContent())n.push(x);let k=D=>D.flatMap(T=>T.items.filter(x=>!x.deleted).flatMap(x=>x.content.getContent())),O=k(S),P=new Set(S.slice(0,v).map(D=>D.head)),j=S.flatMap(D=>D.items.filter(T=>!T.deleted).flatMap(T=>T.content.getContent().map((x,R)=>R===0&&P.has(T)||Yg(d,x,T,R)))),K=[];for(let D of S)for(let T of D.items){if(T.deleted)continue;let x=T.content.getContent().length;for(let R=0;R<x;R+=1){let C=R>0?{client:T.id.client,clock:T.id.clock+R-1}:T.origin;K.push(C?`${C.client}:${C.clock}`:null);}}let Y=S.flatMap(D=>D.items.filter(T=>!T.deleted).flatMap(T=>T.content.getContent().map((x,R)=>R===0&&!P.has(T)&&L.some(C=>Yt(T.rightOrigin,C)&&!(C.deleted&&Md(d,T,C)))))),V=S.flatMap((D,T)=>k([D]).map(()=>T)),q=zg(S,e,t.doc,o,i,D=>P.has(D)||Wi(d,D)),ne=new Set(O).size<O.length?null:Ng(O,j,Y,K,V,o,t.doc,i,h)??(q?k(q):null),A=ne??O,J=l[b-1];if(J&&!J.deleted&&Yt(y.origin,J)){let D=new Set(S.filter(R=>!R.head.deleted).map(R=>Yn(R.head))),T=J.content.getContent()[y.origin.clock-J.id.clock],x=new Map;for(let R of S){let C=T;for(let M of k([R]))x.set(M,C),C=M;}r.push({source:T,heads:A.filter(R=>D.has(R)),shown:A,before:x});}let he=ne!==null&&ne.some((D,T)=>O[T]!==D);he&&(a+=1,s??=new Map,ne.forEach((D,T)=>{(u.get(D)??b)>=b&&s.set(D,{group:a,rank:T});})),g=he?I:g+1;}return s}function Ng(t,e,n,o,r,i,s,a,l=()=>new Set){let d=[],c=[],u=I=>i(I).map(b=>`${b.source}@${b.at}`).join(`
|
|
13
|
+
`),f=I=>{if(!I||!s)return null;let[b,v]=I.split(":").map(Number),L=H(s,{client:b,clock:v});if(!L||L.deleted)return null;let m=L.content.getContent()[v-L.id.clock];return typeof m=="string"?u(m):null},p=I=>{if(!I||!s)return false;let[b,v]=I.split(":").map(Number);return H(s,{client:b,clock:v})?.deleted===true},h=new Map,g=new Set;for(let[I,b]of t.entries()){let v=u(b),L=v!==""&&f(o[I])===v,m=i(b).at(-1),k=m?.source,O=()=>{let V=m.at.replace(/\+$/,"");return t.every((q,ee)=>{if(q===b||q===k)return true;let ne=l(q);return !ne.has(V)&&(!e[ee]||ne.size>0)})},P=k!==void 0&&(g.has(k)||h.has(k)&&O()),j=I===0&&r[1]!==r[0],K=n[I]&&(j||r[I-1]===r[I]||!p(o[I]))?h.get(t[I-1]):e[I]&&!L&&!P?null:P?h.get(k):d.at(-1);if(K===void 0)return null;K&&g.add(b);let Y=K??[];K||(d.push(Y),c.push(r[I])),Y.push(b),h.set(b,Y);}if(d.length<2)return null;let y=d.map(I=>i(I[0])),w=new Map,S=I=>{let b=new Map;c.forEach((k,O)=>{b.has(k)||b.set(k,O);});let v=[...b.keys()].sort((k,O)=>I[b.get(k)]-I[b.get(O)]||k-O),L=new Map(v.map((k,O)=>[k,O])),m=d.map((k,O)=>O);return m.sort((k,O)=>I[k]-I[O]||L.get(c[k])-L.get(c[O])||k-O),m.flatMap(k=>d[k])};for(let I=y[0].length-1;I>=0;I-=1){let b=y[0][I].source,v=y.map(O=>Ei(O,b));if(v.some(O=>O===null))continue;let L=a.length,m=$i(s,y.map(O=>O.at(-1).at),w,a,false);if(m)return S(m);if(a.length>L)return null;let k=$i(s,v,w,a);return k?S(k):null}return null}function Md(t,e,n){if(!t||e.deleted||!Wi(t,e))return false;let o=_e(t,Yn(e));return o!==void 0&&o.id.client===n.id.client&&o.id.clock<n.id.clock}function Wi(t,e){let n=t?.get(Yn(e));if(!(n instanceof z.Map))return false;let o=An(n);return o!==null&&Yt(o,e)}function Yg(t,e,n,o){let r=t?.get(e);if(!(r instanceof z.Map))return false;let i=An(r);return i!==null&&i.client===n.id.client&&i.clock===n.id.clock+o}function Yn(t){return t.content.getContent()[0]}function Ad(t,e){let n=typeof t=="string"?e(t):null;return n?Pd(n):[]}function Dd(t,e,n){let o=e?/^(\d+):(\d+)$/.exec(e):null;if(!o)return null;let r=Number(o[1]),i=Number(o[2]),s=H(t,{client:r,clock:i}),a=s?.parent;if(!s||!(a instanceof z.Text))return null;for(let c=a._item;c;c=c.parent instanceof z.AbstractType?c.parent._item:null)if(c.deleted)return null;let l=n.get(a);if(!l){l=new Map;let c=0;for(let u=be(a);u;u=u.right)l.set(`${u.id.client}:${u.id.clock}`,c),c+=u.length;n.set(a,l);}let d=l.get(`${s.id.client}:${s.id.clock}`);return d===void 0?null:{text:a,at:d+i-s.id.clock}}function _g(t,e,n){for(let o of t.items){if(o.deleted)continue;if(!n(o))return [];let r=Ad(Yn(o),e);if(r.length>0)return r}return []}function Bg(t,e,n,o){return n&&o&&n.text===o.text?n.at<o.at:Ag(t,e)}function Ug(t,e,n){for(let o of t.items){if(o.deleted)continue;if(!n(o))return [];let r=e(Yn(o));if(r.length>0)return r}return []}function Nd(t,e){let[n,o]=e.split(":").map(Number);return o<z.getState(t.store,n)}function Fg(t,e,n,o,r){if(e===n)return null;let i=$i(t,[e,n],o,r);return i&&i[0]!==i[1]?i[0]<i[1]:null}function $i(t,e,n,o,r=true){if(!t)return null;let i=e.map(d=>({identity:d.endsWith("+")?d.slice(0,-1):d,after:d.endsWith("+")?.5:0})),s=i.map(({identity:d})=>d).filter(d=>!Nd(t,d));if(s.length>0)return o.push(...s),null;let a=i.map(({identity:d})=>Dd(t,d,n));if(a.every(d=>d&&d.text===a[0].text))return a.map((d,c)=>d.at+i[c].after);if(!r)return null;let l=i.map(({identity:d})=>d.split(":").map(Number));return l.every(([d])=>d===l[0][0])?l.map(([,d],c)=>d+i[c].after):null}function jg(t,e,n,o,r){for(let i=e.length-1;i>=0;i-=1){let s=Ei(n,e[i].source);if(s!==null)return Fg(t,e[i].at,s,o,r)}return null}function zg(t,e,n,o,r,i){let s=t.map(f=>Ug(f,o,i)),a=t.map(f=>_g(f,e,i)),l=new Map,d=a.map(f=>n?Dd(n,f[0],l):null),c=t.map((f,p)=>p),u=false;for(let f=1;f<c.length;f+=1)for(let p=f;p>0;p-=1){let h=c[p],g=c[p-1];if(t[g].items.every(S=>S.deleted)){[c[p-1],c[p]]=[h,g];continue}if(!(jg(n,s[h],s[g],l,r)??Bg(a[h],a[g],d[h],d[g])))break;[c[p-1],c[p]]=[h,g],u=true;}return u?c.map(f=>t[f]):null}var Mo=class{constructor(e,n,o){this.nodeOf=e;this.textOf=n;this.listingOf=o;}nodeOf;textOf;listingOf;built=new WeakMap;withRuns=new Set;grouped=new Set;recheck=new Map;readers=new Map;membersOf=new Map;ranksOf(e){return this.read(e)?.ranks??null}groupsOf(e){return this.read(e)?.groups??[]}parentsWithRuns(){for(let e of [...this.grouped])this.listingOf(e)||this.grouped.delete(e);return [...this.grouped]}shownChildren(e){return this.read(e)?.shown??this.listingOf(e)}takeChanged(){let e=[];for(let[n,o]of this.recheck){this.recheck.delete(n);let r=this.read(n)?.shown??this.listingOf(n);r&&(r.length!==o.length||r.some((i,s)=>o[s]!==i))&&e.push(n);}for(let n of [...this.withRuns]){let o=this.listingOf(n),r=o?this.built.get(o):void 0;if(!o||!r){this.withRuns.delete(n);continue}let i=this.nodeOf(n)?.doc??null,s=i!==null&&r.missing.some(d=>Nd(i,d)),a=r.waiting.length>0&&this.lengthsKey(r.waiting)!==r.lengths;if(!s&&!a)continue;let l=this.build(n,o);(!l||l.shown.some((d,c)=>r.shown[c]!==d))&&e.push(n);}return e}forget(e){let n=this.listingOf(e),o=n?this.built.get(n):void 0;!n||!o||(this.built.delete(n),this.recheck.has(e)||this.recheck.set(e,o.shown));}textChanged(e){for(let n of this.readers.get(e)??[])this.forget(n);}noteMembers(e,n){for(let o of this.membersOf.get(e)??[]){let r=this.readers.get(o);r?.delete(e),r?.size===0&&this.readers.delete(o);}if(n.length===0){this.membersOf.delete(e);return}this.membersOf.set(e,n);for(let o of n){let r=this.readers.get(o);r||this.readers.set(o,r=new Set),r.add(e);}}lengthsKey(e){return e.map(n=>this.textOf(n)?.length??-1).join(",")}read(e){let n=this.listingOf(e);return n&&this.built.get(n)||this.build(e,n)}build(e,n){let o=ie(this.nodeOf(e));if(!o||o.length<2)return null;let r=[],i=[],s=[],a=Dg(o,this.textOf,r,p=>ut(this.nodeOf(p)),i,s),l=n??o.toArray(),d=_n(l,a),c=d?d.map(p=>l[p]):l,u=r.filter(p=>ut(this.nodeOf(p)).length===0&&Ad(p,this.textOf).length===0),f={ranks:a,shown:c,waiting:u,lengths:this.lengthsKey(u),groups:i,missing:s};return i.length>0?this.grouped.add(e):this.grouped.delete(e),n&&(this.built.set(n,f),this.noteMembers(e,r)),(u.length>0||s.length>0)&&n?this.withRuns.add(e):this.withRuns.delete(e),f}};function _n(t,e){if(!e)return null;let n=t.map((s,a)=>a),o=new Set,r=[];t.forEach((s,a)=>{o.has(s)||(o.add(s),r.push(a));});let i=false;for(let s=0;s<r.length;){let a=e.get(t[r[s]]),l=s+1;for(;a&&l<r.length&&e.get(t[r[l]])?.group===a.group;)l+=1;if(l-s>1){let d=r.slice(s,l);d.sort((c,u)=>e.get(t[c]).rank-e.get(t[u]).rank);for(let c=0;c<d.length;c+=1){let u=r[s+c];n[u]!==d[c]&&(i=true),n[u]=d[c];}}s=l;}return i?n:null}function Yd(t,e,n){if(n.keepBoundary&&t===n.start)return t;let o=t<=n.start?t:Math.max(n.start,t-n.deleted);return o<n.start||o===n.start&&e<0?o:o+n.inserted.length}var Ki=class{constructor(e,n){this.registry=e;this.raw=n;}registry;raw;ranges=new Map;histories=new Map;strings=new Map;actions=[];shadow=null;range(e){if(this.shadow){let o=this.shadow.sources.range(e);return o?{...o,revision:0}:null}if(!this.ranges.has(e)){let o=this.registry.splitTextRange(e);this.ranges.set(e,o?{...o,revision:0}:null);}let n=this.ranges.get(e);if(n){let o=this.histories.get(n.sourceId)??[];for(;n.revision<o.length;){let r=o[n.revision],i=(s,a)=>{let l=a<0?s-1:s;return l>=r.start&&l<r.start+r.deleted};if(n.startAnchorDeleted||n.endAnchorDeleted||r.ambiguousBoundary||i(n.start,n.startAssoc)||i(n.end,n.endAssoc)){this.ensureShadow();let s=this.shadow.sources.range(e);return s?{...s,revision:0}:null}n.start=Yd(n.start,n.startAssoc,r),n.end=Yd(n.end,n.endAssoc,r),n.revision+=1;}}return n}value(e){let n=this.range(e);if(n)return this.value(n.sourceId).slice(n.start,n.end);let o=this.strings.get(e);if(o===void 0){o=this.registry.hasNode(e)?this.registry.textOf(e).toString():"";for(let r of this.histories.get(e)??[])o=o.slice(0,r.start)+r.inserted+o.slice(r.start+r.deleted);this.strings.set(e,o);}return o}apply(e){let n=yt(e),o=n?this.range(n.logicalId):null,r={keepBoundary:n?.utf16Start===0&&o?.startAssoc!==-1&&e.insert.length>0,ambiguousBoundary:o!==null&&o.start===o.end&&e.insert.length>0,start:e.utf16Start,deleted:e.deleteCount,inserted:e.insert},i=this.histories.get(e.logicalId)??[];i.push(r),this.histories.set(e.logicalId,i);let s=this.strings.get(e.logicalId);s!==void 0&&this.strings.set(e.logicalId,s.slice(0,r.start)+r.inserted+s.slice(r.start+r.deleted));let a={kind:"splice",effect:e};this.actions.push(a),this.shadow&&this.replay(a);}register(e,n,o,r){let i=this.range(n),s=i?.sourceId??n,a=i?.start??0,l=i?i.end-i.start:this.raw.node(n)?.textLength??0,d=(p,h)=>i&&h==="end"&&p===l?{assoc:i.endAssoc,deleted:i.endAnchorDeleted}:i&&p===0?{assoc:i.startAssoc,deleted:i.startAnchorDeleted}:i&&p===l?{assoc:i.endAssoc,deleted:i.endAnchorDeleted}:{assoc:a+p===0&&h==="start"?-1:0,deleted:false},c=d(o,"start"),u=d(r,"end");this.ranges.set(e,{sourceId:s,start:a+o,end:a+r,startAssoc:c.assoc,endAssoc:u.assoc,startAnchorDeleted:c.deleted,endAnchorDeleted:u.deleted,revision:this.histories.get(s)?.length??0});let f={kind:"register",product:e,source:n,start:o,end:r};this.actions.push(f),this.shadow&&this.replay(f);}destroy(){this.shadow?.doc.destroy();}ensureShadow(){if(this.shadow)return;let e=new z.Doc({gc:false}),n=e.getMap(mn);this.shadow={doc:e,nodes:n,sources:new an(n,e,this.registry.limits)},z.applyUpdate(e,z.encodeStateAsUpdate(this.registry.doc)),e.clientID=this.registry.doc.clientID,this.shadow.sources.reset();for(let o of this.actions)this.replay(o);}replay(e){let n=this.shadow,o=u=>(n.nodes.has(u)||n.nodes.set(u,Hn("")),n.nodes.get(u).get(Pe));if(e.kind==="register"){o(e.product),n.sources.register(e.product,e.source,e.start,e.end);return}let{effect:r}=e,i=yt(r),s=i?n.sources.range(i.logicalId):null,a=s?.text??o(r.logicalId),l=i?.utf16Start??r.utf16Start,d=(s?.start??0)+l,c=Eo(n.nodes,n.sources,i?.logicalId??r.logicalId,s,l,r.insert);r.deleteCount>0&&a.delete(d,r.deleteCount),r.insert.length>0&&a.insert(d,r.insert),c?.();}},Vi=class extends Dt{constructor(n,o,r,i,s=()=>[],a=()=>null){super(n);this.shared=n;this.visibleIndexes=o;this.raw=r;this.text=i;this.mergedOf=s;this.shownOf=a;}shared;visibleIndexes;raw;text;mergedOf;shownOf;filtered=new Set;node(n){let o=super.node(n);if(o&&!this.filtered.has(n)){this.filtered.add(n);let r=[...this.shared.adoptedChildren(n),...this.mergedOf(n)].filter((a,l,d)=>!o.children.includes(a)&&d.indexOf(a)===l),i=r.length>0?[...o.children,...r]:o.children,s=at(this.shared).shownChildIds(n,i);o.children=this.shownOf(n)?.slice()??this.visibleIndexes(n,s).map(a=>s[a]);}if(o?.isText){let r=this.text.range(n);o.textLength=r?r.end-r.start:this.raw.node(n)?.textLength??o.textLength;}return o}},Wg={shownPartChildren:()=>null,shownParentOf:()=>null};function _d(t,e,n){let o=Id(t,e);return o?{ok:true,journal:{...e,effects:[]},plan:null,typed:o}:$g(t,e,n)}function $g(t,e,n=Wg){let o=yo(t,e.effects,x=>n.shownParentOf(x));if(o.refusal)return {ok:false,...o.refusal};let i=(o.plan?{...e,effects:o.passThrough}:e).effects.map(Ht),s=t.replacementLoserRuns(),a=i.filter(x=>x.kind==="putNode").length;if(t.nodeCount()+a>t.limits.maxNodes)return {ok:false,code:"too-many-nodes"};let l=new Set,d=new Map,c=(x,R)=>{l.add(x);let C=d.get(x)??new Set;C.add(R),d.set(x,C);};for(let x of i){if(x.kind==="spliceChildren"){if(x.childLogicalIds.length>t.limits.maxChildren)return {ok:false,code:"too-many-children"};for(let R of x.childLogicalIds)c(R,x.parentLogicalId);}else x.kind==="moveNode"&&c(x.logicalId,x.destinationParentLogicalId);if(l.size>t.limits.maxNodes)return {ok:false,code:"too-many-nodes"}}let u=new Dt(t),f=new Ki(t,u),p=new Vi(t,(x,R)=>b(x,R),u,f,x=>ee(x),x=>n.shownPartChildren(x)),h=new Map,g=x=>h.get(x)?.kind??t.kindOf(x),y=x=>{let R=h.get(x);return R?R.kind==="textValue"?{kind:"textValue",namespaceUri:"",localName:""}:{kind:R.kind,namespaceUri:R.qname.namespaceUri,localName:R.qname.localName}:et(t,x)},w=new Map,S=(x,R)=>{let C=t.splitSiblings.ranksOf(x),M=w.get(x);if(!C||!M)return C;let B=new Map(C),Q=0;for(let X of R){let F=M.get(X),re=F===void 0||B.has(X)?void 0:B.get(F);re&&B.set(X,{group:re.group,rank:re.rank+(Q+=1)/1e6});}return B},I=(x,R)=>{let C=new Map,M=new Map,B=[],X=(s.size===0?null:To(R,Z=>s.has(Z),Z=>t.splitLineageOf(Z)))??R.map((Z,te)=>te),F=_n(X.map(Z=>R[Z]),S(x,R));(F?F.map(Z=>X[Z]):X).forEach(Z=>{let te=R[Z];if(te===x||s.has(te))return;let Te=C.get(te);if(Te!==void 0){let Os=M.get(Te)??[];Os.push(Z),M.set(Te,Os);return}let Wn=l.has(te)?x:t.parentOf(te);Wn!==null&&Wn!==x&&t.listingParents(te).includes(x)||(C.set(te,Z),!(!h.has(te)&&!t.showsAsChild(te))&&B.push(Z));});let re=g(x),Ke=mo(re==="generic"?y(x)??re:re,B.map(Z=>R[Z]),y);if(!Ke)return {positions:B,companions:new Map,repeats:M};let oe=new Map;for(let[Z,te]of Ke.companions)oe.set(B[Z],te.map(Te=>B[Te]));return {positions:Ke.order.map(Z=>B[Z]),companions:oe,repeats:M}},b=(x,R)=>I(x,R).positions,v=x=>x.some((R,C)=>C>0&&R<x[C-1]),L=(x,R,C,M)=>{let B=b(x,R),Q=B[C]??R.length,X=S(x,R),F=C>0?B[C-1]:void 0,re=B[C];if(X&&F!==void 0&&(X.has(R[F])||re!==void 0&&X.has(R[re]))){if(X.has(R[F])){let oe=w.get(x)??new Map;M.forEach((Z,te)=>oe.set(Z,te===0?R[F]:M[te-1])),w.set(x,oe);}return F+1}if(!v(B))return Q;let Ke=C>0?B[C-1]+1:0;for(let oe of [Q,Ke,R.length]){let Z=[...R.slice(0,oe),...M,...R.slice(oe)],te=b(x,Z).map(Te=>Z[Te]);if(M.every((Te,Wn)=>te[C+Wn]===Te))return oe}return Q},m=x=>{let R=[x],C=new Set;for(;R.length>0;){let M=R.pop();if(C.has(M))continue;C.add(M);let B=u.node(M);if(!(!B||B.isText)){for(let Q of B.children)if(!(l.has(Q)||t.parentOf(Q)!==M)){for(let X of t.listingParents(Q)){if(X===M)continue;let F=u.node(X),re=F&&!F.isText?F.children.indexOf(Q):-1;re<0||T({kind:"spliceChildren",parentLogicalId:X,start:re,deleteCount:1,childLogicalIds:[]});}R.push(Q);}}}},k=(x,R)=>{if(t.parentOf(x)===R)for(let C of t.listingParents(x)){if(C===R||d.get(x)?.has(C))continue;let M=u.node(C);if(!(!M||M.isText))for(let B=M.children.length-1;B>=0;B-=1)M.children[B]===x&&T({kind:"spliceChildren",parentLogicalId:C,start:B,deleteCount:1,childLogicalIds:[]});}},O=new Set,P=x=>{if(O.has(x))return;O.add(x);let R=n.shownPartChildren(x),C=u.node(x);if(!R||!C||C.isText)return;let M=C.children;if(R.length===M.length&&R.every((Q,X)=>M[X]===Q))return;for(let Q of R)if(!M.includes(Q))for(let X of t.listingParents(Q)){let F=u.node(X),re=F&&!F.isText?F.children.indexOf(Q):-1;re<0||X===x||T({kind:"spliceChildren",parentLogicalId:X,start:re,deleteCount:1,childLogicalIds:[]});}let B=M.filter(Q=>!R.includes(Q));T({kind:"spliceChildren",parentLogicalId:x,start:0,deleteCount:M.length,childLogicalIds:[...R,...B]});},j=new Set,K=x=>{for(let R of at(t).movesAt(x)){if(j.has(R.node))continue;j.add(R.node);let C=u.node(R.from),M=u.node(R.to);if(!C||C.isText||!M||M.isText)continue;let B=C.children.indexOf(R.node);B<0||M.children.includes(R.node)||(T({kind:"spliceChildren",parentLogicalId:R.from,start:B,deleteCount:1,childLogicalIds:[]}),T({kind:"spliceChildren",parentLogicalId:R.to,start:R.first?0:ui(t,M.children),deleteCount:0,childLogicalIds:[R.node]}));}},Y=new Set,V=x=>{if(Y.has(x))return;Y.add(x);let R=u.node(x);if(!R||R.isText)return;let C=t.adoptedChildren(x).filter(B=>!R.children.includes(B));if(C.length===0)return;for(let B of C)for(let Q of t.listingParents(B)){if(t.replacedByOf(Q)!==x)continue;let X=u.node(Q),F=X&&!X.isText?X.children.indexOf(B):-1;F<0||T({kind:"spliceChildren",parentLogicalId:Q,start:F,deleteCount:1,childLogicalIds:[]});}let M=b(x,R.children).length;T({kind:"spliceChildren",parentLogicalId:x,start:L(x,R.children,M,C),deleteCount:0,childLogicalIds:C});},q=x=>{if(!ai.has(g(x)??""))return [];let R=t.parentOf(x),C=R?u.node(R):null;return !R||!C||C.isText?[]:(I(R,C.children).companions.get(C.children.indexOf(x))??[]).map(B=>C.children[B])},ee=x=>{let R=[];for(let C of q(x)){let M=u.node(C);M&&!M.isText&&R.push(...M.children);}return R},ne=new Set,A=x=>{if(ne.has(x))return;ne.add(x);let R=u.node(x);if(!R||R.isText)return;let C=[];for(let M of q(x)){let B=u.node(M);if(!B||B.isText||B.children.length===0)continue;let Q=[...B.children];T({kind:"spliceChildren",parentLogicalId:M,start:0,deleteCount:Q.length,childLogicalIds:[]});for(let X of Q)!R.children.includes(X)&&!C.includes(X)&&C.push(X);}C.length!==0&&T({kind:"spliceChildren",parentLogicalId:x,start:u.node(x).children.length,deleteCount:0,childLogicalIds:C});},J={limits:t.limits,projectedTextValue:x=>u.node(x)?.isText?f.value(x):null,registerSplitText:(x,R,C,M)=>f.register(x,R,C,M),splitTextPending:x=>t.splitTextPending(x),record:x=>{let R=u.node(x);if(!R)return null;if(R.isText)return {logicalId:x,kind:"textValue",value:f.value(x)};let C=h.get(x),M=C?null:t.record(x);return M&&M.kind!=="textValue"?{...M,childIds:R.children}:!C||C.kind==="textValue"?null:{logicalId:x,kind:C.kind,namespaceUri:C.qname.namespaceUri,localName:C.qname.localName,prefix:C.qname.prefix??"",attributes:[],bindings:[],childIds:R.children}}},he=[],D=null,T=x=>{if(D)return;let R=Oo(t,x,u);if(R&&!R.ok){D=R;return}he.push(x),Nn(u,x),x.kind==="spliceText"&&f.apply(x);};try{for(let x of i){let R=Oo(t,x,p);if(R&&!R.ok)return R;if(Nn(p,x),x.kind==="putNode"&&h.set(x.descriptor.logicalId,x.descriptor),x.kind==="spliceText"){let C=f.range(x.logicalId);T(C?Es({...x,logicalId:C.sourceId,utf16Start:C.start+x.utf16Start},{logicalId:x.logicalId,utf16Start:x.utf16Start}):x);}else if(x.kind==="spliceChildren"){P(x.parentLogicalId),K(x.parentLogicalId),V(x.parentLogicalId),A(x.parentLogicalId);let C=u.node(x.parentLogicalId);if(!C||C.isText)return {ok:!1,code:"invalid-bound"};let{positions:M,companions:B,repeats:Q}=I(x.parentLogicalId,C.children),X=M.slice(x.start,x.start+x.deleteCount).map(F=>C.children[F]);if(x.deleteCount===0){let F=x.childLogicalIds;T({...x,start:L(x.parentLogicalId,C.children,x.start,F)});}else {let F=M.slice(x.start,x.start+x.deleteCount),re=F.flatMap(oe=>[...B.get(oe)??[],...Q.get(oe)??[]]);if(re.length>0||v(M)){let oe=[...F,...re].sort((te,Te)=>Te-te);for(let te of oe)T({...x,start:te,deleteCount:1,childLogicalIds:[]});let Z=u.node(x.parentLogicalId);if(x.childLogicalIds.length>0&&Z&&!Z.isText){let te=x.childLogicalIds,Te=L(x.parentLogicalId,Z.children,x.start,te);T({...x,start:Te,deleteCount:0});}F.length=0;}let Ke=F.length;for(;Ke>0;){let oe=Ke-1;for(;oe>0&&F[oe-1]===F[oe]-1;)oe-=1;T({...x,start:F[oe],deleteCount:Ke-oe,childLogicalIds:oe===0?x.childLogicalIds:[]}),Ke=oe;}}if(!D)for(let F of X)k(F,x.parentLogicalId),l.has(F)||m(F);if(!D&&x.childLogicalIds.length>0)for(let F of X){if(l.has(F)&&!h.has(F))continue;let re=Ro(g(F),x.childLogicalIds,g);re&&sn(J,F,re);}}else if(x.kind==="moveNode"){P(x.destinationParentLogicalId),K(x.destinationParentLogicalId),V(x.destinationParentLogicalId),A(x.destinationParentLogicalId);let C=u.node(x.destinationParentLogicalId);if(!C||C.isText)return {ok:!1,code:"invalid-bound"};let M=C.children.filter(B=>B!==x.logicalId);T({...x,destinationIndex:L(x.destinationParentLogicalId,M,x.destinationIndex,[x.logicalId])});}else T(x);if(D)return D}return {ok:!0,journal:{effects:he},plan:o.plan}}finally{f.destroy();}}function Bd(t,e,n){if(!e.effects.some(a=>{let l=a.kind==="spliceChildren"?a.parentLogicalId:a.kind==="moveNode"?a.destinationParentLogicalId:null;return l!==null&&t.shownPartChildren(l)!==null}))return null;let r=t.current(),i=r.ok?vt(r.issues):null,s=r.ok?i?{code:"materialize-dropped-content",detail:i}:null:{code:r.code};return s?{failure:s,transient:n()}:null}function Ji(t,e,n){for(let o of e)n.push(o.id),!(o.kind==="textValue"||t.hasNode(U(o)))&&Ji(t,o.children,n);}function Ud(t,e){if(!e)return false;let n=t.partEntries().find(o=>o.name==="/word/document.xml");for(let{id:o,after:r}of e.paragraphs){let i=t.inline.textOf(o);if(!i||t.isTombstoned(o)||n&&Vg(t,o)!==n.rootLogicalId)continue;let s=new Set,a=Ze(o,i,c=>s.has(c)||!t.showsAsChild(c)?null:(s.add(c),eo(c)),t.limits,t.inline.viewOf(o)),l=[];Ji(t,a,l);let d=[];if(Ji(t,r.children.filter(c=>c.kind==="textValue"||!Kg(t,c)),d),l.length!==d.length)return true;for(let c=0;c<l.length;c+=1)if(l[c]!==d[c])return true}return false}function Kg(t,e){return e.kind==="paragraphProperties"||t.hasNode(U(e))&&!t.inline.isEmbed(e.id)}function Vg(t,e){let n=e;for(let o=0;o<t.limits.maxTreeDepth;o+=1){let r=t.parentOf(n);if(r===null)return n;n=r;}return n}var dn=Symbol("docx-restore-marks");function Fd(t,e){let n=new Map;for(let r of it(t,e)){if(r.deleted||!(r.content instanceof z.ContentString))continue;let i=r.parent;if(!(i instanceof z.Text)||je(i)!==ae)continue;let s=n.get(i)??new Set;s.add(`${r.id.client}:${r.id.clock}`),n.set(i,s);}if(n.size===0)return;let o=Le(t);t.transact(()=>{for(let[r,i]of n)for(let s=be(r);s;s=s.right){if(!s.redone)continue;let a=`${s.redone.client}:${s.redone.clock}`;if(!i.has(a))continue;let l=H(t,s.redone);if(!l||l.deleted)continue;let d=ot(r,s,0);o.markCopy("restore",s.redone.client,s.redone.clock,s.length,d),o.origin("move",s.id.client,s.id.clock)!==null&&o.markCopy("move",s.redone.client,s.redone.clock,s.length,d);}},dn);}var Hi=new WeakMap,Xi=new WeakMap,Gi=new WeakMap;function jd(t,e,n,o=null){if(e.size===0&&!o)return n();Hi.set(t.attributes,e),o&&Xi.set(t.attributes,o);try{return n()}finally{Hi.delete(t.attributes),Xi.delete(t.attributes);}}function qi(t,e,n,o){let r=new Map,i=n?.insertions;for(let s of we(n?.deletions))for(let a=s.clock;a<s.clock+s.length;){let l=H(t,{client:s.client,clock:a});if(!l){a+=1;continue}if(a=l.id.clock+l.length,i&&z.isDeleted(i,l.id))continue;let d=l.parent;if(d!==e.attributes&&d!==e.bindings||l.parentSub===null||!(l.content instanceof z.ContentAny))continue;let c=l.content.getContent()[0];if(typeof c!="string")continue;let u=r.get(d)??new Map;u.set(l.parentSub,c),r.set(d,u);}if(r.size===0)return o();Gi.set(e.attributes,r);try{return o()}finally{Gi.delete(e.attributes);}}function Jg(t,e){if(t.parentSub===null||t.deleted)return;let n=t.parent,o=Gi.get(e.attributes)?.get(n)?.get(t.parentSub);o===void 0||n._map.get(t.parentSub)!==t||n.set(t.parentSub,o);}function Hg(t,e){if(!e||t.parentSub===null)return false;let n=t.parent;if(n!==e.attributes&&n!==e.bindings)return false;let o=Hi.get(e.attributes);if(!o)return false;let r=t.parentSub.indexOf(ge);return r>0&&o.has(t.parentSub.slice(0,r))}function Xg(t){return t.content instanceof z.ContentType}function zd(t,e){return n=>{let o=n.parent;if(o===null)return true;if(Hg(n,e)||e&&Xi.get(e.attributes)?.(n)||(e&&(o===e.attributes||o===e.bindings)&&Jg(n,e),o===t))return false;let r=Me(o);return r===null||r.parent!==t?true:n.parentSub===wt||n.parentSub===Jn?false:!Xg(n)}}var Gg=Symbol("docx-tombstone-again");function Kd(t,e,n){if(t.local){Qg(t,e);return}if(n.undoStack.length===0)return;let o=t.doc,r=new Map;z.iterateDeletedStructs(t,t.deleteSet,s=>{if(!(s instanceof z.Item))return;let a=s.parentSub===me;if(!a&&s.parentSub!==ue)return;let l=s.parent;if(!(l instanceof z.Map)||l._item?.parent!==e)return;let d=r.get(l);r.set(l,{deletion:a||d?.deletion===true});});let i=[];for(let[s,{deletion:a}]of r){let l=s.get(me);if(a&&l===void 0){let u=$d(s,o.clientID,n,me);if(u){let f=Zi(s,o.clientID,u.insertions);i.push({record:s,step:u,deletion:true,survivor:f});continue}}if(l!==true||s.get(ue)!==void 0)continue;let d=$d(s,o.clientID,n,ue),c=d?Zi(s,o.clientID,d.insertions):null;d&&c!==null&&i.push({record:s,step:d,deletion:false,survivor:c});}if(i.length!==0){o.transact(()=>{for(let{record:s,deletion:a,survivor:l}of i)Jd(s,a,l);},Gg);for(let{record:s,step:a,deletion:l,survivor:d}of i)Hd(a,s,l,d);}}var Qi=new WeakMap,qg=64,Vd=t=>`${t.client}:${t.clock}`;function Qg(t,e){for(let[n,o]of t.changed){if(!o.has(ue)||!(n instanceof z.Map)||n._item?.parent!==e)continue;let r=n,i=r._map.get(ue),s=r.get(ue);if(!i||i.deleted||i.id.client!==t.doc.clientID||typeof s!="string"||s.length===0)continue;let a=Qi.get(r);a||Qi.set(r,a=new Map),a.size>=qg&&a.delete(a.keys().next().value),a.set(Vd(i.id),s);}}function Zi(t,e,n){if(es(t,e,ue))return null;let o=Qi.get(t);if(!o)return null;for(let r=t._map.get(ue)??null;r;r=r.left)if(r.parentSub===ue&&!(r.id.client!==e||!r.deleted)&&z.isDeleted(n,r.id))return o.get(Vd(r.id))??null;return null}function Jd(t,e,n){e&&t.set(me,true),n!==null&&t.set(ue,n);}function Hd(t,e,n,o){n&&Wd(t,e,me),o!==null&&Wd(t,e,ue);}function Wd(t,e,n){let o=e._map.get(n);if(!o)return;let r=z.createDeleteSet();r.clients.set(o.id.client,[{clock:o.id.clock,len:o.length}]),t.insertions=z.mergeDeleteSets([t.insertions,r]);}function Xd(t,e,n,o,r){let i=new Set,s=e instanceof z.Map?e:null;for(let l of o){let d=s?.get(l);d instanceof z.Map&&!es(d,t.clientID)&&i.add(d);}for(let l of we(n.deletions))for(let d=l.clock;d<l.clock+l.length;){let c=H(t,{client:l.client,clock:d});if(!c)break;if(d=c.id.clock+c.length,c.parentSub!==me||c.id.client!==t.clientID||!c.deleted||c.redone!==null)continue;let u=c.parent;!(u instanceof z.Map)||u._item?.parent!==e||es(u,t.clientID)||i.add(u);}if(i.size===0)return;let a=r();for(let l of i){let d=Zi(l,t.clientID,n.deletions);Jd(l,true,d),Hd(a,l,true,d);}}function $d(t,e,n,o){for(let r=t._map.get(o)??null;r;r=r.left){if(r.parentSub!==o||r.id.client!==e||!r.deleted)continue;let i=n.undoStack.find(s=>z.isDeleted(s.insertions,r.id));if(i)return i}return null}function es(t,e,n=me){let o=t._map.get(n);return !!o&&!o.deleted&&o.id.client===e}function Gd(t,e,n){let o=new Set;for(let r of we(n?.insertions))if(r.client===t.clientID)for(let i=r.clock;i<r.clock+r.length;){let s=H(t,{client:r.client,clock:i});if(!s)break;if(i=s.id.clock+s.length,s.parentSub!==me)continue;let a=s.parent;if(!(a instanceof z.Map)||a._item?.parent!==e)continue;let l=a._item?.parentSub??null;l!==null&&o.add(l);}return [...o]}var Ao="undoneInto",Zg=512;function qd(t){return _(t)&&t.get(ae)instanceof z.Text}function Qd(t){if(!_(t)||Ae(t))return null;let e=t.get(Ao);if(typeof e!="string"||e.length>Zg)return null;let n=e.startsWith("^"),o=n?e.slice(1):e;return o.length>0?{paragraph:G(o),atStart:n}:null}function Zd(t,e,n){let o=new Map;for(let r of we(n?.insertions))for(let i=r.clock;i<r.clock+r.length;){let s=H(t,{client:r.client,clock:i});if(!s)break;i=s.id.clock+s.length;let a=s.parent;if(s.deleted||!(a instanceof z.Array)||je(a)!==xt)continue;let l=Me(a)?.parent;if(!(l instanceof z.Map)||Me(l)?.parent!==e)continue;let d=o.get(a)??new Set;for(let c of s.content.getContent())typeof c=="string"&&qd(e.get(c))&&d.add(G(c));d.size>0&&o.set(a,d);}return o}function ec(t,e,n,o){let r=[];for(let[i,s]of Zd(t,e,n)){let a=i.toArray(),l=f=>{let p=a[f],h=p===void 0?void 0:e.get(p);return p!==void 0&&qd(h)&&!Ae(h)?p:null},d=[],c=null;a.forEach((f,p)=>{d.push(c),s.has(f)||(c=l(p));});let u=null;for(let f=a.length-1;f>=0;f-=1){let p=a[f];if(!s.has(p)){u=l(f);continue}let h=e.get(p),g=d[f]??(u===null?void 0:`^${u}`);h&&h.get(Ao)!==g&&r.push({record:h,target:g});}}r.length!==0&&o(()=>{for(let{record:i,target:s}of r)s===void 0?i.delete(Ao):i.set(Ao,s);});}function em(t,e){let n=e.parent;if(!(n instanceof z.Text)||je(n)!==ae)return null;let o=Me(n)?.parent;return o instanceof z.Map&&Me(o)?.parent===t?o:null}function tc(t,e,n){let o=new Set;for(let d of we(n?.deletions))for(let c=d.clock;c<d.clock+d.length;){let u=H(t,{client:d.client,clock:c});if(!u)break;c=u.id.clock+u.length;let f=em(e,u);f&&o.add(f);}if(o.size===0||[...o].some(d=>!Ae(d)))return null;let r=Le(t),i=d=>r.origin("move",d.id.client,d.id.clock)!==null,s=new Set,a=new Set;for(let d of Zd(t,e,n).values())for(let c of d){let u=e.get(c)?.get(ae);if(u instanceof z.Text){for(let f=be(u);f;f=f.right)if(!(f.deleted||!i(f))){s.add(c),a.add(u);break}}}if(s.size===0)return null;let l=new Set([...s].map(d=>e.get(d)));return d=>{let c=d.parent;if(a.has(c))return i(d);if(l.has(c))return true;if(!(c instanceof z.Array)||je(c)!==xt)return false;let u=d.content.getContent();return u.length>0&&u.every(f=>s.has(f))}}var tm=new Set(["comment","commentEx","footnote","endnote"]),nc="docx-undone-records";function nm(t,e,n,o){let r=n?.meta,i=e==="undo"?o.filter(a=>{let l=t.record(a);return _(t.schema.nodes.get(a))&&!t.isTombstoned(a)&&!!l&&W(l)&&tm.has(l.localName)}):[],s=e==="redo"?r?.get(nc)??[]:[];e==="undo"&&r?.set(nc,i),!(i.length===0&&s.length===0)&&t.doc.transact(()=>{for(let a of i)t.schema.nodes.get(a)?.set(St,true);for(let a of s){let l=t.schema.nodes.get(a);_(l)&&l.has(St)&&l.delete(St);}},dn);}var ts="docx-copy-runs",oc="docx-hidden-copies",ic="docx-copies-only",rc="docx-own-deletes",ns="docx-undo-group";function os(t){t.meta.set(ns,true);}function sc(t,e,n){t.normalizeRestoredSplitTextAnchors(),Fd(e,n),e.transact(()=>nd(e,o=>t.schema.nodes.get(o),n),dn);}function ac(t,e,n,o){let r=n==="undo"?e.undoStack:e.redoStack,i=n==="undo"?e.redoStack:e.undoStack,s=r[r.length-1],a=n==="undo"?dm(t,s):No(s,ts)??[],l=i.length,d=n==="undo"?Gd(t.doc,t.schema.nodes,s):No(s,rc)??[],c=s?.meta.get(ic)===true&&lm(s)===0,u=s?.meta.get(ns)===true;if(c||a.length>0&&cm(t,s))r.pop();else {let p=r.splice(0,u?r.length-1:am(r));try{n==="undo"?(ec(t.doc,t.schema.nodes,s,h=>t.doc.transact(h,dn)),jd(t.schema,im(t,s),()=>qi(t.doc,t.schema,s,()=>e.undo()),tc(t.doc,t.schema.nodes,s))):qi(t.doc,t.schema,s,()=>e.redo());}finally{if(p.length>0){let h=p.concat(r);r.length=0;for(let g of h)r.push(g);}}}let f=i.length>l?i[i.length-1]:void 0;t.doc.transact(()=>{if(o(),n==="redo"&&s&&Xd(t.doc,t.schema.nodes,s,d,()=>(f??=Do(i),f)),n==="undo"&&d.length>0&&(f??=Do(i),f.meta.set(rc,d)),n==="redo"){let p=No(s,oc);p&&p.length>0&&Qe(t.doc).withdraw(p);}a.length>0&&(f??=Do(i),f.meta.set(ts,a),n==="undo"&&f.meta.set(oc,Qe(t.doc).record(a)));},dn),u&&(f??=Do(i),os(f)),nm(t,n,n==="redo"?s:f,t.takeUnlisted()),e.stopCapturing();}function om(t,e,n,o){let r=[];for(let i=n;i<o;){let s=t.origin("restore",e,i);if(s===null||s.client!==e){let d=s===null?o:Math.min(o,s.firstClock+s.length);r.push({client:e,from:i,to:d}),i=d;continue}let a=Math.min(o,s.firstClock+s.length),l=s.clock+(i-s.firstClock);r.push({client:s.client,from:l,to:l+(a-i)}),i=a;}return r}function rm(t,e,n,o){for(let r=n;r<o;r+=1)if(t.shownCopy(`${e}:${r}`))return true;return false}function im(t,e){let n=new Set,o=t.schema.nodes;for(let r of we(e?.insertions))for(let i=r.clock;i<r.clock+r.length;){let s=H(t.doc,{client:r.client,clock:i});if(!s)break;s.parent===o&&s.parentSub!==null&&n.add(s.parentSub),i=s.id.clock+s.length;}return n}function sm(t){return !(t.content instanceof z.ContentString)&&!(t.content instanceof z.ContentEmbed)?false:lc(t)}function lc(t){return t.content instanceof z.ContentFormat?false:t.parent instanceof z.Text&&t.parent._item?.parentSub===ae}function am(t){for(let e=t.length-2;e>=0;e-=1)if(t[e].meta.get(ns)===true)return e+1;return 0}function lm(t){let e=t;return we(e.insertions).length+we(e.deletions).length}function dm(t,e){let n=t.inline.follow,o=Le(t.doc),r=(No(e,ts)??[]).map(s=>({...s})),i=(s,a,l)=>{let d=r[r.length-1];d&&d.client===s&&d.to===a?d.to=l:r.push({client:s,from:a,to:l});};for(let s of we(e?.insertions)){let a=s.clock+s.length;for(let l=s.clock;l<a;){let d=H(t.doc,{client:s.client,clock:l}),c=d?Math.min(d.id.clock+d.length,a):l+1;if(d?.deleted||d&&!o.origin("restore",s.client,l)){let u=om(o,s.client,l,c);if(!!d&&(d.deleted?lc(d):sm(d))||u.some(p=>n.holdsCopyIn(p.client,p.from,p.to)&&rm(n,p.client,p.from,p.to)))for(let p of u)i(p.client,p.from,p.to);}l=c;}}return r}function cm(t,e){if(!e)return false;let n=new Set(t.trackedTypes()),o=e;for(let[r,i]of [[we(o.deletions),true],[we(o.insertions),false]])for(let s of r)for(let a=s.clock;a<s.clock+s.length;){let l=H(t.doc,{client:s.client,clock:a});if(!l||um(l,n)&&(i||!l.deleted))return false;a=l.id.clock+l.length;}return true}function um(t,e){let n=t.parent;for(;n!==null;){if(e.has(n))return true;let o=n._item?.parent;n=o instanceof z.AbstractType?o:null;}return false}function No(t,e){return t?.meta.get(e)}function Do(t){let e={meta:new Map([[ic,true]])};return Object.assign(e,{insertions:z.createDeleteSet(),deletions:z.createDeleteSet()}),t.push(e),e}function dc(t,e,n){let o=t.trackedOrigins.delete(e);try{return n()}finally{o&&t.trackedOrigins.add(e);}}var Yo=class{constructor(e,n){this.undoManager=e;let o=r=>{this.capturing&&r.type==="undo"&&(this.gestureItem=r.stackItem,this.captured=true,this.pinned!==void 0&&os(r.stackItem));};e.on("stack-item-added",o),e.on("stack-item-updated",o),n&&mm(n,e,()=>this.reset());}undoManager;previous;gestureItem;capturing=false;captured=false;pinned;capture(e,n){let o=this.pinned??e,r=this.previous;this.previous=o;let i=this.undoManager.undoStack,s=this.undoManager.captureTimeout;o===r&&o!==void 0&&i[i.length-1]===this.gestureItem?(this.undoManager.lastChange=Date.now(),this.undoManager.captureTimeout=Number.POSITIVE_INFINITY):((o!==r||o!==void 0)&&this.undoManager.stopCapturing(),this.gestureItem=void 0);let a=this.gestureItem;this.captured=false,this.capturing=o!==void 0;try{let l=n();return this.captured&&reportHistoryGroup(e,this.gestureItem===a?"extended":"started"),l}catch(l){throw this.refused(),l}finally{this.capturing=false,this.undoManager.captureTimeout=s;}}captureJournal(e,n,o){return isJournalOutsideUndo(e)?dc(this.undoManager,n,o):this.capture(historyGroupOfJournal(e),o)}reset(){this.previous=void 0,this.gestureItem=void 0;}refused(){this.pinned===void 0&&this.reset();}pin(e){this.undoManager.stopCapturing(),this.reset(),this.pinned=e;}unpin(){this.pinned=void 0,this.reset(),this.undoManager.stopCapturing();}};function mm(t,e,n){let o=new WeakMap,r=i=>{let s=o.get(i);return s||o.set(i,s={}),s};e.on("stack-item-popped",({stackItem:i,type:s})=>{let a=(s==="undo"?e.redoStack:e.undoStack).at(-1);a&&o.set(a,r(i));}),registerUndoHistoryPosition(t,{current:()=>{let i=e.undoStack.at(-1);return i?r(i):null},split:()=>{n(),e.stopCapturing(),e.clear(false,true);}});}function cc(t,e){let n=Le(t),o=Qe(t),r=Cn(t),i=null,s=u=>{if(!e.loading()){if(u==="all"||i==="all"){i="all";return}i??=new Set;for(let f of u)i.add(f);}},a=()=>{let u=i;if(i=null,u===null||e.loading())return;let f=e.inline.marksChanged(u==="all"?e.inline.allTexts():u);f.size>0&&e.changed(f);},l=n.subscribe(s),d=o.subscribe(u=>s(n.textsReading(u))),c=r.subscribe(u=>s(n.textsReading(u)));return t.on("beforeObserverCalls",a),()=>{l(),d(),c(),t.off("beforeObserverCalls",a);}}function uc(t,e){let n=[],o=e;for(let r=0;r<t.maxDepth;r+=1){let i=t.parentOf(o);if(i===void 0)break;n.push(t.childrenOf(i)?.indexOf(o)??-1),o=i;}return {root:o,indexes:n.reverse()}}function fc(t,e,n){if(e===n)return 0;let o=uc(t,e),r=uc(t,n);if(o.root===r.root){let i=Math.min(o.indexes.length,r.indexes.length);for(let s=0;s<i;s+=1){let a=o.indexes[s]-r.indexes[s];if(a!==0)return a}}return e<n?-1:1}var _o=class{unlisted=new Set;marks=new Set;noteUnlisted(e){this.unlisted.add(e);}noteMarkChanged(e){this.marks.add(e);}takeUnlisted(e){let n=[...this.unlisted].filter(o=>!e(o));return this.unlisted.clear(),n}takeMarkChanges(){let e=[...this.marks];return this.marks.clear(),e}};function pc(t,e){let n=i=>{let s=new Set,a=false;for(let l of i){let d=l.path;if(d.length===0){for(let c of l.changes.keys.keys())s.add(G(c));a=true;continue}s.add(G(d[0])),l.target instanceof z.Array&&(a=true),l.target instanceof z.Map&&(l.changes.keys.has(me)||l.changes.keys.has(ue))&&(a=true);}(s.size>0||a)&&e({logicalIds:s,membershipChanged:a,packageChanged:false});},o=i=>{let s=new Set;for(let a of i.changes.keys.keys()){let l=bn(String(a))??Ot(String(a));!l||E(l.logicalId)||s.add(l.logicalId);}s.size>0&&e({logicalIds:s,membershipChanged:false,packageChanged:false});},r=()=>{e({logicalIds:new Set,membershipChanged:false,packageChanged:true});};return t.nodes.observeDeep(n),t.attributes.observe(o),t.bindings.observe(o),t.parts.observeDeep(r),t.relationships.observeDeep(r),t.overrides.observe(r),t.defaults.observe(r),t.binaries.observeDeep(r),()=>{t.nodes.unobserveDeep(n),t.attributes.unobserve(o),t.bindings.unobserve(o),t.parts.unobserveDeep(r),t.relationships.unobserveDeep(r),t.overrides.unobserve(r),t.defaults.unobserve(r),t.binaries.unobserveDeep(r);}}function hc(t,e){if(!t.hasNode(e)||t.isTombstoned(e))return false;let n=t.parentOf(e);if(n===null)return false;let o=t.record(n);return o!==null&&W(o)&&o.childIds.includes(e)}function Uo(t){return typeof t=="string"?t:""}function gc(t,e){return t<e?-1:t>e?1:0}function rs(t,e){return `${t}${ge}${e}`}function bm(t){let e=t.indexOf(ge);return e<0?t:t.slice(0,e)}function mc(t){let e=[];return t.forEach((n,o)=>{!_(n)||E(o)||n.forEach(r=>{if(!_(r))return;let i=Uo(r.get("id")),s=Uo(r.get("type"));if(i.length===0||s.length===0)return;let a=Uo(r.get("ownerPart"))||bm(o);if(E(a))return;let l=r.get("order");e.push({ownerPart:a,id:i,type:s,rawTarget:Uo(r.get("rawTarget")),targetMode:r.get("targetMode")==="External"?"External":"Internal",order:typeof l=="number"&&Number.isSafeInteger(l)?l:0});});}),e.sort((n,o)=>n.order-o.order||gc(n.ownerPart,o.ownerPart)||gc(n.id,o.id)),e}function yc(t,e){return t.nodes.observeDeep(e.onNodeEvents),t.attributes.observe(e.onAttributeEvent),t.bindings.observe(e.onBindingEvent),t.relationships.observeDeep(e.onRelationshipChange),t.parts.observeDeep(e.onPartChange),()=>{t.nodes.unobserveDeep(e.onNodeEvents),t.attributes.unobserve(e.onAttributeEvent),t.bindings.unobserve(e.onBindingEvent),t.relationships.unobserveDeep(e.onRelationshipChange),t.parts.unobserveDeep(e.onPartChange);}}function Im(t,e){let n=Math.min(t.length,e.length);for(let o=0;o<n;o+=1){let r=t[o]-e[o];if(r!==0)return r}return t.length-e.length}function xm(t,e){let n=t.childrenSnapshot.get(e);return n||(ie(t.nodes.get(e))?.toArray()??[])}function Sm(t,e){let n=t.nodes.get(e);return !_(n)||Ae(n)}var is=class{constructor(e){this.ctx=e;}ctx;byParent=new Map;indexOf(e,n){let o=this.byParent.get(e);return o||(o=new Map,xm(this.ctx,e).forEach((r,i)=>{o.has(r)||o.set(r,i);}),this.byParent.set(e,o)),o.get(n)??-1}};function wm(t,e,n,o,r){let i=[],s=new Set,a=r,l;for(;;){if(s.has(a)||(s.add(a),Sm(t,a)))return null;l=n.get(a);let u=t.parentIndex.get(a);if(l!==void 0){if(u!==void 0||o.has(a))return "fallback";break}if(u===void 0)return o.has(a)?"deferred":null;i.push(a),a=u;}let d=[l],c=a;for(let u=i.length-1;u>=0;u-=1){let f=i[u],p=e.indexOf(c,f);if(p<0)return null;d.push(p),c=f;}return d}function km(t,e){let n=new Set(e);for(let l of n)t.parentIndex.delete(l);let o=new Map;t.partRoots.forEach((l,d)=>{o.has(l)||o.set(l,d);});let r=new is(t),i=new Map,s=l=>{let d=i.get(l);if(d!==void 0)return d;let c=wm(t,r,o,n,l);return c!=="deferred"&&i.set(l,c),c},a=[...n];for(;a.length>0;){let l=[];for(let d of a){let c=null,u=false;for(let f of t.listings.get(d)??[]){if(f===d)continue;let p=s(f);if(p==="fallback")return false;if(p==="deferred"){u=true;continue}if(p===null)continue;let h=r.indexOf(f,d);if(h<0)continue;let g=[...p,h];(!c||Im(g,c.rank)<0)&&(c={rank:g,parent:f});}if(u){l.push(d);continue}c&&t.parentIndex.set(d,c.parent),n.delete(d);}if(l.length===a.length)return false;a=l;}return true}function ss(t,e){let{nodes:n,parentIndex:o,childrenSnapshot:r,partRoots:i}=t;if(e)for(let s of e)o.delete(s);for(let s of i){let a=new Set,l=[{id:s,parent:null,exit:false}];for(;l.length>0;){let d=l.pop();if(d.exit){a.delete(d.id);continue}let c=d.id;if(d.parent!==null&&(e===null||e.has(c))&&(o.has(c)||o.set(c,d.parent)),a.has(c))continue;let u=n.get(c);if(!_(u)||Ae(u))continue;let f=r.get(c)??ie(u)?.toArray()??[];a.add(c),l.push({id:c,parent:null,exit:true});let p=new Set,h=[];for(let g of f)p.has(g)||g===c||(p.add(g),h.push(g));for(let g=h.length-1;g>=0;g-=1)l.push({id:h[g],parent:c,exit:false});}}}function bc(t,e){let n=[];for(let o of e){let r=t.listings.get(o);if(!r||r.size===0){t.parentIndex.delete(o);continue}if(r.size===1){t.parentIndex.set(o,[...r][0]);continue}n.push(o);}n.length!==0&&(km(t,n)||ss(t,new Set(n)));}function Ic(t,e){return `${t}${ge}${e}`}function as(t,e,n,o,r){if(E(n)||E(o.localName))return;let i=Wt(t.namespaces,o.namespaceUri,e),s=Or(n,i,o.localName);E(s)||t.attributes.set(s,Js(o.prefix??"",r));}function xc(t,e,n,o){t.attributes.delete(Or(e,Lt(n),o));}function ls(t,e,n,o,r){if(E(n)||E(o))return;let i=Wt(t.namespaces,r,e),s=Er(n,o);E(s)||t.bindings.set(s,i);}function Sc(t,e,n){t.bindings.delete(Er(e,n));}function wc(t,e,n,o,r,i){let{prefix:s,value:a}=Hs(i),l=e.get(n);l||(l=new Map,e.set(n,l)),l.set(Ic(o,r),{namespaceUri:Rt(t.namespaces,o),localName:r,prefix:s.length>0?s:void 0,value:a});}function vm(t,e,n,o){let r=t.get(e);r&&(r.delete(Ic(n,o)),r.size===0&&t.delete(e));}function kc(t,e,n,o,r){let i=e.get(n);i||(i=new Map,e.set(n,i)),i.set(o,{prefix:o,namespaceUri:Rt(t.namespaces,r)});}function Lm(t,e,n){let o=t.get(e);o&&(o.delete(n),o.size===0&&t.delete(e));}function vc(t,e,n){for(let[o,r]of n.changes.keys){let i=bn(String(o));if(!i||E(i.logicalId)||E(i.localName))continue;if(r.action==="delete"){vm(e,i.logicalId,i.namespaceId,i.localName);continue}let s=t.attributes.get(String(o));typeof s=="string"&&wc(t,e,i.logicalId,i.namespaceId,i.localName,s);}}function Lc(t,e,n){for(let[o,r]of n.changes.keys){let i=Ot(String(o));if(!i||E(i.logicalId)||E(i.prefix))continue;if(r.action==="delete"){Lm(e,i.logicalId,i.prefix);continue}let s=t.bindings.get(String(o));typeof s=="string"&&kc(t,e,i.logicalId,i.prefix,s);}}function Rc(t,e,n){t.attributes.forEach((o,r)=>{if(typeof o!="string"||E(r))return;let i=bn(r);!i||E(i.logicalId)||E(i.localName)||wc(t,e,i.logicalId,i.namespaceId,i.localName,o);}),t.bindings.forEach((o,r)=>{if(typeof o!="string"||E(r))return;let i=Ot(r);!i||E(i.logicalId)||E(i.prefix)||kc(t,n,i.logicalId,i.prefix,o);});}function ds(t,e,n){let o=t.listings.get(e)??new Set;o.add(n),t.listings.set(e,o);}function Rm(t,e,n){let o=t.listings.get(e);o&&(o.delete(n),o.size===0&&t.listings.delete(e));}function Oc(t,e,n){let o=t.childrenSnapshot.get(e)??[];if(Qn(o,n))return [];let r=new Set(n),i=new Set(o),s=[];for(let a of o)r.has(a)||(Rm(t,a,e),s.push(a));for(let a of n)i.has(a)||(ds(t,a,e),s.push(a));return t.childrenSnapshot.set(e,n),s}function Ec(t,e){if(!t||e.length===0)return;let n=new Map;for(let o of e)n.set(o,(n.get(o)??0)+1);for(let o=t.length-1;o>=0;o-=1){let r=t.get(o),i=n.get(r)??0;i!==0&&(n.set(r,i-1),t.delete(o,1));}}var Om=1024,Fo=class{constructor(e,n){this.nodes=e;this.reads=n;}nodes;reads;adoptees=new Map;sources=new Map;survivorOf=new Map;reset(){this.adoptees=new Map,this.sources=new Map,this.survivorOf=new Map;}sync(e){let n=this.survivorOf.get(e);if(n!==void 0){this.survivorOf.delete(e);let i=this.sources.get(n);i&&(i.delete(e),i.size===0&&this.sources.delete(n));}let o=this.nodes.get(e),r=qn(o);if(n!==void 0&&n!==r&&this.recompute(n),r!==null){if(Ae(o)){let i=this.sources.get(r)??new Set;i.add(e),this.sources.set(r,i),this.survivorOf.set(e,r);}this.recompute(r);}}recomputeListerSurvivors(e){for(let n of this.reads.listersOf(e)){let o=this.survivorOf.get(n);o!==void 0&&this.recompute(o);}}isContentWitness(e){let n=this.reads.kindOf(e);return n!==null&&!n.endsWith("Properties")}recompute(e){let n=new Set,o=e;for(;o!==void 0&&!n.has(o)&&n.size<Om;)n.add(o),this.recomputeOne(o),o=this.survivorOf.get(o);}recomputeOne(e){let n=[],o=new Set,r=oa(this.nodes,this.sources.get(e));for(let i of r){let s=this.nodes.get(i);if(!s)continue;let a=ie(s)?.toArray()??[];for(let l of [...a,...this.adoptees.get(i)??[]])o.has(l)||this.reads.isTombstoned(l)||!this.nodes.has(l)||this.isContentWitness(l)&&(o.add(l),n.push(l));}n.length>0?this.adoptees.set(e,n):this.adoptees.delete(e);}};function _t(t){let e=2166136261;for(let n=0;n<t.length;n+=1)e=Math.imul(e^t.charCodeAt(n),16777619)>>>0;return String(e).padStart(10,"0")}var Em=/^\d{10}$/,cs=class extends Set{heap=[];add(e){return this.has(e)||(super.add(e),this.heap&&this.push(e)),this}first(){let e=this.heap;for(;e.length>0&&!this.has(e[0]);)this.pop();return e[0]}push(e){let n=this.heap;n.push(e);for(let o=n.length-1;o>0;){let r=o-1>>1;if(n[r]<=n[o])break;[n[r],n[o]]=[n[o],n[r]],o=r;}}pop(){let e=this.heap,n=e.pop();if(e.length!==0){e[0]=n;for(let o=0;;){let r=2*o+1,i=r+1,s=o;if(r<e.length&&e[r]<e[s]&&(s=r),i<e.length&&e[i]<e[s]&&(s=i),s===o)break;[e[s],e[o]]=[e[o],e[s]],o=s;}}}};function un(t){return t.first()}function Cm(t){let e=[];for(let n of [t.run?.id,t.runProperties?.id,t.text?.id,t.textValueId,...t.wrap.map(o=>o.id)])n&&e.push(n);return e}var jo=class{constructor(e,n,o,r,i=()=>{}){this.nodes=e;this.limits=n;this.isDeleted=o;this.textChanged=i;this.follow=new Lo(s=>this.textOf(s),o,r,s=>this.noteOthers(s),s=>this.paragraphHolding(s),s=>Qd(this.nodes.get(s)));}nodes;limits;isDeleted;textChanged;holders=new Map;idsOf=new Map;embeds=new Set;affected=new Set;built=false;drift=false;follow;paragraphHolding(e){let n=ke(e),o=this.nodes.doc;if(!o||!n)return null;let{client:r,clock:i}=n,s=H(o,{client:r,clock:i})?.parent;if(!(s instanceof z.Text)||je(s)!==ae)return null;let a=Me(s)?.parent,l=a instanceof z.Map?je(a):null;if(l===null||E(l))return null;let d=G(l);return this.textOf(d)===s?d:null}isDeletedParagraph(e){return this.isDeleted(e)}textOf(e){let n=this.nodes.get(e);if(!_(n))return null;let o=n.get(ae);return o instanceof z.Text?o:null}owner(e){this.ensureBuilt();let n=e,o=null;for(let r=0;r<64;r+=1){let i=this.holders.get(n);if(i){if(o!==null){for(let d of i)if(_t(d)===o)return d;for(let d of i)for(let c of this.follow.targetsFor(d))if(_t(c)===o)return c;let l=this.paragraphTagged(o);if(l)return l}return un(i)}if(n!==e&&this.textOf(n))return n;let s=n.lastIndexOf("~");if(s<0)return null;let a=n.slice(s+1);o===null&&Em.test(a)&&(o=a),n=n.slice(0,s);}return null}paragraphTagged(e){for(let o of this.idsOf.keys())if(_t(o)===e)return o;let n=null;return this.nodes.forEach((o,r)=>{n===null&&_t(r)===e&&this.textOf(r)&&(n=r);}),n}holdersOf(e){return this.ensureBuilt(),this.holders.get(e)??new Set}shownId(e,n){if(this.ensureBuilt(),this.nodes.has(n))return `${n}~${_t(e)}`;let o=this.holders.get(n);return o&&!o.has(e)?`${n}~${_t(e)}`:!o||o.size<2||un(o)===e?n:`${n}~${_t(e)}`}viewOf(e){return this.ensureBuilt(),{shownId:n=>this.shownId(e,n),noteDrift:()=>this.noteDrift(),showsEmbed:n=>{let o=this.holders.get(n);return !o||o.size<2||un(o)===e},shown:n=>this.follow.shown(e,n),textOf:n=>this.textOf(n),lineageOf:n=>yl(this.nodes.get(n)),listed:n=>!this.isDeleted(n)}}sharesIds(e){this.ensureBuilt();for(let n of this.idsOf.get(e)??[])if((this.holders.get(n)?.size??0)>1||!this.embeds.has(n)&&this.nodes.has(n))return true;return false}isEmbed(e){return this.ensureBuilt(),this.embeds.has(e)}noteDrift(){this.drift=true;}takeDrift(){this.follow.settle();let e=this.drift||this.affected.size>0;return this.drift=false,e}takeAffected(){if(this.follow.settle(),this.affected.size===0)return new Set;let e=new Set(this.affected);return this.affected.clear(),e}allTexts(){let e=new Set;return this.nodes.forEach((n,o)=>{let r=this.textOf(o);r&&e.add(r);}),e}marksChanged(e){let n=new Set;if(!this.built)return n;for(let o of e){if(je(o)!==ae)continue;let r=Me(o)?.parent,i=r instanceof z.Map?je(r):null;if(i===null||E(i))continue;let s=G(i);this.textOf(s)===o&&(this.follow.invalidate(s),this.paragraphChanged(s),n.add(s));}return n}paragraphChanged(e){if(this.textChanged(e),!this.built)return;let n=this.idsOf.get(e)??new Set,o=new Set,r=new Set,i=this.textOf(e);if(i)for(let s of i.toDelta()){if(typeof s.insert=="object"&&s.insert!==null){let a=s.insert.n;typeof a=="string"&&(o.add(a),r.add(a));}for(let a of Cm(Ne(s.attributes,this.limits,e)))o.add(a);}for(let s of n)o.has(s)||this.release(s,e);for(let s of o)n.has(s)||this.hold(s,e);for(let s of r)this.embeds.add(s);o.size>0?this.idsOf.set(e,o):this.idsOf.delete(e),this.noteOthers(this.follow.paragraphChanged(e));}noteOthers(e){for(let n of e)this.affected.add(n);e.size>0&&this.noteDrift();}orderChanged(){if(this.built)for(let e of this.follow.orderChanged())this.affected.add(e);}recordArrived(e){if(this.built)for(let n of this.holders.get(e)??[])this.holderAffected(n);}holderAffected(e){this.affected.add(e);for(let n of this.follow.placedTargetsFor(e))this.affected.add(n);}listingChanged(e){if(this.built){for(let n of this.holders.get(e)??[])this.holderAffected(n);this.textOf(e)&&(this.noteOthers(this.follow.paragraphChanged(e)),this.affected.add(e));}}hold(e,n){let o=this.holders.get(e);if(o||(o=new cs,this.holders.set(e,o)),o.size>0){let i=un(o);n<i&&this.affected.add(i);}let r=o.size<2;o.add(n),r&&this.holdersChanged(o);}release(e,n){let o=this.holders.get(e);if(!o)return;o.size<=2&&this.holdersChanged(o);let r=un(o)===n;if(o.delete(n),o.size===0){this.holders.delete(e),this.embeds.delete(e);return}r&&this.affected.add(un(o));}holdersChanged(e){for(let n of e)for(let o of this.follow.placedTargetsFor(n))e.has(o)||this.affected.add(o);}rebuild(){this.built=true,this.markShared(),this.follow.clear(),this.holders.clear(),this.idsOf.clear(),this.embeds.clear(),this.nodes.forEach((e,n)=>{_(e)&&e.get(ae)instanceof z.Text&&this.paragraphChanged(G(n));}),this.markShared();}ensureBuilt(){this.built||(this.rebuild(),this.follow.settle(),this.affected.clear());}markShared(){for(let e of this.holders.values())if(e.size>1)for(let n of e)this.affected.add(n);}};function fn(t){return typeof t=="string"?t:""}function Cc(t){let e=[];return t.forEach((n,o)=>{if(!_(n)||E(o))return;let r=fn(n.get("rootId"));r.length!==0&&e.push({name:o,id:fn(n.get("id")),rootLogicalId:r,contentType:fn(n.get("contentType"))});}),e.sort((n,o)=>n.name<o.name?-1:n.name>o.name?1:0),e}function Tc(t){let e=new Map;return t.forEach((n,o)=>{typeof n=="string"&&!E(o)&&e.set(partNameKey(o),n);}),e}function Mc(t){let e=new Map;return t.forEach((n,o)=>{typeof n=="string"&&!E(o)&&e.set(o,n);}),e}function Pc(t){let e=[];return t.forEach((n,o)=>{if(!_(n)||E(o))return;let r=fn(n.get("digest")),i=n.get("size"),s=fn(n.get("mediaType")),a=fn(n.get("storageKey"))||o;r.length===0||typeof i!="number"||e.push({digest:r,size:i,mediaType:s,storageKey:a});}),e}var us="/word/numbering.xml",Mm="http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering";function Ac(t,e){let n=e.parent;if(n===t.bindings&&e.parentSub){let a=Ot(e.parentSub),l=a&&t.nodes.get(a.logicalId);if(l){let d=Ge(l);if(d.localName==="numbering"&&t.namespaces.get(d.namespaceId)==="http://schemas.openxmlformats.org/wordprocessingml/2006/main")return true}}if(n===t.overrides&&e.parentSub===us||n===t.parts&&e.parentSub===us)return true;let o=Me(n);if(o?.parent===t.parts&&o.parentSub===us)return true;let r=a=>a instanceof z.Map&&a.get("type")===Mm,i=a=>a instanceof z.Map&&[...a.values()].some(r);return n===t.relationships?e.content.getContent().some(i):o?.parent===t.relationships?e.content.getContent().some(r):Me(o?.parent)?.parent===t.relationships&&r(n)}var rt=class{constructor(e,n){this.doc=e;this.stopKeepingMarkers=Cs(e),this.schema=Ks(e),this.limits=Fs(n),this.splitDedup=new Co(this.schema.nodes),this.inline=new jo(this.schema.nodes,this.limits,o=>this.isTombstoned(o)||!this.parentIndex.has(o),(o,r)=>fc({parentOf:i=>this.parentIndex.get(i),childrenOf:i=>this.splitSiblings.shownChildren(i),maxDepth:this.limits.maxTreeDepth},o,r),o=>this.splitSiblings.textChanged(o)),this.adoption=new Fo(this.schema.nodes,{kindOf:o=>this.kindOf(o),isTombstoned:o=>this.isTombstoned(o),listersOf:o=>this.listings.get(o)??[]}),this.splitTextSources=new an(this.schema.nodes,this.doc,this.limits),this.stopMarks=cc(e,{inline:this.inline,loading:()=>this.bulkLoad>0,changed:o=>{for(let r of this.markListeners)r(o);}}),this.stopObserving=yc(this.schema,{onNodeEvents:o=>{this.bulkLoad>0||this.applyChildArrayEvents(o);},onAttributeEvent:o=>{this.bulkLoad>0||this.applyAttributeMapEvent(o);},onBindingEvent:o=>{this.bulkLoad>0||this.applyBindingMapEvent(o);},onRelationshipChange:()=>{this.relationshipCountCache=-1;},onPartChange:()=>{this.partCountCache=-1;}});}doc;schema;limits;parentIndex=new Map;history=new _o;contested=new Set;structureVersion=0;reparented=new Set;listings=new Map;childrenSnapshot=new Map;adoption;inline;splitSiblings=new Mo(e=>this.schema.nodes.get(e),e=>this.inline.textOf(e),e=>this.childrenSnapshot.get(e));stopMarks;stopKeepingMarkers;markListeners=new Set;attributesByNode=new Map;bindingsByNode=new Map;splitDedup;splitTextSources;bulkLoad=0;unobservedWrites=0;nodeCountCache=-1;pendingNodeAdds=0;relationshipCountCache=-1;partCountCache=-1;stopObserving;destroy(){this.stopObserving(),this.stopMarks(),this.stopKeepingMarkers();}beginBulkLoad(){this.bulkLoad+=1;}endBulkLoad(){this.bulkLoad=Math.max(0,this.bulkLoad-1),this.bulkLoad===0&&this.rebuildDerivedIndexes();}trackedTypes(){return [this.schema.meta,this.schema.nodes,this.schema.parts,this.schema.relationships,this.schema.overrides,this.schema.defaults,this.schema.binaries,this.schema.attributes,this.schema.bindings,this.doc.getMap(qr),this.doc.getMap(ei)]}undoDeleteFilter(){let e=zd(this.schema.nodes,this.schema);return n=>!Ac(this.schema,n)&&e(n)}encodeSnapshot(){return z.encodeStateAsUpdate(this.doc)}encodeUpdate(e){return z.encodeStateAsUpdate(this.doc,e)}partEntries(){return Cc(this.schema.parts)}partCount(){return this.partCountCache<0&&(this.partCountCache=this.partEntries().length),this.partCountCache}relationshipCount(){return this.relationshipCountCache<0&&(this.relationshipCountCache=this.relationships().length),this.relationshipCountCache}mainDocumentPart(){return da(this.schema.meta.get("mainDocumentPart"))}record(e){if(E(e))return null;let n=this.schema.nodes.get(e);if(!_(n))return null;if(Kt(n)){let o=n.get(Pe),r=o instanceof z.Text?o.toString():"";return {logicalId:e,kind:"textValue",value:r}}return aa(e,n,this.schema,[...this.attributesByNode.get(e)?.values()??[]],[...this.bindingsByNode.get(e)?.values()??[]])}parentOf(e){return this.parentIndex.get(e)??this.inline.owner(e)}identityMeta(e){let n=this.schema.nodes.get(e);if(!n)return null;let o=this.record(e),r=o&&W(o)?o.attributes:[];return {logicalId:e,yjsItemKey:la(n),wordFacingIds:Bs(r)}}isTombstoned(e){return Ae(this.schema.nodes.get(e))}replacedByOf(e){return qn(this.schema.nodes.get(e))}adoptedChildren(e){return this.adoption.adoptees.get(e)??[]}adoptionIndex(){return this.adoption.adoptees}hasNamespace(e){return this.schema.namespaces.get(Lt(e))===e}noteWrite(){this.unobservedWrites+=1;}hasUnobservedWrites(){return this.unobservedWrites>0}listingParents(e){return [...this.listings.get(e)??[]]}allLogicalIds(){return [...this.schema.nodes.keys()].filter(Ar)}nodeCount(){return this.nodeCountCache<0&&(this.nodeCountCache=this.schema.nodes.size),this.nodeCountCache+this.pendingNodeAdds}nodeShape(e){return E(e)?null:ia(this.schema.nodes,e)}kindOf(e){return E(e)?null:sa(this.schema.nodes,e)}noteNodeWrite(e){this.schema.nodes.has(e)||(this.pendingNodeAdds+=1);}putElement(e){this.noteNodeWrite(e.logicalId);let n=Wt(this.schema.namespaces,e.namespaceUri,this.limits.maxStringLength);this.schema.nodes.set(e.logicalId,Xs({logicalId:e.logicalId,kind:e.kind,namespaceUri:e.namespaceUri,namespaceId:n,localName:e.localName,prefix:e.prefix}));for(let o of e.attributes)as(this.schema,this.limits.maxStringLength,e.logicalId,o,o.value);for(let o of e.bindings)ls(this.schema,this.limits.maxStringLength,e.logicalId,o.prefix,o.namespaceUri);}updateElementShell(e,n){let o=this.require(e),r=Wt(this.schema.namespaces,n.namespaceUri,this.limits.maxStringLength);o.set(Vn,Rr(n.kind,r,n.localName,n.prefix??""));}putText(e,n){this.noteNodeWrite(e),this.schema.nodes.set(e,Hn(n));}spliceText(e,n,o,r){let i=this.splitTextSources.range(e),s=Eo(this.schema.nodes,this.splitTextSources,e,i,n,r),a=i?.text??this.textOf(e),l=(i?.start??0)+n;i===null&&this.splitTextSources.isPlain(e)?(r.length>0&&a.insert(l,r),o>0&&a.delete(l+r.length,o)):(o>0&&a.delete(l,o),r.length>0&&a.insert(l,r)),s?.();}setAttribute(e,n,o){if(o===null){xc(this.schema,e,n.namespaceUri,n.localName);return}as(this.schema,this.limits.maxStringLength,e,n,o);}setNamespaceBinding(e,n,o){if(o===null){Sc(this.schema,e,n);return}ls(this.schema,this.limits.maxStringLength,e,n,o);}spliceChildren(e,n,o,r){let i=this.childArray(e);o>0&&i.delete(n,o),r.length>0&&i.insert(n,[...r]);}moveNode(e,n,o){this.unlinkFromAllParents(e);let r=this.childArray(n);r.insert(Math.max(0,Math.min(o,r.length)),[e]);}tombstone(e,n){this.unlinkFromAllParents(e);let o=this.require(e);o.set(me,true),n&&o.set(ue,n);}recordRunSplit(e,n,o){this.splitDedup.record(e,n,o);}splitOriginOf(e){return In(this.schema.nodes.get(e))}splitLineageOf(e){return Et(this.schema.nodes.get(e))}replacementLoserRuns(){return this.hasUnobservedWrites()&&this.splitDedup.invalidate(),this.splitDedup.loserRuns({isPresent:e=>hc(this,e)})}splitTextRange(e){return this.splitTextSources.range(e)}splitTextPending(e){return this.splitTextSources.isPending(e)}projectedTextValue(e){return this.splitTextSources.value(e)}registerSplitText(e,n,o,r){this.splitTextSources.register(e,n,o,r);}normalizeRestoredSplitTextAnchors(){this.splitTextSources.normalizeRestoredAnchors();}concurrentSplitTextOverlays(){return this.splitTextSources.overlays()}unlistChildren(e,n){let o=this.schema.nodes.get(e);Ec(o?ie(o):null,n);}putXmlPart(e){this.partCountCache=-1,this.schema.parts.set(e.name,Gs(e.id,e.rootLogicalId,e.contentType));}deleteXmlPart(e){this.partCountCache=-1,this.schema.parts.delete(e);}putRelationship(e){if(E(e.ownerPart)||E(e.id))return;this.relationshipCountCache=-1;let n=new z.Map;n.set(e.id,qs(e)),this.schema.relationships.set(rs(e.ownerPart,e.id),n);}deleteRelationship(e,n){this.relationshipCountCache=-1,this.schema.relationships.delete(rs(e,n)),this.schema.relationships.get(e)?.delete(n);}putContentTypeOverride(e,n){this.schema.overrides.set(partNameKey(e),n);}deleteContentTypeOverride(e){this.schema.overrides.delete(partNameKey(e));}putContentTypeDefault(e,n){this.schema.defaults.set(e,n);}putBinary(e){this.schema.binaries.set(e.storageKey,Qs(e));}deleteBinary(e){this.schema.binaries.delete(e);}relationships(){return mc(this.schema.relationships)}contentTypeOverrides(){return Tc(this.schema.overrides)}contentTypeDefaults(){return Mc(this.schema.defaults)}binaries(){return Pc(this.schema.binaries)}hasNode(e){return this.schema.nodes.has(e)}showsAsChild(e){let n=this.schema.nodes.get(e);return n===void 0||Ae(n)?false:!(Kt(n)&&this.splitTextPending(e))}observeDirty(e){let n=pc(this.schema,e),o=r=>e({logicalIds:r,membershipChanged:false,packageChanged:false});return this.markListeners.add(o),()=>{n(),this.markListeners.delete(o);}}rebuildDerivedIndexes(){this.unobservedWrites=0,this.nodeCountCache=-1,this.pendingNodeAdds=0,this.relationshipCountCache=-1,this.partCountCache=-1,this.parentIndex=new Map,this.listings=new Map,this.childrenSnapshot=new Map,this.adoption.reset(),this.attributesByNode=new Map,this.bindingsByNode=new Map,this.splitDedup.reset(),this.splitTextSources.reset(),this.schema.nodes.forEach((n,o)=>{if(!Ar(o))return;let r=ie(n);if(!r)return;let i=r.toArray();this.childrenSnapshot.set(o,i);for(let s of i)ds(this.listingIndex(),s,o);}),this.schema.nodes.forEach((n,o)=>{Ae(n)&&this.adoption.sync(G(o)),this.splitDedup.indexExisting(G(o));}),Rc(this.schema,this.attributesByNode,this.bindingsByNode),ss(this.placementContext(),null),this.contested=new Set;for(let[n,o]of this.listings)o.size>1&&this.contested.add(n);let e=new Set;for(let n of this.listings.keys())this.parentIndex.has(n)||e.add(n);e.size>0&&this.resolveParents(e),this.inline.rebuild();}assertNoParentFields(){ca(this.schema.nodes);}applyChildArrayEvents(e){this.unobservedWrites=0,this.pendingNodeAdds=0;let n=new Set,o=false;for(let r of e){if(!(r.target instanceof z.Text)&&(r.path.length===0||r.target instanceof z.Array||r.target instanceof z.Map&&[...r.changes.keys.keys()].some(i=>["deleted","replacedBy","splitFrom","splitLineage","children"].includes(String(i))))&&this.splitDedup.invalidate(),r.path.length>0&&this.splitTextSources.noteChanged(G(r.path[0])),r.target instanceof z.Text&&r.path[1]===ae){this.inline.paragraphChanged(G(r.path[0]));continue}if(r.target instanceof z.Map&&r.path.length===1&&(r.changes.keys.has(ae)||r.changes.keys.has(me))&&this.inline.paragraphChanged(G(r.path[0])),r.path.length===0&&r.target instanceof z.Map){o=true;for(let[i,s]of r.changes.keys)if(this.nodeCountCache>=0&&s.action!=="update"&&(this.nodeCountCache+=s.action==="add"?1:-1),!E(String(i))){if(s.action==="delete"){this.inline.paragraphChanged(G(i));continue}this.splitDedup.indexExisting(G(i)),this.splitTextSources.noteChanged(G(i));for(let a of this.syncChildListings(G(i)))n.add(a);this.inline.paragraphChanged(G(i)),this.inline.recordArrived(G(i)),this.isTombstoned(G(i))&&this.adoption.sync(G(i)),this.adoption.recomputeListerSurvivors(G(i));}continue}if(r.target instanceof z.Map&&r.path.length===1){let i=G(r.path[0]),s=r.changes.keys;if(s.has(St)&&this.history.noteMarkChanged(i),(s.has("splitFrom")||s.has("splitLineage"))&&this.splitDedup.indexExisting(i),s.has(ct))for(let a of this.listings.get(i)??[])this.splitSiblings.forget(a);}if(r.target instanceof z.Array&&r.path.length>0){o=true;let i=G(r.path[0]);for(let s of this.syncChildListings(i,true))n.add(s);this.isTombstoned(i)&&this.adoption.sync(i);continue}if(r.target instanceof z.Map&&r.path.length===1&&(r.changes.keys.has(me)||r.changes.keys.has(ue))){o=true;let i=G(r.path[0]);this.adoption.sync(i),this.adoption.recomputeListerSurvivors(i);for(let s of this.childrenSnapshot.get(i)??[])n.add(s);}}if(o)for(let r of this.contested)n.add(r);n.size>0&&this.resolveParents(n),o&&(this.structureVersion+=1,this.inline.orderChanged());}takeUnlisted(){return this.history.takeUnlisted(e=>this.parentIndex.has(e))}takeReparented(){let e=[...this.reparented];return this.reparented.clear(),e}applyAttributeMapEvent(e){this.unobservedWrites=0,vc(this.schema,this.attributesByNode,e);}applyBindingMapEvent(e){this.unobservedWrites=0,Lc(this.schema,this.bindingsByNode,e);}syncChildListings(e,n=false){n&&this.splitSiblings.forget(e);let o=this.schema.nodes.get(e),r=o?ie(o)?.toArray()??[]:[];return Oc(this.listingIndex(),e,r)}listingIndex(){return {listings:this.listings,childrenSnapshot:this.childrenSnapshot}}resolveParents(e){let n=new Map;for(let o of e)n.set(o,this.parentIndex.get(o));this.placeParents(e);for(let[o,r]of n){(this.listings.get(o)?.size??0)>1?this.contested.add(o):this.contested.delete(o);let i=this.parentIndex.get(o);i!==r&&(i===void 0!=(r===void 0)&&(this.inline.listingChanged(o),i===void 0&&this.history.noteUnlisted(o)),r!==void 0&&this.reparented.add(r),i!==void 0&&this.reparented.add(i));}}placeParents(e){bc(this.placementContext(),e);}placementContext(){return {nodes:this.schema.nodes,parentIndex:this.parentIndex,listings:this.listings,childrenSnapshot:this.childrenSnapshot,partRoots:this.partEntries().map(e=>e.rootLogicalId)}}unlinkFromAllParents(e){let n=[...this.listings.get(e)??[]];if(n.length===0){this.schema.nodes.forEach(o=>{let r=ie(o);r&&this.removeFromArray(r,e);});return}for(let o of n){let r=this.schema.nodes.get(o),i=r?ie(r):null;i&&this.removeFromArray(i,e);}}removeFromArray(e,n){for(let o=e.length-1;o>=0;o-=1)e.get(o)===n&&e.delete(o,1);}textOf(e){let n=this.require(e).get(Pe);if(!(n instanceof z.Text))throw new Error(`no text at ${e}`);return n}childArray(e){let n=this.require(e).get(xt);if(!(n instanceof z.Array))throw new Error(`no children at ${e}`);return n}require(e){let n=this.schema.nodes.get(e);if(!n)throw new Error(`registry node ${e} missing`);return n}};var zo=class{blobs=new Map;get(e){let n=this.blobs.get(e);return n?n.slice():null}put(e,n){this.blobs.set(e,n.slice());}};async function Pm(t){let e=await globalThis.crypto.subtle.digest("SHA-256",t.slice().buffer);return `sha256:${[...new Uint8Array(e)].map(n=>n.toString(16).padStart(2,"0")).join("")}`}function Nc(t){let e=t.binaryPart;return typeof e=="function"?e:null}function Yc(t,e){let n=[];for(let r of t)r.kind==="putBinary"&&n.push(r.descriptor);if(n.length===0)return null;if(!e)return {ok:false,failure:{code:"blob-read",detail:"binary-part-reader"}};let o=[];for(let r of n){let i=e(r.storageKey);if(!i)return {ok:false,failure:{code:"missing-local-blob",detail:r.storageKey}};o.push({digest:r.digest,bytes:i});}return {ok:true,payloads:o}}function _c(t,e){for(let n of e)t.put(n.digest,n.bytes);}function Dm(t){return t.attributes.map(e=>({namespaceUri:e.namespaceUri,localName:e.localName,prefix:e.prefix,value:e.value}))}function Nm(t){return t.namespaceBindings.map(e=>({prefix:e.prefix,namespaceUri:e.namespaceUri}))}function Wo(t,e,n,o,r){if(o>t.limits.maxTreeDepth)return "tree-too-deep";if(E(e.id))return "prototype-key";if(r.nodes+=1,r.nodes>t.limits.maxNodes)return "too-many-nodes";if(e.kind==="textValue"){if(e.value.length>t.limits.maxTextLength)return "text-too-long";t.putText(U(e),e.value);}else {if(e.attributes.length>t.limits.maxAttributes)return "too-many-attributes";if(e.children.length>t.limits.maxChildren)return "too-many-children";if(Re(e.namespaceUri,t.limits.maxStringLength))return "invalid-string";for(let i of e.attributes){if(E(i.localName))return "prototype-key";if(Re(i.namespaceUri,t.limits.maxStringLength))return "invalid-string"}for(let i of e.namespaceBindings){if(E(i.prefix))return "prototype-key";if(Re(i.namespaceUri,t.limits.maxStringLength))return "invalid-string"}if(t.putElement({logicalId:U(e),kind:e.kind,namespaceUri:e.namespaceUri,localName:e.localName,prefix:e.prefix,attributes:Dm(e),bindings:Nm(e)}),e.kind==="paragraph"){let i=Ym(t,e,o,r);if(i)return i}else for(let i of e.children){let s=Wo(t,i,U(e),o+1,r);if(s)return s}}return n&&t.childArray(n).push([U(e)]),null}function Ym(t,e,n,o){let r=xn(e);for(let a of r.shell.children){let l=Wo(t,a,U(e),n+1,o);if(l)return l}let i=0;for(let a of r.items){if(i+=1,a.kind!=="embed")continue;let l=Wo(t,a.node,null,n+1,o);if(l)return l}if(i>t.limits.maxTextLength)return "text-too-long";let s=t.schema.nodes.get(e.id);if(!s)return null;try{ho(s,Pa(r.items,e.id,t.limits));}catch(a){if(a instanceof Be)return a.code;throw a}return null}async function _m(t){let e=[],n=[];for(let[o,r]of t.partBytes){if(t.parts.has(o))continue;let s=t.contentTypes.overrides.get(o)??"application/octet-stream",a=Ie(o);if(a)return {ok:false,code:a};if(r.byteLength>bt.maxBlobBytes)return {ok:false,code:"blob-too-large"};let l=await Pm(r);n.push({digest:l,bytes:r}),e.push({digest:l,size:r.byteLength,mediaType:s,storageKey:o});}return {ok:true,descriptors:e,payloads:n}}async function $o(t,e,n=new zo){if(e.parts.size>t.limits.maxParts)return {ok:false,code:"too-many-parts"};let o=await _m(e);if(!o.ok)return o;let r=null;t.beginBulkLoad();try{t.doc.transact(()=>{for(let a of o.payloads)n.put(a.digest,a.bytes);let i={nodes:0};for(let[a,l]of e.parts){let d=Ie(a);if(d){r=d;return}if(Re(l.contentType,t.limits.maxMediaTypeLength)){r="invalid-string";return}let c=Wo(t,l.root,null,0,i);if(c){r=c;return}t.putXmlPart({name:a,id:l.id,rootLogicalId:U(l.root),contentType:l.contentType});}let s=0;for(let a of e.relationships.values())for(let l of a){if(s+=1,s>t.limits.maxRelationships){r="too-many-relationships";return}if(l.ownerPart!=="/"){let d=Ie(l.ownerPart);if(d){r=d;return}}if(E(l.id)){r="prototype-key";return}t.putRelationship({ownerPart:l.ownerPart,id:l.id,type:l.type,rawTarget:l.rawTarget,targetMode:l.targetMode,order:l.order});}for(let[a,l]of e.contentTypes.defaults){if(E(a)){r="prototype-key";return}t.putContentTypeDefault(a,l);}for(let[a,l]of e.contentTypes.overrides){let d=Ie(a);if(d){r=d;return}t.putContentTypeOverride(a,l);}for(let a of o.descriptors)t.putBinary(a);Zs(t.schema.meta),t.schema.meta.set("mainDocumentPart",e.mainDocumentPart);},$s);}finally{t.endBulkLoad();}return r?{ok:false,code:r}:{ok:true}}function Fe(t,e){return t.attributes.find(n=>n.localName===e)?.value}function ps(t){return t.kind==="textValue"?t.id:Fe(t,"id")??t.id}function Bn(t,e){if(t.length===e.length&&t.every((s,a)=>s===e[a]))return t;let n=0,o=Math.min(t.length,e.length);for(;n<o&&t[n]===e[n];)n+=1;let r=t.length,i=e.length;for(;r>n&&i>n&&t[r-1]===e[i-1];)r-=1,i-=1;return Object.freeze([...t.slice(0,n),...e.slice(n,i),...t.slice(r)])}function Fc(t,e){let n=t.root;if(n.children.length===e.length&&n.children.every((r,i)=>r===e[i]))return t;let o=Object.freeze(qe(n,Bn(n.children,e)));return Object.freeze({...t,root:o})}function Bm(t){if(t.namespaceUri===XML_NAMESPACE_URI&&t.localName==="space"){let e=t.value==="preserve"?"preserve":"default";return Object.freeze({kind:"xmlSpace",namespaceUri:XML_NAMESPACE_URI,localName:"space",prefix:"xml",value:e})}return t.namespaceUri===WML_NAMESPACE_URI&&t.localName==="val"?Object.freeze({kind:"wmlVal",namespaceUri:WML_NAMESPACE_URI,localName:"val",prefix:t.prefix,value:t.value}):Object.freeze({kind:"genericExtension",namespaceUri:t.namespaceUri,localName:t.localName,prefix:t.prefix,value:t.value})}function Wc(t){}function Kc(t,e){return Object.freeze({id:t,kind:"textValue",value:e})}function $m(t,e){return t.namespaceBindings.length!==e.bindings.length?false:t.namespaceBindings.every((n,o)=>{let r=e.bindings[o];return n.prefix===r.prefix&&n.namespaceUri===r.namespaceUri})}function Km(t,e){return t.attributes.length!==e.attributes.length?false:t.attributes.every((n,o)=>{let r=e.attributes[o];return n.namespaceUri===r.namespaceUri&&n.localName===r.localName&&n.value===r.value&&n.prefix===(r.prefix?.length?r.prefix:void 0)})}function Ko(t,e,n){let o=n&&n.kind!=="textValue"?n:void 0;return Object.freeze(De({id:t.logicalId,kind:t.kind,namespaceUri:t.namespaceUri,localName:t.localName,...t.prefix===void 0?{}:{prefix:t.prefix},namespaceBindings:o&&$m(o,t)?o.namespaceBindings:Object.freeze(t.bindings.map(r=>Object.freeze({...r}))),attributes:o&&Km(o,t)?o.attributes:Object.freeze(t.attributes.map(Bm)),children:e}))}function Vc(t,e){if(t.attributes.length!==e.attributes.length)return false;let n=new Map(e.attributes.map(o=>[`${o.namespaceUri}
|
|
14
14
|
${o.localName}`,o.value]));for(let o of t.attributes)if(n.get(`${o.namespaceUri}
|
|
15
|
-
${o.localName}`)!==o.value)return false;return t.localName===e.localName&&t.kind===e.kind}function ps(t,e){let n=e.size;e.add(U(t));let o=e.size!==n;if(t.kind==="textValue")return o;for(let r of t.children)ps(r,e)||(o=false);return o}function Kc(t,e,n,o){for(let r of e){let i=n.get(r);for(let s=0;i!==void 0&&s<o;s++)t.add(i),i=n.get(i);}}function Vc(t,e){let n=new Set(e),o=[...e],r=i=>{n.has(i)||(n.add(i),o.push(i));};for(;o.length>0;){let i=o.pop(),s=t.isTombstoned(i)?t.replacedByOf(i):null;s!==null&&r(s);let a=t.listingParents(i),l=t.parentOf(i);for(let d of l===null?a:[l,...a]){r(d);let c=t.isTombstoned(d)?t.replacedByOf(d):null;c!==null&&r(c);}}return n}var Vo="http://schemas.openxmlformats.org/package/2006/relationships",Fm="application/vnd.openxmlformats-package.relationships+xml",Jc=/^(.*)\/_rels\/([^/]*)\.rels$/;function Jo(t){return Jc.test(t)}function Hc(t){let e=Jc.exec(t);return e?e[2]===""?"/":`${e[1]}/${e[2]}`:null}function Ko(t,e){return Object.freeze({kind:"genericExtension",namespaceUri:"",localName:t,value:e})}function jm(t,e){let n=[Ko("Id",e.id),Ko("Type",e.type),Ko("Target",e.rawTarget)];return e.targetMode==="External"&&n.push(Ko("TargetMode","External")),Object.freeze(De({id:t,kind:"generic",namespaceUri:Vo,localName:"Relationship",namespaceBindings:Object.freeze([]),attributes:Object.freeze(n),children:Object.freeze([])}))}function Xc(t,e){if(t.kind==="textValue"||t.namespaceUri!==Vo||t.localName!=="Relationship"||Fe(t,"Id")!==e.id||Fe(t,"Type")!==e.type||Fe(t,"Target")!==e.rawTarget)return false;let n=Fe(t,"TargetMode");return e.targetMode==="External"?n==="External":n===void 0}function Gc(t,e){return t.children.length!==e.length?false:t.children.every((n,o)=>Xc(n,e[o]))}function qc(t,e){if(t.id!==e.id||t.kind!==e.kind||t.namespaceUri!==e.namespaceUri||t.localName!==e.localName||t.prefix!==e.prefix||t.attributes.length!==e.attributes.length)return false;for(let n=0;n<t.attributes.length;n+=1){let o=t.attributes[n],r=e.attributes[n];if(o.namespaceUri!==r.namespaceUri||o.localName!==r.localName||o.value!==r.value||o.prefix!==r.prefix)return false}return t.namespaceBindings.length!==e.namespaceBindings.length?false:t.namespaceBindings.every((n,o)=>{let r=e.namespaceBindings[o];return n.prefix===r.prefix&&n.namespaceUri===r.namespaceUri})}function Qc(t,e,n){let o=[];for(let r of e){if(O(r.id))continue;let i=t.find(a=>a.kind!=="textValue"&&Fe(a,"Id")===r.id);if(i&&Xc(i,r)){o.push(i);continue}let s=i&&i.kind!=="textValue"?U(i):`${n}#rel-${r.id}`;O(s)||o.push(jm(s,r));}return o}function zm(t){return Object.freeze(De({id:`${t}#root`,kind:"generic",namespaceUri:Vo,localName:"Relationships",namespaceBindings:Object.freeze([Object.freeze({prefix:"",namespaceUri:Vo})]),attributes:Object.freeze([]),children:Object.freeze([])}))}function Zc(t){return Object.freeze({id:t,name:t,contentType:Fm,root:zm(t)})}function eu(t){let e=new Map;for(let n of t){if(O(n.id)||n.ownerPart!=="/"&&Ie(n.ownerPart))continue;let o=e.get(n.ownerPart)??[];o.push(n),e.set(n.ownerPart,o);}return e}var ru=/^\/customXml\/item(\d+)\.xml$/i,Vm=/^\/customXml\/itemProps(\d+)\.xml$/i;function Fn(t){return ru.test(t)}function gs(t){return Vm.test(t)}function Jm(t){let e=ru.exec(t);if(!e)return null;let n=Number(e[1]);return Number.isSafeInteger(n)&&n>0?n:null}function tu(t){return {item:`/customXml/item${String(t)}.xml`,props:`/customXml/itemProps${String(t)}.xml`}}function Hm(t,e,n){let o=t.attributes.find(r=>r.localName===e&&r.namespaceUri===n);return o&&o.value.length>0?o.value:null}function nu(t,e){let n=t.record(e);return !n||!$(n)?e:n.attributes.find(r=>r.localName==="id"&&r.value.length>0)?.value??e}function Xm(t,e){let n=t.record(e);if(!n||!$(n))return null;for(let o of n.childIds){let r=t.record(o);if(!(!r||!$(r)||r.localName!=="schemaRefs")&&r.namespaceUri===DATASTORE_NAMESPACE_URI)for(let i of r.childIds){let s=t.record(i);if(!s||!$(s)||s.localName!=="schemaRef")continue;let a=Hm(s,"uri",DATASTORE_NAMESPACE_URI);if(a)return a}}return null}function Gm(t,e){return e.childIds.some(n=>{let o=t.record(n);return !!o&&$(o)&&o.localName==="node"&&o.namespaceUri===e.namespaceUri})}function qm(t,e){return e.localName==="node"||e.namespaceUri===WML_NAMESPACE_URI||e.namespaceUri===DATASTORE_NAMESPACE_URI||e.namespaceUri.length===0||t.parentOf(e.logicalId)!==null?false:Gm(t,e)}function Qm(t,e){return e.localName!=="datastoreItem"||e.namespaceUri!==DATASTORE_NAMESPACE_URI?false:t.parentOf(e.logicalId)===null}function iu(t,e){if(!t.hasNamespace(DATASTORE_NAMESPACE_URI))return [];let n=new Map,o=new Map;for(let[f,p]of e){let h=t.record(U(p.root));!h||!$(h)||(Fn(f)&&n.set(h.logicalId,h),gs(f)&&o.set(h.logicalId,h));}for(let f of t.allLogicalIds()){if(t.isTombstoned(f)||n.has(f)||o.has(f))continue;let p=t.record(f);!p||!$(p)||(qm(t,p)?n.set(f,p):Qm(t,p)&&o.set(f,p));}if(n.size===0)return [];let r=new Map;for(let f of n.values()){let p=r.get(f.namespaceUri)??[];p.push(f),r.set(f.namespaceUri,p);}let i=new Map;for(let f of o.values()){let p=Xm(t,f.logicalId);if(!p)continue;let h=i.get(p)??[];h.push(f),i.set(p,h);}let s=[];for(let[f,p]of r){let h=i.get(f);if(!h||h.length===0)continue;p.sort((b,x)=>b.logicalId.localeCompare(x.logicalId)),h.sort((b,x)=>b.logicalId.localeCompare(x.logicalId));let g=p[0],m=h[0],w=[],I=new Set;for(let b of p)for(let x of b.childIds){if(I.has(x))continue;let L=t.record(x);!L||!$(L)||L.localName!=="node"||L.namespaceUri!==f||(I.add(x),w.push(x));}for(let b of t.allLogicalIds()){if(I.has(b)||t.isTombstoned(b))continue;let x=t.record(b);!x||!$(x)||x.localName!=="node"||x.namespaceUri!==f||(I.add(b),w.push(b));}w.sort((b,x)=>nu(t,b).localeCompare(nu(t,x))),s.push({data:g,props:m,nodeIds:w});}s.sort((f,p)=>f.data.logicalId.localeCompare(p.data.logicalId));let a=new Set,l=[],d=new Set,c=new Set;for(let[f,p]of e){let h=Jm(f);if(h===null)continue;let g=s.find(I=>I.data.logicalId===p.root.id&&!d.has(I.data.logicalId));if(!g)continue;let m=tu(h).props,w=e.get(m);w&&w.root.id!==g.props.logicalId||(a.add(h),d.add(g.data.logicalId),c.add(g.props.logicalId),l.push({dataRootId:g.data.logicalId,propsRootId:g.props.logicalId,namespaceUri:g.data.namespaceUri,itemName:f,propsName:m,nodeIds:g.nodeIds}));}let u=1;for(let f of s){if(d.has(f.data.logicalId))continue;for(;a.has(u);)u+=1;a.add(u);let p=tu(u);l.push({dataRootId:f.data.logicalId,propsRootId:f.props.logicalId,namespaceUri:f.data.namespaceUri,itemName:p.item,propsName:p.props,nodeIds:f.nodeIds}),u+=1;}return l.sort((f,p)=>f.itemName.localeCompare(p.itemName)),l}function Zm(t){return t.type===CUSTOM_XML_REL||t.type===CUSTOM_XML_PROPS_REL?true:Fn(t.ownerPart)}function ey(t){let e=/^rId(\d+)$/.exec(t);if(!e)return 0;let n=Number(e[1]);return Number.isSafeInteger(n)?n:0}function ty(t,e){let n=t.split("/").slice(1,-1),o=e.split("/").slice(1),r=0;for(;r<n.length&&r<o.length-1&&n[r]===o[r];)r+=1;return `${"../".repeat(n.length-r)}${o.slice(r).join("/")}`}function su(t,e){if(e.length===0)return [];let n=t.mainDocumentPart();if(!n)return [];let o=t.relationships(),r=o.filter(a=>a.ownerPart===n&&a.type===CUSTOM_XML_REL).sort((a,l)=>a.id.localeCompare(l.id)),i=0;for(let a of o)i=Math.max(i,ey(a.id));let s=[];for(let a=0;a<e.length;a+=1){let l=e[a],d=r[a],c=d?.id??`rId${String(i+=1)}`;s.push({ownerPart:n,id:c,type:CUSTOM_XML_REL,rawTarget:ty(n,l.itemName),targetMode:"Internal",order:d?.order??a}),s.push({ownerPart:l.itemName,id:"rId1",type:CUSTOM_XML_PROPS_REL,rawTarget:l.propsName.slice(l.propsName.lastIndexOf("/")+1),targetMode:"Internal",order:0});}return s}function au(t,e){return e.length===0?[...t]:[...t.filter(n=>!Zm(n)),...e]}function lu(t){let e=new Map;for(let n of t)e.set(partNameKey(n.propsName),CUSTOM_XML_PROPS_TYPE);return e}function ms(t,e){if(e.length===0)return false;let n=[...t.keys()].filter(Fn).sort(),o=e.map(r=>r.itemName).sort();if(n.length!==o.length||n.some((r,i)=>r!==o[i]))return true;for(let r of e){let i=t.get(r.itemName),s=t.get(r.propsName);if(!i||i.root.id!==r.dataRootId||!s||s.root.id!==r.propsRootId)return true}return false}function du(t,e){if(ms(t,e))return true;for(let n of e){let o=t.get(n.itemName);if(!o)return true;let r=new Set(o.root.children.map(a=>a.id));if(n.nodeIds.some(a=>!r.has(a)))return true;let i=[];for(let a of o.root.children)a.kind!=="textValue"&&i.push(a.attributes.find(l=>l.localName==="id")?.value??a.id);let s=[...i].sort((a,l)=>a.localeCompare(l));if(i.some((a,l)=>a!==s[l]))return true}return false}var ny="http://schemas.microsoft.com/office/word/2012/wordml";function Ho(t){let e=Number(t);return t===void 0||t.length===0||!Number.isSafeInteger(e)?`2${t??""}`:`${e<0?"0":"1"}${String(Math.abs(e)).padStart(12,"0")}`}function cu(t){return e=>e.localName===t&&e.namespaceUri===WML_NAMESPACE_URI}function oy(t){return t.localName==="abstractNum"?`0${Ho(Fe(t,"abstractNumId"))}`:`1${Ho(Fe(t,"numId"))}`}function ry(t){return t.namespaceUri!==WML_NAMESPACE_URI?false:t.localName==="abstractNum"||t.localName==="num"}function ys(t){return t.localName==="comments"?{isMember:e=>e.kind==="comment",sortKey:e=>e.id,adoptedAfterListed:true}:t.localName==="commentsEx"?{isMember:e=>e.localName==="commentEx"&&e.namespaceUri===ny,sortKey:e=>e.id,adoptedAfterListed:true}:t.localName==="footnotes"&&t.namespaceUri===WML_NAMESPACE_URI?{isMember:cu("footnote"),sortKey:e=>Ho(Fe(e,"id"))}:t.localName==="endnotes"&&t.namespaceUri===WML_NAMESPACE_URI?{isMember:cu("endnote"),sortKey:e=>Ho(Fe(e,"id"))}:t.localName==="numbering"&&t.namespaceUri===WML_NAMESPACE_URI?{isMember:ry,sortKey:oy}:null}function uu(t,e){for(let n of t)if(n.root.id===e)return ys(n.root)?n.root.children.map(U):null;return null}function fu(t,e){let n=null;for(let o of t.listingParents(e)){let r=t.record(o);if(!(!r||!$(r)||!r.childIds.includes(e))&&(t.isTombstoned(o)||t.listingParents(o).length>0||(n??=new Set(t.partEntries().map(i=>i.rootLogicalId)),n.has(o))))return true}return false}function pu(t,e,n){let o=t.record(n),r=!!o&&(kt(o)?o.value.length>0:o.childIds.length>0||o.attributes.length>0);e(r?"orphan-with-content":"orphan",n);}function hu(t,e,n,o,r,i){if(!r){for(let l of n)t.isTombstoned(l)||o.has(l)||(pu(t,e,l),i.add(l));return}let s=new Set(t.partEntries().map(l=>l.rootLogicalId)),a=new Set;for(let l of n)a.has(l)||(a.add(l),iy(t,e,l,o,s)&&i.add(l));}function iy(t,e,n,o,r){let i=false,s=new Set,a=[{id:n,underTombstone:false}];for(;a.length>0;){let{id:l,underTombstone:d}=a.pop();if(!(s.has(l)||s.size>=t.limits.maxTreeDepth)){if(s.add(l),t.isTombstoned(l)){let c=t.record(l);if(c&&$(c))for(let u of c.childIds)a.push({id:u,underTombstone:true});continue}r.has(l)||(d?o.has(l):fu(t,l))||(pu(t,e,l),i=true);}}return i}function gu(t,e,n,o,r,i,s,a,l){let d=0;for(let c of a){if(i.has(c)||o.has(c)||t.isTombstoned(c)||Gn(t.schema.nodes.get(c))||s&&fu(t,c))continue;let u=t.record(c);if(!u||!$(u)||!r(u))continue;let f=e(c);!f||f.kind==="textValue"||(n.push(f),o.add(c),l.add(c),d+=1);}return d}var pt="application/vnd.openxmlformats-officedocument.wordprocessingml",dy=new Map(Object.entries({comments:{root:"comments",contentType:`${pt}.comments+xml`},commentsExtended:{root:"commentsEx",contentType:`${pt}.commentsExtended+xml`},commentsIds:{root:"commentsIds",contentType:`${pt}.commentsIds+xml`},commentsExtensible:{root:"commentsExtensible",contentType:`${pt}.commentsExtensible+xml`},people:{root:"people",contentType:`${pt}.people+xml`},footnotes:{root:"footnotes",contentType:`${pt}.footnotes+xml`},endnotes:{root:"endnotes",contentType:`${pt}.endnotes+xml`},numbering:{root:"numbering",contentType:`${pt}.numbering+xml`}}));function cy(t){return Ie(t)===null&&!Jo(t)&&t.toLowerCase()!=="/[content_types].xml"&&t.toLowerCase().endsWith(".xml")}function mu(t,e,n){let o=new Set(e.map(d=>d.name)),r=[];for(let d of n){if(d.targetMode==="External"||!o.has(d.ownerPart))continue;let c=dy.get(d.type.slice(d.type.lastIndexOf("/")+1));if(!c)continue;let u=resolveInternalTarget(d.ownerPart,d.rawTarget);!u.ok||o.has(u.partName)||!cy(u.partName)||(o.add(u.partName),r.push({name:u.partName,...c}));}if(r.length===0)return [];let i=new Set(e.map(d=>d.rootLogicalId)),s=new Set(r.map(d=>d.root)),a=[];for(let d of t.allLogicalIds()){if(i.has(d)||t.isTombstoned(d)||t.parentOf(d)!==null)continue;let c=t.record(d);!c||!$(c)||!s.has(c.localName)||c.bindings.some(u=>u.prefix===(c.prefix??""))&&a.push({id:d,root:c.localName,empty:c.childIds.length===0});}let l=[];for(let d of r){let c=null;for(let{id:u,root:f,empty:p}of a)f!==d.root||i.has(u)||(c===null||c.empty&&!p||c.empty===p&&u<c.id)&&(c={id:u,empty:p});c!==null&&(i.add(c.id),l.push({name:d.name,id:d.name,rootLogicalId:c.id,contentType:d.contentType}));}return l}function yu(t,e,n){for(let[o,r]of t){let i=resolveContentType(e,o);i.ok&&(i.source==="override"||i.contentType===r.contentType)||n.set(partNameKey(o),r.contentType);}}var Xo=class{constructor(e){this.registry=e;}registry;decoded=null;merged=null;grouped=null;assembly=null;defaults=null;overrides=null;partBytes=null;blobBytes=new Map;invalidate(){this.decoded=null,this.merged=null,this.grouped=null,this.assembly=null,this.defaults=null,this.overrides=null,this.partBytes=null;}projected(e){return this.decoded||(this.decoded=this.registry.relationships(),this.merged=null),(!this.merged||this.merged.custom!==e)&&(this.merged={custom:e,records:e.length===0?this.decoded:au(this.decoded,e)}),this.merged.records}groupedByOwner(e){let n=this.projected(e);return (!this.grouped||this.grouped.records!==n)&&(this.grouped={records:n,map:eu(n)}),this.grouped.map}relationshipAssembly(e){let n=this.projected(e);return (!this.assembly||this.assembly.records!==n)&&(this.assembly={records:n,value:py(n)}),this.assembly.value}contentTypeDefaults(){return this.defaults??=this.registry.contentTypeDefaults()}contentTypeOverrides(){return this.overrides??=this.registry.contentTypeOverrides()}resolvePartBytes(e){if(this.partBytes)return this.partBytes;let n=new Map,o=new Set;for(let r of this.registry.binaries()){o.add(r.storageKey);let i=this.blobBytes.get(r.storageKey);if(i&&i.digest===r.digest){n.set(r.storageKey,i.bytes);continue}let s=e.get(r.digest);if(!s)return null;jc(s.length),this.blobBytes.set(r.storageKey,{digest:r.digest,bytes:s}),n.set(r.storageKey,s);}for(let r of [...this.blobBytes.keys()])o.has(r)||this.blobBytes.delete(r);return this.partBytes=n,n}};function py(t){let e=buildRelationshipSet(t);if(!e.ok)return null;let n=[];for(let o of t){let r=resolveRelationship(o);r.mode==="External"&&n.push({ownerPart:o.ownerPart,id:o.id,type:o.type,rawTarget:o.rawTarget,sinkSafe:r.sinkSafe.ok});}return {byOwner:e.byOwner,externalTargets:Object.freeze(n)}}var Go=class{textOverlays=new Map;losers=new Set;awaiting=new Set;update(e){let n=[],o=e.replacementLoserRuns(),r=s=>{n.push(s);let a=e.parentOf(s);a!==null&&n.push(a);};for(let s of o)this.losers.has(s)||r(s);for(let s of this.losers)o.has(s)||r(s);this.losers=o;let i=e.concurrentSplitTextOverlays();return this.textOverlays=i.values,this.awaiting=i.awaiting,n.push(...i.changedIds),n}textValue(e,n){return this.textOverlays.get(e)??n}};function bu(t,e){let n=t.children;for(let i of n){let s=U(i);if(e.placed.has(s)||!e.isCached(i)||e.dirty.has(s)&&!e.canRebuild(s))return null}let o=null,r=[];for(let i=0;i<n.length;i+=1){let s=n[i],a=U(s);if(!e.dirty.has(a)){e.placed.add(a),o?.push(s);continue}let l=e.rebuild(a);if(l===s){o?.push(s);continue}o??=n.slice(0,i),l?o.push(l):r.push(a);}return {children:o?Object.freeze(o):n,dropped:r}}var qo=class{nodes=new Map;heights=new Map;complete=new Set;get(e){return this.nodes.get(e)}holds(e){return this.nodes.get(U(e))===e}remember(e,n){this.nodes.set(e,n),this.heights.delete(e),this.complete.delete(e);}markComplete(e,n){n?this.complete.add(e):this.complete.delete(e);}isComplete(e){return this.complete.has(e)}forget(e){this.nodes.delete(e),this.heights.delete(e),this.complete.delete(e);}evictSubtree(e,n,o){let r=this.nodes.get(e);if(this.forget(e),o(e),!(!r||r.kind==="textValue"))for(let i of r.children){let s=U(i);n.has(s)||this.evictSubtree(s,n,o);}}heightOf(e){let n=this.heights.get(U(e));if(n!==void 0)return n;let o=1;if(e.kind!=="textValue")for(let r of e.children)o=Math.max(o,this.heightOf(r)+1);return this.heights.set(U(e),o),o}setHeight(e,n){this.heights.set(e,n);}ids(){return [...this.nodes.keys()]}};function Iu(t){let e=new Set,n=[];for(let o of t){let r=`${o.code}${o.logicalId??""}`;e.has(r)||(e.add(r),n.push(o));}return n}var hy=4096,Qo=class{constructor(e){this.registry=e;}registry;contested=false;matchesResolution=true;encountered=new Set;lastResolution=new Map;embedsMet=new Set;embedWinners=new Map;embedsDecidedAt=-1;reset(){this.contested=false,this.encountered.clear(),this.matchesResolution=true;}note(e,n,o,r){let i=this.registry,s=i.listingParents(e),a=s.length<=1?s:s.filter(l=>i.isTombstoned(l)?i.replacedByOf(l)!==null:r.has(l)||i.listingParents(l).length>0);a.length<=1||(this.contested=true,this.encountered.add(e),a.some(l=>i.isTombstoned(l)&&i.replacedByOf(l)!==null)?this.matchesResolution=false:!o.has(e)&&i.parentOf(e)!==n&&(this.matchesResolution=false));}noteEmbed(e,n,o,r){let i=o.get(e);return i===void 0||i===n||r.has(i)?true:this.embedWinners.get(e)===i&&this.embedsDecidedAt===this.registry.structureVersion?false:(this.contested=true,this.matchesResolution=false,this.embedsMet.add(e),true)}recordEmbeds(e){this.embedsDecidedAt!==this.registry.structureVersion&&this.embedWinners.clear(),this.embedsDecidedAt=this.registry.structureVersion;for(let n of this.embedsMet){let o=e.get(n);o===void 0?this.embedWinners.delete(n):this.embedWinners.set(n,o);}this.embedsMet.clear(),this.embedWinners.size>hy&&this.embedWinners.clear();}decided(){if(!this.matchesResolution)return false;for(let e of this.encountered){let n=this.lastResolution.get(e);if(n===void 0||n!==this.registry.parentOf(e))return false}return true}record(e){let n=new Map;for(let o of this.encountered)n.set(o,this.registry.parentOf(o));for(let o of e)n.set(o,this.registry.parentOf(o));this.lastResolution=n;}};var Zo=class{lastAdoption=new Map;changes(e){let n=[],o=new Map,r=(i,s)=>{let a=new Set(s);for(let l of i)if(!a.has(l))for(let d of e.listingParents(l))e.isTombstoned(d)||n.push(d);};for(let[i,s]of e.adoptionIndex()){let a=e.isTombstoned(i)?[]:[...s];o.set(i,a);let l=this.lastAdoption.get(i);(l===void 0||!Qn(l,a))&&(n.push(i),l&&r(l,a));}for(let[i,s]of this.lastAdoption)o.has(i)||(n.push(i),r(s,[]));return this.lastAdoption=o,n}};var Bt=class{constructor(e,n){this.registry=e;this.blobs=n;this.packageCache=new Xo(e),this.contests=new Qo(e),this.stop=e.observeDirty(o=>{for(let r of o.logicalIds)this.pendingDirty.add(r);o.membershipChanged&&(this.pendingMembership=true),o.packageChanged&&(this.pendingPackage=true);});}registry;blobs;cache=new qo;partCache=new Map;packageCache;relsProjection=new Map;pendingDirty=new Set;pendingMembership=false;pendingPackage=false;lastDirty=new Set;rawDirty=new Set;shownUnder=new Map;partRoots=new Set;forceFull=false;adoption=new Zo;mergeSources=new Map;builtMerges=new Map;contests;splitProjection=new Go;claimsWholeSubtrees=true;lastDuplicateParents=[];droppedChildren=new Set;looseCandidates=new Set;pkg=null;customXmlRels=[];customXmlOverrides=new Map;stop;issues=[];destroy(){this.stop();}dirtyLogicalIds(){return this.lastDirty}current(){return this.pkg&&this.pendingDirty.size===0&&!this.pendingPackage&&!this.pendingMembership?{ok:true,package:this.pkg,issues:[...this.issues]}:this.rebuild()}rebuildFull(){this.forceFull=true;try{return this.rebuild()}finally{this.forceFull=false;}}rebuild(){let e=new Set(this.pendingDirty),n=this.pendingPackage;this.pendingDirty.clear(),this.pendingMembership=false,this.pendingPackage=false;let o=this.registry.hasUnobservedWrites();o&&this.registry.rebuildDerivedIndexes(),(n||o)&&this.packageCache.invalidate();for(let c of this.adoption.changes(this.registry))e.add(c);for(let c of this.registry.inline.takeAffected())e.add(c);for(let c of this.registry.takeReparented())e.add(c);for(let c of [...e]){if(!this.registry.isTombstoned(c))continue;let u=this.registry.record(c);if(!(!u||!$(u)))for(let f of u.childIds)for(let p of this.registry.listingParents(f))e.add(p);}for(let c of this.splitProjection.update(this.registry))e.add(c);al(this.registry,e);let r=Vc(this.registry,e);Kc(r,e,this.shownUnder,this.registry.limits.maxTreeDepth);let i=this.partRoots=new Set(this.registry.partEntries().map(c=>c.rootLogicalId)),s=[...e].some(c=>i.has(c)||this.registry.parentOf(c)===null&&!this.registry.isTombstoned(c)),a=!this.forceFull&&this.pkg!==null&&!o&&!s&&(r.size>0||n);this.rawDirty=e;let l=this.materializePass(r,n,a);if(!this.contests.contested)return l;if(l.ok&&this.contests.decided())return {ok:true,package:l.package,issues:Iu(l.issues)};let d=this.materializePass(r,n,false);return this.contests.record(this.lastDuplicateParents),this.contests.recordEmbeds(this.shownUnder),d}materializePass(e,n,o){if(this.issues.length=0,this.lastDirty=e,this.contests.reset(),this.claimsWholeSubtrees=!o,this.droppedChildren.clear(),o)for(let f of this.lastDuplicateParents)this.push("duplicate-parent",f);this.customXmlRels=[],this.customXmlOverrides.clear();let r=new Set,i=new Map,s=this.registry.partEntries(),a=[...this.packageCache.groupedByOwner(this.customXmlRels).values()].flat();for(let f of [...s,...mu(this.registry,s,a)]){let p=new Set,h=this.materialize(f.rootLogicalId,r,p,o);if(!h||h.kind==="textValue")return {ok:false,code:"missing-root",issues:[...this.issues]};let g=this.partCache.get(f.name);if(g&&g.root===h&&g.contentType===f.contentType){i.set(f.name,g);continue}let m=Object.freeze({id:f.id||f.name,name:f.name,contentType:f.contentType,root:h});i.set(f.name,m),this.partCache.set(f.name,m);}let l=this.registry.history.takeMarkChanges(),d=o?new Set([...this.droppedChildren,...this.looseCandidates,...l]):this.registry.allLogicalIds(),c=new Set;this.projectRelsParts(i),this.adoptOrphanPartMembers(i,r,o,d,c),this.applyCustomXmlStores(i,r,o);for(let f of [...this.partCache.keys()])i.has(f)||this.partCache.delete(f);for(let f of [...this.relsProjection.keys()])i.has(f)||this.relsProjection.delete(f);this.evictDeadSubtrees(r);for(let f of e)r.has(f)||this.cache.forget(f);hu(this.registry,this.pushIssue,d,r,o,c),this.looseCandidates=c,o||(this.lastDuplicateParents=this.issues.flatMap(f=>f.code==="duplicate-parent"&&f.logicalId!==void 0?[f.logicalId]:[]));let u=this.assemblePackage(i);return u.ok?this.pkg&&!n&&this.pkg.parts.size===i.size&&[...i].every(([f,p])=>this.pkg?.parts.get(f)===p)?{ok:true,package:this.pkg,issues:[...this.issues]}:(this.pkg=u.package,{ok:true,package:this.pkg,issues:[...this.issues]}):u}push(e,n){this.issues.push(n?{code:e,logicalId:n}:{code:e});}pushIssue=(e,n)=>this.push(e,n);materialize(e,n,o,r){if(o.has(e)||o.size>=this.registry.limits.maxTreeDepth)return this.push("cycle",e),null;if(n.has(e))return this.push("duplicate-parent",e),null;let i=this.mergeSources.get(e)?.join("")??"";if(r&&!this.lastDirty.has(e)&&i===(this.builtMerges.get(e)??"")){let y=this.cache.get(e);if(y&&o.size+this.cache.heightOf(y)<=this.registry.limits.maxTreeDepth)return this.claimsWholeSubtrees?ps(y,n)||(this.contests.contested=true):n.add(U(y)),y}if(this.registry.isTombstoned(e))return null;let s=r?this.rebuildSpine(e,n,o):null;if(s)return s;n.add(e);let a=this.registry.record(e);if(!a)return this.push("missing-node",e),null;if(kt(a)){if(this.splitProjection.awaiting.has(e))return null;let y=this.splitProjection.textValue(e,a.value),v=this.cache.get(e);if(v?.kind==="textValue"&&v.value===y)return v;let E=$c(e,y);return this.cache.remember(e,E),E}o.add(e);let l=this.issues.length,d=new Set,c=at(this.registry).shownChildIds(e,a.childIds),u=new Set(c),f=y=>{u.has(y)||(u.add(y),c.push(y));};for(let y of this.registry.adoptedChildren(e))f(y);for(let y of this.mergeSources.get(e)??[]){let v=this.registry.record(y);if(!(!v||!$(v)))for(let E of v.childIds)f(E);}i?this.builtMerges.set(e,i):this.builtMerges.delete(e);let p=this.splitProjection.losers,h=p.size===0?null:Co(c,y=>p.has(y),y=>this.registry.splitLineageOf(y));h&&(c=h.map(y=>c[y]));let g=_n(c,this.registry.splitSiblings.ranksOf(e));g&&(c=g.map(y=>c[y]));let m=[],w=il(a,c,y=>this.splitProjection.losers.has(y)?null:et(this.registry,y));for(let y of w.hidden)n.add(y);for(let y of c)this.mergeSources.delete(y);for(let[y,v]of w.merges??[]){this.mergeSources.set(y,v);for(let E of v)this.shownUnder.set(E,y);}for(let y of w.shown){if(y===e){this.push("self-child",y);continue}if(d.has(y)){this.push("duplicate-child",y);continue}if(d.add(y),this.registry.isTombstoned(y)){this.push("deleted-referenced",y);continue}if(this.splitProjection.losers.has(y)){n.add(y);continue}if(O(y)||!this.registry.hasNode(y)){(O(y)||Zs(this.registry.schema.nodes,y))&&this.push("child-id-not-in-registry",y);continue}this.claimsWholeSubtrees||this.contests.note(y,e,n,this.partRoots);let v=this.materialize(y,n,o,r);v&&(m.push(v),this.shownUnder.set(U(v),e));}let I=w.hidden.length===0&&m.length===w.shown.length&&this.issues.length===l,b=this.registry.inline.textOf(e);if(b){let y=j=>{if(!this.registry.hasNode(j)&&Ke(this.registry.doc)||this.registry.listingParents(j).length>0||this.partRoots.has(j)||!this.claimsWholeSubtrees&&!this.contests.noteEmbed(j,e,this.shownUnder,this.lastDirty))return null;let K=this.materialize(j,n,o,r);return K&&this.shownUnder.set(j,e),K},v=this.registry.inline.viewOf(e),E=Ze(e,b,y,this.registry.limits,v),P=this.cache.get(e);m.push(...Ja(P?.kind==="textValue"?[]:P?.children??[],E));}o.delete(e);let x=this.cache.get(e);if(x&&x.kind!=="textValue"&&x.children.length===m.length&&x.children.every((y,v)=>y===m[v])&&Wc(x,a))return this.cache.markComplete(e,I),x;let L=x&&x.kind!=="textValue"?x.children:[];this.recordDroppedChildren(L,m);let k=Wo(a,Bn(L,m),x);return this.cache.remember(e,k),this.cache.markComplete(e,I),k}rebuildSpine(e,n,o){let r=this.cache.get(e);if(!r||r.kind==="textValue"||this.rawDirty.has(e)||!this.cache.isComplete(e)||ii(r)||this.builtMerges.has(e)||this.mergeSources.has(e)||this.splitProjection.losers.size>0||this.registry.adoptedChildren(e).length>0)return null;let i=this.cache.heightOf(r);if(o.size+i>this.registry.limits.maxTreeDepth)return null;let s=this.issues.length;o.add(e);let a=bu(r,{dirty:this.lastDirty,placed:n,isCached:u=>this.cache.holds(u),canRebuild:u=>O(u)||this.registry.isTombstoned(u)||!this.registry.hasNode(u)?false:(this.contests.note(u,e,n,this.partRoots),true),rebuild:u=>{let f=this.materialize(u,n,o,true);return f&&this.shownUnder.set(U(f),e),f}});if(o.delete(e),!a)return null;n.add(e);let l=a.dropped.length===0&&this.issues.length===s;if(a.children===r.children)return this.cache.markComplete(e,l),r;for(let u of a.dropped)this.droppedChildren.add(u);let d=Object.freeze(qe(r,a.children));this.cache.remember(e,d),this.cache.markComplete(e,l);let c=i;for(let u of a.children)this.lastDirty.has(U(u))&&(c=Math.max(c,this.cache.heightOf(u)+1));return this.cache.setHeight(e,c),d}recordDroppedChildren(e,n){if(e.length===0)return;let o=new Set(n.map(r=>r.id));for(let r of e)o.has(r.id)||this.droppedChildren.add(U(r));}evictDeadSubtrees(e){for(let n of this.droppedChildren)e.has(n)||(this.registry.isTombstoned(n)||!this.registry.hasNode(n))&&this.cache.evictSubtree(n,e,o=>this.shownUnder.delete(o));}retainedNodeIds(){return this.cache.ids()}projectRelsParts(e){let n=this.packageCache.groupedByOwner(this.customXmlRels),o=new Set;for(let[r,i]of n){let s=relsPartNameFor(r);if(s!=="/_rels/.rels"&&Ie(s))continue;o.add(s);let a=this.projectOneRelsPart(s,e.get(s),i);a&&(e.set(s,a),this.partCache.set(s,a));}for(let[r,i]of e){if(o.has(r)||!Jo(r))continue;let s=Hc(r);if(s===null)continue;let a=this.projectOneRelsPart(r,i,n.get(s)??[]);!a||a===i||(e.set(r,a),this.partCache.set(r,a));}}projectOneRelsPart(e,n,o){if(!n&&o.length===0)return this.relsProjection.delete(e),null;let r=this.relsProjection.get(e),s=!!r&&(!n||qc(r.root,n.root))&&r?r:n??Zc(e);if(Gc(s.root,o))return this.relsProjection.set(e,s),s;let a=s.root.children,l=Bc(s,Qc(a,o,e));return this.relsProjection.set(e,l),l}builtNode(e){return this.cache.get(e)??null}shownParentOf(e){return this.shownUnder.get(e)??null}shownPartChildren(e){return uu(this.partCache.values(),e)}adoptOrphanPartMembers(e,n,o,r,i){for(let[s,a]of e){let l=ys(a.root);if(!l)continue;let d=k=>k.logicalId!==a.root.id&&l.isMember(k),c=[],u=new Set,f=new Set,p=this.registry.record(U(a.root)),h=new Set(p&&$(p)?p.childIds:[]);for(let k of a.root.children){if(k.kind==="textValue")continue;let y=U(k);if(this.registry.isTombstoned(y)||!h.has(y)&&(Gn(this.registry.schema.nodes.get(y))||this.registry.listingParents(y).length>0)){f.add(y);continue}let v=this.registry.record(U(k));!v||!$(v)||!d(v)||(c.push(k),u.add(U(k)));}let g=gu(this.registry,k=>this.materialize(k,n,new Set,o),c,u,d,n,o,r,i);if(g===0&&f.size===0)continue;let m=(k,y)=>l.sortKey(k).localeCompare(l.sortKey(y));if(l.adoptedAfterListed){let k=c.length-g;c.splice(k,g,...c.slice(k).sort(m));}else c.sort(m);let w=[];for(let k of a.root.children)u.has(U(k))||f.has(U(k))||w.push(k);let I=Bn(a.root.children,[...w,...c]);if(I===a.root.children)continue;let b=this.registry.record(U(a.root));if(!b||!$(b))continue;let x=Wo(b,I,a.root);this.cache.remember(U(a.root),x);let L=Object.freeze({...a,root:x});e.set(s,L),this.partCache.set(s,L);}}materializeOnce(e,n,o){return n.has(e)?this.cache.get(e)??null:this.materialize(e,n,new Set,o)}adoptNodesIntoRoot(e,n,o,r){let i=this.cache.get(e),s=i&&i.kind!=="textValue"?i:this.materializeOnce(e,o,r);if(!s||s.kind==="textValue")return null;let a=[...s.children],l=new Set(a.map(p=>p.id)),d=0;for(let p of n){if(l.has(p))continue;let h=this.materializeOnce(p,o,r);!h||h.kind==="textValue"||(a.push(h),l.add(p),d+=1);}if(a.sort((p,h)=>fs(p).localeCompare(fs(h))),d===0&&a.every((p,h)=>p===s.children[h]))return s;let c=this.registry.record(e);if(!c||!$(c))return s;let u=Bn(s.children,a),f=Wo(c,u,s);return this.cache.remember(e,f),f}applyCustomXmlStores(e,n,o){let r=iu(this.registry,e);if(r.length===0||!du(e,r))return;let i=ms(e,r),s=new Set;for(let a of r){s.add(a.itemName),s.add(a.propsName);let l=this.adoptNodesIntoRoot(a.dataRootId,a.nodeIds,n,o),d=this.materializeOnce(a.propsRootId,n,o);if(!l||!d||d.kind==="textValue")continue;let c=Object.freeze({id:a.itemName,name:a.itemName,contentType:"application/xml",root:l}),u=Object.freeze({id:a.propsName,name:a.propsName,contentType:CUSTOM_XML_PROPS_TYPE,root:d});e.set(a.itemName,c),e.set(a.propsName,u),this.partCache.set(a.itemName,c),this.partCache.set(a.propsName,u);}if(i){for(let a of [...e.keys()])!Fn(a)&&!gs(a)||s.has(a)||(e.delete(a),this.partCache.delete(a));this.customXmlRels=su(this.registry,r),this.customXmlOverrides=lu(r),this.projectRelsParts(e);}}assemblePackage(e){let n=this.packageCache.relationshipAssembly(this.customXmlRels);if(!n)return {ok:false,code:"invalid-relationships",issues:[...this.issues]};let o=this.packageCache.resolvePartBytes(this.blobs);if(!o)return {ok:false,code:"missing-blob",issues:[...this.issues]};let r=new Map(this.packageCache.contentTypeOverrides());for(let[a,l]of this.customXmlOverrides)r.set(a,l);let i={defaults:this.packageCache.contentTypeDefaults(),overrides:r};yu(e,i,r);let s=this.registry.mainDocumentPart()||[...e.keys()].find(a=>a.endsWith("document.xml"))||"";return {ok:true,package:Object.freeze({parts:e,partBytes:o,relationships:n.byOwner,externalTargets:n.externalTargets,contentTypes:i,mainDocumentPart:s}),issues:[...this.issues]}}};function xu(t,e){if(!t)return e.effects.some(r=>r.kind==="putBinary")?{ok:false,failure:Object.freeze({code:"collaboration-session-not-attached"})}:null;let n=Dc(e.effects,Ac(t));return n===null?null:n.ok?n:{ok:false,failure:Object.freeze(n.failure)}}function Su(t,e){try{Nc(t,e);}catch(n){return n instanceof N?Object.freeze({code:n.code,...n.detail?{detail:n.detail}:{}}):Object.freeze({code:"blob-store-full"})}return null}function bs(t){let{status:e,reason:n}=t;return e!=="ready"&&e!=="disconnected"?null:{status:e,...n?{code:n.code,detail:n.detail}:{}}}var yy=3,by=20,er=class{refused=0;transient=0;published(){this.refused=0,this.transient=0;}refusedOne(e){(!e||++this.transient>by)&&(this.refused+=1);}recoverable(){return this.refused<yy}};var Is="docxEditorSelectionBefore",tr=class{constructor(e,n,o=()=>null){this.undoManager=e;this.textOf=n;this.find=o;e.on("stack-item-added",this.onAdded),e.on("stack-item-popped",this.onPopped);}undoManager;textOf;find;latest=null;before=null;restored=null;onAdded=e=>{e.stackItem.meta.has(Is)||e.stackItem.meta.set(Is,this.before);};onPopped=e=>{let n=e.stackItem.meta.get(Is);this.restored=n??null;};track(e,n=new Map){if(!e){this.latest=null;return}let o=r=>({paragraphId:r.paragraphId,offset:r.offset,...r.character?{character:r.character}:{}});this.latest={selection:{anchor:o(e.anchor),head:o(e.head),...e.kind?{kind:e.kind}:{}},texts:n};}noteBefore(){this.before=this.latest;}startPop(){this.restored=null;}lastRestored(){let e=this.restored;if(!e)return null;let n=r=>{let i=r.character?this.find(r.paragraphId,r.character):null;if(i)return i;let s={paragraphId:r.paragraphId,offset:r.offset},a=e.texts.get(r.paragraphId),l=this.textOf(r.paragraphId);return a===void 0||l===null?s:{...s,offset:mapOffsetAcrossText(r.offset,a,l)}},{selection:o}=e;return {anchor:n(o.anchor),head:n(o.head),...o.kind?{kind:o.kind}:{}}}destroy(){this.undoManager.off("stack-item-added",this.onAdded),this.undoManager.off("stack-item-popped",this.onPopped);}};var wu=Symbol("createDocumentCollaboration.attachWatchdogMs");function ku(t){return t[wu]??2e3}function vu(t,e,n){let o=setTimeout(()=>{n()||console.warn(`[docx-editor] The collaboration session for "${t}" was created ${e}ms ago and no editor attached its document port. The session reports "ready" but no edits replicate. Remount the editor when the session appears \u2014 for example pass key={session.sessionId} \u2014 so collaborationModule({ session }) attaches it.`);},e);return o.unref?.(),o}var pn="docxEditor",ht=256,nr=256,Lu=/^\d{1,16}:\d{1,16}$/;function Ou(t,e,n){let o=new Map,r=s=>{let a=s.paragraphId.toUpperCase(),l=o.get(a);l===void 0&&(l=e(a),l!==void 0&&o.set(a,l));let d=Math.max(0,s.offset),c=n({paragraphId:a,offset:d});return {paragraphId:a,offset:d,...l!==void 0?{digest:or(l)}:{},...c?{character:c}:{}}};return {encoded:{anchor:r(t.anchor),head:r(t.head),...t.kind==="cells"?{kind:"cells"}:{}},texts:o}}function Sy(t){if(typeof t!="object"||t===null||Array.isArray(t))return null;let e=t;if(typeof e.item!="string"||!Lu.test(e.item)||typeof e.after!="boolean")return null;let n=typeof e.identity=="string"&&Lu.test(e.identity)?e.identity:void 0;return {item:e.item,...n?{identity:n}:{},after:e.after}}function or(t){let e=2166136261;for(let n=0;n<t.length;n+=1)e^=t.charCodeAt(n),e=Math.imul(e,16777619);return (e>>>0).toString(16).padStart(8,"0")}var wy=/^[0-9a-f]{8}$/;function Eu(t){let e=t.actorId.trim(),n=t.name.trim();if(e.length===0||e.length>ht||n.length===0||n.length>ht)throw new N("invalid-identity");if(t.color!==void 0&&t.color.length>64)throw new N("invalid-identity-color");return Object.freeze({actorId:e,name:n,...t.color?{color:t.color}:{},role:t.role??"human"})}function Cu(t){let e=t.trim();if(e.length===0||e.length>ht)throw new N("invalid-document-id");return e}function Tu(t){let e=t?.trim()||globalThis.crypto.randomUUID();if(e.length>ht)throw new N("invalid-session-id");return e}function Ru(t){if(typeof t!="object"||t===null||Array.isArray(t))return null;let e=t;if(typeof e.paragraphId!="string"||e.paragraphId.length!==8||!Number.isSafeInteger(e.offset)||e.offset<0)return null;let n=Sy(e.character);return {paragraphId:e.paragraphId.toUpperCase(),offset:e.offset,...typeof e.digest=="string"&&wy.test(e.digest)?{digest:e.digest}:{},...n?{character:n}:{}}}function ky(t){if(t===void 0||typeof t!="object"||t===null||Array.isArray(t))return;let e=t,n=Ru(e.anchor),o=Ru(e.head);if(n&&o)return e.kind==="cells"?{anchor:n,head:o,kind:"cells"}:{anchor:n,head:o};if(typeof e.paragraphId=="string"&&e.paragraphId.length===8&&Number.isSafeInteger(e.start)&&Number.isSafeInteger(e.end)&&e.start>=0&&e.end>=0){let r=e.paragraphId.toUpperCase();return {anchor:{paragraphId:r,offset:e.start},head:{paragraphId:r,offset:e.end}}}}function rr(t){if(typeof t!="object"||t===null||Array.isArray(t))return null;let e=t;if(typeof e.actorId!="string"||e.actorId.length===0||e.actorId.length>ht||typeof e.name!="string"||e.name.length===0||e.name.length>ht)return null;let n=safeParticipantColor(typeof e.color=="string"?e.color:void 0),o=e.role==="agent"?"agent":"human",r={actorId:e.actorId,name:e.name,...n?{color:n}:{},role:o},i=ky(e.selection);return i?{...r,selection:i}:r}var Ly=16,Ry=32,ir=class{baselines=new Map;resolve(e,n,o){let r=[...e.getStates().entries()].slice(0,nr),i=[],s=new Set,a=new Set,l=0,d;for(let[c,u]of r){if(c===e.clientID)continue;let f=rr(u[pn]);if(!f?.selection)continue;s.add(c);let{anchor:p,head:h}=f.selection,g=`${p.paragraphId}:${p.offset}:${p.digest??""}|${h.paragraphId}:${h.offset}:${h.digest??""}`,m=this.baselines.get(c);m?.key!==g&&(m={key:g,texts:new Map,resolved:new Map,missing:new Map},this.baselines.set(c,m));let{texts:w,resolved:I,missing:b}=m,x=y=>{let v=false,E=()=>{if(!y.character||!o)return null;if(l>=Ry)return v=true,null;l+=1;let ne=o(y.paragraphId,y.character),A=ne?n.paragraphByNodeId(ne.nodeId):null;if(!ne||!A)return null;let J={paragraphId:A.paragraphId,nodeId:A.nodeId,offset:ne.offset};return {address:Object.freeze(J),text:A.text}},P=n.paragraphByStableId(y.paragraphId);if(!P){let ne=y.paragraphId+":"+y.offset;d??=n.revision();let A=b.get(ne);if(A?.revision===d)return A.address;let J=E()?.address??null;return v||b.set(ne,{revision:d,address:J}),J}let j=I.get(y.paragraphId+":"+y.offset);if(j?.text===P.text&&j.address.nodeId===P.nodeId&&(j.target===void 0||n.paragraphByNodeId(j.address.nodeId)?.text===j.target))return j.address;let K=E();if(K)return I.set(y.paragraphId+":"+y.offset,{text:P.text,address:K.address,target:K.text}),K.address;let Y=w.get(y.paragraphId);if(Y===void 0){if(y.digest!==void 0&&or(P.text)!==y.digest)return Object.freeze({paragraphId:P.paragraphId,nodeId:P.nodeId,offset:Math.min(y.offset,P.text.length)});Y=P.text,w.set(y.paragraphId,Y);}let V=Y===P.text?"":`${y.paragraphId}:${Y.length}:${or(Y)}`,q=V===""||a.has(V)||a.size<Ly;q&&V!==""&&a.add(V);let ee=Object.freeze({paragraphId:P.paragraphId,nodeId:P.nodeId,offset:q?mapOffsetAcrossText(y.offset,Y,P.text):Math.min(y.offset,P.text.length)});return I.set(y.paragraphId+":"+y.offset,{text:P.text,address:ee}),ee},L=x(p),k=x(h);!L||!k||i.push(Object.freeze({actorId:f.actorId,name:f.name,...f.color?{color:f.color}:{},...f.selection.kind==="cells"?{kind:"cells"}:{},anchor:L,head:k}));}for(let c of this.baselines.keys())s.has(c)||this.baselines.delete(c);return Object.freeze(i)}};var zn=64*1024*1024,hn="docx-package-blobs-v1";function Ey(t){if(t instanceof Uint8Array)return new Uint8Array(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t)){let e=t;return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}return null}function Cy(t){return t instanceof ArrayBuffer||ArrayBuffer.isView(t)?t.byteLength:0}var gt=class{constructor(e){this.shared=e;}shared;verified=new WeakSet;poisoned=new Set;get(e){let n=this.shared.get(e),o=Ey(n);return !o||typeof n!="object"||n===null?null:this.verify(e,n,o)?o:null}has(e){let n=this.shared.get(e);return n===void 0?false:this.verified.has(n)?true:this.get(e)!==null}poisonedDigest(){for(let e of this.poisoned)return e;return null}observeChanges(e){let n=o=>{e([...o.keysChanged]);};return this.shared.observe(n),()=>this.shared.unobserve(n)}verifyNow(e){for(let n of e)if(this.shared.has(n)&&this.get(n)===null)return n;return null}totalByteLength(){let e=0;return this.shared.forEach(n=>{e+=Cy(n);}),e}put(e,n){if(!this.shared.has(e)){if(this.totalByteLength()+n.byteLength>zn)throw new N("blob-store-full");this.shared.set(e,new Uint8Array(n));}}verify(e,n,o){return this.verified.has(n)?true:this.poisoned.has(e)?false:sha256FontBytes(o)!==e?(this.poisoned.add(e),false):(this.verified.add(n),true)}};var Ty=Object.freeze([.75,.9]),Mu=16;function xs(t){let e=0;return t.schema.relationships.forEach(n=>{e+=n instanceof z.Map?n.size:0;}),e}function Au(t){return {limit:"nodes",code:"too-many-nodes",used:t.nodeCount(),max:t.limits.maxNodes}}function Du(t,e){let{limits:n,schema:o}=t;return [{limit:"parts",code:"too-many-parts",used:o.parts.size,max:n.maxParts},{limit:"relationships",code:"too-many-relationships",used:xs(t),max:n.maxRelationships},{limit:"blobBytes",code:"blob-store-full",used:e.totalByteLength(),max:zn}]}function My(t,e){return [Au(t),...Du(t,e)]}function ar(t,e){for(let n of My(t,e))if(n.used>n.max)return Object.freeze({code:n.code,detail:`${n.limit}=${n.used}`});return null}function Py(t){let e=t?.thresholds;if(e===void 0)return Ty;if(!Array.isArray(e)||e.length===0||e.length>Mu)throw new RangeError(`thresholds must hold 1 to ${Mu} values`);for(let n of e)if(typeof n!="number"||!Number.isFinite(n)||n<=0||n>1)throw new RangeError("each threshold must be greater than 0 and at most 1");return [...new Set(e)].sort((n,o)=>n-o)}function Ay(t,e){let n=t[0],o=-1;for(let i of t){let s=i.max>0?i.used/i.max:Number.POSITIVE_INFINITY;s>o&&(n=i,o=s);}let r=0;for(let i of e)o>=i&&(r=i);return Object.freeze({limit:n.limit,fraction:o,threshold:r,used:n.used,max:n.max})}var sr=class{stops=new Set;stopped=false;watch(e,n,o,...[r,i]){let s=Py(i);if(this.stopped)return ()=>{};let{parts:a,relationships:l}=n.schema,d=null,c=()=>{d=null;},u=()=>(d??=Du(n,o),Ay([Au(n),...d],s)),f=w=>{try{r(w);}catch(I){console.error("A subscribeResourcePressure listener threw.",I);}};a.observe(c),l.observeDeep(c);let p=o.observeChanges(c),h=u().threshold,g=()=>{let w=u();w.threshold!==h&&(h=w.threshold,f(w));},m=()=>{this.stops.delete(m)&&(e.off("afterTransaction",g),a.unobserve(c),l.unobserveDeep(c),p());};return e.on("afterTransaction",g),this.stops.add(m),h>0&&f(u()),m}stopAll(){this.stopped=true;for(let e of [...this.stops])e();}};var Yu=20*1024*1024,Fy=new Set(["document","hdr","ftr","footnotes","endnotes"]),Uu=3e4,jy=4e3,zy=1500,$y="docx-collaboration-seeds-v1",Ss="docxEditorSeedCandidate",Wy=/^[0-9a-f]{16}$/,Ky=256;function Fu(t,e=Yu,n={}){if(!(t instanceof Uint8Array)||t.byteLength===0)throw new N("invalid-baseline");let o=Math.min(e,Yu);if(t.byteLength>o)throw new N("baseline-too-large");let r=readOoxmlPackage(t,{zip:{maxEntries:1e4,maxTotalBytes:o,maxRatio:200}});if(!r.ok)throw new N(r.limit==="zip.maxTotalBytes"?"baseline-too-large":"invalid-baseline");let i=r.package.parts.get(r.package.mainDocumentPart);if(!i)throw new N("no-main-document-part");let s=n.keepBound?r.package:refreshBoundContent(r.package);for(let l of s.parts.values()){if(l.root.namespaceUri!==WML_NAMESPACE_URI||!Fy.has(l.root.localName)||!isStoryPart(l))continue;let d=normalizeParagraphIdentity(l);d!==l&&(s=withPart(s,d));}return new TreePackageStore(s,normalizeParagraphIdentity(s.parts.get(i.name))).currentPackage()}function Vy(t,e){for(let n of t.binaries())if(!e.has(n.digest))return false;return true}function lr(t,e,n,o){let r=t.schema.meta,i=()=>r.get("initialized")===true&&Vy(t,e),s=()=>{let l=e.poisonedDigest();return l?new N("blob-digest-mismatch",l):null};if(o?.aborted)return Promise.reject(new N("initialization-aborted"));if(i())return Promise.resolve();let a=s();return a?Promise.reject(a):new Promise((l,d)=>{let c=h=>{clearTimeout(p),r.unobserve(u),t.doc.off("afterTransaction",u),o?.removeEventListener("abort",f),h?d(h):l();},u=()=>{let h=s();if(h){c(h);return}i()&&c();},f=()=>c(new N("initialization-aborted")),p=setTimeout(()=>c(new N("initialization-timeout")),n);r.observe(u),t.doc.on("afterTransaction",u),o?.addEventListener("abort",f,{once:true});})}function cr(t){return t.getArray($y)}function Jy(t){cr(t).push([$u()]);}var Hy="freshBytes";function ju(t){let e=z.encodeStateAsUpdate(t).byteLength;t.getMap(kr).set(Hy,e);}function Xy(t){return cr(t).length}function zu(t,e){let n=cr(t),o=()=>{n.length>1&&e();};return o(),n.observe(o),()=>n.unobserve(o)}function $u(){let t=new Uint8Array(8);return globalThis.crypto.getRandomValues(t),[...t].map(e=>e.toString(16).padStart(2,"0")).join("")}function Gy(t,e){let n=[...t.getStates().entries()].slice(0,Ky);for(let[o,r]of n){if(o===t.clientID)continue;let i=r[Ss];if(!(typeof i!="string"||!Wy.test(i))&&i<e)return true}return false}async function _u(t,e,n,o){try{return await lr(t,e,n,o),!0}catch(r){if(r instanceof N&&r.code==="initialization-timeout")return false;throw r}}function qy(t,e,n){let o=t.schema.meta,r=()=>o.get("documentId")!==void 0;return n?.aborted?Promise.reject(new N("initialization-aborted")):r()?Promise.resolve():new Promise((i,s)=>{let a=u=>{clearTimeout(c),o.unobserve(l),n?.removeEventListener("abort",d),u?s(u):i();},l=()=>{r()&&a();},d=()=>a(new N("initialization-aborted")),c=setTimeout(()=>a(new N("initialization-timeout")),e);o.observe(l),n?.addEventListener("abort",d,{once:true});})}async function Qy(t){let{ydoc:e,awareness:n,registry:o,blobs:r}=t,i=t.probeTimeoutMs??jy,s=t.electionWindowMs??zy,a=t.timeoutMs??Uu,l=async()=>(await qy(o,a,t.signal),"joined");if(await _u(o,r,i,t.signal))return l();let d=$u();n.setLocalStateField(Ss,d);try{let c=await _u(o,r,s,t.signal);if(!c&&Gy(n,d)&&(await lr(o,r,a,t.signal),c=!0),c)return await l();if(o.schema.meta.get("initialized")===!0)return await lr(o,r,a,t.signal),await l();if(t.signal?.aborted)throw new N("initialization-aborted");let u=await $o(o,Fu(t.document),r);if(!u.ok)throw new N(u.code);return e.transact(()=>{o.schema.meta.set("documentId",t.documentId),cr(e).push([d]);}),ju(e),"seeded"}finally{n.setLocalStateField(Ss,null);}}function dr(t,e,n){let o=Xn(t.schema.meta);if(o)throw new N(o.code,o.detail);t.rebuildDerivedIndexes(),ws(t,e,n);}function ws(t,e,n){if(Xy(n)>1)throw new N("concurrent-seed");let o=ar(t,e);if(o)throw new N(o.code,o.detail)}async function Wu(t,e,n,o){if(t.bootstrap.kind==="create"){if(e.schema.meta.get("initialized")===true)throw new N("already-initialized");let r=await $o(e,Fu(t.bootstrap.document),n);if(!r.ok)throw new N(r.code);t.ydoc.transact(()=>{e.schema.meta.set("documentId",o),Jy(t.ydoc);}),ju(t.ydoc),ws(e,n,t.ydoc);}else if(t.bootstrap.kind==="create-or-join")if(await Qy({ydoc:t.ydoc,awareness:t.awareness,registry:e,blobs:n,documentId:o,document:t.bootstrap.document,probeTimeoutMs:t.bootstrap.probeTimeoutMs,electionWindowMs:t.bootstrap.electionWindowMs,timeoutMs:t.bootstrap.timeoutMs,signal:t.bootstrap.signal})==="joined"){if(e.schema.meta.get("documentId")!==o)throw new N("document-id-mismatch");dr(e,n,t.ydoc);}else ws(e,n,t.ydoc);else {if(await lr(e,n,t.bootstrap.timeoutMs??Uu,t.bootstrap.signal),e.schema.meta.get("documentId")!==o)throw new N("document-id-mismatch");dr(e,n,t.ydoc);}}function ur(t,e,n,o){let r=t.inline.textOf(e);if(!r)return null;let i=[],s=new Set,a=Ze(e,r,m=>{if(s.has(m))return null;let w=n(m);return w&&s.add(w.id),w},t.limits,{...t.inline.viewOf(e),noteDrift:()=>{}},m=>i.push(m)),l={id:e,kind:"paragraph",namespaceUri:WML_NAMESPACE_URI,localName:"p",prefix:"w",namespaceBindings:[],attributes:[],children:a},d=new Map,c=0,u=m=>{if(!s.has(m.id)){if(m.kind==="textValue"){d.set(m.id,c),c+=m.value.length;return}for(let w of m.children)u(w);}};for(let m of a)u(m);if(c!==i.length)return null;let f=segmentsOf(l),p=f.length>0?f[f.length-1].end:0;if(p!==o.length)return null;let h=new Int32Array(p).fill(-1),g=new Int32Array(i.length).fill(-1);for(let m of f){if(m.node.kind!=="textValue"||m.removeNodeIds)continue;let w=d.get(m.node.id),I=m.node.value;if(w===void 0||o.slice(m.start,m.end)!==I)return null;for(let b=0;b<m.end-m.start;b+=1)h[m.start+b]=w+b,g[w+b]=m.start+b;}return {length:p,characters:i,characterAt:h,offsetOf:g}}function Ku(t,e){let n=e>0?t.characterAt[e-1]:-1;if(n!==void 0&&n>=0){let r=t.characters[n];return r?{character:r,after:true}:null}let o=e<t.length?t.characterAt[e]:-1;if(o!==void 0&&o>=0){let r=t.characters[o];return r?{character:r,after:false}:null}return null}function ks(t,e){let n=e.character.identity??e.character.item,o=-1;for(let i=0;i<t.characters.length;i+=1){let s=t.characters[i];if(s){if(s.item===e.character.item){o=i;break}o<0&&s.identity===n&&(o=i);}}if(o<0)return null;let r=t.offsetOf[o];return r<0?null:e.after?r+1:r}var tb=4096,Vu=64,fr=class{constructor(e){this.deps=e;}deps;selection=null;anchored=null;stale=true;carried=null;carryOwed=false;track(e){let n=this.deps.port(),o=a=>{let l=n?.paragraphByStableId(a.paragraphId);return l?{nodeId:l.nodeId,offset:a.offset}:null},r=e?o(e.anchor):null,i=e?o(e.head):null,s=r&&i?{anchor:r,head:i}:null;s&&this.selection&&nb(s,this.selection)||(this.selection=s,this.stale=true,this.anchored=null,this.carried=null,this.carryOwed=false);}localChange(){this.stale=true,this.anchored=null,this.carried=null,this.carryOwed=false;}beforeChange(){if(this.carried=null,this.carryOwed=true,!this.stale)return;this.anchored=null;let e=this.selection;if(!e||!this.deps.viewIsCurrent())return;let n=this.anchorOf(e.anchor),o=this.anchorOf(e.head);!n||!o||(this.anchored={anchor:n,head:o},this.stale=false);}afterPublish(){this.carryOwed=false;let{anchored:e,selection:n}=this;if(!e||!n||!this.deps.viewIsCurrent()){this.carried=null;return}let o=this.resolve(e.anchor),r=this.resolve(e.head);this.carried=o&&r?{from:n,to:{anchor:o,head:r}}:null;}move(){return this.carryOwed&&this.afterPublish(),this.carried}characterOf(e){let n=this.deps.port()?.paragraphByStableId(e.paragraphId);if(!n||!this.deps.viewIsCurrent())return;let o=this.anchorOf({nodeId:n.nodeId,offset:e.offset});if(!o)return;let{character:r,after:i}=o.anchor;return {item:r.item,...r.identity!==null?{identity:r.identity}:{},after:i}}find(e,n){if(!this.deps.viewIsCurrent())return null;let o=this.deps.port()?.paragraphByStableId(e);return this.resolve({paragraph:o?this.deps.logicalIdOf(o.nodeId):null,anchor:{character:{item:n.item,identity:n.identity??null},after:n.after}})}findStable(e,n){let o=this.find(e,n),r=o?this.deps.port()?.paragraphByNodeId(o.nodeId):null;return o&&r?{paragraphId:r.paragraphId,offset:o.offset}:null}anchorOf(e){let n=this.deps.logicalIdOf(e.nodeId),o=this.shownText(e.nodeId);if(o===null)return null;let r=ur(this.deps.registry,n,this.deps.embedOf,o),i=r?Ku(r,e.offset):null;return i?{paragraph:n,anchor:i}:null}resolve(e){let{registry:n}=this.deps,o=n.inline.follow,r=e.anchor.character.identity??e.anchor.character.item,i=new Set(e.paragraph?[e.paragraph]:[]),s=o.shownCopy(r);s&&i.add(s);for(let a of o.holdersOf(r))i.add(a);if(e.paragraph)for(let a of o.targetsFor(e.paragraph))i.add(a);for(let a of i){if(i.size>=Vu)break;for(let l of o.targetsFor(a)){if(i.size>=Vu)break;i.add(l);}}for(let a of i){if(n.inline.isDeletedParagraph(a))continue;let l=this.shownText(a);if(l===null)continue;let d=ur(n,a,this.deps.embedOf,l),c=d?ks(d,e.anchor):null;if(c!==null)return {nodeId:a,offset:c}}return e.paragraph?this.besideDeleted(e.paragraph,e.anchor):null}besideDeleted(e,n){let{registry:o}=this.deps,r=o.inline.textOf(e),i=this.shownText(e),s=/^(\d{1,16}):(\d{1,16})$/.exec(n.character.item);if(!r?.doc||i===null||!s||o.inline.isDeletedParagraph(e))return null;let a=H(r.doc,{client:Number(s[1]),clock:Number(s[2])});if(!a||!a.deleted||a.parent!==r)return null;let l=ur(o,e,this.deps.embedOf,i);if(!l)return null;if(i.length===0)return {nodeId:e,offset:0};for(let d of [true,false]){let c=0;for(let u=d?a.left:a.right;u&&c<tb;u=d?u.left:u.right,c+=1){if(u.deleted||!(u.content instanceof z.ContentString))continue;let f=d?u.id.clock+u.length-1:u.id.clock,p=ks(l,{character:{item:`${u.id.client}:${f}`,identity:null},after:d});if(p!==null)return {nodeId:e,offset:p}}}return null}shownText(e){return this.deps.port()?.paragraphTextOf?.(e)??null}};function nb(t,e){return t.anchor.nodeId===e.anchor.nodeId&&t.anchor.offset===e.anchor.offset&&t.head.nodeId===e.head.nodeId&&t.head.offset===e.head.offset}var pr=class{constructor(e){this.deps=e;}deps;waiting=false;held=[];refuses(e){return this.deps.viewWaiting()?this.set(true):Ke(this.deps.ydoc)?this.waits(e)?(this.held=e,this.set(true)):(this.held.length>0&&!this.waits(this.held)&&(this.held=[]),this.set(this.held.length>0),false):(this.held=[],this.set(false))}refresh(){!this.waiting||this.deps.viewWaiting()||(!Ke(this.deps.ydoc)||this.held.length>0&&!this.waits(this.held))&&(this.held=[],this.set(false));}waits(e){return e.some(n=>ob.has(n.op)||rb(n).some(o=>this.deps.nodeWaits(o)))}set(e){return e!==this.waiting&&(this.waiting=e,this.deps.publish(e)),e}},ob=new Set(["acceptAllRevisions","rejectAllRevisions","replaceStoryBlocks","convertAllNotes"]);function rb(t){let e=[],n=(o,r)=>{for(let[i,s]of Object.entries(o))if(typeof s=="string")i.endsWith("Id")&&e.push(s);else if(Array.isArray(s))for(let a of s)typeof a=="string"?i.endsWith("Ids")&&e.push(a):a!==null&&typeof a=="object"&&r<3&&n(a,r+1);else s!==null&&typeof s=="object"&&r<3&&n(s,r+1);};return n(t,0),e}function ib(t){let e=0;return t.schema.nodes.forEach(n=>{_(n)&&n.get(me)===true&&(e+=1);}),e}function sb(t){let e=0;return t.schema.nodes.forEach(n=>{let o=_(n)?n.get(ae):null;if(o instanceof z.Text)for(let r=o._start;r;r=r.right)!r.deleted&&r.content instanceof z.ContentFormat&&(e+=1);}),e}function vs(t,e){return Object.freeze({nodes:t.nodeCount(),tombstonedNodes:ib(t),maxNodes:t.limits.maxNodes,relationships:xs(t),maxRelationships:t.limits.maxRelationships,parts:t.schema.parts.size,maxParts:t.limits.maxParts,blobBytes:e.totalByteLength(),maxBlobBytes:zn,formattingMarkers:sb(t)})}function pR(t){let e=new rt(t);try{let n=new gt(t.getMap(hn));return vs(e,n)}finally{e.destroy();}}var ab={"undo-group-already-open":"End the open group, or use another session for this operation.","editor-attached":"Use editor.beginHistoryGroup() in the editor, or a separate session for the agent.","collaboration-session-destroyed":"Join the room with a new session."},mt=class extends Error{constructor(n){super(`${n}: ${ab[n]}`);this.code=n;this.name="CollaborationUndoGroupError";}code},gr=class{constructor(e,n){this.capture=e;this.flush=n;}capture;flush;current=null;get isOpen(){return this.current!==null}begin(e,n){if(e())throw new mt("collaboration-session-destroyed");if(n())throw new mt("editor-attached");if(this.current!==null)throw new mt("undo-group-already-open");if(this.flush(),e())throw new mt("collaboration-session-destroyed");if(n())throw new mt("editor-attached");if(this.current!==null)throw new mt("undo-group-already-open");let o={};this.current=o,this.capture.pin(Symbol("collaboration-undo-group"));let r=this;return Object.freeze({get state(){return r.current===o?"open":"closed"},end(){r.current===o&&(r.flush(),r.current===o&&(r.current=null,r.capture.unpin()));}})}close(){this.current!==null&&(this.current=null,this.capture.unpin());}};var lb=2;function Hu(t,e){let n=new Set,o=new Set;for(let i of e.effects)if(i.kind==="spliceChildren"){n.add(i.parentLogicalId);for(let s of i.childLogicalIds)o.add(s);}else if(i.kind==="moveNode"){o.add(i.logicalId),n.add(i.destinationParentLogicalId);let s=t.parentOf(i.logicalId);s&&n.add(s);}let r=[];for(let i of n){if(!t.splitSiblings.ranksOf(i))continue;let s=t.splitSiblings.shownChildren(i);s&&r.push({parentId:i,shown:s,placed:o});}return r}function db(t,e,n){let o=new Set(e),r=new Set(t.filter(d=>o.has(d)&&!n.has(d))),i=t.filter(d=>r.has(d)),s=0,a=false,l=e.map(d=>{if(!r.has(d))return d;let c=i[s++];return c!==d&&(a=true),c});return a?l:null}function cb(t,e,n,o){let r=ie(t.schema.nodes.get(e));if(!r)return false;let i=0;for(;o[i]===n[i];)i+=1;let s=o.length-1;for(;o[s]===n[s];)s-=1;let a=o.slice(i,s+1),l=r.toArray();for(let u of a){if(l.indexOf(u)!==l.lastIndexOf(u))return false;let f=t.listingParents(u);if(f.length!==1||f[0]!==e)return false}let d=new Set(a);for(let u=l.length-1;u>=0;u-=1)d.has(l[u])&&r.delete(u,1);let c=i>0?r.toArray().indexOf(o[i-1]):-1;return r.insert(c+1,a),true}function Xu(t,e,n,o){for(let{parentId:r,shown:i,placed:s}of o)for(let a=0;a<lb;a+=1){let l=t.splitSiblings.shownChildren(r),d=l?db(i,l,s):null;if(!l||!d)break;let c=false;if(e.transact(()=>{c=cb(t,r,l,d);},n),!c)break}}var mr=class{constructor(e,n){this.knows=e;this.allocator=new gn(n);}knows;allocator;toLogical=new Map;get replicaId(){return this.allocator.replicaId}reset(){this.toLogical.clear();}mint(e){let n=this.allocator.take();return this.toLogical.set(e,n),n}resolve(e){return this.toLogical.get(e)??e}translate(e){let n=[],o=false;for(let r of e.effects){let i=this.translateEffect(r);i!==r&&(o=true),n.push(i);}return o?Object.freeze({effects:Object.freeze(n)}):e}translateEffect(e){switch(e.kind){case "putNode":{let n=this.translateDescriptor(e.descriptor);return n.logicalId===e.descriptor.logicalId?e:{...e,descriptor:n}}case "spliceText":case "setAttribute":case "setNamespaceBinding":{let n=this.resolve(e.logicalId);return n===e.logicalId?e:{...e,logicalId:n}}case "spliceChildren":{let n=this.resolve(e.parentLogicalId),o=e.childLogicalIds.map(i=>this.resolve(i));return n===e.parentLogicalId&&o.every((i,s)=>i===e.childLogicalIds[s])?e:{...e,parentLogicalId:n,childLogicalIds:o}}case "moveNode":{let n=this.resolve(e.logicalId),o=this.resolve(e.destinationParentLogicalId);return n===e.logicalId&&o===e.destinationParentLogicalId?e:{...e,logicalId:n,destinationParentLogicalId:o}}case "putXmlPart":{let n=this.resolve(e.rootLogicalId);return n===e.rootLogicalId?e:{...e,rootLogicalId:n}}default:return e}}translateDescriptor(e){let n=this.resolve(e.logicalId);return this.knows(n)?{...e,logicalId:n}:{...e,logicalId:this.mint(e.logicalId)}}};async function Gu(t,e){let n=ku(t),o=Cu(t.documentId),r=Tu(t.sessionId),i=Eu(t.identity),s=new rt(t.ydoc);try{return await fb(t,{attachWatchdogMs:n,documentId:o,sessionId:r,identity:i,registry:s},e)}catch(a){throw s.destroy(),a}}async function fb(t,e,n){let{attachWatchdogMs:o,documentId:r,sessionId:i,identity:s,registry:a}=e,l=new mr(u=>a.hasNode(u)||a.inline.owner(u)!==null),d=new gt(t.ydoc.getMap(hn));await Wu(t,a,d,r);let c=new Bt(a,d);try{let u=c.current(),f=d.poisonedDigest();if(f)throw new N("blob-digest-mismatch",f);if(!u.ok)throw new N(u.code);let p=writeOoxmlPackageKeepingRevisionIds(u.package),h=n({ydoc:t.ydoc,awareness:t.awareness,documentId:r,sessionId:i,identity:s,registry:a,materializer:c,identityMap:l,blobs:d,attachWatchdogMs:o,offlineEditing:t.offlineEditing!==!1});return Object.freeze({document:p,session:h,destroy:()=>h.destroy()})}catch(u){throw c.destroy(),u}}function gb(t){return qu(t,writeOoxmlPackage)}function NR(t){return qu(t,writeOoxmlPackageKeepingRevisionIds)}function qu(t,e){let n=new rt(t),o=null;try{if(n.schema.meta.get("initialized")!==!0||typeof n.schema.meta.get("documentId")!="string")throw new N("not-initialized");let r=new gt(t.getMap(hn));dr(n,r,t),o=new Bt(n,r);let i=o.current(),s=r.poisonedDigest();if(s)throw new N("blob-digest-mismatch",s);if(!i.ok)throw new N(i.code);let a=vt(i.issues);if(a)throw new N("materialize-dropped-content",a);if(!i.package.parts.has(i.package.mainDocumentPart))throw new N("no-main-document-part");return e(i.package)}finally{o?.destroy(),n.destroy();}}var Ib=500,Ls=class{constructor(e,n,o,r,i,s,a,l,d,c,u){this.ydoc=e;this.awareness=n;this.registry=s;this.materializer=a;this.identityMap=l;this.blobs=d;this.offlineEditing=u;this.documentId=o,this.sessionId=r,this.currentIdentity=i,this.undoManager=new z.UndoManager([...s.trackedTypes()],{trackedOrigins:new Set([this.localOrigin]),captureTimeout:Ib,deleteFilter:s.undoDeleteFilter()}),this.historyGroups=new No(this.undoManager,this),this.undoGroups=new gr(this.historyGroups,()=>this.flushPendingJournals()),this.historySelections=new tr(this.undoManager,f=>this.port?.paragraphByStableId(f)?.text??null,(f,p)=>this.caretAnchors.findStable(f,p)),this.editWait=new pr({ydoc:e,viewWaiting:()=>this.viewWaiting,nodeWaits:f=>Sd(s,this.identityMap.resolve(f)),publish:f=>this.statusState.setWaiting(f)&&this.notifyStatus()}),this.caretAnchors=new fr({registry:s,port:()=>this.port,logicalIdOf:f=>this.identityMap.resolve(f),embedOf:f=>a.builtNode(f),viewIsCurrent:()=>!this.viewWaiting}),e.on("beforeTransaction",this.onBeforeYjsTransaction),e.on("afterTransaction",this.onYjsTransaction),n.on("change",this.onAwarenessChange),this.stopBlobWatch=d.observeChanges(f=>{let p=d.verifyNow(f);p&&this.setStatus("error","blob-digest-mismatch",p);}),this.publishAwareness(),this.setStatus("ready"),this.stopSeedWatch=zu(e,()=>{this.setStatus("error","concurrent-seed");}),this.attachWatchdog=vu(this.documentId,c,()=>(this.attachWatchdog=null,this.destroyed||this.port!==null));}ydoc;awareness;registry;materializer;identityMap;blobs;offlineEditing;documentId;sessionId;currentIdentity;currentSelection;attachWatchdog=null;statusState=createCollaborationStatusTracker();statusListeners=new Set;selectionListeners=new Set;participantListeners=new Set;localOrigin=Object.freeze({kind:"docx-document-local"});caretAnchors;editWait;undoManager;port=null;detachPort=null;applyingRemote=false;viewWaiting=false;fullRefusedWhileWaiting=false;healTo=null;historySelections;remoteSelectionResolver=new ir;realignedInBatch=false;journalsHeldDuringRemote=[];drainingHeldJournals=false;remoteCounter=0;destroyed=false;pressure=new sr;refusals=new er;historyGroups;undoGroups;stopBlobWatch;stopSeedWatch;get identity(){return this.currentIdentity}clearAttachWatchdog(){this.attachWatchdog!==null&&(clearTimeout(this.attachWatchdog),this.attachWatchdog=null);}status(){return this.statusState.status()}statusSnapshot(){return this.statusState.snapshot()}resourceUsage(){return vs(this.registry,this.blobs)}subscribeResourcePressure(...e){return this.pressure.watch(this.ydoc,this.registry,this.blobs,...e)}subscribeStatus(e){return this.statusListeners.add(e),()=>this.statusListeners.delete(e)}setTransportStatus(e,n,o){if(!this.destroyed){if(this.statusState.status()==="error"&&e!=="error"){this.healTo!==null&&(this.healTo={status:e,code:n,detail:o},this.publishSharedToPort());return}if(n!==void 0){this.setStatus(e,n,o);return}this.setStatus(e);}}get attached(){return this.port!==null}attach(e){let n=this.refuseAttach(e);if(n)return n;this.clearAttachWatchdog(),e.interactive===true&&this.undoGroups.close(),this.port=e,this.publishSharedToPort();let o=e.observePrimitiveJournal(r=>{if(!this.destroyed){if(this.applyingRemote){this.journalsHeldDuringRemote.push(r);return}this.realignedInBatch||this.applyJournal(r);}});return this.detachPort=()=>{this.flushPendingJournals(),o(),this.port===e&&(this.port=null),this.detachPort=null,this.currentSelection&&this.publishAwareness();},()=>this.detachPort?.()}refuseAttach(e){return this.destroyed?()=>{}:this.port?(this.port!==e&&this.setStatus("error","port-already-attached"),()=>{}):e.documentId!==this.documentId?(this.setStatus("error","document-id-mismatch"),()=>{}):null}hasCompatibleSharedSchema(){let e=Xn(this.registry.schema.meta);return e?(this.setStatus("error",e.code,e.detail),false):true}canWriteSharedState(){if(this.destroyed||!this.hasCompatibleSharedSchema())return false;let e=this.statusState.status();return e==="ready"||this.offlineEditing&&e==="disconnected"}gateOperations(e,n){return this.destroyed?"collaboration-session-destroyed":this.canWriteSharedState()?this.port?this.editWait.refuses(e)?"collaboration-session-not-ready":this.textLimitFailure(e):"collaboration-session-not-attached":"collaboration-session-not-ready"}textLimitFailure(e){let n=this.registry.limits.maxTextLength;for(let o of e)if(o.op==="insertText"&&o.text.length>n)return "collaboration-text-limit";return null}canUndo(){return !this.undoGroups.isOpen&&this.canWriteSharedState()&&((this.port?.hasPendingJournals()??false)||this.undoManager.undoStack.length>0)}canRedo(){return !this.undoGroups.isOpen&&this.canWriteSharedState()&&this.undoManager.redoStack.length>0}undo(){return this.popHistory("undo")}historySelection(){return this.historySelections.lastRestored()}redo(){return this.popHistory("redo")}beginUndoGroup(){return this.undoGroups.begin(()=>this.destroyed,()=>this.port?.interactive===true)}get undoGroupOpen(){return this.undoGroups.isOpen}popHistory(e){if(this.undoGroups.isOpen||!this.canWriteSharedState()||(this.flushPendingJournals(),!this.canWriteSharedState())||(e==="undo"?this.undoManager.undoStack:this.undoManager.redoStack).length===0)return false;this.historyGroups.reset(),this.historySelections.noteBefore(),this.historySelections.startPop();let o=z.getState(this.ydoc.store,this.ydoc.clientID);return this.registry.takeUnlisted(),ic(this.registry,this.undoManager,e,()=>rc(this.registry,this.ydoc,o)),true}flushPendingJournals(){this.port?.flushPendingJournals();}setLocalSelection(e){if(this.destroyed)return;if(this.caretAnchors.track(e),!e){this.historySelections.track(null),this.publishAwareness();return}let{encoded:n,texts:o}=Ou(e,r=>this.port?.paragraphByStableId(r)?.text,r=>this.caretAnchors.characterOf(r));this.historySelections.track(n,o),this.publishAwareness(n);}participants(){let e=[],n=[...this.awareness.getStates().entries()].slice(0,nr);for(let[o,r]of n){let i=rr(r[pn]);i&&e.push({actorId:i.actorId,name:i.name,...i.color?{color:i.color}:{},role:i.role,isLocal:o===this.awareness.clientID});}return Object.freeze(e)}subscribeParticipants(e){return this.participantListeners.add(e),()=>this.participantListeners.delete(e)}remoteSelections(){return this.port?this.remoteSelectionResolver.resolve(this.awareness,this.port,(e,n)=>this.caretAnchors.find(e,n)):[]}subscribeRemoteSelections(e){return this.selectionListeners.add(e),()=>this.selectionListeners.delete(e)}setIdentity(e){if(this.destroyed)return;let n=e.name===void 0?this.currentIdentity.name:e.name.trim();if(n.length===0||n.length>ht)throw new N("invalid-identity");let o=this.currentIdentity.color;if(e.color!==void 0){if(e.color.length>64)throw new N("invalid-identity-color");o=safeParticipantColor(e.color);}this.currentIdentity=Object.freeze({actorId:this.currentIdentity.actorId,name:n,...o?{color:o}:{},role:this.currentIdentity.role??"human"}),this.publishAwareness(this.currentSelection);}destroy(){this.destroyed||(this.clearAttachWatchdog(),this.flushPendingJournals(),this.undoGroups.close(),this.detachPort?.(),this.destroyed=true,this.pressure.stopAll(),this.stopBlobWatch(),this.stopSeedWatch(),this.ydoc.off("beforeTransaction",this.onBeforeYjsTransaction),this.ydoc.off("afterTransaction",this.onYjsTransaction),this.awareness.off("change",this.onAwarenessChange),this.awareness.setLocalStateField(pn,null),this.historySelections.destroy(),this.undoManager.destroy(),this.materializer.destroy(),this.registry.destroy(),this.setStatus("destroyed"),this.statusListeners.clear(),this.selectionListeners.clear(),this.participantListeners.clear());}applyJournal(e){if(!this.canWriteSharedState())return;let n=this.identityMap.translate(e),o=Yd(this.materializer,n,()=>Ke(this.ydoc));if(o){this.refuseLocalJournal(o.failure,o.transient);return}this.registry.inline.takeDrift();let r=Nd(this.registry,n,this.materializer);if(!r.ok){this.refuseLocalJournal({code:r.code,...r.detail?{detail:r.detail}:{}});return}let i=r.journal,s=xu(this.port,e);if(s!==null&&s.ok===false){this.refuseLocalJournal(s.failure);return}if(!this.canWriteSharedState())return;let a=false;this.historySelections.noteBefore();let l=Hu(this.registry,i),d=()=>{let u=this.ydoc.transact(()=>{if(s!==null){let p=Su(this.blobs,s.payloads);if(p!==null)return p}let f=Ui(this.registry,i,r.plan,r.typed);return f.ok?null:(a=f.transient===true,{code:f.code,...f.detail?{detail:f.detail}:{}})},this.localOrigin);return u===null&&Xu(this.registry,this.ydoc,this.localOrigin,l),u},c=this.historyGroups.captureJournal(e,this.localOrigin,d);if(c===null){this.refusals.published(),(this.registry.inline.takeDrift()||e.effects.some(f=>f.kind!=="spliceText")&&_d(this.registry,r.plan))&&this.publishSharedToPort(false,true);return}this.refuseLocalJournal(c,a);}refuseLocalJournal(e,n=false){this.historyGroups.refused(),this.undoManager.stopCapturing();let o=this.statusState.snapshot();this.refusals.refusedOne(n);let r=this.refusals.recoverable()?bs(o):null;this.setStatus("error",e.code,e.detail,r),this.publishSharedToPort(true,true),this.realignedInBatch=true,queueMicrotask(()=>{this.realignedInBatch=false;});let i=this.statusState.snapshot().reason;this.refusals.recoverable()&&this.statusState.status()==="error"&&i!==void 0&&i.code===e.code&&i.detail===e.detail&&(o.status==="ready"||o.status==="disconnected")&&this.setStatus(o.status,o.reason?.code,o.reason?.detail);}onBeforeYjsTransaction=e=>{e.origin===this.localOrigin?this.caretAnchors.localChange():this.caretAnchors.beforeChange();};remoteSelectionMove(){return this.caretAnchors.move()}onYjsTransaction=e=>{this.destroyed||!this.hasCompatibleSharedSchema()||(this.canWriteSharedState()&&$d(e,this.registry.schema.nodes,this.undoManager),this.port&&e.origin!==this.localOrigin&&this.publishSharedToPort(false,e.origin===this.undoManager));};publishSharedToPort(e=false,n=false){let o=this.port;if(!(!o||this.applyingRemote)){this.applyingRemote=true;try{if(!this.hasCompatibleSharedSchema())return;let r=ar(this.registry,this.blobs);if(r){this.setStatus("error",r.code,r.detail);return}let i=Ke(this.ydoc);i||(this.fullRefusedWhileWaiting=!1);let s=e?this.materializer.rebuildFull():this.materializer.current(),a=this.blobs.poisonedDigest();if(a){this.setStatus("error","blob-digest-mismatch",a);return}if(this.viewWaiting=!1,!s.ok){i?this.viewWaiting=!0:this.degrade(s.code);return}let l=vt(s.issues);if(l){i?this.viewWaiting=!0:this.degrade("materialize-dropped-content",l);return}let d=f=>(this.remoteCounter+=1,o.applyRemotePackage(f,{origin:ORIGIN_IDS.mutationRemote,actorId:n?this.currentIdentity.actorId:"remote",operationId:`${this.sessionId}:remote:${this.remoteCounter}`})),c=d(s.package);if(!c.ok&&!(i&&this.fullRefusedWhileWaiting)){let f=this.materializer.rebuildFull();f.ok&&!vt(f.issues)&&(c=d(f.package)),!c.ok&&i&&(this.fullRefusedWhileWaiting=!0);}if(!c.ok){i?this.viewWaiting=!0:this.degrade("remote-apply-failed",c.reason);return}c.changed&&this.identityMap.reset(),this.caretAnchors.afterPublish();let u=this.healTo;u!==null&&this.setStatus(u.status,u.code,u.detail);}catch(r){this.degrade(r instanceof N?r.code:"remote-apply-failed",r instanceof N?r.detail:void 0);}finally{this.applyingRemote=false,this.drainJournalsHeldDuringRemote(),this.editWait.refresh();}}}drainJournalsHeldDuringRemote(){if(!this.drainingHeldJournals){this.drainingHeldJournals=true;try{for(;this.journalsHeldDuringRemote.length>0;){if(this.destroyed||this.realignedInBatch){this.journalsHeldDuringRemote.length=0;return}let e=this.journalsHeldDuringRemote.shift();e&&this.applyJournal(e);}}finally{this.drainingHeldJournals=false;}}}onAwarenessChange=()=>{if(this.destroyed)return;let e=this.remoteSelections();for(let o of [...this.selectionListeners])o(e);let n=this.participants();for(let o of [...this.participantListeners])o(n);};publishAwareness(e){this.currentSelection=e;let n={actorId:this.identity.actorId,name:this.identity.name,...this.identity.color?{color:this.identity.color}:{},role:this.identity.role??"human",...e?{selection:e}:{}};this.awareness.setLocalStateField(pn,n);}degrade(e,n){this.setStatus("error",e,n,this.healTo??bs(this.statusState.snapshot()));}setStatus(e,n,o,r=null){this.healTo=e==="error"?r:null,this.statusState.set(e,n,o,this.healTo!==null)&&this.notifyStatus();}notifyStatus(){let e=this.statusState.snapshot();for(let n of [...this.statusListeners])n(e.status,e.reason?.code,e.reason?.detail);}};async function fO(t){return Gu(t,e=>new Ls(e.ydoc,e.awareness,e.documentId,e.sessionId,e.identity,e.registry,e.materializer,e.identityMap,e.blobs,e.attachWatchdogMs,e.offlineEditing))}
|
|
16
|
-
export{
|
|
15
|
+
${o.localName}`)!==o.value)return false;return t.localName===e.localName&&t.kind===e.kind}function hs(t,e){let n=e.size;e.add(U(t));let o=e.size!==n;if(t.kind==="textValue")return o;for(let r of t.children)hs(r,e)||(o=false);return o}function Jc(t,e,n,o){for(let r of e){let i=n.get(r);for(let s=0;i!==void 0&&s<o;s++)t.add(i),i=n.get(i);}}function Hc(t,e){let n=new Set(e),o=[...e],r=i=>{n.has(i)||(n.add(i),o.push(i));};for(;o.length>0;){let i=o.pop(),s=t.isTombstoned(i)?t.replacedByOf(i):null;s!==null&&r(s);let a=t.listingParents(i),l=t.parentOf(i);for(let d of l===null?a:[l,...a]){r(d);let c=t.isTombstoned(d)?t.replacedByOf(d):null;c!==null&&r(c);}}return n}var Jo="http://schemas.openxmlformats.org/package/2006/relationships",Vm="application/vnd.openxmlformats-package.relationships+xml",Xc=/^(.*)\/_rels\/([^/]*)\.rels$/;function Ho(t){return Xc.test(t)}function Gc(t){let e=Xc.exec(t);return e?e[2]===""?"/":`${e[1]}/${e[2]}`:null}function Vo(t,e){return Object.freeze({kind:"genericExtension",namespaceUri:"",localName:t,value:e})}function Jm(t,e){let n=[Vo("Id",e.id),Vo("Type",e.type),Vo("Target",e.rawTarget)];return e.targetMode==="External"&&n.push(Vo("TargetMode","External")),Object.freeze(De({id:t,kind:"generic",namespaceUri:Jo,localName:"Relationship",namespaceBindings:Object.freeze([]),attributes:Object.freeze(n),children:Object.freeze([])}))}function qc(t,e){if(t.kind==="textValue"||t.namespaceUri!==Jo||t.localName!=="Relationship"||Fe(t,"Id")!==e.id||Fe(t,"Type")!==e.type||Fe(t,"Target")!==e.rawTarget)return false;let n=Fe(t,"TargetMode");return e.targetMode==="External"?n==="External":n===void 0}function Qc(t,e){return t.children.length!==e.length?false:t.children.every((n,o)=>qc(n,e[o]))}function Zc(t,e){if(t.id!==e.id||t.kind!==e.kind||t.namespaceUri!==e.namespaceUri||t.localName!==e.localName||t.prefix!==e.prefix||t.attributes.length!==e.attributes.length)return false;for(let n=0;n<t.attributes.length;n+=1){let o=t.attributes[n],r=e.attributes[n];if(o.namespaceUri!==r.namespaceUri||o.localName!==r.localName||o.value!==r.value||o.prefix!==r.prefix)return false}return t.namespaceBindings.length!==e.namespaceBindings.length?false:t.namespaceBindings.every((n,o)=>{let r=e.namespaceBindings[o];return n.prefix===r.prefix&&n.namespaceUri===r.namespaceUri})}function eu(t,e,n){let o=[];for(let r of e){if(E(r.id))continue;let i=t.find(a=>a.kind!=="textValue"&&Fe(a,"Id")===r.id);if(i&&qc(i,r)){o.push(i);continue}let s=i&&i.kind!=="textValue"?U(i):`${n}#rel-${r.id}`;E(s)||o.push(Jm(s,r));}return o}function Hm(t){return Object.freeze(De({id:`${t}#root`,kind:"generic",namespaceUri:Jo,localName:"Relationships",namespaceBindings:Object.freeze([Object.freeze({prefix:"",namespaceUri:Jo})]),attributes:Object.freeze([]),children:Object.freeze([])}))}function tu(t){return Object.freeze({id:t,name:t,contentType:Vm,root:Hm(t)})}function nu(t){let e=new Map;for(let n of t){if(E(n.id)||n.ownerPart!=="/"&&Ie(n.ownerPart))continue;let o=e.get(n.ownerPart)??[];o.push(n),e.set(n.ownerPart,o);}return e}var su=/^\/customXml\/item(\d+)\.xml$/i,Qm=/^\/customXml\/itemProps(\d+)\.xml$/i;function Fn(t){return su.test(t)}function ms(t){return Qm.test(t)}function Zm(t){let e=su.exec(t);if(!e)return null;let n=Number(e[1]);return Number.isSafeInteger(n)&&n>0?n:null}function ou(t){return {item:`/customXml/item${String(t)}.xml`,props:`/customXml/itemProps${String(t)}.xml`}}function ey(t,e,n){let o=t.attributes.find(r=>r.localName===e&&r.namespaceUri===n);return o&&o.value.length>0?o.value:null}function ru(t,e){let n=t.record(e);return !n||!W(n)?e:n.attributes.find(r=>r.localName==="id"&&r.value.length>0)?.value??e}function ty(t,e){let n=t.record(e);if(!n||!W(n))return null;for(let o of n.childIds){let r=t.record(o);if(!(!r||!W(r)||r.localName!=="schemaRefs")&&r.namespaceUri===DATASTORE_NAMESPACE_URI)for(let i of r.childIds){let s=t.record(i);if(!s||!W(s)||s.localName!=="schemaRef")continue;let a=ey(s,"uri",DATASTORE_NAMESPACE_URI);if(a)return a}}return null}function ny(t,e){return e.childIds.some(n=>{let o=t.record(n);return !!o&&W(o)&&o.localName==="node"&&o.namespaceUri===e.namespaceUri})}function oy(t,e){return e.localName==="node"||e.namespaceUri===WML_NAMESPACE_URI||e.namespaceUri===DATASTORE_NAMESPACE_URI||e.namespaceUri.length===0||t.parentOf(e.logicalId)!==null?false:ny(t,e)}function ry(t,e){return e.localName!=="datastoreItem"||e.namespaceUri!==DATASTORE_NAMESPACE_URI?false:t.parentOf(e.logicalId)===null}function au(t,e){if(!t.hasNamespace(DATASTORE_NAMESPACE_URI))return [];let n=new Map,o=new Map;for(let[f,p]of e){let h=t.record(U(p.root));!h||!W(h)||(Fn(f)&&n.set(h.logicalId,h),ms(f)&&o.set(h.logicalId,h));}for(let f of t.allLogicalIds()){if(t.isTombstoned(f)||n.has(f)||o.has(f))continue;let p=t.record(f);!p||!W(p)||(oy(t,p)?n.set(f,p):ry(t,p)&&o.set(f,p));}if(n.size===0)return [];let r=new Map;for(let f of n.values()){let p=r.get(f.namespaceUri)??[];p.push(f),r.set(f.namespaceUri,p);}let i=new Map;for(let f of o.values()){let p=ty(t,f.logicalId);if(!p)continue;let h=i.get(p)??[];h.push(f),i.set(p,h);}let s=[];for(let[f,p]of r){let h=i.get(f);if(!h||h.length===0)continue;p.sort((I,b)=>I.logicalId.localeCompare(b.logicalId)),h.sort((I,b)=>I.logicalId.localeCompare(b.logicalId));let g=p[0],y=h[0],w=[],S=new Set;for(let I of p)for(let b of I.childIds){if(S.has(b))continue;let v=t.record(b);!v||!W(v)||v.localName!=="node"||v.namespaceUri!==f||(S.add(b),w.push(b));}for(let I of t.allLogicalIds()){if(S.has(I)||t.isTombstoned(I))continue;let b=t.record(I);!b||!W(b)||b.localName!=="node"||b.namespaceUri!==f||(S.add(I),w.push(I));}w.sort((I,b)=>ru(t,I).localeCompare(ru(t,b))),s.push({data:g,props:y,nodeIds:w});}s.sort((f,p)=>f.data.logicalId.localeCompare(p.data.logicalId));let a=new Set,l=[],d=new Set,c=new Set;for(let[f,p]of e){let h=Zm(f);if(h===null)continue;let g=s.find(S=>S.data.logicalId===p.root.id&&!d.has(S.data.logicalId));if(!g)continue;let y=ou(h).props,w=e.get(y);w&&w.root.id!==g.props.logicalId||(a.add(h),d.add(g.data.logicalId),c.add(g.props.logicalId),l.push({dataRootId:g.data.logicalId,propsRootId:g.props.logicalId,namespaceUri:g.data.namespaceUri,itemName:f,propsName:y,nodeIds:g.nodeIds}));}let u=1;for(let f of s){if(d.has(f.data.logicalId))continue;for(;a.has(u);)u+=1;a.add(u);let p=ou(u);l.push({dataRootId:f.data.logicalId,propsRootId:f.props.logicalId,namespaceUri:f.data.namespaceUri,itemName:p.item,propsName:p.props,nodeIds:f.nodeIds}),u+=1;}return l.sort((f,p)=>f.itemName.localeCompare(p.itemName)),l}function iy(t){return t.type===CUSTOM_XML_REL||t.type===CUSTOM_XML_PROPS_REL?true:Fn(t.ownerPart)}function sy(t){let e=/^rId(\d+)$/.exec(t);if(!e)return 0;let n=Number(e[1]);return Number.isSafeInteger(n)?n:0}function ay(t,e){let n=t.split("/").slice(1,-1),o=e.split("/").slice(1),r=0;for(;r<n.length&&r<o.length-1&&n[r]===o[r];)r+=1;return `${"../".repeat(n.length-r)}${o.slice(r).join("/")}`}function lu(t,e){if(e.length===0)return [];let n=t.mainDocumentPart();if(!n)return [];let o=t.relationships(),r=o.filter(a=>a.ownerPart===n&&a.type===CUSTOM_XML_REL).sort((a,l)=>a.id.localeCompare(l.id)),i=0;for(let a of o)i=Math.max(i,sy(a.id));let s=[];for(let a=0;a<e.length;a+=1){let l=e[a],d=r[a],c=d?.id??`rId${String(i+=1)}`;s.push({ownerPart:n,id:c,type:CUSTOM_XML_REL,rawTarget:ay(n,l.itemName),targetMode:"Internal",order:d?.order??a}),s.push({ownerPart:l.itemName,id:"rId1",type:CUSTOM_XML_PROPS_REL,rawTarget:l.propsName.slice(l.propsName.lastIndexOf("/")+1),targetMode:"Internal",order:0});}return s}function du(t,e){return e.length===0?[...t]:[...t.filter(n=>!iy(n)),...e]}function cu(t){let e=new Map;for(let n of t)e.set(partNameKey(n.propsName),CUSTOM_XML_PROPS_TYPE);return e}function ys(t,e){if(e.length===0)return false;let n=[...t.keys()].filter(Fn).sort(),o=e.map(r=>r.itemName).sort();if(n.length!==o.length||n.some((r,i)=>r!==o[i]))return true;for(let r of e){let i=t.get(r.itemName),s=t.get(r.propsName);if(!i||i.root.id!==r.dataRootId||!s||s.root.id!==r.propsRootId)return true}return false}function uu(t,e){if(ys(t,e))return true;for(let n of e){let o=t.get(n.itemName);if(!o)return true;let r=new Set(o.root.children.map(a=>a.id));if(n.nodeIds.some(a=>!r.has(a)))return true;let i=[];for(let a of o.root.children)a.kind!=="textValue"&&i.push(a.attributes.find(l=>l.localName==="id")?.value??a.id);let s=[...i].sort((a,l)=>a.localeCompare(l));if(i.some((a,l)=>a!==s[l]))return true}return false}var ly="http://schemas.microsoft.com/office/word/2012/wordml";function Xo(t){let e=Number(t);return t===void 0||t.length===0||!Number.isSafeInteger(e)?`2${t??""}`:`${e<0?"0":"1"}${String(Math.abs(e)).padStart(12,"0")}`}function fu(t){return e=>e.localName===t&&e.namespaceUri===WML_NAMESPACE_URI}function dy(t){return t.localName==="abstractNum"?`0${Xo(Fe(t,"abstractNumId"))}`:`1${Xo(Fe(t,"numId"))}`}function cy(t){return t.namespaceUri!==WML_NAMESPACE_URI?false:t.localName==="abstractNum"||t.localName==="num"}function bs(t){return t.localName==="comments"?{isMember:e=>e.kind==="comment",sortKey:e=>e.id,adoptedAfterListed:true}:t.localName==="commentsEx"?{isMember:e=>e.localName==="commentEx"&&e.namespaceUri===ly,sortKey:e=>e.id,adoptedAfterListed:true}:t.localName==="footnotes"&&t.namespaceUri===WML_NAMESPACE_URI?{isMember:fu("footnote"),sortKey:e=>Xo(Fe(e,"id"))}:t.localName==="endnotes"&&t.namespaceUri===WML_NAMESPACE_URI?{isMember:fu("endnote"),sortKey:e=>Xo(Fe(e,"id"))}:t.localName==="numbering"&&t.namespaceUri===WML_NAMESPACE_URI?{isMember:cy,sortKey:dy}:null}function pu(t,e){for(let n of t)if(n.root.id===e)return bs(n.root)?n.root.children.map(U):null;return null}function hu(t,e){let n=null;for(let o of t.listingParents(e)){let r=t.record(o);if(!(!r||!W(r)||!r.childIds.includes(e))&&(t.isTombstoned(o)||t.listingParents(o).length>0||(n??=new Set(t.partEntries().map(i=>i.rootLogicalId)),n.has(o))))return true}return false}function gu(t,e,n){let o=t.record(n),r=!!o&&(kt(o)?o.value.length>0:o.childIds.length>0||o.attributes.length>0);e(r?"orphan-with-content":"orphan",n);}function mu(t,e,n,o,r,i){if(!r){for(let l of n)t.isTombstoned(l)||o.has(l)||(gu(t,e,l),i.add(l));return}let s=new Set(t.partEntries().map(l=>l.rootLogicalId)),a=new Set;for(let l of n)a.has(l)||(a.add(l),uy(t,e,l,o,s)&&i.add(l));}function uy(t,e,n,o,r){let i=false,s=new Set,a=[{id:n,underTombstone:false}];for(;a.length>0;){let{id:l,underTombstone:d}=a.pop();if(!(s.has(l)||s.size>=t.limits.maxTreeDepth)){if(s.add(l),t.isTombstoned(l)){let c=t.record(l);if(c&&W(c))for(let u of c.childIds)a.push({id:u,underTombstone:true});continue}r.has(l)||(d?o.has(l):hu(t,l))||(gu(t,e,l),i=true);}}return i}function yu(t,e,n,o,r,i,s,a,l){let d=0;for(let c of a){if(i.has(c)||o.has(c)||t.isTombstoned(c)||Gn(t.schema.nodes.get(c))||s&&hu(t,c))continue;let u=t.record(c);if(!u||!W(u)||!r(u))continue;let f=e(c);!f||f.kind==="textValue"||(n.push(f),o.add(c),l.add(c),d+=1);}return d}var pt="application/vnd.openxmlformats-officedocument.wordprocessingml",gy=new Map(Object.entries({comments:{root:"comments",contentType:`${pt}.comments+xml`},commentsExtended:{root:"commentsEx",contentType:`${pt}.commentsExtended+xml`},commentsIds:{root:"commentsIds",contentType:`${pt}.commentsIds+xml`},commentsExtensible:{root:"commentsExtensible",contentType:`${pt}.commentsExtensible+xml`},people:{root:"people",contentType:`${pt}.people+xml`},footnotes:{root:"footnotes",contentType:`${pt}.footnotes+xml`},endnotes:{root:"endnotes",contentType:`${pt}.endnotes+xml`},numbering:{root:"numbering",contentType:`${pt}.numbering+xml`}}));function my(t){return Ie(t)===null&&!Ho(t)&&t.toLowerCase()!=="/[content_types].xml"&&t.toLowerCase().endsWith(".xml")}function bu(t,e,n){let o=new Set(e.map(d=>d.name)),r=[];for(let d of n){if(d.targetMode==="External"||!o.has(d.ownerPart))continue;let c=gy.get(d.type.slice(d.type.lastIndexOf("/")+1));if(!c)continue;let u=resolveInternalTarget(d.ownerPart,d.rawTarget);!u.ok||o.has(u.partName)||!my(u.partName)||(o.add(u.partName),r.push({name:u.partName,...c}));}if(r.length===0)return [];let i=new Set(e.map(d=>d.rootLogicalId)),s=new Set(r.map(d=>d.root)),a=[];for(let d of t.allLogicalIds()){if(i.has(d)||t.isTombstoned(d)||t.parentOf(d)!==null)continue;let c=t.record(d);!c||!W(c)||!s.has(c.localName)||c.bindings.some(u=>u.prefix===(c.prefix??""))&&a.push({id:d,root:c.localName,empty:c.childIds.length===0});}let l=[];for(let d of r){let c=null;for(let{id:u,root:f,empty:p}of a)f!==d.root||i.has(u)||(c===null||c.empty&&!p||c.empty===p&&u<c.id)&&(c={id:u,empty:p});c!==null&&(i.add(c.id),l.push({name:d.name,id:d.name,rootLogicalId:c.id,contentType:d.contentType}));}return l}function Iu(t,e,n){for(let[o,r]of t){let i=resolveContentType(e,o);i.ok&&(i.source==="override"||i.contentType===r.contentType)||n.set(partNameKey(o),r.contentType);}}var Go=class{constructor(e){this.registry=e;}registry;decoded=null;merged=null;grouped=null;assembly=null;defaults=null;overrides=null;partBytes=null;blobBytes=new Map;invalidate(){this.decoded=null,this.merged=null,this.grouped=null,this.assembly=null,this.defaults=null,this.overrides=null,this.partBytes=null;}projected(e){return this.decoded||(this.decoded=this.registry.relationships(),this.merged=null),(!this.merged||this.merged.custom!==e)&&(this.merged={custom:e,records:e.length===0?this.decoded:du(this.decoded,e)}),this.merged.records}groupedByOwner(e){let n=this.projected(e);return (!this.grouped||this.grouped.records!==n)&&(this.grouped={records:n,map:nu(n)}),this.grouped.map}relationshipAssembly(e){let n=this.projected(e);return (!this.assembly||this.assembly.records!==n)&&(this.assembly={records:n,value:Iy(n)}),this.assembly.value}contentTypeDefaults(){return this.defaults??=this.registry.contentTypeDefaults()}contentTypeOverrides(){return this.overrides??=this.registry.contentTypeOverrides()}resolvePartBytes(e){if(this.partBytes)return this.partBytes;let n=new Map,o=new Set;for(let r of this.registry.binaries()){o.add(r.storageKey);let i=this.blobBytes.get(r.storageKey);if(i&&i.digest===r.digest){n.set(r.storageKey,i.bytes);continue}let s=e.get(r.digest);if(!s)return null;Wc(s.length),this.blobBytes.set(r.storageKey,{digest:r.digest,bytes:s}),n.set(r.storageKey,s);}for(let r of [...this.blobBytes.keys()])o.has(r)||this.blobBytes.delete(r);return this.partBytes=n,n}};function Iy(t){let e=buildRelationshipSet(t);if(!e.ok)return null;let n=[];for(let o of t){let r=resolveRelationship(o);r.mode==="External"&&n.push({ownerPart:o.ownerPart,id:o.id,type:o.type,rawTarget:o.rawTarget,sinkSafe:r.sinkSafe.ok});}return {byOwner:e.byOwner,externalTargets:Object.freeze(n)}}var qo=class{textOverlays=new Map;losers=new Set;awaiting=new Set;update(e){let n=[],o=e.replacementLoserRuns(),r=s=>{n.push(s);let a=e.parentOf(s);a!==null&&n.push(a);};for(let s of o)this.losers.has(s)||r(s);for(let s of this.losers)o.has(s)||r(s);this.losers=o;let i=e.concurrentSplitTextOverlays();return this.textOverlays=i.values,this.awaiting=i.awaiting,n.push(...i.changedIds),n}textValue(e,n){return this.textOverlays.get(e)??n}};function xu(t,e){let n=t.children;for(let i of n){let s=U(i);if(e.placed.has(s)||!e.isCached(i)||e.dirty.has(s)&&!e.canRebuild(s))return null}let o=null,r=[];for(let i=0;i<n.length;i+=1){let s=n[i],a=U(s);if(!e.dirty.has(a)){e.placed.add(a),o?.push(s);continue}let l=e.rebuild(a);if(l===s){o?.push(s);continue}o??=n.slice(0,i),l?o.push(l):r.push(a);}return {children:o?Object.freeze(o):n,dropped:r}}var Qo=class{nodes=new Map;heights=new Map;complete=new Set;get(e){return this.nodes.get(e)}holds(e){return this.nodes.get(U(e))===e}remember(e,n){this.nodes.set(e,n),this.heights.delete(e),this.complete.delete(e);}markComplete(e,n){n?this.complete.add(e):this.complete.delete(e);}isComplete(e){return this.complete.has(e)}forget(e){this.nodes.delete(e),this.heights.delete(e),this.complete.delete(e);}evictSubtree(e,n,o){let r=this.nodes.get(e);if(this.forget(e),o(e),!(!r||r.kind==="textValue"))for(let i of r.children){let s=U(i);n.has(s)||this.evictSubtree(s,n,o);}}heightOf(e){let n=this.heights.get(U(e));if(n!==void 0)return n;let o=1;if(e.kind!=="textValue")for(let r of e.children)o=Math.max(o,this.heightOf(r)+1);return this.heights.set(U(e),o),o}setHeight(e,n){this.heights.set(e,n);}ids(){return [...this.nodes.keys()]}};function Su(t){let e=new Set,n=[];for(let o of t){let r=`${o.code}${o.logicalId??""}`;e.has(r)||(e.add(r),n.push(o));}return n}var xy=4096,Zo=class{constructor(e){this.registry=e;}registry;contested=false;matchesResolution=true;encountered=new Set;lastResolution=new Map;embedsMet=new Set;embedWinners=new Map;embedsDecidedAt=-1;reset(){this.contested=false,this.encountered.clear(),this.matchesResolution=true;}note(e,n,o,r){let i=this.registry,s=i.listingParents(e),a=s.length<=1?s:s.filter(l=>i.isTombstoned(l)?i.replacedByOf(l)!==null:r.has(l)||i.listingParents(l).length>0);a.length<=1||(this.contested=true,this.encountered.add(e),a.some(l=>i.isTombstoned(l)&&i.replacedByOf(l)!==null)?this.matchesResolution=false:!o.has(e)&&i.parentOf(e)!==n&&(this.matchesResolution=false));}noteEmbed(e,n,o,r){let i=o.get(e);return i===void 0||i===n||r.has(i)?true:this.embedWinners.get(e)===i&&this.embedsDecidedAt===this.registry.structureVersion?false:(this.contested=true,this.matchesResolution=false,this.embedsMet.add(e),true)}recordEmbeds(e){this.embedsDecidedAt!==this.registry.structureVersion&&this.embedWinners.clear(),this.embedsDecidedAt=this.registry.structureVersion;for(let n of this.embedsMet){let o=e.get(n);o===void 0?this.embedWinners.delete(n):this.embedWinners.set(n,o);}this.embedsMet.clear(),this.embedWinners.size>xy&&this.embedWinners.clear();}decided(){if(!this.matchesResolution)return false;for(let e of this.encountered){let n=this.lastResolution.get(e);if(n===void 0||n!==this.registry.parentOf(e))return false}return true}record(e){let n=new Map;for(let o of this.encountered)n.set(o,this.registry.parentOf(o));for(let o of e)n.set(o,this.registry.parentOf(o));this.lastResolution=n;}};var er=class{lastAdoption=new Map;changes(e){let n=[],o=new Map,r=(i,s)=>{let a=new Set(s);for(let l of i)if(!a.has(l))for(let d of e.listingParents(l))e.isTombstoned(d)||n.push(d);};for(let[i,s]of e.adoptionIndex()){let a=e.isTombstoned(i)?[]:[...s];o.set(i,a);let l=this.lastAdoption.get(i);(l===void 0||!Qn(l,a))&&(n.push(i),l&&r(l,a));}for(let[i,s]of this.lastAdoption)o.has(i)||(n.push(i),r(s,[]));return this.lastAdoption=o,n}};var Ut=class{constructor(e,n){this.registry=e;this.blobs=n;this.packageCache=new Go(e),this.contests=new Zo(e),this.stop=e.observeDirty(o=>{for(let r of o.logicalIds)this.pendingDirty.add(r);o.membershipChanged&&(this.pendingMembership=true),o.packageChanged&&(this.pendingPackage=true);});}registry;blobs;cache=new Qo;partCache=new Map;packageCache;relsProjection=new Map;pendingDirty=new Set;pendingMembership=false;pendingPackage=false;lastDirty=new Set;rawDirty=new Set;shownUnder=new Map;partRoots=new Set;forceFull=false;adoption=new er;mergeSources=new Map;builtMerges=new Map;contests;splitProjection=new qo;claimsWholeSubtrees=true;lastDuplicateParents=[];droppedChildren=new Set;looseCandidates=new Set;pkg=null;customXmlRels=[];customXmlOverrides=new Map;stop;issues=[];destroy(){this.stop();}dirtyLogicalIds(){return this.lastDirty}current(){return this.pkg&&this.pendingDirty.size===0&&!this.pendingPackage&&!this.pendingMembership?{ok:true,package:this.pkg,issues:[...this.issues]}:this.rebuild()}rebuildFull(){this.forceFull=true;try{return this.rebuild()}finally{this.forceFull=false;}}rebuild(){let e=new Set(this.pendingDirty),n=this.pendingPackage;this.pendingDirty.clear(),this.pendingMembership=false,this.pendingPackage=false;let o=this.registry.hasUnobservedWrites();o&&this.registry.rebuildDerivedIndexes(),(n||o)&&this.packageCache.invalidate();for(let c of this.adoption.changes(this.registry))e.add(c);for(let c of this.registry.inline.takeAffected())e.add(c);for(let c of this.registry.takeReparented())e.add(c);for(let c of [...e]){if(!this.registry.isTombstoned(c))continue;let u=this.registry.record(c);if(!(!u||!W(u)))for(let f of u.childIds)for(let p of this.registry.listingParents(f))e.add(p);}for(let c of this.splitProjection.update(this.registry))e.add(c);dl(this.registry,e);let r=Hc(this.registry,e);Jc(r,e,this.shownUnder,this.registry.limits.maxTreeDepth);let i=this.partRoots=new Set(this.registry.partEntries().map(c=>c.rootLogicalId)),s=[...e].some(c=>i.has(c)||this.registry.parentOf(c)===null&&!this.registry.isTombstoned(c)),a=!this.forceFull&&this.pkg!==null&&!o&&!s&&(r.size>0||n);this.rawDirty=e;let l=this.materializePass(r,n,a);if(!this.contests.contested)return l;if(l.ok&&this.contests.decided())return {ok:true,package:l.package,issues:Su(l.issues)};let d=this.materializePass(r,n,false);return this.contests.record(this.lastDuplicateParents),this.contests.recordEmbeds(this.shownUnder),d}materializePass(e,n,o){if(this.issues.length=0,this.lastDirty=e,this.contests.reset(),this.claimsWholeSubtrees=!o,this.droppedChildren.clear(),o)for(let f of this.lastDuplicateParents)this.push("duplicate-parent",f);this.customXmlRels=[],this.customXmlOverrides.clear();let r=new Set,i=new Map,s=this.registry.partEntries(),a=[...this.packageCache.groupedByOwner(this.customXmlRels).values()].flat();for(let f of [...s,...bu(this.registry,s,a)]){let p=new Set,h=this.materialize(f.rootLogicalId,r,p,o);if(!h||h.kind==="textValue")return {ok:false,code:"missing-root",issues:[...this.issues]};let g=this.partCache.get(f.name);if(g&&g.root===h&&g.contentType===f.contentType){i.set(f.name,g);continue}let y=Object.freeze({id:f.id||f.name,name:f.name,contentType:f.contentType,root:h});i.set(f.name,y),this.partCache.set(f.name,y);}let l=this.registry.history.takeMarkChanges(),d=o?new Set([...this.droppedChildren,...this.looseCandidates,...l]):this.registry.allLogicalIds(),c=new Set;this.projectRelsParts(i),this.adoptOrphanPartMembers(i,r,o,d,c),this.applyCustomXmlStores(i,r,o);for(let f of [...this.partCache.keys()])i.has(f)||this.partCache.delete(f);for(let f of [...this.relsProjection.keys()])i.has(f)||this.relsProjection.delete(f);this.evictDeadSubtrees(r);for(let f of e)r.has(f)||this.cache.forget(f);mu(this.registry,this.pushIssue,d,r,o,c),this.looseCandidates=c,o||(this.lastDuplicateParents=this.issues.flatMap(f=>f.code==="duplicate-parent"&&f.logicalId!==void 0?[f.logicalId]:[]));let u=this.assemblePackage(i);return u.ok?this.pkg&&!n&&this.pkg.parts.size===i.size&&[...i].every(([f,p])=>this.pkg?.parts.get(f)===p)?{ok:true,package:this.pkg,issues:[...this.issues]}:(this.pkg=u.package,{ok:true,package:this.pkg,issues:[...this.issues]}):u}push(e,n){this.issues.push(n?{code:e,logicalId:n}:{code:e});}pushIssue=(e,n)=>this.push(e,n);materialize(e,n,o,r){if(o.has(e)||o.size>=this.registry.limits.maxTreeDepth)return this.push("cycle",e),null;if(n.has(e))return this.push("duplicate-parent",e),null;let i=this.mergeSources.get(e)?.join("")??"";if(r&&!this.lastDirty.has(e)&&i===(this.builtMerges.get(e)??"")){let m=this.cache.get(e);if(m&&o.size+this.cache.heightOf(m)<=this.registry.limits.maxTreeDepth)return this.claimsWholeSubtrees?hs(m,n)||(this.contests.contested=true):n.add(U(m)),m}if(this.registry.isTombstoned(e))return null;let s=r?this.rebuildSpine(e,n,o):null;if(s)return s;n.add(e);let a=this.registry.record(e);if(!a)return this.push("missing-node",e),null;if(kt(a)){if(this.splitProjection.awaiting.has(e))return null;let m=this.splitProjection.textValue(e,a.value),k=this.cache.get(e);if(k?.kind==="textValue"&&k.value===m)return k;let O=Kc(e,m);return this.cache.remember(e,O),O}o.add(e);let l=this.issues.length,d=new Set,c=at(this.registry).shownChildIds(e,a.childIds),u=new Set(c),f=m=>{u.has(m)||(u.add(m),c.push(m));};for(let m of this.registry.adoptedChildren(e))f(m);for(let m of this.mergeSources.get(e)??[]){let k=this.registry.record(m);if(!(!k||!W(k)))for(let O of k.childIds)f(O);}i?this.builtMerges.set(e,i):this.builtMerges.delete(e);let p=this.splitProjection.losers,h=p.size===0?null:To(c,m=>p.has(m),m=>this.registry.splitLineageOf(m));h&&(c=h.map(m=>c[m]));let g=_n(c,this.registry.splitSiblings.ranksOf(e));g&&(c=g.map(m=>c[m]));let y=[],w=al(a,c,m=>this.splitProjection.losers.has(m)?null:et(this.registry,m));for(let m of w.hidden)n.add(m);for(let m of c)this.mergeSources.delete(m);for(let[m,k]of w.merges??[]){this.mergeSources.set(m,k);for(let O of k)this.shownUnder.set(O,m);}for(let m of w.shown){if(m===e){this.push("self-child",m);continue}if(d.has(m)){this.push("duplicate-child",m);continue}if(d.add(m),this.registry.isTombstoned(m)){this.push("deleted-referenced",m);continue}if(this.splitProjection.losers.has(m)){n.add(m);continue}if(E(m)||!this.registry.hasNode(m)){(E(m)||ea(this.registry.schema.nodes,m))&&this.push("child-id-not-in-registry",m);continue}this.claimsWholeSubtrees||this.contests.note(m,e,n,this.partRoots);let k=this.materialize(m,n,o,r);k&&(y.push(k),this.shownUnder.set(U(k),e));}let S=w.hidden.length===0&&y.length===w.shown.length&&this.issues.length===l,I=this.registry.inline.textOf(e);if(I){let m=j=>{if(!this.registry.hasNode(j)&&Ve(this.registry.doc)||this.registry.listingParents(j).length>0||this.partRoots.has(j)||!this.claimsWholeSubtrees&&!this.contests.noteEmbed(j,e,this.shownUnder,this.lastDirty))return null;let K=this.materialize(j,n,o,r);return K&&this.shownUnder.set(j,e),K},k=this.registry.inline.viewOf(e),O=Ze(e,I,m,this.registry.limits,k),P=this.cache.get(e);y.push(...Ha(P?.kind==="textValue"?[]:P?.children??[],O));}o.delete(e);let b=this.cache.get(e);if(b&&b.kind!=="textValue"&&b.children.length===y.length&&b.children.every((m,k)=>m===y[k])&&Vc(b,a))return this.cache.markComplete(e,S),b;let v=b&&b.kind!=="textValue"?b.children:[];this.recordDroppedChildren(v,y);let L=Ko(a,Bn(v,y),b);return this.cache.remember(e,L),this.cache.markComplete(e,S),L}rebuildSpine(e,n,o){let r=this.cache.get(e);if(!r||r.kind==="textValue"||this.rawDirty.has(e)||!this.cache.isComplete(e)||si(r)||this.builtMerges.has(e)||this.mergeSources.has(e)||this.splitProjection.losers.size>0||this.registry.adoptedChildren(e).length>0)return null;let i=this.cache.heightOf(r);if(o.size+i>this.registry.limits.maxTreeDepth)return null;let s=this.issues.length;o.add(e);let a=xu(r,{dirty:this.lastDirty,placed:n,isCached:u=>this.cache.holds(u),canRebuild:u=>E(u)||this.registry.isTombstoned(u)||!this.registry.hasNode(u)?false:(this.contests.note(u,e,n,this.partRoots),true),rebuild:u=>{let f=this.materialize(u,n,o,true);return f&&this.shownUnder.set(U(f),e),f}});if(o.delete(e),!a)return null;n.add(e);let l=a.dropped.length===0&&this.issues.length===s;if(a.children===r.children)return this.cache.markComplete(e,l),r;for(let u of a.dropped)this.droppedChildren.add(u);let d=Object.freeze(qe(r,a.children));this.cache.remember(e,d),this.cache.markComplete(e,l);let c=i;for(let u of a.children)this.lastDirty.has(U(u))&&(c=Math.max(c,this.cache.heightOf(u)+1));return this.cache.setHeight(e,c),d}recordDroppedChildren(e,n){if(e.length===0)return;let o=new Set(n.map(r=>r.id));for(let r of e)o.has(r.id)||this.droppedChildren.add(U(r));}evictDeadSubtrees(e){for(let n of this.droppedChildren)e.has(n)||(this.registry.isTombstoned(n)||!this.registry.hasNode(n))&&this.cache.evictSubtree(n,e,o=>this.shownUnder.delete(o));}retainedNodeIds(){return this.cache.ids()}projectRelsParts(e){let n=this.packageCache.groupedByOwner(this.customXmlRels),o=new Set;for(let[r,i]of n){let s=relsPartNameFor(r);if(s!=="/_rels/.rels"&&Ie(s))continue;o.add(s);let a=this.projectOneRelsPart(s,e.get(s),i);a&&(e.set(s,a),this.partCache.set(s,a));}for(let[r,i]of e){if(o.has(r)||!Ho(r))continue;let s=Gc(r);if(s===null)continue;let a=this.projectOneRelsPart(r,i,n.get(s)??[]);!a||a===i||(e.set(r,a),this.partCache.set(r,a));}}projectOneRelsPart(e,n,o){if(!n&&o.length===0)return this.relsProjection.delete(e),null;let r=this.relsProjection.get(e),s=!!r&&(!n||Zc(r.root,n.root))&&r?r:n??tu(e);if(Qc(s.root,o))return this.relsProjection.set(e,s),s;let a=s.root.children,l=Fc(s,eu(a,o,e));return this.relsProjection.set(e,l),l}builtNode(e){return this.cache.get(e)??null}shownParentOf(e){return this.shownUnder.get(e)??null}shownPartChildren(e){return pu(this.partCache.values(),e)}adoptOrphanPartMembers(e,n,o,r,i){for(let[s,a]of e){let l=bs(a.root);if(!l)continue;let d=L=>L.logicalId!==a.root.id&&l.isMember(L),c=[],u=new Set,f=new Set,p=this.registry.record(U(a.root)),h=new Set(p&&W(p)?p.childIds:[]);for(let L of a.root.children){if(L.kind==="textValue")continue;let m=U(L);if(this.registry.isTombstoned(m)||!h.has(m)&&(Gn(this.registry.schema.nodes.get(m))||this.registry.listingParents(m).length>0)){f.add(m);continue}let k=this.registry.record(U(L));!k||!W(k)||!d(k)||(c.push(L),u.add(U(L)));}let g=yu(this.registry,L=>this.materialize(L,n,new Set,o),c,u,d,n,o,r,i);if(g===0&&f.size===0)continue;let y=(L,m)=>l.sortKey(L).localeCompare(l.sortKey(m));if(l.adoptedAfterListed){let L=c.length-g;c.splice(L,g,...c.slice(L).sort(y));}else c.sort(y);let w=[];for(let L of a.root.children)u.has(U(L))||f.has(U(L))||w.push(L);let S=Bn(a.root.children,[...w,...c]);if(S===a.root.children)continue;let I=this.registry.record(U(a.root));if(!I||!W(I))continue;let b=Ko(I,S,a.root);this.cache.remember(U(a.root),b);let v=Object.freeze({...a,root:b});e.set(s,v),this.partCache.set(s,v);}}materializeOnce(e,n,o){return n.has(e)?this.cache.get(e)??null:this.materialize(e,n,new Set,o)}adoptNodesIntoRoot(e,n,o,r){let i=this.cache.get(e),s=i&&i.kind!=="textValue"?i:this.materializeOnce(e,o,r);if(!s||s.kind==="textValue")return null;let a=[...s.children],l=new Set(a.map(p=>p.id)),d=0;for(let p of n){if(l.has(p))continue;let h=this.materializeOnce(p,o,r);!h||h.kind==="textValue"||(a.push(h),l.add(p),d+=1);}if(a.sort((p,h)=>ps(p).localeCompare(ps(h))),d===0&&a.every((p,h)=>p===s.children[h]))return s;let c=this.registry.record(e);if(!c||!W(c))return s;let u=Bn(s.children,a),f=Ko(c,u,s);return this.cache.remember(e,f),f}applyCustomXmlStores(e,n,o){let r=au(this.registry,e);if(r.length===0||!uu(e,r))return;let i=ys(e,r),s=new Set;for(let a of r){s.add(a.itemName),s.add(a.propsName);let l=this.adoptNodesIntoRoot(a.dataRootId,a.nodeIds,n,o),d=this.materializeOnce(a.propsRootId,n,o);if(!l||!d||d.kind==="textValue")continue;let c=Object.freeze({id:a.itemName,name:a.itemName,contentType:"application/xml",root:l}),u=Object.freeze({id:a.propsName,name:a.propsName,contentType:CUSTOM_XML_PROPS_TYPE,root:d});e.set(a.itemName,c),e.set(a.propsName,u),this.partCache.set(a.itemName,c),this.partCache.set(a.propsName,u);}if(i){for(let a of [...e.keys()])!Fn(a)&&!ms(a)||s.has(a)||(e.delete(a),this.partCache.delete(a));this.customXmlRels=lu(this.registry,r),this.customXmlOverrides=cu(r),this.projectRelsParts(e);}}assemblePackage(e){let n=this.packageCache.relationshipAssembly(this.customXmlRels);if(!n)return {ok:false,code:"invalid-relationships",issues:[...this.issues]};let o=this.packageCache.resolvePartBytes(this.blobs);if(!o)return {ok:false,code:"missing-blob",issues:[...this.issues]};let r=new Map(this.packageCache.contentTypeOverrides());for(let[a,l]of this.customXmlOverrides)r.set(a,l);let i={defaults:this.packageCache.contentTypeDefaults(),overrides:r};Iu(e,i,r);let s=this.registry.mainDocumentPart()||[...e.keys()].find(a=>a.endsWith("document.xml"))||"";return {ok:true,package:Object.freeze({parts:e,partBytes:o,relationships:n.byOwner,externalTargets:n.externalTargets,contentTypes:i,mainDocumentPart:s}),issues:[...this.issues]}}};function wu(t,e){if(!t)return e.effects.some(r=>r.kind==="putBinary")?{ok:false,failure:Object.freeze({code:"collaboration-session-not-attached"})}:null;let n=Yc(e.effects,Nc(t));return n===null?null:n.ok?n:{ok:false,failure:Object.freeze(n.failure)}}function ku(t,e){try{_c(t,e);}catch(n){return n instanceof N?Object.freeze({code:n.code,...n.detail?{detail:n.detail}:{}}):Object.freeze({code:"blob-store-full"})}return null}function Is(t){let{status:e,reason:n}=t;return e!=="ready"&&e!=="disconnected"?null:{status:e,...n?{code:n.code,detail:n.detail}:{}}}var ky=3,vy=20,tr=class{refused=0;transient=0;published(){this.refused=0,this.transient=0;}refusedOne(e){(!e||++this.transient>vy)&&(this.refused+=1);}recoverable(){return this.refused<ky}};var xs="docxEditorSelectionBefore",nr=class{constructor(e,n,o=()=>null){this.undoManager=e;this.textOf=n;this.find=o;e.on("stack-item-added",this.onAdded),e.on("stack-item-popped",this.onPopped);}undoManager;textOf;find;latest=null;before=null;restored=null;onAdded=e=>{e.stackItem.meta.has(xs)||e.stackItem.meta.set(xs,this.before);};onPopped=e=>{let n=e.stackItem.meta.get(xs);this.restored=n??null;};track(e,n=new Map){if(!e){this.latest=null;return}let o=r=>({paragraphId:r.paragraphId,offset:r.offset,...r.character?{character:r.character}:{}});this.latest={selection:{anchor:o(e.anchor),head:o(e.head),...e.kind?{kind:e.kind}:{}},texts:n};}noteBefore(){this.before=this.latest;}startPop(){this.restored=null;}lastRestored(){let e=this.restored;if(!e)return null;let n=r=>{let i=r.character?this.find(r.paragraphId,r.character):null;if(i)return i;let s={paragraphId:r.paragraphId,offset:r.offset},a=e.texts.get(r.paragraphId),l=this.textOf(r.paragraphId);return a===void 0||l===null?s:{...s,offset:mapOffsetAcrossText(r.offset,a,l)}},{selection:o}=e;return {anchor:n(o.anchor),head:n(o.head),...o.kind?{kind:o.kind}:{}}}destroy(){this.undoManager.off("stack-item-added",this.onAdded),this.undoManager.off("stack-item-popped",this.onPopped);}};var vu=Symbol("createDocumentCollaboration.attachWatchdogMs");function Lu(t){return t[vu]??2e3}function Ru(t,e,n){let o=setTimeout(()=>{n()||console.warn(`[docx-editor] The collaboration session for "${t}" was created ${e}ms ago and no editor attached its document port. The session reports "ready" but no edits replicate. Remount the editor when the session appears \u2014 for example pass key={session.sessionId} \u2014 so collaborationModule({ session }) attaches it.`);},e);return o.unref?.(),o}var pn="docxEditor",ht=256,or=256,Ou=/^\d{1,16}:\d{1,16}$/;function Cu(t,e,n){let o=new Map,r=s=>{let a=s.paragraphId.toUpperCase(),l=o.get(a);l===void 0&&(l=e(a),l!==void 0&&o.set(a,l));let d=Math.max(0,s.offset),c=n({paragraphId:a,offset:d});return {paragraphId:a,offset:d,...l!==void 0?{digest:rr(l)}:{},...c?{character:c}:{}}};return {encoded:{anchor:r(t.anchor),head:r(t.head),...t.kind==="cells"?{kind:"cells"}:{}},texts:o}}function Oy(t){if(typeof t!="object"||t===null||Array.isArray(t))return null;let e=t;if(typeof e.item!="string"||!Ou.test(e.item)||typeof e.after!="boolean")return null;let n=typeof e.identity=="string"&&Ou.test(e.identity)?e.identity:void 0;return {item:e.item,...n?{identity:n}:{},after:e.after}}function rr(t){let e=2166136261;for(let n=0;n<t.length;n+=1)e^=t.charCodeAt(n),e=Math.imul(e,16777619);return (e>>>0).toString(16).padStart(8,"0")}var Ey=/^[0-9a-f]{8}$/;function Tu(t){let e=t.actorId.trim(),n=t.name.trim();if(e.length===0||e.length>ht||n.length===0||n.length>ht)throw new N("invalid-identity");if(t.color!==void 0&&t.color.length>64)throw new N("invalid-identity-color");return Object.freeze({actorId:e,name:n,...t.color?{color:t.color}:{},role:t.role??"human"})}function Mu(t){let e=t.trim();if(e.length===0||e.length>ht)throw new N("invalid-document-id");return e}function Pu(t){let e=t?.trim()||globalThis.crypto.randomUUID();if(e.length>ht)throw new N("invalid-session-id");return e}function Eu(t){if(typeof t!="object"||t===null||Array.isArray(t))return null;let e=t;if(typeof e.paragraphId!="string"||e.paragraphId.length!==8||!Number.isSafeInteger(e.offset)||e.offset<0)return null;let n=Oy(e.character);return {paragraphId:e.paragraphId.toUpperCase(),offset:e.offset,...typeof e.digest=="string"&&Ey.test(e.digest)?{digest:e.digest}:{},...n?{character:n}:{}}}function Cy(t){if(t===void 0||typeof t!="object"||t===null||Array.isArray(t))return;let e=t,n=Eu(e.anchor),o=Eu(e.head);if(n&&o)return e.kind==="cells"?{anchor:n,head:o,kind:"cells"}:{anchor:n,head:o};if(typeof e.paragraphId=="string"&&e.paragraphId.length===8&&Number.isSafeInteger(e.start)&&Number.isSafeInteger(e.end)&&e.start>=0&&e.end>=0){let r=e.paragraphId.toUpperCase();return {anchor:{paragraphId:r,offset:e.start},head:{paragraphId:r,offset:e.end}}}}function ir(t){if(typeof t!="object"||t===null||Array.isArray(t))return null;let e=t;if(typeof e.actorId!="string"||e.actorId.length===0||e.actorId.length>ht||typeof e.name!="string"||e.name.length===0||e.name.length>ht)return null;let n=safeParticipantColor(typeof e.color=="string"?e.color:void 0),o=e.role==="agent"?"agent":"human",r={actorId:e.actorId,name:e.name,...n?{color:n}:{},role:o},i=Cy(e.selection);return i?{...r,selection:i}:r}var My=16,Py=32,sr=class{baselines=new Map;resolve(e,n,o){let r=[...e.getStates().entries()].slice(0,or),i=[],s=new Set,a=new Set,l=0,d;for(let[c,u]of r){if(c===e.clientID)continue;let f=ir(u[pn]);if(!f?.selection)continue;s.add(c);let{anchor:p,head:h}=f.selection,g=`${p.paragraphId}:${p.offset}:${p.digest??""}|${h.paragraphId}:${h.offset}:${h.digest??""}`,y=this.baselines.get(c);y?.key!==g&&(y={key:g,texts:new Map,resolved:new Map,missing:new Map},this.baselines.set(c,y));let{texts:w,resolved:S,missing:I}=y,b=m=>{let k=false,O=()=>{if(!m.character||!o)return null;if(l>=Py)return k=true,null;l+=1;let ne=o(m.paragraphId,m.character),A=ne?n.paragraphByNodeId(ne.nodeId):null;if(!ne||!A)return null;let J={paragraphId:A.paragraphId,nodeId:A.nodeId,offset:ne.offset};return {address:Object.freeze(J),text:A.text}},P=n.paragraphByStableId(m.paragraphId);if(!P){let ne=m.paragraphId+":"+m.offset;d??=n.revision();let A=I.get(ne);if(A?.revision===d)return A.address;let J=O()?.address??null;return k||I.set(ne,{revision:d,address:J}),J}let j=S.get(m.paragraphId+":"+m.offset);if(j?.text===P.text&&j.address.nodeId===P.nodeId&&(j.target===void 0||n.paragraphByNodeId(j.address.nodeId)?.text===j.target))return j.address;let K=O();if(K)return S.set(m.paragraphId+":"+m.offset,{text:P.text,address:K.address,target:K.text}),K.address;let Y=w.get(m.paragraphId);if(Y===void 0){if(m.digest!==void 0&&rr(P.text)!==m.digest)return Object.freeze({paragraphId:P.paragraphId,nodeId:P.nodeId,offset:Math.min(m.offset,P.text.length)});Y=P.text,w.set(m.paragraphId,Y);}let V=Y===P.text?"":`${m.paragraphId}:${Y.length}:${rr(Y)}`,q=V===""||a.has(V)||a.size<My;q&&V!==""&&a.add(V);let ee=Object.freeze({paragraphId:P.paragraphId,nodeId:P.nodeId,offset:q?mapOffsetAcrossText(m.offset,Y,P.text):Math.min(m.offset,P.text.length)});return S.set(m.paragraphId+":"+m.offset,{text:P.text,address:ee}),ee},v=b(p),L=b(h);!v||!L||i.push(Object.freeze({actorId:f.actorId,name:f.name,...f.color?{color:f.color}:{},...f.selection.kind==="cells"?{kind:"cells"}:{},anchor:v,head:L}));}for(let c of this.baselines.keys())s.has(c)||this.baselines.delete(c);return Object.freeze(i)}};var zn=64*1024*1024,hn="docx-package-blobs-v1";function Dy(t){if(t instanceof Uint8Array)return new Uint8Array(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t)){let e=t;return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}return null}function Ny(t){return t instanceof ArrayBuffer||ArrayBuffer.isView(t)?t.byteLength:0}var gt=class{constructor(e){this.shared=e;}shared;verified=new WeakSet;poisoned=new Set;get(e){let n=this.shared.get(e),o=Dy(n);return !o||typeof n!="object"||n===null?null:this.verify(e,n,o)?o:null}has(e){let n=this.shared.get(e);return n===void 0?false:this.verified.has(n)?true:this.get(e)!==null}poisonedDigest(){for(let e of this.poisoned)return e;return null}observeChanges(e){let n=o=>{e([...o.keysChanged]);};return this.shared.observe(n),()=>this.shared.unobserve(n)}verifyNow(e){for(let n of e)if(this.shared.has(n)&&this.get(n)===null)return n;return null}totalByteLength(){let e=0;return this.shared.forEach(n=>{e+=Ny(n);}),e}put(e,n){if(!this.shared.has(e)){if(this.totalByteLength()+n.byteLength>zn)throw new N("blob-store-full");this.shared.set(e,new Uint8Array(n));}}verify(e,n,o){return this.verified.has(n)?true:this.poisoned.has(e)?false:sha256FontBytes(o)!==e?(this.poisoned.add(e),false):(this.verified.add(n),true)}};var Yy=Object.freeze([.75,.9]),Au=16;function Ss(t){let e=0;return t.schema.relationships.forEach(n=>{e+=n instanceof z.Map?n.size:0;}),e}function Nu(t){return {limit:"nodes",code:"too-many-nodes",used:t.nodeCount(),max:t.limits.maxNodes}}function Yu(t,e){let{limits:n,schema:o}=t;return [{limit:"parts",code:"too-many-parts",used:o.parts.size,max:n.maxParts},{limit:"relationships",code:"too-many-relationships",used:Ss(t),max:n.maxRelationships},{limit:"blobBytes",code:"blob-store-full",used:e.totalByteLength(),max:zn}]}function _y(t,e){return [Nu(t),...Yu(t,e)]}function lr(t,e){for(let n of _y(t,e))if(n.used>n.max)return Object.freeze({code:n.code,detail:`${n.limit}=${n.used}`});return null}function By(t){let e=t?.thresholds;if(e===void 0)return Yy;if(!Array.isArray(e)||e.length===0||e.length>Au)throw new RangeError(`thresholds must hold 1 to ${Au} values`);for(let n of e)if(typeof n!="number"||!Number.isFinite(n)||n<=0||n>1)throw new RangeError("each threshold must be greater than 0 and at most 1");return [...new Set(e)].sort((n,o)=>n-o)}function Uy(t,e){let n=t[0],o=-1;for(let i of t){let s=i.max>0?i.used/i.max:Number.POSITIVE_INFINITY;s>o&&(n=i,o=s);}let r=0;for(let i of e)o>=i&&(r=i);return Object.freeze({limit:n.limit,fraction:o,threshold:r,used:n.used,max:n.max})}var ar=class{stops=new Set;stopped=false;watch(e,n,o,...[r,i]){let s=By(i);if(this.stopped)return ()=>{};let{parts:a,relationships:l}=n.schema,d=null,c=()=>{d=null;},u=()=>(d??=Yu(n,o),Uy([Nu(n),...d],s)),f=w=>{try{r(w);}catch(S){console.error("A subscribeResourcePressure listener threw.",S);}};a.observe(c),l.observeDeep(c);let p=o.observeChanges(c),h=u().threshold,g=()=>{let w=u();w.threshold!==h&&(h=w.threshold,f(w));},y=()=>{this.stops.delete(y)&&(e.off("afterTransaction",g),a.unobserve(c),l.unobserveDeep(c),p());};return e.on("afterTransaction",g),this.stops.add(y),h>0&&f(u()),y}stopAll(){this.stopped=true;for(let e of [...this.stops])e();}};var Bu=20*1024*1024,Vy=new Set(["document","hdr","ftr","footnotes","endnotes"]),ju=3e4,Jy=4e3,Hy=1500,Xy="docx-collaboration-seeds-v1",ws="docxEditorSeedCandidate",Gy=/^[0-9a-f]{16}$/,qy=256;function zu(t,e=Bu,n={}){if(!(t instanceof Uint8Array)||t.byteLength===0)throw new N("invalid-baseline");let o=Math.min(e,Bu);if(t.byteLength>o)throw new N("baseline-too-large");let r=readOoxmlPackage(t,{zip:{maxEntries:1e4,maxTotalBytes:o,maxRatio:200}});if(!r.ok)throw new N(r.limit==="zip.maxTotalBytes"?"baseline-too-large":"invalid-baseline");let i=r.package.parts.get(r.package.mainDocumentPart);if(!i)throw new N("no-main-document-part");let s=n.keepBound?r.package:refreshBoundContent(r.package);for(let l of s.parts.values()){if(l.root.namespaceUri!==WML_NAMESPACE_URI||!Vy.has(l.root.localName)||!isStoryPart(l))continue;let d=normalizeParagraphIdentity(l);d!==l&&(s=withPart(s,d));}return new TreePackageStore(s,normalizeParagraphIdentity(s.parts.get(i.name))).currentPackage()}function Qy(t,e){for(let n of t.binaries())if(!e.has(n.digest))return false;return true}function dr(t,e,n,o){let r=t.schema.meta,i=()=>r.get("initialized")===true&&Qy(t,e),s=()=>{let l=e.poisonedDigest();return l?new N("blob-digest-mismatch",l):null};if(o?.aborted)return Promise.reject(new N("initialization-aborted"));if(i())return Promise.resolve();let a=s();return a?Promise.reject(a):new Promise((l,d)=>{let c=h=>{clearTimeout(p),r.unobserve(u),t.doc.off("afterTransaction",u),o?.removeEventListener("abort",f),h?d(h):l();},u=()=>{let h=s();if(h){c(h);return}i()&&c();},f=()=>c(new N("initialization-aborted")),p=setTimeout(()=>c(new N("initialization-timeout")),n);r.observe(u),t.doc.on("afterTransaction",u),o?.addEventListener("abort",f,{once:true});})}function ur(t){return t.getArray(Xy)}function Zy(t){ur(t).push([Ku()]);}var eb="freshBytes";function Wu(t){let e=z.encodeStateAsUpdate(t).byteLength;t.getMap(vr).set(eb,e);}function tb(t){return ur(t).length}function $u(t,e){let n=ur(t),o=()=>{n.length>1&&e();};return o(),n.observe(o),()=>n.unobserve(o)}function Ku(){let t=new Uint8Array(8);return globalThis.crypto.getRandomValues(t),[...t].map(e=>e.toString(16).padStart(2,"0")).join("")}function nb(t,e){let n=[...t.getStates().entries()].slice(0,qy);for(let[o,r]of n){if(o===t.clientID)continue;let i=r[ws];if(!(typeof i!="string"||!Gy.test(i))&&i<e)return true}return false}async function Uu(t,e,n,o){try{return await dr(t,e,n,o),!0}catch(r){if(r instanceof N&&r.code==="initialization-timeout")return false;throw r}}function ob(t,e,n){let o=t.schema.meta,r=()=>o.get("documentId")!==void 0;return n?.aborted?Promise.reject(new N("initialization-aborted")):r()?Promise.resolve():new Promise((i,s)=>{let a=u=>{clearTimeout(c),o.unobserve(l),n?.removeEventListener("abort",d),u?s(u):i();},l=()=>{r()&&a();},d=()=>a(new N("initialization-aborted")),c=setTimeout(()=>a(new N("initialization-timeout")),e);o.observe(l),n?.addEventListener("abort",d,{once:true});})}async function rb(t){let{ydoc:e,awareness:n,registry:o,blobs:r}=t,i=t.probeTimeoutMs??Jy,s=t.electionWindowMs??Hy,a=t.timeoutMs??ju,l=async()=>(await ob(o,a,t.signal),"joined");if(await Uu(o,r,i,t.signal))return l();let d=Ku();n.setLocalStateField(ws,d);try{let c=await Uu(o,r,s,t.signal);if(!c&&nb(n,d)&&(await dr(o,r,a,t.signal),c=!0),c)return await l();if(o.schema.meta.get("initialized")===!0)return await dr(o,r,a,t.signal),await l();if(t.signal?.aborted)throw new N("initialization-aborted");let u=await $o(o,zu(t.document),r);if(!u.ok)throw new N(u.code);return e.transact(()=>{o.schema.meta.set("documentId",t.documentId),ur(e).push([d]);}),Wu(e),"seeded"}finally{n.setLocalStateField(ws,null);}}function cr(t,e,n){let o=Xn(t.schema.meta);if(o)throw new N(o.code,o.detail);t.rebuildDerivedIndexes(),ks(t,e,n);}function ks(t,e,n){if(tb(n)>1)throw new N("concurrent-seed");let o=lr(t,e);if(o)throw new N(o.code,o.detail)}async function Vu(t,e,n,o){if(t.bootstrap.kind==="create"){if(e.schema.meta.get("initialized")===true)throw new N("already-initialized");let r=await $o(e,zu(t.bootstrap.document),n);if(!r.ok)throw new N(r.code);t.ydoc.transact(()=>{e.schema.meta.set("documentId",o),Zy(t.ydoc);}),Wu(t.ydoc),ks(e,n,t.ydoc);}else if(t.bootstrap.kind==="create-or-join")if(await rb({ydoc:t.ydoc,awareness:t.awareness,registry:e,blobs:n,documentId:o,document:t.bootstrap.document,probeTimeoutMs:t.bootstrap.probeTimeoutMs,electionWindowMs:t.bootstrap.electionWindowMs,timeoutMs:t.bootstrap.timeoutMs,signal:t.bootstrap.signal})==="joined"){if(e.schema.meta.get("documentId")!==o)throw new N("document-id-mismatch");cr(e,n,t.ydoc);}else ks(e,n,t.ydoc);else {if(await dr(e,n,t.bootstrap.timeoutMs??ju,t.bootstrap.signal),e.schema.meta.get("documentId")!==o)throw new N("document-id-mismatch");cr(e,n,t.ydoc);}}function fr(t,e,n,o){let r=t.inline.textOf(e);if(!r)return null;let i=[],s=new Set,a=Ze(e,r,y=>{if(s.has(y))return null;let w=n(y);return w&&s.add(w.id),w},t.limits,{...t.inline.viewOf(e),noteDrift:()=>{}},y=>i.push(y)),l={id:e,kind:"paragraph",namespaceUri:WML_NAMESPACE_URI,localName:"p",prefix:"w",namespaceBindings:[],attributes:[],children:a},d=new Map,c=0,u=y=>{if(!s.has(y.id)){if(y.kind==="textValue"){d.set(y.id,c),c+=y.value.length;return}for(let w of y.children)u(w);}};for(let y of a)u(y);if(c!==i.length)return null;let f=segmentsOf(l),p=f.length>0?f[f.length-1].end:0;if(p!==o.length)return null;let h=new Int32Array(p).fill(-1),g=new Int32Array(i.length).fill(-1);for(let y of f){if(y.node.kind!=="textValue"||y.removeNodeIds)continue;let w=d.get(y.node.id),S=y.node.value;if(w===void 0||o.slice(y.start,y.end)!==S)return null;for(let I=0;I<y.end-y.start;I+=1)h[y.start+I]=w+I,g[w+I]=y.start+I;}return {length:p,characters:i,characterAt:h,offsetOf:g}}function Ju(t,e){let n=e>0?t.characterAt[e-1]:-1;if(n!==void 0&&n>=0){let r=t.characters[n];return r?{character:r,after:true}:null}let o=e<t.length?t.characterAt[e]:-1;if(o!==void 0&&o>=0){let r=t.characters[o];return r?{character:r,after:false}:null}return null}function vs(t,e){let n=e.character.identity??e.character.item,o=-1;for(let i=0;i<t.characters.length;i+=1){let s=t.characters[i];if(s){if(s.item===e.character.item){o=i;break}o<0&&s.identity===n&&(o=i);}}if(o<0)return null;let r=t.offsetOf[o];return r<0?null:e.after?r+1:r}var ab=4096,Hu=64,pr=class{constructor(e){this.deps=e;}deps;selection=null;anchored=null;stale=true;carried=null;carryOwed=false;track(e){let n=this.deps.port(),o=a=>{let l=n?.paragraphByStableId(a.paragraphId);return l?{nodeId:l.nodeId,offset:a.offset}:null},r=e?o(e.anchor):null,i=e?o(e.head):null,s=r&&i?{anchor:r,head:i}:null;s&&this.selection&&lb(s,this.selection)||(this.selection=s,this.stale=true,this.anchored=null,this.carried=null,this.carryOwed=false);}localChange(){this.stale=true,this.anchored=null,this.carried=null,this.carryOwed=false;}beforeChange(){if(this.carried=null,this.carryOwed=true,!this.stale)return;this.anchored=null;let e=this.selection;if(!e||!this.deps.viewIsCurrent())return;let n=this.anchorOf(e.anchor),o=this.anchorOf(e.head);!n||!o||(this.anchored={anchor:n,head:o},this.stale=false);}afterPublish(){this.carryOwed=false;let{anchored:e,selection:n}=this;if(!e||!n||!this.deps.viewIsCurrent()){this.carried=null;return}let o=this.resolve(e.anchor),r=this.resolve(e.head);this.carried=o&&r?{from:n,to:{anchor:o,head:r}}:null;}move(){return this.carryOwed&&this.afterPublish(),this.carried}characterOf(e){let n=this.deps.port()?.paragraphByStableId(e.paragraphId);if(!n||!this.deps.viewIsCurrent())return;let o=this.anchorOf({nodeId:n.nodeId,offset:e.offset});if(!o)return;let{character:r,after:i}=o.anchor;return {item:r.item,...r.identity!==null?{identity:r.identity}:{},after:i}}find(e,n){if(!this.deps.viewIsCurrent())return null;let o=this.deps.port()?.paragraphByStableId(e);return this.resolve({paragraph:o?this.deps.logicalIdOf(o.nodeId):null,anchor:{character:{item:n.item,identity:n.identity??null},after:n.after}})}findStable(e,n){let o=this.find(e,n),r=o?this.deps.port()?.paragraphByNodeId(o.nodeId):null;return o&&r?{paragraphId:r.paragraphId,offset:o.offset}:null}anchorOf(e){let n=this.deps.logicalIdOf(e.nodeId),o=this.shownText(e.nodeId);if(o===null)return null;let r=fr(this.deps.registry,n,this.deps.embedOf,o),i=r?Ju(r,e.offset):null;return i?{paragraph:n,anchor:i}:null}resolve(e){let{registry:n}=this.deps,o=n.inline.follow,r=e.anchor.character.identity??e.anchor.character.item,i=new Set(e.paragraph?[e.paragraph]:[]),s=o.shownCopy(r);s&&i.add(s);for(let a of o.holdersOf(r))i.add(a);if(e.paragraph)for(let a of o.targetsFor(e.paragraph))i.add(a);for(let a of i){if(i.size>=Hu)break;for(let l of o.targetsFor(a)){if(i.size>=Hu)break;i.add(l);}}for(let a of i){if(n.inline.isDeletedParagraph(a))continue;let l=this.shownText(a);if(l===null)continue;let d=fr(n,a,this.deps.embedOf,l),c=d?vs(d,e.anchor):null;if(c!==null)return {nodeId:a,offset:c}}return e.paragraph?this.besideDeleted(e.paragraph,e.anchor):null}besideDeleted(e,n){let{registry:o}=this.deps,r=o.inline.textOf(e),i=this.shownText(e),s=/^(\d{1,16}):(\d{1,16})$/.exec(n.character.item);if(!r?.doc||i===null||!s||o.inline.isDeletedParagraph(e))return null;let a=H(r.doc,{client:Number(s[1]),clock:Number(s[2])});if(!a||!a.deleted||a.parent!==r)return null;let l=fr(o,e,this.deps.embedOf,i);if(!l)return null;if(i.length===0)return {nodeId:e,offset:0};for(let d of [true,false]){let c=0;for(let u=d?a.left:a.right;u&&c<ab;u=d?u.left:u.right,c+=1){if(u.deleted||!(u.content instanceof z.ContentString))continue;let f=d?u.id.clock+u.length-1:u.id.clock,p=vs(l,{character:{item:`${u.id.client}:${f}`,identity:null},after:d});if(p!==null)return {nodeId:e,offset:p}}}return null}shownText(e){return this.deps.port()?.paragraphTextOf?.(e)??null}};function lb(t,e){return t.anchor.nodeId===e.anchor.nodeId&&t.anchor.offset===e.anchor.offset&&t.head.nodeId===e.head.nodeId&&t.head.offset===e.head.offset}var hr=class{constructor(e){this.deps=e;}deps;waiting=false;held=[];refuses(e){return this.deps.viewWaiting()?this.set(true):Ve(this.deps.ydoc)?this.waits(e)?(this.held=e,this.set(true)):(this.held.length>0&&!this.waits(this.held)&&(this.held=[]),this.set(this.held.length>0),false):(this.held=[],this.set(false))}refresh(){!this.waiting||this.deps.viewWaiting()||(!Ve(this.deps.ydoc)||this.held.length>0&&!this.waits(this.held))&&(this.held=[],this.set(false));}waits(e){return e.some(n=>db.has(n.op)||cb(n).some(o=>this.deps.nodeWaits(o)))}set(e){return e!==this.waiting&&(this.waiting=e,this.deps.publish(e)),e}},db=new Set(["acceptAllRevisions","rejectAllRevisions","replaceStoryBlocks","convertAllNotes"]);function cb(t){let e=[],n=(o,r)=>{for(let[i,s]of Object.entries(o))if(typeof s=="string")i.endsWith("Id")&&e.push(s);else if(Array.isArray(s))for(let a of s)typeof a=="string"?i.endsWith("Ids")&&e.push(a):a!==null&&typeof a=="object"&&r<3&&n(a,r+1);else s!==null&&typeof s=="object"&&r<3&&n(s,r+1);};return n(t,0),e}function ub(t){let e=0;return t.schema.nodes.forEach(n=>{_(n)&&n.get(me)===true&&(e+=1);}),e}function fb(t){let e=0;return t.schema.nodes.forEach(n=>{let o=_(n)?n.get(ae):null;if(o instanceof z.Text)for(let r=o._start;r;r=r.right)!r.deleted&&r.content instanceof z.ContentFormat&&(e+=1);}),e}function Ls(t,e){return Object.freeze({nodes:t.nodeCount(),tombstonedNodes:ub(t),maxNodes:t.limits.maxNodes,relationships:Ss(t),maxRelationships:t.limits.maxRelationships,parts:t.schema.parts.size,maxParts:t.limits.maxParts,blobBytes:e.totalByteLength(),maxBlobBytes:zn,formattingMarkers:fb(t)})}function IR(t){let e=new rt(t);try{let n=new gt(t.getMap(hn));return Ls(e,n)}finally{e.destroy();}}var pb={"undo-group-already-open":"End the open group, or use another session for this operation.","editor-attached":"Use editor.beginHistoryGroup() in the editor, or a separate session for the agent.","collaboration-session-destroyed":"Join the room with a new session."},mt=class extends Error{constructor(n){super(`${n}: ${pb[n]}`);this.code=n;this.name="CollaborationUndoGroupError";}code},mr=class{constructor(e,n){this.capture=e;this.flush=n;}capture;flush;current=null;get isOpen(){return this.current!==null}begin(e,n){if(e())throw new mt("collaboration-session-destroyed");if(n())throw new mt("editor-attached");if(this.current!==null)throw new mt("undo-group-already-open");if(this.flush(),e())throw new mt("collaboration-session-destroyed");if(n())throw new mt("editor-attached");if(this.current!==null)throw new mt("undo-group-already-open");let o={};this.current=o,this.capture.pin(Symbol("collaboration-undo-group"));let r=this;return Object.freeze({get state(){return r.current===o?"open":"closed"},end(){r.current===o&&(r.flush(),r.current===o&&(r.current=null,r.capture.unpin()));}})}close(){this.current!==null&&(this.current=null,this.capture.unpin());}};var hb=2;function Gu(t,e){let n=new Set,o=new Set;for(let i of e.effects)if(i.kind==="spliceChildren"){n.add(i.parentLogicalId);for(let s of i.childLogicalIds)o.add(s);}else if(i.kind==="moveNode"){o.add(i.logicalId),n.add(i.destinationParentLogicalId);let s=t.parentOf(i.logicalId);s&&n.add(s);}let r=[];for(let i of n){if(!t.splitSiblings.ranksOf(i))continue;let s=t.splitSiblings.shownChildren(i);s&&r.push({parentId:i,shown:s,placed:o});}return r}function gb(t,e,n){let o=new Set(e),r=new Set(t.filter(d=>o.has(d)&&!n.has(d))),i=t.filter(d=>r.has(d)),s=0,a=false,l=e.map(d=>{if(!r.has(d))return d;let c=i[s++];return c!==d&&(a=true),c});return a?l:null}function mb(t,e,n,o){let r=ie(t.schema.nodes.get(e));if(!r)return false;let i=0;for(;o[i]===n[i];)i+=1;let s=o.length-1;for(;o[s]===n[s];)s-=1;let a=o.slice(i,s+1),l=r.toArray();for(let u of a){if(l.indexOf(u)!==l.lastIndexOf(u))return false;let f=t.listingParents(u);if(f.length!==1||f[0]!==e)return false}let d=new Set(a);for(let u=l.length-1;u>=0;u-=1)d.has(l[u])&&r.delete(u,1);let c=i>0?r.toArray().indexOf(o[i-1]):-1;return r.insert(c+1,a),true}function qu(t,e,n,o){for(let{parentId:r,shown:i,placed:s}of o)for(let a=0;a<hb;a+=1){let l=t.splitSiblings.shownChildren(r),d=l?gb(i,l,s):null;if(!l||!d)break;let c=false;if(e.transact(()=>{c=mb(t,r,l,d);},n),!c)break}}var yr=class{constructor(e,n){this.knows=e;this.allocator=new gn(n);}knows;allocator;toLogical=new Map;get replicaId(){return this.allocator.replicaId}reset(){this.toLogical.clear();}mint(e){let n=this.allocator.take();return this.toLogical.set(e,n),n}resolve(e){return this.toLogical.get(e)??e}translate(e){let n=[],o=false;for(let r of e.effects){let i=this.translateEffect(r);i!==r&&(o=true),n.push(i);}return o?Object.freeze({effects:Object.freeze(n)}):e}translateEffect(e){switch(e.kind){case "putNode":{let n=this.translateDescriptor(e.descriptor);return n.logicalId===e.descriptor.logicalId?e:{...e,descriptor:n}}case "spliceText":case "setAttribute":case "setNamespaceBinding":{let n=this.resolve(e.logicalId);return n===e.logicalId?e:{...e,logicalId:n}}case "spliceChildren":{let n=this.resolve(e.parentLogicalId),o=e.childLogicalIds.map(i=>this.resolve(i));return n===e.parentLogicalId&&o.every((i,s)=>i===e.childLogicalIds[s])?e:{...e,parentLogicalId:n,childLogicalIds:o}}case "moveNode":{let n=this.resolve(e.logicalId),o=this.resolve(e.destinationParentLogicalId);return n===e.logicalId&&o===e.destinationParentLogicalId?e:{...e,logicalId:n,destinationParentLogicalId:o}}case "putXmlPart":{let n=this.resolve(e.rootLogicalId);return n===e.rootLogicalId?e:{...e,rootLogicalId:n}}default:return e}}translateDescriptor(e){let n=this.resolve(e.logicalId);return this.knows(n)?{...e,logicalId:n}:{...e,logicalId:this.mint(e.logicalId)}}};async function Qu(t,e){let n=Lu(t),o=Mu(t.documentId),r=Pu(t.sessionId),i=Tu(t.identity),s=new rt(t.ydoc);try{return await bb(t,{attachWatchdogMs:n,documentId:o,sessionId:r,identity:i,registry:s},e)}catch(a){throw s.destroy(),a}}async function bb(t,e,n){let{attachWatchdogMs:o,documentId:r,sessionId:i,identity:s,registry:a}=e,l=new yr(u=>a.hasNode(u)||a.inline.owner(u)!==null),d=new gt(t.ydoc.getMap(hn));await Vu(t,a,d,r);let c=new Ut(a,d);try{let u=c.current(),f=d.poisonedDigest();if(f)throw new N("blob-digest-mismatch",f);if(!u.ok)throw new N(u.code);let p=writeOoxmlPackageKeepingRevisionIds(u.package),h=n({ydoc:t.ydoc,awareness:t.awareness,documentId:r,sessionId:i,identity:s,registry:a,materializer:c,identityMap:l,blobs:d,attachWatchdogMs:o,offlineEditing:t.offlineEditing!==!1});return Object.freeze({document:p,session:h,destroy:()=>h.destroy()})}catch(u){throw c.destroy(),u}}function Sb(t){return Zu(t,writeOoxmlPackage)}function jR(t){return Zu(t,writeOoxmlPackageKeepingRevisionIds)}function Zu(t,e){let n=new rt(t),o=null;try{if(n.schema.meta.get("initialized")!==!0||typeof n.schema.meta.get("documentId")!="string")throw new N("not-initialized");let r=new gt(t.getMap(hn));cr(n,r,t),o=new Ut(n,r);let i=o.current(),s=r.poisonedDigest();if(s)throw new N("blob-digest-mismatch",s);if(!i.ok)throw new N(i.code);let a=vt(i.issues);if(a)throw new N("materialize-dropped-content",a);if(!i.package.parts.has(i.package.mainDocumentPart))throw new N("no-main-document-part");return e(i.package)}finally{o?.destroy(),n.destroy();}}var Lb=500,Rs=class{constructor(e,n,o,r,i,s,a,l,d,c,u){this.ydoc=e;this.awareness=n;this.registry=s;this.materializer=a;this.identityMap=l;this.blobs=d;this.offlineEditing=u;this.documentId=o,this.sessionId=r,this.currentIdentity=i,this.undoManager=new z.UndoManager([...s.trackedTypes()],{trackedOrigins:new Set([this.localOrigin]),captureTimeout:Lb,deleteFilter:s.undoDeleteFilter()}),this.historyGroups=new Yo(this.undoManager,this),this.undoGroups=new mr(this.historyGroups,()=>this.flushPendingJournals()),this.historySelections=new nr(this.undoManager,f=>this.port?.paragraphByStableId(f)?.text??null,(f,p)=>this.caretAnchors.findStable(f,p)),this.editWait=new hr({ydoc:e,viewWaiting:()=>this.viewWaiting,nodeWaits:f=>kd(s,this.identityMap.resolve(f)),publish:f=>this.statusState.setWaiting(f)&&this.notifyStatus()}),this.caretAnchors=new pr({registry:s,port:()=>this.port,logicalIdOf:f=>this.identityMap.resolve(f),embedOf:f=>a.builtNode(f),viewIsCurrent:()=>!this.viewWaiting}),e.on("beforeTransaction",this.onBeforeYjsTransaction),e.on("afterTransaction",this.onYjsTransaction),n.on("change",this.onAwarenessChange),this.stopBlobWatch=d.observeChanges(f=>{let p=d.verifyNow(f);p&&this.setStatus("error","blob-digest-mismatch",p);}),this.publishAwareness(),this.setStatus("ready"),this.stopSeedWatch=$u(e,()=>{this.setStatus("error","concurrent-seed");}),this.attachWatchdog=Ru(this.documentId,c,()=>(this.attachWatchdog=null,this.destroyed||this.port!==null));}ydoc;awareness;registry;materializer;identityMap;blobs;offlineEditing;documentId;sessionId;currentIdentity;currentSelection;attachWatchdog=null;statusState=createCollaborationStatusTracker();statusListeners=new Set;selectionListeners=new Set;participantListeners=new Set;localOrigin=Object.freeze({kind:"docx-document-local"});caretAnchors;editWait;undoManager;port=null;detachPort=null;applyingRemote=false;viewWaiting=false;fullRefusedWhileWaiting=false;healTo=null;historySelections;remoteSelectionResolver=new sr;realignedInBatch=false;journalsHeldDuringRemote=[];drainingHeldJournals=false;remoteCounter=0;destroyed=false;pressure=new ar;refusals=new tr;historyGroups;undoGroups;stopBlobWatch;stopSeedWatch;get identity(){return this.currentIdentity}clearAttachWatchdog(){this.attachWatchdog!==null&&(clearTimeout(this.attachWatchdog),this.attachWatchdog=null);}status(){return this.statusState.status()}statusSnapshot(){return this.statusState.snapshot()}resourceUsage(){return Ls(this.registry,this.blobs)}subscribeResourcePressure(...e){return this.pressure.watch(this.ydoc,this.registry,this.blobs,...e)}subscribeStatus(e){return this.statusListeners.add(e),()=>this.statusListeners.delete(e)}setTransportStatus(e,n,o){if(!this.destroyed){if(this.statusState.status()==="error"&&e!=="error"){this.healTo!==null&&(this.healTo={status:e,code:n,detail:o},this.publishSharedToPort());return}if(n!==void 0){this.setStatus(e,n,o);return}this.setStatus(e);}}get attached(){return this.port!==null}attach(e){let n=this.refuseAttach(e);if(n)return n;this.clearAttachWatchdog(),e.interactive===true&&this.undoGroups.close(),this.port=e,this.publishSharedToPort();let o=e.observePrimitiveJournal(r=>{if(!this.destroyed){if(this.applyingRemote){this.journalsHeldDuringRemote.push(r);return}this.realignedInBatch||this.applyJournal(r);}});return this.detachPort=()=>{this.flushPendingJournals(),o(),this.port===e&&(this.port=null),this.detachPort=null,this.currentSelection&&this.publishAwareness();},()=>this.detachPort?.()}refuseAttach(e){return this.destroyed?()=>{}:this.port?(this.port!==e&&this.setStatus("error","port-already-attached"),()=>{}):e.documentId!==this.documentId?(this.setStatus("error","document-id-mismatch"),()=>{}):null}hasCompatibleSharedSchema(){let e=Xn(this.registry.schema.meta);return e?(this.setStatus("error",e.code,e.detail),false):true}canWriteSharedState(){if(this.destroyed||!this.hasCompatibleSharedSchema())return false;let e=this.statusState.status();return e==="ready"||this.offlineEditing&&e==="disconnected"}gateOperations(e,n){return this.destroyed?"collaboration-session-destroyed":this.canWriteSharedState()?this.port?this.editWait.refuses(e)?"collaboration-session-not-ready":this.textLimitFailure(e):"collaboration-session-not-attached":"collaboration-session-not-ready"}textLimitFailure(e){let n=this.registry.limits.maxTextLength;for(let o of e)if(o.op==="insertText"&&o.text.length>n)return "collaboration-text-limit";return null}canUndo(){return !this.undoGroups.isOpen&&this.canWriteSharedState()&&((this.port?.hasPendingJournals()??false)||this.undoManager.undoStack.length>0)}canRedo(){return !this.undoGroups.isOpen&&this.canWriteSharedState()&&this.undoManager.redoStack.length>0}undo(){return this.popHistory("undo")}historySelection(){return this.historySelections.lastRestored()}redo(){return this.popHistory("redo")}beginUndoGroup(){return this.undoGroups.begin(()=>this.destroyed,()=>this.port?.interactive===true)}get undoGroupOpen(){return this.undoGroups.isOpen}popHistory(e){if(this.undoGroups.isOpen||!this.canWriteSharedState()||(this.flushPendingJournals(),!this.canWriteSharedState())||(e==="undo"?this.undoManager.undoStack:this.undoManager.redoStack).length===0)return false;this.historyGroups.reset(),this.historySelections.noteBefore(),this.historySelections.startPop();let o=z.getState(this.ydoc.store,this.ydoc.clientID);return this.registry.takeUnlisted(),ac(this.registry,this.undoManager,e,()=>sc(this.registry,this.ydoc,o)),true}flushPendingJournals(){this.port?.flushPendingJournals();}setLocalSelection(e){if(this.destroyed)return;if(this.caretAnchors.track(e),!e){this.historySelections.track(null),this.publishAwareness();return}let{encoded:n,texts:o}=Cu(e,r=>this.port?.paragraphByStableId(r)?.text,r=>this.caretAnchors.characterOf(r));this.historySelections.track(n,o),this.publishAwareness(n);}participants(){let e=[],n=[...this.awareness.getStates().entries()].slice(0,or);for(let[o,r]of n){let i=ir(r[pn]);i&&e.push({actorId:i.actorId,name:i.name,...i.color?{color:i.color}:{},role:i.role,isLocal:o===this.awareness.clientID});}return Object.freeze(e)}subscribeParticipants(e){return this.participantListeners.add(e),()=>this.participantListeners.delete(e)}remoteSelections(){return this.port?this.remoteSelectionResolver.resolve(this.awareness,this.port,(e,n)=>this.caretAnchors.find(e,n)):[]}subscribeRemoteSelections(e){return this.selectionListeners.add(e),()=>this.selectionListeners.delete(e)}setIdentity(e){if(this.destroyed)return;let n=e.name===void 0?this.currentIdentity.name:e.name.trim();if(n.length===0||n.length>ht)throw new N("invalid-identity");let o=this.currentIdentity.color;if(e.color!==void 0){if(e.color.length>64)throw new N("invalid-identity-color");o=safeParticipantColor(e.color);}this.currentIdentity=Object.freeze({actorId:this.currentIdentity.actorId,name:n,...o?{color:o}:{},role:this.currentIdentity.role??"human"}),this.publishAwareness(this.currentSelection);}destroy(){this.destroyed||(this.clearAttachWatchdog(),this.flushPendingJournals(),this.undoGroups.close(),this.detachPort?.(),this.destroyed=true,this.pressure.stopAll(),this.stopBlobWatch(),this.stopSeedWatch(),this.ydoc.off("beforeTransaction",this.onBeforeYjsTransaction),this.ydoc.off("afterTransaction",this.onYjsTransaction),this.awareness.off("change",this.onAwarenessChange),this.awareness.setLocalStateField(pn,null),this.historySelections.destroy(),this.undoManager.destroy(),this.materializer.destroy(),this.registry.destroy(),this.setStatus("destroyed"),this.statusListeners.clear(),this.selectionListeners.clear(),this.participantListeners.clear());}applyJournal(e){if(!this.canWriteSharedState())return;let n=this.identityMap.translate(e),o=Bd(this.materializer,n,()=>Ve(this.ydoc));if(o){this.refuseLocalJournal(o.failure,o.transient);return}this.registry.inline.takeDrift();let r=_d(this.registry,n,this.materializer);if(!r.ok){this.refuseLocalJournal({code:r.code,...r.detail?{detail:r.detail}:{}});return}let i=r.journal,s=wu(this.port,e);if(s!==null&&s.ok===false){this.refuseLocalJournal(s.failure);return}if(!this.canWriteSharedState())return;let a=false;this.historySelections.noteBefore();let l=Gu(this.registry,i),d=()=>{let u=this.ydoc.transact(()=>{if(s!==null){let p=ku(this.blobs,s.payloads);if(p!==null)return p}let f=Fi(this.registry,i,r.plan,r.typed);return f.ok?null:(a=f.transient===true,{code:f.code,...f.detail?{detail:f.detail}:{}})},this.localOrigin);return u===null&&qu(this.registry,this.ydoc,this.localOrigin,l),u},c=this.historyGroups.captureJournal(e,this.localOrigin,d);if(c===null){this.refusals.published(),(this.registry.inline.takeDrift()||e.effects.some(f=>f.kind!=="spliceText")&&Ud(this.registry,r.plan))&&this.publishSharedToPort(false,true);return}this.refuseLocalJournal(c,a);}refuseLocalJournal(e,n=false){this.historyGroups.refused(),this.undoManager.stopCapturing();let o=this.statusState.snapshot();this.refusals.refusedOne(n);let r=this.refusals.recoverable()?Is(o):null;this.setStatus("error",e.code,e.detail,r),this.publishSharedToPort(true,true),this.realignedInBatch=true,queueMicrotask(()=>{this.realignedInBatch=false;});let i=this.statusState.snapshot().reason;this.refusals.recoverable()&&this.statusState.status()==="error"&&i!==void 0&&i.code===e.code&&i.detail===e.detail&&(o.status==="ready"||o.status==="disconnected")&&this.setStatus(o.status,o.reason?.code,o.reason?.detail);}onBeforeYjsTransaction=e=>{e.origin===this.localOrigin?this.caretAnchors.localChange():this.caretAnchors.beforeChange();};remoteSelectionMove(){return this.caretAnchors.move()}onYjsTransaction=e=>{this.destroyed||!this.hasCompatibleSharedSchema()||(this.canWriteSharedState()&&Kd(e,this.registry.schema.nodes,this.undoManager),this.port&&e.origin!==this.localOrigin&&this.publishSharedToPort(false,e.origin===this.undoManager));};publishSharedToPort(e=false,n=false){let o=this.port;if(!(!o||this.applyingRemote)){this.applyingRemote=true;try{if(!this.hasCompatibleSharedSchema())return;let r=lr(this.registry,this.blobs);if(r){this.setStatus("error",r.code,r.detail);return}let i=Ve(this.ydoc);i||(this.fullRefusedWhileWaiting=!1);let s=e?this.materializer.rebuildFull():this.materializer.current(),a=this.blobs.poisonedDigest();if(a){this.setStatus("error","blob-digest-mismatch",a);return}if(this.viewWaiting=!1,!s.ok){i?this.viewWaiting=!0:this.degrade(s.code);return}let l=vt(s.issues);if(l){i?this.viewWaiting=!0:this.degrade("materialize-dropped-content",l);return}let d=f=>(this.remoteCounter+=1,o.applyRemotePackage(f,{origin:ORIGIN_IDS.mutationRemote,actorId:n?this.currentIdentity.actorId:"remote",operationId:`${this.sessionId}:remote:${this.remoteCounter}`})),c=d(s.package);if(!c.ok&&!(i&&this.fullRefusedWhileWaiting)){let f=this.materializer.rebuildFull();f.ok&&!vt(f.issues)&&(c=d(f.package)),!c.ok&&i&&(this.fullRefusedWhileWaiting=!0);}if(!c.ok){i?this.viewWaiting=!0:this.degrade("remote-apply-failed",c.reason);return}c.changed&&this.identityMap.reset(),this.caretAnchors.afterPublish();let u=this.healTo;u!==null&&this.setStatus(u.status,u.code,u.detail);}catch(r){this.degrade(r instanceof N?r.code:"remote-apply-failed",r instanceof N?r.detail:void 0);}finally{this.applyingRemote=false,this.drainJournalsHeldDuringRemote(),this.editWait.refresh();}}}drainJournalsHeldDuringRemote(){if(!this.drainingHeldJournals){this.drainingHeldJournals=true;try{for(;this.journalsHeldDuringRemote.length>0;){if(this.destroyed||this.realignedInBatch){this.journalsHeldDuringRemote.length=0;return}let e=this.journalsHeldDuringRemote.shift();e&&this.applyJournal(e);}}finally{this.drainingHeldJournals=false;}}}onAwarenessChange=()=>{if(this.destroyed)return;let e=this.remoteSelections();for(let o of [...this.selectionListeners])o(e);let n=this.participants();for(let o of [...this.participantListeners])o(n);};publishAwareness(e){this.currentSelection=e;let n={actorId:this.identity.actorId,name:this.identity.name,...this.identity.color?{color:this.identity.color}:{},role:this.identity.role??"human",...e?{selection:e}:{}};this.awareness.setLocalStateField(pn,n);}degrade(e,n){this.setStatus("error",e,n,this.healTo??Is(this.statusState.snapshot()));}setStatus(e,n,o,r=null){this.healTo=e==="error"?r:null,this.statusState.set(e,n,o,this.healTo!==null)&&this.notifyStatus();}notifyStatus(){let e=this.statusState.snapshot();for(let n of [...this.statusListeners])n(e.status,e.reason?.code,e.reason?.detail);}};async function bO(t){return Qu(t,e=>new Rs(e.ydoc,e.awareness,e.documentId,e.sessionId,e.identity,e.registry,e.materializer,e.identityMap,e.blobs,e.attachWatchdogMs,e.offlineEditing))}
|
|
16
|
+
export{Cs as a,N as b,It as c,Ab as d,vr as e,rt as f,$o as g,vu as h,Mu as i,hn as j,gt as k,zu as l,Zy as m,Wu as n,IR as o,mt as p,Sb as q,jR as r,bO as s};
|