@docx-editor.dev/pro 2.32.0 → 2.34.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 +17 -3
- package/dist/chunk-3HW2VWFW.js +1 -0
- package/dist/chunk-3MIZFGHH.cjs +1 -0
- package/dist/chunk-4TS2D6OV.js +11 -0
- package/dist/chunk-5HK5RAD7.cjs +11 -0
- package/dist/chunk-ENMURXLJ.js +1 -0
- package/dist/chunk-EOZ44UA7.js +1 -0
- package/dist/{chunk-RYF4SNKX.cjs → chunk-GOUTDQFX.cjs} +1 -1
- package/dist/chunk-GSBQ5AHL.cjs +1 -0
- package/dist/chunk-HMU7J34H.js +1 -0
- package/dist/chunk-IFDU5O5J.js +1 -0
- package/dist/chunk-IULA3QRZ.cjs +1 -0
- package/dist/chunk-L6ZMFFBX.cjs +1 -0
- package/dist/chunk-NTBGYQX4.js +1 -0
- package/dist/chunk-QEULTKCT.cjs +1 -0
- package/dist/{chunk-OT5R3IYV.cjs → chunk-QOXYHVBM.cjs} +1 -1
- package/dist/chunk-STTJA26X.js +1 -0
- package/dist/chunk-UPKBD6AH.cjs +1 -0
- package/dist/chunk-VQOLBCW6.js +1 -0
- package/dist/chunk-ZMBZ7CWZ.js +6 -0
- package/dist/chunk-ZZ33FL6V.cjs +6 -0
- package/dist/collaboration/hocuspocus.cjs +1 -1
- package/dist/collaboration/hocuspocus.d.cts +1 -1
- package/dist/collaboration/hocuspocus.d.ts +1 -1
- package/dist/collaboration/hocuspocus.js +1 -1
- package/dist/collaboration/index.cjs +2 -2
- package/dist/collaboration/index.d.cts +3 -2
- package/dist/collaboration/index.d.ts +3 -2
- package/dist/collaboration/index.js +2 -2
- package/dist/collaboration/webrtc.cjs +1 -1
- package/dist/collaboration/webrtc.d.cts +1 -1
- package/dist/collaboration/webrtc.d.ts +1 -1
- 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-B-iH-YCU.d.ts → document-session-B6v5LZIK.d.ts} +94 -9
- package/dist/{document-session-B-MlORjE.d.cts → document-session-DZK2tAr4.d.cts} +94 -9
- package/dist/document-session-RPP3WEJ7.cjs +1 -0
- package/dist/document-session-S2N54WP6.js +1 -0
- 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-SDHSTWYT.js +1 -0
- package/dist/metafile-replay-YZ2LHLBT.cjs +1 -0
- package/dist/react/hocuspocus.cjs +1 -1
- package/dist/react/hocuspocus.js +1 -1
- package/dist/react/index.cjs +2 -2
- package/dist/react/index.d.cts +81 -22
- package/dist/react/index.d.ts +81 -22
- package/dist/react/index.js +2 -2
- package/dist/react/webrtc.cjs +1 -1
- package/dist/react/webrtc.js +1 -1
- package/dist/vue/hocuspocus.cjs +1 -1
- package/dist/vue/hocuspocus.js +1 -1
- package/dist/vue/index.cjs +2 -2
- package/dist/vue/index.d.cts +61 -18
- package/dist/vue/index.d.ts +61 -18
- package/dist/vue/index.js +2 -2
- package/dist/vue/webrtc.cjs +1 -1
- package/dist/vue/webrtc.js +1 -1
- package/package.json +11 -5
- package/dist/chunk-3WTOHPAB.js +0 -1
- package/dist/chunk-AVZO5ZHZ.js +0 -1
- package/dist/chunk-DLYVBBO7.js +0 -1
- package/dist/chunk-GAGYRL3L.js +0 -5
- package/dist/chunk-HMSOWKXT.js +0 -1
- package/dist/chunk-I6HVINA4.cjs +0 -1
- package/dist/chunk-MHB6ID2P.cjs +0 -1
- package/dist/chunk-MWO2ZUEJ.js +0 -1
- package/dist/chunk-PMS3PGOE.cjs +0 -1
- package/dist/chunk-Q2VBO66F.js +0 -1
- package/dist/chunk-QLZH2Q2C.cjs +0 -1
- package/dist/chunk-YOWEY5F3.cjs +0 -5
- package/dist/document-session-B35ZX2W4.js +0 -1
- package/dist/document-session-V3O7XBJY.cjs +0 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import*as K from'yjs';import {XML_NAMESPACE_URI,WML_NAMESPACE_URI,partNameKey,readOoxmlPackage,refreshBoundContent,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 bs(t,e){return {...t,projectedTarget:e}}function mt(t){return t.projectedTarget}function Is(t){let e=n=>{n._needFormattingCleanup=false;};return t.on("afterTransaction",e),()=>t.off("afterTransaction",e)}function xs(t,e,n){let o=t.doc;if(!o){t.delete(e,n);return}K.transact(o,r=>{let i=e,s=n;for(let a=t._start;a&&s>0;a=a.right){if(a.deleted||!a.countable)continue;if(i>=a.length){i-=a.length;continue}let l=a;i>0&&(l=K.getItemCleanStart(r,K.createID(a.id.client,a.id.clock+i)),i=0),s<l.length&&K.getItemCleanStart(r,K.createID(l.id.client,l.id.clock+s)),s-=l.length,l.delete(r),a=l;}}),t._searchMarker&&(t._searchMarker.length=0);}function Ss(t,e,n,o,r){let i=t.doc,s=new Set([...r].filter(a=>o[a]===null));if(!i||s.size===0||n<=0){t.format(e,n,{...o});return}K.transact(i,a=>{let l=[],d=0,c=false;for(let u=t._start;u;u=u.right){if(u.deleted)continue;if(u.countable){if(c||(d+=u.length,d>e+n))break;c=d===e+n;continue}let f=u.content;c&&f instanceof K.ContentFormat&&f.value===null&&s.has(f.key)&&l.push(u);}t.format(e,n,{...o});for(let u of l){if(!u.deleted)continue;let f=u.content.key,p=u.right,h=i.clientID;new K.Item(K.createID(h,K.getState(i.store,h)),u,u.lastId,p,p&&p.id,t,null,new K.ContentFormat(f,null)).integrate(a,0);}}),t._searchMarker&&(t._searchMarker.length=0);}function zn(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}K.transact(o,r=>{let i=0,s=0;for(let a=t._start;a&&i<n.length;a=a.right){if(a.deleted||!a.countable)continue;let l=s+a.length,d=a,c=s;for(;i<n.length&&n[i]<l;){let u=n[i],f=u+1;for(i+=1;i<n.length&&n[i]===f&&f<l;)f+=1,i+=1;let p=d;u>c&&(p=K.getItemCleanStart(r,K.createID(d.id.client,d.id.clock+(u-c)))),f-u<p.length&&K.getItemCleanStart(r,K.createID(p.id.client,p.id.clock+(f-u))),p.delete(r),d=f<l?p.right:p,c=f;}a=d,s=l;}}),t._searchMarker&&(t._searchMarker.length=0);}function mr(t,e){let n=[...new Set(e)].filter(s=>s>=0).sort((s,a)=>s-a),o=[],r=0,i=0;for(let s=t._start;s&&r<n.length;s=s.right){if(s.deleted||!s.countable)continue;let a=i+s.length;for(;r<n.length&&n[r]<a;r+=1)o.push({client:s.id.client,clock:s.id.clock+(n[r]-i)});i=a;}return o}function yr(t,e){if(e.length===0)return;let n=new Map;for(let{client:i,clock:s}of e){let a=n.get(i);a||n.set(i,a=new Set),a.add(s);}let o=[],r=0;for(let i=t._start;i;i=i.right){if(i.deleted||!i.countable)continue;let s=n.get(i.id.client);if(s)for(let a=0;a<i.length;a+=1)s.has(i.id.clock+a)&&o.push(r+a);r+=i.length;}zn(t,o);}function ks(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 K.ContentEmbed?o:null;if(n+=o.length,n>e)return null}return null}function ws(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 vs(t,e){let n=t.doc;!n||e.deleted||(K.transact(n,o=>e.delete(o)),t._searchMarker&&(t._searchMarker.length=0));}function ge(t){return t._start}function q(t,e){let n;try{n=K.getItem(t.store,K.createID(e.client,e.clock));}catch{return null}return n instanceof K.Item?n:null}function*rt(t,e){let n=t.clientID,o=K.getState(t.store,n);for(let r=e;r<o;){let i=K.getItem(t.store,K.createID(n,r));r=i.id.clock+i.length,i instanceof K.Item&&(yield i);}}function Au(t,e){for(let n of rt(t,e))if(n.content instanceof K.ContentString)return n;return null}function Bt(t,e,n,o){let r=t.doc,i=r?K.getState(r.store,r.clientID):0;return typeof n=="string"?t.insert(e,n,{...o}):t.insertEmbed(e,n,{...o}),r?typeof n=="string"?Au(r,i):Du(r,i):null}function Du(t,e){for(let n of rt(t,e))if(n.content instanceof K.ContentEmbed)return n;return null}function Be(t){return t._item?.parentSub??null}function Ee(t){return t instanceof K.AbstractType?t._item:null}function $n(t){return t._item?.id??null}function Ne(t,e){return t._map.get(e)}function br(t){return t.store.pendingStructs?.update??null}function $e(t){return t.store.pendingStructs!==null||t.store.pendingDs!==null}function Ut(t,e){for(let[n,o]of t.changed)if(n===e)return o;return null}function Ce(t){let e=t?.clients;if(!(e instanceof Map))return [];let n=[];for(let[o,r]of e)for(let i of r)n.push({client:o,clock:i.clock,length:i.len});return n}function U(t){return t.id}var Nu=16,Ls=16,Yu=new Set(["paraId","textId","id","numId","bookmarkId"]);function Rs(t){let e="";for(let n of t)e+=n.toString(Nu).padStart(2,"0");return e}function _u(t){let e=new Uint8Array(Ls);return globalThis.crypto.getRandomValues(e),Rs(e)}function Ir(t){return /^[0-9a-f]{32}$/.test(t)}function Bu(t,e){if(!Ir(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 we(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 Ft(t,e){let n=t?we(t):null,o=e?we(e):null;return n!==null&&o!==null&&n.client===o.client&&n.clock+1===o.clock}function Os(t,e){return `yjs:${t}:${e}`}function We(t){if(!t.startsWith("lid:"))return null;let e=t.slice(4,t.indexOf(":",4));return Ir(e)?e:null}function Es(t){let e=[];for(let n of t)Yu.has(n.localName)&&e.push(n.value);return e}var fn=class{replicaId;next=0;constructor(e){if(this.replicaId=e??_u(),!Ir(this.replicaId))throw new Error("invalid replica identity")}take(){let e=Bu(this.replicaId,this.next);return this.next+=1,e}get counter(){return this.next}};var yt=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}),Fu=/^sha256:[0-9a-f]{64}$/;function Ts(t){return t?Object.freeze({...yt,...t}):yt}function O(t){return isDangerousKey(t)?"prototype-key":null}function ve(t,e){return typeof t!="string"||t.length>e?"invalid-string":isDangerousKey(t)?"prototype-key":null}function me(t){let e=O(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 Ms(t){for(let e of Object.keys(t)){let n=O(e);if(n)return n}return !Fu.test(t.digest)||!Number.isSafeInteger(t.size)||t.size<0?"invalid-blob-descriptor":t.size>yt.maxBlobBytes?"blob-too-large":ve(t.mediaType,yt.maxMediaTypeLength)||t.mediaType.length===0||ve(t.storageKey,yt.maxStorageKeyLength)||t.storageKey.length===0?"invalid-blob-descriptor":null}var ju="https://www.docx-editor.dev/docs/2.x/pro/collaboration-versions",N=class extends Error{constructor(n,o){let r=n==="collaboration-format-mismatch"||n==="protocol-version-mismatch"||n==="schema-version-mismatch",i=o?`${n}: ${o}`:n;super(r?`${i}
|
|
2
|
+
Collaboration upgrade required. Save local changes and use a compatible app version, or upgrade the saved room. See ${ju}#upgrade-saved-rooms`:i);this.code=n;this.detail=o;this.name="CollaborationSchemaError";}code;detail};var bt=Object.freeze({protocolVersion:1,sharedSchemaVersion:5,repairVersion:3,canonicalModelVersion:1});function xr(t){let e=t!==null&&typeof t=="object"&&!Array.isArray(t)?t:{};for(let n of Object.keys(bt)){let o=bt[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 Gy(t){let e=xr(t);if(e)throw new N(e.code,e.detail)}var zu=bt.protocolVersion,$u=bt.sharedSchemaVersion,Wu=bt.repairVersion,Ku=bt.canonicalModelVersion,Sr="docx-package-meta-v1",pn="docx-package-nodes-v1",Vu="docx-package-parts-v1",Ju="docx-package-rels-v1",Xu="docx-package-overrides-v1",Hu="docx-package-defaults-v1",Gu="docx-package-binaries-v1",qu="docx-package-namespaces-v1",Zu="docx-package-attributes-v1",Qu="docx-package-bindings-v1",Wn="s",Kn="b",Te="t",It="children",ce="deleted",xt="replacedBy",St="undone",hn="splitFrom",kt="splitLineage";var he="",As="-",Ds=Object.freeze({kind:"docx-package-bootstrap"}),kr=Object.freeze({kind:"docx-package-journal"});function wt(t){return t.kind==="textValue"}function J(t){return !wt(t)}var ef=Object.freeze(new Set(["missing-node","child-id-not-in-registry","cycle"])),tf=200;function vt(t){let e=new Map;for(let n of t)ef.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,tf)}function Ns(t){return {meta:t.getMap(Sr),nodes:t.getMap(pn),parts:t.getMap(Vu),relationships:t.getMap(Ju),overrides:t.getMap(Xu),defaults:t.getMap(Hu),binaries:t.getMap(Gu),namespaces:t.getMap(qu),attributes:t.getMap(Zu),bindings:t.getMap(Qu)}}var Ys=[["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"]],nf=new Map(Ys),of=new Map(Ys.map(([t,e])=>[e,t]));function rf(t){let e=0xcbf29ce484222325n,n=0x100000001b3n;for(let o=0;o<t.length;o+=1)e^=BigInt(t.charCodeAt(o)),e=e*n&0xffffffffffffffffn;return e.toString(16).padStart(16,"0")}function Lt(t){return t.length===0?As:nf.get(t)??`n${rf(t)}`}function jt(t,e,n){let o=Lt(e);return e.length===0||O(o)||ve(e,n)||t.get(o)!==e&&t.set(o,e),o}function Rt(t,e){if(e===As||O(e))return "";let n=t.get(e);return typeof n=="string"?n:of.get(e)??""}function wr(t,e,n,o){return `${t}${he}${e}${he}${n}${he}${o}`}function sf(t){let e=t.split(he);return {kind:e[0]||"generic",namespaceId:e[1]??"",localName:e[2]??"",prefix:e[3]??""}}function He(t){let e=t.has(Wn)?t.get(Wn):t.get(Kn);return sf(typeof e=="string"?e:"")}function vr(t,e,n){return `${t}${he}${e}${he}${n}`}function gn(t){let e=t.split(he);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 Lr(t,e){return `${t}${he}${e}`}function Ot(t){let e=t.split(he);if(e.length!==2)return null;let n=e[0],o=e[1];return n.length===0?null:{logicalId:n,prefix:o}}function _s(t,e){return `${t}${he}${e}`}function Bs(t){let e=t.indexOf(he);return e<0?{prefix:"",value:t}:{prefix:t.slice(0,e),value:t.slice(e+1)}}function Us(t){let e=new K.Map,n=wr(t.kind,t.namespaceId,t.localName,t.prefix??"");e.set(Kn,n);let o=new K.Array;return t.childIds&&t.childIds.length>0&&o.push([...t.childIds]),e.set(It,o),e}function Vn(t){let e=new K.Map;return e.set(Te,new K.Text(t)),e}function Fs(t,e,n){let o=new K.Map;return o.set("id",t),o.set("rootId",e),o.set("contentType",n),o}function js(t){let e=new K.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 zs(t){let e=new K.Map;return e.set("digest",t.digest),e.set("size",t.size),e.set("mediaType",t.mediaType),e.set("storageKey",t.storageKey),e}function Jn(t){return xr({protocolVersion:t.get("protocolVersion"),sharedSchemaVersion:t.get("sharedSchemaVersion"),repairVersion:t.get("repairVersion"),canonicalModelVersion:t.get("canonicalModelVersion")})}function $s(t){t.set("protocolVersion",zu),t.set("sharedSchemaVersion",$u),t.set("repairVersion",Wu),t.set("canonicalModelVersion",Ku),t.set("initialized",true);}function Ws(t,e){let n=Ne(t,e);return n!==void 0&&n.deleted}function zt(t){return br(t)!==null}var Ps=new WeakMap,af={origins:new Set,fields:new Set,listed:new Set};function Rr(t){let e=br(t);if(e===null)return af;let n=Ps.get(e);if(n)return n;let o=new Set,r=new Set,i=new Set;try{for(let a of K.decodeUpdateV2(e).structs)if(a instanceof K.Item&&(a.origin&&o.add(`${a.origin.client}:${a.origin.clock}`),a.parent instanceof K.ID&&a.parentSub!==null&&r.add(`${a.parent.client}:${a.parent.clock}:${a.parentSub}`),a.parentSub===null&&a.content instanceof K.ContentAny))for(let l of a.content.arr)typeof l=="string"&&i.add(l);}catch{}let s={origins:o,fields:r,listed:i};return Ps.set(e,s),s}function Ks(t,e){if(t.has(e)||t.doc===null)return false;let n=$n(t);return n!==null&&Rr(t.doc).fields.has(`${n.client}:${n.clock}:${e}`)}function Vs(t,e){return zt(t)&&Rr(t).listed.has(e)}function Or(t,e){if(t.has(e)||t.doc===null||!zt(t.doc))return false;let n=Ne(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 Rr(t.doc).origins.has(`${o.client}:${o.clock}`)}function Y(t){return t instanceof K.Map}function re(t){if(!Y(t))return null;let e=t.get(It);return e instanceof K.Array?e:null}function $t(t){return Y(t)&&t.get(Te)instanceof K.Text}function Me(t){return Y(t)&&t.get(ce)===true}function Xn(t){return Y(t)&&t.get(St)===true}function Hn(t){return Er(t,xt)}function Er(t,e){if(!Y(t))return null;let n=t.get(e);return typeof n=="string"&&n.length>0?n:null}function Js(t,e){let n=o=>{let r=t.get(o);return Y(r)?Ne(r,xt)?.id??{client:0,clock:0}:{client:0,clock:0}};return [...e??[]].sort((o,r)=>{let i=n(o),s=n(r);return i.clock-s.clock||i.client-s.client||(o<r?-1:o>r?1:0)})}function mn(t){return Er(t,hn)}function Et(t){return Er(t,kt)??mn(t)}function Hs(t,e){let n=t.get(e);if(!Y(n))return null;if($t(n)){let o=n.get(Te);return {isText:true,textLength:o instanceof K.Text?o.length:0,children:[]}}return {isText:false,textLength:0,children:re(n)?.toArray()??[]}}function Gs(t,e){let n=t.get(e);return Y(n)?$t(n)?"textValue":He(n).kind:null}function Gn(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 qs(t,e,n,o,r){let i=He(e);return {logicalId:t,kind:i.kind,namespaceUri:Rt(n.namespaces,i.namespaceId),localName:i.localName,prefix:i.prefix.length>0?i.prefix:void 0,attributes:o,bindings:r,childIds:re(e)?.toArray()??[]}}function Zs(t){let e=$n(t);return e&&Os(e.client,e.clock)}function Qs(t){return typeof t=="string"?t:""}function Z(t){return String(t)}function Tr(t){return !O(t)}function ea(t){t.forEach(e=>{if(Y(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 Ge(t,e,n=t.id){return {...t,id:n,children:e}}function ta(t){return t.kind!=="textValue"}function na(t){return t.filter(ta)}function Wt(t){if(!ta(t))throw new Error(`expected an element, found text node ${t.id}`);return t}function qn(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 Zn(t){return Pe({id:t,kind:"generic",namespaceUri:"",localName:"",namespaceBindings:[],attributes:[],children:[]})}function Kt(t,e){return {id:t,kind:"textValue",value:e}}function Vt(t){return t}var cf=new Set(["t","delText","instrText","delInstrText"]),uf=new Set(["hyperlink","ins","del","moveFrom","moveTo","sdt","sdtContent","fldSimple","smartTag","customXml","dir","bdo"]),ff=new Set(["sdtPr","sdtEndPr","smartTagPr","customXmlPr","fldData"]);function Mr(t,e){return t.kind!=="textValue"&&t.namespaceUri===WML_NAMESPACE_URI&&e.has(t.localName)}function Jt(t,e=[]){return Ge(t,e)}function pf(t){return Mr(t,cf)&&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=(a,l)=>{let d=a.children.find(f=>f.kind==="runProperties"),c={...o,run:Jt(a),runProperties:d?Jt(d):null,properties:d?na(d.children):[],wrap:l},u=0;for(let f of a.children)if(f!==d)if(u+=1,pf(f)){let p=f.children.map(g=>g.kind==="textValue"?g.value:"").join(""),h={...c,text:Jt(f),textValueId:f.children[0]?.id??null};p.length===0&&e.push({kind:"anchor",attributes:h});for(let g=0;g<p.length;g+=1)e.push({kind:"char",value:p[g],attributes:h});}else e.push({kind:"embed",node:f,attributes:c});u===0&&e.push({kind:"anchor",attributes:c});},i=(a,l)=>{for(let d of a)if(d.kind==="run")r(d,l);else if(Mr(d,uf)){let c=d.children.filter(p=>Mr(p,ff)),u=[...l,Jt(d,c)],f=d.children.filter(p=>!c.includes(p));f.length===0&&e.push({kind:"anchor",attributes:{...o,wrap:u}}),i(f,u);}else e.push({kind:"embed",node:d,attributes:{...o,wrap:l}});},s=[];for(let a of t.children)a.kind==="paragraphProperties"?n.push(a):s.push(a);return i(s,[]),{shell:Jt(t,n),items:e}}function Qn(t){return {shell:t,children:[...t.children],openRun:null,openText:null}}function hf(t){return t.runSignature!==void 0?t.runSignature:[t.run.id,t.runProperties?.id??"",...t.properties.map(e=>e.id)].join("")}function oa(t){let e=Qn(t.shell),n=[e],o=s=>{let a=s.openText;a&&(a.value.length>0&&a.builder.children.push(Kt(a.valueId,a.value)),s.openText=null);},r=s=>{s.openRun&&o(s.openRun.builder),s.openRun=null;};for(let s of t.items){let{wrap:a}=s.attributes,l=s.attributes.wrapSignatures,d=(h,g)=>l?h.signature===l[g]:h.shell.id===a[g].id,c=1;for(;c<n.length&&c-1<a.length&&d(n[c],c-1);)c+=1;for(;n.length>c;)r(n[n.length-1]),n.pop();for(let h=c-1;h<a.length;h+=1){let g=n[n.length-1];r(g);let y=Qn(a[h]);y.signature=l?.[h],g.children.push(y),n.push(y);}let u=n[n.length-1];if(!s.attributes.run){r(u),s.kind==="embed"&&u.children.push(s.node);continue}let f=hf(s.attributes);if(u.openRun?.key!==f){r(u);let h=Qn(s.attributes.run);s.attributes.runProperties&&h.children.push(Jt(s.attributes.runProperties,s.attributes.properties)),u.children.push(h),u.openRun={key:f,builder:h};}let p=u.openRun.builder;if(s.kind==="embed"){o(p),p.children.push(s.node);continue}if(s.attributes.text){if(p.openText?.key!==s.attributes.text.id){o(p);let h=Qn(s.attributes.text);p.children.push(h),p.openText={key:s.attributes.text.id,builder:h,valueId:s.attributes.textValueId??`${s.attributes.text.id}/value`,value:""};}s.kind==="char"&&(p.openText.value+=s.value);}}for(;n.length>0;)r(n.pop());let i=s=>"shell"in s?Object.freeze(Ge(s.shell,Object.freeze(s.children.map(i)))):s;return Wt(i(e))}var Dr={kind:"run",localName:"r"},eo={kind:"runProperties",localName:"rPr"},Nr={kind:"text",localName:"t"},to=32768,Fe=24;function ra(t,e=0){if(e>Fe)return 1/0;if(!ie(t))return 1;let n=t.c,o=1;if(Array.isArray(n))for(let r of n)o+=ra(r,e+1);return o}var Ye=class extends Error{constructor(n,o){super(`shared text value refused (${n}): ${o}`);this.code=n;this.detail=o;}code;detail};function Yr(t,e,n=0){if(n===0&&ra(t)>to)return "too-many-nodes";if(n>Fe)return "tree-too-deep";if(!ie(t))return "invalid-string";for(let[r,i]of Object.entries(t))if(r==="v"&&typeof i=="string"){if(i.length>e.maxTextLength)return "text-too-long"}else if(typeof i=="string"&&i.length>e.maxStringLength)return "invalid-string";for(let r of ["a","b"]){let i=t[r];if(Array.isArray(i)){if(i.length>e.maxAttributes)return "too-many-attributes";for(let s of i)if(Array.isArray(s))for(let a of s){if(typeof a=="string"&&a.length>e.maxStringLength)return "invalid-string";if(typeof a=="string"&&O(a))return "prototype-key"}}}for(let r of ["l","k","p"]){let i=t[r];if(typeof i=="string"&&O(i))return "prototype-key"}let o=t.c;if(Array.isArray(o)){if(o.length>e.maxChildren)return "too-many-children";for(let r of o){let i=Yr(r,e,n+1);if(i!=="invalid-string"||bn(r,e))return i}}return "invalid-string"}function bn(t,e){return typeof t=="string"?t.length>e.maxStringLength:Array.isArray(t)?t.some(n=>bn(n,e)):ie(t)?Object.entries(t).some(([n,o])=>n==="v"?false:bn(o,e)):false}var ia=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"]]),gf=new Map([...ia].map(([t,e])=>[e,t]));function In(t){return t===WML_NAMESPACE_URI?"":ia.get(t)??t}function xn(t){return t===""?WML_NAMESPACE_URI:t.startsWith("#")?gf.get(t)??null:t}function no(t){if(t===WML_NAMESPACE_URI)return "w";if(t===XML_NAMESPACE_URI)return "xml"}var Pr=/^(.*:)(\d{1,15})$/;function Sn(t,e){if(t===e)return "=";if(e.length>0&&t.startsWith(e))return `^${t.slice(e.length)}`;let n=Pr.exec(t),o=Pr.exec(e);return n&&o&&n[1]===o[1]?`+${Number(n[2])-Number(o[2])}`:/^[=^+!]/.test(t)?`!${t}`:t}function Ht(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=Pr.exec(e),s=i?Number(i[2])+r:NaN;o=i&&Number.isSafeInteger(s)&&s>=0?`${i[1]}${s}`:null;}else t.startsWith("!")?o=t.slice(1):o=t;return !o||o.length>n.maxStringLength||O(o)?null:o}function sa(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 mf(t){let e=[t.localName,t.value],n=t.prefix,o=sa(t.namespaceUri,t.localName,n,t.value),r=[In(t.namespaceUri),n===no(t.namespaceUri)?"":n??null,t.kind===o?"":t.kind];for(;r.length>0&&r[r.length-1]==="";)r.pop();return [...e,...r]}function Gt(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=In(t.namespaceUri);i!==""&&(o.n=i);let s=e&&t.localName===e.localName&&t.namespaceUri===WML_NAMESPACE_URI?e.kind:"generic";return t.kind!==s&&(o.k=t.kind),t.prefix!==no(t.namespaceUri)&&(o.p=t.prefix??""),t.attributes.length>0&&(o.a=t.attributes.map(mf)),t.namespaceBindings.length>0&&(o.b=t.namespaceBindings.map(a=>[a.prefix,In(a.namespaceUri)])),n&&t.children.length>0&&(o.c=t.children.map(a=>Gt(a,null,true))),o}function ie(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Ue(t,e){return typeof t=="string"&&t.length<=e.maxStringLength}function yf(t,e){if(t===void 0)return Object.freeze([]);if(!Array.isArray(t)||t.length>e.maxAttributes)return null;let n=[];for(let o of t){if(!Array.isArray(o)||o.length<2||o.length>5)return null;let[r,i,s="",a="",l=""]=o;if(!Ue(r,e)||O(r)||!Ue(i,e)||!Ue(s,e))return null;let d=xn(s);if(d===null||a!==null&&!Ue(a,e))return null;let c=a===""?no(d):a??void 0;if(c!==void 0&&O(c)||!Ue(l,e))return null;let u=l||sa(d,r,c,i);if(u!=="xmlSpace"&&u!=="wmlVal"&&u!=="genericExtension")return null;n.push(Object.freeze({kind:u,namespaceUri:d,localName:r,...c===void 0?{}:{prefix:c},value:i}));}return Object.freeze(n)}function bf(t,e){if(t===void 0)return Object.freeze([]);if(!Array.isArray(t)||t.length>e.maxAttributes)return null;let n=[];for(let o of t){if(!Array.isArray(o)||o.length!==2)return null;let[r,i]=o;if(!Ue(r,e)||!Ue(i,e)||O(r))return null;let s=xn(i);if(s===null)return null;n.push(Object.freeze({prefix:r,namespaceUri:s}));}return Object.freeze(n)}function qt(t,e,n,o,r,i){if(r.nodes+=1,r.nodes>to||i>Fe||!ie(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(Kt(e,t.v));let s=t.l??n?.localName;if(!Ue(s,o)||O(s))return null;let a=t.n??"";if(!Ue(a,o))return null;let l=xn(a);if(l===null)return null;let d=n&&s===n.localName&&l===WML_NAMESPACE_URI?n.kind:"generic",c=t.k??d;if(!Ue(c,o)||O(c))return null;let u=no(l);if(t.p!==void 0){if(!Ue(t.p,o)||O(t.p))return null;u=t.p===""?void 0:t.p;}let f=yf(t.a,o),p=bf(t.b,o);if(!f||!p)return null;let h=t.c??[];if(!Array.isArray(h)||h.length>o.maxChildren)return null;let g=[];for(let y=0;y<h.length;y+=1){let I=qt(h[y],`${e}~${y}`,null,o,r,i+1);if(!I)return null;g.push(I);}return Object.freeze(Pe({id:e,kind:c,namespaceUri:l,localName:s,namespaceBindings:p,attributes:f,children:Object.freeze(g),...u===void 0?{}:{prefix:u}}))}var de="v:",be="b",ro=512,ua=2**31,If=new Set(["ins","del","moveFrom","moveTo"]);function oo(t){return t.namespaceUri===WML_NAMESPACE_URI&&If.has(t.localName)}var xf=new Set(["hyperlink","fldSimple"]);function fa(t){return t.namespaceUri===WML_NAMESPACE_URI&&xf.has(t.localName)}function vn(t,e,n,o={}){return {i:Sn(t.id,e),...Gt(t,n,false),...o}}function _r(t,e){return vn(t,e,null,{c:t.children.map(n=>Gt(n,null,true))})}function pa(t,e,n){let o=[],r=new Set,i=t.map(a=>{let l=Sn(a.id,e),d=r.has(l)?`!${a.id}`:l;return r.add(d),d}),s=0;return t.forEach((a,l)=>{if(!oo(a)){let d=i.filter((u,f)=>f>l&&oo(t[f])),c=fa(a)?i.filter((u,f)=>f<l&&oo(t[f])):[];o.push({wrapper:a,inside:d,outside:c});return}s+=1,n[`${de}${i[l]}`]=JSON.stringify({e:{..._r(a,e),i:i[l]},d:s});}),o}function Br(t,e,n,o="r"){let r=new Set,i=ie(t)?t[o]:void 0;if(!Array.isArray(i))return r;for(let s of i.slice(0,Fe)){let a=Ht(s,n,e);a!==null&&r.add(a);}return r}function fe(t){if(typeof t=="string")try{return JSON.parse(t)}catch{return}}var Sf=65536,aa=4096;function kn(t){let e=new Set;if(typeof t!="string"||t.length>ro*(aa+3))return e;let n=fe(t);if(!Array.isArray(n))return e;for(let o of n.slice(0,ro))typeof o!="string"||o.length>aa||O(o)||e.add(`${de}${o}`);return e}function kf(t){let e=kn(t[be]);return Object.keys(t).filter(n=>n.startsWith(de)&&!O(n)&&!e.has(n)).sort()}var wf=null;function vf(t){return typeof t=="number"&&Number.isSafeInteger(t)&&t>=1&&t<=ua}function Lf(t,e,n,o){if(typeof e!="string"||e.length>Sf)return null;let r=fe(e);if(!ie(r)||!ie(r.e))return null;let i=r.d;if(!vf(i))return null;let{i:s,...a}=r.e,l=Ht(s,o,n);if(l===null)return null;let d=qt(a,l,wf,n,{nodes:0},0);return !d||d.kind==="textValue"||!oo(d)?null:{key:t,shell:d,encodedId:s,order:i,content:JSON.stringify(a),signature:JSON.stringify(a)}}function wn(t,e,n){let o=[];for(let r of kf(t)){let i=Lf(r,t[r],e,n);if(i&&o.push(i),o.length===Fe)break}return o.sort(Rf)}function Rf(t,e){return t.order-e.order||(t.key<e.key?-1:t.key>e.key?1:0)}function ha(t,e){let n=[...t];for(let o of e.slice(0,Math.max(0,Fe-t.length))){let r=0,i=null;for(let a=n.length-1;a>=0;a-=1)if(n[a].inside?.has(o.shell.id)){r=a+1,i=n[a].shell.id;break}let s=n.some(a=>a.outside?.has(o.shell.id));for(let a=n.length-1;a>=r&&!s;a-=1)if(n[a].anchor===void 0&&fa(n[a].shell)){r=a+1,i=n[a].shell.id;break}for(;r<n.length&&n[r].anchor===i;)r+=1;n.some(a=>a.shell.id===o.shell.id)||n.splice(r,0,{shell:o.shell,signature:o.signature,anchor:i});}return n.map(({shell:o,signature:r})=>({shell:o,signature:r}))}function Of(t,e){let n=new Set,o=[],r=new Map;for(let i of e){let s=t.find(a=>!n.has(a)&&a.content===i.content);s?(n.add(s),r.set(i.encodedId,s.encodedId)):o.push(i);}return {kept:n,added:o,renamed:r}}function Ur(t){let e={};for(let n of Object.keys(t))!n.startsWith(de)&&n!==be&&(e[n]=t[n]);return e}function io(t){for(let e of Object.keys(t))if(e.startsWith(de)||e===be)return true;return false}function Ef(t,e,n){if(t===e)return true;let o=fe(t??"[]"),r=fe(e??"[]");return !Array.isArray(o)||!Array.isArray(r)||o.length!==r.length?false:o.every((i,s)=>{let a=r[s];if(!ie(i)||!ie(a))return false;let{r:l,...d}=i,{r:c,...u}=a;if(JSON.stringify(d)!==JSON.stringify(u))return false;let f=p=>(Array.isArray(p)?p:[]).filter(h=>n.has(h)).sort();return JSON.stringify(f(l))===JSON.stringify(f(c))})}function Cf(t,e){let n=JSON.parse(t);return JSON.stringify({...n,d:e})}function Tf(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=>ie(o)&&Array.isArray(o.r)?{...o,r:o.r.map(r=>typeof r=="string"?e.get(r)??r:r)}:o)):t}function la(t){return JSON.stringify([...t].map(e=>e.slice(de.length)).sort())}function Fr(t,e,n,o,r){if(!io(t))return e;let i=wn(t,o,r),s=wn(e,o,r),a=Ur(e);for(let y of Object.keys(t))y.startsWith(de)&&(a[y]=t[y]);let l=kn(t[be]),{kept:d,added:c,renamed:u}=Of(i,s);for(let y of i)d.has(y)||(n?l.add(y.key):delete a[y.key]);let f=Tf(a.w,u);f!==void 0&&(a.w=f);let p=new Set([...d].map(y=>y.encodedId).concat(c.map(y=>y.encodedId)));Ef(t.w,a.w,p)&&(t.w===void 0?delete a.w:a.w=t.w);let h=i.reduce((y,I)=>Math.max(y,I.order),0),g=false;for(let y of c)h=Math.min(h+1,ua),a[y.key]=Cf(e[y.key],h),g=l.delete(y.key)||g;if(!n&&!g)return t[be]!==void 0&&(a[be]=t[be]),a;if(l.size>ro){let y=[...l].sort();for(let I of y.slice(ro))l.delete(I),delete a[I];}if(l.size>0){let y=la(l);a[be]=t[be]!==void 0&&la(kn(t[be]))===y?t[be]:y;}return a}var da=new WeakMap,Mf=4096;function Pf(t){let e=[];for(let n of Object.keys(t).sort())(n.startsWith(de)||n===be)&&e.push(JSON.stringify([n,t[n]]));return e.join(",")}function jr(t,e,n){if(!io(t))return "[]";let o=da.get(e);o||da.set(e,o=new Map);let r=`${n}\0${Pf(t)}`,i=o.get(r);if(i!==void 0)return i;let s=wn(t,e,n),a=JSON.stringify(s.map(l=>l.content));return o.size>=Mf&&o.clear(),o.set(r,a),a}var se="inline",zr="r",Zt="rp",Ia="t",xa="w",$r="p:";function Wr(t){return t.kind!=="embed"?{a:1}:t.attributes.run?{n:t.node.id,r:1}:{n:t.node.id}}function Nf(t){let e=new Map;return t.map(n=>{let o=In(n.namespaceUri),r=`${$r}${o===""?"":`${o}|`}${n.localName}`,i=(e.get(r)??0)+1;return e.set(r,i),i===1?r:`${r}#${i}`})}function Sa(t){let e=t.slice($r.length).replace(/#\d+$/,""),n=e.indexOf("|"),o=xn(n<0?"":e.slice(0,n)),r=n<0?e:e.slice(n+1);return o===null||r.length===0?null:{namespaceUri:o,localName:r}}function Ct(t,e,n){let o={},r=t.run;if(r&&(o[zr]=JSON.stringify(vn(r,e,Dr))),r&&t.runProperties){let s=Nf(t.properties);o[Zt]=JSON.stringify(vn(t.runProperties,e,eo,{o:s})),t.properties.forEach((a,l)=>{let d={kind:"generic",localName:a.localName};o[s[l]]=JSON.stringify(Gt(a,d,true));});}if(t.text){let s=t.text.id,a=t.textValueId??`${s}~v`,l=a===`${s}~v`?{}:{v:Sn(a,s)};o[Ia]=JSON.stringify(vn(t.text,e,Nr,l));}if(t.wrap.length>Fe)throw new Ye("tree-too-deep",`${t.wrap.length} nested wrappers`);let i=pa(t.wrap,e,o);return i.length>0&&(o[xa]=JSON.stringify(i.map(({wrapper:s,inside:a,outside:l})=>({..._r(s,e),...a.length>0?{r:a}:{},...l.length>0?{x:l}:{}})))),Object.values(o).some(s=>Yf(s,n))&&Bf(t,o,e,n),o}function Yf(t,e){let n=Math.min(e.maxStringLength,e.maxAttributes,e.maxChildren,e.maxTextLength,to);if(t.length>n||_f.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*Fe+2)return true}else (i===125||i===93)&&(o-=1);}return false}var _f=/__proto__|constructor|prototype/;function Bf(t,e,n,o){let r=Ae(e,o,n);if(!((e[Zt]===void 0||Ln(fe(e[Zt]),n,eo,o)!==null)&&r.run===null==(t.run===null)&&r.properties.length===(t.run?t.properties.length:0)&&r.text===null==(t.text===null)&&r.wrap.length===t.wrap.length)){for(let[s,a]of Object.entries(e)){let l=fe(a),d=Array.isArray(l)?l:[l];for(let c of d){let u=Yr(c,o);if(u!=="invalid-string"||bn(c,o))throw new Ye(u,`${s} of an item in ${n}`)}}throw new Ye("invalid-string",`an item in ${n}`)}}function ka(t,e,n){let o=[],r=null,i=()=>{r&&o.push({insert:r.text,attributes:r.attributes}),r=null;};for(let s of t){let a=Ct(s.attributes,e,n);if(s.kind==="char"){let l=Se(a);r&&r.signature===l?r.text+=s.value:(i(),r={text:s.value,attributes:a,signature:l});continue}i(),o.push({insert:Wr(s),attributes:a});}return i(),o}function Se(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 Ln(t,e,n,o,r=false){if(!ie(t))return null;let i=Ht(t.i,e,o);if(!i)return null;let{i:s,v:a,o:l,c:d,...c}=t,u=qt(r?{...c,c:d}:c,i,n,o,{nodes:0},0);return !u||u.kind==="textValue"?null:{shell:u,data:t}}var ga=["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 ma(t){let e=Sa(t),n=e?.namespaceUri===WML_NAMESPACE_URI?ga.indexOf(e.localName):-1;return n<0?ga.length-1:n}function Uf(t,e){return ma(t)-ma(e)||(t<e?-1:t>e?1:0)}function Ff(t){return qn(t,"runProperties","rPr")}var ya=new WeakMap,jf=4096;function Ae(t,e,n){let o=JSON.stringify([n,Se(t)]),r=ya.get(e);r||ya.set(e,r=new Map);let i=r.get(o);if(i)return i;let s=zf(t??{},e,n);return r.size>=jf&&r.clear(),r.set(o,s),s}function zf(t,e,n){let o=Ln(fe(t[zr]),n,Dr,e),r=o?Ln(fe(t[Zt]),n,eo,e):null,i=[],s=[],a=o?Object.keys(t).filter(m=>m.startsWith($r)).sort().slice(0,e.maxChildren):[],l={nodes:0},d=r?.shell??(o&&a.length>0?Ff(`${o.shell.id}~rPr`):null);if(o&&d){let m=Array.isArray(r?.data.o)?r.data.o:[],S=a.every(L=>m.includes(L))?m.filter(L=>typeof L=="string"&&a.includes(L)):[...a].sort(Uf);for(let L of S){let v=Sa(L);if(!v||O(L))continue;let b=qt(fe(t[L]),`${d.id}~${L}`,{kind:"generic",localName:v.localName},e,l,0);b&&b.kind!=="textValue"&&(i.push(b),s.push(L));}}let c=fe(t[Ia]),u=Ln(c,n,Nr,e),f=u?(ie(c)&&c.v!==void 0?Ht(c.v,u.shell.id,e):null)??`${u.shell.id}~v`:null,p=fe(t[xa]),h=[];if(Array.isArray(p)&&p.length<=Fe)for(let m of p){let S=Ln(m,n,null,e,true);if(!S)break;let{r:L,x:v,...b}=m;h.push({shell:S.shell,signature:JSON.stringify(b),inside:Br(m,e,n),outside:Br(m,e,n,"x")});}let g=ha(h,wn(t,e,n)),y=g.map(m=>m.shell),I=g.map(m=>m.signature),k=o?JSON.stringify([t[zr],typeof t[Zt]=="string"?t[Zt]:"",...s.map(m=>[m,t[m]])]):void 0;return Object.freeze({run:o?.shell??null,runProperties:i.length>0||r?d:null,properties:Object.freeze(i),text:u?.shell??null,textValueId:f,wrap:Object.freeze(y),...k!==void 0?{runSignature:k}:{},wrapSignatures:Object.freeze(I)})}function Kr(t,e,n,o,r={}){let i=[],s=[],a=c=>{for(let u of c.entries){for(let f of u.slot?.before??[])a(f);u.item&&(i.push(u.item),s.push(u.placement),u.item.kind==="char"&&r.onCharacter?.(u.character??null));for(let f of u.slot?.after??[])a(f);}},l=(c,u=false)=>{let f=r.following?.at.get(c);for(let p of (u?f?.before:f?.after)??[])a(p);};for(let c of r.following?.atStart??[])a(c);let d=0;for(let c of t){let u=Ae(c.attributes,n,o);if(typeof c.insert=="string"){for(let h=0;h<c.insert.length;h+=1,d+=1)if(!r.hidden?.has(d)){if(l(d,true),i.push({kind:"char",value:c.insert[h],attributes:u}),s.push(void 0),r.onCharacter){let g=r.characters?.items[d];r.onCharacter(g===void 0?null:{item:g,identity:r.characters?.ids[d]??null});}l(d);}continue}if(d+=1,r.hidden?.has(d-1)||!ie(c.insert))continue;if(c.insert.a===1){i.push({kind:"anchor",attributes:u}),s.push(void 0);continue}let f=c.insert.n;if(typeof f!="string"||O(f))continue;let p=e(f);p&&(i.push({kind:"embed",node:p,attributes:u}),s.push(c.insert.r===1));}for(let c of r.following?.atEnd??[])a(c);return Vf(i,s,o,r.onRepair)}function wa(t,e,n=o=>o){let o=new Set,r=(i,s)=>{if(e.has(i.id))return i;let l=s!==null&&i.id.startsWith(s.from)&&(i.id[s.from.length]==="~"||i.id[s.from.length]==="/")?`${s.to}${i.id.slice(s.from.length)}`:i===t?i.id:n(i.id);if(o.has(l)){let f=2;for(;o.has(`${l}~${f}`);)f+=1;l=`${l}~${f}`;}if(o.add(l),i.kind==="textValue")return l===i.id?i:Object.freeze({...i,id:l});let d=l===i.id?null:{from:i.id,to:l},c=i.children.map(f=>r(f,d));return d===null&&c.every((f,p)=>f===i.children[p])?i:Object.freeze(Ge(i,Object.freeze(c),l))};return Wt(r(t,null))}function $f(t,e){return t.kind==="char"||t.kind==="embed"&&e===true}function ba(t){return t.kind==="char"}function Wf(t){return Object.freeze({run:null,runProperties:null,properties:Object.freeze([]),text:null,textValueId:null,wrap:t.wrap,...t.wrapSignatures?{wrapSignatures:t.wrapSignatures}:{}})}function Kf(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 Vf(t,e,n,o){let r=(d,c)=>$f(d,e[c])&&!d.attributes.run||d.kind==="embed"&&e[c]===false&&d.attributes.run!==null||ba(d)&&d.attributes.run!==null&&!d.attributes.text;if(!t.some(r))return t;o?.();let i=(d,c)=>{for(let u=1;u<t.length;u+=1){let f=t[d-u];if(f&&c(f,d-u))return f;let p=t[d+u];if(p&&c(p,d+u))return p;if(!f&&!p)break}return null},s=(d,c)=>d.attributes.run!==null&&!(d.kind==="embed"&&e[c]===false),a=qn(`${n}~r`,"run","r"),l=[];return t.forEach((d,c)=>{if(!r(d,c)){l.push(d);return}let u=t[c-1];if(d.kind==="char"&&u?.kind==="char"&&Xf(d.value)&&Jf(u.value)){l.push({...d,attributes:l[l.length-1].attributes});return}let f=d.attributes;if(d.kind==="embed"&&e[c]===false){l.push({...d,attributes:Wf(f)});return}if(!f.run){let p=i(c,s);f=Kf(f,p?.attributes??null,a);}if(ba(d)&&!f.text){let p=f.run,h=i(c,g=>g.kind==="char"&&g.attributes.run?.id===p.id&&!!g.attributes.text);f=Object.freeze({...f,text:h?.attributes.text??qn(`${p.id}~t`,"text","t",[Object.freeze({kind:"xmlSpace",namespaceUri:XML_NAMESPACE_URI,localName:"space",prefix:"xml",value:"preserve"})]),textValueId:h?.attributes.textValueId??null});}l.push({...d,attributes:f});}),l}function Jf(t){let e=t.charCodeAt(0);return t.length===1&&e>=55296&&e<=56319}function Xf(t){let e=t.charCodeAt(0);return t.length===1&&e>=56320&&e<=57343}var Hf=8;function so(t){let e=new Map;t.identities.ids.forEach((c,u)=>{c&&!t.hidden.has(u)&&!e.has(c)&&e.set(c,u);});let n=new Map;for(let c of t.incoming)c.identities.forEach((u,f)=>{u&&!n.has(u)&&n.set(u,{piece:c,index:f});});let o=new Map;for(let c of t.incoming){if(e.has(c.after))continue;let u=n.get(c.after);u&&u.piece!==c&&o.set(c,Gf(c,u,t));}let r=c=>{let u=c;for(let f=0;f<=Hf;f+=1){let p=o.get(u);if(!p)return true;u=p.piece;}return false};for(;;){let c=t.incoming.find(u=>o.has(u)&&!r(u));if(!c)break;o.delete(c);}let i=new Map,s=new Map,a=[],l=[],d=(c,u)=>{let f=c.get(u);return f||(f={before:[],after:[]},c.set(u,f)),f};for(let c of t.incoming){if(c.atStart){l.push(c);continue}let u=e.get(c.after),f=o.get(c),p=null;if(u!==void 0)p=d(i,u);else if(f){let h=s.get(f.piece);h||(h=new Map,s.set(f.piece,h)),p=d(h,f.index);}p?c.before?p.before.push(c):p.after.push(c):a.push(c);}return {atPosition:i,inside:s,atEnd:a,atStart:l}}function Gf(t,e,n){if(t.before)return e;let{positions:o,items:r}=e.piece,{items:i,origins:s}=n.identities,a=r[e.index];if(a===void 0||i[o[e.index]]!==a)return e;let l=u=>Ft(a,u),d=new Set,c=e.index;for(let u=c+1;u<o.length;u+=1){let f=r[u],p=o[u],h=i[p]===f?s[p]:null;if(!(h===a&&!l(f))&&!(h!==null&&d.has(h)))break;d.add(f),c=u;}return {piece:e.piece,index:c}}var Xr="docx-text-deletions-v1",qf=/^d(\d{1,16}):(\d{1,16})$/,Zf=/^(\d{1,16}):(\d{1,16}):(\d{1,16})$/,Vr=4096,Qf=1<<20;function ao(t){let e=Number(t);return Number.isSafeInteger(e)?e:null}function ep(t,e){let n=qf.exec(t);if(!n||typeof e!="string")return null;let o=ao(n[1]);if(o===null)return null;let r=[];for(let i of e.split(";")){if(r.length>=Vr)return null;let s=Zf.exec(i);if(!s)return null;let a=ao(s[1]),l=ao(s[2]),d=ao(s[3]);if(a===null||l===null||d===null||d<1||d>Qf)return null;r.push({client:a,from:l,to:l+d});}return r.length===0?null:{client:o,runs:r}}var Qt=class t{starts=[];ends=[];static of(e){let n=new t,o=[...e].sort((r,i)=>r.from-i.from);for(let{from:r,to:i}of o){let s=n.ends.length-1;s>=0&&r<=n.ends[s]?n.ends[s]=Math.max(n.ends[s],i):(n.starts.push(r),n.ends.push(i));}return n}add(e,n){let o=0,r=this.starts.length;for(;o<r;){let l=o+r>>1;this.ends[l]<e?o=l+1:r=l;}let i=o,s=e,a=n;for(;i<this.starts.length&&this.starts[i]<=n;)s=Math.min(s,this.starts[i]),a=Math.max(a,this.ends[i]),i+=1;this.starts.splice(o,i-o,s),this.ends.splice(o,i-o,a);}has(e){let n=0,o=this.starts.length-1;for(;n<=o;){let r=n+o>>1;if(this.starts[r]>e)o=r-1;else if(this.ends[r]<=e)n=r+1;else return true}return false}},Jr=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+=Vr){let r=e.slice(o,o+Vr).map(s=>`${s.client}:${s.from}:${s.to-s.from}`).join(";"),i=`d${this.doc.clientID}:${K.getState(this.doc.store,this.doc.clientID)}`;this.map.set(i,r),this.refresh(i,r),n.push(i);}return n}withdraw(e){let n=`d${this.doc.clientID}:`;for(let o of e)!o.startsWith(n)||!this.map.has(o)||this.map.delete(o);}refreshKeys(e){let n=[];for(let o of e){if(o===null)continue;let r=this.byKey.get(o)??[];this.refresh(o,this.map.get(o));let i=this.byKey.get(o)??[];for(let s of r)n.push(s);for(let s of i)n.push(s);}if(n.length!==0)for(let o of this.listeners)o(n);}refresh(e,n){let o=this.byKey.get(e);this.byKey.delete(e);let r=ep(e,n),i=r?Ne(this.map,e):void 0,s=r!==null&&(!i||i.id.client===r.client);if(s&&this.byKey.set(e,r.runs),o){let a=new Set(o.map(l=>l.client));for(let l of a)this.keysByClient.get(l)?.delete(e);s&&this.list(e,r.runs);for(let l of s?r.runs:[])a.add(l.client);for(let l of a)this.stale.add(l);}else if(s){this.list(e,r.runs);for(let a of r.runs){if(this.stale.has(a.client))continue;let l=this.characters.get(a.client);l||this.characters.set(a.client,l=new Qt),l.add(a.from,a.to);}}}list(e,n){for(let o of n){let r=this.keysByClient.get(o.client);r||this.keysByClient.set(o.client,r=new Set),r.add(e);}}reindex(e){let n=this.keysByClient.get(e);if(!n||n.size===0){this.keysByClient.delete(e),this.characters.delete(e);return}let o=[];for(let r of n)for(let i of this.byKey.get(r)??[])i.client===e&&o.push(i);this.characters.set(e,Qt.of(o));}},va=new WeakMap;function qe(t){let e=va.get(t);if(e)return e;let n=t.getMap(Xr),o=new Jr(t,n);return t.on("beforeObserverCalls",r=>{let i=Ut(r,n);i&&o.refreshKeys(i);}),va.set(t,o),e=o,e}var qr="docx-text-decisions-v1",tp=/^a(\d{1,16}):(\d{1,16})$/,np=/^(\d{1,16}):(\d{1,16}):(\d{1,16})$/,Hr=4096,op=1<<20,rp=4096;function lo(t){let e=Number(t);return Number.isSafeInteger(e)?e:null}function ip(t,e){let n=tp.exec(t);if(!n||typeof e!="string")return null;let o=lo(n[1]);if(o===null)return null;let r=e.indexOf(`
|
|
3
|
+
`);if(r<0)return null;let i=e.slice(0,r);if(!i.startsWith(de)||i.length>rp||O(i))return null;let s=[];for(let a of e.slice(r+1).split(";")){if(s.length>=Hr)return null;let l=np.exec(a);if(!l)return null;let d=lo(l[1]),c=lo(l[2]),u=lo(l[3]);if(d===null||c===null||u===null||u<1||u>op)return null;s.push({client:d,from:c,to:c+u});}return s.length===0?null:{client:o,revision:i,runs:s}}var Gr=class{constructor(e,n){this.doc=e;this.map=n;n.forEach((o,r)=>this.refresh(r,o));}doc;map;byKey=new Map;index=null;listeners=new Set;subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}names(e){return this.indexed().has(e)}get empty(){return this.byKey.size===0}decided(e,n,o){return this.indexed().get(e)?.get(n)?.has(o)??false}record(e,n){let o=[];for(let r=0;r<n.length;r+=Hr){let i=`${e}
|
|
4
|
+
${n.slice(r,r+Hr).map(a=>`${a.client}:${a.from}:${a.to-a.from}`).join(";")}`,s=`a${this.doc.clientID}:${K.getState(this.doc.store,this.doc.clientID)}`;this.map.set(s,i),this.refresh(s,i),o.push(s);}return o}refreshKeys(e){let n=[];for(let o of e)if(o!==null){for(let r of this.byKey.get(o)?.runs??[])n.push(r);this.refresh(o,this.map.get(o));for(let r of this.byKey.get(o)?.runs??[])n.push(r);}if(n.length!==0)for(let o of this.listeners)o(n);}refresh(e,n){let o=this.byKey.delete(e),r=ip(e,n),i=r?Ne(this.map,e):void 0,s=r!==null&&(!i||i.id.client===r.client);s&&this.byKey.set(e,r),(o||s)&&(this.index=null);}indexed(){if(this.index)return this.index;let e=new Map;for(let{revision:o,runs:r}of this.byKey.values()){let i=e.get(o);i||e.set(o,i=new Map);for(let s of r){let a=i.get(s.client);a||i.set(s.client,a=[]),a.push(s);}}let n=new Map;for(let[o,r]of e){let i=new Map;for(let[s,a]of r)i.set(s,Qt.of(a));n.set(o,i);}return this.index=n,n}},Ra=new WeakMap;function Rn(t){let e=Ra.get(t);if(e)return e;let n=t.getMap(qr);e=new Gr(t,n);let o=e;return t.on("beforeObserverCalls",r=>{let i=Ut(r,n);i&&o.refreshKeys(i);}),Ra.set(t,e),e}function Ea(t,e,n,o){let r=new Set(Object.keys(e).filter(s=>s.startsWith(de)&&e[s]===null)),i=t.doc;if(i&&n&&r.size>0){let s=[];for(let{position:l}of o){let[d,c]=(n[l]??"").split(":").map(Number);if(!Number.isSafeInteger(d)||!Number.isSafeInteger(c)||d<0)continue;let u=s[s.length-1];u&&u.client===d&&u.to===c?s[s.length-1]={client:d,from:u.from,to:c+1}:s.push({client:d,from:c,to:c+1});}let a=Rn(i);if(s.length>0)for(let l of r)a.record(l,s);}Ss(t,o[0].position,o.length,e,r);}var On="s",Da=256,sp=new Set(["del","moveFrom"]),ap=/^\d{1,16}$/,co=new Map,lp=4096;function uo(t){if(typeof t!="string"||!t.includes(`"${On}":`))return null;let e=co.get(t);if(e!==void 0)return e;let n=null,o=fe(t),r=ie(o)?o[On]:void 0;if(ie(r)&&Object.keys(r).length<=Da&&Zr(o)){n=new Map;for(let[i,s]of Object.entries(r)){if(!ap.test(i)||!Number.isSafeInteger(s)||s<0){n=null;break}n.set(Number(i),s);}}return co.size>=lp&&co.clear(),co.set(t,n),n}function Zr(t){let e=typeof t=="string"?fe(t):t,n=ie(e)?e.e:void 0;return ie(n)&&n.n===void 0&&sp.has(n.l)}function Na(t,e){let n=null,o=null;for(let[r,i]of Object.entries(t)){if(!r.startsWith(de)||i===null||!Zr(i))continue;let s=fe(i);if(s[On]===void 0){if(!o){let a=new Map;for(let{client:l,clock:d}of e)l<0||a.set(l,Math.max(a.get(l)??0,d+1));if(a.size===0||a.size>Da)return {...t};o={};for(let l of [...a.keys()].sort((d,c)=>d-c))o[l]=a.get(l);}n??={...t},n[r]=JSON.stringify({...s,[On]:o});}}return n??{...t}}function Tt(t){let e=null,n=null;for(let[o,r]of Object.entries(t)){if(!o.startsWith(de)||uo(r)===null||(n??=kn(t[be]),n.has(o)))continue;let{[On]:i,...s}=fe(r);e??={...t},e[o]=JSON.stringify(s);}return e??t}function Ca(t,e,n){let o=null;for(let r in t){if(!r.startsWith(de))continue;let i=uo(t[r]);i&&n>=(i.get(e)??0)&&(o??=[]).push(r);}return o}function dp(t,e,n,o){let r=o;for(let i in t){if(!i.startsWith(de))continue;let s=uo(t[i])?.get(e)??0;s>n&&s<r&&(r=s);}return r}var Ta="t",Ma={delText:{},delInstrText:{l:"instrText",k:"instrText"}};function cp(t,e){let n={...t};for(let i of e)delete n[i];for(let i in n)if(i.startsWith(de)&&Zr(n[i]))return n;let o=fe(n[Ta]),r=ie(o)&&typeof o.l=="string"&&Object.hasOwn(Ma,o.l)?Ma[o.l]:void 0;if(ie(o)&&r&&o.n===void 0){let{l:i,k:s,...a}=o;n[Ta]=JSON.stringify({...a,...r});}return n}function Pa(t,e,n,o){let r=null;for(let i of e)t.decided(i,n,o)&&(r??=[]).push(i);return r}function Aa(t,e){return t?e?[...new Set([...t,...e])].sort():t:e}function Mt(t){return Qr(t).ops}function Qr(t){let e=false,n=[],o={},r=null,i=()=>r??={...o},s=false,a=t.doc?Rn(t.doc):null,l=a&&!a.empty?a:null,d=null,c=()=>{if(d)return d;d=[];for(let y in o)y.startsWith(de)&&l.names(y)&&d.push(y);return d},u=null,f=(y,I)=>{let k={insert:y};Object.keys(I).length>0&&(k.attributes=I),n.push(k),u=null;},p=new Map,h=y=>{e=true;let I=y.join(`
|
|
5
|
+
`),k=p.get(I);return k||p.set(I,k=cp(i(),y)),k},g=(y,I)=>{let k=n.at(-1);k&&u===I?k.insert=k.insert+y:(f(y,I),u=I);};for(let y=ge(t);y;y=y.right){if(y.deleted)continue;let I=y.content;if(I instanceof K.ContentFormat){I.value===null?delete o[I.key]:o[I.key]=I.value,uo(I.value)!==null&&(s=true),r=null,d=null,p=new Map;continue}let{client:k,clock:m}=y.id,S=l&&c().length>0?l:null;if(I instanceof K.ContentString){let L=I.str;if(!s&&!S){g(L,i());continue}for(let v=0;v<L.length;){let b=s?Ca(i(),k,m+v):null,w=S?Pa(S,c(),k,m+v):null,E=S?v+1:dp(i(),k,m+v,m+L.length)-m,M=Aa(b,w);g(L.slice(v,E),M?h(M):i()),v=E;}continue}if(I instanceof K.ContentEmbed||I instanceof K.ContentType){let L=s?Ca(i(),k,m):null,v=S?Pa(S,c(),k,m):null,b=Aa(L,v);f(I.getContent()[0],b?h(b):{...i()});}}return {ops:n,leftOut:e}}function fp(t,e,n,o,r,i){let s=Mt(t);if(!r)return Kr(s,e,n,o);let a=r.shown(t);(a.hidden.size>0||a.incoming.length>0)&&r.noteDrift();let l=new Map;for(let h of a.incoming){let g=l.get(h.source)??new Set;for(let y of h.positions)g.add(y);l.set(h.source,g);}let d=new Map;for(let[h,g]of l)d.set(h,pp(r.textOf(h),h,g,e,n));let c=so(a),u=h=>{let g=d.get(h.source),y=c.inside.get(h),I=[];return h.positions.forEach((k,m)=>{let S=g.get(k),L=y?.get(m);if(!S&&!L)return;let v=h.items[m];I.push({item:S?.item,placement:S?.placement,...L?{slot:f(L)}:{},...v!==void 0?{character:{item:v,identity:h.identities[m]??null}}:{}});}),{entries:I}},f=h=>({before:h.before.map(u),after:h.after.map(u)}),p=new Map;for(let[h,g]of c.atPosition)p.set(h,f(g));return Kr(s,e,n,o,{hidden:a.hidden,following:{at:p,atEnd:c.atEnd.map(u),atStart:c.atStart.map(u)},onRepair:()=>r.noteDrift(),...i?{onCharacter:i,characters:{items:a.identities.items,ids:a.identities.ids}}:{}})}function pp(t,e,n,o,r){let i=new Map;if(!t)return i;let s=0;for(let a of Mt(t)){let l=typeof a.insert=="string"?a.insert.length:1;if(typeof a.insert=="string"){let d=null;for(let c=0;c<l;c+=1)n.has(s+c)&&(d??=Ae(a.attributes,r,e),i.set(s+c,{item:{kind:"char",value:a.insert[c],attributes:d},placement:void 0}));}else if(n.has(s)){let d=a.insert,c=d?.n,u=typeof c=="string"&&!O(c)?o(c):null;u&&i.set(s,{item:{kind:"embed",node:u,attributes:Ae(a.attributes,r,e)},placement:d?.r===1});}s+=l;}return i}function Ze(t,e,n,o,r,i){let s=new Set,a=new Set,l=fp(e,f=>{if(r&&!r.showsEmbed(f))return r.noteDrift(),null;let p=r?.lineageOf?.(f)??null;if(p!==null&&p!==f){if(a.has(p)||r.listed?.(p))return r.noteDrift(),null;a.add(p);}let h=n(f);return h&&s.add(f),h},o,t,r,i),d=Pe({id:t,kind:"paragraph",namespaceUri:WML_NAMESPACE_URI,localName:"p",namespaceBindings:[],attributes:[],children:[]}),c=oa({shell:d,items:l}),u=wa(c,s,r?f=>r.shownId(f):void 0);return r&&u!==c&&r.noteDrift(),u.children}function fo(t,e){let n=new K.Text;t.set(se,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 _a(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&&Ba(r,o)?r:o})}function Ba(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&&ei(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)&&ei(t.namespaceBindings,e.namespaceBindings,(n,o)=>n.prefix===o.prefix&&n.namespaceUri===o.namespaceUri)&&ei(t.children,e.children,Ba)}function ei(t,e,n){return t.length===e.length&&t.every((o,r)=>n(o,e[r]))}var ja=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"]})),za=new Set(["drawingWrapNone","drawingWrapSquare","drawingWrapTight","drawingWrapThrough","drawingWrapTopBottom"]),$a=new Map([["inlineDrawing",new Set(["drawingSimplePos","drawingPositionH","drawingPositionV","drawingSizeRelH","drawingSizeRelV",...za])]]),hp=new Set(["choice:position"]),Wa=new Map(Object.entries({drawing:t=>t.kind==="anchoredDrawing"||t.kind==="inlineDrawing"?"choice:placement":null,drawingPositionH:()=>"choice:position",drawingPositionV:()=>"choice:position",anchoredDrawing:t=>za.has(t.kind)?"choice:wrap":null})),Ua={paragraph:"paragraphProperties",run:"runProperties"},gp=new Set(["sectPr","pPrChange"]);function ti(t){return t.kind==="generic"&&t.namespaceUri===WML_NAMESPACE_URI&&gp.has(t.localName)}var Ka=new Set(["paragraphProperties","runProperties","tableProperties"]);function mp(t,e){if(ja.get(t)?.includes(e.kind))return `kind:${e.kind}`;let n=Wa.get(t)?.(e);return n||(Ka.has(t)&&e.kind==="generic"&&e.namespaceUri===WML_NAMESPACE_URI?`wml:${e.localName}`:null)}function ni(t){return t!==null&&(ja.has(t)||Wa.has(t)||$a.has(t)||Ka.has(t))}function po(t,e,n){if(!ni(t))return null;let o=t,r=new Map,i=new Set,s=[],a=$a.get(o),l=new Set,d=-1;for(let I=0;I<e.length;I+=1){let k=e[I];if(i.has(k))continue;i.add(k);let m=n(k);if(s[I]=m,!m)continue;if(a?.has(m.kind)){l.add(I);continue}d<0&&(d=I);let S=mp(o,m);if(S===null)continue;let L=r.get(S);L?L.push(I):r.set(S,[I]);}let c=new Map;for(let[I,k]of r){if(k.length<2||k.every(L=>We(e[L])===null))continue;let m=hp.has(I)?k.find(L=>s[L]?.empty!==true)??k[0]:k[0],S=k.filter(L=>L!==m);for(let L of S)l.add(L);c.set(m,S);}let u=Ua[o]?`kind:${Ua[o]}`:null,f=u?r.get(u)?.[0]:void 0,p=f!==void 0&&d!==f,h=o==="paragraphProperties"?r.get("kind:runProperties")?.[0]:void 0,g=-1;if(h!==void 0)for(let I=h+1;I<e.length;I+=1){let k=s[I];k&&!l.has(I)&&!ti(k)&&(g=I);}if(l.size===0&&!p&&g<0)return null;let y=[];p&&y.push(f);for(let I=0;I<e.length;I+=1)l.has(I)||p&&I===f||g>=0&&I===h||(y.push(I),I===g&&y.push(h));return {order:y,companions:c}}function yp(t,e,n){return po(t,e,n)?.order??null}function Qe(t,e){if(O(e)||t.isTombstoned(e))return null;let n=t.schema.nodes.get(e);if(!Y(n))return null;let o=He(n);return {kind:o.kind,namespaceUri:Rt(t.schema.namespaces,o.namespaceId),localName:o.localName,...re(n)?.length===0?{empty:true}:{}}}function Va(t,e,n){let o=yp(t,e,n);if(!o)return {shown:e,hidden:[]};let r=o.map(s=>e[s]),i=new Set(r);return {shown:r,hidden:e.filter(s=>!i.has(s))}}var oi=new Set(["paragraphProperties","runProperties","tableProperties"]);function Ja(t,e,n){let o=po(t,e,n);if(!o)return {shown:e,hidden:[],merges:null};let r=o.order.map(s=>e[s]),i=new Set(r);return {shown:r,hidden:e.filter(s=>!i.has(s)),merges:bp(o,e,n)}}function bp(t,e,n){let o=null;for(let[r,i]of t.companions){let s=n(e[r]);!s||!oi.has(s.kind)||(o??=new Map,o.set(e[r],i.map(a=>e[a])));}return o}function Ip(t,e){let n=Qe(t,e);return n?n.kind==="paragraphProperties"||n.kind==="runProperties"?n.kind:n.kind==="generic"&&n.localName==="ins"?"ins":null:null}var xp={paragraph:"paragraphProperties",paragraphProperties:"runProperties",runProperties:"ins"};function si(t,e,n){let o=t.record(e);return !o||!J(o)?[]:o.childIds.filter(r=>t.showsAsChild(r)&&Ip(t,r)===n)}function ri(t,e,n,o){return si(t,e,n).filter(r=>!o.has(r))}function Sp(t,e,n){let o=t.record(e);if(!o||!J(o))return false;let r=o.childIds.filter(i=>t.showsAsChild(i));return r.length===1&&r[0]===n}function kp(t,e,n){let o=[],r=e;for(let a of ["paragraphProperties","runProperties","ins"]){let l=si(t,r,a),d=l.filter(u=>We(u)===n),c=d.length===1?d[0]:l.length===1?l[0]:null;if(!c)return null;o.push({node:c,from:r,level:a}),r=c;}let i=o[2];if(We(i.node)!==n)return null;let s=i;for(let a=1;a>=0;a-=1){let l=o[a];if(We(l.node)!==n||!Sp(t,l.node,o[a+1].node))break;s=l;}return s}function wp(t,e,n,o,r){let{node:i,from:s,level:a}=e,l=n;for(a!=="paragraphProperties"&&(l=ri(t,n,"paragraphProperties",o)[0],l&&a==="ins"&&(l=ri(t,l,"runProperties",o)[0]));l;){let d=ri(t,l,a,o);if(d.length===0){r.push({node:i,from:s,to:l,first:a!=="runProperties"});return}if(a==="ins")return;let c=xp[a],u=si(t,i,c);if(u.length!==1)return;s=i,i=u[0],l=d[0],a=c;}}function vp(t,e){let n=[],o=e.source;for(let s of e.shown){let a=e.before.get(s),l=We(s);if(a&&l&&a!==o){let d=kp(t,a,l);d&&n.push({proposal:d,target:o});}o=s;}let r=new Set(n.map(({proposal:s})=>s.node)),i=[];for(let{proposal:s,target:a}of n)wp(t,s,a,r,i);return i}var ii=class{constructor(e){this.registry=e;}registry;moves=[];key="";hidden=new Map;added=new Map;refresh(e,n){let o=[];for(let s of n)for(let a of e.splitSiblings.groupsOf(s))o.push(...vp(e,a));let r=o.map(s=>`${s.node}>${s.to}`).join(";");if(r===this.key)return [];let i=new Set;for(let s of [...this.moves,...o])i.add(s.from),i.add(s.to);this.moves=o,this.key=r,this.hidden.clear(),this.added.clear();for(let s of o){let a=this.hidden.get(s.from);a||this.hidden.set(s.from,a=new Set),a.add(s.node);let l=this.added.get(s.to)??[];l.push(s),this.added.set(s.to,l);}return [...i]}movedOut(e,n){return this.hidden.get(e)?.has(n)??false}shownChildIds(e,n){let o=this.hidden.get(e),r=this.added.get(e);if(!o&&!r)return [...n];let i=o?n.filter(d=>!o.has(d)):[...n],s=(r??[]).filter(d=>d.first&&!i.includes(d.node)),a=(r??[]).filter(d=>!d.first&&!i.includes(d.node)),l=ai(this.registry,i);return [...s.map(d=>d.node),...i.slice(0,l),...a.map(d=>d.node),...i.slice(l)]}movesAt(e){return this.moves.filter(n=>n.from===e||n.to===e)}};function ai(t,e){let n=e.findIndex(o=>{let r=Qe(t,o);return r!==null&&ti(r)});return n<0?e.length:n}var Xa=new WeakMap;function st(t){let e=Xa.get(t);return e||Xa.set(t,e=new ii(t)),e}function Ha(t,e){let n=t.splitSiblings.takeChanged();n.length>0&&t.inline.orderChanged();for(let r of n)e.add(r);let o=new Set(t.splitSiblings.parentsWithRuns());for(let r of e){let i=t.parentOf(r);i&&o.add(i);}for(let r of st(t).refresh(t,o))e.add(r);}var Lp=new Set(["run","runProperties"]),Rp=new Set(["t","delText","instrText","delInstrText"]),el=new Set(["hyperlink","ins","del","moveFrom","moveTo","sdt","sdtContent","fldSimple","smartTag","customXml","dir","bdo"]);function tl(t){return Lp.has(t.kind)?true:t.namespaceUri===WML_NAMESPACE_URI&&(Rp.has(t.localName)||el.has(t.localName))}function qa(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 Za(t){return t.replace(/(~\d+)+$/,"")}var li=class{nodes=new Map;refusal=null;refuse(e,n){return this.refusal??={code:e,detail:n},false}described=new Set;add(e,n,o){let r=U(e),i=o.has(r),s={id:r,kind:e.kind,namespaceUri:e.kind==="textValue"?"":e.namespaceUri,localName:e.kind==="textValue"?"":e.localName,...e.kind!=="textValue"&&e.prefix!==void 0?{prefix:e.prefix}:{},attributes:e.kind==="textValue"?[]:[...e.attributes],bindings:e.kind==="textValue"?[]:[...e.namespaceBindings],children:[],value:e.kind==="textValue"?e.value:null,parent:n,opaque:i,block:false,paragraph:false};if(this.nodes.set(r,s),!(e.kind==="textValue"||i))for(let a of e.children)s.children.push(U(a)),this.add(a,r,o);}placeholder(e,n){let o=this.nodes.get(e);if(o)return o;let r={id:e,kind:n,namespaceUri:"",localName:"",attributes:[],bindings:[],children:[],value:null,parent:null,opaque:true,block:false,paragraph:false};return this.nodes.set(e,r),r}detach(e){let n=this.nodes.get(e);if(!n||n.parent===null)return;let o=this.nodes.get(n.parent);if(o){let r=o.children.indexOf(e);r>=0&&o.children.splice(r,1);}n.parent=null;}open(e){let n=this.nodes.get(e);return n!==void 0&&!n.opaque&&!this.insideOpaque(n)}insideOpaque(e){let n=e.parent;for(let o=0;n!==null&&o<256;o+=1){let r=this.nodes.get(n);if(!r)return false;if(r.opaque)return true;n=r.parent;}return false}region(e){let n=[],o=this.nodes.get(e);for(let i=0;o&&i<256&&(n.push(o),!o.paragraph);i+=1)o=o.parent===null?void 0:this.nodes.get(o.parent);let r=n[n.length-1];if(!r?.paragraph)return null;for(let i=n.length-2;i>=0;i-=1){let s=n[i];if(s.block||s.opaque)return {paragraph:r.id,inline:false};if(!(s.kind==="textValue"||tl(s)||n[i+1].kind==="runProperties"||Op(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"?Kt(Za(o.id),o.value??""):Pe({id:o.paragraph||o.opaque?o.id:Za(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 Op(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&&el.has(r.localName))return o.namespaceUri===WML_NAMESPACE_URI&&/Pr$|^fldData$/.test(o.localName)}return false}function Qa(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 ho(t,e){let n=e.map(Vt),o=new Map;for(let I of n)I.kind==="putNode"&&o.set(I.descriptor.logicalId,I);let r=I=>t.inline.textOf(I)||o.get(I)?.descriptor.kind==="paragraph"||t.kindOf(I)==="paragraph"&&!Mp(t,I)?I:t.inline.owner(I),i=new Set;for(let I of n)for(let k of Qa(I)){let m=r(k);m&&i.add(m);}if(i.size===0)return {passThrough:[...n],plan:null};let s=I=>{let k=new li,m=new Set;for(let S of I){let L=t.inline.textOf(S),v=k.placeholder(S,"paragraph");v.opaque=false,v.paragraph=true,v.kind="paragraph",v.namespaceUri=WML_NAMESPACE_URI,v.localName="p";let b=t.record(S),w=b&&"childIds"in b?b.childIds:[],{shown:E}=Va("paragraph",st(t).shownChildIds(S,w),_=>Qe(t,_));for(let _ of E){let z=k.placeholder(_,t.kindOf(_)??"generic");z.block=true,z.parent=S,v.children.push(_);}if(!L)continue;let M=new Set,j=_=>!t.showsAsChild(_)||M.has(_)?null:(M.add(_),Zn(_));for(let _ of Ze(S,L,j,t.limits,t.inline.viewOf(S)))k.add(_,S,M),v.children.push(U(_));for(let _ of M){m.add(_);let z=k.nodes.get(_);z&&(z.kind=t.kindOf(_)??"generic");}}return {scratch:k,embedsBefore:m}},{scratch:a,embedsBefore:l}=s(i),d=n.flatMap(I=>Qa(I)).filter(I=>!a.nodes.has(I)&&!o.has(I)&&!t.hasNode(I));if(d.length>0){let I=new Set(i);for(let k of Pp(t,new Set(d)))I.add(k);if(I.size>i.size){for(let k of I)i.add(k);({scratch:a,embedsBefore:l}=s(i));}}let c=[],u=new Map;for(let I of n){let k=Ep(a,I,t);if(k&&u.set(c.length,k),c.push(Cp(a,I,t)),a.refusal)return {passThrough:[...n],plan:null,refusal:a.refusal}}let f=[];n.forEach((I,k)=>{let m=u.get(k);m?f.push(m):(!c[k]||!Tp(a,I))&&f.push(I);});let p=[...i].filter(I=>a.nodes.get(I)?.paragraph).map(I=>({id:I,after:Wt(a.toTree(I))})),[h,...g]=n,y=g.length===0&&h?.kind==="spliceText"&&h.deleteCount===0?{textValueId:h.logicalId,utf16Start:h.utf16Start}:void 0;return {passThrough:f,plan:{paragraphs:p,embedsBefore:l,...y?{typed:y}:{}}}}function Ep(t,e,n){if(e.kind!=="spliceChildren")return null;let o=t.nodes.get(e.parentLogicalId);if(!o?.paragraph)return null;let r=c=>{let u=t.nodes.get(c);return u?u.block||u.kind==="paragraphProperties":n.kindOf(c)==="paragraphProperties"},i=o.children.filter(c=>t.nodes.get(c)?.parent===o.id),a=o.children.slice(e.start,e.start+e.deleteCount).filter(c=>t.nodes.get(c)?.block).length,l=e.childLogicalIds.filter(r);if(a===0&&l.length===0)return null;let d=o.children.slice(0,e.start).filter(c=>i.includes(c)&&t.nodes.get(c)?.block).length;return {...e,start:d,deleteCount:a,childLogicalIds:l}}function Cp(t,e,n){switch(e.kind){case "putNode":{let{descriptor:o}=e;if(O(o.logicalId))return t.refuse("invalid-logical-id",o.logicalId);if(o.kind!=="textValue"&&(O(o.qname.localName)||o.qname.prefix!==void 0&&O(o.qname.prefix)))return t.refuse("prototype-key",o.logicalId);let r=t.nodes.get(o.logicalId);if(o.kind==="textValue"){if(r&&t.described.add(o.logicalId),!r){let s=t.placeholder(o.logicalId,"textValue");s.opaque=false,s.value="";}return true}let i=r??t.placeholder(o.logicalId,o.kind);return r||(i.opaque=false),r?.opaque?false:(i.kind=o.kind,i.namespaceUri=o.qname.namespaceUri,i.localName=o.qname.localName,o.qname.prefix!==void 0&&(i.prefix=o.qname.prefix),o.kind==="paragraph"&&!n.hasNode(o.logicalId)&&(i.paragraph=true),true)}case "spliceText":{let o=t.nodes.get(e.logicalId);return !o||o.value===null||!t.open(e.logicalId)?false:!Number.isSafeInteger(e.utf16Start)||!Number.isSafeInteger(e.deleteCount)||e.utf16Start<0||e.deleteCount<0||e.utf16Start+e.deleteCount>o.value.length?t.refuse("invalid-bound",e.logicalId):o.value.length-e.deleteCount+e.insert.length>n.limits.maxTextLength?t.refuse("text-too-long",e.logicalId):(t.described.delete(e.logicalId)&&e.utf16Start===0&&e.deleteCount===0&&e.insert.length>0&&e.insert===o.value||(o.value=o.value.slice(0,e.utf16Start)+e.insert+o.value.slice(e.utf16Start+e.deleteCount)),true)}case "setAttribute":{let o=t.nodes.get(e.logicalId);if(!o||o.paragraph||!t.open(e.logicalId))return false;if(O(e.qname.localName)||e.qname.prefix!==void 0&&O(e.qname.prefix))return t.refuse("prototype-key",e.logicalId);let r=o.attributes.findIndex(i=>i.namespaceUri===e.qname.namespaceUri&&i.localName===e.qname.localName);return e.value===null?r>=0&&o.attributes.splice(r,1):r>=0?o.attributes[r]=qa(e.qname,e.value):o.attributes.push(qa(e.qname,e.value)),true}case "setNamespaceBinding":{let o=t.nodes.get(e.logicalId);if(!o||o.paragraph||!t.open(e.logicalId))return false;if(O(e.prefix))return t.refuse("prototype-key",e.logicalId);let r=o.bindings.findIndex(i=>i.prefix===e.prefix);return e.uri===null?r>=0&&o.bindings.splice(r,1):r>=0?o.bindings[r]={prefix:e.prefix,namespaceUri:e.uri}:o.bindings.push({prefix:e.prefix,namespaceUri:e.uri}),true}case "spliceChildren":{if(!t.open(e.parentLogicalId)){for(let a of e.childLogicalIds){let l=t.nodes.get(a);l&&(l.parent=e.parentLogicalId,l.outside=true);}return false}let o=t.nodes.get(e.parentLogicalId);if(!Number.isSafeInteger(e.start)||!Number.isSafeInteger(e.deleteCount)||e.start<0||e.deleteCount<0||e.start+e.deleteCount>o.children.length)return t.refuse("invalid-bound",e.parentLogicalId);if(o.children.length-e.deleteCount+e.childLogicalIds.length>n.limits.maxChildren)return t.refuse("too-many-children",e.parentLogicalId);let r=e.childLogicalIds.find(a=>O(a));if(r!==void 0)return t.refuse("invalid-logical-id",r);let i=o.children.splice(e.start,e.deleteCount);for(let a of i){let l=t.nodes.get(a);l?.parent===o.id&&(l.parent=null);}let s=[];for(let a of e.childLogicalIds){let l=n.kindOf(a);if(!t.nodes.has(a)&&(l===null||!n.hasNode(a)))return t.refuse("unknown-logical-id",a);let d=t.nodes.get(a)??t.placeholder(a,l);d.parent=o.id,d.outside=false,o.paragraph&&d.kind==="paragraphProperties"&&(d.block=true),s.push(a);}return o.children.splice(e.start,0,...s),true}case "moveNode":{let o=t.open(e.destinationParentLogicalId),r=t.nodes.get(e.logicalId)?.parent!=null;if(!o&&!r)return false;let i=n.kindOf(e.logicalId);if(!t.nodes.has(e.logicalId)&&(i===null||!n.hasNode(e.logicalId)))return t.refuse("unknown-logical-id",e.logicalId);let s=t.nodes.get(e.logicalId)??t.placeholder(e.logicalId,i);if(t.detach(e.logicalId),s.outside=!o,o){let a=t.nodes.get(e.destinationParentLogicalId);s.parent=a.id,a.children.splice(Math.max(0,Math.min(e.destinationIndex,a.children.length)),0,e.logicalId);}return o}default:return false}}function Tp(t,e){let n=o=>{let r=t.region(o);if(r)return r.inline;let i=t.nodes.get(o);if(!i||i.opaque||i.paragraph)return false;let s=t.detachedRoot(o);return !s.outside&&(s.kind==="textValue"||tl(s))};switch(e.kind){case "putNode":{let o=e.descriptor.logicalId,r=t.nodes.get(o);return !r||r.paragraph||r.opaque?false:n(o)}case "spliceText":case "setAttribute":case "setNamespaceBinding":return n(e.logicalId);case "spliceChildren":return t.nodes.get(e.parentLogicalId)?.paragraph===true||n(e.parentLogicalId);case "moveNode":return t.nodes.get(e.destinationParentLogicalId)?.paragraph===true||n(e.destinationParentLogicalId);default:return false}}function Mp(t,e){let n=t.record(e);return !n||!("childIds"in n)?true:n.childIds.some(o=>t.kindOf(o)==="run")}function Pp(t,e){let n=new Set,o=new Set(e),r=i=>i.some(s=>o.delete(U(s))||s.kind!=="textValue"&&r(s.children));return t.schema.nodes.forEach((i,s)=>{if(o.size===0)return;let a=Z(s),l=t.inline.textOf(a);if(!l||t.inline.isDeletedParagraph(a))return;let d=t.inline.viewOf(a);r(Ze(a,l,()=>null,t.limits,d))&&n.add(a);}),n}var Dp=new Set(["proofErr","permStart","permEnd"]);function di(t,e,n){return t==="bookmarkStart"||t==="bookmarkEnd"||isRangeMarkerKind(t)?true:t==="generic"&&n&&Dp.has(e)}var Np=Lt(WML_NAMESPACE_URI);function ci(t){if(!Y(t))return false;let e=He(t);return di(e.kind,e.localName,e.namespaceId===Np)}function ol(t){return ci(t)?Et(t):null}function nl(t){let e=n=>t.find(o=>o.namespaceUri===WML_NAMESPACE_URI&&o.localName===n)?.value??null;return [e("id"),e("name")]}function Yp(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 rl(t,e,n,o,r){if(n.size===0||e.length===0)return;let i=new Map;for(let a of e){let l=t.record(a);if(!l||!J(l)||l.childIds.length>0||!di(l.kind,l.localName,l.namespaceUri===WML_NAMESPACE_URI))continue;let d=JSON.stringify([l.kind,l.localName,...nl(l.attributes)]),c=i.get(d)??[];c.push(a),i.set(d,c);}if(i.size===0)return;let s=Yp(r);for(let a of n){if(!o.has(a))continue;let l=s.get(a);if(!l||!di(l.kind,l.localName,l.namespaceUri===WML_NAMESPACE_URI))continue;let d=JSON.stringify([l.kind,l.localName,...nl(l.attributes)]),c=i.get(d)?.shift();if(c===void 0)continue;let u=t.schema.nodes.get(a);if(!Y(u))continue;let f=t.splitLineageOf(c)??c;u.set(hn,f),u.set(kt,f);}}var _p=new Set(["tableRow","tableCell"]);function il(t,e,n){let o=new Map,r=a=>e.reinserted.has(a)&&!e.unlistedAtEnd.has(a),i=[],s=new Set;for(let a of e.removed){let l=t.kindOf(a);if(!(l===null||l==="paragraph"||_p.has(l))&&!(r(a)||!t.isTombstoned(a))){s.add(a);for(let d of n.get(a)??[])i.push(d);}}for(;i.length>0;){let a=i.pop();if(s.has(a)||r(a)||t.isTombstoned(a))continue;if(s.add(a),t.kindOf(a)==="paragraph"){if(Bp(t,a,s))continue;let c=Up(t,a);c.length>0&&o.set(a,c);continue}let d=t.nodeShape(a);if(d&&!d.isText)for(let c of d.children)i.push(c);}return o}function Bp(t,e,n){return t.listingParents(e).some(o=>!n.has(o)&&!t.isTombstoned(o))}function Up(t,e){let n=t.inline.textOf(e);if(!n)return [];let o=t.inline.viewOf(e).shown(n),r=[];o.identities.ids.forEach((i,s)=>{i&&!o.hidden.has(s)&&r.push(i);});for(let i of o.incoming)for(let s of i.identities)s&&r.push(s);return r}var at="o",Fp=/^(\^?)(\d{1,16}:\d{1,16})$/,et="-";function ll(t){if(t===et)return {identity:et,before:false};let e=typeof t=="string"?Fp.exec(t):null;return e?{identity:e[2],before:e[1]==="^"}:null}function fi(t,e,n,o,r){let i={...o};delete i[at];let s=Bt(t,e,n,i);s&&ke(t.doc).markCopy("move",s.id.client,s.id.clock,n.length,r);}function sl(t,e,n){let o=[],r=[],i="",s=()=>{r.length>0&&o.push({paragraph:e,indexes:r,value:i}),r=[],i="";};for(let a of t.steps){if(a.op!==n){a.op!==(n==="del"?"ins":"del")&&s();continue}let l=a.op==="del"?a.before:a.after,d=a.op==="del"?t.before[l]:t.after[l];if(typeof d.insert!="string"){s();continue}r.push(l),i+=d.insert;}return s(),o}function jp(t,e){let n=e.from+e.length;return (e.from===0||t[e.from-1])&&(n===t.length||t[n])}var zp=1<<20,al=1<<24;function ui(t,e,n,o,r,i,s=false){let a=e(t),l=o.get(t),d=null;for(let c of n){if(c.paragraph===t.paragraph!==s||!r(c.paragraph,t.paragraph))continue;let u=e(c),f=o.get(c),p=u.length*a.length;if(p>zp)continue;if(p>i.cells)return d;i.cells-=p;let h=new Uint32Array(a.length+1);for(let g=1;g<=u.length;g+=1){let y=new Uint32Array(a.length+1);for(let I=1;I<=a.length;I+=1){if(f[g-1]||l[I-1]||u[g-1]!==a[I-1])continue;let k=h[I-1]+1;y[I]=k,k>(d?.length??0)&&(d={source:c,from:g-k,to:I-k,length:k});}h=y;}}return d}function dl(t,e,n,o=()=>"",r=()=>""){let i=new Set,s=t.flatMap((b,w)=>sl(b,w,"del"));if(s.length===0)return i;let a=t.flatMap((b,w)=>sl(b,w,"ins")),l=new Set(s),d={cells:al},c=new Map,u=b=>w=>{let E=l.has(w),M=`${b}:${w.paragraph}:${w.indexes[0]}:${E}`,j=c.get(M);if(!j){let _=t[w.paragraph];j=w.indexes.map(z=>{let ee=E?_.before[z]:_.after[z],H=ee.insert;return b?`${H}\0${o(ee,w.paragraph)}`:H}),c.set(M,j);}return j},f=new Map;for(let b of [...s,...a])f.set(b,b.indexes.map(()=>false));let p=t.map((b,w)=>r(w)),h=(b,w)=>p[b]===""||p[w]===""||p[b]===p[w],g=(b,w)=>{for(let E=0;E<w.length;E+=1)f.get(w.source)[w.from+E]=true,f.get(b)[w.to+E]=true;Wp(t,b,w,e,n,i);};for(let b of a){let w=s.find(E=>E.paragraph!==b.paragraph&&h(E.paragraph,b.paragraph)&&E.value===b.value&&!f.get(E).some(Boolean));w&&g(b,{source:w,from:0,to:0,length:b.indexes.length});}let y=a.filter(b=>t[b.paragraph].before.length===0),I=b=>{let w={cells:al};for(let E of y.length===0?[]:s)if(!f.get(E).some(Boolean))for(let{run:M,from:j}of $p(E,y,f,h,w,b))g(M,{source:E,from:j,to:0,length:M.indexes.length});};I(false);for(let b of a)for(let w=ui(b,u(true),s,f,h,d);w;)g(b,w),w=ui(b,u(true),s,f,h,d);I(true);let k=new Map;for(let b of a)k.set(b.paragraph,[...k.get(b.paragraph)??[],b]);let m=new Set(s.filter(b=>(k.get(b.paragraph)??[]).some(w=>w.value.includes(b.value)))),S=s.filter(b=>!m.has(b)),L=(b,w,E)=>{for(;;){let M=ui(w,u(false),b,f,h,d,E);if(!M||!jp(f.get(M.source),M))break;g(w,M);}};for(let b of a)L(S,b,false);let v=new Map;for(let b of m)v.set(b.paragraph,[...v.get(b.paragraph)??[],b]);for(let b of a){let w=v.get(b.paragraph);w&&L(w,b,true);}return i}function $p(t,e,n,o,r,i){let s=(a,l)=>{if(a.value.length===0||a.paragraph===t.paragraph||!o(t.paragraph,a.paragraph)||n.get(a).some(Boolean))return -1;let d=i?t.value.length:a.value.length;return r.cells<d?-1:(r.cells-=d,i?t.value.indexOf(a.value,l):t.value.startsWith(a.value,l)?l:-1)};for(let a=0;a<e.length;a+=1){if(s(e[a],0)<0)continue;let l=[],d=0,c=0;for(let f=a;f<e.length&&d<t.value.length;f+=1){let p=e[f],h=s(p,d);if(h<0)break;l.push({run:p,from:h}),d=h+p.value.length,c+=p.value.length;}if(i?c*2>t.value.length:c===t.value.length&&l.length>1)return l}return []}function Wp(t,e,n,o,r,i){let s=t[n.source.paragraph],a=c=>{let u=s.before[n.source.indexes[n.from+c]];return u?.position===void 0?null:s.identities[u.position]??null},l=t[e.paragraph],d=null;for(let c=0;c<n.length;c+=1){let u=e.indexes[n.to+c],f=a(c);f&&i.add(f);let p=c>0?l.after[e.indexes[n.to+c-1]]:null,h=p!==null&&r(p)===r(l.after[u]);(!d||!h||!Ft(a(c-1),f))&&(d=f),d&&(l.after[u]=o(l.after[u],d));}}var Kp="docx-text-marks-v1",Vp={move:"o",restore:"u",follow:"f"},ml=/^([ouf])(\d{1,16}):(\d{1,16})$/,Jp=/^(\d{1,16}):(\d{1,16}):(\d{1,16})$/,Xp=/^(\d{1,16})\|(.{1,40})$/,hi=16,cl=1<<20,ul=4096;function fl(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 pl(t,e,n){return `${Vp[t]}${e}:${n}`}function Ke(t){let e=Number(t);return Number.isSafeInteger(e)?e:null}function Hp(t,e){let n=ml.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 u=Xp.exec(e),f=u?Ke(u[1]):null,p=u?ll(u[2]):null;return f===null||f<1||f>cl||!p?null:{kind:o,client:r,span:{key:t,client:r,firstClock:i,length:f,origin:null,follow:p}}}let s=Jp.exec(e),a=s?Ke(s[1]):null,l=s?Ke(s[2]):null,d=s?Ke(s[3]):null;return a===null||l===null||d===null||d<1||d>cl?null:{kind:o,client:r,span:{key:t,client:r,firstClock:i,length:d,origin:{client:a,clock:l,insertClient:r,firstClock:i,length:d},follow:null}}}var Gp={origin:()=>null,follow:()=>null,followStart:()=>null},pi=class{constructor(e,n){this.doc=e;this.map=n;n.forEach((o,r)=>this.refresh(r,o));}doc;map;spans={move:new Map,restore:new Map,follow:new Map};byKey=new Map;dependents=new Map;listeners=new Set;textsOfClients=new Map;subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}origin(e,n,o){return this.find(e,n,o)?.origin??null}follow(e,n){return this.find("follow",e,n)?.follow??null}followStart(e,n){return this.find("follow",e,n)?.firstClock??null}markCopy(e,n,o,r,i){this.write(pl(e,n,o),`${i}:${r}`);}markFollow(e,n,o,r){this.write(pl("follow",e,n),`${o}|${r}`);}refreshKeys(e){let n=[];for(let r of e){if(r===null)continue;let i=this.byKey.get(r)?.span.length??0;this.refresh(r,this.map.get(r));let s=this.byKey.get(r)?.span.length??0,a=ml.exec(r),l=a?Ke(a[2]):null,d=a?Ke(a[3]):null;l===null||d===null||n.push({client:l,from:d,to:d+Math.max(i,s,1)});}let o=this.textsReading(n);if(!(o!=="all"&&o.size===0))for(let r of this.listeners)r(o);}textsReading(e){let n=new Set,o=new Set,r=new Set,i=()=>{for(let a of r)for(let l of this.textsOfClient(a))n.add(l);return n},s=e;for(let a=0;a<=hi&&s.length>0;a+=1){let l=[];for(let d of s)r.add(d.client);for(let d of s){let c=`${d.client}:${d.from}:${d.to}`;if(!o.has(c)){if(o.size>=ul)return this.withDependents(r,i);o.add(c);for(let u=d.from,f=0;u<d.to;f+=1){if(f>=ul)return this.withDependents(r,i);let p=q(this.doc,{client:d.client,clock:u});if(!p)break;p.parent instanceof K.Text&&n.add(p.parent),u=p.id.clock+p.length;}for(let u of this.dependents.get(d.client)??[]){let f=qp(u,d);f&&l.push(f);}}}s=l;}return n}withDependents(e,n){let o=[...e];for(;o.length>0;){let r=o.pop();for(let i of this.dependents.get(r)??[])e.has(i.client)||(e.add(i.client),o.push(i.client));}return n()}textsOfClient(e){let n=K.getState(this.doc.store,e),o=this.textsOfClients.get(e);if(o?.state===n)return o.texts;let r=new Set;for(let i of this.doc.store.clients.get(e)??[]){let s=i instanceof K.Item?i.parent:null;s instanceof K.Text&&r.add(s);}return this.textsOfClients.set(e,{state:n,texts:r}),r}write(e,n){this.map.get(e)!==n&&(this.map.set(e,n),this.refresh(e,n));}refresh(e,n){this.remove(e);let o=Hp(e,n);if(!o)return;let r=Ne(this.map,e);if(r&&r.id.client!==o.client)return;let i=this.spans[o.kind].get(o.client)??[];i.splice(fl(i,o.span.firstClock),0,o.span),this.spans[o.kind].set(o.client,i),this.byKey.set(e,{kind:o.kind,span:o.span});let s=hl(o.span);if(s!==null){let a=this.dependents.get(s)??new Set;a.add(o.span),this.dependents.set(s,a);}}remove(e){let n=this.byKey.get(e);if(!n)return;this.byKey.delete(e);let o=this.spans[n.kind].get(n.span.client);if(o){for(let i=fl(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=hl(n.span);r!==null&&this.dependents.get(r)?.delete(n.span);}find(e,n,o){let r=this.spans[e].get(n);if(!r)return null;let i=0,s=r.length-1,a=null;for(;i<=s;){let l=i+s>>1,d=r[l];d.firstClock<=o?(a=d,i=l+1):s=l-1;}return a&&o<a.firstClock+a.length?a:null}};function hl(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 qp(t,e){if(t.origin){let r=Math.max(e.from,t.origin.clock),i=Math.min(e.to,t.origin.clock+t.length);if(r>=i)return null;let s=t.firstClock-t.origin.clock;return {client:t.client,from:r+s,to:i+s}}let n=t.follow.identity,o=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 gl=new WeakMap;function ke(t){let e=gl.get(t);if(e)return e;let n=t.getMap(Kp),o=new pi(t,n);return t.on("beforeObserverCalls",r=>{let i=Ut(r,n);i&&o.refreshKeys(i);}),gl.set(t,o),e=o,e}function lt(t){return t.doc?ke(t.doc):Gp}function Rl(t,e,n){let o=[],r=0;for(let i of Mt(t)){let s=i.attributes??{},a=n?jr(s,n.limits,n.paragraphId):"";if(typeof i.insert=="string"){let l=bi(s);for(let d=0;d<i.insert.length;d+=1,r+=1){if(e?.has(r))continue;let c=`c${i.insert[d]}`;o.push({key:c,strong:`${c}\0${l}`,insert:i.insert[d],attributes:s,position:r,trail:a});}}else {if(r+=1,e?.has(r-1))continue;let l=i.insert,d=typeof l.n=="string"?`e${l.r===1?"r":""}${l.n}`:Cl(s,a);o.push({key:d,strong:d,insert:l,attributes:s,position:r-1,trail:a});}}return o}function Ol(t,e){let n=yn(t).items;for(let o=0;o<n.length;o+=1){let r=n[o];if(r.kind==="char"&&r.attributes.textValueId===e.textValueId)return o+e.utf16Start}}function yo(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=Ct(r.attributes,n,e);i={attributes:d,trail:jr(d,e,n)},o.set(r.attributes,i);}let{attributes:s,trail:a}=i;if(r.kind==="char"){let d=`c${r.value}`,c=`${d}\0${bi(s)}`;return {key:d,strong:c,insert:r.value,attributes:s,trail:a}}if(r.kind==="embed"){let d=Wr(r),c=`e${"r"in d?"r":""}${r.node.id}`;return {key:c,strong:c,insert:d,attributes:s,trail:a}}let l=Cl(s,a);return {key:l,strong:l,insert:{a:1},attributes:s,trail:a}})}var El=1<<20;function Cl(t,e){return `a${Se(Ur(t))}${e}`}function bi(t){return t.t??""}function Tl(t,e,n=true,o){let r=Il(t),i=Il(e);if(r===null&&i===null)return xl(t,e,n,o);let s=r?.starts??null,a=i?.starts??null,l=(c,u,f)=>{if(c===null)return [u];let p=c[u];return (u+1<c.length?c[u+1]:f)-p===2?[p,p+1]:[p]},d=[];for(let c of xl(r?.tokens??t,i?.tokens??e,n))if(c.op==="del")for(let u of l(s,c.before,t.length))d.push({op:"del",before:u});else if(c.op==="ins")for(let u of l(a,c.after,e.length))d.push({op:"ins",after:u});else {let u=l(s,c.before,t.length),f=l(a,c.after,e.length);u.forEach((p,h)=>d.push({op:"eq",before:p,after:f[h]}));}return d}var yl=t=>{if(t===void 0||typeof t.insert!="string")return false;let e=t.insert.charCodeAt(0);return e>=55296&&e<=56319},bl=t=>{if(t===void 0||typeof t.insert!="string")return false;let e=t.insert.charCodeAt(0);return e>=56320&&e<=57343};function Il(t){let e=false;for(let r=0;r+1<t.length&&!e;r+=1)e=yl(t[r])&&bl(t[r+1]);if(!e)return null;let n=[],o=[];for(let r=0;r<t.length;r+=1){let i=t[r],s=t[r+1];o.push(r);let a=s!==void 0&&(i.position===void 0||s.position===i.position+1);if(yl(i)&&bl(s)&&a){let l=`${i.insert}${s.insert}`,d=`c${l}`;n.push({...i,key:d,strong:`${d}\0${bi(i.attributes)}`,insert:l}),r+=1;}else n.push(i);}return {tokens:n,starts:o}}function xl(t,e,n,o){let r=n?Qp(t,e,o):null;if(r)return r;let i=yi(t,e,false),s=yi(t,e,true),a=mi(t,e,i),l=mi(t,e,s),[d,c]=[gi(a),gi(l)],u=c!==d?c>d?l:a:kl(l)<kl(a)?l:a,f=Math.max(d,c);if(f<Math.min(t.length,e.length)&&Zp(u,t,e)){let p=yi(t,e,false,false);for(let h of [i,s,p]){let g=mi(t,e,h,true),y=gi(g);y>f&&([u,f]=[g,y]);}}return oh(rh(u,e),t)}function Zp(t,e,n){let o=new Set;for(let r of t)r.op==="del"&&o.add(e[r.before].key);if(o.size===0)return false;for(let r of t)if(r.op==="ins"&&o.has(n[r.after].key))return true;return false}function Qp(t,e,n){let o=e.length-t.length;if(o<=0)return null;if(n!==void 0&&eh(t,e,n,o))return Sl(t.length,n,o);let r=0;for(;r<t.length&&t[r].strong===e[r].strong;)r+=1;let i=0;for(;i<t.length-r&&t[t.length-1-i].strong===e[e.length-1-i].strong;)i+=1;if(r+i!==t.length)return null;let s=e[r],a=e[r+o-1],l=r>0?t[r-1]:null;return l&&l.key===a.key&&l.strong!==a.strong||r<t.length&&t[r].key===s.key?null:Sl(t.length,r,o)}function eh(t,e,n,o){if(!Number.isSafeInteger(n)||n<0||n>t.length)return false;for(let r=0;r<n;r+=1)if(t[r].strong!==e[r].strong)return false;for(let r=n;r<t.length;r+=1)if(t[r].strong!==e[r+o].strong)return false;return true}function Sl(t,e,n){let o=[];for(let r=0;r<e;r+=1)o.push({op:"eq",before:r,after:r});for(let r=e;r<e+n;r+=1)o.push({op:"ins",after:r});for(let r=e;r<t;r+=1)o.push({op:"eq",before:r,after:r+n});return o}function th(t){if(!Le(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 nh=16;function oh(t,e){for(let n=0;n<nh;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 u=e[c.before];return !lh(u)&&d.has(u.trail??"")}),s=false,a=[];if(o.forEach((l,d)=>{let c=new Set(l.map(f=>f.op==="eq"?e[f.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(f=>f.op==="eq"&&th(e[f.before])))){for(let f of l)a.push(f);return}s=true;for(let f of l)f.op==="eq"&&a.push({op:"del",before:f.before});for(let f of l)f.op==="eq"&&a.push({op:"ins",after:f.after});}),t=a,!s)break}return t}function rh(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 kl(t){let e=0,n=false;for(let o of t)o.op!=="eq"&&!n&&(e+=1),n=o.op!=="eq";return e}function Le(t){return t.key.startsWith("c")}function ih(t,e,n,o,r,i){let s=e,a=r,l=0;for(;;){for(;s<n&&!Le(t[s]);)s+=1;for(;a<i&&!Le(o[a]);)a+=1;if(s===n||a===i)return s===n&&a===i&&l>0;if(t[s].key!==o[a].key)return false;l+=1,s+=1,a+=1;}}var sh=/"l":"del(Text|InstrText)"/,ah=/\\"l\\":\\"(del|moveFrom)\\"/;function lh(t){let e=t.attributes.t;return typeof e=="string"&&sh.test(e)?true:t.trail!==void 0&&ah.test(t.trail)}function gi(t){let e=0;for(let n of t)n.op==="eq"&&(e+=1);return e}function mi(t,e,n,o=false){let r=[],i=0,s=0;for(let[a,l]of [...n,[t.length,e.length]]){let d=wl(t,e,i,a,s,l,false),c=vl(d,t,e);if(c.inRevision<c.equal){let g=wl(t,e,i,a,s,l,true),y=vl(g,t,e);y.equal>=c.equal&&y.inRevision>c.inRevision&&(d=g);}for(let g of d.head)r.push(g);let u=d.tail;({i,j:s}=d);let{bEnd:f,aEnd:p}=d;if(ih(t,i,f,e,s,p))for(;i<f||s<p;)i<f&&s<p&&Le(t[i])&&Le(e[s])?(r.push({op:"eq",before:i,after:s}),i+=1,s+=1):i<f&&!Le(t[i])?(r.push({op:"del",before:i}),i+=1):(r.push({op:"ins",after:s}),s+=1);let h=o?dh(t,i,f,e,s,p):null;if(h){for(let g of h)r.push(g);i=f,s=p;}for(;i<f;i+=1)r.push({op:"del",before:i});for(;s<p;s+=1)r.push({op:"ins",after:s});for(let g of u)r.push(g);i=a,s=l,i<t.length&&s<e.length&&(r.push({op:"eq",before:i,after:s}),i+=1,s+=1);}return r}function dh(t,e,n,o,r,i){if(r===i||i-r>=n-e)return null;let s=null,a=()=>{if(s)return s;s=new Map;for(let c=e;c<n;c+=1){let{key:u}=t[c],f=t[c].trail??"",p=s.get(u);p||s.set(u,p=new Map);let h=p.get(f);h||p.set(f,h=[]),h.push(c);}return s},l=c=>{let u=[],f=e;for(let p=r;p<i;p+=1){let h=o[p],g=-1;if(c){let y=h.trail??"";for(let[I,k]of a().get(h.key)??[]){if(!En(I,y))continue;let m=ch(k,f);m>=0&&(g<0||m<g)&&(g=m);}}for(let y=f;g<0&&y<n;y+=1)t[y].key===h.key&&(g=y);if(g<0)return null;for(;f<g;f+=1)u.push({op:"del",before:f});u.push({op:"eq",before:g,after:p}),f=g+1;}for(;f<n;f+=1)u.push({op:"del",before:f});return u};return ((i-r)*(n-e)<=El?l(true):null)??l(false)}function ch(t,e){let n=0,o=t.length;for(;n<o;){let r=n+o>>1;t[r]<e?n=r+1:o=r;}return n<t.length?t[n]:-1}function wl(t,e,n,o,r,i,s){let a=[],l=[],d=()=>{for(;;)if(n<o&&r<i&&t[n].key===e[r].key)a.push({op:"eq",before:n,after:r}),n+=1,r+=1;else if(n<o&&r<i&&!Le(t[n])&&Le(e[r]))a.push({op:"del",before:n}),n+=1;else if(n<o&&r<i&&Le(t[n])&&!Le(e[r]))a.push({op:"ins",after:r}),r+=1;else break},c=()=>{for(;;)if(o>n&&i>r&&t[o-1].key===e[i-1].key)o-=1,i-=1,l.unshift({op:"eq",before:o,after:i});else if(o>n&&i>r&&!Le(t[o-1])&&Le(e[i-1]))o-=1,l.unshift({op:"del",before:o});else if(o>n&&i>r&&Le(t[o-1])&&!Le(e[i-1]))i-=1,l.unshift({op:"ins",after:i});else break};return s?(c(),d()):(d(),c()),{head:a,tail:l,i:n,j:r,bEnd:o,aEnd:i}}function vl(t,e,n){let o=0,r=0,i=null,s=null,a=false;for(let l of [t.head,t.tail])for(let d of l){if(d.op!=="eq")continue;o+=1;let c=e[d.before].trail??"",u=n[d.after].trail??"";if(c===u){r+=1;continue}(c!==i||u!==s)&&(a=En(c,u),i=c,s=u),a&&(r+=1);}return {equal:o,inRevision:r}}function En(t,e){if(t===e)return true;let n=mo.get(e);n===void 0&&(mo.size>=Ll&&mo.clear(),mo.set(e,n=new Map));let o=n.get(t);if(o!==void 0)return o;let r=new Set(JSON.parse(e||"[]").map(s=>JSON.stringify(s))),i=JSON.parse(t||"[]").every(s=>r.has(JSON.stringify(s)));return n.size>=Ll&&n.clear(),n.set(t,i),i}var Ll=1024,mo=new Map;function yi(t,e,n,o=true){let r=[],i=(f,p,h)=>t[p]?.strong===h.strong&&!En(t[f].trail??"",h.trail??"")&&En(t[p].trail??"",h.trail??""),s=0;for(;s<t.length&&s<e.length&&t[s].strong===e[s].strong&&!i(s,s+1,e[s]);)r.push([s,s]),s+=1;let a=t.length,l=e.length,d=[];for(;a>s&&l>s&&t[a-1].strong===e[l-1].strong&&!(a-2>=s&&i(a-1,a-2,e[l-1]));)a-=1,l-=1,d.unshift([a,l]);let c=a-s,u=l-s;if(o&&c>0&&u>0&&c*u<=El){let f=u+1,p=new Uint32Array((c+1)*f),h=new Array(c),g=new Array(u);for(let m=0;m<c;m+=1)h[m]=t[s+m].strong;for(let m=0;m<u;m+=1)g[m]=e[s+m].strong;let y=(m,S)=>h[m]===g[S];for(let m=c-1;m>=0;m-=1){let S=h[m],L=m*f,v=L+f;for(let b=u-1;b>=0;b-=1){let w=p[v+b],E=p[L+b+1];p[L+b]=S===g[b]?p[v+b+1]+1:w>E?w:E;}}let I=0,k=0;for(;I<c&&k<u;){let m=()=>p[(I+1)*f+k]!==p[I*f+k]||En(t[s+I].trail??"",e[s+k].trail??"");if(y(I,k))m()&&(r.push([s+I,s+k]),k+=1),I+=1;else {let S=p[(I+1)*f+k],L=p[I*f+k+1];S>L||S===L&&!n?I+=1:k+=1;}}}for(let f of d)r.push(f);return r}function Ml(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 xi=64;function Si(t,e,n){for(let o=0;o<hi;o+=1){let r=t.origin("move",e,n)??t.origin("restore",e,n);if(!r)break;let i=r.client,s=r.clock+n-r.firstClock;if(i===e&&s===n)break;e=i,n=s;}return [e,n]}function Pl(t,e){let n=we(e);return n?ki(t,n.client,n.clock):e}function ki(t,e,n){let[o,r]=Si(t,e,n);return `${o}:${r}`}function nt(t,e,n){return ki(lt(t),e.id.client,e.id.clock+n)}function Ii(t,e){return e===t.id.clock?t.origin:{client:t.id.client,clock:e-1}}function uh(t,e,n){let o=[],r=e.left;if(r&&e.origin&&!r.deleted&&!(r.content instanceof K.ContentFormat)&&r.id.client===e.origin.client&&r.id.clock+r.length-1===e.origin.clock)return {live:n(r,e.origin.clock),deleted:o};let i=e.origin;for(let s=0;i&&s<xi;s+=1){let a=q(t,i);if(!a)break;if(!a.deleted){if(a.content instanceof K.ContentFormat){i=Ii(a,i.clock);continue}return {live:n(a,i.clock),deleted:o}}let l=n(a,i.clock);l&&o.push(l),i=Ii(a,i.clock);}return {live:null,deleted:o}}function fh(t,e,n){let o=e.rightOrigin;for(let r=0;o&&r<xi;r+=1){let i=q(t,o);if(!i)return null;if(i.deleted||!(i.content instanceof K.ContentFormat))return n(i,o.clock);o=i.rightOrigin;}return null}function Al(t,e,n){return e.deleted||e.content instanceof K.ContentString?ki(t,e.id.client,n):null}function Ie(t,e){return t.moved[e]===true||t.restored[e]===true}function ph(t,e,n){let[o,r]=Si(e,n.id.client,n.id.clock),i=t.doc;return i&&q(i,{client:o,clock:r})?.parent===t?[o,r]:null}function hh(t,[e,n],o){return !o||o.identity===et||t.followStart(e,n)===n?o:{identity:`${e}:${n-1}`,before:false}}function gh(t,e,n){return e?e.identity===et||e.before?[]:[Pl(t,e.identity)]:[...n.deleted,...n.live===null?[]:[n.live]]}function tn(t){let e=ge(t),n=lt(t),o=[],r=[],i=[],s=[],a=[],l=[],d=[],c=[],u=t.doc?qe(t.doc):null,f=[],p=[],h=[],g=[],y=false,I=t.doc,k=(m,S)=>Al(n,m,S);for(let m=e;m;m=m.right){if(m.deleted||!m.countable)continue;let S=m.content instanceof K.ContentString,L=S||m.content instanceof K.ContentEmbed,v=P=>S&&n.origin("move",m.id.client,P)!==null,b=P=>S&&!v(P)&&n.origin("restore",m.id.client,P)!==null,w=b(m.id.clock),E=v(m.id.clock)||w,M=w?ph(t,n,m):null,j=L&&(!E||M!==null),_=M?n.follow(...M):null,z=L?M?hh(n,M,_):n.follow(m.id.client,m.id.clock):null,ee=z&&z.identity!==et?{...z,identity:Pl(n,z.identity)}:z,H=I?uh(I,m,k):{live:null,deleted:[]},ae=null;if(j&&ee&&(H.deleted.length>0||H.live===null)?ae=[ee]:j&&H.deleted.length>0&&(ae=H.deleted.map(P=>({identity:P,before:false}))),ae&&(y=true),L&&!E&&!z&&H.live===null&&I){let P=fh(I,m,k);P&&(ae=[...ae??[],{identity:P,before:true}]);}let $=E?gh(n,_,H):null;for(let P=0;P<m.length;P+=1){if(s.push(`${m.id.client}:${m.id.clock+P}`),a.push(P>0?`${m.id.client}:${m.id.clock+P-1}`:m.origin?`${m.origin.client}:${m.origin.clock}`:null),S){let[te,D]=Si(n,m.id.client,m.id.clock+P);o.push(`${te}:${D}`),r.push(te),i.push(D);}else o.push(null),r.push(-1),i.push(-1);l.push(v(m.id.clock+P)),d.push(b(m.id.clock+P)),c.push(S&&u!==null&&u.isDeleted(r[r.length-1],i[i.length-1])),p.push(P===0),h.push(P===0?H.live:null),g.push(P===0?$:null),f.push(P===0?ae:null);}}return {ids:o,clients:r,clocks:i,items:s,origins:a,moved:l,restored:d,deleted:c,anchors:f,hasAnchors:y,starts:p,lefts:h,copiedAfter:g}}function wi(t,e,n){let o=t.doc;if(!o)return false;let r=lt(t),i=e.origin;for(let s=0;i&&s<xi;s+=1){let a=q(o,i);if(!a)return false;let l=Al(r,a,i.clock);if(l!==null&&n(l))return true;i=Ii(a,i.clock);}return false}var dt="splitPoints",mh=/^\d{1,16}:\d{1,16}$/,yh=/^\d{1,16}:\d{1,16}\+?$/;function bh(t){if(!t)return null;let e=null;for(let n=ge(t);n;n=n.right)!n.deleted&&typeof n.content.str=="string"&&(e=n);return e?nt(t,e,e.length-1):null}function Nl(t,e){if(!t||!e)return bh(t);let{ids:n}=e.identities;for(let o=n.length-1;o>=0;o-=1)if(!e.hidden.has(o)&&n[o])return n[o];return null}function Yl(t){let e=t?.get(dt);return typeof e=="string"&&e.length<=4096?e.split(`
|
|
6
|
+
`):null}function Tn(t){let e=Yl(t)?.[0],n=e?/^#(\d{1,16}):(\d{1,16})$/.exec(e):null;return n?K.createID(Number(n[1]),Number(n[2])):null}function ct(t){let e=Yl(t);if(!e)return [];let n=[];for(let o of e.filter(r=>!r.startsWith("#")).slice(-4)){let r=o.lastIndexOf("@"),i=o.slice(r+1);if(r<=0||!yh.test(i))return [];n.push({source:o.slice(0,r),at:i});}return n}function xo(t,e){return [`#${e}`,...t.slice(-4).map(n=>`${n.source}@${n.at}`)].join(`
|
|
7
|
+
`)}function Ih(t,e,n){let o=0,r=t._start;for(;r;r=r.right)if(!(r.deleted||!r.countable)){if(r===e){let i=r.content.getContent().indexOf(n);return i<0?-1:o+i}o+=r.length;}return -1}var Cn=new WeakSet,Io=new WeakMap,_l=(t,e)=>{let n=t.content.getContent().indexOf(e);return n<0?null:`${t.id.client}:${t.id.clock+n}`};function Bl(t){t&&Cn.add(t);}function Ul(){Cn=new WeakSet,Io=new WeakMap;}function Fl(t,e,n,o,r,i=()=>false){if(!n)return;let s=null;for(let a of o){let l=t(a);if(!l)continue;let d=null,c=null;for(let y of r)if(!y.deleted&&(d=_l(y,a))){c=y;break}if(!d||!c)continue;let u=Cn.has(l)&&!Io.has(l);if(u&&Io.set(l,d),u&&l.has(dt)){Cn.delete(l);continue}s??=n.toArray();let f=Ih(n,c,a),p=f>0?s[f-1]:void 0;if(!u&&(p===void 0||!i(p)))continue;let h=ct(p===void 0?void 0:t(p)),g=u&&p!==void 0?e(p):null;g&&(h=[...h,{source:p,at:`${g}+`}]),h.length>0&&l.set(dt,xo(h,d));}}function jl(t,e,n,o,r){if(!e||o<=0)return;let i=[],s=new Set,a=0,l=e._start;for(;l&&a<n+o;l=l.right){if(l.deleted||!l.countable)continue;let u=Math.max(n-a,0),f=Math.min(n+o-a,l.length);for(let p=u;p<f;p+=1)i.push({item:l,at:p});u===0&&f===l.length&&s.add(l),a+=l.length;}let d=(u,f)=>u.content.getContent()[f],c=(u,f)=>!i.some(p=>p.item===u&&p.at===f);for(let{item:u,at:f}of i){let p=d(u,f);if(!r(p))continue;let h=ct(t(p));if(h.length===0)continue;let g=u,y=f+1;for(;y<u.length&&!c(u,y);)y+=1;if(y>=u.length){let v=[u];for(g=u.right;g;g=g.right)if(!(g.deleted&&!v.some(b=>bo(g.origin,b)))){if(!v.some(b=>bo(g.origin,b))){g=null;break}if(!g.deleted&&!s.has(g))break;v.push(g);}if(!g)continue;for(y=0;y<g.length&&!c(g,y);)y+=1;if(y>=g.length)continue}let I=d(g,y),k=t(I),m=k?`${g.id.client}:${g.id.clock+y}`:null;if(!k||!m)continue;let S=Tn(k),L=S&&bo(S,g)?ct(k):[];L.some(v=>v.source===h.at(-1).source)||k.set(dt,xo([...h,...L],m));}}function zl(t,e,n){for(let o of rt(t,n))if(!(o.deleted||!(o.parent instanceof K.Array))&&o.content instanceof K.ContentAny)for(let r of o.content.getContent()){if(typeof r!="string")continue;let i=r,s=e(i),a=Tn(s);if(!s||!a||bo(a,o))continue;let l=q(t,a);for(let c=0;l&&l!==o&&l.redone&&c<64;c+=1)l=q(t,l.redone);let d=l===o?_l(o,i):null;d&&s.set(dt,xo(ct(s),d));}}function bo(t,e){return t!==null&&t.client===e.id.client&&t.clock>=e.id.clock&&t.clock<e.id.clock+e.length}function vi(t,e){for(let n=t.length-1;n>=0;n-=1)if(t[n].source===e)return t[n].at;return null}function $l(t){for(let e of t){if(e.before.length>0)continue;let n=e.after.find(o=>o.attributes[at])?.attributes[at];if(n&&mh.test(n))for(let o of t){if(o===e||!o.identities.includes(n))continue;let r=ct(o.record),i=Io.get(e.record);if(!i||!Cn.delete(e.record))break;e.record.set(dt,xo([...r,{source:o.id,at:n}],i));break}}}function xh(t){for(let e of Object.keys(t))if(e.startsWith(de)&&t[e]===null)return true;return false}function Wl(t,e,n,o,r){let i=new Array(e.length).fill(null),s=false;for(let l of o){if(l.op==="del"&&(i[l.before]="del"),l.op!=="eq")continue;let d=r(e[l.before].attributes,n[l.after].attributes);!d||!xh(d)||(i[l.before]=d,s=true);}if(!s)return;let a=0;for(;a<i.length;){if(i[a]!=="del"){a+=1;continue}let l=a;for(;l<i.length&&i[l]==="del";)l+=1;let d=a>0?i[a-1]:null,c=l<i.length?i[l]:null,u=d&&d!=="del"?d:c&&c!=="del"?c:null;if(u){let f={...Tt(u)};for(let h=a;h<l;h+=1)for(let g of Object.keys(e[h].attributes))(g.startsWith(de)||g===be)&&(f[g]=null);let p=a;for(let h=a+1;h<=l;h+=1){if(h<l&&e[h].position===e[h-1].position+1)continue;let g=e[p].position;t.format(g,e[h-1].position-g+1,f),p=h;}}a=l;}}function Oi(t){let e=[],n=null;return t.ids.forEach((o,r)=>{if(o===null||t.deleted[r])return;let i=t.clients[r],s=t.clocks[r],a=t.moved[r]?"move":t.restored[r]?"restore":"original";if(n&&n.client===i&&n.end===s&&n.kind===a){n.end+=1;return}n&&e.push(n),n={client:i,start:s,end:s+1,kind:a};}),n&&e.push(n),e}var Li=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}},Ri=class{classes=new Map;add(e){let n=Kl(e.run.end-e.run.start),o=this.classes.get(n);o||this.classes.set(n,o=new Li(2**(n+1))),o.add(e);}remove(e){let n=Kl(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 Kl(t){return t<=1?0:31-Math.clz32(t)}var Mn=class{runsOf=new Map;tables={original:new Map,move:new Map,restore:new Map};update(e,n){let o=this.runsOf.get(e)??[],r=u=>`${u.client}:${u.start}:${u.end}:${u.kind}`,i=u=>{let f=new Map;for(let p of u){let h=f.get(r(p));h?h.push(p):f.set(r(p),[p]);}return f},s=i(o),a=i(n),l=new Set,d=[],c=u=>{for(let f of Object.values(this.tables))for(let p of f.get(u.client)?.overlapping(u.start,u.end)??[])p.paragraph!==e&&l.add(p.paragraph);};for(let[u,f]of s)for(let p of f.slice(a.get(u)?.length??0))this.tables[p.kind].get(p.client)?.remove({run:p,paragraph:e}),d.push(p),p.kind!=="original"&&c(p);for(let[u,f]of a)for(let p of f.slice(s.get(u)?.length??0)){let h=this.tables[p.kind],g=h.get(p.client);g||(g=new Ri,h.set(p.client,g)),g.add({run:p,paragraph:e}),d.push(p),p.kind!=="original"&&c(p);}return n.length>0?this.runsOf.set(e,[...n]):this.runsOf.delete(e),{affected:l,changed:d}}overlapping(e,n,o,r){return this.tables[e].get(n)?.overlapping(o,r)??[]}hasCopies(e){return this.tables.move.has(e)||this.tables.restore.has(e)}holdersOf(e,n,o){return (this.tables[e].get(n)?.overlapping(o,o+1)??[]).map(r=>r.paragraph)}holders(e,n){return ["original","move","restore"].flatMap(o=>this.holdersOf(o,e,n))}contested(){let e=new Set,n=[];for(let[o,r]of this.runsOf)for(let i of r){if(i.kind==="original")continue;let s=false;for(let a of ["move","restore"])for(let l of this.overlapping(a,i.client,i.start,i.end))l.paragraph!==o&&(s=true,e.add(o),e.add(l.paragraph));s&&n.push(i);}return {paragraphs:e,runs:n}}clear(){this.runsOf.clear();for(let e of Object.values(this.tables))e.clear();}};var Vl=4096;function Jl(t,e){let n=we(e),o=n?q(t,n):null,r=o?.parent;if(!o||!(r instanceof K.Text))return null;for(let i=r._item;i;i=i.parent instanceof K.AbstractType?i.parent._item:null)if(i.deleted)return null;return {item:o,text:r}}function Sh(t){let e=new Map,n=0;for(let o=ge(t);o;o=o.right)for(let r=0;r<o.length;r+=1,n+=1){let i=nt(t,o,r);e.has(i)||e.set(i,n);}return e}function kh(t,e){let n=lt(t);for(let o=ge(t);o;o=o.right)for(let r=0;r<o.length;r+=1){if(!n.origin("move",o.id.client,o.id.clock+r))continue;let i=e.get(nt(t,o,r));if(i!==void 0)return i}return null}var So=class{constructor(e,n){this.textOf=e;this.order=n;}textOf;order;places=new Map;keys=new Map;sourceSegments(e,n,o,r){let i=this.textOf(e)?.doc,s=[],a=o+r;for(let l=o;l<a;){let d=null;try{d=i&&l<K.getState(i.store,n)?K.getItem(i.store,K.createID(n,l)):null;}catch{d=null;}let c=d?Math.min(a,d.id.clock+d.length):a,u=d&&i?Jl(i,`${n}:${l}`)?.text??null:null,f=s.at(-1);f&&f.source===u?f.end=c-o:s.push({start:l-o,end:c-o,source:u}),l=Math.max(c,l+1);}return s}sourceOf(e,n){let o=this.textOf(e)?.doc;return (o&&Jl(o,n)?.text)??null}compare(e,n,o){if(e===n)return 0;if(o){let r=this.keyOf(e,o),i=this.keyOf(n,o);if(r!==i)return r===null?-1:i===null?1:r-i}return this.order(e,n)}lastOf(e,n,o){let r=o&&e.length>1?this.sourceOf(e[0],n):null,i=null;for(let s of e)(i===null||this.compare(s,i,r)>0)&&(i=s);return i}forget(e){this.keys.delete(e);let n=this.textOf(e);n&&this.places.delete(n);}clear(){this.keys.clear(),this.places.clear();}keyOf(e,n){let o=this.places.get(n);o||(this.places.size>=Vl&&this.places.clear(),o=Sh(n),this.places.set(n,o));let r=this.keys.get(e),i=r?.get(n);if(i&&i.places===o)return i.key;let s=this.textOf(e),a=s?kh(s,o):null;return r||(this.keys.size>=Vl&&this.keys.clear(),r=new Map,this.keys.set(e,r)),r.set(n,{places:o,key:a}),a}};var Xl=new Set,wh=64;function Hl(t){let e=new Set;return t.ids.forEach((n,o)=>{n!==null&&Ie(t,o)&&e.add(n);}),e}function vh(t){let e=Oi(t).map(o=>({...o,kind:"original"})),n=o=>{let r=we(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 Ei(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 Lh(t,e,n,o){if(o.size===0)return [];let{ids:r}=e,i=new Set;r.forEach((l,d)=>{l!==null&&!n.has(d)&&i.add(l);});let s=[];for(let l=1;l<r.length;l+=1){let d=r[l-1];if(n.has(l)||!o.has(l-1)||!d||!i.has(d))continue;let c=[];for(let u=l;u<r.length&&!n.has(u);u+=1)c.push(u);s.push({source:t,after:d,before:false,positions:c,identities:c.map(u=>r[u]??null),items:c.map(u=>e.items[u])}),l+=c.length;}let a=new Set;for(let l of s)for(let d of l.positions)a.add(d);for(let l=0;l<r.length;l+=1){if(!e.starts[l]||n.has(l)||a.has(l))continue;let d=e.anchors[l]?.find(f=>f.before);if(!d||!i.has(d.identity))continue;let c=l+1;for(;c<r.length&&!e.starts[c]&&!n.has(c);)c+=1;if(c>=r.length||!o.has(c)||r[c]!==d.identity)continue;let u=[];for(let f=l;f<c;f+=1)u.push(f);for(let f of u)a.add(f);s.push({source:t,after:d.identity,before:true,positions:u,identities:u.map(f=>r[f]??null),items:u.map(f=>e.items[f])});}for(let l of s)for(let d of l.positions)n.add(d);return s}var ko=class{constructor(e,n,o,r,i,s=()=>null){this.textOf=e;this.isDeleted=n;this.viewsChanged=r;this.originalParagraph=i;this.undoneInto=s;this.holders=new So(e,o);}textOf;isDeleted;viewsChanged;originalParagraph;undoneInto;index=new Mn;sources=new Set;outgoingOf=new Map;incomingOf=new Map;targetsOf=new Map;followingCopiesOf=new Map;followingCopies=new Map;dependencies=new Mn;pending=new Set;ownChanges=new Set;readsOtherSources=new Set;followingIdsOf=new Map;joinedFrom=new Map;typedAnchored=new Map;typedOf=new Map;typedStale=new Set;typedBuilt=false;identities=new Map;recent=new Set;holders;paragraphChanged(e){let n=this.textOf(e),o=this.isDeleted(e);this.invalidate(e);let r=n?this.identitiesOf(e,n):null,{affected:i,changed:s}=this.index.update(e,r&&!o?Oi(r):[]),a=this.sources.has(e),l=!!n&&!!r&&(o?n.length>0:r.hasAnchors);l?this.sources.add(e):this.sources.delete(e),this.identities.has(e)&&this.touch(e);for(let d of s)for(let c of this.dependencies.overlapping("original",d.client,d.start,d.end))this.pending.add(c.paragraph);(a||l)&&(this.pending.add(e),this.ownChanges.add(e));for(let d of this.joinedFrom.get(e)??[])this.pending.add(d);for(let d of this.targetsOf.get(e)??[])i.add(d);return i.delete(e),i}settle(){if(this.pending.size===0)return;for(let r of this.readsOtherSources)this.sources.has(r)&&this.pending.add(r);this.readsOtherSources.clear();let e=[...this.pending],n=[...this.ownChanges];this.pending.clear(),this.ownChanges.clear();let o=this.relocate(e);for(let r of n)for(let i of this.targetsOf.get(r)??[])o.add(i);o.size>0&&this.viewsChanged(o);}shown(e,n){this.settle();let o=this.identitiesOf(e,n),r=new Set,i=new Set,s=new Set,{clients:a,clocks:l}=o,d=Hl(o);for(let p=0;p<a.length;){let h=p+1;for(;h<a.length&&a[h]===a[p]&&l[h]===l[h-1]+1&&o.moved[h]===o.moved[p]&&o.restored[h]===o.restored[p];)h+=1;let g=a[p],y=Ie(o,p);if(g>=0){let I=S=>this.index.overlapping(S,g,l[p],l[h-1]+1).filter(L=>L.paragraph!==e),k=I("move"),m=I("restore");if(k.length>0||m.length>0||y){let S=l[p],L=y?e:null,v=this.coverage("move",k,g,S,h-p,L),b=this.coverage("restore",m,g,S,h-p,L);for(let w=p;w<h;w+=1){let E=w-p,M={move:v.any[E]>0,laterMove:v.later[E]>0,restore:b.any[E]>0,laterRestore:b.later[E]>0};this.hides(o,w,M,i,s)&&r.add(w);}}if(!y&&d.size>0)for(let S=p;S<h;S+=1)d.has(o.ids[S])&&r.add(S);}p=h;}let c=this.outgoingOf.get(e);if(c)for(let p of Ei(c,o))r.add(p);this.followingCopies.size>0&&o.ids.forEach((p,h)=>{p===null||Ie(o,h)||this.followingCopies.has(p)&&r.add(h);}),o.deleted.forEach((p,h)=>{p&&r.add(h);});let u=Lh(e,o,r,s),f=this.distinctIncoming(e,o,r);return {identities:o,hidden:r,incoming:u.length>0?[...f,...u]:f}}distinctIncoming(e,n,o){let r=this.incomingOf.get(e)??[];if(r.length===0)return r;let i=new Set;n.ids.forEach((a,l)=>{a!==null&&!o.has(l)&&i.add(a);});let s=[];for(let a of r){let l=a.positions.flatMap((d,c)=>{let u=a.identities[c]??null;return u!==null&&i.has(u)?[]:(u!==null&&i.add(u),[c])});l.length===a.positions.length?s.push(a):l.length>0&&s.push({...a,positions:l.map(d=>a.positions[d]),identities:l.map(d=>a.identities[d]??null),items:l.map(d=>a.items[d])});}return s}hides(e,n,o,r,i){let s=e.ids[n],a=false;return Ie(e,n)&&r.has(s)&&i.add(n),e.moved[n]?a=r.has(s)||o.laterMove:e.restored[n]?a=r.has(s)||o.move||o.laterRestore:a=o.move||o.restore,Ie(e,n)&&r.add(s),a}coverage(e,n,o,r,i,s){let a=new Int32Array(i+1),l=new Int32Array(i+1),d=s!==null&&e==="move"&&n.length>0?this.holders.sourceSegments(s,o,r,i):[{start:0,end:i,source:null}];for(let c of n){let u=Math.max(c.run.start,r)-r,f=Math.min(c.run.end,r+i)-r;if(!(u>=f)&&(a[u]+=1,a[f]-=1,s!==null))for(let p of d){let h=Math.max(u,p.start),g=Math.min(f,p.end);h>=g||this.holders.compare(c.paragraph,s,p.source)>0&&(l[h]+=1,l[g]-=1);}}for(let c=1;c<=i;c+=1)a[c]+=a[c-1],l[c]+=l[c-1];return {any:a,later:l}}holdersOf(e){let n=we(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=we(e);if(!n)return null;let{client:o,clock:r}=n;return this.index.hasCopies(o)?this.holders.lastOf(this.index.holdersOf("move",o,r),e,true)??this.holders.lastOf(this.index.holdersOf("restore",o,r),e,false):null}orderChanged(){let{paragraphs:e,runs:n}=this.index.contested();for(let o of n)for(let r of this.dependencies.overlapping("original",o.client,o.start,o.end))this.pending.add(r.paragraph);return e}targetsFor(e){return this.settle(),this.targetsOf.get(e)??Xl}placedTargetsFor(e){return this.targetsOf.get(e)??Xl}invalidate(e){this.identities.delete(e),this.holders.forget(e),this.recent.delete(e),this.typedStale.add(e);}identitiesOf(e,n){let o=this.identities.get(e);if(o?.text===n)return this.touch(e),o.identities;let r=tn(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<=wh))return;let n=this.recent.values().next().value;this.recent.delete(n),this.identities.delete(n);}clear(){this.identities.clear(),this.holders.clear(),this.recent.clear(),this.index.clear(),this.sources.clear(),this.outgoingOf.clear(),this.incomingOf.clear(),this.targetsOf.clear(),this.followingCopiesOf.clear(),this.followingCopies.clear(),this.dependencies.clear(),this.pending.clear(),this.ownChanges.clear(),this.joinedFrom.clear(),this.typedAnchored.clear(),this.typedOf.clear(),this.typedStale.clear(),this.typedBuilt=false;}relocate(e){this.followingIdsOf.clear();let n=new Set;for(let d of e)for(let c of this.targetsOf.get(d)??[])n.add(c);let o=new Map;for(let d of n)o.set(d,JSON.stringify(this.incomingOf.get(d)??[]));let r=new Map;for(let d of e)r.set(d,JSON.stringify(this.outgoingOf.get(d)?.positions??[]));let i=new Set(e);for(let d of n){let c=(this.incomingOf.get(d)??[]).filter(u=>!i.has(u.source));c.length>0?this.incomingOf.set(d,c):this.incomingOf.delete(d);}let s=new Map,a=d=>{s.has(d)||s.set(d,this.followingCopies.has(d));};for(let d of e){this.targetsOf.delete(d),this.outgoingOf.delete(d);for(let p of this.followingCopiesOf.get(d)??[])a(p),this.countFollowingCopy(p,-1);this.followingCopiesOf.delete(d);let c=this.sources.has(d)?this.textOf(d):null,u=c?this.identitiesOf(d,c):null;if(this.dependencies.update(d,u?vh(u):[]),!u)continue;let f=new Map;for(let p of this.followingOf(d,u)){let h=p.target??this.shownCopy(p.after),g=this.incomingOf.get(h)??[];g.push(p),this.incomingOf.set(h,g);let y=this.targetsOf.get(d)??new Set;y.add(h),this.targetsOf.set(d,y),p.positions.forEach((I,k)=>{let m=p.identities[k]??null;if(f.set(I,m),m===null||!Ie(u,I))return;let S=this.followingCopiesOf.get(d)??new Set;S.has(m)||(S.add(m),this.followingCopiesOf.set(d,S),a(m),this.countFollowingCopy(m,1));}),o.has(h)||o.set(h,"[]");}if(f.size>0&&!this.isDeleted(d)){let p=[...f.keys()].sort((h,g)=>h-g);this.outgoingOf.set(d,{positions:p,identities:p.map(h=>f.get(h)??null),items:p.map(h=>u.items[h])});}}for(let d of o.keys())this.incomingOf.get(d)?.sort((c,u)=>(c.source<u.source?-1:c.source>u.source?1:0)||c.positions[0]-u.positions[0]);let l=new Set;for(let[d,c]of r)JSON.stringify(this.outgoingOf.get(d)?.positions??[])!==c&&l.add(d);for(let[d,c]of o)JSON.stringify(this.incomingOf.get(d)??[])!==c&&l.add(d);for(let[d,c]of s)if(c!==this.followingCopies.has(d))for(let u of this.holdersOf(d))l.add(u);return l}countFollowingCopy(e,n){let o=(this.followingCopies.get(e)??0)+n;o>0?this.followingCopies.set(e,o):this.followingCopies.delete(e);}followingOf(e,n){let o=[],r=null,i=Hl(n),s=null,a=l=>(s||(s=new Set,n.ids.forEach((d,c)=>{d&&n.moved[c]&&!n.restored[c]&&s.add(d);})),s.has(l));for(let l=0;l<n.ids.length;l+=1){let d=n.ids[l]??null,c=Ie(n,l),u=d===null?null:this.shownCopy(d),f=u!==null&&!(u===e&&n.restored[l]&&!a(d));if(n.deleted[l]||d!==null&&(f||!c&&i.has(d))){r=null;continue}let p=!this.isDeleted(e),h=r!==null&&(!n.starts[l]||l>0&&n.lefts[l]===n.ids[l-1]),g=n.anchors[l]?.find(y=>this.leadsOut(e,p,y))??(p||h?void 0:this.movedAfter(e,n,l));if(g){r={source:e,after:g.identity,before:g.before,...g.target?{target:g.target}:{},...g.atStart?{atStart:true}:{},positions:[l],identities:[d],items:[n.items[l]]},o.push(r);continue}if(r&&h){r.positions.push(l),r.identities.push(d),r.items.push(n.items[l]);continue}r=null;}return o}typedSources(){if(!this.typedBuilt){this.typedBuilt=true;for(let e of this.sources)this.typedStale.add(e);}for(let e of this.typedStale)this.readTyped(e);return this.typedStale.clear(),this.typedAnchored}readTyped(e){for(let s of this.typedOf.get(e)??[]){let a=(this.typedAnchored.get(s)??[]).filter(l=>l.source!==e);a.length>0?this.typedAnchored.set(s,a):this.typedAnchored.delete(s);}this.typedOf.delete(e);let n=this.sources.has(e)?this.textOf(e):null;if(!n)return;let o=this.identitiesOf(e,n),r=new Set,i=null;o.ids.forEach((s,a)=>{if(o.starts[a]&&(i=o.anchors[a]??null),!s||Ie(o,a)||!i)return;let l=this.typedAnchored.get(s)??[];l.push({source:e,anchors:i}),this.typedAnchored.set(s,l),r.add(s);}),r.size>0&&this.typedOf.set(e,[...r]);}follows(e){let n=!this.isDeleted(e.source);return e.anchors.some(o=>this.leadsOut(e.source,n,o))}followsOutOf(e,n){if(this.isDeleted(e)||!this.sources.has(e))return false;let o=this.followingIdsOf.get(e);if(!o){let r=this.textOf(e),i=new Set;if(r)for(let s of this.followingOf(e,this.identitiesOf(e,r)))for(let a of s.identities)a&&i.add(a);o=i,this.followingIdsOf.set(e,o);}return o.has(n)}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)return;let i=this.holdersOf(r);if(!Ie(n,o)&&i.length>0||(this.readsOtherSources.add(e),(this.typedSources().get(r)??[]).some(d=>d.source!==e&&this.follows(d)))||i.some(d=>d!==e&&this.followsOutOf(d,r)))return;for(let d of n.copiedAfter[o]??[]){let c=this.shownCopy(d);if(c!==null&&c!==e)return {identity:d,before:false}}if(n.moved[o]){let d=this.originalParagraph(r);if(d!==null&&d!==e&&!this.isDeleted(d))return {identity:r,before:false,target:d}}let a=this.undoneInto(e);if(a===null||a.paragraph===e)return;let l=this.joinedFrom.get(a.paragraph)??new Set;if(l.add(e),this.joinedFrom.set(a.paragraph,l),!this.isDeleted(a.paragraph))return {identity:r,before:false,target:a.paragraph,...a.atStart?{atStart:true}:{}}}};function Rh(t,e){let n=[],o=0;for(let r of e){let i=r.op==="eq"?"eq":"change",s=n[n.length-1];s&&s.kind===i?s.steps.push(r):n.push({kind:i,steps:[r],after:o}),r.op==="eq"&&(o=t[r.before].position+1);}return n}function Oh(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 Ci(t,e){if(!t)return null;if(e>0){let o=t.ids[e-1];return o&&Ie(t,e-1)?o:null}let n=t.ids[0];return n&&Ie(t,0)?`^${n}`:null}function Ti(t,e,n,o,r,i){let s=Bt(t,e,n,o);!r||!s||!wi(t,s,i)||ke(t.doc).markFollow(s.id.client,s.id.clock,n.length,Gl(r,e));}function Gl(t,e){return e>0?t.ids[e-1]??et:t.ids[0]?`^${t.ids[0]}`:et}function Eh(t,e,n,o,r,i){let s=Bt(t,e,n,o);if(!s)return;let a=r??(i&&wi(t,s,i.hasShownCopy)?Gl(i.identities,e):null);a&&ke(t.doc).markFollow(s.id.client,s.id.clock,1,a);}function Mi(t,e,n,o,r){let i=Bt(t,e,n,o);i&&ke(t.doc).markFollow(i.id.client,i.id.clock,n.length,r);}function ql(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 Ch(t,e,n,o,r,i,s){let a=Rh(e,o),l=null,d=f=>f<=0?{}:(l??=ql(t),l[f-1]??{}),c=new Map,u=(f,p)=>{let h=c.get(f);h||c.set(f,h=new Map);let g=h.get(p);if(g===void 0){let y=Ml(f,s(f,p,false));g=y&&{changes:y,key:JSON.stringify(y),from:Se(f)},h.set(p,g);}return g};Wl(t,e,n,o,(f,p)=>u(f,p)?.changes??null);for(let f=a.length-1;f>=0;f-=1){let p=a[f];if(p.kind==="eq"){let L=[];for(let b of p.steps){let w=u(e[b.before].attributes,n[b.after].attributes);w&&L.push({...w,position:e[b.before].position});}let v=[];for(let b of L){let w=v[v.length-1],E=w?.[w.length-1];E&&E.position+1===b.position&&E.from===b.from&&E.key===b.key?w.push(b):v.push([b]);}for(let b=v.length-1;b>=0;b-=1){let w=v[b],E=r?Na(w[0].changes,w.map(({position:M})=>{let[j,_]=(r.items[M]??"-1:-1").split(":");return {client:Number(j),clock:Number(_)}})):w[0].changes;Ea(t,E,r?.items,w);}continue}let h=p.steps.filter(L=>L.op==="del").map(L=>e[L.before].position),g=p.steps.filter(L=>L.op==="ins").map(L=>n[L.after]),y=h.length>0?h[0]:p.after,I=Ci(r,y),k=0,m=d(y);for(let L of Oh(g,v=>typeof v.insert=="string"?`c${Se(v.attributes)}`:`e${k++}`)){let v={...L[0],attributes:Tt(s(m,L[0].attributes,true))};if(m=v.attributes,typeof v.insert!="string"){let E=r&&y===(h.length>0?h[0]:p.after)?{identities:r,hasShownCopy:i}:null;Eh(t,y,v.insert,v.attributes,I,E),I=null,y+=1;continue}let b=L.map(E=>E.insert).join(""),w=v.attributes[at];w?fi(t,y,b,v.attributes,w):I?Mi(t,y,b,v.attributes,I):y===(h.length>0?h[0]:p.after)?Ti(t,y,b,v.attributes,r,i):t.insert(y,b,{...v.attributes}),I=null,y+=b.length;}let S=y-(h.length>0?h[0]:p.after);for(let L=h.length-1;L>=0;){let v=L;for(;v>0&&h[v-1]+1===h[v];)v-=1;xs(t,h[v]+S,L-v+1),L=v-1;}}}function Th(t,e,n){let r=t.inline.viewOf(e).shown(n);if(r.incoming.length===0)return [];let{ids:i}=r.identities,s=so(r),a=new Map(r.incoming.map((m,S)=>[m,S])),l=[];for(let[m,S]of s.atPosition)for(let L of [...S.before,...S.after])l.push({following:L,order:a.get(L),at:m});for(let m of s.atEnd)l.push({following:m,order:a.get(m),at:i.length,atEnd:true});for(let m of s.atStart)l.push({following:m,order:a.get(m),at:-1,atEnd:true});let d=(m,S)=>S.at-m.at||(m.atEnd?0:Number(m.following.before))-(S.atEnd?0:Number(S.following.before))||S.order-m.order;l.sort(d);let c=new Set,u=new Set,f=[],p=m=>m-f.filter(S=>S<m).length,h=new Map,g=(m,S)=>{let L=h.get(m);return L||(L={identities:tn(S),delta:Mt(S)},h.set(m,L)),L},y=(m,S)=>{let L=new Map,v=t.inline.textOf(m.source);if(!v)return {positions:[],landed:L};let{identities:b,delta:w}=g(m.source,v),E=Ei(m,b),M=b.ids,j=new Set(E),_=[],z=0;for(let $ of w){let P=typeof $.insert=="string"?$.insert.length:1,te=null,D=()=>te??=Ct(Ae($.attributes,t.limits,m.source),e,t.limits);if(typeof $.insert=="string")for(let T=0;T<P;T+=1)j.has(z+T)&&_.push({kind:"char",value:$.insert[T],attributes:{...D()},identity:M[z+T]??null,position:z+T});else if(j.has(z)&&$.insert!==null&&typeof $.insert=="object"){let T=ks(v,z);T&&_.push({kind:"embed",embed:$.insert,attributes:{...D()},item:T,position:z});}z+=P;}let ee=[];for(let $ of _){let P=ee[ee.length-1],te=P?.[P.length-1];$.kind==="char"&&te?.kind==="char"&&Se(te.attributes)===Se($.attributes)&&Ft(te.identity,$.identity)?P.push($):ee.push([$]);}let H=S,ae=($,P)=>Tt(Fr($>0?ql(n)[$-1]??{}:{},P,true,t.limits,e));for(let $ of ee){let P=$[0];if(P.kind==="embed"){let T=v===n?ws(n,P.item):null;vs(v,P.item),h.delete(m.source),u.add(m.source),T!==null&&(f.push(T),T<H&&(H-=1)),n.insertEmbed(H,P.embed,{...ae(H,P.attributes)}),L.set(P.position,H),H+=1;continue}let te=$.map(T=>T.kind==="char"?T.value:"").join(""),D=ae(H,P.attributes);P.identity?fi(n,H,te,D,P.identity):n.insert(H,te,D),$.forEach((T,V)=>L.set(T.position,H+V)),H+=te.length;}return h.delete(e),c.add(m.source),{positions:E,landed:L}},I=[],k=(m,S)=>{let L=s.inside.get(m);if(!L)return;let v=[];for(let[b,w]of L){let E=S.positions[b],M=E===void 0?void 0:S.landed.get(E);for(let j of [...w.before,...w.after])M===void 0?I.push(j):v.push({following:j,order:a.get(j),at:M});}v.sort(d);for(let b of v){let w=b.following.before?b.at:b.at+1;k(b.following,y(b.following,w));}};for(let m of l){let S=m.atEnd?Math.max(m.at,0):m.following.before?m.at:m.at+1;k(m.following,y(m.following,p(S)));}for(let m of I)k(m,y(m,n.length));for(let m of u)t.inline.follow.invalidate(m);return t.inline.follow.invalidate(e),t.inline.noteDrift(),[...c]}function Pi(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 Mh(t){let e=new Set;for(let o of t)for(let r of Pi(o))e.add(r);if(e.size===0)return [];let n=[];for(let o of t){if(!o.text||o.hidden.size===0)continue;let r=[...o.hidden].filter(s=>{let a=o.identities[s];return a!=null&&e.has(a)});if(r.length===0)continue;let i=o.shownIdentities;n.push({write:o,ids:mr(o.text,r),originals:r.map(s=>i&&!i.moved[s]&&!i.restored[s]?o.identities[s]??null:null)});}return n}function Ai(t,e){return t===null||!e.has(t)}function Ph(t,e,n){let o=new Set,r=new Set(e.map(s=>s.id));for(let s of e)for(let a of Pi(s))o.add(a);if(o.size===0)return;let i=new Set;for(let s of o)for(let a of t.inline.follow.holdersOf(s))r.has(a)||i.add(a);for(let s of i){let a=t.inline.textOf(s);if(!a)continue;let l=tn(a),d=l.ids.flatMap((c,u)=>{if(!c||!o.has(c))return [];let f=Ie(l,u);return Ai(f?null:c,n)?[u]:[]});d.length!==0&&(zn(a,d),t.inline.follow.invalidate(s),t.inline.noteDrift());}}function Zl(t,e){let n=new Set,o=new Map,r=new Set;for(let l of e){let d=t.inline.textOf(l);if(!d||!t.isTombstoned(l))continue;let c=t.inline.viewOf(l).shown(d),u=0;for(let p of d.toDelta()){if(typeof p.insert=="string"){u+=p.insert.length;continue}let h=p.insert?.n;typeof h=="string"&&!c.hidden.has(u)&&r.add(h),u+=1;}let f=[];c.identities.ids.forEach((p,h)=>{!p||c.hidden.has(h)||(f.push(p),Ie(c.identities,h)&&n.add(p));});for(let p of c.incoming)for(let h of p.identities)h&&f.push(h);f.length>0&&o.set(l,f);}let i=[];if(n.size===0)return {held:i,shown:o,embeds:r};let s=new Set(e),a=new Set;for(let l of n)for(let d of t.inline.follow.holdersOf(l))s.has(d)||a.add(d);for(let l of a){let d=t.inline.textOf(l);if(!d)continue;let c=tn(d),u=[],f=[];c.ids.forEach((p,h)=>{!p||!n.has(p)||(Ie(c,h)?u.push(h):f.push(h));}),f.length>0&&i.push({holder:l,text:d,items:mr(d,f),identities:f.map(p=>c.ids[p])}),u.length!==0&&(zn(d,u),t.inline.follow.invalidate(l),t.inline.noteDrift());}return {held:i,shown:o,embeds:r}}function Ql(t,e,n,o){let r=new Set(n);for(let i of e){if(o.embedded.has(i)||O(i))continue;let s=i;[...t.inline.holdersOf(s)].some(a=>!r.has(a))||!t.hasNode(s)||t.isTombstoned(s)||t.listingParents(s).length===0&&t.tombstone(s);}}function ed(t,e,n){let o=new Set(e.deleted);for(let i of n.values())for(let s of i)o.add(s);let r=Ah([...o].filter(i=>!e.copied.has(i)));r.length>0&&qe(t.doc).record(r);}function Ah(t){let e=t.flatMap(o=>we(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 td(t,e,n){for(let{holder:o,text:r,items:i,identities:s}of e){let a=i.filter((l,d)=>Ai(s[d],n));a.length!==0&&(yr(r,a),t.inline.follow.invalidate(o),t.inline.noteDrift());}}function nd(t,e,n=new Map,o=new Set){let r=e.typed,i=new Set,s=[],a=new Set;for(let{id:f}of e.paragraphs){let p=t.inline.textOf(f);if(p)for(let h of Th(t,f,p))h===f||o.has(h)||t.inline.isDeletedParagraph(h)&&a.add(h);}for(let{id:f,after:p}of e.paragraphs){let h=t.schema.nodes.get(f);if(!h||a.has(f))continue;let g=n.get(f)??yo(p,t.limits),y=t.isTombstoned(f);for(let S of g){if(y)break;typeof S.insert!="string"&&"n"in S.insert&&i.add(S.insert.n);}let I=t.inline.textOf(f),k=I?t.inline.viewOf(f).shown(I):null,m=I?Rl(I,k?.hidden,{limits:t.limits,paragraphId:f}):[];s.push({id:f,record:h,text:I,before:m,after:g,steps:Tl(m,g,true,r&&Ol(p,r)),identities:k?.identities.ids??[],shownIdentities:k?.identities??null,hidden:k?.hidden??new Set});}let l=Mh(s),d=dl(s,(f,p)=>({...f,attributes:{...f.attributes,[at]:p}}),f=>{let{[at]:p,...h}=f.attributes;return Se(h)},(f,p)=>Ae(f.attributes,t.limits,s[p].id).text?.id??"",f=>Dh(t,s[f].id));$l(s);for(let f of s){let p=f.text??fo(f.record,[]);Ch(p,f.before,f.after,f.steps,f.shownIdentities,h=>t.inline.follow.shownCopy(h)!==null,(h,g,y)=>Fr(h,g,y,t.limits,f.id)),t.inline.follow.invalidate(f.id);}for(let{write:f,ids:p,originals:h}of l){let g=p.filter((y,I)=>Ai(h[I],d));!f.text||g.length===0||(yr(f.text,g),t.inline.follow.invalidate(f.id),t.inline.noteDrift());}Ph(t,s,d);let c=new Set(e.paragraphs.map(f=>f.id));for(let f of e.embedsBefore)i.has(f)||[...t.inline.holdersOf(f)].some(p=>!c.has(p))||t.hasNode(f)&&!t.isTombstoned(f)&&t.listingParents(f).length===0&&t.tombstone(f);let u=new Set;for(let f of s)for(let p of Pi(f))u.add(p);return {copied:d,deleted:u,embedded:i}}function Dh(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 od=new WeakMap,_h=4096;function id(t,e){if(e.effects.length!==1)return null;let n=e.effects[0];if(n.kind!=="spliceText"||n.deleteCount!==0||!Bh(n.insert)||t.hasUnobservedWrites()||$e(t.doc))return null;let o=t.inline.owner(n.logicalId);if(o===null)return null;let r=t.inline.textOf(o);if(!r||t.inline.sharesIds(o))return null;let i=t.inline.viewOf(o),s=i.shown(r);if(s.hidden.size>0||s.incoming.length>0)return null;let a=Qr(r);if(a.leftOut)return null;let l=a.ops,d=0,c=-1,u=0,f=null,p=new Set,h=new Set;for(let S of l){let L=S.attributes??{};if(!Uh(t,o,L))return null;let v=Ae(L,t.limits,o);if(typeof S.insert=="string"&&(!v.run||!v.text))return null;let b=new Set;for(let E of [v.run?.id,v.runProperties?.id,v.text?.id,v.textValueId,...v.wrap.map(M=>M.id)])if(E){if(p.has(E)&&!h.has(E))return null;b.add(E),p.add(E);}h=b;let w=typeof S.insert=="string"?S.insert.length:1;if(typeof S.insert=="string"&&v.textValueId!==null&&i.shownId(v.textValueId)===n.logicalId){if(c<0)c=d;else if(c+u!==d)return null;if(f&&Se(f)!==Se(L))return null;f??=L,u+=w;}d+=w;}if(!f||!Number.isSafeInteger(n.utf16Start)||n.utf16Start<0||n.utf16Start>u||u+n.insert.length>t.limits.maxTextLength)return null;let g=c+n.utf16Start,y=g>0?rd(l,g-1):null,I=g<d?rd(l,g):null,k=n.insert[0],m=n.insert[n.insert.length-1];return I&&I.key===`c${k}`||y&&y.key===`c${m}`&&y.element!==(f.t??"")||y?.highSurrogate||y?.revisions&&y.element!==(f.t??"")?null:{paragraphId:o,text:r,length:r.length,position:g,value:n.insert,attributes:Tt(f),identities:s.identities}}function sd(t,e){if(e.text.length!==e.length)return false;let n=Ci(e.identities,e.position);return n?Mi(e.text,e.position,e.value,e.attributes,n):Ti(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 Bh(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 Uh(t,e,n){let o=Se(n),r=JSON.stringify([e,o]),i=od.get(t.limits);i||od.set(t.limits,i=new Map);let s=i.get(r);if(s!==void 0)return s;let a;try{let l=Ae(n,t.limits,e);a=Se(Ct(l,e,t.limits))===o;}catch(l){if(!(l instanceof Ye))throw l;a=false;}return i.size>=_h&&i.clear(),i.set(r,a),a}function rd(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=io(o.attributes??{});if(typeof o.insert!="string")return {key:"embed",element:"",highSurrogate:false,revisions:i};let s=o.insert.charCodeAt(e-n);return {key:`c${o.insert[e-n]}`,element:o.attributes?.t??"",highSurrogate:s>=55296&&s<=56319,revisions:i}}n+=r;}return null}function Di(t,e){let n=[],o=[{id:e,depth:0}],r=new Set,i=0;for(;o.length>0;){let{id:s,depth:a}=o.pop();if(r.has(s)||a>t.limits.maxTreeDepth)return null;r.add(s);let l=t.record(s);if(!l)return null;if(wt(l)){let d=t.projectedTextValue(s)??l.value;if(i+=d.length,i>t.limits.maxTextLength)return null;n.push({id:s,value:d});}else if(J(l)&&!l.kind.endsWith("Properties"))for(let d=l.childIds.length-1;d>=0;d-=1)o.push({id:l.childIds[d],depth:a+1});}return n}function on(t,e,n){let o=Di(t,e),r=[];if(!o||o.length===0)return false;for(let l of n){let d=Di(t,l);if(!d)return false;for(let c of d)r.push(c);}if(o.map(l=>l.value).join("")!==r.map(l=>l.value).join(""))return false;let i=[],s=0,a=0;for(let l of r){for(;s<o.length-1&&a===o[s].value.length;)s+=1,a=0;let d=o[s];if(!d||a+l.value.length>d.value.length)return false;l.id!==d.id&&i.push({product:l.id,source:d.id,start:a,end:a+l.value.length}),a+=l.value.length;}for(let l of i)t.registerSplitText(l.product,l.source,l.start,l.end);return true}function wo(t,e,n){return t!=="run"&&t!=="text"?null:e.filter(o=>n(o)===t)}function ad(t,e,n,o){for(let{removedId:r,runs:i}of e){let s=n.filter(a=>!i.includes(a));for(let a=1;a<=Math.min(s.length,Fh);a+=1){let l=s.slice(0,a);if(on(t,r,[...i,...l])){o(r,l);break}}}}var Fh=8;function Ni(t,e){return (Di(t,e)??[]).some(n=>t.splitTextPending(n.id))}var At=class{constructor(e){this.registry=e;}registry;touched=new Map;created=new Set;has(e){return this.created.has(e)||this.touched.has(e)||this.registry.hasNode(e)}node(e){let n=this.touched.get(e);if(n)return n;let o=this.registry.nodeShape(e);return o?(this.touched.set(e,o),o):null}putNode(e){this.node(e.logicalId)||(this.created.add(e.logicalId),this.touched.set(e.logicalId,{isText:e.kind==="textValue",textLength:0,children:[]}));}spliceText(e,n,o){let r=this.node(e);r&&(r.textLength=Math.max(0,r.textLength-n)+o);}spliceChildren(e,n,o,r){let i=this.node(e);i&&i.children.splice(n,o,...r);}moveNode(e,n,o){for(let s of this.listersOf(e)){let a=this.node(s);if(a)for(let l=a.children.length-1;l>=0;l-=1)a.children[l]===e&&a.children.splice(l,1);}let r=this.node(n);if(!r)return;let i=Math.min(o,r.children.length);r.children.splice(i,0,e);}listersOf(e){let n=new Set(this.registry.listingParents(e)),o=this.registry.parentOf(e);o!==null&&n.add(o);for(let[r,i]of this.touched)i.children.includes(e)&&n.add(r);return n}};function Pn(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 ut(t,e){return O(e)||e.length===0?{ok:false,code:"prototype-key",detail:e}:t.has(e)?null:{ok:false,code:"unknown-logical-id",detail:e}}function jh(t,e,n){if(O(e.logicalId)||e.logicalId.length===0)return {ok:false,code:"invalid-logical-id",detail:e.logicalId};let o=n.node(e.logicalId);return o&&o.isText!==(e.kind==="textValue")?{ok:false,code:"invalid-bound",detail:`node class ${e.logicalId}`}:e.kind==="textValue"?null:O(e.qname.localName)?{ok:false,code:"prototype-key",detail:e.qname.localName}:ve(e.qname.namespaceUri,t.limits.maxStringLength)?{ok:false,code:"invalid-string"}:null}function vo(t,e,n){switch(e.kind){case "putNode":return jh(t,e.descriptor,n);case "spliceText":{let o=ut(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=ut(n,e.logicalId);return o||(O(e.qname.localName)?{ok:false,code:"prototype-key",detail:e.qname.localName}:ve(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=ut(n,e.logicalId);return o||(O(e.prefix)?{ok:false,code:"prototype-key"}:e.uri!==null&&ve(e.uri,t.limits.maxStringLength)?{ok:false,code:"invalid-string"}:null)}case "spliceChildren":{let o=ut(n,e.parentLogicalId);if(o)return o;if(!Number.isSafeInteger(e.start)||!Number.isSafeInteger(e.deleteCount)||e.start<0||e.deleteCount<0)return {ok:false,code:"invalid-bound"};if(e.childLogicalIds.length>t.limits.maxChildren)return {ok:false,code:"too-many-children"};for(let i of e.childLogicalIds){let s=ut(n,i);if(s)return s}let r=n.node(e.parentLogicalId);if(r&&!r.isText){if(e.start+e.deleteCount>r.children.length&&!fd(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=ut(n,e.logicalId);if(o)return o;let r=ut(n,e.destinationParentLogicalId);return r||(!Number.isSafeInteger(e.destinationIndex)||e.destinationIndex<0?{ok:false,code:"invalid-bound"}:null)}case "putXmlPart":{let o=me(e.name);if(o)return {ok:false,code:o,detail:e.name};let r=ut(n,e.rootLogicalId);return r||(t.partCount()>=t.limits.maxParts?{ok:false,code:"too-many-parts"}:null)}case "deleteXmlPart":{let o=me(e.name);return o?{ok:false,code:o,detail:e.name}:null}case "putRelationship":{if(e.record.ownerPart!=="/"){let o=me(e.owner);if(o)return {ok:false,code:o}}return O(e.record.id)?{ok:false,code:"prototype-key"}:t.relationshipCount()>=t.limits.maxRelationships?{ok:false,code:"too-many-relationships"}:null}case "deleteRelationship":return O(e.relationshipId)?{ok:false,code:"prototype-key"}:null;case "putContentTypeOverride":{let o=me(e.partName);return o?{ok:false,code:o}:ve(e.mediaType,t.limits.maxMediaTypeLength)?{ok:false,code:"invalid-string"}:null}case "deleteContentTypeOverride":{let o=me(e.partName);return o?{ok:false,code:o}:null}case "putBinary":{let o=Ms(e.descriptor);return o?{ok:false,code:o}:null}case "deleteBinary":return O(e.storageKey)?{ok:false,code:"prototype-key"}:null;default:return {ok:false,code:"invalid-bound"}}}function zh(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&&!mt(o)&&!mt(r)){e.push({...o,insert:r.insert}),n+=1;continue}e.push(o);}return e}function $h(t,e,n){switch(e.kind){case "putNode":e.descriptor.kind==="textValue"?t.hasNode(e.descriptor.logicalId)||t.putText(e.descriptor.logicalId,""):t.hasNode(e.descriptor.logicalId)?t.updateElementShell(e.descriptor.logicalId,{kind:e.descriptor.kind,namespaceUri:e.descriptor.qname.namespaceUri,localName:e.descriptor.qname.localName,prefix:e.descriptor.qname.prefix}):(t.putElement({logicalId:e.descriptor.logicalId,kind:e.descriptor.kind,namespaceUri:e.descriptor.qname.namespaceUri,localName:e.descriptor.qname.localName,prefix:e.descriptor.qname.prefix,attributes:[],bindings:[]}),e.descriptor.kind==="paragraph"&&Bl(t.schema.nodes.get(e.descriptor.logicalId)));return;case "spliceText":if(n.has(e.logicalId)&&e.utf16Start===0&&e.deleteCount===0&&t.textOf(e.logicalId).toString()===e.insert)return;let o=mt(e);t.spliceText(o?.logicalId??e.logicalId,o?.utf16Start??e.utf16Start,e.deleteCount,e.insert);return;case "setAttribute":t.setAttribute(e.logicalId,e.qname,e.value);return;case "setNamespaceBinding":t.setNamespaceBinding(e.logicalId,e.prefix,e.uri);return;case "spliceChildren":{let r=t.record(e.parentLogicalId),i=r&&"childIds"in r?r.childIds.length:e.start,s=re(t.schema.nodes.get(e.parentLogicalId)),a=d=>t.splitSiblings.ranksOf(e.parentLogicalId)?.has(d)??false;jl(d=>t.schema.nodes.get(d),s,e.start,e.deleteCount,a);let l=K.getState(t.doc.store,t.doc.clientID);t.spliceChildren(e.parentLogicalId,fd(t,e,i)?i:e.start,e.deleteCount,e.childLogicalIds),Fl(d=>t.schema.nodes.get(d),d=>{let c=t.inline.textOf(d);return Nl(c,c?t.inline.viewOf(d).shown(c):null)},s,e.childLogicalIds,[...rt(t.doc,l)].filter(d=>d.parent===s),a);return}case "moveNode":t.moveNode(e.logicalId,e.destinationParentLogicalId,e.destinationIndex);return;case "putXmlPart":t.putXmlPart({name:e.name,id:e.name,rootLogicalId:e.rootLogicalId,contentType:"application/xml"});return;case "deleteXmlPart":t.deleteXmlPart(e.name);return;case "putRelationship":t.putRelationship({...e.record,ownerPart:e.owner});return;case "deleteRelationship":t.deleteRelationship(e.owner,e.relationshipId);return;case "putContentTypeOverride":t.putContentTypeOverride(e.partName,e.mediaType);return;case "deleteContentTypeOverride":t.deleteContentTypeOverride(e.partName);return;case "putBinary":t.putBinary(e.descriptor);return;case "deleteBinary":t.deleteBinary(e.storageKey);return}}function Wh(t,e){let n=t.kindOf(e);return n!==null&&!n.endsWith("Properties")}function Kh(t,e,n,o){let r=new Set((n.get(e)??[]).filter(i=>Wh(t,i)));if(r.size!==0){for(let i of o)if(!(i.kind!=="spliceChildren"||i.parentLogicalId===e)&&i.childLogicalIds.some(s=>r.has(s)))return i.parentLogicalId}}function Vh(t,e){let n=new At(t),o=[],r=new Set,i=new Set,s=new Set,a=new Set,l=new Map;for(let d of e){let c=vo(t,d,n);if(c)return c;if(d.kind==="spliceChildren"){let u=d.deleteCount>0?n.node(d.parentLogicalId):null;if(u&&!u.isText){let f=d.start+d.deleteCount;for(let p=d.start;p<f;p+=1){let h=u.children[p];if(h!==void 0&&(o.push(h),i.add(h),d.childLogicalIds.length>0)){let g=l.get(d)??[];g.push(h),l.set(d,g);}}}for(let f of d.childLogicalIds)r.add(f),i.delete(f);}else d.kind==="moveNode"?(r.add(d.logicalId),i.delete(d.logicalId)):d.kind==="putNode"&&(a.add(d.descriptor.logicalId),d.descriptor.kind==="textValue"&&s.add(d.descriptor.logicalId));Pn(n,d);}return {removed:o,reinserted:r,unlistedAtEnd:i,mintedText:s,mintedNodes:a,replacementsByEffect:l}}function Jh(t){let e=0;for(let n of t)n.kind==="putNode"&&(e+=1);return e}function Yi(t,e,n,o){if(o){let c=false;return t.doc.transact(()=>{t.noteWrite(),c=sd(t,o);},kr),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=ho(t,e.effects);if(c.refusal)return {ok:false,...c.refusal};r=c.plan,r&&(i={...e,effects:c.passThrough});}let s=i.effects.map(Vt);if(t.nodeCount()+Jh(s)>t.limits.maxNodes)return {ok:false,code:"too-many-nodes"};let a=Vh(t,s);if("ok"in a)return a;for(let c of a.replacementsByEffect.values())for(let u of c)if(t.kindOf(u)==="run"&&Ni(t,u))return {ok:false,code:"invalid-bound",detail:`split of pending text in ${u}`,transient:true};let l=r?.paragraphs.find(({id:c})=>t.inline.textOf(c)===null&&cd(t,c));if(l)return {ok:false,code:"invalid-bound",detail:`pending text of paragraph ${l.id}`,transient:true};let d;try{d=new Map(r?.paragraphs.map(({id:c,after:u})=>[c,yo(u,t.limits)]));}catch(c){if(!(c instanceof Ye))throw c;return {ok:false,code:c.code,detail:c.detail}}try{Xh(t,s,a,r,d);}finally{Ul();}return {ok:true}}function Xh(t,e,n,o,r){t.doc.transact(()=>{t.noteWrite();let i=Qh(t,n.removed),s=[],a=[];for(let u of zh(e))if($h(t,u,n.mintedText),u.kind==="spliceChildren"){if(n.mintedNodes.has(u.parentLogicalId))for(let f of u.childLogicalIds)n.mintedNodes.has(f)&&t.kindOf(f)==="run"&&a.push(f);Zh(t,n,n.replacementsByEffect.get(u)??[],u.childLogicalIds,s);}ad(t,s,a,(u,f)=>{t.recordRunSplit(ud(t,u,n.reinserted),u,f);}),qh(t,e,n,i);let l=Zl(t,n.removed),d=il(t,n,i),c=o?nd(t,o,r,new Set(n.removed)):{copied:new Set,deleted:new Set,embedded:new Set};rl(t,n.removed,c.embedded,n.mintedNodes,o?.paragraphs.map(({after:u})=>u)??[]),td(t,l.held,c.copied),ed(t,c,new Map([...l.shown,...d])),Ql(t,l.embeds,n.removed,c);},kr);}function Hh(t,e){let n=t.inline.textOf(e);if(n===null&&cd(t,e)||n!==null&&Gh(t,e,n))return true;let o=t.record(e);return (o&&"childIds"in o?o.childIds:[]).some(i=>t.kindOf(i)==="run"&&Ni(t,i))}function dd(t,e){let n=t.kindOf(e)==="paragraph"?e:t.inline.owner(e)??t.parentOf(e);return n!==null&&Hh(t,n)}function Gh(t,e,n){return zt(t.doc)?t.inline.viewOf(e).shown(n).incoming.some(o=>Vs(t.doc,o.source)):false}function cd(t,e){let n=t.schema.nodes.get(e);return Y(n)&&Ks(n,se)}function qh(t,e,n,o){if(n.removed.length===0)return;let r=new Set;for(let i of t.partEntries())r.add(i.rootLogicalId);for(let i of n.removed){if(n.reinserted.has(i)&&!n.unlistedAtEnd.has(i)||!t.hasNode(i)||t.isTombstoned(i)||r.has(i))continue;let s=Kh(t,i,o,e);s&&t.unlistChildren(i,o.get(i)??[]),t.tombstone(i,s);}}function Zh(t,e,n,o,r){for(let i of n){let s=t.kindOf(i);if(s!=="run"&&s!=="text"||e.reinserted.has(i)&&!e.mintedNodes.has(i))continue;let a=ud(t,i,e.reinserted);if(s==="text"){let d=wo(s,o,c=>t.kindOf(c));if(d&&on(t,i,d)){let c=o.filter(u=>e.mintedNodes.has(u));t.recordRunSplit(a,i,c);}continue}let l=o.filter(d=>t.kindOf(d)==="run");on(t,i,l)||r.push({removedId:i,runs:l}),t.recordRunSplit(a,i,l);}}function ud(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 Qh(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 fd(t,e,n){return e.deleteCount===0&&e.start>n&&t.partEntries().some(o=>o.rootLogicalId===e.parentLogicalId)}var Oe="splitTextSource",eg=Object.freeze({kind:"docx-package-restored-split-anchors"});function Re(t,e){throw new N(t,e)}function _i(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function pd(t){return _i(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 hd(t){return !_i(t)||!Object.keys(t).every(e=>["type","item","assoc"].includes(e))||!pd(t.type)||t.item!==void 0&&!pd(t.item)||t.assoc!==0&&t.assoc!==-1?Re("invalid-string",Oe):K.createRelativePositionFromJSON(t)}var Dt=class extends Error{},rn=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);(!Y(i)||!(i.get(Te)instanceof K.Text))&&Re("invalid-bound",e);let s=this.read(n),a=s===null?{sourceId:n,text:this.sourceText(n),start:0,end:this.sourceText(n).length}:this.resolve(s);(a.sourceId.length===0||a.sourceId.length>this.limits.maxStringLength||O(a.sourceId))&&Re("invalid-string",n),(!Number.isSafeInteger(o)||!Number.isSafeInteger(r)||o<0||r<o||r>a.end-a.start||e===a.sourceId)&&Re("invalid-bound",e);let l=(c,u)=>{if(s&&u==="end"&&c===a.end-a.start)return s.end;if(s&&c===0)return s.start;if(s&&c===a.end-a.start)return s.end;let f=a.start+c;return K.createRelativePositionFromTypeIndex(a.text,f,f===0&&u==="start"?-1:0)},d=JSON.stringify({sourceId:a.sourceId,start:K.relativePositionToJSON(l(o,"start")),end:K.relativePositionToJSON(l(r,"end"))});d.length>this.limits.maxStringLength&&Re("invalid-string",e),i.set(Oe,d),this.indexExisting(e);}normalizeRestoredAnchors(){let e=new Map,n=r=>{let i=r.item;if(i===null)return r;let s=`${i.client}:${i.clock}:${r.assoc}`,a=e.get(s);if(a)return a;let l=f=>K.getState(this.doc.store,f.client)>f.clock?K.getItem(this.doc.store,f):null,d=i,c=l(d);for(;c instanceof K.Item&&c.redone!==null;)d=K.createID(c.redone.client,c.redone.clock+d.clock-c.id.clock),c=l(d);let u=c instanceof K.Item&&!c.deleted&&!K.compareIDs(i,d)?K.createRelativePositionFromJSON({...K.relativePositionToJSON(r),item:{client:d.client,clock:d.clock}}):r;return e.set(s,u),u},o=[];for(let r of this.sourceByAlias.keys()){let i=this.nodes.get(r);if(Y(i)&&Or(i,Oe))continue;let s=this.read(r);if(!s)continue;let a=n(s.start),l=n(s.end);if(K.compareRelativePositions(a,s.start)&&K.compareRelativePositions(l,s.end))continue;let d=JSON.stringify({sourceId:s.sourceId,start:K.relativePositionToJSON(a),end:K.relativePositionToJSON(l)});d.length>this.limits.maxStringLength&&Re("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(Oe,i),this.indexExisting(r);},eg);}sourceAliases(e){return [...this.aliasesBySource.get(e)??[]]}range(e){try{return this.resolveRange(e)}catch(n){if(n instanceof Dt)return null;throw n}}isPending(e){try{return this.resolveRange(e),!1}catch(n){if(n instanceof Dt)return true;throw n}}resolveRange(e){let n=this.read(e);return n===null?null:this.resolve(n)}value(e){let n=this.range(e);return n===null?null:n.text.toString().slice(n.start,n.end)}indexExisting(e){let n=null,o=false;try{n=this.read(e),n&&this.resolve(n);}catch{o=true;}let r=this.sourceByAlias.get(e);if(r!==void 0&&r!==n?.sourceId){let i=this.aliasesBySource.get(r);i?.delete(e),i?.size===0&&this.aliasesBySource.delete(r),this.sourceByAlias.delete(e);}if(n){this.sourceByAlias.set(e,n.sourceId);let i=this.aliasesBySource.get(n.sourceId)??new Set;i.add(e),this.aliasesBySource.set(n.sourceId,i);}(o||n||r!==void 0||this.values.has(e))&&this.pending.add(e);}noteChanged(e){this.indexExisting(e);for(let n of this.aliasesBySource.get(e)??[])this.pending.add(n);}reset(){this.sourceByAlias.clear(),this.aliasesBySource.clear();for(let e of this.values.keys())this.pending.add(e);this.nodes.forEach((e,n)=>this.indexExisting(n));}overlays(){let e=new Set,n=new Map;if(this.held.size>0&&!zt(this.doc)){for(let o of this.held)this.indexExisting(o);this.held.clear();}for(let o of this.pending){let r=null;try{r=this.resolveRange(o),this.awaiting.delete(o)&&e.add(o);}catch(s){if(!(s instanceof Dt))throw s;this.awaiting.has(o)||e.add(o),this.awaiting.add(o);}let i=null;if(r){let s=n.get(r.sourceId);s===void 0&&(s=r.text.toString(),n.set(r.sourceId,s)),i=s.slice(r.start,r.end);}i===null?this.values.delete(o)&&e.add(o):i!==this.values.get(o)&&(this.values.set(o,i),e.add(o));}return this.pending.clear(),{values:this.values,changedIds:e,awaiting:this.awaiting}}sourceText(e){let n=this.nodes.get(e),o=Y(n)?n.get(Te):null;return !(o instanceof K.Text)||o.doc!==this.doc||o.length>this.limits.maxTextLength?Re("invalid-bound",e):o}read(e){let n=this.nodes.get(e);if(!Y(n))return null;let o;if(Or(n,Oe)){if(o=this.lastEncoded.get(e),o===void 0)throw new Dt(e);this.held.add(e);}else {if(!n.has(Oe))return null;o=n.get(Oe);}if(typeof o!="string"||o.length>this.limits.maxStringLength)return Re("invalid-string",e);let r;try{r=JSON.parse(o);}catch{return Re("invalid-string",e)}if(!_i(r)||!Object.keys(r).every(s=>["sourceId","start","end"].includes(s))||typeof r.sourceId!="string"||r.sourceId.length===0||r.sourceId.length>this.limits.maxStringLength||O(r.sourceId)||r.sourceId===e)return Re("invalid-string",e);if(!(n.get(Te)instanceof K.Text))return Re("invalid-bound",e);let i={sourceId:r.sourceId,start:hd(r.start),end:hd(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&&K.getState(this.doc.store,d.item.client)<=d.item.clock))throw new Dt(e.sourceId);let n=this.nodes.get(e.sourceId);if(Y(n)&&n.has(Oe))return Re("invalid-bound",e.sourceId);let o=this.sourceText(e.sourceId),r=K.createRelativePositionFromTypeIndex(o,0).type;if(!r||[e.start,e.end].some(d=>d.type?.client!==r.client||d.type?.clock!==r.clock))return Re("invalid-bound",e.sourceId);let i=K.createAbsolutePositionFromRelativePosition(e.start,this.doc,false),s=K.createAbsolutePositionFromRelativePosition(e.end,this.doc,false),a=e.start.item!==null&&K.getItem(this.doc.store,e.start.item).deleted,l=e.end.item!==null&&K.getItem(this.doc.store,e.end.item).deleted;return i===null||s===null||i.type!==o||s.type!==o||i.index<0||s.index>o.length?Re("invalid-bound",e.sourceId):{sourceId:e.sourceId,text:o,start:i.index,end:Math.max(i.index,s.index),startAssoc:e.start.assoc,endAssoc:e.end.assoc,startAnchorDeleted:a,endAnchorDeleted:l}}};function Lo(t,e,n,o,r,i){if(!o||i.length===0)return null;let s=r===0&&o.startAssoc!==-1,a=r===o.end-o.start;if(!s&&!a)return null;let l=t.get(n)?.get(Oe);if(typeof l!="string")return null;let d=JSON.parse(l),c=K.createRelativePositionFromJSON(d.start),u=K.createRelativePositionFromJSON(d.end);if(a=a&&(s||u.item!==null&&K.getItem(o.text.doc.store,u.item).deleted),!s&&!a)return null;let f=[],p=o.text.doc.store,h=g=>{if(g.item===null||!K.getItem(p,g.item).deleted)return false;let y=K.createAbsolutePositionFromRelativePosition(g,o.text.doc,false);return y!==null&&y.type===o.text&&y.index===o.end};for(let g of e.sourceAliases(o.sourceId)){if(!e.range(g))continue;let y=t.get(g),I=y.get(Oe);if(typeof I!="string")continue;let k=JSON.parse(I),m=(v,b)=>{let w=K.createRelativePositionFromJSON(v);return s&&a&&K.compareRelativePositions(c,u)&&K.compareRelativePositions(w,c)?b==="start"?"after":"before":s&&K.compareRelativePositions(w,c)?"before":a&&K.compareRelativePositions(w,u)||a&&!s&&!(g===n&&b==="start")&&h(w)?"after":null},S=g===n&&s?"before":m(k.start,"start"),L=g===n&&a?"after":m(k.end,"end");(S||L)&&f.push({record:y,start:S,end:L});}return ()=>{let g=o.start+r,y=K.relativePositionToJSON(K.createRelativePositionFromTypeIndex(o.text,g,g===0&&o.startAssoc===-1?-1:0)),I=K.relativePositionToJSON(K.createRelativePositionFromTypeIndex(o.text,g+i.length,0));for(let k of f){let m=JSON.parse(k.record.get(Oe));k.start&&(m.start=k.start==="before"?y:I),k.end&&(m.end=k.end==="before"?y:I);let S=JSON.stringify(m);S!==k.record.get(Oe)&&k.record.set(Oe,S);}}}var Ro=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);Y(i)&&(i.set(hn,e),i.set(kt,e),this.indexExisting(r));}}indexExisting(e){let n=this.nodes.get(e),o=Et(n);if(o===null||o===e||ci(n))return;this.invalidate();let r=this.runsBySplitOrigin.get(o)??new Set;r.add(e),this.runsBySplitOrigin.set(o,r),this.liveRootedOrigins.add(o);}productsOf(e){return [...this.runsBySplitOrigin.get(e)??[]].filter(n=>Et(this.nodes.get(n))===e)}loserRuns(e){if(this.cachedLosers)return this.cachedLosers;let n=new Set,o=new Set,r=i=>{let s=[i];for(;s.length>0;){let a=s.pop();if(!o.has(a)){o.add(a),e.isPresent(a)&&n.add(a);for(let l of this.productsOf(a))s.push(l);}}};for(let i of this.liveRootedOrigins){let s=this.productsOf(i),a=e.isPresent(i)?null:s.filter(l=>mn(this.nodes.get(l))===i).map(l=>We(l)??"").sort()[0];for(let l of s)(We(l)??"")!==a&&r(l);}return this.cachedLosers=n,n}};function Oo(t,e,n){let o=new Map;for(let a=0;a<t.length;a+=1){let l=t[a],d=n(l);if(d===null||d===l)continue;let c=o.get(d)??{loser:[],winner:[]};(e(l)?c.loser:c.winner).push(a),o.set(d,c);}let r=new Map;for(let{loser:a,winner:l}of o.values())a.length!==1||l.length!==1||a[0]>l[0]||r.set(l[0],a[0]);if(r.size===0)return null;let i=new Map;for(let[a,l]of r)i.set(l,a);let s=[];for(let a=0;a<t.length;a+=1){let l=i.get(a);l!==void 0&&s.push(l),r.has(a)||s.push(a);}return s}var gd=4096;function bd(t){let e=lt(t),n=[],o=0;for(let r=ge(t);r&&o<gd;r=r.right)for(let i=0;i<r.length&&o<gd;i+=1)o+=1,e.origin("move",r.id.client,r.id.clock+i)&&n.push(nt(t,r,i));return n}function tg(t,e){let n=e[0];return n===void 0||t.length===0?false:t.indexOf(n)>0&&e.indexOf(t[0])<=0}function An(t,e){return t!==null&&t.client===e.id.client&&t.clock>=e.id.clock&&t.clock<e.id.clock+e.length}var md=t=>t?`${t.client}:${t.clock}`:"-",Bi=t=>`${md(t.origin)} ${md(t.rightOrigin)}`;function ng(t,e,n=[],o=()=>[],r=[],i=[]){let s=null,a=0,l=[],d=t.doc?.getMap(pn)??null,c=new Map,u=new Map;for(let g=ge(t);g;g=g.right){if(!g.deleted)for(let I of g.content.getContent())u.has(I)||u.set(I,l.length);l.push(g);let y=Bi(g);c.set(y,(c.get(y)??0)+1);}let f=g=>g.deleted||Ui(d,g),p=new Map,h=g=>{let y=p.get(g);if(!y){let I=e(g);y=new Set(I?bd(I):[]),p.set(g,y);}return y};for(let g=0;g<l.length;){let y=l[g],I=Bi(y);if(c.get(I)<2||!f(y)){g+=1;continue}let k=[{head:y,items:[y]}],m=g+1;for(;m<l.length;m+=1){let D=l[m],T=k.at(-1);if(Bi(D)===I&&f(D))k.push({head:D,items:[D]});else if(T.items.some(V=>An(D.origin,V)))T.items.push(D);else break}if(k.length<2){g+=1;continue}let S=g,L=0,v=k.flatMap(D=>D.items);for(let D=g;D>1;){let T=l[D-1],V=v.find(x=>x.deleted&&An(T.rightOrigin,x));if(!V)break;if(D-=1,T.deleted){v.push(T);continue}if(!T.origin||!y.origin||!K.compareIDs(T.origin,y.origin)||!yd(d,T,V))break;k.unshift({head:T,items:[T]}),L+=1,S=D;}for(let D of k)for(let T of D.items)if(!T.deleted)for(let V of T.content.getContent())n.push(V);let b=D=>D.flatMap(T=>T.items.filter(V=>!V.deleted).flatMap(V=>V.content.getContent())),w=b(k),E=new Set(k.slice(0,L).map(D=>D.head)),M=k.flatMap(D=>D.items.filter(T=>!T.deleted).flatMap(T=>T.content.getContent().map((V,x)=>x===0&&E.has(T)||rg(d,V,T,x)))),j=[];for(let D of k)for(let T of D.items){if(T.deleted)continue;let V=T.content.getContent().length;for(let x=0;x<V;x+=1){let R=x>0?{client:T.id.client,clock:T.id.clock+x-1}:T.origin;j.push(R?`${R.client}:${R.clock}`:null);}}let _=k.flatMap(D=>D.items.filter(T=>!T.deleted).flatMap(T=>T.content.getContent().map((V,x)=>x===0&&!E.has(T)&&v.some(R=>An(T.rightOrigin,R)&&!(R.deleted&&yd(d,T,R)))))),z=k.flatMap((D,T)=>b([D]).map(()=>T)),ee=cg(k,e,t.doc,o,i,D=>E.has(D)||Ui(d,D)),ae=new Set(w).size<w.length?null:og(w,M,_,j,z,o,t.doc,i,h)??(ee?b(ee):null),$=ae??w,P=l[S-1];if(P&&!P.deleted&&An(y.origin,P)){let D=new Set(k.filter(x=>!x.head.deleted).map(x=>Dn(x.head))),T=P.content.getContent()[y.origin.clock-P.id.clock],V=new Map;for(let x of k){let R=T;for(let C of b([x]))V.set(C,R),R=C;}r.push({source:T,heads:$.filter(x=>D.has(x)),shown:$,before:V});}let te=ae!==null&&ae.some((D,T)=>w[T]!==D);te&&(a+=1,s??=new Map,ae.forEach((D,T)=>{(u.get(D)??S)>=S&&s.set(D,{group:a,rank:T});})),g=te?m:g+1;}return s}function og(t,e,n,o,r,i,s,a,l=()=>new Set){let d=[],c=[],u=m=>i(m).map(S=>`${S.source}@${S.at}`).join(`
|
|
8
|
+
`),f=m=>{if(!m||!s)return null;let[S,L]=m.split(":").map(Number),v=q(s,{client:S,clock:L});if(!v||v.deleted)return null;let b=v.content.getContent()[L-v.id.clock];return typeof b=="string"?u(b):null},p=m=>{if(!m||!s)return false;let[S,L]=m.split(":").map(Number);return q(s,{client:S,clock:L})?.deleted===true},h=new Map,g=new Set;for(let[m,S]of t.entries()){let L=u(S),v=L!==""&&f(o[m])===L,b=i(S).at(-1),w=b?.source,E=()=>{let ee=b.at.replace(/\+$/,"");return t.every((H,ae)=>{if(H===S||H===w)return true;let $=l(H);return !$.has(ee)&&(!e[ae]||$.size>0)})},M=w!==void 0&&(g.has(w)||h.has(w)&&E()),j=m===0&&r[1]!==r[0],_=n[m]&&(j||r[m-1]===r[m]||!p(o[m]))?h.get(t[m-1]):e[m]&&!v&&!M?null:M?h.get(w):d.at(-1);if(_===void 0)return null;_&&g.add(S);let z=_??[];_||(d.push(z),c.push(r[m])),z.push(S),h.set(S,z);}if(d.length<2)return null;let y=d.map(m=>i(m[0])),I=new Map,k=m=>{let S=new Map;c.forEach((w,E)=>{S.has(w)||S.set(w,E);});let L=[...S.keys()].sort((w,E)=>m[S.get(w)]-m[S.get(E)]||w-E),v=new Map(L.map((w,E)=>[w,E])),b=d.map((w,E)=>E);return b.sort((w,E)=>m[w]-m[E]||v.get(c[w])-v.get(c[E])||w-E),b.flatMap(w=>d[w])};for(let m=y[0].length-1;m>=0;m-=1){let S=y[0][m].source,L=y.map(E=>vi(E,S));if(L.some(E=>E===null))continue;let v=a.length,b=Fi(s,y.map(E=>E.at(-1).at),I,a,false);if(b)return k(b);if(a.length>v)return null;let w=Fi(s,L,I,a);return w?k(w):null}return null}function yd(t,e,n){if(!t||e.deleted||!Ui(t,e))return false;let o=Ne(t,Dn(e));return o!==void 0&&o.id.client===n.id.client&&o.id.clock<n.id.clock}function Ui(t,e){let n=t?.get(Dn(e));if(!(n instanceof K.Map))return false;let o=Tn(n);return o!==null&&An(o,e)}function rg(t,e,n,o){let r=t?.get(e);if(!(r instanceof K.Map))return false;let i=Tn(r);return i!==null&&i.client===n.id.client&&i.clock===n.id.clock+o}function Dn(t){return t.content.getContent()[0]}function Id(t,e){let n=typeof t=="string"?e(t):null;return n?bd(n):[]}function xd(t,e,n){let o=e?/^(\d+):(\d+)$/.exec(e):null;if(!o)return null;let r=Number(o[1]),i=Number(o[2]),s=q(t,{client:r,clock:i}),a=s?.parent;if(!s||!(a instanceof K.Text))return null;for(let c=a._item;c;c=c.parent instanceof K.AbstractType?c.parent._item:null)if(c.deleted)return null;let l=n.get(a);if(!l){l=new Map;let c=0;for(let u=ge(a);u;u=u.right)l.set(`${u.id.client}:${u.id.clock}`,c),c+=u.length;n.set(a,l);}let d=l.get(`${s.id.client}:${s.id.clock}`);return d===void 0?null:{text:a,at:d+i-s.id.clock}}function ig(t,e,n){for(let o of t.items){if(o.deleted)continue;if(!n(o))return [];let r=Id(Dn(o),e);if(r.length>0)return r}return []}function sg(t,e,n,o){return n&&o&&n.text===o.text?n.at<o.at:tg(t,e)}function ag(t,e,n){for(let o of t.items){if(o.deleted)continue;if(!n(o))return [];let r=e(Dn(o));if(r.length>0)return r}return []}function Sd(t,e){let[n,o]=e.split(":").map(Number);return o<K.getState(t.store,n)}function lg(t,e,n,o,r){if(e===n)return null;let i=Fi(t,[e,n],o,r);return i&&i[0]!==i[1]?i[0]<i[1]:null}function Fi(t,e,n,o,r=true){if(!t)return null;let i=e.map(d=>({identity:d.endsWith("+")?d.slice(0,-1):d,after:d.endsWith("+")?.5:0})),s=i.map(({identity:d})=>d).filter(d=>!Sd(t,d));if(s.length>0)return o.push(...s),null;let a=i.map(({identity:d})=>xd(t,d,n));if(a.every(d=>d&&d.text===a[0].text))return a.map((d,c)=>d.at+i[c].after);if(!r)return null;let l=i.map(({identity:d})=>d.split(":").map(Number));return l.every(([d])=>d===l[0][0])?l.map(([,d],c)=>d+i[c].after):null}function dg(t,e,n,o,r){for(let i=e.length-1;i>=0;i-=1){let s=vi(n,e[i].source);if(s!==null)return lg(t,e[i].at,s,o,r)}return null}function cg(t,e,n,o,r,i){let s=t.map(f=>ag(f,o,i)),a=t.map(f=>ig(f,e,i)),l=new Map,d=a.map(f=>n?xd(n,f[0],l):null),c=t.map((f,p)=>p),u=false;for(let f=1;f<c.length;f+=1)for(let p=f;p>0;p-=1){let h=c[p],g=c[p-1];if(t[g].items.every(k=>k.deleted)){[c[p-1],c[p]]=[h,g];continue}if(!(dg(n,s[h],s[g],l,r)??sg(a[h],a[g],d[h],d[g])))break;[c[p-1],c[p]]=[h,g],u=true;}return u?c.map(f=>t[f]):null}var Eo=class{constructor(e,n,o){this.nodeOf=e;this.textOf=n;this.listingOf=o;}nodeOf;textOf;listingOf;built=new WeakMap;withRuns=new Set;grouped=new Set;recheck=new Map;readers=new Map;membersOf=new Map;ranksOf(e){return this.read(e)?.ranks??null}groupsOf(e){return this.read(e)?.groups??[]}parentsWithRuns(){for(let e of [...this.grouped])this.listingOf(e)||this.grouped.delete(e);return [...this.grouped]}shownChildren(e){return this.read(e)?.shown??this.listingOf(e)}takeChanged(){let e=[];for(let[n,o]of this.recheck){this.recheck.delete(n);let r=this.read(n)?.shown??this.listingOf(n);r&&(r.length!==o.length||r.some((i,s)=>o[s]!==i))&&e.push(n);}for(let n of [...this.withRuns]){let o=this.listingOf(n),r=o?this.built.get(o):void 0;if(!o||!r){this.withRuns.delete(n);continue}let i=this.nodeOf(n)?.doc??null,s=i!==null&&r.missing.some(d=>Sd(i,d)),a=r.waiting.length>0&&this.lengthsKey(r.waiting)!==r.lengths;if(!s&&!a)continue;let l=this.build(n,o);(!l||l.shown.some((d,c)=>r.shown[c]!==d))&&e.push(n);}return e}forget(e){let n=this.listingOf(e),o=n?this.built.get(n):void 0;!n||!o||(this.built.delete(n),this.recheck.has(e)||this.recheck.set(e,o.shown));}textChanged(e){for(let n of this.readers.get(e)??[])this.forget(n);}noteMembers(e,n){for(let o of this.membersOf.get(e)??[]){let r=this.readers.get(o);r?.delete(e),r?.size===0&&this.readers.delete(o);}if(n.length===0){this.membersOf.delete(e);return}this.membersOf.set(e,n);for(let o of n){let r=this.readers.get(o);r||this.readers.set(o,r=new Set),r.add(e);}}lengthsKey(e){return e.map(n=>this.textOf(n)?.length??-1).join(",")}read(e){let n=this.listingOf(e);return n&&this.built.get(n)||this.build(e,n)}build(e,n){let o=re(this.nodeOf(e));if(!o||o.length<2)return null;let r=[],i=[],s=[],a=ng(o,this.textOf,r,p=>ct(this.nodeOf(p)),i,s),l=n??o.toArray(),d=Nn(l,a),c=d?d.map(p=>l[p]):l,u=r.filter(p=>ct(this.nodeOf(p)).length===0&&Id(p,this.textOf).length===0),f={ranks:a,shown:c,waiting:u,lengths:this.lengthsKey(u),groups:i,missing:s};return i.length>0?this.grouped.add(e):this.grouped.delete(e),n&&(this.built.set(n,f),this.noteMembers(e,r)),(u.length>0||s.length>0)&&n?this.withRuns.add(e):this.withRuns.delete(e),f}};function Nn(t,e){if(!e)return null;let n=t.map((s,a)=>a),o=new Set,r=[];t.forEach((s,a)=>{o.has(s)||(o.add(s),r.push(a));});let i=false;for(let s=0;s<r.length;){let a=e.get(t[r[s]]),l=s+1;for(;a&&l<r.length&&e.get(t[r[l]])?.group===a.group;)l+=1;if(l-s>1){let d=r.slice(s,l);d.sort((c,u)=>e.get(t[c]).rank-e.get(t[u]).rank);for(let c=0;c<d.length;c+=1){let u=r[s+c];n[u]!==d[c]&&(i=true),n[u]=d[c];}}s=l;}return i?n:null}function kd(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 ji=class{constructor(e,n){this.registry=e;this.raw=n;}registry;raw;ranges=new Map;histories=new Map;strings=new Map;actions=[];shadow=null;range(e){if(this.shadow){let o=this.shadow.sources.range(e);return o?{...o,revision:0}:null}if(!this.ranges.has(e)){let o=this.registry.splitTextRange(e);this.ranges.set(e,o?{...o,revision:0}:null);}let n=this.ranges.get(e);if(n){let o=this.histories.get(n.sourceId)??[];for(;n.revision<o.length;){let r=o[n.revision],i=(s,a)=>{let l=a<0?s-1:s;return l>=r.start&&l<r.start+r.deleted};if(n.startAnchorDeleted||n.endAnchorDeleted||r.ambiguousBoundary||i(n.start,n.startAssoc)||i(n.end,n.endAssoc)){this.ensureShadow();let s=this.shadow.sources.range(e);return s?{...s,revision:0}:null}n.start=kd(n.start,n.startAssoc,r),n.end=kd(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=mt(e),o=n?this.range(n.logicalId):null,r={keepBoundary:n?.utf16Start===0&&o?.startAssoc!==-1&&e.insert.length>0,ambiguousBoundary:o!==null&&o.start===o.end&&e.insert.length>0,start:e.utf16Start,deleted:e.deleteCount,inserted:e.insert},i=this.histories.get(e.logicalId)??[];i.push(r),this.histories.set(e.logicalId,i);let s=this.strings.get(e.logicalId);s!==void 0&&this.strings.set(e.logicalId,s.slice(0,r.start)+r.inserted+s.slice(r.start+r.deleted));let a={kind:"splice",effect:e};this.actions.push(a),this.shadow&&this.replay(a);}register(e,n,o,r){let i=this.range(n),s=i?.sourceId??n,a=i?.start??0,l=i?i.end-i.start:this.raw.node(n)?.textLength??0,d=(p,h)=>i&&h==="end"&&p===l?{assoc:i.endAssoc,deleted:i.endAnchorDeleted}:i&&p===0?{assoc:i.startAssoc,deleted:i.startAnchorDeleted}:i&&p===l?{assoc:i.endAssoc,deleted:i.endAnchorDeleted}:{assoc:a+p===0&&h==="start"?-1:0,deleted:false},c=d(o,"start"),u=d(r,"end");this.ranges.set(e,{sourceId:s,start:a+o,end:a+r,startAssoc:c.assoc,endAssoc:u.assoc,startAnchorDeleted:c.deleted,endAnchorDeleted:u.deleted,revision:this.histories.get(s)?.length??0});let f={kind:"register",product:e,source:n,start:o,end:r};this.actions.push(f),this.shadow&&this.replay(f);}destroy(){this.shadow?.doc.destroy();}ensureShadow(){if(this.shadow)return;let e=new K.Doc({gc:false}),n=e.getMap(pn);this.shadow={doc:e,nodes:n,sources:new rn(n,e,this.registry.limits)},K.applyUpdate(e,K.encodeStateAsUpdate(this.registry.doc)),e.clientID=this.registry.doc.clientID,this.shadow.sources.reset();for(let o of this.actions)this.replay(o);}replay(e){let n=this.shadow,o=u=>(n.nodes.has(u)||n.nodes.set(u,Vn("")),n.nodes.get(u).get(Te));if(e.kind==="register"){o(e.product),n.sources.register(e.product,e.source,e.start,e.end);return}let{effect:r}=e,i=mt(r),s=i?n.sources.range(i.logicalId):null,a=s?.text??o(r.logicalId),l=i?.utf16Start??r.utf16Start,d=(s?.start??0)+l,c=Lo(n.nodes,n.sources,i?.logicalId??r.logicalId,s,l,r.insert);r.deleteCount>0&&a.delete(d,r.deleteCount),r.insert.length>0&&a.insert(d,r.insert),c?.();}},zi=class extends At{constructor(n,o,r,i,s=()=>[],a=()=>null){super(n);this.shared=n;this.visibleIndexes=o;this.raw=r;this.text=i;this.mergedOf=s;this.shownOf=a;}shared;visibleIndexes;raw;text;mergedOf;shownOf;filtered=new Set;node(n){let o=super.node(n);if(o&&!this.filtered.has(n)){this.filtered.add(n);let r=[...this.shared.adoptedChildren(n),...this.mergedOf(n)].filter((a,l,d)=>!o.children.includes(a)&&d.indexOf(a)===l),i=r.length>0?[...o.children,...r]:o.children,s=st(this.shared).shownChildIds(n,i);o.children=this.shownOf(n)?.slice()??this.visibleIndexes(n,s).map(a=>s[a]);}if(o?.isText){let r=this.text.range(n);o.textLength=r?r.end-r.start:this.raw.node(n)?.textLength??o.textLength;}return o}};function wd(t,e,n){let o=id(t,e);return o?{ok:true,journal:{...e,effects:[]},plan:null,typed:o}:ug(t,e,n)}function ug(t,e,n=()=>null){let o=ho(t,e.effects);if(o.refusal)return {ok:false,...o.refusal};let i=(o.plan?{...e,effects:o.passThrough}:e).effects.map(Vt),s=t.replacementLoserRuns(),a=i.filter(x=>x.kind==="putNode").length;if(t.nodeCount()+a>t.limits.maxNodes)return {ok:false,code:"too-many-nodes"};let l=new Set,d=new Map,c=(x,R)=>{l.add(x);let C=d.get(x)??new Set;C.add(R),d.set(x,C);};for(let x of i){if(x.kind==="spliceChildren"){if(x.childLogicalIds.length>t.limits.maxChildren)return {ok:false,code:"too-many-children"};for(let R of x.childLogicalIds)c(R,x.parentLogicalId);}else x.kind==="moveNode"&&c(x.logicalId,x.destinationParentLogicalId);if(l.size>t.limits.maxNodes)return {ok:false,code:"too-many-nodes"}}let u=new At(t),f=new ji(t,u),p=new zi(t,(x,R)=>S(x,R),u,f,x=>ae(x),x=>n(x)),h=new Map,g=x=>h.get(x)?.kind??t.kindOf(x),y=x=>{let R=h.get(x);return R?R.kind==="textValue"?{kind:"textValue",namespaceUri:"",localName:""}:{kind:R.kind,namespaceUri:R.qname.namespaceUri,localName:R.qname.localName}:Qe(t,x)},I=new Map,k=(x,R)=>{let C=t.splitSiblings.ranksOf(x),A=I.get(x);if(!C||!A)return C;let B=new Map(C),Q=0;for(let G of R){let F=A.get(G),ne=F===void 0||B.has(G)?void 0:B.get(F);ne&&B.set(G,{group:ne.group,rank:ne.rank+(Q+=1)/1e6});}return B},m=(x,R)=>{let C=new Map,A=new Map,B=[],G=(s.size===0?null:Oo(R,W=>s.has(W),W=>t.splitLineageOf(W)))??R.map((W,oe)=>oe),F=Nn(G.map(W=>R[W]),k(x,R));(F?F.map(W=>G[W]):G).forEach(W=>{let oe=R[W];if(oe===x||s.has(oe))return;let ye=C.get(oe);if(ye!==void 0){let jn=A.get(ye)??[];jn.push(W),A.set(ye,jn);return}let ze=l.has(oe)?x:t.parentOf(oe);ze!==null&&ze!==x&&t.listingParents(oe).includes(x)||(C.set(oe,W),!(!h.has(oe)&&!t.showsAsChild(oe))&&B.push(W));});let ne=po(g(x),B.map(W=>R[W]),y);if(!ne)return {positions:B,companions:new Map,repeats:A};let Xe=new Map;for(let[W,oe]of ne.companions)Xe.set(B[W],oe.map(ye=>B[ye]));return {positions:ne.order.map(W=>B[W]),companions:Xe,repeats:A}},S=(x,R)=>m(x,R).positions,L=x=>x.some((R,C)=>C>0&&R<x[C-1]),v=(x,R,C,A)=>{let B=S(x,R),Q=B[C]??R.length,G=k(x,R),F=C>0?B[C-1]:void 0,ne=B[C];if(G&&F!==void 0&&(G.has(R[F])||ne!==void 0&&G.has(R[ne]))){if(G.has(R[F])){let W=I.get(x)??new Map;A.forEach((oe,ye)=>W.set(oe,ye===0?R[F]:A[ye-1])),I.set(x,W);}return F+1}if(!L(B))return Q;let Xe=C>0?B[C-1]+1:0;for(let W of [Q,Xe,R.length]){let oe=[...R.slice(0,W),...A,...R.slice(W)],ye=S(x,oe).map(ze=>oe[ze]);if(A.every((ze,jn)=>ye[C+jn]===ze))return W}return Q},b=x=>{let R=[x],C=new Set;for(;R.length>0;){let A=R.pop();if(C.has(A))continue;C.add(A);let B=u.node(A);if(!(!B||B.isText)){for(let Q of B.children)if(!(l.has(Q)||t.parentOf(Q)!==A)){for(let G of t.listingParents(Q)){if(G===A)continue;let F=u.node(G),ne=F&&!F.isText?F.children.indexOf(Q):-1;ne<0||V({kind:"spliceChildren",parentLogicalId:G,start:ne,deleteCount:1,childLogicalIds:[]});}R.push(Q);}}}},w=(x,R)=>{if(t.parentOf(x)===R)for(let C of t.listingParents(x)){if(C===R||d.get(x)?.has(C))continue;let A=u.node(C);if(!(!A||A.isText))for(let B=A.children.length-1;B>=0;B-=1)A.children[B]===x&&V({kind:"spliceChildren",parentLogicalId:C,start:B,deleteCount:1,childLogicalIds:[]});}},E=new Set,M=x=>{if(E.has(x))return;E.add(x);let R=n(x),C=u.node(x);if(!R||!C||C.isText)return;let A=C.children;if(R.length===A.length&&R.every((Q,G)=>A[G]===Q))return;for(let Q of R)if(!A.includes(Q))for(let G of t.listingParents(Q)){let F=u.node(G),ne=F&&!F.isText?F.children.indexOf(Q):-1;ne<0||G===x||V({kind:"spliceChildren",parentLogicalId:G,start:ne,deleteCount:1,childLogicalIds:[]});}let B=A.filter(Q=>!R.includes(Q));V({kind:"spliceChildren",parentLogicalId:x,start:0,deleteCount:A.length,childLogicalIds:[...R,...B]});},j=new Set,_=x=>{for(let R of st(t).movesAt(x)){if(j.has(R.node))continue;j.add(R.node);let C=u.node(R.from),A=u.node(R.to);if(!C||C.isText||!A||A.isText)continue;let B=C.children.indexOf(R.node);B<0||A.children.includes(R.node)||(V({kind:"spliceChildren",parentLogicalId:R.from,start:B,deleteCount:1,childLogicalIds:[]}),V({kind:"spliceChildren",parentLogicalId:R.to,start:R.first?0:ai(t,A.children),deleteCount:0,childLogicalIds:[R.node]}));}},z=new Set,ee=x=>{if(z.has(x))return;z.add(x);let R=u.node(x);if(!R||R.isText)return;let C=t.adoptedChildren(x).filter(B=>!R.children.includes(B));if(C.length===0)return;for(let B of C)for(let Q of t.listingParents(B)){if(t.replacedByOf(Q)!==x)continue;let G=u.node(Q),F=G&&!G.isText?G.children.indexOf(B):-1;F<0||V({kind:"spliceChildren",parentLogicalId:Q,start:F,deleteCount:1,childLogicalIds:[]});}let A=S(x,R.children).length;V({kind:"spliceChildren",parentLogicalId:x,start:v(x,R.children,A,C),deleteCount:0,childLogicalIds:C});},H=x=>{if(!oi.has(g(x)??""))return [];let R=t.parentOf(x),C=R?u.node(R):null;return !R||!C||C.isText?[]:(m(R,C.children).companions.get(C.children.indexOf(x))??[]).map(B=>C.children[B])},ae=x=>{let R=[];for(let C of H(x)){let A=u.node(C);A&&!A.isText&&R.push(...A.children);}return R},$=new Set,P=x=>{if($.has(x))return;$.add(x);let R=u.node(x);if(!R||R.isText)return;let C=[];for(let A of H(x)){let B=u.node(A);if(!B||B.isText||B.children.length===0)continue;let Q=[...B.children];V({kind:"spliceChildren",parentLogicalId:A,start:0,deleteCount:Q.length,childLogicalIds:[]});for(let G of Q)!R.children.includes(G)&&!C.includes(G)&&C.push(G);}C.length!==0&&V({kind:"spliceChildren",parentLogicalId:x,start:u.node(x).children.length,deleteCount:0,childLogicalIds:C});},te={limits:t.limits,projectedTextValue:x=>u.node(x)?.isText?f.value(x):null,registerSplitText:(x,R,C,A)=>f.register(x,R,C,A),splitTextPending:x=>t.splitTextPending(x),record:x=>{let R=u.node(x);if(!R)return null;if(R.isText)return {logicalId:x,kind:"textValue",value:f.value(x)};let C=h.get(x),A=C?null:t.record(x);return A&&A.kind!=="textValue"?{...A,childIds:R.children}:!C||C.kind==="textValue"?null:{logicalId:x,kind:C.kind,namespaceUri:C.qname.namespaceUri,localName:C.qname.localName,prefix:C.qname.prefix??"",attributes:[],bindings:[],childIds:R.children}}},D=[],T=null,V=x=>{if(T)return;let R=vo(t,x,u);if(R&&!R.ok){T=R;return}D.push(x),Pn(u,x),x.kind==="spliceText"&&f.apply(x);};try{for(let x of i){let R=vo(t,x,p);if(R&&!R.ok)return R;if(Pn(p,x),x.kind==="putNode"&&h.set(x.descriptor.logicalId,x.descriptor),x.kind==="spliceText"){let C=f.range(x.logicalId);V(C?bs({...x,logicalId:C.sourceId,utf16Start:C.start+x.utf16Start},{logicalId:x.logicalId,utf16Start:x.utf16Start}):x);}else if(x.kind==="spliceChildren"){M(x.parentLogicalId),_(x.parentLogicalId),ee(x.parentLogicalId),P(x.parentLogicalId);let C=u.node(x.parentLogicalId);if(!C||C.isText)return {ok:!1,code:"invalid-bound"};let{positions:A,companions:B,repeats:Q}=m(x.parentLogicalId,C.children),G=A.slice(x.start,x.start+x.deleteCount).map(F=>C.children[F]);if(x.deleteCount===0){let F=x.childLogicalIds;V({...x,start:v(x.parentLogicalId,C.children,x.start,F)});}else {let F=A.slice(x.start,x.start+x.deleteCount),ne=F.flatMap(W=>[...B.get(W)??[],...Q.get(W)??[]]);if(ne.length>0||L(A)){let W=[...F,...ne].sort((ye,ze)=>ze-ye);for(let ye of W)V({...x,start:ye,deleteCount:1,childLogicalIds:[]});let oe=u.node(x.parentLogicalId);if(x.childLogicalIds.length>0&&oe&&!oe.isText){let ye=x.childLogicalIds,ze=v(x.parentLogicalId,oe.children,x.start,ye);V({...x,start:ze,deleteCount:0});}F.length=0;}let Xe=F.length;for(;Xe>0;){let W=Xe-1;for(;W>0&&F[W-1]===F[W]-1;)W-=1;V({...x,start:F[W],deleteCount:Xe-W,childLogicalIds:W===0?x.childLogicalIds:[]}),Xe=W;}}if(!T)for(let F of G)w(F,x.parentLogicalId),l.has(F)||b(F);if(!T&&x.childLogicalIds.length>0)for(let F of G){if(l.has(F)&&!h.has(F))continue;let ne=wo(g(F),x.childLogicalIds,g);ne&&on(te,F,ne);}}else if(x.kind==="moveNode"){M(x.destinationParentLogicalId),_(x.destinationParentLogicalId),ee(x.destinationParentLogicalId),P(x.destinationParentLogicalId);let C=u.node(x.destinationParentLogicalId);if(!C||C.isText)return {ok:!1,code:"invalid-bound"};let A=C.children.filter(B=>B!==x.logicalId);V({...x,destinationIndex:v(x.destinationParentLogicalId,A,x.destinationIndex,[x.logicalId])});}else V(x);if(T)return T}return {ok:!0,journal:{effects:D},plan:o.plan}}finally{f.destroy();}}function vd(t,e,n){if(!e.effects.some(a=>{let l=a.kind==="spliceChildren"?a.parentLogicalId:a.kind==="moveNode"?a.destinationParentLogicalId:null;return l!==null&&t.shownPartChildren(l)!==null}))return null;let r=t.current(),i=r.ok?vt(r.issues):null,s=r.ok?i?{code:"materialize-dropped-content",detail:i}:null:{code:r.code};return s?{failure:s,transient:n()}:null}function $i(t,e,n){for(let o of e)n.push(o.id),!(o.kind==="textValue"||t.hasNode(U(o)))&&$i(t,o.children,n);}function Ld(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&&pg(t,o)!==n.rootLogicalId)continue;let s=new Set,a=Ze(o,i,c=>s.has(c)||!t.showsAsChild(c)?null:(s.add(c),Zn(c)),t.limits,t.inline.viewOf(o)),l=[];$i(t,a,l);let d=[];if($i(t,r.children.filter(c=>c.kind==="textValue"||!fg(t,c)),d),l.length!==d.length)return true;for(let c=0;c<l.length;c+=1)if(l[c]!==d[c])return true}return false}function fg(t,e){return e.kind==="paragraphProperties"||t.hasNode(U(e))&&!t.inline.isEmbed(e.id)}function pg(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 an=Symbol("docx-restore-marks");function Rd(t,e){let n=new Map;for(let r of rt(t,e)){if(r.deleted||!(r.content instanceof K.ContentString))continue;let i=r.parent;if(!(i instanceof K.Text)||Be(i)!==se)continue;let s=n.get(i)??new Set;s.add(`${r.id.client}:${r.id.clock}`),n.set(i,s);}if(n.size===0)return;let o=ke(t);t.transact(()=>{for(let[r,i]of n)for(let s=ge(r);s;s=s.right){if(!s.redone)continue;let a=`${s.redone.client}:${s.redone.clock}`;if(!i.has(a))continue;let l=q(t,s.redone);if(!l||l.deleted)continue;let d=nt(r,s,0);o.markCopy("restore",s.redone.client,s.redone.clock,s.length,d),o.origin("move",s.id.client,s.id.clock)!==null&&o.markCopy("move",s.redone.client,s.redone.clock,s.length,d);}},an);}var Wi=new WeakMap,Ki=new WeakMap;function Ed(t,e,n,o=null){if(e.size===0&&!o)return n();Wi.set(t.attributes,e),o&&Ki.set(t.attributes,o);try{return n()}finally{Wi.delete(t.attributes),Ki.delete(t.attributes);}}function hg(t,e){if(!e||t.parentSub===null)return false;let n=t.parent;if(n!==e.attributes&&n!==e.bindings)return false;let o=Wi.get(e.attributes);if(!o)return false;let r=t.parentSub.indexOf(he);return r>0&&o.has(t.parentSub.slice(0,r))}function gg(t){return t.content instanceof K.ContentType}function Cd(t,e){return n=>{let o=n.parent;if(o===null)return true;if(hg(n,e)||e&&Ki.get(e.attributes)?.(n)||o===t)return false;let r=Ee(o);return r===null||r.parent!==t?true:n.parentSub===kt||n.parentSub===Kn?false:!gg(n)}}var mg=Symbol("docx-tombstone-again");function Md(t,e,n){if(t.local||n.undoStack.length===0)return;let o=t.doc,r=new Set;K.iterateDeletedStructs(t,t.deleteSet,s=>{if(!(s instanceof K.Item)||s.parentSub!==ce)return;let a=s.parent;a instanceof K.Map&&a._item?.parent===e&&r.add(a);});let i=[];for(let s of r){if(s.get(ce)!==void 0)continue;let a=yg(s,o.clientID,n);a&&i.push({record:s,step:a});}if(i.length!==0){o.transact(()=>{for(let{record:s}of i)s.set(ce,true);},mg);for(let{record:s,step:a}of i)Pd(a,s);}}function Pd(t,e){let n=e._map.get(ce);if(!n)return;let o=K.createDeleteSet();o.clients.set(n.id.client,[{clock:n.id.clock,len:n.length}]),t.insertions=K.mergeDeleteSets([t.insertions,o]);}function Ad(t,e,n,o,r){let i=new Set,s=e instanceof K.Map?e:null;for(let l of o){let d=s?.get(l);d instanceof K.Map&&!Td(d,t.clientID)&&i.add(d);}for(let l of Ce(n.deletions))for(let d=l.clock;d<l.clock+l.length;){let c=q(t,{client:l.client,clock:d});if(!c)break;if(d=c.id.clock+c.length,c.parentSub!==ce||c.id.client!==t.clientID||!c.deleted||c.redone!==null)continue;let u=c.parent;!(u instanceof K.Map)||u._item?.parent!==e||Td(u,t.clientID)||i.add(u);}if(i.size===0)return;let a=r();for(let l of i)l.set(ce,true),Pd(a,l);}function yg(t,e,n){for(let o=t._map.get(ce)??null;o;o=o.left){if(o.parentSub!==ce||o.id.client!==e||!o.deleted)continue;let r=n.undoStack.find(i=>K.isDeleted(i.insertions,o.id));if(r)return r}return null}function Td(t,e){let n=t._map.get(ce);return !!n&&!n.deleted&&n.id.client===e}function Dd(t,e,n){let o=new Set;for(let r of Ce(n?.insertions))if(r.client===t.clientID)for(let i=r.clock;i<r.clock+r.length;){let s=q(t,{client:r.client,clock:i});if(!s)break;if(i=s.id.clock+s.length,s.parentSub!==ce)continue;let a=s.parent;if(!(a instanceof K.Map)||a._item?.parent!==e)continue;let l=a._item?.parentSub??null;l!==null&&o.add(l);}return [...o]}var To="undoneInto",bg=512;function Nd(t){return Y(t)&&t.get(se)instanceof K.Text}function Yd(t){if(!Y(t)||Me(t))return null;let e=t.get(To);if(typeof e!="string"||e.length>bg)return null;let n=e.startsWith("^"),o=n?e.slice(1):e;return o.length>0?{paragraph:Z(o),atStart:n}:null}function _d(t,e,n){let o=new Map;for(let r of Ce(n?.insertions))for(let i=r.clock;i<r.clock+r.length;){let s=q(t,{client:r.client,clock:i});if(!s)break;i=s.id.clock+s.length;let a=s.parent;if(s.deleted||!(a instanceof K.Array)||Be(a)!==It)continue;let l=Ee(a)?.parent;if(!(l instanceof K.Map)||Ee(l)?.parent!==e)continue;let d=o.get(a)??new Set;for(let c of s.content.getContent())typeof c=="string"&&Nd(e.get(c))&&d.add(Z(c));d.size>0&&o.set(a,d);}return o}function Bd(t,e,n,o){let r=[];for(let[i,s]of _d(t,e,n)){let a=i.toArray(),l=f=>{let p=a[f],h=p===void 0?void 0:e.get(p);return p!==void 0&&Nd(h)&&!Me(h)?p:null},d=[],c=null;a.forEach((f,p)=>{d.push(c),s.has(f)||(c=l(p));});let u=null;for(let f=a.length-1;f>=0;f-=1){let p=a[f];if(!s.has(p)){u=l(f);continue}let h=e.get(p),g=d[f]??(u===null?void 0:`^${u}`);h&&h.get(To)!==g&&r.push({record:h,target:g});}}r.length!==0&&o(()=>{for(let{record:i,target:s}of r)s===void 0?i.delete(To):i.set(To,s);});}function Ig(t,e){let n=e.parent;if(!(n instanceof K.Text)||Be(n)!==se)return null;let o=Ee(n)?.parent;return o instanceof K.Map&&Ee(o)?.parent===t?o:null}function Ud(t,e,n){let o=new Set;for(let d of Ce(n?.deletions))for(let c=d.clock;c<d.clock+d.length;){let u=q(t,{client:d.client,clock:c});if(!u)break;c=u.id.clock+u.length;let f=Ig(e,u);f&&o.add(f);}if(o.size===0||[...o].some(d=>!Me(d)))return null;let r=ke(t),i=d=>r.origin("move",d.id.client,d.id.clock)!==null,s=new Set,a=new Set;for(let d of _d(t,e,n).values())for(let c of d){let u=e.get(c)?.get(se);if(u instanceof K.Text){for(let f=ge(u);f;f=f.right)if(!(f.deleted||!i(f))){s.add(c),a.add(u);break}}}if(s.size===0)return null;let l=new Set([...s].map(d=>e.get(d)));return d=>{let c=d.parent;if(a.has(c))return i(d);if(l.has(c))return true;if(!(c instanceof K.Array)||Be(c)!==It)return false;let u=d.content.getContent();return u.length>0&&u.every(f=>s.has(f))}}var xg=new Set(["comment","footnote","endnote"]),Fd="docx-undone-records";function Sg(t,e,n,o){let r=n?.meta,i=e==="undo"?o.filter(a=>{let l=t.record(a);return Y(t.schema.nodes.get(a))&&!t.isTombstoned(a)&&!!l&&J(l)&&xg.has(l.localName)}):[],s=e==="redo"?r?.get(Fd)??[]:[];e==="undo"&&r?.set(Fd,i),!(i.length===0&&s.length===0)&&t.doc.transact(()=>{for(let a of i)t.schema.nodes.get(a)?.set(St,true);for(let a of s){let l=t.schema.nodes.get(a);Y(l)&&l.has(St)&&l.delete(St);}},an);}var Vi="docx-copy-runs",jd="docx-hidden-copies",$d="docx-copies-only",zd="docx-own-deletes",Ji="docx-undo-group";function Xi(t){t.meta.set(Ji,true);}function Wd(t,e,n){t.normalizeRestoredSplitTextAnchors(),Rd(e,n),e.transact(()=>zl(e,o=>t.schema.nodes.get(o),n),an);}function Kd(t,e,n,o){let r=n==="undo"?e.undoStack:e.redoStack,i=n==="undo"?e.redoStack:e.undoStack,s=r[r.length-1],a=n==="undo"?Eg(t,s):Po(s,Vi)??[],l=i.length,d=n==="undo"?Dd(t.doc,t.schema.nodes,s):Po(s,zd)??[],c=s?.meta.get($d)===true&&Og(s)===0,u=s?.meta.get(Ji)===true;if(c||a.length>0&&Cg(t,s))r.pop();else {let p=r.splice(0,u?r.length-1:Rg(r));try{n==="undo"?(Bd(t.doc,t.schema.nodes,s,h=>t.doc.transact(h,an)),Ed(t.schema,vg(t,s),()=>e.undo(),Ud(t.doc,t.schema.nodes,s))):e.redo();}finally{if(p.length>0){let h=p.concat(r);r.length=0;for(let g of h)r.push(g);}}}let f=i.length>l?i[i.length-1]:void 0;t.doc.transact(()=>{if(o(),n==="redo"&&s&&Ad(t.doc,t.schema.nodes,s,d,()=>(f??=Mo(i),f)),n==="undo"&&d.length>0&&(f??=Mo(i),f.meta.set(zd,d)),n==="redo"){let p=Po(s,jd);p&&p.length>0&&qe(t.doc).withdraw(p);}a.length>0&&(f??=Mo(i),f.meta.set(Vi,a),n==="undo"&&f.meta.set(jd,qe(t.doc).record(a)));},an),u&&(f??=Mo(i),Xi(f)),Sg(t,n,n==="redo"?s:f,t.takeUnlisted()),e.stopCapturing();}function kg(t,e,n,o){let r=[];for(let i=n;i<o;){let s=t.origin("restore",e,i);if(s===null||s.client!==e){let d=s===null?o:Math.min(o,s.firstClock+s.length);r.push({client:e,from:i,to:d}),i=d;continue}let a=Math.min(o,s.firstClock+s.length),l=s.clock+(i-s.firstClock);r.push({client:s.client,from:l,to:l+(a-i)}),i=a;}return r}function wg(t,e,n,o){for(let r=n;r<o;r+=1)if(t.shownCopy(`${e}:${r}`))return true;return false}function vg(t,e){let n=new Set,o=t.schema.nodes;for(let r of Ce(e?.insertions))for(let i=r.clock;i<r.clock+r.length;){let s=q(t.doc,{client:r.client,clock:i});if(!s)break;s.parent===o&&s.parentSub!==null&&n.add(s.parentSub),i=s.id.clock+s.length;}return n}function Lg(t){return !(t.content instanceof K.ContentString)&&!(t.content instanceof K.ContentEmbed)?false:Vd(t)}function Vd(t){return t.content instanceof K.ContentFormat?false:t.parent instanceof K.Text&&t.parent._item?.parentSub===se}function Rg(t){for(let e=t.length-2;e>=0;e-=1)if(t[e].meta.get(Ji)===true)return e+1;return 0}function Og(t){let e=t;return Ce(e.insertions).length+Ce(e.deletions).length}function Eg(t,e){let n=t.inline.follow,o=ke(t.doc),r=(Po(e,Vi)??[]).map(s=>({...s})),i=(s,a,l)=>{let d=r[r.length-1];d&&d.client===s&&d.to===a?d.to=l:r.push({client:s,from:a,to:l});};for(let s of Ce(e?.insertions)){let a=s.clock+s.length;for(let l=s.clock;l<a;){let d=q(t.doc,{client:s.client,clock:l}),c=d?Math.min(d.id.clock+d.length,a):l+1;if(d?.deleted||d&&!o.origin("restore",s.client,l)){let u=kg(o,s.client,l,c);if(!!d&&(d.deleted?Vd(d):Lg(d))||u.some(p=>n.holdsCopyIn(p.client,p.from,p.to)&&wg(n,p.client,p.from,p.to)))for(let p of u)i(p.client,p.from,p.to);}l=c;}}return r}function Cg(t,e){if(!e)return false;let n=new Set(t.trackedTypes()),o=e;for(let[r,i]of [[Ce(o.deletions),true],[Ce(o.insertions),false]])for(let s of r)for(let a=s.clock;a<s.clock+s.length;){let l=q(t.doc,{client:s.client,clock:a});if(!l||Tg(l,n)&&(i||!l.deleted))return false;a=l.id.clock+l.length;}return true}function Tg(t,e){let n=t.parent;for(;n!==null;){if(e.has(n))return true;let o=n._item?.parent;n=o instanceof K.AbstractType?o:null;}return false}function Po(t,e){return t?.meta.get(e)}function Mo(t){let e={meta:new Map([[$d,true]])};return Object.assign(e,{insertions:K.createDeleteSet(),deletions:K.createDeleteSet()}),t.push(e),e}var Ao=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&&Xi(r.stackItem));};e.on("stack-item-added",o),e.on("stack-item-updated",o),n&&Ag(n,e,()=>this.reset());}undoManager;previous;gestureItem;capturing=false;captured=false;pinned;capture(e,n){let o=this.pinned??e,r=this.previous;this.previous=o;let i=this.undoManager.undoStack,s=this.undoManager.captureTimeout;o===r&&o!==void 0&&i[i.length-1]===this.gestureItem?(this.undoManager.lastChange=Date.now(),this.undoManager.captureTimeout=Number.POSITIVE_INFINITY):((o!==r||o!==void 0)&&this.undoManager.stopCapturing(),this.gestureItem=void 0);let a=this.gestureItem;this.captured=false,this.capturing=o!==void 0;try{let l=n();return this.captured&&reportHistoryGroup(e,this.gestureItem===a?"extended":"started"),l}catch(l){throw this.refused(),l}finally{this.capturing=false,this.undoManager.captureTimeout=s;}}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 Ag(t,e,n){let o=new WeakMap,r=i=>{let s=o.get(i);return s||o.set(i,s={}),s};e.on("stack-item-popped",({stackItem:i,type:s})=>{let a=(s==="undo"?e.redoStack:e.undoStack).at(-1);a&&o.set(a,r(i));}),registerUndoHistoryPosition(t,{current:()=>{let i=e.undoStack.at(-1);return i?r(i):null},split:()=>{n(),e.stopCapturing(),e.clear(false,true);}});}function Jd(t,e){let n=ke(t),o=qe(t),r=Rn(t),i=null,s=u=>{if(!e.loading()){if(u==="all"||i==="all"){i="all";return}i??=new Set;for(let f of u)i.add(f);}},a=()=>{let u=i;if(i=null,u===null||e.loading())return;let f=e.inline.marksChanged(u==="all"?e.inline.allTexts():u);f.size>0&&e.changed(f);},l=n.subscribe(s),d=o.subscribe(u=>s(n.textsReading(u))),c=r.subscribe(u=>s(n.textsReading(u)));return t.on("beforeObserverCalls",a),()=>{l(),d(),c(),t.off("beforeObserverCalls",a);}}function Xd(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 Hd(t,e,n){if(e===n)return 0;let o=Xd(t,e),r=Xd(t,n);if(o.root===r.root){let i=Math.min(o.indexes.length,r.indexes.length);for(let s=0;s<i;s+=1){let a=o.indexes[s]-r.indexes[s];if(a!==0)return a}}return e<n?-1:1}var Do=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 Gd(t,e){let n=i=>{let s=new Set,a=false;for(let l of i){let d=l.path;if(d.length===0){for(let c of l.changes.keys.keys())s.add(Z(c));a=true;continue}s.add(Z(d[0])),l.target instanceof K.Array&&(a=true),l.target instanceof K.Map&&(l.changes.keys.has(ce)||l.changes.keys.has(xt))&&(a=true);}(s.size>0||a)&&e({logicalIds:s,membershipChanged:a,packageChanged:false});},o=i=>{let s=new Set;for(let a of i.changes.keys.keys()){let l=gn(String(a))??Ot(String(a));!l||O(l.logicalId)||s.add(l.logicalId);}s.size>0&&e({logicalIds:s,membershipChanged:false,packageChanged:false});},r=()=>{e({logicalIds:new Set,membershipChanged:false,packageChanged:true});};return t.nodes.observeDeep(n),t.attributes.observe(o),t.bindings.observe(o),t.parts.observeDeep(r),t.relationships.observeDeep(r),t.overrides.observe(r),t.defaults.observe(r),t.binaries.observeDeep(r),()=>{t.nodes.unobserveDeep(n),t.attributes.unobserve(o),t.bindings.unobserve(o),t.parts.unobserveDeep(r),t.relationships.unobserveDeep(r),t.overrides.unobserve(r),t.defaults.unobserve(r),t.binaries.unobserveDeep(r);}}function qd(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 Yo(t){return typeof t=="string"?t:""}function Zd(t,e){return t<e?-1:t>e?1:0}function Hi(t,e){return `${t}${he}${e}`}function Ng(t){let e=t.indexOf(he);return e<0?t:t.slice(0,e)}function Qd(t){let e=[];return t.forEach((n,o)=>{!Y(n)||O(o)||n.forEach(r=>{if(!Y(r))return;let i=Yo(r.get("id")),s=Yo(r.get("type"));if(i.length===0||s.length===0)return;let a=Yo(r.get("ownerPart"))||Ng(o);if(O(a))return;let l=r.get("order");e.push({ownerPart:a,id:i,type:s,rawTarget:Yo(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||Zd(n.ownerPart,o.ownerPart)||Zd(n.id,o.id)),e}function ec(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 Yg(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 _g(t,e){let n=t.childrenSnapshot.get(e);return n||(re(t.nodes.get(e))?.toArray()??[])}function Bg(t,e){let n=t.nodes.get(e);return !Y(n)||Me(n)}var Gi=class{constructor(e){this.ctx=e;}ctx;byParent=new Map;indexOf(e,n){let o=this.byParent.get(e);return o||(o=new Map,_g(this.ctx,e).forEach((r,i)=>{o.has(r)||o.set(r,i);}),this.byParent.set(e,o)),o.get(n)??-1}};function Ug(t,e,n,o,r){let i=[],s=new Set,a=r,l;for(;;){if(s.has(a)||(s.add(a),Bg(t,a)))return null;l=n.get(a);let u=t.parentIndex.get(a);if(l!==void 0){if(u!==void 0||o.has(a))return "fallback";break}if(u===void 0)return o.has(a)?"deferred":null;i.push(a),a=u;}let d=[l],c=a;for(let u=i.length-1;u>=0;u-=1){let f=i[u],p=e.indexOf(c,f);if(p<0)return null;d.push(p),c=f;}return d}function Fg(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 Gi(t),i=new Map,s=l=>{let d=i.get(l);if(d!==void 0)return d;let c=Ug(t,r,o,n,l);return c!=="deferred"&&i.set(l,c),c},a=[...n];for(;a.length>0;){let l=[];for(let d of a){let c=null,u=false;for(let f of t.listings.get(d)??[]){if(f===d)continue;let p=s(f);if(p==="fallback")return false;if(p==="deferred"){u=true;continue}if(p===null)continue;let h=r.indexOf(f,d);if(h<0)continue;let g=[...p,h];(!c||Yg(g,c.rank)<0)&&(c={rank:g,parent:f});}if(u){l.push(d);continue}c&&t.parentIndex.set(d,c.parent),n.delete(d);}if(l.length===a.length)return false;a=l;}return true}function qi(t,e){let{nodes:n,parentIndex:o,childrenSnapshot:r,partRoots:i}=t;if(e)for(let s of e)o.delete(s);for(let s of i){let a=new Set,l=[{id:s,parent:null,exit:false}];for(;l.length>0;){let d=l.pop();if(d.exit){a.delete(d.id);continue}let c=d.id;if(d.parent!==null&&(e===null||e.has(c))&&(o.has(c)||o.set(c,d.parent)),a.has(c))continue;let u=n.get(c);if(!Y(u)||Me(u))continue;let f=r.get(c)??re(u)?.toArray()??[];a.add(c),l.push({id:c,parent:null,exit:true});let p=new Set,h=[];for(let g of f)p.has(g)||g===c||(p.add(g),h.push(g));for(let g=h.length-1;g>=0;g-=1)l.push({id:h[g],parent:c,exit:false});}}}function tc(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&&(Fg(t,n)||qi(t,new Set(n)));}function nc(t,e){return `${t}${he}${e}`}function Zi(t,e,n,o,r){if(O(n)||O(o.localName))return;let i=jt(t.namespaces,o.namespaceUri,e),s=vr(n,i,o.localName);O(s)||t.attributes.set(s,_s(o.prefix??"",r));}function oc(t,e,n,o){t.attributes.delete(vr(e,Lt(n),o));}function Qi(t,e,n,o,r){if(O(n)||O(o))return;let i=jt(t.namespaces,r,e),s=Lr(n,o);O(s)||t.bindings.set(s,i);}function rc(t,e,n){t.bindings.delete(Lr(e,n));}function ic(t,e,n,o,r,i){let{prefix:s,value:a}=Bs(i),l=e.get(n);l||(l=new Map,e.set(n,l)),l.set(nc(o,r),{namespaceUri:Rt(t.namespaces,o),localName:r,prefix:s.length>0?s:void 0,value:a});}function jg(t,e,n,o){let r=t.get(e);r&&(r.delete(nc(n,o)),r.size===0&&t.delete(e));}function sc(t,e,n,o,r){let i=e.get(n);i||(i=new Map,e.set(n,i)),i.set(o,{prefix:o,namespaceUri:Rt(t.namespaces,r)});}function zg(t,e,n){let o=t.get(e);o&&(o.delete(n),o.size===0&&t.delete(e));}function ac(t,e,n){for(let[o,r]of n.changes.keys){let i=gn(String(o));if(!i||O(i.logicalId)||O(i.localName))continue;if(r.action==="delete"){jg(e,i.logicalId,i.namespaceId,i.localName);continue}let s=t.attributes.get(String(o));typeof s=="string"&&ic(t,e,i.logicalId,i.namespaceId,i.localName,s);}}function lc(t,e,n){for(let[o,r]of n.changes.keys){let i=Ot(String(o));if(!i||O(i.logicalId)||O(i.prefix))continue;if(r.action==="delete"){zg(e,i.logicalId,i.prefix);continue}let s=t.bindings.get(String(o));typeof s=="string"&&sc(t,e,i.logicalId,i.prefix,s);}}function dc(t,e,n){t.attributes.forEach((o,r)=>{if(typeof o!="string"||O(r))return;let i=gn(r);!i||O(i.logicalId)||O(i.localName)||ic(t,e,i.logicalId,i.namespaceId,i.localName,o);}),t.bindings.forEach((o,r)=>{if(typeof o!="string"||O(r))return;let i=Ot(r);!i||O(i.logicalId)||O(i.prefix)||sc(t,n,i.logicalId,i.prefix,o);});}function es(t,e,n){let o=t.listings.get(e)??new Set;o.add(n),t.listings.set(e,o);}function $g(t,e,n){let o=t.listings.get(e);o&&(o.delete(n),o.size===0&&t.listings.delete(e));}function cc(t,e,n){let o=t.childrenSnapshot.get(e)??[];if(Gn(o,n))return [];let r=new Set(n),i=new Set(o),s=[];for(let a of o)r.has(a)||($g(t,a,e),s.push(a));for(let a of n)i.has(a)||(es(t,a,e),s.push(a));return t.childrenSnapshot.set(e,n),s}function uc(t,e){if(!t||e.length===0)return;let n=new Map;for(let o of e)n.set(o,(n.get(o)??0)+1);for(let o=t.length-1;o>=0;o-=1){let r=t.get(o),i=n.get(r)??0;i!==0&&(n.set(r,i-1),t.delete(o,1));}}var Wg=1024,_o=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=Hn(o);if(n!==void 0&&n!==r&&this.recompute(n),r!==null){if(Me(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<Wg;)n.add(o),this.recomputeOne(o),o=this.survivorOf.get(o);}recomputeOne(e){let n=[],o=new Set,r=Js(this.nodes,this.sources.get(e));for(let i of r){let s=this.nodes.get(i);if(!s)continue;let a=re(s)?.toArray()??[];for(let l of [...a,...this.adoptees.get(i)??[]])o.has(l)||this.reads.isTombstoned(l)||!this.nodes.has(l)||this.isContentWitness(l)&&(o.add(l),n.push(l));}n.length>0?this.adoptees.set(e,n):this.adoptees.delete(e);}};function Nt(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 Kg=/^\d{10}$/,ts=class extends Set{heap=[];add(e){return this.has(e)||(super.add(e),this.heap&&this.push(e)),this}first(){let e=this.heap;for(;e.length>0&&!this.has(e[0]);)this.pop();return e[0]}push(e){let n=this.heap;n.push(e);for(let o=n.length-1;o>0;){let r=o-1>>1;if(n[r]<=n[o])break;[n[r],n[o]]=[n[o],n[r]],o=r;}}pop(){let e=this.heap,n=e.pop();if(e.length!==0){e[0]=n;for(let o=0;;){let r=2*o+1,i=r+1,s=o;if(r<e.length&&e[r]<e[s]&&(s=r),i<e.length&&e[i]<e[s]&&(s=i),s===o)break;[e[s],e[o]]=[e[o],e[s]],o=s;}}}};function ln(t){return t.first()}function Vg(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 Bo=class{constructor(e,n,o,r,i=()=>{}){this.nodes=e;this.limits=n;this.isDeleted=o;this.textChanged=i;this.follow=new ko(s=>this.textOf(s),o,r,s=>this.noteOthers(s),s=>this.paragraphHolding(s),s=>Yd(this.nodes.get(s)));}nodes;limits;isDeleted;textChanged;holders=new Map;idsOf=new Map;embeds=new Set;affected=new Set;built=false;drift=false;follow;paragraphHolding(e){let n=we(e),o=this.nodes.doc;if(!o||!n)return null;let{client:r,clock:i}=n,s=q(o,{client:r,clock:i})?.parent;if(!(s instanceof K.Text)||Be(s)!==se)return null;let a=Ee(s)?.parent,l=a instanceof K.Map?Be(a):null;if(l===null||O(l))return null;let d=Z(l);return this.textOf(d)===s?d:null}isDeletedParagraph(e){return this.isDeleted(e)}textOf(e){let n=this.nodes.get(e);if(!Y(n))return null;let o=n.get(se);return o instanceof K.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(Nt(d)===o)return d;for(let d of i)for(let c of this.follow.targetsFor(d))if(Nt(c)===o)return c;let l=this.paragraphTagged(o);if(l)return l}return ln(i)}if(n!==e&&this.textOf(n))return n;let s=n.lastIndexOf("~");if(s<0)return null;let a=n.slice(s+1);o===null&&Kg.test(a)&&(o=a),n=n.slice(0,s);}return null}paragraphTagged(e){for(let o of this.idsOf.keys())if(Nt(o)===e)return o;let n=null;return this.nodes.forEach((o,r)=>{n===null&&Nt(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}~${Nt(e)}`;let o=this.holders.get(n);return o&&!o.has(e)?`${n}~${Nt(e)}`:!o||o.size<2||ln(o)===e?n:`${n}~${Nt(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||ln(o)===e},shown:n=>this.follow.shown(e,n),textOf:n=>this.textOf(n),lineageOf:n=>ol(this.nodes.get(n)),listed:n=>!this.isDeleted(n)}}sharesIds(e){this.ensureBuilt();for(let n of this.idsOf.get(e)??[])if((this.holders.get(n)?.size??0)>1||!this.embeds.has(n)&&this.nodes.has(n))return true;return false}isEmbed(e){return this.ensureBuilt(),this.embeds.has(e)}noteDrift(){this.drift=true;}takeDrift(){this.follow.settle();let e=this.drift||this.affected.size>0;return this.drift=false,e}takeAffected(){if(this.follow.settle(),this.affected.size===0)return new Set;let e=new Set(this.affected);return this.affected.clear(),e}allTexts(){let e=new Set;return this.nodes.forEach((n,o)=>{let r=this.textOf(o);r&&e.add(r);}),e}marksChanged(e){let n=new Set;if(!this.built)return n;for(let o of e){if(Be(o)!==se)continue;let r=Ee(o)?.parent,i=r instanceof K.Map?Be(r):null;if(i===null||O(i))continue;let s=Z(i);this.textOf(s)===o&&(this.follow.invalidate(s),this.paragraphChanged(s),n.add(s));}return n}paragraphChanged(e){if(this.textChanged(e),!this.built)return;let n=this.idsOf.get(e)??new Set,o=new Set,r=new Set,i=this.textOf(e);if(i)for(let s of i.toDelta()){if(typeof s.insert=="object"&&s.insert!==null){let a=s.insert.n;typeof a=="string"&&(o.add(a),r.add(a));}for(let a of Vg(Ae(s.attributes,this.limits,e)))o.add(a);}for(let s of n)o.has(s)||this.release(s,e);for(let s of o)n.has(s)||this.hold(s,e);for(let s of r)this.embeds.add(s);o.size>0?this.idsOf.set(e,o):this.idsOf.delete(e),this.noteOthers(this.follow.paragraphChanged(e));}noteOthers(e){for(let n of e)this.affected.add(n);e.size>0&&this.noteDrift();}orderChanged(){if(this.built)for(let e of this.follow.orderChanged())this.affected.add(e);}recordArrived(e){if(this.built)for(let n of this.holders.get(e)??[])this.holderAffected(n);}holderAffected(e){this.affected.add(e);for(let n of this.follow.placedTargetsFor(e))this.affected.add(n);}listingChanged(e){if(this.built){for(let n of this.holders.get(e)??[])this.holderAffected(n);this.textOf(e)&&(this.noteOthers(this.follow.paragraphChanged(e)),this.affected.add(e));}}hold(e,n){let o=this.holders.get(e);if(o||(o=new ts,this.holders.set(e,o)),o.size>0){let i=ln(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=ln(o)===n;if(o.delete(n),o.size===0){this.holders.delete(e),this.embeds.delete(e);return}r&&this.affected.add(ln(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)=>{Y(e)&&e.get(se)instanceof K.Text&&this.paragraphChanged(Z(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 dn(t){return typeof t=="string"?t:""}function fc(t){let e=[];return t.forEach((n,o)=>{if(!Y(n)||O(o))return;let r=dn(n.get("rootId"));r.length!==0&&e.push({name:o,id:dn(n.get("id")),rootLogicalId:r,contentType:dn(n.get("contentType"))});}),e.sort((n,o)=>n.name<o.name?-1:n.name>o.name?1:0),e}function pc(t){let e=new Map;return t.forEach((n,o)=>{typeof n=="string"&&!O(o)&&e.set(partNameKey(o),n);}),e}function hc(t){let e=new Map;return t.forEach((n,o)=>{typeof n=="string"&&!O(o)&&e.set(o,n);}),e}function gc(t){let e=[];return t.forEach((n,o)=>{if(!Y(n)||O(o))return;let r=dn(n.get("digest")),i=n.get("size"),s=dn(n.get("mediaType")),a=dn(n.get("storageKey"))||o;r.length===0||typeof i!="number"||e.push({digest:r,size:i,mediaType:s,storageKey:a});}),e}var ns="/word/numbering.xml",Xg="http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering";function mc(t,e){let n=e.parent;if(n===t.bindings&&e.parentSub){let a=Ot(e.parentSub),l=a&&t.nodes.get(a.logicalId);if(l){let d=He(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===ns||n===t.parts&&e.parentSub===ns)return true;let o=Ee(n);if(o?.parent===t.parts&&o.parentSub===ns)return true;let r=a=>a instanceof K.Map&&a.get("type")===Xg,i=a=>a instanceof K.Map&&[...a.values()].some(r);return n===t.relationships?e.content.getContent().some(i):o?.parent===t.relationships?e.content.getContent().some(r):Ee(o?.parent)?.parent===t.relationships&&r(n)}var ot=class{constructor(e,n){this.doc=e;this.stopKeepingMarkers=Is(e),this.schema=Ns(e),this.limits=Ts(n),this.splitDedup=new Ro(this.schema.nodes),this.inline=new Bo(this.schema.nodes,this.limits,o=>this.isTombstoned(o)||!this.parentIndex.has(o),(o,r)=>Hd({parentOf:i=>this.parentIndex.get(i),childrenOf:i=>this.splitSiblings.shownChildren(i),maxDepth:this.limits.maxTreeDepth},o,r),o=>this.splitSiblings.textChanged(o)),this.adoption=new _o(this.schema.nodes,{kindOf:o=>this.kindOf(o),isTombstoned:o=>this.isTombstoned(o),listersOf:o=>this.listings.get(o)??[]}),this.splitTextSources=new rn(this.schema.nodes,this.doc,this.limits),this.stopMarks=Jd(e,{inline:this.inline,loading:()=>this.bulkLoad>0,changed:o=>{for(let r of this.markListeners)r(o);}}),this.stopObserving=ec(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 Do;contested=new Set;structureVersion=0;reparented=new Set;listings=new Map;childrenSnapshot=new Map;adoption;inline;splitSiblings=new Eo(e=>this.schema.nodes.get(e),e=>this.inline.textOf(e),e=>this.childrenSnapshot.get(e));stopMarks;stopKeepingMarkers;markListeners=new Set;attributesByNode=new Map;bindingsByNode=new Map;splitDedup;splitTextSources;bulkLoad=0;unobservedWrites=0;nodeCountCache=-1;pendingNodeAdds=0;relationshipCountCache=-1;partCountCache=-1;stopObserving;destroy(){this.stopObserving(),this.stopMarks(),this.stopKeepingMarkers();}beginBulkLoad(){this.bulkLoad+=1;}endBulkLoad(){this.bulkLoad=Math.max(0,this.bulkLoad-1),this.bulkLoad===0&&this.rebuildDerivedIndexes();}trackedTypes(){return [this.schema.meta,this.schema.nodes,this.schema.parts,this.schema.relationships,this.schema.overrides,this.schema.defaults,this.schema.binaries,this.schema.attributes,this.schema.bindings,this.doc.getMap(Xr),this.doc.getMap(qr)]}undoDeleteFilter(){let e=Cd(this.schema.nodes,this.schema);return n=>!mc(this.schema,n)&&e(n)}encodeSnapshot(){return K.encodeStateAsUpdate(this.doc)}encodeUpdate(e){return K.encodeStateAsUpdate(this.doc,e)}partEntries(){return fc(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 Qs(this.schema.meta.get("mainDocumentPart"))}record(e){if(O(e))return null;let n=this.schema.nodes.get(e);if(!Y(n))return null;if($t(n)){let o=n.get(Te),r=o instanceof K.Text?o.toString():"";return {logicalId:e,kind:"textValue",value:r}}return qs(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:Zs(n),wordFacingIds:Es(r)}}isTombstoned(e){return Me(this.schema.nodes.get(e))}replacedByOf(e){return Hn(this.schema.nodes.get(e))}adoptedChildren(e){return this.adoption.adoptees.get(e)??[]}adoptionIndex(){return this.adoption.adoptees}hasNamespace(e){return this.schema.namespaces.get(Lt(e))===e}noteWrite(){this.unobservedWrites+=1;}hasUnobservedWrites(){return this.unobservedWrites>0}listingParents(e){return [...this.listings.get(e)??[]]}allLogicalIds(){return [...this.schema.nodes.keys()].filter(Tr)}nodeCount(){return this.nodeCountCache<0&&(this.nodeCountCache=this.schema.nodes.size),this.nodeCountCache+this.pendingNodeAdds}nodeShape(e){return O(e)?null:Hs(this.schema.nodes,e)}kindOf(e){return O(e)?null:Gs(this.schema.nodes,e)}noteNodeWrite(e){this.schema.nodes.has(e)||(this.pendingNodeAdds+=1);}putElement(e){this.noteNodeWrite(e.logicalId);let n=jt(this.schema.namespaces,e.namespaceUri,this.limits.maxStringLength);this.schema.nodes.set(e.logicalId,Us({logicalId:e.logicalId,kind:e.kind,namespaceUri:e.namespaceUri,namespaceId:n,localName:e.localName,prefix:e.prefix}));for(let o of e.attributes)Zi(this.schema,this.limits.maxStringLength,e.logicalId,o,o.value);for(let o of e.bindings)Qi(this.schema,this.limits.maxStringLength,e.logicalId,o.prefix,o.namespaceUri);}updateElementShell(e,n){let o=this.require(e),r=jt(this.schema.namespaces,n.namespaceUri,this.limits.maxStringLength);o.set(Wn,wr(n.kind,r,n.localName,n.prefix??""));}putText(e,n){this.noteNodeWrite(e),this.schema.nodes.set(e,Vn(n));}spliceText(e,n,o,r){let i=this.splitTextSources.range(e),s=Lo(this.schema.nodes,this.splitTextSources,e,i,n,r),a=i?.text??this.textOf(e),l=(i?.start??0)+n;i===null&&this.splitTextSources.isPlain(e)?(r.length>0&&a.insert(l,r),o>0&&a.delete(l+r.length,o)):(o>0&&a.delete(l,o),r.length>0&&a.insert(l,r)),s?.();}setAttribute(e,n,o){if(o===null){oc(this.schema,e,n.namespaceUri,n.localName);return}Zi(this.schema,this.limits.maxStringLength,e,n,o);}setNamespaceBinding(e,n,o){if(o===null){rc(this.schema,e,n);return}Qi(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(ce,true),n&&o.set(xt,n);}recordRunSplit(e,n,o){this.splitDedup.record(e,n,o);}splitOriginOf(e){return mn(this.schema.nodes.get(e))}splitLineageOf(e){return Et(this.schema.nodes.get(e))}replacementLoserRuns(){return this.hasUnobservedWrites()&&this.splitDedup.invalidate(),this.splitDedup.loserRuns({isPresent:e=>qd(this,e)})}splitTextRange(e){return this.splitTextSources.range(e)}splitTextPending(e){return this.splitTextSources.isPending(e)}projectedTextValue(e){return this.splitTextSources.value(e)}registerSplitText(e,n,o,r){this.splitTextSources.register(e,n,o,r);}normalizeRestoredSplitTextAnchors(){this.splitTextSources.normalizeRestoredAnchors();}concurrentSplitTextOverlays(){return this.splitTextSources.overlays()}unlistChildren(e,n){let o=this.schema.nodes.get(e);uc(o?re(o):null,n);}putXmlPart(e){this.partCountCache=-1,this.schema.parts.set(e.name,Fs(e.id,e.rootLogicalId,e.contentType));}deleteXmlPart(e){this.partCountCache=-1,this.schema.parts.delete(e);}putRelationship(e){if(O(e.ownerPart)||O(e.id))return;this.relationshipCountCache=-1;let n=new K.Map;n.set(e.id,js(e)),this.schema.relationships.set(Hi(e.ownerPart,e.id),n);}deleteRelationship(e,n){this.relationshipCountCache=-1,this.schema.relationships.delete(Hi(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,zs(e));}deleteBinary(e){this.schema.binaries.delete(e);}relationships(){return Qd(this.schema.relationships)}contentTypeOverrides(){return pc(this.schema.overrides)}contentTypeDefaults(){return hc(this.schema.defaults)}binaries(){return gc(this.schema.binaries)}hasNode(e){return this.schema.nodes.has(e)}showsAsChild(e){let n=this.schema.nodes.get(e);return n===void 0||Me(n)?false:!($t(n)&&this.splitTextPending(e))}observeDirty(e){let n=Gd(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(!Tr(o))return;let r=re(n);if(!r)return;let i=r.toArray();this.childrenSnapshot.set(o,i);for(let s of i)es(this.listingIndex(),s,o);}),this.schema.nodes.forEach((n,o)=>{Me(n)&&this.adoption.sync(Z(o)),this.splitDedup.indexExisting(Z(o));}),dc(this.schema,this.attributesByNode,this.bindingsByNode),qi(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(){ea(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 K.Text)&&(r.path.length===0||r.target instanceof K.Array||r.target instanceof K.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(Z(r.path[0])),r.target instanceof K.Text&&r.path[1]===se){this.inline.paragraphChanged(Z(r.path[0]));continue}if(r.target instanceof K.Map&&r.path.length===1&&(r.changes.keys.has(se)||r.changes.keys.has(ce))&&this.inline.paragraphChanged(Z(r.path[0])),r.path.length===0&&r.target instanceof K.Map){o=true;for(let[i,s]of r.changes.keys)if(this.nodeCountCache>=0&&s.action!=="update"&&(this.nodeCountCache+=s.action==="add"?1:-1),!O(String(i))){if(s.action==="delete"){this.inline.paragraphChanged(Z(i));continue}this.splitDedup.indexExisting(Z(i)),this.splitTextSources.noteChanged(Z(i));for(let a of this.syncChildListings(Z(i)))n.add(a);this.inline.paragraphChanged(Z(i)),this.inline.recordArrived(Z(i)),this.isTombstoned(Z(i))&&this.adoption.sync(Z(i)),this.adoption.recomputeListerSurvivors(Z(i));}continue}if(r.target instanceof K.Map&&r.path.length===1){let i=Z(r.path[0]),s=r.changes.keys;if(s.has(St)&&this.history.noteMarkChanged(i),(s.has("splitFrom")||s.has("splitLineage"))&&this.splitDedup.indexExisting(i),s.has(dt))for(let a of this.listings.get(i)??[])this.splitSiblings.forget(a);}if(r.target instanceof K.Array&&r.path.length>0){o=true;let i=Z(r.path[0]);for(let s of this.syncChildListings(i,true))n.add(s);this.isTombstoned(i)&&this.adoption.sync(i);continue}if(r.target instanceof K.Map&&r.path.length===1&&(r.changes.keys.has(ce)||r.changes.keys.has(xt))){o=true;let i=Z(r.path[0]);this.adoption.sync(i),this.adoption.recomputeListerSurvivors(i);for(let s of this.childrenSnapshot.get(i)??[])n.add(s);}}if(o)for(let r of this.contested)n.add(r);n.size>0&&this.resolveParents(n),o&&(this.structureVersion+=1,this.inline.orderChanged());}takeUnlisted(){return this.history.takeUnlisted(e=>this.parentIndex.has(e))}takeReparented(){let e=[...this.reparented];return this.reparented.clear(),e}applyAttributeMapEvent(e){this.unobservedWrites=0,ac(this.schema,this.attributesByNode,e);}applyBindingMapEvent(e){this.unobservedWrites=0,lc(this.schema,this.bindingsByNode,e);}syncChildListings(e,n=false){n&&this.splitSiblings.forget(e);let o=this.schema.nodes.get(e),r=o?re(o)?.toArray()??[]:[];return cc(this.listingIndex(),e,r)}listingIndex(){return {listings:this.listings,childrenSnapshot:this.childrenSnapshot}}resolveParents(e){let n=new Map;for(let o of e)n.set(o,this.parentIndex.get(o));this.placeParents(e);for(let[o,r]of n){(this.listings.get(o)?.size??0)>1?this.contested.add(o):this.contested.delete(o);let i=this.parentIndex.get(o);i!==r&&(i===void 0!=(r===void 0)&&(this.inline.listingChanged(o),i===void 0&&this.history.noteUnlisted(o)),r!==void 0&&this.reparented.add(r),i!==void 0&&this.reparented.add(i));}}placeParents(e){tc(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=re(o);r&&this.removeFromArray(r,e);});return}for(let o of n){let r=this.schema.nodes.get(o),i=r?re(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(Te);if(!(n instanceof K.Text))throw new Error(`no text at ${e}`);return n}childArray(e){let n=this.require(e).get(It);if(!(n instanceof K.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 Uo=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 Hg(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 bc(t){let e=t.binaryPart;return typeof e=="function"?e:null}function Ic(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 xc(t,e){for(let n of e)t.put(n.digest,n.bytes);}function qg(t){return t.attributes.map(e=>({namespaceUri:e.namespaceUri,localName:e.localName,prefix:e.prefix,value:e.value}))}function Zg(t){return t.namespaceBindings.map(e=>({prefix:e.prefix,namespaceUri:e.namespaceUri}))}function Fo(t,e,n,o,r){if(o>t.limits.maxTreeDepth)return "tree-too-deep";if(O(e.id))return "prototype-key";if(r.nodes+=1,r.nodes>t.limits.maxNodes)return "too-many-nodes";if(e.kind==="textValue"){if(e.value.length>t.limits.maxTextLength)return "text-too-long";t.putText(U(e),e.value);}else {if(e.attributes.length>t.limits.maxAttributes)return "too-many-attributes";if(e.children.length>t.limits.maxChildren)return "too-many-children";if(ve(e.namespaceUri,t.limits.maxStringLength))return "invalid-string";for(let i of e.attributes){if(O(i.localName))return "prototype-key";if(ve(i.namespaceUri,t.limits.maxStringLength))return "invalid-string"}for(let i of e.namespaceBindings){if(O(i.prefix))return "prototype-key";if(ve(i.namespaceUri,t.limits.maxStringLength))return "invalid-string"}if(t.putElement({logicalId:U(e),kind:e.kind,namespaceUri:e.namespaceUri,localName:e.localName,prefix:e.prefix,attributes:qg(e),bindings:Zg(e)}),e.kind==="paragraph"){let i=Qg(t,e,o,r);if(i)return i}else for(let i of e.children){let s=Fo(t,i,U(e),o+1,r);if(s)return s}}return n&&t.childArray(n).push([U(e)]),null}function Qg(t,e,n,o){let r=yn(e);for(let a of r.shell.children){let l=Fo(t,a,U(e),n+1,o);if(l)return l}let i=0;for(let a of r.items){if(i+=1,a.kind!=="embed")continue;let l=Fo(t,a.node,null,n+1,o);if(l)return l}if(i>t.limits.maxTextLength)return "text-too-long";let s=t.schema.nodes.get(e.id);if(!s)return null;try{fo(s,ka(r.items,e.id,t.limits));}catch(a){if(a instanceof Ye)return a.code;throw a}return null}async function em(t){let e=[],n=[];for(let[o,r]of t.partBytes){if(t.parts.has(o))continue;let s=t.contentTypes.overrides.get(o)??"application/octet-stream",a=me(o);if(a)return {ok:false,code:a};if(r.byteLength>yt.maxBlobBytes)return {ok:false,code:"blob-too-large"};let l=await Hg(r);n.push({digest:l,bytes:r}),e.push({digest:l,size:r.byteLength,mediaType:s,storageKey:o});}return {ok:true,descriptors:e,payloads:n}}async function jo(t,e,n=new Uo){if(e.parts.size>t.limits.maxParts)return {ok:false,code:"too-many-parts"};let o=await em(e);if(!o.ok)return o;let r=null;t.beginBulkLoad();try{t.doc.transact(()=>{for(let a of o.payloads)n.put(a.digest,a.bytes);let i={nodes:0};for(let[a,l]of e.parts){let d=me(a);if(d){r=d;return}if(ve(l.contentType,t.limits.maxMediaTypeLength)){r="invalid-string";return}let c=Fo(t,l.root,null,0,i);if(c){r=c;return}t.putXmlPart({name:a,id:l.id,rootLogicalId:U(l.root),contentType:l.contentType});}let s=0;for(let a of e.relationships.values())for(let l of a){if(s+=1,s>t.limits.maxRelationships){r="too-many-relationships";return}if(l.ownerPart!=="/"){let d=me(l.ownerPart);if(d){r=d;return}}if(O(l.id)){r="prototype-key";return}t.putRelationship({ownerPart:l.ownerPart,id:l.id,type:l.type,rawTarget:l.rawTarget,targetMode:l.targetMode,order:l.order});}for(let[a,l]of e.contentTypes.defaults){if(O(a)){r="prototype-key";return}t.putContentTypeDefault(a,l);}for(let[a,l]of e.contentTypes.overrides){let d=me(a);if(d){r=d;return}t.putContentTypeOverride(a,l);}for(let a of o.descriptors)t.putBinary(a);$s(t.schema.meta),t.schema.meta.set("mainDocumentPart",e.mainDocumentPart);},Ds);}finally{t.endBulkLoad();}return r?{ok:false,code:r}:{ok:true}}function _e(t,e){return t.attributes.find(n=>n.localName===e)?.value}function rs(t){return t.kind==="textValue"?t.id:_e(t,"id")??t.id}function Yn(t,e){if(t.length===e.length&&t.every((s,a)=>s===e[a]))return t;let n=0,o=Math.min(t.length,e.length);for(;n<o&&t[n]===e[n];)n+=1;let r=t.length,i=e.length;for(;r>n&&i>n&&t[r-1]===e[i-1];)r-=1,i-=1;return Object.freeze([...t.slice(0,n),...e.slice(n,i),...t.slice(r)])}function wc(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(Ge(n,Yn(n.children,e)));return Object.freeze({...t,root:o})}function tm(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 Rc(t){}function Ec(t,e){return Object.freeze({id:t,kind:"textValue",value:e})}function am(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 lm(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 zo(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&&am(o,t)?o.namespaceBindings:Object.freeze(t.bindings.map(r=>Object.freeze({...r}))),attributes:o&&lm(o,t)?o.attributes:Object.freeze(t.attributes.map(tm)),children:e}))}function Cc(t,e){if(t.attributes.length!==e.attributes.length)return false;let n=new Map(e.attributes.map(o=>[`${o.namespaceUri}
|
|
9
|
+
${o.localName}`,o.value]));for(let o of t.attributes)if(n.get(`${o.namespaceUri}
|
|
10
|
+
${o.localName}`)!==o.value)return false;return t.localName===e.localName&&t.kind===e.kind}function is(t,e){let n=e.size;e.add(U(t));let o=e.size!==n;if(t.kind==="textValue")return o;for(let r of t.children)is(r,e)||(o=false);return o}function Tc(t,e){let n=new Set(e),o=[...e],r=i=>{n.has(i)||(n.add(i),o.push(i));};for(;o.length>0;){let i=o.pop(),s=t.isTombstoned(i)?t.replacedByOf(i):null;s!==null&&r(s);let a=t.listingParents(i),l=t.parentOf(i);for(let d of l===null?a:[l,...a]){r(d);let c=t.isTombstoned(d)?t.replacedByOf(d):null;c!==null&&r(c);}}return n}var Wo="http://schemas.openxmlformats.org/package/2006/relationships",dm="application/vnd.openxmlformats-package.relationships+xml",Mc=/^(.*)\/_rels\/([^/]*)\.rels$/;function Ko(t){return Mc.test(t)}function Pc(t){let e=Mc.exec(t);return e?e[2]===""?"/":`${e[1]}/${e[2]}`:null}function $o(t,e){return Object.freeze({kind:"genericExtension",namespaceUri:"",localName:t,value:e})}function cm(t,e){let n=[$o("Id",e.id),$o("Type",e.type),$o("Target",e.rawTarget)];return e.targetMode==="External"&&n.push($o("TargetMode","External")),Object.freeze(Pe({id:t,kind:"generic",namespaceUri:Wo,localName:"Relationship",namespaceBindings:Object.freeze([]),attributes:Object.freeze(n),children:Object.freeze([])}))}function Ac(t,e){if(t.kind==="textValue"||t.namespaceUri!==Wo||t.localName!=="Relationship"||_e(t,"Id")!==e.id||_e(t,"Type")!==e.type||_e(t,"Target")!==e.rawTarget)return false;let n=_e(t,"TargetMode");return e.targetMode==="External"?n==="External":n===void 0}function Dc(t,e){return t.children.length!==e.length?false:t.children.every((n,o)=>Ac(n,e[o]))}function Nc(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 Yc(t,e,n){let o=[];for(let r of e){if(O(r.id))continue;let i=t.find(a=>a.kind!=="textValue"&&_e(a,"Id")===r.id);if(i&&Ac(i,r)){o.push(i);continue}let s=i&&i.kind!=="textValue"?U(i):`${n}#rel-${r.id}`;O(s)||o.push(cm(s,r));}return o}function um(t){return Object.freeze(Pe({id:`${t}#root`,kind:"generic",namespaceUri:Wo,localName:"Relationships",namespaceBindings:Object.freeze([Object.freeze({prefix:"",namespaceUri:Wo})]),attributes:Object.freeze([]),children:Object.freeze([])}))}function _c(t){return Object.freeze({id:t,name:t,contentType:dm,root:um(t)})}function Bc(t){let e=new Map;for(let n of t){if(O(n.id)||n.ownerPart!=="/"&&me(n.ownerPart))continue;let o=e.get(n.ownerPart)??[];o.push(n),e.set(n.ownerPart,o);}return e}var zc=/^\/customXml\/item(\d+)\.xml$/i,gm=/^\/customXml\/itemProps(\d+)\.xml$/i;function Bn(t){return zc.test(t)}function as(t){return gm.test(t)}function mm(t){let e=zc.exec(t);if(!e)return null;let n=Number(e[1]);return Number.isSafeInteger(n)&&n>0?n:null}function Uc(t){return {item:`/customXml/item${String(t)}.xml`,props:`/customXml/itemProps${String(t)}.xml`}}function ym(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 Fc(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 bm(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 s=t.record(i);if(!s||!J(s)||s.localName!=="schemaRef")continue;let a=ym(s,"uri",DATASTORE_NAMESPACE_URI);if(a)return a}}return null}function Im(t,e){return e.childIds.some(n=>{let o=t.record(n);return !!o&&J(o)&&o.localName==="node"&&o.namespaceUri===e.namespaceUri})}function xm(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:Im(t,e)}function Sm(t,e){return e.localName!=="datastoreItem"||e.namespaceUri!==DATASTORE_NAMESPACE_URI?false:t.parentOf(e.logicalId)===null}function $c(t,e){if(!t.hasNamespace(DATASTORE_NAMESPACE_URI))return [];let n=new Map,o=new Map;for(let[f,p]of e){let h=t.record(U(p.root));!h||!J(h)||(Bn(f)&&n.set(h.logicalId,h),as(f)&&o.set(h.logicalId,h));}for(let f of t.allLogicalIds()){if(t.isTombstoned(f)||n.has(f)||o.has(f))continue;let p=t.record(f);!p||!J(p)||(xm(t,p)?n.set(f,p):Sm(t,p)&&o.set(f,p));}if(n.size===0)return [];let r=new Map;for(let f of n.values()){let p=r.get(f.namespaceUri)??[];p.push(f),r.set(f.namespaceUri,p);}let i=new Map;for(let f of o.values()){let p=bm(t,f.logicalId);if(!p)continue;let h=i.get(p)??[];h.push(f),i.set(p,h);}let s=[];for(let[f,p]of r){let h=i.get(f);if(!h||h.length===0)continue;p.sort((m,S)=>m.logicalId.localeCompare(S.logicalId)),h.sort((m,S)=>m.logicalId.localeCompare(S.logicalId));let g=p[0],y=h[0],I=[],k=new Set;for(let m of p)for(let S of m.childIds){if(k.has(S))continue;let L=t.record(S);!L||!J(L)||L.localName!=="node"||L.namespaceUri!==f||(k.add(S),I.push(S));}for(let m of t.allLogicalIds()){if(k.has(m)||t.isTombstoned(m))continue;let S=t.record(m);!S||!J(S)||S.localName!=="node"||S.namespaceUri!==f||(k.add(m),I.push(m));}I.sort((m,S)=>Fc(t,m).localeCompare(Fc(t,S))),s.push({data:g,props:y,nodeIds:I});}s.sort((f,p)=>f.data.logicalId.localeCompare(p.data.logicalId));let a=new Set,l=[],d=new Set,c=new Set;for(let[f,p]of e){let h=mm(f);if(h===null)continue;let g=s.find(k=>k.data.logicalId===p.root.id&&!d.has(k.data.logicalId));if(!g)continue;let y=Uc(h).props,I=e.get(y);I&&I.root.id!==g.props.logicalId||(a.add(h),d.add(g.data.logicalId),c.add(g.props.logicalId),l.push({dataRootId:g.data.logicalId,propsRootId:g.props.logicalId,namespaceUri:g.data.namespaceUri,itemName:f,propsName:y,nodeIds:g.nodeIds}));}let u=1;for(let f of s){if(d.has(f.data.logicalId))continue;for(;a.has(u);)u+=1;a.add(u);let p=Uc(u);l.push({dataRootId:f.data.logicalId,propsRootId:f.props.logicalId,namespaceUri:f.data.namespaceUri,itemName:p.item,propsName:p.props,nodeIds:f.nodeIds}),u+=1;}return l.sort((f,p)=>f.itemName.localeCompare(p.itemName)),l}function km(t){return t.type===CUSTOM_XML_REL||t.type===CUSTOM_XML_PROPS_REL?true:Bn(t.ownerPart)}function wm(t){let e=/^rId(\d+)$/.exec(t);if(!e)return 0;let n=Number(e[1]);return Number.isSafeInteger(n)?n:0}function vm(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 Wc(t,e){if(e.length===0)return [];let n=t.mainDocumentPart();if(!n)return [];let o=t.relationships(),r=o.filter(a=>a.ownerPart===n&&a.type===CUSTOM_XML_REL).sort((a,l)=>a.id.localeCompare(l.id)),i=0;for(let a of o)i=Math.max(i,wm(a.id));let s=[];for(let a=0;a<e.length;a+=1){let l=e[a],d=r[a],c=d?.id??`rId${String(i+=1)}`;s.push({ownerPart:n,id:c,type:CUSTOM_XML_REL,rawTarget:vm(n,l.itemName),targetMode:"Internal",order:d?.order??a}),s.push({ownerPart:l.itemName,id:"rId1",type:CUSTOM_XML_PROPS_REL,rawTarget:l.propsName.slice(l.propsName.lastIndexOf("/")+1),targetMode:"Internal",order:0});}return s}function Kc(t,e){return e.length===0?[...t]:[...t.filter(n=>!km(n)),...e]}function Vc(t){let e=new Map;for(let n of t)e.set(partNameKey(n.propsName),CUSTOM_XML_PROPS_TYPE);return e}function ls(t,e){if(e.length===0)return false;let n=[...t.keys()].filter(Bn).sort(),o=e.map(r=>r.itemName).sort();if(n.length!==o.length||n.some((r,i)=>r!==o[i]))return true;for(let r of e){let i=t.get(r.itemName),s=t.get(r.propsName);if(!i||i.root.id!==r.dataRootId||!s||s.root.id!==r.propsRootId)return true}return false}function Jc(t,e){if(ls(t,e))return true;for(let n of e){let o=t.get(n.itemName);if(!o)return true;let r=new Set(o.root.children.map(a=>a.id));if(n.nodeIds.some(a=>!r.has(a)))return true;let i=[];for(let a of o.root.children)a.kind!=="textValue"&&i.push(a.attributes.find(l=>l.localName==="id")?.value??a.id);let s=[...i].sort((a,l)=>a.localeCompare(l));if(i.some((a,l)=>a!==s[l]))return true}return false}var Lm="http://schemas.microsoft.com/office/word/2012/wordml";function Vo(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 Xc(t){return e=>e.localName===t&&e.namespaceUri===WML_NAMESPACE_URI}function Rm(t){return t.localName==="abstractNum"?`0${Vo(_e(t,"abstractNumId"))}`:`1${Vo(_e(t,"numId"))}`}function Om(t){return t.namespaceUri!==WML_NAMESPACE_URI?false:t.localName==="abstractNum"||t.localName==="num"}function ds(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===Lm,sortKey:e=>e.id,adoptedAfterListed:true}:t.localName==="footnotes"&&t.namespaceUri===WML_NAMESPACE_URI?{isMember:Xc("footnote"),sortKey:e=>Vo(_e(e,"id"))}:t.localName==="endnotes"&&t.namespaceUri===WML_NAMESPACE_URI?{isMember:Xc("endnote"),sortKey:e=>Vo(_e(e,"id"))}:t.localName==="numbering"&&t.namespaceUri===WML_NAMESPACE_URI?{isMember:Om,sortKey:Rm}:null}function Hc(t,e){for(let n of t)if(n.root.id===e)return ds(n.root)?n.root.children.map(U):null;return null}function Gc(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 qc(t,e,n){let o=t.record(n),r=!!o&&(wt(o)?o.value.length>0:o.childIds.length>0||o.attributes.length>0);e(r?"orphan-with-content":"orphan",n);}function Zc(t,e,n,o,r,i){if(!r){for(let l of n)t.isTombstoned(l)||o.has(l)||(qc(t,e,l),i.add(l));return}let s=new Set(t.partEntries().map(l=>l.rootLogicalId)),a=new Set;for(let l of n)a.has(l)||(a.add(l),Em(t,e,l,o,s)&&i.add(l));}function Em(t,e,n,o,r){let i=false,s=new Set,a=[{id:n,underTombstone:false}];for(;a.length>0;){let{id:l,underTombstone:d}=a.pop();if(!(s.has(l)||s.size>=t.limits.maxTreeDepth)){if(s.add(l),t.isTombstoned(l)){let c=t.record(l);if(c&&J(c))for(let u of c.childIds)a.push({id:u,underTombstone:true});continue}r.has(l)||(d?o.has(l):Gc(t,l))||(qc(t,e,l),i=true);}}return i}function Qc(t,e,n,o,r,i,s,a,l){let d=0;for(let c of a){if(i.has(c)||o.has(c)||t.isTombstoned(c)||Xn(t.schema.nodes.get(c))||s&&Gc(t,c))continue;let u=t.record(c);if(!u||!J(u)||!r(u))continue;let f=e(c);!f||f.kind==="textValue"||(n.push(f),o.add(c),l.add(c),d+=1);}return d}var ft="application/vnd.openxmlformats-officedocument.wordprocessingml",Pm=new Map(Object.entries({comments:{root:"comments",contentType:`${ft}.comments+xml`},commentsExtended:{root:"commentsEx",contentType:`${ft}.commentsExtended+xml`},commentsIds:{root:"commentsIds",contentType:`${ft}.commentsIds+xml`},commentsExtensible:{root:"commentsExtensible",contentType:`${ft}.commentsExtensible+xml`},people:{root:"people",contentType:`${ft}.people+xml`},footnotes:{root:"footnotes",contentType:`${ft}.footnotes+xml`},endnotes:{root:"endnotes",contentType:`${ft}.endnotes+xml`},numbering:{root:"numbering",contentType:`${ft}.numbering+xml`}}));function Am(t){return me(t)===null&&!Ko(t)&&t.toLowerCase()!=="/[content_types].xml"&&t.toLowerCase().endsWith(".xml")}function eu(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=Pm.get(d.type.slice(d.type.lastIndexOf("/")+1));if(!c)continue;let u=resolveInternalTarget(d.ownerPart,d.rawTarget);!u.ok||o.has(u.partName)||!Am(u.partName)||(o.add(u.partName),r.push({name:u.partName,...c}));}if(r.length===0)return [];let i=new Set(e.map(d=>d.rootLogicalId)),s=new Set(r.map(d=>d.root)),a=[];for(let d of t.allLogicalIds()){if(i.has(d)||t.isTombstoned(d)||t.parentOf(d)!==null)continue;let c=t.record(d);!c||!J(c)||!s.has(c.localName)||c.bindings.some(u=>u.prefix===(c.prefix??""))&&a.push({id:d,root:c.localName,empty:c.childIds.length===0});}let l=[];for(let d of r){let c=null;for(let{id:u,root:f,empty:p}of a)f!==d.root||i.has(u)||(c===null||c.empty&&!p||c.empty===p&&u<c.id)&&(c={id:u,empty:p});c!==null&&(i.add(c.id),l.push({name:d.name,id:d.name,rootLogicalId:c.id,contentType:d.contentType}));}return l}function tu(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 Jo=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:Kc(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:Bc(n)}),this.grouped.map}relationshipAssembly(e){let n=this.projected(e);return (!this.assembly||this.assembly.records!==n)&&(this.assembly={records:n,value:Ym(n)}),this.assembly.value}contentTypeDefaults(){return this.defaults??=this.registry.contentTypeDefaults()}contentTypeOverrides(){return this.overrides??=this.registry.contentTypeOverrides()}resolvePartBytes(e){if(this.partBytes)return this.partBytes;let n=new Map,o=new Set;for(let r of this.registry.binaries()){o.add(r.storageKey);let i=this.blobBytes.get(r.storageKey);if(i&&i.digest===r.digest){n.set(r.storageKey,i.bytes);continue}let s=e.get(r.digest);if(!s)return null;Rc(s.length),this.blobBytes.set(r.storageKey,{digest:r.digest,bytes:s}),n.set(r.storageKey,s);}for(let r of [...this.blobBytes.keys()])o.has(r)||this.blobBytes.delete(r);return this.partBytes=n,n}};function Ym(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 Xo=class{textOverlays=new Map;losers=new Set;awaiting=new Set;update(e){let n=[],o=e.replacementLoserRuns(),r=s=>{n.push(s);let a=e.parentOf(s);a!==null&&n.push(a);};for(let s of o)this.losers.has(s)||r(s);for(let s of this.losers)o.has(s)||r(s);this.losers=o;let i=e.concurrentSplitTextOverlays();return this.textOverlays=i.values,this.awaiting=i.awaiting,n.push(...i.changedIds),n}textValue(e,n){return this.textOverlays.get(e)??n}};function nu(t,e){let n=t.children;for(let i of n){let s=U(i);if(e.placed.has(s)||!e.isCached(i)||e.dirty.has(s)&&!e.canRebuild(s))return null}let o=null,r=[];for(let i=0;i<n.length;i+=1){let s=n[i],a=U(s);if(!e.dirty.has(a)){e.placed.add(a),o?.push(s);continue}let l=e.rebuild(a);if(l===s){o?.push(s);continue}o??=n.slice(0,i),l?o.push(l):r.push(a);}return {children:o?Object.freeze(o):n,dropped:r}}var Ho=class{nodes=new Map;heights=new Map;complete=new Set;get(e){return this.nodes.get(e)}holds(e){return this.nodes.get(U(e))===e}remember(e,n){this.nodes.set(e,n),this.heights.delete(e),this.complete.delete(e);}markComplete(e,n){n?this.complete.add(e):this.complete.delete(e);}isComplete(e){return this.complete.has(e)}forget(e){this.nodes.delete(e),this.heights.delete(e),this.complete.delete(e);}evictSubtree(e,n,o){let r=this.nodes.get(e);if(this.forget(e),o(e),!(!r||r.kind==="textValue"))for(let i of r.children){let s=U(i);n.has(s)||this.evictSubtree(s,n,o);}}heightOf(e){let n=this.heights.get(U(e));if(n!==void 0)return n;let o=1;if(e.kind!=="textValue")for(let r of e.children)o=Math.max(o,this.heightOf(r)+1);return this.heights.set(U(e),o),o}setHeight(e,n){this.heights.set(e,n);}ids(){return [...this.nodes.keys()]}};function ou(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 _m=4096,Go=class{constructor(e){this.registry=e;}registry;contested=false;matchesResolution=true;encountered=new Set;lastResolution=new Map;embedsMet=new Set;embedWinners=new Map;embedsDecidedAt=-1;reset(){this.contested=false,this.encountered.clear(),this.matchesResolution=true;}note(e,n,o,r){let i=this.registry,s=i.listingParents(e),a=s.length<=1?s:s.filter(l=>i.isTombstoned(l)?i.replacedByOf(l)!==null:r.has(l)||i.listingParents(l).length>0);a.length<=1||(this.contested=true,this.encountered.add(e),a.some(l=>i.isTombstoned(l)&&i.replacedByOf(l)!==null)?this.matchesResolution=false:!o.has(e)&&i.parentOf(e)!==n&&(this.matchesResolution=false));}noteEmbed(e,n,o,r){let i=o.get(e);return i===void 0||i===n||r.has(i)?true:this.embedWinners.get(e)===i&&this.embedsDecidedAt===this.registry.structureVersion?false:(this.contested=true,this.matchesResolution=false,this.embedsMet.add(e),true)}recordEmbeds(e){this.embedsDecidedAt!==this.registry.structureVersion&&this.embedWinners.clear(),this.embedsDecidedAt=this.registry.structureVersion;for(let n of this.embedsMet){let o=e.get(n);o===void 0?this.embedWinners.delete(n):this.embedWinners.set(n,o);}this.embedsMet.clear(),this.embedWinners.size>_m&&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 qo=class{lastAdoption=new Map;changes(e){let n=[],o=new Map,r=(i,s)=>{let a=new Set(s);for(let l of i)if(!a.has(l))for(let d of e.listingParents(l))e.isTombstoned(d)||n.push(d);};for(let[i,s]of e.adoptionIndex()){let a=e.isTombstoned(i)?[]:[...s];o.set(i,a);let l=this.lastAdoption.get(i);(l===void 0||!Gn(l,a))&&(n.push(i),l&&r(l,a));}for(let[i,s]of this.lastAdoption)o.has(i)||(n.push(i),r(s,[]));return this.lastAdoption=o,n}};var _t=class{constructor(e,n){this.registry=e;this.blobs=n;this.packageCache=new Jo(e),this.contests=new Go(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 Ho;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 qo;mergeSources=new Map;builtMerges=new Map;contests;splitProjection=new Xo;claimsWholeSubtrees=true;lastDuplicateParents=[];droppedChildren=new Set;looseCandidates=new Set;pkg=null;customXmlRels=[];customXmlOverrides=new Map;stop;issues=[];destroy(){this.stop();}dirtyLogicalIds(){return this.lastDirty}current(){return this.pkg&&this.pendingDirty.size===0&&!this.pendingPackage&&!this.pendingMembership?{ok:true,package:this.pkg,issues:[...this.issues]}:this.rebuild()}rebuildFull(){this.forceFull=true;try{return this.rebuild()}finally{this.forceFull=false;}}rebuild(){let e=new Set(this.pendingDirty),n=this.pendingPackage;this.pendingDirty.clear(),this.pendingMembership=false,this.pendingPackage=false;let o=this.registry.hasUnobservedWrites();o&&this.registry.rebuildDerivedIndexes(),(n||o)&&this.packageCache.invalidate();for(let c of this.adoption.changes(this.registry))e.add(c);for(let c of this.registry.inline.takeAffected())e.add(c);for(let c of this.registry.takeReparented())e.add(c);for(let c of [...e]){if(!this.registry.isTombstoned(c))continue;let u=this.registry.record(c);if(!(!u||!J(u)))for(let f of u.childIds)for(let p of this.registry.listingParents(f))e.add(p);}for(let c of this.splitProjection.update(this.registry))e.add(c);Ha(this.registry,e);let r=Tc(this.registry,e);for(let c of e){let u=this.shownUnder.get(c);for(let f=0;u!==void 0&&f<this.registry.limits.maxTreeDepth;f++)r.add(u),u=this.shownUnder.get(u);}let i=this.partRoots=new Set(this.registry.partEntries().map(c=>c.rootLogicalId)),s=[...e].some(c=>i.has(c)||this.registry.parentOf(c)===null&&!this.registry.isTombstoned(c)),a=!this.forceFull&&this.pkg!==null&&!o&&!s&&(r.size>0||n);this.rawDirty=e;let l=this.materializePass(r,n,a);if(!this.contests.contested)return l;if(l.ok&&this.contests.decided())return {ok:true,package:l.package,issues:ou(l.issues)};let d=this.materializePass(r,n,false);return this.contests.record(this.lastDuplicateParents),this.contests.recordEmbeds(this.shownUnder),d}materializePass(e,n,o){if(this.issues.length=0,this.lastDirty=e,this.contests.reset(),this.claimsWholeSubtrees=!o,this.droppedChildren.clear(),o)for(let f of this.lastDuplicateParents)this.push("duplicate-parent",f);this.customXmlRels=[],this.customXmlOverrides.clear();let r=new Set,i=new Map,s=this.registry.partEntries(),a=[...this.packageCache.groupedByOwner(this.customXmlRels).values()].flat();for(let f of [...s,...eu(this.registry,s,a)]){let p=new Set,h=this.materialize(f.rootLogicalId,r,p,o);if(!h||h.kind==="textValue")return {ok:false,code:"missing-root",issues:[...this.issues]};let g=this.partCache.get(f.name);if(g&&g.root===h&&g.contentType===f.contentType){i.set(f.name,g);continue}let y=Object.freeze({id:f.id||f.name,name:f.name,contentType:f.contentType,root:h});i.set(f.name,y),this.partCache.set(f.name,y);}let l=this.registry.history.takeMarkChanges(),d=o?new Set([...this.droppedChildren,...this.looseCandidates,...l]):this.registry.allLogicalIds(),c=new Set;this.projectRelsParts(i),this.adoptOrphanPartMembers(i,r,o,d,c),this.applyCustomXmlStores(i,r,o);for(let f of [...this.partCache.keys()])i.has(f)||this.partCache.delete(f);for(let f of [...this.relsProjection.keys()])i.has(f)||this.relsProjection.delete(f);this.evictDeadSubtrees(r);for(let f of e)r.has(f)||this.cache.forget(f);Zc(this.registry,this.pushIssue,d,r,o,c),this.looseCandidates=c,o||(this.lastDuplicateParents=this.issues.flatMap(f=>f.code==="duplicate-parent"&&f.logicalId!==void 0?[f.logicalId]:[]));let u=this.assemblePackage(i);return u.ok?this.pkg&&!n&&this.pkg.parts.size===i.size&&[...i].every(([f,p])=>this.pkg?.parts.get(f)===p)?{ok:true,package:this.pkg,issues:[...this.issues]}:(this.pkg=u.package,{ok:true,package:this.pkg,issues:[...this.issues]}):u}push(e,n){this.issues.push(n?{code:e,logicalId:n}:{code:e});}pushIssue=(e,n)=>this.push(e,n);materialize(e,n,o,r){if(o.has(e)||o.size>=this.registry.limits.maxTreeDepth)return this.push("cycle",e),null;if(n.has(e))return this.push("duplicate-parent",e),null;let i=this.mergeSources.get(e)?.join("")??"";if(r&&!this.lastDirty.has(e)&&i===(this.builtMerges.get(e)??"")){let b=this.cache.get(e);if(b&&o.size+this.cache.heightOf(b)<=this.registry.limits.maxTreeDepth)return this.claimsWholeSubtrees?is(b,n)||(this.contests.contested=true):n.add(U(b)),b}if(this.registry.isTombstoned(e))return null;let s=r?this.rebuildSpine(e,n,o):null;if(s)return s;n.add(e);let a=this.registry.record(e);if(!a)return this.push("missing-node",e),null;if(wt(a)){if(this.splitProjection.awaiting.has(e))return null;let b=this.splitProjection.textValue(e,a.value),w=this.cache.get(e);if(w?.kind==="textValue"&&w.value===b)return w;let E=Ec(e,b);return this.cache.remember(e,E),E}o.add(e);let l=this.issues.length,d=new Set,c=st(this.registry).shownChildIds(e,a.childIds),u=new Set(c),f=b=>{u.has(b)||(u.add(b),c.push(b));};for(let b of this.registry.adoptedChildren(e))f(b);for(let b of this.mergeSources.get(e)??[]){let w=this.registry.record(b);if(!(!w||!J(w)))for(let E of w.childIds)f(E);}i?this.builtMerges.set(e,i):this.builtMerges.delete(e);let p=this.splitProjection.losers,h=p.size===0?null:Oo(c,b=>p.has(b),b=>this.registry.splitLineageOf(b));h&&(c=h.map(b=>c[b]));let g=Nn(c,this.registry.splitSiblings.ranksOf(e));g&&(c=g.map(b=>c[b]));let y=[],I=Ja(a.kind,c,b=>this.splitProjection.losers.has(b)?null:Qe(this.registry,b));for(let b of I.hidden)n.add(b);for(let b of c)this.mergeSources.delete(b);for(let[b,w]of I.merges??[]){this.mergeSources.set(b,w);for(let E of w)this.shownUnder.set(E,b);}for(let b of I.shown){if(b===e){this.push("self-child",b);continue}if(d.has(b)){this.push("duplicate-child",b);continue}if(d.add(b),this.registry.isTombstoned(b)){this.push("deleted-referenced",b);continue}if(this.splitProjection.losers.has(b)){n.add(b);continue}if(O(b)||!this.registry.hasNode(b)){(O(b)||Ws(this.registry.schema.nodes,b))&&this.push("child-id-not-in-registry",b);continue}this.claimsWholeSubtrees||this.contests.note(b,e,n,this.partRoots);let w=this.materialize(b,n,o,r);w&&(y.push(w),this.shownUnder.set(U(w),e));}let k=I.hidden.length===0&&y.length===I.shown.length&&this.issues.length===l,m=this.registry.inline.textOf(e);if(m){let b=j=>{if(!this.registry.hasNode(j)&&$e(this.registry.doc)||this.registry.listingParents(j).length>0||this.partRoots.has(j)||!this.claimsWholeSubtrees&&!this.contests.noteEmbed(j,e,this.shownUnder,this.lastDirty))return null;let _=this.materialize(j,n,o,r);return _&&this.shownUnder.set(j,e),_},w=this.registry.inline.viewOf(e),E=Ze(e,m,b,this.registry.limits,w),M=this.cache.get(e);y.push(..._a(M?.kind==="textValue"?[]:M?.children??[],E));}o.delete(e);let S=this.cache.get(e);if(S&&S.kind!=="textValue"&&S.children.length===y.length&&S.children.every((b,w)=>b===y[w])&&Cc(S,a))return this.cache.markComplete(e,k),S;let L=S&&S.kind!=="textValue"?S.children:[];this.recordDroppedChildren(L,y);let v=zo(a,Yn(L,y),S);return this.cache.remember(e,v),this.cache.markComplete(e,k),v}rebuildSpine(e,n,o){let r=this.cache.get(e);if(!r||r.kind==="textValue"||this.rawDirty.has(e)||!this.cache.isComplete(e)||ni(r.kind)||this.builtMerges.has(e)||this.mergeSources.has(e)||this.splitProjection.losers.size>0||this.registry.adoptedChildren(e).length>0)return null;let i=this.cache.heightOf(r);if(o.size+i>this.registry.limits.maxTreeDepth)return null;let s=this.issues.length;o.add(e);let a=nu(r,{dirty:this.lastDirty,placed:n,isCached:u=>this.cache.holds(u),canRebuild:u=>O(u)||this.registry.isTombstoned(u)||!this.registry.hasNode(u)?false:(this.contests.note(u,e,n,this.partRoots),true),rebuild:u=>{let f=this.materialize(u,n,o,true);return f&&this.shownUnder.set(U(f),e),f}});if(o.delete(e),!a)return null;n.add(e);let l=a.dropped.length===0&&this.issues.length===s;if(a.children===r.children)return this.cache.markComplete(e,l),r;for(let u of a.dropped)this.droppedChildren.add(u);let d=Object.freeze(Ge(r,a.children));this.cache.remember(e,d),this.cache.markComplete(e,l);let c=i;for(let u of a.children)this.lastDirty.has(U(u))&&(c=Math.max(c,this.cache.heightOf(u)+1));return this.cache.setHeight(e,c),d}recordDroppedChildren(e,n){if(e.length===0)return;let o=new Set(n.map(r=>r.id));for(let r of e)o.has(r.id)||this.droppedChildren.add(U(r));}evictDeadSubtrees(e){for(let n of this.droppedChildren)e.has(n)||(this.registry.isTombstoned(n)||!this.registry.hasNode(n))&&this.cache.evictSubtree(n,e,o=>this.shownUnder.delete(o));}retainedNodeIds(){return this.cache.ids()}projectRelsParts(e){let n=this.packageCache.groupedByOwner(this.customXmlRels),o=new Set;for(let[r,i]of n){let s=relsPartNameFor(r);if(s!=="/_rels/.rels"&&me(s))continue;o.add(s);let a=this.projectOneRelsPart(s,e.get(s),i);a&&(e.set(s,a),this.partCache.set(s,a));}for(let[r,i]of e){if(o.has(r)||!Ko(r))continue;let s=Pc(r);if(s===null)continue;let a=this.projectOneRelsPart(r,i,n.get(s)??[]);!a||a===i||(e.set(r,a),this.partCache.set(r,a));}}projectOneRelsPart(e,n,o){if(!n&&o.length===0)return this.relsProjection.delete(e),null;let r=this.relsProjection.get(e),s=!!r&&(!n||Nc(r.root,n.root))&&r?r:n??_c(e);if(Dc(s.root,o))return this.relsProjection.set(e,s),s;let a=s.root.children,l=wc(s,Yc(a,o,e));return this.relsProjection.set(e,l),l}builtNode(e){return this.cache.get(e)??null}shownPartChildren(e){return Hc(this.partCache.values(),e)}adoptOrphanPartMembers(e,n,o,r,i){for(let[s,a]of e){let l=ds(a.root);if(!l)continue;let d=v=>v.logicalId!==a.root.id&&l.isMember(v),c=[],u=new Set,f=new Set,p=this.registry.record(U(a.root)),h=new Set(p&&J(p)?p.childIds:[]);for(let v of a.root.children){if(v.kind==="textValue")continue;let b=U(v);if(this.registry.isTombstoned(b)||!h.has(b)&&(Xn(this.registry.schema.nodes.get(b))||this.registry.listingParents(b).length>0)){f.add(b);continue}let w=this.registry.record(U(v));!w||!J(w)||!d(w)||(c.push(v),u.add(U(v)));}let g=Qc(this.registry,v=>this.materialize(v,n,new Set,o),c,u,d,n,o,r,i);if(g===0&&f.size===0)continue;let y=(v,b)=>l.sortKey(v).localeCompare(l.sortKey(b));if(l.adoptedAfterListed){let v=c.length-g;c.splice(v,g,...c.slice(v).sort(y));}else c.sort(y);let I=[];for(let v of a.root.children)u.has(U(v))||f.has(U(v))||I.push(v);let k=Yn(a.root.children,[...I,...c]);if(k===a.root.children)continue;let m=this.registry.record(U(a.root));if(!m||!J(m))continue;let S=zo(m,k,a.root);this.cache.remember(U(a.root),S);let L=Object.freeze({...a,root:S});e.set(s,L),this.partCache.set(s,L);}}materializeOnce(e,n,o){return n.has(e)?this.cache.get(e)??null:this.materialize(e,n,new Set,o)}adoptNodesIntoRoot(e,n,o,r){let i=this.cache.get(e),s=i&&i.kind!=="textValue"?i:this.materializeOnce(e,o,r);if(!s||s.kind==="textValue")return null;let a=[...s.children],l=new Set(a.map(p=>p.id)),d=0;for(let p of n){if(l.has(p))continue;let h=this.materializeOnce(p,o,r);!h||h.kind==="textValue"||(a.push(h),l.add(p),d+=1);}if(a.sort((p,h)=>rs(p).localeCompare(rs(h))),d===0&&a.every((p,h)=>p===s.children[h]))return s;let c=this.registry.record(e);if(!c||!J(c))return s;let u=Yn(s.children,a),f=zo(c,u,s);return this.cache.remember(e,f),f}applyCustomXmlStores(e,n,o){let r=$c(this.registry,e);if(r.length===0||!Jc(e,r))return;let i=ls(e,r),s=new Set;for(let a of r){s.add(a.itemName),s.add(a.propsName);let l=this.adoptNodesIntoRoot(a.dataRootId,a.nodeIds,n,o),d=this.materializeOnce(a.propsRootId,n,o);if(!l||!d||d.kind==="textValue")continue;let c=Object.freeze({id:a.itemName,name:a.itemName,contentType:"application/xml",root:l}),u=Object.freeze({id:a.propsName,name:a.propsName,contentType:CUSTOM_XML_PROPS_TYPE,root:d});e.set(a.itemName,c),e.set(a.propsName,u),this.partCache.set(a.itemName,c),this.partCache.set(a.propsName,u);}if(i){for(let a of [...e.keys()])!Bn(a)&&!as(a)||s.has(a)||(e.delete(a),this.partCache.delete(a));this.customXmlRels=Wc(this.registry,r),this.customXmlOverrides=Vc(r),this.projectRelsParts(e);}}assemblePackage(e){let n=this.packageCache.relationshipAssembly(this.customXmlRels);if(!n)return {ok:false,code:"invalid-relationships",issues:[...this.issues]};let o=this.packageCache.resolvePartBytes(this.blobs);if(!o)return {ok:false,code:"missing-blob",issues:[...this.issues]};let r=new Map(this.packageCache.contentTypeOverrides());for(let[a,l]of this.customXmlOverrides)r.set(a,l);let i={defaults:this.packageCache.contentTypeDefaults(),overrides:r};tu(e,i,r);let s=this.registry.mainDocumentPart()||[...e.keys()].find(a=>a.endsWith("document.xml"))||"";return {ok:true,package:Object.freeze({parts:e,partBytes:o,relationships:n.byOwner,externalTargets:n.externalTargets,contentTypes:i,mainDocumentPart:s}),issues:[...this.issues]}}};function ru(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=Ic(e.effects,bc(t));return n===null?null:n.ok?n:{ok:false,failure:Object.freeze(n.failure)}}function iu(t,e){try{xc(t,e);}catch(n){return n instanceof N?Object.freeze({code:n.code,...n.detail?{detail:n.detail}:{}}):Object.freeze({code:"blob-store-full"})}return null}function cs(t){let{status:e,reason:n}=t;return e!=="ready"&&e!=="disconnected"?null:{status:e,...n?{code:n.code,detail:n.detail}:{}}}var Fm=3,jm=20,Zo=class{refused=0;transient=0;published(){this.refused=0,this.transient=0;}refusedOne(e){(!e||++this.transient>jm)&&(this.refused+=1);}recoverable(){return this.refused<Fm}};var us="docxEditorSelectionBefore",Qo=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(us)||e.stackItem.meta.set(us,this.before);};onPopped=e=>{let n=e.stackItem.meta.get(us);this.restored=n??null;};track(e,n=new Map){if(!e){this.latest=null;return}let o=r=>({paragraphId:r.paragraphId,offset:r.offset,...r.character?{character:r.character}:{}});this.latest={selection:{anchor:o(e.anchor),head:o(e.head),...e.kind?{kind:e.kind}:{}},texts:n};}noteBefore(){this.before=this.latest;}startPop(){this.restored=null;}lastRestored(){let e=this.restored;if(!e)return null;let n=r=>{let i=r.character?this.find(r.paragraphId,r.character):null;if(i)return i;let s={paragraphId:r.paragraphId,offset:r.offset},a=e.texts.get(r.paragraphId),l=this.textOf(r.paragraphId);return a===void 0||l===null?s:{...s,offset:mapOffsetAcrossText(r.offset,a,l)}},{selection:o}=e;return {anchor:n(o.anchor),head:n(o.head),...o.kind?{kind:o.kind}:{}}}destroy(){this.undoManager.off("stack-item-added",this.onAdded),this.undoManager.off("stack-item-popped",this.onPopped);}};var su=Symbol("createDocumentCollaboration.attachWatchdogMs");function au(t){return t[su]??2e3}function lu(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 cn="docxEditor",pt=256,er=256,du=/^\d{1,16}:\d{1,16}$/;function uu(t,e,n){let o=new Map,r=s=>{let a=s.paragraphId.toUpperCase(),l=o.get(a);l===void 0&&(l=e(a),l!==void 0&&o.set(a,l));let d=Math.max(0,s.offset),c=n({paragraphId:a,offset:d});return {paragraphId:a,offset:d,...l!==void 0?{digest:tr(l)}:{},...c?{character:c}:{}}};return {encoded:{anchor:r(t.anchor),head:r(t.head),...t.kind==="cells"?{kind:"cells"}:{}},texts:o}}function Wm(t){if(typeof t!="object"||t===null||Array.isArray(t))return null;let e=t;if(typeof e.item!="string"||!du.test(e.item)||typeof e.after!="boolean")return null;let n=typeof e.identity=="string"&&du.test(e.identity)?e.identity:void 0;return {item:e.item,...n?{identity:n}:{},after:e.after}}function tr(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 Km=/^[0-9a-f]{8}$/;function fu(t){let e=t.actorId.trim(),n=t.name.trim();if(e.length===0||e.length>pt||n.length===0||n.length>pt)throw new N("invalid-identity");if(t.color!==void 0&&t.color.length>64)throw new N("invalid-identity-color");return Object.freeze({actorId:e,name:n,...t.color?{color:t.color}:{},role:t.role??"human"})}function pu(t){let e=t.trim();if(e.length===0||e.length>pt)throw new N("invalid-document-id");return e}function hu(t){let e=t?.trim()||globalThis.crypto.randomUUID();if(e.length>pt)throw new N("invalid-session-id");return e}function cu(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=Wm(e.character);return {paragraphId:e.paragraphId.toUpperCase(),offset:e.offset,...typeof e.digest=="string"&&Km.test(e.digest)?{digest:e.digest}:{},...n?{character:n}:{}}}function Vm(t){if(t===void 0||typeof t!="object"||t===null||Array.isArray(t))return;let e=t,n=cu(e.anchor),o=cu(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 nr(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>pt||typeof e.name!="string"||e.name.length===0||e.name.length>pt)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=Vm(e.selection);return i?{...r,selection:i}:r}var Xm=16,Hm=32,or=class{baselines=new Map;resolve(e,n,o){let r=[...e.getStates().entries()].slice(0,er),i=[],s=new Set,a=new Set,l=0,d;for(let[c,u]of r){if(c===e.clientID)continue;let f=nr(u[cn]);if(!f?.selection)continue;s.add(c);let{anchor:p,head:h}=f.selection,g=`${p.paragraphId}:${p.offset}:${p.digest??""}|${h.paragraphId}:${h.offset}:${h.digest??""}`,y=this.baselines.get(c);y?.key!==g&&(y={key:g,texts:new Map,resolved:new Map,missing:new Map},this.baselines.set(c,y));let{texts:I,resolved:k,missing:m}=y,S=b=>{let w=false,E=()=>{if(!b.character||!o)return null;if(l>=Hm)return w=true,null;l+=1;let $=o(b.paragraphId,b.character),P=$?n.paragraphByNodeId($.nodeId):null;if(!$||!P)return null;let te={paragraphId:P.paragraphId,nodeId:P.nodeId,offset:$.offset};return {address:Object.freeze(te),text:P.text}},M=n.paragraphByStableId(b.paragraphId);if(!M){let $=b.paragraphId+":"+b.offset;d??=n.revision();let P=m.get($);if(P?.revision===d)return P.address;let te=E()?.address??null;return w||m.set($,{revision:d,address:te}),te}let j=k.get(b.paragraphId+":"+b.offset);if(j?.text===M.text&&j.address.nodeId===M.nodeId&&(j.target===void 0||n.paragraphByNodeId(j.address.nodeId)?.text===j.target))return j.address;let _=E();if(_)return k.set(b.paragraphId+":"+b.offset,{text:M.text,address:_.address,target:_.text}),_.address;let z=I.get(b.paragraphId);if(z===void 0){if(b.digest!==void 0&&tr(M.text)!==b.digest)return Object.freeze({paragraphId:M.paragraphId,nodeId:M.nodeId,offset:Math.min(b.offset,M.text.length)});z=M.text,I.set(b.paragraphId,z);}let ee=z===M.text?"":`${b.paragraphId}:${z.length}:${tr(z)}`,H=ee===""||a.has(ee)||a.size<Xm;H&&ee!==""&&a.add(ee);let ae=Object.freeze({paragraphId:M.paragraphId,nodeId:M.nodeId,offset:H?mapOffsetAcrossText(b.offset,z,M.text):Math.min(b.offset,M.text.length)});return k.set(b.paragraphId+":"+b.offset,{text:M.text,address:ae}),ae},L=S(p),v=S(h);!L||!v||i.push(Object.freeze({actorId:f.actorId,name:f.name,...f.color?{color:f.color}:{},...f.selection.kind==="cells"?{kind:"cells"}:{},anchor:L,head:v}));}for(let c of this.baselines.keys())s.has(c)||this.baselines.delete(c);return Object.freeze(i)}};var Fn=64*1024*1024,un="docx-package-blobs-v1";function qm(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 Zm(t){return t instanceof ArrayBuffer||ArrayBuffer.isView(t)?t.byteLength:0}var ht=class{constructor(e){this.shared=e;}shared;verified=new WeakSet;poisoned=new Set;get(e){let n=this.shared.get(e),o=qm(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+=Zm(n);}),e}put(e,n){if(!this.shared.has(e)){if(this.totalByteLength()+n.byteLength>Fn)throw new N("blob-store-full");this.shared.set(e,new Uint8Array(n));}}verify(e,n,o){return this.verified.has(n)?true:this.poisoned.has(e)?false:sha256FontBytes(o)!==e?(this.poisoned.add(e),false):(this.verified.add(n),true)}};var Qm=Object.freeze([.75,.9]),gu=16;function fs(t){let e=0;return t.schema.relationships.forEach(n=>{e+=n instanceof K.Map?n.size:0;}),e}function yu(t){return {limit:"nodes",code:"too-many-nodes",used:t.nodeCount(),max:t.limits.maxNodes}}function bu(t,e){let{limits:n,schema:o}=t;return [{limit:"parts",code:"too-many-parts",used:o.parts.size,max:n.maxParts},{limit:"relationships",code:"too-many-relationships",used:fs(t),max:n.maxRelationships},{limit:"blobBytes",code:"blob-store-full",used:e.totalByteLength(),max:Fn}]}function ey(t,e){return [yu(t),...bu(t,e)]}function ir(t,e){for(let n of ey(t,e))if(n.used>n.max)return Object.freeze({code:n.code,detail:`${n.limit}=${n.used}`});return null}function ty(t){let e=t?.thresholds;if(e===void 0)return Qm;if(!Array.isArray(e)||e.length===0||e.length>gu)throw new RangeError(`thresholds must hold 1 to ${gu} values`);for(let n of e)if(typeof n!="number"||!Number.isFinite(n)||n<=0||n>1)throw new RangeError("each threshold must be greater than 0 and at most 1");return [...new Set(e)].sort((n,o)=>n-o)}function ny(t,e){let n=t[0],o=-1;for(let i of t){let s=i.max>0?i.used/i.max:Number.POSITIVE_INFINITY;s>o&&(n=i,o=s);}let r=0;for(let i of e)o>=i&&(r=i);return Object.freeze({limit:n.limit,fraction:o,threshold:r,used:n.used,max:n.max})}var rr=class{stops=new Set;stopped=false;watch(e,n,o,...[r,i]){let s=ty(i);if(this.stopped)return ()=>{};let{parts:a,relationships:l}=n.schema,d=null,c=()=>{d=null;},u=()=>(d??=bu(n,o),ny([yu(n),...d],s)),f=I=>{try{r(I);}catch(k){console.error("A subscribeResourcePressure listener threw.",k);}};a.observe(c),l.observeDeep(c);let p=o.observeChanges(c),h=u().threshold,g=()=>{let I=u();I.threshold!==h&&(h=I.threshold,f(I));},y=()=>{this.stops.delete(y)&&(e.off("afterTransaction",g),a.unobserve(c),l.unobserveDeep(c),p());};return e.on("afterTransaction",g),this.stops.add(y),h>0&&f(u()),y}stopAll(){this.stopped=true;for(let e of [...this.stops])e();}};var xu=20*1024*1024,dy=new Set(["document","hdr","ftr","footnotes","endnotes"]),wu=3e4,cy=4e3,uy=1500,fy="docx-collaboration-seeds-v1",ps="docxEditorSeedCandidate",py=/^[0-9a-f]{16}$/,hy=256;function vu(t,e=xu,n={}){if(!(t instanceof Uint8Array)||t.byteLength===0)throw new N("invalid-baseline");let o=Math.min(e,xu);if(t.byteLength>o)throw new N("baseline-too-large");let r=readOoxmlPackage(t,{zip:{maxEntries:1e4,maxTotalBytes:o,maxRatio:200}});if(!r.ok)throw new N(r.limit==="zip.maxTotalBytes"?"baseline-too-large":"invalid-baseline");let i=r.package.parts.get(r.package.mainDocumentPart);if(!i)throw new N("no-main-document-part");let s=n.keepBound?r.package:refreshBoundContent(r.package);for(let l of s.parts.values()){if(l.root.namespaceUri!==WML_NAMESPACE_URI||!dy.has(l.root.localName)||!isStoryPart(l))continue;let d=normalizeParagraphIdentity(l);d!==l&&(s=withPart(s,d));}return new TreePackageStore(s,normalizeParagraphIdentity(s.parts.get(i.name))).currentPackage()}function gy(t,e){for(let n of t.binaries())if(!e.has(n.digest))return false;return true}function sr(t,e,n,o){let r=t.schema.meta,i=()=>r.get("initialized")===true&&gy(t,e),s=()=>{let l=e.poisonedDigest();return l?new N("blob-digest-mismatch",l):null};if(o?.aborted)return Promise.reject(new N("initialization-aborted"));if(i())return Promise.resolve();let a=s();return a?Promise.reject(a):new Promise((l,d)=>{let c=h=>{clearTimeout(p),r.unobserve(u),t.doc.off("afterTransaction",u),o?.removeEventListener("abort",f),h?d(h):l();},u=()=>{let h=s();if(h){c(h);return}i()&&c();},f=()=>c(new N("initialization-aborted")),p=setTimeout(()=>c(new N("initialization-timeout")),n);r.observe(u),t.doc.on("afterTransaction",u),o?.addEventListener("abort",f,{once:true});})}function lr(t){return t.getArray(fy)}function my(t){lr(t).push([Ou()]);}var yy="freshBytes";function Lu(t){let e=K.encodeStateAsUpdate(t).byteLength;t.getMap(Sr).set(yy,e);}function by(t){return lr(t).length}function Ru(t,e){let n=lr(t),o=()=>{n.length>1&&e();};return o(),n.observe(o),()=>n.unobserve(o)}function Ou(){let t=new Uint8Array(8);return globalThis.crypto.getRandomValues(t),[...t].map(e=>e.toString(16).padStart(2,"0")).join("")}function Iy(t,e){let n=[...t.getStates().entries()].slice(0,hy);for(let[o,r]of n){if(o===t.clientID)continue;let i=r[ps];if(!(typeof i!="string"||!py.test(i))&&i<e)return true}return false}async function Su(t,e,n,o){try{return await sr(t,e,n,o),!0}catch(r){if(r instanceof N&&r.code==="initialization-timeout")return false;throw r}}function xy(t,e,n){let o=t.schema.meta,r=()=>o.get("documentId")!==void 0;return n?.aborted?Promise.reject(new N("initialization-aborted")):r()?Promise.resolve():new Promise((i,s)=>{let a=u=>{clearTimeout(c),o.unobserve(l),n?.removeEventListener("abort",d),u?s(u):i();},l=()=>{r()&&a();},d=()=>a(new N("initialization-aborted")),c=setTimeout(()=>a(new N("initialization-timeout")),e);o.observe(l),n?.addEventListener("abort",d,{once:true});})}async function Sy(t){let{ydoc:e,awareness:n,registry:o,blobs:r}=t,i=t.probeTimeoutMs??cy,s=t.electionWindowMs??uy,a=t.timeoutMs??wu,l=async()=>(await xy(o,a,t.signal),"joined");if(await Su(o,r,i,t.signal))return l();let d=Ou();n.setLocalStateField(ps,d);try{let c=await Su(o,r,s,t.signal);if(!c&&Iy(n,d)&&(await sr(o,r,a,t.signal),c=!0),c)return await l();if(o.schema.meta.get("initialized")===!0)return await sr(o,r,a,t.signal),await l();if(t.signal?.aborted)throw new N("initialization-aborted");let u=await jo(o,vu(t.document),r);if(!u.ok)throw new N(u.code);return e.transact(()=>{o.schema.meta.set("documentId",t.documentId),lr(e).push([d]);}),Lu(e),"seeded"}finally{n.setLocalStateField(ps,null);}}function ar(t,e,n){let o=Jn(t.schema.meta);if(o)throw new N(o.code,o.detail);t.rebuildDerivedIndexes(),hs(t,e,n);}function hs(t,e,n){if(by(n)>1)throw new N("concurrent-seed");let o=ir(t,e);if(o)throw new N(o.code,o.detail)}async function Eu(t,e,n,o){if(t.bootstrap.kind==="create"){if(e.schema.meta.get("initialized")===true)throw new N("already-initialized");let r=await jo(e,vu(t.bootstrap.document),n);if(!r.ok)throw new N(r.code);t.ydoc.transact(()=>{e.schema.meta.set("documentId",o),my(t.ydoc);}),Lu(t.ydoc),hs(e,n,t.ydoc);}else if(t.bootstrap.kind==="create-or-join")if(await Sy({ydoc:t.ydoc,awareness:t.awareness,registry:e,blobs:n,documentId:o,document:t.bootstrap.document,probeTimeoutMs:t.bootstrap.probeTimeoutMs,electionWindowMs:t.bootstrap.electionWindowMs,timeoutMs:t.bootstrap.timeoutMs,signal:t.bootstrap.signal})==="joined"){if(e.schema.meta.get("documentId")!==o)throw new N("document-id-mismatch");ar(e,n,t.ydoc);}else hs(e,n,t.ydoc);else {if(await sr(e,n,t.bootstrap.timeoutMs??wu,t.bootstrap.signal),e.schema.meta.get("documentId")!==o)throw new N("document-id-mismatch");ar(e,n,t.ydoc);}}var dr=class{constructor(e,n){this.knows=e;this.allocator=new fn(n);}knows;allocator;toLogical=new Map;get replicaId(){return this.allocator.replicaId}reset(){this.toLogical.clear();}mint(e){let n=this.allocator.take();return this.toLogical.set(e,n),n}resolve(e){return this.toLogical.get(e)??e}translate(e){let n=[],o=false;for(let r of e.effects){let i=this.translateEffect(r);i!==r&&(o=true),n.push(i);}return o?Object.freeze({effects:Object.freeze(n)}):e}translateEffect(e){switch(e.kind){case "putNode":{let n=this.translateDescriptor(e.descriptor);return n.logicalId===e.descriptor.logicalId?e:{...e,descriptor:n}}case "spliceText":case "setAttribute":case "setNamespaceBinding":{let n=this.resolve(e.logicalId);return n===e.logicalId?e:{...e,logicalId:n}}case "spliceChildren":{let n=this.resolve(e.parentLogicalId),o=e.childLogicalIds.map(i=>this.resolve(i));return n===e.parentLogicalId&&o.every((i,s)=>i===e.childLogicalIds[s])?e:{...e,parentLogicalId:n,childLogicalIds:o}}case "moveNode":{let n=this.resolve(e.logicalId),o=this.resolve(e.destinationParentLogicalId);return n===e.logicalId&&o===e.destinationParentLogicalId?e:{...e,logicalId:n,destinationParentLogicalId:o}}case "putXmlPart":{let n=this.resolve(e.rootLogicalId);return n===e.rootLogicalId?e:{...e,rootLogicalId:n}}default:return e}}translateDescriptor(e){let n=this.resolve(e.logicalId);return this.knows(n)?{...e,logicalId:n}:{...e,logicalId:this.mint(e.logicalId)}}};function cr(t,e,n,o){let r=t.inline.textOf(e);if(!r)return null;let i=[],s=new Set,a=Ze(e,r,y=>{if(s.has(y))return null;let I=n(y);return I&&s.add(I.id),I},t.limits,{...t.inline.viewOf(e),noteDrift:()=>{}},y=>i.push(y)),l={id:e,kind:"paragraph",namespaceUri:WML_NAMESPACE_URI,localName:"p",prefix:"w",namespaceBindings:[],attributes:[],children:a},d=new Map,c=0,u=y=>{if(!s.has(y.id)){if(y.kind==="textValue"){d.set(y.id,c),c+=y.value.length;return}for(let I of y.children)u(I);}};for(let y of a)u(y);if(c!==i.length)return null;let f=segmentsOf(l),p=f.length>0?f[f.length-1].end:0;if(p!==o.length)return null;let h=new Int32Array(p).fill(-1),g=new Int32Array(i.length).fill(-1);for(let y of f){if(y.node.kind!=="textValue"||y.removeNodeIds)continue;let I=d.get(y.node.id),k=y.node.value;if(I===void 0||o.slice(y.start,y.end)!==k)return null;for(let m=0;m<y.end-y.start;m+=1)h[y.start+m]=I+m,g[I+m]=y.start+m;}return {length:p,characters:i,characterAt:h,offsetOf:g}}function Cu(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 gs(t,e){let n=e.character.identity??e.character.item,o=-1;for(let i=0;i<t.characters.length;i+=1){let s=t.characters[i];if(s){if(s.item===e.character.item){o=i;break}o<0&&s.identity===n&&(o=i);}}if(o<0)return null;let r=t.offsetOf[o];return r<0?null:e.after?r+1:r}var vy=4096,ur=class{constructor(e){this.deps=e;}deps;selection=null;anchored=null;stale=true;carried=null;carryOwed=false;track(e){let n=this.deps.port(),o=a=>{let l=n?.paragraphByStableId(a.paragraphId);return l?{nodeId:l.nodeId,offset:a.offset}:null},r=e?o(e.anchor):null,i=e?o(e.head):null,s=r&&i?{anchor:r,head:i}:null;s&&this.selection&&Ly(s,this.selection)||(this.selection=s,this.stale=true,this.anchored=null,this.carried=null,this.carryOwed=false);}localChange(){this.stale=true,this.anchored=null,this.carried=null,this.carryOwed=false;}beforeChange(){if(this.carried=null,this.carryOwed=true,!this.stale)return;this.anchored=null;let e=this.selection;if(!e||!this.deps.viewIsCurrent())return;let n=this.anchorOf(e.anchor),o=this.anchorOf(e.head);!n||!o||(this.anchored={anchor:n,head:o},this.stale=false);}afterPublish(){this.carryOwed=false;let{anchored:e,selection:n}=this;if(!e||!n||!this.deps.viewIsCurrent()){this.carried=null;return}let o=this.resolve(e.anchor),r=this.resolve(e.head);this.carried=o&&r?{from:n,to:{anchor:o,head:r}}:null;}move(){return this.carryOwed&&this.afterPublish(),this.carried}characterOf(e){let n=this.deps.port()?.paragraphByStableId(e.paragraphId);if(!n||!this.deps.viewIsCurrent())return;let o=this.anchorOf({nodeId:n.nodeId,offset:e.offset});if(!o)return;let{character:r,after:i}=o.anchor;return {item:r.item,...r.identity!==null?{identity:r.identity}:{},after:i}}find(e,n){if(!this.deps.viewIsCurrent())return null;let o=this.deps.port()?.paragraphByStableId(e);return this.resolve({paragraph:o?this.deps.logicalIdOf(o.nodeId):null,anchor:{character:{item:n.item,identity:n.identity??null},after:n.after}})}findStable(e,n){let o=this.find(e,n),r=o?this.deps.port()?.paragraphByNodeId(o.nodeId):null;return o&&r?{paragraphId:r.paragraphId,offset:o.offset}:null}anchorOf(e){let n=this.deps.logicalIdOf(e.nodeId),o=this.shownText(e.nodeId);if(o===null)return null;let r=cr(this.deps.registry,n,this.deps.embedOf,o),i=r?Cu(r,e.offset):null;return i?{paragraph:n,anchor:i}:null}resolve(e){let{registry:n}=this.deps,o=n.inline.follow,r=e.anchor.character.identity??e.anchor.character.item,i=new Set(e.paragraph?[e.paragraph]:[]),s=o.shownCopy(r);s&&i.add(s);for(let a of o.holdersOf(r))i.add(a);if(e.paragraph)for(let a of o.targetsFor(e.paragraph))i.add(a);for(let a of i){if(n.inline.isDeletedParagraph(a))continue;let l=this.shownText(a);if(l===null)continue;let d=cr(n,a,this.deps.embedOf,l),c=d?gs(d,e.anchor):null;if(c!==null)return {nodeId:a,offset:c}}return e.paragraph?this.besideDeleted(e.paragraph,e.anchor):null}besideDeleted(e,n){let{registry:o}=this.deps,r=o.inline.textOf(e),i=this.shownText(e),s=/^(\d{1,16}):(\d{1,16})$/.exec(n.character.item);if(!r?.doc||i===null||!s||o.inline.isDeletedParagraph(e))return null;let a=q(r.doc,{client:Number(s[1]),clock:Number(s[2])});if(!a||!a.deleted||a.parent!==r)return null;let l=cr(o,e,this.deps.embedOf,i);if(!l)return null;if(i.length===0)return {nodeId:e,offset:0};for(let d of [true,false]){let c=0;for(let u=d?a.left:a.right;u&&c<vy;u=d?u.left:u.right,c+=1){if(u.deleted||!(u.content instanceof K.ContentString))continue;let f=d?u.id.clock+u.length-1:u.id.clock,p=gs(l,{character:{item:`${u.id.client}:${f}`,identity:null},after:d});if(p!==null)return {nodeId:e,offset:p}}}return null}shownText(e){return this.deps.port()?.paragraphTextOf?.(e)??null}};function Ly(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 fr=class{constructor(e){this.deps=e;}deps;waiting=false;held=[];refuses(e){return this.deps.viewWaiting()?this.set(true):$e(this.deps.ydoc)?this.waits(e)?(this.held=e,this.set(true)):(this.held.length>0&&!this.waits(this.held)&&(this.held=[]),this.set(this.held.length>0),false):(this.held=[],this.set(false))}refresh(){!this.waiting||this.deps.viewWaiting()||(!$e(this.deps.ydoc)||this.held.length>0&&!this.waits(this.held))&&(this.held=[],this.set(false));}waits(e){return e.some(n=>Ry.has(n.op)||Oy(n).some(o=>this.deps.nodeWaits(o)))}set(e){return e!==this.waiting&&(this.waiting=e,this.deps.publish(e)),e}},Ry=new Set(["acceptAllRevisions","rejectAllRevisions","replaceStoryBlocks","convertAllNotes"]);function Oy(t){let e=[],n=(o,r)=>{for(let[i,s]of Object.entries(o))if(typeof s=="string")i.endsWith("Id")&&e.push(s);else if(Array.isArray(s))for(let a of s)typeof a=="string"?i.endsWith("Ids")&&e.push(a):a!==null&&typeof a=="object"&&r<3&&n(a,r+1);else s!==null&&typeof s=="object"&&r<3&&n(s,r+1);};return n(t,0),e}function Ey(t){let e=0;return t.schema.nodes.forEach(n=>{Y(n)&&n.get(ce)===true&&(e+=1);}),e}function Cy(t){let e=0;return t.schema.nodes.forEach(n=>{let o=Y(n)?n.get(se):null;if(o instanceof K.Text)for(let r=o._start;r;r=r.right)!r.deleted&&r.content instanceof K.ContentFormat&&(e+=1);}),e}function ms(t,e){return Object.freeze({nodes:t.nodeCount(),tombstonedNodes:Ey(t),maxNodes:t.limits.maxNodes,relationships:fs(t),maxRelationships:t.limits.maxRelationships,parts:t.schema.parts.size,maxParts:t.limits.maxParts,blobBytes:e.totalByteLength(),maxBlobBytes:Fn,formattingMarkers:Cy(t)})}function NL(t){let e=new ot(t);try{let n=new ht(t.getMap(un));return ms(e,n)}finally{e.destroy();}}var Ty={"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."},gt=class extends Error{constructor(n){super(`${n}: ${Ty[n]}`);this.code=n;this.name="CollaborationUndoGroupError";}code},hr=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 gt("collaboration-session-destroyed");if(n())throw new gt("editor-attached");if(this.current!==null)throw new gt("undo-group-already-open");if(this.flush(),e())throw new gt("collaboration-session-destroyed");if(n())throw new gt("editor-attached");if(this.current!==null)throw new gt("undo-group-already-open");let o={};this.current=o,this.capture.pin(Symbol("collaboration-undo-group"));let r=this;return Object.freeze({get state(){return r.current===o?"open":"closed"},end(){r.current===o&&(r.flush(),r.current===o&&(r.current=null,r.capture.unpin()));}})}close(){this.current!==null&&(this.current=null,this.capture.unpin());}};var My=2;function Mu(t,e){let n=new Set,o=new Set;for(let i of e.effects)if(i.kind==="spliceChildren"){n.add(i.parentLogicalId);for(let s of i.childLogicalIds)o.add(s);}else if(i.kind==="moveNode"){o.add(i.logicalId),n.add(i.destinationParentLogicalId);let s=t.parentOf(i.logicalId);s&&n.add(s);}let r=[];for(let i of n){if(!t.splitSiblings.ranksOf(i))continue;let s=t.splitSiblings.shownChildren(i);s&&r.push({parentId:i,shown:s,placed:o});}return r}function Py(t,e,n){let o=new Set(e),r=new Set(t.filter(d=>o.has(d)&&!n.has(d))),i=t.filter(d=>r.has(d)),s=0,a=false,l=e.map(d=>{if(!r.has(d))return d;let c=i[s++];return c!==d&&(a=true),c});return a?l:null}function Ay(t,e,n,o){let r=re(t.schema.nodes.get(e));if(!r)return false;let i=0;for(;o[i]===n[i];)i+=1;let s=o.length-1;for(;o[s]===n[s];)s-=1;let a=o.slice(i,s+1),l=r.toArray();for(let u of a){if(l.indexOf(u)!==l.lastIndexOf(u))return false;let f=t.listingParents(u);if(f.length!==1||f[0]!==e)return false}let d=new Set(a);for(let u=l.length-1;u>=0;u-=1)d.has(l[u])&&r.delete(u,1);let c=i>0?r.toArray().indexOf(o[i-1]):-1;return r.insert(c+1,a),true}function Pu(t,e,n,o){for(let{parentId:r,shown:i,placed:s}of o)for(let a=0;a<My;a+=1){let l=t.splitSiblings.shownChildren(r),d=l?Py(i,l,s):null;if(!l||!d)break;let c=false;if(e.transact(()=>{c=Ay(t,r,l,d);},n),!c)break}}function Ny(t){let e=new ot(t),n=null;try{if(e.schema.meta.get("initialized")!==!0||typeof e.schema.meta.get("documentId")!="string")throw new N("not-initialized");let o=new ht(t.getMap(un));ar(e,o,t),n=new _t(e,o);let r=n.current(),i=o.poisonedDigest();if(i)throw new N("blob-digest-mismatch",i);if(!r.ok)throw new N(r.code);let s=vt(r.issues);if(s)throw new N("materialize-dropped-content",s);if(!r.package.parts.has(r.package.mainDocumentPart))throw new N("no-main-document-part");return writeOoxmlPackage(r.package)}finally{n?.destroy(),e.destroy();}}var jy=500,ys=class{constructor(e,n,o,r,i,s,a,l,d,c,u){this.ydoc=e;this.awareness=n;this.registry=s;this.materializer=a;this.identityMap=l;this.blobs=d;this.offlineEditing=u;this.documentId=o,this.sessionId=r,this.currentIdentity=i,this.undoManager=new K.UndoManager([...s.trackedTypes()],{trackedOrigins:new Set([this.localOrigin]),captureTimeout:jy,deleteFilter:s.undoDeleteFilter()}),this.historyGroups=new Ao(this.undoManager,this),this.undoGroups=new hr(this.historyGroups,()=>this.flushPendingJournals()),this.historySelections=new Qo(this.undoManager,f=>this.port?.paragraphByStableId(f)?.text??null,(f,p)=>this.caretAnchors.findStable(f,p)),this.editWait=new fr({ydoc:e,viewWaiting:()=>this.viewWaiting,nodeWaits:f=>dd(s,this.identityMap.resolve(f)),publish:f=>this.statusState.setWaiting(f)&&this.notifyStatus()}),this.caretAnchors=new ur({registry:s,port:()=>this.port,logicalIdOf:f=>this.identityMap.resolve(f),embedOf:f=>a.builtNode(f),viewIsCurrent:()=>!this.viewWaiting}),e.on("beforeTransaction",this.onBeforeYjsTransaction),e.on("afterTransaction",this.onYjsTransaction),n.on("change",this.onAwarenessChange),this.stopBlobWatch=d.observeChanges(f=>{let p=d.verifyNow(f);p&&this.setStatus("error","blob-digest-mismatch",p);}),this.publishAwareness(),this.setStatus("ready"),this.stopSeedWatch=Ru(e,()=>{this.setStatus("error","concurrent-seed");}),this.attachWatchdog=lu(this.documentId,c,()=>(this.attachWatchdog=null,this.destroyed||this.port!==null));}ydoc;awareness;registry;materializer;identityMap;blobs;offlineEditing;documentId;sessionId;currentIdentity;currentSelection;attachWatchdog=null;statusState=createCollaborationStatusTracker();statusListeners=new Set;selectionListeners=new Set;participantListeners=new Set;localOrigin=Object.freeze({kind:"docx-document-local"});caretAnchors;editWait;undoManager;port=null;detachPort=null;applyingRemote=false;viewWaiting=false;fullRefusedWhileWaiting=false;healTo=null;historySelections;remoteSelectionResolver=new or;realignedInBatch=false;journalsHeldDuringRemote=[];drainingHeldJournals=false;remoteCounter=0;destroyed=false;pressure=new rr;refusals=new Zo;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 ms(this.registry,this.blobs)}subscribeResourcePressure(...e){return this.pressure.watch(this.ydoc,this.registry,this.blobs,...e)}subscribeStatus(e){return this.statusListeners.add(e),()=>this.statusListeners.delete(e)}setTransportStatus(e,n,o){if(!this.destroyed){if(this.statusState.status()==="error"&&e!=="error"){this.healTo!==null&&(this.healTo={status:e,code:n,detail:o},this.publishSharedToPort());return}if(n!==void 0){this.setStatus(e,n,o);return}this.setStatus(e);}}get attached(){return this.port!==null}attach(e){let n=this.refuseAttach(e);if(n)return n;this.clearAttachWatchdog(),e.interactive===true&&this.undoGroups.close(),this.port=e,this.publishSharedToPort();let o=e.observePrimitiveJournal(r=>{if(!this.destroyed){if(this.applyingRemote){this.journalsHeldDuringRemote.push(r);return}this.realignedInBatch||this.applyJournal(r);}});return this.detachPort=()=>{this.flushPendingJournals(),o(),this.port===e&&(this.port=null),this.detachPort=null,this.currentSelection&&this.publishAwareness();},()=>this.detachPort?.()}refuseAttach(e){return this.destroyed?()=>{}:this.port?(this.port!==e&&this.setStatus("error","port-already-attached"),()=>{}):e.documentId!==this.documentId?(this.setStatus("error","document-id-mismatch"),()=>{}):null}hasCompatibleSharedSchema(){let e=Jn(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=K.getState(this.ydoc.store,this.ydoc.clientID);return this.registry.takeUnlisted(),Kd(this.registry,this.undoManager,e,()=>Wd(this.registry,this.ydoc,o)),true}flushPendingJournals(){this.port?.flushPendingJournals();}setLocalSelection(e){if(this.destroyed)return;if(this.caretAnchors.track(e),!e){this.historySelections.track(null),this.publishAwareness();return}let{encoded:n,texts:o}=uu(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,er);for(let[o,r]of n){let i=nr(r[cn]);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>pt)throw new N("invalid-identity");let o=this.currentIdentity.color;if(e.color!==void 0){if(e.color.length>64)throw new N("invalid-identity-color");o=safeParticipantColor(e.color);}this.currentIdentity=Object.freeze({actorId:this.currentIdentity.actorId,name:n,...o?{color:o}:{},role:this.currentIdentity.role??"human"}),this.publishAwareness(this.currentSelection);}destroy(){this.destroyed||(this.clearAttachWatchdog(),this.flushPendingJournals(),this.undoGroups.close(),this.detachPort?.(),this.destroyed=true,this.pressure.stopAll(),this.stopBlobWatch(),this.stopSeedWatch(),this.ydoc.off("beforeTransaction",this.onBeforeYjsTransaction),this.ydoc.off("afterTransaction",this.onYjsTransaction),this.awareness.off("change",this.onAwarenessChange),this.awareness.setLocalStateField(cn,null),this.historySelections.destroy(),this.undoManager.destroy(),this.materializer.destroy(),this.registry.destroy(),this.setStatus("destroyed"),this.statusListeners.clear(),this.selectionListeners.clear(),this.participantListeners.clear());}applyJournal(e){if(!this.canWriteSharedState())return;let n=this.identityMap.translate(e),o=vd(this.materializer,n,()=>$e(this.ydoc));if(o){this.refuseLocalJournal(o.failure,o.transient);return}this.registry.inline.takeDrift();let r=wd(this.registry,n,c=>this.materializer.shownPartChildren(c));if(!r.ok){this.refuseLocalJournal({code:r.code,...r.detail?{detail:r.detail}:{}});return}let i=r.journal,s=ru(this.port,e);if(s!==null&&s.ok===false){this.refuseLocalJournal(s.failure);return}if(!this.canWriteSharedState())return;let a=false;this.historySelections.noteBefore();let l=Mu(this.registry,i),d=this.historyGroups.capture(historyGroupOfJournal(e),()=>{let c=this.ydoc.transact(()=>{if(s!==null){let f=iu(this.blobs,s.payloads);if(f!==null)return f}let u=Yi(this.registry,i,r.plan,r.typed);return u.ok?null:(a=u.transient===true,{code:u.code,...u.detail?{detail:u.detail}:{}})},this.localOrigin);return c===null&&Pu(this.registry,this.ydoc,this.localOrigin,l),c});if(d===null){this.refusals.published(),(this.registry.inline.takeDrift()||e.effects.some(u=>u.kind!=="spliceText")&&Ld(this.registry,r.plan))&&this.publishSharedToPort();return}this.refuseLocalJournal(d,a);}refuseLocalJournal(e,n=false){this.historyGroups.refused(),this.undoManager.stopCapturing();let o=this.statusState.snapshot();this.refusals.refusedOne(n);let r=this.refusals.recoverable()?cs(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.canWriteSharedState()&&Md(e,this.registry.schema.nodes,this.undoManager),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=ir(this.registry,this.blobs);if(o){this.setStatus("error",o.code,o.detail);return}let r=$e(this.ydoc);r||(this.fullRefusedWhileWaiting=!1);let i=e?this.materializer.rebuildFull():this.materializer.current(),s=this.blobs.poisonedDigest();if(s){this.setStatus("error","blob-digest-mismatch",s);return}if(this.viewWaiting=!1,!i.ok){r?this.viewWaiting=!0:this.degrade(i.code);return}let a=vt(i.issues);if(a){r?this.viewWaiting=!0:this.degrade("materialize-dropped-content",a);return}let l=u=>(this.remoteCounter+=1,n.applyRemotePackage(u,{origin:ORIGIN_IDS.mutationRemote,actorId:"remote",operationId:`${this.sessionId}:remote:${this.remoteCounter}`})),d=l(i.package);if(!d.ok&&!(r&&this.fullRefusedWhileWaiting)){let u=this.materializer.rebuildFull();u.ok&&!vt(u.issues)&&(d=l(u.package)),!d.ok&&r&&(this.fullRefusedWhileWaiting=!0);}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 N?o.code:"remote-apply-failed",o instanceof N?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(cn,n);}degrade(e,n){this.setStatus("error",e,n,this.healTo??cs(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 kR(t){let e=au(t),n=pu(t.documentId),o=hu(t.sessionId),r=fu(t.identity),i=new ot(t.ydoc);try{return await zy(t,{attachWatchdogMs:e,documentId:n,sessionId:o,identity:r,registry:i})}catch(s){throw i.destroy(),s}}async function zy(t,e){let{attachWatchdogMs:n,documentId:o,sessionId:r,identity:i,registry:s}=e,a=new dr(c=>s.hasNode(c)||s.inline.owner(c)!==null),l=new ht(t.ydoc.getMap(un));await Eu(t,s,l,o);let d=new _t(s,l);try{let c=d.current(),u=l.poisonedDigest();if(u)throw new N("blob-digest-mismatch",u);if(!c.ok)throw new N(c.code);let f=writeOoxmlPackage(c.package),p=new ys(t.ydoc,t.awareness,o,r,i,s,d,a,l,n,t.offlineEditing!==!1);return Object.freeze({document:f,session:p,destroy:()=>p.destroy()})}catch(c){throw d.destroy(),c}}
|
|
11
|
+
export{Is as a,N as b,bt as c,Gy as d,Sr as e,ot as f,jo as g,su as h,pu as i,un as j,ht as k,vu as l,my as m,Lu as n,NL as o,gt as p,Ny as q,kR as r};
|