document-model 1.1.0-experimental.3 → 1.1.0-experimental.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/dist/browser/cjs/document-model.js +1 -1
  3. package/dist/browser/cjs/document.js +1 -1
  4. package/dist/browser/cjs/index.js +1 -1
  5. package/dist/browser/cjs/internal/{index-DMRH7zDy.js → index-BLpgsifL.js} +1 -1
  6. package/dist/browser/cjs/internal/{index-dwAOfmBp.js → index-BTG_-qY6.js} +1 -1
  7. package/dist/browser/cjs/internal/object-BHB7lY3H.js +25 -0
  8. package/dist/browser/es/document-model.js +2 -2
  9. package/dist/browser/es/document.js +9 -7
  10. package/dist/browser/es/index.js +3 -3
  11. package/dist/browser/es/internal/index-2Qq00NLA.js +46 -0
  12. package/dist/browser/es/internal/{index-DQztOVJu.js → index-BD2hB9El.js} +1 -1
  13. package/dist/browser/es/internal/{object-iTBekDVP.js → object-BW-G4r5m.js} +733 -735
  14. package/dist/browser/src/document/reducer.d.ts +17 -0
  15. package/dist/node/cjs/document-model.js +1 -1
  16. package/dist/node/cjs/document.js +1 -1
  17. package/dist/node/cjs/index.js +1 -1
  18. package/dist/node/cjs/internal/{index-FvRO8SnG.js → index-B31DqWHj.js} +1 -1
  19. package/dist/node/cjs/internal/{index-BNFVmPew.js → index-BBm_wnUa.js} +1 -1
  20. package/dist/node/cjs/internal/{object-Xvr4kDQj.js → object-CxVzP-Xe.js} +17 -17
  21. package/dist/node/es/document-model.js +2 -2
  22. package/dist/node/es/document.js +10 -8
  23. package/dist/node/es/index.js +3 -3
  24. package/dist/node/es/internal/{index-DOpbr_uw.js → index-BPCSW4M1.js} +1 -1
  25. package/dist/node/es/internal/index-C7I4OGkU.js +46 -0
  26. package/dist/node/es/internal/{object-C2s2eZ08.js → object-C-_SkpQ0.js} +516 -518
  27. package/dist/node/src/document/reducer.d.ts +17 -0
  28. package/dist/src/document/actions/creators.d.ts +47 -0
  29. package/dist/src/document/actions/index.d.ts +14 -0
  30. package/dist/src/document/actions/types.d.ts +15 -0
  31. package/dist/src/document/index.d.ts +6 -0
  32. package/dist/src/document/object.d.ts +1210 -0
  33. package/dist/src/document/reducer.d.ts +60 -0
  34. package/dist/src/document/schema/index.d.ts +2 -0
  35. package/dist/src/document/schema/types.d.ts +176 -0
  36. package/dist/src/document/schema/zod.d.ts +113 -0
  37. package/dist/src/document/signal.d.ts +29 -0
  38. package/dist/src/document/types.d.ts +255 -0
  39. package/dist/src/document/utils/base.d.ts +86 -0
  40. package/dist/src/document/utils/document-helpers.d.ts +53 -0
  41. package/dist/src/document/utils/file.d.ts +48 -0
  42. package/dist/src/document/utils/index.d.ts +5 -0
  43. package/dist/src/document/utils/node.d.ts +9 -0
  44. package/dist/src/document/utils/validation.d.ts +2 -0
  45. package/dist/src/document-model/custom/reducers/header.d.ts +2 -0
  46. package/dist/src/document-model/custom/reducers/module.d.ts +2 -0
  47. package/dist/src/document-model/custom/reducers/operation-error.d.ts +2 -0
  48. package/dist/src/document-model/custom/reducers/operation-example.d.ts +2 -0
  49. package/dist/src/document-model/custom/reducers/operation.d.ts +2 -0
  50. package/dist/src/document-model/custom/reducers/state.d.ts +2 -0
  51. package/dist/src/document-model/custom/reducers/versioning.d.ts +7 -0
  52. package/dist/src/document-model/custom/utils.d.ts +7 -0
  53. package/dist/src/document-model/gen/actions.d.ts +15 -0
  54. package/dist/src/document-model/gen/creators.d.ts +7 -0
  55. package/dist/src/document-model/gen/document-model.d.ts +2 -0
  56. package/dist/src/document-model/gen/header/actions.d.ts +9 -0
  57. package/dist/src/document-model/gen/header/creators.d.ts +8 -0
  58. package/dist/src/document-model/gen/header/object.d.ts +12 -0
  59. package/dist/src/document-model/gen/header/operations.d.ts +10 -0
  60. package/dist/src/document-model/gen/index.d.ts +5 -0
  61. package/dist/src/document-model/gen/module/actions.d.ts +8 -0
  62. package/dist/src/document-model/gen/module/creators.d.ts +7 -0
  63. package/dist/src/document-model/gen/module/object.d.ts +11 -0
  64. package/dist/src/document-model/gen/module/operations.d.ts +9 -0
  65. package/dist/src/document-model/gen/object.d.ts +28 -0
  66. package/dist/src/document-model/gen/operation/actions.d.ts +13 -0
  67. package/dist/src/document-model/gen/operation/creators.d.ts +12 -0
  68. package/dist/src/document-model/gen/operation/object.d.ts +16 -0
  69. package/dist/src/document-model/gen/operation/operations.d.ts +14 -0
  70. package/dist/src/document-model/gen/operation-error/actions.d.ts +10 -0
  71. package/dist/src/document-model/gen/operation-error/creators.d.ts +9 -0
  72. package/dist/src/document-model/gen/operation-error/object.d.ts +13 -0
  73. package/dist/src/document-model/gen/operation-error/operations.d.ts +11 -0
  74. package/dist/src/document-model/gen/operation-example/actions.d.ts +7 -0
  75. package/dist/src/document-model/gen/operation-example/creators.d.ts +6 -0
  76. package/dist/src/document-model/gen/operation-example/object.d.ts +10 -0
  77. package/dist/src/document-model/gen/operation-example/operations.d.ts +8 -0
  78. package/dist/src/document-model/gen/reducer.d.ts +5 -0
  79. package/dist/src/document-model/gen/schema/index.d.ts +2 -0
  80. package/dist/src/document-model/gen/schema/types.d.ts +453 -0
  81. package/dist/src/document-model/gen/schema/zod.d.ts +453 -0
  82. package/dist/src/document-model/gen/state/actions.d.ts +9 -0
  83. package/dist/src/document-model/gen/state/creators.d.ts +8 -0
  84. package/dist/src/document-model/gen/state/object.d.ts +12 -0
  85. package/dist/src/document-model/gen/state/operations.d.ts +10 -0
  86. package/dist/src/document-model/gen/types.d.ts +8 -0
  87. package/dist/src/document-model/gen/utils.d.ts +6 -0
  88. package/dist/src/document-model/gen/versioning/actions.d.ts +8 -0
  89. package/dist/src/document-model/gen/versioning/creators.d.ts +7 -0
  90. package/dist/src/document-model/gen/versioning/object.d.ts +11 -0
  91. package/dist/src/document-model/gen/versioning/operations.d.ts +9 -0
  92. package/dist/src/document-model/index.d.ts +80 -0
  93. package/dist/src/index.d.ts +25 -0
  94. package/dist/vite.config.d.ts +2 -0
  95. package/dist/vitest.config.d.ts +2 -0
  96. package/package.json +1 -1
  97. package/dist/browser/cjs/internal/object-C-PazS9q.js +0 -25
  98. package/dist/browser/es/internal/index-BVJxzkIs.js +0 -44
  99. package/dist/node/es/internal/index-BIrQOTP_.js +0 -44
package/CHANGELOG.md ADDED
@@ -0,0 +1,33 @@
1
+ # [1.1.0-experimental.3](https://github.com/powerhouse-inc/document-model/compare/v1.1.0-experimental.2...v1.1.0-experimental.3) (2024-05-20)
2
+
3
+
4
+ ### Features
5
+
6
+ * correctly set header and resulting state when replaying document ([3183d06](https://github.com/powerhouse-inc/document-model/commit/3183d06ca30fefd15955b09a3cf63d292ee4dc0a))
7
+
8
+ # [1.1.0-experimental.2](https://github.com/powerhouse-inc/document-model/compare/v1.1.0-experimental.1...v1.1.0-experimental.2) (2024-05-20)
9
+
10
+
11
+ ### Features
12
+
13
+ * support reusing operation resulting state when replaying document ([6dee233](https://github.com/powerhouse-inc/document-model/commit/6dee233641d19dc5d50e18d4b8cee43bdbe3709e))
14
+
15
+ # [1.1.0-experimental.1](https://github.com/powerhouse-inc/document-model/compare/v1.0.53...v1.1.0-experimental.1) (2024-05-06)
16
+
17
+
18
+ ### Features
19
+
20
+ * added experimental release setup ([014410e](https://github.com/powerhouse-inc/document-model/commit/014410e0b493f7562b27268392d506ffa32a5735))
21
+ * added preprare script for husky ([bd1d405](https://github.com/powerhouse-inc/document-model/commit/bd1d405b48b987b653e1322ca82ec2d290db3d47))
22
+ * added processSkipOperation helper ([2b56e53](https://github.com/powerhouse-inc/document-model/commit/2b56e53aafc799ce2b4c90bb1c108e84e5f11c1d))
23
+ * added release config ([26a315b](https://github.com/powerhouse-inc/document-model/commit/26a315b7498bb818ce0710c5a1f3d71963bb38f9))
24
+ * added skipHeaderOperations util ([ea760dd](https://github.com/powerhouse-inc/document-model/commit/ea760dd22b6e7242fba64bea355a2116d26dfa49))
25
+ * change replayOperations to expect clearedOperations ([5d7c7c5](https://github.com/powerhouse-inc/document-model/commit/5d7c7c58ac8dd479c57c5cd19e398fcc9d35430d))
26
+ * fix last operation check ([51dc692](https://github.com/powerhouse-inc/document-model/commit/51dc69268ccb9d361c28bba45f5cfcac6e136595))
27
+ * fix nextIndex validation ([4a48fa6](https://github.com/powerhouse-inc/document-model/commit/4a48fa6c893855cd22db16c7a09ffc5f544bc404))
28
+ * implemented append-only operations into reducer ([61bea1b](https://github.com/powerhouse-inc/document-model/commit/61bea1bfdf59db01f852cd326f39d3f6047f2ac5))
29
+ * migrated document-helpers ([d37af90](https://github.com/powerhouse-inc/document-model/commit/d37af909c6145083ecbda57fb881cfb69ed2869f))
30
+ * only run release manually ([54e3b48](https://github.com/powerhouse-inc/document-model/commit/54e3b48bb6b8d4e81fa2795914a10aebb8981210))
31
+ * return garbage collected history from reducer ([e7320e7](https://github.com/powerhouse-inc/document-model/commit/e7320e706fa225b07e68eb55fd37697f87676627))
32
+ * revert state when a skip operation fails ([0f1ea8b](https://github.com/powerhouse-inc/document-model/commit/0f1ea8b498c5998f741697673c0d82df8d7ee702))
33
+ * small fixes ([4d9e757](https://github.com/powerhouse-inc/document-model/commit/4d9e757950090d0f5eac42410f71ae7d3771e687))
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("./internal/object-C-PazS9q.js");require("immer");require("jszip");const e=require("./internal/index-dwAOfmBp.js");require("zod");exports.Document=e.Document;exports.DocumentModel=e.DocumentModel$1;exports.actions=e.actions;exports.documentModel=e.documentModel;exports.module=e.module;exports.reducer=e.reducer;exports.utils=e.utils;exports.validateInitialState=e.validateInitialState;exports.validateModule=e.validateModule;exports.validateModuleOperation=e.validateModuleOperation;exports.validateModules=e.validateModules;exports.validateStateSchemaName=e.validateStateSchemaName;exports.z=e.zod;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("./internal/object-BHB7lY3H.js");require("immer");require("jszip");const e=require("./internal/index-BTG_-qY6.js");require("zod");exports.Document=e.Document;exports.DocumentModel=e.DocumentModel$1;exports.actions=e.actions;exports.documentModel=e.documentModel;exports.module=e.module;exports.reducer=e.reducer;exports.utils=e.utils;exports.validateInitialState=e.validateInitialState;exports.validateModule=e.validateModule;exports.validateModuleOperation=e.validateModuleOperation;exports.validateModules=e.validateModules;exports.validateStateSchemaName=e.validateStateSchemaName;exports.z=e.zod;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./internal/object-C-PazS9q.js"),o=require("./internal/index-DMRH7zDy.js");require("immer");require("zod");require("jszip");exports.BaseDocument=e.BaseDocument;exports.actions=e.BaseActions;exports.applyMixins=e.applyMixins;exports.baseReducer=e.baseReducer;exports.processUndoRedo=e.processUndoRedo;exports.z=e.zod;exports.utils=o.index;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./internal/object-BHB7lY3H.js"),o=require("./internal/index-BLpgsifL.js");require("immer");require("zod");require("jszip");exports.BaseDocument=e.BaseDocument;exports.actions=e.BaseActions;exports.applyMixins=e.applyMixins;exports.baseReducer=e.baseReducer;exports.processUndoRedo=e.processUndoRedo;exports.updateDocument=e.updateDocument;exports.updateHeader=e.updateHeader;exports.z=e.zod;exports.utils=o.index;
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./internal/index-DMRH7zDy.js"),o=require("./internal/index-dwAOfmBp.js");require("./internal/object-C-PazS9q.js");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;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./internal/index-BLpgsifL.js"),o=require("./internal/index-BTG_-qY6.js");require("./internal/object-BHB7lY3H.js");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;
@@ -1 +1 @@
1
- "use strict";const e=require("./object-C-PazS9q.js"),t=Object.freeze(Object.defineProperty({__proto__:null,calculateSkipsLeft:e.calculateSkipsLeft,createAction:e.createAction,createDocument:e.createDocument,createExtendedState:e.createExtendedState,createReducer:e.createReducer,createZip:e.createZip,documentHelpers:e.documentHelpers,getLocalFile:e.getLocalFile,getRemoteFile:e.getRemoteFile,hashDocument:e.hashDocument,hashKey:e.hashKey,isBaseAction:e.isBaseAction,isNoopOperation:e.isNoopOperation,isSameDocument:e.isSameDocument,isUndoRedo:e.isUndoRedo,loadFromFile:e.loadFromFile,loadFromInput:e.loadFromInput,mapSkippedOperations:e.mapSkippedOperations,parseResultingState:e.parseResultingState,readOnly:e.readOnly,replayDocument:e.replayDocument,replayOperations:e.replayOperations,saveToFile:e.saveToFile,saveToFileHandle:e.saveToFileHandle,sortMappedOperations:e.sortMappedOperations,sortOperations:e.sortOperations,validateOperations:e.validateOperations},Symbol.toStringTag,{value:"Module"})),o=Object.freeze(Object.defineProperty({__proto__:null,BaseDocument:e.BaseDocument,actions:e.BaseActions,applyMixins:e.applyMixins,baseReducer:e.baseReducer,processUndoRedo:e.processUndoRedo,utils:t,z:e.zod},Symbol.toStringTag,{value:"Module"}));exports.Document=o;exports.index=t;
1
+ "use strict";const e=require("./object-BHB7lY3H.js"),t=Object.freeze(Object.defineProperty({__proto__:null,calculateSkipsLeft:e.calculateSkipsLeft,createAction:e.createAction,createDocument:e.createDocument,createExtendedState:e.createExtendedState,createReducer:e.createReducer,createZip:e.createZip,documentHelpers:e.documentHelpers,getLocalFile:e.getLocalFile,getRemoteFile:e.getRemoteFile,hashDocument:e.hashDocument,hashKey:e.hashKey,isBaseAction:e.isBaseAction,isNoopOperation:e.isNoopOperation,isSameDocument:e.isSameDocument,isUndoRedo:e.isUndoRedo,loadFromFile:e.loadFromFile,loadFromInput:e.loadFromInput,mapSkippedOperations:e.mapSkippedOperations,parseResultingState:e.parseResultingState,readOnly:e.readOnly,replayDocument:e.replayDocument,replayOperations:e.replayOperations,saveToFile:e.saveToFile,saveToFileHandle:e.saveToFileHandle,sortMappedOperations:e.sortMappedOperations,sortOperations:e.sortOperations,validateOperations:e.validateOperations},Symbol.toStringTag,{value:"Module"})),o=Object.freeze(Object.defineProperty({__proto__:null,BaseDocument:e.BaseDocument,actions:e.BaseActions,applyMixins:e.applyMixins,baseReducer:e.baseReducer,processUndoRedo:e.processUndoRedo,updateDocument:e.updateDocument,updateHeader:e.updateHeader,utils:t,z:e.zod},Symbol.toStringTag,{value:"Module"}));exports.Document=o;exports.index=t;
@@ -1,4 +1,4 @@
1
- "use strict";var Tt=Object.defineProperty;var Rt=(t,e,r)=>e in t?Tt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var be=(t,e,r)=>(Rt(t,typeof e!="symbol"?e+"":e,r),r);const s=require("./object-C-PazS9q.js");require("immer");require("jszip");const o=require("zod"),xt=new RegExp("([\\p{Ll}\\d])(\\p{Lu})","gu"),Mt=new RegExp("(\\p{Lu})([\\p{Lu}][\\p{Ll}])","gu"),Dt=new RegExp("(\\d)\\p{Ll}|(\\p{L})\\d","u"),Nt=/[^\p{L}\d]+/giu,_e="$1\0$2",Ae="";function ze(t){let e=t.trim();e=e.replace(xt,_e).replace(Mt,_e),e=e.replace(Nt,"\0");let r=0,n=e.length;for(;e.charAt(r)==="\0";)r++;if(r===n)return[];for(;e.charAt(n-1)==="\0";)n--;return e.slice(r,n).split(/\0/g)}function Lt(t){const e=ze(t);for(let r=0;r<e.length;r++){const n=e[r],i=Dt.exec(n);if(i){const a=i.index+(i[1]??i[2]).length;e.splice(r,1,n.slice(0,a),n.slice(a))}}return e}function Ie(t,e){const[r,n,i]=wt(t,e),a=Pt(e==null?void 0:e.locale),l=jt(e==null?void 0:e.locale),d=e!=null&&e.mergeAmbiguousCharacters?Ct(a,l):yt(a,l);return r+n.map(d).join((e==null?void 0:e.delimiter)??"")+i}function Pt(t){return t===!1?e=>e.toLowerCase():e=>e.toLocaleLowerCase(t)}function jt(t){return t===!1?e=>e.toUpperCase():e=>e.toLocaleUpperCase(t)}function Ct(t,e){return r=>`${e(r[0])}${t(r.slice(1))}`}function yt(t,e){return(r,n)=>{const i=r[0];return(n>0&&i>="0"&&i<="9"?"_"+i:e(i))+t(r.slice(1))}}function wt(t,e={}){const r=e.split??(e.separateNumbers?Lt:ze),n=e.prefixCharacters??Ae,i=e.suffixCharacters??Ae;let a=0,l=t.length;for(;a<t.length;){const d=t.charAt(a);if(!n.includes(d))break;a++}for(;l>a;){const d=l-1,zt=t.charAt(d);if(!i.includes(zt))break;l=d}return[t.slice(0,a),r(t.slice(a,l)),t.slice(l)]}function T(t,e=!1){const r=[];if(e&&t==="")return r;try{const n=JSON.parse(t);!e&&!Object.keys(n).length&&r.push({message:"Initial state cannot be empty",details:{initialState:t}})}catch{r.push({message:"Invalid initial state",details:{initialState:t}})}return r}function R(t,e,r="",n=!0){const i=[];if(!n&&!t)return i.push({message:"State schema is required",details:{schema:t}}),i;if(n&&!t)return i;const a=`type ${Ie(e)}${Ie(r)}State`;return t.includes(a)||i.push({message:`Invalid state schema name. Expected ${a}`,details:{schema:t}}),i}function x(t){const e=[];t.length||e.push({message:"Modules are required",details:{modules:t}});const r=t.reduce((n,i)=>[...n,...b(i)],[]);return[...e,...r]}function b(t){const e=[];t.name||e.push({message:"Module name is required",details:{module:t}}),t.operations.length||e.push({message:"Module operations are required",details:{module:t}});const r=t.operations.reduce((n,i)=>[...n,..._(i)],[]);return[...e,...r]}function _(t){const e=[];return t.name||e.push({message:"Operation name is required",details:{operation:t}}),t.schema||e.push({message:"Operation schema is required",details:{operation:t}}),e}const kt=Object.freeze(Object.defineProperty({__proto__:null,validateInitialState:T,validateModule:b,validateModuleOperation:_,validateModules:x,validateStateSchemaName:R},Symbol.toStringTag,{value:"Module"})),M={id:"powerhouse/document-model",name:"DocumentModel",extension:"phdm",description:"The Powerhouse Document Model describes the state and operations of a document type.",author:{name:"Powerhouse",website:"https://www.powerhouse.inc/"},specifications:[{version:1,changeLog:[],modules:[{name:"header",operations:[{name:"SetModelName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetModelId",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetModelExtension",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetModelDescription",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetAuthorName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetAuthorWebsite",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"}],id:"",description:""},{name:"versioning",operations:[{name:"AddChangeLogItem",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"UpdateChangeLogItem",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"DeleteChangeLogItem",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"ReorderChangeLogItems",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"ReleaseNewVersion",schema:null,id:"",description:"",template:"",reducer:"",examples:[],errors:[],scope:"global"}],id:"",description:""},{name:"module",operations:[{name:"AddModule",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetModuleName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetModuleDescription",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"DeleteModule",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"ReorderModules",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"}],id:"",description:""},{name:"operation-error",operations:[{name:"AddOperationError",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationErrorCode",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationErrorName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationErrorDescription",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationErrorTemplate",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"DeleteOperationError",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"ReorderOperationErrors",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"}],id:"",description:""},{name:"operation-example",operations:[{name:"AddOperationExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"UpdateOperationExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"DeleteOperationExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"ReorderOperationExamples",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"}],id:"",description:""},{name:"operation",operations:[{name:"AddOperation",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationSchema",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationDescription",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationTemplate",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationReducer",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"MoveOperation",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"DeleteOperation",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"ReorderModuleOperations",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"}],id:"",description:""},{name:"state",operations:[{name:"SetStateSchema",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetInitialState",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"AddStateExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"UpdateStateExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"DeleteStateExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"ReorderStateExamples",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"}],id:"",description:""}],state:{global:{schema:"",initialValue:`{
1
+ "use strict";var Tt=Object.defineProperty;var Rt=(t,e,r)=>e in t?Tt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var be=(t,e,r)=>(Rt(t,typeof e!="symbol"?e+"":e,r),r);const s=require("./object-BHB7lY3H.js");require("immer");require("jszip");const o=require("zod"),xt=new RegExp("([\\p{Ll}\\d])(\\p{Lu})","gu"),Mt=new RegExp("(\\p{Lu})([\\p{Lu}][\\p{Ll}])","gu"),Dt=new RegExp("(\\d)\\p{Ll}|(\\p{L})\\d","u"),Nt=/[^\p{L}\d]+/giu,_e="$1\0$2",Ae="";function ze(t){let e=t.trim();e=e.replace(xt,_e).replace(Mt,_e),e=e.replace(Nt,"\0");let r=0,n=e.length;for(;e.charAt(r)==="\0";)r++;if(r===n)return[];for(;e.charAt(n-1)==="\0";)n--;return e.slice(r,n).split(/\0/g)}function Lt(t){const e=ze(t);for(let r=0;r<e.length;r++){const n=e[r],i=Dt.exec(n);if(i){const a=i.index+(i[1]??i[2]).length;e.splice(r,1,n.slice(0,a),n.slice(a))}}return e}function Ie(t,e){const[r,n,i]=wt(t,e),a=Pt(e==null?void 0:e.locale),l=jt(e==null?void 0:e.locale),d=e!=null&&e.mergeAmbiguousCharacters?Ct(a,l):yt(a,l);return r+n.map(d).join((e==null?void 0:e.delimiter)??"")+i}function Pt(t){return t===!1?e=>e.toLowerCase():e=>e.toLocaleLowerCase(t)}function jt(t){return t===!1?e=>e.toUpperCase():e=>e.toLocaleUpperCase(t)}function Ct(t,e){return r=>`${e(r[0])}${t(r.slice(1))}`}function yt(t,e){return(r,n)=>{const i=r[0];return(n>0&&i>="0"&&i<="9"?"_"+i:e(i))+t(r.slice(1))}}function wt(t,e={}){const r=e.split??(e.separateNumbers?Lt:ze),n=e.prefixCharacters??Ae,i=e.suffixCharacters??Ae;let a=0,l=t.length;for(;a<t.length;){const d=t.charAt(a);if(!n.includes(d))break;a++}for(;l>a;){const d=l-1,zt=t.charAt(d);if(!i.includes(zt))break;l=d}return[t.slice(0,a),r(t.slice(a,l)),t.slice(l)]}function T(t,e=!1){const r=[];if(e&&t==="")return r;try{const n=JSON.parse(t);!e&&!Object.keys(n).length&&r.push({message:"Initial state cannot be empty",details:{initialState:t}})}catch{r.push({message:"Invalid initial state",details:{initialState:t}})}return r}function R(t,e,r="",n=!0){const i=[];if(!n&&!t)return i.push({message:"State schema is required",details:{schema:t}}),i;if(n&&!t)return i;const a=`type ${Ie(e)}${Ie(r)}State`;return t.includes(a)||i.push({message:`Invalid state schema name. Expected ${a}`,details:{schema:t}}),i}function x(t){const e=[];t.length||e.push({message:"Modules are required",details:{modules:t}});const r=t.reduce((n,i)=>[...n,...b(i)],[]);return[...e,...r]}function b(t){const e=[];t.name||e.push({message:"Module name is required",details:{module:t}}),t.operations.length||e.push({message:"Module operations are required",details:{module:t}});const r=t.operations.reduce((n,i)=>[...n,..._(i)],[]);return[...e,...r]}function _(t){const e=[];return t.name||e.push({message:"Operation name is required",details:{operation:t}}),t.schema||e.push({message:"Operation schema is required",details:{operation:t}}),e}const kt=Object.freeze(Object.defineProperty({__proto__:null,validateInitialState:T,validateModule:b,validateModuleOperation:_,validateModules:x,validateStateSchemaName:R},Symbol.toStringTag,{value:"Module"})),M={id:"powerhouse/document-model",name:"DocumentModel",extension:"phdm",description:"The Powerhouse Document Model describes the state and operations of a document type.",author:{name:"Powerhouse",website:"https://www.powerhouse.inc/"},specifications:[{version:1,changeLog:[],modules:[{name:"header",operations:[{name:"SetModelName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetModelId",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetModelExtension",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetModelDescription",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetAuthorName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetAuthorWebsite",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"}],id:"",description:""},{name:"versioning",operations:[{name:"AddChangeLogItem",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"UpdateChangeLogItem",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"DeleteChangeLogItem",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"ReorderChangeLogItems",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"ReleaseNewVersion",schema:null,id:"",description:"",template:"",reducer:"",examples:[],errors:[],scope:"global"}],id:"",description:""},{name:"module",operations:[{name:"AddModule",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetModuleName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetModuleDescription",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"DeleteModule",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"ReorderModules",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"}],id:"",description:""},{name:"operation-error",operations:[{name:"AddOperationError",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationErrorCode",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationErrorName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationErrorDescription",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationErrorTemplate",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"DeleteOperationError",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"ReorderOperationErrors",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"}],id:"",description:""},{name:"operation-example",operations:[{name:"AddOperationExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"UpdateOperationExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"DeleteOperationExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"ReorderOperationExamples",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"}],id:"",description:""},{name:"operation",operations:[{name:"AddOperation",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationSchema",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationDescription",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationTemplate",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationReducer",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"MoveOperation",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"DeleteOperation",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"ReorderModuleOperations",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"}],id:"",description:""},{name:"state",operations:[{name:"SetStateSchema",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetInitialState",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"AddStateExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"UpdateStateExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"DeleteStateExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"ReorderStateExamples",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"}],id:"",description:""}],state:{global:{schema:"",initialValue:`{
2
2
  "id": "",
3
3
  "name": "",
4
4
  "extension": "",
@@ -0,0 +1,25 @@
1
+ "use strict";var tr=Object.defineProperty;var er=(r,i,o)=>i in r?tr(r,i,{enumerable:!0,configurable:!0,writable:!0,value:o}):r[i]=o;var Ot=(r,i,o)=>(er(r,typeof i!="symbol"?i+"":i,o),o);const nt=require("immer"),_=require("zod"),ce=require("jszip"),le=r=>r!=null,rr=_.z.any().refine(r=>le(r)),ue=_.z.enum(["LOAD_STATE"]),fe=_.z.enum(["PRUNE"]),he=_.z.enum(["REDO"]),me=_.z.enum(["SET_NAME"]),xe=_.z.enum(["UNDO"]);function ir(){return _.z.object({__typename:_.z.literal("Action").optional(),type:_.z.string()})}function Et(){return _.z.literal("global").or(_.z.literal("local"))}function de(){return _.z.union([ge(),we(),Ee(),be(),Se()])}function nr(){return _.z.object({__typename:_.z.literal("DocumentFile").optional(),data:_.z.string(),extension:_.z.string().nullable(),fileName:_.z.string().nullable(),mimeType:_.z.string()})}function ge(){return _.z.object({input:_.z.lazy(()=>Ht()),type:ue,scope:Et()})}function Ht(){return _.z.object({operations:_.z.number(),state:_.z.lazy(()=>ye())})}function ye(){return _.z.object({data:_.z.unknown().nullish(),name:_.z.string()})}function or(){return _.z.object({__typename:_.z.literal("Operation").optional(),hash:_.z.string(),index:_.z.number(),timestamp:_.z.string().datetime(),type:_.z.string()})}function we(){return _.z.object({input:_.z.lazy(()=>Jt()),type:fe,scope:Et()})}function Jt(){return _.z.object({end:_.z.number().nullish(),start:_.z.number().nullish()})}const Wt=_.z.number;function Ee(){return _.z.object({input:Wt(),type:he,scope:Et()})}const Xt=_.z.string;function be(){return _.z.object({input:Xt(),type:me,scope:_.z.literal("global")})}function ar(){return _.z.object({__typename:_.z.literal("SetNameOperation").optional(),hash:_.z.string(),index:_.z.number(),input:_.z.string(),timestamp:_.z.string().datetime(),type:_.z.string()})}const Vt=_.z.number;function Se(){return _.z.object({input:Vt(),type:xe,scope:Et()})}const sr=Object.freeze(Object.defineProperty({__proto__:null,ActionSchema:ir,BaseActionSchema:de,DocumentFileSchema:nr,LoadStateActionInputSchema:Ht,LoadStateActionSchema:ge,LoadStateActionStateInputSchema:ye,Load_StateSchema:ue,OperationSchema:or,OperationScopeSchema:Et,PruneActionInputSchema:Jt,PruneActionSchema:we,PruneSchema:fe,RedoActionInputSchema:Wt,RedoActionSchema:Ee,RedoSchema:he,SetNameActionInputSchema:Xt,SetNameActionSchema:be,SetNameOperationSchema:ar,Set_NameSchema:me,UndoActionInputSchema:Vt,UndoActionSchema:Se,UndoSchema:xe,definedNonNullAnySchema:rr,isDefinedNonNullAny:le},Symbol.toStringTag,{value:"Module"}));function Kt(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var zt={exports:{}};(function(r,i){const{hasOwnProperty:o}=Object.prototype,p=Z();p.configure=Z,p.stringify=p,p.default=p,i.stringify=p,i.configure=Z,r.exports=p;const u=/[\u0000-\u001f\u0022\u005c\ud800-\udfff]|[\ud800-\udbff](?![\udc00-\udfff])|(?:[^\ud800-\udbff]|^)[\udc00-\udfff]/;function f(w){return w.length<5e3&&!u.test(w)?`"${w}"`:JSON.stringify(w)}function c(w){if(w.length>200)return w.sort();for(let E=1;E<w.length;E++){const S=w[E];let z=E;for(;z!==0&&w[z-1]>S;)w[z]=w[z-1],z--;w[z]=S}return w}const s=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Object.getPrototypeOf(new Int8Array)),Symbol.toStringTag).get;function h(w){return s.call(w)!==void 0&&w.length!==0}function g(w,E,S){w.length<S&&(S=w.length);const z=E===","?"":" ";let J=`"0":${z}${w[0]}`;for(let W=1;W<S;W++)J+=`${E}"${W}":${z}${w[W]}`;return J}function y(w){if(o.call(w,"circularValue")){const E=w.circularValue;if(typeof E=="string")return`"${E}"`;if(E==null)return E;if(E===Error||E===TypeError)return{toString(){throw new TypeError("Converting circular structure to JSON")}};throw new TypeError('The "circularValue" argument must be of type string or the value null or undefined')}return'"[Circular]"'}function b(w,E){let S;if(o.call(w,E)&&(S=w[E],typeof S!="boolean"))throw new TypeError(`The "${E}" argument must be of type boolean`);return S===void 0?!0:S}function F(w,E){let S;if(o.call(w,E)){if(S=w[E],typeof S!="number")throw new TypeError(`The "${E}" argument must be of type number`);if(!Number.isInteger(S))throw new TypeError(`The "${E}" argument must be an integer`);if(S<1)throw new RangeError(`The "${E}" argument must be >= 1`)}return S===void 0?1/0:S}function j(w){return w===1?"1 item":`${w} items`}function U(w){const E=new Set;for(const S of w)(typeof S=="string"||typeof S=="number")&&E.add(String(S));return E}function q(w){if(o.call(w,"strict")){const E=w.strict;if(typeof E!="boolean")throw new TypeError('The "strict" argument must be of type boolean');if(E)return S=>{let z=`Object can not safely be stringified. Received type ${typeof S}`;throw typeof S!="function"&&(z+=` (${S.toString()})`),new Error(z)}}}function Z(w){w={...w};const E=q(w);E&&(w.bigint===void 0&&(w.bigint=!1),"circularValue"in w||(w.circularValue=Error));const S=y(w),z=b(w,"bigint"),J=b(w,"deterministic"),W=F(w,"maximumDepth"),M=F(w,"maximumBreadth");function ht(X,m,v,D,B,C){let A=m[X];switch(typeof A=="object"&&A!==null&&typeof A.toJSON=="function"&&(A=A.toJSON(X)),A=D.call(m,X,A),typeof A){case"string":return f(A);case"object":{if(A===null)return"null";if(v.indexOf(A)!==-1)return S;let T="",O=",";const I=C;if(Array.isArray(A)){if(A.length===0)return"[]";if(W<v.length+1)return'"[Array]"';v.push(A),B!==""&&(C+=B,T+=`
2
+ ${C}`,O=`,
3
+ ${C}`);const V=Math.min(A.length,M);let Q=0;for(;Q<V-1;Q++){const lt=ht(String(Q),A,v,D,B,C);T+=lt!==void 0?lt:"null",T+=O}const tt=ht(String(Q),A,v,D,B,C);if(T+=tt!==void 0?tt:"null",A.length-1>M){const lt=A.length-M-1;T+=`${O}"... ${j(lt)} not stringified"`}return B!==""&&(T+=`
4
+ ${I}`),v.pop(),`[${T}]`}let R=Object.keys(A);const H=R.length;if(H===0)return"{}";if(W<v.length+1)return'"[Object]"';let $="",K="";B!==""&&(C+=B,O=`,
5
+ ${C}`,$=" ");const Y=Math.min(H,M);J&&!h(A)&&(R=c(R)),v.push(A);for(let V=0;V<Y;V++){const Q=R[V],tt=ht(Q,A,v,D,B,C);tt!==void 0&&(T+=`${K}${f(Q)}:${$}${tt}`,K=O)}if(H>M){const V=H-M;T+=`${K}"...":${$}"${j(V)} not stringified"`,K=O}return B!==""&&K.length>1&&(T=`
6
+ ${C}${T}
7
+ ${I}`),v.pop(),`{${T}}`}case"number":return isFinite(A)?String(A):E?E(A):"null";case"boolean":return A===!0?"true":"false";case"undefined":return;case"bigint":if(z)return String(A);default:return E?E(A):void 0}}function mt(X,m,v,D,B,C){switch(typeof m=="object"&&m!==null&&typeof m.toJSON=="function"&&(m=m.toJSON(X)),typeof m){case"string":return f(m);case"object":{if(m===null)return"null";if(v.indexOf(m)!==-1)return S;const A=C;let T="",O=",";if(Array.isArray(m)){if(m.length===0)return"[]";if(W<v.length+1)return'"[Array]"';v.push(m),B!==""&&(C+=B,T+=`
8
+ ${C}`,O=`,
9
+ ${C}`);const H=Math.min(m.length,M);let $=0;for(;$<H-1;$++){const Y=mt(String($),m[$],v,D,B,C);T+=Y!==void 0?Y:"null",T+=O}const K=mt(String($),m[$],v,D,B,C);if(T+=K!==void 0?K:"null",m.length-1>M){const Y=m.length-M-1;T+=`${O}"... ${j(Y)} not stringified"`}return B!==""&&(T+=`
10
+ ${A}`),v.pop(),`[${T}]`}v.push(m);let I="";B!==""&&(C+=B,O=`,
11
+ ${C}`,I=" ");let R="";for(const H of D){const $=mt(H,m[H],v,D,B,C);$!==void 0&&(T+=`${R}${f(H)}:${I}${$}`,R=O)}return B!==""&&R.length>1&&(T=`
12
+ ${C}${T}
13
+ ${A}`),v.pop(),`{${T}}`}case"number":return isFinite(m)?String(m):E?E(m):"null";case"boolean":return m===!0?"true":"false";case"undefined":return;case"bigint":if(z)return String(m);default:return E?E(m):void 0}}function pt(X,m,v,D,B){switch(typeof m){case"string":return f(m);case"object":{if(m===null)return"null";if(typeof m.toJSON=="function"){if(m=m.toJSON(X),typeof m!="object")return pt(X,m,v,D,B);if(m===null)return"null"}if(v.indexOf(m)!==-1)return S;const C=B;if(Array.isArray(m)){if(m.length===0)return"[]";if(W<v.length+1)return'"[Array]"';v.push(m),B+=D;let $=`
14
+ ${B}`;const K=`,
15
+ ${B}`,Y=Math.min(m.length,M);let V=0;for(;V<Y-1;V++){const tt=pt(String(V),m[V],v,D,B);$+=tt!==void 0?tt:"null",$+=K}const Q=pt(String(V),m[V],v,D,B);if($+=Q!==void 0?Q:"null",m.length-1>M){const tt=m.length-M-1;$+=`${K}"... ${j(tt)} not stringified"`}return $+=`
16
+ ${C}`,v.pop(),`[${$}]`}let A=Object.keys(m);const T=A.length;if(T===0)return"{}";if(W<v.length+1)return'"[Object]"';B+=D;const O=`,
17
+ ${B}`;let I="",R="",H=Math.min(T,M);h(m)&&(I+=g(m,O,M),A=A.slice(m.length),H-=m.length,R=O),J&&(A=c(A)),v.push(m);for(let $=0;$<H;$++){const K=A[$],Y=pt(K,m[K],v,D,B);Y!==void 0&&(I+=`${R}${f(K)}: ${Y}`,R=O)}if(T>M){const $=T-M;I+=`${R}"...": "${j($)} not stringified"`,R=O}return R!==""&&(I=`
18
+ ${B}${I}
19
+ ${C}`),v.pop(),`{${I}}`}case"number":return isFinite(m)?String(m):E?E(m):"null";case"boolean":return m===!0?"true":"false";case"undefined":return;case"bigint":if(z)return String(m);default:return E?E(m):void 0}}function ct(X,m,v){switch(typeof m){case"string":return f(m);case"object":{if(m===null)return"null";if(typeof m.toJSON=="function"){if(m=m.toJSON(X),typeof m!="object")return ct(X,m,v);if(m===null)return"null"}if(v.indexOf(m)!==-1)return S;let D="";if(Array.isArray(m)){if(m.length===0)return"[]";if(W<v.length+1)return'"[Array]"';v.push(m);const O=Math.min(m.length,M);let I=0;for(;I<O-1;I++){const H=ct(String(I),m[I],v);D+=H!==void 0?H:"null",D+=","}const R=ct(String(I),m[I],v);if(D+=R!==void 0?R:"null",m.length-1>M){const H=m.length-M-1;D+=`,"... ${j(H)} not stringified"`}return v.pop(),`[${D}]`}let B=Object.keys(m);const C=B.length;if(C===0)return"{}";if(W<v.length+1)return'"[Object]"';let A="",T=Math.min(C,M);h(m)&&(D+=g(m,",",M),B=B.slice(m.length),T-=m.length,A=","),J&&(B=c(B)),v.push(m);for(let O=0;O<T;O++){const I=B[O],R=ct(I,m[I],v);R!==void 0&&(D+=`${A}${f(I)}:${R}`,A=",")}if(C>M){const O=C-M;D+=`${A}"...":"${j(O)} not stringified"`}return v.pop(),`{${D}}`}case"number":return isFinite(m)?String(m):E?E(m):"null";case"boolean":return m===!0?"true":"false";case"undefined":return;case"bigint":if(z)return String(m);default:return E?E(m):void 0}}function Ut(X,m,v){if(arguments.length>1){let D="";if(typeof v=="number"?D=" ".repeat(Math.min(v,10)):typeof v=="string"&&(D=v.slice(0,10)),m!=null){if(typeof m=="function")return ht("",{"":X},[],m,D,"");if(Array.isArray(m))return mt("",X,[],U(m),D,"")}if(D.length!==0)return pt("",X,[],D,"")}return ct("",X,[])}return Ut}})(zt,zt.exports);var pr=zt.exports;const gt=Kt(pr);gt.configure;function cr(r,i){return{...r,name:i}}function lr(r,i,o){const{scope:p,input:u}=i,f={document:r,action:i,skip:o};return nt.produce(f,c=>{if(c.document.operations[p].length<1)throw new Error(`Cannot undo: no operations in history for scope "${p}"`);if(u<1)throw new Error("Invalid UNDO action: input value must be greater than 0");if(c.skip>0)throw new Error("Cannot undo: skip value from reducer cannot be used with UNDO action");const s=c.document.operations[p].at(-1),h=s&&s.type==="NOOP"&&s.skip>0;if(c.skip+=u,h){c.skip+=s.skip;const F=c.document.operations[p][c.document.operations[p].length-2];F&&s.index-F.index===1&&c.document.operations[p].pop()}if(c.document.operations[p].length<c.skip)throw new Error("Cannot undo: you can't undo more operations than the ones in the scope history");const g=c.document.operations[p].length-1;let y=u,b=h?g-s.skip:g;for(;y>0&&b>=0;){const F=c.document.operations[p][b];if(!F){y--,b--;continue}F.type==="NOOP"&&F.skip>0?(b=b-(F.skip+1),c.skip+=F.skip+1):(c.document.clipboard.push({...F}),y--,b--)}c.action=Ye(p)})}function ur(r,i,o){const{scope:p,input:u}=i,f={document:r,action:i,skip:o};return nt.produce(f,c=>{if(c.skip>0)throw new Error("Cannot redo: skip value from reducer cannot be used with REDO action");if(u>1)throw new Error("Cannot redo: you can only redo one operation at a time");if(u<1)throw new Error("Invalid REDO action: invalid redo input value");if(c.document.clipboard.length<1)throw new Error("Cannot redo: no operations in the clipboard");const s=c.document.clipboard.findLastIndex(g=>g.scope===p);if(s<0)throw new Error(`Cannot redo: no operations in clipboard for scope "${p}"`);const h=c.document.clipboard.splice(s,1)[0];c.action=nt.castDraft({type:h.type,scope:h.scope,input:h.input})})}function fr(r,i,o){const{scope:p}=i,u=r.operations[p];let{input:{start:f,end:c}}=i;f=f||0,c=c||u.length;const s=u.slice(f,c),h=u.slice(0,f),g=u.slice(c),y=Bt(r.initialState,{...r.operations,[p]:h.concat(s)},o),{name:b,state:F}=y,j=h.length,U=h.length?h[h.length-1].timestamp:g.length?g[0].timestamp:new Date().toISOString();return Bt(r.initialState,{...r.operations,[p]:[...h,{...ae({name:b,state:F},s.length),timestamp:U,index:j,hash:kt({state:F},"global")},...g.map((q,Z)=>({...q,index:j+Z+1}))]},o)}function hr(r,i){return{...r,name:i.name,state:i.state??{global:{},local:{}}}}const ve="SET_NAME",bt="UNDO",St="REDO",It="PRUNE",_e="LOAD_STATE",mr="NOOP",Ae={"application/andrew-inset":["ez"],"application/appinstaller":["appinstaller"],"application/applixware":["aw"],"application/appx":["appx"],"application/appxbundle":["appxbundle"],"application/atom+xml":["atom"],"application/atomcat+xml":["atomcat"],"application/atomdeleted+xml":["atomdeleted"],"application/atomsvc+xml":["atomsvc"],"application/atsc-dwd+xml":["dwd"],"application/atsc-held+xml":["held"],"application/atsc-rsat+xml":["rsat"],"application/automationml-aml+xml":["aml"],"application/automationml-amlx+zip":["amlx"],"application/bdoc":["bdoc"],"application/calendar+xml":["xcs"],"application/ccxml+xml":["ccxml"],"application/cdfx+xml":["cdfx"],"application/cdmi-capability":["cdmia"],"application/cdmi-container":["cdmic"],"application/cdmi-domain":["cdmid"],"application/cdmi-object":["cdmio"],"application/cdmi-queue":["cdmiq"],"application/cpl+xml":["cpl"],"application/cu-seeme":["cu"],"application/cwl":["cwl"],"application/dash+xml":["mpd"],"application/dash-patch+xml":["mpp"],"application/davmount+xml":["davmount"],"application/docbook+xml":["dbk"],"application/dssc+der":["dssc"],"application/dssc+xml":["xdssc"],"application/ecmascript":["ecma"],"application/emma+xml":["emma"],"application/emotionml+xml":["emotionml"],"application/epub+zip":["epub"],"application/exi":["exi"],"application/express":["exp"],"application/fdf":["fdf"],"application/fdt+xml":["fdt"],"application/font-tdpfr":["pfr"],"application/geo+json":["geojson"],"application/gml+xml":["gml"],"application/gpx+xml":["gpx"],"application/gxf":["gxf"],"application/gzip":["gz"],"application/hjson":["hjson"],"application/hyperstudio":["stk"],"application/inkml+xml":["ink","inkml"],"application/ipfix":["ipfix"],"application/its+xml":["its"],"application/java-archive":["jar","war","ear"],"application/java-serialized-object":["ser"],"application/java-vm":["class"],"application/javascript":["*js"],"application/json":["json","map"],"application/json5":["json5"],"application/jsonml+json":["jsonml"],"application/ld+json":["jsonld"],"application/lgr+xml":["lgr"],"application/lost+xml":["lostxml"],"application/mac-binhex40":["hqx"],"application/mac-compactpro":["cpt"],"application/mads+xml":["mads"],"application/manifest+json":["webmanifest"],"application/marc":["mrc"],"application/marcxml+xml":["mrcx"],"application/mathematica":["ma","nb","mb"],"application/mathml+xml":["mathml"],"application/mbox":["mbox"],"application/media-policy-dataset+xml":["mpf"],"application/mediaservercontrol+xml":["mscml"],"application/metalink+xml":["metalink"],"application/metalink4+xml":["meta4"],"application/mets+xml":["mets"],"application/mmt-aei+xml":["maei"],"application/mmt-usd+xml":["musd"],"application/mods+xml":["mods"],"application/mp21":["m21","mp21"],"application/mp4":["*mp4","*mpg4","mp4s","m4p"],"application/msix":["msix"],"application/msixbundle":["msixbundle"],"application/msword":["doc","dot"],"application/mxf":["mxf"],"application/n-quads":["nq"],"application/n-triples":["nt"],"application/node":["cjs"],"application/octet-stream":["bin","dms","lrf","mar","so","dist","distz","pkg","bpk","dump","elc","deploy","exe","dll","deb","dmg","iso","img","msi","msp","msm","buffer"],"application/oda":["oda"],"application/oebps-package+xml":["opf"],"application/ogg":["ogx"],"application/omdoc+xml":["omdoc"],"application/onenote":["onetoc","onetoc2","onetmp","onepkg"],"application/oxps":["oxps"],"application/p2p-overlay+xml":["relo"],"application/patch-ops-error+xml":["xer"],"application/pdf":["pdf"],"application/pgp-encrypted":["pgp"],"application/pgp-keys":["asc"],"application/pgp-signature":["sig","*asc"],"application/pics-rules":["prf"],"application/pkcs10":["p10"],"application/pkcs7-mime":["p7m","p7c"],"application/pkcs7-signature":["p7s"],"application/pkcs8":["p8"],"application/pkix-attr-cert":["ac"],"application/pkix-cert":["cer"],"application/pkix-crl":["crl"],"application/pkix-pkipath":["pkipath"],"application/pkixcmp":["pki"],"application/pls+xml":["pls"],"application/postscript":["ai","eps","ps"],"application/provenance+xml":["provx"],"application/pskc+xml":["pskcxml"],"application/raml+yaml":["raml"],"application/rdf+xml":["rdf","owl"],"application/reginfo+xml":["rif"],"application/relax-ng-compact-syntax":["rnc"],"application/resource-lists+xml":["rl"],"application/resource-lists-diff+xml":["rld"],"application/rls-services+xml":["rs"],"application/route-apd+xml":["rapd"],"application/route-s-tsid+xml":["sls"],"application/route-usd+xml":["rusd"],"application/rpki-ghostbusters":["gbr"],"application/rpki-manifest":["mft"],"application/rpki-roa":["roa"],"application/rsd+xml":["rsd"],"application/rss+xml":["rss"],"application/rtf":["rtf"],"application/sbml+xml":["sbml"],"application/scvp-cv-request":["scq"],"application/scvp-cv-response":["scs"],"application/scvp-vp-request":["spq"],"application/scvp-vp-response":["spp"],"application/sdp":["sdp"],"application/senml+xml":["senmlx"],"application/sensml+xml":["sensmlx"],"application/set-payment-initiation":["setpay"],"application/set-registration-initiation":["setreg"],"application/shf+xml":["shf"],"application/sieve":["siv","sieve"],"application/smil+xml":["smi","smil"],"application/sparql-query":["rq"],"application/sparql-results+xml":["srx"],"application/sql":["sql"],"application/srgs":["gram"],"application/srgs+xml":["grxml"],"application/sru+xml":["sru"],"application/ssdl+xml":["ssdl"],"application/ssml+xml":["ssml"],"application/swid+xml":["swidtag"],"application/tei+xml":["tei","teicorpus"],"application/thraud+xml":["tfi"],"application/timestamped-data":["tsd"],"application/toml":["toml"],"application/trig":["trig"],"application/ttml+xml":["ttml"],"application/ubjson":["ubj"],"application/urc-ressheet+xml":["rsheet"],"application/urc-targetdesc+xml":["td"],"application/voicexml+xml":["vxml"],"application/wasm":["wasm"],"application/watcherinfo+xml":["wif"],"application/widget":["wgt"],"application/winhlp":["hlp"],"application/wsdl+xml":["wsdl"],"application/wspolicy+xml":["wspolicy"],"application/xaml+xml":["xaml"],"application/xcap-att+xml":["xav"],"application/xcap-caps+xml":["xca"],"application/xcap-diff+xml":["xdf"],"application/xcap-el+xml":["xel"],"application/xcap-ns+xml":["xns"],"application/xenc+xml":["xenc"],"application/xfdf":["xfdf"],"application/xhtml+xml":["xhtml","xht"],"application/xliff+xml":["xlf"],"application/xml":["xml","xsl","xsd","rng"],"application/xml-dtd":["dtd"],"application/xop+xml":["xop"],"application/xproc+xml":["xpl"],"application/xslt+xml":["*xsl","xslt"],"application/xspf+xml":["xspf"],"application/xv+xml":["mxml","xhvml","xvml","xvm"],"application/yang":["yang"],"application/yin+xml":["yin"],"application/zip":["zip"],"audio/3gpp":["*3gpp"],"audio/aac":["adts","aac"],"audio/adpcm":["adp"],"audio/amr":["amr"],"audio/basic":["au","snd"],"audio/midi":["mid","midi","kar","rmi"],"audio/mobile-xmf":["mxmf"],"audio/mp3":["*mp3"],"audio/mp4":["m4a","mp4a"],"audio/mpeg":["mpga","mp2","mp2a","mp3","m2a","m3a"],"audio/ogg":["oga","ogg","spx","opus"],"audio/s3m":["s3m"],"audio/silk":["sil"],"audio/wav":["wav"],"audio/wave":["*wav"],"audio/webm":["weba"],"audio/xm":["xm"],"font/collection":["ttc"],"font/otf":["otf"],"font/ttf":["ttf"],"font/woff":["woff"],"font/woff2":["woff2"],"image/aces":["exr"],"image/apng":["apng"],"image/avci":["avci"],"image/avcs":["avcs"],"image/avif":["avif"],"image/bmp":["bmp","dib"],"image/cgm":["cgm"],"image/dicom-rle":["drle"],"image/dpx":["dpx"],"image/emf":["emf"],"image/fits":["fits"],"image/g3fax":["g3"],"image/gif":["gif"],"image/heic":["heic"],"image/heic-sequence":["heics"],"image/heif":["heif"],"image/heif-sequence":["heifs"],"image/hej2k":["hej2"],"image/hsj2":["hsj2"],"image/ief":["ief"],"image/jls":["jls"],"image/jp2":["jp2","jpg2"],"image/jpeg":["jpeg","jpg","jpe"],"image/jph":["jph"],"image/jphc":["jhc"],"image/jpm":["jpm","jpgm"],"image/jpx":["jpx","jpf"],"image/jxr":["jxr"],"image/jxra":["jxra"],"image/jxrs":["jxrs"],"image/jxs":["jxs"],"image/jxsc":["jxsc"],"image/jxsi":["jxsi"],"image/jxss":["jxss"],"image/ktx":["ktx"],"image/ktx2":["ktx2"],"image/png":["png"],"image/sgi":["sgi"],"image/svg+xml":["svg","svgz"],"image/t38":["t38"],"image/tiff":["tif","tiff"],"image/tiff-fx":["tfx"],"image/webp":["webp"],"image/wmf":["wmf"],"message/disposition-notification":["disposition-notification"],"message/global":["u8msg"],"message/global-delivery-status":["u8dsn"],"message/global-disposition-notification":["u8mdn"],"message/global-headers":["u8hdr"],"message/rfc822":["eml","mime"],"model/3mf":["3mf"],"model/gltf+json":["gltf"],"model/gltf-binary":["glb"],"model/iges":["igs","iges"],"model/jt":["jt"],"model/mesh":["msh","mesh","silo"],"model/mtl":["mtl"],"model/obj":["obj"],"model/prc":["prc"],"model/step+xml":["stpx"],"model/step+zip":["stpz"],"model/step-xml+zip":["stpxz"],"model/stl":["stl"],"model/u3d":["u3d"],"model/vrml":["wrl","vrml"],"model/x3d+binary":["*x3db","x3dbz"],"model/x3d+fastinfoset":["x3db"],"model/x3d+vrml":["*x3dv","x3dvz"],"model/x3d+xml":["x3d","x3dz"],"model/x3d-vrml":["x3dv"],"text/cache-manifest":["appcache","manifest"],"text/calendar":["ics","ifb"],"text/coffeescript":["coffee","litcoffee"],"text/css":["css"],"text/csv":["csv"],"text/html":["html","htm","shtml"],"text/jade":["jade"],"text/javascript":["js","mjs"],"text/jsx":["jsx"],"text/less":["less"],"text/markdown":["md","markdown"],"text/mathml":["mml"],"text/mdx":["mdx"],"text/n3":["n3"],"text/plain":["txt","text","conf","def","list","log","in","ini"],"text/richtext":["rtx"],"text/rtf":["*rtf"],"text/sgml":["sgml","sgm"],"text/shex":["shex"],"text/slim":["slim","slm"],"text/spdx":["spdx"],"text/stylus":["stylus","styl"],"text/tab-separated-values":["tsv"],"text/troff":["t","tr","roff","man","me","ms"],"text/turtle":["ttl"],"text/uri-list":["uri","uris","urls"],"text/vcard":["vcard"],"text/vtt":["vtt"],"text/wgsl":["wgsl"],"text/xml":["*xml"],"text/yaml":["yaml","yml"],"video/3gpp":["3gp","3gpp"],"video/3gpp2":["3g2"],"video/h261":["h261"],"video/h263":["h263"],"video/h264":["h264"],"video/iso.segment":["m4s"],"video/jpeg":["jpgv"],"video/jpm":["*jpm","*jpgm"],"video/mj2":["mj2","mjp2"],"video/mp2t":["ts"],"video/mp4":["mp4","mp4v","mpg4"],"video/mpeg":["mpeg","mpg","mpe","m1v","m2v"],"video/ogg":["ogv"],"video/quicktime":["qt","mov"],"video/webm":["webm"]};Object.freeze(Ae);var et=function(r,i,o,p){if(o==="a"&&!p)throw new TypeError("Private accessor was defined without a getter");if(typeof i=="function"?r!==i||!p:!i.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return o==="m"?p:o==="a"?p.call(r):p?p.value:i.get(r)},dt,yt,ut;class xr{constructor(...i){dt.set(this,new Map),yt.set(this,new Map),ut.set(this,new Map);for(const o of i)this.define(o)}define(i,o=!1){for(let[p,u]of Object.entries(i)){p=p.toLowerCase(),u=u.map(s=>s.toLowerCase()),et(this,ut,"f").has(p)||et(this,ut,"f").set(p,new Set);const f=et(this,ut,"f").get(p);let c=!0;for(let s of u){const h=s.startsWith("*");if(s=h?s.slice(1):s,f==null||f.add(s),c&&et(this,yt,"f").set(p,s),c=!1,h)continue;const g=et(this,dt,"f").get(s);if(g&&g!=p&&!o)throw new Error(`"${p} -> ${s}" conflicts with "${g} -> ${s}". Pass \`force=true\` to override this definition.`);et(this,dt,"f").set(s,p)}}return this}getType(i){if(typeof i!="string")return null;const o=i.replace(/^.*[/\\]/,"").toLowerCase(),p=o.replace(/^.*\./,"").toLowerCase(),u=o.length<i.length;return!(p.length<o.length-1)&&u?null:et(this,dt,"f").get(p)??null}getExtension(i){var o;return typeof i!="string"?null:(i=(o=i==null?void 0:i.split)==null?void 0:o.call(i,";")[0],(i&&et(this,yt,"f").get(i.trim().toLowerCase()))??null)}getAllExtensions(i){return typeof i!="string"?null:et(this,ut,"f").get(i.toLowerCase())??null}_freeze(){this.define=()=>{throw new Error("define() not allowed for built-in Mime objects. See https://github.com/broofa/mime/blob/main/README.md#custom-mime-instances")},Object.freeze(this);for(const i of et(this,ut,"f").values())Object.freeze(i);return this}_getTestState(){return{types:et(this,dt,"f"),extensions:et(this,yt,"f")}}}dt=new WeakMap,yt=new WeakMap,ut=new WeakMap;const dr=new xr(Ae)._freeze();var Mt={exports:{}};typeof Object.create=="function"?Mt.exports=function(i,o){o&&(i.super_=o,i.prototype=Object.create(o.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}))}:Mt.exports=function(i,o){if(o){i.super_=o;var p=function(){};p.prototype=o.prototype,i.prototype=new p,i.prototype.constructor=i}};var Fe=Mt.exports,Rt={exports:{}},Oe={},jt={};jt.byteLength=wr;jt.toByteArray=br;jt.fromByteArray=_r;var ot=[],rt=[],gr=typeof Uint8Array<"u"?Uint8Array:Array,$t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var xt=0,yr=$t.length;xt<yr;++xt)ot[xt]=$t[xt],rt[$t.charCodeAt(xt)]=xt;rt[45]=62;rt[95]=63;function Be(r){var i=r.length;if(i%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var o=r.indexOf("=");o===-1&&(o=i);var p=o===i?0:4-o%4;return[o,p]}function wr(r){var i=Be(r),o=i[0],p=i[1];return(o+p)*3/4-p}function Er(r,i,o){return(i+o)*3/4-o}function br(r){var i,o=Be(r),p=o[0],u=o[1],f=new gr(Er(r,p,u)),c=0,s=u>0?p-4:p,h;for(h=0;h<s;h+=4)i=rt[r.charCodeAt(h)]<<18|rt[r.charCodeAt(h+1)]<<12|rt[r.charCodeAt(h+2)]<<6|rt[r.charCodeAt(h+3)],f[c++]=i>>16&255,f[c++]=i>>8&255,f[c++]=i&255;return u===2&&(i=rt[r.charCodeAt(h)]<<2|rt[r.charCodeAt(h+1)]>>4,f[c++]=i&255),u===1&&(i=rt[r.charCodeAt(h)]<<10|rt[r.charCodeAt(h+1)]<<4|rt[r.charCodeAt(h+2)]>>2,f[c++]=i>>8&255,f[c++]=i&255),f}function Sr(r){return ot[r>>18&63]+ot[r>>12&63]+ot[r>>6&63]+ot[r&63]}function vr(r,i,o){for(var p,u=[],f=i;f<o;f+=3)p=(r[f]<<16&16711680)+(r[f+1]<<8&65280)+(r[f+2]&255),u.push(Sr(p));return u.join("")}function _r(r){for(var i,o=r.length,p=o%3,u=[],f=16383,c=0,s=o-p;c<s;c+=f)u.push(vr(r,c,c+f>s?s:c+f));return p===1?(i=r[o-1],u.push(ot[i>>2]+ot[i<<4&63]+"==")):p===2&&(i=(r[o-2]<<8)+r[o-1],u.push(ot[i>>10]+ot[i>>4&63]+ot[i<<2&63]+"=")),u.join("")}var Gt={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */Gt.read=function(r,i,o,p,u){var f,c,s=u*8-p-1,h=(1<<s)-1,g=h>>1,y=-7,b=o?u-1:0,F=o?-1:1,j=r[i+b];for(b+=F,f=j&(1<<-y)-1,j>>=-y,y+=s;y>0;f=f*256+r[i+b],b+=F,y-=8);for(c=f&(1<<-y)-1,f>>=-y,y+=p;y>0;c=c*256+r[i+b],b+=F,y-=8);if(f===0)f=1-g;else{if(f===h)return c?NaN:(j?-1:1)*(1/0);c=c+Math.pow(2,p),f=f-g}return(j?-1:1)*c*Math.pow(2,f-p)};Gt.write=function(r,i,o,p,u,f){var c,s,h,g=f*8-u-1,y=(1<<g)-1,b=y>>1,F=u===23?Math.pow(2,-24)-Math.pow(2,-77):0,j=p?0:f-1,U=p?1:-1,q=i<0||i===0&&1/i<0?1:0;for(i=Math.abs(i),isNaN(i)||i===1/0?(s=isNaN(i)?1:0,c=y):(c=Math.floor(Math.log(i)/Math.LN2),i*(h=Math.pow(2,-c))<1&&(c--,h*=2),c+b>=1?i+=F/h:i+=F*Math.pow(2,1-b),i*h>=2&&(c++,h/=2),c+b>=y?(s=0,c=y):c+b>=1?(s=(i*h-1)*Math.pow(2,u),c=c+b):(s=i*Math.pow(2,b-1)*Math.pow(2,u),c=0));u>=8;r[o+j]=s&255,j+=U,s/=256,u-=8);for(c=c<<u|s,g+=u;g>0;r[o+j]=c&255,j+=U,c/=256,g-=8);r[o+j-U]|=q*128};/*!
20
+ * The buffer module from node.js, for the browser.
21
+ *
22
+ * @author Feross Aboukhadijeh <https://feross.org>
23
+ * @license MIT
24
+ */(function(r){var i=jt,o=Gt,p=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;r.Buffer=s,r.SlowBuffer=E,r.INSPECT_MAX_BYTES=50;var u=2147483647;r.kMaxLength=u,s.TYPED_ARRAY_SUPPORT=f(),!s.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function f(){try{var n=new Uint8Array(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,Uint8Array.prototype),Object.setPrototypeOf(n,t),n.foo()===42}catch{return!1}}Object.defineProperty(s.prototype,"parent",{enumerable:!0,get:function(){if(s.isBuffer(this))return this.buffer}}),Object.defineProperty(s.prototype,"offset",{enumerable:!0,get:function(){if(s.isBuffer(this))return this.byteOffset}});function c(n){if(n>u)throw new RangeError('The value "'+n+'" is invalid for option "size"');var t=new Uint8Array(n);return Object.setPrototypeOf(t,s.prototype),t}function s(n,t,e){if(typeof n=="number"){if(typeof t=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return b(n)}return h(n,t,e)}s.poolSize=8192;function h(n,t,e){if(typeof n=="string")return F(n,t);if(ArrayBuffer.isView(n))return U(n);if(n==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof n);if(it(n,ArrayBuffer)||n&&it(n.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(it(n,SharedArrayBuffer)||n&&it(n.buffer,SharedArrayBuffer)))return q(n,t,e);if(typeof n=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');var a=n.valueOf&&n.valueOf();if(a!=null&&a!==n)return s.from(a,t,e);var l=Z(n);if(l)return l;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof n[Symbol.toPrimitive]=="function")return s.from(n[Symbol.toPrimitive]("string"),t,e);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof n)}s.from=function(n,t,e){return h(n,t,e)},Object.setPrototypeOf(s.prototype,Uint8Array.prototype),Object.setPrototypeOf(s,Uint8Array);function g(n){if(typeof n!="number")throw new TypeError('"size" argument must be of type number');if(n<0)throw new RangeError('The value "'+n+'" is invalid for option "size"')}function y(n,t,e){return g(n),n<=0?c(n):t!==void 0?typeof e=="string"?c(n).fill(t,e):c(n).fill(t):c(n)}s.alloc=function(n,t,e){return y(n,t,e)};function b(n){return g(n),c(n<0?0:w(n)|0)}s.allocUnsafe=function(n){return b(n)},s.allocUnsafeSlow=function(n){return b(n)};function F(n,t){if((typeof t!="string"||t==="")&&(t="utf8"),!s.isEncoding(t))throw new TypeError("Unknown encoding: "+t);var e=S(n,t)|0,a=c(e),l=a.write(n,t);return l!==e&&(a=a.slice(0,l)),a}function j(n){for(var t=n.length<0?0:w(n.length)|0,e=c(t),a=0;a<t;a+=1)e[a]=n[a]&255;return e}function U(n){if(it(n,Uint8Array)){var t=new Uint8Array(n);return q(t.buffer,t.byteOffset,t.byteLength)}return j(n)}function q(n,t,e){if(t<0||n.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(n.byteLength<t+(e||0))throw new RangeError('"length" is outside of buffer bounds');var a;return t===void 0&&e===void 0?a=new Uint8Array(n):e===void 0?a=new Uint8Array(n,t):a=new Uint8Array(n,t,e),Object.setPrototypeOf(a,s.prototype),a}function Z(n){if(s.isBuffer(n)){var t=w(n.length)|0,e=c(t);return e.length===0||n.copy(e,0,0,t),e}if(n.length!==void 0)return typeof n.length!="number"||Ct(n.length)?c(0):j(n);if(n.type==="Buffer"&&Array.isArray(n.data))return j(n.data)}function w(n){if(n>=u)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+u.toString(16)+" bytes");return n|0}function E(n){return+n!=n&&(n=0),s.alloc(+n)}s.isBuffer=function(t){return t!=null&&t._isBuffer===!0&&t!==s.prototype},s.compare=function(t,e){if(it(t,Uint8Array)&&(t=s.from(t,t.offset,t.byteLength)),it(e,Uint8Array)&&(e=s.from(e,e.offset,e.byteLength)),!s.isBuffer(t)||!s.isBuffer(e))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===e)return 0;for(var a=t.length,l=e.length,x=0,d=Math.min(a,l);x<d;++x)if(t[x]!==e[x]){a=t[x],l=e[x];break}return a<l?-1:l<a?1:0},s.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}},s.concat=function(t,e){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(t.length===0)return s.alloc(0);var a;if(e===void 0)for(e=0,a=0;a<t.length;++a)e+=t[a].length;var l=s.allocUnsafe(e),x=0;for(a=0;a<t.length;++a){var d=t[a];if(it(d,Uint8Array))x+d.length>l.length?s.from(d).copy(l,x):Uint8Array.prototype.set.call(l,d,x);else if(s.isBuffer(d))d.copy(l,x);else throw new TypeError('"list" argument must be an Array of Buffers');x+=d.length}return l};function S(n,t){if(s.isBuffer(n))return n.length;if(ArrayBuffer.isView(n)||it(n,ArrayBuffer))return n.byteLength;if(typeof n!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof n);var e=n.length,a=arguments.length>2&&arguments[2]===!0;if(!a&&e===0)return 0;for(var l=!1;;)switch(t){case"ascii":case"latin1":case"binary":return e;case"utf8":case"utf-8":return V(n).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return e*2;case"hex":return e>>>1;case"base64":return lt(n).length;default:if(l)return a?-1:V(n).length;t=(""+t).toLowerCase(),l=!0}}s.byteLength=S;function z(n,t,e){var a=!1;if((t===void 0||t<0)&&(t=0),t>this.length||((e===void 0||e>this.length)&&(e=this.length),e<=0)||(e>>>=0,t>>>=0,e<=t))return"";for(n||(n="utf8");;)switch(n){case"hex":return A(this,t,e);case"utf8":case"utf-8":return m(this,t,e);case"ascii":return B(this,t,e);case"latin1":case"binary":return C(this,t,e);case"base64":return X(this,t,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return T(this,t,e);default:if(a)throw new TypeError("Unknown encoding: "+n);n=(n+"").toLowerCase(),a=!0}}s.prototype._isBuffer=!0;function J(n,t,e){var a=n[t];n[t]=n[e],n[e]=a}s.prototype.swap16=function(){var t=this.length;if(t%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;e<t;e+=2)J(this,e,e+1);return this},s.prototype.swap32=function(){var t=this.length;if(t%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;e<t;e+=4)J(this,e,e+3),J(this,e+1,e+2);return this},s.prototype.swap64=function(){var t=this.length;if(t%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;e<t;e+=8)J(this,e,e+7),J(this,e+1,e+6),J(this,e+2,e+5),J(this,e+3,e+4);return this},s.prototype.toString=function(){var t=this.length;return t===0?"":arguments.length===0?m(this,0,t):z.apply(this,arguments)},s.prototype.toLocaleString=s.prototype.toString,s.prototype.equals=function(t){if(!s.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t?!0:s.compare(this,t)===0},s.prototype.inspect=function(){var t="",e=r.INSPECT_MAX_BYTES;return t=this.toString("hex",0,e).replace(/(.{2})/g,"$1 ").trim(),this.length>e&&(t+=" ... "),"<Buffer "+t+">"},p&&(s.prototype[p]=s.prototype.inspect),s.prototype.compare=function(t,e,a,l,x){if(it(t,Uint8Array)&&(t=s.from(t,t.offset,t.byteLength)),!s.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(e===void 0&&(e=0),a===void 0&&(a=t?t.length:0),l===void 0&&(l=0),x===void 0&&(x=this.length),e<0||a>t.length||l<0||x>this.length)throw new RangeError("out of range index");if(l>=x&&e>=a)return 0;if(l>=x)return-1;if(e>=a)return 1;if(e>>>=0,a>>>=0,l>>>=0,x>>>=0,this===t)return 0;for(var d=x-l,k=a-e,N=Math.min(d,k),L=this.slice(l,x),G=t.slice(e,a),P=0;P<N;++P)if(L[P]!==G[P]){d=L[P],k=G[P];break}return d<k?-1:k<d?1:0};function W(n,t,e,a,l){if(n.length===0)return-1;if(typeof e=="string"?(a=e,e=0):e>2147483647?e=2147483647:e<-2147483648&&(e=-2147483648),e=+e,Ct(e)&&(e=l?0:n.length-1),e<0&&(e=n.length+e),e>=n.length){if(l)return-1;e=n.length-1}else if(e<0)if(l)e=0;else return-1;if(typeof t=="string"&&(t=s.from(t,a)),s.isBuffer(t))return t.length===0?-1:M(n,t,e,a,l);if(typeof t=="number")return t=t&255,typeof Uint8Array.prototype.indexOf=="function"?l?Uint8Array.prototype.indexOf.call(n,t,e):Uint8Array.prototype.lastIndexOf.call(n,t,e):M(n,[t],e,a,l);throw new TypeError("val must be string, number or Buffer")}function M(n,t,e,a,l){var x=1,d=n.length,k=t.length;if(a!==void 0&&(a=String(a).toLowerCase(),a==="ucs2"||a==="ucs-2"||a==="utf16le"||a==="utf-16le")){if(n.length<2||t.length<2)return-1;x=2,d/=2,k/=2,e/=2}function N(se,pe){return x===1?se[pe]:se.readUInt16BE(pe*x)}var L;if(l){var G=-1;for(L=e;L<d;L++)if(N(n,L)===N(t,G===-1?0:L-G)){if(G===-1&&(G=L),L-G+1===k)return G*x}else G!==-1&&(L-=L-G),G=-1}else for(e+k>d&&(e=d-k),L=e;L>=0;L--){for(var P=!0,Ft=0;Ft<k;Ft++)if(N(n,L+Ft)!==N(t,Ft)){P=!1;break}if(P)return L}return-1}s.prototype.includes=function(t,e,a){return this.indexOf(t,e,a)!==-1},s.prototype.indexOf=function(t,e,a){return W(this,t,e,a,!0)},s.prototype.lastIndexOf=function(t,e,a){return W(this,t,e,a,!1)};function ht(n,t,e,a){e=Number(e)||0;var l=n.length-e;a?(a=Number(a),a>l&&(a=l)):a=l;var x=t.length;a>x/2&&(a=x/2);for(var d=0;d<a;++d){var k=parseInt(t.substr(d*2,2),16);if(Ct(k))return d;n[e+d]=k}return d}function mt(n,t,e,a){return At(V(t,n.length-e),n,e,a)}function pt(n,t,e,a){return At(Q(t),n,e,a)}function ct(n,t,e,a){return At(lt(t),n,e,a)}function Ut(n,t,e,a){return At(tt(t,n.length-e),n,e,a)}s.prototype.write=function(t,e,a,l){if(e===void 0)l="utf8",a=this.length,e=0;else if(a===void 0&&typeof e=="string")l=e,a=this.length,e=0;else if(isFinite(e))e=e>>>0,isFinite(a)?(a=a>>>0,l===void 0&&(l="utf8")):(l=a,a=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");var x=this.length-e;if((a===void 0||a>x)&&(a=x),t.length>0&&(a<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");l||(l="utf8");for(var d=!1;;)switch(l){case"hex":return ht(this,t,e,a);case"utf8":case"utf-8":return mt(this,t,e,a);case"ascii":case"latin1":case"binary":return pt(this,t,e,a);case"base64":return ct(this,t,e,a);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Ut(this,t,e,a);default:if(d)throw new TypeError("Unknown encoding: "+l);l=(""+l).toLowerCase(),d=!0}},s.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function X(n,t,e){return t===0&&e===n.length?i.fromByteArray(n):i.fromByteArray(n.slice(t,e))}function m(n,t,e){e=Math.min(n.length,e);for(var a=[],l=t;l<e;){var x=n[l],d=null,k=x>239?4:x>223?3:x>191?2:1;if(l+k<=e){var N,L,G,P;switch(k){case 1:x<128&&(d=x);break;case 2:N=n[l+1],(N&192)===128&&(P=(x&31)<<6|N&63,P>127&&(d=P));break;case 3:N=n[l+1],L=n[l+2],(N&192)===128&&(L&192)===128&&(P=(x&15)<<12|(N&63)<<6|L&63,P>2047&&(P<55296||P>57343)&&(d=P));break;case 4:N=n[l+1],L=n[l+2],G=n[l+3],(N&192)===128&&(L&192)===128&&(G&192)===128&&(P=(x&15)<<18|(N&63)<<12|(L&63)<<6|G&63,P>65535&&P<1114112&&(d=P))}}d===null?(d=65533,k=1):d>65535&&(d-=65536,a.push(d>>>10&1023|55296),d=56320|d&1023),a.push(d),l+=k}return D(a)}var v=4096;function D(n){var t=n.length;if(t<=v)return String.fromCharCode.apply(String,n);for(var e="",a=0;a<t;)e+=String.fromCharCode.apply(String,n.slice(a,a+=v));return e}function B(n,t,e){var a="";e=Math.min(n.length,e);for(var l=t;l<e;++l)a+=String.fromCharCode(n[l]&127);return a}function C(n,t,e){var a="";e=Math.min(n.length,e);for(var l=t;l<e;++l)a+=String.fromCharCode(n[l]);return a}function A(n,t,e){var a=n.length;(!t||t<0)&&(t=0),(!e||e<0||e>a)&&(e=a);for(var l="",x=t;x<e;++x)l+=Qe[n[x]];return l}function T(n,t,e){for(var a=n.slice(t,e),l="",x=0;x<a.length-1;x+=2)l+=String.fromCharCode(a[x]+a[x+1]*256);return l}s.prototype.slice=function(t,e){var a=this.length;t=~~t,e=e===void 0?a:~~e,t<0?(t+=a,t<0&&(t=0)):t>a&&(t=a),e<0?(e+=a,e<0&&(e=0)):e>a&&(e=a),e<t&&(e=t);var l=this.subarray(t,e);return Object.setPrototypeOf(l,s.prototype),l};function O(n,t,e){if(n%1!==0||n<0)throw new RangeError("offset is not uint");if(n+t>e)throw new RangeError("Trying to access beyond buffer length")}s.prototype.readUintLE=s.prototype.readUIntLE=function(t,e,a){t=t>>>0,e=e>>>0,a||O(t,e,this.length);for(var l=this[t],x=1,d=0;++d<e&&(x*=256);)l+=this[t+d]*x;return l},s.prototype.readUintBE=s.prototype.readUIntBE=function(t,e,a){t=t>>>0,e=e>>>0,a||O(t,e,this.length);for(var l=this[t+--e],x=1;e>0&&(x*=256);)l+=this[t+--e]*x;return l},s.prototype.readUint8=s.prototype.readUInt8=function(t,e){return t=t>>>0,e||O(t,1,this.length),this[t]},s.prototype.readUint16LE=s.prototype.readUInt16LE=function(t,e){return t=t>>>0,e||O(t,2,this.length),this[t]|this[t+1]<<8},s.prototype.readUint16BE=s.prototype.readUInt16BE=function(t,e){return t=t>>>0,e||O(t,2,this.length),this[t]<<8|this[t+1]},s.prototype.readUint32LE=s.prototype.readUInt32LE=function(t,e){return t=t>>>0,e||O(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+this[t+3]*16777216},s.prototype.readUint32BE=s.prototype.readUInt32BE=function(t,e){return t=t>>>0,e||O(t,4,this.length),this[t]*16777216+(this[t+1]<<16|this[t+2]<<8|this[t+3])},s.prototype.readIntLE=function(t,e,a){t=t>>>0,e=e>>>0,a||O(t,e,this.length);for(var l=this[t],x=1,d=0;++d<e&&(x*=256);)l+=this[t+d]*x;return x*=128,l>=x&&(l-=Math.pow(2,8*e)),l},s.prototype.readIntBE=function(t,e,a){t=t>>>0,e=e>>>0,a||O(t,e,this.length);for(var l=e,x=1,d=this[t+--l];l>0&&(x*=256);)d+=this[t+--l]*x;return x*=128,d>=x&&(d-=Math.pow(2,8*e)),d},s.prototype.readInt8=function(t,e){return t=t>>>0,e||O(t,1,this.length),this[t]&128?(255-this[t]+1)*-1:this[t]},s.prototype.readInt16LE=function(t,e){t=t>>>0,e||O(t,2,this.length);var a=this[t]|this[t+1]<<8;return a&32768?a|4294901760:a},s.prototype.readInt16BE=function(t,e){t=t>>>0,e||O(t,2,this.length);var a=this[t+1]|this[t]<<8;return a&32768?a|4294901760:a},s.prototype.readInt32LE=function(t,e){return t=t>>>0,e||O(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},s.prototype.readInt32BE=function(t,e){return t=t>>>0,e||O(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},s.prototype.readFloatLE=function(t,e){return t=t>>>0,e||O(t,4,this.length),o.read(this,t,!0,23,4)},s.prototype.readFloatBE=function(t,e){return t=t>>>0,e||O(t,4,this.length),o.read(this,t,!1,23,4)},s.prototype.readDoubleLE=function(t,e){return t=t>>>0,e||O(t,8,this.length),o.read(this,t,!0,52,8)},s.prototype.readDoubleBE=function(t,e){return t=t>>>0,e||O(t,8,this.length),o.read(this,t,!1,52,8)};function I(n,t,e,a,l,x){if(!s.isBuffer(n))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>l||t<x)throw new RangeError('"value" argument is out of bounds');if(e+a>n.length)throw new RangeError("Index out of range")}s.prototype.writeUintLE=s.prototype.writeUIntLE=function(t,e,a,l){if(t=+t,e=e>>>0,a=a>>>0,!l){var x=Math.pow(2,8*a)-1;I(this,t,e,a,x,0)}var d=1,k=0;for(this[e]=t&255;++k<a&&(d*=256);)this[e+k]=t/d&255;return e+a},s.prototype.writeUintBE=s.prototype.writeUIntBE=function(t,e,a,l){if(t=+t,e=e>>>0,a=a>>>0,!l){var x=Math.pow(2,8*a)-1;I(this,t,e,a,x,0)}var d=a-1,k=1;for(this[e+d]=t&255;--d>=0&&(k*=256);)this[e+d]=t/k&255;return e+a},s.prototype.writeUint8=s.prototype.writeUInt8=function(t,e,a){return t=+t,e=e>>>0,a||I(this,t,e,1,255,0),this[e]=t&255,e+1},s.prototype.writeUint16LE=s.prototype.writeUInt16LE=function(t,e,a){return t=+t,e=e>>>0,a||I(this,t,e,2,65535,0),this[e]=t&255,this[e+1]=t>>>8,e+2},s.prototype.writeUint16BE=s.prototype.writeUInt16BE=function(t,e,a){return t=+t,e=e>>>0,a||I(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=t&255,e+2},s.prototype.writeUint32LE=s.prototype.writeUInt32LE=function(t,e,a){return t=+t,e=e>>>0,a||I(this,t,e,4,4294967295,0),this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=t&255,e+4},s.prototype.writeUint32BE=s.prototype.writeUInt32BE=function(t,e,a){return t=+t,e=e>>>0,a||I(this,t,e,4,4294967295,0),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=t&255,e+4},s.prototype.writeIntLE=function(t,e,a,l){if(t=+t,e=e>>>0,!l){var x=Math.pow(2,8*a-1);I(this,t,e,a,x-1,-x)}var d=0,k=1,N=0;for(this[e]=t&255;++d<a&&(k*=256);)t<0&&N===0&&this[e+d-1]!==0&&(N=1),this[e+d]=(t/k>>0)-N&255;return e+a},s.prototype.writeIntBE=function(t,e,a,l){if(t=+t,e=e>>>0,!l){var x=Math.pow(2,8*a-1);I(this,t,e,a,x-1,-x)}var d=a-1,k=1,N=0;for(this[e+d]=t&255;--d>=0&&(k*=256);)t<0&&N===0&&this[e+d+1]!==0&&(N=1),this[e+d]=(t/k>>0)-N&255;return e+a},s.prototype.writeInt8=function(t,e,a){return t=+t,e=e>>>0,a||I(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=t&255,e+1},s.prototype.writeInt16LE=function(t,e,a){return t=+t,e=e>>>0,a||I(this,t,e,2,32767,-32768),this[e]=t&255,this[e+1]=t>>>8,e+2},s.prototype.writeInt16BE=function(t,e,a){return t=+t,e=e>>>0,a||I(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=t&255,e+2},s.prototype.writeInt32LE=function(t,e,a){return t=+t,e=e>>>0,a||I(this,t,e,4,2147483647,-2147483648),this[e]=t&255,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4},s.prototype.writeInt32BE=function(t,e,a){return t=+t,e=e>>>0,a||I(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=t&255,e+4};function R(n,t,e,a,l,x){if(e+a>n.length)throw new RangeError("Index out of range");if(e<0)throw new RangeError("Index out of range")}function H(n,t,e,a,l){return t=+t,e=e>>>0,l||R(n,t,e,4),o.write(n,t,e,a,23,4),e+4}s.prototype.writeFloatLE=function(t,e,a){return H(this,t,e,!0,a)},s.prototype.writeFloatBE=function(t,e,a){return H(this,t,e,!1,a)};function $(n,t,e,a,l){return t=+t,e=e>>>0,l||R(n,t,e,8),o.write(n,t,e,a,52,8),e+8}s.prototype.writeDoubleLE=function(t,e,a){return $(this,t,e,!0,a)},s.prototype.writeDoubleBE=function(t,e,a){return $(this,t,e,!1,a)},s.prototype.copy=function(t,e,a,l){if(!s.isBuffer(t))throw new TypeError("argument should be a Buffer");if(a||(a=0),!l&&l!==0&&(l=this.length),e>=t.length&&(e=t.length),e||(e=0),l>0&&l<a&&(l=a),l===a||t.length===0||this.length===0)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(a<0||a>=this.length)throw new RangeError("Index out of range");if(l<0)throw new RangeError("sourceEnd out of bounds");l>this.length&&(l=this.length),t.length-e<l-a&&(l=t.length-e+a);var x=l-a;return this===t&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(e,a,l):Uint8Array.prototype.set.call(t,this.subarray(a,l),e),x},s.prototype.fill=function(t,e,a,l){if(typeof t=="string"){if(typeof e=="string"?(l=e,e=0,a=this.length):typeof a=="string"&&(l=a,a=this.length),l!==void 0&&typeof l!="string")throw new TypeError("encoding must be a string");if(typeof l=="string"&&!s.isEncoding(l))throw new TypeError("Unknown encoding: "+l);if(t.length===1){var x=t.charCodeAt(0);(l==="utf8"&&x<128||l==="latin1")&&(t=x)}}else typeof t=="number"?t=t&255:typeof t=="boolean"&&(t=Number(t));if(e<0||this.length<e||this.length<a)throw new RangeError("Out of range index");if(a<=e)return this;e=e>>>0,a=a===void 0?this.length:a>>>0,t||(t=0);var d;if(typeof t=="number")for(d=e;d<a;++d)this[d]=t;else{var k=s.isBuffer(t)?t:s.from(t,l),N=k.length;if(N===0)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(d=0;d<a-e;++d)this[d+e]=k[d%N]}return this};var K=/[^+/0-9A-Za-z-_]/g;function Y(n){if(n=n.split("=")[0],n=n.trim().replace(K,""),n.length<2)return"";for(;n.length%4!==0;)n=n+"=";return n}function V(n,t){t=t||1/0;for(var e,a=n.length,l=null,x=[],d=0;d<a;++d){if(e=n.charCodeAt(d),e>55295&&e<57344){if(!l){if(e>56319){(t-=3)>-1&&x.push(239,191,189);continue}else if(d+1===a){(t-=3)>-1&&x.push(239,191,189);continue}l=e;continue}if(e<56320){(t-=3)>-1&&x.push(239,191,189),l=e;continue}e=(l-55296<<10|e-56320)+65536}else l&&(t-=3)>-1&&x.push(239,191,189);if(l=null,e<128){if((t-=1)<0)break;x.push(e)}else if(e<2048){if((t-=2)<0)break;x.push(e>>6|192,e&63|128)}else if(e<65536){if((t-=3)<0)break;x.push(e>>12|224,e>>6&63|128,e&63|128)}else if(e<1114112){if((t-=4)<0)break;x.push(e>>18|240,e>>12&63|128,e>>6&63|128,e&63|128)}else throw new Error("Invalid code point")}return x}function Q(n){for(var t=[],e=0;e<n.length;++e)t.push(n.charCodeAt(e)&255);return t}function tt(n,t){for(var e,a,l,x=[],d=0;d<n.length&&!((t-=2)<0);++d)e=n.charCodeAt(d),a=e>>8,l=e%256,x.push(l),x.push(a);return x}function lt(n){return i.toByteArray(Y(n))}function At(n,t,e,a){for(var l=0;l<a&&!(l+e>=t.length||l>=n.length);++l)t[l+e]=n[l];return l}function it(n,t){return n instanceof t||n!=null&&n.constructor!=null&&n.constructor.name!=null&&n.constructor.name===t.name}function Ct(n){return n!==n}var Qe=function(){for(var n="0123456789abcdef",t=new Array(256),e=0;e<16;++e)for(var a=e*16,l=0;l<16;++l)t[a+l]=n[e]+n[l];return t}()})(Oe);/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */(function(r,i){var o=Oe,p=o.Buffer;function u(c,s){for(var h in c)s[h]=c[h]}p.from&&p.alloc&&p.allocUnsafe&&p.allocUnsafeSlow?r.exports=o:(u(o,i),i.Buffer=f);function f(c,s,h){return p(c,s,h)}f.prototype=Object.create(p.prototype),u(p,f),f.from=function(c,s,h){if(typeof c=="number")throw new TypeError("Argument must not be a number");return p(c,s,h)},f.alloc=function(c,s,h){if(typeof c!="number")throw new TypeError("Argument must be a number");var g=p(c);return s!==void 0?typeof h=="string"?g.fill(s,h):g.fill(s):g.fill(0),g},f.allocUnsafe=function(c){if(typeof c!="number")throw new TypeError("Argument must be a number");return p(c)},f.allocUnsafeSlow=function(c){if(typeof c!="number")throw new TypeError("Argument must be a number");return o.SlowBuffer(c)}})(Rt,Rt.exports);var Zt=Rt.exports,Ie=Zt.Buffer;function Dt(r,i){this._block=Ie.alloc(r),this._finalSize=i,this._blockSize=r,this._len=0}Dt.prototype.update=function(r,i){typeof r=="string"&&(i=i||"utf8",r=Ie.from(r,i));for(var o=this._block,p=this._blockSize,u=r.length,f=this._len,c=0;c<u;){for(var s=f%p,h=Math.min(u-c,p-s),g=0;g<h;g++)o[s+g]=r[c+g];f+=h,c+=h,f%p===0&&this._update(o)}return this._len+=u,this};Dt.prototype.digest=function(r){var i=this._len%this._blockSize;this._block[i]=128,this._block.fill(0,i+1),i>=this._finalSize&&(this._update(this._block),this._block.fill(0));var o=this._len*8;if(o<=4294967295)this._block.writeUInt32BE(o,this._blockSize-4);else{var p=(o&4294967295)>>>0,u=(o-p)/4294967296;this._block.writeUInt32BE(u,this._blockSize-8),this._block.writeUInt32BE(p,this._blockSize-4)}this._update(this._block);var f=this._hash();return r?f.toString(r):f};Dt.prototype._update=function(){throw new Error("_update must be implemented by subclass")};var je=Dt,Ar=Fe,De=je,Fr=Zt.Buffer,Or=[1518500249,1859775393,-1894007588,-899497514],Br=new Array(80);function vt(){this.init(),this._w=Br,De.call(this,64,56)}Ar(vt,De);vt.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function Ir(r){return r<<1|r>>>31}function jr(r){return r<<5|r>>>27}function Dr(r){return r<<30|r>>>2}function Tr(r,i,o,p){return r===0?i&o|~i&p:r===2?i&o|i&p|o&p:i^o^p}vt.prototype._update=function(r){for(var i=this._w,o=this._a|0,p=this._b|0,u=this._c|0,f=this._d|0,c=this._e|0,s=0;s<16;++s)i[s]=r.readInt32BE(s*4);for(;s<80;++s)i[s]=Ir(i[s-3]^i[s-8]^i[s-14]^i[s-16]);for(var h=0;h<80;++h){var g=~~(h/20),y=jr(o)+Tr(g,p,u,f)+c+i[h]+Or[g]|0;c=f,f=u,u=Dr(p),p=o,o=y}this._a=o+this._a|0,this._b=p+this._b|0,this._c=u+this._c|0,this._d=f+this._d|0,this._e=c+this._e|0};vt.prototype._hash=function(){var r=Fr.allocUnsafe(20);return r.writeInt32BE(this._a|0,0),r.writeInt32BE(this._b|0,4),r.writeInt32BE(this._c|0,8),r.writeInt32BE(this._d|0,12),r.writeInt32BE(this._e|0,16),r};var kr=vt;const Ur=Kt(kr);var Cr=Fe,Te=je,$r=Zt.Buffer,Nr=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],zr=new Array(64);function _t(){this.init(),this._w=zr,Te.call(this,64,56)}Cr(_t,Te);_t.prototype.init=function(){return this._a=1779033703,this._b=3144134277,this._c=1013904242,this._d=2773480762,this._e=1359893119,this._f=2600822924,this._g=528734635,this._h=1541459225,this};function Mr(r,i,o){return o^r&(i^o)}function Rr(r,i,o){return r&i|o&(r|i)}function Lr(r){return(r>>>2|r<<30)^(r>>>13|r<<19)^(r>>>22|r<<10)}function Pr(r){return(r>>>6|r<<26)^(r>>>11|r<<21)^(r>>>25|r<<7)}function qr(r){return(r>>>7|r<<25)^(r>>>18|r<<14)^r>>>3}function Hr(r){return(r>>>17|r<<15)^(r>>>19|r<<13)^r>>>10}_t.prototype._update=function(r){for(var i=this._w,o=this._a|0,p=this._b|0,u=this._c|0,f=this._d|0,c=this._e|0,s=this._f|0,h=this._g|0,g=this._h|0,y=0;y<16;++y)i[y]=r.readInt32BE(y*4);for(;y<64;++y)i[y]=Hr(i[y-2])+i[y-7]+qr(i[y-15])+i[y-16]|0;for(var b=0;b<64;++b){var F=g+Pr(c)+Mr(c,s,h)+Nr[b]+i[b]|0,j=Lr(o)+Rr(o,p,u)|0;g=h,h=s,s=c,c=f+F|0,f=u,u=p,p=o,o=F+j|0}this._a=o+this._a|0,this._b=p+this._b|0,this._c=u+this._c|0,this._d=f+this._d|0,this._e=c+this._e|0,this._f=s+this._f|0,this._g=h+this._g|0,this._h=g+this._h|0};_t.prototype._hash=function(){var r=$r.allocUnsafe(32);return r.writeInt32BE(this._a,0),r.writeInt32BE(this._b,4),r.writeInt32BE(this._c,8),r.writeInt32BE(this._d,12),r.writeInt32BE(this._e,16),r.writeInt32BE(this._f,20),r.writeInt32BE(this._g,24),r.writeInt32BE(this._h,28),r};var Jr=_t;const Wr=Kt(Jr),Yt=new Error("File system not available.");function Xr(r,i,o){throw Yt}function ke(r){throw Yt}function Vr(r){throw Yt}const Kr=async r=>ke(),Gr={sha1:Ur,sha256:Wr},Tt=(r,i="sha1")=>{if(!["sha1","sha256"].includes(i))throw new Error("Hashing algorithm not supported: Available: sha1, sha256");const o=Gr[i];return new o().update(r).digest("base64")};function Ue(r){const i=[],o=Object.keys(r);for(const p of o){const u=r[p].sort((f,c)=>f.index-c.index);for(let f=0;f<u.length;f++)u[f].index!==f&&i.push({message:`Invalid operation index ${u[f].index} at position ${f}`,details:{position:f,operation:u[f],scope:u[f].scope}})}return i}const Qt=async r=>{const i=new ce,{name:o,revision:p,documentType:u,created:f,lastModified:c}=r,s={name:o,revision:p,documentType:u,created:f,lastModified:c};return i.file("header.json",JSON.stringify(s,null,2)),i.file("state.json",JSON.stringify(r.initialState||{},null,2)),i.file("operations.json",JSON.stringify(r.operations,null,2)),Object.keys(r.attachments).forEach(g=>{const{data:y,...b}=r.attachments[g];i.file(g,y,{base64:!0,createFolders:!0,comment:JSON.stringify(b)})}),i},Ce=async(r,i,o,p)=>{await(await Qt(r)).generateAsync({type:"uint8array",streamFiles:!0});const f=p??r.name,c=`.${o}.zip`;return Xr(i,f.endsWith(c)?f:`${f}${c}`)},Zr=async(r,i)=>{const p=await(await Qt(r)).generateAsync({type:"blob"}),u=await i.createWritable();await u.write(p),await u.close()},Lt=async(r,i,o)=>{const p=ke();return $e(p,i,o)},$e=async(r,i,o)=>{const p=new ce;return await p.loadAsync(r),Yr(p,i,o)};async function Yr(r,i,o){const p=r.file("state.json");if(!p)throw new Error("Initial state not found");const u=await p.async("string"),f=JSON.parse(u),c=r.file("header.json");let s;c&&(s=JSON.parse(await c.async("string")));const h=r.file("operations.json");if(!h)throw new Error("Operations history not found");const g=JSON.parse(await h.async("string")),y=Ue(g);if(y.length){const F=y.map(j=>j.message);throw new Error(F.join(`
25
+ `))}let b=ne(f,g,i,void 0,s,{},o);return s&&(b={...b,...s}),b}function Ne(r){const i=r.replace(/^.*\./,"")||void 0,o=r.replace(/^.*[/\\]/,"")||void 0;return{extension:i,fileName:o}}async function Qr(r){const{buffer:i,mimeType:o="application/octet-stream"}=await Vr(),p=Ne(r),u=i.toString("base64");return{data:u,hash:Tt(u),mimeType:o,...p}}async function ti(r){const i=await Kr(),o=dr.getType(r)||"application/octet-stream",p=Ne(r),u=i.toString("base64");return{data:u,hash:Tt(u),mimeType:o,...p}}var ze=(r=>(r.UNEXPECTED_INDEX="UNEXPECTED_INDEX",r))(ze||{}),Me=(r=>(r.DUPLICATED_INDEX="DUPLICATED_INDEX",r.MISSING_INDEX="MISSING_INDEX",r))(Me||{});function te(r){const i=[];let o=-1;for(const p of r){const u=p.index-p.skip;u!==o+1&&i.push({operation:{index:p.index,skip:p.skip},issue:"UNEXPECTED_INDEX",category:u>o+1?"MISSING_INDEX":"DUPLICATED_INDEX",message:`Expected index ${o+1} with skip 0 or equivalent, got index ${p.index} with skip ${p.skip}`}),o=p.index}return i}function at(r){var p,u,f;const i=[];let o=r.length-1;for(;o>-1;){i.unshift(r[o]);const c=(((p=r[o])==null?void 0:p.index)||0)-(((u=r[o])==null?void 0:u.skip)||0)-1;let s=o-1;for(;s>-1&&(((f=r[s])==null?void 0:f.index)||0)>c;)s--;o=s}return i}function ei(r){const i=[...r],o=i[i.length-1];return o&&(o.type==="NOOP"?i.push({...o,index:o.index,type:"NOOP",skip:Pe(r)}):i.push({type:"NOOP",index:o.index+1,timestamp:new Date().toISOString(),input:{},skip:1,scope:o.scope,hash:o.hash})),i}function st(r){return r.slice().sort((i,o)=>i.skip-o.skip).sort((i,o)=>i.index-o.index)}const ri=(r,i,o)=>[...i,...o].sort((p,u)=>new Date(p.timestamp).getTime()-new Date(u.timestamp).getTime()).map((p,u)=>({...p,index:r.index+u,skip:u===0?r.skip:0})),ii=(r,i,o)=>[...i,...o].sort((p,u)=>new Date(p.timestamp).getTime()-new Date(u.timestamp).getTime()).sort((p,u)=>p.index-u.index).map((p,u)=>({...p,index:r.index+u,skip:u===0?r.skip:0}));function ee(r,i){return gt(r)===gt(i)}function ni(r,i){const o=at(st(r.slice())),p=at(st(i.slice()));if(o.length<1)return[p,[]];const u=[];let f=!1;for(;p.length>0;){const c=p[0];let s=o.shift();for(;s&&Re(s,c);)u.push(s),s=o.shift();if(s?f||(ee(s,c)?(p.shift(),u.push(s)):(o.unshift(s),f=!0)):f=!0,f){let h=p.shift();for(;h;)u.push(h),h=p.shift()}}if(!f){let c=o.shift();for(;c;)u.push(c),c=o.shift()}return[at(u),o]}function Re(r,i){return r.index<i.index||r.index===i.index&&r.skip<i.skip}function Le(r,i){const o=[],p=[],u=[],f=Math.max(r.length,i.length);let c=!1;for(let s=0;s<f;s++){const h=r[s],g=i[s];h&&g?!c&&ee(h,g)?o.push(h):(c=!0,p.push(h),u.push(g)):h?p.push(h):g&&u.push(g)}return[o,p,u]}function oi(r,i,o){const[p,u,f]=Le(at(r),at(i)),c=Nt(p),s=1+Math.max(c,Nt(u),Nt(f)),h=o({index:s,skip:s-(c+1)},u,f);return p.concat(h)}function Nt(r){const i=r[r.length-1];return i?i.index:-1}function Pe(r){var p,u,f;if(r.length<1)return-1;const i=at(r);let o=(((p=i[i.length-1])==null?void 0:p.skip)||0)+1;return i.length>1&&(o+=((u=i[i.length-2])==null?void 0:u.skip)||0),(((f=i[i.length-1])==null?void 0:f.index)||-1)<o?-1:o}const ai=r=>te(at(st(r))),si=r=>r.reduce((o,p)=>{var u;return o[p.scope]||(o[p.scope]=[]),(u=o[p.scope])==null||u.push(p),o},{}),pi=(r,i)=>{var h;const o={integrityIssues:[],validOperations:[],invalidOperations:[],duplicatedOperations:[]},p=st(r),u=st(i),f=te([...p,...u]),s=(h=[...f.filter(g=>g.category==="MISSING_INDEX")].sort((g,y)=>y.operation.index-g.operation.index).pop())==null?void 0:h.operation;for(const g of u){if(s&&g.index>=s.index){o.invalidOperations.push(g);continue}if(f.some(b=>b.operation.index===g.index&&b.operation.skip===g.skip&&b.category==="DUPLICATED_INDEX")){o.duplicatedOperations.push(g);continue}o.validOperations.push(g)}return o.integrityIssues.push(...f),o};function ci(r,i){return r.filter(o=>!i.some(p=>o.type==="NOOP"&&o.skip===0&&o.index===p.index||o.index===p.index&&o.skip===p.skip&&o.scope===p.scope&&o.hash===p.hash&&o.type===p.type))}function qe(r,i){const[o]=st(r).slice(-1),p=(o==null?void 0:o.index)??-1,u=p+1,f={...i,index:i.index??u};if(f.index<p)throw new Error(`The skip header operation index must be greater than or equal to ${p}`);return(at(st([...r,f]))||[]).slice(0,-1)}function Pt(r){return{...Object.entries(r).reduce((o,p)=>{const[u,f]=p;return{...o,[u]:at(st(f))}},{})}}const li=Object.freeze(Object.defineProperty({__proto__:null,IntegrityIssueSubType:Me,IntegrityIssueType:ze,addUndo:ei,attachBranch:ni,checkCleanedOperationsIntegrity:te,checkOperationsIntegrity:ai,garbageCollect:at,garbageCollectDocumentOperations:Pt,groupOperationsByScope:si,merge:oi,nextSkipNumber:Pe,operationsAreEqual:ee,precedes:Re,prepareOperations:pi,removeExistingOperations:ci,reshuffleByTimestamp:ri,reshuffleByTimestampAndIndex:ii,skipHeaderOperations:qe,sortOperations:st,split:Le},Symbol.toStringTag,{value:"Module"}));function ui(r,i){let o;return"index"in i?o={...i}:o=r.operations[i.scope].at(-1),((o==null?void 0:o.index)??-1)+1}function re(r,i){return{...r,revision:{...r.revision,[i.scope]:ui(r,i)},lastModified:new Date().toISOString()}}function fi(r,i,o=0){if([bt,St,It].includes(i.type))return r;const{scope:p}=i,u=r.operations[p].slice(),f=u.at(-1);let c=((f==null?void 0:f.index)??-1)+1;if("index"in i){if(i.index-o>c)throw new Error(`Missing operations: expected ${c} with skip 0 or equivalent, got index ${i.index} with skip ${o}`);c=i.index}return u.push({...i,index:c,timestamp:new Date().toISOString(),hash:"",scope:p,skip:o,error:void 0}),{...r,operations:{...r.operations,[p]:u}}}function He(r,i,o=0){let p=fi(r,i,o);return p=re(p,i),p}function hi(r,i,o){switch(de().parse(i),i.type){case ve:return cr(r,i.input);case It:return fr(r,i,o);case _e:return hr(r,i.input.state);default:return r}}function mi(r,i,o){switch(i.type){case bt:return lr(r,i,o);case St:return ur(r,i,o);default:return{document:r,action:i,skip:o}}}function xi(r,i,o,p,u=!1,f=oe){const c=i.scope,s=r.operations[c].at(-1);if(!s)return r;const h=Pt({...r.operations,[c]:qe(r.operations[c],s)});let g;const y=h[c].at(-1);if(u&&(y!=null&&y.resultingState))g=f(y.resultingState);else{const{state:b}=Bt(r.initialState,h,o,void 0,void 0,void 0,void 0,{reuseHash:!0,reuseOperationResultingState:u,operationResultingStateParser:f});g=b[c]}return{...r,state:{...r.state,[c]:g},operations:Pt({...r.operations})}}function ie(r,i,o,p,u={}){const{skip:f,ignoreSkipOperations:c=!1,reuseHash:s=!1,reuseOperationResultingState:h=!1,operationResultingStateParser:g}=u,y={...i},b=f||0;let F={...r};const j=!c&&(b>0||"index"in y&&y.skip>0);return qt(y)&&(F=hi(F,y,o)),F=He(F,y,b),j&&(F=xi(F,y,o,b,h,g)),F=nt.produce(F,U=>{try{const q=o(U.state,y,p);if(q)return nt.castDraft({...F,state:q})}catch(q){const Z=F.operations[y.scope].length-1;U.operations[y.scope][Z].error=q.message,U.operations[y.scope][Z].skip=0,j&&(U.state=nt.castDraft({...r.state}),U.operations=nt.castDraft({...r.operations,[y.scope]:[...r.operations[y.scope],{...U.operations[y.scope][Z]}]}))}}),nt.produce(F,U=>{if([bt,St,It].includes(y.type))return U;const q=y.scope||"global",Z=s&&Object.prototype.hasOwnProperty.call(y,"hash")?y.hash:kt(U,q),w=U.operations[q].at(-1);w&&(w.hash=Z,h&&(w.resultingState=U.state[q]),!qt(y)&&y.attachments&&y.attachments.forEach(E=>{const{hash:S,...z}=E;U.attachments[S]={...z}}))})}function di(r){return r.type===mr&&r.skip!==void 0&&r.skip>0&&r.hash!==void 0}function gi(r){return[bt,St].includes(r.type)}function qt(r){return[ve,bt,St,It,_e].includes(r.type)}function ft(r,i,o,p,u="global"){if(!r)throw new Error("Empty action type");if(typeof r!="string")throw new Error(`Invalid action type: ${JSON.stringify(r)}`);const f={type:r,input:i,scope:u};o&&(f.attachments=o);try{p==null||p().parse(f.input)}catch(c){throw new Error(`Invalid action input: ${c}`)}return f}function Je(r,i=ie){return(o,p,u,f)=>i(o,p,r,u,f)}const We=(r,i)=>({name:"",documentType:"",revision:{global:0,local:0},created:new Date().toISOString(),lastModified:new Date().toISOString(),attachments:{},...r,state:(i==null?void 0:i(r==null?void 0:r.state))??(r==null?void 0:r.state)??{global:{},local:{}}}),Xe=(r,i)=>{const o=We(r,i);return{...o,initialState:o,operations:{global:[],local:[]},clipboard:[]}},kt=(r,i="global")=>Tt(gt(r.state[i]||"")),yi=(r,i=1e3)=>{const o=Math.random()*i;return Tt(`${(r??new Date).toISOString()}${o}`)};function wt(r){return nt.castImmutable(nt.freeze(r,!0))}function wi(r,i){const o=[...r];let p=i||0,u=o.length>0?o[o.length-1].index:0;const f=[];for(const c of o.reverse()){if(p>0){const g=u-c.index;p-=g}if(p<0)throw new Error("Invalid operation index, missing operations");const s={ignore:p>0,operation:c},h=c.skip>0?c.skip+1:0;if(h>0&&h>p){const g=h-p;p=p+g}u=c.index,f.push(s)}return f.reverse()}function Ei(r,i,o){const p=r.slice().sort((s,h)=>s.skip-h.skip).sort((s,h)=>s.index-h.index);let u=o,f=0,c=i;for(const s of p.reverse()){const h=c-s.index;if(u=u-h,u>-1)f++,c=s.index;else break}return f}function bi(r){return Object.values(r).flatMap(i=>i).sort((i,o)=>new Date(i.timestamp).getTime()-new Date(o.timestamp).getTime())}function Si(r){return Object.values(r).flatMap(i=>i).sort((i,o)=>new Date(i.operation.timestamp).getTime()-new Date(o.operation.timestamp).getTime())}function Bt(r,i,o,p,u,f=ie,c={},s){const h=Je(o,f);return ne(r,i,h,p,u,c,s)}function ne(r,i,o,p,u,f={},c){const{checkHashes:s=!0,reuseOperationResultingState:h,operationResultingStateParser:g=oe}=c||{};let y=r;const b=[],F={global:[],local:[]};if(h)for(const[w,E]of Object.entries(i)){const S=E.findLastIndex(J=>!!J.resultingState);if(S<0){b.push(...E);continue}const z=E[S];try{const J=g(z.resultingState);y={...y,state:{...y.state,[w]:J}},F[w].push(...E.slice(0,S+1)),b.push(...E.slice(S+1))}catch{b.push(...E)}}else b.push(...Object.values(i).flat());const j=Xe(y);j.initialState=r,j.operations=F;let U=j;if(b.length)U=b.reduce((w,E)=>o(w,E,p,{skip:E.skip,ignoreSkipOperations:!0,reuseHash:!s}),j);else for(const w of Object.values(F)){const E=w.at(-1);E&&(U=re(U,E))}if(!s)for(const w of Object.keys(U.state))for(let E=b.length-1;E>=0;E--){const S=b[E];if(S.scope===w){if(S.hash!==kt(U,w))throw new Error(`Hash mismatch for scope ${w}`);break}}const q=Object.keys(U.operations).reduce((w,E)=>{const S=E;return{...w,[S]:[...U.operations[S].map((z,J)=>{var W;return{...z,timestamp:((W=i[S][J])==null?void 0:W.timestamp)??z.timestamp}})]}},{global:[],local:[]}),Z=Object.values(q).reduce((w,E)=>{const S=E[E.length-1];return(S==null?void 0:S.timestamp)>w&&(w=S.timestamp),w},r.lastModified);return{...U,operations:q,lastModified:Z}}function vi(r,i){return gt(r)===gt(i)}function oe(r){const i=typeof r;if(i==="string")return JSON.parse(r);if(i==="object")return r;throw new Error(`Providing resulting state is of type: ${i}`)}const Ve=r=>ft("SET_NAME",r,void 0,Xt,void 0),Ke=(r=1,i="global")=>ft("UNDO",r,void 0,Vt,i),Ge=(r=1,i="global")=>ft("REDO",r,void 0,Wt,i),Ze=(r,i,o="global")=>ft("PRUNE",{start:r,end:i},void 0,Jt,o),ae=(r,i)=>ft("LOAD_STATE",{state:r,operations:i},void 0,Ht),Ye=(r="global")=>ft("NOOP",{},void 0,void 0,r),_i=Object.freeze(Object.defineProperty({__proto__:null,loadState:ae,noop:Ye,prune:Ze,redo:Ge,setName:Ve,undo:Ke},Symbol.toStringTag,{value:"Module"}));class Ai{constructor(i,o,p){Ot(this,"_document");Ot(this,"_reducer");Ot(this,"_signalDispatch");this._reducer=i,this._document=o,this._signalDispatch=p}dispatch(i,o){return this._document=this._reducer(this._document,i,this._signalDispatch,o),this}saveToFile(i,o,p){return Ce(this._document,i,o,p)}async loadFromFile(i){this._document=await Lt(i,this._reducer)}static async stateFromFile(i,o){return await Lt(i,o)}get state(){return wt(this._document.state)}get operations(){return wt(this._document.operations)}get name(){return this._document.name}get documentType(){return this._document.documentType}get created(){return this._document.created}get lastModified(){return this._document.lastModified}get revision(){return this._document.revision.global}getRevision(i){return this._document.revision[i]}get initialState(){return wt(this._document.initialState)}toDocument(){return wt(this._document)}getAttachment(i){return this._document.attachments[i]}setName(i){return this.dispatch(Ve(i)),this}undo(i){return this.dispatch(Ke(i)),this}redo(i){return this.dispatch(Ge(i)),this}prune(i,o){return this.dispatch(Ze(i,o)),this}loadState(i,o){return this.dispatch(ae(i,o)),this}}function Fi(r,i){i.forEach(o=>{Object.getOwnPropertyNames(o.prototype).forEach(p=>{Object.defineProperty(r.prototype,p,Object.getOwnPropertyDescriptor(o.prototype,p)||Object.create(null))})})}exports.BaseActions=_i;exports.BaseDocument=Ai;exports.applyMixins=Fi;exports.baseReducer=ie;exports.calculateSkipsLeft=Ei;exports.createAction=ft;exports.createDocument=Xe;exports.createExtendedState=We;exports.createReducer=Je;exports.createZip=Qt;exports.documentHelpers=li;exports.getLocalFile=ti;exports.getRemoteFile=Qr;exports.hashDocument=kt;exports.hashKey=yi;exports.isBaseAction=qt;exports.isNoopOperation=di;exports.isSameDocument=vi;exports.isUndoRedo=gi;exports.loadFromFile=Lt;exports.loadFromInput=$e;exports.mapSkippedOperations=wi;exports.parseResultingState=oe;exports.processUndoRedo=mi;exports.readOnly=wt;exports.replayDocument=ne;exports.replayOperations=Bt;exports.saveToFile=Ce;exports.saveToFileHandle=Zr;exports.sortMappedOperations=Si;exports.sortOperations=bi;exports.updateDocument=He;exports.updateHeader=re;exports.validateOperations=Ue;exports.zod=sr;
@@ -1,7 +1,7 @@
1
- import "./internal/object-iTBekDVP.js";
1
+ import "./internal/object-BW-G4r5m.js";
2
2
  import "immer";
3
3
  import "jszip";
4
- import { b as i, a as l, c as m, d as r, m as u, r as c, u as n, v as p, g as v, h as M, f as S, e as f, z as h } from "./internal/index-DQztOVJu.js";
4
+ import { b as i, a as l, c as m, d as r, m as u, r as c, u as n, v as p, g as v, h as M, f as S, e as f, z as h } from "./internal/index-BD2hB9El.js";
5
5
  import "zod";
6
6
  export {
7
7
  i as Document,
@@ -1,14 +1,16 @@
1
- import { B as i, h as p, g as t, E as m, F as c, G as n } from "./internal/object-iTBekDVP.js";
2
- import { i as u } from "./internal/index-BVJxzkIs.js";
1
+ import { B as p, h as r, g as i, E as m, F as d, G as u, H as c, I as n } from "./internal/object-BW-G4r5m.js";
2
+ import { i as f } from "./internal/index-2Qq00NLA.js";
3
3
  import "immer";
4
4
  import "zod";
5
5
  import "jszip";
6
6
  export {
7
- i as BaseDocument,
8
- p as actions,
9
- t as applyMixins,
7
+ p as BaseDocument,
8
+ r as actions,
9
+ i as applyMixins,
10
10
  m as baseReducer,
11
- c as processUndoRedo,
12
- u as utils,
11
+ d as processUndoRedo,
12
+ u as updateDocument,
13
+ c as updateHeader,
14
+ f as utils,
13
15
  n as z
14
16
  };
@@ -1,6 +1,6 @@
1
- import { D as o } from "./internal/index-BVJxzkIs.js";
2
- import { D as e } from "./internal/index-DQztOVJu.js";
3
- import "./internal/object-iTBekDVP.js";
1
+ import { D as o } from "./internal/index-2Qq00NLA.js";
2
+ import { D as e } from "./internal/index-BD2hB9El.js";
3
+ import "./internal/object-BW-G4r5m.js";
4
4
  import "immer";
5
5
  import "zod";
6
6
  import "jszip";
@@ -0,0 +1,46 @@
1
+ import { j as e, f as a, b as s, a as t, c as o, k as r, m as n, n as i, o as p, p as c, q as l, i as d, r as u, t as m, u as O, l as y, e as D, v as S, w as b, x as g, y as F, z as _, s as f, d as v, A as R, C as h, D as j, B as x, h as z, g as A, E as B, F as H, G as M, H as T, I as k } from "./object-BW-G4r5m.js";
2
+ const E = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
3
+ __proto__: null,
4
+ calculateSkipsLeft: e,
5
+ createAction: a,
6
+ createDocument: s,
7
+ createExtendedState: t,
8
+ createReducer: o,
9
+ createZip: r,
10
+ documentHelpers: n,
11
+ getLocalFile: i,
12
+ getRemoteFile: p,
13
+ hashDocument: c,
14
+ hashKey: l,
15
+ isBaseAction: d,
16
+ isNoopOperation: u,
17
+ isSameDocument: m,
18
+ isUndoRedo: O,
19
+ loadFromFile: y,
20
+ loadFromInput: D,
21
+ mapSkippedOperations: S,
22
+ parseResultingState: b,
23
+ readOnly: g,
24
+ replayDocument: F,
25
+ replayOperations: _,
26
+ saveToFile: f,
27
+ saveToFileHandle: v,
28
+ sortMappedOperations: R,
29
+ sortOperations: h,
30
+ validateOperations: j
31
+ }, Symbol.toStringTag, { value: "Module" })), L = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
32
+ __proto__: null,
33
+ BaseDocument: x,
34
+ actions: z,
35
+ applyMixins: A,
36
+ baseReducer: B,
37
+ processUndoRedo: H,
38
+ updateDocument: M,
39
+ updateHeader: T,
40
+ utils: E,
41
+ z: k
42
+ }, Symbol.toStringTag, { value: "Module" }));
43
+ export {
44
+ L as D,
45
+ E as i
46
+ };
@@ -1,7 +1,7 @@
1
1
  var Rt = Object.defineProperty;
2
2
  var xt = (t, e, r) => e in t ? Rt(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
3
3
  var Ee = (t, e, r) => (xt(t, typeof e != "symbol" ? e + "" : e, r), r);
4
- import { c as At, i as Mt, a as Dt, b as Nt, s as Lt, d as Pt, l as Ct, e as jt, f as a, B as c, g as yt, h as wt } from "./object-iTBekDVP.js";
4
+ import { c as At, i as Mt, a as Dt, b as Nt, s as Lt, d as Pt, l as Ct, e as jt, f as a, B as c, g as yt, h as wt } from "./object-BW-G4r5m.js";
5
5
  import "immer";
6
6
  import "jszip";
7
7
  import { z as o } from "zod";