hlp 3.8.5 → 3.8.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 (3) hide show
  1. package/README.md +3 -3
  2. package/_js/_build/script.js +2103 -2869
  3. package/package.json +25 -37
@@ -1,2873 +1,2107 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
6
4
  });
7
- exports.default = void 0;
8
- var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
9
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
- var _templateObject;
11
- class hlp {
12
- static x(input) {
13
- if (typeof input === 'function') {
14
- try {
15
- input = input();
16
- return this.x(input);
17
- } catch (e) {
18
- return false;
19
- }
20
- }
21
- 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] === '') {
22
- return false;
23
- }
24
- return true;
25
- }
26
- static nx(input) {
27
- return !this.x(input);
28
- }
29
- static true(input) {
30
- if (typeof input === 'function') {
31
- try {
32
- input = input();
33
- return this.true(input);
34
- } catch (e) {
35
- return false;
36
- }
37
- }
38
- if (input === undefined) {
39
- return false;
40
- }
41
- if (input === null) {
42
- return false;
43
- }
44
- if (input === false) {
45
- return false;
46
- }
47
- if (Array.isArray(input) && input.length === 0) {
48
- return false;
49
- }
50
- if (Array.isArray(input) && hlp.first(input) === '') {
51
- return false;
52
- }
53
- if (typeof input === 'object' && Object.keys(input).length === 0 && input.constructor === Object) {
54
- return false;
55
- }
56
- if (input === 0) {
57
- return false;
58
- }
59
- if (input === '0') {
60
- return false;
61
- }
62
- if (input === '') {
63
- return false;
64
- }
65
- if (input === ' ') {
66
- return false;
67
- }
68
- if (input === 'null') {
69
- return false;
70
- }
71
- if (input === 'false') {
72
- return false;
73
- }
74
- return true;
75
- }
76
- static false(input) {
77
- if (typeof input === 'function') {
78
- try {
79
- input = input();
80
- return this.false(input);
81
- } catch (e) {
82
- return false;
83
- }
84
- }
85
- if (input === undefined) {
86
- return false;
87
- }
88
- if (input === null) {
89
- return false;
90
- }
91
- if (input === false) {
92
- return true;
93
- }
94
- if (Array.isArray(input) && input.length === 0) {
95
- return false;
96
- }
97
- if (Array.isArray(input) && hlp.first(input) === '') {
98
- return false;
99
- }
100
- if (typeof input === 'object' && Object.keys(input).length === 0 && input.constructor === Object) {
101
- return false;
102
- }
103
- if (input === 0) {
104
- return true;
105
- }
106
- if (input === '0') {
107
- return true;
108
- }
109
- if (input === '') {
110
- return false;
111
- }
112
- if (input === ' ') {
113
- return false;
114
- }
115
- if (input === 'null') {
116
- return false;
117
- }
118
- if (input === 'false') {
119
- return true;
120
- }
121
- return false;
122
- }
123
- static v() {
124
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
125
- args[_key] = arguments[_key];
126
- }
127
- if (this.nx(arguments)) {
128
- return '';
129
- }
130
- for (let i = 0; i < arguments.length; i++) {
131
- if (this.x(arguments[i])) {
132
- return arguments[i];
133
- }
134
- }
135
- return '';
136
- }
137
- static loop(input, fun) {
138
- if (this.nx(input)) {
139
- return null;
140
- }
141
- if (Array.isArray(input)) {
142
- input.forEach((input__value, input__key) => {
143
- fun(input__value, input__key);
144
- });
145
- } else if (typeof input === 'object') {
146
- Object.entries(input).forEach(_ref => {
147
- let _ref2 = (0, _slicedToArray2.default)(_ref, 2),
148
- input__key = _ref2[0],
149
- input__value = _ref2[1];
150
- fun(input__value, input__key);
151
- });
152
- }
153
- }
154
- static map(obj, fn) {
155
- let ctx = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
156
- return Object.keys(obj).reduce((a, b) => {
157
- a[b] = fn.call(ctx || null, b, obj[b]);
158
- return a;
159
- }, {});
160
- }
161
- static first(input) {
162
- if (Array.isArray(input)) {
163
- var ret = null;
164
- input.forEach((input__value, input__key) => {
165
- if (ret === null) {
166
- ret = input__value;
167
- }
168
- });
169
- return ret;
170
- }
171
- if (typeof input === 'object') {
172
- var ret = null;
173
- Object.entries(input).forEach(_ref3 => {
174
- let _ref4 = (0, _slicedToArray2.default)(_ref3, 2),
175
- input__key = _ref4[0],
176
- input__value = _ref4[1];
177
- if (ret === null) {
178
- ret = input__value;
179
- }
180
- });
181
- return ret;
182
- }
183
- return null;
184
- }
185
- static last(input) {
186
- if (Array.isArray(input)) {
187
- let ret = null;
188
- input.forEach((input__value, input__key) => {
189
- ret = input__value;
190
- });
191
- return ret;
192
- }
193
- if (typeof input === 'object') {
194
- let ret = null;
195
- Object.entries(input).forEach(_ref5 => {
196
- let _ref6 = (0, _slicedToArray2.default)(_ref5, 2),
197
- input__key = _ref6[0],
198
- input__value = _ref6[1];
199
- ret = input__value;
200
- });
201
- return ret;
202
- }
203
- return null;
204
- }
205
- static rand(input) {
206
- if (Array.isArray(input)) {
207
- return input[Math.floor(Math.random() * input.length)];
208
- }
209
- if (typeof input === 'object') {
210
- var inputArr = Object.values(input);
211
- return inputArr[Math.floor(Math.random() * inputArr.length)];
212
- }
213
- return null;
214
- }
215
- static random_string() {
216
- let length = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 8;
217
- let chars = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
218
- if (chars === null) {
219
- chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
220
- }
221
- let chars_length = chars.length,
222
- random_string = '';
223
- for (let i = 0; i < length; i++) {
224
- random_string += chars[~~(Math.random() * (chars_length - 1 - 0 + 1)) + 0];
225
- }
226
- return random_string;
227
- }
228
- static round() {
229
- let value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
230
- let decimals = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
231
- return Number(Math.round(value + 'e' + decimals) + 'e-' + decimals);
232
- }
233
- static isInteger(value) {
234
- return !isNaN(value) && parseInt(Number(value)) == value && !isNaN(parseInt(value, 10));
235
- }
236
- static random_int() {
237
- let min = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
238
- let max = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 99999;
239
- if (!this.isInteger(min) || !this.isInteger(max)) {
240
- return false;
241
- }
242
- if (min > max) {
243
- var _ref7 = [max, min];
244
- min = _ref7[0];
245
- max = _ref7[1];
246
- }
247
- return ~~(Math.random() * (max - min + 1)) + min;
248
- }
249
- static capitalize() {
250
- let string = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
251
- if (string === null) {
252
- return string;
253
- }
254
- if (string === '') {
255
- return string;
256
- }
257
- return string.charAt(0).toUpperCase() + string.slice(1);
258
- }
259
- static cookieExists(cookie_name) {
260
- if (document.cookie !== undefined && this.cookieGet(cookie_name) !== null) {
261
- return true;
262
- }
263
- return false;
264
- }
265
- static cookieGet(cookie_name) {
266
- var cookie_match = document.cookie.match(new RegExp(cookie_name + '=([^;]+)'));
267
- if (cookie_match) {
268
- return decodeURIComponent(cookie_match[1]);
269
- }
270
- return null;
271
- }
272
- static cookieSet(cookie_name, cookie_value, days) {
273
- let full_domain = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
274
- let samesite = '';
275
- if (window.location.protocol.indexOf('https') > -1) {
276
- samesite = '; SameSite=None; Secure';
277
- }
278
- document.cookie = cookie_name + '=' + encodeURIComponent(cookie_value) + '; ' + 'expires=' + new Date(new Date().getTime() + days * 24 * 60 * 60 * 1000).toUTCString() + '; path=/' + samesite + '; domain=' + (full_domain === true ? this.urlHostTopLevel() : '');
279
- }
280
- static cookieDelete(cookie_name) {
281
- let full_domain = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
282
- let samesite = '';
283
- if (window.location.protocol.indexOf('https') > -1) {
284
- samesite = '; SameSite=None; Secure';
285
- }
286
- document.cookie = cookie_name + '=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/' + samesite + '; domain=' + (full_domain === true ? this.urlHostTopLevel() : '');
287
- }
288
- static localStorageSet(key, value) {
289
- let ttl = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
290
- ttl = ttl * (24 * 60 * 60 * 1000);
291
- let now = new Date(),
292
- item = {
293
- value: value,
294
- expiry: now.getTime() + ttl
295
- };
296
- localStorage.setItem(key, JSON.stringify(item));
297
- }
298
- static localStorageGet(key) {
299
- let itemStr = localStorage.getItem(key);
300
- if (!itemStr) {
301
- return null;
302
- }
303
- let item = JSON.parse(itemStr),
304
- now = new Date();
305
- if (now.getTime() > item.expiry) {
306
- localStorage.removeItem(key);
307
- return null;
308
- }
309
- return item.value;
310
- }
311
- static localStorageDelete(key) {
312
- localStorage.removeItem(key);
313
- }
314
- static localStorageExists(key) {
315
- return this.localStorageGet(key) !== null;
316
- }
317
- static getParam(variable) {
318
- let url = window.location.search;
319
- if (this.nx(url)) {
320
- return null;
321
- }
322
- let query = url.substring(1),
323
- vars = query.split('&');
324
- for (var i = 0; i < vars.length; i++) {
325
- var pair = vars[i].split('=');
326
- if (pair[0] == variable && this.x(pair[1])) {
327
- return pair[1];
328
- }
329
- }
330
- return null;
331
- }
332
- static getDevice() {
333
- if (this.isPhone()) {
334
- return 'phone';
335
- }
336
- if (this.isTablet()) {
337
- return 'tablet';
338
- }
339
- return 'desktop';
340
- }
341
- static isPhone() {
342
- // based on detectmobilebrowsers.com
343
- let a = navigator.userAgent || navigator.vendor || window.opera;
344
- 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));
345
- }
346
- static isTablet() {
347
- // based on detectmobilebrowsers.com
348
- let a = navigator.userAgent || navigator.vendor || window.opera;
349
- 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));
350
- }
351
- static isDesktop() {
352
- return !this.isPhone() && !this.isTablet();
353
- }
354
- static isMobile() {
355
- // viewport width based OR phone based
356
- if (window.innerWidth < 750 || this.isPhone()) {
357
- return true;
358
- }
359
- return false;
360
- }
361
- static isTouch() {
362
- return 'ontouchstart' in window || navigator.maxTouchPoints || false;
363
- }
364
- static isPageSpeed() {
365
- const ua = navigator.userAgent || '';
366
- let score = 0;
367
- if (/Lighthouse|HeadlessChrome|Chrome-Lighthouse|Speed Insights|PTST|PageSpeed/i.test(ua)) {
368
- return true;
369
- }
370
- if (navigator.webdriver) {
371
- return true;
372
- }
373
- if (!navigator.languages || navigator.languages.length === 0) {
374
- score += 3;
375
- }
376
- if (/moto g power|Moto G4/i.test(ua)) {
377
- score += 2;
378
- }
379
- if (/Chrome\/\d{3}\.0\.0\.0/i.test(ua)) {
380
- score += 1;
381
- }
382
- if (typeof window !== 'undefined') {
383
- const w = window.innerWidth;
384
- const h = window.innerHeight;
385
- if (w === 1350 && h === 940 || w === 412 && (h === 823 || h === 915) || w === 360 && h === 640) {
386
- score += 2;
387
- }
388
- }
389
- if (navigator.plugins && navigator.plugins.length === 0) {
390
- score += 1;
391
- }
392
- if (!navigator.connection && !navigator.deviceMemory && !navigator.hardwareConcurrency) {
393
- score += 1;
394
- }
395
- if (typeof navigator.permissions === 'undefined') {
396
- score += 1;
397
- }
398
- if (/Chrome/i.test(ua) && typeof window.chrome === 'undefined') {
399
- score += 2;
400
- }
401
- return score >= 4;
402
- }
403
- static isMac() {
404
- return hlp.getOs() === 'mac';
405
- }
406
- static isLinux() {
407
- return hlp.getOs() === 'linux';
408
- }
409
- static isWindows() {
410
- return hlp.getOs() === 'windows';
411
- }
412
- static getOs() {
413
- let userAgent = window.navigator.userAgent,
414
- platform = window.navigator.platform,
415
- macosPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'],
416
- windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE'],
417
- iosPlatforms = ['iPhone', 'iPad', 'iPod'],
418
- os = 'unknown';
419
- if (macosPlatforms.indexOf(platform) !== -1) {
420
- os = 'mac';
421
- } else if (iosPlatforms.indexOf(platform) !== -1) {
422
- os = 'mac';
423
- } else if (windowsPlatforms.indexOf(platform) !== -1) {
424
- os = 'windows';
425
- } else if (/Android/.test(userAgent)) {
426
- os = 'linux';
427
- } else if (/Linux/.test(platform)) {
428
- os = 'linux';
429
- }
430
- return os;
431
- }
432
- static getBrowser() {
433
- let browser_name = '',
434
- isIE = /*@cc_on!@*/false || !!document.documentMode,
435
- isEdge = !isIE && !!window.StyleMedia;
436
- if (navigator.userAgent.indexOf('Opera') != -1 || navigator.userAgent.indexOf('OPR') != -1) {
437
- browser_name = 'opera';
438
- } else if (navigator.userAgent.indexOf('Chrome') != -1 && !isEdge) {
439
- browser_name = 'chrome';
440
- } else if (navigator.userAgent.indexOf('Safari') != -1 && !isEdge) {
441
- browser_name = 'safari';
442
- } else if (navigator.userAgent.indexOf('Firefox') != -1) {
443
- browser_name = 'firefox';
444
- } else if (navigator.userAgent.indexOf('MSIE') != -1 || !!document.documentMode == true) {
445
- //IF IE > 10
446
- browser_name = 'ie';
447
- } else if (isEdge) {
448
- browser_name = 'edge';
449
- } else {
450
- browser_name = 'unknown';
451
- }
452
- return browser_name;
453
- }
454
- static isObject() {
455
- let a = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
456
- return !!a && a.constructor === Object;
457
- }
458
- static isArray() {
459
- let a = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
460
- return !!a && a.constructor === Array;
461
- }
462
- static isString(string) {
463
- return typeof string === 'string' || string instanceof String;
464
- }
465
- static isDate(string) {
466
- if (this.nx(string)) {
467
- return false;
468
- }
469
- // if string is of object date
470
- if (Object.prototype.toString.call(string) === '[object Date]') {
471
- return true;
472
- }
473
- // if this is not a string
474
- if (!this.isString(string)) {
475
- return false;
476
- }
477
- // strong check
478
- if (string.split('-').length !== 3) {
479
- return false;
480
- }
481
- let day = parseInt(string.split('-')[2]),
482
- month = parseInt(string.split('-')[1]),
483
- year = parseInt(string.split('-')[0]),
484
- date = new Date();
485
- date.setFullYear(year, month - 1, day);
486
- if (date.getFullYear() == year && date.getMonth() + 1 == month && date.getDate() == day) {
487
- return true;
488
- }
489
- return false;
490
- }
491
- static password_generate() {
492
- let length = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 20;
493
- let chars = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ['a-z', 'A-Z', '0-9', '$!?'];
494
- let exclude = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'lI';
495
- if (chars === null || !chars.length || length < chars.length) {
496
- return null;
497
- }
498
- let charGroups = [];
499
- for (let group of chars) {
500
- let expanded = [];
501
- if (group === 'a-z') {
502
- expanded = Array.from({
503
- length: 26
504
- }, (_, i) => String.fromCharCode(97 + i));
505
- } else if (group === 'A-Z') {
506
- expanded = Array.from({
507
- length: 26
508
- }, (_, i) => String.fromCharCode(65 + i));
509
- } else if (group === '0-9') {
510
- expanded = Array.from({
511
- length: 10
512
- }, (_, i) => String.fromCharCode(48 + i));
513
- } else {
514
- expanded = group.split('');
515
- }
516
- if (exclude) {
517
- expanded = expanded.filter(c => !exclude.includes(c));
518
- }
519
- if (expanded.length === 0) {
520
- return null;
521
- }
522
- charGroups.push(expanded);
523
- }
524
- let passwordChars = charGroups.map(group => group[Math.floor(Math.random() * group.length)]);
525
- let allChars = charGroups.flat();
526
- while (passwordChars.length < length) {
527
- let i = Math.floor(Math.random() * allChars.length);
528
- passwordChars.push(allChars[i]);
529
- }
530
- for (let i = passwordChars.length - 1; i > 0; i--) {
531
- let j = Math.floor(Math.random() * (i + 1));
532
- var _ref8 = [passwordChars[j], passwordChars[i]];
533
- passwordChars[i] = _ref8[0];
534
- passwordChars[j] = _ref8[1];
535
- }
536
- return passwordChars.join('');
537
- }
538
- static formatNumber(number) {
539
- let decimals = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
540
- let dec_point = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '.';
541
- let thousands_sep = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : ',';
542
- number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
543
- var n = !isFinite(+number) ? 0 : +number,
544
- prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
545
- sep = typeof thousands_sep === 'undefined' ? ',' : thousands_sep,
546
- dec = typeof dec_point === 'undefined' ? '.' : dec_point,
547
- toFixedFix = function (n, prec) {
548
- var k = Math.pow(10, prec);
549
- return '' + Math.round(n * k) / k;
550
- };
551
- let sArr = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
552
- if (sArr[0].length > 3) {
553
- sArr[0] = sArr[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
554
- }
555
- if ((sArr[1] || '').length < prec) {
556
- sArr[1] = sArr[1] || '';
557
- sArr[1] += new Array(prec - sArr[1].length + 1).join('0');
558
- }
559
- return sArr.join(dec);
560
- }
561
- static formatDate(format) {
562
- let date = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
563
- if (date === false || date === true || date === null || date === '') {
564
- date = new Date();
565
- } else if (typeof date !== 'object') {
566
- date = new Date(date.replace(/-/g, '/').replace(/T|Z/g, ' '));
567
- }
568
- let string = '',
569
- mo = date.getMonth(),
570
- m1 = mo + 1,
571
- dow = date.getDay(),
572
- d = date.getDate(),
573
- y = date.getFullYear(),
574
- h = date.getHours(),
575
- mi = date.getMinutes(),
576
- s = date.getSeconds();
577
- for (let i = 0, len = format.length; i < len; i++) {
578
- switch (format[i]) {
579
- case 'j':
580
- string += d;
581
- break;
582
- case 'd':
583
- string += d < 10 ? '0' + d : d;
584
- break;
585
- case 'l':
586
- let days = Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
587
- string += days[dow];
588
- break;
589
- case 'w':
590
- string += dow;
591
- break;
592
- case 'D':
593
- days = Array('Sun', 'Mon', 'Tue', 'Wed', 'Thr', 'Fri', 'Sat');
594
- string += days[dow];
595
- break;
596
- case 'm':
597
- string += m1 < 10 ? '0' + m1 : m1;
598
- break;
599
- case 'n':
600
- string += m1;
601
- break;
602
- case 'F':
603
- let months = Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
604
- string += months[mo];
605
- break;
606
- case 'M':
607
- months = Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
608
- string += months[mo];
609
- break;
610
- case 'Y':
611
- string += y;
612
- break;
613
- case 'y':
614
- string += y.toString().slice(-2);
615
- break;
616
- case 'H':
617
- string += h < 10 ? '0' + h : h;
618
- break;
619
- case 'g':
620
- let hour = h === 0 ? 12 : h;
621
- string += hour > 12 ? hour - 12 : hour;
622
- break;
623
- case 'h':
624
- hour = h === 0 ? 12 : h;
625
- hour = hour > 12 ? hour - 12 : hour;
626
- string += hour < 10 ? '0' + hour : hour;
627
- break;
628
- case 'a':
629
- string += h < 12 ? 'am' : 'pm';
630
- break;
631
- case 'i':
632
- string += mi < 10 ? '0' + mi : mi;
633
- break;
634
- case 's':
635
- string += s < 10 ? '0' + s : s;
636
- break;
637
- case 'c':
638
- string += date.toISOString();
639
- break;
640
- default:
641
- string += format[i];
642
- }
643
- }
644
- return string;
645
- }
646
- static deepCopy(obj) {
647
- let hash = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new WeakMap();
648
- if (Object(obj) !== obj) return obj; // primitives
649
- if (hash.has(obj)) return hash.get(obj); // cyclic reference
650
- 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);
651
- hash.set(obj, result);
652
- if (obj instanceof Map) Array.from(obj, _ref9 => {
653
- let _ref0 = (0, _slicedToArray2.default)(_ref9, 2),
654
- key = _ref0[0],
655
- val = _ref0[1];
656
- return result.set(key, hlp.deepCopy(val, hash));
657
- });
658
- return Object.assign(result, ...Object.keys(obj).map(key => ({
659
- [key]: hlp.deepCopy(obj[key], hash)
660
- })));
661
- }
662
- static jsonStringToObject(string) {
663
- if (this.nx(string) || !this.isString(string)) {
664
- return null;
665
- }
666
- try {
667
- return JSON.parse(string);
668
- } catch (error) {
669
- return null;
670
- }
671
- }
672
- static isJsonString(string) {
673
- if (this.nx(string) || !this.isString(string)) {
674
- return false;
675
- }
676
- try {
677
- let json = JSON.parse(string);
678
- return true;
679
- } catch (error) {
680
- return false;
681
- }
682
- }
683
- static jsonObjectToString(object) {
684
- try {
685
- return JSON.stringify(object);
686
- } catch (error) {
687
- return null;
688
- }
689
- }
690
- static uuid() {
691
- function s4() {
692
- return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
693
- }
694
- return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
695
- }
696
- static guid() {
697
- return this.uuid();
698
- }
699
- static replaceAll(string, search, replace) {
700
- return string.split(search).join(replace);
701
- }
702
- static replaceLast(string, search, replace) {
703
- let n = string.lastIndexOf(search);
704
- string = string.slice(0, n) + string.slice(n).replace(search, replace);
705
- return string;
706
- }
707
- static replaceFirst(string, search, replace) {
708
- return string.replace(search, replace);
709
- }
710
- static findAllPositions(searchStr, str) {
711
- let searchStrLen = searchStr.length,
712
- startIndex = 0,
713
- index,
714
- indices = [];
715
- if (searchStrLen == 0) {
716
- return [];
717
- }
718
- while ((index = str.indexOf(searchStr, startIndex)) > -1) {
719
- indices.push(index);
720
- startIndex = index + searchStrLen;
721
- }
722
- return indices;
723
- }
724
- static findAllPositionsCaseInsensitive(searchStr, str) {
725
- let searchStrLen = searchStr.length,
726
- startIndex = 0,
727
- index,
728
- indices = [];
729
- if (searchStrLen == 0) {
730
- return [];
731
- }
732
- while ((index = this.indexOfCaseInsensitive(searchStr, str, startIndex)) > -1) {
733
- indices.push(index);
734
- startIndex = index + searchStrLen;
735
- }
736
- return indices;
737
- }
738
- static countAllOccurences(value, str) {
739
- return this.findAllPositions(value, str).length;
740
- }
741
- static countAllOccurencesCaseInsensitive(value, str) {
742
- return this.findAllPositionsCaseInsensitive(value, str).length;
743
- }
744
- static indexOfCaseInsensitive(searchStr, str) {
745
- let offset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
746
- return str.toLowerCase().indexOf(searchStr.toLowerCase(), offset);
747
- }
748
- static highlight(string, query) {
749
- let strip = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
750
- let strip_length = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 500;
751
- if (this.nx(string) || this.nx(query)) {
752
- return string;
753
- }
754
- if (strip === true) {
755
- let dots = '...';
756
- // get all query begin positions in spot
757
- let positions = this.findAllPositionsCaseInsensitive(query, string);
758
- // strip away parts
759
- let words = string.split(' ');
760
- let i = 0;
761
- words.forEach((words__value, words__key) => {
762
- let strip_now = true;
763
- positions.forEach(positions__value => {
764
- if (i >= positions__value - strip_length && i <= positions__value + query.length + strip_length - 1) {
765
- strip_now = false;
766
- }
767
- });
768
- if (strip_now === true) {
769
- words[words__key] = dots;
770
- }
771
- i += words__value.length + 1;
772
- });
773
- string = words.join(' ');
774
- while (string.indexOf(dots + ' ' + dots) > -1) {
775
- string = this.replaceAll(string, dots + ' ' + dots, dots);
776
- }
777
- string = string.trim();
778
- }
779
- // again: get all query begin positions in spot
780
- let positions = this.findAllPositionsCaseInsensitive(query, string);
781
- // wrap span element around them
782
- let wrap_begin = '<strong class="highlight">';
783
- let wrap_end = '</strong>';
784
- for (let x = 0; x < positions.length; x++) {
785
- string = string.substring(0, positions[x]) + wrap_begin + string.substring(positions[x], positions[x] + query.length) + wrap_end + string.substring(positions[x] + query.length);
786
- // shift other positions
787
- for (let y = x + 1; y < positions.length; y++) {
788
- positions[y] = positions[y] + wrap_begin.length + wrap_end.length;
789
- }
790
- }
791
- return string;
792
- }
793
- static get(url) {
794
- let args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
795
- return this.call('GET', url, args);
796
- }
797
- static post(url) {
798
- let args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
799
- return this.call('POST', url, args);
800
- }
801
- static call(method, url) {
802
- let args = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
803
- if (args === null) {
804
- args = {};
805
- }
806
- if (!('data' in args)) {
807
- args.data = {};
808
- }
809
- if (!('headers' in args)) {
810
- args.headers = null;
811
- }
812
- if (!('throttle' in args)) {
813
- args.throttle = 0;
814
- }
815
- if (!('allow_errors' in args)) {
816
- args.allow_errors = true;
817
- }
818
- return new Promise((resolve, reject) => {
819
- setTimeout(() => {
820
- if (url.indexOf('http') !== 0) {
821
- url = hlp.baseUrl() + '/' + url;
822
- }
823
- let xhr = new XMLHttpRequest();
824
- xhr.open(method, url, true);
825
- if (method === 'POST') {
826
- if ('data' in args && args.data !== null && typeof args.data === 'object' && !(args.data instanceof FormData)) {
827
- xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
828
- args.data = JSON.stringify(args.data);
829
- }
830
- xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
831
- }
832
- if (this.x(args.headers)) {
833
- Object.entries(args.headers).forEach(_ref1 => {
834
- let _ref10 = (0, _slicedToArray2.default)(_ref1, 2),
835
- headers__key = _ref10[0],
836
- headers__value = _ref10[1];
837
- xhr.setRequestHeader(headers__key, headers__value);
838
- });
839
- }
840
- xhr.onload = () => {
841
- if (xhr.readyState != 4 || args.allow_errors !== true && xhr.status != 200 && xhr.status != 304) {
842
- if (this.isJsonString(xhr.responseText)) {
843
- reject(this.jsonStringToObject(xhr.responseText));
844
- } else {
845
- reject(xhr.responseText);
846
- }
847
- }
848
- if (this.isJsonString(xhr.responseText)) {
849
- resolve(this.jsonStringToObject(xhr.responseText));
850
- } else {
851
- resolve(xhr.responseText);
852
- }
853
- };
854
- xhr.onerror = () => {
855
- reject([xhr.readyState, xhr.status, xhr.statusText]);
856
- };
857
- if (method === 'GET') {
858
- xhr.send(null);
859
- }
860
- if (method === 'POST') {
861
- xhr.send(args.data);
862
- }
863
- }, args.throttle);
864
- });
865
- }
866
- static onResizeHorizontal(fun) {
867
- let windowWidth = window.innerWidth,
868
- windowWidthNew,
869
- timeout;
870
- window.addEventListener('resize', () => {
871
- windowWidthNew = window.innerWidth;
872
- if (windowWidthNew != windowWidth) {
873
- windowWidth = windowWidthNew;
874
- if (timeout) {
875
- clearTimeout(timeout);
876
- }
877
- timeout = window.setTimeout(() => {
878
- fun();
879
- }, 50);
880
- }
881
- });
882
- fun();
883
- }
884
- static onResizeVertical(fun) {
885
- var windowHeight = window.innerHeight,
886
- windowHeightNew,
887
- timeout;
888
- window.addEventListener('resize', () => {
889
- windowHeightNew = window.innerHeight;
890
- if (windowHeightNew != windowHeight) {
891
- windowHeight = windowHeightNew;
892
- if (timeout) {
893
- clearTimeout(timeout);
894
- }
895
- timeout = window.setTimeout(() => {
896
- fun();
897
- }, 50);
898
- }
899
- });
900
- fun();
901
- }
902
- static removeEmpty(array) {
903
- if (this.nx(array) || !Array.isArray(array)) {
904
- return array;
905
- }
906
- array = array.filter(array__value => {
907
- return this.x(array__value);
908
- });
909
- return array;
910
- }
911
- static uniqueArray(array) {
912
- let seen = {},
913
- ret_arr = [];
914
- for (let i = 0; i < array.length; i++) {
915
- if (!(array[i] in seen)) {
916
- ret_arr.push(array[i]);
917
- seen[array[i]] = true;
918
- }
919
- }
920
- return ret_arr;
921
- }
922
- static powerset(array) {
923
- if (!Array.isArray(array)) {
924
- return array;
925
- }
926
- return array.reduce((subsets, value) => subsets.concat(subsets.map(set => [...set, value])), [[]]);
927
- }
928
- static charToInt(val) {
929
- val = val.toUpperCase();
930
- let base = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
931
- i,
932
- j,
933
- result = 0;
934
- for (i = 0, j = val.length - 1; i < val.length; i += 1, j -= 1) {
935
- result += Math.pow(base.length, j) * (base.indexOf(val[i]) + 1);
936
- }
937
- return result;
938
- }
939
- static intToChar(num) {
940
- for (var ret = '', a = 1, b = 26; (num -= a) >= 0; a = b, b *= 26) {
941
- ret = String.fromCharCode(parseInt(num % b / a) + 65) + ret;
942
- }
943
- return ret;
944
- }
945
- static slugify(text) {
946
- return text.toString().toLowerCase().trim().split('ä').join('ae').split('ö').join('oe').split('ü').join('ue').split('ß').join('ss').replace(/[^\w\s-]/g, '') // remove non-word [a-z0-9_], non-whitespace, non-hyphen characters
947
- .replace(/[\s_-]+/g, '-') // swap any length of whitespace, underscore, hyphen characters with a single -
948
- .replace(/^-+|-+$/g, ''); // remove leading, trailing -
949
- }
950
- static incChar(char) {
951
- let shift = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
952
- return this.intToChar(this.charToInt(char) + shift);
953
- }
954
- static decChar(char) {
955
- let shift = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
956
- return this.intToChar(this.charToInt(char) - shift);
957
- }
958
- static range(start, end) {
959
- let range = [],
960
- typeofStart = typeof start,
961
- typeofEnd = typeof end,
962
- step = 1;
963
- if (typeofStart == 'undefined' || typeofEnd == 'undefined' || typeofStart != typeofEnd) {
964
- return null;
965
- }
966
- if (end < start) {
967
- step = -step;
968
- }
969
- if (typeofStart == 'number') {
970
- while (step > 0 ? end >= start : end <= start) {
971
- range.push(start);
972
- start += step;
973
- }
974
- } else if (typeofStart == 'string') {
975
- if (start.length != 1 || end.length != 1) {
976
- return null;
977
- }
978
- start = start.charCodeAt(0);
979
- end = end.charCodeAt(0);
980
- while (step > 0 ? end >= start : end <= start) {
981
- range.push(String.fromCharCode(start));
982
- start += step;
983
- }
984
- } else {
985
- return null;
986
- }
987
- return range;
988
- }
989
- static dateToWeek() {
990
- let d = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
991
- if (d === null) {
992
- d = new Date();
993
- }
994
- d = new Date(Date.UTC(d.getFullYear(), d.getMonth(), d.getDate()));
995
- d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
996
- let yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1)),
997
- weekNo = Math.ceil(((d - yearStart) / 86400000 + 1) / 7);
998
- return weekNo;
999
- }
1000
- static weekToDate(week, year) {
1001
- if (year == null) {
1002
- year = new Date().getFullYear();
1003
- }
1004
- let date = new Date();
1005
- date.setFullYear(year);
1006
- date.setDate(1);
1007
- date.setMonth(0);
1008
- date.setHours(0);
1009
- date.setMinutes(0);
1010
- date.setSeconds(0);
1011
- date.setMilliseconds(0);
1012
- let FIRST_DAY_OF_WEEK = 1;
1013
- let WEEK_LENGTH = 7;
1014
- let day = date.getDay();
1015
- day = day === 0 ? 7 : day;
1016
- let dayOffset = -day + FIRST_DAY_OF_WEEK;
1017
- if (WEEK_LENGTH - day + 1 < 4) {
1018
- dayOffset += WEEK_LENGTH;
1019
- }
1020
- date = new Date(date.getTime() + dayOffset * 24 * 60 * 60 * 1000);
1021
- let weekTime = 1000 * 60 * 60 * 24 * 7 * (week - 1);
1022
- let targetTime = date.getTime() + weekTime;
1023
- date.setTime(targetTime);
1024
- date.setHours(0);
1025
- date.setMinutes(0);
1026
- date.setSeconds(0);
1027
- date.setMilliseconds(0);
1028
- return date;
1029
- }
1030
- static addDays(date, days) {
1031
- var result = new Date(date);
1032
- result.setDate(result.getDate() + days);
1033
- return result;
1034
- }
1035
- static diffInMonths(date1, date2) {
1036
- let d1 = new Date(date1),
1037
- d2 = new Date(date2),
1038
- yearDiff = d2.getFullYear() - d1.getFullYear(),
1039
- monthDiff = d2.getMonth() - d1.getMonth(),
1040
- dayDiff = d2.getDate() - d1.getDate(),
1041
- daysInMonth = new Date(d2.getFullYear(), d2.getMonth() + 1, 0).getDate(),
1042
- months = yearDiff * 12 + monthDiff + dayDiff / daysInMonth;
1043
- return months;
1044
- }
1045
- static objectsAreEqual(x, y) {
1046
- var _this = this;
1047
- if (x === null || x === undefined || y === null || y === undefined) {
1048
- return x === y;
1049
- }
1050
- if (x.constructor !== y.constructor) {
1051
- return false;
1052
- }
1053
- if (x instanceof Function) {
1054
- return x === y;
1055
- }
1056
- if (x instanceof RegExp) {
1057
- return x === y;
1058
- }
1059
- if (x === y || x.valueOf() === y.valueOf()) {
1060
- return true;
1061
- }
1062
- if (Array.isArray(x) && x.length !== y.length) {
1063
- return false;
1064
- }
1065
- if (x instanceof Date) {
1066
- return false;
1067
- }
1068
- if (!(x instanceof Object)) {
1069
- return false;
1070
- }
1071
- if (!(y instanceof Object)) {
1072
- return false;
1073
- }
1074
- var p = Object.keys(x);
1075
- return Object.keys(y).every(function (i) {
1076
- return p.indexOf(i) !== -1;
1077
- }) && p.every(function (i) {
1078
- return _this.objectsAreEqual(x[i], y[i]);
1079
- });
1080
- }
1081
- static containsObject(obj, list) {
1082
- var x;
1083
- for (x in list) {
1084
- if (list.hasOwnProperty(x) && this.objectsAreEqual(list[x], obj)) {
1085
- return true;
1086
- }
1087
- }
1088
- return false;
1089
- }
1090
- static fadeOut(el) {
1091
- let speed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1000;
1092
- if (speed <= 25) {
1093
- speed = 25;
1094
- }
1095
- return new Promise(resolve => {
1096
- el.style.opacity = 1;
1097
- (function fade() {
1098
- if ((el.style.opacity -= 25 / speed) < 0) {
1099
- el.style.display = 'none';
1100
- resolve();
1101
- } else {
1102
- requestAnimationFrame(fade);
1103
- }
1104
- })();
1105
- });
1106
- }
1107
- static fadeIn(el) {
1108
- let speed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1000;
1109
- if (speed <= 25) {
1110
- speed = 25;
1111
- }
1112
- return new Promise(resolve => {
1113
- el.style.opacity = 0;
1114
- el.style.display = 'block';
1115
- (function fade() {
1116
- var val = parseFloat(el.style.opacity);
1117
- if (!((val += 25 / speed) > 1)) {
1118
- el.style.opacity = val;
1119
- requestAnimationFrame(fade);
1120
- } else {
1121
- resolve();
1122
- }
1123
- })();
1124
- });
1125
- }
1126
- static scrollTop() {
1127
- let doc = document.documentElement;
1128
- return (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0);
1129
- }
1130
- static scrollLeft() {
1131
- let doc = document.documentElement;
1132
- return (window.pageXOffset || doc.scrollLeft) - (doc.clientLeft || 0);
1133
- }
1134
- static closestScrollable(node) {
1135
- let isElement = node instanceof HTMLElement,
1136
- overflowY = isElement && window.getComputedStyle(node).overflowY,
1137
- isScrollable = overflowY && !(overflowY.includes('hidden') || overflowY.includes('visible'));
1138
- if (!node) {
1139
- return null;
1140
- } else if (isScrollable && node.scrollHeight >= node.clientHeight) {
1141
- return node;
1142
- }
1143
- return this.closestScrollable(node.parentNode) || document.scrollingElement || document.body;
1144
- }
1145
- static offsetTop(el) {
1146
- return el.getBoundingClientRect().top + window.pageYOffset - document.documentElement.clientTop;
1147
- }
1148
- static offsetLeft(el) {
1149
- return el.getBoundingClientRect().left + window.pageXOffset - document.documentElement.clientLeft;
1150
- }
1151
- static offsetRight(el) {
1152
- return el.getBoundingClientRect().left + window.pageXOffset - document.documentElement.clientLeft + el.offsetWidth;
1153
- }
1154
- static offsetBottom(el) {
1155
- return el.getBoundingClientRect().top + window.pageYOffset - document.documentElement.clientTop + el.offsetHeight;
1156
- }
1157
- static offsetTopWithMargin(el) {
1158
- return this.offsetTop(el) - parseInt(getComputedStyle(el).marginTop);
1159
- }
1160
- static offsetLeftWithMargin(el) {
1161
- return this.offsetLeft(el) - parseInt(getComputedStyle(el).marginLeft);
1162
- }
1163
- static offsetRightWithMargin(el) {
1164
- return this.offsetRight(el) + parseInt(getComputedStyle(el).marginRight);
1165
- }
1166
- static offsetBottomWithMargin(el) {
1167
- return this.offsetBottom(el) + parseInt(getComputedStyle(el).marginBottom);
1168
- }
1169
- static documentHeight() {
1170
- return Math.max(document.body.offsetHeight, document.body.scrollHeight, document.documentElement.clientHeight, document.documentElement.offsetHeight, document.documentElement.scrollHeight);
1171
- }
1172
- static documentWidth() {
1173
- return document.documentElement.clientWidth || document.body.clientWidth;
1174
- }
1175
- static windowWidth() {
1176
- return window.innerWidth;
1177
- }
1178
- static windowHeight() {
1179
- return window.innerHeight;
1180
- }
1181
- static windowWidthWithoutScrollbar() {
1182
- return document.documentElement.clientWidth || document.body.clientWidth;
1183
- }
1184
- static windowHeightWithoutScrollbar() {
1185
- return document.documentElement.clientHeight || document.body.clientHeight;
1186
- }
1187
- static outerWidthWithMargin(el) {
1188
- return el.offsetWidth + parseInt(getComputedStyle(el).marginLeft) + parseInt(getComputedStyle(el).marginRight);
1189
- }
1190
- static outerHeightWithMargin(el) {
1191
- return el.offsetHeight + parseInt(getComputedStyle(el).marginTop) + parseInt(getComputedStyle(el).marginBottom);
1192
- }
1193
- static async cursorPosition() {
1194
- // https://stackoverflow.com/a/43326327/2068362
1195
- document.head.insertAdjacentHTML('afterbegin', "\n <style type=\"text/css\">\n .find-pointer-quad {\n --hit: 0;\n position: fixed;\n\t z-index:2147483647;\n transform: translateZ(0);\n &:hover { --hit: 1; }\n }\n </style>\n ");
1196
- window.cursorPositionDelay = 50;
1197
- window.cursorPositionQuads = [];
1198
- let dim = 10;
1199
- let createQuad = (_, pos) => {
1200
- let a = document.createElement('a');
1201
- a.classList.add('find-pointer-quad');
1202
- let style = a.style;
1203
- style.top = pos < 2 ? '0' : "".concat(dim, "%");
1204
- style.left = pos % 2 === 0 ? '0' : "".concat(dim, "%");
1205
- style.width = style.height = "".concat(dim, "%");
1206
- document.body.appendChild(a);
1207
- return a;
1208
- };
1209
- window.cursorPositionQuads = [1, 2, 3, 4].map(createQuad);
1210
- return this.cursorPositionBisect(dim);
1211
- }
1212
- static cursorPositionBisect(dim) {
1213
- let hit;
1214
- window.cursorPositionQuads.some(a => {
1215
- let style = getComputedStyle(a);
1216
- let result = style.getPropertyValue("--hit");
1217
- if (result === "1") return hit = {
1218
- style,
1219
- a
1220
- };
1221
- });
1222
- if (!hit) {
1223
- let _cursorPositionQuads = (0, _slicedToArray2.default)(window.cursorPositionQuads, 1),
1224
- q1 = _cursorPositionQuads[0];
1225
- let reset = Math.abs(dim) > 10000;
1226
- let top = parseFloat(q1.style.top) - dim / 2;
1227
- let left = parseFloat(q1.style.left) - dim / 2;
1228
- window.cursorPositionQuads.forEach((_ref11, pos) => {
1229
- let style = _ref11.style;
1230
- if (reset) {
1231
- style.top = pos < 2 ? '0' : "".concat(dim, "%");
1232
- style.left = pos % 2 === 0 ? '0' : "".concat(dim, "%");
1233
- style.width = style.height = "".concat(dim, "%");
1234
- } else {
1235
- style.top = pos < 2 ? "".concat(top, "%") : "".concat(top + dim, "%");
1236
- style.left = pos % 2 === 0 ? "".concat(left, "%") : "".concat(left + dim, "%");
1237
- style.width = "".concat(dim, "%");
1238
- style.height = "".concat(dim, "%");
1239
- }
1240
- });
1241
- return new Promise(resolve => {
1242
- setTimeout(() => resolve(this.cursorPositionBisect(!reset ? 2 * dim : dim)), window.cursorPositionDelay);
1243
- });
1244
- }
1245
- let _hit = hit,
1246
- style = _hit.style,
1247
- a = _hit.a;
1248
- let _a$getBoundingClientR = a.getBoundingClientRect(),
1249
- top = _a$getBoundingClientR.top,
1250
- left = _a$getBoundingClientR.left,
1251
- width = _a$getBoundingClientR.width,
1252
- height = _a$getBoundingClientR.height;
1253
- if (width < 3) {
1254
- window.cursorPositionQuads.forEach(a => a.remove());
1255
- return {
1256
- x: Math.round(left + width / 2 + window.scrollX),
1257
- y: Math.round(top + height / 2 + window.scrollY)
1258
- };
1259
- }
1260
- let ox = a.style.left;
1261
- let oy = a.style.top;
1262
- let nextStep = dim / 2;
1263
- window.cursorPositionQuads.forEach((_ref12, pos) => {
1264
- let style = _ref12.style;
1265
- style.top = pos < 2 ? oy : "".concat(nextStep + parseFloat(oy), "%");
1266
- style.left = pos % 2 === 0 ? ox : "".concat(nextStep + parseFloat(ox), "%");
1267
- style.width = "".concat(nextStep, "%");
1268
- style.height = "".concat(nextStep, "%");
1269
- });
1270
- return new Promise(resolve => {
1271
- setTimeout(() => resolve(this.cursorPositionBisect(nextStep)), window.cursorPositionDelay);
1272
- });
1273
- }
1274
- static scrollTo(to) {
1275
- let duration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1000;
1276
- let element = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
1277
- let offset = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
1278
- let only_up = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
1279
- return new Promise(resolve => {
1280
- if (element === null) {
1281
- element = document.scrollingElement || document.documentElement;
1282
- }
1283
- if (!hlp.isNumeric(to)) {
1284
- if (element === (document.scrollingElement || document.documentElement)) {
1285
- to = this.offsetTopWithMargin(to);
1286
- } else {
1287
- to = to.getBoundingClientRect().top - parseInt(getComputedStyle(to).marginTop) - (element.getBoundingClientRect().top - element.scrollTop - parseInt(getComputedStyle(element).marginTop));
1288
- }
1289
- }
1290
- let offset_calc = 0;
1291
- let offsetArr = offset;
1292
- if (!Array.isArray(offsetArr)) {
1293
- offsetArr = [offsetArr];
1294
- }
1295
- offsetArr.forEach(offset__value => {
1296
- if (hlp.isNumeric(offset__value)) {
1297
- offset_calc += offset__value;
1298
- } else {
1299
- if (offset__value !== null) {
1300
- if (window.getComputedStyle(offset__value).position === 'fixed') {
1301
- offset_calc += -1 * offset__value.offsetHeight;
1302
- }
1303
- }
1304
- }
1305
- });
1306
- to += offset_calc;
1307
- const start = element.scrollTop,
1308
- change = to - start,
1309
- startDate = +new Date(),
1310
- // t = current time
1311
- // b = start value
1312
- // c = change in value
1313
- // d = duration
1314
- easeInOutQuad = function (t, b, c, d) {
1315
- t /= d / 2;
1316
- if (t < 1) return c / 2 * t * t + b;
1317
- t--;
1318
- return -c / 2 * (t * (t - 2) - 1) + b;
1319
- },
1320
- easeInOutCirc = function (t, b, c, d) {
1321
- t /= d / 2;
1322
- if (t < 1) return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b;
1323
- t -= 2;
1324
- return c / 2 * (Math.sqrt(1 - t * t) + 1) + b;
1325
- },
1326
- animateScroll = function () {
1327
- const currentDate = +new Date();
1328
- const currentTime = currentDate - startDate;
1329
- element.scrollTop = parseInt(easeInOutCirc(currentTime, start, change, duration));
1330
- if (currentTime < duration) {
1331
- requestAnimationFrame(animateScroll);
1332
- } else {
1333
- element.scrollTop = to;
1334
- resolve();
1335
- }
1336
- };
1337
- if (only_up === true && change > 0) {
1338
- resolve();
1339
- return;
1340
- }
1341
- animateScroll();
1342
- });
1343
- }
1344
- static loadJs(urls) {
1345
- if (!hlp.isArray(urls)) {
1346
- urls = [urls];
1347
- }
1348
- let promises = [];
1349
- hlp.loop(urls, (urls__value, urls__key) => {
1350
- promises.push(new Promise((resolve, reject) => {
1351
- let script = document.createElement('script');
1352
- script.src = urls__value;
1353
- script.onload = () => {
1354
- resolve();
1355
- };
1356
- document.head.appendChild(script);
1357
- }));
1358
- });
1359
- return Promise.all(promises);
1360
- }
1361
- static async loadJsSequentially(urls) {
1362
- if (!hlp.isArray(urls)) {
1363
- urls = [urls];
1364
- }
1365
- for (let urls__value of urls) {
1366
- await hlp.loadJs(urls__value);
1367
- }
1368
- return;
1369
- }
1370
- static triggerAfterAllImagesLoaded(selectorContainer, selectorImage, fn) {
1371
- window.addEventListener('load', e => {
1372
- if (document.querySelector(selectorContainer + ' ' + selectorImage) !== null) {
1373
- document.querySelectorAll(selectorContainer + ' ' + selectorImage).forEach(el => {
1374
- this.triggerAfterAllImagesLoadedBindLoadEvent(el, selectorContainer, selectorImage, fn);
1375
- });
1376
- }
1377
- });
1378
- document.addEventListener('DOMContentLoaded', () => {
1379
- if (document.querySelector(selectorContainer) !== null) {
1380
- new MutationObserver(mutations => {
1381
- mutations.forEach(mutation => {
1382
- if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
1383
- mutation.addedNodes.forEach(el => {
1384
- this.triggerAfterAllImagesLoadedHandleEl(el, selectorContainer, selectorImage, fn);
1385
- });
1386
- } else if (mutation.type === 'attributes' && mutation.attributeName === 'src' && mutation.target.classList.contains(selectorImage.replace('.', '')) && mutation.oldValue !== mutation.target.getAttribute('src')) {
1387
- this.triggerAfterAllImagesLoadedHandleEl(mutation.target, selectorContainer, selectorImage, fn);
1388
- }
1389
- });
1390
- }).observe(document.querySelector(selectorContainer), {
1391
- attributes: true,
1392
- childList: true,
1393
- characterData: false,
1394
- subtree: true,
1395
- attributeOldValue: true,
1396
- characterDataOldValue: false
1397
- });
1398
- }
1399
- });
1400
- }
1401
- static triggerAfterAllImagesLoadedHandleEl(el, selectorContainer, selectorImage, fn) {
1402
- if (el.nodeType === Node.ELEMENT_NODE) {
1403
- el.classList.remove('loaded-img');
1404
- el.closest(selectorContainer).classList.remove('loaded-all');
1405
- // only bind if not yet binded
1406
- if (!el.classList.contains('binded-trigger')) {
1407
- el.classList.add('binded-trigger');
1408
- el.addEventListener('load', () => {
1409
- this.triggerAfterAllImagesLoadedBindLoadEvent(el, selectorContainer, selectorImage, fn);
1410
- });
1411
- }
1412
- }
1413
- }
1414
- static triggerAfterAllImagesLoadedBindLoadEvent(el, selectorContainer, selectorImage, fn) {
1415
- el.classList.add('loaded-img');
1416
- if (el.closest(selectorContainer).querySelectorAll('.loaded-img').length === el.closest(selectorContainer).querySelectorAll(selectorImage).length) {
1417
- el.closest(selectorContainer).classList.add('loaded-all');
1418
- fn();
1419
- }
1420
- }
1421
- static isVisible(el) {
1422
- return !!(el.offsetWidth || el.offsetHeight || el.getClientRects().length);
1423
- }
1424
- static isVisibleInViewport(el) {
1425
- if (!this.isVisible(el)) {
1426
- return false;
1427
- }
1428
- let rect = el.getBoundingClientRect();
1429
- return !(rect.bottom < 0 || rect.right < 0 || rect.left > window.innerWidth || rect.top > window.innerHeight);
1430
- }
1431
- static textareaAutoHeight() {
1432
- let selector = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'textarea';
1433
- this.textareaSetHeights(selector);
1434
- this.onResizeHorizontal(() => {
1435
- this.textareaSetHeights(selector);
1436
- });
1437
- [].forEach.call(document.querySelectorAll(selector), el => {
1438
- el.addEventListener('keyup', e => {
1439
- this.textareaSetHeight(e.target);
1440
- });
1441
- });
1442
- }
1443
- static textareaSetHeights() {
1444
- let selector = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'textarea';
1445
- [].forEach.call(document.querySelectorAll(selector), el => {
1446
- if (this.isVisible(el)) {
1447
- this.textareaSetHeight(el);
1448
- }
1449
- });
1450
- }
1451
- static textareaSetHeight(el) {
1452
- el.style.height = '5px';
1453
- el.style.height = el.scrollHeight + 'px';
1454
- }
1455
- static real100vh() {
1456
- let selector = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
1457
- let percent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 100;
1458
- if (selector === null) {
1459
- // apply trick from https://css-tricks.com/the-trick-to-viewport-units-on-mobile/
1460
- let fn = () => {
1461
- let vh = window.innerHeight * 0.01;
1462
- document.documentElement.style.setProperty('--vh', "".concat(vh, "px"));
1463
- };
1464
- fn();
1465
- window.addEventListener('resize', () => {
1466
- fn();
1467
- });
1468
- } else {
1469
- let fn = () => {
1470
- console.log(selector);
1471
- if (document.querySelector(selector) !== null) {
1472
- document.querySelectorAll(selector).forEach(selector__value => {
1473
- selector__value.style.height = window.innerHeight * (percent / 100) + 'px';
1474
- });
1475
- }
1476
- };
1477
- fn();
1478
- window.addEventListener('resize', () => {
1479
- fn();
1480
- });
1481
- }
1482
- }
1483
- static iOsRemoveHover() {
1484
- if (hlp.getBrowser() === 'safari' && hlp.getDevice() !== 'desktop') {
1485
- hlp.on('touchend', 'a', (e, el) => {
1486
- el.click();
1487
- });
1488
- }
1489
- }
1490
- static isNumeric(n) {
1491
- return !isNaN(parseFloat(n)) && isFinite(n);
1492
- }
1493
- static animate(el, from, to, easing, duration) {
1494
- return new Promise(resolve => {
1495
- // on durations smaller than 50, the end event does not trigger!
1496
- if (duration <= 50) {
1497
- duration = 50;
1498
- }
1499
- let properties = [];
1500
- from.split(';').forEach(from__value => {
1501
- properties.push(from__value.split(':')[0].trim());
1502
- });
1503
- let transitionArr = [];
1504
- properties.forEach(properties__value => {
1505
- transitionArr.push(properties__value + ' ' + Math.round(duration / 1000 * 10) / 10 + 's ' + easing);
1506
- });
1507
- let transition = 'transition: ' + transitionArr.join(', ') + ' !important;';
1508
- let els = null;
1509
- if (NodeList.prototype.isPrototypeOf(el)) {
1510
- els = Array.from(el);
1511
- } else if (el === null) {
1512
- console.log('cannot animate element from ' + from + ' to ' + to + ' because it does not exist');
1513
- resolve();
1514
- } else {
1515
- els = [el];
1516
- }
1517
- let toFinish = els.length;
1518
- els.forEach((els__value, els__key) => {
1519
- // add random class
1520
- let random_class = hlp.random_string(10, 'abcdefghijklmnopqrstuvwxyz');
1521
- els__value.classList.add(random_class);
1522
- window.requestAnimationFrame(() => {
1523
- // set from style inline (don't fully remove previous style)
1524
- let new_style_arr = [];
1525
- let new_style = '';
1526
- let prev_style = els__value.getAttribute('style');
1527
- if (prev_style !== null) {
1528
- prev_style.split(';').forEach(prev_style__value => {
1529
- if (prev_style__value != '' && !properties.includes(prev_style__value.split(':')[0].trim())) {
1530
- new_style_arr.push(prev_style__value);
1531
- }
1532
- });
1533
- }
1534
- if (new_style_arr.length > 0) {
1535
- new_style = new_style_arr.join(';') + ';' + from + ';';
1536
- } else {
1537
- new_style = from + ';';
1538
- }
1539
- els__value.setAttribute('style', new_style);
1540
- window.requestAnimationFrame(() => {
1541
- // add transition property
1542
- let style = document.createElement('style');
1543
- style.innerHTML = '.' + random_class + ' { ' + transition + ' }';
1544
- document.head.appendChild(style);
1545
- window.requestAnimationFrame(() => {
1546
- // set last style inline
1547
- els__value.setAttribute('style', els__value.getAttribute('style').replace(from + ';', '') + to + ';');
1548
- if (this.isVisible(els__value)) {
1549
- let fired = false;
1550
- hlp.addEventListenerOnce(els__value, 'transitionend', event => {
1551
- fired = true;
1552
-
1553
- // transitionend fires also, when animating child elements
1554
- // the following line ensures, that those events do not bubble up
1555
- // in that case, we return false and ensure, the event listener is still alive
1556
- if (event.target !== event.currentTarget) {
1557
- return false;
1558
- }
1559
-
1560
- // remove previous styles property
1561
- if (document.head.contains(style)) {
1562
- document.head.removeChild(style);
1563
- }
1564
-
1565
- // remove random class
1566
- els__value.classList.remove(random_class);
1567
-
1568
- // resolve promise when last is finished
1569
- toFinish--;
1570
- if (toFinish <= 0) {
1571
- window.requestAnimationFrame(() => {
1572
- resolve();
1573
- });
1574
- }
1575
- });
1576
-
1577
- // safeguard
1578
- // in some edge cases, transitionend does not fire
1579
- setTimeout(() => {
1580
- if (fired === false) {
1581
- if (document.head.contains(style)) {
1582
- document.head.removeChild(style);
5
+ //#region _js/script.ts
6
+ var hlp = class hlp {
7
+ static x(input) {
8
+ if (typeof input === "function") try {
9
+ input = input();
10
+ return this.x(input);
11
+ } catch (e) {
12
+ return false;
13
+ }
14
+ 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;
15
+ return true;
16
+ }
17
+ static nx(input) {
18
+ return !this.x(input);
19
+ }
20
+ static true(input) {
21
+ if (typeof input === "function") try {
22
+ input = input();
23
+ return this.true(input);
24
+ } catch (e) {
25
+ return false;
26
+ }
27
+ if (input === void 0) return false;
28
+ if (input === null) return false;
29
+ if (input === false) return false;
30
+ if (Array.isArray(input) && input.length === 0) return false;
31
+ if (Array.isArray(input) && hlp.first(input) === "") return false;
32
+ if (typeof input === "object" && Object.keys(input).length === 0 && input.constructor === Object) return false;
33
+ if (input === 0) return false;
34
+ if (input === "0") return false;
35
+ if (input === "") return false;
36
+ if (input === " ") return false;
37
+ if (input === "null") return false;
38
+ if (input === "false") return false;
39
+ return true;
40
+ }
41
+ static false(input) {
42
+ if (typeof input === "function") try {
43
+ input = input();
44
+ return this.false(input);
45
+ } catch (e) {
46
+ return false;
47
+ }
48
+ if (input === void 0) return false;
49
+ if (input === null) return false;
50
+ if (input === false) return true;
51
+ if (Array.isArray(input) && input.length === 0) return false;
52
+ if (Array.isArray(input) && hlp.first(input) === "") return false;
53
+ if (typeof input === "object" && Object.keys(input).length === 0 && input.constructor === Object) return false;
54
+ if (input === 0) return true;
55
+ if (input === "0") return true;
56
+ if (input === "") return false;
57
+ if (input === " ") return false;
58
+ if (input === "null") return false;
59
+ if (input === "false") return true;
60
+ return false;
61
+ }
62
+ static v(...args) {
63
+ if (this.nx(arguments)) return "";
64
+ for (let i = 0; i < arguments.length; i++) if (this.x(arguments[i])) return arguments[i];
65
+ return "";
66
+ }
67
+ static loop(input, fun) {
68
+ if (this.nx(input)) return null;
69
+ if (Array.isArray(input)) input.forEach((input__value, input__key) => {
70
+ fun(input__value, input__key);
71
+ });
72
+ else if (typeof input === "object") Object.entries(input).forEach(([input__key, input__value]) => {
73
+ fun(input__value, input__key);
74
+ });
75
+ }
76
+ static map(obj, fn, ctx = null) {
77
+ return Object.keys(obj).reduce((a, b) => {
78
+ a[b] = fn.call(ctx || null, b, obj[b]);
79
+ return a;
80
+ }, {});
81
+ }
82
+ static first(input) {
83
+ if (Array.isArray(input)) {
84
+ var ret = null;
85
+ input.forEach((input__value, input__key) => {
86
+ if (ret === null) ret = input__value;
87
+ });
88
+ return ret;
89
+ }
90
+ if (typeof input === "object") {
91
+ var ret = null;
92
+ Object.entries(input).forEach(([input__key, input__value]) => {
93
+ if (ret === null) ret = input__value;
94
+ });
95
+ return ret;
96
+ }
97
+ return null;
98
+ }
99
+ static last(input) {
100
+ if (Array.isArray(input)) {
101
+ let ret = null;
102
+ input.forEach((input__value, input__key) => {
103
+ ret = input__value;
104
+ });
105
+ return ret;
106
+ }
107
+ if (typeof input === "object") {
108
+ let ret = null;
109
+ Object.entries(input).forEach(([input__key, input__value]) => {
110
+ ret = input__value;
111
+ });
112
+ return ret;
113
+ }
114
+ return null;
115
+ }
116
+ static rand(input) {
117
+ if (Array.isArray(input)) return input[Math.floor(Math.random() * input.length)];
118
+ if (typeof input === "object") {
119
+ var inputArr = Object.values(input);
120
+ return inputArr[Math.floor(Math.random() * inputArr.length)];
121
+ }
122
+ return null;
123
+ }
124
+ static random_string(length = 8, chars = null) {
125
+ if (chars === null) chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
126
+ let chars_length = chars.length, random_string = "";
127
+ for (let i = 0; i < length; i++) random_string += chars[~~(Math.random() * (chars_length - 1 - 0 + 1)) + 0];
128
+ return random_string;
129
+ }
130
+ static round(value = 0, decimals = 0) {
131
+ return Number(Math.round(value + "e" + decimals) + "e-" + decimals);
132
+ }
133
+ static isInteger(value) {
134
+ return !isNaN(value) && parseInt(Number(value)) == value && !isNaN(parseInt(value, 10));
135
+ }
136
+ static random_int(min = 0, max = 99999) {
137
+ if (!this.isInteger(min) || !this.isInteger(max)) return false;
138
+ if (min > max) [min, max] = [max, min];
139
+ return ~~(Math.random() * (max - min + 1)) + min;
140
+ }
141
+ static capitalize(string = null) {
142
+ if (string === null) return string;
143
+ if (string === "") return string;
144
+ return string.charAt(0).toUpperCase() + string.slice(1);
145
+ }
146
+ static cookieExists(cookie_name) {
147
+ if (document.cookie !== void 0 && this.cookieGet(cookie_name) !== null) return true;
148
+ return false;
149
+ }
150
+ static cookieGet(cookie_name) {
151
+ var cookie_match = document.cookie.match(new RegExp(cookie_name + "=([^;]+)"));
152
+ if (cookie_match) return decodeURIComponent(cookie_match[1]);
153
+ return null;
154
+ }
155
+ static cookieSet(cookie_name, cookie_value, days, full_domain = true) {
156
+ let samesite = "";
157
+ if (window.location.protocol.indexOf("https") > -1) samesite = "; SameSite=None; Secure";
158
+ 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() : "");
159
+ }
160
+ static cookieDelete(cookie_name, full_domain = true) {
161
+ let samesite = "";
162
+ if (window.location.protocol.indexOf("https") > -1) samesite = "; SameSite=None; Secure";
163
+ document.cookie = cookie_name + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/" + samesite + "; domain=" + (full_domain === true ? this.urlHostTopLevel() : "");
164
+ }
165
+ static localStorageSet(key, value, ttl = 0) {
166
+ ttl = ttl * (1440 * 60 * 1e3);
167
+ let item = {
168
+ value,
169
+ expiry: (/* @__PURE__ */ new Date()).getTime() + ttl
170
+ };
171
+ localStorage.setItem(key, JSON.stringify(item));
172
+ }
173
+ static localStorageGet(key) {
174
+ let itemStr = localStorage.getItem(key);
175
+ if (!itemStr) return null;
176
+ let item = JSON.parse(itemStr);
177
+ if ((/* @__PURE__ */ new Date()).getTime() > item.expiry) {
178
+ localStorage.removeItem(key);
179
+ return null;
180
+ }
181
+ return item.value;
182
+ }
183
+ static localStorageDelete(key) {
184
+ localStorage.removeItem(key);
185
+ }
186
+ static localStorageExists(key) {
187
+ return this.localStorageGet(key) !== null;
188
+ }
189
+ static getParam(variable) {
190
+ let url = window.location.search;
191
+ if (this.nx(url)) return null;
192
+ let vars = url.substring(1).split("&");
193
+ for (var i = 0; i < vars.length; i++) {
194
+ var pair = vars[i].split("=");
195
+ if (pair[0] == variable && this.x(pair[1])) return pair[1];
196
+ }
197
+ return null;
198
+ }
199
+ static getDevice() {
200
+ if (this.isPhone()) return "phone";
201
+ if (this.isTablet()) return "tablet";
202
+ return "desktop";
203
+ }
204
+ static isPhone() {
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/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 isTablet() {
209
+ let a = navigator.userAgent || navigator.vendor || window.opera;
210
+ 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));
211
+ }
212
+ static isDesktop() {
213
+ return !this.isPhone() && !this.isTablet();
214
+ }
215
+ static isMobile() {
216
+ if (window.innerWidth < 750 || this.isPhone()) return true;
217
+ return false;
218
+ }
219
+ static isTouch() {
220
+ return "ontouchstart" in window || navigator.maxTouchPoints || false;
221
+ }
222
+ static isPageSpeed() {
223
+ const ua = navigator.userAgent || "";
224
+ let score = 0;
225
+ if (/Lighthouse|HeadlessChrome|Chrome-Lighthouse|Speed Insights|PTST|PageSpeed/i.test(ua)) return true;
226
+ if (navigator.webdriver) return true;
227
+ if (!navigator.languages || navigator.languages.length === 0) score += 3;
228
+ if (/moto g power|Moto G4/i.test(ua)) score += 2;
229
+ if (/Chrome\/\d{3}\.0\.0\.0/i.test(ua)) score += 1;
230
+ if (typeof window !== "undefined") {
231
+ const w = window.innerWidth;
232
+ const h = window.innerHeight;
233
+ if (w === 1350 && h === 940 || w === 412 && (h === 823 || h === 915) || w === 360 && h === 640) score += 2;
234
+ }
235
+ if (navigator.plugins && navigator.plugins.length === 0) score += 1;
236
+ if (!navigator.connection && !navigator.deviceMemory && !navigator.hardwareConcurrency) score += 1;
237
+ if (typeof navigator.permissions === "undefined") score += 1;
238
+ if (/Chrome/i.test(ua) && typeof window.chrome === "undefined") score += 2;
239
+ return score >= 4;
240
+ }
241
+ static isMac() {
242
+ return hlp.getOs() === "mac";
243
+ }
244
+ static isLinux() {
245
+ return hlp.getOs() === "linux";
246
+ }
247
+ static isWindows() {
248
+ return hlp.getOs() === "windows";
249
+ }
250
+ static getOs() {
251
+ let userAgent = window.navigator.userAgent, platform = window.navigator.platform, macosPlatforms = [
252
+ "Macintosh",
253
+ "MacIntel",
254
+ "MacPPC",
255
+ "Mac68K"
256
+ ], windowsPlatforms = [
257
+ "Win32",
258
+ "Win64",
259
+ "Windows",
260
+ "WinCE"
261
+ ], iosPlatforms = [
262
+ "iPhone",
263
+ "iPad",
264
+ "iPod"
265
+ ], os = "unknown";
266
+ if (macosPlatforms.indexOf(platform) !== -1) os = "mac";
267
+ else if (iosPlatforms.indexOf(platform) !== -1) os = "mac";
268
+ else if (windowsPlatforms.indexOf(platform) !== -1) os = "windows";
269
+ else if (/Android/.test(userAgent)) os = "linux";
270
+ else if (/Linux/.test(platform)) os = "linux";
271
+ return os;
272
+ }
273
+ static getBrowser() {
274
+ let browser_name = "", isEdge = !!!document.documentMode && !!window.StyleMedia;
275
+ if (navigator.userAgent.indexOf("Opera") != -1 || navigator.userAgent.indexOf("OPR") != -1) browser_name = "opera";
276
+ else if (navigator.userAgent.indexOf("Chrome") != -1 && !isEdge) browser_name = "chrome";
277
+ else if (navigator.userAgent.indexOf("Safari") != -1 && !isEdge) browser_name = "safari";
278
+ else if (navigator.userAgent.indexOf("Firefox") != -1) browser_name = "firefox";
279
+ else if (navigator.userAgent.indexOf("MSIE") != -1 || !!document.documentMode == true) browser_name = "ie";
280
+ else if (isEdge) browser_name = "edge";
281
+ else browser_name = "unknown";
282
+ return browser_name;
283
+ }
284
+ static isObject(a = null) {
285
+ return !!a && a.constructor === Object;
286
+ }
287
+ static isArray(a = null) {
288
+ return !!a && a.constructor === Array;
289
+ }
290
+ static isString(string) {
291
+ return typeof string === "string" || string instanceof String;
292
+ }
293
+ static isDate(string) {
294
+ if (this.nx(string)) return false;
295
+ if (Object.prototype.toString.call(string) === "[object Date]") return true;
296
+ if (!this.isString(string)) return false;
297
+ if (string.split("-").length !== 3) return false;
298
+ let day = parseInt(string.split("-")[2]), month = parseInt(string.split("-")[1]), year = parseInt(string.split("-")[0]), date = /* @__PURE__ */ new Date();
299
+ date.setFullYear(year, month - 1, day);
300
+ if (date.getFullYear() == year && date.getMonth() + 1 == month && date.getDate() == day) return true;
301
+ return false;
302
+ }
303
+ static password_generate(length = 20, chars = [
304
+ "a-z",
305
+ "A-Z",
306
+ "0-9",
307
+ "$!?"
308
+ ], exclude = "lI") {
309
+ if (chars === null || !chars.length || length < chars.length) return null;
310
+ let charGroups = [];
311
+ for (let group of chars) {
312
+ let expanded = [];
313
+ if (group === "a-z") expanded = Array.from({ length: 26 }, (_, i) => String.fromCharCode(97 + i));
314
+ else if (group === "A-Z") expanded = Array.from({ length: 26 }, (_, i) => String.fromCharCode(65 + i));
315
+ else if (group === "0-9") expanded = Array.from({ length: 10 }, (_, i) => String.fromCharCode(48 + i));
316
+ else expanded = group.split("");
317
+ if (exclude) expanded = expanded.filter((c) => !exclude.includes(c));
318
+ if (expanded.length === 0) return null;
319
+ charGroups.push(expanded);
320
+ }
321
+ let passwordChars = charGroups.map((group) => group[Math.floor(Math.random() * group.length)]);
322
+ let allChars = charGroups.flat();
323
+ while (passwordChars.length < length) {
324
+ let i = Math.floor(Math.random() * allChars.length);
325
+ passwordChars.push(allChars[i]);
326
+ }
327
+ for (let i = passwordChars.length - 1; i > 0; i--) {
328
+ let j = Math.floor(Math.random() * (i + 1));
329
+ [passwordChars[i], passwordChars[j]] = [passwordChars[j], passwordChars[i]];
330
+ }
331
+ return passwordChars.join("");
332
+ }
333
+ static formatNumber(number, decimals = 0, dec_point = ".", thousands_sep = ",") {
334
+ number = (number + "").replace(/[^0-9+\-Ee.]/g, "");
335
+ 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, toFixedFix = function(n, prec) {
336
+ var k = Math.pow(10, prec);
337
+ return "" + Math.round(n * k) / k;
338
+ };
339
+ let sArr = (prec ? toFixedFix(n, prec) : "" + Math.round(n)).split(".");
340
+ if (sArr[0].length > 3) sArr[0] = sArr[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
341
+ if ((sArr[1] || "").length < prec) {
342
+ sArr[1] = sArr[1] || "";
343
+ sArr[1] += new Array(prec - sArr[1].length + 1).join("0");
344
+ }
345
+ return sArr.join(dec);
346
+ }
347
+ static formatDate(format, date = null) {
348
+ if (date === false || date === true || date === null || date === "") date = /* @__PURE__ */ new Date();
349
+ else if (typeof date !== "object") date = new Date(date.replace(/-/g, "/").replace(/T|Z/g, " "));
350
+ 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();
351
+ for (let i = 0, len = format.length; i < len; i++) switch (format[i]) {
352
+ case "j":
353
+ string += d;
354
+ break;
355
+ case "d":
356
+ string += d < 10 ? "0" + d : d;
357
+ break;
358
+ case "l":
359
+ let days = Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
360
+ string += days[dow];
361
+ break;
362
+ case "w":
363
+ string += dow;
364
+ break;
365
+ case "D":
366
+ days = Array("Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat");
367
+ string += days[dow];
368
+ break;
369
+ case "m":
370
+ string += m1 < 10 ? "0" + m1 : m1;
371
+ break;
372
+ case "n":
373
+ string += m1;
374
+ break;
375
+ case "F":
376
+ let months = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
377
+ string += months[mo];
378
+ break;
379
+ case "M":
380
+ months = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
381
+ string += months[mo];
382
+ break;
383
+ case "Y":
384
+ string += y;
385
+ break;
386
+ case "y":
387
+ string += y.toString().slice(-2);
388
+ break;
389
+ case "H":
390
+ string += h < 10 ? "0" + h : h;
391
+ break;
392
+ case "g":
393
+ let hour = h === 0 ? 12 : h;
394
+ string += hour > 12 ? hour - 12 : hour;
395
+ break;
396
+ case "h":
397
+ hour = h === 0 ? 12 : h;
398
+ hour = hour > 12 ? hour - 12 : hour;
399
+ string += hour < 10 ? "0" + hour : hour;
400
+ break;
401
+ case "a":
402
+ string += h < 12 ? "am" : "pm";
403
+ break;
404
+ case "i":
405
+ string += mi < 10 ? "0" + mi : mi;
406
+ break;
407
+ case "s":
408
+ string += s < 10 ? "0" + s : s;
409
+ break;
410
+ case "c":
411
+ string += date.toISOString();
412
+ break;
413
+ default: string += format[i];
414
+ }
415
+ return string;
416
+ }
417
+ static deepCopy(obj, hash = /* @__PURE__ */ new WeakMap()) {
418
+ if (Object(obj) !== obj) return obj;
419
+ if (hash.has(obj)) return hash.get(obj);
420
+ 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);
421
+ hash.set(obj, result);
422
+ if (obj instanceof Map) Array.from(obj, ([key, val]) => result.set(key, hlp.deepCopy(val, hash)));
423
+ return Object.assign(result, ...Object.keys(obj).map((key) => ({ [key]: hlp.deepCopy(obj[key], hash) })));
424
+ }
425
+ static jsonStringToObject(string) {
426
+ if (this.nx(string) || !this.isString(string)) return null;
427
+ try {
428
+ return JSON.parse(string);
429
+ } catch (error) {
430
+ return null;
431
+ }
432
+ }
433
+ static isJsonString(string) {
434
+ if (this.nx(string) || !this.isString(string)) return false;
435
+ try {
436
+ JSON.parse(string);
437
+ return true;
438
+ } catch (error) {
439
+ return false;
440
+ }
441
+ }
442
+ static jsonObjectToString(object) {
443
+ try {
444
+ return JSON.stringify(object);
445
+ } catch (error) {
446
+ return null;
447
+ }
448
+ }
449
+ static uuid() {
450
+ function s4() {
451
+ return Math.floor((1 + Math.random()) * 65536).toString(16).substring(1);
452
+ }
453
+ return s4() + s4() + "-" + s4() + "-" + s4() + "-" + s4() + "-" + s4() + s4() + s4();
454
+ }
455
+ static guid() {
456
+ return this.uuid();
457
+ }
458
+ static replaceAll(string, search, replace) {
459
+ return string.split(search).join(replace);
460
+ }
461
+ static replaceLast(string, search, replace) {
462
+ let n = string.lastIndexOf(search);
463
+ string = string.slice(0, n) + string.slice(n).replace(search, replace);
464
+ return string;
465
+ }
466
+ static replaceFirst(string, search, replace) {
467
+ return string.replace(search, replace);
468
+ }
469
+ static findAllPositions(searchStr, str) {
470
+ let searchStrLen = searchStr.length, startIndex = 0, index, indices = [];
471
+ if (searchStrLen == 0) return [];
472
+ while ((index = str.indexOf(searchStr, startIndex)) > -1) {
473
+ indices.push(index);
474
+ startIndex = index + searchStrLen;
475
+ }
476
+ return indices;
477
+ }
478
+ static findAllPositionsCaseInsensitive(searchStr, str) {
479
+ let searchStrLen = searchStr.length, startIndex = 0, index, indices = [];
480
+ if (searchStrLen == 0) return [];
481
+ while ((index = this.indexOfCaseInsensitive(searchStr, str, startIndex)) > -1) {
482
+ indices.push(index);
483
+ startIndex = index + searchStrLen;
484
+ }
485
+ return indices;
486
+ }
487
+ static countAllOccurences(value, str) {
488
+ return this.findAllPositions(value, str).length;
489
+ }
490
+ static countAllOccurencesCaseInsensitive(value, str) {
491
+ return this.findAllPositionsCaseInsensitive(value, str).length;
492
+ }
493
+ static indexOfCaseInsensitive(searchStr, str, offset = 0) {
494
+ return str.toLowerCase().indexOf(searchStr.toLowerCase(), offset);
495
+ }
496
+ static highlight(string, query, strip = false, strip_length = 500) {
497
+ if (this.nx(string) || this.nx(query)) return string;
498
+ if (strip === true) {
499
+ let dots = "...";
500
+ let positions = this.findAllPositionsCaseInsensitive(query, string);
501
+ let words = string.split(" ");
502
+ let i = 0;
503
+ words.forEach((words__value, words__key) => {
504
+ let strip_now = true;
505
+ positions.forEach((positions__value) => {
506
+ if (i >= positions__value - strip_length && i <= positions__value + query.length + strip_length - 1) strip_now = false;
507
+ });
508
+ if (strip_now === true) words[words__key] = dots;
509
+ i += words__value.length + 1;
510
+ });
511
+ string = words.join(" ");
512
+ while (string.indexOf("... ...") > -1) string = this.replaceAll(string, "... ...", dots);
513
+ string = string.trim();
514
+ }
515
+ let positions = this.findAllPositionsCaseInsensitive(query, string);
516
+ let wrap_begin = "<strong class=\"highlight\">";
517
+ let wrap_end = "</strong>";
518
+ for (let x = 0; x < positions.length; x++) {
519
+ string = string.substring(0, positions[x]) + wrap_begin + string.substring(positions[x], positions[x] + query.length) + wrap_end + string.substring(positions[x] + query.length);
520
+ for (let y = x + 1; y < positions.length; y++) positions[y] = positions[y] + 26 + 9;
521
+ }
522
+ return string;
523
+ }
524
+ static get(url, args = null) {
525
+ return this.call("GET", url, args);
526
+ }
527
+ static post(url, args = null) {
528
+ return this.call("POST", url, args);
529
+ }
530
+ static call(method, url, args = null) {
531
+ if (args === null) args = {};
532
+ if (!("data" in args)) args.data = {};
533
+ if (!("headers" in args)) args.headers = null;
534
+ if (!("throttle" in args)) args.throttle = 0;
535
+ if (!("allow_errors" in args)) args.allow_errors = true;
536
+ return new Promise((resolve, reject) => {
537
+ setTimeout(() => {
538
+ if (url.indexOf("http") !== 0) url = hlp.baseUrl() + "/" + url;
539
+ let xhr = new XMLHttpRequest();
540
+ xhr.open(method, url, true);
541
+ if (method === "POST") {
542
+ if ("data" in args && args.data !== null && typeof args.data === "object" && !(args.data instanceof FormData)) {
543
+ xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
544
+ args.data = JSON.stringify(args.data);
545
+ }
546
+ xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
547
+ }
548
+ if (this.x(args.headers)) Object.entries(args.headers).forEach(([headers__key, headers__value]) => {
549
+ xhr.setRequestHeader(headers__key, headers__value);
550
+ });
551
+ xhr.onload = () => {
552
+ if (xhr.readyState != 4 || args.allow_errors !== true && xhr.status != 200 && xhr.status != 304) if (this.isJsonString(xhr.responseText)) reject(this.jsonStringToObject(xhr.responseText));
553
+ else reject(xhr.responseText);
554
+ if (this.isJsonString(xhr.responseText)) resolve(this.jsonStringToObject(xhr.responseText));
555
+ else resolve(xhr.responseText);
556
+ };
557
+ xhr.onerror = () => {
558
+ reject([
559
+ xhr.readyState,
560
+ xhr.status,
561
+ xhr.statusText
562
+ ]);
563
+ };
564
+ if (method === "GET") xhr.send(null);
565
+ if (method === "POST") xhr.send(args.data);
566
+ }, args.throttle);
567
+ });
568
+ }
569
+ static onResizeHorizontal(fun) {
570
+ let windowWidth = window.innerWidth, windowWidthNew, timeout;
571
+ window.addEventListener("resize", () => {
572
+ windowWidthNew = window.innerWidth;
573
+ if (windowWidthNew != windowWidth) {
574
+ windowWidth = windowWidthNew;
575
+ if (timeout) clearTimeout(timeout);
576
+ timeout = window.setTimeout(() => {
577
+ fun();
578
+ }, 50);
579
+ }
580
+ });
581
+ fun();
582
+ }
583
+ static onResizeVertical(fun) {
584
+ var windowHeight = window.innerHeight, windowHeightNew, timeout;
585
+ window.addEventListener("resize", () => {
586
+ windowHeightNew = window.innerHeight;
587
+ if (windowHeightNew != windowHeight) {
588
+ windowHeight = windowHeightNew;
589
+ if (timeout) clearTimeout(timeout);
590
+ timeout = window.setTimeout(() => {
591
+ fun();
592
+ }, 50);
593
+ }
594
+ });
595
+ fun();
596
+ }
597
+ static removeEmpty(array) {
598
+ if (this.nx(array) || !Array.isArray(array)) return array;
599
+ array = array.filter((array__value) => {
600
+ return this.x(array__value);
601
+ });
602
+ return array;
603
+ }
604
+ static uniqueArray(array) {
605
+ let seen = {}, ret_arr = [];
606
+ for (let i = 0; i < array.length; i++) if (!(array[i] in seen)) {
607
+ ret_arr.push(array[i]);
608
+ seen[array[i]] = true;
609
+ }
610
+ return ret_arr;
611
+ }
612
+ static powerset(array) {
613
+ if (!Array.isArray(array)) return array;
614
+ return array.reduce((subsets, value) => subsets.concat(subsets.map((set) => [...set, value])), [[]]);
615
+ }
616
+ static charToInt(val) {
617
+ val = val.toUpperCase();
618
+ let base = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", i, j, result = 0;
619
+ for (i = 0, j = val.length - 1; i < val.length; i += 1, j -= 1) result += Math.pow(26, j) * (base.indexOf(val[i]) + 1);
620
+ return result;
621
+ }
622
+ static intToChar(num) {
623
+ for (var ret = "", a = 1, b = 26; (num -= a) >= 0; a = b, b *= 26) ret = String.fromCharCode(parseInt(num % b / a) + 65) + ret;
624
+ return ret;
625
+ }
626
+ static slugify(text) {
627
+ 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, "");
628
+ }
629
+ static incChar(char, shift = 1) {
630
+ return this.intToChar(this.charToInt(char) + shift);
631
+ }
632
+ static decChar(char, shift = 1) {
633
+ return this.intToChar(this.charToInt(char) - shift);
634
+ }
635
+ static range(start, end) {
636
+ let range = [], typeofStart = typeof start, typeofEnd = typeof end, step = 1;
637
+ if (typeofStart == "undefined" || typeofEnd == "undefined" || typeofStart != typeofEnd) return null;
638
+ if (end < start) step = -step;
639
+ if (typeofStart == "number") while (step > 0 ? end >= start : end <= start) {
640
+ range.push(start);
641
+ start += step;
642
+ }
643
+ else if (typeofStart == "string") {
644
+ if (start.length != 1 || end.length != 1) return null;
645
+ start = start.charCodeAt(0);
646
+ end = end.charCodeAt(0);
647
+ while (step > 0 ? end >= start : end <= start) {
648
+ range.push(String.fromCharCode(start));
649
+ start += step;
650
+ }
651
+ } else return null;
652
+ return range;
653
+ }
654
+ static dateToWeek(d = null) {
655
+ if (d === null) d = /* @__PURE__ */ new Date();
656
+ d = new Date(Date.UTC(d.getFullYear(), d.getMonth(), d.getDate()));
657
+ d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
658
+ let yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
659
+ return Math.ceil(((d - yearStart) / 864e5 + 1) / 7);
660
+ }
661
+ static weekToDate(week, year) {
662
+ if (year == null) year = (/* @__PURE__ */ new Date()).getFullYear();
663
+ let date = /* @__PURE__ */ new Date();
664
+ date.setFullYear(year);
665
+ date.setDate(1);
666
+ date.setMonth(0);
667
+ date.setHours(0);
668
+ date.setMinutes(0);
669
+ date.setSeconds(0);
670
+ date.setMilliseconds(0);
671
+ let FIRST_DAY_OF_WEEK = 1;
672
+ let WEEK_LENGTH = 7;
673
+ let day = date.getDay();
674
+ day = day === 0 ? 7 : day;
675
+ let dayOffset = -day + FIRST_DAY_OF_WEEK;
676
+ if (WEEK_LENGTH - day + 1 < 4) dayOffset += WEEK_LENGTH;
677
+ date = new Date(date.getTime() + dayOffset * 24 * 60 * 60 * 1e3);
678
+ let weekTime = 1e3 * 60 * 60 * 24 * 7 * (week - 1);
679
+ let targetTime = date.getTime() + weekTime;
680
+ date.setTime(targetTime);
681
+ date.setHours(0);
682
+ date.setMinutes(0);
683
+ date.setSeconds(0);
684
+ date.setMilliseconds(0);
685
+ return date;
686
+ }
687
+ static addDays(date, days) {
688
+ var result = new Date(date);
689
+ result.setDate(result.getDate() + days);
690
+ return result;
691
+ }
692
+ static diffInMonths(date1, date2) {
693
+ 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();
694
+ return yearDiff * 12 + monthDiff + dayDiff / daysInMonth;
695
+ }
696
+ static objectsAreEqual(x, y) {
697
+ var _this = this;
698
+ if (x === null || x === void 0 || y === null || y === void 0) return x === y;
699
+ if (x.constructor !== y.constructor) return false;
700
+ if (x instanceof Function) return x === y;
701
+ if (x instanceof RegExp) return x === y;
702
+ if (x === y || x.valueOf() === y.valueOf()) return true;
703
+ if (Array.isArray(x) && x.length !== y.length) return false;
704
+ if (x instanceof Date) return false;
705
+ if (!(x instanceof Object)) return false;
706
+ if (!(y instanceof Object)) return false;
707
+ var p = Object.keys(x);
708
+ return Object.keys(y).every(function(i) {
709
+ return p.indexOf(i) !== -1;
710
+ }) && p.every(function(i) {
711
+ return _this.objectsAreEqual(x[i], y[i]);
712
+ });
713
+ }
714
+ static containsObject(obj, list) {
715
+ var x;
716
+ for (x in list) if (list.hasOwnProperty(x) && this.objectsAreEqual(list[x], obj)) return true;
717
+ return false;
718
+ }
719
+ static fadeOut(el, speed = 1e3) {
720
+ if (speed <= 25) speed = 25;
721
+ return new Promise((resolve) => {
722
+ el.style.opacity = 1;
723
+ (function fade() {
724
+ if ((el.style.opacity -= 25 / speed) < 0) {
725
+ el.style.display = "none";
726
+ resolve();
727
+ } else requestAnimationFrame(fade);
728
+ })();
729
+ });
730
+ }
731
+ static fadeIn(el, speed = 1e3) {
732
+ if (speed <= 25) speed = 25;
733
+ return new Promise((resolve) => {
734
+ el.style.opacity = 0;
735
+ el.style.display = "block";
736
+ (function fade() {
737
+ var val = parseFloat(el.style.opacity);
738
+ if (!((val += 25 / speed) > 1)) {
739
+ el.style.opacity = val;
740
+ requestAnimationFrame(fade);
741
+ } else resolve();
742
+ })();
743
+ });
744
+ }
745
+ static scrollTop() {
746
+ let doc = document.documentElement;
747
+ return (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0);
748
+ }
749
+ static scrollLeft() {
750
+ let doc = document.documentElement;
751
+ return (window.pageXOffset || doc.scrollLeft) - (doc.clientLeft || 0);
752
+ }
753
+ static closestScrollable(node) {
754
+ let overflowY = node instanceof HTMLElement && window.getComputedStyle(node).overflowY, isScrollable = overflowY && !(overflowY.includes("hidden") || overflowY.includes("visible"));
755
+ if (!node) return null;
756
+ else if (isScrollable && node.scrollHeight >= node.clientHeight) return node;
757
+ return this.closestScrollable(node.parentNode) || document.scrollingElement || document.body;
758
+ }
759
+ static offsetTop(el) {
760
+ return el.getBoundingClientRect().top + window.pageYOffset - document.documentElement.clientTop;
761
+ }
762
+ static offsetLeft(el) {
763
+ return el.getBoundingClientRect().left + window.pageXOffset - document.documentElement.clientLeft;
764
+ }
765
+ static offsetRight(el) {
766
+ return el.getBoundingClientRect().left + window.pageXOffset - document.documentElement.clientLeft + el.offsetWidth;
767
+ }
768
+ static offsetBottom(el) {
769
+ return el.getBoundingClientRect().top + window.pageYOffset - document.documentElement.clientTop + el.offsetHeight;
770
+ }
771
+ static offsetTopWithMargin(el) {
772
+ return this.offsetTop(el) - parseInt(getComputedStyle(el).marginTop);
773
+ }
774
+ static offsetLeftWithMargin(el) {
775
+ return this.offsetLeft(el) - parseInt(getComputedStyle(el).marginLeft);
776
+ }
777
+ static offsetRightWithMargin(el) {
778
+ return this.offsetRight(el) + parseInt(getComputedStyle(el).marginRight);
779
+ }
780
+ static offsetBottomWithMargin(el) {
781
+ return this.offsetBottom(el) + parseInt(getComputedStyle(el).marginBottom);
782
+ }
783
+ static documentHeight() {
784
+ return Math.max(document.body.offsetHeight, document.body.scrollHeight, document.documentElement.clientHeight, document.documentElement.offsetHeight, document.documentElement.scrollHeight);
785
+ }
786
+ static documentWidth() {
787
+ return document.documentElement.clientWidth || document.body.clientWidth;
788
+ }
789
+ static windowWidth() {
790
+ return window.innerWidth;
791
+ }
792
+ static windowHeight() {
793
+ return window.innerHeight;
794
+ }
795
+ static windowWidthWithoutScrollbar() {
796
+ return document.documentElement.clientWidth || document.body.clientWidth;
797
+ }
798
+ static windowHeightWithoutScrollbar() {
799
+ return document.documentElement.clientHeight || document.body.clientHeight;
800
+ }
801
+ static outerWidthWithMargin(el) {
802
+ return el.offsetWidth + parseInt(getComputedStyle(el).marginLeft) + parseInt(getComputedStyle(el).marginRight);
803
+ }
804
+ static outerHeightWithMargin(el) {
805
+ return el.offsetHeight + parseInt(getComputedStyle(el).marginTop) + parseInt(getComputedStyle(el).marginBottom);
806
+ }
807
+ static async cursorPosition() {
808
+ document.head.insertAdjacentHTML("afterbegin", `
809
+ <style type="text/css">
810
+ .find-pointer-quad {
811
+ --hit: 0;
812
+ position: fixed;
813
+ z-index:2147483647;
814
+ transform: translateZ(0);
815
+ &:hover { --hit: 1; }
1583
816
  }
1584
- els__value.classList.remove(random_class);
1585
- toFinish--;
1586
- if (toFinish <= 0) {
1587
- resolve();
1588
- }
1589
- }
1590
- }, duration * 1.5);
1591
- } else {
1592
- if (document.head.contains(style)) {
1593
- document.head.removeChild(style);
1594
- }
1595
- els__value.classList.remove(random_class);
1596
- toFinish--;
1597
- if (toFinish <= 0) {
1598
- resolve();
1599
- }
1600
- }
1601
- });
1602
- });
1603
- });
1604
- });
1605
- });
1606
- }
1607
- static addEventListenerOnce(target, type, listener) {
1608
- let addOptions = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : undefined;
1609
- let removeOptions = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : undefined;
1610
- target.addEventListener(type, function fn(event) {
1611
- let result = listener.apply(this, arguments, addOptions);
1612
- if (result !== false) {
1613
- target.removeEventListener(type, fn, removeOptions);
1614
- }
1615
- });
1616
- }
1617
- static htmlDecode(value) {
1618
- let tmp = document.createElement('textarea');
1619
- tmp.innerHTML = value;
1620
- return tmp.value;
1621
- }
1622
- static htmlEncode(value) {
1623
- return value.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#x27;').replace(/`/g, '&#96;');
1624
- }
1625
- static nl2br(str) {
1626
- if (typeof str === 'undefined' || str === null) {
1627
- return '';
1628
- }
1629
- let breakTag = '<br/>',
1630
- replaceStr = '$1' + breakTag;
1631
- return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, replaceStr);
1632
- }
1633
- static br2nl(str) {
1634
- if (typeof str === 'undefined' || str === null) {
1635
- return '';
1636
- }
1637
- let replaceStr = '\n';
1638
- return str.replace(/<\s*\/?br\s*[\/]?>/gi, replaceStr);
1639
- }
1640
- static closest(el, selector) {
1641
- if (!document.documentElement.contains(el)) {
1642
- return null;
1643
- }
1644
- do {
1645
- if (this.matches(el, selector)) {
1646
- return el;
1647
- }
1648
- el = el.parentElement || el.parentNode;
1649
- } while (el !== null && el.nodeType === 1);
1650
- return null;
1651
- }
1652
- static matches(el, selector) {
1653
- let node = el,
1654
- nodes = (node.parentNode || node.document).querySelectorAll(selector),
1655
- i = -1;
1656
- while (nodes[++i] && nodes[i] != node);
1657
- return !!nodes[i];
1658
- }
1659
- static wrap(el, html) {
1660
- if (el === null) {
1661
- return;
1662
- }
1663
- let wrapper = new DOMParser().parseFromString(html, 'text/html').body.childNodes[0];
1664
- el.parentNode.insertBefore(wrapper, el.nextSibling);
1665
- wrapper.appendChild(el);
1666
- }
1667
- static wrapTextNodes(el, tag) {
1668
- if (el === null) {
1669
- return;
1670
- }
1671
- Array.from(el.childNodes).filter(node => node.nodeType === 3 && node.textContent.trim().length > 1).forEach(node => {
1672
- const wrapper = document.createElement(tag);
1673
- node.after(wrapper);
1674
- wrapper.appendChild(node);
1675
- });
1676
- }
1677
- static html2dom(html) {
1678
- let template = document.createElement('template');
1679
- html = html.trim();
1680
- template.innerHTML = html;
1681
- if (template.content === undefined) {
1682
- return this.html2domLegacy(html);
1683
- }
1684
- return template.content.firstChild;
1685
- }
1686
- static html2domLegacy(html) {
1687
- /* source: https://gist.github.com/Munawwar/6e6362dbdf77c7865a99 */
1688
- var rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,
1689
- rtagName = /<([\w:]+)/,
1690
- rhtml = /<|&#?\w+;/,
1691
- wrapMap = {
1692
- option: [1, "<select multiple='multiple'>", '</select>'],
1693
- thead: [1, '<table>', '</table>'],
1694
- col: [2, '<table><colgroup>', '</colgroup></table>'],
1695
- tr: [2, '<table><tbody>', '</tbody></table>'],
1696
- td: [3, '<table><tbody><tr>', '</tr></tbody></table>'],
1697
- _default: [0, '', '']
1698
- },
1699
- context = document;
1700
- var tmp,
1701
- tag,
1702
- wrap,
1703
- j,
1704
- fragment = context.createDocumentFragment();
1705
- if (!rhtml.test(html)) {
1706
- fragment.appendChild(context.createTextNode(html));
1707
- } else {
1708
- tmp = fragment.appendChild(context.createElement('div'));
1709
- tag = (rtagName.exec(html) || ['', ''])[1].toLowerCase();
1710
- wrap = wrapMap[tag] || wrapMap._default;
1711
- tmp.innerHTML = wrap[1] + html.replace(rxhtmlTag, '<$1></$2>') + wrap[2];
1712
- j = wrap[0];
1713
- while (j--) {
1714
- tmp = tmp.lastChild;
1715
- }
1716
- fragment.removeChild(fragment.firstChild);
1717
- while (tmp.firstChild) {
1718
- fragment.appendChild(tmp.firstChild);
1719
- }
1720
- }
1721
- return fragment.querySelector('*');
1722
- }
1723
- static prev(elem, filter) {
1724
- let prev = elem.previousElementSibling;
1725
- if (prev === null) {
1726
- return null;
1727
- }
1728
- if (filter === undefined || this.matches(prev, filter)) {
1729
- return prev;
1730
- }
1731
- return null;
1732
- }
1733
- static next(elem, filter) {
1734
- let next = elem.nextElementSibling;
1735
- if (next === null) {
1736
- return null;
1737
- }
1738
- if (filter === undefined || this.matches(next, filter)) {
1739
- return next;
1740
- }
1741
- return null;
1742
- }
1743
- static prevAll(elem, filter) {
1744
- let sibs = [];
1745
- while (elem = elem.previousElementSibling) {
1746
- if (filter === undefined || this.matches(elem, filter)) {
1747
- sibs.push(elem);
1748
- }
1749
- }
1750
- return sibs;
1751
- }
1752
- static nextAll(elem, filter) {
1753
- let sibs = [];
1754
- while (elem = elem.nextElementSibling) {
1755
- if (filter === undefined || this.matches(elem, filter)) {
1756
- sibs.push(elem);
1757
- }
1758
- }
1759
- return sibs;
1760
- }
1761
- static prevUntil(elem, filter) {
1762
- let sibs = [];
1763
- while (elem = elem.previousElementSibling) {
1764
- if (!this.matches(elem, filter)) {
1765
- sibs.push(elem);
1766
- } else {
1767
- break;
1768
- }
1769
- }
1770
- return sibs;
1771
- }
1772
- static nextUntil(elem, filter) {
1773
- let sibs = [];
1774
- while (elem = elem.nextElementSibling) {
1775
- if (!this.matches(elem, filter)) {
1776
- sibs.push(elem);
1777
- } else {
1778
- break;
1779
- }
1780
- }
1781
- return sibs;
1782
- }
1783
- static siblings(elem, filter) {
1784
- let sibs = [];
1785
- let self = elem;
1786
- elem = elem.parentNode.firstChild;
1787
- while (elem = elem.nextElementSibling) {
1788
- if (filter === undefined || this.matches(elem, filter)) {
1789
- if (self !== elem) {
1790
- sibs.push(elem);
1791
- }
1792
- }
1793
- }
1794
- return sibs;
1795
- }
1796
- static parents(elem, selector) {
1797
- let elements = [];
1798
- let ishaveselector = selector !== undefined;
1799
- while ((elem = elem.parentElement) !== null) {
1800
- if (elem.nodeType !== Node.ELEMENT_NODE) {
1801
- continue;
1802
- }
1803
- if (!ishaveselector || this.matches(elem, selector)) {
1804
- elements.push(elem);
1805
- }
1806
- }
1807
- return elements;
1808
- }
1809
- static css(el) {
1810
- let sheets = document.styleSheets,
1811
- o = {};
1812
- for (let sheets__key in sheets) {
1813
- try {
1814
- let rules = sheets[sheets__key].rules || sheets[sheets__key].cssRules;
1815
- for (let rules__key in rules) {
1816
- if (this.matches(el, rules[rules__key].selectorText)) {
1817
- o = Object.assign(o, this.css2json(rules[rules__key].style), this.css2json(el.getAttribute('style')));
1818
- }
1819
- }
1820
- } catch (e) {}
1821
- }
1822
- return o;
1823
- }
1824
- static css2json(css) {
1825
- let obj = {};
1826
- if (!css) {
1827
- return obj;
1828
- }
1829
- if (css instanceof CSSStyleDeclaration) {
1830
- for (let css__key in css) {
1831
- if (css[css__key].toLowerCase && css[css[css__key]] !== undefined) {
1832
- obj[css[css__key].toLowerCase()] = css[css[css__key]];
1833
- }
1834
- }
1835
- } else if (typeof css == 'string') {
1836
- css = css.split(';');
1837
- for (let css__key in css) {
1838
- if (css[css__key].indexOf(':') > -1) {
1839
- let val = css[css__key].split(':');
1840
- obj[val[0].toLowerCase().trim()] = val[1].trim();
1841
- }
1842
- }
1843
- }
1844
- return obj;
1845
- }
1846
- static compareDates(d1, d2) {
1847
- // safari has problems in parsing "2019-01-01 00:00:00"
1848
- if (typeof d1 === 'string') {
1849
- d1 = d1.split(' ').join('T');
1850
- }
1851
- if (typeof d2 === 'string') {
1852
- d2 = d2.split(' ').join('T');
1853
- }
1854
- d1 = new Date(d1);
1855
- d2 = new Date(d2);
1856
- d1.setHours(0);
1857
- d1.setMinutes(0);
1858
- d1.setSeconds(0);
1859
- d1.setMilliseconds(0);
1860
- d2.setHours(0);
1861
- d2.setMinutes(0);
1862
- d2.setSeconds(0);
1863
- d2.setMilliseconds(0);
1864
- if (d1.getFullYear() === d2.getFullYear() && d1.getMonth() === d2.getMonth() && d1.getDate() === d2.getDate()) {
1865
- return 0;
1866
- }
1867
- if (d1 < d2) {
1868
- return -1;
1869
- }
1870
- return 1;
1871
- }
1872
- static spaceship(val1, val2) {
1873
- if (val1 === null || val2 === null || typeof val1 != typeof val2) {
1874
- return null;
1875
- }
1876
- if (typeof val1 === 'string') {
1877
- return val1.localeCompare(val2);
1878
- } else {
1879
- if (val1 > val2) {
1880
- return 1;
1881
- } else if (val1 < val2) {
1882
- return -1;
1883
- }
1884
- return 0;
1885
- }
1886
- }
1887
- static querySelectorAllShadowDom(selector) {
1888
- let traverse = function ($parent) {
1889
- let $els = [];
1890
- if ($parent.querySelector('*') !== null) {
1891
- $parent.querySelectorAll('*').forEach($el => {
1892
- $els.push($el);
1893
- if ($el.shadowRoot !== undefined && $el.shadowRoot !== null) {
1894
- $els = $els.concat(traverse($el.shadowRoot));
1895
- }
1896
- });
1897
- }
1898
- return $els;
1899
- };
1900
- let fragment = document.createDocumentFragment();
1901
- let $els = traverse(document);
1902
- $els.forEach($el => {
1903
- if ($el.matches(selector)) {
1904
- fragment.appendChild($el.cloneNode());
1905
- }
1906
- });
1907
- return fragment.childNodes;
1908
- }
1909
- static focus(selector) {
1910
- hlp.unfocus();
1911
- let el = null;
1912
- if (typeof selector === 'string' || selector instanceof String) {
1913
- el = document.querySelector(selector);
1914
- } else {
1915
- el = selector;
1916
- }
1917
- if (el !== null) {
1918
- let mask = document.createElement('div');
1919
- mask.classList.add('hlp-focus-mask');
1920
- mask.style.position = 'fixed';
1921
- mask.style.top = '0';
1922
- mask.style.bottom = '0';
1923
- mask.style.left = '0';
1924
- mask.style.right = '0';
1925
- mask.style.backgroundColor = 'rgba(0,0,0,0.8)';
1926
- mask.style.zIndex = '2147483646';
1927
- el.before(mask);
1928
- el.setAttribute('data-focussed', '1');
1929
- el.setAttribute('data-focussed-orig-z-index', el.style.zIndex);
1930
- el.setAttribute('data-focussed-orig-position', el.style.position);
1931
- el.setAttribute('data-focussed-orig-background-color', el.style.backgroundColor);
1932
- el.setAttribute('data-focussed-orig-box-shadow', el.style.boxShadow);
1933
- el.style.zIndex = '2147483647';
1934
- el.style.position = 'relative';
1935
- el.style.backgroundColor = '#ffffff';
1936
- el.style.boxShadow = '0px 0px 0px 20px #fff';
1937
- }
1938
- }
1939
- static unfocus() {
1940
- if (document.querySelector('.hlp-focus-mask') !== null) {
1941
- document.querySelectorAll('.hlp-focus-mask').forEach(el => {
1942
- hlp.remove(el);
1943
- });
1944
- }
1945
- if (document.querySelector('[data-focussed]') !== null) {
1946
- document.querySelectorAll('[data-focussed]').forEach(el => {
1947
- el.style.zIndex = el.getAttribute('data-focussed-orig-z-index');
1948
- el.style.position = el.getAttribute('data-focussed-orig-position');
1949
- el.style.backgroundColor = el.getAttribute('data-focussed-orig-background-color');
1950
- el.style.boxShadow = el.getAttribute('data-focussed-orig-box-shadow');
1951
- el.removeAttribute('data-focussed');
1952
- el.removeAttribute('data-focussed-orig-z-index');
1953
- el.removeAttribute('data-focussed-orig-position');
1954
- el.removeAttribute('data-focussed-orig-background-color');
1955
- el.removeAttribute('data-focussed-orig-box-shadow');
1956
- });
1957
- }
1958
- }
1959
- static remove(el) {
1960
- if (el !== null) {
1961
- el.parentNode.removeChild(el);
1962
- }
1963
- }
1964
- static on(event, selector, scope) {
1965
- let callback = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
1966
- if (callback === null) {
1967
- callback = scope;
1968
- scope = document;
1969
- } else {
1970
- scope = document.querySelector(scope);
1971
- }
1972
- scope.addEventListener(event, e => {
1973
- var el = hlp.closest(e.target, selector);
1974
- if (el) {
1975
- callback(e, el);
1976
- }
1977
- }, false);
1978
- }
1979
- static url() {
1980
- return window.location.protocol + '//' + window.location.host + window.location.pathname;
1981
- }
1982
- static urlWithHash() {
1983
- return window.location.protocol + '//' + window.location.host + window.location.pathname + window.location.hash;
1984
- }
1985
- static fullUrl() {
1986
- return window.location.href;
1987
- }
1988
- static urlWithArgs() {
1989
- return window.location.href.split('#')[0];
1990
- }
1991
- static baseUrl() {
1992
- return window.location.protocol + '//' + window.location.host;
1993
- }
1994
- static urlProtocol() {
1995
- return window.location.protocol + '//';
1996
- }
1997
- static urlHost() {
1998
- return window.location.host;
1999
- }
2000
- static urlHostTopLevel() {
2001
- let host = window.location.host;
2002
- // ipv4
2003
- if (host.match(/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/)) {
2004
- return host;
2005
- }
2006
- host = host.split('.');
2007
- while (host.length > 2) {
2008
- host.shift();
2009
- }
2010
- host = host.join('.');
2011
- return host;
2012
- }
2013
- static urlPath() {
2014
- return window.location.pathname;
2015
- }
2016
- static urlHash() {
2017
- return window.location.hash;
2018
- }
2019
- static urlArgs() {
2020
- return window.location.search;
2021
- }
2022
- static urlOfScript() {
2023
- if (document.currentScript) {
2024
- return document.currentScript.src;
2025
- } else {
2026
- let scripts = document.getElementsByTagName('script');
2027
- return scripts[scripts.length - 1].src;
2028
- }
2029
- }
2030
- static pathOfScript() {
2031
- let script = this.urlOfScript(),
2032
- path = script.substring(0, script.lastIndexOf('/'));
2033
- return path;
2034
- }
2035
- static waitUntil(selector) {
2036
- let css_option = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
2037
- let css_value = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
2038
- return new Promise((resolve, reject) => {
2039
- let timeout = setInterval(() => {
2040
- if (document.querySelector(selector) !== null && (css_option === null || css_value === null && window.getComputedStyle(document.querySelector(selector))[css_option] !== undefined && window.getComputedStyle(document.querySelector(selector))[css_option] != '' || css_value !== null && window.getComputedStyle(document.querySelector(selector))[css_option] === css_value)) {
2041
- window.clearInterval(timeout);
2042
- resolve();
2043
- }
2044
- }, 30);
2045
- });
2046
- }
2047
- static waitUntilEach(selector, callback) {
2048
- let observer = new MutationObserver(() => {
2049
- let elements = document.querySelectorAll(selector);
2050
- if (elements.length > 0) {
2051
- elements.forEach(element => {
2052
- if (!element.__processed) {
2053
- element.__processed = true;
2054
- callback(element);
2055
- }
2056
- });
2057
- }
2058
- });
2059
- observer.observe(document.body, {
2060
- childList: true,
2061
- subtree: true
2062
- });
2063
- let initialElements = document.querySelectorAll(selector);
2064
- if (initialElements.length > 0) {
2065
- initialElements.forEach(element => {
2066
- if (!element.__processed) {
2067
- element.__processed = true;
2068
- callback(element);
2069
- }
2070
- });
2071
- }
2072
- }
2073
- static waitUntilVar() {
2074
- let arg1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
2075
- let arg2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
2076
- let value = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
2077
- let varName = null,
2078
- parentContainer = null;
2079
- if (arg2 === null) {
2080
- varName = arg1;
2081
- parentContainer = window;
2082
- } else {
2083
- varName = arg2;
2084
- parentContainer = arg1;
2085
- }
2086
- return new Promise((resolve, reject) => {
2087
- let timeout = setInterval(() => {
2088
- if (parentContainer[varName] !== undefined && parentContainer[varName] !== null) {
2089
- if (value === null || parentContainer[varName] === value) {
2090
- window.clearInterval(timeout);
2091
- resolve();
2092
- }
2093
- }
2094
- }, 30);
2095
- });
2096
- }
2097
- static ready() {
2098
- return new Promise(resolve => {
2099
- if (document.readyState !== 'loading') {
2100
- return resolve();
2101
- } else {
2102
- document.addEventListener('DOMContentLoaded', () => {
2103
- return resolve();
2104
- });
2105
- }
2106
- });
2107
- }
2108
- static load() {
2109
- return new Promise(resolve => {
2110
- if (document.readyState === 'complete') {
2111
- return resolve();
2112
- } else {
2113
- window.addEventListener('load', () => {
2114
- return resolve();
2115
- });
2116
- }
2117
- });
2118
- }
2119
- static runForEl(selector, callback) {
2120
- hlp.ready().then(() => {
2121
- // add unique id
2122
- let id = hlp.pushId();
2123
-
2124
- // also run for existing
2125
- if (document.querySelector(selector) !== null) {
2126
- document.querySelectorAll(selector).forEach(el => {
2127
- if (el.runForEl === undefined) {
2128
- el.runForEl = [];
2129
- }
2130
- if (!el.runForEl.includes(id)) {
2131
- el.runForEl.push(id);
2132
- callback(el);
2133
- }
2134
- });
2135
- }
2136
- // setup queue
2137
- if (window.runForEl_queue === undefined) {
2138
- window.runForEl_queue = [];
2139
- }
2140
- // setup observer
2141
- if (window.runForEl_observer === undefined) {
2142
- window.runForEl_observer = new MutationObserver(mutations => {
2143
- mutations.forEach(mutations__value => {
2144
- if (!mutations__value.addedNodes) {
2145
- return;
2146
- }
2147
- for (let i = 0; i < mutations__value.addedNodes.length; i++) {
2148
- let node = mutations__value.addedNodes[i];
2149
- if (node.nodeType === Node.ELEMENT_NODE) {
2150
- window.runForEl_queue.forEach(queue__value => {
2151
- if (node.matches(queue__value.selector)) {
2152
- if (node.runForEl === undefined) {
2153
- node.runForEl = [];
2154
- }
2155
- if (!node.runForEl.includes(queue__value.id)) {
2156
- node.runForEl.push(queue__value.id);
2157
- queue__value.callback(node);
2158
- }
2159
- }
2160
- // if you modify lots of html (e.g. with innerHTML), also check childs
2161
- if (node.querySelector(queue__value.selector) !== null) {
2162
- node.querySelectorAll(queue__value.selector).forEach(nodes__value => {
2163
- if (nodes__value.runForEl === undefined) {
2164
- nodes__value.runForEl = [];
2165
- }
2166
- if (!nodes__value.runForEl.includes(queue__value.id)) {
2167
- nodes__value.runForEl.push(queue__value.id);
2168
- queue__value.callback(nodes__value);
2169
- }
2170
- });
2171
- }
2172
- });
2173
- }
2174
- }
2175
- });
2176
- }).observe(document.body, {
2177
- attributes: false,
2178
- childList: true,
2179
- characterData: false,
2180
- subtree: true,
2181
- attributeOldValue: false,
2182
- characterDataOldValue: false
2183
- });
2184
- }
2185
- // push to queue
2186
- window.runForEl_queue.push({
2187
- id: id,
2188
- selector: selector,
2189
- callback: callback
2190
- });
2191
- });
2192
- }
2193
- static fmath(op, x, y) {
2194
- let precision = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 8;
2195
- let n = {
2196
- '*': x * y,
2197
- '-': x - y,
2198
- '+': x + y,
2199
- '/': x / y
2200
- }[op];
2201
- return Math.round(n * 10 * Math.pow(10, precision)) / (10 * Math.pow(10, precision));
2202
- }
2203
- static trim(str) {
2204
- let charlist = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
2205
- let whitespace = [' ', '\n', '\r', '\t', '\f', '\x0b', '\xa0', '\u2000', '\u2001', '\u2002', '\u2003', '\u2004', '\u2005', '\u2006', '\u2007', '\u2008', '\u2009', '\u200a', '\u200b', '\u2028', '\u2029', '\u3000'].join('');
2206
- let l = 0;
2207
- let i = 0;
2208
- str += '';
2209
- if (charlist) {
2210
- whitespace = (charlist + '').replace(/([[\]().?/*{}+$^:])/g, '$1');
2211
- }
2212
- l = str.length;
2213
- for (i = 0; i < l; i++) {
2214
- if (whitespace.indexOf(str.charAt(i)) === -1) {
2215
- str = str.substring(i);
2216
- break;
2217
- }
2218
- }
2219
- l = str.length;
2220
- for (i = l - 1; i >= 0; i--) {
2221
- if (whitespace.indexOf(str.charAt(i)) === -1) {
2222
- str = str.substring(0, i + 1);
2223
- break;
2224
- }
2225
- }
2226
- return whitespace.indexOf(str.charAt(0)) === -1 ? str : '';
2227
- }
2228
- static ltrim(str) {
2229
- let charlist = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
2230
- charlist = !charlist ? ' \\s\u00A0' : (charlist + '').replace(/([[\]().?/*{}+$^:])/g, '$1');
2231
- const re = new RegExp('^[' + charlist + ']+', 'g');
2232
- return (str + '').replace(re, '');
2233
- }
2234
- static rtrim(str) {
2235
- let charlist = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
2236
- charlist = !charlist ? ' \\s\u00A0' : (charlist + '').replace(/([[\]().?/*{}+$^:])/g, '\\$1');
2237
- const re = new RegExp('[' + charlist + ']+$', 'g');
2238
- return (str + '').replace(re, '');
2239
- }
2240
- static truncate_string(str) {
2241
- let len = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 50;
2242
- let chars = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '...';
2243
- if (this.nx(str) || !(typeof str === 'string' || str instanceof String)) {
2244
- return str;
2245
- }
2246
- if (str.indexOf(' ') === -1) {
2247
- if (str.length > len) {
2248
- str = str.substring(0, len);
2249
- str = hlp.rtrim(str);
2250
- str += ' ' + chars;
2251
- }
2252
- } else {
2253
- if (str.length > len) {
2254
- str = hlp.rtrim(str);
2255
- // cut of whole word
2256
- while (str.length > len && str.lastIndexOf(' ') > -1 && str.substring(len - 1, len) != ' ') {
2257
- str = str.substring(0, str.lastIndexOf(' '));
2258
- str = hlp.rtrim(str);
2259
- }
2260
- str = str.substring(0, len);
2261
- str = hlp.rtrim(str);
2262
- str += ' ' + chars;
2263
- }
2264
- }
2265
- return str;
2266
- }
2267
- static emojiRegex() {
2268
- let global = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
2269
- return new RegExp(hlp.emojiRegexPattern(), (global === true ? 'g' : '') + 'u');
2270
- }
2271
- static emojiRegexPattern() {
2272
- return String.raw(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["p{RI}p{RI}|p{Extended_Pictographic}(p{EMod}|\uFE0F\u20E3?|[\uDB40\uDC20-\uDB40\uDC7E]+\uDB40\uDC7F)?(\u200D(p{RI}p{RI}|p{Extended_Pictographic}(p{EMod}|\uFE0F\u20E3?|[\uDB40\uDC20-\uDB40\uDC7E]+\uDB40\uDC7F)?))*"], ["\\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})?))*"])));
2273
- }
2274
- static emojiSplit(str) {
2275
- if (!(typeof str === 'string' || str instanceof String)) {
2276
- return str;
2277
- }
2278
- return [...new Intl.Segmenter().segment(str)].map(x => x.segment);
2279
- }
2280
- static serialize(mixedValue) {
2281
- let val, key, okey;
2282
- let ktype = '';
2283
- let vals = '';
2284
- let count = 0;
2285
- const _utf8Size = function (str) {
2286
- return ~-encodeURI(str).split(/%..|./).length;
2287
- };
2288
- const _getType = function (inp) {
2289
- let match;
2290
- let key;
2291
- let cons;
2292
- let types;
2293
- let type = typeof inp;
2294
- if (type === 'object' && !inp) {
2295
- return 'null';
2296
- }
2297
- if (type === 'object') {
2298
- if (!inp.constructor) {
2299
- return 'object';
2300
- }
2301
- cons = inp.constructor.toString();
2302
- match = cons.match(/(\w+)\(/);
2303
- if (match) {
2304
- cons = match[1].toLowerCase();
2305
- }
2306
- types = ['boolean', 'number', 'string', 'array'];
2307
- for (key in types) {
2308
- if (cons === types[key]) {
2309
- type = types[key];
2310
- break;
2311
- }
2312
- }
2313
- }
2314
- return type;
2315
- };
2316
- const type = _getType(mixedValue);
2317
- switch (type) {
2318
- case 'function':
2319
- val = '';
2320
- break;
2321
- case 'boolean':
2322
- val = 'b:' + (mixedValue ? '1' : '0');
2323
- break;
2324
- case 'number':
2325
- val = (Math.round(mixedValue) === mixedValue ? 'i' : 'd') + ':' + mixedValue;
2326
- break;
2327
- case 'string':
2328
- val = 's:' + _utf8Size(mixedValue) + ':"' + mixedValue + '"';
2329
- break;
2330
- case 'array':
2331
- case 'object':
2332
- val = 'a';
2333
- for (key in mixedValue) {
2334
- if (mixedValue.hasOwnProperty(key)) {
2335
- ktype = _getType(mixedValue[key]);
2336
- if (ktype === 'function') {
2337
- continue;
2338
- }
2339
- okey = key.match(/^[0-9]+$/) ? parseInt(key, 10) : key;
2340
- vals += this.serialize(okey) + this.serialize(mixedValue[key]);
2341
- count++;
2342
- }
2343
- }
2344
- val += ':' + count + ':{' + vals + '}';
2345
- break;
2346
- case 'undefined':
2347
- default:
2348
- val = 'N';
2349
- break;
2350
- }
2351
- if (type !== 'object' && type !== 'array') {
2352
- val += ';';
2353
- }
2354
- return val;
2355
- }
2356
- static unserialize(str) {
2357
- try {
2358
- if (typeof str !== 'string') {
2359
- return false;
2360
- }
2361
- const store = [];
2362
- const cache = value => {
2363
- store.push(value[0]);
2364
- return value;
2365
- };
2366
- cache.get = index => {
2367
- if (index >= store.length) {
2368
- throw RangeError("Can't resolve reference ".concat(index + 1));
2369
- }
2370
- return store[index];
2371
- };
2372
- const expectType = s => {
2373
- const types = /^(?:N(?=;)|[bidsSaOCrR](?=:)|[^:]+(?=:))/g;
2374
- const type = (types.exec(s) || [])[0];
2375
- if (!type) throw SyntaxError('Invalid input: ' + s);
2376
- switch (type) {
2377
- case 'N':
2378
- return cache([null, 2]);
2379
- case 'b':
2380
- return cache(expectBool(s));
2381
- case 'i':
2382
- return cache(expectInt(s));
2383
- case 'd':
2384
- return cache(expectFloat(s));
2385
- case 's':
2386
- return cache(expectString(s));
2387
- case 'S':
2388
- return cache(expectEscapedString(s));
2389
- case 'a':
2390
- return expectArray(s);
2391
- case 'O':
2392
- return expectObject(s);
2393
- case 'C':
2394
- throw Error('Not yet implemented');
2395
- case 'r':
2396
- case 'R':
2397
- return expectReference(s);
2398
- default:
2399
- throw SyntaxError("Invalid or unsupported data type: ".concat(type));
2400
- }
2401
- };
2402
- const expectBool = s => {
2403
- const reBool = /^b:([01]);/;
2404
- const _ref13 = reBool.exec(s) || [],
2405
- _ref14 = (0, _slicedToArray2.default)(_ref13, 2),
2406
- match = _ref14[0],
2407
- boolMatch = _ref14[1];
2408
- if (!boolMatch) throw SyntaxError('Invalid bool value, expected 0 or 1');
2409
- return [boolMatch === '1', match.length];
2410
- };
2411
- const expectInt = s => {
2412
- const reInt = /^i:([+-]?\d+);/;
2413
- const _ref15 = reInt.exec(s) || [],
2414
- _ref16 = (0, _slicedToArray2.default)(_ref15, 2),
2415
- match = _ref16[0],
2416
- intMatch = _ref16[1];
2417
- if (!intMatch) throw SyntaxError('Expected an integer value');
2418
- return [parseInt(intMatch, 10), match.length];
2419
- };
2420
- const expectFloat = s => {
2421
- const reFloat = /^d:(NAN|-?INF|(?:\d+\.\d*|\d*\.\d+|\d+)(?:[eE][+-]\d+)?);/;
2422
- const _ref17 = reFloat.exec(s) || [],
2423
- _ref18 = (0, _slicedToArray2.default)(_ref17, 2),
2424
- match = _ref18[0],
2425
- floatMatch = _ref18[1];
2426
- if (!floatMatch) throw SyntaxError('Expected a float value');
2427
- return [floatMatch === 'NAN' ? Number.NaN : floatMatch === '-INF' ? Number.NEGATIVE_INFINITY : floatMatch === 'INF' ? Number.POSITIVE_INFINITY : parseFloat(floatMatch), match.length];
2428
- };
2429
- const expectString = s => {
2430
- const reStrLength = /^s:(\d+):"/g;
2431
- const _ref19 = reStrLength.exec(s) || [],
2432
- _ref20 = (0, _slicedToArray2.default)(_ref19, 2),
2433
- match = _ref20[0],
2434
- byteLenMatch = _ref20[1];
2435
- if (!match) throw SyntaxError('Expected a string value');
2436
- const len = parseInt(byteLenMatch, 10);
2437
- s = s.substr(match.length);
2438
- const strMatch = s.substr(0, len);
2439
- s = s.substr(len);
2440
- if (!s.startsWith('";')) throw SyntaxError('Expected ";');
2441
- return [strMatch, match.length + len + 2];
2442
- };
2443
- const expectEscapedString = s => {
2444
- const reStrLength = /^S:(\d+):"/g;
2445
- const _ref21 = reStrLength.exec(s) || [],
2446
- _ref22 = (0, _slicedToArray2.default)(_ref21, 2),
2447
- match = _ref22[0],
2448
- strLenMatch = _ref22[1];
2449
- if (!match) throw SyntaxError('Expected an escaped string value');
2450
- const len = parseInt(strLenMatch, 10);
2451
- s = s.substr(match.length);
2452
- const strMatch = s.substr(0, len);
2453
- s = s.substr(len);
2454
- if (!s.startsWith('";')) throw SyntaxError('Expected ";');
2455
- return [strMatch, match.length + len + 2];
2456
- };
2457
- const expectReference = s => {
2458
- const reRef = /^[rR]:(\d+);/;
2459
- const _ref23 = reRef.exec(s) || [],
2460
- _ref24 = (0, _slicedToArray2.default)(_ref23, 2),
2461
- match = _ref24[0],
2462
- refIndex = _ref24[1];
2463
- if (!match) throw SyntaxError('Expected reference value');
2464
- return [cache.get(parseInt(refIndex, 10) - 1), match.length];
2465
- };
2466
- const expectArray = s => {
2467
- const reArrayLength = /^a:(\d+):\{/;
2468
- const _ref25 = reArrayLength.exec(s) || [],
2469
- _ref26 = (0, _slicedToArray2.default)(_ref25, 2),
2470
- arrayLiteralBeginMatch = _ref26[0],
2471
- arrayLengthMatch = _ref26[1];
2472
- if (!arrayLengthMatch) throw SyntaxError('Expected array length annotation');
2473
- s = s.substr(arrayLiteralBeginMatch.length);
2474
- const items = {};
2475
- cache([items]);
2476
- for (let i = 0; i < parseInt(arrayLengthMatch, 10); i++) {
2477
- const key = expectType(s);
2478
- s = s.substr(key[1]);
2479
- const value = expectType(s);
2480
- s = s.substr(value[1]);
2481
- items[key[0]] = value[0];
2482
- }
2483
- if (s.charAt(0) !== '}') throw SyntaxError('Expected }');
2484
- return [items, arrayLiteralBeginMatch.length + 1];
2485
- };
2486
- const expectObject = s => {
2487
- const reObjectLiteral = /^O:(\d+):"([^\"]+)":(\d+):\{/;
2488
- const _ref27 = reObjectLiteral.exec(s) || [],
2489
- _ref28 = (0, _slicedToArray2.default)(_ref27, 4),
2490
- match = _ref28[0],
2491
- className = _ref28[2],
2492
- propCountMatch = _ref28[3];
2493
- if (!match) throw SyntaxError('Invalid input');
2494
- if (className !== 'stdClass') throw SyntaxError("Unsupported object type: ".concat(className));
2495
- let obj = {};
2496
- cache([obj]);
2497
- s = s.substr(match.length);
2498
- for (let i = 0; i < parseInt(propCountMatch, 10); i++) {
2499
- const prop = expectType(s);
2500
- s = s.substr(prop[1]);
2501
- const value = expectType(s);
2502
- s = s.substr(value[1]);
2503
- obj[prop[0]] = value[0];
2504
- }
2505
- if (s.charAt(0) !== '}') throw SyntaxError('Expected }');
2506
- return [obj, match.length + 1];
2507
- };
2508
- return expectType(str)[0];
2509
- } catch (err) {
2510
- console.error(err);
2511
- return false;
2512
- }
2513
- }
2514
- static pushId() {
2515
- /* source https://gist.github.com/mikelehen/3596a30bd69384624c11 */
2516
- let pushIdData = null;
2517
- // browser
2518
- if (window !== undefined) {
2519
- if (window.pushIdDataGlobal === undefined) {
2520
- window.pushIdDataGlobal = {};
2521
- }
2522
- pushIdData = window.pushIdDataGlobal;
2523
- }
2524
- // node.js
2525
- if (typeof global !== 'undefined') {
2526
- if (global.pushIdDataGlobal === undefined) {
2527
- global.pushIdDataGlobal = {};
2528
- }
2529
- pushIdData = global.pushIdDataGlobal;
2530
- }
2531
- // first run
2532
- if (hlp.objectsAreEqual(pushIdData, {})) {
2533
- pushIdData.lastPushTime = 0;
2534
- pushIdData.lastRandChars = [];
2535
- pushIdData.PUSH_CHARS = '-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz';
2536
- }
2537
- let now = new Date().getTime(),
2538
- duplicateTime = now === pushIdData.lastPushTime;
2539
- pushIdData.lastPushTime = now;
2540
- let timeStampChars = new Array(8);
2541
- for (var i = 7; i >= 0; i--) {
2542
- timeStampChars[i] = pushIdData.PUSH_CHARS.charAt(now % 64);
2543
- now = Math.floor(now / 64);
2544
- }
2545
- if (now !== 0) {
2546
- throw new Error();
2547
- }
2548
- let id = timeStampChars.join('');
2549
- if (!duplicateTime) {
2550
- for (i = 0; i < 12; i++) {
2551
- pushIdData.lastRandChars[i] = Math.floor(Math.random() * 64);
2552
- }
2553
- } else {
2554
- for (i = 11; i >= 0 && pushIdData.lastRandChars[i] === 63; i--) {
2555
- pushIdData.lastRandChars[i] = 0;
2556
- }
2557
- pushIdData.lastRandChars[i]++;
2558
- }
2559
- for (i = 0; i < 12; i++) {
2560
- id += pushIdData.PUSH_CHARS.charAt(pushIdData.lastRandChars[i]);
2561
- }
2562
- if (id.length != 20) {
2563
- throw new Error();
2564
- }
2565
- return id;
2566
- }
2567
- static getProp(obj, desc) {
2568
- let arr = desc.split('.');
2569
- while (arr.length && (obj = obj[arr.shift()]));
2570
- return obj;
2571
- }
2572
- static base64toblob(base64) {
2573
- let contentType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
2574
- let sliceSize = 512,
2575
- byteCharacters = atob(base64),
2576
- byteArrays = [];
2577
- for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
2578
- let slice = byteCharacters.slice(offset, offset + sliceSize),
2579
- byteNumbers = new Array(slice.length);
2580
- for (let i = 0; i < slice.length; i++) {
2581
- byteNumbers[i] = slice.charCodeAt(i);
2582
- }
2583
- let byteArray = new Uint8Array(byteNumbers);
2584
- byteArrays.push(byteArray);
2585
- }
2586
- let blob = new Blob(byteArrays, {
2587
- type: contentType
2588
- });
2589
- return blob;
2590
- }
2591
- static blobtobase64(blob) {
2592
- return new Promise(resolve => {
2593
- let reader = new FileReader();
2594
- reader.onload = () => {
2595
- var dataUrl = reader.result;
2596
- var base64 = dataUrl.split(',')[1];
2597
- resolve(base64);
2598
- };
2599
- reader.readAsDataURL(blob);
2600
- });
2601
- }
2602
- static stringtoblob(string) {
2603
- let contentType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
2604
- let blob = new Blob([string], {
2605
- type: contentType
2606
- });
2607
- return blob;
2608
- }
2609
- static blobtostring(blob) {
2610
- return new Promise(resolve => {
2611
- let reader = new FileReader();
2612
- reader.onload = () => {
2613
- resolve(reader.result);
2614
- };
2615
- reader.readAsText(blob);
2616
- });
2617
- }
2618
- static filetobase64(file) {
2619
- return new Promise((resolve, reject) => {
2620
- const reader = new FileReader();
2621
- reader.readAsDataURL(file);
2622
- reader.onload = () => resolve(reader.result.split(',')[1]);
2623
- reader.onerror = error => reject(error);
2624
- });
2625
- }
2626
- static blobtofile(blob) {
2627
- let filename = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'file.txt';
2628
- let file = null;
2629
- try {
2630
- file = new File([blob], filename);
2631
- } catch (_unused) {
2632
- // ie 11
2633
- file = new Blob([blob], filename);
2634
- }
2635
- return file;
2636
- }
2637
- static filetoblob(file) {
2638
- return new Blob([file]);
2639
- }
2640
- static base64tofile(base64) {
2641
- let contentType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
2642
- let filename = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'file.txt';
2643
- return this.blobtofile(this.base64toblob(base64, contentType), filename);
2644
- }
2645
- static blobtourl(blob) {
2646
- return URL.createObjectURL(blob);
2647
- }
2648
- static stringtourl(string) {
2649
- return this.blobtourl(this.stringtoblob(string));
2650
- }
2651
- static base64tostring(base64) {
2652
- return atob(base64);
2653
- }
2654
- static stringtobase64(string) {
2655
- return btoa(string);
2656
- }
2657
- static base64tourl(base64) {
2658
- return this.blobtourl(this.base64toblob(base64));
2659
- }
2660
- static filetourl(file) {
2661
- return this.blobtourl(this.filetoblob(file));
2662
- }
2663
- static getImageOrientation(base64) {
2664
- return new Promise((resolve, reject) => {
2665
- base64 = base64.replace('data:image/jpeg;base64,', '');
2666
- let file = this.base64tofile(base64),
2667
- reader = new FileReader();
2668
- reader.onload = e => {
2669
- var view = new DataView(e.target.result);
2670
- if (view.getUint16(0, false) != 0xffd8) {
2671
- resolve(-2);
2672
- return;
2673
- }
2674
- var length = view.byteLength,
2675
- offset = 2;
2676
- while (offset < length) {
2677
- if (view.getUint16(offset + 2, false) <= 8) {
2678
- resolve(-1);
2679
- return;
2680
- }
2681
- var marker = view.getUint16(offset, false);
2682
- offset += 2;
2683
- if (marker == 0xffe1) {
2684
- if (view.getUint32(offset += 2, false) != 0x45786966) {
2685
- resolve(-1);
2686
- return;
2687
- }
2688
- var little = view.getUint16(offset += 6, false) == 0x4949;
2689
- offset += view.getUint32(offset + 4, little);
2690
- var tags = view.getUint16(offset, little);
2691
- offset += 2;
2692
- for (var i = 0; i < tags; i++) {
2693
- if (view.getUint16(offset + i * 12, little) == 0x0112) {
2694
- resolve(view.getUint16(offset + i * 12 + 8, little));
2695
- return;
2696
- }
2697
- }
2698
- } else if ((marker & 0xff00) != 0xff00) {
2699
- break;
2700
- } else {
2701
- offset += view.getUint16(offset, false);
2702
- }
2703
- }
2704
- resolve(-1);
2705
- return;
2706
- };
2707
- reader.readAsArrayBuffer(file);
2708
- });
2709
- }
2710
- static resetImageOrientation(srcBase64, srcOrientation) {
2711
- return new Promise((resolve, reject) => {
2712
- var img = new Image();
2713
- img.onload = () => {
2714
- var width = img.width,
2715
- height = img.height,
2716
- canvas = document.createElement('canvas'),
2717
- ctx = canvas.getContext('2d');
2718
- if (4 < srcOrientation && srcOrientation < 9) {
2719
- canvas.width = height;
2720
- canvas.height = width;
2721
- } else {
2722
- canvas.width = width;
2723
- canvas.height = height;
2724
- }
2725
- switch (srcOrientation) {
2726
- case 2:
2727
- ctx.transform(-1, 0, 0, 1, width, 0);
2728
- break;
2729
- case 3:
2730
- ctx.transform(-1, 0, 0, -1, width, height);
2731
- break;
2732
- case 4:
2733
- ctx.transform(1, 0, 0, -1, 0, height);
2734
- break;
2735
- case 5:
2736
- ctx.transform(0, 1, 1, 0, 0, 0);
2737
- break;
2738
- case 6:
2739
- ctx.transform(0, 1, -1, 0, height, 0);
2740
- break;
2741
- case 7:
2742
- ctx.transform(0, -1, -1, 0, height, width);
2743
- break;
2744
- case 8:
2745
- ctx.transform(0, -1, 1, 0, 0, width);
2746
- break;
2747
- default:
2748
- break;
2749
- }
2750
- ctx.drawImage(img, 0, 0);
2751
- let base64 = canvas.toDataURL();
2752
- base64 = 'data:image/jpeg;base64,' + base64.split(',')[1];
2753
- resolve(base64);
2754
- return;
2755
- };
2756
- img.src = srcBase64;
2757
- });
2758
- }
2759
- static fixImageOrientation(base64) {
2760
- return new Promise((resolve, reject) => {
2761
- if (base64.indexOf('data:') === -1) {
2762
- resolve(base64);
2763
- return;
2764
- }
2765
- if (base64.indexOf('data:image/jpeg;base64,') === 0) {
2766
- base64 = base64.replace('data:image/jpeg;base64,', '');
2767
- }
2768
- this.getImageOrientation(base64).then(orientation => {
2769
- base64 = 'data:image/jpeg;base64,' + base64;
2770
- if (orientation <= 1) {
2771
- resolve(base64);
2772
- return;
2773
- } else {
2774
- this.resetImageOrientation(base64, orientation).then(base64_new => {
2775
- resolve(base64_new);
2776
- return;
2777
- });
2778
- }
2779
- });
2780
- });
2781
- }
2782
- static debounce(func, wait, immediate) {
2783
- var timeout;
2784
- return function () {
2785
- var context = this,
2786
- args = arguments;
2787
- var later = function () {
2788
- timeout = null;
2789
- if (!immediate) func.apply(context, args);
2790
- };
2791
- var callNow = immediate && !timeout;
2792
- clearTimeout(timeout);
2793
- timeout = setTimeout(later, wait);
2794
- if (callNow) func.apply(context, args);
2795
- };
2796
- }
2797
- static throttle(func, wait, options) {
2798
- var context, args, result;
2799
- var timeout = null;
2800
- var previous = 0;
2801
- if (!options) options = {};
2802
- var later = function () {
2803
- previous = options.leading === false ? 0 : Date.now();
2804
- timeout = null;
2805
- result = func.apply(context, args);
2806
- if (!timeout) context = args = null;
2807
- };
2808
- return function () {
2809
- var now = Date.now();
2810
- if (!previous && options.leading === false) previous = now;
2811
- var remaining = wait - (now - previous);
2812
- context = this;
2813
- args = arguments;
2814
- if (remaining <= 0 || remaining > wait) {
2815
- if (timeout) {
2816
- clearTimeout(timeout);
2817
- timeout = null;
2818
- }
2819
- previous = now;
2820
- result = func.apply(context, args);
2821
- if (!timeout) context = args = null;
2822
- } else if (!timeout && options.trailing !== false) {
2823
- timeout = setTimeout(later, remaining);
2824
- }
2825
- return result;
2826
- };
2827
- }
2828
- static shuffle(array) {
2829
- let currentIndex = array.length,
2830
- temporaryValue,
2831
- randomIndex;
2832
- while (0 !== currentIndex) {
2833
- randomIndex = Math.floor(Math.random() * currentIndex);
2834
- currentIndex -= 1;
2835
- temporaryValue = array[currentIndex];
2836
- array[currentIndex] = array[randomIndex];
2837
- array[randomIndex] = temporaryValue;
2838
- }
2839
- return array;
2840
- }
2841
- static findRecursiveInObject(object) {
2842
- let key = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
2843
- let value = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
2844
- let path = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
2845
- let paths = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
2846
- if (object !== null && typeof object === 'object') {
2847
- for (const _ref29 of Object.entries(object)) {
2848
- var _ref30 = (0, _slicedToArray2.default)(_ref29, 2);
2849
- const object__key = _ref30[0];
2850
- const object__value = _ref30[1];
2851
- if (object__value !== null && typeof object__value === 'object') {
2852
- this.findRecursiveInObject(object__value, key, value, (path === '' ? '' : path + '.') + object__key, paths);
2853
- } else if ((key === null || object__key === key) && (value === null || object__value === value)) {
2854
- paths.push(path);
2855
- break; // only take first
2856
- }
2857
- }
2858
- }
2859
- return paths;
2860
- }
817
+ </style>
818
+ `);
819
+ window.cursorPositionDelay = 50;
820
+ window.cursorPositionQuads = [];
821
+ let dim = 10;
822
+ let createQuad = (_, pos) => {
823
+ let a = document.createElement("a");
824
+ a.classList.add("find-pointer-quad");
825
+ let { style } = a;
826
+ style.top = pos < 2 ? "0" : `${dim}%`;
827
+ style.left = pos % 2 === 0 ? "0" : `${dim}%`;
828
+ style.width = style.height = `${dim}%`;
829
+ document.body.appendChild(a);
830
+ return a;
831
+ };
832
+ window.cursorPositionQuads = [
833
+ 1,
834
+ 2,
835
+ 3,
836
+ 4
837
+ ].map(createQuad);
838
+ return this.cursorPositionBisect(dim);
839
+ }
840
+ static cursorPositionBisect(dim) {
841
+ let hit;
842
+ window.cursorPositionQuads.some((a) => {
843
+ let style = getComputedStyle(a);
844
+ if (style.getPropertyValue(`--hit`) === `1`) return hit = {
845
+ style,
846
+ a
847
+ };
848
+ });
849
+ if (!hit) {
850
+ let [q1] = window.cursorPositionQuads;
851
+ let reset = Math.abs(dim) > 1e4;
852
+ let top = parseFloat(q1.style.top) - dim / 2;
853
+ let left = parseFloat(q1.style.left) - dim / 2;
854
+ window.cursorPositionQuads.forEach(({ style }, pos) => {
855
+ if (reset) {
856
+ style.top = pos < 2 ? "0" : `${dim}%`;
857
+ style.left = pos % 2 === 0 ? "0" : `${dim}%`;
858
+ style.width = style.height = `${dim}%`;
859
+ } else {
860
+ style.top = pos < 2 ? `${top}%` : `${top + dim}%`;
861
+ style.left = pos % 2 === 0 ? `${left}%` : `${left + dim}%`;
862
+ style.width = `${dim}%`;
863
+ style.height = `${dim}%`;
864
+ }
865
+ });
866
+ return new Promise((resolve) => {
867
+ setTimeout(() => resolve(this.cursorPositionBisect(!reset ? 2 * dim : dim)), window.cursorPositionDelay);
868
+ });
869
+ }
870
+ let { style, a } = hit;
871
+ let { top, left, width, height } = a.getBoundingClientRect();
872
+ if (width < 3) {
873
+ window.cursorPositionQuads.forEach((a) => a.remove());
874
+ return {
875
+ x: Math.round(left + width / 2 + window.scrollX),
876
+ y: Math.round(top + height / 2 + window.scrollY)
877
+ };
878
+ }
879
+ let ox = a.style.left;
880
+ let oy = a.style.top;
881
+ let nextStep = dim / 2;
882
+ window.cursorPositionQuads.forEach(({ style }, pos) => {
883
+ style.top = pos < 2 ? oy : `${nextStep + parseFloat(oy)}%`;
884
+ style.left = pos % 2 === 0 ? ox : `${nextStep + parseFloat(ox)}%`;
885
+ style.width = `${nextStep}%`;
886
+ style.height = `${nextStep}%`;
887
+ });
888
+ return new Promise((resolve) => {
889
+ setTimeout(() => resolve(this.cursorPositionBisect(nextStep)), window.cursorPositionDelay);
890
+ });
891
+ }
892
+ static scrollTo(to, duration = 1e3, element = null, offset = 0, only_up = false) {
893
+ return new Promise((resolve) => {
894
+ if (element === null) element = document.scrollingElement || document.documentElement;
895
+ if (!hlp.isNumeric(to)) if (element === (document.scrollingElement || document.documentElement)) to = this.offsetTopWithMargin(to);
896
+ else to = to.getBoundingClientRect().top - parseInt(getComputedStyle(to).marginTop) - (element.getBoundingClientRect().top - element.scrollTop - parseInt(getComputedStyle(element).marginTop));
897
+ let offset_calc = 0;
898
+ let offsetArr = offset;
899
+ if (!Array.isArray(offsetArr)) offsetArr = [offsetArr];
900
+ offsetArr.forEach((offset__value) => {
901
+ if (hlp.isNumeric(offset__value)) offset_calc += offset__value;
902
+ else if (offset__value !== null) {
903
+ if (window.getComputedStyle(offset__value).position === "fixed") offset_calc += -1 * offset__value.offsetHeight;
904
+ }
905
+ });
906
+ to += offset_calc;
907
+ const start = element.scrollTop, change = to - start, startDate = +/* @__PURE__ */ new Date(), easeInOutCirc = function(t, b, c, d) {
908
+ t /= d / 2;
909
+ if (t < 1) return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b;
910
+ t -= 2;
911
+ return c / 2 * (Math.sqrt(1 - t * t) + 1) + b;
912
+ }, animateScroll = function() {
913
+ const currentTime = +/* @__PURE__ */ new Date() - startDate;
914
+ element.scrollTop = parseInt(easeInOutCirc(currentTime, start, change, duration));
915
+ if (currentTime < duration) requestAnimationFrame(animateScroll);
916
+ else {
917
+ element.scrollTop = to;
918
+ resolve();
919
+ }
920
+ };
921
+ if (only_up === true && change > 0) {
922
+ resolve();
923
+ return;
924
+ }
925
+ animateScroll();
926
+ });
927
+ }
928
+ static loadJs(urls) {
929
+ if (!hlp.isArray(urls)) urls = [urls];
930
+ let promises = [];
931
+ hlp.loop(urls, (urls__value, urls__key) => {
932
+ promises.push(new Promise((resolve, reject) => {
933
+ let script = document.createElement("script");
934
+ script.src = urls__value;
935
+ script.onload = () => {
936
+ resolve();
937
+ };
938
+ document.head.appendChild(script);
939
+ }));
940
+ });
941
+ return Promise.all(promises);
942
+ }
943
+ static async loadJsSequentially(urls) {
944
+ if (!hlp.isArray(urls)) urls = [urls];
945
+ for (let urls__value of urls) await hlp.loadJs(urls__value);
946
+ }
947
+ static triggerAfterAllImagesLoaded(selectorContainer, selectorImage, fn) {
948
+ window.addEventListener("load", (e) => {
949
+ if (document.querySelector(selectorContainer + " " + selectorImage) !== null) document.querySelectorAll(selectorContainer + " " + selectorImage).forEach((el) => {
950
+ this.triggerAfterAllImagesLoadedBindLoadEvent(el, selectorContainer, selectorImage, fn);
951
+ });
952
+ });
953
+ document.addEventListener("DOMContentLoaded", () => {
954
+ if (document.querySelector(selectorContainer) !== null) new MutationObserver((mutations) => {
955
+ mutations.forEach((mutation) => {
956
+ if (mutation.type === "childList" && mutation.addedNodes.length > 0) mutation.addedNodes.forEach((el) => {
957
+ this.triggerAfterAllImagesLoadedHandleEl(el, selectorContainer, selectorImage, fn);
958
+ });
959
+ 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);
960
+ });
961
+ }).observe(document.querySelector(selectorContainer), {
962
+ attributes: true,
963
+ childList: true,
964
+ characterData: false,
965
+ subtree: true,
966
+ attributeOldValue: true,
967
+ characterDataOldValue: false
968
+ });
969
+ });
970
+ }
971
+ static triggerAfterAllImagesLoadedHandleEl(el, selectorContainer, selectorImage, fn) {
972
+ if (el.nodeType === Node.ELEMENT_NODE) {
973
+ el.classList.remove("loaded-img");
974
+ el.closest(selectorContainer).classList.remove("loaded-all");
975
+ if (!el.classList.contains("binded-trigger")) {
976
+ el.classList.add("binded-trigger");
977
+ el.addEventListener("load", () => {
978
+ this.triggerAfterAllImagesLoadedBindLoadEvent(el, selectorContainer, selectorImage, fn);
979
+ });
980
+ }
981
+ }
982
+ }
983
+ static triggerAfterAllImagesLoadedBindLoadEvent(el, selectorContainer, selectorImage, fn) {
984
+ el.classList.add("loaded-img");
985
+ if (el.closest(selectorContainer).querySelectorAll(".loaded-img").length === el.closest(selectorContainer).querySelectorAll(selectorImage).length) {
986
+ el.closest(selectorContainer).classList.add("loaded-all");
987
+ fn();
988
+ }
989
+ }
990
+ static isVisible(el) {
991
+ return !!(el.offsetWidth || el.offsetHeight || el.getClientRects().length);
992
+ }
993
+ static isVisibleInViewport(el) {
994
+ if (!this.isVisible(el)) return false;
995
+ let rect = el.getBoundingClientRect();
996
+ return !(rect.bottom < 0 || rect.right < 0 || rect.left > window.innerWidth || rect.top > window.innerHeight);
997
+ }
998
+ static textareaAutoHeight(selector = "textarea") {
999
+ this.textareaSetHeights(selector);
1000
+ this.onResizeHorizontal(() => {
1001
+ this.textareaSetHeights(selector);
1002
+ });
1003
+ [].forEach.call(document.querySelectorAll(selector), (el) => {
1004
+ el.addEventListener("keyup", (e) => {
1005
+ this.textareaSetHeight(e.target);
1006
+ });
1007
+ });
1008
+ }
1009
+ static textareaSetHeights(selector = "textarea") {
1010
+ [].forEach.call(document.querySelectorAll(selector), (el) => {
1011
+ if (this.isVisible(el)) this.textareaSetHeight(el);
1012
+ });
1013
+ }
1014
+ static textareaSetHeight(el) {
1015
+ el.style.height = "5px";
1016
+ el.style.height = el.scrollHeight + "px";
1017
+ }
1018
+ static real100vh(selector = null, percent = 100) {
1019
+ if (selector === null) {
1020
+ let fn = () => {
1021
+ let vh = window.innerHeight * .01;
1022
+ document.documentElement.style.setProperty("--vh", `${vh}px`);
1023
+ };
1024
+ fn();
1025
+ window.addEventListener("resize", () => {
1026
+ fn();
1027
+ });
1028
+ } else {
1029
+ let fn = () => {
1030
+ console.log(selector);
1031
+ if (document.querySelector(selector) !== null) document.querySelectorAll(selector).forEach((selector__value) => {
1032
+ selector__value.style.height = window.innerHeight * (percent / 100) + "px";
1033
+ });
1034
+ };
1035
+ fn();
1036
+ window.addEventListener("resize", () => {
1037
+ fn();
1038
+ });
1039
+ }
1040
+ }
1041
+ static iOsRemoveHover() {
1042
+ if (hlp.getBrowser() === "safari" && hlp.getDevice() !== "desktop") hlp.on("touchend", "a", (e, el) => {
1043
+ el.click();
1044
+ });
1045
+ }
1046
+ static isNumeric(n) {
1047
+ return !isNaN(parseFloat(n)) && isFinite(n);
1048
+ }
1049
+ static animate(el, from, to, easing, duration) {
1050
+ return new Promise((resolve) => {
1051
+ if (duration <= 50) duration = 50;
1052
+ let properties = [];
1053
+ from.split(";").forEach((from__value) => {
1054
+ properties.push(from__value.split(":")[0].trim());
1055
+ });
1056
+ let transitionArr = [];
1057
+ properties.forEach((properties__value) => {
1058
+ transitionArr.push(properties__value + " " + Math.round(duration / 1e3 * 10) / 10 + "s " + easing);
1059
+ });
1060
+ let transition = "transition: " + transitionArr.join(", ") + " !important;";
1061
+ let els = null;
1062
+ if (NodeList.prototype.isPrototypeOf(el)) els = Array.from(el);
1063
+ else if (el === null) {
1064
+ console.log("cannot animate element from " + from + " to " + to + " because it does not exist");
1065
+ resolve();
1066
+ } else els = [el];
1067
+ let toFinish = els.length;
1068
+ els.forEach((els__value, els__key) => {
1069
+ let random_class = hlp.random_string(10, "abcdefghijklmnopqrstuvwxyz");
1070
+ els__value.classList.add(random_class);
1071
+ window.requestAnimationFrame(() => {
1072
+ let new_style_arr = [];
1073
+ let new_style = "";
1074
+ let prev_style = els__value.getAttribute("style");
1075
+ if (prev_style !== null) prev_style.split(";").forEach((prev_style__value) => {
1076
+ if (prev_style__value != "" && !properties.includes(prev_style__value.split(":")[0].trim())) new_style_arr.push(prev_style__value);
1077
+ });
1078
+ if (new_style_arr.length > 0) new_style = new_style_arr.join(";") + ";" + from + ";";
1079
+ else new_style = from + ";";
1080
+ els__value.setAttribute("style", new_style);
1081
+ window.requestAnimationFrame(() => {
1082
+ let style = document.createElement("style");
1083
+ style.innerHTML = "." + random_class + " { " + transition + " }";
1084
+ document.head.appendChild(style);
1085
+ window.requestAnimationFrame(() => {
1086
+ els__value.setAttribute("style", els__value.getAttribute("style").replace(from + ";", "") + to + ";");
1087
+ if (this.isVisible(els__value)) {
1088
+ let fired = false;
1089
+ hlp.addEventListenerOnce(els__value, "transitionend", (event) => {
1090
+ fired = true;
1091
+ if (event.target !== event.currentTarget) return false;
1092
+ if (document.head.contains(style)) document.head.removeChild(style);
1093
+ els__value.classList.remove(random_class);
1094
+ toFinish--;
1095
+ if (toFinish <= 0) window.requestAnimationFrame(() => {
1096
+ resolve();
1097
+ });
1098
+ });
1099
+ setTimeout(() => {
1100
+ if (fired === false) {
1101
+ if (document.head.contains(style)) document.head.removeChild(style);
1102
+ els__value.classList.remove(random_class);
1103
+ toFinish--;
1104
+ if (toFinish <= 0) resolve();
1105
+ }
1106
+ }, duration * 1.5);
1107
+ } else {
1108
+ if (document.head.contains(style)) document.head.removeChild(style);
1109
+ els__value.classList.remove(random_class);
1110
+ toFinish--;
1111
+ if (toFinish <= 0) resolve();
1112
+ }
1113
+ });
1114
+ });
1115
+ });
1116
+ });
1117
+ });
1118
+ }
1119
+ static addEventListenerOnce(target, type, listener, addOptions = void 0, removeOptions = void 0) {
1120
+ target.addEventListener(type, function fn(event) {
1121
+ if (listener.apply(this, arguments, addOptions) !== false) target.removeEventListener(type, fn, removeOptions);
1122
+ });
1123
+ }
1124
+ static htmlDecode(value) {
1125
+ let tmp = document.createElement("textarea");
1126
+ tmp.innerHTML = value;
1127
+ return tmp.value;
1128
+ }
1129
+ static htmlEncode(value) {
1130
+ return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#x27;").replace(/`/g, "&#96;");
1131
+ }
1132
+ static nl2br(str) {
1133
+ if (typeof str === "undefined" || str === null) return "";
1134
+ return (str + "").replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, "$1<br/>");
1135
+ }
1136
+ static br2nl(str) {
1137
+ if (typeof str === "undefined" || str === null) return "";
1138
+ return str.replace(/<\s*\/?br\s*[\/]?>/gi, "\n");
1139
+ }
1140
+ static closest(el, selector) {
1141
+ if (!document.documentElement.contains(el)) return null;
1142
+ do {
1143
+ if (this.matches(el, selector)) return el;
1144
+ el = el.parentElement || el.parentNode;
1145
+ } while (el !== null && el.nodeType === 1);
1146
+ return null;
1147
+ }
1148
+ static matches(el, selector) {
1149
+ let node = el, nodes = (node.parentNode || node.document).querySelectorAll(selector), i = -1;
1150
+ while (nodes[++i] && nodes[i] != node);
1151
+ return !!nodes[i];
1152
+ }
1153
+ static wrap(el, html) {
1154
+ if (el === null) return;
1155
+ let wrapper = new DOMParser().parseFromString(html, "text/html").body.childNodes[0];
1156
+ el.parentNode.insertBefore(wrapper, el.nextSibling);
1157
+ wrapper.appendChild(el);
1158
+ }
1159
+ static wrapTextNodes(el, tag) {
1160
+ if (el === null) return;
1161
+ Array.from(el.childNodes).filter((node) => node.nodeType === 3 && node.textContent.trim().length > 1).forEach((node) => {
1162
+ const wrapper = document.createElement(tag);
1163
+ node.after(wrapper);
1164
+ wrapper.appendChild(node);
1165
+ });
1166
+ }
1167
+ static html2dom(html) {
1168
+ let template = document.createElement("template");
1169
+ html = html.trim();
1170
+ template.innerHTML = html;
1171
+ if (template.content === void 0) return this.html2domLegacy(html);
1172
+ return template.content.firstChild;
1173
+ }
1174
+ static html2domLegacy(html) {
1175
+ var rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi, rtagName = /<([\w:]+)/, rhtml = /<|&#?\w+;/, wrapMap = {
1176
+ option: [
1177
+ 1,
1178
+ "<select multiple='multiple'>",
1179
+ "</select>"
1180
+ ],
1181
+ thead: [
1182
+ 1,
1183
+ "<table>",
1184
+ "</table>"
1185
+ ],
1186
+ col: [
1187
+ 2,
1188
+ "<table><colgroup>",
1189
+ "</colgroup></table>"
1190
+ ],
1191
+ tr: [
1192
+ 2,
1193
+ "<table><tbody>",
1194
+ "</tbody></table>"
1195
+ ],
1196
+ td: [
1197
+ 3,
1198
+ "<table><tbody><tr>",
1199
+ "</tr></tbody></table>"
1200
+ ],
1201
+ _default: [
1202
+ 0,
1203
+ "",
1204
+ ""
1205
+ ]
1206
+ }, context = document;
1207
+ var tmp, tag, wrap, j, fragment = context.createDocumentFragment();
1208
+ if (!rhtml.test(html)) fragment.appendChild(context.createTextNode(html));
1209
+ else {
1210
+ tmp = fragment.appendChild(context.createElement("div"));
1211
+ tag = (rtagName.exec(html) || ["", ""])[1].toLowerCase();
1212
+ wrap = wrapMap[tag] || wrapMap._default;
1213
+ tmp.innerHTML = wrap[1] + html.replace(rxhtmlTag, "<$1></$2>") + wrap[2];
1214
+ j = wrap[0];
1215
+ while (j--) tmp = tmp.lastChild;
1216
+ fragment.removeChild(fragment.firstChild);
1217
+ while (tmp.firstChild) fragment.appendChild(tmp.firstChild);
1218
+ }
1219
+ return fragment.querySelector("*");
1220
+ }
1221
+ static prev(elem, filter) {
1222
+ let prev = elem.previousElementSibling;
1223
+ if (prev === null) return null;
1224
+ if (filter === void 0 || this.matches(prev, filter)) return prev;
1225
+ return null;
1226
+ }
1227
+ static next(elem, filter) {
1228
+ let next = elem.nextElementSibling;
1229
+ if (next === null) return null;
1230
+ if (filter === void 0 || this.matches(next, filter)) return next;
1231
+ return null;
1232
+ }
1233
+ static prevAll(elem, filter) {
1234
+ let sibs = [];
1235
+ while (elem = elem.previousElementSibling) if (filter === void 0 || this.matches(elem, filter)) sibs.push(elem);
1236
+ return sibs;
1237
+ }
1238
+ static nextAll(elem, filter) {
1239
+ let sibs = [];
1240
+ while (elem = elem.nextElementSibling) if (filter === void 0 || this.matches(elem, filter)) sibs.push(elem);
1241
+ return sibs;
1242
+ }
1243
+ static prevUntil(elem, filter) {
1244
+ let sibs = [];
1245
+ while (elem = elem.previousElementSibling) if (!this.matches(elem, filter)) sibs.push(elem);
1246
+ else break;
1247
+ return sibs;
1248
+ }
1249
+ static nextUntil(elem, filter) {
1250
+ let sibs = [];
1251
+ while (elem = elem.nextElementSibling) if (!this.matches(elem, filter)) sibs.push(elem);
1252
+ else break;
1253
+ return sibs;
1254
+ }
1255
+ static siblings(elem, filter) {
1256
+ let sibs = [];
1257
+ let self = elem;
1258
+ elem = elem.parentNode.firstChild;
1259
+ while (elem = elem.nextElementSibling) if (filter === void 0 || this.matches(elem, filter)) {
1260
+ if (self !== elem) sibs.push(elem);
1261
+ }
1262
+ return sibs;
1263
+ }
1264
+ static parents(elem, selector) {
1265
+ let elements = [];
1266
+ let ishaveselector = selector !== void 0;
1267
+ while ((elem = elem.parentElement) !== null) {
1268
+ if (elem.nodeType !== Node.ELEMENT_NODE) continue;
1269
+ if (!ishaveselector || this.matches(elem, selector)) elements.push(elem);
1270
+ }
1271
+ return elements;
1272
+ }
1273
+ static css(el) {
1274
+ let sheets = document.styleSheets, o = {};
1275
+ for (let sheets__key in sheets) try {
1276
+ let rules = sheets[sheets__key].rules || sheets[sheets__key].cssRules;
1277
+ 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")));
1278
+ } catch (e) {}
1279
+ return o;
1280
+ }
1281
+ static css2json(css) {
1282
+ let obj = {};
1283
+ if (!css) return obj;
1284
+ if (css instanceof CSSStyleDeclaration) {
1285
+ 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]];
1286
+ } else if (typeof css == "string") {
1287
+ css = css.split(";");
1288
+ for (let css__key in css) if (css[css__key].indexOf(":") > -1) {
1289
+ let val = css[css__key].split(":");
1290
+ obj[val[0].toLowerCase().trim()] = val[1].trim();
1291
+ }
1292
+ }
1293
+ return obj;
1294
+ }
1295
+ static compareDates(d1, d2) {
1296
+ if (typeof d1 === "string") d1 = d1.split(" ").join("T");
1297
+ if (typeof d2 === "string") d2 = d2.split(" ").join("T");
1298
+ d1 = new Date(d1);
1299
+ d2 = new Date(d2);
1300
+ d1.setHours(0);
1301
+ d1.setMinutes(0);
1302
+ d1.setSeconds(0);
1303
+ d1.setMilliseconds(0);
1304
+ d2.setHours(0);
1305
+ d2.setMinutes(0);
1306
+ d2.setSeconds(0);
1307
+ d2.setMilliseconds(0);
1308
+ if (d1.getFullYear() === d2.getFullYear() && d1.getMonth() === d2.getMonth() && d1.getDate() === d2.getDate()) return 0;
1309
+ if (d1 < d2) return -1;
1310
+ return 1;
1311
+ }
1312
+ static spaceship(val1, val2) {
1313
+ if (val1 === null || val2 === null || typeof val1 != typeof val2) return null;
1314
+ if (typeof val1 === "string") return val1.localeCompare(val2);
1315
+ else {
1316
+ if (val1 > val2) return 1;
1317
+ else if (val1 < val2) return -1;
1318
+ return 0;
1319
+ }
1320
+ }
1321
+ static querySelectorAllShadowDom(selector) {
1322
+ let traverse = function($parent) {
1323
+ let $els = [];
1324
+ if ($parent.querySelector("*") !== null) $parent.querySelectorAll("*").forEach(($el) => {
1325
+ $els.push($el);
1326
+ if ($el.shadowRoot !== void 0 && $el.shadowRoot !== null) $els = $els.concat(traverse($el.shadowRoot));
1327
+ });
1328
+ return $els;
1329
+ };
1330
+ let fragment = document.createDocumentFragment();
1331
+ traverse(document).forEach(($el) => {
1332
+ if ($el.matches(selector)) fragment.appendChild($el.cloneNode());
1333
+ });
1334
+ return fragment.childNodes;
1335
+ }
1336
+ static focus(selector) {
1337
+ hlp.unfocus();
1338
+ let el = null;
1339
+ if (typeof selector === "string" || selector instanceof String) el = document.querySelector(selector);
1340
+ else el = selector;
1341
+ if (el !== null) {
1342
+ let mask = document.createElement("div");
1343
+ mask.classList.add("hlp-focus-mask");
1344
+ mask.style.position = "fixed";
1345
+ mask.style.top = "0";
1346
+ mask.style.bottom = "0";
1347
+ mask.style.left = "0";
1348
+ mask.style.right = "0";
1349
+ mask.style.backgroundColor = "rgba(0,0,0,0.8)";
1350
+ mask.style.zIndex = "2147483646";
1351
+ el.before(mask);
1352
+ el.setAttribute("data-focussed", "1");
1353
+ el.setAttribute("data-focussed-orig-z-index", el.style.zIndex);
1354
+ el.setAttribute("data-focussed-orig-position", el.style.position);
1355
+ el.setAttribute("data-focussed-orig-background-color", el.style.backgroundColor);
1356
+ el.setAttribute("data-focussed-orig-box-shadow", el.style.boxShadow);
1357
+ el.style.zIndex = "2147483647";
1358
+ el.style.position = "relative";
1359
+ el.style.backgroundColor = "#ffffff";
1360
+ el.style.boxShadow = "0px 0px 0px 20px #fff";
1361
+ }
1362
+ }
1363
+ static unfocus() {
1364
+ if (document.querySelector(".hlp-focus-mask") !== null) document.querySelectorAll(".hlp-focus-mask").forEach((el) => {
1365
+ hlp.remove(el);
1366
+ });
1367
+ if (document.querySelector("[data-focussed]") !== null) document.querySelectorAll("[data-focussed]").forEach((el) => {
1368
+ el.style.zIndex = el.getAttribute("data-focussed-orig-z-index");
1369
+ el.style.position = el.getAttribute("data-focussed-orig-position");
1370
+ el.style.backgroundColor = el.getAttribute("data-focussed-orig-background-color");
1371
+ el.style.boxShadow = el.getAttribute("data-focussed-orig-box-shadow");
1372
+ el.removeAttribute("data-focussed");
1373
+ el.removeAttribute("data-focussed-orig-z-index");
1374
+ el.removeAttribute("data-focussed-orig-position");
1375
+ el.removeAttribute("data-focussed-orig-background-color");
1376
+ el.removeAttribute("data-focussed-orig-box-shadow");
1377
+ });
1378
+ }
1379
+ static remove(el) {
1380
+ if (el !== null) el.parentNode.removeChild(el);
1381
+ }
1382
+ static on(event, selector, scope, callback = null) {
1383
+ if (callback === null) {
1384
+ callback = scope;
1385
+ scope = document;
1386
+ } else scope = document.querySelector(scope);
1387
+ scope.addEventListener(event, (e) => {
1388
+ var el = hlp.closest(e.target, selector);
1389
+ if (el) callback(e, el);
1390
+ }, false);
1391
+ }
1392
+ static url() {
1393
+ return window.location.protocol + "//" + window.location.host + window.location.pathname;
1394
+ }
1395
+ static urlWithHash() {
1396
+ return window.location.protocol + "//" + window.location.host + window.location.pathname + window.location.hash;
1397
+ }
1398
+ static fullUrl() {
1399
+ return window.location.href;
1400
+ }
1401
+ static urlWithArgs() {
1402
+ return window.location.href.split("#")[0];
1403
+ }
1404
+ static baseUrl() {
1405
+ return window.location.protocol + "//" + window.location.host;
1406
+ }
1407
+ static urlProtocol() {
1408
+ return window.location.protocol + "//";
1409
+ }
1410
+ static urlHost() {
1411
+ return window.location.host;
1412
+ }
1413
+ static urlHostTopLevel() {
1414
+ let host = window.location.host;
1415
+ if (host.match(/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/)) return host;
1416
+ host = host.split(".");
1417
+ while (host.length > 2) host.shift();
1418
+ host = host.join(".");
1419
+ return host;
1420
+ }
1421
+ static urlPath() {
1422
+ return window.location.pathname;
1423
+ }
1424
+ static urlHash() {
1425
+ return window.location.hash;
1426
+ }
1427
+ static urlArgs() {
1428
+ return window.location.search;
1429
+ }
1430
+ static urlOfScript() {
1431
+ if (document.currentScript) return document.currentScript.src;
1432
+ else {
1433
+ let scripts = document.getElementsByTagName("script");
1434
+ return scripts[scripts.length - 1].src;
1435
+ }
1436
+ }
1437
+ static pathOfScript() {
1438
+ let script = this.urlOfScript();
1439
+ return script.substring(0, script.lastIndexOf("/"));
1440
+ }
1441
+ static waitUntil(selector, css_option = null, css_value = null) {
1442
+ return new Promise((resolve, reject) => {
1443
+ let timeout = setInterval(() => {
1444
+ 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)) {
1445
+ window.clearInterval(timeout);
1446
+ resolve();
1447
+ }
1448
+ }, 30);
1449
+ });
1450
+ }
1451
+ static waitUntilEach(selector, callback) {
1452
+ new MutationObserver(() => {
1453
+ let elements = document.querySelectorAll(selector);
1454
+ if (elements.length > 0) elements.forEach((element) => {
1455
+ if (!element.__processed) {
1456
+ element.__processed = true;
1457
+ callback(element);
1458
+ }
1459
+ });
1460
+ }).observe(document.body, {
1461
+ childList: true,
1462
+ subtree: true
1463
+ });
1464
+ let initialElements = document.querySelectorAll(selector);
1465
+ if (initialElements.length > 0) initialElements.forEach((element) => {
1466
+ if (!element.__processed) {
1467
+ element.__processed = true;
1468
+ callback(element);
1469
+ }
1470
+ });
1471
+ }
1472
+ static waitUntilVar(arg1 = null, arg2 = null, value = null) {
1473
+ let varName = null, parentContainer = null;
1474
+ if (arg2 === null) {
1475
+ varName = arg1;
1476
+ parentContainer = window;
1477
+ } else {
1478
+ varName = arg2;
1479
+ parentContainer = arg1;
1480
+ }
1481
+ return new Promise((resolve, reject) => {
1482
+ let timeout = setInterval(() => {
1483
+ if (parentContainer[varName] !== void 0 && parentContainer[varName] !== null) {
1484
+ if (value === null || parentContainer[varName] === value) {
1485
+ window.clearInterval(timeout);
1486
+ resolve();
1487
+ }
1488
+ }
1489
+ }, 30);
1490
+ });
1491
+ }
1492
+ static ready() {
1493
+ return new Promise((resolve) => {
1494
+ if (document.readyState !== "loading") return resolve();
1495
+ else document.addEventListener("DOMContentLoaded", () => {
1496
+ return resolve();
1497
+ });
1498
+ });
1499
+ }
1500
+ static load() {
1501
+ return new Promise((resolve) => {
1502
+ if (document.readyState === "complete") return resolve();
1503
+ else window.addEventListener("load", () => {
1504
+ return resolve();
1505
+ });
1506
+ });
1507
+ }
1508
+ static runForEl(selector, callback) {
1509
+ hlp.ready().then(() => {
1510
+ let id = hlp.pushId();
1511
+ if (document.querySelector(selector) !== null) document.querySelectorAll(selector).forEach((el) => {
1512
+ if (el.runForEl === void 0) el.runForEl = [];
1513
+ if (!el.runForEl.includes(id)) {
1514
+ el.runForEl.push(id);
1515
+ callback(el);
1516
+ }
1517
+ });
1518
+ if (window.runForEl_queue === void 0) window.runForEl_queue = [];
1519
+ if (window.runForEl_observer === void 0) window.runForEl_observer = new MutationObserver((mutations) => {
1520
+ mutations.forEach((mutations__value) => {
1521
+ if (!mutations__value.addedNodes) return;
1522
+ for (let i = 0; i < mutations__value.addedNodes.length; i++) {
1523
+ let node = mutations__value.addedNodes[i];
1524
+ if (node.nodeType === Node.ELEMENT_NODE) window.runForEl_queue.forEach((queue__value) => {
1525
+ if (node.matches(queue__value.selector)) {
1526
+ if (node.runForEl === void 0) node.runForEl = [];
1527
+ if (!node.runForEl.includes(queue__value.id)) {
1528
+ node.runForEl.push(queue__value.id);
1529
+ queue__value.callback(node);
1530
+ }
1531
+ }
1532
+ if (node.querySelector(queue__value.selector) !== null) node.querySelectorAll(queue__value.selector).forEach((nodes__value) => {
1533
+ if (nodes__value.runForEl === void 0) nodes__value.runForEl = [];
1534
+ if (!nodes__value.runForEl.includes(queue__value.id)) {
1535
+ nodes__value.runForEl.push(queue__value.id);
1536
+ queue__value.callback(nodes__value);
1537
+ }
1538
+ });
1539
+ });
1540
+ }
1541
+ });
1542
+ }).observe(document.body, {
1543
+ attributes: false,
1544
+ childList: true,
1545
+ characterData: false,
1546
+ subtree: true,
1547
+ attributeOldValue: false,
1548
+ characterDataOldValue: false
1549
+ });
1550
+ window.runForEl_queue.push({
1551
+ id,
1552
+ selector,
1553
+ callback
1554
+ });
1555
+ });
1556
+ }
1557
+ static fmath(op, x, y, precision = 8) {
1558
+ let n = {
1559
+ "*": x * y,
1560
+ "-": x - y,
1561
+ "+": x + y,
1562
+ "/": x / y
1563
+ }[op];
1564
+ return Math.round(n * 10 * Math.pow(10, precision)) / (10 * Math.pow(10, precision));
1565
+ }
1566
+ static trim(str, charlist = null) {
1567
+ let whitespace = [
1568
+ " ",
1569
+ "\n",
1570
+ "\r",
1571
+ " ",
1572
+ "\f",
1573
+ "\v",
1574
+ "\xA0",
1575
+ " ",
1576
+ " ",
1577
+ " ",
1578
+ " ",
1579
+ " ",
1580
+ " ",
1581
+ " ",
1582
+ " ",
1583
+ " ",
1584
+ " ",
1585
+ " ",
1586
+ "​",
1587
+ "\u2028",
1588
+ "\u2029",
1589
+ " "
1590
+ ].join("");
1591
+ let l = 0;
1592
+ let i = 0;
1593
+ str += "";
1594
+ if (charlist) whitespace = (charlist + "").replace(/([[\]().?/*{}+$^:])/g, "$1");
1595
+ l = str.length;
1596
+ for (i = 0; i < l; i++) if (whitespace.indexOf(str.charAt(i)) === -1) {
1597
+ str = str.substring(i);
1598
+ break;
1599
+ }
1600
+ l = str.length;
1601
+ for (i = l - 1; i >= 0; i--) if (whitespace.indexOf(str.charAt(i)) === -1) {
1602
+ str = str.substring(0, i + 1);
1603
+ break;
1604
+ }
1605
+ return whitespace.indexOf(str.charAt(0)) === -1 ? str : "";
1606
+ }
1607
+ static ltrim(str, charlist = null) {
1608
+ charlist = !charlist ? " \\s\xA0" : (charlist + "").replace(/([[\]().?/*{}+$^:])/g, "$1");
1609
+ const re = new RegExp("^[" + charlist + "]+", "g");
1610
+ return (str + "").replace(re, "");
1611
+ }
1612
+ static rtrim(str, charlist = null) {
1613
+ charlist = !charlist ? " \\s\xA0" : (charlist + "").replace(/([[\]().?/*{}+$^:])/g, "\\$1");
1614
+ const re = new RegExp("[" + charlist + "]+$", "g");
1615
+ return (str + "").replace(re, "");
1616
+ }
1617
+ static truncate_string(str, len = 50, chars = "...") {
1618
+ if (this.nx(str) || !(typeof str === "string" || str instanceof String)) return str;
1619
+ if (str.indexOf(" ") === -1) {
1620
+ if (str.length > len) {
1621
+ str = str.substring(0, len);
1622
+ str = hlp.rtrim(str);
1623
+ str += " " + chars;
1624
+ }
1625
+ } else if (str.length > len) {
1626
+ str = hlp.rtrim(str);
1627
+ while (str.length > len && str.lastIndexOf(" ") > -1 && str.substring(len - 1, len) != " ") {
1628
+ str = str.substring(0, str.lastIndexOf(" "));
1629
+ str = hlp.rtrim(str);
1630
+ }
1631
+ str = str.substring(0, len);
1632
+ str = hlp.rtrim(str);
1633
+ str += " " + chars;
1634
+ }
1635
+ return str;
1636
+ }
1637
+ static emojiRegex(global = true) {
1638
+ return new RegExp(hlp.emojiRegexPattern(), (global === true ? "g" : "") + "u");
1639
+ }
1640
+ static emojiRegexPattern() {
1641
+ 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})?))*`;
1642
+ }
1643
+ static emojiSplit(str) {
1644
+ if (!(typeof str === "string" || str instanceof String)) return str;
1645
+ return [...new Intl.Segmenter().segment(str)].map((x) => x.segment);
1646
+ }
1647
+ static serialize(mixedValue) {
1648
+ let val, key, okey;
1649
+ let ktype = "";
1650
+ let vals = "";
1651
+ let count = 0;
1652
+ const _utf8Size = function(str) {
1653
+ return ~-encodeURI(str).split(/%..|./).length;
1654
+ };
1655
+ const _getType = function(inp) {
1656
+ let match;
1657
+ let key;
1658
+ let cons;
1659
+ let types;
1660
+ let type = typeof inp;
1661
+ if (type === "object" && !inp) return "null";
1662
+ if (type === "object") {
1663
+ if (!inp.constructor) return "object";
1664
+ cons = inp.constructor.toString();
1665
+ match = cons.match(/(\w+)\(/);
1666
+ if (match) cons = match[1].toLowerCase();
1667
+ types = [
1668
+ "boolean",
1669
+ "number",
1670
+ "string",
1671
+ "array"
1672
+ ];
1673
+ for (key in types) if (cons === types[key]) {
1674
+ type = types[key];
1675
+ break;
1676
+ }
1677
+ }
1678
+ return type;
1679
+ };
1680
+ const type = _getType(mixedValue);
1681
+ switch (type) {
1682
+ case "function":
1683
+ val = "";
1684
+ break;
1685
+ case "boolean":
1686
+ val = "b:" + (mixedValue ? "1" : "0");
1687
+ break;
1688
+ case "number":
1689
+ val = (Math.round(mixedValue) === mixedValue ? "i" : "d") + ":" + mixedValue;
1690
+ break;
1691
+ case "string":
1692
+ val = "s:" + _utf8Size(mixedValue) + ":\"" + mixedValue + "\"";
1693
+ break;
1694
+ case "array":
1695
+ case "object":
1696
+ val = "a";
1697
+ for (key in mixedValue) if (mixedValue.hasOwnProperty(key)) {
1698
+ ktype = _getType(mixedValue[key]);
1699
+ if (ktype === "function") continue;
1700
+ okey = key.match(/^[0-9]+$/) ? parseInt(key, 10) : key;
1701
+ vals += this.serialize(okey) + this.serialize(mixedValue[key]);
1702
+ count++;
1703
+ }
1704
+ val += ":" + count + ":{" + vals + "}";
1705
+ break;
1706
+ default:
1707
+ val = "N";
1708
+ break;
1709
+ }
1710
+ if (type !== "object" && type !== "array") val += ";";
1711
+ return val;
1712
+ }
1713
+ static unserialize(str) {
1714
+ try {
1715
+ if (typeof str !== "string") return false;
1716
+ const store = [];
1717
+ const cache = (value) => {
1718
+ store.push(value[0]);
1719
+ return value;
1720
+ };
1721
+ cache.get = (index) => {
1722
+ if (index >= store.length) throw RangeError(`Can't resolve reference ${index + 1}`);
1723
+ return store[index];
1724
+ };
1725
+ const expectType = (s) => {
1726
+ const type = (/^(?:N(?=;)|[bidsSaOCrR](?=:)|[^:]+(?=:))/g.exec(s) || [])[0];
1727
+ if (!type) throw SyntaxError("Invalid input: " + s);
1728
+ switch (type) {
1729
+ case "N": return cache([null, 2]);
1730
+ case "b": return cache(expectBool(s));
1731
+ case "i": return cache(expectInt(s));
1732
+ case "d": return cache(expectFloat(s));
1733
+ case "s": return cache(expectString(s));
1734
+ case "S": return cache(expectEscapedString(s));
1735
+ case "a": return expectArray(s);
1736
+ case "O": return expectObject(s);
1737
+ case "C": throw Error("Not yet implemented");
1738
+ case "r":
1739
+ case "R": return expectReference(s);
1740
+ default: throw SyntaxError(`Invalid or unsupported data type: ${type}`);
1741
+ }
1742
+ };
1743
+ const expectBool = (s) => {
1744
+ const [match, boolMatch] = /^b:([01]);/.exec(s) || [];
1745
+ if (!boolMatch) throw SyntaxError("Invalid bool value, expected 0 or 1");
1746
+ return [boolMatch === "1", match.length];
1747
+ };
1748
+ const expectInt = (s) => {
1749
+ const [match, intMatch] = /^i:([+-]?\d+);/.exec(s) || [];
1750
+ if (!intMatch) throw SyntaxError("Expected an integer value");
1751
+ return [parseInt(intMatch, 10), match.length];
1752
+ };
1753
+ const expectFloat = (s) => {
1754
+ const [match, floatMatch] = /^d:(NAN|-?INF|(?:\d+\.\d*|\d*\.\d+|\d+)(?:[eE][+-]\d+)?);/.exec(s) || [];
1755
+ if (!floatMatch) throw SyntaxError("Expected a float value");
1756
+ return [floatMatch === "NAN" ? NaN : floatMatch === "-INF" ? Number.NEGATIVE_INFINITY : floatMatch === "INF" ? Number.POSITIVE_INFINITY : parseFloat(floatMatch), match.length];
1757
+ };
1758
+ const expectString = (s) => {
1759
+ const [match, byteLenMatch] = /^s:(\d+):"/g.exec(s) || [];
1760
+ if (!match) throw SyntaxError("Expected a string value");
1761
+ const len = parseInt(byteLenMatch, 10);
1762
+ s = s.substr(match.length);
1763
+ const strMatch = s.substr(0, len);
1764
+ s = s.substr(len);
1765
+ if (!s.startsWith("\";")) throw SyntaxError("Expected \";");
1766
+ return [strMatch, match.length + len + 2];
1767
+ };
1768
+ const expectEscapedString = (s) => {
1769
+ const [match, strLenMatch] = /^S:(\d+):"/g.exec(s) || [];
1770
+ if (!match) throw SyntaxError("Expected an escaped string value");
1771
+ const len = parseInt(strLenMatch, 10);
1772
+ s = s.substr(match.length);
1773
+ const strMatch = s.substr(0, len);
1774
+ s = s.substr(len);
1775
+ if (!s.startsWith("\";")) throw SyntaxError("Expected \";");
1776
+ return [strMatch, match.length + len + 2];
1777
+ };
1778
+ const expectReference = (s) => {
1779
+ const [match, refIndex] = /^[rR]:(\d+);/.exec(s) || [];
1780
+ if (!match) throw SyntaxError("Expected reference value");
1781
+ return [cache.get(parseInt(refIndex, 10) - 1), match.length];
1782
+ };
1783
+ const expectArray = (s) => {
1784
+ const [arrayLiteralBeginMatch, arrayLengthMatch] = /^a:(\d+):\{/.exec(s) || [];
1785
+ if (!arrayLengthMatch) throw SyntaxError("Expected array length annotation");
1786
+ s = s.substr(arrayLiteralBeginMatch.length);
1787
+ const items = {};
1788
+ cache([items]);
1789
+ for (let i = 0; i < parseInt(arrayLengthMatch, 10); i++) {
1790
+ const key = expectType(s);
1791
+ s = s.substr(key[1]);
1792
+ const value = expectType(s);
1793
+ s = s.substr(value[1]);
1794
+ items[key[0]] = value[0];
1795
+ }
1796
+ if (s.charAt(0) !== "}") throw SyntaxError("Expected }");
1797
+ return [items, arrayLiteralBeginMatch.length + 1];
1798
+ };
1799
+ const expectObject = (s) => {
1800
+ const [match, , className, propCountMatch] = /^O:(\d+):"([^\"]+)":(\d+):\{/.exec(s) || [];
1801
+ if (!match) throw SyntaxError("Invalid input");
1802
+ if (className !== "stdClass") throw SyntaxError(`Unsupported object type: ${className}`);
1803
+ let obj = {};
1804
+ cache([obj]);
1805
+ s = s.substr(match.length);
1806
+ for (let i = 0; i < parseInt(propCountMatch, 10); i++) {
1807
+ const prop = expectType(s);
1808
+ s = s.substr(prop[1]);
1809
+ const value = expectType(s);
1810
+ s = s.substr(value[1]);
1811
+ obj[prop[0]] = value[0];
1812
+ }
1813
+ if (s.charAt(0) !== "}") throw SyntaxError("Expected }");
1814
+ return [obj, match.length + 1];
1815
+ };
1816
+ return expectType(str)[0];
1817
+ } catch (err) {
1818
+ console.error(err);
1819
+ return false;
1820
+ }
1821
+ }
1822
+ static pushId() {
1823
+ let pushIdData = null;
1824
+ if (window !== void 0) {
1825
+ if (window.pushIdDataGlobal === void 0) window.pushIdDataGlobal = {};
1826
+ pushIdData = window.pushIdDataGlobal;
1827
+ }
1828
+ if (typeof global !== "undefined") {
1829
+ if (global.pushIdDataGlobal === void 0) global.pushIdDataGlobal = {};
1830
+ pushIdData = global.pushIdDataGlobal;
1831
+ }
1832
+ if (hlp.objectsAreEqual(pushIdData, {})) {
1833
+ pushIdData.lastPushTime = 0;
1834
+ pushIdData.lastRandChars = [];
1835
+ pushIdData.PUSH_CHARS = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
1836
+ }
1837
+ let now = (/* @__PURE__ */ new Date()).getTime(), duplicateTime = now === pushIdData.lastPushTime;
1838
+ pushIdData.lastPushTime = now;
1839
+ let timeStampChars = new Array(8);
1840
+ for (var i = 7; i >= 0; i--) {
1841
+ timeStampChars[i] = pushIdData.PUSH_CHARS.charAt(now % 64);
1842
+ now = Math.floor(now / 64);
1843
+ }
1844
+ if (now !== 0) throw new Error();
1845
+ let id = timeStampChars.join("");
1846
+ if (!duplicateTime) for (i = 0; i < 12; i++) pushIdData.lastRandChars[i] = Math.floor(Math.random() * 64);
1847
+ else {
1848
+ for (i = 11; i >= 0 && pushIdData.lastRandChars[i] === 63; i--) pushIdData.lastRandChars[i] = 0;
1849
+ pushIdData.lastRandChars[i]++;
1850
+ }
1851
+ for (i = 0; i < 12; i++) id += pushIdData.PUSH_CHARS.charAt(pushIdData.lastRandChars[i]);
1852
+ if (id.length != 20) throw new Error();
1853
+ return id;
1854
+ }
1855
+ static getProp(obj, desc) {
1856
+ let arr = desc.split(".");
1857
+ while (arr.length && (obj = obj[arr.shift()]));
1858
+ return obj;
1859
+ }
1860
+ static base64toblob(base64, contentType = "") {
1861
+ let sliceSize = 512, byteCharacters = atob(base64), byteArrays = [];
1862
+ for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
1863
+ let slice = byteCharacters.slice(offset, offset + sliceSize), byteNumbers = new Array(slice.length);
1864
+ for (let i = 0; i < slice.length; i++) byteNumbers[i] = slice.charCodeAt(i);
1865
+ let byteArray = new Uint8Array(byteNumbers);
1866
+ byteArrays.push(byteArray);
1867
+ }
1868
+ return new Blob(byteArrays, { type: contentType });
1869
+ }
1870
+ static blobtobase64(blob) {
1871
+ return new Promise((resolve) => {
1872
+ let reader = new FileReader();
1873
+ reader.onload = () => {
1874
+ var base64 = reader.result.split(",")[1];
1875
+ resolve(base64);
1876
+ };
1877
+ reader.readAsDataURL(blob);
1878
+ });
1879
+ }
1880
+ static stringtoblob(string, contentType = "") {
1881
+ return new Blob([string], { type: contentType });
1882
+ }
1883
+ static blobtostring(blob) {
1884
+ return new Promise((resolve) => {
1885
+ let reader = new FileReader();
1886
+ reader.onload = () => {
1887
+ resolve(reader.result);
1888
+ };
1889
+ reader.readAsText(blob);
1890
+ });
1891
+ }
1892
+ static filetobase64(file) {
1893
+ return new Promise((resolve, reject) => {
1894
+ const reader = new FileReader();
1895
+ reader.readAsDataURL(file);
1896
+ reader.onload = () => resolve(reader.result.split(",")[1]);
1897
+ reader.onerror = (error) => reject(error);
1898
+ });
1899
+ }
1900
+ static blobtofile(blob, filename = "file.txt") {
1901
+ let file = null;
1902
+ try {
1903
+ file = new File([blob], filename);
1904
+ } catch {
1905
+ file = new Blob([blob], filename);
1906
+ }
1907
+ return file;
1908
+ }
1909
+ static filetoblob(file) {
1910
+ return new Blob([file]);
1911
+ }
1912
+ static base64tofile(base64, contentType = "", filename = "file.txt") {
1913
+ return this.blobtofile(this.base64toblob(base64, contentType), filename);
1914
+ }
1915
+ static blobtourl(blob) {
1916
+ return URL.createObjectURL(blob);
1917
+ }
1918
+ static stringtourl(string) {
1919
+ return this.blobtourl(this.stringtoblob(string));
1920
+ }
1921
+ static base64tostring(base64) {
1922
+ return atob(base64);
1923
+ }
1924
+ static stringtobase64(string) {
1925
+ return btoa(string);
1926
+ }
1927
+ static base64tourl(base64) {
1928
+ return this.blobtourl(this.base64toblob(base64));
1929
+ }
1930
+ static filetourl(file) {
1931
+ return this.blobtourl(this.filetoblob(file));
1932
+ }
1933
+ static getImageOrientation(base64) {
1934
+ return new Promise((resolve, reject) => {
1935
+ base64 = base64.replace("data:image/jpeg;base64,", "");
1936
+ let file = this.base64tofile(base64), reader = new FileReader();
1937
+ reader.onload = (e) => {
1938
+ var view = new DataView(e.target.result);
1939
+ if (view.getUint16(0, false) != 65496) {
1940
+ resolve(-2);
1941
+ return;
1942
+ }
1943
+ var length = view.byteLength, offset = 2;
1944
+ while (offset < length) {
1945
+ if (view.getUint16(offset + 2, false) <= 8) {
1946
+ resolve(-1);
1947
+ return;
1948
+ }
1949
+ var marker = view.getUint16(offset, false);
1950
+ offset += 2;
1951
+ if (marker == 65505) {
1952
+ if (view.getUint32(offset += 2, false) != 1165519206) {
1953
+ resolve(-1);
1954
+ return;
1955
+ }
1956
+ var little = view.getUint16(offset += 6, false) == 18761;
1957
+ offset += view.getUint32(offset + 4, little);
1958
+ var tags = view.getUint16(offset, little);
1959
+ offset += 2;
1960
+ for (var i = 0; i < tags; i++) if (view.getUint16(offset + i * 12, little) == 274) {
1961
+ resolve(view.getUint16(offset + i * 12 + 8, little));
1962
+ return;
1963
+ }
1964
+ } else if ((marker & 65280) != 65280) break;
1965
+ else offset += view.getUint16(offset, false);
1966
+ }
1967
+ resolve(-1);
1968
+ };
1969
+ reader.readAsArrayBuffer(file);
1970
+ });
1971
+ }
1972
+ static resetImageOrientation(srcBase64, srcOrientation) {
1973
+ return new Promise((resolve, reject) => {
1974
+ var img = new Image();
1975
+ img.onload = () => {
1976
+ var width = img.width, height = img.height, canvas = document.createElement("canvas"), ctx = canvas.getContext("2d");
1977
+ if (4 < srcOrientation && srcOrientation < 9) {
1978
+ canvas.width = height;
1979
+ canvas.height = width;
1980
+ } else {
1981
+ canvas.width = width;
1982
+ canvas.height = height;
1983
+ }
1984
+ switch (srcOrientation) {
1985
+ case 2:
1986
+ ctx.transform(-1, 0, 0, 1, width, 0);
1987
+ break;
1988
+ case 3:
1989
+ ctx.transform(-1, 0, 0, -1, width, height);
1990
+ break;
1991
+ case 4:
1992
+ ctx.transform(1, 0, 0, -1, 0, height);
1993
+ break;
1994
+ case 5:
1995
+ ctx.transform(0, 1, 1, 0, 0, 0);
1996
+ break;
1997
+ case 6:
1998
+ ctx.transform(0, 1, -1, 0, height, 0);
1999
+ break;
2000
+ case 7:
2001
+ ctx.transform(0, -1, -1, 0, height, width);
2002
+ break;
2003
+ case 8:
2004
+ ctx.transform(0, -1, 1, 0, 0, width);
2005
+ break;
2006
+ default: break;
2007
+ }
2008
+ ctx.drawImage(img, 0, 0);
2009
+ let base64 = canvas.toDataURL();
2010
+ base64 = "data:image/jpeg;base64," + base64.split(",")[1];
2011
+ resolve(base64);
2012
+ };
2013
+ img.src = srcBase64;
2014
+ });
2015
+ }
2016
+ static fixImageOrientation(base64) {
2017
+ return new Promise((resolve, reject) => {
2018
+ if (base64.indexOf("data:") === -1) {
2019
+ resolve(base64);
2020
+ return;
2021
+ }
2022
+ if (base64.indexOf("data:image/jpeg;base64,") === 0) base64 = base64.replace("data:image/jpeg;base64,", "");
2023
+ this.getImageOrientation(base64).then((orientation) => {
2024
+ base64 = "data:image/jpeg;base64," + base64;
2025
+ if (orientation <= 1) {
2026
+ resolve(base64);
2027
+ return;
2028
+ } else this.resetImageOrientation(base64, orientation).then((base64_new) => {
2029
+ resolve(base64_new);
2030
+ });
2031
+ });
2032
+ });
2033
+ }
2034
+ static debounce(func, wait, immediate) {
2035
+ var timeout;
2036
+ return function() {
2037
+ var context = this, args = arguments;
2038
+ var later = function() {
2039
+ timeout = null;
2040
+ if (!immediate) func.apply(context, args);
2041
+ };
2042
+ var callNow = immediate && !timeout;
2043
+ clearTimeout(timeout);
2044
+ timeout = setTimeout(later, wait);
2045
+ if (callNow) func.apply(context, args);
2046
+ };
2047
+ }
2048
+ static throttle(func, wait, options) {
2049
+ var context, args, result;
2050
+ var timeout = null;
2051
+ var previous = 0;
2052
+ if (!options) options = {};
2053
+ var later = function() {
2054
+ previous = options.leading === false ? 0 : Date.now();
2055
+ timeout = null;
2056
+ result = func.apply(context, args);
2057
+ if (!timeout) context = args = null;
2058
+ };
2059
+ return function() {
2060
+ var now = Date.now();
2061
+ if (!previous && options.leading === false) previous = now;
2062
+ var remaining = wait - (now - previous);
2063
+ context = this;
2064
+ args = arguments;
2065
+ if (remaining <= 0 || remaining > wait) {
2066
+ if (timeout) {
2067
+ clearTimeout(timeout);
2068
+ timeout = null;
2069
+ }
2070
+ previous = now;
2071
+ result = func.apply(context, args);
2072
+ if (!timeout) context = args = null;
2073
+ } else if (!timeout && options.trailing !== false) timeout = setTimeout(later, remaining);
2074
+ return result;
2075
+ };
2076
+ }
2077
+ static shuffle(array) {
2078
+ let currentIndex = array.length, temporaryValue, randomIndex;
2079
+ while (0 !== currentIndex) {
2080
+ randomIndex = Math.floor(Math.random() * currentIndex);
2081
+ currentIndex -= 1;
2082
+ temporaryValue = array[currentIndex];
2083
+ array[currentIndex] = array[randomIndex];
2084
+ array[randomIndex] = temporaryValue;
2085
+ }
2086
+ return array;
2087
+ }
2088
+ static findRecursiveInObject(object, key = null, value = null, path = "", paths = []) {
2089
+ if (object !== null && typeof object === "object") {
2090
+ 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);
2091
+ else if ((key === null || object__key === key) && (value === null || object__value === value)) {
2092
+ paths.push(path);
2093
+ break;
2094
+ }
2095
+ }
2096
+ return paths;
2097
+ }
2098
+ };
2099
+ if (typeof window !== "undefined") {
2100
+ window.hlp = {};
2101
+ Object.getOwnPropertyNames(hlp).forEach((value, key) => {
2102
+ if (value === "length" || value === "name" || value === "prototype" || value === "caller" || value === "arguments") return;
2103
+ window.hlp[value] = hlp[value];
2104
+ });
2861
2105
  }
2862
-
2863
- /* expose all functions to window */
2106
+ //#endregion
2864
2107
  exports.default = hlp;
2865
- if (typeof window !== 'undefined') {
2866
- window.hlp = {};
2867
- Object.getOwnPropertyNames(hlp).forEach((value, key) => {
2868
- if (value === 'length' || value === 'name' || value === 'prototype' || value === 'caller' || value === 'arguments') {
2869
- return;
2870
- }
2871
- window.hlp[value] = hlp[value];
2872
- });
2873
- }