document-model 1.0.24 → 1.0.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/document-model.cjs +1 -1
- package/dist/browser/document-model.js +2 -2
- package/dist/browser/document.cjs +1 -1
- package/dist/browser/document.js +2 -2
- package/dist/browser/index.cjs +1 -1
- package/dist/browser/index.js +3 -3
- package/dist/browser/internal/{index-sfNIE5tQ.js → index-IVF7gvRz.js} +16 -6
- package/dist/{node/internal/index-HgkfWSZk.js → browser/internal/index-JkTAMqR0.js} +1 -1
- package/dist/{node/internal/index-aihhQ-ya.js → browser/internal/index-ZuT5Pi3Z.js} +1 -1
- package/dist/browser/internal/{index-Xpydy6AU.js → index-gREVUw-G.js} +1 -1
- package/dist/browser/internal/object-1Edh7roc.js +1844 -0
- package/dist/browser/internal/object-v0zgcnse.js +6 -0
- package/dist/browser/src/document/schema/index.d.ts +2 -2
- package/dist/browser/src/document-model/custom/reducers/versioning.d.ts +4 -4
- package/dist/browser/vitest.config.d.ts +2 -0
- package/dist/node/document-model.cjs +1 -1
- package/dist/node/document-model.js +2 -2
- package/dist/node/document.cjs +1 -1
- package/dist/node/document.js +2 -2
- package/dist/node/index.cjs +1 -1
- package/dist/node/index.js +3 -3
- package/dist/{browser/internal/index-e4O5HJBs.js → node/internal/index-8_P5_maf.js} +1 -1
- package/dist/node/internal/{index-sNi-u40H.js → index-AWkBpPdl.js} +16 -6
- package/dist/node/internal/{index-PkGY1BML.js → index-VzErJ06c.js} +1 -1
- package/dist/{browser/internal/index-v3lMuqpK.js → node/internal/index-y-8qoZvC.js} +1 -1
- package/dist/node/internal/object-6KU11KDZ.js +843 -0
- package/dist/node/internal/object-YfG4E2oW.js +1 -0
- package/dist/node/src/document/schema/index.d.ts +2 -2
- package/dist/node/src/document-model/custom/reducers/versioning.d.ts +4 -4
- package/dist/node/vitest.config.d.ts +2 -0
- package/dist/src/document/actions/index.d.ts +3 -3
- package/dist/src/document/object.d.ts +63 -0
- package/dist/src/document/reducer.d.ts +16 -0
- package/dist/src/document/schema/types.d.ts +9 -12
- package/dist/src/document/types.d.ts +9 -0
- package/dist/src/document/utils/base.d.ts +7 -4
- package/dist/src/document/utils/index.d.ts +1 -0
- package/dist/test/document/undo-redo.test.d.ts +1 -0
- package/package.json +23 -17
- package/dist/browser/internal/object-U8CbkcSV.js +0 -6
- package/dist/browser/internal/object-YlWt1S0J.js +0 -1831
- package/dist/browser/jest.config.d.ts +0 -8
- package/dist/node/internal/object-Nz1iEXFy.js +0 -1
- package/dist/node/internal/object-T2hpMYZ4.js +0 -833
- package/dist/node/jest.config.d.ts +0 -8
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var yt=Object.defineProperty;var zt=(e,t,i)=>t in e?yt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i;var E=(e,t,i)=>(zt(e,typeof t!="symbol"?t+"":t,i),i);const St=require("json-stringify-deterministic"),w=require("immer"),o=require("zod"),W=require("jszip"),Ot=require("crypto"),N=require("fs"),_t=require("https"),kt=require("path"),Z=e=>e!=null,Dt=o.z.any().refine(e=>Z(e)),H=o.z.enum(["LOAD_STATE"]),K=o.z.enum(["PRUNE"]),G=o.z.enum(["REDO"]),Q=o.z.enum(["SET_NAME"]),V=o.z.enum(["UNDO"]);function Et(){return o.z.object({__typename:o.z.literal("Action").optional(),type:o.z.string()})}function y(){return o.z.literal("global").or(o.z.literal("local"))}function X(){return o.z.union([Y(),et(),it(),at(),nt()])}function Tt(){return o.z.object({__typename:o.z.literal("DocumentFile").optional(),data:o.z.string(),extension:o.z.string().nullable(),fileName:o.z.string().nullable(),mimeType:o.z.string()})}function Y(){return o.z.object({input:o.z.lazy(()=>q()),type:H,scope:y()})}function q(){return o.z.object({operations:o.z.number(),state:o.z.lazy(()=>tt())})}function tt(){return o.z.object({data:o.z.unknown().nullish(),name:o.z.string()})}function At(){return o.z.object({__typename:o.z.literal("Operation").optional(),hash:o.z.string(),index:o.z.number(),timestamp:o.z.string().datetime(),type:o.z.string()})}function et(){return o.z.object({input:o.z.lazy(()=>I()),type:K,scope:y()})}function I(){return o.z.object({end:o.z.number().nullish(),start:o.z.number().nullish()})}const P=o.z.number;function it(){return o.z.object({input:P(),type:G,scope:y()})}const R=o.z.string;function at(){return o.z.object({input:R(),type:Q,scope:o.z.literal("global")})}function Nt(){return o.z.object({__typename:o.z.literal("SetNameOperation").optional(),hash:o.z.string(),index:o.z.number(),input:o.z.string(),timestamp:o.z.string().datetime(),type:o.z.string()})}const L=o.z.number;function nt(){return o.z.object({input:L(),type:V,scope:y()})}const Ft=Object.freeze(Object.defineProperty({__proto__:null,ActionSchema:Et,BaseActionSchema:X,DocumentFileSchema:Tt,LoadStateActionInputSchema:q,LoadStateActionSchema:Y,LoadStateActionStateInputSchema:tt,Load_StateSchema:H,OperationSchema:At,OperationScopeSchema:y,PruneActionInputSchema:I,PruneActionSchema:et,PruneSchema:K,RedoActionInputSchema:P,RedoActionSchema:it,RedoSchema:G,SetNameActionInputSchema:R,SetNameActionSchema:at,SetNameOperationSchema:Nt,Set_NameSchema:Q,UndoActionInputSchema:L,UndoActionSchema:nt,UndoSchema:V,definedNonNullAnySchema:Dt,isDefinedNonNullAny:Z},Symbol.toStringTag,{value:"Module"}));function Mt(e,t){return{...e,name:t}}function qt(e,t,i){const{scope:a,input:n}=t,p=e.revision[t.scope],s=Math.min(n,p),c=e.operations[a].slice(0,p-s);return{...j(e.initialState,{...e.operations,[a]:c},i),operations:e.operations,revision:{...e.revision,[a]:e.revision[a]-s}}}function It(e,t,i){const{scope:a,input:n}=t,p=e.operations[a].length-e.revision[a];if(!p)throw new Error("There is no UNDO operation to REDO");const s=n<p?n:p,c=e.operations[a].slice(0,e.revision[a]+s);return{...j(e.initialState,{...e.operations,[a]:c},i),operations:e.operations,revision:{...e.revision,[a]:e.revision[a]+s}}}function Pt(e,t,i){const{scope:a}=t,n=e.operations[a];let{input:{start:p,end:s}}=t;p=p||0,s=s||n.length;const c=n.slice(p,s),l=n.slice(0,p),m=n.slice(s),u=j(e.initialState,{...e.operations,[a]:l.concat(c)},i),{name:d,state:r}=u,_=l.length,k=l.length?l[l.length-1].timestamp:m.length?m[0].timestamp:new Date().toISOString();return j(e.initialState,{...e.operations,[a]:[...l,{...B({name:d,state:r},c.length),timestamp:k,index:_,hash:C({state:r},"global")},...m.map((A,D)=>({...A,index:_+D+1}))]},i)}function Rt(e,t){return{...e,name:t.name,state:t.state??{global:{},local:{}}}}const ot="SET_NAME",z="UNDO",S="REDO",O="PRUNE",st="LOAD_STATE",pt={"application/andrew-inset":["ez"],"application/appinstaller":["appinstaller"],"application/applixware":["aw"],"application/appx":["appx"],"application/appxbundle":["appxbundle"],"application/atom+xml":["atom"],"application/atomcat+xml":["atomcat"],"application/atomdeleted+xml":["atomdeleted"],"application/atomsvc+xml":["atomsvc"],"application/atsc-dwd+xml":["dwd"],"application/atsc-held+xml":["held"],"application/atsc-rsat+xml":["rsat"],"application/automationml-aml+xml":["aml"],"application/automationml-amlx+zip":["amlx"],"application/bdoc":["bdoc"],"application/calendar+xml":["xcs"],"application/ccxml+xml":["ccxml"],"application/cdfx+xml":["cdfx"],"application/cdmi-capability":["cdmia"],"application/cdmi-container":["cdmic"],"application/cdmi-domain":["cdmid"],"application/cdmi-object":["cdmio"],"application/cdmi-queue":["cdmiq"],"application/cpl+xml":["cpl"],"application/cu-seeme":["cu"],"application/cwl":["cwl"],"application/dash+xml":["mpd"],"application/dash-patch+xml":["mpp"],"application/davmount+xml":["davmount"],"application/docbook+xml":["dbk"],"application/dssc+der":["dssc"],"application/dssc+xml":["xdssc"],"application/ecmascript":["ecma"],"application/emma+xml":["emma"],"application/emotionml+xml":["emotionml"],"application/epub+zip":["epub"],"application/exi":["exi"],"application/express":["exp"],"application/fdf":["fdf"],"application/fdt+xml":["fdt"],"application/font-tdpfr":["pfr"],"application/geo+json":["geojson"],"application/gml+xml":["gml"],"application/gpx+xml":["gpx"],"application/gxf":["gxf"],"application/gzip":["gz"],"application/hjson":["hjson"],"application/hyperstudio":["stk"],"application/inkml+xml":["ink","inkml"],"application/ipfix":["ipfix"],"application/its+xml":["its"],"application/java-archive":["jar","war","ear"],"application/java-serialized-object":["ser"],"application/java-vm":["class"],"application/javascript":["*js"],"application/json":["json","map"],"application/json5":["json5"],"application/jsonml+json":["jsonml"],"application/ld+json":["jsonld"],"application/lgr+xml":["lgr"],"application/lost+xml":["lostxml"],"application/mac-binhex40":["hqx"],"application/mac-compactpro":["cpt"],"application/mads+xml":["mads"],"application/manifest+json":["webmanifest"],"application/marc":["mrc"],"application/marcxml+xml":["mrcx"],"application/mathematica":["ma","nb","mb"],"application/mathml+xml":["mathml"],"application/mbox":["mbox"],"application/media-policy-dataset+xml":["mpf"],"application/mediaservercontrol+xml":["mscml"],"application/metalink+xml":["metalink"],"application/metalink4+xml":["meta4"],"application/mets+xml":["mets"],"application/mmt-aei+xml":["maei"],"application/mmt-usd+xml":["musd"],"application/mods+xml":["mods"],"application/mp21":["m21","mp21"],"application/mp4":["*mp4","*mpg4","mp4s","m4p"],"application/msix":["msix"],"application/msixbundle":["msixbundle"],"application/msword":["doc","dot"],"application/mxf":["mxf"],"application/n-quads":["nq"],"application/n-triples":["nt"],"application/node":["cjs"],"application/octet-stream":["bin","dms","lrf","mar","so","dist","distz","pkg","bpk","dump","elc","deploy","exe","dll","deb","dmg","iso","img","msi","msp","msm","buffer"],"application/oda":["oda"],"application/oebps-package+xml":["opf"],"application/ogg":["ogx"],"application/omdoc+xml":["omdoc"],"application/onenote":["onetoc","onetoc2","onetmp","onepkg"],"application/oxps":["oxps"],"application/p2p-overlay+xml":["relo"],"application/patch-ops-error+xml":["xer"],"application/pdf":["pdf"],"application/pgp-encrypted":["pgp"],"application/pgp-keys":["asc"],"application/pgp-signature":["sig","*asc"],"application/pics-rules":["prf"],"application/pkcs10":["p10"],"application/pkcs7-mime":["p7m","p7c"],"application/pkcs7-signature":["p7s"],"application/pkcs8":["p8"],"application/pkix-attr-cert":["ac"],"application/pkix-cert":["cer"],"application/pkix-crl":["crl"],"application/pkix-pkipath":["pkipath"],"application/pkixcmp":["pki"],"application/pls+xml":["pls"],"application/postscript":["ai","eps","ps"],"application/provenance+xml":["provx"],"application/pskc+xml":["pskcxml"],"application/raml+yaml":["raml"],"application/rdf+xml":["rdf","owl"],"application/reginfo+xml":["rif"],"application/relax-ng-compact-syntax":["rnc"],"application/resource-lists+xml":["rl"],"application/resource-lists-diff+xml":["rld"],"application/rls-services+xml":["rs"],"application/route-apd+xml":["rapd"],"application/route-s-tsid+xml":["sls"],"application/route-usd+xml":["rusd"],"application/rpki-ghostbusters":["gbr"],"application/rpki-manifest":["mft"],"application/rpki-roa":["roa"],"application/rsd+xml":["rsd"],"application/rss+xml":["rss"],"application/rtf":["rtf"],"application/sbml+xml":["sbml"],"application/scvp-cv-request":["scq"],"application/scvp-cv-response":["scs"],"application/scvp-vp-request":["spq"],"application/scvp-vp-response":["spp"],"application/sdp":["sdp"],"application/senml+xml":["senmlx"],"application/sensml+xml":["sensmlx"],"application/set-payment-initiation":["setpay"],"application/set-registration-initiation":["setreg"],"application/shf+xml":["shf"],"application/sieve":["siv","sieve"],"application/smil+xml":["smi","smil"],"application/sparql-query":["rq"],"application/sparql-results+xml":["srx"],"application/sql":["sql"],"application/srgs":["gram"],"application/srgs+xml":["grxml"],"application/sru+xml":["sru"],"application/ssdl+xml":["ssdl"],"application/ssml+xml":["ssml"],"application/swid+xml":["swidtag"],"application/tei+xml":["tei","teicorpus"],"application/thraud+xml":["tfi"],"application/timestamped-data":["tsd"],"application/toml":["toml"],"application/trig":["trig"],"application/ttml+xml":["ttml"],"application/ubjson":["ubj"],"application/urc-ressheet+xml":["rsheet"],"application/urc-targetdesc+xml":["td"],"application/voicexml+xml":["vxml"],"application/wasm":["wasm"],"application/watcherinfo+xml":["wif"],"application/widget":["wgt"],"application/winhlp":["hlp"],"application/wsdl+xml":["wsdl"],"application/wspolicy+xml":["wspolicy"],"application/xaml+xml":["xaml"],"application/xcap-att+xml":["xav"],"application/xcap-caps+xml":["xca"],"application/xcap-diff+xml":["xdf"],"application/xcap-el+xml":["xel"],"application/xcap-ns+xml":["xns"],"application/xenc+xml":["xenc"],"application/xfdf":["xfdf"],"application/xhtml+xml":["xhtml","xht"],"application/xliff+xml":["xlf"],"application/xml":["xml","xsl","xsd","rng"],"application/xml-dtd":["dtd"],"application/xop+xml":["xop"],"application/xproc+xml":["xpl"],"application/xslt+xml":["*xsl","xslt"],"application/xspf+xml":["xspf"],"application/xv+xml":["mxml","xhvml","xvml","xvm"],"application/yang":["yang"],"application/yin+xml":["yin"],"application/zip":["zip"],"audio/3gpp":["*3gpp"],"audio/aac":["adts","aac"],"audio/adpcm":["adp"],"audio/amr":["amr"],"audio/basic":["au","snd"],"audio/midi":["mid","midi","kar","rmi"],"audio/mobile-xmf":["mxmf"],"audio/mp3":["*mp3"],"audio/mp4":["m4a","mp4a"],"audio/mpeg":["mpga","mp2","mp2a","mp3","m2a","m3a"],"audio/ogg":["oga","ogg","spx","opus"],"audio/s3m":["s3m"],"audio/silk":["sil"],"audio/wav":["wav"],"audio/wave":["*wav"],"audio/webm":["weba"],"audio/xm":["xm"],"font/collection":["ttc"],"font/otf":["otf"],"font/ttf":["ttf"],"font/woff":["woff"],"font/woff2":["woff2"],"image/aces":["exr"],"image/apng":["apng"],"image/avci":["avci"],"image/avcs":["avcs"],"image/avif":["avif"],"image/bmp":["bmp","dib"],"image/cgm":["cgm"],"image/dicom-rle":["drle"],"image/dpx":["dpx"],"image/emf":["emf"],"image/fits":["fits"],"image/g3fax":["g3"],"image/gif":["gif"],"image/heic":["heic"],"image/heic-sequence":["heics"],"image/heif":["heif"],"image/heif-sequence":["heifs"],"image/hej2k":["hej2"],"image/hsj2":["hsj2"],"image/ief":["ief"],"image/jls":["jls"],"image/jp2":["jp2","jpg2"],"image/jpeg":["jpeg","jpg","jpe"],"image/jph":["jph"],"image/jphc":["jhc"],"image/jpm":["jpm","jpgm"],"image/jpx":["jpx","jpf"],"image/jxr":["jxr"],"image/jxra":["jxra"],"image/jxrs":["jxrs"],"image/jxs":["jxs"],"image/jxsc":["jxsc"],"image/jxsi":["jxsi"],"image/jxss":["jxss"],"image/ktx":["ktx"],"image/ktx2":["ktx2"],"image/png":["png"],"image/sgi":["sgi"],"image/svg+xml":["svg","svgz"],"image/t38":["t38"],"image/tiff":["tif","tiff"],"image/tiff-fx":["tfx"],"image/webp":["webp"],"image/wmf":["wmf"],"message/disposition-notification":["disposition-notification"],"message/global":["u8msg"],"message/global-delivery-status":["u8dsn"],"message/global-disposition-notification":["u8mdn"],"message/global-headers":["u8hdr"],"message/rfc822":["eml","mime"],"model/3mf":["3mf"],"model/gltf+json":["gltf"],"model/gltf-binary":["glb"],"model/iges":["igs","iges"],"model/jt":["jt"],"model/mesh":["msh","mesh","silo"],"model/mtl":["mtl"],"model/obj":["obj"],"model/prc":["prc"],"model/step+xml":["stpx"],"model/step+zip":["stpz"],"model/step-xml+zip":["stpxz"],"model/stl":["stl"],"model/u3d":["u3d"],"model/vrml":["wrl","vrml"],"model/x3d+binary":["*x3db","x3dbz"],"model/x3d+fastinfoset":["x3db"],"model/x3d+vrml":["*x3dv","x3dvz"],"model/x3d+xml":["x3d","x3dz"],"model/x3d-vrml":["x3dv"],"text/cache-manifest":["appcache","manifest"],"text/calendar":["ics","ifb"],"text/coffeescript":["coffee","litcoffee"],"text/css":["css"],"text/csv":["csv"],"text/html":["html","htm","shtml"],"text/jade":["jade"],"text/javascript":["js","mjs"],"text/jsx":["jsx"],"text/less":["less"],"text/markdown":["md","markdown"],"text/mathml":["mml"],"text/mdx":["mdx"],"text/n3":["n3"],"text/plain":["txt","text","conf","def","list","log","in","ini"],"text/richtext":["rtx"],"text/rtf":["*rtf"],"text/sgml":["sgml","sgm"],"text/shex":["shex"],"text/slim":["slim","slm"],"text/spdx":["spdx"],"text/stylus":["stylus","styl"],"text/tab-separated-values":["tsv"],"text/troff":["t","tr","roff","man","me","ms"],"text/turtle":["ttl"],"text/uri-list":["uri","uris","urls"],"text/vcard":["vcard"],"text/vtt":["vtt"],"text/wgsl":["wgsl"],"text/xml":["*xml"],"text/yaml":["yaml","yml"],"video/3gpp":["3gp","3gpp"],"video/3gpp2":["3g2"],"video/h261":["h261"],"video/h263":["h263"],"video/h264":["h264"],"video/iso.segment":["m4s"],"video/jpeg":["jpgv"],"video/jpm":["*jpm","*jpgm"],"video/mj2":["mj2","mjp2"],"video/mp2t":["ts"],"video/mp4":["mp4","mp4v","mpg4"],"video/mpeg":["mpeg","mpg","mpe","m1v","m2v"],"video/ogg":["ogv"],"video/quicktime":["qt","mov"],"video/webm":["webm"]};Object.freeze(pt);var x=function(e,t,i,a){if(i==="a"&&!a)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?e!==t||!a:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return i==="m"?a:i==="a"?a.call(e):a?a.value:t.get(e)},h,b,f;class Lt{constructor(...t){h.set(this,new Map),b.set(this,new Map),f.set(this,new Map);for(const i of t)this.define(i)}define(t,i=!1){for(let[a,n]of Object.entries(t)){a=a.toLowerCase(),n=n.map(c=>c.toLowerCase()),x(this,f,"f").has(a)||x(this,f,"f").set(a,new Set);const p=x(this,f,"f").get(a);let s=!0;for(let c of n){const l=c.startsWith("*");if(c=l?c.slice(1):c,p==null||p.add(c),s&&x(this,b,"f").set(a,c),s=!1,l)continue;const m=x(this,h,"f").get(c);if(m&&m!=a&&!i)throw new Error(`"${a} -> ${c}" conflicts with "${m} -> ${c}". Pass \`force=true\` to override this definition.`);x(this,h,"f").set(c,a)}}return this}getType(t){if(typeof t!="string")return null;const i=t.replace(/^.*[/\\]/,"").toLowerCase(),a=i.replace(/^.*\./,"").toLowerCase(),n=i.length<t.length;return!(a.length<i.length-1)&&n?null:x(this,h,"f").get(a)??null}getExtension(t){var i;return typeof t!="string"?null:(t=(i=t==null?void 0:t.split)==null?void 0:i.call(t,";")[0],(t&&x(this,b,"f").get(t.trim().toLowerCase()))??null)}getAllExtensions(t){return typeof t!="string"?null:x(this,f,"f").get(t.toLowerCase())??null}_freeze(){this.define=()=>{throw new Error("define() not allowed for built-in Mime objects. See https://github.com/broofa/mime/blob/main/README.md#custom-mime-instances")},Object.freeze(this);for(const t of x(this,f,"f").values())Object.freeze(t);return this}_getTestState(){return{types:x(this,h,"f"),extensions:x(this,b,"f")}}}h=new WeakMap,b=new WeakMap,f=new WeakMap;const Ut=new Lt(pt)._freeze();function $t(e,t,i){const a=kt.join(e,t);return N.mkdirSync(e,{recursive:!0}),new Promise((n,p)=>{try{N.writeFile(a,i,{},s=>{s?p(s):n(a)})}catch(s){p(s)}})}function ct(e){return N.readFileSync(e)}function Ct(e){return new Promise((t,i)=>{_t.get(e,a=>{const n=[],p=a.headers["content-type"];a.on("data",s=>{n.push(s)}),a.on("end",()=>{t({buffer:Buffer.concat(n),mimeType:p})})}).on("error",a=>{i(a)})})}const Jt=async e=>ct(e),T=(e,t="sha1")=>Ot.createHash(t).update(e).digest("base64"),U=async e=>{const t=new W,{name:i,revision:a,documentType:n,created:p,lastModified:s}=e,c={name:i,revision:a,documentType:n,created:p,lastModified:s};return t.file("header.json",JSON.stringify(c,null,2)),t.file("state.json",JSON.stringify(e.initialState||{},null,2)),t.file("operations.json",JSON.stringify(e.operations,null,2)),Object.keys(e.attachments).forEach(m=>{const{data:u,...d}=e.attachments[m];t.file(m,u,{base64:!0,createFolders:!0,comment:JSON.stringify(d)})}),t},lt=async(e,t,i,a)=>{const p=await(await U(e)).generateAsync({type:"uint8array",streamFiles:!0}),s=a??e.name,c=`.${i}.zip`;return $t(t,s.endsWith(c)?s:`${s}${c}`,p)},Bt=async(e,t)=>{const a=await(await U(e)).generateAsync({type:"blob"}),n=await t.createWritable();await n.write(a),await n.close()},F=async(e,t)=>{const i=ct(e);return rt(i,t)},rt=async(e,t)=>{const i=new W;return await i.loadAsync(e),Wt(i,t)};async function Wt(e,t){const i=e.file("state.json");if(!i)throw new Error("Initial state not found");const a=await i.async("string"),n=JSON.parse(a),p=e.file("header.json");let s;p&&(s=JSON.parse(await p.async("string")));const c=e.file("operations.json");if(!c)throw new Error("Operations history not found");const l=JSON.parse(await c.async("string"));let m=J(n,l,t,void 0,s);return s&&(m={...m,...s}),m}function mt(e){const t=e.replace(/^.*\./,"")||void 0,i=e.replace(/^.*[/\\]/,"")||void 0;return{extension:t,fileName:i}}async function Zt(e){const{buffer:t,mimeType:i="application/octet-stream"}=await Ct(e),a=mt(e),n=t.toString("base64");return{data:n,hash:T(n),mimeType:i,...a}}async function Ht(e){const t=await Jt(e),i=Ut.getType(e)||"application/octet-stream",a=mt(e),n=t.toString("base64");return{data:n,hash:T(n),mimeType:i,...a}}function Kt(e,t){const i=e.revision[t.scope];return[z,S,O].includes(t.type)?i:i+1}function Gt(e,t){return{...e,revision:{...e.revision,[t.scope]:Kt(e,t)},lastModified:new Date().toISOString()}}function Qt(e,t,i=0){if([z,S,O].includes(t.type))return e;const{scope:a}=t,n=e.operations[a].slice(0,e.revision[a]);return n.push({...t,index:n.length,timestamp:new Date().toISOString(),hash:"",scope:a,skip:i}),{...e,operations:{...e.operations,[a]:n}}}function Vt(e,t,i=0){let a=Qt(e,t,i);return a=Gt(a,t),a}function Xt(e,t,i){switch(X().parse(t),t.type){case ot:return Mt(e,t.input);case z:return qt(e,t,i);case S:return It(e,t,i);case O:return Pt(e,t,i);case st:return Rt(e,t.input.state);default:return e}}function $(e,t,i,a,n={}){const{skip:p=0}=n;let s=e;return M(t)&&(s=Xt(s,t,i)),s=Vt(s,t,p),s=w.produce(s,c=>{const l=i(c.state,t,a);if(l)return w.castDraft({...s,state:l})}),w.produce(s,c=>{if([z,S,O].includes(t.type))return c;const l=t.scope||"global";c.operations[l][c.operations[l].length-1].hash=C(c,l),!M(t)&&t.attachments&&t.attachments.forEach(m=>{const{hash:u,...d}=m;c.attachments[u]={...d}})})}function M(e){return[ot,z,S,O,st].includes(e.type)}function g(e,t,i,a,n="global"){if(!e)throw new Error("Empty action type");if(typeof e!="string")throw new Error(`Invalid action type: ${e}`);const p={type:e,input:t,scope:n};i&&(p.attachments=i);try{a==null||a().parse(p.input)}catch(s){throw new Error(`Invalid action input: ${s}`)}return p}function ut(e,t=$){return(i,a,n,p)=>t(i,a,e,n,p)}const dt=(e,t)=>({name:"",documentType:"",revision:{global:0,local:0},created:new Date().toISOString(),lastModified:new Date().toISOString(),attachments:{},...e,state:(t==null?void 0:t(e==null?void 0:e.state))??(e==null?void 0:e.state)??{global:{},local:{}}}),xt=(e,t)=>{const i=dt(e,t);return{...i,initialState:i,operations:{global:[],local:[]}}},C=(e,t="global")=>T(St(e.state[t])),Yt=(e,t=1e3)=>{const i=Math.random()*t;return T(`${(e??new Date).toISOString()}${i}`)};function v(e){return w.castImmutable(w.freeze(e,!0))}function ft(e){const t=[...e];let i=0,a=t.length>0?t[t.length-1].index:0;const n=[];for(const p of t.reverse()){if(i>0){const c=a-p.index;i-=c}if(i<0)throw new Error("Invalid operation index, missing operations");const s={ignore:i>0,operation:p};p.skip>0&&(i=i+(p.skip+1)),a=p.index,n.push(s)}return n.reverse()}function te(e){return Object.values(e).flatMap(t=>t).sort((t,i)=>new Date(t.timestamp).getTime()-new Date(i.timestamp).getTime())}function gt(e){return Object.values(e).flatMap(t=>t).sort((t,i)=>new Date(t.operation.timestamp).getTime()-new Date(i.operation.timestamp).getTime())}function j(e,t,i,a,n,p=$){const s=ut(i,p);return J(e,t,s,a,n)}function J(e,t,i,a,n){const p=xt(e),s=Object.keys(t).reduce((u,d)=>{const r=d;return{...u,[r]:t[r].slice(0,n==null?void 0:n.revision[r])}},{}),c=Object.keys(s).reduce((u,d)=>{const r=d;return{...u,[r]:ft(s[r])}},{}),l=gt(c).reduce((u,{ignore:d,operation:r})=>d?i(u,jt(r.scope),a,{skip:r.skip}):i(u,r,a),p),m=Object.keys(l.operations).reduce((u,d)=>{const r=d,_=n&&n.revision[r]<t[r].length?t[r].slice(n.revision[r]):[];return{...u,[r]:[...l.operations[r].map((k,A)=>{var D;return{...k,timestamp:((D=t[r][A])==null?void 0:D.timestamp)??k.timestamp}}),..._]}},{global:[],local:[]});return{...l,operations:m}}const ht=e=>g("SET_NAME",e,void 0,R,void 0),bt=(e=1,t="global")=>g("UNDO",e,void 0,L,t),vt=(e=1,t="global")=>g("REDO",e,void 0,P,t),wt=(e,t,i="global")=>g("PRUNE",{start:e,end:t},void 0,I,i),B=(e,t)=>g("LOAD_STATE",{state:e,operations:t},void 0,q),jt=(e="global")=>g("NOOP",{},void 0,void 0,e),ee=Object.freeze(Object.defineProperty({__proto__:null,loadState:B,noop:jt,prune:wt,redo:vt,setName:ht,undo:bt},Symbol.toStringTag,{value:"Module"}));class ie{constructor(t,i,a){E(this,"_document");E(this,"_reducer");E(this,"_signalDispatch");this._reducer=t,this._document=i,this._signalDispatch=a}dispatch(t,i){return this._document=this._reducer(this._document,t,this._signalDispatch,i),this}saveToFile(t,i,a){return lt(this._document,t,i,a)}async loadFromFile(t){this._document=await F(t,this._reducer)}static async stateFromFile(t,i){return await F(t,i)}get state(){return v(this._document.state)}get operations(){return v(this._document.operations)}get name(){return this._document.name}get documentType(){return this._document.documentType}get created(){return this._document.created}get lastModified(){return this._document.lastModified}get revision(){return this._document.revision.global}getRevision(t){return this._document.revision[t]}get initialState(){return v(this._document.initialState)}toDocument(){return v(this._document)}getAttachment(t){return this._document.attachments[t]}setName(t){return this.dispatch(ht(t)),this}undo(t){return this.dispatch(bt(t)),this}redo(t){return this.dispatch(vt(t)),this}prune(t,i){return this.dispatch(wt(t,i)),this}loadState(t,i){return this.dispatch(B(t,i)),this}}function ae(e,t){t.forEach(i=>{Object.getOwnPropertyNames(i.prototype).forEach(a=>{Object.defineProperty(e.prototype,a,Object.getOwnPropertyDescriptor(i.prototype,a)||Object.create(null))})})}exports.BaseActions=ee;exports.BaseDocument=ie;exports.applyMixins=ae;exports.baseReducer=$;exports.createAction=g;exports.createDocument=xt;exports.createExtendedState=dt;exports.createReducer=ut;exports.createZip=U;exports.getLocalFile=Ht;exports.getRemoteFile=Zt;exports.hashDocument=C;exports.hashKey=Yt;exports.isBaseAction=M;exports.loadFromFile=F;exports.loadFromInput=rt;exports.mapSkippedOperations=ft;exports.readOnly=v;exports.replayDocument=J;exports.replayOperations=j;exports.saveToFile=lt;exports.saveToFileHandle=Bt;exports.sortMappedOperations=gt;exports.sortOperations=te;exports.zod=Ft;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * as z from
|
|
1
|
+
export * from './types';
|
|
2
|
+
export * as z from './zod';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* This is a scaffold file meant for customization:
|
|
3
|
-
* - modify it by implementing the reducer functions
|
|
4
|
-
* - delete the file and run the code generator again to have it reset
|
|
5
|
-
*/
|
|
2
|
+
* This is a scaffold file meant for customization:
|
|
3
|
+
* - modify it by implementing the reducer functions
|
|
4
|
+
* - delete the file and run the code generator again to have it reset
|
|
5
|
+
*/
|
|
6
6
|
import { DocumentModelVersioningOperations } from '../../gen/versioning/operations';
|
|
7
7
|
export declare const reducer: DocumentModelVersioningOperations;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Action, Document, ImmutableStateReducer, PruneAction, RedoAction, State, UndoAction } from '../types';
|
|
1
|
+
import { Action, Document, ImmutableStateReducer, PruneAction, RedoAction, State, UndoAction, UndoRedoProcessResult } from '../types';
|
|
2
2
|
export declare function setNameOperation<T>(document: T, name: string): T;
|
|
3
|
-
export declare function undoOperation<T, A extends Action, L>(document: Document<T, A, L>, action: UndoAction,
|
|
4
|
-
export declare function redoOperation<T, A extends Action, L>(document: Document<T, A, L>, action: RedoAction,
|
|
3
|
+
export declare function undoOperation<T, A extends Action, L>(document: Document<T, A, L>, action: UndoAction, skip: number): UndoRedoProcessResult<T, A, L>;
|
|
4
|
+
export declare function redoOperation<T, A extends Action, L>(document: Document<T, A, L>, action: RedoAction, skip: number): UndoRedoProcessResult<T, A, L>;
|
|
5
5
|
export declare function pruneOperation<T, A extends Action, L>(document: Document<T, A, L>, action: PruneAction, wrappedReducer: ImmutableStateReducer<T, A, L>): Document<T, A, L>;
|
|
6
6
|
export declare function loadStateOperation<T, A extends Action, L>(oldDocument: Document<T, A, L>, newDocument: {
|
|
7
7
|
name: string;
|
|
@@ -400,6 +400,69 @@ export declare abstract class BaseDocument<T, A extends Action, L = unknown> {
|
|
|
400
400
|
};
|
|
401
401
|
};
|
|
402
402
|
};
|
|
403
|
+
readonly clipboard: readonly ({
|
|
404
|
+
readonly input: {
|
|
405
|
+
readonly operations: number;
|
|
406
|
+
readonly state: {
|
|
407
|
+
readonly data?: unknown;
|
|
408
|
+
readonly name: string;
|
|
409
|
+
};
|
|
410
|
+
};
|
|
411
|
+
readonly type: "LOAD_STATE";
|
|
412
|
+
readonly scope: OperationScope;
|
|
413
|
+
readonly index: number;
|
|
414
|
+
readonly timestamp: string;
|
|
415
|
+
readonly hash: string;
|
|
416
|
+
readonly skip: number;
|
|
417
|
+
} | {
|
|
418
|
+
readonly input: {
|
|
419
|
+
readonly end?: import("./types").InputMaybe<number>;
|
|
420
|
+
readonly start?: import("./types").InputMaybe<number>;
|
|
421
|
+
};
|
|
422
|
+
readonly type: "PRUNE";
|
|
423
|
+
readonly scope: OperationScope;
|
|
424
|
+
readonly index: number;
|
|
425
|
+
readonly timestamp: string;
|
|
426
|
+
readonly hash: string;
|
|
427
|
+
readonly skip: number;
|
|
428
|
+
} | {
|
|
429
|
+
readonly input: number;
|
|
430
|
+
readonly type: "REDO";
|
|
431
|
+
readonly scope: OperationScope;
|
|
432
|
+
readonly index: number;
|
|
433
|
+
readonly timestamp: string;
|
|
434
|
+
readonly hash: string;
|
|
435
|
+
readonly skip: number;
|
|
436
|
+
} | {
|
|
437
|
+
readonly input: string;
|
|
438
|
+
readonly type: "SET_NAME";
|
|
439
|
+
readonly scope: "global";
|
|
440
|
+
readonly index: number;
|
|
441
|
+
readonly timestamp: string;
|
|
442
|
+
readonly hash: string;
|
|
443
|
+
readonly skip: number;
|
|
444
|
+
} | {
|
|
445
|
+
readonly input: number;
|
|
446
|
+
readonly type: "UNDO";
|
|
447
|
+
readonly scope: OperationScope;
|
|
448
|
+
readonly index: number;
|
|
449
|
+
readonly timestamp: string;
|
|
450
|
+
readonly hash: string;
|
|
451
|
+
readonly skip: number;
|
|
452
|
+
} | {
|
|
453
|
+
readonly input: unknown;
|
|
454
|
+
readonly type: "NOOP";
|
|
455
|
+
readonly scope: OperationScope;
|
|
456
|
+
readonly index: number;
|
|
457
|
+
readonly timestamp: string;
|
|
458
|
+
readonly hash: string;
|
|
459
|
+
readonly skip: number;
|
|
460
|
+
} | import("immer").Immutable<A & {
|
|
461
|
+
index: number;
|
|
462
|
+
timestamp: string;
|
|
463
|
+
hash: string;
|
|
464
|
+
skip: number;
|
|
465
|
+
}>)[];
|
|
403
466
|
};
|
|
404
467
|
/**
|
|
405
468
|
* Gets the attachment associated with the given key.
|
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
import { BaseAction } from './actions/types';
|
|
2
|
+
import { UndoRedoAction } from './schema';
|
|
2
3
|
import { Action, Document, ImmutableStateReducer, ReducerOptions } from './types';
|
|
3
4
|
import { SignalDispatch } from './signal';
|
|
5
|
+
type UndoRedoProcessResult<T, A extends Action, L> = {
|
|
6
|
+
document: Document<T, A, L>;
|
|
7
|
+
action: A | BaseAction;
|
|
8
|
+
skip: number;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Processes an UNDO or REDO action.
|
|
12
|
+
*
|
|
13
|
+
* @param document The current state of the document.
|
|
14
|
+
* @param action The action being applied to the document.
|
|
15
|
+
* @param skip The number of operations to skip before applying the action.
|
|
16
|
+
* @returns The updated document, calculated skip value and transformed action (if apply).
|
|
17
|
+
*/
|
|
18
|
+
export declare function processUndoRedo<T, A extends Action, L>(document: Document<T, A, L>, action: UndoRedoAction, skip: number): UndoRedoProcessResult<T, A, L>;
|
|
4
19
|
/**
|
|
5
20
|
* Base document reducer that wraps a custom document reducer and handles
|
|
6
21
|
* document-level actions such as undo, redo, prune, and set name.
|
|
@@ -14,3 +29,4 @@ import { SignalDispatch } from './signal';
|
|
|
14
29
|
* @returns The new state of the document.
|
|
15
30
|
*/
|
|
16
31
|
export declare function baseReducer<T, A extends Action, L>(document: Document<T, A, L>, action: A | BaseAction, customReducer: ImmutableStateReducer<T, A, L>, dispatch?: SignalDispatch, options?: ReducerOptions): Document<T, A, L>;
|
|
32
|
+
export {};
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { OperationScope } from '..';
|
|
2
2
|
export type Maybe<T> = T | null;
|
|
3
3
|
export type InputMaybe<T> = T | null | undefined;
|
|
4
|
-
export type Exact<T extends {
|
|
5
|
-
[key: string]: unknown;
|
|
6
|
-
}> = {
|
|
4
|
+
export type Exact<T extends Record<string, unknown>> = {
|
|
7
5
|
[K in keyof T]: T[K];
|
|
8
6
|
};
|
|
9
7
|
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & {
|
|
@@ -12,9 +10,7 @@ export type MakeOptional<T, K extends keyof T> = Omit<T, K> & {
|
|
|
12
10
|
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & {
|
|
13
11
|
[SubKey in K]: Maybe<T[SubKey]>;
|
|
14
12
|
};
|
|
15
|
-
export type MakeEmpty<T extends {
|
|
16
|
-
[key: string]: unknown;
|
|
17
|
-
}, K extends keyof T> = {
|
|
13
|
+
export type MakeEmpty<T extends Record<string, unknown>, K extends keyof T> = {
|
|
18
14
|
[_ in K]?: never;
|
|
19
15
|
};
|
|
20
16
|
export type Incremental<T> = T | {
|
|
@@ -64,6 +60,7 @@ export type Action = IAction & {
|
|
|
64
60
|
type: Scalars['String']['output'];
|
|
65
61
|
};
|
|
66
62
|
export type BaseAction = LoadStateAction | PruneAction | RedoAction | SetNameAction | UndoAction | NOOPAction;
|
|
63
|
+
export type UndoRedoAction = RedoAction | UndoAction;
|
|
67
64
|
export type DocumentFile = {
|
|
68
65
|
__typename?: 'DocumentFile';
|
|
69
66
|
data: Scalars['String']['output'];
|
|
@@ -91,7 +88,7 @@ export type IOperation = {
|
|
|
91
88
|
export type Load_State = 'LOAD_STATE';
|
|
92
89
|
export type LoadStateAction = {
|
|
93
90
|
input: LoadStateActionInput;
|
|
94
|
-
type: Load_State
|
|
91
|
+
type: Load_State;
|
|
95
92
|
scope: OperationScope;
|
|
96
93
|
};
|
|
97
94
|
export type LoadStateActionInput = {
|
|
@@ -135,7 +132,7 @@ export type Operation = IOperation & {
|
|
|
135
132
|
export type Prune = 'PRUNE';
|
|
136
133
|
export type PruneAction = {
|
|
137
134
|
input: PruneActionInput;
|
|
138
|
-
type: Prune
|
|
135
|
+
type: Prune;
|
|
139
136
|
scope: OperationScope;
|
|
140
137
|
};
|
|
141
138
|
export type PruneActionInput = {
|
|
@@ -149,13 +146,13 @@ export type Query = {
|
|
|
149
146
|
export type Redo = 'REDO';
|
|
150
147
|
export type RedoAction = {
|
|
151
148
|
input: Scalars['Int']['input'];
|
|
152
|
-
type: Redo
|
|
149
|
+
type: Redo;
|
|
153
150
|
scope: OperationScope;
|
|
154
151
|
};
|
|
155
152
|
export type Set_Name = 'SET_NAME';
|
|
156
153
|
export type SetNameAction = {
|
|
157
154
|
input: Scalars['String']['input'];
|
|
158
|
-
type: Set_Name
|
|
155
|
+
type: Set_Name;
|
|
159
156
|
scope: 'global';
|
|
160
157
|
};
|
|
161
158
|
export type SetNameOperation = IOperation & {
|
|
@@ -169,12 +166,12 @@ export type SetNameOperation = IOperation & {
|
|
|
169
166
|
export type Undo = 'UNDO';
|
|
170
167
|
export type UndoAction = {
|
|
171
168
|
input: Scalars['Int']['input'];
|
|
172
|
-
type: Undo
|
|
169
|
+
type: Undo;
|
|
173
170
|
scope: OperationScope;
|
|
174
171
|
};
|
|
175
172
|
export type NOOP = 'NOOP';
|
|
176
173
|
export type NOOPAction = {
|
|
177
174
|
input: Scalars['Unknown']['input'];
|
|
178
|
-
type: NOOP
|
|
175
|
+
type: NOOP;
|
|
179
176
|
scope: OperationScope;
|
|
180
177
|
};
|
|
@@ -30,6 +30,8 @@ export type ActionWithAttachment<T extends string = string, I = unknown, S exten
|
|
|
30
30
|
export type ReducerOptions = {
|
|
31
31
|
/** The number of operations to skip before this new action is applied */
|
|
32
32
|
skip?: number;
|
|
33
|
+
/** When true the skip count is ignored and the action is applied regardless of the skip count */
|
|
34
|
+
ignoreSkipOperations?: boolean;
|
|
33
35
|
};
|
|
34
36
|
/**
|
|
35
37
|
* A pure function that takes an action and the previous state
|
|
@@ -151,6 +153,8 @@ ExtendedState<GlobalState, LocalState> & {
|
|
|
151
153
|
operations: DocumentOperations<A>;
|
|
152
154
|
/** The initial state of the document, enabling replaying operations. */
|
|
153
155
|
initialState: ExtendedState<GlobalState, LocalState>;
|
|
156
|
+
/** A list of undone operations */
|
|
157
|
+
clipboard: Operation<BaseAction | A>[];
|
|
154
158
|
};
|
|
155
159
|
/**
|
|
156
160
|
* String type representing an attachment in a Document.
|
|
@@ -199,3 +203,8 @@ export type DocumentModelLib = {
|
|
|
199
203
|
documentModels: DocumentModel[];
|
|
200
204
|
editors: Editor[];
|
|
201
205
|
};
|
|
206
|
+
export type UndoRedoProcessResult<T, A extends Action, L> = {
|
|
207
|
+
document: Document<T, A, L>;
|
|
208
|
+
action: A | BaseAction;
|
|
209
|
+
skip: number;
|
|
210
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { baseReducer } from '../reducer';
|
|
2
|
-
import { Action, BaseAction, Document, ExtendedState, ImmutableStateReducer, Reducer, Immutable, OperationScope, State, CreateState, PartialState, DocumentOperations, DocumentHeader, DocumentOperationsIgnoreMap, Operation, MappedOperation } from '../types';
|
|
2
|
+
import { Action, BaseAction, UndoRedoAction, Document, ExtendedState, ImmutableStateReducer, Reducer, Immutable, OperationScope, State, CreateState, PartialState, DocumentOperations, DocumentHeader, DocumentOperationsIgnoreMap, Operation, MappedOperation } from '../types';
|
|
3
3
|
import { SignalDispatch } from '../signal';
|
|
4
|
+
export declare function isUndoRedo(action: Action): action is UndoRedoAction;
|
|
4
5
|
export declare function isBaseAction(action: Action): action is BaseAction;
|
|
5
6
|
/**
|
|
6
7
|
* Helper function to be used by action creators.
|
|
@@ -64,11 +65,13 @@ export declare function readOnly<T>(value: T): Immutable<T>;
|
|
|
64
65
|
* Maps skipped operations in an array of operations.
|
|
65
66
|
* Skipped operations are operations that are ignored during processing.
|
|
66
67
|
* @param operations - The array of operations to map.
|
|
68
|
+
* @param skippedHeadOperations - The number of operations to skip at the head of the array of operations.
|
|
67
69
|
* @returns An array of mapped operations with ignore flag indicating if the operation is skipped.
|
|
68
70
|
* @throws Error if the operation index is invalid and there are missing operations.
|
|
69
71
|
*/
|
|
70
|
-
export declare function mapSkippedOperations<A extends Action>(operations: Operation<BaseAction | A>[]): MappedOperation<A>[];
|
|
72
|
+
export declare function mapSkippedOperations<A extends Action>(operations: Operation<BaseAction | A>[], skippedHeadOperations?: number): MappedOperation<A>[];
|
|
71
73
|
export declare function sortOperations<A extends Action>(operations: DocumentOperations<A>): Operation<BaseAction | A>[];
|
|
72
74
|
export declare function sortMappedOperations<A extends Action>(operations: DocumentOperationsIgnoreMap<A>): MappedOperation<A>[];
|
|
73
|
-
export declare function replayOperations<T, A extends Action, L>(initialState: ExtendedState<T, L>, operations: DocumentOperations<A>, reducer: ImmutableStateReducer<T, A, L>, dispatch?: SignalDispatch, header?: DocumentHeader, documentReducer?: typeof baseReducer): Document<T, A, L>;
|
|
74
|
-
export
|
|
75
|
+
export declare function replayOperations<T, A extends Action, L>(initialState: ExtendedState<T, L>, operations: DocumentOperations<A>, reducer: ImmutableStateReducer<T, A, L>, dispatch?: SignalDispatch, header?: DocumentHeader, documentReducer?: typeof baseReducer, skipHeaderOperations?: SkipHeaderOperations): Document<T, A, L>;
|
|
76
|
+
export type SkipHeaderOperations = Partial<Record<OperationScope, number>>;
|
|
77
|
+
export declare function replayDocument<T, A extends Action, L>(initialState: ExtendedState<T, L>, operations: DocumentOperations<A>, reducer: Reducer<T, A, L>, dispatch?: SignalDispatch, header?: DocumentHeader, skipHeaderOperations?: SkipHeaderOperations): Document<T, A, L>;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export * from './base';
|
|
2
|
+
export { createAction, createDocument, createExtendedState, createReducer, hashDocument, hashKey, isBaseAction, mapSkippedOperations, readOnly, replayDocument, replayOperations, sortMappedOperations, sortOperations, } from './base';
|
|
2
3
|
export * from './file';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "document-model",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.26",
|
|
4
4
|
"license": "AGPL-3.0-only",
|
|
5
5
|
"private": false,
|
|
6
6
|
"files": [
|
|
@@ -11,12 +11,13 @@
|
|
|
11
11
|
"module": "dist/node/index.js",
|
|
12
12
|
"browser": "dist/browser/index.js",
|
|
13
13
|
"scripts": {
|
|
14
|
-
"
|
|
15
|
-
"
|
|
14
|
+
"check-types": "tsc",
|
|
15
|
+
"lint": "eslint . && yarn check-types",
|
|
16
|
+
"lint:fix": "eslint --fix . && yarn check-types",
|
|
16
17
|
"build": "yarn build:browser && yarn build:node",
|
|
17
18
|
"build:browser": "vite build --mode browser",
|
|
18
19
|
"build:node": "vite build --mode node",
|
|
19
|
-
"test": "
|
|
20
|
+
"test": "vitest run"
|
|
20
21
|
},
|
|
21
22
|
"exports": {
|
|
22
23
|
".": {
|
|
@@ -51,33 +52,38 @@
|
|
|
51
52
|
}
|
|
52
53
|
},
|
|
53
54
|
"devDependencies": {
|
|
54
|
-
"@
|
|
55
|
+
"@commitlint/cli": "^18.4.4",
|
|
56
|
+
"@commitlint/config-conventional": "^18.4.4",
|
|
57
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
55
58
|
"@total-typescript/ts-reset": "^0.5.1",
|
|
56
59
|
"@types/jest": "^29.5.11",
|
|
57
60
|
"@types/mime": "^3.0.4",
|
|
58
|
-
"@types/react": "^18.2.
|
|
59
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
60
|
-
"@typescript-eslint/parser": "^6.
|
|
61
|
+
"@types/react": "^18.2.48",
|
|
62
|
+
"@typescript-eslint/eslint-plugin": "^6.19.0",
|
|
63
|
+
"@typescript-eslint/parser": "^6.19.0",
|
|
61
64
|
"eslint": "^8.56.0",
|
|
62
65
|
"eslint-config-prettier": "^9.1.0",
|
|
63
|
-
"
|
|
64
|
-
"
|
|
66
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
67
|
+
"husky": "^8.0.3",
|
|
68
|
+
"lint-staged": "^15.2.0",
|
|
69
|
+
"prettier": "^3.2.4",
|
|
65
70
|
"prettier-plugin-organize-imports": "^3.2.4",
|
|
66
71
|
"react": "^18.2.0",
|
|
67
|
-
"rollup-plugin-polyfill-node": "^0.
|
|
72
|
+
"rollup-plugin-polyfill-node": "^0.13.0",
|
|
68
73
|
"sha.js": "^2.4.11",
|
|
69
74
|
"ts-jest": "^29.1.1",
|
|
70
75
|
"ts-node": "^10.9.2",
|
|
71
76
|
"typescript": "^5.3.3",
|
|
72
77
|
"vite": "^5.0.11",
|
|
73
|
-
"vite-plugin-dts": "^3.7.
|
|
74
|
-
"vite-plugin-node-polyfills": "^0.19.0"
|
|
78
|
+
"vite-plugin-dts": "^3.7.1",
|
|
79
|
+
"vite-plugin-node-polyfills": "^0.19.0",
|
|
80
|
+
"vitest": "^1.2.1"
|
|
75
81
|
},
|
|
76
82
|
"dependencies": {
|
|
77
|
-
"immer": "^10.0.
|
|
78
|
-
"json-stringify-deterministic": "^1.0.
|
|
83
|
+
"immer": "^10.0.3",
|
|
84
|
+
"json-stringify-deterministic": "^1.0.12",
|
|
79
85
|
"jszip": "^3.10.1",
|
|
80
|
-
"mime": "^
|
|
81
|
-
"zod": "^3.22.
|
|
86
|
+
"mime": "^4.0.1",
|
|
87
|
+
"zod": "^3.22.4"
|
|
82
88
|
}
|
|
83
89
|
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
"use strict";var Ue=Object.defineProperty;var ke=(i,o,p)=>o in i?Ue(i,o,{enumerable:!0,configurable:!0,writable:!0,value:p}):i[o]=p;var K=(i,o,p)=>(ke(i,typeof o!="symbol"?o+"":o,p),p);const Te=require("json-stringify-deterministic"),C=require("immer"),d=require("zod"),Ut=require("jszip"),kt=i=>i!=null,ze=d.z.any().refine(i=>kt(i)),Tt=d.z.enum(["LOAD_STATE"]),zt=d.z.enum(["PRUNE"]),Ot=d.z.enum(["REDO"]),Dt=d.z.enum(["SET_NAME"]),Nt=d.z.enum(["UNDO"]);function Oe(){return d.z.object({__typename:d.z.literal("Action").optional(),type:d.z.string()})}function q(){return d.z.literal("global").or(d.z.literal("local"))}function Mt(){return d.z.union([Rt(),Lt(),qt(),$t(),Pt()])}function De(){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 Rt(){return d.z.object({input:d.z.lazy(()=>pt()),type:Tt,scope:q()})}function pt(){return d.z.object({operations:d.z.number(),state:d.z.lazy(()=>Ct())})}function Ct(){return d.z.object({data:d.z.unknown().nullish(),name:d.z.string()})}function Ne(){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 Lt(){return d.z.object({input:d.z.lazy(()=>st()),type:zt,scope:q()})}function st(){return d.z.object({end:d.z.number().nullish(),start:d.z.number().nullish()})}const ct=d.z.number;function qt(){return d.z.object({input:ct(),type:Ot,scope:q()})}const lt=d.z.string;function $t(){return d.z.object({input:lt(),type:Dt,scope:d.z.literal("global")})}function Me(){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()})}const ut=d.z.number;function Pt(){return d.z.object({input:ut(),type:Nt,scope:q()})}const Re=Object.freeze(Object.defineProperty({__proto__:null,ActionSchema:Oe,BaseActionSchema:Mt,DocumentFileSchema:De,LoadStateActionInputSchema:pt,LoadStateActionSchema:Rt,LoadStateActionStateInputSchema:Ct,Load_StateSchema:Tt,OperationSchema:Ne,OperationScopeSchema:q,PruneActionInputSchema:st,PruneActionSchema:Lt,PruneSchema:zt,RedoActionInputSchema:ct,RedoActionSchema:qt,RedoSchema:Ot,SetNameActionInputSchema:lt,SetNameActionSchema:$t,SetNameOperationSchema:Me,Set_NameSchema:Dt,UndoActionInputSchema:ut,UndoActionSchema:Pt,UndoSchema:Nt,definedNonNullAnySchema:ze,isDefinedNonNullAny:kt},Symbol.toStringTag,{value:"Module"}));function Ce(i,o){return{...i,name:o}}function Le(i,o,p){const{scope:c,input:u}=o,f=i.revision[o.scope],l=Math.min(u,f),a=i.operations[c].slice(0,f-l);return{...L(i.initialState,{...i.operations,[c]:a},p),operations:i.operations,revision:{...i.revision,[c]:i.revision[c]-l}}}function qe(i,o,p){const{scope:c,input:u}=o,f=i.operations[c].length-i.revision[c];if(!f)throw new Error("There is no UNDO operation to REDO");const l=u<f?u:f,a=i.operations[c].slice(0,i.revision[c]+l);return{...L(i.initialState,{...i.operations,[c]:a},p),operations:i.operations,revision:{...i.revision,[c]:i.revision[c]+l}}}function $e(i,o,p){const{scope:c}=o,u=i.operations[c];let{input:{start:f,end:l}}=o;f=f||0,l=l||u.length;const a=u.slice(f,l),x=u.slice(0,f),g=u.slice(l),y=L(i.initialState,{...i.operations,[c]:x.concat(a)},p),{name:v,state:E}=y,A=x.length,U=x.length?x[x.length-1].timestamp:g.length?g[0].timestamp:new Date().toISOString();return L(i.initialState,{...i.operations,[c]:[...x,{...yt({name:v,state:E},a.length),timestamp:U,index:A,hash:dt({state:E},"global")},...g.map((z,N)=>({...z,index:A+N+1}))]},p)}function Pe(i,o){return{...i,name:o.name,state:o.state??{global:{},local:{}}}}const Jt="SET_NAME",$="UNDO",P="REDO",J="PRUNE",Wt="LOAD_STATE";function Ht(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}function Y(){this._types=Object.create(null),this._extensions=Object.create(null);for(let i=0;i<arguments.length;i++)this.define(arguments[i]);this.define=this.define.bind(this),this.getType=this.getType.bind(this),this.getExtension=this.getExtension.bind(this)}Y.prototype.define=function(i,o){for(let p in i){let c=i[p].map(function(u){return u.toLowerCase()});p=p.toLowerCase();for(let u=0;u<c.length;u++){const f=c[u];if(f[0]!=="*"){if(!o&&f in this._types)throw new Error('Attempt to change mapping for "'+f+'" extension from "'+this._types[f]+'" to "'+p+'". Pass `force=true` to allow this, otherwise remove "'+f+'" from the list of extensions for "'+p+'".');this._types[f]=p}}if(o||!this._extensions[p]){const u=c[0];this._extensions[p]=u[0]!=="*"?u:u.substr(1)}}};Y.prototype.getType=function(i){i=String(i);let o=i.replace(/^.*[/\\]/,"").toLowerCase(),p=o.replace(/^.*\./,"").toLowerCase(),c=o.length<i.length;return(p.length<o.length-1||!c)&&this._types[p]||null};Y.prototype.getExtension=function(i){return i=/^\s*([^;\s]*)/.test(i)&&RegExp.$1,i&&this._extensions[i.toLowerCase()]||null};var Je=Y,We={"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 He=Je;var Ze=new He(We);const Ke=Ht(Ze);var it={exports:{}};typeof Object.create=="function"?it.exports=function(o,p){p&&(o.super_=p,o.prototype=Object.create(p.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}))}:it.exports=function(o,p){if(p){o.super_=p;var c=function(){};c.prototype=p.prototype,o.prototype=new c,o.prototype.constructor=o}};var Ye=it.exports,nt={exports:{}},Zt={},X={};X.byteLength=Ve;X.toByteArray=tr;X.fromByteArray=ir;var T=[],I=[],Xe=typeof Uint8Array<"u"?Uint8Array:Array,rt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var M=0,Ge=rt.length;M<Ge;++M)T[M]=rt[M],I[rt.charCodeAt(M)]=M;I[45]=62;I[95]=63;function Kt(i){var o=i.length;if(o%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var p=i.indexOf("=");p===-1&&(p=o);var c=p===o?0:4-p%4;return[p,c]}function Ve(i){var o=Kt(i),p=o[0],c=o[1];return(p+c)*3/4-c}function Qe(i,o,p){return(o+p)*3/4-p}function tr(i){var o,p=Kt(i),c=p[0],u=p[1],f=new Xe(Qe(i,c,u)),l=0,a=u>0?c-4:c,x;for(x=0;x<a;x+=4)o=I[i.charCodeAt(x)]<<18|I[i.charCodeAt(x+1)]<<12|I[i.charCodeAt(x+2)]<<6|I[i.charCodeAt(x+3)],f[l++]=o>>16&255,f[l++]=o>>8&255,f[l++]=o&255;return u===2&&(o=I[i.charCodeAt(x)]<<2|I[i.charCodeAt(x+1)]>>4,f[l++]=o&255),u===1&&(o=I[i.charCodeAt(x)]<<10|I[i.charCodeAt(x+1)]<<4|I[i.charCodeAt(x+2)]>>2,f[l++]=o>>8&255,f[l++]=o&255),f}function er(i){return T[i>>18&63]+T[i>>12&63]+T[i>>6&63]+T[i&63]}function rr(i,o,p){for(var c,u=[],f=o;f<p;f+=3)c=(i[f]<<16&16711680)+(i[f+1]<<8&65280)+(i[f+2]&255),u.push(er(c));return u.join("")}function ir(i){for(var o,p=i.length,c=p%3,u=[],f=16383,l=0,a=p-c;l<a;l+=f)u.push(rr(i,l,l+f>a?a:l+f));return c===1?(o=i[p-1],u.push(T[o>>2]+T[o<<4&63]+"==")):c===2&&(o=(i[p-2]<<8)+i[p-1],u.push(T[o>>10]+T[o>>4&63]+T[o<<2&63]+"=")),u.join("")}var ft={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */ft.read=function(i,o,p,c,u){var f,l,a=u*8-c-1,x=(1<<a)-1,g=x>>1,y=-7,v=p?u-1:0,E=p?-1:1,A=i[o+v];for(v+=E,f=A&(1<<-y)-1,A>>=-y,y+=a;y>0;f=f*256+i[o+v],v+=E,y-=8);for(l=f&(1<<-y)-1,f>>=-y,y+=c;y>0;l=l*256+i[o+v],v+=E,y-=8);if(f===0)f=1-g;else{if(f===x)return l?NaN:(A?-1:1)*(1/0);l=l+Math.pow(2,c),f=f-g}return(A?-1:1)*l*Math.pow(2,f-c)};ft.write=function(i,o,p,c,u,f){var l,a,x,g=f*8-u-1,y=(1<<g)-1,v=y>>1,E=u===23?Math.pow(2,-24)-Math.pow(2,-77):0,A=c?0:f-1,U=c?1:-1,z=o<0||o===0&&1/o<0?1:0;for(o=Math.abs(o),isNaN(o)||o===1/0?(a=isNaN(o)?1:0,l=y):(l=Math.floor(Math.log(o)/Math.LN2),o*(x=Math.pow(2,-l))<1&&(l--,x*=2),l+v>=1?o+=E/x:o+=E*Math.pow(2,1-v),o*x>=2&&(l++,x/=2),l+v>=y?(a=0,l=y):l+v>=1?(a=(o*x-1)*Math.pow(2,u),l=l+v):(a=o*Math.pow(2,v-1)*Math.pow(2,u),l=0));u>=8;i[p+A]=a&255,A+=U,a/=256,u-=8);for(l=l<<u|a,g+=u;g>0;i[p+A]=l&255,A+=U,l/=256,g-=8);i[p+A-U]|=z*128};/*!
|
|
2
|
-
* The buffer module from node.js, for the browser.
|
|
3
|
-
*
|
|
4
|
-
* @author Feross Aboukhadijeh <https://feross.org>
|
|
5
|
-
* @license MIT
|
|
6
|
-
*/(function(i){var o=X,p=ft,c=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;i.Buffer=a,i.SlowBuffer=fe,i.INSPECT_MAX_BYTES=50;var u=2147483647;i.kMaxLength=u,a.TYPED_ARRAY_SUPPORT=f(),!a.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function f(){try{var r=new Uint8Array(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,Uint8Array.prototype),Object.setPrototypeOf(r,t),r.foo()===42}catch{return!1}}Object.defineProperty(a.prototype,"parent",{enumerable:!0,get:function(){if(a.isBuffer(this))return this.buffer}}),Object.defineProperty(a.prototype,"offset",{enumerable:!0,get:function(){if(a.isBuffer(this))return this.byteOffset}});function l(r){if(r>u)throw new RangeError('The value "'+r+'" is invalid for option "size"');var t=new Uint8Array(r);return Object.setPrototypeOf(t,a.prototype),t}function a(r,t,e){if(typeof r=="number"){if(typeof t=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return v(r)}return x(r,t,e)}a.poolSize=8192;function x(r,t,e){if(typeof r=="string")return E(r,t);if(ArrayBuffer.isView(r))return U(r);if(r==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof r);if(k(r,ArrayBuffer)||r&&k(r.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(k(r,SharedArrayBuffer)||r&&k(r.buffer,SharedArrayBuffer)))return z(r,t,e);if(typeof r=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');var n=r.valueOf&&r.valueOf();if(n!=null&&n!==r)return a.from(n,t,e);var s=N(r);if(s)return s;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof r[Symbol.toPrimitive]=="function")return a.from(r[Symbol.toPrimitive]("string"),t,e);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof r)}a.from=function(r,t,e){return x(r,t,e)},Object.setPrototypeOf(a.prototype,Uint8Array.prototype),Object.setPrototypeOf(a,Uint8Array);function g(r){if(typeof r!="number")throw new TypeError('"size" argument must be of type number');if(r<0)throw new RangeError('The value "'+r+'" is invalid for option "size"')}function y(r,t,e){return g(r),r<=0?l(r):t!==void 0?typeof e=="string"?l(r).fill(t,e):l(r).fill(t):l(r)}a.alloc=function(r,t,e){return y(r,t,e)};function v(r){return g(r),l(r<0?0:Q(r)|0)}a.allocUnsafe=function(r){return v(r)},a.allocUnsafeSlow=function(r){return v(r)};function E(r,t){if((typeof t!="string"||t==="")&&(t="utf8"),!a.isEncoding(t))throw new TypeError("Unknown encoding: "+t);var e=wt(r,t)|0,n=l(e),s=n.write(r,t);return s!==e&&(n=n.slice(0,s)),n}function A(r){for(var t=r.length<0?0:Q(r.length)|0,e=l(t),n=0;n<t;n+=1)e[n]=r[n]&255;return e}function U(r){if(k(r,Uint8Array)){var t=new Uint8Array(r);return z(t.buffer,t.byteOffset,t.byteLength)}return A(r)}function z(r,t,e){if(t<0||r.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(r.byteLength<t+(e||0))throw new RangeError('"length" is outside of buffer bounds');var n;return t===void 0&&e===void 0?n=new Uint8Array(r):e===void 0?n=new Uint8Array(r,t):n=new Uint8Array(r,t,e),Object.setPrototypeOf(n,a.prototype),n}function N(r){if(a.isBuffer(r)){var t=Q(r.length)|0,e=l(t);return e.length===0||r.copy(e,0,0,t),e}if(r.length!==void 0)return typeof r.length!="number"||et(r.length)?l(0):A(r);if(r.type==="Buffer"&&Array.isArray(r.data))return A(r.data)}function Q(r){if(r>=u)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+u.toString(16)+" bytes");return r|0}function fe(r){return+r!=r&&(r=0),a.alloc(+r)}a.isBuffer=function(t){return t!=null&&t._isBuffer===!0&&t!==a.prototype},a.compare=function(t,e){if(k(t,Uint8Array)&&(t=a.from(t,t.offset,t.byteLength)),k(e,Uint8Array)&&(e=a.from(e,e.offset,e.byteLength)),!a.isBuffer(t)||!a.isBuffer(e))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===e)return 0;for(var n=t.length,s=e.length,h=0,m=Math.min(n,s);h<m;++h)if(t[h]!==e[h]){n=t[h],s=e[h];break}return n<s?-1:s<n?1:0},a.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},a.concat=function(t,e){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(t.length===0)return a.alloc(0);var n;if(e===void 0)for(e=0,n=0;n<t.length;++n)e+=t[n].length;var s=a.allocUnsafe(e),h=0;for(n=0;n<t.length;++n){var m=t[n];if(k(m,Uint8Array))h+m.length>s.length?a.from(m).copy(s,h):Uint8Array.prototype.set.call(s,m,h);else if(a.isBuffer(m))m.copy(s,h);else throw new TypeError('"list" argument must be an Array of Buffers');h+=m.length}return s};function wt(r,t){if(a.isBuffer(r))return r.length;if(ArrayBuffer.isView(r)||k(r,ArrayBuffer))return r.byteLength;if(typeof r!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof r);var e=r.length,n=arguments.length>2&&arguments[2]===!0;if(!n&&e===0)return 0;for(var s=!1;;)switch(t){case"ascii":case"latin1":case"binary":return e;case"utf8":case"utf-8":return tt(r).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return e*2;case"hex":return e>>>1;case"base64":return Bt(r).length;default:if(s)return n?-1:tt(r).length;t=(""+t).toLowerCase(),s=!0}}a.byteLength=wt;function he(r,t,e){var n=!1;if((t===void 0||t<0)&&(t=0),t>this.length||((e===void 0||e>this.length)&&(e=this.length),e<=0)||(e>>>=0,t>>>=0,e<=t))return"";for(r||(r="utf8");;)switch(r){case"hex":return Fe(this,t,e);case"utf8":case"utf-8":return bt(this,t,e);case"ascii":return Ee(this,t,e);case"latin1":case"binary":return be(this,t,e);case"base64":return we(this,t,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return _e(this,t,e);default:if(n)throw new TypeError("Unknown encoding: "+r);r=(r+"").toLowerCase(),n=!0}}a.prototype._isBuffer=!0;function O(r,t,e){var n=r[t];r[t]=r[e],r[e]=n}a.prototype.swap16=function(){var t=this.length;if(t%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;e<t;e+=2)O(this,e,e+1);return this},a.prototype.swap32=function(){var t=this.length;if(t%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;e<t;e+=4)O(this,e,e+3),O(this,e+1,e+2);return this},a.prototype.swap64=function(){var t=this.length;if(t%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;e<t;e+=8)O(this,e,e+7),O(this,e+1,e+6),O(this,e+2,e+5),O(this,e+3,e+4);return this},a.prototype.toString=function(){var t=this.length;return t===0?"":arguments.length===0?bt(this,0,t):he.apply(this,arguments)},a.prototype.toLocaleString=a.prototype.toString,a.prototype.equals=function(t){if(!a.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t?!0:a.compare(this,t)===0},a.prototype.inspect=function(){var t="",e=i.INSPECT_MAX_BYTES;return t=this.toString("hex",0,e).replace(/(.{2})/g,"$1 ").trim(),this.length>e&&(t+=" ... "),"<Buffer "+t+">"},c&&(a.prototype[c]=a.prototype.inspect),a.prototype.compare=function(t,e,n,s,h){if(k(t,Uint8Array)&&(t=a.from(t,t.offset,t.byteLength)),!a.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(e===void 0&&(e=0),n===void 0&&(n=t?t.length:0),s===void 0&&(s=0),h===void 0&&(h=this.length),e<0||n>t.length||s<0||h>this.length)throw new RangeError("out of range index");if(s>=h&&e>=n)return 0;if(s>=h)return-1;if(e>=n)return 1;if(e>>>=0,n>>>=0,s>>>=0,h>>>=0,this===t)return 0;for(var m=h-s,w=n-e,b=Math.min(m,w),F=this.slice(s,h),B=t.slice(e,n),_=0;_<b;++_)if(F[_]!==B[_]){m=F[_],w=B[_];break}return m<w?-1:w<m?1:0};function vt(r,t,e,n,s){if(r.length===0)return-1;if(typeof e=="string"?(n=e,e=0):e>2147483647?e=2147483647:e<-2147483648&&(e=-2147483648),e=+e,et(e)&&(e=s?0:r.length-1),e<0&&(e=r.length+e),e>=r.length){if(s)return-1;e=r.length-1}else if(e<0)if(s)e=0;else return-1;if(typeof t=="string"&&(t=a.from(t,n)),a.isBuffer(t))return t.length===0?-1:Et(r,t,e,n,s);if(typeof t=="number")return t=t&255,typeof Uint8Array.prototype.indexOf=="function"?s?Uint8Array.prototype.indexOf.call(r,t,e):Uint8Array.prototype.lastIndexOf.call(r,t,e):Et(r,[t],e,n,s);throw new TypeError("val must be string, number or Buffer")}function Et(r,t,e,n,s){var h=1,m=r.length,w=t.length;if(n!==void 0&&(n=String(n).toLowerCase(),n==="ucs2"||n==="ucs-2"||n==="utf16le"||n==="utf-16le")){if(r.length<2||t.length<2)return-1;h=2,m/=2,w/=2,e/=2}function b(jt,It){return h===1?jt[It]:jt.readUInt16BE(It*h)}var F;if(s){var B=-1;for(F=e;F<m;F++)if(b(r,F)===b(t,B===-1?0:F-B)){if(B===-1&&(B=F),F-B+1===w)return B*h}else B!==-1&&(F-=F-B),B=-1}else for(e+w>m&&(e=m-w),F=e;F>=0;F--){for(var _=!0,Z=0;Z<w;Z++)if(b(r,F+Z)!==b(t,Z)){_=!1;break}if(_)return F}return-1}a.prototype.includes=function(t,e,n){return this.indexOf(t,e,n)!==-1},a.prototype.indexOf=function(t,e,n){return vt(this,t,e,n,!0)},a.prototype.lastIndexOf=function(t,e,n){return vt(this,t,e,n,!1)};function me(r,t,e,n){e=Number(e)||0;var s=r.length-e;n?(n=Number(n),n>s&&(n=s)):n=s;var h=t.length;n>h/2&&(n=h/2);for(var m=0;m<n;++m){var w=parseInt(t.substr(m*2,2),16);if(et(w))return m;r[e+m]=w}return m}function xe(r,t,e,n){return H(tt(t,r.length-e),r,e,n)}function de(r,t,e,n){return H(Be(t),r,e,n)}function ge(r,t,e,n){return H(Bt(t),r,e,n)}function ye(r,t,e,n){return H(je(t,r.length-e),r,e,n)}a.prototype.write=function(t,e,n,s){if(e===void 0)s="utf8",n=this.length,e=0;else if(n===void 0&&typeof e=="string")s=e,n=this.length,e=0;else if(isFinite(e))e=e>>>0,isFinite(n)?(n=n>>>0,s===void 0&&(s="utf8")):(s=n,n=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");var h=this.length-e;if((n===void 0||n>h)&&(n=h),t.length>0&&(n<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");s||(s="utf8");for(var m=!1;;)switch(s){case"hex":return me(this,t,e,n);case"utf8":case"utf-8":return xe(this,t,e,n);case"ascii":case"latin1":case"binary":return de(this,t,e,n);case"base64":return ge(this,t,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ye(this,t,e,n);default:if(m)throw new TypeError("Unknown encoding: "+s);s=(""+s).toLowerCase(),m=!0}},a.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function we(r,t,e){return t===0&&e===r.length?o.fromByteArray(r):o.fromByteArray(r.slice(t,e))}function bt(r,t,e){e=Math.min(r.length,e);for(var n=[],s=t;s<e;){var h=r[s],m=null,w=h>239?4:h>223?3:h>191?2:1;if(s+w<=e){var b,F,B,_;switch(w){case 1:h<128&&(m=h);break;case 2:b=r[s+1],(b&192)===128&&(_=(h&31)<<6|b&63,_>127&&(m=_));break;case 3:b=r[s+1],F=r[s+2],(b&192)===128&&(F&192)===128&&(_=(h&15)<<12|(b&63)<<6|F&63,_>2047&&(_<55296||_>57343)&&(m=_));break;case 4:b=r[s+1],F=r[s+2],B=r[s+3],(b&192)===128&&(F&192)===128&&(B&192)===128&&(_=(h&15)<<18|(b&63)<<12|(F&63)<<6|B&63,_>65535&&_<1114112&&(m=_))}}m===null?(m=65533,w=1):m>65535&&(m-=65536,n.push(m>>>10&1023|55296),m=56320|m&1023),n.push(m),s+=w}return ve(n)}var Ft=4096;function ve(r){var t=r.length;if(t<=Ft)return String.fromCharCode.apply(String,r);for(var e="",n=0;n<t;)e+=String.fromCharCode.apply(String,r.slice(n,n+=Ft));return e}function Ee(r,t,e){var n="";e=Math.min(r.length,e);for(var s=t;s<e;++s)n+=String.fromCharCode(r[s]&127);return n}function be(r,t,e){var n="";e=Math.min(r.length,e);for(var s=t;s<e;++s)n+=String.fromCharCode(r[s]);return n}function Fe(r,t,e){var n=r.length;(!t||t<0)&&(t=0),(!e||e<0||e>n)&&(e=n);for(var s="",h=t;h<e;++h)s+=Ie[r[h]];return s}function _e(r,t,e){for(var n=r.slice(t,e),s="",h=0;h<n.length-1;h+=2)s+=String.fromCharCode(n[h]+n[h+1]*256);return s}a.prototype.slice=function(t,e){var n=this.length;t=~~t,e=e===void 0?n:~~e,t<0?(t+=n,t<0&&(t=0)):t>n&&(t=n),e<0?(e+=n,e<0&&(e=0)):e>n&&(e=n),e<t&&(e=t);var s=this.subarray(t,e);return Object.setPrototypeOf(s,a.prototype),s};function S(r,t,e){if(r%1!==0||r<0)throw new RangeError("offset is not uint");if(r+t>e)throw new RangeError("Trying to access beyond buffer length")}a.prototype.readUintLE=a.prototype.readUIntLE=function(t,e,n){t=t>>>0,e=e>>>0,n||S(t,e,this.length);for(var s=this[t],h=1,m=0;++m<e&&(h*=256);)s+=this[t+m]*h;return s},a.prototype.readUintBE=a.prototype.readUIntBE=function(t,e,n){t=t>>>0,e=e>>>0,n||S(t,e,this.length);for(var s=this[t+--e],h=1;e>0&&(h*=256);)s+=this[t+--e]*h;return s},a.prototype.readUint8=a.prototype.readUInt8=function(t,e){return t=t>>>0,e||S(t,1,this.length),this[t]},a.prototype.readUint16LE=a.prototype.readUInt16LE=function(t,e){return t=t>>>0,e||S(t,2,this.length),this[t]|this[t+1]<<8},a.prototype.readUint16BE=a.prototype.readUInt16BE=function(t,e){return t=t>>>0,e||S(t,2,this.length),this[t]<<8|this[t+1]},a.prototype.readUint32LE=a.prototype.readUInt32LE=function(t,e){return t=t>>>0,e||S(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+this[t+3]*16777216},a.prototype.readUint32BE=a.prototype.readUInt32BE=function(t,e){return t=t>>>0,e||S(t,4,this.length),this[t]*16777216+(this[t+1]<<16|this[t+2]<<8|this[t+3])},a.prototype.readIntLE=function(t,e,n){t=t>>>0,e=e>>>0,n||S(t,e,this.length);for(var s=this[t],h=1,m=0;++m<e&&(h*=256);)s+=this[t+m]*h;return h*=128,s>=h&&(s-=Math.pow(2,8*e)),s},a.prototype.readIntBE=function(t,e,n){t=t>>>0,e=e>>>0,n||S(t,e,this.length);for(var s=e,h=1,m=this[t+--s];s>0&&(h*=256);)m+=this[t+--s]*h;return h*=128,m>=h&&(m-=Math.pow(2,8*e)),m},a.prototype.readInt8=function(t,e){return t=t>>>0,e||S(t,1,this.length),this[t]&128?(255-this[t]+1)*-1:this[t]},a.prototype.readInt16LE=function(t,e){t=t>>>0,e||S(t,2,this.length);var n=this[t]|this[t+1]<<8;return n&32768?n|4294901760:n},a.prototype.readInt16BE=function(t,e){t=t>>>0,e||S(t,2,this.length);var n=this[t+1]|this[t]<<8;return n&32768?n|4294901760:n},a.prototype.readInt32LE=function(t,e){return t=t>>>0,e||S(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},a.prototype.readInt32BE=function(t,e){return t=t>>>0,e||S(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},a.prototype.readFloatLE=function(t,e){return t=t>>>0,e||S(t,4,this.length),p.read(this,t,!0,23,4)},a.prototype.readFloatBE=function(t,e){return t=t>>>0,e||S(t,4,this.length),p.read(this,t,!1,23,4)},a.prototype.readDoubleLE=function(t,e){return t=t>>>0,e||S(t,8,this.length),p.read(this,t,!0,52,8)},a.prototype.readDoubleBE=function(t,e){return t=t>>>0,e||S(t,8,this.length),p.read(this,t,!1,52,8)};function j(r,t,e,n,s,h){if(!a.isBuffer(r))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>s||t<h)throw new RangeError('"value" argument is out of bounds');if(e+n>r.length)throw new RangeError("Index out of range")}a.prototype.writeUintLE=a.prototype.writeUIntLE=function(t,e,n,s){if(t=+t,e=e>>>0,n=n>>>0,!s){var h=Math.pow(2,8*n)-1;j(this,t,e,n,h,0)}var m=1,w=0;for(this[e]=t&255;++w<n&&(m*=256);)this[e+w]=t/m&255;return e+n},a.prototype.writeUintBE=a.prototype.writeUIntBE=function(t,e,n,s){if(t=+t,e=e>>>0,n=n>>>0,!s){var h=Math.pow(2,8*n)-1;j(this,t,e,n,h,0)}var m=n-1,w=1;for(this[e+m]=t&255;--m>=0&&(w*=256);)this[e+m]=t/w&255;return e+n},a.prototype.writeUint8=a.prototype.writeUInt8=function(t,e,n){return t=+t,e=e>>>0,n||j(this,t,e,1,255,0),this[e]=t&255,e+1},a.prototype.writeUint16LE=a.prototype.writeUInt16LE=function(t,e,n){return t=+t,e=e>>>0,n||j(this,t,e,2,65535,0),this[e]=t&255,this[e+1]=t>>>8,e+2},a.prototype.writeUint16BE=a.prototype.writeUInt16BE=function(t,e,n){return t=+t,e=e>>>0,n||j(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=t&255,e+2},a.prototype.writeUint32LE=a.prototype.writeUInt32LE=function(t,e,n){return t=+t,e=e>>>0,n||j(this,t,e,4,4294967295,0),this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=t&255,e+4},a.prototype.writeUint32BE=a.prototype.writeUInt32BE=function(t,e,n){return t=+t,e=e>>>0,n||j(this,t,e,4,4294967295,0),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=t&255,e+4},a.prototype.writeIntLE=function(t,e,n,s){if(t=+t,e=e>>>0,!s){var h=Math.pow(2,8*n-1);j(this,t,e,n,h-1,-h)}var m=0,w=1,b=0;for(this[e]=t&255;++m<n&&(w*=256);)t<0&&b===0&&this[e+m-1]!==0&&(b=1),this[e+m]=(t/w>>0)-b&255;return e+n},a.prototype.writeIntBE=function(t,e,n,s){if(t=+t,e=e>>>0,!s){var h=Math.pow(2,8*n-1);j(this,t,e,n,h-1,-h)}var m=n-1,w=1,b=0;for(this[e+m]=t&255;--m>=0&&(w*=256);)t<0&&b===0&&this[e+m+1]!==0&&(b=1),this[e+m]=(t/w>>0)-b&255;return e+n},a.prototype.writeInt8=function(t,e,n){return t=+t,e=e>>>0,n||j(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=t&255,e+1},a.prototype.writeInt16LE=function(t,e,n){return t=+t,e=e>>>0,n||j(this,t,e,2,32767,-32768),this[e]=t&255,this[e+1]=t>>>8,e+2},a.prototype.writeInt16BE=function(t,e,n){return t=+t,e=e>>>0,n||j(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=t&255,e+2},a.prototype.writeInt32LE=function(t,e,n){return t=+t,e=e>>>0,n||j(this,t,e,4,2147483647,-2147483648),this[e]=t&255,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4},a.prototype.writeInt32BE=function(t,e,n){return t=+t,e=e>>>0,n||j(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=t&255,e+4};function _t(r,t,e,n,s,h){if(e+n>r.length)throw new RangeError("Index out of range");if(e<0)throw new RangeError("Index out of range")}function At(r,t,e,n,s){return t=+t,e=e>>>0,s||_t(r,t,e,4),p.write(r,t,e,n,23,4),e+4}a.prototype.writeFloatLE=function(t,e,n){return At(this,t,e,!0,n)},a.prototype.writeFloatBE=function(t,e,n){return At(this,t,e,!1,n)};function St(r,t,e,n,s){return t=+t,e=e>>>0,s||_t(r,t,e,8),p.write(r,t,e,n,52,8),e+8}a.prototype.writeDoubleLE=function(t,e,n){return St(this,t,e,!0,n)},a.prototype.writeDoubleBE=function(t,e,n){return St(this,t,e,!1,n)},a.prototype.copy=function(t,e,n,s){if(!a.isBuffer(t))throw new TypeError("argument should be a Buffer");if(n||(n=0),!s&&s!==0&&(s=this.length),e>=t.length&&(e=t.length),e||(e=0),s>0&&s<n&&(s=n),s===n||t.length===0||this.length===0)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(s<0)throw new RangeError("sourceEnd out of bounds");s>this.length&&(s=this.length),t.length-e<s-n&&(s=t.length-e+n);var h=s-n;return this===t&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(e,n,s):Uint8Array.prototype.set.call(t,this.subarray(n,s),e),h},a.prototype.fill=function(t,e,n,s){if(typeof t=="string"){if(typeof e=="string"?(s=e,e=0,n=this.length):typeof n=="string"&&(s=n,n=this.length),s!==void 0&&typeof s!="string")throw new TypeError("encoding must be a string");if(typeof s=="string"&&!a.isEncoding(s))throw new TypeError("Unknown encoding: "+s);if(t.length===1){var h=t.charCodeAt(0);(s==="utf8"&&h<128||s==="latin1")&&(t=h)}}else typeof t=="number"?t=t&255:typeof t=="boolean"&&(t=Number(t));if(e<0||this.length<e||this.length<n)throw new RangeError("Out of range index");if(n<=e)return this;e=e>>>0,n=n===void 0?this.length:n>>>0,t||(t=0);var m;if(typeof t=="number")for(m=e;m<n;++m)this[m]=t;else{var w=a.isBuffer(t)?t:a.from(t,s),b=w.length;if(b===0)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(m=0;m<n-e;++m)this[m+e]=w[m%b]}return this};var Ae=/[^+/0-9A-Za-z-_]/g;function Se(r){if(r=r.split("=")[0],r=r.trim().replace(Ae,""),r.length<2)return"";for(;r.length%4!==0;)r=r+"=";return r}function tt(r,t){t=t||1/0;for(var e,n=r.length,s=null,h=[],m=0;m<n;++m){if(e=r.charCodeAt(m),e>55295&&e<57344){if(!s){if(e>56319){(t-=3)>-1&&h.push(239,191,189);continue}else if(m+1===n){(t-=3)>-1&&h.push(239,191,189);continue}s=e;continue}if(e<56320){(t-=3)>-1&&h.push(239,191,189),s=e;continue}e=(s-55296<<10|e-56320)+65536}else s&&(t-=3)>-1&&h.push(239,191,189);if(s=null,e<128){if((t-=1)<0)break;h.push(e)}else if(e<2048){if((t-=2)<0)break;h.push(e>>6|192,e&63|128)}else if(e<65536){if((t-=3)<0)break;h.push(e>>12|224,e>>6&63|128,e&63|128)}else if(e<1114112){if((t-=4)<0)break;h.push(e>>18|240,e>>12&63|128,e>>6&63|128,e&63|128)}else throw new Error("Invalid code point")}return h}function Be(r){for(var t=[],e=0;e<r.length;++e)t.push(r.charCodeAt(e)&255);return t}function je(r,t){for(var e,n,s,h=[],m=0;m<r.length&&!((t-=2)<0);++m)e=r.charCodeAt(m),n=e>>8,s=e%256,h.push(s),h.push(n);return h}function Bt(r){return o.toByteArray(Se(r))}function H(r,t,e,n){for(var s=0;s<n&&!(s+e>=t.length||s>=r.length);++s)t[s+e]=r[s];return s}function k(r,t){return r instanceof t||r!=null&&r.constructor!=null&&r.constructor.name!=null&&r.constructor.name===t.name}function et(r){return r!==r}var Ie=function(){for(var r="0123456789abcdef",t=new Array(256),e=0;e<16;++e)for(var n=e*16,s=0;s<16;++s)t[n+s]=r[e]+r[s];return t}()})(Zt);/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */(function(i,o){var p=Zt,c=p.Buffer;function u(l,a){for(var x in l)a[x]=l[x]}c.from&&c.alloc&&c.allocUnsafe&&c.allocUnsafeSlow?i.exports=p:(u(p,o),o.Buffer=f);function f(l,a,x){return c(l,a,x)}f.prototype=Object.create(c.prototype),u(c,f),f.from=function(l,a,x){if(typeof l=="number")throw new TypeError("Argument must not be a number");return c(l,a,x)},f.alloc=function(l,a,x){if(typeof l!="number")throw new TypeError("Argument must be a number");var g=c(l);return a!==void 0?typeof x=="string"?g.fill(a,x):g.fill(a):g.fill(0),g},f.allocUnsafe=function(l){if(typeof l!="number")throw new TypeError("Argument must be a number");return c(l)},f.allocUnsafeSlow=function(l){if(typeof l!="number")throw new TypeError("Argument must be a number");return p.SlowBuffer(l)}})(nt,nt.exports);var Yt=nt.exports,Xt=Yt.Buffer;function G(i,o){this._block=Xt.alloc(i),this._finalSize=o,this._blockSize=i,this._len=0}G.prototype.update=function(i,o){typeof i=="string"&&(o=o||"utf8",i=Xt.from(i,o));for(var p=this._block,c=this._blockSize,u=i.length,f=this._len,l=0;l<u;){for(var a=f%c,x=Math.min(u-l,c-a),g=0;g<x;g++)p[a+g]=i[l+g];f+=x,l+=x,f%c===0&&this._update(p)}return this._len+=u,this};G.prototype.digest=function(i){var o=this._len%this._blockSize;this._block[o]=128,this._block.fill(0,o+1),o>=this._finalSize&&(this._update(this._block),this._block.fill(0));var p=this._len*8;if(p<=4294967295)this._block.writeUInt32BE(p,this._blockSize-4);else{var c=(p&4294967295)>>>0,u=(p-c)/4294967296;this._block.writeUInt32BE(u,this._blockSize-8),this._block.writeUInt32BE(c,this._blockSize-4)}this._update(this._block);var f=this._hash();return i?f.toString(i):f};G.prototype._update=function(){throw new Error("_update must be implemented by subclass")};var nr=G,or=Ye,Gt=nr,ar=Yt.Buffer,pr=[1518500249,1859775393,-1894007588,-899497514],sr=new Array(80);function W(){this.init(),this._w=sr,Gt.call(this,64,56)}or(W,Gt);W.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function cr(i){return i<<1|i>>>31}function lr(i){return i<<5|i>>>27}function ur(i){return i<<30|i>>>2}function fr(i,o,p,c){return i===0?o&p|~o&c:i===2?o&p|o&c|p&c:o^p^c}W.prototype._update=function(i){for(var o=this._w,p=this._a|0,c=this._b|0,u=this._c|0,f=this._d|0,l=this._e|0,a=0;a<16;++a)o[a]=i.readInt32BE(a*4);for(;a<80;++a)o[a]=cr(o[a-3]^o[a-8]^o[a-14]^o[a-16]);for(var x=0;x<80;++x){var g=~~(x/20),y=lr(p)+fr(g,c,u,f)+l+o[x]+pr[g]|0;l=f,f=u,u=ur(c),c=p,p=y}this._a=p+this._a|0,this._b=c+this._b|0,this._c=u+this._c|0,this._d=f+this._d|0,this._e=l+this._e|0};W.prototype._hash=function(){var i=ar.allocUnsafe(20);return i.writeInt32BE(this._a|0,0),i.writeInt32BE(this._b|0,4),i.writeInt32BE(this._c|0,8),i.writeInt32BE(this._d|0,12),i.writeInt32BE(this._e|0,16),i};var hr=W;const mr=Ht(hr),ht=new Error("File system not available.");function xr(i,o,p){throw ht}function Vt(i){throw ht}function dr(i){throw ht}const gr=async i=>Vt();function yr(i){let o="";for(let p=0;p<i.length;p+=2)o+=String.fromCharCode(parseInt(i.substr(p,2),16));return btoa(o)}const V=(i,o="sha1")=>{if(o!=="sha1")throw new Error("Only sha1 algorithm is available.");const p=new mr;return yr(p.update(i).digest("hex"))},mt=async i=>{const o=new Ut,{name:p,revision:c,documentType:u,created:f,lastModified:l}=i,a={name:p,revision:c,documentType:u,created:f,lastModified:l};return o.file("header.json",JSON.stringify(a,null,2)),o.file("state.json",JSON.stringify(i.initialState||{},null,2)),o.file("operations.json",JSON.stringify(i.operations,null,2)),Object.keys(i.attachments).forEach(g=>{const{data:y,...v}=i.attachments[g];o.file(g,y,{base64:!0,createFolders:!0,comment:JSON.stringify(v)})}),o},Qt=async(i,o,p,c)=>{await(await mt(i)).generateAsync({type:"uint8array",streamFiles:!0});const f=c??i.name,l=`.${p}.zip`;return xr(o,f.endsWith(l)?f:`${f}${l}`)},wr=async(i,o)=>{const c=await(await mt(i)).generateAsync({type:"blob"}),u=await o.createWritable();await u.write(c),await u.close()},ot=async(i,o)=>{const p=Vt();return te(p,o)},te=async(i,o)=>{const p=new Ut;return await p.loadAsync(i),vr(p,o)};async function vr(i,o){const p=i.file("state.json");if(!p)throw new Error("Initial state not found");const c=await p.async("string"),u=JSON.parse(c),f=i.file("header.json");let l;f&&(l=JSON.parse(await f.async("string")));const a=i.file("operations.json");if(!a)throw new Error("Operations history not found");const x=JSON.parse(await a.async("string"));let g=gt(u,x,o,void 0,l);return l&&(g={...g,...l}),g}function ee(i){const o=i.replace(/^.*\./,"")||void 0,p=i.replace(/^.*[/\\]/,"")||void 0;return{extension:o,fileName:p}}async function Er(i){const{buffer:o,mimeType:p="application/octet-stream"}=await dr(),c=ee(i),u=o.toString("base64");return{data:u,hash:V(u),mimeType:p,...c}}async function br(i){const o=await gr(),p=Ke.getType(i)||"application/octet-stream",c=ee(i),u=o.toString("base64");return{data:u,hash:V(u),mimeType:p,...c}}function Fr(i,o){const p=i.revision[o.scope];return[$,P,J].includes(o.type)?p:p+1}function _r(i,o){return{...i,revision:{...i.revision,[o.scope]:Fr(i,o)},lastModified:new Date().toISOString()}}function Ar(i,o,p=0){if([$,P,J].includes(o.type))return i;const{scope:c}=o,u=i.operations[c].slice(0,i.revision[c]);return u.push({...o,index:u.length,timestamp:new Date().toISOString(),hash:"",scope:c,skip:p}),{...i,operations:{...i.operations,[c]:u}}}function Sr(i,o,p=0){let c=Ar(i,o,p);return c=_r(c,o),c}function Br(i,o,p){switch(Mt().parse(o),o.type){case Jt:return Ce(i,o.input);case $:return Le(i,o,p);case P:return qe(i,o,p);case J:return $e(i,o,p);case Wt:return Pe(i,o.input.state);default:return i}}function xt(i,o,p,c,u={}){const{skip:f=0}=u;let l=i;return at(o)&&(l=Br(l,o,p)),l=Sr(l,o,f),l=C.produce(l,a=>{const x=p(a.state,o,c);if(x)return C.castDraft({...l,state:x})}),C.produce(l,a=>{if([$,P,J].includes(o.type))return a;const x=o.scope||"global";a.operations[x][a.operations[x].length-1].hash=dt(a,x),!at(o)&&o.attachments&&o.attachments.forEach(g=>{const{hash:y,...v}=g;a.attachments[y]={...v}})})}function at(i){return[Jt,$,P,J,Wt].includes(i.type)}function D(i,o,p,c,u="global"){if(!i)throw new Error("Empty action type");if(typeof i!="string")throw new Error(`Invalid action type: ${i}`);const f={type:i,input:o,scope:u};p&&(f.attachments=p);try{c==null||c().parse(f.input)}catch(l){throw new Error(`Invalid action input: ${l}`)}return f}function re(i,o=xt){return(p,c,u,f)=>o(p,c,i,u,f)}const ie=(i,o)=>({name:"",documentType:"",revision:{global:0,local:0},created:new Date().toISOString(),lastModified:new Date().toISOString(),attachments:{},...i,state:(o==null?void 0:o(i==null?void 0:i.state))??(i==null?void 0:i.state)??{global:{},local:{}}}),ne=(i,o)=>{const p=ie(i,o);return{...p,initialState:p,operations:{global:[],local:[]}}},dt=(i,o="global")=>V(Te(i.state[o])),jr=(i,o=1e3)=>{const p=Math.random()*o;return V(`${(i??new Date).toISOString()}${p}`)};function R(i){return C.castImmutable(C.freeze(i,!0))}function oe(i){const o=[...i];let p=0,c=o.length>0?o[o.length-1].index:0;const u=[];for(const f of o.reverse()){if(p>0){const a=c-f.index;p-=a}if(p<0)throw new Error("Invalid operation index, missing operations");const l={ignore:p>0,operation:f};f.skip>0&&(p=p+(f.skip+1)),c=f.index,u.push(l)}return u.reverse()}function Ir(i){return Object.values(i).flatMap(o=>o).sort((o,p)=>new Date(o.timestamp).getTime()-new Date(p.timestamp).getTime())}function ae(i){return Object.values(i).flatMap(o=>o).sort((o,p)=>new Date(o.operation.timestamp).getTime()-new Date(p.operation.timestamp).getTime())}function L(i,o,p,c,u,f=xt){const l=re(p,f);return gt(i,o,l,c,u)}function gt(i,o,p,c,u){const f=ne(i),l=Object.keys(o).reduce((y,v)=>{const E=v;return{...y,[E]:o[E].slice(0,u==null?void 0:u.revision[E])}},{}),a=Object.keys(l).reduce((y,v)=>{const E=v;return{...y,[E]:oe(l[E])}},{}),x=ae(a).reduce((y,{ignore:v,operation:E})=>v?p(y,ue(E.scope),c,{skip:E.skip}):p(y,E,c),f),g=Object.keys(x.operations).reduce((y,v)=>{const E=v,A=u&&u.revision[E]<o[E].length?o[E].slice(u.revision[E]):[];return{...y,[E]:[...x.operations[E].map((U,z)=>{var N;return{...U,timestamp:((N=o[E][z])==null?void 0:N.timestamp)??U.timestamp}}),...A]}},{global:[],local:[]});return{...x,operations:g}}const pe=i=>D("SET_NAME",i,void 0,lt,void 0),se=(i=1,o="global")=>D("UNDO",i,void 0,ut,o),ce=(i=1,o="global")=>D("REDO",i,void 0,ct,o),le=(i,o,p="global")=>D("PRUNE",{start:i,end:o},void 0,st,p),yt=(i,o)=>D("LOAD_STATE",{state:i,operations:o},void 0,pt),ue=(i="global")=>D("NOOP",{},void 0,void 0,i),Ur=Object.freeze(Object.defineProperty({__proto__:null,loadState:yt,noop:ue,prune:le,redo:ce,setName:pe,undo:se},Symbol.toStringTag,{value:"Module"}));class kr{constructor(o,p,c){K(this,"_document");K(this,"_reducer");K(this,"_signalDispatch");this._reducer=o,this._document=p,this._signalDispatch=c}dispatch(o,p){return this._document=this._reducer(this._document,o,this._signalDispatch,p),this}saveToFile(o,p,c){return Qt(this._document,o,p,c)}async loadFromFile(o){this._document=await ot(o,this._reducer)}static async stateFromFile(o,p){return await ot(o,p)}get state(){return R(this._document.state)}get operations(){return R(this._document.operations)}get name(){return this._document.name}get documentType(){return this._document.documentType}get created(){return this._document.created}get lastModified(){return this._document.lastModified}get revision(){return this._document.revision.global}getRevision(o){return this._document.revision[o]}get initialState(){return R(this._document.initialState)}toDocument(){return R(this._document)}getAttachment(o){return this._document.attachments[o]}setName(o){return this.dispatch(pe(o)),this}undo(o){return this.dispatch(se(o)),this}redo(o){return this.dispatch(ce(o)),this}prune(o,p){return this.dispatch(le(o,p)),this}loadState(o,p){return this.dispatch(yt(o,p)),this}}function Tr(i,o){o.forEach(p=>{Object.getOwnPropertyNames(p.prototype).forEach(c=>{Object.defineProperty(i.prototype,c,Object.getOwnPropertyDescriptor(p.prototype,c)||Object.create(null))})})}exports.BaseActions=Ur;exports.BaseDocument=kr;exports.applyMixins=Tr;exports.baseReducer=xt;exports.createAction=D;exports.createDocument=ne;exports.createExtendedState=ie;exports.createReducer=re;exports.createZip=mt;exports.getLocalFile=br;exports.getRemoteFile=Er;exports.hashDocument=dt;exports.hashKey=jr;exports.isBaseAction=at;exports.loadFromFile=ot;exports.loadFromInput=te;exports.mapSkippedOperations=oe;exports.readOnly=R;exports.replayDocument=gt;exports.replayOperations=L;exports.saveToFile=Qt;exports.saveToFileHandle=wr;exports.sortMappedOperations=ae;exports.sortOperations=Ir;exports.zod=Re;
|