tsgrid-ui 2.7.1 → 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/CHANGELOG.md +173 -0
  2. package/dist/base.d.ts +148 -0
  3. package/dist/base.es6.js +11 -0
  4. package/dist/base.es6.js.map +1 -0
  5. package/dist/chunks/chunk-26XP2XU3.js +1795 -0
  6. package/dist/chunks/chunk-26XP2XU3.js.map +1 -0
  7. package/dist/chunks/chunk-3NYH6545.js +2423 -0
  8. package/dist/chunks/chunk-3NYH6545.js.map +1 -0
  9. package/dist/chunks/chunk-BIB3X2TW.js +1638 -0
  10. package/dist/chunks/chunk-BIB3X2TW.js.map +1 -0
  11. package/dist/chunks/chunk-DXZJHS4M.js +1283 -0
  12. package/dist/chunks/chunk-DXZJHS4M.js.map +1 -0
  13. package/dist/chunks/chunk-EVZMMVXO.js +1212 -0
  14. package/dist/chunks/chunk-EVZMMVXO.js.map +1 -0
  15. package/dist/chunks/chunk-GJD5NFWQ.js +2305 -0
  16. package/dist/chunks/chunk-GJD5NFWQ.js.map +1 -0
  17. package/dist/chunks/chunk-IYF3Q7GX.js +127 -0
  18. package/dist/chunks/chunk-IYF3Q7GX.js.map +1 -0
  19. package/dist/chunks/chunk-OFASTA2A.js +2980 -0
  20. package/dist/chunks/chunk-OFASTA2A.js.map +1 -0
  21. package/dist/chunks/chunk-OMLGN735.js +677 -0
  22. package/dist/chunks/chunk-OMLGN735.js.map +1 -0
  23. package/dist/chunks/chunk-WKSLGUB3.js +1127 -0
  24. package/dist/chunks/chunk-WKSLGUB3.js.map +1 -0
  25. package/dist/chunks/chunk-YBY52G2U.js +849 -0
  26. package/dist/chunks/chunk-YBY52G2U.js.map +1 -0
  27. package/dist/field.d.ts +329 -0
  28. package/dist/field.es6.js +11 -0
  29. package/dist/field.es6.js.map +1 -0
  30. package/dist/form.d.ts +162 -0
  31. package/dist/form.es6.js +14 -0
  32. package/dist/form.es6.js.map +1 -0
  33. package/dist/layout.d.ts +108 -0
  34. package/dist/layout.es6.js +13 -0
  35. package/dist/layout.es6.js.map +1 -0
  36. package/dist/locale.d.ts +30 -0
  37. package/dist/locale.es6.js +7 -0
  38. package/dist/locale.es6.js.map +1 -0
  39. package/dist/metafile-esm.json +1 -0
  40. package/dist/popup.d.ts +92 -0
  41. package/dist/popup.es6.js +18 -0
  42. package/dist/popup.es6.js.map +1 -0
  43. package/dist/query-CKGg5Ugv.d.ts +81 -0
  44. package/dist/sidebar.d.ts +138 -0
  45. package/dist/sidebar.es6.js +11 -0
  46. package/dist/sidebar.es6.js.map +1 -0
  47. package/dist/tabs.d.ts +63 -0
  48. package/dist/tabs.es6.js +11 -0
  49. package/dist/tabs.es6.js.map +1 -0
  50. package/dist/toolbar.d.ts +97 -0
  51. package/dist/toolbar.es6.js +11 -0
  52. package/dist/toolbar.es6.js.map +1 -0
  53. package/dist/tooltip.d.ts +322 -0
  54. package/dist/tooltip.es6.js +18 -0
  55. package/dist/tooltip.es6.js.map +1 -0
  56. package/dist/tsgrid-ui.css +2 -2
  57. package/dist/tsgrid-ui.d.ts +16 -2004
  58. package/dist/tsgrid-ui.es6.js +7750 -23830
  59. package/dist/tsgrid-ui.es6.js.map +1 -1
  60. package/dist/tsgrid-ui.es6.min.js +28 -28
  61. package/dist/tsgrid-ui.js +96 -17
  62. package/dist/tsgrid-ui.min.css +2 -2
  63. package/dist/tsgrid-ui.min.js +24 -24
  64. package/dist/tsutils-message-CogFtVtO.d.ts +82 -0
  65. package/dist/utils.d.ts +418 -0
  66. package/dist/utils.es6.js +14 -0
  67. package/dist/utils.es6.js.map +1 -0
  68. package/package.json +26 -5
@@ -0,0 +1,2423 @@
1
+ import {
2
+ TsLocale
3
+ } from "./chunk-IYF3Q7GX.js";
4
+ import {
5
+ TsBase,
6
+ checkName,
7
+ clone,
8
+ debounce,
9
+ encodeParams,
10
+ extend,
11
+ getNested,
12
+ isAlphaNumeric,
13
+ isBin,
14
+ isEmail,
15
+ isFloat,
16
+ isHex,
17
+ isInt,
18
+ isIpAddress,
19
+ isMoney,
20
+ isPlainObject,
21
+ naturalCompare,
22
+ normMenu,
23
+ parseRoute,
24
+ prepareParams,
25
+ query,
26
+ wait
27
+ } from "./chunk-DXZJHS4M.js";
28
+
29
+ // src/tsutils-color.ts
30
+ function parseColor(str) {
31
+ if (typeof str !== "string") return null;
32
+ else str = str.trim().toUpperCase();
33
+ if (str[0] === "#") str = str.substr(1);
34
+ let color = { r: 0, g: 0, b: 0, a: 1 };
35
+ if (str.length === 3) {
36
+ const s0 = str[0] ?? "0", s1 = str[1] ?? "0", s2 = str[2] ?? "0";
37
+ color = {
38
+ r: parseInt(s0 + s0, 16),
39
+ g: parseInt(s1 + s1, 16),
40
+ b: parseInt(s2 + s2, 16),
41
+ a: 1
42
+ };
43
+ } else if (str.length === 6) {
44
+ color = {
45
+ r: parseInt(str.substr(0, 2), 16),
46
+ g: parseInt(str.substr(2, 2), 16),
47
+ b: parseInt(str.substr(4, 2), 16),
48
+ a: 1
49
+ };
50
+ } else if (str.length === 8) {
51
+ color = {
52
+ r: parseInt(str.substr(0, 2), 16),
53
+ g: parseInt(str.substr(2, 2), 16),
54
+ b: parseInt(str.substr(4, 2), 16),
55
+ a: Math.round(parseInt(str.substr(6, 2), 16) / 255 * 100) / 100
56
+ // alpha channel 0-1
57
+ };
58
+ } else if (str.length > 4 && str.substr(0, 4) === "RGB(") {
59
+ const tmp = str.replace("RGB", "").replace(/\(/g, "").replace(/\)/g, "").split(",");
60
+ color = {
61
+ r: parseInt(tmp[0] ?? "0", 10),
62
+ g: parseInt(tmp[1] ?? "0", 10),
63
+ b: parseInt(tmp[2] ?? "0", 10),
64
+ a: 1
65
+ };
66
+ } else if (str.length > 5 && str.substr(0, 5) === "RGBA(") {
67
+ const tmp = str.replace("RGBA", "").replace(/\(/g, "").replace(/\)/g, "").split(",");
68
+ color = {
69
+ r: parseInt(tmp[0] ?? "0", 10),
70
+ g: parseInt(tmp[1] ?? "0", 10),
71
+ b: parseInt(tmp[2] ?? "0", 10),
72
+ a: parseFloat(tmp[3] ?? "1")
73
+ };
74
+ } else {
75
+ return null;
76
+ }
77
+ return color;
78
+ }
79
+ function colorContrastValue(color1, color2) {
80
+ const lum1 = calcLumens(color1);
81
+ const lum2 = calcLumens(color2);
82
+ return (Math.max(lum1, lum2) + 0.05) / (Math.min(lum1, lum2) + 0.05);
83
+ function calcLumens(color) {
84
+ const { r, g, b } = parseColor(color) ?? { r: 0, g: 0, b: 0, a: 1 };
85
+ const gamma = 2.2;
86
+ const normR = r / 255;
87
+ const normG = g / 255;
88
+ const normB = b / 255;
89
+ const sR = normR <= 0.03928 ? normR / 12.92 : Math.pow((normR + 0.055) / 1.055, gamma);
90
+ const sG = normG <= 0.03928 ? normG / 12.92 : Math.pow((normG + 0.055) / 1.055, gamma);
91
+ const sB = normB <= 0.03928 ? normB / 12.92 : Math.pow((normB + 0.055) / 1.055, gamma);
92
+ return 0.2126 * sR + 0.7152 * sG + 0.0722 * sB;
93
+ }
94
+ }
95
+ function colorContrast(color1, color2) {
96
+ return colorContrastValue(color1, color2).toFixed(2);
97
+ }
98
+ function hsv2rgb(h, s, v, a) {
99
+ let r, g, b;
100
+ if (typeof h === "object" && h !== null) {
101
+ s = h.s;
102
+ v = h.v;
103
+ a = h.a;
104
+ h = h.h;
105
+ }
106
+ h = h / 360;
107
+ s = s / 100;
108
+ v = v / 100;
109
+ const i = Math.floor(h * 6);
110
+ const f = h * 6 - i;
111
+ const p = v * (1 - s);
112
+ const q = v * (1 - f * s);
113
+ const t = v * (1 - (1 - f) * s);
114
+ switch (i % 6) {
115
+ case 0:
116
+ r = v, g = t, b = p;
117
+ break;
118
+ case 1:
119
+ r = q, g = v, b = p;
120
+ break;
121
+ case 2:
122
+ r = p, g = v, b = t;
123
+ break;
124
+ case 3:
125
+ r = p, g = q, b = v;
126
+ break;
127
+ case 4:
128
+ r = t, g = p, b = v;
129
+ break;
130
+ case 5:
131
+ r = v, g = p, b = q;
132
+ break;
133
+ }
134
+ return {
135
+ r: Math.round((r ?? 0) * 255),
136
+ g: Math.round((g ?? 0) * 255),
137
+ b: Math.round((b ?? 0) * 255),
138
+ a: a != null ? a : 1
139
+ };
140
+ }
141
+ function rgb2hsv(r, g, b, a) {
142
+ if (typeof r === "object" && r !== null) {
143
+ g = r.g;
144
+ b = r.b;
145
+ a = r.a;
146
+ r = r.r;
147
+ }
148
+ const max = Math.max(r, g, b), min = Math.min(r, g, b), d = max - min;
149
+ let h;
150
+ const s = max === 0 ? 0 : d / max, v = max / 255;
151
+ switch (max) {
152
+ case min:
153
+ h = 0;
154
+ break;
155
+ case r:
156
+ h = g - b + d * (g < b ? 6 : 0);
157
+ h /= 6 * d;
158
+ break;
159
+ case g:
160
+ h = b - r + d * 2;
161
+ h /= 6 * d;
162
+ break;
163
+ case b:
164
+ h = r - g + d * 4;
165
+ h /= 6 * d;
166
+ break;
167
+ }
168
+ return {
169
+ h: Math.round((h ?? 0) * 360),
170
+ s: Math.round(s * 100),
171
+ v: Math.round(v * 100),
172
+ a: a != null ? a : 1
173
+ };
174
+ }
175
+
176
+ // src/tsutils-string.ts
177
+ function stripSpaces(html) {
178
+ if (html == null) return html;
179
+ switch (typeof html) {
180
+ case "number":
181
+ break;
182
+ case "string":
183
+ html = String(html).replace(/(?:\r\n|\r|\n)/g, " ").replace(/\s\s+/g, " ").trim();
184
+ break;
185
+ case "object":
186
+ if (Array.isArray(html)) {
187
+ const arr = extend([], html);
188
+ arr.forEach((key, ind) => {
189
+ arr[ind] = stripSpaces(key);
190
+ });
191
+ return arr;
192
+ } else {
193
+ const obj = extend({}, html);
194
+ Object.keys(obj).forEach((key) => {
195
+ obj[key] = stripSpaces(obj[key]);
196
+ });
197
+ return obj;
198
+ }
199
+ }
200
+ return html;
201
+ }
202
+ function stripTags(html) {
203
+ if (html == null) return html;
204
+ switch (typeof html) {
205
+ case "number":
206
+ break;
207
+ case "string":
208
+ html = String(html).replace(/<(?:[^>=]|='[^']*'|="[^"]*"|=[^'"][^\s>]*)*>/ig, "");
209
+ break;
210
+ case "object":
211
+ if (Array.isArray(html)) {
212
+ const arr = extend([], html);
213
+ arr.forEach((key, ind) => {
214
+ arr[ind] = stripTags(key);
215
+ });
216
+ return arr;
217
+ } else {
218
+ const obj = extend({}, html);
219
+ Object.keys(obj).forEach((key) => {
220
+ obj[key] = stripTags(obj[key]);
221
+ });
222
+ return obj;
223
+ }
224
+ }
225
+ return html;
226
+ }
227
+ function encodeTags(html) {
228
+ if (html == null) return html;
229
+ switch (typeof html) {
230
+ case "number":
231
+ break;
232
+ case "string":
233
+ html = String(html).replace(/&/g, "&amp;").replace(/>/g, "&gt;").replace(/</g, "&lt;").replace(/"/g, "&quot;");
234
+ break;
235
+ case "object":
236
+ if (Array.isArray(html)) {
237
+ const arr = extend([], html);
238
+ arr.forEach((key, ind) => {
239
+ arr[ind] = encodeTags(key);
240
+ });
241
+ return arr;
242
+ } else {
243
+ const obj = extend({}, html);
244
+ Object.keys(obj).forEach((key) => {
245
+ obj[key] = encodeTags(obj[key]);
246
+ });
247
+ return obj;
248
+ }
249
+ }
250
+ return html;
251
+ }
252
+ function decodeTags(html) {
253
+ if (html == null) return html;
254
+ switch (typeof html) {
255
+ case "number":
256
+ break;
257
+ case "string":
258
+ html = String(html).replace(/&gt;/g, ">").replace(/&lt;/g, "<").replace(/&quot;/g, '"').replace(/&amp;/g, "&");
259
+ break;
260
+ case "object":
261
+ if (Array.isArray(html)) {
262
+ const arr = extend([], html);
263
+ arr.forEach((key, ind) => {
264
+ arr[ind] = decodeTags(key);
265
+ });
266
+ return arr;
267
+ } else {
268
+ const obj = extend({}, html);
269
+ Object.keys(obj).forEach((key) => {
270
+ obj[key] = decodeTags(obj[key]);
271
+ });
272
+ return obj;
273
+ }
274
+ }
275
+ return html;
276
+ }
277
+ function escapeId(id) {
278
+ if (id === "" || id == null) return "";
279
+ const re = /([\0-\x1f\x7f]|^-?\d)|^-$|[^\0-\x1f\x7f-￿\w-]/g;
280
+ return (id + "").replace(re, (ch, asCodePoint) => {
281
+ if (asCodePoint) {
282
+ if (ch === "\0") return "\uFFFD";
283
+ return ch.slice(0, -1) + "\\" + ch.charCodeAt(ch.length - 1).toString(16) + " ";
284
+ }
285
+ return "\\" + ch;
286
+ });
287
+ }
288
+ function unescapeId(id) {
289
+ if (id === "" || id == null) return "";
290
+ const re = /\\[\da-fA-F]{1,6}[\x20\t\r\n\f]?|\\([^\r\n\f])/g;
291
+ return id.replace(re, (escape, nonHex) => {
292
+ const high = parseInt("0x" + escape.slice(1), 16) - 65536;
293
+ return nonHex ? nonHex : high < 0 ? String.fromCharCode(high + 65536) : String.fromCharCode(high >> 10 | 55296, high & 1023 | 56320);
294
+ });
295
+ }
296
+ function base64encode(str) {
297
+ const utf8Bytes = new TextEncoder().encode(str);
298
+ let binaryString = "";
299
+ for (const byte of utf8Bytes) {
300
+ binaryString += String.fromCharCode(byte);
301
+ }
302
+ return btoa(binaryString);
303
+ }
304
+ function base64decode(encodedStr) {
305
+ const binaryString = atob(encodedStr);
306
+ const utf8Bytes = new Uint8Array(binaryString.length);
307
+ for (let i = 0; i < binaryString.length; i++) {
308
+ utf8Bytes[i] = binaryString.charCodeAt(i);
309
+ }
310
+ return new TextDecoder().decode(utf8Bytes);
311
+ }
312
+ async function sha256(str) {
313
+ const utf8 = new TextEncoder().encode(str);
314
+ return crypto.subtle.digest("SHA-256", utf8).then((hashBuffer) => {
315
+ const hashArray = Array.from(new Uint8Array(hashBuffer));
316
+ return hashArray.map((bytes) => bytes.toString(16).padStart(2, "0")).join("");
317
+ });
318
+ }
319
+ function execTemplate(str, replace_obj) {
320
+ if (typeof str !== "string" || !replace_obj || typeof replace_obj !== "object") {
321
+ return str;
322
+ }
323
+ return str.replace(/\${([^}]+)?}/g, function(_$1, $2) {
324
+ return replace_obj[$2] || $2;
325
+ });
326
+ }
327
+
328
+ // src/tsutils-marker.ts
329
+ var query2 = query;
330
+ function _clearMarkers(el, options) {
331
+ const markerRE = new RegExp(`<${options.tag}[^>]*class=["']${options.class.replace(/-/g, "\\-")}["'][^>]*>([\\s\\S]*?)<\\/${options.tag}>`, "ig");
332
+ if (typeof el == "string") {
333
+ while (el.indexOf(`<${options.tag} class="${options.class}"`) !== -1) {
334
+ el = el.replace(markerRE, "$1");
335
+ }
336
+ } else {
337
+ while (el.innerHTML.indexOf(`<${options.tag} class="${options.class}"`) !== -1) {
338
+ el.innerHTML = el.innerHTML.replace(markerRE, "$1");
339
+ }
340
+ }
341
+ }
342
+ function _replace(html, term, replaceWith, options) {
343
+ const ww = options.wholeWord;
344
+ if (typeof term !== "string") term = String(term);
345
+ term = term.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&").replace(/&/g, "&amp;").replace(/</g, "&gt;").replace(/>/g, "&lt;");
346
+ const regex = new RegExp((ww ? "\\b" : "") + term + (ww ? "\\b" : "") + "(?![^<]*>)", "i" + (!options.onlyFirst ? "g" : ""));
347
+ return html = html.replace(regex, replaceWith);
348
+ }
349
+ function marker(el, items, options = { onlyFirst: false, wholeWord: false, isRegex: false }) {
350
+ options.tag ??= "span";
351
+ options.class ??= "tsg-marker";
352
+ options.raplace = (matched) => `<${options.tag} class="${options.class}">${matched}</${options.tag}>`;
353
+ const isRegexSearch = options.isRegex || false;
354
+ if (!Array.isArray(items)) {
355
+ if (items != null && items !== "") {
356
+ items = [items];
357
+ } else {
358
+ items = [];
359
+ }
360
+ }
361
+ if (typeof el == "string") {
362
+ _clearMarkers(el, options);
363
+ items.forEach((item) => {
364
+ if (isRegexSearch) {
365
+ try {
366
+ const flags = "i" + (!options.onlyFirst ? "g" : "");
367
+ const regex = new RegExp(item, flags);
368
+ el = el.replace(regex, options.raplace);
369
+ } catch (e) {
370
+ console.error("Invalid regular expression:", e);
371
+ el = _replace(el, item, options.raplace, options);
372
+ }
373
+ } else {
374
+ el = _replace(el, item, options.raplace, options);
375
+ }
376
+ });
377
+ } else {
378
+ query2(el).each((el2) => {
379
+ _clearMarkers(el2, options);
380
+ if (isRegexSearch) {
381
+ items.forEach((pattern) => {
382
+ try {
383
+ let getTextNodes2 = function(node) {
384
+ if (node.nodeType === 3) {
385
+ textNodes.push(node);
386
+ } else if (node.nodeType === 1) {
387
+ if (node.tagName !== "SCRIPT" && node.tagName !== "STYLE") {
388
+ for (let i = 0; i < node.childNodes.length; i++) {
389
+ getTextNodes2(node.childNodes[i]);
390
+ }
391
+ }
392
+ }
393
+ };
394
+ var getTextNodes = getTextNodes2;
395
+ let flags = "i";
396
+ if (!options.onlyFirst) {
397
+ flags += "g";
398
+ }
399
+ if (options.wholeWord) {
400
+ pattern = "\b" + pattern + "\b";
401
+ }
402
+ const regex = new RegExp(pattern, flags);
403
+ const textNodes = [];
404
+ getTextNodes2(el2);
405
+ textNodes.forEach((textNode) => {
406
+ const text = textNode.nodeValue;
407
+ const matches = [];
408
+ let match;
409
+ if (options.onlyFirst) {
410
+ match = regex.exec(text);
411
+ if (match) matches.push({
412
+ index: match.index,
413
+ text: match[0]
414
+ });
415
+ } else {
416
+ while ((match = regex.exec(text)) !== null) {
417
+ matches.push({
418
+ index: match.index,
419
+ text: match[0]
420
+ });
421
+ }
422
+ }
423
+ if (matches.length > 0) {
424
+ const parent = textNode.parentNode;
425
+ const fragment = document.createDocumentFragment();
426
+ let lastIndex = 0;
427
+ matches.forEach((match2) => {
428
+ if (match2.index > lastIndex) {
429
+ fragment.appendChild(document.createTextNode(
430
+ text.substring(lastIndex, match2.index)
431
+ ));
432
+ }
433
+ const span = document.createElement(options.tag);
434
+ span.className = options.class;
435
+ span.appendChild(document.createTextNode(match2.text));
436
+ fragment.appendChild(span);
437
+ lastIndex = match2.index + match2.text.length;
438
+ });
439
+ if (lastIndex < text.length) {
440
+ fragment.appendChild(document.createTextNode(
441
+ text.substring(lastIndex)
442
+ ));
443
+ }
444
+ parent.replaceChild(fragment, textNode);
445
+ }
446
+ });
447
+ } catch (e) {
448
+ console.error("Invalid regular expression:", e);
449
+ el2.innerHTML = _replace(el2.innerHTML, pattern, options.raplace, options);
450
+ }
451
+ });
452
+ } else {
453
+ items.forEach((item) => {
454
+ ;
455
+ el2.innerHTML = _replace(el2.innerHTML, item, options.raplace, options);
456
+ });
457
+ }
458
+ });
459
+ }
460
+ return el;
461
+ }
462
+
463
+ // src/tsutils-notify.ts
464
+ var query3 = query;
465
+ function notify(text, options, deps) {
466
+ return new Promise((resolve) => {
467
+ let opts = options ?? {};
468
+ let textStr = "";
469
+ if (typeof text == "object") {
470
+ opts = text;
471
+ textStr = String(opts["text"] ?? "");
472
+ } else {
473
+ textStr = String(text ?? "");
474
+ }
475
+ opts["where"] ??= document.body;
476
+ opts["timeout"] ??= 15e3;
477
+ if (typeof deps.tmpSlot["notify_resolve"] == "function") {
478
+ ;
479
+ deps.tmpSlot["notify_resolve"]();
480
+ query3(deps.tmpSlot["notify_where"]).find("#tsg-notify").remove();
481
+ }
482
+ deps.tmpSlot["notify_resolve"] = resolve;
483
+ deps.tmpSlot["notify_where"] = opts["where"];
484
+ clearTimeout(deps.tmpSlot["notify_timer"]);
485
+ const where = opts["where"];
486
+ if (textStr) {
487
+ if (typeof opts["actions"] == "object") {
488
+ const actions = {};
489
+ Object.keys(opts["actions"]).forEach((action) => {
490
+ actions[action] = `<a class="tsg-notify-link" value="${action}">${action}</a>`;
491
+ });
492
+ textStr = deps.execTemplate(textStr, actions);
493
+ }
494
+ const html = `
495
+ <div id="tsg-notify" style="${where == document.body ? "position: fixed" : ""}">
496
+ <div class="${opts["class"] ?? ""} ${opts["error"] ? "tsg-notify-error" : ""} ${opts["success"] ? "tsg-notify-success" : ""}">
497
+ ${textStr}
498
+ <span class="tsg-notify-close tsg-icon-cross"></span>
499
+ </div>
500
+ </div>`;
501
+ query3(where).append(html);
502
+ query3(where).find("#tsg-notify").find(".tsg-notify-close").on("click", (_event) => {
503
+ query3(where).find("#tsg-notify").remove();
504
+ resolve();
505
+ });
506
+ if (opts["actions"]) {
507
+ query3(where).find("#tsg-notify .tsg-notify-link").on("click", (event) => {
508
+ const value = query3(event.target).attr("value") ?? "";
509
+ opts["actions"][value]();
510
+ query3(where).find("#tsg-notify").remove();
511
+ resolve();
512
+ });
513
+ }
514
+ if (opts["timeout"] > 0) {
515
+ deps.tmpSlot["notify_timer"] = setTimeout(() => {
516
+ query3(where).find("#tsg-notify").remove();
517
+ resolve();
518
+ }, opts["timeout"]);
519
+ }
520
+ }
521
+ });
522
+ }
523
+
524
+ // src/tsutils-message.ts
525
+ var query4 = query;
526
+ function normButtons(options, btn, deps) {
527
+ options["actions"] = options["actions"] ?? {};
528
+ const btns = Object.keys(btn);
529
+ btns.forEach((name) => {
530
+ const action = options["btn_" + name];
531
+ if (action) {
532
+ btn[name] = {
533
+ text: deps.lang(String(action["text"] ?? btn[name] ?? "")),
534
+ class: action["class"] ?? "",
535
+ style: action["style"] ?? "",
536
+ attrs: action["attrs"] ?? ""
537
+ };
538
+ delete options["btn_" + name];
539
+ }
540
+ ;
541
+ ["text", "class", "style", "attrs"].forEach((suffix) => {
542
+ if (options[name + "_" + suffix]) {
543
+ if (typeof btn[name] == "string") {
544
+ btn[name] = { text: btn[name] };
545
+ }
546
+ ;
547
+ btn[name][suffix] = options[name + "_" + suffix];
548
+ delete options[name + "_" + suffix];
549
+ }
550
+ });
551
+ });
552
+ if (btns.includes("yes") && btns.includes("no")) {
553
+ if (deps.settings.macButtonOrder) {
554
+ deps.extend(options["actions"], { no: btn["no"], yes: btn["yes"] });
555
+ } else {
556
+ deps.extend(options["actions"], { yes: btn["yes"], no: btn["no"] });
557
+ }
558
+ }
559
+ if (btns.includes("ok") && btns.includes("cancel")) {
560
+ if (deps.settings.macButtonOrder) {
561
+ deps.extend(options["actions"], { cancel: btn["cancel"], ok: btn["ok"] });
562
+ } else {
563
+ deps.extend(options["actions"], { ok: btn["ok"], cancel: btn["cancel"] });
564
+ }
565
+ }
566
+ return options;
567
+ }
568
+ function _message(where, options, deps) {
569
+ let closeTimer, openTimer, edata;
570
+ let msgBase = {};
571
+ const removeLast = () => {
572
+ const msgs = query4(where?.box).find(".tsg-message");
573
+ if (msgs.length == 0) return;
574
+ msgBase = msgs.get(0)["_msg_options"] || {};
575
+ if (typeof msgBase?.close == "function") {
576
+ msgBase.close();
577
+ }
578
+ };
579
+ const closeComplete = (options2) => {
580
+ const msgBoxEl = options2["box"];
581
+ const focus = msgBoxEl?.["_msg_prevFocus"];
582
+ if (query4(where.box).find(".tsg-message").length <= 1) {
583
+ if (where.owner) {
584
+ where.owner.unlock?.(where.param, 150);
585
+ } else {
586
+ deps.unlock(where.box, 150);
587
+ }
588
+ } else {
589
+ query4(where.box).find(`#tsg-message-${where.owner?.name}-${options2["msgIndex"] - 1}`).css("z-index", "1500");
590
+ }
591
+ if (focus) {
592
+ const msg = query4(focus).closest(".tsg-message");
593
+ if (msg.length > 0) {
594
+ const opt = msg.get(0)["_msg_options"];
595
+ opt["setFocus"](focus);
596
+ } else {
597
+ focus.focus();
598
+ }
599
+ } else {
600
+ if (typeof where.owner?.focus == "function") where.owner.focus();
601
+ }
602
+ query4(options2["box"]).remove();
603
+ if (options2["msgIndex"] === 0) {
604
+ const tmp = options2["tmp"];
605
+ head.css("z-index", tmp.zIndex);
606
+ query4(where.box).css("overflow", tmp.overflow);
607
+ }
608
+ if (options2["trigger"]) {
609
+ ;
610
+ edata?.["finish"]?.();
611
+ }
612
+ };
613
+ if (typeof options == "string" || typeof options == "number") {
614
+ msgBase = {
615
+ width: String(options).length < 300 ? 350 : 550,
616
+ height: String(options).length < 300 ? 170 : 250,
617
+ text: String(options)
618
+ };
619
+ } else if (options == null) {
620
+ msgBase = where;
621
+ } else {
622
+ msgBase = options ?? {};
623
+ }
624
+ if ((msgBase.text === "" || msgBase.text == null) && (msgBase.body === "" || msgBase.body == null)) {
625
+ removeLast();
626
+ return;
627
+ }
628
+ if (msgBase.text != null) msgBase.body = `<div class="tsg-centered tsg-msg-text">${msgBase.text}</div>`;
629
+ if (msgBase.width == null) msgBase.width = 350;
630
+ if (msgBase.height == null) msgBase.height = 170;
631
+ if (msgBase.hideOn == null) msgBase.hideOn = ["esc"];
632
+ msgBase.cancelAction ??= "Ok";
633
+ if (msgBase.on == null) {
634
+ const opts = msgBase;
635
+ msgBase = new TsBase();
636
+ deps.extend(msgBase, opts);
637
+ }
638
+ const msgOpts = msgBase;
639
+ msgOpts["on"]("open", (event) => {
640
+ deps.bindEvents(query4(msgOpts["box"]).find(".tsg-eaction"), msgOpts);
641
+ const detail = event["detail"];
642
+ query4(detail["box"]).find("button, input, textarea, [name=hidden-first]").off(".message").on("keydown.message", function(evt) {
643
+ const keyEvt = evt;
644
+ if (keyEvt.keyCode == 27 && msgOpts["hideOn"].includes("esc")) {
645
+ if (msgOpts["cancelAction"]) {
646
+ ;
647
+ msgOpts["action"](msgOpts["cancelAction"]);
648
+ } else {
649
+ ;
650
+ msgOpts["close"]();
651
+ }
652
+ }
653
+ });
654
+ setTimeout(() => msgOpts["setFocus"](msgOpts["focus"]), 300);
655
+ });
656
+ msgOpts["off"](".prom");
657
+ const prom = {
658
+ self: msgBase,
659
+ action(callBack) {
660
+ ;
661
+ msgOpts["on"]("action.prom", callBack);
662
+ return prom;
663
+ },
664
+ close(callBack) {
665
+ ;
666
+ msgOpts["on"]("close.prom", callBack);
667
+ return prom;
668
+ },
669
+ open(callBack) {
670
+ ;
671
+ msgOpts["on"]("open.prom", callBack);
672
+ return prom;
673
+ },
674
+ then(callBack) {
675
+ ;
676
+ msgOpts["on"]("open:after.prom", callBack);
677
+ return prom;
678
+ }
679
+ };
680
+ if (msgBase.actions == null && msgBase.buttons == null && msgBase.html == null) {
681
+ msgBase.actions = { Ok(event) {
682
+ event["detail"]?.["self"]?.["close"]?.();
683
+ } };
684
+ }
685
+ ;
686
+ msgOpts["off"](".buttons");
687
+ if (msgBase.actions != null) {
688
+ msgBase.buttons = "";
689
+ Object.keys(msgBase.actions).forEach((action) => {
690
+ const handler = msgBase.actions[action];
691
+ let btnAction = action;
692
+ if (typeof handler == "function") {
693
+ msgBase.buttons += `<button class="tsg-btn tsg-eaction" data-click='["action","${action}","event"]' name="${action}">${action}</button>`;
694
+ }
695
+ if (typeof handler == "object" && handler !== null) {
696
+ const h = handler;
697
+ msgBase.buttons += `<button class="tsg-btn tsg-eaction ${h["class"] || ""}" name="${action}" data-click='["action","${action}","event"]'
698
+ style="${h["style"] ?? ""}" ${h["attrs"] ?? ""}>${h["text"] || action}</button>`;
699
+ btnAction = Array.isArray(msgBase.actions) ? String(h["text"]) : action;
700
+ }
701
+ if (typeof handler == "string") {
702
+ msgBase.buttons += `<button class="tsg-btn tsg-eaction" name="${handler}" data-click='["action","${handler}","event"]'>${handler}</button>`;
703
+ btnAction = handler;
704
+ }
705
+ if (typeof btnAction == "string") {
706
+ btnAction = (btnAction[0] ?? "").toLowerCase() + btnAction.substr(1).replace(/\s+/g, "");
707
+ }
708
+ prom[btnAction] = function(callBack) {
709
+ ;
710
+ msgOpts["on"]("action.buttons", (event) => {
711
+ const detail = event["detail"];
712
+ const act = String(detail["action"]);
713
+ const target = (act[0] ?? "").toLowerCase() + act.substr(1).replace(/\s+/g, "");
714
+ if (target == btnAction) callBack(event);
715
+ });
716
+ return prom;
717
+ };
718
+ });
719
+ }
720
+ ;
721
+ ["html", "body", "buttons"].forEach((param) => {
722
+ msgBase[param] = String(msgBase[param] ?? "").trim();
723
+ });
724
+ if (msgBase.body !== "" || msgBase.buttons !== "") {
725
+ msgBase.html = `
726
+ <div class="tsg-message-body">${msgBase.body || ""}</div>
727
+ <div class="tsg-message-buttons">${msgBase.buttons || ""}</div>
728
+ `;
729
+ }
730
+ let styles = getComputedStyle(query4(where.box).get(0));
731
+ const pWidth = parseFloat(styles.width);
732
+ const pHeight = parseFloat(styles.height);
733
+ let titleHeight = 0;
734
+ if (query4(where.after).length > 0) {
735
+ styles = getComputedStyle(query4(where.after).get(0));
736
+ titleHeight = parseInt(styles.display != "none" ? styles.height : "0");
737
+ }
738
+ if ((msgBase.width ?? 0) > pWidth) msgBase.width = pWidth - 10;
739
+ if ((msgBase.height ?? 0) > pHeight - titleHeight) msgBase.height = pHeight - 10 - titleHeight;
740
+ if (msgBase.width != null) msgBase.originalWidth = msgBase.width;
741
+ if (msgBase.height != null) msgBase.originalHeight = msgBase.height;
742
+ if (parseInt(String(msgBase.width)) < 0) msgBase.width = pWidth + (msgBase.width ?? 0);
743
+ if (parseInt(String(msgBase.width)) < 10) msgBase.width = 10;
744
+ if (parseInt(String(msgBase.height)) < 0) msgBase.height = pHeight + (msgBase.height ?? 0) - titleHeight;
745
+ if (parseInt(String(msgBase.height)) < 10) msgBase.height = 10;
746
+ if ((msgBase.originalHeight ?? 0) < 0) msgBase.height = pHeight + (msgBase.originalHeight ?? 0) - titleHeight;
747
+ if ((msgBase.originalWidth ?? 0) < 0) msgBase.width = pWidth + (msgBase.originalWidth ?? 0) * 2;
748
+ const head = query4(where.box).find(where.after);
749
+ if (!msgBase.tmp) {
750
+ msgBase.tmp = {
751
+ zIndex: String(head.css("z-index")),
752
+ overflow: styles.overflow
753
+ };
754
+ }
755
+ if (msgBase.html === "" && msgBase.body === "" && msgBase.buttons === "") {
756
+ removeLast();
757
+ } else {
758
+ msgBase.msgIndex = query4(where.box).find(".tsg-message").length;
759
+ if (msgBase.msgIndex === 0 && typeof deps.lock == "function") {
760
+ query4(where.box).css("overflow", "hidden");
761
+ if (where.owner) {
762
+ ;
763
+ where.owner.lock?.(where.param);
764
+ } else {
765
+ deps.lock(where.box);
766
+ }
767
+ }
768
+ query4(where.box).find(".tsg-message").css("z-index", "1390");
769
+ head.css("z-index", "1501");
770
+ const content = `
771
+ <div id="tsg-message-${where.owner?.name}-${msgBase.msgIndex}" class="tsg-message" data-mousedown="stop"
772
+ style="z-index: 1500; left: ${(pWidth - (msgBase.width ?? 0)) / 2}px; top: ${titleHeight}px;
773
+ width: ${msgBase.width}px; height: ${msgBase.height}px; transform: translateY(-${msgBase.height}px)"
774
+ ${(msgBase.hideOn ?? []).includes("click") ? where.param ? `data-click='["message", "${where.param}"]` : 'data-click="message"' : ""}>
775
+ <span name="hidden-first" tabindex="0" style="position: absolute; top: 0; outline: none"></span>
776
+ ${msgBase.html}
777
+ <span name="hidden-last" tabindex="0" style="position: absolute; top: 0; outline: none"></span>
778
+ </div>`;
779
+ if (query4(where.after).length > 0) {
780
+ query4(where.box).find(where.after).after(content);
781
+ } else {
782
+ query4(where.box).prepend(content);
783
+ }
784
+ msgBase.box = query4(where.box).find(`#tsg-message-${where.owner?.name}-${msgBase.msgIndex}`)[0];
785
+ deps.bindEvents(msgBase.box, deps.self);
786
+ query4(msgBase.box).addClass("animating");
787
+ msgBase.box["_msg_options"] = msgBase;
788
+ msgBase.box["_msg_prevFocus"] = document.activeElement;
789
+ setTimeout(() => {
790
+ edata = msgOpts["trigger"]("open", { target: deps.ownerName, box: msgBase.box, self: msgBase });
791
+ const edataR = edata;
792
+ if (edataR["isCancelled"] === true) {
793
+ query4(where.box).find(`#tsg-message-${where.owner?.name}-${msgBase.msgIndex}`).remove();
794
+ if (msgBase.msgIndex === 0) {
795
+ head.css("z-index", msgBase.tmp.zIndex);
796
+ query4(where.box).css("overflow", msgBase.tmp.overflow);
797
+ }
798
+ return;
799
+ }
800
+ query4(msgBase.box).css({
801
+ transition: "0.3s",
802
+ transform: "translateY(0px)"
803
+ });
804
+ }, 0);
805
+ openTimer = setTimeout(() => {
806
+ query4(where.box).find(`#tsg-message-${where.owner?.name}-${msgBase.msgIndex}`).removeClass("animating").css({ "transition": "0s" });
807
+ edata?.["finish"]?.();
808
+ }, 300);
809
+ }
810
+ msgBase.action = (action, event) => {
811
+ let click = msgBase.actions?.[action];
812
+ if (click instanceof Object && click["onClick"]) click = click["onClick"];
813
+ const edata2 = msgOpts["trigger"]("action", {
814
+ target: deps.ownerName,
815
+ action,
816
+ self: msgBase,
817
+ originalEvent: event,
818
+ value: msgBase.input ? msgBase.input.value : null
819
+ });
820
+ const edataR = edata2;
821
+ if (edataR["isCancelled"] === true) return;
822
+ if (typeof click === "function") click(edata2);
823
+ edataR["finish"]?.();
824
+ };
825
+ msgBase.close = () => {
826
+ edata = msgOpts["trigger"]("close", { target: "self", box: msgBase.box, self: msgBase });
827
+ const edataR = edata;
828
+ if (edataR["isCancelled"] === true) return;
829
+ clearTimeout(openTimer);
830
+ if (query4(msgBase.box).hasClass("animating")) {
831
+ clearTimeout(closeTimer);
832
+ closeComplete(msgOpts);
833
+ return;
834
+ }
835
+ query4(msgBase.box).addClass("tsg-closing animating").css({
836
+ "transition": "0.15s",
837
+ "transform": "translateY(-" + msgBase.height + "px)"
838
+ });
839
+ if ((msgBase.msgIndex ?? 0) !== 0) {
840
+ query4(where.box).find(`#tsg-message-${where.owner?.name}-${(msgBase.msgIndex ?? 1) - 1}`).css("z-index", "1499");
841
+ }
842
+ closeTimer = setTimeout(() => {
843
+ closeComplete(msgOpts);
844
+ }, 150);
845
+ };
846
+ msgBase.setFocus = (focus) => {
847
+ const cnt = query4(where.box).find(".tsg-message").length - 1;
848
+ const box = query4(where.box).find(`#tsg-message-${where.owner?.name}-${cnt}`);
849
+ const sel = "input, button, select, textarea, [contentEditable], .tsg-input";
850
+ if (focus != null) {
851
+ const el = typeof focus === "string" ? box.find(sel).filter(focus).get(0) : box.find(sel).get(focus);
852
+ el?.focus();
853
+ } else {
854
+ box.find("[name=hidden-first]").get(0)?.focus();
855
+ }
856
+ query4(where.box).find(".tsg-message").find(sel + ",[name=hidden-first],[name=hidden-last]").off(".keep-focus");
857
+ query4(box).find(sel + ",[name=hidden-first],[name=hidden-last]").on("blur.keep-focus", function(_event) {
858
+ setTimeout(() => {
859
+ const focus2 = document.activeElement;
860
+ const inside = focus2 != null && query4(box).find(sel).filter(focus2).length > 0;
861
+ const name = query4(focus2).attr("name");
862
+ if (!inside && focus2 && focus2 !== document.body) {
863
+ query4(box).find(sel).get(0)?.focus();
864
+ }
865
+ if (name == "hidden-last") {
866
+ query4(box).find(sel).get(0)?.focus();
867
+ }
868
+ if (name == "hidden-first") {
869
+ query4(box).find(sel).get(-1)?.focus();
870
+ }
871
+ }, 1);
872
+ });
873
+ };
874
+ return prom;
875
+ }
876
+ function _alert(where, options, deps) {
877
+ return _message(where, options, deps);
878
+ }
879
+ function _confirm(where, options, deps) {
880
+ let msgOpts = {};
881
+ if (["string", "number"].includes(typeof options)) {
882
+ msgOpts = { text: options };
883
+ } else if (options == null) {
884
+ msgOpts = where;
885
+ } else {
886
+ msgOpts = options ?? {};
887
+ }
888
+ deps.normButtons(msgOpts, { yes: "Yes", no: "No" });
889
+ msgOpts["cancelAction"] ??= "No";
890
+ const prom = deps.message(where, msgOpts);
891
+ if (prom) {
892
+ prom.action((event) => {
893
+ const d = event["detail"];
894
+ const self = d?.["self"];
895
+ self?.["close"]?.();
896
+ });
897
+ }
898
+ return prom;
899
+ }
900
+ function _prompt(where, options, deps) {
901
+ let msgOpts = {};
902
+ if (["string", "number"].includes(typeof options)) {
903
+ msgOpts = { label: options };
904
+ } else if (options == null) {
905
+ msgOpts = where;
906
+ } else {
907
+ msgOpts = options ?? {};
908
+ }
909
+ msgOpts["cancelAction"] ??= "Cancel";
910
+ if (msgOpts["label"]) {
911
+ msgOpts["focus"] = 0;
912
+ msgOpts["body"] = msgOpts["textarea"] ? `<div class="tsg-prompt textarea">
913
+ <div>${msgOpts["label"]}</div>
914
+ <textarea id="TsPrompt" class="tsg-input" ${msgOpts["attrs"] ?? ""}
915
+ data-keydown="keydown|event" data-keyup="change|event"></textarea>
916
+ </div>` : `<div class="tsg-prompt tsg-centered">
917
+ <label>${msgOpts["label"]}&nbsp;</label>
918
+ <input id="TsPrompt" class="tsg-input" ${msgOpts["attrs"] ?? ""}
919
+ data-keydown="keydown|event" data-keyup="change|event">
920
+ </div>`;
921
+ }
922
+ deps.normButtons(msgOpts, { ok: deps.lang("Ok"), cancel: deps.lang("Cancel") });
923
+ const prom = deps.message(where, msgOpts);
924
+ if (prom) {
925
+ prom.change = function(callBack) {
926
+ const selfR = prom.self;
927
+ selfR?.["on"]?.("change.prom", callBack);
928
+ return prom;
929
+ };
930
+ prom.action((event) => {
931
+ const d = event["detail"];
932
+ const self = d?.["self"];
933
+ self?.["close"]?.();
934
+ }).then((event) => {
935
+ const d = event["detail"];
936
+ (d?.["self"])["input"] = query4(d?.["box"]).find("#TsPrompt").get(0);
937
+ query4(d?.["box"]).find("#TsPrompt").on("keydown", (evt) => {
938
+ if (evt.keyCode == 13 && evt.shiftKey === false) {
939
+ evt.preventDefault();
940
+ }
941
+ }).on("keyup", (evt) => {
942
+ const self = d?.["self"];
943
+ const edata = self?.["trigger"]?.("change", { value: evt.target.value, input: evt.target, originalEvent: evt });
944
+ if (evt.keyCode == 13 && evt.shiftKey === false) {
945
+ ;
946
+ self?.["action"]?.("Ok", evt);
947
+ }
948
+ ;
949
+ edata?.["finish"]?.();
950
+ });
951
+ });
952
+ }
953
+ return prom;
954
+ }
955
+
956
+ // src/tsutils-dom.ts
957
+ var query5 = query;
958
+ function transition(divOld, divNew, type, callBack) {
959
+ return new Promise((resolve, _reject) => {
960
+ const styles = getComputedStyle(divOld);
961
+ const width = parseInt(styles.width);
962
+ const height = parseInt(styles.height);
963
+ const time = 0.5;
964
+ if (!divOld || !divNew) {
965
+ console.log("ERROR: Cannot do transition when one of the divs is null");
966
+ return;
967
+ }
968
+ ;
969
+ divOld.parentNode.style.cssText += "perspective: 900px; overflow: hidden;";
970
+ divOld.style.cssText += "; position: absolute; z-index: 1019; backface-visibility: hidden";
971
+ divNew.style.cssText += "; position: absolute; z-index: 1020; backface-visibility: hidden";
972
+ switch (type) {
973
+ case "slide-left":
974
+ divOld.style.cssText += "overflow: hidden; transform: translate3d(0, 0, 0)";
975
+ divNew.style.cssText += "overflow: hidden; transform: translate3d(" + width + "px, 0, 0)";
976
+ query5(divNew).show();
977
+ setTimeout(() => {
978
+ divNew.style.cssText += "transition: " + time + "s; transform: translate3d(0, 0, 0)";
979
+ divOld.style.cssText += "transition: " + time + "s; transform: translate3d(-" + width + "px, 0, 0)";
980
+ }, 1);
981
+ break;
982
+ case "slide-right":
983
+ divOld.style.cssText += "overflow: hidden; transform: translate3d(0, 0, 0)";
984
+ divNew.style.cssText += "overflow: hidden; transform: translate3d(-" + width + "px, 0, 0)";
985
+ query5(divNew).show();
986
+ setTimeout(() => {
987
+ divNew.style.cssText += "transition: " + time + "s; transform: translate3d(0px, 0, 0)";
988
+ divOld.style.cssText += "transition: " + time + "s; transform: translate3d(" + width + "px, 0, 0)";
989
+ }, 1);
990
+ break;
991
+ case "slide-down":
992
+ divOld.style.cssText += "overflow: hidden; z-index: 1; transform: translate3d(0, 0, 0)";
993
+ divNew.style.cssText += "overflow: hidden; z-index: 0; transform: translate3d(0, 0, 0)";
994
+ query5(divNew).show();
995
+ setTimeout(() => {
996
+ divNew.style.cssText += "transition: " + time + "s; transform: translate3d(0, 0, 0)";
997
+ divOld.style.cssText += "transition: " + time + "s; transform: translate3d(0, " + height + "px, 0)";
998
+ }, 1);
999
+ break;
1000
+ case "slide-up":
1001
+ divOld.style.cssText += "overflow: hidden; transform: translate3d(0, 0, 0)";
1002
+ divNew.style.cssText += "overflow: hidden; transform: translate3d(0, " + height + "px, 0)";
1003
+ query5(divNew).show();
1004
+ setTimeout(() => {
1005
+ divNew.style.cssText += "transition: " + time + "s; transform: translate3d(0, 0, 0)";
1006
+ divOld.style.cssText += "transition: " + time + "s; transform: translate3d(0, 0, 0)";
1007
+ }, 1);
1008
+ break;
1009
+ case "flip-left":
1010
+ divOld.style.cssText += "overflow: hidden; transform: rotateY(0deg)";
1011
+ divNew.style.cssText += "overflow: hidden; transform: rotateY(-180deg)";
1012
+ query5(divNew).show();
1013
+ setTimeout(() => {
1014
+ divNew.style.cssText += "transition: " + time + "s; transform: rotateY(0deg)";
1015
+ divOld.style.cssText += "transition: " + time + "s; transform: rotateY(180deg)";
1016
+ }, 1);
1017
+ break;
1018
+ case "flip-right":
1019
+ divOld.style.cssText += "overflow: hidden; transform: rotateY(0deg)";
1020
+ divNew.style.cssText += "overflow: hidden; transform: rotateY(180deg)";
1021
+ query5(divNew).show();
1022
+ setTimeout(() => {
1023
+ divNew.style.cssText += "transition: " + time + "s; transform: rotateY(0deg)";
1024
+ divOld.style.cssText += "transition: " + time + "s; transform: rotateY(-180deg)";
1025
+ }, 1);
1026
+ break;
1027
+ case "flip-down":
1028
+ divOld.style.cssText += "overflow: hidden; transform: rotateX(0deg)";
1029
+ divNew.style.cssText += "overflow: hidden; transform: rotateX(180deg)";
1030
+ query5(divNew).show();
1031
+ setTimeout(() => {
1032
+ divNew.style.cssText += "transition: " + time + "s; transform: rotateX(0deg)";
1033
+ divOld.style.cssText += "transition: " + time + "s; transform: rotateX(-180deg)";
1034
+ }, 1);
1035
+ break;
1036
+ case "flip-up":
1037
+ divOld.style.cssText += "overflow: hidden; transform: rotateX(0deg)";
1038
+ divNew.style.cssText += "overflow: hidden; transform: rotateX(-180deg)";
1039
+ query5(divNew).show();
1040
+ setTimeout(() => {
1041
+ divNew.style.cssText += "transition: " + time + "s; transform: rotateX(0deg)";
1042
+ divOld.style.cssText += "transition: " + time + "s; transform: rotateX(180deg)";
1043
+ }, 1);
1044
+ break;
1045
+ case "pop-in":
1046
+ divOld.style.cssText += "overflow: hidden; transform: translate3d(0, 0, 0)";
1047
+ divNew.style.cssText += "overflow: hidden; transform: translate3d(0, 0, 0); transform: scale(.8); opacity: 0;";
1048
+ query5(divNew).show();
1049
+ setTimeout(() => {
1050
+ divNew.style.cssText += "transition: " + time + "s; transform: scale(1); opacity: 1;";
1051
+ divOld.style.cssText += "transition: " + time + "s;";
1052
+ }, 1);
1053
+ break;
1054
+ case "pop-out":
1055
+ divOld.style.cssText += "overflow: hidden; transform: translate3d(0, 0, 0); transform: scale(1); opacity: 1;";
1056
+ divNew.style.cssText += "overflow: hidden; transform: translate3d(0, 0, 0); opacity: 0;";
1057
+ query5(divNew).show();
1058
+ setTimeout(() => {
1059
+ divNew.style.cssText += "transition: " + time + "s; opacity: 1;";
1060
+ divOld.style.cssText += "transition: " + time + "s; transform: scale(1.7); opacity: 0;";
1061
+ }, 1);
1062
+ break;
1063
+ default:
1064
+ divOld.style.cssText += "overflow: hidden; transform: translate3d(0, 0, 0)";
1065
+ divNew.style.cssText += "overflow: hidden; translate3d(0, 0, 0); opacity: 0;";
1066
+ query5(divNew).show();
1067
+ setTimeout(() => {
1068
+ divNew.style.cssText += "transition: " + time + "s; opacity: 1;";
1069
+ divOld.style.cssText += "transition: " + time + "s";
1070
+ }, 1);
1071
+ break;
1072
+ }
1073
+ setTimeout(() => {
1074
+ if (type === "slide-down") {
1075
+ query5(divOld).css("z-index", "1019");
1076
+ query5(divNew).css("z-index", "1020");
1077
+ }
1078
+ if (divNew) {
1079
+ ;
1080
+ query5(divNew).css({ "opacity": "1" }).css({ "transition": "", "transform": "" });
1081
+ }
1082
+ if (divOld) {
1083
+ ;
1084
+ query5(divOld).css({ "opacity": "1" }).css({ "transition": "", "transform": "" });
1085
+ }
1086
+ if (typeof callBack === "function") callBack();
1087
+ resolve();
1088
+ }, time * 1e3);
1089
+ });
1090
+ }
1091
+ function lock(box, options = {}, ...rest) {
1092
+ if (box == null) return;
1093
+ let opts = typeof options === "string" ? { msg: options } : { ...options };
1094
+ if (rest[0] != null) {
1095
+ opts.spinner = rest[0];
1096
+ }
1097
+ opts = extend({ spinner: false }, opts);
1098
+ let boxSel = box;
1099
+ if (box?.[0] instanceof Node) {
1100
+ boxSel = Array.isArray(box) ? box : box.get();
1101
+ }
1102
+ if (!opts.msg && opts.msg !== 0) opts.msg = "";
1103
+ unlock(boxSel);
1104
+ const el = query5(boxSel).get(0);
1105
+ const pWidth = el.scrollWidth;
1106
+ const pHeight = el.scrollHeight;
1107
+ let style = `height: ${pHeight}px; width: ${pWidth}px`;
1108
+ if (el.tagName == "BODY") {
1109
+ style = "position: fixed; right: 0; bottom: 0;";
1110
+ }
1111
+ query5(boxSel).prepend(
1112
+ `<div class="tsg-lock" style="${style}"></div><div class="tsg-lock-msg"></div>`
1113
+ );
1114
+ const $lock = query5(boxSel).find(".tsg-lock");
1115
+ const $mess = query5(boxSel).find(".tsg-lock-msg");
1116
+ if (!opts.msg) {
1117
+ $mess.css({
1118
+ "background-color": "transparent",
1119
+ "background-image": "none",
1120
+ "border": "0px",
1121
+ "box-shadow": "none"
1122
+ });
1123
+ }
1124
+ if (opts.spinner === true) {
1125
+ opts.msg = `<div class="tsg-spinner" ${!opts.msg ? 'style="width: 35px; height: 35px"' : ""}></div>` + opts.msg;
1126
+ }
1127
+ if (opts.msg) {
1128
+ ;
1129
+ $mess.html(String(opts.msg)).css("display", "block");
1130
+ } else {
1131
+ $mess.remove();
1132
+ }
1133
+ if (opts.opacity != null) {
1134
+ $lock.css("opacity", String(opts.opacity));
1135
+ }
1136
+ $lock.css({ display: "block" });
1137
+ if (opts.bgColor) {
1138
+ $lock.css({ "background-color": opts.bgColor });
1139
+ }
1140
+ const styles = getComputedStyle($lock.get(0));
1141
+ const opacity = styles.opacity ?? 0.15;
1142
+ $lock.on("mousedown", function() {
1143
+ if (typeof opts.onClick == "function") {
1144
+ opts.onClick();
1145
+ } else {
1146
+ $lock.css({
1147
+ "transition": ".2s",
1148
+ "opacity": String(Number(opacity) * 1.5)
1149
+ });
1150
+ }
1151
+ }).on("mouseup", function() {
1152
+ if (typeof opts.onClick !== "function") {
1153
+ $lock.css({
1154
+ "transition": ".2s",
1155
+ "opacity": String(opacity)
1156
+ });
1157
+ }
1158
+ }).on("mousewheel", function(event) {
1159
+ if (event) {
1160
+ event.stopPropagation();
1161
+ event.preventDefault();
1162
+ }
1163
+ });
1164
+ }
1165
+ function unlock(box, speed) {
1166
+ if (box == null) return;
1167
+ const prevBox = box;
1168
+ clearTimeout(prevBox["_prevUnlock"]);
1169
+ let boxSel = box;
1170
+ if (box?.[0] instanceof Node) {
1171
+ boxSel = Array.isArray(box) ? box : box.get();
1172
+ }
1173
+ if (isInt(speed) && (speed ?? 0) > 0) {
1174
+ query5(boxSel).find(".tsg-lock").css({
1175
+ transition: (speed ?? 0) / 1e3 + "s",
1176
+ opacity: 0
1177
+ });
1178
+ const _box = query5(boxSel).get(0);
1179
+ clearTimeout(_box["_prevUnlock"]);
1180
+ _box["_prevUnlock"] = setTimeout(() => {
1181
+ query5(boxSel).find(".tsg-lock").remove();
1182
+ }, speed);
1183
+ query5(boxSel).find(".tsg-lock-msg").remove();
1184
+ } else {
1185
+ query5(boxSel).find(".tsg-lock").remove();
1186
+ query5(boxSel).find(".tsg-lock-msg").remove();
1187
+ }
1188
+ }
1189
+ function getSize(el, type) {
1190
+ const $el = query5(el);
1191
+ let ret = 0;
1192
+ if ($el.length > 0) {
1193
+ const styles = getComputedStyle($el[0]);
1194
+ switch (type) {
1195
+ case "width":
1196
+ ret = parseFloat(styles.width);
1197
+ if (styles.width === "auto") ret = 0;
1198
+ break;
1199
+ case "height":
1200
+ ret = parseFloat(styles.height);
1201
+ if (styles.height === "auto") ret = 0;
1202
+ break;
1203
+ default:
1204
+ ret = parseFloat(String(styles[type] ?? "")) || 0;
1205
+ break;
1206
+ }
1207
+ }
1208
+ return ret;
1209
+ }
1210
+ function getStrDimentions(str, styles, raw) {
1211
+ let div = query5("body > #_tmp_width");
1212
+ if (div.length === 0) {
1213
+ query5("body").append('<div id="_tmp_width" style="position: absolute; top: -9000px;"></div>');
1214
+ div = query5("body > #_tmp_width");
1215
+ }
1216
+ if (raw === void 0 && str.trim().startsWith("<") && str.trim().endsWith(">")) {
1217
+ raw = true;
1218
+ }
1219
+ ;
1220
+ div.html(raw ? str : encodeTags(str ?? "")).attr("style", `position: absolute; top: -9000px; ${styles || ""}`);
1221
+ const width = div[0].clientWidth;
1222
+ const height = div[0].clientHeight;
1223
+ div.html("");
1224
+ return { width, height };
1225
+ }
1226
+ function bindEvents(selector, subject) {
1227
+ const selectorR = selector;
1228
+ if (selectorR?.["length"] == 0) return;
1229
+ let normalizedSelector = selector;
1230
+ if (selectorR?.[0] instanceof Node) {
1231
+ normalizedSelector = Array.isArray(selector) ? selector : selector.get();
1232
+ }
1233
+ ;
1234
+ query5(normalizedSelector).each((el) => {
1235
+ const actions = query5(el).data();
1236
+ Object.keys(actions).forEach((name) => {
1237
+ const events = [
1238
+ "click",
1239
+ "dblclick",
1240
+ "mouseenter",
1241
+ "mouseleave",
1242
+ "mouseover",
1243
+ "mouseout",
1244
+ "mousedown",
1245
+ "mousemove",
1246
+ "mouseup",
1247
+ "contextmenu",
1248
+ "focus",
1249
+ "focusin",
1250
+ "focusout",
1251
+ "blur",
1252
+ "input",
1253
+ "change",
1254
+ "keydown",
1255
+ "keyup",
1256
+ "keypress"
1257
+ ];
1258
+ if (events.indexOf(String(name).toLowerCase()) == -1) {
1259
+ return;
1260
+ }
1261
+ let params = Array.isArray(actions[name]) ? actions[name] : [actions[name]];
1262
+ if (typeof actions[name] == "string") {
1263
+ params = actions[name].split("|").map((key) => {
1264
+ let val = key;
1265
+ if (key === "true") val = true;
1266
+ if (key === "false") val = false;
1267
+ if (key === "undefined") val = void 0;
1268
+ if (key === "null") val = null;
1269
+ if (typeof val === "string" && parseFloat(val) == val) val = parseFloat(val);
1270
+ const quotes = ["'", '"', "`"];
1271
+ if (typeof val == "string" && quotes.includes(val[0] ?? "") && quotes.includes(val[val.length - 1] ?? "")) {
1272
+ val = val.substring(1, val.length - 1);
1273
+ }
1274
+ return val;
1275
+ });
1276
+ }
1277
+ const method = String(params[0]);
1278
+ params = params.slice(1);
1279
+ query5(el).off(name + ".TsUtils-bind").on(name + ".TsUtils-bind", function(event) {
1280
+ switch (method) {
1281
+ case "alert":
1282
+ alert(params[0]);
1283
+ break;
1284
+ case "stop":
1285
+ event.stopPropagation();
1286
+ break;
1287
+ case "prevent":
1288
+ event.preventDefault();
1289
+ break;
1290
+ case "stopPrevent":
1291
+ event.stopPropagation();
1292
+ event.preventDefault();
1293
+ return false;
1294
+ break;
1295
+ default:
1296
+ if (subject[method] == null) {
1297
+ throw new Error(`Cannot dispatch event as the method "${method}" does not exist.`);
1298
+ }
1299
+ ;
1300
+ subject[method](...params.map((key, _ind) => {
1301
+ switch (String(key).toLowerCase()) {
1302
+ case "event":
1303
+ return event;
1304
+ case "this":
1305
+ return this;
1306
+ default:
1307
+ return key;
1308
+ }
1309
+ }));
1310
+ }
1311
+ });
1312
+ });
1313
+ });
1314
+ }
1315
+
1316
+ // src/tsutils-datetime.ts
1317
+ function _isDate(val, format, retDate, settings) {
1318
+ if (!val) return false;
1319
+ let dt = "Invalid Date";
1320
+ let month, day, year;
1321
+ if (format == null) format = settings.dateFormat;
1322
+ if (val instanceof Date) {
1323
+ year = val.getFullYear();
1324
+ month = val.getMonth() + 1;
1325
+ day = val.getDate();
1326
+ } else if (typeof val === "number" || typeof val === "string" && parseInt(val) == val && parseInt(val) > 0) {
1327
+ const d = new Date(parseInt(String(val)));
1328
+ year = d.getFullYear();
1329
+ month = d.getMonth() + 1;
1330
+ day = d.getDate();
1331
+ } else {
1332
+ let strVal = String(val);
1333
+ if (new RegExp("mon", "ig").test(format)) {
1334
+ format = format.replace(/month/ig, "m").replace(/mon/ig, "m").replace(/dd/ig, "d").replace(/[, ]/ig, "/").replace(/\/\//g, "/").toLowerCase();
1335
+ strVal = strVal.replace(/[, ]/ig, "/").replace(/\/\//g, "/").toLowerCase();
1336
+ for (let m = 0, len = settings.fullmonths.length; m < len; m++) {
1337
+ const t = settings.fullmonths[m] ?? "";
1338
+ strVal = strVal.replace(new RegExp(t, "ig"), String(m + 1)).replace(new RegExp(t.substr(0, 3), "ig"), String(m + 1));
1339
+ }
1340
+ }
1341
+ const tmp = strVal.replace(/-/g, "/").replace(/\./g, "/").toLowerCase().split("/");
1342
+ const tmp2 = format.replace(/-/g, "/").replace(/\./g, "/").toLowerCase();
1343
+ if (tmp2 === "mm/dd/yyyy") {
1344
+ month = tmp[0];
1345
+ day = tmp[1];
1346
+ year = tmp[2];
1347
+ }
1348
+ if (tmp2 === "m/d/yyyy") {
1349
+ month = tmp[0];
1350
+ day = tmp[1];
1351
+ year = tmp[2];
1352
+ }
1353
+ if (tmp2 === "dd/mm/yyyy") {
1354
+ month = tmp[1];
1355
+ day = tmp[0];
1356
+ year = tmp[2];
1357
+ }
1358
+ if (tmp2 === "d/m/yyyy") {
1359
+ month = tmp[1];
1360
+ day = tmp[0];
1361
+ year = tmp[2];
1362
+ }
1363
+ if (tmp2 === "yyyy/dd/mm") {
1364
+ month = tmp[2];
1365
+ day = tmp[1];
1366
+ year = tmp[0];
1367
+ }
1368
+ if (tmp2 === "yyyy/d/m") {
1369
+ month = tmp[2];
1370
+ day = tmp[1];
1371
+ year = tmp[0];
1372
+ }
1373
+ if (tmp2 === "yyyy/mm/dd") {
1374
+ month = tmp[1];
1375
+ day = tmp[2];
1376
+ year = tmp[0];
1377
+ }
1378
+ if (tmp2 === "yyyy/m/d") {
1379
+ month = tmp[1];
1380
+ day = tmp[2];
1381
+ year = tmp[0];
1382
+ }
1383
+ if (tmp2 === "mm/dd/yy") {
1384
+ month = tmp[0];
1385
+ day = tmp[1];
1386
+ year = tmp[2];
1387
+ }
1388
+ if (tmp2 === "m/d/yy") {
1389
+ month = tmp[0];
1390
+ day = tmp[1];
1391
+ year = parseInt(tmp[2] ?? "0") + 1900;
1392
+ }
1393
+ if (tmp2 === "dd/mm/yy") {
1394
+ month = tmp[1];
1395
+ day = tmp[0];
1396
+ year = parseInt(tmp[2] ?? "0") + 1900;
1397
+ }
1398
+ if (tmp2 === "d/m/yy") {
1399
+ month = tmp[1];
1400
+ day = tmp[0];
1401
+ year = parseInt(tmp[2] ?? "0") + 1900;
1402
+ }
1403
+ if (tmp2 === "yy/dd/mm") {
1404
+ month = tmp[2];
1405
+ day = tmp[1];
1406
+ year = parseInt(tmp[0] ?? "0") + 1900;
1407
+ }
1408
+ if (tmp2 === "yy/d/m") {
1409
+ month = tmp[2];
1410
+ day = tmp[1];
1411
+ year = parseInt(tmp[0] ?? "0") + 1900;
1412
+ }
1413
+ if (tmp2 === "yy/mm/dd") {
1414
+ month = tmp[1];
1415
+ day = tmp[2];
1416
+ year = parseInt(tmp[0] ?? "0") + 1900;
1417
+ }
1418
+ if (tmp2 === "yy/m/d") {
1419
+ month = tmp[1];
1420
+ day = tmp[2];
1421
+ year = parseInt(tmp[0] ?? "0") + 1900;
1422
+ }
1423
+ }
1424
+ if (!isInt(year)) return false;
1425
+ if (!isInt(month)) return false;
1426
+ if (!isInt(day)) return false;
1427
+ const numYear = +(year ?? 0);
1428
+ const numMonth = +(month ?? 0);
1429
+ const numDay = +(day ?? 0);
1430
+ dt = new Date(numYear, numMonth - 1, numDay);
1431
+ dt.setFullYear(numYear);
1432
+ if (numMonth == null) return false;
1433
+ if (String(dt) === "Invalid Date") return false;
1434
+ if (dt.getMonth() + 1 !== numMonth || dt.getDate() !== numDay || dt.getFullYear() !== numYear) return false;
1435
+ if (retDate === true) return dt;
1436
+ else return true;
1437
+ }
1438
+ function _isTime(val, retTime) {
1439
+ if (val == null) return false;
1440
+ let max;
1441
+ let strVal = String(val).toUpperCase();
1442
+ const am = strVal.indexOf("AM") >= 0;
1443
+ const pm = strVal.indexOf("PM") >= 0;
1444
+ const ampm = pm || am;
1445
+ if (ampm) max = 12;
1446
+ else max = 24;
1447
+ strVal = strVal.replace("AM", "").replace("PM", "").trim();
1448
+ const tmp = strVal.split(":");
1449
+ const tmp0 = tmp[0] ?? "", tmp1 = tmp[1] ?? "", tmp2 = tmp[2] ?? "";
1450
+ let h = parseInt(tmp0 || "0");
1451
+ const m = parseInt(tmp1 || "0"), s = parseInt(tmp2 || "0");
1452
+ if ((!ampm || tmp.length !== 1) && tmp.length !== 2 && tmp.length !== 3) {
1453
+ return false;
1454
+ }
1455
+ if (tmp0 === "" || h < 0 || h > max || !isInt(tmp0) || tmp0.length > 2) {
1456
+ return false;
1457
+ }
1458
+ if (tmp.length > 1 && (tmp1 === "" || m < 0 || m > 59 || !isInt(tmp1) || tmp1.length !== 2)) {
1459
+ return false;
1460
+ }
1461
+ if (tmp.length > 2 && (tmp2 === "" || s < 0 || s > 59 || !isInt(tmp2) || tmp2.length !== 2)) {
1462
+ return false;
1463
+ }
1464
+ if (!ampm && max === h && (m !== 0 || s !== 0)) {
1465
+ return false;
1466
+ }
1467
+ if (ampm && tmp.length === 1 && h === 0) {
1468
+ return false;
1469
+ }
1470
+ if (retTime === true) {
1471
+ if (pm && h !== 12) h += 12;
1472
+ if (am && h === 12) h += 12;
1473
+ return {
1474
+ hours: h,
1475
+ minutes: m,
1476
+ seconds: s
1477
+ };
1478
+ }
1479
+ return true;
1480
+ }
1481
+ function _isDateTime(val, format, retDate, settings) {
1482
+ if (val instanceof Date) {
1483
+ if (retDate !== true) return true;
1484
+ return val;
1485
+ }
1486
+ const intVal = parseInt(String(val));
1487
+ if (intVal === val) {
1488
+ if (intVal < 0) return false;
1489
+ else if (retDate !== true) return true;
1490
+ else return new Date(intVal);
1491
+ }
1492
+ const strVal = String(val);
1493
+ const tmp = strVal.indexOf(" ");
1494
+ if (tmp < 0) {
1495
+ if (strVal.indexOf("T") < 0 || String(new Date(strVal)) == "Invalid Date") return false;
1496
+ else if (retDate !== true) return true;
1497
+ else return new Date(strVal);
1498
+ } else {
1499
+ if (format == null) format = settings.datetimeFormat;
1500
+ const formats = format.split("|");
1501
+ const values = [strVal.substr(0, tmp), strVal.substr(tmp).trim()];
1502
+ if (formats[0] != null) formats[0] = formats[0].trim();
1503
+ if (formats[1]) formats[1] = formats[1].trim();
1504
+ const tmp1 = _isDate(values[0], formats[0], true, settings);
1505
+ const tmp2 = _isTime(values[1], true);
1506
+ if (tmp1 !== false && tmp2 !== false) {
1507
+ if (retDate !== true) return true;
1508
+ const dt1 = tmp1;
1509
+ const t2 = tmp2;
1510
+ dt1.setHours(t2.hours);
1511
+ dt1.setMinutes(t2.minutes);
1512
+ dt1.setSeconds(t2.seconds);
1513
+ return dt1;
1514
+ } else {
1515
+ return false;
1516
+ }
1517
+ }
1518
+ }
1519
+ function _age(dateStr) {
1520
+ let d1;
1521
+ if (dateStr === "" || dateStr == null) return "";
1522
+ if (dateStr instanceof Date) {
1523
+ d1 = dateStr;
1524
+ } else if (typeof dateStr === "number" || typeof dateStr === "string" && parseInt(dateStr) == dateStr && parseInt(dateStr) > 0) {
1525
+ d1 = new Date(parseInt(String(dateStr)));
1526
+ } else {
1527
+ d1 = new Date(String(dateStr));
1528
+ }
1529
+ if (String(d1) === "Invalid Date") return "";
1530
+ const d2 = /* @__PURE__ */ new Date();
1531
+ const sec = (d2.getTime() - d1.getTime()) / 1e3;
1532
+ let amount = 0;
1533
+ let type = "";
1534
+ if (sec < 0) {
1535
+ amount = 0;
1536
+ type = "sec";
1537
+ } else if (sec < 60) {
1538
+ amount = Math.floor(sec);
1539
+ type = "sec";
1540
+ if (sec < 0) {
1541
+ amount = 0;
1542
+ type = "sec";
1543
+ }
1544
+ } else if (sec < 60 * 60) {
1545
+ amount = Math.floor(sec / 60);
1546
+ type = "min";
1547
+ } else if (sec < 24 * 60 * 60) {
1548
+ amount = Math.floor(sec / 60 / 60);
1549
+ type = "hour";
1550
+ } else if (sec < 30 * 24 * 60 * 60) {
1551
+ amount = Math.floor(sec / 24 / 60 / 60);
1552
+ type = "day";
1553
+ } else if (sec < 365 * 24 * 60 * 60) {
1554
+ amount = Math.floor(sec / 30 / 24 / 60 / 60 * 10) / 10;
1555
+ type = "month";
1556
+ } else if (sec < 365 * 4 * 24 * 60 * 60) {
1557
+ amount = Math.floor(sec / 365 / 24 / 60 / 60 * 10) / 10;
1558
+ type = "year";
1559
+ } else if (sec >= 365 * 4 * 24 * 60 * 60) {
1560
+ amount = Math.floor(sec / 365.25 / 24 / 60 / 60 * 10) / 10;
1561
+ type = "year";
1562
+ }
1563
+ return amount + " " + type + (amount > 1 ? "s" : "");
1564
+ }
1565
+ function _interval(value) {
1566
+ let ret = "";
1567
+ if (value < 100) {
1568
+ ret = "< 0.01 sec";
1569
+ } else if (value < 1e3) {
1570
+ ret = Math.floor(value / 10) / 100 + " sec";
1571
+ } else if (value < 1e4) {
1572
+ ret = Math.floor(value / 100) / 10 + " sec";
1573
+ } else if (value < 6e4) {
1574
+ ret = Math.floor(value / 1e3) + " secs";
1575
+ } else if (value < 36e5) {
1576
+ ret = Math.floor(value / 6e4) + " mins";
1577
+ } else if (value < 864e5) {
1578
+ ret = Math.floor(value / 36e5 * 10) / 10 + " hours";
1579
+ } else if (value < 2628e6) {
1580
+ ret = Math.floor(value / 864e5 * 10) / 10 + " days";
1581
+ } else if (value < 31536e6) {
1582
+ ret = Math.floor(value / 2628e6 * 10) / 10 + " months";
1583
+ } else {
1584
+ ret = Math.floor(value / 31536e5) / 10 + " years";
1585
+ }
1586
+ return ret;
1587
+ }
1588
+ function _formatDate(dateStr, format, settings) {
1589
+ if (!format) format = settings.dateFormat;
1590
+ if (dateStr === "" || dateStr == null || typeof dateStr === "object" && !dateStr.getMonth) return "";
1591
+ let dt = new Date(dateStr);
1592
+ if (isInt(dateStr)) dt = new Date(Number(dateStr));
1593
+ if (String(dt) === "Invalid Date") return "";
1594
+ const year = dt.getFullYear();
1595
+ const month = dt.getMonth();
1596
+ const date = dt.getDate();
1597
+ return format.toLowerCase().replace("month", settings.fullmonths[month] ?? "").replace("mon", settings.shortmonths[month] ?? "").replace(/yyyy/g, ("000" + year).slice(-4)).replace(/yyy/g, ("000" + year).slice(-4)).replace(/yy/g, ("0" + year).slice(-2)).replace(/(^|[^a-z$])y/g, "$1" + year).replace(/mm/g, ("0" + (month + 1)).slice(-2)).replace(/dd/g, ("0" + date).slice(-2)).replace(/th/g, date == 1 ? "st" : "th").replace(/th/g, date == 2 ? "nd" : "th").replace(/th/g, date == 3 ? "rd" : "th").replace(/(^|[^a-z$])m/g, "$1" + (month + 1)).replace(/(^|[^a-z$])d/g, "$1" + date);
1598
+ }
1599
+ function _formatTime(dateStr, format, settings) {
1600
+ if (!format) format = settings.timeFormat;
1601
+ if (dateStr === "" || dateStr == null || typeof dateStr === "object" && !dateStr.getMonth) return "";
1602
+ let dt = new Date(dateStr);
1603
+ if (isInt(dateStr)) dt = new Date(Number(dateStr));
1604
+ if (_isTime(dateStr)) {
1605
+ const tmp = _isTime(dateStr, true);
1606
+ dt = /* @__PURE__ */ new Date();
1607
+ dt.setHours(tmp.hours);
1608
+ dt.setMinutes(tmp.minutes);
1609
+ }
1610
+ if (String(dt) === "Invalid Date") return "";
1611
+ if (format == "h12") format = "hh:mi pm";
1612
+ let type = "am";
1613
+ let hour = dt.getHours();
1614
+ const h24 = dt.getHours();
1615
+ let min = dt.getMinutes();
1616
+ let sec = dt.getSeconds();
1617
+ if (min < 10) min = "0" + min;
1618
+ if (sec < 10) sec = "0" + sec;
1619
+ if (format.indexOf("am") !== -1 || format.indexOf("pm") !== -1) {
1620
+ if (hour >= 12) type = "pm";
1621
+ if (hour > 12) hour = hour - 12;
1622
+ if (hour === 0) hour = 12;
1623
+ }
1624
+ const hourStr = String(hour);
1625
+ const minStr = String(min);
1626
+ const secStr = String(sec);
1627
+ const h24Str = String(h24);
1628
+ return format.toLowerCase().replace("am", type).replace("pm", type).replace("hhh", Number(hour) < 10 ? "0" + hourStr : hourStr).replace("hh24", h24 < 10 ? "0" + h24Str : h24Str).replace("h24", h24Str).replace("hh", hourStr).replace("mm", minStr).replace("mi", minStr).replace("ss", secStr).replace(/(^|[^a-z$])h/g, "$1" + hourStr).replace(/(^|[^a-z$])m/g, "$1" + minStr).replace(/(^|[^a-z$])s/g, "$1" + secStr);
1629
+ }
1630
+ function _formatDateTime(dateStr, format, settings) {
1631
+ let fmt;
1632
+ if (dateStr === "" || dateStr == null || typeof dateStr === "object" && !dateStr.getMonth) return "";
1633
+ if (typeof format !== "string") {
1634
+ fmt = [settings.dateFormat, settings.timeFormat];
1635
+ } else {
1636
+ fmt = format.split("|");
1637
+ if (fmt[0] != null) fmt[0] = fmt[0].trim();
1638
+ fmt[1] = fmt.length > 1 ? (fmt[1] ?? "").trim() : settings.timeFormat;
1639
+ }
1640
+ if (fmt[1] === "h12") fmt[1] = "h:m pm";
1641
+ if (fmt[1] === "h24") fmt[1] = "h24:m";
1642
+ return _formatDate(dateStr, fmt[0], settings) + " " + _formatTime(dateStr, fmt[1], settings);
1643
+ }
1644
+ function _date(dateStr, settings, deps) {
1645
+ if (dateStr === "" || dateStr == null || typeof dateStr === "object" && !dateStr.getMonth) return "";
1646
+ let d1 = new Date(dateStr);
1647
+ if (isInt(dateStr)) d1 = new Date(Number(dateStr));
1648
+ if (String(d1) === "Invalid Date") return "";
1649
+ const months = settings.shortmonths;
1650
+ const d2 = /* @__PURE__ */ new Date();
1651
+ const d3 = /* @__PURE__ */ new Date();
1652
+ d3.setTime(d3.getTime() - 864e5);
1653
+ const dd1 = months[d1.getMonth()] + " " + d1.getDate() + ", " + d1.getFullYear();
1654
+ const dd2 = months[d2.getMonth()] + " " + d2.getDate() + ", " + d2.getFullYear();
1655
+ const dd3 = months[d3.getMonth()] + " " + d3.getDate() + ", " + d3.getFullYear();
1656
+ const time = d1.getHours() - (d1.getHours() > 12 ? 12 : 0) + ":" + (d1.getMinutes() < 10 ? "0" : "") + d1.getMinutes() + " " + (d1.getHours() >= 12 ? "pm" : "am");
1657
+ const time2 = d1.getHours() - (d1.getHours() > 12 ? 12 : 0) + ":" + (d1.getMinutes() < 10 ? "0" : "") + d1.getMinutes() + ":" + (d1.getSeconds() < 10 ? "0" : "") + d1.getSeconds() + " " + (d1.getHours() >= 12 ? "pm" : "am");
1658
+ let dsp = dd1;
1659
+ if (dd1 === dd2) dsp = time;
1660
+ if (dd1 === dd3) dsp = deps.lang("Yesterday");
1661
+ return '<span title="' + dd1 + " " + time2 + '">' + dsp + "</span>";
1662
+ }
1663
+
1664
+ // src/tsutils-locale.ts
1665
+ async function _locale(locale, keepPhrases, noMerge, settings, deps) {
1666
+ if (Array.isArray(locale)) {
1667
+ let mergedSettings = deps.extend({}, { ...settings, phrases: {} });
1668
+ const localeArr = locale.map(
1669
+ (f) => f.length === 5 ? "locale/" + f.toLowerCase() + ".json" : f
1670
+ );
1671
+ const proms = [];
1672
+ const files = {};
1673
+ localeArr.forEach((file) => {
1674
+ proms.push(_locale(file, true, false, mergedSettings, deps));
1675
+ });
1676
+ const res = await Promise.allSettled(proms);
1677
+ res.forEach((r) => {
1678
+ if (r.status === "fulfilled" && r.value.kind === "load") {
1679
+ files[r.value.file] = r.value.data;
1680
+ }
1681
+ });
1682
+ localeArr.forEach((file) => {
1683
+ mergedSettings = deps.extend({}, mergedSettings, files[file] ?? {});
1684
+ });
1685
+ return { kind: "void", settings: mergedSettings };
1686
+ }
1687
+ if (!locale) locale = "en-us";
1688
+ if (typeof locale === "object") {
1689
+ const mergedSettings = deps.extend({}, settings, TsLocale, locale);
1690
+ return { kind: "merge", settings: mergedSettings };
1691
+ }
1692
+ let localeStr = locale;
1693
+ if (localeStr.length === 5) {
1694
+ localeStr = "locale/" + localeStr.toLowerCase() + ".json";
1695
+ }
1696
+ try {
1697
+ const res = await deps.fetch(localeStr, { method: "GET" });
1698
+ const data = await res.json();
1699
+ if (noMerge !== true) {
1700
+ if (keepPhrases) {
1701
+ const newSettings = deps.extend({}, settings, data);
1702
+ return { kind: "load", file: localeStr, data, settings: newSettings };
1703
+ } else {
1704
+ const phrasesCleared = { ...settings, phrases: {} };
1705
+ const newSettings = deps.extend({}, phrasesCleared, TsLocale, data);
1706
+ return { kind: "load", file: localeStr, data, settings: newSettings };
1707
+ }
1708
+ }
1709
+ return { kind: "load", file: localeStr, data };
1710
+ } catch (err) {
1711
+ console.log("ERROR: Cannot load locale " + localeStr);
1712
+ throw err;
1713
+ }
1714
+ }
1715
+
1716
+ // src/tsutils.ts
1717
+ var query6 = query;
1718
+ var Utils = class {
1719
+ version;
1720
+ tmp;
1721
+ settings;
1722
+ i18nCompare;
1723
+ hasLocalStorage;
1724
+ isMac;
1725
+ isMobile;
1726
+ isIOS;
1727
+ isAndroid;
1728
+ isSafari;
1729
+ isFirefox;
1730
+ formatters;
1731
+ constructor() {
1732
+ this.version = "2.0.x";
1733
+ this.tmp = {};
1734
+ this.settings = this.extend({}, {
1735
+ "dataType": "JSON",
1736
+ // can be HTTP, JSON, RESTFULL (case sensitive)
1737
+ "dateStartYear": 1950,
1738
+ // start year for date-picker
1739
+ "dateEndYear": 2030,
1740
+ // end year for date picker
1741
+ "macButtonOrder": false,
1742
+ // if true, Yes on the right side
1743
+ "warnNoPhrase": false
1744
+ // call console.warn if lang() encounters a missing phrase
1745
+ }, TsLocale, { phrases: null }), // if there are no phrases, then it is original language
1746
+ this.i18nCompare = Intl.Collator().compare;
1747
+ this.hasLocalStorage = testLocalStorage();
1748
+ this.isMac = /Mac/i.test(navigator.platform);
1749
+ this.isMobile = /(iphone|ipod|mobile|android)/i.test(navigator.userAgent);
1750
+ this.isIOS = /(iphone|ipod|ipad)/i.test(navigator.platform);
1751
+ this.isAndroid = /(android)/i.test(navigator.userAgent);
1752
+ this.isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
1753
+ this.isFirefox = /(Firefox)/i.test(navigator.userAgent);
1754
+ this.formatters = {
1755
+ "number"(record, extra) {
1756
+ if (extra == void 0) extra = record;
1757
+ const { value } = extra;
1758
+ let params = extra.params;
1759
+ if (parseInt(String(params)) > 20) params = 20;
1760
+ if (parseInt(String(params)) < 0) params = 0;
1761
+ if (value == null || value === "") return "";
1762
+ return TsUtils.formatNumber(parseFloat(String(value)), params, true);
1763
+ },
1764
+ "float"(record, extra) {
1765
+ return TsUtils.formatters["number"]?.(record, extra) ?? "";
1766
+ },
1767
+ "int"(record, extra) {
1768
+ return TsUtils.formatters["number"]?.(record, extra) ?? "";
1769
+ },
1770
+ "money"(record, extra) {
1771
+ if (extra == void 0) extra = record;
1772
+ const { value } = extra;
1773
+ if (value == null || value === "") return "";
1774
+ const data = TsUtils.formatNumber(Number(value), TsUtils.settings.currencyPrecision, true);
1775
+ return (TsUtils.settings.currencyPrefix || "") + data + (TsUtils.settings.currencySuffix || "");
1776
+ },
1777
+ "currency"(record, extra) {
1778
+ return TsUtils.formatters["money"]?.(record, extra) ?? "";
1779
+ },
1780
+ "percent"(record, extra) {
1781
+ if (extra == void 0) extra = record;
1782
+ const { value, params } = extra;
1783
+ if (value == null || value === "") return "";
1784
+ return TsUtils.formatNumber(value, params || 1) + "%";
1785
+ },
1786
+ "size"(record, extra) {
1787
+ if (extra == void 0) extra = record;
1788
+ const { value } = extra;
1789
+ if (value == null || value === "") return "";
1790
+ return String(TsUtils.formatSize(parseInt(String(value))));
1791
+ },
1792
+ "date"(record, extra) {
1793
+ if (extra == void 0) extra = record;
1794
+ const { value } = extra;
1795
+ let params = extra.params;
1796
+ if (params === "") params = TsUtils.settings.dateFormat;
1797
+ if (value == null || value === 0 || value === "") return "";
1798
+ let dt = TsUtils.isDateTime(value, params ?? null, true);
1799
+ if (dt === false) dt = TsUtils.isDate(value, params ?? null, true);
1800
+ const dtStr = dt instanceof Date ? dt : "";
1801
+ return '<span title="' + dtStr + '">' + TsUtils.formatDate(dt instanceof Date ? dt : void 0, params) + "</span>";
1802
+ },
1803
+ "datetime"(record, extra) {
1804
+ if (extra == void 0) extra = record;
1805
+ const { value } = extra;
1806
+ let params = extra.params;
1807
+ if (params === "") params = TsUtils.settings.datetimeFormat;
1808
+ if (value == null || value === 0 || value === "") return "";
1809
+ let dt = TsUtils.isDateTime(value, params ?? null, true);
1810
+ if (dt === false) dt = TsUtils.isDate(value, params ?? null, true);
1811
+ const dtStr = dt instanceof Date ? dt : "";
1812
+ return '<span title="' + dtStr + '">' + TsUtils.formatDateTime(dt instanceof Date ? dt : void 0, params) + "</span>";
1813
+ },
1814
+ "time"(record, extra) {
1815
+ if (extra == void 0) extra = record;
1816
+ const { value } = extra;
1817
+ let params = extra.params;
1818
+ if (params === "") params = TsUtils.settings.timeFormat;
1819
+ if (params === "h12") params = "hh:mi pm";
1820
+ if (params === "h24") params = "h24:mi";
1821
+ if (value == null || value === 0 || value === "") return "";
1822
+ let dt = TsUtils.isDateTime(value, params ?? null, true);
1823
+ if (dt === false) dt = TsUtils.isDate(value, params ?? null, true);
1824
+ const dtStr = dt instanceof Date ? dt : "";
1825
+ return '<span title="' + dtStr + '">' + TsUtils.formatTime(value, params) + "</span>";
1826
+ },
1827
+ "timestamp"(record, extra) {
1828
+ if (extra == void 0) extra = record;
1829
+ const { value } = extra;
1830
+ let params = extra.params;
1831
+ if (params === "") params = TsUtils.settings.datetimeFormat;
1832
+ if (value == null || value === 0 || value === "") return "";
1833
+ let dt = TsUtils.isDateTime(value, params ?? null, true);
1834
+ if (dt === false) dt = TsUtils.isDate(value, params ?? null, true);
1835
+ return dt instanceof Date ? dt.toString() : "";
1836
+ },
1837
+ "gmt"(record, extra) {
1838
+ if (extra == void 0) extra = record;
1839
+ const { value } = extra;
1840
+ let params = extra.params;
1841
+ if (params === "") params = TsUtils.settings.datetimeFormat;
1842
+ if (value == null || value === 0 || value === "") return "";
1843
+ let dt = TsUtils.isDateTime(value, params ?? null, true);
1844
+ if (dt === false) dt = TsUtils.isDate(value, params ?? null, true);
1845
+ return dt instanceof Date ? dt.toUTCString() : "";
1846
+ },
1847
+ "age"(record, extra) {
1848
+ if (extra == void 0) extra = record;
1849
+ const { value, params } = extra;
1850
+ if (value == null || value === 0 || value === "") return "";
1851
+ let dt = TsUtils.isDateTime(value, null, true);
1852
+ if (dt === false) dt = TsUtils.isDate(value, null, true);
1853
+ const dtStr = dt instanceof Date ? dt : "";
1854
+ return '<span title="' + dtStr + '">' + TsUtils.age(value) + (params ? " " + params : "") + "</span>";
1855
+ },
1856
+ "interval"(record, extra) {
1857
+ if (extra == void 0) extra = record;
1858
+ const { value, params } = extra;
1859
+ if (value == null || value === 0 || value === "") return "";
1860
+ return TsUtils.interval(Number(value)) + (params ? " " + params : "");
1861
+ },
1862
+ "toggle"(record, extra) {
1863
+ if (extra == void 0) extra = record;
1864
+ const { value } = extra;
1865
+ return value ? TsUtils.lang("Yes") : "";
1866
+ },
1867
+ "password"(record, extra) {
1868
+ if (extra == void 0) extra = record;
1869
+ const { value } = extra;
1870
+ let ret = "";
1871
+ if (!value) return ret;
1872
+ const strVal = String(value);
1873
+ for (let i = 0; i < strVal.length; i++) {
1874
+ ret += "*";
1875
+ }
1876
+ return ret;
1877
+ }
1878
+ };
1879
+ return;
1880
+ function testLocalStorage() {
1881
+ const str = "w2ui_test";
1882
+ try {
1883
+ localStorage.setItem(str, str);
1884
+ localStorage.removeItem(str);
1885
+ return true;
1886
+ } catch (e) {
1887
+ return false;
1888
+ }
1889
+ }
1890
+ }
1891
+ isBin(val) {
1892
+ return isBin(val);
1893
+ }
1894
+ isInt(val) {
1895
+ return isInt(val);
1896
+ }
1897
+ isFloat(val) {
1898
+ return isFloat(val, this.settings);
1899
+ }
1900
+ isMoney(val) {
1901
+ return isMoney(val, this.settings);
1902
+ }
1903
+ isHex(val) {
1904
+ return isHex(val);
1905
+ }
1906
+ isAlphaNumeric(val) {
1907
+ return isAlphaNumeric(val);
1908
+ }
1909
+ isEmail(val) {
1910
+ return isEmail(val);
1911
+ }
1912
+ isIpAddress(val) {
1913
+ return isIpAddress(val);
1914
+ }
1915
+ isDate(val, format, retDate) {
1916
+ return _isDate(val, format, retDate, this.settings);
1917
+ }
1918
+ isTime(val, retTime) {
1919
+ return _isTime(val, retTime);
1920
+ }
1921
+ isDateTime(val, format, retDate) {
1922
+ return _isDateTime(val, format, retDate, this.settings);
1923
+ }
1924
+ age(dateStr) {
1925
+ return _age(dateStr);
1926
+ }
1927
+ interval(value) {
1928
+ return _interval(value);
1929
+ }
1930
+ date(dateStr) {
1931
+ return _date(dateStr, this.settings, { lang: this.lang.bind(this) });
1932
+ }
1933
+ formatSize(sizeStr) {
1934
+ if (!this.isFloat(sizeStr) || sizeStr === "") return "";
1935
+ const num = parseFloat(String(sizeStr));
1936
+ if (num === 0) return 0;
1937
+ const sizes = ["Bt", "KB", "MB", "GB", "TB", "PB", "EB", "ZB"];
1938
+ const i = parseInt(String(Math.floor(Math.log(num) / Math.log(1024))));
1939
+ return (Math.floor(num / Math.pow(1024, i) * 10) / 10).toFixed(i === 0 ? 0 : 1) + " " + (sizes[i] || "??");
1940
+ }
1941
+ formatNumber(val, fraction, useGrouping) {
1942
+ if (val == null || val === "" || typeof val === "object") return "";
1943
+ const options = {
1944
+ minimumFractionDigits: fraction != null ? parseInt(String(fraction)) : void 0,
1945
+ maximumFractionDigits: fraction != null ? parseInt(String(fraction)) : void 0,
1946
+ useGrouping: !!useGrouping
1947
+ };
1948
+ if (fraction == null || Number(fraction) < 0) {
1949
+ options.minimumFractionDigits = 0;
1950
+ options.maximumFractionDigits = 20;
1951
+ }
1952
+ return parseFloat(String(val)).toLocaleString(this.settings.locale, options);
1953
+ }
1954
+ formatDate(dateStr, format) {
1955
+ return _formatDate(dateStr, format, this.settings);
1956
+ }
1957
+ formatTime(dateStr, format) {
1958
+ return _formatTime(dateStr, format, this.settings);
1959
+ }
1960
+ formatDateTime(dateStr, format) {
1961
+ return _formatDateTime(dateStr, format, this.settings);
1962
+ }
1963
+ stripSpaces(html) {
1964
+ return stripSpaces(html);
1965
+ }
1966
+ stripTags(html) {
1967
+ return stripTags(html);
1968
+ }
1969
+ encodeTags(html) {
1970
+ return encodeTags(html);
1971
+ }
1972
+ decodeTags(html) {
1973
+ return decodeTags(html);
1974
+ }
1975
+ escapeId(id) {
1976
+ return escapeId(id);
1977
+ }
1978
+ unescapeId(id) {
1979
+ return unescapeId(id);
1980
+ }
1981
+ base64encode(str) {
1982
+ return base64encode(str);
1983
+ }
1984
+ base64decode(encodedStr) {
1985
+ return base64decode(encodedStr);
1986
+ }
1987
+ sha256(str) {
1988
+ return sha256(str);
1989
+ }
1990
+ transition(div_old, div_new, type, callBack) {
1991
+ return transition(div_old, div_new, type, callBack);
1992
+ }
1993
+ lock(box, options = {}, ...rest) {
1994
+ return lock(box, options, ...rest);
1995
+ }
1996
+ unlock(box, speed) {
1997
+ return unlock(box, speed);
1998
+ }
1999
+ /**
2000
+ * Constructs the MessageDeps object for the _message() delegator.
2001
+ * Called once per message() invocation — captures `this` at call time.
2002
+ * Per design §C.5 / §C.2.
2003
+ * @internal
2004
+ */
2005
+ _msgDeps() {
2006
+ return {
2007
+ extend,
2008
+ bindEvents: (s, subj) => this.bindEvents(s, subj),
2009
+ lock: (box, opts) => this.lock(box, opts),
2010
+ unlock: (box, speed) => this.unlock(box, speed),
2011
+ // any: 'name' is set dynamically on widget instances (TsGrid, TsForm, etc.) at runtime
2012
+ ownerName: this["name"],
2013
+ self: this
2014
+ };
2015
+ }
2016
+ /**
2017
+ * Constructs the ConfirmDeps object for the _confirm() delegator.
2018
+ * Per design §C.3.
2019
+ * normButtons closure: uses inline lambda that binds this.lang and this.settings
2020
+ * at call time — preserving the call-time timing semantics (design §C.3 caveat).
2021
+ * @internal
2022
+ */
2023
+ _confirmDeps() {
2024
+ return {
2025
+ extend,
2026
+ normButtons: (opts, btn) => normButtons(opts, btn, { extend, lang: this.lang.bind(this), settings: this.settings }),
2027
+ message: (w, o) => this.message(w, o),
2028
+ settings: this.settings,
2029
+ lang: this.lang.bind(this)
2030
+ };
2031
+ }
2032
+ /**
2033
+ * Constructs the PromptDeps object for the _prompt() delegator.
2034
+ * Per design §C.3.
2035
+ * lang is bound at call time so deps.lang('Ok') uses current locale.
2036
+ * @internal
2037
+ */
2038
+ _promptDeps() {
2039
+ return {
2040
+ extend,
2041
+ normButtons: (opts, btn) => normButtons(opts, btn, { extend, lang: this.lang.bind(this), settings: this.settings }),
2042
+ message: (w, o) => this.message(w, o),
2043
+ settings: this.settings,
2044
+ lang: this.lang.bind(this)
2045
+ };
2046
+ }
2047
+ /**
2048
+ * Opens a context message, similar in parameters as TsPopup.open()
2049
+ *
2050
+ * Sample Calls
2051
+ * TsUtils.message({ box: '#div', text: 'message' }).ok(() => {})
2052
+ * TsUtils.message({ box: '#div', text: 'message', width: 300 }).ok(() => {})
2053
+ * TsUtils.message({ box: '#div', text: 'message', actions: ['Save'] }).Save(() => {})
2054
+ *
2055
+ * Used in TsGrid, TsForm, TsLayout (should be in TsPopup too)
2056
+ * should be called with .call(...) method
2057
+ *
2058
+ * @param where = {
2059
+ * box, // where to open
2060
+ * after, // title if any, adds title heights
2061
+ * param // additional parameters, used in layouts for panel
2062
+ * }
2063
+ * @param options {
2064
+ * width, // (int), width in px, if negative, then it is maxWidth - width
2065
+ * height, // (int), height in px, if negative, then it is maxHeight - height
2066
+ * text, // centered text
2067
+ * body, // body of the message
2068
+ * buttons, // buttons of the message
2069
+ * html, // if body & buttons are not defined, then html is the entire message
2070
+ * focus, // int or id with a selector, default is 0
2071
+ * hideOn, // ['esc', 'click'], default is ['esc']
2072
+ * actions, // array of actions (only if buttons is not defined)
2073
+ * onOpen, // event when opened
2074
+ * onClose, // event when closed
2075
+ * onAction, // event on action
2076
+ * }
2077
+ */
2078
+ message(where, options) {
2079
+ return _message(where, options, this._msgDeps());
2080
+ }
2081
+ alert(where, options) {
2082
+ return _alert(where, options, this._msgDeps());
2083
+ }
2084
+ /**
2085
+ * Shows a prompt as a context message. It will use same where: { box: ... } as TsUtils.message() function
2086
+ * but it will have options similar to TsPrompt dialog
2087
+ *
2088
+ * Example:
2089
+ * - TsUtils.conrirm({
2090
+ * box: '#custom',
2091
+ * text: 'Some message'
2092
+ * })
2093
+ * .yes(event => console.log(event))
2094
+ */
2095
+ confirm(where, options) {
2096
+ return _confirm(where, options, this._confirmDeps());
2097
+ }
2098
+ /**
2099
+ * Shows a prompt as a context message. It will use same where: { box: ... } as TsUtils.message() function
2100
+ * but it will have options similar to TsPrompt dialog
2101
+ *
2102
+ * Example:
2103
+ * - TsUtils.prompt({
2104
+ * box: '#custom',
2105
+ * label: 'Enter Name',
2106
+ * textarea: false,
2107
+ * attrs: 'style="border: 1px solid red"'
2108
+ * })
2109
+ * .ok(event => console.log(event))
2110
+ */
2111
+ prompt(where, options) {
2112
+ return _prompt(where, options, this._promptDeps());
2113
+ }
2114
+ /**
2115
+ * Normalizes yes, no buttons for confirmation dialog
2116
+ *
2117
+ * @param {*} options
2118
+ * @returns options
2119
+ */
2120
+ normButtons(options, btn) {
2121
+ return normButtons(options, btn, {
2122
+ extend,
2123
+ lang: this.lang.bind(this),
2124
+ settings: this.settings
2125
+ });
2126
+ }
2127
+ /**
2128
+ * Shows small notification message at the bottom of the page, or containter that you specify
2129
+ * in options.where (could be element or a selector)
2130
+ *
2131
+ * TsUtils.notify('Document saved')
2132
+ * TsUtils.notify('Mesage sent ${udon}', { actions: { undo: function () {...} }})
2133
+ *
2134
+ * @param {String/Object} options can be {
2135
+ * text: string, // message, can be html
2136
+ * where: el/selector, // element or selector where to show, default is document.body
2137
+ * timeout: int, // timeout when to hide, if 0 - indefinite
2138
+ * error: boolean, // add error clases
2139
+ * class: string, // additional class strings
2140
+ * actions: object // object with action functions, it should correspot to templated text: '... ${action} ...'
2141
+ * }
2142
+ * @returns promise
2143
+ */
2144
+ notify(text, options) {
2145
+ return notify(text, options, { execTemplate: this.execTemplate.bind(this), tmpSlot: this.tmp });
2146
+ }
2147
+ getSize(el, type) {
2148
+ return getSize(el, type);
2149
+ }
2150
+ getStrDimentions(str, styles, raw) {
2151
+ return getStrDimentions(str, styles, raw);
2152
+ }
2153
+ getStrWidth(str, styles, raw) {
2154
+ return this.getStrDimentions(str, styles, raw).width;
2155
+ }
2156
+ getStrHeight(str, styles, raw) {
2157
+ return this.getStrDimentions(str, styles, raw).height;
2158
+ }
2159
+ // any: targeted-any per typing_policy; TsUtils helper accepts heterogeneous runtime input
2160
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2161
+ execTemplate(str, replace_obj) {
2162
+ return execTemplate(str, replace_obj);
2163
+ }
2164
+ // any: parameter typed any — runtime dispatch by call site; TsUtils helper accepts heterogeneous runtime input
2165
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2166
+ marker(el, items, options) {
2167
+ return marker(el, items, options);
2168
+ }
2169
+ lang(phrase, params) {
2170
+ if (!phrase || this.settings.phrases == null || typeof phrase !== "string" || "<=>=".includes(phrase)) {
2171
+ return this.execTemplate(phrase, params);
2172
+ }
2173
+ let translation = this.settings.phrases[phrase];
2174
+ if (translation == null) {
2175
+ translation = phrase;
2176
+ if (this.settings.warnNoPhrase) {
2177
+ if (!this.settings.missing) {
2178
+ this.settings.missing = {};
2179
+ }
2180
+ this.settings.missing[phrase] = "---";
2181
+ this.settings.phrases[phrase] = "---";
2182
+ console.log(
2183
+ `Missing translation for "%c${phrase}%c", see %c TsUtils.settings.phrases %c with value "---"`,
2184
+ "color: orange",
2185
+ "",
2186
+ "color: #999",
2187
+ ""
2188
+ );
2189
+ }
2190
+ } else if (translation === "---" && !this.settings.warnNoPhrase) {
2191
+ translation = phrase;
2192
+ }
2193
+ if (translation === "---") {
2194
+ translation = `<span ${this.tooltip(phrase)}>---</span>`;
2195
+ }
2196
+ return this.execTemplate(translation, params);
2197
+ }
2198
+ locale(locale, keepPhrases, noMerge) {
2199
+ const deps = {
2200
+ extend: this.extend.bind(this),
2201
+ fetch: globalThis.fetch.bind(globalThis)
2202
+ };
2203
+ return _locale(locale, keepPhrases, noMerge, this.settings, deps).then((result) => {
2204
+ if (result.settings) this.settings = result.settings;
2205
+ return result.kind === "load" ? { file: result.file, data: result.data } : void 0;
2206
+ });
2207
+ }
2208
+ scrollBarSize() {
2209
+ if (this.tmp["scrollBarSize"]) return this.tmp["scrollBarSize"];
2210
+ const html = `
2211
+ <div id="_scrollbar_width" style="position: absolute; top: -300px; width: 100px; height: 100px; overflow-y: scroll;">
2212
+ <div style="height: 120px">1</div>
2213
+ </div>
2214
+ `;
2215
+ query6("body").append(html);
2216
+ this.tmp["scrollBarSize"] = 100 - query6("#_scrollbar_width > div")[0].clientWidth;
2217
+ query6("#_scrollbar_width").remove();
2218
+ return this.tmp["scrollBarSize"];
2219
+ }
2220
+ checkName(name) {
2221
+ return checkName(name);
2222
+ }
2223
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2224
+ checkUniqueId(id, items, desc, obj) {
2225
+ if (!Array.isArray(items)) items = [items];
2226
+ let isUnique = true;
2227
+ items.forEach((item) => {
2228
+ if (item.id === id) {
2229
+ console.log(`ERROR: The item id="${id}" is not unique within the ${desc} "${obj}".`, items);
2230
+ isUnique = false;
2231
+ }
2232
+ });
2233
+ return isUnique;
2234
+ }
2235
+ /**
2236
+ * Takes an object and encodes it into params string to be passed as a url
2237
+ * { a: 1, b: 'str'} => "a=1&b=str"
2238
+ * { a: 1, b: { c: 2 }} => "a=1&b[c]=2"
2239
+ * { a: 1, b: {c: { k: 'dfdf' } } } => "a=1&b[c][k]=dfdf"
2240
+ */
2241
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2242
+ encodeParams(obj, prefix = "") {
2243
+ return encodeParams(obj, prefix);
2244
+ }
2245
+ parseRoute(route) {
2246
+ return parseRoute(route);
2247
+ }
2248
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2249
+ getCursorPosition(input) {
2250
+ if (input == null) return null;
2251
+ let caretOffset = 0;
2252
+ const doc = input.ownerDocument || input.document;
2253
+ const win = doc.defaultView || doc.parentWindow;
2254
+ let sel;
2255
+ if (["INPUT", "TEXTAREA"].includes(input.tagName)) {
2256
+ caretOffset = input.selectionStart;
2257
+ } else {
2258
+ if (win.getSelection) {
2259
+ sel = win.getSelection();
2260
+ if (sel.rangeCount > 0) {
2261
+ const range = sel.getRangeAt(0);
2262
+ const preCaretRange = range.cloneRange();
2263
+ preCaretRange.selectNodeContents(input);
2264
+ preCaretRange.setEnd(range.endContainer, range.endOffset);
2265
+ caretOffset = preCaretRange.toString().length;
2266
+ }
2267
+ } else if ((sel = doc.selection) && sel.type !== "Control") {
2268
+ const textRange = sel.createRange();
2269
+ const preCaretTextRange = doc.body.createTextRange();
2270
+ preCaretTextRange.moveToElementText(input);
2271
+ preCaretTextRange.setEndPoint("EndToEnd", textRange);
2272
+ caretOffset = preCaretTextRange.text.length;
2273
+ }
2274
+ }
2275
+ return caretOffset;
2276
+ }
2277
+ setCursorPosition(input, pos, posEnd) {
2278
+ if (input == null) return;
2279
+ const range = document.createRange();
2280
+ let el = null;
2281
+ const sel = window.getSelection();
2282
+ if (["INPUT", "TEXTAREA"].includes(input.tagName)) {
2283
+ ;
2284
+ input.setSelectionRange(pos, posEnd ?? pos);
2285
+ } else {
2286
+ for (let i = 0; i < input.childNodes.length; i++) {
2287
+ let tmp = String(query6(input.childNodes[i]).text());
2288
+ if (input.childNodes[i].tagName) {
2289
+ tmp = String(query6(input.childNodes[i]).html());
2290
+ tmp = tmp.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&").replace(/&quot;/g, '"').replace(/&nbsp;/g, " ");
2291
+ }
2292
+ if (pos <= tmp.length) {
2293
+ el = input.childNodes[i] ?? null;
2294
+ if (el != null && el.childNodes && el.childNodes.length > 0) el = el.childNodes[0] ?? null;
2295
+ if (el != null && el.childNodes && el.childNodes.length > 0) el = el.childNodes[0] ?? null;
2296
+ break;
2297
+ } else {
2298
+ pos -= tmp.length;
2299
+ }
2300
+ }
2301
+ if (el == null) return;
2302
+ const elLen = el.length ?? 0;
2303
+ if (pos > elLen) pos = elLen;
2304
+ range.setStart(el, pos);
2305
+ if (posEnd) {
2306
+ range.setEnd(el, posEnd);
2307
+ } else {
2308
+ range.collapse(true);
2309
+ }
2310
+ sel?.removeAllRanges();
2311
+ sel?.addRange(range);
2312
+ }
2313
+ }
2314
+ parseColor(str) {
2315
+ return parseColor(str);
2316
+ }
2317
+ colorContrast(color1, color2) {
2318
+ return colorContrast(color1, color2);
2319
+ }
2320
+ colorContrastValue(color1, color2) {
2321
+ return colorContrastValue(color1, color2);
2322
+ }
2323
+ // h=0..360, s=0..100, v=0..100
2324
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2325
+ hsv2rgb(h, s, v, a) {
2326
+ return hsv2rgb(h, s, v, a);
2327
+ }
2328
+ // any: overloaded dual-form delegator
2329
+ // r=0..255, g=0..255, b=0..255
2330
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2331
+ rgb2hsv(r, g, b, a) {
2332
+ return rgb2hsv(r, g, b, a);
2333
+ }
2334
+ // any: overloaded dual-form delegator
2335
+ tooltip(html, options) {
2336
+ let showOn = "mouseenter";
2337
+ let hideOn = "mouseleave";
2338
+ let opts = options ?? {};
2339
+ if (typeof html == "object") {
2340
+ opts = html;
2341
+ }
2342
+ if (typeof html == "string") {
2343
+ opts = { ...opts, html };
2344
+ }
2345
+ if (opts["showOn"]) {
2346
+ showOn = opts["showOn"];
2347
+ delete opts["showOn"];
2348
+ }
2349
+ if (opts["hideOn"]) {
2350
+ hideOn = opts["hideOn"];
2351
+ delete opts["hideOn"];
2352
+ }
2353
+ if (!opts["name"]) opts["name"] = "no-name";
2354
+ const actions = ` on${showOn}="TsTooltip.show(this, JSON.parse(TsUtils.base64decode('${this.base64encode(JSON.stringify(opts))}')))" on${hideOn}="TsTooltip.hide('${opts["name"]}')"`;
2355
+ return actions;
2356
+ }
2357
+ // determins if it is plain Object, not DOM element, nor a function, event, etc.
2358
+ isPlainObject(value) {
2359
+ return isPlainObject(value);
2360
+ }
2361
+ /**
2362
+ * Deep copy of an object or an array. Function, events and HTML elements will not be cloned,
2363
+ * you can choose to include them or not, by default they are included.
2364
+ * You can also exclude certain elements from final object if used with options: { exclude }
2365
+ */
2366
+ // any: return type any — caller narrows by code path; TsUtils helper accepts heterogeneous runtime input
2367
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2368
+ clone(obj, options) {
2369
+ return clone(obj, options);
2370
+ }
2371
+ /**
2372
+ * Deep extend an object, if an array, it overwrrites it, cloning objects in the process
2373
+ * target, source1, source2, ...
2374
+ */
2375
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2376
+ extend(target, source, ...rest) {
2377
+ return extend(target, source, ...rest);
2378
+ }
2379
+ // any: generic deep-extend; arbitrary object shapes at runtime
2380
+ /*
2381
+ * @author Lauri Rooden (https://github.com/litejs/natural-compare-lite)
2382
+ * @license MIT License
2383
+ */
2384
+ naturalCompare(a, b) {
2385
+ return naturalCompare(a, b);
2386
+ }
2387
+ /**
2388
+ * Takes a menu (used in drop downs, context menu, field: list/combo/enum) and normalizes it to the common structure, which
2389
+ * is { id: ..., text: ... }. In options you can pass { itemMap: { id: 'id_field', text: 'text_field' }} that will be used
2390
+ * to find out id and text fields.
2391
+ */
2392
+ normMenu(menu, options = {}) {
2393
+ return normMenu(menu, options);
2394
+ }
2395
+ /**
2396
+ * Takes Url object and fetchOptions and changes it in place applying selected user dataType. Since
2397
+ * dataType is in TsUtils. This method is used in grid, form and tooltip to prepare fetch parameters
2398
+ */
2399
+ prepareParams(url, fetchOptions, options = {}) {
2400
+ return prepareParams(url, fetchOptions, options, TsUtils.settings.dataType);
2401
+ }
2402
+ bindEvents(selector, subject) {
2403
+ return bindEvents(selector, subject);
2404
+ }
2405
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2406
+ debounce(func, wait2 = 250) {
2407
+ return debounce(func, wait2);
2408
+ }
2409
+ async wait(time = 0) {
2410
+ return wait(time);
2411
+ }
2412
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2413
+ getNested(obj, prop) {
2414
+ return getNested(obj, prop);
2415
+ }
2416
+ };
2417
+ var TsUtils = new Utils();
2418
+
2419
+ export {
2420
+ query6 as query,
2421
+ TsUtils
2422
+ };
2423
+ //# sourceMappingURL=chunk-3NYH6545.js.map