hlp 3.7.4 → 3.7.6

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 (4) hide show
  1. package/hlp.esm.js +2106 -0
  2. package/hlp.js +1 -1
  3. package/package.json +13 -11
  4. package/_js/script.js +0 -3174
package/hlp.esm.js ADDED
@@ -0,0 +1,2106 @@
1
+ //#region _js/script.ts
2
+ var hlp = class hlp {
3
+ static x(input) {
4
+ if (typeof input === "function") try {
5
+ input = input();
6
+ return this.x(input);
7
+ } catch (e) {
8
+ return false;
9
+ }
10
+ if (input === null || input === false || typeof input === "string" && input.trim() == "" || typeof input === "object" && Object.keys(input).length === 0 && input.constructor === Object || typeof input === "undefined" || Array.isArray(input) && input.length === 0 || Array.isArray(input) && input.length === 1 && input[0] === "") return false;
11
+ return true;
12
+ }
13
+ static nx(input) {
14
+ return !this.x(input);
15
+ }
16
+ static true(input) {
17
+ if (typeof input === "function") try {
18
+ input = input();
19
+ return this.true(input);
20
+ } catch (e) {
21
+ return false;
22
+ }
23
+ if (input === void 0) return false;
24
+ if (input === null) return false;
25
+ if (input === false) return false;
26
+ if (Array.isArray(input) && input.length === 0) return false;
27
+ if (Array.isArray(input) && hlp.first(input) === "") return false;
28
+ if (typeof input === "object" && Object.keys(input).length === 0 && input.constructor === Object) return false;
29
+ if (input === 0) return false;
30
+ if (input === "0") return false;
31
+ if (input === "") return false;
32
+ if (input === " ") return false;
33
+ if (input === "null") return false;
34
+ if (input === "false") return false;
35
+ return true;
36
+ }
37
+ static false(input) {
38
+ if (typeof input === "function") try {
39
+ input = input();
40
+ return this.false(input);
41
+ } catch (e) {
42
+ return false;
43
+ }
44
+ if (input === void 0) return false;
45
+ if (input === null) return false;
46
+ if (input === false) return true;
47
+ if (Array.isArray(input) && input.length === 0) return false;
48
+ if (Array.isArray(input) && hlp.first(input) === "") return false;
49
+ if (typeof input === "object" && Object.keys(input).length === 0 && input.constructor === Object) return false;
50
+ if (input === 0) return true;
51
+ if (input === "0") return true;
52
+ if (input === "") return false;
53
+ if (input === " ") return false;
54
+ if (input === "null") return false;
55
+ if (input === "false") return true;
56
+ return false;
57
+ }
58
+ static v() {
59
+ if (this.nx(arguments)) return "";
60
+ for (let i = 0; i < arguments.length; i++) if (this.x(arguments[i])) return arguments[i];
61
+ return "";
62
+ }
63
+ static loop(input, fun) {
64
+ if (this.nx(input)) return null;
65
+ if (Array.isArray(input)) input.forEach((input__value, input__key) => {
66
+ fun(input__value, input__key);
67
+ });
68
+ else if (typeof input === "object") Object.entries(input).forEach(([input__key, input__value]) => {
69
+ fun(input__value, input__key);
70
+ });
71
+ }
72
+ static map(obj, fn, ctx) {
73
+ return Object.keys(obj).reduce((a, b) => {
74
+ a[b] = fn.call(ctx || null, b, obj[b]);
75
+ return a;
76
+ }, {});
77
+ }
78
+ static first(input) {
79
+ if (Array.isArray(input)) {
80
+ var ret = null;
81
+ input.forEach((input__value, input__key) => {
82
+ if (ret === null) ret = input__value;
83
+ });
84
+ return ret;
85
+ }
86
+ if (typeof input === "object") {
87
+ var ret = null;
88
+ Object.entries(input).forEach(([input__key, input__value]) => {
89
+ if (ret === null) ret = input__value;
90
+ });
91
+ return ret;
92
+ }
93
+ return null;
94
+ }
95
+ static last(input) {
96
+ if (Array.isArray(input)) {
97
+ let ret = null;
98
+ input.forEach((input__value, input__key) => {
99
+ ret = input__value;
100
+ });
101
+ return ret;
102
+ }
103
+ if (typeof input === "object") {
104
+ let ret = null;
105
+ Object.entries(input).forEach(([input__key, input__value]) => {
106
+ ret = input__value;
107
+ });
108
+ return ret;
109
+ }
110
+ return null;
111
+ }
112
+ static rand(input) {
113
+ if (Array.isArray(input)) return input[Math.floor(Math.random() * input.length)];
114
+ if (typeof input === "object") {
115
+ var input = Object.values(input);
116
+ return input[Math.floor(Math.random() * input.length)];
117
+ }
118
+ return null;
119
+ }
120
+ static random_string(length = 8, chars = null) {
121
+ if (chars === null) chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
122
+ let chars_length = chars.length, random_string = "";
123
+ for (let i = 0; i < length; i++) random_string += chars[~~(Math.random() * (chars_length - 1 - 0 + 1)) + 0];
124
+ return random_string;
125
+ }
126
+ static round(value = 0, decimals = 0) {
127
+ return Number(Math.round(value + "e" + decimals) + "e-" + decimals);
128
+ }
129
+ static isInteger(value) {
130
+ return !isNaN(value) && parseInt(Number(value)) == value && !isNaN(parseInt(value, 10));
131
+ }
132
+ static random_int(min = 0, max = 99999) {
133
+ if (!this.isInteger(min) || !this.isInteger(max)) return false;
134
+ if (min > max) [min, max] = [max, min];
135
+ return ~~(Math.random() * (max - min + 1)) + min;
136
+ }
137
+ static capitalize(string = null) {
138
+ if (string === null) return string;
139
+ if (string === "") return string;
140
+ return string.charAt(0).toUpperCase() + string.slice(1);
141
+ }
142
+ static cookieExists(cookie_name) {
143
+ if (document.cookie !== void 0 && this.cookieGet(cookie_name) !== null) return true;
144
+ return false;
145
+ }
146
+ static cookieGet(cookie_name) {
147
+ var cookie_match = document.cookie.match(new RegExp(cookie_name + "=([^;]+)"));
148
+ if (cookie_match) return decodeURIComponent(cookie_match[1]);
149
+ return null;
150
+ }
151
+ static cookieSet(cookie_name, cookie_value, days, full_domain = true) {
152
+ let samesite = "";
153
+ if (window.location.protocol.indexOf("https") > -1) samesite = "; SameSite=None; Secure";
154
+ document.cookie = cookie_name + "=" + encodeURIComponent(cookie_value) + "; expires=" + new Date((/* @__PURE__ */ new Date()).getTime() + days * 24 * 60 * 60 * 1e3).toUTCString() + "; path=/" + samesite + "; domain=" + (full_domain === true ? this.urlHostTopLevel() : "");
155
+ }
156
+ static cookieDelete(cookie_name, full_domain = true) {
157
+ let samesite = "";
158
+ if (window.location.protocol.indexOf("https") > -1) samesite = "; SameSite=None; Secure";
159
+ document.cookie = cookie_name + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/" + samesite + "; domain=" + (full_domain === true ? this.urlHostTopLevel() : "");
160
+ }
161
+ static localStorageSet(key, value, ttl = 0) {
162
+ ttl = ttl * (1440 * 60 * 1e3);
163
+ let item = {
164
+ value,
165
+ expiry: (/* @__PURE__ */ new Date()).getTime() + ttl
166
+ };
167
+ localStorage.setItem(key, JSON.stringify(item));
168
+ }
169
+ static localStorageGet(key) {
170
+ let itemStr = localStorage.getItem(key);
171
+ if (!itemStr) return null;
172
+ let item = JSON.parse(itemStr);
173
+ if ((/* @__PURE__ */ new Date()).getTime() > item.expiry) {
174
+ localStorage.removeItem(key);
175
+ return null;
176
+ }
177
+ return item.value;
178
+ }
179
+ static localStorageDelete(key) {
180
+ localStorage.removeItem(key);
181
+ }
182
+ static localStorageExists(key) {
183
+ return this.localStorageGet(key) !== null;
184
+ }
185
+ static getParam(variable) {
186
+ let url = window.location.search;
187
+ if (this.nx(url)) return null;
188
+ let vars = url.substring(1).split("&");
189
+ for (var i = 0; i < vars.length; i++) {
190
+ var pair = vars[i].split("=");
191
+ if (pair[0] == variable && this.x(pair[1])) return pair[1];
192
+ }
193
+ return null;
194
+ }
195
+ static getDevice() {
196
+ if (this.isPhone()) return "phone";
197
+ if (this.isTablet()) return "tablet";
198
+ return "desktop";
199
+ }
200
+ static isPhone() {
201
+ let a = navigator.userAgent || navigator.vendor || window.opera;
202
+ return /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4));
203
+ }
204
+ static isTablet() {
205
+ let a = navigator.userAgent || navigator.vendor || window.opera;
206
+ return /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4));
207
+ }
208
+ static isDesktop() {
209
+ return !this.isPhone() && !this.isTablet();
210
+ }
211
+ static isMobile() {
212
+ if (window.innerWidth < 750 || this.isPhone()) return true;
213
+ return false;
214
+ }
215
+ static isTouch() {
216
+ return "ontouchstart" in window || navigator.maxTouchPoints || false;
217
+ }
218
+ static isPageSpeed() {
219
+ const ua = navigator.userAgent || "";
220
+ let score = 0;
221
+ if (/Lighthouse|HeadlessChrome|Chrome-Lighthouse|Speed Insights|PTST|PageSpeed/i.test(ua)) return true;
222
+ if (navigator.webdriver) return true;
223
+ if (!navigator.languages || navigator.languages.length === 0) score += 3;
224
+ if (/moto g power|Moto G4/i.test(ua)) score += 2;
225
+ if (/Chrome\/\d{3}\.0\.0\.0/i.test(ua)) score += 1;
226
+ if (typeof window !== "undefined") {
227
+ const w = window.innerWidth;
228
+ const h = window.innerHeight;
229
+ if (w === 1350 && h === 940 || w === 412 && (h === 823 || h === 915) || w === 360 && h === 640) score += 2;
230
+ }
231
+ if (navigator.plugins && navigator.plugins.length === 0) score += 1;
232
+ if (!navigator.connection && !navigator.deviceMemory && !navigator.hardwareConcurrency) score += 1;
233
+ if (typeof navigator.permissions === "undefined") score += 1;
234
+ if (/Chrome/i.test(ua) && typeof window.chrome === "undefined") score += 2;
235
+ return score >= 4;
236
+ }
237
+ static isMac() {
238
+ return hlp.getOs() === "mac";
239
+ }
240
+ static isLinux() {
241
+ return hlp.getOs() === "linux";
242
+ }
243
+ static isWindows() {
244
+ return hlp.getOs() === "windows";
245
+ }
246
+ static getOs() {
247
+ let userAgent = window.navigator.userAgent, platform = window.navigator.platform, macosPlatforms = [
248
+ "Macintosh",
249
+ "MacIntel",
250
+ "MacPPC",
251
+ "Mac68K"
252
+ ], windowsPlatforms = [
253
+ "Win32",
254
+ "Win64",
255
+ "Windows",
256
+ "WinCE"
257
+ ], iosPlatforms = [
258
+ "iPhone",
259
+ "iPad",
260
+ "iPod"
261
+ ], os = "unknown";
262
+ if (macosPlatforms.indexOf(platform) !== -1) os = "mac";
263
+ else if (iosPlatforms.indexOf(platform) !== -1) os = "mac";
264
+ else if (windowsPlatforms.indexOf(platform) !== -1) os = "windows";
265
+ else if (/Android/.test(userAgent)) os = "linux";
266
+ else if (/Linux/.test(platform)) os = "linux";
267
+ return os;
268
+ }
269
+ static getBrowser() {
270
+ let browser_name = "", isEdge = !!!document.documentMode && !!window.StyleMedia;
271
+ if (navigator.userAgent.indexOf("Opera") != -1 || navigator.userAgent.indexOf("OPR") != -1) browser_name = "opera";
272
+ else if (navigator.userAgent.indexOf("Chrome") != -1 && !isEdge) browser_name = "chrome";
273
+ else if (navigator.userAgent.indexOf("Safari") != -1 && !isEdge) browser_name = "safari";
274
+ else if (navigator.userAgent.indexOf("Firefox") != -1) browser_name = "firefox";
275
+ else if (navigator.userAgent.indexOf("MSIE") != -1 || !!document.documentMode == true) browser_name = "ie";
276
+ else if (isEdge) browser_name = "edge";
277
+ else browser_name = "unknown";
278
+ return browser_name;
279
+ }
280
+ static isObject(a) {
281
+ return !!a && a.constructor === Object;
282
+ }
283
+ static isArray(a) {
284
+ return !!a && a.constructor === Array;
285
+ }
286
+ static isString(string) {
287
+ return typeof string === "string" || string instanceof String;
288
+ }
289
+ static isDate(string) {
290
+ if (this.nx(string)) return false;
291
+ if (Object.prototype.toString.call(string) === "[object Date]") return true;
292
+ if (!this.isString(string)) return false;
293
+ if (string.split("-").length !== 3) return false;
294
+ let day = parseInt(string.split("-")[2]), month = parseInt(string.split("-")[1]), year = parseInt(string.split("-")[0]), date = /* @__PURE__ */ new Date();
295
+ date.setFullYear(year, month - 1, day);
296
+ if (date.getFullYear() == year && date.getMonth() + 1 == month && date.getDate() == day) return true;
297
+ return false;
298
+ }
299
+ static password_generate(length = 20, chars = [
300
+ "a-z",
301
+ "A-Z",
302
+ "0-9",
303
+ "$!?"
304
+ ], exclude = "lI") {
305
+ if (chars === null || !chars.length || length < chars.length) return null;
306
+ let charGroups = [];
307
+ for (let group of chars) {
308
+ let expanded = [];
309
+ if (group === "a-z") expanded = Array.from({ length: 26 }, (_, i) => String.fromCharCode(97 + i));
310
+ else if (group === "A-Z") expanded = Array.from({ length: 26 }, (_, i) => String.fromCharCode(65 + i));
311
+ else if (group === "0-9") expanded = Array.from({ length: 10 }, (_, i) => String.fromCharCode(48 + i));
312
+ else expanded = group.split("");
313
+ if (exclude) expanded = expanded.filter((c) => !exclude.includes(c));
314
+ if (expanded.length === 0) return null;
315
+ charGroups.push(expanded);
316
+ }
317
+ let passwordChars = charGroups.map((group) => group[Math.floor(Math.random() * group.length)]);
318
+ let allChars = charGroups.flat();
319
+ while (passwordChars.length < length) {
320
+ let i = Math.floor(Math.random() * allChars.length);
321
+ passwordChars.push(allChars[i]);
322
+ }
323
+ for (let i = passwordChars.length - 1; i > 0; i--) {
324
+ let j = Math.floor(Math.random() * (i + 1));
325
+ [passwordChars[i], passwordChars[j]] = [passwordChars[j], passwordChars[i]];
326
+ }
327
+ return passwordChars.join("");
328
+ }
329
+ static formatNumber(number, decimals = 0, dec_point = ".", thousands_sep = ",") {
330
+ number = (number + "").replace(/[^0-9+\-Ee.]/g, "");
331
+ var n = !isFinite(+number) ? 0 : +number, prec = !isFinite(+decimals) ? 0 : Math.abs(decimals), sep = typeof thousands_sep === "undefined" ? "," : thousands_sep, dec = typeof dec_point === "undefined" ? "." : dec_point, s = "", toFixedFix = function(n, prec) {
332
+ var k = Math.pow(10, prec);
333
+ return "" + Math.round(n * k) / k;
334
+ };
335
+ s = (prec ? toFixedFix(n, prec) : "" + Math.round(n)).split(".");
336
+ if (s[0].length > 3) s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
337
+ if ((s[1] || "").length < prec) {
338
+ s[1] = s[1] || "";
339
+ s[1] += new Array(prec - s[1].length + 1).join("0");
340
+ }
341
+ return s.join(dec);
342
+ }
343
+ static formatDate(format, date = null) {
344
+ if (date === false || date === true || date === null || date === "") date = /* @__PURE__ */ new Date();
345
+ else if (typeof date !== "object") date = new Date(date.replace(/-/g, "/").replace(/T|Z/g, " "));
346
+ let string = "", mo = date.getMonth(), m1 = mo + 1, dow = date.getDay(), d = date.getDate(), y = date.getFullYear(), h = date.getHours(), mi = date.getMinutes(), s = date.getSeconds();
347
+ for (let i = 0, len = format.length; i < len; i++) switch (format[i]) {
348
+ case "j":
349
+ string += d;
350
+ break;
351
+ case "d":
352
+ string += d < 10 ? "0" + d : d;
353
+ break;
354
+ case "l":
355
+ let days = Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
356
+ string += days[dow];
357
+ break;
358
+ case "w":
359
+ string += dow;
360
+ break;
361
+ case "D":
362
+ days = Array("Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat");
363
+ string += days[dow];
364
+ break;
365
+ case "m":
366
+ string += m1 < 10 ? "0" + m1 : m1;
367
+ break;
368
+ case "n":
369
+ string += m1;
370
+ break;
371
+ case "F":
372
+ let months = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
373
+ string += months[mo];
374
+ break;
375
+ case "M":
376
+ months = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
377
+ string += months[mo];
378
+ break;
379
+ case "Y":
380
+ string += y;
381
+ break;
382
+ case "y":
383
+ string += y.toString().slice(-2);
384
+ break;
385
+ case "H":
386
+ string += h < 10 ? "0" + h : h;
387
+ break;
388
+ case "g":
389
+ let hour = h === 0 ? 12 : h;
390
+ string += hour > 12 ? hour - 12 : hour;
391
+ break;
392
+ case "h":
393
+ hour = h === 0 ? 12 : h;
394
+ hour = hour > 12 ? hour - 12 : hour;
395
+ string += hour < 10 ? "0" + hour : hour;
396
+ break;
397
+ case "a":
398
+ string += h < 12 ? "am" : "pm";
399
+ break;
400
+ case "i":
401
+ string += mi < 10 ? "0" + mi : mi;
402
+ break;
403
+ case "s":
404
+ string += s < 10 ? "0" + s : s;
405
+ break;
406
+ case "c":
407
+ string += date.toISOString();
408
+ break;
409
+ default: string += format[i];
410
+ }
411
+ return string;
412
+ }
413
+ static deepCopy(obj, hash = /* @__PURE__ */ new WeakMap()) {
414
+ if (Object(obj) !== obj) return obj;
415
+ if (hash.has(obj)) return hash.get(obj);
416
+ const result = obj instanceof Date ? new Date(obj) : obj instanceof RegExp ? new RegExp(obj.source, obj.flags) : obj.constructor ? new obj.constructor() : Object.create(null);
417
+ hash.set(obj, result);
418
+ if (obj instanceof Map) Array.from(obj, ([key, val]) => result.set(key, hlp.deepCopy(val, hash)));
419
+ return Object.assign(result, ...Object.keys(obj).map((key) => ({ [key]: hlp.deepCopy(obj[key], hash) })));
420
+ }
421
+ static jsonStringToObject(string) {
422
+ if (this.nx(string) || !this.isString(string)) return null;
423
+ try {
424
+ return JSON.parse(string);
425
+ } catch (error) {
426
+ return null;
427
+ }
428
+ }
429
+ static isJsonString(string) {
430
+ if (this.nx(string) || !this.isString(string)) return false;
431
+ try {
432
+ JSON.parse(string);
433
+ return true;
434
+ } catch (error) {
435
+ return false;
436
+ }
437
+ }
438
+ static jsonObjectToString(object) {
439
+ try {
440
+ return JSON.stringify(object);
441
+ } catch (error) {
442
+ return null;
443
+ }
444
+ }
445
+ static uuid() {
446
+ function s4() {
447
+ return Math.floor((1 + Math.random()) * 65536).toString(16).substring(1);
448
+ }
449
+ return s4() + s4() + "-" + s4() + "-" + s4() + "-" + s4() + "-" + s4() + s4() + s4();
450
+ }
451
+ static guid() {
452
+ return this.uuid();
453
+ }
454
+ static replaceAll(string, search, replace) {
455
+ return string.split(search).join(replace);
456
+ }
457
+ static replaceLast(string, search, replace) {
458
+ let n = string.lastIndexOf(search);
459
+ string = string.slice(0, n) + string.slice(n).replace(search, replace);
460
+ return string;
461
+ }
462
+ static replaceFirst(string, search, replace) {
463
+ return string.replace(search, replace);
464
+ }
465
+ static findAllPositions(searchStr, str) {
466
+ let searchStrLen = searchStr.length, startIndex = 0, index, indices = [];
467
+ if (searchStrLen == 0) return [];
468
+ while ((index = str.indexOf(searchStr, startIndex)) > -1) {
469
+ indices.push(index);
470
+ startIndex = index + searchStrLen;
471
+ }
472
+ return indices;
473
+ }
474
+ static findAllPositionsCaseInsensitive(searchStr, str) {
475
+ let searchStrLen = searchStr.length, startIndex = 0, index, indices = [];
476
+ if (searchStrLen == 0) return [];
477
+ while ((index = this.indexOfCaseInsensitive(searchStr, str, startIndex)) > -1) {
478
+ indices.push(index);
479
+ startIndex = index + searchStrLen;
480
+ }
481
+ return indices;
482
+ }
483
+ static countAllOccurences(value, str) {
484
+ let regExp = new RegExp(value, "g");
485
+ return (str.match(regExp) || []).length;
486
+ }
487
+ static countAllOccurencesCaseInsensitive(value, str) {
488
+ let regExp = new RegExp(value, "gi");
489
+ return (str.match(regExp) || []).length;
490
+ }
491
+ static indexOfCaseInsensitive(searchStr, str, offset) {
492
+ return str.toLowerCase().indexOf(searchStr.toLowerCase(), offset);
493
+ }
494
+ static highlight(string, query, strip = false, strip_length = 500) {
495
+ if (this.nx(string) || this.nx(query)) return string;
496
+ if (strip === true) {
497
+ let dots = "...";
498
+ let positions = this.findAllPositionsCaseInsensitive(query, string);
499
+ let words = string.split(" ");
500
+ let i = 0;
501
+ words.forEach((words__value, words__key) => {
502
+ let strip_now = true;
503
+ positions.forEach((positions__value) => {
504
+ if (i >= positions__value - strip_length && i <= positions__value + query.length + strip_length - 1) strip_now = false;
505
+ });
506
+ if (strip_now === true) words[words__key] = dots;
507
+ i += words__value.length + 1;
508
+ });
509
+ string = words.join(" ");
510
+ while (string.indexOf(dots + " ...") > -1) string = this.replaceAll(string, dots + " ...", dots);
511
+ string = string.trim();
512
+ }
513
+ let positions = this.findAllPositionsCaseInsensitive(query, string);
514
+ let wrap_begin = "<strong class=\"highlight\">";
515
+ let wrap_end = "</strong>";
516
+ for (let x = 0; x < positions.length; x++) {
517
+ string = string.substring(0, positions[x]) + wrap_begin + string.substring(positions[x], positions[x] + query.length) + wrap_end + string.substring(positions[x] + query.length);
518
+ for (let y = x + 1; y < positions.length; y++) positions[y] = positions[y] + 26 + 9;
519
+ }
520
+ return string;
521
+ }
522
+ static get(url, args = null) {
523
+ return this.call("GET", url, args);
524
+ }
525
+ static post(url, args = null) {
526
+ return this.call("POST", url, args);
527
+ }
528
+ static call(method, url, args = null) {
529
+ if (args === null) args = {};
530
+ if (!("data" in args)) args.data = {};
531
+ if (!("headers" in args)) args.headers = null;
532
+ if (!("throttle" in args)) args.throttle = 0;
533
+ if (!("allow_errors" in args)) args.allow_errors = true;
534
+ return new Promise((resolve, reject) => {
535
+ setTimeout(() => {
536
+ if (url.indexOf("http") !== 0) url = hlp.baseUrl() + "/" + url;
537
+ let xhr = new XMLHttpRequest();
538
+ xhr.open(method, url, true);
539
+ if (method === "POST") {
540
+ if ("data" in args && args.data !== null && typeof args.data === "object" && !(args.data instanceof FormData)) {
541
+ xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
542
+ args.data = JSON.stringify(args.data);
543
+ }
544
+ xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
545
+ }
546
+ if (this.x(args.headers)) Object.entries(args.headers).forEach(([headers__key, headers__value]) => {
547
+ xhr.setRequestHeader(headers__key, headers__value);
548
+ });
549
+ xhr.onload = () => {
550
+ if (xhr.readyState != 4 || args.allow_errors !== true && xhr.status != 200 && xhr.status != 304) if (this.isJsonString(xhr.responseText)) reject(this.jsonStringToObject(xhr.responseText));
551
+ else reject(xhr.responseText);
552
+ if (this.isJsonString(xhr.responseText)) resolve(this.jsonStringToObject(xhr.responseText));
553
+ else resolve(xhr.responseText);
554
+ };
555
+ xhr.onerror = () => {
556
+ reject([
557
+ xhr.readyState,
558
+ xhr.status,
559
+ xhr.statusText
560
+ ]);
561
+ };
562
+ if (method === "GET") xhr.send(null);
563
+ if (method === "POST") xhr.send(args.data);
564
+ }, args.throttle);
565
+ });
566
+ }
567
+ static onResizeHorizontal(fun) {
568
+ let windowWidth = window.innerWidth, windowWidthNew, timeout;
569
+ window.addEventListener("resize", () => {
570
+ windowWidthNew = window.innerWidth;
571
+ if (windowWidthNew != windowWidth) {
572
+ windowWidth = windowWidthNew;
573
+ if (timeout) clearTimeout(timeout);
574
+ timeout = window.setTimeout(() => {
575
+ fun();
576
+ }, 50);
577
+ }
578
+ });
579
+ fun();
580
+ }
581
+ static onResizeVertical(fun) {
582
+ var windowHeight = window.innerHeight, windowHeightNew, timeout;
583
+ window.addEventListener("resize", () => {
584
+ windowHeightNew = window.innerHeight;
585
+ if (windowHeightNew != windowHeight) {
586
+ windowHeight = windowHeightNew;
587
+ if (timeout) clearTimeout(timeout);
588
+ timeout = window.setTimeout(() => {
589
+ fun();
590
+ }, 50);
591
+ }
592
+ });
593
+ fun();
594
+ }
595
+ static removeEmpty(array) {
596
+ if (this.nx(array) || !Array.isArray(array)) return array;
597
+ array = array.filter((array__value) => {
598
+ return this.x(array__value);
599
+ });
600
+ return array;
601
+ }
602
+ static uniqueArray(array) {
603
+ let seen = {}, ret_arr = [];
604
+ for (let i = 0; i < array.length; i++) if (!(array[i] in seen)) {
605
+ ret_arr.push(array[i]);
606
+ seen[array[i]] = true;
607
+ }
608
+ return ret_arr;
609
+ }
610
+ static powerset(array) {
611
+ if (!Array.isArray(array)) return array;
612
+ return array.reduce((subsets, value) => subsets.concat(subsets.map((set) => [...set, value])), [[]]);
613
+ }
614
+ static charToInt(val) {
615
+ val = val.toUpperCase();
616
+ let base = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", i, j, result = 0;
617
+ for (i = 0, j = val.length - 1; i < val.length; i += 1, j -= 1) result += Math.pow(26, j) * (base.indexOf(val[i]) + 1);
618
+ return result;
619
+ }
620
+ static intToChar(num) {
621
+ for (var ret = "", a = 1, b = 26; (num -= a) >= 0; a = b, b *= 26) ret = String.fromCharCode(parseInt(num % b / a) + 65) + ret;
622
+ return ret;
623
+ }
624
+ static slugify(text) {
625
+ return text.toString().toLowerCase().trim().split("ä").join("ae").split("ö").join("oe").split("ü").join("ue").split("ß").join("ss").replace(/[^\w\s-]/g, "").replace(/[\s_-]+/g, "-").replace(/^-+|-+$/g, "");
626
+ }
627
+ static incChar(char, shift = 1) {
628
+ return this.intToChar(this.charToInt(char) + shift);
629
+ }
630
+ static decChar(char, shift = 1) {
631
+ return this.intToChar(this.charToInt(char) - shift);
632
+ }
633
+ static range(start, end) {
634
+ let range = [], typeofStart = typeof start, typeofEnd = typeof end, step = 1;
635
+ if (typeofStart == "undefined" || typeofEnd == "undefined" || typeofStart != typeofEnd) return null;
636
+ if (end < start) step = -step;
637
+ if (typeofStart == "number") while (step > 0 ? end >= start : end <= start) {
638
+ range.push(start);
639
+ start += step;
640
+ }
641
+ else if (typeofStart == "string") {
642
+ if (start.length != 1 || end.length != 1) return null;
643
+ start = start.charCodeAt(0);
644
+ end = end.charCodeAt(0);
645
+ while (step > 0 ? end >= start : end <= start) {
646
+ range.push(String.fromCharCode(start));
647
+ start += step;
648
+ }
649
+ } else return null;
650
+ return range;
651
+ }
652
+ static dateToWeek(d = null) {
653
+ if (d === null) d = /* @__PURE__ */ new Date();
654
+ d = new Date(Date.UTC(d.getFullYear(), d.getMonth(), d.getDate()));
655
+ d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
656
+ let yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
657
+ return Math.ceil(((d - yearStart) / 864e5 + 1) / 7);
658
+ }
659
+ static weekToDate(week, year) {
660
+ if (year == null) year = (/* @__PURE__ */ new Date()).getFullYear();
661
+ let date = /* @__PURE__ */ new Date();
662
+ date.setYear(year);
663
+ date.setDate(1);
664
+ date.setMonth(0);
665
+ date.setHours(0);
666
+ date.setMinutes(0);
667
+ date.setSeconds(0);
668
+ date.setMilliseconds(0);
669
+ let FIRST_DAY_OF_WEEK = 1;
670
+ let WEEK_LENGTH = 7;
671
+ let day = date.getDay();
672
+ day = day === 0 ? 7 : day;
673
+ let dayOffset = -day + FIRST_DAY_OF_WEEK;
674
+ if (WEEK_LENGTH - day + 1 < 4) dayOffset += WEEK_LENGTH;
675
+ date = new Date(date.getTime() + dayOffset * 24 * 60 * 60 * 1e3);
676
+ let weekTime = 1e3 * 60 * 60 * 24 * 7 * (week - 1);
677
+ let targetTime = date.getTime() + weekTime;
678
+ date.setTime(targetTime);
679
+ date.setHours(0);
680
+ date.setMinutes(0);
681
+ date.setSeconds(0);
682
+ date.setMilliseconds(0);
683
+ return date;
684
+ }
685
+ static addDays(date, days) {
686
+ var result = new Date(date);
687
+ result.setDate(result.getDate() + days);
688
+ return result;
689
+ }
690
+ static diffInMonths(date1, date2) {
691
+ let d1 = new Date(date1), d2 = new Date(date2), yearDiff = d2.getFullYear() - d1.getFullYear(), monthDiff = d2.getMonth() - d1.getMonth(), dayDiff = d2.getDate() - d1.getDate(), daysInMonth = new Date(d2.getFullYear(), d2.getMonth() + 1, 0).getDate();
692
+ return yearDiff * 12 + monthDiff + dayDiff / daysInMonth;
693
+ }
694
+ static objectsAreEqual(x, y) {
695
+ var _this = this;
696
+ if (x === null || x === void 0 || y === null || y === void 0) return x === y;
697
+ if (x.constructor !== y.constructor) return false;
698
+ if (x instanceof Function) return x === y;
699
+ if (x instanceof RegExp) return x === y;
700
+ if (x === y || x.valueOf() === y.valueOf()) return true;
701
+ if (Array.isArray(x) && x.length !== y.length) return false;
702
+ if (x instanceof Date) return false;
703
+ if (!(x instanceof Object)) return false;
704
+ if (!(y instanceof Object)) return false;
705
+ var p = Object.keys(x);
706
+ return Object.keys(y).every(function(i) {
707
+ return p.indexOf(i) !== -1;
708
+ }) && p.every(function(i) {
709
+ return _this.objectsAreEqual(x[i], y[i]);
710
+ });
711
+ }
712
+ static containsObject(obj, list) {
713
+ var x;
714
+ for (x in list) if (list.hasOwnProperty(x) && this.objectsAreEqual(list[x], obj)) return true;
715
+ return false;
716
+ }
717
+ static fadeOut(el, speed = 1e3) {
718
+ if (speed <= 25) speed = 25;
719
+ return new Promise((resolve) => {
720
+ el.style.opacity = 1;
721
+ (function fade() {
722
+ if ((el.style.opacity -= 25 / speed) < 0) {
723
+ el.style.display = "none";
724
+ resolve();
725
+ } else requestAnimationFrame(fade);
726
+ })();
727
+ });
728
+ }
729
+ static fadeIn(el, speed = 1e3) {
730
+ if (speed <= 25) speed = 25;
731
+ return new Promise((resolve) => {
732
+ el.style.opacity = 0;
733
+ el.style.display = "block";
734
+ (function fade() {
735
+ var val = parseFloat(el.style.opacity);
736
+ if (!((val += 25 / speed) > 1)) {
737
+ el.style.opacity = val;
738
+ requestAnimationFrame(fade);
739
+ } else resolve();
740
+ })();
741
+ });
742
+ }
743
+ static scrollTop() {
744
+ let doc = document.documentElement;
745
+ return (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0);
746
+ }
747
+ static scrollLeft() {
748
+ let doc = document.documentElement;
749
+ return (window.pageXOffset || doc.scrollLeft) - (doc.clientLeft || 0);
750
+ }
751
+ static closestScrollable(node) {
752
+ let overflowY = node instanceof HTMLElement && window.getComputedStyle(node).overflowY, isScrollable = overflowY && !(overflowY.includes("hidden") || overflowY.includes("visible"));
753
+ if (!node) return null;
754
+ else if (isScrollable && node.scrollHeight >= node.clientHeight) return node;
755
+ return this.closestScrollable(node.parentNode) || document.scrollingElement || document.body;
756
+ }
757
+ static offsetTop(el) {
758
+ return el.getBoundingClientRect().top + window.pageYOffset - document.documentElement.clientTop;
759
+ }
760
+ static offsetLeft(el) {
761
+ return el.getBoundingClientRect().left + window.pageXOffset - document.documentElement.clientLeft;
762
+ }
763
+ static offsetRight(el) {
764
+ return el.getBoundingClientRect().left + window.pageXOffset - document.documentElement.clientLeft + el.offsetWidth;
765
+ }
766
+ static offsetBottom(el) {
767
+ return el.getBoundingClientRect().top + window.pageYOffset - document.documentElement.clientTop + el.offsetHeight;
768
+ }
769
+ static offsetTopWithMargin(el) {
770
+ return this.offsetTop(el) - parseInt(getComputedStyle(el).marginTop);
771
+ }
772
+ static offsetLeftWithMargin(el) {
773
+ return this.offsetLeft(el) - parseInt(getComputedStyle(el).marginLeft);
774
+ }
775
+ static offsetRightWithMargin(el) {
776
+ return this.offsetRight(el) + parseInt(getComputedStyle(el).marginRight);
777
+ }
778
+ static offsetBottomWithMargin(el) {
779
+ return this.offsetBottom(el) + parseInt(getComputedStyle(el).marginBottom);
780
+ }
781
+ static documentHeight() {
782
+ return Math.max(document.body.offsetHeight, document.body.scrollHeight, document.documentElement.clientHeight, document.documentElement.offsetHeight, document.documentElement.scrollHeight);
783
+ }
784
+ static documentWidth() {
785
+ return document.documentElement.clientWidth || document.body.clientWidth;
786
+ }
787
+ static windowWidth() {
788
+ return window.innerWidth;
789
+ }
790
+ static windowHeight() {
791
+ return window.innerHeight;
792
+ }
793
+ static windowWidthWithoutScrollbar() {
794
+ return document.documentElement.clientWidth || document.body.clientWidth;
795
+ }
796
+ static windowHeightWithoutScrollbar() {
797
+ return document.documentElement.clientHeight || document.body.clientHeight;
798
+ }
799
+ static outerWidthWithMargin(el) {
800
+ return el.offsetWidth + parseInt(getComputedStyle(el).marginLeft) + parseInt(getComputedStyle(el).marginRight);
801
+ }
802
+ static outerHeightWithMargin(el) {
803
+ return el.offsetHeight + parseInt(getComputedStyle(el).marginTop) + parseInt(getComputedStyle(el).marginBottom);
804
+ }
805
+ static async cursorPosition() {
806
+ document.head.insertAdjacentHTML("afterbegin", `
807
+ <style type="text/css">
808
+ .find-pointer-quad {
809
+ --hit: 0;
810
+ position: fixed;
811
+ z-index:2147483647;
812
+ transform: translateZ(0);
813
+ &:hover { --hit: 1; }
814
+ }
815
+ </style>
816
+ `);
817
+ window.cursorPositionDelay = 50;
818
+ window.cursorPositionQuads = [];
819
+ let dim = 10;
820
+ let createQuad = (_, pos) => {
821
+ let a = document.createElement("a");
822
+ a.classList.add("find-pointer-quad");
823
+ let { style } = a;
824
+ style.top = pos < 2 ? 0 : `${dim}%`;
825
+ style.left = pos % 2 === 0 ? 0 : `${dim}%`;
826
+ style.width = style.height = `${dim}%`;
827
+ document.body.appendChild(a);
828
+ return a;
829
+ };
830
+ window.cursorPositionQuads = [
831
+ 1,
832
+ 2,
833
+ 3,
834
+ 4
835
+ ].map(createQuad);
836
+ return this.cursorPositionBisect(dim);
837
+ }
838
+ static cursorPositionBisect(dim) {
839
+ let hit;
840
+ window.cursorPositionQuads.some((a) => {
841
+ let style = getComputedStyle(a);
842
+ if (style.getPropertyValue(`--hit`) === `1`) return hit = {
843
+ style,
844
+ a
845
+ };
846
+ });
847
+ if (!hit) {
848
+ let [q1] = window.cursorPositionQuads;
849
+ let reset = Math.abs(dim) > 1e4;
850
+ let top = parseFloat(q1.style.top) - dim / 2;
851
+ let left = parseFloat(q1.style.left) - dim / 2;
852
+ window.cursorPositionQuads.forEach(({ style }, pos) => {
853
+ if (reset) {
854
+ style.top = pos < 2 ? 0 : `${dim}%`;
855
+ style.left = pos % 2 === 0 ? 0 : `${dim}%`;
856
+ style.width = style.height = `${dim}%`;
857
+ } else {
858
+ style.top = pos < 2 ? `${top}%` : `${top + dim}%`;
859
+ style.left = pos % 2 === 0 ? `${left}%` : `${left + dim}%`;
860
+ style.width = `${dim}%`;
861
+ style.height = `${dim}%`;
862
+ }
863
+ });
864
+ return new Promise((resolve) => {
865
+ setTimeout(() => resolve(this.cursorPositionBisect(!reset ? 2 * dim : dim)), window.cursorPositionDelay);
866
+ });
867
+ }
868
+ let { style, a } = hit;
869
+ let { top, left, width, height } = a.getBoundingClientRect();
870
+ if (width < 3) {
871
+ window.cursorPositionQuads.forEach((a) => a.remove());
872
+ return {
873
+ x: Math.round(left + width / 2 + window.scrollX),
874
+ y: Math.round(top + height / 2 + window.scrollY)
875
+ };
876
+ }
877
+ let ox = a.style.left;
878
+ let oy = a.style.top;
879
+ let nextStep = dim / 2;
880
+ window.cursorPositionQuads.forEach(({ style }, pos) => {
881
+ style.top = pos < 2 ? oy : `${nextStep + parseFloat(oy)}%`;
882
+ style.left = pos % 2 === 0 ? ox : `${nextStep + parseFloat(ox)}%`;
883
+ style.width = `${nextStep}%`;
884
+ style.height = `${nextStep}%`;
885
+ });
886
+ return new Promise((resolve) => {
887
+ setTimeout(() => resolve(this.cursorPositionBisect(nextStep)), window.cursorPositionDelay);
888
+ });
889
+ }
890
+ static scrollTo(to, duration = 1e3, element = null, offset = 0, only_up = false) {
891
+ return new Promise((resolve) => {
892
+ if (element === null) element = document.scrollingElement || document.documentElement;
893
+ if (!hlp.isNumeric(to)) if (element === (document.scrollingElement || documentElement)) to = this.offsetTopWithMargin(to);
894
+ else to = to.getBoundingClientRect().top - parseInt(getComputedStyle(to).marginTop) - (element.getBoundingClientRect().top - element.scrollTop - parseInt(getComputedStyle(element).marginTop));
895
+ let offset_calc = 0;
896
+ if (!Array.isArray(offset)) offset = [offset];
897
+ offset.forEach((offset__value) => {
898
+ if (hlp.isNumeric(offset__value)) offset_calc += offset__value;
899
+ else if (offset__value !== null) {
900
+ if (window.getComputedStyle(offset__value).position === "fixed") offset_calc += -1 * offset__value.offsetHeight;
901
+ }
902
+ });
903
+ to += offset_calc;
904
+ const start = element.scrollTop, change = to - start, startDate = +/* @__PURE__ */ new Date(), easeInOutCirc = function(t, b, c, d) {
905
+ t /= d / 2;
906
+ if (t < 1) return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b;
907
+ t -= 2;
908
+ return c / 2 * (Math.sqrt(1 - t * t) + 1) + b;
909
+ }, animateScroll = function() {
910
+ const currentTime = +/* @__PURE__ */ new Date() - startDate;
911
+ element.scrollTop = parseInt(easeInOutCirc(currentTime, start, change, duration));
912
+ if (currentTime < duration) requestAnimationFrame(animateScroll);
913
+ else {
914
+ element.scrollTop = to;
915
+ resolve();
916
+ }
917
+ };
918
+ if (only_up === true && change > 0) {
919
+ resolve();
920
+ return;
921
+ }
922
+ animateScroll();
923
+ });
924
+ }
925
+ static loadJs(urls) {
926
+ if (!hlp.isArray(urls)) urls = [urls];
927
+ let promises = [];
928
+ hlp.loop(urls, (urls__value, urls__key) => {
929
+ promises.push(new Promise((resolve, reject) => {
930
+ let script = document.createElement("script");
931
+ script.src = urls__value;
932
+ script.onload = () => {
933
+ resolve();
934
+ };
935
+ document.head.appendChild(script);
936
+ }));
937
+ });
938
+ return Promise.all(promises);
939
+ }
940
+ static async loadJsSequentially(urls) {
941
+ if (!hlp.isArray(urls)) urls = [urls];
942
+ for (let urls__value of urls) await hlp.loadJs(urls__value);
943
+ }
944
+ static triggerAfterAllImagesLoaded(selectorContainer, selectorImage, fn) {
945
+ window.addEventListener("load", (e) => {
946
+ if (document.querySelector(selectorContainer + " " + selectorImage) !== null) document.querySelectorAll(selectorContainer + " " + selectorImage).forEach((el) => {
947
+ this.triggerAfterAllImagesLoadedBindLoadEvent(el, selectorContainer, selectorImage, fn);
948
+ });
949
+ });
950
+ document.addEventListener("DOMContentLoaded", () => {
951
+ if (document.querySelector(selectorContainer) !== null) new MutationObserver((mutations) => {
952
+ mutations.forEach((mutation) => {
953
+ if (mutation.type === "childList" && mutation.addedNodes.length > 0) mutation.addedNodes.forEach((el) => {
954
+ this.triggerAfterAllImagesLoadedHandleEl(el, selectorContainer, selectorImage, fn);
955
+ });
956
+ else if (mutation.type === "attributes" && mutation.attributeName === "src" && mutation.target.classList.contains(selectorImage.replace(".", "")) && mutation.oldValue !== mutation.target.getAttribute("src")) this.triggerAfterAllImagesLoadedHandleEl(mutation.target, selectorContainer, selectorImage, fn);
957
+ });
958
+ }).observe(document.querySelector(selectorContainer), {
959
+ attributes: true,
960
+ childList: true,
961
+ characterData: false,
962
+ subtree: true,
963
+ attributeOldValue: true,
964
+ characterDataOldValue: false
965
+ });
966
+ });
967
+ }
968
+ static triggerAfterAllImagesLoadedHandleEl(el, selectorContainer, selectorImage, fn) {
969
+ if (el.nodeType === Node.ELEMENT_NODE) {
970
+ el.classList.remove("loaded-img");
971
+ el.closest(selectorContainer).classList.remove("loaded-all");
972
+ if (!el.classList.contains("binded-trigger")) {
973
+ el.classList.add("binded-trigger");
974
+ el.addEventListener("load", () => {
975
+ this.triggerAfterAllImagesLoadedBindLoadEvent(el, selectorContainer, selectorImage, fn);
976
+ });
977
+ }
978
+ }
979
+ }
980
+ static triggerAfterAllImagesLoadedBindLoadEvent(el, selectorContainer, selectorImage, fn) {
981
+ el.classList.add("loaded-img");
982
+ if (el.closest(selectorContainer).querySelectorAll(".loaded-img").length === el.closest(selectorContainer).querySelectorAll(selectorImage).length) {
983
+ el.closest(selectorContainer).classList.add("loaded-all");
984
+ fn();
985
+ }
986
+ }
987
+ static isVisible(el) {
988
+ return !!(el.offsetWidth || el.offsetHeight || el.getClientRects().length);
989
+ }
990
+ static isVisibleInViewport(el) {
991
+ if (!this.isVisible(el)) return false;
992
+ let rect = el.getBoundingClientRect();
993
+ return !(rect.bottom < 0 || rect.right < 0 || rect.left > window.innerWidth || rect.top > window.innerHeight);
994
+ }
995
+ static textareaAutoHeight(selector = "textarea") {
996
+ this.textareaSetHeights(selector);
997
+ this.onResizeHorizontal(() => {
998
+ this.textareaSetHeights(selector);
999
+ });
1000
+ [].forEach.call(document.querySelectorAll(selector), (el) => {
1001
+ el.addEventListener("keyup", (e) => {
1002
+ this.textareaSetHeight(e.target);
1003
+ });
1004
+ });
1005
+ }
1006
+ static textareaSetHeights(selector = "textarea") {
1007
+ [].forEach.call(document.querySelectorAll(selector), (el) => {
1008
+ if (this.isVisible(el)) this.textareaSetHeight(el);
1009
+ });
1010
+ }
1011
+ static textareaSetHeight(el) {
1012
+ el.style.height = "5px";
1013
+ el.style.height = el.scrollHeight + "px";
1014
+ }
1015
+ static real100vh(selector = null, percent = 100) {
1016
+ if (selector === null) {
1017
+ let fn = () => {
1018
+ let vh = window.innerHeight * .01;
1019
+ document.documentElement.style.setProperty("--vh", `${vh}px`);
1020
+ };
1021
+ fn();
1022
+ window.addEventListener("resize", () => {
1023
+ fn();
1024
+ });
1025
+ } else {
1026
+ let fn = () => {
1027
+ console.log(selector);
1028
+ if (document.querySelector(selector) !== null) document.querySelectorAll(selector).forEach((selector__value) => {
1029
+ selector__value.style.height = window.innerHeight * (percent / 100) + "px";
1030
+ });
1031
+ };
1032
+ fn();
1033
+ window.addEventListener("resize", () => {
1034
+ fn();
1035
+ });
1036
+ }
1037
+ }
1038
+ static iOsRemoveHover() {
1039
+ if (hlp.getBrowser() === "safari" && hlp.getDevice() !== "desktop") hlp.on("touchend", "a", (e, el) => {
1040
+ el.click();
1041
+ });
1042
+ }
1043
+ static isNumeric(n) {
1044
+ return !isNaN(parseFloat(n)) && isFinite(n);
1045
+ }
1046
+ static animate(el, from, to, easing, duration) {
1047
+ return new Promise((resolve) => {
1048
+ if (duration <= 50) duration = 50;
1049
+ let properties = [];
1050
+ from.split(";").forEach((from__value) => {
1051
+ properties.push(from__value.split(":")[0].trim());
1052
+ });
1053
+ let transition = [];
1054
+ properties.forEach((properties__value) => {
1055
+ transition.push(properties__value + " " + Math.round(duration / 1e3 * 10) / 10 + "s " + easing);
1056
+ });
1057
+ transition = "transition: " + transition.join(", ") + " !important;";
1058
+ let els = null;
1059
+ if (NodeList.prototype.isPrototypeOf(el)) els = Array.from(el);
1060
+ else if (el === null) {
1061
+ console.log("cannot animate element from " + from + " to " + to + " because it does not exist");
1062
+ resolve();
1063
+ } else els = [el];
1064
+ let toFinish = els.length;
1065
+ els.forEach((els__value, els__key) => {
1066
+ let random_class = hlp.random_string(10, "abcdefghijklmnopqrstuvwxyz");
1067
+ els__value.classList.add(random_class);
1068
+ window.requestAnimationFrame(() => {
1069
+ let new_style = [];
1070
+ let prev_style = els__value.getAttribute("style");
1071
+ if (prev_style !== null) prev_style.split(";").forEach((prev_style__value) => {
1072
+ if (prev_style__value != "" && !properties.includes(prev_style__value.split(":")[0].trim())) new_style.push(prev_style__value);
1073
+ });
1074
+ if (new_style.length > 0) new_style = new_style.join(";") + ";" + from + ";";
1075
+ else new_style = from + ";";
1076
+ els__value.setAttribute("style", new_style);
1077
+ window.requestAnimationFrame(() => {
1078
+ let style = document.createElement("style");
1079
+ style.innerHTML = "." + random_class + " { " + transition + " }";
1080
+ document.head.appendChild(style);
1081
+ window.requestAnimationFrame(() => {
1082
+ els__value.setAttribute("style", els__value.getAttribute("style").replace(from + ";", "") + to + ";");
1083
+ if (this.isVisible(els__value)) {
1084
+ let fired = false;
1085
+ hlp.addEventListenerOnce(els__value, "transitionend", (event) => {
1086
+ fired = true;
1087
+ if (event.target !== event.currentTarget) return false;
1088
+ if (document.head.contains(style)) document.head.removeChild(style);
1089
+ els__value.classList.remove(random_class);
1090
+ toFinish--;
1091
+ if (toFinish <= 0) window.requestAnimationFrame(() => {
1092
+ resolve();
1093
+ });
1094
+ });
1095
+ setTimeout(() => {
1096
+ if (fired === false) {
1097
+ if (document.head.contains(style)) document.head.removeChild(style);
1098
+ els__value.classList.remove(random_class);
1099
+ toFinish--;
1100
+ if (toFinish <= 0) resolve();
1101
+ }
1102
+ }, duration * 1.5);
1103
+ } else {
1104
+ if (document.head.contains(style)) document.head.removeChild(style);
1105
+ els__value.classList.remove(random_class);
1106
+ toFinish--;
1107
+ if (toFinish <= 0) resolve();
1108
+ }
1109
+ });
1110
+ });
1111
+ });
1112
+ });
1113
+ });
1114
+ }
1115
+ static addEventListenerOnce(target, type, listener, addOptions, removeOptions) {
1116
+ target.addEventListener(type, function fn(event) {
1117
+ if (listener.apply(this, arguments, addOptions) !== false) target.removeEventListener(type, fn, removeOptions);
1118
+ });
1119
+ }
1120
+ static htmlDecode(value) {
1121
+ let tmp = document.createElement("textarea");
1122
+ tmp.innerHTML = value;
1123
+ return tmp.value;
1124
+ }
1125
+ static htmlEncode(value) {
1126
+ return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#x27;").replace(/`/g, "&#96;");
1127
+ }
1128
+ static nl2br(str) {
1129
+ if (typeof str === "undefined" || str === null) return "";
1130
+ return (str + "").replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, "$1<br/>");
1131
+ }
1132
+ static br2nl(str) {
1133
+ if (typeof str === "undefined" || str === null) return "";
1134
+ return str.replace(/<\s*\/?br\s*[\/]?>/gi, "\n");
1135
+ }
1136
+ static closest(el, selector) {
1137
+ if (!document.documentElement.contains(el)) return null;
1138
+ do {
1139
+ if (this.matches(el, selector)) return el;
1140
+ el = el.parentElement || el.parentNode;
1141
+ } while (el !== null && el.nodeType === 1);
1142
+ return null;
1143
+ }
1144
+ static matches(el, selector) {
1145
+ let node = el, nodes = (node.parentNode || node.document).querySelectorAll(selector), i = -1;
1146
+ while (nodes[++i] && nodes[i] != node);
1147
+ return !!nodes[i];
1148
+ }
1149
+ static wrap(el, html) {
1150
+ if (el === null) return;
1151
+ let wrapper = new DOMParser().parseFromString(html, "text/html").body.childNodes[0];
1152
+ el.parentNode.insertBefore(wrapper, el.nextSibling);
1153
+ wrapper.appendChild(el);
1154
+ }
1155
+ static wrapTextNodes(el, tag) {
1156
+ if (el === null) return;
1157
+ Array.from(el.childNodes).filter((node) => node.nodeType === 3 && node.textContent.trim().length > 1).forEach((node) => {
1158
+ const wrapper = document.createElement(tag);
1159
+ node.after(wrapper);
1160
+ wrapper.appendChild(node);
1161
+ });
1162
+ }
1163
+ static html2dom(html) {
1164
+ let template = document.createElement("template");
1165
+ html = html.trim();
1166
+ template.innerHTML = html;
1167
+ if (template.content === void 0) return this.html2domLegacy(html);
1168
+ return template.content.firstChild;
1169
+ }
1170
+ static html2domLegacy(html) {
1171
+ var rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi, rtagName = /<([\w:]+)/, rhtml = /<|&#?\w+;/, wrapMap = {
1172
+ option: [
1173
+ 1,
1174
+ "<select multiple='multiple'>",
1175
+ "</select>"
1176
+ ],
1177
+ thead: [
1178
+ 1,
1179
+ "<table>",
1180
+ "</table>"
1181
+ ],
1182
+ col: [
1183
+ 2,
1184
+ "<table><colgroup>",
1185
+ "</colgroup></table>"
1186
+ ],
1187
+ tr: [
1188
+ 2,
1189
+ "<table><tbody>",
1190
+ "</tbody></table>"
1191
+ ],
1192
+ td: [
1193
+ 3,
1194
+ "<table><tbody><tr>",
1195
+ "</tr></tbody></table>"
1196
+ ],
1197
+ _default: [
1198
+ 0,
1199
+ "",
1200
+ ""
1201
+ ]
1202
+ }, context = document;
1203
+ var tmp, tag, wrap, j, fragment = context.createDocumentFragment();
1204
+ if (!rhtml.test(html)) fragment.appendChild(context.createTextNode(html));
1205
+ else {
1206
+ tmp = fragment.appendChild(context.createElement("div"));
1207
+ tag = (rtagName.exec(html) || ["", ""])[1].toLowerCase();
1208
+ wrap = wrapMap[tag] || wrapMap._default;
1209
+ tmp.innerHTML = wrap[1] + html.replace(rxhtmlTag, "<$1></$2>") + wrap[2];
1210
+ j = wrap[0];
1211
+ while (j--) tmp = tmp.lastChild;
1212
+ fragment.removeChild(fragment.firstChild);
1213
+ while (tmp.firstChild) fragment.appendChild(tmp.firstChild);
1214
+ }
1215
+ return fragment.querySelector("*");
1216
+ }
1217
+ static prev(elem, filter) {
1218
+ let prev = elem.previousElementSibling;
1219
+ if (prev === null) return null;
1220
+ if (filter === void 0 || this.matches(prev, filter)) return prev;
1221
+ return null;
1222
+ }
1223
+ static next(elem, filter) {
1224
+ let next = elem.nextElementSibling;
1225
+ if (next === null) return null;
1226
+ if (filter === void 0 || this.matches(next, filter)) return next;
1227
+ return null;
1228
+ }
1229
+ static prevAll(elem, filter) {
1230
+ let sibs = [];
1231
+ while (elem = elem.previousElementSibling) if (filter === void 0 || this.matches(elem, filter)) sibs.push(elem);
1232
+ return sibs;
1233
+ }
1234
+ static nextAll(elem, filter) {
1235
+ let sibs = [];
1236
+ while (elem = elem.nextElementSibling) if (filter === void 0 || this.matches(elem, filter)) sibs.push(elem);
1237
+ return sibs;
1238
+ }
1239
+ static prevUntil(elem, filter) {
1240
+ let sibs = [];
1241
+ while (elem = elem.previousElementSibling) if (!this.matches(elem, filter)) sibs.push(elem);
1242
+ else break;
1243
+ return sibs;
1244
+ }
1245
+ static nextUntil(elem, filter) {
1246
+ let sibs = [];
1247
+ while (elem = elem.nextElementSibling) if (!this.matches(elem, filter)) sibs.push(elem);
1248
+ else break;
1249
+ return sibs;
1250
+ }
1251
+ static siblings(elem, filter) {
1252
+ let sibs = [];
1253
+ let self = elem;
1254
+ elem = elem.parentNode.firstChild;
1255
+ while (elem = elem.nextElementSibling) if (filter === void 0 || this.matches(elem, filter)) {
1256
+ if (self !== elem) sibs.push(elem);
1257
+ }
1258
+ return sibs;
1259
+ }
1260
+ static parents(elem, selector) {
1261
+ let elements = [];
1262
+ let ishaveselector = selector !== void 0;
1263
+ while ((elem = elem.parentElement) !== null) {
1264
+ if (elem.nodeType !== Node.ELEMENT_NODE) continue;
1265
+ if (!ishaveselector || this.matches(elem, selector)) elements.push(elem);
1266
+ }
1267
+ return elements;
1268
+ }
1269
+ static css(el) {
1270
+ let sheets = document.styleSheets, o = {};
1271
+ for (let sheets__key in sheets) try {
1272
+ let rules = sheets[sheets__key].rules || sheets[sheets__key].cssRules;
1273
+ for (let rules__key in rules) if (this.matches(el, rules[rules__key].selectorText)) o = Object.assign(o, this.css2json(rules[rules__key].style), this.css2json(el.getAttribute("style")));
1274
+ } catch (e) {}
1275
+ return o;
1276
+ }
1277
+ static css2json(css) {
1278
+ let obj = {};
1279
+ if (!css) return obj;
1280
+ if (css instanceof CSSStyleDeclaration) {
1281
+ for (let css__key in css) if (css[css__key].toLowerCase && css[css[css__key]] !== void 0) obj[css[css__key].toLowerCase()] = css[css[css__key]];
1282
+ } else if (typeof css == "string") {
1283
+ css = css.split(";");
1284
+ for (let css__key in css) if (css[css__key].indexOf(":") > -1) {
1285
+ let val = css[css__key].split(":");
1286
+ obj[val[0].toLowerCase().trim()] = val[1].trim();
1287
+ }
1288
+ }
1289
+ return obj;
1290
+ }
1291
+ static compareDates(d1, d2) {
1292
+ if (typeof d1 === "string") d1 = d1.split(" ").join("T");
1293
+ if (typeof d2 === "string") d2 = d2.split(" ").join("T");
1294
+ d1 = new Date(d1);
1295
+ d2 = new Date(d2);
1296
+ d1.setHours(0);
1297
+ d1.setMinutes(0);
1298
+ d1.setSeconds(0);
1299
+ d1.setMilliseconds(0);
1300
+ d2.setHours(0);
1301
+ d2.setMinutes(0);
1302
+ d2.setSeconds(0);
1303
+ d2.setMilliseconds(0);
1304
+ if (d1.getFullYear() === d2.getFullYear() && d1.getMonth() === d2.getMonth() && d1.getDate() === d2.getDate()) return 0;
1305
+ if (d1 < d2) return -1;
1306
+ return 1;
1307
+ }
1308
+ static spaceship(val1, val2) {
1309
+ if (val1 === null || val2 === null || typeof val1 != typeof val2) return null;
1310
+ if (typeof val1 === "string") return val1.localeCompare(val2);
1311
+ else {
1312
+ if (val1 > val2) return 1;
1313
+ else if (val1 < val2) return -1;
1314
+ return 0;
1315
+ }
1316
+ }
1317
+ static querySelectorAllShadowDom(selector) {
1318
+ let traverse = function($parent) {
1319
+ $els = [];
1320
+ if ($parent.querySelector("*") !== null) $parent.querySelectorAll("*").forEach(($el) => {
1321
+ $els.push($el);
1322
+ if ($el.shadowRoot !== void 0 && $el.shadowRoot !== null) $els = $els.concat(traverse($el.shadowRoot));
1323
+ });
1324
+ return $els;
1325
+ };
1326
+ let fragment = document.createDocumentFragment();
1327
+ $els = traverse(document);
1328
+ $els.forEach(($el) => {
1329
+ if ($el.matches(selector)) fragment.appendChild($el.cloneNode());
1330
+ });
1331
+ return fragment.childNodes;
1332
+ }
1333
+ static focus(selector) {
1334
+ hlp.unfocus();
1335
+ let el = null;
1336
+ if (typeof selector === "string" || selector instanceof String) el = document.querySelector(selector);
1337
+ else el = selector;
1338
+ if (el !== null) {
1339
+ let mask = document.createElement("div");
1340
+ mask.classList.add("hlp-focus-mask");
1341
+ mask.style.position = "fixed";
1342
+ mask.style.top = 0;
1343
+ mask.style.bottom = 0;
1344
+ mask.style.left = 0;
1345
+ mask.style.right = 0;
1346
+ mask.style.backgroundColor = "rgba(0,0,0,0.8)";
1347
+ mask.style.zIndex = 2147483646;
1348
+ el.before(mask);
1349
+ el.setAttribute("data-focussed", 1);
1350
+ el.setAttribute("data-focussed-orig-z-index", el.style.zIndex);
1351
+ el.setAttribute("data-focussed-orig-position", el.style.position);
1352
+ el.setAttribute("data-focussed-orig-background-color", el.style.backgroundColor);
1353
+ el.setAttribute("data-focussed-orig-box-shadow", el.style.boxShadow);
1354
+ el.style.zIndex = 2147483647;
1355
+ el.style.position = "relative";
1356
+ el.style.backgroundColor = "#ffffff";
1357
+ el.style.boxShadow = "0px 0px 0px 20px #fff";
1358
+ }
1359
+ }
1360
+ static unfocus() {
1361
+ if (document.querySelector(".hlp-focus-mask") !== null) document.querySelectorAll(".hlp-focus-mask").forEach((el) => {
1362
+ hlp.remove(el);
1363
+ });
1364
+ if (document.querySelector("[data-focussed]") !== null) document.querySelectorAll("[data-focussed]").forEach((el) => {
1365
+ el.style.zIndex = el.getAttribute("data-focussed-orig-z-index");
1366
+ el.style.position = el.getAttribute("data-focussed-orig-position");
1367
+ el.style.backgroundColor = el.getAttribute("data-focussed-orig-background-color");
1368
+ el.style.boxShadow = el.getAttribute("data-focussed-orig-box-shadow");
1369
+ el.removeAttribute("data-focussed");
1370
+ el.removeAttribute("data-focussed-orig-z-index");
1371
+ el.removeAttribute("data-focussed-orig-position");
1372
+ el.removeAttribute("data-focussed-orig-background-color");
1373
+ el.removeAttribute("data-focussed-orig-box-shadow");
1374
+ });
1375
+ }
1376
+ static remove(el) {
1377
+ if (el !== null) el.parentNode.removeChild(el);
1378
+ }
1379
+ static on(event, selector, scope, callback = null) {
1380
+ if (callback === null) {
1381
+ callback = scope;
1382
+ scope = document;
1383
+ } else scope = document.querySelector(scope);
1384
+ scope.addEventListener(event, (e) => {
1385
+ var el = hlp.closest(e.target, selector);
1386
+ if (el) callback(e, el);
1387
+ }, false);
1388
+ }
1389
+ static url() {
1390
+ return window.location.protocol + "//" + window.location.host + window.location.pathname;
1391
+ }
1392
+ static urlWithHash() {
1393
+ return window.location.protocol + "//" + window.location.host + window.location.pathname + window.location.hash;
1394
+ }
1395
+ static fullUrl() {
1396
+ return window.location.href;
1397
+ }
1398
+ static urlWithArgs() {
1399
+ return window.location.href.split("#")[0];
1400
+ }
1401
+ static baseUrl() {
1402
+ return window.location.protocol + "//" + window.location.host;
1403
+ }
1404
+ static urlProtocol() {
1405
+ return window.location.protocol + "//";
1406
+ }
1407
+ static urlHost() {
1408
+ return window.location.host;
1409
+ }
1410
+ static urlHostTopLevel() {
1411
+ let host = window.location.host;
1412
+ if (host.match(/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/)) return host;
1413
+ host = host.split(".");
1414
+ while (host.length > 2) host.shift();
1415
+ host = host.join(".");
1416
+ return host;
1417
+ }
1418
+ static urlPath() {
1419
+ return window.location.pathname;
1420
+ }
1421
+ static urlHash() {
1422
+ return window.location.hash;
1423
+ }
1424
+ static urlArgs() {
1425
+ return window.location.search;
1426
+ }
1427
+ static urlOfScript() {
1428
+ if (document.currentScript) return document.currentScript.src;
1429
+ else {
1430
+ let scripts = document.getElementsByTagName("script");
1431
+ return scripts[scripts.length - 1].src;
1432
+ }
1433
+ }
1434
+ static pathOfScript() {
1435
+ let script = this.urlOfScript();
1436
+ return script.substring(0, script.lastIndexOf("/"));
1437
+ }
1438
+ static waitUntil(selector, css_option = null, css_value = null) {
1439
+ return new Promise((resolve, reject) => {
1440
+ let timeout = setInterval(() => {
1441
+ if (document.querySelector(selector) !== null && (css_option === null || css_value === null && window.getComputedStyle(document.querySelector(selector))[css_option] !== void 0 && window.getComputedStyle(document.querySelector(selector))[css_option] != "" || css_value !== null && window.getComputedStyle(document.querySelector(selector))[css_option] === css_value)) {
1442
+ window.clearInterval(timeout);
1443
+ resolve();
1444
+ }
1445
+ }, 30);
1446
+ });
1447
+ }
1448
+ static waitUntilEach(selector, callback) {
1449
+ new MutationObserver(() => {
1450
+ let elements = document.querySelectorAll(selector);
1451
+ if (elements.length > 0) elements.forEach((element) => {
1452
+ if (!element.__processed) {
1453
+ element.__processed = true;
1454
+ callback(element);
1455
+ }
1456
+ });
1457
+ }).observe(document.body, {
1458
+ childList: true,
1459
+ subtree: true
1460
+ });
1461
+ let initialElements = document.querySelectorAll(selector);
1462
+ if (initialElements.length > 0) initialElements.forEach((element) => {
1463
+ if (!element.__processed) {
1464
+ element.__processed = true;
1465
+ callback(element);
1466
+ }
1467
+ });
1468
+ }
1469
+ static waitUntilVar(arg1 = null, arg2 = null, value = null) {
1470
+ let varName = null, parentContainer = null;
1471
+ if (arg2 === null) {
1472
+ varName = arg1;
1473
+ parentContainer = window;
1474
+ } else {
1475
+ varName = arg2;
1476
+ parentContainer = arg1;
1477
+ }
1478
+ return new Promise((resolve, reject) => {
1479
+ let timeout = setInterval(() => {
1480
+ if (parentContainer[varName] !== void 0 && parentContainer[varName] !== null) {
1481
+ if (value === null || parentContainer[varName] === value) {
1482
+ window.clearInterval(timeout);
1483
+ resolve();
1484
+ }
1485
+ }
1486
+ }, 30);
1487
+ });
1488
+ }
1489
+ static ready() {
1490
+ return new Promise((resolve) => {
1491
+ if (document.readyState !== "loading") return resolve();
1492
+ else document.addEventListener("DOMContentLoaded", () => {
1493
+ return resolve();
1494
+ });
1495
+ });
1496
+ }
1497
+ static load() {
1498
+ return new Promise((resolve) => {
1499
+ if (document.readyState === "complete") return resolve();
1500
+ else window.addEventListener("load", () => {
1501
+ return resolve();
1502
+ });
1503
+ });
1504
+ }
1505
+ static runForEl(selector, callback) {
1506
+ hlp.ready().then(() => {
1507
+ let id = hlp.pushId();
1508
+ if (document.querySelector(selector) !== null) document.querySelectorAll(selector).forEach((el) => {
1509
+ if (el.runForEl === void 0) el.runForEl = [];
1510
+ if (!el.runForEl.includes(id)) {
1511
+ el.runForEl.push(id);
1512
+ callback(el);
1513
+ }
1514
+ });
1515
+ if (window.runForEl_queue === void 0) window.runForEl_queue = [];
1516
+ if (window.runForEl_observer === void 0) window.runForEl_observer = new MutationObserver((mutations) => {
1517
+ mutations.forEach((mutations__value) => {
1518
+ if (!mutations__value.addedNodes) return;
1519
+ for (let i = 0; i < mutations__value.addedNodes.length; i++) {
1520
+ let node = mutations__value.addedNodes[i];
1521
+ if (node.nodeType === Node.ELEMENT_NODE) window.runForEl_queue.forEach((queue__value) => {
1522
+ if (node.matches(queue__value.selector)) {
1523
+ if (node.runForEl === void 0) node.runForEl = [];
1524
+ if (!node.runForEl.includes(queue__value.id)) {
1525
+ node.runForEl.push(queue__value.id);
1526
+ queue__value.callback(node);
1527
+ }
1528
+ }
1529
+ if (node.querySelector(queue__value.selector) !== null) node.querySelectorAll(queue__value.selector).forEach((nodes__value) => {
1530
+ if (nodes__value.runForEl === void 0) nodes__value.runForEl = [];
1531
+ if (!nodes__value.runForEl.includes(queue__value.id)) {
1532
+ nodes__value.runForEl.push(queue__value.id);
1533
+ queue__value.callback(nodes__value);
1534
+ }
1535
+ });
1536
+ });
1537
+ }
1538
+ });
1539
+ }).observe(document.body, {
1540
+ attributes: false,
1541
+ childList: true,
1542
+ characterData: false,
1543
+ subtree: true,
1544
+ attributeOldValue: false,
1545
+ characterDataOldValue: false
1546
+ });
1547
+ window.runForEl_queue.push({
1548
+ id,
1549
+ selector,
1550
+ callback
1551
+ });
1552
+ });
1553
+ }
1554
+ static fmath(op, x, y, precision = 8) {
1555
+ let n = {
1556
+ "*": x * y,
1557
+ "-": x - y,
1558
+ "+": x + y,
1559
+ "/": x / y
1560
+ }[op];
1561
+ return Math.round(n * 10 * Math.pow(10, precision)) / (10 * Math.pow(10, precision));
1562
+ }
1563
+ static trim(str, charlist) {
1564
+ let whitespace = [
1565
+ " ",
1566
+ "\n",
1567
+ "\r",
1568
+ " ",
1569
+ "\f",
1570
+ "\v",
1571
+ "\xA0",
1572
+ " ",
1573
+ " ",
1574
+ " ",
1575
+ " ",
1576
+ " ",
1577
+ " ",
1578
+ " ",
1579
+ " ",
1580
+ " ",
1581
+ " ",
1582
+ " ",
1583
+ "​",
1584
+ "\u2028",
1585
+ "\u2029",
1586
+ " "
1587
+ ].join("");
1588
+ let l = 0;
1589
+ let i = 0;
1590
+ str += "";
1591
+ if (charlist) whitespace = (charlist + "").replace(/([[\]().?/*{}+$^:])/g, "$1");
1592
+ l = str.length;
1593
+ for (i = 0; i < l; i++) if (whitespace.indexOf(str.charAt(i)) === -1) {
1594
+ str = str.substring(i);
1595
+ break;
1596
+ }
1597
+ l = str.length;
1598
+ for (i = l - 1; i >= 0; i--) if (whitespace.indexOf(str.charAt(i)) === -1) {
1599
+ str = str.substring(0, i + 1);
1600
+ break;
1601
+ }
1602
+ return whitespace.indexOf(str.charAt(0)) === -1 ? str : "";
1603
+ }
1604
+ static ltrim(str, charlist) {
1605
+ charlist = !charlist ? " \\s\xA0" : (charlist + "").replace(/([[\]().?/*{}+$^:])/g, "$1");
1606
+ const re = new RegExp("^[" + charlist + "]+", "g");
1607
+ return (str + "").replace(re, "");
1608
+ }
1609
+ static rtrim(str, charlist) {
1610
+ charlist = !charlist ? " \\s\xA0" : (charlist + "").replace(/([[\]().?/*{}+$^:])/g, "\\$1");
1611
+ const re = new RegExp("[" + charlist + "]+$", "g");
1612
+ return (str + "").replace(re, "");
1613
+ }
1614
+ static truncate_string(str, len = 50, chars = "...") {
1615
+ if (this.nx(str) || !(typeof str === "string" || str instanceof String)) return str;
1616
+ if (str.indexOf(" ") === -1) {
1617
+ if (str.length > len) {
1618
+ str = str.substring(0, len);
1619
+ str = hlp.rtrim(str);
1620
+ str += " " + chars;
1621
+ }
1622
+ } else if (str.length > len) {
1623
+ str = hlp.rtrim(str);
1624
+ while (str.length > len && str.lastIndexOf(" ") > -1 && str.substring(len - 1, len) != " ") {
1625
+ str = str.substring(0, str.lastIndexOf(" "));
1626
+ str = hlp.rtrim(str);
1627
+ }
1628
+ str = str.substring(0, len);
1629
+ str = hlp.rtrim(str);
1630
+ str += " " + chars;
1631
+ }
1632
+ return str;
1633
+ }
1634
+ static emojiRegex(global = true) {
1635
+ return new RegExp(hlp.emojiRegexPattern(), (global === true ? "g" : "") + "u");
1636
+ }
1637
+ static emojiRegexPattern() {
1638
+ return String.raw`\p{RI}\p{RI}|\p{Extended_Pictographic}(\p{EMod}|\uFE0F\u20E3?|[\u{E0020}-\u{E007E}]+\u{E007F})?(\u200D(\p{RI}\p{RI}|\p{Extended_Pictographic}(\p{EMod}|\uFE0F\u20E3?|[\u{E0020}-\u{E007E}]+\u{E007F})?))*`;
1639
+ }
1640
+ static emojiSplit(str) {
1641
+ if (!(typeof str === "string" || str instanceof String)) return str;
1642
+ return [...new Intl.Segmenter().segment(str)].map((x) => x.segment);
1643
+ }
1644
+ static serialize(mixedValue) {
1645
+ let val, key, okey;
1646
+ let ktype = "";
1647
+ let vals = "";
1648
+ let count = 0;
1649
+ const _utf8Size = function(str) {
1650
+ return ~-encodeURI(str).split(/%..|./).length;
1651
+ };
1652
+ const _getType = function(inp) {
1653
+ let match;
1654
+ let key;
1655
+ let cons;
1656
+ let types;
1657
+ let type = typeof inp;
1658
+ if (type === "object" && !inp) return "null";
1659
+ if (type === "object") {
1660
+ if (!inp.constructor) return "object";
1661
+ cons = inp.constructor.toString();
1662
+ match = cons.match(/(\w+)\(/);
1663
+ if (match) cons = match[1].toLowerCase();
1664
+ types = [
1665
+ "boolean",
1666
+ "number",
1667
+ "string",
1668
+ "array"
1669
+ ];
1670
+ for (key in types) if (cons === types[key]) {
1671
+ type = types[key];
1672
+ break;
1673
+ }
1674
+ }
1675
+ return type;
1676
+ };
1677
+ const type = _getType(mixedValue);
1678
+ switch (type) {
1679
+ case "function":
1680
+ val = "";
1681
+ break;
1682
+ case "boolean":
1683
+ val = "b:" + (mixedValue ? "1" : "0");
1684
+ break;
1685
+ case "number":
1686
+ val = (Math.round(mixedValue) === mixedValue ? "i" : "d") + ":" + mixedValue;
1687
+ break;
1688
+ case "string":
1689
+ val = "s:" + _utf8Size(mixedValue) + ":\"" + mixedValue + "\"";
1690
+ break;
1691
+ case "array":
1692
+ case "object":
1693
+ val = "a";
1694
+ for (key in mixedValue) if (mixedValue.hasOwnProperty(key)) {
1695
+ ktype = _getType(mixedValue[key]);
1696
+ if (ktype === "function") continue;
1697
+ okey = key.match(/^[0-9]+$/) ? parseInt(key, 10) : key;
1698
+ vals += this.serialize(okey) + this.serialize(mixedValue[key]);
1699
+ count++;
1700
+ }
1701
+ val += ":" + count + ":{" + vals + "}";
1702
+ break;
1703
+ default:
1704
+ val = "N";
1705
+ break;
1706
+ }
1707
+ if (type !== "object" && type !== "array") val += ";";
1708
+ return val;
1709
+ }
1710
+ static unserialize(str) {
1711
+ try {
1712
+ if (typeof str !== "string") return false;
1713
+ const store = [];
1714
+ const cache = (value) => {
1715
+ store.push(value[0]);
1716
+ return value;
1717
+ };
1718
+ cache.get = (index) => {
1719
+ if (index >= store.length) throw RangeError(`Can't resolve reference ${index + 1}`);
1720
+ return store[index];
1721
+ };
1722
+ const expectType = (s) => {
1723
+ const type = (/^(?:N(?=;)|[bidsSaOCrR](?=:)|[^:]+(?=:))/g.exec(s) || [])[0];
1724
+ if (!type) throw SyntaxError("Invalid input: " + s);
1725
+ switch (type) {
1726
+ case "N": return cache([null, 2]);
1727
+ case "b": return cache(expectBool(s));
1728
+ case "i": return cache(expectInt(s));
1729
+ case "d": return cache(expectFloat(s));
1730
+ case "s": return cache(expectString(s));
1731
+ case "S": return cache(expectEscapedString(s));
1732
+ case "a": return expectArray(s);
1733
+ case "O": return expectObject(s);
1734
+ case "C": throw Error("Not yet implemented");
1735
+ case "r":
1736
+ case "R": return expectReference(s);
1737
+ default: throw SyntaxError(`Invalid or unsupported data type: ${type}`);
1738
+ }
1739
+ };
1740
+ const expectBool = (s) => {
1741
+ const [match, boolMatch] = /^b:([01]);/.exec(s) || [];
1742
+ if (!boolMatch) throw SyntaxError("Invalid bool value, expected 0 or 1");
1743
+ return [boolMatch === "1", match.length];
1744
+ };
1745
+ const expectInt = (s) => {
1746
+ const [match, intMatch] = /^i:([+-]?\d+);/.exec(s) || [];
1747
+ if (!intMatch) throw SyntaxError("Expected an integer value");
1748
+ return [parseInt(intMatch, 10), match.length];
1749
+ };
1750
+ const expectFloat = (s) => {
1751
+ const [match, floatMatch] = /^d:(NAN|-?INF|(?:\d+\.\d*|\d*\.\d+|\d+)(?:[eE][+-]\d+)?);/.exec(s) || [];
1752
+ if (!floatMatch) throw SyntaxError("Expected a float value");
1753
+ return [floatMatch === "NAN" ? NaN : floatMatch === "-INF" ? Number.NEGATIVE_INFINITY : floatMatch === "INF" ? Number.POSITIVE_INFINITY : parseFloat(floatMatch), match.length];
1754
+ };
1755
+ const expectString = (s) => {
1756
+ const [match, byteLenMatch] = /^s:(\d+):"/g.exec(s) || [];
1757
+ if (!match) throw SyntaxError("Expected a string value");
1758
+ const len = parseInt(byteLenMatch, 10);
1759
+ s = s.substr(match.length);
1760
+ const strMatch = s.substr(0, len);
1761
+ s = s.substr(len);
1762
+ if (!s.startsWith("\";")) throw SyntaxError("Expected \";");
1763
+ return [strMatch, match.length + len + 2];
1764
+ };
1765
+ const expectEscapedString = (s) => {
1766
+ const [match, strLenMatch] = /^S:(\d+):"/g.exec(s) || [];
1767
+ if (!match) throw SyntaxError("Expected an escaped string value");
1768
+ const len = parseInt(strLenMatch, 10);
1769
+ s = s.substr(match.length);
1770
+ const strMatch = s.substr(0, len);
1771
+ s = s.substr(len);
1772
+ if (!s.startsWith("\";")) throw SyntaxError("Expected \";");
1773
+ return [strMatch, match.length + len + 2];
1774
+ };
1775
+ const expectReference = (s) => {
1776
+ const [match, refIndex] = /^[rR]:(\d+);/.exec(s) || [];
1777
+ if (!match) throw SyntaxError("Expected reference value");
1778
+ return [cache.get(parseInt(refIndex, 10) - 1), match.length];
1779
+ };
1780
+ const expectArray = (s) => {
1781
+ const [arrayLiteralBeginMatch, arrayLengthMatch] = /^a:(\d+):\{/.exec(s) || [];
1782
+ if (!arrayLengthMatch) throw SyntaxError("Expected array length annotation");
1783
+ s = s.substr(arrayLiteralBeginMatch.length);
1784
+ const items = {};
1785
+ cache([items]);
1786
+ for (let i = 0; i < parseInt(arrayLengthMatch, 10); i++) {
1787
+ const key = expectType(s);
1788
+ s = s.substr(key[1]);
1789
+ const value = expectType(s);
1790
+ s = s.substr(value[1]);
1791
+ items[key[0]] = value[0];
1792
+ }
1793
+ if (s.charAt(0) !== "}") throw SyntaxError("Expected }");
1794
+ return [items, arrayLiteralBeginMatch.length + 1];
1795
+ };
1796
+ const expectObject = (s) => {
1797
+ const [match, , className, propCountMatch] = /^O:(\d+):"([^\"]+)":(\d+):\{/.exec(s) || [];
1798
+ if (!match) throw SyntaxError("Invalid input");
1799
+ if (className !== "stdClass") throw SyntaxError(`Unsupported object type: ${className}`);
1800
+ let obj = {};
1801
+ cache([obj]);
1802
+ s = s.substr(match.length);
1803
+ for (let i = 0; i < parseInt(propCountMatch, 10); i++) {
1804
+ const prop = expectType(s);
1805
+ s = s.substr(prop[1]);
1806
+ const value = expectType(s);
1807
+ s = s.substr(value[1]);
1808
+ obj[prop[0]] = value[0];
1809
+ }
1810
+ if (s.charAt(0) !== "}") throw SyntaxError("Expected }");
1811
+ return [obj, match.length + 1];
1812
+ };
1813
+ return expectType(str)[0];
1814
+ } catch (err) {
1815
+ console.error(err);
1816
+ return false;
1817
+ }
1818
+ }
1819
+ static pushId() {
1820
+ let pushIdData = null;
1821
+ if (window !== void 0) {
1822
+ if (window.pushIdDataGlobal === void 0) window.pushIdDataGlobal = {};
1823
+ pushIdData = window.pushIdDataGlobal;
1824
+ }
1825
+ if (typeof global !== "undefined") {
1826
+ if (global.pushIdDataGlobal === void 0) global.pushIdDataGlobal = {};
1827
+ pushIdData = global.pushIdDataGlobal;
1828
+ }
1829
+ if (hlp.objectsAreEqual(pushIdData, {})) {
1830
+ pushIdData.lastPushTime = 0;
1831
+ pushIdData.lastRandChars = [];
1832
+ pushIdData.PUSH_CHARS = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
1833
+ }
1834
+ let now = (/* @__PURE__ */ new Date()).getTime(), duplicateTime = now === pushIdData.lastPushTime;
1835
+ pushIdData.lastPushTime = now;
1836
+ let timeStampChars = new Array(8);
1837
+ for (var i = 7; i >= 0; i--) {
1838
+ timeStampChars[i] = pushIdData.PUSH_CHARS.charAt(now % 64);
1839
+ now = Math.floor(now / 64);
1840
+ }
1841
+ if (now !== 0) throw new Error();
1842
+ let id = timeStampChars.join("");
1843
+ if (!duplicateTime) for (i = 0; i < 12; i++) pushIdData.lastRandChars[i] = Math.floor(Math.random() * 64);
1844
+ else {
1845
+ for (i = 11; i >= 0 && pushIdData.lastRandChars[i] === 63; i--) pushIdData.lastRandChars[i] = 0;
1846
+ pushIdData.lastRandChars[i]++;
1847
+ }
1848
+ for (i = 0; i < 12; i++) id += pushIdData.PUSH_CHARS.charAt(pushIdData.lastRandChars[i]);
1849
+ if (id.length != 20) throw new Error();
1850
+ return id;
1851
+ }
1852
+ static getProp(obj, desc) {
1853
+ let arr = desc.split(".");
1854
+ while (arr.length && (obj = obj[arr.shift()]));
1855
+ return obj;
1856
+ }
1857
+ static base64toblob(base64, contentType = "") {
1858
+ let sliceSize = 512, byteCharacters = atob(base64), byteArrays = [];
1859
+ for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
1860
+ let slice = byteCharacters.slice(offset, offset + sliceSize), byteNumbers = new Array(slice.length);
1861
+ for (let i = 0; i < slice.length; i++) byteNumbers[i] = slice.charCodeAt(i);
1862
+ let byteArray = new Uint8Array(byteNumbers);
1863
+ byteArrays.push(byteArray);
1864
+ }
1865
+ return new Blob(byteArrays, { type: contentType });
1866
+ }
1867
+ static blobtobase64(blob) {
1868
+ return new Promise((resolve) => {
1869
+ let reader = new FileReader();
1870
+ reader.onload = () => {
1871
+ var base64 = reader.result.split(",")[1];
1872
+ resolve(base64);
1873
+ };
1874
+ reader.readAsDataURL(blob);
1875
+ });
1876
+ }
1877
+ static stringtoblob(string, contentType = "") {
1878
+ return new Blob([string], { type: contentType });
1879
+ }
1880
+ static blobtostring(blob) {
1881
+ return new Promise((resolve) => {
1882
+ let reader = new FileReader();
1883
+ reader.onload = () => {
1884
+ resolve(reader.result);
1885
+ };
1886
+ reader.readAsText(blob);
1887
+ });
1888
+ }
1889
+ static filetobase64(file) {
1890
+ return new Promise((resolve, reject) => {
1891
+ const reader = new FileReader();
1892
+ reader.readAsDataURL(file);
1893
+ reader.onload = () => resolve(reader.result.split(",")[1]);
1894
+ reader.onerror = (error) => reject(error);
1895
+ });
1896
+ }
1897
+ static blobtofile(blob, filename = "file.txt") {
1898
+ let file = null;
1899
+ try {
1900
+ file = new File([blob], filename);
1901
+ } catch {
1902
+ file = new Blob([blob], filename);
1903
+ }
1904
+ return file;
1905
+ }
1906
+ static filetoblob(file) {
1907
+ return new Blob([file]);
1908
+ }
1909
+ static base64tofile(base64, contentType = "", filename = "file.txt") {
1910
+ return this.blobtofile(this.base64toblob(base64, contentType), filename);
1911
+ }
1912
+ static blobtourl(blob) {
1913
+ return URL.createObjectURL(blob, { type: "text/plain" });
1914
+ }
1915
+ static stringtourl(string) {
1916
+ return this.blobtourl(this.stringtoblob(string));
1917
+ }
1918
+ static base64tostring(base64) {
1919
+ return atob(base64);
1920
+ }
1921
+ static stringtobase64(string) {
1922
+ return btoa(string);
1923
+ }
1924
+ static base64tourl(base64) {
1925
+ return this.blobtourl(this.base64toblob(base64));
1926
+ }
1927
+ static filetourl(file) {
1928
+ return this.blobtourl(this.filetoblob(file));
1929
+ }
1930
+ static getImageOrientation(base64) {
1931
+ return new Promise((resolve, reject) => {
1932
+ base64 = base64.replace("data:image/jpeg;base64,", "");
1933
+ let file = this.base64tofile(base64), reader = new FileReader();
1934
+ reader.onload = (e) => {
1935
+ var view = new DataView(e.target.result);
1936
+ if (view.getUint16(0, false) != 65496) {
1937
+ resolve(-2);
1938
+ return;
1939
+ }
1940
+ var length = view.byteLength, offset = 2;
1941
+ while (offset < length) {
1942
+ if (view.getUint16(offset + 2, false) <= 8) {
1943
+ resolve(-1);
1944
+ return;
1945
+ }
1946
+ var marker = view.getUint16(offset, false);
1947
+ offset += 2;
1948
+ if (marker == 65505) {
1949
+ if (view.getUint32(offset += 2, false) != 1165519206) {
1950
+ resolve(-1);
1951
+ return;
1952
+ }
1953
+ var little = view.getUint16(offset += 6, false) == 18761;
1954
+ offset += view.getUint32(offset + 4, little);
1955
+ var tags = view.getUint16(offset, little);
1956
+ offset += 2;
1957
+ for (var i = 0; i < tags; i++) if (view.getUint16(offset + i * 12, little) == 274) {
1958
+ resolve(view.getUint16(offset + i * 12 + 8, little));
1959
+ return;
1960
+ }
1961
+ } else if ((marker & 65280) != 65280) break;
1962
+ else offset += view.getUint16(offset, false);
1963
+ }
1964
+ resolve(-1);
1965
+ };
1966
+ reader.readAsArrayBuffer(file);
1967
+ });
1968
+ }
1969
+ static resetImageOrientation(srcBase64, srcOrientation) {
1970
+ return new Promise((resolve, reject) => {
1971
+ var img = new Image();
1972
+ img.onload = () => {
1973
+ var width = img.width, height = img.height, canvas = document.createElement("canvas"), ctx = canvas.getContext("2d");
1974
+ if (4 < srcOrientation && srcOrientation < 9) {
1975
+ canvas.width = height;
1976
+ canvas.height = width;
1977
+ } else {
1978
+ canvas.width = width;
1979
+ canvas.height = height;
1980
+ }
1981
+ switch (srcOrientation) {
1982
+ case 2:
1983
+ ctx.transform(-1, 0, 0, 1, width, 0);
1984
+ break;
1985
+ case 3:
1986
+ ctx.transform(-1, 0, 0, -1, width, height);
1987
+ break;
1988
+ case 4:
1989
+ ctx.transform(1, 0, 0, -1, 0, height);
1990
+ break;
1991
+ case 5:
1992
+ ctx.transform(0, 1, 1, 0, 0, 0);
1993
+ break;
1994
+ case 6:
1995
+ ctx.transform(0, 1, -1, 0, height, 0);
1996
+ break;
1997
+ case 7:
1998
+ ctx.transform(0, -1, -1, 0, height, width);
1999
+ break;
2000
+ case 8:
2001
+ ctx.transform(0, -1, 1, 0, 0, width);
2002
+ break;
2003
+ default: break;
2004
+ }
2005
+ ctx.drawImage(img, 0, 0);
2006
+ let base64 = canvas.toDataURL();
2007
+ base64 = "data:image/jpeg;base64," + base64.split(",")[1];
2008
+ resolve(base64);
2009
+ };
2010
+ img.src = srcBase64;
2011
+ });
2012
+ }
2013
+ static fixImageOrientation(base64) {
2014
+ return new Promise((resolve, reject) => {
2015
+ if (base64.indexOf("data:") === -1) {
2016
+ resolve(base64);
2017
+ return;
2018
+ }
2019
+ if (base64.indexOf("data:image/jpeg;base64,") === 0) base64 = base64.replace("data:image/jpeg;base64,", "");
2020
+ this.getImageOrientation(base64).then((orientation) => {
2021
+ base64 = "data:image/jpeg;base64," + base64;
2022
+ if (orientation <= 1) {
2023
+ resolve(base64);
2024
+ return;
2025
+ } else this.resetImageOrientation(base64, orientation).then((base64_new) => {
2026
+ resolve(base64_new);
2027
+ });
2028
+ });
2029
+ });
2030
+ }
2031
+ static debounce(func, wait, immediate) {
2032
+ var timeout;
2033
+ return function() {
2034
+ var context = this, args = arguments;
2035
+ var later = function() {
2036
+ timeout = null;
2037
+ if (!immediate) func.apply(context, args);
2038
+ };
2039
+ var callNow = immediate && !timeout;
2040
+ clearTimeout(timeout);
2041
+ timeout = setTimeout(later, wait);
2042
+ if (callNow) func.apply(context, args);
2043
+ };
2044
+ }
2045
+ static throttle(func, wait, options) {
2046
+ var context, args, result;
2047
+ var timeout = null;
2048
+ var previous = 0;
2049
+ if (!options) options = {};
2050
+ var later = function() {
2051
+ previous = options.leading === false ? 0 : Date.now();
2052
+ timeout = null;
2053
+ result = func.apply(context, args);
2054
+ if (!timeout) context = args = null;
2055
+ };
2056
+ return function() {
2057
+ var now = Date.now();
2058
+ if (!previous && options.leading === false) previous = now;
2059
+ var remaining = wait - (now - previous);
2060
+ context = this;
2061
+ args = arguments;
2062
+ if (remaining <= 0 || remaining > wait) {
2063
+ if (timeout) {
2064
+ clearTimeout(timeout);
2065
+ timeout = null;
2066
+ }
2067
+ previous = now;
2068
+ result = func.apply(context, args);
2069
+ if (!timeout) context = args = null;
2070
+ } else if (!timeout && options.trailing !== false) timeout = setTimeout(later, remaining);
2071
+ return result;
2072
+ };
2073
+ }
2074
+ static shuffle(array) {
2075
+ let currentIndex = array.length, temporaryValue, randomIndex;
2076
+ while (0 !== currentIndex) {
2077
+ randomIndex = Math.floor(Math.random() * currentIndex);
2078
+ currentIndex -= 1;
2079
+ temporaryValue = array[currentIndex];
2080
+ array[currentIndex] = array[randomIndex];
2081
+ array[randomIndex] = temporaryValue;
2082
+ }
2083
+ return array;
2084
+ }
2085
+ static findRecursiveInObject(object, key = null, value = null, path = "", paths = []) {
2086
+ if (object !== null && typeof object === "object") {
2087
+ for (const [object__key, object__value] of Object.entries(object)) if (object__value !== null && typeof object__value === "object") this.findRecursiveInObject(object__value, key, value, (path === "" ? "" : path + ".") + object__key, paths);
2088
+ else if ((key === null || object__key === key) && (value === null || object__value === value)) {
2089
+ paths.push(path);
2090
+ break;
2091
+ }
2092
+ }
2093
+ return paths;
2094
+ }
2095
+ };
2096
+ if (typeof window !== "undefined") {
2097
+ window.hlp = {};
2098
+ Object.getOwnPropertyNames(hlp).forEach((value, key) => {
2099
+ if (value === "length" || value === "name" || value === "prototype" || value === "caller" || value === "arguments") return;
2100
+ window.hlp[value] = hlp[value];
2101
+ });
2102
+ }
2103
+ //#endregion
2104
+ export { hlp as default };
2105
+
2106
+ //# sourceMappingURL=hlp.esm.js.map