document-model 1.1.0-experimental.2 → 1.1.0-experimental.3
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/cjs/document-model.js +1 -1
- package/dist/browser/cjs/document.js +1 -1
- package/dist/browser/cjs/index.js +1 -1
- package/dist/{node/cjs/internal/index-CTavCc1t.js → browser/cjs/internal/index-DMRH7zDy.js} +1 -1
- package/dist/browser/cjs/internal/{index-DLodkpOq.js → index-dwAOfmBp.js} +1 -1
- package/dist/browser/cjs/internal/{object-CMr-_AP8.js → object-C-PazS9q.js} +4 -4
- package/dist/browser/es/document-model.js +2 -2
- package/dist/browser/es/document.js +2 -2
- package/dist/browser/es/index.js +3 -3
- package/dist/{node/es/internal/index-8lUz8qED.js → browser/es/internal/index-BVJxzkIs.js} +1 -1
- package/dist/browser/es/internal/{index-CL_1ivGq.js → index-DQztOVJu.js} +1 -1
- package/dist/browser/es/internal/{object-FFc9n_3I.js → object-iTBekDVP.js} +456 -445
- package/dist/node/cjs/document-model.js +1 -1
- package/dist/node/cjs/document.js +1 -1
- package/dist/node/cjs/index.js +1 -1
- package/dist/node/cjs/internal/{index-CPeTtUsk.js → index-BNFVmPew.js} +1 -1
- package/dist/{browser/cjs/internal/index-azT4DEce.js → node/cjs/internal/index-FvRO8SnG.js} +1 -1
- package/dist/node/cjs/internal/{object-DhI24-1e.js → object-Xvr4kDQj.js} +1 -1
- package/dist/node/es/document-model.js +2 -2
- package/dist/node/es/document.js +2 -2
- package/dist/node/es/index.js +3 -3
- package/dist/{browser/es/internal/index-BzNpRs2a.js → node/es/internal/index-BIrQOTP_.js} +1 -1
- package/dist/node/es/internal/{index-A880In4b.js → index-DOpbr_uw.js} +1 -1
- package/dist/node/es/internal/{object-C9n9Ijnt.js → object-C2s2eZ08.js} +26 -15
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("./internal/object-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("./internal/object-Xvr4kDQj.js");require("immer");require("jszip");require("crypto");require("fs");require("https");require("path");const e=require("./internal/index-BNFVmPew.js");require("zod");exports.Document=e.Document;exports.DocumentModel=e.DocumentModel$1;exports.actions=e.actions;exports.documentModel=e.documentModel;exports.module=e.module;exports.reducer=e.reducer;exports.utils=e.utils;exports.validateInitialState=e.validateInitialState;exports.validateModule=e.validateModule;exports.validateModuleOperation=e.validateModuleOperation;exports.validateModules=e.validateModules;exports.validateStateSchemaName=e.validateStateSchemaName;exports.z=e.zod;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./internal/object-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./internal/object-Xvr4kDQj.js"),r=require("./internal/index-FvRO8SnG.js");require("immer");require("zod");require("jszip");require("crypto");require("fs");require("https");require("path");exports.BaseDocument=e.BaseDocument;exports.actions=e.BaseActions;exports.applyMixins=e.applyMixins;exports.baseReducer=e.baseReducer;exports.processUndoRedo=e.processUndoRedo;exports.z=e.zod;exports.utils=r.index;
|
package/dist/node/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./internal/index-
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./internal/index-FvRO8SnG.js"),o=require("./internal/index-BNFVmPew.js");require("./internal/object-Xvr4kDQj.js");require("immer");require("zod");require("jszip");require("crypto");require("fs");require("https");require("path");const u={"powerhouse/document":e.Document,"powerhouse/document-model":o.DocumentModel},t={Document:e.Document,DocumentModel:o.DocumentModel};exports.Document=e.Document;exports.DocumentModel=o.DocumentModel;exports.DocumentModels=u;exports.default=t;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var Tt=Object.defineProperty;var Rt=(t,e,r)=>e in t?Tt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var be=(t,e,r)=>(Rt(t,typeof e!="symbol"?e+"":e,r),r);const s=require("./object-
|
|
1
|
+
"use strict";var Tt=Object.defineProperty;var Rt=(t,e,r)=>e in t?Tt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var be=(t,e,r)=>(Rt(t,typeof e!="symbol"?e+"":e,r),r);const s=require("./object-Xvr4kDQj.js");require("immer");require("jszip");require("crypto");require("fs");require("https");require("path");const o=require("zod"),xt=new RegExp("([\\p{Ll}\\d])(\\p{Lu})","gu"),Mt=new RegExp("(\\p{Lu})([\\p{Lu}][\\p{Ll}])","gu"),Dt=new RegExp("(\\d)\\p{Ll}|(\\p{L})\\d","u"),Nt=/[^\p{L}\d]+/giu,_e="$1\0$2",Ae="";function ze(t){let e=t.trim();e=e.replace(xt,_e).replace(Mt,_e),e=e.replace(Nt,"\0");let r=0,n=e.length;for(;e.charAt(r)==="\0";)r++;if(r===n)return[];for(;e.charAt(n-1)==="\0";)n--;return e.slice(r,n).split(/\0/g)}function Lt(t){const e=ze(t);for(let r=0;r<e.length;r++){const n=e[r],i=Dt.exec(n);if(i){const a=i.index+(i[1]??i[2]).length;e.splice(r,1,n.slice(0,a),n.slice(a))}}return e}function Ie(t,e){const[r,n,i]=wt(t,e),a=Pt(e==null?void 0:e.locale),l=jt(e==null?void 0:e.locale),d=e!=null&&e.mergeAmbiguousCharacters?Ct(a,l):yt(a,l);return r+n.map(d).join((e==null?void 0:e.delimiter)??"")+i}function Pt(t){return t===!1?e=>e.toLowerCase():e=>e.toLocaleLowerCase(t)}function jt(t){return t===!1?e=>e.toUpperCase():e=>e.toLocaleUpperCase(t)}function Ct(t,e){return r=>`${e(r[0])}${t(r.slice(1))}`}function yt(t,e){return(r,n)=>{const i=r[0];return(n>0&&i>="0"&&i<="9"?"_"+i:e(i))+t(r.slice(1))}}function wt(t,e={}){const r=e.split??(e.separateNumbers?Lt:ze),n=e.prefixCharacters??Ae,i=e.suffixCharacters??Ae;let a=0,l=t.length;for(;a<t.length;){const d=t.charAt(a);if(!n.includes(d))break;a++}for(;l>a;){const d=l-1,zt=t.charAt(d);if(!i.includes(zt))break;l=d}return[t.slice(0,a),r(t.slice(a,l)),t.slice(l)]}function T(t,e=!1){const r=[];if(e&&t==="")return r;try{const n=JSON.parse(t);!e&&!Object.keys(n).length&&r.push({message:"Initial state cannot be empty",details:{initialState:t}})}catch{r.push({message:"Invalid initial state",details:{initialState:t}})}return r}function R(t,e,r="",n=!0){const i=[];if(!n&&!t)return i.push({message:"State schema is required",details:{schema:t}}),i;if(n&&!t)return i;const a=`type ${Ie(e)}${Ie(r)}State`;return t.includes(a)||i.push({message:`Invalid state schema name. Expected ${a}`,details:{schema:t}}),i}function x(t){const e=[];t.length||e.push({message:"Modules are required",details:{modules:t}});const r=t.reduce((n,i)=>[...n,...b(i)],[]);return[...e,...r]}function b(t){const e=[];t.name||e.push({message:"Module name is required",details:{module:t}}),t.operations.length||e.push({message:"Module operations are required",details:{module:t}});const r=t.operations.reduce((n,i)=>[...n,..._(i)],[]);return[...e,...r]}function _(t){const e=[];return t.name||e.push({message:"Operation name is required",details:{operation:t}}),t.schema||e.push({message:"Operation schema is required",details:{operation:t}}),e}const kt=Object.freeze(Object.defineProperty({__proto__:null,validateInitialState:T,validateModule:b,validateModuleOperation:_,validateModules:x,validateStateSchemaName:R},Symbol.toStringTag,{value:"Module"})),M={id:"powerhouse/document-model",name:"DocumentModel",extension:"phdm",description:"The Powerhouse Document Model describes the state and operations of a document type.",author:{name:"Powerhouse",website:"https://www.powerhouse.inc/"},specifications:[{version:1,changeLog:[],modules:[{name:"header",operations:[{name:"SetModelName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetModelId",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetModelExtension",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetModelDescription",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetAuthorName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetAuthorWebsite",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"}],id:"",description:""},{name:"versioning",operations:[{name:"AddChangeLogItem",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"UpdateChangeLogItem",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"DeleteChangeLogItem",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"ReorderChangeLogItems",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"ReleaseNewVersion",schema:null,id:"",description:"",template:"",reducer:"",examples:[],errors:[],scope:"global"}],id:"",description:""},{name:"module",operations:[{name:"AddModule",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetModuleName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetModuleDescription",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"DeleteModule",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"ReorderModules",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"}],id:"",description:""},{name:"operation-error",operations:[{name:"AddOperationError",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationErrorCode",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationErrorName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationErrorDescription",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationErrorTemplate",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"DeleteOperationError",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"ReorderOperationErrors",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"}],id:"",description:""},{name:"operation-example",operations:[{name:"AddOperationExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"UpdateOperationExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"DeleteOperationExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"ReorderOperationExamples",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"}],id:"",description:""},{name:"operation",operations:[{name:"AddOperation",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationSchema",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationDescription",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationTemplate",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationReducer",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"MoveOperation",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"DeleteOperation",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"ReorderModuleOperations",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"}],id:"",description:""},{name:"state",operations:[{name:"SetStateSchema",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetInitialState",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"AddStateExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"UpdateStateExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"DeleteStateExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"ReorderStateExamples",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"}],id:"",description:""}],state:{global:{schema:"",initialValue:`{
|
|
2
2
|
"id": "",
|
|
3
3
|
"name": "",
|
|
4
4
|
"extension": "",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=require("./object-
|
|
1
|
+
"use strict";const e=require("./object-Xvr4kDQj.js"),t=Object.freeze(Object.defineProperty({__proto__:null,calculateSkipsLeft:e.calculateSkipsLeft,createAction:e.createAction,createDocument:e.createDocument,createExtendedState:e.createExtendedState,createReducer:e.createReducer,createZip:e.createZip,documentHelpers:e.documentHelpers,getLocalFile:e.getLocalFile,getRemoteFile:e.getRemoteFile,hashDocument:e.hashDocument,hashKey:e.hashKey,isBaseAction:e.isBaseAction,isNoopOperation:e.isNoopOperation,isSameDocument:e.isSameDocument,isUndoRedo:e.isUndoRedo,loadFromFile:e.loadFromFile,loadFromInput:e.loadFromInput,mapSkippedOperations:e.mapSkippedOperations,parseResultingState:e.parseResultingState,readOnly:e.readOnly,replayDocument:e.replayDocument,replayOperations:e.replayOperations,saveToFile:e.saveToFile,saveToFileHandle:e.saveToFileHandle,sortMappedOperations:e.sortMappedOperations,sortOperations:e.sortOperations,validateOperations:e.validateOperations},Symbol.toStringTag,{value:"Module"})),o=Object.freeze(Object.defineProperty({__proto__:null,BaseDocument:e.BaseDocument,actions:e.BaseActions,applyMixins:e.applyMixins,baseReducer:e.baseReducer,processUndoRedo:e.processUndoRedo,utils:t,z:e.zod},Symbol.toStringTag,{value:"Module"}));exports.Document=o;exports.index=t;
|
|
@@ -17,4 +17,4 @@ ${j}`,g.pop(),`[${E}]`}let x=Object.keys(s);const S=x.length;if(S===0)return"{}"
|
|
|
17
17
|
${y}`;let k="",_="",N=Math.min(S,D);m(s)&&(k+=d(s,$,D),x=x.slice(s.length),N-=s.length,_=$),L&&(x=r(x)),g.push(s);for(let E=0;E<N;E++){const M=x[E],C=Z(M,s[M],g,w,y);C!==void 0&&(k+=`${_}${a(M)}: ${C}`,_=$)}if(S>D){const E=S-D;k+=`${_}"...": "${v(E)} not stringified"`,_=$}return _!==""&&(k=`
|
|
18
18
|
${y}${k}
|
|
19
19
|
${j}`),g.pop(),`{${k}}`}case"number":return isFinite(s)?String(s):l?l(s):"null";case"boolean":return s===!0?"true":"false";case"undefined":return;case"bigint":if(T)return String(s);default:return l?l(s):void 0}}function Q(I,s,g){switch(typeof s){case"string":return a(s);case"object":{if(s===null)return"null";if(typeof s.toJSON=="function"){if(s=s.toJSON(I),typeof s!="object")return Q(I,s,g);if(s===null)return"null"}if(g.indexOf(s)!==-1)return u;let w="";if(Array.isArray(s)){if(s.length===0)return"[]";if(P<g.length+1)return'"[Array]"';g.push(s);const $=Math.min(s.length,D);let k=0;for(;k<$-1;k++){const N=Q(String(k),s[k],g);w+=N!==void 0?N:"null",w+=","}const _=Q(String(k),s[k],g);if(w+=_!==void 0?_:"null",s.length-1>D){const N=s.length-D-1;w+=`,"... ${v(N)} not stringified"`}return g.pop(),`[${w}]`}let y=Object.keys(s);const j=y.length;if(j===0)return"{}";if(P<g.length+1)return'"[Object]"';let x="",S=Math.min(j,D);m(s)&&(w+=d(s,",",D),y=y.slice(s.length),S-=s.length,x=","),L&&(y=r(y)),g.push(s);for(let $=0;$<S;$++){const k=y[$],_=Q(k,s[k],g);_!==void 0&&(w+=`${x}${a(k)}:${_}`,x=",")}if(j>D){const $=j-D;w+=`${x}"...":"${v($)} not stringified"`}return g.pop(),`{${w}}`}case"number":return isFinite(s)?String(s):l?l(s):"null";case"boolean":return s===!0?"true":"false";case"undefined":return;case"bigint":if(T)return String(s);default:return l?l(s):void 0}}function ue(I,s,g){if(arguments.length>1){let w="";if(typeof g=="number"?w=" ".repeat(Math.min(g,10)):typeof g=="string"&&(w=g.slice(0,10)),s!=null){if(typeof s=="function")return ot("",{"":I},[],s,w,"");if(Array.isArray(s))return st("",I,[],z(s),w,"")}if(w.length!==0)return Z("",I,[],w,"")}return Q("",I,[])}return ue}})(dt,dt.exports);var $e=dt.exports;const G=Ee($e);G.configure;function De(t,e){return{...t,name:e}}function ke(t,e,n){const{scope:i,input:o}=e,a={document:t,action:e,skip:n};return H.produce(a,r=>{if(r.document.operations[i].length<1)throw new Error(`Cannot undo: no operations in history for scope "${i}"`);if(o<1)throw new Error("Invalid UNDO action: input value must be greater than 0");if(r.skip>0)throw new Error("Cannot undo: skip value from reducer cannot be used with UNDO action");const p=r.document.operations[i].at(-1),m=p&&p.type==="NOOP"&&p.skip>0;if(r.skip+=o,m){r.skip+=p.skip;const O=r.document.operations[i][r.document.operations[i].length-2];O&&p.index-O.index===1&&r.document.operations[i].pop()}if(r.document.operations[i].length<r.skip)throw new Error("Cannot undo: you can't undo more operations than the ones in the scope history");const d=r.document.operations[i].length-1;let h=o,b=m?d-p.skip:d;for(;h>0&&b>=0;){const O=r.document.operations[i][b];if(!O){h--,b--;continue}O.type==="NOOP"&&O.skip>0?(b=b-(O.skip+1),r.skip+=O.skip+1):(r.document.clipboard.push({...O}),h--,b--)}r.action=me(i)})}function ze(t,e,n){const{scope:i,input:o}=e,a={document:t,action:e,skip:n};return H.produce(a,r=>{if(r.skip>0)throw new Error("Cannot redo: skip value from reducer cannot be used with REDO action");if(o>1)throw new Error("Cannot redo: you can only redo one operation at a time");if(o<1)throw new Error("Invalid REDO action: invalid redo input value");if(r.document.clipboard.length<1)throw new Error("Cannot redo: no operations in the clipboard");const p=r.document.clipboard.findLastIndex(d=>d.scope===i);if(p<0)throw new Error(`Cannot redo: no operations in clipboard for scope "${i}"`);const m=r.document.clipboard.splice(p,1)[0];r.action=H.castDraft({type:m.type,scope:m.scope,input:m.input})})}function Te(t,e,n){const{scope:i}=e,o=t.operations[i];let{input:{start:a,end:r}}=e;a=a||0,r=r||o.length;const p=o.slice(a,r),m=o.slice(0,a),d=o.slice(r),h=pt(t.initialState,{...t.operations,[i]:m.concat(p)},n),{name:b,state:O}=h,v=m.length,z=m.length?m[m.length-1].timestamp:d.length?d[0].timestamp:new Date().toISOString();return pt(t.initialState,{...t.operations,[i]:[...m,{...Tt({name:b,state:O},p.length),timestamp:z,index:v,hash:mt({state:O},"global")},...d.map((A,R)=>({...A,index:v+R+1}))]},n)}function _e(t,e){return{...t,name:e.name,state:e.state??{global:{},local:{}}}}const Ht="SET_NAME",nt="UNDO",it="REDO",ct="PRUNE",Vt="LOAD_STATE",ve="NOOP",Bt={"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(Bt);var q=function(t,e,n,i){if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!i:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return n==="m"?i:n==="a"?i.call(t):i?i.value:e.get(t)},W,Y,X;class Ne{constructor(...e){W.set(this,new Map),Y.set(this,new Map),X.set(this,new Map);for(const n of e)this.define(n)}define(e,n=!1){for(let[i,o]of Object.entries(e)){i=i.toLowerCase(),o=o.map(p=>p.toLowerCase()),q(this,X,"f").has(i)||q(this,X,"f").set(i,new Set);const a=q(this,X,"f").get(i);let r=!0;for(let p of o){const m=p.startsWith("*");if(p=m?p.slice(1):p,a==null||a.add(p),r&&q(this,Y,"f").set(i,p),r=!1,m)continue;const d=q(this,W,"f").get(p);if(d&&d!=i&&!n)throw new Error(`"${i} -> ${p}" conflicts with "${d} -> ${p}". Pass \`force=true\` to override this definition.`);q(this,W,"f").set(p,i)}}return this}getType(e){if(typeof e!="string")return null;const n=e.replace(/^.*[/\\]/,"").toLowerCase(),i=n.replace(/^.*\./,"").toLowerCase(),o=n.length<e.length;return!(i.length<n.length-1)&&o?null:q(this,W,"f").get(i)??null}getExtension(e){var n;return typeof e!="string"?null:(e=(n=e==null?void 0:e.split)==null?void 0:n.call(e,";")[0],(e&&q(this,Y,"f").get(e.trim().toLowerCase()))??null)}getAllExtensions(e){return typeof e!="string"?null:q(this,X,"f").get(e.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 e of q(this,X,"f").values())Object.freeze(e);return this}_getTestState(){return{types:q(this,W,"f"),extensions:q(this,Y,"f")}}}W=new WeakMap,Y=new WeakMap,X=new WeakMap;const Ie=new Ne(Bt)._freeze();function Ae(t,e,n){const i=xe.join(t,e);return ft.mkdirSync(t,{recursive:!0}),new Promise((o,a)=>{try{ft.writeFile(i,n,{},r=>{r?a(r):o(i)})}catch(r){a(r)}})}function Xt(t){return ft.readFileSync(t)}function Pe(t){return new Promise((e,n)=>{he.get(t,i=>{const o=[],a=i.headers["content-type"];i.on("data",r=>{o.push(r)}),i.on("end",()=>{e({buffer:Buffer.concat(o),mimeType:a})})}).on("error",i=>{n(i)})})}const Me=async t=>Xt(t),lt=(t,e="sha1")=>ge.createHash(e).update(t).digest("base64");function Kt(t){const e=[],n=Object.keys(t);for(const i of n){const o=t[i].sort((a,r)=>a.index-r.index);for(let a=0;a<o.length;a++)o[a].index!==a&&e.push({message:`Invalid operation index ${o[a].index} at position ${a}`,details:{position:a,operation:o[a],scope:o[a].scope}})}return e}const jt=async t=>{const e=new _t,{name:n,revision:i,documentType:o,created:a,lastModified:r}=t,p={name:n,revision:i,documentType:o,created:a,lastModified:r};return e.file("header.json",JSON.stringify(p,null,2)),e.file("state.json",JSON.stringify(t.initialState||{},null,2)),e.file("operations.json",JSON.stringify(t.operations,null,2)),Object.keys(t.attachments).forEach(d=>{const{data:h,...b}=t.attachments[d];e.file(d,h,{base64:!0,createFolders:!0,comment:JSON.stringify(b)})}),e},Wt=async(t,e,n,i)=>{const a=await(await jt(t)).generateAsync({type:"uint8array",streamFiles:!0}),r=i??t.name,p=`.${n}.zip`;return Ae(e,r.endsWith(p)?r:`${r}${p}`,a)},Fe=async(t,e)=>{const i=await(await jt(t)).generateAsync({type:"blob"}),o=await e.createWritable();await o.write(i),await o.close()},gt=async(t,e,n)=>{const i=Xt(t);return Gt(i,e,n)},Gt=async(t,e,n)=>{const i=new _t;return await i.loadAsync(t),Re(i,e,n)};async function Re(t,e,n){const i=t.file("state.json");if(!i)throw new Error("Initial state not found");const o=await i.async("string"),a=JSON.parse(o),r=t.file("header.json");let p;r&&(p=JSON.parse(await r.async("string")));const m=t.file("operations.json");if(!m)throw new Error("Operations history not found");const d=JSON.parse(await m.async("string")),h=Kt(d);if(h.length){const O=h.map(v=>v.message);throw new Error(O.join(`
|
|
20
|
-
`))}let b=kt(a,d,e,void 0,p,{},n);return p&&(b={...b,...p}),b}function Zt(t){const e=t.replace(/^.*\./,"")||void 0,n=t.replace(/^.*[/\\]/,"")||void 0;return{extension:e,fileName:n}}async function Le(t){const{buffer:e,mimeType:n="application/octet-stream"}=await Pe(t),i=Zt(t),o=e.toString("base64");return{data:o,hash:lt(o),mimeType:n,...i}}async function qe(t){const e=await Me(t),n=Ie.getType(t)||"application/octet-stream",i=Zt(t),o=e.toString("base64");return{data:o,hash:lt(o),mimeType:n,...i}}var Qt=(t=>(t.UNEXPECTED_INDEX="UNEXPECTED_INDEX",t))(Qt||{}),Yt=(t=>(t.DUPLICATED_INDEX="DUPLICATED_INDEX",t.MISSING_INDEX="MISSING_INDEX",t))(Yt||{});function Et(t){const e=[];let n=-1;for(const i of t){const o=i.index-i.skip;o!==n+1&&e.push({operation:{index:i.index,skip:i.skip},issue:"UNEXPECTED_INDEX",category:o>n+1?"MISSING_INDEX":"DUPLICATED_INDEX",message:`Expected index ${n+1} with skip 0 or equivalent, got index ${i.index} with skip ${i.skip}`}),n=i.index}return e}function V(t){var i,o,a;const e=[];let n=t.length-1;for(;n>-1;){e.unshift(t[n]);const r=(((i=t[n])==null?void 0:i.index)||0)-(((o=t[n])==null?void 0:o.skip)||0)-1;let p=n-1;for(;p>-1&&(((a=t[p])==null?void 0:a.index)||0)>r;)p--;n=p}return e}function Ce(t){const e=[...t],n=e[e.length-1];return n&&(n.type==="NOOP"?e.push({...n,index:n.index,type:"NOOP",skip:ne(t)}):e.push({type:"NOOP",index:n.index+1,timestamp:new Date().toISOString(),input:{},skip:1,scope:n.scope,hash:n.hash})),e}function B(t){return t.slice().sort((e,n)=>e.skip-n.skip).sort((e,n)=>e.index-n.index)}const Ue=(t,e,n)=>[...e,...n].sort((i,o)=>new Date(i.timestamp).getTime()-new Date(o.timestamp).getTime()).map((i,o)=>({...i,index:t.index+o,skip:o===0?t.skip:0})),Je=(t,e,n)=>[...e,...n].sort((i,o)=>new Date(i.timestamp).getTime()-new Date(o.timestamp).getTime()).sort((i,o)=>i.index-o.index).map((i,o)=>({...i,index:t.index+o,skip:o===0?t.skip:0}));function $t(t,e){return G(t)===G(e)}function He(t,e){const n=V(B(t.slice())),i=V(B(e.slice()));if(n.length<1)return[i,[]];const o=[];let a=!1;for(;i.length>0;){const r=i[0];let p=n.shift();for(;p&&te(p,r);)o.push(p),p=n.shift();if(p?a||($t(p,r)?(i.shift(),o.push(p)):(n.unshift(p),a=!0)):a=!0,a){let m=i.shift();for(;m;)o.push(m),m=i.shift()}}if(!a){let r=n.shift();for(;r;)o.push(r),r=n.shift()}return[V(o),n]}function te(t,e){return t.index<e.index||t.index===e.index&&t.skip<e.skip}function ee(t,e){const n=[],i=[],o=[],a=Math.max(t.length,e.length);let r=!1;for(let p=0;p<a;p++){const m=t[p],d=e[p];m&&d?!r&&$t(m,d)?n.push(m):(r=!0,i.push(m),o.push(d)):m?i.push(m):d&&o.push(d)}return[n,i,o]}function Ve(t,e,n){const[i,o,a]=ee(V(t),V(e)),r=ut(i),p=1+Math.max(r,ut(o),ut(a)),m=n({index:p,skip:p-(r+1)},o,a);return i.concat(m)}function ut(t){const e=t[t.length-1];return e?e.index:-1}function ne(t){var i,o,a;if(t.length<1)return-1;const e=V(t);let n=(((i=e[e.length-1])==null?void 0:i.skip)||0)+1;return e.length>1&&(n+=((o=e[e.length-2])==null?void 0:o.skip)||0),(((a=e[e.length-1])==null?void 0:a.index)||-1)<n?-1:n}const Be=t=>Et(V(B(t))),Xe=t=>t.reduce((n,i)=>{var o;return n[i.scope]||(n[i.scope]=[]),(o=n[i.scope])==null||o.push(i),n},{}),Ke=(t,e)=>{var m;const n={integrityIssues:[],validOperations:[],invalidOperations:[],duplicatedOperations:[]},i=B(t),o=B(e),a=Et([...i,...o]),p=(m=[...a.filter(d=>d.category==="MISSING_INDEX")].sort((d,h)=>h.operation.index-d.operation.index).pop())==null?void 0:m.operation;for(const d of o){if(p&&d.index>=p.index){n.invalidOperations.push(d);continue}if(a.some(b=>b.operation.index===d.index&&b.operation.skip===d.skip&&b.category==="DUPLICATED_INDEX")){n.duplicatedOperations.push(d);continue}n.validOperations.push(d)}return n.integrityIssues.push(...a),n};function We(t,e){return t.filter(n=>!e.some(i=>n.type==="NOOP"&&n.skip===0&&n.index===i.index||n.index===i.index&&n.skip===i.skip&&n.scope===i.scope&&n.hash===i.hash&&n.type===i.type))}function ie(t,e){const[n]=B(t).slice(-1),i=(n==null?void 0:n.index)??-1,o=i+1,a={...e,index:e.index??o};if(a.index<i)throw new Error(`The skip header operation index must be greater than or equal to ${i}`);return(V(B([...t,a]))||[]).slice(0,-1)}function ht(t){return{...Object.entries(t).reduce((n,i)=>{const[o,a]=i;return{...n,[o]:V(B(a))}},{})}}const Ge=Object.freeze(Object.defineProperty({__proto__:null,IntegrityIssueSubType:Yt,IntegrityIssueType:Qt,addUndo:Ce,attachBranch:He,checkCleanedOperationsIntegrity:Et,checkOperationsIntegrity:Be,garbageCollect:V,garbageCollectDocumentOperations:ht,groupOperationsByScope:Xe,merge:Ve,nextSkipNumber:ne,operationsAreEqual:$t,precedes:te,prepareOperations:Ke,removeExistingOperations:We,reshuffleByTimestamp:Ue,reshuffleByTimestampAndIndex:Je,skipHeaderOperations:ie,sortOperations:B,split:ee},Symbol.toStringTag,{value:"Module"}));function Ze(t,e){let n;return"index"in e?n={...e}:n=t.operations[e.scope].at(-1),((n==null?void 0:n.index)??-1)+1}function Qe(t,e){return{...t,revision:{...t.revision,[e.scope]:Ze(t,e)},lastModified:new Date().toISOString()}}function Ye(t,e,n=0){if([nt,it,ct].includes(e.type))return t;const{scope:i}=e,o=t.operations[i].slice(),a=o.at(-1);let r=((a==null?void 0:a.index)??-1)+1;if("index"in e){if(e.index-n>r)throw new Error(`Missing operations: expected ${r} with skip 0 or equivalent, got index ${e.index} with skip ${n}`);r=e.index}return o.push({...e,index:r,timestamp:new Date().toISOString(),hash:"",scope:i,skip:n,error:void 0}),{...t,operations:{...t.operations,[i]:o}}}function tn(t,e,n=0){let i=Ye(t,e,n);return i=Qe(i,e),i}function en(t,e,n){switch(Ft().parse(e),e.type){case Ht:return De(t,e.input);case ct:return Te(t,e,n);case Vt:return _e(t,e.input.state);default:return t}}function nn(t,e,n){switch(e.type){case nt:return ke(t,e,n);case it:return ze(t,e,n);default:return{document:t,action:e,skip:n}}}function on(t,e,n,i,o=!1,a=zt){const r=e.scope,p=t.operations[r].at(-1);if(!p)return t;const m=ht({...t.operations,[r]:ie(t.operations[r],p)});let d;const h=m[r].at(-1);if(o&&(h!=null&&h.resultingState))d=a(h.resultingState);else{const{state:b}=pt(t.initialState,m,n,void 0,void 0,void 0,void 0,{reuseHash:!0,reuseOperationResultingState:o,operationResultingStateParser:a});d=b[r]}return{...t,state:{...t.state,[r]:d},operations:ht({...t.operations})}}function Dt(t,e,n,i,o={}){const{skip:a,ignoreSkipOperations:r=!1,reuseHash:p=!1,reuseOperationResultingState:m=!1,operationResultingStateParser:d}=o,h={...e},b=a||0;let O={...t};const v=!r&&(b>0||"index"in h&&h.skip>0);return xt(h)&&(O=en(O,h,n)),O=tn(O,h,b),v&&(O=on(O,h,n,b,m,d)),O=H.produce(O,z=>{try{const A=n(z.state,h,i);if(A)return H.castDraft({...O,state:A})}catch(A){const R=O.operations[h.scope].length-1;z.operations[h.scope][R].error=A.message,z.operations[h.scope][R].skip=0,v&&(z.state=H.castDraft({...t.state}),z.operations=H.castDraft({...t.operations,[h.scope]:[...t.operations[h.scope],{...z.operations[h.scope][R]}]}))}}),H.produce(O,z=>{if([nt,it,ct].includes(h.type))return z;const A=h.scope||"global",R=p&&Object.prototype.hasOwnProperty.call(h,"hash")?h.hash:mt(z,A);z.operations[A][z.operations[A].length-1].hash=R,!xt(h)&&h.attachments&&h.attachments.forEach(c=>{const{hash:l,...u}=c;z.attachments[l]={...u}})})}function sn(t){return t.type===ve&&t.skip!==void 0&&t.skip>0&&t.hash!==void 0}function rn(t){return[nt,it].includes(t.type)}function xt(t){return[Ht,nt,it,ct,Vt].includes(t.type)}function K(t,e,n,i,o="global"){if(!t)throw new Error("Empty action type");if(typeof t!="string")throw new Error(`Invalid action type: ${JSON.stringify(t)}`);const a={type:t,input:e,scope:o};n&&(a.attachments=n);try{i==null||i().parse(a.input)}catch(r){throw new Error(`Invalid action input: ${r}`)}return a}function oe(t,e=Dt){return(n,i,o,a)=>e(n,i,t,o,a)}const se=(t,e)=>({name:"",documentType:"",revision:{global:0,local:0},created:new Date().toISOString(),lastModified:new Date().toISOString(),attachments:{},...t,state:(e==null?void 0:e(t==null?void 0:t.state))??(t==null?void 0:t.state)??{global:{},local:{}}}),re=(t,e)=>{const n=se(t,e);return{...n,initialState:n,operations:{global:[],local:[]},clipboard:[]}},mt=(t,e="global")=>lt(G(t.state[e]||"")),an=(t,e=1e3)=>{const n=Math.random()*e;return lt(`${(t??new Date).toISOString()}${n}`)};function tt(t){return H.castImmutable(H.freeze(t,!0))}function pn(t,e){const n=[...t];let i=e||0,o=n.length>0?n[n.length-1].index:0;const a=[];for(const r of n.reverse()){if(i>0){const d=o-r.index;i-=d}if(i<0)throw new Error("Invalid operation index, missing operations");const p={ignore:i>0,operation:r},m=r.skip>0?r.skip+1:0;if(m>0&&m>i){const d=m-i;i=i+d}o=r.index,a.push(p)}return a.reverse()}function cn(t,e,n){const i=t.slice().sort((p,m)=>p.skip-m.skip).sort((p,m)=>p.index-m.index);let o=n,a=0,r=e;for(const p of i.reverse()){const m=r-p.index;if(o=o-m,o>-1)a++,r=p.index;else break}return a}function ln(t){return Object.values(t).flatMap(e=>e).sort((e,n)=>new Date(e.timestamp).getTime()-new Date(n.timestamp).getTime())}function mn(t){return Object.values(t).flatMap(e=>e).sort((e,n)=>new Date(e.operation.timestamp).getTime()-new Date(n.operation.timestamp).getTime())}function pt(t,e,n,i,o,a=Dt,r={},p){const m=oe(n,a);return kt(t,e,m,i,o,r,p)}function kt(t,e,n,i,o,a={},r){const{checkHashes:p=!0,reuseOperationResultingState:m,operationResultingStateParser:d=zt}=r||{};let h=t;const b=[],O={global:[],local:[]};if(m)for(const[c,l]of Object.entries(e)){const u=l.findLastIndex(L=>!!L.resultingState);if(u<0){b.push(...l);continue}const T=l[u];try{const L=d(T.resultingState);h={...h,state:{...h.state,[c]:L}},O[c].push(...l.slice(0,u+1)),b.push(...l.slice(u+1))}catch{b.push(...l)}}else b.push(...Object.values(e).flat());const v=re(h);v.initialState=t,v.operations=O;const z=b.reduce((c,l)=>n(c,l,i,{skip:l.skip,ignoreSkipOperations:!0,reuseHash:!p}),v);if(!p)for(const c of Object.keys(z.state))for(let l=b.length-1;l>=0;l--){const u=b[l];if(u.scope===c){if(u.hash!==mt(z,c))throw new Error(`Hash mismatch for scope ${c}`);break}}const A=Object.keys(z.operations).reduce((c,l)=>{const u=l;return{...c,[u]:[...z.operations[u].map((T,L)=>{var P;return{...T,timestamp:((P=e[u][L])==null?void 0:P.timestamp)??T.timestamp}})]}},{global:[],local:[]}),R=Object.values(A).reduce((c,l)=>{const u=l[l.length-1];return(u==null?void 0:u.timestamp)>c&&(c=u.timestamp),c},t.lastModified);return{...z,operations:A,lastModified:R}}function un(t,e){return G(t)===G(e)}function zt(t){const e=typeof t;if(e==="string")return JSON.parse(t);if(e==="object")return t;throw new Error(`Providing resulting state is of type: ${e}`)}const ae=t=>K("SET_NAME",t,void 0,Ot,void 0),pe=(t=1,e="global")=>K("UNDO",t,void 0,St,e),ce=(t=1,e="global")=>K("REDO",t,void 0,wt,e),le=(t,e,n="global")=>K("PRUNE",{start:t,end:e},void 0,bt,n),Tt=(t,e)=>K("LOAD_STATE",{state:t,operations:e},void 0,yt),me=(t="global")=>K("NOOP",{},void 0,void 0,t),fn=Object.freeze(Object.defineProperty({__proto__:null,loadState:Tt,noop:me,prune:le,redo:ce,setName:ae,undo:pe},Symbol.toStringTag,{value:"Module"}));class dn{constructor(e,n,i){at(this,"_document");at(this,"_reducer");at(this,"_signalDispatch");this._reducer=e,this._document=n,this._signalDispatch=i}dispatch(e,n){return this._document=this._reducer(this._document,e,this._signalDispatch,n),this}saveToFile(e,n,i){return Wt(this._document,e,n,i)}async loadFromFile(e){this._document=await gt(e,this._reducer)}static async stateFromFile(e,n){return await gt(e,n)}get state(){return tt(this._document.state)}get operations(){return tt(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(e){return this._document.revision[e]}get initialState(){return tt(this._document.initialState)}toDocument(){return tt(this._document)}getAttachment(e){return this._document.attachments[e]}setName(e){return this.dispatch(ae(e)),this}undo(e){return this.dispatch(pe(e)),this}redo(e){return this.dispatch(ce(e)),this}prune(e,n){return this.dispatch(le(e,n)),this}loadState(e,n){return this.dispatch(Tt(e,n)),this}}function gn(t,e){e.forEach(n=>{Object.getOwnPropertyNames(n.prototype).forEach(i=>{Object.defineProperty(t.prototype,i,Object.getOwnPropertyDescriptor(n.prototype,i)||Object.create(null))})})}exports.BaseActions=fn;exports.BaseDocument=dn;exports.applyMixins=gn;exports.baseReducer=Dt;exports.calculateSkipsLeft=cn;exports.createAction=K;exports.createDocument=re;exports.createExtendedState=se;exports.createReducer=oe;exports.createZip=jt;exports.documentHelpers=Ge;exports.getLocalFile=qe;exports.getRemoteFile=Le;exports.hashDocument=mt;exports.hashKey=an;exports.isBaseAction=xt;exports.isNoopOperation=sn;exports.isSameDocument=un;exports.isUndoRedo=rn;exports.loadFromFile=gt;exports.loadFromInput=Gt;exports.mapSkippedOperations=pn;exports.parseResultingState=zt;exports.processUndoRedo=nn;exports.readOnly=tt;exports.replayDocument=kt;exports.replayOperations=pt;exports.saveToFile=Wt;exports.saveToFileHandle=Fe;exports.sortMappedOperations=mn;exports.sortOperations=ln;exports.validateOperations=Kt;exports.zod=je;
|
|
20
|
+
`))}let b=kt(a,d,e,void 0,p,{},n);return p&&(b={...b,...p}),b}function Zt(t){const e=t.replace(/^.*\./,"")||void 0,n=t.replace(/^.*[/\\]/,"")||void 0;return{extension:e,fileName:n}}async function Le(t){const{buffer:e,mimeType:n="application/octet-stream"}=await Pe(t),i=Zt(t),o=e.toString("base64");return{data:o,hash:lt(o),mimeType:n,...i}}async function qe(t){const e=await Me(t),n=Ie.getType(t)||"application/octet-stream",i=Zt(t),o=e.toString("base64");return{data:o,hash:lt(o),mimeType:n,...i}}var Qt=(t=>(t.UNEXPECTED_INDEX="UNEXPECTED_INDEX",t))(Qt||{}),Yt=(t=>(t.DUPLICATED_INDEX="DUPLICATED_INDEX",t.MISSING_INDEX="MISSING_INDEX",t))(Yt||{});function Et(t){const e=[];let n=-1;for(const i of t){const o=i.index-i.skip;o!==n+1&&e.push({operation:{index:i.index,skip:i.skip},issue:"UNEXPECTED_INDEX",category:o>n+1?"MISSING_INDEX":"DUPLICATED_INDEX",message:`Expected index ${n+1} with skip 0 or equivalent, got index ${i.index} with skip ${i.skip}`}),n=i.index}return e}function V(t){var i,o,a;const e=[];let n=t.length-1;for(;n>-1;){e.unshift(t[n]);const r=(((i=t[n])==null?void 0:i.index)||0)-(((o=t[n])==null?void 0:o.skip)||0)-1;let p=n-1;for(;p>-1&&(((a=t[p])==null?void 0:a.index)||0)>r;)p--;n=p}return e}function Ce(t){const e=[...t],n=e[e.length-1];return n&&(n.type==="NOOP"?e.push({...n,index:n.index,type:"NOOP",skip:ne(t)}):e.push({type:"NOOP",index:n.index+1,timestamp:new Date().toISOString(),input:{},skip:1,scope:n.scope,hash:n.hash})),e}function B(t){return t.slice().sort((e,n)=>e.skip-n.skip).sort((e,n)=>e.index-n.index)}const Ue=(t,e,n)=>[...e,...n].sort((i,o)=>new Date(i.timestamp).getTime()-new Date(o.timestamp).getTime()).map((i,o)=>({...i,index:t.index+o,skip:o===0?t.skip:0})),Je=(t,e,n)=>[...e,...n].sort((i,o)=>new Date(i.timestamp).getTime()-new Date(o.timestamp).getTime()).sort((i,o)=>i.index-o.index).map((i,o)=>({...i,index:t.index+o,skip:o===0?t.skip:0}));function $t(t,e){return G(t)===G(e)}function He(t,e){const n=V(B(t.slice())),i=V(B(e.slice()));if(n.length<1)return[i,[]];const o=[];let a=!1;for(;i.length>0;){const r=i[0];let p=n.shift();for(;p&&te(p,r);)o.push(p),p=n.shift();if(p?a||($t(p,r)?(i.shift(),o.push(p)):(n.unshift(p),a=!0)):a=!0,a){let m=i.shift();for(;m;)o.push(m),m=i.shift()}}if(!a){let r=n.shift();for(;r;)o.push(r),r=n.shift()}return[V(o),n]}function te(t,e){return t.index<e.index||t.index===e.index&&t.skip<e.skip}function ee(t,e){const n=[],i=[],o=[],a=Math.max(t.length,e.length);let r=!1;for(let p=0;p<a;p++){const m=t[p],d=e[p];m&&d?!r&&$t(m,d)?n.push(m):(r=!0,i.push(m),o.push(d)):m?i.push(m):d&&o.push(d)}return[n,i,o]}function Ve(t,e,n){const[i,o,a]=ee(V(t),V(e)),r=ut(i),p=1+Math.max(r,ut(o),ut(a)),m=n({index:p,skip:p-(r+1)},o,a);return i.concat(m)}function ut(t){const e=t[t.length-1];return e?e.index:-1}function ne(t){var i,o,a;if(t.length<1)return-1;const e=V(t);let n=(((i=e[e.length-1])==null?void 0:i.skip)||0)+1;return e.length>1&&(n+=((o=e[e.length-2])==null?void 0:o.skip)||0),(((a=e[e.length-1])==null?void 0:a.index)||-1)<n?-1:n}const Be=t=>Et(V(B(t))),Xe=t=>t.reduce((n,i)=>{var o;return n[i.scope]||(n[i.scope]=[]),(o=n[i.scope])==null||o.push(i),n},{}),Ke=(t,e)=>{var m;const n={integrityIssues:[],validOperations:[],invalidOperations:[],duplicatedOperations:[]},i=B(t),o=B(e),a=Et([...i,...o]),p=(m=[...a.filter(d=>d.category==="MISSING_INDEX")].sort((d,h)=>h.operation.index-d.operation.index).pop())==null?void 0:m.operation;for(const d of o){if(p&&d.index>=p.index){n.invalidOperations.push(d);continue}if(a.some(b=>b.operation.index===d.index&&b.operation.skip===d.skip&&b.category==="DUPLICATED_INDEX")){n.duplicatedOperations.push(d);continue}n.validOperations.push(d)}return n.integrityIssues.push(...a),n};function We(t,e){return t.filter(n=>!e.some(i=>n.type==="NOOP"&&n.skip===0&&n.index===i.index||n.index===i.index&&n.skip===i.skip&&n.scope===i.scope&&n.hash===i.hash&&n.type===i.type))}function ie(t,e){const[n]=B(t).slice(-1),i=(n==null?void 0:n.index)??-1,o=i+1,a={...e,index:e.index??o};if(a.index<i)throw new Error(`The skip header operation index must be greater than or equal to ${i}`);return(V(B([...t,a]))||[]).slice(0,-1)}function ht(t){return{...Object.entries(t).reduce((n,i)=>{const[o,a]=i;return{...n,[o]:V(B(a))}},{})}}const Ge=Object.freeze(Object.defineProperty({__proto__:null,IntegrityIssueSubType:Yt,IntegrityIssueType:Qt,addUndo:Ce,attachBranch:He,checkCleanedOperationsIntegrity:Et,checkOperationsIntegrity:Be,garbageCollect:V,garbageCollectDocumentOperations:ht,groupOperationsByScope:Xe,merge:Ve,nextSkipNumber:ne,operationsAreEqual:$t,precedes:te,prepareOperations:Ke,removeExistingOperations:We,reshuffleByTimestamp:Ue,reshuffleByTimestampAndIndex:Je,skipHeaderOperations:ie,sortOperations:B,split:ee},Symbol.toStringTag,{value:"Module"}));function Ze(t,e){let n;return"index"in e?n={...e}:n=t.operations[e.scope].at(-1),((n==null?void 0:n.index)??-1)+1}function Qe(t,e){return{...t,revision:{...t.revision,[e.scope]:Ze(t,e)},lastModified:new Date().toISOString()}}function Ye(t,e,n=0,i=!1){if([nt,it,ct].includes(e.type))return t;const{scope:o}=e,a=t.operations[o].slice(),r=a.at(-1);let p=((r==null?void 0:r.index)??-1)+1;if("index"in e){if(e.index-n>p)throw new Error(`Missing operations: expected ${p} with skip 0 or equivalent, got index ${e.index} with skip ${n}`);p=e.index}const m={...e,index:p,timestamp:new Date().toISOString(),hash:"",scope:o,skip:n,error:void 0};return i&&(m.resultingState=t.state[o]),a.push(m),{...t,operations:{...t.operations,[o]:a}}}function tn(t,e,n=0,i=!1){let o=Ye(t,e,n,i);return o=Qe(o,e),o}function en(t,e,n){switch(Ft().parse(e),e.type){case Ht:return De(t,e.input);case ct:return Te(t,e,n);case Vt:return _e(t,e.input.state);default:return t}}function nn(t,e,n){switch(e.type){case nt:return ke(t,e,n);case it:return ze(t,e,n);default:return{document:t,action:e,skip:n}}}function on(t,e,n,i,o=!1,a=zt){const r=e.scope,p=t.operations[r].at(-1);if(!p)return t;const m=ht({...t.operations,[r]:ie(t.operations[r],p)});let d;const h=m[r].at(-1);if(o&&(h!=null&&h.resultingState))d=a(h.resultingState);else{const{state:b}=pt(t.initialState,m,n,void 0,void 0,void 0,void 0,{reuseHash:!0,reuseOperationResultingState:o,operationResultingStateParser:a});d=b[r]}return{...t,state:{...t.state,[r]:d},operations:ht({...t.operations})}}function Dt(t,e,n,i,o={}){const{skip:a,ignoreSkipOperations:r=!1,reuseHash:p=!1,reuseOperationResultingState:m=!1,operationResultingStateParser:d}=o,h={...e},b=a||0;let O={...t};const v=!r&&(b>0||"index"in h&&h.skip>0);return xt(h)&&(O=en(O,h,n)),O=tn(O,h,b,m),v&&(O=on(O,h,n,b,m,d)),O=H.produce(O,z=>{try{const A=n(z.state,h,i);if(A)return H.castDraft({...O,state:A})}catch(A){const R=O.operations[h.scope].length-1;z.operations[h.scope][R].error=A.message,z.operations[h.scope][R].skip=0,v&&(z.state=H.castDraft({...t.state}),z.operations=H.castDraft({...t.operations,[h.scope]:[...t.operations[h.scope],{...z.operations[h.scope][R]}]}))}}),H.produce(O,z=>{if([nt,it,ct].includes(h.type))return z;const A=h.scope||"global",R=p&&Object.prototype.hasOwnProperty.call(h,"hash")?h.hash:mt(z,A);z.operations[A][z.operations[A].length-1].hash=R,!xt(h)&&h.attachments&&h.attachments.forEach(c=>{const{hash:l,...u}=c;z.attachments[l]={...u}})})}function sn(t){return t.type===ve&&t.skip!==void 0&&t.skip>0&&t.hash!==void 0}function rn(t){return[nt,it].includes(t.type)}function xt(t){return[Ht,nt,it,ct,Vt].includes(t.type)}function K(t,e,n,i,o="global"){if(!t)throw new Error("Empty action type");if(typeof t!="string")throw new Error(`Invalid action type: ${JSON.stringify(t)}`);const a={type:t,input:e,scope:o};n&&(a.attachments=n);try{i==null||i().parse(a.input)}catch(r){throw new Error(`Invalid action input: ${r}`)}return a}function oe(t,e=Dt){return(n,i,o,a)=>e(n,i,t,o,a)}const se=(t,e)=>({name:"",documentType:"",revision:{global:0,local:0},created:new Date().toISOString(),lastModified:new Date().toISOString(),attachments:{},...t,state:(e==null?void 0:e(t==null?void 0:t.state))??(t==null?void 0:t.state)??{global:{},local:{}}}),re=(t,e)=>{const n=se(t,e);return{...n,initialState:n,operations:{global:[],local:[]},clipboard:[]}},mt=(t,e="global")=>lt(G(t.state[e]||"")),an=(t,e=1e3)=>{const n=Math.random()*e;return lt(`${(t??new Date).toISOString()}${n}`)};function tt(t){return H.castImmutable(H.freeze(t,!0))}function pn(t,e){const n=[...t];let i=e||0,o=n.length>0?n[n.length-1].index:0;const a=[];for(const r of n.reverse()){if(i>0){const d=o-r.index;i-=d}if(i<0)throw new Error("Invalid operation index, missing operations");const p={ignore:i>0,operation:r},m=r.skip>0?r.skip+1:0;if(m>0&&m>i){const d=m-i;i=i+d}o=r.index,a.push(p)}return a.reverse()}function cn(t,e,n){const i=t.slice().sort((p,m)=>p.skip-m.skip).sort((p,m)=>p.index-m.index);let o=n,a=0,r=e;for(const p of i.reverse()){const m=r-p.index;if(o=o-m,o>-1)a++,r=p.index;else break}return a}function ln(t){return Object.values(t).flatMap(e=>e).sort((e,n)=>new Date(e.timestamp).getTime()-new Date(n.timestamp).getTime())}function mn(t){return Object.values(t).flatMap(e=>e).sort((e,n)=>new Date(e.operation.timestamp).getTime()-new Date(n.operation.timestamp).getTime())}function pt(t,e,n,i,o,a=Dt,r={},p){const m=oe(n,a);return kt(t,e,m,i,o,r,p)}function kt(t,e,n,i,o,a={},r){const{checkHashes:p=!0,reuseOperationResultingState:m,operationResultingStateParser:d=zt}=r||{};let h=t;const b=[],O={global:[],local:[]};if(m)for(const[c,l]of Object.entries(e)){const u=l.findLastIndex(L=>!!L.resultingState);if(u<0){b.push(...l);continue}const T=l[u];try{const L=d(T.resultingState);h={...h,state:{...h.state,[c]:L}},O[c].push(...l.slice(0,u+1)),b.push(...l.slice(u+1))}catch{b.push(...l)}}else b.push(...Object.values(e).flat());const v=re(h);v.initialState=t,v.operations=O;const z=b.reduce((c,l)=>n(c,l,i,{skip:l.skip,ignoreSkipOperations:!0,reuseHash:!p}),v);if(!p)for(const c of Object.keys(z.state))for(let l=b.length-1;l>=0;l--){const u=b[l];if(u.scope===c){if(u.hash!==mt(z,c))throw new Error(`Hash mismatch for scope ${c}`);break}}const A=Object.keys(z.operations).reduce((c,l)=>{const u=l;return{...c,[u]:[...z.operations[u].map((T,L)=>{var P;return{...T,timestamp:((P=e[u][L])==null?void 0:P.timestamp)??T.timestamp}})]}},{global:[],local:[]}),R=Object.values(A).reduce((c,l)=>{const u=l[l.length-1];return(u==null?void 0:u.timestamp)>c&&(c=u.timestamp),c},t.lastModified);return{...z,operations:A,lastModified:R}}function un(t,e){return G(t)===G(e)}function zt(t){const e=typeof t;if(e==="string")return JSON.parse(t);if(e==="object")return t;throw new Error(`Providing resulting state is of type: ${e}`)}const ae=t=>K("SET_NAME",t,void 0,Ot,void 0),pe=(t=1,e="global")=>K("UNDO",t,void 0,St,e),ce=(t=1,e="global")=>K("REDO",t,void 0,wt,e),le=(t,e,n="global")=>K("PRUNE",{start:t,end:e},void 0,bt,n),Tt=(t,e)=>K("LOAD_STATE",{state:t,operations:e},void 0,yt),me=(t="global")=>K("NOOP",{},void 0,void 0,t),fn=Object.freeze(Object.defineProperty({__proto__:null,loadState:Tt,noop:me,prune:le,redo:ce,setName:ae,undo:pe},Symbol.toStringTag,{value:"Module"}));class dn{constructor(e,n,i){at(this,"_document");at(this,"_reducer");at(this,"_signalDispatch");this._reducer=e,this._document=n,this._signalDispatch=i}dispatch(e,n){return this._document=this._reducer(this._document,e,this._signalDispatch,n),this}saveToFile(e,n,i){return Wt(this._document,e,n,i)}async loadFromFile(e){this._document=await gt(e,this._reducer)}static async stateFromFile(e,n){return await gt(e,n)}get state(){return tt(this._document.state)}get operations(){return tt(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(e){return this._document.revision[e]}get initialState(){return tt(this._document.initialState)}toDocument(){return tt(this._document)}getAttachment(e){return this._document.attachments[e]}setName(e){return this.dispatch(ae(e)),this}undo(e){return this.dispatch(pe(e)),this}redo(e){return this.dispatch(ce(e)),this}prune(e,n){return this.dispatch(le(e,n)),this}loadState(e,n){return this.dispatch(Tt(e,n)),this}}function gn(t,e){e.forEach(n=>{Object.getOwnPropertyNames(n.prototype).forEach(i=>{Object.defineProperty(t.prototype,i,Object.getOwnPropertyDescriptor(n.prototype,i)||Object.create(null))})})}exports.BaseActions=fn;exports.BaseDocument=dn;exports.applyMixins=gn;exports.baseReducer=Dt;exports.calculateSkipsLeft=cn;exports.createAction=K;exports.createDocument=re;exports.createExtendedState=se;exports.createReducer=oe;exports.createZip=jt;exports.documentHelpers=Ge;exports.getLocalFile=qe;exports.getRemoteFile=Le;exports.hashDocument=mt;exports.hashKey=an;exports.isBaseAction=xt;exports.isNoopOperation=sn;exports.isSameDocument=un;exports.isUndoRedo=rn;exports.loadFromFile=gt;exports.loadFromInput=Gt;exports.mapSkippedOperations=pn;exports.parseResultingState=zt;exports.processUndoRedo=nn;exports.readOnly=tt;exports.replayDocument=kt;exports.replayOperations=pt;exports.saveToFile=Wt;exports.saveToFileHandle=Fe;exports.sortMappedOperations=mn;exports.sortOperations=ln;exports.validateOperations=Kt;exports.zod=je;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import "./internal/object-
|
|
1
|
+
import "./internal/object-C2s2eZ08.js";
|
|
2
2
|
import "immer";
|
|
3
3
|
import "jszip";
|
|
4
4
|
import "crypto";
|
|
5
5
|
import "fs";
|
|
6
6
|
import "https";
|
|
7
7
|
import "path";
|
|
8
|
-
import { b as p, a as u, c, d as n, m as v, r as M, u as S, v as f, g as h, h as D, f as b, e as g, z as x } from "./internal/index-
|
|
8
|
+
import { b as p, a as u, c, d as n, m as v, r as M, u as S, v as f, g as h, h as D, f as b, e as g, z as x } from "./internal/index-DOpbr_uw.js";
|
|
9
9
|
import "zod";
|
|
10
10
|
export {
|
|
11
11
|
p as Document,
|
package/dist/node/es/document.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { B as c, h as n, g as d, E as u, F as x, G as f } from "./internal/object-
|
|
2
|
-
import { i as B } from "./internal/index-
|
|
1
|
+
import { B as c, h as n, g as d, E as u, F as x, G as f } from "./internal/object-C2s2eZ08.js";
|
|
2
|
+
import { i as B } from "./internal/index-BIrQOTP_.js";
|
|
3
3
|
import "immer";
|
|
4
4
|
import "zod";
|
|
5
5
|
import "jszip";
|
package/dist/node/es/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { D as o } from "./internal/index-
|
|
2
|
-
import { D as t } from "./internal/index-
|
|
3
|
-
import "./internal/object-
|
|
1
|
+
import { D as o } from "./internal/index-BIrQOTP_.js";
|
|
2
|
+
import { D as t } from "./internal/index-DOpbr_uw.js";
|
|
3
|
+
import "./internal/object-C2s2eZ08.js";
|
|
4
4
|
import "immer";
|
|
5
5
|
import "zod";
|
|
6
6
|
import "jszip";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { j as e, f as a, b as s, a as t, c as o, k as r, m as i, n, o as l, p as c, q as p, i as d, r as u, t as m, u as O, l as y, e as S, v as b, w as g, x as D, y as F, z as _, s as f, d as v, A as R, C as h, D as j, B as x, h as z, g as A, E as B, F as M, G as T } from "./object-
|
|
1
|
+
import { j as e, f as a, b as s, a as t, c as o, k as r, m as i, n, o as l, p as c, q as p, i as d, r as u, t as m, u as O, l as y, e as S, v as b, w as g, x as D, y as F, z as _, s as f, d as v, A as R, C as h, D as j, B as x, h as z, g as A, E as B, F as M, G as T } from "./object-C2s2eZ08.js";
|
|
2
2
|
const k = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
3
3
|
__proto__: null,
|
|
4
4
|
calculateSkipsLeft: e,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var Rt = Object.defineProperty;
|
|
2
2
|
var xt = (t, e, r) => e in t ? Rt(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
|
|
3
3
|
var Ee = (t, e, r) => (xt(t, typeof e != "symbol" ? e + "" : e, r), r);
|
|
4
|
-
import { c as At, i as Mt, a as Dt, b as Nt, s as Lt, d as Pt, l as Ct, e as jt, f as a, B as c, g as yt, h as wt } from "./object-
|
|
4
|
+
import { c as At, i as Mt, a as Dt, b as Nt, s as Lt, d as Pt, l as Ct, e as jt, f as a, B as c, g as yt, h as wt } from "./object-C2s2eZ08.js";
|
|
5
5
|
import "immer";
|
|
6
6
|
import "jszip";
|
|
7
7
|
import "crypto";
|
|
@@ -1087,34 +1087,40 @@ function Be(t, e) {
|
|
|
1087
1087
|
lastModified: (/* @__PURE__ */ new Date()).toISOString()
|
|
1088
1088
|
};
|
|
1089
1089
|
}
|
|
1090
|
-
function Ke(t, e, n = 0) {
|
|
1090
|
+
function Ke(t, e, n = 0, i = !1) {
|
|
1091
1091
|
if ([tt, et, ct].includes(e.type))
|
|
1092
1092
|
return t;
|
|
1093
|
-
const { scope:
|
|
1094
|
-
let
|
|
1093
|
+
const { scope: o } = e, a = t.operations[o].slice(), r = a.at(-1);
|
|
1094
|
+
let p = ((r == null ? void 0 : r.index) ?? -1) + 1;
|
|
1095
1095
|
if ("index" in e) {
|
|
1096
|
-
if (e.index - n >
|
|
1096
|
+
if (e.index - n > p)
|
|
1097
1097
|
throw new Error(
|
|
1098
|
-
`Missing operations: expected ${
|
|
1098
|
+
`Missing operations: expected ${p} with skip 0 or equivalent, got index ${e.index} with skip ${n}`
|
|
1099
1099
|
);
|
|
1100
|
-
|
|
1100
|
+
p = e.index;
|
|
1101
1101
|
}
|
|
1102
|
-
|
|
1102
|
+
const m = {
|
|
1103
1103
|
...e,
|
|
1104
|
-
index:
|
|
1104
|
+
index: p,
|
|
1105
1105
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1106
1106
|
hash: "",
|
|
1107
|
-
scope:
|
|
1107
|
+
scope: o,
|
|
1108
1108
|
skip: n,
|
|
1109
1109
|
error: void 0
|
|
1110
|
-
}
|
|
1110
|
+
};
|
|
1111
|
+
return i && (m.resultingState = t.state[o]), a.push(m), {
|
|
1111
1112
|
...t,
|
|
1112
|
-
operations: { ...t.operations, [
|
|
1113
|
+
operations: { ...t.operations, [o]: a }
|
|
1113
1114
|
};
|
|
1114
1115
|
}
|
|
1115
|
-
function We(t, e, n = 0) {
|
|
1116
|
-
let
|
|
1117
|
-
|
|
1116
|
+
function We(t, e, n = 0, i = !1) {
|
|
1117
|
+
let o = Ke(
|
|
1118
|
+
t,
|
|
1119
|
+
e,
|
|
1120
|
+
n,
|
|
1121
|
+
i
|
|
1122
|
+
);
|
|
1123
|
+
return o = Be(o, e), o;
|
|
1118
1124
|
}
|
|
1119
1125
|
function Ge(t, e, n) {
|
|
1120
1126
|
switch (Pt().parse(e), e.type) {
|
|
@@ -1195,7 +1201,12 @@ function Yt(t, e, n, i, o = {}) {
|
|
|
1195
1201
|
} = o, h = { ...e }, b = a || 0;
|
|
1196
1202
|
let O = { ...t };
|
|
1197
1203
|
const v = !r && (b > 0 || "index" in h && h.skip > 0);
|
|
1198
|
-
return kt(h) && (O = Ge(O, h, n)), O = We(
|
|
1204
|
+
return kt(h) && (O = Ge(O, h, n)), O = We(
|
|
1205
|
+
O,
|
|
1206
|
+
h,
|
|
1207
|
+
b,
|
|
1208
|
+
m
|
|
1209
|
+
), v && (O = Ze(
|
|
1199
1210
|
O,
|
|
1200
1211
|
h,
|
|
1201
1212
|
n,
|