ranuts 0.1.0-alpha.11 → 0.1.0-alpha.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/dist/index.d.ts +5 -3
  2. package/dist/index.js +25 -16
  3. package/dist/{mimeType-Clvz2Teb.js → mimeType-eRf1TlBb.js} +4 -9
  4. package/dist/{reactify-C4cesbXi.js → reactify-Z-V9Vblb.js} +3 -8
  5. package/dist/{ml.js → src/ml/index.js} +19 -24
  6. package/dist/src/node/body.d.ts +0 -1
  7. package/dist/src/node/command.d.ts +0 -1
  8. package/dist/src/node/ctx2req.d.ts +0 -1
  9. package/dist/src/node/fs.d.ts +0 -2
  10. package/dist/src/node/index.d.ts +3 -2
  11. package/dist/src/node/index.js +54 -0
  12. package/dist/src/node/paresUrl.d.ts +0 -1
  13. package/dist/src/node/readFile.d.ts +0 -1
  14. package/dist/src/node/server.d.ts +0 -1
  15. package/dist/src/node/stream.d.ts +0 -1
  16. package/dist/src/node/traverse.d.ts +0 -1
  17. package/dist/src/node/watchFile.d.ts +1 -1
  18. package/dist/src/node/websocket.d.ts +2 -6
  19. package/dist/src/node/ws.d.ts +0 -1
  20. package/dist/src/optimize/index.d.ts +3 -3
  21. package/dist/src/react/index.js +4 -0
  22. package/dist/src/utils/behavior.d.ts +1 -1
  23. package/dist/src/utils/bom.d.ts +7 -7
  24. package/dist/src/utils/device.d.ts +9 -3
  25. package/dist/src/utils/dom.d.ts +87 -2
  26. package/dist/src/utils/img.d.ts +1 -1
  27. package/dist/src/utils/index.d.ts +8 -4
  28. package/dist/src/utils/index.js +4021 -0
  29. package/dist/src/utils/number.d.ts +1 -1
  30. package/dist/src/utils/obj.d.ts +10 -3
  31. package/dist/src/utils/storage.d.ts +2 -0
  32. package/dist/src/utils/subscribe.d.ts +34 -4
  33. package/dist/src/utils/totp/sha/common.d.ts +151 -0
  34. package/dist/src/utils/totp/sha/converters.d.ts +88 -0
  35. package/dist/src/utils/totp/sha/custom_types.d.ts +60 -0
  36. package/dist/src/utils/totp/sha/primitives_32.d.ts +98 -0
  37. package/dist/src/utils/totp/sha/primitives_64.d.ts +116 -0
  38. package/dist/src/utils/totp/sha/sha.d.ts +103 -0
  39. package/dist/src/utils/totp/sha/sha1.d.ts +18 -0
  40. package/dist/src/utils/totp/sha/sha256.d.ts +20 -0
  41. package/dist/src/utils/totp/sha/sha3.d.ts +53 -0
  42. package/dist/src/utils/totp/sha/sha512.d.ts +21 -0
  43. package/dist/src/utils/totp/totp.d.ts +23 -0
  44. package/dist/src/utils/visual/application.d.ts +10 -0
  45. package/dist/src/utils/visual/demo/index.d.ts +1 -0
  46. package/dist/src/utils/visual/demo/sankey.d.ts +2 -0
  47. package/dist/src/utils/visual/enums.d.ts +21 -0
  48. package/dist/src/utils/visual/event/boundary.d.ts +22 -0
  49. package/dist/src/utils/visual/event/event.d.ts +14 -0
  50. package/dist/src/utils/visual/event/index.d.ts +3 -0
  51. package/dist/src/utils/visual/event/types.d.ts +32 -0
  52. package/dist/src/utils/visual/graphics/graphics.d.ts +19 -0
  53. package/dist/src/utils/visual/graphics/graphicsData.d.ts +10 -0
  54. package/dist/src/utils/visual/graphics/graphicsGeometry.d.ts +10 -0
  55. package/dist/src/utils/visual/graphics/index.d.ts +3 -0
  56. package/dist/src/utils/visual/index.d.ts +4 -0
  57. package/dist/src/utils/visual/math/bezier.d.ts +2 -0
  58. package/dist/src/utils/visual/math/enums.d.ts +2 -0
  59. package/dist/src/utils/visual/math/index.d.ts +4 -0
  60. package/dist/src/utils/visual/math/matrix.d.ts +32 -0
  61. package/dist/src/utils/visual/math/transform.d.ts +27 -0
  62. package/dist/src/utils/visual/render/canvasRenderer.d.ts +9 -0
  63. package/dist/src/utils/visual/render/index.d.ts +3 -0
  64. package/dist/src/utils/visual/render/render.d.ts +10 -0
  65. package/dist/src/utils/visual/render/webGlRenderer.d.ts +7 -0
  66. package/dist/src/utils/visual/shape/circle.d.ts +11 -0
  67. package/dist/src/utils/visual/shape/ellipse.d.ts +12 -0
  68. package/dist/src/utils/visual/shape/index.d.ts +5 -0
  69. package/dist/src/utils/visual/shape/polygon.d.ts +10 -0
  70. package/dist/src/utils/visual/shape/rectangle.d.ts +12 -0
  71. package/dist/src/utils/visual/shape/shape.d.ts +7 -0
  72. package/dist/src/utils/visual/style/fill.d.ts +8 -0
  73. package/dist/src/utils/visual/style/index.d.ts +2 -0
  74. package/dist/src/utils/visual/style/line.d.ts +9 -0
  75. package/dist/src/utils/visual/types.d.ts +6 -0
  76. package/dist/src/utils/visual/vertex/application.d.ts +13 -0
  77. package/dist/src/utils/visual/vertex/container.d.ts +38 -0
  78. package/dist/src/utils/visual/vertex/index.d.ts +4 -0
  79. package/dist/src/utils/visual/vertex/point.d.ts +18 -0
  80. package/dist/src/utils/visual/vertex/vertex.d.ts +36 -0
  81. package/dist/src/vnode/chainDom.d.ts +47 -0
  82. package/dist/{wasm.js → src/wasm/index.js} +4 -8
  83. package/dist/test/writeFile.test.d.ts +1 -0
  84. package/dist/tsconfig.json +1 -0
  85. package/dist/umd/index.umd.cjs +1 -1
  86. package/dist/umd/ml/ml.umd.cjs +1 -1
  87. package/dist/umd/node/node.umd.cjs +1 -1
  88. package/dist/umd/react/react.umd.cjs +1 -1
  89. package/dist/umd/utils/utils.umd.cjs +1 -1
  90. package/dist/{ws-DoSbcWWZ.js → ws-CQA-0Bzm.js} +31 -53
  91. package/package.json +18 -16
  92. package/readme.md +6 -2
  93. package/typings.d.ts +4 -10
  94. package/dist/node.js +0 -27
  95. package/dist/react.js +0 -4
  96. package/dist/utils.js +0 -2092
  97. /package/dist/test/{server/encodeUrl.test.d.ts → encodeUrl.test.d.ts} +0 -0
  98. /package/dist/test/{server/escapeHtml.test.d.ts → escapeHtml.test.d.ts} +0 -0
  99. /package/dist/test/{server/mimeType.test.d.ts → mimeType.test.d.ts} +0 -0
  100. /package/dist/test/{server/server.test.d.ts → server.test.d.ts} +0 -0
  101. /package/dist/test/{server/status.test.d.ts → status.test.d.ts} +0 -0
  102. /package/dist/test/{file/writeFile.test.d.ts → totp.test.d.ts} +0 -0
  103. /package/dist/test/{server/websocket.test.d.ts → websocket.test.d.ts} +0 -0
@@ -0,0 +1,4021 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+ import { o as isString, p as randomString } from "../../mimeType-eRf1TlBb.js";
5
+ import { C, a, F, H, b, M, R, c, d, e, f, g, h, i, j, k, l, m, n, r, q, s, t, u, v, w } from "../../mimeType-eRf1TlBb.js";
6
+ const sections = {
7
+ 172351395: { name: "EBML", type: "Container" },
8
+ 646: { name: "EBMLVersion", type: "Uint" },
9
+ 759: { name: "EBMLReadVersion", type: "Uint" },
10
+ 754: { name: "EBMLMaxIDLength", type: "Uint" },
11
+ 755: { name: "EBMLMaxSizeLength", type: "Uint" },
12
+ 642: { name: "DocType", type: "String" },
13
+ 647: { name: "DocTypeVersion", type: "Uint" },
14
+ 645: { name: "DocTypeReadVersion", type: "Uint" },
15
+ 108: { name: "Void", type: "Binary" },
16
+ 63: { name: "CRC-32", type: "Binary" },
17
+ 190023271: { name: "SignatureSlot", type: "Container" },
18
+ 16010: { name: "SignatureAlgo", type: "Uint" },
19
+ 16026: { name: "SignatureHash", type: "Uint" },
20
+ 16037: { name: "SignaturePublicKey", type: "Binary" },
21
+ 16053: { name: "Signature", type: "Binary" },
22
+ 15963: { name: "SignatureElements", type: "Container" },
23
+ 15995: { name: "SignatureElementList", type: "Container" },
24
+ 9522: { name: "SignedElement", type: "Binary" },
25
+ 139690087: { name: "Segment", type: "Container" },
26
+ 21863284: { name: "SeekHead", type: "Container" },
27
+ 3515: { name: "Seek", type: "Container" },
28
+ 5035: { name: "SeekID", type: "Binary" },
29
+ 5036: { name: "SeekPosition", type: "Uint" },
30
+ 88713574: { name: "Info", type: "Container" },
31
+ 13220: { name: "SegmentUID", type: "Binary" },
32
+ 13188: { name: "SegmentFilename", type: "String" },
33
+ 1882403: { name: "PrevUID", type: "Binary" },
34
+ 1868715: { name: "PrevFilename", type: "String" },
35
+ 2013475: { name: "NextUID", type: "Binary" },
36
+ 1999803: { name: "NextFilename", type: "String" },
37
+ 1092: { name: "SegmentFamily", type: "Binary" },
38
+ 10532: { name: "ChapterTranslate", type: "Container" },
39
+ 10748: { name: "ChapterTranslateEditionUID", type: "Uint" },
40
+ 10687: { name: "ChapterTranslateCodec", type: "Uint" },
41
+ 10661: { name: "ChapterTranslateID", type: "Binary" },
42
+ 710577: { name: "TimecodeScale", type: "Uint" },
43
+ 1161: { name: "Duration", type: "Float" },
44
+ 1121: { name: "DateUTC", type: "Date" },
45
+ 15273: { name: "Title", type: "String" },
46
+ 3456: { name: "MuxingApp", type: "String" },
47
+ 5953: { name: "WritingApp", type: "String" },
48
+ // 0xf43b675: { name: 'Cluster', type: 'Container' },
49
+ 103: { name: "Timecode", type: "Uint" },
50
+ 6228: { name: "SilentTracks", type: "Container" },
51
+ 6359: { name: "SilentTrackNumber", type: "Uint" },
52
+ 39: { name: "Position", type: "Uint" },
53
+ 43: { name: "PrevSize", type: "Uint" },
54
+ 35: { name: "SimpleBlock", type: "Binary" },
55
+ 32: { name: "BlockGroup", type: "Container" },
56
+ 33: { name: "Block", type: "Binary" },
57
+ 34: { name: "BlockVirtual", type: "Binary" },
58
+ 13729: { name: "BlockAdditions", type: "Container" },
59
+ 38: { name: "BlockMore", type: "Container" },
60
+ 110: { name: "BlockAddID", type: "Uint" },
61
+ 37: { name: "BlockAdditional", type: "Binary" },
62
+ 27: { name: "BlockDuration", type: "Uint" },
63
+ 122: { name: "ReferencePriority", type: "Uint" },
64
+ 123: { name: "ReferenceBlock", type: "Int" },
65
+ 125: { name: "ReferenceVirtual", type: "Int" },
66
+ 36: { name: "CodecState", type: "Binary" },
67
+ 13730: { name: "DiscardPadding", type: "Int" },
68
+ 14: { name: "Slices", type: "Container" },
69
+ 104: { name: "TimeSlice", type: "Container" },
70
+ 76: { name: "LaceNumber", type: "Uint" },
71
+ 77: { name: "FrameNumber", type: "Uint" },
72
+ 75: { name: "BlockAdditionID", type: "Uint" },
73
+ 78: { name: "Delay", type: "Uint" },
74
+ 79: { name: "SliceDuration", type: "Uint" },
75
+ 72: { name: "ReferenceFrame", type: "Container" },
76
+ 73: { name: "ReferenceOffset", type: "Uint" },
77
+ 74: { name: "ReferenceTimeCode", type: "Uint" },
78
+ 47: { name: "EncryptedBlock", type: "Binary" },
79
+ 106212971: { name: "Tracks", type: "Container" },
80
+ 46: { name: "TrackEntry", type: "Container" },
81
+ 87: { name: "TrackNumber", type: "Uint" },
82
+ 13253: { name: "TrackUID", type: "Uint" },
83
+ 3: { name: "TrackType", type: "Uint" },
84
+ 57: { name: "FlagEnabled", type: "Uint" },
85
+ 8: { name: "FlagDefault", type: "Uint" },
86
+ 5546: { name: "FlagForced", type: "Uint" },
87
+ 28: { name: "FlagLacing", type: "Uint" },
88
+ 11751: { name: "MinCache", type: "Uint" },
89
+ 11768: { name: "MaxCache", type: "Uint" },
90
+ 254851: { name: "DefaultDuration", type: "Uint" },
91
+ 216698: { name: "DefaultDecodedFieldDuration", type: "Uint" },
92
+ 209231: { name: "TrackTimecodeScale", type: "Float" },
93
+ 4991: { name: "TrackOffset", type: "Int" },
94
+ 5614: { name: "MaxBlockAdditionID", type: "Uint" },
95
+ 4974: { name: "Name", type: "String" },
96
+ 177564: { name: "Language", type: "String" },
97
+ 6: { name: "CodecID", type: "String" },
98
+ 9122: { name: "CodecPrivate", type: "Binary" },
99
+ 362120: { name: "CodecName", type: "String" },
100
+ 13382: { name: "AttachmentLink", type: "Uint" },
101
+ 1742487: { name: "CodecSettings", type: "String" },
102
+ 1785920: { name: "CodecInfoURL", type: "String" },
103
+ 438848: { name: "CodecDownloadURL", type: "String" },
104
+ 42: { name: "CodecDecodeAll", type: "Uint" },
105
+ 12203: { name: "TrackOverlay", type: "Uint" },
106
+ 5802: { name: "CodecDelay", type: "Uint" },
107
+ 5819: { name: "SeekPreRoll", type: "Uint" },
108
+ 9764: { name: "TrackTranslate", type: "Container" },
109
+ 9980: { name: "TrackTranslateEditionUID", type: "Uint" },
110
+ 9919: { name: "TrackTranslateCodec", type: "Uint" },
111
+ 9893: { name: "TrackTranslateTrackID", type: "Binary" },
112
+ 96: { name: "Video", type: "Container" },
113
+ 26: { name: "FlagInterlaced", type: "Uint" },
114
+ 5048: { name: "StereoMode", type: "Uint" },
115
+ 5056: { name: "AlphaMode", type: "Uint" },
116
+ 5049: { name: "OldStereoMode", type: "Uint" },
117
+ 48: { name: "PixelWidth", type: "Uint" },
118
+ 58: { name: "PixelHeight", type: "Uint" },
119
+ 5290: { name: "PixelCropBottom", type: "Uint" },
120
+ 5307: { name: "PixelCropTop", type: "Uint" },
121
+ 5324: { name: "PixelCropLeft", type: "Uint" },
122
+ 5341: { name: "PixelCropRight", type: "Uint" },
123
+ 5296: { name: "DisplayWidth", type: "Uint" },
124
+ 5306: { name: "DisplayHeight", type: "Uint" },
125
+ 5298: { name: "DisplayUnit", type: "Uint" },
126
+ 5299: { name: "AspectRatioType", type: "Uint" },
127
+ 963876: { name: "ColourSpace", type: "Binary" },
128
+ 1029411: { name: "GammaValue", type: "Float" },
129
+ 230371: { name: "FrameRate", type: "Float" },
130
+ 97: { name: "Audio", type: "Container" },
131
+ 53: { name: "SamplingFrequency", type: "Float" },
132
+ 14517: { name: "OutputSamplingFrequency", type: "Float" },
133
+ 31: { name: "Channels", type: "Uint" },
134
+ 15739: { name: "ChannelPositions", type: "Binary" },
135
+ 8804: { name: "BitDepth", type: "Uint" },
136
+ 98: { name: "TrackOperation", type: "Container" },
137
+ 99: { name: "TrackCombinePlanes", type: "Container" },
138
+ 100: { name: "TrackPlane", type: "Container" },
139
+ 101: { name: "TrackPlaneUID", type: "Uint" },
140
+ 102: { name: "TrackPlaneType", type: "Uint" },
141
+ 105: { name: "TrackJoinBlocks", type: "Container" },
142
+ 109: { name: "TrackJoinUID", type: "Uint" },
143
+ 64: { name: "TrickTrackUID", type: "Uint" },
144
+ 65: { name: "TrickTrackSegmentUID", type: "Binary" },
145
+ 70: { name: "TrickTrackFlag", type: "Uint" },
146
+ 71: { name: "TrickMasterTrackUID", type: "Uint" },
147
+ 68: { name: "TrickMasterTrackSegmentUID", type: "Binary" },
148
+ 11648: { name: "ContentEncodings", type: "Container" },
149
+ 8768: { name: "ContentEncoding", type: "Container" },
150
+ 4145: { name: "ContentEncodingOrder", type: "Uint" },
151
+ 4146: { name: "ContentEncodingScope", type: "Uint" },
152
+ 4147: { name: "ContentEncodingType", type: "Uint" },
153
+ 4148: { name: "ContentCompression", type: "Container" },
154
+ 596: { name: "ContentCompAlgo", type: "Uint" },
155
+ 597: { name: "ContentCompSettings", type: "Binary" },
156
+ 4149: { name: "ContentEncryption", type: "Container" },
157
+ 2017: { name: "ContentEncAlgo", type: "Uint" },
158
+ 2018: { name: "ContentEncKeyID", type: "Binary" },
159
+ 2019: { name: "ContentSignature", type: "Binary" },
160
+ 2020: { name: "ContentSigKeyID", type: "Binary" },
161
+ 2021: { name: "ContentSigAlgo", type: "Uint" },
162
+ 2022: { name: "ContentSigHashAlgo", type: "Uint" },
163
+ 206814059: { name: "Cues", type: "Container" },
164
+ 59: { name: "CuePoint", type: "Container" },
165
+ 51: { name: "CueTime", type: "Uint" },
166
+ 55: { name: "CueTrackPositions", type: "Container" },
167
+ 119: { name: "CueTrack", type: "Uint" },
168
+ 113: { name: "CueClusterPosition", type: "Uint" },
169
+ 112: { name: "CueRelativePosition", type: "Uint" },
170
+ 50: { name: "CueDuration", type: "Uint" },
171
+ 4984: { name: "CueBlockNumber", type: "Uint" },
172
+ 106: { name: "CueCodecState", type: "Uint" },
173
+ 91: { name: "CueReference", type: "Container" },
174
+ 22: { name: "CueRefTime", type: "Uint" },
175
+ 23: { name: "CueRefCluster", type: "Uint" },
176
+ 4959: { name: "CueRefNumber", type: "Uint" },
177
+ 107: { name: "CueRefCodecState", type: "Uint" },
178
+ 155296873: { name: "Attachments", type: "Container" },
179
+ 8615: { name: "AttachedFile", type: "Container" },
180
+ 1662: { name: "FileDescription", type: "String" },
181
+ 1646: { name: "FileName", type: "String" },
182
+ 1632: { name: "FileMimeType", type: "String" },
183
+ 1628: { name: "FileData", type: "Binary" },
184
+ 1710: { name: "FileUID", type: "Uint" },
185
+ 1653: { name: "FileReferral", type: "Binary" },
186
+ 1633: { name: "FileUsedStartTime", type: "Uint" },
187
+ 1634: { name: "FileUsedEndTime", type: "Uint" },
188
+ 4433776: { name: "Chapters", type: "Container" },
189
+ 1465: { name: "EditionEntry", type: "Container" },
190
+ 1468: { name: "EditionUID", type: "Uint" },
191
+ 1469: { name: "EditionFlagHidden", type: "Uint" },
192
+ 1499: { name: "EditionFlagDefault", type: "Uint" },
193
+ 1501: { name: "EditionFlagOrdered", type: "Uint" },
194
+ 54: { name: "ChapterAtom", type: "Container" },
195
+ 13252: { name: "ChapterUID", type: "Uint" },
196
+ 5716: { name: "ChapterStringUID", type: "String" },
197
+ 17: { name: "ChapterTimeStart", type: "Uint" },
198
+ 18: { name: "ChapterTimeEnd", type: "Uint" },
199
+ 24: { name: "ChapterFlagHidden", type: "Uint" },
200
+ 1432: { name: "ChapterFlagEnabled", type: "Uint" },
201
+ 11879: { name: "ChapterSegmentUID", type: "Binary" },
202
+ 11964: { name: "ChapterSegmentEditionUID", type: "Uint" },
203
+ 9155: { name: "ChapterPhysicalEquiv", type: "Uint" },
204
+ 15: { name: "ChapterTrack", type: "Container" },
205
+ 9: { name: "ChapterTrackNumber", type: "Uint" },
206
+ 0: { name: "ChapterDisplay", type: "Container" },
207
+ 5: { name: "ChapString", type: "String" },
208
+ 892: { name: "ChapLanguage", type: "String" },
209
+ 894: { name: "ChapCountry", type: "String" },
210
+ 10564: { name: "ChapProcess", type: "Container" },
211
+ 10581: { name: "ChapProcessCodecID", type: "Uint" },
212
+ 1293: { name: "ChapProcessPrivate", type: "Binary" },
213
+ 10513: { name: "ChapProcessCommand", type: "Container" },
214
+ 10530: { name: "ChapProcessTime", type: "Uint" },
215
+ 10547: { name: "ChapProcessData", type: "Binary" },
216
+ 39109479: { name: "Tags", type: "Container" },
217
+ 13171: { name: "Tag", type: "Container" },
218
+ 9152: { name: "Targets", type: "Container" },
219
+ 10442: { name: "TargetTypeValue", type: "Uint" },
220
+ 9162: { name: "TargetType", type: "String" },
221
+ 9157: { name: "TagTrackUID", type: "Uint" },
222
+ 9161: { name: "TagEditionUID", type: "Uint" },
223
+ 9156: { name: "TagChapterUID", type: "Uint" },
224
+ 9158: { name: "TagAttachmentUID", type: "Uint" },
225
+ 10184: { name: "SimpleTag", type: "Container" },
226
+ 1443: { name: "TagName", type: "String" },
227
+ 1146: { name: "TagLanguage", type: "String" },
228
+ 1156: { name: "TagDefault", type: "Uint" },
229
+ 1159: { name: "TagString", type: "String" },
230
+ 1157: { name: "TagBinary", type: "Binary" }
231
+ };
232
+ class WebmBase {
233
+ constructor(name = "Unknown", type = "Unknown") {
234
+ __publicField(this, "source");
235
+ __publicField(this, "data");
236
+ this.name = name;
237
+ this.type = type;
238
+ }
239
+ updateBySource() {
240
+ }
241
+ setSource(source) {
242
+ this.source = source;
243
+ this.updateBySource();
244
+ }
245
+ updateByData() {
246
+ }
247
+ setData(data) {
248
+ this.data = data;
249
+ this.updateByData();
250
+ }
251
+ }
252
+ function padHex(hex) {
253
+ return hex.length % 2 === 1 ? "0" + hex : hex;
254
+ }
255
+ class WebmUint extends WebmBase {
256
+ constructor(name, type) {
257
+ super(name, type || "Uint");
258
+ }
259
+ updateBySource() {
260
+ this.data = "";
261
+ for (let i2 = 0; i2 < this.source.length; i2++) {
262
+ const hex = this.source[i2].toString(16);
263
+ this.data += padHex(hex);
264
+ }
265
+ }
266
+ updateByData() {
267
+ const length = this.data.length / 2;
268
+ this.source = new Uint8Array(length);
269
+ for (let i2 = 0; i2 < length; i2++) {
270
+ const hex = this.data.substr(i2 * 2, 2);
271
+ this.source[i2] = parseInt(hex, 16);
272
+ }
273
+ }
274
+ getValue() {
275
+ return parseInt(this.data, 16);
276
+ }
277
+ setValue(value) {
278
+ this.setData(padHex(value.toString(16)));
279
+ }
280
+ }
281
+ class WebmFloat extends WebmBase {
282
+ constructor(name, type) {
283
+ super(name, type || "Float");
284
+ }
285
+ getFloatArrayType() {
286
+ return this.source && this.source.length === 4 ? Float32Array : Float64Array;
287
+ }
288
+ updateBySource() {
289
+ const byteArray = this.source.reverse();
290
+ const floatArrayType = this.getFloatArrayType();
291
+ const floatArray = new floatArrayType(byteArray.buffer);
292
+ this.data = floatArray[0];
293
+ }
294
+ updateByData() {
295
+ const floatArrayType = this.getFloatArrayType();
296
+ const floatArray = new floatArrayType([this.data]);
297
+ const byteArray = new Uint8Array(floatArray.buffer);
298
+ this.source = byteArray.reverse();
299
+ }
300
+ getValue() {
301
+ return this.data;
302
+ }
303
+ setValue(value) {
304
+ this.setData(value);
305
+ }
306
+ }
307
+ class WebmContainer extends WebmBase {
308
+ constructor(name, type) {
309
+ super(name, type || "Container");
310
+ __publicField(this, "offset", 0);
311
+ __publicField(this, "data", []);
312
+ }
313
+ readByte() {
314
+ return this.source[this.offset++];
315
+ }
316
+ readUint() {
317
+ const firstByte = this.readByte();
318
+ const bytes = 8 - firstByte.toString(2).length;
319
+ let value = firstByte - (1 << 7 - bytes);
320
+ for (let i2 = 0; i2 < bytes; i2++) {
321
+ value *= 256;
322
+ value += this.readByte();
323
+ }
324
+ return value;
325
+ }
326
+ updateBySource() {
327
+ let end = void 0;
328
+ this.data = [];
329
+ for (this.offset = 0; this.offset < this.source.length; this.offset = end) {
330
+ const id = this.readUint();
331
+ const len = this.readUint();
332
+ end = Math.min(this.offset + len, this.source.length);
333
+ const data = this.source.slice(this.offset, end);
334
+ const info = sections[id] || { name: "Unknown", type: "Unknown" };
335
+ let ctr = WebmBase;
336
+ switch (info.type) {
337
+ case "Container":
338
+ ctr = WebmContainer;
339
+ break;
340
+ case "Uint":
341
+ ctr = WebmUint;
342
+ break;
343
+ case "Float":
344
+ ctr = WebmFloat;
345
+ break;
346
+ }
347
+ const section = new ctr(info.name, info.type);
348
+ section.setSource(data);
349
+ this.data.push({
350
+ id,
351
+ idHex: id.toString(16),
352
+ data: section
353
+ });
354
+ }
355
+ }
356
+ writeUint(x, draft = false) {
357
+ let bytes = 1, flag = 128;
358
+ while (x >= flag && bytes < 8) {
359
+ bytes++, flag *= 128;
360
+ }
361
+ if (!draft) {
362
+ let value = flag + x;
363
+ for (let i2 = bytes - 1; i2 >= 0; i2--) {
364
+ const c2 = value % 256;
365
+ this.source[this.offset + i2] = c2;
366
+ value = (value - c2) / 256;
367
+ }
368
+ }
369
+ this.offset += bytes;
370
+ }
371
+ writeSections(draft = false) {
372
+ this.offset = 0;
373
+ for (let i2 = 0; i2 < this.data.length; i2++) {
374
+ const section = this.data[i2], content = section.data.source, contentLength = content.length;
375
+ this.writeUint(section.id, draft);
376
+ this.writeUint(contentLength, draft);
377
+ if (!draft) {
378
+ this.source.set(content, this.offset);
379
+ }
380
+ this.offset += contentLength;
381
+ }
382
+ return this.offset;
383
+ }
384
+ updateByData() {
385
+ const length = this.writeSections(true);
386
+ this.source = new Uint8Array(length);
387
+ this.writeSections();
388
+ }
389
+ getSectionById(id) {
390
+ for (let i2 = 0; i2 < this.data.length; i2++) {
391
+ const section = this.data[i2];
392
+ if (section.id === id) {
393
+ return section.data;
394
+ }
395
+ }
396
+ return void 0;
397
+ }
398
+ }
399
+ class WebmFile extends WebmContainer {
400
+ constructor(source) {
401
+ super("File", "File");
402
+ this.setSource(source);
403
+ }
404
+ fixDuration(duration) {
405
+ const segmentSection = this.getSectionById(139690087);
406
+ if (!segmentSection) {
407
+ return false;
408
+ }
409
+ const infoSection = segmentSection.getSectionById(88713574);
410
+ if (!infoSection) {
411
+ return false;
412
+ }
413
+ const timeScaleSection = infoSection.getSectionById(710577);
414
+ if (!timeScaleSection) {
415
+ return false;
416
+ }
417
+ let durationSection = infoSection.getSectionById(1161);
418
+ if (durationSection) {
419
+ if (durationSection.getValue() <= 0) {
420
+ durationSection.setValue(duration);
421
+ } else {
422
+ return false;
423
+ }
424
+ } else {
425
+ durationSection = new WebmFloat("Duration", "Float");
426
+ durationSection.setValue(duration);
427
+ infoSection.data.push({
428
+ id: 1161,
429
+ data: durationSection
430
+ });
431
+ }
432
+ timeScaleSection.setValue(1e6);
433
+ infoSection.updateByData();
434
+ segmentSection.updateByData();
435
+ this.updateByData();
436
+ return true;
437
+ }
438
+ toBlob(type = "video/webm") {
439
+ return new Blob([this.source.buffer], { type });
440
+ }
441
+ }
442
+ const webmFixDuration = (blob, duration, type = "video/webm") => {
443
+ return new Promise((resolve, reject) => {
444
+ try {
445
+ const reader = new FileReader();
446
+ reader.addEventListener("loadend", () => {
447
+ try {
448
+ const result = reader.result;
449
+ const file = new WebmFile(new Uint8Array(result));
450
+ if (file.fixDuration(duration)) {
451
+ resolve(file.toBlob(type));
452
+ } else {
453
+ resolve(blob);
454
+ }
455
+ } catch (ex) {
456
+ reject(ex);
457
+ }
458
+ });
459
+ reader.addEventListener("error", () => reject());
460
+ reader.readAsArrayBuffer(blob);
461
+ } catch (ex) {
462
+ reject(ex);
463
+ }
464
+ });
465
+ };
466
+ function getMimeType() {
467
+ const types = ["audio/webm", "audio/mp4", "audio/ogg", "audio/wav", "audio/aac"];
468
+ for (let i2 = 0; i2 < types.length; i2++) {
469
+ if (MediaRecorder.isTypeSupported(types[i2])) {
470
+ return types[i2];
471
+ }
472
+ }
473
+ return void 0;
474
+ }
475
+ class AudioRecorder {
476
+ constructor() {
477
+ __publicField(this, "startTime");
478
+ __publicField(this, "chunks");
479
+ __publicField(this, "mediaRecorder");
480
+ __publicField(this, "blob");
481
+ this.startTime = Date.now();
482
+ this.chunks = [];
483
+ navigator.mediaDevices.getUserMedia({
484
+ audio: true
485
+ }).then((stream) => {
486
+ this.init(stream);
487
+ }).catch((error) => {
488
+ });
489
+ }
490
+ init(stream) {
491
+ var _a, _b;
492
+ const mimeType = getMimeType();
493
+ this.mediaRecorder = new MediaRecorder(stream, {
494
+ mimeType
495
+ });
496
+ (_a = this.mediaRecorder) == null ? void 0 : _a.addEventListener("dataavailable", async (event) => {
497
+ var _a2;
498
+ if (event.data.size > 0) {
499
+ this.chunks.push(event.data);
500
+ }
501
+ if (((_a2 = this.mediaRecorder) == null ? void 0 : _a2.state) === "inactive") {
502
+ const duration = Date.now() - this.startTime;
503
+ this.blob = new Blob(this.chunks, { type: mimeType });
504
+ if (mimeType === "audio/webm") {
505
+ this.blob = await webmFixDuration(this.blob, duration, this.blob.type);
506
+ }
507
+ this.chunks = [];
508
+ }
509
+ });
510
+ (_b = this.mediaRecorder) == null ? void 0 : _b.start();
511
+ }
512
+ start() {
513
+ var _a;
514
+ if (((_a = this.mediaRecorder) == null ? void 0 : _a.state) === "paused") {
515
+ this.mediaRecorder.resume();
516
+ }
517
+ return this.mediaRecorder;
518
+ }
519
+ pause() {
520
+ var _a;
521
+ if (((_a = this.mediaRecorder) == null ? void 0 : _a.state) === "recording") {
522
+ this.mediaRecorder.pause();
523
+ }
524
+ return this.mediaRecorder;
525
+ }
526
+ stop() {
527
+ var _a;
528
+ (_a = this.mediaRecorder) == null ? void 0 : _a.stop();
529
+ return this.blob;
530
+ }
531
+ }
532
+ const noop = () => {
533
+ };
534
+ var DEVICE = /* @__PURE__ */ ((DEVICE2) => {
535
+ DEVICE2["IPAD"] = "ipad";
536
+ DEVICE2["ANDROID"] = "android";
537
+ DEVICE2["IPhONE"] = "iphone";
538
+ DEVICE2["PC"] = "pc";
539
+ return DEVICE2;
540
+ })(DEVICE || {});
541
+ const currentDevice = () => {
542
+ if (typeof window !== "undefined") {
543
+ const ua = navigator.userAgent.toLowerCase();
544
+ if (/ipad|ipod/.test(ua)) return "ipad";
545
+ if (/android/.test(ua)) return "android";
546
+ if (/iphone/.test(ua)) return "iphone";
547
+ return "pc";
548
+ }
549
+ return "pc";
550
+ };
551
+ const isClient = typeof window !== "undefined";
552
+ const isWeiXin = () => {
553
+ if (isClient) {
554
+ const ua = window.navigator.userAgent.toLowerCase();
555
+ return ua.includes("micromessenger");
556
+ }
557
+ return false;
558
+ };
559
+ const isMobile = () => {
560
+ if (!isClient) return false;
561
+ const ua = window.navigator.userAgent;
562
+ if (/Android|webOS|iPhone|iPod|iPad|BlackBerry/i.test(ua)) {
563
+ return true;
564
+ }
565
+ return false;
566
+ };
567
+ const isBangDevice = () => {
568
+ if (!isClient) return false;
569
+ const iphone = /iphone/i.test(window.navigator.userAgent);
570
+ const ratio2 = window.devicePixelRatio && window.devicePixelRatio === 2;
571
+ const ratio3 = window.devicePixelRatio && window.devicePixelRatio === 3;
572
+ const mini12 = window.screen.width === 360 && window.screen.height === 780;
573
+ const pro11 = window.screen.width === 375 && window.screen.height === 812;
574
+ const pro12 = window.screen.width === 390 && window.screen.height === 844;
575
+ const promax11 = window.screen.width === 414 && window.screen.height === 896;
576
+ const promax12 = window.screen.width === 428 && window.screen.height === 926;
577
+ switch (true) {
578
+ case (iphone && ratio3 && mini12):
579
+ case (iphone && ratio3 && pro11):
580
+ case (iphone && ratio3 && pro12):
581
+ case (iphone && ratio2 && promax11):
582
+ case (iphone && ratio3 && promax11):
583
+ case (iphone && ratio3 && promax12):
584
+ return true;
585
+ default:
586
+ return false;
587
+ }
588
+ };
589
+ const handleClick = (hooks = noop) => {
590
+ if (typeof document !== "undefined") {
591
+ document.addEventListener(
592
+ "click",
593
+ function(event) {
594
+ hooks(event);
595
+ },
596
+ true
597
+ );
598
+ }
599
+ };
600
+ const webglVendor = () => {
601
+ const glCanvas = document.createElement("canvas");
602
+ const gl = glCanvas.getContext("webgl2");
603
+ function getHardwareInfo(gl2) {
604
+ const debugInfo = gl2.getExtension("WEBGL_debug_renderer_info");
605
+ if (!debugInfo) {
606
+ return null;
607
+ }
608
+ const vendor = gl2.getParameter(debugInfo.UNMASKED_VENDOR_WEBGL);
609
+ const renderer = gl2.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL);
610
+ return {
611
+ vendor,
612
+ renderer
613
+ };
614
+ }
615
+ if (gl) {
616
+ return getHardwareInfo(gl);
617
+ }
618
+ return null;
619
+ };
620
+ const canvasVendor = () => {
621
+ const outScreenCanvas = document.createElement("canvas");
622
+ const ctx = outScreenCanvas.getContext("2d");
623
+ const txt = "BrowserLeaks,com <canvas> 1.0";
624
+ if (!ctx) return null;
625
+ ctx.textBaseline = "top";
626
+ ctx.font = "14px 'Arial'";
627
+ ctx.textBaseline = "alphabetic";
628
+ ctx.fillStyle = "#f60";
629
+ ctx.fillRect(125, 1, 62, 20);
630
+ ctx.fillStyle = "#069";
631
+ ctx.fillText(txt, 2, 15);
632
+ ctx.fillStyle = "rgba(102, 204, 0, 0.7)";
633
+ ctx.fillText(txt, 4, 17);
634
+ const canvasImageData = outScreenCanvas.toDataURL();
635
+ return canvasImageData;
636
+ };
637
+ const audioVendor = () => {
638
+ return new Promise((resolve, reject) => {
639
+ if (!isClient) reject("window is undefined");
640
+ const each = function(obj, iterator) {
641
+ if (Array.prototype.forEach && obj.forEach === Array.prototype.forEach) {
642
+ obj.forEach(iterator);
643
+ } else if (obj.length === +obj.length) {
644
+ for (let i2 = 0, l2 = obj.length; i2 < l2; i2++) {
645
+ iterator(obj[i2], i2, obj);
646
+ }
647
+ } else {
648
+ for (const key in obj) {
649
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
650
+ iterator(obj[key], Number(key), obj);
651
+ }
652
+ }
653
+ }
654
+ };
655
+ const AudioContext = window.OfflineAudioContext || window.webkitOfflineAudioContext;
656
+ const context = new AudioContext(1, 44100, 44100);
657
+ const oscillator = context.createOscillator();
658
+ oscillator.type = "triangle";
659
+ oscillator.frequency.setValueAtTime(1e4, context.currentTime);
660
+ const compressor = context.createDynamicsCompressor();
661
+ each(
662
+ [
663
+ ["threshold", -50],
664
+ ["knee", 40],
665
+ ["ratio", 12],
666
+ ["reduction", -20],
667
+ ["attack", 0],
668
+ ["release", 0.25]
669
+ ],
670
+ function(item) {
671
+ if (compressor[item[0]] && typeof compressor[item[0]] !== "number") {
672
+ const { setValueAtTime } = compressor[item[0]];
673
+ setValueAtTime(item[1], context.currentTime);
674
+ }
675
+ }
676
+ );
677
+ oscillator.connect(compressor);
678
+ compressor.connect(context.destination);
679
+ oscillator.start(0);
680
+ context.startRendering();
681
+ const audioTimeoutId = setTimeout(function() {
682
+ context.oncomplete = () => {
683
+ };
684
+ reject("audioTimeout");
685
+ return "audioTimeout";
686
+ }, 100);
687
+ context.oncomplete = (event) => {
688
+ try {
689
+ clearTimeout(audioTimeoutId);
690
+ const result = event.renderedBuffer.getChannelData(0).slice(4500, 5e3).reduce(function(acc, val) {
691
+ return acc + Math.abs(val);
692
+ }, 0).toString();
693
+ oscillator.disconnect();
694
+ compressor.disconnect();
695
+ resolve(result);
696
+ return result;
697
+ } catch (error) {
698
+ reject(error);
699
+ return;
700
+ }
701
+ };
702
+ });
703
+ };
704
+ const b64Tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
705
+ const arraybuffer_error = "ARRAYBUFFER not supported by this environment";
706
+ const uint8array_error = "UINT8ARRAY not supported by this environment";
707
+ function str2packed(str, utfType, existingPacked, existingPackedLen, bigEndianMod) {
708
+ let codePnt, codePntArr, byteCnt = 0, i2, j2, intOffset, byteOffset, shiftModifier, transposeBytes;
709
+ existingPackedLen = existingPackedLen || 0;
710
+ const packed = existingPacked || [0], existingByteLen = existingPackedLen >>> 3;
711
+ if ("UTF8" === utfType) {
712
+ shiftModifier = bigEndianMod === -1 ? 3 : 0;
713
+ for (i2 = 0; i2 < str.length; i2 += 1) {
714
+ codePnt = str.charCodeAt(i2);
715
+ codePntArr = [];
716
+ if (128 > codePnt) {
717
+ codePntArr.push(codePnt);
718
+ } else if (2048 > codePnt) {
719
+ codePntArr.push(192 | codePnt >>> 6);
720
+ codePntArr.push(128 | codePnt & 63);
721
+ } else if (55296 > codePnt || 57344 <= codePnt) {
722
+ codePntArr.push(224 | codePnt >>> 12, 128 | codePnt >>> 6 & 63, 128 | codePnt & 63);
723
+ } else {
724
+ i2 += 1;
725
+ codePnt = 65536 + ((codePnt & 1023) << 10 | str.charCodeAt(i2) & 1023);
726
+ codePntArr.push(
727
+ 240 | codePnt >>> 18,
728
+ 128 | codePnt >>> 12 & 63,
729
+ 128 | codePnt >>> 6 & 63,
730
+ 128 | codePnt & 63
731
+ );
732
+ }
733
+ for (j2 = 0; j2 < codePntArr.length; j2 += 1) {
734
+ byteOffset = byteCnt + existingByteLen;
735
+ intOffset = byteOffset >>> 2;
736
+ while (packed.length <= intOffset) {
737
+ packed.push(0);
738
+ }
739
+ packed[intOffset] |= codePntArr[j2] << 8 * (shiftModifier + bigEndianMod * (byteOffset % 4));
740
+ byteCnt += 1;
741
+ }
742
+ }
743
+ } else {
744
+ shiftModifier = bigEndianMod === -1 ? 2 : 0;
745
+ transposeBytes = "UTF16LE" === utfType && bigEndianMod !== 1 || "UTF16LE" !== utfType && bigEndianMod === 1;
746
+ for (i2 = 0; i2 < str.length; i2 += 1) {
747
+ codePnt = str.charCodeAt(i2);
748
+ if (transposeBytes === true) {
749
+ j2 = codePnt & 255;
750
+ codePnt = j2 << 8 | codePnt >>> 8;
751
+ }
752
+ byteOffset = byteCnt + existingByteLen;
753
+ intOffset = byteOffset >>> 2;
754
+ while (packed.length <= intOffset) {
755
+ packed.push(0);
756
+ }
757
+ packed[intOffset] |= codePnt << 8 * (shiftModifier + bigEndianMod * (byteOffset % 4));
758
+ byteCnt += 2;
759
+ }
760
+ }
761
+ return { value: packed, binLen: byteCnt * 8 + existingPackedLen };
762
+ }
763
+ function hex2packed(str, existingPacked, existingPackedLen, bigEndianMod) {
764
+ let i2, num, intOffset, byteOffset;
765
+ if (0 !== str.length % 2) {
766
+ throw new Error("String of HEX type must be in byte increments");
767
+ }
768
+ existingPackedLen = existingPackedLen || 0;
769
+ const packed = existingPacked || [0], existingByteLen = existingPackedLen >>> 3, shiftModifier = bigEndianMod === -1 ? 3 : 0;
770
+ for (i2 = 0; i2 < str.length; i2 += 2) {
771
+ num = parseInt(str.substr(i2, 2), 16);
772
+ if (!isNaN(num)) {
773
+ byteOffset = (i2 >>> 1) + existingByteLen;
774
+ intOffset = byteOffset >>> 2;
775
+ while (packed.length <= intOffset) {
776
+ packed.push(0);
777
+ }
778
+ packed[intOffset] |= num << 8 * (shiftModifier + bigEndianMod * (byteOffset % 4));
779
+ } else {
780
+ throw new Error("String of HEX type contains invalid characters");
781
+ }
782
+ }
783
+ return { value: packed, binLen: str.length * 4 + existingPackedLen };
784
+ }
785
+ function bytes2packed(str, existingPacked, existingPackedLen, bigEndianMod) {
786
+ let codePnt, i2, intOffset, byteOffset;
787
+ existingPackedLen = existingPackedLen || 0;
788
+ const packed = existingPacked || [0], existingByteLen = existingPackedLen >>> 3, shiftModifier = bigEndianMod === -1 ? 3 : 0;
789
+ for (i2 = 0; i2 < str.length; i2 += 1) {
790
+ codePnt = str.charCodeAt(i2);
791
+ byteOffset = i2 + existingByteLen;
792
+ intOffset = byteOffset >>> 2;
793
+ if (packed.length <= intOffset) {
794
+ packed.push(0);
795
+ }
796
+ packed[intOffset] |= codePnt << 8 * (shiftModifier + bigEndianMod * (byteOffset % 4));
797
+ }
798
+ return { value: packed, binLen: str.length * 8 + existingPackedLen };
799
+ }
800
+ function b642packed(str, existingPacked, existingPackedLen, bigEndianMod) {
801
+ let byteCnt = 0, index, i2, j2, tmpInt, strPart, intOffset, byteOffset;
802
+ existingPackedLen = existingPackedLen || 0;
803
+ const packed = existingPacked || [0], existingByteLen = existingPackedLen >>> 3, shiftModifier = bigEndianMod === -1 ? 3 : 0, firstEqual = str.indexOf("=");
804
+ if (-1 === str.search(/^[a-z\d=+/]+$/i)) {
805
+ throw new Error("Invalid character in base-64 string");
806
+ }
807
+ str = str.replace(/=/g, "");
808
+ if (-1 !== firstEqual && firstEqual < str.length) {
809
+ throw new Error("Invalid '=' found in base-64 string");
810
+ }
811
+ for (i2 = 0; i2 < str.length; i2 += 4) {
812
+ strPart = str.substr(i2, 4);
813
+ tmpInt = 0;
814
+ for (j2 = 0; j2 < strPart.length; j2 += 1) {
815
+ index = b64Tab.indexOf(strPart.charAt(j2));
816
+ tmpInt |= index << 18 - 6 * j2;
817
+ }
818
+ for (j2 = 0; j2 < strPart.length - 1; j2 += 1) {
819
+ byteOffset = byteCnt + existingByteLen;
820
+ intOffset = byteOffset >>> 2;
821
+ while (packed.length <= intOffset) {
822
+ packed.push(0);
823
+ }
824
+ packed[intOffset] |= (tmpInt >>> 16 - j2 * 8 & 255) << 8 * (shiftModifier + bigEndianMod * (byteOffset % 4));
825
+ byteCnt += 1;
826
+ }
827
+ }
828
+ return { value: packed, binLen: byteCnt * 8 + existingPackedLen };
829
+ }
830
+ function uint8array2packed(arr, existingPacked, existingPackedLen, bigEndianMod) {
831
+ let i2, intOffset, byteOffset;
832
+ existingPackedLen = existingPackedLen || 0;
833
+ const packed = existingPacked || [0], existingByteLen = existingPackedLen >>> 3, shiftModifier = bigEndianMod === -1 ? 3 : 0;
834
+ for (i2 = 0; i2 < arr.length; i2 += 1) {
835
+ byteOffset = i2 + existingByteLen;
836
+ intOffset = byteOffset >>> 2;
837
+ if (packed.length <= intOffset) {
838
+ packed.push(0);
839
+ }
840
+ packed[intOffset] |= arr[i2] << 8 * (shiftModifier + bigEndianMod * (byteOffset % 4));
841
+ }
842
+ return { value: packed, binLen: arr.length * 8 + existingPackedLen };
843
+ }
844
+ function arraybuffer2packed(arr, existingPacked, existingPackedLen, bigEndianMod) {
845
+ return uint8array2packed(new Uint8Array(arr), existingPacked, existingPackedLen, bigEndianMod);
846
+ }
847
+ function getStrConverter(format, utfType, bigEndianMod) {
848
+ switch (utfType) {
849
+ case "UTF8":
850
+ case "UTF16BE":
851
+ case "UTF16LE":
852
+ break;
853
+ default:
854
+ throw new Error("encoding must be UTF8, UTF16BE, or UTF16LE");
855
+ }
856
+ switch (format) {
857
+ case "HEX":
858
+ return function(str, existingBin, existingBinLen) {
859
+ return hex2packed(str, existingBin, existingBinLen, bigEndianMod);
860
+ };
861
+ case "TEXT":
862
+ return function(str, existingBin, existingBinLen) {
863
+ return str2packed(str, utfType, existingBin, existingBinLen, bigEndianMod);
864
+ };
865
+ case "B64":
866
+ return function(str, existingBin, existingBinLen) {
867
+ return b642packed(str, existingBin, existingBinLen, bigEndianMod);
868
+ };
869
+ case "BYTES":
870
+ return function(str, existingBin, existingBinLen) {
871
+ return bytes2packed(str, existingBin, existingBinLen, bigEndianMod);
872
+ };
873
+ case "ARRAYBUFFER":
874
+ try {
875
+ new ArrayBuffer(0);
876
+ } catch (ignore) {
877
+ throw new Error(arraybuffer_error);
878
+ }
879
+ return function(arr, existingBin, existingBinLen) {
880
+ return arraybuffer2packed(arr, existingBin, existingBinLen, bigEndianMod);
881
+ };
882
+ case "UINT8ARRAY":
883
+ try {
884
+ new Uint8Array(0);
885
+ } catch (ignore) {
886
+ throw new Error(uint8array_error);
887
+ }
888
+ return function(arr, existingBin, existingBinLen) {
889
+ return uint8array2packed(arr, existingBin, existingBinLen, bigEndianMod);
890
+ };
891
+ default:
892
+ throw new Error("format must be HEX, TEXT, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY");
893
+ }
894
+ }
895
+ function packed2hex(packed, outputLength, bigEndianMod, formatOpts) {
896
+ const hex_tab = "0123456789abcdef";
897
+ let str = "", i2, srcByte;
898
+ const length = outputLength / 8, shiftModifier = bigEndianMod === -1 ? 3 : 0;
899
+ for (i2 = 0; i2 < length; i2 += 1) {
900
+ srcByte = packed[i2 >>> 2] >>> 8 * (shiftModifier + bigEndianMod * (i2 % 4));
901
+ str += hex_tab.charAt(srcByte >>> 4 & 15) + hex_tab.charAt(srcByte & 15);
902
+ }
903
+ return formatOpts["outputUpper"] ? str.toUpperCase() : str;
904
+ }
905
+ function packed2b64(packed, outputLength, bigEndianMod, formatOpts) {
906
+ let str = "", i2, j2, triplet, int1, int2;
907
+ const length = outputLength / 8, shiftModifier = bigEndianMod === -1 ? 3 : 0;
908
+ for (i2 = 0; i2 < length; i2 += 3) {
909
+ int1 = i2 + 1 < length ? packed[i2 + 1 >>> 2] : 0;
910
+ int2 = i2 + 2 < length ? packed[i2 + 2 >>> 2] : 0;
911
+ triplet = (packed[i2 >>> 2] >>> 8 * (shiftModifier + bigEndianMod * (i2 % 4)) & 255) << 16 | (int1 >>> 8 * (shiftModifier + bigEndianMod * ((i2 + 1) % 4)) & 255) << 8 | int2 >>> 8 * (shiftModifier + bigEndianMod * ((i2 + 2) % 4)) & 255;
912
+ for (j2 = 0; j2 < 4; j2 += 1) {
913
+ if (i2 * 8 + j2 * 6 <= outputLength) {
914
+ str += b64Tab.charAt(triplet >>> 6 * (3 - j2) & 63);
915
+ } else {
916
+ str += formatOpts["b64Pad"];
917
+ }
918
+ }
919
+ }
920
+ return str;
921
+ }
922
+ function packed2bytes(packed, outputLength, bigEndianMod) {
923
+ let str = "", i2, srcByte;
924
+ const length = outputLength / 8, shiftModifier = bigEndianMod === -1 ? 3 : 0;
925
+ for (i2 = 0; i2 < length; i2 += 1) {
926
+ srcByte = packed[i2 >>> 2] >>> 8 * (shiftModifier + bigEndianMod * (i2 % 4)) & 255;
927
+ str += String.fromCharCode(srcByte);
928
+ }
929
+ return str;
930
+ }
931
+ function packed2arraybuffer(packed, outputLength, bigEndianMod) {
932
+ let i2;
933
+ const length = outputLength / 8, retVal = new ArrayBuffer(length), arrView = new Uint8Array(retVal), shiftModifier = bigEndianMod === -1 ? 3 : 0;
934
+ for (i2 = 0; i2 < length; i2 += 1) {
935
+ arrView[i2] = packed[i2 >>> 2] >>> 8 * (shiftModifier + bigEndianMod * (i2 % 4)) & 255;
936
+ }
937
+ return retVal;
938
+ }
939
+ function packed2uint8array(packed, outputLength, bigEndianMod) {
940
+ let i2;
941
+ const length = outputLength / 8, shiftModifier = bigEndianMod === -1 ? 3 : 0, retVal = new Uint8Array(length);
942
+ for (i2 = 0; i2 < length; i2 += 1) {
943
+ retVal[i2] = packed[i2 >>> 2] >>> 8 * (shiftModifier + bigEndianMod * (i2 % 4)) & 255;
944
+ }
945
+ return retVal;
946
+ }
947
+ function getOutputConverter(format, outputBinLen, bigEndianMod, outputOptions) {
948
+ switch (format) {
949
+ case "HEX":
950
+ return function(binarray) {
951
+ return packed2hex(binarray, outputBinLen, bigEndianMod, outputOptions);
952
+ };
953
+ case "B64":
954
+ return function(binarray) {
955
+ return packed2b64(binarray, outputBinLen, bigEndianMod, outputOptions);
956
+ };
957
+ case "BYTES":
958
+ return function(binarray) {
959
+ return packed2bytes(binarray, outputBinLen, bigEndianMod);
960
+ };
961
+ case "ARRAYBUFFER":
962
+ try {
963
+ new ArrayBuffer(0);
964
+ } catch (ignore) {
965
+ throw new Error(arraybuffer_error);
966
+ }
967
+ return function(binarray) {
968
+ return packed2arraybuffer(binarray, outputBinLen, bigEndianMod);
969
+ };
970
+ case "UINT8ARRAY":
971
+ try {
972
+ new Uint8Array(0);
973
+ } catch (ignore) {
974
+ throw new Error(uint8array_error);
975
+ }
976
+ return function(binarray) {
977
+ return packed2uint8array(binarray, outputBinLen, bigEndianMod);
978
+ };
979
+ default:
980
+ throw new Error("format must be HEX, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY");
981
+ }
982
+ }
983
+ const TWO_PWR_32 = 4294967296;
984
+ const K_sha2 = [
985
+ 1116352408,
986
+ 1899447441,
987
+ 3049323471,
988
+ 3921009573,
989
+ 961987163,
990
+ 1508970993,
991
+ 2453635748,
992
+ 2870763221,
993
+ 3624381080,
994
+ 310598401,
995
+ 607225278,
996
+ 1426881987,
997
+ 1925078388,
998
+ 2162078206,
999
+ 2614888103,
1000
+ 3248222580,
1001
+ 3835390401,
1002
+ 4022224774,
1003
+ 264347078,
1004
+ 604807628,
1005
+ 770255983,
1006
+ 1249150122,
1007
+ 1555081692,
1008
+ 1996064986,
1009
+ 2554220882,
1010
+ 2821834349,
1011
+ 2952996808,
1012
+ 3210313671,
1013
+ 3336571891,
1014
+ 3584528711,
1015
+ 113926993,
1016
+ 338241895,
1017
+ 666307205,
1018
+ 773529912,
1019
+ 1294757372,
1020
+ 1396182291,
1021
+ 1695183700,
1022
+ 1986661051,
1023
+ 2177026350,
1024
+ 2456956037,
1025
+ 2730485921,
1026
+ 2820302411,
1027
+ 3259730800,
1028
+ 3345764771,
1029
+ 3516065817,
1030
+ 3600352804,
1031
+ 4094571909,
1032
+ 275423344,
1033
+ 430227734,
1034
+ 506948616,
1035
+ 659060556,
1036
+ 883997877,
1037
+ 958139571,
1038
+ 1322822218,
1039
+ 1537002063,
1040
+ 1747873779,
1041
+ 1955562222,
1042
+ 2024104815,
1043
+ 2227730452,
1044
+ 2361852424,
1045
+ 2428436474,
1046
+ 2756734187,
1047
+ 3204031479,
1048
+ 3329325298
1049
+ ];
1050
+ const H_trunc = [3238371032, 914150663, 812702999, 4144912697, 4290775857, 1750603025, 1694076839, 3204075428];
1051
+ const H_full = [1779033703, 3144134277, 1013904242, 2773480762, 1359893119, 2600822924, 528734635, 1541459225];
1052
+ const sha_variant_error = "Chosen SHA variant is not supported";
1053
+ const mac_rounds_error = "Cannot set numRounds with MAC";
1054
+ function packedLEConcat(a2, b2) {
1055
+ let i2, arrOffset;
1056
+ const aByteLen = a2["binLen"] >>> 3, bByteLen = b2["binLen"] >>> 3, leftShiftAmount = aByteLen << 3, rightShiftAmount = 4 - aByteLen << 3;
1057
+ if (aByteLen % 4 !== 0) {
1058
+ for (i2 = 0; i2 < bByteLen; i2 += 4) {
1059
+ arrOffset = aByteLen + i2 >>> 2;
1060
+ a2["value"][arrOffset] |= b2["value"][i2 >>> 2] << leftShiftAmount;
1061
+ a2["value"].push(0);
1062
+ a2["value"][arrOffset + 1] |= b2["value"][i2 >>> 2] >>> rightShiftAmount;
1063
+ }
1064
+ if ((a2["value"].length << 2) - 4 >= bByteLen + aByteLen) {
1065
+ a2["value"].pop();
1066
+ }
1067
+ return { value: a2["value"], binLen: a2["binLen"] + b2["binLen"] };
1068
+ } else {
1069
+ return { value: a2["value"].concat(b2["value"]), binLen: a2["binLen"] + b2["binLen"] };
1070
+ }
1071
+ }
1072
+ function getOutputOpts(options) {
1073
+ const retVal = { outputUpper: false, b64Pad: "=", outputLen: -1 }, outputOptions = options || {}, lenErrstr = "Output length must be a multiple of 8";
1074
+ retVal["outputUpper"] = outputOptions["outputUpper"] || false;
1075
+ if (outputOptions["b64Pad"]) {
1076
+ retVal["b64Pad"] = outputOptions["b64Pad"];
1077
+ }
1078
+ if (outputOptions["outputLen"]) {
1079
+ if (outputOptions["outputLen"] % 8 !== 0) {
1080
+ throw new Error(lenErrstr);
1081
+ }
1082
+ retVal["outputLen"] = outputOptions["outputLen"];
1083
+ } else if (outputOptions["shakeLen"]) {
1084
+ if (outputOptions["shakeLen"] % 8 !== 0) {
1085
+ throw new Error(lenErrstr);
1086
+ }
1087
+ retVal["outputLen"] = outputOptions["shakeLen"];
1088
+ }
1089
+ if ("boolean" !== typeof retVal["outputUpper"]) {
1090
+ throw new Error("Invalid outputUpper formatting option");
1091
+ }
1092
+ if ("string" !== typeof retVal["b64Pad"]) {
1093
+ throw new Error("Invalid b64Pad formatting option");
1094
+ }
1095
+ return retVal;
1096
+ }
1097
+ function parseInputOption(key, value, bigEndianMod, fallback) {
1098
+ const errStr = key + " must include a value and format";
1099
+ if (!value) {
1100
+ if (!fallback) {
1101
+ throw new Error(errStr);
1102
+ }
1103
+ return fallback;
1104
+ }
1105
+ if (typeof value["value"] === "undefined" || !value["format"]) {
1106
+ throw new Error(errStr);
1107
+ }
1108
+ return getStrConverter(
1109
+ value["format"],
1110
+ // @ts-expect-error - the value of encoding gets value checked by getStrConverter
1111
+ value["encoding"] || "UTF8",
1112
+ bigEndianMod
1113
+ )(value["value"]);
1114
+ }
1115
+ class jsSHABase {
1116
+ constructor(variant, inputFormat, options) {
1117
+ /**
1118
+ * @param variant The desired SHA variant.
1119
+ * @param inputFormat The input format to be used in future `update` calls.
1120
+ * @param options Hashmap of extra input options.
1121
+ */
1122
+ /* Needed inputs */
1123
+ __publicField(this, "shaVariant");
1124
+ __publicField(this, "inputFormat");
1125
+ __publicField(this, "utfType");
1126
+ __publicField(this, "numRounds");
1127
+ __publicField(this, "keyWithIPad");
1128
+ __publicField(this, "keyWithOPad");
1129
+ __publicField(this, "remainder");
1130
+ __publicField(this, "remainderLen");
1131
+ __publicField(this, "updateCalled");
1132
+ __publicField(this, "processedLen");
1133
+ __publicField(this, "macKeySet");
1134
+ const inputOptions = options || {};
1135
+ this.inputFormat = inputFormat;
1136
+ this.utfType = inputOptions["encoding"] || "UTF8";
1137
+ this.numRounds = inputOptions["numRounds"] || 1;
1138
+ if (isNaN(this.numRounds) || this.numRounds !== parseInt(this.numRounds, 10) || 1 > this.numRounds) {
1139
+ throw new Error("numRounds must a integer >= 1");
1140
+ }
1141
+ this.shaVariant = variant;
1142
+ this.remainder = [];
1143
+ this.remainderLen = 0;
1144
+ this.updateCalled = false;
1145
+ this.processedLen = 0;
1146
+ this.macKeySet = false;
1147
+ this.keyWithIPad = [];
1148
+ this.keyWithOPad = [];
1149
+ }
1150
+ /**
1151
+ * Hashes as many blocks as possible. Stores the rest for either a future update or getHash call.
1152
+ *
1153
+ * @param srcString The input to be hashed.
1154
+ * @returns A reference to the object.
1155
+ */
1156
+ update(srcString) {
1157
+ let i2, updateProcessedLen = 0;
1158
+ const variantBlockIntInc = this.variantBlockSize >>> 5, convertRet = this.converterFunc(srcString, this.remainder, this.remainderLen), chunkBinLen = convertRet["binLen"], chunk = convertRet["value"], chunkIntLen = chunkBinLen >>> 5;
1159
+ for (i2 = 0; i2 < chunkIntLen; i2 += variantBlockIntInc) {
1160
+ if (updateProcessedLen + this.variantBlockSize <= chunkBinLen) {
1161
+ this.intermediateState = this.roundFunc(chunk.slice(i2, i2 + variantBlockIntInc), this.intermediateState);
1162
+ updateProcessedLen += this.variantBlockSize;
1163
+ }
1164
+ }
1165
+ this.processedLen += updateProcessedLen;
1166
+ this.remainder = chunk.slice(updateProcessedLen >>> 5);
1167
+ this.remainderLen = chunkBinLen % this.variantBlockSize;
1168
+ this.updateCalled = true;
1169
+ return this;
1170
+ }
1171
+ getHash(format, options) {
1172
+ let i2, finalizedState, outputBinLen = this.outputBinLen;
1173
+ const outputOptions = getOutputOpts(options);
1174
+ if (this.isVariableLen) {
1175
+ if (outputOptions["outputLen"] === -1) {
1176
+ throw new Error("Output length must be specified in options");
1177
+ }
1178
+ outputBinLen = outputOptions["outputLen"];
1179
+ }
1180
+ const formatFunc = getOutputConverter(format, outputBinLen, this.bigEndianMod, outputOptions);
1181
+ if (this.macKeySet && this.getMAC) {
1182
+ return formatFunc(this.getMAC(outputOptions));
1183
+ }
1184
+ finalizedState = this.finalizeFunc(
1185
+ this.remainder.slice(),
1186
+ this.remainderLen,
1187
+ this.processedLen,
1188
+ this.stateCloneFunc(this.intermediateState),
1189
+ outputBinLen
1190
+ );
1191
+ for (i2 = 1; i2 < this.numRounds; i2 += 1) {
1192
+ if (this.isVariableLen && outputBinLen % 32 !== 0) {
1193
+ finalizedState[finalizedState.length - 1] &= 16777215 >>> 24 - outputBinLen % 32;
1194
+ }
1195
+ finalizedState = this.finalizeFunc(
1196
+ finalizedState,
1197
+ outputBinLen,
1198
+ 0,
1199
+ this.newStateFunc(this.shaVariant),
1200
+ outputBinLen
1201
+ );
1202
+ }
1203
+ return formatFunc(finalizedState);
1204
+ }
1205
+ setHMACKey(key, inputFormat, options) {
1206
+ if (!this.HMACSupported) {
1207
+ throw new Error("Variant does not support HMAC");
1208
+ }
1209
+ if (this.updateCalled) {
1210
+ throw new Error("Cannot set MAC key after calling update");
1211
+ }
1212
+ const keyOptions = options || {}, keyConverterFunc = getStrConverter(inputFormat, keyOptions["encoding"] || "UTF8", this.bigEndianMod);
1213
+ this._setHMACKey(keyConverterFunc(key));
1214
+ }
1215
+ /**
1216
+ * Internal function that sets the MAC key.
1217
+ *
1218
+ * @param key The packed MAC key to use
1219
+ */
1220
+ _setHMACKey(key) {
1221
+ const blockByteSize = this.variantBlockSize >>> 3, lastArrayIndex = blockByteSize / 4 - 1;
1222
+ let i2;
1223
+ if (this.numRounds !== 1) {
1224
+ throw new Error(mac_rounds_error);
1225
+ }
1226
+ if (this.macKeySet) {
1227
+ throw new Error("MAC key already set");
1228
+ }
1229
+ if (blockByteSize < key["binLen"] / 8) {
1230
+ key["value"] = this.finalizeFunc(
1231
+ key["value"],
1232
+ key["binLen"],
1233
+ 0,
1234
+ this.newStateFunc(this.shaVariant),
1235
+ this.outputBinLen
1236
+ );
1237
+ }
1238
+ while (key["value"].length <= lastArrayIndex) {
1239
+ key["value"].push(0);
1240
+ }
1241
+ for (i2 = 0; i2 <= lastArrayIndex; i2 += 1) {
1242
+ this.keyWithIPad[i2] = key["value"][i2] ^ 909522486;
1243
+ this.keyWithOPad[i2] = key["value"][i2] ^ 1549556828;
1244
+ }
1245
+ this.intermediateState = this.roundFunc(this.keyWithIPad, this.intermediateState);
1246
+ this.processedLen = this.variantBlockSize;
1247
+ this.macKeySet = true;
1248
+ }
1249
+ getHMAC(format, options) {
1250
+ const outputOptions = getOutputOpts(options), formatFunc = getOutputConverter(format, this.outputBinLen, this.bigEndianMod, outputOptions);
1251
+ return formatFunc(this._getHMAC());
1252
+ }
1253
+ /**
1254
+ * Internal function that returns the "raw" HMAC
1255
+ */
1256
+ _getHMAC() {
1257
+ let finalizedState;
1258
+ if (!this.macKeySet) {
1259
+ throw new Error("Cannot call getHMAC without first setting MAC key");
1260
+ }
1261
+ const firstHash = this.finalizeFunc(
1262
+ this.remainder.slice(),
1263
+ this.remainderLen,
1264
+ this.processedLen,
1265
+ this.stateCloneFunc(this.intermediateState),
1266
+ this.outputBinLen
1267
+ );
1268
+ finalizedState = this.roundFunc(this.keyWithOPad, this.newStateFunc(this.shaVariant));
1269
+ finalizedState = this.finalizeFunc(
1270
+ firstHash,
1271
+ this.outputBinLen,
1272
+ this.variantBlockSize,
1273
+ finalizedState,
1274
+ this.outputBinLen
1275
+ );
1276
+ return finalizedState;
1277
+ }
1278
+ }
1279
+ function rotl_32(x, n2) {
1280
+ return x << n2 | x >>> 32 - n2;
1281
+ }
1282
+ function rotr_32(x, n2) {
1283
+ return x >>> n2 | x << 32 - n2;
1284
+ }
1285
+ function shr_32(x, n2) {
1286
+ return x >>> n2;
1287
+ }
1288
+ function parity_32(x, y, z) {
1289
+ return x ^ y ^ z;
1290
+ }
1291
+ function ch_32(x, y, z) {
1292
+ return x & y ^ ~x & z;
1293
+ }
1294
+ function maj_32(x, y, z) {
1295
+ return x & y ^ x & z ^ y & z;
1296
+ }
1297
+ function sigma0_32(x) {
1298
+ return rotr_32(x, 2) ^ rotr_32(x, 13) ^ rotr_32(x, 22);
1299
+ }
1300
+ function safeAdd_32_2(a2, b2) {
1301
+ const lsw = (a2 & 65535) + (b2 & 65535), msw = (a2 >>> 16) + (b2 >>> 16) + (lsw >>> 16);
1302
+ return (msw & 65535) << 16 | lsw & 65535;
1303
+ }
1304
+ function safeAdd_32_4(a2, b2, c2, d2) {
1305
+ const lsw = (a2 & 65535) + (b2 & 65535) + (c2 & 65535) + (d2 & 65535), msw = (a2 >>> 16) + (b2 >>> 16) + (c2 >>> 16) + (d2 >>> 16) + (lsw >>> 16);
1306
+ return (msw & 65535) << 16 | lsw & 65535;
1307
+ }
1308
+ function safeAdd_32_5(a2, b2, c2, d2, e2) {
1309
+ const lsw = (a2 & 65535) + (b2 & 65535) + (c2 & 65535) + (d2 & 65535) + (e2 & 65535), msw = (a2 >>> 16) + (b2 >>> 16) + (c2 >>> 16) + (d2 >>> 16) + (e2 >>> 16) + (lsw >>> 16);
1310
+ return (msw & 65535) << 16 | lsw & 65535;
1311
+ }
1312
+ function gamma1_32(x) {
1313
+ return rotr_32(x, 17) ^ rotr_32(x, 19) ^ shr_32(x, 10);
1314
+ }
1315
+ function gamma0_32(x) {
1316
+ return rotr_32(x, 7) ^ rotr_32(x, 18) ^ shr_32(x, 3);
1317
+ }
1318
+ function sigma1_32(x) {
1319
+ return rotr_32(x, 6) ^ rotr_32(x, 11) ^ rotr_32(x, 25);
1320
+ }
1321
+ function getNewState$1(_variant) {
1322
+ return [1732584193, 4023233417, 2562383102, 271733878, 3285377520];
1323
+ }
1324
+ function roundSHA1(block, H2) {
1325
+ let a2, b2, c2, d2, e2, T, t2;
1326
+ const W = [];
1327
+ a2 = H2[0];
1328
+ b2 = H2[1];
1329
+ c2 = H2[2];
1330
+ d2 = H2[3];
1331
+ e2 = H2[4];
1332
+ for (t2 = 0; t2 < 80; t2 += 1) {
1333
+ if (t2 < 16) {
1334
+ W[t2] = block[t2];
1335
+ } else {
1336
+ W[t2] = rotl_32(W[t2 - 3] ^ W[t2 - 8] ^ W[t2 - 14] ^ W[t2 - 16], 1);
1337
+ }
1338
+ if (t2 < 20) {
1339
+ T = safeAdd_32_5(rotl_32(a2, 5), ch_32(b2, c2, d2), e2, 1518500249, W[t2]);
1340
+ } else if (t2 < 40) {
1341
+ T = safeAdd_32_5(rotl_32(a2, 5), parity_32(b2, c2, d2), e2, 1859775393, W[t2]);
1342
+ } else if (t2 < 60) {
1343
+ T = safeAdd_32_5(rotl_32(a2, 5), maj_32(b2, c2, d2), e2, 2400959708, W[t2]);
1344
+ } else {
1345
+ T = safeAdd_32_5(rotl_32(a2, 5), parity_32(b2, c2, d2), e2, 3395469782, W[t2]);
1346
+ }
1347
+ e2 = d2;
1348
+ d2 = c2;
1349
+ c2 = rotl_32(b2, 30);
1350
+ b2 = a2;
1351
+ a2 = T;
1352
+ }
1353
+ H2[0] = safeAdd_32_2(a2, H2[0]);
1354
+ H2[1] = safeAdd_32_2(b2, H2[1]);
1355
+ H2[2] = safeAdd_32_2(c2, H2[2]);
1356
+ H2[3] = safeAdd_32_2(d2, H2[3]);
1357
+ H2[4] = safeAdd_32_2(e2, H2[4]);
1358
+ return H2;
1359
+ }
1360
+ function finalizeSHA1(remainder, remainderBinLen, processedBinLen, H2) {
1361
+ let i2;
1362
+ const offset = (remainderBinLen + 65 >>> 9 << 4) + 15, totalLen = remainderBinLen + processedBinLen;
1363
+ while (remainder.length <= offset) {
1364
+ remainder.push(0);
1365
+ }
1366
+ remainder[remainderBinLen >>> 5] |= 128 << 24 - remainderBinLen % 32;
1367
+ remainder[offset] = totalLen & 4294967295;
1368
+ remainder[offset - 1] = totalLen / TWO_PWR_32 | 0;
1369
+ for (i2 = 0; i2 < remainder.length; i2 += 16) {
1370
+ H2 = roundSHA1(remainder.slice(i2, i2 + 16), H2);
1371
+ }
1372
+ return H2;
1373
+ }
1374
+ let jsSHA$4 = class jsSHA extends jsSHABase {
1375
+ constructor(variant, inputFormat, options) {
1376
+ if ("SHA-1" !== variant) {
1377
+ throw new Error(sha_variant_error);
1378
+ }
1379
+ super(variant, inputFormat, options);
1380
+ __publicField(this, "intermediateState");
1381
+ __publicField(this, "variantBlockSize");
1382
+ __publicField(this, "bigEndianMod");
1383
+ __publicField(this, "outputBinLen");
1384
+ __publicField(this, "isVariableLen");
1385
+ __publicField(this, "HMACSupported");
1386
+ __publicField(this, "converterFunc");
1387
+ __publicField(this, "roundFunc");
1388
+ __publicField(this, "finalizeFunc");
1389
+ __publicField(this, "stateCloneFunc");
1390
+ __publicField(this, "newStateFunc");
1391
+ __publicField(this, "getMAC");
1392
+ const resolvedOptions = options || {};
1393
+ this.HMACSupported = true;
1394
+ this.getMAC = this._getHMAC;
1395
+ this.bigEndianMod = -1;
1396
+ this.converterFunc = getStrConverter(this.inputFormat, this.utfType, this.bigEndianMod);
1397
+ this.roundFunc = roundSHA1;
1398
+ this.stateCloneFunc = function(state) {
1399
+ return state.slice();
1400
+ };
1401
+ this.newStateFunc = getNewState$1;
1402
+ this.finalizeFunc = finalizeSHA1;
1403
+ this.intermediateState = getNewState$1();
1404
+ this.variantBlockSize = 512;
1405
+ this.outputBinLen = 160;
1406
+ this.isVariableLen = false;
1407
+ if (resolvedOptions["hmacKey"]) {
1408
+ this._setHMACKey(parseInputOption("hmacKey", resolvedOptions["hmacKey"], this.bigEndianMod));
1409
+ }
1410
+ }
1411
+ };
1412
+ function getNewState256(variant) {
1413
+ let retVal;
1414
+ if ("SHA-224" === variant) {
1415
+ retVal = H_trunc.slice();
1416
+ } else {
1417
+ retVal = H_full.slice();
1418
+ }
1419
+ return retVal;
1420
+ }
1421
+ function roundSHA256(block, H2) {
1422
+ let a2, b2, c2, d2, e2, f2, g2, h2, T1, T2, t2;
1423
+ const W = [];
1424
+ a2 = H2[0];
1425
+ b2 = H2[1];
1426
+ c2 = H2[2];
1427
+ d2 = H2[3];
1428
+ e2 = H2[4];
1429
+ f2 = H2[5];
1430
+ g2 = H2[6];
1431
+ h2 = H2[7];
1432
+ for (t2 = 0; t2 < 64; t2 += 1) {
1433
+ if (t2 < 16) {
1434
+ W[t2] = block[t2];
1435
+ } else {
1436
+ W[t2] = safeAdd_32_4(gamma1_32(W[t2 - 2]), W[t2 - 7], gamma0_32(W[t2 - 15]), W[t2 - 16]);
1437
+ }
1438
+ T1 = safeAdd_32_5(h2, sigma1_32(e2), ch_32(e2, f2, g2), K_sha2[t2], W[t2]);
1439
+ T2 = safeAdd_32_2(sigma0_32(a2), maj_32(a2, b2, c2));
1440
+ h2 = g2;
1441
+ g2 = f2;
1442
+ f2 = e2;
1443
+ e2 = safeAdd_32_2(d2, T1);
1444
+ d2 = c2;
1445
+ c2 = b2;
1446
+ b2 = a2;
1447
+ a2 = safeAdd_32_2(T1, T2);
1448
+ }
1449
+ H2[0] = safeAdd_32_2(a2, H2[0]);
1450
+ H2[1] = safeAdd_32_2(b2, H2[1]);
1451
+ H2[2] = safeAdd_32_2(c2, H2[2]);
1452
+ H2[3] = safeAdd_32_2(d2, H2[3]);
1453
+ H2[4] = safeAdd_32_2(e2, H2[4]);
1454
+ H2[5] = safeAdd_32_2(f2, H2[5]);
1455
+ H2[6] = safeAdd_32_2(g2, H2[6]);
1456
+ H2[7] = safeAdd_32_2(h2, H2[7]);
1457
+ return H2;
1458
+ }
1459
+ function finalizeSHA256(remainder, remainderBinLen, processedBinLen, H2, variant) {
1460
+ let i2, retVal;
1461
+ const offset = (remainderBinLen + 65 >>> 9 << 4) + 15, binaryStringInc = 16, totalLen = remainderBinLen + processedBinLen;
1462
+ while (remainder.length <= offset) {
1463
+ remainder.push(0);
1464
+ }
1465
+ remainder[remainderBinLen >>> 5] |= 128 << 24 - remainderBinLen % 32;
1466
+ remainder[offset] = totalLen & 4294967295;
1467
+ remainder[offset - 1] = totalLen / TWO_PWR_32 | 0;
1468
+ for (i2 = 0; i2 < remainder.length; i2 += binaryStringInc) {
1469
+ H2 = roundSHA256(remainder.slice(i2, i2 + binaryStringInc), H2);
1470
+ }
1471
+ if ("SHA-224" === variant) {
1472
+ retVal = [H2[0], H2[1], H2[2], H2[3], H2[4], H2[5], H2[6]];
1473
+ } else {
1474
+ retVal = H2;
1475
+ }
1476
+ return retVal;
1477
+ }
1478
+ let jsSHA$3 = class jsSHA2 extends jsSHABase {
1479
+ constructor(variant, inputFormat, options) {
1480
+ if (!("SHA-224" === variant || "SHA-256" === variant)) {
1481
+ throw new Error(sha_variant_error);
1482
+ }
1483
+ super(variant, inputFormat, options);
1484
+ __publicField(this, "intermediateState");
1485
+ __publicField(this, "variantBlockSize");
1486
+ __publicField(this, "bigEndianMod");
1487
+ __publicField(this, "outputBinLen");
1488
+ __publicField(this, "isVariableLen");
1489
+ __publicField(this, "HMACSupported");
1490
+ __publicField(this, "converterFunc");
1491
+ __publicField(this, "roundFunc");
1492
+ __publicField(this, "finalizeFunc");
1493
+ __publicField(this, "stateCloneFunc");
1494
+ __publicField(this, "newStateFunc");
1495
+ __publicField(this, "getMAC");
1496
+ const resolvedOptions = options || {};
1497
+ this.getMAC = this._getHMAC;
1498
+ this.HMACSupported = true;
1499
+ this.bigEndianMod = -1;
1500
+ this.converterFunc = getStrConverter(this.inputFormat, this.utfType, this.bigEndianMod);
1501
+ this.roundFunc = roundSHA256;
1502
+ this.stateCloneFunc = function(state) {
1503
+ return state.slice();
1504
+ };
1505
+ this.newStateFunc = getNewState256;
1506
+ this.finalizeFunc = function(remainder, remainderBinLen, processedBinLen, H2) {
1507
+ return finalizeSHA256(remainder, remainderBinLen, processedBinLen, H2, variant);
1508
+ };
1509
+ this.intermediateState = getNewState256(variant);
1510
+ this.variantBlockSize = 512;
1511
+ this.outputBinLen = "SHA-224" === variant ? 224 : 256;
1512
+ this.isVariableLen = false;
1513
+ if (resolvedOptions["hmacKey"]) {
1514
+ this._setHMACKey(parseInputOption("hmacKey", resolvedOptions["hmacKey"], this.bigEndianMod));
1515
+ }
1516
+ }
1517
+ };
1518
+ class Int_64 {
1519
+ constructor(msint_32, lsint_32) {
1520
+ /**
1521
+ * @param msint_32 The most significant 32-bits of a 64-bit number.
1522
+ * @param lsint_32 The least significant 32-bits of a 64-bit number.
1523
+ */
1524
+ __publicField(this, "highOrder");
1525
+ __publicField(this, "lowOrder");
1526
+ this.highOrder = msint_32;
1527
+ this.lowOrder = lsint_32;
1528
+ }
1529
+ }
1530
+ function rotl_64(x, n2) {
1531
+ let tmp;
1532
+ if (n2 > 32) {
1533
+ tmp = 64 - n2;
1534
+ return new Int_64(x.lowOrder << n2 | x.highOrder >>> tmp, x.highOrder << n2 | x.lowOrder >>> tmp);
1535
+ } else if (0 !== n2) {
1536
+ tmp = 32 - n2;
1537
+ return new Int_64(x.highOrder << n2 | x.lowOrder >>> tmp, x.lowOrder << n2 | x.highOrder >>> tmp);
1538
+ } else {
1539
+ return x;
1540
+ }
1541
+ }
1542
+ function rotr_64(x, n2) {
1543
+ let tmp;
1544
+ if (n2 < 32) {
1545
+ tmp = 32 - n2;
1546
+ return new Int_64(x.highOrder >>> n2 | x.lowOrder << tmp, x.lowOrder >>> n2 | x.highOrder << tmp);
1547
+ } else {
1548
+ tmp = 64 - n2;
1549
+ return new Int_64(x.lowOrder >>> n2 | x.highOrder << tmp, x.highOrder >>> n2 | x.lowOrder << tmp);
1550
+ }
1551
+ }
1552
+ function shr_64(x, n2) {
1553
+ return new Int_64(x.highOrder >>> n2, x.lowOrder >>> n2 | x.highOrder << 32 - n2);
1554
+ }
1555
+ function ch_64(x, y, z) {
1556
+ return new Int_64(
1557
+ x.highOrder & y.highOrder ^ ~x.highOrder & z.highOrder,
1558
+ x.lowOrder & y.lowOrder ^ ~x.lowOrder & z.lowOrder
1559
+ );
1560
+ }
1561
+ function maj_64(x, y, z) {
1562
+ return new Int_64(
1563
+ x.highOrder & y.highOrder ^ x.highOrder & z.highOrder ^ y.highOrder & z.highOrder,
1564
+ x.lowOrder & y.lowOrder ^ x.lowOrder & z.lowOrder ^ y.lowOrder & z.lowOrder
1565
+ );
1566
+ }
1567
+ function sigma0_64(x) {
1568
+ const rotr28 = rotr_64(x, 28), rotr34 = rotr_64(x, 34), rotr39 = rotr_64(x, 39);
1569
+ return new Int_64(
1570
+ rotr28.highOrder ^ rotr34.highOrder ^ rotr39.highOrder,
1571
+ rotr28.lowOrder ^ rotr34.lowOrder ^ rotr39.lowOrder
1572
+ );
1573
+ }
1574
+ function safeAdd_64_2(x, y) {
1575
+ let lsw, msw;
1576
+ lsw = (x.lowOrder & 65535) + (y.lowOrder & 65535);
1577
+ msw = (x.lowOrder >>> 16) + (y.lowOrder >>> 16) + (lsw >>> 16);
1578
+ const lowOrder = (msw & 65535) << 16 | lsw & 65535;
1579
+ lsw = (x.highOrder & 65535) + (y.highOrder & 65535) + (msw >>> 16);
1580
+ msw = (x.highOrder >>> 16) + (y.highOrder >>> 16) + (lsw >>> 16);
1581
+ const highOrder = (msw & 65535) << 16 | lsw & 65535;
1582
+ return new Int_64(highOrder, lowOrder);
1583
+ }
1584
+ function safeAdd_64_4(a2, b2, c2, d2) {
1585
+ let lsw, msw;
1586
+ lsw = (a2.lowOrder & 65535) + (b2.lowOrder & 65535) + (c2.lowOrder & 65535) + (d2.lowOrder & 65535);
1587
+ msw = (a2.lowOrder >>> 16) + (b2.lowOrder >>> 16) + (c2.lowOrder >>> 16) + (d2.lowOrder >>> 16) + (lsw >>> 16);
1588
+ const lowOrder = (msw & 65535) << 16 | lsw & 65535;
1589
+ lsw = (a2.highOrder & 65535) + (b2.highOrder & 65535) + (c2.highOrder & 65535) + (d2.highOrder & 65535) + (msw >>> 16);
1590
+ msw = (a2.highOrder >>> 16) + (b2.highOrder >>> 16) + (c2.highOrder >>> 16) + (d2.highOrder >>> 16) + (lsw >>> 16);
1591
+ const highOrder = (msw & 65535) << 16 | lsw & 65535;
1592
+ return new Int_64(highOrder, lowOrder);
1593
+ }
1594
+ function safeAdd_64_5(a2, b2, c2, d2, e2) {
1595
+ let lsw, msw;
1596
+ lsw = (a2.lowOrder & 65535) + (b2.lowOrder & 65535) + (c2.lowOrder & 65535) + (d2.lowOrder & 65535) + (e2.lowOrder & 65535);
1597
+ msw = (a2.lowOrder >>> 16) + (b2.lowOrder >>> 16) + (c2.lowOrder >>> 16) + (d2.lowOrder >>> 16) + (e2.lowOrder >>> 16) + (lsw >>> 16);
1598
+ const lowOrder = (msw & 65535) << 16 | lsw & 65535;
1599
+ lsw = (a2.highOrder & 65535) + (b2.highOrder & 65535) + (c2.highOrder & 65535) + (d2.highOrder & 65535) + (e2.highOrder & 65535) + (msw >>> 16);
1600
+ msw = (a2.highOrder >>> 16) + (b2.highOrder >>> 16) + (c2.highOrder >>> 16) + (d2.highOrder >>> 16) + (e2.highOrder >>> 16) + (lsw >>> 16);
1601
+ const highOrder = (msw & 65535) << 16 | lsw & 65535;
1602
+ return new Int_64(highOrder, lowOrder);
1603
+ }
1604
+ function xor_64_2(a2, b2) {
1605
+ return new Int_64(a2.highOrder ^ b2.highOrder, a2.lowOrder ^ b2.lowOrder);
1606
+ }
1607
+ function xor_64_5(a2, b2, c2, d2, e2) {
1608
+ return new Int_64(
1609
+ a2.highOrder ^ b2.highOrder ^ c2.highOrder ^ d2.highOrder ^ e2.highOrder,
1610
+ a2.lowOrder ^ b2.lowOrder ^ c2.lowOrder ^ d2.lowOrder ^ e2.lowOrder
1611
+ );
1612
+ }
1613
+ function gamma1_64(x) {
1614
+ const rotr19 = rotr_64(x, 19), rotr61 = rotr_64(x, 61), shr6 = shr_64(x, 6);
1615
+ return new Int_64(
1616
+ rotr19.highOrder ^ rotr61.highOrder ^ shr6.highOrder,
1617
+ rotr19.lowOrder ^ rotr61.lowOrder ^ shr6.lowOrder
1618
+ );
1619
+ }
1620
+ function gamma0_64(x) {
1621
+ const rotr1 = rotr_64(x, 1), rotr8 = rotr_64(x, 8), shr7 = shr_64(x, 7);
1622
+ return new Int_64(
1623
+ rotr1.highOrder ^ rotr8.highOrder ^ shr7.highOrder,
1624
+ rotr1.lowOrder ^ rotr8.lowOrder ^ shr7.lowOrder
1625
+ );
1626
+ }
1627
+ function sigma1_64(x) {
1628
+ const rotr14 = rotr_64(x, 14), rotr18 = rotr_64(x, 18), rotr41 = rotr_64(x, 41);
1629
+ return new Int_64(
1630
+ rotr14.highOrder ^ rotr18.highOrder ^ rotr41.highOrder,
1631
+ rotr14.lowOrder ^ rotr18.lowOrder ^ rotr41.lowOrder
1632
+ );
1633
+ }
1634
+ const K_sha512 = [
1635
+ new Int_64(K_sha2[0], 3609767458),
1636
+ new Int_64(K_sha2[1], 602891725),
1637
+ new Int_64(K_sha2[2], 3964484399),
1638
+ new Int_64(K_sha2[3], 2173295548),
1639
+ new Int_64(K_sha2[4], 4081628472),
1640
+ new Int_64(K_sha2[5], 3053834265),
1641
+ new Int_64(K_sha2[6], 2937671579),
1642
+ new Int_64(K_sha2[7], 3664609560),
1643
+ new Int_64(K_sha2[8], 2734883394),
1644
+ new Int_64(K_sha2[9], 1164996542),
1645
+ new Int_64(K_sha2[10], 1323610764),
1646
+ new Int_64(K_sha2[11], 3590304994),
1647
+ new Int_64(K_sha2[12], 4068182383),
1648
+ new Int_64(K_sha2[13], 991336113),
1649
+ new Int_64(K_sha2[14], 633803317),
1650
+ new Int_64(K_sha2[15], 3479774868),
1651
+ new Int_64(K_sha2[16], 2666613458),
1652
+ new Int_64(K_sha2[17], 944711139),
1653
+ new Int_64(K_sha2[18], 2341262773),
1654
+ new Int_64(K_sha2[19], 2007800933),
1655
+ new Int_64(K_sha2[20], 1495990901),
1656
+ new Int_64(K_sha2[21], 1856431235),
1657
+ new Int_64(K_sha2[22], 3175218132),
1658
+ new Int_64(K_sha2[23], 2198950837),
1659
+ new Int_64(K_sha2[24], 3999719339),
1660
+ new Int_64(K_sha2[25], 766784016),
1661
+ new Int_64(K_sha2[26], 2566594879),
1662
+ new Int_64(K_sha2[27], 3203337956),
1663
+ new Int_64(K_sha2[28], 1034457026),
1664
+ new Int_64(K_sha2[29], 2466948901),
1665
+ new Int_64(K_sha2[30], 3758326383),
1666
+ new Int_64(K_sha2[31], 168717936),
1667
+ new Int_64(K_sha2[32], 1188179964),
1668
+ new Int_64(K_sha2[33], 1546045734),
1669
+ new Int_64(K_sha2[34], 1522805485),
1670
+ new Int_64(K_sha2[35], 2643833823),
1671
+ new Int_64(K_sha2[36], 2343527390),
1672
+ new Int_64(K_sha2[37], 1014477480),
1673
+ new Int_64(K_sha2[38], 1206759142),
1674
+ new Int_64(K_sha2[39], 344077627),
1675
+ new Int_64(K_sha2[40], 1290863460),
1676
+ new Int_64(K_sha2[41], 3158454273),
1677
+ new Int_64(K_sha2[42], 3505952657),
1678
+ new Int_64(K_sha2[43], 106217008),
1679
+ new Int_64(K_sha2[44], 3606008344),
1680
+ new Int_64(K_sha2[45], 1432725776),
1681
+ new Int_64(K_sha2[46], 1467031594),
1682
+ new Int_64(K_sha2[47], 851169720),
1683
+ new Int_64(K_sha2[48], 3100823752),
1684
+ new Int_64(K_sha2[49], 1363258195),
1685
+ new Int_64(K_sha2[50], 3750685593),
1686
+ new Int_64(K_sha2[51], 3785050280),
1687
+ new Int_64(K_sha2[52], 3318307427),
1688
+ new Int_64(K_sha2[53], 3812723403),
1689
+ new Int_64(K_sha2[54], 2003034995),
1690
+ new Int_64(K_sha2[55], 3602036899),
1691
+ new Int_64(K_sha2[56], 1575990012),
1692
+ new Int_64(K_sha2[57], 1125592928),
1693
+ new Int_64(K_sha2[58], 2716904306),
1694
+ new Int_64(K_sha2[59], 442776044),
1695
+ new Int_64(K_sha2[60], 593698344),
1696
+ new Int_64(K_sha2[61], 3733110249),
1697
+ new Int_64(K_sha2[62], 2999351573),
1698
+ new Int_64(K_sha2[63], 3815920427),
1699
+ new Int_64(3391569614, 3928383900),
1700
+ new Int_64(3515267271, 566280711),
1701
+ new Int_64(3940187606, 3454069534),
1702
+ new Int_64(4118630271, 4000239992),
1703
+ new Int_64(116418474, 1914138554),
1704
+ new Int_64(174292421, 2731055270),
1705
+ new Int_64(289380356, 3203993006),
1706
+ new Int_64(460393269, 320620315),
1707
+ new Int_64(685471733, 587496836),
1708
+ new Int_64(852142971, 1086792851),
1709
+ new Int_64(1017036298, 365543100),
1710
+ new Int_64(1126000580, 2618297676),
1711
+ new Int_64(1288033470, 3409855158),
1712
+ new Int_64(1501505948, 4234509866),
1713
+ new Int_64(1607167915, 987167468),
1714
+ new Int_64(1816402316, 1246189591)
1715
+ ];
1716
+ function getNewState512(variant) {
1717
+ if ("SHA-384" === variant) {
1718
+ return [
1719
+ new Int_64(3418070365, H_trunc[0]),
1720
+ new Int_64(1654270250, H_trunc[1]),
1721
+ new Int_64(2438529370, H_trunc[2]),
1722
+ new Int_64(355462360, H_trunc[3]),
1723
+ new Int_64(1731405415, H_trunc[4]),
1724
+ new Int_64(41048885895, H_trunc[5]),
1725
+ new Int_64(3675008525, H_trunc[6]),
1726
+ new Int_64(1203062813, H_trunc[7])
1727
+ ];
1728
+ } else {
1729
+ return [
1730
+ new Int_64(H_full[0], 4089235720),
1731
+ new Int_64(H_full[1], 2227873595),
1732
+ new Int_64(H_full[2], 4271175723),
1733
+ new Int_64(H_full[3], 1595750129),
1734
+ new Int_64(H_full[4], 2917565137),
1735
+ new Int_64(H_full[5], 725511199),
1736
+ new Int_64(H_full[6], 4215389547),
1737
+ new Int_64(H_full[7], 327033209)
1738
+ ];
1739
+ }
1740
+ }
1741
+ function roundSHA512(block, H2) {
1742
+ let a2, b2, c2, d2, e2, f2, g2, h2, T1, T2, t2, offset;
1743
+ const W = [];
1744
+ a2 = H2[0];
1745
+ b2 = H2[1];
1746
+ c2 = H2[2];
1747
+ d2 = H2[3];
1748
+ e2 = H2[4];
1749
+ f2 = H2[5];
1750
+ g2 = H2[6];
1751
+ h2 = H2[7];
1752
+ for (t2 = 0; t2 < 80; t2 += 1) {
1753
+ if (t2 < 16) {
1754
+ offset = t2 * 2;
1755
+ W[t2] = new Int_64(block[offset], block[offset + 1]);
1756
+ } else {
1757
+ W[t2] = safeAdd_64_4(gamma1_64(W[t2 - 2]), W[t2 - 7], gamma0_64(W[t2 - 15]), W[t2 - 16]);
1758
+ }
1759
+ T1 = safeAdd_64_5(h2, sigma1_64(e2), ch_64(e2, f2, g2), K_sha512[t2], W[t2]);
1760
+ T2 = safeAdd_64_2(sigma0_64(a2), maj_64(a2, b2, c2));
1761
+ h2 = g2;
1762
+ g2 = f2;
1763
+ f2 = e2;
1764
+ e2 = safeAdd_64_2(d2, T1);
1765
+ d2 = c2;
1766
+ c2 = b2;
1767
+ b2 = a2;
1768
+ a2 = safeAdd_64_2(T1, T2);
1769
+ }
1770
+ H2[0] = safeAdd_64_2(a2, H2[0]);
1771
+ H2[1] = safeAdd_64_2(b2, H2[1]);
1772
+ H2[2] = safeAdd_64_2(c2, H2[2]);
1773
+ H2[3] = safeAdd_64_2(d2, H2[3]);
1774
+ H2[4] = safeAdd_64_2(e2, H2[4]);
1775
+ H2[5] = safeAdd_64_2(f2, H2[5]);
1776
+ H2[6] = safeAdd_64_2(g2, H2[6]);
1777
+ H2[7] = safeAdd_64_2(h2, H2[7]);
1778
+ return H2;
1779
+ }
1780
+ function finalizeSHA512(remainder, remainderBinLen, processedBinLen, H2, variant) {
1781
+ let i2, retVal;
1782
+ const offset = (remainderBinLen + 129 >>> 10 << 5) + 31, binaryStringInc = 32, totalLen = remainderBinLen + processedBinLen;
1783
+ while (remainder.length <= offset) {
1784
+ remainder.push(0);
1785
+ }
1786
+ remainder[remainderBinLen >>> 5] |= 128 << 24 - remainderBinLen % 32;
1787
+ remainder[offset] = totalLen & 4294967295;
1788
+ remainder[offset - 1] = totalLen / TWO_PWR_32 | 0;
1789
+ for (i2 = 0; i2 < remainder.length; i2 += binaryStringInc) {
1790
+ H2 = roundSHA512(remainder.slice(i2, i2 + binaryStringInc), H2);
1791
+ }
1792
+ if ("SHA-384" === variant) {
1793
+ H2 = H2;
1794
+ retVal = [
1795
+ H2[0].highOrder,
1796
+ H2[0].lowOrder,
1797
+ H2[1].highOrder,
1798
+ H2[1].lowOrder,
1799
+ H2[2].highOrder,
1800
+ H2[2].lowOrder,
1801
+ H2[3].highOrder,
1802
+ H2[3].lowOrder,
1803
+ H2[4].highOrder,
1804
+ H2[4].lowOrder,
1805
+ H2[5].highOrder,
1806
+ H2[5].lowOrder
1807
+ ];
1808
+ } else {
1809
+ retVal = [
1810
+ H2[0].highOrder,
1811
+ H2[0].lowOrder,
1812
+ H2[1].highOrder,
1813
+ H2[1].lowOrder,
1814
+ H2[2].highOrder,
1815
+ H2[2].lowOrder,
1816
+ H2[3].highOrder,
1817
+ H2[3].lowOrder,
1818
+ H2[4].highOrder,
1819
+ H2[4].lowOrder,
1820
+ H2[5].highOrder,
1821
+ H2[5].lowOrder,
1822
+ H2[6].highOrder,
1823
+ H2[6].lowOrder,
1824
+ H2[7].highOrder,
1825
+ H2[7].lowOrder
1826
+ ];
1827
+ }
1828
+ return retVal;
1829
+ }
1830
+ let jsSHA$2 = class jsSHA3 extends jsSHABase {
1831
+ constructor(variant, inputFormat, options) {
1832
+ if (!("SHA-384" === variant || "SHA-512" === variant)) {
1833
+ throw new Error(sha_variant_error);
1834
+ }
1835
+ super(variant, inputFormat, options);
1836
+ __publicField(this, "intermediateState");
1837
+ __publicField(this, "variantBlockSize");
1838
+ __publicField(this, "bigEndianMod");
1839
+ __publicField(this, "outputBinLen");
1840
+ __publicField(this, "isVariableLen");
1841
+ __publicField(this, "HMACSupported");
1842
+ __publicField(this, "converterFunc");
1843
+ __publicField(this, "roundFunc");
1844
+ __publicField(this, "finalizeFunc");
1845
+ __publicField(this, "stateCloneFunc");
1846
+ __publicField(this, "newStateFunc");
1847
+ __publicField(this, "getMAC");
1848
+ const resolvedOptions = options || {};
1849
+ this.getMAC = this._getHMAC;
1850
+ this.HMACSupported = true;
1851
+ this.bigEndianMod = -1;
1852
+ this.converterFunc = getStrConverter(this.inputFormat, this.utfType, this.bigEndianMod);
1853
+ this.roundFunc = roundSHA512;
1854
+ this.stateCloneFunc = function(state) {
1855
+ return state.slice();
1856
+ };
1857
+ this.newStateFunc = getNewState512;
1858
+ this.finalizeFunc = function(remainder, remainderBinLen, processedBinLen, H2) {
1859
+ return finalizeSHA512(remainder, remainderBinLen, processedBinLen, H2, variant);
1860
+ };
1861
+ this.intermediateState = getNewState512(variant);
1862
+ this.variantBlockSize = 1024;
1863
+ this.outputBinLen = "SHA-384" === variant ? 384 : 512;
1864
+ this.isVariableLen = false;
1865
+ if (resolvedOptions["hmacKey"]) {
1866
+ this._setHMACKey(parseInputOption("hmacKey", resolvedOptions["hmacKey"], this.bigEndianMod));
1867
+ }
1868
+ }
1869
+ };
1870
+ const rc_sha3 = [
1871
+ new Int_64(0, 1),
1872
+ new Int_64(0, 32898),
1873
+ new Int_64(2147483648, 32906),
1874
+ new Int_64(2147483648, 2147516416),
1875
+ new Int_64(0, 32907),
1876
+ new Int_64(0, 2147483649),
1877
+ new Int_64(2147483648, 2147516545),
1878
+ new Int_64(2147483648, 32777),
1879
+ new Int_64(0, 138),
1880
+ new Int_64(0, 136),
1881
+ new Int_64(0, 2147516425),
1882
+ new Int_64(0, 2147483658),
1883
+ new Int_64(0, 2147516555),
1884
+ new Int_64(2147483648, 139),
1885
+ new Int_64(2147483648, 32905),
1886
+ new Int_64(2147483648, 32771),
1887
+ new Int_64(2147483648, 32770),
1888
+ new Int_64(2147483648, 128),
1889
+ new Int_64(0, 32778),
1890
+ new Int_64(2147483648, 2147483658),
1891
+ new Int_64(2147483648, 2147516545),
1892
+ new Int_64(2147483648, 32896),
1893
+ new Int_64(0, 2147483649),
1894
+ new Int_64(2147483648, 2147516424)
1895
+ ];
1896
+ const r_sha3 = [
1897
+ [0, 36, 3, 41, 18],
1898
+ [1, 44, 10, 45, 2],
1899
+ [62, 6, 43, 15, 61],
1900
+ [28, 55, 25, 21, 56],
1901
+ [27, 20, 39, 8, 14]
1902
+ ];
1903
+ function getNewState(_variant) {
1904
+ let i2;
1905
+ const retVal = [];
1906
+ for (i2 = 0; i2 < 5; i2 += 1) {
1907
+ retVal[i2] = [new Int_64(0, 0), new Int_64(0, 0), new Int_64(0, 0), new Int_64(0, 0), new Int_64(0, 0)];
1908
+ }
1909
+ return retVal;
1910
+ }
1911
+ function cloneSHA3State(state) {
1912
+ let i2;
1913
+ const clone = [];
1914
+ for (i2 = 0; i2 < 5; i2 += 1) {
1915
+ clone[i2] = state[i2].slice();
1916
+ }
1917
+ return clone;
1918
+ }
1919
+ function roundSHA3(block, state) {
1920
+ let round, x, y, B;
1921
+ const C2 = [], D = [];
1922
+ if (null != block) {
1923
+ for (x = 0; x < block.length; x += 2) {
1924
+ state[(x >>> 1) % 5][(x >>> 1) / 5 | 0] = xor_64_2(
1925
+ state[(x >>> 1) % 5][(x >>> 1) / 5 | 0],
1926
+ new Int_64(block[x + 1], block[x])
1927
+ );
1928
+ }
1929
+ }
1930
+ for (round = 0; round < 24; round += 1) {
1931
+ B = getNewState();
1932
+ for (x = 0; x < 5; x += 1) {
1933
+ C2[x] = xor_64_5(state[x][0], state[x][1], state[x][2], state[x][3], state[x][4]);
1934
+ }
1935
+ for (x = 0; x < 5; x += 1) {
1936
+ D[x] = xor_64_2(C2[(x + 4) % 5], rotl_64(C2[(x + 1) % 5], 1));
1937
+ }
1938
+ for (x = 0; x < 5; x += 1) {
1939
+ for (y = 0; y < 5; y += 1) {
1940
+ state[x][y] = xor_64_2(state[x][y], D[x]);
1941
+ }
1942
+ }
1943
+ for (x = 0; x < 5; x += 1) {
1944
+ for (y = 0; y < 5; y += 1) {
1945
+ B[y][(2 * x + 3 * y) % 5] = rotl_64(state[x][y], r_sha3[x][y]);
1946
+ }
1947
+ }
1948
+ for (x = 0; x < 5; x += 1) {
1949
+ for (y = 0; y < 5; y += 1) {
1950
+ state[x][y] = xor_64_2(
1951
+ B[x][y],
1952
+ new Int_64(
1953
+ ~B[(x + 1) % 5][y].highOrder & B[(x + 2) % 5][y].highOrder,
1954
+ ~B[(x + 1) % 5][y].lowOrder & B[(x + 2) % 5][y].lowOrder
1955
+ )
1956
+ );
1957
+ }
1958
+ }
1959
+ state[0][0] = xor_64_2(state[0][0], rc_sha3[round]);
1960
+ }
1961
+ return state;
1962
+ }
1963
+ function finalizeSHA3(remainder, remainderBinLen, _processedBinLen, state, blockSize, delimiter, outputLen) {
1964
+ let i2, state_offset = 0, temp;
1965
+ const retVal = [], binaryStringInc = blockSize >>> 5, remainderIntLen = remainderBinLen >>> 5;
1966
+ for (i2 = 0; i2 < remainderIntLen && remainderBinLen >= blockSize; i2 += binaryStringInc) {
1967
+ state = roundSHA3(remainder.slice(i2, i2 + binaryStringInc), state);
1968
+ remainderBinLen -= blockSize;
1969
+ }
1970
+ remainder = remainder.slice(i2);
1971
+ remainderBinLen = remainderBinLen % blockSize;
1972
+ while (remainder.length < binaryStringInc) {
1973
+ remainder.push(0);
1974
+ }
1975
+ i2 = remainderBinLen >>> 3;
1976
+ remainder[i2 >> 2] ^= delimiter << 8 * (i2 % 4);
1977
+ remainder[binaryStringInc - 1] ^= 2147483648;
1978
+ state = roundSHA3(remainder, state);
1979
+ while (retVal.length * 32 < outputLen) {
1980
+ temp = state[state_offset % 5][state_offset / 5 | 0];
1981
+ retVal.push(temp.lowOrder);
1982
+ if (retVal.length * 32 >= outputLen) {
1983
+ break;
1984
+ }
1985
+ retVal.push(temp.highOrder);
1986
+ state_offset += 1;
1987
+ if (0 === state_offset * 64 % blockSize) {
1988
+ roundSHA3(null, state);
1989
+ state_offset = 0;
1990
+ }
1991
+ }
1992
+ return retVal;
1993
+ }
1994
+ function left_encode(x) {
1995
+ let byteOffset, byte, numEncodedBytes = 0;
1996
+ const retVal = [0, 0], x_64 = [x & 4294967295, x / TWO_PWR_32 & 2097151];
1997
+ for (byteOffset = 6; byteOffset >= 0; byteOffset--) {
1998
+ byte = x_64[byteOffset >> 2] >>> 8 * byteOffset & 255;
1999
+ if (byte !== 0 || numEncodedBytes !== 0) {
2000
+ retVal[numEncodedBytes + 1 >> 2] |= byte << (numEncodedBytes + 1) * 8;
2001
+ numEncodedBytes += 1;
2002
+ }
2003
+ }
2004
+ numEncodedBytes = numEncodedBytes !== 0 ? numEncodedBytes : 1;
2005
+ retVal[0] |= numEncodedBytes;
2006
+ return { value: numEncodedBytes + 1 > 4 ? retVal : [retVal[0]], binLen: 8 + numEncodedBytes * 8 };
2007
+ }
2008
+ function right_encode(x) {
2009
+ let byteOffset, byte, numEncodedBytes = 0;
2010
+ const retVal = [0, 0], x_64 = [x & 4294967295, x / TWO_PWR_32 & 2097151];
2011
+ for (byteOffset = 6; byteOffset >= 0; byteOffset--) {
2012
+ byte = x_64[byteOffset >> 2] >>> 8 * byteOffset & 255;
2013
+ if (byte !== 0 || numEncodedBytes !== 0) {
2014
+ retVal[numEncodedBytes >> 2] |= byte << numEncodedBytes * 8;
2015
+ numEncodedBytes += 1;
2016
+ }
2017
+ }
2018
+ numEncodedBytes = numEncodedBytes !== 0 ? numEncodedBytes : 1;
2019
+ retVal[numEncodedBytes >> 2] |= numEncodedBytes << numEncodedBytes * 8;
2020
+ return { value: numEncodedBytes + 1 > 4 ? retVal : [retVal[0]], binLen: 8 + numEncodedBytes * 8 };
2021
+ }
2022
+ function encode_string(input) {
2023
+ return packedLEConcat(left_encode(input["binLen"]), input);
2024
+ }
2025
+ function byte_pad(packed, outputByteLen) {
2026
+ let encodedLen = left_encode(outputByteLen), i2;
2027
+ encodedLen = packedLEConcat(encodedLen, packed);
2028
+ const outputIntLen = outputByteLen >>> 2, intsToAppend = (outputIntLen - encodedLen["value"].length % outputIntLen) % outputIntLen;
2029
+ for (i2 = 0; i2 < intsToAppend; i2++) {
2030
+ encodedLen["value"].push(0);
2031
+ }
2032
+ return encodedLen["value"];
2033
+ }
2034
+ function resolveCSHAKEOptions(options) {
2035
+ const resolvedOptions = options || {};
2036
+ return {
2037
+ funcName: parseInputOption("funcName", resolvedOptions["funcName"], 1, { value: [], binLen: 0 }),
2038
+ customization: parseInputOption("Customization", resolvedOptions["customization"], 1, { value: [], binLen: 0 })
2039
+ };
2040
+ }
2041
+ function resolveKMACOptions(options) {
2042
+ const resolvedOptions = options || {};
2043
+ return {
2044
+ kmacKey: parseInputOption("kmacKey", resolvedOptions["kmacKey"], 1),
2045
+ /* This is little-endian packed "KMAC" */
2046
+ funcName: { value: [1128353099], binLen: 32 },
2047
+ customization: parseInputOption("Customization", resolvedOptions["customization"], 1, { value: [], binLen: 0 })
2048
+ };
2049
+ }
2050
+ let jsSHA$1 = class jsSHA4 extends jsSHABase {
2051
+ constructor(variant, inputFormat, options) {
2052
+ let delimiter = 6, variantBlockSize = 0;
2053
+ super(variant, inputFormat, options);
2054
+ __publicField(this, "intermediateState");
2055
+ __publicField(this, "variantBlockSize");
2056
+ __publicField(this, "bigEndianMod");
2057
+ __publicField(this, "outputBinLen");
2058
+ __publicField(this, "isVariableLen");
2059
+ __publicField(this, "HMACSupported");
2060
+ __publicField(this, "converterFunc");
2061
+ __publicField(this, "roundFunc");
2062
+ __publicField(this, "finalizeFunc");
2063
+ __publicField(this, "stateCloneFunc");
2064
+ __publicField(this, "newStateFunc");
2065
+ __publicField(this, "getMAC");
2066
+ const resolvedOptions = options || {};
2067
+ if (this.numRounds !== 1) {
2068
+ if (resolvedOptions["kmacKey"] || resolvedOptions["hmacKey"]) {
2069
+ throw new Error(mac_rounds_error);
2070
+ } else if (this.shaVariant === "CSHAKE128" || this.shaVariant === "CSHAKE256") {
2071
+ throw new Error("Cannot set numRounds for CSHAKE variants");
2072
+ }
2073
+ }
2074
+ this.bigEndianMod = 1;
2075
+ this.converterFunc = getStrConverter(this.inputFormat, this.utfType, this.bigEndianMod);
2076
+ this.roundFunc = roundSHA3;
2077
+ this.stateCloneFunc = cloneSHA3State;
2078
+ this.newStateFunc = getNewState;
2079
+ this.intermediateState = getNewState();
2080
+ this.isVariableLen = false;
2081
+ switch (variant) {
2082
+ case "SHA3-224":
2083
+ this.variantBlockSize = variantBlockSize = 1152;
2084
+ this.outputBinLen = 224;
2085
+ this.HMACSupported = true;
2086
+ this.getMAC = this._getHMAC;
2087
+ break;
2088
+ case "SHA3-256":
2089
+ this.variantBlockSize = variantBlockSize = 1088;
2090
+ this.outputBinLen = 256;
2091
+ this.HMACSupported = true;
2092
+ this.getMAC = this._getHMAC;
2093
+ break;
2094
+ case "SHA3-384":
2095
+ this.variantBlockSize = variantBlockSize = 832;
2096
+ this.outputBinLen = 384;
2097
+ this.HMACSupported = true;
2098
+ this.getMAC = this._getHMAC;
2099
+ break;
2100
+ case "SHA3-512":
2101
+ this.variantBlockSize = variantBlockSize = 576;
2102
+ this.outputBinLen = 512;
2103
+ this.HMACSupported = true;
2104
+ this.getMAC = this._getHMAC;
2105
+ break;
2106
+ case "SHAKE128":
2107
+ delimiter = 31;
2108
+ this.variantBlockSize = variantBlockSize = 1344;
2109
+ this.outputBinLen = -1;
2110
+ this.isVariableLen = true;
2111
+ this.HMACSupported = false;
2112
+ this.getMAC = null;
2113
+ break;
2114
+ case "SHAKE256":
2115
+ delimiter = 31;
2116
+ this.variantBlockSize = variantBlockSize = 1088;
2117
+ this.outputBinLen = -1;
2118
+ this.isVariableLen = true;
2119
+ this.HMACSupported = false;
2120
+ this.getMAC = null;
2121
+ break;
2122
+ case "KMAC128":
2123
+ delimiter = 4;
2124
+ this.variantBlockSize = variantBlockSize = 1344;
2125
+ this._initializeKMAC(options);
2126
+ this.outputBinLen = -1;
2127
+ this.isVariableLen = true;
2128
+ this.HMACSupported = false;
2129
+ this.getMAC = this._getKMAC;
2130
+ break;
2131
+ case "KMAC256":
2132
+ delimiter = 4;
2133
+ this.variantBlockSize = variantBlockSize = 1088;
2134
+ this._initializeKMAC(options);
2135
+ this.outputBinLen = -1;
2136
+ this.isVariableLen = true;
2137
+ this.HMACSupported = false;
2138
+ this.getMAC = this._getKMAC;
2139
+ break;
2140
+ case "CSHAKE128":
2141
+ this.variantBlockSize = variantBlockSize = 1344;
2142
+ delimiter = this._initializeCSHAKE(options);
2143
+ this.outputBinLen = -1;
2144
+ this.isVariableLen = true;
2145
+ this.HMACSupported = false;
2146
+ this.getMAC = null;
2147
+ break;
2148
+ case "CSHAKE256":
2149
+ this.variantBlockSize = variantBlockSize = 1088;
2150
+ delimiter = this._initializeCSHAKE(options);
2151
+ this.outputBinLen = -1;
2152
+ this.isVariableLen = true;
2153
+ this.HMACSupported = false;
2154
+ this.getMAC = null;
2155
+ break;
2156
+ default:
2157
+ throw new Error(sha_variant_error);
2158
+ }
2159
+ this.finalizeFunc = function(remainder, remainderBinLen, processedBinLen, state, outputBinLen) {
2160
+ return finalizeSHA3(
2161
+ remainder,
2162
+ remainderBinLen,
2163
+ processedBinLen,
2164
+ state,
2165
+ variantBlockSize,
2166
+ delimiter,
2167
+ outputBinLen
2168
+ );
2169
+ };
2170
+ if (resolvedOptions["hmacKey"]) {
2171
+ this._setHMACKey(parseInputOption("hmacKey", resolvedOptions["hmacKey"], this.bigEndianMod));
2172
+ }
2173
+ }
2174
+ /**
2175
+ * Initialize CSHAKE variants.
2176
+ *
2177
+ * @param options Options containing CSHAKE params.
2178
+ * @param funcNameOverride Overrides any "funcName" present in `options` (used with KMAC)
2179
+ * @returns The delimiter to be used
2180
+ */
2181
+ _initializeCSHAKE(options, funcNameOverride) {
2182
+ const resolvedOptions = resolveCSHAKEOptions(options || {});
2183
+ if (funcNameOverride) {
2184
+ resolvedOptions["funcName"] = funcNameOverride;
2185
+ }
2186
+ const packedParams = packedLEConcat(
2187
+ encode_string(resolvedOptions["funcName"]),
2188
+ encode_string(resolvedOptions["customization"])
2189
+ );
2190
+ if (resolvedOptions["customization"]["binLen"] !== 0 || resolvedOptions["funcName"]["binLen"] !== 0) {
2191
+ const byte_pad_out = byte_pad(packedParams, this.variantBlockSize >>> 3);
2192
+ for (let i2 = 0; i2 < byte_pad_out.length; i2 += this.variantBlockSize >>> 5) {
2193
+ this.intermediateState = this.roundFunc(
2194
+ byte_pad_out.slice(i2, i2 + (this.variantBlockSize >>> 5)),
2195
+ this.intermediateState
2196
+ );
2197
+ this.processedLen += this.variantBlockSize;
2198
+ }
2199
+ return 4;
2200
+ } else {
2201
+ return 31;
2202
+ }
2203
+ }
2204
+ /**
2205
+ * Initialize KMAC variants.
2206
+ *
2207
+ * @param options Options containing KMAC params.
2208
+ */
2209
+ _initializeKMAC(options) {
2210
+ const resolvedOptions = resolveKMACOptions(options || {});
2211
+ this._initializeCSHAKE(options, resolvedOptions["funcName"]);
2212
+ const byte_pad_out = byte_pad(encode_string(resolvedOptions["kmacKey"]), this.variantBlockSize >>> 3);
2213
+ for (let i2 = 0; i2 < byte_pad_out.length; i2 += this.variantBlockSize >>> 5) {
2214
+ this.intermediateState = this.roundFunc(
2215
+ byte_pad_out.slice(i2, i2 + (this.variantBlockSize >>> 5)),
2216
+ this.intermediateState
2217
+ );
2218
+ this.processedLen += this.variantBlockSize;
2219
+ }
2220
+ this.macKeySet = true;
2221
+ }
2222
+ /**
2223
+ * Returns the the KMAC in the specified format.
2224
+ *
2225
+ * @param options Hashmap of extra outputs options. `outputLen` must be specified.
2226
+ * @returns The KMAC in the format specified.
2227
+ */
2228
+ _getKMAC(options) {
2229
+ const concatedRemainder = packedLEConcat(
2230
+ { value: this.remainder.slice(), binLen: this.remainderLen },
2231
+ right_encode(options["outputLen"])
2232
+ );
2233
+ return this.finalizeFunc(
2234
+ concatedRemainder["value"],
2235
+ concatedRemainder["binLen"],
2236
+ this.processedLen,
2237
+ this.stateCloneFunc(this.intermediateState),
2238
+ options["outputLen"]
2239
+ );
2240
+ }
2241
+ };
2242
+ class jsSHA5 {
2243
+ constructor(variant, inputFormat, options) {
2244
+ __publicField(this, "shaObj");
2245
+ if ("SHA-1" === variant) {
2246
+ this.shaObj = new jsSHA$4(variant, inputFormat, options);
2247
+ } else if ("SHA-224" === variant || "SHA-256" === variant) {
2248
+ this.shaObj = new jsSHA$3(variant, inputFormat, options);
2249
+ } else if ("SHA-384" === variant || "SHA-512" === variant) {
2250
+ this.shaObj = new jsSHA$2(variant, inputFormat, options);
2251
+ } else if ("SHA3-224" === variant || "SHA3-256" === variant || "SHA3-384" === variant || "SHA3-512" === variant || "SHAKE128" === variant || "SHAKE256" === variant || "CSHAKE128" === variant || "CSHAKE256" === variant || "KMAC128" === variant || "KMAC256" === variant) {
2252
+ this.shaObj = new jsSHA$1(variant, inputFormat, options);
2253
+ } else {
2254
+ throw new Error(sha_variant_error);
2255
+ }
2256
+ }
2257
+ /**
2258
+ * Takes `input` and hashes as many blocks as possible. Stores the rest for either a future `update` or `getHash` call.
2259
+ *
2260
+ * @param input The input to be hashed.
2261
+ * @returns A reference to the object.
2262
+ */
2263
+ update(input) {
2264
+ this.shaObj.update(input);
2265
+ return this;
2266
+ }
2267
+ getHash(format, options) {
2268
+ return this.shaObj.getHash(format, options);
2269
+ }
2270
+ setHMACKey(key, inputFormat, options) {
2271
+ this.shaObj.setHMACKey(key, inputFormat, options);
2272
+ }
2273
+ getHMAC(format, options) {
2274
+ return this.shaObj.getHMAC(format, options);
2275
+ }
2276
+ }
2277
+ class TOTP {
2278
+ static generate(key, options) {
2279
+ const _options = {
2280
+ digits: 6,
2281
+ algorithm: "SHA-1",
2282
+ period: 30,
2283
+ timestamp: Date.now(),
2284
+ ...options
2285
+ };
2286
+ const epoch = Math.floor(_options.timestamp / 1e3);
2287
+ const time = this.leftpad(this.dec2hex(Math.floor(epoch / _options.period)), 16, "0");
2288
+ const shaObj = new jsSHA5(_options.algorithm, "HEX");
2289
+ shaObj.setHMACKey(this.base32tohex(key), "HEX");
2290
+ shaObj.update(time);
2291
+ const hmac = shaObj.getHMAC("HEX");
2292
+ const offset = this.hex2dec(hmac.substring(hmac.length - 1));
2293
+ let otp = (this.hex2dec(hmac.substr(offset * 2, 8)) & this.hex2dec("7fffffff")) + "";
2294
+ const start = Math.max(otp.length - _options.digits, 0);
2295
+ otp = otp.substring(start, start + _options.digits);
2296
+ const expires = Math.ceil((_options.timestamp + 1) / (_options.period * 1e3)) * _options.period * 1e3;
2297
+ return { otp, expires };
2298
+ }
2299
+ static hex2dec(hex) {
2300
+ return parseInt(hex, 16);
2301
+ }
2302
+ static dec2hex(dec) {
2303
+ return (dec < 15.5 ? "0" : "") + Math.round(dec).toString(16);
2304
+ }
2305
+ static base32tohex(base32) {
2306
+ const base32chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
2307
+ let bits = "";
2308
+ let hex = "";
2309
+ const _base32 = base32.replace(/=+$/, "");
2310
+ for (let i2 = 0; i2 < _base32.length; i2++) {
2311
+ const val = base32chars.indexOf(base32.charAt(i2).toUpperCase());
2312
+ if (val === -1) throw new Error("Invalid base32 character in key");
2313
+ bits += this.leftpad(val.toString(2), 5, "0");
2314
+ }
2315
+ for (let i2 = 0; i2 + 8 <= bits.length; i2 += 8) {
2316
+ const chunk = bits.substr(i2, 8);
2317
+ hex = hex + this.leftpad(parseInt(chunk, 2).toString(16), 2, "0");
2318
+ }
2319
+ return hex;
2320
+ }
2321
+ static leftpad(str, len, pad) {
2322
+ if (len + 1 >= str.length) {
2323
+ str = Array(len + 1 - str.length).join(pad) + str;
2324
+ }
2325
+ return str;
2326
+ }
2327
+ }
2328
+ const localStorageSetItem = (name, value) => {
2329
+ if (!isClient) return;
2330
+ localStorage.setItem(name, value);
2331
+ };
2332
+ const localStorageGetItem = (name) => {
2333
+ if (!isClient) return "";
2334
+ return localStorage.getItem(name) || "";
2335
+ };
2336
+ function formatDuration(time) {
2337
+ return time < 10 ? `0${time}` : time;
2338
+ }
2339
+ function timestampToTime(timestamp) {
2340
+ let date = /* @__PURE__ */ new Date();
2341
+ if (timestamp) {
2342
+ date = new Date(timestamp);
2343
+ }
2344
+ date.format = (format = "YYYY-MM-DD HH:mm:ss") => {
2345
+ const year = date.getFullYear();
2346
+ const month = formatDuration(date.getMonth() + 1);
2347
+ const day = formatDuration(date.getDate());
2348
+ const hour = formatDuration(date.getHours());
2349
+ const minute = formatDuration(date.getMinutes());
2350
+ const second = formatDuration(date.getSeconds());
2351
+ return format.replace(/Y+/gi, `${year}`).replace(/M+/g, `${month}`).replace(/D+/gi, `${day}`).replace(/H+/gi, `${hour}`).replace(/m+/g, `${minute}`).replace(/S+/gi, `${second}`);
2352
+ };
2353
+ return date;
2354
+ }
2355
+ const timeFormat = (time) => {
2356
+ if (time === 0) return "00:00";
2357
+ if (!time) return "";
2358
+ const hour = Math.trunc(time / 3600);
2359
+ const minute = Math.trunc(time % 3600 / 60);
2360
+ const second = formatDuration(Math.trunc(time - hour * 3600 - minute * 60));
2361
+ if (hour === 0) {
2362
+ return `${formatDuration(minute)}:${second}`;
2363
+ }
2364
+ return `${formatDuration(hour)}:${formatDuration(minute)}:${second}`;
2365
+ };
2366
+ const performanceTime = () => {
2367
+ if (typeof document !== "undefined") {
2368
+ return performance.now();
2369
+ }
2370
+ if (typeof process !== "undefined") {
2371
+ const [seconds, nanosecond] = process.hrtime();
2372
+ return seconds * 1e3 + nanosecond / 1e6;
2373
+ }
2374
+ return Date.now();
2375
+ };
2376
+ const retain = (callback = noop) => {
2377
+ const historyReturnCb = () => {
2378
+ callback();
2379
+ isClient && window.removeEventListener("popstate", historyReturnCb);
2380
+ };
2381
+ isClient && window.history.pushState(null, "", window.location.href);
2382
+ setTimeout(() => {
2383
+ isClient && window.addEventListener("popstate", historyReturnCb);
2384
+ }, 500);
2385
+ };
2386
+ const getCookie = (objName) => {
2387
+ const arrStr = document.cookie.split("; ");
2388
+ for (let i2 = 0; i2 < arrStr.length; i2++) {
2389
+ const item = arrStr[i2].split("=");
2390
+ if (item[0] === objName) {
2391
+ return decodeURIComponent(item[1]);
2392
+ }
2393
+ }
2394
+ return "";
2395
+ };
2396
+ const requestUrlToBuffer = (src, options) => {
2397
+ return new Promise(function(resolve, reject) {
2398
+ const xhr = new XMLHttpRequest();
2399
+ xhr.open(options.method || "GET", src, true);
2400
+ xhr.responseType = options.responseType || "arraybuffer";
2401
+ xhr.onload = function() {
2402
+ if (xhr.status === 200) {
2403
+ resolve({ success: true, data: xhr.response, message: "" });
2404
+ } else {
2405
+ reject({
2406
+ success: false,
2407
+ data: xhr.status,
2408
+ message: `The request status is${xhr.status}`
2409
+ });
2410
+ }
2411
+ };
2412
+ xhr.onerror = function(e2) {
2413
+ reject({ success: false, data: e2, message: `` });
2414
+ };
2415
+ xhr.onprogress = (event) => {
2416
+ options.onProgress && options.onProgress(event);
2417
+ };
2418
+ xhr.withCredentials = options.withCredentials || false;
2419
+ if (options.headers) {
2420
+ Object.keys(options.headers).forEach(function(key) {
2421
+ var _a;
2422
+ ((_a = options.headers) == null ? void 0 : _a[key]) && xhr.setRequestHeader(key, options.headers[key]);
2423
+ });
2424
+ }
2425
+ xhr.send(options.body);
2426
+ });
2427
+ };
2428
+ const getPixelRatio = (context) => {
2429
+ const backingStore = context.backingStorePixelRatio || context.webkitBackingStorePixelRatio || context.mozBackingStorePixelRatio || context.msBackingStorePixelRatio || context.oBackingStorePixelRatio || 1;
2430
+ return (isClient && window.devicePixelRatio || 1) / backingStore;
2431
+ };
2432
+ const createObjectURL = async (src) => {
2433
+ if (typeof src === "string") {
2434
+ return src;
2435
+ } else if (src instanceof Blob) {
2436
+ return URL.createObjectURL(src);
2437
+ } else if (src instanceof ArrayBuffer) {
2438
+ return URL.createObjectURL(new Blob([src]));
2439
+ } else if (src instanceof Response) {
2440
+ const result = await src.blob();
2441
+ return URL.createObjectURL(result);
2442
+ } else {
2443
+ return src;
2444
+ }
2445
+ };
2446
+ const getFrame = (n2 = 10) => {
2447
+ const frameList = [];
2448
+ let lastFrame = 0;
2449
+ let requestAnimationFrameRef;
2450
+ return new Promise((resolve) => {
2451
+ const a2 = () => {
2452
+ const now = performanceTime();
2453
+ const frame = now - lastFrame;
2454
+ if (lastFrame !== 0) {
2455
+ frameList.push(frame);
2456
+ }
2457
+ lastFrame = now;
2458
+ if (frameList.length > n2) {
2459
+ const num = frameList.reduce((i2, j2) => i2 + j2);
2460
+ resolve(1 / (num / n2));
2461
+ cancelAnimationFrame(requestAnimationFrameRef);
2462
+ }
2463
+ requestAnimationFrameRef = requestAnimationFrame(a2);
2464
+ };
2465
+ if (frameList.length <= n2) {
2466
+ requestAnimationFrameRef = requestAnimationFrame(a2);
2467
+ }
2468
+ });
2469
+ };
2470
+ const getHost = (env) => {
2471
+ if (typeof window !== "undefined") {
2472
+ if (env && isString(env)) ;
2473
+ else {
2474
+ const env2 = /\w(\.trunk|\.neibu|\.release|test)\./.exec(window.location.hostname);
2475
+ if (env2) {
2476
+ env2[1];
2477
+ }
2478
+ }
2479
+ return "//log.chaxus.com";
2480
+ }
2481
+ };
2482
+ const getAllQueryString = (url) => {
2483
+ if (typeof window !== "undefined") {
2484
+ const r2 = {};
2485
+ const href = url || window.location.href;
2486
+ if (href.split("?")[1]) {
2487
+ const str = href.split("?")[1];
2488
+ const strList = str.split("&");
2489
+ strList.forEach((item) => {
2490
+ const [key, val] = item.split("=");
2491
+ if (key && val) {
2492
+ r2[key] = decodeURIComponent(val);
2493
+ }
2494
+ });
2495
+ }
2496
+ return r2;
2497
+ }
2498
+ return {};
2499
+ };
2500
+ function appendUrl(url, params = {}) {
2501
+ let _url = url;
2502
+ if (_url.indexOf("//") === 0) {
2503
+ _url = _url.replace("//", "https://");
2504
+ }
2505
+ const urlObj = new URL(_url);
2506
+ if (params) {
2507
+ Object.keys(params).forEach((key) => {
2508
+ params[key] && urlObj.searchParams.set(key, params[key]);
2509
+ });
2510
+ }
2511
+ return urlObj.href;
2512
+ }
2513
+ const removeGhosting = (event) => {
2514
+ const dragIcon = document.createElement("img");
2515
+ const url = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
2516
+ dragIcon.src = url;
2517
+ dragIcon.width = 0;
2518
+ dragIcon.height = 0;
2519
+ dragIcon.style.opacity = "0";
2520
+ if (event.dataTransfer) {
2521
+ event.dataTransfer.setDragImage(dragIcon, 0, 0);
2522
+ }
2523
+ };
2524
+ function getCookieByName(name) {
2525
+ if (typeof window !== "undefined") {
2526
+ const cookieList = document.cookie.match(new RegExp(`(^| )${name}(?:=([^;]*))?(;|$)`));
2527
+ if (cookieList && cookieList[2]) return cookieList[2];
2528
+ }
2529
+ return "";
2530
+ }
2531
+ const getWindow = () => {
2532
+ if (typeof window !== "undefined") {
2533
+ return {
2534
+ width: window.innerWidth,
2535
+ height: window.innerHeight
2536
+ };
2537
+ }
2538
+ return {
2539
+ width: 0,
2540
+ height: 0
2541
+ };
2542
+ };
2543
+ const connection = () => {
2544
+ if (typeof window !== "undefined") {
2545
+ return window.navigator.connection;
2546
+ }
2547
+ };
2548
+ const ENCODE_CHARS_REGEXP = /(?:[^\x21\x25\x26-\x3B\x3D\x3F-\x5B\x5D\x5F\x7E]|%(?:[^\da-f]|[\da-f][^\da-f]|$))+/gi;
2549
+ const UNMATCHED_SURROGATE_PAIR_REGEXP = /(^|[^\uD800-\uDBFF])[\uDC00-\uDFFF]|[\uD800-\uDBFF]([^\uDC00-\uDFFF]|$)/g;
2550
+ const UNMATCHED_SURROGATE_PAIR_REPLACE = "$1�$2";
2551
+ function encodeUrl(url) {
2552
+ return String(url).replace(UNMATCHED_SURROGATE_PAIR_REGEXP, UNMATCHED_SURROGATE_PAIR_REPLACE).replace(ENCODE_CHARS_REGEXP, encodeURI);
2553
+ }
2554
+ const imageRequest = (url) => {
2555
+ return new Promise((resolve, reject) => {
2556
+ const img = new Image();
2557
+ const startTime = (/* @__PURE__ */ new Date()).getTime();
2558
+ img.src = url ? url : `https://github.com/favicon.ico?d=${startTime}`;
2559
+ img.onload = () => {
2560
+ const endTime = (/* @__PURE__ */ new Date()).getTime();
2561
+ const delta = endTime - startTime;
2562
+ resolve(delta);
2563
+ };
2564
+ img.onerror = (err) => {
2565
+ reject(err);
2566
+ };
2567
+ });
2568
+ };
2569
+ const durationHandler = (handler, ...params) => (duration) => new Promise((resolve, reject) => {
2570
+ setTimeout(async () => {
2571
+ try {
2572
+ const result = await handler(...params);
2573
+ resolve(result);
2574
+ } catch (error) {
2575
+ reject(error);
2576
+ }
2577
+ }, duration);
2578
+ });
2579
+ const networkSpeed = async (options) => {
2580
+ const { url, duration = 3e3, count = 5 } = options;
2581
+ let jitter = 0;
2582
+ let ping = 0;
2583
+ const pingList = [];
2584
+ for (let i2 = 0; i2 < count; i2++) {
2585
+ const handler = durationHandler(imageRequest, url);
2586
+ const delta = await handler(duration);
2587
+ pingList.push(delta);
2588
+ }
2589
+ const maxPing = Math.max(...pingList);
2590
+ const minPing = Math.min(...pingList);
2591
+ jitter = maxPing - minPing;
2592
+ ping = pingList.reduce((a2, b2) => a2 + b2) / pingList.length;
2593
+ return { ping, jitter };
2594
+ };
2595
+ function compose(middleware) {
2596
+ if (!Array.isArray(middleware)) throw new TypeError("Middleware stack must be an array!");
2597
+ for (const fn of middleware) {
2598
+ if (typeof fn !== "function") throw new TypeError("Middleware must be composed of functions!");
2599
+ }
2600
+ return function(context, next) {
2601
+ let index = -1;
2602
+ return dispatch(0);
2603
+ function dispatch(i2) {
2604
+ if (i2 <= index) return Promise.reject(new Error("next() called multiple times"));
2605
+ index = i2;
2606
+ let fn = middleware[i2];
2607
+ if (i2 === middleware.length && next) fn = next;
2608
+ if (!fn) return Promise.resolve();
2609
+ try {
2610
+ return Promise.resolve(fn(context, dispatch.bind(null, i2 + 1)));
2611
+ } catch (err) {
2612
+ return Promise.reject(err);
2613
+ }
2614
+ }
2615
+ };
2616
+ }
2617
+ const memoize = (fn) => {
2618
+ let cache = false;
2619
+ let result = void 0;
2620
+ return (...args) => {
2621
+ if (cache) {
2622
+ return result;
2623
+ } else {
2624
+ result = typeof fn === "function" ? fn(...args) : fn;
2625
+ cache = true;
2626
+ fn = void 0;
2627
+ return result;
2628
+ }
2629
+ };
2630
+ };
2631
+ function querystring(data = {}) {
2632
+ if (typeof data !== "object") {
2633
+ throw new TypeError("param must be object");
2634
+ }
2635
+ return Object.entries(data).reduce(
2636
+ (searchParams, [name, value]) => value === void 0 || value == null ? searchParams : (searchParams.append(decodeURIComponent(name), decodeURIComponent(value)), searchParams),
2637
+ new URLSearchParams()
2638
+ ).toString();
2639
+ }
2640
+ const transitionJsonToString = (jsonObj, callback = (error) => {
2641
+ }) => {
2642
+ let _jsonObj = "";
2643
+ if (Object.prototype.toString.call(jsonObj) !== "[object String]") {
2644
+ try {
2645
+ _jsonObj = JSON.stringify(jsonObj);
2646
+ } catch (error) {
2647
+ callback(error);
2648
+ }
2649
+ } else {
2650
+ try {
2651
+ jsonObj = typeof jsonObj === "string" ? jsonObj.replace(/(')/g, '"') : JSON.stringify(jsonObj);
2652
+ _jsonObj = JSON.stringify(JSON.parse(jsonObj));
2653
+ } catch (error) {
2654
+ callback(error);
2655
+ }
2656
+ }
2657
+ return _jsonObj;
2658
+ };
2659
+ const formatJson = (jsonObj, callback = () => {
2660
+ }) => {
2661
+ let formatted = "";
2662
+ let pad = 0;
2663
+ const PADDING = " ";
2664
+ let jsonString = transitionJsonToString(jsonObj, callback);
2665
+ if (!jsonString) {
2666
+ return jsonString;
2667
+ }
2668
+ const _index = [];
2669
+ let _indexStart = null;
2670
+ let _indexEnd = null;
2671
+ let jsonArray = [];
2672
+ jsonString = jsonString.replace(/([{}])/g, "\r\n$1\r\n");
2673
+ jsonString = jsonString.replace(/([[\]])/g, "\r\n$1\r\n");
2674
+ jsonString = jsonString.replace(/(,)/g, "$1\r\n");
2675
+ jsonString = jsonString.replace(/(\r\n\r\n)/g, "\r\n");
2676
+ jsonString = jsonString.replace(/\r\n,/g, ",");
2677
+ jsonArray = jsonString.split("\r\n");
2678
+ jsonArray.forEach(function(node, index) {
2679
+ var _a;
2680
+ const num = node.match(/"/g) ? ((_a = node.match(/"/g)) == null ? void 0 : _a.length) || 0 : 0;
2681
+ if (num % 2 && !_indexStart) {
2682
+ _indexStart = index;
2683
+ }
2684
+ if (num % 2 && _indexStart && _indexStart !== index) {
2685
+ _indexEnd = index;
2686
+ }
2687
+ if (_indexStart && _indexEnd) {
2688
+ _index.push({
2689
+ start: _indexStart,
2690
+ end: _indexEnd
2691
+ });
2692
+ _indexStart = null;
2693
+ _indexEnd = null;
2694
+ }
2695
+ });
2696
+ _index.reverse().forEach(function(item, index) {
2697
+ const newArray = jsonArray.slice(item.start, item.end + 1);
2698
+ jsonArray.splice(item.start, item.end + 1 - item.start, newArray.join(""));
2699
+ });
2700
+ jsonString = jsonArray.join("\r\n");
2701
+ jsonString = jsonString.replace(/:\r\n\{/g, ":{");
2702
+ jsonString = jsonString.replace(/:\r\n\[/g, ":[");
2703
+ jsonArray = jsonString.split("\r\n");
2704
+ jsonArray.forEach(function(item, index) {
2705
+ let i2 = 0;
2706
+ let indent = 0;
2707
+ let padding = "";
2708
+ if (item.match(/\{$/) || item.match(/\[$/)) {
2709
+ indent += 1;
2710
+ } else if (item.match(/\}$/) || item.match(/\]$/) || item.match(/\},$/) || item.match(/\],$/)) {
2711
+ if (pad !== 0) {
2712
+ pad -= 1;
2713
+ }
2714
+ } else {
2715
+ indent = 0;
2716
+ }
2717
+ for (i2 = 0; i2 < pad; i2++) {
2718
+ padding += PADDING;
2719
+ }
2720
+ formatted += padding + item + "\r\n";
2721
+ pad += indent;
2722
+ });
2723
+ return formatted.trim();
2724
+ };
2725
+ const filterObj = (obj, list) => {
2726
+ const result = {};
2727
+ Object.keys(obj).forEach((item) => {
2728
+ if (!list.includes(item)) {
2729
+ result[item] = obj[item];
2730
+ }
2731
+ });
2732
+ return result;
2733
+ };
2734
+ const merge = (a2, b2) => {
2735
+ if (a2 && b2) {
2736
+ for (const key in b2) {
2737
+ a2[key] = b2[key];
2738
+ }
2739
+ }
2740
+ return a2;
2741
+ };
2742
+ function replaceOld(source, name, replacement, isForced) {
2743
+ if (typeof source === "undefined") return;
2744
+ if (name in source || isForced) {
2745
+ const original = source[name];
2746
+ const wrapped = replacement(original);
2747
+ if (typeof wrapped === "function") {
2748
+ source[name] = wrapped;
2749
+ }
2750
+ }
2751
+ }
2752
+ const mergeExports = (obj, exports) => {
2753
+ const descriptors = Object.getOwnPropertyDescriptors(exports);
2754
+ for (const name of Object.keys(descriptors)) {
2755
+ const descriptor = descriptors[name];
2756
+ if (descriptor.get) {
2757
+ const fn = descriptor.get;
2758
+ Object.defineProperty(obj, name, {
2759
+ configurable: false,
2760
+ enumerable: true,
2761
+ get: memoize(fn)
2762
+ });
2763
+ } else if (typeof descriptor.value === "object") {
2764
+ Object.defineProperty(obj, name, {
2765
+ configurable: false,
2766
+ enumerable: true,
2767
+ writable: false,
2768
+ value: mergeExports({}, descriptor.value)
2769
+ });
2770
+ } else {
2771
+ throw new Error("Exposed values must be either a getter or an nested object");
2772
+ }
2773
+ }
2774
+ return Object.freeze(obj);
2775
+ };
2776
+ const setAttributeByGlobal = (name, value) => {
2777
+ if (typeof window !== "undefined") {
2778
+ window[name] = value;
2779
+ }
2780
+ if (typeof global !== "undefined") {
2781
+ global[name] = value;
2782
+ }
2783
+ };
2784
+ const handleConsole = (hooks = noop) => {
2785
+ const consoleTypeList = ["log", "info", "warn", "error", "assert"];
2786
+ consoleTypeList.forEach((type) => {
2787
+ const replacement = (originalConsole) => {
2788
+ return function(...args) {
2789
+ if (originalConsole) {
2790
+ hooks(type, ...args);
2791
+ originalConsole.apply(console, args);
2792
+ }
2793
+ };
2794
+ };
2795
+ replaceOld(console, type, replacement);
2796
+ });
2797
+ };
2798
+ const debounce = (fn, ms = 500) => {
2799
+ let timeout;
2800
+ return (...args) => {
2801
+ clearTimeout(timeout);
2802
+ timeout = setTimeout(() => {
2803
+ fn.apply(void 0, args);
2804
+ }, ms);
2805
+ };
2806
+ };
2807
+ const addClassToElement = (element, addClass) => {
2808
+ if (typeof document === "undefined") return void 0;
2809
+ const classList = element.classList;
2810
+ if (!classList.contains(addClass)) {
2811
+ classList.add(addClass);
2812
+ }
2813
+ };
2814
+ const removeClassToElement = (element, removeClass) => {
2815
+ if (typeof document === "undefined") return void 0;
2816
+ const classList = element.classList;
2817
+ if (classList.contains(removeClass)) {
2818
+ classList.remove(removeClass);
2819
+ }
2820
+ };
2821
+ const createDocumentFragment = (list) => {
2822
+ if (typeof document === "undefined") return void 0;
2823
+ const Fragment = document.createDocumentFragment();
2824
+ list.forEach((item) => Fragment.appendChild(item));
2825
+ return Fragment;
2826
+ };
2827
+ const matchHtmlRegExp = /["'&<>]/;
2828
+ function escapeHtml(string) {
2829
+ const str = "" + string;
2830
+ const match = matchHtmlRegExp.exec(str);
2831
+ if (!match) {
2832
+ return str;
2833
+ }
2834
+ let escape;
2835
+ let html = "";
2836
+ let index = 0;
2837
+ let lastIndex = 0;
2838
+ for (index = match.index; index < str.length; index++) {
2839
+ switch (str.charCodeAt(index)) {
2840
+ case 34:
2841
+ escape = "&quot;";
2842
+ break;
2843
+ case 38:
2844
+ escape = "&amp;";
2845
+ break;
2846
+ case 39:
2847
+ escape = "&#39;";
2848
+ break;
2849
+ case 60:
2850
+ escape = "&lt;";
2851
+ break;
2852
+ case 62:
2853
+ escape = "&gt;";
2854
+ break;
2855
+ default:
2856
+ continue;
2857
+ }
2858
+ if (lastIndex !== index) {
2859
+ html += str.substring(lastIndex, index);
2860
+ }
2861
+ lastIndex = index + 1;
2862
+ html += escape;
2863
+ }
2864
+ return lastIndex !== index ? html + str.substring(lastIndex, index) : html;
2865
+ }
2866
+ const setFontSize2html = (designWidth = 375) => {
2867
+ let base = designWidth;
2868
+ const { documentElement } = document;
2869
+ const mediaQuery = window.matchMedia("(orientation: portrait)");
2870
+ let timer;
2871
+ let standardRatio = 667 / 375;
2872
+ if (currentDevice() === DEVICE.IPAD) {
2873
+ standardRatio = 1024 / 768;
2874
+ base = 768;
2875
+ }
2876
+ function setFontSize() {
2877
+ const isLandscape = !mediaQuery.matches;
2878
+ let screenWidth = window.screen.width;
2879
+ let screenHeight = window.screen.height;
2880
+ if (screenWidth < screenHeight) {
2881
+ [screenWidth, screenHeight] = [screenHeight, screenWidth];
2882
+ }
2883
+ let width = documentElement.clientWidth;
2884
+ let height = screenHeight;
2885
+ const realRatio = width / height;
2886
+ if (realRatio >= standardRatio) {
2887
+ width = height * standardRatio;
2888
+ documentElement.classList.remove("adjustHeight");
2889
+ documentElement.classList.add("adjustWidth");
2890
+ } else {
2891
+ height = width / standardRatio;
2892
+ documentElement.classList.remove("adjustWidth");
2893
+ documentElement.classList.add("adjustHeight");
2894
+ }
2895
+ let target = width / base * 16;
2896
+ if (isLandscape) {
2897
+ target /= standardRatio;
2898
+ }
2899
+ documentElement.style.fontSize = `${target}px`;
2900
+ const currentSize = window.getComputedStyle(documentElement).fontSize.replace("px", "") || 0;
2901
+ if (target !== currentSize) {
2902
+ documentElement.style.fontSize = `${target / Number(currentSize) * target}px`;
2903
+ }
2904
+ }
2905
+ window.addEventListener(
2906
+ "resize",
2907
+ function() {
2908
+ clearTimeout(timer);
2909
+ timer = setTimeout(setFontSize, 300);
2910
+ },
2911
+ false
2912
+ );
2913
+ window.addEventListener(
2914
+ "pageshow",
2915
+ function(e2) {
2916
+ e2.persisted && (clearTimeout(timer), timer = setTimeout(setFontSize, 300));
2917
+ },
2918
+ false
2919
+ );
2920
+ window.addEventListener(
2921
+ "orientationchange",
2922
+ function() {
2923
+ setFontSize();
2924
+ },
2925
+ false
2926
+ );
2927
+ setFontSize();
2928
+ };
2929
+ const SVG_NS = "http://www.w3.org/2000/svg";
2930
+ const SVG_TAG_NAMES = [
2931
+ "svg",
2932
+ "path",
2933
+ "g",
2934
+ "circle",
2935
+ "rect",
2936
+ "line",
2937
+ "polyline",
2938
+ "polygon",
2939
+ "ellipse",
2940
+ "text",
2941
+ "tspan",
2942
+ "textPath",
2943
+ "defs",
2944
+ "marker",
2945
+ "radialGradient",
2946
+ "stop",
2947
+ "linearGradient",
2948
+ "clipPath",
2949
+ "mask",
2950
+ "pattern",
2951
+ "image",
2952
+ "use",
2953
+ "symbol",
2954
+ "foreignObject",
2955
+ "feGaussianBlur",
2956
+ "feColorMatrix"
2957
+ ];
2958
+ class Chain {
2959
+ constructor(tagName, options) {
2960
+ __publicField(this, "listener");
2961
+ __publicField(this, "element");
2962
+ /**
2963
+ * @description: 创建元素
2964
+ * @param {string} tagName
2965
+ * @param {ElementCreationOptions} options
2966
+ * @return {Chain}
2967
+ */
2968
+ __publicField(this, "create", (tagName, options) => {
2969
+ if (SVG_TAG_NAMES.includes(tagName)) {
2970
+ return document.createElementNS(SVG_NS, tagName, options);
2971
+ }
2972
+ return document.createElement(tagName, options);
2973
+ });
2974
+ /**
2975
+ * @description: 设置当前元素的属性
2976
+ * @param {string} name
2977
+ * @param {string} value
2978
+ * @return {Chain}
2979
+ */
2980
+ __publicField(this, "setAttribute", (name, value) => {
2981
+ this.element.setAttribute(name, value);
2982
+ return this;
2983
+ });
2984
+ /**
2985
+ * @description: 移除当前元素的属性
2986
+ * @param {string} name
2987
+ * @return {Chain}
2988
+ */
2989
+ __publicField(this, "removeAttribute", (name) => {
2990
+ this.element.removeAttribute(name);
2991
+ return this;
2992
+ });
2993
+ /**
2994
+ * @description: 当前元素添加子元素
2995
+ * @param {HTMLElement} child
2996
+ * @return {ChainElement}
2997
+ */
2998
+ __publicField(this, "append", (child) => {
2999
+ this.element.appendChild(child);
3000
+ return this;
3001
+ });
3002
+ /**
3003
+ * @description: 当前元素移除子元素
3004
+ * @param {HTMLElement} child
3005
+ * @return {Chain}
3006
+ */
3007
+ __publicField(this, "remove", (child) => {
3008
+ this.element.removeChild(child);
3009
+ return this;
3010
+ });
3011
+ /**
3012
+ * @description: 给当前元素设置文本内容
3013
+ * @param {string} text
3014
+ * @return {Chain}
3015
+ */
3016
+ __publicField(this, "setTextContent", (text) => {
3017
+ this.element.textContent = text;
3018
+ return this;
3019
+ });
3020
+ /**
3021
+ * @description: 给当前元素设置样式
3022
+ * @param {string} name
3023
+ * @param {string} value
3024
+ * @return {Chain}
3025
+ */
3026
+ __publicField(this, "setStyle", (name, value) => {
3027
+ this.element.style.setProperty(name, value);
3028
+ return this;
3029
+ });
3030
+ /**
3031
+ * @description: 给当前元素添加子元素
3032
+ * @return {Chain}
3033
+ */
3034
+ __publicField(this, "addChild", (child) => {
3035
+ if (Array.isArray(child)) {
3036
+ const Fragment = document.createDocumentFragment();
3037
+ child.forEach((item) => Fragment.appendChild(item.element));
3038
+ this.element.appendChild(Fragment);
3039
+ } else {
3040
+ this.element.appendChild(child.element);
3041
+ }
3042
+ return this;
3043
+ });
3044
+ /**
3045
+ * @description: 给当前元素添加事件监听
3046
+ * @param {string} type
3047
+ * @param {EventListener} listener
3048
+ * @return {Chain}
3049
+ */
3050
+ __publicField(this, "listen", (type, listener, options) => {
3051
+ let event = this.listener.get(type);
3052
+ if (!event) {
3053
+ event = /* @__PURE__ */ new Map();
3054
+ this.listener.set(type, event);
3055
+ }
3056
+ const value = event.get(listener.name);
3057
+ if (value === listener) {
3058
+ console.warn(`${value.name} listener has been added to ${type} event, please remove it first.`);
3059
+ }
3060
+ this.element.addEventListener(type, listener, options);
3061
+ event.set(listener.name, listener);
3062
+ return this;
3063
+ });
3064
+ /**
3065
+ * @description: 移除当前元素的事件监听
3066
+ * @param {string} type
3067
+ * @return {Chain}
3068
+ */
3069
+ __publicField(this, "clearListener", (type, listener, options) => {
3070
+ this.element.removeEventListener(type, listener, options);
3071
+ const event = this.listener.get(type);
3072
+ if (event) {
3073
+ event.delete(listener.name);
3074
+ } else {
3075
+ console.warn(`No ${type} event listener has been added.`);
3076
+ }
3077
+ return this;
3078
+ });
3079
+ /**
3080
+ * @description: 移除当前元素的所有事件监听
3081
+ * @return {Chain}
3082
+ */
3083
+ __publicField(this, "clearAllListener", () => {
3084
+ for (const [key, value] of this.listener) {
3085
+ for (const [k2, v2] of value) {
3086
+ this.element.removeEventListener(key, v2);
3087
+ value.delete(k2);
3088
+ }
3089
+ this.listener.delete(key);
3090
+ }
3091
+ return this;
3092
+ });
3093
+ this.element = this.create(tagName, options);
3094
+ this.listener = /* @__PURE__ */ new Map();
3095
+ }
3096
+ }
3097
+ const create = (tagName, options) => {
3098
+ return new Chain(tagName, options);
3099
+ };
3100
+ const handleError = (hooks = noop) => {
3101
+ if (typeof window !== "undefined") {
3102
+ window.addEventListener(
3103
+ "unhandledrejection",
3104
+ (error) => {
3105
+ hooks(error);
3106
+ },
3107
+ true
3108
+ );
3109
+ window.addEventListener(
3110
+ "error",
3111
+ (error) => {
3112
+ hooks(error);
3113
+ return false;
3114
+ },
3115
+ true
3116
+ );
3117
+ }
3118
+ };
3119
+ const isImageSize = (file, width, height) => {
3120
+ return new Promise((resolve, reject) => {
3121
+ if (!isClient) reject("window is undefined");
3122
+ const _URL = window.URL || window.webkitURL;
3123
+ const img = new Image();
3124
+ img.onload = function() {
3125
+ let valid = false;
3126
+ if (width) {
3127
+ valid = img.width === width;
3128
+ }
3129
+ if (height) {
3130
+ valid = img.height === height;
3131
+ }
3132
+ _URL.revokeObjectURL(img.src);
3133
+ resolve(valid);
3134
+ };
3135
+ img.src = _URL.createObjectURL(file);
3136
+ });
3137
+ };
3138
+ const convertImageToBase64 = (file) => {
3139
+ return new Promise((resolve, reject) => {
3140
+ const reader = new FileReader();
3141
+ reader.onload = function() {
3142
+ resolve({ success: true, data: reader.result, message: "" });
3143
+ };
3144
+ reader.onerror = (e2) => {
3145
+ reject({ success: false, data: e2, message: "" });
3146
+ };
3147
+ reader.readAsDataURL(file);
3148
+ });
3149
+ };
3150
+ function getPerformance() {
3151
+ if (typeof window !== "undefined") {
3152
+ const [performanceNavigationTiming] = performance.getEntriesByType("navigation");
3153
+ const [firstPaint = {}, firstContentfulPaint = {}] = performance.getEntriesByType("paint");
3154
+ const { startTime: fp } = firstPaint;
3155
+ const { startTime: fcp } = firstContentfulPaint;
3156
+ const {
3157
+ domainLookupEnd,
3158
+ domainLookupStart,
3159
+ connectEnd,
3160
+ connectStart,
3161
+ secureConnectionStart,
3162
+ loadEventStart,
3163
+ domInteractive,
3164
+ domContentLoadedEventEnd,
3165
+ duration,
3166
+ responseStart,
3167
+ requestStart,
3168
+ responseEnd,
3169
+ fetchStart,
3170
+ transferSize,
3171
+ encodedBodySize,
3172
+ redirectEnd,
3173
+ redirectStart,
3174
+ redirectCount
3175
+ } = performanceNavigationTiming;
3176
+ return {
3177
+ // DNS
3178
+ dnsSearch: domainLookupEnd - domainLookupStart,
3179
+ // TCP
3180
+ tcpConnect: connectEnd - connectStart,
3181
+ sslConnect: connectEnd - secureConnectionStart,
3182
+ request: responseStart - requestStart,
3183
+ response: responseEnd - responseStart,
3184
+ parseDomTree: domInteractive - responseEnd,
3185
+ resource: loadEventStart - domContentLoadedEventEnd,
3186
+ domReady: domContentLoadedEventEnd - fetchStart,
3187
+ interactive: domInteractive - fetchStart,
3188
+ complete: loadEventStart - fetchStart,
3189
+ httpHead: transferSize - encodedBodySize,
3190
+ redirect: redirectCount,
3191
+ // redirect
3192
+ redirectTime: redirectEnd - redirectStart,
3193
+ duration,
3194
+ fp,
3195
+ fcp
3196
+ };
3197
+ }
3198
+ }
3199
+ const sendBeacon = ({ url = "", type = "application/json; charset=UTF-8", payload = {} }) => {
3200
+ const requestUrl = url ? url : getHost();
3201
+ if (navigator.sendBeacon && requestUrl) {
3202
+ const param = new Blob([JSON.stringify(payload)], { type });
3203
+ return navigator.sendBeacon(requestUrl, param);
3204
+ }
3205
+ };
3206
+ const sendImage = ({ url = "", payload = {} }) => {
3207
+ const requestUrl = url ? url : getHost();
3208
+ if (typeof document !== "undefined" && requestUrl) {
3209
+ const image = new Image();
3210
+ image.width = 1;
3211
+ image.height = 1;
3212
+ image.src = `${requestUrl}?${querystring(payload)}`;
3213
+ }
3214
+ };
3215
+ const report = ({
3216
+ url = "",
3217
+ type = "application/json; charset=UTF-8",
3218
+ payload = {}
3219
+ }) => {
3220
+ const requestUrl = url ? url : getHost();
3221
+ if (typeof navigator !== "undefined") {
3222
+ return sendBeacon({ url: requestUrl, type, payload });
3223
+ }
3224
+ return sendImage({ url: requestUrl, payload });
3225
+ };
3226
+ function createData(params = {}) {
3227
+ if (typeof window !== "undefined") {
3228
+ const { width, height } = getWindow();
3229
+ return Object.assign(
3230
+ {},
3231
+ {
3232
+ id: randomString(),
3233
+ path: window.location.href,
3234
+ time: Date.now(),
3235
+ referrer: document.referrer,
3236
+ ip: window.returnCitySN || { cid: "", cip: "", cname: "" },
3237
+ userId: getCookie("chaxus_prod"),
3238
+ ratio: `${width}x${height}`,
3239
+ userAgent: window.navigator.userAgent
3240
+ },
3241
+ params
3242
+ );
3243
+ }
3244
+ return {};
3245
+ }
3246
+ const handleFetchHook = (options = {}) => {
3247
+ if (typeof window !== "undefined") {
3248
+ const { requestHook = noop, responseHook = noop, errorHook = noop } = options;
3249
+ const replacement = (originalFetch) => {
3250
+ return (url, config) => {
3251
+ requestHook(url, config);
3252
+ return originalFetch.apply(window, [url, config]).then((response) => {
3253
+ responseHook(url, config, response);
3254
+ return response;
3255
+ }).catch((error) => {
3256
+ errorHook(url, error);
3257
+ throw error;
3258
+ });
3259
+ };
3260
+ };
3261
+ replaceOld(window, "fetch", replacement);
3262
+ }
3263
+ };
3264
+ const handleXhrHook = (options = {}) => {
3265
+ if (typeof window !== "undefined") {
3266
+ const originalXhrProto = XMLHttpRequest.prototype;
3267
+ const { requestHook = noop, responseHook = noop, errorHook = noop } = options;
3268
+ const replacementXhrOpen = (originalOpen) => {
3269
+ return function(...args) {
3270
+ requestHook(args);
3271
+ originalOpen.apply(this, args);
3272
+ };
3273
+ };
3274
+ replaceOld(originalXhrProto, "open", replacementXhrOpen);
3275
+ const replacementXhrSend = (originalSend) => {
3276
+ return function(...args) {
3277
+ this.addEventListener("loadend", function() {
3278
+ responseHook(this);
3279
+ });
3280
+ this.addEventListener("error", function() {
3281
+ errorHook(this);
3282
+ });
3283
+ originalSend.apply(this, args);
3284
+ };
3285
+ };
3286
+ replaceOld(originalXhrProto, "send", replacementXhrSend);
3287
+ }
3288
+ };
3289
+ const throttle = (fn, wait = 300) => {
3290
+ let timer;
3291
+ return function() {
3292
+ const context = this;
3293
+ const args = arguments;
3294
+ if (!timer) {
3295
+ timer = setTimeout(() => {
3296
+ timer = null;
3297
+ fn.apply(context, args);
3298
+ }, wait);
3299
+ }
3300
+ };
3301
+ };
3302
+ const generateThrottle = () => {
3303
+ let timer;
3304
+ return function(fn, wait = 300) {
3305
+ return function(...args) {
3306
+ if (timer) {
3307
+ clearTimeout(timer);
3308
+ timer = void 0;
3309
+ }
3310
+ const context = this;
3311
+ if (!timer) {
3312
+ timer = setTimeout(() => {
3313
+ fn.apply(context, args);
3314
+ clearTimeout(timer);
3315
+ timer = void 0;
3316
+ }, wait);
3317
+ }
3318
+ };
3319
+ };
3320
+ };
3321
+ const requestAnimation = (fn) => {
3322
+ if (!isClient) return;
3323
+ let ticking = false;
3324
+ return function() {
3325
+ const context = this;
3326
+ const args = arguments;
3327
+ if (!ticking) {
3328
+ window.requestAnimationFrame(function() {
3329
+ fn.apply(context, args);
3330
+ ticking = false;
3331
+ });
3332
+ ticking = true;
3333
+ }
3334
+ };
3335
+ };
3336
+ class Monitor {
3337
+ constructor() {
3338
+ __publicField(this, "init", () => {
3339
+ this.reportClick();
3340
+ this.reportError();
3341
+ this.reportFetch();
3342
+ this.reportPerformance();
3343
+ this.reportXhr();
3344
+ });
3345
+ this.initialize();
3346
+ }
3347
+ /**
3348
+ * @description: 页面加载性能上报
3349
+ * @param {Payload} param1
3350
+ */
3351
+ reportPerformance() {
3352
+ const params = getPerformance();
3353
+ const payload = createData();
3354
+ report({
3355
+ payload: {
3356
+ ...params,
3357
+ ...payload
3358
+ }
3359
+ });
3360
+ }
3361
+ /**
3362
+ * @description: 手动触发的上报
3363
+ * @param {Record} payload
3364
+ * @param {*} unknown
3365
+ */
3366
+ log(payload) {
3367
+ report({ payload });
3368
+ }
3369
+ /**
3370
+ * @description: 点击上报
3371
+ * @return {*}
3372
+ */
3373
+ reportClick() {
3374
+ const throttleReport = throttle(report);
3375
+ const payload = createData();
3376
+ const hook = (event) => {
3377
+ const { pageX, pageY, screenX, screenY, type } = event;
3378
+ throttleReport({
3379
+ payload: {
3380
+ ...payload,
3381
+ data: { pageX, pageY, screenX, screenY, type },
3382
+ type: "click"
3383
+ }
3384
+ });
3385
+ };
3386
+ handleClick(hook);
3387
+ }
3388
+ // ajax 上报
3389
+ reportXhr() {
3390
+ const throttleReport = throttle(report);
3391
+ const payload = createData();
3392
+ const requestHook = (...args) => {
3393
+ throttleReport({
3394
+ payload: { ...payload, data: { ...args }, type: "xhrRequest" }
3395
+ });
3396
+ };
3397
+ const responseHook = (...args) => {
3398
+ throttleReport({
3399
+ payload: { ...payload, data: { ...args }, type: "xhrResponse" }
3400
+ });
3401
+ };
3402
+ const errorHook = (...args) => {
3403
+ throttleReport({
3404
+ payload: { ...payload, data: { ...args }, type: "xhrError" }
3405
+ });
3406
+ };
3407
+ handleXhrHook({ requestHook, responseHook, errorHook });
3408
+ }
3409
+ /**
3410
+ * @description: fetch上报
3411
+ */
3412
+ reportFetch() {
3413
+ const throttleReport = throttle(report);
3414
+ const payload = createData();
3415
+ const requestHook = (...args) => {
3416
+ throttleReport({
3417
+ payload: { ...payload, data: { ...args }, type: "fetchRequest" }
3418
+ });
3419
+ };
3420
+ const responseHook = (...args) => {
3421
+ throttleReport({
3422
+ payload: { ...payload, data: { ...args }, type: "fetchResponse" }
3423
+ });
3424
+ };
3425
+ const errorHook = (...args) => {
3426
+ throttleReport({
3427
+ payload: { ...payload, data: { ...args }, type: "fetchError" }
3428
+ });
3429
+ };
3430
+ handleFetchHook({ requestHook, responseHook, errorHook });
3431
+ }
3432
+ /**
3433
+ * @description: 错误上报
3434
+ */
3435
+ reportError() {
3436
+ const throttleReport = throttle(report);
3437
+ const payload = createData();
3438
+ const hook = (...args) => {
3439
+ throttleReport({
3440
+ payload: { ...payload, data: { ...args }, type: "error" }
3441
+ });
3442
+ };
3443
+ handleError(hook);
3444
+ }
3445
+ /**
3446
+ * @description: 上报console
3447
+ */
3448
+ reportConsole() {
3449
+ const throttleReport = throttle(report);
3450
+ const payload = createData();
3451
+ const hook = (...args) => {
3452
+ throttleReport({
3453
+ payload: { ...payload, data: { ...args }, type: "console" }
3454
+ });
3455
+ };
3456
+ handleConsole(hook);
3457
+ }
3458
+ initialize() {
3459
+ if (typeof window !== "undefined" && !window.ranlog) {
3460
+ window.ranlog = true;
3461
+ this.init();
3462
+ }
3463
+ if (typeof process !== "undefined" && !process.ranlog) {
3464
+ process.ranlog = true;
3465
+ this.init();
3466
+ }
3467
+ }
3468
+ }
3469
+ const codes = /* @__PURE__ */ new Map([
3470
+ [100, "Continue"],
3471
+ [101, "Switching Protocols"],
3472
+ [102, "Processing"],
3473
+ [103, "Early Hints"],
3474
+ [200, "OK"],
3475
+ [201, "Created"],
3476
+ [202, "Accepted"],
3477
+ [203, "Non-Authoritative Information"],
3478
+ [204, "No Content"],
3479
+ [205, "Reset Content"],
3480
+ [206, "Partial Content"],
3481
+ [207, "Multi-Status"],
3482
+ [208, "Already Reported"],
3483
+ [226, "IM Used"],
3484
+ [300, "Multiple Choices"],
3485
+ [301, "Moved Permanently"],
3486
+ [302, "Found"],
3487
+ [303, "See Other"],
3488
+ [304, "Not Modified"],
3489
+ [305, "Use Proxy"],
3490
+ [307, "Temporary Redirect"],
3491
+ [308, "Permanent Redirect"],
3492
+ [400, "Bad Request"],
3493
+ [401, "Unauthorized"],
3494
+ [402, "Payment Required"],
3495
+ [403, "Forbidden"],
3496
+ [404, "Not Found"],
3497
+ [405, "Method Not Allowed"],
3498
+ [406, "Not Acceptable"],
3499
+ [407, "Proxy Authentication Required"],
3500
+ [408, "Request Timeout"],
3501
+ [409, "Conflict"],
3502
+ [410, "Gone"],
3503
+ [411, "Length Required"],
3504
+ [412, "Precondition Failed"],
3505
+ [413, "Payload Too Large"],
3506
+ [414, "URI Too Long"],
3507
+ [415, "Unsupported Media Type"],
3508
+ [416, "Range Not Satisfiable"],
3509
+ [417, "Expectation Failed"],
3510
+ [418, "I'm a Teapot"],
3511
+ [421, "Misdirected Request"],
3512
+ [422, "Unprocessable Entity"],
3513
+ [423, "Locked"],
3514
+ [424, "Failed Dependency"],
3515
+ [425, "Too Early"],
3516
+ [426, "Upgrade Required"],
3517
+ [428, "Precondition Required"],
3518
+ [429, "Too Many Requests"],
3519
+ [431, "Request Header Fields Too Large"],
3520
+ [451, "Unavailable For Legal Reasons"],
3521
+ [500, "Internal Server Error"],
3522
+ [501, "Not Implemented"],
3523
+ [502, "Bad Gateway"],
3524
+ [503, "Service Unavailable"],
3525
+ [504, "Gateway Timeout"],
3526
+ [505, "HTTP Version Not Supported"],
3527
+ [506, "Variant Also Negotiates"],
3528
+ [507, "Insufficient Storage"],
3529
+ [508, "Loop Detected"],
3530
+ [509, "Bandwidth Limit Exceeded"],
3531
+ [510, "Not Extended"],
3532
+ [511, "Network Authentication Required"]
3533
+ ]);
3534
+ const status = {
3535
+ // status code to message map
3536
+ message: codes,
3537
+ // status message (lower-case) to code map
3538
+ code: createMessageToStatusCodeMap(codes),
3539
+ // array of status codes
3540
+ codes: createStatusCodeList(codes),
3541
+ // status codes for redirects
3542
+ redirect: {
3543
+ 300: true,
3544
+ 301: true,
3545
+ 302: true,
3546
+ 303: true,
3547
+ 305: true,
3548
+ 307: true,
3549
+ 308: true
3550
+ },
3551
+ // status codes for empty bodies
3552
+ empty: {
3553
+ 204: true,
3554
+ 205: true,
3555
+ 304: true
3556
+ },
3557
+ // status codes for when you should retry the request
3558
+ retry: {
3559
+ 502: true,
3560
+ 503: true,
3561
+ 504: true
3562
+ }
3563
+ };
3564
+ function createMessageToStatusCodeMap(codes2) {
3565
+ const map = /* @__PURE__ */ new Map();
3566
+ for (const [status2, message] of codes2) {
3567
+ map.set(message.toLowerCase(), status2);
3568
+ }
3569
+ return map;
3570
+ }
3571
+ function createStatusCodeList(codes2) {
3572
+ const codeList = [];
3573
+ for (const [status2, _] of codes2) {
3574
+ codeList.push(status2);
3575
+ }
3576
+ return codeList;
3577
+ }
3578
+ function getStatusCode(message) {
3579
+ const msg = message.toLowerCase();
3580
+ status.code.has(msg);
3581
+ if (!status.code.has(msg)) {
3582
+ throw new Error('invalid status message: "' + message + '"');
3583
+ }
3584
+ return status.code.get(msg);
3585
+ }
3586
+ function getStatusMessage(code) {
3587
+ if (!status.message.has(code)) {
3588
+ throw new Error("invalid status code: " + code);
3589
+ }
3590
+ return status.message.get(code);
3591
+ }
3592
+ function getStatus(code) {
3593
+ if (typeof code === "number") {
3594
+ return getStatusMessage(code);
3595
+ }
3596
+ if (typeof code !== "string") {
3597
+ throw new TypeError("code must be a number or string");
3598
+ }
3599
+ const n2 = parseInt(code, 10);
3600
+ if (!isNaN(n2) && status.codes.includes(n2)) {
3601
+ return getStatusMessage(n2);
3602
+ }
3603
+ return getStatusCode(code);
3604
+ }
3605
+ const perToNum = (str = "") => {
3606
+ if (str.length === 0) return 0;
3607
+ if (str.endsWith("%")) {
3608
+ const value = Number(str.replace("%", ""));
3609
+ return value > 1 ? value / 100 : value;
3610
+ } else {
3611
+ return Number(str);
3612
+ }
3613
+ };
3614
+ const range = (num, min = 0, max = 1) => {
3615
+ return Math.min(max, Math.max(min, num));
3616
+ };
3617
+ const _Mathjs = class _Mathjs {
3618
+ constructor() {
3619
+ /**
3620
+ * 获取数字小数点的长度
3621
+ * @param {number} n 数字
3622
+ */
3623
+ __publicField(this, "getDecimalLength", (n2) => {
3624
+ const [_, decimal] = n2.toString().split(".");
3625
+ return decimal ? decimal.length : 0;
3626
+ });
3627
+ __publicField(this, "amend", (n2, precision = 15) => parseFloat(Number(n2).toPrecision(precision)));
3628
+ __publicField(this, "power", (a2, b2) => Math.pow(10, Math.max(this.getDecimalLength(a2), this.getDecimalLength(b2))));
3629
+ }
3630
+ };
3631
+ __publicField(_Mathjs, "handleMethod", (l2, r2) => {
3632
+ const mathjs2 = new _Mathjs();
3633
+ const { power, amend } = mathjs2;
3634
+ const pow = power(l2, r2);
3635
+ const a2 = amend(l2 * pow);
3636
+ const b2 = amend(r2 * pow);
3637
+ return (type) => {
3638
+ switch (type) {
3639
+ case "+":
3640
+ return (a2 + b2) / pow;
3641
+ case "-":
3642
+ return (a2 - b2) / pow;
3643
+ case "*":
3644
+ return a2 * b2 / (pow * pow);
3645
+ case "/":
3646
+ return a2 / b2;
3647
+ }
3648
+ };
3649
+ });
3650
+ __publicField(_Mathjs, "add", (a2, b2) => {
3651
+ return _Mathjs.handleMethod(a2, b2)("+");
3652
+ });
3653
+ __publicField(_Mathjs, "divide", (a2, b2) => {
3654
+ return _Mathjs.handleMethod(a2, b2)("/");
3655
+ });
3656
+ __publicField(_Mathjs, "multiply", (a2, b2) => {
3657
+ return _Mathjs.handleMethod(a2, b2)("*");
3658
+ });
3659
+ __publicField(_Mathjs, "subtract", (a2, b2) => {
3660
+ return _Mathjs.handleMethod(a2, b2)("-");
3661
+ });
3662
+ let Mathjs = _Mathjs;
3663
+ function mathjs(a2, type, b2) {
3664
+ function getDecimalLength(n2) {
3665
+ const [_, decimal] = n2.toString().split(".");
3666
+ return decimal ? decimal.length : 0;
3667
+ }
3668
+ const amend = (n2, precision = 15) => parseFloat(Number(n2).toPrecision(precision));
3669
+ const power = Math.pow(10, Math.max(getDecimalLength(a2), getDecimalLength(b2)));
3670
+ let result = 0;
3671
+ a2 = amend(a2 * power);
3672
+ b2 = amend(b2 * power);
3673
+ switch (type) {
3674
+ case "+":
3675
+ result = (a2 + b2) / power;
3676
+ break;
3677
+ case "-":
3678
+ result = (a2 - b2) / power;
3679
+ break;
3680
+ case "*":
3681
+ result = a2 * b2 / (power * power);
3682
+ break;
3683
+ case "/":
3684
+ result = a2 / b2;
3685
+ break;
3686
+ }
3687
+ result = amend(result);
3688
+ return {
3689
+ /** 计算结果 */
3690
+ result,
3691
+ /**
3692
+ * 继续计算
3693
+ * @param {"+"|"-"|"*"|"/"} nextType 继续计算方式
3694
+ * @param {number} nextValue 继续计算的值
3695
+ */
3696
+ next: (nextType, nextValue) => {
3697
+ return mathjs(result, nextType, nextValue);
3698
+ }
3699
+ };
3700
+ }
3701
+ class QuestQueue {
3702
+ constructor({ simultaneous, total }) {
3703
+ __publicField(this, "current");
3704
+ __publicField(this, "queue");
3705
+ __publicField(this, "simultaneous");
3706
+ // 并发的请求
3707
+ __publicField(this, "executed");
3708
+ __publicField(this, "total");
3709
+ /**
3710
+ * @description: 传入异步函数,添加到队列并执行
3711
+ * @param {Fun} asynchronous
3712
+ * @return {*}
3713
+ */
3714
+ __publicField(this, "add", (asynchronous) => {
3715
+ if (typeof asynchronous !== "function") return;
3716
+ const task = () => {
3717
+ return new Promise((resolve, reject) => {
3718
+ this.current++;
3719
+ asynchronous().then(resolve).catch(reject).finally(() => {
3720
+ this.current--;
3721
+ this.running();
3722
+ });
3723
+ });
3724
+ };
3725
+ this.queue.push(task);
3726
+ });
3727
+ /**
3728
+ * @description: 执行异步函数
3729
+ * @param {*} Promise
3730
+ * @return {*}
3731
+ */
3732
+ __publicField(this, "running", () => {
3733
+ return new Promise((resolve, reject) => {
3734
+ if (this.current <= this.simultaneous && this.queue.length) {
3735
+ const task = this.queue.pop();
3736
+ if (task) {
3737
+ task().then(resolve).catch(reject).finally(() => {
3738
+ this.executed++;
3739
+ });
3740
+ }
3741
+ } else {
3742
+ resolve({});
3743
+ }
3744
+ });
3745
+ });
3746
+ /**
3747
+ * @description: 并发执行所有的异步函数,并返回所有的结果
3748
+ * @param {*} Promise
3749
+ * @return {*}
3750
+ */
3751
+ __publicField(this, "allSettled", () => {
3752
+ let index = 0;
3753
+ return new Promise((resolve, reject) => {
3754
+ const result = [];
3755
+ if (this.current < this.simultaneous && this.queue.length) {
3756
+ const task = this.queue.pop();
3757
+ index++;
3758
+ if (task) {
3759
+ task().then((x) => {
3760
+ result[index] = x;
3761
+ resolve(x);
3762
+ }).catch((x) => {
3763
+ result[index] = x;
3764
+ reject(x);
3765
+ }).finally(() => {
3766
+ this.executed++;
3767
+ });
3768
+ }
3769
+ }
3770
+ if (this.executed >= this.total) {
3771
+ resolve(result);
3772
+ }
3773
+ });
3774
+ });
3775
+ this.current = 0;
3776
+ this.queue = [];
3777
+ this.simultaneous = simultaneous;
3778
+ this.executed = 0;
3779
+ this.total = total;
3780
+ }
3781
+ }
3782
+ const scriptOnLoad = (urls, append, callback) => {
3783
+ urls = Array.isArray(urls) ? urls : [urls];
3784
+ const array = urls.map((src) => {
3785
+ const cssReg = /\w*.css$/;
3786
+ let script;
3787
+ if (cssReg.test(src)) {
3788
+ const link = document.createElement("link");
3789
+ link.type = "text/css";
3790
+ link.rel = "stylesheet";
3791
+ link.href = src;
3792
+ script = link;
3793
+ } else {
3794
+ script = document.createElement("script");
3795
+ script.type = "text/javascript";
3796
+ script.src = src;
3797
+ }
3798
+ const bodyElement = document.getElementsByTagName("body")[0];
3799
+ const currentAppend = append || bodyElement;
3800
+ currentAppend.appendChild(script);
3801
+ return new Promise((resolve) => {
3802
+ script.onload = () => {
3803
+ resolve();
3804
+ };
3805
+ });
3806
+ });
3807
+ return new Promise((resolve) => {
3808
+ Promise.all(array).then(() => {
3809
+ if (typeof callback === "function") {
3810
+ callback();
3811
+ }
3812
+ resolve();
3813
+ });
3814
+ });
3815
+ };
3816
+ const NEW_LISTENER = "NEW_LISTENER";
3817
+ class SyncHook {
3818
+ constructor() {
3819
+ __publicField(this, "_events");
3820
+ /**
3821
+ * @description: 订阅事件
3822
+ * @param {EventName} eventName
3823
+ * @param {EventItem} eventItem
3824
+ * @return {void}
3825
+ */
3826
+ __publicField(this, "tap", (eventName, eventItem) => {
3827
+ if (this._events[eventName] && eventName !== Symbol.for(NEW_LISTENER)) {
3828
+ this.call(Symbol.for(NEW_LISTENER), eventName);
3829
+ }
3830
+ const callbacks = this._events[eventName] || [];
3831
+ if (typeof eventItem === "function") {
3832
+ callbacks.push({
3833
+ name: eventName,
3834
+ callback: eventItem
3835
+ });
3836
+ } else {
3837
+ callbacks.push(eventItem);
3838
+ }
3839
+ this._events[eventName] = callbacks;
3840
+ return this;
3841
+ });
3842
+ /**
3843
+ * @description: 触发事件
3844
+ * @param {EventName} eventName
3845
+ * @param {array} args
3846
+ * @return {void}
3847
+ */
3848
+ __publicField(this, "call", (eventName, ...args) => {
3849
+ const callbacks = this._events[eventName] || [];
3850
+ callbacks.forEach((item) => {
3851
+ const { callback } = item;
3852
+ callback(...args);
3853
+ });
3854
+ });
3855
+ /**
3856
+ * @description: 同步触发事件
3857
+ * @param {EventName} eventName
3858
+ * @param {array} args
3859
+ * @return {Promise<void>}
3860
+ */
3861
+ __publicField(this, "callSync", async (eventName, ...args) => {
3862
+ const callbacks = this._events[eventName] || [];
3863
+ for (const item of callbacks) {
3864
+ const { callback } = item;
3865
+ await callback(...args);
3866
+ }
3867
+ });
3868
+ /**
3869
+ * @description: 只订阅一次事件,触发后就移除事件
3870
+ * @param {EventName} eventName
3871
+ * @param {EventItem} eventItem
3872
+ * @return {void}
3873
+ */
3874
+ __publicField(this, "once", (eventName, eventItem) => {
3875
+ let one;
3876
+ if (typeof eventItem === "function") {
3877
+ one = {
3878
+ name: eventName,
3879
+ callback: (...args) => {
3880
+ eventItem(...args);
3881
+ this.off(eventName, one);
3882
+ },
3883
+ initialCallback: eventItem
3884
+ };
3885
+ } else {
3886
+ const { callback } = eventItem;
3887
+ one = {
3888
+ name: eventName,
3889
+ callback: (...args) => {
3890
+ callback(...args);
3891
+ this.off(eventName, one);
3892
+ },
3893
+ initialCallback: callback
3894
+ };
3895
+ }
3896
+ this.tap(eventName, one);
3897
+ return this;
3898
+ });
3899
+ /**
3900
+ * @description: 移除订阅的事件
3901
+ * @param {EventName} eventName
3902
+ * @param {EventItem} eventItem
3903
+ * @return {void}
3904
+ */
3905
+ __publicField(this, "off", (eventName, eventItem) => {
3906
+ const callbacks = this._events[eventName] || [];
3907
+ const newCallbacks = callbacks.filter((item) => {
3908
+ if (typeof eventItem === "function") {
3909
+ return item.callback !== eventItem && item.initialCallback !== eventItem;
3910
+ } else {
3911
+ const { callback } = eventItem;
3912
+ return item.callback !== callback && item.initialCallback !== callback;
3913
+ }
3914
+ });
3915
+ this._events[eventName] = newCallbacks;
3916
+ return this;
3917
+ });
3918
+ this._events = {};
3919
+ }
3920
+ }
3921
+ export {
3922
+ AudioRecorder,
3923
+ Chain,
3924
+ C as Color,
3925
+ a as ColorScheme,
3926
+ F as FMT,
3927
+ H as Hsl,
3928
+ b as Hsla,
3929
+ Mathjs,
3930
+ M as MimeType,
3931
+ Monitor,
3932
+ QuestQueue,
3933
+ R as Rgb,
3934
+ c as Rgba,
3935
+ SyncHook,
3936
+ TOTP,
3937
+ addClassToElement,
3938
+ appendUrl,
3939
+ audioVendor,
3940
+ canvasVendor,
3941
+ d as changeHumpToLowerCase,
3942
+ e as clearBr,
3943
+ f as clearStr,
3944
+ g as componentToHex,
3945
+ compose,
3946
+ connection,
3947
+ convertImageToBase64,
3948
+ create,
3949
+ createData,
3950
+ createDocumentFragment,
3951
+ createObjectURL,
3952
+ currentDevice,
3953
+ debounce,
3954
+ durationHandler,
3955
+ encodeUrl,
3956
+ escapeHtml,
3957
+ filterObj,
3958
+ formatJson,
3959
+ generateThrottle,
3960
+ getAllQueryString,
3961
+ getCookie,
3962
+ getCookieByName,
3963
+ getFrame,
3964
+ getHost,
3965
+ h as getMime,
3966
+ getPerformance,
3967
+ getPixelRatio,
3968
+ getStatus,
3969
+ getWindow,
3970
+ handleConsole,
3971
+ handleError,
3972
+ handleFetchHook,
3973
+ i as hexToRgb,
3974
+ j as hsbToRgb,
3975
+ k as hslToRgb,
3976
+ l as hsvToHsl,
3977
+ m as hsvToRgb,
3978
+ n as hue2rgb,
3979
+ imageRequest,
3980
+ isBangDevice,
3981
+ isClient,
3982
+ isImageSize,
3983
+ isMobile,
3984
+ isString,
3985
+ isWeiXin,
3986
+ localStorageGetItem,
3987
+ localStorageSetItem,
3988
+ mathjs,
3989
+ memoize,
3990
+ merge,
3991
+ mergeExports,
3992
+ networkSpeed,
3993
+ noop,
3994
+ perToNum,
3995
+ performanceTime,
3996
+ querystring,
3997
+ r as randomColor,
3998
+ randomString,
3999
+ range,
4000
+ removeClassToElement,
4001
+ removeGhosting,
4002
+ replaceOld,
4003
+ report,
4004
+ requestAnimation,
4005
+ requestUrlToBuffer,
4006
+ retain,
4007
+ q as rgbToHex,
4008
+ s as rgbToHsb,
4009
+ t as rgbToHsl,
4010
+ scriptOnLoad,
4011
+ setAttributeByGlobal,
4012
+ setFontSize2html,
4013
+ u as setMime,
4014
+ status,
4015
+ v as str2Xml,
4016
+ w as strParse,
4017
+ throttle,
4018
+ timeFormat,
4019
+ timestampToTime,
4020
+ webglVendor
4021
+ };