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