ranuts 0.1.0-alpha.2 → 0.1.0-alpha.20

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