@docx-editor.dev/pro 2.27.0 → 2.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-CNXDNDD3.js +1 -0
- package/dist/{chunk-PVRTSPHN.cjs → chunk-FD2KDBHX.cjs} +1 -1
- package/dist/chunk-JRHEYVVY.cjs +1 -0
- package/dist/chunk-L567WP3J.js +5 -0
- package/dist/chunk-MJECUVHQ.cjs +5 -0
- package/dist/chunk-MWO2ZUEJ.js +1 -0
- package/dist/chunk-N34IUO36.cjs +1 -0
- package/dist/chunk-OT5R3IYV.cjs +1 -0
- package/dist/chunk-P2EF7WMV.js +1 -0
- package/dist/chunk-Q5JTCGJI.js +1 -0
- package/dist/chunk-SNQCYZLT.js +1 -0
- package/dist/chunk-ZSAAX6HV.cjs +1 -0
- package/dist/collaboration/hocuspocus.cjs +1 -1
- package/dist/collaboration/hocuspocus.d.cts +18 -11
- package/dist/collaboration/hocuspocus.d.ts +18 -11
- package/dist/collaboration/hocuspocus.js +1 -1
- package/dist/collaboration/index.cjs +2 -2
- package/dist/collaboration/index.d.cts +333 -18
- package/dist/collaboration/index.d.ts +333 -18
- package/dist/collaboration/index.js +2 -2
- package/dist/collaboration/webrtc.cjs +2 -2
- package/dist/collaboration/webrtc.d.cts +26 -3
- package/dist/collaboration/webrtc.d.ts +26 -3
- package/dist/collaboration/webrtc.js +2 -2
- package/dist/{collaboration-module-DlSv0oAd.d.cts → collaboration-module-DWn2heE1.d.cts} +1 -0
- package/dist/{collaboration-module-DlSv0oAd.d.ts → collaboration-module-DWn2heE1.d.ts} +1 -0
- package/dist/{define-custom-node-DUJ4ZZdo.d.ts → define-custom-node-CNRQG1TI.d.cts} +12 -4
- package/dist/{define-custom-node-DG5gpRa5.d.cts → define-custom-node-D0c36PpZ.d.ts} +12 -4
- package/dist/document-session-3VC43WNI.cjs +1 -0
- package/dist/{document-session-BKKfJzKB.d.cts → document-session-Bxs4_GgX.d.ts} +55 -33
- package/dist/document-session-J2YKWERI.js +1 -0
- package/dist/{document-session-BQ4nBDTd.d.ts → document-session-_v9vqiSX.d.cts} +55 -33
- package/dist/document-session-options-CfKypp9c.d.cts +37 -0
- package/dist/document-session-options-DelOC7PX.d.ts +37 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +29 -4
- package/dist/index.d.ts +29 -4
- package/dist/index.js +1 -1
- package/dist/react/hocuspocus.cjs +1 -1
- package/dist/react/hocuspocus.d.cts +52 -8
- package/dist/react/hocuspocus.d.ts +52 -8
- package/dist/react/hocuspocus.js +1 -1
- package/dist/react/index.cjs +2 -2
- package/dist/react/index.d.cts +354 -156
- package/dist/react/index.d.ts +354 -156
- package/dist/react/index.js +2 -2
- package/dist/react/webrtc.cjs +1 -1
- package/dist/react/webrtc.d.cts +35 -7
- package/dist/react/webrtc.d.ts +35 -7
- package/dist/react/webrtc.js +1 -1
- package/dist/{session-okdqygLg.d.cts → types-6EmrEn4n.d.cts} +26 -4
- package/dist/{session-okdqygLg.d.ts → types-6EmrEn4n.d.ts} +26 -4
- package/dist/{session-B-ds4k64.d.cts → types-BQ1vBt5Q.d.cts} +32 -54
- package/dist/{session-B-ds4k64.d.ts → types-BQ1vBt5Q.d.ts} +32 -54
- package/dist/vue/hocuspocus.cjs +1 -1
- package/dist/vue/hocuspocus.d.cts +52 -7
- package/dist/vue/hocuspocus.d.ts +52 -7
- package/dist/vue/hocuspocus.js +1 -1
- package/dist/vue/index.cjs +2 -2
- package/dist/vue/index.d.cts +235 -24
- package/dist/vue/index.d.ts +235 -24
- package/dist/vue/index.js +2 -2
- package/dist/vue/webrtc.cjs +1 -1
- package/dist/vue/webrtc.d.cts +36 -6
- package/dist/vue/webrtc.d.ts +36 -6
- package/dist/vue/webrtc.js +1 -1
- package/package.json +5 -5
- package/dist/chunk-6CDC4KCE.js +0 -4
- package/dist/chunk-6SR5OK66.cjs +0 -4
- package/dist/chunk-GDTCNTK7.cjs +0 -1
- package/dist/chunk-HJB77VBO.js +0 -1
- package/dist/chunk-HZEWGK5A.cjs +0 -4
- package/dist/chunk-Q4YPX2DT.cjs +0 -1
- package/dist/chunk-Q7P2DQ33.js +0 -1
- package/dist/chunk-RGR2BLZD.js +0 -4
- package/dist/chunk-W3V54DWZ.js +0 -1
- package/dist/document-session-32FPPQHT.js +0 -1
- package/dist/document-session-32ULDU2C.js +0 -1
- package/dist/document-session-HCU2O55L.cjs +0 -1
- package/dist/document-session-ZOM2KHHX.cjs +0 -1
- package/dist/hocuspocus-BMF7MTMJ.js +0 -1
- package/dist/hocuspocus-JPJOC6ZV.cjs +0 -1
- package/dist/webrtc-MM3LDVLU.cjs +0 -2
- package/dist/webrtc-RYONN7E7.js +0 -2
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import*as B from'yjs';import {XML_NAMESPACE_URI,WML_NAMESPACE_URI,partNameKey,readOoxmlPackage,isStoryPart,normalizeParagraphIdentity,withPart,TreePackageStore,writeOoxmlPackage,isDangerousKey,normalizePartName,relsPartNameFor,CUSTOM_XML_PROPS_TYPE,ORIGIN_IDS,resolveInternalTarget,DATASTORE_NAMESPACE_URI,CUSTOM_XML_REL,CUSTOM_XML_PROPS_REL,resolveContentType,isRangeMarkerKind,buildRelationshipSet,resolveRelationship,segmentsOf}from'@docx-editor.dev/core/store';import {historyGroupOfJournal,reportHistoryGroup,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 Jr(t,e){return {...t,projectedTarget:e}}function _e(t){return t.projectedTarget}function Xr(t){let e=n=>{n._needFormattingCleanup=false;};return t.on("afterTransaction",e),()=>t.off("afterTransaction",e)}function Hr(t,e,n){let o=t.doc;if(!o){t.delete(e,n);return}B.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=B.getItemCleanStart(r,B.createID(a.id.client,a.id.clock+i)),i=0),s<l.length&&B.getItemCleanStart(r,B.createID(l.id.client,l.id.clock+s)),s-=l.length,l.delete(r),a=l;}}),t._searchMarker&&(t._searchMarker.length=0);}function Ot(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}B.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],p=u+1;for(i+=1;i<n.length&&n[i]===p&&p<l;)p+=1,i+=1;let f=d;u>c&&(f=B.getItemCleanStart(r,B.createID(d.id.client,d.id.clock+(u-c)))),p-u<f.length&&B.getItemCleanStart(r,B.createID(f.id.client,f.id.clock+(p-u))),f.delete(r),d=p<l?f.right:f,c=p;}a=d,s=l;}}),t._searchMarker&&(t._searchMarker.length=0);}function fo(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 ho(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;}Ot(t,o);}function qr(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 B.ContentEmbed?o:null;if(n+=o.length,n>e)return null}return null}function Gr(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 Zr(t,e){let n=t.doc;!n||e.deleted||(B.transact(n,o=>e.delete(o)),t._searchMarker&&(t._searchMarker.length=0));}function Vt(t){return t._start}function le(t,e){let n;try{n=B.getItem(t.store,B.createID(e.client,e.clock));}catch{return null}return n instanceof B.Item?n:null}function*Jt(t,e){let n=t.clientID,o=B.getState(t.store,n);for(let r=e;r<o;){let i=B.getItem(t.store,B.createID(n,r));r=i.id.clock+i.length,i instanceof B.Item&&(yield i);}}function Wl(t,e){for(let n of Jt(t,e))if(n.content instanceof B.ContentString)return n;return null}function st(t,e,n,o){let r=t.doc,i=r?B.getState(r.store,r.clientID):0;return typeof n=="string"?t.insert(e,n,{...o}):t.insertEmbed(e,n,{...o}),r?typeof n=="string"?Wl(r,i):Vl(r,i):null}function Vl(t,e){for(let n of Jt(t,e))if(n.content instanceof B.ContentEmbed)return n;return null}function Be(t){return t._item?.parentSub??null}function Ee(t){return t instanceof B.AbstractType?t._item:null}function Xt(t){return t._item?.id??null}function Ce(t,e){return t._map.get(e)}function mo(t){return t.store.pendingStructs?.update??null}function xe(t){return t.store.pendingStructs!==null||t.store.pendingDs!==null}function Ht(t,e){for(let[n,o]of t.changed)if(n===e)return o;return null}function at(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 P(t){return t.id}var Jl=16,Qr=16,Xl=new Set(["paraId","textId","id","numId","bookmarkId"]);function ei(t){let e="";for(let n of t)e+=n.toString(Jl).padStart(2,"0");return e}function Hl(t){let e=new Uint8Array(Qr);return globalThis.crypto.getRandomValues(e),ei(e)}function go(t){return /^[0-9a-f]{32}$/.test(t)}function ql(t,e){if(!go(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 fe(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 lt(t,e){let n=t?fe(t):null,o=e?fe(e):null;return n!==null&&o!==null&&n.client===o.client&&n.clock+1===o.clock}function ti(t,e){return `yjs:${t}:${e}`}function Ct(t){if(!t.startsWith("lid:"))return null;let e=t.slice(4,t.indexOf(":",4));return go(e)?e:null}function ni(t){let e=[];for(let n of t)Xl.has(n.localName)&&e.push(n.value);return e}var Et=class{replicaId;next=0;constructor(e){if(this.replicaId=e??Hl(),!go(this.replicaId))throw new Error("invalid replica identity")}take(){let e=ql(this.replicaId,this.next);return this.next+=1,e}get counter(){return this.next}};var Ue=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}),Zl=/^sha256:[0-9a-f]{64}$/;function ri(t){return t?Object.freeze({...Ue,...t}):Ue}function L(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 Z(t){let e=L(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 ii(t){for(let e of Object.keys(t)){let n=L(e);if(n)return n}return !Zl.test(t.digest)||!Number.isSafeInteger(t.size)||t.size<0?"invalid-blob-descriptor":t.size>Ue.maxBlobBytes?"blob-too-large":re(t.mediaType,Ue.maxMediaTypeLength)||t.mediaType.length===0||re(t.storageKey,Ue.maxStorageKeyLength)||t.storageKey.length===0?"invalid-blob-descriptor":null}var Ql="https://www.docx-editor.dev/docs/2.x/pro/collaboration-versions",T=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}
|
|
2
|
+
Collaboration upgrade required. Save local changes and use a compatible app version, or upgrade the saved room. See ${Ql}#upgrade-saved-rooms`:i);this.code=n;this.detail=o;this.name="CollaborationSchemaError";}code;detail};var Fe=Object.freeze({protocolVersion:1,sharedSchemaVersion:4,repairVersion:2,canonicalModelVersion:1});function yo(t){let e=t!==null&&typeof t=="object"&&!Array.isArray(t)?t:{};for(let n of Object.keys(Fe)){let o=Fe[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 Df(t){let e=yo(t);if(e)throw new T(e.code,e.detail)}var ed=Fe.protocolVersion,td=Fe.sharedSchemaVersion,nd=Fe.repairVersion,od=Fe.canonicalModelVersion,bo="docx-package-meta-v1",xo="docx-package-nodes-v1",rd="docx-package-parts-v1",id="docx-package-rels-v1",sd="docx-package-overrides-v1",ad="docx-package-defaults-v1",ld="docx-package-binaries-v1",dd="docx-package-namespaces-v1",cd="docx-package-attributes-v1",ud="docx-package-bindings-v1",qt="s",Gt="b",de="t",Zt="children",Ie="deleted",je="replacedBy",ze="undone",Tt="splitFrom",$e="splitLineage";var ee="",ai="-",li=Object.freeze({kind:"docx-package-bootstrap"}),Io=Object.freeze({kind:"docx-package-journal"});function Ke(t){return t.kind==="textValue"}function F(t){return !Ke(t)}var pd=Object.freeze(new Set(["missing-node","child-id-not-in-registry","cycle"])),fd=200;function Pt(t){let e=new Map;for(let n of t)pd.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,fd)}function di(t){return {meta:t.getMap(bo),nodes:t.getMap(xo),parts:t.getMap(rd),relationships:t.getMap(id),overrides:t.getMap(sd),defaults:t.getMap(ad),binaries:t.getMap(ld),namespaces:t.getMap(dd),attributes:t.getMap(cd),bindings:t.getMap(ud)}}var ci=[["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"]],hd=new Map(ci),md=new Map(ci.map(([t,e])=>[e,t]));function gd(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 We(t){return t.length===0?ai:hd.get(t)??`n${gd(t)}`}function dt(t,e,n){let o=We(e);return e.length===0||L(o)||re(e,n)||t.get(o)!==e&&t.set(o,e),o}function Ve(t,e){if(e===ai||L(e))return "";let n=t.get(e);return typeof n=="string"?n:md.get(e)??""}function So(t,e,n,o){return `${t}${ee}${e}${ee}${n}${ee}${o}`}function yd(t){let e=t.split(ee);return {kind:e[0]||"generic",namespaceId:e[1]??"",localName:e[2]??"",prefix:e[3]??""}}function Se(t){let e=t.has(qt)?t.get(qt):t.get(Gt);return yd(typeof e=="string"?e:"")}function wo(t,e,n){return `${t}${ee}${e}${ee}${n}`}function Nt(t){let e=t.split(ee);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 vo(t,e){return `${t}${ee}${e}`}function Je(t){let e=t.split(ee);if(e.length!==2)return null;let n=e[0],o=e[1];return n.length===0?null:{logicalId:n,prefix:o}}function ui(t,e){return `${t}${ee}${e}`}function pi(t){let e=t.indexOf(ee);return e<0?{prefix:"",value:t}:{prefix:t.slice(0,e),value:t.slice(e+1)}}function fi(t){let e=new B.Map,n=So(t.kind,t.namespaceId,t.localName,t.prefix??"");e.set(Gt,n);let o=new B.Array;return t.childIds&&t.childIds.length>0&&o.push([...t.childIds]),e.set(Zt,o),e}function Qt(t){let e=new B.Map;return e.set(de,new B.Text(t)),e}function hi(t,e,n){let o=new B.Map;return o.set("id",t),o.set("rootId",e),o.set("contentType",n),o}function mi(t){let e=new B.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 gi(t){let e=new B.Map;return e.set("digest",t.digest),e.set("size",t.size),e.set("mediaType",t.mediaType),e.set("storageKey",t.storageKey),e}function en(t){return yo({protocolVersion:t.get("protocolVersion"),sharedSchemaVersion:t.get("sharedSchemaVersion"),repairVersion:t.get("repairVersion"),canonicalModelVersion:t.get("canonicalModelVersion")})}function yi(t){t.set("protocolVersion",ed),t.set("sharedSchemaVersion",td),t.set("repairVersion",nd),t.set("canonicalModelVersion",od),t.set("initialized",true);}function bi(t,e){let n=Ce(t,e);return n!==void 0&&n.deleted}function ko(t){return mo(t)!==null}var si=new WeakMap,bd={origins:new Set,fields:new Set};function xi(t){let e=mo(t);if(e===null)return bd;let n=si.get(e);if(n)return n;let o=new Set,r=new Set;try{for(let s of B.decodeUpdateV2(e).structs)s instanceof B.Item&&(s.origin&&o.add(`${s.origin.client}:${s.origin.clock}`),s.parent instanceof B.ID&&s.parentSub!==null&&r.add(`${s.parent.client}:${s.parent.clock}:${s.parentSub}`));}catch{}let i={origins:o,fields:r};return si.set(e,i),i}function Ii(t,e){if(t.has(e)||t.doc===null)return false;let n=Xt(t);return n!==null&&xi(t.doc).fields.has(`${n.client}:${n.clock}:${e}`)}function Lo(t,e){if(t.has(e)||t.doc===null||!ko(t.doc))return false;let n=Ce(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 xi(t.doc).origins.has(`${o.client}:${o.clock}`)}function N(t){return t instanceof B.Map}function te(t){if(!N(t))return null;let e=t.get(Zt);return e instanceof B.Array?e:null}function ct(t){return N(t)&&t.get(de)instanceof B.Text}function we(t){return N(t)&&t.get(Ie)===true}function tn(t){return N(t)&&t.get(ze)===true}function nn(t){return Ro(t,je)}function Ro(t,e){if(!N(t))return null;let n=t.get(e);return typeof n=="string"&&n.length>0?n:null}function Si(t,e){let n=o=>{let r=t.get(o);return N(r)?Ce(r,je)?.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 At(t){return Ro(t,Tt)}function Xe(t){return Ro(t,$e)??At(t)}function vi(t,e){let n=t.get(e);if(!N(n))return null;if(ct(n)){let o=n.get(de);return {isText:true,textLength:o instanceof B.Text?o.length:0,children:[]}}return {isText:false,textLength:0,children:te(n)?.toArray()??[]}}function ki(t,e){let n=t.get(e);return N(n)?ct(n)?"textValue":Se(n).kind:null}function on(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 Li(t,e,n,o,r){let i=Se(e);return {logicalId:t,kind:i.kind,namespaceUri:Ve(n.namespaces,i.namespaceId),localName:i.localName,prefix:i.prefix.length>0?i.prefix:void 0,attributes:o,bindings:r,childIds:te(e)?.toArray()??[]}}function Ri(t){let e=Xt(t);return e&&ti(e.client,e.clock)}function Oi(t){return typeof t=="string"?t:""}function W(t){return String(t)}function Eo(t){return !L(t)}function Ei(t){t.forEach(e=>{if(N(e)&&(e.has("parent")||e.has("parentId")))throw new Error("registry record must not replicate a parent field")});}function ce(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 ve(t,e,n=t.id){return {...t,id:n,children:e}}function Ci(t){return t.kind!=="textValue"}function Ti(t){return t.filter(Ci)}function ut(t){if(!Ci(t))throw new Error(`expected an element, found text node ${t.id}`);return t}function rn(t,e,n,o=[]){return Object.freeze(ce({id:t,kind:e,namespaceUri:WML_NAMESPACE_URI,localName:n,prefix:"w",namespaceBindings:Object.freeze([]),attributes:Object.freeze([...o]),children:Object.freeze([])}))}function sn(t){return ce({id:t,kind:"generic",namespaceUri:"",localName:"",namespaceBindings:[],attributes:[],children:[]})}function pt(t,e){return {id:t,kind:"textValue",value:e}}function ft(t){return t}var Sd=new Set(["t","delText","instrText","delInstrText"]),wd=new Set(["hyperlink","ins","del","moveFrom","moveTo","sdt","sdtContent","fldSimple","smartTag","customXml","dir","bdo"]),vd=new Set(["sdtPr","sdtEndPr","smartTagPr","customXmlPr","fldData"]);function Co(t,e){return t.kind!=="textValue"&&t.namespaceUri===WML_NAMESPACE_URI&&e.has(t.localName)}function ht(t,e=[]){return ve(t,e)}function kd(t){return Co(t,Sd)&&t.children.every(e=>e.kind==="textValue")}function ln(t){let e=[],n=[],o={run:null,runProperties:null,properties:[],text:null,textValueId:null,wrap:[]},r=(a,l)=>{let d=a.children.find(p=>p.kind==="runProperties"),c={...o,run:ht(a),runProperties:d?ht(d):null,properties:d?Ti(d.children):[],wrap:l},u=0;for(let p of a.children)if(p!==d)if(u+=1,kd(p)){let f=p.children.map(g=>g.kind==="textValue"?g.value:"").join(""),h={...c,text:ht(p),textValueId:p.children[0]?.id??null};f.length===0&&e.push({kind:"anchor",attributes:h});for(let g=0;g<f.length;g+=1)e.push({kind:"char",value:f[g],attributes:h});}else e.push({kind:"embed",node:p,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(Co(d,wd)){let c=d.children.filter(f=>Co(f,vd)),u=[...l,ht(d,c)],p=d.children.filter(f=>!c.includes(f));p.length===0&&e.push({kind:"anchor",attributes:{...o,wrap:u}}),i(p,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 an(t){return {shell:t,children:[...t.children],openRun:null,openText:null}}function Ld(t){return t.runSignature!==void 0?t.runSignature:[t.run.id,t.runProperties?.id??"",...t.properties.map(e=>e.id)].join("")}function Pi(t){let e=an(t.shell),n=[e],o=s=>{let a=s.openText;a&&(a.value.length>0&&a.builder.children.push(pt(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 x=an(a[h]);x.signature=l?.[h],g.children.push(x),n.push(x);}let u=n[n.length-1];if(!s.attributes.run){r(u),s.kind==="embed"&&u.children.push(s.node);continue}let p=Ld(s.attributes);if(u.openRun?.key!==p){r(u);let h=an(s.attributes.run);s.attributes.runProperties&&h.children.push(ht(s.attributes.runProperties,s.attributes.properties)),u.children.push(h),u.openRun={key:p,builder:h};}let f=u.openRun.builder;if(s.kind==="embed"){o(f),f.children.push(s.node);continue}if(s.attributes.text){if(f.openText?.key!==s.attributes.text.id){o(f);let h=an(s.attributes.text);f.children.push(h),f.openText={key:s.attributes.text.id,builder:h,valueId:s.attributes.textValueId??`${s.attributes.text.id}/value`,value:""};}s.kind==="char"&&(f.openText.value+=s.value);}}for(;n.length>0;)r(n.pop());let i=s=>"shell"in s?Object.freeze(ve(s.shell,Object.freeze(s.children.map(i)))):s;return ut(i(e))}var No={kind:"run",localName:"r"},dn={kind:"runProperties",localName:"rPr"},Ao={kind:"text",localName:"t"},cn=32768,He=24;function Ni(t,e=0){if(e>He)return 1/0;if(!Te(t))return 1;let n=t.c,o=1;if(Array.isArray(n))for(let r of n)o+=Ni(r,e+1);return o}var he=class extends Error{constructor(n,o){super(`shared text value refused (${n}): ${o}`);this.code=n;this.detail=o;}code;detail};function Mo(t,e,n=0){if(n===0&&Ni(t)>cn)return "too-many-nodes";if(n>He)return "tree-too-deep";if(!Te(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"&&L(a))return "prototype-key"}}}for(let r of ["l","k","p"]){let i=t[r];if(typeof i=="string"&&L(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=Mo(r,e,n+1);if(i!=="invalid-string"||Mt(r,e))return i}}return "invalid-string"}function Mt(t,e){return typeof t=="string"?t.length>e.maxStringLength:Array.isArray(t)?t.some(n=>Mt(n,e)):Te(t)?Object.entries(t).some(([n,o])=>n==="v"?false:Mt(o,e)):false}var Ai=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"]]),Rd=new Map([...Ai].map(([t,e])=>[e,t]));function Dt(t){return t===WML_NAMESPACE_URI?"":Ai.get(t)??t}function Yt(t){return t===""?WML_NAMESPACE_URI:t.startsWith("#")?Rd.get(t)??null:t}function un(t){if(t===WML_NAMESPACE_URI)return "w";if(t===XML_NAMESPACE_URI)return "xml"}var To=/^(.*:)(\d{1,15})$/;function Do(t,e){if(t===e)return "=";if(e.length>0&&t.startsWith(e))return `^${t.slice(e.length)}`;let n=To.exec(t),o=To.exec(e);return n&&o&&n[1]===o[1]?`+${Number(n[2])-Number(o[2])}`:/^[=^+!]/.test(t)?`!${t}`:t}function Yo(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=To.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||L(o)?null:o}function Mi(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 Od(t){let e=[t.localName,t.value],n=t.prefix,o=Mi(t.namespaceUri,t.localName,n,t.value),r=[Dt(t.namespaceUri),n===un(t.namespaceUri)?"":n??null,t.kind===o?"":t.kind];for(;r.length>0&&r[r.length-1]==="";)r.pop();return [...e,...r]}function _t(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=Dt(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!==un(t.namespaceUri)&&(o.p=t.prefix??""),t.attributes.length>0&&(o.a=t.attributes.map(Od)),t.namespaceBindings.length>0&&(o.b=t.namespaceBindings.map(a=>[a.prefix,Dt(a.namespaceUri)])),n&&t.children.length>0&&(o.c=t.children.map(a=>_t(a,null,true))),o}function Te(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function ge(t,e){return typeof t=="string"&&t.length<=e.maxStringLength}function Ed(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(!ge(r,e)||L(r)||!ge(i,e)||!ge(s,e))return null;let d=Yt(s);if(d===null||a!==null&&!ge(a,e))return null;let c=a===""?un(d):a??void 0;if(c!==void 0&&L(c)||!ge(l,e))return null;let u=l||Mi(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 Cd(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(!ge(r,e)||!ge(i,e)||L(r))return null;let s=Yt(i);if(s===null)return null;n.push(Object.freeze({prefix:r,namespaceUri:s}));}return Object.freeze(n)}function pn(t,e,n,o,r,i){if(r.nodes+=1,r.nodes>cn||i>He||!Te(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(pt(e,t.v));let s=t.l??n?.localName;if(!ge(s,o)||L(s))return null;let a=t.n??"";if(!ge(a,o))return null;let l=Yt(a);if(l===null)return null;let d=n&&s===n.localName&&l===WML_NAMESPACE_URI?n.kind:"generic",c=t.k??d;if(!ge(c,o)||L(c))return null;let u=un(l);if(t.p!==void 0){if(!ge(t.p,o)||L(t.p))return null;u=t.p===""?void 0:t.p;}let p=Ed(t.a,o),f=Cd(t.b,o);if(!p||!f)return null;let h=t.c??[];if(!Array.isArray(h)||h.length>o.maxChildren)return null;let g=[];for(let x=0;x<h.length;x+=1){let S=pn(h[x],`${e}~${x}`,null,o,r,i+1);if(!S)return null;g.push(S);}return Object.freeze(ce({id:e,kind:c,namespaceUri:l,localName:s,namespaceBindings:f,attributes:p,children:Object.freeze(g),...u===void 0?{}:{prefix:u}}))}var ne="inline",_o="r",gt="rp",Ui="t",Fi="w",Bo="p:";function Uo(t){return t.kind!=="embed"?{a:1}:t.attributes.run?{n:t.node.id,r:1}:{n:t.node.id}}function fn(t,e,n,o={}){return {i:Do(t.id,e),..._t(t,n,false),...o}}function Nd(t){let e=new Map;return t.map(n=>{let o=Dt(n.namespaceUri),r=`${Bo}${o===""?"":`${o}|`}${n.localName}`,i=(e.get(r)??0)+1;return e.set(r,i),i===1?r:`${r}#${i}`})}function ji(t){let e=t.slice(Bo.length).replace(/#\d+$/,""),n=e.indexOf("|"),o=Yt(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 Ge(t,e,n){let o={},r=t.run;if(r&&(o[_o]=JSON.stringify(fn(r,e,No))),r&&t.runProperties){let i=Nd(t.properties);o[gt]=JSON.stringify(fn(t.runProperties,e,dn,{o:i})),t.properties.forEach((s,a)=>{let l={kind:"generic",localName:s.localName};o[i[a]]=JSON.stringify(_t(s,l,true));});}if(t.text){let i=t.text.id,s=t.textValueId??`${i}~v`,a=s===`${i}~v`?{}:{v:Do(s,i)};o[Ui]=JSON.stringify(fn(t.text,e,Ao,a));}if(t.wrap.length>He)throw new he("tree-too-deep",`${t.wrap.length} nested wrappers`);return t.wrap.length>0&&(o[Fi]=JSON.stringify(t.wrap.map(i=>fn(i,e,null,{c:i.children.map(s=>_t(s,null,true))})))),Object.values(o).some(i=>Ad(i,n))&&Dd(t,o,e,n),o}function Ad(t,e){let n=Math.min(e.maxStringLength,e.maxAttributes,e.maxChildren,e.maxTextLength,cn);if(t.length>n||Md.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*He+2)return true}else (i===125||i===93)&&(o-=1);}return false}var Md=/__proto__|constructor|prototype/;function Dd(t,e,n,o){let r=ue(e,o,n);if(!((e[gt]===void 0||Bt(qe(e[gt]),n,dn,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=qe(a),d=Array.isArray(l)?l:[l];for(let c of d){let u=Mo(c,o);if(u!=="invalid-string"||Mt(c,o))throw new he(u,`${s} of an item in ${n}`)}}throw new he("invalid-string",`an item in ${n}`)}}function zi(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=Ge(s.attributes,e,n);if(s.kind==="char"){let l=oe(a);r&&r.signature===l?r.text+=s.value:(i(),r={text:s.value,attributes:a,signature:l});continue}i(),o.push({insert:Uo(s),attributes:a});}return i(),o}function oe(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 qe(t){if(typeof t=="string")try{return JSON.parse(t)}catch{return}}function Bt(t,e,n,o,r=false){if(!Te(t))return null;let i=Yo(t.i,e,o);if(!i)return null;let{i:s,v:a,o:l,c:d,...c}=t,u=pn(r?{...c,c:d}:c,i,n,o,{nodes:0},0);return !u||u.kind==="textValue"?null:{shell:u,data:t}}var Di=["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 Yi(t){let e=ji(t),n=e?.namespaceUri===WML_NAMESPACE_URI?Di.indexOf(e.localName):-1;return n<0?Di.length-1:n}function Yd(t,e){return Yi(t)-Yi(e)||(t<e?-1:t>e?1:0)}function _d(t){return rn(t,"runProperties","rPr")}var _i=new WeakMap,Bd=4096;function ue(t,e,n){let o=JSON.stringify([n,oe(t)]),r=_i.get(e);r||_i.set(e,r=new Map);let i=r.get(o);if(i)return i;let s=Ud(t??{},e,n);return r.size>=Bd&&r.clear(),r.set(o,s),s}function Ud(t,e,n){let o=Bt(qe(t[_o]),n,No,e),r=o?Bt(qe(t[gt]),n,dn,e):null,i=[],s=[],a=o?Object.keys(t).filter(S=>S.startsWith(Bo)).sort().slice(0,e.maxChildren):[],l={nodes:0},d=r?.shell??(o&&a.length>0?_d(`${o.shell.id}~rPr`):null);if(o&&d){let S=Array.isArray(r?.data.o)?r.data.o:[],v=a.every(m=>S.includes(m))?S.filter(m=>typeof m=="string"&&a.includes(m)):[...a].sort(Yd);for(let m of v){let w=ji(m);if(!w||L(m))continue;let I=pn(qe(t[m]),`${d.id}~${m}`,{kind:"generic",localName:w.localName},e,l,0);I&&I.kind!=="textValue"&&(i.push(I),s.push(m));}}let c=qe(t[Ui]),u=Bt(c,n,Ao,e),p=u?(Te(c)&&c.v!==void 0?Yo(c.v,u.shell.id,e):null)??`${u.shell.id}~v`:null,f=qe(t[Fi]),h=[],g=[];if(Array.isArray(f)&&f.length<=He)for(let S of f){let v=Bt(S,n,null,e,true);if(!v)break;h.push(v.shell),g.push(JSON.stringify(S));}let x=o?JSON.stringify([t[_o],typeof t[gt]=="string"?t[gt]:"",...s.map(S=>[S,t[S]])]):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:p,wrap:Object.freeze(h),...x!==void 0?{runSignature:x}:{},wrapSignatures:Object.freeze(g)})}function Fo(t,e,n,o,r={}){let i=[],s=[],a=c=>{for(let u of c.entries){for(let p of u.slot?.before??[])a(p);u.item&&(i.push(u.item),s.push(u.placement),u.item.kind==="char"&&r.onCharacter?.(u.character??null));for(let p of u.slot?.after??[])a(p);}},l=(c,u=false)=>{let p=r.following?.at.get(c);for(let f of (u?p?.before:p?.after)??[])a(f);},d=0;for(let c of t){let u=ue(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)||!Te(c.insert))continue;if(c.insert.a===1){i.push({kind:"anchor",attributes:u}),s.push(void 0);continue}let p=c.insert.n;if(typeof p!="string"||L(p))continue;let f=e(p);f&&(i.push({kind:"embed",node:f,attributes:u}),s.push(c.insert.r===1));}for(let c of r.following?.atEnd??[])a(c);return $d(i,s,o,r.onRepair)}function $i(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 p=2;for(;o.has(`${l}~${p}`);)p+=1;l=`${l}~${p}`;}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(p=>r(p,d));return d===null&&c.every((p,f)=>p===i.children[f])?i:Object.freeze(ve(i,Object.freeze(c),l))};return ut(r(t,null))}function Fd(t,e){return t.kind==="char"||t.kind==="embed"&&e===true}function Bi(t){return t.kind==="char"}function jd(t){return Object.freeze({run:null,runProperties:null,properties:Object.freeze([]),text:null,textValueId:null,wrap:t.wrap,...t.wrapSignatures?{wrapSignatures:t.wrapSignatures}:{}})}function zd(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 $d(t,e,n,o){let r=(d,c)=>Fd(d,e[c])&&!d.attributes.run||d.kind==="embed"&&e[c]===false&&d.attributes.run!==null||Bi(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 p=t[d-u];if(p&&c(p,d-u))return p;let f=t[d+u];if(f&&c(f,d+u))return f;if(!p&&!f)break}return null},s=(d,c)=>d.attributes.run!==null&&!(d.kind==="embed"&&e[c]===false),a=rn(`${n}~r`,"run","r"),l=[];return t.forEach((d,c)=>{if(!r(d,c)){l.push(d);return}let u=d.attributes;if(d.kind==="embed"&&e[c]===false){l.push({...d,attributes:jd(u)});return}if(!u.run){let p=i(c,s);u=zd(u,p?.attributes??null,a);}if(Bi(d)&&!u.text){let p=u.run,f=i(c,h=>h.kind==="char"&&h.attributes.run?.id===p.id&&!!h.attributes.text);u=Object.freeze({...u,text:f?.attributes.text??rn(`${p.id}~t`,"text","t",[Object.freeze({kind:"xmlSpace",namespaceUri:XML_NAMESPACE_URI,localName:"space",prefix:"xml",value:"preserve"})]),textValueId:f?.attributes.textValueId??null});}l.push({...d,attributes:u});}),l}var Kd=8;function hn(t){let e=new Map;t.identities.ids.forEach((d,c)=>{d&&!t.hidden.has(c)&&!e.has(d)&&e.set(d,c);});let n=new Map;for(let d of t.incoming)d.identities.forEach((c,u)=>{c&&!n.has(c)&&n.set(c,{piece:d,index:u});});let o=new Map;for(let d of t.incoming){if(e.has(d.after))continue;let c=n.get(d.after);c&&c.piece!==d&&o.set(d,Wd(d,c,t));}let r=d=>{let c=d;for(let u=0;u<=Kd;u+=1){let p=o.get(c);if(!p)return true;c=p.piece;}return false};for(;;){let d=t.incoming.find(c=>o.has(c)&&!r(c));if(!d)break;o.delete(d);}let i=new Map,s=new Map,a=[],l=(d,c)=>{let u=d.get(c);return u||(u={before:[],after:[]},d.set(c,u)),u};for(let d of t.incoming){let c=e.get(d.after),u=o.get(d),p=null;if(c!==void 0)p=l(i,c);else if(u){let f=s.get(u.piece);f||(f=new Map,s.set(u.piece,f)),p=l(f,u.index);}p?d.before?p.before.push(d):p.after.push(d):a.push(d);}return {atPosition:i,inside:s,atEnd:a}}function Wd(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=>lt(a,u),d=new Set,c=e.index;for(let u=c+1;u<o.length;u+=1){let p=r[u],f=o[u],h=i[f]===p?s[f]:null;if(!(h===a&&!l(p))&&!(h!==null&&d.has(h)))break;d.add(p),c=u;}return {piece:e.piece,index:c}}function Jd(t,e,n,o,r,i){let s=t.toDelta();if(!r)return Fo(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 x of h.positions)g.add(x);l.set(h.source,g);}let d=new Map;for(let[h,g]of l)d.set(h,Xd(r.textOf(h),h,g,e,n));let c=hn(a),u=h=>{let g=d.get(h.source),x=c.inside.get(h),S=[];return h.positions.forEach((v,m)=>{let w=g.get(v),I=x?.get(m);if(!w&&!I)return;let y=h.items[m];S.push({item:w?.item,placement:w?.placement,...I?{slot:p(I)}:{},...y!==void 0?{character:{item:y,identity:h.identities[m]??null}}:{}});}),{entries:S}},p=h=>({before:h.before.map(u),after:h.after.map(u)}),f=new Map;for(let[h,g]of c.atPosition)f.set(h,p(g));return Fo(s,e,n,o,{hidden:a.hidden,following:{at:f,atEnd:c.atEnd.map(u)},onRepair:()=>r.noteDrift(),...i?{onCharacter:i,characters:{items:a.identities.items,ids:a.identities.ids}}:{}})}function Xd(t,e,n,o,r){let i=new Map;if(!t)return i;let s=0;for(let a of t.toDelta()){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??=ue(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"&&!L(c)?o(c):null;u&&i.set(s,{item:{kind:"embed",node:u,attributes:ue(a.attributes,r,e)},placement:d?.r===1});}s+=l;}return i}function ke(t,e,n,o,r,i){let s=new Set,a=new Set,l=Jd(e,p=>{if(r&&!r.showsEmbed(p))return r.noteDrift(),null;let f=r?.lineageOf?.(p)??null;if(f!==null&&f!==p){if(a.has(f)||r.listed?.(f))return r.noteDrift(),null;a.add(f);}let h=n(p);return h&&s.add(p),h},o,t,r,i),d=ce({id:t,kind:"paragraph",namespaceUri:WML_NAMESPACE_URI,localName:"p",namespaceBindings:[],attributes:[],children:[]}),c=Pi({shell:d,items:l}),u=$i(c,s,r?p=>r.shownId(p):void 0);return r&&u!==c&&r.noteDrift(),u.children}function mn(t,e){let n=new B.Text;t.set(ne,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 Wi(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&&Vi(r,o)?r:o})}function Vi(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&&jo(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)&&jo(t.namespaceBindings,e.namespaceBindings,(n,o)=>n.prefix===o.prefix&&n.namespaceUri===o.namespaceUri)&&jo(t.children,e.children,Vi)}function jo(t,e,n){return t.length===e.length&&t.every((o,r)=>n(o,e[r]))}var Hi=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"]})),qi=new Set(["drawingWrapNone","drawingWrapSquare","drawingWrapTight","drawingWrapThrough","drawingWrapTopBottom"]),Gi=new Map([["inlineDrawing",new Set(["drawingSimplePos","drawingPositionH","drawingPositionV","drawingSizeRelH","drawingSizeRelV",...qi])]]),Hd=new Set(["choice:position"]),Zi=new Map(Object.entries({drawing:t=>t.kind==="anchoredDrawing"||t.kind==="inlineDrawing"?"choice:placement":null,drawingPositionH:()=>"choice:position",drawingPositionV:()=>"choice:position",anchoredDrawing:t=>qi.has(t.kind)?"choice:wrap":null})),Ji={paragraph:"paragraphProperties",run:"runProperties"},qd=new Set(["sectPr","pPrChange"]);function Gd(t){return t.kind==="generic"&&t.namespaceUri===WML_NAMESPACE_URI&&qd.has(t.localName)}var Qi=new Set(["paragraphProperties","runProperties","tableProperties"]);function Zd(t,e){if(Hi.get(t)?.includes(e.kind))return `kind:${e.kind}`;let n=Zi.get(t)?.(e);return n||(Qi.has(t)&&e.kind==="generic"&&e.namespaceUri===WML_NAMESPACE_URI?`wml:${e.localName}`:null)}function zo(t){return t!==null&&(Hi.has(t)||Zi.has(t)||Gi.has(t)||Qi.has(t))}function gn(t,e,n){if(!zo(t))return null;let o=t,r=new Map,i=new Set,s=[],a=Gi.get(o),l=new Set,d=-1;for(let S=0;S<e.length;S+=1){let v=e[S];if(i.has(v))continue;i.add(v);let m=n(v);if(s[S]=m,!m)continue;if(a?.has(m.kind)){l.add(S);continue}d<0&&(d=S);let w=Zd(o,m);if(w===null)continue;let I=r.get(w);I?I.push(S):r.set(w,[S]);}let c=new Map;for(let[S,v]of r){if(v.length<2||v.every(I=>Ct(e[I])===null))continue;let m=Hd.has(S)?v.find(I=>s[I]?.empty!==true)??v[0]:v[0],w=v.filter(I=>I!==m);for(let I of w)l.add(I);c.set(m,w);}let u=Ji[o]?`kind:${Ji[o]}`:null,p=u?r.get(u)?.[0]:void 0,f=p!==void 0&&d!==p,h=o==="paragraphProperties"?r.get("kind:runProperties")?.[0]:void 0,g=-1;if(h!==void 0)for(let S=h+1;S<e.length;S+=1){let v=s[S];v&&!l.has(S)&&!Gd(v)&&(g=S);}if(l.size===0&&!f&&g<0)return null;let x=[];f&&x.push(p);for(let S=0;S<e.length;S+=1)l.has(S)||f&&S===p||g>=0&&S===h||(x.push(S),S===g&&x.push(h));return {order:x,companions:c}}function Qd(t,e,n){return gn(t,e,n)?.order??null}function yt(t,e){if(L(e)||t.isTombstoned(e))return null;let n=t.schema.nodes.get(e);if(!N(n))return null;let o=Se(n);return {kind:o.kind,namespaceUri:Ve(t.schema.namespaces,o.namespaceId),localName:o.localName,...te(n)?.length===0?{empty:true}:{}}}function es(t,e,n){let o=Qd(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 $o=new Set(["paragraphProperties","runProperties","tableProperties"]);function ts(t,e,n){let o=gn(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:ec(o,e,n)}}function ec(t,e,n){let o=null;for(let[r,i]of t.companions){let s=n(e[r]);!s||!$o.has(s.kind)||(o??=new Map,o.set(e[r],i.map(a=>e[a])));}return o}var tc=new Set(["run","runProperties"]),nc=new Set(["t","delText","instrText","delInstrText"]),ss=new Set(["hyperlink","ins","del","moveFrom","moveTo","sdt","sdtContent","fldSimple","smartTag","customXml","dir","bdo"]);function as(t){return tc.has(t.kind)?true:t.namespaceUri===WML_NAMESPACE_URI&&(nc.has(t.localName)||ss.has(t.localName))}function os(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 rs(t){return t.replace(/(~\d+)+$/,"")}var Ko=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=P(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(P(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"||as(s)||n[i+1].kind==="runProperties"||oc(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"?pt(rs(o.id),o.value??""):ce({id:o.paragraph||o.opaque?o.id:rs(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 oc(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&&ss.has(r.localName))return o.namespaceUri===WML_NAMESPACE_URI&&/Pr$|^fldData$/.test(o.localName)}return false}function is(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 yn(t,e){let n=e.map(ft),o=new Map;for(let h of n)h.kind==="putNode"&&o.set(h.descriptor.logicalId,h);let r=h=>t.inline.textOf(h)||o.get(h)?.descriptor.kind==="paragraph"||t.kindOf(h)==="paragraph"&&!ac(t,h)?h:t.inline.owner(h),i=new Set;for(let h of n)for(let g of is(h)){let x=r(g);x&&i.add(x);}if(i.size===0)return {passThrough:[...n],plan:null};let s=h=>{let g=new Ko,x=new Set;for(let S of h){let v=t.inline.textOf(S),m=g.placeholder(S,"paragraph");m.opaque=false,m.paragraph=true,m.kind="paragraph",m.namespaceUri=WML_NAMESPACE_URI,m.localName="p";let w=t.record(S),{shown:I}=es("paragraph",w&&"childIds"in w?w.childIds:[],E=>yt(t,E));for(let E of I){let _=g.placeholder(E,t.kindOf(E)??"generic");_.block=true,_.parent=S,m.children.push(E);}if(!v)continue;let y=new Set,R=E=>t.showsAsChild(E)?(y.add(E),sn(E)):null;for(let E of ke(S,v,R,t.limits,t.inline.viewOf(S)))g.add(E,S,y),m.children.push(P(E));for(let E of y){x.add(E);let _=g.nodes.get(E);_&&(_.kind=t.kindOf(E)??"generic");}}return {scratch:g,embedsBefore:x}},{scratch:a,embedsBefore:l}=s(i),d=n.flatMap(h=>is(h)).filter(h=>!a.nodes.has(h)&&!o.has(h)&&!t.hasNode(h));if(d.length>0){let h=new Set(i);for(let g of lc(t,new Set(d)))h.add(g);if(h.size>i.size){for(let g of h)i.add(g);({scratch:a,embedsBefore:l}=s(i));}}let c=[],u=new Map;for(let h of n){let g=rc(a,h,t);if(g&&u.set(c.length,g),c.push(ic(a,h,t)),a.refusal)return {passThrough:[...n],plan:null,refusal:a.refusal}}let p=[];n.forEach((h,g)=>{let x=u.get(g);x?p.push(x):(!c[g]||!sc(a,h))&&p.push(h);});let f=[...i].filter(h=>a.nodes.get(h)?.paragraph).map(h=>({id:h,after:ut(a.toTree(h))}));return {passThrough:p,plan:{paragraphs:f,embedsBefore:l}}}function rc(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 ic(t,e,n){switch(e.kind){case "putNode":{let{descriptor:o}=e;if(L(o.logicalId))return t.refuse("invalid-logical-id",o.logicalId);if(o.kind!=="textValue"&&(L(o.qname.localName)||o.qname.prefix!==void 0&&L(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(L(e.qname.localName)||e.qname.prefix!==void 0&&L(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]=os(e.qname,e.value):o.attributes.push(os(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(L(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=>L(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 sc(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"||as(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 ac(t,e){let n=t.record(e);return !n||!("childIds"in n)?true:n.childIds.some(o=>t.kindOf(o)==="run")}function lc(t,e){let n=new Set,o=new Set(e),r=i=>i.some(s=>o.delete(P(s))||s.kind!=="textValue"&&r(s.children));return t.schema.nodes.forEach((i,s)=>{if(o.size===0)return;let a=W(s),l=t.inline.textOf(a);if(!l||t.inline.isDeletedParagraph(a))return;let d=t.inline.viewOf(a);r(ke(a,l,()=>null,t.limits,d))&&n.add(a);}),n}var cc=new Set(["proofErr","permStart","permEnd"]);function Wo(t,e,n){return t==="bookmarkStart"||t==="bookmarkEnd"||isRangeMarkerKind(t)?true:t==="generic"&&n&&cc.has(e)}var uc=We(WML_NAMESPACE_URI);function Vo(t){if(!N(t))return false;let e=Se(t);return Wo(e.kind,e.localName,e.namespaceId===uc)}function ds(t){return Vo(t)?Xe(t):null}function ls(t){let e=n=>t.find(o=>o.namespaceUri===WML_NAMESPACE_URI&&o.localName===n)?.value??null;return [e("id"),e("name")]}function pc(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 cs(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||!F(l)||l.childIds.length>0||!Wo(l.kind,l.localName,l.namespaceUri===WML_NAMESPACE_URI))continue;let d=JSON.stringify([l.kind,l.localName,...ls(l.attributes)]),c=i.get(d)??[];c.push(a),i.set(d,c);}if(i.size===0)return;let s=pc(r);for(let a of n){if(!o.has(a))continue;let l=s.get(a);if(!l||!Wo(l.kind,l.localName,l.namespaceUri===WML_NAMESPACE_URI))continue;let d=JSON.stringify([l.kind,l.localName,...ls(l.attributes)]),c=i.get(d)?.shift();if(c===void 0)continue;let u=t.schema.nodes.get(a);if(!N(u))continue;let p=t.splitLineageOf(c)??c;u.set(Tt,p),u.set($e,p);}}var Ut="o",fc=/^(\^?)(\d{1,16}:\d{1,16})$/,Ze="-";function ps(t){if(t===Ze)return {identity:Ze,before:false};let e=typeof t=="string"?fc.exec(t):null;return e?{identity:e[2],before:e[1]==="^"}:null}function Xo(t,e,n,o,r){let i={...o};delete i[Ut];let s=st(t,e,n,i);s&&ye(t.doc).markCopy("move",s.id.client,s.id.clock,n.length,r);}function us(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 hc(t,e){let n=e.from+e.length;return (e.from===0||t[e.from-1])&&(n===t.length||t[n])}var mc=1<<20,gc=1<<24;function Jo(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),p=o.get(c),f=u.length*a.length;if(f>mc)continue;if(f>i.cells)return d;i.cells-=f;let h=new Uint32Array(a.length+1);for(let g=1;g<=u.length;g+=1){let x=new Uint32Array(a.length+1);for(let S=1;S<=a.length;S+=1){if(p[g-1]||l[S-1]||u[g-1]!==a[S-1])continue;let v=h[S-1]+1;x[S]=v,v>(d?.length??0)&&(d={source:c,from:g-v,to:S-v,length:v});}h=x;}}return d}function fs(t,e,n,o=()=>"",r=()=>""){let i=new Set,s=t.flatMap((I,y)=>us(I,y,"del"));if(s.length===0)return i;let a=t.flatMap((I,y)=>us(I,y,"ins")),l=new Set(s),d={cells:gc},c=new Map,u=I=>y=>{let R=l.has(y),E=`${I}:${y.paragraph}:${y.indexes[0]}:${R}`,_=c.get(E);if(!_){let U=t[y.paragraph];_=y.indexes.map(j=>{let X=R?U.before[j]:U.after[j],J=X.insert;return I?`${J}\0${o(X,y.paragraph)}`:J}),c.set(E,_);}return _},p=new Map;for(let I of [...s,...a])p.set(I,I.indexes.map(()=>false));let f=t.map((I,y)=>r(y)),h=(I,y)=>f[I]===""||f[y]===""||f[I]===f[y],g=(I,y)=>{for(let R=0;R<y.length;R+=1)p.get(y.source)[y.from+R]=true,p.get(I)[y.to+R]=true;yc(t,I,y,e,n,i);};for(let I of a){let y=s.find(R=>R.paragraph!==I.paragraph&&h(R.paragraph,I.paragraph)&&R.value===I.value&&!p.get(R).some(Boolean));y&&g(I,{source:y,from:0,to:0,length:I.indexes.length});}for(let I of a)for(let y=Jo(I,u(true),s,p,h,d);y;)g(I,y),y=Jo(I,u(true),s,p,h,d);let x=new Map;for(let I of a)x.set(I.paragraph,[...x.get(I.paragraph)??[],I]);let S=new Set(s.filter(I=>(x.get(I.paragraph)??[]).some(y=>y.value.includes(I.value)))),v=s.filter(I=>!S.has(I)),m=(I,y,R)=>{for(;;){let E=Jo(y,u(false),I,p,h,d,R);if(!E||!hc(p.get(E.source),E))break;g(y,E);}};for(let I of a)m(v,I,false);let w=new Map;for(let I of S)w.set(I.paragraph,[...w.get(I.paragraph)??[],I]);for(let I of a){let y=w.get(I.paragraph);y&&m(y,I,true);}return i}function yc(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],p=a(c);p&&i.add(p);let f=c>0?l.after[e.indexes[n.to+c-1]]:null,h=f!==null&&r(f)===r(l.after[u]);(!d||!h||!lt(a(c-1),p))&&(d=p),d&&(l.after[u]=o(l.after[u],d));}}var bc="docx-text-marks-v1",xc={move:"o",restore:"u",follow:"f"},Is=/^([ouf])(\d{1,16}):(\d{1,16})$/,Ic=/^(\d{1,16}):(\d{1,16}):(\d{1,16})$/,Sc=/^(\d{1,16})\|(.{1,40})$/,qo=16,hs=1<<20,ms=4096;function gs(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 ys(t,e,n){return `${xc[t]}${e}:${n}`}function be(t){let e=Number(t);return Number.isSafeInteger(e)?e:null}function wc(t,e){let n=Is.exec(t);if(!n||typeof e!="string")return null;let o=n[1]==="o"?"move":n[1]==="u"?"restore":"follow",r=be(n[2]),i=be(n[3]);if(r===null||i===null)return null;if(o==="follow"){let u=Sc.exec(e),p=u?be(u[1]):null,f=u?ps(u[2]):null;return p===null||p<1||p>hs||!f?null:{kind:o,client:r,span:{key:t,client:r,firstClock:i,length:p,origin:null,follow:f}}}let s=Ic.exec(e),a=s?be(s[1]):null,l=s?be(s[2]):null,d=s?be(s[3]):null;return a===null||l===null||d===null||d<1||d>hs?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 vc={origin:()=>null,follow:()=>null},Ho=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}markCopy(e,n,o,r,i){this.write(ys(e,n,o),`${i}:${r}`);}markFollow(e,n,o,r){this.write(ys("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=Is.exec(r),l=a?be(a[2]):null,d=a?be(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<=qo&&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>=ms)return this.withDependents(r,i);o.add(c);for(let u=d.from,p=0;u<d.to;p+=1){if(p>=ms)return this.withDependents(r,i);let f=le(this.doc,{client:d.client,clock:u});if(!f)break;f.parent instanceof B.Text&&n.add(f.parent),u=f.id.clock+f.length;}for(let u of this.dependents.get(d.client)??[]){let p=kc(u,d);p&&l.push(p);}}}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=B.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 B.Item?i.parent:null;s instanceof B.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=wc(e,n);if(!o)return;let r=Ce(this.map,e);if(r&&r.id.client!==o.client)return;let i=this.spans[o.kind].get(o.client)??[];i.splice(gs(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=bs(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=gs(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=bs(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 bs(t){if(t.origin)return t.origin.client;let e=t.follow?.identity,n=e?.indexOf(":")??-1;return n>0?be(e.slice(0,n)):null}function kc(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=be(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 xs=new WeakMap;function ye(t){let e=xs.get(t);if(e)return e;let n=t.getMap(bc),o=new Ho(t,n);return t.on("beforeObserverCalls",r=>{let i=Ht(r,n);i&&o.refreshKeys(i);}),xs.set(t,o),e=o,e}function xn(t){return t.doc?ye(t.doc):vc}var Qo="docx-text-deletions-v1",Lc=/^d(\d{1,16}):(\d{1,16})$/,Rc=/^(\d{1,16}):(\d{1,16}):(\d{1,16})$/,Go=4096,Oc=1<<20;function In(t){let e=Number(t);return Number.isSafeInteger(e)?e:null}function Ec(t,e){let n=Lc.exec(t);if(!n||typeof e!="string")return null;let o=In(n[1]);if(o===null)return null;let r=[];for(let i of e.split(";")){if(r.length>=Go)return null;let s=Rc.exec(i);if(!s)return null;let a=In(s[1]),l=In(s[2]),d=In(s[3]);if(a===null||l===null||d===null||d<1||d>Oc)return null;r.push({client:a,from:l,to:l+d});}return r.length===0?null:{client:o,runs:r}}var Sn=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}},Zo=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+=Go){let r=e.slice(o,o+Go).map(s=>`${s.client}:${s.from}:${s.to-s.from}`).join(";"),i=`d${this.doc.clientID}:${B.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=Ec(e,n),i=r?Ce(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 Sn),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,Sn.of(o));}},Ss=new WeakMap;function Le(t){let e=Ss.get(t);if(e)return e;let n=t.getMap(Qo),o=new Zo(t,n);return t.on("beforeObserverCalls",r=>{let i=Ht(r,n);i&&o.refreshKeys(i);}),Ss.set(t,o),e=o,e}function Ps(t,e){let n=[],o=0;for(let r of t.toDelta()){let i=r.attributes??{};if(typeof r.insert=="string"){let s=er(i);for(let a=0;a<r.insert.length;a+=1,o+=1){if(e?.has(o))continue;let l=`c${r.insert[a]}`;n.push({key:l,strong:`${l}\0${s}`,insert:r.insert[a],attributes:i,position:o});}}else {if(o+=1,e?.has(o-1))continue;let s=r.insert,a=typeof s.n=="string"?`e${s.r===1?"r":""}${s.n}`:`a${oe(i)}`;n.push({key:a,strong:a,insert:s,attributes:i,position:o-1});}}return n}function wn(t,e){let n=t.id,o=new Map;return ln(t).items.map(r=>{let i=o.get(r.attributes);if(i||(i=Ge(r.attributes,n,e),o.set(r.attributes,i)),r.kind==="char"){let a=`c${r.value}`,l=`${a}\0${er(i)}`;return {key:a,strong:l,insert:r.value,attributes:i}}if(r.kind==="embed"){let a=Uo(r),l=`e${"r"in a?"r":""}${r.node.id}`;return {key:l,strong:l,insert:a,attributes:i}}let s=`a${oe(i)}`;return {key:s,strong:s,insert:{a:1},attributes:i}})}var Cc=1<<20;function er(t){return t.t??""}function Ns(t,e,n=true){let o=Ls(t),r=Ls(e);if(o===null&&r===null)return Rs(t,e,n);let i=o?.starts??null,s=r?.starts??null,a=(d,c,u)=>{if(d===null)return [c];let p=d[c];return (c+1<d.length?d[c+1]:u)-p===2?[p,p+1]:[p]},l=[];for(let d of Rs(o?.tokens??t,r?.tokens??e,n))if(d.op==="del")for(let c of a(i,d.before,t.length))l.push({op:"del",before:c});else if(d.op==="ins")for(let c of a(s,d.after,e.length))l.push({op:"ins",after:c});else {let c=a(i,d.before,t.length),u=a(s,d.after,e.length);c.forEach((p,f)=>l.push({op:"eq",before:p,after:u[f]}));}return l}var vs=t=>{if(t===void 0||typeof t.insert!="string")return false;let e=t.insert.charCodeAt(0);return e>=55296&&e<=56319},ks=t=>{if(t===void 0||typeof t.insert!="string")return false;let e=t.insert.charCodeAt(0);return e>=56320&&e<=57343};function Ls(t){let e=false;for(let r=0;r+1<t.length&&!e;r+=1)e=vs(t[r])&&ks(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(vs(i)&&ks(s)&&a){let l=`${i.insert}${s.insert}`,d=`c${l}`;n.push({...i,key:d,strong:`${d}\0${er(i.attributes)}`,insert:l}),r+=1;}else n.push(i);}return {tokens:n,starts:o}}function Rs(t,e,n){let o=n?Tc(t,e):null;if(o)return o;let r=Cs(t,e,Ts(t,e,false)),i=Cs(t,e,Ts(t,e,true)),[s,a]=[Es(r),Es(i)],l=a!==s?a>s?i:r:Os(i)<Os(r)?i:r;return Ac(Mc(l,e),t)}function Tc(t,e){let n=e.length-t.length;if(n<=0)return null;let o=0;for(;o<t.length&&t[o].strong===e[o].strong;)o+=1;let r=0;for(;r<t.length-o&&t[t.length-1-r].strong===e[e.length-1-r].strong;)r+=1;if(o+r!==t.length)return null;let i=e[o],s=e[o+n-1],a=o>0?t[o-1]:null;if(a&&a.key===s.key&&a.strong!==s.strong||o<t.length&&t[o].key===i.key)return null;let l=[];for(let d=0;d<o;d+=1)l.push({op:"eq",before:d,after:d});for(let d=o;d<o+n;d+=1)l.push({op:"ins",after:d});for(let d=o;d<t.length;d+=1)l.push({op:"eq",before:d,after:d+n});return l}function Pc(t){if(!ie(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 Nc=16;function Ac(t,e){for(let n=0;n<Nc;n+=1){let o=[];for(let l of t){let d=o[o.length-1];d&&d[0].op==="eq"==(l.op==="eq")?d.push(l):o.push([l]);}let r=l=>{if(!l||l[0].op==="eq")return 0;let d=0;for(let c of l)c.op==="ins"&&(d+=1);return Math.max(d,l.length-d)},i=l=>l!==void 0&&l.some(d=>d.op==="del"),s=false,a=[];if(o.forEach((l,d)=>{if(!(l[0].op==="eq"&&l.length<=r(o[d-1])&&l.length<=r(o[d+1])&&(i(o[d-1])||i(o[d+1]))&&l.every(u=>u.op==="eq"&&Pc(e[u.before])))){a.push(...l);return}s=true;for(let u of l)u.op==="eq"&&a.push({op:"del",before:u.before});for(let u of l)u.op==="eq"&&a.push({op:"ins",after:u.after});}),t=a,!s)break}return t}function Mc(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 Os(t){let e=0,n=false;for(let o of t)o.op!=="eq"&&!n&&(e+=1),n=o.op!=="eq";return e}function ie(t){return t.key.startsWith("c")}function Dc(t,e,n,o,r,i){let s=e,a=r,l=0;for(;;){for(;s<n&&!ie(t[s]);)s+=1;for(;a<i&&!ie(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;}}function Es(t){let e=0;for(let n of t)n.op==="eq"&&(e+=1);return e}function Cs(t,e,n){let o=[],r=0,i=0;for(let[s,a]of [...n,[t.length,e.length]]){let l=s,d=a;for(;;)if(r<l&&i<d&&t[r].key===e[i].key)o.push({op:"eq",before:r,after:i}),r+=1,i+=1;else if(r<l&&i<d&&!ie(t[r])&&ie(e[i]))o.push({op:"del",before:r}),r+=1;else if(r<l&&i<d&&ie(t[r])&&!ie(e[i]))o.push({op:"ins",after:i}),i+=1;else break;let c=[];for(;;)if(l>r&&d>i&&t[l-1].key===e[d-1].key)l-=1,d-=1,c.unshift({op:"eq",before:l,after:d});else if(l>r&&d>i&&!ie(t[l-1])&&ie(e[d-1]))l-=1,c.unshift({op:"del",before:l});else if(l>r&&d>i&&ie(t[l-1])&&!ie(e[d-1]))d-=1,c.unshift({op:"ins",after:d});else break;if(Dc(t,r,l,e,i,d))for(;r<l||i<d;)r<l&&i<d&&ie(t[r])&&ie(e[i])?(o.push({op:"eq",before:r,after:i}),r+=1,i+=1):r<l&&!ie(t[r])?(o.push({op:"del",before:r}),r+=1):(o.push({op:"ins",after:i}),i+=1);for(;r<l;r+=1)o.push({op:"del",before:r});for(;i<d;i+=1)o.push({op:"ins",after:i});o.push(...c),r=s,i=a,r<t.length&&i<e.length&&(o.push({op:"eq",before:r,after:i}),r+=1,i+=1);}return o}function Ts(t,e,n){let o=[],r=0;for(;r<t.length&&r<e.length&&t[r].strong===e[r].strong;)o.push([r,r]),r+=1;let i=t.length,s=e.length,a=[];for(;i>r&&s>r&&t[i-1].strong===e[s-1].strong;)i-=1,s-=1,a.unshift([i,s]);let l=i-r,d=s-r;if(l>0&&d>0&&l*d<=Cc){let c=d+1,u=new Uint32Array((l+1)*c),p=(g,x)=>t[r+g].strong===e[r+x].strong;for(let g=l-1;g>=0;g-=1)for(let x=d-1;x>=0;x-=1)u[g*c+x]=p(g,x)?u[(g+1)*c+x+1]+1:Math.max(u[(g+1)*c+x],u[g*c+x+1]);let f=0,h=0;for(;f<l&&h<d;)if(p(f,h))o.push([r+f,r+h]),f+=1,h+=1;else {let g=u[(f+1)*c+h],x=u[f*c+h+1];g>x||g===x&&!n?f+=1:h+=1;}}return o.push(...a),o}function As(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 nr=64;function Ms(t,e,n){for(let o=0;o<qo;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 Yc(t,e){let n=fe(e);return n?or(t,n.client,n.clock):e}function or(t,e,n){let[o,r]=Ms(t,e,n);return `${o}:${r}`}function Ds(t,e,n){return or(xn(t),e.id.client,e.id.clock+n)}function tr(t,e){return e===t.id.clock?t.origin:{client:t.id.client,clock:e-1}}function _c(t,e,n){let o=[],r=e.left;if(r&&e.origin&&!r.deleted&&!(r.content instanceof B.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<nr;s+=1){let a=le(t,i);if(!a)break;if(!a.deleted){if(a.content instanceof B.ContentFormat){i=tr(a,i.clock);continue}return {live:n(a,i.clock),deleted:o}}let l=n(a,i.clock);l&&o.push(l),i=tr(a,i.clock);}return {live:null,deleted:o}}function Bc(t,e,n){let o=e.rightOrigin;for(let r=0;o&&r<nr;r+=1){let i=le(t,o);if(!i)return null;if(i.deleted||!(i.content instanceof B.ContentFormat))return n(i,o.clock);o=i.rightOrigin;}return null}function Ys(t,e,n){return e.deleted||e.content instanceof B.ContentString?or(t,e.id.client,n):null}function pe(t,e){return t.moved[e]===true||t.restored[e]===true}function et(t){let e=Vt(t),n=xn(t),o=[],r=[],i=[],s=[],a=[],l=[],d=[],c=[],u=t.doc?Le(t.doc):null,p=[],f=[],h=[],g=[],x=false,S=t.doc,v=(m,w)=>Ys(n,m,w);for(let m=e;m;m=m.right){if(m.deleted||!m.countable)continue;let w=m.content instanceof B.ContentString,I=w||m.content instanceof B.ContentEmbed,y=D=>w&&n.origin("move",m.id.client,D)!==null,R=D=>w&&!y(D)&&n.origin("restore",m.id.client,D)!==null,E=y(m.id.clock)||R(m.id.clock),_=I?n.follow(m.id.client,m.id.clock):null,U=_&&_.identity!==Ze?{..._,identity:Yc(n,_.identity)}:_,j=S?_c(S,m,v):{live:null,deleted:[]},X=null;if(I&&!E&&U&&(j.deleted.length>0||j.live===null)?X=[U]:I&&!E&&j.deleted.length>0&&(X=j.deleted.map(D=>({identity:D,before:false}))),X&&(x=true),I&&!E&&!_&&j.live===null&&S){let D=Bc(S,m,v);D&&(X=[...X??[],{identity:D,before:true}]);}let J=E?[...j.deleted,...j.live===null?[]:[j.live]]:null;for(let D=0;D<m.length;D+=1){if(s.push(`${m.id.client}:${m.id.clock+D}`),a.push(D>0?`${m.id.client}:${m.id.clock+D-1}`:m.origin?`${m.origin.client}:${m.origin.clock}`:null),w){let[b,k]=Ms(n,m.id.client,m.id.clock+D);o.push(`${b}:${k}`),r.push(b),i.push(k);}else o.push(null),r.push(-1),i.push(-1);l.push(y(m.id.clock+D));let K=R(m.id.clock+D);d.push(K),c.push(w&&u!==null&&u.isDeleted(r[r.length-1],i[i.length-1])),f.push(D===0),h.push(D===0?j.live:null),g.push(D===0?J:null),p.push(D===0?X:null);}}return {ids:o,clients:r,clocks:i,items:s,origins:a,moved:l,restored:d,deleted:c,anchors:p,hasAnchors:x,starts:f,lefts:h,copiedAfter:g}}function rr(t,e,n){let o=t.doc;if(!o)return false;let r=xn(t),i=e.origin;for(let s=0;i&&s<nr;s+=1){let a=le(o,i);if(!a)return false;let l=Ys(r,a,i.clock);if(l!==null&&n(l))return true;i=tr(a,i.clock);}return false}function ar(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 ir=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}},sr=class{classes=new Map;add(e){let n=_s(e.run.end-e.run.start),o=this.classes.get(n);o||this.classes.set(n,o=new ir(2**(n+1))),o.add(e);}remove(e){let n=_s(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 _s(t){return t<=1?0:31-Math.clz32(t)}var Ft=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 p=new Map;for(let f of u){let h=p.get(r(f));h?h.push(f):p.set(r(f),[f]);}return p},s=i(o),a=i(n),l=new Set,d=[],c=u=>{for(let p of Object.values(this.tables))for(let f of p.get(u.client)?.overlapping(u.start,u.end)??[])f.paragraph!==e&&l.add(f.paragraph);};for(let[u,p]of s)for(let f of p.slice(a.get(u)?.length??0))this.tables[f.kind].get(f.client)?.remove({run:f,paragraph:e}),d.push(f),f.kind!=="original"&&c(f);for(let[u,p]of a)for(let f of p.slice(s.get(u)?.length??0)){let h=this.tables[f.kind],g=h.get(f.client);g||(g=new sr,h.set(f.client,g)),g.add({run:f,paragraph:e}),d.push(f),f.kind!=="original"&&c(f);}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 Bs=new Set,Uc=64;function Us(t){let e=new Set;return t.ids.forEach((n,o)=>{n!==null&&pe(t,o)&&e.add(n);}),e}function Fc(t){let e=ar(t).map(o=>({...o,kind:"original"})),n=o=>{let r=fe(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 lr(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 jc(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(p=>p.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 p=l;p<c;p+=1)u.push(p);for(let p of u)a.add(p);s.push({source:t,after:d.identity,before:true,positions:u,identities:u.map(p=>r[p]??null),items:u.map(p=>e.items[p])});}for(let l of s)for(let d of l.positions)n.add(d);return s}var vn=class{constructor(e,n,o,r,i){this.textOf=e;this.isDeleted=n;this.order=o;this.viewsChanged=r;this.originalParagraph=i;}textOf;isDeleted;order;viewsChanged;originalParagraph;index=new Ft;sources=new Set;outgoingOf=new Map;incomingOf=new Map;targetsOf=new Map;dependencies=new Ft;pending=new Set;ownChanges=new Set;readsOtherSources=new Set;typedAnchored=new Map;typedOf=new Map;typedStale=new Set;typedBuilt=false;identities=new Map;recent=new Set;lastOf(e){let n=null;for(let o of e)(n===null||this.order(o,n)>0)&&(n=o);return n}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?ar(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.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=Us(o);for(let f=0;f<a.length;){let h=f+1;for(;h<a.length&&a[h]===a[f]&&l[h]===l[h-1]+1&&o.moved[h]===o.moved[f]&&o.restored[h]===o.restored[f];)h+=1;let g=a[f],x=pe(o,f);if(g>=0){let S=w=>this.index.overlapping(w,g,l[f],l[h-1]+1).filter(I=>I.paragraph!==e),v=S("move"),m=S("restore");if(v.length>0||m.length>0||x){let w=l[f],I=this.coverage(v,w,h-f,e),y=this.coverage(m,w,h-f,e);for(let R=f;R<h;R+=1){let E=R-f,_={move:I.any[E]>0,laterMove:I.later[E]>0,restore:y.any[E]>0,laterRestore:y.later[E]>0};this.hides(o,R,_,i,s)&&r.add(R);}}if(!x&&d.size>0)for(let w=f;w<h;w+=1)d.has(o.ids[w])&&r.add(w);}f=h;}let c=this.outgoingOf.get(e);if(c)for(let f of lr(c,o))r.add(f);o.deleted.forEach((f,h)=>{f&&r.add(h);});let u=jc(e,o,r,s),p=this.distinctIncoming(e,o,r);return {identities:o,hidden:r,incoming:u.length>0?[...p,...u]:p}}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 pe(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,pe(e,n)&&r.add(s),a}coverage(e,n,o,r){let i=new Int32Array(o+1),s=new Int32Array(o+1);for(let a of e){let l=Math.max(a.run.start,n)-n,d=Math.min(a.run.end,n+o)-n;l>=d||(i[l]+=1,i[d]-=1,this.order(a.paragraph,r)>0&&(s[l]+=1,s[d]-=1));}for(let a=1;a<=o;a+=1)i[a]+=i[a-1],s[a]+=s[a-1];return {any:i,later:s}}holdersOf(e){let n=fe(e);return n?this.index.holders(n.client,n.clock):[]}shownCopy(e){let n=fe(e);if(!n)return null;let{client:o,clock:r}=n;return this.index.hasCopies(o)?this.lastOf(this.index.holdersOf("move",o,r))??this.lastOf(this.index.holdersOf("restore",o,r)):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)??Bs}placedTargetsFor(e){return this.targetsOf.get(e)??Bs}invalidate(e){this.identities.delete(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=et(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<=Uc))return;let n=this.recent.values().next().value;this.recent.delete(n),this.identities.delete(n);}clear(){this.identities.clear(),this.recent.clear(),this.index.clear(),this.sources.clear(),this.outgoingOf.clear(),this.incomingOf.clear(),this.targetsOf.clear(),this.dependencies.clear(),this.pending.clear(),this.ownChanges.clear(),this.typedAnchored.clear(),this.typedOf.clear(),this.typedStale.clear(),this.typedBuilt=false;}relocate(e){let n=new Set;for(let a of e)for(let l of this.targetsOf.get(a)??[])n.add(l);let o=new Map;for(let a of n)o.set(a,JSON.stringify(this.incomingOf.get(a)??[]));let r=new Map;for(let a of e)r.set(a,JSON.stringify(this.outgoingOf.get(a)?.positions??[]));let i=new Set(e);for(let a of n){let l=(this.incomingOf.get(a)??[]).filter(d=>!i.has(d.source));l.length>0?this.incomingOf.set(a,l):this.incomingOf.delete(a);}for(let a of e){this.targetsOf.delete(a),this.outgoingOf.delete(a);let l=this.sources.has(a)?this.textOf(a):null,d=l?this.identitiesOf(a,l):null;if(this.dependencies.update(a,d?Fc(d):[]),!d)continue;let c=new Map;for(let u of this.followingOf(a,d)){let p=u.target??this.shownCopy(u.after),f=this.incomingOf.get(p)??[];f.push(u),this.incomingOf.set(p,f);let h=this.targetsOf.get(a)??new Set;h.add(p),this.targetsOf.set(a,h),u.positions.forEach((g,x)=>{c.set(g,u.identities[x]??null);}),o.has(p)||o.set(p,"[]");}if(c.size>0&&!this.isDeleted(a)){let u=[...c.keys()].sort((p,f)=>p-f);this.outgoingOf.set(a,{positions:u,identities:u.map(p=>c.get(p)??null),items:u.map(p=>d.items[p])});}}for(let a of o.keys())this.incomingOf.get(a)?.sort((l,d)=>(l.source<d.source?-1:l.source>d.source?1:0)||l.positions[0]-d.positions[0]);let s=new Set;for(let[a,l]of r)JSON.stringify(this.outgoingOf.get(a)?.positions??[])!==l&&s.add(a);for(let[a,l]of o)JSON.stringify(this.incomingOf.get(a)??[])!==l&&s.add(a);return s}followingOf(e,n){let o=[],r=null,i=Us(n);for(let s=0;s<n.ids.length;s+=1){let a=n.ids[s]??null,l=pe(n,s);if(n.deleted[s]||a!==null&&(this.shownCopy(a)!==null||!l&&i.has(a))){r=null;continue}let d=!this.isDeleted(e),c=r!==null&&(!n.starts[s]||s>0&&n.lefts[s]===n.ids[s-1]),u=n.anchors[s]?.find(p=>this.leadsOut(e,d,p))??(d||c?void 0:this.movedAfter(e,n,s));if(u){r={source:e,after:u.identity,before:u.before,...u.target?{target:u.target}:{},positions:[s],identities:[a],items:[n.items[s]]},o.push(r);continue}if(r&&c){r.positions.push(s),r.identities.push(a),r.items.push(n.items[s]);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||pe(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 e.anchors.some(o=>this.leadsOut(e.source,n,o))}leadsOut(e,n,o){if(o.before&&n)return false;let r=this.shownCopy(o.identity);return r!==null&&r!==e}movedAfter(e,n,o){let r=n.ids[o];if(!r||this.holdersOf(r).length>0||(this.readsOtherSources.add(e),(this.typedSources().get(r)??[]).some(a=>a.source!==e&&this.follows(a))))return;for(let a of n.copiedAfter[o]??[]){let l=this.shownCopy(a);if(l!==null&&l!==e)return {identity:a,before:false}}if(!n.moved[o])return;let s=this.originalParagraph(r);if(!(s===null||s===e||this.isDeleted(s)))return {identity:r,before:false,target:s}}};function zc(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 $c(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 dr(t,e){if(!t)return null;if(e>0){let o=t.ids[e-1];return o&&pe(t,e-1)?o:null}let n=t.ids[0];return n&&pe(t,0)?`^${n}`:null}function cr(t,e,n,o,r,i){let s=st(t,e,n,o);!r||!s||!rr(t,s,i)||ye(t.doc).markFollow(s.id.client,s.id.clock,n.length,Fs(r,e));}function Fs(t,e){return e>0?t.ids[e-1]??Ze:t.ids[0]?`^${t.ids[0]}`:Ze}function Kc(t,e,n,o,r,i){let s=st(t,e,n,o);if(!s)return;let a=r??(i&&rr(t,s,i.hasShownCopy)?Fs(i.identities,e):null);a&&ye(t.doc).markFollow(s.id.client,s.id.clock,1,a);}function ur(t,e,n,o,r){let i=st(t,e,n,o);i&&ye(t.doc).markFollow(i.id.client,i.id.clock,n.length,r);}function Wc(t,e,n,o,r,i){let s=zc(e,o),a=new Map,l=(d,c)=>{let u=a.get(d);u||a.set(d,u=new Map);let p=u.get(c);if(p===void 0){let f=As(d,c);p=f&&{changes:f,key:JSON.stringify(f),from:oe(d)},u.set(c,p);}return p};for(let d=s.length-1;d>=0;d-=1){let c=s[d];if(c.kind==="eq"){let S=[];for(let m of c.steps){let w=l(e[m.before].attributes,n[m.after].attributes);w&&S.push({...w,position:e[m.before].position});}let v=[];for(let m of S){let w=v[v.length-1],I=w?.[w.length-1];I&&I.position+1===m.position&&I.from===m.from&&I.key===m.key?w.push(m):v.push([m]);}for(let m=v.length-1;m>=0;m-=1){let w=v[m];t.format(w[0].position,w.length,w[0].changes);}continue}let u=c.steps.filter(S=>S.op==="del").map(S=>e[S.before].position),p=c.steps.filter(S=>S.op==="ins").map(S=>n[S.after]),f=u.length>0?u[0]:c.after,h=dr(r,f),g=0;for(let S of $c(p,v=>typeof v.insert=="string"?`c${oe(v.attributes)}`:`e${g++}`)){let v=S[0];if(typeof v.insert!="string"){let I=r&&f===(u.length>0?u[0]:c.after)?{identities:r,hasShownCopy:i}:null;Kc(t,f,v.insert,v.attributes,h,I),h=null,f+=1;continue}let m=S.map(I=>I.insert).join(""),w=v.attributes[Ut];w?Xo(t,f,m,v.attributes,w):h?ur(t,f,m,v.attributes,h):f===(u.length>0?u[0]:c.after)?cr(t,f,m,v.attributes,r,i):t.insert(f,m,{...v.attributes}),h=null,f+=m.length;}let x=f-(u.length>0?u[0]:c.after);for(let S=u.length-1;S>=0;){let v=S;for(;v>0&&u[v-1]+1===u[v];)v-=1;Hr(t,u[v]+x,S-v+1),S=v-1;}}}function Vc(t,e,n){let r=t.inline.viewOf(e).shown(n);if(r.incoming.length===0)return [];let{ids:i}=r.identities,s=hn(r),a=new Map(r.incoming.map((m,w)=>[m,w])),l=[];for(let[m,w]of s.atPosition)for(let I of [...w.before,...w.after])l.push({following:I,order:a.get(I),at:m});for(let m of s.atEnd)l.push({following:m,order:a.get(m),at:i.length,atEnd:true});let d=(m,w)=>w.at-m.at||(m.atEnd?0:Number(m.following.before))-(w.atEnd?0:Number(w.following.before))||w.order-m.order;l.sort(d);let c=new Map,u=new Set,p=[],f=m=>m-p.filter(w=>w<m).length,h=new Map,g=(m,w)=>{let I=h.get(m);return I||(I={identities:et(w),delta:w.toDelta()},h.set(m,I)),I},x=(m,w)=>{let I=new Map,y=t.inline.textOf(m.source);if(!y)return {positions:[],landed:I};let{identities:R,delta:E}=g(m.source,y),_=lr(m,R),U=R.ids,j=new Set(_),X=[],J=0;for(let k of E){let O=typeof k.insert=="string"?k.insert.length:1,C=null,Y=()=>C??=Ge(ue(k.attributes,t.limits,m.source),e,t.limits);if(typeof k.insert=="string")for(let A=0;A<O;A+=1)j.has(J+A)&&X.push({kind:"char",value:k.insert[A],attributes:{...Y()},identity:U[J+A]??null,position:J+A});else if(j.has(J)&&k.insert!==null&&typeof k.insert=="object"){let A=qr(y,J);A&&X.push({kind:"embed",embed:k.insert,attributes:{...Y()},item:A,position:J});}J+=O;}let D=[];for(let k of X){let O=D[D.length-1],C=O?.[O.length-1];k.kind==="char"&&C?.kind==="char"&&oe(C.attributes)===oe(k.attributes)&<(C.identity,k.identity)?O.push(k):D.push([k]);}let K=w;for(let k of D){let O=k[0];if(O.kind==="embed"){let Y=y===n?Gr(n,O.item):null;Zr(y,O.item),h.delete(m.source),u.add(m.source),Y!==null&&(p.push(Y),Y<K&&(K-=1)),n.insertEmbed(K,O.embed,{...O.attributes}),I.set(O.position,K),K+=1;continue}let C=k.map(Y=>Y.kind==="char"?Y.value:"").join("");O.identity?Xo(n,K,C,O.attributes,O.identity):n.insert(K,C,O.attributes),k.forEach((Y,A)=>I.set(Y.position,K+A)),K+=C.length;}h.delete(e);let b=X.flatMap(k=>k.kind==="char"&&k.identity?[k.identity]:[]);return c.set(m.source,[...c.get(m.source)??[],...b]),{positions:_,landed:I}},S=[],v=(m,w)=>{let I=s.inside.get(m);if(!I)return;let y=[];for(let[R,E]of I){let _=w.positions[R],U=_===void 0?void 0:w.landed.get(_);for(let j of [...E.before,...E.after])U===void 0?S.push(j):y.push({following:j,order:a.get(j),at:U});}y.sort(d);for(let R of y){let E=R.following.before?R.at:R.at+1;v(R.following,x(R.following,E));}};for(let m of l){let w=m.atEnd||m.following.before?m.at:m.at+1;v(m.following,x(m.following,f(w)));}for(let m of S)v(m,x(m,n.length));for(let[m,w]of c){let I=t.inline.textOf(m);if(I&&m!==e&&t.inline.isDeletedParagraph(m)){let y=new Set(w),R=et(I).ids;Ot(I,R.flatMap((E,_)=>E&&y.has(E)?[_]:[])),u.add(m);}}for(let m of u)t.inline.follow.invalidate(m);return t.inline.follow.invalidate(e),t.inline.noteDrift(),[...c.keys()]}function pr(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 Jc(t){let e=new Set;for(let o of t)for(let r of pr(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:fo(o.text,r),originals:r.map(s=>i&&!i.moved[s]&&!i.restored[s]?o.identities[s]??null:null)});}return n}function fr(t,e){return t===null||!e.has(t)}function Xc(t,e,n){let o=new Set,r=new Set(e.map(s=>s.id));for(let s of e)for(let a of pr(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=et(a),d=l.ids.flatMap((c,u)=>{if(!c||!o.has(c))return [];let p=pe(l,u);return fr(p?null:c,n)?[u]:[]});d.length!==0&&(Ot(a,d),t.inline.follow.invalidate(s),t.inline.noteDrift());}}function js(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 f of d.toDelta()){if(typeof f.insert=="string"){u+=f.insert.length;continue}let h=f.insert?.n;typeof h=="string"&&!c.hidden.has(u)&&r.add(h),u+=1;}let p=[];c.identities.ids.forEach((f,h)=>{!f||c.hidden.has(h)||(p.push(f),pe(c.identities,h)&&n.add(f));});for(let f of c.incoming)for(let h of f.identities)h&&p.push(h);p.length>0&&o.set(l,p);}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=et(d),u=[],p=[];c.ids.forEach((f,h)=>{!f||!n.has(f)||(pe(c,h)?u.push(h):p.push(h));}),p.length>0&&i.push({holder:l,text:d,items:fo(d,p),identities:p.map(f=>c.ids[f])}),u.length!==0&&(Ot(d,u),t.inline.follow.invalidate(l),t.inline.noteDrift());}return {held:i,shown:o,embeds:r}}function zs(t,e,n,o){let r=new Set(n);for(let i of e){if(o.embedded.has(i)||L(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 $s(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=Hc([...o].filter(i=>!e.copied.has(i)));r.length>0&&Le(t.doc).record(r);}function Hc(t){let e=t.flatMap(o=>fe(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}function Ks(t,e,n){for(let{holder:o,text:r,items:i,identities:s}of e){let a=i.filter((l,d)=>fr(s[d],n));a.length!==0&&(ho(r,a),t.inline.follow.invalidate(o),t.inline.noteDrift());}}function Ws(t,e,n=new Map){let o=new Set,r=[],i=new Set;for(let{id:c}of e.paragraphs){let u=t.inline.textOf(c);if(u)for(let p of Vc(t,c,u))p!==c&&t.inline.isDeletedParagraph(p)&&i.add(p);}for(let{id:c,after:u}of e.paragraphs){let p=t.schema.nodes.get(c);if(!p||i.has(c))continue;let f=n.get(c)??wn(u,t.limits);for(let S of f)typeof S.insert!="string"&&"n"in S.insert&&o.add(S.insert.n);let h=t.inline.textOf(c),g=h?t.inline.viewOf(c).shown(h):null,x=h?Ps(h,g?.hidden):[];r.push({id:c,record:p,text:h,before:x,after:f,steps:Ns(x,f),identities:g?.identities.ids??[],shownIdentities:g?.identities??null,hidden:g?.hidden??new Set});}let s=Jc(r),a=fs(r,(c,u)=>({...c,attributes:{...c.attributes,[Ut]:u}}),c=>{let{[Ut]:u,...p}=c.attributes;return oe(p)},(c,u)=>ue(c.attributes,t.limits,r[u].id).text?.id??"",c=>qc(t,r[c].id));for(let c of r){let u=c.text??mn(c.record,[]);Wc(u,c.before,c.after,c.steps,c.shownIdentities,p=>t.inline.follow.shownCopy(p)!==null),t.inline.follow.invalidate(c.id);}for(let{write:c,ids:u,originals:p}of s){let f=u.filter((h,g)=>fr(p[g],a));!c.text||f.length===0||(ho(c.text,f),t.inline.follow.invalidate(c.id),t.inline.noteDrift());}Xc(t,r,a);let l=new Set(e.paragraphs.map(c=>c.id));for(let c of e.embedsBefore)o.has(c)||[...t.inline.holdersOf(c)].some(u=>!l.has(u))||t.hasNode(c)&&!t.isTombstoned(c)&&t.listingParents(c).length===0&&t.tombstone(c);let d=new Set;for(let c of r)for(let u of pr(c))d.add(u);return {copied:a,deleted:d,embedded:o}}function qc(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 Vs=new WeakMap,Qc=4096;function Xs(t,e){if(e.effects.length!==1)return null;let n=e.effects[0];if(n.kind!=="spliceText"||n.deleteCount!==0||!eu(n.insert)||t.hasUnobservedWrites()||xe(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=r.toDelta(),l=0,d=-1,c=0,u=null,p=new Set,f=new Set;for(let m of a){let w=m.attributes??{};if(!tu(t,o,w))return null;let I=ue(w,t.limits,o),y=new Set;for(let E of [I.run?.id,I.runProperties?.id,I.text?.id,I.textValueId,...I.wrap.map(_=>_.id)])if(E){if(p.has(E)&&!f.has(E))return null;y.add(E),p.add(E);}f=y;let R=typeof m.insert=="string"?m.insert.length:1;if(typeof m.insert=="string"&&I.textValueId!==null&&i.shownId(I.textValueId)===n.logicalId){if(d<0)d=l;else if(d+c!==l)return null;if(u&&oe(u)!==oe(w))return null;u??=w,c+=R;}l+=R;}if(!u||!Number.isSafeInteger(n.utf16Start)||n.utf16Start<0||n.utf16Start>c||c+n.insert.length>t.limits.maxTextLength)return null;let h=d+n.utf16Start,g=h>0?Js(a,h-1):null,x=h<l?Js(a,h):null,S=n.insert[0],v=n.insert[n.insert.length-1];return x&&x.key===`c${S}`||g&&g.key===`c${v}`&&g.element!==(u.t??"")||g?.highSurrogate?null:{paragraphId:o,text:r,length:r.length,position:h,value:n.insert,attributes:u,identities:s.identities}}function Hs(t,e){if(e.text.length!==e.length)return false;let n=dr(e.identities,e.position);return n?ur(e.text,e.position,e.value,e.attributes,n):cr(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 eu(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 tu(t,e,n){let o=oe(n),r=JSON.stringify([e,o]),i=Vs.get(t.limits);i||Vs.set(t.limits,i=new Map);let s=i.get(r);if(s!==void 0)return s;let a;try{let l=ue(n,t.limits,e);a=oe(Ge(l,e,t.limits))===o;}catch(l){if(!(l instanceof he))throw l;a=false;}return i.size>=Qc&&i.clear(),i.set(r,a),a}function Js(t,e){let n=0;for(let o of t){let r=typeof o.insert=="string"?o.insert.length:1;if(e<n+r){if(typeof o.insert!="string")return {key:"embed",element:"",highSurrogate:false};let i=o.insert.charCodeAt(e-n);return {key:`c${o.insert[e-n]}`,element:o.attributes?.t??"",highSurrogate:i>=55296&&i<=56319}}n+=r;}return null}function hr(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(Ke(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(F(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 xt(t,e,n){let o=hr(t,e),r=[];if(!o||o.length===0)return false;for(let l of n){let d=hr(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 kn(t,e,n){return t!=="run"&&t!=="text"?null:e.filter(o=>n(o)===t)}function qs(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,nu);a+=1){let l=s.slice(0,a);if(xt(t,r,[...i,...l])){o(r,l);break}}}}var nu=8;function mr(t,e){return (hr(t,e)??[]).some(n=>t.splitTextPending(n.id))}var tt=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){let r=this.parentOf(e);if(r!==null){let a=this.node(r),l=a?.children.indexOf(e)??-1;a&&l>=0&&a.children.splice(l,1);}let i=this.node(n);if(!i)return;let s=Math.min(o,i.children.length);i.children.splice(s,0,e);}parentOf(e){for(let[n,o]of this.touched)if(o.children.includes(e))return n;return this.registry.parentOf(e)}};function jt(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 Pe(t,e){return L(e)||e.length===0?{ok:false,code:"prototype-key",detail:e}:t.has(e)?null:{ok:false,code:"unknown-logical-id",detail:e}}function ou(t,e,n){if(L(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:L(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 Ln(t,e,n){switch(e.kind){case "putNode":return ou(t,e.descriptor,n);case "spliceText":{let o=Pe(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=Pe(n,e.logicalId);return o||(L(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=Pe(n,e.logicalId);return o||(L(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=Pe(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=Pe(n,i);if(s)return s}let r=n.node(e.parentLogicalId);if(r&&!r.isText){if(e.start+e.deleteCount>r.children.length&&!ea(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=Pe(n,e.logicalId);if(o)return o;let r=Pe(n,e.destinationParentLogicalId);return r||(!Number.isSafeInteger(e.destinationIndex)||e.destinationIndex<0?{ok:false,code:"invalid-bound"}:null)}case "putXmlPart":{let o=Z(e.name);if(o)return {ok:false,code:o,detail:e.name};let r=Pe(n,e.rootLogicalId);return r||(t.partCount()>=t.limits.maxParts?{ok:false,code:"too-many-parts"}:null)}case "deleteXmlPart":{let o=Z(e.name);return o?{ok:false,code:o,detail:e.name}:null}case "putRelationship":{if(e.record.ownerPart!=="/"){let o=Z(e.owner);if(o)return {ok:false,code:o}}return L(e.record.id)?{ok:false,code:"prototype-key"}:t.relationshipCount()>=t.limits.maxRelationships?{ok:false,code:"too-many-relationships"}:null}case "deleteRelationship":return L(e.relationshipId)?{ok:false,code:"prototype-key"}:null;case "putContentTypeOverride":{let o=Z(e.partName);return o?{ok:false,code:o}:re(e.mediaType,t.limits.maxMediaTypeLength)?{ok:false,code:"invalid-string"}:null}case "deleteContentTypeOverride":{let o=Z(e.partName);return o?{ok:false,code:o}:null}case "putBinary":{let o=ii(e.descriptor);return o?{ok:false,code:o}:null}case "deleteBinary":return L(e.storageKey)?{ok:false,code:"prototype-key"}:null;default:return {ok:false,code:"invalid-bound"}}}function ru(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&&!_e(o)&&!_e(r)){e.push({...o,insert:r.insert}),n+=1;continue}e.push(o);}return e}function iu(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:[]});return;case "spliceText":if(n.has(e.logicalId)&&e.utf16Start===0&&e.deleteCount===0&&t.textOf(e.logicalId).toString()===e.insert)return;let o=_e(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;t.spliceChildren(e.parentLogicalId,ea(t,e,i)?i:e.start,e.deleteCount,e.childLogicalIds);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 su(t,e){let n=t.kindOf(e);return n!==null&&!n.endsWith("Properties")}function au(t,e,n,o){let r=new Set((n.get(e)??[]).filter(i=>su(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 lu(t,e){let n=new tt(t),o=[],r=new Set,i=new Set,s=new Set,a=new Set,l=new Map;for(let d of e){let c=Ln(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 p=d.start+d.deleteCount;for(let f=d.start;f<p;f+=1){let h=u.children[f];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 p of d.childLogicalIds)r.add(p),i.delete(p);}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));jt(n,d);}return {removed:o,reinserted:r,unlistedAtEnd:i,mintedText:s,mintedNodes:a,replacementsByEffect:l}}function du(t){let e=0;for(let n of t)n.kind==="putNode"&&(e+=1);return e}function gr(t,e,n,o){if(o){let c=false;return t.doc.transact(()=>{t.noteWrite(),c=Hs(t,o);},Io),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=yn(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(ft);if(t.nodeCount()+du(s)>t.limits.maxNodes)return {ok:false,code:"too-many-nodes"};let a=lu(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"&&mr(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&&Zs(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,wn(u,t.limits)]));}catch(c){if(!(c instanceof he))throw c;return {ok:false,code:c.code,detail:c.detail}}return t.doc.transact(()=>{t.noteWrite();let c=fu(t,a.removed),u=[],p=[];for(let g of ru(s))if(iu(t,g,a.mintedText),g.kind==="spliceChildren"){if(a.mintedNodes.has(g.parentLogicalId))for(let x of g.childLogicalIds)a.mintedNodes.has(x)&&t.kindOf(x)==="run"&&p.push(x);pu(t,a,a.replacementsByEffect.get(g)??[],g.childLogicalIds,u);}qs(t,u,p,(g,x)=>{t.recordRunSplit(Qs(t,g,a.reinserted),g,x);}),uu(t,s,a,c);let f=js(t,a.removed),h=r?Ws(t,r,d):{copied:new Set,deleted:new Set,embedded:new Set};cs(t,a.removed,h.embedded,a.mintedNodes,r?.paragraphs.map(({after:g})=>g)??[]),Ks(t,f.held,h.copied),$s(t,h,f.shown),zs(t,f.embeds,a.removed,h);},Io),{ok:true}}function cu(t,e){if(t.inline.textOf(e)===null&&Zs(t,e))return true;let n=t.record(e);return (n&&"childIds"in n?n.childIds:[]).some(r=>t.kindOf(r)==="run"&&mr(t,r))}function Gs(t,e){let n=t.kindOf(e)==="paragraph"?e:t.inline.owner(e)??t.parentOf(e);return n!==null&&cu(t,n)}function Zs(t,e){let n=t.schema.nodes.get(e);return N(n)&&Ii(n,ne)}function uu(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=au(t,i,o,e);s&&t.unlistChildren(i,o.get(i)??[]),t.tombstone(i,s);}}function pu(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=Qs(t,i,e.reinserted);if(s==="text"){let d=kn(s,o,c=>t.kindOf(c));if(d&&xt(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");xt(t,i,l)||r.push({removedId:i,runs:l}),t.recordRunSplit(a,i,l);}}function Qs(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 fu(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 ea(t,e,n){return e.deleteCount===0&&e.start>n&&t.partEntries().some(o=>o.rootLogicalId===e.parentLogicalId)}var ae="splitTextSource",hu=Object.freeze({kind:"docx-package-restored-split-anchors"});function se(t,e){throw new T(t,e)}function yr(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function ta(t){return yr(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 na(t){return !yr(t)||!Object.keys(t).every(e=>["type","item","assoc"].includes(e))||!ta(t.type)||t.item!==void 0&&!ta(t.item)||t.assoc!==0&&t.assoc!==-1?se("invalid-string",ae):B.createRelativePositionFromJSON(t)}var nt=class extends Error{},It=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);(!N(i)||!(i.get(de)instanceof B.Text))&&se("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||L(a.sourceId))&&se("invalid-string",n),(!Number.isSafeInteger(o)||!Number.isSafeInteger(r)||o<0||r<o||r>a.end-a.start||e===a.sourceId)&&se("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 p=a.start+c;return B.createRelativePositionFromTypeIndex(a.text,p,p===0&&u==="start"?-1:0)},d=JSON.stringify({sourceId:a.sourceId,start:B.relativePositionToJSON(l(o,"start")),end:B.relativePositionToJSON(l(r,"end"))});d.length>this.limits.maxStringLength&&se("invalid-string",e),i.set(ae,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=p=>B.getState(this.doc.store,p.client)>p.clock?B.getItem(this.doc.store,p):null,d=i,c=l(d);for(;c instanceof B.Item&&c.redone!==null;)d=B.createID(c.redone.client,c.redone.clock+d.clock-c.id.clock),c=l(d);let u=c instanceof B.Item&&!c.deleted&&!B.compareIDs(i,d)?B.createRelativePositionFromJSON({...B.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(N(i)&&Lo(i,ae))continue;let s=this.read(r);if(!s)continue;let a=n(s.start),l=n(s.end);if(B.compareRelativePositions(a,s.start)&&B.compareRelativePositions(l,s.end))continue;let d=JSON.stringify({sourceId:s.sourceId,start:B.relativePositionToJSON(a),end:B.relativePositionToJSON(l)});d.length>this.limits.maxStringLength&&se("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(ae,i),this.indexExisting(r);},hu);}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&&!ko(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)?n.get(de):null;return !(o instanceof B.Text)||o.doc!==this.doc||o.length>this.limits.maxTextLength?se("invalid-bound",e):o}read(e){let n=this.nodes.get(e);if(!N(n))return null;let o;if(Lo(n,ae)){if(o=this.lastEncoded.get(e),o===void 0)throw new nt(e);this.held.add(e);}else {if(!n.has(ae))return null;o=n.get(ae);}if(typeof o!="string"||o.length>this.limits.maxStringLength)return se("invalid-string",e);let r;try{r=JSON.parse(o);}catch{return se("invalid-string",e)}if(!yr(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||L(r.sourceId)||r.sourceId===e)return se("invalid-string",e);if(!(n.get(de)instanceof B.Text))return se("invalid-bound",e);let i={sourceId:r.sourceId,start:na(r.start),end:na(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&&B.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)&&n.has(ae))return se("invalid-bound",e.sourceId);let o=this.sourceText(e.sourceId),r=B.createRelativePositionFromTypeIndex(o,0).type;if(!r||[e.start,e.end].some(d=>d.type?.client!==r.client||d.type?.clock!==r.clock))return se("invalid-bound",e.sourceId);let i=B.createAbsolutePositionFromRelativePosition(e.start,this.doc,false),s=B.createAbsolutePositionFromRelativePosition(e.end,this.doc,false),a=e.start.item!==null&&B.getItem(this.doc.store,e.start.item).deleted,l=e.end.item!==null&&B.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?se("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 Rn(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(ae);if(typeof l!="string")return null;let d=JSON.parse(l),c=B.createRelativePositionFromJSON(d.start),u=B.createRelativePositionFromJSON(d.end);if(a=a&&(s||u.item!==null&&B.getItem(o.text.doc.store,u.item).deleted),!s&&!a)return null;let p=[],f=o.text.doc.store,h=g=>{if(g.item===null||!B.getItem(f,g.item).deleted)return false;let x=B.createAbsolutePositionFromRelativePosition(g,o.text.doc,false);return x!==null&&x.type===o.text&&x.index===o.end};for(let g of e.sourceAliases(o.sourceId)){if(!e.range(g))continue;let x=t.get(g),S=x.get(ae);if(typeof S!="string")continue;let v=JSON.parse(S),m=(y,R)=>{let E=B.createRelativePositionFromJSON(y);return s&&a&&B.compareRelativePositions(c,u)&&B.compareRelativePositions(E,c)?R==="start"?"after":"before":s&&B.compareRelativePositions(E,c)?"before":a&&B.compareRelativePositions(E,u)||a&&!s&&!(g===n&&R==="start")&&h(E)?"after":null},w=g===n&&s?"before":m(v.start,"start"),I=g===n&&a?"after":m(v.end,"end");(w||I)&&p.push({record:x,start:w,end:I});}return ()=>{let g=o.start+r,x=B.relativePositionToJSON(B.createRelativePositionFromTypeIndex(o.text,g,g===0&&o.startAssoc===-1?-1:0)),S=B.relativePositionToJSON(B.createRelativePositionFromTypeIndex(o.text,g+i.length,0));for(let v of p){let m=JSON.parse(v.record.get(ae));v.start&&(m.start=v.start==="before"?x:S),v.end&&(m.end=v.end==="before"?x:S);let w=JSON.stringify(m);w!==v.record.get(ae)&&v.record.set(ae,w);}}}var On=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);N(i)&&(i.set(Tt,e),i.set($e,e),this.indexExisting(r));}}indexExisting(e){let n=this.nodes.get(e),o=Xe(n);if(o===null||o===e||Vo(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=>Xe(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=>At(this.nodes.get(l))===i).map(l=>Ct(l)??"").sort()[0];for(let l of s)(Ct(l)??"")!==a&&r(l);}return this.cachedLosers=n,n}};function En(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}function oa(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 br=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=oa(n.start,n.startAssoc,r),n.end=oa(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=_e(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=(f,h)=>i&&h==="end"&&f===l?{assoc:i.endAssoc,deleted:i.endAnchorDeleted}:i&&f===0?{assoc:i.startAssoc,deleted:i.startAnchorDeleted}:i&&f===l?{assoc:i.endAssoc,deleted:i.endAnchorDeleted}:{assoc:a+f===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 p={kind:"register",product:e,source:n,start:o,end:r};this.actions.push(p),this.shadow&&this.replay(p);}destroy(){this.shadow?.doc.destroy();}ensureShadow(){if(this.shadow)return;let e=new B.Doc({gc:false}),n=e.getMap(xo);this.shadow={doc:e,nodes:n,sources:new It(n,e,this.registry.limits)},B.applyUpdate(e,B.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,Qt("")),n.nodes.get(u).get(de));if(e.kind==="register"){o(e.product),n.sources.register(e.product,e.source,e.start,e.end);return}let{effect:r}=e,i=_e(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=Rn(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?.();}},xr=class extends tt{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((s,a,l)=>!o.children.includes(s)&&l.indexOf(s)===a),i=r.length>0?[...o.children,...r]:o.children;o.children=this.shownOf(n)?.slice()??this.visibleIndexes(n,i).map(s=>i[s]);}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}};function ra(t,e,n){let o=Xs(t,e);return o?{ok:true,journal:{...e,effects:[]},plan:null,typed:o}:mu(t,e,n)}function mu(t,e,n=()=>null){let o=yn(t,e.effects);if(o.refusal)return {ok:false,...o.refusal};let i=(o.plan?{...e,effects:o.passThrough}:e).effects.map(ft),s=t.replacementLoserRuns(),a=i.filter(b=>b.kind==="putNode").length;if(t.nodeCount()+a>t.limits.maxNodes)return {ok:false,code:"too-many-nodes"};let l=new Set;for(let b of i){if(b.kind==="spliceChildren"){if(b.childLogicalIds.length>t.limits.maxChildren)return {ok:false,code:"too-many-children"};for(let k of b.childLogicalIds)l.add(k);}else b.kind==="moveNode"&&l.add(b.logicalId);if(l.size>t.limits.maxNodes)return {ok:false,code:"too-many-nodes"}}let d=new tt(t),c=new br(t,d),u=new xr(t,(b,k)=>x(b,k),d,c,b=>_(b),b=>n(b)),p=new Map,f=b=>p.get(b)?.kind??t.kindOf(b),h=b=>{let k=p.get(b);return k?k.kind==="textValue"?{kind:"textValue",namespaceUri:"",localName:""}:{kind:k.kind,namespaceUri:k.qname.namespaceUri,localName:k.qname.localName}:yt(t,b)},g=(b,k)=>{let O=new Set,C=[];((s.size===0?null:En(k,$=>s.has($),$=>t.splitLineageOf($)))??k.map(($,V)=>V)).forEach($=>{let V=k[$];V===b||O.has(V)||s.has(V)||(O.add(V),!(!p.has(V)&&!t.showsAsChild(V))&&C.push($));});let A=gn(f(b),C.map($=>k[$]),h);if(!A)return {positions:C,companions:new Map};let M=new Map;for(let[$,V]of A.companions)M.set(C[$],V.map(Q=>C[Q]));return {positions:A.order.map($=>C[$]),companions:M}},x=(b,k)=>g(b,k).positions,S=b=>b.some((k,O)=>O>0&&k<b[O-1]),v=(b,k,O,C)=>{let Y=x(b,k),A=Y[O]??k.length;if(!S(Y))return A;let M=O>0?Y[O-1]+1:0;for(let $ of [A,M,k.length]){let V=[...k.slice(0,$),...C,...k.slice($)],Q=x(b,V).map(De=>V[De]);if(C.every((De,Ye)=>Q[O+Ye]===De))return $}return A},m=b=>{let k=[b],O=new Set;for(;k.length>0;){let C=k.pop();if(O.has(C))continue;O.add(C);let Y=d.node(C);if(!(!Y||Y.isText)){for(let A of Y.children)if(!(l.has(A)||t.parentOf(A)!==C)){for(let M of t.listingParents(A)){if(M===C)continue;let $=d.node(M),V=$&&!$.isText?$.children.indexOf(A):-1;V<0||K({kind:"spliceChildren",parentLogicalId:M,start:V,deleteCount:1,childLogicalIds:[]});}k.push(A);}}}},w=new Set,I=b=>{if(w.has(b))return;w.add(b);let k=n(b),O=d.node(b);if(!k||!O||O.isText)return;let C=O.children;if(k.length===C.length&&k.every((A,M)=>C[M]===A))return;for(let A of k)if(!C.includes(A))for(let M of t.listingParents(A)){let $=d.node(M),V=$&&!$.isText?$.children.indexOf(A):-1;V<0||M===b||K({kind:"spliceChildren",parentLogicalId:M,start:V,deleteCount:1,childLogicalIds:[]});}let Y=C.filter(A=>!k.includes(A));K({kind:"spliceChildren",parentLogicalId:b,start:0,deleteCount:C.length,childLogicalIds:[...k,...Y]});},y=new Set,R=b=>{if(y.has(b))return;y.add(b);let k=d.node(b);if(!k||k.isText)return;let O=t.adoptedChildren(b).filter(C=>!k.children.includes(C));if(O.length!==0){for(let C of O)for(let Y of t.listingParents(C)){if(t.replacedByOf(Y)!==b)continue;let A=d.node(Y),M=A&&!A.isText?A.children.indexOf(C):-1;M<0||K({kind:"spliceChildren",parentLogicalId:Y,start:M,deleteCount:1,childLogicalIds:[]});}K({kind:"spliceChildren",parentLogicalId:b,start:k.children.length,deleteCount:0,childLogicalIds:O});}},E=b=>{if(!$o.has(f(b)??""))return [];let k=t.parentOf(b),O=k?d.node(k):null;return !k||!O||O.isText?[]:(g(k,O.children).companions.get(O.children.indexOf(b))??[]).map(Y=>O.children[Y])},_=b=>{let k=[];for(let O of E(b)){let C=d.node(O);C&&!C.isText&&k.push(...C.children);}return k},U=new Set,j=b=>{if(U.has(b))return;U.add(b);let k=d.node(b);if(!k||k.isText)return;let O=[];for(let C of E(b)){let Y=d.node(C);if(!Y||Y.isText||Y.children.length===0)continue;let A=[...Y.children];K({kind:"spliceChildren",parentLogicalId:C,start:0,deleteCount:A.length,childLogicalIds:[]});for(let M of A)!k.children.includes(M)&&!O.includes(M)&&O.push(M);}O.length!==0&&K({kind:"spliceChildren",parentLogicalId:b,start:d.node(b).children.length,deleteCount:0,childLogicalIds:O});},X={limits:t.limits,projectedTextValue:b=>d.node(b)?.isText?c.value(b):null,registerSplitText:(b,k,O,C)=>c.register(b,k,O,C),splitTextPending:b=>t.splitTextPending(b),record:b=>{let k=d.node(b);if(!k)return null;if(k.isText)return {logicalId:b,kind:"textValue",value:c.value(b)};let O=p.get(b),C=O?null:t.record(b);return C&&C.kind!=="textValue"?{...C,childIds:k.children}:!O||O.kind==="textValue"?null:{logicalId:b,kind:O.kind,namespaceUri:O.qname.namespaceUri,localName:O.qname.localName,prefix:O.qname.prefix??"",attributes:[],bindings:[],childIds:k.children}}},J=[],D=null,K=b=>{if(D)return;let k=Ln(t,b,d);if(k&&!k.ok){D=k;return}J.push(b),jt(d,b),b.kind==="spliceText"&&c.apply(b);};try{for(let b of i){let k=Ln(t,b,u);if(k&&!k.ok)return k;if(jt(u,b),b.kind==="putNode"&&p.set(b.descriptor.logicalId,b.descriptor),b.kind==="spliceText"){let O=c.range(b.logicalId);K(O?Jr({...b,logicalId:O.sourceId,utf16Start:O.start+b.utf16Start},{logicalId:b.logicalId,utf16Start:b.utf16Start}):b);}else if(b.kind==="spliceChildren"){I(b.parentLogicalId),R(b.parentLogicalId),j(b.parentLogicalId);let O=d.node(b.parentLogicalId);if(!O||O.isText)return {ok:!1,code:"invalid-bound"};let{positions:C,companions:Y}=g(b.parentLogicalId,O.children),A=C.slice(b.start,b.start+b.deleteCount).map(M=>O.children[M]);if(b.deleteCount===0){let M=b.childLogicalIds;K({...b,start:v(b.parentLogicalId,O.children,b.start,M)});}else {let M=C.slice(b.start,b.start+b.deleteCount),$=M.flatMap(Q=>Y.get(Q)??[]);if($.length>0||S(C)){let Q=[...M,...$].sort((Ye,po)=>po-Ye);for(let Ye of Q)K({...b,start:Ye,deleteCount:1,childLogicalIds:[]});let De=d.node(b.parentLogicalId);if(b.childLogicalIds.length>0&&De&&!De.isText){let Ye=b.childLogicalIds,po=v(b.parentLogicalId,De.children,b.start,Ye);K({...b,start:po,deleteCount:0});}M.length=0;}let V=M.length;for(;V>0;){let Q=V-1;for(;Q>0&&M[Q-1]===M[Q]-1;)Q-=1;K({...b,start:M[Q],deleteCount:V-Q,childLogicalIds:Q===0?b.childLogicalIds:[]}),V=Q;}}if(!D)for(let M of A)l.has(M)||m(M);if(!D&&b.childLogicalIds.length>0)for(let M of A){if(l.has(M)&&!p.has(M))continue;let $=kn(f(M),b.childLogicalIds,f);$&&xt(X,M,$);}}else if(b.kind==="moveNode"){I(b.destinationParentLogicalId),R(b.destinationParentLogicalId),j(b.destinationParentLogicalId);let O=d.node(b.destinationParentLogicalId);if(!O||O.isText)return {ok:!1,code:"invalid-bound"};let C=O.children.filter(Y=>Y!==b.logicalId);K({...b,destinationIndex:v(b.destinationParentLogicalId,C,b.destinationIndex,[b.logicalId])});}else K(b);if(D)return D}return {ok:!0,journal:{effects:J},plan:o.plan}}finally{c.destroy();}}var Ir=Symbol("docx-restore-marks");function ia(t,e){let n=new Map;for(let r of Jt(t,e)){if(r.deleted||!(r.content instanceof B.ContentString))continue;let i=r.parent;if(!(i instanceof B.Text)||Be(i)!==ne)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=ye(t);t.transact(()=>{for(let[r,i]of n)for(let s=Vt(r);s;s=s.right){if(!s.redone)continue;let a=`${s.redone.client}:${s.redone.clock}`;if(!i.has(a))continue;let l=le(t,s.redone);if(!l||l.deleted)continue;let d=Ds(r,s,0);o.markCopy("restore",s.redone.client,s.redone.clock,s.length,d);}},Ir);}function Sr(t,e,n){for(let o of e)n.push(o.id),!(o.kind==="textValue"||t.hasNode(P(o)))&&Sr(t,o.children,n);}function sa(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&&yu(t,o)!==n.rootLogicalId)continue;let s=ke(o,i,d=>t.showsAsChild(d)?sn(d):null,t.limits,t.inline.viewOf(o)),a=[];Sr(t,s,a);let l=[];if(Sr(t,r.children.filter(d=>d.kind==="textValue"||!gu(t,d)),l),a.length!==l.length)return true;for(let d=0;d<a.length;d+=1)if(a[d]!==l[d])return true}return false}function gu(t,e){return e.kind==="paragraphProperties"||t.hasNode(P(e))&&!t.inline.isEmbed(e.id)}function yu(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 bu=new Set(["comment","footnote","endnote"]),aa="docx-undone-records";function xu(t,e,n,o){let r=n?.meta,i=e==="undo"?o.filter(a=>{let l=t.record(a);return N(t.schema.nodes.get(a))&&!t.isTombstoned(a)&&!!l&&F(l)&&bu.has(l.localName)}):[],s=e==="redo"?r?.get(aa)??[]:[];e==="undo"&&r?.set(aa,i),!(i.length===0&&s.length===0)&&t.doc.transact(()=>{for(let a of i)t.schema.nodes.get(a)?.set(ze,true);for(let a of s){let l=t.schema.nodes.get(a);N(l)&&l.has(ze)&&l.delete(ze);}},Ir);}var vr="docx-copy-runs",la="docx-hidden-copies",da="docx-copies-only";function ca(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"?Su(t,s):kr(s,vr)??[],l=i.length;s?.meta.get(da)===true&&Iu(s)===0||a.length>0&&wu(t,s)?r.pop():n==="undo"?e.undo():e.redo(),o();let c=i.length>l?i[i.length-1]:void 0;if(n==="redo"){let u=kr(s,la);u&&u.length>0&&t.doc.transact(()=>Le(t.doc).withdraw(u));}if(a.length>0&&(c??=vu(i),c.meta.set(vr,a),n==="undo")){let u=[];t.doc.transact(()=>{u=Le(t.doc).record(a);}),c.meta.set(la,u);}xu(t,n,n==="redo"?s:c,t.takeUnlisted()),e.stopCapturing();}function Iu(t){let e=t;return at(e.insertions).length+at(e.deletions).length}function Su(t,e){let n=t.inline.follow,o=[...kr(e,vr)??[]],r=(i,s,a)=>{let l=o[o.length-1];l&&l.client===i&&l.to===s?o[o.length-1]={...l,to:a}:o.push({client:i,from:s,to:a});};for(let i of at(e?.insertions)){let s=i.clock+i.length;for(let a=i.clock;a<s;){let l=le(t.doc,{client:i.client,clock:a}),d=l?Math.min(l.id.clock+l.length,s):a+1;if(l?.deleted){for(let c=a;c<d;c+=1)if(n.shownCopy(`${i.client}:${c}`)!==null){r(i.client,a,d);break}}a=d;}}return o}function wu(t,e){if(!e||at(e.deletions).length>0)return false;for(let n of at(e.insertions))for(let o=n.clock;o<n.clock+n.length;){let r=le(t.doc,{client:n.client,clock:o});if(!r||!r.deleted)return false;o=r.id.clock+r.length;}return true}function kr(t,e){return t?.meta.get(e)}function vu(t){let e={meta:new Map([[da,true]])};return Object.assign(e,{insertions:B.createDeleteSet(),deletions:B.createDeleteSet()}),t.push(e),e}var Tn=class{constructor(e,n){this.undoManager=e;let o=r=>{this.capturing&&r.type==="undo"&&(this.gestureItem=r.stackItem,this.captured=true);};e.on("stack-item-added",o),e.on("stack-item-updated",o),n&&Ru(n,e,()=>this.reset());}undoManager;previous;gestureItem;capturing=false;captured=false;capture(e,n){let o=this.previous;this.previous=e;let r=this.undoManager.undoStack,i=this.undoManager.captureTimeout;e===o&&e!==void 0&&r[r.length-1]===this.gestureItem?(this.undoManager.lastChange=Date.now(),this.undoManager.captureTimeout=Number.POSITIVE_INFINITY):((e!==o||e!==void 0)&&this.undoManager.stopCapturing(),this.gestureItem=void 0);let s=this.gestureItem;this.captured=false,this.capturing=e!==void 0;try{let a=n();return this.captured&&reportHistoryGroup(e,this.gestureItem===s?"extended":"started"),a}catch(a){throw this.reset(),a}finally{this.capturing=false,this.undoManager.captureTimeout=i;}}reset(){this.previous=void 0,this.gestureItem=void 0;}};function Ru(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 ua(t,e){let n=ye(t),o=Le(t),r=a=>{if(e.loading())return;let l=e.inline.marksChanged(a==="all"?e.inline.allTexts():a);l.size>0&&e.changed(l);},i=n.subscribe(r),s=o.subscribe(a=>r(n.textsReading(a)));return ()=>{i(),s();}}function pa(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 fa(t,e,n){if(e===n)return 0;let o=pa(t,e),r=pa(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 Pn=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 ha(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(W(c));a=true;continue}s.add(W(d[0])),l.target instanceof B.Array&&(a=true),l.target instanceof B.Map&&(l.changes.keys.has(Ie)||l.changes.keys.has(je))&&(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=Nt(String(a))??Je(String(a));!l||L(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 ma(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&&F(o)&&o.childIds.includes(e)}function An(t){return typeof t=="string"?t:""}function ga(t,e){return t<e?-1:t>e?1:0}function Lr(t,e){return `${t}${ee}${e}`}function Eu(t){let e=t.indexOf(ee);return e<0?t:t.slice(0,e)}function ya(t){let e=[];return t.forEach((n,o)=>{!N(n)||L(o)||n.forEach(r=>{if(!N(r))return;let i=An(r.get("id")),s=An(r.get("type"));if(i.length===0||s.length===0)return;let a=An(r.get("ownerPart"))||Eu(o);if(L(a))return;let l=r.get("order");e.push({ownerPart:a,id:i,type:s,rawTarget:An(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||ga(n.ownerPart,o.ownerPart)||ga(n.id,o.id)),e}function ba(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 Cu(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 Tu(t,e){let n=t.childrenSnapshot.get(e);return n||(te(t.nodes.get(e))?.toArray()??[])}function Pu(t,e){let n=t.nodes.get(e);return !N(n)||we(n)}var Rr=class{constructor(e){this.ctx=e;}ctx;byParent=new Map;indexOf(e,n){let o=this.byParent.get(e);return o||(o=new Map,Tu(this.ctx,e).forEach((r,i)=>{o.has(r)||o.set(r,i);}),this.byParent.set(e,o)),o.get(n)??-1}};function Nu(t,e,n,o,r){let i=[],s=new Set,a=r,l;for(;;){if(s.has(a)||(s.add(a),Pu(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 p=i[u],f=e.indexOf(c,p);if(f<0)return null;d.push(f),c=p;}return d}function Au(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 Rr(t),i=new Map,s=l=>{let d=i.get(l);if(d!==void 0)return d;let c=Nu(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 p of t.listings.get(d)??[]){if(p===d)continue;let f=s(p);if(f==="fallback")return false;if(f==="deferred"){u=true;continue}if(f===null)continue;let h=r.indexOf(p,d);if(h<0)continue;let g=[...f,h];(!c||Cu(g,c.rank)<0)&&(c={rank:g,parent:p});}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 Or(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(!N(u)||we(u))continue;let p=r.get(c)??te(u)?.toArray()??[];a.add(c),l.push({id:c,parent:null,exit:true});let f=new Set,h=[];for(let g of p)f.has(g)||g===c||(f.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 xa(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&&(Au(t,n)||Or(t,new Set(n)));}function Ia(t,e){return `${t}${ee}${e}`}function Er(t,e,n,o,r){if(L(n)||L(o.localName))return;let i=dt(t.namespaces,o.namespaceUri,e),s=wo(n,i,o.localName);L(s)||t.attributes.set(s,ui(o.prefix??"",r));}function Sa(t,e,n,o){t.attributes.delete(wo(e,We(n),o));}function Cr(t,e,n,o,r){if(L(n)||L(o))return;let i=dt(t.namespaces,r,e),s=vo(n,o);L(s)||t.bindings.set(s,i);}function wa(t,e,n){t.bindings.delete(vo(e,n));}function va(t,e,n,o,r,i){let{prefix:s,value:a}=pi(i),l=e.get(n);l||(l=new Map,e.set(n,l)),l.set(Ia(o,r),{namespaceUri:Ve(t.namespaces,o),localName:r,prefix:s.length>0?s:void 0,value:a});}function Mu(t,e,n,o){let r=t.get(e);r&&(r.delete(Ia(n,o)),r.size===0&&t.delete(e));}function ka(t,e,n,o,r){let i=e.get(n);i||(i=new Map,e.set(n,i)),i.set(o,{prefix:o,namespaceUri:Ve(t.namespaces,r)});}function Du(t,e,n){let o=t.get(e);o&&(o.delete(n),o.size===0&&t.delete(e));}function La(t,e,n){for(let[o,r]of n.changes.keys){let i=Nt(String(o));if(!i||L(i.logicalId)||L(i.localName))continue;if(r.action==="delete"){Mu(e,i.logicalId,i.namespaceId,i.localName);continue}let s=t.attributes.get(String(o));typeof s=="string"&&va(t,e,i.logicalId,i.namespaceId,i.localName,s);}}function Ra(t,e,n){for(let[o,r]of n.changes.keys){let i=Je(String(o));if(!i||L(i.logicalId)||L(i.prefix))continue;if(r.action==="delete"){Du(e,i.logicalId,i.prefix);continue}let s=t.bindings.get(String(o));typeof s=="string"&&ka(t,e,i.logicalId,i.prefix,s);}}function Oa(t,e,n){t.attributes.forEach((o,r)=>{if(typeof o!="string"||L(r))return;let i=Nt(r);!i||L(i.logicalId)||L(i.localName)||va(t,e,i.logicalId,i.namespaceId,i.localName,o);}),t.bindings.forEach((o,r)=>{if(typeof o!="string"||L(r))return;let i=Je(r);!i||L(i.logicalId)||L(i.prefix)||ka(t,n,i.logicalId,i.prefix,o);});}function Tr(t,e,n){let o=t.listings.get(e)??new Set;o.add(n),t.listings.set(e,o);}function Yu(t,e,n){let o=t.listings.get(e);o&&(o.delete(n),o.size===0&&t.listings.delete(e));}function Ea(t,e,n){let o=t.childrenSnapshot.get(e)??[];if(on(o,n))return [];let r=new Set(n),i=new Set(o),s=[];for(let a of o)r.has(a)||(Yu(t,a,e),s.push(a));for(let a of n)i.has(a)||(Tr(t,a,e),s.push(a));return t.childrenSnapshot.set(e,n),s}var Mn=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=nn(o);if(n!==void 0&&n!==r&&this.recompute(n),r!==null){if(we(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=[],o=Si(this.nodes,this.sources.get(e));for(let r of o){let i=this.nodes.get(r);if(i)for(let s of te(i)?.toArray()??[])this.reads.isTombstoned(s)||!this.nodes.has(s)||this.isContentWitness(s)&&n.push(s);}n.length>0?this.adoptees.set(e,n):this.adoptees.delete(e);}};function ot(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 _u=/^\d{10}$/,Pr=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 wt(t){return t.first()}function Bu(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 Dn=class{constructor(e,n,o,r){this.nodes=e;this.limits=n;this.isDeleted=o;this.follow=new vn(i=>this.textOf(i),o,r,i=>this.noteOthers(i),i=>this.paragraphHolding(i));}nodes;limits;isDeleted;holders=new Map;idsOf=new Map;embeds=new Set;affected=new Set;built=false;drift=false;follow;paragraphHolding(e){let n=fe(e),o=this.nodes.doc;if(!o||!n)return null;let{client:r,clock:i}=n,s=le(o,{client:r,clock:i})?.parent;if(!(s instanceof B.Text)||Be(s)!==ne)return null;let a=Ee(s)?.parent,l=a instanceof B.Map?Be(a):null;if(l===null||L(l))return null;let d=W(l);return this.textOf(d)===s?d:null}isDeletedParagraph(e){return this.isDeleted(e)}textOf(e){let n=this.nodes.get(e);if(!N(n))return null;let o=n.get(ne);return o instanceof B.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(ot(d)===o)return d;for(let d of i)for(let c of this.follow.targetsFor(d))if(ot(c)===o)return c;let l=this.paragraphTagged(o);if(l)return l}return wt(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&&_u.test(a)&&(o=a),n=n.slice(0,s);}return null}paragraphTagged(e){for(let o of this.idsOf.keys())if(ot(o)===e)return o;let n=null;return this.nodes.forEach((o,r)=>{n===null&&ot(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}~${ot(e)}`;let o=this.holders.get(n);return o&&!o.has(e)?`${n}~${ot(e)}`:!o||o.size<2||wt(o)===e?n:`${n}~${ot(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||wt(o)===e},shown:n=>this.follow.shown(e,n),textOf:n=>this.textOf(n),lineageOf:n=>ds(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(Be(o)!==ne)continue;let r=Ee(o)?.parent,i=r instanceof B.Map?Be(r):null;if(i===null||L(i))continue;let s=W(i);this.textOf(s)===o&&(this.follow.invalidate(s),this.paragraphChanged(s),n.add(s));}return n}paragraphChanged(e){if(!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 Bu(ue(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.affected.add(n);}listingChanged(e){if(this.built){for(let n of this.holders.get(e)??[])this.affected.add(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 Pr,this.holders.set(e,o)),o.size>0){let i=wt(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=wt(o)===n;if(o.delete(n),o.size===0){this.holders.delete(e),this.embeds.delete(e);return}r&&this.affected.add(wt(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)=>{N(e)&&e.get(ne)instanceof B.Text&&this.paragraphChanged(W(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 vt(t){return typeof t=="string"?t:""}function Ca(t){let e=[];return t.forEach((n,o)=>{if(!N(n)||L(o))return;let r=vt(n.get("rootId"));r.length!==0&&e.push({name:o,id:vt(n.get("id")),rootLogicalId:r,contentType:vt(n.get("contentType"))});}),e.sort((n,o)=>n.name<o.name?-1:n.name>o.name?1:0),e}function Ta(t){let e=new Map;return t.forEach((n,o)=>{typeof n=="string"&&!L(o)&&e.set(partNameKey(o),n);}),e}function Pa(t){let e=new Map;return t.forEach((n,o)=>{typeof n=="string"&&!L(o)&&e.set(o,n);}),e}function Na(t){let e=[];return t.forEach((n,o)=>{if(!N(n)||L(o))return;let r=vt(n.get("digest")),i=n.get("size"),s=vt(n.get("mediaType")),a=vt(n.get("storageKey"))||o;r.length===0||typeof i!="number"||e.push({digest:r,size:i,mediaType:s,storageKey:a});}),e}var Nr="/word/numbering.xml",Fu="http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering";function Aa(t,e){let n=e.parent;if(n===t.bindings&&e.parentSub){let a=Je(e.parentSub),l=a&&t.nodes.get(a.logicalId);if(l){let d=Se(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===Nr||n===t.parts&&e.parentSub===Nr)return true;let o=Ee(n);if(o?.parent===t.parts&&o.parentSub===Nr)return true;let r=a=>a instanceof B.Map&&a.get("type")===Fu,i=a=>a instanceof B.Map&&[...a.values()].some(r);return n===t.relationships?e.content.getContent().some(i):o?.parent===t.relationships?e.content.getContent().some(r):Ee(o?.parent)?.parent===t.relationships&&r(n)}function ju(t){return t.content instanceof B.ContentType}function Da(t){return e=>{let n=e.parent;if(n===null)return true;if(n===t)return false;let o=Ee(n);return o===null||o.parent!==t?true:e.parentSub===$e||e.parentSub===Gt?false:!ju(e)}}var Oe=class{constructor(e,n){this.doc=e;this.stopKeepingMarkers=Xr(e),this.schema=di(e),this.limits=ri(n),this.splitDedup=new On(this.schema.nodes),this.inline=new Dn(this.schema.nodes,this.limits,o=>this.isTombstoned(o)||!this.parentIndex.has(o),(o,r)=>fa({parentOf:i=>this.parentIndex.get(i),childrenOf:i=>this.childrenSnapshot.get(i),maxDepth:this.limits.maxTreeDepth},o,r)),this.adoption=new Mn(this.schema.nodes,{kindOf:o=>this.kindOf(o),isTombstoned:o=>this.isTombstoned(o),listersOf:o=>this.listings.get(o)??[]}),this.splitTextSources=new It(this.schema.nodes,this.doc,this.limits),this.stopMarks=ua(e,{inline:this.inline,loading:()=>this.bulkLoad>0,changed:o=>{for(let r of this.markListeners)r(o);}}),this.stopObserving=ba(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 Pn;contested=new Set;reparented=new Set;listings=new Map;childrenSnapshot=new Map;adoption;inline;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(Qo)]}undoDeleteFilter(){let e=Da(this.schema.nodes);return n=>!Aa(this.schema,n)&&e(n)}encodeSnapshot(){return B.encodeStateAsUpdate(this.doc)}encodeUpdate(e){return B.encodeStateAsUpdate(this.doc,e)}partEntries(){return Ca(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 Oi(this.schema.meta.get("mainDocumentPart"))}record(e){if(L(e))return null;let n=this.schema.nodes.get(e);if(!N(n))return null;if(ct(n)){let o=n.get(de),r=o instanceof B.Text?o.toString():"";return {logicalId:e,kind:"textValue",value:r}}return Li(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&&F(o)?o.attributes:[];return {logicalId:e,yjsItemKey:Ri(n),wordFacingIds:ni(r)}}isTombstoned(e){return we(this.schema.nodes.get(e))}replacedByOf(e){return nn(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(We(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(Eo)}nodeCount(){return this.nodeCountCache<0&&(this.nodeCountCache=this.schema.nodes.size),this.nodeCountCache+this.pendingNodeAdds}nodeShape(e){return L(e)?null:vi(this.schema.nodes,e)}kindOf(e){return L(e)?null:ki(this.schema.nodes,e)}noteNodeWrite(e){this.schema.nodes.has(e)||(this.pendingNodeAdds+=1);}putElement(e){this.noteNodeWrite(e.logicalId);let n=dt(this.schema.namespaces,e.namespaceUri,this.limits.maxStringLength);this.schema.nodes.set(e.logicalId,fi({logicalId:e.logicalId,kind:e.kind,namespaceUri:e.namespaceUri,namespaceId:n,localName:e.localName,prefix:e.prefix}));for(let o of e.attributes)Er(this.schema,this.limits.maxStringLength,e.logicalId,o,o.value);for(let o of e.bindings)Cr(this.schema,this.limits.maxStringLength,e.logicalId,o.prefix,o.namespaceUri);}updateElementShell(e,n){let o=this.require(e),r=dt(this.schema.namespaces,n.namespaceUri,this.limits.maxStringLength);o.set(qt,So(n.kind,r,n.localName,n.prefix??""));}putText(e,n){this.noteNodeWrite(e),this.schema.nodes.set(e,Qt(n));}spliceText(e,n,o,r){let i=this.splitTextSources.range(e),s=Rn(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){Sa(this.schema,e,n.namespaceUri,n.localName);return}Er(this.schema,this.limits.maxStringLength,e,n,o);}setNamespaceBinding(e,n,o){if(o===null){wa(this.schema,e,n);return}Cr(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(Ie,true),n&&o.set(je,n);}recordRunSplit(e,n,o){this.splitDedup.record(e,n,o);}splitOriginOf(e){return At(this.schema.nodes.get(e))}splitLineageOf(e){return Xe(this.schema.nodes.get(e))}replacementLoserRuns(){return this.hasUnobservedWrites()&&this.splitDedup.invalidate(),this.splitDedup.loserRuns({isPresent:e=>ma(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){if(n.length===0)return;let o=this.schema.nodes.get(e),r=o?te(o):null;if(!r)return;let i=new Map;for(let s of n)i.set(s,(i.get(s)??0)+1);for(let s=r.length-1;s>=0;s-=1){let a=r.get(s),l=i.get(a)??0;l!==0&&(i.set(a,l-1),r.delete(s,1));}}putXmlPart(e){this.partCountCache=-1,this.schema.parts.set(e.name,hi(e.id,e.rootLogicalId,e.contentType));}deleteXmlPart(e){this.partCountCache=-1,this.schema.parts.delete(e);}putRelationship(e){if(L(e.ownerPart)||L(e.id))return;this.relationshipCountCache=-1;let n=new B.Map;n.set(e.id,mi(e)),this.schema.relationships.set(Lr(e.ownerPart,e.id),n);}deleteRelationship(e,n){this.relationshipCountCache=-1,this.schema.relationships.delete(Lr(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,gi(e));}deleteBinary(e){this.schema.binaries.delete(e);}relationships(){return ya(this.schema.relationships)}contentTypeOverrides(){return Ta(this.schema.overrides)}contentTypeDefaults(){return Pa(this.schema.defaults)}binaries(){return Na(this.schema.binaries)}hasNode(e){return this.schema.nodes.has(e)}showsAsChild(e){let n=this.schema.nodes.get(e);return n===void 0||we(n)?false:!(ct(n)&&this.splitTextPending(e))}observeDirty(e){let n=ha(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(!Eo(o))return;let r=te(n);if(!r)return;let i=r.toArray();this.childrenSnapshot.set(o,i);for(let s of i)Tr(this.listingIndex(),s,o);}),this.schema.nodes.forEach((n,o)=>{we(n)&&this.adoption.sync(W(o)),this.splitDedup.indexExisting(W(o));}),Oa(this.schema,this.attributesByNode,this.bindingsByNode),Or(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(){Ei(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 B.Text)&&(r.path.length===0||r.target instanceof B.Array||r.target instanceof B.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(W(r.path[0])),r.target instanceof B.Text&&r.path[1]===ne){this.inline.paragraphChanged(W(r.path[0]));continue}if(r.target instanceof B.Map&&r.path.length===1&&(r.changes.keys.has(ne)||r.changes.keys.has(Ie))&&this.inline.paragraphChanged(W(r.path[0])),r.path.length===0&&r.target instanceof B.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),!L(String(i))){if(s.action==="delete"){this.inline.paragraphChanged(W(i));continue}this.splitDedup.indexExisting(W(i)),this.splitTextSources.noteChanged(W(i));for(let a of this.syncChildListings(W(i)))n.add(a);this.inline.paragraphChanged(W(i)),this.inline.recordArrived(W(i)),this.isTombstoned(W(i))&&this.adoption.sync(W(i)),this.adoption.recomputeListerSurvivors(W(i));}continue}if(r.target instanceof B.Map&&r.path.length===1&&r.changes.keys.has(ze)&&this.history.noteMarkChanged(W(r.path[0])),r.target instanceof B.Map&&r.path.length===1&&(r.changes.keys.has("splitFrom")||r.changes.keys.has("splitLineage"))&&this.splitDedup.indexExisting(W(r.path[0])),r.target instanceof B.Array&&r.path.length>0){o=true;let i=W(r.path[0]);for(let s of this.syncChildListings(i))n.add(s);this.isTombstoned(i)&&this.adoption.sync(i);continue}if(r.target instanceof B.Map&&r.path.length===1&&(r.changes.keys.has(Ie)||r.changes.keys.has(je))){o=true;let i=W(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.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,La(this.schema,this.attributesByNode,e);}applyBindingMapEvent(e){this.unobservedWrites=0,Ra(this.schema,this.bindingsByNode,e);}syncChildListings(e){let n=this.schema.nodes.get(e),o=n?te(n)?.toArray()??[]:[];return Ea(this.listingIndex(),e,o)}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){xa(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=te(o);r&&this.removeFromArray(r,e);});return}for(let o of n){let r=this.schema.nodes.get(o),i=r?te(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(de);if(!(n instanceof B.Text))throw new Error(`no text at ${e}`);return n}childArray(e){let n=this.require(e).get(Zt);if(!(n instanceof B.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 Yn=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 zu(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 _a(t){let e=t.binaryPart;return typeof e=="function"?e:null}function Ba(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 Ua(t,e){for(let n of e)t.put(n.digest,n.bytes);}function Ku(t){return t.attributes.map(e=>({namespaceUri:e.namespaceUri,localName:e.localName,prefix:e.prefix,value:e.value}))}function Wu(t){return t.namespaceBindings.map(e=>({prefix:e.prefix,namespaceUri:e.namespaceUri}))}function _n(t,e,n,o,r){if(o>t.limits.maxTreeDepth)return "tree-too-deep";if(L(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(P(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(L(i.localName))return "prototype-key";if(re(i.namespaceUri,t.limits.maxStringLength))return "invalid-string"}for(let i of e.namespaceBindings){if(L(i.prefix))return "prototype-key";if(re(i.namespaceUri,t.limits.maxStringLength))return "invalid-string"}if(t.putElement({logicalId:P(e),kind:e.kind,namespaceUri:e.namespaceUri,localName:e.localName,prefix:e.prefix,attributes:Ku(e),bindings:Wu(e)}),e.kind==="paragraph"){let i=Vu(t,e,o,r);if(i)return i}else for(let i of e.children){let s=_n(t,i,P(e),o+1,r);if(s)return s}}return n&&t.childArray(n).push([P(e)]),null}function Vu(t,e,n,o){let r=ln(e);for(let a of r.shell.children){let l=_n(t,a,P(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=_n(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{mn(s,zi(r.items,e.id,t.limits));}catch(a){if(a instanceof he)return a.code;throw a}return null}async function Ju(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=Z(o);if(a)return {ok:false,code:a};if(r.byteLength>Ue.maxBlobBytes)return {ok:false,code:"blob-too-large"};let l=await zu(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 Bn(t,e,n=new Yn){if(e.parts.size>t.limits.maxParts)return {ok:false,code:"too-many-parts"};let o=await Ju(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=Z(a);if(d){r=d;return}if(re(l.contentType,t.limits.maxMediaTypeLength)){r="invalid-string";return}let c=_n(t,l.root,null,0,i);if(c){r=c;return}t.putXmlPart({name:a,id:l.id,rootLogicalId:P(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=Z(l.ownerPart);if(d){r=d;return}}if(L(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(L(a)){r="prototype-key";return}t.putContentTypeDefault(a,l);}for(let[a,l]of e.contentTypes.overrides){let d=Z(a);if(d){r=d;return}t.putContentTypeOverride(a,l);}for(let a of o.descriptors)t.putBinary(a);yi(t.schema.meta),t.schema.meta.set("mainDocumentPart",e.mainDocumentPart);},li);}finally{t.endBulkLoad();}return r?{ok:false,code:r}:{ok:true}}function me(t,e){return t.attributes.find(n=>n.localName===e)?.value}function Mr(t){return t.kind==="textValue"?t.id:me(t,"id")??t.id}function zt(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 za(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(ve(n,zt(n.children,e)));return Object.freeze({...t,root:o})}function Xu(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 Wa(t){}function Ja(t,e){return Object.freeze({id:t,kind:"textValue",value:e})}function ep(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 tp(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 Un(t,e,n){let o=n&&n.kind!=="textValue"?n:void 0;return Object.freeze(ce({id:t.logicalId,kind:t.kind,namespaceUri:t.namespaceUri,localName:t.localName,...t.prefix===void 0?{}:{prefix:t.prefix},namespaceBindings:o&&ep(o,t)?o.namespaceBindings:Object.freeze(t.bindings.map(r=>Object.freeze({...r}))),attributes:o&&tp(o,t)?o.attributes:Object.freeze(t.attributes.map(Xu)),children:e}))}function Xa(t,e){if(t.attributes.length!==e.attributes.length)return false;let n=new Map(e.attributes.map(o=>[`${o.namespaceUri}
|
|
3
|
+
${o.localName}`,o.value]));for(let o of t.attributes)if(n.get(`${o.namespaceUri}
|
|
4
|
+
${o.localName}`)!==o.value)return false;return t.localName===e.localName&&t.kind===e.kind}function Dr(t,e){let n=e.size;e.add(P(t));let o=e.size!==n;if(t.kind==="textValue")return o;for(let r of t.children)Dr(r,e)||(o=false);return o}function Ha(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.listingParents(i),a=t.parentOf(i);for(let l of a===null?s:[a,...s]){r(l);let d=t.isTombstoned(l)?t.replacedByOf(l):null;d!==null&&r(d);}}return n}var jn="http://schemas.openxmlformats.org/package/2006/relationships",np="application/vnd.openxmlformats-package.relationships+xml",qa=/^(.*)\/_rels\/([^/]*)\.rels$/;function zn(t){return qa.test(t)}function Ga(t){let e=qa.exec(t);return e?e[2]===""?"/":`${e[1]}/${e[2]}`:null}function Fn(t,e){return Object.freeze({kind:"genericExtension",namespaceUri:"",localName:t,value:e})}function op(t,e){let n=[Fn("Id",e.id),Fn("Type",e.type),Fn("Target",e.rawTarget)];return e.targetMode==="External"&&n.push(Fn("TargetMode","External")),Object.freeze(ce({id:t,kind:"generic",namespaceUri:jn,localName:"Relationship",namespaceBindings:Object.freeze([]),attributes:Object.freeze(n),children:Object.freeze([])}))}function Za(t,e){if(t.kind==="textValue"||t.namespaceUri!==jn||t.localName!=="Relationship"||me(t,"Id")!==e.id||me(t,"Type")!==e.type||me(t,"Target")!==e.rawTarget)return false;let n=me(t,"TargetMode");return e.targetMode==="External"?n==="External":n===void 0}function Qa(t,e){return t.children.length!==e.length?false:t.children.every((n,o)=>Za(n,e[o]))}function el(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 tl(t,e,n){let o=[];for(let r of e){if(L(r.id))continue;let i=t.find(a=>a.kind!=="textValue"&&me(a,"Id")===r.id);if(i&&Za(i,r)){o.push(i);continue}let s=i&&i.kind!=="textValue"?P(i):`${n}#rel-${r.id}`;L(s)||o.push(op(s,r));}return o}function rp(t){return Object.freeze(ce({id:`${t}#root`,kind:"generic",namespaceUri:jn,localName:"Relationships",namespaceBindings:Object.freeze([Object.freeze({prefix:"",namespaceUri:jn})]),attributes:Object.freeze([]),children:Object.freeze([])}))}function nl(t){return Object.freeze({id:t,name:t,contentType:np,root:rp(t)})}function ol(t){let e=new Map;for(let n of t){if(L(n.id)||n.ownerPart!=="/"&&Z(n.ownerPart))continue;let o=e.get(n.ownerPart)??[];o.push(n),e.set(n.ownerPart,o);}return e}var al=/^\/customXml\/item(\d+)\.xml$/i,lp=/^\/customXml\/itemProps(\d+)\.xml$/i;function Kt(t){return al.test(t)}function _r(t){return lp.test(t)}function dp(t){let e=al.exec(t);if(!e)return null;let n=Number(e[1]);return Number.isSafeInteger(n)&&n>0?n:null}function rl(t){return {item:`/customXml/item${String(t)}.xml`,props:`/customXml/itemProps${String(t)}.xml`}}function cp(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 il(t,e){let n=t.record(e);return !n||!F(n)?e:n.attributes.find(r=>r.localName==="id"&&r.value.length>0)?.value??e}function up(t,e){let n=t.record(e);if(!n||!F(n))return null;for(let o of n.childIds){let r=t.record(o);if(!(!r||!F(r)||r.localName!=="schemaRefs")&&r.namespaceUri===DATASTORE_NAMESPACE_URI)for(let i of r.childIds){let s=t.record(i);if(!s||!F(s)||s.localName!=="schemaRef")continue;let a=cp(s,"uri",DATASTORE_NAMESPACE_URI);if(a)return a}}return null}function pp(t,e){return e.childIds.some(n=>{let o=t.record(n);return !!o&&F(o)&&o.localName==="node"&&o.namespaceUri===e.namespaceUri})}function fp(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:pp(t,e)}function hp(t,e){return e.localName!=="datastoreItem"||e.namespaceUri!==DATASTORE_NAMESPACE_URI?false:t.parentOf(e.logicalId)===null}function ll(t,e){if(!t.hasNamespace(DATASTORE_NAMESPACE_URI))return [];let n=new Map,o=new Map;for(let[p,f]of e){let h=t.record(P(f.root));!h||!F(h)||(Kt(p)&&n.set(h.logicalId,h),_r(p)&&o.set(h.logicalId,h));}for(let p of t.allLogicalIds()){if(t.isTombstoned(p)||n.has(p)||o.has(p))continue;let f=t.record(p);!f||!F(f)||(fp(t,f)?n.set(p,f):hp(t,f)&&o.set(p,f));}if(n.size===0)return [];let r=new Map;for(let p of n.values()){let f=r.get(p.namespaceUri)??[];f.push(p),r.set(p.namespaceUri,f);}let i=new Map;for(let p of o.values()){let f=up(t,p.logicalId);if(!f)continue;let h=i.get(f)??[];h.push(p),i.set(f,h);}let s=[];for(let[p,f]of r){let h=i.get(p);if(!h||h.length===0)continue;f.sort((m,w)=>m.logicalId.localeCompare(w.logicalId)),h.sort((m,w)=>m.logicalId.localeCompare(w.logicalId));let g=f[0],x=h[0],S=[],v=new Set;for(let m of f)for(let w of m.childIds){if(v.has(w))continue;let I=t.record(w);!I||!F(I)||I.localName!=="node"||I.namespaceUri!==p||(v.add(w),S.push(w));}for(let m of t.allLogicalIds()){if(v.has(m)||t.isTombstoned(m))continue;let w=t.record(m);!w||!F(w)||w.localName!=="node"||w.namespaceUri!==p||(v.add(m),S.push(m));}S.sort((m,w)=>il(t,m).localeCompare(il(t,w))),s.push({data:g,props:x,nodeIds:S});}s.sort((p,f)=>p.data.logicalId.localeCompare(f.data.logicalId));let a=new Set,l=[],d=new Set,c=new Set;for(let[p,f]of e){let h=dp(p);if(h===null)continue;let g=s.find(v=>v.data.logicalId===f.root.id&&!d.has(v.data.logicalId));if(!g)continue;let x=rl(h).props,S=e.get(x);S&&S.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:p,propsName:x,nodeIds:g.nodeIds}));}let u=1;for(let p of s){if(d.has(p.data.logicalId))continue;for(;a.has(u);)u+=1;a.add(u);let f=rl(u);l.push({dataRootId:p.data.logicalId,propsRootId:p.props.logicalId,namespaceUri:p.data.namespaceUri,itemName:f.item,propsName:f.props,nodeIds:p.nodeIds}),u+=1;}return l.sort((p,f)=>p.itemName.localeCompare(f.itemName)),l}function mp(t){return t.type===CUSTOM_XML_REL||t.type===CUSTOM_XML_PROPS_REL?true:Kt(t.ownerPart)}function gp(t){let e=/^rId(\d+)$/.exec(t);if(!e)return 0;let n=Number(e[1]);return Number.isSafeInteger(n)?n:0}function yp(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 dl(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,gp(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:yp(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 cl(t,e){return e.length===0?[...t]:[...t.filter(n=>!mp(n)),...e]}function ul(t){let e=new Map;for(let n of t)e.set(partNameKey(n.propsName),CUSTOM_XML_PROPS_TYPE);return e}function Br(t,e){if(e.length===0)return false;let n=[...t.keys()].filter(Kt).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 pl(t,e){if(Br(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 bp="http://schemas.microsoft.com/office/word/2012/wordml";function $n(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 fl(t){return e=>e.localName===t&&e.namespaceUri===WML_NAMESPACE_URI}function xp(t){return t.localName==="abstractNum"?`0${$n(me(t,"abstractNumId"))}`:`1${$n(me(t,"numId"))}`}function Ip(t){return t.namespaceUri!==WML_NAMESPACE_URI?false:t.localName==="abstractNum"||t.localName==="num"}function Ur(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===bp,sortKey:e=>e.id,adoptedAfterListed:true}:t.localName==="footnotes"&&t.namespaceUri===WML_NAMESPACE_URI?{isMember:fl("footnote"),sortKey:e=>$n(me(e,"id"))}:t.localName==="endnotes"&&t.namespaceUri===WML_NAMESPACE_URI?{isMember:fl("endnote"),sortKey:e=>$n(me(e,"id"))}:t.localName==="numbering"&&t.namespaceUri===WML_NAMESPACE_URI?{isMember:Ip,sortKey:xp}:null}function hl(t,e){for(let n of t)if(n.root.id===e)return Ur(n.root)?n.root.children.map(P):null;return null}function ml(t,e){let n=null;for(let o of t.listingParents(e)){let r=t.record(o);if(!(!r||!F(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 gl(t,e,n){let o=t.record(n),r=!!o&&(Ke(o)?o.value.length>0:o.childIds.length>0||o.attributes.length>0);e(r?"orphan-with-content":"orphan",n);}function yl(t,e,n,o,r,i){if(!r){for(let l of n)t.isTombstoned(l)||o.has(l)||(gl(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),Sp(t,e,l,o,s)&&i.add(l));}function Sp(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&&F(c))for(let u of c.childIds)a.push({id:u,underTombstone:true});continue}r.has(l)||(d?o.has(l):ml(t,l))||(gl(t,e,l),i=true);}}return i}function bl(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)||tn(t.schema.nodes.get(c))||s&&ml(t,c))continue;let u=t.record(c);if(!u||!F(u)||!r(u))continue;let p=e(c);!p||p.kind==="textValue"||(n.push(p),o.add(c),l.add(c),d+=1);}return d}var Ne="application/vnd.openxmlformats-officedocument.wordprocessingml",Lp=new Map(Object.entries({comments:{root:"comments",contentType:`${Ne}.comments+xml`},commentsExtended:{root:"commentsEx",contentType:`${Ne}.commentsExtended+xml`},commentsIds:{root:"commentsIds",contentType:`${Ne}.commentsIds+xml`},commentsExtensible:{root:"commentsExtensible",contentType:`${Ne}.commentsExtensible+xml`},people:{root:"people",contentType:`${Ne}.people+xml`},footnotes:{root:"footnotes",contentType:`${Ne}.footnotes+xml`},endnotes:{root:"endnotes",contentType:`${Ne}.endnotes+xml`},numbering:{root:"numbering",contentType:`${Ne}.numbering+xml`}}));function Rp(t){return Z(t)===null&&!zn(t)&&t.toLowerCase()!=="/[content_types].xml"&&t.toLowerCase().endsWith(".xml")}function xl(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=Lp.get(d.type.slice(d.type.lastIndexOf("/")+1));if(!c)continue;let u=resolveInternalTarget(d.ownerPart,d.rawTarget);!u.ok||o.has(u.partName)||!Rp(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||!F(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:p,empty:f}of a)p!==d.root||i.has(u)||(c===null||c.empty&&!f||c.empty===f&&u<c.id)&&(c={id:u,empty:f});c!==null&&(i.add(c.id),l.push({name:d.name,id:d.name,rootLogicalId:c.id,contentType:d.contentType}));}return l}function Il(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 Kn=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:cl(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:ol(n)}),this.grouped.map}relationshipAssembly(e){let n=this.projected(e);return (!this.assembly||this.assembly.records!==n)&&(this.assembly={records:n,value:Cp(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;Wa(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 Cp(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 Wn=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 Sl(t,e){let n=t.children;for(let i of n){let s=P(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=P(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 Vn=class{nodes=new Map;heights=new Map;complete=new Set;get(e){return this.nodes.get(e)}holds(e){return this.nodes.get(P(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=P(i);n.has(s)||this.evictSubtree(s,n,o);}}heightOf(e){let n=this.heights.get(P(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(P(e),o),o}setHeight(e,n){this.heights.set(e,n);}ids(){return [...this.nodes.keys()]}};function wl(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 Jn=class{constructor(e){this.registry=e;}registry;contested=false;matchesResolution=true;encountered=new Set;lastResolution=new Map;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));}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 Xn=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||!on(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 it=class{constructor(e,n){this.registry=e;this.blobs=n;this.packageCache=new Kn(e),this.contests=new Jn(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 Vn;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 Xn;mergeSources=new Map;builtMerges=new Map;contests;splitProjection=new Wn;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||!F(u)))for(let p of u.childIds)for(let f of this.registry.listingParents(p))e.add(f);}for(let c of this.splitProjection.update(this.registry))e.add(c);let r=Ha(this.registry,e);for(let c of e){let u=this.shownUnder.get(c);for(let p=0;u!==void 0&&p<this.registry.limits.maxTreeDepth;p++)r.add(u),u=this.shownUnder.get(u);}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:wl(l.issues)};let d=this.materializePass(r,n,false);return this.contests.record(this.lastDuplicateParents),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 p of this.lastDuplicateParents)this.push("duplicate-parent",p);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 p of [...s,...xl(this.registry,s,a)]){let f=new Set,h=this.materialize(p.rootLogicalId,r,f,o);if(!h||h.kind==="textValue")return {ok:false,code:"missing-root",issues:[...this.issues]};let g=this.partCache.get(p.name);if(g&&g.root===h&&g.contentType===p.contentType){i.set(p.name,g);continue}let x=Object.freeze({id:p.id||p.name,name:p.name,contentType:p.contentType,root:h});i.set(p.name,x),this.partCache.set(p.name,x);}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 p of [...this.partCache.keys()])i.has(p)||this.partCache.delete(p);for(let p of [...this.relsProjection.keys()])i.has(p)||this.relsProjection.delete(p);this.evictDeadSubtrees(r);for(let p of e)r.has(p)||this.cache.forget(p);yl(this.registry,this.pushIssue,d,r,o,c),this.looseCandidates=c,o||(this.lastDuplicateParents=this.issues.flatMap(p=>p.code==="duplicate-parent"&&p.logicalId!==void 0?[p.logicalId]:[]));let u=this.assemblePackage(i);return u.ok?this.pkg&&!n&&this.pkg.parts.size===i.size&&[...i].every(([p,f])=>this.pkg?.parts.get(p)===f)?{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?Dr(y,n)||(this.contests.contested=true):n.add(P(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(Ke(a)){if(this.splitProjection.awaiting.has(e))return null;let y=this.splitProjection.textValue(e,a.value),R=this.cache.get(e);if(R?.kind==="textValue"&&R.value===y)return R;let E=Ja(e,y);return this.cache.remember(e,E),E}o.add(e);let l=this.issues.length,d=new Set,c=[...a.childIds],u=new Set(c),p=y=>{u.has(y)||(u.add(y),c.push(y));};for(let y of this.registry.adoptedChildren(e))p(y);for(let y of this.mergeSources.get(e)??[]){let R=this.registry.record(y);if(!(!R||!F(R)))for(let E of R.childIds)p(E);}i?this.builtMerges.set(e,i):this.builtMerges.delete(e);let f=this.splitProjection.losers,h=f.size===0?null:En(c,y=>f.has(y),y=>this.registry.splitLineageOf(y));h&&(c=h.map(y=>c[y]));let g=[],x=ts(a.kind,c,y=>this.splitProjection.losers.has(y)?null:yt(this.registry,y));for(let y of x.hidden)n.add(y);for(let y of c)this.mergeSources.delete(y);for(let[y,R]of x.merges??[]){this.mergeSources.set(y,R);for(let E of R)this.shownUnder.set(E,y);}for(let y of x.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(L(y)||!this.registry.hasNode(y)){(L(y)||bi(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 R=this.materialize(y,n,o,r);R&&(g.push(R),this.shownUnder.set(P(R),e));}let S=x.hidden.length===0&&g.length===x.shown.length&&this.issues.length===l,v=this.registry.inline.textOf(e);if(v){let y=U=>{if(!this.registry.hasNode(U)&&xe(this.registry.doc)||this.registry.listingParents(U).length>0||this.partRoots.has(U))return null;let j=this.materialize(U,n,o,r);return j&&this.shownUnder.set(U,e),j},R=this.registry.inline.viewOf(e),E=ke(e,v,y,this.registry.limits,R),_=this.cache.get(e);g.push(...Wi(_?.kind==="textValue"?[]:_?.children??[],E));}o.delete(e);let m=this.cache.get(e);if(m&&m.kind!=="textValue"&&m.children.length===g.length&&m.children.every((y,R)=>y===g[R])&&Xa(m,a))return this.cache.markComplete(e,S),m;let w=m&&m.kind!=="textValue"?m.children:[];this.recordDroppedChildren(w,g);let I=Un(a,zt(w,g),m);return this.cache.remember(e,I),this.cache.markComplete(e,S),I}rebuildSpine(e,n,o){let r=this.cache.get(e);if(!r||r.kind==="textValue"||this.rawDirty.has(e)||!this.cache.isComplete(e)||zo(r.kind)||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=Sl(r,{dirty:this.lastDirty,placed:n,isCached:u=>this.cache.holds(u),canRebuild:u=>L(u)||this.registry.isTombstoned(u)||!this.registry.hasNode(u)?false:(this.contests.note(u,e,n,this.partRoots),true),rebuild:u=>{let p=this.materialize(u,n,o,true);return p&&this.shownUnder.set(P(p),e),p}});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(ve(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(P(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(P(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"&&Z(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)||!zn(r))continue;let s=Ga(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||el(r.root,n.root))&&r?r:n??nl(e);if(Qa(s.root,o))return this.relsProjection.set(e,s),s;let a=s.root.children,l=za(s,tl(a,o,e));return this.relsProjection.set(e,l),l}builtNode(e){return this.cache.get(e)??null}shownPartChildren(e){return hl(this.partCache.values(),e)}adoptOrphanPartMembers(e,n,o,r,i){for(let[s,a]of e){let l=Ur(a.root);if(!l)continue;let d=y=>y.logicalId!==a.root.id&&l.isMember(y),c=[],u=new Set,p=new Set,f=this.registry.record(P(a.root)),h=new Set(f&&F(f)?f.childIds:[]);for(let y of a.root.children){if(y.kind==="textValue")continue;let R=P(y);if(this.registry.isTombstoned(R)||!h.has(R)&&(tn(this.registry.schema.nodes.get(R))||this.registry.listingParents(R).length>0)){p.add(R);continue}let E=this.registry.record(P(y));!E||!F(E)||!d(E)||(c.push(y),u.add(P(y)));}let g=bl(this.registry,y=>this.materialize(y,n,new Set,o),c,u,d,n,o,r,i);if(g===0&&p.size===0)continue;let x=(y,R)=>l.sortKey(y).localeCompare(l.sortKey(R));if(l.adoptedAfterListed){let y=c.length-g;c.splice(y,g,...c.slice(y).sort(x));}else c.sort(x);let S=[];for(let y of a.root.children)u.has(P(y))||p.has(P(y))||S.push(y);let v=zt(a.root.children,[...S,...c]);if(v===a.root.children)continue;let m=this.registry.record(P(a.root));if(!m||!F(m))continue;let w=Un(m,v,a.root);this.cache.remember(P(a.root),w);let I=Object.freeze({...a,root:w});e.set(s,I),this.partCache.set(s,I);}}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(f=>f.id)),d=0;for(let f of n){if(l.has(f))continue;let h=this.materializeOnce(f,o,r);!h||h.kind==="textValue"||(a.push(h),l.add(f),d+=1);}if(a.sort((f,h)=>Mr(f).localeCompare(Mr(h))),d===0&&a.every((f,h)=>f===s.children[h]))return s;let c=this.registry.record(e);if(!c||!F(c))return s;let u=zt(s.children,a),p=Un(c,u,s);return this.cache.remember(e,p),p}applyCustomXmlStores(e,n,o){let r=ll(this.registry,e);if(r.length===0||!pl(e,r))return;let i=Br(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()])!Kt(a)&&!_r(a)||s.has(a)||(e.delete(a),this.partCache.delete(a));this.customXmlRels=dl(this.registry,r),this.customXmlOverrides=ul(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};Il(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 vl(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=Ba(e.effects,_a(t));return n===null?null:n.ok?n:{ok:false,failure:Object.freeze(n.failure)}}function kl(t,e){try{Ua(t,e);}catch(n){return n instanceof T?Object.freeze({code:n.code,...n.detail?{detail:n.detail}:{}}):Object.freeze({code:"blob-store-full"})}return null}function Fr(t){let{status:e,reason:n}=t;return e!=="ready"&&e!=="disconnected"?null:{status:e,...n?{code:n.code,detail:n.detail}:{}}}var Np=3,Ap=20,Hn=class{refused=0;transient=0;published(){this.refused=0,this.transient=0;}refusedOne(e){(!e||++this.transient>Ap)&&(this.refused+=1);}recoverable(){return this.refused<Np}};var jr="docxEditorSelectionBefore",qn=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(jr)||e.stackItem.meta.set(jr,this.before);};onPopped=e=>{let n=e.stackItem.meta.get(jr);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);}};function Ll(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 kt="docxEditor",Ae=256,Gn=256,Rl=/^\d{1,16}:\d{1,16}$/;function El(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:Zn(l)}:{},...c?{character:c}:{}}};return {encoded:{anchor:r(t.anchor),head:r(t.head),...t.kind==="cells"?{kind:"cells"}:{}},texts:o}}function Yp(t){if(typeof t!="object"||t===null||Array.isArray(t))return null;let e=t;if(typeof e.item!="string"||!Rl.test(e.item)||typeof e.after!="boolean")return null;let n=typeof e.identity=="string"&&Rl.test(e.identity)?e.identity:void 0;return {item:e.item,...n?{identity:n}:{},after:e.after}}function Zn(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 _p=/^[0-9a-f]{8}$/;function Cl(t){let e=t.actorId.trim(),n=t.name.trim();if(e.length===0||e.length>Ae||n.length===0||n.length>Ae)throw new T("invalid-identity");if(t.color!==void 0&&t.color.length>64)throw new T("invalid-identity-color");return Object.freeze({actorId:e,name:n,...t.color?{color:t.color}:{},role:t.role??"human"})}function Tl(t){let e=t.trim();if(e.length===0||e.length>Ae)throw new T("invalid-document-id");return e}function Pl(t){let e=t?.trim()||globalThis.crypto.randomUUID();if(e.length>Ae)throw new T("invalid-session-id");return e}function Ol(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=Yp(e.character);return {paragraphId:e.paragraphId.toUpperCase(),offset:e.offset,...typeof e.digest=="string"&&_p.test(e.digest)?{digest:e.digest}:{},...n?{character:n}:{}}}function Bp(t){if(t===void 0||typeof t!="object"||t===null||Array.isArray(t))return;let e=t,n=Ol(e.anchor),o=Ol(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 Qn(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>Ae||typeof e.name!="string"||e.name.length===0||e.name.length>Ae)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=Bp(e.selection);return i?{...r,selection:i}:r}var Fp=16,jp=32,eo=class{baselines=new Map;resolve(e,n,o){let r=[...e.getStates().entries()].slice(0,Gn),i=[],s=new Set,a=new Set,l=0,d;for(let[c,u]of r){if(c===e.clientID)continue;let p=Qn(u[kt]);if(!p?.selection)continue;s.add(c);let{anchor:f,head:h}=p.selection,g=`${f.paragraphId}:${f.offset}:${f.digest??""}|${h.paragraphId}:${h.offset}:${h.digest??""}`,x=this.baselines.get(c);x?.key!==g&&(x={key:g,texts:new Map,resolved:new Map,missing:new Map},this.baselines.set(c,x));let{texts:S,resolved:v,missing:m}=x,w=R=>{let E=false,_=()=>{if(!R.character||!o)return null;if(l>=jp)return E=true,null;l+=1;let k=o(R.paragraphId,R.character),O=k?n.paragraphByNodeId(k.nodeId):null;if(!k||!O)return null;let C={paragraphId:O.paragraphId,nodeId:O.nodeId,offset:k.offset};return {address:Object.freeze(C),text:O.text}},U=n.paragraphByStableId(R.paragraphId);if(!U){let k=R.paragraphId+":"+R.offset;d??=n.revision();let O=m.get(k);if(O?.revision===d)return O.address;let C=_()?.address??null;return E||m.set(k,{revision:d,address:C}),C}let j=v.get(R.paragraphId+":"+R.offset);if(j?.text===U.text&&j.address.nodeId===U.nodeId&&(j.target===void 0||n.paragraphByNodeId(j.address.nodeId)?.text===j.target))return j.address;let X=_();if(X)return v.set(R.paragraphId+":"+R.offset,{text:U.text,address:X.address,target:X.text}),X.address;let J=S.get(R.paragraphId);if(J===void 0){if(R.digest!==void 0&&Zn(U.text)!==R.digest)return Object.freeze({paragraphId:U.paragraphId,nodeId:U.nodeId,offset:Math.min(R.offset,U.text.length)});J=U.text,S.set(R.paragraphId,J);}let D=J===U.text?"":`${R.paragraphId}:${J.length}:${Zn(J)}`,K=D===""||a.has(D)||a.size<Fp;K&&D!==""&&a.add(D);let b=Object.freeze({paragraphId:U.paragraphId,nodeId:U.nodeId,offset:K?mapOffsetAcrossText(R.offset,J,U.text):Math.min(R.offset,U.text.length)});return v.set(R.paragraphId+":"+R.offset,{text:U.text,address:b}),b},I=w(f),y=w(h);!I||!y||i.push(Object.freeze({actorId:p.actorId,name:p.name,...p.color?{color:p.color}:{},...p.selection.kind==="cells"?{kind:"cells"}:{},anchor:I,head:y}));}for(let c of this.baselines.keys())s.has(c)||this.baselines.delete(c);return Object.freeze(i)}};var no=64*1024*1024,Lt="docx-package-blobs-v1";function $p(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 Kp(t){return t instanceof ArrayBuffer||ArrayBuffer.isView(t)?t.byteLength:0}function to(t,e){return Object.freeze(e===void 0?{code:t}:{code:t,detail:e})}var Me=class{constructor(e){this.shared=e;}shared;verified=new WeakSet;poisoned=new Set;get(e){let n=this.shared.get(e),o=$p(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+=Kp(n);}),e}put(e,n){if(!this.shared.has(e)){if(this.totalByteLength()+n.byteLength>no)throw new T("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)}};function oo(t,e){let{limits:n}=t,o=t.nodeCount();if(o>n.maxNodes)return to("too-many-nodes",`${o}`);let r=t.schema.parts.size;if(r>n.maxParts)return to("too-many-parts",`${r}`);let i=0;if(t.schema.relationships.forEach(a=>{i+=a instanceof B.Map?a.size:0;}),i>n.maxRelationships)return to("too-many-relationships",`${i}`);let s=e.totalByteLength();return s>no?to("blob-store-full",`${s}`):null}var Ml=20*1024*1024,_l=3e4,qp=4e3,Gp=1500,Zp="docx-collaboration-seeds-v1",zr="docxEditorSeedCandidate",Qp=/^[0-9a-f]{16}$/,ef=256;function Bl(t){if(!(t instanceof Uint8Array)||t.byteLength===0)throw new T("invalid-baseline");if(t.byteLength>Ml)throw new T("baseline-too-large");let e=readOoxmlPackage(t,{zip:{maxEntries:1e4,maxTotalBytes:Ml,maxRatio:200}});if(!e.ok)throw new T("invalid-baseline");let n=e.package.parts.get(e.package.mainDocumentPart);if(!n)throw new T("no-main-document-part");let o=e.package;for(let i of o.parts.values()){if(i.root.namespaceUri!==WML_NAMESPACE_URI||!["document","hdr","ftr"].includes(i.root.localName)||!isStoryPart(i))continue;let s=normalizeParagraphIdentity(i);s!==i&&(o=withPart(o,s));}return new TreePackageStore(o,normalizeParagraphIdentity(o.parts.get(n.name))).currentPackage()}function tf(t,e){for(let n of t.binaries())if(!e.has(n.digest))return false;return true}function ro(t,e,n,o){let r=t.schema.meta,i=()=>r.get("initialized")===true&&tf(t,e),s=()=>{let l=e.poisonedDigest();return l?new T("blob-digest-mismatch",l):null};if(i())return Promise.resolve();let a=s();return a?Promise.reject(a):o?.aborted?Promise.reject(new T("initialization-aborted")):new Promise((l,d)=>{let c=h=>{clearTimeout(f),r.unobserve(u),t.doc.off("afterTransaction",u),o?.removeEventListener("abort",p),h?d(h):l();},u=()=>{let h=s();if(h){c(h);return}i()&&c();},p=()=>c(new T("initialization-aborted")),f=setTimeout(()=>c(new T("initialization-timeout")),n);r.observe(u),t.doc.on("afterTransaction",u),o?.addEventListener("abort",p,{once:true});})}function so(t){return t.getArray(Zp)}function nf(t){so(t).push([jl()]);}var of="freshBytes";function Ul(t){let e=B.encodeStateAsUpdate(t).byteLength;t.getMap(bo).set(of,e);}function rf(t){return so(t).length}function Fl(t,e){let n=so(t),o=()=>{n.length>1&&e();};return o(),n.observe(o),()=>n.unobserve(o)}function jl(){let t=new Uint8Array(8);return globalThis.crypto.getRandomValues(t),[...t].map(e=>e.toString(16).padStart(2,"0")).join("")}function sf(t,e){let n=[...t.getStates().entries()].slice(0,ef);for(let[o,r]of n){if(o===t.clientID)continue;let i=r[zr];if(!(typeof i!="string"||!Qp.test(i))&&i<e)return true}return false}async function Dl(t,e,n,o){try{return await ro(t,e,n,o),!0}catch(r){if(r instanceof T&&r.code==="initialization-timeout")return false;throw r}}function af(t,e,n){let o=t.schema.meta,r=()=>o.get("documentId")!==void 0;return r()?Promise.resolve():n?.aborted?Promise.reject(new T("initialization-aborted")):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 T("initialization-aborted")),c=setTimeout(()=>a(new T("initialization-timeout")),e);o.observe(l),n?.addEventListener("abort",d,{once:true});})}async function lf(t){let{ydoc:e,awareness:n,registry:o,blobs:r}=t,i=t.probeTimeoutMs??qp,s=t.electionWindowMs??Gp,a=t.timeoutMs??_l,l=async()=>(await af(o,a,t.signal),"joined");if(await Dl(o,r,i,t.signal))return l();let d=jl();n.setLocalStateField(zr,d);try{let c=await Dl(o,r,s,t.signal);if(!c&&sf(n,d)&&(await ro(o,r,a,t.signal),c=!0),c)return await l();if(o.schema.meta.get("initialized")===!0)return await ro(o,r,a,t.signal),await l();let u=await Bn(o,Bl(t.document),r);if(!u.ok)throw new T(u.code);return e.transact(()=>{o.schema.meta.set("documentId",t.documentId),so(e).push([d]);}),Ul(e),"seeded"}finally{n.setLocalStateField(zr,null);}}function io(t,e,n){let o=en(t.schema.meta);if(o)throw new T(o.code,o.detail);t.rebuildDerivedIndexes(),$r(t,e,n);}function $r(t,e,n){if(rf(n)>1)throw new T("concurrent-seed");let o=oo(t,e);if(o)throw new T(o.code,o.detail)}async function zl(t,e,n,o){if(t.bootstrap.kind==="create"){if(e.schema.meta.get("initialized")===true)throw new T("already-initialized");let r=await Bn(e,Bl(t.bootstrap.document),n);if(!r.ok)throw new T(r.code);t.ydoc.transact(()=>{e.schema.meta.set("documentId",o),nf(t.ydoc);}),Ul(t.ydoc),$r(e,n,t.ydoc);}else if(t.bootstrap.kind==="create-or-join")if(await lf({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 T("document-id-mismatch");io(e,n,t.ydoc);}else $r(e,n,t.ydoc);else {if(await ro(e,n,t.bootstrap.timeoutMs??_l,t.bootstrap.signal),e.schema.meta.get("documentId")!==o)throw new T("document-id-mismatch");io(e,n,t.ydoc);}}var ao=class{constructor(e,n){this.knows=e;this.allocator=new Et(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)}}};function Kr(t,e,n,o){let r=t.inline.textOf(e);if(!r)return null;let i=[],s=new Set,a=ke(e,r,x=>{if(s.has(x))return null;let S=n(x);return S&&s.add(S.id),S},t.limits,{...t.inline.viewOf(e),noteDrift:()=>{}},x=>i.push(x)),l={id:e,kind:"paragraph",namespaceUri:WML_NAMESPACE_URI,localName:"p",prefix:"w",namespaceBindings:[],attributes:[],children:a},d=new Map,c=0,u=x=>{if(!s.has(x.id)){if(x.kind==="textValue"){d.set(x.id,c),c+=x.value.length;return}for(let S of x.children)u(S);}};for(let x of a)u(x);if(c!==i.length)return null;let p=segmentsOf(l),f=p.length>0?p[p.length-1].end:0;if(f!==o.length)return null;let h=new Int32Array(f).fill(-1),g=new Int32Array(i.length).fill(-1);for(let x of p){if(x.node.kind!=="textValue"||x.removeNodeIds)continue;let S=d.get(x.node.id),v=x.node.value;if(S===void 0||o.slice(x.start,x.end)!==v)return null;for(let m=0;m<x.end-x.start;m+=1)h[x.start+m]=S+m,g[S+m]=x.start+m;}return {length:f,characters:i,characterAt:h,offsetOf:g}}function $l(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 Kl(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 lo=class{constructor(e){this.deps=e;}deps;selection=null;anchored=null;stale=true;carried=null;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&&uf(s,this.selection)||(this.selection=s,this.stale=true,this.anchored=null,this.carried=null);}localChange(){this.stale=true,this.anchored=null,this.carried=null;}beforeChange(){if(!this.stale)return;this.stale=false,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});}afterPublish(){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.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=Kr(this.deps.registry,n,this.deps.embedOf,o),i=r?$l(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);for(let a of i){if(n.inline.isDeletedParagraph(a))continue;let l=this.shownText(a);if(l===null)continue;let d=Kr(n,a,this.deps.embedOf,l),c=d?Kl(d,e.anchor):null;if(c!==null)return {nodeId:a,offset:c}}return null}shownText(e){return this.deps.port()?.paragraphTextOf?.(e)??null}};function uf(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 co=class{constructor(e){this.deps=e;}deps;waiting=false;refuses(e){return this.deps.viewWaiting()?this.set(true):xe(this.deps.ydoc)?this.set(e.some(n=>pf.has(n.op)||ff(n).some(o=>this.deps.nodeWaits(o)))):this.set(false)}refresh(){this.waiting&&!this.deps.viewWaiting()&&!xe(this.deps.ydoc)&&this.set(false);}set(e){return e!==this.waiting&&(this.waiting=e,this.deps.publish(e)),e}},pf=new Set(["acceptAllRevisions","rejectAllRevisions","replaceStoryBlocks","convertAllNotes"]);function ff(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 hf(t){let e=0;return t.schema.nodes.forEach(n=>{N(n)&&n.get(Ie)===true&&(e+=1);}),e}function mf(t){let e=0;return t.schema.nodes.forEach(n=>{let o=N(n)?n.get(ne):null;if(o instanceof B.Text)for(let r=o._start;r;r=r.right)!r.deleted&&r.content instanceof B.ContentFormat&&(e+=1);}),e}function gf(t){let e=0;return t.schema.relationships.forEach(n=>{e+=n instanceof B.Map?n.size:0;}),e}function Wr(t,e){return Object.freeze({nodes:t.nodeCount(),tombstonedNodes:hf(t),maxNodes:t.limits.maxNodes,relationships:gf(t),maxRelationships:t.limits.maxRelationships,parts:t.schema.parts.size,maxParts:t.limits.maxParts,blobBytes:e.totalByteLength(),maxBlobBytes:no,formattingMarkers:mf(t)})}function Kx(t){let e=new Oe(t);try{let n=new Me(t.getMap(Lt));return Wr(e,n)}finally{e.destroy();}}function bf(t){let e=new Oe(t),n=null;try{if(e.schema.meta.get("initialized")!==!0||typeof e.schema.meta.get("documentId")!="string")throw new T("not-initialized");let o=new Me(t.getMap(Lt));io(e,o,t),n=new it(e,o);let r=n.current(),i=o.poisonedDigest();if(i)throw new T("blob-digest-mismatch",i);if(!r.ok)throw new T(r.code);let s=Pt(r.issues);if(s)throw new T("materialize-dropped-content",s);if(!r.package.parts.has(r.package.mainDocumentPart))throw new T("no-main-document-part");return writeOoxmlPackage(r.package)}finally{n?.destroy(),e.destroy();}}var kf=500,Lf=2e3,Rf=Symbol("createDocumentCollaboration.attachWatchdogMs"),Vr=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 B.UndoManager([...s.trackedTypes()],{trackedOrigins:new Set([this.localOrigin]),captureTimeout:kf,deleteFilter:s.undoDeleteFilter()}),this.historyGroups=new Tn(this.undoManager,this),this.historySelections=new qn(this.undoManager,p=>this.port?.paragraphByStableId(p)?.text??null,(p,f)=>this.caretAnchors.findStable(p,f)),this.editWait=new co({ydoc:e,viewWaiting:()=>this.viewWaiting,nodeWaits:p=>Gs(s,this.identityMap.resolve(p)),publish:p=>this.statusState.setWaiting(p)&&this.notifyStatus()}),this.caretAnchors=new lo({registry:s,port:()=>this.port,logicalIdOf:p=>this.identityMap.resolve(p),embedOf:p=>a.builtNode(p),viewIsCurrent:()=>!this.viewWaiting}),e.on("beforeTransaction",this.onBeforeYjsTransaction),e.on("afterTransaction",this.onYjsTransaction),n.on("change",this.onAwarenessChange),this.stopBlobWatch=d.observeChanges(p=>{let f=d.verifyNow(p);f&&this.setStatus("error","blob-digest-mismatch",f);}),this.publishAwareness(),this.setStatus("ready"),this.stopSeedWatch=Fl(e,()=>{this.setStatus("error","concurrent-seed");}),this.attachWatchdog=Ll(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;healTo=null;historySelections;remoteSelectionResolver=new eo;realignedInBatch=false;journalsHeldDuringRemote=[];drainingHeldJournals=false;remoteCounter=0;destroyed=false;refusals=new Hn;historyGroups;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 Wr(this.registry,this.blobs)}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(),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=en(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.canWriteSharedState()&&((this.port?.hasPendingJournals()??false)||this.undoManager.undoStack.length>0)}canRedo(){return this.canWriteSharedState()&&this.undoManager.redoStack.length>0}undo(){return this.popHistory("undo")}historySelection(){return this.historySelections.lastRestored()}redo(){return this.popHistory("redo")}popHistory(e){if(!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=B.getState(this.ydoc.store,this.ydoc.clientID);return this.registry.takeUnlisted(),ca(this.registry,this.undoManager,e,()=>{this.registry.normalizeRestoredSplitTextAnchors(),ia(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}=El(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,Gn);for(let[o,r]of n){let i=Qn(r[kt]);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>Ae)throw new T("invalid-identity");let o=this.currentIdentity.color;if(e.color!==void 0){if(e.color.length>64)throw new T("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.detachPort?.(),this.destroyed=true,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(kt,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;this.registry.inline.takeDrift();let n=ra(this.registry,this.identityMap.translate(e),a=>this.materializer.shownPartChildren(a));if(!n.ok){this.refuseLocalJournal({code:n.code,...n.detail?{detail:n.detail}:{}});return}let o=n.journal,r=vl(this.port,e);if(r!==null&&r.ok===false){this.refuseLocalJournal(r.failure);return}if(!this.canWriteSharedState())return;let i=false;this.historySelections.noteBefore();let s=this.historyGroups.capture(historyGroupOfJournal(e),()=>this.ydoc.transact(()=>{if(r!==null){let l=kl(this.blobs,r.payloads);if(l!==null)return l}let a=gr(this.registry,o,n.plan,n.typed);return a.ok?null:(i=a.transient===true,{code:a.code,...a.detail?{detail:a.detail}:{}})},this.localOrigin));if(s===null){this.refusals.published(),(this.registry.inline.takeDrift()||e.effects.some(l=>l.kind!=="spliceText")&&sa(this.registry,n.plan))&&this.publishSharedToPort();return}this.refuseLocalJournal(s,i);}refuseLocalJournal(e,n=false){this.historyGroups.reset(),this.undoManager.stopCapturing();let o=this.statusState.snapshot();this.refusals.refusedOne(n);let r=this.refusals.recoverable()?Fr(o):null;this.setStatus("error",e.code,e.detail,r),this.publishSharedToPort(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.port||e.origin!==this.localOrigin&&this.publishSharedToPort();};publishSharedToPort(e=false){let n=this.port;if(!(!n||this.applyingRemote)){this.applyingRemote=true;try{if(!this.hasCompatibleSharedSchema())return;let o=oo(this.registry,this.blobs);if(o){this.setStatus("error",o.code,o.detail);return}let r=xe(this.ydoc),i=e?this.materializer.rebuildFull():this.materializer.current(),s=this.blobs.poisonedDigest();if(s){this.setStatus("error","blob-digest-mismatch",s);return}if(this.viewWaiting=!1,!i.ok){r?this.viewWaiting=!0:this.degrade(i.code);return}let a=Pt(i.issues);if(a){r?this.viewWaiting=!0:this.degrade("materialize-dropped-content",a);return}let l=u=>(this.remoteCounter+=1,n.applyRemotePackage(u,{origin:ORIGIN_IDS.mutationRemote,actorId:"remote",operationId:`${this.sessionId}:remote:${this.remoteCounter}`})),d=l(i.package);if(!d.ok){let u=this.materializer.rebuildFull();u.ok&&!Pt(u.issues)&&(d=l(u.package));}if(!d.ok){r?this.viewWaiting=!0:this.degrade("remote-apply-failed",d.reason);return}d.changed&&this.identityMap.reset(),this.caretAnchors.afterPublish();let c=this.healTo;c!==null&&this.setStatus(c.status,c.code,c.detail);}catch(o){this.degrade(o instanceof T?o.code:"remote-apply-failed",o instanceof T?o.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(kt,n);}degrade(e,n){this.setStatus("error",e,n,this.healTo??Fr(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 kI(t){let e=t[Rf]??Lf,n=Tl(t.documentId),o=Pl(t.sessionId),r=Cl(t.identity),i=new Oe(t.ydoc);try{return await Of(t,{attachWatchdogMs:e,documentId:n,sessionId:o,identity:r,registry:i})}catch(s){throw i.destroy(),s}}async function Of(t,e){let{attachWatchdogMs:n,documentId:o,sessionId:r,identity:i,registry:s}=e,a=new ao(c=>s.hasNode(c)||s.inline.owner(c)!==null),l=new Me(t.ydoc.getMap(Lt));await zl(t,s,l,o);let d=new it(s,l);try{let c=d.current(),u=l.poisonedDigest();if(u)throw new T("blob-digest-mismatch",u);if(!c.ok)throw new T(c.code);let p=writeOoxmlPackage(c.package),f=new Vr(t.ydoc,t.awareness,o,r,i,s,d,a,l,n,t.offlineEditing!==!1);return Object.freeze({document:p,session:f,destroy:()=>f.destroy()})}catch(c){throw d.destroy(),c}}
|
|
5
|
+
export{Xr as a,T as b,Fe as c,Df as d,bo as e,Oe as f,Bn as g,Tl as h,Lt as i,Me as j,Bl as k,nf as l,Ul as m,Kx as n,bf as o,Rf as p,kI as q};
|