revise 1.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +962 -0
- package/FONT-LICENSE-HAN-EXT-B.txt +91 -0
- package/FONT-LICENSE-KATEX.txt +95 -0
- package/FONT-LICENSE-LIBERATION.txt +102 -0
- package/FONT-LICENSE-NOTO-MULTILINGUAL.txt +93 -0
- package/FONT-LICENSE-NOTO-SANS-SC.txt +93 -0
- package/FONT-LICENSE-NOTO.txt +94 -0
- package/FONT-LICENSE-SOURCE-CODE-PRO.txt +94 -0
- package/FONT-LICENSE-SOURCE-SERIF-4.txt +93 -0
- package/LICENSE +41 -21
- package/README.md +39 -1
- package/THIRD-PARTY-NOTICES.md +3376 -0
- package/assets/historyMaterializeWorker-CoAX9ZAi.js +3 -0
- package/backend.d.ts +133 -0
- package/backend.js +1 -0
- package/chunks/AgentPageRenderer-C0n4EnuW.js +1 -0
- package/chunks/AgentPageRenderer-DURfmiu0.js +1 -0
- package/chunks/AttachmentDocumentImporter-DSic_6At.js +1 -0
- package/chunks/AttachmentDocumentImporter-dNMtkxrv.js +1 -0
- package/chunks/BidiText-B4Hzrjg9.js +1 -0
- package/chunks/ColorParserFull-BKH72fK8.js +1 -0
- package/chunks/DocumentStylesheet-byN5dtC6.js +1 -0
- package/chunks/DocxConverter-B7P52lw7.js +11 -0
- package/chunks/DocxConverter-COV6CjUM.js +11 -0
- package/chunks/DocxConverter-Cq_zCEJC.js +11 -0
- package/chunks/DocxGraft-CJ12C9WP.js +1 -0
- package/chunks/DocxGraft-CQpvFcYb.js +1 -0
- package/chunks/DocxGraft-DcmFuUkd.js +1 -0
- package/chunks/FileImporter-DVnYOJHp.js +1 -0
- package/chunks/FileImporter-q9mCch0J.js +1 -0
- package/chunks/HorizontalRuleOrnaments-gmUZ3R7Q.js +1 -0
- package/chunks/HtmlConverter-JvRlkQM3.js +61 -0
- package/chunks/ListNumbering-Qlu6AuRZ.js +1 -0
- package/chunks/MarkdownConverter-B-tPY7X3.js +17 -0
- package/chunks/MathRenderer-B0Y1h1JU.js +33 -0
- package/chunks/OdtConverter-Br81BSoJ.js +1 -0
- package/chunks/OdtConverter-CQjh0vlo.js +1 -0
- package/chunks/OdtConverter-DYHnR4E8.js +1 -0
- package/chunks/PdfConverter-D26rXumc.js +21 -0
- package/chunks/PdfConverter-DGZpUSVf.js +21 -0
- package/chunks/PdfConverter-DZzVP0-B.js +21 -0
- package/chunks/PdfImportService-CBD8TL1k.js +2 -0
- package/chunks/PdfImportService-D6uUKGMf.js +2 -0
- package/chunks/RtfConverter-BQGge3K-.js +14 -0
- package/chunks/RtfConverter-CMfZ4olw.js +14 -0
- package/chunks/RtfConverter-oIwzoqCD.js +14 -0
- package/chunks/TableBorders-BLkZYt1k.js +1 -0
- package/chunks/TableGrid-DVWaRZv0.js +1 -0
- package/chunks/TextFileDecoder--rsVs3NR.js +2 -0
- package/chunks/TxtConverter-C1lp6dBS.js +11 -0
- package/chunks/__vite-browser-external-l0sNRNKZ.js +0 -0
- package/chunks/_commonjsHelpers-DaMA6jEr.js +1 -0
- package/chunks/_revise-sdk-lazy-harfbuzz-CDWdjF9f.js +1 -0
- package/chunks/_revise-sdk-lazy-harfbuzz-X8gnYTZL.js +1 -0
- package/chunks/ar-kgSWdrXF.js +8 -0
- package/chunks/backend-Cq-khfdG.js +1 -0
- package/chunks/base64-CfDUyGi8.js +36 -0
- package/chunks/browser-module-6b2Fq-5C.js +3 -0
- package/chunks/browser-module-CFmqfGkE.js +3 -0
- package/chunks/browser-module-CkO57IPL.js +3 -0
- package/chunks/bundle.min-DRpfgV69.js +8 -0
- package/chunks/capture-DU3MC7tb.js +1 -0
- package/chunks/carrier-WgcRSu7a.js +1 -0
- package/chunks/de-C2QTHrqo.js +8 -0
- package/chunks/es-BKboUn4q.js +8 -0
- package/chunks/footnoteFlatten-CW-DUcgK.js +1 -0
- package/chunks/graftExport-CVg7PO2A.js +2 -0
- package/chunks/html2canvas.esm-CntiHiYW.js +5 -0
- package/chunks/index-BWdRWxoH.js +24 -0
- package/chunks/index-CLw_BlSL.js +353 -0
- package/chunks/index-F-kHIwWT.js +353 -0
- package/chunks/index.es-CI0QPo8w.js +5 -0
- package/chunks/index.es-DOqegDGr.js +5 -0
- package/chunks/index.es-tXDO0RMv.js +5 -0
- package/chunks/jspdf.es.min-CzYti8jo.js +77 -0
- package/chunks/jspdf.es.min-DU74zN8b.js +77 -0
- package/chunks/jspdf.es.min-ejWOGhkJ.js +77 -0
- package/chunks/jszip.min-CPW0h1Kx.js +2 -0
- package/chunks/katex-DWj8TvwO.js +261 -0
- package/chunks/pdf-BLWDCiFF.js +12 -0
- package/chunks/persistInlineDocumentImages-DQj2iaqg.js +1 -0
- package/chunks/pseudoLocale-CdBtPHRi.js +1 -0
- package/chunks/pseudoLocale-DEVWLkGC.js +1 -0
- package/chunks/purify.es-BwLardii.js +2 -0
- package/chunks/serverDocumentSession-DZrYbdpk.js +42 -0
- package/chunks/tree-sitter-D6zWWUMP.js +4 -0
- package/chunks/wasmInline.generated-CBYFkdSM.js +1 -0
- package/chunks/web-tree-sitter-BXGZGnNj.js +1 -0
- package/full.js +1 -0
- package/index.d.ts +929 -0
- package/index.js +1 -0
- package/package.json +93 -26
- package/root.d.ts +5 -0
- package/root.js +2 -0
- package/serverToolContract.d.ts +373 -0
- package/serverToolInputs.generated.d.ts +229 -0
- package/style.css +1 -0
- package/.npmignore +0 -4
- package/.travis.yml +0 -16
- package/revise.js +0 -16
- package/t/cover +0 -18
- package/t/revise/comparator.t.js +0 -31
- package/t/revise/extractor.t.js +0 -29
- package/t/test +0 -20
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
(function(){"use strict";const U=()=>new Map,Ze=e=>{const t=U();return e.forEach((n,r)=>{t.set(r,n)}),t},B=(e,t,n)=>{let r=e.get(t);return r===void 0&&e.set(t,r=n()),r},ai=(e,t)=>{const n=[];for(const[r,s]of e)n.push(t(s,r));return n},di=(e,t)=>{for(const[n,r]of e)if(t(r,n))return!0;return!1},Wt=()=>new Set,tn=e=>e[e.length-1],hi=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},ft=Array.from,ui=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1},gi=(e,t)=>{const n=new Array(e);for(let r=0;r<e;r++)n[r]=t(r,n);return n},en=Array.isArray;class nn{constructor(){this._observers=U()}on(t,n){return B(this._observers,t,Wt).add(n),n}once(t,n){const r=(...s)=>{this.off(t,r),n(...s)};this.on(t,r)}off(t,n){const r=this._observers.get(t);r!==void 0&&(r.delete(n),r.size===0&&this._observers.delete(t))}emit(t,n){return ft((this._observers.get(t)||U()).values()).forEach(r=>r(...n))}destroy(){this._observers=U()}}const pt=Math.floor,xe=Math.abs,Kn=(e,t)=>e<t?e:t,Ct=(e,t)=>e>t?e:t,Yn=e=>e!==0?e<0:1/e<0,Qn=1,Zn=2,rn=4,sn=8,ne=32,ot=64,L=128,fi=1<<29,Ce=31,on=63,Et=127,pi=2147483647,tr=Number.MAX_SAFE_INTEGER,mi=Number.isInteger||(e=>typeof e=="number"&&isFinite(e)&&pt(e)===e),bi=e=>e.toLowerCase(),yi=/^\s*/g,wi=e=>e.replace(yi,""),ki=/([A-Z])/g,er=(e,t)=>wi(e.replace(ki,n=>`${t}${bi(n)}`)),Si=e=>{const t=unescape(encodeURIComponent(e)),n=t.length,r=new Uint8Array(n);for(let s=0;s<n;s++)r[s]=t.codePointAt(s);return r},re=typeof TextEncoder<"u"?new TextEncoder:null,_i=re?e=>re.encode(e):Si;let se=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});se&&se.decode(new Uint8Array).length===1&&(se=null);const vi=(e,t)=>gi(t,()=>e).join("");class ie{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const Jt=()=>new ie,xi=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t},G=e=>{const t=new Uint8Array(xi(e));let n=0;for(let r=0;r<e.bufs.length;r++){const s=e.bufs[r];t.set(s,n),n+=s.length}return t.set(new Uint8Array(e.cbuf.buffer,0,e.cpos),n),t},Ci=(e,t)=>{const n=e.cbuf.length;n-e.cpos<t&&(e.bufs.push(new Uint8Array(e.cbuf.buffer,0,e.cpos)),e.cbuf=new Uint8Array(Ct(n,t)*2),e.cpos=0)},N=(e,t)=>{const n=e.cbuf.length;e.cpos===n&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(n*2),e.cpos=0),e.cbuf[e.cpos++]=t},oe=N,m=(e,t)=>{for(;t>Et;)N(e,L|Et&t),t=pt(t/128);N(e,Et&t)},Ee=(e,t)=>{const n=Yn(t);for(n&&(t=-t),N(e,(t>on?L:0)|(n?ot:0)|on&t),t=pt(t/64);t>0;)N(e,(t>Et?L:0)|Et&t),t=pt(t/128)},cn=new Uint8Array(3e4),Ei=cn.length/3,Ai=(e,t)=>{if(t.length<Ei){const n=re.encodeInto(t,cn).written||0;m(e,n);for(let r=0;r<n;r++)N(e,cn[r])}else z(e,_i(t))},Di=(e,t)=>{const n=unescape(encodeURIComponent(t)),r=n.length;m(e,r);for(let s=0;s<r;s++)N(e,n.codePointAt(s))},At=re&&re.encodeInto?Ai:Di,Pi=(e,t)=>ce(e,G(t)),ce=(e,t)=>{const n=e.cbuf.length,r=e.cpos,s=Kn(n-r,t.length),i=t.length-s;e.cbuf.set(t.subarray(0,s),r),e.cpos+=s,i>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(Ct(n*2,i)),e.cbuf.set(t.subarray(s)),e.cpos=i)},z=(e,t)=>{m(e,t.byteLength),ce(e,t)},ln=(e,t)=>{Ci(e,t);const n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},Ni=(e,t)=>ln(e,4).setFloat32(0,t,!1),Ii=(e,t)=>ln(e,8).setFloat64(0,t,!1),Mi=(e,t)=>ln(e,8).setBigInt64(0,t,!1),nr=new DataView(new ArrayBuffer(4)),Ti=e=>(nr.setFloat32(0,e),nr.getFloat32(0)===e),le=(e,t)=>{switch(typeof t){case"string":N(e,119),At(e,t);break;case"number":mi(t)&&xe(t)<=pi?(N(e,125),Ee(e,t)):Ti(t)?(N(e,124),Ni(e,t)):(N(e,123),Ii(e,t));break;case"bigint":N(e,122),Mi(e,t);break;case"object":if(t===null)N(e,126);else if(en(t)){N(e,117),m(e,t.length);for(let n=0;n<t.length;n++)le(e,t[n])}else if(t instanceof Uint8Array)N(e,116),z(e,t);else{N(e,118);const n=Object.keys(t);m(e,n.length);for(let r=0;r<n.length;r++){const s=n[r];At(e,s),le(e,t[s])}}break;case"boolean":N(e,t?120:121);break;default:N(e,127)}};class rr extends ie{constructor(t){super(),this.w=t,this.s=null,this.count=0}write(t){this.s===t?this.count++:(this.count>0&&m(this,this.count-1),this.count=1,this.w(this,t),this.s=t)}}const sr=e=>{e.count>0&&(Ee(e.encoder,e.count===1?e.s:-e.s),e.count>1&&m(e.encoder,e.count-2))};class Ae{constructor(){this.encoder=new ie,this.s=0,this.count=0}write(t){this.s===t?this.count++:(sr(this),this.count=1,this.s=t)}toUint8Array(){return sr(this),G(this.encoder)}}const ir=e=>{if(e.count>0){const t=e.diff*2+(e.count===1?0:1);Ee(e.encoder,t),e.count>1&&m(e.encoder,e.count-2)}};class an{constructor(){this.encoder=new ie,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(ir(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return ir(this),G(this.encoder)}}class Oi{constructor(){this.sarr=[],this.s="",this.lensE=new Ae}write(t){this.s+=t,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(t.length)}toUint8Array(){const t=new ie;return this.sarr.push(this.s),this.s="",At(t,this.sarr.join("")),ce(t,this.lensE.toUint8Array()),G(t)}}const mt=e=>new Error(e),Z=()=>{throw mt("Method unimplemented")},j=()=>{throw mt("Unexpected case")},or=mt("Unexpected end of array"),cr=mt("Integer out of Range");class De{constructor(t){this.arr=t,this.pos=0}}const T=e=>new De(e),lr=e=>e.pos!==e.arr.length,Ui=(e,t)=>{const n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},W=e=>Ui(e,S(e)),Ht=e=>e.arr[e.pos++],S=e=>{let t=0,n=1;const r=e.arr.length;for(;e.pos<r;){const s=e.arr[e.pos++];if(t=t+(s&Et)*n,n*=128,s<L)return t;if(t>tr)throw cr}throw or},Pe=e=>{let t=e.arr[e.pos++],n=t&on,r=64;const s=(t&ot)>0?-1:1;if((t&L)===0)return s*n;const i=e.arr.length;for(;e.pos<i;){if(t=e.arr[e.pos++],n=n+(t&Et)*r,r*=128,t<L)return s*n;if(n>tr)throw cr}throw or},Dt=se?e=>se.decode(W(e)):e=>{let t=S(e);if(t===0)return"";{let n=String.fromCodePoint(Ht(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(Ht(e));else for(;t>0;){const r=t<1e4?t:1e4,s=e.arr.subarray(e.pos,e.pos+r);e.pos+=r,n+=String.fromCodePoint.apply(null,s),t-=r}return decodeURIComponent(escape(n))}},dn=(e,t)=>{const n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},Li=[e=>{},e=>null,Pe,e=>dn(e,4).getFloat32(0,!1),e=>dn(e,8).getFloat64(0,!1),e=>dn(e,8).getBigInt64(0,!1),e=>!1,e=>!0,Dt,e=>{const t=S(e),n={};for(let r=0;r<t;r++){const s=Dt(e);n[s]=ae(e)}return n},e=>{const t=S(e),n=[];for(let r=0;r<t;r++)n.push(ae(e));return n},W],ae=e=>Li[127-Ht(e)](e);class ar extends De{constructor(t,n){super(t),this.reader=n,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),lr(this)?this.count=S(this)+1:this.count=-1),this.count--,this.s}}class Ne extends De{constructor(t){super(t),this.s=0,this.count=0}read(){if(this.count===0){this.s=Pe(this);const t=Yn(this.s);this.count=1,t&&(this.s=-this.s,this.count=S(this)+2)}return this.count--,this.s}}class hn extends De{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const t=Pe(this),n=t&1;this.diff=pt(t/2),this.count=1,n&&(this.count=S(this)+2)}return this.s+=this.diff,this.count--,this.s}}class Fi{constructor(t){this.decoder=new Ne(t),this.str=Dt(this.decoder),this.spos=0}read(){const t=this.spos+this.decoder.read(),n=this.str.slice(this.spos,t);return this.spos=t,n}}const Ri=crypto.getRandomValues.bind(crypto),dr=()=>Ri(new Uint32Array(1))[0],ji="10000000-1000-4000-8000"+-1e11,Vi=()=>ji.replace(/[018]/g,e=>(e^dr()&15>>e/4).toString(16)),Bi=Date.now,hr=e=>new Promise(e);Promise.all.bind(Promise);const zi=e=>e===void 0?null:e;class Wi{constructor(){this.map=new Map}setItem(t,n){this.map.set(t,n)}getItem(t){return this.map.get(t)}}let ur=new Wi,Ji=!0;try{typeof localStorage<"u"&&localStorage&&(ur=localStorage,Ji=!1)}catch{}const Hi=ur,Gi=Object.assign,Xi=Object.keys,qi=(e,t)=>{for(const n in e)t(e[n],n)},gr=e=>Xi(e).length,$i=e=>{for(const t in e)return!1;return!0},Ki=(e,t)=>{for(const n in e)if(!t(e[n],n))return!1;return!0},Yi=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),Qi=(e,t)=>e===t||gr(e)===gr(t)&&Ki(e,(n,r)=>(n!==void 0||Yi(t,r))&&t[r]===n),Zi=Object.freeze,fr=e=>{for(const t in e){const n=e[t];(typeof n=="object"||typeof n=="function")&&fr(e[t])}return Zi(e)},un=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&un(e,t,n+1)}},pr=e=>e,to=(e,t)=>t.includes(e),de=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]";let tt;const eo=()=>{if(tt===void 0)if(de){tt=U();const e=process.argv;let t=null;for(let n=0;n<e.length;n++){const r=e[n];r[0]==="-"?(t!==null&&tt.set(t,""),t=r):t!==null&&(tt.set(t,r),t=null)}t!==null&&tt.set(t,"")}else typeof location=="object"?(tt=U(),(location.search||"?").slice(1).split("&").forEach(e=>{if(e.length!==0){const[t,n]=e.split("=");tt.set(`--${er(t,"-")}`,n),tt.set(`-${er(t,"-")}`,n)}})):tt=U();return tt},gn=e=>eo().has(e),Ie=e=>zi(de?process.env[e.toUpperCase().replaceAll("-","_")]:Hi.getItem(e)),mr=e=>gn("--"+e)||Ie(e)!==null;mr("production");const no=de&&to(process.env.FORCE_COLOR,["true","1","2"])||!gn("--no-colors")&&!mr("no-color")&&(!de||process.stdout.isTTY)&&(!de||gn("--color")||Ie("COLORTERM")!==null||(Ie("TERM")||"").includes("color")),ro=e=>new Uint8Array(e),so=e=>{const t=ro(e.byteLength);return t.set(e),t};class io{constructor(t,n){this.left=t,this.right=n}}const ct=(e,t)=>new io(e,t);typeof DOMParser<"u"&&new DOMParser;const oo=e=>ai(e,(t,n)=>`${n}:${t};`).join(""),lt=Symbol,br=lt(),yr=lt(),co=lt(),lo=lt(),ao=lt(),wr=lt(),ho=lt(),fn=lt(),uo=lt(),go=e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());const t=[],n=[];let r=0;for(;r<e.length;r++){const s=e[r];if(s===void 0)break;if(s.constructor===String||s.constructor===Number)t.push(s);else if(s.constructor===Object)break}for(r>0&&n.push(t.join(""));r<e.length;r++){const s=e[r];s instanceof Symbol||n.push(s)}return n},fo={[br]:ct("font-weight","bold"),[yr]:ct("font-weight","normal"),[co]:ct("color","blue"),[ao]:ct("color","green"),[lo]:ct("color","grey"),[wr]:ct("color","red"),[ho]:ct("color","purple"),[fn]:ct("color","orange"),[uo]:ct("color","black")},kr=no?e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());const t=[],n=[],r=U();let s=[],i=0;for(;i<e.length;i++){const o=e[i],c=fo[o];if(c!==void 0)r.set(c.left,c.right);else{if(o===void 0)break;if(o.constructor===String||o.constructor===Number){const l=oo(r);i>0||l.length>0?(t.push("%c"+o),n.push(l)):t.push(o)}else break}}for(i>0&&(s=n,s.unshift(t.join("")));i<e.length;i++){const o=e[i];o instanceof Symbol||s.push(o)}return s}:go,pn=(...e)=>{[...kr(e)],_r.forEach(t=>t.print(e))},Sr=(...e)=>{console.warn(...kr(e)),e.unshift(fn),_r.forEach(t=>t.print(e))},_r=Wt(),vr=e=>({[Symbol.iterator](){return this},next:e}),po=(e,t)=>vr(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),mn=(e,t)=>vr(()=>{const{done:n,value:r}=e.next();return{done:n,value:n?void 0:t(r)}});class mo extends nn{constructor(t,n){super(),this.doc=t,this.awareness=n}}class bn{constructor(t,n){this.clock=t,this.len=n}}class Gt{constructor(){this.clients=new Map}}const Pt=(e,t,n)=>t.clients.forEach((r,s)=>{const i=e.doc.store.clients.get(s);if(i!=null){const o=i[i.length-1],c=o.id.clock+o.length;for(let l=0,d=r[l];l<r.length&&d.clock<c;d=r[++l])zr(e,i,d.clock,d.len,n)}}),bo=(e,t)=>{let n=0,r=e.length-1;for(;n<=r;){const s=pt((n+r)/2),i=e[s],o=i.clock;if(o<=t){if(t<o+i.len)return s;n=s+1}else r=s-1}return null},Nt=(e,t)=>{const n=e.clients.get(t.client);return n!==void 0&&bo(n,t.clock)!==null},yn=e=>{e.clients.forEach(t=>{t.sort((s,i)=>s.clock-i.clock);let n,r;for(n=1,r=1;n<t.length;n++){const s=t[r-1],i=t[n];s.clock+s.len>=i.clock?s.len=Ct(s.len,i.clock+i.len-s.clock):(r<n&&(t[r]=i),r++)}t.length=r})},It=e=>{const t=new Gt;for(let n=0;n<e.length;n++)e[n].clients.forEach((r,s)=>{if(!t.clients.has(s)){const i=r.slice();for(let o=n+1;o<e.length;o++)hi(i,e[o].clients.get(s)||[]);t.clients.set(s,i)}});return yn(t),t},he=(e,t,n,r)=>{B(e.clients,t,()=>[]).push(new bn(n,r))},Me=()=>new Gt,wn=e=>{const t=Me();return e.clients.forEach((n,r)=>{const s=[];for(let i=0;i<n.length;i++){const o=n[i];if(o.deleted){const c=o.id.clock;let l=o.length;if(i+1<n.length)for(let d=n[i+1];i+1<n.length&&d.deleted;d=n[++i+1])l+=d.length;s.push(new bn(c,l))}}s.length>0&&t.clients.set(r,s)}),t},et=(e,t)=>{m(e.restEncoder,t.clients.size),ft(t.clients.entries()).sort((n,r)=>r[0]-n[0]).forEach(([n,r])=>{e.resetDsCurVal(),m(e.restEncoder,n);const s=r.length;m(e.restEncoder,s);for(let i=0;i<s;i++){const o=r[i];e.writeDsClock(o.clock),e.writeDsLen(o.len)}})},at=e=>{const t=new Gt,n=S(e.restDecoder);for(let r=0;r<n;r++){e.resetDsCurVal();const s=S(e.restDecoder),i=S(e.restDecoder);if(i>0){const o=B(t.clients,s,()=>[]);for(let c=0;c<i;c++)o.push(new bn(e.readDsClock(),e.readDsLen()))}}return t},xr=(e,t,n)=>{const r=new Gt,s=S(e.restDecoder);for(let i=0;i<s;i++){e.resetDsCurVal();const o=S(e.restDecoder),c=S(e.restDecoder),l=n.clients.get(o)||[],d=A(n,o);for(let a=0;a<c;a++){const h=e.readDsClock(),u=h+e.readDsLen();if(h<d){d<u&&he(r,o,d,u-d);let g=q(l,h),f=l[g];for(!f.deleted&&f.id.clock<h&&(l.splice(g+1,0,Ge(t,f,h-f.id.clock)),g++);g<l.length&&(f=l[g++],f.id.clock<u);)f.deleted||(u<f.id.clock+f.length&&l.splice(g,0,Ge(t,f,u-f.id.clock)),f.delete(t))}else he(r,o,h,u-h)}}if(r.clients.size>0){const i=new Y;return m(i.restEncoder,0),et(i,r),i.toUint8Array()}return null},Cr=(e,t)=>{if(e.clients.size!==t.clients.size)return!1;for(const[n,r]of e.clients.entries()){const s=t.clients.get(n);if(s===void 0||r.length!==s.length)return!1;for(let i=0;i<r.length;i++){const o=r[i],c=s[i];if(o.clock!==c.clock||o.len!==c.len)return!1}}return!0},Er=dr;class nt extends nn{constructor({guid:t=Vi(),collectionid:n=null,gc:r=!0,gcFilter:s=()=>!0,meta:i=null,autoLoad:o=!1,shouldLoad:c=!0}={}){super(),this.gc=r,this.gcFilter=s,this.clientID=Er(),this.guid=t,this.collectionid=n,this.share=new Map,this.store=new Vr,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=c,this.autoLoad=o,this.meta=i,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=hr(d=>{this.on("load",()=>{this.isLoaded=!0,d(this)})});const l=()=>hr(d=>{const a=h=>{(h===void 0||h===!0)&&(this.off("sync",a),d())};this.on("sync",a)});this.on("sync",d=>{d===!1&&this.isSynced&&(this.whenSynced=l()),this.isSynced=d===void 0||d===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=l()}load(){const t=this._item;t!==null&&!this.shouldLoad&&E(t.parent.doc,n=>{n.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(ft(this.subdocs).map(t=>t.guid))}transact(t,n=null){return E(this,t,n)}get(t,n=P){const r=B(this.share,t,()=>{const i=new n;return i._integrate(this,null),i}),s=r.constructor;if(n!==P&&s!==n)if(s===P){const i=new n;i._map=r._map,r._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=i}),i._start=r._start;for(let o=i._start;o!==null;o=o.right)o.parent=i;return i._length=r._length,this.share.set(t,i),i._integrate(this,null),i}else throw new Error(`Type with the name ${t} has already been defined with a different constructor`);return r}getArray(t=""){return this.get(t,dt)}getText(t=""){return this.get(t,Ut)}getMap(t=""){return this.get(t,St)}getXmlElement(t=""){return this.get(t,rt)}getXmlFragment(t=""){return this.get(t,vt)}toJSON(){const t={};return this.share.forEach((n,r)=>{t[r]=n.toJSON()}),t}destroy(){this.isDestroyed=!0,ft(this.subdocs).forEach(n=>n.destroy());const t=this._item;if(t!==null){this._item=null;const n=t.content;n.doc=new nt({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,E(t.parent.doc,r=>{const s=n.doc;t.deleted||r.subdocsAdded.add(s),r.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}}class ue{constructor(t){this.restDecoder=t}resetDsCurVal(){}readDsClock(){return S(this.restDecoder)}readDsLen(){return S(this.restDecoder)}}class X extends ue{readLeftID(){return b(S(this.restDecoder),S(this.restDecoder))}readRightID(){return b(S(this.restDecoder),S(this.restDecoder))}readClient(){return S(this.restDecoder)}readInfo(){return Ht(this.restDecoder)}readString(){return Dt(this.restDecoder)}readParentInfo(){return S(this.restDecoder)===1}readTypeRef(){return S(this.restDecoder)}readLen(){return S(this.restDecoder)}readAny(){return ae(this.restDecoder)}readBuf(){return so(W(this.restDecoder))}readJSON(){return JSON.parse(Dt(this.restDecoder))}readKey(){return Dt(this.restDecoder)}}class Ar{constructor(t){this.dsCurrVal=0,this.restDecoder=t}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=S(this.restDecoder),this.dsCurrVal}readDsLen(){const t=S(this.restDecoder)+1;return this.dsCurrVal+=t,t}}class J extends Ar{constructor(t){super(t),this.keys=[],S(t),this.keyClockDecoder=new hn(W(t)),this.clientDecoder=new Ne(W(t)),this.leftClockDecoder=new hn(W(t)),this.rightClockDecoder=new hn(W(t)),this.infoDecoder=new ar(W(t),Ht),this.stringDecoder=new Fi(W(t)),this.parentInfoDecoder=new ar(W(t),Ht),this.typeRefDecoder=new Ne(W(t)),this.lenDecoder=new Ne(W(t))}readLeftID(){return new Mt(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Mt(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return this.parentInfoDecoder.read()===1}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return ae(this.restDecoder)}readBuf(){return W(this.restDecoder)}readJSON(){return ae(this.restDecoder)}readKey(){const t=this.keyClockDecoder.read();if(t<this.keys.length)return this.keys[t];{const n=this.stringDecoder.read();return this.keys.push(n),n}}}class Xt{constructor(){this.restEncoder=Jt()}toUint8Array(){return G(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){m(this.restEncoder,t)}writeDsLen(t){m(this.restEncoder,t)}}class bt extends Xt{writeLeftID(t){m(this.restEncoder,t.client),m(this.restEncoder,t.clock)}writeRightID(t){m(this.restEncoder,t.client),m(this.restEncoder,t.clock)}writeClient(t){m(this.restEncoder,t)}writeInfo(t){oe(this.restEncoder,t)}writeString(t){At(this.restEncoder,t)}writeParentInfo(t){m(this.restEncoder,t?1:0)}writeTypeRef(t){m(this.restEncoder,t)}writeLen(t){m(this.restEncoder,t)}writeAny(t){le(this.restEncoder,t)}writeBuf(t){z(this.restEncoder,t)}writeJSON(t){At(this.restEncoder,JSON.stringify(t))}writeKey(t){At(this.restEncoder,t)}}class Te{constructor(){this.restEncoder=Jt(),this.dsCurrVal=0}toUint8Array(){return G(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){const n=t-this.dsCurrVal;this.dsCurrVal=t,m(this.restEncoder,n)}writeDsLen(t){t===0&&j(),m(this.restEncoder,t-1),this.dsCurrVal+=t}}class Y extends Te{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new an,this.clientEncoder=new Ae,this.leftClockEncoder=new an,this.rightClockEncoder=new an,this.infoEncoder=new rr(oe),this.stringEncoder=new Oi,this.parentInfoEncoder=new rr(oe),this.typeRefEncoder=new Ae,this.lenEncoder=new Ae}toUint8Array(){const t=Jt();return m(t,0),z(t,this.keyClockEncoder.toUint8Array()),z(t,this.clientEncoder.toUint8Array()),z(t,this.leftClockEncoder.toUint8Array()),z(t,this.rightClockEncoder.toUint8Array()),z(t,G(this.infoEncoder)),z(t,this.stringEncoder.toUint8Array()),z(t,G(this.parentInfoEncoder)),z(t,this.typeRefEncoder.toUint8Array()),z(t,this.lenEncoder.toUint8Array()),ce(t,G(this.restEncoder)),G(t)}writeLeftID(t){this.clientEncoder.write(t.client),this.leftClockEncoder.write(t.clock)}writeRightID(t){this.clientEncoder.write(t.client),this.rightClockEncoder.write(t.clock)}writeClient(t){this.clientEncoder.write(t)}writeInfo(t){this.infoEncoder.write(t)}writeString(t){this.stringEncoder.write(t)}writeParentInfo(t){this.parentInfoEncoder.write(t?1:0)}writeTypeRef(t){this.typeRefEncoder.write(t)}writeLen(t){this.lenEncoder.write(t)}writeAny(t){le(this.restEncoder,t)}writeBuf(t){z(this.restEncoder,t)}writeJSON(t){le(this.restEncoder,t)}writeKey(t){const n=this.keyMap.get(t);n===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(t)):this.keyClockEncoder.write(n)}}const yo=(e,t,n,r)=>{r=Ct(r,t[0].id.clock);const s=q(t,r);m(e.restEncoder,t.length-s),e.writeClient(n),m(e.restEncoder,r);const i=t[s];i.write(e,r-i.id.clock);for(let o=s+1;o<t.length;o++)t[o].write(e,0)},kn=(e,t,n)=>{const r=new Map;n.forEach((s,i)=>{A(t,i)>s&&r.set(i,s)}),fe(t).forEach((s,i)=>{n.has(i)||r.set(i,0)}),m(e.restEncoder,r.size),ft(r.entries()).sort((s,i)=>i[0]-s[0]).forEach(([s,i])=>{yo(e,t.clients.get(s),s,i)})},wo=(e,t)=>{const n=U(),r=S(e.restDecoder);for(let s=0;s<r;s++){const i=S(e.restDecoder),o=new Array(i),c=e.readClient();let l=S(e.restDecoder);n.set(c,{i:0,refs:o});for(let d=0;d<i;d++){const a=e.readInfo();switch(Ce&a){case 0:{const h=e.readLen();o[d]=new V(b(c,l),h),l+=h;break}case 10:{const h=S(e.restDecoder);o[d]=new F(b(c,l),h),l+=h;break}default:{const h=(a&(ot|L))===0,u=new x(b(c,l),null,(a&L)===L?e.readLeftID():null,null,(a&ot)===ot?e.readRightID():null,h?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,h&&(a&ne)===ne?e.readString():null,Ts(e,a));o[d]=u,l+=u.length}}}}return n},ko=(e,t,n)=>{const r=[];let s=ft(n.keys()).sort((g,f)=>g-f);if(s.length===0)return null;const i=()=>{if(s.length===0)return null;let g=n.get(s[s.length-1]);for(;g.refs.length===g.i;)if(s.pop(),s.length>0)g=n.get(s[s.length-1]);else return null;return g};let o=i();if(o===null)return null;const c=new Vr,l=new Map,d=(g,f)=>{const p=l.get(g);(p==null||p>f)&&l.set(g,f)};let a=o.refs[o.i++];const h=new Map,u=()=>{for(const g of r){const f=g.id.client,p=n.get(f);p?(p.i--,c.clients.set(f,p.refs.slice(p.i)),n.delete(f),p.i=0,p.refs=[]):c.clients.set(f,[g]),s=s.filter(_=>_!==f)}r.length=0};for(;;){if(a.constructor!==F){const g=B(h,a.id.client,()=>A(t,a.id.client))-a.id.clock;if(g<0)r.push(a),d(a.id.client,a.id.clock-1),u();else{const f=a.getMissing(e,t);if(f!==null){r.push(a);const p=n.get(f)||{refs:[],i:0};if(p.refs.length===p.i)d(f,A(t,f)),u();else{a=p.refs[p.i++];continue}}else(g===0||g<a.length)&&(a.integrate(e,g),h.set(a.id.client,a.id.clock+a.length))}}if(r.length>0)a=r.pop();else if(o!==null&&o.i<o.refs.length)a=o.refs[o.i++];else{if(o=i(),o===null)break;a=o.refs[o.i++]}}if(c.clients.size>0){const g=new Y;return kn(g,c,new Map),m(g.restEncoder,0),{missing:l,update:g.toUint8Array()}}return null},So=(e,t)=>kn(e,t.doc.store,t.beforeState),Sn=(e,t,n,r=new J(e))=>E(t,s=>{s.local=!1;let i=!1;const o=s.doc,c=o.store,l=wo(r,o),d=ko(s,c,l),a=c.pendingStructs;if(a){for(const[u,g]of a.missing)if(g<A(c,u)){i=!0;break}if(d){for(const[u,g]of d.missing){const f=a.missing.get(u);(f==null||f>g)&&a.missing.set(u,g)}a.update=pe([a.update,d.update])}}else c.pendingStructs=d;const h=xr(r,s,c);if(c.pendingDs){const u=new J(T(c.pendingDs));S(u.restDecoder);const g=xr(u,s,c);h&&g?c.pendingDs=pe([h,g]):c.pendingDs=h||g}else c.pendingDs=h;if(i){const u=c.pendingStructs.update;c.pendingStructs=null,Oe(s.doc,u)}},n,!1),_o=(e,t,n)=>Sn(e,t,n,new X(e)),Oe=(e,t,n,r=J)=>{const s=T(t);Sn(s,e,n,new r(s))},Dr=(e,t,n)=>Oe(e,t,n,X),vo=(e,t,n=new Map)=>{kn(e,t.store,n),et(e,wn(t.store))},Pr=(e,t=new Uint8Array([0]),n=new Y)=>{const r=_n(t);vo(n,e,r);const s=[n.toUint8Array()];if(e.store.pendingDs&&s.push(e.store.pendingDs),e.store.pendingStructs&&s.push(In(e.store.pendingStructs.update,t)),s.length>1){if(n.constructor===bt)return Zr(s.map((i,o)=>o===0?i:ss(i)));if(n.constructor===Y)return pe(s)}return s[0]},xo=(e,t)=>Pr(e,t,new bt),Nr=e=>{const t=new Map,n=S(e.restDecoder);for(let r=0;r<n;r++){const s=S(e.restDecoder),i=S(e.restDecoder);t.set(s,i)}return t},_n=e=>Nr(new ue(T(e))),vn=(e,t)=>(m(e.restEncoder,t.size),ft(t.entries()).sort((n,r)=>r[0]-n[0]).forEach(([n,r])=>{m(e.restEncoder,n),m(e.restEncoder,r)}),e),Co=(e,t)=>vn(e,fe(t.store)),Eo=(e,t=new Te)=>(e instanceof Map?vn(t,e):Co(t,e),t.toUint8Array()),Ao=e=>Eo(e,new Xt);class Do{constructor(){this.l=[]}}const Ir=()=>new Do,Mr=(e,t)=>e.l.push(t),Tr=(e,t)=>{const n=e.l,r=n.length;e.l=n.filter(s=>t!==s),r===e.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},Or=(e,t,n)=>un(e.l,[t,n]);class Mt{constructor(t,n){this.client=t,this.clock=n}}const Tt=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,b=(e,t)=>new Mt(e,t),Ur=(e,t)=>{m(e,t.client),m(e,t.clock)},Lr=e=>b(S(e),S(e)),xn=e=>{for(const[t,n]of e.doc.share.entries())if(n===e)return t;throw j()},ge=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1},Po=e=>{const t=[];let n=e._start;for(;n;)t.push(n),n=n.right;t.filter(r=>!r.deleted).map(r=>r.content)};class No{constructor(t,n=t.getMap("users")){const r=new Map;this.yusers=n,this.doc=t,this.clients=new Map,this.dss=r;const s=(i,o)=>{const c=i.get("ds"),l=i.get("ids"),d=a=>this.clients.set(a,o);c.observe(a=>{a.changes.added.forEach(h=>{h.content.getContent().forEach(u=>{u instanceof Uint8Array&&this.dss.set(o,It([this.dss.get(o)||Me(),at(new ue(T(u)))]))})})}),this.dss.set(o,It(c.map(a=>at(new ue(T(a)))))),l.observe(a=>a.changes.added.forEach(h=>h.content.getContent().forEach(d))),l.forEach(d)};n.observe(i=>{i.keysChanged.forEach(o=>s(n.get(o),o))}),n.forEach(s)}setUserMapping(t,n,r,{filter:s=()=>!0}={}){const i=this.yusers;let o=i.get(r);o||(o=new St,o.set("ids",new dt),o.set("ds",new dt),i.set(r,o)),o.get("ids").push([n]),i.observe(c=>{setTimeout(()=>{const l=i.get(r);if(l!==o){o=l,this.clients.forEach((h,u)=>{r===h&&o.get("ids").push([u])});const d=new Xt,a=this.dss.get(r);a&&(et(d,a),o.get("ds").push([d.toUint8Array()]))}},0)}),t.on("afterTransaction",c=>{setTimeout(()=>{const l=o.get("ds"),d=c.deleteSet;if(c.local&&d.clients.size>0&&s(c,d)){const a=new Xt;et(a,d),l.push([a.toUint8Array()])}})})}getUserByClientId(t){return this.clients.get(t)||null}getUserByDeletedId(t){for(const[n,r]of this.dss.entries())if(Nt(r,t))return n;return null}}class Ue{constructor(t,n,r,s=0){this.type=t,this.tname=n,this.item=r,this.assoc=s}}const Io=e=>{const t={};return e.type&&(t.type=e.type),e.tname&&(t.tname=e.tname),e.item&&(t.item=e.item),e.assoc!=null&&(t.assoc=e.assoc),t},Mo=e=>new Ue(e.type==null?null:b(e.type.client,e.type.clock),e.tname??null,e.item==null?null:b(e.item.client,e.item.clock),e.assoc==null?0:e.assoc);class Fr{constructor(t,n,r=0){this.type=t,this.index=n,this.assoc=r}}const To=(e,t,n=0)=>new Fr(e,t,n),Le=(e,t,n)=>{let r=null,s=null;return e._item===null?s=xn(e):r=b(e._item.id.client,e._item.id.clock),new Ue(r,s,t,n)},Oo=(e,t,n=0)=>{let r=e._start;if(n<0){if(t===0)return Le(e,null,n);t--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>t)return Le(e,b(r.id.client,r.id.clock+t),n);t-=r.length}if(r.right===null&&n<0)return Le(e,r.lastId,n);r=r.right}return Le(e,null,n)},Uo=(e,t)=>{const{type:n,tname:r,item:s,assoc:i}=t;if(s!==null)m(e,0),Ur(e,s);else if(r!==null)oe(e,1),At(e,r);else if(n!==null)oe(e,2),Ur(e,n);else throw j();return Ee(e,i),e},Lo=e=>{const t=Jt();return Uo(t,e),G(t)},Fo=e=>{let t=null,n=null,r=null;switch(S(e)){case 0:r=Lr(e);break;case 1:n=Dt(e);break;case 2:t=Lr(e)}const s=lr(e)?Pe(e):0;return new Ue(t,n,r,s)},Ro=e=>Fo(T(e)),jo=(e,t)=>{const n=Ot(e,t),r=t.clock-n.id.clock;return{item:n,diff:r}},Vo=(e,t,n=!0)=>{const r=t.store,s=e.item,i=e.type,o=e.tname,c=e.assoc;let l=null,d=0;if(s!==null){if(A(r,s.client)<=s.clock)return null;const a=n?jn(r,s):jo(r,s),h=a.item;if(!(h instanceof x))return null;if(l=h.parent,l._item===null||!l._item.deleted){d=h.deleted||!h.countable?0:a.diff+(c>=0?0:1);let u=h.left;for(;u!==null;)!u.deleted&&u.countable&&(d+=u.length),u=u.left}}else{if(o!==null)l=t.get(o);else if(i!==null){if(A(r,i.client)<=i.clock)return null;const{item:a}=n?jn(r,i):{item:Ot(r,i)};if(a instanceof x&&a.content instanceof K)l=a.content.type;else return null}else throw j();c>=0?d=l._length:d=0}return To(l,d,e.assoc)},Bo=(e,t)=>e===t||e!==null&&t!==null&&e.tname===t.tname&&Tt(e.item,t.item)&&Tt(e.type,t.type)&&e.assoc===t.assoc;class Cn{constructor(t,n){this.ds=t,this.sv=n}}const zo=(e,t)=>{const n=e.ds.clients,r=t.ds.clients,s=e.sv,i=t.sv;if(s.size!==i.size||n.size!==r.size)return!1;for(const[o,c]of s.entries())if(i.get(o)!==c)return!1;for(const[o,c]of n.entries()){const l=r.get(o)||[];if(c.length!==l.length)return!1;for(let d=0;d<c.length;d++){const a=c[d],h=l[d];if(a.clock!==h.clock||a.len!==h.len)return!1}}return!0},Rr=(e,t=new Te)=>(et(t,e.ds),vn(t,e.sv),t.toUint8Array()),Wo=e=>Rr(e,new Xt),jr=(e,t=new Ar(T(e)))=>new Cn(at(t),Nr(t)),Jo=e=>jr(e,new ue(T(e))),En=(e,t)=>new Cn(e,t),Ho=En(Me(),new Map),Go=e=>En(wn(e.store),fe(e.store)),yt=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!Nt(t.ds,e.id),An=(e,t)=>{const n=B(e.meta,An,Wt),r=e.doc.store;n.has(t)||(t.sv.forEach((s,i)=>{s<A(r,i)&&O(e,b(i,s))}),Pt(e,t.ds,s=>{}),n.add(t))},Xo=(e,t,n=new nt)=>{if(e.gc)throw new Error("Garbage-collection must be disabled in `originDoc`!");const{sv:r,ds:s}=t,i=new Y;return e.transact(o=>{let c=0;r.forEach(l=>{l>0&&c++}),m(i.restEncoder,c);for(const[l,d]of r){if(d===0)continue;d<A(e.store,l)&&O(o,b(l,d));const a=e.store.clients.get(l)||[],h=q(a,d-1);m(i.restEncoder,h+1),i.writeClient(l),m(i.restEncoder,0);for(let u=0;u<=h;u++)a[u].write(i,0)}et(i,s)}),Oe(n,i.toUint8Array(),"snapshot"),n},qo=(e,t,n=J)=>{const r=new n(T(t)),s=new wt(r,!1);for(let o=s.curr;o!==null;o=s.next())if((e.sv.get(o.id.client)||0)<o.id.clock+o.length)return!1;const i=It([e.ds,at(r)]);return Cr(e.ds,i)},$o=(e,t)=>qo(e,t,X);class Vr{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const fe=e=>{const t=new Map;return e.clients.forEach((n,r)=>{const s=n[n.length-1];t.set(r,s.id.clock+s.length)}),t},A=(e,t)=>{const n=e.clients.get(t);if(n===void 0)return 0;const r=n[n.length-1];return r.id.clock+r.length},Br=(e,t)=>{let n=e.clients.get(t.id.client);if(n===void 0)n=[],e.clients.set(t.id.client,n);else{const r=n[n.length-1];if(r.id.clock+r.length!==t.id.clock)throw j()}n.push(t)},q=(e,t)=>{let n=0,r=e.length-1,s=e[r],i=s.id.clock;if(i===t)return r;let o=pt(t/(i+s.length-1)*r);for(;n<=r;){if(s=e[o],i=s.id.clock,i<=t){if(t<i+s.length)return o;n=o+1}else r=o-1;o=pt((n+r)/2)}throw j()},Ot=(e,t)=>{const n=e.clients.get(t.client);return n[q(n,t.clock)]},Dn=(e,t,n)=>{const r=q(t,n),s=t[r];return s.id.clock<n&&s instanceof x?(t.splice(r+1,0,Ge(e,s,n-s.id.clock)),r+1):r},O=(e,t)=>{const n=e.doc.store.clients.get(t.client);return n[Dn(e,n,t.clock)]},Pn=(e,t,n)=>{const r=t.clients.get(n.client),s=q(r,n.clock),i=r[s];return n.clock!==i.id.clock+i.length-1&&i.constructor!==V&&r.splice(s+1,0,Ge(e,i,n.clock-i.id.clock+1)),i},Ko=(e,t,n)=>{const r=e.clients.get(t.id.client);r[q(r,t.id.clock)]=n},zr=(e,t,n,r,s)=>{if(r===0)return;const i=n+r;let o=Dn(e,t,n),c;do c=t[o++],i<c.id.clock+c.length&&Dn(e,t,i),s(c);while(o<t.length&&t[o].id.clock<i)};class Wr{constructor(t,n,r){this.doc=t,this.deleteSet=new Gt,this.beforeState=fe(t.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=n,this.meta=new Map,this.local=r,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const Jr=(e,t)=>t.deleteSet.clients.size===0&&!di(t.afterState,(n,r)=>t.beforeState.get(r)!==n)?!1:(yn(t.deleteSet),So(e,t),et(e,t.deleteSet),!0),Hr=(e,t,n)=>{const r=t._item;(r===null||r.id.clock<(e.beforeState.get(r.id.client)||0)&&!r.deleted)&&B(e.changed,t,Wt).add(n)},Fe=(e,t)=>{let n=e[t],r=e[t-1],s=t;for(;s>0;n=r,r=e[--s-1]){if(r.deleted===n.deleted&&r.constructor===n.constructor&&r.mergeWith(n)){n instanceof x&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,r);continue}break}const i=t-s;return i&&e.splice(t+1-i,i),i},Gr=(e,t,n)=>{for(const[r,s]of e.clients.entries()){const i=t.clients.get(r);for(let o=s.length-1;o>=0;o--){const c=s[o],l=c.clock+c.len;for(let d=q(i,c.clock),a=i[d];d<i.length&&a.id.clock<l;a=i[++d]){const h=i[d];if(c.clock+c.len<=h.id.clock)break;h instanceof x&&h.deleted&&!h.keep&&n(h)&&h.gc(t,!1)}}}},Xr=(e,t)=>{e.clients.forEach((n,r)=>{const s=t.clients.get(r);for(let i=n.length-1;i>=0;i--){const o=n[i],c=Kn(s.length-1,1+q(s,o.clock+o.len-1));for(let l=c,d=s[l];l>0&&d.id.clock>=o.clock;d=s[l])l-=1+Fe(s,l)}})},Yo=(e,t,n)=>{Gr(e,t,n),Xr(e,t)},qr=(e,t)=>{if(t<e.length){const n=e[t],r=n.doc,s=r.store,i=n.deleteSet,o=n._mergeStructs;try{yn(i),n.afterState=fe(n.doc.store),r.emit("beforeObserverCalls",[n,r]);const c=[];n.changed.forEach((l,d)=>c.push(()=>{(d._item===null||!d._item.deleted)&&d._callObserver(n,l)})),c.push(()=>{n.changedParentTypes.forEach((l,d)=>{d._dEH.l.length>0&&(d._item===null||!d._item.deleted)&&(l=l.filter(a=>a.target._item===null||!a.target._item.deleted),l.forEach(a=>{a.currentTarget=d,a._path=null}),l.sort((a,h)=>a.path.length-h.path.length),Or(d._dEH,l,n))})}),c.push(()=>r.emit("afterTransaction",[n,r])),un(c,[]),n._needFormattingCleanup&&_c(n)}finally{r.gc&&Gr(i,s,r.gcFilter),Xr(i,s),n.afterState.forEach((a,h)=>{const u=n.beforeState.get(h)||0;if(u!==a){const g=s.clients.get(h),f=Ct(q(g,u),1);for(let p=g.length-1;p>=f;)p-=1+Fe(g,p)}});for(let a=o.length-1;a>=0;a--){const{client:h,clock:u}=o[a].id,g=s.clients.get(h),f=q(g,u);f+1<g.length&&Fe(g,f+1)>1||f>0&&Fe(g,f)}if(!n.local&&n.afterState.get(r.clientID)!==n.beforeState.get(r.clientID)&&(pn(fn,br,"[yjs] ",yr,wr,"Changed the client-id because another client seems to be using it."),r.clientID=Er()),r.emit("afterTransactionCleanup",[n,r]),r._observers.has("update")){const a=new bt;Jr(a,n)&&r.emit("update",[a.toUint8Array(),n.origin,r,n])}if(r._observers.has("updateV2")){const a=new Y;Jr(a,n)&&r.emit("updateV2",[a.toUint8Array(),n.origin,r,n])}const{subdocsAdded:c,subdocsLoaded:l,subdocsRemoved:d}=n;(c.size>0||d.size>0||l.size>0)&&(c.forEach(a=>{a.clientID=r.clientID,a.collectionid==null&&(a.collectionid=r.collectionid),r.subdocs.add(a)}),d.forEach(a=>r.subdocs.delete(a)),r.emit("subdocs",[{loaded:l,added:c,removed:d},r,n]),d.forEach(a=>a.destroy())),e.length<=t+1?(r._transactionCleanups=[],r.emit("afterAllTransactions",[r,e])):qr(e,t+1)}}},E=(e,t,n=null,r=!0)=>{const s=e._transactionCleanups;let i=!1,o=null;e._transaction===null&&(i=!0,e._transaction=new Wr(e,n,r),s.push(e._transaction),s.length===1&&e.emit("beforeAllTransactions",[e]),e.emit("beforeTransaction",[e._transaction,e]));try{o=t(e._transaction)}finally{if(i){const c=e._transaction===s[0];e._transaction=null,c&&qr(s,0)}}return o};class Qo{constructor(t,n){this.insertions=n,this.deletions=t,this.meta=new Map}}const $r=(e,t,n)=>{Pt(e,n.deletions,r=>{r instanceof x&&t.scope.some(s=>s===e.doc||ge(s,r))&&Vn(r,!1)})},Kr=(e,t,n)=>{let r=null;const s=e.doc,i=e.scope;E(s,c=>{for(;t.length>0&&e.currStackItem===null;){const l=s.store,d=t.pop(),a=new Set,h=[];let u=!1;Pt(c,d.insertions,g=>{if(g instanceof x){if(g.redone!==null){let{item:f,diff:p}=jn(l,g.id);p>0&&(f=O(c,b(f.id.client,f.id.clock+p))),g=f}!g.deleted&&i.some(f=>f===c.doc||ge(f,g))&&h.push(g)}}),Pt(c,d.deletions,g=>{g instanceof x&&i.some(f=>f===c.doc||ge(f,g))&&!Nt(d.insertions,g.id)&&a.add(g)}),a.forEach(g=>{u=Ms(c,g,a,d.insertions,e.ignoreRemoteMapChanges,e)!==null||u});for(let g=h.length-1;g>=0;g--){const f=h[g];e.deleteFilter(f)&&(f.delete(c),u=!0)}e.currStackItem=u?d:null}c.changed.forEach((l,d)=>{l.has(null)&&d._searchMarker&&(d._searchMarker.length=0)}),r=c},e);const o=e.currStackItem;if(o!=null){const c=r.changedParentTypes;e.emit("stack-item-popped",[{stackItem:o,type:n,changedParentTypes:c,origin:e},e]),e.currStackItem=null}return o};class Zo extends nn{constructor(t,{captureTimeout:n=500,captureTransaction:r=l=>!0,deleteFilter:s=()=>!0,trackedOrigins:i=new Set([null]),ignoreRemoteMapChanges:o=!1,doc:c=en(t)?t[0].doc:t instanceof nt?t:t.doc}={}){super(),this.scope=[],this.doc=c,this.addToScope(t),this.deleteFilter=s,i.add(this),this.trackedOrigins=i,this.captureTransaction=r,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=o,this.captureTimeout=n,this.afterTransactionHandler=l=>{if(!this.captureTransaction(l)||!this.scope.some(_=>l.changedParentTypes.has(_)||_===this.doc)||!this.trackedOrigins.has(l.origin)&&(!l.origin||!this.trackedOrigins.has(l.origin.constructor)))return;const d=this.undoing,a=this.redoing,h=d?this.redoStack:this.undoStack;d?this.stopCapturing():a||this.clear(!1,!0);const u=new Gt;l.afterState.forEach((_,y)=>{const w=l.beforeState.get(y)||0,M=_-w;M>0&&he(u,y,w,M)});const g=Bi();let f=!1;if(this.lastChange>0&&g-this.lastChange<this.captureTimeout&&h.length>0&&!d&&!a){const _=h[h.length-1];_.deletions=It([_.deletions,l.deleteSet]),_.insertions=It([_.insertions,u])}else h.push(new Qo(l.deleteSet,u)),f=!0;!d&&!a&&(this.lastChange=g),Pt(l,l.deleteSet,_=>{_ instanceof x&&this.scope.some(y=>y===l.doc||ge(y,_))&&Vn(_,!0)});const p=[{stackItem:h[h.length-1],origin:l.origin,type:d?"redo":"undo",changedParentTypes:l.changedParentTypes},this];f?this.emit("stack-item-added",p):this.emit("stack-item-updated",p)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",()=>{this.destroy()})}addToScope(t){const n=new Set(this.scope);t=en(t)?t:[t],t.forEach(r=>{n.has(r)||(n.add(r),(r instanceof P?r.doc!==this.doc:r!==this.doc)&&Sr("[yjs#509] Not same Y.Doc"),this.scope.push(r))})}addTrackedOrigin(t){this.trackedOrigins.add(t)}removeTrackedOrigin(t){this.trackedOrigins.delete(t)}clear(t=!0,n=!0){(t&&this.canUndo()||n&&this.canRedo())&&this.doc.transact(r=>{t&&(this.undoStack.forEach(s=>$r(r,this,s)),this.undoStack=[]),n&&(this.redoStack.forEach(s=>$r(r,this,s)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:t,redoStackCleared:n}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let t;try{t=Kr(this,this.undoStack,"undo")}finally{this.undoing=!1}return t}redo(){this.redoing=!0;let t;try{t=Kr(this,this.redoStack,"redo")}finally{this.redoing=!1}return t}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off("afterTransaction",this.afterTransactionHandler),super.destroy()}}function*tc(e){const t=S(e.restDecoder);for(let n=0;n<t;n++){const r=S(e.restDecoder),s=e.readClient();let i=S(e.restDecoder);for(let o=0;o<r;o++){const c=e.readInfo();if(c===10){const l=S(e.restDecoder);yield new F(b(s,i),l),i+=l}else if((Ce&c)!==0){const l=(c&(ot|L))===0,d=new x(b(s,i),null,(c&L)===L?e.readLeftID():null,null,(c&ot)===ot?e.readRightID():null,l?e.readParentInfo()?e.readString():e.readLeftID():null,l&&(c&ne)===ne?e.readString():null,Ts(e,c));yield d,i+=d.length}else{const l=e.readLen();yield new V(b(s,i),l),i+=l}}}}class wt{constructor(t,n){this.gen=tc(t),this.curr=null,this.done=!1,this.filterSkips=n,this.next()}next(){do this.curr=this.gen.next().value||null;while(this.filterSkips&&this.curr!==null&&this.curr.constructor===F);return this.curr}}const ec=e=>Yr(e,X),Yr=(e,t=J)=>{const n=[],r=new t(T(e)),s=new wt(r,!1);for(let o=s.curr;o!==null;o=s.next())n.push(o);pn("Structs: ",n);const i=at(r);pn("DeleteSet: ",i)},nc=e=>Qr(e,X),Qr=(e,t=J)=>{const n=[],r=new t(T(e)),s=new wt(r,!1);for(let i=s.curr;i!==null;i=s.next())n.push(i);return{structs:n,ds:at(r)}};class Nn{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}}const Zr=e=>pe(e,X,bt),ts=(e,t=Te,n=J)=>{const r=new t,s=new wt(new n(T(e)),!1);let i=s.curr;if(i!==null){let o=0,c=i.id.client,l=i.id.clock!==0,d=l?0:i.id.clock+i.length;for(;i!==null;i=s.next())c!==i.id.client&&(d!==0&&(o++,m(r.restEncoder,c),m(r.restEncoder,d)),c=i.id.client,d=0,l=i.id.clock!==0),i.constructor===F&&(l=!0),l||(d=i.id.clock+i.length);d!==0&&(o++,m(r.restEncoder,c),m(r.restEncoder,d));const a=Jt();return m(a,o),Pi(a,r.restEncoder),r.restEncoder=a,r.toUint8Array()}else return m(r.restEncoder,0),r.toUint8Array()},rc=e=>ts(e,Xt,X),es=(e,t=J)=>{const n=new Map,r=new Map,s=new wt(new t(T(e)),!1);let i=s.curr;if(i!==null){let o=i.id.client,c=i.id.clock;for(n.set(o,c);i!==null;i=s.next())o!==i.id.client&&(r.set(o,c),n.set(i.id.client,i.id.clock),o=i.id.client),c=i.id.clock+i.length;r.set(o,c)}return{from:n,to:r}},sc=e=>es(e,X),ic=(e,t)=>{if(e.constructor===V){const{client:n,clock:r}=e.id;return new V(b(n,r+t),e.length-t)}else if(e.constructor===F){const{client:n,clock:r}=e.id;return new F(b(n,r+t),e.length-t)}else{const n=e,{client:r,clock:s}=n.id;return new x(b(r,s+t),null,b(r,s+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},pe=(e,t=J,n=Y)=>{if(e.length===1)return e[0];const r=e.map(a=>new t(T(a)));let s=r.map(a=>new wt(a,!0)),i=null;const o=new n,c=new Nn(o);for(;s=s.filter(a=>a.curr!==null),s.sort((a,h)=>{if(a.curr.id.client===h.curr.id.client){const u=a.curr.id.clock-h.curr.id.clock;return u===0?a.curr.constructor===h.curr.constructor?0:a.curr.constructor===F?1:-1:u}else return h.curr.id.client-a.curr.id.client}),s.length!==0;){const a=s[0],h=a.curr.id.client;if(i!==null){let u=a.curr,g=!1;for(;u!==null&&u.id.clock+u.length<=i.struct.id.clock+i.struct.length&&u.id.client>=i.struct.id.client;)u=a.next(),g=!0;if(u===null||u.id.client!==h||g&&u.id.clock>i.struct.id.clock+i.struct.length)continue;if(h!==i.struct.id.client)kt(c,i.struct,i.offset),i={struct:u,offset:0},a.next();else if(i.struct.id.clock+i.struct.length<u.id.clock)if(i.struct.constructor===F)i.struct.length=u.id.clock+u.length-i.struct.id.clock;else{kt(c,i.struct,i.offset);const f=u.id.clock-i.struct.id.clock-i.struct.length;i={struct:new F(b(h,i.struct.id.clock+i.struct.length),f),offset:0}}else{const f=i.struct.id.clock+i.struct.length-u.id.clock;f>0&&(i.struct.constructor===F?i.struct.length-=f:u=ic(u,f)),i.struct.mergeWith(u)||(kt(c,i.struct,i.offset),i={struct:u,offset:0},a.next())}}else i={struct:a.curr,offset:0},a.next();for(let u=a.curr;u!==null&&u.id.client===h&&u.id.clock===i.struct.id.clock+i.struct.length&&u.constructor!==F;u=a.next())kt(c,i.struct,i.offset),i={struct:u,offset:0}}i!==null&&(kt(c,i.struct,i.offset),i=null),Mn(c);const l=r.map(a=>at(a)),d=It(l);return et(o,d),o.toUint8Array()},In=(e,t,n=J,r=Y)=>{const s=_n(t),i=new r,o=new Nn(i),c=new n(T(e)),l=new wt(c,!1);for(;l.curr;){const a=l.curr,h=a.id.client,u=s.get(h)||0;if(l.curr.constructor===F){l.next();continue}if(a.id.clock+a.length>u)for(kt(o,a,Ct(u-a.id.clock,0)),l.next();l.curr&&l.curr.id.client===h;)kt(o,l.curr,0),l.next();else for(;l.curr&&l.curr.id.client===h&&l.curr.id.clock+l.curr.length<=u;)l.next()}Mn(o);const d=at(c);return et(i,d),i.toUint8Array()},oc=(e,t)=>In(e,t,X,bt),ns=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:G(e.encoder.restEncoder)}),e.encoder.restEncoder=Jt(),e.written=0)},kt=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&ns(e),e.written===0&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),m(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},Mn=e=>{ns(e);const t=e.encoder.restEncoder;m(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){const r=e.clientStructs[n];m(t,r.written),ce(t,r.restEncoder)}},Re=(e,t,n,r)=>{const s=new n(T(e)),i=new wt(s,!1),o=new r,c=new Nn(o);for(let d=i.curr;d!==null;d=i.next())kt(c,t(d),0);Mn(c);const l=at(s);return et(o,l),o.toUint8Array()},rs=({formatting:e=!0,subdocs:t=!0,yxml:n=!0}={})=>{let r=0;const s=U(),i=U(),o=U(),c=U();return c.set(null,null),l=>{switch(l.constructor){case V:case F:return l;case x:{const d=l,a=d.content;switch(a.constructor){case Ft:break;case K:{if(n){const h=a.type;h instanceof rt&&(h.nodeName=B(i,h.nodeName,()=>"node-"+r)),h instanceof $t&&(h.hookName=B(i,h.hookName,()=>"hook-"+r))}break}case ut:{const h=a;h.arr=h.arr.map(()=>r);break}case Lt:{const h=a;h.content=new Uint8Array([r]);break}case Rt:{const h=a;t&&(h.opts={},h.doc.guid=r+"");break}case ht:{const h=a;h.embed={};break}case D:{const h=a;e&&(h.key=B(o,h.key,()=>r+""),h.value=B(c,h.value,()=>({i:r})));break}case Yt:{const h=a;h.arr=h.arr.map(()=>r);break}case $:{const h=a;h.str=vi(r%10+"",h.str.length);break}default:j()}return d.parentSub&&(d.parentSub=B(s,d.parentSub,()=>r+"")),r++,l}default:j()}}},cc=(e,t)=>Re(e,rs(t),X,bt),lc=(e,t)=>Re(e,rs(t),J,Y),ac=e=>Re(e,pr,X,Y),ss=e=>Re(e,pr,J,bt),is="You must not compute changes after the event-handler fired.";class me{constructor(t,n){this.target=t,this.currentTarget=t,this.transaction=n,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=dc(this.currentTarget,this.target))}deletes(t){return Nt(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw mt(is);const t=new Map,n=this.target;this.transaction.changed.get(n).forEach(r=>{if(r!==null){const s=n._map.get(r);let i,o;if(this.adds(s)){let c=s.left;for(;c!==null&&this.adds(c);)c=c.left;if(this.deletes(s))if(c!==null&&this.deletes(c))i="delete",o=tn(c.content.getContent());else return;else c!==null&&this.deletes(c)?(i="update",o=tn(c.content.getContent())):(i="add",o=void 0)}else if(this.deletes(s))i="delete",o=tn(s.content.getContent());else return;t.set(r,{action:i,oldValue:o})}}),this._keys=t}return this._keys}get delta(){return this.changes.delta}adds(t){return t.id.clock>=(this.transaction.beforeState.get(t.id.client)||0)}get changes(){let t=this._changes;if(t===null){if(this.transaction.doc._transactionCleanups.length===0)throw mt(is);const n=this.target,r=Wt(),s=Wt(),i=[];if(t={added:r,deleted:s,delta:i,keys:this.keys},this.transaction.changed.get(n).has(null)){let o=null;const c=()=>{o&&i.push(o)};for(let l=n._start;l!==null;l=l.right)l.deleted?this.deletes(l)&&!this.adds(l)&&((o===null||o.delete===void 0)&&(c(),o={delete:0}),o.delete+=l.length,s.add(l)):this.adds(l)?((o===null||o.insert===void 0)&&(c(),o={insert:[]}),o.insert=o.insert.concat(l.content.getContent()),r.add(l)):((o===null||o.retain===void 0)&&(c(),o={retain:0}),o.retain+=l.length);o!==null&&o.retain===void 0&&c()}this._changes=t}return t}}const dc=(e,t)=>{const n=[];for(;t._item!==null&&t!==e;){if(t._item.parentSub!==null)n.unshift(t._item.parentSub);else{let r=0,s=t._item.parent._start;for(;s!==t._item&&s!==null;)!s.deleted&&s.countable&&(r+=s.length),s=s.right;n.unshift(r)}t=t._item.parent}return n},I=()=>{Sr("Invalid access: Add Yjs type to a document before reading data.")},os=80;let Tn=0;class hc{constructor(t,n){t.marker=!0,this.p=t,this.index=n,this.timestamp=Tn++}}const uc=e=>{e.timestamp=Tn++},cs=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=Tn++},gc=(e,t,n)=>{if(e.length>=os){const r=e.reduce((s,i)=>s.timestamp<i.timestamp?s:i);return cs(r,t,n),r}else{const r=new hc(t,n);return e.push(r),r}},je=(e,t)=>{if(e._start===null||t===0||e._searchMarker===null)return null;const n=e._searchMarker.length===0?null:e._searchMarker.reduce((i,o)=>xe(t-i.index)<xe(t-o.index)?i:o);let r=e._start,s=0;for(n!==null&&(r=n.p,s=n.index,uc(n));r.right!==null&&s<t;){if(!r.deleted&&r.countable){if(t<s+r.length)break;s+=r.length}r=r.right}for(;r.left!==null&&s>t;)r=r.left,!r.deleted&&r.countable&&(s-=r.length);for(;r.left!==null&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(s-=r.length);return n!==null&&xe(n.index-s)<r.parent.length/os?(cs(n,r,s),n):gc(e._searchMarker,r,s)},be=(e,t,n)=>{for(let r=e.length-1;r>=0;r--){const s=e[r];if(n>0){let i=s.p;for(i.marker=!1;i&&(i.deleted||!i.countable);)i=i.left,i&&!i.deleted&&i.countable&&(s.index-=i.length);if(i===null||i.marker===!0){e.splice(r,1);continue}s.p=i,i.marker=!0}(t<s.index||n>0&&t===s.index)&&(s.index=Ct(t,s.index+n))}},fc=e=>{e.doc??I();let t=e._start;const n=[];for(;t;)n.push(t),t=t.right;return n},Ve=(e,t,n)=>{const r=e,s=t.changedParentTypes;for(;B(s,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;Or(r._eH,n,t)};class P{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Ir(),this._dEH=Ir(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,n){this.doc=t,this._item=n}_copy(){throw Z()}clone(){throw Z()}_write(t){}get _first(){let t=this._start;for(;t!==null&&t.deleted;)t=t.right;return t}_callObserver(t,n){!t.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(t){Mr(this._eH,t)}observeDeep(t){Mr(this._dEH,t)}unobserve(t){Tr(this._eH,t)}unobserveDeep(t){Tr(this._dEH,t)}toJSON(){}}const ls=(e,t,n)=>{e.doc??I(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let r=n-t;const s=[];let i=e._start;for(;i!==null&&r>0;){if(i.countable&&!i.deleted){const o=i.content.getContent();if(o.length<=t)t-=o.length;else{for(let c=t;c<o.length&&r>0;c++)s.push(o[c]),r--;t=0}}i=i.right}return s},as=e=>{e.doc??I();const t=[];let n=e._start;for(;n!==null;){if(n.countable&&!n.deleted){const r=n.content.getContent();for(let s=0;s<r.length;s++)t.push(r[s])}n=n.right}return t},pc=(e,t)=>{const n=[];let r=e._start;for(;r!==null;){if(r.countable&&yt(r,t)){const s=r.content.getContent();for(let i=0;i<s.length;i++)n.push(s[i])}r=r.right}return n},ye=(e,t)=>{let n=0,r=e._start;for(e.doc??I();r!==null;){if(r.countable&&!r.deleted){const s=r.content.getContent();for(let i=0;i<s.length;i++)t(s[i],n++,e)}r=r.right}},ds=(e,t)=>{const n=[];return ye(e,(r,s)=>{n.push(t(r,s,e))}),n},mc=e=>{let t=e._start,n=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(n===null){for(;t!==null&&t.deleted;)t=t.right;if(t===null)return{done:!0,value:void 0};n=t.content.getContent(),r=0,t=t.right}const s=n[r++];return n.length<=r&&(n=null),{done:!1,value:s}}}},hs=(e,t)=>{e.doc??I();const n=je(e,t);let r=e._start;for(n!==null&&(r=n.p,t-=n.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(t<r.length)return r.content.getContent()[t];t-=r.length}},Be=(e,t,n,r)=>{let s=n;const i=e.doc,o=i.clientID,c=i.store,l=n===null?t._start:n.right;let d=[];const a=()=>{d.length>0&&(s=new x(b(o,A(c,o)),s,s&&s.lastId,l,l&&l.id,t,null,new ut(d)),s.integrate(e,0),d=[])};r.forEach(h=>{if(h===null)d.push(h);else switch(h.constructor){case Number:case Object:case Boolean:case Array:case String:d.push(h);break;default:switch(a(),h.constructor){case Uint8Array:case ArrayBuffer:s=new x(b(o,A(c,o)),s,s&&s.lastId,l,l&&l.id,t,null,new Lt(new Uint8Array(h))),s.integrate(e,0);break;case nt:s=new x(b(o,A(c,o)),s,s&&s.lastId,l,l&&l.id,t,null,new Rt(h)),s.integrate(e,0);break;default:if(h instanceof P)s=new x(b(o,A(c,o)),s,s&&s.lastId,l,l&&l.id,t,null,new K(h)),s.integrate(e,0);else throw new Error("Unexpected content type in insert operation")}}}),a()},us=()=>mt("Length exceeded!"),gs=(e,t,n,r)=>{if(n>t._length)throw us();if(n===0)return t._searchMarker&&be(t._searchMarker,n,r.length),Be(e,t,null,r);const s=n,i=je(t,n);let o=t._start;for(i!==null&&(o=i.p,n-=i.index,n===0&&(o=o.prev,n+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(n<=o.length){n<o.length&&O(e,b(o.id.client,o.id.clock+n));break}n-=o.length}return t._searchMarker&&be(t._searchMarker,s,r.length),Be(e,t,o,r)},bc=(e,t,n)=>{let r=(t._searchMarker||[]).reduce((s,i)=>i.index>s.index?i:s,{index:0,p:t._start}).p;if(r)for(;r.right;)r=r.right;return Be(e,t,r,n)},fs=(e,t,n,r)=>{if(r===0)return;const s=n,i=r,o=je(t,n);let c=t._start;for(o!==null&&(c=o.p,n-=o.index);c!==null&&n>0;c=c.right)!c.deleted&&c.countable&&(n<c.length&&O(e,b(c.id.client,c.id.clock+n)),n-=c.length);for(;r>0&&c!==null;)c.deleted||(r<c.length&&O(e,b(c.id.client,c.id.clock+r)),c.delete(e),r-=c.length),c=c.right;if(r>0)throw us();t._searchMarker&&be(t._searchMarker,s,-i+r)},ze=(e,t,n)=>{const r=t._map.get(n);r!==void 0&&r.delete(e)},On=(e,t,n,r)=>{const s=t._map.get(n)||null,i=e.doc,o=i.clientID;let c;if(r==null)c=new ut([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:c=new ut([r]);break;case Uint8Array:c=new Lt(r);break;case nt:c=new Rt(r);break;default:if(r instanceof P)c=new K(r);else throw new Error("Unexpected content type")}new x(b(o,A(i.store,o)),s,s&&s.lastId,null,null,t,n,c).integrate(e,0)},Un=(e,t)=>{e.doc??I();const n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},ps=e=>{const t={};return e.doc??I(),e._map.forEach((n,r)=>{n.deleted||(t[r]=n.content.getContent()[n.length-1])}),t},ms=(e,t)=>{e.doc??I();const n=e._map.get(t);return n!==void 0&&!n.deleted},yc=(e,t,n)=>{let r=e._map.get(t)||null;for(;r!==null&&(!n.sv.has(r.id.client)||r.id.clock>=(n.sv.get(r.id.client)||0));)r=r.left;return r!==null&&yt(r,n)?r.content.getContent()[r.length-1]:void 0},bs=(e,t)=>{const n={};return e._map.forEach((r,s)=>{let i=r;for(;i!==null&&(!t.sv.has(i.id.client)||i.id.clock>=(t.sv.get(i.id.client)||0));)i=i.left;i!==null&&yt(i,t)&&(n[s]=i.content.getContent()[i.length-1])}),n},We=e=>(e.doc??I(),po(e._map.entries(),t=>!t[1].deleted));class ys extends me{}class dt extends P{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){const n=new dt;return n.push(t),n}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new dt}clone(){const t=new dt;return t.insert(0,this.toArray().map(n=>n instanceof P?n.clone():n)),t}get length(){return this.doc??I(),this._length}_callObserver(t,n){super._callObserver(t,n),Ve(this,t,new ys(this,t))}insert(t,n){this.doc!==null?E(this.doc,r=>{gs(r,this,t,n)}):this._prelimContent.splice(t,0,...n)}push(t){this.doc!==null?E(this.doc,n=>{bc(n,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,n=1){this.doc!==null?E(this.doc,r=>{fs(r,this,t,n)}):this._prelimContent.splice(t,n)}get(t){return hs(this,t)}toArray(){return as(this)}slice(t=0,n=this.length){return ls(this,t,n)}toJSON(){return this.map(t=>t instanceof P?t.toJSON():t)}map(t){return ds(this,t)}forEach(t){ye(this,t)}[Symbol.iterator](){return mc(this)}_write(t){t.writeTypeRef(jc)}}const wc=e=>new dt;class ws extends me{constructor(t,n,r){super(t,n),this.keysChanged=r}}class St extends P{constructor(t){super(),this._prelimContent=null,t===void 0?this._prelimContent=new Map:this._prelimContent=new Map(t)}_integrate(t,n){super._integrate(t,n),this._prelimContent.forEach((r,s)=>{this.set(s,r)}),this._prelimContent=null}_copy(){return new St}clone(){const t=new St;return this.forEach((n,r)=>{t.set(r,n instanceof P?n.clone():n)}),t}_callObserver(t,n){Ve(this,t,new ws(this,t,n))}toJSON(){this.doc??I();const t={};return this._map.forEach((n,r)=>{if(!n.deleted){const s=n.content.getContent()[n.length-1];t[r]=s instanceof P?s.toJSON():s}}),t}get size(){return[...We(this)].length}keys(){return mn(We(this),t=>t[0])}values(){return mn(We(this),t=>t[1].content.getContent()[t[1].length-1])}entries(){return mn(We(this),t=>[t[0],t[1].content.getContent()[t[1].length-1]])}forEach(t){this.doc??I(),this._map.forEach((n,r)=>{n.deleted||t(n.content.getContent()[n.length-1],r,this)})}[Symbol.iterator](){return this.entries()}delete(t){this.doc!==null?E(this.doc,n=>{ze(n,this,t)}):this._prelimContent.delete(t)}set(t,n){return this.doc!==null?E(this.doc,r=>{On(r,this,t,n)}):this._prelimContent.set(t,n),n}get(t){return Un(this,t)}has(t){return ms(this,t)}clear(){this.doc!==null?E(this.doc,t=>{this.forEach(function(n,r,s){ze(t,s,r)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(Vc)}}const kc=e=>new St,_t=(e,t)=>e===t||typeof e=="object"&&typeof t=="object"&&e&&t&&Qi(e,t);class Ln{constructor(t,n,r,s){this.left=t,this.right=n,this.index=r,this.currentAttributes=s}forward(){switch(this.right===null&&j(),this.right.content.constructor){case D:this.right.deleted||qt(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length);break}this.left=this.right,this.right=this.right.right}}const ks=(e,t,n)=>{for(;t.right!==null&&n>0;){switch(t.right.content.constructor){case D:t.right.deleted||qt(t.currentAttributes,t.right.content);break;default:t.right.deleted||(n<t.right.length&&O(e,b(t.right.id.client,t.right.id.clock+n)),t.index+=t.right.length,n-=t.right.length);break}t.left=t.right,t.right=t.right.right}return t},Je=(e,t,n,r)=>{const s=new Map,i=r?je(t,n):null;if(i){const o=new Ln(i.p.left,i.p,i.index,s);return ks(e,o,n-i.index)}else{const o=new Ln(null,t._start,0,s);return ks(e,o,n)}},Ss=(e,t,n,r)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===D&&_t(r.get(n.right.content.key),n.right.content.value));)n.right.deleted||r.delete(n.right.content.key),n.forward();const s=e.doc,i=s.clientID;r.forEach((o,c)=>{const l=n.left,d=n.right,a=new x(b(i,A(s.store,i)),l,l&&l.lastId,d,d&&d.id,t,null,new D(c,o));a.integrate(e,0),n.right=a,n.forward()})},qt=(e,t)=>{const{key:n,value:r}=t;r===null?e.delete(n):e.set(n,r)},_s=(e,t)=>{for(;e.right!==null&&(e.right.deleted||e.right.content.constructor===D&&_t(t[e.right.content.key]??null,e.right.content.value));)e.forward()},vs=(e,t,n,r)=>{const s=e.doc,i=s.clientID,o=new Map;for(const c in r){const l=r[c],d=n.currentAttributes.get(c)??null;if(!_t(d,l)){o.set(c,d);const{left:a,right:h}=n;n.right=new x(b(i,A(s.store,i)),a,a&&a.lastId,h,h&&h.id,t,null,new D(c,l)),n.right.integrate(e,0),n.forward()}}return o},Fn=(e,t,n,r,s)=>{n.currentAttributes.forEach((u,g)=>{s[g]===void 0&&(s[g]=null)});const i=e.doc,o=i.clientID;_s(n,s);const c=vs(e,t,n,s),l=r.constructor===String?new $(r):r instanceof P?new K(r):new ht(r);let{left:d,right:a,index:h}=n;t._searchMarker&&be(t._searchMarker,n.index,l.getLength()),a=new x(b(o,A(i.store,o)),d,d&&d.lastId,a,a&&a.id,t,null,l),a.integrate(e,0),n.right=a,n.index=h,n.forward(),Ss(e,t,n,c)},xs=(e,t,n,r,s)=>{const i=e.doc,o=i.clientID;_s(n,s);const c=vs(e,t,n,s);t:for(;n.right!==null&&(r>0||c.size>0&&(n.right.deleted||n.right.content.constructor===D));){if(!n.right.deleted)switch(n.right.content.constructor){case D:{const{key:l,value:d}=n.right.content,a=s[l];if(a!==void 0){if(_t(a,d))c.delete(l);else{if(r===0)break t;c.set(l,d)}n.right.delete(e)}else n.currentAttributes.set(l,d);break}default:r<n.right.length&&O(e,b(n.right.id.client,n.right.id.clock+r)),r-=n.right.length;break}n.forward()}if(r>0){let l="";for(;r>0;r--)l+=`
|
|
2
|
+
`;n.right=new x(b(o,A(i.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new $(l)),n.right.integrate(e,0),n.forward()}Ss(e,t,n,c)},Cs=(e,t,n,r,s)=>{let i=t;const o=U();for(;i&&(!i.countable||i.deleted);){if(!i.deleted&&i.content.constructor===D){const d=i.content;o.set(d.key,d)}i=i.right}let c=0,l=!1;for(;t!==i;){if(n===t&&(l=!0),!t.deleted){const d=t.content;switch(d.constructor){case D:{const{key:a,value:h}=d,u=r.get(a)??null;(o.get(a)!==d||u===h)&&(t.delete(e),c++,!l&&(s.get(a)??null)===h&&u!==h&&(u===null?s.delete(a):s.set(a,u))),!l&&!t.deleted&&qt(s,d);break}}}t=t.right}return c},Sc=(e,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;const n=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===D){const r=t.content.key;n.has(r)?t.delete(e):n.add(r)}t=t.left}},Es=e=>{let t=0;return E(e.doc,n=>{let r=e._start,s=e._start,i=U();const o=Ze(i);for(;s;){if(s.deleted===!1)switch(s.content.constructor){case D:qt(o,s.content);break;default:t+=Cs(n,r,s,i,o),i=Ze(o),r=s;break}s=s.right}}),t},_c=e=>{const t=new Set,n=e.doc;for(const[r,s]of e.afterState.entries()){const i=e.beforeState.get(r)||0;s!==i&&zr(e,n.store.clients.get(r),i,s,o=>{!o.deleted&&o.content.constructor===D&&o.constructor!==V&&t.add(o.parent)})}E(n,r=>{Pt(e,e.deleteSet,s=>{if(s instanceof V||!s.parent._hasFormatting||t.has(s.parent))return;const i=s.parent;s.content.constructor===D?t.add(i):Sc(r,s)});for(const s of t)Es(s)})},As=(e,t,n)=>{const r=n,s=Ze(t.currentAttributes),i=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case K:case ht:case $:n<t.right.length&&O(e,b(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e);break}t.forward()}i&&Cs(e,i,t.right,s,t.currentAttributes);const o=(t.left||t.right).parent;return o._searchMarker&&be(o._searchMarker,t.index,-r+n),t};class Ds extends me{constructor(t,n,r){super(t,n),this.childListChanged=!1,this.keysChanged=new Set,r.forEach(s=>{s===null?this.childListChanged=!0:this.keysChanged.add(s)})}get changes(){if(this._changes===null){const t={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=t}return this._changes}get delta(){if(this._delta===null){const t=this.target.doc,n=[];E(t,r=>{const s=new Map,i=new Map;let o=this.target._start,c=null;const l={};let d="",a=0,h=0;const u=()=>{if(c!==null){let g=null;switch(c){case"delete":h>0&&(g={delete:h}),h=0;break;case"insert":(typeof d=="object"||d.length>0)&&(g={insert:d},s.size>0&&(g.attributes={},s.forEach((f,p)=>{f!==null&&(g.attributes[p]=f)}))),d="";break;case"retain":a>0&&(g={retain:a},$i(l)||(g.attributes=Gi({},l))),a=0;break}g&&n.push(g),c=null}};for(;o!==null;){switch(o.content.constructor){case K:case ht:this.adds(o)?this.deletes(o)||(u(),c="insert",d=o.content.getContent()[0],u()):this.deletes(o)?(c!=="delete"&&(u(),c="delete"),h+=1):o.deleted||(c!=="retain"&&(u(),c="retain"),a+=1);break;case $:this.adds(o)?this.deletes(o)||(c!=="insert"&&(u(),c="insert"),d+=o.content.str):this.deletes(o)?(c!=="delete"&&(u(),c="delete"),h+=o.length):o.deleted||(c!=="retain"&&(u(),c="retain"),a+=o.length);break;case D:{const{key:g,value:f}=o.content;if(this.adds(o)){if(!this.deletes(o)){const p=s.get(g)??null;_t(p,f)?f!==null&&o.delete(r):(c==="retain"&&u(),_t(f,i.get(g)??null)?delete l[g]:l[g]=f)}}else if(this.deletes(o)){i.set(g,f);const p=s.get(g)??null;_t(p,f)||(c==="retain"&&u(),l[g]=p)}else if(!o.deleted){i.set(g,f);const p=l[g];p!==void 0&&(_t(p,f)?p!==null&&o.delete(r):(c==="retain"&&u(),f===null?delete l[g]:l[g]=f))}o.deleted||(c==="insert"&&u(),qt(s,o.content));break}}o=o.right}for(u();n.length>0;){const g=n[n.length-1];if(g.retain!==void 0&&g.attributes===void 0)n.pop();else break}}),this._delta=n}return this._delta}}class Ut extends P{constructor(t){super(),this._pending=t!==void 0?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??I(),this._length}_integrate(t,n){super._integrate(t,n);try{this._pending.forEach(r=>r())}catch(r){console.error(r)}this._pending=null}_copy(){return new Ut}clone(){const t=new Ut;return t.applyDelta(this.toDelta()),t}_callObserver(t,n){super._callObserver(t,n);const r=new Ds(this,t,n);Ve(this,t,r),!t.local&&this._hasFormatting&&(t._needFormattingCleanup=!0)}toString(){this.doc??I();let t="",n=this._start;for(;n!==null;)!n.deleted&&n.countable&&n.content.constructor===$&&(t+=n.content.str),n=n.right;return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:n=!0}={}){this.doc!==null?E(this.doc,r=>{const s=new Ln(null,this._start,0,new Map);for(let i=0;i<t.length;i++){const o=t[i];if(o.insert!==void 0){const c=!n&&typeof o.insert=="string"&&i===t.length-1&&s.right===null&&o.insert.slice(-1)===`
|
|
3
|
+
`?o.insert.slice(0,-1):o.insert;(typeof c!="string"||c.length>0)&&Fn(r,this,s,c,o.attributes||{})}else o.retain!==void 0?xs(r,this,s,o.retain,o.attributes||{}):o.delete!==void 0&&As(r,s,o.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,n,r){this.doc??I();const s=[],i=new Map,o=this.doc;let c="",l=this._start;function d(){if(c.length>0){const h={};let u=!1;i.forEach((f,p)=>{u=!0,h[p]=f});const g={insert:c};u&&(g.attributes=h),s.push(g),c=""}}const a=()=>{for(;l!==null;){if(yt(l,t)||n!==void 0&&yt(l,n))switch(l.content.constructor){case $:{const h=i.get("ychange");t!==void 0&&!yt(l,t)?(h===void 0||h.user!==l.id.client||h.type!=="removed")&&(d(),i.set("ychange",r?r("removed",l.id):{type:"removed"})):n!==void 0&&!yt(l,n)?(h===void 0||h.user!==l.id.client||h.type!=="added")&&(d(),i.set("ychange",r?r("added",l.id):{type:"added"})):h!==void 0&&(d(),i.delete("ychange")),c+=l.content.str;break}case K:case ht:{d();const h={insert:l.content.getContent()[0]};if(i.size>0){const u={};h.attributes=u,i.forEach((g,f)=>{u[f]=g})}s.push(h);break}case D:yt(l,t)&&(d(),qt(i,l.content));break}l=l.right}d()};return t||n?E(o,h=>{t&&An(h,t),n&&An(h,n),a()},"cleanup"):a(),s}insert(t,n,r){if(n.length<=0)return;const s=this.doc;s!==null?E(s,i=>{const o=Je(i,this,t,!r);r||(r={},o.currentAttributes.forEach((c,l)=>{r[l]=c})),Fn(i,this,o,n,r)}):this._pending.push(()=>this.insert(t,n,r))}insertEmbed(t,n,r){const s=this.doc;s!==null?E(s,i=>{const o=Je(i,this,t,!r);Fn(i,this,o,n,r||{})}):this._pending.push(()=>this.insertEmbed(t,n,r||{}))}delete(t,n){if(n===0)return;const r=this.doc;r!==null?E(r,s=>{As(s,Je(s,this,t,!0),n)}):this._pending.push(()=>this.delete(t,n))}format(t,n,r){if(n===0)return;const s=this.doc;s!==null?E(s,i=>{const o=Je(i,this,t,!1);o.right!==null&&xs(i,this,o,n,r)}):this._pending.push(()=>this.format(t,n,r))}removeAttribute(t){this.doc!==null?E(this.doc,n=>{ze(n,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,n){this.doc!==null?E(this.doc,r=>{On(r,this,t,n)}):this._pending.push(()=>this.setAttribute(t,n))}getAttribute(t){return Un(this,t)}getAttributes(){return ps(this)}_write(t){t.writeTypeRef(Bc)}}const vc=e=>new Ut;class Rn{constructor(t,n=()=>!0){this._filter=n,this._root=t,this._currentNode=t._start,this._firstCall=!0,t.doc??I()}[Symbol.iterator](){return this}next(){let t=this._currentNode,n=t&&t.content&&t.content.type;if(t!==null&&(!this._firstCall||t.deleted||!this._filter(n)))do if(n=t.content.type,!t.deleted&&(n.constructor===rt||n.constructor===vt)&&n._start!==null)t=n._start;else for(;t!==null;){const r=t.next;if(r!==null){t=r;break}else t.parent===this._root?t=null:t=t.parent._item}while(t!==null&&(t.deleted||!this._filter(t.content.type)));return this._firstCall=!1,t===null?{value:void 0,done:!0}:(this._currentNode=t,{value:t.content.type,done:!1})}}class vt extends P{constructor(){super(),this._prelimContent=[]}get firstChild(){const t=this._first;return t?t.content.getContent()[0]:null}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new vt}clone(){const t=new vt;return t.insert(0,this.toArray().map(n=>n instanceof P?n.clone():n)),t}get length(){return this.doc??I(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new Rn(this,t)}querySelector(t){t=t.toUpperCase();const n=new Rn(this,r=>r.nodeName&&r.nodeName.toUpperCase()===t).next();return n.done?null:n.value}querySelectorAll(t){return t=t.toUpperCase(),ft(new Rn(this,n=>n.nodeName&&n.nodeName.toUpperCase()===t))}_callObserver(t,n){Ve(this,t,new Ps(this,n,t))}toString(){return ds(this,t=>t.toString()).join("")}toJSON(){return this.toString()}toDOM(t=document,n={},r){const s=t.createDocumentFragment();return r!==void 0&&r._createAssociation(s,this),ye(this,i=>{s.insertBefore(i.toDOM(t,n,r),null)}),s}insert(t,n){this.doc!==null?E(this.doc,r=>{gs(r,this,t,n)}):this._prelimContent.splice(t,0,...n)}insertAfter(t,n){if(this.doc!==null)E(this.doc,r=>{const s=t&&t instanceof P?t._item:t;Be(r,this,s,n)});else{const r=this._prelimContent,s=t===null?0:r.findIndex(i=>i===t)+1;if(s===0&&t!==null)throw mt("Reference item not found");r.splice(s,0,...n)}}delete(t,n=1){this.doc!==null?E(this.doc,r=>{fs(r,this,t,n)}):this._prelimContent.splice(t,n)}toArray(){return as(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return hs(this,t)}slice(t=0,n=this.length){return ls(this,t,n)}forEach(t){ye(this,t)}_write(t){t.writeTypeRef(Wc)}}const xc=e=>new vt;class rt extends vt{constructor(t="UNDEFINED"){super(),this.nodeName=t,this._prelimAttrs=new Map}get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_integrate(t,n){super._integrate(t,n),this._prelimAttrs.forEach((r,s)=>{this.setAttribute(s,r)}),this._prelimAttrs=null}_copy(){return new rt(this.nodeName)}clone(){const t=new rt(this.nodeName),n=this.getAttributes();return qi(n,(r,s)=>{typeof r=="string"&&t.setAttribute(s,r)}),t.insert(0,this.toArray().map(r=>r instanceof P?r.clone():r)),t}toString(){const t=this.getAttributes(),n=[],r=[];for(const c in t)r.push(c);r.sort();const s=r.length;for(let c=0;c<s;c++){const l=r[c];n.push(l+'="'+t[l]+'"')}const i=this.nodeName.toLocaleLowerCase(),o=n.length>0?" "+n.join(" "):"";return`<${i}${o}>${super.toString()}</${i}>`}removeAttribute(t){this.doc!==null?E(this.doc,n=>{ze(n,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,n){this.doc!==null?E(this.doc,r=>{On(r,this,t,n)}):this._prelimAttrs.set(t,n)}getAttribute(t){return Un(this,t)}hasAttribute(t){return ms(this,t)}getAttributes(t){return t?bs(this,t):ps(this)}toDOM(t=document,n={},r){const s=t.createElement(this.nodeName),i=this.getAttributes();for(const o in i){const c=i[o];typeof c=="string"&&s.setAttribute(o,c)}return ye(this,o=>{s.appendChild(o.toDOM(t,n,r))}),r!==void 0&&r._createAssociation(s,this),s}_write(t){t.writeTypeRef(zc),t.writeKey(this.nodeName)}}const Cc=e=>new rt(e.readKey());class Ps extends me{constructor(t,n,r){super(t,r),this.childListChanged=!1,this.attributesChanged=new Set,n.forEach(s=>{s===null?this.childListChanged=!0:this.attributesChanged.add(s)})}}class $t extends St{constructor(t){super(),this.hookName=t}_copy(){return new $t(this.hookName)}clone(){const t=new $t(this.hookName);return this.forEach((n,r)=>{t.set(r,n)}),t}toDOM(t=document,n={},r){const s=n[this.hookName];let i;return s!==void 0?i=s.createDom(this):i=document.createElement(this.hookName),i.setAttribute("data-yjs-hook",this.hookName),r!==void 0&&r._createAssociation(i,this),i}_write(t){t.writeTypeRef(Jc),t.writeKey(this.hookName)}}const Ec=e=>new $t(e.readKey());class Kt extends Ut{get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_copy(){return new Kt}clone(){const t=new Kt;return t.applyDelta(this.toDelta()),t}toDOM(t=document,n,r){const s=t.createTextNode(this.toString());return r!==void 0&&r._createAssociation(s,this),s}toString(){return this.toDelta().map(t=>{const n=[];for(const s in t.attributes){const i=[];for(const o in t.attributes[s])i.push({key:o,value:t.attributes[s][o]});i.sort((o,c)=>o.key<c.key?-1:1),n.push({nodeName:s,attrs:i})}n.sort((s,i)=>s.nodeName<i.nodeName?-1:1);let r="";for(let s=0;s<n.length;s++){const i=n[s];r+=`<${i.nodeName}`;for(let o=0;o<i.attrs.length;o++){const c=i.attrs[o];r+=` ${c.key}="${c.value}"`}r+=">"}r+=t.insert;for(let s=n.length-1;s>=0;s--)r+=`</${n[s].nodeName}>`;return r}).join("")}toJSON(){return this.toString()}_write(t){t.writeTypeRef(Hc)}}const Ac=e=>new Kt;class He{constructor(t,n){this.id=t,this.length=n}get deleted(){throw Z()}mergeWith(t){return!1}write(t,n,r){throw Z()}integrate(t,n){throw Z()}}const Dc=0;class V extends He{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,n){n>0&&(this.id.clock+=n,this.length-=n),Br(t.doc.store,this)}write(t,n){t.writeInfo(Dc),t.writeLen(this.length-n)}getMissing(t,n){return null}}class Lt{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new Lt(this.content)}splice(t){throw Z()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeBuf(this.content)}getRef(){return 3}}const Pc=e=>new Lt(e.readBuf());class Ft{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new Ft(this.len)}splice(t){const n=new Ft(this.len-t);return this.len=t,n}mergeWith(t){return this.len+=t.len,!0}integrate(t,n){he(t.deleteSet,n.id.client,n.id.clock,this.len),n.markDeleted()}delete(t){}gc(t){}write(t,n){t.writeLen(this.len-n)}getRef(){return 1}}const Nc=e=>new Ft(e.readLen()),Ns=(e,t)=>new nt({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1});class Rt{constructor(t){t._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=t;const n={};this.opts=n,t.gc||(n.gc=!1),t.autoLoad&&(n.autoLoad=!0),t.meta!==null&&(n.meta=t.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new Rt(Ns(this.doc.guid,this.opts))}splice(t){throw Z()}mergeWith(t){return!1}integrate(t,n){this.doc._item=n,t.subdocsAdded.add(this.doc),this.doc.shouldLoad&&t.subdocsLoaded.add(this.doc)}delete(t){t.subdocsAdded.has(this.doc)?t.subdocsAdded.delete(this.doc):t.subdocsRemoved.add(this.doc)}gc(t){}write(t,n){t.writeString(this.doc.guid),t.writeAny(this.opts)}getRef(){return 9}}const Ic=e=>new Rt(Ns(e.readString(),e.readAny()));class ht{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new ht(this.embed)}splice(t){throw Z()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeJSON(this.embed)}getRef(){return 5}}const Mc=e=>new ht(e.readJSON());class D{constructor(t,n){this.key=t,this.value=n}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new D(this.key,this.value)}splice(t){throw Z()}mergeWith(t){return!1}integrate(t,n){const r=n.parent;r._searchMarker=null,r._hasFormatting=!0}delete(t){}gc(t){}write(t,n){t.writeKey(this.key),t.writeJSON(this.value)}getRef(){return 6}}const Tc=e=>new D(e.readKey(),e.readJSON());class Yt{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Yt(this.arr)}splice(t){const n=new Yt(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){const r=this.arr.length;t.writeLen(r-n);for(let s=n;s<r;s++){const i=this.arr[s];t.writeString(i===void 0?"undefined":JSON.stringify(i))}}getRef(){return 2}}const Oc=e=>{const t=e.readLen(),n=[];for(let r=0;r<t;r++){const s=e.readString();s==="undefined"?n.push(void 0):n.push(JSON.parse(s))}return new Yt(n)},Uc=Ie("node_env")==="development";class ut{constructor(t){this.arr=t,Uc&&fr(t)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new ut(this.arr)}splice(t){const n=new ut(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){const r=this.arr.length;t.writeLen(r-n);for(let s=n;s<r;s++){const i=this.arr[s];t.writeAny(i)}}getRef(){return 8}}const Lc=e=>{const t=e.readLen(),n=[];for(let r=0;r<t;r++)n.push(e.readAny());return new ut(n)};class ${constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new $(this.str)}splice(t){const n=new $(this.str.slice(t));this.str=this.str.slice(0,t);const r=this.str.charCodeAt(t-1);return r>=55296&&r<=56319&&(this.str=this.str.slice(0,t-1)+"�",n.str="�"+n.str.slice(1)),n}mergeWith(t){return this.str+=t.str,!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeString(n===0?this.str:this.str.slice(n))}getRef(){return 4}}const Fc=e=>new $(e.readString()),Rc=[wc,kc,vc,Cc,xc,Ec,Ac],jc=0,Vc=1,Bc=2,zc=3,Wc=4,Jc=5,Hc=6;class K{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new K(this.type._copy())}splice(t){throw Z()}mergeWith(t){return!1}integrate(t,n){this.type._integrate(t.doc,n)}delete(t){let n=this.type._start;for(;n!==null;)n.deleted?n.id.clock<(t.beforeState.get(n.id.client)||0)&&t._mergeStructs.push(n):n.delete(t),n=n.right;this.type._map.forEach(r=>{r.deleted?r.id.clock<(t.beforeState.get(r.id.client)||0)&&t._mergeStructs.push(r):r.delete(t)}),t.changed.delete(this.type)}gc(t){let n=this.type._start;for(;n!==null;)n.gc(t,!0),n=n.right;this.type._start=null,this.type._map.forEach(r=>{for(;r!==null;)r.gc(t,!0),r=r.left}),this.type._map=new Map}write(t,n){this.type._write(t)}getRef(){return 7}}const Gc=e=>new K(Rc[e.readTypeRef()](e)),jn=(e,t)=>{let n=t,r=0,s;do r>0&&(n=b(n.client,n.clock+r)),s=Ot(e,n),r=n.clock-s.id.clock,n=s.redone;while(n!==null&&s instanceof x);return{item:s,diff:r}},Vn=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},Ge=(e,t,n)=>{const{client:r,clock:s}=t.id,i=new x(b(r,s+n),t,b(r,s+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&i.markDeleted(),t.keep&&(i.keep=!0),t.redone!==null&&(i.redone=b(t.redone.client,t.redone.clock+n)),t.right=i,i.right!==null&&(i.right.left=i),e._mergeStructs.push(i),i.parentSub!==null&&i.right===null&&i.parent._map.set(i.parentSub,i),t.length=n,i},Is=(e,t)=>ui(e,n=>Nt(n.deletions,t)),Ms=(e,t,n,r,s,i)=>{const o=e.doc,c=o.store,l=o.clientID,d=t.redone;if(d!==null)return O(e,d);let a=t.parent._item,h=null,u;if(a!==null&&a.deleted===!0){if(a.redone===null&&(!n.has(a)||Ms(e,a,n,r,s,i)===null))return null;for(;a.redone!==null;)a=O(e,a.redone)}const g=a===null?t.parent:a.content.type;if(t.parentSub===null){for(h=t.left,u=t;h!==null;){let y=h;for(;y!==null&&y.parent._item!==a;)y=y.redone===null?null:O(e,y.redone);if(y!==null&&y.parent._item===a){h=y;break}h=h.left}for(;u!==null;){let y=u;for(;y!==null&&y.parent._item!==a;)y=y.redone===null?null:O(e,y.redone);if(y!==null&&y.parent._item===a){u=y;break}u=u.right}}else if(u=null,t.right&&!s){for(h=t;h!==null&&h.right!==null&&(h.right.redone||Nt(r,h.right.id)||Is(i.undoStack,h.right.id)||Is(i.redoStack,h.right.id));)for(h=h.right;h.redone;)h=O(e,h.redone);if(h&&h.right!==null)return null}else h=g._map.get(t.parentSub)||null;const f=A(c,l),p=b(l,f),_=new x(p,h,h&&h.lastId,u,u&&u.id,g,t.parentSub,t.content.copy());return t.redone=p,Vn(_,!0),_.integrate(e,0),_};class x extends He{constructor(t,n,r,s,i,o,c,l){super(t,l.getLength()),this.origin=r,this.left=n,this.right=s,this.rightOrigin=i,this.parent=o,this.parentSub=c,this.redone=null,this.content=l,this.info=this.content.isCountable()?Zn:0}set marker(t){(this.info&sn)>0!==t&&(this.info^=sn)}get marker(){return(this.info&sn)>0}get keep(){return(this.info&Qn)>0}set keep(t){this.keep!==t&&(this.info^=Qn)}get countable(){return(this.info&Zn)>0}get deleted(){return(this.info&rn)>0}set deleted(t){this.deleted!==t&&(this.info^=rn)}markDeleted(){this.info|=rn}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=A(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=A(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Mt&&this.id.client!==this.parent.client&&this.parent.clock>=A(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Pn(t,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=O(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===V||this.right&&this.right.constructor===V)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===x?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===x&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Mt){const r=Ot(n,this.parent);r.constructor===V?this.parent=null:this.parent=r.content.type}return null}integrate(t,n){if(n>0&&(this.id.clock+=n,this.left=Pn(t,t.doc.store,b(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(n),this.length-=n),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let r=this.left,s;if(r!==null)s=r.right;else if(this.parentSub!==null)for(s=this.parent._map.get(this.parentSub)||null;s!==null&&s.left!==null;)s=s.left;else s=this.parent._start;const i=new Set,o=new Set;for(;s!==null&&s!==this.right;){if(o.add(s),i.add(s),Tt(this.origin,s.origin)){if(s.id.client<this.id.client)r=s,i.clear();else if(Tt(this.rightOrigin,s.rightOrigin))break}else if(s.origin!==null&&o.has(Ot(t.doc.store,s.origin)))i.has(Ot(t.doc.store,s.origin))||(r=s,i.clear());else break;s=s.right}this.left=r}if(this.left!==null){const r=this.left.right;this.right=r,this.left.right=this}else{let r;if(this.parentSub!==null)for(r=this.parent._map.get(this.parentSub)||null;r!==null&&r.left!==null;)r=r.left;else r=this.parent._start,this.parent._start=this;this.right=r}this.right!==null?this.right.left=this:this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(t)),this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),Br(t.doc.store,this),this.content.integrate(t,this),Hr(t,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(t)}else new V(this.id,this.length).integrate(t,0)}get next(){let t=this.right;for(;t!==null&&t.deleted;)t=t.right;return t}get prev(){let t=this.left;for(;t!==null&&t.deleted;)t=t.left;return t}get lastId(){return this.length===1?this.id:b(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&Tt(t.origin,this.lastId)&&this.right===t&&Tt(this.rightOrigin,t.rightOrigin)&&this.id.client===t.id.client&&this.id.clock+this.length===t.id.clock&&this.deleted===t.deleted&&this.redone===null&&t.redone===null&&this.content.constructor===t.content.constructor&&this.content.mergeWith(t.content)){const n=this.parent._searchMarker;return n&&n.forEach(r=>{r.p===t&&(r.p=this,!this.deleted&&this.countable&&(r.index-=this.length))}),t.keep&&(this.keep=!0),this.right=t.right,this.right!==null&&(this.right.left=this),this.length+=t.length,!0}return!1}delete(t){if(!this.deleted){const n=this.parent;this.countable&&this.parentSub===null&&(n._length-=this.length),this.markDeleted(),he(t.deleteSet,this.id.client,this.id.clock,this.length),Hr(t,n,this.parentSub),this.content.delete(t)}}gc(t,n){if(!this.deleted)throw j();this.content.gc(t),n?Ko(t,this,new V(this.id,this.length)):this.content=new Ft(this.length)}write(t,n){const r=n>0?b(this.id.client,this.id.clock+n-1):this.origin,s=this.rightOrigin,i=this.parentSub,o=this.content.getRef()&Ce|(r===null?0:L)|(s===null?0:ot)|(i===null?0:ne);if(t.writeInfo(o),r!==null&&t.writeLeftID(r),s!==null&&t.writeRightID(s),r===null&&s===null){const c=this.parent;if(c._item!==void 0){const l=c._item;if(l===null){const d=xn(c);t.writeParentInfo(!0),t.writeString(d)}else t.writeParentInfo(!1),t.writeLeftID(l.id)}else c.constructor===String?(t.writeParentInfo(!0),t.writeString(c)):c.constructor===Mt?(t.writeParentInfo(!1),t.writeLeftID(c)):j();i!==null&&t.writeString(i)}this.content.write(t,n)}}const Ts=(e,t)=>Xc[t&Ce](e),Xc=[()=>{j()},Nc,Oc,Pc,Fc,Mc,Tc,Gc,Lc,Ic,()=>{j()}],qc=10;class F extends He{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,n){j()}write(t,n){t.writeInfo(qc),m(t.restEncoder,this.length-n)}getMissing(t,n){return null}}const Os=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Us="__ $YJS$ __";Os[Us]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438"),Os[Us]=!0;var $c=Object.freeze({__proto__:null,AbsolutePosition:Fr,AbstractConnector:mo,AbstractStruct:He,AbstractType:P,Array:dt,ContentAny:ut,ContentBinary:Lt,ContentDeleted:Ft,ContentDoc:Rt,ContentEmbed:ht,ContentFormat:D,ContentJSON:Yt,ContentString:$,ContentType:K,Doc:nt,GC:V,ID:Mt,Item:x,Map:St,PermanentUserData:No,RelativePosition:Ue,Skip:F,Snapshot:Cn,Text:Ut,Transaction:Wr,UndoManager:Zo,UpdateDecoderV1:X,UpdateDecoderV2:J,UpdateEncoderV1:bt,UpdateEncoderV2:Y,XmlElement:rt,XmlFragment:vt,XmlHook:$t,XmlText:Kt,YArrayEvent:ys,YEvent:me,YMapEvent:ws,YTextEvent:Ds,YXmlEvent:Ps,applyUpdate:Dr,applyUpdateV2:Oe,cleanupYTextFormatting:Es,compareIDs:Tt,compareRelativePositions:Bo,convertUpdateFormatV1ToV2:ac,convertUpdateFormatV2ToV1:ss,createAbsolutePositionFromRelativePosition:Vo,createDeleteSet:Me,createDeleteSetFromStructStore:wn,createDocFromSnapshot:Xo,createID:b,createRelativePositionFromJSON:Mo,createRelativePositionFromTypeIndex:Oo,createSnapshot:En,decodeRelativePosition:Ro,decodeSnapshot:Jo,decodeSnapshotV2:jr,decodeStateVector:_n,decodeUpdate:nc,decodeUpdateV2:Qr,diffUpdate:oc,diffUpdateV2:In,emptySnapshot:Ho,encodeRelativePosition:Lo,encodeSnapshot:Wo,encodeSnapshotV2:Rr,encodeStateAsUpdate:xo,encodeStateAsUpdateV2:Pr,encodeStateVector:Ao,encodeStateVectorFromUpdate:rc,encodeStateVectorFromUpdateV2:ts,equalDeleteSets:Cr,equalSnapshots:zo,findIndexSS:q,findRootTypeKey:xn,getItem:Ot,getItemCleanEnd:Pn,getItemCleanStart:O,getState:A,getTypeChildren:fc,isDeleted:Nt,isParentOf:ge,iterateDeletedStructs:Pt,logType:Po,logUpdate:ec,logUpdateV2:Yr,mergeDeleteSets:It,mergeUpdates:Zr,mergeUpdatesV2:pe,obfuscateUpdate:cc,obfuscateUpdateV2:lc,parseUpdateMeta:sc,parseUpdateMetaV2:es,readUpdate:_o,readUpdateV2:Sn,relativePositionToJSON:Io,snapshot:Go,snapshotContainsUpdate:$o,transact:E,tryGc:Yo,typeListToArraySnapshot:pc,typeMapGetAllSnapshot:bs,typeMapGetSnapshot:yc});const Bn=["lineSpacing","spaceBefore","spaceAfter"],st=(e,t)=>e>>>t|e<<32-t,Kc=e=>st(e,2)^st(e,13)^st(e,22),Yc=e=>st(e,6)^st(e,11)^st(e,25),Qc=e=>st(e,7)^st(e,18)^e>>>3,Zc=e=>st(e,17)^st(e,19)^e>>>10,tl=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),el=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);class nl{constructor(){const t=new ArrayBuffer(320);this._H=new Uint32Array(t,0,8),this._H.set(el),this._W=new Uint32Array(t,64,64)}_updateHash(){const t=this._H,n=this._W;for(let h=16;h<64;h++)n[h]=Zc(n[h-2])+n[h-7]+Qc(n[h-15])+n[h-16];let r=t[0],s=t[1],i=t[2],o=t[3],c=t[4],l=t[5],d=t[6],a=t[7];for(let h=0,u,g;h<64;h++)u=a+Yc(c)+(c&l^~c&d)+tl[h]+n[h]>>>0,g=Kc(r)+(r&s^r&i^s&i)>>>0,a=d,d=l,l=c,c=o+u>>>0,o=i,i=s,s=r,r=u+g>>>0;t[0]+=r,t[1]+=s,t[2]+=i,t[3]+=o,t[4]+=c,t[5]+=l,t[6]+=d,t[7]+=a}digest(t){let n=0;for(;n+56<=t.length;){let o=0;for(;o<16&&n+3<t.length;o++)this._W[o]=t[n++]<<24|t[n++]<<16|t[n++]<<8|t[n++];if(n%64!==0){for(this._W.fill(0,o,16);n<t.length;)this._W[o]|=t[n]<<(3-n%4)*8,n++;this._W[o]|=L<<(3-n%4)*8}this._updateHash()}const r=n%64!==0;this._W.fill(0,0,16);let s=0;for(;n<t.length;s++)for(let o=3;o>=0&&n<t.length;o--)this._W[s]|=t[n++]<<o*8;r||(this._W[s-(n%4===0?0:1)]|=L<<(3-n%4)*8),this._W[14]=t.byteLength/fi,this._W[15]=t.byteLength*8,this._updateHash();const i=new Uint8Array(32);for(let o=0;o<this._H.length;o++)for(let c=0;c<4;c++)i[o*4+c]=this._H[o]>>>(3-c)*8;return i}}const rl=e=>new nl().digest(e),sl="revise:styles:v1",il="sharedStylesVersion",Ls="_reviseTextStyle",ol="_reviseParagraphStyle",Fs=new Set(["fontFamily","fontSize","bold","italic","underline","strikethrough","doubleStrikethrough","smallCaps","allCaps","superscript","subscript","hidden","color","backgroundColor","letterSpacing","lang","code","docxRunPropertyResets","oxmlRPr"]),Rs=new Set(["align","lineSpacing","spaceBefore","spaceAfter","contextualSpacing","direction","tabStops","borders","shading","leftIndent","firstLineIndent","pagination"]);class Xe extends Error{constructor(){super(...arguments),this.name="SharedStyleError"}}function js(e){return JSON.stringify(Object.fromEntries(Object.entries(e).filter(([,t])=>t!=null).sort(([t],[n])=>t<n?-1:t>n?1:0)))}function cl(e,t){return`${e}:${Array.from(rl(new TextEncoder().encode(t)).subarray(0,16),n=>n.toString(16).padStart(2,"0")).join("")}`}function ll(e){return!!e?.share.has("metadata")&&e.getMap("metadata").get(il)===1}const Vs=new WeakMap;function Bs(e,t,n){if(t==null)return{};if(!e||typeof t!="string"||!t.startsWith(`${n}:`))throw new Xe("Invalid shared style reference");const r=e.getMap(sl).get(t);if(typeof r!="string")throw new Xe("Missing shared style definition; resync the document");let s=Vs.get(e);s||Vs.set(e,s=new Map);const i=s.get(t);if(i?.json===r)return i.marks;if(cl(n,r)!==t)throw new Xe("Modified shared style definition");const o=JSON.parse(r),c=n==="t"?Fs:Rs;if(!o||typeof o!="object"||Array.isArray(o)||Object.entries(o).some(([l,d])=>!c.has(l)||!["string","number","boolean"].includes(typeof d)))throw new Xe("Invalid shared style properties");return Object.freeze(o),s.size>=4096&&s.clear(),s.set(t,{json:r,marks:o}),o}function al(e,t={}){const n={...Bs(e.doc,t[Ls],"t"),...t};delete n[Ls];for(const[r,s]of Object.entries(t))Fs.has(r)&&s!==null&&typeof s=="object"&&s._reviseStyleUnset===1&&Object.keys(s).length===1&&delete n[r];return n}function zs(e){if(!ll(e.doc))return e.toDelta();const t=[];for(const n of e.toDelta()){const r=al(e,n.attributes),s={...n};Object.keys(r).length?s.attributes=r:delete s.attributes;const i=t[t.length-1];i&&typeof i.insert=="string"&&typeof s.insert=="string"&&js(i.attributes??{})===js(s.attributes??{})?i.insert+=s.insert:t.push(s)}return t}function qe(e,t){const n=e.getAttribute(t);return n!=null||!Rs.has(t)||!e.doc?n:Bs(e.doc,e.getAttribute(ol),"p")[t]}function dl(e){const t=e.notes;if(!t||t.length===0)return;const n=new Map;let r;const s=c=>{if(!c||typeof c!="object")return;if(Array.isArray(c)){for(const d of c)s(d);return}const l=c;if(l.type==="text"){r===void 0&&typeof l.text=="string"&&l.text.length>0&&(r=l.marks?.fontFamily),l.marks?.footnoteRef&&!n.has(l.marks.footnoteRef)&&n.set(l.marks.footnoteRef,l.marks?.fontFamily);return}l.children&&s(l.children)};s(e.children);let i=!1;const o=t.map(c=>{const l=c.id,d=n.has(l)?n.get(l)??r:r;let a=!1;const h=c.children.map(u=>{if(u.type!=="paragraph"||!Array.isArray(u.children))return u;let g=!1;const f=u.children.map(p=>{if(p.type!=="text")return p;const _=p.marks??{};if(_.fontFamily===d||d===void 0&&_.fontFamily===void 0)return p;g=!0;const y={..._};return d===void 0?delete y.fontFamily:y.fontFamily=d,{...p,marks:y}});return g?(a=!0,{...u,children:f}):u});return a?(i=!0,{...c,children:h}):c});i&&(e.notes=o)}function Ws(e,t){if(!t)return;const n=new Set(t.split(","));n.has("keepNext")&&(e.keepNext=!0),n.has("keepLines")&&(e.keepLines=!0),n.has("noWidow")&&(e.widowControl=!1)}function we(){const e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let t="";for(let n=0;n<6;n++)t+=e.charAt(Math.floor(Math.random()*e.length));return t}const hl=[{value:"arial",label:"Arial",cssValue:"Arial, sans-serif"},{value:"helvetica",label:"Helvetica",cssValue:"Helvetica, Arial, sans-serif"},{value:"times",label:"Times New Roman",cssValue:"'Times New Roman', Times, serif"},{value:"computermodern",label:"Computer Modern",cssValue:"KaTeX_Main, 'Times New Roman', serif"},{value:"georgia",label:"Georgia",cssValue:"Georgia, serif"},{value:"sourceserif4",label:"Source Serif 4",cssValue:"'Source Serif 4', serif"},{value:"garamond",label:"Garamond",cssValue:"Garamond, 'Times New Roman', serif"},{value:"palatino",label:"Palatino",cssValue:"'Palatino Linotype', Palatino, serif"},{value:"bookman",label:"Bookman",cssValue:"'Bookman Old Style', Bookman, serif"},{value:"verdana",label:"Verdana",cssValue:"Verdana, Geneva, sans-serif"},{value:"trebuchet",label:"Trebuchet MS",cssValue:"'Trebuchet MS', Helvetica, sans-serif"},{value:"courier",label:"Courier New",cssValue:"'Courier New', Courier, monospace"},{value:"lucida",label:"Lucida Console",cssValue:"'Lucida Console', Monaco, monospace"},{value:"impact",label:"Impact",cssValue:"Impact, Charcoal, sans-serif"},{value:"comicsans",label:"Comic Sans MS",cssValue:"'Comic Sans MS', cursive"}];function ul(e){return e.trim().replace(/^["']|["']$/g,"")}const gl=new Map;let Js={};function fl(e){!e||Object.keys(e).length===0||(Js={...Js,...e},gl.clear())}new Set(hl.map(e=>ul(e.cssValue.split(",")[0]).toLowerCase()));const pl=["bold","italic","underline","strikethrough","doubleStrikethrough","smallCaps","allCaps","hidden","superscript","subscript"],ke="Arial, sans-serif",ml=new Set(pl);function Hs(e){const t=bl(e);for(const n of ml)e?.[n]===!1&&(t[n]=!1);return t}function bl(e){const t={};for(const[n,r]of Object.entries(e??{}))r===!0?t[n]=!0:(typeof r=="string"&&r!==""||typeof r=="number")&&(t[n]=r);return t.fontFamily||(t.fontFamily=ke),t}function yl(e){const t=e;return JSON.stringify(Object.keys(t).sort().map(n=>[n,t[n]]))}function Gs(e){const t=[];let n=null;for(const r of e){const s=yl(r.marks??{}),i=t[t.length-1];if(i&&s===n){t[t.length-1]={...i,text:i.text+r.text};continue}t.push(r),n=s}return t}Object.fromEntries("aliceblue:f0f8ff,antiquewhite:faebd7,aqua:00ffff,aquamarine:7fffd4,azure:f0ffff,beige:f5f5dc,bisque:ffe4c4,black:000000,blanchedalmond:ffebcd,blue:0000ff,blueviolet:8a2be2,brown:a52a2a,burlywood:deb887,cadetblue:5f9ea0,chartreuse:7fff00,chocolate:d2691e,coral:ff7f50,cornflowerblue:6495ed,cornsilk:fff8dc,crimson:dc143c,cyan:00ffff,darkblue:00008b,darkcyan:008b8b,darkgoldenrod:b8860b,darkgray:a9a9a9,darkgreen:006400,darkgrey:a9a9a9,darkkhaki:bdb76b,darkmagenta:8b008b,darkolivegreen:556b2f,darkorange:ff8c00,darkorchid:9932cc,darkred:8b0000,darksalmon:e9967a,darkseagreen:8fbc8f,darkslateblue:483d8b,darkslategray:2f4f4f,darkslategrey:2f4f4f,darkturquoise:00ced1,darkviolet:9400d3,deeppink:ff1493,deepskyblue:00bfff,dimgray:696969,dimgrey:696969,dodgerblue:1e90ff,firebrick:b22222,floralwhite:fffaf0,forestgreen:228b22,fuchsia:ff00ff,gainsboro:dcdcdc,ghostwhite:f8f8ff,gold:ffd700,goldenrod:daa520,gray:808080,green:008000,greenyellow:adff2f,grey:808080,honeydew:f0fff0,hotpink:ff69b4,indianred:cd5c5c,indigo:4b0082,ivory:fffff0,khaki:f0e68c,lavender:e6e6fa,lavenderblush:fff0f5,lawngreen:7cfc00,lemonchiffon:fffacd,lightblue:add8e6,lightcoral:f08080,lightcyan:e0ffff,lightgoldenrodyellow:fafad2,lightgray:d3d3d3,lightgreen:90ee90,lightgrey:d3d3d3,lightpink:ffb6c1,lightsalmon:ffa07a,lightseagreen:20b2aa,lightskyblue:87cefa,lightslategray:778899,lightslategrey:778899,lightsteelblue:b0c4de,lightyellow:ffffe0,lime:00ff00,limegreen:32cd32,linen:faf0e6,magenta:ff00ff,maroon:800000,mediumaquamarine:66cdaa,mediumblue:0000cd,mediumorchid:ba55d3,mediumpurple:9370db,mediumseagreen:3cb371,mediumslateblue:7b68ee,mediumspringgreen:00fa9a,mediumturquoise:48d1cc,mediumvioletred:c71585,midnightblue:191970,mintcream:f5fffa,mistyrose:ffe4e1,moccasin:ffe4b5,navajowhite:ffdead,navy:000080,oldlace:fdf5e6,olive:808000,olivedrab:6b8e23,orange:ffa500,orangered:ff4500,orchid:da70d6,palegoldenrod:eee8aa,palegreen:98fb98,paleturquoise:afeeee,palevioletred:db7093,papayawhip:ffefd5,peachpuff:ffdab9,peru:cd853f,pink:ffc0cb,plum:dda0dd,powderblue:b0e0e6,purple:800080,rebeccapurple:663399,red:ff0000,rosybrown:bc8f8f,royalblue:4169e1,saddlebrown:8b4513,salmon:fa8072,sandybrown:f4a460,seagreen:2e8b57,seashell:fff5ee,sienna:a0522d,silver:c0c0c0,skyblue:87ceeb,slateblue:6a5acd,slategray:708090,slategrey:708090,snow:fffafa,springgreen:00ff7f,steelblue:4682b4,tan:d2b48c,teal:008080,thistle:d8bfd8,tomato:ff6347,turquoise:40e0d0,violet:ee82ee,wheat:f5deb3,white:ffffff,whitesmoke:f5f5f5,yellow:ffff00,yellowgreen:9acd32".split(",").map(e=>e.split(":")));const wl=6,kl=96,Qt=96,Sl=1*Qt,zn=Qt*.5,_l=1;function vl(e){return typeof e!="number"||!Number.isFinite(e)?0:Math.max(0,e)}function xl(e){return typeof e!="number"||!Number.isFinite(e)?0:Math.max(0,Math.round(e))}function Cl(e){if(typeof e!="number"||!Number.isFinite(e))return 0;const t=Math.round(e);return t<0?-1:t>0?1:0}function Xs(e,t=zn){return!Number.isFinite(t)||t<=0?0:Math.max(0,Math.round(vl(e)/t))}function qs(e,t){const n=t?.indentStepPx??zn;if(t?.firstLine){const s=t?.storedAsUnits?Cl(e):e&&e<0?-1:Xs(e,n)>0?_l:0;return s===0?void 0:s}const r=t?.storedAsUnits?xl(e):Xs(e,n);return r>0?r:void 0}function $s(e,t){return typeof e=="object"&&e!==null&&e.constructor?.name===t}function Wn(e){return e instanceof rt||$s(e,"YXmlElement")&&typeof e.nodeName=="string"&&typeof e.getAttribute=="function"}function El(e){return e instanceof Kt||$s(e,"YXmlText")&&typeof e.toDelta=="function"}const Al="Arial, sans-serif",H=[{attr:"structuralSuggestionId",kind:"string"},{attr:"structuralSuggestionKind",kind:"enum",enum:["insert","delete","split","merge","change"]},{attr:"structuralSuggestionRole",kind:"enum",enum:["before","after"]},{attr:"structuralSuggestionLabel",kind:"string"},{attr:"structuralSuggestionRecord",kind:"string"},{attr:"structuralSuggestionRecords",kind:"string"}],R=[{attr:"diffState",kind:"enum",enum:["insert","delete","equal"]},{attr:"suggestionId",kind:"string"}];[...H.map(e=>e.attr),...R.map(e=>e.attr)];const Jn=Object.fromEntries([{type:"paragraph",attrs:[{attr:"heading",kind:"int"},{attr:"align",kind:"string"},{attr:"lineSpacing",kind:"float"},{attr:"spaceBefore",kind:"float"},{attr:"spaceAfter",kind:"float"},{attr:"contextualSpacing",kind:"boolean"},{attr:"styleId",kind:"string"},{attr:"direction",kind:"string"},{attr:"tabStops",kind:"string"},{attr:"borders",kind:"string"},{attr:"shading",kind:"string"},{attr:"oxmlAttrs",kind:"string"},{attr:"oxmlPPr",kind:"string"},{attr:"leftIndent",kind:"float"},{attr:"firstLineIndent",kind:"float"},...H,...R],children:"text"},{type:"list",attrs:[{attr:"variant",kind:"string"},{attr:"startNumber",kind:"int"},{attr:"numberingChainId",kind:"string"},{attr:"numberingFormat",kind:"string"},...Bn.map(e=>({attr:e,kind:"float"})),{attr:"contextualSpacing",kind:"boolean"},...H,...R],children:"list-items"},{type:"list-item",attrs:[...Bn.map(e=>({attr:e,kind:"float"})),{attr:"checked",kind:"boolean"},{attr:"indentLevel",kind:"int",validate:e=>e>0},{attr:"direction",kind:"string"},...H],children:"text"},{type:"table",attrs:[{attr:"columnWidths",kind:"json"},{attr:"tableWidth",kind:"int"},{attr:"align",kind:"enum",enum:["left","center","right"]},{attr:"borderColor",kind:"string"},{attr:"borderWidth",kind:"int"},{attr:"borders",kind:"string"},{attr:"cellPadding",kind:"int"},{attr:"hasHeader",kind:"booleanTrue"},{attr:"docxTablePropertyOverrides",kind:"string"},{attr:"oxmlTblPr",kind:"string"},...H,...R],children:"table-rows"},{type:"table-row",attrs:[{attr:"oxmlAttrs",kind:"string"},{attr:"oxmlTrPr",kind:"string"},...R,...H],children:"blocks"},{type:"table-cell",attrs:[{attr:"verticalAlign",kind:"string"},{attr:"backgroundColor",kind:"string"},{attr:"borders",kind:"string"},{attr:"padding",kind:"string"},{attr:"colSpan",kind:"int",validate:e=>e>1},{attr:"rowSpan",kind:"int",validate:e=>e>1},{attr:"oxmlTcPr",kind:"string"},...R,...H],children:"blocks"},{type:"container",attrs:[{attr:"borderColor",kind:"string"},{attr:"padding",kind:"int"},...H,...R],children:"blocks"},{type:"header-footer",attrs:[{attr:"side",kind:"enum",enum:["header","footer"]},{attr:"slot",kind:"enum",enum:["default","first","even"]},{attr:"sectionIndex",kind:"int",validate:e=>e>=0}],children:"blocks"},{type:"footnote",attrs:[{attr:"noteKind",kind:"enum",enum:["endnote"]},...H,...R],children:"blocks"},{type:"code",attrs:[{attr:"language",kind:"string"},{attr:"toolCallId",kind:"string"},{attr:"renderDiagram",kind:"boolean"},{attr:"showDiagramSource",kind:"boolean"},...R,...H],children:"rawtext"},{type:"math",attrs:[{attr:"displayMode",kind:"enum",enum:["inline","block"]},{attr:"align",kind:"enum",enum:["left","center","right"]},...R,...H],children:"rawtext"},{type:"image",attrs:[{attr:"src",kind:"string"},{attr:"sourceUrl",kind:"string"},{attr:"width",kind:"int"},{attr:"height",kind:"int"},{attr:"alt",kind:"string"},{attr:"align",kind:"string"},{attr:"uploading",kind:"boolean"},{attr:"tempId",kind:"string"},{attr:"originalFormat",kind:"enum",enum:["emf","wmf"]},{attr:"originalDataUrl",kind:"string"},{attr:"anchorXml",kind:"string"},...R,...H],children:"none"},{type:"page-break",attrs:[...R],children:"none"},{type:"docx-raw",attrs:[{attr:"xml",kind:"string"},{attr:"tagName",kind:"string"},{attr:"detail",kind:"string"},{attr:"origin",kind:"enum",enum:["run","body"]},...H,...R],children:"none"},{type:"section-break",attrs:[{attr:"layout",kind:"json"},{attr:"breakType",kind:"enum",enum:["nextPage","continuous","evenPage","oddPage"]},...R],children:"none"},{type:"toc",attrs:[{attr:"direction",kind:"enum",enum:["rtl","ltr"]},{attr:"align",kind:"enum",enum:["left","center","right","justify"]},{attr:"levels",kind:"int",validate:e=>e>=1&&e<=6},{attr:"instr",kind:"string"},{attr:"fontFamily",kind:"string"},{attr:"fontSize",kind:"float",validate:e=>e>=wl&&e<=kl},{attr:"color",kind:"string"},...R],children:"none"},{type:"placeholder",attrs:[{attr:"height",kind:"int"}],children:"none"}].map(e=>[e.type,e])),Dl={image:{src:"",width:200,height:200},code:{content:""},math:{displayMode:"block"},placeholder:{height:100},list:{variant:"unordered"}};function Pl(e,t){if(!(t==null||t===""))switch(e.kind){case"string":return t;case"int":{const n=parseInt(t,10);return Number.isNaN(n)||e.validate&&!e.validate(n)?void 0:n}case"float":{const n=parseFloat(t);return Number.isNaN(n)||e.validate&&!e.validate(n)?void 0:n}case"boolean":return t==="true"?!0:t==="false"?!1:void 0;case"booleanTrue":return t==="true"?!0:void 0;case"json":try{return JSON.parse(t)}catch{return}case"enum":return e.enum?.includes(t)?t:void 0}}function Nl(e){const t=[],n=zs(e);for(const r of n){if(typeof r.insert!="string")continue;const s=r.attributes||{},i={type:"text",text:r.insert,marks:Hs(s)};t.push(i)}return Gs(t)}function Ks(e){for(let t=0;t<e.length;t++){const n=e.get(t);if(El(n))return n}return null}function Ys(e){const t=qe(e,"_emptyTextMarks");let n={fontFamily:Al};if(t)try{n=JSON.parse(t)}catch{}return[{type:"text",text:"",marks:n}]}function Il(e){const t=Ks(e);if(!t)return Ys(e);const n=Nl(t);return n.length>0?n:Ys(e)}function Ml(e,t){for(const[n,r]of[["leftIndent",!1],["firstLineIndent",!0]])if(typeof e[n]=="number"){if(e[n]===0)continue;const s=qs(e[n],{indentStepPx:t.indentStepPx,storedAsUnits:t.storedAsUnits,firstLine:r});s===void 0?delete e[n]:e[n]=s}}function $e(e,t,n,r){const s=e.nodeName,i=Jn[s]??Jn.paragraph,o=Jn[s]?s:"paragraph",c={type:o,id:qe(e,"id")||we()};for(const d of i.attrs){const a=Pl(d,qe(e,d.attr));a!==void 0&&(c[d.field??d.attr]=a)}o==="paragraph"&&Ws(c,qe(e,"pagination"));const l=Dl[o];if(l)for(const[d,a]of Object.entries(l))c[d]===void 0&&(c[d]=a);switch(i.children){case"text":c.children=Il(e);break;case"rawtext":{const d=Ks(e);c.content=d?d.toString():"";break}case"blocks":{const d=[];for(const a of e.toArray())if(Wn(a)){const h=$e(a,t);h&&d.push(h)}c.children=d;break}case"list-items":{const d=[];for(const a of e.toArray())if(Wn(a)&&a.nodeName==="list-item"){const h=$e(a,t);h&&d.push(h)}c.children=d;break}case"table-rows":{const d=[];for(const a of e.toArray())if(Wn(a)&&a.nodeName==="table-row"){const h=$e(a,t);h&&d.push(h)}c.children=d,c.columnWidths===void 0&&(c.columnWidths=[]);break}}return(o==="paragraph"||i.children==="text")&&Ml(c,t),c}function Tl(e){return!!e?.children.some(t=>t.type==="text"&&t.text.trim()!=="")}function Ol(e){const t=e.children,n=[2,1,0].find(s=>Tl(t[s]))??-1;if(n===-1)return;const r=[];for(let s=0;s<=n;s++){s>0&&r.push({type:"text",text:" "});for(const i of t[s]?.children??[])i.type==="text"&&i.text&&r.push(i)}return{type:"paragraph",id:e.id?`${e.id}-zone`:we(),children:r}}function Ul(e){const t={},n={};for(const r of e){if(r.type!=="header-footer"||r.sectionIndex!==void 0)continue;const s=Ol(r);if(!s)continue;const i=r.side==="header"?t:n;i[r.slot]=[s]}return{...Object.keys(t).length>0?{headers:t}:{},...Object.keys(n).length>0?{footers:n}:{}}}const Ll=["decimal","lowerRoman","upperRoman"];function Qs(e){return typeof e=="string"&&Ll.includes(e)}const Fl=["top","right","bottom","left"],Rl=["single","double","dotted","dashed"];function Zs(e){if(e===null||e==="")return null;if(e===void 0)return;if(typeof e=="string")try{e=JSON.parse(e)}catch{return}if(!e||typeof e!="object"||Array.isArray(e))return;const t=e,n={offsetFrom:t.offsetFrom==="page"?"page":"text",display:t.display==="firstPage"||t.display==="notFirstPage"?t.display:"allPages",zOrder:t.zOrder==="back"?"back":"front"};for(const r of Fl){const s=t[r];if(s!=null){if(!Rl.includes(s.style)||typeof s.color!="string"||!/^#[0-9a-f]{6}$/i.test(s.color)||typeof s.widthPt!="number"||!Number.isFinite(s.widthPt)||s.widthPt<.25||s.widthPt>12||typeof s.spacePt!="number"||!Number.isFinite(s.spacePt)||s.spacePt<0||s.spacePt>31)return;n[r]={style:s.style,color:s.color.toLowerCase(),widthPt:s.widthPt,spacePt:s.spacePt}}}return n}function jl(e){let t=e;if(typeof e=="string"){const c=e.trim();if(c==="")return null;try{t=JSON.parse(c)}catch{return null}}if(!t||typeof t!="object"||Array.isArray(t))return null;const n=t,r=typeof n.countBy=="number"&&Number.isFinite(n.countBy)&&n.countBy>=1?Math.round(n.countBy):1,s=typeof n.start=="number"&&Number.isFinite(n.start)&&n.start>=1?Math.round(n.start):1,i=n.restart==="newSection"||n.restart==="continuous"?n.restart:"newPage",o=typeof n.distancePx=="number"&&Number.isFinite(n.distancePx)&&n.distancePx>=0?n.distancePx:void 0;return{countBy:r,start:s,restart:i,...o!==void 0?{distancePx:o}:{}}}const Vl=1,k={pageBorders:"pageBorders",pageSize:"pageSize",orientation:"pageOrientation",marginPx:"pageMarginPx",marginTopPx:"pageMarginTopPx",marginRightPx:"pageMarginRightPx",marginBottomPx:"pageMarginBottomPx",marginLeftPx:"pageMarginLeftPx",indentStepPx:"indentStepPx",blockSpacingPx:"blockSpacingPx",showPageNumbers:"showPageNumbers",pageNumberPosition:"pageNumberPosition",pageNumberStart:"pageNumberStart",pageNumberFormat:"pageNumberFormat",pageNumberRestart:"pageNumberRestart",paragraphIndentStorageVersion:"paragraphIndentStorageVersion",hyphenationEnabled:"hyphenationEnabled",lineNumbering:"lineNumbering",columnCount:"columnCount",columnGapTwips:"columnGapTwips",oxmlSectPr:"oxmlSectPr"},Bl=["top-left","top-right","bottom-left","bottom-right"];function ti(e){return typeof e=="string"&&Bl.includes(e)}const ei={letter:{width:8.5,height:11},tabloid:{width:11,height:17},legal:{width:8.5,height:14},statement:{width:5.5,height:8.5},executive:{width:7.25,height:10.5},folio:{width:8.5,height:13},a3:{width:11.6929,height:16.5354},a4:{width:8.2677,height:11.6929},a5:{width:5.8268,height:8.2677},b4:{width:9.8425,height:13.8976},b5:{width:6.9291,height:9.8425}};Object.entries(ei).map(([e,t])=>({pageSize:e,width:Math.min(t.width,t.height),height:Math.max(t.width,t.height)}));function ni(e){return typeof e=="string"&&Object.prototype.hasOwnProperty.call(ei,e)}const zl=0,Wl=3*Qt,Jl=.125*Qt,Hl=2*Qt,Gl=0,Xl=2*Qt,ql=12,$l=1,Kl=99999,it={pageSize:"letter",orientation:"portrait",marginLeftPx:Sl,indentStepPx:zn,blockSpacingPx:ql,pageNumberPosition:"top-right",pageNumberStart:1,pageNumberFormat:"decimal",columnCount:1,columnGapTwips:720};function Zt(e,t,n){return Math.max(t,Math.min(n,e))}function Se(e){return typeof e!="number"||!Number.isFinite(e)?it.marginLeftPx:Zt(e,zl,Wl)}function Yl(e){return typeof e!="number"||!Number.isFinite(e)?it.indentStepPx:Zt(e,Jl,Hl)}function Ql(e){return typeof e!="number"||!Number.isFinite(e)?it.blockSpacingPx:Zt(e,Gl,Xl)}function Zl(e){return ti(e)?e:it.pageNumberPosition}function ta(e){return typeof e!="number"||!Number.isFinite(e)?it.pageNumberStart:Zt(Math.round(e),$l,Kl)}function ea(e){return typeof e!="number"||!Number.isFinite(e)?it.columnCount:Zt(Math.round(e),1,12)}function na(e){return typeof e!="number"||!Number.isFinite(e)?it.columnGapTwips:Zt(Math.round(e),0,14400)}function Hn(e){const t=e?.pageSize&&ni(e.pageSize)?e.pageSize:it.pageSize,n=e?.orientation==="landscape"||e?.orientation==="portrait"?e.orientation:it.orientation,r=Se(e?.marginPx);return{pageSize:t,orientation:n,pageBorders:Zs(e?.pageBorders),marginTopPx:Se(e?.marginTopPx??r),marginRightPx:Se(e?.marginRightPx??r),marginBottomPx:Se(e?.marginBottomPx??r),marginLeftPx:Se(e?.marginLeftPx??r),indentStepPx:Yl(e?.indentStepPx),blockSpacingPx:Ql(e?.blockSpacingPx),showPageNumbers:e?.showPageNumbers===!0,pageNumberPosition:Zl(e?.pageNumberPosition),pageNumberStart:ta(e?.pageNumberStart),pageNumberFormat:Qs(e?.pageNumberFormat)?e.pageNumberFormat:it.pageNumberFormat,...e?.pageNumberRestart===!0?{pageNumberRestart:!0}:{},noteMode:e?.noteMode==="endnotes"?"endnotes":"footnotes",columnCount:ea(e?.columnCount),columnGapTwips:na(e?.columnGapTwips),hyphenationEnabled:e?.hyphenationEnabled===!0,lineNumbering:jl(e?.lineNumbering),...(()=>{const s=e?.oxmlSectPr;return typeof s=="string"&&s?{oxmlSectPr:s}:{}})()}}const ra=[k.pageBorders,k.pageSize,k.orientation,k.marginTopPx,k.marginRightPx,k.marginBottomPx,k.marginLeftPx,k.marginPx,k.indentStepPx,k.blockSpacingPx,k.showPageNumbers,k.pageNumberPosition,k.pageNumberStart,k.pageNumberFormat,k.pageNumberRestart,k.hyphenationEnabled,k.lineNumbering,k.columnCount,k.columnGapTwips,k.oxmlSectPr];function sa(e){if(!ra.some(M=>e.has(M)))return;const t=e.get(k.pageSize),n=e.get(k.orientation),r=e.get(k.marginTopPx),s=e.get(k.marginRightPx),i=e.get(k.marginBottomPx),o=e.get(k.marginLeftPx),c=e.get(k.marginPx),l=e.get(k.indentStepPx),d=e.get(k.blockSpacingPx),a=e.get(k.showPageNumbers),h=e.get(k.pageNumberPosition),u=e.get(k.pageNumberStart),g=e.get(k.hyphenationEnabled),f=e.get(k.lineNumbering),p=e.get(k.columnCount),_=e.get(k.columnGapTwips),y=e.get(k.oxmlSectPr),w=ni(t)?t:void 0;return Hn({pageSize:w,orientation:n==="portrait"||n==="landscape"?n:void 0,marginTopPx:typeof r=="number"?r:void 0,marginRightPx:typeof s=="number"?s:void 0,marginBottomPx:typeof i=="number"?i:void 0,marginLeftPx:typeof o=="number"?o:void 0,marginPx:typeof c=="number"?c:void 0,indentStepPx:typeof l=="number"?l:void 0,blockSpacingPx:typeof d=="number"?d:void 0,showPageNumbers:typeof a=="boolean"?a:void 0,pageNumberPosition:ti(h)?h:void 0,pageNumberStart:typeof u=="number"?u:void 0,pageNumberFormat:Qs(e.get(k.pageNumberFormat))?e.get(k.pageNumberFormat):void 0,pageNumberRestart:e.get(k.pageNumberRestart)===!0?!0:void 0,hyphenationEnabled:typeof g=="boolean"?g:void 0,pageBorders:Zs(e.get(k.pageBorders)),lineNumbering:typeof f=="string"?f:void 0,columnCount:typeof p=="number"?p:void 0,columnGapTwips:typeof _=="number"?_:void 0,oxmlSectPr:typeof y=="string"&&y?y:void 0})}function ia(e,t){return typeof e=="object"&&e!==null&&e.constructor?.name===t}function Gn(e){return e instanceof rt||ia(e,"YXmlElement")&&typeof e.nodeName=="string"&&typeof e.getAttribute=="function"&&typeof e.setAttribute=="function"&&typeof e.get=="function"&&typeof e.length=="number"}function oa(e){return e.get(k.paragraphIndentStorageVersion)===Vl}function ca(e){return e.share.has("paragraphs")?e.getArray("paragraphs").length>0:!1}function la(e){return e.share.has("content")?e.getXmlFragment("content").length>0:!1}function aa(e){return!!(la(e)||ca(e))}const ri={indentStepPx:Hn(void 0).indentStepPx,storedAsUnits:!1};function si(e,t,n=!1){return qs(e,{indentStepPx:t.indentStepPx,storedAsUnits:t.storedAsUnits,firstLine:n})}function ii(e){const t=e.getMap("metadata"),n=t?.get("title"),r=t?.get("pageless"),s=sa(t),i={indentStepPx:Hn(s).indentStepPx,storedAsUnits:oa(t)},o=e.getXmlFragment("content");let c;if(o.length>0){c=[];for(const C of o.toArray())if(Gn(C)){const v=Xn(C,i);v&&c.push(v)}}else{const C=e.getArray("paragraphs"),v=t?.get("defaultFontFamily");c=[],C.forEach(xt=>{const Q=_e(xt,v,i);Q&&c.push(Q)})}const l={type:"doc",children:c};n&&(l.title=n),r!==void 0&&(l.pageless=r),s&&(l.pageLayout=s);const d=t?.get("coreProperties");d&&typeof d=="object"&&Object.keys(d).length>0&&(l.coreProperties={...d});const a=t?.get("fontSubstitutes");a&&typeof a=="object"&&Object.keys(a).length>0&&(l.fontSubstitutes={...a},fl(l.fontSubstitutes));const h=e.getXmlFragment("chrome"),u=[];for(const C of h.toArray())if(Gn(C)){const v=Xn(C,i);v&&v.type==="header-footer"&&u.push(v)}u.length>0&&(l.chrome=u);const g=e.getXmlFragment("notes"),f=[];for(const C of g.toArray())if(Gn(C)){const v=Xn(C,i);v&&v.type==="footnote"&&f.push(v)}const p=l.children.filter(C=>C.type==="footnote");p.length>0&&(l.children=l.children.filter(C=>C.type!=="footnote"),f.push(...p)),f.length>0&&(l.notes=f,dl(l));const _=Ul(u),y=t?.get("headers"),w=t?.get("footers"),M=_.headers??(y&&Object.keys(y).length>0?y:void 0),gt=_.footers??(w&&Object.keys(w).length>0?w:void 0);M&&(l.headers=M),gt&&(l.footers=gt);const ve=e.getMap("comments");if(ve.size>0){const C=[];ve.forEach(v=>{v&&typeof v=="object"&&C.push(v)}),C.length>0&&(C.sort((v,xt)=>(v.createdAt??"").localeCompare(xt.createdAt??"")),l.comments=C)}const te=e.getMap("sdt-wrappers");if(te.size>0){const C=[];if(te.forEach(v=>{v&&typeof v=="object"&&C.push(v)}),C.length>0){const v=new Map;l.children.forEach((Q,Qe)=>{Q.id&&v.set(Q.id,Qe)});const xt=Q=>Q.blockIds?.[0]??Q.startBlockId??"";C.sort((Q,Qe)=>(v.get(xt(Q))??Number.MAX_SAFE_INTEGER)-(v.get(xt(Qe))??Number.MAX_SAFE_INTEGER)||Q.id.localeCompare(Qe.id)),l.sdtWrappers=C}}const ee=e.getMap("oxml-ranges");if(ee.size>0){const C=[];ee.forEach(v=>{v&&typeof v=="object"&&C.push(v)}),C.length>0&&(C.sort((v,xt)=>v.id.localeCompare(xt.id)),l.oxmlRanges=C)}const Vt=e.getMap("metadata").get("stylesXml");typeof Vt=="string"&&Vt.length>0&&(l.stylesXml=Vt);const Bt=e.getMap("metadata").get("stylesheet");Bt&&typeof Bt=="object"&&Array.isArray(Bt.paragraphStyles)&&Bt.paragraphStyles.length>0&&(l.stylesheet=Bt);const zt=e.getMap("metadata").get("docxSource");zt&&typeof zt=="object"&&Array.isArray(zt.spans)&&(l.docxSource=zt);const qn=e.getMap("metadata").get("watermark");typeof qn=="string"&&qn.length>0&&(l.watermark=qn);const $n=e.getMap("metadata").get("chromeImages");return Array.isArray($n)&&$n.length>0&&(l.chromeImages=$n),l}function Xn(e,t=ri){return $e(e,t)}function _e(e,t,n=ri){const r=e.get("type")||"paragraph",s=e.get("id")||we();switch(r){case"page-break":const i={type:"page-break",id:s};{const o=e.get("diffState"),c=e.get("suggestionId");(o==="insert"||o==="delete"||o==="equal")&&(i.diffState=o),typeof c=="string"&&(i.suggestionId=c)}return i;case"section-break":{const o={type:"section-break",id:s},c=e.get("layout");if(typeof c=="string")try{o.layout=JSON.parse(c)}catch{}const l=e.get("breakType");(l==="nextPage"||l==="continuous"||l==="evenPage"||l==="oddPage")&&(o.breakType=l);const d=e.get("diffState"),a=e.get("suggestionId");return(d==="insert"||d==="delete"||d==="equal")&&(o.diffState=d),typeof a=="string"&&(o.suggestionId=a),o}case"toc":{const o={type:"toc",id:s},c=e.get("levels");typeof c=="number"&&c>=1&&c<=6&&(o.levels=c);const l=e.get("instr");typeof l=="string"&&l!==""&&(o.instr=l);const d=e.get("direction"),a=e.get("align");(d==="rtl"||d==="ltr")&&(o.direction=d),(a==="left"||a==="center"||a==="right"||a==="justify")&&(o.align=a);const h=e.get("fontFamily");typeof h=="string"&&h!==""&&(o.fontFamily=h);const u=e.get("fontSize");typeof u=="number"&&u>0&&(o.fontSize=u);const g=e.get("color");typeof g=="string"&&g!==""&&(o.color=g);const f=e.get("diffState"),p=e.get("suggestionId");return(f==="insert"||f==="delete"||f==="equal")&&(o.diffState=f),typeof p=="string"&&(o.suggestionId=p),o}case"placeholder":return{type:"placeholder",id:s,height:e.get("height")||100};case"image":{const o={type:"image",id:s,src:e.get("src")||"",sourceUrl:e.get("sourceUrl")||void 0,width:e.get("width")||200,height:e.get("height")||200,alt:e.get("alt")||void 0,align:e.get("align")||void 0},c=e.get("diffState"),l=e.get("suggestionId");(c==="insert"||c==="delete"||c==="equal")&&(o.diffState=c),typeof l=="string"&&(o.suggestionId=l);const d=e.get("uploading");d!==void 0&&(o.uploading=d);const a=e.get("tempId");a&&(o.tempId=a);const h=e.get("originalFormat");(h==="emf"||h==="wmf")&&(o.originalFormat=h);const u=e.get("originalDataUrl");typeof u=="string"&&u&&(o.originalDataUrl=u);const g=e.get("anchorXml");return typeof g=="string"&&g&&(o.anchorXml=g),o}case"list":{const o=e.get("items"),c=[];o&&o.forEach(u=>{const g=da(u);g&&c.push(g)});const l={type:"list",id:s,variant:e.get("variant")||"unordered",children:c},d=e.get("startNumber");d!==void 0&&(l.startNumber=d);const a=e.get("numberingChainId");a&&(l.numberingChainId=a);const h=e.get("numberingFormat");return h&&(l.numberingFormat=h),l}case"footnote":{const o=e.get("children"),c=[];o&&o.forEach(d=>{const a=_e(d,t,n);a&&c.push(a)});const l={type:"footnote",id:s,children:c};return e.get("noteKind")==="endnote"&&(l.noteKind="endnote"),l}case"container":{const o=e.get("children"),c=[];o&&o.forEach(h=>{const u=_e(h,t,n);u&&c.push(u)});const l={type:"container",id:s,children:c},d=e.get("borderColor");d&&(l.borderColor=d);const a=e.get("padding");return typeof a=="number"&&(l.padding=a),l}case"table":{const o=e.get("children"),c=[];o&&o.forEach(w=>{const M=w.get("id")||we(),gt=w.get("children"),ve=[];gt&>.forEach(Bt=>{const zt=_e(Bt,t,n);zt&&ve.push(zt)});const te={type:"table-row",id:M,children:ve},ee=w.get("oxmlAttrs");typeof ee=="string"&&ee&&(te.oxmlAttrs=ee);const Vt=w.get("oxmlTrPr");typeof Vt=="string"&&Vt&&(te.oxmlTrPr=Vt),c.push(te)});const l=e.get("columnWidths")||[],d={type:"table",id:s,children:c,columnWidths:l},a=e.get("tableWidth"),h=e.get("align"),u=e.get("borderColor"),g=e.get("borderWidth"),f=e.get("borders"),p=e.get("cellPadding"),_=e.get("hasHeader");a!==void 0&&(d.tableWidth=a),(h==="left"||h==="center"||h==="right")&&(d.align=h),u&&(d.borderColor=u),g!==void 0&&(d.borderWidth=g),typeof f=="string"&&f&&(d.borders=f),p!==void 0&&(d.cellPadding=p),_!==void 0&&(d.hasHeader=_);const y=e.get("oxmlTblPr");return typeof y=="string"&&y&&(d.oxmlTblPr=y),d}case"table-cell":{const o=e.get("children"),c=[];o&&o.forEach(_=>{const y=_e(_,t,n);y&&c.push(y)});const l={type:"table-cell",id:s,children:c},d=e.get("verticalAlign"),a=e.get("backgroundColor");d&&(l.verticalAlign=d),a&&(l.backgroundColor=a);const h=e.get("borders"),u=e.get("padding");typeof h=="string"&&h&&(l.borders=h),typeof u=="string"&&u&&(l.padding=u);const g=Number(e.get("colSpan")),f=Number(e.get("rowSpan"));Number.isFinite(g)&&g>1&&(l.colSpan=g),Number.isFinite(f)&&f>1&&(l.rowSpan=f);const p=e.get("oxmlTcPr");return typeof p=="string"&&p&&(l.oxmlTcPr=p),l}case"code":{const o=e.get("renderDiagram"),c=e.get("showDiagramSource"),l={type:"code",id:s,content:e.get("content")||"",language:e.get("language")||void 0,renderDiagram:typeof o=="boolean"?o:void 0,showDiagramSource:typeof c=="boolean"?c:void 0},d=e.get("diffState"),a=e.get("suggestionId");return(d==="insert"||d==="delete"||d==="equal")&&(l.diffState=d),typeof a=="string"&&(l.suggestionId=a),l}case"math":{const o=e.get("displayMode")||"block",c={type:"math",id:s,content:e.get("content")||"",displayMode:o},l=e.get("align");(l==="left"||l==="center"||l==="right"||l==="justify")&&(c.align=l);const d=e.get("diffState"),a=e.get("suggestionId");return(d==="insert"||d==="delete"||d==="equal")&&(c.diffState=d),typeof a=="string"&&(c.suggestionId=a),c}case"paragraph":default:{const o={type:"paragraph",id:s,children:[]},c=e.get("heading"),l=e.get("align"),d=e.get("lineSpacing"),a=e.get("leftIndent"),h=e.get("firstLineIndent"),u=e.get("structuralSuggestionId"),g=e.get("structuralSuggestionKind"),f=e.get("structuralSuggestionRole");c!==void 0&&(o.heading=c),l!==void 0&&(o.align=l),d!==void 0&&(o.lineSpacing=d),Ws(o,e.get("pagination"));{const w=e.get("styleId");typeof w=="string"&&w&&(o.styleId=w)}{const w=e.get("direction");(w==="rtl"||w==="ltr")&&(o.direction=w)}{const w=e.get("tabStops");typeof w=="string"&&w&&(o.tabStops=w)}{const w=e.get("borders");typeof w=="string"&&w&&(o.borders=w)}{const w=e.get("shading");typeof w=="string"&&w&&(o.shading=w)}{const w=e.get("oxmlAttrs");typeof w=="string"&&w&&(o.oxmlAttrs=w);const M=e.get("oxmlPPr");typeof M=="string"&&M&&(o.oxmlPPr=M)}typeof u=="string"&&(o.structuralSuggestionId=u),(g==="insert"||g==="delete"||g==="split"||g==="merge"||g==="change")&&(o.structuralSuggestionKind=g),(f==="before"||f==="after")&&(o.structuralSuggestionRole=f);const p=si(a,n);a===0?o.leftIndent=0:p!==void 0&&(o.leftIndent=p);const _=si(h,n,!0);h===0?o.firstLineIndent=0:_!==void 0&&(o.firstLineIndent=_);const y=e.get("content");if(y){const w=oi(y);if(w.length>0)o.children=w;else{const M=e.get("_emptyTextMarks"),gt={type:"text",text:""};M&&Object.keys(M).length>0?gt.marks=M:gt.marks={fontFamily:ke},o.children=[gt]}}else o.children=[{type:"text",text:"",marks:{fontFamily:ke}}];return t&&o.children.forEach(w=>{w.type==="text"&&(w.marks={fontFamily:t,...w.marks||{}})}),o}}}function da(e){if(!e)return null;const t={type:"list-item",id:e.get("id")||we(),children:[]},n=e.get("checked");n!==void 0&&(t.checked=n);const r=e.get("indentLevel");typeof r=="number"&&r>0&&(t.indentLevel=r);for(const o of Bn){const c=e.get(o);typeof c=="number"&&Number.isFinite(c)&&c>=0&&(t[o]=c)}const s=e.get("direction");(s==="rtl"||s==="ltr")&&(t.direction=s);const i=e.get("content");if(i){const o=oi(i);if(o.length>0)t.children=o;else{const c=e.get("_emptyTextMarks");t.children=[{type:"text",text:"",marks:c||{fontFamily:ke}}]}}else t.children=[{type:"text",text:"",marks:{fontFamily:ke}}];return t}function oi(e){const t=[];return zs(e).forEach(n=>{if(typeof n.insert=="string"){const r=n.attributes||{},s={type:"text",text:n.insert};s.marks=Hs(r),t.push(s)}}),Gs(t)}function jt(e,t){let n=e;for(let r=0;r<t.length;r++)n^=t.charCodeAt(r),n=Math.imul(n,16777619);return n>>>0}function ci(e,t){if(!e||typeof e!="object")return t;let n=t;if(typeof e.type=="string"&&(n=jt(n,e.type)),typeof e.text=="string"&&(n=jt(n,e.text)),typeof e.content=="string"&&(n=jt(n,e.content)),typeof e.language=="string"&&(n=jt(n,e.language)),e.marks&&(n=jt(n,JSON.stringify(e.marks))),Array.isArray(e.children)){n=jt(n,"[");for(const r of e.children)n=ci(r,n);n=jt(n,"]")}return n>>>0}function ha(e){return ci(e,2166136261)}function Ke(e){const t=atob(e),n=new Uint8Array(t.length);for(let r=0;r<t.length;r++)n[r]=t.charCodeAt(r);return n}function Ye(e,t){try{Dr(e,t),aa(e)||li(e,t)}catch{li(e,t)}}function li(e,t){const n=$c;if(typeof n.applyUpdateV2=="function")try{n.applyUpdateV2(e,t)}catch(r){console.warn("[HistoryWorker] Failed to apply V2 update:",r)}}function ua(e){const t=new nt({gc:!1});try{const n=Ke(e.snapshotB64);Ye(t,n);const r=e.uptoIndex<0?e.updatesB64.length:e.uptoIndex;for(let s=0;s<r&&s<e.updatesB64.length;s++)Ye(t,Ke(e.updatesB64[s]));return ii(t)}finally{t.destroy()}}function ga(e){const t=new Set(e.candidateIds),n=[];let r=null;for(const s of e.segments){const i=new nt({gc:!1});try{Ye(i,Ke(s.snapshotB64));for(let o=0;o<s.updatesB64.length;o++){Ye(i,Ke(s.updatesB64[o]));const c=s.startUpdateId+o;if(!t.has(c))continue;const l=ha(ii(i));l!==r&&(r=l,n.push(c))}}finally{i.destroy()}}return n}self.onmessage=e=>{const t=e.data;try{if(t.kind==="filterDistinct"){const s=ga(t),i={id:t.id,kind:"filterDistinct",success:!0,distinctIds:s};self.postMessage(i);return}const n=ua(t),r={id:t.id,success:!0,doc:n};self.postMessage(r)}catch(n){const r={id:t.id,kind:t.kind==="filterDistinct"?"filterDistinct":"materialize",success:!1,error:n instanceof Error?n.message:String(n)};self.postMessage(r)}}})();
|
package/backend.d.ts
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-side primitives. Node only.
|
|
3
|
+
*
|
|
4
|
+
* Peer dependencies: `yjs` (one copy, shared with anything else that touches
|
|
5
|
+
* the document) and `jsdom` (the converters parse XML and HTML with DOM
|
|
6
|
+
* APIs).
|
|
7
|
+
*/
|
|
8
|
+
import type { Doc } from "yjs";
|
|
9
|
+
import type {
|
|
10
|
+
ServerDocumentSession,
|
|
11
|
+
ServerDocumentSessionOptions,
|
|
12
|
+
} from "./serverToolContract.js";
|
|
13
|
+
|
|
14
|
+
/** Revise's document model. Opaque here — convert rather than inspect. */
|
|
15
|
+
export interface ReviseDocument {
|
|
16
|
+
type: "doc";
|
|
17
|
+
children: unknown[];
|
|
18
|
+
[key: string]: unknown;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Formats readable on the server. PDF and images are browser-only. */
|
|
22
|
+
export type ReviseServerFormat = "docx" | "markdown" | "txt" | "html";
|
|
23
|
+
|
|
24
|
+
/** Top-level keys the editor owns inside a shared document. */
|
|
25
|
+
export declare const RESERVED_DOCUMENT_KEYS: readonly string[];
|
|
26
|
+
|
|
27
|
+
/** A document built with the settings the editor requires. */
|
|
28
|
+
export declare function createReviseYDoc(): Doc;
|
|
29
|
+
|
|
30
|
+
/** Throws if a document already uses the editor's reserved keys for
|
|
31
|
+
* something else. */
|
|
32
|
+
export declare function assertUsableSharedDocument(ydoc: Doc): void;
|
|
33
|
+
|
|
34
|
+
/** Install the DOM globals the converters need. Called for you by everything
|
|
35
|
+
* here; exported for hosts importing converters directly. */
|
|
36
|
+
export declare function installDomShims(): Promise<void>;
|
|
37
|
+
|
|
38
|
+
/** Parse .docx, .md, .txt, or .html into the document model. */
|
|
39
|
+
export declare function parseDocument(
|
|
40
|
+
bytes: Uint8Array,
|
|
41
|
+
filename: string,
|
|
42
|
+
): Promise<ReviseDocument>;
|
|
43
|
+
|
|
44
|
+
/** Serialize the document model back to .docx bytes. With `originalDocx`
|
|
45
|
+
* (the file this document was imported from), untouched content exports
|
|
46
|
+
* byte-for-byte via graft mode; any graft-proof failure falls back to full
|
|
47
|
+
* regeneration. */
|
|
48
|
+
export declare function documentToDocx(
|
|
49
|
+
doc: ReviseDocument,
|
|
50
|
+
options?: { originalDocx?: Uint8Array },
|
|
51
|
+
): Promise<Uint8Array>;
|
|
52
|
+
|
|
53
|
+
/** Build a room's Yjs document from a file — server-side document creation,
|
|
54
|
+
* so every client simply joins. */
|
|
55
|
+
export declare function fileToYDoc(
|
|
56
|
+
bytes: Uint8Array,
|
|
57
|
+
filename: string,
|
|
58
|
+
): Promise<Doc>;
|
|
59
|
+
|
|
60
|
+
/** Seed an empty room from a file. Returns false when it already had
|
|
61
|
+
* content, so it is safe to call on every connection — including under a
|
|
62
|
+
* connect race: every seed records a claim, and a room two peers both
|
|
63
|
+
* seeded before syncing is repaired deterministically (on the next call
|
|
64
|
+
* here, or by any live editor session the moment the claims merge). */
|
|
65
|
+
export declare function seedYDocFromFile(
|
|
66
|
+
ydoc: Doc,
|
|
67
|
+
bytes: Uint8Array,
|
|
68
|
+
filename: string,
|
|
69
|
+
): Promise<boolean>;
|
|
70
|
+
|
|
71
|
+
export interface SeedRaceRepairResult {
|
|
72
|
+
/** Losing seed claims removed. */
|
|
73
|
+
losingClaims: number;
|
|
74
|
+
/** Top-level body blocks removed. */
|
|
75
|
+
removedBlocks: number;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Detect and repair a double-seed connect race: keep the deterministic
|
|
79
|
+
* winner and delete everything the losing seeds created. Idempotent and
|
|
80
|
+
* convergent — safe on any peer, at any time; null when there is nothing
|
|
81
|
+
* to repair. Editor sessions run this automatically. */
|
|
82
|
+
export declare function repairSeedRace(
|
|
83
|
+
ydoc: Doc,
|
|
84
|
+
): SeedRaceRepairResult | null;
|
|
85
|
+
|
|
86
|
+
/** Read a room back as the document model. */
|
|
87
|
+
export declare function ydocToDocument(ydoc: Doc): ReviseDocument;
|
|
88
|
+
|
|
89
|
+
/** Export a room straight to .docx. A DOCX-imported room carries its
|
|
90
|
+
* original file inside the document; untouched content exports
|
|
91
|
+
* byte-for-byte. */
|
|
92
|
+
export declare function ydocToDocx(ydoc: Doc): Promise<Uint8Array>;
|
|
93
|
+
|
|
94
|
+
/** DOCX-mode fidelity for a room: "exact" (export reproduces the original
|
|
95
|
+
* file byte-for-byte), "grafted" (original + this document's edits), or
|
|
96
|
+
* "converted" (no usable original; export regenerates). */
|
|
97
|
+
export declare function ydocSourceFidelity(ydoc: Doc): Promise<{
|
|
98
|
+
fidelity: "exact" | "grafted" | "converted";
|
|
99
|
+
regeneratedBlockIds: string[];
|
|
100
|
+
changedDomains: string[];
|
|
101
|
+
convertedReason?:
|
|
102
|
+
| "no-capture"
|
|
103
|
+
| "no-carrier"
|
|
104
|
+
| "carrier-hash-mismatch"
|
|
105
|
+
| "unpaired-capture";
|
|
106
|
+
}>;
|
|
107
|
+
|
|
108
|
+
/** Whether a room already holds a Revise document. */
|
|
109
|
+
export declare function hasDocument(ydoc: Doc): boolean;
|
|
110
|
+
|
|
111
|
+
/** The whole room as one update, for storage. */
|
|
112
|
+
export declare function encodeYDoc(ydoc: Doc): Uint8Array;
|
|
113
|
+
|
|
114
|
+
/** Restore a room from stored bytes. */
|
|
115
|
+
export declare function decodeYDoc(update: Uint8Array): Doc;
|
|
116
|
+
|
|
117
|
+
export type * from "./serverToolContract.js";
|
|
118
|
+
|
|
119
|
+
export declare class ReviseToolError<Name extends string = string> extends Error {
|
|
120
|
+
readonly failure: import("./serverToolContract.js").ReviseToolFailure<Name>;
|
|
121
|
+
readonly callId: string;
|
|
122
|
+
readonly tool: Name;
|
|
123
|
+
readonly code: string;
|
|
124
|
+
constructor(failure: import("./serverToolContract.js").ReviseToolFailure<Name>);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Bind the canonical deterministic semantic tools to a host-owned Y.Doc.
|
|
128
|
+
* Async: the tool session's mutation engine is loaded on first use, so
|
|
129
|
+
* conversion-only hosts never pay for it. */
|
|
130
|
+
export declare function createServerDocumentSession(
|
|
131
|
+
ydoc: Doc,
|
|
132
|
+
options: ServerDocumentSessionOptions,
|
|
133
|
+
): Promise<ServerDocumentSession>;
|
package/backend.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{bU as s,aN as a,bT as e,bS as o,bQ as c,bP as r,bH as b,bO as D,bI as t,bN as i,aO as m,bG as d,bR as n,bJ as S,bM as l,bK as u,bL as T}from"./chunks/backend-Cq-khfdG.js";import"yjs";export{s as RESERVED_DOCUMENT_KEYS,a as ReviseToolError,e as assertUsableSharedDocument,o as createReviseYDoc,c as createServerDocumentSession,r as decodeYDoc,b as documentToDocx,D as encodeYDoc,t as fileToYDoc,i as hasDocument,m as installDomShims,d as parseDocument,n as repairSeedRace,S as seedYDocFromFile,l as ydocSourceFidelity,u as ydocToDocument,T as ydocToDocx};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{y as P,z as I,A as E,B as L,S as R,E as q,F as D,H as $,I as N,J as F,K as H,L as B,M as j,N as W}from"./index-F-kHIwWT.js";function w(t,r,o,n){if(Array.isArray(t)){for(const s of t)w(s,r,o,n);return}if(!t||typeof t!="object")return;const a=t,e=typeof a.id=="string"?a.id:r;a.type==="math"&&typeof a.content=="string"&&o.push({content:a.content,displayMode:a.displayMode!=="inline",blockId:e}),a.type==="text"&&typeof a.text=="string"&&a.marks?.latex&&o.push({content:a.text,displayMode:!1,blockId:e}),a.type==="image"&&typeof a.src=="string"&&n.push({src:a.src,blockId:e,permanentlyPlaceholder:a.originalFormat==="emf"||a.originalFormat==="wmf"});for(const s of Object.values(a))if(Array.isArray(s))for(const l of s)w(l,e,o,n);else s&&typeof s=="object"&&w(s,e,o,n)}function S(){return new Promise(t=>{let r=!1;const o=()=>{r||(r=!0,clearTimeout(n),t())},n=setTimeout(o,50);typeof requestAnimationFrame=="function"&&requestAnimationFrame(o)})}async function G(t,r){if(t.length===0)return;const o=Promise.allSettled(t.map(n=>D(n.content,n.displayMode,r)));await Promise.race([o,new Promise(n=>setTimeout(n,2500))]),await S(),await S()}function v(t,r){if(typeof t.pageNumber=="number")return t.pageNumber-1;const o=t.bounds.y;return r.pageGeometries?.find(n=>o>=n.pageTop&&o<n.pageTop+n.pageHeight)?.pageIndex??0}function Y(t,r){return new Set(t.fragments.filter(o=>r.has(v(o,t))).map(o=>o.blockId))}function O(t){return t==="table"?"#7c3aed":t==="table-cell"||t==="table-row"?"#db2777":t==="image"?"#ea580c":t==="container"?"#2563eb":t==="math"?"#ca8a04":"#0891b2"}function A(t,r,o){t.save(),t.lineWidth=.75,t.setLineDash([4,3]),t.strokeStyle="rgba(22, 163, 74, 0.9)",t.strokeRect(o.marginLeft,o.marginTop,o.pageWidth-o.marginLeft-o.marginRight,o.pageHeight-o.marginTop-o.marginBottom),t.setLineDash([]);const n=new Set;for(const a of r.fragments){if(v(a,r)!==o.pageIndex)continue;const{bounds:e}=a,s=e.relativeToPage?e.y:e.y-o.pageTop,l=`${a.blockId}:${Math.round(e.x)}:${Math.round(s)}:${Math.round(e.width)}:${Math.round(e.height)}`;if(n.has(l)||e.width<=0||e.height<=0)continue;n.add(l);const m=O(a.block.type);if(t.strokeStyle=m,t.globalAlpha=.82,t.strokeRect(e.x,s,e.width,e.height),(a.block.type==="table"||a.block.type==="table-cell"||a.block.type==="image"||a.block.type==="container"||a.block.type==="math")&&e.width>=42&&e.height>=12){const p=`${a.block.type} #${a.blockId}`;t.font="10px ui-monospace, SFMono-Regular, Menlo, monospace",t.textAlign="left",t.textBaseline="top";const f=Math.min(e.width,t.measureText(p).width+5);t.globalAlpha=.88,t.fillStyle=m,t.fillRect(e.x,Math.max(0,s),f,13),t.globalAlpha=1,t.fillStyle="#ffffff",t.fillText(p,e.x+2,Math.max(0,s)+1,Math.max(1,f-4))}}t.restore()}function _(t,r){return{pageIndex:0,sectionIndex:0,pageTop:0,pageWidth:t.pageWidth,pageHeight:Math.min(4096,Math.max(t.pageHeight,r.totalHeight)),marginTop:t.pageMarginTop??t.pageMargin,marginRight:t.pageMarginRight??t.pageMargin,marginBottom:t.pageMarginBottom??t.pageMargin,marginLeft:t.pageMarginLeft??t.pageMargin,showPageNumbers:!1,pageNumberPosition:"bottom-right",renderedPageNumber:1}}function z(t){const r=document.createElement("canvas");r.width=Math.ceil(t.geometry.pageWidth),r.height=Math.ceil(t.geometry.pageHeight);const o=r.getContext("2d");if(!o)throw new Error("The browser could not create a page canvas.");const n=P(t.themeElement);o.fillStyle=n.pageBackground,o.fillRect(0,0,r.width,r.height);const a=I(o);t.editor.setTextMeasurementContext(a,t.layout);const e=$(o,r,t.layout,a);e.theme=n,e.currentPage=t.geometry.pageIndex,e.pageGeometry=t.geometry,e.yOffset=t.geometry.pageTop,e.startY=t.geometry.pageTop,e.endY=t.geometry.pageTop+t.geometry.pageHeight,e.pageLayoutSettings=t.pageLayoutSettings,e.headersContent=t.editor.getDocument().headers,e.footersContent=t.editor.getDocument().footers,e.watermark=N(t.editor.getDocument().watermark),e.totalPages=t.computed.pageCount,e.lineNumberMarks=t.computed.lineNumberMarks,e.headingPageNumbers=F(t.computed),e.syntaxTheme=H(t.codeTheme||"solarized",n.isDark),B(e,1);const s={showCursor:!1,isFocused:!1,readOnly:!0,printPreview:!0,forceImagePlaceholders:t.forceImagePlaceholders};if(t.pageless){const l={startY:0,endY:t.geometry.pageHeight};j(e,t.editor,l,s)}else W(e,t.editor,t.geometry.pageIndex,s);return t.mode==="layout"&&A(o,t.computed,t.geometry),r}function U(t,r,o){const n=o==="compact"?360:720,a=o==="compact"?Math.min(2,t.length):t.length,e=Math.ceil(t.length/a),s=16,l=16,m=26,p=t.map(c=>({width:n,height:Math.round(c.height/c.width*n)})),f=Array.from({length:e},(c,u)=>Math.max(...p.slice(u*a,(u+1)*a).map(h=>h.height+m))),d=document.createElement("canvas");d.width=l*2+a*n+Math.max(0,a-1)*s,d.height=l*2+f.reduce((c,u)=>c+u,0)+Math.max(0,e-1)*s;const g=d.getContext("2d");if(!g)throw new Error("The browser could not create a page contact sheet.");g.fillStyle="#e5e7eb",g.fillRect(0,0,d.width,d.height),g.fillStyle="#111827",g.font="600 14px ui-sans-serif, system-ui, sans-serif",g.textBaseline="top";let y=l;for(let c=0;c<e;c+=1){for(let u=0;u<a;u+=1){const h=c*a+u;if(h>=t.length)break;const b=l+u*(n+s);g.fillText(`Page ${r[h]}`,b,y+4),g.drawImage(t[h],b,y+m,p[h].width,p[h].height),g.strokeStyle="#9ca3af",g.strokeRect(b,y+m,p[h].width,p[h].height)}y+=f[c]+s}return d}async function K(t){const r=t.editor.getDocument(),o=P(t.themeElement),n=[],a=[];w(r,null,n,a),await G(n,o.text);const e=document.createElement("canvas");e.width=8,e.height=8;const s=e.getContext("2d");if(!s)throw new Error("The browser could not measure document pages.");const l=I(s);t.editor.setTextMeasurementContext(l,t.layout);const m=E(r,l,t.layout),p=m.pageGeometries?.length?m.pageGeometries:[_(t.layout,m)],f=p.length,d=t.request.startPage-1;if(d<0||d>=f)throw new Error(`start_page ${t.request.startPage} is outside this ${f}-page document.`);const g=p.slice(d,Math.min(f,d+t.request.pageCount)),y=new Set(g.map(i=>i.pageIndex)),c=Y(m,y),u=a.filter(i=>i.blockId===null||c.has(i.blockId)),h=await Promise.all(u.map(i=>i.permanentlyPlaceholder?Promise.resolve("placeholder"):L(i.src))),b=g.map(i=>z({editor:t.editor,layout:t.layout,computed:m,geometry:i,pageLayoutSettings:t.pageLayoutSettings,mode:t.request.mode,codeTheme:t.codeTheme,themeElement:t.themeElement,pageless:!!r.pageless})),M=g.map(i=>i.pageIndex+1),x=U(b,M,t.request.quality);let k;try{k=x.toDataURL("image/jpeg",t.request.quality==="compact"?.78:.9)}catch(i){throw typeof i=="object"&&i!==null&&"name"in i&&i.name==="SecurityError"?new R("visual_resource_unavailable","A document resource prevented safe page export. Re-upload external images and retry visual inspection.","verification",!1):i}const C=n.filter(i=>i.blockId===null||c.has(i.blockId)).filter(i=>{const T=q(i.content,i.displayMode,o.text);return T.loading||!T.image}).length;return{dataUrl:k,width:x.width,height:x.height,pages:M,totalPages:f,placeholderImageCount:h.filter(i=>i==="placeholder").length,failedImageCount:h.filter(i=>i==="failed").length,mathPlaceholderCount:C}}export{A as paintPageLayoutDiagnostics,K as renderDocumentPagesForAgent};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{y as P,z as I,A as E,B as L,S as R,E as q,F as D,H as $,I as N,J as F,K as H,L as B,M as j,N as W}from"./index-CLw_BlSL.js";function w(t,r,o,n){if(Array.isArray(t)){for(const s of t)w(s,r,o,n);return}if(!t||typeof t!="object")return;const a=t,e=typeof a.id=="string"?a.id:r;a.type==="math"&&typeof a.content=="string"&&o.push({content:a.content,displayMode:a.displayMode!=="inline",blockId:e}),a.type==="text"&&typeof a.text=="string"&&a.marks?.latex&&o.push({content:a.text,displayMode:!1,blockId:e}),a.type==="image"&&typeof a.src=="string"&&n.push({src:a.src,blockId:e,permanentlyPlaceholder:a.originalFormat==="emf"||a.originalFormat==="wmf"});for(const s of Object.values(a))if(Array.isArray(s))for(const l of s)w(l,e,o,n);else s&&typeof s=="object"&&w(s,e,o,n)}function S(){return new Promise(t=>{let r=!1;const o=()=>{r||(r=!0,clearTimeout(n),t())},n=setTimeout(o,50);typeof requestAnimationFrame=="function"&&requestAnimationFrame(o)})}async function G(t,r){if(t.length===0)return;const o=Promise.allSettled(t.map(n=>D(n.content,n.displayMode,r)));await Promise.race([o,new Promise(n=>setTimeout(n,2500))]),await S(),await S()}function v(t,r){if(typeof t.pageNumber=="number")return t.pageNumber-1;const o=t.bounds.y;return r.pageGeometries?.find(n=>o>=n.pageTop&&o<n.pageTop+n.pageHeight)?.pageIndex??0}function Y(t,r){return new Set(t.fragments.filter(o=>r.has(v(o,t))).map(o=>o.blockId))}function O(t){return t==="table"?"#7c3aed":t==="table-cell"||t==="table-row"?"#db2777":t==="image"?"#ea580c":t==="container"?"#2563eb":t==="math"?"#ca8a04":"#0891b2"}function A(t,r,o){t.save(),t.lineWidth=.75,t.setLineDash([4,3]),t.strokeStyle="rgba(22, 163, 74, 0.9)",t.strokeRect(o.marginLeft,o.marginTop,o.pageWidth-o.marginLeft-o.marginRight,o.pageHeight-o.marginTop-o.marginBottom),t.setLineDash([]);const n=new Set;for(const a of r.fragments){if(v(a,r)!==o.pageIndex)continue;const{bounds:e}=a,s=e.relativeToPage?e.y:e.y-o.pageTop,l=`${a.blockId}:${Math.round(e.x)}:${Math.round(s)}:${Math.round(e.width)}:${Math.round(e.height)}`;if(n.has(l)||e.width<=0||e.height<=0)continue;n.add(l);const m=O(a.block.type);if(t.strokeStyle=m,t.globalAlpha=.82,t.strokeRect(e.x,s,e.width,e.height),(a.block.type==="table"||a.block.type==="table-cell"||a.block.type==="image"||a.block.type==="container"||a.block.type==="math")&&e.width>=42&&e.height>=12){const p=`${a.block.type} #${a.blockId}`;t.font="10px ui-monospace, SFMono-Regular, Menlo, monospace",t.textAlign="left",t.textBaseline="top";const f=Math.min(e.width,t.measureText(p).width+5);t.globalAlpha=.88,t.fillStyle=m,t.fillRect(e.x,Math.max(0,s),f,13),t.globalAlpha=1,t.fillStyle="#ffffff",t.fillText(p,e.x+2,Math.max(0,s)+1,Math.max(1,f-4))}}t.restore()}function _(t,r){return{pageIndex:0,sectionIndex:0,pageTop:0,pageWidth:t.pageWidth,pageHeight:Math.min(4096,Math.max(t.pageHeight,r.totalHeight)),marginTop:t.pageMarginTop??t.pageMargin,marginRight:t.pageMarginRight??t.pageMargin,marginBottom:t.pageMarginBottom??t.pageMargin,marginLeft:t.pageMarginLeft??t.pageMargin,showPageNumbers:!1,pageNumberPosition:"bottom-right",renderedPageNumber:1}}function z(t){const r=document.createElement("canvas");r.width=Math.ceil(t.geometry.pageWidth),r.height=Math.ceil(t.geometry.pageHeight);const o=r.getContext("2d");if(!o)throw new Error("The browser could not create a page canvas.");const n=P(t.themeElement);o.fillStyle=n.pageBackground,o.fillRect(0,0,r.width,r.height);const a=I(o);t.editor.setTextMeasurementContext(a,t.layout);const e=$(o,r,t.layout,a);e.theme=n,e.currentPage=t.geometry.pageIndex,e.pageGeometry=t.geometry,e.yOffset=t.geometry.pageTop,e.startY=t.geometry.pageTop,e.endY=t.geometry.pageTop+t.geometry.pageHeight,e.pageLayoutSettings=t.pageLayoutSettings,e.headersContent=t.editor.getDocument().headers,e.footersContent=t.editor.getDocument().footers,e.watermark=N(t.editor.getDocument().watermark),e.totalPages=t.computed.pageCount,e.lineNumberMarks=t.computed.lineNumberMarks,e.headingPageNumbers=F(t.computed),e.syntaxTheme=H(t.codeTheme||"solarized",n.isDark),B(e,1);const s={showCursor:!1,isFocused:!1,readOnly:!0,printPreview:!0,forceImagePlaceholders:t.forceImagePlaceholders};if(t.pageless){const l={startY:0,endY:t.geometry.pageHeight};j(e,t.editor,l,s)}else W(e,t.editor,t.geometry.pageIndex,s);return t.mode==="layout"&&A(o,t.computed,t.geometry),r}function U(t,r,o){const n=o==="compact"?360:720,a=o==="compact"?Math.min(2,t.length):t.length,e=Math.ceil(t.length/a),s=16,l=16,m=26,p=t.map(c=>({width:n,height:Math.round(c.height/c.width*n)})),f=Array.from({length:e},(c,u)=>Math.max(...p.slice(u*a,(u+1)*a).map(h=>h.height+m))),d=document.createElement("canvas");d.width=l*2+a*n+Math.max(0,a-1)*s,d.height=l*2+f.reduce((c,u)=>c+u,0)+Math.max(0,e-1)*s;const g=d.getContext("2d");if(!g)throw new Error("The browser could not create a page contact sheet.");g.fillStyle="#e5e7eb",g.fillRect(0,0,d.width,d.height),g.fillStyle="#111827",g.font="600 14px ui-sans-serif, system-ui, sans-serif",g.textBaseline="top";let y=l;for(let c=0;c<e;c+=1){for(let u=0;u<a;u+=1){const h=c*a+u;if(h>=t.length)break;const b=l+u*(n+s);g.fillText(`Page ${r[h]}`,b,y+4),g.drawImage(t[h],b,y+m,p[h].width,p[h].height),g.strokeStyle="#9ca3af",g.strokeRect(b,y+m,p[h].width,p[h].height)}y+=f[c]+s}return d}async function K(t){const r=t.editor.getDocument(),o=P(t.themeElement),n=[],a=[];w(r,null,n,a),await G(n,o.text);const e=document.createElement("canvas");e.width=8,e.height=8;const s=e.getContext("2d");if(!s)throw new Error("The browser could not measure document pages.");const l=I(s);t.editor.setTextMeasurementContext(l,t.layout);const m=E(r,l,t.layout),p=m.pageGeometries?.length?m.pageGeometries:[_(t.layout,m)],f=p.length,d=t.request.startPage-1;if(d<0||d>=f)throw new Error(`start_page ${t.request.startPage} is outside this ${f}-page document.`);const g=p.slice(d,Math.min(f,d+t.request.pageCount)),y=new Set(g.map(i=>i.pageIndex)),c=Y(m,y),u=a.filter(i=>i.blockId===null||c.has(i.blockId)),h=await Promise.all(u.map(i=>i.permanentlyPlaceholder?Promise.resolve("placeholder"):L(i.src))),b=g.map(i=>z({editor:t.editor,layout:t.layout,computed:m,geometry:i,pageLayoutSettings:t.pageLayoutSettings,mode:t.request.mode,codeTheme:t.codeTheme,themeElement:t.themeElement,pageless:!!r.pageless})),M=g.map(i=>i.pageIndex+1),x=U(b,M,t.request.quality);let k;try{k=x.toDataURL("image/jpeg",t.request.quality==="compact"?.78:.9)}catch(i){throw typeof i=="object"&&i!==null&&"name"in i&&i.name==="SecurityError"?new R("visual_resource_unavailable","A document resource prevented safe page export. Re-upload external images and retry visual inspection.","verification",!1):i}const C=n.filter(i=>i.blockId===null||c.has(i.blockId)).filter(i=>{const T=q(i.content,i.displayMode,o.text);return T.loading||!T.image}).length;return{dataUrl:k,width:x.width,height:x.height,pages:M,totalPages:f,placeholderImageCount:h.filter(i=>i==="placeholder").length,failedImageCount:h.filter(i=>i==="failed").length,mathPlaceholderCount:C}}export{A as paintPageLayoutDiagnostics,K as renderDocumentPagesForAgent};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{O as d,P as g,Q as y}from"./index-F-kHIwWT.js";const f="This attachment was stored in an older per-page image format that cannot be imported. Ask the user to re-attach the original file.";async function D(e){if(e.type==="pdf"&&(e.urls?.length??0)>1)throw new Error(f);const o=e.urls?.[0];if(!o)throw new Error("The attachment no longer has an importable file URL.");const r=await fetch(o);if(!r.ok)throw new Error(`Could not download the attachment (${r.status}).`);const n=await r.blob();if(n.type.startsWith("image/"))throw new Error(f);const t=e.type==="pdf"?"attachment.pdf":"attachment.docx";return new File([n],e.fileName||t,{type:e.mimeType||n.type})}async function k(e){const{attachment:o,documentId:r,documentSession:n}=e,t=e.afterBlockId?.trim()||void 0;if(o.type!=="docx"&&o.type!=="pdf")throw new Error("Only DOCX and PDF attachments can be imported into the document.");const h=n.getWorkingDocument(),u=h.children.length;if(!d(h)&&!t)throw new Error("The current document has content. Provide after_block_id to insert the attachment after a current top-level block without replacing existing content.");if(t&&!h.children.some(a=>a.id===t))throw new Error(`Block "${t}" was not found as a top-level insertion anchor. Read the document and use a current top-level block ID.`);const m=await D(o);let p;if(o.type==="docx"){const{FileImporter:a}=await import("./FileImporter-q9mCch0J.js"),s=await a.parseFile(m),i=n.getYDoc();if(t)p=g(i,s,t);else{if(!d(n.getWorkingDocument()))throw new Error("The current document is no longer empty; import was cancelled. Read the document and provide after_block_id to insert the attachment without replacing existing content.");const l=s.pendingDocxCarrier;if(delete s.pendingDocxCarrier,i.transact(()=>{const c=i.getXmlFragment("content");c.length>0&&c.delete(0,c.length),y(i,s)}),l){const{storeDocxCarrier:c}=await import("./DocxGraft-DcmFuUkd.js");await c(i,l.bytes,{hash:l.hash})}}}else{const{importPdfIntoExistingDocument:a}=await import("./PdfImportService-CBD8TL1k.js");await a(m,r,n.getYDoc(),void 0,t)}const w=n.getWorkingDocument();return{blockCount:p??(t?Math.max(0,w.children.length-u):w.children.length),fileName:o.fileName||m.name}}export{k as importAttachmentIntoDocument,d as isEmptyDocumentForAttachmentImport};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{O as d,P as g,Q as y}from"./index-CLw_BlSL.js";const f="This attachment was stored in an older per-page image format that cannot be imported. Ask the user to re-attach the original file.";async function D(e){if(e.type==="pdf"&&(e.urls?.length??0)>1)throw new Error(f);const o=e.urls?.[0];if(!o)throw new Error("The attachment no longer has an importable file URL.");const r=await fetch(o);if(!r.ok)throw new Error(`Could not download the attachment (${r.status}).`);const n=await r.blob();if(n.type.startsWith("image/"))throw new Error(f);const t=e.type==="pdf"?"attachment.pdf":"attachment.docx";return new File([n],e.fileName||t,{type:e.mimeType||n.type})}async function k(e){const{attachment:o,documentId:r,documentSession:n}=e,t=e.afterBlockId?.trim()||void 0;if(o.type!=="docx"&&o.type!=="pdf")throw new Error("Only DOCX and PDF attachments can be imported into the document.");const h=n.getWorkingDocument(),u=h.children.length;if(!d(h)&&!t)throw new Error("The current document has content. Provide after_block_id to insert the attachment after a current top-level block without replacing existing content.");if(t&&!h.children.some(a=>a.id===t))throw new Error(`Block "${t}" was not found as a top-level insertion anchor. Read the document and use a current top-level block ID.`);const m=await D(o);let p;if(o.type==="docx"){const{FileImporter:a}=await import("./FileImporter-DVnYOJHp.js"),s=await a.parseFile(m),i=n.getYDoc();if(t)p=g(i,s,t);else{if(!d(n.getWorkingDocument()))throw new Error("The current document is no longer empty; import was cancelled. Read the document and provide after_block_id to insert the attachment without replacing existing content.");const l=s.pendingDocxCarrier;if(delete s.pendingDocxCarrier,i.transact(()=>{const c=i.getXmlFragment("content");c.length>0&&c.delete(0,c.length),y(i,s)}),l){const{storeDocxCarrier:c}=await import("./DocxGraft-CJ12C9WP.js");await c(i,l.bytes,{hash:l.hash})}}}else{const{importPdfIntoExistingDocument:a}=await import("./PdfImportService-D6uUKGMf.js");await a(m,r,n.getYDoc(),void 0,t)}const w=n.getWorkingDocument();return{blockCount:p??(t?Math.max(0,w.children.length-u):w.children.length),fileName:o.fileName||m.name}}export{k as importAttachmentIntoDocument,d as isEmptyDocumentForAttachmentImport};
|