document-model 1.0.5 → 1.0.6
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/object.d.ts +4 -0
- 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/{node/internal/index-6317539b.js → browser/internal/index-05f6fe71.js} +1 -1
- package/dist/{node/internal/index-bb0a856f.js → browser/internal/index-336e6f47.js} +1 -1
- package/dist/browser/internal/{index-32915b74.js → index-91e3abf2.js} +1 -1
- package/dist/browser/internal/{index-32683024.js → index-d577364b.js} +1 -1
- package/dist/browser/internal/{object-d689b6ce.js → object-41731a51.js} +1 -1
- package/dist/browser/internal/{object-70e73c9d.js → object-e8af0c3a.js} +6 -0
- package/dist/node/document/object.d.ts +4 -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/node/internal/{index-027f73ec.js → index-574ece31.js} +1 -1
- package/dist/{browser/internal/index-8e2ab717.js → node/internal/index-6ee6330b.js} +1 -1
- package/dist/{browser/internal/index-66e00945.js → node/internal/index-af4b7a66.js} +1 -1
- package/dist/node/internal/{index-551f2c89.js → index-f3fdeced.js} +1 -1
- package/dist/node/internal/{object-8edc0f76.js → object-19968a54.js} +17 -11
- package/dist/node/internal/{object-2bb87214.js → object-9fcc9b3e.js} +1 -1
- package/package.json +1 -1
|
@@ -72,6 +72,10 @@ export declare abstract class BaseDocument<T, A extends Action> {
|
|
|
72
72
|
* Gets the initial state of the document.
|
|
73
73
|
*/
|
|
74
74
|
get initialState(): ExtendedState<T>;
|
|
75
|
+
/**
|
|
76
|
+
* Returns the current document as an object
|
|
77
|
+
*/
|
|
78
|
+
toDocument(): Document<T, A>;
|
|
75
79
|
/**
|
|
76
80
|
* Gets the attachment associated with the given key.
|
|
77
81
|
* @param attachment - The key of the attachment to retrieve.
|
|
@@ -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-41731a51.js");require("json-stringify-deterministic");require("immer");require("jszip");const e=require("./internal/index-91e3abf2.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.z=e.zod;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import "./internal/object-
|
|
1
|
+
import "./internal/object-e8af0c3a.js";
|
|
2
2
|
import "json-stringify-deterministic";
|
|
3
3
|
import "immer";
|
|
4
4
|
import "jszip";
|
|
5
|
-
import { b as i, a as u, c, d, m as p, r as l, u as n, z as D } from "./internal/index-
|
|
5
|
+
import { b as i, a as u, c, d, m as p, r as l, u as n, z as D } from "./internal/index-d577364b.js";
|
|
6
6
|
import "zod";
|
|
7
7
|
export {
|
|
8
8
|
i as Document,
|
|
@@ -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-41731a51.js"),r=require("./internal/index-336e6f47.js");require("json-stringify-deterministic");require("immer");require("zod");require("jszip");exports.BaseDocument=e.BaseDocument;exports.actions=e.BaseActions;exports.applyMixins=e.applyMixins;exports.baseReducer=e.baseReducer;exports.z=e.zod;exports.utils=r.index;
|
package/dist/browser/document.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { B as t, h as e, g as m, p as c, z as n } from "./internal/object-
|
|
2
|
-
import { i as x } from "./internal/index-
|
|
1
|
+
import { B as t, h as e, g as m, p as c, z as n } from "./internal/object-e8af0c3a.js";
|
|
2
|
+
import { i as x } from "./internal/index-05f6fe71.js";
|
|
3
3
|
import "json-stringify-deterministic";
|
|
4
4
|
import "immer";
|
|
5
5
|
import "zod";
|
package/dist/browser/index.cjs
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-336e6f47.js"),o=require("./internal/index-91e3abf2.js");require("./internal/object-41731a51.js");require("json-stringify-deterministic");require("immer");require("zod");require("jszip");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;
|
package/dist/browser/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-05f6fe71.js";
|
|
2
|
+
import { D as t } from "./internal/index-d577364b.js";
|
|
3
|
+
import "./internal/object-e8af0c3a.js";
|
|
4
4
|
import "json-stringify-deterministic";
|
|
5
5
|
import "immer";
|
|
6
6
|
import "zod";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { f as e, b as a, a as s, c as t, j as o, k as c, m as i, n as l, o as n, i as r, l as d, e as u, s as m, d as p, B as b, h as _, g, p as F, z as f } from "./object-
|
|
1
|
+
import { f as e, b as a, a as s, c as t, j as o, k as c, m as i, n as l, o as n, i as r, l as d, e as u, s as m, d as p, B as b, h as _, g, p as F, z as f } from "./object-e8af0c3a.js";
|
|
2
2
|
const y = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
3
3
|
__proto__: null,
|
|
4
4
|
createAction: e,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=require("./object-
|
|
1
|
+
"use strict";const e=require("./object-41731a51.js"),t=Object.freeze(Object.defineProperty({__proto__:null,createAction:e.createAction,createDocument:e.createDocument,createExtendedState:e.createExtendedState,createReducer:e.createReducer,createZip:e.createZip,getLocalFile:e.getLocalFile,getRemoteFile:e.getRemoteFile,hashDocument:e.hashDocument,hashKey:e.hashKey,isBaseAction:e.isBaseAction,loadFromFile:e.loadFromFile,loadFromInput:e.loadFromInput,saveToFile:e.saveToFile,saveToFileHandle:e.saveToFileHandle},Symbol.toStringTag,{value:"Module"})),o=Object.freeze(Object.defineProperty({__proto__:null,BaseDocument:e.BaseDocument,actions:e.BaseActions,applyMixins:e.applyMixins,baseReducer:e.baseReducer,utils:t,z:e.zod},Symbol.toStringTag,{value:"Module"}));exports.Document=o;exports.index=t;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var ct=Object.defineProperty;var lt=(t,e,o)=>e in t?ct(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o;var de=(t,e,o)=>(lt(t,typeof e!="symbol"?e+"":e,o),o);const s=require("./object-
|
|
1
|
+
"use strict";var ct=Object.defineProperty;var lt=(t,e,o)=>e in t?ct(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o;var de=(t,e,o)=>(lt(t,typeof e!="symbol"?e+"":e,o),o);const s=require("./object-41731a51.js");require("json-stringify-deterministic");require("immer");require("jszip");const r=require("zod"),dt=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"})),_={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:[]},{name:"SetModelId",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetModelExtension",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetModelDescription",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetAuthorName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetAuthorWebsite",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]}],id:"",description:""},{name:"versioning",operations:[{name:"AddChangeLogItem",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"UpdateChangeLogItem",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"DeleteChangeLogItem",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"ReorderChangeLogItems",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"ReleaseNewVersion",schema:null,id:"",description:"",template:"",reducer:"",examples:[],errors:[]}],id:"",description:""},{name:"module",operations:[{name:"AddModule",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetModuleName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetModuleDescription",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"DeleteModule",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"ReorderModules",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]}],id:"",description:""},{name:"operation-error",operations:[{name:"AddOperationError",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetOperationErrorCode",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetOperationErrorName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetOperationErrorDescription",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetOperationErrorTemplate",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"DeleteOperationError",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"ReorderOperationErrors",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]}],id:"",description:""},{name:"operation-example",operations:[{name:"AddOperationExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"UpdateOperationExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"DeleteOperationExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"ReorderOperationExamples",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]}],id:"",description:""},{name:"operation",operations:[{name:"AddOperation",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetOperationName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetOperationSchema",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetOperationDescription",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetOperationTemplate",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetOperationReducer",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"MoveOperation",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"DeleteOperation",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"ReorderModuleOperations",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]}],id:"",description:""},{name:"state",operations:[{name:"SetStateSchema",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetInitialState",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"AddStateExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"UpdateStateExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"DeleteStateExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"ReorderStateExamples",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]}],id:"",description:""}],state:{schema:"",initialValue:`{
|
|
2
2
|
"id": "",
|
|
3
3
|
"name": "",
|
|
4
4
|
"extension": "",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var pt = Object.defineProperty;
|
|
2
2
|
var lt = (t, e, i) => e in t ? pt(t, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : t[e] = i;
|
|
3
3
|
var pe = (t, e, i) => (lt(t, typeof e != "symbol" ? e + "" : e, i), i);
|
|
4
|
-
import { c as dt, i as ct, a as ut, b as mt, s as Et, d as ht, l as Ot, e as St, f as s, B as l, g as gt, h as ft } from "./object-
|
|
4
|
+
import { c as dt, i as ct, a as ut, b as mt, s as Et, d as ht, l as Ot, e as St, f as s, B as l, g as gt, h as ft } from "./object-e8af0c3a.js";
|
|
5
5
|
import "json-stringify-deterministic";
|
|
6
6
|
import "immer";
|
|
7
7
|
import "jszip";
|
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @author Feross Aboukhadijeh <https://feross.org>
|
|
5
5
|
* @license MIT
|
|
6
|
-
*/(function(n){var a=J,s=ct,c=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;n.Buffer=o,n.SlowBuffer=er,n.INSPECT_MAX_BYTES=50;var f=2147483647;n.kMaxLength=f,o.TYPED_ARRAY_SUPPORT=m(),!o.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function m(){try{var i=new Uint8Array(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,Uint8Array.prototype),Object.setPrototypeOf(i,t),i.foo()===42}catch{return!1}}Object.defineProperty(o.prototype,"parent",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.buffer}}),Object.defineProperty(o.prototype,"offset",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.byteOffset}});function u(i){if(i>f)throw new RangeError('The value "'+i+'" is invalid for option "size"');var t=new Uint8Array(i);return Object.setPrototypeOf(t,o.prototype),t}function o(i,t,r){if(typeof i=="number"){if(typeof t=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return F(i)}return x(i,t,r)}o.poolSize=8192;function x(i,t,r){if(typeof i=="string")return U(i,t);if(ArrayBuffer.isView(i))return O(i);if(i==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof i);if(I(i,ArrayBuffer)||i&&I(i.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(I(i,SharedArrayBuffer)||i&&I(i.buffer,SharedArrayBuffer)))return N(i,t,r);if(typeof i=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');var e=i.valueOf&&i.valueOf();if(e!=null&&e!==i)return o.from(e,t,r);var p=ir(i);if(p)return p;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof i[Symbol.toPrimitive]=="function")return o.from(i[Symbol.toPrimitive]("string"),t,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof i)}o.from=function(i,t,r){return x(i,t,r)},Object.setPrototypeOf(o.prototype,Uint8Array.prototype),Object.setPrototypeOf(o,Uint8Array);function y(i){if(typeof i!="number")throw new TypeError('"size" argument must be of type number');if(i<0)throw new RangeError('The value "'+i+'" is invalid for option "size"')}function v(i,t,r){return y(i),i<=0?u(i):t!==void 0?typeof r=="string"?u(i).fill(t,r):u(i).fill(t):u(i)}o.alloc=function(i,t,r){return v(i,t,r)};function F(i){return y(i),u(i<0?0:K(i)|0)}o.allocUnsafe=function(i){return F(i)},o.allocUnsafeSlow=function(i){return F(i)};function U(i,t){if((typeof t!="string"||t==="")&&(t="utf8"),!o.isEncoding(t))throw new TypeError("Unknown encoding: "+t);var r=ht(i,t)|0,e=u(r),p=e.write(i,t);return p!==r&&(e=e.slice(0,p)),e}function B(i){for(var t=i.length<0?0:K(i.length)|0,r=u(t),e=0;e<t;e+=1)r[e]=i[e]&255;return r}function O(i){if(I(i,Uint8Array)){var t=new Uint8Array(i);return N(t.buffer,t.byteOffset,t.byteLength)}return B(i)}function N(i,t,r){if(t<0||i.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(i.byteLength<t+(r||0))throw new RangeError('"length" is outside of buffer bounds');var e;return t===void 0&&r===void 0?e=new Uint8Array(i):r===void 0?e=new Uint8Array(i,t):e=new Uint8Array(i,t,r),Object.setPrototypeOf(e,o.prototype),e}function ir(i){if(o.isBuffer(i)){var t=K(i.length)|0,r=u(t);return r.length===0||i.copy(r,0,0,t),r}if(i.length!==void 0)return typeof i.length!="number"||X(i.length)?u(0):B(i);if(i.type==="Buffer"&&Array.isArray(i.data))return B(i.data)}function K(i){if(i>=f)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+f.toString(16)+" bytes");return i|0}function er(i){return+i!=i&&(i=0),o.alloc(+i)}o.isBuffer=function(t){return t!=null&&t._isBuffer===!0&&t!==o.prototype},o.compare=function(t,r){if(I(t,Uint8Array)&&(t=o.from(t,t.offset,t.byteLength)),I(r,Uint8Array)&&(r=o.from(r,r.offset,r.byteLength)),!o.isBuffer(t)||!o.isBuffer(r))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===r)return 0;for(var e=t.length,p=r.length,l=0,h=Math.min(e,p);l<h;++l)if(t[l]!==r[l]){e=t[l],p=r[l];break}return e<p?-1:p<e?1:0},o.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},o.concat=function(t,r){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(t.length===0)return o.alloc(0);var e;if(r===void 0)for(r=0,e=0;e<t.length;++e)r+=t[e].length;var p=o.allocUnsafe(r),l=0;for(e=0;e<t.length;++e){var h=t[e];if(I(h,Uint8Array))l+h.length>p.length?o.from(h).copy(p,l):Uint8Array.prototype.set.call(p,h,l);else if(o.isBuffer(h))h.copy(p,l);else throw new TypeError('"list" argument must be an Array of Buffers');l+=h.length}return p};function ht(i,t){if(o.isBuffer(i))return i.length;if(ArrayBuffer.isView(i)||I(i,ArrayBuffer))return i.byteLength;if(typeof i!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof i);var r=i.length,e=arguments.length>2&&arguments[2]===!0;if(!e&&r===0)return 0;for(var p=!1;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return Y(i).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return r*2;case"hex":return r>>>1;case"base64":return Et(i).length;default:if(p)return e?-1:Y(i).length;t=(""+t).toLowerCase(),p=!0}}o.byteLength=ht;function nr(i,t,r){var e=!1;if((t===void 0||t<0)&&(t=0),t>this.length||((r===void 0||r>this.length)&&(r=this.length),r<=0)||(r>>>=0,t>>>=0,r<=t))return"";for(i||(i="utf8");;)switch(i){case"hex":return mr(this,t,r);case"utf8":case"utf-8":return dt(this,t,r);case"ascii":return fr(this,t,r);case"latin1":case"binary":return hr(this,t,r);case"base64":return lr(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return xr(this,t,r);default:if(e)throw new TypeError("Unknown encoding: "+i);i=(i+"").toLowerCase(),e=!0}}o.prototype._isBuffer=!0;function k(i,t,r){var e=i[t];i[t]=i[r],i[r]=e}o.prototype.swap16=function(){var t=this.length;if(t%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var r=0;r<t;r+=2)k(this,r,r+1);return this},o.prototype.swap32=function(){var t=this.length;if(t%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var r=0;r<t;r+=4)k(this,r,r+3),k(this,r+1,r+2);return this},o.prototype.swap64=function(){var t=this.length;if(t%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var r=0;r<t;r+=8)k(this,r,r+7),k(this,r+1,r+6),k(this,r+2,r+5),k(this,r+3,r+4);return this},o.prototype.toString=function(){var t=this.length;return t===0?"":arguments.length===0?dt(this,0,t):nr.apply(this,arguments)},o.prototype.toLocaleString=o.prototype.toString,o.prototype.equals=function(t){if(!o.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t?!0:o.compare(this,t)===0},o.prototype.inspect=function(){var t="",r=n.INSPECT_MAX_BYTES;return t=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(t+=" ... "),"<Buffer "+t+">"},c&&(o.prototype[c]=o.prototype.inspect),o.prototype.compare=function(t,r,e,p,l){if(I(t,Uint8Array)&&(t=o.from(t,t.offset,t.byteLength)),!o.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(r===void 0&&(r=0),e===void 0&&(e=t?t.length:0),p===void 0&&(p=0),l===void 0&&(l=this.length),r<0||e>t.length||p<0||l>this.length)throw new RangeError("out of range index");if(p>=l&&r>=e)return 0;if(p>=l)return-1;if(r>=e)return 1;if(r>>>=0,e>>>=0,p>>>=0,l>>>=0,this===t)return 0;for(var h=l-p,w=e-r,g=Math.min(h,w),E=this.slice(p,l),A=t.slice(r,e),b=0;b<g;++b)if(E[b]!==A[b]){h=E[b],w=A[b];break}return h<w?-1:w<h?1:0};function mt(i,t,r,e,p){if(i.length===0)return-1;if(typeof r=="string"?(e=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,X(r)&&(r=p?0:i.length-1),r<0&&(r=i.length+r),r>=i.length){if(p)return-1;r=i.length-1}else if(r<0)if(p)r=0;else return-1;if(typeof t=="string"&&(t=o.from(t,e)),o.isBuffer(t))return t.length===0?-1:xt(i,t,r,e,p);if(typeof t=="number")return t=t&255,typeof Uint8Array.prototype.indexOf=="function"?p?Uint8Array.prototype.indexOf.call(i,t,r):Uint8Array.prototype.lastIndexOf.call(i,t,r):xt(i,[t],r,e,p);throw new TypeError("val must be string, number or Buffer")}function xt(i,t,r,e,p){var l=1,h=i.length,w=t.length;if(e!==void 0&&(e=String(e).toLowerCase(),e==="ucs2"||e==="ucs-2"||e==="utf16le"||e==="utf-16le")){if(i.length<2||t.length<2)return-1;l=2,h/=2,w/=2,r/=2}function g(bt,Ft){return l===1?bt[Ft]:bt.readUInt16BE(Ft*l)}var E;if(p){var A=-1;for(E=r;E<h;E++)if(g(i,E)===g(t,A===-1?0:E-A)){if(A===-1&&(A=E),E-A+1===w)return A*l}else A!==-1&&(E-=E-A),A=-1}else for(r+w>h&&(r=h-w),E=r;E>=0;E--){for(var b=!0,L=0;L<w;L++)if(g(i,E+L)!==g(t,L)){b=!1;break}if(b)return E}return-1}o.prototype.includes=function(t,r,e){return this.indexOf(t,r,e)!==-1},o.prototype.indexOf=function(t,r,e){return mt(this,t,r,e,!0)},o.prototype.lastIndexOf=function(t,r,e){return mt(this,t,r,e,!1)};function ar(i,t,r,e){r=Number(r)||0;var p=i.length-r;e?(e=Number(e),e>p&&(e=p)):e=p;var l=t.length;e>l/2&&(e=l/2);for(var h=0;h<e;++h){var w=parseInt(t.substr(h*2,2),16);if(X(w))return h;i[r+h]=w}return h}function or(i,t,r,e){return C(Y(t,i.length-r),i,r,e)}function pr(i,t,r,e){return C(yr(t),i,r,e)}function sr(i,t,r,e){return C(Et(t),i,r,e)}function cr(i,t,r,e){return C(gr(t,i.length-r),i,r,e)}o.prototype.write=function(t,r,e,p){if(r===void 0)p="utf8",e=this.length,r=0;else if(e===void 0&&typeof r=="string")p=r,e=this.length,r=0;else if(isFinite(r))r=r>>>0,isFinite(e)?(e=e>>>0,p===void 0&&(p="utf8")):(p=e,e=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");var l=this.length-r;if((e===void 0||e>l)&&(e=l),t.length>0&&(e<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");p||(p="utf8");for(var h=!1;;)switch(p){case"hex":return ar(this,t,r,e);case"utf8":case"utf-8":return or(this,t,r,e);case"ascii":case"latin1":case"binary":return pr(this,t,r,e);case"base64":return sr(this,t,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return cr(this,t,r,e);default:if(h)throw new TypeError("Unknown encoding: "+p);p=(""+p).toLowerCase(),h=!0}},o.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function lr(i,t,r){return t===0&&r===i.length?a.fromByteArray(i):a.fromByteArray(i.slice(t,r))}function dt(i,t,r){r=Math.min(i.length,r);for(var e=[],p=t;p<r;){var l=i[p],h=null,w=l>239?4:l>223?3:l>191?2:1;if(p+w<=r){var g,E,A,b;switch(w){case 1:l<128&&(h=l);break;case 2:g=i[p+1],(g&192)===128&&(b=(l&31)<<6|g&63,b>127&&(h=b));break;case 3:g=i[p+1],E=i[p+2],(g&192)===128&&(E&192)===128&&(b=(l&15)<<12|(g&63)<<6|E&63,b>2047&&(b<55296||b>57343)&&(h=b));break;case 4:g=i[p+1],E=i[p+2],A=i[p+3],(g&192)===128&&(E&192)===128&&(A&192)===128&&(b=(l&15)<<18|(g&63)<<12|(E&63)<<6|A&63,b>65535&&b<1114112&&(h=b))}}h===null?(h=65533,w=1):h>65535&&(h-=65536,e.push(h>>>10&1023|55296),h=56320|h&1023),e.push(h),p+=w}return ur(e)}var wt=4096;function ur(i){var t=i.length;if(t<=wt)return String.fromCharCode.apply(String,i);for(var r="",e=0;e<t;)r+=String.fromCharCode.apply(String,i.slice(e,e+=wt));return r}function fr(i,t,r){var e="";r=Math.min(i.length,r);for(var p=t;p<r;++p)e+=String.fromCharCode(i[p]&127);return e}function hr(i,t,r){var e="";r=Math.min(i.length,r);for(var p=t;p<r;++p)e+=String.fromCharCode(i[p]);return e}function mr(i,t,r){var e=i.length;(!t||t<0)&&(t=0),(!r||r<0||r>e)&&(r=e);for(var p="",l=t;l<r;++l)p+=vr[i[l]];return p}function xr(i,t,r){for(var e=i.slice(t,r),p="",l=0;l<e.length-1;l+=2)p+=String.fromCharCode(e[l]+e[l+1]*256);return p}o.prototype.slice=function(t,r){var e=this.length;t=~~t,r=r===void 0?e:~~r,t<0?(t+=e,t<0&&(t=0)):t>e&&(t=e),r<0?(r+=e,r<0&&(r=0)):r>e&&(r=e),r<t&&(r=t);var p=this.subarray(t,r);return Object.setPrototypeOf(p,o.prototype),p};function _(i,t,r){if(i%1!==0||i<0)throw new RangeError("offset is not uint");if(i+t>r)throw new RangeError("Trying to access beyond buffer length")}o.prototype.readUintLE=o.prototype.readUIntLE=function(t,r,e){t=t>>>0,r=r>>>0,e||_(t,r,this.length);for(var p=this[t],l=1,h=0;++h<r&&(l*=256);)p+=this[t+h]*l;return p},o.prototype.readUintBE=o.prototype.readUIntBE=function(t,r,e){t=t>>>0,r=r>>>0,e||_(t,r,this.length);for(var p=this[t+--r],l=1;r>0&&(l*=256);)p+=this[t+--r]*l;return p},o.prototype.readUint8=o.prototype.readUInt8=function(t,r){return t=t>>>0,r||_(t,1,this.length),this[t]},o.prototype.readUint16LE=o.prototype.readUInt16LE=function(t,r){return t=t>>>0,r||_(t,2,this.length),this[t]|this[t+1]<<8},o.prototype.readUint16BE=o.prototype.readUInt16BE=function(t,r){return t=t>>>0,r||_(t,2,this.length),this[t]<<8|this[t+1]},o.prototype.readUint32LE=o.prototype.readUInt32LE=function(t,r){return t=t>>>0,r||_(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+this[t+3]*16777216},o.prototype.readUint32BE=o.prototype.readUInt32BE=function(t,r){return t=t>>>0,r||_(t,4,this.length),this[t]*16777216+(this[t+1]<<16|this[t+2]<<8|this[t+3])},o.prototype.readIntLE=function(t,r,e){t=t>>>0,r=r>>>0,e||_(t,r,this.length);for(var p=this[t],l=1,h=0;++h<r&&(l*=256);)p+=this[t+h]*l;return l*=128,p>=l&&(p-=Math.pow(2,8*r)),p},o.prototype.readIntBE=function(t,r,e){t=t>>>0,r=r>>>0,e||_(t,r,this.length);for(var p=r,l=1,h=this[t+--p];p>0&&(l*=256);)h+=this[t+--p]*l;return l*=128,h>=l&&(h-=Math.pow(2,8*r)),h},o.prototype.readInt8=function(t,r){return t=t>>>0,r||_(t,1,this.length),this[t]&128?(255-this[t]+1)*-1:this[t]},o.prototype.readInt16LE=function(t,r){t=t>>>0,r||_(t,2,this.length);var e=this[t]|this[t+1]<<8;return e&32768?e|4294901760:e},o.prototype.readInt16BE=function(t,r){t=t>>>0,r||_(t,2,this.length);var e=this[t+1]|this[t]<<8;return e&32768?e|4294901760:e},o.prototype.readInt32LE=function(t,r){return t=t>>>0,r||_(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},o.prototype.readInt32BE=function(t,r){return t=t>>>0,r||_(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},o.prototype.readFloatLE=function(t,r){return t=t>>>0,r||_(t,4,this.length),s.read(this,t,!0,23,4)},o.prototype.readFloatBE=function(t,r){return t=t>>>0,r||_(t,4,this.length),s.read(this,t,!1,23,4)},o.prototype.readDoubleLE=function(t,r){return t=t>>>0,r||_(t,8,this.length),s.read(this,t,!0,52,8)},o.prototype.readDoubleBE=function(t,r){return t=t>>>0,r||_(t,8,this.length),s.read(this,t,!1,52,8)};function S(i,t,r,e,p,l){if(!o.isBuffer(i))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>p||t<l)throw new RangeError('"value" argument is out of bounds');if(r+e>i.length)throw new RangeError("Index out of range")}o.prototype.writeUintLE=o.prototype.writeUIntLE=function(t,r,e,p){if(t=+t,r=r>>>0,e=e>>>0,!p){var l=Math.pow(2,8*e)-1;S(this,t,r,e,l,0)}var h=1,w=0;for(this[r]=t&255;++w<e&&(h*=256);)this[r+w]=t/h&255;return r+e},o.prototype.writeUintBE=o.prototype.writeUIntBE=function(t,r,e,p){if(t=+t,r=r>>>0,e=e>>>0,!p){var l=Math.pow(2,8*e)-1;S(this,t,r,e,l,0)}var h=e-1,w=1;for(this[r+h]=t&255;--h>=0&&(w*=256);)this[r+h]=t/w&255;return r+e},o.prototype.writeUint8=o.prototype.writeUInt8=function(t,r,e){return t=+t,r=r>>>0,e||S(this,t,r,1,255,0),this[r]=t&255,r+1},o.prototype.writeUint16LE=o.prototype.writeUInt16LE=function(t,r,e){return t=+t,r=r>>>0,e||S(this,t,r,2,65535,0),this[r]=t&255,this[r+1]=t>>>8,r+2},o.prototype.writeUint16BE=o.prototype.writeUInt16BE=function(t,r,e){return t=+t,r=r>>>0,e||S(this,t,r,2,65535,0),this[r]=t>>>8,this[r+1]=t&255,r+2},o.prototype.writeUint32LE=o.prototype.writeUInt32LE=function(t,r,e){return t=+t,r=r>>>0,e||S(this,t,r,4,4294967295,0),this[r+3]=t>>>24,this[r+2]=t>>>16,this[r+1]=t>>>8,this[r]=t&255,r+4},o.prototype.writeUint32BE=o.prototype.writeUInt32BE=function(t,r,e){return t=+t,r=r>>>0,e||S(this,t,r,4,4294967295,0),this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=t&255,r+4},o.prototype.writeIntLE=function(t,r,e,p){if(t=+t,r=r>>>0,!p){var l=Math.pow(2,8*e-1);S(this,t,r,e,l-1,-l)}var h=0,w=1,g=0;for(this[r]=t&255;++h<e&&(w*=256);)t<0&&g===0&&this[r+h-1]!==0&&(g=1),this[r+h]=(t/w>>0)-g&255;return r+e},o.prototype.writeIntBE=function(t,r,e,p){if(t=+t,r=r>>>0,!p){var l=Math.pow(2,8*e-1);S(this,t,r,e,l-1,-l)}var h=e-1,w=1,g=0;for(this[r+h]=t&255;--h>=0&&(w*=256);)t<0&&g===0&&this[r+h+1]!==0&&(g=1),this[r+h]=(t/w>>0)-g&255;return r+e},o.prototype.writeInt8=function(t,r,e){return t=+t,r=r>>>0,e||S(this,t,r,1,127,-128),t<0&&(t=255+t+1),this[r]=t&255,r+1},o.prototype.writeInt16LE=function(t,r,e){return t=+t,r=r>>>0,e||S(this,t,r,2,32767,-32768),this[r]=t&255,this[r+1]=t>>>8,r+2},o.prototype.writeInt16BE=function(t,r,e){return t=+t,r=r>>>0,e||S(this,t,r,2,32767,-32768),this[r]=t>>>8,this[r+1]=t&255,r+2},o.prototype.writeInt32LE=function(t,r,e){return t=+t,r=r>>>0,e||S(this,t,r,4,2147483647,-2147483648),this[r]=t&255,this[r+1]=t>>>8,this[r+2]=t>>>16,this[r+3]=t>>>24,r+4},o.prototype.writeInt32BE=function(t,r,e){return t=+t,r=r>>>0,e||S(this,t,r,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=t&255,r+4};function yt(i,t,r,e,p,l){if(r+e>i.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function gt(i,t,r,e,p){return t=+t,r=r>>>0,p||yt(i,t,r,4),s.write(i,t,r,e,23,4),r+4}o.prototype.writeFloatLE=function(t,r,e){return gt(this,t,r,!0,e)},o.prototype.writeFloatBE=function(t,r,e){return gt(this,t,r,!1,e)};function vt(i,t,r,e,p){return t=+t,r=r>>>0,p||yt(i,t,r,8),s.write(i,t,r,e,52,8),r+8}o.prototype.writeDoubleLE=function(t,r,e){return vt(this,t,r,!0,e)},o.prototype.writeDoubleBE=function(t,r,e){return vt(this,t,r,!1,e)},o.prototype.copy=function(t,r,e,p){if(!o.isBuffer(t))throw new TypeError("argument should be a Buffer");if(e||(e=0),!p&&p!==0&&(p=this.length),r>=t.length&&(r=t.length),r||(r=0),p>0&&p<e&&(p=e),p===e||t.length===0||this.length===0)return 0;if(r<0)throw new RangeError("targetStart out of bounds");if(e<0||e>=this.length)throw new RangeError("Index out of range");if(p<0)throw new RangeError("sourceEnd out of bounds");p>this.length&&(p=this.length),t.length-r<p-e&&(p=t.length-r+e);var l=p-e;return this===t&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(r,e,p):Uint8Array.prototype.set.call(t,this.subarray(e,p),r),l},o.prototype.fill=function(t,r,e,p){if(typeof t=="string"){if(typeof r=="string"?(p=r,r=0,e=this.length):typeof e=="string"&&(p=e,e=this.length),p!==void 0&&typeof p!="string")throw new TypeError("encoding must be a string");if(typeof p=="string"&&!o.isEncoding(p))throw new TypeError("Unknown encoding: "+p);if(t.length===1){var l=t.charCodeAt(0);(p==="utf8"&&l<128||p==="latin1")&&(t=l)}}else typeof t=="number"?t=t&255:typeof t=="boolean"&&(t=Number(t));if(r<0||this.length<r||this.length<e)throw new RangeError("Out of range index");if(e<=r)return this;r=r>>>0,e=e===void 0?this.length:e>>>0,t||(t=0);var h;if(typeof t=="number")for(h=r;h<e;++h)this[h]=t;else{var w=o.isBuffer(t)?t:o.from(t,p),g=w.length;if(g===0)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(h=0;h<e-r;++h)this[h+r]=w[h%g]}return this};var dr=/[^+/0-9A-Za-z-_]/g;function wr(i){if(i=i.split("=")[0],i=i.trim().replace(dr,""),i.length<2)return"";for(;i.length%4!==0;)i=i+"=";return i}function Y(i,t){t=t||1/0;for(var r,e=i.length,p=null,l=[],h=0;h<e;++h){if(r=i.charCodeAt(h),r>55295&&r<57344){if(!p){if(r>56319){(t-=3)>-1&&l.push(239,191,189);continue}else if(h+1===e){(t-=3)>-1&&l.push(239,191,189);continue}p=r;continue}if(r<56320){(t-=3)>-1&&l.push(239,191,189),p=r;continue}r=(p-55296<<10|r-56320)+65536}else p&&(t-=3)>-1&&l.push(239,191,189);if(p=null,r<128){if((t-=1)<0)break;l.push(r)}else if(r<2048){if((t-=2)<0)break;l.push(r>>6|192,r&63|128)}else if(r<65536){if((t-=3)<0)break;l.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((t-=4)<0)break;l.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else throw new Error("Invalid code point")}return l}function yr(i){for(var t=[],r=0;r<i.length;++r)t.push(i.charCodeAt(r)&255);return t}function gr(i,t){for(var r,e,p,l=[],h=0;h<i.length&&!((t-=2)<0);++h)r=i.charCodeAt(h),e=r>>8,p=r%256,l.push(p),l.push(e);return l}function Et(i){return a.toByteArray(wr(i))}function C(i,t,r,e){for(var p=0;p<e&&!(p+r>=t.length||p>=i.length);++p)t[p+r]=i[p];return p}function I(i,t){return i instanceof t||i!=null&&i.constructor!=null&&i.constructor.name!=null&&i.constructor.name===t.name}function X(i){return i!==i}var vr=function(){for(var i="0123456789abcdef",t=new Array(256),r=0;r<16;++r)for(var e=r*16,p=0;p<16;++p)t[e+p]=i[r]+i[p];return t}()})(Nt);/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */(function(n,a){var s=Nt,c=s.Buffer;function f(u,o){for(var x in u)o[x]=u[x]}c.from&&c.alloc&&c.allocUnsafe&&c.allocUnsafeSlow?n.exports=s:(f(s,a),a.Buffer=m);function m(u,o,x){return c(u,o,x)}m.prototype=Object.create(c.prototype),f(c,m),m.from=function(u,o,x){if(typeof u=="number")throw new TypeError("Argument must not be a number");return c(u,o,x)},m.alloc=function(u,o,x){if(typeof u!="number")throw new TypeError("Argument must be a number");var y=c(u);return o!==void 0?typeof x=="string"?y.fill(o,x):y.fill(o):y.fill(0),y},m.allocUnsafe=function(u){if(typeof u!="number")throw new TypeError("Argument must be a number");return c(u)},m.allocUnsafeSlow=function(u){if(typeof u!="number")throw new TypeError("Argument must be a number");return s.SlowBuffer(u)}})(rt,rt.exports);var Rt=rt.exports,Ct=Rt.Buffer;function P(n,a){this._block=Ct.alloc(n),this._finalSize=a,this._blockSize=n,this._len=0}P.prototype.update=function(n,a){typeof n=="string"&&(a=a||"utf8",n=Ct.from(n,a));for(var s=this._block,c=this._blockSize,f=n.length,m=this._len,u=0;u<f;){for(var o=m%c,x=Math.min(f-u,c-o),y=0;y<x;y++)s[o+y]=n[u+y];m+=x,u+=x,m%c===0&&this._update(s)}return this._len+=f,this};P.prototype.digest=function(n){var a=this._len%this._blockSize;this._block[a]=128,this._block.fill(0,a+1),a>=this._finalSize&&(this._update(this._block),this._block.fill(0));var s=this._len*8;if(s<=4294967295)this._block.writeUInt32BE(s,this._blockSize-4);else{var c=(s&4294967295)>>>0,f=(s-c)/4294967296;this._block.writeUInt32BE(f,this._blockSize-8),this._block.writeUInt32BE(c,this._blockSize-4)}this._update(this._block);var m=this._hash();return n?m.toString(n):m};P.prototype._update=function(){throw new Error("_update must be implemented by subclass")};var Pr=P,Wr=Or,Lt=Pr,Hr=Rt.Buffer,Zr=[1518500249,1859775393,-1894007588,-899497514],Kr=new Array(80);function R(){this.init(),this._w=Kr,Lt.call(this,64,56)}Wr(R,Lt);R.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function Yr(n){return n<<1|n>>>31}function Xr(n){return n<<5|n>>>27}function Gr(n){return n<<30|n>>>2}function Vr(n,a,s,c){return n===0?a&s|~a&c:n===2?a&s|a&c|s&c:a^s^c}R.prototype._update=function(n){for(var a=this._w,s=this._a|0,c=this._b|0,f=this._c|0,m=this._d|0,u=this._e|0,o=0;o<16;++o)a[o]=n.readInt32BE(o*4);for(;o<80;++o)a[o]=Yr(a[o-3]^a[o-8]^a[o-14]^a[o-16]);for(var x=0;x<80;++x){var y=~~(x/20),v=Xr(s)+Vr(y,c,f,m)+u+a[x]+Zr[y]|0;u=m,m=f,f=Gr(c),c=s,s=v}this._a=s+this._a|0,this._b=c+this._b|0,this._c=f+this._c|0,this._d=m+this._d|0,this._e=u+this._e|0};R.prototype._hash=function(){var n=Hr.allocUnsafe(20);return n.writeInt32BE(this._a|0,0),n.writeInt32BE(this._b|0,4),n.writeInt32BE(this._c|0,8),n.writeInt32BE(this._d|0,12),n.writeInt32BE(this._e|0,16),n};var Qr=R;const ti=Ot(Qr),lt=new Error("File system not available.");function ri(n,a,s){throw lt}function qt(n){throw lt}function ii(n){throw lt}const ei=async n=>qt();function ni(n){let a="";for(let s=0;s<n.length;s+=2)a+=String.fromCharCode(parseInt(n.substr(s,2),16));return btoa(a)}const W=(n,a="sha1")=>{if(a!=="sha1")throw new Error("Only sha1 algorithm is available.");const s=new ti;return ni(s.update(n).digest("hex"))},ut=async n=>{const a=new _t,{name:s,revision:c,documentType:f,created:m,lastModified:u}=n,o={name:s,revision:c,documentType:f,created:m,lastModified:u};return a.file("header.json",JSON.stringify(o,null,2)),a.file("state.json",JSON.stringify(n.initialState||{},null,2)),a.file("operations.json",JSON.stringify(n.operations,null,2)),Object.keys(n.attachments).forEach(y=>{const{data:v,...F}=n.attachments[y];a.file(y,v,{base64:!0,createFolders:!0,comment:JSON.stringify(F)})}),a},$t=async(n,a,s,c)=>{await(await ut(n)).generateAsync({type:"uint8array",streamFiles:!0});const m=c??n.name,u=`.${s}.zip`;return ri(a,m.endsWith(u)?m:`${m}${u}`)},ai=async(n,a)=>{const c=await(await ut(n)).generateAsync({type:"blob"}),f=await a.createWritable();await f.write(c),await f.close()},it=async(n,a)=>{const s=qt();return Jt(s,a)},Jt=async(n,a)=>{const s=new _t;return await s.loadAsync(n),oi(s,a)};async function oi(n,a){const s=n.file("state.json");if(!s)throw new Error("Initial state not found");const c=await s.async("string"),f=JSON.parse(c),m=n.file("header.json");let u=null;m&&(u=JSON.parse(await m.async("string")));const o=n.file("operations.json");if(!o)throw new Error("Operations history not found");const x=JSON.parse(await o.async("string")),y={...f,...u,initialState:f,operations:[],attachments:{...f.attachments}};let v=x.slice(0,u==null?void 0:u.revision).reduce((F,U)=>a(F,U),y);return u&&(v={...v,...u,operations:[...v.operations,...x.slice(u.revision)]}),v}function Pt(n){const a=n.replace(/^.*\./,"")||void 0,s=n.replace(/^.*[/\\]/,"")||void 0;return{extension:a,fileName:s}}async function pi(n){const{buffer:a,mimeType:s="application/octet-stream"}=await ii(),c=Pt(n),f=a.toString("base64");return{data:f,hash:W(f),mimeType:s,...c}}async function si(n){const a=await ei(),s=Dr.getType(n)||"application/octet-stream",c=Pt(n),f=a.toString("base64");return{data:f,hash:W(f),mimeType:s,...c}}function q(n,a,s){const c=Xt(n),f=Kt(s);return a.reduce((m,u)=>f(m,u),c)}function ci(n,a){return{...n,name:a}}function li(n,a,s){const c=Math.min(a,n.revision),f=n.operations.slice(0,n.revision-c);return{...q(n.initialState,f,s),operations:n.operations,revision:n.revision-c}}function ui(n,a,s){const c=n.operations.length-n.revision;if(!c)throw new Error("There is no UNDO operation to REDO");const f=a<c?a:c,m=n.operations.slice(0,n.revision+f);return{...q(n.initialState,m,s),operations:n.operations,revision:n.revision+f}}function fi(n,a,s,c){a=a||0,s=s||n.operations.length;const f=n.operations.slice(a,s),m=n.operations.slice(0,a),u=n.operations.slice(s),o=q(n.initialState,m.concat(f),c),{name:x,state:y}=o;return q(n.initialState,[...m,ft({name:x,state:y},f.length),...u],c)}function hi(n,a){return{...n,name:a.name,state:a.state??{}}}const Wt="SET_NAME",H="UNDO",Z="REDO",M="PRUNE",Ht="LOAD_STATE";function mi(n,a){return[H,Z,M].includes(a.type)?n.revision:n.revision+1}function xi(n,a){return{...n,revision:mi(n,a),lastModified:new Date().toISOString()}}function di(n,a){if([H,Z,M,M].includes(a.type))return n;const s=n.operations.slice(0,n.revision);return{...n,operations:[...s,{...a,index:s.length,timestamp:new Date().toISOString(),hash:""}]}}function wi(n,a){let s=di(n,a);return s=xi(s,a),s}function yi(n,a,s){switch(Tt().parse(a),a.type){case Wt:return ci(n,a.input);case H:return li(n,a.input,s);case Z:return ui(n,a.input,s);case M:return fi(n,a.input.start,a.input.end,s);case Ht:return hi(n,a.input.state);default:return n}}function Zt(n,a,s){let c=n;return et(a)&&(c=yi(c,a,s)),c=wi(c,a),c=V.produce(c,f=>{const m=s(f.state,a);if(m)return V.castDraft({...c,state:m})}),V.produce(c,f=>{f.operations[f.operations.length-1].hash=Gt(f),!et(a)&&a.attachments&&a.attachments.forEach(m=>{const{hash:u,...o}=m;f.attachments[u]={...o}})})}function et(n){return[Wt,H,Z,M,Ht].includes(n.type)}function D(n,a,s,c){if(!n)throw new Error("Empty action type");if(typeof n!="string")throw new Error(`Invalid action type: ${n}`);const f=s?{type:n,input:a,attachments:s}:{type:n,input:a};return c==null||c().parse(f),f}function Kt(n,a=Zt){return(s,c)=>a(s,c,n)}const Yt=(n,a)=>({name:"",documentType:"",revision:0,created:new Date().toISOString(),lastModified:new Date().toISOString(),attachments:{},...n,state:(a==null?void 0:a(n==null?void 0:n.state))??(n==null?void 0:n.state)??{}}),Xt=(n,a)=>{const s=Yt(n,a);return{...s,initialState:s,operations:[]}},Gt=n=>W(Fr(n.state)),gi=(n,a=1e3)=>{const s=Math.random()*a;return W(`${(n??new Date).toISOString()}${s}`)},Vt=n=>D("SET_NAME",n,void 0,pt),Qt=(n=1)=>D("UNDO",n,void 0,st),tr=(n=1)=>D("REDO",n,void 0,ot),rr=(n,a)=>D("PRUNE",{start:n,end:a},void 0,at),ft=(n,a)=>D("LOAD_STATE",{state:n,operations:a},void 0,nt),vi=Object.freeze(Object.defineProperty({__proto__:null,loadState:ft,prune:rr,redo:tr,setName:Vt,undo:Qt},Symbol.toStringTag,{value:"Module"}));class Ei{constructor(a,s){G(this,"_document");G(this,"_reducer");this._reducer=a,this._document=s}dispatch(a){return this._document=this._reducer(this._document,a),this}saveToFile(a,s,c){return $t(this._document,a,s,c)}async loadFromFile(a){this._document=await it(a,this._reducer)}static async stateFromFile(a,s){return await it(a,s)}get state(){return this._document.state}get operations(){return this._document.operations}get name(){return this._document.name}get documentType(){return this._document.documentType}get created(){return this._document.created}get lastModified(){return this._document.lastModified}get revision(){return this._document.revision}get initialState(){return this._document.initialState}getAttachment(a){return this._document.attachments[a]}setName(a){return this.dispatch(Vt(a)),this}undo(a){return this.dispatch(Qt(a)),this}redo(a){return this.dispatch(tr(a)),this}prune(a,s){return this.dispatch(rr(a,s)),this}loadState(a,s){return this.dispatch(ft(a,s)),this}}function bi(n,a){a.forEach(s=>{Object.getOwnPropertyNames(s.prototype).forEach(c=>{Object.defineProperty(n.prototype,c,Object.getOwnPropertyDescriptor(s.prototype,c)||Object.create(null))})})}exports.BaseActions=vi;exports.BaseDocument=Ei;exports.applyMixins=bi;exports.baseReducer=Zt;exports.createAction=D;exports.createDocument=Xt;exports.createExtendedState=Yt;exports.createReducer=Kt;exports.createZip=ut;exports.getLocalFile=si;exports.getRemoteFile=pi;exports.hashDocument=Gt;exports.hashKey=gi;exports.isBaseAction=et;exports.loadFromFile=it;exports.loadFromInput=Jt;exports.saveToFile=$t;exports.saveToFileHandle=ai;exports.zod=Ur;
|
|
6
|
+
*/(function(n){var a=J,s=ct,c=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;n.Buffer=o,n.SlowBuffer=er,n.INSPECT_MAX_BYTES=50;var f=2147483647;n.kMaxLength=f,o.TYPED_ARRAY_SUPPORT=m(),!o.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function m(){try{var i=new Uint8Array(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,Uint8Array.prototype),Object.setPrototypeOf(i,t),i.foo()===42}catch{return!1}}Object.defineProperty(o.prototype,"parent",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.buffer}}),Object.defineProperty(o.prototype,"offset",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.byteOffset}});function u(i){if(i>f)throw new RangeError('The value "'+i+'" is invalid for option "size"');var t=new Uint8Array(i);return Object.setPrototypeOf(t,o.prototype),t}function o(i,t,r){if(typeof i=="number"){if(typeof t=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return F(i)}return x(i,t,r)}o.poolSize=8192;function x(i,t,r){if(typeof i=="string")return U(i,t);if(ArrayBuffer.isView(i))return O(i);if(i==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof i);if(I(i,ArrayBuffer)||i&&I(i.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(I(i,SharedArrayBuffer)||i&&I(i.buffer,SharedArrayBuffer)))return N(i,t,r);if(typeof i=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');var e=i.valueOf&&i.valueOf();if(e!=null&&e!==i)return o.from(e,t,r);var p=ir(i);if(p)return p;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof i[Symbol.toPrimitive]=="function")return o.from(i[Symbol.toPrimitive]("string"),t,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof i)}o.from=function(i,t,r){return x(i,t,r)},Object.setPrototypeOf(o.prototype,Uint8Array.prototype),Object.setPrototypeOf(o,Uint8Array);function y(i){if(typeof i!="number")throw new TypeError('"size" argument must be of type number');if(i<0)throw new RangeError('The value "'+i+'" is invalid for option "size"')}function v(i,t,r){return y(i),i<=0?u(i):t!==void 0?typeof r=="string"?u(i).fill(t,r):u(i).fill(t):u(i)}o.alloc=function(i,t,r){return v(i,t,r)};function F(i){return y(i),u(i<0?0:K(i)|0)}o.allocUnsafe=function(i){return F(i)},o.allocUnsafeSlow=function(i){return F(i)};function U(i,t){if((typeof t!="string"||t==="")&&(t="utf8"),!o.isEncoding(t))throw new TypeError("Unknown encoding: "+t);var r=ht(i,t)|0,e=u(r),p=e.write(i,t);return p!==r&&(e=e.slice(0,p)),e}function B(i){for(var t=i.length<0?0:K(i.length)|0,r=u(t),e=0;e<t;e+=1)r[e]=i[e]&255;return r}function O(i){if(I(i,Uint8Array)){var t=new Uint8Array(i);return N(t.buffer,t.byteOffset,t.byteLength)}return B(i)}function N(i,t,r){if(t<0||i.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(i.byteLength<t+(r||0))throw new RangeError('"length" is outside of buffer bounds');var e;return t===void 0&&r===void 0?e=new Uint8Array(i):r===void 0?e=new Uint8Array(i,t):e=new Uint8Array(i,t,r),Object.setPrototypeOf(e,o.prototype),e}function ir(i){if(o.isBuffer(i)){var t=K(i.length)|0,r=u(t);return r.length===0||i.copy(r,0,0,t),r}if(i.length!==void 0)return typeof i.length!="number"||X(i.length)?u(0):B(i);if(i.type==="Buffer"&&Array.isArray(i.data))return B(i.data)}function K(i){if(i>=f)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+f.toString(16)+" bytes");return i|0}function er(i){return+i!=i&&(i=0),o.alloc(+i)}o.isBuffer=function(t){return t!=null&&t._isBuffer===!0&&t!==o.prototype},o.compare=function(t,r){if(I(t,Uint8Array)&&(t=o.from(t,t.offset,t.byteLength)),I(r,Uint8Array)&&(r=o.from(r,r.offset,r.byteLength)),!o.isBuffer(t)||!o.isBuffer(r))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===r)return 0;for(var e=t.length,p=r.length,l=0,h=Math.min(e,p);l<h;++l)if(t[l]!==r[l]){e=t[l],p=r[l];break}return e<p?-1:p<e?1:0},o.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},o.concat=function(t,r){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(t.length===0)return o.alloc(0);var e;if(r===void 0)for(r=0,e=0;e<t.length;++e)r+=t[e].length;var p=o.allocUnsafe(r),l=0;for(e=0;e<t.length;++e){var h=t[e];if(I(h,Uint8Array))l+h.length>p.length?o.from(h).copy(p,l):Uint8Array.prototype.set.call(p,h,l);else if(o.isBuffer(h))h.copy(p,l);else throw new TypeError('"list" argument must be an Array of Buffers');l+=h.length}return p};function ht(i,t){if(o.isBuffer(i))return i.length;if(ArrayBuffer.isView(i)||I(i,ArrayBuffer))return i.byteLength;if(typeof i!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof i);var r=i.length,e=arguments.length>2&&arguments[2]===!0;if(!e&&r===0)return 0;for(var p=!1;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return Y(i).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return r*2;case"hex":return r>>>1;case"base64":return Et(i).length;default:if(p)return e?-1:Y(i).length;t=(""+t).toLowerCase(),p=!0}}o.byteLength=ht;function nr(i,t,r){var e=!1;if((t===void 0||t<0)&&(t=0),t>this.length||((r===void 0||r>this.length)&&(r=this.length),r<=0)||(r>>>=0,t>>>=0,r<=t))return"";for(i||(i="utf8");;)switch(i){case"hex":return mr(this,t,r);case"utf8":case"utf-8":return dt(this,t,r);case"ascii":return fr(this,t,r);case"latin1":case"binary":return hr(this,t,r);case"base64":return lr(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return xr(this,t,r);default:if(e)throw new TypeError("Unknown encoding: "+i);i=(i+"").toLowerCase(),e=!0}}o.prototype._isBuffer=!0;function k(i,t,r){var e=i[t];i[t]=i[r],i[r]=e}o.prototype.swap16=function(){var t=this.length;if(t%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var r=0;r<t;r+=2)k(this,r,r+1);return this},o.prototype.swap32=function(){var t=this.length;if(t%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var r=0;r<t;r+=4)k(this,r,r+3),k(this,r+1,r+2);return this},o.prototype.swap64=function(){var t=this.length;if(t%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var r=0;r<t;r+=8)k(this,r,r+7),k(this,r+1,r+6),k(this,r+2,r+5),k(this,r+3,r+4);return this},o.prototype.toString=function(){var t=this.length;return t===0?"":arguments.length===0?dt(this,0,t):nr.apply(this,arguments)},o.prototype.toLocaleString=o.prototype.toString,o.prototype.equals=function(t){if(!o.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t?!0:o.compare(this,t)===0},o.prototype.inspect=function(){var t="",r=n.INSPECT_MAX_BYTES;return t=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(t+=" ... "),"<Buffer "+t+">"},c&&(o.prototype[c]=o.prototype.inspect),o.prototype.compare=function(t,r,e,p,l){if(I(t,Uint8Array)&&(t=o.from(t,t.offset,t.byteLength)),!o.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(r===void 0&&(r=0),e===void 0&&(e=t?t.length:0),p===void 0&&(p=0),l===void 0&&(l=this.length),r<0||e>t.length||p<0||l>this.length)throw new RangeError("out of range index");if(p>=l&&r>=e)return 0;if(p>=l)return-1;if(r>=e)return 1;if(r>>>=0,e>>>=0,p>>>=0,l>>>=0,this===t)return 0;for(var h=l-p,w=e-r,g=Math.min(h,w),E=this.slice(p,l),A=t.slice(r,e),b=0;b<g;++b)if(E[b]!==A[b]){h=E[b],w=A[b];break}return h<w?-1:w<h?1:0};function mt(i,t,r,e,p){if(i.length===0)return-1;if(typeof r=="string"?(e=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,X(r)&&(r=p?0:i.length-1),r<0&&(r=i.length+r),r>=i.length){if(p)return-1;r=i.length-1}else if(r<0)if(p)r=0;else return-1;if(typeof t=="string"&&(t=o.from(t,e)),o.isBuffer(t))return t.length===0?-1:xt(i,t,r,e,p);if(typeof t=="number")return t=t&255,typeof Uint8Array.prototype.indexOf=="function"?p?Uint8Array.prototype.indexOf.call(i,t,r):Uint8Array.prototype.lastIndexOf.call(i,t,r):xt(i,[t],r,e,p);throw new TypeError("val must be string, number or Buffer")}function xt(i,t,r,e,p){var l=1,h=i.length,w=t.length;if(e!==void 0&&(e=String(e).toLowerCase(),e==="ucs2"||e==="ucs-2"||e==="utf16le"||e==="utf-16le")){if(i.length<2||t.length<2)return-1;l=2,h/=2,w/=2,r/=2}function g(bt,Ft){return l===1?bt[Ft]:bt.readUInt16BE(Ft*l)}var E;if(p){var A=-1;for(E=r;E<h;E++)if(g(i,E)===g(t,A===-1?0:E-A)){if(A===-1&&(A=E),E-A+1===w)return A*l}else A!==-1&&(E-=E-A),A=-1}else for(r+w>h&&(r=h-w),E=r;E>=0;E--){for(var b=!0,L=0;L<w;L++)if(g(i,E+L)!==g(t,L)){b=!1;break}if(b)return E}return-1}o.prototype.includes=function(t,r,e){return this.indexOf(t,r,e)!==-1},o.prototype.indexOf=function(t,r,e){return mt(this,t,r,e,!0)},o.prototype.lastIndexOf=function(t,r,e){return mt(this,t,r,e,!1)};function ar(i,t,r,e){r=Number(r)||0;var p=i.length-r;e?(e=Number(e),e>p&&(e=p)):e=p;var l=t.length;e>l/2&&(e=l/2);for(var h=0;h<e;++h){var w=parseInt(t.substr(h*2,2),16);if(X(w))return h;i[r+h]=w}return h}function or(i,t,r,e){return C(Y(t,i.length-r),i,r,e)}function pr(i,t,r,e){return C(yr(t),i,r,e)}function sr(i,t,r,e){return C(Et(t),i,r,e)}function cr(i,t,r,e){return C(gr(t,i.length-r),i,r,e)}o.prototype.write=function(t,r,e,p){if(r===void 0)p="utf8",e=this.length,r=0;else if(e===void 0&&typeof r=="string")p=r,e=this.length,r=0;else if(isFinite(r))r=r>>>0,isFinite(e)?(e=e>>>0,p===void 0&&(p="utf8")):(p=e,e=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");var l=this.length-r;if((e===void 0||e>l)&&(e=l),t.length>0&&(e<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");p||(p="utf8");for(var h=!1;;)switch(p){case"hex":return ar(this,t,r,e);case"utf8":case"utf-8":return or(this,t,r,e);case"ascii":case"latin1":case"binary":return pr(this,t,r,e);case"base64":return sr(this,t,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return cr(this,t,r,e);default:if(h)throw new TypeError("Unknown encoding: "+p);p=(""+p).toLowerCase(),h=!0}},o.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function lr(i,t,r){return t===0&&r===i.length?a.fromByteArray(i):a.fromByteArray(i.slice(t,r))}function dt(i,t,r){r=Math.min(i.length,r);for(var e=[],p=t;p<r;){var l=i[p],h=null,w=l>239?4:l>223?3:l>191?2:1;if(p+w<=r){var g,E,A,b;switch(w){case 1:l<128&&(h=l);break;case 2:g=i[p+1],(g&192)===128&&(b=(l&31)<<6|g&63,b>127&&(h=b));break;case 3:g=i[p+1],E=i[p+2],(g&192)===128&&(E&192)===128&&(b=(l&15)<<12|(g&63)<<6|E&63,b>2047&&(b<55296||b>57343)&&(h=b));break;case 4:g=i[p+1],E=i[p+2],A=i[p+3],(g&192)===128&&(E&192)===128&&(A&192)===128&&(b=(l&15)<<18|(g&63)<<12|(E&63)<<6|A&63,b>65535&&b<1114112&&(h=b))}}h===null?(h=65533,w=1):h>65535&&(h-=65536,e.push(h>>>10&1023|55296),h=56320|h&1023),e.push(h),p+=w}return ur(e)}var wt=4096;function ur(i){var t=i.length;if(t<=wt)return String.fromCharCode.apply(String,i);for(var r="",e=0;e<t;)r+=String.fromCharCode.apply(String,i.slice(e,e+=wt));return r}function fr(i,t,r){var e="";r=Math.min(i.length,r);for(var p=t;p<r;++p)e+=String.fromCharCode(i[p]&127);return e}function hr(i,t,r){var e="";r=Math.min(i.length,r);for(var p=t;p<r;++p)e+=String.fromCharCode(i[p]);return e}function mr(i,t,r){var e=i.length;(!t||t<0)&&(t=0),(!r||r<0||r>e)&&(r=e);for(var p="",l=t;l<r;++l)p+=vr[i[l]];return p}function xr(i,t,r){for(var e=i.slice(t,r),p="",l=0;l<e.length-1;l+=2)p+=String.fromCharCode(e[l]+e[l+1]*256);return p}o.prototype.slice=function(t,r){var e=this.length;t=~~t,r=r===void 0?e:~~r,t<0?(t+=e,t<0&&(t=0)):t>e&&(t=e),r<0?(r+=e,r<0&&(r=0)):r>e&&(r=e),r<t&&(r=t);var p=this.subarray(t,r);return Object.setPrototypeOf(p,o.prototype),p};function _(i,t,r){if(i%1!==0||i<0)throw new RangeError("offset is not uint");if(i+t>r)throw new RangeError("Trying to access beyond buffer length")}o.prototype.readUintLE=o.prototype.readUIntLE=function(t,r,e){t=t>>>0,r=r>>>0,e||_(t,r,this.length);for(var p=this[t],l=1,h=0;++h<r&&(l*=256);)p+=this[t+h]*l;return p},o.prototype.readUintBE=o.prototype.readUIntBE=function(t,r,e){t=t>>>0,r=r>>>0,e||_(t,r,this.length);for(var p=this[t+--r],l=1;r>0&&(l*=256);)p+=this[t+--r]*l;return p},o.prototype.readUint8=o.prototype.readUInt8=function(t,r){return t=t>>>0,r||_(t,1,this.length),this[t]},o.prototype.readUint16LE=o.prototype.readUInt16LE=function(t,r){return t=t>>>0,r||_(t,2,this.length),this[t]|this[t+1]<<8},o.prototype.readUint16BE=o.prototype.readUInt16BE=function(t,r){return t=t>>>0,r||_(t,2,this.length),this[t]<<8|this[t+1]},o.prototype.readUint32LE=o.prototype.readUInt32LE=function(t,r){return t=t>>>0,r||_(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+this[t+3]*16777216},o.prototype.readUint32BE=o.prototype.readUInt32BE=function(t,r){return t=t>>>0,r||_(t,4,this.length),this[t]*16777216+(this[t+1]<<16|this[t+2]<<8|this[t+3])},o.prototype.readIntLE=function(t,r,e){t=t>>>0,r=r>>>0,e||_(t,r,this.length);for(var p=this[t],l=1,h=0;++h<r&&(l*=256);)p+=this[t+h]*l;return l*=128,p>=l&&(p-=Math.pow(2,8*r)),p},o.prototype.readIntBE=function(t,r,e){t=t>>>0,r=r>>>0,e||_(t,r,this.length);for(var p=r,l=1,h=this[t+--p];p>0&&(l*=256);)h+=this[t+--p]*l;return l*=128,h>=l&&(h-=Math.pow(2,8*r)),h},o.prototype.readInt8=function(t,r){return t=t>>>0,r||_(t,1,this.length),this[t]&128?(255-this[t]+1)*-1:this[t]},o.prototype.readInt16LE=function(t,r){t=t>>>0,r||_(t,2,this.length);var e=this[t]|this[t+1]<<8;return e&32768?e|4294901760:e},o.prototype.readInt16BE=function(t,r){t=t>>>0,r||_(t,2,this.length);var e=this[t+1]|this[t]<<8;return e&32768?e|4294901760:e},o.prototype.readInt32LE=function(t,r){return t=t>>>0,r||_(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},o.prototype.readInt32BE=function(t,r){return t=t>>>0,r||_(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},o.prototype.readFloatLE=function(t,r){return t=t>>>0,r||_(t,4,this.length),s.read(this,t,!0,23,4)},o.prototype.readFloatBE=function(t,r){return t=t>>>0,r||_(t,4,this.length),s.read(this,t,!1,23,4)},o.prototype.readDoubleLE=function(t,r){return t=t>>>0,r||_(t,8,this.length),s.read(this,t,!0,52,8)},o.prototype.readDoubleBE=function(t,r){return t=t>>>0,r||_(t,8,this.length),s.read(this,t,!1,52,8)};function S(i,t,r,e,p,l){if(!o.isBuffer(i))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>p||t<l)throw new RangeError('"value" argument is out of bounds');if(r+e>i.length)throw new RangeError("Index out of range")}o.prototype.writeUintLE=o.prototype.writeUIntLE=function(t,r,e,p){if(t=+t,r=r>>>0,e=e>>>0,!p){var l=Math.pow(2,8*e)-1;S(this,t,r,e,l,0)}var h=1,w=0;for(this[r]=t&255;++w<e&&(h*=256);)this[r+w]=t/h&255;return r+e},o.prototype.writeUintBE=o.prototype.writeUIntBE=function(t,r,e,p){if(t=+t,r=r>>>0,e=e>>>0,!p){var l=Math.pow(2,8*e)-1;S(this,t,r,e,l,0)}var h=e-1,w=1;for(this[r+h]=t&255;--h>=0&&(w*=256);)this[r+h]=t/w&255;return r+e},o.prototype.writeUint8=o.prototype.writeUInt8=function(t,r,e){return t=+t,r=r>>>0,e||S(this,t,r,1,255,0),this[r]=t&255,r+1},o.prototype.writeUint16LE=o.prototype.writeUInt16LE=function(t,r,e){return t=+t,r=r>>>0,e||S(this,t,r,2,65535,0),this[r]=t&255,this[r+1]=t>>>8,r+2},o.prototype.writeUint16BE=o.prototype.writeUInt16BE=function(t,r,e){return t=+t,r=r>>>0,e||S(this,t,r,2,65535,0),this[r]=t>>>8,this[r+1]=t&255,r+2},o.prototype.writeUint32LE=o.prototype.writeUInt32LE=function(t,r,e){return t=+t,r=r>>>0,e||S(this,t,r,4,4294967295,0),this[r+3]=t>>>24,this[r+2]=t>>>16,this[r+1]=t>>>8,this[r]=t&255,r+4},o.prototype.writeUint32BE=o.prototype.writeUInt32BE=function(t,r,e){return t=+t,r=r>>>0,e||S(this,t,r,4,4294967295,0),this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=t&255,r+4},o.prototype.writeIntLE=function(t,r,e,p){if(t=+t,r=r>>>0,!p){var l=Math.pow(2,8*e-1);S(this,t,r,e,l-1,-l)}var h=0,w=1,g=0;for(this[r]=t&255;++h<e&&(w*=256);)t<0&&g===0&&this[r+h-1]!==0&&(g=1),this[r+h]=(t/w>>0)-g&255;return r+e},o.prototype.writeIntBE=function(t,r,e,p){if(t=+t,r=r>>>0,!p){var l=Math.pow(2,8*e-1);S(this,t,r,e,l-1,-l)}var h=e-1,w=1,g=0;for(this[r+h]=t&255;--h>=0&&(w*=256);)t<0&&g===0&&this[r+h+1]!==0&&(g=1),this[r+h]=(t/w>>0)-g&255;return r+e},o.prototype.writeInt8=function(t,r,e){return t=+t,r=r>>>0,e||S(this,t,r,1,127,-128),t<0&&(t=255+t+1),this[r]=t&255,r+1},o.prototype.writeInt16LE=function(t,r,e){return t=+t,r=r>>>0,e||S(this,t,r,2,32767,-32768),this[r]=t&255,this[r+1]=t>>>8,r+2},o.prototype.writeInt16BE=function(t,r,e){return t=+t,r=r>>>0,e||S(this,t,r,2,32767,-32768),this[r]=t>>>8,this[r+1]=t&255,r+2},o.prototype.writeInt32LE=function(t,r,e){return t=+t,r=r>>>0,e||S(this,t,r,4,2147483647,-2147483648),this[r]=t&255,this[r+1]=t>>>8,this[r+2]=t>>>16,this[r+3]=t>>>24,r+4},o.prototype.writeInt32BE=function(t,r,e){return t=+t,r=r>>>0,e||S(this,t,r,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=t&255,r+4};function yt(i,t,r,e,p,l){if(r+e>i.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function gt(i,t,r,e,p){return t=+t,r=r>>>0,p||yt(i,t,r,4),s.write(i,t,r,e,23,4),r+4}o.prototype.writeFloatLE=function(t,r,e){return gt(this,t,r,!0,e)},o.prototype.writeFloatBE=function(t,r,e){return gt(this,t,r,!1,e)};function vt(i,t,r,e,p){return t=+t,r=r>>>0,p||yt(i,t,r,8),s.write(i,t,r,e,52,8),r+8}o.prototype.writeDoubleLE=function(t,r,e){return vt(this,t,r,!0,e)},o.prototype.writeDoubleBE=function(t,r,e){return vt(this,t,r,!1,e)},o.prototype.copy=function(t,r,e,p){if(!o.isBuffer(t))throw new TypeError("argument should be a Buffer");if(e||(e=0),!p&&p!==0&&(p=this.length),r>=t.length&&(r=t.length),r||(r=0),p>0&&p<e&&(p=e),p===e||t.length===0||this.length===0)return 0;if(r<0)throw new RangeError("targetStart out of bounds");if(e<0||e>=this.length)throw new RangeError("Index out of range");if(p<0)throw new RangeError("sourceEnd out of bounds");p>this.length&&(p=this.length),t.length-r<p-e&&(p=t.length-r+e);var l=p-e;return this===t&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(r,e,p):Uint8Array.prototype.set.call(t,this.subarray(e,p),r),l},o.prototype.fill=function(t,r,e,p){if(typeof t=="string"){if(typeof r=="string"?(p=r,r=0,e=this.length):typeof e=="string"&&(p=e,e=this.length),p!==void 0&&typeof p!="string")throw new TypeError("encoding must be a string");if(typeof p=="string"&&!o.isEncoding(p))throw new TypeError("Unknown encoding: "+p);if(t.length===1){var l=t.charCodeAt(0);(p==="utf8"&&l<128||p==="latin1")&&(t=l)}}else typeof t=="number"?t=t&255:typeof t=="boolean"&&(t=Number(t));if(r<0||this.length<r||this.length<e)throw new RangeError("Out of range index");if(e<=r)return this;r=r>>>0,e=e===void 0?this.length:e>>>0,t||(t=0);var h;if(typeof t=="number")for(h=r;h<e;++h)this[h]=t;else{var w=o.isBuffer(t)?t:o.from(t,p),g=w.length;if(g===0)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(h=0;h<e-r;++h)this[h+r]=w[h%g]}return this};var dr=/[^+/0-9A-Za-z-_]/g;function wr(i){if(i=i.split("=")[0],i=i.trim().replace(dr,""),i.length<2)return"";for(;i.length%4!==0;)i=i+"=";return i}function Y(i,t){t=t||1/0;for(var r,e=i.length,p=null,l=[],h=0;h<e;++h){if(r=i.charCodeAt(h),r>55295&&r<57344){if(!p){if(r>56319){(t-=3)>-1&&l.push(239,191,189);continue}else if(h+1===e){(t-=3)>-1&&l.push(239,191,189);continue}p=r;continue}if(r<56320){(t-=3)>-1&&l.push(239,191,189),p=r;continue}r=(p-55296<<10|r-56320)+65536}else p&&(t-=3)>-1&&l.push(239,191,189);if(p=null,r<128){if((t-=1)<0)break;l.push(r)}else if(r<2048){if((t-=2)<0)break;l.push(r>>6|192,r&63|128)}else if(r<65536){if((t-=3)<0)break;l.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((t-=4)<0)break;l.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else throw new Error("Invalid code point")}return l}function yr(i){for(var t=[],r=0;r<i.length;++r)t.push(i.charCodeAt(r)&255);return t}function gr(i,t){for(var r,e,p,l=[],h=0;h<i.length&&!((t-=2)<0);++h)r=i.charCodeAt(h),e=r>>8,p=r%256,l.push(p),l.push(e);return l}function Et(i){return a.toByteArray(wr(i))}function C(i,t,r,e){for(var p=0;p<e&&!(p+r>=t.length||p>=i.length);++p)t[p+r]=i[p];return p}function I(i,t){return i instanceof t||i!=null&&i.constructor!=null&&i.constructor.name!=null&&i.constructor.name===t.name}function X(i){return i!==i}var vr=function(){for(var i="0123456789abcdef",t=new Array(256),r=0;r<16;++r)for(var e=r*16,p=0;p<16;++p)t[e+p]=i[r]+i[p];return t}()})(Nt);/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */(function(n,a){var s=Nt,c=s.Buffer;function f(u,o){for(var x in u)o[x]=u[x]}c.from&&c.alloc&&c.allocUnsafe&&c.allocUnsafeSlow?n.exports=s:(f(s,a),a.Buffer=m);function m(u,o,x){return c(u,o,x)}m.prototype=Object.create(c.prototype),f(c,m),m.from=function(u,o,x){if(typeof u=="number")throw new TypeError("Argument must not be a number");return c(u,o,x)},m.alloc=function(u,o,x){if(typeof u!="number")throw new TypeError("Argument must be a number");var y=c(u);return o!==void 0?typeof x=="string"?y.fill(o,x):y.fill(o):y.fill(0),y},m.allocUnsafe=function(u){if(typeof u!="number")throw new TypeError("Argument must be a number");return c(u)},m.allocUnsafeSlow=function(u){if(typeof u!="number")throw new TypeError("Argument must be a number");return s.SlowBuffer(u)}})(rt,rt.exports);var Rt=rt.exports,Ct=Rt.Buffer;function P(n,a){this._block=Ct.alloc(n),this._finalSize=a,this._blockSize=n,this._len=0}P.prototype.update=function(n,a){typeof n=="string"&&(a=a||"utf8",n=Ct.from(n,a));for(var s=this._block,c=this._blockSize,f=n.length,m=this._len,u=0;u<f;){for(var o=m%c,x=Math.min(f-u,c-o),y=0;y<x;y++)s[o+y]=n[u+y];m+=x,u+=x,m%c===0&&this._update(s)}return this._len+=f,this};P.prototype.digest=function(n){var a=this._len%this._blockSize;this._block[a]=128,this._block.fill(0,a+1),a>=this._finalSize&&(this._update(this._block),this._block.fill(0));var s=this._len*8;if(s<=4294967295)this._block.writeUInt32BE(s,this._blockSize-4);else{var c=(s&4294967295)>>>0,f=(s-c)/4294967296;this._block.writeUInt32BE(f,this._blockSize-8),this._block.writeUInt32BE(c,this._blockSize-4)}this._update(this._block);var m=this._hash();return n?m.toString(n):m};P.prototype._update=function(){throw new Error("_update must be implemented by subclass")};var Pr=P,Wr=Or,Lt=Pr,Hr=Rt.Buffer,Zr=[1518500249,1859775393,-1894007588,-899497514],Kr=new Array(80);function R(){this.init(),this._w=Kr,Lt.call(this,64,56)}Wr(R,Lt);R.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function Yr(n){return n<<1|n>>>31}function Xr(n){return n<<5|n>>>27}function Gr(n){return n<<30|n>>>2}function Vr(n,a,s,c){return n===0?a&s|~a&c:n===2?a&s|a&c|s&c:a^s^c}R.prototype._update=function(n){for(var a=this._w,s=this._a|0,c=this._b|0,f=this._c|0,m=this._d|0,u=this._e|0,o=0;o<16;++o)a[o]=n.readInt32BE(o*4);for(;o<80;++o)a[o]=Yr(a[o-3]^a[o-8]^a[o-14]^a[o-16]);for(var x=0;x<80;++x){var y=~~(x/20),v=Xr(s)+Vr(y,c,f,m)+u+a[x]+Zr[y]|0;u=m,m=f,f=Gr(c),c=s,s=v}this._a=s+this._a|0,this._b=c+this._b|0,this._c=f+this._c|0,this._d=m+this._d|0,this._e=u+this._e|0};R.prototype._hash=function(){var n=Hr.allocUnsafe(20);return n.writeInt32BE(this._a|0,0),n.writeInt32BE(this._b|0,4),n.writeInt32BE(this._c|0,8),n.writeInt32BE(this._d|0,12),n.writeInt32BE(this._e|0,16),n};var Qr=R;const ti=Ot(Qr),lt=new Error("File system not available.");function ri(n,a,s){throw lt}function qt(n){throw lt}function ii(n){throw lt}const ei=async n=>qt();function ni(n){let a="";for(let s=0;s<n.length;s+=2)a+=String.fromCharCode(parseInt(n.substr(s,2),16));return btoa(a)}const W=(n,a="sha1")=>{if(a!=="sha1")throw new Error("Only sha1 algorithm is available.");const s=new ti;return ni(s.update(n).digest("hex"))},ut=async n=>{const a=new _t,{name:s,revision:c,documentType:f,created:m,lastModified:u}=n,o={name:s,revision:c,documentType:f,created:m,lastModified:u};return a.file("header.json",JSON.stringify(o,null,2)),a.file("state.json",JSON.stringify(n.initialState||{},null,2)),a.file("operations.json",JSON.stringify(n.operations,null,2)),Object.keys(n.attachments).forEach(y=>{const{data:v,...F}=n.attachments[y];a.file(y,v,{base64:!0,createFolders:!0,comment:JSON.stringify(F)})}),a},$t=async(n,a,s,c)=>{await(await ut(n)).generateAsync({type:"uint8array",streamFiles:!0});const m=c??n.name,u=`.${s}.zip`;return ri(a,m.endsWith(u)?m:`${m}${u}`)},ai=async(n,a)=>{const c=await(await ut(n)).generateAsync({type:"blob"}),f=await a.createWritable();await f.write(c),await f.close()},it=async(n,a)=>{const s=qt();return Jt(s,a)},Jt=async(n,a)=>{const s=new _t;return await s.loadAsync(n),oi(s,a)};async function oi(n,a){const s=n.file("state.json");if(!s)throw new Error("Initial state not found");const c=await s.async("string"),f=JSON.parse(c),m=n.file("header.json");let u=null;m&&(u=JSON.parse(await m.async("string")));const o=n.file("operations.json");if(!o)throw new Error("Operations history not found");const x=JSON.parse(await o.async("string")),y={...f,...u,initialState:f,operations:[],attachments:{...f.attachments}};let v=x.slice(0,u==null?void 0:u.revision).reduce((F,U)=>a(F,U),y);return u&&(v={...v,...u,operations:[...v.operations,...x.slice(u.revision)]}),v}function Pt(n){const a=n.replace(/^.*\./,"")||void 0,s=n.replace(/^.*[/\\]/,"")||void 0;return{extension:a,fileName:s}}async function pi(n){const{buffer:a,mimeType:s="application/octet-stream"}=await ii(),c=Pt(n),f=a.toString("base64");return{data:f,hash:W(f),mimeType:s,...c}}async function si(n){const a=await ei(),s=Dr.getType(n)||"application/octet-stream",c=Pt(n),f=a.toString("base64");return{data:f,hash:W(f),mimeType:s,...c}}function q(n,a,s){const c=Xt(n),f=Kt(s);return a.reduce((m,u)=>f(m,u),c)}function ci(n,a){return{...n,name:a}}function li(n,a,s){const c=Math.min(a,n.revision),f=n.operations.slice(0,n.revision-c);return{...q(n.initialState,f,s),operations:n.operations,revision:n.revision-c}}function ui(n,a,s){const c=n.operations.length-n.revision;if(!c)throw new Error("There is no UNDO operation to REDO");const f=a<c?a:c,m=n.operations.slice(0,n.revision+f);return{...q(n.initialState,m,s),operations:n.operations,revision:n.revision+f}}function fi(n,a,s,c){a=a||0,s=s||n.operations.length;const f=n.operations.slice(a,s),m=n.operations.slice(0,a),u=n.operations.slice(s),o=q(n.initialState,m.concat(f),c),{name:x,state:y}=o;return q(n.initialState,[...m,ft({name:x,state:y},f.length),...u],c)}function hi(n,a){return{...n,name:a.name,state:a.state??{}}}const Wt="SET_NAME",H="UNDO",Z="REDO",M="PRUNE",Ht="LOAD_STATE";function mi(n,a){return[H,Z,M].includes(a.type)?n.revision:n.revision+1}function xi(n,a){return{...n,revision:mi(n,a),lastModified:new Date().toISOString()}}function di(n,a){if([H,Z,M,M].includes(a.type))return n;const s=n.operations.slice(0,n.revision);return{...n,operations:[...s,{...a,index:s.length,timestamp:new Date().toISOString(),hash:""}]}}function wi(n,a){let s=di(n,a);return s=xi(s,a),s}function yi(n,a,s){switch(Tt().parse(a),a.type){case Wt:return ci(n,a.input);case H:return li(n,a.input,s);case Z:return ui(n,a.input,s);case M:return fi(n,a.input.start,a.input.end,s);case Ht:return hi(n,a.input.state);default:return n}}function Zt(n,a,s){let c=n;return et(a)&&(c=yi(c,a,s)),c=wi(c,a),c=V.produce(c,f=>{const m=s(f.state,a);if(m)return V.castDraft({...c,state:m})}),V.produce(c,f=>{f.operations[f.operations.length-1].hash=Gt(f),!et(a)&&a.attachments&&a.attachments.forEach(m=>{const{hash:u,...o}=m;f.attachments[u]={...o}})})}function et(n){return[Wt,H,Z,M,Ht].includes(n.type)}function D(n,a,s,c){if(!n)throw new Error("Empty action type");if(typeof n!="string")throw new Error(`Invalid action type: ${n}`);const f=s?{type:n,input:a,attachments:s}:{type:n,input:a};return c==null||c().parse(f),f}function Kt(n,a=Zt){return(s,c)=>a(s,c,n)}const Yt=(n,a)=>({name:"",documentType:"",revision:0,created:new Date().toISOString(),lastModified:new Date().toISOString(),attachments:{},...n,state:(a==null?void 0:a(n==null?void 0:n.state))??(n==null?void 0:n.state)??{}}),Xt=(n,a)=>{const s=Yt(n,a);return{...s,initialState:s,operations:[]}},Gt=n=>W(Fr(n.state)),gi=(n,a=1e3)=>{const s=Math.random()*a;return W(`${(n??new Date).toISOString()}${s}`)},Vt=n=>D("SET_NAME",n,void 0,pt),Qt=(n=1)=>D("UNDO",n,void 0,st),tr=(n=1)=>D("REDO",n,void 0,ot),rr=(n,a)=>D("PRUNE",{start:n,end:a},void 0,at),ft=(n,a)=>D("LOAD_STATE",{state:n,operations:a},void 0,nt),vi=Object.freeze(Object.defineProperty({__proto__:null,loadState:ft,prune:rr,redo:tr,setName:Vt,undo:Qt},Symbol.toStringTag,{value:"Module"}));class Ei{constructor(a,s){G(this,"_document");G(this,"_reducer");this._reducer=a,this._document=s}dispatch(a){return this._document=this._reducer(this._document,a),this}saveToFile(a,s,c){return $t(this._document,a,s,c)}async loadFromFile(a){this._document=await it(a,this._reducer)}static async stateFromFile(a,s){return await it(a,s)}get state(){return this._document.state}get operations(){return this._document.operations}get name(){return this._document.name}get documentType(){return this._document.documentType}get created(){return this._document.created}get lastModified(){return this._document.lastModified}get revision(){return this._document.revision}get initialState(){return this._document.initialState}toDocument(){return this._document}getAttachment(a){return this._document.attachments[a]}setName(a){return this.dispatch(Vt(a)),this}undo(a){return this.dispatch(Qt(a)),this}redo(a){return this.dispatch(tr(a)),this}prune(a,s){return this.dispatch(rr(a,s)),this}loadState(a,s){return this.dispatch(ft(a,s)),this}}function bi(n,a){a.forEach(s=>{Object.getOwnPropertyNames(s.prototype).forEach(c=>{Object.defineProperty(n.prototype,c,Object.getOwnPropertyDescriptor(s.prototype,c)||Object.create(null))})})}exports.BaseActions=vi;exports.BaseDocument=Ei;exports.applyMixins=bi;exports.baseReducer=Zt;exports.createAction=D;exports.createDocument=Xt;exports.createExtendedState=Yt;exports.createReducer=Kt;exports.createZip=ut;exports.getLocalFile=si;exports.getRemoteFile=pi;exports.hashDocument=Gt;exports.hashKey=gi;exports.isBaseAction=et;exports.loadFromFile=it;exports.loadFromInput=Jt;exports.saveToFile=$t;exports.saveToFileHandle=ai;exports.zod=Ur;
|
|
@@ -1571,6 +1571,12 @@ class Si {
|
|
|
1571
1571
|
get initialState() {
|
|
1572
1572
|
return this._document.initialState;
|
|
1573
1573
|
}
|
|
1574
|
+
/**
|
|
1575
|
+
* Returns the current document as an object
|
|
1576
|
+
*/
|
|
1577
|
+
toDocument() {
|
|
1578
|
+
return this._document;
|
|
1579
|
+
}
|
|
1574
1580
|
/**
|
|
1575
1581
|
* Gets the attachment associated with the given key.
|
|
1576
1582
|
* @param attachment - The key of the attachment to retrieve.
|
|
@@ -72,6 +72,10 @@ export declare abstract class BaseDocument<T, A extends Action> {
|
|
|
72
72
|
* Gets the initial state of the document.
|
|
73
73
|
*/
|
|
74
74
|
get initialState(): ExtendedState<T>;
|
|
75
|
+
/**
|
|
76
|
+
* Returns the current document as an object
|
|
77
|
+
*/
|
|
78
|
+
toDocument(): Document<T, A>;
|
|
75
79
|
/**
|
|
76
80
|
* Gets the attachment associated with the given key.
|
|
77
81
|
* @param attachment - The key of the attachment to retrieve.
|
|
@@ -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-9fcc9b3e.js");require("json-stringify-deterministic");require("immer");require("crypto");require("fs");require("https");require("path");require("jszip");const e=require("./internal/index-574ece31.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.z=e.zod;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./internal/object-
|
|
1
|
+
import "./internal/object-19968a54.js";
|
|
2
2
|
import "json-stringify-deterministic";
|
|
3
3
|
import "immer";
|
|
4
4
|
import "crypto";
|
|
@@ -6,7 +6,7 @@ import "fs";
|
|
|
6
6
|
import "https";
|
|
7
7
|
import "path";
|
|
8
8
|
import "jszip";
|
|
9
|
-
import { b as d, a as l, c as n, d as D, m as M, r as b, u as f, z as x } from "./internal/index-
|
|
9
|
+
import { b as d, a as l, c as n, d as D, m as M, r as b, u as f, z as x } from "./internal/index-f3fdeced.js";
|
|
10
10
|
import "zod";
|
|
11
11
|
export {
|
|
12
12
|
d as Document,
|
package/dist/node/document.cjs
CHANGED
|
@@ -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-9fcc9b3e.js"),r=require("./internal/index-6ee6330b.js");require("json-stringify-deterministic");require("immer");require("zod");require("crypto");require("fs");require("https");require("path");require("jszip");exports.BaseDocument=e.BaseDocument;exports.actions=e.BaseActions;exports.applyMixins=e.applyMixins;exports.baseReducer=e.baseReducer;exports.z=e.zod;exports.utils=r.index;
|
package/dist/node/document.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { B as n, h as u, g as x, p as f, z as l } from "./internal/object-
|
|
2
|
-
import { i as b } from "./internal/index-
|
|
1
|
+
import { B as n, h as u, g as x, p as f, z as l } from "./internal/object-19968a54.js";
|
|
2
|
+
import { i as b } from "./internal/index-af4b7a66.js";
|
|
3
3
|
import "json-stringify-deterministic";
|
|
4
4
|
import "immer";
|
|
5
5
|
import "zod";
|
package/dist/node/index.cjs
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-6ee6330b.js"),o=require("./internal/index-574ece31.js");require("./internal/object-9fcc9b3e.js");require("json-stringify-deterministic");require("immer");require("zod");require("crypto");require("fs");require("https");require("path");require("jszip");const u={"powerhouse/document":e.Document,"powerhouse/document-model":o.DocumentModel},r={Document:e.Document,DocumentModel:o.DocumentModel};exports.Document=e.Document;exports.DocumentModel=o.DocumentModel;exports.DocumentModels=u;exports.default=r;
|
package/dist/node/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-af4b7a66.js";
|
|
2
|
+
import { D as t } from "./internal/index-f3fdeced.js";
|
|
3
|
+
import "./internal/object-19968a54.js";
|
|
4
4
|
import "json-stringify-deterministic";
|
|
5
5
|
import "immer";
|
|
6
6
|
import "zod";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var ct=Object.defineProperty;var lt=(t,e,o)=>e in t?ct(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o;var de=(t,e,o)=>(lt(t,typeof e!="symbol"?e+"":e,o),o);const s=require("./object-
|
|
1
|
+
"use strict";var ct=Object.defineProperty;var lt=(t,e,o)=>e in t?ct(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o;var de=(t,e,o)=>(lt(t,typeof e!="symbol"?e+"":e,o),o);const s=require("./object-9fcc9b3e.js");require("json-stringify-deterministic");require("immer");require("crypto");require("fs");require("https");require("path");require("jszip");const r=require("zod"),dt=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"})),_={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:[]},{name:"SetModelId",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetModelExtension",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetModelDescription",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetAuthorName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetAuthorWebsite",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]}],id:"",description:""},{name:"versioning",operations:[{name:"AddChangeLogItem",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"UpdateChangeLogItem",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"DeleteChangeLogItem",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"ReorderChangeLogItems",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"ReleaseNewVersion",schema:null,id:"",description:"",template:"",reducer:"",examples:[],errors:[]}],id:"",description:""},{name:"module",operations:[{name:"AddModule",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetModuleName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetModuleDescription",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"DeleteModule",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"ReorderModules",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]}],id:"",description:""},{name:"operation-error",operations:[{name:"AddOperationError",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetOperationErrorCode",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetOperationErrorName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetOperationErrorDescription",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetOperationErrorTemplate",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"DeleteOperationError",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"ReorderOperationErrors",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]}],id:"",description:""},{name:"operation-example",operations:[{name:"AddOperationExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"UpdateOperationExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"DeleteOperationExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"ReorderOperationExamples",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]}],id:"",description:""},{name:"operation",operations:[{name:"AddOperation",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetOperationName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetOperationSchema",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetOperationDescription",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetOperationTemplate",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetOperationReducer",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"MoveOperation",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"DeleteOperation",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"ReorderModuleOperations",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]}],id:"",description:""},{name:"state",operations:[{name:"SetStateSchema",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetInitialState",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"AddStateExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"UpdateStateExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"DeleteStateExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"ReorderStateExamples",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]}],id:"",description:""}],state:{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-9fcc9b3e.js"),t=Object.freeze(Object.defineProperty({__proto__:null,createAction:e.createAction,createDocument:e.createDocument,createExtendedState:e.createExtendedState,createReducer:e.createReducer,createZip:e.createZip,getLocalFile:e.getLocalFile,getRemoteFile:e.getRemoteFile,hashDocument:e.hashDocument,hashKey:e.hashKey,isBaseAction:e.isBaseAction,loadFromFile:e.loadFromFile,loadFromInput:e.loadFromInput,saveToFile:e.saveToFile,saveToFileHandle:e.saveToFileHandle},Symbol.toStringTag,{value:"Module"})),o=Object.freeze(Object.defineProperty({__proto__:null,BaseDocument:e.BaseDocument,actions:e.BaseActions,applyMixins:e.applyMixins,baseReducer:e.baseReducer,utils:t,z:e.zod},Symbol.toStringTag,{value:"Module"}));exports.Document=o;exports.index=t;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { f as e, b as a, a as s, c as t, j as o, k as c, m as i, n as l, o as n, i as r, l as d, e as u, s as m, d as p, B as b, h as _, g, p as F, z as f } from "./object-
|
|
1
|
+
import { f as e, b as a, a as s, c as t, j as o, k as c, m as i, n as l, o as n, i as r, l as d, e as u, s as m, d as p, B as b, h as _, g, p as F, z as f } from "./object-19968a54.js";
|
|
2
2
|
const y = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
3
3
|
__proto__: null,
|
|
4
4
|
createAction: e,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var pt = Object.defineProperty;
|
|
2
2
|
var lt = (t, e, i) => e in t ? pt(t, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : t[e] = i;
|
|
3
3
|
var pe = (t, e, i) => (lt(t, typeof e != "symbol" ? e + "" : e, i), i);
|
|
4
|
-
import { c as dt, i as ct, a as ut, b as mt, s as Et, d as ht, l as Ot, e as St, f as s, B as l, g as gt, h as ft } from "./object-
|
|
4
|
+
import { c as dt, i as ct, a as ut, b as mt, s as Et, d as ht, l as Ot, e as St, f as s, B as l, g as gt, h as ft } from "./object-19968a54.js";
|
|
5
5
|
import "json-stringify-deterministic";
|
|
6
6
|
import "immer";
|
|
7
7
|
import "crypto";
|
|
@@ -2,7 +2,7 @@ var X = Object.defineProperty;
|
|
|
2
2
|
var Y = (t, i, e) => i in t ? X(t, i, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[i] = e;
|
|
3
3
|
var y = (t, i, e) => (Y(t, typeof i != "symbol" ? i + "" : i, e), e);
|
|
4
4
|
import tt from "json-stringify-deterministic";
|
|
5
|
-
import { produce as
|
|
5
|
+
import { produce as E, castDraft as it } from "immer";
|
|
6
6
|
import { z as o } from "zod";
|
|
7
7
|
import et from "crypto";
|
|
8
8
|
import b from "fs";
|
|
@@ -340,7 +340,7 @@ function Ot(t, i, e, a) {
|
|
|
340
340
|
t.initialState,
|
|
341
341
|
[
|
|
342
342
|
...s,
|
|
343
|
-
|
|
343
|
+
D({ name: m, state: c }, n.length),
|
|
344
344
|
...p
|
|
345
345
|
],
|
|
346
346
|
a
|
|
@@ -354,13 +354,13 @@ function kt(t, i) {
|
|
|
354
354
|
};
|
|
355
355
|
}
|
|
356
356
|
const Z = "SET_NAME", h = "UNDO", v = "REDO", d = "PRUNE", H = "LOAD_STATE";
|
|
357
|
-
function
|
|
357
|
+
function Dt(t, i) {
|
|
358
358
|
return [h, v, d].includes(i.type) ? t.revision : t.revision + 1;
|
|
359
359
|
}
|
|
360
|
-
function
|
|
360
|
+
function Et(t, i) {
|
|
361
361
|
return {
|
|
362
362
|
...t,
|
|
363
|
-
revision:
|
|
363
|
+
revision: Dt(t, i),
|
|
364
364
|
lastModified: (/* @__PURE__ */ new Date()).toISOString()
|
|
365
365
|
};
|
|
366
366
|
}
|
|
@@ -383,7 +383,7 @@ function Nt(t, i) {
|
|
|
383
383
|
}
|
|
384
384
|
function At(t, i) {
|
|
385
385
|
let e = Nt(t, i);
|
|
386
|
-
return e =
|
|
386
|
+
return e = Et(e, i), e;
|
|
387
387
|
}
|
|
388
388
|
function Tt(t, i, e) {
|
|
389
389
|
switch (R().parse(i), i.type) {
|
|
@@ -408,14 +408,14 @@ function Tt(t, i, e) {
|
|
|
408
408
|
}
|
|
409
409
|
function zt(t, i, e) {
|
|
410
410
|
let a = t;
|
|
411
|
-
return A(i) && (a = Tt(a, i, e)), a = At(a, i), a =
|
|
411
|
+
return A(i) && (a = Tt(a, i, e)), a = At(a, i), a = E(a, (n) => {
|
|
412
412
|
const s = e(n.state, i);
|
|
413
413
|
if (s)
|
|
414
414
|
return it({
|
|
415
415
|
...a,
|
|
416
416
|
state: s
|
|
417
417
|
});
|
|
418
|
-
}),
|
|
418
|
+
}), E(a, (n) => {
|
|
419
419
|
n.operations[n.operations.length - 1].hash = Mt(n), !A(i) && i.attachments && i.attachments.forEach((s) => {
|
|
420
420
|
const { hash: p, ...l } = s;
|
|
421
421
|
n.attachments[p] = {
|
|
@@ -470,14 +470,14 @@ const Pt = (t, i) => ({
|
|
|
470
470
|
{ start: t, end: i },
|
|
471
471
|
void 0,
|
|
472
472
|
S
|
|
473
|
-
),
|
|
473
|
+
), D = (t, i) => u(
|
|
474
474
|
"LOAD_STATE",
|
|
475
475
|
{ state: t, operations: i },
|
|
476
476
|
void 0,
|
|
477
477
|
w
|
|
478
478
|
), Vt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
479
479
|
__proto__: null,
|
|
480
|
-
loadState:
|
|
480
|
+
loadState: D,
|
|
481
481
|
prune: Q,
|
|
482
482
|
redo: G,
|
|
483
483
|
setName: K,
|
|
@@ -575,6 +575,12 @@ class Xt {
|
|
|
575
575
|
get initialState() {
|
|
576
576
|
return this._document.initialState;
|
|
577
577
|
}
|
|
578
|
+
/**
|
|
579
|
+
* Returns the current document as an object
|
|
580
|
+
*/
|
|
581
|
+
toDocument() {
|
|
582
|
+
return this._document;
|
|
583
|
+
}
|
|
578
584
|
/**
|
|
579
585
|
* Gets the attachment associated with the given key.
|
|
580
586
|
* @param attachment - The key of the attachment to retrieve.
|
|
@@ -617,7 +623,7 @@ class Xt {
|
|
|
617
623
|
* @param operations - The operations to apply to the document.
|
|
618
624
|
*/
|
|
619
625
|
loadState(i, e) {
|
|
620
|
-
return this.dispatch(
|
|
626
|
+
return this.dispatch(D(i, e)), this;
|
|
621
627
|
}
|
|
622
628
|
}
|
|
623
629
|
function Yt(t, i) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var ot=Object.defineProperty;var st=(t,e,i)=>e in t?ot(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i;var b=(t,e,i)=>(st(t,typeof e!="symbol"?e+"":e,i),i);const pt=require("json-stringify-deterministic"),j=require("immer"),o=require("zod"),ct=require("crypto"),w=require("fs"),lt=require("https"),rt=require("path"),T=require("jszip"),F=t=>t!=null,mt=o.z.any().refine(t=>F(t)),q=o.z.enum(["LOAD_STATE"]),P=o.z.enum(["PRUNE"]),M=o.z.enum(["REDO"]),R=o.z.enum(["SET_NAME"]),L=o.z.enum(["UNDO"]);function ut(){return o.z.object({__typename:o.z.literal("Action").optional(),type:o.z.string()})}function I(){return o.z.union([_(),O(),k(),D(),E()])}function dt(){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 _(){return o.z.object({input:o.z.lazy(()=>U()),type:q})}function U(){return o.z.object({operations:o.z.number(),state:o.z.lazy(()=>J())})}function J(){return o.z.object({data:o.z.unknown().nullish(),name:o.z.string()})}function xt(){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 O(){return o.z.object({input:o.z.lazy(()=>B()),type:P})}function B(){return o.z.object({end:o.z.number().nullish(),start:o.z.number().nullish()})}function k(){return o.z.object({input:o.z.number(),type:M})}function D(){return o.z.object({input:o.z.string(),type:R})}function ft(){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()})}function E(){return o.z.object({input:o.z.number(),type:L})}const gt=Object.freeze(Object.defineProperty({__proto__:null,ActionSchema:ut,BaseActionSchema:I,DocumentFileSchema:dt,LoadStateActionInputSchema:U,LoadStateActionSchema:_,LoadStateActionStateInputSchema:J,Load_StateSchema:q,OperationSchema:xt,PruneActionInputSchema:B,PruneActionSchema:O,PruneSchema:P,RedoActionSchema:k,RedoSchema:M,SetNameActionSchema:D,SetNameOperationSchema:ft,Set_NameSchema:R,UndoActionSchema:E,UndoSchema:L,definedNonNullAnySchema:mt,isDefinedNonNullAny:F},Symbol.toStringTag,{value:"Module"}));function ht(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function f(){this._types=Object.create(null),this._extensions=Object.create(null);for(let t=0;t<arguments.length;t++)this.define(arguments[t]);this.define=this.define.bind(this),this.getType=this.getType.bind(this),this.getExtension=this.getExtension.bind(this)}f.prototype.define=function(t,e){for(let i in t){let a=t[i].map(function(n){return n.toLowerCase()});i=i.toLowerCase();for(let n=0;n<a.length;n++){const s=a[n];if(s[0]!=="*"){if(!e&&s in this._types)throw new Error('Attempt to change mapping for "'+s+'" extension from "'+this._types[s]+'" to "'+i+'". Pass `force=true` to allow this, otherwise remove "'+s+'" from the list of extensions for "'+i+'".');this._types[s]=i}}if(e||!this._extensions[i]){const n=a[0];this._extensions[i]=n[0]!=="*"?n:n.substr(1)}}};f.prototype.getType=function(t){t=String(t);let e=t.replace(/^.*[/\\]/,"").toLowerCase(),i=e.replace(/^.*\./,"").toLowerCase(),a=e.length<t.length;return(i.length<e.length-1||!a)&&this._types[i]||null};f.prototype.getExtension=function(t){return t=/^\s*([^;\s]*)/.test(t)&&RegExp.$1,t&&this._extensions[t.toLowerCase()]||null};var vt=f,yt={"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 bt=vt;var jt=new bt(yt);const wt=ht(jt);function zt(t,e,i){const a=rt.join(t,e);return w.mkdirSync(t,{recursive:!0}),new Promise((n,s)=>{try{w.writeFile(a,i,{},p=>{p?s(p):n(a)})}catch(p){s(p)}})}function C(t){return w.readFileSync(t)}function St(t){return new Promise((e,i)=>{lt.get(t,a=>{const n=[],s=a.headers["content-type"];a.on("data",p=>{n.push(p)}),a.on("end",()=>{e({buffer:Buffer.concat(n),mimeType:s})})}).on("error",a=>{i(a)})})}const _t=async t=>C(t),g=(t,e="sha1")=>ct.createHash(e).update(t).digest("base64"),A=async t=>{const e=new T,{name:i,revision:a,documentType:n,created:s,lastModified:p}=t,c={name:i,revision:a,documentType:n,created:s,lastModified:p};return e.file("header.json",JSON.stringify(c,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(l=>{const{data:r,...y}=t.attachments[l];e.file(l,r,{base64:!0,createFolders:!0,comment:JSON.stringify(y)})}),e},$=async(t,e,i,a)=>{const s=await(await A(t)).generateAsync({type:"uint8array",streamFiles:!0}),p=a??t.name,c=`.${i}.zip`;return zt(e,p.endsWith(c)?p:`${p}${c}`,s)},Ot=async(t,e)=>{const a=await(await A(t)).generateAsync({type:"blob"}),n=await e.createWritable();await n.write(a),await n.close()},z=async(t,e)=>{const i=C(t);return Z(i,e)},Z=async(t,e)=>{const i=new T;return await i.loadAsync(t),kt(i,e)};async function kt(t,e){const i=t.file("state.json");if(!i)throw new Error("Initial state not found");const a=await i.async("string"),n=JSON.parse(a),s=t.file("header.json");let p=null;s&&(p=JSON.parse(await s.async("string")));const c=t.file("operations.json");if(!c)throw new Error("Operations history not found");const u=JSON.parse(await c.async("string")),l={...n,...p,initialState:n,operations:[],attachments:{...n.attachments}};let r=u.slice(0,p==null?void 0:p.revision).reduce((y,nt)=>e(y,nt),l);return p&&(r={...r,...p,operations:[...r.operations,...u.slice(p.revision)]}),r}function H(t){const e=t.replace(/^.*\./,"")||void 0,i=t.replace(/^.*[/\\]/,"")||void 0;return{extension:e,fileName:i}}async function Dt(t){const{buffer:e,mimeType:i="application/octet-stream"}=await St(t),a=H(t),n=e.toString("base64");return{data:n,hash:g(n),mimeType:i,...a}}async function Et(t){const e=await _t(t),i=wt.getType(t)||"application/octet-stream",a=H(t),n=e.toString("base64");return{data:n,hash:g(n),mimeType:i,...a}}function x(t,e,i){const a=X(t),n=Q(i);return e.reduce((s,p)=>n(s,p),a)}function At(t,e){return{...t,name:e}}function Nt(t,e,i){const a=Math.min(e,t.revision),n=t.operations.slice(0,t.revision-a);return{...x(t.initialState,n,i),operations:t.operations,revision:t.revision-a}}function Tt(t,e,i){const a=t.operations.length-t.revision;if(!a)throw new Error("There is no UNDO operation to REDO");const n=e<a?e:a,s=t.operations.slice(0,t.revision+n);return{...x(t.initialState,s,i),operations:t.operations,revision:t.revision+n}}function Ft(t,e,i,a){e=e||0,i=i||t.operations.length;const n=t.operations.slice(e,i),s=t.operations.slice(0,e),p=t.operations.slice(i),c=x(t.initialState,s.concat(n),a),{name:u,state:l}=c;return x(t.initialState,[...s,N({name:u,state:l},n.length),...p],a)}function qt(t,e){return{...t,name:e.name,state:e.state??{}}}const K="SET_NAME",h="UNDO",v="REDO",d="PRUNE",W="LOAD_STATE";function Pt(t,e){return[h,v,d].includes(e.type)?t.revision:t.revision+1}function Mt(t,e){return{...t,revision:Pt(t,e),lastModified:new Date().toISOString()}}function Rt(t,e){if([h,v,d,d].includes(e.type))return t;const i=t.operations.slice(0,t.revision);return{...t,operations:[...i,{...e,index:i.length,timestamp:new Date().toISOString(),hash:""}]}}function Lt(t,e){let i=Rt(t,e);return i=Mt(i,e),i}function It(t,e,i){switch(I().parse(e),e.type){case K:return At(t,e.input);case h:return Nt(t,e.input,i);case v:return Tt(t,e.input,i);case d:return Ft(t,e.input.start,e.input.end,i);case W:return qt(t,e.input.state);default:return t}}function G(t,e,i){let a=t;return S(e)&&(a=It(a,e,i)),a=Lt(a,e),a=j.produce(a,n=>{const s=i(n.state,e);if(s)return j.castDraft({...a,state:s})}),j.produce(a,n=>{n.operations[n.operations.length-1].hash=Y(n),!S(e)&&e.attachments&&e.attachments.forEach(s=>{const{hash:p,...c}=s;n.attachments[p]={...c}})})}function S(t){return[K,h,v,d,W].includes(t.type)}function m(t,e,i,a){if(!t)throw new Error("Empty action type");if(typeof t!="string")throw new Error(`Invalid action type: ${t}`);const n=i?{type:t,input:e,attachments:i}:{type:t,input:e};return a==null||a().parse(n),n}function Q(t,e=G){return(i,a)=>e(i,a,t)}const V=(t,e)=>({name:"",documentType:"",revision: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)??{}}),X=(t,e)=>{const i=V(t,e);return{...i,initialState:i,operations:[]}},Y=t=>g(pt(t.state)),Ut=(t,e=1e3)=>{const i=Math.random()*e;return g(`${(t??new Date).toISOString()}${i}`)},tt=t=>m("SET_NAME",t,void 0,D),et=(t=1)=>m("UNDO",t,void 0,E),it=(t=1)=>m("REDO",t,void 0,k),at=(t,e)=>m("PRUNE",{start:t,end:e},void 0,O),N=(t,e)=>m("LOAD_STATE",{state:t,operations:e},void 0,_),Jt=Object.freeze(Object.defineProperty({__proto__:null,loadState:N,prune:at,redo:it,setName:tt,undo:et},Symbol.toStringTag,{value:"Module"}));class Bt{constructor(e,i){b(this,"_document");b(this,"_reducer");this._reducer=e,this._document=i}dispatch(e){return this._document=this._reducer(this._document,e),this}saveToFile(e,i,a){return $(this._document,e,i,a)}async loadFromFile(e){this._document=await z(e,this._reducer)}static async stateFromFile(e,i){return await z(e,i)}get state(){return this._document.state}get operations(){return this._document.operations}get name(){return this._document.name}get documentType(){return this._document.documentType}get created(){return this._document.created}get lastModified(){return this._document.lastModified}get revision(){return this._document.revision}get initialState(){return this._document.initialState}getAttachment(e){return this._document.attachments[e]}setName(e){return this.dispatch(tt(e)),this}undo(e){return this.dispatch(et(e)),this}redo(e){return this.dispatch(it(e)),this}prune(e,i){return this.dispatch(at(e,i)),this}loadState(e,i){return this.dispatch(N(e,i)),this}}function Ct(t,e){e.forEach(i=>{Object.getOwnPropertyNames(i.prototype).forEach(a=>{Object.defineProperty(t.prototype,a,Object.getOwnPropertyDescriptor(i.prototype,a)||Object.create(null))})})}exports.BaseActions=Jt;exports.BaseDocument=Bt;exports.applyMixins=Ct;exports.baseReducer=G;exports.createAction=m;exports.createDocument=X;exports.createExtendedState=V;exports.createReducer=Q;exports.createZip=A;exports.getLocalFile=Et;exports.getRemoteFile=Dt;exports.hashDocument=Y;exports.hashKey=Ut;exports.isBaseAction=S;exports.loadFromFile=z;exports.loadFromInput=Z;exports.saveToFile=$;exports.saveToFileHandle=Ot;exports.zod=gt;
|
|
1
|
+
"use strict";var ot=Object.defineProperty;var st=(t,e,i)=>e in t?ot(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i;var b=(t,e,i)=>(st(t,typeof e!="symbol"?e+"":e,i),i);const pt=require("json-stringify-deterministic"),j=require("immer"),o=require("zod"),ct=require("crypto"),w=require("fs"),lt=require("https"),rt=require("path"),T=require("jszip"),F=t=>t!=null,mt=o.z.any().refine(t=>F(t)),q=o.z.enum(["LOAD_STATE"]),P=o.z.enum(["PRUNE"]),M=o.z.enum(["REDO"]),R=o.z.enum(["SET_NAME"]),L=o.z.enum(["UNDO"]);function ut(){return o.z.object({__typename:o.z.literal("Action").optional(),type:o.z.string()})}function I(){return o.z.union([_(),O(),D(),k(),E()])}function dt(){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 _(){return o.z.object({input:o.z.lazy(()=>U()),type:q})}function U(){return o.z.object({operations:o.z.number(),state:o.z.lazy(()=>J())})}function J(){return o.z.object({data:o.z.unknown().nullish(),name:o.z.string()})}function xt(){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 O(){return o.z.object({input:o.z.lazy(()=>B()),type:P})}function B(){return o.z.object({end:o.z.number().nullish(),start:o.z.number().nullish()})}function D(){return o.z.object({input:o.z.number(),type:M})}function k(){return o.z.object({input:o.z.string(),type:R})}function ft(){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()})}function E(){return o.z.object({input:o.z.number(),type:L})}const gt=Object.freeze(Object.defineProperty({__proto__:null,ActionSchema:ut,BaseActionSchema:I,DocumentFileSchema:dt,LoadStateActionInputSchema:U,LoadStateActionSchema:_,LoadStateActionStateInputSchema:J,Load_StateSchema:q,OperationSchema:xt,PruneActionInputSchema:B,PruneActionSchema:O,PruneSchema:P,RedoActionSchema:D,RedoSchema:M,SetNameActionSchema:k,SetNameOperationSchema:ft,Set_NameSchema:R,UndoActionSchema:E,UndoSchema:L,definedNonNullAnySchema:mt,isDefinedNonNullAny:F},Symbol.toStringTag,{value:"Module"}));function ht(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function f(){this._types=Object.create(null),this._extensions=Object.create(null);for(let t=0;t<arguments.length;t++)this.define(arguments[t]);this.define=this.define.bind(this),this.getType=this.getType.bind(this),this.getExtension=this.getExtension.bind(this)}f.prototype.define=function(t,e){for(let i in t){let a=t[i].map(function(n){return n.toLowerCase()});i=i.toLowerCase();for(let n=0;n<a.length;n++){const s=a[n];if(s[0]!=="*"){if(!e&&s in this._types)throw new Error('Attempt to change mapping for "'+s+'" extension from "'+this._types[s]+'" to "'+i+'". Pass `force=true` to allow this, otherwise remove "'+s+'" from the list of extensions for "'+i+'".');this._types[s]=i}}if(e||!this._extensions[i]){const n=a[0];this._extensions[i]=n[0]!=="*"?n:n.substr(1)}}};f.prototype.getType=function(t){t=String(t);let e=t.replace(/^.*[/\\]/,"").toLowerCase(),i=e.replace(/^.*\./,"").toLowerCase(),a=e.length<t.length;return(i.length<e.length-1||!a)&&this._types[i]||null};f.prototype.getExtension=function(t){return t=/^\s*([^;\s]*)/.test(t)&&RegExp.$1,t&&this._extensions[t.toLowerCase()]||null};var vt=f,yt={"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 bt=vt;var jt=new bt(yt);const wt=ht(jt);function zt(t,e,i){const a=rt.join(t,e);return w.mkdirSync(t,{recursive:!0}),new Promise((n,s)=>{try{w.writeFile(a,i,{},p=>{p?s(p):n(a)})}catch(p){s(p)}})}function C(t){return w.readFileSync(t)}function St(t){return new Promise((e,i)=>{lt.get(t,a=>{const n=[],s=a.headers["content-type"];a.on("data",p=>{n.push(p)}),a.on("end",()=>{e({buffer:Buffer.concat(n),mimeType:s})})}).on("error",a=>{i(a)})})}const _t=async t=>C(t),g=(t,e="sha1")=>ct.createHash(e).update(t).digest("base64"),A=async t=>{const e=new T,{name:i,revision:a,documentType:n,created:s,lastModified:p}=t,c={name:i,revision:a,documentType:n,created:s,lastModified:p};return e.file("header.json",JSON.stringify(c,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(l=>{const{data:r,...y}=t.attachments[l];e.file(l,r,{base64:!0,createFolders:!0,comment:JSON.stringify(y)})}),e},$=async(t,e,i,a)=>{const s=await(await A(t)).generateAsync({type:"uint8array",streamFiles:!0}),p=a??t.name,c=`.${i}.zip`;return zt(e,p.endsWith(c)?p:`${p}${c}`,s)},Ot=async(t,e)=>{const a=await(await A(t)).generateAsync({type:"blob"}),n=await e.createWritable();await n.write(a),await n.close()},z=async(t,e)=>{const i=C(t);return Z(i,e)},Z=async(t,e)=>{const i=new T;return await i.loadAsync(t),Dt(i,e)};async function Dt(t,e){const i=t.file("state.json");if(!i)throw new Error("Initial state not found");const a=await i.async("string"),n=JSON.parse(a),s=t.file("header.json");let p=null;s&&(p=JSON.parse(await s.async("string")));const c=t.file("operations.json");if(!c)throw new Error("Operations history not found");const u=JSON.parse(await c.async("string")),l={...n,...p,initialState:n,operations:[],attachments:{...n.attachments}};let r=u.slice(0,p==null?void 0:p.revision).reduce((y,nt)=>e(y,nt),l);return p&&(r={...r,...p,operations:[...r.operations,...u.slice(p.revision)]}),r}function H(t){const e=t.replace(/^.*\./,"")||void 0,i=t.replace(/^.*[/\\]/,"")||void 0;return{extension:e,fileName:i}}async function kt(t){const{buffer:e,mimeType:i="application/octet-stream"}=await St(t),a=H(t),n=e.toString("base64");return{data:n,hash:g(n),mimeType:i,...a}}async function Et(t){const e=await _t(t),i=wt.getType(t)||"application/octet-stream",a=H(t),n=e.toString("base64");return{data:n,hash:g(n),mimeType:i,...a}}function x(t,e,i){const a=X(t),n=Q(i);return e.reduce((s,p)=>n(s,p),a)}function At(t,e){return{...t,name:e}}function Nt(t,e,i){const a=Math.min(e,t.revision),n=t.operations.slice(0,t.revision-a);return{...x(t.initialState,n,i),operations:t.operations,revision:t.revision-a}}function Tt(t,e,i){const a=t.operations.length-t.revision;if(!a)throw new Error("There is no UNDO operation to REDO");const n=e<a?e:a,s=t.operations.slice(0,t.revision+n);return{...x(t.initialState,s,i),operations:t.operations,revision:t.revision+n}}function Ft(t,e,i,a){e=e||0,i=i||t.operations.length;const n=t.operations.slice(e,i),s=t.operations.slice(0,e),p=t.operations.slice(i),c=x(t.initialState,s.concat(n),a),{name:u,state:l}=c;return x(t.initialState,[...s,N({name:u,state:l},n.length),...p],a)}function qt(t,e){return{...t,name:e.name,state:e.state??{}}}const K="SET_NAME",h="UNDO",v="REDO",d="PRUNE",W="LOAD_STATE";function Pt(t,e){return[h,v,d].includes(e.type)?t.revision:t.revision+1}function Mt(t,e){return{...t,revision:Pt(t,e),lastModified:new Date().toISOString()}}function Rt(t,e){if([h,v,d,d].includes(e.type))return t;const i=t.operations.slice(0,t.revision);return{...t,operations:[...i,{...e,index:i.length,timestamp:new Date().toISOString(),hash:""}]}}function Lt(t,e){let i=Rt(t,e);return i=Mt(i,e),i}function It(t,e,i){switch(I().parse(e),e.type){case K:return At(t,e.input);case h:return Nt(t,e.input,i);case v:return Tt(t,e.input,i);case d:return Ft(t,e.input.start,e.input.end,i);case W:return qt(t,e.input.state);default:return t}}function G(t,e,i){let a=t;return S(e)&&(a=It(a,e,i)),a=Lt(a,e),a=j.produce(a,n=>{const s=i(n.state,e);if(s)return j.castDraft({...a,state:s})}),j.produce(a,n=>{n.operations[n.operations.length-1].hash=Y(n),!S(e)&&e.attachments&&e.attachments.forEach(s=>{const{hash:p,...c}=s;n.attachments[p]={...c}})})}function S(t){return[K,h,v,d,W].includes(t.type)}function m(t,e,i,a){if(!t)throw new Error("Empty action type");if(typeof t!="string")throw new Error(`Invalid action type: ${t}`);const n=i?{type:t,input:e,attachments:i}:{type:t,input:e};return a==null||a().parse(n),n}function Q(t,e=G){return(i,a)=>e(i,a,t)}const V=(t,e)=>({name:"",documentType:"",revision: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)??{}}),X=(t,e)=>{const i=V(t,e);return{...i,initialState:i,operations:[]}},Y=t=>g(pt(t.state)),Ut=(t,e=1e3)=>{const i=Math.random()*e;return g(`${(t??new Date).toISOString()}${i}`)},tt=t=>m("SET_NAME",t,void 0,k),et=(t=1)=>m("UNDO",t,void 0,E),it=(t=1)=>m("REDO",t,void 0,D),at=(t,e)=>m("PRUNE",{start:t,end:e},void 0,O),N=(t,e)=>m("LOAD_STATE",{state:t,operations:e},void 0,_),Jt=Object.freeze(Object.defineProperty({__proto__:null,loadState:N,prune:at,redo:it,setName:tt,undo:et},Symbol.toStringTag,{value:"Module"}));class Bt{constructor(e,i){b(this,"_document");b(this,"_reducer");this._reducer=e,this._document=i}dispatch(e){return this._document=this._reducer(this._document,e),this}saveToFile(e,i,a){return $(this._document,e,i,a)}async loadFromFile(e){this._document=await z(e,this._reducer)}static async stateFromFile(e,i){return await z(e,i)}get state(){return this._document.state}get operations(){return this._document.operations}get name(){return this._document.name}get documentType(){return this._document.documentType}get created(){return this._document.created}get lastModified(){return this._document.lastModified}get revision(){return this._document.revision}get initialState(){return this._document.initialState}toDocument(){return this._document}getAttachment(e){return this._document.attachments[e]}setName(e){return this.dispatch(tt(e)),this}undo(e){return this.dispatch(et(e)),this}redo(e){return this.dispatch(it(e)),this}prune(e,i){return this.dispatch(at(e,i)),this}loadState(e,i){return this.dispatch(N(e,i)),this}}function Ct(t,e){e.forEach(i=>{Object.getOwnPropertyNames(i.prototype).forEach(a=>{Object.defineProperty(t.prototype,a,Object.getOwnPropertyDescriptor(i.prototype,a)||Object.create(null))})})}exports.BaseActions=Jt;exports.BaseDocument=Bt;exports.applyMixins=Ct;exports.baseReducer=G;exports.createAction=m;exports.createDocument=X;exports.createExtendedState=V;exports.createReducer=Q;exports.createZip=A;exports.getLocalFile=Et;exports.getRemoteFile=kt;exports.hashDocument=Y;exports.hashKey=Ut;exports.isBaseAction=S;exports.loadFromFile=z;exports.loadFromInput=Z;exports.saveToFile=$;exports.saveToFileHandle=Ot;exports.zod=gt;
|