document-model 1.6.0 → 1.8.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 (69) hide show
  1. package/dist/browser/cjs/document-model.js +2 -2
  2. package/dist/browser/cjs/document.js +2 -2
  3. package/dist/browser/cjs/index.js +2 -2
  4. package/dist/browser/cjs/internal/{index-vlbA6Asd.js → index-UG6TQ_ad.js} +5 -10
  5. package/dist/browser/{es/internal/index-CuhiYn-8.js.map → cjs/internal/index-UG6TQ_ad.js.map} +1 -1
  6. package/dist/browser/cjs/internal/{index-BImZF-Wk.js → index-jRdLtWv9.js} +12 -4
  7. package/dist/browser/cjs/internal/index-jRdLtWv9.js.map +1 -0
  8. package/dist/browser/cjs/internal/{object-9Wvjprnm.js → object-CCclzskm.js} +640 -2287
  9. package/dist/browser/cjs/internal/object-CCclzskm.js.map +1 -0
  10. package/dist/browser/es/document-model.js +2 -2
  11. package/dist/browser/es/document.js +8 -8
  12. package/dist/browser/es/index.js +2 -2
  13. package/dist/browser/es/internal/{index-CuhiYn-8.js → index-CDwXQBxG.js} +5 -10
  14. package/dist/{node/es/internal/index-BNAE-_Hg.js.map → browser/es/internal/index-CDwXQBxG.js.map} +1 -1
  15. package/dist/browser/es/internal/index-v4H3kbAF.js +58 -0
  16. package/dist/browser/es/internal/index-v4H3kbAF.js.map +1 -0
  17. package/dist/browser/es/internal/{object-CyAog_F_.js → object-CU5T1DpX.js} +664 -2311
  18. package/dist/browser/es/internal/object-CU5T1DpX.js.map +1 -0
  19. package/dist/browser/src/document/actions/creators.d.ts +1 -1
  20. package/dist/browser/src/document/reducer.d.ts +4 -1
  21. package/dist/browser/src/document/schema/zod.d.ts +18 -18
  22. package/dist/browser/src/document/types.d.ts +13 -1
  23. package/dist/browser/src/document/utils/base.d.ts +3 -3
  24. package/dist/browser/src/document/utils/crypto.d.ts +10 -0
  25. package/dist/browser/src/document/utils/document-helpers.d.ts +10 -0
  26. package/dist/browser/src/document/utils/index.d.ts +1 -0
  27. package/dist/browser/src/document/utils/node.d.ts +3 -2
  28. package/dist/browser/src/document-model/gen/schema/zod.d.ts +169 -169
  29. package/dist/browser/src/document-model/index.d.ts +3 -3
  30. package/dist/node/cjs/document-model.js +2 -2
  31. package/dist/node/cjs/document.js +2 -2
  32. package/dist/node/cjs/index.js +2 -2
  33. package/dist/node/cjs/internal/{index-CJIU8iX-.js → index-5qN282Jw.js} +12 -4
  34. package/dist/node/cjs/internal/index-5qN282Jw.js.map +1 -0
  35. package/dist/node/cjs/internal/{index-DWeC8dwW.js → index-Bm-pIfaz.js} +5 -10
  36. package/dist/node/cjs/internal/{index-DWeC8dwW.js.map → index-Bm-pIfaz.js.map} +1 -1
  37. package/dist/node/cjs/internal/{object-op6YzhH1.js → object-BMOaYPkd.js} +381 -244
  38. package/dist/node/cjs/internal/object-BMOaYPkd.js.map +1 -0
  39. package/dist/node/es/document-model.js +2 -2
  40. package/dist/node/es/document.js +8 -8
  41. package/dist/node/es/index.js +2 -2
  42. package/dist/node/es/internal/{index-BNAE-_Hg.js → index-CAjAt1Xx.js} +5 -10
  43. package/dist/{browser/cjs/internal/index-vlbA6Asd.js.map → node/es/internal/index-CAjAt1Xx.js.map} +1 -1
  44. package/dist/node/es/internal/index-CVuLZAmf.js +58 -0
  45. package/dist/node/es/internal/index-CVuLZAmf.js.map +1 -0
  46. package/dist/node/es/internal/{object-BuK9PFjs.js → object-COSf2HUT.js} +405 -268
  47. package/dist/node/es/internal/object-COSf2HUT.js.map +1 -0
  48. package/dist/node/src/document/actions/creators.d.ts +1 -1
  49. package/dist/node/src/document/reducer.d.ts +4 -1
  50. package/dist/node/src/document/schema/zod.d.ts +18 -18
  51. package/dist/node/src/document/types.d.ts +13 -1
  52. package/dist/node/src/document/utils/base.d.ts +3 -3
  53. package/dist/node/src/document/utils/crypto.d.ts +10 -0
  54. package/dist/node/src/document/utils/document-helpers.d.ts +10 -0
  55. package/dist/node/src/document/utils/index.d.ts +1 -0
  56. package/dist/node/src/document/utils/node.d.ts +3 -2
  57. package/dist/node/src/document-model/gen/schema/zod.d.ts +169 -169
  58. package/dist/node/src/document-model/index.d.ts +3 -3
  59. package/package.json +6 -3
  60. package/dist/browser/cjs/internal/index-BImZF-Wk.js.map +0 -1
  61. package/dist/browser/cjs/internal/object-9Wvjprnm.js.map +0 -1
  62. package/dist/browser/es/internal/index-Drp90r05.js +0 -50
  63. package/dist/browser/es/internal/index-Drp90r05.js.map +0 -1
  64. package/dist/browser/es/internal/object-CyAog_F_.js.map +0 -1
  65. package/dist/node/cjs/internal/index-CJIU8iX-.js.map +0 -1
  66. package/dist/node/cjs/internal/object-op6YzhH1.js.map +0 -1
  67. package/dist/node/es/internal/index-B_7z_4EV.js +0 -50
  68. package/dist/node/es/internal/index-B_7z_4EV.js.map +0 -1
  69. package/dist/node/es/internal/object-BuK9PFjs.js.map +0 -1
@@ -1,9 +1,6 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => {
4
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
- return value;
6
- };
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
7
4
  import { create, castDraft, unsafe } from "mutative";
8
5
  import { z } from "zod";
9
6
  import JSZip from "jszip";
@@ -156,16 +153,16 @@ var safeStableStringify = { exports: {} };
156
153
  exports.stringify = stringify;
157
154
  exports.configure = configure;
158
155
  module.exports = stringify;
159
- const strEscapeSequencesRegExp = /[\u0000-\u001f\u0022\u005c\ud800-\udfff]|[\ud800-\udbff](?![\udc00-\udfff])|(?:[^\ud800-\udbff]|^)[\udc00-\udfff]/;
156
+ const strEscapeSequencesRegExp = /[\u0000-\u001f\u0022\u005c\ud800-\udfff]/;
160
157
  function strEscape(str) {
161
158
  if (str.length < 5e3 && !strEscapeSequencesRegExp.test(str)) {
162
159
  return `"${str}"`;
163
160
  }
164
161
  return JSON.stringify(str);
165
162
  }
166
- function insertSort(array) {
167
- if (array.length > 200) {
168
- return array.sort();
163
+ function sort(array, comparator) {
164
+ if (array.length > 200 || comparator) {
165
+ return array.sort(comparator);
169
166
  }
170
167
  for (let i = 1; i < array.length; i++) {
171
168
  const currentValue = array[i];
@@ -220,6 +217,16 @@ var safeStableStringify = { exports: {} };
220
217
  }
221
218
  return '"[Circular]"';
222
219
  }
220
+ function getDeterministicOption(options) {
221
+ let value;
222
+ if (hasOwnProperty.call(options, "deterministic")) {
223
+ value = options.deterministic;
224
+ if (typeof value !== "boolean" && typeof value !== "function") {
225
+ throw new TypeError('The "deterministic" argument must be of type boolean or comparator function');
226
+ }
227
+ }
228
+ return value === void 0 ? true : value;
229
+ }
223
230
  function getBooleanOption(options, key) {
224
231
  let value;
225
232
  if (hasOwnProperty.call(options, key)) {
@@ -270,8 +277,7 @@ var safeStableStringify = { exports: {} };
270
277
  if (value) {
271
278
  return (value2) => {
272
279
  let message = `Object can not safely be stringified. Received type ${typeof value2}`;
273
- if (typeof value2 !== "function")
274
- message += ` (${value2.toString()})`;
280
+ if (typeof value2 !== "function") message += ` (${value2.toString()})`;
275
281
  throw new Error(message);
276
282
  };
277
283
  }
@@ -290,7 +296,8 @@ var safeStableStringify = { exports: {} };
290
296
  }
291
297
  const circularValue = getCircularValueOption(options);
292
298
  const bigint = getBooleanOption(options, "bigint");
293
- const deterministic = getBooleanOption(options, "deterministic");
299
+ const deterministic = getDeterministicOption(options);
300
+ const comparator = typeof deterministic === "function" ? deterministic : void 0;
294
301
  const maximumDepth = getPositiveIntegerOption(options, "maximumDepth");
295
302
  const maximumBreadth = getPositiveIntegerOption(options, "maximumBreadth");
296
303
  function stringifyFnReplacer(key, parent, stack, replacer, spacer, indentation) {
@@ -365,7 +372,7 @@ ${indentation}`;
365
372
  }
366
373
  const maximumPropertiesToStringify = Math.min(keyLength, maximumBreadth);
367
374
  if (deterministic && !isTypedArrayWithEntries(value)) {
368
- keys = insertSort(keys);
375
+ keys = sort(keys, comparator);
369
376
  }
370
377
  stack.push(value);
371
378
  for (let i = 0; i < maximumPropertiesToStringify; i++) {
@@ -566,7 +573,7 @@ ${indentation}`;
566
573
  separator = join;
567
574
  }
568
575
  if (deterministic) {
569
- keys = insertSort(keys);
576
+ keys = sort(keys, comparator);
570
577
  }
571
578
  stack.push(value);
572
579
  for (let i = 0; i < maximumPropertiesToStringify; i++) {
@@ -625,7 +632,8 @@ ${originalIndentation}`;
625
632
  return circularValue;
626
633
  }
627
634
  let res = "";
628
- if (Array.isArray(value)) {
635
+ const hasLength = value.length !== void 0;
636
+ if (hasLength && Array.isArray(value)) {
629
637
  if (value.length === 0) {
630
638
  return "[]";
631
639
  }
@@ -659,14 +667,14 @@ ${originalIndentation}`;
659
667
  }
660
668
  let separator = "";
661
669
  let maximumPropertiesToStringify = Math.min(keyLength, maximumBreadth);
662
- if (isTypedArrayWithEntries(value)) {
670
+ if (hasLength && isTypedArrayWithEntries(value)) {
663
671
  res += stringifyTypedArray(value, ",", maximumBreadth);
664
672
  keys = keys.slice(value.length);
665
673
  maximumPropertiesToStringify -= value.length;
666
674
  separator = ",";
667
675
  }
668
676
  if (deterministic) {
669
- keys = insertSort(keys);
677
+ keys = sort(keys, comparator);
670
678
  }
671
679
  stack.push(value);
672
680
  for (let i = 0; i < maximumPropertiesToStringify; i++) {
@@ -758,175 +766,361 @@ function v4(options, buf, offset) {
758
766
  rnds[8] = rnds[8] & 63 | 128;
759
767
  return unsafeStringify(rnds);
760
768
  }
761
- function setNameOperation(document, name) {
762
- return { ...document, name };
763
- }
764
- function undoOperation(document, action, skip) {
765
- const { scope, input } = action;
766
- const defaultResult = {
767
- document,
768
- action,
769
- skip
770
- };
771
- return create(defaultResult, (draft) => {
772
- if (draft.document.operations[scope].length < 1) {
773
- throw new Error(
774
- `Cannot undo: no operations in history for scope "${scope}"`
769
+ const K = [
770
+ 1518500249 | 0,
771
+ 1859775393 | 0,
772
+ 2400959708 | 0,
773
+ 3395469782 | 0
774
+ ];
775
+ function createHash(algorithm) {
776
+ return new Hash();
777
+ }
778
+ class Hash {
779
+ constructor() {
780
+ this.A = 1732584193 | 0;
781
+ this.B = 4023233417 | 0;
782
+ this.C = 2562383102 | 0;
783
+ this.D = 271733878 | 0;
784
+ this.E = 3285377520 | 0;
785
+ this._size = 0;
786
+ this._sp = 0;
787
+ if (!sharedBuffer || sharedOffset >= 8e3) {
788
+ sharedBuffer = new ArrayBuffer(
789
+ 8e3
790
+ /* N.allocTotal */
775
791
  );
792
+ sharedOffset = 0;
776
793
  }
777
- if (input < 1) {
778
- throw new Error(
779
- `Invalid UNDO action: input value must be greater than 0`
794
+ this._byte = new Uint8Array(
795
+ sharedBuffer,
796
+ sharedOffset,
797
+ 80
798
+ /* N.allocBytes */
799
+ );
800
+ this._word = new Int32Array(
801
+ sharedBuffer,
802
+ sharedOffset,
803
+ 20
804
+ /* N.allocWords */
805
+ );
806
+ sharedOffset += 80;
807
+ }
808
+ update(data) {
809
+ if ("string" === typeof data) {
810
+ return this._utf8(data);
811
+ }
812
+ if (data == null) {
813
+ throw new TypeError("Invalid type: " + typeof data);
814
+ }
815
+ const byteOffset = data.byteOffset;
816
+ const length = data.byteLength;
817
+ let blocks = length / 64 | 0;
818
+ let offset = 0;
819
+ if (blocks && !(byteOffset & 3) && !(this._size % 64)) {
820
+ const block = new Int32Array(
821
+ data.buffer,
822
+ byteOffset,
823
+ blocks * 16
824
+ /* N.inputWords */
780
825
  );
826
+ while (blocks--) {
827
+ this._int32(block, offset >> 2);
828
+ offset += 64;
829
+ }
830
+ this._size += offset;
781
831
  }
782
- if (draft.skip > 0) {
783
- throw new Error(
784
- `Cannot undo: skip value from reducer cannot be used with UNDO action`
785
- );
832
+ const BYTES_PER_ELEMENT = data.BYTES_PER_ELEMENT;
833
+ if (BYTES_PER_ELEMENT !== 1 && data.buffer) {
834
+ const rest = new Uint8Array(data.buffer, byteOffset + offset, length - offset);
835
+ return this._uint8(rest);
786
836
  }
787
- const lastOperation = draft.document.operations[scope].at(-1);
788
- const isLatestOpNOOP = lastOperation && lastOperation.type === "NOOP" && lastOperation.skip > 0;
789
- draft.skip += input;
790
- if (isLatestOpNOOP) {
791
- draft.skip += lastOperation.skip;
792
- const preLastOperation = draft.document.operations[scope][draft.document.operations[scope].length - 2];
793
- if (preLastOperation && lastOperation.index - preLastOperation.index === 1) {
794
- draft.document.operations[scope].pop();
837
+ if (offset === length)
838
+ return this;
839
+ return this._uint8(data, offset);
840
+ }
841
+ _uint8(data, offset) {
842
+ const { _byte, _word } = this;
843
+ const length = data.length;
844
+ offset = offset | 0;
845
+ while (offset < length) {
846
+ const start = this._size % 64;
847
+ let index = start;
848
+ while (offset < length && index < 64) {
849
+ _byte[index++] = data[offset++];
795
850
  }
851
+ if (index >= 64) {
852
+ this._int32(_word);
853
+ }
854
+ this._size += index - start;
796
855
  }
797
- if (draft.document.operations[scope].length < draft.skip) {
798
- throw new Error(
799
- `Cannot undo: you can't undo more operations than the ones in the scope history`
800
- );
801
- }
802
- const operationsLastIndex = draft.document.operations[scope].length - 1;
803
- let skippedOpsLeft = input;
804
- let index = isLatestOpNOOP ? operationsLastIndex - lastOperation.skip : operationsLastIndex;
805
- while (skippedOpsLeft > 0 && index >= 0) {
806
- const op = draft.document.operations[scope][index];
807
- if (!op) {
808
- skippedOpsLeft--;
809
- index--;
810
- continue;
856
+ return this;
857
+ }
858
+ _utf8(text) {
859
+ const { _byte, _word } = this;
860
+ const length = text.length;
861
+ let surrogate = this._sp;
862
+ for (let offset = 0; offset < length; ) {
863
+ const start = this._size % 64;
864
+ let index = start;
865
+ while (offset < length && index < 64) {
866
+ let code = text.charCodeAt(offset++) | 0;
867
+ if (code < 128) {
868
+ _byte[index++] = code;
869
+ } else if (code < 2048) {
870
+ _byte[index++] = 192 | code >>> 6;
871
+ _byte[index++] = 128 | code & 63;
872
+ } else if (code < 55296 || code > 57343) {
873
+ _byte[index++] = 224 | code >>> 12;
874
+ _byte[index++] = 128 | code >>> 6 & 63;
875
+ _byte[index++] = 128 | code & 63;
876
+ } else if (surrogate) {
877
+ code = ((surrogate & 1023) << 10) + (code & 1023) + 65536;
878
+ _byte[index++] = 240 | code >>> 18;
879
+ _byte[index++] = 128 | code >>> 12 & 63;
880
+ _byte[index++] = 128 | code >>> 6 & 63;
881
+ _byte[index++] = 128 | code & 63;
882
+ surrogate = 0;
883
+ } else {
884
+ surrogate = code;
885
+ }
811
886
  }
812
- if (op.type === "NOOP" && op.skip > 0) {
813
- index = index - (op.skip + 1);
814
- draft.skip += op.skip + 1;
815
- } else {
816
- draft.document.clipboard.push({ ...op });
817
- skippedOpsLeft--;
818
- index--;
887
+ if (index >= 64) {
888
+ this._int32(_word);
889
+ _word[0] = _word[
890
+ 16
891
+ /* N.inputWords */
892
+ ];
819
893
  }
894
+ this._size += index - start;
820
895
  }
821
- draft.action = noop(scope);
822
- });
896
+ this._sp = surrogate;
897
+ return this;
898
+ }
899
+ _int32(data, offset) {
900
+ let { A, B, C, D, E } = this;
901
+ let i = 0;
902
+ offset = offset | 0;
903
+ while (i < 16) {
904
+ W[i++] = swap32(data[offset++]);
905
+ }
906
+ for (i = 16; i < 80; i++) {
907
+ W[i] = rotate1(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]);
908
+ }
909
+ for (i = 0; i < 80; i++) {
910
+ const S = i / 20 | 0;
911
+ const T = rotate5(A) + ft(S, B, C, D) + E + W[i] + K[S] | 0;
912
+ E = D;
913
+ D = C;
914
+ C = rotate30(B);
915
+ B = A;
916
+ A = T;
917
+ }
918
+ this.A = A + this.A | 0;
919
+ this.B = B + this.B | 0;
920
+ this.C = C + this.C | 0;
921
+ this.D = D + this.D | 0;
922
+ this.E = E + this.E | 0;
923
+ }
924
+ digest(encoding) {
925
+ const { _byte, _word } = this;
926
+ let i = this._size % 64 | 0;
927
+ _byte[i++] = 128;
928
+ while (i & 3) {
929
+ _byte[i++] = 0;
930
+ }
931
+ i >>= 2;
932
+ if (i > 14) {
933
+ while (i < 16) {
934
+ _word[i++] = 0;
935
+ }
936
+ i = 0;
937
+ this._int32(_word);
938
+ }
939
+ while (i < 16) {
940
+ _word[i++] = 0;
941
+ }
942
+ const bits64 = this._size * 8;
943
+ const low32 = (bits64 & 4294967295) >>> 0;
944
+ const high32 = (bits64 - low32) / 4294967296;
945
+ if (high32)
946
+ _word[
947
+ 14
948
+ /* N.highIndex */
949
+ ] = swap32(high32);
950
+ if (low32)
951
+ _word[
952
+ 15
953
+ /* N.lowIndex */
954
+ ] = swap32(low32);
955
+ this._int32(_word);
956
+ return encoding === "hex" ? this._hex() : this._bin();
957
+ }
958
+ _hex() {
959
+ const { A, B, C, D, E } = this;
960
+ return hex32(A) + hex32(B) + hex32(C) + hex32(D) + hex32(E);
961
+ }
962
+ _bin() {
963
+ const { A, B, C, D, E, _byte, _word } = this;
964
+ _word[0] = swap32(A);
965
+ _word[1] = swap32(B);
966
+ _word[2] = swap32(C);
967
+ _word[3] = swap32(D);
968
+ _word[4] = swap32(E);
969
+ return _byte.slice(0, 20);
970
+ }
971
+ }
972
+ const W = new Int32Array(
973
+ 80
974
+ /* N.workWords */
975
+ );
976
+ let sharedBuffer;
977
+ let sharedOffset = 0;
978
+ const hex32 = (num) => (num + 4294967296).toString(16).substr(-8);
979
+ const swapLE = (c) => c << 24 & 4278190080 | c << 8 & 16711680 | c >> 8 & 65280 | c >> 24 & 255;
980
+ const swapBE = (c) => c;
981
+ const swap32 = isBE() ? swapBE : swapLE;
982
+ const rotate1 = (num) => num << 1 | num >>> 31;
983
+ const rotate5 = (num) => num << 5 | num >>> 27;
984
+ const rotate30 = (num) => num << 30 | num >>> 2;
985
+ function ft(s, b, c, d) {
986
+ if (s === 0)
987
+ return b & c | ~b & d;
988
+ if (s === 2)
989
+ return b & c | b & d | c & d;
990
+ return b ^ c ^ d;
823
991
  }
824
- function redoOperation(document, action, skip) {
825
- const { scope, input } = action;
826
- const defaultResult = {
827
- document,
828
- action,
829
- skip
830
- };
831
- return create(defaultResult, (draft) => {
832
- if (draft.skip > 0) {
833
- throw new Error(
834
- `Cannot redo: skip value from reducer cannot be used with REDO action`
835
- );
836
- }
837
- if (input > 1) {
838
- throw new Error(
839
- `Cannot redo: you can only redo one operation at a time`
840
- );
841
- }
842
- if (input < 1) {
843
- throw new Error(`Invalid REDO action: invalid redo input value`);
844
- }
845
- if (draft.document.clipboard.length < 1) {
846
- throw new Error(`Cannot redo: no operations in the clipboard`);
847
- }
848
- const operationIndex = draft.document.clipboard.findLastIndex(
849
- (op) => op.scope === scope
850
- );
851
- if (operationIndex < 0) {
852
- throw new Error(
853
- `Cannot redo: no operations in clipboard for scope "${scope}"`
854
- );
855
- }
856
- const operation = draft.document.clipboard.splice(operationIndex, 1)[0];
857
- draft.action = castDraft({
858
- type: operation.type,
859
- scope: operation.scope,
860
- input: operation.input
861
- });
862
- });
992
+ function isBE() {
993
+ const buf = new Uint8Array(new Uint16Array([65279]).buffer);
994
+ return buf[0] === 254;
863
995
  }
864
- function pruneOperation(document, action, wrappedReducer) {
865
- const { scope } = action;
866
- const operations = document.operations[scope];
867
- let {
868
- input: { start, end }
869
- } = action;
870
- start = start || 0;
871
- end = end || operations.length;
872
- const actionsToPrune = operations.slice(start, end);
873
- const actionsToKeepStart = operations.slice(0, start);
874
- const actionsToKeepEnd = operations.slice(end);
875
- const newDocument = replayOperations(
876
- document.initialState,
877
- {
878
- ...document.operations,
879
- [scope]: actionsToKeepStart.concat(actionsToPrune)
880
- },
881
- wrappedReducer
996
+ const FileSystemError = new Error("File system not available.");
997
+ function writeFile(path, name, stream) {
998
+ throw FileSystemError;
999
+ }
1000
+ function readFile(path) {
1001
+ throw FileSystemError;
1002
+ }
1003
+ function fetchFile(url) {
1004
+ throw FileSystemError;
1005
+ }
1006
+ const getFile = async (file) => {
1007
+ return readFile();
1008
+ };
1009
+ const hash = (data, algorithm = "sha1") => {
1010
+ if (!["sha1"].includes(algorithm)) {
1011
+ throw new Error("Hashing algorithm not supported: Available: sha1");
1012
+ }
1013
+ const hash2 = hashUIntArray(data);
1014
+ return uint8ArrayToBase64(hash2);
1015
+ };
1016
+ function uint8ArrayToBase64(uint8Array) {
1017
+ let binaryString = "";
1018
+ for (let i = 0; i < uint8Array.length; i++) {
1019
+ binaryString += String.fromCharCode(uint8Array[i]);
1020
+ }
1021
+ const base64String = btoa(binaryString);
1022
+ return base64String;
1023
+ }
1024
+ function hashUIntArray(data, algorithm = "sha1") {
1025
+ if (!["sha1"].includes(algorithm)) {
1026
+ throw new Error("Hashing algorithm not supported: Available: sha1");
1027
+ }
1028
+ return createHash().update(data).digest();
1029
+ }
1030
+ function getUnixTimestamp(date) {
1031
+ return (new Date(date).getTime() / 1e3).toFixed(0);
1032
+ }
1033
+ function buildOperationSignatureParams({
1034
+ documentId,
1035
+ signer,
1036
+ operation,
1037
+ previousStateHash
1038
+ }) {
1039
+ const { timestamp, scope, id, type } = operation;
1040
+ return [
1041
+ getUnixTimestamp(timestamp),
1042
+ // timestamp,
1043
+ signer.app.key,
1044
+ // signer public key
1045
+ hash(
1046
+ // hash (docID, scope, operationID, operationName, operationInput)
1047
+ [documentId, scope, id, type, cjsModule(operation.input)].join(
1048
+ ""
1049
+ )
1050
+ ),
1051
+ previousStateHash
1052
+ // state hash that the operation was applied to
1053
+ ];
1054
+ }
1055
+ const textEncode = new TextEncoder();
1056
+ function buildOperationSignatureMessage(params) {
1057
+ const message = params.join("");
1058
+ const prefix = "Signed Operation:\n" + message.length.toString();
1059
+ return textEncode.encode(prefix + message);
1060
+ }
1061
+ function ab2hex(ab) {
1062
+ return Array.prototype.map.call(
1063
+ new Uint8Array(ab),
1064
+ (x) => ("00" + x.toString(16)).slice(-2)
1065
+ ).join("");
1066
+ }
1067
+ function hex2ab(hex) {
1068
+ var _a;
1069
+ return new Uint8Array(
1070
+ ((_a = hex.match(/[\da-f]{2}/gi)) == null ? void 0 : _a.map(function(h) {
1071
+ return parseInt(h, 16);
1072
+ })) ?? []
882
1073
  );
883
- const { name, state: newState } = newDocument;
884
- const loadStateIndex = actionsToKeepStart.length;
885
- const loadStateTimestamp = actionsToKeepStart.length ? actionsToKeepStart[actionsToKeepStart.length - 1].timestamp : actionsToKeepEnd.length ? actionsToKeepEnd[0].timestamp : (/* @__PURE__ */ new Date()).toISOString();
886
- return replayOperations(
887
- document.initialState,
1074
+ }
1075
+ async function buildOperationSignature(context, signMethod) {
1076
+ const params = buildOperationSignatureParams(context);
1077
+ const message = buildOperationSignatureMessage(params);
1078
+ const signature = await signMethod(message);
1079
+ return [...params, `0x${ab2hex(signature)}`];
1080
+ }
1081
+ async function buildSignedOperation(action, reducer, document, context, signHandler) {
1082
+ var _a, _b;
1083
+ const result = reducer(document, action, void 0, {
1084
+ reuseHash: true,
1085
+ reuseOperationResultingState: true
1086
+ });
1087
+ const operation = result.operations[action.scope].at(-1);
1088
+ if (!operation) {
1089
+ throw new Error("Action was not applied");
1090
+ }
1091
+ const previousStateHash = ((_a = result.operations[action.scope].at(-2)) == null ? void 0 : _a.hash) ?? "";
1092
+ const signature = await buildOperationSignature(
888
1093
  {
889
- ...document.operations,
890
- [scope]: [
891
- ...actionsToKeepStart,
892
- {
893
- ...loadState(
894
- { name, state: newState },
895
- actionsToPrune.length
896
- ),
897
- timestamp: loadStateTimestamp,
898
- index: loadStateIndex,
899
- hash: hashDocument({ state: newState }, "global")
900
- },
901
- ...actionsToKeepEnd.map((action2, index) => ({
902
- ...action2,
903
- index: loadStateIndex + index + 1
904
- }))
905
- ]
1094
+ ...context,
1095
+ operation,
1096
+ previousStateHash
906
1097
  },
907
- wrappedReducer
1098
+ signHandler
908
1099
  );
909
- }
910
- function loadStateOperation(oldDocument, newDocument) {
911
1100
  return {
912
- ...oldDocument,
913
- name: newDocument.name,
914
- state: newDocument.state ?? { global: {}, local: {} }
1101
+ ...operation,
1102
+ context: {
1103
+ ...operation.context,
1104
+ signer: {
1105
+ ...(_b = operation.context) == null ? void 0 : _b.signer,
1106
+ ...context.signer,
1107
+ signatures: [...context.signer.signatures ?? [], signature]
1108
+ }
1109
+ }
915
1110
  };
916
1111
  }
917
- const SET_NAME = "SET_NAME";
918
- const UNDO = "UNDO";
919
- const REDO = "REDO";
920
- const PRUNE = "PRUNE";
921
- const LOAD_STATE = "LOAD_STATE";
922
- const NOOP = "NOOP";
1112
+ async function verifyOperationSignature(signature, signer, verifyHandler) {
1113
+ const publicKey = signer.app.key;
1114
+ const params = signature.slice(0, 4);
1115
+ const signatureBytes = hex2ab(signature[4]);
1116
+ const expectedMessage = buildOperationSignatureMessage(params);
1117
+ return verifyHandler(publicKey, signatureBytes, expectedMessage);
1118
+ }
923
1119
  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"] };
924
1120
  Object.freeze(types);
925
1121
  var __classPrivateFieldGet = function(receiver, state, kind, f) {
926
- if (kind === "a" && !f)
927
- throw new TypeError("Private accessor was defined without a getter");
928
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
929
- throw new TypeError("Cannot read private member from an object whose class did not declare it");
1122
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
1123
+ 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");
930
1124
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
931
1125
  };
932
1126
  var _Mime_extensionToType, _Mime_typeToExtension, _Mime_typeToExtensions;
@@ -957,2103 +1151,58 @@ class Mime {
957
1151
  }
958
1152
  first = false;
959
1153
  if (starred)
960
- continue;
961
- const currentType = __classPrivateFieldGet(this, _Mime_extensionToType, "f").get(extension);
962
- if (currentType && currentType != type && !force) {
963
- throw new Error(`"${type} -> ${extension}" conflicts with "${currentType} -> ${extension}". Pass \`force=true\` to override this definition.`);
964
- }
965
- __classPrivateFieldGet(this, _Mime_extensionToType, "f").set(extension, type);
966
- }
967
- }
968
- return this;
969
- }
970
- getType(path) {
971
- if (typeof path !== "string")
972
- return null;
973
- const last = path.replace(/^.*[/\\]/, "").toLowerCase();
974
- const ext = last.replace(/^.*\./, "").toLowerCase();
975
- const hasPath = last.length < path.length;
976
- const hasDot = ext.length < last.length - 1;
977
- if (!hasDot && hasPath)
978
- return null;
979
- return __classPrivateFieldGet(this, _Mime_extensionToType, "f").get(ext) ?? null;
980
- }
981
- getExtension(type) {
982
- var _a;
983
- if (typeof type !== "string")
984
- return null;
985
- type = (_a = type == null ? void 0 : type.split) == null ? void 0 : _a.call(type, ";")[0];
986
- return (type && __classPrivateFieldGet(this, _Mime_typeToExtension, "f").get(type.trim().toLowerCase())) ?? null;
987
- }
988
- getAllExtensions(type) {
989
- if (typeof type !== "string")
990
- return null;
991
- return __classPrivateFieldGet(this, _Mime_typeToExtensions, "f").get(type.toLowerCase()) ?? null;
992
- }
993
- _freeze() {
994
- this.define = () => {
995
- throw new Error("define() not allowed for built-in Mime objects. See https://github.com/broofa/mime/blob/main/README.md#custom-mime-instances");
996
- };
997
- Object.freeze(this);
998
- for (const extensions of __classPrivateFieldGet(this, _Mime_typeToExtensions, "f").values()) {
999
- Object.freeze(extensions);
1000
- }
1001
- return this;
1002
- }
1003
- _getTestState() {
1004
- return {
1005
- types: __classPrivateFieldGet(this, _Mime_extensionToType, "f"),
1006
- extensions: __classPrivateFieldGet(this, _Mime_typeToExtension, "f")
1007
- };
1008
- }
1009
- }
1010
- _Mime_extensionToType = /* @__PURE__ */ new WeakMap(), _Mime_typeToExtension = /* @__PURE__ */ new WeakMap(), _Mime_typeToExtensions = /* @__PURE__ */ new WeakMap();
1011
- const mime = new Mime(types)._freeze();
1012
- var inherits_browser = { exports: {} };
1013
- if (typeof Object.create === "function") {
1014
- inherits_browser.exports = function inherits2(ctor, superCtor) {
1015
- if (superCtor) {
1016
- ctor.super_ = superCtor;
1017
- ctor.prototype = Object.create(superCtor.prototype, {
1018
- constructor: {
1019
- value: ctor,
1020
- enumerable: false,
1021
- writable: true,
1022
- configurable: true
1023
- }
1024
- });
1025
- }
1026
- };
1027
- } else {
1028
- inherits_browser.exports = function inherits2(ctor, superCtor) {
1029
- if (superCtor) {
1030
- ctor.super_ = superCtor;
1031
- var TempCtor = function() {
1032
- };
1033
- TempCtor.prototype = superCtor.prototype;
1034
- ctor.prototype = new TempCtor();
1035
- ctor.prototype.constructor = ctor;
1036
- }
1037
- };
1038
- }
1039
- var inherits_browserExports = inherits_browser.exports;
1040
- var safeBuffer = { exports: {} };
1041
- var buffer = {};
1042
- var base64Js = {};
1043
- base64Js.byteLength = byteLength;
1044
- base64Js.toByteArray = toByteArray;
1045
- base64Js.fromByteArray = fromByteArray;
1046
- var lookup = [];
1047
- var revLookup = [];
1048
- var Arr = typeof Uint8Array !== "undefined" ? Uint8Array : Array;
1049
- var code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
1050
- for (var i = 0, len = code.length; i < len; ++i) {
1051
- lookup[i] = code[i];
1052
- revLookup[code.charCodeAt(i)] = i;
1053
- }
1054
- revLookup["-".charCodeAt(0)] = 62;
1055
- revLookup["_".charCodeAt(0)] = 63;
1056
- function getLens(b64) {
1057
- var len = b64.length;
1058
- if (len % 4 > 0) {
1059
- throw new Error("Invalid string. Length must be a multiple of 4");
1060
- }
1061
- var validLen = b64.indexOf("=");
1062
- if (validLen === -1)
1063
- validLen = len;
1064
- var placeHoldersLen = validLen === len ? 0 : 4 - validLen % 4;
1065
- return [validLen, placeHoldersLen];
1066
- }
1067
- function byteLength(b64) {
1068
- var lens = getLens(b64);
1069
- var validLen = lens[0];
1070
- var placeHoldersLen = lens[1];
1071
- return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
1072
- }
1073
- function _byteLength(b64, validLen, placeHoldersLen) {
1074
- return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
1075
- }
1076
- function toByteArray(b64) {
1077
- var tmp;
1078
- var lens = getLens(b64);
1079
- var validLen = lens[0];
1080
- var placeHoldersLen = lens[1];
1081
- var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
1082
- var curByte = 0;
1083
- var len = placeHoldersLen > 0 ? validLen - 4 : validLen;
1084
- var i;
1085
- for (i = 0; i < len; i += 4) {
1086
- tmp = revLookup[b64.charCodeAt(i)] << 18 | revLookup[b64.charCodeAt(i + 1)] << 12 | revLookup[b64.charCodeAt(i + 2)] << 6 | revLookup[b64.charCodeAt(i + 3)];
1087
- arr[curByte++] = tmp >> 16 & 255;
1088
- arr[curByte++] = tmp >> 8 & 255;
1089
- arr[curByte++] = tmp & 255;
1090
- }
1091
- if (placeHoldersLen === 2) {
1092
- tmp = revLookup[b64.charCodeAt(i)] << 2 | revLookup[b64.charCodeAt(i + 1)] >> 4;
1093
- arr[curByte++] = tmp & 255;
1094
- }
1095
- if (placeHoldersLen === 1) {
1096
- tmp = revLookup[b64.charCodeAt(i)] << 10 | revLookup[b64.charCodeAt(i + 1)] << 4 | revLookup[b64.charCodeAt(i + 2)] >> 2;
1097
- arr[curByte++] = tmp >> 8 & 255;
1098
- arr[curByte++] = tmp & 255;
1099
- }
1100
- return arr;
1101
- }
1102
- function tripletToBase64(num) {
1103
- return lookup[num >> 18 & 63] + lookup[num >> 12 & 63] + lookup[num >> 6 & 63] + lookup[num & 63];
1104
- }
1105
- function encodeChunk(uint8, start, end) {
1106
- var tmp;
1107
- var output = [];
1108
- for (var i = start; i < end; i += 3) {
1109
- tmp = (uint8[i] << 16 & 16711680) + (uint8[i + 1] << 8 & 65280) + (uint8[i + 2] & 255);
1110
- output.push(tripletToBase64(tmp));
1111
- }
1112
- return output.join("");
1113
- }
1114
- function fromByteArray(uint8) {
1115
- var tmp;
1116
- var len = uint8.length;
1117
- var extraBytes = len % 3;
1118
- var parts = [];
1119
- var maxChunkLength = 16383;
1120
- for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
1121
- parts.push(encodeChunk(uint8, i, i + maxChunkLength > len2 ? len2 : i + maxChunkLength));
1122
- }
1123
- if (extraBytes === 1) {
1124
- tmp = uint8[len - 1];
1125
- parts.push(
1126
- lookup[tmp >> 2] + lookup[tmp << 4 & 63] + "=="
1127
- );
1128
- } else if (extraBytes === 2) {
1129
- tmp = (uint8[len - 2] << 8) + uint8[len - 1];
1130
- parts.push(
1131
- lookup[tmp >> 10] + lookup[tmp >> 4 & 63] + lookup[tmp << 2 & 63] + "="
1132
- );
1133
- }
1134
- return parts.join("");
1135
- }
1136
- var ieee754 = {};
1137
- /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
1138
- ieee754.read = function(buffer2, offset, isLE, mLen, nBytes) {
1139
- var e, m;
1140
- var eLen = nBytes * 8 - mLen - 1;
1141
- var eMax = (1 << eLen) - 1;
1142
- var eBias = eMax >> 1;
1143
- var nBits = -7;
1144
- var i = isLE ? nBytes - 1 : 0;
1145
- var d = isLE ? -1 : 1;
1146
- var s = buffer2[offset + i];
1147
- i += d;
1148
- e = s & (1 << -nBits) - 1;
1149
- s >>= -nBits;
1150
- nBits += eLen;
1151
- for (; nBits > 0; e = e * 256 + buffer2[offset + i], i += d, nBits -= 8) {
1152
- }
1153
- m = e & (1 << -nBits) - 1;
1154
- e >>= -nBits;
1155
- nBits += mLen;
1156
- for (; nBits > 0; m = m * 256 + buffer2[offset + i], i += d, nBits -= 8) {
1157
- }
1158
- if (e === 0) {
1159
- e = 1 - eBias;
1160
- } else if (e === eMax) {
1161
- return m ? NaN : (s ? -1 : 1) * Infinity;
1162
- } else {
1163
- m = m + Math.pow(2, mLen);
1164
- e = e - eBias;
1165
- }
1166
- return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
1167
- };
1168
- ieee754.write = function(buffer2, value, offset, isLE, mLen, nBytes) {
1169
- var e, m, c;
1170
- var eLen = nBytes * 8 - mLen - 1;
1171
- var eMax = (1 << eLen) - 1;
1172
- var eBias = eMax >> 1;
1173
- var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
1174
- var i = isLE ? 0 : nBytes - 1;
1175
- var d = isLE ? 1 : -1;
1176
- var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
1177
- value = Math.abs(value);
1178
- if (isNaN(value) || value === Infinity) {
1179
- m = isNaN(value) ? 1 : 0;
1180
- e = eMax;
1181
- } else {
1182
- e = Math.floor(Math.log(value) / Math.LN2);
1183
- if (value * (c = Math.pow(2, -e)) < 1) {
1184
- e--;
1185
- c *= 2;
1186
- }
1187
- if (e + eBias >= 1) {
1188
- value += rt / c;
1189
- } else {
1190
- value += rt * Math.pow(2, 1 - eBias);
1191
- }
1192
- if (value * c >= 2) {
1193
- e++;
1194
- c /= 2;
1195
- }
1196
- if (e + eBias >= eMax) {
1197
- m = 0;
1198
- e = eMax;
1199
- } else if (e + eBias >= 1) {
1200
- m = (value * c - 1) * Math.pow(2, mLen);
1201
- e = e + eBias;
1202
- } else {
1203
- m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
1204
- e = 0;
1205
- }
1206
- }
1207
- for (; mLen >= 8; buffer2[offset + i] = m & 255, i += d, m /= 256, mLen -= 8) {
1208
- }
1209
- e = e << mLen | m;
1210
- eLen += mLen;
1211
- for (; eLen > 0; buffer2[offset + i] = e & 255, i += d, e /= 256, eLen -= 8) {
1212
- }
1213
- buffer2[offset + i - d] |= s * 128;
1214
- };
1215
- /*!
1216
- * The buffer module from node.js, for the browser.
1217
- *
1218
- * @author Feross Aboukhadijeh <https://feross.org>
1219
- * @license MIT
1220
- */
1221
- (function(exports) {
1222
- var base64 = base64Js;
1223
- var ieee754$1 = ieee754;
1224
- var customInspectSymbol = typeof Symbol === "function" && typeof Symbol["for"] === "function" ? Symbol["for"]("nodejs.util.inspect.custom") : null;
1225
- exports.Buffer = Buffer3;
1226
- exports.SlowBuffer = SlowBuffer;
1227
- exports.INSPECT_MAX_BYTES = 50;
1228
- var K_MAX_LENGTH = 2147483647;
1229
- exports.kMaxLength = K_MAX_LENGTH;
1230
- Buffer3.TYPED_ARRAY_SUPPORT = typedArraySupport();
1231
- if (!Buffer3.TYPED_ARRAY_SUPPORT && typeof console !== "undefined" && typeof console.error === "function") {
1232
- console.error(
1233
- "This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."
1234
- );
1235
- }
1236
- function typedArraySupport() {
1237
- try {
1238
- var arr = new Uint8Array(1);
1239
- var proto = { foo: function() {
1240
- return 42;
1241
- } };
1242
- Object.setPrototypeOf(proto, Uint8Array.prototype);
1243
- Object.setPrototypeOf(arr, proto);
1244
- return arr.foo() === 42;
1245
- } catch (e) {
1246
- return false;
1247
- }
1248
- }
1249
- Object.defineProperty(Buffer3.prototype, "parent", {
1250
- enumerable: true,
1251
- get: function() {
1252
- if (!Buffer3.isBuffer(this))
1253
- return void 0;
1254
- return this.buffer;
1255
- }
1256
- });
1257
- Object.defineProperty(Buffer3.prototype, "offset", {
1258
- enumerable: true,
1259
- get: function() {
1260
- if (!Buffer3.isBuffer(this))
1261
- return void 0;
1262
- return this.byteOffset;
1263
- }
1264
- });
1265
- function createBuffer(length) {
1266
- if (length > K_MAX_LENGTH) {
1267
- throw new RangeError('The value "' + length + '" is invalid for option "size"');
1268
- }
1269
- var buf = new Uint8Array(length);
1270
- Object.setPrototypeOf(buf, Buffer3.prototype);
1271
- return buf;
1272
- }
1273
- function Buffer3(arg, encodingOrOffset, length) {
1274
- if (typeof arg === "number") {
1275
- if (typeof encodingOrOffset === "string") {
1276
- throw new TypeError(
1277
- 'The "string" argument must be of type string. Received type number'
1278
- );
1279
- }
1280
- return allocUnsafe(arg);
1281
- }
1282
- return from(arg, encodingOrOffset, length);
1283
- }
1284
- Buffer3.poolSize = 8192;
1285
- function from(value, encodingOrOffset, length) {
1286
- if (typeof value === "string") {
1287
- return fromString(value, encodingOrOffset);
1288
- }
1289
- if (ArrayBuffer.isView(value)) {
1290
- return fromArrayView(value);
1291
- }
1292
- if (value == null) {
1293
- throw new TypeError(
1294
- "The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof value
1295
- );
1296
- }
1297
- if (isInstance(value, ArrayBuffer) || value && isInstance(value.buffer, ArrayBuffer)) {
1298
- return fromArrayBuffer(value, encodingOrOffset, length);
1299
- }
1300
- if (typeof SharedArrayBuffer !== "undefined" && (isInstance(value, SharedArrayBuffer) || value && isInstance(value.buffer, SharedArrayBuffer))) {
1301
- return fromArrayBuffer(value, encodingOrOffset, length);
1302
- }
1303
- if (typeof value === "number") {
1304
- throw new TypeError(
1305
- 'The "value" argument must not be of type number. Received type number'
1306
- );
1307
- }
1308
- var valueOf = value.valueOf && value.valueOf();
1309
- if (valueOf != null && valueOf !== value) {
1310
- return Buffer3.from(valueOf, encodingOrOffset, length);
1311
- }
1312
- var b = fromObject(value);
1313
- if (b)
1314
- return b;
1315
- if (typeof Symbol !== "undefined" && Symbol.toPrimitive != null && typeof value[Symbol.toPrimitive] === "function") {
1316
- return Buffer3.from(
1317
- value[Symbol.toPrimitive]("string"),
1318
- encodingOrOffset,
1319
- length
1320
- );
1321
- }
1322
- throw new TypeError(
1323
- "The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof value
1324
- );
1325
- }
1326
- Buffer3.from = function(value, encodingOrOffset, length) {
1327
- return from(value, encodingOrOffset, length);
1328
- };
1329
- Object.setPrototypeOf(Buffer3.prototype, Uint8Array.prototype);
1330
- Object.setPrototypeOf(Buffer3, Uint8Array);
1331
- function assertSize(size) {
1332
- if (typeof size !== "number") {
1333
- throw new TypeError('"size" argument must be of type number');
1334
- } else if (size < 0) {
1335
- throw new RangeError('The value "' + size + '" is invalid for option "size"');
1336
- }
1337
- }
1338
- function alloc(size, fill, encoding) {
1339
- assertSize(size);
1340
- if (size <= 0) {
1341
- return createBuffer(size);
1342
- }
1343
- if (fill !== void 0) {
1344
- return typeof encoding === "string" ? createBuffer(size).fill(fill, encoding) : createBuffer(size).fill(fill);
1345
- }
1346
- return createBuffer(size);
1347
- }
1348
- Buffer3.alloc = function(size, fill, encoding) {
1349
- return alloc(size, fill, encoding);
1350
- };
1351
- function allocUnsafe(size) {
1352
- assertSize(size);
1353
- return createBuffer(size < 0 ? 0 : checked(size) | 0);
1354
- }
1355
- Buffer3.allocUnsafe = function(size) {
1356
- return allocUnsafe(size);
1357
- };
1358
- Buffer3.allocUnsafeSlow = function(size) {
1359
- return allocUnsafe(size);
1360
- };
1361
- function fromString(string, encoding) {
1362
- if (typeof encoding !== "string" || encoding === "") {
1363
- encoding = "utf8";
1364
- }
1365
- if (!Buffer3.isEncoding(encoding)) {
1366
- throw new TypeError("Unknown encoding: " + encoding);
1367
- }
1368
- var length = byteLength2(string, encoding) | 0;
1369
- var buf = createBuffer(length);
1370
- var actual = buf.write(string, encoding);
1371
- if (actual !== length) {
1372
- buf = buf.slice(0, actual);
1373
- }
1374
- return buf;
1375
- }
1376
- function fromArrayLike(array) {
1377
- var length = array.length < 0 ? 0 : checked(array.length) | 0;
1378
- var buf = createBuffer(length);
1379
- for (var i = 0; i < length; i += 1) {
1380
- buf[i] = array[i] & 255;
1381
- }
1382
- return buf;
1383
- }
1384
- function fromArrayView(arrayView) {
1385
- if (isInstance(arrayView, Uint8Array)) {
1386
- var copy = new Uint8Array(arrayView);
1387
- return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength);
1388
- }
1389
- return fromArrayLike(arrayView);
1390
- }
1391
- function fromArrayBuffer(array, byteOffset, length) {
1392
- if (byteOffset < 0 || array.byteLength < byteOffset) {
1393
- throw new RangeError('"offset" is outside of buffer bounds');
1394
- }
1395
- if (array.byteLength < byteOffset + (length || 0)) {
1396
- throw new RangeError('"length" is outside of buffer bounds');
1397
- }
1398
- var buf;
1399
- if (byteOffset === void 0 && length === void 0) {
1400
- buf = new Uint8Array(array);
1401
- } else if (length === void 0) {
1402
- buf = new Uint8Array(array, byteOffset);
1403
- } else {
1404
- buf = new Uint8Array(array, byteOffset, length);
1405
- }
1406
- Object.setPrototypeOf(buf, Buffer3.prototype);
1407
- return buf;
1408
- }
1409
- function fromObject(obj) {
1410
- if (Buffer3.isBuffer(obj)) {
1411
- var len = checked(obj.length) | 0;
1412
- var buf = createBuffer(len);
1413
- if (buf.length === 0) {
1414
- return buf;
1415
- }
1416
- obj.copy(buf, 0, 0, len);
1417
- return buf;
1418
- }
1419
- if (obj.length !== void 0) {
1420
- if (typeof obj.length !== "number" || numberIsNaN(obj.length)) {
1421
- return createBuffer(0);
1422
- }
1423
- return fromArrayLike(obj);
1424
- }
1425
- if (obj.type === "Buffer" && Array.isArray(obj.data)) {
1426
- return fromArrayLike(obj.data);
1427
- }
1428
- }
1429
- function checked(length) {
1430
- if (length >= K_MAX_LENGTH) {
1431
- throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x" + K_MAX_LENGTH.toString(16) + " bytes");
1432
- }
1433
- return length | 0;
1434
- }
1435
- function SlowBuffer(length) {
1436
- if (+length != length) {
1437
- length = 0;
1438
- }
1439
- return Buffer3.alloc(+length);
1440
- }
1441
- Buffer3.isBuffer = function isBuffer(b) {
1442
- return b != null && b._isBuffer === true && b !== Buffer3.prototype;
1443
- };
1444
- Buffer3.compare = function compare(a, b) {
1445
- if (isInstance(a, Uint8Array))
1446
- a = Buffer3.from(a, a.offset, a.byteLength);
1447
- if (isInstance(b, Uint8Array))
1448
- b = Buffer3.from(b, b.offset, b.byteLength);
1449
- if (!Buffer3.isBuffer(a) || !Buffer3.isBuffer(b)) {
1450
- throw new TypeError(
1451
- 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
1452
- );
1453
- }
1454
- if (a === b)
1455
- return 0;
1456
- var x = a.length;
1457
- var y = b.length;
1458
- for (var i = 0, len = Math.min(x, y); i < len; ++i) {
1459
- if (a[i] !== b[i]) {
1460
- x = a[i];
1461
- y = b[i];
1462
- break;
1463
- }
1464
- }
1465
- if (x < y)
1466
- return -1;
1467
- if (y < x)
1468
- return 1;
1469
- return 0;
1470
- };
1471
- Buffer3.isEncoding = function isEncoding(encoding) {
1472
- switch (String(encoding).toLowerCase()) {
1473
- case "hex":
1474
- case "utf8":
1475
- case "utf-8":
1476
- case "ascii":
1477
- case "latin1":
1478
- case "binary":
1479
- case "base64":
1480
- case "ucs2":
1481
- case "ucs-2":
1482
- case "utf16le":
1483
- case "utf-16le":
1484
- return true;
1485
- default:
1486
- return false;
1487
- }
1488
- };
1489
- Buffer3.concat = function concat(list, length) {
1490
- if (!Array.isArray(list)) {
1491
- throw new TypeError('"list" argument must be an Array of Buffers');
1492
- }
1493
- if (list.length === 0) {
1494
- return Buffer3.alloc(0);
1495
- }
1496
- var i;
1497
- if (length === void 0) {
1498
- length = 0;
1499
- for (i = 0; i < list.length; ++i) {
1500
- length += list[i].length;
1501
- }
1502
- }
1503
- var buffer2 = Buffer3.allocUnsafe(length);
1504
- var pos = 0;
1505
- for (i = 0; i < list.length; ++i) {
1506
- var buf = list[i];
1507
- if (isInstance(buf, Uint8Array)) {
1508
- if (pos + buf.length > buffer2.length) {
1509
- Buffer3.from(buf).copy(buffer2, pos);
1510
- } else {
1511
- Uint8Array.prototype.set.call(
1512
- buffer2,
1513
- buf,
1514
- pos
1515
- );
1516
- }
1517
- } else if (!Buffer3.isBuffer(buf)) {
1518
- throw new TypeError('"list" argument must be an Array of Buffers');
1519
- } else {
1520
- buf.copy(buffer2, pos);
1521
- }
1522
- pos += buf.length;
1523
- }
1524
- return buffer2;
1525
- };
1526
- function byteLength2(string, encoding) {
1527
- if (Buffer3.isBuffer(string)) {
1528
- return string.length;
1529
- }
1530
- if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
1531
- return string.byteLength;
1532
- }
1533
- if (typeof string !== "string") {
1534
- throw new TypeError(
1535
- 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type ' + typeof string
1536
- );
1537
- }
1538
- var len = string.length;
1539
- var mustMatch = arguments.length > 2 && arguments[2] === true;
1540
- if (!mustMatch && len === 0)
1541
- return 0;
1542
- var loweredCase = false;
1543
- for (; ; ) {
1544
- switch (encoding) {
1545
- case "ascii":
1546
- case "latin1":
1547
- case "binary":
1548
- return len;
1549
- case "utf8":
1550
- case "utf-8":
1551
- return utf8ToBytes(string).length;
1552
- case "ucs2":
1553
- case "ucs-2":
1554
- case "utf16le":
1555
- case "utf-16le":
1556
- return len * 2;
1557
- case "hex":
1558
- return len >>> 1;
1559
- case "base64":
1560
- return base64ToBytes(string).length;
1561
- default:
1562
- if (loweredCase) {
1563
- return mustMatch ? -1 : utf8ToBytes(string).length;
1564
- }
1565
- encoding = ("" + encoding).toLowerCase();
1566
- loweredCase = true;
1567
- }
1568
- }
1569
- }
1570
- Buffer3.byteLength = byteLength2;
1571
- function slowToString(encoding, start, end) {
1572
- var loweredCase = false;
1573
- if (start === void 0 || start < 0) {
1574
- start = 0;
1575
- }
1576
- if (start > this.length) {
1577
- return "";
1578
- }
1579
- if (end === void 0 || end > this.length) {
1580
- end = this.length;
1581
- }
1582
- if (end <= 0) {
1583
- return "";
1584
- }
1585
- end >>>= 0;
1586
- start >>>= 0;
1587
- if (end <= start) {
1588
- return "";
1589
- }
1590
- if (!encoding)
1591
- encoding = "utf8";
1592
- while (true) {
1593
- switch (encoding) {
1594
- case "hex":
1595
- return hexSlice(this, start, end);
1596
- case "utf8":
1597
- case "utf-8":
1598
- return utf8Slice(this, start, end);
1599
- case "ascii":
1600
- return asciiSlice(this, start, end);
1601
- case "latin1":
1602
- case "binary":
1603
- return latin1Slice(this, start, end);
1604
- case "base64":
1605
- return base64Slice(this, start, end);
1606
- case "ucs2":
1607
- case "ucs-2":
1608
- case "utf16le":
1609
- case "utf-16le":
1610
- return utf16leSlice(this, start, end);
1611
- default:
1612
- if (loweredCase)
1613
- throw new TypeError("Unknown encoding: " + encoding);
1614
- encoding = (encoding + "").toLowerCase();
1615
- loweredCase = true;
1616
- }
1617
- }
1618
- }
1619
- Buffer3.prototype._isBuffer = true;
1620
- function swap(b, n, m) {
1621
- var i = b[n];
1622
- b[n] = b[m];
1623
- b[m] = i;
1624
- }
1625
- Buffer3.prototype.swap16 = function swap16() {
1626
- var len = this.length;
1627
- if (len % 2 !== 0) {
1628
- throw new RangeError("Buffer size must be a multiple of 16-bits");
1629
- }
1630
- for (var i = 0; i < len; i += 2) {
1631
- swap(this, i, i + 1);
1632
- }
1633
- return this;
1634
- };
1635
- Buffer3.prototype.swap32 = function swap32() {
1636
- var len = this.length;
1637
- if (len % 4 !== 0) {
1638
- throw new RangeError("Buffer size must be a multiple of 32-bits");
1639
- }
1640
- for (var i = 0; i < len; i += 4) {
1641
- swap(this, i, i + 3);
1642
- swap(this, i + 1, i + 2);
1643
- }
1644
- return this;
1645
- };
1646
- Buffer3.prototype.swap64 = function swap64() {
1647
- var len = this.length;
1648
- if (len % 8 !== 0) {
1649
- throw new RangeError("Buffer size must be a multiple of 64-bits");
1650
- }
1651
- for (var i = 0; i < len; i += 8) {
1652
- swap(this, i, i + 7);
1653
- swap(this, i + 1, i + 6);
1654
- swap(this, i + 2, i + 5);
1655
- swap(this, i + 3, i + 4);
1656
- }
1657
- return this;
1658
- };
1659
- Buffer3.prototype.toString = function toString() {
1660
- var length = this.length;
1661
- if (length === 0)
1662
- return "";
1663
- if (arguments.length === 0)
1664
- return utf8Slice(this, 0, length);
1665
- return slowToString.apply(this, arguments);
1666
- };
1667
- Buffer3.prototype.toLocaleString = Buffer3.prototype.toString;
1668
- Buffer3.prototype.equals = function equals(b) {
1669
- if (!Buffer3.isBuffer(b))
1670
- throw new TypeError("Argument must be a Buffer");
1671
- if (this === b)
1672
- return true;
1673
- return Buffer3.compare(this, b) === 0;
1674
- };
1675
- Buffer3.prototype.inspect = function inspect() {
1676
- var str = "";
1677
- var max = exports.INSPECT_MAX_BYTES;
1678
- str = this.toString("hex", 0, max).replace(/(.{2})/g, "$1 ").trim();
1679
- if (this.length > max)
1680
- str += " ... ";
1681
- return "<Buffer " + str + ">";
1682
- };
1683
- if (customInspectSymbol) {
1684
- Buffer3.prototype[customInspectSymbol] = Buffer3.prototype.inspect;
1685
- }
1686
- Buffer3.prototype.compare = function compare(target, start, end, thisStart, thisEnd) {
1687
- if (isInstance(target, Uint8Array)) {
1688
- target = Buffer3.from(target, target.offset, target.byteLength);
1689
- }
1690
- if (!Buffer3.isBuffer(target)) {
1691
- throw new TypeError(
1692
- 'The "target" argument must be one of type Buffer or Uint8Array. Received type ' + typeof target
1693
- );
1694
- }
1695
- if (start === void 0) {
1696
- start = 0;
1697
- }
1698
- if (end === void 0) {
1699
- end = target ? target.length : 0;
1700
- }
1701
- if (thisStart === void 0) {
1702
- thisStart = 0;
1703
- }
1704
- if (thisEnd === void 0) {
1705
- thisEnd = this.length;
1706
- }
1707
- if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
1708
- throw new RangeError("out of range index");
1709
- }
1710
- if (thisStart >= thisEnd && start >= end) {
1711
- return 0;
1712
- }
1713
- if (thisStart >= thisEnd) {
1714
- return -1;
1715
- }
1716
- if (start >= end) {
1717
- return 1;
1718
- }
1719
- start >>>= 0;
1720
- end >>>= 0;
1721
- thisStart >>>= 0;
1722
- thisEnd >>>= 0;
1723
- if (this === target)
1724
- return 0;
1725
- var x = thisEnd - thisStart;
1726
- var y = end - start;
1727
- var len = Math.min(x, y);
1728
- var thisCopy = this.slice(thisStart, thisEnd);
1729
- var targetCopy = target.slice(start, end);
1730
- for (var i = 0; i < len; ++i) {
1731
- if (thisCopy[i] !== targetCopy[i]) {
1732
- x = thisCopy[i];
1733
- y = targetCopy[i];
1734
- break;
1735
- }
1736
- }
1737
- if (x < y)
1738
- return -1;
1739
- if (y < x)
1740
- return 1;
1741
- return 0;
1742
- };
1743
- function bidirectionalIndexOf(buffer2, val, byteOffset, encoding, dir) {
1744
- if (buffer2.length === 0)
1745
- return -1;
1746
- if (typeof byteOffset === "string") {
1747
- encoding = byteOffset;
1748
- byteOffset = 0;
1749
- } else if (byteOffset > 2147483647) {
1750
- byteOffset = 2147483647;
1751
- } else if (byteOffset < -2147483648) {
1752
- byteOffset = -2147483648;
1753
- }
1754
- byteOffset = +byteOffset;
1755
- if (numberIsNaN(byteOffset)) {
1756
- byteOffset = dir ? 0 : buffer2.length - 1;
1757
- }
1758
- if (byteOffset < 0)
1759
- byteOffset = buffer2.length + byteOffset;
1760
- if (byteOffset >= buffer2.length) {
1761
- if (dir)
1762
- return -1;
1763
- else
1764
- byteOffset = buffer2.length - 1;
1765
- } else if (byteOffset < 0) {
1766
- if (dir)
1767
- byteOffset = 0;
1768
- else
1769
- return -1;
1770
- }
1771
- if (typeof val === "string") {
1772
- val = Buffer3.from(val, encoding);
1773
- }
1774
- if (Buffer3.isBuffer(val)) {
1775
- if (val.length === 0) {
1776
- return -1;
1777
- }
1778
- return arrayIndexOf(buffer2, val, byteOffset, encoding, dir);
1779
- } else if (typeof val === "number") {
1780
- val = val & 255;
1781
- if (typeof Uint8Array.prototype.indexOf === "function") {
1782
- if (dir) {
1783
- return Uint8Array.prototype.indexOf.call(buffer2, val, byteOffset);
1784
- } else {
1785
- return Uint8Array.prototype.lastIndexOf.call(buffer2, val, byteOffset);
1786
- }
1787
- }
1788
- return arrayIndexOf(buffer2, [val], byteOffset, encoding, dir);
1789
- }
1790
- throw new TypeError("val must be string, number or Buffer");
1791
- }
1792
- function arrayIndexOf(arr, val, byteOffset, encoding, dir) {
1793
- var indexSize = 1;
1794
- var arrLength = arr.length;
1795
- var valLength = val.length;
1796
- if (encoding !== void 0) {
1797
- encoding = String(encoding).toLowerCase();
1798
- if (encoding === "ucs2" || encoding === "ucs-2" || encoding === "utf16le" || encoding === "utf-16le") {
1799
- if (arr.length < 2 || val.length < 2) {
1800
- return -1;
1801
- }
1802
- indexSize = 2;
1803
- arrLength /= 2;
1804
- valLength /= 2;
1805
- byteOffset /= 2;
1806
- }
1807
- }
1808
- function read(buf, i2) {
1809
- if (indexSize === 1) {
1810
- return buf[i2];
1811
- } else {
1812
- return buf.readUInt16BE(i2 * indexSize);
1813
- }
1814
- }
1815
- var i;
1816
- if (dir) {
1817
- var foundIndex = -1;
1818
- for (i = byteOffset; i < arrLength; i++) {
1819
- if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
1820
- if (foundIndex === -1)
1821
- foundIndex = i;
1822
- if (i - foundIndex + 1 === valLength)
1823
- return foundIndex * indexSize;
1824
- } else {
1825
- if (foundIndex !== -1)
1826
- i -= i - foundIndex;
1827
- foundIndex = -1;
1828
- }
1829
- }
1830
- } else {
1831
- if (byteOffset + valLength > arrLength)
1832
- byteOffset = arrLength - valLength;
1833
- for (i = byteOffset; i >= 0; i--) {
1834
- var found = true;
1835
- for (var j = 0; j < valLength; j++) {
1836
- if (read(arr, i + j) !== read(val, j)) {
1837
- found = false;
1838
- break;
1839
- }
1840
- }
1841
- if (found)
1842
- return i;
1843
- }
1844
- }
1845
- return -1;
1846
- }
1847
- Buffer3.prototype.includes = function includes(val, byteOffset, encoding) {
1848
- return this.indexOf(val, byteOffset, encoding) !== -1;
1849
- };
1850
- Buffer3.prototype.indexOf = function indexOf(val, byteOffset, encoding) {
1851
- return bidirectionalIndexOf(this, val, byteOffset, encoding, true);
1852
- };
1853
- Buffer3.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) {
1854
- return bidirectionalIndexOf(this, val, byteOffset, encoding, false);
1855
- };
1856
- function hexWrite(buf, string, offset, length) {
1857
- offset = Number(offset) || 0;
1858
- var remaining = buf.length - offset;
1859
- if (!length) {
1860
- length = remaining;
1861
- } else {
1862
- length = Number(length);
1863
- if (length > remaining) {
1864
- length = remaining;
1865
- }
1866
- }
1867
- var strLen = string.length;
1868
- if (length > strLen / 2) {
1869
- length = strLen / 2;
1870
- }
1871
- for (var i = 0; i < length; ++i) {
1872
- var parsed = parseInt(string.substr(i * 2, 2), 16);
1873
- if (numberIsNaN(parsed))
1874
- return i;
1875
- buf[offset + i] = parsed;
1876
- }
1877
- return i;
1878
- }
1879
- function utf8Write(buf, string, offset, length) {
1880
- return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length);
1881
- }
1882
- function asciiWrite(buf, string, offset, length) {
1883
- return blitBuffer(asciiToBytes(string), buf, offset, length);
1884
- }
1885
- function base64Write(buf, string, offset, length) {
1886
- return blitBuffer(base64ToBytes(string), buf, offset, length);
1887
- }
1888
- function ucs2Write(buf, string, offset, length) {
1889
- return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length);
1890
- }
1891
- Buffer3.prototype.write = function write(string, offset, length, encoding) {
1892
- if (offset === void 0) {
1893
- encoding = "utf8";
1894
- length = this.length;
1895
- offset = 0;
1896
- } else if (length === void 0 && typeof offset === "string") {
1897
- encoding = offset;
1898
- length = this.length;
1899
- offset = 0;
1900
- } else if (isFinite(offset)) {
1901
- offset = offset >>> 0;
1902
- if (isFinite(length)) {
1903
- length = length >>> 0;
1904
- if (encoding === void 0)
1905
- encoding = "utf8";
1906
- } else {
1907
- encoding = length;
1908
- length = void 0;
1909
- }
1910
- } else {
1911
- throw new Error(
1912
- "Buffer.write(string, encoding, offset[, length]) is no longer supported"
1913
- );
1914
- }
1915
- var remaining = this.length - offset;
1916
- if (length === void 0 || length > remaining)
1917
- length = remaining;
1918
- if (string.length > 0 && (length < 0 || offset < 0) || offset > this.length) {
1919
- throw new RangeError("Attempt to write outside buffer bounds");
1920
- }
1921
- if (!encoding)
1922
- encoding = "utf8";
1923
- var loweredCase = false;
1924
- for (; ; ) {
1925
- switch (encoding) {
1926
- case "hex":
1927
- return hexWrite(this, string, offset, length);
1928
- case "utf8":
1929
- case "utf-8":
1930
- return utf8Write(this, string, offset, length);
1931
- case "ascii":
1932
- case "latin1":
1933
- case "binary":
1934
- return asciiWrite(this, string, offset, length);
1935
- case "base64":
1936
- return base64Write(this, string, offset, length);
1937
- case "ucs2":
1938
- case "ucs-2":
1939
- case "utf16le":
1940
- case "utf-16le":
1941
- return ucs2Write(this, string, offset, length);
1942
- default:
1943
- if (loweredCase)
1944
- throw new TypeError("Unknown encoding: " + encoding);
1945
- encoding = ("" + encoding).toLowerCase();
1946
- loweredCase = true;
1947
- }
1948
- }
1949
- };
1950
- Buffer3.prototype.toJSON = function toJSON() {
1951
- return {
1952
- type: "Buffer",
1953
- data: Array.prototype.slice.call(this._arr || this, 0)
1954
- };
1955
- };
1956
- function base64Slice(buf, start, end) {
1957
- if (start === 0 && end === buf.length) {
1958
- return base64.fromByteArray(buf);
1959
- } else {
1960
- return base64.fromByteArray(buf.slice(start, end));
1961
- }
1962
- }
1963
- function utf8Slice(buf, start, end) {
1964
- end = Math.min(buf.length, end);
1965
- var res = [];
1966
- var i = start;
1967
- while (i < end) {
1968
- var firstByte = buf[i];
1969
- var codePoint = null;
1970
- var bytesPerSequence = firstByte > 239 ? 4 : firstByte > 223 ? 3 : firstByte > 191 ? 2 : 1;
1971
- if (i + bytesPerSequence <= end) {
1972
- var secondByte, thirdByte, fourthByte, tempCodePoint;
1973
- switch (bytesPerSequence) {
1974
- case 1:
1975
- if (firstByte < 128) {
1976
- codePoint = firstByte;
1977
- }
1978
- break;
1979
- case 2:
1980
- secondByte = buf[i + 1];
1981
- if ((secondByte & 192) === 128) {
1982
- tempCodePoint = (firstByte & 31) << 6 | secondByte & 63;
1983
- if (tempCodePoint > 127) {
1984
- codePoint = tempCodePoint;
1985
- }
1986
- }
1987
- break;
1988
- case 3:
1989
- secondByte = buf[i + 1];
1990
- thirdByte = buf[i + 2];
1991
- if ((secondByte & 192) === 128 && (thirdByte & 192) === 128) {
1992
- tempCodePoint = (firstByte & 15) << 12 | (secondByte & 63) << 6 | thirdByte & 63;
1993
- if (tempCodePoint > 2047 && (tempCodePoint < 55296 || tempCodePoint > 57343)) {
1994
- codePoint = tempCodePoint;
1995
- }
1996
- }
1997
- break;
1998
- case 4:
1999
- secondByte = buf[i + 1];
2000
- thirdByte = buf[i + 2];
2001
- fourthByte = buf[i + 3];
2002
- if ((secondByte & 192) === 128 && (thirdByte & 192) === 128 && (fourthByte & 192) === 128) {
2003
- tempCodePoint = (firstByte & 15) << 18 | (secondByte & 63) << 12 | (thirdByte & 63) << 6 | fourthByte & 63;
2004
- if (tempCodePoint > 65535 && tempCodePoint < 1114112) {
2005
- codePoint = tempCodePoint;
2006
- }
2007
- }
2008
- }
2009
- }
2010
- if (codePoint === null) {
2011
- codePoint = 65533;
2012
- bytesPerSequence = 1;
2013
- } else if (codePoint > 65535) {
2014
- codePoint -= 65536;
2015
- res.push(codePoint >>> 10 & 1023 | 55296);
2016
- codePoint = 56320 | codePoint & 1023;
2017
- }
2018
- res.push(codePoint);
2019
- i += bytesPerSequence;
2020
- }
2021
- return decodeCodePointsArray(res);
2022
- }
2023
- var MAX_ARGUMENTS_LENGTH = 4096;
2024
- function decodeCodePointsArray(codePoints) {
2025
- var len = codePoints.length;
2026
- if (len <= MAX_ARGUMENTS_LENGTH) {
2027
- return String.fromCharCode.apply(String, codePoints);
2028
- }
2029
- var res = "";
2030
- var i = 0;
2031
- while (i < len) {
2032
- res += String.fromCharCode.apply(
2033
- String,
2034
- codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
2035
- );
2036
- }
2037
- return res;
2038
- }
2039
- function asciiSlice(buf, start, end) {
2040
- var ret = "";
2041
- end = Math.min(buf.length, end);
2042
- for (var i = start; i < end; ++i) {
2043
- ret += String.fromCharCode(buf[i] & 127);
2044
- }
2045
- return ret;
2046
- }
2047
- function latin1Slice(buf, start, end) {
2048
- var ret = "";
2049
- end = Math.min(buf.length, end);
2050
- for (var i = start; i < end; ++i) {
2051
- ret += String.fromCharCode(buf[i]);
2052
- }
2053
- return ret;
2054
- }
2055
- function hexSlice(buf, start, end) {
2056
- var len = buf.length;
2057
- if (!start || start < 0)
2058
- start = 0;
2059
- if (!end || end < 0 || end > len)
2060
- end = len;
2061
- var out = "";
2062
- for (var i = start; i < end; ++i) {
2063
- out += hexSliceLookupTable[buf[i]];
2064
- }
2065
- return out;
2066
- }
2067
- function utf16leSlice(buf, start, end) {
2068
- var bytes = buf.slice(start, end);
2069
- var res = "";
2070
- for (var i = 0; i < bytes.length - 1; i += 2) {
2071
- res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
2072
- }
2073
- return res;
2074
- }
2075
- Buffer3.prototype.slice = function slice(start, end) {
2076
- var len = this.length;
2077
- start = ~~start;
2078
- end = end === void 0 ? len : ~~end;
2079
- if (start < 0) {
2080
- start += len;
2081
- if (start < 0)
2082
- start = 0;
2083
- } else if (start > len) {
2084
- start = len;
2085
- }
2086
- if (end < 0) {
2087
- end += len;
2088
- if (end < 0)
2089
- end = 0;
2090
- } else if (end > len) {
2091
- end = len;
2092
- }
2093
- if (end < start)
2094
- end = start;
2095
- var newBuf = this.subarray(start, end);
2096
- Object.setPrototypeOf(newBuf, Buffer3.prototype);
2097
- return newBuf;
2098
- };
2099
- function checkOffset(offset, ext, length) {
2100
- if (offset % 1 !== 0 || offset < 0)
2101
- throw new RangeError("offset is not uint");
2102
- if (offset + ext > length)
2103
- throw new RangeError("Trying to access beyond buffer length");
2104
- }
2105
- Buffer3.prototype.readUintLE = Buffer3.prototype.readUIntLE = function readUIntLE(offset, byteLength3, noAssert) {
2106
- offset = offset >>> 0;
2107
- byteLength3 = byteLength3 >>> 0;
2108
- if (!noAssert)
2109
- checkOffset(offset, byteLength3, this.length);
2110
- var val = this[offset];
2111
- var mul = 1;
2112
- var i = 0;
2113
- while (++i < byteLength3 && (mul *= 256)) {
2114
- val += this[offset + i] * mul;
2115
- }
2116
- return val;
2117
- };
2118
- Buffer3.prototype.readUintBE = Buffer3.prototype.readUIntBE = function readUIntBE(offset, byteLength3, noAssert) {
2119
- offset = offset >>> 0;
2120
- byteLength3 = byteLength3 >>> 0;
2121
- if (!noAssert) {
2122
- checkOffset(offset, byteLength3, this.length);
2123
- }
2124
- var val = this[offset + --byteLength3];
2125
- var mul = 1;
2126
- while (byteLength3 > 0 && (mul *= 256)) {
2127
- val += this[offset + --byteLength3] * mul;
2128
- }
2129
- return val;
2130
- };
2131
- Buffer3.prototype.readUint8 = Buffer3.prototype.readUInt8 = function readUInt8(offset, noAssert) {
2132
- offset = offset >>> 0;
2133
- if (!noAssert)
2134
- checkOffset(offset, 1, this.length);
2135
- return this[offset];
2136
- };
2137
- Buffer3.prototype.readUint16LE = Buffer3.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) {
2138
- offset = offset >>> 0;
2139
- if (!noAssert)
2140
- checkOffset(offset, 2, this.length);
2141
- return this[offset] | this[offset + 1] << 8;
2142
- };
2143
- Buffer3.prototype.readUint16BE = Buffer3.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) {
2144
- offset = offset >>> 0;
2145
- if (!noAssert)
2146
- checkOffset(offset, 2, this.length);
2147
- return this[offset] << 8 | this[offset + 1];
2148
- };
2149
- Buffer3.prototype.readUint32LE = Buffer3.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) {
2150
- offset = offset >>> 0;
2151
- if (!noAssert)
2152
- checkOffset(offset, 4, this.length);
2153
- return (this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16) + this[offset + 3] * 16777216;
2154
- };
2155
- Buffer3.prototype.readUint32BE = Buffer3.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) {
2156
- offset = offset >>> 0;
2157
- if (!noAssert)
2158
- checkOffset(offset, 4, this.length);
2159
- return this[offset] * 16777216 + (this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]);
2160
- };
2161
- Buffer3.prototype.readIntLE = function readIntLE(offset, byteLength3, noAssert) {
2162
- offset = offset >>> 0;
2163
- byteLength3 = byteLength3 >>> 0;
2164
- if (!noAssert)
2165
- checkOffset(offset, byteLength3, this.length);
2166
- var val = this[offset];
2167
- var mul = 1;
2168
- var i = 0;
2169
- while (++i < byteLength3 && (mul *= 256)) {
2170
- val += this[offset + i] * mul;
2171
- }
2172
- mul *= 128;
2173
- if (val >= mul)
2174
- val -= Math.pow(2, 8 * byteLength3);
2175
- return val;
2176
- };
2177
- Buffer3.prototype.readIntBE = function readIntBE(offset, byteLength3, noAssert) {
2178
- offset = offset >>> 0;
2179
- byteLength3 = byteLength3 >>> 0;
2180
- if (!noAssert)
2181
- checkOffset(offset, byteLength3, this.length);
2182
- var i = byteLength3;
2183
- var mul = 1;
2184
- var val = this[offset + --i];
2185
- while (i > 0 && (mul *= 256)) {
2186
- val += this[offset + --i] * mul;
2187
- }
2188
- mul *= 128;
2189
- if (val >= mul)
2190
- val -= Math.pow(2, 8 * byteLength3);
2191
- return val;
2192
- };
2193
- Buffer3.prototype.readInt8 = function readInt8(offset, noAssert) {
2194
- offset = offset >>> 0;
2195
- if (!noAssert)
2196
- checkOffset(offset, 1, this.length);
2197
- if (!(this[offset] & 128))
2198
- return this[offset];
2199
- return (255 - this[offset] + 1) * -1;
2200
- };
2201
- Buffer3.prototype.readInt16LE = function readInt16LE(offset, noAssert) {
2202
- offset = offset >>> 0;
2203
- if (!noAssert)
2204
- checkOffset(offset, 2, this.length);
2205
- var val = this[offset] | this[offset + 1] << 8;
2206
- return val & 32768 ? val | 4294901760 : val;
2207
- };
2208
- Buffer3.prototype.readInt16BE = function readInt16BE(offset, noAssert) {
2209
- offset = offset >>> 0;
2210
- if (!noAssert)
2211
- checkOffset(offset, 2, this.length);
2212
- var val = this[offset + 1] | this[offset] << 8;
2213
- return val & 32768 ? val | 4294901760 : val;
2214
- };
2215
- Buffer3.prototype.readInt32LE = function readInt32LE(offset, noAssert) {
2216
- offset = offset >>> 0;
2217
- if (!noAssert)
2218
- checkOffset(offset, 4, this.length);
2219
- return this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16 | this[offset + 3] << 24;
2220
- };
2221
- Buffer3.prototype.readInt32BE = function readInt32BE(offset, noAssert) {
2222
- offset = offset >>> 0;
2223
- if (!noAssert)
2224
- checkOffset(offset, 4, this.length);
2225
- return this[offset] << 24 | this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3];
2226
- };
2227
- Buffer3.prototype.readFloatLE = function readFloatLE(offset, noAssert) {
2228
- offset = offset >>> 0;
2229
- if (!noAssert)
2230
- checkOffset(offset, 4, this.length);
2231
- return ieee754$1.read(this, offset, true, 23, 4);
2232
- };
2233
- Buffer3.prototype.readFloatBE = function readFloatBE(offset, noAssert) {
2234
- offset = offset >>> 0;
2235
- if (!noAssert)
2236
- checkOffset(offset, 4, this.length);
2237
- return ieee754$1.read(this, offset, false, 23, 4);
2238
- };
2239
- Buffer3.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) {
2240
- offset = offset >>> 0;
2241
- if (!noAssert)
2242
- checkOffset(offset, 8, this.length);
2243
- return ieee754$1.read(this, offset, true, 52, 8);
2244
- };
2245
- Buffer3.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) {
2246
- offset = offset >>> 0;
2247
- if (!noAssert)
2248
- checkOffset(offset, 8, this.length);
2249
- return ieee754$1.read(this, offset, false, 52, 8);
2250
- };
2251
- function checkInt(buf, value, offset, ext, max, min) {
2252
- if (!Buffer3.isBuffer(buf))
2253
- throw new TypeError('"buffer" argument must be a Buffer instance');
2254
- if (value > max || value < min)
2255
- throw new RangeError('"value" argument is out of bounds');
2256
- if (offset + ext > buf.length)
2257
- throw new RangeError("Index out of range");
2258
- }
2259
- Buffer3.prototype.writeUintLE = Buffer3.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength3, noAssert) {
2260
- value = +value;
2261
- offset = offset >>> 0;
2262
- byteLength3 = byteLength3 >>> 0;
2263
- if (!noAssert) {
2264
- var maxBytes = Math.pow(2, 8 * byteLength3) - 1;
2265
- checkInt(this, value, offset, byteLength3, maxBytes, 0);
2266
- }
2267
- var mul = 1;
2268
- var i = 0;
2269
- this[offset] = value & 255;
2270
- while (++i < byteLength3 && (mul *= 256)) {
2271
- this[offset + i] = value / mul & 255;
2272
- }
2273
- return offset + byteLength3;
2274
- };
2275
- Buffer3.prototype.writeUintBE = Buffer3.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength3, noAssert) {
2276
- value = +value;
2277
- offset = offset >>> 0;
2278
- byteLength3 = byteLength3 >>> 0;
2279
- if (!noAssert) {
2280
- var maxBytes = Math.pow(2, 8 * byteLength3) - 1;
2281
- checkInt(this, value, offset, byteLength3, maxBytes, 0);
2282
- }
2283
- var i = byteLength3 - 1;
2284
- var mul = 1;
2285
- this[offset + i] = value & 255;
2286
- while (--i >= 0 && (mul *= 256)) {
2287
- this[offset + i] = value / mul & 255;
2288
- }
2289
- return offset + byteLength3;
2290
- };
2291
- Buffer3.prototype.writeUint8 = Buffer3.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) {
2292
- value = +value;
2293
- offset = offset >>> 0;
2294
- if (!noAssert)
2295
- checkInt(this, value, offset, 1, 255, 0);
2296
- this[offset] = value & 255;
2297
- return offset + 1;
2298
- };
2299
- Buffer3.prototype.writeUint16LE = Buffer3.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) {
2300
- value = +value;
2301
- offset = offset >>> 0;
2302
- if (!noAssert)
2303
- checkInt(this, value, offset, 2, 65535, 0);
2304
- this[offset] = value & 255;
2305
- this[offset + 1] = value >>> 8;
2306
- return offset + 2;
2307
- };
2308
- Buffer3.prototype.writeUint16BE = Buffer3.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) {
2309
- value = +value;
2310
- offset = offset >>> 0;
2311
- if (!noAssert)
2312
- checkInt(this, value, offset, 2, 65535, 0);
2313
- this[offset] = value >>> 8;
2314
- this[offset + 1] = value & 255;
2315
- return offset + 2;
2316
- };
2317
- Buffer3.prototype.writeUint32LE = Buffer3.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) {
2318
- value = +value;
2319
- offset = offset >>> 0;
2320
- if (!noAssert)
2321
- checkInt(this, value, offset, 4, 4294967295, 0);
2322
- this[offset + 3] = value >>> 24;
2323
- this[offset + 2] = value >>> 16;
2324
- this[offset + 1] = value >>> 8;
2325
- this[offset] = value & 255;
2326
- return offset + 4;
2327
- };
2328
- Buffer3.prototype.writeUint32BE = Buffer3.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) {
2329
- value = +value;
2330
- offset = offset >>> 0;
2331
- if (!noAssert)
2332
- checkInt(this, value, offset, 4, 4294967295, 0);
2333
- this[offset] = value >>> 24;
2334
- this[offset + 1] = value >>> 16;
2335
- this[offset + 2] = value >>> 8;
2336
- this[offset + 3] = value & 255;
2337
- return offset + 4;
2338
- };
2339
- Buffer3.prototype.writeIntLE = function writeIntLE(value, offset, byteLength3, noAssert) {
2340
- value = +value;
2341
- offset = offset >>> 0;
2342
- if (!noAssert) {
2343
- var limit = Math.pow(2, 8 * byteLength3 - 1);
2344
- checkInt(this, value, offset, byteLength3, limit - 1, -limit);
2345
- }
2346
- var i = 0;
2347
- var mul = 1;
2348
- var sub = 0;
2349
- this[offset] = value & 255;
2350
- while (++i < byteLength3 && (mul *= 256)) {
2351
- if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
2352
- sub = 1;
2353
- }
2354
- this[offset + i] = (value / mul >> 0) - sub & 255;
2355
- }
2356
- return offset + byteLength3;
2357
- };
2358
- Buffer3.prototype.writeIntBE = function writeIntBE(value, offset, byteLength3, noAssert) {
2359
- value = +value;
2360
- offset = offset >>> 0;
2361
- if (!noAssert) {
2362
- var limit = Math.pow(2, 8 * byteLength3 - 1);
2363
- checkInt(this, value, offset, byteLength3, limit - 1, -limit);
2364
- }
2365
- var i = byteLength3 - 1;
2366
- var mul = 1;
2367
- var sub = 0;
2368
- this[offset + i] = value & 255;
2369
- while (--i >= 0 && (mul *= 256)) {
2370
- if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
2371
- sub = 1;
2372
- }
2373
- this[offset + i] = (value / mul >> 0) - sub & 255;
2374
- }
2375
- return offset + byteLength3;
2376
- };
2377
- Buffer3.prototype.writeInt8 = function writeInt8(value, offset, noAssert) {
2378
- value = +value;
2379
- offset = offset >>> 0;
2380
- if (!noAssert)
2381
- checkInt(this, value, offset, 1, 127, -128);
2382
- if (value < 0)
2383
- value = 255 + value + 1;
2384
- this[offset] = value & 255;
2385
- return offset + 1;
2386
- };
2387
- Buffer3.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) {
2388
- value = +value;
2389
- offset = offset >>> 0;
2390
- if (!noAssert)
2391
- checkInt(this, value, offset, 2, 32767, -32768);
2392
- this[offset] = value & 255;
2393
- this[offset + 1] = value >>> 8;
2394
- return offset + 2;
2395
- };
2396
- Buffer3.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) {
2397
- value = +value;
2398
- offset = offset >>> 0;
2399
- if (!noAssert)
2400
- checkInt(this, value, offset, 2, 32767, -32768);
2401
- this[offset] = value >>> 8;
2402
- this[offset + 1] = value & 255;
2403
- return offset + 2;
2404
- };
2405
- Buffer3.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) {
2406
- value = +value;
2407
- offset = offset >>> 0;
2408
- if (!noAssert)
2409
- checkInt(this, value, offset, 4, 2147483647, -2147483648);
2410
- this[offset] = value & 255;
2411
- this[offset + 1] = value >>> 8;
2412
- this[offset + 2] = value >>> 16;
2413
- this[offset + 3] = value >>> 24;
2414
- return offset + 4;
2415
- };
2416
- Buffer3.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) {
2417
- value = +value;
2418
- offset = offset >>> 0;
2419
- if (!noAssert)
2420
- checkInt(this, value, offset, 4, 2147483647, -2147483648);
2421
- if (value < 0)
2422
- value = 4294967295 + value + 1;
2423
- this[offset] = value >>> 24;
2424
- this[offset + 1] = value >>> 16;
2425
- this[offset + 2] = value >>> 8;
2426
- this[offset + 3] = value & 255;
2427
- return offset + 4;
2428
- };
2429
- function checkIEEE754(buf, value, offset, ext, max, min) {
2430
- if (offset + ext > buf.length)
2431
- throw new RangeError("Index out of range");
2432
- if (offset < 0)
2433
- throw new RangeError("Index out of range");
2434
- }
2435
- function writeFloat(buf, value, offset, littleEndian, noAssert) {
2436
- value = +value;
2437
- offset = offset >>> 0;
2438
- if (!noAssert) {
2439
- checkIEEE754(buf, value, offset, 4);
2440
- }
2441
- ieee754$1.write(buf, value, offset, littleEndian, 23, 4);
2442
- return offset + 4;
2443
- }
2444
- Buffer3.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) {
2445
- return writeFloat(this, value, offset, true, noAssert);
2446
- };
2447
- Buffer3.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) {
2448
- return writeFloat(this, value, offset, false, noAssert);
2449
- };
2450
- function writeDouble(buf, value, offset, littleEndian, noAssert) {
2451
- value = +value;
2452
- offset = offset >>> 0;
2453
- if (!noAssert) {
2454
- checkIEEE754(buf, value, offset, 8);
2455
- }
2456
- ieee754$1.write(buf, value, offset, littleEndian, 52, 8);
2457
- return offset + 8;
2458
- }
2459
- Buffer3.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) {
2460
- return writeDouble(this, value, offset, true, noAssert);
2461
- };
2462
- Buffer3.prototype.writeDoubleBE = function writeDoubleBE(value, offset, noAssert) {
2463
- return writeDouble(this, value, offset, false, noAssert);
2464
- };
2465
- Buffer3.prototype.copy = function copy(target, targetStart, start, end) {
2466
- if (!Buffer3.isBuffer(target))
2467
- throw new TypeError("argument should be a Buffer");
2468
- if (!start)
2469
- start = 0;
2470
- if (!end && end !== 0)
2471
- end = this.length;
2472
- if (targetStart >= target.length)
2473
- targetStart = target.length;
2474
- if (!targetStart)
2475
- targetStart = 0;
2476
- if (end > 0 && end < start)
2477
- end = start;
2478
- if (end === start)
2479
- return 0;
2480
- if (target.length === 0 || this.length === 0)
2481
- return 0;
2482
- if (targetStart < 0) {
2483
- throw new RangeError("targetStart out of bounds");
2484
- }
2485
- if (start < 0 || start >= this.length)
2486
- throw new RangeError("Index out of range");
2487
- if (end < 0)
2488
- throw new RangeError("sourceEnd out of bounds");
2489
- if (end > this.length)
2490
- end = this.length;
2491
- if (target.length - targetStart < end - start) {
2492
- end = target.length - targetStart + start;
2493
- }
2494
- var len = end - start;
2495
- if (this === target && typeof Uint8Array.prototype.copyWithin === "function") {
2496
- this.copyWithin(targetStart, start, end);
2497
- } else {
2498
- Uint8Array.prototype.set.call(
2499
- target,
2500
- this.subarray(start, end),
2501
- targetStart
2502
- );
2503
- }
2504
- return len;
2505
- };
2506
- Buffer3.prototype.fill = function fill(val, start, end, encoding) {
2507
- if (typeof val === "string") {
2508
- if (typeof start === "string") {
2509
- encoding = start;
2510
- start = 0;
2511
- end = this.length;
2512
- } else if (typeof end === "string") {
2513
- encoding = end;
2514
- end = this.length;
2515
- }
2516
- if (encoding !== void 0 && typeof encoding !== "string") {
2517
- throw new TypeError("encoding must be a string");
2518
- }
2519
- if (typeof encoding === "string" && !Buffer3.isEncoding(encoding)) {
2520
- throw new TypeError("Unknown encoding: " + encoding);
2521
- }
2522
- if (val.length === 1) {
2523
- var code2 = val.charCodeAt(0);
2524
- if (encoding === "utf8" && code2 < 128 || encoding === "latin1") {
2525
- val = code2;
2526
- }
2527
- }
2528
- } else if (typeof val === "number") {
2529
- val = val & 255;
2530
- } else if (typeof val === "boolean") {
2531
- val = Number(val);
2532
- }
2533
- if (start < 0 || this.length < start || this.length < end) {
2534
- throw new RangeError("Out of range index");
2535
- }
2536
- if (end <= start) {
2537
- return this;
2538
- }
2539
- start = start >>> 0;
2540
- end = end === void 0 ? this.length : end >>> 0;
2541
- if (!val)
2542
- val = 0;
2543
- var i;
2544
- if (typeof val === "number") {
2545
- for (i = start; i < end; ++i) {
2546
- this[i] = val;
2547
- }
2548
- } else {
2549
- var bytes = Buffer3.isBuffer(val) ? val : Buffer3.from(val, encoding);
2550
- var len = bytes.length;
2551
- if (len === 0) {
2552
- throw new TypeError('The value "' + val + '" is invalid for argument "value"');
2553
- }
2554
- for (i = 0; i < end - start; ++i) {
2555
- this[i + start] = bytes[i % len];
2556
- }
2557
- }
2558
- return this;
2559
- };
2560
- var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
2561
- function base64clean(str) {
2562
- str = str.split("=")[0];
2563
- str = str.trim().replace(INVALID_BASE64_RE, "");
2564
- if (str.length < 2)
2565
- return "";
2566
- while (str.length % 4 !== 0) {
2567
- str = str + "=";
2568
- }
2569
- return str;
2570
- }
2571
- function utf8ToBytes(string, units) {
2572
- units = units || Infinity;
2573
- var codePoint;
2574
- var length = string.length;
2575
- var leadSurrogate = null;
2576
- var bytes = [];
2577
- for (var i = 0; i < length; ++i) {
2578
- codePoint = string.charCodeAt(i);
2579
- if (codePoint > 55295 && codePoint < 57344) {
2580
- if (!leadSurrogate) {
2581
- if (codePoint > 56319) {
2582
- if ((units -= 3) > -1)
2583
- bytes.push(239, 191, 189);
2584
- continue;
2585
- } else if (i + 1 === length) {
2586
- if ((units -= 3) > -1)
2587
- bytes.push(239, 191, 189);
2588
- continue;
2589
- }
2590
- leadSurrogate = codePoint;
2591
- continue;
2592
- }
2593
- if (codePoint < 56320) {
2594
- if ((units -= 3) > -1)
2595
- bytes.push(239, 191, 189);
2596
- leadSurrogate = codePoint;
2597
- continue;
2598
- }
2599
- codePoint = (leadSurrogate - 55296 << 10 | codePoint - 56320) + 65536;
2600
- } else if (leadSurrogate) {
2601
- if ((units -= 3) > -1)
2602
- bytes.push(239, 191, 189);
2603
- }
2604
- leadSurrogate = null;
2605
- if (codePoint < 128) {
2606
- if ((units -= 1) < 0)
2607
- break;
2608
- bytes.push(codePoint);
2609
- } else if (codePoint < 2048) {
2610
- if ((units -= 2) < 0)
2611
- break;
2612
- bytes.push(
2613
- codePoint >> 6 | 192,
2614
- codePoint & 63 | 128
2615
- );
2616
- } else if (codePoint < 65536) {
2617
- if ((units -= 3) < 0)
2618
- break;
2619
- bytes.push(
2620
- codePoint >> 12 | 224,
2621
- codePoint >> 6 & 63 | 128,
2622
- codePoint & 63 | 128
2623
- );
2624
- } else if (codePoint < 1114112) {
2625
- if ((units -= 4) < 0)
2626
- break;
2627
- bytes.push(
2628
- codePoint >> 18 | 240,
2629
- codePoint >> 12 & 63 | 128,
2630
- codePoint >> 6 & 63 | 128,
2631
- codePoint & 63 | 128
2632
- );
2633
- } else {
2634
- throw new Error("Invalid code point");
2635
- }
2636
- }
2637
- return bytes;
2638
- }
2639
- function asciiToBytes(str) {
2640
- var byteArray = [];
2641
- for (var i = 0; i < str.length; ++i) {
2642
- byteArray.push(str.charCodeAt(i) & 255);
2643
- }
2644
- return byteArray;
2645
- }
2646
- function utf16leToBytes(str, units) {
2647
- var c, hi, lo;
2648
- var byteArray = [];
2649
- for (var i = 0; i < str.length; ++i) {
2650
- if ((units -= 2) < 0)
2651
- break;
2652
- c = str.charCodeAt(i);
2653
- hi = c >> 8;
2654
- lo = c % 256;
2655
- byteArray.push(lo);
2656
- byteArray.push(hi);
2657
- }
2658
- return byteArray;
2659
- }
2660
- function base64ToBytes(str) {
2661
- return base64.toByteArray(base64clean(str));
2662
- }
2663
- function blitBuffer(src, dst, offset, length) {
2664
- for (var i = 0; i < length; ++i) {
2665
- if (i + offset >= dst.length || i >= src.length)
2666
- break;
2667
- dst[i + offset] = src[i];
2668
- }
2669
- return i;
2670
- }
2671
- function isInstance(obj, type) {
2672
- return obj instanceof type || obj != null && obj.constructor != null && obj.constructor.name != null && obj.constructor.name === type.name;
2673
- }
2674
- function numberIsNaN(obj) {
2675
- return obj !== obj;
2676
- }
2677
- var hexSliceLookupTable = function() {
2678
- var alphabet = "0123456789abcdef";
2679
- var table = new Array(256);
2680
- for (var i = 0; i < 16; ++i) {
2681
- var i16 = i * 16;
2682
- for (var j = 0; j < 16; ++j) {
2683
- table[i16 + j] = alphabet[i] + alphabet[j];
2684
- }
2685
- }
2686
- return table;
2687
- }();
2688
- })(buffer);
2689
- /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
2690
- (function(module, exports) {
2691
- var buffer$1 = buffer;
2692
- var Buffer3 = buffer$1.Buffer;
2693
- function copyProps(src, dst) {
2694
- for (var key in src) {
2695
- dst[key] = src[key];
2696
- }
2697
- }
2698
- if (Buffer3.from && Buffer3.alloc && Buffer3.allocUnsafe && Buffer3.allocUnsafeSlow) {
2699
- module.exports = buffer$1;
2700
- } else {
2701
- copyProps(buffer$1, exports);
2702
- exports.Buffer = SafeBuffer;
2703
- }
2704
- function SafeBuffer(arg, encodingOrOffset, length) {
2705
- return Buffer3(arg, encodingOrOffset, length);
2706
- }
2707
- SafeBuffer.prototype = Object.create(Buffer3.prototype);
2708
- copyProps(Buffer3, SafeBuffer);
2709
- SafeBuffer.from = function(arg, encodingOrOffset, length) {
2710
- if (typeof arg === "number") {
2711
- throw new TypeError("Argument must not be a number");
2712
- }
2713
- return Buffer3(arg, encodingOrOffset, length);
2714
- };
2715
- SafeBuffer.alloc = function(size, fill, encoding) {
2716
- if (typeof size !== "number") {
2717
- throw new TypeError("Argument must be a number");
2718
- }
2719
- var buf = Buffer3(size);
2720
- if (fill !== void 0) {
2721
- if (typeof encoding === "string") {
2722
- buf.fill(fill, encoding);
2723
- } else {
2724
- buf.fill(fill);
1154
+ continue;
1155
+ const currentType = __classPrivateFieldGet(this, _Mime_extensionToType, "f").get(extension);
1156
+ if (currentType && currentType != type && !force) {
1157
+ throw new Error(`"${type} -> ${extension}" conflicts with "${currentType} -> ${extension}". Pass \`force=true\` to override this definition.`);
1158
+ }
1159
+ __classPrivateFieldGet(this, _Mime_extensionToType, "f").set(extension, type);
2725
1160
  }
2726
- } else {
2727
- buf.fill(0);
2728
- }
2729
- return buf;
2730
- };
2731
- SafeBuffer.allocUnsafe = function(size) {
2732
- if (typeof size !== "number") {
2733
- throw new TypeError("Argument must be a number");
2734
- }
2735
- return Buffer3(size);
2736
- };
2737
- SafeBuffer.allocUnsafeSlow = function(size) {
2738
- if (typeof size !== "number") {
2739
- throw new TypeError("Argument must be a number");
2740
1161
  }
2741
- return buffer$1.SlowBuffer(size);
2742
- };
2743
- })(safeBuffer, safeBuffer.exports);
2744
- var safeBufferExports = safeBuffer.exports;
2745
- var Buffer$2 = safeBufferExports.Buffer;
2746
- function Hash$2(blockSize, finalSize) {
2747
- this._block = Buffer$2.alloc(blockSize);
2748
- this._finalSize = finalSize;
2749
- this._blockSize = blockSize;
2750
- this._len = 0;
2751
- }
2752
- Hash$2.prototype.update = function(data, enc) {
2753
- if (typeof data === "string") {
2754
- enc = enc || "utf8";
2755
- data = Buffer$2.from(data, enc);
1162
+ return this;
2756
1163
  }
2757
- var block = this._block;
2758
- var blockSize = this._blockSize;
2759
- var length = data.length;
2760
- var accum = this._len;
2761
- for (var offset = 0; offset < length; ) {
2762
- var assigned = accum % blockSize;
2763
- var remainder = Math.min(length - offset, blockSize - assigned);
2764
- for (var i = 0; i < remainder; i++) {
2765
- block[assigned + i] = data[offset + i];
2766
- }
2767
- accum += remainder;
2768
- offset += remainder;
2769
- if (accum % blockSize === 0) {
2770
- this._update(block);
2771
- }
1164
+ getType(path) {
1165
+ if (typeof path !== "string")
1166
+ return null;
1167
+ const last = path.replace(/^.*[/\\]/, "").toLowerCase();
1168
+ const ext = last.replace(/^.*\./, "").toLowerCase();
1169
+ const hasPath = last.length < path.length;
1170
+ const hasDot = ext.length < last.length - 1;
1171
+ if (!hasDot && hasPath)
1172
+ return null;
1173
+ return __classPrivateFieldGet(this, _Mime_extensionToType, "f").get(ext) ?? null;
2772
1174
  }
2773
- this._len += length;
2774
- return this;
2775
- };
2776
- Hash$2.prototype.digest = function(enc) {
2777
- var rem = this._len % this._blockSize;
2778
- this._block[rem] = 128;
2779
- this._block.fill(0, rem + 1);
2780
- if (rem >= this._finalSize) {
2781
- this._update(this._block);
2782
- this._block.fill(0);
1175
+ getExtension(type) {
1176
+ var _a;
1177
+ if (typeof type !== "string")
1178
+ return null;
1179
+ type = (_a = type == null ? void 0 : type.split) == null ? void 0 : _a.call(type, ";")[0];
1180
+ return (type && __classPrivateFieldGet(this, _Mime_typeToExtension, "f").get(type.trim().toLowerCase())) ?? null;
2783
1181
  }
2784
- var bits = this._len * 8;
2785
- if (bits <= 4294967295) {
2786
- this._block.writeUInt32BE(bits, this._blockSize - 4);
2787
- } else {
2788
- var lowBits = (bits & 4294967295) >>> 0;
2789
- var highBits = (bits - lowBits) / 4294967296;
2790
- this._block.writeUInt32BE(highBits, this._blockSize - 8);
2791
- this._block.writeUInt32BE(lowBits, this._blockSize - 4);
1182
+ getAllExtensions(type) {
1183
+ if (typeof type !== "string")
1184
+ return null;
1185
+ return __classPrivateFieldGet(this, _Mime_typeToExtensions, "f").get(type.toLowerCase()) ?? null;
2792
1186
  }
2793
- this._update(this._block);
2794
- var hash2 = this._hash();
2795
- return enc ? hash2.toString(enc) : hash2;
2796
- };
2797
- Hash$2.prototype._update = function() {
2798
- throw new Error("_update must be implemented by subclass");
2799
- };
2800
- var hash$1 = Hash$2;
2801
- var inherits$1 = inherits_browserExports;
2802
- var Hash$1 = hash$1;
2803
- var Buffer$1 = safeBufferExports.Buffer;
2804
- var K$1 = [
2805
- 1518500249,
2806
- 1859775393,
2807
- 2400959708 | 0,
2808
- 3395469782 | 0
2809
- ];
2810
- var W$1 = new Array(80);
2811
- function Sha1() {
2812
- this.init();
2813
- this._w = W$1;
2814
- Hash$1.call(this, 64, 56);
2815
- }
2816
- inherits$1(Sha1, Hash$1);
2817
- Sha1.prototype.init = function() {
2818
- this._a = 1732584193;
2819
- this._b = 4023233417;
2820
- this._c = 2562383102;
2821
- this._d = 271733878;
2822
- this._e = 3285377520;
2823
- return this;
2824
- };
2825
- function rotl1(num) {
2826
- return num << 1 | num >>> 31;
2827
- }
2828
- function rotl5(num) {
2829
- return num << 5 | num >>> 27;
2830
- }
2831
- function rotl30(num) {
2832
- return num << 30 | num >>> 2;
2833
- }
2834
- function ft(s, b, c, d) {
2835
- if (s === 0)
2836
- return b & c | ~b & d;
2837
- if (s === 2)
2838
- return b & c | b & d | c & d;
2839
- return b ^ c ^ d;
2840
- }
2841
- Sha1.prototype._update = function(M) {
2842
- var W2 = this._w;
2843
- var a = this._a | 0;
2844
- var b = this._b | 0;
2845
- var c = this._c | 0;
2846
- var d = this._d | 0;
2847
- var e = this._e | 0;
2848
- for (var i = 0; i < 16; ++i)
2849
- W2[i] = M.readInt32BE(i * 4);
2850
- for (; i < 80; ++i)
2851
- W2[i] = rotl1(W2[i - 3] ^ W2[i - 8] ^ W2[i - 14] ^ W2[i - 16]);
2852
- for (var j = 0; j < 80; ++j) {
2853
- var s = ~~(j / 20);
2854
- var t = rotl5(a) + ft(s, b, c, d) + e + W2[j] + K$1[s] | 0;
2855
- e = d;
2856
- d = c;
2857
- c = rotl30(b);
2858
- b = a;
2859
- a = t;
1187
+ _freeze() {
1188
+ this.define = () => {
1189
+ throw new Error("define() not allowed for built-in Mime objects. See https://github.com/broofa/mime/blob/main/README.md#custom-mime-instances");
1190
+ };
1191
+ Object.freeze(this);
1192
+ for (const extensions of __classPrivateFieldGet(this, _Mime_typeToExtensions, "f").values()) {
1193
+ Object.freeze(extensions);
1194
+ }
1195
+ return this;
2860
1196
  }
2861
- this._a = a + this._a | 0;
2862
- this._b = b + this._b | 0;
2863
- this._c = c + this._c | 0;
2864
- this._d = d + this._d | 0;
2865
- this._e = e + this._e | 0;
2866
- };
2867
- Sha1.prototype._hash = function() {
2868
- var H = Buffer$1.allocUnsafe(20);
2869
- H.writeInt32BE(this._a | 0, 0);
2870
- H.writeInt32BE(this._b | 0, 4);
2871
- H.writeInt32BE(this._c | 0, 8);
2872
- H.writeInt32BE(this._d | 0, 12);
2873
- H.writeInt32BE(this._e | 0, 16);
2874
- return H;
2875
- };
2876
- var sha1 = Sha1;
2877
- const Sha1$1 = /* @__PURE__ */ getDefaultExportFromCjs(sha1);
2878
- var inherits = inherits_browserExports;
2879
- var Hash = hash$1;
2880
- var Buffer2 = safeBufferExports.Buffer;
2881
- var K = [
2882
- 1116352408,
2883
- 1899447441,
2884
- 3049323471,
2885
- 3921009573,
2886
- 961987163,
2887
- 1508970993,
2888
- 2453635748,
2889
- 2870763221,
2890
- 3624381080,
2891
- 310598401,
2892
- 607225278,
2893
- 1426881987,
2894
- 1925078388,
2895
- 2162078206,
2896
- 2614888103,
2897
- 3248222580,
2898
- 3835390401,
2899
- 4022224774,
2900
- 264347078,
2901
- 604807628,
2902
- 770255983,
2903
- 1249150122,
2904
- 1555081692,
2905
- 1996064986,
2906
- 2554220882,
2907
- 2821834349,
2908
- 2952996808,
2909
- 3210313671,
2910
- 3336571891,
2911
- 3584528711,
2912
- 113926993,
2913
- 338241895,
2914
- 666307205,
2915
- 773529912,
2916
- 1294757372,
2917
- 1396182291,
2918
- 1695183700,
2919
- 1986661051,
2920
- 2177026350,
2921
- 2456956037,
2922
- 2730485921,
2923
- 2820302411,
2924
- 3259730800,
2925
- 3345764771,
2926
- 3516065817,
2927
- 3600352804,
2928
- 4094571909,
2929
- 275423344,
2930
- 430227734,
2931
- 506948616,
2932
- 659060556,
2933
- 883997877,
2934
- 958139571,
2935
- 1322822218,
2936
- 1537002063,
2937
- 1747873779,
2938
- 1955562222,
2939
- 2024104815,
2940
- 2227730452,
2941
- 2361852424,
2942
- 2428436474,
2943
- 2756734187,
2944
- 3204031479,
2945
- 3329325298
2946
- ];
2947
- var W = new Array(64);
2948
- function Sha256() {
2949
- this.init();
2950
- this._w = W;
2951
- Hash.call(this, 64, 56);
2952
- }
2953
- inherits(Sha256, Hash);
2954
- Sha256.prototype.init = function() {
2955
- this._a = 1779033703;
2956
- this._b = 3144134277;
2957
- this._c = 1013904242;
2958
- this._d = 2773480762;
2959
- this._e = 1359893119;
2960
- this._f = 2600822924;
2961
- this._g = 528734635;
2962
- this._h = 1541459225;
2963
- return this;
2964
- };
2965
- function ch(x, y, z2) {
2966
- return z2 ^ x & (y ^ z2);
2967
- }
2968
- function maj(x, y, z2) {
2969
- return x & y | z2 & (x | y);
2970
- }
2971
- function sigma0(x) {
2972
- return (x >>> 2 | x << 30) ^ (x >>> 13 | x << 19) ^ (x >>> 22 | x << 10);
2973
- }
2974
- function sigma1(x) {
2975
- return (x >>> 6 | x << 26) ^ (x >>> 11 | x << 21) ^ (x >>> 25 | x << 7);
2976
- }
2977
- function gamma0(x) {
2978
- return (x >>> 7 | x << 25) ^ (x >>> 18 | x << 14) ^ x >>> 3;
2979
- }
2980
- function gamma1(x) {
2981
- return (x >>> 17 | x << 15) ^ (x >>> 19 | x << 13) ^ x >>> 10;
2982
- }
2983
- Sha256.prototype._update = function(M) {
2984
- var W2 = this._w;
2985
- var a = this._a | 0;
2986
- var b = this._b | 0;
2987
- var c = this._c | 0;
2988
- var d = this._d | 0;
2989
- var e = this._e | 0;
2990
- var f = this._f | 0;
2991
- var g = this._g | 0;
2992
- var h = this._h | 0;
2993
- for (var i = 0; i < 16; ++i)
2994
- W2[i] = M.readInt32BE(i * 4);
2995
- for (; i < 64; ++i)
2996
- W2[i] = gamma1(W2[i - 2]) + W2[i - 7] + gamma0(W2[i - 15]) + W2[i - 16] | 0;
2997
- for (var j = 0; j < 64; ++j) {
2998
- var T1 = h + sigma1(e) + ch(e, f, g) + K[j] + W2[j] | 0;
2999
- var T2 = sigma0(a) + maj(a, b, c) | 0;
3000
- h = g;
3001
- g = f;
3002
- f = e;
3003
- e = d + T1 | 0;
3004
- d = c;
3005
- c = b;
3006
- b = a;
3007
- a = T1 + T2 | 0;
1197
+ _getTestState() {
1198
+ return {
1199
+ types: __classPrivateFieldGet(this, _Mime_extensionToType, "f"),
1200
+ extensions: __classPrivateFieldGet(this, _Mime_typeToExtension, "f")
1201
+ };
3008
1202
  }
3009
- this._a = a + this._a | 0;
3010
- this._b = b + this._b | 0;
3011
- this._c = c + this._c | 0;
3012
- this._d = d + this._d | 0;
3013
- this._e = e + this._e | 0;
3014
- this._f = f + this._f | 0;
3015
- this._g = g + this._g | 0;
3016
- this._h = h + this._h | 0;
3017
- };
3018
- Sha256.prototype._hash = function() {
3019
- var H = Buffer2.allocUnsafe(32);
3020
- H.writeInt32BE(this._a, 0);
3021
- H.writeInt32BE(this._b, 4);
3022
- H.writeInt32BE(this._c, 8);
3023
- H.writeInt32BE(this._d, 12);
3024
- H.writeInt32BE(this._e, 16);
3025
- H.writeInt32BE(this._f, 20);
3026
- H.writeInt32BE(this._g, 24);
3027
- H.writeInt32BE(this._h, 28);
3028
- return H;
3029
- };
3030
- var sha256 = Sha256;
3031
- const Sha256$1 = /* @__PURE__ */ getDefaultExportFromCjs(sha256);
3032
- const FileSystemError = new Error("File system not available.");
3033
- function writeFile(path, name, stream) {
3034
- throw FileSystemError;
3035
- }
3036
- function readFile(path) {
3037
- throw FileSystemError;
3038
1203
  }
3039
- function fetchFile(url) {
3040
- throw FileSystemError;
3041
- }
3042
- const getFile = async (file) => {
3043
- return readFile();
3044
- };
3045
- const hashAlgorithms = {
3046
- sha1: Sha1$1,
3047
- sha256: Sha256$1
3048
- };
3049
- const hash = (data, algorithm = "sha1") => {
3050
- if (!["sha1", "sha256"].includes(algorithm)) {
3051
- throw new Error("Hashing algorithm not supported: Available: sha1, sha256");
3052
- }
3053
- const Algorithm = hashAlgorithms[algorithm];
3054
- const sha = new Algorithm();
3055
- return sha.update(data).digest("base64");
3056
- };
1204
+ _Mime_extensionToType = /* @__PURE__ */ new WeakMap(), _Mime_typeToExtension = /* @__PURE__ */ new WeakMap(), _Mime_typeToExtensions = /* @__PURE__ */ new WeakMap();
1205
+ const mime = new Mime(types)._freeze();
3057
1206
  function validateOperations(operations) {
3058
1207
  const errors = [];
3059
1208
  const scopes = Object.keys(operations);
@@ -3123,8 +1272,7 @@ function garbageCollect(sortedOperations) {
3123
1272
  function addUndo(sortedOperations) {
3124
1273
  const operationsCopy = [...sortedOperations];
3125
1274
  const latestOperation = operationsCopy[operationsCopy.length - 1];
3126
- if (!latestOperation)
3127
- return operationsCopy;
1275
+ if (!latestOperation) return operationsCopy;
3128
1276
  if (latestOperation.type === "NOOP") {
3129
1277
  operationsCopy.push({
3130
1278
  ...latestOperation,
@@ -3403,6 +1551,13 @@ function filterDocumentOperationsResultingState(documentOperations) {
3403
1551
  {}
3404
1552
  );
3405
1553
  }
1554
+ function diffOperations(clearedOperationsA, clearedOperationsB) {
1555
+ return clearedOperationsA.filter(
1556
+ (operationA) => !clearedOperationsB.some(
1557
+ (operationB) => operationA.index === operationB.index
1558
+ )
1559
+ );
1560
+ }
3406
1561
  const documentHelpers = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
3407
1562
  __proto__: null,
3408
1563
  IntegrityIssueSubType,
@@ -3411,6 +1566,7 @@ const documentHelpers = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.def
3411
1566
  attachBranch,
3412
1567
  checkCleanedOperationsIntegrity,
3413
1568
  checkOperationsIntegrity,
1569
+ diffOperations,
3414
1570
  filterDocumentOperationsResultingState,
3415
1571
  filterDuplicatedOperations,
3416
1572
  garbageCollect,
@@ -3541,9 +1697,9 @@ function getFileAttributes(file) {
3541
1697
  return { extension, fileName };
3542
1698
  }
3543
1699
  async function getRemoteFile(url) {
3544
- const { buffer: buffer2, mimeType = "application/octet-stream" } = await fetchFile();
1700
+ const { buffer, mimeType = "application/octet-stream" } = await fetchFile();
3545
1701
  const attributes = getFileAttributes(url);
3546
- const data = buffer2.toString("base64");
1702
+ const data = buffer.toString("base64");
3547
1703
  return {
3548
1704
  data,
3549
1705
  hash: hash(data),
@@ -3552,12 +1708,147 @@ async function getRemoteFile(url) {
3552
1708
  };
3553
1709
  }
3554
1710
  async function getLocalFile(path) {
3555
- const buffer2 = await getFile();
1711
+ const buffer = await getFile();
3556
1712
  const mimeType = mime.getType(path) || "application/octet-stream";
3557
1713
  const attributes = getFileAttributes(path);
3558
- const data = buffer2.toString("base64");
1714
+ const data = buffer.toString("base64");
3559
1715
  return { data, hash: hash(data), mimeType, ...attributes };
3560
1716
  }
1717
+ function setNameOperation(document, name) {
1718
+ return { ...document, name };
1719
+ }
1720
+ function undoOperation(document, action, skip) {
1721
+ const { scope, input } = action;
1722
+ const defaultResult = {
1723
+ document,
1724
+ action,
1725
+ skip,
1726
+ reuseLastOperationIndex: false
1727
+ };
1728
+ return create(defaultResult, (draft) => {
1729
+ const operations = [...document.operations[scope]];
1730
+ const sortedOperations = sortOperations$1(operations);
1731
+ draft.action = noop(scope);
1732
+ const lastOperation = sortedOperations.at(-1);
1733
+ let nextIndex = (lastOperation == null ? void 0 : lastOperation.index) ?? -1;
1734
+ const isNewNoop = (lastOperation == null ? void 0 : lastOperation.type) !== "NOOP";
1735
+ if (isNewNoop) {
1736
+ nextIndex = nextIndex + 1;
1737
+ } else {
1738
+ draft.reuseLastOperationIndex = true;
1739
+ }
1740
+ const nextOperationHistory = isNewNoop ? [...sortedOperations, { index: nextIndex, skip: 0 }] : sortedOperations;
1741
+ draft.skip = nextSkipNumber(nextOperationHistory);
1742
+ if (lastOperation && draft.skip > lastOperation.skip + 1) {
1743
+ draft.skip = draft.skip + 1;
1744
+ }
1745
+ if (draft.skip < 0) {
1746
+ throw new Error(
1747
+ `Cannot undo: you can't undo more operations than the ones in the scope history`
1748
+ );
1749
+ }
1750
+ });
1751
+ }
1752
+ function redoOperation(document, action, skip) {
1753
+ const { scope, input } = action;
1754
+ const defaultResult = {
1755
+ document,
1756
+ action,
1757
+ skip,
1758
+ reuseLastOperationIndex: false
1759
+ };
1760
+ return create(defaultResult, (draft) => {
1761
+ if (draft.skip > 0) {
1762
+ throw new Error(
1763
+ `Cannot redo: skip value from reducer cannot be used with REDO action`
1764
+ );
1765
+ }
1766
+ if (input > 1) {
1767
+ throw new Error(
1768
+ `Cannot redo: you can only redo one operation at a time`
1769
+ );
1770
+ }
1771
+ if (input < 1) {
1772
+ throw new Error(`Invalid REDO action: invalid redo input value`);
1773
+ }
1774
+ if (draft.document.clipboard.length < 1) {
1775
+ throw new Error(`Cannot redo: no operations in the clipboard`);
1776
+ }
1777
+ const operationIndex = draft.document.clipboard.findLastIndex(
1778
+ (op) => op.scope === scope
1779
+ );
1780
+ if (operationIndex < 0) {
1781
+ throw new Error(
1782
+ `Cannot redo: no operations in clipboard for scope "${scope}"`
1783
+ );
1784
+ }
1785
+ const operation = draft.document.clipboard.splice(operationIndex, 1)[0];
1786
+ draft.action = castDraft({
1787
+ type: operation.type,
1788
+ scope: operation.scope,
1789
+ input: operation.input
1790
+ });
1791
+ });
1792
+ }
1793
+ function pruneOperation(document, action, wrappedReducer) {
1794
+ const { scope } = action;
1795
+ const operations = document.operations[scope];
1796
+ let {
1797
+ input: { start, end }
1798
+ } = action;
1799
+ start = start || 0;
1800
+ end = end || operations.length;
1801
+ const actionsToPrune = operations.slice(start, end);
1802
+ const actionsToKeepStart = operations.slice(0, start);
1803
+ const actionsToKeepEnd = operations.slice(end);
1804
+ const newDocument = replayOperations(
1805
+ document.initialState,
1806
+ {
1807
+ ...document.operations,
1808
+ [scope]: actionsToKeepStart.concat(actionsToPrune)
1809
+ },
1810
+ wrappedReducer
1811
+ );
1812
+ const { name, state: newState } = newDocument;
1813
+ const loadStateIndex = actionsToKeepStart.length;
1814
+ const loadStateTimestamp = actionsToKeepStart.length ? actionsToKeepStart[actionsToKeepStart.length - 1].timestamp : actionsToKeepEnd.length ? actionsToKeepEnd[0].timestamp : (/* @__PURE__ */ new Date()).toISOString();
1815
+ return replayOperations(
1816
+ document.initialState,
1817
+ {
1818
+ ...document.operations,
1819
+ [scope]: [
1820
+ ...actionsToKeepStart,
1821
+ {
1822
+ ...loadState(
1823
+ { name, state: newState },
1824
+ actionsToPrune.length
1825
+ ),
1826
+ timestamp: loadStateTimestamp,
1827
+ index: loadStateIndex,
1828
+ hash: hashDocument({ state: newState }, "global")
1829
+ },
1830
+ ...actionsToKeepEnd.map((action2, index) => ({
1831
+ ...action2,
1832
+ index: loadStateIndex + index + 1
1833
+ }))
1834
+ ]
1835
+ },
1836
+ wrappedReducer
1837
+ );
1838
+ }
1839
+ function loadStateOperation(oldDocument, newDocument) {
1840
+ return {
1841
+ ...oldDocument,
1842
+ name: newDocument.name,
1843
+ state: newDocument.state ?? { global: {}, local: {} }
1844
+ };
1845
+ }
1846
+ const SET_NAME = "SET_NAME";
1847
+ const UNDO = "UNDO";
1848
+ const REDO = "REDO";
1849
+ const PRUNE = "PRUNE";
1850
+ const LOAD_STATE = "LOAD_STATE";
1851
+ const NOOP = "NOOP";
3561
1852
  function getNextRevision(document, action) {
3562
1853
  let latestOperation;
3563
1854
  if ("index" in action) {
@@ -3577,7 +1868,7 @@ function updateHeader(document, action) {
3577
1868
  lastModified: (/* @__PURE__ */ new Date()).toISOString()
3578
1869
  };
3579
1870
  }
3580
- function updateOperations(document, action, skip = 0) {
1871
+ function updateOperations(document, action, skip = 0, reuseLastOperationIndex = false) {
3581
1872
  if ([UNDO, REDO, PRUNE].includes(action.type)) {
3582
1873
  return document;
3583
1874
  }
@@ -3585,7 +1876,8 @@ function updateOperations(document, action, skip = 0) {
3585
1876
  const operations = document.operations[scope].slice();
3586
1877
  let operationId;
3587
1878
  const latestOperation = operations.at(-1);
3588
- let nextIndex = ((latestOperation == null ? void 0 : latestOperation.index) ?? -1) + 1;
1879
+ const lastOperationIndex = (latestOperation == null ? void 0 : latestOperation.index) ?? -1;
1880
+ let nextIndex = reuseLastOperationIndex ? lastOperationIndex : lastOperationIndex + 1;
3589
1881
  if ("index" in action) {
3590
1882
  if (action.index - skip > nextIndex) {
3591
1883
  throw new Error(
@@ -3595,7 +1887,7 @@ function updateOperations(document, action, skip = 0) {
3595
1887
  nextIndex = action.index;
3596
1888
  operationId = action.id;
3597
1889
  } else {
3598
- operationId = v4();
1890
+ operationId = "id" in action ? action.id : v4();
3599
1891
  }
3600
1892
  operations.push({
3601
1893
  ...action,
@@ -3612,8 +1904,13 @@ function updateOperations(document, action, skip = 0) {
3612
1904
  operations: { ...document.operations, [scope]: operations }
3613
1905
  };
3614
1906
  }
3615
- function updateDocument(document, action, skip = 0) {
3616
- let newDocument = updateOperations(document, action, skip);
1907
+ function updateDocument(document, action, skip = 0, reuseLastOperationIndex = false) {
1908
+ let newDocument = updateOperations(
1909
+ document,
1910
+ action,
1911
+ skip,
1912
+ reuseLastOperationIndex
1913
+ );
3617
1914
  newDocument = updateHeader(newDocument, action);
3618
1915
  return newDocument;
3619
1916
  }
@@ -3637,14 +1934,13 @@ function processUndoRedo(document, action, skip) {
3637
1934
  case REDO:
3638
1935
  return redoOperation(document, action, skip);
3639
1936
  default:
3640
- return { document, action, skip };
1937
+ return { document, action, skip, reuseLastOperationIndex: false };
3641
1938
  }
3642
1939
  }
3643
1940
  function processSkipOperation(document, action, customReducer, skipValue, reuseOperationResultingState = false, resultingStateParser = parseResultingState) {
3644
1941
  const scope = action.scope;
3645
1942
  const latestOperation = document.operations[scope].at(-1);
3646
- if (!latestOperation)
3647
- return document;
1943
+ if (!latestOperation) return document;
3648
1944
  const documentOperations = garbageCollectDocumentOperations(
3649
1945
  {
3650
1946
  ...document.operations,
@@ -3688,6 +1984,37 @@ function processSkipOperation(document, action, customReducer, skipValue, reuseO
3688
1984
  })
3689
1985
  };
3690
1986
  }
1987
+ function processUndoOperation(document, scope, customReducer, reuseOperationResultingState = false, resultingStateParser = parseResultingState) {
1988
+ const operations = [...document.operations[scope]];
1989
+ const sortedOperations = sortOperations$1(operations);
1990
+ sortedOperations.pop();
1991
+ const documentOperations = garbageCollectDocumentOperations(
1992
+ { ...document.operations }
1993
+ );
1994
+ const clearedOperations = [...documentOperations[scope]];
1995
+ const diff = diffOperations(
1996
+ garbageCollect(sortedOperations),
1997
+ clearedOperations
1998
+ );
1999
+ const doc = replayOperations(
2000
+ document.initialState,
2001
+ documentOperations,
2002
+ customReducer,
2003
+ void 0,
2004
+ void 0,
2005
+ void 0,
2006
+ void 0,
2007
+ {
2008
+ reuseHash: true,
2009
+ reuseOperationResultingState,
2010
+ operationResultingStateParser: resultingStateParser
2011
+ }
2012
+ );
2013
+ const clipboard = sortOperations$1(
2014
+ [...document.clipboard, ...diff].filter((op) => op.type !== "NOOP")
2015
+ ).reverse();
2016
+ return { ...doc, clipboard };
2017
+ }
3691
2018
  function baseReducer(document, action, customReducer, dispatch, options = {}) {
3692
2019
  const {
3693
2020
  skip,
@@ -3696,14 +2023,46 @@ function baseReducer(document, action, customReducer, dispatch, options = {}) {
3696
2023
  reuseOperationResultingState = false,
3697
2024
  operationResultingStateParser
3698
2025
  } = options;
3699
- const _action = { ...action };
3700
- const skipValue = skip || 0;
2026
+ let _action = { ...action };
2027
+ let skipValue = skip || 0;
3701
2028
  let newDocument = { ...document };
2029
+ let reuseLastOperationIndex = false;
3702
2030
  const shouldProcessSkipOperation = !ignoreSkipOperations && (skipValue > 0 || "index" in _action && _action.skip > 0);
2031
+ if (isUndoRedo(_action)) {
2032
+ const {
2033
+ skip: calculatedSkip,
2034
+ action: transformedAction,
2035
+ document: processedDocument,
2036
+ reuseLastOperationIndex: reuseIndex
2037
+ } = processUndoRedo(document, _action, skipValue);
2038
+ _action = transformedAction;
2039
+ skipValue = calculatedSkip;
2040
+ newDocument = processedDocument;
2041
+ reuseLastOperationIndex = reuseIndex;
2042
+ } else {
2043
+ newDocument = {
2044
+ ...newDocument,
2045
+ clipboard: []
2046
+ };
2047
+ }
3703
2048
  if (isBaseAction(_action)) {
3704
2049
  newDocument = _baseReducer(newDocument, _action, customReducer);
3705
2050
  }
3706
- newDocument = updateDocument(newDocument, _action, skipValue);
2051
+ newDocument = updateDocument(
2052
+ newDocument,
2053
+ _action,
2054
+ skipValue,
2055
+ reuseLastOperationIndex
2056
+ );
2057
+ const isUndoAction = isUndo(action);
2058
+ if (isUndoAction) {
2059
+ const result = processUndoOperation(
2060
+ newDocument,
2061
+ action.scope,
2062
+ customReducer
2063
+ );
2064
+ return result;
2065
+ }
3707
2066
  if (shouldProcessSkipOperation) {
3708
2067
  newDocument = processSkipOperation(
3709
2068
  newDocument,
@@ -3843,6 +2202,9 @@ function isNoopOperation(op) {
3843
2202
  function isUndoRedo(action) {
3844
2203
  return [UNDO, REDO].includes(action.type);
3845
2204
  }
2205
+ function isUndo(action) {
2206
+ return action.type === UNDO;
2207
+ }
3846
2208
  function isBaseAction(action) {
3847
2209
  return [SET_NAME, UNDO, REDO, PRUNE, LOAD_STATE].includes(action.type);
3848
2210
  }
@@ -3938,23 +2300,6 @@ function mapSkippedOperations(operations, skippedHeadOperations) {
3938
2300
  }
3939
2301
  return scopeOpsWithIgnore.reverse();
3940
2302
  }
3941
- function calculateSkipsLeft(operations, currentIndex, skip) {
3942
- const sortedOperations = operations.slice().sort((a, b) => a.skip - b.skip).sort((a, b) => a.index - b.index);
3943
- let skipsLeft = skip;
3944
- let skipsToPerform = 0;
3945
- let lastIndex = currentIndex;
3946
- for (const operation of sortedOperations.reverse()) {
3947
- const distance = lastIndex - operation.index;
3948
- skipsLeft = skipsLeft - distance;
3949
- if (skipsLeft > -1) {
3950
- skipsToPerform++;
3951
- lastIndex = operation.index;
3952
- } else {
3953
- break;
3954
- }
3955
- }
3956
- return skipsToPerform;
3957
- }
3958
2303
  function sortOperations(operations) {
3959
2304
  return Object.values(operations).flatMap((array) => array).sort(
3960
2305
  (a, b) => new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime()
@@ -4320,17 +2665,25 @@ function applyMixins(derivedCtor, constructors) {
4320
2665
  });
4321
2666
  }
4322
2667
  export {
4323
- replayOperations as A,
2668
+ isSameDocument as A,
4324
2669
  BaseDocument as B,
4325
- sortMappedOperations as C,
4326
- sortOperations as D,
4327
- validateOperations as E,
4328
- baseReducer as F,
4329
- mutableBaseReducer as G,
4330
- processUndoRedo as H,
4331
- updateDocument as I,
4332
- updateHeader as J,
4333
- zod as K,
2670
+ isUndo as C,
2671
+ isUndoRedo as D,
2672
+ mapSkippedOperations as E,
2673
+ parseResultingState as F,
2674
+ readOnly as G,
2675
+ replayDocument as H,
2676
+ replayOperations as I,
2677
+ sortMappedOperations as J,
2678
+ sortOperations as K,
2679
+ validateOperations as L,
2680
+ verifyOperationSignature as M,
2681
+ baseReducer as N,
2682
+ mutableBaseReducer as O,
2683
+ processUndoRedo as P,
2684
+ updateDocument as Q,
2685
+ updateHeader as R,
2686
+ zod as S,
4334
2687
  createExtendedState as a,
4335
2688
  createDocument as b,
4336
2689
  createReducer as c,
@@ -4340,22 +2693,22 @@ export {
4340
2693
  applyMixins as g,
4341
2694
  BaseActions as h,
4342
2695
  isBaseAction as i,
4343
- calculateSkipsLeft as j,
4344
- createUnsafeReducer as k,
2696
+ ab2hex as j,
2697
+ buildOperationSignature as k,
4345
2698
  loadFromFile as l,
4346
- createZip as m,
4347
- documentHelpers as n,
4348
- getLocalFile as o,
4349
- getRemoteFile as p,
4350
- hashDocument as q,
4351
- hashKey as r,
2699
+ buildOperationSignatureMessage as m,
2700
+ buildOperationSignatureParams as n,
2701
+ buildSignedOperation as o,
2702
+ createUnsafeReducer as p,
2703
+ createZip as q,
2704
+ documentHelpers as r,
4352
2705
  saveToFile as s,
4353
- isNoopOperation as t,
4354
- isSameDocument as u,
4355
- isUndoRedo as v,
4356
- mapSkippedOperations as w,
4357
- parseResultingState as x,
4358
- readOnly as y,
4359
- replayDocument as z
2706
+ getLocalFile as t,
2707
+ getRemoteFile as u,
2708
+ getUnixTimestamp as v,
2709
+ hashDocument as w,
2710
+ hashKey as x,
2711
+ hex2ab as y,
2712
+ isNoopOperation as z
4360
2713
  };
4361
- //# sourceMappingURL=object-CyAog_F_.js.map
2714
+ //# sourceMappingURL=object-CU5T1DpX.js.map