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