document-model 2.4.0 → 2.5.0-test.0

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 (637) hide show
  1. package/dist/index.d.ts +18 -0
  2. package/dist/index.d.ts.map +1 -0
  3. package/dist/index.js +13 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/{browser/src → src}/document/actions/creators.d.ts +4 -2
  6. package/dist/src/document/actions/creators.d.ts.map +1 -0
  7. package/dist/{node/src/document/actions/creators.d.ts → src/document/actions/creators.js} +18 -8
  8. package/dist/src/document/actions/creators.js.map +1 -0
  9. package/dist/src/document/actions/operations.d.ts +23 -0
  10. package/dist/src/document/actions/operations.d.ts.map +1 -0
  11. package/dist/src/document/actions/operations.js +131 -0
  12. package/dist/src/document/actions/operations.js.map +1 -0
  13. package/dist/src/document/actions/types.d.ts +16 -0
  14. package/dist/src/document/actions/types.d.ts.map +1 -0
  15. package/dist/src/document/actions/types.js +7 -0
  16. package/dist/src/document/actions/types.js.map +1 -0
  17. package/dist/{browser/src → src}/document/object.d.ts +17 -14
  18. package/dist/src/document/object.d.ts.map +1 -0
  19. package/dist/{node/src/document/object.d.ts → src/document/object.js} +93 -29
  20. package/dist/src/document/object.js.map +1 -0
  21. package/dist/src/document/reducer.d.ts +49 -0
  22. package/dist/src/document/reducer.d.ts.map +1 -0
  23. package/dist/src/document/reducer.js +342 -0
  24. package/dist/src/document/reducer.js.map +1 -0
  25. package/dist/{browser/src → src}/document/schema/types.d.ts +2 -1
  26. package/dist/src/document/schema/types.d.ts.map +1 -0
  27. package/dist/src/document/schema/types.js +2 -0
  28. package/dist/src/document/schema/types.js.map +1 -0
  29. package/dist/{browser/src → src}/document/schema/zod.d.ts +30 -47
  30. package/dist/src/document/schema/zod.d.ts.map +1 -0
  31. package/dist/src/document/schema/zod.js +113 -0
  32. package/dist/src/document/schema/zod.js.map +1 -0
  33. package/dist/{node/src → src}/document/signal.d.ts +10 -9
  34. package/dist/src/document/signal.d.ts.map +1 -0
  35. package/dist/src/document/signal.js +2 -0
  36. package/dist/src/document/signal.js.map +1 -0
  37. package/dist/src/document/types.d.ts +345 -0
  38. package/dist/src/document/types.d.ts.map +1 -0
  39. package/dist/src/document/types.js +2 -0
  40. package/dist/src/document/types.js.map +1 -0
  41. package/dist/src/document/utils/base.d.ts +83 -0
  42. package/dist/src/document/utils/base.d.ts.map +1 -0
  43. package/dist/src/document/utils/base.js +331 -0
  44. package/dist/src/document/utils/base.js.map +1 -0
  45. package/dist/src/document/utils/browser.d.ts +18 -0
  46. package/dist/src/document/utils/browser.d.ts.map +1 -0
  47. package/dist/src/document/utils/browser.js +54 -0
  48. package/dist/src/document/utils/browser.js.map +1 -0
  49. package/dist/src/document/utils/crypto.d.ts +11 -0
  50. package/dist/src/document/utils/crypto.d.ts.map +1 -0
  51. package/dist/src/document/utils/crypto.js +80 -0
  52. package/dist/src/document/utils/crypto.js.map +1 -0
  53. package/dist/src/document/utils/document-helpers.d.ts +78 -0
  54. package/dist/src/document/utils/document-helpers.d.ts.map +1 -0
  55. package/dist/src/document/utils/document-helpers.js +411 -0
  56. package/dist/src/document/utils/document-helpers.js.map +1 -0
  57. package/dist/src/document/utils/errors.d.ts +10 -0
  58. package/dist/src/document/utils/errors.d.ts.map +1 -0
  59. package/dist/src/document/utils/errors.js +19 -0
  60. package/dist/src/document/utils/errors.js.map +1 -0
  61. package/dist/{node/src → src}/document/utils/file.d.ts +10 -8
  62. package/dist/src/document/utils/file.d.ts.map +1 -0
  63. package/dist/src/document/utils/file.js +158 -0
  64. package/dist/src/document/utils/file.js.map +1 -0
  65. package/dist/src/document/utils/node.d.ts +18 -0
  66. package/dist/src/document/utils/node.d.ts.map +1 -0
  67. package/dist/src/document/utils/node.js +62 -0
  68. package/dist/src/document/utils/node.js.map +1 -0
  69. package/dist/src/document/utils/validation.d.ts +3 -0
  70. package/dist/src/document/utils/validation.d.ts.map +1 -0
  71. package/dist/src/document/utils/validation.js +23 -0
  72. package/dist/src/document/utils/validation.js.map +1 -0
  73. package/dist/src/document-model/custom/reducers/header.d.ts +3 -0
  74. package/dist/src/document-model/custom/reducers/header.d.ts.map +1 -0
  75. package/dist/src/document-model/custom/reducers/header.js +23 -0
  76. package/dist/src/document-model/custom/reducers/header.js.map +1 -0
  77. package/dist/src/document-model/custom/reducers/module.d.ts +3 -0
  78. package/dist/src/document-model/custom/reducers/module.d.ts.map +1 -0
  79. package/dist/src/document-model/custom/reducers/module.js +41 -0
  80. package/dist/src/document-model/custom/reducers/module.js.map +1 -0
  81. package/dist/src/document-model/custom/reducers/operation-error.d.ts +3 -0
  82. package/dist/src/document-model/custom/reducers/operation-error.d.ts.map +1 -0
  83. package/dist/src/document-model/custom/reducers/operation-error.js +94 -0
  84. package/dist/src/document-model/custom/reducers/operation-error.js.map +1 -0
  85. package/dist/src/document-model/custom/reducers/operation-example.d.ts +3 -0
  86. package/dist/src/document-model/custom/reducers/operation-example.d.ts.map +1 -0
  87. package/dist/src/document-model/custom/reducers/operation-example.js +53 -0
  88. package/dist/src/document-model/custom/reducers/operation-example.js.map +1 -0
  89. package/dist/src/document-model/custom/reducers/operation.d.ts +3 -0
  90. package/dist/src/document-model/custom/reducers/operation.d.ts.map +1 -0
  91. package/dist/src/document-model/custom/reducers/operation.js +125 -0
  92. package/dist/src/document-model/custom/reducers/operation.js.map +1 -0
  93. package/dist/src/document-model/custom/reducers/state.d.ts +3 -0
  94. package/dist/src/document-model/custom/reducers/state.d.ts.map +1 -0
  95. package/dist/src/document-model/custom/reducers/state.js +71 -0
  96. package/dist/src/document-model/custom/reducers/state.js.map +1 -0
  97. package/dist/src/document-model/custom/reducers/versioning.d.ts +8 -0
  98. package/dist/src/document-model/custom/reducers/versioning.d.ts.map +1 -0
  99. package/dist/src/document-model/custom/reducers/versioning.js +23 -0
  100. package/dist/src/document-model/custom/reducers/versioning.js.map +1 -0
  101. package/dist/{browser/src → src}/document-model/custom/utils.d.ts +4 -3
  102. package/dist/src/document-model/custom/utils.d.ts.map +1 -0
  103. package/dist/src/document-model/custom/utils.js +105 -0
  104. package/dist/src/document-model/custom/utils.js.map +1 -0
  105. package/dist/src/document-model/gen/actions.d.ts +16 -0
  106. package/dist/src/document-model/gen/actions.d.ts.map +1 -0
  107. package/dist/src/document-model/gen/actions.js +8 -0
  108. package/dist/src/document-model/gen/actions.js.map +1 -0
  109. package/dist/src/document-model/gen/constants.d.ts +7 -0
  110. package/dist/src/document-model/gen/constants.d.ts.map +1 -0
  111. package/dist/src/document-model/gen/constants.js +34 -0
  112. package/dist/src/document-model/gen/constants.js.map +1 -0
  113. package/dist/src/document-model/gen/creators.d.ts +8 -0
  114. package/dist/src/document-model/gen/creators.d.ts.map +1 -0
  115. package/dist/src/document-model/gen/creators.js +8 -0
  116. package/dist/src/document-model/gen/creators.js.map +1 -0
  117. package/dist/src/document-model/gen/document-model.d.ts +3 -0
  118. package/dist/src/document-model/gen/document-model.d.ts.map +1 -0
  119. package/dist/src/document-model/gen/document-model.js +542 -0
  120. package/dist/src/document-model/gen/document-model.js.map +1 -0
  121. package/dist/src/document-model/gen/header/actions.d.ts +10 -0
  122. package/dist/src/document-model/gen/header/actions.d.ts.map +1 -0
  123. package/dist/src/document-model/gen/header/actions.js +2 -0
  124. package/dist/src/document-model/gen/header/actions.js.map +1 -0
  125. package/dist/{node/src → src}/document-model/gen/header/creators.d.ts +3 -2
  126. package/dist/src/document-model/gen/header/creators.d.ts.map +1 -0
  127. package/dist/src/document-model/gen/header/creators.js +10 -0
  128. package/dist/src/document-model/gen/header/creators.js.map +1 -0
  129. package/dist/src/document-model/gen/header/object.d.ts +13 -0
  130. package/dist/src/document-model/gen/header/object.d.ts.map +1 -0
  131. package/dist/src/document-model/gen/header/object.js +23 -0
  132. package/dist/src/document-model/gen/header/object.js.map +1 -0
  133. package/dist/{node/src → src}/document-model/gen/header/operations.d.ts +3 -2
  134. package/dist/src/document-model/gen/header/operations.d.ts.map +1 -0
  135. package/dist/src/document-model/gen/header/operations.js +2 -0
  136. package/dist/src/document-model/gen/header/operations.js.map +1 -0
  137. package/dist/src/document-model/gen/module/actions.d.ts +9 -0
  138. package/dist/src/document-model/gen/module/actions.d.ts.map +1 -0
  139. package/dist/src/document-model/gen/module/actions.js +2 -0
  140. package/dist/src/document-model/gen/module/actions.js.map +1 -0
  141. package/dist/{node/src → src}/document-model/gen/module/creators.d.ts +3 -2
  142. package/dist/src/document-model/gen/module/creators.d.ts.map +1 -0
  143. package/dist/src/document-model/gen/module/creators.js +9 -0
  144. package/dist/src/document-model/gen/module/creators.js.map +1 -0
  145. package/dist/src/document-model/gen/module/object.d.ts +12 -0
  146. package/dist/src/document-model/gen/module/object.d.ts.map +1 -0
  147. package/dist/src/document-model/gen/module/object.js +20 -0
  148. package/dist/src/document-model/gen/module/object.js.map +1 -0
  149. package/dist/{browser/src → src}/document-model/gen/module/operations.d.ts +3 -2
  150. package/dist/src/document-model/gen/module/operations.d.ts.map +1 -0
  151. package/dist/src/document-model/gen/module/operations.js +2 -0
  152. package/dist/src/document-model/gen/module/operations.js.map +1 -0
  153. package/dist/src/document-model/gen/object.d.ts +29 -0
  154. package/dist/src/document-model/gen/object.d.ts.map +1 -0
  155. package/dist/src/document-model/gen/object.js +46 -0
  156. package/dist/src/document-model/gen/object.js.map +1 -0
  157. package/dist/src/document-model/gen/operation/actions.d.ts +14 -0
  158. package/dist/src/document-model/gen/operation/actions.d.ts.map +1 -0
  159. package/dist/src/document-model/gen/operation/actions.js +2 -0
  160. package/dist/src/document-model/gen/operation/actions.js.map +1 -0
  161. package/dist/{browser/src → src}/document-model/gen/operation/creators.d.ts +3 -2
  162. package/dist/src/document-model/gen/operation/creators.d.ts.map +1 -0
  163. package/dist/src/document-model/gen/operation/creators.js +20 -0
  164. package/dist/src/document-model/gen/operation/creators.js.map +1 -0
  165. package/dist/{node/src → src}/document-model/gen/operation/object.d.ts +7 -5
  166. package/dist/src/document-model/gen/operation/object.d.ts.map +1 -0
  167. package/dist/src/document-model/gen/operation/object.js +35 -0
  168. package/dist/src/document-model/gen/operation/object.js.map +1 -0
  169. package/dist/{node/src → src}/document-model/gen/operation/operations.d.ts +3 -2
  170. package/dist/src/document-model/gen/operation/operations.d.ts.map +1 -0
  171. package/dist/src/document-model/gen/operation/operations.js +2 -0
  172. package/dist/src/document-model/gen/operation/operations.js.map +1 -0
  173. package/dist/src/document-model/gen/operation-error/actions.d.ts +11 -0
  174. package/dist/src/document-model/gen/operation-error/actions.d.ts.map +1 -0
  175. package/dist/src/document-model/gen/operation-error/actions.js +2 -0
  176. package/dist/src/document-model/gen/operation-error/actions.js.map +1 -0
  177. package/dist/{node/src → src}/document-model/gen/operation-error/creators.d.ts +3 -2
  178. package/dist/src/document-model/gen/operation-error/creators.d.ts.map +1 -0
  179. package/dist/src/document-model/gen/operation-error/creators.js +17 -0
  180. package/dist/src/document-model/gen/operation-error/creators.js.map +1 -0
  181. package/dist/{node/src → src}/document-model/gen/operation-error/object.d.ts +7 -5
  182. package/dist/src/document-model/gen/operation-error/object.d.ts.map +1 -0
  183. package/dist/src/document-model/gen/operation-error/object.js +26 -0
  184. package/dist/src/document-model/gen/operation-error/object.js.map +1 -0
  185. package/dist/{browser/src → src}/document-model/gen/operation-error/operations.d.ts +3 -2
  186. package/dist/src/document-model/gen/operation-error/operations.d.ts.map +1 -0
  187. package/dist/src/document-model/gen/operation-error/operations.js +2 -0
  188. package/dist/src/document-model/gen/operation-error/operations.js.map +1 -0
  189. package/dist/src/document-model/gen/operation-example/actions.d.ts +8 -0
  190. package/dist/src/document-model/gen/operation-example/actions.d.ts.map +1 -0
  191. package/dist/src/document-model/gen/operation-example/actions.js +2 -0
  192. package/dist/src/document-model/gen/operation-example/actions.js.map +1 -0
  193. package/dist/{browser/src → src}/document-model/gen/operation-example/creators.d.ts +3 -2
  194. package/dist/src/document-model/gen/operation-example/creators.d.ts.map +1 -0
  195. package/dist/src/document-model/gen/operation-example/creators.js +14 -0
  196. package/dist/src/document-model/gen/operation-example/creators.js.map +1 -0
  197. package/dist/src/document-model/gen/operation-example/object.d.ts +12 -0
  198. package/dist/src/document-model/gen/operation-example/object.d.ts.map +1 -0
  199. package/dist/src/document-model/gen/operation-example/object.js +17 -0
  200. package/dist/src/document-model/gen/operation-example/object.js.map +1 -0
  201. package/dist/{browser/src → src}/document-model/gen/operation-example/operations.d.ts +3 -2
  202. package/dist/src/document-model/gen/operation-example/operations.d.ts.map +1 -0
  203. package/dist/src/document-model/gen/operation-example/operations.js +2 -0
  204. package/dist/src/document-model/gen/operation-example/operations.js.map +1 -0
  205. package/dist/src/document-model/gen/reducer.d.ts +5 -0
  206. package/dist/src/document-model/gen/reducer.d.ts.map +1 -0
  207. package/dist/src/document-model/gen/reducer.js +193 -0
  208. package/dist/src/document-model/gen/reducer.js.map +1 -0
  209. package/dist/{browser/src → src}/document-model/gen/schema/types.d.ts +6 -1
  210. package/dist/src/document-model/gen/schema/types.d.ts.map +1 -0
  211. package/dist/src/document-model/gen/schema/types.js +2 -0
  212. package/dist/src/document-model/gen/schema/types.js.map +1 -0
  213. package/dist/src/document-model/gen/schema/zod.d.ts +454 -0
  214. package/dist/src/document-model/gen/schema/zod.d.ts.map +1 -0
  215. package/dist/src/document-model/gen/schema/zod.js +394 -0
  216. package/dist/src/document-model/gen/schema/zod.js.map +1 -0
  217. package/dist/src/document-model/gen/state/actions.d.ts +10 -0
  218. package/dist/src/document-model/gen/state/actions.d.ts.map +1 -0
  219. package/dist/src/document-model/gen/state/actions.js +2 -0
  220. package/dist/src/document-model/gen/state/actions.js.map +1 -0
  221. package/dist/{browser/src → src}/document-model/gen/state/creators.d.ts +3 -2
  222. package/dist/src/document-model/gen/state/creators.d.ts.map +1 -0
  223. package/dist/src/document-model/gen/state/creators.js +10 -0
  224. package/dist/src/document-model/gen/state/creators.js.map +1 -0
  225. package/dist/src/document-model/gen/state/object.d.ts +13 -0
  226. package/dist/src/document-model/gen/state/object.d.ts.map +1 -0
  227. package/dist/src/document-model/gen/state/object.js +23 -0
  228. package/dist/src/document-model/gen/state/object.js.map +1 -0
  229. package/dist/{browser/src → src}/document-model/gen/state/operations.d.ts +3 -2
  230. package/dist/src/document-model/gen/state/operations.d.ts.map +1 -0
  231. package/dist/src/document-model/gen/state/operations.js +2 -0
  232. package/dist/src/document-model/gen/state/operations.js.map +1 -0
  233. package/dist/src/document-model/gen/types.d.ts +7 -0
  234. package/dist/src/document-model/gen/types.d.ts.map +1 -0
  235. package/dist/src/document-model/gen/types.js +2 -0
  236. package/dist/src/document-model/gen/types.js.map +1 -0
  237. package/dist/src/document-model/gen/utils.d.ts +11 -0
  238. package/dist/src/document-model/gen/utils.d.ts.map +1 -0
  239. package/dist/src/document-model/gen/utils.js +30 -0
  240. package/dist/src/document-model/gen/utils.js.map +1 -0
  241. package/dist/src/document-model/gen/versioning/actions.d.ts +9 -0
  242. package/dist/src/document-model/gen/versioning/actions.d.ts.map +1 -0
  243. package/dist/src/document-model/gen/versioning/actions.js +2 -0
  244. package/dist/src/document-model/gen/versioning/actions.js.map +1 -0
  245. package/dist/{browser/src → src}/document-model/gen/versioning/creators.d.ts +3 -2
  246. package/dist/src/document-model/gen/versioning/creators.d.ts.map +1 -0
  247. package/dist/src/document-model/gen/versioning/creators.js +13 -0
  248. package/dist/src/document-model/gen/versioning/creators.js.map +1 -0
  249. package/dist/src/document-model/gen/versioning/object.d.ts +13 -0
  250. package/dist/src/document-model/gen/versioning/object.d.ts.map +1 -0
  251. package/dist/src/document-model/gen/versioning/object.js +20 -0
  252. package/dist/src/document-model/gen/versioning/object.js.map +1 -0
  253. package/dist/{browser/src → src}/document-model/gen/versioning/operations.d.ts +3 -2
  254. package/dist/src/document-model/gen/versioning/operations.d.ts.map +1 -0
  255. package/dist/src/document-model/gen/versioning/operations.js +2 -0
  256. package/dist/src/document-model/gen/versioning/operations.js.map +1 -0
  257. package/dist/src/document-model/module.d.ts +3 -0
  258. package/dist/src/document-model/module.d.ts.map +1 -0
  259. package/dist/src/document-model/module.js +13 -0
  260. package/dist/src/document-model/module.js.map +1 -0
  261. package/dist/src/document-model/types.d.ts +4 -0
  262. package/dist/src/document-model/types.d.ts.map +1 -0
  263. package/dist/src/document-model/types.js +2 -0
  264. package/dist/src/document-model/types.js.map +1 -0
  265. package/dist/test/document/crypto.test.d.ts +2 -0
  266. package/dist/test/document/crypto.test.d.ts.map +1 -0
  267. package/dist/test/document/crypto.test.js +181 -0
  268. package/dist/test/document/crypto.test.js.map +1 -0
  269. package/dist/test/document/event-vs-command.test.d.ts +2 -0
  270. package/dist/test/document/event-vs-command.test.d.ts.map +1 -0
  271. package/dist/test/document/event-vs-command.test.js +169 -0
  272. package/dist/test/document/event-vs-command.test.js.map +1 -0
  273. package/dist/test/document/local.test.d.ts +2 -0
  274. package/dist/test/document/local.test.d.ts.map +1 -0
  275. package/dist/test/document/local.test.js +248 -0
  276. package/dist/test/document/local.test.js.map +1 -0
  277. package/dist/test/document/object.test.d.ts +2 -0
  278. package/dist/test/document/object.test.d.ts.map +1 -0
  279. package/dist/test/document/object.test.js +13 -0
  280. package/dist/test/document/object.test.js.map +1 -0
  281. package/dist/test/document/operation-id.test.d.ts +2 -0
  282. package/dist/test/document/operation-id.test.d.ts.map +1 -0
  283. package/dist/test/document/operation-id.test.js +159 -0
  284. package/dist/test/document/operation-id.test.js.map +1 -0
  285. package/dist/test/document/prune.test.d.ts +2 -0
  286. package/dist/test/document/prune.test.d.ts.map +1 -0
  287. package/dist/test/document/prune.test.js +177 -0
  288. package/dist/test/document/prune.test.js.map +1 -0
  289. package/dist/test/document/reducer.test.d.ts +2 -0
  290. package/dist/test/document/reducer.test.d.ts.map +1 -0
  291. package/dist/test/document/reducer.test.js +270 -0
  292. package/dist/test/document/reducer.test.js.map +1 -0
  293. package/dist/test/document/skip-operations.test.d.ts +2 -0
  294. package/dist/test/document/skip-operations.test.d.ts.map +1 -0
  295. package/dist/test/document/skip-operations.test.js +442 -0
  296. package/dist/test/document/skip-operations.test.js.map +1 -0
  297. package/dist/test/document/undo-redo.test.d.ts +2 -0
  298. package/dist/test/document/undo-redo.test.d.ts.map +1 -0
  299. package/dist/test/document/undo-redo.test.js +377 -0
  300. package/dist/test/document/undo-redo.test.js.map +1 -0
  301. package/dist/test/document/utils.test.d.ts +2 -0
  302. package/dist/test/document/utils.test.d.ts.map +1 -0
  303. package/dist/test/document/utils.test.js +152 -0
  304. package/dist/test/document/utils.test.js.map +1 -0
  305. package/dist/test/document-helpers/addUndo.test.d.ts +2 -0
  306. package/dist/test/document-helpers/addUndo.test.d.ts.map +1 -0
  307. package/dist/test/document-helpers/addUndo.test.js +120 -0
  308. package/dist/test/document-helpers/addUndo.test.js.map +1 -0
  309. package/dist/test/document-helpers/attachBranch.test.d.ts +2 -0
  310. package/dist/test/document-helpers/attachBranch.test.d.ts.map +1 -0
  311. package/dist/test/document-helpers/attachBranch.test.js +364 -0
  312. package/dist/test/document-helpers/attachBranch.test.js.map +1 -0
  313. package/dist/test/document-helpers/checkCleanedOperationsIntegrity.test.d.ts +2 -0
  314. package/dist/test/document-helpers/checkCleanedOperationsIntegrity.test.d.ts.map +1 -0
  315. package/dist/test/document-helpers/checkCleanedOperationsIntegrity.test.js +252 -0
  316. package/dist/test/document-helpers/checkCleanedOperationsIntegrity.test.js.map +1 -0
  317. package/dist/test/document-helpers/conflictResolution.test.d.ts +2 -0
  318. package/dist/test/document-helpers/conflictResolution.test.d.ts.map +1 -0
  319. package/dist/test/document-helpers/conflictResolution.test.js +109 -0
  320. package/dist/test/document-helpers/conflictResolution.test.js.map +1 -0
  321. package/dist/test/document-helpers/filterDuplicatedOperations.test.d.ts +2 -0
  322. package/dist/test/document-helpers/filterDuplicatedOperations.test.d.ts.map +1 -0
  323. package/dist/test/document-helpers/filterDuplicatedOperations.test.js +126 -0
  324. package/dist/test/document-helpers/filterDuplicatedOperations.test.js.map +1 -0
  325. package/dist/test/document-helpers/garbageCollect.test.d.ts +2 -0
  326. package/dist/test/document-helpers/garbageCollect.test.d.ts.map +1 -0
  327. package/dist/test/document-helpers/garbageCollect.test.js +136 -0
  328. package/dist/test/document-helpers/garbageCollect.test.js.map +1 -0
  329. package/dist/test/document-helpers/groupOperationsByScope.test.d.ts +2 -0
  330. package/dist/test/document-helpers/groupOperationsByScope.test.d.ts.map +1 -0
  331. package/dist/test/document-helpers/groupOperationsByScope.test.js +98 -0
  332. package/dist/test/document-helpers/groupOperationsByScope.test.js.map +1 -0
  333. package/dist/test/document-helpers/merge.test.d.ts +2 -0
  334. package/dist/test/document-helpers/merge.test.d.ts.map +1 -0
  335. package/dist/test/document-helpers/merge.test.js +906 -0
  336. package/dist/test/document-helpers/merge.test.js.map +1 -0
  337. package/dist/test/document-helpers/nextSkipNumber.test.d.ts +2 -0
  338. package/dist/test/document-helpers/nextSkipNumber.test.d.ts.map +1 -0
  339. package/dist/test/document-helpers/nextSkipNumber.test.js +135 -0
  340. package/dist/test/document-helpers/nextSkipNumber.test.js.map +1 -0
  341. package/dist/test/document-helpers/prepareOperations.test.d.ts +2 -0
  342. package/dist/test/document-helpers/prepareOperations.test.d.ts.map +1 -0
  343. package/dist/test/document-helpers/prepareOperations.test.js +304 -0
  344. package/dist/test/document-helpers/prepareOperations.test.js.map +1 -0
  345. package/dist/test/document-helpers/removeExistingOperations.test.d.ts +2 -0
  346. package/dist/test/document-helpers/removeExistingOperations.test.d.ts.map +1 -0
  347. package/dist/test/document-helpers/removeExistingOperations.test.js +150 -0
  348. package/dist/test/document-helpers/removeExistingOperations.test.js.map +1 -0
  349. package/dist/test/document-helpers/reshuffleByTimestamp.test.d.ts +2 -0
  350. package/dist/test/document-helpers/reshuffleByTimestamp.test.d.ts.map +1 -0
  351. package/dist/test/document-helpers/reshuffleByTimestamp.test.js +148 -0
  352. package/dist/test/document-helpers/reshuffleByTimestamp.test.js.map +1 -0
  353. package/dist/test/document-helpers/reshuffleByTimestampAndIndex.test.d.ts +2 -0
  354. package/dist/test/document-helpers/reshuffleByTimestampAndIndex.test.d.ts.map +1 -0
  355. package/dist/test/document-helpers/reshuffleByTimestampAndIndex.test.js +200 -0
  356. package/dist/test/document-helpers/reshuffleByTimestampAndIndex.test.js.map +1 -0
  357. package/dist/test/document-helpers/skipHeaderOperations.test.d.ts +2 -0
  358. package/dist/test/document-helpers/skipHeaderOperations.test.d.ts.map +1 -0
  359. package/dist/test/document-helpers/skipHeaderOperations.test.js +74 -0
  360. package/dist/test/document-helpers/skipHeaderOperations.test.js.map +1 -0
  361. package/dist/test/document-helpers/sortOperations.test.d.ts +2 -0
  362. package/dist/test/document-helpers/sortOperations.test.d.ts.map +1 -0
  363. package/dist/test/document-helpers/sortOperations.test.js +101 -0
  364. package/dist/test/document-helpers/sortOperations.test.js.map +1 -0
  365. package/dist/test/document-helpers/split.test.d.ts +2 -0
  366. package/dist/test/document-helpers/split.test.d.ts.map +1 -0
  367. package/dist/test/document-helpers/split.test.js +121 -0
  368. package/dist/test/document-helpers/split.test.js.map +1 -0
  369. package/dist/{browser/test → test}/document-helpers/utils.d.ts +2 -1
  370. package/dist/test/document-helpers/utils.d.ts.map +1 -0
  371. package/dist/test/document-helpers/utils.js +22 -0
  372. package/dist/test/document-helpers/utils.js.map +1 -0
  373. package/dist/test/document-model/object.test.d.ts +2 -0
  374. package/dist/test/document-model/object.test.d.ts.map +1 -0
  375. package/dist/test/document-model/object.test.js +243 -0
  376. package/dist/test/document-model/object.test.js.map +1 -0
  377. package/dist/test/document-model/replay.test.d.ts +2 -0
  378. package/dist/test/document-model/replay.test.d.ts.map +1 -0
  379. package/dist/test/document-model/replay.test.js +149 -0
  380. package/dist/test/document-model/replay.test.js.map +1 -0
  381. package/dist/test/document-model/skip-operations.test.d.ts +2 -0
  382. package/dist/test/document-model/skip-operations.test.d.ts.map +1 -0
  383. package/dist/test/document-model/skip-operations.test.js +220 -0
  384. package/dist/test/document-model/skip-operations.test.js.map +1 -0
  385. package/dist/test/document-model/validation.test.d.ts +2 -0
  386. package/dist/test/document-model/validation.test.d.ts.map +1 -0
  387. package/dist/test/document-model/validation.test.js +258 -0
  388. package/dist/test/document-model/validation.test.js.map +1 -0
  389. package/dist/test/document-model/zip.test.d.ts +2 -0
  390. package/dist/test/document-model/zip.test.d.ts.map +1 -0
  391. package/dist/test/document-model/zip.test.js +80 -0
  392. package/dist/test/document-model/zip.test.js.map +1 -0
  393. package/dist/test/helpers.d.ts +31 -0
  394. package/dist/test/helpers.d.ts.map +1 -0
  395. package/dist/test/helpers.js +71 -0
  396. package/dist/test/helpers.js.map +1 -0
  397. package/dist/tsconfig.tsbuildinfo +1 -0
  398. package/dist/vitest.config.d.ts +3 -0
  399. package/dist/vitest.config.d.ts.map +1 -0
  400. package/dist/vitest.config.js +13 -0
  401. package/dist/vitest.config.js.map +1 -0
  402. package/package.json +27 -53
  403. package/dist/browser/cjs/document-model.js +0 -20
  404. package/dist/browser/cjs/document-model.js.map +0 -1
  405. package/dist/browser/cjs/document.js +0 -15
  406. package/dist/browser/cjs/document.js.map +0 -1
  407. package/dist/browser/cjs/index.js +0 -14
  408. package/dist/browser/cjs/index.js.map +0 -1
  409. package/dist/browser/cjs/internal/index-DyKphRZa.js +0 -2215
  410. package/dist/browser/cjs/internal/index-DyKphRZa.js.map +0 -1
  411. package/dist/browser/cjs/internal/index-y9w_m1Lo.js +0 -57
  412. package/dist/browser/cjs/internal/index-y9w_m1Lo.js.map +0 -1
  413. package/dist/browser/cjs/internal/object-Dbc1GbBl.js +0 -2694
  414. package/dist/browser/cjs/internal/object-Dbc1GbBl.js.map +0 -1
  415. package/dist/browser/cjs/package.json +0 -1
  416. package/dist/browser/document-model.d.ts +0 -2
  417. package/dist/browser/document.d.ts +0 -2
  418. package/dist/browser/es/document-model.js +0 -20
  419. package/dist/browser/es/document-model.js.map +0 -1
  420. package/dist/browser/es/document.js +0 -15
  421. package/dist/browser/es/document.js.map +0 -1
  422. package/dist/browser/es/index.js +0 -14
  423. package/dist/browser/es/index.js.map +0 -1
  424. package/dist/browser/es/internal/index-BI16PNmr.js +0 -58
  425. package/dist/browser/es/internal/index-BI16PNmr.js.map +0 -1
  426. package/dist/browser/es/internal/index-CiQX4huJ.js +0 -2216
  427. package/dist/browser/es/internal/index-CiQX4huJ.js.map +0 -1
  428. package/dist/browser/es/internal/object-BTIqCvb-.js +0 -2695
  429. package/dist/browser/es/internal/object-BTIqCvb-.js.map +0 -1
  430. package/dist/browser/es/package.json +0 -1
  431. package/dist/browser/index.d.ts +0 -6
  432. package/dist/browser/src/document/actions/index.d.ts +0 -14
  433. package/dist/browser/src/document/actions/types.d.ts +0 -15
  434. package/dist/browser/src/document/index.d.ts +0 -6
  435. package/dist/browser/src/document/reducer.d.ts +0 -65
  436. package/dist/browser/src/document/schema/index.d.ts +0 -2
  437. package/dist/browser/src/document/signal.d.ts +0 -29
  438. package/dist/browser/src/document/types.d.ts +0 -271
  439. package/dist/browser/src/document/utils/base.d.ts +0 -87
  440. package/dist/browser/src/document/utils/crypto.d.ts +0 -9
  441. package/dist/browser/src/document/utils/document-helpers.d.ts +0 -73
  442. package/dist/browser/src/document/utils/file.d.ts +0 -48
  443. package/dist/browser/src/document/utils/index.d.ts +0 -6
  444. package/dist/browser/src/document/utils/node.d.ts +0 -9
  445. package/dist/browser/src/document/utils/validation.d.ts +0 -2
  446. package/dist/browser/src/document-model/custom/reducers/header.d.ts +0 -2
  447. package/dist/browser/src/document-model/custom/reducers/module.d.ts +0 -2
  448. package/dist/browser/src/document-model/custom/reducers/operation-error.d.ts +0 -2
  449. package/dist/browser/src/document-model/custom/reducers/operation-example.d.ts +0 -2
  450. package/dist/browser/src/document-model/custom/reducers/operation.d.ts +0 -2
  451. package/dist/browser/src/document-model/custom/reducers/state.d.ts +0 -2
  452. package/dist/browser/src/document-model/custom/reducers/versioning.d.ts +0 -2
  453. package/dist/browser/src/document-model/gen/actions.d.ts +0 -15
  454. package/dist/browser/src/document-model/gen/creators.d.ts +0 -7
  455. package/dist/browser/src/document-model/gen/document-model.d.ts +0 -2
  456. package/dist/browser/src/document-model/gen/header/actions.d.ts +0 -9
  457. package/dist/browser/src/document-model/gen/header/creators.d.ts +0 -8
  458. package/dist/browser/src/document-model/gen/header/object.d.ts +0 -12
  459. package/dist/browser/src/document-model/gen/header/operations.d.ts +0 -10
  460. package/dist/browser/src/document-model/gen/index.d.ts +0 -5
  461. package/dist/browser/src/document-model/gen/module/actions.d.ts +0 -8
  462. package/dist/browser/src/document-model/gen/module/creators.d.ts +0 -7
  463. package/dist/browser/src/document-model/gen/module/object.d.ts +0 -11
  464. package/dist/browser/src/document-model/gen/object.d.ts +0 -28
  465. package/dist/browser/src/document-model/gen/operation/actions.d.ts +0 -13
  466. package/dist/browser/src/document-model/gen/operation/object.d.ts +0 -16
  467. package/dist/browser/src/document-model/gen/operation/operations.d.ts +0 -14
  468. package/dist/browser/src/document-model/gen/operation-error/actions.d.ts +0 -10
  469. package/dist/browser/src/document-model/gen/operation-error/creators.d.ts +0 -9
  470. package/dist/browser/src/document-model/gen/operation-error/object.d.ts +0 -13
  471. package/dist/browser/src/document-model/gen/operation-example/actions.d.ts +0 -7
  472. package/dist/browser/src/document-model/gen/operation-example/object.d.ts +0 -10
  473. package/dist/browser/src/document-model/gen/reducer.d.ts +0 -5
  474. package/dist/browser/src/document-model/gen/schema/index.d.ts +0 -2
  475. package/dist/browser/src/document-model/gen/schema/zod.d.ts +0 -453
  476. package/dist/browser/src/document-model/gen/state/actions.d.ts +0 -9
  477. package/dist/browser/src/document-model/gen/state/object.d.ts +0 -12
  478. package/dist/browser/src/document-model/gen/types.d.ts +0 -8
  479. package/dist/browser/src/document-model/gen/utils.d.ts +0 -6
  480. package/dist/browser/src/document-model/gen/versioning/actions.d.ts +0 -8
  481. package/dist/browser/src/document-model/gen/versioning/object.d.ts +0 -11
  482. package/dist/browser/src/document-model/index.d.ts +0 -76
  483. package/dist/browser/src/index.d.ts +0 -24
  484. package/dist/browser/test/document/crypto.test.d.ts +0 -1
  485. package/dist/browser/test/document/event-vs-command.test.d.ts +0 -1
  486. package/dist/browser/test/document/local.test.d.ts +0 -1
  487. package/dist/browser/test/document/object.test.d.ts +0 -1
  488. package/dist/browser/test/document/operation-id.test.d.ts +0 -1
  489. package/dist/browser/test/document/prune.test.d.ts +0 -1
  490. package/dist/browser/test/document/reducer.test.d.ts +0 -1
  491. package/dist/browser/test/document/skip-operations.test.d.ts +0 -1
  492. package/dist/browser/test/document/undo-redo.test.d.ts +0 -1
  493. package/dist/browser/test/document/utils.test.d.ts +0 -1
  494. package/dist/browser/test/document-helpers/addUndo.test.d.ts +0 -1
  495. package/dist/browser/test/document-helpers/attachBranch.test.d.ts +0 -1
  496. package/dist/browser/test/document-helpers/checkCleanedOperationsIntegrity.test.d.ts +0 -1
  497. package/dist/browser/test/document-helpers/conflictResolution.test.d.ts +0 -1
  498. package/dist/browser/test/document-helpers/filterDuplicatedOperations.test.d.ts +0 -1
  499. package/dist/browser/test/document-helpers/garbageCollect.test.d.ts +0 -1
  500. package/dist/browser/test/document-helpers/groupOperationsByScope.test.d.ts +0 -1
  501. package/dist/browser/test/document-helpers/merge.test.d.ts +0 -1
  502. package/dist/browser/test/document-helpers/nextSkipNumber.test.d.ts +0 -1
  503. package/dist/browser/test/document-helpers/prepareOperations.test.d.ts +0 -1
  504. package/dist/browser/test/document-helpers/removeExistingOperations.test.d.ts +0 -1
  505. package/dist/browser/test/document-helpers/reshuffleByTimestamp.test.d.ts +0 -1
  506. package/dist/browser/test/document-helpers/reshuffleByTimestampAndIndex.test.d.ts +0 -1
  507. package/dist/browser/test/document-helpers/skipHeaderOperations.test.d.ts +0 -1
  508. package/dist/browser/test/document-helpers/sortOperations.test.d.ts +0 -1
  509. package/dist/browser/test/document-helpers/split.test.d.ts +0 -1
  510. package/dist/browser/test/document-model/object.test.d.ts +0 -1
  511. package/dist/browser/test/document-model/replay.test.d.ts +0 -1
  512. package/dist/browser/test/document-model/skip-operations.test.d.ts +0 -1
  513. package/dist/browser/test/document-model/validation.test.d.ts +0 -1
  514. package/dist/browser/test/document-model/zip.test.d.ts +0 -1
  515. package/dist/browser/test/helpers.d.ts +0 -39
  516. package/dist/browser/vite.config.d.ts +0 -2
  517. package/dist/browser/vitest.config.d.ts +0 -2
  518. package/dist/node/cjs/document-model.js +0 -24
  519. package/dist/node/cjs/document-model.js.map +0 -1
  520. package/dist/node/cjs/document.js +0 -15
  521. package/dist/node/cjs/document.js.map +0 -1
  522. package/dist/node/cjs/index.js +0 -14
  523. package/dist/node/cjs/index.js.map +0 -1
  524. package/dist/node/cjs/internal/index-CLCVBs4I.js +0 -57
  525. package/dist/node/cjs/internal/index-CLCVBs4I.js.map +0 -1
  526. package/dist/node/cjs/internal/index-Cp37sm40.js +0 -2219
  527. package/dist/node/cjs/internal/index-Cp37sm40.js.map +0 -1
  528. package/dist/node/cjs/internal/object-ByNZ3G_j.js +0 -2480
  529. package/dist/node/cjs/internal/object-ByNZ3G_j.js.map +0 -1
  530. package/dist/node/cjs/package.json +0 -1
  531. package/dist/node/document-model.d.ts +0 -2
  532. package/dist/node/document.d.ts +0 -2
  533. package/dist/node/es/document-model.js +0 -24
  534. package/dist/node/es/document-model.js.map +0 -1
  535. package/dist/node/es/document.js +0 -15
  536. package/dist/node/es/document.js.map +0 -1
  537. package/dist/node/es/index.js +0 -14
  538. package/dist/node/es/index.js.map +0 -1
  539. package/dist/node/es/internal/index-BXfMlE4L.js +0 -58
  540. package/dist/node/es/internal/index-BXfMlE4L.js.map +0 -1
  541. package/dist/node/es/internal/index-ppDSDiFU.js +0 -2220
  542. package/dist/node/es/internal/index-ppDSDiFU.js.map +0 -1
  543. package/dist/node/es/internal/object-C8sca9DR.js +0 -2481
  544. package/dist/node/es/internal/object-C8sca9DR.js.map +0 -1
  545. package/dist/node/es/package.json +0 -1
  546. package/dist/node/index.d.ts +0 -6
  547. package/dist/node/src/document/actions/index.d.ts +0 -14
  548. package/dist/node/src/document/actions/types.d.ts +0 -15
  549. package/dist/node/src/document/index.d.ts +0 -6
  550. package/dist/node/src/document/reducer.d.ts +0 -65
  551. package/dist/node/src/document/schema/index.d.ts +0 -2
  552. package/dist/node/src/document/schema/types.d.ts +0 -176
  553. package/dist/node/src/document/schema/zod.d.ts +0 -116
  554. package/dist/node/src/document/types.d.ts +0 -271
  555. package/dist/node/src/document/utils/base.d.ts +0 -87
  556. package/dist/node/src/document/utils/crypto.d.ts +0 -9
  557. package/dist/node/src/document/utils/document-helpers.d.ts +0 -73
  558. package/dist/node/src/document/utils/index.d.ts +0 -6
  559. package/dist/node/src/document/utils/node.d.ts +0 -9
  560. package/dist/node/src/document/utils/validation.d.ts +0 -2
  561. package/dist/node/src/document-model/custom/reducers/header.d.ts +0 -2
  562. package/dist/node/src/document-model/custom/reducers/module.d.ts +0 -2
  563. package/dist/node/src/document-model/custom/reducers/operation-error.d.ts +0 -2
  564. package/dist/node/src/document-model/custom/reducers/operation-example.d.ts +0 -2
  565. package/dist/node/src/document-model/custom/reducers/operation.d.ts +0 -2
  566. package/dist/node/src/document-model/custom/reducers/state.d.ts +0 -2
  567. package/dist/node/src/document-model/custom/reducers/versioning.d.ts +0 -2
  568. package/dist/node/src/document-model/custom/utils.d.ts +0 -7
  569. package/dist/node/src/document-model/gen/actions.d.ts +0 -15
  570. package/dist/node/src/document-model/gen/creators.d.ts +0 -7
  571. package/dist/node/src/document-model/gen/document-model.d.ts +0 -2
  572. package/dist/node/src/document-model/gen/header/actions.d.ts +0 -9
  573. package/dist/node/src/document-model/gen/header/object.d.ts +0 -12
  574. package/dist/node/src/document-model/gen/index.d.ts +0 -5
  575. package/dist/node/src/document-model/gen/module/actions.d.ts +0 -8
  576. package/dist/node/src/document-model/gen/module/object.d.ts +0 -11
  577. package/dist/node/src/document-model/gen/module/operations.d.ts +0 -9
  578. package/dist/node/src/document-model/gen/object.d.ts +0 -28
  579. package/dist/node/src/document-model/gen/operation/actions.d.ts +0 -13
  580. package/dist/node/src/document-model/gen/operation/creators.d.ts +0 -12
  581. package/dist/node/src/document-model/gen/operation-error/actions.d.ts +0 -10
  582. package/dist/node/src/document-model/gen/operation-error/operations.d.ts +0 -11
  583. package/dist/node/src/document-model/gen/operation-example/actions.d.ts +0 -7
  584. package/dist/node/src/document-model/gen/operation-example/creators.d.ts +0 -6
  585. package/dist/node/src/document-model/gen/operation-example/object.d.ts +0 -10
  586. package/dist/node/src/document-model/gen/operation-example/operations.d.ts +0 -8
  587. package/dist/node/src/document-model/gen/reducer.d.ts +0 -5
  588. package/dist/node/src/document-model/gen/schema/index.d.ts +0 -2
  589. package/dist/node/src/document-model/gen/schema/types.d.ts +0 -453
  590. package/dist/node/src/document-model/gen/schema/zod.d.ts +0 -453
  591. package/dist/node/src/document-model/gen/state/actions.d.ts +0 -9
  592. package/dist/node/src/document-model/gen/state/creators.d.ts +0 -8
  593. package/dist/node/src/document-model/gen/state/object.d.ts +0 -12
  594. package/dist/node/src/document-model/gen/state/operations.d.ts +0 -10
  595. package/dist/node/src/document-model/gen/types.d.ts +0 -8
  596. package/dist/node/src/document-model/gen/utils.d.ts +0 -6
  597. package/dist/node/src/document-model/gen/versioning/actions.d.ts +0 -8
  598. package/dist/node/src/document-model/gen/versioning/creators.d.ts +0 -7
  599. package/dist/node/src/document-model/gen/versioning/object.d.ts +0 -11
  600. package/dist/node/src/document-model/gen/versioning/operations.d.ts +0 -9
  601. package/dist/node/src/document-model/index.d.ts +0 -76
  602. package/dist/node/src/index.d.ts +0 -24
  603. package/dist/node/test/document/crypto.test.d.ts +0 -1
  604. package/dist/node/test/document/event-vs-command.test.d.ts +0 -1
  605. package/dist/node/test/document/local.test.d.ts +0 -1
  606. package/dist/node/test/document/object.test.d.ts +0 -1
  607. package/dist/node/test/document/operation-id.test.d.ts +0 -1
  608. package/dist/node/test/document/prune.test.d.ts +0 -1
  609. package/dist/node/test/document/reducer.test.d.ts +0 -1
  610. package/dist/node/test/document/skip-operations.test.d.ts +0 -1
  611. package/dist/node/test/document/undo-redo.test.d.ts +0 -1
  612. package/dist/node/test/document/utils.test.d.ts +0 -1
  613. package/dist/node/test/document-helpers/addUndo.test.d.ts +0 -1
  614. package/dist/node/test/document-helpers/attachBranch.test.d.ts +0 -1
  615. package/dist/node/test/document-helpers/checkCleanedOperationsIntegrity.test.d.ts +0 -1
  616. package/dist/node/test/document-helpers/conflictResolution.test.d.ts +0 -1
  617. package/dist/node/test/document-helpers/filterDuplicatedOperations.test.d.ts +0 -1
  618. package/dist/node/test/document-helpers/garbageCollect.test.d.ts +0 -1
  619. package/dist/node/test/document-helpers/groupOperationsByScope.test.d.ts +0 -1
  620. package/dist/node/test/document-helpers/merge.test.d.ts +0 -1
  621. package/dist/node/test/document-helpers/nextSkipNumber.test.d.ts +0 -1
  622. package/dist/node/test/document-helpers/prepareOperations.test.d.ts +0 -1
  623. package/dist/node/test/document-helpers/removeExistingOperations.test.d.ts +0 -1
  624. package/dist/node/test/document-helpers/reshuffleByTimestamp.test.d.ts +0 -1
  625. package/dist/node/test/document-helpers/reshuffleByTimestampAndIndex.test.d.ts +0 -1
  626. package/dist/node/test/document-helpers/skipHeaderOperations.test.d.ts +0 -1
  627. package/dist/node/test/document-helpers/sortOperations.test.d.ts +0 -1
  628. package/dist/node/test/document-helpers/split.test.d.ts +0 -1
  629. package/dist/node/test/document-helpers/utils.d.ts +0 -7
  630. package/dist/node/test/document-model/object.test.d.ts +0 -1
  631. package/dist/node/test/document-model/replay.test.d.ts +0 -1
  632. package/dist/node/test/document-model/skip-operations.test.d.ts +0 -1
  633. package/dist/node/test/document-model/validation.test.d.ts +0 -1
  634. package/dist/node/test/document-model/zip.test.d.ts +0 -1
  635. package/dist/node/test/helpers.d.ts +0 -39
  636. package/dist/node/vite.config.d.ts +0 -2
  637. package/dist/node/vitest.config.d.ts +0 -2
@@ -1,2694 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
- const mutative = require("mutative");
6
- const zod$1 = require("zod");
7
- const JSZip = require("jszip");
8
- const isDefinedNonNullAny = (v) => v !== void 0 && v !== null;
9
- const definedNonNullAnySchema = zod$1.z.any().refine((v) => isDefinedNonNullAny(v));
10
- const Load_StateSchema = zod$1.z.enum(["LOAD_STATE"]);
11
- const PruneSchema = zod$1.z.enum(["PRUNE"]);
12
- const RedoSchema = zod$1.z.enum(["REDO"]);
13
- const Set_NameSchema = zod$1.z.enum(["SET_NAME"]);
14
- const UndoSchema = zod$1.z.enum(["UNDO"]);
15
- function ActionSchema() {
16
- return zod$1.z.object({
17
- __typename: zod$1.z.literal("Action").optional(),
18
- type: zod$1.z.string()
19
- });
20
- }
21
- function OperationScopeSchema() {
22
- return zod$1.z.literal("global").or(zod$1.z.literal("local"));
23
- }
24
- function BaseActionSchema() {
25
- return zod$1.z.union([
26
- LoadStateActionSchema(),
27
- PruneActionSchema(),
28
- RedoActionSchema(),
29
- SetNameActionSchema(),
30
- UndoActionSchema()
31
- ]);
32
- }
33
- function DocumentFileSchema() {
34
- return zod$1.z.object({
35
- __typename: zod$1.z.literal("DocumentFile").optional(),
36
- data: zod$1.z.string(),
37
- extension: zod$1.z.string().nullable(),
38
- fileName: zod$1.z.string().nullable(),
39
- mimeType: zod$1.z.string()
40
- });
41
- }
42
- function LoadStateActionSchema() {
43
- return zod$1.z.object({
44
- input: zod$1.z.lazy(() => LoadStateActionInputSchema()),
45
- type: Load_StateSchema,
46
- scope: OperationScopeSchema()
47
- });
48
- }
49
- function LoadStateActionInputSchema() {
50
- return zod$1.z.object({
51
- operations: zod$1.z.number(),
52
- state: zod$1.z.lazy(() => LoadStateActionStateInputSchema())
53
- });
54
- }
55
- function LoadStateActionStateInputSchema() {
56
- return zod$1.z.object({
57
- data: zod$1.z.unknown().nullish(),
58
- name: zod$1.z.string()
59
- });
60
- }
61
- function OperationSchema() {
62
- return zod$1.z.object({
63
- __typename: zod$1.z.literal("Operation").optional(),
64
- hash: zod$1.z.string(),
65
- index: zod$1.z.number(),
66
- timestamp: zod$1.z.string().datetime(),
67
- type: zod$1.z.string()
68
- });
69
- }
70
- function PruneActionSchema() {
71
- return zod$1.z.object({
72
- input: zod$1.z.lazy(() => PruneActionInputSchema()),
73
- type: PruneSchema,
74
- scope: OperationScopeSchema()
75
- });
76
- }
77
- function PruneActionInputSchema() {
78
- return zod$1.z.object({
79
- end: zod$1.z.number().nullish(),
80
- start: zod$1.z.number().nullish()
81
- });
82
- }
83
- const RedoActionInputSchema = zod$1.z.number;
84
- function RedoActionSchema() {
85
- return zod$1.z.object({
86
- input: RedoActionInputSchema(),
87
- type: RedoSchema,
88
- scope: OperationScopeSchema()
89
- });
90
- }
91
- const SetNameActionInputSchema = zod$1.z.string;
92
- function SetNameActionSchema() {
93
- return zod$1.z.object({
94
- input: SetNameActionInputSchema(),
95
- type: Set_NameSchema,
96
- scope: zod$1.z.literal("global")
97
- });
98
- }
99
- function SetNameOperationSchema() {
100
- return zod$1.z.object({
101
- __typename: zod$1.z.literal("SetNameOperation").optional(),
102
- hash: zod$1.z.string(),
103
- index: zod$1.z.number(),
104
- input: zod$1.z.string(),
105
- timestamp: zod$1.z.string().datetime(),
106
- type: zod$1.z.string()
107
- });
108
- }
109
- const UndoActionInputSchema = zod$1.z.number;
110
- function UndoActionSchema() {
111
- return zod$1.z.object({
112
- input: UndoActionInputSchema(),
113
- type: UndoSchema,
114
- scope: OperationScopeSchema()
115
- });
116
- }
117
- const zod = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
118
- __proto__: null,
119
- ActionSchema,
120
- BaseActionSchema,
121
- DocumentFileSchema,
122
- LoadStateActionInputSchema,
123
- LoadStateActionSchema,
124
- LoadStateActionStateInputSchema,
125
- Load_StateSchema,
126
- OperationSchema,
127
- OperationScopeSchema,
128
- PruneActionInputSchema,
129
- PruneActionSchema,
130
- PruneSchema,
131
- RedoActionInputSchema,
132
- RedoActionSchema,
133
- RedoSchema,
134
- SetNameActionInputSchema,
135
- SetNameActionSchema,
136
- SetNameOperationSchema,
137
- Set_NameSchema,
138
- UndoActionInputSchema,
139
- UndoActionSchema,
140
- UndoSchema,
141
- definedNonNullAnySchema,
142
- isDefinedNonNullAny
143
- }, Symbol.toStringTag, { value: "Module" }));
144
- function getDefaultExportFromCjs(x) {
145
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
146
- }
147
- var safeStableStringify = { exports: {} };
148
- (function(module2, exports2) {
149
- const { hasOwnProperty } = Object.prototype;
150
- const stringify = configure();
151
- stringify.configure = configure;
152
- stringify.stringify = stringify;
153
- stringify.default = stringify;
154
- exports2.stringify = stringify;
155
- exports2.configure = configure;
156
- module2.exports = stringify;
157
- const strEscapeSequencesRegExp = /[\u0000-\u001f\u0022\u005c\ud800-\udfff]/;
158
- function strEscape(str) {
159
- if (str.length < 5e3 && !strEscapeSequencesRegExp.test(str)) {
160
- return `"${str}"`;
161
- }
162
- return JSON.stringify(str);
163
- }
164
- function sort(array, comparator) {
165
- if (array.length > 200 || comparator) {
166
- return array.sort(comparator);
167
- }
168
- for (let i = 1; i < array.length; i++) {
169
- const currentValue = array[i];
170
- let position = i;
171
- while (position !== 0 && array[position - 1] > currentValue) {
172
- array[position] = array[position - 1];
173
- position--;
174
- }
175
- array[position] = currentValue;
176
- }
177
- return array;
178
- }
179
- const typedArrayPrototypeGetSymbolToStringTag = Object.getOwnPropertyDescriptor(
180
- Object.getPrototypeOf(
181
- Object.getPrototypeOf(
182
- new Int8Array()
183
- )
184
- ),
185
- Symbol.toStringTag
186
- ).get;
187
- function isTypedArrayWithEntries(value) {
188
- return typedArrayPrototypeGetSymbolToStringTag.call(value) !== void 0 && value.length !== 0;
189
- }
190
- function stringifyTypedArray(array, separator, maximumBreadth) {
191
- if (array.length < maximumBreadth) {
192
- maximumBreadth = array.length;
193
- }
194
- const whitespace = separator === "," ? "" : " ";
195
- let res = `"0":${whitespace}${array[0]}`;
196
- for (let i = 1; i < maximumBreadth; i++) {
197
- res += `${separator}"${i}":${whitespace}${array[i]}`;
198
- }
199
- return res;
200
- }
201
- function getCircularValueOption(options) {
202
- if (hasOwnProperty.call(options, "circularValue")) {
203
- const circularValue = options.circularValue;
204
- if (typeof circularValue === "string") {
205
- return `"${circularValue}"`;
206
- }
207
- if (circularValue == null) {
208
- return circularValue;
209
- }
210
- if (circularValue === Error || circularValue === TypeError) {
211
- return {
212
- toString() {
213
- throw new TypeError("Converting circular structure to JSON");
214
- }
215
- };
216
- }
217
- throw new TypeError('The "circularValue" argument must be of type string or the value null or undefined');
218
- }
219
- return '"[Circular]"';
220
- }
221
- function getDeterministicOption(options) {
222
- let value;
223
- if (hasOwnProperty.call(options, "deterministic")) {
224
- value = options.deterministic;
225
- if (typeof value !== "boolean" && typeof value !== "function") {
226
- throw new TypeError('The "deterministic" argument must be of type boolean or comparator function');
227
- }
228
- }
229
- return value === void 0 ? true : value;
230
- }
231
- function getBooleanOption(options, key) {
232
- let value;
233
- if (hasOwnProperty.call(options, key)) {
234
- value = options[key];
235
- if (typeof value !== "boolean") {
236
- throw new TypeError(`The "${key}" argument must be of type boolean`);
237
- }
238
- }
239
- return value === void 0 ? true : value;
240
- }
241
- function getPositiveIntegerOption(options, key) {
242
- let value;
243
- if (hasOwnProperty.call(options, key)) {
244
- value = options[key];
245
- if (typeof value !== "number") {
246
- throw new TypeError(`The "${key}" argument must be of type number`);
247
- }
248
- if (!Number.isInteger(value)) {
249
- throw new TypeError(`The "${key}" argument must be an integer`);
250
- }
251
- if (value < 1) {
252
- throw new RangeError(`The "${key}" argument must be >= 1`);
253
- }
254
- }
255
- return value === void 0 ? Infinity : value;
256
- }
257
- function getItemCount(number) {
258
- if (number === 1) {
259
- return "1 item";
260
- }
261
- return `${number} items`;
262
- }
263
- function getUniqueReplacerSet(replacerArray) {
264
- const replacerSet = /* @__PURE__ */ new Set();
265
- for (const value of replacerArray) {
266
- if (typeof value === "string" || typeof value === "number") {
267
- replacerSet.add(String(value));
268
- }
269
- }
270
- return replacerSet;
271
- }
272
- function getStrictOption(options) {
273
- if (hasOwnProperty.call(options, "strict")) {
274
- const value = options.strict;
275
- if (typeof value !== "boolean") {
276
- throw new TypeError('The "strict" argument must be of type boolean');
277
- }
278
- if (value) {
279
- return (value2) => {
280
- let message = `Object can not safely be stringified. Received type ${typeof value2}`;
281
- if (typeof value2 !== "function") message += ` (${value2.toString()})`;
282
- throw new Error(message);
283
- };
284
- }
285
- }
286
- }
287
- function configure(options) {
288
- options = { ...options };
289
- const fail = getStrictOption(options);
290
- if (fail) {
291
- if (options.bigint === void 0) {
292
- options.bigint = false;
293
- }
294
- if (!("circularValue" in options)) {
295
- options.circularValue = Error;
296
- }
297
- }
298
- const circularValue = getCircularValueOption(options);
299
- const bigint = getBooleanOption(options, "bigint");
300
- const deterministic = getDeterministicOption(options);
301
- const comparator = typeof deterministic === "function" ? deterministic : void 0;
302
- const maximumDepth = getPositiveIntegerOption(options, "maximumDepth");
303
- const maximumBreadth = getPositiveIntegerOption(options, "maximumBreadth");
304
- function stringifyFnReplacer(key, parent, stack, replacer, spacer, indentation) {
305
- let value = parent[key];
306
- if (typeof value === "object" && value !== null && typeof value.toJSON === "function") {
307
- value = value.toJSON(key);
308
- }
309
- value = replacer.call(parent, key, value);
310
- switch (typeof value) {
311
- case "string":
312
- return strEscape(value);
313
- case "object": {
314
- if (value === null) {
315
- return "null";
316
- }
317
- if (stack.indexOf(value) !== -1) {
318
- return circularValue;
319
- }
320
- let res = "";
321
- let join = ",";
322
- const originalIndentation = indentation;
323
- if (Array.isArray(value)) {
324
- if (value.length === 0) {
325
- return "[]";
326
- }
327
- if (maximumDepth < stack.length + 1) {
328
- return '"[Array]"';
329
- }
330
- stack.push(value);
331
- if (spacer !== "") {
332
- indentation += spacer;
333
- res += `
334
- ${indentation}`;
335
- join = `,
336
- ${indentation}`;
337
- }
338
- const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
339
- let i = 0;
340
- for (; i < maximumValuesToStringify - 1; i++) {
341
- const tmp2 = stringifyFnReplacer(String(i), value, stack, replacer, spacer, indentation);
342
- res += tmp2 !== void 0 ? tmp2 : "null";
343
- res += join;
344
- }
345
- const tmp = stringifyFnReplacer(String(i), value, stack, replacer, spacer, indentation);
346
- res += tmp !== void 0 ? tmp : "null";
347
- if (value.length - 1 > maximumBreadth) {
348
- const removedKeys = value.length - maximumBreadth - 1;
349
- res += `${join}"... ${getItemCount(removedKeys)} not stringified"`;
350
- }
351
- if (spacer !== "") {
352
- res += `
353
- ${originalIndentation}`;
354
- }
355
- stack.pop();
356
- return `[${res}]`;
357
- }
358
- let keys = Object.keys(value);
359
- const keyLength = keys.length;
360
- if (keyLength === 0) {
361
- return "{}";
362
- }
363
- if (maximumDepth < stack.length + 1) {
364
- return '"[Object]"';
365
- }
366
- let whitespace = "";
367
- let separator = "";
368
- if (spacer !== "") {
369
- indentation += spacer;
370
- join = `,
371
- ${indentation}`;
372
- whitespace = " ";
373
- }
374
- const maximumPropertiesToStringify = Math.min(keyLength, maximumBreadth);
375
- if (deterministic && !isTypedArrayWithEntries(value)) {
376
- keys = sort(keys, comparator);
377
- }
378
- stack.push(value);
379
- for (let i = 0; i < maximumPropertiesToStringify; i++) {
380
- const key2 = keys[i];
381
- const tmp = stringifyFnReplacer(key2, value, stack, replacer, spacer, indentation);
382
- if (tmp !== void 0) {
383
- res += `${separator}${strEscape(key2)}:${whitespace}${tmp}`;
384
- separator = join;
385
- }
386
- }
387
- if (keyLength > maximumBreadth) {
388
- const removedKeys = keyLength - maximumBreadth;
389
- res += `${separator}"...":${whitespace}"${getItemCount(removedKeys)} not stringified"`;
390
- separator = join;
391
- }
392
- if (spacer !== "" && separator.length > 1) {
393
- res = `
394
- ${indentation}${res}
395
- ${originalIndentation}`;
396
- }
397
- stack.pop();
398
- return `{${res}}`;
399
- }
400
- case "number":
401
- return isFinite(value) ? String(value) : fail ? fail(value) : "null";
402
- case "boolean":
403
- return value === true ? "true" : "false";
404
- case "undefined":
405
- return void 0;
406
- case "bigint":
407
- if (bigint) {
408
- return String(value);
409
- }
410
- default:
411
- return fail ? fail(value) : void 0;
412
- }
413
- }
414
- function stringifyArrayReplacer(key, value, stack, replacer, spacer, indentation) {
415
- if (typeof value === "object" && value !== null && typeof value.toJSON === "function") {
416
- value = value.toJSON(key);
417
- }
418
- switch (typeof value) {
419
- case "string":
420
- return strEscape(value);
421
- case "object": {
422
- if (value === null) {
423
- return "null";
424
- }
425
- if (stack.indexOf(value) !== -1) {
426
- return circularValue;
427
- }
428
- const originalIndentation = indentation;
429
- let res = "";
430
- let join = ",";
431
- if (Array.isArray(value)) {
432
- if (value.length === 0) {
433
- return "[]";
434
- }
435
- if (maximumDepth < stack.length + 1) {
436
- return '"[Array]"';
437
- }
438
- stack.push(value);
439
- if (spacer !== "") {
440
- indentation += spacer;
441
- res += `
442
- ${indentation}`;
443
- join = `,
444
- ${indentation}`;
445
- }
446
- const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
447
- let i = 0;
448
- for (; i < maximumValuesToStringify - 1; i++) {
449
- const tmp2 = stringifyArrayReplacer(String(i), value[i], stack, replacer, spacer, indentation);
450
- res += tmp2 !== void 0 ? tmp2 : "null";
451
- res += join;
452
- }
453
- const tmp = stringifyArrayReplacer(String(i), value[i], stack, replacer, spacer, indentation);
454
- res += tmp !== void 0 ? tmp : "null";
455
- if (value.length - 1 > maximumBreadth) {
456
- const removedKeys = value.length - maximumBreadth - 1;
457
- res += `${join}"... ${getItemCount(removedKeys)} not stringified"`;
458
- }
459
- if (spacer !== "") {
460
- res += `
461
- ${originalIndentation}`;
462
- }
463
- stack.pop();
464
- return `[${res}]`;
465
- }
466
- stack.push(value);
467
- let whitespace = "";
468
- if (spacer !== "") {
469
- indentation += spacer;
470
- join = `,
471
- ${indentation}`;
472
- whitespace = " ";
473
- }
474
- let separator = "";
475
- for (const key2 of replacer) {
476
- const tmp = stringifyArrayReplacer(key2, value[key2], stack, replacer, spacer, indentation);
477
- if (tmp !== void 0) {
478
- res += `${separator}${strEscape(key2)}:${whitespace}${tmp}`;
479
- separator = join;
480
- }
481
- }
482
- if (spacer !== "" && separator.length > 1) {
483
- res = `
484
- ${indentation}${res}
485
- ${originalIndentation}`;
486
- }
487
- stack.pop();
488
- return `{${res}}`;
489
- }
490
- case "number":
491
- return isFinite(value) ? String(value) : fail ? fail(value) : "null";
492
- case "boolean":
493
- return value === true ? "true" : "false";
494
- case "undefined":
495
- return void 0;
496
- case "bigint":
497
- if (bigint) {
498
- return String(value);
499
- }
500
- default:
501
- return fail ? fail(value) : void 0;
502
- }
503
- }
504
- function stringifyIndent(key, value, stack, spacer, indentation) {
505
- switch (typeof value) {
506
- case "string":
507
- return strEscape(value);
508
- case "object": {
509
- if (value === null) {
510
- return "null";
511
- }
512
- if (typeof value.toJSON === "function") {
513
- value = value.toJSON(key);
514
- if (typeof value !== "object") {
515
- return stringifyIndent(key, value, stack, spacer, indentation);
516
- }
517
- if (value === null) {
518
- return "null";
519
- }
520
- }
521
- if (stack.indexOf(value) !== -1) {
522
- return circularValue;
523
- }
524
- const originalIndentation = indentation;
525
- if (Array.isArray(value)) {
526
- if (value.length === 0) {
527
- return "[]";
528
- }
529
- if (maximumDepth < stack.length + 1) {
530
- return '"[Array]"';
531
- }
532
- stack.push(value);
533
- indentation += spacer;
534
- let res2 = `
535
- ${indentation}`;
536
- const join2 = `,
537
- ${indentation}`;
538
- const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
539
- let i = 0;
540
- for (; i < maximumValuesToStringify - 1; i++) {
541
- const tmp2 = stringifyIndent(String(i), value[i], stack, spacer, indentation);
542
- res2 += tmp2 !== void 0 ? tmp2 : "null";
543
- res2 += join2;
544
- }
545
- const tmp = stringifyIndent(String(i), value[i], stack, spacer, indentation);
546
- res2 += tmp !== void 0 ? tmp : "null";
547
- if (value.length - 1 > maximumBreadth) {
548
- const removedKeys = value.length - maximumBreadth - 1;
549
- res2 += `${join2}"... ${getItemCount(removedKeys)} not stringified"`;
550
- }
551
- res2 += `
552
- ${originalIndentation}`;
553
- stack.pop();
554
- return `[${res2}]`;
555
- }
556
- let keys = Object.keys(value);
557
- const keyLength = keys.length;
558
- if (keyLength === 0) {
559
- return "{}";
560
- }
561
- if (maximumDepth < stack.length + 1) {
562
- return '"[Object]"';
563
- }
564
- indentation += spacer;
565
- const join = `,
566
- ${indentation}`;
567
- let res = "";
568
- let separator = "";
569
- let maximumPropertiesToStringify = Math.min(keyLength, maximumBreadth);
570
- if (isTypedArrayWithEntries(value)) {
571
- res += stringifyTypedArray(value, join, maximumBreadth);
572
- keys = keys.slice(value.length);
573
- maximumPropertiesToStringify -= value.length;
574
- separator = join;
575
- }
576
- if (deterministic) {
577
- keys = sort(keys, comparator);
578
- }
579
- stack.push(value);
580
- for (let i = 0; i < maximumPropertiesToStringify; i++) {
581
- const key2 = keys[i];
582
- const tmp = stringifyIndent(key2, value[key2], stack, spacer, indentation);
583
- if (tmp !== void 0) {
584
- res += `${separator}${strEscape(key2)}: ${tmp}`;
585
- separator = join;
586
- }
587
- }
588
- if (keyLength > maximumBreadth) {
589
- const removedKeys = keyLength - maximumBreadth;
590
- res += `${separator}"...": "${getItemCount(removedKeys)} not stringified"`;
591
- separator = join;
592
- }
593
- if (separator !== "") {
594
- res = `
595
- ${indentation}${res}
596
- ${originalIndentation}`;
597
- }
598
- stack.pop();
599
- return `{${res}}`;
600
- }
601
- case "number":
602
- return isFinite(value) ? String(value) : fail ? fail(value) : "null";
603
- case "boolean":
604
- return value === true ? "true" : "false";
605
- case "undefined":
606
- return void 0;
607
- case "bigint":
608
- if (bigint) {
609
- return String(value);
610
- }
611
- default:
612
- return fail ? fail(value) : void 0;
613
- }
614
- }
615
- function stringifySimple(key, value, stack) {
616
- switch (typeof value) {
617
- case "string":
618
- return strEscape(value);
619
- case "object": {
620
- if (value === null) {
621
- return "null";
622
- }
623
- if (typeof value.toJSON === "function") {
624
- value = value.toJSON(key);
625
- if (typeof value !== "object") {
626
- return stringifySimple(key, value, stack);
627
- }
628
- if (value === null) {
629
- return "null";
630
- }
631
- }
632
- if (stack.indexOf(value) !== -1) {
633
- return circularValue;
634
- }
635
- let res = "";
636
- const hasLength = value.length !== void 0;
637
- if (hasLength && Array.isArray(value)) {
638
- if (value.length === 0) {
639
- return "[]";
640
- }
641
- if (maximumDepth < stack.length + 1) {
642
- return '"[Array]"';
643
- }
644
- stack.push(value);
645
- const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
646
- let i = 0;
647
- for (; i < maximumValuesToStringify - 1; i++) {
648
- const tmp2 = stringifySimple(String(i), value[i], stack);
649
- res += tmp2 !== void 0 ? tmp2 : "null";
650
- res += ",";
651
- }
652
- const tmp = stringifySimple(String(i), value[i], stack);
653
- res += tmp !== void 0 ? tmp : "null";
654
- if (value.length - 1 > maximumBreadth) {
655
- const removedKeys = value.length - maximumBreadth - 1;
656
- res += `,"... ${getItemCount(removedKeys)} not stringified"`;
657
- }
658
- stack.pop();
659
- return `[${res}]`;
660
- }
661
- let keys = Object.keys(value);
662
- const keyLength = keys.length;
663
- if (keyLength === 0) {
664
- return "{}";
665
- }
666
- if (maximumDepth < stack.length + 1) {
667
- return '"[Object]"';
668
- }
669
- let separator = "";
670
- let maximumPropertiesToStringify = Math.min(keyLength, maximumBreadth);
671
- if (hasLength && isTypedArrayWithEntries(value)) {
672
- res += stringifyTypedArray(value, ",", maximumBreadth);
673
- keys = keys.slice(value.length);
674
- maximumPropertiesToStringify -= value.length;
675
- separator = ",";
676
- }
677
- if (deterministic) {
678
- keys = sort(keys, comparator);
679
- }
680
- stack.push(value);
681
- for (let i = 0; i < maximumPropertiesToStringify; i++) {
682
- const key2 = keys[i];
683
- const tmp = stringifySimple(key2, value[key2], stack);
684
- if (tmp !== void 0) {
685
- res += `${separator}${strEscape(key2)}:${tmp}`;
686
- separator = ",";
687
- }
688
- }
689
- if (keyLength > maximumBreadth) {
690
- const removedKeys = keyLength - maximumBreadth;
691
- res += `${separator}"...":"${getItemCount(removedKeys)} not stringified"`;
692
- }
693
- stack.pop();
694
- return `{${res}}`;
695
- }
696
- case "number":
697
- return isFinite(value) ? String(value) : fail ? fail(value) : "null";
698
- case "boolean":
699
- return value === true ? "true" : "false";
700
- case "undefined":
701
- return void 0;
702
- case "bigint":
703
- if (bigint) {
704
- return String(value);
705
- }
706
- default:
707
- return fail ? fail(value) : void 0;
708
- }
709
- }
710
- function stringify2(value, replacer, space) {
711
- if (arguments.length > 1) {
712
- let spacer = "";
713
- if (typeof space === "number") {
714
- spacer = " ".repeat(Math.min(space, 10));
715
- } else if (typeof space === "string") {
716
- spacer = space.slice(0, 10);
717
- }
718
- if (replacer != null) {
719
- if (typeof replacer === "function") {
720
- return stringifyFnReplacer("", { "": value }, [], replacer, spacer, "");
721
- }
722
- if (Array.isArray(replacer)) {
723
- return stringifyArrayReplacer("", value, [], getUniqueReplacerSet(replacer), spacer, "");
724
- }
725
- }
726
- if (spacer.length !== 0) {
727
- return stringifyIndent("", value, [], spacer, "");
728
- }
729
- }
730
- return stringifySimple("", value, []);
731
- }
732
- return stringify2;
733
- }
734
- })(safeStableStringify, safeStableStringify.exports);
735
- var safeStableStringifyExports = safeStableStringify.exports;
736
- const cjsModule = /* @__PURE__ */ getDefaultExportFromCjs(safeStableStringifyExports);
737
- cjsModule.configure;
738
- let getRandomValues;
739
- const rnds8 = new Uint8Array(16);
740
- function rng() {
741
- if (!getRandomValues) {
742
- getRandomValues = typeof crypto !== "undefined" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);
743
- if (!getRandomValues) {
744
- throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
745
- }
746
- }
747
- return getRandomValues(rnds8);
748
- }
749
- const byteToHex = [];
750
- for (let i = 0; i < 256; ++i) {
751
- byteToHex.push((i + 256).toString(16).slice(1));
752
- }
753
- function unsafeStringify(arr, offset = 0) {
754
- return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]];
755
- }
756
- const randomUUID = typeof crypto !== "undefined" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
757
- const native = {
758
- randomUUID
759
- };
760
- function v4(options, buf, offset) {
761
- if (native.randomUUID && !buf && !options) {
762
- return native.randomUUID();
763
- }
764
- options = options || {};
765
- const rnds = options.random || (options.rng || rng)();
766
- rnds[6] = rnds[6] & 15 | 64;
767
- rnds[8] = rnds[8] & 63 | 128;
768
- return unsafeStringify(rnds);
769
- }
770
- const K = [
771
- 1518500249 | 0,
772
- 1859775393 | 0,
773
- 2400959708 | 0,
774
- 3395469782 | 0
775
- ];
776
- function createHash(algorithm) {
777
- return new Hash();
778
- }
779
- class Hash {
780
- constructor() {
781
- this.A = 1732584193 | 0;
782
- this.B = 4023233417 | 0;
783
- this.C = 2562383102 | 0;
784
- this.D = 271733878 | 0;
785
- this.E = 3285377520 | 0;
786
- this._size = 0;
787
- this._sp = 0;
788
- if (!sharedBuffer || sharedOffset >= 8e3) {
789
- sharedBuffer = new ArrayBuffer(
790
- 8e3
791
- /* N.allocTotal */
792
- );
793
- sharedOffset = 0;
794
- }
795
- this._byte = new Uint8Array(
796
- sharedBuffer,
797
- sharedOffset,
798
- 80
799
- /* N.allocBytes */
800
- );
801
- this._word = new Int32Array(
802
- sharedBuffer,
803
- sharedOffset,
804
- 20
805
- /* N.allocWords */
806
- );
807
- sharedOffset += 80;
808
- }
809
- update(data) {
810
- if ("string" === typeof data) {
811
- return this._utf8(data);
812
- }
813
- if (data == null) {
814
- throw new TypeError("Invalid type: " + typeof data);
815
- }
816
- const byteOffset = data.byteOffset;
817
- const length = data.byteLength;
818
- let blocks = length / 64 | 0;
819
- let offset = 0;
820
- if (blocks && !(byteOffset & 3) && !(this._size % 64)) {
821
- const block = new Int32Array(
822
- data.buffer,
823
- byteOffset,
824
- blocks * 16
825
- /* N.inputWords */
826
- );
827
- while (blocks--) {
828
- this._int32(block, offset >> 2);
829
- offset += 64;
830
- }
831
- this._size += offset;
832
- }
833
- const BYTES_PER_ELEMENT = data.BYTES_PER_ELEMENT;
834
- if (BYTES_PER_ELEMENT !== 1 && data.buffer) {
835
- const rest = new Uint8Array(data.buffer, byteOffset + offset, length - offset);
836
- return this._uint8(rest);
837
- }
838
- if (offset === length)
839
- return this;
840
- return this._uint8(data, offset);
841
- }
842
- _uint8(data, offset) {
843
- const { _byte, _word } = this;
844
- const length = data.length;
845
- offset = offset | 0;
846
- while (offset < length) {
847
- const start = this._size % 64;
848
- let index = start;
849
- while (offset < length && index < 64) {
850
- _byte[index++] = data[offset++];
851
- }
852
- if (index >= 64) {
853
- this._int32(_word);
854
- }
855
- this._size += index - start;
856
- }
857
- return this;
858
- }
859
- _utf8(text) {
860
- const { _byte, _word } = this;
861
- const length = text.length;
862
- let surrogate = this._sp;
863
- for (let offset = 0; offset < length; ) {
864
- const start = this._size % 64;
865
- let index = start;
866
- while (offset < length && index < 64) {
867
- let code = text.charCodeAt(offset++) | 0;
868
- if (code < 128) {
869
- _byte[index++] = code;
870
- } else if (code < 2048) {
871
- _byte[index++] = 192 | code >>> 6;
872
- _byte[index++] = 128 | code & 63;
873
- } else if (code < 55296 || code > 57343) {
874
- _byte[index++] = 224 | code >>> 12;
875
- _byte[index++] = 128 | code >>> 6 & 63;
876
- _byte[index++] = 128 | code & 63;
877
- } else if (surrogate) {
878
- code = ((surrogate & 1023) << 10) + (code & 1023) + 65536;
879
- _byte[index++] = 240 | code >>> 18;
880
- _byte[index++] = 128 | code >>> 12 & 63;
881
- _byte[index++] = 128 | code >>> 6 & 63;
882
- _byte[index++] = 128 | code & 63;
883
- surrogate = 0;
884
- } else {
885
- surrogate = code;
886
- }
887
- }
888
- if (index >= 64) {
889
- this._int32(_word);
890
- _word[0] = _word[
891
- 16
892
- /* N.inputWords */
893
- ];
894
- }
895
- this._size += index - start;
896
- }
897
- this._sp = surrogate;
898
- return this;
899
- }
900
- _int32(data, offset) {
901
- let { A, B, C, D, E } = this;
902
- let i = 0;
903
- offset = offset | 0;
904
- while (i < 16) {
905
- W[i++] = swap32(data[offset++]);
906
- }
907
- for (i = 16; i < 80; i++) {
908
- W[i] = rotate1(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]);
909
- }
910
- for (i = 0; i < 80; i++) {
911
- const S = i / 20 | 0;
912
- const T = rotate5(A) + ft(S, B, C, D) + E + W[i] + K[S] | 0;
913
- E = D;
914
- D = C;
915
- C = rotate30(B);
916
- B = A;
917
- A = T;
918
- }
919
- this.A = A + this.A | 0;
920
- this.B = B + this.B | 0;
921
- this.C = C + this.C | 0;
922
- this.D = D + this.D | 0;
923
- this.E = E + this.E | 0;
924
- }
925
- digest(encoding) {
926
- const { _byte, _word } = this;
927
- let i = this._size % 64 | 0;
928
- _byte[i++] = 128;
929
- while (i & 3) {
930
- _byte[i++] = 0;
931
- }
932
- i >>= 2;
933
- if (i > 14) {
934
- while (i < 16) {
935
- _word[i++] = 0;
936
- }
937
- i = 0;
938
- this._int32(_word);
939
- }
940
- while (i < 16) {
941
- _word[i++] = 0;
942
- }
943
- const bits64 = this._size * 8;
944
- const low32 = (bits64 & 4294967295) >>> 0;
945
- const high32 = (bits64 - low32) / 4294967296;
946
- if (high32)
947
- _word[
948
- 14
949
- /* N.highIndex */
950
- ] = swap32(high32);
951
- if (low32)
952
- _word[
953
- 15
954
- /* N.lowIndex */
955
- ] = swap32(low32);
956
- this._int32(_word);
957
- return encoding === "hex" ? this._hex() : this._bin();
958
- }
959
- _hex() {
960
- const { A, B, C, D, E } = this;
961
- return hex32(A) + hex32(B) + hex32(C) + hex32(D) + hex32(E);
962
- }
963
- _bin() {
964
- const { A, B, C, D, E, _byte, _word } = this;
965
- _word[0] = swap32(A);
966
- _word[1] = swap32(B);
967
- _word[2] = swap32(C);
968
- _word[3] = swap32(D);
969
- _word[4] = swap32(E);
970
- return _byte.slice(0, 20);
971
- }
972
- }
973
- const W = new Int32Array(
974
- 80
975
- /* N.workWords */
976
- );
977
- let sharedBuffer;
978
- let sharedOffset = 0;
979
- const hex32 = (num) => (num + 4294967296).toString(16).substr(-8);
980
- const swapLE = (c) => c << 24 & 4278190080 | c << 8 & 16711680 | c >> 8 & 65280 | c >> 24 & 255;
981
- const swapBE = (c) => c;
982
- const swap32 = isBE() ? swapBE : swapLE;
983
- const rotate1 = (num) => num << 1 | num >>> 31;
984
- const rotate5 = (num) => num << 5 | num >>> 27;
985
- const rotate30 = (num) => num << 30 | num >>> 2;
986
- function ft(s, b, c, d) {
987
- if (s === 0)
988
- return b & c | ~b & d;
989
- if (s === 2)
990
- return b & c | b & d | c & d;
991
- return b ^ c ^ d;
992
- }
993
- function isBE() {
994
- const buf = new Uint8Array(new Uint16Array([65279]).buffer);
995
- return buf[0] === 254;
996
- }
997
- const FileSystemError = new Error("File system not available.");
998
- function writeFile(path, name, stream) {
999
- throw FileSystemError;
1000
- }
1001
- function readFile(path) {
1002
- throw FileSystemError;
1003
- }
1004
- function fetchFile(url) {
1005
- throw FileSystemError;
1006
- }
1007
- const getFile = async (file) => {
1008
- return readFile();
1009
- };
1010
- const hash = (data, algorithm = "sha1") => {
1011
- if (!["sha1"].includes(algorithm)) {
1012
- throw new Error("Hashing algorithm not supported: Available: sha1");
1013
- }
1014
- const hash2 = hashUIntArray(data);
1015
- return uint8ArrayToBase64(hash2);
1016
- };
1017
- function uint8ArrayToBase64(uint8Array) {
1018
- let binaryString = "";
1019
- for (let i = 0; i < uint8Array.length; i++) {
1020
- binaryString += String.fromCharCode(uint8Array[i]);
1021
- }
1022
- const base64String = btoa(binaryString);
1023
- return base64String;
1024
- }
1025
- function hashUIntArray(data, algorithm = "sha1") {
1026
- if (!["sha1"].includes(algorithm)) {
1027
- throw new Error("Hashing algorithm not supported: Available: sha1");
1028
- }
1029
- return createHash().update(data).digest();
1030
- }
1031
- function getUnixTimestamp(date) {
1032
- return (new Date(date).getTime() / 1e3).toFixed(0);
1033
- }
1034
- function buildOperationSignatureParams({
1035
- documentId,
1036
- signer,
1037
- operation,
1038
- previousStateHash
1039
- }) {
1040
- const { timestamp, scope, id, type } = operation;
1041
- return [
1042
- getUnixTimestamp(timestamp),
1043
- // timestamp,
1044
- signer.app.key,
1045
- // signer public key
1046
- hash(
1047
- // hash (docID, scope, operationID, operationName, operationInput)
1048
- [documentId, scope, id, type, cjsModule(operation.input)].join("")
1049
- ),
1050
- previousStateHash
1051
- // state hash that the operation was applied to
1052
- ];
1053
- }
1054
- const textEncode = new TextEncoder();
1055
- function buildOperationSignatureMessage(params) {
1056
- const message = params.join("");
1057
- const prefix = "Signed Operation:\n" + message.length.toString();
1058
- return textEncode.encode(prefix + message);
1059
- }
1060
- function ab2hex(ab) {
1061
- return Array.prototype.map.call(new Uint8Array(ab), (x) => ("00" + x.toString(16)).slice(-2)).join("");
1062
- }
1063
- function hex2ab(hex) {
1064
- var _a;
1065
- return new Uint8Array(
1066
- ((_a = hex.match(/[\da-f]{2}/gi)) == null ? void 0 : _a.map(function(h) {
1067
- return parseInt(h, 16);
1068
- })) ?? []
1069
- );
1070
- }
1071
- async function buildOperationSignature(context, signMethod) {
1072
- const params = buildOperationSignatureParams(context);
1073
- const message = buildOperationSignatureMessage(params);
1074
- const signature = await signMethod(message);
1075
- return [...params, `0x${ab2hex(signature)}`];
1076
- }
1077
- async function buildSignedOperation(action, reducer, document, context, signHandler) {
1078
- var _a, _b;
1079
- const result = reducer(document, action, void 0, {
1080
- reuseHash: true,
1081
- reuseOperationResultingState: true
1082
- });
1083
- const operation = result.operations[action.scope].at(-1);
1084
- if (!operation) {
1085
- throw new Error("Action was not applied");
1086
- }
1087
- const previousStateHash = ((_a = result.operations[action.scope].at(-2)) == null ? void 0 : _a.hash) ?? "";
1088
- const signature = await buildOperationSignature(
1089
- {
1090
- ...context,
1091
- operation,
1092
- previousStateHash
1093
- },
1094
- signHandler
1095
- );
1096
- return {
1097
- ...operation,
1098
- context: {
1099
- ...operation.context,
1100
- signer: {
1101
- ...(_b = operation.context) == null ? void 0 : _b.signer,
1102
- ...context.signer,
1103
- signatures: [...context.signer.signatures ?? [], signature]
1104
- }
1105
- }
1106
- };
1107
- }
1108
- async function verifyOperationSignature(signature, signer, verifyHandler) {
1109
- const publicKey = signer.app.key;
1110
- const params = signature.slice(0, 4);
1111
- const signatureBytes = hex2ab(signature[4]);
1112
- const expectedMessage = buildOperationSignatureMessage(params);
1113
- return verifyHandler(publicKey, signatureBytes, expectedMessage);
1114
- }
1115
- const types = { "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"] };
1116
- Object.freeze(types);
1117
- var __classPrivateFieldGet = function(receiver, state, kind, f) {
1118
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
1119
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
1120
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
1121
- };
1122
- var _Mime_extensionToType, _Mime_typeToExtension, _Mime_typeToExtensions;
1123
- class Mime {
1124
- constructor(...args) {
1125
- _Mime_extensionToType.set(this, /* @__PURE__ */ new Map());
1126
- _Mime_typeToExtension.set(this, /* @__PURE__ */ new Map());
1127
- _Mime_typeToExtensions.set(this, /* @__PURE__ */ new Map());
1128
- for (const arg of args) {
1129
- this.define(arg);
1130
- }
1131
- }
1132
- define(typeMap, force = false) {
1133
- for (let [type, extensions] of Object.entries(typeMap)) {
1134
- type = type.toLowerCase();
1135
- extensions = extensions.map((ext) => ext.toLowerCase());
1136
- if (!__classPrivateFieldGet(this, _Mime_typeToExtensions, "f").has(type)) {
1137
- __classPrivateFieldGet(this, _Mime_typeToExtensions, "f").set(type, /* @__PURE__ */ new Set());
1138
- }
1139
- const allExtensions = __classPrivateFieldGet(this, _Mime_typeToExtensions, "f").get(type);
1140
- let first = true;
1141
- for (let extension of extensions) {
1142
- const starred = extension.startsWith("*");
1143
- extension = starred ? extension.slice(1) : extension;
1144
- allExtensions == null ? void 0 : allExtensions.add(extension);
1145
- if (first) {
1146
- __classPrivateFieldGet(this, _Mime_typeToExtension, "f").set(type, extension);
1147
- }
1148
- first = false;
1149
- if (starred)
1150
- continue;
1151
- const currentType = __classPrivateFieldGet(this, _Mime_extensionToType, "f").get(extension);
1152
- if (currentType && currentType != type && !force) {
1153
- throw new Error(`"${type} -> ${extension}" conflicts with "${currentType} -> ${extension}". Pass \`force=true\` to override this definition.`);
1154
- }
1155
- __classPrivateFieldGet(this, _Mime_extensionToType, "f").set(extension, type);
1156
- }
1157
- }
1158
- return this;
1159
- }
1160
- getType(path) {
1161
- if (typeof path !== "string")
1162
- return null;
1163
- const last = path.replace(/^.*[/\\]/, "").toLowerCase();
1164
- const ext = last.replace(/^.*\./, "").toLowerCase();
1165
- const hasPath = last.length < path.length;
1166
- const hasDot = ext.length < last.length - 1;
1167
- if (!hasDot && hasPath)
1168
- return null;
1169
- return __classPrivateFieldGet(this, _Mime_extensionToType, "f").get(ext) ?? null;
1170
- }
1171
- getExtension(type) {
1172
- var _a;
1173
- if (typeof type !== "string")
1174
- return null;
1175
- type = (_a = type == null ? void 0 : type.split) == null ? void 0 : _a.call(type, ";")[0];
1176
- return (type && __classPrivateFieldGet(this, _Mime_typeToExtension, "f").get(type.trim().toLowerCase())) ?? null;
1177
- }
1178
- getAllExtensions(type) {
1179
- if (typeof type !== "string")
1180
- return null;
1181
- return __classPrivateFieldGet(this, _Mime_typeToExtensions, "f").get(type.toLowerCase()) ?? null;
1182
- }
1183
- _freeze() {
1184
- this.define = () => {
1185
- throw new Error("define() not allowed for built-in Mime objects. See https://github.com/broofa/mime/blob/main/README.md#custom-mime-instances");
1186
- };
1187
- Object.freeze(this);
1188
- for (const extensions of __classPrivateFieldGet(this, _Mime_typeToExtensions, "f").values()) {
1189
- Object.freeze(extensions);
1190
- }
1191
- return this;
1192
- }
1193
- _getTestState() {
1194
- return {
1195
- types: __classPrivateFieldGet(this, _Mime_extensionToType, "f"),
1196
- extensions: __classPrivateFieldGet(this, _Mime_typeToExtension, "f")
1197
- };
1198
- }
1199
- }
1200
- _Mime_extensionToType = /* @__PURE__ */ new WeakMap(), _Mime_typeToExtension = /* @__PURE__ */ new WeakMap(), _Mime_typeToExtensions = /* @__PURE__ */ new WeakMap();
1201
- const mime = new Mime(types)._freeze();
1202
- function validateOperations(operations) {
1203
- const errors = [];
1204
- const scopes = Object.keys(operations);
1205
- for (const scope of scopes) {
1206
- const ops = operations[scope].sort((a, b) => a.index - b.index);
1207
- let opIndex = -1;
1208
- for (let i = 0; i < ops.length; i++) {
1209
- opIndex = opIndex + 1 + ops[i].skip;
1210
- if (ops[i].index !== opIndex) {
1211
- errors.push({
1212
- message: `Invalid operation index ${ops[i].index} at position ${i}`,
1213
- details: {
1214
- position: i,
1215
- operation: ops[i],
1216
- scope: ops[i].scope
1217
- }
1218
- });
1219
- }
1220
- }
1221
- }
1222
- return errors;
1223
- }
1224
- var IntegrityIssueType = /* @__PURE__ */ ((IntegrityIssueType2) => {
1225
- IntegrityIssueType2["UNEXPECTED_INDEX"] = "UNEXPECTED_INDEX";
1226
- return IntegrityIssueType2;
1227
- })(IntegrityIssueType || {});
1228
- var IntegrityIssueSubType = /* @__PURE__ */ ((IntegrityIssueSubType2) => {
1229
- IntegrityIssueSubType2["DUPLICATED_INDEX"] = "DUPLICATED_INDEX";
1230
- IntegrityIssueSubType2["MISSING_INDEX"] = "MISSING_INDEX";
1231
- return IntegrityIssueSubType2;
1232
- })(IntegrityIssueSubType || {});
1233
- function checkCleanedOperationsIntegrity(sortedOperations) {
1234
- const result = [];
1235
- let currentIndex = -1;
1236
- for (const nextOperation of sortedOperations) {
1237
- const nextIndex = nextOperation.index - nextOperation.skip;
1238
- if (nextIndex !== currentIndex + 1) {
1239
- result.push({
1240
- operation: {
1241
- index: nextOperation.index,
1242
- skip: nextOperation.skip
1243
- },
1244
- issue: "UNEXPECTED_INDEX",
1245
- category: nextIndex > currentIndex + 1 ? "MISSING_INDEX" : "DUPLICATED_INDEX",
1246
- message: `Expected index ${currentIndex + 1} with skip 0 or equivalent, got index ${nextOperation.index} with skip ${nextOperation.skip}`
1247
- });
1248
- }
1249
- currentIndex = nextOperation.index;
1250
- }
1251
- return result;
1252
- }
1253
- function garbageCollect(sortedOperations) {
1254
- var _a, _b, _c;
1255
- const result = [];
1256
- let i = sortedOperations.length - 1;
1257
- while (i > -1) {
1258
- result.unshift(sortedOperations[i]);
1259
- const skipUntil = (((_a = sortedOperations[i]) == null ? void 0 : _a.index) || 0) - (((_b = sortedOperations[i]) == null ? void 0 : _b.skip) || 0) - 1;
1260
- let j = i - 1;
1261
- while (j > -1 && (((_c = sortedOperations[j]) == null ? void 0 : _c.index) || 0) > skipUntil) {
1262
- j--;
1263
- }
1264
- i = j;
1265
- }
1266
- return result;
1267
- }
1268
- function addUndo(sortedOperations) {
1269
- const operationsCopy = [...sortedOperations];
1270
- const latestOperation = operationsCopy[operationsCopy.length - 1];
1271
- if (!latestOperation) return operationsCopy;
1272
- if (latestOperation.type === "NOOP") {
1273
- operationsCopy.push({
1274
- ...latestOperation,
1275
- index: latestOperation.index,
1276
- type: "NOOP",
1277
- skip: nextSkipNumber(sortedOperations)
1278
- });
1279
- } else {
1280
- operationsCopy.push({
1281
- type: "NOOP",
1282
- index: latestOperation.index + 1,
1283
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1284
- input: {},
1285
- skip: 1,
1286
- scope: latestOperation.scope,
1287
- hash: latestOperation.hash
1288
- });
1289
- }
1290
- return operationsCopy;
1291
- }
1292
- function sortOperations$1(operations) {
1293
- return operations.slice().sort((a, b) => a.skip - b.skip).sort((a, b) => a.index - b.index);
1294
- }
1295
- const reshuffleByTimestamp = (startIndex, opsA, opsB) => {
1296
- return [...opsA, ...opsB].sort(
1297
- (a, b) => new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime()
1298
- ).map((op, i) => ({
1299
- ...op,
1300
- index: startIndex.index + i,
1301
- skip: i === 0 ? startIndex.skip : 0
1302
- }));
1303
- };
1304
- const reshuffleByTimestampAndIndex = (startIndex, opsA, opsB) => {
1305
- return [...opsA, ...opsB].sort(
1306
- (a, b) => new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime()
1307
- ).sort((a, b) => a.index - b.index).map((op, i) => ({
1308
- ...op,
1309
- index: startIndex.index + i,
1310
- skip: i === 0 ? startIndex.skip : 0
1311
- }));
1312
- };
1313
- function operationsAreEqual(op1, op2) {
1314
- return cjsModule(op1) === cjsModule(op2);
1315
- }
1316
- function attachBranch(trunk, newBranch) {
1317
- const trunkCopy = garbageCollect(sortOperations$1(trunk.slice()));
1318
- const newOperations = garbageCollect(sortOperations$1(newBranch.slice()));
1319
- if (trunkCopy.length < 1) {
1320
- return [newOperations, []];
1321
- }
1322
- const result = [];
1323
- let enteredBranch = false;
1324
- while (newOperations.length > 0) {
1325
- const newOperationCandidate = newOperations[0];
1326
- let nextTrunkOperation = trunkCopy.shift();
1327
- while (nextTrunkOperation && precedes(nextTrunkOperation, newOperationCandidate)) {
1328
- result.push(nextTrunkOperation);
1329
- nextTrunkOperation = trunkCopy.shift();
1330
- }
1331
- if (!nextTrunkOperation) {
1332
- enteredBranch = true;
1333
- } else if (!enteredBranch) {
1334
- if (operationsAreEqual(nextTrunkOperation, newOperationCandidate)) {
1335
- newOperations.shift();
1336
- result.push(nextTrunkOperation);
1337
- } else {
1338
- trunkCopy.unshift(nextTrunkOperation);
1339
- enteredBranch = true;
1340
- }
1341
- }
1342
- if (enteredBranch) {
1343
- let nextAppend = newOperations.shift();
1344
- while (nextAppend) {
1345
- result.push(nextAppend);
1346
- nextAppend = newOperations.shift();
1347
- }
1348
- }
1349
- }
1350
- if (!enteredBranch) {
1351
- let nextAppend = trunkCopy.shift();
1352
- while (nextAppend) {
1353
- result.push(nextAppend);
1354
- nextAppend = trunkCopy.shift();
1355
- }
1356
- }
1357
- return [garbageCollect(result), trunkCopy];
1358
- }
1359
- function precedes(op1, op2) {
1360
- return op1.index < op2.index || op1.index === op2.index && op1.id === op2.id && op1.skip < op2.skip;
1361
- }
1362
- function split(sortedTargetOperations, sortedMergeOperations) {
1363
- const commonOperations = [];
1364
- const targetDiffOperations = [];
1365
- const mergeDiffOperations = [];
1366
- const maxLength = Math.max(
1367
- sortedTargetOperations.length,
1368
- sortedMergeOperations.length
1369
- );
1370
- let splitHappened = false;
1371
- for (let i = 0; i < maxLength; i++) {
1372
- const targetOperation = sortedTargetOperations[i];
1373
- const mergeOperation = sortedMergeOperations[i];
1374
- if (targetOperation && mergeOperation) {
1375
- if (!splitHappened && operationsAreEqual(targetOperation, mergeOperation)) {
1376
- commonOperations.push(targetOperation);
1377
- } else {
1378
- splitHappened = true;
1379
- targetDiffOperations.push(targetOperation);
1380
- mergeDiffOperations.push(mergeOperation);
1381
- }
1382
- } else if (targetOperation) {
1383
- targetDiffOperations.push(targetOperation);
1384
- } else if (mergeOperation) {
1385
- mergeDiffOperations.push(mergeOperation);
1386
- }
1387
- }
1388
- return [commonOperations, targetDiffOperations, mergeDiffOperations];
1389
- }
1390
- function merge(sortedTargetOperations, sortedMergeOperations, reshuffle) {
1391
- const [_commonOperations, _targetOperations, _mergeOperations] = split(
1392
- garbageCollect(sortedTargetOperations),
1393
- garbageCollect(sortedMergeOperations)
1394
- );
1395
- const maxCommonIndex = getMaxIndex(_commonOperations);
1396
- const nextIndex = 1 + Math.max(
1397
- maxCommonIndex,
1398
- getMaxIndex(_targetOperations),
1399
- getMaxIndex(_mergeOperations)
1400
- );
1401
- const filteredMergeOperations = filterDuplicatedOperations(
1402
- _mergeOperations,
1403
- _targetOperations
1404
- );
1405
- const newOperationHistory = reshuffle(
1406
- {
1407
- index: nextIndex,
1408
- skip: nextIndex - (maxCommonIndex + 1)
1409
- },
1410
- _targetOperations,
1411
- filteredMergeOperations
1412
- );
1413
- return _commonOperations.concat(newOperationHistory);
1414
- }
1415
- function getMaxIndex(sortedOperations) {
1416
- const lastElement = sortedOperations[sortedOperations.length - 1];
1417
- if (!lastElement) {
1418
- return -1;
1419
- }
1420
- return lastElement.index;
1421
- }
1422
- function nextSkipNumber(sortedOperations) {
1423
- var _a, _b, _c;
1424
- if (sortedOperations.length < 1) {
1425
- return -1;
1426
- }
1427
- const cleanedOperations = garbageCollect(sortedOperations);
1428
- let nextSkip = (((_a = cleanedOperations[cleanedOperations.length - 1]) == null ? void 0 : _a.skip) || 0) + 1;
1429
- if (cleanedOperations.length > 1) {
1430
- nextSkip += ((_b = cleanedOperations[cleanedOperations.length - 2]) == null ? void 0 : _b.skip) || 0;
1431
- }
1432
- return (((_c = cleanedOperations[cleanedOperations.length - 1]) == null ? void 0 : _c.index) || -1) < nextSkip ? -1 : nextSkip;
1433
- }
1434
- const checkOperationsIntegrity = (operations) => {
1435
- return checkCleanedOperationsIntegrity(
1436
- garbageCollect(sortOperations$1(operations))
1437
- );
1438
- };
1439
- const groupOperationsByScope = (operations) => {
1440
- const result = operations.reduce((acc, operation) => {
1441
- var _a;
1442
- if (!acc[operation.scope]) {
1443
- acc[operation.scope] = [];
1444
- }
1445
- (_a = acc[operation.scope]) == null ? void 0 : _a.push(operation);
1446
- return acc;
1447
- }, {});
1448
- return result;
1449
- };
1450
- const prepareOperations = (operationsHistory, newOperations) => {
1451
- var _a;
1452
- const result = {
1453
- integrityIssues: [],
1454
- validOperations: [],
1455
- invalidOperations: [],
1456
- duplicatedOperations: []
1457
- };
1458
- const sortedOperationsHistory = sortOperations$1(operationsHistory);
1459
- const sortedOperations = sortOperations$1(newOperations);
1460
- const integrityErrors = checkCleanedOperationsIntegrity([
1461
- ...sortedOperationsHistory,
1462
- ...sortedOperations
1463
- ]);
1464
- const missingIndexErrors = integrityErrors.filter(
1465
- (integrityIssue) => integrityIssue.category === "MISSING_INDEX"
1466
- /* MISSING_INDEX */
1467
- );
1468
- const firstMissingIndexOperation = (_a = [...missingIndexErrors].sort((a, b) => b.operation.index - a.operation.index).pop()) == null ? void 0 : _a.operation;
1469
- for (const newOperation of sortedOperations) {
1470
- if (firstMissingIndexOperation && newOperation.index >= firstMissingIndexOperation.index) {
1471
- result.invalidOperations.push(newOperation);
1472
- continue;
1473
- }
1474
- const isDuplicatedOperation = integrityErrors.some((integrityError) => {
1475
- return integrityError.operation.index === newOperation.index && integrityError.operation.skip === newOperation.skip && integrityError.category === "DUPLICATED_INDEX";
1476
- });
1477
- if (isDuplicatedOperation) {
1478
- result.duplicatedOperations.push(newOperation);
1479
- continue;
1480
- }
1481
- result.validOperations.push(newOperation);
1482
- }
1483
- result.integrityIssues.push(...integrityErrors);
1484
- return result;
1485
- };
1486
- function removeExistingOperations(newOperations, operationsHistory) {
1487
- return newOperations.filter((newOperation) => {
1488
- return !operationsHistory.some((historyOperation) => {
1489
- return newOperation.type === "NOOP" && newOperation.skip === 0 && newOperation.index === historyOperation.index || newOperation.index === historyOperation.index && newOperation.skip === historyOperation.skip && newOperation.scope === historyOperation.scope && newOperation.hash === historyOperation.hash && newOperation.type === historyOperation.type;
1490
- });
1491
- });
1492
- }
1493
- function skipHeaderOperations(operations, skipHeaderOperation) {
1494
- const [lastOperation] = sortOperations$1(operations).slice(-1);
1495
- const lastIndex = (lastOperation == null ? void 0 : lastOperation.index) ?? -1;
1496
- const nextIndex = lastIndex + 1;
1497
- const skipOperationIndex = {
1498
- ...skipHeaderOperation,
1499
- index: skipHeaderOperation.index ?? nextIndex
1500
- };
1501
- if (skipOperationIndex.index < lastIndex) {
1502
- throw new Error(
1503
- `The skip header operation index must be greater than or equal to ${lastIndex}`
1504
- );
1505
- }
1506
- const clearedOperations = garbageCollect(
1507
- sortOperations$1([...operations, skipOperationIndex])
1508
- );
1509
- return (clearedOperations || []).slice(0, -1);
1510
- }
1511
- function garbageCollectDocumentOperations(documentOperations) {
1512
- const clearedOperations = Object.entries(documentOperations).reduce(
1513
- (acc, entry) => {
1514
- const [scope, ops] = entry;
1515
- return {
1516
- ...acc,
1517
- [scope]: garbageCollect(sortOperations$1(ops))
1518
- };
1519
- },
1520
- {}
1521
- );
1522
- return {
1523
- ...clearedOperations
1524
- };
1525
- }
1526
- function filterDuplicatedOperations(targetOperations, sourceOperations) {
1527
- return targetOperations.filter((op) => {
1528
- if (op.id) {
1529
- return !sourceOperations.some((targetOp) => targetOp.id === op.id);
1530
- }
1531
- return true;
1532
- });
1533
- }
1534
- function filterDocumentOperationsResultingState(documentOperations) {
1535
- if (!documentOperations) {
1536
- return {};
1537
- }
1538
- const entries = Object.entries(documentOperations);
1539
- return entries.reduce(
1540
- (acc, [scope, operations]) => ({
1541
- ...acc,
1542
- [scope]: operations.map((op) => {
1543
- const { resultingState, ...restProps } = op;
1544
- return restProps;
1545
- })
1546
- }),
1547
- {}
1548
- );
1549
- }
1550
- function diffOperations(clearedOperationsA, clearedOperationsB) {
1551
- return clearedOperationsA.filter(
1552
- (operationA) => !clearedOperationsB.some(
1553
- (operationB) => operationA.index === operationB.index
1554
- )
1555
- );
1556
- }
1557
- const documentHelpers = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1558
- __proto__: null,
1559
- IntegrityIssueSubType,
1560
- IntegrityIssueType,
1561
- addUndo,
1562
- attachBranch,
1563
- checkCleanedOperationsIntegrity,
1564
- checkOperationsIntegrity,
1565
- diffOperations,
1566
- filterDocumentOperationsResultingState,
1567
- filterDuplicatedOperations,
1568
- garbageCollect,
1569
- garbageCollectDocumentOperations,
1570
- groupOperationsByScope,
1571
- merge,
1572
- nextSkipNumber,
1573
- operationsAreEqual,
1574
- precedes,
1575
- prepareOperations,
1576
- removeExistingOperations,
1577
- reshuffleByTimestamp,
1578
- reshuffleByTimestampAndIndex,
1579
- skipHeaderOperations,
1580
- sortOperations: sortOperations$1,
1581
- split
1582
- }, Symbol.toStringTag, { value: "Module" }));
1583
- const createZip = async (document) => {
1584
- const zip = new JSZip();
1585
- const { name, revision, documentType, created, lastModified } = document;
1586
- const header = {
1587
- name,
1588
- revision,
1589
- documentType,
1590
- created,
1591
- lastModified
1592
- };
1593
- zip.file("header.json", JSON.stringify(header, null, 2));
1594
- zip.file("state.json", JSON.stringify(document.initialState || {}, null, 2));
1595
- zip.file(
1596
- "operations.json",
1597
- JSON.stringify(
1598
- filterDocumentOperationsResultingState(document.operations),
1599
- null,
1600
- 2
1601
- )
1602
- );
1603
- if (document.attachments) {
1604
- const attachments = Object.keys(document.attachments);
1605
- attachments.forEach((key) => {
1606
- const { data, ...attributes } = document.attachments[key];
1607
- zip.file(key, data, {
1608
- base64: true,
1609
- createFolders: true,
1610
- comment: JSON.stringify(attributes)
1611
- });
1612
- });
1613
- }
1614
- return zip;
1615
- };
1616
- const saveToFile = async (document, path, extension, name) => {
1617
- const zip = await createZip(document);
1618
- await zip.generateAsync({
1619
- type: "uint8array",
1620
- streamFiles: true
1621
- });
1622
- const fileName = name ?? document.name;
1623
- const fileExtension = `.${extension}.zip`;
1624
- return writeFile(
1625
- path,
1626
- fileName.endsWith(fileExtension) ? fileName : `${fileName}${fileExtension}`
1627
- );
1628
- };
1629
- const saveToFileHandle = async (document, input) => {
1630
- const zip = await createZip(document);
1631
- const blob = await zip.generateAsync({ type: "blob" });
1632
- const writable = await input.createWritable();
1633
- await writable.write(blob);
1634
- await writable.close();
1635
- };
1636
- const loadFromFile = async (path, reducer, options) => {
1637
- const file = readFile();
1638
- return loadFromInput(file, reducer, options);
1639
- };
1640
- const loadFromInput = async (input, reducer, options) => {
1641
- const zip = new JSZip();
1642
- await zip.loadAsync(input);
1643
- return loadFromZip(zip, reducer, options);
1644
- };
1645
- async function loadFromZip(zip, reducer, options) {
1646
- const initialStateZip = zip.file("state.json");
1647
- if (!initialStateZip) {
1648
- throw new Error("Initial state not found");
1649
- }
1650
- const initialStateStr = await initialStateZip.async("string");
1651
- const initialState = JSON.parse(initialStateStr);
1652
- const headerZip = zip.file("header.json");
1653
- let header = void 0;
1654
- if (headerZip) {
1655
- header = JSON.parse(await headerZip.async("string"));
1656
- }
1657
- const operationsZip = zip.file("operations.json");
1658
- if (!operationsZip) {
1659
- throw new Error("Operations history not found");
1660
- }
1661
- const operations = JSON.parse(
1662
- await operationsZip.async("string")
1663
- );
1664
- const clearedOperations = garbageCollectDocumentOperations(operations);
1665
- const operationsError = validateOperations(clearedOperations);
1666
- if (operationsError.length) {
1667
- const errorMessages = operationsError.map((err) => err.message);
1668
- throw new Error(errorMessages.join("\n"));
1669
- }
1670
- let result = replayDocument(
1671
- initialState,
1672
- clearedOperations,
1673
- reducer,
1674
- void 0,
1675
- header,
1676
- {},
1677
- options
1678
- );
1679
- if (header) {
1680
- result = {
1681
- ...result,
1682
- ...header
1683
- };
1684
- }
1685
- return result;
1686
- }
1687
- function getFileAttributes(file) {
1688
- const extension = file.replace(/^.*\./, "") || void 0;
1689
- const fileName = file.replace(/^.*[/\\]/, "") || void 0;
1690
- return { extension, fileName };
1691
- }
1692
- async function getRemoteFile(url) {
1693
- const { buffer, mimeType = "application/octet-stream" } = await fetchFile();
1694
- const attributes = getFileAttributes(url);
1695
- const data = buffer.toString("base64");
1696
- return {
1697
- data,
1698
- hash: hash(data),
1699
- mimeType,
1700
- ...attributes
1701
- };
1702
- }
1703
- async function getLocalFile(path) {
1704
- const buffer = await getFile();
1705
- const mimeType = mime.getType(path) || "application/octet-stream";
1706
- const attributes = getFileAttributes(path);
1707
- const data = buffer.toString("base64");
1708
- return { data, hash: hash(data), mimeType, ...attributes };
1709
- }
1710
- function setNameOperation(document, name) {
1711
- return { ...document, name };
1712
- }
1713
- function undoOperation(document, action, skip) {
1714
- const { scope, input } = action;
1715
- const defaultResult = {
1716
- document,
1717
- action,
1718
- skip,
1719
- reuseLastOperationIndex: false
1720
- };
1721
- return mutative.create(defaultResult, (draft) => {
1722
- const operations = [...document.operations[scope]];
1723
- const sortedOperations = sortOperations$1(operations);
1724
- draft.action = noop(scope);
1725
- const lastOperation = sortedOperations.at(-1);
1726
- let nextIndex = (lastOperation == null ? void 0 : lastOperation.index) ?? -1;
1727
- const isNewNoop = (lastOperation == null ? void 0 : lastOperation.type) !== "NOOP";
1728
- if (isNewNoop) {
1729
- nextIndex = nextIndex + 1;
1730
- } else {
1731
- draft.reuseLastOperationIndex = true;
1732
- }
1733
- const nextOperationHistory = isNewNoop ? [...sortedOperations, { index: nextIndex, skip: 0 }] : sortedOperations;
1734
- draft.skip = nextSkipNumber(nextOperationHistory);
1735
- if (lastOperation && draft.skip > lastOperation.skip + 1) {
1736
- draft.skip = draft.skip + 1;
1737
- }
1738
- if (draft.skip < 0) {
1739
- throw new Error(
1740
- `Cannot undo: you can't undo more operations than the ones in the scope history`
1741
- );
1742
- }
1743
- });
1744
- }
1745
- function redoOperation(document, action, skip) {
1746
- const { scope, input } = action;
1747
- const defaultResult = {
1748
- document,
1749
- action,
1750
- skip,
1751
- reuseLastOperationIndex: false
1752
- };
1753
- return mutative.create(defaultResult, (draft) => {
1754
- if (draft.skip > 0) {
1755
- throw new Error(
1756
- `Cannot redo: skip value from reducer cannot be used with REDO action`
1757
- );
1758
- }
1759
- if (input > 1) {
1760
- throw new Error(`Cannot redo: you can only redo one operation at a time`);
1761
- }
1762
- if (input < 1) {
1763
- throw new Error(`Invalid REDO action: invalid redo input value`);
1764
- }
1765
- if (draft.document.clipboard.length < 1) {
1766
- throw new Error(`Cannot redo: no operations in the clipboard`);
1767
- }
1768
- const operationIndex = draft.document.clipboard.findLastIndex(
1769
- (op) => op.scope === scope
1770
- );
1771
- if (operationIndex < 0) {
1772
- throw new Error(
1773
- `Cannot redo: no operations in clipboard for scope "${scope}"`
1774
- );
1775
- }
1776
- const operation = draft.document.clipboard.splice(operationIndex, 1)[0];
1777
- draft.action = mutative.castDraft({
1778
- type: operation.type,
1779
- scope: operation.scope,
1780
- input: operation.input
1781
- });
1782
- });
1783
- }
1784
- function pruneOperation(document, action, wrappedReducer) {
1785
- const { scope } = action;
1786
- const operations = document.operations[scope];
1787
- let {
1788
- input: { start, end }
1789
- } = action;
1790
- start = start || 0;
1791
- end = end || operations.length;
1792
- const actionsToPrune = operations.slice(start, end);
1793
- const actionsToKeepStart = operations.slice(0, start);
1794
- const actionsToKeepEnd = operations.slice(end);
1795
- const newDocument = replayOperations(
1796
- document.initialState,
1797
- {
1798
- ...document.operations,
1799
- [scope]: actionsToKeepStart.concat(actionsToPrune)
1800
- },
1801
- wrappedReducer
1802
- );
1803
- const { name, state: newState } = newDocument;
1804
- const loadStateIndex = actionsToKeepStart.length;
1805
- const loadStateTimestamp = actionsToKeepStart.length ? actionsToKeepStart[actionsToKeepStart.length - 1].timestamp : actionsToKeepEnd.length ? actionsToKeepEnd[0].timestamp : (/* @__PURE__ */ new Date()).toISOString();
1806
- return replayOperations(
1807
- document.initialState,
1808
- {
1809
- ...document.operations,
1810
- [scope]: [
1811
- ...actionsToKeepStart,
1812
- {
1813
- ...loadState({ name, state: newState }, actionsToPrune.length),
1814
- timestamp: loadStateTimestamp,
1815
- index: loadStateIndex,
1816
- hash: hashDocument({ state: newState }, "global")
1817
- },
1818
- ...actionsToKeepEnd.map((action2, index) => ({
1819
- ...action2,
1820
- index: loadStateIndex + index + 1
1821
- }))
1822
- ]
1823
- },
1824
- wrappedReducer
1825
- );
1826
- }
1827
- function loadStateOperation(oldDocument, newDocument) {
1828
- return {
1829
- ...oldDocument,
1830
- name: newDocument.name,
1831
- state: newDocument.state ?? { global: {}, local: {} }
1832
- };
1833
- }
1834
- const SET_NAME = "SET_NAME";
1835
- const UNDO = "UNDO";
1836
- const REDO = "REDO";
1837
- const PRUNE = "PRUNE";
1838
- const LOAD_STATE = "LOAD_STATE";
1839
- const NOOP = "NOOP";
1840
- function getNextRevision(document, action) {
1841
- let latestOperation;
1842
- if ("index" in action) {
1843
- latestOperation = { ...action };
1844
- } else {
1845
- latestOperation = document.operations[action.scope].at(-1);
1846
- }
1847
- return ((latestOperation == null ? void 0 : latestOperation.index) ?? -1) + 1;
1848
- }
1849
- function updateHeader(document, action) {
1850
- return {
1851
- ...document,
1852
- revision: {
1853
- ...document.revision,
1854
- [action.scope]: getNextRevision(document, action)
1855
- },
1856
- lastModified: (/* @__PURE__ */ new Date()).toISOString()
1857
- };
1858
- }
1859
- function updateOperations(document, action, skip = 0, reuseLastOperationIndex = false) {
1860
- if ([UNDO, REDO, PRUNE].includes(action.type)) {
1861
- return document;
1862
- }
1863
- const { scope } = action;
1864
- const operations = document.operations[scope].slice();
1865
- let operationId;
1866
- const latestOperation = operations.at(-1);
1867
- const lastOperationIndex = (latestOperation == null ? void 0 : latestOperation.index) ?? -1;
1868
- let nextIndex = reuseLastOperationIndex ? lastOperationIndex : lastOperationIndex + 1;
1869
- if ("index" in action) {
1870
- if (action.index - skip > nextIndex) {
1871
- throw new Error(
1872
- `Missing operations: expected ${nextIndex} with skip 0 or equivalent, got index ${action.index} with skip ${skip}`
1873
- );
1874
- }
1875
- nextIndex = action.index;
1876
- operationId = action.id;
1877
- } else {
1878
- operationId = "id" in action ? action.id : v4();
1879
- }
1880
- operations.push({
1881
- ...action,
1882
- id: operationId,
1883
- index: nextIndex,
1884
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1885
- hash: "",
1886
- scope,
1887
- skip,
1888
- error: void 0
1889
- });
1890
- return {
1891
- ...document,
1892
- operations: { ...document.operations, [scope]: operations }
1893
- };
1894
- }
1895
- function updateDocument(document, action, skip = 0, reuseLastOperationIndex = false) {
1896
- let newDocument = updateOperations(
1897
- document,
1898
- action,
1899
- skip,
1900
- reuseLastOperationIndex
1901
- );
1902
- newDocument = updateHeader(newDocument, action);
1903
- return newDocument;
1904
- }
1905
- function _baseReducer(document, action, wrappedReducer) {
1906
- BaseActionSchema().parse(action);
1907
- switch (action.type) {
1908
- case SET_NAME:
1909
- return setNameOperation(document, action.input);
1910
- case PRUNE:
1911
- return pruneOperation(document, action, wrappedReducer);
1912
- case LOAD_STATE:
1913
- return loadStateOperation(document, action.input.state);
1914
- default:
1915
- return document;
1916
- }
1917
- }
1918
- function processUndoRedo(document, action, skip) {
1919
- switch (action.type) {
1920
- case UNDO:
1921
- return undoOperation(document, action, skip);
1922
- case REDO:
1923
- return redoOperation(document, action, skip);
1924
- default:
1925
- return { document, action, skip, reuseLastOperationIndex: false };
1926
- }
1927
- }
1928
- function processSkipOperation(document, action, customReducer, skipValue, reuseOperationResultingState = false, resultingStateParser = parseResultingState) {
1929
- const scope = action.scope;
1930
- const latestOperation = document.operations[scope].at(-1);
1931
- if (!latestOperation) return document;
1932
- const documentOperations = garbageCollectDocumentOperations({
1933
- ...document.operations,
1934
- [scope]: skipHeaderOperations(
1935
- document.operations[scope],
1936
- latestOperation
1937
- )
1938
- });
1939
- let scopeState = void 0;
1940
- const lastRemainingOperation = documentOperations[scope].at(-1);
1941
- if (reuseOperationResultingState && (lastRemainingOperation == null ? void 0 : lastRemainingOperation.resultingState)) {
1942
- scopeState = resultingStateParser(lastRemainingOperation.resultingState);
1943
- } else {
1944
- const { state } = replayOperations(
1945
- document.initialState,
1946
- documentOperations,
1947
- customReducer,
1948
- void 0,
1949
- void 0,
1950
- void 0,
1951
- void 0,
1952
- {
1953
- reuseHash: true,
1954
- reuseOperationResultingState,
1955
- operationResultingStateParser: resultingStateParser
1956
- }
1957
- );
1958
- scopeState = state[scope];
1959
- }
1960
- return {
1961
- ...document,
1962
- state: {
1963
- ...document.state,
1964
- [scope]: scopeState
1965
- },
1966
- operations: garbageCollectDocumentOperations({
1967
- ...document.operations
1968
- })
1969
- };
1970
- }
1971
- function processUndoOperation(document, scope, customReducer, reuseOperationResultingState = false, resultingStateParser = parseResultingState) {
1972
- const operations = [...document.operations[scope]];
1973
- const sortedOperations = sortOperations$1(operations);
1974
- sortedOperations.pop();
1975
- const documentOperations = garbageCollectDocumentOperations({
1976
- ...document.operations
1977
- });
1978
- const clearedOperations = [...documentOperations[scope]];
1979
- const diff = diffOperations(
1980
- garbageCollect(sortedOperations),
1981
- clearedOperations
1982
- );
1983
- const doc = replayOperations(
1984
- document.initialState,
1985
- documentOperations,
1986
- customReducer,
1987
- void 0,
1988
- void 0,
1989
- void 0,
1990
- void 0,
1991
- {
1992
- reuseHash: true,
1993
- reuseOperationResultingState,
1994
- operationResultingStateParser: resultingStateParser
1995
- }
1996
- );
1997
- const clipboard = sortOperations$1(
1998
- [...document.clipboard, ...diff].filter((op) => op.type !== "NOOP")
1999
- ).reverse();
2000
- return { ...doc, clipboard };
2001
- }
2002
- function baseReducer(document, action, customReducer, dispatch, options = {}) {
2003
- const {
2004
- skip,
2005
- ignoreSkipOperations = false,
2006
- reuseHash = false,
2007
- reuseOperationResultingState = false,
2008
- operationResultingStateParser
2009
- } = options;
2010
- let _action = { ...action };
2011
- let skipValue = skip || 0;
2012
- let newDocument = { ...document };
2013
- let reuseLastOperationIndex = false;
2014
- const shouldProcessSkipOperation = !ignoreSkipOperations && (skipValue > 0 || "index" in _action && _action.skip > 0);
2015
- if (isUndoRedo(_action)) {
2016
- const {
2017
- skip: calculatedSkip,
2018
- action: transformedAction,
2019
- document: processedDocument,
2020
- reuseLastOperationIndex: reuseIndex
2021
- } = processUndoRedo(document, _action, skipValue);
2022
- _action = transformedAction;
2023
- skipValue = calculatedSkip;
2024
- newDocument = processedDocument;
2025
- reuseLastOperationIndex = reuseIndex;
2026
- } else {
2027
- newDocument = {
2028
- ...newDocument,
2029
- clipboard: []
2030
- };
2031
- }
2032
- if (isBaseAction(_action)) {
2033
- newDocument = _baseReducer(newDocument, _action, customReducer);
2034
- }
2035
- newDocument = updateDocument(
2036
- newDocument,
2037
- _action,
2038
- skipValue,
2039
- reuseLastOperationIndex
2040
- );
2041
- const isUndoAction = isUndo(action);
2042
- if (isUndoAction) {
2043
- const result = processUndoOperation(
2044
- newDocument,
2045
- action.scope,
2046
- customReducer
2047
- );
2048
- return result;
2049
- }
2050
- if (shouldProcessSkipOperation) {
2051
- newDocument = processSkipOperation(
2052
- newDocument,
2053
- _action,
2054
- customReducer,
2055
- skipValue,
2056
- reuseOperationResultingState,
2057
- operationResultingStateParser
2058
- );
2059
- }
2060
- newDocument = mutative.create(newDocument, (draft) => {
2061
- try {
2062
- const newState = customReducer(draft.state, _action, dispatch);
2063
- if (newState) {
2064
- mutative.unsafe(() => {
2065
- draft.state = mutative.castDraft(newState);
2066
- });
2067
- } else {
2068
- }
2069
- } catch (error) {
2070
- const lastOperationIndex = newDocument.operations[_action.scope].length - 1;
2071
- draft.operations[_action.scope][lastOperationIndex].error = error.message;
2072
- draft.operations[_action.scope][lastOperationIndex].skip = 0;
2073
- if (shouldProcessSkipOperation) {
2074
- draft.state = mutative.castDraft({ ...document.state });
2075
- draft.operations = mutative.castDraft({
2076
- ...document.operations,
2077
- [_action.scope]: [
2078
- ...document.operations[_action.scope],
2079
- {
2080
- ...draft.operations[_action.scope][lastOperationIndex]
2081
- }
2082
- ]
2083
- });
2084
- }
2085
- }
2086
- });
2087
- if ([UNDO, REDO, PRUNE].includes(_action.type)) {
2088
- return newDocument;
2089
- }
2090
- const scope = _action.scope || "global";
2091
- const hash2 = reuseHash && Object.prototype.hasOwnProperty.call(_action, "hash") ? _action.hash : hashDocument(newDocument, scope);
2092
- const lastOperation = newDocument.operations[scope].at(-1);
2093
- if (lastOperation) {
2094
- lastOperation.hash = hash2;
2095
- if (reuseOperationResultingState) {
2096
- lastOperation.resultingState = newDocument.state[scope];
2097
- }
2098
- if (!isBaseAction(_action) && _action.attachments) {
2099
- _action.attachments.forEach((attachment) => {
2100
- const { hash: hash22, ...file } = attachment;
2101
- newDocument.attachments[hash22] = {
2102
- ...file
2103
- };
2104
- });
2105
- }
2106
- }
2107
- return newDocument;
2108
- }
2109
- function mutableBaseReducer(document, action, customReducer, dispatch, options = {}) {
2110
- const {
2111
- skip,
2112
- ignoreSkipOperations = false,
2113
- reuseHash = false,
2114
- reuseOperationResultingState = false,
2115
- operationResultingStateParser
2116
- } = options;
2117
- const _action = { ...action };
2118
- const skipValue = skip || 0;
2119
- let newDocument = { ...document };
2120
- const shouldProcessSkipOperation = !ignoreSkipOperations && (skipValue > 0 || "index" in _action && _action.skip > 0);
2121
- if (isBaseAction(_action)) {
2122
- newDocument = _baseReducer(newDocument, _action, customReducer);
2123
- }
2124
- newDocument = updateDocument(newDocument, _action, skipValue);
2125
- if (shouldProcessSkipOperation) {
2126
- newDocument = processSkipOperation(
2127
- newDocument,
2128
- _action,
2129
- customReducer,
2130
- skipValue,
2131
- reuseOperationResultingState,
2132
- operationResultingStateParser
2133
- );
2134
- }
2135
- try {
2136
- const newState = customReducer(
2137
- newDocument.state,
2138
- _action,
2139
- dispatch
2140
- );
2141
- if (newState) {
2142
- newDocument.state = newState;
2143
- }
2144
- } catch (error) {
2145
- const lastOperationIndex = newDocument.operations[_action.scope].length - 1;
2146
- newDocument.operations[_action.scope][lastOperationIndex].error = error.message;
2147
- newDocument.operations[_action.scope][lastOperationIndex].skip = 0;
2148
- if (shouldProcessSkipOperation) {
2149
- newDocument.state = { ...document.state };
2150
- newDocument.operations = {
2151
- ...document.operations,
2152
- [_action.scope]: [
2153
- ...document.operations[_action.scope],
2154
- {
2155
- ...newDocument.operations[_action.scope][lastOperationIndex]
2156
- }
2157
- ]
2158
- };
2159
- }
2160
- }
2161
- if ([UNDO, REDO, PRUNE].includes(_action.type)) {
2162
- return newDocument;
2163
- }
2164
- const scope = _action.scope || "global";
2165
- const hash2 = reuseHash && Object.prototype.hasOwnProperty.call(_action, "hash") ? _action.hash : hashDocument(newDocument, scope);
2166
- const lastOperation = newDocument.operations[scope].at(-1);
2167
- if (lastOperation) {
2168
- lastOperation.hash = hash2;
2169
- if (reuseOperationResultingState) {
2170
- lastOperation.resultingState = newDocument.state[scope];
2171
- }
2172
- if (!isBaseAction(_action) && _action.attachments) {
2173
- _action.attachments.forEach((attachment) => {
2174
- const { hash: hash22, ...file } = attachment;
2175
- newDocument.attachments[hash22] = {
2176
- ...file
2177
- };
2178
- });
2179
- }
2180
- }
2181
- return newDocument;
2182
- }
2183
- function isNoopOperation(op) {
2184
- return op.type === NOOP && op.skip !== void 0 && op.skip > 0 && op.hash !== void 0;
2185
- }
2186
- function isUndoRedo(action) {
2187
- return [UNDO, REDO].includes(action.type);
2188
- }
2189
- function isUndo(action) {
2190
- return action.type === UNDO;
2191
- }
2192
- function isBaseAction(action) {
2193
- return [SET_NAME, UNDO, REDO, PRUNE, LOAD_STATE].includes(action.type);
2194
- }
2195
- function createAction(type, input, attachments, validator, scope = "global") {
2196
- if (!type) {
2197
- throw new Error("Empty action type");
2198
- }
2199
- if (typeof type !== "string") {
2200
- throw new Error(`Invalid action type: ${JSON.stringify(type)}`);
2201
- }
2202
- const action = { type, input, scope };
2203
- if (attachments) {
2204
- action.attachments = attachments;
2205
- }
2206
- try {
2207
- validator == null ? void 0 : validator().parse(action.input);
2208
- } catch (error) {
2209
- throw new Error(`Invalid action input: ${error}`);
2210
- }
2211
- return action;
2212
- }
2213
- function createReducer(reducer, documentReducer = baseReducer) {
2214
- return (document, action, dispatch, options) => {
2215
- return documentReducer(document, action, reducer, dispatch, options);
2216
- };
2217
- }
2218
- function createUnsafeReducer(reducer, documentReducer = mutableBaseReducer) {
2219
- return (document, action, dispatch, options) => {
2220
- return documentReducer(document, action, reducer, dispatch, options);
2221
- };
2222
- }
2223
- const createExtendedState = (initialState, createState) => {
2224
- return {
2225
- name: "",
2226
- documentType: "",
2227
- revision: {
2228
- global: 0,
2229
- local: 0
2230
- },
2231
- created: (/* @__PURE__ */ new Date()).toISOString(),
2232
- lastModified: (/* @__PURE__ */ new Date()).toISOString(),
2233
- attachments: {},
2234
- ...initialState,
2235
- state: (createState == null ? void 0 : createState(initialState == null ? void 0 : initialState.state)) ?? ((initialState == null ? void 0 : initialState.state) ?? { global: {}, local: {} })
2236
- };
2237
- };
2238
- const createDocument = (initialState, createState) => {
2239
- const state = createExtendedState(
2240
- initialState,
2241
- createState
2242
- );
2243
- return {
2244
- ...state,
2245
- initialState: state,
2246
- operations: { global: [], local: [] },
2247
- clipboard: []
2248
- };
2249
- };
2250
- const hashDocument = (document, scope = "global") => {
2251
- return hash(cjsModule(document.state[scope] || ""));
2252
- };
2253
- const hashKey = (date, randomLimit = 1e3) => {
2254
- const random = Math.random() * randomLimit;
2255
- return hash(`${(date ?? /* @__PURE__ */ new Date()).toISOString()}${random}`);
2256
- };
2257
- function readOnly(value) {
2258
- return Object.freeze(value);
2259
- }
2260
- function mapSkippedOperations(operations, skippedHeadOperations) {
2261
- const ops = [...operations];
2262
- let skipped = skippedHeadOperations || 0;
2263
- let latestOpIndex = ops.length > 0 ? ops[ops.length - 1].index : 0;
2264
- const scopeOpsWithIgnore = [];
2265
- for (const operation of ops.reverse()) {
2266
- if (skipped > 0) {
2267
- const operationsDiff = latestOpIndex - operation.index;
2268
- skipped -= operationsDiff;
2269
- }
2270
- if (skipped < 0) {
2271
- throw new Error("Invalid operation index, missing operations");
2272
- }
2273
- const mappedOp = {
2274
- ignore: skipped > 0,
2275
- operation
2276
- };
2277
- const operationSkip = operation.skip > 0 ? operation.skip + 1 : 0;
2278
- if (operationSkip > 0 && operationSkip > skipped) {
2279
- const skipDiff = operationSkip - skipped;
2280
- skipped = skipped + skipDiff;
2281
- }
2282
- latestOpIndex = operation.index;
2283
- scopeOpsWithIgnore.push(mappedOp);
2284
- }
2285
- return scopeOpsWithIgnore.reverse();
2286
- }
2287
- function sortOperations(operations) {
2288
- return Object.values(operations).flatMap((array) => array).sort(
2289
- (a, b) => new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime()
2290
- );
2291
- }
2292
- function sortMappedOperations(operations) {
2293
- return Object.values(operations).flatMap((array) => array).sort(
2294
- (a, b) => new Date(a.operation.timestamp).getTime() - new Date(b.operation.timestamp).getTime()
2295
- );
2296
- }
2297
- function replayOperations(initialState, clearedOperations, reducer, dispatch, header, documentReducer = baseReducer, skipHeaderOperations2 = {}, options) {
2298
- const wrappedReducer = createReducer(reducer, documentReducer);
2299
- return replayDocument(
2300
- initialState,
2301
- clearedOperations,
2302
- wrappedReducer,
2303
- dispatch,
2304
- header,
2305
- skipHeaderOperations2,
2306
- options
2307
- );
2308
- }
2309
- function replayDocument(initialState, operations, reducer, dispatch, header, skipHeaderOperations2 = {}, options) {
2310
- const {
2311
- checkHashes = true,
2312
- reuseOperationResultingState,
2313
- operationResultingStateParser = parseResultingState
2314
- } = options || {};
2315
- let documentState = initialState;
2316
- const operationsToReplay = [];
2317
- const initialOperations = {
2318
- global: [],
2319
- local: []
2320
- };
2321
- if (reuseOperationResultingState) {
2322
- for (const [scope, scopeOperations] of Object.entries(operations)) {
2323
- const index = scopeOperations.findLastIndex((s) => !!s.resultingState);
2324
- if (index < 0) {
2325
- operationsToReplay.push(...scopeOperations);
2326
- continue;
2327
- }
2328
- const opWithState = scopeOperations[index];
2329
- try {
2330
- const scopeState = operationResultingStateParser(
2331
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-unnecessary-type-assertion
2332
- opWithState.resultingState
2333
- );
2334
- documentState = {
2335
- ...documentState,
2336
- state: {
2337
- ...documentState.state,
2338
- // TODO how to deal with attachments?
2339
- [scope]: scopeState
2340
- }
2341
- };
2342
- initialOperations[scope].push(
2343
- ...scopeOperations.slice(0, index + 1)
2344
- );
2345
- operationsToReplay.push(...scopeOperations.slice(index + 1));
2346
- } catch {
2347
- operationsToReplay.push(...scopeOperations);
2348
- }
2349
- }
2350
- } else {
2351
- operationsToReplay.push(...Object.values(operations).flat());
2352
- }
2353
- const document = createDocument(documentState);
2354
- document.initialState = initialState;
2355
- document.operations = initialOperations;
2356
- let result = document;
2357
- if (operationsToReplay.length) {
2358
- result = operationsToReplay.reduce((document2, operation) => {
2359
- const doc = reducer(document2, operation, dispatch, {
2360
- skip: operation.skip,
2361
- ignoreSkipOperations: true,
2362
- reuseHash: !checkHashes
2363
- });
2364
- return doc;
2365
- }, document);
2366
- } else {
2367
- for (const scopeOperations of Object.values(initialOperations)) {
2368
- const lastOperation = scopeOperations.at(-1);
2369
- if (lastOperation) {
2370
- result = updateHeader(result, lastOperation);
2371
- }
2372
- }
2373
- }
2374
- if (!checkHashes) {
2375
- for (const scope of Object.keys(result.state)) {
2376
- for (let i = operationsToReplay.length - 1; i >= 0; i--) {
2377
- const operation = operationsToReplay[i];
2378
- if (operation.scope !== scope) {
2379
- continue;
2380
- }
2381
- if (operation.hash !== hashDocument(result, scope)) {
2382
- throw new Error(`Hash mismatch for scope ${scope}`);
2383
- } else {
2384
- break;
2385
- }
2386
- }
2387
- }
2388
- }
2389
- const resultOperations = Object.keys(
2390
- result.operations
2391
- ).reduce(
2392
- (acc, key) => {
2393
- const scope = key;
2394
- return {
2395
- ...acc,
2396
- [scope]: [
2397
- ...result.operations[scope].map((operation, index) => {
2398
- var _a;
2399
- return {
2400
- ...operation,
2401
- timestamp: ((_a = operations[scope][index]) == null ? void 0 : _a.timestamp) ?? operation.timestamp
2402
- };
2403
- })
2404
- ]
2405
- };
2406
- },
2407
- { global: [], local: [] }
2408
- );
2409
- const lastModified = Object.values(resultOperations).reduce((acc, curr) => {
2410
- const operation = curr.at(-1);
2411
- if (operation && operation.timestamp > acc) {
2412
- acc = operation.timestamp;
2413
- }
2414
- return acc;
2415
- }, initialState.lastModified);
2416
- return { ...result, operations: resultOperations, lastModified };
2417
- }
2418
- function isSameDocument(documentA, documentB) {
2419
- return cjsModule(documentA) === cjsModule(documentB);
2420
- }
2421
- function parseResultingState(state) {
2422
- const stateType = typeof state;
2423
- if (stateType === "string") {
2424
- return JSON.parse(state);
2425
- } else if (stateType === "object") {
2426
- return state;
2427
- } else {
2428
- throw new Error(`Providing resulting state is of type: ${stateType}`);
2429
- }
2430
- }
2431
- const setName = (name) => createAction(
2432
- "SET_NAME",
2433
- name,
2434
- void 0,
2435
- SetNameActionInputSchema,
2436
- void 0
2437
- );
2438
- const undo = (skip = 1, scope = "global") => createAction(
2439
- "UNDO",
2440
- skip,
2441
- void 0,
2442
- UndoActionInputSchema,
2443
- scope
2444
- );
2445
- const redo = (count = 1, scope = "global") => createAction(
2446
- "REDO",
2447
- count,
2448
- void 0,
2449
- RedoActionInputSchema,
2450
- scope
2451
- );
2452
- const prune = (start, end, scope = "global") => createAction(
2453
- "PRUNE",
2454
- { start, end },
2455
- void 0,
2456
- PruneActionInputSchema,
2457
- scope
2458
- );
2459
- const loadState = (state, operations) => createAction(
2460
- "LOAD_STATE",
2461
- { state, operations },
2462
- void 0,
2463
- LoadStateActionInputSchema
2464
- );
2465
- const noop = (scope = "global") => createAction("NOOP", {}, void 0, void 0, scope);
2466
- const BaseActions = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
2467
- __proto__: null,
2468
- loadState,
2469
- noop,
2470
- prune,
2471
- redo,
2472
- setName,
2473
- undo
2474
- }, Symbol.toStringTag, { value: "Module" }));
2475
- class BaseDocument {
2476
- /**
2477
- * Constructs a BaseDocument instance with an initial state.
2478
- * @param reducer - The reducer function that updates the state.
2479
- * @param document - The initial state of the document.
2480
- */
2481
- constructor(reducer, document, signalDispatch) {
2482
- __publicField(this, "_document");
2483
- __publicField(this, "_reducer");
2484
- __publicField(this, "_signalDispatch");
2485
- this._reducer = reducer;
2486
- this._document = document;
2487
- this._signalDispatch = signalDispatch;
2488
- }
2489
- /**
2490
- * Dispatches an action to update the state of the document.
2491
- * @param action - The action to dispatch.
2492
- * @returns The Document instance.
2493
- */
2494
- dispatch(action, options) {
2495
- this._document = this._reducer(
2496
- this._document,
2497
- action,
2498
- this._signalDispatch,
2499
- options
2500
- );
2501
- return this;
2502
- }
2503
- /**
2504
- * Saves the state of the document to a file.
2505
- * @param path - The file path where the state should be saved.
2506
- * @param extension - The file extension to use when saving the state.
2507
- * @returns The file path where the state was saved.
2508
- */
2509
- saveToFile(path, extension, name) {
2510
- return saveToFile(this._document, path, extension, name);
2511
- }
2512
- /**
2513
- * Loads the state of the document from a file.
2514
- * @param path - The file path where the state is stored.
2515
- */
2516
- async loadFromFile(path) {
2517
- this._document = await loadFromFile(path, this._reducer);
2518
- }
2519
- /**
2520
- * Loads the state of the document from a file and returns it.
2521
- * @param path - The file path where the state is stored.
2522
- * @param reducer - The reducer function that updates the state.
2523
- * @returns The state of the document.
2524
- */
2525
- static async stateFromFile(path, reducer) {
2526
- const state = await loadFromFile(path, reducer);
2527
- return state;
2528
- }
2529
- /**
2530
- * Gets the current state of the document.
2531
- */
2532
- get state() {
2533
- return readOnly(this._document.state);
2534
- }
2535
- /**
2536
- * Gets the list of operations performed on the document.
2537
- */
2538
- get operations() {
2539
- return readOnly(this._document.operations);
2540
- }
2541
- /**
2542
- * Gets the name of the document.
2543
- */
2544
- get name() {
2545
- return this._document.name;
2546
- }
2547
- /**
2548
- * Gets the type of document.
2549
- */
2550
- get documentType() {
2551
- return this._document.documentType;
2552
- }
2553
- /**
2554
- * Gets the timestamp of the date the document was created.
2555
- */
2556
- get created() {
2557
- return this._document.created;
2558
- }
2559
- /**
2560
- * Gets the timestamp of the date the document was last modified.
2561
- */
2562
- get lastModified() {
2563
- return this._document.lastModified;
2564
- }
2565
- /**
2566
- * Gets the global revision number of the document.
2567
- */
2568
- get revision() {
2569
- return this._document.revision.global;
2570
- }
2571
- getRevision(scope) {
2572
- return this._document.revision[scope];
2573
- }
2574
- /**
2575
- * Gets the initial state of the document.
2576
- */
2577
- get initialState() {
2578
- return readOnly(this._document.initialState);
2579
- }
2580
- /**
2581
- * Returns the current document as an object
2582
- */
2583
- toDocument() {
2584
- return readOnly(this._document);
2585
- }
2586
- /**
2587
- * Gets the attachment associated with the given key.
2588
- * @param attachment - The key of the attachment to retrieve.
2589
- */
2590
- getAttachment(attachment) {
2591
- return this._document.attachments[attachment];
2592
- }
2593
- /**
2594
- * Sets the name of the document.
2595
- * @param name - The new name of the document.
2596
- */
2597
- setName(name) {
2598
- this.dispatch(setName(name));
2599
- return this;
2600
- }
2601
- /**
2602
- * Reverts a number of actions from the document.
2603
- * @param count - The number of actions to revert.
2604
- */
2605
- undo(count) {
2606
- this.dispatch(undo(count));
2607
- return this;
2608
- }
2609
- /**
2610
- * Reapplies a number of actions to the document.
2611
- * @param count - The number of actions to reapply.
2612
- */
2613
- redo(count) {
2614
- this.dispatch(redo(count));
2615
- return this;
2616
- }
2617
- /**
2618
- * Removes a range of operations from the document.
2619
- * @param start - The starting index of the range to remove.
2620
- * @param end - The ending index of the range to remove.
2621
- */
2622
- prune(start, end) {
2623
- this.dispatch(prune(start, end));
2624
- return this;
2625
- }
2626
- /**
2627
- * Loads a document state and a set of operations.
2628
- * @param state - The state to load.
2629
- * @param operations - The operations to apply to the document.
2630
- */
2631
- loadState(state, operations) {
2632
- this.dispatch(loadState(state, operations));
2633
- return this;
2634
- }
2635
- }
2636
- function applyMixins(derivedCtor, constructors) {
2637
- constructors.forEach((baseCtor) => {
2638
- Object.getOwnPropertyNames(baseCtor.prototype).forEach((name) => {
2639
- Object.defineProperty(
2640
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
2641
- derivedCtor.prototype,
2642
- name,
2643
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
2644
- Object.getOwnPropertyDescriptor(baseCtor.prototype, name) || /* @__PURE__ */ Object.create(null)
2645
- );
2646
- });
2647
- });
2648
- }
2649
- exports.BaseActions = BaseActions;
2650
- exports.BaseDocument = BaseDocument;
2651
- exports.ab2hex = ab2hex;
2652
- exports.applyMixins = applyMixins;
2653
- exports.baseReducer = baseReducer;
2654
- exports.buildOperationSignature = buildOperationSignature;
2655
- exports.buildOperationSignatureMessage = buildOperationSignatureMessage;
2656
- exports.buildOperationSignatureParams = buildOperationSignatureParams;
2657
- exports.buildSignedOperation = buildSignedOperation;
2658
- exports.createAction = createAction;
2659
- exports.createDocument = createDocument;
2660
- exports.createExtendedState = createExtendedState;
2661
- exports.createReducer = createReducer;
2662
- exports.createUnsafeReducer = createUnsafeReducer;
2663
- exports.createZip = createZip;
2664
- exports.documentHelpers = documentHelpers;
2665
- exports.getLocalFile = getLocalFile;
2666
- exports.getRemoteFile = getRemoteFile;
2667
- exports.getUnixTimestamp = getUnixTimestamp;
2668
- exports.hashDocument = hashDocument;
2669
- exports.hashKey = hashKey;
2670
- exports.hex2ab = hex2ab;
2671
- exports.isBaseAction = isBaseAction;
2672
- exports.isNoopOperation = isNoopOperation;
2673
- exports.isSameDocument = isSameDocument;
2674
- exports.isUndo = isUndo;
2675
- exports.isUndoRedo = isUndoRedo;
2676
- exports.loadFromFile = loadFromFile;
2677
- exports.loadFromInput = loadFromInput;
2678
- exports.mapSkippedOperations = mapSkippedOperations;
2679
- exports.mutableBaseReducer = mutableBaseReducer;
2680
- exports.parseResultingState = parseResultingState;
2681
- exports.processUndoRedo = processUndoRedo;
2682
- exports.readOnly = readOnly;
2683
- exports.replayDocument = replayDocument;
2684
- exports.replayOperations = replayOperations;
2685
- exports.saveToFile = saveToFile;
2686
- exports.saveToFileHandle = saveToFileHandle;
2687
- exports.sortMappedOperations = sortMappedOperations;
2688
- exports.sortOperations = sortOperations;
2689
- exports.updateDocument = updateDocument;
2690
- exports.updateHeader = updateHeader;
2691
- exports.validateOperations = validateOperations;
2692
- exports.verifyOperationSignature = verifyOperationSignature;
2693
- exports.zod = zod;
2694
- //# sourceMappingURL=object-Dbc1GbBl.js.map