@docx-editor.dev/pro 2.31.0 → 2.33.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/README.md +41 -3
- package/dist/chunk-25A5N6OL.js +1 -0
- package/dist/chunk-3HW2VWFW.js +1 -0
- package/dist/chunk-3MIZFGHH.cjs +1 -0
- package/dist/chunk-46N5DWZV.cjs +1 -0
- package/dist/chunk-65JEI6FY.cjs +5 -0
- package/dist/chunk-ENMURXLJ.js +1 -0
- package/dist/chunk-EOZ44UA7.js +1 -0
- package/dist/chunk-GLYQ72LS.cjs +6 -0
- package/dist/{chunk-RYF4SNKX.cjs → chunk-GOUTDQFX.cjs} +1 -1
- package/dist/chunk-HMU7J34H.js +1 -0
- package/dist/chunk-IULA3QRZ.cjs +1 -0
- package/dist/chunk-QEULTKCT.cjs +1 -0
- package/dist/{chunk-OT5R3IYV.cjs → chunk-QOXYHVBM.cjs} +1 -1
- package/dist/chunk-SINNHH3H.js +1 -0
- package/dist/chunk-SL6K2CUL.js +6 -0
- package/dist/chunk-STTJA26X.js +1 -0
- package/dist/chunk-VY7374QP.cjs +1 -0
- package/dist/chunk-WGBOER6G.js +1 -0
- package/dist/chunk-WX43PF3Z.cjs +1 -0
- package/dist/chunk-WYVEFRAM.js +5 -0
- package/dist/collaboration/hocuspocus.cjs +1 -1
- package/dist/collaboration/hocuspocus.d.cts +3 -3
- package/dist/collaboration/hocuspocus.d.ts +3 -3
- package/dist/collaboration/hocuspocus.js +1 -1
- package/dist/collaboration/index.cjs +2 -2
- package/dist/collaboration/index.d.cts +65 -8
- package/dist/collaboration/index.d.ts +65 -8
- package/dist/collaboration/index.js +2 -2
- package/dist/collaboration/webrtc.cjs +1 -1
- package/dist/collaboration/webrtc.d.cts +3 -3
- package/dist/collaboration/webrtc.d.ts +3 -3
- package/dist/collaboration/webrtc.js +1 -1
- package/dist/{collaboration-module-DWn2heE1.d.cts → collaboration-module-02CIP5sN.d.cts} +2 -20
- package/dist/{collaboration-module-DWn2heE1.d.ts → collaboration-module-COZAgqwg.d.ts} +2 -20
- package/dist/{define-custom-node-D0c36PpZ.d.ts → define-custom-node-CISpZvVB.d.cts} +8 -3
- package/dist/{define-custom-node-CNRQG1TI.d.cts → define-custom-node-DE1KjR1r.d.ts} +8 -3
- package/dist/document-session-4NUOLWKQ.cjs +1 -0
- package/dist/document-session-5VAD24RH.js +1 -0
- package/dist/{document-session-_v9vqiSX.d.cts → document-session-B-MlORjE.d.cts} +105 -9
- package/dist/{document-session-Bxs4_GgX.d.ts → document-session-B-iH-YCU.d.ts} +105 -9
- package/dist/{document-session-options-DelOC7PX.d.ts → document-session-options-CdOH-TNn.d.ts} +1 -1
- package/dist/{document-session-options-CfKypp9c.d.cts → document-session-options-CxR0F5xT.d.cts} +1 -1
- package/dist/drawing/index.cjs +1 -0
- package/dist/drawing/index.d.cts +112 -0
- package/dist/drawing/index.d.ts +112 -0
- package/dist/drawing/index.js +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +1 -1
- package/dist/license-D-ds5Y7c.d.cts +20 -0
- package/dist/license-D-ds5Y7c.d.ts +20 -0
- package/dist/metafile-raster-3MCAHWYO.js +1 -0
- package/dist/metafile-raster-DWGCWQTU.cjs +1 -0
- package/dist/metafile-replay-GHPEUR2W.js +1 -0
- package/dist/metafile-replay-NZWGGGZR.cjs +1 -0
- package/dist/react/hocuspocus.cjs +1 -1
- package/dist/react/hocuspocus.d.cts +2 -2
- package/dist/react/hocuspocus.d.ts +2 -2
- package/dist/react/hocuspocus.js +1 -1
- package/dist/react/index.cjs +2 -2
- package/dist/react/index.d.cts +176 -34
- package/dist/react/index.d.ts +176 -34
- package/dist/react/index.js +2 -2
- package/dist/react/webrtc.cjs +1 -1
- package/dist/react/webrtc.d.cts +2 -2
- package/dist/react/webrtc.d.ts +2 -2
- package/dist/react/webrtc.js +1 -1
- package/dist/{types-BQ1vBt5Q.d.ts → types-DvGpDOcZ.d.cts} +9 -1
- package/dist/{types-BQ1vBt5Q.d.cts → types-DvGpDOcZ.d.ts} +9 -1
- package/dist/{types-6EmrEn4n.d.cts → types-bt2k1VO0.d.cts} +9 -1
- package/dist/{types-6EmrEn4n.d.ts → types-bt2k1VO0.d.ts} +9 -1
- package/dist/vue/hocuspocus.cjs +1 -1
- package/dist/vue/hocuspocus.d.cts +2 -2
- package/dist/vue/hocuspocus.d.ts +2 -2
- package/dist/vue/hocuspocus.js +1 -1
- package/dist/vue/index.cjs +2 -2
- package/dist/vue/index.d.cts +149 -30
- package/dist/vue/index.d.ts +149 -30
- package/dist/vue/index.js +2 -2
- package/dist/vue/webrtc.cjs +1 -1
- package/dist/vue/webrtc.d.cts +2 -2
- package/dist/vue/webrtc.d.ts +2 -2
- package/dist/vue/webrtc.js +1 -1
- package/docs/accept-reject-without-scrolling.md +95 -0
- package/docs/comment-on-found-text.md +72 -0
- package/docs/custom-review-cards.md +178 -0
- package/docs/highlight-ranges.md +48 -0
- package/docs/index.md +36 -0
- package/docs/propose-rewrite.md +247 -0
- package/docs/tracked-replacement.md +68 -0
- package/package.json +12 -5
- package/dist/chunk-32WEH2XH.cjs +0 -1
- package/dist/chunk-DLYVBBO7.js +0 -1
- package/dist/chunk-FD2KDBHX.cjs +0 -1
- package/dist/chunk-L567WP3J.js +0 -5
- package/dist/chunk-MJECUVHQ.cjs +0 -5
- package/dist/chunk-MWO2ZUEJ.js +0 -1
- package/dist/chunk-Q2VBO66F.js +0 -1
- package/dist/chunk-Q5JTCGJI.js +0 -1
- package/dist/chunk-QLZH2Q2C.cjs +0 -1
- package/dist/chunk-SNQCYZLT.js +0 -1
- package/dist/chunk-UOAEJRVX.js +0 -1
- package/dist/chunk-ZSAAX6HV.cjs +0 -1
- package/dist/document-session-3VC43WNI.cjs +0 -1
- package/dist/document-session-J2YKWERI.js +0 -1
|
@@ -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 di(t,e){return {...t,projectedTarget:e}}function ze(t){return t.projectedTarget}function ci(t){let e=n=>{n._needFormattingCleanup=false;};return t.on("afterTransaction",e),()=>t.off("afterTransaction",e)}function ui(t,e,n){let o=t.doc;if(!o){t.delete(e,n);return}B.transact(o,r=>{let i=e,a=n;for(let s=t._start;s&&a>0;s=s.right){if(s.deleted||!s.countable)continue;if(i>=s.length){i-=s.length;continue}let l=s;i>0&&(l=B.getItemCleanStart(r,B.createID(s.id.client,s.id.clock+i)),i=0),a<l.length&&B.getItemCleanStart(r,B.createID(l.id.client,l.id.clock+a)),a-=l.length,l.delete(r),s=l;}}),t._searchMarker&&(t._searchMarker.length=0);}function Nt(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,a=0;for(let s=t._start;s&&i<n.length;s=s.right){if(s.deleted||!s.countable)continue;let l=a+s.length,d=s,c=a;for(;i<n.length&&n[i]<l;){let p=n[i],u=p+1;for(i+=1;i<n.length&&n[i]===u&&u<l;)u+=1,i+=1;let f=d;p>c&&(f=B.getItemCleanStart(r,B.createID(d.id.client,d.id.clock+(p-c)))),u-p<f.length&&B.getItemCleanStart(r,B.createID(f.id.client,f.id.clock+(u-p))),f.delete(r),d=u<l?f.right:f,c=u;}s=d,a=l;}}),t._searchMarker&&(t._searchMarker.length=0);}function vo(t,e){let n=[...new Set(e)].filter(a=>a>=0).sort((a,s)=>a-s),o=[],r=0,i=0;for(let a=t._start;a&&r<n.length;a=a.right){if(a.deleted||!a.countable)continue;let s=i+a.length;for(;r<n.length&&n[r]<s;r+=1)o.push({client:a.id.client,clock:a.id.clock+(n[r]-i)});i=s;}return o}function Lo(t,e){if(e.length===0)return;let n=new Map;for(let{client:i,clock:a}of e){let s=n.get(i);s||n.set(i,s=new Set),s.add(a);}let o=[],r=0;for(let i=t._start;i;i=i.right){if(i.deleted||!i.countable)continue;let a=n.get(i.id.client);if(a)for(let s=0;s<i.length;s+=1)a.has(i.id.clock+s)&&o.push(r+s);r+=i.length;}Nt(t,o);}function pi(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 fi(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 hi(t,e){let n=t.doc;!n||e.deleted||(B.transact(n,o=>e.delete(o)),t._searchMarker&&(t._searchMarker.length=0));}function tn(t){return t._start}function ce(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*nn(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 Sd(t,e){for(let n of nn(t,e))if(n.content instanceof B.ContentString)return n;return null}function dt(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"?Sd(r,i):wd(r,i):null}function wd(t,e){for(let n of nn(t,e))if(n.content instanceof B.ContentEmbed)return n;return null}function $e(t){return t._item?.parentSub??null}function Ne(t){return t instanceof B.AbstractType?t._item:null}function on(t){return t._item?.id??null}function Me(t,e){return t._map.get(e)}function Ro(t){return t.store.pendingStructs?.update??null}function ve(t){return t.store.pendingStructs!==null||t.store.pendingDs!==null}function rn(t,e){for(let[n,o]of t.changed)if(n===e)return o;return null}function ct(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 N(t){return t.id}var kd=16,mi=16,vd=new Set(["paraId","textId","id","numId","bookmarkId"]);function gi(t){let e="";for(let n of t)e+=n.toString(kd).padStart(2,"0");return e}function Ld(t){let e=new Uint8Array(mi);return globalThis.crypto.getRandomValues(e),gi(e)}function Oo(t){return /^[0-9a-f]{32}$/.test(t)}function Rd(t,e){if(!Oo(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 ye(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 ut(t,e){let n=t?ye(t):null,o=e?ye(e):null;return n!==null&&o!==null&&n.client===o.client&&n.clock+1===o.clock}function yi(t,e){return `yjs:${t}:${e}`}function Dt(t){if(!t.startsWith("lid:"))return null;let e=t.slice(4,t.indexOf(":",4));return Oo(e)?e:null}function bi(t){let e=[];for(let n of t)vd.has(n.localName)&&e.push(n.value);return e}var Mt=class{replicaId;next=0;constructor(e){if(this.replicaId=e??Ld(),!Oo(this.replicaId))throw new Error("invalid replica identity")}take(){let e=Rd(this.replicaId,this.next);return this.next+=1,e}get counter(){return this.next}};var We=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}),Ed=/^sha256:[0-9a-f]{64}$/;function xi(t){return t?Object.freeze({...We,...t}):We}function v(t){return isDangerousKey(t)?"prototype-key":null}function ie(t,e){return typeof t!="string"||t.length>e?"invalid-string":isDangerousKey(t)?"prototype-key":null}function Z(t){let e=v(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 Si(t){for(let e of Object.keys(t)){let n=v(e);if(n)return n}return !Ed.test(t.digest)||!Number.isSafeInteger(t.size)||t.size<0?"invalid-blob-descriptor":t.size>We.maxBlobBytes?"blob-too-large":ie(t.mediaType,We.maxMediaTypeLength)||t.mediaType.length===0||ie(t.storageKey,We.maxStorageKeyLength)||t.storageKey.length===0?"invalid-blob-descriptor":null}var Cd="https://www.docx-editor.dev/docs/2.x/pro/collaboration-versions",A=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 ${Cd}#upgrade-saved-rooms`:i);this.code=n;this.detail=o;this.name="CollaborationSchemaError";}code;detail};var Ve=Object.freeze({protocolVersion:1,sharedSchemaVersion:5,repairVersion:2,canonicalModelVersion:1});function Eo(t){let e=t!==null&&typeof t=="object"&&!Array.isArray(t)?t:{};for(let n of Object.keys(Ve)){let o=Ve[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 Yh(t){let e=Eo(t);if(e)throw new A(e.code,e.detail)}var Td=Ve.protocolVersion,Ad=Ve.sharedSchemaVersion,Pd=Ve.repairVersion,Nd=Ve.canonicalModelVersion,Co="docx-package-meta-v1",To="docx-package-nodes-v1",Md="docx-package-parts-v1",Dd="docx-package-rels-v1",_d="docx-package-overrides-v1",Yd="docx-package-defaults-v1",Bd="docx-package-binaries-v1",Ud="docx-package-namespaces-v1",Fd="docx-package-attributes-v1",jd="docx-package-bindings-v1",sn="s",an="b",ue="t",ln="children",Le="deleted",Ke="replacedBy",Je="undone",_t="splitFrom",Xe="splitLineage";var ee="",ki="-",vi=Object.freeze({kind:"docx-package-bootstrap"}),Ao=Object.freeze({kind:"docx-package-journal"});function He(t){return t.kind==="textValue"}function j(t){return !He(t)}var zd=Object.freeze(new Set(["missing-node","child-id-not-in-registry","cycle"])),$d=200;function Yt(t){let e=new Map;for(let n of t)zd.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,$d)}function Li(t){return {meta:t.getMap(Co),nodes:t.getMap(To),parts:t.getMap(Md),relationships:t.getMap(Dd),overrides:t.getMap(_d),defaults:t.getMap(Yd),binaries:t.getMap(Bd),namespaces:t.getMap(Ud),attributes:t.getMap(Fd),bindings:t.getMap(jd)}}var Ri=[["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"]],Wd=new Map(Ri),Vd=new Map(Ri.map(([t,e])=>[e,t]));function Kd(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 Ge(t){return t.length===0?ki:Wd.get(t)??`n${Kd(t)}`}function pt(t,e,n){let o=Ge(e);return e.length===0||v(o)||ie(e,n)||t.get(o)!==e&&t.set(o,e),o}function qe(t,e){if(e===ki||v(e))return "";let n=t.get(e);return typeof n=="string"?n:Vd.get(e)??""}function Po(t,e,n,o){return `${t}${ee}${e}${ee}${n}${ee}${o}`}function Jd(t){let e=t.split(ee);return {kind:e[0]||"generic",namespaceId:e[1]??"",localName:e[2]??"",prefix:e[3]??""}}function Re(t){let e=t.has(sn)?t.get(sn):t.get(an);return Jd(typeof e=="string"?e:"")}function No(t,e,n){return `${t}${ee}${e}${ee}${n}`}function Bt(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 Mo(t,e){return `${t}${ee}${e}`}function Ze(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 Oi(t,e){return `${t}${ee}${e}`}function Ei(t){let e=t.indexOf(ee);return e<0?{prefix:"",value:t}:{prefix:t.slice(0,e),value:t.slice(e+1)}}function Ci(t){let e=new B.Map,n=Po(t.kind,t.namespaceId,t.localName,t.prefix??"");e.set(an,n);let o=new B.Array;return t.childIds&&t.childIds.length>0&&o.push([...t.childIds]),e.set(ln,o),e}function dn(t){let e=new B.Map;return e.set(ue,new B.Text(t)),e}function Ti(t,e,n){let o=new B.Map;return o.set("id",t),o.set("rootId",e),o.set("contentType",n),o}function Ai(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 Pi(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 cn(t){return Eo({protocolVersion:t.get("protocolVersion"),sharedSchemaVersion:t.get("sharedSchemaVersion"),repairVersion:t.get("repairVersion"),canonicalModelVersion:t.get("canonicalModelVersion")})}function Ni(t){t.set("protocolVersion",Td),t.set("sharedSchemaVersion",Ad),t.set("repairVersion",Pd),t.set("canonicalModelVersion",Nd),t.set("initialized",true);}function Mi(t,e){let n=Me(t,e);return n!==void 0&&n.deleted}function Do(t){return Ro(t)!==null}var wi=new WeakMap,Xd={origins:new Set,fields:new Set};function Di(t){let e=Ro(t);if(e===null)return Xd;let n=wi.get(e);if(n)return n;let o=new Set,r=new Set;try{for(let a of B.decodeUpdateV2(e).structs)a instanceof B.Item&&(a.origin&&o.add(`${a.origin.client}:${a.origin.clock}`),a.parent instanceof B.ID&&a.parentSub!==null&&r.add(`${a.parent.client}:${a.parent.clock}:${a.parentSub}`));}catch{}let i={origins:o,fields:r};return wi.set(e,i),i}function _i(t,e){if(t.has(e)||t.doc===null)return false;let n=on(t);return n!==null&&Di(t.doc).fields.has(`${n.client}:${n.clock}:${e}`)}function _o(t,e){if(t.has(e)||t.doc===null||!Do(t.doc))return false;let n=Me(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 Di(t.doc).origins.has(`${o.client}:${o.clock}`)}function M(t){return t instanceof B.Map}function te(t){if(!M(t))return null;let e=t.get(ln);return e instanceof B.Array?e:null}function ft(t){return M(t)&&t.get(ue)instanceof B.Text}function Oe(t){return M(t)&&t.get(Le)===true}function un(t){return M(t)&&t.get(Je)===true}function pn(t){return Yo(t,Ke)}function Yo(t,e){if(!M(t))return null;let n=t.get(e);return typeof n=="string"&&n.length>0?n:null}function Yi(t,e){let n=o=>{let r=t.get(o);return M(r)?Me(r,Ke)?.id??{client:0,clock:0}:{client:0,clock:0}};return [...e??[]].sort((o,r)=>{let i=n(o),a=n(r);return i.clock-a.clock||i.client-a.client||(o<r?-1:o>r?1:0)})}function Ut(t){return Yo(t,_t)}function Qe(t){return Yo(t,Xe)??Ut(t)}function Ui(t,e){let n=t.get(e);if(!M(n))return null;if(ft(n)){let o=n.get(ue);return {isText:true,textLength:o instanceof B.Text?o.length:0,children:[]}}return {isText:false,textLength:0,children:te(n)?.toArray()??[]}}function Fi(t,e){let n=t.get(e);return M(n)?ft(n)?"textValue":Re(n).kind:null}function fn(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 ji(t,e,n,o,r){let i=Re(e);return {logicalId:t,kind:i.kind,namespaceUri:qe(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 zi(t){let e=on(t);return e&&yi(e.client,e.clock)}function $i(t){return typeof t=="string"?t:""}function V(t){return String(t)}function Uo(t){return !v(t)}function Wi(t){t.forEach(e=>{if(M(e)&&(e.has("parent")||e.has("parentId")))throw new Error("registry record must not replicate a parent field")});}function pe(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 Ee(t,e,n=t.id){return {...t,id:n,children:e}}function Vi(t){return t.kind!=="textValue"}function Ki(t){return t.filter(Vi)}function ht(t){if(!Vi(t))throw new Error(`expected an element, found text node ${t.id}`);return t}function hn(t,e,n,o=[]){return Object.freeze(pe({id:t,kind:e,namespaceUri:WML_NAMESPACE_URI,localName:n,prefix:"w",namespaceBindings:Object.freeze([]),attributes:Object.freeze([...o]),children:Object.freeze([])}))}function mn(t){return pe({id:t,kind:"generic",namespaceUri:"",localName:"",namespaceBindings:[],attributes:[],children:[]})}function mt(t,e){return {id:t,kind:"textValue",value:e}}function gt(t){return t}var qd=new Set(["t","delText","instrText","delInstrText"]),Zd=new Set(["hyperlink","ins","del","moveFrom","moveTo","sdt","sdtContent","fldSimple","smartTag","customXml","dir","bdo"]),Qd=new Set(["sdtPr","sdtEndPr","smartTagPr","customXmlPr","fldData"]);function Fo(t,e){return t.kind!=="textValue"&&t.namespaceUri===WML_NAMESPACE_URI&&e.has(t.localName)}function yt(t,e=[]){return Ee(t,e)}function ec(t){return Fo(t,qd)&&t.children.every(e=>e.kind==="textValue")}function yn(t){let e=[],n=[],o={run:null,runProperties:null,properties:[],text:null,textValueId:null,wrap:[]},r=(s,l)=>{let d=s.children.find(u=>u.kind==="runProperties"),c={...o,run:yt(s),runProperties:d?yt(d):null,properties:d?Ki(d.children):[],wrap:l},p=0;for(let u of s.children)if(u!==d)if(p+=1,ec(u)){let f=u.children.map(m=>m.kind==="textValue"?m.value:"").join(""),h={...c,text:yt(u),textValueId:u.children[0]?.id??null};f.length===0&&e.push({kind:"anchor",attributes:h});for(let m=0;m<f.length;m+=1)e.push({kind:"char",value:f[m],attributes:h});}else e.push({kind:"embed",node:u,attributes:c});p===0&&e.push({kind:"anchor",attributes:c});},i=(s,l)=>{for(let d of s)if(d.kind==="run")r(d,l);else if(Fo(d,Zd)){let c=d.children.filter(f=>Fo(f,Qd)),p=[...l,yt(d,c)],u=d.children.filter(f=>!c.includes(f));u.length===0&&e.push({kind:"anchor",attributes:{...o,wrap:p}}),i(u,p);}else e.push({kind:"embed",node:d,attributes:{...o,wrap:l}});},a=[];for(let s of t.children)s.kind==="paragraphProperties"?n.push(s):a.push(s);return i(a,[]),{shell:yt(t,n),items:e}}function gn(t){return {shell:t,children:[...t.children],openRun:null,openText:null}}function tc(t){return t.runSignature!==void 0?t.runSignature:[t.run.id,t.runProperties?.id??"",...t.properties.map(e=>e.id)].join("")}function Ji(t){let e=gn(t.shell),n=[e],o=a=>{let s=a.openText;s&&(s.value.length>0&&s.builder.children.push(mt(s.valueId,s.value)),a.openText=null);},r=a=>{a.openRun&&o(a.openRun.builder),a.openRun=null;};for(let a of t.items){let{wrap:s}=a.attributes,l=a.attributes.wrapSignatures,d=(h,m)=>l?h.signature===l[m]:h.shell.id===s[m].id,c=1;for(;c<n.length&&c-1<s.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<s.length;h+=1){let m=n[n.length-1];r(m);let b=gn(s[h]);b.signature=l?.[h],m.children.push(b),n.push(b);}let p=n[n.length-1];if(!a.attributes.run){r(p),a.kind==="embed"&&p.children.push(a.node);continue}let u=tc(a.attributes);if(p.openRun?.key!==u){r(p);let h=gn(a.attributes.run);a.attributes.runProperties&&h.children.push(yt(a.attributes.runProperties,a.attributes.properties)),p.children.push(h),p.openRun={key:u,builder:h};}let f=p.openRun.builder;if(a.kind==="embed"){o(f),f.children.push(a.node);continue}if(a.attributes.text){if(f.openText?.key!==a.attributes.text.id){o(f);let h=gn(a.attributes.text);f.children.push(h),f.openText={key:a.attributes.text.id,builder:h,valueId:a.attributes.textValueId??`${a.attributes.text.id}/value`,value:""};}a.kind==="char"&&(f.openText.value+=a.value);}}for(;n.length>0;)r(n.pop());let i=a=>"shell"in a?Object.freeze(Ee(a.shell,Object.freeze(a.children.map(i)))):a;return ht(i(e))}var $o={kind:"run",localName:"r"},bn={kind:"runProperties",localName:"rPr"},Wo={kind:"text",localName:"t"},In=32768,Se=24;function Xi(t,e=0){if(e>Se)return 1/0;if(!oe(t))return 1;let n=t.c,o=1;if(Array.isArray(n))for(let r of n)o+=Xi(r,e+1);return o}var be=class extends Error{constructor(n,o){super(`shared text value refused (${n}): ${o}`);this.code=n;this.detail=o;}code;detail};function Vo(t,e,n=0){if(n===0&&Xi(t)>In)return "too-many-nodes";if(n>Se)return "tree-too-deep";if(!oe(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 a of i)if(Array.isArray(a))for(let s of a){if(typeof s=="string"&&s.length>e.maxStringLength)return "invalid-string";if(typeof s=="string"&&v(s))return "prototype-key"}}}for(let r of ["l","k","p"]){let i=t[r];if(typeof i=="string"&&v(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=Vo(r,e,n+1);if(i!=="invalid-string"||Ft(r,e))return i}}return "invalid-string"}function Ft(t,e){return typeof t=="string"?t.length>e.maxStringLength:Array.isArray(t)?t.some(n=>Ft(n,e)):oe(t)?Object.entries(t).some(([n,o])=>n==="v"?false:Ft(o,e)):false}var Hi=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"]]),nc=new Map([...Hi].map(([t,e])=>[e,t]));function jt(t){return t===WML_NAMESPACE_URI?"":Hi.get(t)??t}function zt(t){return t===""?WML_NAMESPACE_URI:t.startsWith("#")?nc.get(t)??null:t}function xn(t){if(t===WML_NAMESPACE_URI)return "w";if(t===XML_NAMESPACE_URI)return "xml"}var jo=/^(.*:)(\d{1,15})$/;function $t(t,e){if(t===e)return "=";if(e.length>0&&t.startsWith(e))return `^${t.slice(e.length)}`;let n=jo.exec(t),o=jo.exec(e);return n&&o&&n[1]===o[1]?`+${Number(n[2])-Number(o[2])}`:/^[=^+!]/.test(t)?`!${t}`:t}function It(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=jo.exec(e),a=i?Number(i[2])+r:NaN;o=i&&Number.isSafeInteger(a)&&a>=0?`${i[1]}${a}`:null;}else t.startsWith("!")?o=t.slice(1):o=t;return !o||o.length>n.maxStringLength||v(o)?null:o}function Gi(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 oc(t){let e=[t.localName,t.value],n=t.prefix,o=Gi(t.namespaceUri,t.localName,n,t.value),r=[jt(t.namespaceUri),n===xn(t.namespaceUri)?"":n??null,t.kind===o?"":t.kind];for(;r.length>0&&r[r.length-1]==="";)r.pop();return [...e,...r]}function xt(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=jt(t.namespaceUri);i!==""&&(o.n=i);let a=e&&t.localName===e.localName&&t.namespaceUri===WML_NAMESPACE_URI?e.kind:"generic";return t.kind!==a&&(o.k=t.kind),t.prefix!==xn(t.namespaceUri)&&(o.p=t.prefix??""),t.attributes.length>0&&(o.a=t.attributes.map(oc)),t.namespaceBindings.length>0&&(o.b=t.namespaceBindings.map(s=>[s.prefix,jt(s.namespaceUri)])),n&&t.children.length>0&&(o.c=t.children.map(s=>xt(s,null,true))),o}function oe(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function xe(t,e){return typeof t=="string"&&t.length<=e.maxStringLength}function rc(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,a="",s="",l=""]=o;if(!xe(r,e)||v(r)||!xe(i,e)||!xe(a,e))return null;let d=zt(a);if(d===null||s!==null&&!xe(s,e))return null;let c=s===""?xn(d):s??void 0;if(c!==void 0&&v(c)||!xe(l,e))return null;let p=l||Gi(d,r,c,i);if(p!=="xmlSpace"&&p!=="wmlVal"&&p!=="genericExtension")return null;n.push(Object.freeze({kind:p,namespaceUri:d,localName:r,...c===void 0?{}:{prefix:c},value:i}));}return Object.freeze(n)}function ic(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(!xe(r,e)||!xe(i,e)||v(r))return null;let a=zt(i);if(a===null)return null;n.push(Object.freeze({prefix:r,namespaceUri:a}));}return Object.freeze(n)}function St(t,e,n,o,r,i){if(r.nodes+=1,r.nodes>In||i>Se||!oe(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(mt(e,t.v));let a=t.l??n?.localName;if(!xe(a,o)||v(a))return null;let s=t.n??"";if(!xe(s,o))return null;let l=zt(s);if(l===null)return null;let d=n&&a===n.localName&&l===WML_NAMESPACE_URI?n.kind:"generic",c=t.k??d;if(!xe(c,o)||v(c))return null;let p=xn(l);if(t.p!==void 0){if(!xe(t.p,o)||v(t.p))return null;p=t.p===""?void 0:t.p;}let u=rc(t.a,o),f=ic(t.b,o);if(!u||!f)return null;let h=t.c??[];if(!Array.isArray(h)||h.length>o.maxChildren)return null;let m=[];for(let b=0;b<h.length;b+=1){let w=St(h[b],`${e}~${b}`,null,o,r,i+1);if(!w)return null;m.push(w);}return Object.freeze(pe({id:e,kind:c,namespaceUri:l,localName:a,namespaceBindings:f,attributes:u,children:Object.freeze(m),...p===void 0?{}:{prefix:p}}))}var we="v:",se="b",wn=512,ts=2**31,sc=new Set(["ins","del","moveFrom","moveTo"]);function Sn(t){return t.namespaceUri===WML_NAMESPACE_URI&&sc.has(t.localName)}var ac=new Set(["hyperlink","fldSimple"]);function ns(t){return t.namespaceUri===WML_NAMESPACE_URI&&ac.has(t.localName)}function Vt(t,e,n,o={}){return {i:$t(t.id,e),...xt(t,n,false),...o}}function Jo(t,e){return Vt(t,e,null,{c:t.children.map(n=>xt(n,null,true))})}function os(t,e,n){let o=[],r=new Set,i=t.map(s=>{let l=$t(s.id,e),d=r.has(l)?`!${s.id}`:l;return r.add(d),d}),a=0;return t.forEach((s,l)=>{if(!Sn(s)){let d=i.filter((p,u)=>u>l&&Sn(t[u])),c=ns(s)?i.filter((p,u)=>u<l&&Sn(t[u])):[];o.push({wrapper:s,inside:d,outside:c});return}a+=1,n[`${we}${i[l]}`]=JSON.stringify({e:{...Jo(s,e),i:i[l]},d:a});}),o}function Xo(t,e,n,o="r"){let r=new Set,i=oe(t)?t[o]:void 0;if(!Array.isArray(i))return r;for(let a of i.slice(0,Se)){let s=It(a,n,e);s!==null&&r.add(s);}return r}function fe(t){if(typeof t=="string")try{return JSON.parse(t)}catch{return}}var lc=65536,qi=4096;function Ko(t){let e=new Set;if(typeof t!="string"||t.length>wn*(qi+3))return e;let n=fe(t);if(!Array.isArray(n))return e;for(let o of n.slice(0,wn))typeof o!="string"||o.length>qi||v(o)||e.add(`${we}${o}`);return e}function dc(t){let e=Ko(t[se]);return Object.keys(t).filter(n=>n.startsWith(we)&&!v(n)&&!e.has(n)).sort()}var cc=null;function uc(t){return typeof t=="number"&&Number.isSafeInteger(t)&&t>=1&&t<=ts}function pc(t,e,n,o){if(typeof e!="string"||e.length>lc)return null;let r=fe(e);if(!oe(r)||!oe(r.e))return null;let i=r.d;if(!uc(i))return null;let{i:a,...s}=r.e,l=It(a,o,n);if(l===null)return null;let d=St(s,l,cc,n,{nodes:0},0);return !d||d.kind==="textValue"||!Sn(d)?null:{key:t,shell:d,encodedId:a,order:i,content:JSON.stringify(s),signature:JSON.stringify(s)}}function Wt(t,e,n){let o=[];for(let r of dc(t)){let i=pc(r,t[r],e,n);if(i&&o.push(i),o.length===Se)break}return o.sort(fc)}function fc(t,e){return t.order-e.order||(t.key<e.key?-1:t.key>e.key?1:0)}function rs(t,e){let n=[...t];for(let o of e.slice(0,Math.max(0,Se-t.length))){let r=0,i=null;for(let s=n.length-1;s>=0;s-=1)if(n[s].inside?.has(o.shell.id)){r=s+1,i=n[s].shell.id;break}let a=n.some(s=>s.outside?.has(o.shell.id));for(let s=n.length-1;s>=r&&!a;s-=1)if(n[s].anchor===void 0&&ns(n[s].shell)){r=s+1,i=n[s].shell.id;break}for(;r<n.length&&n[r].anchor===i;)r+=1;n.some(s=>s.shell.id===o.shell.id)||n.splice(r,0,{shell:o.shell,signature:o.signature,anchor:i});}return n.map(({shell:o,signature:r})=>({shell:o,signature:r}))}function hc(t,e){let n=new Set,o=[],r=new Map;for(let i of e){let a=t.find(s=>!n.has(s)&&s.content===i.content);a?(n.add(a),r.set(i.encodedId,a.encodedId)):o.push(i);}return {kept:n,added:o,renamed:r}}function Ho(t){let e={};for(let n of Object.keys(t))!n.startsWith(we)&&n!==se&&(e[n]=t[n]);return e}function kn(t){for(let e of Object.keys(t))if(e.startsWith(we)||e===se)return true;return false}function mc(t,e,n){if(t===e)return true;let o=fe(t??"[]"),r=fe(e??"[]");return !Array.isArray(o)||!Array.isArray(r)||o.length!==r.length?false:o.every((i,a)=>{let s=r[a];if(!oe(i)||!oe(s))return false;let{r:l,...d}=i,{r:c,...p}=s;if(JSON.stringify(d)!==JSON.stringify(p))return false;let u=f=>(Array.isArray(f)?f:[]).filter(h=>n.has(h)).sort();return JSON.stringify(u(l))===JSON.stringify(u(c))})}function gc(t,e){let n=JSON.parse(t);return JSON.stringify({...n,d:e})}function yc(t,e){if(t===void 0||![...e].some(([o,r])=>o!==r))return t;let n=fe(t);return Array.isArray(n)?JSON.stringify(n.map(o=>oe(o)&&Array.isArray(o.r)?{...o,r:o.r.map(r=>typeof r=="string"?e.get(r)??r:r)}:o)):t}function Zi(t){return JSON.stringify([...t].map(e=>e.slice(we.length)).sort())}function Go(t,e,n,o,r){if(!kn(t))return e;let i=Wt(t,o,r),a=Wt(e,o,r),s=Ho(e);for(let b of Object.keys(t))b.startsWith(we)&&(s[b]=t[b]);let l=Ko(t[se]),{kept:d,added:c,renamed:p}=hc(i,a);for(let b of i)d.has(b)||(n?l.add(b.key):delete s[b.key]);let u=yc(s.w,p);u!==void 0&&(s.w=u);let f=new Set([...d].map(b=>b.encodedId).concat(c.map(b=>b.encodedId)));mc(t.w,s.w,f)&&(t.w===void 0?delete s.w:s.w=t.w);let h=i.reduce((b,w)=>Math.max(b,w.order),0),m=false;for(let b of c)h=Math.min(h+1,ts),s[b.key]=gc(e[b.key],h),m=l.delete(b.key)||m;if(!n&&!m)return t[se]!==void 0&&(s[se]=t[se]),s;if(l.size>wn){let b=[...l].sort();for(let w of b.slice(wn))l.delete(w),delete s[w];}if(l.size>0){let b=Zi(l);s[se]=t[se]!==void 0&&Zi(Ko(t[se]))===b?t[se]:b;}return s}var Qi=new WeakMap,bc=4096;function Ic(t){let e=[];for(let n of Object.keys(t).sort())(n.startsWith(we)||n===se)&&e.push(JSON.stringify([n,t[n]]));return e.join(",")}function qo(t,e,n){if(!kn(t))return "[]";let o=Qi.get(e);o||Qi.set(e,o=new Map);let r=`${n}\0${Ic(t)}`,i=o.get(r);if(i!==void 0)return i;let a=Wt(t,e,n),s=JSON.stringify(a.map(l=>l.content));return o.size>=bc&&o.clear(),o.set(r,s),s}var ne="inline",Zo="r",wt="rp",ds="t",cs="w",Qo="p:";function er(t){return t.kind!=="embed"?{a:1}:t.attributes.run?{n:t.node.id,r:1}:{n:t.node.id}}function wc(t){let e=new Map;return t.map(n=>{let o=jt(n.namespaceUri),r=`${Qo}${o===""?"":`${o}|`}${n.localName}`,i=(e.get(r)??0)+1;return e.set(r,i),i===1?r:`${r}#${i}`})}function us(t){let e=t.slice(Qo.length).replace(/#\d+$/,""),n=e.indexOf("|"),o=zt(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 et(t,e,n){let o={},r=t.run;if(r&&(o[Zo]=JSON.stringify(Vt(r,e,$o))),r&&t.runProperties){let a=wc(t.properties);o[wt]=JSON.stringify(Vt(t.runProperties,e,bn,{o:a})),t.properties.forEach((s,l)=>{let d={kind:"generic",localName:s.localName};o[a[l]]=JSON.stringify(xt(s,d,true));});}if(t.text){let a=t.text.id,s=t.textValueId??`${a}~v`,l=s===`${a}~v`?{}:{v:$t(s,a)};o[ds]=JSON.stringify(Vt(t.text,e,Wo,l));}if(t.wrap.length>Se)throw new be("tree-too-deep",`${t.wrap.length} nested wrappers`);let i=os(t.wrap,e,o);return i.length>0&&(o[cs]=JSON.stringify(i.map(({wrapper:a,inside:s,outside:l})=>({...Jo(a,e),...s.length>0?{r:s}:{},...l.length>0?{x:l}:{}})))),Object.values(o).some(a=>kc(a,n))&&Lc(t,o,e,n),o}function kc(t,e){let n=Math.min(e.maxStringLength,e.maxAttributes,e.maxChildren,e.maxTextLength,In);if(t.length>n||vc.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*Se+2)return true}else (i===125||i===93)&&(o-=1);}return false}var vc=/__proto__|constructor|prototype/;function Lc(t,e,n,o){let r=he(e,o,n);if(!((e[wt]===void 0||Kt(fe(e[wt]),n,bn,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[a,s]of Object.entries(e)){let l=fe(s),d=Array.isArray(l)?l:[l];for(let c of d){let p=Vo(c,o);if(p!=="invalid-string"||Ft(c,o))throw new be(p,`${a} of an item in ${n}`)}}throw new be("invalid-string",`an item in ${n}`)}}function ps(t,e,n){let o=[],r=null,i=()=>{r&&o.push({insert:r.text,attributes:r.attributes}),r=null;};for(let a of t){let s=et(a.attributes,e,n);if(a.kind==="char"){let l=re(s);r&&r.signature===l?r.text+=a.value:(i(),r={text:a.value,attributes:s,signature:l});continue}i(),o.push({insert:er(a),attributes:s});}return i(),o}function re(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 Kt(t,e,n,o,r=false){if(!oe(t))return null;let i=It(t.i,e,o);if(!i)return null;let{i:a,v:s,o:l,c:d,...c}=t,p=St(r?{...c,c:d}:c,i,n,o,{nodes:0},0);return !p||p.kind==="textValue"?null:{shell:p,data:t}}var is=["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 ss(t){let e=us(t),n=e?.namespaceUri===WML_NAMESPACE_URI?is.indexOf(e.localName):-1;return n<0?is.length-1:n}function Rc(t,e){return ss(t)-ss(e)||(t<e?-1:t>e?1:0)}function Oc(t){return hn(t,"runProperties","rPr")}var as=new WeakMap,Ec=4096;function he(t,e,n){let o=JSON.stringify([n,re(t)]),r=as.get(e);r||as.set(e,r=new Map);let i=r.get(o);if(i)return i;let a=Cc(t??{},e,n);return r.size>=Ec&&r.clear(),r.set(o,a),a}function Cc(t,e,n){let o=Kt(fe(t[Zo]),n,$o,e),r=o?Kt(fe(t[wt]),n,bn,e):null,i=[],a=[],s=o?Object.keys(t).filter(y=>y.startsWith(Qo)).sort().slice(0,e.maxChildren):[],l={nodes:0},d=r?.shell??(o&&s.length>0?Oc(`${o.shell.id}~rPr`):null);if(o&&d){let y=Array.isArray(r?.data.o)?r.data.o:[],k=s.every(I=>y.includes(I))?y.filter(I=>typeof I=="string"&&s.includes(I)):[...s].sort(Rc);for(let I of k){let g=us(I);if(!g||v(I))continue;let S=St(fe(t[I]),`${d.id}~${I}`,{kind:"generic",localName:g.localName},e,l,0);S&&S.kind!=="textValue"&&(i.push(S),a.push(I));}}let c=fe(t[ds]),p=Kt(c,n,Wo,e),u=p?(oe(c)&&c.v!==void 0?It(c.v,p.shell.id,e):null)??`${p.shell.id}~v`:null,f=fe(t[cs]),h=[];if(Array.isArray(f)&&f.length<=Se)for(let y of f){let k=Kt(y,n,null,e,true);if(!k)break;let{r:I,x:g,...S}=y;h.push({shell:k.shell,signature:JSON.stringify(S),inside:Xo(y,e,n),outside:Xo(y,e,n,"x")});}let m=rs(h,Wt(t,e,n)),b=m.map(y=>y.shell),w=m.map(y=>y.signature),E=o?JSON.stringify([t[Zo],typeof t[wt]=="string"?t[wt]:"",...a.map(y=>[y,t[y]])]):void 0;return Object.freeze({run:o?.shell??null,runProperties:i.length>0||r?d:null,properties:Object.freeze(i),text:p?.shell??null,textValueId:u,wrap:Object.freeze(b),...E!==void 0?{runSignature:E}:{},wrapSignatures:Object.freeze(w)})}function tr(t,e,n,o,r={}){let i=[],a=[],s=c=>{for(let p of c.entries){for(let u of p.slot?.before??[])s(u);p.item&&(i.push(p.item),a.push(p.placement),p.item.kind==="char"&&r.onCharacter?.(p.character??null));for(let u of p.slot?.after??[])s(u);}},l=(c,p=false)=>{let u=r.following?.at.get(c);for(let f of (p?u?.before:u?.after)??[])s(f);},d=0;for(let c of t){let p=he(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:p}),a.push(void 0),r.onCharacter){let m=r.characters?.items[d];r.onCharacter(m===void 0?null:{item:m,identity:r.characters?.ids[d]??null});}l(d);}continue}if(d+=1,r.hidden?.has(d-1)||!oe(c.insert))continue;if(c.insert.a===1){i.push({kind:"anchor",attributes:p}),a.push(void 0);continue}let u=c.insert.n;if(typeof u!="string"||v(u))continue;let f=e(u);f&&(i.push({kind:"embed",node:f,attributes:p}),a.push(c.insert.r===1));}for(let c of r.following?.atEnd??[])s(c);return Nc(i,a,o,r.onRepair)}function fs(t,e,n=o=>o){let o=new Set,r=(i,a)=>{if(e.has(i.id))return i;let l=a!==null&&i.id.startsWith(a.from)&&(i.id[a.from.length]==="~"||i.id[a.from.length]==="/")?`${a.to}${i.id.slice(a.from.length)}`:i===t?i.id:n(i.id);if(o.has(l)){let u=2;for(;o.has(`${l}~${u}`);)u+=1;l=`${l}~${u}`;}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(u=>r(u,d));return d===null&&c.every((u,f)=>u===i.children[f])?i:Object.freeze(Ee(i,Object.freeze(c),l))};return ht(r(t,null))}function Tc(t,e){return t.kind==="char"||t.kind==="embed"&&e===true}function ls(t){return t.kind==="char"}function Ac(t){return Object.freeze({run:null,runProperties:null,properties:Object.freeze([]),text:null,textValueId:null,wrap:t.wrap,...t.wrapSignatures?{wrapSignatures:t.wrapSignatures}:{}})}function Pc(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 Nc(t,e,n,o){let r=(d,c)=>Tc(d,e[c])&&!d.attributes.run||d.kind==="embed"&&e[c]===false&&d.attributes.run!==null||ls(d)&&d.attributes.run!==null&&!d.attributes.text;if(!t.some(r))return t;o?.();let i=(d,c)=>{for(let p=1;p<t.length;p+=1){let u=t[d-p];if(u&&c(u,d-p))return u;let f=t[d+p];if(f&&c(f,d+p))return f;if(!u&&!f)break}return null},a=(d,c)=>d.attributes.run!==null&&!(d.kind==="embed"&&e[c]===false),s=hn(`${n}~r`,"run","r"),l=[];return t.forEach((d,c)=>{if(!r(d,c)){l.push(d);return}let p=t[c-1];if(d.kind==="char"&&p?.kind==="char"&&Dc(d.value)&&Mc(p.value)){l.push({...d,attributes:l[l.length-1].attributes});return}let u=d.attributes;if(d.kind==="embed"&&e[c]===false){l.push({...d,attributes:Ac(u)});return}if(!u.run){let f=i(c,a);u=Pc(u,f?.attributes??null,s);}if(ls(d)&&!u.text){let f=u.run,h=i(c,m=>m.kind==="char"&&m.attributes.run?.id===f.id&&!!m.attributes.text);u=Object.freeze({...u,text:h?.attributes.text??hn(`${f.id}~t`,"text","t",[Object.freeze({kind:"xmlSpace",namespaceUri:XML_NAMESPACE_URI,localName:"space",prefix:"xml",value:"preserve"})]),textValueId:h?.attributes.textValueId??null});}l.push({...d,attributes:u});}),l}function Mc(t){let e=t.charCodeAt(0);return t.length===1&&e>=55296&&e<=56319}function Dc(t){let e=t.charCodeAt(0);return t.length===1&&e>=56320&&e<=57343}var _c=8;function vn(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,p)=>{c&&!n.has(c)&&n.set(c,{piece:d,index:p});});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,Yc(d,c,t));}let r=d=>{let c=d;for(let p=0;p<=_c;p+=1){let u=o.get(c);if(!u)return true;c=u.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,a=new Map,s=[],l=(d,c)=>{let p=d.get(c);return p||(p={before:[],after:[]},d.set(c,p)),p};for(let d of t.incoming){let c=e.get(d.after),p=o.get(d),u=null;if(c!==void 0)u=l(i,c);else if(p){let f=a.get(p.piece);f||(f=new Map,a.set(p.piece,f)),u=l(f,p.index);}u?d.before?u.before.push(d):u.after.push(d):s.push(d);}return {atPosition:i,inside:a,atEnd:s}}function Yc(t,e,n){if(t.before)return e;let{positions:o,items:r}=e.piece,{items:i,origins:a}=n.identities,s=r[e.index];if(s===void 0||i[o[e.index]]!==s)return e;let l=p=>ut(s,p),d=new Set,c=e.index;for(let p=c+1;p<o.length;p+=1){let u=r[p],f=o[p],h=i[f]===u?a[f]:null;if(!(h===s&&!l(u))&&!(h!==null&&d.has(h)))break;d.add(u),c=p;}return {piece:e.piece,index:c}}function Uc(t,e,n,o,r,i){let a=t.toDelta();if(!r)return tr(a,e,n,o);let s=r.shown(t);(s.hidden.size>0||s.incoming.length>0)&&r.noteDrift();let l=new Map;for(let h of s.incoming){let m=l.get(h.source)??new Set;for(let b of h.positions)m.add(b);l.set(h.source,m);}let d=new Map;for(let[h,m]of l)d.set(h,Fc(r.textOf(h),h,m,e,n));let c=vn(s),p=h=>{let m=d.get(h.source),b=c.inside.get(h),w=[];return h.positions.forEach((E,y)=>{let k=m.get(E),I=b?.get(y);if(!k&&!I)return;let g=h.items[y];w.push({item:k?.item,placement:k?.placement,...I?{slot:u(I)}:{},...g!==void 0?{character:{item:g,identity:h.identities[y]??null}}:{}});}),{entries:w}},u=h=>({before:h.before.map(p),after:h.after.map(p)}),f=new Map;for(let[h,m]of c.atPosition)f.set(h,u(m));return tr(a,e,n,o,{hidden:s.hidden,following:{at:f,atEnd:c.atEnd.map(p)},onRepair:()=>r.noteDrift(),...i?{onCharacter:i,characters:{items:s.identities.items,ids:s.identities.ids}}:{}})}function Fc(t,e,n,o,r){let i=new Map;if(!t)return i;let a=0;for(let s of t.toDelta()){let l=typeof s.insert=="string"?s.insert.length:1;if(typeof s.insert=="string"){let d=null;for(let c=0;c<l;c+=1)n.has(a+c)&&(d??=he(s.attributes,r,e),i.set(a+c,{item:{kind:"char",value:s.insert[c],attributes:d},placement:void 0}));}else if(n.has(a)){let d=s.insert,c=d?.n,p=typeof c=="string"&&!v(c)?o(c):null;p&&i.set(a,{item:{kind:"embed",node:p,attributes:he(s.attributes,r,e)},placement:d?.r===1});}a+=l;}return i}function Ce(t,e,n,o,r,i){let a=new Set,s=new Set,l=Uc(e,u=>{if(r&&!r.showsEmbed(u))return r.noteDrift(),null;let f=r?.lineageOf?.(u)??null;if(f!==null&&f!==u){if(s.has(f)||r.listed?.(f))return r.noteDrift(),null;s.add(f);}let h=n(u);return h&&a.add(u),h},o,t,r,i),d=pe({id:t,kind:"paragraph",namespaceUri:WML_NAMESPACE_URI,localName:"p",namespaceBindings:[],attributes:[],children:[]}),c=Ji({shell:d,items:l}),p=fs(c,a,r?u=>r.shownId(u):void 0);return r&&p!==c&&r.noteDrift(),p.children}function Ln(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 ms(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&&gs(r,o)?r:o})}function gs(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&&nr(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)&&nr(t.namespaceBindings,e.namespaceBindings,(n,o)=>n.prefix===o.prefix&&n.namespaceUri===o.namespaceUri)&&nr(t.children,e.children,gs)}function nr(t,e,n){return t.length===e.length&&t.every((o,r)=>n(o,e[r]))}var Is=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"]})),xs=new Set(["drawingWrapNone","drawingWrapSquare","drawingWrapTight","drawingWrapThrough","drawingWrapTopBottom"]),Ss=new Map([["inlineDrawing",new Set(["drawingSimplePos","drawingPositionH","drawingPositionV","drawingSizeRelH","drawingSizeRelV",...xs])]]),jc=new Set(["choice:position"]),ws=new Map(Object.entries({drawing:t=>t.kind==="anchoredDrawing"||t.kind==="inlineDrawing"?"choice:placement":null,drawingPositionH:()=>"choice:position",drawingPositionV:()=>"choice:position",anchoredDrawing:t=>xs.has(t.kind)?"choice:wrap":null})),ys={paragraph:"paragraphProperties",run:"runProperties"},zc=new Set(["sectPr","pPrChange"]);function $c(t){return t.kind==="generic"&&t.namespaceUri===WML_NAMESPACE_URI&&zc.has(t.localName)}var ks=new Set(["paragraphProperties","runProperties","tableProperties"]);function Wc(t,e){if(Is.get(t)?.includes(e.kind))return `kind:${e.kind}`;let n=ws.get(t)?.(e);return n||(ks.has(t)&&e.kind==="generic"&&e.namespaceUri===WML_NAMESPACE_URI?`wml:${e.localName}`:null)}function or(t){return t!==null&&(Is.has(t)||ws.has(t)||Ss.has(t)||ks.has(t))}function Rn(t,e,n){if(!or(t))return null;let o=t,r=new Map,i=new Set,a=[],s=Ss.get(o),l=new Set,d=-1;for(let w=0;w<e.length;w+=1){let E=e[w];if(i.has(E))continue;i.add(E);let y=n(E);if(a[w]=y,!y)continue;if(s?.has(y.kind)){l.add(w);continue}d<0&&(d=w);let k=Wc(o,y);if(k===null)continue;let I=r.get(k);I?I.push(w):r.set(k,[w]);}let c=new Map;for(let[w,E]of r){if(E.length<2||E.every(I=>Dt(e[I])===null))continue;let y=jc.has(w)?E.find(I=>a[I]?.empty!==true)??E[0]:E[0],k=E.filter(I=>I!==y);for(let I of k)l.add(I);c.set(y,k);}let p=ys[o]?`kind:${ys[o]}`:null,u=p?r.get(p)?.[0]:void 0,f=u!==void 0&&d!==u,h=o==="paragraphProperties"?r.get("kind:runProperties")?.[0]:void 0,m=-1;if(h!==void 0)for(let w=h+1;w<e.length;w+=1){let E=a[w];E&&!l.has(w)&&!$c(E)&&(m=w);}if(l.size===0&&!f&&m<0)return null;let b=[];f&&b.push(u);for(let w=0;w<e.length;w+=1)l.has(w)||f&&w===u||m>=0&&w===h||(b.push(w),w===m&&b.push(h));return {order:b,companions:c}}function Vc(t,e,n){return Rn(t,e,n)?.order??null}function kt(t,e){if(v(e)||t.isTombstoned(e))return null;let n=t.schema.nodes.get(e);if(!M(n))return null;let o=Re(n);return {kind:o.kind,namespaceUri:qe(t.schema.namespaces,o.namespaceId),localName:o.localName,...te(n)?.length===0?{empty:true}:{}}}function vs(t,e,n){let o=Vc(t,e,n);if(!o)return {shown:e,hidden:[]};let r=o.map(a=>e[a]),i=new Set(r);return {shown:r,hidden:e.filter(a=>!i.has(a))}}var rr=new Set(["paragraphProperties","runProperties","tableProperties"]);function Ls(t,e,n){let o=Rn(t,e,n);if(!o)return {shown:e,hidden:[],merges:null};let r=o.order.map(a=>e[a]),i=new Set(r);return {shown:r,hidden:e.filter(a=>!i.has(a)),merges:Kc(o,e,n)}}function Kc(t,e,n){let o=null;for(let[r,i]of t.companions){let a=n(e[r]);!a||!rr.has(a.kind)||(o??=new Map,o.set(e[r],i.map(s=>e[s])));}return o}var Jc=new Set(["run","runProperties"]),Xc=new Set(["t","delText","instrText","delInstrText"]),Ts=new Set(["hyperlink","ins","del","moveFrom","moveTo","sdt","sdtContent","fldSimple","smartTag","customXml","dir","bdo"]);function As(t){return Jc.has(t.kind)?true:t.namespaceUri===WML_NAMESPACE_URI&&(Xc.has(t.localName)||Ts.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 Es(t){return t.replace(/(~\d+)+$/,"")}var ir=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=N(e),i=o.has(r),a={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,a),!(e.kind==="textValue"||i))for(let s of e.children)a.children.push(N(s)),this.add(s,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 a=n[i];if(a.block||a.opaque)return {paragraph:r.id,inline:false};if(!(a.kind==="textValue"||As(a)||n[i+1].kind==="runProperties"||Hc(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"?mt(Es(o.id),o.value??""):pe({id:o.paragraph||o.opaque?o.id:Es(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 Hc(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&&Ts.has(r.localName))return o.namespaceUri===WML_NAMESPACE_URI&&/Pr$|^fldData$/.test(o.localName)}return false}function Cs(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 On(t,e){let n=e.map(gt),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"&&!Qc(t,h)?h:t.inline.owner(h),i=new Set;for(let h of n)for(let m of Cs(h)){let b=r(m);b&&i.add(b);}if(i.size===0)return {passThrough:[...n],plan:null};let a=h=>{let m=new ir,b=new Set;for(let w of h){let E=t.inline.textOf(w),y=m.placeholder(w,"paragraph");y.opaque=false,y.paragraph=true,y.kind="paragraph",y.namespaceUri=WML_NAMESPACE_URI,y.localName="p";let k=t.record(w),{shown:I}=vs("paragraph",k&&"childIds"in k?k.childIds:[],R=>kt(t,R));for(let R of I){let P=m.placeholder(R,t.kindOf(R)??"generic");P.block=true,P.parent=w,y.children.push(R);}if(!E)continue;let g=new Set,S=R=>t.showsAsChild(R)?(g.add(R),mn(R)):null;for(let R of Ce(w,E,S,t.limits,t.inline.viewOf(w)))m.add(R,w,g),y.children.push(N(R));for(let R of g){b.add(R);let P=m.nodes.get(R);P&&(P.kind=t.kindOf(R)??"generic");}}return {scratch:m,embedsBefore:b}},{scratch:s,embedsBefore:l}=a(i),d=n.flatMap(h=>Cs(h)).filter(h=>!s.nodes.has(h)&&!o.has(h)&&!t.hasNode(h));if(d.length>0){let h=new Set(i);for(let m of eu(t,new Set(d)))h.add(m);if(h.size>i.size){for(let m of h)i.add(m);({scratch:s,embedsBefore:l}=a(i));}}let c=[],p=new Map;for(let h of n){let m=Gc(s,h,t);if(m&&p.set(c.length,m),c.push(qc(s,h,t)),s.refusal)return {passThrough:[...n],plan:null,refusal:s.refusal}}let u=[];n.forEach((h,m)=>{let b=p.get(m);b?u.push(b):(!c[m]||!Zc(s,h))&&u.push(h);});let f=[...i].filter(h=>s.nodes.get(h)?.paragraph).map(h=>({id:h,after:ht(s.toTree(h))}));return {passThrough:u,plan:{paragraphs:f,embedsBefore:l}}}function Gc(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 p=t.nodes.get(c);return p?p.block||p.kind==="paragraphProperties":n.kindOf(c)==="paragraphProperties"},i=o.children.filter(c=>t.nodes.get(c)?.parent===o.id),s=o.children.slice(e.start,e.start+e.deleteCount).filter(c=>t.nodes.get(c)?.block).length,l=e.childLogicalIds.filter(r);if(s===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:s,childLogicalIds:l}}function qc(t,e,n){switch(e.kind){case "putNode":{let{descriptor:o}=e;if(v(o.logicalId))return t.refuse("invalid-logical-id",o.logicalId);if(o.kind!=="textValue"&&(v(o.qname.localName)||o.qname.prefix!==void 0&&v(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 a=t.placeholder(o.logicalId,"textValue");a.opaque=false,a.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(v(e.qname.localName)||e.qname.prefix!==void 0&&v(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(v(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 s of e.childLogicalIds){let l=t.nodes.get(s);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(s=>v(s));if(r!==void 0)return t.refuse("invalid-logical-id",r);let i=o.children.splice(e.start,e.deleteCount);for(let s of i){let l=t.nodes.get(s);l?.parent===o.id&&(l.parent=null);}let a=[];for(let s of e.childLogicalIds){let l=n.kindOf(s);if(!t.nodes.has(s)&&(l===null||!n.hasNode(s)))return t.refuse("unknown-logical-id",s);let d=t.nodes.get(s)??t.placeholder(s,l);d.parent=o.id,d.outside=false,o.paragraph&&d.kind==="paragraphProperties"&&(d.block=true),a.push(s);}return o.children.splice(e.start,0,...a),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 a=t.nodes.get(e.logicalId)??t.placeholder(e.logicalId,i);if(t.detach(e.logicalId),a.outside=!o,o){let s=t.nodes.get(e.destinationParentLogicalId);a.parent=s.id,s.children.splice(Math.max(0,Math.min(e.destinationIndex,s.children.length)),0,e.logicalId);}return o}default:return false}}function Zc(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 a=t.detachedRoot(o);return !a.outside&&(a.kind==="textValue"||As(a))};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 Qc(t,e){let n=t.record(e);return !n||!("childIds"in n)?true:n.childIds.some(o=>t.kindOf(o)==="run")}function eu(t,e){let n=new Set,o=new Set(e),r=i=>i.some(a=>o.delete(N(a))||a.kind!=="textValue"&&r(a.children));return t.schema.nodes.forEach((i,a)=>{if(o.size===0)return;let s=V(a),l=t.inline.textOf(s);if(!l||t.inline.isDeletedParagraph(s))return;let d=t.inline.viewOf(s);r(Ce(s,l,()=>null,t.limits,d))&&n.add(s);}),n}var nu=new Set(["proofErr","permStart","permEnd"]);function sr(t,e,n){return t==="bookmarkStart"||t==="bookmarkEnd"||isRangeMarkerKind(t)?true:t==="generic"&&n&&nu.has(e)}var ou=Ge(WML_NAMESPACE_URI);function ar(t){if(!M(t))return false;let e=Re(t);return sr(e.kind,e.localName,e.namespaceId===ou)}function Ns(t){return ar(t)?Qe(t):null}function Ps(t){let e=n=>t.find(o=>o.namespaceUri===WML_NAMESPACE_URI&&o.localName===n)?.value??null;return [e("id"),e("name")]}function ru(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 Ms(t,e,n,o,r){if(n.size===0||e.length===0)return;let i=new Map;for(let s of e){let l=t.record(s);if(!l||!j(l)||l.childIds.length>0||!sr(l.kind,l.localName,l.namespaceUri===WML_NAMESPACE_URI))continue;let d=JSON.stringify([l.kind,l.localName,...Ps(l.attributes)]),c=i.get(d)??[];c.push(s),i.set(d,c);}if(i.size===0)return;let a=ru(r);for(let s of n){if(!o.has(s))continue;let l=a.get(s);if(!l||!sr(l.kind,l.localName,l.namespaceUri===WML_NAMESPACE_URI))continue;let d=JSON.stringify([l.kind,l.localName,...Ps(l.attributes)]),c=i.get(d)?.shift();if(c===void 0)continue;let p=t.schema.nodes.get(s);if(!M(p))continue;let u=t.splitLineageOf(c)??c;p.set(_t,u),p.set(Xe,u);}}var Jt="o",iu=/^(\^?)(\d{1,16}:\d{1,16})$/,tt="-";function _s(t){if(t===tt)return {identity:tt,before:false};let e=typeof t=="string"?iu.exec(t):null;return e?{identity:e[2],before:e[1]==="^"}:null}function dr(t,e,n,o,r){let i={...o};delete i[Jt];let a=dt(t,e,n,i);a&&me(t.doc).markCopy("move",a.id.client,a.id.clock,n.length,r);}function Ds(t,e,n){let o=[],r=[],i="",a=()=>{r.length>0&&o.push({paragraph:e,indexes:r,value:i}),r=[],i="";};for(let s of t.steps){if(s.op!==n){s.op!==(n==="del"?"ins":"del")&&a();continue}let l=s.op==="del"?s.before:s.after,d=s.op==="del"?t.before[l]:t.after[l];if(typeof d.insert!="string"){a();continue}r.push(l),i+=d.insert;}return a(),o}function su(t,e){let n=e.from+e.length;return (e.from===0||t[e.from-1])&&(n===t.length||t[n])}var au=1<<20,lu=1<<24;function lr(t,e,n,o,r,i,a=false){let s=e(t),l=o.get(t),d=null;for(let c of n){if(c.paragraph===t.paragraph!==a||!r(c.paragraph,t.paragraph))continue;let p=e(c),u=o.get(c),f=p.length*s.length;if(f>au)continue;if(f>i.cells)return d;i.cells-=f;let h=new Uint32Array(s.length+1);for(let m=1;m<=p.length;m+=1){let b=new Uint32Array(s.length+1);for(let w=1;w<=s.length;w+=1){if(u[m-1]||l[w-1]||p[m-1]!==s[w-1])continue;let E=h[w-1]+1;b[w]=E,E>(d?.length??0)&&(d={source:c,from:m-E,to:w-E,length:E});}h=b;}}return d}function Ys(t,e,n,o=()=>"",r=()=>""){let i=new Set,a=t.flatMap((I,g)=>Ds(I,g,"del"));if(a.length===0)return i;let s=t.flatMap((I,g)=>Ds(I,g,"ins")),l=new Set(a),d={cells:lu},c=new Map,p=I=>g=>{let S=l.has(g),R=`${I}:${g.paragraph}:${g.indexes[0]}:${S}`,P=c.get(R);if(!P){let Y=t[g.paragraph];P=g.indexes.map(z=>{let X=S?Y.before[z]:Y.after[z],J=X.insert;return I?`${J}\0${o(X,g.paragraph)}`:J}),c.set(R,P);}return P},u=new Map;for(let I of [...a,...s])u.set(I,I.indexes.map(()=>false));let f=t.map((I,g)=>r(g)),h=(I,g)=>f[I]===""||f[g]===""||f[I]===f[g],m=(I,g)=>{for(let S=0;S<g.length;S+=1)u.get(g.source)[g.from+S]=true,u.get(I)[g.to+S]=true;du(t,I,g,e,n,i);};for(let I of s){let g=a.find(S=>S.paragraph!==I.paragraph&&h(S.paragraph,I.paragraph)&&S.value===I.value&&!u.get(S).some(Boolean));g&&m(I,{source:g,from:0,to:0,length:I.indexes.length});}for(let I of s)for(let g=lr(I,p(true),a,u,h,d);g;)m(I,g),g=lr(I,p(true),a,u,h,d);let b=new Map;for(let I of s)b.set(I.paragraph,[...b.get(I.paragraph)??[],I]);let w=new Set(a.filter(I=>(b.get(I.paragraph)??[]).some(g=>g.value.includes(I.value)))),E=a.filter(I=>!w.has(I)),y=(I,g,S)=>{for(;;){let R=lr(g,p(false),I,u,h,d,S);if(!R||!su(u.get(R.source),R))break;m(g,R);}};for(let I of s)y(E,I,false);let k=new Map;for(let I of w)k.set(I.paragraph,[...k.get(I.paragraph)??[],I]);for(let I of s){let g=k.get(I.paragraph);g&&y(g,I,true);}return i}function du(t,e,n,o,r,i){let a=t[n.source.paragraph],s=c=>{let p=a.before[n.source.indexes[n.from+c]];return p?.position===void 0?null:a.identities[p.position]??null},l=t[e.paragraph],d=null;for(let c=0;c<n.length;c+=1){let p=e.indexes[n.to+c],u=s(c);u&&i.add(u);let f=c>0?l.after[e.indexes[n.to+c-1]]:null,h=f!==null&&r(f)===r(l.after[p]);(!d||!h||!ut(s(c-1),u))&&(d=u),d&&(l.after[p]=o(l.after[p],d));}}var cu="docx-text-marks-v1",uu={move:"o",restore:"u",follow:"f"},Ws=/^([ouf])(\d{1,16}):(\d{1,16})$/,pu=/^(\d{1,16}):(\d{1,16}):(\d{1,16})$/,fu=/^(\d{1,16})\|(.{1,40})$/,ur=16,Bs=1<<20,Us=4096;function Fs(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 js(t,e,n){return `${uu[t]}${e}:${n}`}function ke(t){let e=Number(t);return Number.isSafeInteger(e)?e:null}function hu(t,e){let n=Ws.exec(t);if(!n||typeof e!="string")return null;let o=n[1]==="o"?"move":n[1]==="u"?"restore":"follow",r=ke(n[2]),i=ke(n[3]);if(r===null||i===null)return null;if(o==="follow"){let p=fu.exec(e),u=p?ke(p[1]):null,f=p?_s(p[2]):null;return u===null||u<1||u>Bs||!f?null:{kind:o,client:r,span:{key:t,client:r,firstClock:i,length:u,origin:null,follow:f}}}let a=pu.exec(e),s=a?ke(a[1]):null,l=a?ke(a[2]):null,d=a?ke(a[3]):null;return s===null||l===null||d===null||d<1||d>Bs?null:{kind:o,client:r,span:{key:t,client:r,firstClock:i,length:d,origin:{client:s,clock:l,insertClient:r,firstClock:i,length:d},follow:null}}}var mu={origin:()=>null,follow:()=>null},cr=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(js(e,n,o),`${i}:${r}`);}markFollow(e,n,o,r){this.write(js("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 a=this.byKey.get(r)?.span.length??0,s=Ws.exec(r),l=s?ke(s[2]):null,d=s?ke(s[3]):null;l===null||d===null||n.push({client:l,from:d,to:d+Math.max(i,a,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 s of r)for(let l of this.textsOfClient(s))n.add(l);return n},a=e;for(let s=0;s<=ur&&a.length>0;s+=1){let l=[];for(let d of a)r.add(d.client);for(let d of a){let c=`${d.client}:${d.from}:${d.to}`;if(!o.has(c)){if(o.size>=Us)return this.withDependents(r,i);o.add(c);for(let p=d.from,u=0;p<d.to;u+=1){if(u>=Us)return this.withDependents(r,i);let f=ce(this.doc,{client:d.client,clock:p});if(!f)break;f.parent instanceof B.Text&&n.add(f.parent),p=f.id.clock+f.length;}for(let p of this.dependents.get(d.client)??[]){let u=gu(p,d);u&&l.push(u);}}}a=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 a=i instanceof B.Item?i.parent:null;a instanceof B.Text&&r.add(a);}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=hu(e,n);if(!o)return;let r=Me(this.map,e);if(r&&r.id.client!==o.client)return;let i=this.spans[o.kind].get(o.client)??[];i.splice(Fs(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 a=zs(o.span);if(a!==null){let s=this.dependents.get(a)??new Set;s.add(o.span),this.dependents.set(a,s);}}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=Fs(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=zs(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,a=r.length-1,s=null;for(;i<=a;){let l=i+a>>1,d=r[l];d.firstClock<=o?(s=d,i=l+1):a=l-1;}return s&&o<s.firstClock+s.length?s:null}};function zs(t){if(t.origin)return t.origin.client;let e=t.follow?.identity,n=e?.indexOf(":")??-1;return n>0?ke(e.slice(0,n)):null}function gu(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 a=t.firstClock-t.origin.clock;return {client:t.client,from:r+a,to:i+a}}let n=t.follow.identity,o=ke(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 $s=new WeakMap;function me(t){let e=$s.get(t);if(e)return e;let n=t.getMap(cu),o=new cr(t,n);return t.on("beforeObserverCalls",r=>{let i=rn(r,n);i&&o.refreshKeys(i);}),$s.set(t,o),e=o,e}function Cn(t){return t.doc?me(t.doc):mu}var hr="docx-text-deletions-v1",yu=/^d(\d{1,16}):(\d{1,16})$/,bu=/^(\d{1,16}):(\d{1,16}):(\d{1,16})$/,pr=4096,Iu=1<<20;function Tn(t){let e=Number(t);return Number.isSafeInteger(e)?e:null}function xu(t,e){let n=yu.exec(t);if(!n||typeof e!="string")return null;let o=Tn(n[1]);if(o===null)return null;let r=[];for(let i of e.split(";")){if(r.length>=pr)return null;let a=bu.exec(i);if(!a)return null;let s=Tn(a[1]),l=Tn(a[2]),d=Tn(a[3]);if(s===null||l===null||d===null||d<1||d>Iu)return null;r.push({client:s,from:l,to:l+d});}return r.length===0?null:{client:o,runs:r}}var An=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 a=n.ends.length-1;a>=0&&r<=n.ends[a]?n.ends[a]=Math.max(n.ends[a],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,a=e,s=n;for(;i<this.starts.length&&this.starts[i]<=n;)a=Math.min(a,this.starts[i]),s=Math.max(s,this.ends[i]),i+=1;this.starts.splice(o,i-o,a),this.ends.splice(o,i-o,s);}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}},fr=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+=pr){let r=e.slice(o,o+pr).map(a=>`${a.client}:${a.from}:${a.to-a.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 a of r)n.push(a);for(let a of i)n.push(a);}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=xu(e,n),i=r?Me(this.map,e):void 0,a=r!==null&&(!i||i.id.client===r.client);if(a&&this.byKey.set(e,r.runs),o){let s=new Set(o.map(l=>l.client));for(let l of s)this.keysByClient.get(l)?.delete(e);a&&this.list(e,r.runs);for(let l of a?r.runs:[])s.add(l.client);for(let l of s)this.stale.add(l);}else if(a){this.list(e,r.runs);for(let s of r.runs){if(this.stale.has(s.client))continue;let l=this.characters.get(s.client);l||this.characters.set(s.client,l=new An),l.add(s.from,s.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,An.of(o));}},Vs=new WeakMap;function Te(t){let e=Vs.get(t);if(e)return e;let n=t.getMap(hr),o=new fr(t,n);return t.on("beforeObserverCalls",r=>{let i=rn(r,n);i&&o.refreshKeys(i);}),Vs.set(t,o),e=o,e}function oa(t,e,n){let o=[],r=0;for(let i of t.toDelta()){let a=i.attributes??{},s=n?qo(a,n.limits,n.paragraphId):"";if(typeof i.insert=="string"){let l=mr(a);for(let d=0;d<i.insert.length;d+=1,r+=1){if(e?.has(r))continue;let c=`c${i.insert[d]}`;o.push({key:c,strong:`${c}\0${l}`,insert:i.insert[d],attributes:a,position:r,trail:s});}}else {if(r+=1,e?.has(r-1))continue;let l=i.insert,d=typeof l.n=="string"?`e${l.r===1?"r":""}${l.n}`:ra(a,s);o.push({key:d,strong:d,insert:l,attributes:a,position:r-1,trail:s});}}return o}function Pn(t,e){let n=t.id,o=new Map;return yn(t).items.map(r=>{let i=o.get(r.attributes);if(!i){let d=et(r.attributes,n,e);i={attributes:d,trail:qo(d,e,n)},o.set(r.attributes,i);}let{attributes:a,trail:s}=i;if(r.kind==="char"){let d=`c${r.value}`,c=`${d}\0${mr(a)}`;return {key:d,strong:c,insert:r.value,attributes:a,trail:s}}if(r.kind==="embed"){let d=er(r),c=`e${"r"in d?"r":""}${r.node.id}`;return {key:c,strong:c,insert:d,attributes:a,trail:s}}let l=ra(a,s);return {key:l,strong:l,insert:{a:1},attributes:a,trail:s}})}var Su=1<<20;function ra(t,e){return `a${re(Ho(t))}${e}`}function mr(t){return t.t??""}function ia(t,e,n=true){let o=Hs(t),r=Hs(e);if(o===null&&r===null)return Gs(t,e,n);let i=o?.starts??null,a=r?.starts??null,s=(d,c,p)=>{if(d===null)return [c];let u=d[c];return (c+1<d.length?d[c+1]:p)-u===2?[u,u+1]:[u]},l=[];for(let d of Gs(o?.tokens??t,r?.tokens??e,n))if(d.op==="del")for(let c of s(i,d.before,t.length))l.push({op:"del",before:c});else if(d.op==="ins")for(let c of s(a,d.after,e.length))l.push({op:"ins",after:c});else {let c=s(i,d.before,t.length),p=s(a,d.after,e.length);c.forEach((u,f)=>l.push({op:"eq",before:u,after:p[f]}));}return l}var Js=t=>{if(t===void 0||typeof t.insert!="string")return false;let e=t.insert.charCodeAt(0);return e>=55296&&e<=56319},Xs=t=>{if(t===void 0||typeof t.insert!="string")return false;let e=t.insert.charCodeAt(0);return e>=56320&&e<=57343};function Hs(t){let e=false;for(let r=0;r+1<t.length&&!e;r+=1)e=Js(t[r])&&Xs(t[r+1]);if(!e)return null;let n=[],o=[];for(let r=0;r<t.length;r+=1){let i=t[r],a=t[r+1];o.push(r);let s=a!==void 0&&(i.position===void 0||a.position===i.position+1);if(Js(i)&&Xs(a)&&s){let l=`${i.insert}${a.insert}`,d=`c${l}`;n.push({...i,key:d,strong:`${d}\0${mr(i.attributes)}`,insert:l}),r+=1;}else n.push(i);}return {tokens:n,starts:o}}function Gs(t,e,n){let o=n?wu(t,e):null;if(o)return o;let r=Qs(t,e,na(t,e,false)),i=Qs(t,e,na(t,e,true)),[a,s]=[Zs(r),Zs(i)],l=s!==a?s>a?i:r:qs(i)<qs(r)?i:r;return Lu(Ru(l,e),t)}function wu(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],a=e[o+n-1],s=o>0?t[o-1]:null;if(s&&s.key===a.key&&s.strong!==a.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 ku(t){if(!ae(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 vu=16;function Lu(t,e){for(let n=0;n<vu;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,d)=>l!==void 0&&l.some(c=>{if(c.op!=="del")return false;let p=e[c.before];return !Tu(p)&&d.has(p.trail??"")}),a=false,s=[];if(o.forEach((l,d)=>{let c=new Set(l.map(u=>u.op==="eq"?e[u.before].trail??"":""));if(!(l[0].op==="eq"&&l.length<=r(o[d-1])&&l.length<=r(o[d+1])&&(i(o[d-1],c)||i(o[d+1],c))&&l.every(u=>u.op==="eq"&&ku(e[u.before])))){for(let u of l)s.push(u);return}a=true;for(let u of l)u.op==="eq"&&s.push({op:"del",before:u.before});for(let u of l)u.op==="eq"&&s.push({op:"ins",after:u.after});}),t=s,!a)break}return t}function Ru(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 qs(t){let e=0,n=false;for(let o of t)o.op!=="eq"&&!n&&(e+=1),n=o.op!=="eq";return e}function ae(t){return t.key.startsWith("c")}function Ou(t,e,n,o,r,i){let a=e,s=r,l=0;for(;;){for(;a<n&&!ae(t[a]);)a+=1;for(;s<i&&!ae(o[s]);)s+=1;if(a===n||s===i)return a===n&&s===i&&l>0;if(t[a].key!==o[s].key)return false;l+=1,a+=1,s+=1;}}var Eu=/"l":"del(Text|InstrText)"/,Cu=/\\"l\\":\\"(del|moveFrom)\\"/;function Tu(t){let e=t.attributes.t;return typeof e=="string"&&Eu.test(e)?true:t.trail!==void 0&&Cu.test(t.trail)}function Zs(t){let e=0;for(let n of t)n.op==="eq"&&(e+=1);return e}function Qs(t,e,n){let o=[],r=0,i=0;for(let[a,s]of [...n,[t.length,e.length]]){let l=ea(t,e,r,a,i,s,false),d=ta(l,t,e);if(d.inRevision<d.equal){let f=ea(t,e,r,a,i,s,true),h=ta(f,t,e);h.equal>=d.equal&&h.inRevision>d.inRevision&&(l=f);}for(let f of l.head)o.push(f);let c=l.tail;({i:r,j:i}=l);let{bEnd:p,aEnd:u}=l;if(Ou(t,r,p,e,i,u))for(;r<p||i<u;)r<p&&i<u&&ae(t[r])&&ae(e[i])?(o.push({op:"eq",before:r,after:i}),r+=1,i+=1):r<p&&!ae(t[r])?(o.push({op:"del",before:r}),r+=1):(o.push({op:"ins",after:i}),i+=1);for(;r<p;r+=1)o.push({op:"del",before:r});for(;i<u;i+=1)o.push({op:"ins",after:i});for(let f of c)o.push(f);r=a,i=s,r<t.length&&i<e.length&&(o.push({op:"eq",before:r,after:i}),r+=1,i+=1);}return o}function ea(t,e,n,o,r,i,a){let s=[],l=[],d=()=>{for(;;)if(n<o&&r<i&&t[n].key===e[r].key)s.push({op:"eq",before:n,after:r}),n+=1,r+=1;else if(n<o&&r<i&&!ae(t[n])&&ae(e[r]))s.push({op:"del",before:n}),n+=1;else if(n<o&&r<i&&ae(t[n])&&!ae(e[r]))s.push({op:"ins",after:r}),r+=1;else break},c=()=>{for(;;)if(o>n&&i>r&&t[o-1].key===e[i-1].key)o-=1,i-=1,l.unshift({op:"eq",before:o,after:i});else if(o>n&&i>r&&!ae(t[o-1])&&ae(e[i-1]))o-=1,l.unshift({op:"del",before:o});else if(o>n&&i>r&&ae(t[o-1])&&!ae(e[i-1]))i-=1,l.unshift({op:"ins",after:i});else break};return a?(c(),d()):(d(),c()),{head:s,tail:l,i:n,j:r,bEnd:o,aEnd:i}}function ta(t,e,n){let o=0,r=0;for(let i of [t.head,t.tail])for(let a of i)a.op==="eq"&&(o+=1,(e[a.before].trail??"")===(n[a.after].trail??"")&&(r+=1));return {equal:o,inRevision:r}}function na(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,a=e.length,s=[];for(;i>r&&a>r&&t[i-1].strong===e[a-1].strong;)i-=1,a-=1,s.unshift([i,a]);let l=i-r,d=a-r;if(l>0&&d>0&&l*d<=Su){let c=d+1,p=new Uint32Array((l+1)*c),u=(m,b)=>t[r+m].strong===e[r+b].strong;for(let m=l-1;m>=0;m-=1)for(let b=d-1;b>=0;b-=1)p[m*c+b]=u(m,b)?p[(m+1)*c+b+1]+1:Math.max(p[(m+1)*c+b],p[m*c+b+1]);let f=0,h=0;for(;f<l&&h<d;)if(u(f,h))o.push([r+f,r+h]),f+=1,h+=1;else {let m=p[(f+1)*c+h],b=p[f*c+h+1];m>b||m===b&&!n?f+=1:h+=1;}}for(let c of s)o.push(c);return o}function sa(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 yr=64;function aa(t,e,n){for(let o=0;o<ur;o+=1){let r=t.origin("move",e,n)??t.origin("restore",e,n);if(!r)break;let i=r.client,a=r.clock+n-r.firstClock;if(i===e&&a===n)break;e=i,n=a;}return [e,n]}function Au(t,e){let n=ye(e);return n?br(t,n.client,n.clock):e}function br(t,e,n){let[o,r]=aa(t,e,n);return `${o}:${r}`}function la(t,e,n){return br(Cn(t),e.id.client,e.id.clock+n)}function gr(t,e){return e===t.id.clock?t.origin:{client:t.id.client,clock:e-1}}function Pu(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 a=0;i&&a<yr;a+=1){let s=ce(t,i);if(!s)break;if(!s.deleted){if(s.content instanceof B.ContentFormat){i=gr(s,i.clock);continue}return {live:n(s,i.clock),deleted:o}}let l=n(s,i.clock);l&&o.push(l),i=gr(s,i.clock);}return {live:null,deleted:o}}function Nu(t,e,n){let o=e.rightOrigin;for(let r=0;o&&r<yr;r+=1){let i=ce(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 da(t,e,n){return e.deleted||e.content instanceof B.ContentString?br(t,e.id.client,n):null}function ge(t,e){return t.moved[e]===true||t.restored[e]===true}function ot(t){let e=tn(t),n=Cn(t),o=[],r=[],i=[],a=[],s=[],l=[],d=[],c=[],p=t.doc?Te(t.doc):null,u=[],f=[],h=[],m=[],b=false,w=t.doc,E=(y,k)=>da(n,y,k);for(let y=e;y;y=y.right){if(y.deleted||!y.countable)continue;let k=y.content instanceof B.ContentString,I=k||y.content instanceof B.ContentEmbed,g=D=>k&&n.origin("move",y.id.client,D)!==null,S=D=>k&&!g(D)&&n.origin("restore",y.id.client,D)!==null,R=g(y.id.clock)||S(y.id.clock),P=I?n.follow(y.id.client,y.id.clock):null,Y=P&&P.identity!==tt?{...P,identity:Au(n,P.identity)}:P,z=w?Pu(w,y,E):{live:null,deleted:[]},X=null;if(I&&!R&&Y&&(z.deleted.length>0||z.live===null)?X=[Y]:I&&!R&&z.deleted.length>0&&(X=z.deleted.map(D=>({identity:D,before:false}))),X&&(b=true),I&&!R&&!P&&z.live===null&&w){let D=Nu(w,y,E);D&&(X=[...X??[],{identity:D,before:true}]);}let J=R?[...z.deleted,...z.live===null?[]:[z.live]]:null;for(let D=0;D<y.length;D+=1){if(a.push(`${y.id.client}:${y.id.clock+D}`),s.push(D>0?`${y.id.client}:${y.id.clock+D-1}`:y.origin?`${y.origin.client}:${y.origin.clock}`:null),k){let[x,O]=aa(n,y.id.client,y.id.clock+D);o.push(`${x}:${O}`),r.push(x),i.push(O);}else o.push(null),r.push(-1),i.push(-1);l.push(g(y.id.clock+D));let W=S(y.id.clock+D);d.push(W),c.push(k&&p!==null&&p.isDeleted(r[r.length-1],i[i.length-1])),f.push(D===0),h.push(D===0?z.live:null),m.push(D===0?J:null),u.push(D===0?X:null);}}return {ids:o,clients:r,clocks:i,items:a,origins:s,moved:l,restored:d,deleted:c,anchors:u,hasAnchors:b,starts:f,lefts:h,copiedAfter:m}}function Ir(t,e,n){let o=t.doc;if(!o)return false;let r=Cn(t),i=e.origin;for(let a=0;i&&a<yr;a+=1){let s=ce(o,i);if(!s)return false;let l=da(r,s,i.clock);if(l!==null&&n(l))return true;i=gr(s,i.clock);}return false}function Mu(t){for(let e of Object.keys(t))if(e.startsWith(we)&&t[e]===null)return true;return false}function ca(t,e,n,o,r){let i=new Array(e.length).fill(null),a=false;for(let l of o){if(l.op==="del"&&(i[l.before]="del"),l.op!=="eq")continue;let d=r(e[l.before].attributes,n[l.after].attributes);!d||!Mu(d)||(i[l.before]=d,a=true);}if(!a)return;let s=0;for(;s<i.length;){if(i[s]!=="del"){s+=1;continue}let l=s;for(;l<i.length&&i[l]==="del";)l+=1;let d=s>0?i[s-1]:null,c=l<i.length?i[l]:null,p=d&&d!=="del"?d:c&&c!=="del"?c:null;if(p){let u={...p};for(let h=s;h<l;h+=1)for(let m of Object.keys(e[h].attributes))(m.startsWith(we)||m===se)&&(u[m]=null);let f=s;for(let h=s+1;h<=l;h+=1){if(h<l&&e[h].position===e[h-1].position+1)continue;let m=e[f].position;t.format(m,e[h-1].position-m+1,u),f=h;}}s=l;}}function wr(t){let e=[],n=null;return t.ids.forEach((o,r)=>{if(o===null||t.deleted[r])return;let i=t.clients[r],a=t.clocks[r],s=t.moved[r]?"move":t.restored[r]?"restore":"original";if(n&&n.client===i&&n.end===a&&n.kind===s){n.end+=1;return}n&&e.push(n),n={client:i,start:a,end:a+1,kind:s};}),n&&e.push(n),e}var xr=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=ua(e.run.end-e.run.start),o=this.classes.get(n);o||this.classes.set(n,o=new xr(2**(n+1))),o.add(e);}remove(e){let n=ua(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 ua(t){return t<=1?0:31-Math.clz32(t)}var Xt=class{runsOf=new Map;tables={original:new Map,move:new Map,restore:new Map};update(e,n){let o=this.runsOf.get(e)??[],r=p=>`${p.client}:${p.start}:${p.end}:${p.kind}`,i=p=>{let u=new Map;for(let f of p){let h=u.get(r(f));h?h.push(f):u.set(r(f),[f]);}return u},a=i(o),s=i(n),l=new Set,d=[],c=p=>{for(let u of Object.values(this.tables))for(let f of u.get(p.client)?.overlapping(p.start,p.end)??[])f.paragraph!==e&&l.add(f.paragraph);};for(let[p,u]of a)for(let f of u.slice(s.get(p)?.length??0))this.tables[f.kind].get(f.client)?.remove({run:f,paragraph:e}),d.push(f),f.kind!=="original"&&c(f);for(let[p,u]of s)for(let f of u.slice(a.get(p)?.length??0)){let h=this.tables[f.kind],m=h.get(f.client);m||(m=new Sr,h.set(f.client,m)),m.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 a=false;for(let s of ["move","restore"])for(let l of this.overlapping(s,i.client,i.start,i.end))l.paragraph!==o&&(a=true,e.add(o),e.add(l.paragraph));a&&n.push(i);}return {paragraphs:e,runs:n}}clear(){this.runsOf.clear();for(let e of Object.values(this.tables))e.clear();}};var pa=new Set,Du=64;function fa(t){let e=new Set;return t.ids.forEach((n,o)=>{n!==null&&ge(t,o)&&e.add(n);}),e}function _u(t){let e=wr(t).map(o=>({...o,kind:"original"})),n=o=>{let r=ye(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 kr(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 Yu(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 a=[];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 p=l;p<r.length&&!n.has(p);p+=1)c.push(p);a.push({source:t,after:d,before:false,positions:c,identities:c.map(p=>r[p]??null),items:c.map(p=>e.items[p])}),l+=c.length;}let s=new Set;for(let l of a)for(let d of l.positions)s.add(d);for(let l=0;l<r.length;l+=1){if(!e.starts[l]||n.has(l)||s.has(l))continue;let d=e.anchors[l]?.find(u=>u.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 p=[];for(let u=l;u<c;u+=1)p.push(u);for(let u of p)s.add(u);a.push({source:t,after:d.identity,before:true,positions:p,identities:p.map(u=>r[u]??null),items:p.map(u=>e.items[u])});}for(let l of a)for(let d of l.positions)n.add(d);return a}var Nn=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 Xt;sources=new Set;outgoingOf=new Map;incomingOf=new Map;targetsOf=new Map;dependencies=new Xt;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:a}=this.index.update(e,r&&!o?wr(r):[]),s=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 a)for(let c of this.dependencies.overlapping("original",d.client,d.start,d.end))this.pending.add(c.paragraph);(s||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,a=new Set,{clients:s,clocks:l}=o,d=fa(o);for(let f=0;f<s.length;){let h=f+1;for(;h<s.length&&s[h]===s[f]&&l[h]===l[h-1]+1&&o.moved[h]===o.moved[f]&&o.restored[h]===o.restored[f];)h+=1;let m=s[f],b=ge(o,f);if(m>=0){let w=k=>this.index.overlapping(k,m,l[f],l[h-1]+1).filter(I=>I.paragraph!==e),E=w("move"),y=w("restore");if(E.length>0||y.length>0||b){let k=l[f],I=this.coverage(E,k,h-f,e),g=this.coverage(y,k,h-f,e);for(let S=f;S<h;S+=1){let R=S-f,P={move:I.any[R]>0,laterMove:I.later[R]>0,restore:g.any[R]>0,laterRestore:g.later[R]>0};this.hides(o,S,P,i,a)&&r.add(S);}}if(!b&&d.size>0)for(let k=f;k<h;k+=1)d.has(o.ids[k])&&r.add(k);}f=h;}let c=this.outgoingOf.get(e);if(c)for(let f of kr(c,o))r.add(f);o.deleted.forEach((f,h)=>{f&&r.add(h);});let p=Yu(e,o,r,a),u=this.distinctIncoming(e,o,r);return {identities:o,hidden:r,incoming:p.length>0?[...u,...p]:u}}distinctIncoming(e,n,o){let r=this.incomingOf.get(e)??[];if(r.length===0)return r;let i=new Set;n.ids.forEach((s,l)=>{s!==null&&!o.has(l)&&i.add(s);});let a=[];for(let s of r){let l=s.positions.flatMap((d,c)=>{let p=s.identities[c]??null;return p!==null&&i.has(p)?[]:(p!==null&&i.add(p),[c])});l.length===s.positions.length?a.push(s):l.length>0&&a.push({...s,positions:l.map(d=>s.positions[d]),identities:l.map(d=>s.identities[d]??null),items:l.map(d=>s.items[d])});}return a}hides(e,n,o,r,i){let a=e.ids[n],s=false;return ge(e,n)&&r.has(a)&&i.add(n),e.moved[n]?s=r.has(a)||o.laterMove:e.restored[n]?s=r.has(a)||o.move||o.laterRestore:s=o.move||o.restore,ge(e,n)&&r.add(a),s}coverage(e,n,o,r){let i=new Int32Array(o+1),a=new Int32Array(o+1);for(let s of e){let l=Math.max(s.run.start,n)-n,d=Math.min(s.run.end,n+o)-n;l>=d||(i[l]+=1,i[d]-=1,this.order(s.paragraph,r)>0&&(a[l]+=1,a[d]-=1));}for(let s=1;s<=o;s+=1)i[s]+=i[s-1],a[s]+=a[s-1];return {any:i,later:a}}holdersOf(e){let n=ye(e);return n?this.index.holders(n.client,n.clock):[]}holdsCopyIn(e,n,o){return this.index.hasCopies(e)?this.index.overlapping("move",e,n,o).length>0||this.index.overlapping("restore",e,n,o).length>0:false}shownCopy(e){let n=ye(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)??pa}placedTargetsFor(e){return this.targetsOf.get(e)??pa}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=ot(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<=Du))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 s of e)for(let l of this.targetsOf.get(s)??[])n.add(l);let o=new Map;for(let s of n)o.set(s,JSON.stringify(this.incomingOf.get(s)??[]));let r=new Map;for(let s of e)r.set(s,JSON.stringify(this.outgoingOf.get(s)?.positions??[]));let i=new Set(e);for(let s of n){let l=(this.incomingOf.get(s)??[]).filter(d=>!i.has(d.source));l.length>0?this.incomingOf.set(s,l):this.incomingOf.delete(s);}for(let s of e){this.targetsOf.delete(s),this.outgoingOf.delete(s);let l=this.sources.has(s)?this.textOf(s):null,d=l?this.identitiesOf(s,l):null;if(this.dependencies.update(s,d?_u(d):[]),!d)continue;let c=new Map;for(let p of this.followingOf(s,d)){let u=p.target??this.shownCopy(p.after),f=this.incomingOf.get(u)??[];f.push(p),this.incomingOf.set(u,f);let h=this.targetsOf.get(s)??new Set;h.add(u),this.targetsOf.set(s,h),p.positions.forEach((m,b)=>{c.set(m,p.identities[b]??null);}),o.has(u)||o.set(u,"[]");}if(c.size>0&&!this.isDeleted(s)){let p=[...c.keys()].sort((u,f)=>u-f);this.outgoingOf.set(s,{positions:p,identities:p.map(u=>c.get(u)??null),items:p.map(u=>d.items[u])});}}for(let s of o.keys())this.incomingOf.get(s)?.sort((l,d)=>(l.source<d.source?-1:l.source>d.source?1:0)||l.positions[0]-d.positions[0]);let a=new Set;for(let[s,l]of r)JSON.stringify(this.outgoingOf.get(s)?.positions??[])!==l&&a.add(s);for(let[s,l]of o)JSON.stringify(this.incomingOf.get(s)??[])!==l&&a.add(s);return a}followingOf(e,n){let o=[],r=null,i=fa(n);for(let a=0;a<n.ids.length;a+=1){let s=n.ids[a]??null,l=ge(n,a);if(n.deleted[a]||s!==null&&(this.shownCopy(s)!==null||!l&&i.has(s))){r=null;continue}let d=!this.isDeleted(e),c=r!==null&&(!n.starts[a]||a>0&&n.lefts[a]===n.ids[a-1]),p=n.anchors[a]?.find(u=>this.leadsOut(e,d,u))??(d||c?void 0:this.movedAfter(e,n,a));if(p){r={source:e,after:p.identity,before:p.before,...p.target?{target:p.target}:{},positions:[a],identities:[s],items:[n.items[a]]},o.push(r);continue}if(r&&c){r.positions.push(a),r.identities.push(s),r.items.push(n.items[a]);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 a of this.typedOf.get(e)??[]){let s=(this.typedAnchored.get(a)??[]).filter(l=>l.source!==e);s.length>0?this.typedAnchored.set(a,s):this.typedAnchored.delete(a);}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((a,s)=>{if(o.starts[s]&&(i=o.anchors[s]??null),!a||ge(o,s)||!i)return;let l=this.typedAnchored.get(a)??[];l.push({source:e,anchors:i}),this.typedAnchored.set(a,l),r.add(a);}),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(s=>s.source!==e&&this.follows(s))))return;for(let s of n.copiedAfter[o]??[]){let l=this.shownCopy(s);if(l!==null&&l!==e)return {identity:s,before:false}}if(!n.moved[o])return;let a=this.originalParagraph(r);if(!(a===null||a===e||this.isDeleted(a)))return {identity:r,before:false,target:a}}};function Bu(t,e){let n=[],o=0;for(let r of e){let i=r.op==="eq"?"eq":"change",a=n[n.length-1];a&&a.kind===i?a.steps.push(r):n.push({kind:i,steps:[r],after:o}),r.op==="eq"&&(o=t[r.before].position+1);}return n}function Uu(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 vr(t,e){if(!t)return null;if(e>0){let o=t.ids[e-1];return o&&ge(t,e-1)?o:null}let n=t.ids[0];return n&&ge(t,0)?`^${n}`:null}function Lr(t,e,n,o,r,i){let a=dt(t,e,n,o);!r||!a||!Ir(t,a,i)||me(t.doc).markFollow(a.id.client,a.id.clock,n.length,ha(r,e));}function ha(t,e){return e>0?t.ids[e-1]??tt:t.ids[0]?`^${t.ids[0]}`:tt}function Fu(t,e,n,o,r,i){let a=dt(t,e,n,o);if(!a)return;let s=r??(i&&Ir(t,a,i.hasShownCopy)?ha(i.identities,e):null);s&&me(t.doc).markFollow(a.id.client,a.id.clock,1,s);}function Rr(t,e,n,o,r){let i=dt(t,e,n,o);i&&me(t.doc).markFollow(i.id.client,i.id.clock,n.length,r);}function ma(t){let e=[];for(let n of t.toDelta()){let o=n.attributes??{},r=typeof n.insert=="string"?n.insert.length:1;for(let i=0;i<r;i+=1)e.push(o);}return e}function ju(t,e,n,o,r,i,a){let s=Bu(e,o),l=null,d=u=>u<=0?{}:(l??=ma(t),l[u-1]??{}),c=new Map,p=(u,f)=>{let h=c.get(u);h||c.set(u,h=new Map);let m=h.get(f);if(m===void 0){let b=sa(u,a(u,f,false));m=b&&{changes:b,key:JSON.stringify(b),from:re(u)},h.set(f,m);}return m};ca(t,e,n,o,(u,f)=>p(u,f)?.changes??null);for(let u=s.length-1;u>=0;u-=1){let f=s[u];if(f.kind==="eq"){let I=[];for(let S of f.steps){let R=p(e[S.before].attributes,n[S.after].attributes);R&&I.push({...R,position:e[S.before].position});}let g=[];for(let S of I){let R=g[g.length-1],P=R?.[R.length-1];P&&P.position+1===S.position&&P.from===S.from&&P.key===S.key?R.push(S):g.push([S]);}for(let S=g.length-1;S>=0;S-=1){let R=g[S];t.format(R[0].position,R.length,R[0].changes);}continue}let h=f.steps.filter(I=>I.op==="del").map(I=>e[I.before].position),m=f.steps.filter(I=>I.op==="ins").map(I=>n[I.after]),b=h.length>0?h[0]:f.after,w=vr(r,b),E=0,y=d(b);for(let I of Uu(m,g=>typeof g.insert=="string"?`c${re(g.attributes)}`:`e${E++}`)){let g={...I[0],attributes:a(y,I[0].attributes,true)};if(y=g.attributes,typeof g.insert!="string"){let P=r&&b===(h.length>0?h[0]:f.after)?{identities:r,hasShownCopy:i}:null;Fu(t,b,g.insert,g.attributes,w,P),w=null,b+=1;continue}let S=I.map(P=>P.insert).join(""),R=g.attributes[Jt];R?dr(t,b,S,g.attributes,R):w?Rr(t,b,S,g.attributes,w):b===(h.length>0?h[0]:f.after)?Lr(t,b,S,g.attributes,r,i):t.insert(b,S,{...g.attributes}),w=null,b+=S.length;}let k=b-(h.length>0?h[0]:f.after);for(let I=h.length-1;I>=0;){let g=I;for(;g>0&&h[g-1]+1===h[g];)g-=1;ui(t,h[g]+k,I-g+1),I=g-1;}}}function zu(t,e,n){let r=t.inline.viewOf(e).shown(n);if(r.incoming.length===0)return [];let{ids:i}=r.identities,a=vn(r),s=new Map(r.incoming.map((y,k)=>[y,k])),l=[];for(let[y,k]of a.atPosition)for(let I of [...k.before,...k.after])l.push({following:I,order:s.get(I),at:y});for(let y of a.atEnd)l.push({following:y,order:s.get(y),at:i.length,atEnd:true});let d=(y,k)=>k.at-y.at||(y.atEnd?0:Number(y.following.before))-(k.atEnd?0:Number(k.following.before))||k.order-y.order;l.sort(d);let c=new Map,p=new Set,u=[],f=y=>y-u.filter(k=>k<y).length,h=new Map,m=(y,k)=>{let I=h.get(y);return I||(I={identities:ot(k),delta:k.toDelta()},h.set(y,I)),I},b=(y,k)=>{let I=new Map,g=t.inline.textOf(y.source);if(!g)return {positions:[],landed:I};let{identities:S,delta:R}=m(y.source,g),P=kr(y,S),Y=S.ids,z=new Set(P),X=[],J=0;for(let L of R){let C=typeof L.insert=="string"?L.insert.length:1,U=null,_=()=>U??=et(he(L.attributes,t.limits,y.source),e,t.limits);if(typeof L.insert=="string")for(let T=0;T<C;T+=1)z.has(J+T)&&X.push({kind:"char",value:L.insert[T],attributes:{..._()},identity:Y[J+T]??null,position:J+T});else if(z.has(J)&&L.insert!==null&&typeof L.insert=="object"){let T=pi(g,J);T&&X.push({kind:"embed",embed:L.insert,attributes:{..._()},item:T,position:J});}J+=C;}let D=[];for(let L of X){let C=D[D.length-1],U=C?.[C.length-1];L.kind==="char"&&U?.kind==="char"&&re(U.attributes)===re(L.attributes)&&ut(U.identity,L.identity)?C.push(L):D.push([L]);}let W=k,x=(L,C)=>Go(L>0?ma(n)[L-1]??{}:{},C,true,t.limits,e);for(let L of D){let C=L[0];if(C.kind==="embed"){let T=g===n?fi(n,C.item):null;hi(g,C.item),h.delete(y.source),p.add(y.source),T!==null&&(u.push(T),T<W&&(W-=1)),n.insertEmbed(W,C.embed,{...x(W,C.attributes)}),I.set(C.position,W),W+=1;continue}let U=L.map(T=>T.kind==="char"?T.value:"").join(""),_=x(W,C.attributes);C.identity?dr(n,W,U,_,C.identity):n.insert(W,U,_),L.forEach((T,F)=>I.set(T.position,W+F)),W+=U.length;}h.delete(e);let O=X.flatMap(L=>L.kind==="char"&&L.identity?[L.identity]:[]);return c.set(y.source,[...c.get(y.source)??[],...O]),{positions:P,landed:I}},w=[],E=(y,k)=>{let I=a.inside.get(y);if(!I)return;let g=[];for(let[S,R]of I){let P=k.positions[S],Y=P===void 0?void 0:k.landed.get(P);for(let z of [...R.before,...R.after])Y===void 0?w.push(z):g.push({following:z,order:s.get(z),at:Y});}g.sort(d);for(let S of g){let R=S.following.before?S.at:S.at+1;E(S.following,b(S.following,R));}};for(let y of l){let k=y.atEnd||y.following.before?y.at:y.at+1;E(y.following,b(y.following,f(k)));}for(let y of w)E(y,b(y,n.length));for(let[y,k]of c){let I=t.inline.textOf(y);if(I&&y!==e&&t.inline.isDeletedParagraph(y)){let g=new Set(k),S=ot(I).ids;Nt(I,S.flatMap((R,P)=>R&&g.has(R)?[P]:[])),p.add(y);}}for(let y of p)t.inline.follow.invalidate(y);return t.inline.follow.invalidate(e),t.inline.noteDrift(),[...c.keys()]}function Or(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 $u(t){let e=new Set;for(let o of t)for(let r of Or(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(a=>{let s=o.identities[a];return s!=null&&e.has(s)});if(r.length===0)continue;let i=o.shownIdentities;n.push({write:o,ids:vo(o.text,r),originals:r.map(a=>i&&!i.moved[a]&&!i.restored[a]?o.identities[a]??null:null)});}return n}function Er(t,e){return t===null||!e.has(t)}function Wu(t,e,n){let o=new Set,r=new Set(e.map(a=>a.id));for(let a of e)for(let s of Or(a))o.add(s);if(o.size===0)return;let i=new Set;for(let a of o)for(let s of t.inline.follow.holdersOf(a))r.has(s)||i.add(s);for(let a of i){let s=t.inline.textOf(a);if(!s)continue;let l=ot(s),d=l.ids.flatMap((c,p)=>{if(!c||!o.has(c))return [];let u=ge(l,p);return Er(u?null:c,n)?[p]:[]});d.length!==0&&(Nt(s,d),t.inline.follow.invalidate(a),t.inline.noteDrift());}}function ga(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),p=0;for(let f of d.toDelta()){if(typeof f.insert=="string"){p+=f.insert.length;continue}let h=f.insert?.n;typeof h=="string"&&!c.hidden.has(p)&&r.add(h),p+=1;}let u=[];c.identities.ids.forEach((f,h)=>{!f||c.hidden.has(h)||(u.push(f),ge(c.identities,h)&&n.add(f));});for(let f of c.incoming)for(let h of f.identities)h&&u.push(h);u.length>0&&o.set(l,u);}let i=[];if(n.size===0)return {held:i,shown:o,embeds:r};let a=new Set(e),s=new Set;for(let l of n)for(let d of t.inline.follow.holdersOf(l))a.has(d)||s.add(d);for(let l of s){let d=t.inline.textOf(l);if(!d)continue;let c=ot(d),p=[],u=[];c.ids.forEach((f,h)=>{!f||!n.has(f)||(ge(c,h)?p.push(h):u.push(h));}),u.length>0&&i.push({holder:l,text:d,items:vo(d,u),identities:u.map(f=>c.ids[f])}),p.length!==0&&(Nt(d,p),t.inline.follow.invalidate(l),t.inline.noteDrift());}return {held:i,shown:o,embeds:r}}function ya(t,e,n,o){let r=new Set(n);for(let i of e){if(o.embedded.has(i)||v(i))continue;let a=i;[...t.inline.holdersOf(a)].some(s=>!r.has(s))||!t.hasNode(a)||t.isTombstoned(a)||t.listingParents(a).length===0&&t.tombstone(a);}}function ba(t,e,n){let o=new Set(e.deleted);for(let i of n.values())for(let a of i)o.add(a);let r=Vu([...o].filter(i=>!e.copied.has(i)));r.length>0&&Te(t.doc).record(r);}function Vu(t){let e=t.flatMap(o=>ye(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 Ia(t,e,n){for(let{holder:o,text:r,items:i,identities:a}of e){let s=i.filter((l,d)=>Er(a[d],n));s.length!==0&&(Lo(r,s),t.inline.follow.invalidate(o),t.inline.noteDrift());}}function xa(t,e,n=new Map){let o=new Set,r=[],i=new Set;for(let{id:c}of e.paragraphs){let p=t.inline.textOf(c);if(p)for(let u of zu(t,c,p))u!==c&&t.inline.isDeletedParagraph(u)&&i.add(u);}for(let{id:c,after:p}of e.paragraphs){let u=t.schema.nodes.get(c);if(!u||i.has(c))continue;let f=n.get(c)??Pn(p,t.limits);for(let w of f)typeof w.insert!="string"&&"n"in w.insert&&o.add(w.insert.n);let h=t.inline.textOf(c),m=h?t.inline.viewOf(c).shown(h):null,b=h?oa(h,m?.hidden,{limits:t.limits,paragraphId:c}):[];r.push({id:c,record:u,text:h,before:b,after:f,steps:ia(b,f),identities:m?.identities.ids??[],shownIdentities:m?.identities??null,hidden:m?.hidden??new Set});}let a=$u(r),s=Ys(r,(c,p)=>({...c,attributes:{...c.attributes,[Jt]:p}}),c=>{let{[Jt]:p,...u}=c.attributes;return re(u)},(c,p)=>he(c.attributes,t.limits,r[p].id).text?.id??"",c=>Ku(t,r[c].id));for(let c of r){let p=c.text??Ln(c.record,[]);ju(p,c.before,c.after,c.steps,c.shownIdentities,u=>t.inline.follow.shownCopy(u)!==null,(u,f,h)=>Go(u,f,h,t.limits,c.id)),t.inline.follow.invalidate(c.id);}for(let{write:c,ids:p,originals:u}of a){let f=p.filter((h,m)=>Er(u[m],s));!c.text||f.length===0||(Lo(c.text,f),t.inline.follow.invalidate(c.id),t.inline.noteDrift());}Wu(t,r,s);let l=new Set(e.paragraphs.map(c=>c.id));for(let c of e.embedsBefore)o.has(c)||[...t.inline.holdersOf(c)].some(p=>!l.has(p))||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 p of Or(c))d.add(p);return {copied:s,deleted:d,embedded:o}}function Ku(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 Sa=new WeakMap,Hu=4096;function ka(t,e){if(e.effects.length!==1)return null;let n=e.effects[0];if(n.kind!=="spliceText"||n.deleteCount!==0||!Gu(n.insert)||t.hasUnobservedWrites()||ve(t.doc))return null;let o=t.inline.owner(n.logicalId);if(o===null)return null;let r=t.inline.textOf(o);if(!r||t.inline.sharesIds(o))return null;let i=t.inline.viewOf(o),a=i.shown(r);if(a.hidden.size>0||a.incoming.length>0)return null;let s=r.toDelta(),l=0,d=-1,c=0,p=null,u=new Set,f=new Set;for(let y of s){let k=y.attributes??{};if(!qu(t,o,k))return null;let I=he(k,t.limits,o);if(typeof y.insert=="string"&&(!I.run||!I.text))return null;let g=new Set;for(let R of [I.run?.id,I.runProperties?.id,I.text?.id,I.textValueId,...I.wrap.map(P=>P.id)])if(R){if(u.has(R)&&!f.has(R))return null;g.add(R),u.add(R);}f=g;let S=typeof y.insert=="string"?y.insert.length:1;if(typeof y.insert=="string"&&I.textValueId!==null&&i.shownId(I.textValueId)===n.logicalId){if(d<0)d=l;else if(d+c!==l)return null;if(p&&re(p)!==re(k))return null;p??=k,c+=S;}l+=S;}if(!p||!Number.isSafeInteger(n.utf16Start)||n.utf16Start<0||n.utf16Start>c||c+n.insert.length>t.limits.maxTextLength)return null;let h=d+n.utf16Start,m=h>0?wa(s,h-1):null,b=h<l?wa(s,h):null,w=n.insert[0],E=n.insert[n.insert.length-1];return b&&b.key===`c${w}`||m&&m.key===`c${E}`&&m.element!==(p.t??"")||m?.highSurrogate||m?.revisions&&m.element!==(p.t??"")?null:{paragraphId:o,text:r,length:r.length,position:h,value:n.insert,attributes:p,identities:a.identities}}function va(t,e){if(e.text.length!==e.length)return false;let n=vr(e.identities,e.position);return n?Rr(e.text,e.position,e.value,e.attributes,n):Lr(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 Gu(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 qu(t,e,n){let o=re(n),r=JSON.stringify([e,o]),i=Sa.get(t.limits);i||Sa.set(t.limits,i=new Map);let a=i.get(r);if(a!==void 0)return a;let s;try{let l=he(n,t.limits,e);s=re(et(l,e,t.limits))===o;}catch(l){if(!(l instanceof be))throw l;s=false;}return i.size>=Hu&&i.clear(),i.set(r,s),s}function wa(t,e){let n=0;for(let o of t){let r=typeof o.insert=="string"?o.insert.length:1;if(e<n+r){let i=kn(o.attributes??{});if(typeof o.insert!="string")return {key:"embed",element:"",highSurrogate:false,revisions:i};let a=o.insert.charCodeAt(e-n);return {key:`c${o.insert[e-n]}`,element:o.attributes?.t??"",highSurrogate:a>=55296&&a<=56319,revisions:i}}n+=r;}return null}function Cr(t,e){let n=[],o=[{id:e,depth:0}],r=new Set,i=0;for(;o.length>0;){let{id:a,depth:s}=o.pop();if(r.has(a)||s>t.limits.maxTreeDepth)return null;r.add(a);let l=t.record(a);if(!l)return null;if(He(l)){let d=t.projectedTextValue(a)??l.value;if(i+=d.length,i>t.limits.maxTextLength)return null;n.push({id:a,value:d});}else if(j(l)&&!l.kind.endsWith("Properties"))for(let d=l.childIds.length-1;d>=0;d-=1)o.push({id:l.childIds[d],depth:s+1});}return n}function Lt(t,e,n){let o=Cr(t,e),r=[];if(!o||o.length===0)return false;for(let l of n){let d=Cr(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=[],a=0,s=0;for(let l of r){for(;a<o.length-1&&s===o[a].value.length;)a+=1,s=0;let d=o[a];if(!d||s+l.value.length>d.value.length)return false;l.id!==d.id&&i.push({product:l.id,source:d.id,start:s,end:s+l.value.length}),s+=l.value.length;}for(let l of i)t.registerSplitText(l.product,l.source,l.start,l.end);return true}function Mn(t,e,n){return t!=="run"&&t!=="text"?null:e.filter(o=>n(o)===t)}function La(t,e,n,o){for(let{removedId:r,runs:i}of e){let a=n.filter(s=>!i.includes(s));for(let s=1;s<=Math.min(a.length,Zu);s+=1){let l=a.slice(0,s);if(Lt(t,r,[...i,...l])){o(r,l);break}}}}var Zu=8;function Tr(t,e){return (Cr(t,e)??[]).some(n=>t.splitTextPending(n.id))}var rt=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 s=this.node(r),l=s?.children.indexOf(e)??-1;s&&l>=0&&s.children.splice(l,1);}let i=this.node(n);if(!i)return;let a=Math.min(o,i.children.length);i.children.splice(a,0,e);}parentOf(e){for(let[n,o]of this.touched)if(o.children.includes(e))return n;return this.registry.parentOf(e)}};function Ht(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 De(t,e){return v(e)||e.length===0?{ok:false,code:"prototype-key",detail:e}:t.has(e)?null:{ok:false,code:"unknown-logical-id",detail:e}}function Qu(t,e,n){if(v(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:v(e.qname.localName)?{ok:false,code:"prototype-key",detail:e.qname.localName}:ie(e.qname.namespaceUri,t.limits.maxStringLength)?{ok:false,code:"invalid-string"}:null}function Dn(t,e,n){switch(e.kind){case "putNode":return Qu(t,e.descriptor,n);case "spliceText":{let o=De(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=De(n,e.logicalId);return o||(v(e.qname.localName)?{ok:false,code:"prototype-key",detail:e.qname.localName}:ie(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=De(n,e.logicalId);return o||(v(e.prefix)?{ok:false,code:"prototype-key"}:e.uri!==null&&ie(e.uri,t.limits.maxStringLength)?{ok:false,code:"invalid-string"}:null)}case "spliceChildren":{let o=De(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 a=De(n,i);if(a)return a}let r=n.node(e.parentLogicalId);if(r&&!r.isText){if(e.start+e.deleteCount>r.children.length&&!Ca(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=De(n,e.logicalId);if(o)return o;let r=De(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=De(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 v(e.record.id)?{ok:false,code:"prototype-key"}:t.relationshipCount()>=t.limits.maxRelationships?{ok:false,code:"too-many-relationships"}:null}case "deleteRelationship":return v(e.relationshipId)?{ok:false,code:"prototype-key"}:null;case "putContentTypeOverride":{let o=Z(e.partName);return o?{ok:false,code:o}:ie(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=Si(e.descriptor);return o?{ok:false,code:o}:null}case "deleteBinary":return v(e.storageKey)?{ok:false,code:"prototype-key"}:null;default:return {ok:false,code:"invalid-bound"}}}function ep(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&&!ze(o)&&!ze(r)){e.push({...o,insert:r.insert}),n+=1;continue}e.push(o);}return e}function tp(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=ze(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,Ca(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 np(t,e){let n=t.kindOf(e);return n!==null&&!n.endsWith("Properties")}function op(t,e,n,o){let r=new Set((n.get(e)??[]).filter(i=>np(t,i)));if(r.size!==0){for(let i of o)if(!(i.kind!=="spliceChildren"||i.parentLogicalId===e)&&i.childLogicalIds.some(a=>r.has(a)))return i.parentLogicalId}}function rp(t,e){let n=new rt(t),o=[],r=new Set,i=new Set,a=new Set,s=new Set,l=new Map;for(let d of e){let c=Dn(t,d,n);if(c)return c;if(d.kind==="spliceChildren"){let p=d.deleteCount>0?n.node(d.parentLogicalId):null;if(p&&!p.isText){let u=d.start+d.deleteCount;for(let f=d.start;f<u;f+=1){let h=p.children[f];if(h!==void 0&&(o.push(h),i.add(h),d.childLogicalIds.length>0)){let m=l.get(d)??[];m.push(h),l.set(d,m);}}}for(let u of d.childLogicalIds)r.add(u),i.delete(u);}else d.kind==="moveNode"?(r.add(d.logicalId),i.delete(d.logicalId)):d.kind==="putNode"&&(s.add(d.descriptor.logicalId),d.descriptor.kind==="textValue"&&a.add(d.descriptor.logicalId));Ht(n,d);}return {removed:o,reinserted:r,unlistedAtEnd:i,mintedText:a,mintedNodes:s,replacementsByEffect:l}}function ip(t){let e=0;for(let n of t)n.kind==="putNode"&&(e+=1);return e}function Ar(t,e,n,o){if(o){let c=false;return t.doc.transact(()=>{t.noteWrite(),c=va(t,o);},Ao),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=On(t,e.effects);if(c.refusal)return {ok:false,...c.refusal};r=c.plan,r&&(i={...e,effects:c.passThrough});}let a=i.effects.map(gt);if(t.nodeCount()+ip(a)>t.limits.maxNodes)return {ok:false,code:"too-many-nodes"};let s=rp(t,a);if("ok"in s)return s;for(let c of s.replacementsByEffect.values())for(let p of c)if(t.kindOf(p)==="run"&&Tr(t,p))return {ok:false,code:"invalid-bound",detail:`split of pending text in ${p}`,transient:true};let l=r?.paragraphs.find(({id:c})=>t.inline.textOf(c)===null&&Oa(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:p})=>[c,Pn(p,t.limits)]));}catch(c){if(!(c instanceof be))throw c;return {ok:false,code:c.code,detail:c.detail}}return t.doc.transact(()=>{t.noteWrite();let c=dp(t,s.removed),p=[],u=[];for(let m of ep(a))if(tp(t,m,s.mintedText),m.kind==="spliceChildren"){if(s.mintedNodes.has(m.parentLogicalId))for(let b of m.childLogicalIds)s.mintedNodes.has(b)&&t.kindOf(b)==="run"&&u.push(b);lp(t,s,s.replacementsByEffect.get(m)??[],m.childLogicalIds,p);}La(t,p,u,(m,b)=>{t.recordRunSplit(Ea(t,m,s.reinserted),m,b);}),ap(t,a,s,c);let f=ga(t,s.removed),h=r?xa(t,r,d):{copied:new Set,deleted:new Set,embedded:new Set};Ms(t,s.removed,h.embedded,s.mintedNodes,r?.paragraphs.map(({after:m})=>m)??[]),Ia(t,f.held,h.copied),ba(t,h,f.shown),ya(t,f.embeds,s.removed,h);},Ao),{ok:true}}function sp(t,e){if(t.inline.textOf(e)===null&&Oa(t,e))return true;let n=t.record(e);return (n&&"childIds"in n?n.childIds:[]).some(r=>t.kindOf(r)==="run"&&Tr(t,r))}function Ra(t,e){let n=t.kindOf(e)==="paragraph"?e:t.inline.owner(e)??t.parentOf(e);return n!==null&&sp(t,n)}function Oa(t,e){let n=t.schema.nodes.get(e);return M(n)&&_i(n,ne)}function ap(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 a=op(t,i,o,e);a&&t.unlistChildren(i,o.get(i)??[]),t.tombstone(i,a);}}function lp(t,e,n,o,r){for(let i of n){let a=t.kindOf(i);if(a!=="run"&&a!=="text"||e.reinserted.has(i)&&!e.mintedNodes.has(i))continue;let s=Ea(t,i,e.reinserted);if(a==="text"){let d=Mn(a,o,c=>t.kindOf(c));if(d&&Lt(t,i,d)){let c=o.filter(p=>e.mintedNodes.has(p));t.recordRunSplit(s,i,c);}continue}let l=o.filter(d=>t.kindOf(d)==="run");Lt(t,i,l)||r.push({removedId:i,runs:l}),t.recordRunSplit(s,i,l);}}function Ea(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 dp(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 Ca(t,e,n){return e.deleteCount===0&&e.start>n&&t.partEntries().some(o=>o.rootLogicalId===e.parentLogicalId)}var de="splitTextSource",cp=Object.freeze({kind:"docx-package-restored-split-anchors"});function le(t,e){throw new A(t,e)}function Pr(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function Ta(t){return Pr(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 Aa(t){return !Pr(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?le("invalid-string",de):B.createRelativePositionFromJSON(t)}var it=class extends Error{},Rt=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);(!M(i)||!(i.get(ue)instanceof B.Text))&&le("invalid-bound",e);let a=this.read(n),s=a===null?{sourceId:n,text:this.sourceText(n),start:0,end:this.sourceText(n).length}:this.resolve(a);(s.sourceId.length===0||s.sourceId.length>this.limits.maxStringLength||v(s.sourceId))&&le("invalid-string",n),(!Number.isSafeInteger(o)||!Number.isSafeInteger(r)||o<0||r<o||r>s.end-s.start||e===s.sourceId)&&le("invalid-bound",e);let l=(c,p)=>{if(a&&p==="end"&&c===s.end-s.start)return a.end;if(a&&c===0)return a.start;if(a&&c===s.end-s.start)return a.end;let u=s.start+c;return B.createRelativePositionFromTypeIndex(s.text,u,u===0&&p==="start"?-1:0)},d=JSON.stringify({sourceId:s.sourceId,start:B.relativePositionToJSON(l(o,"start")),end:B.relativePositionToJSON(l(r,"end"))});d.length>this.limits.maxStringLength&&le("invalid-string",e),i.set(de,d),this.indexExisting(e);}normalizeRestoredAnchors(){let e=new Map,n=r=>{let i=r.item;if(i===null)return r;let a=`${i.client}:${i.clock}:${r.assoc}`,s=e.get(a);if(s)return s;let l=u=>B.getState(this.doc.store,u.client)>u.clock?B.getItem(this.doc.store,u):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 p=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(a,p),p},o=[];for(let r of this.sourceByAlias.keys()){let i=this.nodes.get(r);if(M(i)&&_o(i,de))continue;let a=this.read(r);if(!a)continue;let s=n(a.start),l=n(a.end);if(B.compareRelativePositions(s,a.start)&&B.compareRelativePositions(l,a.end))continue;let d=JSON.stringify({sourceId:a.sourceId,start:B.relativePositionToJSON(s),end:B.relativePositionToJSON(l)});d.length>this.limits.maxStringLength&&le("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(de,i),this.indexExisting(r);},cp);}sourceAliases(e){return [...this.aliasesBySource.get(e)??[]]}range(e){try{return this.resolveRange(e)}catch(n){if(n instanceof it)return null;throw n}}isPending(e){try{return this.resolveRange(e),!1}catch(n){if(n instanceof it)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&&!Do(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(a){if(!(a instanceof it))throw a;this.awaiting.has(o)||e.add(o),this.awaiting.add(o);}let i=null;if(r){let a=n.get(r.sourceId);a===void 0&&(a=r.text.toString(),n.set(r.sourceId,a)),i=a.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=M(n)?n.get(ue):null;return !(o instanceof B.Text)||o.doc!==this.doc||o.length>this.limits.maxTextLength?le("invalid-bound",e):o}read(e){let n=this.nodes.get(e);if(!M(n))return null;let o;if(_o(n,de)){if(o=this.lastEncoded.get(e),o===void 0)throw new it(e);this.held.add(e);}else {if(!n.has(de))return null;o=n.get(de);}if(typeof o!="string"||o.length>this.limits.maxStringLength)return le("invalid-string",e);let r;try{r=JSON.parse(o);}catch{return le("invalid-string",e)}if(!Pr(r)||!Object.keys(r).every(a=>["sourceId","start","end"].includes(a))||typeof r.sourceId!="string"||r.sourceId.length===0||r.sourceId.length>this.limits.maxStringLength||v(r.sourceId)||r.sourceId===e)return le("invalid-string",e);if(!(n.get(ue)instanceof B.Text))return le("invalid-bound",e);let i={sourceId:r.sourceId,start:Aa(r.start),end:Aa(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 it(e.sourceId);let n=this.nodes.get(e.sourceId);if(M(n)&&n.has(de))return le("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 le("invalid-bound",e.sourceId);let i=B.createAbsolutePositionFromRelativePosition(e.start,this.doc,false),a=B.createAbsolutePositionFromRelativePosition(e.end,this.doc,false),s=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||a===null||i.type!==o||a.type!==o||i.index<0||a.index>o.length?le("invalid-bound",e.sourceId):{sourceId:e.sourceId,text:o,start:i.index,end:Math.max(i.index,a.index),startAssoc:e.start.assoc,endAssoc:e.end.assoc,startAnchorDeleted:s,endAnchorDeleted:l}}};function _n(t,e,n,o,r,i){if(!o||i.length===0)return null;let a=r===0&&o.startAssoc!==-1,s=r===o.end-o.start;if(!a&&!s)return null;let l=t.get(n)?.get(de);if(typeof l!="string")return null;let d=JSON.parse(l),c=B.createRelativePositionFromJSON(d.start),p=B.createRelativePositionFromJSON(d.end);if(s=s&&(a||p.item!==null&&B.getItem(o.text.doc.store,p.item).deleted),!a&&!s)return null;let u=[],f=o.text.doc.store,h=m=>{if(m.item===null||!B.getItem(f,m.item).deleted)return false;let b=B.createAbsolutePositionFromRelativePosition(m,o.text.doc,false);return b!==null&&b.type===o.text&&b.index===o.end};for(let m of e.sourceAliases(o.sourceId)){if(!e.range(m))continue;let b=t.get(m),w=b.get(de);if(typeof w!="string")continue;let E=JSON.parse(w),y=(g,S)=>{let R=B.createRelativePositionFromJSON(g);return a&&s&&B.compareRelativePositions(c,p)&&B.compareRelativePositions(R,c)?S==="start"?"after":"before":a&&B.compareRelativePositions(R,c)?"before":s&&B.compareRelativePositions(R,p)||s&&!a&&!(m===n&&S==="start")&&h(R)?"after":null},k=m===n&&a?"before":y(E.start,"start"),I=m===n&&s?"after":y(E.end,"end");(k||I)&&u.push({record:b,start:k,end:I});}return ()=>{let m=o.start+r,b=B.relativePositionToJSON(B.createRelativePositionFromTypeIndex(o.text,m,m===0&&o.startAssoc===-1?-1:0)),w=B.relativePositionToJSON(B.createRelativePositionFromTypeIndex(o.text,m+i.length,0));for(let E of u){let y=JSON.parse(E.record.get(de));E.start&&(y.start=E.start==="before"?b:w),E.end&&(y.end=E.end==="before"?b:w);let k=JSON.stringify(y);k!==E.record.get(de)&&E.record.set(de,k);}}}var Yn=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);M(i)&&(i.set(_t,e),i.set(Xe,e),this.indexExisting(r));}}indexExisting(e){let n=this.nodes.get(e),o=Qe(n);if(o===null||o===e||ar(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=>Qe(this.nodes.get(n))===e)}loserRuns(e){if(this.cachedLosers)return this.cachedLosers;let n=new Set,o=new Set,r=i=>{let a=[i];for(;a.length>0;){let s=a.pop();if(!o.has(s)){o.add(s),e.isPresent(s)&&n.add(s);for(let l of this.productsOf(s))a.push(l);}}};for(let i of this.liveRootedOrigins){let a=this.productsOf(i),s=e.isPresent(i)?null:a.filter(l=>Ut(this.nodes.get(l))===i).map(l=>Dt(l)??"").sort()[0];for(let l of a)(Dt(l)??"")!==s&&r(l);}return this.cachedLosers=n,n}};function Bn(t,e,n){let o=new Map;for(let s=0;s<t.length;s+=1){let l=t[s],d=n(l);if(d===null||d===l)continue;let c=o.get(d)??{loser:[],winner:[]};(e(l)?c.loser:c.winner).push(s),o.set(d,c);}let r=new Map;for(let{loser:s,winner:l}of o.values())s.length!==1||l.length!==1||s[0]>l[0]||r.set(l[0],s[0]);if(r.size===0)return null;let i=new Map;for(let[s,l]of r)i.set(l,s);let a=[];for(let s=0;s<t.length;s+=1){let l=i.get(s);l!==void 0&&a.push(l),r.has(s)||a.push(s);}return a}function Pa(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 Nr=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=(a,s)=>{let l=s<0?a-1:a;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 a=this.shadow.sources.range(e);return a?{...a,revision:0}:null}n.start=Pa(n.start,n.startAssoc,r),n.end=Pa(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=ze(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 a=this.strings.get(e.logicalId);a!==void 0&&this.strings.set(e.logicalId,a.slice(0,r.start)+r.inserted+a.slice(r.start+r.deleted));let s={kind:"splice",effect:e};this.actions.push(s),this.shadow&&this.replay(s);}register(e,n,o,r){let i=this.range(n),a=i?.sourceId??n,s=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:s+f===0&&h==="start"?-1:0,deleted:false},c=d(o,"start"),p=d(r,"end");this.ranges.set(e,{sourceId:a,start:s+o,end:s+r,startAssoc:c.assoc,endAssoc:p.assoc,startAnchorDeleted:c.deleted,endAnchorDeleted:p.deleted,revision:this.histories.get(a)?.length??0});let u={kind:"register",product:e,source:n,start:o,end:r};this.actions.push(u),this.shadow&&this.replay(u);}destroy(){this.shadow?.doc.destroy();}ensureShadow(){if(this.shadow)return;let e=new B.Doc({gc:false}),n=e.getMap(To);this.shadow={doc:e,nodes:n,sources:new Rt(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=p=>(n.nodes.has(p)||n.nodes.set(p,dn("")),n.nodes.get(p).get(ue));if(e.kind==="register"){o(e.product),n.sources.register(e.product,e.source,e.start,e.end);return}let{effect:r}=e,i=ze(r),a=i?n.sources.range(i.logicalId):null,s=a?.text??o(r.logicalId),l=i?.utf16Start??r.utf16Start,d=(a?.start??0)+l,c=_n(n.nodes,n.sources,i?.logicalId??r.logicalId,a,l,r.insert);r.deleteCount>0&&s.delete(d,r.deleteCount),r.insert.length>0&&s.insert(d,r.insert),c?.();}},Mr=class extends rt{constructor(n,o,r,i,a=()=>[],s=()=>null){super(n);this.shared=n;this.visibleIndexes=o;this.raw=r;this.text=i;this.mergedOf=a;this.shownOf=s;}shared;visibleIndexes;raw;text;mergedOf;shownOf;filtered=new Set;node(n){let o=super.node(n);if(o&&!this.filtered.has(n)){this.filtered.add(n);let r=[...this.shared.adoptedChildren(n),...this.mergedOf(n)].filter((a,s,l)=>!o.children.includes(a)&&l.indexOf(a)===s),i=r.length>0?[...o.children,...r]:o.children;o.children=this.shownOf(n)?.slice()??this.visibleIndexes(n,i).map(a=>i[a]);}if(o?.isText){let r=this.text.range(n);o.textLength=r?r.end-r.start:this.raw.node(n)?.textLength??o.textLength;}return o}};function Na(t,e,n){let o=ka(t,e);return o?{ok:true,journal:{...e,effects:[]},plan:null,typed:o}:up(t,e,n)}function up(t,e,n=()=>null){let o=On(t,e.effects);if(o.refusal)return {ok:false,...o.refusal};let i=(o.plan?{...e,effects:o.passThrough}:e).effects.map(gt),a=t.replacementLoserRuns(),s=i.filter(x=>x.kind==="putNode").length;if(t.nodeCount()+s>t.limits.maxNodes)return {ok:false,code:"too-many-nodes"};let l=new Set;for(let x of i){if(x.kind==="spliceChildren"){if(x.childLogicalIds.length>t.limits.maxChildren)return {ok:false,code:"too-many-children"};for(let O of x.childLogicalIds)l.add(O);}else x.kind==="moveNode"&&l.add(x.logicalId);if(l.size>t.limits.maxNodes)return {ok:false,code:"too-many-nodes"}}let d=new rt(t),c=new Nr(t,d),p=new Mr(t,(x,O)=>b(x,O),d,c,x=>P(x),x=>n(x)),u=new Map,f=x=>u.get(x)?.kind??t.kindOf(x),h=x=>{let O=u.get(x);return O?O.kind==="textValue"?{kind:"textValue",namespaceUri:"",localName:""}:{kind:O.kind,namespaceUri:O.qname.namespaceUri,localName:O.qname.localName}:kt(t,x)},m=(x,O)=>{let L=new Set,C=[];((a.size===0?null:Bn(O,F=>a.has(F),F=>t.splitLineageOf(F)))??O.map((F,K)=>K)).forEach(F=>{let K=O[F];K===x||L.has(K)||a.has(K)||(L.add(K),!(!u.has(K)&&!t.showsAsChild(K))&&C.push(F));});let _=Rn(f(x),C.map(F=>O[F]),h);if(!_)return {positions:C,companions:new Map};let T=new Map;for(let[F,K]of _.companions)T.set(C[F],K.map(Q=>C[Q]));return {positions:_.order.map(F=>C[F]),companions:T}},b=(x,O)=>m(x,O).positions,w=x=>x.some((O,L)=>L>0&&O<x[L-1]),E=(x,O,L,C)=>{let U=b(x,O),_=U[L]??O.length;if(!w(U))return _;let T=L>0?U[L-1]+1:0;for(let F of [_,T,O.length]){let K=[...O.slice(0,F),...C,...O.slice(F)],Q=b(x,K).map(Fe=>K[Fe]);if(C.every((Fe,je)=>Q[L+je]===Fe))return F}return _},y=x=>{let O=[x],L=new Set;for(;O.length>0;){let C=O.pop();if(L.has(C))continue;L.add(C);let U=d.node(C);if(!(!U||U.isText)){for(let _ of U.children)if(!(l.has(_)||t.parentOf(_)!==C)){for(let T of t.listingParents(_)){if(T===C)continue;let F=d.node(T),K=F&&!F.isText?F.children.indexOf(_):-1;K<0||W({kind:"spliceChildren",parentLogicalId:T,start:K,deleteCount:1,childLogicalIds:[]});}O.push(_);}}}},k=new Set,I=x=>{if(k.has(x))return;k.add(x);let O=n(x),L=d.node(x);if(!O||!L||L.isText)return;let C=L.children;if(O.length===C.length&&O.every((_,T)=>C[T]===_))return;for(let _ of O)if(!C.includes(_))for(let T of t.listingParents(_)){let F=d.node(T),K=F&&!F.isText?F.children.indexOf(_):-1;K<0||T===x||W({kind:"spliceChildren",parentLogicalId:T,start:K,deleteCount:1,childLogicalIds:[]});}let U=C.filter(_=>!O.includes(_));W({kind:"spliceChildren",parentLogicalId:x,start:0,deleteCount:C.length,childLogicalIds:[...O,...U]});},g=new Set,S=x=>{if(g.has(x))return;g.add(x);let O=d.node(x);if(!O||O.isText)return;let L=t.adoptedChildren(x).filter(C=>!O.children.includes(C));if(L.length!==0){for(let C of L)for(let U of t.listingParents(C)){if(t.replacedByOf(U)!==x)continue;let _=d.node(U),T=_&&!_.isText?_.children.indexOf(C):-1;T<0||W({kind:"spliceChildren",parentLogicalId:U,start:T,deleteCount:1,childLogicalIds:[]});}W({kind:"spliceChildren",parentLogicalId:x,start:O.children.length,deleteCount:0,childLogicalIds:L});}},R=x=>{if(!rr.has(f(x)??""))return [];let O=t.parentOf(x),L=O?d.node(O):null;return !O||!L||L.isText?[]:(m(O,L.children).companions.get(L.children.indexOf(x))??[]).map(U=>L.children[U])},P=x=>{let O=[];for(let L of R(x)){let C=d.node(L);C&&!C.isText&&O.push(...C.children);}return O},Y=new Set,z=x=>{if(Y.has(x))return;Y.add(x);let O=d.node(x);if(!O||O.isText)return;let L=[];for(let C of R(x)){let U=d.node(C);if(!U||U.isText||U.children.length===0)continue;let _=[...U.children];W({kind:"spliceChildren",parentLogicalId:C,start:0,deleteCount:_.length,childLogicalIds:[]});for(let T of _)!O.children.includes(T)&&!L.includes(T)&&L.push(T);}L.length!==0&&W({kind:"spliceChildren",parentLogicalId:x,start:d.node(x).children.length,deleteCount:0,childLogicalIds:L});},X={limits:t.limits,projectedTextValue:x=>d.node(x)?.isText?c.value(x):null,registerSplitText:(x,O,L,C)=>c.register(x,O,L,C),splitTextPending:x=>t.splitTextPending(x),record:x=>{let O=d.node(x);if(!O)return null;if(O.isText)return {logicalId:x,kind:"textValue",value:c.value(x)};let L=u.get(x),C=L?null:t.record(x);return C&&C.kind!=="textValue"?{...C,childIds:O.children}:!L||L.kind==="textValue"?null:{logicalId:x,kind:L.kind,namespaceUri:L.qname.namespaceUri,localName:L.qname.localName,prefix:L.qname.prefix??"",attributes:[],bindings:[],childIds:O.children}}},J=[],D=null,W=x=>{if(D)return;let O=Dn(t,x,d);if(O&&!O.ok){D=O;return}J.push(x),Ht(d,x),x.kind==="spliceText"&&c.apply(x);};try{for(let x of i){let O=Dn(t,x,p);if(O&&!O.ok)return O;if(Ht(p,x),x.kind==="putNode"&&u.set(x.descriptor.logicalId,x.descriptor),x.kind==="spliceText"){let L=c.range(x.logicalId);W(L?di({...x,logicalId:L.sourceId,utf16Start:L.start+x.utf16Start},{logicalId:x.logicalId,utf16Start:x.utf16Start}):x);}else if(x.kind==="spliceChildren"){I(x.parentLogicalId),S(x.parentLogicalId),z(x.parentLogicalId);let L=d.node(x.parentLogicalId);if(!L||L.isText)return {ok:!1,code:"invalid-bound"};let{positions:C,companions:U}=m(x.parentLogicalId,L.children),_=C.slice(x.start,x.start+x.deleteCount).map(T=>L.children[T]);if(x.deleteCount===0){let T=x.childLogicalIds;W({...x,start:E(x.parentLogicalId,L.children,x.start,T)});}else {let T=C.slice(x.start,x.start+x.deleteCount),F=T.flatMap(Q=>U.get(Q)??[]);if(F.length>0||w(C)){let Q=[...T,...F].sort((je,ko)=>ko-je);for(let je of Q)W({...x,start:je,deleteCount:1,childLogicalIds:[]});let Fe=d.node(x.parentLogicalId);if(x.childLogicalIds.length>0&&Fe&&!Fe.isText){let je=x.childLogicalIds,ko=E(x.parentLogicalId,Fe.children,x.start,je);W({...x,start:ko,deleteCount:0});}T.length=0;}let K=T.length;for(;K>0;){let Q=K-1;for(;Q>0&&T[Q-1]===T[Q]-1;)Q-=1;W({...x,start:T[Q],deleteCount:K-Q,childLogicalIds:Q===0?x.childLogicalIds:[]}),K=Q;}}if(!D)for(let T of _)l.has(T)||y(T);if(!D&&x.childLogicalIds.length>0)for(let T of _){if(l.has(T)&&!u.has(T))continue;let F=Mn(f(T),x.childLogicalIds,f);F&&Lt(X,T,F);}}else if(x.kind==="moveNode"){I(x.destinationParentLogicalId),S(x.destinationParentLogicalId),z(x.destinationParentLogicalId);let L=d.node(x.destinationParentLogicalId);if(!L||L.isText)return {ok:!1,code:"invalid-bound"};let C=L.children.filter(U=>U!==x.logicalId);W({...x,destinationIndex:E(x.destinationParentLogicalId,C,x.destinationIndex,[x.logicalId])});}else W(x);if(D)return D}return {ok:!0,journal:{effects:J},plan:o.plan}}finally{c.destroy();}}var Dr=Symbol("docx-restore-marks");function Ma(t,e){let n=new Map;for(let r of nn(t,e)){if(r.deleted||!(r.content instanceof B.ContentString))continue;let i=r.parent;if(!(i instanceof B.Text)||$e(i)!==ne)continue;let a=n.get(i)??new Set;a.add(`${r.id.client}:${r.id.clock}`),n.set(i,a);}if(n.size===0)return;let o=me(t);t.transact(()=>{for(let[r,i]of n)for(let a=tn(r);a;a=a.right){if(!a.redone)continue;let s=`${a.redone.client}:${a.redone.clock}`;if(!i.has(s))continue;let l=ce(t,a.redone);if(!l||l.deleted)continue;let d=la(r,a,0);o.markCopy("restore",a.redone.client,a.redone.clock,a.length,d);}},Dr);}function _r(t,e,n){for(let o of e)n.push(o.id),!(o.kind==="textValue"||t.hasNode(N(o)))&&_r(t,o.children,n);}function Da(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&&fp(t,o)!==n.rootLogicalId)continue;let a=Ce(o,i,d=>t.showsAsChild(d)?mn(d):null,t.limits,t.inline.viewOf(o)),s=[];_r(t,a,s);let l=[];if(_r(t,r.children.filter(d=>d.kind==="textValue"||!pp(t,d)),l),s.length!==l.length)return true;for(let d=0;d<s.length;d+=1)if(s[d]!==l[d])return true}return false}function pp(t,e){return e.kind==="paragraphProperties"||t.hasNode(N(e))&&!t.inline.isEmbed(e.id)}function fp(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 hp=new Set(["comment","footnote","endnote"]),_a="docx-undone-records";function mp(t,e,n,o){let r=n?.meta,i=e==="undo"?o.filter(s=>{let l=t.record(s);return M(t.schema.nodes.get(s))&&!t.isTombstoned(s)&&!!l&&j(l)&&hp.has(l.localName)}):[],a=e==="redo"?r?.get(_a)??[]:[];e==="undo"&&r?.set(_a,i),!(i.length===0&&a.length===0)&&t.doc.transact(()=>{for(let s of i)t.schema.nodes.get(s)?.set(Je,true);for(let s of a){let l=t.schema.nodes.get(s);M(l)&&l.has(Je)&&l.delete(Je);}},Dr);}var Yr="docx-copy-runs",Ya="docx-hidden-copies",Ua="docx-copies-only",Ur="docx-undo-group";function Fr(t){t.meta.set(Ur,true);}function Fa(t,e,n,o){let r=n==="undo"?e.undoStack:e.redoStack,i=n==="undo"?e.redoStack:e.undoStack,a=r[r.length-1],s=n==="undo"?xp(t,a):Br(a,Yr)??[],l=i.length,d=a?.meta.get(Ua)===true&&Ip(a)===0,c=a?.meta.get(Ur)===true;if(d||s.length>0&&Sp(t,a))r.pop();else {let u=r.splice(0,c?r.length-1:bp(r));try{n==="undo"?e.undo():e.redo();}finally{if(u.length>0){let f=u.concat(r);r.length=0;for(let h of f)r.push(h);}}}o();let p=i.length>l?i[i.length-1]:void 0;if(n==="redo"){let u=Br(a,Ya);u&&u.length>0&&t.doc.transact(()=>Te(t.doc).withdraw(u));}if(s.length>0&&(p??=Ba(i),p.meta.set(Yr,s),n==="undo")){let u=[];t.doc.transact(()=>{u=Te(t.doc).record(s);}),p.meta.set(Ya,u);}c&&(p??=Ba(i),Fr(p)),mp(t,n,n==="redo"?a:p,t.takeUnlisted()),e.stopCapturing();}function gp(t,e,n,o){let r=[];for(let i=n;i<o;){let a=t.origin("restore",e,i);if(a===null||a.client!==e){let d=a===null?o:Math.min(o,a.firstClock+a.length);r.push({client:e,from:i,to:d}),i=d;continue}let s=Math.min(o,a.firstClock+a.length),l=a.clock+(i-a.firstClock);r.push({client:a.client,from:l,to:l+(s-i)}),i=s;}return r}function yp(t,e,n,o){for(let r=n;r<o;r+=1)if(t.shownCopy(`${e}:${r}`))return true;return false}function bp(t){for(let e=t.length-2;e>=0;e-=1)if(t[e].meta.get(Ur)===true)return e+1;return 0}function Ip(t){let e=t;return ct(e.insertions).length+ct(e.deletions).length}function xp(t,e){let n=t.inline.follow,o=me(t.doc),r=(Br(e,Yr)??[]).map(a=>({...a})),i=(a,s,l)=>{let d=r[r.length-1];d&&d.client===a&&d.to===s?d.to=l:r.push({client:a,from:s,to:l});};for(let a of ct(e?.insertions)){let s=a.clock+a.length;for(let l=a.clock;l<s;){let d=ce(t.doc,{client:a.client,clock:l}),c=d?Math.min(d.id.clock+d.length,s):l+1;if(d?.deleted||d&&!o.origin("restore",a.client,l)){let p=gp(o,a.client,l,c);if(p.some(f=>n.holdsCopyIn(f.client,f.from,f.to)&&yp(n,f.client,f.from,f.to)))for(let f of p)i(f.client,f.from,f.to);}l=c;}}return r}function Sp(t,e){if(!e)return false;let n=new Set(t.trackedTypes()),o=e;for(let[r,i]of [[ct(o.deletions),true],[ct(o.insertions),false]])for(let a of r)for(let s=a.clock;s<a.clock+a.length;){let l=ce(t.doc,{client:a.client,clock:s});if(!l||wp(l,n)&&(i||!l.deleted))return false;s=l.id.clock+l.length;}return true}function wp(t,e){let n=t.parent;for(;n!==null;){if(e.has(n))return true;let o=n._item?.parent;n=o instanceof B.AbstractType?o:null;}return false}function Br(t,e){return t?.meta.get(e)}function Ba(t){let e={meta:new Map([[Ua,true]])};return Object.assign(e,{insertions:B.createDeleteSet(),deletions:B.createDeleteSet()}),t.push(e),e}var Fn=class{constructor(e,n){this.undoManager=e;let o=r=>{this.capturing&&r.type==="undo"&&(this.gestureItem=r.stackItem,this.captured=true,this.pinned!==void 0&&Fr(r.stackItem));};e.on("stack-item-added",o),e.on("stack-item-updated",o),n&&Lp(n,e,()=>this.reset());}undoManager;previous;gestureItem;capturing=false;captured=false;pinned;capture(e,n){let o=this.pinned??e,r=this.previous;this.previous=o;let i=this.undoManager.undoStack,a=this.undoManager.captureTimeout;o===r&&o!==void 0&&i[i.length-1]===this.gestureItem?(this.undoManager.lastChange=Date.now(),this.undoManager.captureTimeout=Number.POSITIVE_INFINITY):((o!==r||o!==void 0)&&this.undoManager.stopCapturing(),this.gestureItem=void 0);let s=this.gestureItem;this.captured=false,this.capturing=o!==void 0;try{let l=n();return this.captured&&reportHistoryGroup(e,this.gestureItem===s?"extended":"started"),l}catch(l){throw this.refused(),l}finally{this.capturing=false,this.undoManager.captureTimeout=a;}}reset(){this.previous=void 0,this.gestureItem=void 0;}refused(){this.pinned===void 0&&this.reset();}pin(e){this.undoManager.stopCapturing(),this.reset(),this.pinned=e;}unpin(){this.pinned=void 0,this.reset(),this.undoManager.stopCapturing();}};function Lp(t,e,n){let o=new WeakMap,r=i=>{let a=o.get(i);return a||o.set(i,a={}),a};e.on("stack-item-popped",({stackItem:i,type:a})=>{let s=(a==="undo"?e.redoStack:e.undoStack).at(-1);s&&o.set(s,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 ja(t,e){let n=me(t),o=Te(t),r=s=>{if(e.loading())return;let l=e.inline.marksChanged(s==="all"?e.inline.allTexts():s);l.size>0&&e.changed(l);},i=n.subscribe(r),a=o.subscribe(s=>r(n.textsReading(s)));return ()=>{i(),a();}}function za(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 $a(t,e,n){if(e===n)return 0;let o=za(t,e),r=za(t,n);if(o.root===r.root){let i=Math.min(o.indexes.length,r.indexes.length);for(let a=0;a<i;a+=1){let s=o.indexes[a]-r.indexes[a];if(s!==0)return s}}return e<n?-1:1}var jn=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 Wa(t,e){let n=i=>{let a=new Set,s=false;for(let l of i){let d=l.path;if(d.length===0){for(let c of l.changes.keys.keys())a.add(V(c));s=true;continue}a.add(V(d[0])),l.target instanceof B.Array&&(s=true),l.target instanceof B.Map&&(l.changes.keys.has(Le)||l.changes.keys.has(Ke))&&(s=true);}(a.size>0||s)&&e({logicalIds:a,membershipChanged:s,packageChanged:false});},o=i=>{let a=new Set;for(let s of i.changes.keys.keys()){let l=Bt(String(s))??Ze(String(s));!l||v(l.logicalId)||a.add(l.logicalId);}a.size>0&&e({logicalIds:a,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 Va(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&&j(o)&&o.childIds.includes(e)}function $n(t){return typeof t=="string"?t:""}function Ka(t,e){return t<e?-1:t>e?1:0}function jr(t,e){return `${t}${ee}${e}`}function Op(t){let e=t.indexOf(ee);return e<0?t:t.slice(0,e)}function Ja(t){let e=[];return t.forEach((n,o)=>{!M(n)||v(o)||n.forEach(r=>{if(!M(r))return;let i=$n(r.get("id")),a=$n(r.get("type"));if(i.length===0||a.length===0)return;let s=$n(r.get("ownerPart"))||Op(o);if(v(s))return;let l=r.get("order");e.push({ownerPart:s,id:i,type:a,rawTarget:$n(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||Ka(n.ownerPart,o.ownerPart)||Ka(n.id,o.id)),e}function Xa(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 Ep(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 Cp(t,e){let n=t.childrenSnapshot.get(e);return n||(te(t.nodes.get(e))?.toArray()??[])}function Tp(t,e){let n=t.nodes.get(e);return !M(n)||Oe(n)}var zr=class{constructor(e){this.ctx=e;}ctx;byParent=new Map;indexOf(e,n){let o=this.byParent.get(e);return o||(o=new Map,Cp(this.ctx,e).forEach((r,i)=>{o.has(r)||o.set(r,i);}),this.byParent.set(e,o)),o.get(n)??-1}};function Ap(t,e,n,o,r){let i=[],a=new Set,s=r,l;for(;;){if(a.has(s)||(a.add(s),Tp(t,s)))return null;l=n.get(s);let p=t.parentIndex.get(s);if(l!==void 0){if(p!==void 0||o.has(s))return "fallback";break}if(p===void 0)return o.has(s)?"deferred":null;i.push(s),s=p;}let d=[l],c=s;for(let p=i.length-1;p>=0;p-=1){let u=i[p],f=e.indexOf(c,u);if(f<0)return null;d.push(f),c=u;}return d}function Pp(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 zr(t),i=new Map,a=l=>{let d=i.get(l);if(d!==void 0)return d;let c=Ap(t,r,o,n,l);return c!=="deferred"&&i.set(l,c),c},s=[...n];for(;s.length>0;){let l=[];for(let d of s){let c=null,p=false;for(let u of t.listings.get(d)??[]){if(u===d)continue;let f=a(u);if(f==="fallback")return false;if(f==="deferred"){p=true;continue}if(f===null)continue;let h=r.indexOf(u,d);if(h<0)continue;let m=[...f,h];(!c||Ep(m,c.rank)<0)&&(c={rank:m,parent:u});}if(p){l.push(d);continue}c&&t.parentIndex.set(d,c.parent),n.delete(d);}if(l.length===s.length)return false;s=l;}return true}function $r(t,e){let{nodes:n,parentIndex:o,childrenSnapshot:r,partRoots:i}=t;if(e)for(let a of e)o.delete(a);for(let a of i){let s=new Set,l=[{id:a,parent:null,exit:false}];for(;l.length>0;){let d=l.pop();if(d.exit){s.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)),s.has(c))continue;let p=n.get(c);if(!M(p)||Oe(p))continue;let u=r.get(c)??te(p)?.toArray()??[];s.add(c),l.push({id:c,parent:null,exit:true});let f=new Set,h=[];for(let m of u)f.has(m)||m===c||(f.add(m),h.push(m));for(let m=h.length-1;m>=0;m-=1)l.push({id:h[m],parent:c,exit:false});}}}function Ha(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&&(Pp(t,n)||$r(t,new Set(n)));}function Ga(t,e){return `${t}${ee}${e}`}function Wr(t,e,n,o,r){if(v(n)||v(o.localName))return;let i=pt(t.namespaces,o.namespaceUri,e),a=No(n,i,o.localName);v(a)||t.attributes.set(a,Oi(o.prefix??"",r));}function qa(t,e,n,o){t.attributes.delete(No(e,Ge(n),o));}function Vr(t,e,n,o,r){if(v(n)||v(o))return;let i=pt(t.namespaces,r,e),a=Mo(n,o);v(a)||t.bindings.set(a,i);}function Za(t,e,n){t.bindings.delete(Mo(e,n));}function Qa(t,e,n,o,r,i){let{prefix:a,value:s}=Ei(i),l=e.get(n);l||(l=new Map,e.set(n,l)),l.set(Ga(o,r),{namespaceUri:qe(t.namespaces,o),localName:r,prefix:a.length>0?a:void 0,value:s});}function Np(t,e,n,o){let r=t.get(e);r&&(r.delete(Ga(n,o)),r.size===0&&t.delete(e));}function el(t,e,n,o,r){let i=e.get(n);i||(i=new Map,e.set(n,i)),i.set(o,{prefix:o,namespaceUri:qe(t.namespaces,r)});}function Mp(t,e,n){let o=t.get(e);o&&(o.delete(n),o.size===0&&t.delete(e));}function tl(t,e,n){for(let[o,r]of n.changes.keys){let i=Bt(String(o));if(!i||v(i.logicalId)||v(i.localName))continue;if(r.action==="delete"){Np(e,i.logicalId,i.namespaceId,i.localName);continue}let a=t.attributes.get(String(o));typeof a=="string"&&Qa(t,e,i.logicalId,i.namespaceId,i.localName,a);}}function nl(t,e,n){for(let[o,r]of n.changes.keys){let i=Ze(String(o));if(!i||v(i.logicalId)||v(i.prefix))continue;if(r.action==="delete"){Mp(e,i.logicalId,i.prefix);continue}let a=t.bindings.get(String(o));typeof a=="string"&&el(t,e,i.logicalId,i.prefix,a);}}function ol(t,e,n){t.attributes.forEach((o,r)=>{if(typeof o!="string"||v(r))return;let i=Bt(r);!i||v(i.logicalId)||v(i.localName)||Qa(t,e,i.logicalId,i.namespaceId,i.localName,o);}),t.bindings.forEach((o,r)=>{if(typeof o!="string"||v(r))return;let i=Ze(r);!i||v(i.logicalId)||v(i.prefix)||el(t,n,i.logicalId,i.prefix,o);});}function Kr(t,e,n){let o=t.listings.get(e)??new Set;o.add(n),t.listings.set(e,o);}function Dp(t,e,n){let o=t.listings.get(e);o&&(o.delete(n),o.size===0&&t.listings.delete(e));}function rl(t,e,n){let o=t.childrenSnapshot.get(e)??[];if(fn(o,n))return [];let r=new Set(n),i=new Set(o),a=[];for(let s of o)r.has(s)||(Dp(t,s,e),a.push(s));for(let s of n)i.has(s)||(Kr(t,s,e),a.push(s));return t.childrenSnapshot.set(e,n),a}var _p=1024,Wn=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=pn(o);if(n!==void 0&&n!==r&&this.recompute(n),r!==null){if(Oe(o)){let i=this.sources.get(r)??new Set;i.add(e),this.sources.set(r,i),this.survivorOf.set(e,r);}this.recompute(r);}}recomputeListerSurvivors(e){for(let n of this.reads.listersOf(e)){let o=this.survivorOf.get(n);o!==void 0&&this.recompute(o);}}isContentWitness(e){let n=this.reads.kindOf(e);return n!==null&&!n.endsWith("Properties")}recompute(e){let n=new Set,o=e;for(;o!==void 0&&!n.has(o)&&n.size<_p;)n.add(o),this.recomputeOne(o),o=this.survivorOf.get(o);}recomputeOne(e){let n=[],o=new Set,r=Yi(this.nodes,this.sources.get(e));for(let i of r){let a=this.nodes.get(i);if(!a)continue;let s=te(a)?.toArray()??[];for(let l of [...s,...this.adoptees.get(i)??[]])o.has(l)||this.reads.isTombstoned(l)||!this.nodes.has(l)||this.isContentWitness(l)&&(o.add(l),n.push(l));}n.length>0?this.adoptees.set(e,n):this.adoptees.delete(e);}};function st(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 Yp=/^\d{10}$/,Jr=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,a=o;if(r<e.length&&e[r]<e[a]&&(a=r),i<e.length&&e[i]<e[a]&&(a=i),a===o)break;[e[a],e[o]]=[e[o],e[a]],o=a;}}}};function Et(t){return t.first()}function Bp(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 Vn=class{constructor(e,n,o,r){this.nodes=e;this.limits=n;this.isDeleted=o;this.follow=new Nn(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=ye(e),o=this.nodes.doc;if(!o||!n)return null;let{client:r,clock:i}=n,a=ce(o,{client:r,clock:i})?.parent;if(!(a instanceof B.Text)||$e(a)!==ne)return null;let s=Ne(a)?.parent,l=s instanceof B.Map?$e(s):null;if(l===null||v(l))return null;let d=V(l);return this.textOf(d)===a?d:null}isDeletedParagraph(e){return this.isDeleted(e)}textOf(e){let n=this.nodes.get(e);if(!M(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(st(d)===o)return d;for(let d of i)for(let c of this.follow.targetsFor(d))if(st(c)===o)return c;let l=this.paragraphTagged(o);if(l)return l}return Et(i)}if(n!==e&&this.textOf(n))return n;let a=n.lastIndexOf("~");if(a<0)return null;let s=n.slice(a+1);o===null&&Yp.test(s)&&(o=s),n=n.slice(0,a);}return null}paragraphTagged(e){for(let o of this.idsOf.keys())if(st(o)===e)return o;let n=null;return this.nodes.forEach((o,r)=>{n===null&&st(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}~${st(e)}`;let o=this.holders.get(n);return o&&!o.has(e)?`${n}~${st(e)}`:!o||o.size<2||Et(o)===e?n:`${n}~${st(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||Et(o)===e},shown:n=>this.follow.shown(e,n),textOf:n=>this.textOf(n),lineageOf:n=>Ns(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($e(o)!==ne)continue;let r=Ne(o)?.parent,i=r instanceof B.Map?$e(r):null;if(i===null||v(i))continue;let a=V(i);this.textOf(a)===o&&(this.follow.invalidate(a),this.paragraphChanged(a),n.add(a));}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 a of i.toDelta()){if(typeof a.insert=="object"&&a.insert!==null){let s=a.insert.n;typeof s=="string"&&(o.add(s),r.add(s));}for(let s of Bp(he(a.attributes,this.limits,e)))o.add(s);}for(let a of n)o.has(a)||this.release(a,e);for(let a of o)n.has(a)||this.hold(a,e);for(let a of r)this.embeds.add(a);o.size>0?this.idsOf.set(e,o):this.idsOf.delete(e),this.noteOthers(this.follow.paragraphChanged(e));}noteOthers(e){for(let n of e)this.affected.add(n);e.size>0&&this.noteDrift();}orderChanged(){if(this.built)for(let e of this.follow.orderChanged())this.affected.add(e);}recordArrived(e){if(this.built)for(let n of this.holders.get(e)??[])this.holderAffected(n);}holderAffected(e){this.affected.add(e);for(let n of this.follow.placedTargetsFor(e))this.affected.add(n);}listingChanged(e){if(this.built){for(let n of this.holders.get(e)??[])this.holderAffected(n);this.textOf(e)&&(this.noteOthers(this.follow.paragraphChanged(e)),this.affected.add(e));}}hold(e,n){let o=this.holders.get(e);if(o||(o=new Jr,this.holders.set(e,o)),o.size>0){let i=Et(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=Et(o)===n;if(o.delete(n),o.size===0){this.holders.delete(e),this.embeds.delete(e);return}r&&this.affected.add(Et(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)=>{M(e)&&e.get(ne)instanceof B.Text&&this.paragraphChanged(V(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 Ct(t){return typeof t=="string"?t:""}function il(t){let e=[];return t.forEach((n,o)=>{if(!M(n)||v(o))return;let r=Ct(n.get("rootId"));r.length!==0&&e.push({name:o,id:Ct(n.get("id")),rootLogicalId:r,contentType:Ct(n.get("contentType"))});}),e.sort((n,o)=>n.name<o.name?-1:n.name>o.name?1:0),e}function sl(t){let e=new Map;return t.forEach((n,o)=>{typeof n=="string"&&!v(o)&&e.set(partNameKey(o),n);}),e}function al(t){let e=new Map;return t.forEach((n,o)=>{typeof n=="string"&&!v(o)&&e.set(o,n);}),e}function ll(t){let e=[];return t.forEach((n,o)=>{if(!M(n)||v(o))return;let r=Ct(n.get("digest")),i=n.get("size"),a=Ct(n.get("mediaType")),s=Ct(n.get("storageKey"))||o;r.length===0||typeof i!="number"||e.push({digest:r,size:i,mediaType:a,storageKey:s});}),e}var Xr="/word/numbering.xml",Fp="http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering";function dl(t,e){let n=e.parent;if(n===t.bindings&&e.parentSub){let s=Ze(e.parentSub),l=s&&t.nodes.get(s.logicalId);if(l){let d=Re(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===Xr||n===t.parts&&e.parentSub===Xr)return true;let o=Ne(n);if(o?.parent===t.parts&&o.parentSub===Xr)return true;let r=s=>s instanceof B.Map&&s.get("type")===Fp,i=s=>s instanceof B.Map&&[...s.values()].some(r);return n===t.relationships?e.content.getContent().some(i):o?.parent===t.relationships?e.content.getContent().some(r):Ne(o?.parent)?.parent===t.relationships&&r(n)}function jp(t){return t.content instanceof B.ContentType}function ul(t){return e=>{let n=e.parent;if(n===null)return true;if(n===t)return false;let o=Ne(n);return o===null||o.parent!==t?true:e.parentSub===Xe||e.parentSub===an?false:!jp(e)}}var Pe=class{constructor(e,n){this.doc=e;this.stopKeepingMarkers=ci(e),this.schema=Li(e),this.limits=xi(n),this.splitDedup=new Yn(this.schema.nodes),this.inline=new Vn(this.schema.nodes,this.limits,o=>this.isTombstoned(o)||!this.parentIndex.has(o),(o,r)=>$a({parentOf:i=>this.parentIndex.get(i),childrenOf:i=>this.childrenSnapshot.get(i),maxDepth:this.limits.maxTreeDepth},o,r)),this.adoption=new Wn(this.schema.nodes,{kindOf:o=>this.kindOf(o),isTombstoned:o=>this.isTombstoned(o),listersOf:o=>this.listings.get(o)??[]}),this.splitTextSources=new Rt(this.schema.nodes,this.doc,this.limits),this.stopMarks=ja(e,{inline:this.inline,loading:()=>this.bulkLoad>0,changed:o=>{for(let r of this.markListeners)r(o);}}),this.stopObserving=Xa(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 jn;contested=new Set;structureVersion=0;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(hr)]}undoDeleteFilter(){let e=ul(this.schema.nodes);return n=>!dl(this.schema,n)&&e(n)}encodeSnapshot(){return B.encodeStateAsUpdate(this.doc)}encodeUpdate(e){return B.encodeStateAsUpdate(this.doc,e)}partEntries(){return il(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 $i(this.schema.meta.get("mainDocumentPart"))}record(e){if(v(e))return null;let n=this.schema.nodes.get(e);if(!M(n))return null;if(ft(n)){let o=n.get(ue),r=o instanceof B.Text?o.toString():"";return {logicalId:e,kind:"textValue",value:r}}return ji(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&&j(o)?o.attributes:[];return {logicalId:e,yjsItemKey:zi(n),wordFacingIds:bi(r)}}isTombstoned(e){return Oe(this.schema.nodes.get(e))}replacedByOf(e){return pn(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(Ge(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(Uo)}nodeCount(){return this.nodeCountCache<0&&(this.nodeCountCache=this.schema.nodes.size),this.nodeCountCache+this.pendingNodeAdds}nodeShape(e){return v(e)?null:Ui(this.schema.nodes,e)}kindOf(e){return v(e)?null:Fi(this.schema.nodes,e)}noteNodeWrite(e){this.schema.nodes.has(e)||(this.pendingNodeAdds+=1);}putElement(e){this.noteNodeWrite(e.logicalId);let n=pt(this.schema.namespaces,e.namespaceUri,this.limits.maxStringLength);this.schema.nodes.set(e.logicalId,Ci({logicalId:e.logicalId,kind:e.kind,namespaceUri:e.namespaceUri,namespaceId:n,localName:e.localName,prefix:e.prefix}));for(let o of e.attributes)Wr(this.schema,this.limits.maxStringLength,e.logicalId,o,o.value);for(let o of e.bindings)Vr(this.schema,this.limits.maxStringLength,e.logicalId,o.prefix,o.namespaceUri);}updateElementShell(e,n){let o=this.require(e),r=pt(this.schema.namespaces,n.namespaceUri,this.limits.maxStringLength);o.set(sn,Po(n.kind,r,n.localName,n.prefix??""));}putText(e,n){this.noteNodeWrite(e),this.schema.nodes.set(e,dn(n));}spliceText(e,n,o,r){let i=this.splitTextSources.range(e),a=_n(this.schema.nodes,this.splitTextSources,e,i,n,r),s=i?.text??this.textOf(e),l=(i?.start??0)+n;i===null&&this.splitTextSources.isPlain(e)?(r.length>0&&s.insert(l,r),o>0&&s.delete(l+r.length,o)):(o>0&&s.delete(l,o),r.length>0&&s.insert(l,r)),a?.();}setAttribute(e,n,o){if(o===null){qa(this.schema,e,n.namespaceUri,n.localName);return}Wr(this.schema,this.limits.maxStringLength,e,n,o);}setNamespaceBinding(e,n,o){if(o===null){Za(this.schema,e,n);return}Vr(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(Le,true),n&&o.set(Ke,n);}recordRunSplit(e,n,o){this.splitDedup.record(e,n,o);}splitOriginOf(e){return Ut(this.schema.nodes.get(e))}splitLineageOf(e){return Qe(this.schema.nodes.get(e))}replacementLoserRuns(){return this.hasUnobservedWrites()&&this.splitDedup.invalidate(),this.splitDedup.loserRuns({isPresent:e=>Va(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 a of n)i.set(a,(i.get(a)??0)+1);for(let a=r.length-1;a>=0;a-=1){let s=r.get(a),l=i.get(s)??0;l!==0&&(i.set(s,l-1),r.delete(a,1));}}putXmlPart(e){this.partCountCache=-1,this.schema.parts.set(e.name,Ti(e.id,e.rootLogicalId,e.contentType));}deleteXmlPart(e){this.partCountCache=-1,this.schema.parts.delete(e);}putRelationship(e){if(v(e.ownerPart)||v(e.id))return;this.relationshipCountCache=-1;let n=new B.Map;n.set(e.id,Ai(e)),this.schema.relationships.set(jr(e.ownerPart,e.id),n);}deleteRelationship(e,n){this.relationshipCountCache=-1,this.schema.relationships.delete(jr(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,Pi(e));}deleteBinary(e){this.schema.binaries.delete(e);}relationships(){return Ja(this.schema.relationships)}contentTypeOverrides(){return sl(this.schema.overrides)}contentTypeDefaults(){return al(this.schema.defaults)}binaries(){return ll(this.schema.binaries)}hasNode(e){return this.schema.nodes.has(e)}showsAsChild(e){let n=this.schema.nodes.get(e);return n===void 0||Oe(n)?false:!(ft(n)&&this.splitTextPending(e))}observeDirty(e){let n=Wa(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(!Uo(o))return;let r=te(n);if(!r)return;let i=r.toArray();this.childrenSnapshot.set(o,i);for(let a of i)Kr(this.listingIndex(),a,o);}),this.schema.nodes.forEach((n,o)=>{Oe(n)&&this.adoption.sync(V(o)),this.splitDedup.indexExisting(V(o));}),ol(this.schema,this.attributesByNode,this.bindingsByNode),$r(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(){Wi(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(V(r.path[0])),r.target instanceof B.Text&&r.path[1]===ne){this.inline.paragraphChanged(V(r.path[0]));continue}if(r.target instanceof B.Map&&r.path.length===1&&(r.changes.keys.has(ne)||r.changes.keys.has(Le))&&this.inline.paragraphChanged(V(r.path[0])),r.path.length===0&&r.target instanceof B.Map){o=true;for(let[i,a]of r.changes.keys)if(this.nodeCountCache>=0&&a.action!=="update"&&(this.nodeCountCache+=a.action==="add"?1:-1),!v(String(i))){if(a.action==="delete"){this.inline.paragraphChanged(V(i));continue}this.splitDedup.indexExisting(V(i)),this.splitTextSources.noteChanged(V(i));for(let s of this.syncChildListings(V(i)))n.add(s);this.inline.paragraphChanged(V(i)),this.inline.recordArrived(V(i)),this.isTombstoned(V(i))&&this.adoption.sync(V(i)),this.adoption.recomputeListerSurvivors(V(i));}continue}if(r.target instanceof B.Map&&r.path.length===1&&r.changes.keys.has(Je)&&this.history.noteMarkChanged(V(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(V(r.path[0])),r.target instanceof B.Array&&r.path.length>0){o=true;let i=V(r.path[0]);for(let a of this.syncChildListings(i))n.add(a);this.isTombstoned(i)&&this.adoption.sync(i);continue}if(r.target instanceof B.Map&&r.path.length===1&&(r.changes.keys.has(Le)||r.changes.keys.has(Ke))){o=true;let i=V(r.path[0]);this.adoption.sync(i),this.adoption.recomputeListerSurvivors(i);for(let a of this.childrenSnapshot.get(i)??[])n.add(a);}}if(o)for(let r of this.contested)n.add(r);n.size>0&&this.resolveParents(n),o&&(this.structureVersion+=1,this.inline.orderChanged());}takeUnlisted(){return this.history.takeUnlisted(e=>this.parentIndex.has(e))}takeReparented(){let e=[...this.reparented];return this.reparented.clear(),e}applyAttributeMapEvent(e){this.unobservedWrites=0,tl(this.schema,this.attributesByNode,e);}applyBindingMapEvent(e){this.unobservedWrites=0,nl(this.schema,this.bindingsByNode,e);}syncChildListings(e){let n=this.schema.nodes.get(e),o=n?te(n)?.toArray()??[]:[];return rl(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){Ha(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(ue);if(!(n instanceof B.Text))throw new Error(`no text at ${e}`);return n}childArray(e){let n=this.require(e).get(ln);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 Kn=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 zp(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 fl(t){let e=t.binaryPart;return typeof e=="function"?e:null}function hl(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 ml(t,e){for(let n of e)t.put(n.digest,n.bytes);}function Wp(t){return t.attributes.map(e=>({namespaceUri:e.namespaceUri,localName:e.localName,prefix:e.prefix,value:e.value}))}function Vp(t){return t.namespaceBindings.map(e=>({prefix:e.prefix,namespaceUri:e.namespaceUri}))}function Jn(t,e,n,o,r){if(o>t.limits.maxTreeDepth)return "tree-too-deep";if(v(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(N(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(ie(e.namespaceUri,t.limits.maxStringLength))return "invalid-string";for(let i of e.attributes){if(v(i.localName))return "prototype-key";if(ie(i.namespaceUri,t.limits.maxStringLength))return "invalid-string"}for(let i of e.namespaceBindings){if(v(i.prefix))return "prototype-key";if(ie(i.namespaceUri,t.limits.maxStringLength))return "invalid-string"}if(t.putElement({logicalId:N(e),kind:e.kind,namespaceUri:e.namespaceUri,localName:e.localName,prefix:e.prefix,attributes:Wp(e),bindings:Vp(e)}),e.kind==="paragraph"){let i=Kp(t,e,o,r);if(i)return i}else for(let i of e.children){let a=Jn(t,i,N(e),o+1,r);if(a)return a}}return n&&t.childArray(n).push([N(e)]),null}function Kp(t,e,n,o){let r=yn(e);for(let s of r.shell.children){let l=Jn(t,s,N(e),n+1,o);if(l)return l}let i=0;for(let s of r.items){if(i+=1,s.kind!=="embed")continue;let l=Jn(t,s.node,null,n+1,o);if(l)return l}if(i>t.limits.maxTextLength)return "text-too-long";let a=t.schema.nodes.get(e.id);if(!a)return null;try{Ln(a,ps(r.items,e.id,t.limits));}catch(s){if(s instanceof be)return s.code;throw s}return null}async function Jp(t){let e=[],n=[];for(let[o,r]of t.partBytes){if(t.parts.has(o))continue;let a=t.contentTypes.overrides.get(o)??"application/octet-stream",s=Z(o);if(s)return {ok:false,code:s};if(r.byteLength>We.maxBlobBytes)return {ok:false,code:"blob-too-large"};let l=await zp(r);n.push({digest:l,bytes:r}),e.push({digest:l,size:r.byteLength,mediaType:a,storageKey:o});}return {ok:true,descriptors:e,payloads:n}}async function Xn(t,e,n=new Kn){if(e.parts.size>t.limits.maxParts)return {ok:false,code:"too-many-parts"};let o=await Jp(e);if(!o.ok)return o;let r=null;t.beginBulkLoad();try{t.doc.transact(()=>{for(let s of o.payloads)n.put(s.digest,s.bytes);let i={nodes:0};for(let[s,l]of e.parts){let d=Z(s);if(d){r=d;return}if(ie(l.contentType,t.limits.maxMediaTypeLength)){r="invalid-string";return}let c=Jn(t,l.root,null,0,i);if(c){r=c;return}t.putXmlPart({name:s,id:l.id,rootLogicalId:N(l.root),contentType:l.contentType});}let a=0;for(let s of e.relationships.values())for(let l of s){if(a+=1,a>t.limits.maxRelationships){r="too-many-relationships";return}if(l.ownerPart!=="/"){let d=Z(l.ownerPart);if(d){r=d;return}}if(v(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[s,l]of e.contentTypes.defaults){if(v(s)){r="prototype-key";return}t.putContentTypeDefault(s,l);}for(let[s,l]of e.contentTypes.overrides){let d=Z(s);if(d){r=d;return}t.putContentTypeOverride(s,l);}for(let s of o.descriptors)t.putBinary(s);Ni(t.schema.meta),t.schema.meta.set("mainDocumentPart",e.mainDocumentPart);},vi);}finally{t.endBulkLoad();}return r?{ok:false,code:r}:{ok:true}}function Ie(t,e){return t.attributes.find(n=>n.localName===e)?.value}function Gr(t){return t.kind==="textValue"?t.id:Ie(t,"id")??t.id}function qt(t,e){if(t.length===e.length&&t.every((a,s)=>a===e[s]))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 bl(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(Ee(n,qt(n.children,e)));return Object.freeze({...t,root:o})}function Xp(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 Sl(t){}function kl(t,e){return Object.freeze({id:t,kind:"textValue",value:e})}function ef(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 tf(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 Hn(t,e,n){let o=n&&n.kind!=="textValue"?n:void 0;return Object.freeze(pe({id:t.logicalId,kind:t.kind,namespaceUri:t.namespaceUri,localName:t.localName,...t.prefix===void 0?{}:{prefix:t.prefix},namespaceBindings:o&&ef(o,t)?o.namespaceBindings:Object.freeze(t.bindings.map(r=>Object.freeze({...r}))),attributes:o&&tf(o,t)?o.attributes:Object.freeze(t.attributes.map(Xp)),children:e}))}function vl(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 qr(t,e){let n=e.size;e.add(N(t));let o=e.size!==n;if(t.kind==="textValue")return o;for(let r of t.children)qr(r,e)||(o=false);return o}function Ll(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(),a=t.isTombstoned(i)?t.replacedByOf(i):null;a!==null&&r(a);let s=t.listingParents(i),l=t.parentOf(i);for(let d of l===null?s:[l,...s]){r(d);let c=t.isTombstoned(d)?t.replacedByOf(d):null;c!==null&&r(c);}}return n}var qn="http://schemas.openxmlformats.org/package/2006/relationships",nf="application/vnd.openxmlformats-package.relationships+xml",Rl=/^(.*)\/_rels\/([^/]*)\.rels$/;function Zn(t){return Rl.test(t)}function Ol(t){let e=Rl.exec(t);return e?e[2]===""?"/":`${e[1]}/${e[2]}`:null}function Gn(t,e){return Object.freeze({kind:"genericExtension",namespaceUri:"",localName:t,value:e})}function of(t,e){let n=[Gn("Id",e.id),Gn("Type",e.type),Gn("Target",e.rawTarget)];return e.targetMode==="External"&&n.push(Gn("TargetMode","External")),Object.freeze(pe({id:t,kind:"generic",namespaceUri:qn,localName:"Relationship",namespaceBindings:Object.freeze([]),attributes:Object.freeze(n),children:Object.freeze([])}))}function El(t,e){if(t.kind==="textValue"||t.namespaceUri!==qn||t.localName!=="Relationship"||Ie(t,"Id")!==e.id||Ie(t,"Type")!==e.type||Ie(t,"Target")!==e.rawTarget)return false;let n=Ie(t,"TargetMode");return e.targetMode==="External"?n==="External":n===void 0}function Cl(t,e){return t.children.length!==e.length?false:t.children.every((n,o)=>El(n,e[o]))}function Tl(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 Al(t,e,n){let o=[];for(let r of e){if(v(r.id))continue;let i=t.find(s=>s.kind!=="textValue"&&Ie(s,"Id")===r.id);if(i&&El(i,r)){o.push(i);continue}let a=i&&i.kind!=="textValue"?N(i):`${n}#rel-${r.id}`;v(a)||o.push(of(a,r));}return o}function rf(t){return Object.freeze(pe({id:`${t}#root`,kind:"generic",namespaceUri:qn,localName:"Relationships",namespaceBindings:Object.freeze([Object.freeze({prefix:"",namespaceUri:qn})]),attributes:Object.freeze([]),children:Object.freeze([])}))}function Pl(t){return Object.freeze({id:t,name:t,contentType:nf,root:rf(t)})}function Nl(t){let e=new Map;for(let n of t){if(v(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 Yl=/^\/customXml\/item(\d+)\.xml$/i,df=/^\/customXml\/itemProps(\d+)\.xml$/i;function Qt(t){return Yl.test(t)}function Qr(t){return df.test(t)}function cf(t){let e=Yl.exec(t);if(!e)return null;let n=Number(e[1]);return Number.isSafeInteger(n)&&n>0?n:null}function Ml(t){return {item:`/customXml/item${String(t)}.xml`,props:`/customXml/itemProps${String(t)}.xml`}}function uf(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 Dl(t,e){let n=t.record(e);return !n||!j(n)?e:n.attributes.find(r=>r.localName==="id"&&r.value.length>0)?.value??e}function pf(t,e){let n=t.record(e);if(!n||!j(n))return null;for(let o of n.childIds){let r=t.record(o);if(!(!r||!j(r)||r.localName!=="schemaRefs")&&r.namespaceUri===DATASTORE_NAMESPACE_URI)for(let i of r.childIds){let a=t.record(i);if(!a||!j(a)||a.localName!=="schemaRef")continue;let s=uf(a,"uri",DATASTORE_NAMESPACE_URI);if(s)return s}}return null}function ff(t,e){return e.childIds.some(n=>{let o=t.record(n);return !!o&&j(o)&&o.localName==="node"&&o.namespaceUri===e.namespaceUri})}function hf(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:ff(t,e)}function mf(t,e){return e.localName!=="datastoreItem"||e.namespaceUri!==DATASTORE_NAMESPACE_URI?false:t.parentOf(e.logicalId)===null}function Bl(t,e){if(!t.hasNamespace(DATASTORE_NAMESPACE_URI))return [];let n=new Map,o=new Map;for(let[u,f]of e){let h=t.record(N(f.root));!h||!j(h)||(Qt(u)&&n.set(h.logicalId,h),Qr(u)&&o.set(h.logicalId,h));}for(let u of t.allLogicalIds()){if(t.isTombstoned(u)||n.has(u)||o.has(u))continue;let f=t.record(u);!f||!j(f)||(hf(t,f)?n.set(u,f):mf(t,f)&&o.set(u,f));}if(n.size===0)return [];let r=new Map;for(let u of n.values()){let f=r.get(u.namespaceUri)??[];f.push(u),r.set(u.namespaceUri,f);}let i=new Map;for(let u of o.values()){let f=pf(t,u.logicalId);if(!f)continue;let h=i.get(f)??[];h.push(u),i.set(f,h);}let a=[];for(let[u,f]of r){let h=i.get(u);if(!h||h.length===0)continue;f.sort((y,k)=>y.logicalId.localeCompare(k.logicalId)),h.sort((y,k)=>y.logicalId.localeCompare(k.logicalId));let m=f[0],b=h[0],w=[],E=new Set;for(let y of f)for(let k of y.childIds){if(E.has(k))continue;let I=t.record(k);!I||!j(I)||I.localName!=="node"||I.namespaceUri!==u||(E.add(k),w.push(k));}for(let y of t.allLogicalIds()){if(E.has(y)||t.isTombstoned(y))continue;let k=t.record(y);!k||!j(k)||k.localName!=="node"||k.namespaceUri!==u||(E.add(y),w.push(y));}w.sort((y,k)=>Dl(t,y).localeCompare(Dl(t,k))),a.push({data:m,props:b,nodeIds:w});}a.sort((u,f)=>u.data.logicalId.localeCompare(f.data.logicalId));let s=new Set,l=[],d=new Set,c=new Set;for(let[u,f]of e){let h=cf(u);if(h===null)continue;let m=a.find(E=>E.data.logicalId===f.root.id&&!d.has(E.data.logicalId));if(!m)continue;let b=Ml(h).props,w=e.get(b);w&&w.root.id!==m.props.logicalId||(s.add(h),d.add(m.data.logicalId),c.add(m.props.logicalId),l.push({dataRootId:m.data.logicalId,propsRootId:m.props.logicalId,namespaceUri:m.data.namespaceUri,itemName:u,propsName:b,nodeIds:m.nodeIds}));}let p=1;for(let u of a){if(d.has(u.data.logicalId))continue;for(;s.has(p);)p+=1;s.add(p);let f=Ml(p);l.push({dataRootId:u.data.logicalId,propsRootId:u.props.logicalId,namespaceUri:u.data.namespaceUri,itemName:f.item,propsName:f.props,nodeIds:u.nodeIds}),p+=1;}return l.sort((u,f)=>u.itemName.localeCompare(f.itemName)),l}function gf(t){return t.type===CUSTOM_XML_REL||t.type===CUSTOM_XML_PROPS_REL?true:Qt(t.ownerPart)}function yf(t){let e=/^rId(\d+)$/.exec(t);if(!e)return 0;let n=Number(e[1]);return Number.isSafeInteger(n)?n:0}function bf(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 Ul(t,e){if(e.length===0)return [];let n=t.mainDocumentPart();if(!n)return [];let o=t.relationships(),r=o.filter(s=>s.ownerPart===n&&s.type===CUSTOM_XML_REL).sort((s,l)=>s.id.localeCompare(l.id)),i=0;for(let s of o)i=Math.max(i,yf(s.id));let a=[];for(let s=0;s<e.length;s+=1){let l=e[s],d=r[s],c=d?.id??`rId${String(i+=1)}`;a.push({ownerPart:n,id:c,type:CUSTOM_XML_REL,rawTarget:bf(n,l.itemName),targetMode:"Internal",order:d?.order??s}),a.push({ownerPart:l.itemName,id:"rId1",type:CUSTOM_XML_PROPS_REL,rawTarget:l.propsName.slice(l.propsName.lastIndexOf("/")+1),targetMode:"Internal",order:0});}return a}function Fl(t,e){return e.length===0?[...t]:[...t.filter(n=>!gf(n)),...e]}function jl(t){let e=new Map;for(let n of t)e.set(partNameKey(n.propsName),CUSTOM_XML_PROPS_TYPE);return e}function ei(t,e){if(e.length===0)return false;let n=[...t.keys()].filter(Qt).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),a=t.get(r.propsName);if(!i||i.root.id!==r.dataRootId||!a||a.root.id!==r.propsRootId)return true}return false}function zl(t,e){if(ei(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(s=>s.id));if(n.nodeIds.some(s=>!r.has(s)))return true;let i=[];for(let s of o.root.children)s.kind!=="textValue"&&i.push(s.attributes.find(l=>l.localName==="id")?.value??s.id);let a=[...i].sort((s,l)=>s.localeCompare(l));if(i.some((s,l)=>s!==a[l]))return true}return false}var If="http://schemas.microsoft.com/office/word/2012/wordml";function Qn(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 $l(t){return e=>e.localName===t&&e.namespaceUri===WML_NAMESPACE_URI}function xf(t){return t.localName==="abstractNum"?`0${Qn(Ie(t,"abstractNumId"))}`:`1${Qn(Ie(t,"numId"))}`}function Sf(t){return t.namespaceUri!==WML_NAMESPACE_URI?false:t.localName==="abstractNum"||t.localName==="num"}function ti(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===If,sortKey:e=>e.id,adoptedAfterListed:true}:t.localName==="footnotes"&&t.namespaceUri===WML_NAMESPACE_URI?{isMember:$l("footnote"),sortKey:e=>Qn(Ie(e,"id"))}:t.localName==="endnotes"&&t.namespaceUri===WML_NAMESPACE_URI?{isMember:$l("endnote"),sortKey:e=>Qn(Ie(e,"id"))}:t.localName==="numbering"&&t.namespaceUri===WML_NAMESPACE_URI?{isMember:Sf,sortKey:xf}:null}function Wl(t,e){for(let n of t)if(n.root.id===e)return ti(n.root)?n.root.children.map(N):null;return null}function Vl(t,e){let n=null;for(let o of t.listingParents(e)){let r=t.record(o);if(!(!r||!j(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 Kl(t,e,n){let o=t.record(n),r=!!o&&(He(o)?o.value.length>0:o.childIds.length>0||o.attributes.length>0);e(r?"orphan-with-content":"orphan",n);}function Jl(t,e,n,o,r,i){if(!r){for(let l of n)t.isTombstoned(l)||o.has(l)||(Kl(t,e,l),i.add(l));return}let a=new Set(t.partEntries().map(l=>l.rootLogicalId)),s=new Set;for(let l of n)s.has(l)||(s.add(l),wf(t,e,l,o,a)&&i.add(l));}function wf(t,e,n,o,r){let i=false,a=new Set,s=[{id:n,underTombstone:false}];for(;s.length>0;){let{id:l,underTombstone:d}=s.pop();if(!(a.has(l)||a.size>=t.limits.maxTreeDepth)){if(a.add(l),t.isTombstoned(l)){let c=t.record(l);if(c&&j(c))for(let p of c.childIds)s.push({id:p,underTombstone:true});continue}r.has(l)||(d?o.has(l):Vl(t,l))||(Kl(t,e,l),i=true);}}return i}function Xl(t,e,n,o,r,i,a,s,l){let d=0;for(let c of s){if(i.has(c)||o.has(c)||t.isTombstoned(c)||un(t.schema.nodes.get(c))||a&&Vl(t,c))continue;let p=t.record(c);if(!p||!j(p)||!r(p))continue;let u=e(c);!u||u.kind==="textValue"||(n.push(u),o.add(c),l.add(c),d+=1);}return d}var _e="application/vnd.openxmlformats-officedocument.wordprocessingml",Rf=new Map(Object.entries({comments:{root:"comments",contentType:`${_e}.comments+xml`},commentsExtended:{root:"commentsEx",contentType:`${_e}.commentsExtended+xml`},commentsIds:{root:"commentsIds",contentType:`${_e}.commentsIds+xml`},commentsExtensible:{root:"commentsExtensible",contentType:`${_e}.commentsExtensible+xml`},people:{root:"people",contentType:`${_e}.people+xml`},footnotes:{root:"footnotes",contentType:`${_e}.footnotes+xml`},endnotes:{root:"endnotes",contentType:`${_e}.endnotes+xml`},numbering:{root:"numbering",contentType:`${_e}.numbering+xml`}}));function Of(t){return Z(t)===null&&!Zn(t)&&t.toLowerCase()!=="/[content_types].xml"&&t.toLowerCase().endsWith(".xml")}function Hl(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=Rf.get(d.type.slice(d.type.lastIndexOf("/")+1));if(!c)continue;let p=resolveInternalTarget(d.ownerPart,d.rawTarget);!p.ok||o.has(p.partName)||!Of(p.partName)||(o.add(p.partName),r.push({name:p.partName,...c}));}if(r.length===0)return [];let i=new Set(e.map(d=>d.rootLogicalId)),a=new Set(r.map(d=>d.root)),s=[];for(let d of t.allLogicalIds()){if(i.has(d)||t.isTombstoned(d)||t.parentOf(d)!==null)continue;let c=t.record(d);!c||!j(c)||!a.has(c.localName)||c.bindings.some(p=>p.prefix===(c.prefix??""))&&s.push({id:d,root:c.localName,empty:c.childIds.length===0});}let l=[];for(let d of r){let c=null;for(let{id:p,root:u,empty:f}of s)u!==d.root||i.has(p)||(c===null||c.empty&&!f||c.empty===f&&p<c.id)&&(c={id:p,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 Gl(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 eo=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:Fl(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:Nl(n)}),this.grouped.map}relationshipAssembly(e){let n=this.projected(e);return (!this.assembly||this.assembly.records!==n)&&(this.assembly={records:n,value:Tf(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 a=e.get(r.digest);if(!a)return null;Sl(a.length),this.blobBytes.set(r.storageKey,{digest:r.digest,bytes:a}),n.set(r.storageKey,a);}for(let r of [...this.blobBytes.keys()])o.has(r)||this.blobBytes.delete(r);return this.partBytes=n,n}};function Tf(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 to=class{textOverlays=new Map;losers=new Set;awaiting=new Set;update(e){let n=[],o=e.replacementLoserRuns(),r=a=>{n.push(a);let s=e.parentOf(a);s!==null&&n.push(s);};for(let a of o)this.losers.has(a)||r(a);for(let a of this.losers)o.has(a)||r(a);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 ql(t,e){let n=t.children;for(let i of n){let a=N(i);if(e.placed.has(a)||!e.isCached(i)||e.dirty.has(a)&&!e.canRebuild(a))return null}let o=null,r=[];for(let i=0;i<n.length;i+=1){let a=n[i],s=N(a);if(!e.dirty.has(s)){e.placed.add(s),o?.push(a);continue}let l=e.rebuild(s);if(l===a){o?.push(a);continue}o??=n.slice(0,i),l?o.push(l):r.push(s);}return {children:o?Object.freeze(o):n,dropped:r}}var no=class{nodes=new Map;heights=new Map;complete=new Set;get(e){return this.nodes.get(e)}holds(e){return this.nodes.get(N(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 a=N(i);n.has(a)||this.evictSubtree(a,n,o);}}heightOf(e){let n=this.heights.get(N(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(N(e),o),o}setHeight(e,n){this.heights.set(e,n);}ids(){return [...this.nodes.keys()]}};function Zl(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 Af=4096,oo=class{constructor(e){this.registry=e;}registry;contested=false;matchesResolution=true;encountered=new Set;lastResolution=new Map;embedsMet=new Set;embedWinners=new Map;embedsDecidedAt=-1;reset(){this.contested=false,this.encountered.clear(),this.matchesResolution=true;}note(e,n,o,r){let i=this.registry,a=i.listingParents(e),s=a.length<=1?a:a.filter(l=>i.isTombstoned(l)?i.replacedByOf(l)!==null:r.has(l)||i.listingParents(l).length>0);s.length<=1||(this.contested=true,this.encountered.add(e),s.some(l=>i.isTombstoned(l)&&i.replacedByOf(l)!==null)?this.matchesResolution=false:!o.has(e)&&i.parentOf(e)!==n&&(this.matchesResolution=false));}noteEmbed(e,n,o,r){let i=o.get(e);return i===void 0||i===n||r.has(i)?true:this.embedWinners.get(e)===i&&this.embedsDecidedAt===this.registry.structureVersion?false:(this.contested=true,this.matchesResolution=false,this.embedsMet.add(e),true)}recordEmbeds(e){this.embedsDecidedAt!==this.registry.structureVersion&&this.embedWinners.clear(),this.embedsDecidedAt=this.registry.structureVersion;for(let n of this.embedsMet){let o=e.get(n);o===void 0?this.embedWinners.delete(n):this.embedWinners.set(n,o);}this.embedsMet.clear(),this.embedWinners.size>Af&&this.embedWinners.clear();}decided(){if(!this.matchesResolution)return false;for(let e of this.encountered){let n=this.lastResolution.get(e);if(n===void 0||n!==this.registry.parentOf(e))return false}return true}record(e){let n=new Map;for(let o of this.encountered)n.set(o,this.registry.parentOf(o));for(let o of e)n.set(o,this.registry.parentOf(o));this.lastResolution=n;}};var ro=class{lastAdoption=new Map;changes(e){let n=[],o=new Map,r=(i,a)=>{let s=new Set(a);for(let l of i)if(!s.has(l))for(let d of e.listingParents(l))e.isTombstoned(d)||n.push(d);};for(let[i,a]of e.adoptionIndex()){let s=e.isTombstoned(i)?[]:[...a];o.set(i,s);let l=this.lastAdoption.get(i);(l===void 0||!fn(l,s))&&(n.push(i),l&&r(l,s));}for(let[i,a]of this.lastAdoption)o.has(i)||(n.push(i),r(a,[]));return this.lastAdoption=o,n}};var lt=class{constructor(e,n){this.registry=e;this.blobs=n;this.packageCache=new eo(e),this.contests=new oo(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 no;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 ro;mergeSources=new Map;builtMerges=new Map;contests;splitProjection=new to;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 p=this.registry.record(c);if(!(!p||!j(p)))for(let u of p.childIds)for(let f of this.registry.listingParents(u))e.add(f);}for(let c of this.splitProjection.update(this.registry))e.add(c);let r=Ll(this.registry,e);for(let c of e){let p=this.shownUnder.get(c);for(let u=0;p!==void 0&&u<this.registry.limits.maxTreeDepth;u++)r.add(p),p=this.shownUnder.get(p);}let i=this.partRoots=new Set(this.registry.partEntries().map(c=>c.rootLogicalId)),a=[...e].some(c=>i.has(c)||this.registry.parentOf(c)===null&&!this.registry.isTombstoned(c)),s=!this.forceFull&&this.pkg!==null&&!o&&!a&&(r.size>0||n);this.rawDirty=e;let l=this.materializePass(r,n,s);if(!this.contests.contested)return l;if(l.ok&&this.contests.decided())return {ok:true,package:l.package,issues:Zl(l.issues)};let d=this.materializePass(r,n,false);return this.contests.record(this.lastDuplicateParents),this.contests.recordEmbeds(this.shownUnder),d}materializePass(e,n,o){if(this.issues.length=0,this.lastDirty=e,this.contests.reset(),this.claimsWholeSubtrees=!o,this.droppedChildren.clear(),o)for(let u of this.lastDuplicateParents)this.push("duplicate-parent",u);this.customXmlRels=[],this.customXmlOverrides.clear();let r=new Set,i=new Map,a=this.registry.partEntries(),s=[...this.packageCache.groupedByOwner(this.customXmlRels).values()].flat();for(let u of [...a,...Hl(this.registry,a,s)]){let f=new Set,h=this.materialize(u.rootLogicalId,r,f,o);if(!h||h.kind==="textValue")return {ok:false,code:"missing-root",issues:[...this.issues]};let m=this.partCache.get(u.name);if(m&&m.root===h&&m.contentType===u.contentType){i.set(u.name,m);continue}let b=Object.freeze({id:u.id||u.name,name:u.name,contentType:u.contentType,root:h});i.set(u.name,b),this.partCache.set(u.name,b);}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 u of [...this.partCache.keys()])i.has(u)||this.partCache.delete(u);for(let u of [...this.relsProjection.keys()])i.has(u)||this.relsProjection.delete(u);this.evictDeadSubtrees(r);for(let u of e)r.has(u)||this.cache.forget(u);Jl(this.registry,this.pushIssue,d,r,o,c),this.looseCandidates=c,o||(this.lastDuplicateParents=this.issues.flatMap(u=>u.code==="duplicate-parent"&&u.logicalId!==void 0?[u.logicalId]:[]));let p=this.assemblePackage(i);return p.ok?this.pkg&&!n&&this.pkg.parts.size===i.size&&[...i].every(([u,f])=>this.pkg?.parts.get(u)===f)?{ok:true,package:this.pkg,issues:[...this.issues]}:(this.pkg=p.package,{ok:true,package:this.pkg,issues:[...this.issues]}):p}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 g=this.cache.get(e);if(g&&o.size+this.cache.heightOf(g)<=this.registry.limits.maxTreeDepth)return this.claimsWholeSubtrees?qr(g,n)||(this.contests.contested=true):n.add(N(g)),g}if(this.registry.isTombstoned(e))return null;let a=r?this.rebuildSpine(e,n,o):null;if(a)return a;n.add(e);let s=this.registry.record(e);if(!s)return this.push("missing-node",e),null;if(He(s)){if(this.splitProjection.awaiting.has(e))return null;let g=this.splitProjection.textValue(e,s.value),S=this.cache.get(e);if(S?.kind==="textValue"&&S.value===g)return S;let R=kl(e,g);return this.cache.remember(e,R),R}o.add(e);let l=this.issues.length,d=new Set,c=[...s.childIds],p=new Set(c),u=g=>{p.has(g)||(p.add(g),c.push(g));};for(let g of this.registry.adoptedChildren(e))u(g);for(let g of this.mergeSources.get(e)??[]){let S=this.registry.record(g);if(!(!S||!j(S)))for(let R of S.childIds)u(R);}i?this.builtMerges.set(e,i):this.builtMerges.delete(e);let f=this.splitProjection.losers,h=f.size===0?null:Bn(c,g=>f.has(g),g=>this.registry.splitLineageOf(g));h&&(c=h.map(g=>c[g]));let m=[],b=Ls(s.kind,c,g=>this.splitProjection.losers.has(g)?null:kt(this.registry,g));for(let g of b.hidden)n.add(g);for(let g of c)this.mergeSources.delete(g);for(let[g,S]of b.merges??[]){this.mergeSources.set(g,S);for(let R of S)this.shownUnder.set(R,g);}for(let g of b.shown){if(g===e){this.push("self-child",g);continue}if(d.has(g)){this.push("duplicate-child",g);continue}if(d.add(g),this.registry.isTombstoned(g)){this.push("deleted-referenced",g);continue}if(this.splitProjection.losers.has(g)){n.add(g);continue}if(v(g)||!this.registry.hasNode(g)){(v(g)||Mi(this.registry.schema.nodes,g))&&this.push("child-id-not-in-registry",g);continue}this.claimsWholeSubtrees||this.contests.note(g,e,n,this.partRoots);let S=this.materialize(g,n,o,r);S&&(m.push(S),this.shownUnder.set(N(S),e));}let w=b.hidden.length===0&&m.length===b.shown.length&&this.issues.length===l,E=this.registry.inline.textOf(e);if(E){let g=Y=>{if(!this.registry.hasNode(Y)&&ve(this.registry.doc)||this.registry.listingParents(Y).length>0||this.partRoots.has(Y)||!this.claimsWholeSubtrees&&!this.contests.noteEmbed(Y,e,this.shownUnder,this.lastDirty))return null;let z=this.materialize(Y,n,o,r);return z&&this.shownUnder.set(Y,e),z},S=this.registry.inline.viewOf(e),R=Ce(e,E,g,this.registry.limits,S),P=this.cache.get(e);m.push(...ms(P?.kind==="textValue"?[]:P?.children??[],R));}o.delete(e);let y=this.cache.get(e);if(y&&y.kind!=="textValue"&&y.children.length===m.length&&y.children.every((g,S)=>g===m[S])&&vl(y,s))return this.cache.markComplete(e,w),y;let k=y&&y.kind!=="textValue"?y.children:[];this.recordDroppedChildren(k,m);let I=Hn(s,qt(k,m),y);return this.cache.remember(e,I),this.cache.markComplete(e,w),I}rebuildSpine(e,n,o){let r=this.cache.get(e);if(!r||r.kind==="textValue"||this.rawDirty.has(e)||!this.cache.isComplete(e)||or(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 a=this.issues.length;o.add(e);let s=ql(r,{dirty:this.lastDirty,placed:n,isCached:p=>this.cache.holds(p),canRebuild:p=>v(p)||this.registry.isTombstoned(p)||!this.registry.hasNode(p)?false:(this.contests.note(p,e,n,this.partRoots),true),rebuild:p=>{let u=this.materialize(p,n,o,true);return u&&this.shownUnder.set(N(u),e),u}});if(o.delete(e),!s)return null;n.add(e);let l=s.dropped.length===0&&this.issues.length===a;if(s.children===r.children)return this.cache.markComplete(e,l),r;for(let p of s.dropped)this.droppedChildren.add(p);let d=Object.freeze(Ee(r,s.children));this.cache.remember(e,d),this.cache.markComplete(e,l);let c=i;for(let p of s.children)this.lastDirty.has(N(p))&&(c=Math.max(c,this.cache.heightOf(p)+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(N(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 a=relsPartNameFor(r);if(a!=="/_rels/.rels"&&Z(a))continue;o.add(a);let s=this.projectOneRelsPart(a,e.get(a),i);s&&(e.set(a,s),this.partCache.set(a,s));}for(let[r,i]of e){if(o.has(r)||!Zn(r))continue;let a=Ol(r);if(a===null)continue;let s=this.projectOneRelsPart(r,i,n.get(a)??[]);!s||s===i||(e.set(r,s),this.partCache.set(r,s));}}projectOneRelsPart(e,n,o){if(!n&&o.length===0)return this.relsProjection.delete(e),null;let r=this.relsProjection.get(e),a=!!r&&(!n||Tl(r.root,n.root))&&r?r:n??Pl(e);if(Cl(a.root,o))return this.relsProjection.set(e,a),a;let s=a.root.children,l=bl(a,Al(s,o,e));return this.relsProjection.set(e,l),l}builtNode(e){return this.cache.get(e)??null}shownPartChildren(e){return Wl(this.partCache.values(),e)}adoptOrphanPartMembers(e,n,o,r,i){for(let[a,s]of e){let l=ti(s.root);if(!l)continue;let d=g=>g.logicalId!==s.root.id&&l.isMember(g),c=[],p=new Set,u=new Set,f=this.registry.record(N(s.root)),h=new Set(f&&j(f)?f.childIds:[]);for(let g of s.root.children){if(g.kind==="textValue")continue;let S=N(g);if(this.registry.isTombstoned(S)||!h.has(S)&&(un(this.registry.schema.nodes.get(S))||this.registry.listingParents(S).length>0)){u.add(S);continue}let R=this.registry.record(N(g));!R||!j(R)||!d(R)||(c.push(g),p.add(N(g)));}let m=Xl(this.registry,g=>this.materialize(g,n,new Set,o),c,p,d,n,o,r,i);if(m===0&&u.size===0)continue;let b=(g,S)=>l.sortKey(g).localeCompare(l.sortKey(S));if(l.adoptedAfterListed){let g=c.length-m;c.splice(g,m,...c.slice(g).sort(b));}else c.sort(b);let w=[];for(let g of s.root.children)p.has(N(g))||u.has(N(g))||w.push(g);let E=qt(s.root.children,[...w,...c]);if(E===s.root.children)continue;let y=this.registry.record(N(s.root));if(!y||!j(y))continue;let k=Hn(y,E,s.root);this.cache.remember(N(s.root),k);let I=Object.freeze({...s,root:k});e.set(a,I),this.partCache.set(a,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),a=i&&i.kind!=="textValue"?i:this.materializeOnce(e,o,r);if(!a||a.kind==="textValue")return null;let s=[...a.children],l=new Set(s.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"||(s.push(h),l.add(f),d+=1);}if(s.sort((f,h)=>Gr(f).localeCompare(Gr(h))),d===0&&s.every((f,h)=>f===a.children[h]))return a;let c=this.registry.record(e);if(!c||!j(c))return a;let p=qt(a.children,s),u=Hn(c,p,a);return this.cache.remember(e,u),u}applyCustomXmlStores(e,n,o){let r=Bl(this.registry,e);if(r.length===0||!zl(e,r))return;let i=ei(e,r),a=new Set;for(let s of r){a.add(s.itemName),a.add(s.propsName);let l=this.adoptNodesIntoRoot(s.dataRootId,s.nodeIds,n,o),d=this.materializeOnce(s.propsRootId,n,o);if(!l||!d||d.kind==="textValue")continue;let c=Object.freeze({id:s.itemName,name:s.itemName,contentType:"application/xml",root:l}),p=Object.freeze({id:s.propsName,name:s.propsName,contentType:CUSTOM_XML_PROPS_TYPE,root:d});e.set(s.itemName,c),e.set(s.propsName,p),this.partCache.set(s.itemName,c),this.partCache.set(s.propsName,p);}if(i){for(let s of [...e.keys()])!Qt(s)&&!Qr(s)||a.has(s)||(e.delete(s),this.partCache.delete(s));this.customXmlRels=Ul(this.registry,r),this.customXmlOverrides=jl(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[s,l]of this.customXmlOverrides)r.set(s,l);let i={defaults:this.packageCache.contentTypeDefaults(),overrides:r};Gl(e,i,r);let a=this.registry.mainDocumentPart()||[...e.keys()].find(s=>s.endsWith("document.xml"))||"";return {ok:true,package:Object.freeze({parts:e,partBytes:o,relationships:n.byOwner,externalTargets:n.externalTargets,contentTypes:i,mainDocumentPart:a}),issues:[...this.issues]}}};function Ql(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=hl(e.effects,fl(t));return n===null?null:n.ok?n:{ok:false,failure:Object.freeze(n.failure)}}function ed(t,e){try{ml(t,e);}catch(n){return n instanceof A?Object.freeze({code:n.code,...n.detail?{detail:n.detail}:{}}):Object.freeze({code:"blob-store-full"})}return null}function ni(t){let{status:e,reason:n}=t;return e!=="ready"&&e!=="disconnected"?null:{status:e,...n?{code:n.code,detail:n.detail}:{}}}var Mf=3,Df=20,io=class{refused=0;transient=0;published(){this.refused=0,this.transient=0;}refusedOne(e){(!e||++this.transient>Df)&&(this.refused+=1);}recoverable(){return this.refused<Mf}};var oi="docxEditorSelectionBefore",so=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(oi)||e.stackItem.meta.set(oi,this.before);};onPopped=e=>{let n=e.stackItem.meta.get(oi);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 a={paragraphId:r.paragraphId,offset:r.offset},s=e.texts.get(r.paragraphId),l=this.textOf(r.paragraphId);return s===void 0||l===null?a:{...a,offset:mapOffsetAcrossText(r.offset,s,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 td(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 Tt="docxEditor",Ye=256,ao=256,nd=/^\d{1,16}:\d{1,16}$/;function rd(t,e,n){let o=new Map,r=a=>{let s=a.paragraphId.toUpperCase(),l=o.get(s);l===void 0&&(l=e(s),l!==void 0&&o.set(s,l));let d=Math.max(0,a.offset),c=n({paragraphId:s,offset:d});return {paragraphId:s,offset:d,...l!==void 0?{digest:lo(l)}:{},...c?{character:c}:{}}};return {encoded:{anchor:r(t.anchor),head:r(t.head),...t.kind==="cells"?{kind:"cells"}:{}},texts:o}}function Bf(t){if(typeof t!="object"||t===null||Array.isArray(t))return null;let e=t;if(typeof e.item!="string"||!nd.test(e.item)||typeof e.after!="boolean")return null;let n=typeof e.identity=="string"&&nd.test(e.identity)?e.identity:void 0;return {item:e.item,...n?{identity:n}:{},after:e.after}}function lo(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 Uf=/^[0-9a-f]{8}$/;function id(t){let e=t.actorId.trim(),n=t.name.trim();if(e.length===0||e.length>Ye||n.length===0||n.length>Ye)throw new A("invalid-identity");if(t.color!==void 0&&t.color.length>64)throw new A("invalid-identity-color");return Object.freeze({actorId:e,name:n,...t.color?{color:t.color}:{},role:t.role??"human"})}function sd(t){let e=t.trim();if(e.length===0||e.length>Ye)throw new A("invalid-document-id");return e}function ad(t){let e=t?.trim()||globalThis.crypto.randomUUID();if(e.length>Ye)throw new A("invalid-session-id");return e}function od(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=Bf(e.character);return {paragraphId:e.paragraphId.toUpperCase(),offset:e.offset,...typeof e.digest=="string"&&Uf.test(e.digest)?{digest:e.digest}:{},...n?{character:n}:{}}}function Ff(t){if(t===void 0||typeof t!="object"||t===null||Array.isArray(t))return;let e=t,n=od(e.anchor),o=od(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 co(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>Ye||typeof e.name!="string"||e.name.length===0||e.name.length>Ye)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=Ff(e.selection);return i?{...r,selection:i}:r}var zf=16,$f=32,uo=class{baselines=new Map;resolve(e,n,o){let r=[...e.getStates().entries()].slice(0,ao),i=[],a=new Set,s=new Set,l=0,d;for(let[c,p]of r){if(c===e.clientID)continue;let u=co(p[Tt]);if(!u?.selection)continue;a.add(c);let{anchor:f,head:h}=u.selection,m=`${f.paragraphId}:${f.offset}:${f.digest??""}|${h.paragraphId}:${h.offset}:${h.digest??""}`,b=this.baselines.get(c);b?.key!==m&&(b={key:m,texts:new Map,resolved:new Map,missing:new Map},this.baselines.set(c,b));let{texts:w,resolved:E,missing:y}=b,k=S=>{let R=false,P=()=>{if(!S.character||!o)return null;if(l>=$f)return R=true,null;l+=1;let O=o(S.paragraphId,S.character),L=O?n.paragraphByNodeId(O.nodeId):null;if(!O||!L)return null;let C={paragraphId:L.paragraphId,nodeId:L.nodeId,offset:O.offset};return {address:Object.freeze(C),text:L.text}},Y=n.paragraphByStableId(S.paragraphId);if(!Y){let O=S.paragraphId+":"+S.offset;d??=n.revision();let L=y.get(O);if(L?.revision===d)return L.address;let C=P()?.address??null;return R||y.set(O,{revision:d,address:C}),C}let z=E.get(S.paragraphId+":"+S.offset);if(z?.text===Y.text&&z.address.nodeId===Y.nodeId&&(z.target===void 0||n.paragraphByNodeId(z.address.nodeId)?.text===z.target))return z.address;let X=P();if(X)return E.set(S.paragraphId+":"+S.offset,{text:Y.text,address:X.address,target:X.text}),X.address;let J=w.get(S.paragraphId);if(J===void 0){if(S.digest!==void 0&&lo(Y.text)!==S.digest)return Object.freeze({paragraphId:Y.paragraphId,nodeId:Y.nodeId,offset:Math.min(S.offset,Y.text.length)});J=Y.text,w.set(S.paragraphId,J);}let D=J===Y.text?"":`${S.paragraphId}:${J.length}:${lo(J)}`,W=D===""||s.has(D)||s.size<zf;W&&D!==""&&s.add(D);let x=Object.freeze({paragraphId:Y.paragraphId,nodeId:Y.nodeId,offset:W?mapOffsetAcrossText(S.offset,J,Y.text):Math.min(S.offset,Y.text.length)});return E.set(S.paragraphId+":"+S.offset,{text:Y.text,address:x}),x},I=k(f),g=k(h);!I||!g||i.push(Object.freeze({actorId:u.actorId,name:u.name,...u.color?{color:u.color}:{},...u.selection.kind==="cells"?{kind:"cells"}:{},anchor:I,head:g}));}for(let c of this.baselines.keys())a.has(c)||this.baselines.delete(c);return Object.freeze(i)}};var fo=64*1024*1024,At="docx-package-blobs-v1";function Vf(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 Kf(t){return t instanceof ArrayBuffer||ArrayBuffer.isView(t)?t.byteLength:0}function po(t,e){return Object.freeze(e===void 0?{code:t}:{code:t,detail:e})}var Be=class{constructor(e){this.shared=e;}shared;verified=new WeakSet;poisoned=new Set;get(e){let n=this.shared.get(e),o=Vf(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+=Kf(n);}),e}put(e,n){if(!this.shared.has(e)){if(this.totalByteLength()+n.byteLength>fo)throw new A("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 ho(t,e){let{limits:n}=t,o=t.nodeCount();if(o>n.maxNodes)return po("too-many-nodes",`${o}`);let r=t.schema.parts.size;if(r>n.maxParts)return po("too-many-parts",`${r}`);let i=0;if(t.schema.relationships.forEach(s=>{i+=s instanceof B.Map?s.size:0;}),i>n.maxRelationships)return po("too-many-relationships",`${i}`);let a=e.totalByteLength();return a>fo?po("blob-store-full",`${a}`):null}var cd=20*1024*1024,fd=3e4,Zf=4e3,Qf=1500,eh="docx-collaboration-seeds-v1",ri="docxEditorSeedCandidate",th=/^[0-9a-f]{16}$/,nh=256;function hd(t,e=cd){if(!(t instanceof Uint8Array)||t.byteLength===0)throw new A("invalid-baseline");let n=Math.min(e,cd);if(t.byteLength>n)throw new A("baseline-too-large");let o=readOoxmlPackage(t,{zip:{maxEntries:1e4,maxTotalBytes:n,maxRatio:200}});if(!o.ok)throw new A(o.limit==="zip.maxTotalBytes"?"baseline-too-large":"invalid-baseline");let r=o.package.parts.get(o.package.mainDocumentPart);if(!r)throw new A("no-main-document-part");let i=o.package;for(let s of i.parts.values()){if(s.root.namespaceUri!==WML_NAMESPACE_URI||!["document","hdr","ftr"].includes(s.root.localName)||!isStoryPart(s))continue;let l=normalizeParagraphIdentity(s);l!==s&&(i=withPart(i,l));}return new TreePackageStore(i,normalizeParagraphIdentity(i.parts.get(r.name))).currentPackage()}function oh(t,e){for(let n of t.binaries())if(!e.has(n.digest))return false;return true}function mo(t,e,n,o){let r=t.schema.meta,i=()=>r.get("initialized")===true&&oh(t,e),a=()=>{let l=e.poisonedDigest();return l?new A("blob-digest-mismatch",l):null};if(o?.aborted)return Promise.reject(new A("initialization-aborted"));if(i())return Promise.resolve();let s=a();return s?Promise.reject(s):new Promise((l,d)=>{let c=h=>{clearTimeout(f),r.unobserve(p),t.doc.off("afterTransaction",p),o?.removeEventListener("abort",u),h?d(h):l();},p=()=>{let h=a();if(h){c(h);return}i()&&c();},u=()=>c(new A("initialization-aborted")),f=setTimeout(()=>c(new A("initialization-timeout")),n);r.observe(p),t.doc.on("afterTransaction",p),o?.addEventListener("abort",u,{once:true});})}function yo(t){return t.getArray(eh)}function rh(t){yo(t).push([yd()]);}var ih="freshBytes";function md(t){let e=B.encodeStateAsUpdate(t).byteLength;t.getMap(Co).set(ih,e);}function sh(t){return yo(t).length}function gd(t,e){let n=yo(t),o=()=>{n.length>1&&e();};return o(),n.observe(o),()=>n.unobserve(o)}function yd(){let t=new Uint8Array(8);return globalThis.crypto.getRandomValues(t),[...t].map(e=>e.toString(16).padStart(2,"0")).join("")}function ah(t,e){let n=[...t.getStates().entries()].slice(0,nh);for(let[o,r]of n){if(o===t.clientID)continue;let i=r[ri];if(!(typeof i!="string"||!th.test(i))&&i<e)return true}return false}async function ud(t,e,n,o){try{return await mo(t,e,n,o),!0}catch(r){if(r instanceof A&&r.code==="initialization-timeout")return false;throw r}}function lh(t,e,n){let o=t.schema.meta,r=()=>o.get("documentId")!==void 0;return n?.aborted?Promise.reject(new A("initialization-aborted")):r()?Promise.resolve():new Promise((i,a)=>{let s=p=>{clearTimeout(c),o.unobserve(l),n?.removeEventListener("abort",d),p?a(p):i();},l=()=>{r()&&s();},d=()=>s(new A("initialization-aborted")),c=setTimeout(()=>s(new A("initialization-timeout")),e);o.observe(l),n?.addEventListener("abort",d,{once:true});})}async function dh(t){let{ydoc:e,awareness:n,registry:o,blobs:r}=t,i=t.probeTimeoutMs??Zf,a=t.electionWindowMs??Qf,s=t.timeoutMs??fd,l=async()=>(await lh(o,s,t.signal),"joined");if(await ud(o,r,i,t.signal))return l();let d=yd();n.setLocalStateField(ri,d);try{let c=await ud(o,r,a,t.signal);if(!c&&ah(n,d)&&(await mo(o,r,s,t.signal),c=!0),c)return await l();if(o.schema.meta.get("initialized")===!0)return await mo(o,r,s,t.signal),await l();if(t.signal?.aborted)throw new A("initialization-aborted");let p=await Xn(o,hd(t.document),r);if(!p.ok)throw new A(p.code);return e.transact(()=>{o.schema.meta.set("documentId",t.documentId),yo(e).push([d]);}),md(e),"seeded"}finally{n.setLocalStateField(ri,null);}}function go(t,e,n){let o=cn(t.schema.meta);if(o)throw new A(o.code,o.detail);t.rebuildDerivedIndexes(),ii(t,e,n);}function ii(t,e,n){if(sh(n)>1)throw new A("concurrent-seed");let o=ho(t,e);if(o)throw new A(o.code,o.detail)}async function bd(t,e,n,o){if(t.bootstrap.kind==="create"){if(e.schema.meta.get("initialized")===true)throw new A("already-initialized");let r=await Xn(e,hd(t.bootstrap.document),n);if(!r.ok)throw new A(r.code);t.ydoc.transact(()=>{e.schema.meta.set("documentId",o),rh(t.ydoc);}),md(t.ydoc),ii(e,n,t.ydoc);}else if(t.bootstrap.kind==="create-or-join")if(await dh({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 A("document-id-mismatch");go(e,n,t.ydoc);}else ii(e,n,t.ydoc);else {if(await mo(e,n,t.bootstrap.timeoutMs??fd,t.bootstrap.signal),e.schema.meta.get("documentId")!==o)throw new A("document-id-mismatch");go(e,n,t.ydoc);}}var bo=class{constructor(e,n){this.knows=e;this.allocator=new Mt(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,a)=>i===e.childLogicalIds[a])?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 si(t,e,n,o){let r=t.inline.textOf(e);if(!r)return null;let i=[],a=new Set,s=Ce(e,r,b=>{if(a.has(b))return null;let w=n(b);return w&&a.add(w.id),w},t.limits,{...t.inline.viewOf(e),noteDrift:()=>{}},b=>i.push(b)),l={id:e,kind:"paragraph",namespaceUri:WML_NAMESPACE_URI,localName:"p",prefix:"w",namespaceBindings:[],attributes:[],children:s},d=new Map,c=0,p=b=>{if(!a.has(b.id)){if(b.kind==="textValue"){d.set(b.id,c),c+=b.value.length;return}for(let w of b.children)p(w);}};for(let b of s)p(b);if(c!==i.length)return null;let u=segmentsOf(l),f=u.length>0?u[u.length-1].end:0;if(f!==o.length)return null;let h=new Int32Array(f).fill(-1),m=new Int32Array(i.length).fill(-1);for(let b of u){if(b.node.kind!=="textValue"||b.removeNodeIds)continue;let w=d.get(b.node.id),E=b.node.value;if(w===void 0||o.slice(b.start,b.end)!==E)return null;for(let y=0;y<b.end-b.start;y+=1)h[b.start+y]=w+y,m[w+y]=b.start+y;}return {length:f,characters:i,characterAt:h,offsetOf:m}}function Id(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 xd(t,e){let n=e.character.identity??e.character.item,o=-1;for(let i=0;i<t.characters.length;i+=1){let a=t.characters[i];if(a){if(a.item===e.character.item){o=i;break}o<0&&a.identity===n&&(o=i);}}if(o<0)return null;let r=t.offsetOf[o];return r<0?null:e.after?r+1:r}var Io=class{constructor(e){this.deps=e;}deps;selection=null;anchored=null;stale=true;carried=null;track(e){let n=this.deps.port(),o=s=>{let l=n?.paragraphByStableId(s.paragraphId);return l?{nodeId:l.nodeId,offset:s.offset}:null},r=e?o(e.anchor):null,i=e?o(e.head):null,a=r&&i?{anchor:r,head:i}:null;a&&this.selection&&ph(a,this.selection)||(this.selection=a,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=si(this.deps.registry,n,this.deps.embedOf,o),i=r?Id(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]:[]),a=o.shownCopy(r);a&&i.add(a);for(let s of o.holdersOf(r))i.add(s);for(let s of i){if(n.inline.isDeletedParagraph(s))continue;let l=this.shownText(s);if(l===null)continue;let d=si(n,s,this.deps.embedOf,l),c=d?xd(d,e.anchor):null;if(c!==null)return {nodeId:s,offset:c}}return null}shownText(e){return this.deps.port()?.paragraphTextOf?.(e)??null}};function ph(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 xo=class{constructor(e){this.deps=e;}deps;waiting=false;refuses(e){return this.deps.viewWaiting()?this.set(true):ve(this.deps.ydoc)?this.set(e.some(n=>fh.has(n.op)||hh(n).some(o=>this.deps.nodeWaits(o)))):this.set(false)}refresh(){this.waiting&&!this.deps.viewWaiting()&&!ve(this.deps.ydoc)&&this.set(false);}set(e){return e!==this.waiting&&(this.waiting=e,this.deps.publish(e)),e}},fh=new Set(["acceptAllRevisions","rejectAllRevisions","replaceStoryBlocks","convertAllNotes"]);function hh(t){let e=[],n=(o,r)=>{for(let[i,a]of Object.entries(o))if(typeof a=="string")i.endsWith("Id")&&e.push(a);else if(Array.isArray(a))for(let s of a)typeof s=="string"?i.endsWith("Ids")&&e.push(s):s!==null&&typeof s=="object"&&r<3&&n(s,r+1);else a!==null&&typeof a=="object"&&r<3&&n(a,r+1);};return n(t,0),e}function mh(t){let e=0;return t.schema.nodes.forEach(n=>{M(n)&&n.get(Le)===true&&(e+=1);}),e}function gh(t){let e=0;return t.schema.nodes.forEach(n=>{let o=M(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 yh(t){let e=0;return t.schema.relationships.forEach(n=>{e+=n instanceof B.Map?n.size:0;}),e}function ai(t,e){return Object.freeze({nodes:t.nodeCount(),tombstonedNodes:mh(t),maxNodes:t.limits.maxNodes,relationships:yh(t),maxRelationships:t.limits.maxRelationships,parts:t.schema.parts.size,maxParts:t.limits.maxParts,blobBytes:e.totalByteLength(),maxBlobBytes:fo,formattingMarkers:gh(t)})}function iS(t){let e=new Pe(t);try{let n=new Be(t.getMap(At));return ai(e,n)}finally{e.destroy();}}var bh={"undo-group-already-open":"End the open group, or use another session for this operation.","editor-attached":"Use editor.beginHistoryGroup() in the editor, or a separate session for the agent.","collaboration-session-destroyed":"Join the room with a new session."},Ue=class extends Error{constructor(n){super(`${n}: ${bh[n]}`);this.code=n;this.name="CollaborationUndoGroupError";}code},So=class{constructor(e,n){this.capture=e;this.flush=n;}capture;flush;current=null;get isOpen(){return this.current!==null}begin(e,n){if(e())throw new Ue("collaboration-session-destroyed");if(n())throw new Ue("editor-attached");if(this.current!==null)throw new Ue("undo-group-already-open");if(this.flush(),e())throw new Ue("collaboration-session-destroyed");if(n())throw new Ue("editor-attached");if(this.current!==null)throw new Ue("undo-group-already-open");let o={};this.current=o,this.capture.pin(Symbol("collaboration-undo-group"));let r=this;return Object.freeze({get state(){return r.current===o?"open":"closed"},end(){r.current===o&&(r.flush(),r.current===o&&(r.current=null,r.capture.unpin()));}})}close(){this.current!==null&&(this.current=null,this.capture.unpin());}};function xh(t){let e=new Pe(t),n=null;try{if(e.schema.meta.get("initialized")!==!0||typeof e.schema.meta.get("documentId")!="string")throw new A("not-initialized");let o=new Be(t.getMap(At));go(e,o,t),n=new lt(e,o);let r=n.current(),i=o.poisonedDigest();if(i)throw new A("blob-digest-mismatch",i);if(!r.ok)throw new A(r.code);let a=Yt(r.issues);if(a)throw new A("materialize-dropped-content",a);if(!r.package.parts.has(r.package.mainDocumentPart))throw new A("no-main-document-part");return writeOoxmlPackage(r.package)}finally{n?.destroy(),e.destroy();}}var Rh=500,Oh=2e3,Eh=Symbol("createDocumentCollaboration.attachWatchdogMs"),li=class{constructor(e,n,o,r,i,a,s,l,d,c,p){this.ydoc=e;this.awareness=n;this.registry=a;this.materializer=s;this.identityMap=l;this.blobs=d;this.offlineEditing=p;this.documentId=o,this.sessionId=r,this.currentIdentity=i,this.undoManager=new B.UndoManager([...a.trackedTypes()],{trackedOrigins:new Set([this.localOrigin]),captureTimeout:Rh,deleteFilter:a.undoDeleteFilter()}),this.historyGroups=new Fn(this.undoManager,this),this.undoGroups=new So(this.historyGroups,()=>this.flushPendingJournals()),this.historySelections=new so(this.undoManager,u=>this.port?.paragraphByStableId(u)?.text??null,(u,f)=>this.caretAnchors.findStable(u,f)),this.editWait=new xo({ydoc:e,viewWaiting:()=>this.viewWaiting,nodeWaits:u=>Ra(a,this.identityMap.resolve(u)),publish:u=>this.statusState.setWaiting(u)&&this.notifyStatus()}),this.caretAnchors=new Io({registry:a,port:()=>this.port,logicalIdOf:u=>this.identityMap.resolve(u),embedOf:u=>s.builtNode(u),viewIsCurrent:()=>!this.viewWaiting}),e.on("beforeTransaction",this.onBeforeYjsTransaction),e.on("afterTransaction",this.onYjsTransaction),n.on("change",this.onAwarenessChange),this.stopBlobWatch=d.observeChanges(u=>{let f=d.verifyNow(u);f&&this.setStatus("error","blob-digest-mismatch",f);}),this.publishAwareness(),this.setStatus("ready"),this.stopSeedWatch=gd(e,()=>{this.setStatus("error","concurrent-seed");}),this.attachWatchdog=td(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 uo;realignedInBatch=false;journalsHeldDuringRemote=[];drainingHeldJournals=false;remoteCounter=0;destroyed=false;refusals=new io;historyGroups;undoGroups;stopBlobWatch;stopSeedWatch;get identity(){return this.currentIdentity}clearAttachWatchdog(){this.attachWatchdog!==null&&(clearTimeout(this.attachWatchdog),this.attachWatchdog=null);}status(){return this.statusState.status()}statusSnapshot(){return this.statusState.snapshot()}resourceUsage(){return ai(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(),e.interactive===true&&this.undoGroups.close(),this.port=e,this.publishSharedToPort();let o=e.observePrimitiveJournal(r=>{if(!this.destroyed){if(this.applyingRemote){this.journalsHeldDuringRemote.push(r);return}this.realignedInBatch||this.applyJournal(r);}});return this.detachPort=()=>{this.flushPendingJournals(),o(),this.port===e&&(this.port=null),this.detachPort=null,this.currentSelection&&this.publishAwareness();},()=>this.detachPort?.()}refuseAttach(e){return this.destroyed?()=>{}:this.port?(this.port!==e&&this.setStatus("error","port-already-attached"),()=>{}):e.documentId!==this.documentId?(this.setStatus("error","document-id-mismatch"),()=>{}):null}hasCompatibleSharedSchema(){let e=cn(this.registry.schema.meta);return e?(this.setStatus("error",e.code,e.detail),false):true}canWriteSharedState(){if(this.destroyed||!this.hasCompatibleSharedSchema())return false;let e=this.statusState.status();return e==="ready"||this.offlineEditing&&e==="disconnected"}gateOperations(e,n){return this.destroyed?"collaboration-session-destroyed":this.canWriteSharedState()?this.port?this.editWait.refuses(e)?"collaboration-session-not-ready":this.textLimitFailure(e):"collaboration-session-not-attached":"collaboration-session-not-ready"}textLimitFailure(e){let n=this.registry.limits.maxTextLength;for(let o of e)if(o.op==="insertText"&&o.text.length>n)return "collaboration-text-limit";return null}canUndo(){return !this.undoGroups.isOpen&&this.canWriteSharedState()&&((this.port?.hasPendingJournals()??false)||this.undoManager.undoStack.length>0)}canRedo(){return !this.undoGroups.isOpen&&this.canWriteSharedState()&&this.undoManager.redoStack.length>0}undo(){return this.popHistory("undo")}historySelection(){return this.historySelections.lastRestored()}redo(){return this.popHistory("redo")}beginUndoGroup(){return this.undoGroups.begin(()=>this.destroyed,()=>this.port?.interactive===true)}get undoGroupOpen(){return this.undoGroups.isOpen}popHistory(e){if(this.undoGroups.isOpen||!this.canWriteSharedState()||(this.flushPendingJournals(),!this.canWriteSharedState())||(e==="undo"?this.undoManager.undoStack:this.undoManager.redoStack).length===0)return false;this.historyGroups.reset(),this.historySelections.noteBefore(),this.historySelections.startPop();let o=B.getState(this.ydoc.store,this.ydoc.clientID);return this.registry.takeUnlisted(),Fa(this.registry,this.undoManager,e,()=>{this.registry.normalizeRestoredSplitTextAnchors(),Ma(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}=rd(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,ao);for(let[o,r]of n){let i=co(r[Tt]);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>Ye)throw new A("invalid-identity");let o=this.currentIdentity.color;if(e.color!==void 0){if(e.color.length>64)throw new A("invalid-identity-color");o=safeParticipantColor(e.color);}this.currentIdentity=Object.freeze({actorId:this.currentIdentity.actorId,name:n,...o?{color:o}:{},role:this.currentIdentity.role??"human"}),this.publishAwareness(this.currentSelection);}destroy(){this.destroyed||(this.clearAttachWatchdog(),this.flushPendingJournals(),this.undoGroups.close(),this.detachPort?.(),this.destroyed=true,this.stopBlobWatch(),this.stopSeedWatch(),this.ydoc.off("beforeTransaction",this.onBeforeYjsTransaction),this.ydoc.off("afterTransaction",this.onYjsTransaction),this.awareness.off("change",this.onAwarenessChange),this.awareness.setLocalStateField(Tt,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=Na(this.registry,this.identityMap.translate(e),s=>this.materializer.shownPartChildren(s));if(!n.ok){this.refuseLocalJournal({code:n.code,...n.detail?{detail:n.detail}:{}});return}let o=n.journal,r=Ql(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 a=this.historyGroups.capture(historyGroupOfJournal(e),()=>this.ydoc.transact(()=>{if(r!==null){let l=ed(this.blobs,r.payloads);if(l!==null)return l}let s=Ar(this.registry,o,n.plan,n.typed);return s.ok?null:(i=s.transient===true,{code:s.code,...s.detail?{detail:s.detail}:{}})},this.localOrigin));if(a===null){this.refusals.published(),(this.registry.inline.takeDrift()||e.effects.some(l=>l.kind!=="spliceText")&&Da(this.registry,n.plan))&&this.publishSharedToPort();return}this.refuseLocalJournal(a,i);}refuseLocalJournal(e,n=false){this.historyGroups.refused(),this.undoManager.stopCapturing();let o=this.statusState.snapshot();this.refusals.refusedOne(n);let r=this.refusals.recoverable()?ni(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=ho(this.registry,this.blobs);if(o){this.setStatus("error",o.code,o.detail);return}let r=ve(this.ydoc),i=e?this.materializer.rebuildFull():this.materializer.current(),a=this.blobs.poisonedDigest();if(a){this.setStatus("error","blob-digest-mismatch",a);return}if(this.viewWaiting=!1,!i.ok){r?this.viewWaiting=!0:this.degrade(i.code);return}let s=Yt(i.issues);if(s){r?this.viewWaiting=!0:this.degrade("materialize-dropped-content",s);return}let l=p=>(this.remoteCounter+=1,n.applyRemotePackage(p,{origin:ORIGIN_IDS.mutationRemote,actorId:"remote",operationId:`${this.sessionId}:remote:${this.remoteCounter}`})),d=l(i.package);if(!d.ok){let p=this.materializer.rebuildFull();p.ok&&!Yt(p.issues)&&(d=l(p.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 A?o.code:"remote-apply-failed",o instanceof A?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(Tt,n);}degrade(e,n){this.setStatus("error",e,n,this.healTo??ni(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 jS(t){let e=t[Eh]??Oh,n=sd(t.documentId),o=ad(t.sessionId),r=id(t.identity),i=new Pe(t.ydoc);try{return await Ch(t,{attachWatchdogMs:e,documentId:n,sessionId:o,identity:r,registry:i})}catch(a){throw i.destroy(),a}}async function Ch(t,e){let{attachWatchdogMs:n,documentId:o,sessionId:r,identity:i,registry:a}=e,s=new bo(c=>a.hasNode(c)||a.inline.owner(c)!==null),l=new Be(t.ydoc.getMap(At));await bd(t,a,l,o);let d=new lt(a,l);try{let c=d.current(),p=l.poisonedDigest();if(p)throw new A("blob-digest-mismatch",p);if(!c.ok)throw new A(c.code);let u=writeOoxmlPackage(c.package),f=new li(t.ydoc,t.awareness,o,r,i,a,d,s,l,n,t.offlineEditing!==!1);return Object.freeze({document:u,session:f,destroy:()=>f.destroy()})}catch(c){throw d.destroy(),c}}
|
|
5
|
+
export{ci as a,A as b,Ve as c,Yh as d,Co as e,Pe as f,Xn as g,sd as h,At as i,Be as j,hd as k,rh as l,md as m,iS as n,Ue as o,xh as p,Eh as q,jS as r};
|