document-model 1.0.43 → 1.0.45

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.
Files changed (33) hide show
  1. package/dist/browser/document-model.cjs +1 -1
  2. package/dist/browser/document-model.js +2 -2
  3. package/dist/browser/document.cjs +1 -1
  4. package/dist/browser/document.js +2 -2
  5. package/dist/browser/index.cjs +1 -1
  6. package/dist/browser/index.js +3 -3
  7. package/dist/browser/internal/{index-CDcO7NCS.js → index-BzIVYv7p.js} +1 -1
  8. package/dist/browser/internal/{index-DhzefrNj.js → index-CPJM383s.js} +1 -1
  9. package/dist/{node/internal/index-fctxJxHD.js → browser/internal/index-REU04m7f.js} +1 -1
  10. package/dist/{node/internal/index-D_LMFQg7.js → browser/internal/index-tEH7iGUj.js} +1 -1
  11. package/dist/browser/internal/{object-CrDRbO7a.js → object-Dev4WFVH.js} +824 -808
  12. package/dist/browser/internal/object-DkoS83BB.js +25 -0
  13. package/dist/browser/src/document/types.d.ts +2 -0
  14. package/dist/browser/src/document/utils/base.d.ts +7 -2
  15. package/dist/browser/src/document/utils/file.d.ts +3 -2
  16. package/dist/node/document-model.cjs +1 -1
  17. package/dist/node/document-model.js +2 -2
  18. package/dist/node/document.cjs +1 -1
  19. package/dist/node/document.js +2 -2
  20. package/dist/node/index.cjs +1 -1
  21. package/dist/node/index.js +3 -3
  22. package/dist/node/internal/{index-BWW7KbVk.js → index-BX95XaQ_.js} +1 -1
  23. package/dist/node/internal/{index-Cz8HaIxu.js → index-BzNCX_-9.js} +1 -1
  24. package/dist/{browser/internal/index-CfgX2mMt.js → node/internal/index-CRjFLQNR.js} +1 -1
  25. package/dist/{browser/internal/index-EdTViyyq.js → node/internal/index-DpH4_29z.js} +1 -1
  26. package/dist/node/internal/{object-BDRv-l-h.js → object-BFkXGmt6.js} +624 -608
  27. package/dist/node/internal/object-CGt7Qacd.js +20 -0
  28. package/dist/node/src/document/types.d.ts +2 -0
  29. package/dist/node/src/document/utils/base.d.ts +7 -2
  30. package/dist/node/src/document/utils/file.d.ts +3 -2
  31. package/package.json +2 -5
  32. package/dist/browser/internal/object-BkewFVld.js +0 -25
  33. package/dist/node/internal/object-Br6jYeW0.js +0 -20
@@ -0,0 +1,20 @@
1
+ "use strict";var se=Object.defineProperty;var ae=(e,t,i)=>t in e?se(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i;var ot=(e,t,i)=>(ae(e,typeof t!="symbol"?t+"":t,i),i);const U=require("immer"),u=require("zod"),pe=require("crypto"),lt=require("fs"),ce=require("https"),le=require("path"),zt=require("jszip"),Et=e=>e!=null,me=u.z.any().refine(e=>Et(e)),vt=u.z.enum(["LOAD_STATE"]),Tt=u.z.enum(["PRUNE"]),kt=u.z.enum(["REDO"]),_t=u.z.enum(["SET_NAME"]),Dt=u.z.enum(["UNDO"]);function ue(){return u.z.object({__typename:u.z.literal("Action").optional(),type:u.z.string()})}function X(){return u.z.literal("global").or(u.z.literal("local"))}function At(){return u.z.union([Nt(),Pt(),Ft(),It(),Rt()])}function fe(){return u.z.object({__typename:u.z.literal("DocumentFile").optional(),data:u.z.string(),extension:u.z.string().nullable(),fileName:u.z.string().nullable(),mimeType:u.z.string()})}function Nt(){return u.z.object({input:u.z.lazy(()=>gt()),type:vt,scope:X()})}function gt(){return u.z.object({operations:u.z.number(),state:u.z.lazy(()=>Mt())})}function Mt(){return u.z.object({data:u.z.unknown().nullish(),name:u.z.string()})}function de(){return u.z.object({__typename:u.z.literal("Operation").optional(),hash:u.z.string(),index:u.z.number(),timestamp:u.z.string().datetime(),type:u.z.string()})}function Pt(){return u.z.object({input:u.z.lazy(()=>ht()),type:Tt,scope:X()})}function ht(){return u.z.object({end:u.z.number().nullish(),start:u.z.number().nullish()})}const xt=u.z.number;function Ft(){return u.z.object({input:xt(),type:kt,scope:X()})}const yt=u.z.string;function It(){return u.z.object({input:yt(),type:_t,scope:u.z.literal("global")})}function ge(){return u.z.object({__typename:u.z.literal("SetNameOperation").optional(),hash:u.z.string(),index:u.z.number(),input:u.z.string(),timestamp:u.z.string().datetime(),type:u.z.string()})}const bt=u.z.number;function Rt(){return u.z.object({input:bt(),type:Dt,scope:X()})}const he=Object.freeze(Object.defineProperty({__proto__:null,ActionSchema:ue,BaseActionSchema:At,DocumentFileSchema:fe,LoadStateActionInputSchema:gt,LoadStateActionSchema:Nt,LoadStateActionStateInputSchema:Mt,Load_StateSchema:vt,OperationSchema:de,OperationScopeSchema:X,PruneActionInputSchema:ht,PruneActionSchema:Pt,PruneSchema:Tt,RedoActionInputSchema:xt,RedoActionSchema:Ft,RedoSchema:kt,SetNameActionInputSchema:yt,SetNameActionSchema:It,SetNameOperationSchema:ge,Set_NameSchema:_t,UndoActionInputSchema:bt,UndoActionSchema:Rt,UndoSchema:Dt,definedNonNullAnySchema:me,isDefinedNonNullAny:Et},Symbol.toStringTag,{value:"Module"}));function xe(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var mt={exports:{}};(function(e,t){const{hasOwnProperty:i}=Object.prototype,n=_();n.configure=_,n.stringify=n,n.default=n,t.stringify=n,t.configure=_,e.exports=n;const a=/[\u0000-\u001f\u0022\u005c\ud800-\udfff]|[\ud800-\udbff](?![\udc00-\udfff])|(?:[^\ud800-\udbff]|^)[\udc00-\udfff]/;function p(s){return s.length<5e3&&!a.test(s)?`"${s}"`:JSON.stringify(s)}function r(s){if(s.length>200)return s.sort();for(let m=1;m<s.length;m++){const y=s[m];let A=m;for(;A!==0&&s[A-1]>y;)s[A]=s[A-1],A--;s[A]=y}return s}const l=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Object.getPrototypeOf(new Int8Array)),Symbol.toStringTag).get;function c(s){return l.call(s)!==void 0&&s.length!==0}function x(s,m,y){s.length<y&&(y=s.length);const A=m===","?"":" ";let V=`"0":${A}${s[0]}`;for(let R=1;R<y;R++)V+=`${m}"${R}":${A}${s[R]}`;return V}function j(s){if(i.call(s,"circularValue")){const m=s.circularValue;if(typeof m=="string")return`"${m}"`;if(m==null)return m;if(m===Error||m===TypeError)return{toString(){throw new TypeError("Converting circular structure to JSON")}};throw new TypeError('The "circularValue" argument must be of type string or the value null or undefined')}return'"[Circular]"'}function z(s,m){let y;if(i.call(s,m)&&(y=s[m],typeof y!="boolean"))throw new TypeError(`The "${m}" argument must be of type boolean`);return y===void 0?!0:y}function g(s,m){let y;if(i.call(s,m)){if(y=s[m],typeof y!="number")throw new TypeError(`The "${m}" argument must be of type number`);if(!Number.isInteger(y))throw new TypeError(`The "${m}" argument must be an integer`);if(y<1)throw new RangeError(`The "${m}" argument must be >= 1`)}return y===void 0?1/0:y}function S(s){return s===1?"1 item":`${s} items`}function I(s){const m=new Set;for(const y of s)(typeof y=="string"||typeof y=="number")&&m.add(String(y));return m}function k(s){if(i.call(s,"strict")){const m=s.strict;if(typeof m!="boolean")throw new TypeError('The "strict" argument must be of type boolean');if(m)return y=>{let A=`Object can not safely be stringified. Received type ${typeof y}`;throw typeof y!="function"&&(A+=` (${y.toString()})`),new Error(A)}}}function _(s){s={...s};const m=k(s);m&&(s.bigint===void 0&&(s.bigint=!1),"circularValue"in s||(s.circularValue=Error));const y=j(s),A=z(s,"bigint"),V=z(s,"deterministic"),R=g(s,"maximumDepth"),v=g(s,"maximumBreadth");function et(M,o,f,b,h,O){let d=o[M];switch(typeof d=="object"&&d!==null&&typeof d.toJSON=="function"&&(d=d.toJSON(M)),d=b.call(o,M,d),typeof d){case"string":return p(d);case"object":{if(d===null)return"null";if(f.indexOf(d)!==-1)return y;let w="",E=",";const T=O;if(Array.isArray(d)){if(d.length===0)return"[]";if(R<f.length+1)return'"[Array]"';f.push(d),h!==""&&(O+=h,w+=`
2
+ ${O}`,E=`,
3
+ ${O}`);const F=Math.min(d.length,v);let J=0;for(;J<F-1;J++){const nt=et(String(J),d,f,b,h,O);w+=nt!==void 0?nt:"null",w+=E}const C=et(String(J),d,f,b,h,O);if(w+=C!==void 0?C:"null",d.length-1>v){const nt=d.length-v-1;w+=`${E}"... ${S(nt)} not stringified"`}return h!==""&&(w+=`
4
+ ${T}`),f.pop(),`[${w}]`}let D=Object.keys(d);const N=D.length;if(N===0)return"{}";if(R<f.length+1)return'"[Object]"';let $="",P="";h!==""&&(O+=h,E=`,
5
+ ${O}`,$=" ");const L=Math.min(N,v);V&&!c(d)&&(D=r(D)),f.push(d);for(let F=0;F<L;F++){const J=D[F],C=et(J,d,f,b,h,O);C!==void 0&&(w+=`${P}${p(J)}:${$}${C}`,P=E)}if(N>v){const F=N-v;w+=`${P}"...":${$}"${S(F)} not stringified"`,P=E}return h!==""&&P.length>1&&(w=`
6
+ ${O}${w}
7
+ ${T}`),f.pop(),`{${w}}`}case"number":return isFinite(d)?String(d):m?m(d):"null";case"boolean":return d===!0?"true":"false";case"undefined":return;case"bigint":if(A)return String(d);default:return m?m(d):void 0}}function it(M,o,f,b,h,O){switch(typeof o=="object"&&o!==null&&typeof o.toJSON=="function"&&(o=o.toJSON(M)),typeof o){case"string":return p(o);case"object":{if(o===null)return"null";if(f.indexOf(o)!==-1)return y;const d=O;let w="",E=",";if(Array.isArray(o)){if(o.length===0)return"[]";if(R<f.length+1)return'"[Array]"';f.push(o),h!==""&&(O+=h,w+=`
8
+ ${O}`,E=`,
9
+ ${O}`);const N=Math.min(o.length,v);let $=0;for(;$<N-1;$++){const L=it(String($),o[$],f,b,h,O);w+=L!==void 0?L:"null",w+=E}const P=it(String($),o[$],f,b,h,O);if(w+=P!==void 0?P:"null",o.length-1>v){const L=o.length-v-1;w+=`${E}"... ${S(L)} not stringified"`}return h!==""&&(w+=`
10
+ ${d}`),f.pop(),`[${w}]`}f.push(o);let T="";h!==""&&(O+=h,E=`,
11
+ ${O}`,T=" ");let D="";for(const N of b){const $=it(N,o[N],f,b,h,O);$!==void 0&&(w+=`${D}${p(N)}:${T}${$}`,D=E)}return h!==""&&D.length>1&&(w=`
12
+ ${O}${w}
13
+ ${d}`),f.pop(),`{${w}}`}case"number":return isFinite(o)?String(o):m?m(o):"null";case"boolean":return o===!0?"true":"false";case"undefined":return;case"bigint":if(A)return String(o);default:return m?m(o):void 0}}function W(M,o,f,b,h){switch(typeof o){case"string":return p(o);case"object":{if(o===null)return"null";if(typeof o.toJSON=="function"){if(o=o.toJSON(M),typeof o!="object")return W(M,o,f,b,h);if(o===null)return"null"}if(f.indexOf(o)!==-1)return y;const O=h;if(Array.isArray(o)){if(o.length===0)return"[]";if(R<f.length+1)return'"[Array]"';f.push(o),h+=b;let $=`
14
+ ${h}`;const P=`,
15
+ ${h}`,L=Math.min(o.length,v);let F=0;for(;F<L-1;F++){const C=W(String(F),o[F],f,b,h);$+=C!==void 0?C:"null",$+=P}const J=W(String(F),o[F],f,b,h);if($+=J!==void 0?J:"null",o.length-1>v){const C=o.length-v-1;$+=`${P}"... ${S(C)} not stringified"`}return $+=`
16
+ ${O}`,f.pop(),`[${$}]`}let d=Object.keys(o);const w=d.length;if(w===0)return"{}";if(R<f.length+1)return'"[Object]"';h+=b;const E=`,
17
+ ${h}`;let T="",D="",N=Math.min(w,v);c(o)&&(T+=x(o,E,v),d=d.slice(o.length),N-=o.length,D=E),V&&(d=r(d)),f.push(o);for(let $=0;$<N;$++){const P=d[$],L=W(P,o[P],f,b,h);L!==void 0&&(T+=`${D}${p(P)}: ${L}`,D=E)}if(w>v){const $=w-v;T+=`${D}"...": "${S($)} not stringified"`,D=E}return D!==""&&(T=`
18
+ ${h}${T}
19
+ ${O}`),f.pop(),`{${T}}`}case"number":return isFinite(o)?String(o):m?m(o):"null";case"boolean":return o===!0?"true":"false";case"undefined":return;case"bigint":if(A)return String(o);default:return m?m(o):void 0}}function Z(M,o,f){switch(typeof o){case"string":return p(o);case"object":{if(o===null)return"null";if(typeof o.toJSON=="function"){if(o=o.toJSON(M),typeof o!="object")return Z(M,o,f);if(o===null)return"null"}if(f.indexOf(o)!==-1)return y;let b="";if(Array.isArray(o)){if(o.length===0)return"[]";if(R<f.length+1)return'"[Array]"';f.push(o);const E=Math.min(o.length,v);let T=0;for(;T<E-1;T++){const N=Z(String(T),o[T],f);b+=N!==void 0?N:"null",b+=","}const D=Z(String(T),o[T],f);if(b+=D!==void 0?D:"null",o.length-1>v){const N=o.length-v-1;b+=`,"... ${S(N)} not stringified"`}return f.pop(),`[${b}]`}let h=Object.keys(o);const O=h.length;if(O===0)return"{}";if(R<f.length+1)return'"[Object]"';let d="",w=Math.min(O,v);c(o)&&(b+=x(o,",",v),h=h.slice(o.length),w-=o.length,d=","),V&&(h=r(h)),f.push(o);for(let E=0;E<w;E++){const T=h[E],D=Z(T,o[T],f);D!==void 0&&(b+=`${d}${p(T)}:${D}`,d=",")}if(O>v){const E=O-v;b+=`${d}"...":"${S(E)} not stringified"`}return f.pop(),`{${b}}`}case"number":return isFinite(o)?String(o):m?m(o):"null";case"boolean":return o===!0?"true":"false";case"undefined":return;case"bigint":if(A)return String(o);default:return m?m(o):void 0}}function re(M,o,f){if(arguments.length>1){let b="";if(typeof f=="number"?b=" ".repeat(Math.min(f,10)):typeof f=="string"&&(b=f.slice(0,10)),o!=null){if(typeof o=="function")return et("",{"":M},[],o,b,"");if(Array.isArray(o))return it("",M,[],I(o),b,"")}if(b.length!==0)return W("",M,[],b,"")}return Z("",M,[])}return re}})(mt,mt.exports);var ye=mt.exports;const rt=xe(ye);rt.configure;function be(e,t){return{...e,name:t}}function we(e,t,i){const n={skip:i,document:e},{scope:a}=t;return!a||t.skip===void 0?n:U.produce(n,p=>{const[r]=p.document.operations[a].slice(-1);t.skip&&t.skip>0&&(p.skip=t.skip),r.type==="NOOP"&&t.index===r.index&&p.skip>r.skip&&p.document.operations[a].pop()})}function je(e,t,i){const{scope:n,input:a}=t,p={document:e,action:t,skip:i};return U.produce(p,r=>{if(r.document.operations[n].length<1)throw new Error(`Cannot undo: no operations in history for scope "${n}"`);if(a<1)throw new Error("Invalid UNDO action: input value must be greater than 0");if(r.skip>0)throw new Error("Cannot undo: skip value from reducer cannot be used with UNDO action");const[l]=r.document.operations[n].slice(-1),c=l.type==="NOOP"&&l.skip>0;if(r.skip+=a,c){r.skip+=l.skip;const g=r.document.operations[n][r.document.operations[n].length-2];g&&l.index-g.index===1&&r.document.operations[n].pop()}if(r.document.operations[n].length<r.skip)throw new Error("Cannot undo: you can't undo more operations than the ones in the scope history");const x=r.document.operations[n].length-1;let j=a,z=c?x-l.skip:x;for(;j>0&&z>=0;){const g=r.document.operations[n][z];if(!g){j--,z--;continue}g.type==="NOOP"&&g.skip>0?(z=z-(g.skip+1),r.skip+=g.skip+1):(r.document.clipboard.push({...g}),j--,z--)}r.action=St(n)})}function Oe(e,t,i){const{scope:n,input:a}=t,p={document:e,action:t,skip:i};return U.produce(p,r=>{if(r.skip>0)throw new Error("Cannot redo: skip value from reducer cannot be used with REDO action");if(a>1)throw new Error("Cannot redo: you can only redo one operation at a time");if(a<1)throw new Error("Invalid REDO action: invalid redo input value");if(r.document.clipboard.length<1)throw new Error("Cannot redo: no operations in the clipboard");const l=r.document.clipboard.findLastIndex(x=>x.scope===n);if(l<0)throw new Error(`Cannot redo: no operations in clipboard for scope "${n}"`);const c=r.document.clipboard.splice(l,1)[0];r.action=U.castDraft({type:c.type,scope:c.scope,input:c.input})})}function Se(e,t,i){const{scope:n}=t,a=e.operations[n];let{input:{start:p,end:r}}=t;p=p||0,r=r||a.length;const l=a.slice(p,r),c=a.slice(0,p),x=a.slice(r),j=st(e.initialState,{...e.operations,[n]:c.concat(l)},i),{name:z,state:g}=j,S=c.length,I=c.length?c[c.length-1].timestamp:x.length?x[0].timestamp:new Date().toISOString();return st(e.initialState,{...e.operations,[n]:[...c,{...Ot({name:z,state:g},l.length),timestamp:I,index:S,hash:ct({state:g},"global")},...x.map((k,_)=>({...k,index:S+_+1}))]},i)}function $e(e,t){return{...e,name:t.name,state:t.state??{global:{},local:{}}}}const qt="SET_NAME",Y="UNDO",tt="REDO",at="PRUNE",Lt="LOAD_STATE",ze="NOOP";function Ee(e,t){let i;return"index"in t?i={...t}:i=e.operations[t.scope].slice(-1)[0],((i==null?void 0:i.index)??-1)+1}function ve(e,t){return{...e,revision:{...e.revision,[t.scope]:Ee(e,t)},lastModified:new Date().toISOString()}}function Te(e,t,i=0){if([Y,tt,at].includes(t.type))return e;const{scope:n}=t,a=e.operations[n].slice(0,e.revision[n]),p=[...a].pop();let r=((p==null?void 0:p.index)??-1)+1;if("index"in t){if(t.index>r+i)throw new Error(`Missing operations: expected ${r} with skip 0 or equivalent, got index ${t.index} with skip ${i}`);r=t.index}return a.push({...t,index:r,timestamp:new Date().toISOString(),hash:"",scope:n,skip:i}),{...e,operations:{...e.operations,[n]:a}}}function ke(e,t,i=0){let n=Te(e,t,i);return n=ve(n,t),n}function _e(e,t,i){switch(At().parse(t),t.type){case qt:return be(e,t.input);case at:return Se(e,t,i);case Lt:return $e(e,t.input.state);default:return e}}function Jt(e,t,i){switch(t.type){case Y:return je(e,t,i);case tt:return Oe(e,t,i);default:return{document:e,action:t,skip:i}}}function wt(e,t,i,n,a={}){const{skip:p,ignoreSkipOperations:r=!1,reuseHash:l=!1}=a;let c={...t},x=p||0,j=e,z=[...e.clipboard];if(Ut(c)){const{document:g,skip:S}=we(j,c,x);x=S,j=g}if(ut(c)){const{skip:g,action:S,document:I}=Jt(e,c,x);c=S,x=g,j=I,z=[...j.clipboard]}if(ft(c)&&(j=_e(j,c,i)),x>0&&!r){let g=x;"index"in c&&(g=Wt(j.operations[c.scope],c.index,x)),j=st(j.initialState,j.operations,i,void 0,void 0,void 0,{[c.scope]:g})}return j=ke(j,c,x),j=U.produce(j,g=>{const S=i(g.state,c,n),I=ut(t)?[...z]:[];if(S)return U.castDraft({...j,clipboard:[...I],state:S});g.clipboard=U.castDraft([...I])}),U.produce(j,g=>{if([Y,tt,at].includes(c.type))return g;const S=c.scope||"global",I=l&&Object.prototype.hasOwnProperty.call(c,"hash")?c.hash:ct(g,S);g.operations[S][g.operations[S].length-1].hash=I,!ft(c)&&c.attachments&&c.attachments.forEach(k=>{const{hash:_,...s}=k;g.attachments[_]={...s}})})}function De(e,t,i){const n=le.join(e,t);return lt.mkdirSync(e,{recursive:!0}),new Promise((a,p)=>{try{lt.writeFile(n,i,{},r=>{r?p(r):a(n)})}catch(r){p(r)}})}function Ct(e){return lt.readFileSync(e)}function Ae(e){return new Promise((t,i)=>{ce.get(e,n=>{const a=[],p=n.headers["content-type"];n.on("data",r=>{a.push(r)}),n.on("end",()=>{t({buffer:Buffer.concat(a),mimeType:p})})}).on("error",n=>{i(n)})})}const Ne=async e=>Ct(e),pt=(e,t="sha1")=>pe.createHash(t).update(e).digest("base64");function Ut(e){return e.type===ze&&e.skip!==void 0&&e.skip>0&&e.hash!==void 0}function ut(e){return[Y,tt].includes(e.type)}function ft(e){return[qt,Y,tt,at,Lt].includes(e.type)}function B(e,t,i,n,a="global"){if(!e)throw new Error("Empty action type");if(typeof e!="string")throw new Error(`Invalid action type: ${JSON.stringify(e)}`);const p={type:e,input:t,scope:a};i&&(p.attachments=i);try{n==null||n().parse(p.input)}catch(r){throw new Error(`Invalid action input: ${r}`)}return p}function Vt(e,t=wt){return(i,n,a,p)=>t(i,n,e,a,p)}const Kt=(e,t)=>({name:"",documentType:"",revision:{global:0,local:0},created:new Date().toISOString(),lastModified:new Date().toISOString(),attachments:{},...e,state:(t==null?void 0:t(e==null?void 0:e.state))??(e==null?void 0:e.state)??{global:{},local:{}}}),Bt=(e,t)=>{const i=Kt(e,t);return{...i,initialState:i,operations:{global:[],local:[]},clipboard:[]}},ct=(e,t="global")=>pt(rt(e.state[t]||"")),Me=(e,t=1e3)=>{const i=Math.random()*t;return pt(`${(e??new Date).toISOString()}${i}`)};function G(e){return U.castImmutable(U.freeze(e,!0))}function Ht(e,t){const i=[...e];let n=t||0,a=i.length>0?i[i.length-1].index:0;const p=[];for(const r of i.reverse()){if(n>0){const x=a-r.index;n-=x}if(n<0)throw new Error("Invalid operation index, missing operations");const l={ignore:n>0,operation:r},c=r.skip>0?r.skip+1:0;if(c>0&&c>n){const x=c-n;n=n+x}a=r.index,p.push(l)}return p.reverse()}function Wt(e,t,i){const n=e.slice().sort((l,c)=>l.skip-c.skip).sort((l,c)=>l.index-c.index);let a=i,p=0,r=t;for(const l of n.reverse()){const c=r-l.index;if(a=a-c,a>-1)p++,r=l.index;else break}return p}function Pe(e){return Object.values(e).flatMap(t=>t).sort((t,i)=>new Date(t.timestamp).getTime()-new Date(i.timestamp).getTime())}function Zt(e){return Object.values(e).flatMap(t=>t).sort((t,i)=>new Date(t.operation.timestamp).getTime()-new Date(i.operation.timestamp).getTime())}function st(e,t,i,n,a,p=wt,r={},l){const c=Vt(i,p);return jt(e,t,c,n,a,r,l)}function jt(e,t,i,n,a,p={},r){const l=(r==null?void 0:r.checkHashes)??!0,c=Bt(e),x=Object.keys(t).reduce((k,_)=>{const s=_;return{...k,[s]:t[s].slice(0,a==null?void 0:a.revision[s])}},{}),j=Object.keys(x).reduce((k,_)=>{const s=_;return{...k,[s]:Ht(x[s],p[s])}},{}),z=Zt(j),g=z.reduce((k,{ignore:_,operation:s},m,y)=>_?i(k,St(s.scope),n,{skip:s.skip,ignoreSkipOperations:!0}):i(k,s,n,{skip:s.skip,ignoreSkipOperations:!0,reuseHash:!l}),c);if(!l){for(const k of Object.keys(g.state))for(let _=z.length-1;_>=0;_--)if(z[_].operation.scope===k){if(z[_].operation.hash!==ct(g,k))throw new Error(`Hash mismatch for scope ${k}`);break}}const S=Object.keys(g.operations).reduce((k,_)=>{const s=_,m=a&&a.revision[s]<t[s].length?t[s].slice(a.revision[s]):[];return{...k,[s]:[...g.operations[s].map((y,A)=>{var V;return{...y,timestamp:((V=t[s][A])==null?void 0:V.timestamp)??y.timestamp}}),...m]}},{global:[],local:[]}),I=Object.values(S).reduce((k,_)=>{for(const s of _)s.timestamp>k&&(k=s.timestamp);return k},e.lastModified);return{...g,operations:S,lastModified:I}}function Fe(e,t){return rt(e)===rt(t)}const Gt=e=>B("SET_NAME",e,void 0,yt,void 0),Qt=(e=1,t="global")=>B("UNDO",e,void 0,bt,t),Xt=(e=1,t="global")=>B("REDO",e,void 0,xt,t),Yt=(e,t,i="global")=>B("PRUNE",{start:e,end:t},void 0,ht,i),Ot=(e,t)=>B("LOAD_STATE",{state:e,operations:t},void 0,gt),St=(e="global")=>B("NOOP",{},void 0,void 0,e),Ie=Object.freeze(Object.defineProperty({__proto__:null,loadState:Ot,noop:St,prune:Yt,redo:Xt,setName:Gt,undo:Qt},Symbol.toStringTag,{value:"Module"})),te={"application/andrew-inset":["ez"],"application/appinstaller":["appinstaller"],"application/applixware":["aw"],"application/appx":["appx"],"application/appxbundle":["appxbundle"],"application/atom+xml":["atom"],"application/atomcat+xml":["atomcat"],"application/atomdeleted+xml":["atomdeleted"],"application/atomsvc+xml":["atomsvc"],"application/atsc-dwd+xml":["dwd"],"application/atsc-held+xml":["held"],"application/atsc-rsat+xml":["rsat"],"application/automationml-aml+xml":["aml"],"application/automationml-amlx+zip":["amlx"],"application/bdoc":["bdoc"],"application/calendar+xml":["xcs"],"application/ccxml+xml":["ccxml"],"application/cdfx+xml":["cdfx"],"application/cdmi-capability":["cdmia"],"application/cdmi-container":["cdmic"],"application/cdmi-domain":["cdmid"],"application/cdmi-object":["cdmio"],"application/cdmi-queue":["cdmiq"],"application/cpl+xml":["cpl"],"application/cu-seeme":["cu"],"application/cwl":["cwl"],"application/dash+xml":["mpd"],"application/dash-patch+xml":["mpp"],"application/davmount+xml":["davmount"],"application/docbook+xml":["dbk"],"application/dssc+der":["dssc"],"application/dssc+xml":["xdssc"],"application/ecmascript":["ecma"],"application/emma+xml":["emma"],"application/emotionml+xml":["emotionml"],"application/epub+zip":["epub"],"application/exi":["exi"],"application/express":["exp"],"application/fdf":["fdf"],"application/fdt+xml":["fdt"],"application/font-tdpfr":["pfr"],"application/geo+json":["geojson"],"application/gml+xml":["gml"],"application/gpx+xml":["gpx"],"application/gxf":["gxf"],"application/gzip":["gz"],"application/hjson":["hjson"],"application/hyperstudio":["stk"],"application/inkml+xml":["ink","inkml"],"application/ipfix":["ipfix"],"application/its+xml":["its"],"application/java-archive":["jar","war","ear"],"application/java-serialized-object":["ser"],"application/java-vm":["class"],"application/javascript":["*js"],"application/json":["json","map"],"application/json5":["json5"],"application/jsonml+json":["jsonml"],"application/ld+json":["jsonld"],"application/lgr+xml":["lgr"],"application/lost+xml":["lostxml"],"application/mac-binhex40":["hqx"],"application/mac-compactpro":["cpt"],"application/mads+xml":["mads"],"application/manifest+json":["webmanifest"],"application/marc":["mrc"],"application/marcxml+xml":["mrcx"],"application/mathematica":["ma","nb","mb"],"application/mathml+xml":["mathml"],"application/mbox":["mbox"],"application/media-policy-dataset+xml":["mpf"],"application/mediaservercontrol+xml":["mscml"],"application/metalink+xml":["metalink"],"application/metalink4+xml":["meta4"],"application/mets+xml":["mets"],"application/mmt-aei+xml":["maei"],"application/mmt-usd+xml":["musd"],"application/mods+xml":["mods"],"application/mp21":["m21","mp21"],"application/mp4":["*mp4","*mpg4","mp4s","m4p"],"application/msix":["msix"],"application/msixbundle":["msixbundle"],"application/msword":["doc","dot"],"application/mxf":["mxf"],"application/n-quads":["nq"],"application/n-triples":["nt"],"application/node":["cjs"],"application/octet-stream":["bin","dms","lrf","mar","so","dist","distz","pkg","bpk","dump","elc","deploy","exe","dll","deb","dmg","iso","img","msi","msp","msm","buffer"],"application/oda":["oda"],"application/oebps-package+xml":["opf"],"application/ogg":["ogx"],"application/omdoc+xml":["omdoc"],"application/onenote":["onetoc","onetoc2","onetmp","onepkg"],"application/oxps":["oxps"],"application/p2p-overlay+xml":["relo"],"application/patch-ops-error+xml":["xer"],"application/pdf":["pdf"],"application/pgp-encrypted":["pgp"],"application/pgp-keys":["asc"],"application/pgp-signature":["sig","*asc"],"application/pics-rules":["prf"],"application/pkcs10":["p10"],"application/pkcs7-mime":["p7m","p7c"],"application/pkcs7-signature":["p7s"],"application/pkcs8":["p8"],"application/pkix-attr-cert":["ac"],"application/pkix-cert":["cer"],"application/pkix-crl":["crl"],"application/pkix-pkipath":["pkipath"],"application/pkixcmp":["pki"],"application/pls+xml":["pls"],"application/postscript":["ai","eps","ps"],"application/provenance+xml":["provx"],"application/pskc+xml":["pskcxml"],"application/raml+yaml":["raml"],"application/rdf+xml":["rdf","owl"],"application/reginfo+xml":["rif"],"application/relax-ng-compact-syntax":["rnc"],"application/resource-lists+xml":["rl"],"application/resource-lists-diff+xml":["rld"],"application/rls-services+xml":["rs"],"application/route-apd+xml":["rapd"],"application/route-s-tsid+xml":["sls"],"application/route-usd+xml":["rusd"],"application/rpki-ghostbusters":["gbr"],"application/rpki-manifest":["mft"],"application/rpki-roa":["roa"],"application/rsd+xml":["rsd"],"application/rss+xml":["rss"],"application/rtf":["rtf"],"application/sbml+xml":["sbml"],"application/scvp-cv-request":["scq"],"application/scvp-cv-response":["scs"],"application/scvp-vp-request":["spq"],"application/scvp-vp-response":["spp"],"application/sdp":["sdp"],"application/senml+xml":["senmlx"],"application/sensml+xml":["sensmlx"],"application/set-payment-initiation":["setpay"],"application/set-registration-initiation":["setreg"],"application/shf+xml":["shf"],"application/sieve":["siv","sieve"],"application/smil+xml":["smi","smil"],"application/sparql-query":["rq"],"application/sparql-results+xml":["srx"],"application/sql":["sql"],"application/srgs":["gram"],"application/srgs+xml":["grxml"],"application/sru+xml":["sru"],"application/ssdl+xml":["ssdl"],"application/ssml+xml":["ssml"],"application/swid+xml":["swidtag"],"application/tei+xml":["tei","teicorpus"],"application/thraud+xml":["tfi"],"application/timestamped-data":["tsd"],"application/toml":["toml"],"application/trig":["trig"],"application/ttml+xml":["ttml"],"application/ubjson":["ubj"],"application/urc-ressheet+xml":["rsheet"],"application/urc-targetdesc+xml":["td"],"application/voicexml+xml":["vxml"],"application/wasm":["wasm"],"application/watcherinfo+xml":["wif"],"application/widget":["wgt"],"application/winhlp":["hlp"],"application/wsdl+xml":["wsdl"],"application/wspolicy+xml":["wspolicy"],"application/xaml+xml":["xaml"],"application/xcap-att+xml":["xav"],"application/xcap-caps+xml":["xca"],"application/xcap-diff+xml":["xdf"],"application/xcap-el+xml":["xel"],"application/xcap-ns+xml":["xns"],"application/xenc+xml":["xenc"],"application/xfdf":["xfdf"],"application/xhtml+xml":["xhtml","xht"],"application/xliff+xml":["xlf"],"application/xml":["xml","xsl","xsd","rng"],"application/xml-dtd":["dtd"],"application/xop+xml":["xop"],"application/xproc+xml":["xpl"],"application/xslt+xml":["*xsl","xslt"],"application/xspf+xml":["xspf"],"application/xv+xml":["mxml","xhvml","xvml","xvm"],"application/yang":["yang"],"application/yin+xml":["yin"],"application/zip":["zip"],"audio/3gpp":["*3gpp"],"audio/aac":["adts","aac"],"audio/adpcm":["adp"],"audio/amr":["amr"],"audio/basic":["au","snd"],"audio/midi":["mid","midi","kar","rmi"],"audio/mobile-xmf":["mxmf"],"audio/mp3":["*mp3"],"audio/mp4":["m4a","mp4a"],"audio/mpeg":["mpga","mp2","mp2a","mp3","m2a","m3a"],"audio/ogg":["oga","ogg","spx","opus"],"audio/s3m":["s3m"],"audio/silk":["sil"],"audio/wav":["wav"],"audio/wave":["*wav"],"audio/webm":["weba"],"audio/xm":["xm"],"font/collection":["ttc"],"font/otf":["otf"],"font/ttf":["ttf"],"font/woff":["woff"],"font/woff2":["woff2"],"image/aces":["exr"],"image/apng":["apng"],"image/avci":["avci"],"image/avcs":["avcs"],"image/avif":["avif"],"image/bmp":["bmp","dib"],"image/cgm":["cgm"],"image/dicom-rle":["drle"],"image/dpx":["dpx"],"image/emf":["emf"],"image/fits":["fits"],"image/g3fax":["g3"],"image/gif":["gif"],"image/heic":["heic"],"image/heic-sequence":["heics"],"image/heif":["heif"],"image/heif-sequence":["heifs"],"image/hej2k":["hej2"],"image/hsj2":["hsj2"],"image/ief":["ief"],"image/jls":["jls"],"image/jp2":["jp2","jpg2"],"image/jpeg":["jpeg","jpg","jpe"],"image/jph":["jph"],"image/jphc":["jhc"],"image/jpm":["jpm","jpgm"],"image/jpx":["jpx","jpf"],"image/jxr":["jxr"],"image/jxra":["jxra"],"image/jxrs":["jxrs"],"image/jxs":["jxs"],"image/jxsc":["jxsc"],"image/jxsi":["jxsi"],"image/jxss":["jxss"],"image/ktx":["ktx"],"image/ktx2":["ktx2"],"image/png":["png"],"image/sgi":["sgi"],"image/svg+xml":["svg","svgz"],"image/t38":["t38"],"image/tiff":["tif","tiff"],"image/tiff-fx":["tfx"],"image/webp":["webp"],"image/wmf":["wmf"],"message/disposition-notification":["disposition-notification"],"message/global":["u8msg"],"message/global-delivery-status":["u8dsn"],"message/global-disposition-notification":["u8mdn"],"message/global-headers":["u8hdr"],"message/rfc822":["eml","mime"],"model/3mf":["3mf"],"model/gltf+json":["gltf"],"model/gltf-binary":["glb"],"model/iges":["igs","iges"],"model/jt":["jt"],"model/mesh":["msh","mesh","silo"],"model/mtl":["mtl"],"model/obj":["obj"],"model/prc":["prc"],"model/step+xml":["stpx"],"model/step+zip":["stpz"],"model/step-xml+zip":["stpxz"],"model/stl":["stl"],"model/u3d":["u3d"],"model/vrml":["wrl","vrml"],"model/x3d+binary":["*x3db","x3dbz"],"model/x3d+fastinfoset":["x3db"],"model/x3d+vrml":["*x3dv","x3dvz"],"model/x3d+xml":["x3d","x3dz"],"model/x3d-vrml":["x3dv"],"text/cache-manifest":["appcache","manifest"],"text/calendar":["ics","ifb"],"text/coffeescript":["coffee","litcoffee"],"text/css":["css"],"text/csv":["csv"],"text/html":["html","htm","shtml"],"text/jade":["jade"],"text/javascript":["js","mjs"],"text/jsx":["jsx"],"text/less":["less"],"text/markdown":["md","markdown"],"text/mathml":["mml"],"text/mdx":["mdx"],"text/n3":["n3"],"text/plain":["txt","text","conf","def","list","log","in","ini"],"text/richtext":["rtx"],"text/rtf":["*rtf"],"text/sgml":["sgml","sgm"],"text/shex":["shex"],"text/slim":["slim","slm"],"text/spdx":["spdx"],"text/stylus":["stylus","styl"],"text/tab-separated-values":["tsv"],"text/troff":["t","tr","roff","man","me","ms"],"text/turtle":["ttl"],"text/uri-list":["uri","uris","urls"],"text/vcard":["vcard"],"text/vtt":["vtt"],"text/wgsl":["wgsl"],"text/xml":["*xml"],"text/yaml":["yaml","yml"],"video/3gpp":["3gp","3gpp"],"video/3gpp2":["3g2"],"video/h261":["h261"],"video/h263":["h263"],"video/h264":["h264"],"video/iso.segment":["m4s"],"video/jpeg":["jpgv"],"video/jpm":["*jpm","*jpgm"],"video/mj2":["mj2","mjp2"],"video/mp2t":["ts"],"video/mp4":["mp4","mp4v","mpg4"],"video/mpeg":["mpeg","mpg","mpe","m1v","m2v"],"video/ogg":["ogv"],"video/quicktime":["qt","mov"],"video/webm":["webm"]};Object.freeze(te);var q=function(e,t,i,n){if(i==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?e!==t||!n:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return i==="m"?n:i==="a"?n.call(e):n?n.value:t.get(e)},H,Q,K;class Re{constructor(...t){H.set(this,new Map),Q.set(this,new Map),K.set(this,new Map);for(const i of t)this.define(i)}define(t,i=!1){for(let[n,a]of Object.entries(t)){n=n.toLowerCase(),a=a.map(l=>l.toLowerCase()),q(this,K,"f").has(n)||q(this,K,"f").set(n,new Set);const p=q(this,K,"f").get(n);let r=!0;for(let l of a){const c=l.startsWith("*");if(l=c?l.slice(1):l,p==null||p.add(l),r&&q(this,Q,"f").set(n,l),r=!1,c)continue;const x=q(this,H,"f").get(l);if(x&&x!=n&&!i)throw new Error(`"${n} -> ${l}" conflicts with "${x} -> ${l}". Pass \`force=true\` to override this definition.`);q(this,H,"f").set(l,n)}}return this}getType(t){if(typeof t!="string")return null;const i=t.replace(/^.*[/\\]/,"").toLowerCase(),n=i.replace(/^.*\./,"").toLowerCase(),a=i.length<t.length;return!(n.length<i.length-1)&&a?null:q(this,H,"f").get(n)??null}getExtension(t){var i;return typeof t!="string"?null:(t=(i=t==null?void 0:t.split)==null?void 0:i.call(t,";")[0],(t&&q(this,Q,"f").get(t.trim().toLowerCase()))??null)}getAllExtensions(t){return typeof t!="string"?null:q(this,K,"f").get(t.toLowerCase())??null}_freeze(){this.define=()=>{throw new Error("define() not allowed for built-in Mime objects. See https://github.com/broofa/mime/blob/main/README.md#custom-mime-instances")},Object.freeze(this);for(const t of q(this,K,"f").values())Object.freeze(t);return this}_getTestState(){return{types:q(this,H,"f"),extensions:q(this,Q,"f")}}}H=new WeakMap,Q=new WeakMap,K=new WeakMap;const qe=new Re(te)._freeze();function ee(e){const t=[],i=Object.keys(e);for(const n of i){const a=e[n].sort((p,r)=>p.index-r.index);for(let p=0;p<a.length;p++)a[p].index!==p&&t.push({message:`Invalid operation index ${a[p].index} at position ${p}`,details:{position:p,operation:a[p],scope:a[p].scope}})}return t}const $t=async e=>{const t=new zt,{name:i,revision:n,documentType:a,created:p,lastModified:r}=e,l={name:i,revision:n,documentType:a,created:p,lastModified:r};return t.file("header.json",JSON.stringify(l,null,2)),t.file("state.json",JSON.stringify(e.initialState||{},null,2)),t.file("operations.json",JSON.stringify(e.operations,null,2)),Object.keys(e.attachments).forEach(x=>{const{data:j,...z}=e.attachments[x];t.file(x,j,{base64:!0,createFolders:!0,comment:JSON.stringify(z)})}),t},ie=async(e,t,i,n)=>{const p=await(await $t(e)).generateAsync({type:"uint8array",streamFiles:!0}),r=n??e.name,l=`.${i}.zip`;return De(t,r.endsWith(l)?r:`${r}${l}`,p)},Le=async(e,t)=>{const n=await(await $t(e)).generateAsync({type:"blob"}),a=await t.createWritable();await a.write(n),await a.close()},dt=async(e,t,i)=>{const n=Ct(e);return ne(n,t,i)},ne=async(e,t,i)=>{const n=new zt;return await n.loadAsync(e),Je(n,t,i)};async function Je(e,t,i){const n=e.file("state.json");if(!n)throw new Error("Initial state not found");const a=await n.async("string"),p=JSON.parse(a),r=e.file("header.json");let l;r&&(l=JSON.parse(await r.async("string")));const c=e.file("operations.json");if(!c)throw new Error("Operations history not found");const x=JSON.parse(await c.async("string")),j=ee(x);if(j.length){const g=j.map(S=>S.message);throw new Error(g.join(`
20
+ `))}let z=jt(p,x,t,void 0,l,{},i);return l&&(z={...z,...l}),z}function oe(e){const t=e.replace(/^.*\./,"")||void 0,i=e.replace(/^.*[/\\]/,"")||void 0;return{extension:t,fileName:i}}async function Ce(e){const{buffer:t,mimeType:i="application/octet-stream"}=await Ae(e),n=oe(e),a=t.toString("base64");return{data:a,hash:pt(a),mimeType:i,...n}}async function Ue(e){const t=await Ne(e),i=qe.getType(e)||"application/octet-stream",n=oe(e),a=t.toString("base64");return{data:a,hash:pt(a),mimeType:i,...n}}class Ve{constructor(t,i,n){ot(this,"_document");ot(this,"_reducer");ot(this,"_signalDispatch");this._reducer=t,this._document=i,this._signalDispatch=n}dispatch(t,i){return this._document=this._reducer(this._document,t,this._signalDispatch,i),this}saveToFile(t,i,n){return ie(this._document,t,i,n)}async loadFromFile(t){this._document=await dt(t,this._reducer)}static async stateFromFile(t,i){return await dt(t,i)}get state(){return G(this._document.state)}get operations(){return G(this._document.operations)}get name(){return this._document.name}get documentType(){return this._document.documentType}get created(){return this._document.created}get lastModified(){return this._document.lastModified}get revision(){return this._document.revision.global}getRevision(t){return this._document.revision[t]}get initialState(){return G(this._document.initialState)}toDocument(){return G(this._document)}getAttachment(t){return this._document.attachments[t]}setName(t){return this.dispatch(Gt(t)),this}undo(t){return this.dispatch(Qt(t)),this}redo(t){return this.dispatch(Xt(t)),this}prune(t,i){return this.dispatch(Yt(t,i)),this}loadState(t,i){return this.dispatch(Ot(t,i)),this}}function Ke(e,t){t.forEach(i=>{Object.getOwnPropertyNames(i.prototype).forEach(n=>{Object.defineProperty(e.prototype,n,Object.getOwnPropertyDescriptor(i.prototype,n)||Object.create(null))})})}exports.BaseActions=Ie;exports.BaseDocument=Ve;exports.applyMixins=Ke;exports.baseReducer=wt;exports.calculateSkipsLeft=Wt;exports.createAction=B;exports.createDocument=Bt;exports.createExtendedState=Kt;exports.createReducer=Vt;exports.createZip=$t;exports.getLocalFile=Ue;exports.getRemoteFile=Ce;exports.hashDocument=ct;exports.hashKey=Me;exports.isBaseAction=ft;exports.isNoopOperation=Ut;exports.isSameDocument=Fe;exports.isUndoRedo=ut;exports.loadFromFile=dt;exports.loadFromInput=ne;exports.mapSkippedOperations=Ht;exports.processUndoRedo=Jt;exports.readOnly=G;exports.replayDocument=jt;exports.replayOperations=st;exports.saveToFile=ie;exports.saveToFileHandle=Le;exports.sortMappedOperations=Zt;exports.sortOperations=Pe;exports.validateOperations=ee;exports.zod=he;
@@ -50,6 +50,8 @@ export type ReducerOptions = {
50
50
  skip?: number;
51
51
  /** When true the skip count is ignored and the action is applied regardless of the skip count */
52
52
  ignoreSkipOperations?: boolean;
53
+ /** if true reuses the provided action hash */
54
+ reuseHash?: boolean;
53
55
  };
54
56
  /**
55
57
  * A pure function that takes an action and the previous state
@@ -74,7 +74,12 @@ export declare function mapSkippedOperations<A extends Action>(operations: Opera
74
74
  export declare function calculateSkipsLeft<A extends Action>(operations: Operation<BaseAction | A>[], currentIndex: number, skip: number): number;
75
75
  export declare function sortOperations<A extends Action>(operations: DocumentOperations<A>): Operation<BaseAction | A>[];
76
76
  export declare function sortMappedOperations<A extends Action>(operations: DocumentOperationsIgnoreMap<A>): MappedOperation<A>[];
77
- export declare function replayOperations<T, A extends Action, L>(initialState: ExtendedState<T, L>, operations: DocumentOperations<A>, reducer: ImmutableStateReducer<T, A, L>, dispatch?: SignalDispatch, header?: DocumentHeader, documentReducer?: typeof baseReducer, skipHeaderOperations?: SkipHeaderOperations): Document<T, A, L>;
77
+ export declare function replayOperations<T, A extends Action, L>(initialState: ExtendedState<T, L>, operations: DocumentOperations<A>, reducer: ImmutableStateReducer<T, A, L>, dispatch?: SignalDispatch, header?: DocumentHeader, documentReducer?: typeof baseReducer, skipHeaderOperations?: SkipHeaderOperations, options?: {
78
+ checkHashes?: boolean;
79
+ }): Document<T, A, L>;
78
80
  export type SkipHeaderOperations = Partial<Record<OperationScope, number>>;
79
- export declare function replayDocument<T, A extends Action, L>(initialState: ExtendedState<T, L>, operations: DocumentOperations<A>, reducer: Reducer<T, A, L>, dispatch?: SignalDispatch, header?: DocumentHeader, skipHeaderOperations?: SkipHeaderOperations): Document<T, A, L>;
81
+ export type ReplayDocumentOptions = {
82
+ checkHashes?: boolean;
83
+ };
84
+ export declare function replayDocument<T, A extends Action, L>(initialState: ExtendedState<T, L>, operations: DocumentOperations<A>, reducer: Reducer<T, A, L>, dispatch?: SignalDispatch, header?: DocumentHeader, skipHeaderOperations?: SkipHeaderOperations, options?: ReplayDocumentOptions): Document<T, A, L>;
80
85
  export declare function isSameDocument(documentA: Document, documentB: Document): boolean;
@@ -1,5 +1,6 @@
1
1
  import JSZip from 'jszip';
2
2
  import type { Action, AttachmentInput, Document, Reducer } from '../types';
3
+ import { ReplayDocumentOptions } from './base';
3
4
  export type FileInput = string | number[] | Uint8Array | ArrayBuffer | Blob;
4
5
  export declare const createZip: (document: Document) => Promise<JSZip>;
5
6
  /**
@@ -31,8 +32,8 @@ export declare const saveToFileHandle: (document: Document, input: FileSystemFil
31
32
  * @returns A promise that resolves to the document state after applying all the operations.
32
33
  * @throws An error if the initial state or the operations history is not found in the ZIP file.
33
34
  */
34
- export declare const loadFromFile: <S, A extends Action, L>(path: string, reducer: Reducer<S, A, L>) => Promise<Document<S, A, L>>;
35
- export declare const loadFromInput: <S, A extends Action, L>(input: FileInput, reducer: Reducer<S, A, L>) => Promise<Document<S, A, L>>;
35
+ export declare const loadFromFile: <S, A extends Action, L>(path: string, reducer: Reducer<S, A, L>, options?: ReplayDocumentOptions) => Promise<Document<S, A, L>>;
36
+ export declare const loadFromInput: <S, A extends Action, L>(input: FileInput, reducer: Reducer<S, A, L>, options?: ReplayDocumentOptions) => Promise<Document<S, A, L>>;
36
37
  /**
37
38
  * Fetches an attachment from a URL and returns its base64-encoded data and MIME type.
38
39
  * @param url - The URL of the attachment to fetch.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "document-model",
3
- "version": "1.0.43",
3
+ "version": "1.0.45",
4
4
  "license": "AGPL-3.0-only",
5
5
  "private": false,
6
6
  "files": [
@@ -57,7 +57,6 @@
57
57
  "@commitlint/config-conventional": "^18.4.4",
58
58
  "@rollup/plugin-node-resolve": "^15.2.3",
59
59
  "@total-typescript/ts-reset": "^0.5.1",
60
- "@types/jest": "^29.5.11",
61
60
  "@types/mime": "^3.0.4",
62
61
  "@types/node": "^20.11.17",
63
62
  "@types/react": "^18.2.48",
@@ -73,13 +72,11 @@
73
72
  "react": "^18.2.0",
74
73
  "rollup-plugin-polyfill-node": "^0.13.0",
75
74
  "sha.js": "^2.4.11",
76
- "ts-jest": "^29.1.1",
77
- "ts-node": "^10.9.2",
78
75
  "typescript": "^5.3.3",
79
76
  "vite": "^5.0.11",
80
77
  "vite-plugin-dts": "^3.7.1",
81
78
  "vite-plugin-node-polyfills": "^0.19.0",
82
- "vitest": "^1.2.1"
79
+ "vitest": "^1.5.0"
83
80
  },
84
81
  "dependencies": {
85
82
  "change-case": "^5.4.3",
@@ -1,25 +0,0 @@
1
- "use strict";var We=Object.defineProperty;var Ve=(i,r,s)=>r in i?We(i,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):i[r]=s;var St=(i,r,s)=>(Ve(i,typeof r!="symbol"?r+"":r,s),s);const ot=require("immer"),S=require("zod"),ie=require("jszip"),ne=i=>i!=null,Ke=S.z.any().refine(i=>ne(i)),oe=S.z.enum(["LOAD_STATE"]),ae=S.z.enum(["PRUNE"]),se=S.z.enum(["REDO"]),pe=S.z.enum(["SET_NAME"]),ce=S.z.enum(["UNDO"]);function He(){return S.z.object({__typename:S.z.literal("Action").optional(),type:S.z.string()})}function gt(){return S.z.literal("global").or(S.z.literal("local"))}function le(){return S.z.union([ue(),he(),me(),xe(),de()])}function Ze(){return S.z.object({__typename:S.z.literal("DocumentFile").optional(),data:S.z.string(),extension:S.z.string().nullable(),fileName:S.z.string().nullable(),mimeType:S.z.string()})}function ue(){return S.z.object({input:S.z.lazy(()=>Rt()),type:oe,scope:gt()})}function Rt(){return S.z.object({operations:S.z.number(),state:S.z.lazy(()=>fe())})}function fe(){return S.z.object({data:S.z.unknown().nullish(),name:S.z.string()})}function Ge(){return S.z.object({__typename:S.z.literal("Operation").optional(),hash:S.z.string(),index:S.z.number(),timestamp:S.z.string().datetime(),type:S.z.string()})}function he(){return S.z.object({input:S.z.lazy(()=>Lt()),type:ae,scope:gt()})}function Lt(){return S.z.object({end:S.z.number().nullish(),start:S.z.number().nullish()})}const Pt=S.z.number;function me(){return S.z.object({input:Pt(),type:se,scope:gt()})}const qt=S.z.string;function xe(){return S.z.object({input:qt(),type:pe,scope:S.z.literal("global")})}function Ye(){return S.z.object({__typename:S.z.literal("SetNameOperation").optional(),hash:S.z.string(),index:S.z.number(),input:S.z.string(),timestamp:S.z.string().datetime(),type:S.z.string()})}const Jt=S.z.number;function de(){return S.z.object({input:Jt(),type:ce,scope:gt()})}const Xe=Object.freeze(Object.defineProperty({__proto__:null,ActionSchema:He,BaseActionSchema:le,DocumentFileSchema:Ze,LoadStateActionInputSchema:Rt,LoadStateActionSchema:ue,LoadStateActionStateInputSchema:fe,Load_StateSchema:oe,OperationSchema:Ge,OperationScopeSchema:gt,PruneActionInputSchema:Lt,PruneActionSchema:he,PruneSchema:ae,RedoActionInputSchema:Pt,RedoActionSchema:me,RedoSchema:se,SetNameActionInputSchema:qt,SetNameActionSchema:xe,SetNameOperationSchema:Ye,Set_NameSchema:pe,UndoActionInputSchema:Jt,UndoActionSchema:de,UndoSchema:ce,definedNonNullAnySchema:Ke,isDefinedNonNullAny:ne},Symbol.toStringTag,{value:"Module"}));function Wt(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}var Ut={exports:{}};(function(i,r){const{hasOwnProperty:s}=Object.prototype,p=rt();p.configure=rt,p.stringify=p,p.default=p,r.stringify=p,r.configure=rt,i.exports=p;const f=/[\u0000-\u001f\u0022\u005c\ud800-\udfff]|[\ud800-\udbff](?![\udc00-\udfff])|(?:[^\ud800-\udbff]|^)[\udc00-\udfff]/;function u(y){return y.length<5e3&&!f.test(y)?`"${y}"`:JSON.stringify(y)}function l(y){if(y.length>200)return y.sort();for(let E=1;E<y.length;E++){const k=y[E];let q=E;for(;q!==0&&y[q-1]>k;)y[q]=y[q-1],q--;y[q]=k}return y}const a=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Object.getPrototypeOf(new Int8Array)),Symbol.toStringTag).get;function x(y){return a.call(y)!==void 0&&y.length!==0}function g(y,E,k){y.length<k&&(k=y.length);const q=E===","?"":" ";let Z=`"0":${q}${y[0]}`;for(let H=1;H<k;H++)Z+=`${E}"${H}":${q}${y[H]}`;return Z}function A(y){if(s.call(y,"circularValue")){const E=y.circularValue;if(typeof E=="string")return`"${E}"`;if(E==null)return E;if(E===Error||E===TypeError)return{toString(){throw new TypeError("Converting circular structure to JSON")}};throw new TypeError('The "circularValue" argument must be of type string or the value null or undefined')}return'"[Circular]"'}function w(y,E){let k;if(s.call(y,E)&&(k=y[E],typeof k!="boolean"))throw new TypeError(`The "${E}" argument must be of type boolean`);return k===void 0?!0:k}function b(y,E){let k;if(s.call(y,E)){if(k=y[E],typeof k!="number")throw new TypeError(`The "${E}" argument must be of type number`);if(!Number.isInteger(k))throw new TypeError(`The "${E}" argument must be an integer`);if(k<1)throw new RangeError(`The "${E}" argument must be >= 1`)}return k===void 0?1/0:k}function F(y){return y===1?"1 item":`${y} items`}function I(y){const E=new Set;for(const k of y)(typeof k=="string"||typeof k=="number")&&E.add(String(k));return E}function G(y){if(s.call(y,"strict")){const E=y.strict;if(typeof E!="boolean")throw new TypeError('The "strict" argument must be of type boolean');if(E)return k=>{let q=`Object can not safely be stringified. Received type ${typeof k}`;throw typeof k!="function"&&(q+=` (${k.toString()})`),new Error(q)}}}function rt(y){y={...y};const E=G(y);E&&(y.bigint===void 0&&(y.bigint=!1),"circularValue"in y||(y.circularValue=Error));const k=A(y),q=w(y,"bigint"),Z=w(y,"deterministic"),H=b(y,"maximumDepth"),M=b(y,"maximumBreadth");function ut(J,h,v,T,O,$){let _=h[J];switch(typeof _=="object"&&_!==null&&typeof _.toJSON=="function"&&(_=_.toJSON(J)),_=T.call(h,J,_),typeof _){case"string":return u(_);case"object":{if(_===null)return"null";if(v.indexOf(_)!==-1)return k;let D="",B=",";const j=$;if(Array.isArray(_)){if(_.length===0)return"[]";if(H<v.length+1)return'"[Array]"';v.push(_),O!==""&&($+=O,D+=`
2
- ${$}`,B=`,
3
- ${$}`);const W=Math.min(_.length,M);let X=0;for(;X<W-1;X++){const pt=ut(String(X),_,v,T,O,$);D+=pt!==void 0?pt:"null",D+=B}const Q=ut(String(X),_,v,T,O,$);if(D+=Q!==void 0?Q:"null",_.length-1>M){const pt=_.length-M-1;D+=`${B}"... ${F(pt)} not stringified"`}return O!==""&&(D+=`
4
- ${j}`),v.pop(),`[${D}]`}let N=Object.keys(_);const P=N.length;if(P===0)return"{}";if(H<v.length+1)return'"[Object]"';let C="",V="";O!==""&&($+=O,B=`,
5
- ${$}`,C=" ");const Y=Math.min(P,M);Z&&!x(_)&&(N=l(N)),v.push(_);for(let W=0;W<Y;W++){const X=N[W],Q=ut(X,_,v,T,O,$);Q!==void 0&&(D+=`${V}${u(X)}:${C}${Q}`,V=B)}if(P>M){const W=P-M;D+=`${V}"...":${C}"${F(W)} not stringified"`,V=B}return O!==""&&V.length>1&&(D=`
6
- ${$}${D}
7
- ${j}`),v.pop(),`{${D}}`}case"number":return isFinite(_)?String(_):E?E(_):"null";case"boolean":return _===!0?"true":"false";case"undefined":return;case"bigint":if(q)return String(_);default:return E?E(_):void 0}}function ft(J,h,v,T,O,$){switch(typeof h=="object"&&h!==null&&typeof h.toJSON=="function"&&(h=h.toJSON(J)),typeof h){case"string":return u(h);case"object":{if(h===null)return"null";if(v.indexOf(h)!==-1)return k;const _=$;let D="",B=",";if(Array.isArray(h)){if(h.length===0)return"[]";if(H<v.length+1)return'"[Array]"';v.push(h),O!==""&&($+=O,D+=`
8
- ${$}`,B=`,
9
- ${$}`);const P=Math.min(h.length,M);let C=0;for(;C<P-1;C++){const Y=ft(String(C),h[C],v,T,O,$);D+=Y!==void 0?Y:"null",D+=B}const V=ft(String(C),h[C],v,T,O,$);if(D+=V!==void 0?V:"null",h.length-1>M){const Y=h.length-M-1;D+=`${B}"... ${F(Y)} not stringified"`}return O!==""&&(D+=`
10
- ${_}`),v.pop(),`[${D}]`}v.push(h);let j="";O!==""&&($+=O,B=`,
11
- ${$}`,j=" ");let N="";for(const P of T){const C=ft(P,h[P],v,T,O,$);C!==void 0&&(D+=`${N}${u(P)}:${j}${C}`,N=B)}return O!==""&&N.length>1&&(D=`
12
- ${$}${D}
13
- ${_}`),v.pop(),`{${D}}`}case"number":return isFinite(h)?String(h):E?E(h):"null";case"boolean":return h===!0?"true":"false";case"undefined":return;case"bigint":if(q)return String(h);default:return E?E(h):void 0}}function at(J,h,v,T,O){switch(typeof h){case"string":return u(h);case"object":{if(h===null)return"null";if(typeof h.toJSON=="function"){if(h=h.toJSON(J),typeof h!="object")return at(J,h,v,T,O);if(h===null)return"null"}if(v.indexOf(h)!==-1)return k;const $=O;if(Array.isArray(h)){if(h.length===0)return"[]";if(H<v.length+1)return'"[Array]"';v.push(h),O+=T;let C=`
14
- ${O}`;const V=`,
15
- ${O}`,Y=Math.min(h.length,M);let W=0;for(;W<Y-1;W++){const Q=at(String(W),h[W],v,T,O);C+=Q!==void 0?Q:"null",C+=V}const X=at(String(W),h[W],v,T,O);if(C+=X!==void 0?X:"null",h.length-1>M){const Q=h.length-M-1;C+=`${V}"... ${F(Q)} not stringified"`}return C+=`
16
- ${$}`,v.pop(),`[${C}]`}let _=Object.keys(h);const D=_.length;if(D===0)return"{}";if(H<v.length+1)return'"[Object]"';O+=T;const B=`,
17
- ${O}`;let j="",N="",P=Math.min(D,M);x(h)&&(j+=g(h,B,M),_=_.slice(h.length),P-=h.length,N=B),Z&&(_=l(_)),v.push(h);for(let C=0;C<P;C++){const V=_[C],Y=at(V,h[V],v,T,O);Y!==void 0&&(j+=`${N}${u(V)}: ${Y}`,N=B)}if(D>M){const C=D-M;j+=`${N}"...": "${F(C)} not stringified"`,N=B}return N!==""&&(j=`
18
- ${O}${j}
19
- ${$}`),v.pop(),`{${j}}`}case"number":return isFinite(h)?String(h):E?E(h):"null";case"boolean":return h===!0?"true":"false";case"undefined":return;case"bigint":if(q)return String(h);default:return E?E(h):void 0}}function st(J,h,v){switch(typeof h){case"string":return u(h);case"object":{if(h===null)return"null";if(typeof h.toJSON=="function"){if(h=h.toJSON(J),typeof h!="object")return st(J,h,v);if(h===null)return"null"}if(v.indexOf(h)!==-1)return k;let T="";if(Array.isArray(h)){if(h.length===0)return"[]";if(H<v.length+1)return'"[Array]"';v.push(h);const B=Math.min(h.length,M);let j=0;for(;j<B-1;j++){const P=st(String(j),h[j],v);T+=P!==void 0?P:"null",T+=","}const N=st(String(j),h[j],v);if(T+=N!==void 0?N:"null",h.length-1>M){const P=h.length-M-1;T+=`,"... ${F(P)} not stringified"`}return v.pop(),`[${T}]`}let O=Object.keys(h);const $=O.length;if($===0)return"{}";if(H<v.length+1)return'"[Object]"';let _="",D=Math.min($,M);x(h)&&(T+=g(h,",",M),O=O.slice(h.length),D-=h.length,_=","),Z&&(O=l(O)),v.push(h);for(let B=0;B<D;B++){const j=O[B],N=st(j,h[j],v);N!==void 0&&(T+=`${_}${u(j)}:${N}`,_=",")}if($>M){const B=$-M;T+=`${_}"...":"${F(B)} not stringified"`}return v.pop(),`{${T}}`}case"number":return isFinite(h)?String(h):E?E(h):"null";case"boolean":return h===!0?"true":"false";case"undefined":return;case"bigint":if(q)return String(h);default:return E?E(h):void 0}}function Tt(J,h,v){if(arguments.length>1){let T="";if(typeof v=="number"?T=" ".repeat(Math.min(v,10)):typeof v=="string"&&(T=v.slice(0,10)),h!=null){if(typeof h=="function")return ut("",{"":J},[],h,T,"");if(Array.isArray(h))return ft("",J,[],I(h),T,"")}if(T.length!==0)return at("",J,[],T,"")}return st("",J,[])}return Tt}})(Ut,Ut.exports);var Qe=Ut.exports;const _t=Wt(Qe);_t.configure;function tr(i,r){return{...i,name:r}}function er(i,r,s){const p={skip:s,document:i},{scope:f}=r;return!f||r.skip===void 0?p:ot.produce(p,u=>{const[l]=u.document.operations[f].slice(-1);r.skip&&r.skip>0&&(u.skip=r.skip),l.type==="NOOP"&&r.index===l.index&&u.skip>l.skip&&u.document.operations[f].pop()})}function rr(i,r,s){const{scope:p,input:f}=r,u={document:i,action:r,skip:s};return ot.produce(u,l=>{if(l.document.operations[p].length<1)throw new Error(`Cannot undo: no operations in history for scope "${p}"`);if(f<1)throw new Error("Invalid UNDO action: input value must be greater than 0");if(l.skip>0)throw new Error("Cannot undo: skip value from reducer cannot be used with UNDO action");const[a]=l.document.operations[p].slice(-1),x=a.type==="NOOP"&&a.skip>0;if(l.skip+=f,x){l.skip+=a.skip;const b=l.document.operations[p][l.document.operations[p].length-2];b&&a.index-b.index===1&&l.document.operations[p].pop()}if(l.document.operations[p].length<l.skip)throw new Error("Cannot undo: you can't undo more operations than the ones in the scope history");const g=l.document.operations[p].length-1;let A=f,w=x?g-a.skip:g;for(;A>0&&w>=0;){const b=l.document.operations[p][w];if(!b){A--,w--;continue}b.type==="NOOP"&&b.skip>0?(w=w-(b.skip+1),l.skip+=b.skip+1):(l.document.clipboard.push({...b}),A--,w--)}l.action=Qt(p)})}function ir(i,r,s){const{scope:p,input:f}=r,u={document:i,action:r,skip:s};return ot.produce(u,l=>{if(l.skip>0)throw new Error("Cannot redo: skip value from reducer cannot be used with REDO action");if(f>1)throw new Error("Cannot redo: you can only redo one operation at a time");if(f<1)throw new Error("Invalid REDO action: invalid redo input value");if(l.document.clipboard.length<1)throw new Error("Cannot redo: no operations in the clipboard");const a=l.document.clipboard.findLastIndex(g=>g.scope===p);if(a<0)throw new Error(`Cannot redo: no operations in clipboard for scope "${p}"`);const x=l.document.clipboard.splice(a,1)[0];l.action=ot.castDraft({type:x.type,scope:x.scope,input:x.input})})}function nr(i,r,s){const{scope:p}=r,f=i.operations[p];let{input:{start:u,end:l}}=r;u=u||0,l=l||f.length;const a=f.slice(u,l),x=f.slice(0,u),g=f.slice(l),A=Ft(i.initialState,{...i.operations,[p]:x.concat(a)},s),{name:w,state:b}=A,F=x.length,I=x.length?x[x.length-1].timestamp:g.length?g[0].timestamp:new Date().toISOString();return Ft(i.initialState,{...i.operations,[p]:[...x,{...Xt({name:w,state:b},a.length),timestamp:I,index:F,hash:Gt({state:b},"global")},...g.map((G,rt)=>({...G,index:F+rt+1}))]},s)}function or(i,r){return{...i,name:r.name,state:r.state??{global:{},local:{}}}}const ge="SET_NAME",yt="UNDO",wt="REDO",Bt="PRUNE",ye="LOAD_STATE",ar="NOOP";function sr(i,r){let s;return"index"in r?s={...r}:s=i.operations[r.scope].slice(-1)[0],((s==null?void 0:s.index)??-1)+1}function pr(i,r){return{...i,revision:{...i.revision,[r.scope]:sr(i,r)},lastModified:new Date().toISOString()}}function cr(i,r,s=0){if([yt,wt,Bt].includes(r.type))return i;const{scope:p}=r,f=i.operations[p].slice(0,i.revision[p]),u=[...f].pop();let l=((u==null?void 0:u.index)??-1)+1;if("index"in r){if(r.index>l+s)throw new Error(`Missing operations: expected ${l} with skip 0 or equivalent, got index ${r.index} with skip ${s}`);l=r.index}return f.push({...r,index:l,timestamp:new Date().toISOString(),hash:"",scope:p,skip:s}),{...i,operations:{...i.operations,[p]:f}}}function lr(i,r,s=0){let p=cr(i,r,s);return p=pr(p,r),p}function ur(i,r,s){switch(le().parse(r),r.type){case ge:return tr(i,r.input);case Bt:return nr(i,r,s);case ye:return or(i,r.input.state);default:return i}}function we(i,r,s){switch(r.type){case yt:return rr(i,r,s);case wt:return ir(i,r,s);default:return{document:i,action:r,skip:s}}}function Vt(i,r,s,p,f={}){const{skip:u,ignoreSkipOperations:l=!1}=f;let a={...r},x=u||0,g=i,A=[...i.clipboard];if(Oe(a)){const{document:w,skip:b}=er(g,a,x);x=b,g=w}if(zt(a)){const{skip:w,action:b,document:F}=we(i,a,x);a=b,x=w,g=F,A=[...g.clipboard]}if(Mt(a)&&(g=ur(g,a,s)),x>0&&!l){let w=x;"index"in a&&(w=De(g.operations[a.scope],a.index,x)),g=Ft(g.initialState,g.operations,s,void 0,void 0,void 0,{[a.scope]:w})}return g=lr(g,a,x),g=ot.produce(g,w=>{const b=s(w.state,a,p),F=zt(r)?[...A]:[];if(b)return ot.castDraft({...g,clipboard:[...F],state:b});w.clipboard=ot.castDraft([...F])}),ot.produce(g,w=>{if([yt,wt,Bt].includes(a.type))return w;const b=a.scope||"global";w.operations[b][w.operations[b].length-1].hash=Gt(w,b),!Mt(a)&&a.attachments&&a.attachments.forEach(F=>{const{hash:I,...G}=F;w.attachments[I]={...G}})})}var $t={exports:{}};typeof Object.create=="function"?$t.exports=function(r,s){s&&(r.super_=s,r.prototype=Object.create(s.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}))}:$t.exports=function(r,s){if(s){r.super_=s;var p=function(){};p.prototype=s.prototype,r.prototype=new p,r.prototype.constructor=r}};var be=$t.exports,Ct={exports:{}},Ee={},Ot={};Ot.byteLength=mr;Ot.toByteArray=dr;Ot.fromByteArray=wr;var nt=[],et=[],fr=typeof Uint8Array<"u"?Uint8Array:Array,Dt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var ht=0,hr=Dt.length;ht<hr;++ht)nt[ht]=Dt[ht],et[Dt.charCodeAt(ht)]=ht;et[45]=62;et[95]=63;function ve(i){var r=i.length;if(r%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var s=i.indexOf("=");s===-1&&(s=r);var p=s===r?0:4-s%4;return[s,p]}function mr(i){var r=ve(i),s=r[0],p=r[1];return(s+p)*3/4-p}function xr(i,r,s){return(r+s)*3/4-s}function dr(i){var r,s=ve(i),p=s[0],f=s[1],u=new fr(xr(i,p,f)),l=0,a=f>0?p-4:p,x;for(x=0;x<a;x+=4)r=et[i.charCodeAt(x)]<<18|et[i.charCodeAt(x+1)]<<12|et[i.charCodeAt(x+2)]<<6|et[i.charCodeAt(x+3)],u[l++]=r>>16&255,u[l++]=r>>8&255,u[l++]=r&255;return f===2&&(r=et[i.charCodeAt(x)]<<2|et[i.charCodeAt(x+1)]>>4,u[l++]=r&255),f===1&&(r=et[i.charCodeAt(x)]<<10|et[i.charCodeAt(x+1)]<<4|et[i.charCodeAt(x+2)]>>2,u[l++]=r>>8&255,u[l++]=r&255),u}function gr(i){return nt[i>>18&63]+nt[i>>12&63]+nt[i>>6&63]+nt[i&63]}function yr(i,r,s){for(var p,f=[],u=r;u<s;u+=3)p=(i[u]<<16&16711680)+(i[u+1]<<8&65280)+(i[u+2]&255),f.push(gr(p));return f.join("")}function wr(i){for(var r,s=i.length,p=s%3,f=[],u=16383,l=0,a=s-p;l<a;l+=u)f.push(yr(i,l,l+u>a?a:l+u));return p===1?(r=i[s-1],f.push(nt[r>>2]+nt[r<<4&63]+"==")):p===2&&(r=(i[s-2]<<8)+i[s-1],f.push(nt[r>>10]+nt[r>>4&63]+nt[r<<2&63]+"=")),f.join("")}var Kt={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */Kt.read=function(i,r,s,p,f){var u,l,a=f*8-p-1,x=(1<<a)-1,g=x>>1,A=-7,w=s?f-1:0,b=s?-1:1,F=i[r+w];for(w+=b,u=F&(1<<-A)-1,F>>=-A,A+=a;A>0;u=u*256+i[r+w],w+=b,A-=8);for(l=u&(1<<-A)-1,u>>=-A,A+=p;A>0;l=l*256+i[r+w],w+=b,A-=8);if(u===0)u=1-g;else{if(u===x)return l?NaN:(F?-1:1)*(1/0);l=l+Math.pow(2,p),u=u-g}return(F?-1:1)*l*Math.pow(2,u-p)};Kt.write=function(i,r,s,p,f,u){var l,a,x,g=u*8-f-1,A=(1<<g)-1,w=A>>1,b=f===23?Math.pow(2,-24)-Math.pow(2,-77):0,F=p?0:u-1,I=p?1:-1,G=r<0||r===0&&1/r<0?1:0;for(r=Math.abs(r),isNaN(r)||r===1/0?(a=isNaN(r)?1:0,l=A):(l=Math.floor(Math.log(r)/Math.LN2),r*(x=Math.pow(2,-l))<1&&(l--,x*=2),l+w>=1?r+=b/x:r+=b*Math.pow(2,1-w),r*x>=2&&(l++,x/=2),l+w>=A?(a=0,l=A):l+w>=1?(a=(r*x-1)*Math.pow(2,f),l=l+w):(a=r*Math.pow(2,w-1)*Math.pow(2,f),l=0));f>=8;i[s+F]=a&255,F+=I,a/=256,f-=8);for(l=l<<f|a,g+=f;g>0;i[s+F]=l&255,F+=I,l/=256,g-=8);i[s+F-I]|=G*128};/*!
20
- * The buffer module from node.js, for the browser.
21
- *
22
- * @author Feross Aboukhadijeh <https://feross.org>
23
- * @license MIT
24
- */(function(i){var r=Ot,s=Kt,p=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;i.Buffer=a,i.SlowBuffer=E,i.INSPECT_MAX_BYTES=50;var f=2147483647;i.kMaxLength=f,a.TYPED_ARRAY_SUPPORT=u(),!a.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function u(){try{var n=new Uint8Array(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,Uint8Array.prototype),Object.setPrototypeOf(n,t),n.foo()===42}catch{return!1}}Object.defineProperty(a.prototype,"parent",{enumerable:!0,get:function(){if(a.isBuffer(this))return this.buffer}}),Object.defineProperty(a.prototype,"offset",{enumerable:!0,get:function(){if(a.isBuffer(this))return this.byteOffset}});function l(n){if(n>f)throw new RangeError('The value "'+n+'" is invalid for option "size"');var t=new Uint8Array(n);return Object.setPrototypeOf(t,a.prototype),t}function a(n,t,e){if(typeof n=="number"){if(typeof t=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return w(n)}return x(n,t,e)}a.poolSize=8192;function x(n,t,e){if(typeof n=="string")return b(n,t);if(ArrayBuffer.isView(n))return I(n);if(n==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof n);if(it(n,ArrayBuffer)||n&&it(n.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(it(n,SharedArrayBuffer)||n&&it(n.buffer,SharedArrayBuffer)))return G(n,t,e);if(typeof n=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');var o=n.valueOf&&n.valueOf();if(o!=null&&o!==n)return a.from(o,t,e);var c=rt(n);if(c)return c;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof n[Symbol.toPrimitive]=="function")return a.from(n[Symbol.toPrimitive]("string"),t,e);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof n)}a.from=function(n,t,e){return x(n,t,e)},Object.setPrototypeOf(a.prototype,Uint8Array.prototype),Object.setPrototypeOf(a,Uint8Array);function g(n){if(typeof n!="number")throw new TypeError('"size" argument must be of type number');if(n<0)throw new RangeError('The value "'+n+'" is invalid for option "size"')}function A(n,t,e){return g(n),n<=0?l(n):t!==void 0?typeof e=="string"?l(n).fill(t,e):l(n).fill(t):l(n)}a.alloc=function(n,t,e){return A(n,t,e)};function w(n){return g(n),l(n<0?0:y(n)|0)}a.allocUnsafe=function(n){return w(n)},a.allocUnsafeSlow=function(n){return w(n)};function b(n,t){if((typeof t!="string"||t==="")&&(t="utf8"),!a.isEncoding(t))throw new TypeError("Unknown encoding: "+t);var e=k(n,t)|0,o=l(e),c=o.write(n,t);return c!==e&&(o=o.slice(0,c)),o}function F(n){for(var t=n.length<0?0:y(n.length)|0,e=l(t),o=0;o<t;o+=1)e[o]=n[o]&255;return e}function I(n){if(it(n,Uint8Array)){var t=new Uint8Array(n);return G(t.buffer,t.byteOffset,t.byteLength)}return F(n)}function G(n,t,e){if(t<0||n.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(n.byteLength<t+(e||0))throw new RangeError('"length" is outside of buffer bounds');var o;return t===void 0&&e===void 0?o=new Uint8Array(n):e===void 0?o=new Uint8Array(n,t):o=new Uint8Array(n,t,e),Object.setPrototypeOf(o,a.prototype),o}function rt(n){if(a.isBuffer(n)){var t=y(n.length)|0,e=l(t);return e.length===0||n.copy(e,0,0,t),e}if(n.length!==void 0)return typeof n.length!="number"||kt(n.length)?l(0):F(n);if(n.type==="Buffer"&&Array.isArray(n.data))return F(n.data)}function y(n){if(n>=f)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+f.toString(16)+" bytes");return n|0}function E(n){return+n!=n&&(n=0),a.alloc(+n)}a.isBuffer=function(t){return t!=null&&t._isBuffer===!0&&t!==a.prototype},a.compare=function(t,e){if(it(t,Uint8Array)&&(t=a.from(t,t.offset,t.byteLength)),it(e,Uint8Array)&&(e=a.from(e,e.offset,e.byteLength)),!a.isBuffer(t)||!a.isBuffer(e))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===e)return 0;for(var o=t.length,c=e.length,m=0,d=Math.min(o,c);m<d;++m)if(t[m]!==e[m]){o=t[m],c=e[m];break}return o<c?-1:c<o?1:0},a.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},a.concat=function(t,e){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(t.length===0)return a.alloc(0);var o;if(e===void 0)for(e=0,o=0;o<t.length;++o)e+=t[o].length;var c=a.allocUnsafe(e),m=0;for(o=0;o<t.length;++o){var d=t[o];if(it(d,Uint8Array))m+d.length>c.length?a.from(d).copy(c,m):Uint8Array.prototype.set.call(c,d,m);else if(a.isBuffer(d))d.copy(c,m);else throw new TypeError('"list" argument must be an Array of Buffers');m+=d.length}return c};function k(n,t){if(a.isBuffer(n))return n.length;if(ArrayBuffer.isView(n)||it(n,ArrayBuffer))return n.byteLength;if(typeof n!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof n);var e=n.length,o=arguments.length>2&&arguments[2]===!0;if(!o&&e===0)return 0;for(var c=!1;;)switch(t){case"ascii":case"latin1":case"binary":return e;case"utf8":case"utf-8":return W(n).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return e*2;case"hex":return e>>>1;case"base64":return pt(n).length;default:if(c)return o?-1:W(n).length;t=(""+t).toLowerCase(),c=!0}}a.byteLength=k;function q(n,t,e){var o=!1;if((t===void 0||t<0)&&(t=0),t>this.length||((e===void 0||e>this.length)&&(e=this.length),e<=0)||(e>>>=0,t>>>=0,e<=t))return"";for(n||(n="utf8");;)switch(n){case"hex":return _(this,t,e);case"utf8":case"utf-8":return h(this,t,e);case"ascii":return O(this,t,e);case"latin1":case"binary":return $(this,t,e);case"base64":return J(this,t,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return D(this,t,e);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(n+"").toLowerCase(),o=!0}}a.prototype._isBuffer=!0;function Z(n,t,e){var o=n[t];n[t]=n[e],n[e]=o}a.prototype.swap16=function(){var t=this.length;if(t%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;e<t;e+=2)Z(this,e,e+1);return this},a.prototype.swap32=function(){var t=this.length;if(t%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;e<t;e+=4)Z(this,e,e+3),Z(this,e+1,e+2);return this},a.prototype.swap64=function(){var t=this.length;if(t%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;e<t;e+=8)Z(this,e,e+7),Z(this,e+1,e+6),Z(this,e+2,e+5),Z(this,e+3,e+4);return this},a.prototype.toString=function(){var t=this.length;return t===0?"":arguments.length===0?h(this,0,t):q.apply(this,arguments)},a.prototype.toLocaleString=a.prototype.toString,a.prototype.equals=function(t){if(!a.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t?!0:a.compare(this,t)===0},a.prototype.inspect=function(){var t="",e=i.INSPECT_MAX_BYTES;return t=this.toString("hex",0,e).replace(/(.{2})/g,"$1 ").trim(),this.length>e&&(t+=" ... "),"<Buffer "+t+">"},p&&(a.prototype[p]=a.prototype.inspect),a.prototype.compare=function(t,e,o,c,m){if(it(t,Uint8Array)&&(t=a.from(t,t.offset,t.byteLength)),!a.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(e===void 0&&(e=0),o===void 0&&(o=t?t.length:0),c===void 0&&(c=0),m===void 0&&(m=this.length),e<0||o>t.length||c<0||m>this.length)throw new RangeError("out of range index");if(c>=m&&e>=o)return 0;if(c>=m)return-1;if(e>=o)return 1;if(e>>>=0,o>>>=0,c>>>=0,m>>>=0,this===t)return 0;for(var d=m-c,U=o-e,z=Math.min(d,U),R=this.slice(c,m),K=t.slice(e,o),L=0;L<z;++L)if(R[L]!==K[L]){d=R[L],U=K[L];break}return d<U?-1:U<d?1:0};function H(n,t,e,o,c){if(n.length===0)return-1;if(typeof e=="string"?(o=e,e=0):e>2147483647?e=2147483647:e<-2147483648&&(e=-2147483648),e=+e,kt(e)&&(e=c?0:n.length-1),e<0&&(e=n.length+e),e>=n.length){if(c)return-1;e=n.length-1}else if(e<0)if(c)e=0;else return-1;if(typeof t=="string"&&(t=a.from(t,o)),a.isBuffer(t))return t.length===0?-1:M(n,t,e,o,c);if(typeof t=="number")return t=t&255,typeof Uint8Array.prototype.indexOf=="function"?c?Uint8Array.prototype.indexOf.call(n,t,e):Uint8Array.prototype.lastIndexOf.call(n,t,e):M(n,[t],e,o,c);throw new TypeError("val must be string, number or Buffer")}function M(n,t,e,o,c){var m=1,d=n.length,U=t.length;if(o!==void 0&&(o=String(o).toLowerCase(),o==="ucs2"||o==="ucs-2"||o==="utf16le"||o==="utf-16le")){if(n.length<2||t.length<2)return-1;m=2,d/=2,U/=2,e/=2}function z(ee,re){return m===1?ee[re]:ee.readUInt16BE(re*m)}var R;if(c){var K=-1;for(R=e;R<d;R++)if(z(n,R)===z(t,K===-1?0:R-K)){if(K===-1&&(K=R),R-K+1===U)return K*m}else K!==-1&&(R-=R-K),K=-1}else for(e+U>d&&(e=d-U),R=e;R>=0;R--){for(var L=!0,At=0;At<U;At++)if(z(n,R+At)!==z(t,At)){L=!1;break}if(L)return R}return-1}a.prototype.includes=function(t,e,o){return this.indexOf(t,e,o)!==-1},a.prototype.indexOf=function(t,e,o){return H(this,t,e,o,!0)},a.prototype.lastIndexOf=function(t,e,o){return H(this,t,e,o,!1)};function ut(n,t,e,o){e=Number(e)||0;var c=n.length-e;o?(o=Number(o),o>c&&(o=c)):o=c;var m=t.length;o>m/2&&(o=m/2);for(var d=0;d<o;++d){var U=parseInt(t.substr(d*2,2),16);if(kt(U))return d;n[e+d]=U}return d}function ft(n,t,e,o){return vt(W(t,n.length-e),n,e,o)}function at(n,t,e,o){return vt(X(t),n,e,o)}function st(n,t,e,o){return vt(pt(t),n,e,o)}function Tt(n,t,e,o){return vt(Q(t,n.length-e),n,e,o)}a.prototype.write=function(t,e,o,c){if(e===void 0)c="utf8",o=this.length,e=0;else if(o===void 0&&typeof e=="string")c=e,o=this.length,e=0;else if(isFinite(e))e=e>>>0,isFinite(o)?(o=o>>>0,c===void 0&&(c="utf8")):(c=o,o=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");var m=this.length-e;if((o===void 0||o>m)&&(o=m),t.length>0&&(o<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");c||(c="utf8");for(var d=!1;;)switch(c){case"hex":return ut(this,t,e,o);case"utf8":case"utf-8":return ft(this,t,e,o);case"ascii":case"latin1":case"binary":return at(this,t,e,o);case"base64":return st(this,t,e,o);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Tt(this,t,e,o);default:if(d)throw new TypeError("Unknown encoding: "+c);c=(""+c).toLowerCase(),d=!0}},a.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function J(n,t,e){return t===0&&e===n.length?r.fromByteArray(n):r.fromByteArray(n.slice(t,e))}function h(n,t,e){e=Math.min(n.length,e);for(var o=[],c=t;c<e;){var m=n[c],d=null,U=m>239?4:m>223?3:m>191?2:1;if(c+U<=e){var z,R,K,L;switch(U){case 1:m<128&&(d=m);break;case 2:z=n[c+1],(z&192)===128&&(L=(m&31)<<6|z&63,L>127&&(d=L));break;case 3:z=n[c+1],R=n[c+2],(z&192)===128&&(R&192)===128&&(L=(m&15)<<12|(z&63)<<6|R&63,L>2047&&(L<55296||L>57343)&&(d=L));break;case 4:z=n[c+1],R=n[c+2],K=n[c+3],(z&192)===128&&(R&192)===128&&(K&192)===128&&(L=(m&15)<<18|(z&63)<<12|(R&63)<<6|K&63,L>65535&&L<1114112&&(d=L))}}d===null?(d=65533,U=1):d>65535&&(d-=65536,o.push(d>>>10&1023|55296),d=56320|d&1023),o.push(d),c+=U}return T(o)}var v=4096;function T(n){var t=n.length;if(t<=v)return String.fromCharCode.apply(String,n);for(var e="",o=0;o<t;)e+=String.fromCharCode.apply(String,n.slice(o,o+=v));return e}function O(n,t,e){var o="";e=Math.min(n.length,e);for(var c=t;c<e;++c)o+=String.fromCharCode(n[c]&127);return o}function $(n,t,e){var o="";e=Math.min(n.length,e);for(var c=t;c<e;++c)o+=String.fromCharCode(n[c]);return o}function _(n,t,e){var o=n.length;(!t||t<0)&&(t=0),(!e||e<0||e>o)&&(e=o);for(var c="",m=t;m<e;++m)c+=Je[n[m]];return c}function D(n,t,e){for(var o=n.slice(t,e),c="",m=0;m<o.length-1;m+=2)c+=String.fromCharCode(o[m]+o[m+1]*256);return c}a.prototype.slice=function(t,e){var o=this.length;t=~~t,e=e===void 0?o:~~e,t<0?(t+=o,t<0&&(t=0)):t>o&&(t=o),e<0?(e+=o,e<0&&(e=0)):e>o&&(e=o),e<t&&(e=t);var c=this.subarray(t,e);return Object.setPrototypeOf(c,a.prototype),c};function B(n,t,e){if(n%1!==0||n<0)throw new RangeError("offset is not uint");if(n+t>e)throw new RangeError("Trying to access beyond buffer length")}a.prototype.readUintLE=a.prototype.readUIntLE=function(t,e,o){t=t>>>0,e=e>>>0,o||B(t,e,this.length);for(var c=this[t],m=1,d=0;++d<e&&(m*=256);)c+=this[t+d]*m;return c},a.prototype.readUintBE=a.prototype.readUIntBE=function(t,e,o){t=t>>>0,e=e>>>0,o||B(t,e,this.length);for(var c=this[t+--e],m=1;e>0&&(m*=256);)c+=this[t+--e]*m;return c},a.prototype.readUint8=a.prototype.readUInt8=function(t,e){return t=t>>>0,e||B(t,1,this.length),this[t]},a.prototype.readUint16LE=a.prototype.readUInt16LE=function(t,e){return t=t>>>0,e||B(t,2,this.length),this[t]|this[t+1]<<8},a.prototype.readUint16BE=a.prototype.readUInt16BE=function(t,e){return t=t>>>0,e||B(t,2,this.length),this[t]<<8|this[t+1]},a.prototype.readUint32LE=a.prototype.readUInt32LE=function(t,e){return t=t>>>0,e||B(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+this[t+3]*16777216},a.prototype.readUint32BE=a.prototype.readUInt32BE=function(t,e){return t=t>>>0,e||B(t,4,this.length),this[t]*16777216+(this[t+1]<<16|this[t+2]<<8|this[t+3])},a.prototype.readIntLE=function(t,e,o){t=t>>>0,e=e>>>0,o||B(t,e,this.length);for(var c=this[t],m=1,d=0;++d<e&&(m*=256);)c+=this[t+d]*m;return m*=128,c>=m&&(c-=Math.pow(2,8*e)),c},a.prototype.readIntBE=function(t,e,o){t=t>>>0,e=e>>>0,o||B(t,e,this.length);for(var c=e,m=1,d=this[t+--c];c>0&&(m*=256);)d+=this[t+--c]*m;return m*=128,d>=m&&(d-=Math.pow(2,8*e)),d},a.prototype.readInt8=function(t,e){return t=t>>>0,e||B(t,1,this.length),this[t]&128?(255-this[t]+1)*-1:this[t]},a.prototype.readInt16LE=function(t,e){t=t>>>0,e||B(t,2,this.length);var o=this[t]|this[t+1]<<8;return o&32768?o|4294901760:o},a.prototype.readInt16BE=function(t,e){t=t>>>0,e||B(t,2,this.length);var o=this[t+1]|this[t]<<8;return o&32768?o|4294901760:o},a.prototype.readInt32LE=function(t,e){return t=t>>>0,e||B(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},a.prototype.readInt32BE=function(t,e){return t=t>>>0,e||B(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},a.prototype.readFloatLE=function(t,e){return t=t>>>0,e||B(t,4,this.length),s.read(this,t,!0,23,4)},a.prototype.readFloatBE=function(t,e){return t=t>>>0,e||B(t,4,this.length),s.read(this,t,!1,23,4)},a.prototype.readDoubleLE=function(t,e){return t=t>>>0,e||B(t,8,this.length),s.read(this,t,!0,52,8)},a.prototype.readDoubleBE=function(t,e){return t=t>>>0,e||B(t,8,this.length),s.read(this,t,!1,52,8)};function j(n,t,e,o,c,m){if(!a.isBuffer(n))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>c||t<m)throw new RangeError('"value" argument is out of bounds');if(e+o>n.length)throw new RangeError("Index out of range")}a.prototype.writeUintLE=a.prototype.writeUIntLE=function(t,e,o,c){if(t=+t,e=e>>>0,o=o>>>0,!c){var m=Math.pow(2,8*o)-1;j(this,t,e,o,m,0)}var d=1,U=0;for(this[e]=t&255;++U<o&&(d*=256);)this[e+U]=t/d&255;return e+o},a.prototype.writeUintBE=a.prototype.writeUIntBE=function(t,e,o,c){if(t=+t,e=e>>>0,o=o>>>0,!c){var m=Math.pow(2,8*o)-1;j(this,t,e,o,m,0)}var d=o-1,U=1;for(this[e+d]=t&255;--d>=0&&(U*=256);)this[e+d]=t/U&255;return e+o},a.prototype.writeUint8=a.prototype.writeUInt8=function(t,e,o){return t=+t,e=e>>>0,o||j(this,t,e,1,255,0),this[e]=t&255,e+1},a.prototype.writeUint16LE=a.prototype.writeUInt16LE=function(t,e,o){return t=+t,e=e>>>0,o||j(this,t,e,2,65535,0),this[e]=t&255,this[e+1]=t>>>8,e+2},a.prototype.writeUint16BE=a.prototype.writeUInt16BE=function(t,e,o){return t=+t,e=e>>>0,o||j(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=t&255,e+2},a.prototype.writeUint32LE=a.prototype.writeUInt32LE=function(t,e,o){return t=+t,e=e>>>0,o||j(this,t,e,4,4294967295,0),this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=t&255,e+4},a.prototype.writeUint32BE=a.prototype.writeUInt32BE=function(t,e,o){return t=+t,e=e>>>0,o||j(this,t,e,4,4294967295,0),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=t&255,e+4},a.prototype.writeIntLE=function(t,e,o,c){if(t=+t,e=e>>>0,!c){var m=Math.pow(2,8*o-1);j(this,t,e,o,m-1,-m)}var d=0,U=1,z=0;for(this[e]=t&255;++d<o&&(U*=256);)t<0&&z===0&&this[e+d-1]!==0&&(z=1),this[e+d]=(t/U>>0)-z&255;return e+o},a.prototype.writeIntBE=function(t,e,o,c){if(t=+t,e=e>>>0,!c){var m=Math.pow(2,8*o-1);j(this,t,e,o,m-1,-m)}var d=o-1,U=1,z=0;for(this[e+d]=t&255;--d>=0&&(U*=256);)t<0&&z===0&&this[e+d+1]!==0&&(z=1),this[e+d]=(t/U>>0)-z&255;return e+o},a.prototype.writeInt8=function(t,e,o){return t=+t,e=e>>>0,o||j(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=t&255,e+1},a.prototype.writeInt16LE=function(t,e,o){return t=+t,e=e>>>0,o||j(this,t,e,2,32767,-32768),this[e]=t&255,this[e+1]=t>>>8,e+2},a.prototype.writeInt16BE=function(t,e,o){return t=+t,e=e>>>0,o||j(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=t&255,e+2},a.prototype.writeInt32LE=function(t,e,o){return t=+t,e=e>>>0,o||j(this,t,e,4,2147483647,-2147483648),this[e]=t&255,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4},a.prototype.writeInt32BE=function(t,e,o){return t=+t,e=e>>>0,o||j(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=t&255,e+4};function N(n,t,e,o,c,m){if(e+o>n.length)throw new RangeError("Index out of range");if(e<0)throw new RangeError("Index out of range")}function P(n,t,e,o,c){return t=+t,e=e>>>0,c||N(n,t,e,4),s.write(n,t,e,o,23,4),e+4}a.prototype.writeFloatLE=function(t,e,o){return P(this,t,e,!0,o)},a.prototype.writeFloatBE=function(t,e,o){return P(this,t,e,!1,o)};function C(n,t,e,o,c){return t=+t,e=e>>>0,c||N(n,t,e,8),s.write(n,t,e,o,52,8),e+8}a.prototype.writeDoubleLE=function(t,e,o){return C(this,t,e,!0,o)},a.prototype.writeDoubleBE=function(t,e,o){return C(this,t,e,!1,o)},a.prototype.copy=function(t,e,o,c){if(!a.isBuffer(t))throw new TypeError("argument should be a Buffer");if(o||(o=0),!c&&c!==0&&(c=this.length),e>=t.length&&(e=t.length),e||(e=0),c>0&&c<o&&(c=o),c===o||t.length===0||this.length===0)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(o<0||o>=this.length)throw new RangeError("Index out of range");if(c<0)throw new RangeError("sourceEnd out of bounds");c>this.length&&(c=this.length),t.length-e<c-o&&(c=t.length-e+o);var m=c-o;return this===t&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(e,o,c):Uint8Array.prototype.set.call(t,this.subarray(o,c),e),m},a.prototype.fill=function(t,e,o,c){if(typeof t=="string"){if(typeof e=="string"?(c=e,e=0,o=this.length):typeof o=="string"&&(c=o,o=this.length),c!==void 0&&typeof c!="string")throw new TypeError("encoding must be a string");if(typeof c=="string"&&!a.isEncoding(c))throw new TypeError("Unknown encoding: "+c);if(t.length===1){var m=t.charCodeAt(0);(c==="utf8"&&m<128||c==="latin1")&&(t=m)}}else typeof t=="number"?t=t&255:typeof t=="boolean"&&(t=Number(t));if(e<0||this.length<e||this.length<o)throw new RangeError("Out of range index");if(o<=e)return this;e=e>>>0,o=o===void 0?this.length:o>>>0,t||(t=0);var d;if(typeof t=="number")for(d=e;d<o;++d)this[d]=t;else{var U=a.isBuffer(t)?t:a.from(t,c),z=U.length;if(z===0)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(d=0;d<o-e;++d)this[d+e]=U[d%z]}return this};var V=/[^+/0-9A-Za-z-_]/g;function Y(n){if(n=n.split("=")[0],n=n.trim().replace(V,""),n.length<2)return"";for(;n.length%4!==0;)n=n+"=";return n}function W(n,t){t=t||1/0;for(var e,o=n.length,c=null,m=[],d=0;d<o;++d){if(e=n.charCodeAt(d),e>55295&&e<57344){if(!c){if(e>56319){(t-=3)>-1&&m.push(239,191,189);continue}else if(d+1===o){(t-=3)>-1&&m.push(239,191,189);continue}c=e;continue}if(e<56320){(t-=3)>-1&&m.push(239,191,189),c=e;continue}e=(c-55296<<10|e-56320)+65536}else c&&(t-=3)>-1&&m.push(239,191,189);if(c=null,e<128){if((t-=1)<0)break;m.push(e)}else if(e<2048){if((t-=2)<0)break;m.push(e>>6|192,e&63|128)}else if(e<65536){if((t-=3)<0)break;m.push(e>>12|224,e>>6&63|128,e&63|128)}else if(e<1114112){if((t-=4)<0)break;m.push(e>>18|240,e>>12&63|128,e>>6&63|128,e&63|128)}else throw new Error("Invalid code point")}return m}function X(n){for(var t=[],e=0;e<n.length;++e)t.push(n.charCodeAt(e)&255);return t}function Q(n,t){for(var e,o,c,m=[],d=0;d<n.length&&!((t-=2)<0);++d)e=n.charCodeAt(d),o=e>>8,c=e%256,m.push(c),m.push(o);return m}function pt(n){return r.toByteArray(Y(n))}function vt(n,t,e,o){for(var c=0;c<o&&!(c+e>=t.length||c>=n.length);++c)t[c+e]=n[c];return c}function it(n,t){return n instanceof t||n!=null&&n.constructor!=null&&n.constructor.name!=null&&n.constructor.name===t.name}function kt(n){return n!==n}var Je=function(){for(var n="0123456789abcdef",t=new Array(256),e=0;e<16;++e)for(var o=e*16,c=0;c<16;++c)t[o+c]=n[e]+n[c];return t}()})(Ee);/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */(function(i,r){var s=Ee,p=s.Buffer;function f(l,a){for(var x in l)a[x]=l[x]}p.from&&p.alloc&&p.allocUnsafe&&p.allocUnsafeSlow?i.exports=s:(f(s,r),r.Buffer=u);function u(l,a,x){return p(l,a,x)}u.prototype=Object.create(p.prototype),f(p,u),u.from=function(l,a,x){if(typeof l=="number")throw new TypeError("Argument must not be a number");return p(l,a,x)},u.alloc=function(l,a,x){if(typeof l!="number")throw new TypeError("Argument must be a number");var g=p(l);return a!==void 0?typeof x=="string"?g.fill(a,x):g.fill(a):g.fill(0),g},u.allocUnsafe=function(l){if(typeof l!="number")throw new TypeError("Argument must be a number");return p(l)},u.allocUnsafeSlow=function(l){if(typeof l!="number")throw new TypeError("Argument must be a number");return s.SlowBuffer(l)}})(Ct,Ct.exports);var Ht=Ct.exports,Ae=Ht.Buffer;function jt(i,r){this._block=Ae.alloc(i),this._finalSize=r,this._blockSize=i,this._len=0}jt.prototype.update=function(i,r){typeof i=="string"&&(r=r||"utf8",i=Ae.from(i,r));for(var s=this._block,p=this._blockSize,f=i.length,u=this._len,l=0;l<f;){for(var a=u%p,x=Math.min(f-l,p-a),g=0;g<x;g++)s[a+g]=i[l+g];u+=x,l+=x,u%p===0&&this._update(s)}return this._len+=f,this};jt.prototype.digest=function(i){var r=this._len%this._blockSize;this._block[r]=128,this._block.fill(0,r+1),r>=this._finalSize&&(this._update(this._block),this._block.fill(0));var s=this._len*8;if(s<=4294967295)this._block.writeUInt32BE(s,this._blockSize-4);else{var p=(s&4294967295)>>>0,f=(s-p)/4294967296;this._block.writeUInt32BE(f,this._blockSize-8),this._block.writeUInt32BE(p,this._blockSize-4)}this._update(this._block);var u=this._hash();return i?u.toString(i):u};jt.prototype._update=function(){throw new Error("_update must be implemented by subclass")};var Se=jt,br=be,_e=Se,Er=Ht.Buffer,vr=[1518500249,1859775393,-1894007588,-899497514],Ar=new Array(80);function bt(){this.init(),this._w=Ar,_e.call(this,64,56)}br(bt,_e);bt.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function Sr(i){return i<<1|i>>>31}function _r(i){return i<<5|i>>>27}function Fr(i){return i<<30|i>>>2}function Br(i,r,s,p){return i===0?r&s|~r&p:i===2?r&s|r&p|s&p:r^s^p}bt.prototype._update=function(i){for(var r=this._w,s=this._a|0,p=this._b|0,f=this._c|0,u=this._d|0,l=this._e|0,a=0;a<16;++a)r[a]=i.readInt32BE(a*4);for(;a<80;++a)r[a]=Sr(r[a-3]^r[a-8]^r[a-14]^r[a-16]);for(var x=0;x<80;++x){var g=~~(x/20),A=_r(s)+Br(g,p,f,u)+l+r[x]+vr[g]|0;l=u,u=f,f=Fr(p),p=s,s=A}this._a=s+this._a|0,this._b=p+this._b|0,this._c=f+this._c|0,this._d=u+this._d|0,this._e=l+this._e|0};bt.prototype._hash=function(){var i=Er.allocUnsafe(20);return i.writeInt32BE(this._a|0,0),i.writeInt32BE(this._b|0,4),i.writeInt32BE(this._c|0,8),i.writeInt32BE(this._d|0,12),i.writeInt32BE(this._e|0,16),i};var Or=bt;const jr=Wt(Or);var Ir=be,Fe=Se,Tr=Ht.Buffer,kr=[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],Dr=new Array(64);function Et(){this.init(),this._w=Dr,Fe.call(this,64,56)}Ir(Et,Fe);Et.prototype.init=function(){return this._a=1779033703,this._b=3144134277,this._c=1013904242,this._d=2773480762,this._e=1359893119,this._f=2600822924,this._g=528734635,this._h=1541459225,this};function Ur(i,r,s){return s^i&(r^s)}function $r(i,r,s){return i&r|s&(i|r)}function Cr(i){return(i>>>2|i<<30)^(i>>>13|i<<19)^(i>>>22|i<<10)}function zr(i){return(i>>>6|i<<26)^(i>>>11|i<<21)^(i>>>25|i<<7)}function Mr(i){return(i>>>7|i<<25)^(i>>>18|i<<14)^i>>>3}function Nr(i){return(i>>>17|i<<15)^(i>>>19|i<<13)^i>>>10}Et.prototype._update=function(i){for(var r=this._w,s=this._a|0,p=this._b|0,f=this._c|0,u=this._d|0,l=this._e|0,a=this._f|0,x=this._g|0,g=this._h|0,A=0;A<16;++A)r[A]=i.readInt32BE(A*4);for(;A<64;++A)r[A]=Nr(r[A-2])+r[A-7]+Mr(r[A-15])+r[A-16]|0;for(var w=0;w<64;++w){var b=g+zr(l)+Ur(l,a,x)+kr[w]+r[w]|0,F=Cr(s)+$r(s,p,f)|0;g=x,x=a,a=l,l=u+b|0,u=f,f=p,p=s,s=b+F|0}this._a=s+this._a|0,this._b=p+this._b|0,this._c=f+this._c|0,this._d=u+this._d|0,this._e=l+this._e|0,this._f=a+this._f|0,this._g=x+this._g|0,this._h=g+this._h|0};Et.prototype._hash=function(){var i=Tr.allocUnsafe(32);return i.writeInt32BE(this._a,0),i.writeInt32BE(this._b,4),i.writeInt32BE(this._c,8),i.writeInt32BE(this._d,12),i.writeInt32BE(this._e,16),i.writeInt32BE(this._f,20),i.writeInt32BE(this._g,24),i.writeInt32BE(this._h,28),i};var Rr=Et;const Lr=Wt(Rr),Zt=new Error("File system not available.");function Pr(i,r,s){throw Zt}function Be(i){throw Zt}function qr(i){throw Zt}const Jr=async i=>Be(),Wr={sha1:jr,sha256:Lr},It=(i,r="sha1")=>{if(!["sha1","sha256"].includes(r))throw new Error("Hashing algorithm not supported: Available: sha1, sha256");const s=Wr[r];return new s().update(i).digest("base64")};function Oe(i){return i.type===ar&&i.skip!==void 0&&i.skip>0&&i.hash!==void 0}function zt(i){return[yt,wt].includes(i.type)}function Mt(i){return[ge,yt,wt,Bt,ye].includes(i.type)}function lt(i,r,s,p,f="global"){if(!i)throw new Error("Empty action type");if(typeof i!="string")throw new Error(`Invalid action type: ${i}`);const u={type:i,input:r,scope:f};s&&(u.attachments=s);try{p==null||p().parse(u.input)}catch(l){throw new Error(`Invalid action input: ${l}`)}return u}function je(i,r=Vt){return(s,p,f,u)=>r(s,p,i,f,u)}const Ie=(i,r)=>({name:"",documentType:"",revision:{global:0,local:0},created:new Date().toISOString(),lastModified:new Date().toISOString(),attachments:{},...i,state:(r==null?void 0:r(i==null?void 0:i.state))??(i==null?void 0:i.state)??{global:{},local:{}}}),Te=(i,r)=>{const s=Ie(i,r);return{...s,initialState:s,operations:{global:[],local:[]},clipboard:[]}},Gt=(i,r="global")=>It(_t(i.state[r]||"")),Vr=(i,r=1e3)=>{const s=Math.random()*r;return It(`${(i??new Date).toISOString()}${s}`)};function xt(i){return ot.castImmutable(ot.freeze(i,!0))}function ke(i,r){const s=[...i];let p=r||0,f=s.length>0?s[s.length-1].index:0;const u=[];for(const l of s.reverse()){if(p>0){const g=f-l.index;p-=g}if(p<0)throw new Error("Invalid operation index, missing operations");const a={ignore:p>0,operation:l},x=l.skip>0?l.skip+1:0;if(x>0&&x>p){const g=x-p;p=p+g}f=l.index,u.push(a)}return u.reverse()}function De(i,r,s){const p=i.slice().sort((a,x)=>a.skip-x.skip).sort((a,x)=>a.index-x.index);let f=s,u=0,l=r;for(const a of p.reverse()){const x=l-a.index;if(f=f-x,f>-1)u++,l=a.index;else break}return u}function Kr(i){return Object.values(i).flatMap(r=>r).sort((r,s)=>new Date(r.timestamp).getTime()-new Date(s.timestamp).getTime())}function Ue(i){return Object.values(i).flatMap(r=>r).sort((r,s)=>new Date(r.operation.timestamp).getTime()-new Date(s.operation.timestamp).getTime())}function Ft(i,r,s,p,f,u=Vt,l={}){const a=je(s,u);return Yt(i,r,a,p,f,l)}function Yt(i,r,s,p,f,u={}){const l=Te(i),a=Object.keys(r).reduce((b,F)=>{const I=F;return{...b,[I]:r[I].slice(0,f==null?void 0:f.revision[I])}},{}),x=Object.keys(a).reduce((b,F)=>{const I=F;return{...b,[I]:ke(a[I],u[I])}},{}),g=Ue(x).reduce((b,{ignore:F,operation:I})=>F?s(b,Qt(I.scope),p,{skip:I.skip,ignoreSkipOperations:!0}):s(b,I,p,{skip:I.skip,ignoreSkipOperations:!0}),l),A=Object.keys(g.operations).reduce((b,F)=>{const I=F,G=f&&f.revision[I]<r[I].length?r[I].slice(f.revision[I]):[];return{...b,[I]:[...g.operations[I].map((rt,y)=>{var E;return{...rt,timestamp:((E=r[I][y])==null?void 0:E.timestamp)??rt.timestamp}}),...G]}},{global:[],local:[]}),w=Object.values(A).reduce((b,F)=>{for(const I of F)I.timestamp>b&&(b=I.timestamp);return b},i.lastModified);return{...g,operations:A,lastModified:w}}function Hr(i,r){return _t(i)===_t(r)}const $e=i=>lt("SET_NAME",i,void 0,qt,void 0),Ce=(i=1,r="global")=>lt("UNDO",i,void 0,Jt,r),ze=(i=1,r="global")=>lt("REDO",i,void 0,Pt,r),Me=(i,r,s="global")=>lt("PRUNE",{start:i,end:r},void 0,Lt,s),Xt=(i,r)=>lt("LOAD_STATE",{state:i,operations:r},void 0,Rt),Qt=(i="global")=>lt("NOOP",{},void 0,void 0,i),Zr=Object.freeze(Object.defineProperty({__proto__:null,loadState:Xt,noop:Qt,prune:Me,redo:ze,setName:$e,undo:Ce},Symbol.toStringTag,{value:"Module"})),Ne={"application/andrew-inset":["ez"],"application/appinstaller":["appinstaller"],"application/applixware":["aw"],"application/appx":["appx"],"application/appxbundle":["appxbundle"],"application/atom+xml":["atom"],"application/atomcat+xml":["atomcat"],"application/atomdeleted+xml":["atomdeleted"],"application/atomsvc+xml":["atomsvc"],"application/atsc-dwd+xml":["dwd"],"application/atsc-held+xml":["held"],"application/atsc-rsat+xml":["rsat"],"application/automationml-aml+xml":["aml"],"application/automationml-amlx+zip":["amlx"],"application/bdoc":["bdoc"],"application/calendar+xml":["xcs"],"application/ccxml+xml":["ccxml"],"application/cdfx+xml":["cdfx"],"application/cdmi-capability":["cdmia"],"application/cdmi-container":["cdmic"],"application/cdmi-domain":["cdmid"],"application/cdmi-object":["cdmio"],"application/cdmi-queue":["cdmiq"],"application/cpl+xml":["cpl"],"application/cu-seeme":["cu"],"application/cwl":["cwl"],"application/dash+xml":["mpd"],"application/dash-patch+xml":["mpp"],"application/davmount+xml":["davmount"],"application/docbook+xml":["dbk"],"application/dssc+der":["dssc"],"application/dssc+xml":["xdssc"],"application/ecmascript":["ecma"],"application/emma+xml":["emma"],"application/emotionml+xml":["emotionml"],"application/epub+zip":["epub"],"application/exi":["exi"],"application/express":["exp"],"application/fdf":["fdf"],"application/fdt+xml":["fdt"],"application/font-tdpfr":["pfr"],"application/geo+json":["geojson"],"application/gml+xml":["gml"],"application/gpx+xml":["gpx"],"application/gxf":["gxf"],"application/gzip":["gz"],"application/hjson":["hjson"],"application/hyperstudio":["stk"],"application/inkml+xml":["ink","inkml"],"application/ipfix":["ipfix"],"application/its+xml":["its"],"application/java-archive":["jar","war","ear"],"application/java-serialized-object":["ser"],"application/java-vm":["class"],"application/javascript":["*js"],"application/json":["json","map"],"application/json5":["json5"],"application/jsonml+json":["jsonml"],"application/ld+json":["jsonld"],"application/lgr+xml":["lgr"],"application/lost+xml":["lostxml"],"application/mac-binhex40":["hqx"],"application/mac-compactpro":["cpt"],"application/mads+xml":["mads"],"application/manifest+json":["webmanifest"],"application/marc":["mrc"],"application/marcxml+xml":["mrcx"],"application/mathematica":["ma","nb","mb"],"application/mathml+xml":["mathml"],"application/mbox":["mbox"],"application/media-policy-dataset+xml":["mpf"],"application/mediaservercontrol+xml":["mscml"],"application/metalink+xml":["metalink"],"application/metalink4+xml":["meta4"],"application/mets+xml":["mets"],"application/mmt-aei+xml":["maei"],"application/mmt-usd+xml":["musd"],"application/mods+xml":["mods"],"application/mp21":["m21","mp21"],"application/mp4":["*mp4","*mpg4","mp4s","m4p"],"application/msix":["msix"],"application/msixbundle":["msixbundle"],"application/msword":["doc","dot"],"application/mxf":["mxf"],"application/n-quads":["nq"],"application/n-triples":["nt"],"application/node":["cjs"],"application/octet-stream":["bin","dms","lrf","mar","so","dist","distz","pkg","bpk","dump","elc","deploy","exe","dll","deb","dmg","iso","img","msi","msp","msm","buffer"],"application/oda":["oda"],"application/oebps-package+xml":["opf"],"application/ogg":["ogx"],"application/omdoc+xml":["omdoc"],"application/onenote":["onetoc","onetoc2","onetmp","onepkg"],"application/oxps":["oxps"],"application/p2p-overlay+xml":["relo"],"application/patch-ops-error+xml":["xer"],"application/pdf":["pdf"],"application/pgp-encrypted":["pgp"],"application/pgp-keys":["asc"],"application/pgp-signature":["sig","*asc"],"application/pics-rules":["prf"],"application/pkcs10":["p10"],"application/pkcs7-mime":["p7m","p7c"],"application/pkcs7-signature":["p7s"],"application/pkcs8":["p8"],"application/pkix-attr-cert":["ac"],"application/pkix-cert":["cer"],"application/pkix-crl":["crl"],"application/pkix-pkipath":["pkipath"],"application/pkixcmp":["pki"],"application/pls+xml":["pls"],"application/postscript":["ai","eps","ps"],"application/provenance+xml":["provx"],"application/pskc+xml":["pskcxml"],"application/raml+yaml":["raml"],"application/rdf+xml":["rdf","owl"],"application/reginfo+xml":["rif"],"application/relax-ng-compact-syntax":["rnc"],"application/resource-lists+xml":["rl"],"application/resource-lists-diff+xml":["rld"],"application/rls-services+xml":["rs"],"application/route-apd+xml":["rapd"],"application/route-s-tsid+xml":["sls"],"application/route-usd+xml":["rusd"],"application/rpki-ghostbusters":["gbr"],"application/rpki-manifest":["mft"],"application/rpki-roa":["roa"],"application/rsd+xml":["rsd"],"application/rss+xml":["rss"],"application/rtf":["rtf"],"application/sbml+xml":["sbml"],"application/scvp-cv-request":["scq"],"application/scvp-cv-response":["scs"],"application/scvp-vp-request":["spq"],"application/scvp-vp-response":["spp"],"application/sdp":["sdp"],"application/senml+xml":["senmlx"],"application/sensml+xml":["sensmlx"],"application/set-payment-initiation":["setpay"],"application/set-registration-initiation":["setreg"],"application/shf+xml":["shf"],"application/sieve":["siv","sieve"],"application/smil+xml":["smi","smil"],"application/sparql-query":["rq"],"application/sparql-results+xml":["srx"],"application/sql":["sql"],"application/srgs":["gram"],"application/srgs+xml":["grxml"],"application/sru+xml":["sru"],"application/ssdl+xml":["ssdl"],"application/ssml+xml":["ssml"],"application/swid+xml":["swidtag"],"application/tei+xml":["tei","teicorpus"],"application/thraud+xml":["tfi"],"application/timestamped-data":["tsd"],"application/toml":["toml"],"application/trig":["trig"],"application/ttml+xml":["ttml"],"application/ubjson":["ubj"],"application/urc-ressheet+xml":["rsheet"],"application/urc-targetdesc+xml":["td"],"application/voicexml+xml":["vxml"],"application/wasm":["wasm"],"application/watcherinfo+xml":["wif"],"application/widget":["wgt"],"application/winhlp":["hlp"],"application/wsdl+xml":["wsdl"],"application/wspolicy+xml":["wspolicy"],"application/xaml+xml":["xaml"],"application/xcap-att+xml":["xav"],"application/xcap-caps+xml":["xca"],"application/xcap-diff+xml":["xdf"],"application/xcap-el+xml":["xel"],"application/xcap-ns+xml":["xns"],"application/xenc+xml":["xenc"],"application/xfdf":["xfdf"],"application/xhtml+xml":["xhtml","xht"],"application/xliff+xml":["xlf"],"application/xml":["xml","xsl","xsd","rng"],"application/xml-dtd":["dtd"],"application/xop+xml":["xop"],"application/xproc+xml":["xpl"],"application/xslt+xml":["*xsl","xslt"],"application/xspf+xml":["xspf"],"application/xv+xml":["mxml","xhvml","xvml","xvm"],"application/yang":["yang"],"application/yin+xml":["yin"],"application/zip":["zip"],"audio/3gpp":["*3gpp"],"audio/aac":["adts","aac"],"audio/adpcm":["adp"],"audio/amr":["amr"],"audio/basic":["au","snd"],"audio/midi":["mid","midi","kar","rmi"],"audio/mobile-xmf":["mxmf"],"audio/mp3":["*mp3"],"audio/mp4":["m4a","mp4a"],"audio/mpeg":["mpga","mp2","mp2a","mp3","m2a","m3a"],"audio/ogg":["oga","ogg","spx","opus"],"audio/s3m":["s3m"],"audio/silk":["sil"],"audio/wav":["wav"],"audio/wave":["*wav"],"audio/webm":["weba"],"audio/xm":["xm"],"font/collection":["ttc"],"font/otf":["otf"],"font/ttf":["ttf"],"font/woff":["woff"],"font/woff2":["woff2"],"image/aces":["exr"],"image/apng":["apng"],"image/avci":["avci"],"image/avcs":["avcs"],"image/avif":["avif"],"image/bmp":["bmp","dib"],"image/cgm":["cgm"],"image/dicom-rle":["drle"],"image/dpx":["dpx"],"image/emf":["emf"],"image/fits":["fits"],"image/g3fax":["g3"],"image/gif":["gif"],"image/heic":["heic"],"image/heic-sequence":["heics"],"image/heif":["heif"],"image/heif-sequence":["heifs"],"image/hej2k":["hej2"],"image/hsj2":["hsj2"],"image/ief":["ief"],"image/jls":["jls"],"image/jp2":["jp2","jpg2"],"image/jpeg":["jpeg","jpg","jpe"],"image/jph":["jph"],"image/jphc":["jhc"],"image/jpm":["jpm","jpgm"],"image/jpx":["jpx","jpf"],"image/jxr":["jxr"],"image/jxra":["jxra"],"image/jxrs":["jxrs"],"image/jxs":["jxs"],"image/jxsc":["jxsc"],"image/jxsi":["jxsi"],"image/jxss":["jxss"],"image/ktx":["ktx"],"image/ktx2":["ktx2"],"image/png":["png"],"image/sgi":["sgi"],"image/svg+xml":["svg","svgz"],"image/t38":["t38"],"image/tiff":["tif","tiff"],"image/tiff-fx":["tfx"],"image/webp":["webp"],"image/wmf":["wmf"],"message/disposition-notification":["disposition-notification"],"message/global":["u8msg"],"message/global-delivery-status":["u8dsn"],"message/global-disposition-notification":["u8mdn"],"message/global-headers":["u8hdr"],"message/rfc822":["eml","mime"],"model/3mf":["3mf"],"model/gltf+json":["gltf"],"model/gltf-binary":["glb"],"model/iges":["igs","iges"],"model/jt":["jt"],"model/mesh":["msh","mesh","silo"],"model/mtl":["mtl"],"model/obj":["obj"],"model/prc":["prc"],"model/step+xml":["stpx"],"model/step+zip":["stpz"],"model/step-xml+zip":["stpxz"],"model/stl":["stl"],"model/u3d":["u3d"],"model/vrml":["wrl","vrml"],"model/x3d+binary":["*x3db","x3dbz"],"model/x3d+fastinfoset":["x3db"],"model/x3d+vrml":["*x3dv","x3dvz"],"model/x3d+xml":["x3d","x3dz"],"model/x3d-vrml":["x3dv"],"text/cache-manifest":["appcache","manifest"],"text/calendar":["ics","ifb"],"text/coffeescript":["coffee","litcoffee"],"text/css":["css"],"text/csv":["csv"],"text/html":["html","htm","shtml"],"text/jade":["jade"],"text/javascript":["js","mjs"],"text/jsx":["jsx"],"text/less":["less"],"text/markdown":["md","markdown"],"text/mathml":["mml"],"text/mdx":["mdx"],"text/n3":["n3"],"text/plain":["txt","text","conf","def","list","log","in","ini"],"text/richtext":["rtx"],"text/rtf":["*rtf"],"text/sgml":["sgml","sgm"],"text/shex":["shex"],"text/slim":["slim","slm"],"text/spdx":["spdx"],"text/stylus":["stylus","styl"],"text/tab-separated-values":["tsv"],"text/troff":["t","tr","roff","man","me","ms"],"text/turtle":["ttl"],"text/uri-list":["uri","uris","urls"],"text/vcard":["vcard"],"text/vtt":["vtt"],"text/wgsl":["wgsl"],"text/xml":["*xml"],"text/yaml":["yaml","yml"],"video/3gpp":["3gp","3gpp"],"video/3gpp2":["3g2"],"video/h261":["h261"],"video/h263":["h263"],"video/h264":["h264"],"video/iso.segment":["m4s"],"video/jpeg":["jpgv"],"video/jpm":["*jpm","*jpgm"],"video/mj2":["mj2","mjp2"],"video/mp2t":["ts"],"video/mp4":["mp4","mp4v","mpg4"],"video/mpeg":["mpeg","mpg","mpe","m1v","m2v"],"video/ogg":["ogv"],"video/quicktime":["qt","mov"],"video/webm":["webm"]};Object.freeze(Ne);var tt=function(i,r,s,p){if(s==="a"&&!p)throw new TypeError("Private accessor was defined without a getter");if(typeof r=="function"?i!==r||!p:!r.has(i))throw new TypeError("Cannot read private member from an object whose class did not declare it");return s==="m"?p:s==="a"?p.call(i):p?p.value:r.get(i)},mt,dt,ct;class Gr{constructor(...r){mt.set(this,new Map),dt.set(this,new Map),ct.set(this,new Map);for(const s of r)this.define(s)}define(r,s=!1){for(let[p,f]of Object.entries(r)){p=p.toLowerCase(),f=f.map(a=>a.toLowerCase()),tt(this,ct,"f").has(p)||tt(this,ct,"f").set(p,new Set);const u=tt(this,ct,"f").get(p);let l=!0;for(let a of f){const x=a.startsWith("*");if(a=x?a.slice(1):a,u==null||u.add(a),l&&tt(this,dt,"f").set(p,a),l=!1,x)continue;const g=tt(this,mt,"f").get(a);if(g&&g!=p&&!s)throw new Error(`"${p} -> ${a}" conflicts with "${g} -> ${a}". Pass \`force=true\` to override this definition.`);tt(this,mt,"f").set(a,p)}}return this}getType(r){if(typeof r!="string")return null;const s=r.replace(/^.*[/\\]/,"").toLowerCase(),p=s.replace(/^.*\./,"").toLowerCase(),f=s.length<r.length;return!(p.length<s.length-1)&&f?null:tt(this,mt,"f").get(p)??null}getExtension(r){var s;return typeof r!="string"?null:(r=(s=r==null?void 0:r.split)==null?void 0:s.call(r,";")[0],(r&&tt(this,dt,"f").get(r.trim().toLowerCase()))??null)}getAllExtensions(r){return typeof r!="string"?null:tt(this,ct,"f").get(r.toLowerCase())??null}_freeze(){this.define=()=>{throw new Error("define() not allowed for built-in Mime objects. See https://github.com/broofa/mime/blob/main/README.md#custom-mime-instances")},Object.freeze(this);for(const r of tt(this,ct,"f").values())Object.freeze(r);return this}_getTestState(){return{types:tt(this,mt,"f"),extensions:tt(this,dt,"f")}}}mt=new WeakMap,dt=new WeakMap,ct=new WeakMap;const Yr=new Gr(Ne)._freeze();function Re(i){const r=[],s=Object.keys(i);for(const p of s){const f=i[p].sort((u,l)=>u.index-l.index);for(let u=0;u<f.length;u++)f[u].index!==u&&r.push({message:`Invalid operation index ${f[u].index} at position ${u}`,details:{position:u,operation:f[u],scope:f[u].scope}})}return r}const te=async i=>{const r=new ie,{name:s,revision:p,documentType:f,created:u,lastModified:l}=i,a={name:s,revision:p,documentType:f,created:u,lastModified:l};return r.file("header.json",JSON.stringify(a,null,2)),r.file("state.json",JSON.stringify(i.initialState||{},null,2)),r.file("operations.json",JSON.stringify(i.operations,null,2)),Object.keys(i.attachments).forEach(g=>{const{data:A,...w}=i.attachments[g];r.file(g,A,{base64:!0,createFolders:!0,comment:JSON.stringify(w)})}),r},Le=async(i,r,s,p)=>{await(await te(i)).generateAsync({type:"uint8array",streamFiles:!0});const u=p??i.name,l=`.${s}.zip`;return Pr(r,u.endsWith(l)?u:`${u}${l}`)},Xr=async(i,r)=>{const p=await(await te(i)).generateAsync({type:"blob"}),f=await r.createWritable();await f.write(p),await f.close()},Nt=async(i,r)=>{const s=Be();return Pe(s,r)},Pe=async(i,r)=>{const s=new ie;return await s.loadAsync(i),Qr(s,r)};async function Qr(i,r){const s=i.file("state.json");if(!s)throw new Error("Initial state not found");const p=await s.async("string"),f=JSON.parse(p),u=i.file("header.json");let l;u&&(l=JSON.parse(await u.async("string")));const a=i.file("operations.json");if(!a)throw new Error("Operations history not found");const x=JSON.parse(await a.async("string")),g=Re(x);if(g.length){const w=g.map(b=>b.message);throw new Error(w.join(`
25
- `))}let A=Yt(f,x,r,void 0,l);return l&&(A={...A,...l}),A}function qe(i){const r=i.replace(/^.*\./,"")||void 0,s=i.replace(/^.*[/\\]/,"")||void 0;return{extension:r,fileName:s}}async function ti(i){const{buffer:r,mimeType:s="application/octet-stream"}=await qr(),p=qe(i),f=r.toString("base64");return{data:f,hash:It(f),mimeType:s,...p}}async function ei(i){const r=await Jr(),s=Yr.getType(i)||"application/octet-stream",p=qe(i),f=r.toString("base64");return{data:f,hash:It(f),mimeType:s,...p}}class ri{constructor(r,s,p){St(this,"_document");St(this,"_reducer");St(this,"_signalDispatch");this._reducer=r,this._document=s,this._signalDispatch=p}dispatch(r,s){return this._document=this._reducer(this._document,r,this._signalDispatch,s),this}saveToFile(r,s,p){return Le(this._document,r,s,p)}async loadFromFile(r){this._document=await Nt(r,this._reducer)}static async stateFromFile(r,s){return await Nt(r,s)}get state(){return xt(this._document.state)}get operations(){return xt(this._document.operations)}get name(){return this._document.name}get documentType(){return this._document.documentType}get created(){return this._document.created}get lastModified(){return this._document.lastModified}get revision(){return this._document.revision.global}getRevision(r){return this._document.revision[r]}get initialState(){return xt(this._document.initialState)}toDocument(){return xt(this._document)}getAttachment(r){return this._document.attachments[r]}setName(r){return this.dispatch($e(r)),this}undo(r){return this.dispatch(Ce(r)),this}redo(r){return this.dispatch(ze(r)),this}prune(r,s){return this.dispatch(Me(r,s)),this}loadState(r,s){return this.dispatch(Xt(r,s)),this}}function ii(i,r){r.forEach(s=>{Object.getOwnPropertyNames(s.prototype).forEach(p=>{Object.defineProperty(i.prototype,p,Object.getOwnPropertyDescriptor(s.prototype,p)||Object.create(null))})})}exports.BaseActions=Zr;exports.BaseDocument=ri;exports.applyMixins=ii;exports.baseReducer=Vt;exports.calculateSkipsLeft=De;exports.createAction=lt;exports.createDocument=Te;exports.createExtendedState=Ie;exports.createReducer=je;exports.createZip=te;exports.getLocalFile=ei;exports.getRemoteFile=ti;exports.hashDocument=Gt;exports.hashKey=Vr;exports.isBaseAction=Mt;exports.isNoopOperation=Oe;exports.isSameDocument=Hr;exports.isUndoRedo=zt;exports.loadFromFile=Nt;exports.loadFromInput=Pe;exports.mapSkippedOperations=ke;exports.processUndoRedo=we;exports.readOnly=xt;exports.replayDocument=Yt;exports.replayOperations=Ft;exports.saveToFile=Le;exports.saveToFileHandle=Xr;exports.sortMappedOperations=Ue;exports.sortOperations=Kr;exports.validateOperations=Re;exports.zod=Xe;
@@ -1,20 +0,0 @@
1
- "use strict";var se=Object.defineProperty;var ae=(e,t,i)=>t in e?se(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i;var ot=(e,t,i)=>(ae(e,typeof t!="symbol"?t+"":t,i),i);const C=require("immer"),m=require("zod"),pe=require("crypto"),ct=require("fs"),ce=require("https"),le=require("path"),zt=require("jszip"),vt=e=>e!=null,me=m.z.any().refine(e=>vt(e)),Et=m.z.enum(["LOAD_STATE"]),Tt=m.z.enum(["PRUNE"]),_t=m.z.enum(["REDO"]),kt=m.z.enum(["SET_NAME"]),Dt=m.z.enum(["UNDO"]);function ue(){return m.z.object({__typename:m.z.literal("Action").optional(),type:m.z.string()})}function X(){return m.z.literal("global").or(m.z.literal("local"))}function At(){return m.z.union([Nt(),Ft(),It(),Pt(),Rt()])}function fe(){return m.z.object({__typename:m.z.literal("DocumentFile").optional(),data:m.z.string(),extension:m.z.string().nullable(),fileName:m.z.string().nullable(),mimeType:m.z.string()})}function Nt(){return m.z.object({input:m.z.lazy(()=>dt()),type:Et,scope:X()})}function dt(){return m.z.object({operations:m.z.number(),state:m.z.lazy(()=>Mt())})}function Mt(){return m.z.object({data:m.z.unknown().nullish(),name:m.z.string()})}function de(){return m.z.object({__typename:m.z.literal("Operation").optional(),hash:m.z.string(),index:m.z.number(),timestamp:m.z.string().datetime(),type:m.z.string()})}function Ft(){return m.z.object({input:m.z.lazy(()=>gt()),type:Tt,scope:X()})}function gt(){return m.z.object({end:m.z.number().nullish(),start:m.z.number().nullish()})}const ht=m.z.number;function It(){return m.z.object({input:ht(),type:_t,scope:X()})}const xt=m.z.string;function Pt(){return m.z.object({input:xt(),type:kt,scope:m.z.literal("global")})}function ge(){return m.z.object({__typename:m.z.literal("SetNameOperation").optional(),hash:m.z.string(),index:m.z.number(),input:m.z.string(),timestamp:m.z.string().datetime(),type:m.z.string()})}const bt=m.z.number;function Rt(){return m.z.object({input:bt(),type:Dt,scope:X()})}const he=Object.freeze(Object.defineProperty({__proto__:null,ActionSchema:ue,BaseActionSchema:At,DocumentFileSchema:fe,LoadStateActionInputSchema:dt,LoadStateActionSchema:Nt,LoadStateActionStateInputSchema:Mt,Load_StateSchema:Et,OperationSchema:de,OperationScopeSchema:X,PruneActionInputSchema:gt,PruneActionSchema:Ft,PruneSchema:Tt,RedoActionInputSchema:ht,RedoActionSchema:It,RedoSchema:_t,SetNameActionInputSchema:xt,SetNameActionSchema:Pt,SetNameOperationSchema:ge,Set_NameSchema:kt,UndoActionInputSchema:bt,UndoActionSchema:Rt,UndoSchema:Dt,definedNonNullAnySchema:me,isDefinedNonNullAny:vt},Symbol.toStringTag,{value:"Module"}));function xe(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var lt={exports:{}};(function(e,t){const{hasOwnProperty:i}=Object.prototype,n=J();n.configure=J,n.stringify=n,n.default=n,t.stringify=n,t.configure=J,e.exports=n;const s=/[\u0000-\u001f\u0022\u005c\ud800-\udfff]|[\ud800-\udbff](?![\udc00-\udfff])|(?:[^\ud800-\udbff]|^)[\udc00-\udfff]/;function a(c){return c.length<5e3&&!s.test(c)?`"${c}"`:JSON.stringify(c)}function r(c){if(c.length>200)return c.sort();for(let l=1;l<c.length;l++){const j=c[l];let A=l;for(;A!==0&&c[A-1]>j;)c[A]=c[A-1],A--;c[A]=j}return c}const p=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Object.getPrototypeOf(new Int8Array)),Symbol.toStringTag).get;function d(c){return p.call(c)!==void 0&&c.length!==0}function f(c,l,j){c.length<j&&(j=c.length);const A=l===","?"":" ";let B=`"0":${A}${c[0]}`;for(let I=1;I<j;I++)B+=`${l}"${I}":${A}${c[I]}`;return B}function k(c){if(i.call(c,"circularValue")){const l=c.circularValue;if(typeof l=="string")return`"${l}"`;if(l==null)return l;if(l===Error||l===TypeError)return{toString(){throw new TypeError("Converting circular structure to JSON")}};throw new TypeError('The "circularValue" argument must be of type string or the value null or undefined')}return'"[Circular]"'}function b(c,l){let j;if(i.call(c,l)&&(j=c[l],typeof j!="boolean"))throw new TypeError(`The "${l}" argument must be of type boolean`);return j===void 0?!0:j}function h(c,l){let j;if(i.call(c,l)){if(j=c[l],typeof j!="number")throw new TypeError(`The "${l}" argument must be of type number`);if(!Number.isInteger(j))throw new TypeError(`The "${l}" argument must be an integer`);if(j<1)throw new RangeError(`The "${l}" argument must be >= 1`)}return j===void 0?1/0:j}function $(c){return c===1?"1 item":`${c} items`}function O(c){const l=new Set;for(const j of c)(typeof j=="string"||typeof j=="number")&&l.add(String(j));return l}function U(c){if(i.call(c,"strict")){const l=c.strict;if(typeof l!="boolean")throw new TypeError('The "strict" argument must be of type boolean');if(l)return j=>{let A=`Object can not safely be stringified. Received type ${typeof j}`;throw typeof j!="function"&&(A+=` (${j.toString()})`),new Error(A)}}}function J(c){c={...c};const l=U(c);l&&(c.bigint===void 0&&(c.bigint=!1),"circularValue"in c||(c.circularValue=Error));const j=k(c),A=b(c,"bigint"),B=b(c,"deterministic"),I=h(c,"maximumDepth"),E=h(c,"maximumBreadth");function et(N,o,u,y,x,S){let g=o[N];switch(typeof g=="object"&&g!==null&&typeof g.toJSON=="function"&&(g=g.toJSON(N)),g=y.call(o,N,g),typeof g){case"string":return a(g);case"object":{if(g===null)return"null";if(u.indexOf(g)!==-1)return j;let w="",v=",";const T=S;if(Array.isArray(g)){if(g.length===0)return"[]";if(I<u.length+1)return'"[Array]"';u.push(g),x!==""&&(S+=x,w+=`
2
- ${S}`,v=`,
3
- ${S}`);const F=Math.min(g.length,E);let q=0;for(;q<F-1;q++){const nt=et(String(q),g,u,y,x,S);w+=nt!==void 0?nt:"null",w+=v}const L=et(String(q),g,u,y,x,S);if(w+=L!==void 0?L:"null",g.length-1>E){const nt=g.length-E-1;w+=`${v}"... ${$(nt)} not stringified"`}return x!==""&&(w+=`
4
- ${T}`),u.pop(),`[${w}]`}let _=Object.keys(g);const D=_.length;if(D===0)return"{}";if(I<u.length+1)return'"[Object]"';let z="",M="";x!==""&&(S+=x,v=`,
5
- ${S}`,z=" ");const R=Math.min(D,E);B&&!d(g)&&(_=r(_)),u.push(g);for(let F=0;F<R;F++){const q=_[F],L=et(q,g,u,y,x,S);L!==void 0&&(w+=`${M}${a(q)}:${z}${L}`,M=v)}if(D>E){const F=D-E;w+=`${M}"...":${z}"${$(F)} not stringified"`,M=v}return x!==""&&M.length>1&&(w=`
6
- ${S}${w}
7
- ${T}`),u.pop(),`{${w}}`}case"number":return isFinite(g)?String(g):l?l(g):"null";case"boolean":return g===!0?"true":"false";case"undefined":return;case"bigint":if(A)return String(g);default:return l?l(g):void 0}}function it(N,o,u,y,x,S){switch(typeof o=="object"&&o!==null&&typeof o.toJSON=="function"&&(o=o.toJSON(N)),typeof o){case"string":return a(o);case"object":{if(o===null)return"null";if(u.indexOf(o)!==-1)return j;const g=S;let w="",v=",";if(Array.isArray(o)){if(o.length===0)return"[]";if(I<u.length+1)return'"[Array]"';u.push(o),x!==""&&(S+=x,w+=`
8
- ${S}`,v=`,
9
- ${S}`);const D=Math.min(o.length,E);let z=0;for(;z<D-1;z++){const R=it(String(z),o[z],u,y,x,S);w+=R!==void 0?R:"null",w+=v}const M=it(String(z),o[z],u,y,x,S);if(w+=M!==void 0?M:"null",o.length-1>E){const R=o.length-E-1;w+=`${v}"... ${$(R)} not stringified"`}return x!==""&&(w+=`
10
- ${g}`),u.pop(),`[${w}]`}u.push(o);let T="";x!==""&&(S+=x,v=`,
11
- ${S}`,T=" ");let _="";for(const D of y){const z=it(D,o[D],u,y,x,S);z!==void 0&&(w+=`${_}${a(D)}:${T}${z}`,_=v)}return x!==""&&_.length>1&&(w=`
12
- ${S}${w}
13
- ${g}`),u.pop(),`{${w}}`}case"number":return isFinite(o)?String(o):l?l(o):"null";case"boolean":return o===!0?"true":"false";case"undefined":return;case"bigint":if(A)return String(o);default:return l?l(o):void 0}}function Z(N,o,u,y,x){switch(typeof o){case"string":return a(o);case"object":{if(o===null)return"null";if(typeof o.toJSON=="function"){if(o=o.toJSON(N),typeof o!="object")return Z(N,o,u,y,x);if(o===null)return"null"}if(u.indexOf(o)!==-1)return j;const S=x;if(Array.isArray(o)){if(o.length===0)return"[]";if(I<u.length+1)return'"[Array]"';u.push(o),x+=y;let z=`
14
- ${x}`;const M=`,
15
- ${x}`,R=Math.min(o.length,E);let F=0;for(;F<R-1;F++){const L=Z(String(F),o[F],u,y,x);z+=L!==void 0?L:"null",z+=M}const q=Z(String(F),o[F],u,y,x);if(z+=q!==void 0?q:"null",o.length-1>E){const L=o.length-E-1;z+=`${M}"... ${$(L)} not stringified"`}return z+=`
16
- ${S}`,u.pop(),`[${z}]`}let g=Object.keys(o);const w=g.length;if(w===0)return"{}";if(I<u.length+1)return'"[Object]"';x+=y;const v=`,
17
- ${x}`;let T="",_="",D=Math.min(w,E);d(o)&&(T+=f(o,v,E),g=g.slice(o.length),D-=o.length,_=v),B&&(g=r(g)),u.push(o);for(let z=0;z<D;z++){const M=g[z],R=Z(M,o[M],u,y,x);R!==void 0&&(T+=`${_}${a(M)}: ${R}`,_=v)}if(w>E){const z=w-E;T+=`${_}"...": "${$(z)} not stringified"`,_=v}return _!==""&&(T=`
18
- ${x}${T}
19
- ${S}`),u.pop(),`{${T}}`}case"number":return isFinite(o)?String(o):l?l(o):"null";case"boolean":return o===!0?"true":"false";case"undefined":return;case"bigint":if(A)return String(o);default:return l?l(o):void 0}}function H(N,o,u){switch(typeof o){case"string":return a(o);case"object":{if(o===null)return"null";if(typeof o.toJSON=="function"){if(o=o.toJSON(N),typeof o!="object")return H(N,o,u);if(o===null)return"null"}if(u.indexOf(o)!==-1)return j;let y="";if(Array.isArray(o)){if(o.length===0)return"[]";if(I<u.length+1)return'"[Array]"';u.push(o);const v=Math.min(o.length,E);let T=0;for(;T<v-1;T++){const D=H(String(T),o[T],u);y+=D!==void 0?D:"null",y+=","}const _=H(String(T),o[T],u);if(y+=_!==void 0?_:"null",o.length-1>E){const D=o.length-E-1;y+=`,"... ${$(D)} not stringified"`}return u.pop(),`[${y}]`}let x=Object.keys(o);const S=x.length;if(S===0)return"{}";if(I<u.length+1)return'"[Object]"';let g="",w=Math.min(S,E);d(o)&&(y+=f(o,",",E),x=x.slice(o.length),w-=o.length,g=","),B&&(x=r(x)),u.push(o);for(let v=0;v<w;v++){const T=x[v],_=H(T,o[T],u);_!==void 0&&(y+=`${g}${a(T)}:${_}`,g=",")}if(S>E){const v=S-E;y+=`${g}"...":"${$(v)} not stringified"`}return u.pop(),`{${y}}`}case"number":return isFinite(o)?String(o):l?l(o):"null";case"boolean":return o===!0?"true":"false";case"undefined":return;case"bigint":if(A)return String(o);default:return l?l(o):void 0}}function re(N,o,u){if(arguments.length>1){let y="";if(typeof u=="number"?y=" ".repeat(Math.min(u,10)):typeof u=="string"&&(y=u.slice(0,10)),o!=null){if(typeof o=="function")return et("",{"":N},[],o,y,"");if(Array.isArray(o))return it("",N,[],O(o),y,"")}if(y.length!==0)return Z("",N,[],y,"")}return H("",N,[])}return re}})(lt,lt.exports);var be=lt.exports;const rt=xe(be);rt.configure;function ye(e,t){return{...e,name:t}}function we(e,t,i){const n={skip:i,document:e},{scope:s}=t;return!s||t.skip===void 0?n:C.produce(n,a=>{const[r]=a.document.operations[s].slice(-1);t.skip&&t.skip>0&&(a.skip=t.skip),r.type==="NOOP"&&t.index===r.index&&a.skip>r.skip&&a.document.operations[s].pop()})}function je(e,t,i){const{scope:n,input:s}=t,a={document:e,action:t,skip:i};return C.produce(a,r=>{if(r.document.operations[n].length<1)throw new Error(`Cannot undo: no operations in history for scope "${n}"`);if(s<1)throw new Error("Invalid UNDO action: input value must be greater than 0");if(r.skip>0)throw new Error("Cannot undo: skip value from reducer cannot be used with UNDO action");const[p]=r.document.operations[n].slice(-1),d=p.type==="NOOP"&&p.skip>0;if(r.skip+=s,d){r.skip+=p.skip;const h=r.document.operations[n][r.document.operations[n].length-2];h&&p.index-h.index===1&&r.document.operations[n].pop()}if(r.document.operations[n].length<r.skip)throw new Error("Cannot undo: you can't undo more operations than the ones in the scope history");const f=r.document.operations[n].length-1;let k=s,b=d?f-p.skip:f;for(;k>0&&b>=0;){const h=r.document.operations[n][b];if(!h){k--,b--;continue}h.type==="NOOP"&&h.skip>0?(b=b-(h.skip+1),r.skip+=h.skip+1):(r.document.clipboard.push({...h}),k--,b--)}r.action=St(n)})}function Oe(e,t,i){const{scope:n,input:s}=t,a={document:e,action:t,skip:i};return C.produce(a,r=>{if(r.skip>0)throw new Error("Cannot redo: skip value from reducer cannot be used with REDO action");if(s>1)throw new Error("Cannot redo: you can only redo one operation at a time");if(s<1)throw new Error("Invalid REDO action: invalid redo input value");if(r.document.clipboard.length<1)throw new Error("Cannot redo: no operations in the clipboard");const p=r.document.clipboard.findLastIndex(f=>f.scope===n);if(p<0)throw new Error(`Cannot redo: no operations in clipboard for scope "${n}"`);const d=r.document.clipboard.splice(p,1)[0];r.action=C.castDraft({type:d.type,scope:d.scope,input:d.input})})}function Se(e,t,i){const{scope:n}=t,s=e.operations[n];let{input:{start:a,end:r}}=t;a=a||0,r=r||s.length;const p=s.slice(a,r),d=s.slice(0,a),f=s.slice(r),k=st(e.initialState,{...e.operations,[n]:d.concat(p)},i),{name:b,state:h}=k,$=d.length,O=d.length?d[d.length-1].timestamp:f.length?f[0].timestamp:new Date().toISOString();return st(e.initialState,{...e.operations,[n]:[...d,{...Ot({name:b,state:h},p.length),timestamp:O,index:$,hash:wt({state:h},"global")},...f.map((U,J)=>({...U,index:$+J+1}))]},i)}function $e(e,t){return{...e,name:t.name,state:t.state??{global:{},local:{}}}}const qt="SET_NAME",Y="UNDO",tt="REDO",at="PRUNE",Lt="LOAD_STATE",ze="NOOP";function ve(e,t){let i;return"index"in t?i={...t}:i=e.operations[t.scope].slice(-1)[0],((i==null?void 0:i.index)??-1)+1}function Ee(e,t){return{...e,revision:{...e.revision,[t.scope]:ve(e,t)},lastModified:new Date().toISOString()}}function Te(e,t,i=0){if([Y,tt,at].includes(t.type))return e;const{scope:n}=t,s=e.operations[n].slice(0,e.revision[n]),a=[...s].pop();let r=((a==null?void 0:a.index)??-1)+1;if("index"in t){if(t.index>r+i)throw new Error(`Missing operations: expected ${r} with skip 0 or equivalent, got index ${t.index} with skip ${i}`);r=t.index}return s.push({...t,index:r,timestamp:new Date().toISOString(),hash:"",scope:n,skip:i}),{...e,operations:{...e.operations,[n]:s}}}function _e(e,t,i=0){let n=Te(e,t,i);return n=Ee(n,t),n}function ke(e,t,i){switch(At().parse(t),t.type){case qt:return ye(e,t.input);case at:return Se(e,t,i);case Lt:return $e(e,t.input.state);default:return e}}function Ct(e,t,i){switch(t.type){case Y:return je(e,t,i);case tt:return Oe(e,t,i);default:return{document:e,action:t,skip:i}}}function yt(e,t,i,n,s={}){const{skip:a,ignoreSkipOperations:r=!1}=s;let p={...t},d=a||0,f=e,k=[...e.clipboard];if(Ut(p)){const{document:b,skip:h}=we(f,p,d);d=h,f=b}if(mt(p)){const{skip:b,action:h,document:$}=Ct(e,p,d);p=h,d=b,f=$,k=[...f.clipboard]}if(ut(p)&&(f=ke(f,p,i)),d>0&&!r){let b=d;"index"in p&&(b=Zt(f.operations[p.scope],p.index,d)),f=st(f.initialState,f.operations,i,void 0,void 0,void 0,{[p.scope]:b})}return f=_e(f,p,d),f=C.produce(f,b=>{const h=i(b.state,p,n),$=mt(t)?[...k]:[];if(h)return C.castDraft({...f,clipboard:[...$],state:h});b.clipboard=C.castDraft([...$])}),C.produce(f,b=>{if([Y,tt,at].includes(p.type))return b;const h=p.scope||"global";b.operations[h][b.operations[h].length-1].hash=wt(b,h),!ut(p)&&p.attachments&&p.attachments.forEach($=>{const{hash:O,...U}=$;b.attachments[O]={...U}})})}function De(e,t,i){const n=le.join(e,t);return ct.mkdirSync(e,{recursive:!0}),new Promise((s,a)=>{try{ct.writeFile(n,i,{},r=>{r?a(r):s(n)})}catch(r){a(r)}})}function Jt(e){return ct.readFileSync(e)}function Ae(e){return new Promise((t,i)=>{ce.get(e,n=>{const s=[],a=n.headers["content-type"];n.on("data",r=>{s.push(r)}),n.on("end",()=>{t({buffer:Buffer.concat(s),mimeType:a})})}).on("error",n=>{i(n)})})}const Ne=async e=>Jt(e),pt=(e,t="sha1")=>pe.createHash(t).update(e).digest("base64");function Ut(e){return e.type===ze&&e.skip!==void 0&&e.skip>0&&e.hash!==void 0}function mt(e){return[Y,tt].includes(e.type)}function ut(e){return[qt,Y,tt,at,Lt].includes(e.type)}function K(e,t,i,n,s="global"){if(!e)throw new Error("Empty action type");if(typeof e!="string")throw new Error(`Invalid action type: ${e}`);const a={type:e,input:t,scope:s};i&&(a.attachments=i);try{n==null||n().parse(a.input)}catch(r){throw new Error(`Invalid action input: ${r}`)}return a}function Vt(e,t=yt){return(i,n,s,a)=>t(i,n,e,s,a)}const Kt=(e,t)=>({name:"",documentType:"",revision:{global:0,local:0},created:new Date().toISOString(),lastModified:new Date().toISOString(),attachments:{},...e,state:(t==null?void 0:t(e==null?void 0:e.state))??(e==null?void 0:e.state)??{global:{},local:{}}}),Bt=(e,t)=>{const i=Kt(e,t);return{...i,initialState:i,operations:{global:[],local:[]},clipboard:[]}},wt=(e,t="global")=>pt(rt(e.state[t]||"")),Me=(e,t=1e3)=>{const i=Math.random()*t;return pt(`${(e??new Date).toISOString()}${i}`)};function G(e){return C.castImmutable(C.freeze(e,!0))}function Wt(e,t){const i=[...e];let n=t||0,s=i.length>0?i[i.length-1].index:0;const a=[];for(const r of i.reverse()){if(n>0){const f=s-r.index;n-=f}if(n<0)throw new Error("Invalid operation index, missing operations");const p={ignore:n>0,operation:r},d=r.skip>0?r.skip+1:0;if(d>0&&d>n){const f=d-n;n=n+f}s=r.index,a.push(p)}return a.reverse()}function Zt(e,t,i){const n=e.slice().sort((p,d)=>p.skip-d.skip).sort((p,d)=>p.index-d.index);let s=i,a=0,r=t;for(const p of n.reverse()){const d=r-p.index;if(s=s-d,s>-1)a++,r=p.index;else break}return a}function Fe(e){return Object.values(e).flatMap(t=>t).sort((t,i)=>new Date(t.timestamp).getTime()-new Date(i.timestamp).getTime())}function Ht(e){return Object.values(e).flatMap(t=>t).sort((t,i)=>new Date(t.operation.timestamp).getTime()-new Date(i.operation.timestamp).getTime())}function st(e,t,i,n,s,a=yt,r={}){const p=Vt(i,a);return jt(e,t,p,n,s,r)}function jt(e,t,i,n,s,a={}){const r=Bt(e),p=Object.keys(t).reduce((h,$)=>{const O=$;return{...h,[O]:t[O].slice(0,s==null?void 0:s.revision[O])}},{}),d=Object.keys(p).reduce((h,$)=>{const O=$;return{...h,[O]:Wt(p[O],a[O])}},{}),f=Ht(d).reduce((h,{ignore:$,operation:O})=>$?i(h,St(O.scope),n,{skip:O.skip,ignoreSkipOperations:!0}):i(h,O,n,{skip:O.skip,ignoreSkipOperations:!0}),r),k=Object.keys(f.operations).reduce((h,$)=>{const O=$,U=s&&s.revision[O]<t[O].length?t[O].slice(s.revision[O]):[];return{...h,[O]:[...f.operations[O].map((J,c)=>{var l;return{...J,timestamp:((l=t[O][c])==null?void 0:l.timestamp)??J.timestamp}}),...U]}},{global:[],local:[]}),b=Object.values(k).reduce((h,$)=>{for(const O of $)O.timestamp>h&&(h=O.timestamp);return h},e.lastModified);return{...f,operations:k,lastModified:b}}function Ie(e,t){return rt(e)===rt(t)}const Gt=e=>K("SET_NAME",e,void 0,xt,void 0),Qt=(e=1,t="global")=>K("UNDO",e,void 0,bt,t),Xt=(e=1,t="global")=>K("REDO",e,void 0,ht,t),Yt=(e,t,i="global")=>K("PRUNE",{start:e,end:t},void 0,gt,i),Ot=(e,t)=>K("LOAD_STATE",{state:e,operations:t},void 0,dt),St=(e="global")=>K("NOOP",{},void 0,void 0,e),Pe=Object.freeze(Object.defineProperty({__proto__:null,loadState:Ot,noop:St,prune:Yt,redo:Xt,setName:Gt,undo:Qt},Symbol.toStringTag,{value:"Module"})),te={"application/andrew-inset":["ez"],"application/appinstaller":["appinstaller"],"application/applixware":["aw"],"application/appx":["appx"],"application/appxbundle":["appxbundle"],"application/atom+xml":["atom"],"application/atomcat+xml":["atomcat"],"application/atomdeleted+xml":["atomdeleted"],"application/atomsvc+xml":["atomsvc"],"application/atsc-dwd+xml":["dwd"],"application/atsc-held+xml":["held"],"application/atsc-rsat+xml":["rsat"],"application/automationml-aml+xml":["aml"],"application/automationml-amlx+zip":["amlx"],"application/bdoc":["bdoc"],"application/calendar+xml":["xcs"],"application/ccxml+xml":["ccxml"],"application/cdfx+xml":["cdfx"],"application/cdmi-capability":["cdmia"],"application/cdmi-container":["cdmic"],"application/cdmi-domain":["cdmid"],"application/cdmi-object":["cdmio"],"application/cdmi-queue":["cdmiq"],"application/cpl+xml":["cpl"],"application/cu-seeme":["cu"],"application/cwl":["cwl"],"application/dash+xml":["mpd"],"application/dash-patch+xml":["mpp"],"application/davmount+xml":["davmount"],"application/docbook+xml":["dbk"],"application/dssc+der":["dssc"],"application/dssc+xml":["xdssc"],"application/ecmascript":["ecma"],"application/emma+xml":["emma"],"application/emotionml+xml":["emotionml"],"application/epub+zip":["epub"],"application/exi":["exi"],"application/express":["exp"],"application/fdf":["fdf"],"application/fdt+xml":["fdt"],"application/font-tdpfr":["pfr"],"application/geo+json":["geojson"],"application/gml+xml":["gml"],"application/gpx+xml":["gpx"],"application/gxf":["gxf"],"application/gzip":["gz"],"application/hjson":["hjson"],"application/hyperstudio":["stk"],"application/inkml+xml":["ink","inkml"],"application/ipfix":["ipfix"],"application/its+xml":["its"],"application/java-archive":["jar","war","ear"],"application/java-serialized-object":["ser"],"application/java-vm":["class"],"application/javascript":["*js"],"application/json":["json","map"],"application/json5":["json5"],"application/jsonml+json":["jsonml"],"application/ld+json":["jsonld"],"application/lgr+xml":["lgr"],"application/lost+xml":["lostxml"],"application/mac-binhex40":["hqx"],"application/mac-compactpro":["cpt"],"application/mads+xml":["mads"],"application/manifest+json":["webmanifest"],"application/marc":["mrc"],"application/marcxml+xml":["mrcx"],"application/mathematica":["ma","nb","mb"],"application/mathml+xml":["mathml"],"application/mbox":["mbox"],"application/media-policy-dataset+xml":["mpf"],"application/mediaservercontrol+xml":["mscml"],"application/metalink+xml":["metalink"],"application/metalink4+xml":["meta4"],"application/mets+xml":["mets"],"application/mmt-aei+xml":["maei"],"application/mmt-usd+xml":["musd"],"application/mods+xml":["mods"],"application/mp21":["m21","mp21"],"application/mp4":["*mp4","*mpg4","mp4s","m4p"],"application/msix":["msix"],"application/msixbundle":["msixbundle"],"application/msword":["doc","dot"],"application/mxf":["mxf"],"application/n-quads":["nq"],"application/n-triples":["nt"],"application/node":["cjs"],"application/octet-stream":["bin","dms","lrf","mar","so","dist","distz","pkg","bpk","dump","elc","deploy","exe","dll","deb","dmg","iso","img","msi","msp","msm","buffer"],"application/oda":["oda"],"application/oebps-package+xml":["opf"],"application/ogg":["ogx"],"application/omdoc+xml":["omdoc"],"application/onenote":["onetoc","onetoc2","onetmp","onepkg"],"application/oxps":["oxps"],"application/p2p-overlay+xml":["relo"],"application/patch-ops-error+xml":["xer"],"application/pdf":["pdf"],"application/pgp-encrypted":["pgp"],"application/pgp-keys":["asc"],"application/pgp-signature":["sig","*asc"],"application/pics-rules":["prf"],"application/pkcs10":["p10"],"application/pkcs7-mime":["p7m","p7c"],"application/pkcs7-signature":["p7s"],"application/pkcs8":["p8"],"application/pkix-attr-cert":["ac"],"application/pkix-cert":["cer"],"application/pkix-crl":["crl"],"application/pkix-pkipath":["pkipath"],"application/pkixcmp":["pki"],"application/pls+xml":["pls"],"application/postscript":["ai","eps","ps"],"application/provenance+xml":["provx"],"application/pskc+xml":["pskcxml"],"application/raml+yaml":["raml"],"application/rdf+xml":["rdf","owl"],"application/reginfo+xml":["rif"],"application/relax-ng-compact-syntax":["rnc"],"application/resource-lists+xml":["rl"],"application/resource-lists-diff+xml":["rld"],"application/rls-services+xml":["rs"],"application/route-apd+xml":["rapd"],"application/route-s-tsid+xml":["sls"],"application/route-usd+xml":["rusd"],"application/rpki-ghostbusters":["gbr"],"application/rpki-manifest":["mft"],"application/rpki-roa":["roa"],"application/rsd+xml":["rsd"],"application/rss+xml":["rss"],"application/rtf":["rtf"],"application/sbml+xml":["sbml"],"application/scvp-cv-request":["scq"],"application/scvp-cv-response":["scs"],"application/scvp-vp-request":["spq"],"application/scvp-vp-response":["spp"],"application/sdp":["sdp"],"application/senml+xml":["senmlx"],"application/sensml+xml":["sensmlx"],"application/set-payment-initiation":["setpay"],"application/set-registration-initiation":["setreg"],"application/shf+xml":["shf"],"application/sieve":["siv","sieve"],"application/smil+xml":["smi","smil"],"application/sparql-query":["rq"],"application/sparql-results+xml":["srx"],"application/sql":["sql"],"application/srgs":["gram"],"application/srgs+xml":["grxml"],"application/sru+xml":["sru"],"application/ssdl+xml":["ssdl"],"application/ssml+xml":["ssml"],"application/swid+xml":["swidtag"],"application/tei+xml":["tei","teicorpus"],"application/thraud+xml":["tfi"],"application/timestamped-data":["tsd"],"application/toml":["toml"],"application/trig":["trig"],"application/ttml+xml":["ttml"],"application/ubjson":["ubj"],"application/urc-ressheet+xml":["rsheet"],"application/urc-targetdesc+xml":["td"],"application/voicexml+xml":["vxml"],"application/wasm":["wasm"],"application/watcherinfo+xml":["wif"],"application/widget":["wgt"],"application/winhlp":["hlp"],"application/wsdl+xml":["wsdl"],"application/wspolicy+xml":["wspolicy"],"application/xaml+xml":["xaml"],"application/xcap-att+xml":["xav"],"application/xcap-caps+xml":["xca"],"application/xcap-diff+xml":["xdf"],"application/xcap-el+xml":["xel"],"application/xcap-ns+xml":["xns"],"application/xenc+xml":["xenc"],"application/xfdf":["xfdf"],"application/xhtml+xml":["xhtml","xht"],"application/xliff+xml":["xlf"],"application/xml":["xml","xsl","xsd","rng"],"application/xml-dtd":["dtd"],"application/xop+xml":["xop"],"application/xproc+xml":["xpl"],"application/xslt+xml":["*xsl","xslt"],"application/xspf+xml":["xspf"],"application/xv+xml":["mxml","xhvml","xvml","xvm"],"application/yang":["yang"],"application/yin+xml":["yin"],"application/zip":["zip"],"audio/3gpp":["*3gpp"],"audio/aac":["adts","aac"],"audio/adpcm":["adp"],"audio/amr":["amr"],"audio/basic":["au","snd"],"audio/midi":["mid","midi","kar","rmi"],"audio/mobile-xmf":["mxmf"],"audio/mp3":["*mp3"],"audio/mp4":["m4a","mp4a"],"audio/mpeg":["mpga","mp2","mp2a","mp3","m2a","m3a"],"audio/ogg":["oga","ogg","spx","opus"],"audio/s3m":["s3m"],"audio/silk":["sil"],"audio/wav":["wav"],"audio/wave":["*wav"],"audio/webm":["weba"],"audio/xm":["xm"],"font/collection":["ttc"],"font/otf":["otf"],"font/ttf":["ttf"],"font/woff":["woff"],"font/woff2":["woff2"],"image/aces":["exr"],"image/apng":["apng"],"image/avci":["avci"],"image/avcs":["avcs"],"image/avif":["avif"],"image/bmp":["bmp","dib"],"image/cgm":["cgm"],"image/dicom-rle":["drle"],"image/dpx":["dpx"],"image/emf":["emf"],"image/fits":["fits"],"image/g3fax":["g3"],"image/gif":["gif"],"image/heic":["heic"],"image/heic-sequence":["heics"],"image/heif":["heif"],"image/heif-sequence":["heifs"],"image/hej2k":["hej2"],"image/hsj2":["hsj2"],"image/ief":["ief"],"image/jls":["jls"],"image/jp2":["jp2","jpg2"],"image/jpeg":["jpeg","jpg","jpe"],"image/jph":["jph"],"image/jphc":["jhc"],"image/jpm":["jpm","jpgm"],"image/jpx":["jpx","jpf"],"image/jxr":["jxr"],"image/jxra":["jxra"],"image/jxrs":["jxrs"],"image/jxs":["jxs"],"image/jxsc":["jxsc"],"image/jxsi":["jxsi"],"image/jxss":["jxss"],"image/ktx":["ktx"],"image/ktx2":["ktx2"],"image/png":["png"],"image/sgi":["sgi"],"image/svg+xml":["svg","svgz"],"image/t38":["t38"],"image/tiff":["tif","tiff"],"image/tiff-fx":["tfx"],"image/webp":["webp"],"image/wmf":["wmf"],"message/disposition-notification":["disposition-notification"],"message/global":["u8msg"],"message/global-delivery-status":["u8dsn"],"message/global-disposition-notification":["u8mdn"],"message/global-headers":["u8hdr"],"message/rfc822":["eml","mime"],"model/3mf":["3mf"],"model/gltf+json":["gltf"],"model/gltf-binary":["glb"],"model/iges":["igs","iges"],"model/jt":["jt"],"model/mesh":["msh","mesh","silo"],"model/mtl":["mtl"],"model/obj":["obj"],"model/prc":["prc"],"model/step+xml":["stpx"],"model/step+zip":["stpz"],"model/step-xml+zip":["stpxz"],"model/stl":["stl"],"model/u3d":["u3d"],"model/vrml":["wrl","vrml"],"model/x3d+binary":["*x3db","x3dbz"],"model/x3d+fastinfoset":["x3db"],"model/x3d+vrml":["*x3dv","x3dvz"],"model/x3d+xml":["x3d","x3dz"],"model/x3d-vrml":["x3dv"],"text/cache-manifest":["appcache","manifest"],"text/calendar":["ics","ifb"],"text/coffeescript":["coffee","litcoffee"],"text/css":["css"],"text/csv":["csv"],"text/html":["html","htm","shtml"],"text/jade":["jade"],"text/javascript":["js","mjs"],"text/jsx":["jsx"],"text/less":["less"],"text/markdown":["md","markdown"],"text/mathml":["mml"],"text/mdx":["mdx"],"text/n3":["n3"],"text/plain":["txt","text","conf","def","list","log","in","ini"],"text/richtext":["rtx"],"text/rtf":["*rtf"],"text/sgml":["sgml","sgm"],"text/shex":["shex"],"text/slim":["slim","slm"],"text/spdx":["spdx"],"text/stylus":["stylus","styl"],"text/tab-separated-values":["tsv"],"text/troff":["t","tr","roff","man","me","ms"],"text/turtle":["ttl"],"text/uri-list":["uri","uris","urls"],"text/vcard":["vcard"],"text/vtt":["vtt"],"text/wgsl":["wgsl"],"text/xml":["*xml"],"text/yaml":["yaml","yml"],"video/3gpp":["3gp","3gpp"],"video/3gpp2":["3g2"],"video/h261":["h261"],"video/h263":["h263"],"video/h264":["h264"],"video/iso.segment":["m4s"],"video/jpeg":["jpgv"],"video/jpm":["*jpm","*jpgm"],"video/mj2":["mj2","mjp2"],"video/mp2t":["ts"],"video/mp4":["mp4","mp4v","mpg4"],"video/mpeg":["mpeg","mpg","mpe","m1v","m2v"],"video/ogg":["ogv"],"video/quicktime":["qt","mov"],"video/webm":["webm"]};Object.freeze(te);var P=function(e,t,i,n){if(i==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?e!==t||!n:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return i==="m"?n:i==="a"?n.call(e):n?n.value:t.get(e)},W,Q,V;class Re{constructor(...t){W.set(this,new Map),Q.set(this,new Map),V.set(this,new Map);for(const i of t)this.define(i)}define(t,i=!1){for(let[n,s]of Object.entries(t)){n=n.toLowerCase(),s=s.map(p=>p.toLowerCase()),P(this,V,"f").has(n)||P(this,V,"f").set(n,new Set);const a=P(this,V,"f").get(n);let r=!0;for(let p of s){const d=p.startsWith("*");if(p=d?p.slice(1):p,a==null||a.add(p),r&&P(this,Q,"f").set(n,p),r=!1,d)continue;const f=P(this,W,"f").get(p);if(f&&f!=n&&!i)throw new Error(`"${n} -> ${p}" conflicts with "${f} -> ${p}". Pass \`force=true\` to override this definition.`);P(this,W,"f").set(p,n)}}return this}getType(t){if(typeof t!="string")return null;const i=t.replace(/^.*[/\\]/,"").toLowerCase(),n=i.replace(/^.*\./,"").toLowerCase(),s=i.length<t.length;return!(n.length<i.length-1)&&s?null:P(this,W,"f").get(n)??null}getExtension(t){var i;return typeof t!="string"?null:(t=(i=t==null?void 0:t.split)==null?void 0:i.call(t,";")[0],(t&&P(this,Q,"f").get(t.trim().toLowerCase()))??null)}getAllExtensions(t){return typeof t!="string"?null:P(this,V,"f").get(t.toLowerCase())??null}_freeze(){this.define=()=>{throw new Error("define() not allowed for built-in Mime objects. See https://github.com/broofa/mime/blob/main/README.md#custom-mime-instances")},Object.freeze(this);for(const t of P(this,V,"f").values())Object.freeze(t);return this}_getTestState(){return{types:P(this,W,"f"),extensions:P(this,Q,"f")}}}W=new WeakMap,Q=new WeakMap,V=new WeakMap;const qe=new Re(te)._freeze();function ee(e){const t=[],i=Object.keys(e);for(const n of i){const s=e[n].sort((a,r)=>a.index-r.index);for(let a=0;a<s.length;a++)s[a].index!==a&&t.push({message:`Invalid operation index ${s[a].index} at position ${a}`,details:{position:a,operation:s[a],scope:s[a].scope}})}return t}const $t=async e=>{const t=new zt,{name:i,revision:n,documentType:s,created:a,lastModified:r}=e,p={name:i,revision:n,documentType:s,created:a,lastModified:r};return t.file("header.json",JSON.stringify(p,null,2)),t.file("state.json",JSON.stringify(e.initialState||{},null,2)),t.file("operations.json",JSON.stringify(e.operations,null,2)),Object.keys(e.attachments).forEach(f=>{const{data:k,...b}=e.attachments[f];t.file(f,k,{base64:!0,createFolders:!0,comment:JSON.stringify(b)})}),t},ie=async(e,t,i,n)=>{const a=await(await $t(e)).generateAsync({type:"uint8array",streamFiles:!0}),r=n??e.name,p=`.${i}.zip`;return De(t,r.endsWith(p)?r:`${r}${p}`,a)},Le=async(e,t)=>{const n=await(await $t(e)).generateAsync({type:"blob"}),s=await t.createWritable();await s.write(n),await s.close()},ft=async(e,t)=>{const i=Jt(e);return ne(i,t)},ne=async(e,t)=>{const i=new zt;return await i.loadAsync(e),Ce(i,t)};async function Ce(e,t){const i=e.file("state.json");if(!i)throw new Error("Initial state not found");const n=await i.async("string"),s=JSON.parse(n),a=e.file("header.json");let r;a&&(r=JSON.parse(await a.async("string")));const p=e.file("operations.json");if(!p)throw new Error("Operations history not found");const d=JSON.parse(await p.async("string")),f=ee(d);if(f.length){const b=f.map(h=>h.message);throw new Error(b.join(`
20
- `))}let k=jt(s,d,t,void 0,r);return r&&(k={...k,...r}),k}function oe(e){const t=e.replace(/^.*\./,"")||void 0,i=e.replace(/^.*[/\\]/,"")||void 0;return{extension:t,fileName:i}}async function Je(e){const{buffer:t,mimeType:i="application/octet-stream"}=await Ae(e),n=oe(e),s=t.toString("base64");return{data:s,hash:pt(s),mimeType:i,...n}}async function Ue(e){const t=await Ne(e),i=qe.getType(e)||"application/octet-stream",n=oe(e),s=t.toString("base64");return{data:s,hash:pt(s),mimeType:i,...n}}class Ve{constructor(t,i,n){ot(this,"_document");ot(this,"_reducer");ot(this,"_signalDispatch");this._reducer=t,this._document=i,this._signalDispatch=n}dispatch(t,i){return this._document=this._reducer(this._document,t,this._signalDispatch,i),this}saveToFile(t,i,n){return ie(this._document,t,i,n)}async loadFromFile(t){this._document=await ft(t,this._reducer)}static async stateFromFile(t,i){return await ft(t,i)}get state(){return G(this._document.state)}get operations(){return G(this._document.operations)}get name(){return this._document.name}get documentType(){return this._document.documentType}get created(){return this._document.created}get lastModified(){return this._document.lastModified}get revision(){return this._document.revision.global}getRevision(t){return this._document.revision[t]}get initialState(){return G(this._document.initialState)}toDocument(){return G(this._document)}getAttachment(t){return this._document.attachments[t]}setName(t){return this.dispatch(Gt(t)),this}undo(t){return this.dispatch(Qt(t)),this}redo(t){return this.dispatch(Xt(t)),this}prune(t,i){return this.dispatch(Yt(t,i)),this}loadState(t,i){return this.dispatch(Ot(t,i)),this}}function Ke(e,t){t.forEach(i=>{Object.getOwnPropertyNames(i.prototype).forEach(n=>{Object.defineProperty(e.prototype,n,Object.getOwnPropertyDescriptor(i.prototype,n)||Object.create(null))})})}exports.BaseActions=Pe;exports.BaseDocument=Ve;exports.applyMixins=Ke;exports.baseReducer=yt;exports.calculateSkipsLeft=Zt;exports.createAction=K;exports.createDocument=Bt;exports.createExtendedState=Kt;exports.createReducer=Vt;exports.createZip=$t;exports.getLocalFile=Ue;exports.getRemoteFile=Je;exports.hashDocument=wt;exports.hashKey=Me;exports.isBaseAction=ut;exports.isNoopOperation=Ut;exports.isSameDocument=Ie;exports.isUndoRedo=mt;exports.loadFromFile=ft;exports.loadFromInput=ne;exports.mapSkippedOperations=Wt;exports.processUndoRedo=Ct;exports.readOnly=G;exports.replayDocument=jt;exports.replayOperations=st;exports.saveToFile=ie;exports.saveToFileHandle=Le;exports.sortMappedOperations=Ht;exports.sortOperations=Fe;exports.validateOperations=ee;exports.zod=he;