document-model 1.0.34 → 1.0.36

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 (47) hide show
  1. package/dist/browser/document-model.cjs +1 -1
  2. package/dist/browser/document-model.js +13 -8
  3. package/dist/browser/document.cjs +1 -1
  4. package/dist/browser/document.js +2 -2
  5. package/dist/browser/index.cjs +1 -1
  6. package/dist/browser/index.js +3 -3
  7. package/dist/browser/internal/{index-CDGYwLIP.js → index-4Z_H8F_J.js} +572 -405
  8. package/dist/browser/internal/index-6u2yDIEF.js +22 -0
  9. package/dist/browser/internal/index-DQeD1Q-a.js +42 -0
  10. package/dist/browser/internal/index-QJX_Fa1V.js +1 -0
  11. package/dist/browser/internal/object-EriwiDIs.js +7 -0
  12. package/dist/browser/internal/{object-B-Aw8ilC.js → object-Fq6PThAX.js} +301 -263
  13. package/dist/browser/src/document/reducer.d.ts +2 -2
  14. package/dist/browser/src/document/utils/base.d.ts +1 -0
  15. package/dist/browser/src/document-model/custom/utils.d.ts +7 -1
  16. package/dist/browser/src/document-model/index.d.ts +5 -0
  17. package/dist/browser/test/document/event-vs-command.test.d.ts +1 -0
  18. package/dist/browser/test/document-model/validation.test.d.ts +1 -0
  19. package/dist/browser/test/helpers.d.ts +5 -3
  20. package/dist/node/document-model.cjs +1 -1
  21. package/dist/node/document-model.js +12 -7
  22. package/dist/node/document.cjs +1 -1
  23. package/dist/node/document.js +2 -2
  24. package/dist/node/index.cjs +1 -1
  25. package/dist/node/index.js +3 -3
  26. package/dist/node/internal/{index-CEkeEja8.js → index-A6Rqm2SZ.js} +572 -405
  27. package/dist/node/internal/index-BpBnSlTZ.js +22 -0
  28. package/dist/node/internal/index-Dl5T5qdc.js +42 -0
  29. package/dist/node/internal/index-DyCS1h0M.js +1 -0
  30. package/dist/node/internal/{object-CvntAblp.js → object-S6TngMa9.js} +324 -286
  31. package/dist/node/internal/object-ifvac9k2.js +2 -0
  32. package/dist/node/src/document/reducer.d.ts +2 -2
  33. package/dist/node/src/document/utils/base.d.ts +1 -0
  34. package/dist/node/src/document-model/custom/utils.d.ts +7 -1
  35. package/dist/node/src/document-model/index.d.ts +5 -0
  36. package/dist/node/test/document/event-vs-command.test.d.ts +1 -0
  37. package/dist/node/test/document-model/validation.test.d.ts +1 -0
  38. package/dist/node/test/helpers.d.ts +5 -3
  39. package/package.json +2 -1
  40. package/dist/browser/internal/index-368Qgjhp.js +0 -22
  41. package/dist/browser/internal/index-A_QX9cy_.js +0 -41
  42. package/dist/browser/internal/index-CZWjb-hc.js +0 -1
  43. package/dist/browser/internal/object-C8B-mq5Y.js +0 -7
  44. package/dist/node/internal/index-D_eCXEyL.js +0 -41
  45. package/dist/node/internal/index-DjP2tO7C.js +0 -1
  46. package/dist/node/internal/index-qa67kbhM.js +0 -22
  47. package/dist/node/internal/object-B5Lf9AWl.js +0 -2
@@ -1,22 +0,0 @@
1
- "use strict";var mt=Object.defineProperty;var Et=(t,e,r)=>e in t?mt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var me=(t,e,r)=>(Et(t,typeof e!="symbol"?e+"":e,r),r);const s=require("./object-B5Lf9AWl.js");require("immer");require("json-stringify-deterministic");require("crypto");require("fs");require("https");require("path");require("jszip");const o=require("zod"),ht=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"})),_={id:"powerhouse/document-model",name:"DocumentModel",extension:"phdm",description:"The Powerhouse Document Model describes the state and operations of a document type.",author:{name:"Powerhouse",website:"https://www.powerhouse.inc/"},specifications:[{version:1,changeLog:[],modules:[{name:"header",operations:[{name:"SetModelName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],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
- "id": "",
3
- "name": "",
4
- "extension": "",
5
- "description": "",
6
- "author": {
7
- "name": "",
8
- "website": ""
9
- },
10
- "specifications": [
11
- {
12
- "version": 1,
13
- "changeLog": [],
14
- "state": {
15
- "schema": "",
16
- "initialValue": "",
17
- "examples": []
18
- },
19
- "modules": []
20
- }
21
- ]
22
- }`,examples:[]},local:{schema:"",initialValue:"{}",examples:[]}}}]},Ee=t=>t!=null,Ot=o.z.any().refine(t=>Ee(t));function z(){return o.z.object({__typename:o.z.literal("AddChangeLogItemInput").optional(),content:o.z.string(),id:o.z.string(),insertBefore:o.z.string().nullable()})}function A(){return o.z.object({description:o.z.string().nullish(),id:o.z.string(),name:o.z.string()})}function I(){return o.z.object({errorCode:o.z.string().nullish(),errorDescription:o.z.string().nullish(),errorName:o.z.string().nullish(),errorTemplate:o.z.string().nullish(),id:o.z.string(),operationId:o.z.string()})}function T(){return o.z.object({example:o.z.string(),id:o.z.string(),operationId:o.z.string()})}function R(){return o.z.object({description:o.z.string().nullish(),id:o.z.string(),moduleId:o.z.string(),name:o.z.string(),reducer:o.z.string().nullish(),schema:o.z.string().nullish(),template:o.z.string().nullish(),scope:S().nullish()})}function D(){return o.z.object({scope:o.z.string(),example:o.z.string(),id:o.z.string(),insertBefore:o.z.string().nullish()})}function he(){return o.z.object({__typename:o.z.literal("Author").optional(),name:o.z.string(),website:o.z.string().nullable()})}function M(){return o.z.object({__typename:o.z.literal("CodeExample").optional(),id:o.z.string(),value:o.z.string()})}function x(){return o.z.object({__typename:o.z.literal("DeleteChangeLogItemInput").optional(),id:o.z.string()})}function N(){return o.z.object({id:o.z.string()})}function L(){return o.z.object({id:o.z.string()})}function j(){return o.z.object({id:o.z.string()})}function P(){return o.z.object({id:o.z.string()})}function C(){return o.z.object({scope:o.z.string(),id:o.z.string()})}function S(){return o.z.literal("global").or(o.z.literal("local"))}function gt(){return o.z.union([z(),A(),I(),T(),R(),D(),x(),N(),L(),j(),P(),C(),k(),y(),w(),v(),U(),V(),F(),H(),$(),X(),G(),B(),W(),q(),J(),K(),Q(),Y(),Z(),ee(),te(),re(),oe(),ne(),ie(),se(),ae(),pe(),le()])}function St(){return o.z.object({__typename:o.z.literal("DocumentModelState").optional(),author:he(),description:o.z.string(),extension:o.z.string(),id:o.z.string(),name:o.z.string(),specifications:o.z.array(Oe())})}function Oe(){return o.z.object({__typename:o.z.literal("DocumentSpecification").optional(),changeLog:o.z.array(o.z.string()),modules:o.z.array(ge()),state:_e(),version:o.z.number()})}function ge(){return o.z.object({__typename:o.z.literal("Module").optional(),description:o.z.string().nullable(),id:o.z.string(),name:o.z.string(),operations:o.z.array(Se())})}function k(){return o.z.object({newModuleId:o.z.string(),operationId:o.z.string()})}function Se(){return o.z.object({__typename:o.z.literal("Operation").optional(),description:o.z.string().nullable(),errors:o.z.array(be()),examples:o.z.array(M()),id:o.z.string(),name:o.z.string().nullable(),reducer:o.z.string().nullable(),schema:o.z.string().nullable(),template:o.z.string().nullable(),scope:S()})}function be(){return o.z.object({__typename:o.z.literal("OperationError").optional(),code:o.z.string().nullable(),description:o.z.string().nullable(),id:o.z.string(),name:o.z.string().nullable(),template:o.z.string().nullable()})}function y(){return o.z.object({__typename:o.z.literal("ReorderChangeLogItemsInput").optional(),order:o.z.array(o.z.string())})}function w(){return o.z.object({moduleId:o.z.string(),order:o.z.array(o.z.string())})}function v(){return o.z.object({order:o.z.array(o.z.string())})}function U(){return o.z.object({operationId:o.z.string(),order:o.z.array(o.z.string())})}function V(){return o.z.object({operationId:o.z.string(),order:o.z.array(o.z.string())})}function F(){return o.z.object({scope:o.z.string(),order:o.z.array(o.z.string())})}function H(){return o.z.object({authorName:o.z.string()})}function $(){return o.z.object({authorWebsite:o.z.string()})}function X(){return o.z.object({scope:o.z.string(),initialValue:o.z.string()})}function G(){return o.z.object({description:o.z.string()})}function B(){return o.z.object({extension:o.z.string()})}function W(){return o.z.object({id:o.z.string()})}function q(){return o.z.object({name:o.z.string()})}function J(){return o.z.object({description:o.z.string().nullish(),id:o.z.string()})}function K(){return o.z.object({id:o.z.string(),name:o.z.string().nullish()})}function Q(){return o.z.object({description:o.z.string().nullish(),id:o.z.string()})}function Y(){return o.z.object({errorCode:o.z.string().nullish(),id:o.z.string()})}function Z(){return o.z.object({errorDescription:o.z.string().nullish(),id:o.z.string()})}function ee(){return o.z.object({errorName:o.z.string().nullish(),id:o.z.string()})}function te(){return o.z.object({errorTemplate:o.z.string().nullish(),id:o.z.string()})}function re(){return o.z.object({id:o.z.string(),name:o.z.string().nullish()})}function fe(){return o.z.object({id:o.z.string(),scope:S()})}function oe(){return o.z.object({id:o.z.string(),reducer:o.z.string().nullish()})}function ne(){return o.z.object({id:o.z.string(),schema:o.z.string().nullish()})}function ie(){return o.z.object({id:o.z.string(),template:o.z.string().nullish()})}function se(){return o.z.object({scope:o.z.string(),schema:o.z.string()})}function f(){return o.z.object({__typename:o.z.literal("State").optional(),examples:o.z.array(M()),initialValue:o.z.string(),schema:o.z.string()})}function _e(){return o.z.object({global:f(),local:f()})}function ae(){return o.z.object({__typename:o.z.literal("UpdateChangeLogItemInput").optional(),id:o.z.string(),newContent:o.z.string()})}function pe(){return o.z.object({example:o.z.string(),id:o.z.string()})}function le(){return o.z.object({scope:o.z.string(),id:o.z.string(),newExample:o.z.string()})}const ze=Object.freeze(Object.defineProperty({__proto__:null,AddChangeLogItemInputSchema:z,AddModuleInputSchema:A,AddOperationErrorInputSchema:I,AddOperationExampleInputSchema:T,AddOperationInputSchema:R,AddStateExampleInputSchema:D,AuthorSchema:he,CodeExampleSchema:M,DeleteChangeLogItemInputSchema:x,DeleteModuleInputSchema:N,DeleteOperationErrorInputSchema:L,DeleteOperationExampleInputSchema:j,DeleteOperationInputSchema:P,DeleteStateExampleInputSchema:C,DocumentModelInputSchema:gt,DocumentModelStateSchema:St,DocumentSpecificationSchema:Oe,ModuleSchema:ge,MoveOperationInputSchema:k,OperationErrorSchema:be,OperationSchema:Se,OperationScopeSchema:S,ReorderChangeLogItemsInputSchema:y,ReorderModuleOperationsInputSchema:w,ReorderModulesInputSchema:v,ReorderOperationErrorsInputSchema:U,ReorderOperationExamplesInputSchema:V,ReorderStateExamplesInputSchema:F,ScopeStateSchema:_e,SetAuthorNameInputSchema:H,SetAuthorWebsiteInputSchema:$,SetInitialStateInputSchema:X,SetModelDescriptionInputSchema:G,SetModelExtensionInputSchema:B,SetModelIdInputSchema:W,SetModelNameInputSchema:q,SetModuleDescriptionInputSchema:J,SetModuleNameInputSchema:K,SetOperationDescriptionInputSchema:Q,SetOperationErrorCodeInputSchema:Y,SetOperationErrorDescriptionInputSchema:Z,SetOperationErrorNameInputSchema:ee,SetOperationErrorTemplateInputSchema:te,SetOperationNameInputSchema:re,SetOperationReducerInputSchema:oe,SetOperationSchemaInputSchema:ne,SetOperationScopeInputSchema:fe,SetOperationTemplateInputSchema:ie,SetStateSchemaInputSchema:se,StateSchema:f,UpdateChangeLogItemInputSchema:ae,UpdateOperationExampleInputSchema:pe,UpdateStateExampleInputSchema:le,definedNonNullAnySchema:Ot,isDefinedNonNullAny:Ee},Symbol.toStringTag,{value:"Module"})),c={setModelNameOperation(t,e){t.name=e.input.name},setModelIdOperation(t,e){t.id=e.input.id},setModelExtensionOperation(t,e){t.extension=e.input.extension},setModelDescriptionOperation(t,e){t.description=e.input.description},setAuthorNameOperation(t,e){t.author=t.author||{name:"",website:null},t.author.name=e.input.authorName},setAuthorWebsiteOperation(t,e){t.author=t.author||{name:"",website:null},t.author.website=e.input.authorWebsite}},E={addChangeLogItemOperation(t,e){throw new Error('Reducer "addChangeLogItemOperation" not yet implemented')},updateChangeLogItemOperation(t,e){throw new Error('Reducer "updateChangeLogItemOperation" not yet implemented')},deleteChangeLogItemOperation(t,e){throw new Error('Reducer "deleteChangeLogItemOperation" not yet implemented')},reorderChangeLogItemsOperation(t,e){throw new Error('Reducer "reorderChangeLogItemsOperation" not yet implemented')},releaseNewVersionOperation(t,e){throw new Error('Reducer "releaseNewVersionOperation" not yet implemented')}},bt=t=>{const e={};return t.forEach((r,n)=>e[r]=n),(r,n)=>(e[n.id]||999999)-(e[r.id]||999999)},h={addModuleOperation(t,e){t.specifications[t.specifications.length-1].modules.push({id:e.input.id,name:e.input.name,description:e.input.description||"",operations:[]})},setModuleNameOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)r.modules[n].id===e.input.id&&(r.modules[n].name=e.input.name||"")},setModuleDescriptionOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)r.modules[n].id===e.input.id&&(r.modules[n].description=e.input.description||"")},deleteModuleOperation(t,e){const r=t.specifications[t.specifications.length-1];r.modules=r.modules.filter(n=>n.id!=e.input.id)},reorderModulesOperation(t,e){t.specifications[t.specifications.length-1].modules.sort(bt(e.input.order))}},ft=t=>{const e={};return t.forEach((r,n)=>e[r]=n),(r,n)=>(e[n.id]||999999)-(e[r.id]||999999)},l={addOperationErrorOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)for(let i=0;i<r.modules[n].operations.length;i++)r.modules[n].operations[i].id==e.input.operationId&&r.modules[n].operations[i].errors.push({id:e.input.id,name:e.input.errorName||"",code:e.input.errorCode||"",description:e.input.errorDescription||"",template:e.input.errorTemplate||""})},setOperationErrorCodeOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)for(let i=0;i<r.modules[n].operations.length;i++)for(let a=0;a<r.modules[n].operations[i].errors.length;a++)r.modules[n].operations[i].errors[a].id==e.input.id&&(r.modules[n].operations[i].errors[a].code=e.input.errorCode||"")},setOperationErrorNameOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)for(let i=0;i<r.modules[n].operations.length;i++)for(let a=0;a<r.modules[n].operations[i].errors.length;a++)r.modules[n].operations[i].errors[a].id==e.input.id&&(r.modules[n].operations[i].errors[a].name=e.input.errorName||"")},setOperationErrorDescriptionOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)for(let i=0;i<r.modules[n].operations.length;i++)for(let a=0;a<r.modules[n].operations[i].errors.length;a++)r.modules[n].operations[i].errors[a].id==e.input.id&&(r.modules[n].operations[i].errors[a].description=e.input.errorDescription||"")},setOperationErrorTemplateOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)for(let i=0;i<r.modules[n].operations.length;i++)for(let a=0;a<r.modules[n].operations[i].errors.length;a++)r.modules[n].operations[i].errors[a].id==e.input.id&&(r.modules[n].operations[i].errors[a].template=e.input.errorTemplate||"")},deleteOperationErrorOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)for(let i=0;i<r.modules[n].operations.length;i++)r.modules[n].operations[i].errors=r.modules[n].operations[i].errors.filter(a=>a.id!=e.input.id)},reorderOperationErrorsOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)for(let i=0;i<r.modules[n].operations.length;i++)r.modules[n].operations[i].id==e.input.operationId&&r.modules[n].operations[i].errors.sort(ft(e.input.order))}},_t=t=>{const e={};return t.forEach((r,n)=>e[r]=n),(r,n)=>(e[n.id]||999999)-(e[r.id]||999999)},g={addOperationExampleOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)for(let i=0;i<r.modules[n].operations.length;i++)r.modules[n].operations[i].id==e.input.operationId&&r.modules[n].operations[i].examples.push({id:e.input.id,value:e.input.example})},updateOperationExampleOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)for(let i=0;i<r.modules[n].operations.length;i++)for(let a=0;a<r.modules[n].operations[i].examples.length;a++)r.modules[n].operations[i].examples[a].id==e.input.id&&(r.modules[n].operations[i].examples[a].value=e.input.example)},deleteOperationExampleOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)for(let i=0;i<r.modules[n].operations.length;i++)r.modules[n].operations[i].examples=r.modules[n].operations[i].examples.filter(a=>a.id!=e.input.id)},reorderOperationExamplesOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)for(let i=0;i<r.modules[n].operations.length;i++)r.modules[n].operations[i].id==e.input.operationId&&r.modules[n].operations[i].examples.sort(_t(e.input.order))}},zt=t=>{const e={};return t.forEach((r,n)=>e[r]=n),(r,n)=>(e[n.id]||999999)-(e[r.id]||999999)},p={addOperationOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)r.modules[n].id==e.input.moduleId&&r.modules[n].operations.push({id:e.input.id,name:e.input.name,description:e.input.description||"",schema:e.input.schema||"",template:e.input.template||e.input.description||"",reducer:e.input.reducer||"",errors:[],examples:[],scope:e.input.scope||"global"})},setOperationNameOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)for(let i=0;i<r.modules[n].operations.length;i++)r.modules[n].operations[i].id==e.input.id&&(r.modules[n].operations[i].name=e.input.name||"")},setOperationScopeOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)for(let i=0;i<r.modules[n].operations.length;i++)r.modules[n].operations[i].id==e.input.id&&(r.modules[n].operations[i].scope=e.input.scope||"global")},setOperationSchemaOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)for(let i=0;i<r.modules[n].operations.length;i++)r.modules[n].operations[i].id==e.input.id&&(r.modules[n].operations[i].schema=e.input.schema||"")},setOperationDescriptionOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)for(let i=0;i<r.modules[n].operations.length;i++)r.modules[n].operations[i].id==e.input.id&&(r.modules[n].operations[i].description=e.input.description||"")},setOperationTemplateOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)for(let i=0;i<r.modules[n].operations.length;i++)r.modules[n].operations[i].id==e.input.id&&(r.modules[n].operations[i].template=e.input.template||"")},setOperationReducerOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)for(let i=0;i<r.modules[n].operations.length;i++)r.modules[n].operations[i].id==e.input.id&&(r.modules[n].operations[i].reducer=e.input.reducer||"")},moveOperationOperation(t,e){const r=[],n=t.specifications[t.specifications.length-1];for(let i=0;i<n.modules.length;i++)n.modules[i].operations=n.modules[i].operations.filter(a=>a.id==e.input.operationId?(r.push(a),!1):!0);for(let i=0;i<n.modules.length;i++)n.modules[i].id==e.input.newModuleId&&n.modules[i].operations.push(...r)},deleteOperationOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)r.modules[n].operations=r.modules[n].operations.filter(i=>i.id!=e.input.id)},reorderModuleOperationsOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)r.modules[n].id==e.input.moduleId&&r.modules[n].operations.sort(zt(e.input.order))}},At=t=>{const e={};return t.forEach((r,n)=>e[r]=n),(r,n)=>(e[n.id]||999999)-(e[r.id]||999999)},d={setStateSchemaOperation(t,e){const r=t.specifications[t.specifications.length-1];if(Object.keys(r.state).includes(e.input.scope))r.state[e.input.scope].schema=e.input.schema;else throw new Error(`Invalid scope: ${e.input.scope}`)},setInitialStateOperation(t,e){const r=t.specifications[t.specifications.length-1];if(Object.keys(r.state).includes(e.input.scope))r.state[e.input.scope].initialValue=e.input.initialValue;else throw new Error(`Invalid scope: ${e.input.scope}`)},addStateExampleOperation(t,e){const r=t.specifications[t.specifications.length-1];if(Object.keys(r.state).includes(e.input.scope))r.state[e.input.scope].examples.push({id:e.input.id,value:e.input.example});else throw new Error(`Invalid scope: ${e.input.scope}`)},updateStateExampleOperation(t,e){const r=t.specifications[t.specifications.length-1];if(!Object.keys(r.state).includes(e.input.scope))throw new Error(`Invalid scope: ${e.input.scope}`);const n=r.state[e.input.scope].examples;for(let i=0;i<n.length;i++)n[i].id==e.input.id&&(n[i].value=e.input.newExample)},deleteStateExampleOperation(t,e){const r=t.specifications[t.specifications.length-1];if(Object.keys(r.state).includes(e.input.scope))r.state[e.input.scope].examples=r.state[e.input.scope].examples.filter(n=>n.id!=e.input.id);else throw new Error(`Invalid scope: ${e.input.scope}`)},reorderStateExamplesOperation(t,e){const r=t.specifications[t.specifications.length-1];if(Object.keys(r.state).includes(e.input.scope))r.state[e.input.scope].examples.sort(At(e.input.order));else throw new Error(`Invalid scope: ${e.input.scope}`)}},It=(t,e)=>{if(s.isBaseAction(e))return t;switch(e.type){case"SET_MODEL_NAME":q().parse(e.input),c.setModelNameOperation(t.global,e);break;case"SET_MODEL_ID":W().parse(e.input),c.setModelIdOperation(t.global,e);break;case"SET_MODEL_EXTENSION":B().parse(e.input),c.setModelExtensionOperation(t.global,e);break;case"SET_MODEL_DESCRIPTION":G().parse(e.input),c.setModelDescriptionOperation(t.global,e);break;case"SET_AUTHOR_NAME":H().parse(e.input),c.setAuthorNameOperation(t.global,e);break;case"SET_AUTHOR_WEBSITE":$().parse(e.input),c.setAuthorWebsiteOperation(t.global,e);break;case"ADD_CHANGE_LOG_ITEM":z().parse(e.input),E.addChangeLogItemOperation(t.global,e);break;case"UPDATE_CHANGE_LOG_ITEM":ae().parse(e.input),E.updateChangeLogItemOperation(t.global,e);break;case"DELETE_CHANGE_LOG_ITEM":x().parse(e.input),E.deleteChangeLogItemOperation(t.global,e);break;case"REORDER_CHANGE_LOG_ITEMS":y().parse(e.input),E.reorderChangeLogItemsOperation(t.global,e);break;case"RELEASE_NEW_VERSION":if(Object.keys(e.input).length>0)throw new Error("Expected empty input for action RELEASE_NEW_VERSION");E.releaseNewVersionOperation(t.global,e);break;case"ADD_MODULE":A().parse(e.input),h.addModuleOperation(t.global,e);break;case"SET_MODULE_NAME":K().parse(e.input),h.setModuleNameOperation(t.global,e);break;case"SET_MODULE_DESCRIPTION":J().parse(e.input),h.setModuleDescriptionOperation(t.global,e);break;case"DELETE_MODULE":N().parse(e.input),h.deleteModuleOperation(t.global,e);break;case"REORDER_MODULES":v().parse(e.input),h.reorderModulesOperation(t.global,e);break;case"ADD_OPERATION_ERROR":I().parse(e.input),l.addOperationErrorOperation(t.global,e);break;case"SET_OPERATION_ERROR_CODE":Y().parse(e.input),l.setOperationErrorCodeOperation(t.global,e);break;case"SET_OPERATION_ERROR_NAME":ee().parse(e.input),l.setOperationErrorNameOperation(t.global,e);break;case"SET_OPERATION_ERROR_DESCRIPTION":Z().parse(e.input),l.setOperationErrorDescriptionOperation(t.global,e);break;case"SET_OPERATION_ERROR_TEMPLATE":te().parse(e.input),l.setOperationErrorTemplateOperation(t.global,e);break;case"DELETE_OPERATION_ERROR":L().parse(e.input),l.deleteOperationErrorOperation(t.global,e);break;case"REORDER_OPERATION_ERRORS":U().parse(e.input),l.reorderOperationErrorsOperation(t.global,e);break;case"ADD_OPERATION_EXAMPLE":T().parse(e.input),g.addOperationExampleOperation(t.global,e);break;case"UPDATE_OPERATION_EXAMPLE":pe().parse(e.input),g.updateOperationExampleOperation(t.global,e);break;case"DELETE_OPERATION_EXAMPLE":j().parse(e.input),g.deleteOperationExampleOperation(t.global,e);break;case"REORDER_OPERATION_EXAMPLES":V().parse(e.input),g.reorderOperationExamplesOperation(t.global,e);break;case"ADD_OPERATION":R().parse(e.input),p.addOperationOperation(t.global,e);break;case"SET_OPERATION_NAME":re().parse(e.input),p.setOperationNameOperation(t.global,e);break;case"SET_OPERATION_SCOPE":fe().parse(e.input),p.setOperationScopeOperation(t.global,e);break;case"SET_OPERATION_SCHEMA":ne().parse(e.input),p.setOperationSchemaOperation(t.global,e);break;case"SET_OPERATION_DESCRIPTION":Q().parse(e.input),p.setOperationDescriptionOperation(t.global,e);break;case"SET_OPERATION_TEMPLATE":ie().parse(e.input),p.setOperationTemplateOperation(t.global,e);break;case"SET_OPERATION_REDUCER":oe().parse(e.input),p.setOperationReducerOperation(t.global,e);break;case"MOVE_OPERATION":k().parse(e.input),p.moveOperationOperation(t.global,e);break;case"DELETE_OPERATION":P().parse(e.input),p.deleteOperationOperation(t.global,e);break;case"REORDER_MODULE_OPERATIONS":w().parse(e.input),p.reorderModuleOperationsOperation(t.global,e);break;case"SET_STATE_SCHEMA":se().parse(e.input),d.setStateSchemaOperation(t.global,e);break;case"SET_INITIAL_STATE":X().parse(e.input),d.setInitialStateOperation(t.global,e);break;case"ADD_STATE_EXAMPLE":D().parse(e.input),d.addStateExampleOperation(t.global,e);break;case"UPDATE_STATE_EXAMPLE":le().parse(e.input),d.updateStateExampleOperation(t.global,e);break;case"DELETE_STATE_EXAMPLE":C().parse(e.input),d.deleteStateExampleOperation(t.global,e);break;case"REORDER_STATE_EXAMPLES":F().parse(e.input),d.reorderStateExamplesOperation(t.global,e);break;default:return t}},m=s.createReducer(It),Tt={id:"",name:"",extension:"",description:"",author:{name:"",website:""},specifications:[{version:1,changeLog:[],state:{global:{schema:"",initialValue:"",examples:[]},local:{schema:"",initialValue:"",examples:[]}},modules:[]}]},Rt={},O={fileExtension:"phdm",createState(t){return{global:{...Tt,...t==null?void 0:t.global},local:{...Rt,...t==null?void 0:t.local}}},createExtendedState(t){return s.createExtendedState({...t,documentType:"powerhouse/document-model"},O.createState)},createDocument(t){return s.createDocument(O.createExtendedState(t),O.createState)},saveToFile(t,e,r){return s.saveToFile(t,e,"phdm",r)},saveToFileHandle(t,e){return s.saveToFileHandle(t,e)},loadFromFile(t){return s.loadFromFile(t,m)},loadFromInput(t){return s.loadFromInput(t,m)}},Ae=t=>s.createAction("SET_MODEL_NAME",{...t}),Ie=t=>s.createAction("SET_MODEL_ID",{...t}),Te=t=>s.createAction("SET_MODEL_EXTENSION",{...t}),Re=t=>s.createAction("SET_MODEL_DESCRIPTION",{...t}),De=t=>s.createAction("SET_AUTHOR_NAME",{...t}),Me=t=>s.createAction("SET_AUTHOR_WEBSITE",{...t});class Dt extends s.BaseDocument{setModelName(e,r){return this.dispatch(Ae(e),r)}setModelId(e,r){return this.dispatch(Ie(e),r)}setModelExtension(e,r){return this.dispatch(Te(e),r)}setModelDescription(e,r){return this.dispatch(Re(e),r)}setAuthorName(e,r){return this.dispatch(De(e),r)}setAuthorWebsite(e,r){return this.dispatch(Me(e),r)}}const xe=t=>s.createAction("ADD_CHANGE_LOG_ITEM",{...t}),Ne=t=>s.createAction("UPDATE_CHANGE_LOG_ITEM",{...t}),Le=t=>s.createAction("DELETE_CHANGE_LOG_ITEM",{...t}),je=t=>s.createAction("REORDER_CHANGE_LOG_ITEMS",{...t}),Pe=()=>s.createAction("RELEASE_NEW_VERSION");class Mt extends s.BaseDocument{addChangeLogItem(e,r){return this.dispatch(xe(e),r)}updateChangeLogItem(e,r){return this.dispatch(Ne(e),r)}deleteChangeLogItem(e,r){return this.dispatch(Le(e),r)}reorderChangeLogItems(e,r){return this.dispatch(je(e),r)}releaseNewVersion(e){return this.dispatch(Pe(),e)}}const Ce=t=>s.createAction("ADD_MODULE",{...t}),ke=t=>s.createAction("SET_MODULE_NAME",{...t}),ye=t=>s.createAction("SET_MODULE_DESCRIPTION",{...t}),we=t=>s.createAction("DELETE_MODULE",{...t}),ve=t=>s.createAction("REORDER_MODULES",{...t});class xt extends s.BaseDocument{addModule(e,r){return this.dispatch(Ce(e),r)}setModuleName(e,r){return this.dispatch(ke(e),r)}setModuleDescription(e,r){return this.dispatch(ye(e),r)}deleteModule(e,r){return this.dispatch(we(e),r)}reorderModules(e,r){return this.dispatch(ve(e),r)}}const Ue=t=>s.createAction("ADD_OPERATION_ERROR",{...t}),Ve=t=>s.createAction("SET_OPERATION_ERROR_CODE",{...t}),Fe=t=>s.createAction("SET_OPERATION_ERROR_NAME",{...t}),He=t=>s.createAction("SET_OPERATION_ERROR_DESCRIPTION",{...t}),$e=t=>s.createAction("SET_OPERATION_ERROR_TEMPLATE",{...t}),Xe=t=>s.createAction("DELETE_OPERATION_ERROR",{...t}),Ge=t=>s.createAction("REORDER_OPERATION_ERRORS",{...t});class Nt extends s.BaseDocument{addOperationError(e,r){return this.dispatch(Ue(e),r)}setOperationErrorCode(e,r){return this.dispatch(Ve(e),r)}setOperationErrorName(e,r){return this.dispatch(Fe(e),r)}setOperationErrorDescription(e,r){return this.dispatch(He(e),r)}setOperationErrorTemplate(e,r){return this.dispatch($e(e),r)}deleteOperationError(e,r){return this.dispatch(Xe(e),r)}reorderOperationErrors(e,r){return this.dispatch(Ge(e),r)}}const Be=t=>s.createAction("ADD_OPERATION_EXAMPLE",{...t}),We=t=>s.createAction("UPDATE_OPERATION_EXAMPLE",{...t}),qe=t=>s.createAction("DELETE_OPERATION_EXAMPLE",{...t}),Je=t=>s.createAction("REORDER_OPERATION_EXAMPLES",{...t});class Lt extends s.BaseDocument{addOperationExample(e,r){return this.dispatch(Be(e),r)}updateOperationExample(e,r){return this.dispatch(We(e),r)}deleteOperationExample(e,r){return this.dispatch(qe(e),r)}reorderOperationExamples(e,r){return this.dispatch(Je(e),r)}}const Ke=t=>s.createAction("ADD_OPERATION",{...t}),Qe=t=>s.createAction("SET_OPERATION_NAME",{...t}),Ye=t=>s.createAction("SET_OPERATION_SCOPE",{...t}),Ze=t=>s.createAction("SET_OPERATION_SCHEMA",{...t}),et=t=>s.createAction("SET_OPERATION_DESCRIPTION",{...t}),tt=t=>s.createAction("SET_OPERATION_TEMPLATE",{...t}),rt=t=>s.createAction("SET_OPERATION_REDUCER",{...t}),ot=t=>s.createAction("MOVE_OPERATION",{...t}),nt=t=>s.createAction("DELETE_OPERATION",{...t}),it=t=>s.createAction("REORDER_MODULE_OPERATIONS",{...t});class jt extends s.BaseDocument{addOperation(e,r){return this.dispatch(Ke(e),r)}setOperationName(e,r){return this.dispatch(Qe(e),r)}setOperationScope(e,r){return this.dispatch(Ye(e),r)}setOperationSchema(e,r){return this.dispatch(Ze(e),r)}setOperationDescription(e,r){return this.dispatch(et(e),r)}setOperationTemplate(e,r){return this.dispatch(tt(e),r)}setOperationReducer(e,r){return this.dispatch(rt(e),r)}moveOperation(e,r){return this.dispatch(ot(e),r)}deleteOperation(e,r){return this.dispatch(nt(e),r)}reorderModuleOperations(e,r){return this.dispatch(it(e),r)}}const st=t=>s.createAction("SET_STATE_SCHEMA",{...t}),at=t=>s.createAction("SET_INITIAL_STATE",{...t}),pt=t=>s.createAction("ADD_STATE_EXAMPLE",{...t}),lt=t=>s.createAction("UPDATE_STATE_EXAMPLE",{...t}),ct=t=>s.createAction("DELETE_STATE_EXAMPLE",{...t}),dt=t=>s.createAction("REORDER_STATE_EXAMPLES",{...t});class Pt extends s.BaseDocument{setStateSchema(e,r){return this.dispatch(st(e),r)}setInitialState(e,r){return this.dispatch(at(e),r)}addStateExample(e,r){return this.dispatch(pt(e),r)}updateStateExample(e,r){return this.dispatch(lt(e),r)}deleteStateExample(e,r){return this.dispatch(ct(e),r)}reorderStateExamples(e,r){return this.dispatch(dt(e),r)}}var u;let b=(u=class extends s.BaseDocument{constructor(e,r){super(m,O.createDocument(e),r)}saveToFile(e,r){return super.saveToFile(e,u.fileExtension,r)}loadFromFile(e){return super.loadFromFile(e)}static async fromFile(e){const r=new this;return await r.loadFromFile(e),r}},me(u,"fileExtension","phdm"),u);s.applyMixins(b,[Dt,Mt,xt,Nt,Lt,jt,Pt]);const Ct=Object.freeze(Object.defineProperty({__proto__:null,addChangeLogItem:xe,addModule:Ce,addOperation:Ke,addOperationError:Ue,addOperationExample:Be,addStateExample:pt,deleteChangeLogItem:Le,deleteModule:we,deleteOperation:nt,deleteOperationError:Xe,deleteOperationExample:qe,deleteStateExample:ct,moveOperation:ot,releaseNewVersion:Pe,reorderChangeLogItems:je,reorderModuleOperations:it,reorderModules:ve,reorderOperationErrors:Ge,reorderOperationExamples:Je,reorderStateExamples:dt,setAuthorName:De,setAuthorWebsite:Me,setInitialState:at,setModelDescription:Re,setModelExtension:Te,setModelId:Ie,setModelName:Ae,setModuleDescription:ye,setModuleName:ke,setOperationDescription:et,setOperationErrorCode:Ve,setOperationErrorDescription:He,setOperationErrorName:Fe,setOperationErrorTemplate:$e,setOperationName:Qe,setOperationReducer:rt,setOperationSchema:Ze,setOperationScope:Ye,setOperationTemplate:tt,setStateSchema:st,updateChangeLogItem:Ne,updateOperationExample:We,updateStateExample:lt},Symbol.toStringTag,{value:"Module"})),ce=b,de={...O,...ht},ue={...s.BaseActions,...Ct},ut={Document:ce,reducer:m,actions:ue,utils:de,documentModel:_},kt=Object.freeze(Object.defineProperty({__proto__:null,Document:ce,DocumentModel:b,actions:ue,documentModel:_,module:ut,reducer:m,utils:de,z:ze},Symbol.toStringTag,{value:"Module"}));exports.Document=ce;exports.DocumentModel=kt;exports.DocumentModel$1=b;exports.actions=ue;exports.documentModel=_;exports.module=ut;exports.reducer=m;exports.utils=de;exports.zod=ze;
@@ -1,2 +0,0 @@
1
- "use strict";var Et=Object.defineProperty;var Nt=(e,t,i)=>t in e?Et(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i;var E=(e,t,i)=>(Nt(e,typeof t!="symbol"?t+"":t,i),i);const h=require("immer"),A=require("json-stringify-deterministic"),c=require("zod"),Tt=require("crypto"),M=require("fs"),At=require("https"),Mt=require("path"),V=require("jszip"),G=e=>e!=null,Ft=c.z.any().refine(e=>G(e)),Q=c.z.enum(["LOAD_STATE"]),X=c.z.enum(["PRUNE"]),Y=c.z.enum(["REDO"]),tt=c.z.enum(["SET_NAME"]),et=c.z.enum(["UNDO"]);function It(){return c.z.object({__typename:c.z.literal("Action").optional(),type:c.z.string()})}function z(){return c.z.literal("global").or(c.z.literal("local"))}function it(){return c.z.union([nt(),ot(),st(),pt(),ct()])}function Pt(){return c.z.object({__typename:c.z.literal("DocumentFile").optional(),data:c.z.string(),extension:c.z.string().nullable(),fileName:c.z.string().nullable(),mimeType:c.z.string()})}function nt(){return c.z.object({input:c.z.lazy(()=>R()),type:Q,scope:z()})}function R(){return c.z.object({operations:c.z.number(),state:c.z.lazy(()=>at())})}function at(){return c.z.object({data:c.z.unknown().nullish(),name:c.z.string()})}function Rt(){return c.z.object({__typename:c.z.literal("Operation").optional(),hash:c.z.string(),index:c.z.number(),timestamp:c.z.string().datetime(),type:c.z.string()})}function ot(){return c.z.object({input:c.z.lazy(()=>q()),type:X,scope:z()})}function q(){return c.z.object({end:c.z.number().nullish(),start:c.z.number().nullish()})}const L=c.z.number;function st(){return c.z.object({input:L(),type:Y,scope:z()})}const U=c.z.string;function pt(){return c.z.object({input:U(),type:tt,scope:c.z.literal("global")})}function qt(){return c.z.object({__typename:c.z.literal("SetNameOperation").optional(),hash:c.z.string(),index:c.z.number(),input:c.z.string(),timestamp:c.z.string().datetime(),type:c.z.string()})}const $=c.z.number;function ct(){return c.z.object({input:$(),type:et,scope:z()})}const Lt=Object.freeze(Object.defineProperty({__proto__:null,ActionSchema:It,BaseActionSchema:it,DocumentFileSchema:Pt,LoadStateActionInputSchema:R,LoadStateActionSchema:nt,LoadStateActionStateInputSchema:at,Load_StateSchema:Q,OperationSchema:Rt,OperationScopeSchema:z,PruneActionInputSchema:q,PruneActionSchema:ot,PruneSchema:X,RedoActionInputSchema:L,RedoActionSchema:st,RedoSchema:Y,SetNameActionInputSchema:U,SetNameActionSchema:pt,SetNameOperationSchema:qt,Set_NameSchema:tt,UndoActionInputSchema:$,UndoActionSchema:ct,UndoSchema:et,definedNonNullAnySchema:Ft,isDefinedNonNullAny:G},Symbol.toStringTag,{value:"Module"}));function Ut(e,t){return{...e,name:t}}function $t(e,t,i){const n={skip:i,document:e},{scope:a}=t;return!a||t.skip===void 0?n:h.produce(n,s=>{const[o]=s.document.operations[a].slice(-1);t.skip&&t.skip>0&&(s.skip=t.skip),o.type==="NOOP"&&t.index===o.index&&s.skip>o.skip&&s.document.operations[a].pop()})}function Ct(e,t,i){const{scope:n,input:a}=t,s={document:e,action:t,skip:i};return h.produce(s,o=>{if(o.document.operations[n].length<1)throw new Error(`Cannot undo: no operations in history for scope "${n}"`);if(a<1)throw new Error("Invalid UNDO action: input value must be greater than 0");if(o.skip>0)throw new Error("Cannot undo: skip value from reducer cannot be used with UNDO action");const[p]=o.document.operations[n].slice(-1),l=p.type==="NOOP"&&p.skip>0;if(o.skip+=a,l&&(o.skip+=p.skip,o.document.operations[n].pop()),o.document.operations[n].length<o.skip)throw new Error("Cannot undo: you can't undo more operations than the ones in the scope history");const r=o.document.operations[n].length-1;let x=a,u=l?r-p.skip:r;for(;x>0&&u>=0;){const m=o.document.operations[n][u];m.type==="NOOP"&&m.skip>0?(u=u-(m.skip+1),o.skip+=m.skip+1):(o.document.clipboard.push({...m}),x--,u--)}o.action=Z(n)})}function Jt(e,t,i){const{scope:n,input:a}=t,s={document:e,action:t,skip:i};return h.produce(s,o=>{if(o.skip>0)throw new Error("Cannot redo: skip value from reducer cannot be used with REDO action");if(a>1)throw new Error("Cannot redo: you can only redo one operation at a time");if(a<1)throw new Error("Invalid REDO action: invalid redo input value");if(o.document.clipboard.length<1)throw new Error("Cannot redo: no operations in the clipboard");const p=o.document.clipboard.findLastIndex(r=>r.scope===n);if(p<0)throw new Error(`Cannot redo: no operations in clipboard for scope "${n}"`);const l=o.document.clipboard.splice(p,1)[0];o.action=h.castDraft({type:l.type,scope:l.scope,input:l.input})})}function Bt(e,t,i){const{scope:n}=t,a=e.operations[n];let{input:{start:s,end:o}}=t;s=s||0,o=o||a.length;const p=a.slice(s,o),l=a.slice(0,s),r=a.slice(o),x=N(e.initialState,{...e.operations,[n]:l.concat(p)},i),{name:u,state:m}=x,f=l.length,d=l.length?l[l.length-1].timestamp:r.length?r[0].timestamp:new Date().toISOString();return N(e.initialState,{...e.operations,[n]:[...l,{...W({name:u,state:m},p.length),timestamp:d,index:f,hash:J({state:m},"global")},...r.map((O,D)=>({...O,index:f+D+1}))]},i)}function Wt(e,t){return{...e,name:t.name,state:t.state??{global:{},local:{}}}}const rt="SET_NAME",y="UNDO",j="REDO",_="PRUNE",lt="LOAD_STATE",Zt="NOOP";function Ht(e,t){const i=e.revision[t.scope];return[y,j,_].includes(t.type)?i:i+1}function Kt(e,t){return{...e,revision:{...e.revision,[t.scope]:Ht(e,t)},lastModified:new Date().toISOString()}}function Vt(e,t,i=0){if([y,j,_].includes(t.type))return e;const{scope:n}=t,a=e.operations[n].slice(0,e.revision[n]);return a.push({...t,index:a.length,timestamp:new Date().toISOString(),hash:"",scope:n,skip:i}),{...e,operations:{...e.operations,[n]:a}}}function Gt(e,t,i=0){let n=Vt(e,t,i);return n=Kt(n,t),n}function Qt(e,t,i){switch(it().parse(t),t.type){case rt:return Ut(e,t.input);case _:return Bt(e,t,i);case lt:return Wt(e,t.input.state);default:return e}}function mt(e,t,i){switch(t.type){case y:return Ct(e,t,i);case j:return Jt(e,t,i);default:return{document:e,action:t,skip:i}}}function C(e,t,i,n,a={}){const{skip:s,ignoreSkipOperations:o=!1}=a;let p={...t},l=s||0,r=e,x=[...e.clipboard];if(ut(p)){const{document:u,skip:m}=$t(r,p,l);l=m,r=u}if(F(p)){const{skip:u,action:m,document:f}=mt(e,p,l);p=m,l=u,r=f,x=[...r.clipboard]}return I(p)&&(r=Qt(r,p,i)),l>0&&!o&&(r=N(r.initialState,r.operations,i,void 0,void 0,void 0,{[p.scope]:l})),r=Gt(r,p,l),r=h.produce(r,u=>{const m=i(u.state,p,n),f=F(t)?[...x]:[];if(m)return h.castDraft({...r,clipboard:[...f],state:m});u.clipboard=h.castDraft([...f])}),h.produce(r,u=>{if([y,j,_].includes(p.type))return u;const m=p.scope||"global";u.operations[m][u.operations[m].length-1].hash=J(u,m),!I(p)&&p.attachments&&p.attachments.forEach(f=>{const{hash:d,...O}=f;u.attachments[d]={...O}})})}function Xt(e,t,i){const n=Mt.join(e,t);return M.mkdirSync(e,{recursive:!0}),new Promise((a,s)=>{try{M.writeFile(n,i,{},o=>{o?s(o):a(n)})}catch(o){s(o)}})}function dt(e){return M.readFileSync(e)}function Yt(e){return new Promise((t,i)=>{At.get(e,n=>{const a=[],s=n.headers["content-type"];n.on("data",o=>{a.push(o)}),n.on("end",()=>{t({buffer:Buffer.concat(a),mimeType:s})})}).on("error",n=>{i(n)})})}const te=async e=>dt(e),T=(e,t="sha1")=>Tt.createHash(t).update(e).digest("base64");function ut(e){return e.type===Zt&&e.skip!==void 0&&e.skip>0&&e.hash!==void 0}function F(e){return[y,j].includes(e.type)}function I(e){return[rt,y,j,_,lt].includes(e.type)}function w(e,t,i,n,a="global"){if(!e)throw new Error("Empty action type");if(typeof e!="string")throw new Error(`Invalid action type: ${e}`);const s={type:e,input:t,scope:a};i&&(s.attachments=i);try{n==null||n().parse(s.input)}catch(o){throw new Error(`Invalid action input: ${o}`)}return s}function ft(e,t=C){return(i,n,a,s)=>t(i,n,e,a,s)}const xt=(e,t)=>({name:"",documentType:"",revision:{global:0,local:0},created:new Date().toISOString(),lastModified:new Date().toISOString(),attachments:{},...e,state:(t==null?void 0:t(e==null?void 0:e.state))??(e==null?void 0:e.state)??{global:{},local:{}}}),gt=(e,t)=>{const i=xt(e,t);return{...i,initialState:i,operations:{global:[],local:[]},clipboard:[]}},J=(e,t="global")=>T(A(e.state[t])),ee=(e,t=1e3)=>{const i=Math.random()*t;return T(`${(e??new Date).toISOString()}${i}`)};function k(e){return h.castImmutable(h.freeze(e,!0))}function ht(e,t){const i=[...e];let n=t||0,a=i.length>0?i[i.length-1].index:0;const s=[];for(const o of i.reverse()){if(n>0){const r=a-o.index;n-=r}if(n<0)throw new Error("Invalid operation index, missing operations");const p={ignore:n>0,operation:o},l=o.skip>0?o.skip+1:0;if(l>0&&l>n){const r=l-n;n=n+r}a=o.index,s.push(p)}return s.reverse()}function ie(e){return Object.values(e).flatMap(t=>t).sort((t,i)=>new Date(t.timestamp).getTime()-new Date(i.timestamp).getTime())}function bt(e){return Object.values(e).flatMap(t=>t).sort((t,i)=>new Date(t.operation.timestamp).getTime()-new Date(i.operation.timestamp).getTime())}function N(e,t,i,n,a,s=C,o={}){const p=ft(i,s);return B(e,t,p,n,a,o)}function B(e,t,i,n,a,s={}){const o=gt(e),p=Object.keys(t).reduce((m,f)=>{const d=f;return{...m,[d]:t[d].slice(0,a==null?void 0:a.revision[d])}},{}),l=Object.keys(p).reduce((m,f)=>{const d=f;return{...m,[d]:ht(p[d],s[d])}},{}),r=bt(l).reduce((m,{ignore:f,operation:d})=>f?i(m,Z(d.scope),n,{skip:d.skip,ignoreSkipOperations:!0}):i(m,d,n,{skip:d.skip,ignoreSkipOperations:!0}),o),x=Object.keys(r.operations).reduce((m,f)=>{const d=f,O=a&&a.revision[d]<t[d].length?t[d].slice(a.revision[d]):[];return{...m,[d]:[...r.operations[d].map((D,Dt)=>{var K;return{...D,timestamp:((K=t[d][Dt])==null?void 0:K.timestamp)??D.timestamp}}),...O]}},{global:[],local:[]}),u=Object.values(x).reduce((m,f)=>{for(const d of f)d.timestamp>m&&(m=d.timestamp);return m},e.lastModified);return{...r,operations:x,lastModified:u}}function ne(e,t){return A(e)===A(t)}const wt=e=>w("SET_NAME",e,void 0,U,void 0),vt=(e=1,t="global")=>w("UNDO",e,void 0,$,t),yt=(e=1,t="global")=>w("REDO",e,void 0,L,t),jt=(e,t,i="global")=>w("PRUNE",{start:e,end:t},void 0,q,i),W=(e,t)=>w("LOAD_STATE",{state:e,operations:t},void 0,R),Z=(e="global")=>w("NOOP",{},void 0,void 0,e),ae=Object.freeze(Object.defineProperty({__proto__:null,loadState:W,noop:Z,prune:jt,redo:yt,setName:wt,undo:vt},Symbol.toStringTag,{value:"Module"})),Ot={"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(Ot);var g=function(e,t,i,n){if(i==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?e!==t||!n:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return i==="m"?n:i==="a"?n.call(e):n?n.value:t.get(e)},v,S,b;class oe{constructor(...t){v.set(this,new Map),S.set(this,new Map),b.set(this,new Map);for(const i of t)this.define(i)}define(t,i=!1){for(let[n,a]of Object.entries(t)){n=n.toLowerCase(),a=a.map(p=>p.toLowerCase()),g(this,b,"f").has(n)||g(this,b,"f").set(n,new Set);const s=g(this,b,"f").get(n);let o=!0;for(let p of a){const l=p.startsWith("*");if(p=l?p.slice(1):p,s==null||s.add(p),o&&g(this,S,"f").set(n,p),o=!1,l)continue;const r=g(this,v,"f").get(p);if(r&&r!=n&&!i)throw new Error(`"${n} -> ${p}" conflicts with "${r} -> ${p}". Pass \`force=true\` to override this definition.`);g(this,v,"f").set(p,n)}}return this}getType(t){if(typeof t!="string")return null;const i=t.replace(/^.*[/\\]/,"").toLowerCase(),n=i.replace(/^.*\./,"").toLowerCase(),a=i.length<t.length;return!(n.length<i.length-1)&&a?null:g(this,v,"f").get(n)??null}getExtension(t){var i;return typeof t!="string"?null:(t=(i=t==null?void 0:t.split)==null?void 0:i.call(t,";")[0],(t&&g(this,S,"f").get(t.trim().toLowerCase()))??null)}getAllExtensions(t){return typeof t!="string"?null:g(this,b,"f").get(t.toLowerCase())??null}_freeze(){this.define=()=>{throw new Error("define() not allowed for built-in Mime objects. See https://github.com/broofa/mime/blob/main/README.md#custom-mime-instances")},Object.freeze(this);for(const t of g(this,b,"f").values())Object.freeze(t);return this}_getTestState(){return{types:g(this,v,"f"),extensions:g(this,S,"f")}}}v=new WeakMap,S=new WeakMap,b=new WeakMap;const se=new oe(Ot)._freeze();function kt(e){const t=[],i=Object.keys(e);for(const n of i){const a=e[n].sort((s,o)=>s.index-o.index);for(let s=0;s<a.length;s++)a[s].index!==s&&t.push({message:`Invalid operation index ${a[s].index} at position ${s}`,details:{position:s,operation:a[s],scope:a[s].scope}})}return t}const H=async e=>{const t=new V,{name:i,revision:n,documentType:a,created:s,lastModified:o}=e,p={name:i,revision:n,documentType:a,created:s,lastModified:o};return t.file("header.json",JSON.stringify(p,null,2)),t.file("state.json",JSON.stringify(e.initialState||{},null,2)),t.file("operations.json",JSON.stringify(e.operations,null,2)),Object.keys(e.attachments).forEach(r=>{const{data:x,...u}=e.attachments[r];t.file(r,x,{base64:!0,createFolders:!0,comment:JSON.stringify(u)})}),t},St=async(e,t,i,n)=>{const s=await(await H(e)).generateAsync({type:"uint8array",streamFiles:!0}),o=n??e.name,p=`.${i}.zip`;return Xt(t,o.endsWith(p)?o:`${o}${p}`,s)},pe=async(e,t)=>{const n=await(await H(e)).generateAsync({type:"blob"}),a=await t.createWritable();await a.write(n),await a.close()},P=async(e,t)=>{const i=dt(e);return zt(i,t)},zt=async(e,t)=>{const i=new V;return await i.loadAsync(e),ce(i,t)};async function ce(e,t){const i=e.file("state.json");if(!i)throw new Error("Initial state not found");const n=await i.async("string"),a=JSON.parse(n),s=e.file("header.json");let o;s&&(o=JSON.parse(await s.async("string")));const p=e.file("operations.json");if(!p)throw new Error("Operations history not found");const l=JSON.parse(await p.async("string")),r=kt(l);if(r.length){const u=r.map(m=>m.message);throw new Error(u.join(`
2
- `))}let x=B(a,l,t,void 0,o);return o&&(x={...x,...o}),x}function _t(e){const t=e.replace(/^.*\./,"")||void 0,i=e.replace(/^.*[/\\]/,"")||void 0;return{extension:t,fileName:i}}async function re(e){const{buffer:t,mimeType:i="application/octet-stream"}=await Yt(e),n=_t(e),a=t.toString("base64");return{data:a,hash:T(a),mimeType:i,...n}}async function le(e){const t=await te(e),i=se.getType(e)||"application/octet-stream",n=_t(e),a=t.toString("base64");return{data:a,hash:T(a),mimeType:i,...n}}class me{constructor(t,i,n){E(this,"_document");E(this,"_reducer");E(this,"_signalDispatch");this._reducer=t,this._document=i,this._signalDispatch=n}dispatch(t,i){return this._document=this._reducer(this._document,t,this._signalDispatch,i),this}saveToFile(t,i,n){return St(this._document,t,i,n)}async loadFromFile(t){this._document=await P(t,this._reducer)}static async stateFromFile(t,i){return await P(t,i)}get state(){return k(this._document.state)}get operations(){return k(this._document.operations)}get name(){return this._document.name}get documentType(){return this._document.documentType}get created(){return this._document.created}get lastModified(){return this._document.lastModified}get revision(){return this._document.revision.global}getRevision(t){return this._document.revision[t]}get initialState(){return k(this._document.initialState)}toDocument(){return k(this._document)}getAttachment(t){return this._document.attachments[t]}setName(t){return this.dispatch(wt(t)),this}undo(t){return this.dispatch(vt(t)),this}redo(t){return this.dispatch(yt(t)),this}prune(t,i){return this.dispatch(jt(t,i)),this}loadState(t,i){return this.dispatch(W(t,i)),this}}function de(e,t){t.forEach(i=>{Object.getOwnPropertyNames(i.prototype).forEach(n=>{Object.defineProperty(e.prototype,n,Object.getOwnPropertyDescriptor(i.prototype,n)||Object.create(null))})})}exports.BaseActions=ae;exports.BaseDocument=me;exports.applyMixins=de;exports.baseReducer=C;exports.createAction=w;exports.createDocument=gt;exports.createExtendedState=xt;exports.createReducer=ft;exports.createZip=H;exports.getLocalFile=le;exports.getRemoteFile=re;exports.hashDocument=J;exports.hashKey=ee;exports.isBaseAction=I;exports.isNoopOperation=ut;exports.isSameDocument=ne;exports.isUndoRedo=F;exports.loadFromFile=P;exports.loadFromInput=zt;exports.mapSkippedOperations=ht;exports.processUndoRedo=mt;exports.readOnly=k;exports.replayDocument=B;exports.replayOperations=N;exports.saveToFile=St;exports.saveToFileHandle=pe;exports.sortMappedOperations=bt;exports.sortOperations=ie;exports.validateOperations=kt;exports.zod=Lt;