document-model 1.0.9 → 1.0.11

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 (55) hide show
  1. package/dist/browser/document/index.d.ts +1 -0
  2. package/dist/browser/document/object.d.ts +10 -4
  3. package/dist/browser/document/reducer.d.ts +2 -1
  4. package/dist/browser/document/signal.d.ts +15 -0
  5. package/dist/browser/document/types.d.ts +12 -3
  6. package/dist/browser/document/utils/base.d.ts +2 -2
  7. package/dist/browser/document-model/gen/object.d.ts +2 -2
  8. package/dist/browser/document-model/gen/operation/actions.d.ts +3 -2
  9. package/dist/browser/document-model/gen/operation/creators.d.ts +3 -2
  10. package/dist/browser/document-model/gen/operation/object.d.ts +2 -1
  11. package/dist/browser/document-model/gen/operation/operations.d.ts +2 -1
  12. package/dist/browser/document-model/gen/schema/types.d.ts +8 -0
  13. package/dist/browser/document-model/gen/schema/zod.d.ts +5 -1
  14. package/dist/browser/document-model/index.d.ts +1 -0
  15. package/dist/browser/document-model.cjs +1 -1
  16. package/dist/browser/document-model.js +2 -2
  17. package/dist/browser/document.cjs +1 -1
  18. package/dist/browser/document.js +2 -2
  19. package/dist/browser/index.cjs +1 -1
  20. package/dist/browser/index.js +3 -3
  21. package/dist/browser/internal/index-ac329925.js +22 -0
  22. package/dist/{node/internal/index-5b0ca13a.js → browser/internal/index-c9e4dc9e.js} +1 -1
  23. package/dist/{node/internal/index-6a7277fe.js → browser/internal/index-cf51e575.js} +1 -1
  24. package/dist/browser/internal/{index-48f140bc.js → index-df1f6a1b.js} +442 -374
  25. package/dist/browser/internal/{object-ceb8f869.js → object-113c73e2.js} +2 -2
  26. package/dist/browser/internal/{object-98a2cff6.js → object-13eaec2b.js} +219 -218
  27. package/dist/node/document/index.d.ts +1 -0
  28. package/dist/node/document/object.d.ts +10 -4
  29. package/dist/node/document/reducer.d.ts +2 -1
  30. package/dist/node/document/signal.d.ts +15 -0
  31. package/dist/node/document/types.d.ts +12 -3
  32. package/dist/node/document/utils/base.d.ts +2 -2
  33. package/dist/node/document-model/gen/object.d.ts +2 -2
  34. package/dist/node/document-model/gen/operation/actions.d.ts +3 -2
  35. package/dist/node/document-model/gen/operation/creators.d.ts +3 -2
  36. package/dist/node/document-model/gen/operation/object.d.ts +2 -1
  37. package/dist/node/document-model/gen/operation/operations.d.ts +2 -1
  38. package/dist/node/document-model/gen/schema/types.d.ts +8 -0
  39. package/dist/node/document-model/gen/schema/zod.d.ts +5 -1
  40. package/dist/node/document-model/index.d.ts +1 -0
  41. package/dist/node/document-model.cjs +1 -1
  42. package/dist/node/document-model.js +2 -2
  43. package/dist/node/document.cjs +1 -1
  44. package/dist/node/document.js +2 -2
  45. package/dist/node/index.cjs +1 -1
  46. package/dist/node/index.js +3 -3
  47. package/dist/node/internal/{index-dfaca09a.js → index-0abc9251.js} +442 -374
  48. package/dist/{browser/internal/index-9922a4fc.js → node/internal/index-150bbba4.js} +1 -1
  49. package/dist/node/internal/index-2cd26a65.js +22 -0
  50. package/dist/{browser/internal/index-ff22a5bb.js → node/internal/index-a74d15aa.js} +1 -1
  51. package/dist/node/internal/{object-10abe15d.js → object-073dccc4.js} +1 -1
  52. package/dist/node/internal/{object-6f942fcb.js → object-baf4e3d5.js} +79 -78
  53. package/package.json +1 -1
  54. package/dist/browser/internal/index-7d7d05c8.js +0 -22
  55. package/dist/node/internal/index-2e487f63.js +0 -22
@@ -1,6 +1,6 @@
1
- "use strict";var br=Object.defineProperty;var Fr=(n,a,s)=>a in n?br(n,a,{enumerable:!0,configurable:!0,writable:!0,value:s}):n[a]=s;var Q=(n,a,s)=>(Fr(n,typeof a!="symbol"?a+"":a,s),s);const _r=require("json-stringify-deterministic"),R=require("immer"),At=require("jszip"),d=require("zod"),Bt=n=>n!=null,Ar=d.z.any().refine(n=>Bt(n)),St=d.z.enum(["LOAD_STATE"]),jt=d.z.enum(["PRUNE"]),Ut=d.z.enum(["REDO"]),It=d.z.enum(["SET_NAME"]),Tt=d.z.enum(["UNDO"]);function Br(){return d.z.object({__typename:d.z.literal("Action").optional(),type:d.z.string()})}function kt(){return d.z.union([at(),ot(),pt(),st(),ct()])}function Sr(){return d.z.object({__typename:d.z.literal("DocumentFile").optional(),data:d.z.string(),extension:d.z.string().nullable(),fileName:d.z.string().nullable(),mimeType:d.z.string()})}function at(){return d.z.object({input:d.z.lazy(()=>zt()),type:St})}function zt(){return d.z.object({operations:d.z.number(),state:d.z.lazy(()=>Dt())})}function Dt(){return d.z.object({data:d.z.unknown().nullish(),name:d.z.string()})}function jr(){return d.z.object({__typename:d.z.literal("Operation").optional(),hash:d.z.string(),index:d.z.number(),timestamp:d.z.string().datetime(),type:d.z.string()})}function ot(){return d.z.object({input:d.z.lazy(()=>Ot()),type:jt})}function Ot(){return d.z.object({end:d.z.number().nullish(),start:d.z.number().nullish()})}function pt(){return d.z.object({input:d.z.number(),type:Ut})}function st(){return d.z.object({input:d.z.string(),type:It})}function Ur(){return d.z.object({__typename:d.z.literal("SetNameOperation").optional(),hash:d.z.string(),index:d.z.number(),input:d.z.string(),timestamp:d.z.string().datetime(),type:d.z.string()})}function ct(){return d.z.object({input:d.z.number(),type:Tt})}const Ir=Object.freeze(Object.defineProperty({__proto__:null,ActionSchema:Br,BaseActionSchema:kt,DocumentFileSchema:Sr,LoadStateActionInputSchema:zt,LoadStateActionSchema:at,LoadStateActionStateInputSchema:Dt,Load_StateSchema:St,OperationSchema:jr,PruneActionInputSchema:Ot,PruneActionSchema:ot,PruneSchema:jt,RedoActionSchema:pt,RedoSchema:Ut,SetNameActionSchema:st,SetNameOperationSchema:Ur,Set_NameSchema:It,UndoActionSchema:ct,UndoSchema:Tt,definedNonNullAnySchema:Ar,isDefinedNonNullAny:Bt},Symbol.toStringTag,{value:"Module"}));function Nt(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}function P(){this._types=Object.create(null),this._extensions=Object.create(null);for(let n=0;n<arguments.length;n++)this.define(arguments[n]);this.define=this.define.bind(this),this.getType=this.getType.bind(this),this.getExtension=this.getExtension.bind(this)}P.prototype.define=function(n,a){for(let s in n){let c=n[s].map(function(f){return f.toLowerCase()});s=s.toLowerCase();for(let f=0;f<c.length;f++){const m=c[f];if(m[0]!=="*"){if(!a&&m in this._types)throw new Error('Attempt to change mapping for "'+m+'" extension from "'+this._types[m]+'" to "'+s+'". Pass `force=true` to allow this, otherwise remove "'+m+'" from the list of extensions for "'+s+'".');this._types[m]=s}}if(a||!this._extensions[s]){const f=c[0];this._extensions[s]=f[0]!=="*"?f:f.substr(1)}}};P.prototype.getType=function(n){n=String(n);let a=n.replace(/^.*[/\\]/,"").toLowerCase(),s=a.replace(/^.*\./,"").toLowerCase(),c=a.length<n.length;return(s.length<a.length-1||!c)&&this._types[s]||null};P.prototype.getExtension=function(n){return n=/^\s*([^;\s]*)/.test(n)&&RegExp.$1,n&&this._extensions[n.toLowerCase()]||null};var Tr=P,kr={"application/andrew-inset":["ez"],"application/applixware":["aw"],"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/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/cu-seeme":["cu"],"application/dash+xml":["mpd"],"application/davmount+xml":["davmount"],"application/docbook+xml":["dbk"],"application/dssc+der":["dssc"],"application/dssc+xml":["xdssc"],"application/ecmascript":["es","ecma"],"application/emma+xml":["emma"],"application/emotionml+xml":["emotionml"],"application/epub+zip":["epub"],"application/exi":["exi"],"application/express":["exp"],"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","mjs"],"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/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":["mp4s","m4p"],"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-signature":["asc","sig"],"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/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/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/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/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/avif":["avif"],"image/bmp":["bmp"],"image/cgm":["cgm"],"image/dicom-rle":["drle"],"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"],"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/mesh":["msh","mesh","silo"],"model/mtl":["mtl"],"model/obj":["obj"],"model/step+xml":["stpx"],"model/step+zip":["stpz"],"model/step-xml+zip":["stpxz"],"model/stl":["stl"],"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/jsx":["jsx"],"text/less":["less"],"text/markdown":["markdown","md"],"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/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"]};let zr=Tr;var Dr=new zr(kr);const Or=Nt(Dr);var rt={exports:{}};typeof Object.create=="function"?rt.exports=function(a,s){s&&(a.super_=s,a.prototype=Object.create(s.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}))}:rt.exports=function(a,s){if(s){a.super_=s;var c=function(){};c.prototype=s.prototype,a.prototype=new c,a.prototype.constructor=a}};var Nr=rt.exports,et={exports:{}},Mt={},W={};W.byteLength=Cr;W.toByteArray=qr;W.fromByteArray=Pr;var T=[],j=[],Mr=typeof Uint8Array<"u"?Uint8Array:Array,tt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var z=0,Rr=tt.length;z<Rr;++z)T[z]=tt[z],j[tt.charCodeAt(z)]=z;j["-".charCodeAt(0)]=62;j["_".charCodeAt(0)]=63;function Rt(n){var a=n.length;if(a%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var s=n.indexOf("=");s===-1&&(s=a);var c=s===a?0:4-s%4;return[s,c]}function Cr(n){var a=Rt(n),s=a[0],c=a[1];return(s+c)*3/4-c}function Lr(n,a,s){return(a+s)*3/4-s}function qr(n){var a,s=Rt(n),c=s[0],f=s[1],m=new Mr(Lr(n,c,f)),u=0,o=f>0?c-4:c,x;for(x=0;x<o;x+=4)a=j[n.charCodeAt(x)]<<18|j[n.charCodeAt(x+1)]<<12|j[n.charCodeAt(x+2)]<<6|j[n.charCodeAt(x+3)],m[u++]=a>>16&255,m[u++]=a>>8&255,m[u++]=a&255;return f===2&&(a=j[n.charCodeAt(x)]<<2|j[n.charCodeAt(x+1)]>>4,m[u++]=a&255),f===1&&(a=j[n.charCodeAt(x)]<<10|j[n.charCodeAt(x+1)]<<4|j[n.charCodeAt(x+2)]>>2,m[u++]=a>>8&255,m[u++]=a&255),m}function $r(n){return T[n>>18&63]+T[n>>12&63]+T[n>>6&63]+T[n&63]}function Jr(n,a,s){for(var c,f=[],m=a;m<s;m+=3)c=(n[m]<<16&16711680)+(n[m+1]<<8&65280)+(n[m+2]&255),f.push($r(c));return f.join("")}function Pr(n){for(var a,s=n.length,c=s%3,f=[],m=16383,u=0,o=s-c;u<o;u+=m)f.push(Jr(n,u,u+m>o?o:u+m));return c===1?(a=n[s-1],f.push(T[a>>2]+T[a<<4&63]+"==")):c===2&&(a=(n[s-2]<<8)+n[s-1],f.push(T[a>>10]+T[a>>4&63]+T[a<<2&63]+"=")),f.join("")}var lt={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */lt.read=function(n,a,s,c,f){var m,u,o=f*8-c-1,x=(1<<o)-1,w=x>>1,v=-7,F=s?f-1:0,U=s?-1:1,B=n[a+F];for(F+=U,m=B&(1<<-v)-1,B>>=-v,v+=o;v>0;m=m*256+n[a+F],F+=U,v-=8);for(u=m&(1<<-v)-1,m>>=-v,v+=c;v>0;u=u*256+n[a+F],F+=U,v-=8);if(m===0)m=1-w;else{if(m===x)return u?NaN:(B?-1:1)*(1/0);u=u+Math.pow(2,c),m=m-w}return(B?-1:1)*u*Math.pow(2,m-c)};lt.write=function(n,a,s,c,f,m){var u,o,x,w=m*8-f-1,v=(1<<w)-1,F=v>>1,U=f===23?Math.pow(2,-24)-Math.pow(2,-77):0,B=c?0:m-1,O=c?1:-1,N=a<0||a===0&&1/a<0?1:0;for(a=Math.abs(a),isNaN(a)||a===1/0?(o=isNaN(a)?1:0,u=v):(u=Math.floor(Math.log(a)/Math.LN2),a*(x=Math.pow(2,-u))<1&&(u--,x*=2),u+F>=1?a+=U/x:a+=U*Math.pow(2,1-F),a*x>=2&&(u++,x/=2),u+F>=v?(o=0,u=v):u+F>=1?(o=(a*x-1)*Math.pow(2,f),u=u+F):(o=a*Math.pow(2,F-1)*Math.pow(2,f),u=0));f>=8;n[s+B]=o&255,B+=O,o/=256,f-=8);for(u=u<<f|o,w+=f;w>0;n[s+B]=u&255,B+=O,u/=256,w-=8);n[s+B-O]|=N*128};/*!
1
+ "use strict";var br=Object.defineProperty;var Fr=(n,a,s)=>a in n?br(n,a,{enumerable:!0,configurable:!0,writable:!0,value:s}):n[a]=s;var J=(n,a,s)=>(Fr(n,typeof a!="symbol"?a+"":a,s),s);const _r=require("json-stringify-deterministic"),R=require("immer"),At=require("jszip"),d=require("zod"),Bt=n=>n!=null,Ar=d.z.any().refine(n=>Bt(n)),St=d.z.enum(["LOAD_STATE"]),jt=d.z.enum(["PRUNE"]),Ut=d.z.enum(["REDO"]),It=d.z.enum(["SET_NAME"]),Tt=d.z.enum(["UNDO"]);function Br(){return d.z.object({__typename:d.z.literal("Action").optional(),type:d.z.string()})}function kt(){return d.z.union([at(),ot(),pt(),st(),ct()])}function Sr(){return d.z.object({__typename:d.z.literal("DocumentFile").optional(),data:d.z.string(),extension:d.z.string().nullable(),fileName:d.z.string().nullable(),mimeType:d.z.string()})}function at(){return d.z.object({input:d.z.lazy(()=>zt()),type:St})}function zt(){return d.z.object({operations:d.z.number(),state:d.z.lazy(()=>Dt())})}function Dt(){return d.z.object({data:d.z.unknown().nullish(),name:d.z.string()})}function jr(){return d.z.object({__typename:d.z.literal("Operation").optional(),hash:d.z.string(),index:d.z.number(),timestamp:d.z.string().datetime(),type:d.z.string()})}function ot(){return d.z.object({input:d.z.lazy(()=>Ot()),type:jt})}function Ot(){return d.z.object({end:d.z.number().nullish(),start:d.z.number().nullish()})}function pt(){return d.z.object({input:d.z.number(),type:Ut})}function st(){return d.z.object({input:d.z.string(),type:It})}function Ur(){return d.z.object({__typename:d.z.literal("SetNameOperation").optional(),hash:d.z.string(),index:d.z.number(),input:d.z.string(),timestamp:d.z.string().datetime(),type:d.z.string()})}function ct(){return d.z.object({input:d.z.number(),type:Tt})}const Ir=Object.freeze(Object.defineProperty({__proto__:null,ActionSchema:Br,BaseActionSchema:kt,DocumentFileSchema:Sr,LoadStateActionInputSchema:zt,LoadStateActionSchema:at,LoadStateActionStateInputSchema:Dt,Load_StateSchema:St,OperationSchema:jr,PruneActionInputSchema:Ot,PruneActionSchema:ot,PruneSchema:jt,RedoActionSchema:pt,RedoSchema:Ut,SetNameActionSchema:st,SetNameOperationSchema:Ur,Set_NameSchema:It,UndoActionSchema:ct,UndoSchema:Tt,definedNonNullAnySchema:Ar,isDefinedNonNullAny:Bt},Symbol.toStringTag,{value:"Module"}));function Nt(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}function W(){this._types=Object.create(null),this._extensions=Object.create(null);for(let n=0;n<arguments.length;n++)this.define(arguments[n]);this.define=this.define.bind(this),this.getType=this.getType.bind(this),this.getExtension=this.getExtension.bind(this)}W.prototype.define=function(n,a){for(let s in n){let c=n[s].map(function(f){return f.toLowerCase()});s=s.toLowerCase();for(let f=0;f<c.length;f++){const h=c[f];if(h[0]!=="*"){if(!a&&h in this._types)throw new Error('Attempt to change mapping for "'+h+'" extension from "'+this._types[h]+'" to "'+s+'". Pass `force=true` to allow this, otherwise remove "'+h+'" from the list of extensions for "'+s+'".');this._types[h]=s}}if(a||!this._extensions[s]){const f=c[0];this._extensions[s]=f[0]!=="*"?f:f.substr(1)}}};W.prototype.getType=function(n){n=String(n);let a=n.replace(/^.*[/\\]/,"").toLowerCase(),s=a.replace(/^.*\./,"").toLowerCase(),c=a.length<n.length;return(s.length<a.length-1||!c)&&this._types[s]||null};W.prototype.getExtension=function(n){return n=/^\s*([^;\s]*)/.test(n)&&RegExp.$1,n&&this._extensions[n.toLowerCase()]||null};var Tr=W,kr={"application/andrew-inset":["ez"],"application/applixware":["aw"],"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/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/cu-seeme":["cu"],"application/dash+xml":["mpd"],"application/davmount+xml":["davmount"],"application/docbook+xml":["dbk"],"application/dssc+der":["dssc"],"application/dssc+xml":["xdssc"],"application/ecmascript":["es","ecma"],"application/emma+xml":["emma"],"application/emotionml+xml":["emotionml"],"application/epub+zip":["epub"],"application/exi":["exi"],"application/express":["exp"],"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","mjs"],"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/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":["mp4s","m4p"],"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-signature":["asc","sig"],"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/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/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/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/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/avif":["avif"],"image/bmp":["bmp"],"image/cgm":["cgm"],"image/dicom-rle":["drle"],"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"],"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/mesh":["msh","mesh","silo"],"model/mtl":["mtl"],"model/obj":["obj"],"model/step+xml":["stpx"],"model/step+zip":["stpz"],"model/step-xml+zip":["stpxz"],"model/stl":["stl"],"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/jsx":["jsx"],"text/less":["less"],"text/markdown":["markdown","md"],"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/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"]};let zr=Tr;var Dr=new zr(kr);const Or=Nt(Dr);var rt={exports:{}};typeof Object.create=="function"?rt.exports=function(a,s){s&&(a.super_=s,a.prototype=Object.create(s.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}))}:rt.exports=function(a,s){if(s){a.super_=s;var c=function(){};c.prototype=s.prototype,a.prototype=new c,a.prototype.constructor=a}};var Nr=rt.exports,it={exports:{}},Mt={},H={};H.byteLength=Cr;H.toByteArray=qr;H.fromByteArray=Pr;var T=[],j=[],Mr=typeof Uint8Array<"u"?Uint8Array:Array,tt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var z=0,Rr=tt.length;z<Rr;++z)T[z]=tt[z],j[tt.charCodeAt(z)]=z;j["-".charCodeAt(0)]=62;j["_".charCodeAt(0)]=63;function Rt(n){var a=n.length;if(a%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var s=n.indexOf("=");s===-1&&(s=a);var c=s===a?0:4-s%4;return[s,c]}function Cr(n){var a=Rt(n),s=a[0],c=a[1];return(s+c)*3/4-c}function Lr(n,a,s){return(a+s)*3/4-s}function qr(n){var a,s=Rt(n),c=s[0],f=s[1],h=new Mr(Lr(n,c,f)),u=0,o=f>0?c-4:c,x;for(x=0;x<o;x+=4)a=j[n.charCodeAt(x)]<<18|j[n.charCodeAt(x+1)]<<12|j[n.charCodeAt(x+2)]<<6|j[n.charCodeAt(x+3)],h[u++]=a>>16&255,h[u++]=a>>8&255,h[u++]=a&255;return f===2&&(a=j[n.charCodeAt(x)]<<2|j[n.charCodeAt(x+1)]>>4,h[u++]=a&255),f===1&&(a=j[n.charCodeAt(x)]<<10|j[n.charCodeAt(x+1)]<<4|j[n.charCodeAt(x+2)]>>2,h[u++]=a>>8&255,h[u++]=a&255),h}function $r(n){return T[n>>18&63]+T[n>>12&63]+T[n>>6&63]+T[n&63]}function Jr(n,a,s){for(var c,f=[],h=a;h<s;h+=3)c=(n[h]<<16&16711680)+(n[h+1]<<8&65280)+(n[h+2]&255),f.push($r(c));return f.join("")}function Pr(n){for(var a,s=n.length,c=s%3,f=[],h=16383,u=0,o=s-c;u<o;u+=h)f.push(Jr(n,u,u+h>o?o:u+h));return c===1?(a=n[s-1],f.push(T[a>>2]+T[a<<4&63]+"==")):c===2&&(a=(n[s-2]<<8)+n[s-1],f.push(T[a>>10]+T[a>>4&63]+T[a<<2&63]+"=")),f.join("")}var lt={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */lt.read=function(n,a,s,c,f){var h,u,o=f*8-c-1,x=(1<<o)-1,w=x>>1,v=-7,F=s?f-1:0,U=s?-1:1,B=n[a+F];for(F+=U,h=B&(1<<-v)-1,B>>=-v,v+=o;v>0;h=h*256+n[a+F],F+=U,v-=8);for(u=h&(1<<-v)-1,h>>=-v,v+=c;v>0;u=u*256+n[a+F],F+=U,v-=8);if(h===0)h=1-w;else{if(h===x)return u?NaN:(B?-1:1)*(1/0);u=u+Math.pow(2,c),h=h-w}return(B?-1:1)*u*Math.pow(2,h-c)};lt.write=function(n,a,s,c,f,h){var u,o,x,w=h*8-f-1,v=(1<<w)-1,F=v>>1,U=f===23?Math.pow(2,-24)-Math.pow(2,-77):0,B=c?0:h-1,O=c?1:-1,N=a<0||a===0&&1/a<0?1:0;for(a=Math.abs(a),isNaN(a)||a===1/0?(o=isNaN(a)?1:0,u=v):(u=Math.floor(Math.log(a)/Math.LN2),a*(x=Math.pow(2,-u))<1&&(u--,x*=2),u+F>=1?a+=U/x:a+=U*Math.pow(2,1-F),a*x>=2&&(u++,x/=2),u+F>=v?(o=0,u=v):u+F>=1?(o=(a*x-1)*Math.pow(2,f),u=u+F):(o=a*Math.pow(2,F-1)*Math.pow(2,f),u=0));f>=8;n[s+B]=o&255,B+=O,o/=256,f-=8);for(u=u<<f|o,w+=f;w>0;n[s+B]=u&255,B+=O,u/=256,w-=8);n[s+B-O]|=N*128};/*!
2
2
  * The buffer module from node.js, for the browser.
3
3
  *
4
4
  * @author Feross Aboukhadijeh <https://feross.org>
5
5
  * @license MIT
6
- */(function(n){var a=W,s=lt,c=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;n.Buffer=o,n.SlowBuffer=nr,n.INSPECT_MAX_BYTES=50;var f=2147483647;n.kMaxLength=f,o.TYPED_ARRAY_SUPPORT=m(),!o.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 m(){try{var e=new Uint8Array(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,Uint8Array.prototype),Object.setPrototypeOf(e,t),e.foo()===42}catch{return!1}}Object.defineProperty(o.prototype,"parent",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.buffer}}),Object.defineProperty(o.prototype,"offset",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.byteOffset}});function u(e){if(e>f)throw new RangeError('The value "'+e+'" is invalid for option "size"');var t=new Uint8Array(e);return Object.setPrototypeOf(t,o.prototype),t}function o(e,t,r){if(typeof e=="number"){if(typeof t=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return F(e)}return x(e,t,r)}o.poolSize=8192;function x(e,t,r){if(typeof e=="string")return U(e,t);if(ArrayBuffer.isView(e))return O(e);if(e==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(I(e,ArrayBuffer)||e&&I(e.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(I(e,SharedArrayBuffer)||e&&I(e.buffer,SharedArrayBuffer)))return N(e,t,r);if(typeof e=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');var i=e.valueOf&&e.valueOf();if(i!=null&&i!==e)return o.from(i,t,r);var p=ir(e);if(p)return p;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof e[Symbol.toPrimitive]=="function")return o.from(e[Symbol.toPrimitive]("string"),t,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}o.from=function(e,t,r){return x(e,t,r)},Object.setPrototypeOf(o.prototype,Uint8Array.prototype),Object.setPrototypeOf(o,Uint8Array);function w(e){if(typeof e!="number")throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function v(e,t,r){return w(e),e<=0?u(e):t!==void 0?typeof r=="string"?u(e).fill(t,r):u(e).fill(t):u(e)}o.alloc=function(e,t,r){return v(e,t,r)};function F(e){return w(e),u(e<0?0:X(e)|0)}o.allocUnsafe=function(e){return F(e)},o.allocUnsafeSlow=function(e){return F(e)};function U(e,t){if((typeof t!="string"||t==="")&&(t="utf8"),!o.isEncoding(t))throw new TypeError("Unknown encoding: "+t);var r=mt(e,t)|0,i=u(r),p=i.write(e,t);return p!==r&&(i=i.slice(0,p)),i}function B(e){for(var t=e.length<0?0:X(e.length)|0,r=u(t),i=0;i<t;i+=1)r[i]=e[i]&255;return r}function O(e){if(I(e,Uint8Array)){var t=new Uint8Array(e);return N(t.buffer,t.byteOffset,t.byteLength)}return B(e)}function N(e,t,r){if(t<0||e.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(e.byteLength<t+(r||0))throw new RangeError('"length" is outside of buffer bounds');var i;return t===void 0&&r===void 0?i=new Uint8Array(e):r===void 0?i=new Uint8Array(e,t):i=new Uint8Array(e,t,r),Object.setPrototypeOf(i,o.prototype),i}function ir(e){if(o.isBuffer(e)){var t=X(e.length)|0,r=u(t);return r.length===0||e.copy(r,0,0,t),r}if(e.length!==void 0)return typeof e.length!="number"||V(e.length)?u(0):B(e);if(e.type==="Buffer"&&Array.isArray(e.data))return B(e.data)}function X(e){if(e>=f)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+f.toString(16)+" bytes");return e|0}function nr(e){return+e!=e&&(e=0),o.alloc(+e)}o.isBuffer=function(t){return t!=null&&t._isBuffer===!0&&t!==o.prototype},o.compare=function(t,r){if(I(t,Uint8Array)&&(t=o.from(t,t.offset,t.byteLength)),I(r,Uint8Array)&&(r=o.from(r,r.offset,r.byteLength)),!o.isBuffer(t)||!o.isBuffer(r))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===r)return 0;for(var i=t.length,p=r.length,l=0,h=Math.min(i,p);l<h;++l)if(t[l]!==r[l]){i=t[l],p=r[l];break}return i<p?-1:p<i?1:0},o.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}},o.concat=function(t,r){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(t.length===0)return o.alloc(0);var i;if(r===void 0)for(r=0,i=0;i<t.length;++i)r+=t[i].length;var p=o.allocUnsafe(r),l=0;for(i=0;i<t.length;++i){var h=t[i];if(I(h,Uint8Array))l+h.length>p.length?o.from(h).copy(p,l):Uint8Array.prototype.set.call(p,h,l);else if(o.isBuffer(h))h.copy(p,l);else throw new TypeError('"list" argument must be an Array of Buffers');l+=h.length}return p};function mt(e,t){if(o.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||I(e,ArrayBuffer))return e.byteLength;if(typeof e!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);var r=e.length,i=arguments.length>2&&arguments[2]===!0;if(!i&&r===0)return 0;for(var p=!1;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return G(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return r*2;case"hex":return r>>>1;case"base64":return bt(e).length;default:if(p)return i?-1:G(e).length;t=(""+t).toLowerCase(),p=!0}}o.byteLength=mt;function ar(e,t,r){var i=!1;if((t===void 0||t<0)&&(t=0),t>this.length||((r===void 0||r>this.length)&&(r=this.length),r<=0)||(r>>>=0,t>>>=0,r<=t))return"";for(e||(e="utf8");;)switch(e){case"hex":return xr(this,t,r);case"utf8":case"utf-8":return yt(this,t,r);case"ascii":return hr(this,t,r);case"latin1":case"binary":return mr(this,t,r);case"base64":return ur(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return dr(this,t,r);default:if(i)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),i=!0}}o.prototype._isBuffer=!0;function k(e,t,r){var i=e[t];e[t]=e[r],e[r]=i}o.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 r=0;r<t;r+=2)k(this,r,r+1);return this},o.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 r=0;r<t;r+=4)k(this,r,r+3),k(this,r+1,r+2);return this},o.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 r=0;r<t;r+=8)k(this,r,r+7),k(this,r+1,r+6),k(this,r+2,r+5),k(this,r+3,r+4);return this},o.prototype.toString=function(){var t=this.length;return t===0?"":arguments.length===0?yt(this,0,t):ar.apply(this,arguments)},o.prototype.toLocaleString=o.prototype.toString,o.prototype.equals=function(t){if(!o.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t?!0:o.compare(this,t)===0},o.prototype.inspect=function(){var t="",r=n.INSPECT_MAX_BYTES;return t=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(t+=" ... "),"<Buffer "+t+">"},c&&(o.prototype[c]=o.prototype.inspect),o.prototype.compare=function(t,r,i,p,l){if(I(t,Uint8Array)&&(t=o.from(t,t.offset,t.byteLength)),!o.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(r===void 0&&(r=0),i===void 0&&(i=t?t.length:0),p===void 0&&(p=0),l===void 0&&(l=this.length),r<0||i>t.length||p<0||l>this.length)throw new RangeError("out of range index");if(p>=l&&r>=i)return 0;if(p>=l)return-1;if(r>=i)return 1;if(r>>>=0,i>>>=0,p>>>=0,l>>>=0,this===t)return 0;for(var h=l-p,y=i-r,g=Math.min(h,y),E=this.slice(p,l),A=t.slice(r,i),b=0;b<g;++b)if(E[b]!==A[b]){h=E[b],y=A[b];break}return h<y?-1:y<h?1:0};function xt(e,t,r,i,p){if(e.length===0)return-1;if(typeof r=="string"?(i=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,V(r)&&(r=p?0:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(p)return-1;r=e.length-1}else if(r<0)if(p)r=0;else return-1;if(typeof t=="string"&&(t=o.from(t,i)),o.isBuffer(t))return t.length===0?-1:dt(e,t,r,i,p);if(typeof t=="number")return t=t&255,typeof Uint8Array.prototype.indexOf=="function"?p?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):dt(e,[t],r,i,p);throw new TypeError("val must be string, number or Buffer")}function dt(e,t,r,i,p){var l=1,h=e.length,y=t.length;if(i!==void 0&&(i=String(i).toLowerCase(),i==="ucs2"||i==="ucs-2"||i==="utf16le"||i==="utf-16le")){if(e.length<2||t.length<2)return-1;l=2,h/=2,y/=2,r/=2}function g(Ft,_t){return l===1?Ft[_t]:Ft.readUInt16BE(_t*l)}var E;if(p){var A=-1;for(E=r;E<h;E++)if(g(e,E)===g(t,A===-1?0:E-A)){if(A===-1&&(A=E),E-A+1===y)return A*l}else A!==-1&&(E-=E-A),A=-1}else for(r+y>h&&(r=h-y),E=r;E>=0;E--){for(var b=!0,$=0;$<y;$++)if(g(e,E+$)!==g(t,$)){b=!1;break}if(b)return E}return-1}o.prototype.includes=function(t,r,i){return this.indexOf(t,r,i)!==-1},o.prototype.indexOf=function(t,r,i){return xt(this,t,r,i,!0)},o.prototype.lastIndexOf=function(t,r,i){return xt(this,t,r,i,!1)};function or(e,t,r,i){r=Number(r)||0;var p=e.length-r;i?(i=Number(i),i>p&&(i=p)):i=p;var l=t.length;i>l/2&&(i=l/2);for(var h=0;h<i;++h){var y=parseInt(t.substr(h*2,2),16);if(V(y))return h;e[r+h]=y}return h}function pr(e,t,r,i){return q(G(t,e.length-r),e,r,i)}function sr(e,t,r,i){return q(gr(t),e,r,i)}function cr(e,t,r,i){return q(bt(t),e,r,i)}function lr(e,t,r,i){return q(vr(t,e.length-r),e,r,i)}o.prototype.write=function(t,r,i,p){if(r===void 0)p="utf8",i=this.length,r=0;else if(i===void 0&&typeof r=="string")p=r,i=this.length,r=0;else if(isFinite(r))r=r>>>0,isFinite(i)?(i=i>>>0,p===void 0&&(p="utf8")):(p=i,i=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");var l=this.length-r;if((i===void 0||i>l)&&(i=l),t.length>0&&(i<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");p||(p="utf8");for(var h=!1;;)switch(p){case"hex":return or(this,t,r,i);case"utf8":case"utf-8":return pr(this,t,r,i);case"ascii":case"latin1":case"binary":return sr(this,t,r,i);case"base64":return cr(this,t,r,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return lr(this,t,r,i);default:if(h)throw new TypeError("Unknown encoding: "+p);p=(""+p).toLowerCase(),h=!0}},o.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function ur(e,t,r){return t===0&&r===e.length?a.fromByteArray(e):a.fromByteArray(e.slice(t,r))}function yt(e,t,r){r=Math.min(e.length,r);for(var i=[],p=t;p<r;){var l=e[p],h=null,y=l>239?4:l>223?3:l>191?2:1;if(p+y<=r){var g,E,A,b;switch(y){case 1:l<128&&(h=l);break;case 2:g=e[p+1],(g&192)===128&&(b=(l&31)<<6|g&63,b>127&&(h=b));break;case 3:g=e[p+1],E=e[p+2],(g&192)===128&&(E&192)===128&&(b=(l&15)<<12|(g&63)<<6|E&63,b>2047&&(b<55296||b>57343)&&(h=b));break;case 4:g=e[p+1],E=e[p+2],A=e[p+3],(g&192)===128&&(E&192)===128&&(A&192)===128&&(b=(l&15)<<18|(g&63)<<12|(E&63)<<6|A&63,b>65535&&b<1114112&&(h=b))}}h===null?(h=65533,y=1):h>65535&&(h-=65536,i.push(h>>>10&1023|55296),h=56320|h&1023),i.push(h),p+=y}return fr(i)}var wt=4096;function fr(e){var t=e.length;if(t<=wt)return String.fromCharCode.apply(String,e);for(var r="",i=0;i<t;)r+=String.fromCharCode.apply(String,e.slice(i,i+=wt));return r}function hr(e,t,r){var i="";r=Math.min(e.length,r);for(var p=t;p<r;++p)i+=String.fromCharCode(e[p]&127);return i}function mr(e,t,r){var i="";r=Math.min(e.length,r);for(var p=t;p<r;++p)i+=String.fromCharCode(e[p]);return i}function xr(e,t,r){var i=e.length;(!t||t<0)&&(t=0),(!r||r<0||r>i)&&(r=i);for(var p="",l=t;l<r;++l)p+=Er[e[l]];return p}function dr(e,t,r){for(var i=e.slice(t,r),p="",l=0;l<i.length-1;l+=2)p+=String.fromCharCode(i[l]+i[l+1]*256);return p}o.prototype.slice=function(t,r){var i=this.length;t=~~t,r=r===void 0?i:~~r,t<0?(t+=i,t<0&&(t=0)):t>i&&(t=i),r<0?(r+=i,r<0&&(r=0)):r>i&&(r=i),r<t&&(r=t);var p=this.subarray(t,r);return Object.setPrototypeOf(p,o.prototype),p};function _(e,t,r){if(e%1!==0||e<0)throw new RangeError("offset is not uint");if(e+t>r)throw new RangeError("Trying to access beyond buffer length")}o.prototype.readUintLE=o.prototype.readUIntLE=function(t,r,i){t=t>>>0,r=r>>>0,i||_(t,r,this.length);for(var p=this[t],l=1,h=0;++h<r&&(l*=256);)p+=this[t+h]*l;return p},o.prototype.readUintBE=o.prototype.readUIntBE=function(t,r,i){t=t>>>0,r=r>>>0,i||_(t,r,this.length);for(var p=this[t+--r],l=1;r>0&&(l*=256);)p+=this[t+--r]*l;return p},o.prototype.readUint8=o.prototype.readUInt8=function(t,r){return t=t>>>0,r||_(t,1,this.length),this[t]},o.prototype.readUint16LE=o.prototype.readUInt16LE=function(t,r){return t=t>>>0,r||_(t,2,this.length),this[t]|this[t+1]<<8},o.prototype.readUint16BE=o.prototype.readUInt16BE=function(t,r){return t=t>>>0,r||_(t,2,this.length),this[t]<<8|this[t+1]},o.prototype.readUint32LE=o.prototype.readUInt32LE=function(t,r){return t=t>>>0,r||_(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+this[t+3]*16777216},o.prototype.readUint32BE=o.prototype.readUInt32BE=function(t,r){return t=t>>>0,r||_(t,4,this.length),this[t]*16777216+(this[t+1]<<16|this[t+2]<<8|this[t+3])},o.prototype.readIntLE=function(t,r,i){t=t>>>0,r=r>>>0,i||_(t,r,this.length);for(var p=this[t],l=1,h=0;++h<r&&(l*=256);)p+=this[t+h]*l;return l*=128,p>=l&&(p-=Math.pow(2,8*r)),p},o.prototype.readIntBE=function(t,r,i){t=t>>>0,r=r>>>0,i||_(t,r,this.length);for(var p=r,l=1,h=this[t+--p];p>0&&(l*=256);)h+=this[t+--p]*l;return l*=128,h>=l&&(h-=Math.pow(2,8*r)),h},o.prototype.readInt8=function(t,r){return t=t>>>0,r||_(t,1,this.length),this[t]&128?(255-this[t]+1)*-1:this[t]},o.prototype.readInt16LE=function(t,r){t=t>>>0,r||_(t,2,this.length);var i=this[t]|this[t+1]<<8;return i&32768?i|4294901760:i},o.prototype.readInt16BE=function(t,r){t=t>>>0,r||_(t,2,this.length);var i=this[t+1]|this[t]<<8;return i&32768?i|4294901760:i},o.prototype.readInt32LE=function(t,r){return t=t>>>0,r||_(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},o.prototype.readInt32BE=function(t,r){return t=t>>>0,r||_(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},o.prototype.readFloatLE=function(t,r){return t=t>>>0,r||_(t,4,this.length),s.read(this,t,!0,23,4)},o.prototype.readFloatBE=function(t,r){return t=t>>>0,r||_(t,4,this.length),s.read(this,t,!1,23,4)},o.prototype.readDoubleLE=function(t,r){return t=t>>>0,r||_(t,8,this.length),s.read(this,t,!0,52,8)},o.prototype.readDoubleBE=function(t,r){return t=t>>>0,r||_(t,8,this.length),s.read(this,t,!1,52,8)};function S(e,t,r,i,p,l){if(!o.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>p||t<l)throw new RangeError('"value" argument is out of bounds');if(r+i>e.length)throw new RangeError("Index out of range")}o.prototype.writeUintLE=o.prototype.writeUIntLE=function(t,r,i,p){if(t=+t,r=r>>>0,i=i>>>0,!p){var l=Math.pow(2,8*i)-1;S(this,t,r,i,l,0)}var h=1,y=0;for(this[r]=t&255;++y<i&&(h*=256);)this[r+y]=t/h&255;return r+i},o.prototype.writeUintBE=o.prototype.writeUIntBE=function(t,r,i,p){if(t=+t,r=r>>>0,i=i>>>0,!p){var l=Math.pow(2,8*i)-1;S(this,t,r,i,l,0)}var h=i-1,y=1;for(this[r+h]=t&255;--h>=0&&(y*=256);)this[r+h]=t/y&255;return r+i},o.prototype.writeUint8=o.prototype.writeUInt8=function(t,r,i){return t=+t,r=r>>>0,i||S(this,t,r,1,255,0),this[r]=t&255,r+1},o.prototype.writeUint16LE=o.prototype.writeUInt16LE=function(t,r,i){return t=+t,r=r>>>0,i||S(this,t,r,2,65535,0),this[r]=t&255,this[r+1]=t>>>8,r+2},o.prototype.writeUint16BE=o.prototype.writeUInt16BE=function(t,r,i){return t=+t,r=r>>>0,i||S(this,t,r,2,65535,0),this[r]=t>>>8,this[r+1]=t&255,r+2},o.prototype.writeUint32LE=o.prototype.writeUInt32LE=function(t,r,i){return t=+t,r=r>>>0,i||S(this,t,r,4,4294967295,0),this[r+3]=t>>>24,this[r+2]=t>>>16,this[r+1]=t>>>8,this[r]=t&255,r+4},o.prototype.writeUint32BE=o.prototype.writeUInt32BE=function(t,r,i){return t=+t,r=r>>>0,i||S(this,t,r,4,4294967295,0),this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=t&255,r+4},o.prototype.writeIntLE=function(t,r,i,p){if(t=+t,r=r>>>0,!p){var l=Math.pow(2,8*i-1);S(this,t,r,i,l-1,-l)}var h=0,y=1,g=0;for(this[r]=t&255;++h<i&&(y*=256);)t<0&&g===0&&this[r+h-1]!==0&&(g=1),this[r+h]=(t/y>>0)-g&255;return r+i},o.prototype.writeIntBE=function(t,r,i,p){if(t=+t,r=r>>>0,!p){var l=Math.pow(2,8*i-1);S(this,t,r,i,l-1,-l)}var h=i-1,y=1,g=0;for(this[r+h]=t&255;--h>=0&&(y*=256);)t<0&&g===0&&this[r+h+1]!==0&&(g=1),this[r+h]=(t/y>>0)-g&255;return r+i},o.prototype.writeInt8=function(t,r,i){return t=+t,r=r>>>0,i||S(this,t,r,1,127,-128),t<0&&(t=255+t+1),this[r]=t&255,r+1},o.prototype.writeInt16LE=function(t,r,i){return t=+t,r=r>>>0,i||S(this,t,r,2,32767,-32768),this[r]=t&255,this[r+1]=t>>>8,r+2},o.prototype.writeInt16BE=function(t,r,i){return t=+t,r=r>>>0,i||S(this,t,r,2,32767,-32768),this[r]=t>>>8,this[r+1]=t&255,r+2},o.prototype.writeInt32LE=function(t,r,i){return t=+t,r=r>>>0,i||S(this,t,r,4,2147483647,-2147483648),this[r]=t&255,this[r+1]=t>>>8,this[r+2]=t>>>16,this[r+3]=t>>>24,r+4},o.prototype.writeInt32BE=function(t,r,i){return t=+t,r=r>>>0,i||S(this,t,r,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=t&255,r+4};function gt(e,t,r,i,p,l){if(r+i>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function vt(e,t,r,i,p){return t=+t,r=r>>>0,p||gt(e,t,r,4),s.write(e,t,r,i,23,4),r+4}o.prototype.writeFloatLE=function(t,r,i){return vt(this,t,r,!0,i)},o.prototype.writeFloatBE=function(t,r,i){return vt(this,t,r,!1,i)};function Et(e,t,r,i,p){return t=+t,r=r>>>0,p||gt(e,t,r,8),s.write(e,t,r,i,52,8),r+8}o.prototype.writeDoubleLE=function(t,r,i){return Et(this,t,r,!0,i)},o.prototype.writeDoubleBE=function(t,r,i){return Et(this,t,r,!1,i)},o.prototype.copy=function(t,r,i,p){if(!o.isBuffer(t))throw new TypeError("argument should be a Buffer");if(i||(i=0),!p&&p!==0&&(p=this.length),r>=t.length&&(r=t.length),r||(r=0),p>0&&p<i&&(p=i),p===i||t.length===0||this.length===0)return 0;if(r<0)throw new RangeError("targetStart out of bounds");if(i<0||i>=this.length)throw new RangeError("Index out of range");if(p<0)throw new RangeError("sourceEnd out of bounds");p>this.length&&(p=this.length),t.length-r<p-i&&(p=t.length-r+i);var l=p-i;return this===t&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(r,i,p):Uint8Array.prototype.set.call(t,this.subarray(i,p),r),l},o.prototype.fill=function(t,r,i,p){if(typeof t=="string"){if(typeof r=="string"?(p=r,r=0,i=this.length):typeof i=="string"&&(p=i,i=this.length),p!==void 0&&typeof p!="string")throw new TypeError("encoding must be a string");if(typeof p=="string"&&!o.isEncoding(p))throw new TypeError("Unknown encoding: "+p);if(t.length===1){var l=t.charCodeAt(0);(p==="utf8"&&l<128||p==="latin1")&&(t=l)}}else typeof t=="number"?t=t&255:typeof t=="boolean"&&(t=Number(t));if(r<0||this.length<r||this.length<i)throw new RangeError("Out of range index");if(i<=r)return this;r=r>>>0,i=i===void 0?this.length:i>>>0,t||(t=0);var h;if(typeof t=="number")for(h=r;h<i;++h)this[h]=t;else{var y=o.isBuffer(t)?t:o.from(t,p),g=y.length;if(g===0)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(h=0;h<i-r;++h)this[h+r]=y[h%g]}return this};var yr=/[^+/0-9A-Za-z-_]/g;function wr(e){if(e=e.split("=")[0],e=e.trim().replace(yr,""),e.length<2)return"";for(;e.length%4!==0;)e=e+"=";return e}function G(e,t){t=t||1/0;for(var r,i=e.length,p=null,l=[],h=0;h<i;++h){if(r=e.charCodeAt(h),r>55295&&r<57344){if(!p){if(r>56319){(t-=3)>-1&&l.push(239,191,189);continue}else if(h+1===i){(t-=3)>-1&&l.push(239,191,189);continue}p=r;continue}if(r<56320){(t-=3)>-1&&l.push(239,191,189),p=r;continue}r=(p-55296<<10|r-56320)+65536}else p&&(t-=3)>-1&&l.push(239,191,189);if(p=null,r<128){if((t-=1)<0)break;l.push(r)}else if(r<2048){if((t-=2)<0)break;l.push(r>>6|192,r&63|128)}else if(r<65536){if((t-=3)<0)break;l.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((t-=4)<0)break;l.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else throw new Error("Invalid code point")}return l}function gr(e){for(var t=[],r=0;r<e.length;++r)t.push(e.charCodeAt(r)&255);return t}function vr(e,t){for(var r,i,p,l=[],h=0;h<e.length&&!((t-=2)<0);++h)r=e.charCodeAt(h),i=r>>8,p=r%256,l.push(p),l.push(i);return l}function bt(e){return a.toByteArray(wr(e))}function q(e,t,r,i){for(var p=0;p<i&&!(p+r>=t.length||p>=e.length);++p)t[p+r]=e[p];return p}function I(e,t){return e instanceof t||e!=null&&e.constructor!=null&&e.constructor.name!=null&&e.constructor.name===t.name}function V(e){return e!==e}var Er=function(){for(var e="0123456789abcdef",t=new Array(256),r=0;r<16;++r)for(var i=r*16,p=0;p<16;++p)t[i+p]=e[r]+e[p];return t}()})(Mt);/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */(function(n,a){var s=Mt,c=s.Buffer;function f(u,o){for(var x in u)o[x]=u[x]}c.from&&c.alloc&&c.allocUnsafe&&c.allocUnsafeSlow?n.exports=s:(f(s,a),a.Buffer=m);function m(u,o,x){return c(u,o,x)}m.prototype=Object.create(c.prototype),f(c,m),m.from=function(u,o,x){if(typeof u=="number")throw new TypeError("Argument must not be a number");return c(u,o,x)},m.alloc=function(u,o,x){if(typeof u!="number")throw new TypeError("Argument must be a number");var w=c(u);return o!==void 0?typeof x=="string"?w.fill(o,x):w.fill(o):w.fill(0),w},m.allocUnsafe=function(u){if(typeof u!="number")throw new TypeError("Argument must be a number");return c(u)},m.allocUnsafeSlow=function(u){if(typeof u!="number")throw new TypeError("Argument must be a number");return s.SlowBuffer(u)}})(et,et.exports);var Ct=et.exports,Lt=Ct.Buffer;function H(n,a){this._block=Lt.alloc(n),this._finalSize=a,this._blockSize=n,this._len=0}H.prototype.update=function(n,a){typeof n=="string"&&(a=a||"utf8",n=Lt.from(n,a));for(var s=this._block,c=this._blockSize,f=n.length,m=this._len,u=0;u<f;){for(var o=m%c,x=Math.min(f-u,c-o),w=0;w<x;w++)s[o+w]=n[u+w];m+=x,u+=x,m%c===0&&this._update(s)}return this._len+=f,this};H.prototype.digest=function(n){var a=this._len%this._blockSize;this._block[a]=128,this._block.fill(0,a+1),a>=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 c=(s&4294967295)>>>0,f=(s-c)/4294967296;this._block.writeUInt32BE(f,this._blockSize-8),this._block.writeUInt32BE(c,this._blockSize-4)}this._update(this._block);var m=this._hash();return n?m.toString(n):m};H.prototype._update=function(){throw new Error("_update must be implemented by subclass")};var Wr=H,Hr=Nr,qt=Wr,Zr=Ct.Buffer,Kr=[1518500249,1859775393,-1894007588,-899497514],Yr=new Array(80);function L(){this.init(),this._w=Yr,qt.call(this,64,56)}Hr(L,qt);L.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function Xr(n){return n<<1|n>>>31}function Gr(n){return n<<5|n>>>27}function Vr(n){return n<<30|n>>>2}function Qr(n,a,s,c){return n===0?a&s|~a&c:n===2?a&s|a&c|s&c:a^s^c}L.prototype._update=function(n){for(var a=this._w,s=this._a|0,c=this._b|0,f=this._c|0,m=this._d|0,u=this._e|0,o=0;o<16;++o)a[o]=n.readInt32BE(o*4);for(;o<80;++o)a[o]=Xr(a[o-3]^a[o-8]^a[o-14]^a[o-16]);for(var x=0;x<80;++x){var w=~~(x/20),v=Gr(s)+Qr(w,c,f,m)+u+a[x]+Kr[w]|0;u=m,m=f,f=Vr(c),c=s,s=v}this._a=s+this._a|0,this._b=c+this._b|0,this._c=f+this._c|0,this._d=m+this._d|0,this._e=u+this._e|0};L.prototype._hash=function(){var n=Zr.allocUnsafe(20);return n.writeInt32BE(this._a|0,0),n.writeInt32BE(this._b|0,4),n.writeInt32BE(this._c|0,8),n.writeInt32BE(this._d|0,12),n.writeInt32BE(this._e|0,16),n};var te=L;const re=Nt(te),ut=new Error("File system not available.");function ee(n,a,s){throw ut}function $t(n){throw ut}function ie(n){throw ut}const ne=async n=>$t();function ae(n){let a="";for(let s=0;s<n.length;s+=2)a+=String.fromCharCode(parseInt(n.substr(s,2),16));return btoa(a)}const Z=(n,a="sha1")=>{if(a!=="sha1")throw new Error("Only sha1 algorithm is available.");const s=new re;return ae(s.update(n).digest("hex"))},ft=async n=>{const a=new At,{name:s,revision:c,documentType:f,created:m,lastModified:u}=n,o={name:s,revision:c,documentType:f,created:m,lastModified:u};return a.file("header.json",JSON.stringify(o,null,2)),a.file("state.json",JSON.stringify(n.initialState||{},null,2)),a.file("operations.json",JSON.stringify(n.operations,null,2)),Object.keys(n.attachments).forEach(w=>{const{data:v,...F}=n.attachments[w];a.file(w,v,{base64:!0,createFolders:!0,comment:JSON.stringify(F)})}),a},Jt=async(n,a,s,c)=>{await(await ft(n)).generateAsync({type:"uint8array",streamFiles:!0});const m=c??n.name,u=`.${s}.zip`;return ee(a,m.endsWith(u)?m:`${m}${u}`)},oe=async(n,a)=>{const c=await(await ft(n)).generateAsync({type:"blob"}),f=await a.createWritable();await f.write(c),await f.close()},it=async(n,a)=>{const s=$t();return Pt(s,a)},Pt=async(n,a)=>{const s=new At;return await s.loadAsync(n),pe(s,a)};async function pe(n,a){const s=n.file("state.json");if(!s)throw new Error("Initial state not found");const c=await s.async("string"),f=JSON.parse(c),m=n.file("header.json");let u=null;m&&(u=JSON.parse(await m.async("string")));const o=n.file("operations.json");if(!o)throw new Error("Operations history not found");const x=JSON.parse(await o.async("string")),w={...f,...u,initialState:f,operations:[],attachments:{...f.attachments}};let v=x.slice(0,u==null?void 0:u.revision).reduce((F,U)=>a(F,U),w);return u&&(v={...v,...u,operations:[...v.operations,...x.slice(u.revision)]}),v}function Wt(n){const a=n.replace(/^.*\./,"")||void 0,s=n.replace(/^.*[/\\]/,"")||void 0;return{extension:a,fileName:s}}async function se(n){const{buffer:a,mimeType:s="application/octet-stream"}=await ie(),c=Wt(n),f=a.toString("base64");return{data:f,hash:Z(f),mimeType:s,...c}}async function ce(n){const a=await ne(),s=Or.getType(n)||"application/octet-stream",c=Wt(n),f=a.toString("base64");return{data:f,hash:Z(f),mimeType:s,...c}}function J(n,a,s){const c=Gt(n),f=Yt(s);return a.reduce((m,u)=>f(m,u),c)}function le(n,a){return{...n,name:a}}function ue(n,a,s){const c=Math.min(a,n.revision),f=n.operations.slice(0,n.revision-c);return{...J(n.initialState,f,s),operations:n.operations,revision:n.revision-c}}function fe(n,a,s){const c=n.operations.length-n.revision;if(!c)throw new Error("There is no UNDO operation to REDO");const f=a<c?a:c,m=n.operations.slice(0,n.revision+f);return{...J(n.initialState,m,s),operations:n.operations,revision:n.revision+f}}function he(n,a,s,c){a=a||0,s=s||n.operations.length;const f=n.operations.slice(a,s),m=n.operations.slice(0,a),u=n.operations.slice(s),o=J(n.initialState,m.concat(f),c),{name:x,state:w}=o;return J(n.initialState,[...m,ht({name:x,state:w},f.length),...u],c)}function me(n,a){return{...n,name:a.name,state:a.state??{}}}const Ht="SET_NAME",K="UNDO",Y="REDO",C="PRUNE",Zt="LOAD_STATE";function xe(n,a){return[K,Y,C].includes(a.type)?n.revision:n.revision+1}function de(n,a){return{...n,revision:xe(n,a),lastModified:new Date().toISOString()}}function ye(n,a){if([K,Y,C,C].includes(a.type))return n;const s=n.operations.slice(0,n.revision);return{...n,operations:[...s,{...a,index:s.length,timestamp:new Date().toISOString(),hash:""}]}}function we(n,a){let s=ye(n,a);return s=de(s,a),s}function ge(n,a,s){switch(kt().parse(a),a.type){case Ht:return le(n,a.input);case K:return ue(n,a.input,s);case Y:return fe(n,a.input,s);case C:return he(n,a.input.start,a.input.end,s);case Zt:return me(n,a.input.state);default:return n}}function Kt(n,a,s){let c=n;return nt(a)&&(c=ge(c,a,s)),c=we(c,a),c=R.produce(c,f=>{const m=s(f.state,a);if(m)return R.castDraft({...c,state:m})}),R.produce(c,f=>{f.operations[f.operations.length-1].hash=Vt(f),!nt(a)&&a.attachments&&a.attachments.forEach(m=>{const{hash:u,...o}=m;f.attachments[u]={...o}})})}function nt(n){return[Ht,K,Y,C,Zt].includes(n.type)}function D(n,a,s,c){if(!n)throw new Error("Empty action type");if(typeof n!="string")throw new Error(`Invalid action type: ${n}`);const f=s?{type:n,input:a,attachments:s}:{type:n,input:a};return c==null||c().parse(f),f}function Yt(n,a=Kt){return(s,c)=>a(s,c,n)}const Xt=(n,a)=>({name:"",documentType:"",revision:0,created:new Date().toISOString(),lastModified:new Date().toISOString(),attachments:{},...n,state:(a==null?void 0:a(n==null?void 0:n.state))??(n==null?void 0:n.state)??{}}),Gt=(n,a)=>{const s=Xt(n,a);return{...s,initialState:s,operations:[]}},Vt=n=>Z(_r(n.state)),ve=(n,a=1e3)=>{const s=Math.random()*a;return Z(`${(n??new Date).toISOString()}${s}`)};function M(n){return R.castImmutable(R.freeze(n,!0))}const Qt=n=>D("SET_NAME",n,void 0,st),tr=(n=1)=>D("UNDO",n,void 0,ct),rr=(n=1)=>D("REDO",n,void 0,pt),er=(n,a)=>D("PRUNE",{start:n,end:a},void 0,ot),ht=(n,a)=>D("LOAD_STATE",{state:n,operations:a},void 0,at),Ee=Object.freeze(Object.defineProperty({__proto__:null,loadState:ht,prune:er,redo:rr,setName:Qt,undo:tr},Symbol.toStringTag,{value:"Module"}));class be{constructor(a,s){Q(this,"_document");Q(this,"_reducer");this._reducer=a,this._document=s}dispatch(a){return this._document=this._reducer(this._document,a),this}saveToFile(a,s,c){return Jt(this._document,a,s,c)}async loadFromFile(a){this._document=await it(a,this._reducer)}static async stateFromFile(a,s){return await it(a,s)}get state(){return M(this._document.state)}get operations(){return M(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}get initialState(){return M(this._document.initialState)}toDocument(){return M(this._document)}getAttachment(a){return this._document.attachments[a]}setName(a){return this.dispatch(Qt(a)),this}undo(a){return this.dispatch(tr(a)),this}redo(a){return this.dispatch(rr(a)),this}prune(a,s){return this.dispatch(er(a,s)),this}loadState(a,s){return this.dispatch(ht(a,s)),this}}function Fe(n,a){a.forEach(s=>{Object.getOwnPropertyNames(s.prototype).forEach(c=>{Object.defineProperty(n.prototype,c,Object.getOwnPropertyDescriptor(s.prototype,c)||Object.create(null))})})}exports.BaseActions=Ee;exports.BaseDocument=be;exports.applyMixins=Fe;exports.baseReducer=Kt;exports.createAction=D;exports.createDocument=Gt;exports.createExtendedState=Xt;exports.createReducer=Yt;exports.createZip=ft;exports.getLocalFile=ce;exports.getRemoteFile=se;exports.hashDocument=Vt;exports.hashKey=ve;exports.isBaseAction=nt;exports.loadFromFile=it;exports.loadFromInput=Pt;exports.readOnly=M;exports.saveToFile=Jt;exports.saveToFileHandle=oe;exports.zod=Ir;
6
+ */(function(n){var a=H,s=lt,c=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;n.Buffer=o,n.SlowBuffer=nr,n.INSPECT_MAX_BYTES=50;var f=2147483647;n.kMaxLength=f,o.TYPED_ARRAY_SUPPORT=h(),!o.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 h(){try{var i=new Uint8Array(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,Uint8Array.prototype),Object.setPrototypeOf(i,t),i.foo()===42}catch{return!1}}Object.defineProperty(o.prototype,"parent",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.buffer}}),Object.defineProperty(o.prototype,"offset",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.byteOffset}});function u(i){if(i>f)throw new RangeError('The value "'+i+'" is invalid for option "size"');var t=new Uint8Array(i);return Object.setPrototypeOf(t,o.prototype),t}function o(i,t,r){if(typeof i=="number"){if(typeof t=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return F(i)}return x(i,t,r)}o.poolSize=8192;function x(i,t,r){if(typeof i=="string")return U(i,t);if(ArrayBuffer.isView(i))return O(i);if(i==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof i);if(I(i,ArrayBuffer)||i&&I(i.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(I(i,SharedArrayBuffer)||i&&I(i.buffer,SharedArrayBuffer)))return N(i,t,r);if(typeof i=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');var e=i.valueOf&&i.valueOf();if(e!=null&&e!==i)return o.from(e,t,r);var p=er(i);if(p)return p;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof i[Symbol.toPrimitive]=="function")return o.from(i[Symbol.toPrimitive]("string"),t,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof i)}o.from=function(i,t,r){return x(i,t,r)},Object.setPrototypeOf(o.prototype,Uint8Array.prototype),Object.setPrototypeOf(o,Uint8Array);function w(i){if(typeof i!="number")throw new TypeError('"size" argument must be of type number');if(i<0)throw new RangeError('The value "'+i+'" is invalid for option "size"')}function v(i,t,r){return w(i),i<=0?u(i):t!==void 0?typeof r=="string"?u(i).fill(t,r):u(i).fill(t):u(i)}o.alloc=function(i,t,r){return v(i,t,r)};function F(i){return w(i),u(i<0?0:G(i)|0)}o.allocUnsafe=function(i){return F(i)},o.allocUnsafeSlow=function(i){return F(i)};function U(i,t){if((typeof t!="string"||t==="")&&(t="utf8"),!o.isEncoding(t))throw new TypeError("Unknown encoding: "+t);var r=mt(i,t)|0,e=u(r),p=e.write(i,t);return p!==r&&(e=e.slice(0,p)),e}function B(i){for(var t=i.length<0?0:G(i.length)|0,r=u(t),e=0;e<t;e+=1)r[e]=i[e]&255;return r}function O(i){if(I(i,Uint8Array)){var t=new Uint8Array(i);return N(t.buffer,t.byteOffset,t.byteLength)}return B(i)}function N(i,t,r){if(t<0||i.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(i.byteLength<t+(r||0))throw new RangeError('"length" is outside of buffer bounds');var e;return t===void 0&&r===void 0?e=new Uint8Array(i):r===void 0?e=new Uint8Array(i,t):e=new Uint8Array(i,t,r),Object.setPrototypeOf(e,o.prototype),e}function er(i){if(o.isBuffer(i)){var t=G(i.length)|0,r=u(t);return r.length===0||i.copy(r,0,0,t),r}if(i.length!==void 0)return typeof i.length!="number"||Q(i.length)?u(0):B(i);if(i.type==="Buffer"&&Array.isArray(i.data))return B(i.data)}function G(i){if(i>=f)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+f.toString(16)+" bytes");return i|0}function nr(i){return+i!=i&&(i=0),o.alloc(+i)}o.isBuffer=function(t){return t!=null&&t._isBuffer===!0&&t!==o.prototype},o.compare=function(t,r){if(I(t,Uint8Array)&&(t=o.from(t,t.offset,t.byteLength)),I(r,Uint8Array)&&(r=o.from(r,r.offset,r.byteLength)),!o.isBuffer(t)||!o.isBuffer(r))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===r)return 0;for(var e=t.length,p=r.length,l=0,m=Math.min(e,p);l<m;++l)if(t[l]!==r[l]){e=t[l],p=r[l];break}return e<p?-1:p<e?1:0},o.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}},o.concat=function(t,r){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(t.length===0)return o.alloc(0);var e;if(r===void 0)for(r=0,e=0;e<t.length;++e)r+=t[e].length;var p=o.allocUnsafe(r),l=0;for(e=0;e<t.length;++e){var m=t[e];if(I(m,Uint8Array))l+m.length>p.length?o.from(m).copy(p,l):Uint8Array.prototype.set.call(p,m,l);else if(o.isBuffer(m))m.copy(p,l);else throw new TypeError('"list" argument must be an Array of Buffers');l+=m.length}return p};function mt(i,t){if(o.isBuffer(i))return i.length;if(ArrayBuffer.isView(i)||I(i,ArrayBuffer))return i.byteLength;if(typeof i!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof i);var r=i.length,e=arguments.length>2&&arguments[2]===!0;if(!e&&r===0)return 0;for(var p=!1;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return V(i).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return r*2;case"hex":return r>>>1;case"base64":return bt(i).length;default:if(p)return e?-1:V(i).length;t=(""+t).toLowerCase(),p=!0}}o.byteLength=mt;function ar(i,t,r){var e=!1;if((t===void 0||t<0)&&(t=0),t>this.length||((r===void 0||r>this.length)&&(r=this.length),r<=0)||(r>>>=0,t>>>=0,r<=t))return"";for(i||(i="utf8");;)switch(i){case"hex":return xr(this,t,r);case"utf8":case"utf-8":return yt(this,t,r);case"ascii":return hr(this,t,r);case"latin1":case"binary":return mr(this,t,r);case"base64":return ur(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return dr(this,t,r);default:if(e)throw new TypeError("Unknown encoding: "+i);i=(i+"").toLowerCase(),e=!0}}o.prototype._isBuffer=!0;function k(i,t,r){var e=i[t];i[t]=i[r],i[r]=e}o.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 r=0;r<t;r+=2)k(this,r,r+1);return this},o.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 r=0;r<t;r+=4)k(this,r,r+3),k(this,r+1,r+2);return this},o.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 r=0;r<t;r+=8)k(this,r,r+7),k(this,r+1,r+6),k(this,r+2,r+5),k(this,r+3,r+4);return this},o.prototype.toString=function(){var t=this.length;return t===0?"":arguments.length===0?yt(this,0,t):ar.apply(this,arguments)},o.prototype.toLocaleString=o.prototype.toString,o.prototype.equals=function(t){if(!o.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t?!0:o.compare(this,t)===0},o.prototype.inspect=function(){var t="",r=n.INSPECT_MAX_BYTES;return t=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(t+=" ... "),"<Buffer "+t+">"},c&&(o.prototype[c]=o.prototype.inspect),o.prototype.compare=function(t,r,e,p,l){if(I(t,Uint8Array)&&(t=o.from(t,t.offset,t.byteLength)),!o.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(r===void 0&&(r=0),e===void 0&&(e=t?t.length:0),p===void 0&&(p=0),l===void 0&&(l=this.length),r<0||e>t.length||p<0||l>this.length)throw new RangeError("out of range index");if(p>=l&&r>=e)return 0;if(p>=l)return-1;if(r>=e)return 1;if(r>>>=0,e>>>=0,p>>>=0,l>>>=0,this===t)return 0;for(var m=l-p,y=e-r,g=Math.min(m,y),E=this.slice(p,l),A=t.slice(r,e),b=0;b<g;++b)if(E[b]!==A[b]){m=E[b],y=A[b];break}return m<y?-1:y<m?1:0};function xt(i,t,r,e,p){if(i.length===0)return-1;if(typeof r=="string"?(e=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,Q(r)&&(r=p?0:i.length-1),r<0&&(r=i.length+r),r>=i.length){if(p)return-1;r=i.length-1}else if(r<0)if(p)r=0;else return-1;if(typeof t=="string"&&(t=o.from(t,e)),o.isBuffer(t))return t.length===0?-1:dt(i,t,r,e,p);if(typeof t=="number")return t=t&255,typeof Uint8Array.prototype.indexOf=="function"?p?Uint8Array.prototype.indexOf.call(i,t,r):Uint8Array.prototype.lastIndexOf.call(i,t,r):dt(i,[t],r,e,p);throw new TypeError("val must be string, number or Buffer")}function dt(i,t,r,e,p){var l=1,m=i.length,y=t.length;if(e!==void 0&&(e=String(e).toLowerCase(),e==="ucs2"||e==="ucs-2"||e==="utf16le"||e==="utf-16le")){if(i.length<2||t.length<2)return-1;l=2,m/=2,y/=2,r/=2}function g(Ft,_t){return l===1?Ft[_t]:Ft.readUInt16BE(_t*l)}var E;if(p){var A=-1;for(E=r;E<m;E++)if(g(i,E)===g(t,A===-1?0:E-A)){if(A===-1&&(A=E),E-A+1===y)return A*l}else A!==-1&&(E-=E-A),A=-1}else for(r+y>m&&(r=m-y),E=r;E>=0;E--){for(var b=!0,$=0;$<y;$++)if(g(i,E+$)!==g(t,$)){b=!1;break}if(b)return E}return-1}o.prototype.includes=function(t,r,e){return this.indexOf(t,r,e)!==-1},o.prototype.indexOf=function(t,r,e){return xt(this,t,r,e,!0)},o.prototype.lastIndexOf=function(t,r,e){return xt(this,t,r,e,!1)};function or(i,t,r,e){r=Number(r)||0;var p=i.length-r;e?(e=Number(e),e>p&&(e=p)):e=p;var l=t.length;e>l/2&&(e=l/2);for(var m=0;m<e;++m){var y=parseInt(t.substr(m*2,2),16);if(Q(y))return m;i[r+m]=y}return m}function pr(i,t,r,e){return q(V(t,i.length-r),i,r,e)}function sr(i,t,r,e){return q(gr(t),i,r,e)}function cr(i,t,r,e){return q(bt(t),i,r,e)}function lr(i,t,r,e){return q(vr(t,i.length-r),i,r,e)}o.prototype.write=function(t,r,e,p){if(r===void 0)p="utf8",e=this.length,r=0;else if(e===void 0&&typeof r=="string")p=r,e=this.length,r=0;else if(isFinite(r))r=r>>>0,isFinite(e)?(e=e>>>0,p===void 0&&(p="utf8")):(p=e,e=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");var l=this.length-r;if((e===void 0||e>l)&&(e=l),t.length>0&&(e<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");p||(p="utf8");for(var m=!1;;)switch(p){case"hex":return or(this,t,r,e);case"utf8":case"utf-8":return pr(this,t,r,e);case"ascii":case"latin1":case"binary":return sr(this,t,r,e);case"base64":return cr(this,t,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return lr(this,t,r,e);default:if(m)throw new TypeError("Unknown encoding: "+p);p=(""+p).toLowerCase(),m=!0}},o.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function ur(i,t,r){return t===0&&r===i.length?a.fromByteArray(i):a.fromByteArray(i.slice(t,r))}function yt(i,t,r){r=Math.min(i.length,r);for(var e=[],p=t;p<r;){var l=i[p],m=null,y=l>239?4:l>223?3:l>191?2:1;if(p+y<=r){var g,E,A,b;switch(y){case 1:l<128&&(m=l);break;case 2:g=i[p+1],(g&192)===128&&(b=(l&31)<<6|g&63,b>127&&(m=b));break;case 3:g=i[p+1],E=i[p+2],(g&192)===128&&(E&192)===128&&(b=(l&15)<<12|(g&63)<<6|E&63,b>2047&&(b<55296||b>57343)&&(m=b));break;case 4:g=i[p+1],E=i[p+2],A=i[p+3],(g&192)===128&&(E&192)===128&&(A&192)===128&&(b=(l&15)<<18|(g&63)<<12|(E&63)<<6|A&63,b>65535&&b<1114112&&(m=b))}}m===null?(m=65533,y=1):m>65535&&(m-=65536,e.push(m>>>10&1023|55296),m=56320|m&1023),e.push(m),p+=y}return fr(e)}var wt=4096;function fr(i){var t=i.length;if(t<=wt)return String.fromCharCode.apply(String,i);for(var r="",e=0;e<t;)r+=String.fromCharCode.apply(String,i.slice(e,e+=wt));return r}function hr(i,t,r){var e="";r=Math.min(i.length,r);for(var p=t;p<r;++p)e+=String.fromCharCode(i[p]&127);return e}function mr(i,t,r){var e="";r=Math.min(i.length,r);for(var p=t;p<r;++p)e+=String.fromCharCode(i[p]);return e}function xr(i,t,r){var e=i.length;(!t||t<0)&&(t=0),(!r||r<0||r>e)&&(r=e);for(var p="",l=t;l<r;++l)p+=Er[i[l]];return p}function dr(i,t,r){for(var e=i.slice(t,r),p="",l=0;l<e.length-1;l+=2)p+=String.fromCharCode(e[l]+e[l+1]*256);return p}o.prototype.slice=function(t,r){var e=this.length;t=~~t,r=r===void 0?e:~~r,t<0?(t+=e,t<0&&(t=0)):t>e&&(t=e),r<0?(r+=e,r<0&&(r=0)):r>e&&(r=e),r<t&&(r=t);var p=this.subarray(t,r);return Object.setPrototypeOf(p,o.prototype),p};function _(i,t,r){if(i%1!==0||i<0)throw new RangeError("offset is not uint");if(i+t>r)throw new RangeError("Trying to access beyond buffer length")}o.prototype.readUintLE=o.prototype.readUIntLE=function(t,r,e){t=t>>>0,r=r>>>0,e||_(t,r,this.length);for(var p=this[t],l=1,m=0;++m<r&&(l*=256);)p+=this[t+m]*l;return p},o.prototype.readUintBE=o.prototype.readUIntBE=function(t,r,e){t=t>>>0,r=r>>>0,e||_(t,r,this.length);for(var p=this[t+--r],l=1;r>0&&(l*=256);)p+=this[t+--r]*l;return p},o.prototype.readUint8=o.prototype.readUInt8=function(t,r){return t=t>>>0,r||_(t,1,this.length),this[t]},o.prototype.readUint16LE=o.prototype.readUInt16LE=function(t,r){return t=t>>>0,r||_(t,2,this.length),this[t]|this[t+1]<<8},o.prototype.readUint16BE=o.prototype.readUInt16BE=function(t,r){return t=t>>>0,r||_(t,2,this.length),this[t]<<8|this[t+1]},o.prototype.readUint32LE=o.prototype.readUInt32LE=function(t,r){return t=t>>>0,r||_(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+this[t+3]*16777216},o.prototype.readUint32BE=o.prototype.readUInt32BE=function(t,r){return t=t>>>0,r||_(t,4,this.length),this[t]*16777216+(this[t+1]<<16|this[t+2]<<8|this[t+3])},o.prototype.readIntLE=function(t,r,e){t=t>>>0,r=r>>>0,e||_(t,r,this.length);for(var p=this[t],l=1,m=0;++m<r&&(l*=256);)p+=this[t+m]*l;return l*=128,p>=l&&(p-=Math.pow(2,8*r)),p},o.prototype.readIntBE=function(t,r,e){t=t>>>0,r=r>>>0,e||_(t,r,this.length);for(var p=r,l=1,m=this[t+--p];p>0&&(l*=256);)m+=this[t+--p]*l;return l*=128,m>=l&&(m-=Math.pow(2,8*r)),m},o.prototype.readInt8=function(t,r){return t=t>>>0,r||_(t,1,this.length),this[t]&128?(255-this[t]+1)*-1:this[t]},o.prototype.readInt16LE=function(t,r){t=t>>>0,r||_(t,2,this.length);var e=this[t]|this[t+1]<<8;return e&32768?e|4294901760:e},o.prototype.readInt16BE=function(t,r){t=t>>>0,r||_(t,2,this.length);var e=this[t+1]|this[t]<<8;return e&32768?e|4294901760:e},o.prototype.readInt32LE=function(t,r){return t=t>>>0,r||_(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},o.prototype.readInt32BE=function(t,r){return t=t>>>0,r||_(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},o.prototype.readFloatLE=function(t,r){return t=t>>>0,r||_(t,4,this.length),s.read(this,t,!0,23,4)},o.prototype.readFloatBE=function(t,r){return t=t>>>0,r||_(t,4,this.length),s.read(this,t,!1,23,4)},o.prototype.readDoubleLE=function(t,r){return t=t>>>0,r||_(t,8,this.length),s.read(this,t,!0,52,8)},o.prototype.readDoubleBE=function(t,r){return t=t>>>0,r||_(t,8,this.length),s.read(this,t,!1,52,8)};function S(i,t,r,e,p,l){if(!o.isBuffer(i))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>p||t<l)throw new RangeError('"value" argument is out of bounds');if(r+e>i.length)throw new RangeError("Index out of range")}o.prototype.writeUintLE=o.prototype.writeUIntLE=function(t,r,e,p){if(t=+t,r=r>>>0,e=e>>>0,!p){var l=Math.pow(2,8*e)-1;S(this,t,r,e,l,0)}var m=1,y=0;for(this[r]=t&255;++y<e&&(m*=256);)this[r+y]=t/m&255;return r+e},o.prototype.writeUintBE=o.prototype.writeUIntBE=function(t,r,e,p){if(t=+t,r=r>>>0,e=e>>>0,!p){var l=Math.pow(2,8*e)-1;S(this,t,r,e,l,0)}var m=e-1,y=1;for(this[r+m]=t&255;--m>=0&&(y*=256);)this[r+m]=t/y&255;return r+e},o.prototype.writeUint8=o.prototype.writeUInt8=function(t,r,e){return t=+t,r=r>>>0,e||S(this,t,r,1,255,0),this[r]=t&255,r+1},o.prototype.writeUint16LE=o.prototype.writeUInt16LE=function(t,r,e){return t=+t,r=r>>>0,e||S(this,t,r,2,65535,0),this[r]=t&255,this[r+1]=t>>>8,r+2},o.prototype.writeUint16BE=o.prototype.writeUInt16BE=function(t,r,e){return t=+t,r=r>>>0,e||S(this,t,r,2,65535,0),this[r]=t>>>8,this[r+1]=t&255,r+2},o.prototype.writeUint32LE=o.prototype.writeUInt32LE=function(t,r,e){return t=+t,r=r>>>0,e||S(this,t,r,4,4294967295,0),this[r+3]=t>>>24,this[r+2]=t>>>16,this[r+1]=t>>>8,this[r]=t&255,r+4},o.prototype.writeUint32BE=o.prototype.writeUInt32BE=function(t,r,e){return t=+t,r=r>>>0,e||S(this,t,r,4,4294967295,0),this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=t&255,r+4},o.prototype.writeIntLE=function(t,r,e,p){if(t=+t,r=r>>>0,!p){var l=Math.pow(2,8*e-1);S(this,t,r,e,l-1,-l)}var m=0,y=1,g=0;for(this[r]=t&255;++m<e&&(y*=256);)t<0&&g===0&&this[r+m-1]!==0&&(g=1),this[r+m]=(t/y>>0)-g&255;return r+e},o.prototype.writeIntBE=function(t,r,e,p){if(t=+t,r=r>>>0,!p){var l=Math.pow(2,8*e-1);S(this,t,r,e,l-1,-l)}var m=e-1,y=1,g=0;for(this[r+m]=t&255;--m>=0&&(y*=256);)t<0&&g===0&&this[r+m+1]!==0&&(g=1),this[r+m]=(t/y>>0)-g&255;return r+e},o.prototype.writeInt8=function(t,r,e){return t=+t,r=r>>>0,e||S(this,t,r,1,127,-128),t<0&&(t=255+t+1),this[r]=t&255,r+1},o.prototype.writeInt16LE=function(t,r,e){return t=+t,r=r>>>0,e||S(this,t,r,2,32767,-32768),this[r]=t&255,this[r+1]=t>>>8,r+2},o.prototype.writeInt16BE=function(t,r,e){return t=+t,r=r>>>0,e||S(this,t,r,2,32767,-32768),this[r]=t>>>8,this[r+1]=t&255,r+2},o.prototype.writeInt32LE=function(t,r,e){return t=+t,r=r>>>0,e||S(this,t,r,4,2147483647,-2147483648),this[r]=t&255,this[r+1]=t>>>8,this[r+2]=t>>>16,this[r+3]=t>>>24,r+4},o.prototype.writeInt32BE=function(t,r,e){return t=+t,r=r>>>0,e||S(this,t,r,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=t&255,r+4};function gt(i,t,r,e,p,l){if(r+e>i.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function vt(i,t,r,e,p){return t=+t,r=r>>>0,p||gt(i,t,r,4),s.write(i,t,r,e,23,4),r+4}o.prototype.writeFloatLE=function(t,r,e){return vt(this,t,r,!0,e)},o.prototype.writeFloatBE=function(t,r,e){return vt(this,t,r,!1,e)};function Et(i,t,r,e,p){return t=+t,r=r>>>0,p||gt(i,t,r,8),s.write(i,t,r,e,52,8),r+8}o.prototype.writeDoubleLE=function(t,r,e){return Et(this,t,r,!0,e)},o.prototype.writeDoubleBE=function(t,r,e){return Et(this,t,r,!1,e)},o.prototype.copy=function(t,r,e,p){if(!o.isBuffer(t))throw new TypeError("argument should be a Buffer");if(e||(e=0),!p&&p!==0&&(p=this.length),r>=t.length&&(r=t.length),r||(r=0),p>0&&p<e&&(p=e),p===e||t.length===0||this.length===0)return 0;if(r<0)throw new RangeError("targetStart out of bounds");if(e<0||e>=this.length)throw new RangeError("Index out of range");if(p<0)throw new RangeError("sourceEnd out of bounds");p>this.length&&(p=this.length),t.length-r<p-e&&(p=t.length-r+e);var l=p-e;return this===t&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(r,e,p):Uint8Array.prototype.set.call(t,this.subarray(e,p),r),l},o.prototype.fill=function(t,r,e,p){if(typeof t=="string"){if(typeof r=="string"?(p=r,r=0,e=this.length):typeof e=="string"&&(p=e,e=this.length),p!==void 0&&typeof p!="string")throw new TypeError("encoding must be a string");if(typeof p=="string"&&!o.isEncoding(p))throw new TypeError("Unknown encoding: "+p);if(t.length===1){var l=t.charCodeAt(0);(p==="utf8"&&l<128||p==="latin1")&&(t=l)}}else typeof t=="number"?t=t&255:typeof t=="boolean"&&(t=Number(t));if(r<0||this.length<r||this.length<e)throw new RangeError("Out of range index");if(e<=r)return this;r=r>>>0,e=e===void 0?this.length:e>>>0,t||(t=0);var m;if(typeof t=="number")for(m=r;m<e;++m)this[m]=t;else{var y=o.isBuffer(t)?t:o.from(t,p),g=y.length;if(g===0)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(m=0;m<e-r;++m)this[m+r]=y[m%g]}return this};var yr=/[^+/0-9A-Za-z-_]/g;function wr(i){if(i=i.split("=")[0],i=i.trim().replace(yr,""),i.length<2)return"";for(;i.length%4!==0;)i=i+"=";return i}function V(i,t){t=t||1/0;for(var r,e=i.length,p=null,l=[],m=0;m<e;++m){if(r=i.charCodeAt(m),r>55295&&r<57344){if(!p){if(r>56319){(t-=3)>-1&&l.push(239,191,189);continue}else if(m+1===e){(t-=3)>-1&&l.push(239,191,189);continue}p=r;continue}if(r<56320){(t-=3)>-1&&l.push(239,191,189),p=r;continue}r=(p-55296<<10|r-56320)+65536}else p&&(t-=3)>-1&&l.push(239,191,189);if(p=null,r<128){if((t-=1)<0)break;l.push(r)}else if(r<2048){if((t-=2)<0)break;l.push(r>>6|192,r&63|128)}else if(r<65536){if((t-=3)<0)break;l.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((t-=4)<0)break;l.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else throw new Error("Invalid code point")}return l}function gr(i){for(var t=[],r=0;r<i.length;++r)t.push(i.charCodeAt(r)&255);return t}function vr(i,t){for(var r,e,p,l=[],m=0;m<i.length&&!((t-=2)<0);++m)r=i.charCodeAt(m),e=r>>8,p=r%256,l.push(p),l.push(e);return l}function bt(i){return a.toByteArray(wr(i))}function q(i,t,r,e){for(var p=0;p<e&&!(p+r>=t.length||p>=i.length);++p)t[p+r]=i[p];return p}function I(i,t){return i instanceof t||i!=null&&i.constructor!=null&&i.constructor.name!=null&&i.constructor.name===t.name}function Q(i){return i!==i}var Er=function(){for(var i="0123456789abcdef",t=new Array(256),r=0;r<16;++r)for(var e=r*16,p=0;p<16;++p)t[e+p]=i[r]+i[p];return t}()})(Mt);/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */(function(n,a){var s=Mt,c=s.Buffer;function f(u,o){for(var x in u)o[x]=u[x]}c.from&&c.alloc&&c.allocUnsafe&&c.allocUnsafeSlow?n.exports=s:(f(s,a),a.Buffer=h);function h(u,o,x){return c(u,o,x)}h.prototype=Object.create(c.prototype),f(c,h),h.from=function(u,o,x){if(typeof u=="number")throw new TypeError("Argument must not be a number");return c(u,o,x)},h.alloc=function(u,o,x){if(typeof u!="number")throw new TypeError("Argument must be a number");var w=c(u);return o!==void 0?typeof x=="string"?w.fill(o,x):w.fill(o):w.fill(0),w},h.allocUnsafe=function(u){if(typeof u!="number")throw new TypeError("Argument must be a number");return c(u)},h.allocUnsafeSlow=function(u){if(typeof u!="number")throw new TypeError("Argument must be a number");return s.SlowBuffer(u)}})(it,it.exports);var Ct=it.exports,Lt=Ct.Buffer;function Z(n,a){this._block=Lt.alloc(n),this._finalSize=a,this._blockSize=n,this._len=0}Z.prototype.update=function(n,a){typeof n=="string"&&(a=a||"utf8",n=Lt.from(n,a));for(var s=this._block,c=this._blockSize,f=n.length,h=this._len,u=0;u<f;){for(var o=h%c,x=Math.min(f-u,c-o),w=0;w<x;w++)s[o+w]=n[u+w];h+=x,u+=x,h%c===0&&this._update(s)}return this._len+=f,this};Z.prototype.digest=function(n){var a=this._len%this._blockSize;this._block[a]=128,this._block.fill(0,a+1),a>=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 c=(s&4294967295)>>>0,f=(s-c)/4294967296;this._block.writeUInt32BE(f,this._blockSize-8),this._block.writeUInt32BE(c,this._blockSize-4)}this._update(this._block);var h=this._hash();return n?h.toString(n):h};Z.prototype._update=function(){throw new Error("_update must be implemented by subclass")};var Wr=Z,Hr=Nr,qt=Wr,Zr=Ct.Buffer,Kr=[1518500249,1859775393,-1894007588,-899497514],Yr=new Array(80);function L(){this.init(),this._w=Yr,qt.call(this,64,56)}Hr(L,qt);L.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function Xr(n){return n<<1|n>>>31}function Gr(n){return n<<5|n>>>27}function Vr(n){return n<<30|n>>>2}function Qr(n,a,s,c){return n===0?a&s|~a&c:n===2?a&s|a&c|s&c:a^s^c}L.prototype._update=function(n){for(var a=this._w,s=this._a|0,c=this._b|0,f=this._c|0,h=this._d|0,u=this._e|0,o=0;o<16;++o)a[o]=n.readInt32BE(o*4);for(;o<80;++o)a[o]=Xr(a[o-3]^a[o-8]^a[o-14]^a[o-16]);for(var x=0;x<80;++x){var w=~~(x/20),v=Gr(s)+Qr(w,c,f,h)+u+a[x]+Kr[w]|0;u=h,h=f,f=Vr(c),c=s,s=v}this._a=s+this._a|0,this._b=c+this._b|0,this._c=f+this._c|0,this._d=h+this._d|0,this._e=u+this._e|0};L.prototype._hash=function(){var n=Zr.allocUnsafe(20);return n.writeInt32BE(this._a|0,0),n.writeInt32BE(this._b|0,4),n.writeInt32BE(this._c|0,8),n.writeInt32BE(this._d|0,12),n.writeInt32BE(this._e|0,16),n};var ti=L;const ri=Nt(ti),ut=new Error("File system not available.");function ii(n,a,s){throw ut}function $t(n){throw ut}function ei(n){throw ut}const ni=async n=>$t();function ai(n){let a="";for(let s=0;s<n.length;s+=2)a+=String.fromCharCode(parseInt(n.substr(s,2),16));return btoa(a)}const K=(n,a="sha1")=>{if(a!=="sha1")throw new Error("Only sha1 algorithm is available.");const s=new ri;return ai(s.update(n).digest("hex"))},ft=async n=>{const a=new At,{name:s,revision:c,documentType:f,created:h,lastModified:u}=n,o={name:s,revision:c,documentType:f,created:h,lastModified:u};return a.file("header.json",JSON.stringify(o,null,2)),a.file("state.json",JSON.stringify(n.initialState||{},null,2)),a.file("operations.json",JSON.stringify(n.operations,null,2)),Object.keys(n.attachments).forEach(w=>{const{data:v,...F}=n.attachments[w];a.file(w,v,{base64:!0,createFolders:!0,comment:JSON.stringify(F)})}),a},Jt=async(n,a,s,c)=>{await(await ft(n)).generateAsync({type:"uint8array",streamFiles:!0});const h=c??n.name,u=`.${s}.zip`;return ii(a,h.endsWith(u)?h:`${h}${u}`)},oi=async(n,a)=>{const c=await(await ft(n)).generateAsync({type:"blob"}),f=await a.createWritable();await f.write(c),await f.close()},et=async(n,a)=>{const s=$t();return Pt(s,a)},Pt=async(n,a)=>{const s=new At;return await s.loadAsync(n),pi(s,a)};async function pi(n,a){const s=n.file("state.json");if(!s)throw new Error("Initial state not found");const c=await s.async("string"),f=JSON.parse(c),h=n.file("header.json");let u=null;h&&(u=JSON.parse(await h.async("string")));const o=n.file("operations.json");if(!o)throw new Error("Operations history not found");const x=JSON.parse(await o.async("string")),w={...f,...u,initialState:f,operations:[],attachments:{...f.attachments}};let v=x.slice(0,u==null?void 0:u.revision).reduce((F,U)=>a(F,U),w);return u&&(v={...v,...u,operations:[...v.operations,...x.slice(u.revision)]}),v}function Wt(n){const a=n.replace(/^.*\./,"")||void 0,s=n.replace(/^.*[/\\]/,"")||void 0;return{extension:a,fileName:s}}async function si(n){const{buffer:a,mimeType:s="application/octet-stream"}=await ei(),c=Wt(n),f=a.toString("base64");return{data:f,hash:K(f),mimeType:s,...c}}async function ci(n){const a=await ni(),s=Or.getType(n)||"application/octet-stream",c=Wt(n),f=a.toString("base64");return{data:f,hash:K(f),mimeType:s,...c}}function P(n,a,s,c){const f=Gt(n),h=Yt(s);return a.reduce((u,o)=>h(u,o,c),f)}function li(n,a){return{...n,name:a}}function ui(n,a,s){const c=Math.min(a,n.revision),f=n.operations.slice(0,n.revision-c);return{...P(n.initialState,f,s),operations:n.operations,revision:n.revision-c}}function fi(n,a,s){const c=n.operations.length-n.revision;if(!c)throw new Error("There is no UNDO operation to REDO");const f=a<c?a:c,h=n.operations.slice(0,n.revision+f);return{...P(n.initialState,h,s),operations:n.operations,revision:n.revision+f}}function hi(n,a,s,c){a=a||0,s=s||n.operations.length;const f=n.operations.slice(a,s),h=n.operations.slice(0,a),u=n.operations.slice(s),o=P(n.initialState,h.concat(f),c),{name:x,state:w}=o;return P(n.initialState,[...h,ht({name:x,state:w},f.length),...u],c)}function mi(n,a){return{...n,name:a.name,state:a.state??{}}}const Ht="SET_NAME",Y="UNDO",X="REDO",C="PRUNE",Zt="LOAD_STATE";function xi(n,a){return[Y,X,C].includes(a.type)?n.revision:n.revision+1}function di(n,a){return{...n,revision:xi(n,a),lastModified:new Date().toISOString()}}function yi(n,a){if([Y,X,C,C].includes(a.type))return n;const s=n.operations.slice(0,n.revision);return{...n,operations:[...s,{...a,index:s.length,timestamp:new Date().toISOString(),hash:""}]}}function wi(n,a){let s=yi(n,a);return s=di(s,a),s}function gi(n,a,s){switch(kt().parse(a),a.type){case Ht:return li(n,a.input);case Y:return ui(n,a.input,s);case X:return fi(n,a.input,s);case C:return hi(n,a.input.start,a.input.end,s);case Zt:return mi(n,a.input.state);default:return n}}function Kt(n,a,s,c){let f=n;return nt(a)&&(f=gi(f,a,s)),f=wi(f,a),f=R.produce(f,h=>{const u=s(h.state,a,c);if(u)return R.castDraft({...f,state:u})}),R.produce(f,h=>{h.operations[h.operations.length-1].hash=Vt(h),!nt(a)&&a.attachments&&a.attachments.forEach(u=>{const{hash:o,...x}=u;h.attachments[o]={...x}})})}function nt(n){return[Ht,Y,X,C,Zt].includes(n.type)}function D(n,a,s,c,f="global"){if(!n)throw new Error("Empty action type");if(typeof n!="string")throw new Error(`Invalid action type: ${n}`);const h={type:n,input:a,scope:f};return s&&(h.attachments=s),c==null||c().parse(h),h}function Yt(n,a=Kt){return(s,c,f)=>a(s,c,n,f)}const Xt=(n,a)=>({name:"",documentType:"",revision:0,created:new Date().toISOString(),lastModified:new Date().toISOString(),attachments:{},...n,state:(a==null?void 0:a(n==null?void 0:n.state))??(n==null?void 0:n.state)??{}}),Gt=(n,a)=>{const s=Xt(n,a);return{...s,initialState:s,operations:[]}},Vt=n=>K(_r(n.state)),vi=(n,a=1e3)=>{const s=Math.random()*a;return K(`${(n??new Date).toISOString()}${s}`)};function M(n){return R.castImmutable(R.freeze(n,!0))}const Qt=n=>D("SET_NAME",n,void 0,st),tr=(n=1)=>D("UNDO",n,void 0,ct),rr=(n=1)=>D("REDO",n,void 0,pt),ir=(n,a)=>D("PRUNE",{start:n,end:a},void 0,ot),ht=(n,a)=>D("LOAD_STATE",{state:n,operations:a},void 0,at),Ei=Object.freeze(Object.defineProperty({__proto__:null,loadState:ht,prune:ir,redo:rr,setName:Qt,undo:tr},Symbol.toStringTag,{value:"Module"}));class bi{constructor(a,s,c){J(this,"_document");J(this,"_reducer");J(this,"_dispatch");this._reducer=a,this._document=s,this._dispatch=c}dispatch(a){return this._document=this._reducer(this._document,a,this._dispatch),this}saveToFile(a,s,c){return Jt(this._document,a,s,c)}async loadFromFile(a){this._document=await et(a,this._reducer)}static async stateFromFile(a,s){return await et(a,s)}get state(){return M(this._document.state)}get operations(){return M(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}get initialState(){return M(this._document.initialState)}toDocument(){return M(this._document)}getAttachment(a){return this._document.attachments[a]}setName(a){return this.dispatch(Qt(a)),this}undo(a){return this.dispatch(tr(a)),this}redo(a){return this.dispatch(rr(a)),this}prune(a,s){return this.dispatch(ir(a,s)),this}loadState(a,s){return this.dispatch(ht(a,s)),this}}function Fi(n,a){a.forEach(s=>{Object.getOwnPropertyNames(s.prototype).forEach(c=>{Object.defineProperty(n.prototype,c,Object.getOwnPropertyDescriptor(s.prototype,c)||Object.create(null))})})}exports.BaseActions=Ei;exports.BaseDocument=bi;exports.applyMixins=Fi;exports.baseReducer=Kt;exports.createAction=D;exports.createDocument=Gt;exports.createExtendedState=Xt;exports.createReducer=Yt;exports.createZip=ft;exports.getLocalFile=ci;exports.getRemoteFile=si;exports.hashDocument=Vt;exports.hashKey=vi;exports.isBaseAction=nt;exports.loadFromFile=et;exports.loadFromInput=Pt;exports.readOnly=M;exports.saveToFile=Jt;exports.saveToFileHandle=oi;exports.zod=Ir;