@ngrdt/utils 0.0.77 → 0.0.80
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.
- package/fesm2022/ngrdt-utils.mjs +1616 -4
- package/fesm2022/ngrdt-utils.mjs.map +1 -1
- package/package.json +3 -2
package/fesm2022/ngrdt-utils.mjs
CHANGED
|
@@ -1,8 +1,1620 @@
|
|
|
1
|
-
|
|
1
|
+
import { Observable, combineLatest, startWith, map, switchMap, EMPTY, of } from 'rxjs';
|
|
2
|
+
import { assertInInjectionContext, inject, Injector, effect, untracked, DestroyRef } from '@angular/core';
|
|
3
|
+
|
|
4
|
+
var RdtEncoding;
|
|
5
|
+
(function (RdtEncoding) {
|
|
6
|
+
RdtEncoding["UTF_8"] = "utf-8";
|
|
7
|
+
RdtEncoding["IBM_866"] = "ibm866";
|
|
8
|
+
RdtEncoding["ISO_8859_2"] = "iso-8859-2";
|
|
9
|
+
RdtEncoding["ISO_8859_3"] = "iso-8859-3";
|
|
10
|
+
RdtEncoding["ISO_8859_4"] = "iso-8859-4";
|
|
11
|
+
RdtEncoding["ISO_8859_5"] = "iso-8859-5";
|
|
12
|
+
RdtEncoding["ISO_8859_6"] = "iso-8859-6";
|
|
13
|
+
RdtEncoding["ISO_8859_7"] = "iso-8859-7";
|
|
14
|
+
RdtEncoding["ISO_8859_8"] = "iso-8859-8";
|
|
15
|
+
RdtEncoding["ISO_8859_8_I"] = "iso-8859-8-i";
|
|
16
|
+
RdtEncoding["ISO_8859_10"] = "iso-8859-10";
|
|
17
|
+
RdtEncoding["ISO_8859_13"] = "iso-8859-13";
|
|
18
|
+
RdtEncoding["ISO_8859_14"] = "iso-8859-14";
|
|
19
|
+
RdtEncoding["ISO_8859_15"] = "iso-8859-15";
|
|
20
|
+
RdtEncoding["ISO_8859_16"] = "iso-8859-16";
|
|
21
|
+
RdtEncoding["KOI8_R"] = "koi8-r";
|
|
22
|
+
RdtEncoding["MACINTOSH"] = "macintosh";
|
|
23
|
+
RdtEncoding["WINDOWS_874"] = "windows-874";
|
|
24
|
+
RdtEncoding["WINDOWS_1250"] = "windows-1250";
|
|
25
|
+
RdtEncoding["WINDOWS_1251"] = "windows-1251";
|
|
26
|
+
RdtEncoding["WINDOWS_1252"] = "windows-1252";
|
|
27
|
+
RdtEncoding["WINDOWS_1253"] = "windows-1253";
|
|
28
|
+
RdtEncoding["WINDOWS_1254"] = "windows-1254";
|
|
29
|
+
RdtEncoding["WINDOWS_1255"] = "windows-1255";
|
|
30
|
+
RdtEncoding["WINDOWS_1256"] = "windows-1256";
|
|
31
|
+
RdtEncoding["WINDOWS_1257"] = "windows-1257";
|
|
32
|
+
RdtEncoding["WINDOWS_1258"] = "windows-1258";
|
|
33
|
+
RdtEncoding["X_MAC_CYRILLIC"] = "x-mac-cyrillic";
|
|
34
|
+
RdtEncoding["GBK"] = "gbk";
|
|
35
|
+
RdtEncoding["GB18030"] = "gb18030";
|
|
36
|
+
RdtEncoding["BIG5"] = "big5";
|
|
37
|
+
RdtEncoding["EUC_JP"] = "euc-jp";
|
|
38
|
+
RdtEncoding["ISO_2022_JP"] = "iso-2022-jp";
|
|
39
|
+
RdtEncoding["SHIFT_JIS"] = "shift-jis";
|
|
40
|
+
RdtEncoding["EUC_KR"] = "euc-kr";
|
|
41
|
+
RdtEncoding["HZ_GB_2312"] = "hz-gb-2312";
|
|
42
|
+
RdtEncoding["ISO_2022_CN"] = "iso-2022-cn";
|
|
43
|
+
RdtEncoding["ISO_2022_CN_EXT"] = "iso-2022-cn-ext";
|
|
44
|
+
RdtEncoding["ISO_2022_KR"] = "iso-2022-kr";
|
|
45
|
+
RdtEncoding["UTF_16"] = "utf-16";
|
|
46
|
+
RdtEncoding["X_USER_DEFINED"] = "x-user-defined";
|
|
47
|
+
})(RdtEncoding || (RdtEncoding = {}));
|
|
48
|
+
|
|
49
|
+
const ARROW = {
|
|
50
|
+
UP: 'ArrowUp',
|
|
51
|
+
DOWN: 'ArrowDown',
|
|
52
|
+
LEFT: 'ArrowLeft',
|
|
53
|
+
RIGHT: 'ArrowRight',
|
|
54
|
+
};
|
|
55
|
+
const KB_KEY = {
|
|
56
|
+
SPACEBAR: ' ',
|
|
57
|
+
ENTER: 'Enter',
|
|
58
|
+
ESCAPE: 'Escape',
|
|
59
|
+
HOME: 'Home',
|
|
60
|
+
END: 'End',
|
|
61
|
+
TAB: 'Tab',
|
|
62
|
+
ARROW: ARROW,
|
|
63
|
+
};
|
|
64
|
+
const KB_CODE = {
|
|
65
|
+
...KB_KEY,
|
|
66
|
+
SPACEBAR: 'Space',
|
|
67
|
+
};
|
|
68
|
+
const ALPHABET_KEYCODES = Array.from(Array(26)).map((e, i) => i + 65);
|
|
69
|
+
const ALPHABET_KB_KEYS = ALPHABET_KEYCODES.map(x => String.fromCharCode(x));
|
|
70
|
+
const KB_ALPHABET_CODES = ALPHABET_KB_KEYS.map(key => `Key${key.toUpperCase()}`);
|
|
71
|
+
|
|
72
|
+
var RdtMimeType;
|
|
73
|
+
(function (RdtMimeType) {
|
|
74
|
+
RdtMimeType["DOCX"] = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
|
75
|
+
RdtMimeType["XLSX"] = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
76
|
+
RdtMimeType["PDF"] = "application/pdf";
|
|
77
|
+
RdtMimeType["TXT"] = "text/plain";
|
|
78
|
+
RdtMimeType["CSV"] = "text/csv";
|
|
79
|
+
RdtMimeType["ZIP"] = "application/zip";
|
|
80
|
+
RdtMimeType["JPG"] = "image/jpeg";
|
|
81
|
+
RdtMimeType["PNG"] = "image/png";
|
|
82
|
+
RdtMimeType["GIF"] = "image/gif";
|
|
83
|
+
RdtMimeType["SVG"] = "image/svg+xml";
|
|
84
|
+
RdtMimeType["HTML"] = "text/html";
|
|
85
|
+
RdtMimeType["XML"] = "application/xml";
|
|
86
|
+
RdtMimeType["JSON"] = "application/json";
|
|
87
|
+
RdtMimeType["MP3"] = "audio/mpeg";
|
|
88
|
+
RdtMimeType["MP4"] = "video/mp4";
|
|
89
|
+
RdtMimeType["OGG"] = "audio/ogg";
|
|
90
|
+
RdtMimeType["WEBM"] = "video/webm";
|
|
91
|
+
RdtMimeType["WAV"] = "audio/wav";
|
|
92
|
+
RdtMimeType["AVI"] = "video/x-msvideo";
|
|
93
|
+
RdtMimeType["MPEG"] = "video/mpeg";
|
|
94
|
+
RdtMimeType["WEBP"] = "image/webp";
|
|
95
|
+
RdtMimeType["ICO"] = "image/x-icon";
|
|
96
|
+
RdtMimeType["TTF"] = "font/ttf";
|
|
97
|
+
RdtMimeType["WOFF"] = "font/woff";
|
|
98
|
+
RdtMimeType["WOFF2"] = "font/woff2";
|
|
99
|
+
RdtMimeType["EOT"] = "application/vnd.ms-fontobject";
|
|
100
|
+
RdtMimeType["OTF"] = "font/otf";
|
|
101
|
+
RdtMimeType["PPTX"] = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
|
|
102
|
+
RdtMimeType["PPT"] = "application/vnd.ms-powerpoint";
|
|
103
|
+
RdtMimeType["XLS"] = "application/vnd.ms-excel";
|
|
104
|
+
RdtMimeType["DOC"] = "application/msword";
|
|
105
|
+
RdtMimeType["ODT"] = "application/vnd.oasis.opendocument.text";
|
|
106
|
+
RdtMimeType["ODS"] = "application/vnd.oasis.opendocument.spreadsheet";
|
|
107
|
+
RdtMimeType["ODP"] = "application/vnd.oasis.opendocument.presentation";
|
|
108
|
+
RdtMimeType["ODF"] = "application/vnd.oasis.opendocument.formula";
|
|
109
|
+
RdtMimeType["RAR"] = "application/vnd.rar";
|
|
110
|
+
RdtMimeType["TAR"] = "application/x-tar";
|
|
111
|
+
RdtMimeType["GZIP"] = "application/gzip";
|
|
112
|
+
RdtMimeType["BZIP2"] = "application/x-bzip2";
|
|
113
|
+
RdtMimeType["XZ"] = "application/x-xz";
|
|
114
|
+
RdtMimeType["SEVENZ"] = "application/x-7z-compressed";
|
|
115
|
+
RdtMimeType["RAR5"] = "application/x-rar-compressed";
|
|
116
|
+
RdtMimeType["WMA"] = "audio/x-ms-wma";
|
|
117
|
+
RdtMimeType["WMV"] = "video/x-ms-wmv";
|
|
118
|
+
RdtMimeType["FLV"] = "video/x-flv";
|
|
119
|
+
RdtMimeType["OGV"] = "video/ogg";
|
|
120
|
+
RdtMimeType["BIN"] = "application/octet-stream";
|
|
121
|
+
RdtMimeType["UNKNOWN"] = "unknown";
|
|
122
|
+
})(RdtMimeType || (RdtMimeType = {}));
|
|
123
|
+
var RdtCombinedMimeType;
|
|
124
|
+
(function (RdtCombinedMimeType) {
|
|
125
|
+
RdtCombinedMimeType["IMAGE"] = "image/*";
|
|
126
|
+
RdtCombinedMimeType["AUDIO"] = "audio/*";
|
|
127
|
+
RdtCombinedMimeType["VIDEO"] = "video/*";
|
|
128
|
+
RdtCombinedMimeType["FONT"] = "font/*";
|
|
129
|
+
RdtCombinedMimeType["DOCUMENT"] = "application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.oasis.opendocument.text,application/pdf,text/plain,text/csv";
|
|
130
|
+
RdtCombinedMimeType["SPREADSHEET"] = "application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.oasis.opendocument.spreadsheet";
|
|
131
|
+
RdtCombinedMimeType["PRESENTATION"] = "application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/vnd.oasis.opendocument.presentation";
|
|
132
|
+
RdtCombinedMimeType["ARCHIVE"] = "application/zip,application/vnd.rar,application/x-tar,application/gzip,application/x-bzip2,application/x-xz,application/x-7z-compressed,application/x-rar-compressed";
|
|
133
|
+
})(RdtCombinedMimeType || (RdtCombinedMimeType = {}));
|
|
134
|
+
const EXTENSION_BY_MIME_TYPE = {
|
|
135
|
+
[RdtMimeType.DOCX]: 'docx',
|
|
136
|
+
[RdtMimeType.XLSX]: 'xlsx',
|
|
137
|
+
[RdtMimeType.PDF]: 'pdf',
|
|
138
|
+
[RdtMimeType.TXT]: 'txt',
|
|
139
|
+
[RdtMimeType.CSV]: 'csv',
|
|
140
|
+
[RdtMimeType.ZIP]: 'zip',
|
|
141
|
+
[RdtMimeType.JPG]: 'jpg',
|
|
142
|
+
[RdtMimeType.PNG]: 'png',
|
|
143
|
+
[RdtMimeType.GIF]: 'gif',
|
|
144
|
+
[RdtMimeType.SVG]: 'svg',
|
|
145
|
+
[RdtMimeType.HTML]: 'html',
|
|
146
|
+
[RdtMimeType.XML]: 'xml',
|
|
147
|
+
[RdtMimeType.JSON]: 'json',
|
|
148
|
+
[RdtMimeType.MP3]: 'mp3',
|
|
149
|
+
[RdtMimeType.MP4]: 'mp4',
|
|
150
|
+
[RdtMimeType.OGG]: 'ogg',
|
|
151
|
+
[RdtMimeType.WEBM]: 'webm',
|
|
152
|
+
[RdtMimeType.WAV]: 'wav',
|
|
153
|
+
[RdtMimeType.AVI]: 'avi',
|
|
154
|
+
[RdtMimeType.MPEG]: 'mpeg',
|
|
155
|
+
[RdtMimeType.WEBP]: 'webp',
|
|
156
|
+
[RdtMimeType.ICO]: 'ico',
|
|
157
|
+
[RdtMimeType.TTF]: 'ttf',
|
|
158
|
+
[RdtMimeType.WOFF]: 'woff',
|
|
159
|
+
[RdtMimeType.WOFF2]: 'woff2',
|
|
160
|
+
[RdtMimeType.EOT]: 'eot',
|
|
161
|
+
[RdtMimeType.OTF]: 'otf',
|
|
162
|
+
[RdtMimeType.PPTX]: 'pptx',
|
|
163
|
+
[RdtMimeType.PPT]: 'ppt',
|
|
164
|
+
[RdtMimeType.XLS]: 'xls',
|
|
165
|
+
[RdtMimeType.DOC]: 'doc',
|
|
166
|
+
[RdtMimeType.ODT]: 'odt',
|
|
167
|
+
[RdtMimeType.ODS]: 'ods',
|
|
168
|
+
[RdtMimeType.ODP]: 'odp',
|
|
169
|
+
[RdtMimeType.ODF]: 'odf',
|
|
170
|
+
[RdtMimeType.RAR]: 'rar',
|
|
171
|
+
[RdtMimeType.TAR]: 'tar',
|
|
172
|
+
[RdtMimeType.GZIP]: 'gz',
|
|
173
|
+
[RdtMimeType.BZIP2]: 'bz2',
|
|
174
|
+
[RdtMimeType.XZ]: 'xz',
|
|
175
|
+
[RdtMimeType.SEVENZ]: '7z',
|
|
176
|
+
[RdtMimeType.RAR5]: 'rar',
|
|
177
|
+
[RdtMimeType.WMA]: 'wma',
|
|
178
|
+
[RdtMimeType.WMV]: 'wmv',
|
|
179
|
+
[RdtMimeType.FLV]: 'flv',
|
|
180
|
+
[RdtMimeType.OGV]: 'ogv',
|
|
181
|
+
[RdtMimeType.BIN]: 'bin',
|
|
182
|
+
[RdtMimeType.UNKNOWN]: 'unknown',
|
|
183
|
+
};
|
|
184
|
+
const MIME_TYPE_BY_EXTENSION = {};
|
|
185
|
+
for (const [key, value] of Object.entries(EXTENSION_BY_MIME_TYPE)) {
|
|
186
|
+
MIME_TYPE_BY_EXTENSION[value] = key;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
class RdtArrayUtils {
|
|
190
|
+
static removeAt(array, index) {
|
|
191
|
+
if (index < 0 || index > array.length) {
|
|
192
|
+
throw new Error(`Out of bounds! Array length: ${array.length}, index: ${index}`);
|
|
193
|
+
}
|
|
194
|
+
return [...array.slice(0, index), ...array.slice(index + 1)];
|
|
195
|
+
}
|
|
196
|
+
static insertAt(array, index, item) {
|
|
197
|
+
if (index < 0 || index > array.length) {
|
|
198
|
+
throw new Error(`Out of bounds! Array length: ${array.length}, index: ${index}`);
|
|
199
|
+
}
|
|
200
|
+
return [...array.slice(0, index), item, ...array.slice(index)];
|
|
201
|
+
}
|
|
202
|
+
static isEqual(a, b) {
|
|
203
|
+
if (!a || !b) {
|
|
204
|
+
return !a === !b;
|
|
205
|
+
}
|
|
206
|
+
return a.length === b.length && a.every((el) => b.indexOf(el) > -1);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
class RdtCssUtils {
|
|
211
|
+
static normalizeColor(color) {
|
|
212
|
+
const normalized = color.trim();
|
|
213
|
+
if (this.isHexColor(normalized)) {
|
|
214
|
+
return RdtCssUtils.normalizeHex(normalized);
|
|
215
|
+
}
|
|
216
|
+
else if (this.isRgbColor(normalized)) {
|
|
217
|
+
return RdtCssUtils.normalizeRgb(normalized);
|
|
218
|
+
}
|
|
219
|
+
else if (this.isRgbaColor(normalized)) {
|
|
220
|
+
return RdtCssUtils.normalizeRgba(normalized);
|
|
221
|
+
}
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
static normalizeHex(color) {
|
|
225
|
+
const matches = color.match(RdtCssUtils.hexRegex);
|
|
226
|
+
if (!matches) {
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
return `#${matches[2]}`;
|
|
230
|
+
}
|
|
231
|
+
static normalizeRgb(color) {
|
|
232
|
+
const matches = color.match(RdtCssUtils.rgbRegex);
|
|
233
|
+
if (!matches) {
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
return `rgb(${matches[2]},${matches[3]},${matches[4]})`;
|
|
237
|
+
}
|
|
238
|
+
static normalizeRgba(color) {
|
|
239
|
+
const matches = color.match(RdtCssUtils.rgbaRegex);
|
|
240
|
+
if (!matches) {
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
return `rgba(${matches[2]},${matches[3]},${matches[4]},${matches[5]})`;
|
|
244
|
+
}
|
|
245
|
+
static isRgbColor(color) {
|
|
246
|
+
return RdtCssUtils.rgbRegex.test(color);
|
|
247
|
+
}
|
|
248
|
+
static isHexColor(color) {
|
|
249
|
+
return RdtCssUtils.hexRegex.test(color);
|
|
250
|
+
}
|
|
251
|
+
static isRgbaColor(color) {
|
|
252
|
+
return RdtCssUtils.rgbaRegex.test(color);
|
|
253
|
+
}
|
|
254
|
+
static rgbRegex = /^(rgb)?\(?\s*([01]?\d\d?|2[0-4]\d|25[0-5])\W+([01]?\d\d?|2[0-4]\d|25[0-5])\W+([01]?\d\d?|2[0-4]\d|25[0-5])\s*\)?$/;
|
|
255
|
+
static rgbaRegex = /^(rgba)?\(?\s*([01]?\d\d?|2[0-4]\d|25[0-5])\W+([01]?\d\d?|2[0-4]\d|25[0-5])\W+([01]?\d\d?|2[0-4]\d|25[0-5])\W+((0(\.\d+)?)|(1(\.0)?))\s*\)?$/;
|
|
256
|
+
static hexRegex = /^(#?)([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
class RdtDateUtils {
|
|
260
|
+
static MS = 1;
|
|
261
|
+
static SECOND = 1000 * RdtDateUtils.MS;
|
|
262
|
+
static MINUTE = 60 * RdtDateUtils.SECOND;
|
|
263
|
+
static HOUR = 60 * RdtDateUtils.MINUTE;
|
|
264
|
+
static DAY = 24 * RdtDateUtils.HOUR;
|
|
265
|
+
/**
|
|
266
|
+
* Returns number of days between two dates.
|
|
267
|
+
* Returns zero in case dates are the same. Ignores time.
|
|
268
|
+
*/
|
|
269
|
+
static getDays(a, b) {
|
|
270
|
+
return (RdtDateUtils.getDayOffset(new Date(a)) -
|
|
271
|
+
RdtDateUtils.getDayOffset(new Date(b)));
|
|
272
|
+
}
|
|
273
|
+
static checkDate(year, month, day) {
|
|
274
|
+
const d = new Date(year, month - 1, day);
|
|
275
|
+
return (d.getFullYear() === year &&
|
|
276
|
+
d.getMonth() + 1 === month &&
|
|
277
|
+
d.getDate() === day);
|
|
278
|
+
}
|
|
279
|
+
static isValidDate(value) {
|
|
280
|
+
if (value == null) {
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
if (value instanceof Date) {
|
|
284
|
+
return !isNaN(value.getTime());
|
|
285
|
+
}
|
|
286
|
+
return !isNaN(new Date(value).getTime());
|
|
287
|
+
}
|
|
288
|
+
static startOfDay(input) {
|
|
289
|
+
const date = new Date(input);
|
|
290
|
+
date.setHours(0, 0, 0, 0);
|
|
291
|
+
return date;
|
|
292
|
+
}
|
|
293
|
+
static endOfDay(input) {
|
|
294
|
+
const date = new Date(input);
|
|
295
|
+
date.setHours(23, 59, 59);
|
|
296
|
+
return date;
|
|
297
|
+
}
|
|
298
|
+
static startOfMonth(input) {
|
|
299
|
+
const date = new Date(input);
|
|
300
|
+
date.setHours(0, 0, 0, 0);
|
|
301
|
+
date.setDate(1);
|
|
302
|
+
return date;
|
|
303
|
+
}
|
|
304
|
+
static endOfMonth(input) {
|
|
305
|
+
const date = new Date(input);
|
|
306
|
+
date.setHours(23, 59, 59);
|
|
307
|
+
date.setDate(0);
|
|
308
|
+
return date;
|
|
309
|
+
}
|
|
310
|
+
static startOfYear(year) {
|
|
311
|
+
return new Date(year, Month.January, 1);
|
|
312
|
+
}
|
|
313
|
+
static endOfYear(year) {
|
|
314
|
+
return new Date(year, Month.December, 31);
|
|
315
|
+
}
|
|
316
|
+
static beginningOfNextMonth() {
|
|
317
|
+
const today = new Date();
|
|
318
|
+
if (today.getMonth() === 11) {
|
|
319
|
+
return new Date(today.getFullYear() + 1, 0, 1);
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
return new Date(today.getFullYear(), today.getMonth() + 1, 1);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
static endOfNextMonth() {
|
|
326
|
+
const today = new Date();
|
|
327
|
+
if (today.getMonth() === 10) {
|
|
328
|
+
const firstDayOfInTwoMonths = new Date(today.getFullYear() + 1, 0, 1);
|
|
329
|
+
return this.minusOneDay(firstDayOfInTwoMonths);
|
|
330
|
+
}
|
|
331
|
+
else if (today.getMonth() === 11) {
|
|
332
|
+
const firstDayOfInTwoMonths = new Date(today.getFullYear() + 1, 1, 1);
|
|
333
|
+
return this.minusOneDay(firstDayOfInTwoMonths);
|
|
334
|
+
}
|
|
335
|
+
else {
|
|
336
|
+
const firstDayOfInTwoMonths = new Date(today.getFullYear(), today.getMonth() + 2, 1);
|
|
337
|
+
return this.minusOneDay(firstDayOfInTwoMonths);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
static beginningOfInThreeMonths() {
|
|
341
|
+
const today = new Date();
|
|
342
|
+
if (today.getMonth() === 10) {
|
|
343
|
+
return new Date(today.getFullYear() + 1, 1, 1);
|
|
344
|
+
}
|
|
345
|
+
else if (today.getMonth() === 11) {
|
|
346
|
+
return new Date(today.getFullYear() + 1, 2, 1);
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
return new Date(today.getFullYear(), today.getMonth() + 3, 1);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
static endOfInNextThreeMonths() {
|
|
353
|
+
const today = new Date();
|
|
354
|
+
if (today.getMonth() === 9) {
|
|
355
|
+
const firstDayOfInFourMonths = new Date(today.getFullYear() + 1, 1, 1);
|
|
356
|
+
return this.minusOneDay(firstDayOfInFourMonths);
|
|
357
|
+
}
|
|
358
|
+
else if (today.getMonth() === 10) {
|
|
359
|
+
const firstDayOfInFourMonths = new Date(today.getFullYear() + 1, 2, 1);
|
|
360
|
+
return this.minusOneDay(firstDayOfInFourMonths);
|
|
361
|
+
}
|
|
362
|
+
else if (today.getMonth() === 11) {
|
|
363
|
+
const firstDayOfInFourMonths = new Date(today.getFullYear() + 1, 3, 1);
|
|
364
|
+
return this.minusOneDay(firstDayOfInFourMonths);
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
const firstDayOfInFourMonths = new Date(today.getFullYear(), today.getMonth() + 4, 1);
|
|
368
|
+
return this.minusOneDay(firstDayOfInFourMonths);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
static minusOneDay(date) {
|
|
372
|
+
return new Date(date.getTime() - RdtDateUtils.DAY);
|
|
373
|
+
}
|
|
374
|
+
static toISOLocal(d) {
|
|
375
|
+
const year = d.getFullYear();
|
|
376
|
+
const month = `${d.getMonth() + 1}`.padStart(2, '0');
|
|
377
|
+
const day = `${d.getDate()}`.padStart(2, '0');
|
|
378
|
+
const hours = `${d.getHours()}`.padStart(2, '0');
|
|
379
|
+
const minutes = `${d.getMinutes()}`.padStart(2, '0');
|
|
380
|
+
const seconds = `${d.getSeconds()}`.padStart(2, '0');
|
|
381
|
+
return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}`;
|
|
382
|
+
}
|
|
383
|
+
static formatDate(date) {
|
|
384
|
+
if (date === null || date === undefined || date === '') {
|
|
385
|
+
return '';
|
|
386
|
+
}
|
|
387
|
+
const d = date instanceof Date ? date : new Date(date);
|
|
388
|
+
if (RdtDateUtils.isValidDate(d)) {
|
|
389
|
+
const year = d.getFullYear();
|
|
390
|
+
const month = `${d.getMonth() + 1}`.padStart(2, '0');
|
|
391
|
+
const day = `${d.getDate()}`.padStart(2, '0');
|
|
392
|
+
return `${day}.${month}.${year}`;
|
|
393
|
+
}
|
|
394
|
+
else {
|
|
395
|
+
return '';
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
static timeToDate(time) {
|
|
399
|
+
const date = new Date(0);
|
|
400
|
+
if (RdtDateUtils.hhMmSsMsRegex.test(time)) {
|
|
401
|
+
const matches = time.match(RdtDateUtils.hhMmSsMsRegex);
|
|
402
|
+
if (matches) {
|
|
403
|
+
const h = parseInt(matches[1]);
|
|
404
|
+
const m = parseInt(matches[2]);
|
|
405
|
+
const s = parseInt(matches[3]);
|
|
406
|
+
const ms = parseInt(matches[4]);
|
|
407
|
+
date.setHours(h, m, s, ms);
|
|
408
|
+
return date;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
else if (RdtDateUtils.hhMmSsRegex.test(time)) {
|
|
412
|
+
const matches = time.match(RdtDateUtils.hhMmSsRegex);
|
|
413
|
+
if (matches) {
|
|
414
|
+
const h = parseInt(matches[1]);
|
|
415
|
+
const m = parseInt(matches[2]);
|
|
416
|
+
const s = parseInt(matches[3]);
|
|
417
|
+
date.setHours(h, m, s);
|
|
418
|
+
return date;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
else if (RdtDateUtils.hhMmRegex.test(time)) {
|
|
422
|
+
const matches = time.match(RdtDateUtils.hhMmRegex);
|
|
423
|
+
if (matches) {
|
|
424
|
+
const h = parseInt(matches[1]);
|
|
425
|
+
const m = parseInt(matches[2]);
|
|
426
|
+
date.setHours(h, m);
|
|
427
|
+
return date;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
return null;
|
|
431
|
+
}
|
|
432
|
+
static setTime(date, time) {
|
|
433
|
+
const newDate = new Date(date);
|
|
434
|
+
const timeDate = RdtDateUtils.timeToDate(time);
|
|
435
|
+
if (timeDate) {
|
|
436
|
+
newDate.setHours(timeDate.getHours(), timeDate.getMinutes(), timeDate.getSeconds(), timeDate.getMilliseconds());
|
|
437
|
+
}
|
|
438
|
+
return newDate;
|
|
439
|
+
}
|
|
440
|
+
static getTime(d, showSeconds = true) {
|
|
441
|
+
const hh = d.getHours().toString().padStart(2, '0');
|
|
442
|
+
const mm = d.getMinutes().toString().padStart(2, '0');
|
|
443
|
+
if (showSeconds) {
|
|
444
|
+
const ss = d.getSeconds().toString().padStart(2, '0');
|
|
445
|
+
return `${hh}:${mm}:${ss}`;
|
|
446
|
+
}
|
|
447
|
+
else {
|
|
448
|
+
return `${hh}:${mm}`;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
static parseToDate(input) {
|
|
452
|
+
if (input instanceof Date) {
|
|
453
|
+
return RdtDateUtils.isValidDate(input) ? input : null;
|
|
454
|
+
}
|
|
455
|
+
if (typeof input === 'string') {
|
|
456
|
+
const date = new Date(input);
|
|
457
|
+
if (RdtDateUtils.isValidDate(date)) {
|
|
458
|
+
return date;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
return null;
|
|
462
|
+
}
|
|
463
|
+
static parse(input) {
|
|
464
|
+
if (input instanceof Date) {
|
|
465
|
+
return RdtDateUtils.isValidDate(input) ? input.getTime() : null;
|
|
466
|
+
}
|
|
467
|
+
if (typeof input === 'string') {
|
|
468
|
+
const date = new Date(input);
|
|
469
|
+
if (RdtDateUtils.isValidDate(date)) {
|
|
470
|
+
return date.getTime();
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
return null;
|
|
474
|
+
}
|
|
475
|
+
static isEqual(d1, d2) {
|
|
476
|
+
if (d1 === d2) {
|
|
477
|
+
return true;
|
|
478
|
+
}
|
|
479
|
+
if (!d1 || !d2) {
|
|
480
|
+
return false;
|
|
481
|
+
}
|
|
482
|
+
return d1.getTime() === d2.getTime();
|
|
483
|
+
}
|
|
484
|
+
static isLeapYear(year) {
|
|
485
|
+
return new Date(year, 1, 29).getDate() === 29;
|
|
486
|
+
}
|
|
487
|
+
static getDaysInYear(year) {
|
|
488
|
+
return RdtDateUtils.isLeapYear(year) ? 366 : 365;
|
|
489
|
+
}
|
|
490
|
+
static hhMmRegex = /^\s*([0-9]|0[0-9]|1[0-9]|2[0-3])\s*\W+\s*([0-5]?[0-9])\s*$/;
|
|
491
|
+
static hhMmSsRegex = /^\s*([0-9]|0[0-9]|1[0-9]|2[0-3])\s*\W+\s*([0-5]?[0-9])\s*\W+\s*([0-5]?\d)\s*$/;
|
|
492
|
+
static hhMmSsMsRegex = /^\s*([0-9]|0[0-9]|1[0-9]|2[0-3])\s*\W+\s*([0-5]?[0-9])\s*\W+\s*([0-5]?\d)\s*[\W|\s]\s*(\d{1,3})\s*$/;
|
|
493
|
+
static daysUpToMonth = [
|
|
494
|
+
0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334,
|
|
495
|
+
];
|
|
496
|
+
static daysUpToMonthLeapYear = [
|
|
497
|
+
0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335,
|
|
498
|
+
];
|
|
499
|
+
static getDayOffset(date) {
|
|
500
|
+
const year = date.getFullYear() - 1;
|
|
501
|
+
const month = date.getMonth() + 1, day = date.getDate();
|
|
502
|
+
const numOfLeapsYear = Math.trunc(year / 4) - Math.trunc(year / 100) + Math.trunc(year / 400);
|
|
503
|
+
if (RdtDateUtils.isLeapYear(year + 1)) {
|
|
504
|
+
return (year * 365 +
|
|
505
|
+
numOfLeapsYear +
|
|
506
|
+
RdtDateUtils.daysUpToMonthLeapYear[month - 1] +
|
|
507
|
+
day -
|
|
508
|
+
1);
|
|
509
|
+
}
|
|
510
|
+
else {
|
|
511
|
+
return (year * 365 +
|
|
512
|
+
numOfLeapsYear +
|
|
513
|
+
RdtDateUtils.daysUpToMonth[month - 1] +
|
|
514
|
+
day -
|
|
515
|
+
1);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
static doubleDigitYearToPast(year2) {
|
|
519
|
+
// If current year is 2024 and input is 24 or less, then result is 2024
|
|
520
|
+
// If input is 25 or greater, then result is 1925-1999
|
|
521
|
+
const currentYear = RdtDateUtils.getCurrentYear();
|
|
522
|
+
const current2 = currentYear % 100;
|
|
523
|
+
if (year2 <= current2) {
|
|
524
|
+
return year2 + currentYear - current2;
|
|
525
|
+
}
|
|
526
|
+
else {
|
|
527
|
+
return year2 + currentYear - current2 - 100;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
static doubleDigitYearToFuture(year2) {
|
|
531
|
+
// If current year is 2024 and input is 24 or less, then result is 2124
|
|
532
|
+
// If input is 25 or greater, then result is 2025-2099
|
|
533
|
+
const currentYear = RdtDateUtils.getCurrentYear();
|
|
534
|
+
const current2 = currentYear % 100;
|
|
535
|
+
if (year2 >= current2) {
|
|
536
|
+
return year2 + currentYear - current2;
|
|
537
|
+
}
|
|
538
|
+
else {
|
|
539
|
+
return year2 + currentYear - current2 + 100;
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
static getCurrentYear() {
|
|
543
|
+
return new Date().getFullYear();
|
|
544
|
+
}
|
|
545
|
+
static calculateAge(birthDateStr, referenceDateStr) {
|
|
546
|
+
const birthDate = new Date(birthDateStr);
|
|
547
|
+
const referenceDate = new Date(referenceDateStr);
|
|
548
|
+
let age = referenceDate.getFullYear() - birthDate.getFullYear();
|
|
549
|
+
const monthDifference = referenceDate.getMonth() - birthDate.getMonth();
|
|
550
|
+
const dayDifference = referenceDate.getDate() - birthDate.getDate();
|
|
551
|
+
if (monthDifference < 0 || (monthDifference === 0 && dayDifference < 0)) {
|
|
552
|
+
age--;
|
|
553
|
+
}
|
|
554
|
+
return age;
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
var Month;
|
|
558
|
+
(function (Month) {
|
|
559
|
+
Month[Month["January"] = 0] = "January";
|
|
560
|
+
Month[Month["February"] = 1] = "February";
|
|
561
|
+
Month[Month["March"] = 2] = "March";
|
|
562
|
+
Month[Month["April"] = 3] = "April";
|
|
563
|
+
Month[Month["May"] = 4] = "May";
|
|
564
|
+
Month[Month["June"] = 5] = "June";
|
|
565
|
+
Month[Month["July"] = 6] = "July";
|
|
566
|
+
Month[Month["August"] = 7] = "August";
|
|
567
|
+
Month[Month["September"] = 8] = "September";
|
|
568
|
+
Month[Month["October"] = 9] = "October";
|
|
569
|
+
Month[Month["November"] = 10] = "November";
|
|
570
|
+
Month[Month["December"] = 11] = "December";
|
|
571
|
+
})(Month || (Month = {}));
|
|
572
|
+
|
|
573
|
+
class RdtHTMLUtils {
|
|
574
|
+
static scrollIntoViewHorizontallyWithinParent(element) {
|
|
575
|
+
const container = element.parentElement;
|
|
576
|
+
if (!container) {
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
const elOffset = element.offsetLeft;
|
|
580
|
+
const elWidth = element.offsetWidth;
|
|
581
|
+
const containerWidth = container.offsetWidth;
|
|
582
|
+
const currentScroll = container.scrollLeft;
|
|
583
|
+
const alignLeft = elOffset;
|
|
584
|
+
const alignRight = elOffset - containerWidth + elWidth;
|
|
585
|
+
if (currentScroll > alignLeft) {
|
|
586
|
+
container.scrollLeft = alignLeft;
|
|
587
|
+
}
|
|
588
|
+
else if (currentScroll < alignRight) {
|
|
589
|
+
container.scrollLeft = alignRight;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
static setCaretPosition(element, index) {
|
|
593
|
+
element.focus();
|
|
594
|
+
element.setSelectionRange(index, index);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
class RdtStringUtils {
|
|
599
|
+
static tokenize(value) {
|
|
600
|
+
return value ? value.split(/\W+/).filter((tokens) => !!tokens) : [];
|
|
601
|
+
}
|
|
602
|
+
static joinPaths(parent, child) {
|
|
603
|
+
const b = parent.endsWith('/');
|
|
604
|
+
const p = child.startsWith('/');
|
|
605
|
+
if (b && p) {
|
|
606
|
+
return parent.slice(0, -1) + child;
|
|
607
|
+
}
|
|
608
|
+
else if (b || p) {
|
|
609
|
+
return parent + child;
|
|
610
|
+
}
|
|
611
|
+
else {
|
|
612
|
+
return parent + '/' + child;
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
static isAlphabetCharacter(char) {
|
|
616
|
+
if (char.length > 1) {
|
|
617
|
+
return false;
|
|
618
|
+
}
|
|
619
|
+
return char.toLocaleLowerCase() !== char.toLocaleUpperCase();
|
|
620
|
+
}
|
|
621
|
+
static isNumericCharacter(char) {
|
|
622
|
+
return !isNaN(parseInt(char));
|
|
623
|
+
}
|
|
624
|
+
static capitalize(str) {
|
|
625
|
+
return str.charAt(0).toLocaleUpperCase() + str.slice(1);
|
|
626
|
+
}
|
|
627
|
+
static toDataTestId(str) {
|
|
628
|
+
return RdtStringUtils.removeAccents(str).toLowerCase()?.replace(/ /g, '-');
|
|
629
|
+
}
|
|
630
|
+
static removeAccents(str) {
|
|
631
|
+
return str.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
|
|
632
|
+
}
|
|
633
|
+
static stripTrailingSlash(url) {
|
|
634
|
+
const match = url.match(/#|\?|$/);
|
|
635
|
+
const pathEndIdx = (match && match.index) || url.length;
|
|
636
|
+
const droppedSlashIdx = pathEndIdx - (url[pathEndIdx - 1] === '/' ? 1 : 0);
|
|
637
|
+
return url.slice(0, droppedSlashIdx) + url.slice(pathEndIdx);
|
|
638
|
+
}
|
|
639
|
+
static createAbsoluteUrl(url, baseHref) {
|
|
640
|
+
return RdtStringUtils.joinPaths(baseHref, url);
|
|
641
|
+
}
|
|
642
|
+
static appendQueryParams(url, params) {
|
|
643
|
+
if (!params || Object.keys(params).length === 0) {
|
|
644
|
+
return url;
|
|
645
|
+
}
|
|
646
|
+
else {
|
|
647
|
+
const queryParams = new URLSearchParams(params);
|
|
648
|
+
return `${url}?${queryParams}`;
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
static localeCompare(a, b, order = 'asc') {
|
|
652
|
+
const mult = order === 'asc' ? 1 : -1;
|
|
653
|
+
if (a == b) {
|
|
654
|
+
return 0;
|
|
655
|
+
}
|
|
656
|
+
else if (a == null) {
|
|
657
|
+
return -mult;
|
|
658
|
+
}
|
|
659
|
+
else if (b == null) {
|
|
660
|
+
return mult;
|
|
661
|
+
}
|
|
662
|
+
return a.localeCompare(b) * mult;
|
|
663
|
+
}
|
|
664
|
+
static komixcomlocalReplaceString(url) {
|
|
665
|
+
const hostname = location.hostname;
|
|
666
|
+
const replaceString = url.includes('komix.com')
|
|
667
|
+
? 'komix.com'
|
|
668
|
+
: 'komix.local';
|
|
669
|
+
const toReplace = hostname.includes('komix.com')
|
|
670
|
+
? 'komix.com'
|
|
671
|
+
: 'komix.local';
|
|
672
|
+
return { replaceString, toReplace };
|
|
673
|
+
}
|
|
674
|
+
static swapChars(src, i, j) {
|
|
675
|
+
if (i < 0 || j < 0 || i >= src.length || j >= src.length) {
|
|
676
|
+
return src;
|
|
677
|
+
}
|
|
678
|
+
if (j < i) {
|
|
679
|
+
[i, j] = [j, i];
|
|
680
|
+
}
|
|
681
|
+
return (src.slice(0, i) + src[j] + src.slice(i + 1, j) + src[i] + src.slice(j + 1));
|
|
682
|
+
}
|
|
683
|
+
static insertAt(src, index, value) {
|
|
684
|
+
return src.slice(0, index) + value + src.slice(index);
|
|
685
|
+
}
|
|
686
|
+
static getDataTestId(label, prefix, suffix) {
|
|
687
|
+
let dataTestId = label.toLowerCase()?.replace(/ /g, '-');
|
|
688
|
+
if (prefix) {
|
|
689
|
+
dataTestId = `${prefix}__${dataTestId}`;
|
|
690
|
+
}
|
|
691
|
+
if (suffix) {
|
|
692
|
+
dataTestId = `${dataTestId}--${suffix}`;
|
|
693
|
+
}
|
|
694
|
+
return RdtStringUtils.removeAccents(dataTestId);
|
|
695
|
+
}
|
|
696
|
+
static stripQueryParams(url) {
|
|
697
|
+
const match = url.match(/#|\?|$/);
|
|
698
|
+
const pathEndIdx = (match && match.index) || url.length;
|
|
699
|
+
return url.slice(0, pathEndIdx);
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
var RdtFormatType;
|
|
704
|
+
(function (RdtFormatType) {
|
|
705
|
+
RdtFormatType["Day"] = "day";
|
|
706
|
+
RdtFormatType["Month"] = "month";
|
|
707
|
+
RdtFormatType["Year"] = "year";
|
|
708
|
+
RdtFormatType["Constant"] = "constant";
|
|
709
|
+
})(RdtFormatType || (RdtFormatType = {}));
|
|
710
|
+
const PRIMENG_DATE_FORMAT_META = {
|
|
711
|
+
d: {
|
|
712
|
+
type: RdtFormatType.Day,
|
|
713
|
+
minLength: 1,
|
|
714
|
+
maxLength: 2,
|
|
715
|
+
},
|
|
716
|
+
dd: {
|
|
717
|
+
type: RdtFormatType.Day,
|
|
718
|
+
minLength: 2,
|
|
719
|
+
maxLength: 2,
|
|
720
|
+
},
|
|
721
|
+
m: {
|
|
722
|
+
type: RdtFormatType.Month,
|
|
723
|
+
minLength: 1,
|
|
724
|
+
maxLength: 2,
|
|
725
|
+
},
|
|
726
|
+
mm: {
|
|
727
|
+
type: RdtFormatType.Month,
|
|
728
|
+
minLength: 2,
|
|
729
|
+
maxLength: 2,
|
|
730
|
+
},
|
|
731
|
+
y: {
|
|
732
|
+
type: RdtFormatType.Year,
|
|
733
|
+
minLength: 2,
|
|
734
|
+
maxLength: 2,
|
|
735
|
+
},
|
|
736
|
+
yy: {
|
|
737
|
+
type: RdtFormatType.Year,
|
|
738
|
+
minLength: 4,
|
|
739
|
+
maxLength: 4,
|
|
740
|
+
},
|
|
741
|
+
};
|
|
742
|
+
var RdtInsertMode;
|
|
743
|
+
(function (RdtInsertMode) {
|
|
744
|
+
RdtInsertMode[RdtInsertMode["Overwrite"] = 0] = "Overwrite";
|
|
745
|
+
RdtInsertMode[RdtInsertMode["Shift"] = 1] = "Shift";
|
|
746
|
+
})(RdtInsertMode || (RdtInsertMode = {}));
|
|
747
|
+
var RdtPasteMode;
|
|
748
|
+
(function (RdtPasteMode) {
|
|
749
|
+
RdtPasteMode[RdtPasteMode["Replace"] = 0] = "Replace";
|
|
750
|
+
RdtPasteMode[RdtPasteMode["Insert"] = 1] = "Insert";
|
|
751
|
+
})(RdtPasteMode || (RdtPasteMode = {}));
|
|
752
|
+
var RdtYearInputMode;
|
|
753
|
+
(function (RdtYearInputMode) {
|
|
754
|
+
RdtYearInputMode[RdtYearInputMode["FourDigit"] = 1] = "FourDigit";
|
|
755
|
+
RdtYearInputMode[RdtYearInputMode["TwoDigit"] = 2] = "TwoDigit";
|
|
756
|
+
RdtYearInputMode[RdtYearInputMode["Both"] = 3] = "Both";
|
|
757
|
+
})(RdtYearInputMode || (RdtYearInputMode = {}));
|
|
758
|
+
var RdtLeadingZeroInputMode;
|
|
759
|
+
(function (RdtLeadingZeroInputMode) {
|
|
760
|
+
RdtLeadingZeroInputMode[RdtLeadingZeroInputMode["NoLeadingZero"] = 1] = "NoLeadingZero";
|
|
761
|
+
RdtLeadingZeroInputMode[RdtLeadingZeroInputMode["LeadingZero"] = 2] = "LeadingZero";
|
|
762
|
+
RdtLeadingZeroInputMode[RdtLeadingZeroInputMode["Both"] = 3] = "Both";
|
|
763
|
+
})(RdtLeadingZeroInputMode || (RdtLeadingZeroInputMode = {}));
|
|
764
|
+
function getDigitCount(value) {
|
|
765
|
+
return (Math.log10(value) + 1) | 0;
|
|
766
|
+
}
|
|
767
|
+
class RdtDateParser {
|
|
768
|
+
cfg;
|
|
769
|
+
_value;
|
|
770
|
+
_inputValue;
|
|
771
|
+
_parsedFormat;
|
|
772
|
+
deleting;
|
|
773
|
+
caretPosition;
|
|
774
|
+
constructor(cfg) {
|
|
775
|
+
this.cfg = cfg;
|
|
776
|
+
this._inputValue = '';
|
|
777
|
+
this._value = null;
|
|
778
|
+
this._parsedFormat = this.parseFormat(cfg);
|
|
779
|
+
this.deleting = false;
|
|
780
|
+
this.caretPosition = 0;
|
|
781
|
+
}
|
|
782
|
+
set leadingZeroMode(mode) {
|
|
783
|
+
this.cfg.leadingZeroMode = mode;
|
|
784
|
+
this._parsedFormat = this.parseFormat(this.cfg);
|
|
785
|
+
}
|
|
786
|
+
get leadingZeroMode() {
|
|
787
|
+
return this.cfg.leadingZeroMode;
|
|
788
|
+
}
|
|
789
|
+
set yearInputMode(mode) {
|
|
790
|
+
this.cfg.yearInputMode = mode;
|
|
791
|
+
this._parsedFormat = this.parseFormat(this.cfg);
|
|
792
|
+
}
|
|
793
|
+
get yearInputMode() {
|
|
794
|
+
return this.cfg.yearInputMode;
|
|
795
|
+
}
|
|
796
|
+
set twoDigitYearInputStrategy(strategy) {
|
|
797
|
+
this.cfg.twoDigitYearInputStrategy = strategy;
|
|
798
|
+
this._parsedFormat = this.parseFormat(this.cfg);
|
|
799
|
+
}
|
|
800
|
+
get twoDigitYearInputStrategy() {
|
|
801
|
+
return this.cfg.twoDigitYearInputStrategy;
|
|
802
|
+
}
|
|
803
|
+
set insertMode(mode) {
|
|
804
|
+
this.cfg.insertMode = mode;
|
|
805
|
+
this._parsedFormat = this.parseFormat(this.cfg);
|
|
806
|
+
}
|
|
807
|
+
get insertMode() {
|
|
808
|
+
return this.cfg.insertMode;
|
|
809
|
+
}
|
|
810
|
+
set format(format) {
|
|
811
|
+
this.cfg.format = format;
|
|
812
|
+
this._parsedFormat = this.parseFormat(this.cfg);
|
|
813
|
+
}
|
|
814
|
+
get format() {
|
|
815
|
+
return this.cfg.format;
|
|
816
|
+
}
|
|
817
|
+
onKeyDown(event) {
|
|
818
|
+
if (event.key === 'Backspace') {
|
|
819
|
+
this.deleting = true;
|
|
820
|
+
}
|
|
821
|
+
const target = event.target;
|
|
822
|
+
this.caretPosition = target.selectionStart ?? target.value.length - 1;
|
|
823
|
+
}
|
|
824
|
+
onKeyUp(event) {
|
|
825
|
+
if (event.key === 'Backspace') {
|
|
826
|
+
this.deleting = false;
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
onInput(event) {
|
|
830
|
+
const target = event.target;
|
|
831
|
+
const value = target.value;
|
|
832
|
+
const caretPosition = target.selectionStart ?? value.length - 1;
|
|
833
|
+
const res = this.parse(value, caretPosition);
|
|
834
|
+
target.value = res.prettyInput;
|
|
835
|
+
RdtHTMLUtils.setCaretPosition(target, res.caret);
|
|
836
|
+
this._value = res.date;
|
|
837
|
+
this._inputValue = res.prettyInput;
|
|
838
|
+
this.caretPosition = res.caret;
|
|
839
|
+
}
|
|
840
|
+
get value() {
|
|
841
|
+
return this._value;
|
|
842
|
+
}
|
|
843
|
+
set value(d) {
|
|
844
|
+
if (!(d instanceof Date)) {
|
|
845
|
+
this._value = null;
|
|
846
|
+
this._inputValue = '';
|
|
847
|
+
return;
|
|
848
|
+
}
|
|
849
|
+
let result = '';
|
|
850
|
+
this._parsedFormat.forEach((node) => {
|
|
851
|
+
switch (node.type) {
|
|
852
|
+
case RdtFormatType.Constant:
|
|
853
|
+
result += node.value;
|
|
854
|
+
break;
|
|
855
|
+
case RdtFormatType.Day:
|
|
856
|
+
result += `${d.getDate()}`.padStart(node.minLength, '0');
|
|
857
|
+
break;
|
|
858
|
+
case RdtFormatType.Month:
|
|
859
|
+
result += `${d.getMonth() + 1}`.padStart(node.minLength, '0');
|
|
860
|
+
break;
|
|
861
|
+
case RdtFormatType.Year:
|
|
862
|
+
result += `${d.getFullYear() % 10 ** node.maxLength}`.padStart(node.minLength, '0');
|
|
863
|
+
break;
|
|
864
|
+
}
|
|
865
|
+
});
|
|
866
|
+
this._value = d;
|
|
867
|
+
this._inputValue = result;
|
|
868
|
+
}
|
|
869
|
+
set inputValue(value) {
|
|
870
|
+
this._inputValue = value;
|
|
871
|
+
}
|
|
872
|
+
get inputValue() {
|
|
873
|
+
return this._inputValue;
|
|
874
|
+
}
|
|
875
|
+
parse(input, caretPosition = this.caretPosition, deleting = this.deleting) {
|
|
876
|
+
let rest = input;
|
|
877
|
+
let day = null, month = null, year = null;
|
|
878
|
+
let output = '';
|
|
879
|
+
let targetCaret = caretPosition;
|
|
880
|
+
let allComplete = true;
|
|
881
|
+
let ambiguous = false;
|
|
882
|
+
for (let i = 0; i < this._parsedFormat.length; i++) {
|
|
883
|
+
if (rest.length === 0) {
|
|
884
|
+
break;
|
|
885
|
+
}
|
|
886
|
+
const node = this._parsedFormat[i];
|
|
887
|
+
const firstNumber = rest.search(/\d/);
|
|
888
|
+
if (node.type === RdtFormatType.Constant) {
|
|
889
|
+
if (firstNumber > 0) {
|
|
890
|
+
const value = deleting
|
|
891
|
+
? rest.substring(0, node.value.length)
|
|
892
|
+
: rest.substring(0, firstNumber);
|
|
893
|
+
// In case we are deleting from separator, delete previous number as well
|
|
894
|
+
if (deleting && value !== node.value) {
|
|
895
|
+
if (rest.length === input.length) {
|
|
896
|
+
continue;
|
|
897
|
+
}
|
|
898
|
+
else {
|
|
899
|
+
targetCaret -= node.value.length - value.length;
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
rest = rest.substring(firstNumber);
|
|
903
|
+
}
|
|
904
|
+
output += node.value;
|
|
905
|
+
}
|
|
906
|
+
else {
|
|
907
|
+
if (firstNumber < 0) {
|
|
908
|
+
break;
|
|
909
|
+
}
|
|
910
|
+
if (targetCaret > output.length) {
|
|
911
|
+
allComplete = true;
|
|
912
|
+
}
|
|
913
|
+
if (node.type === RdtFormatType.Year) {
|
|
914
|
+
if (this.cfg.yearInputMode & RdtYearInputMode.FourDigit &&
|
|
915
|
+
(rest.match(/^\d{3,4}/) ||
|
|
916
|
+
(rest.match(/^\d{2}$/) && i !== this._parsedFormat.length - 1))) {
|
|
917
|
+
if (!deleting &&
|
|
918
|
+
this.cfg.insertMode === RdtInsertMode.Overwrite &&
|
|
919
|
+
rest.match(/^\d{5}/) &&
|
|
920
|
+
caretPosition < rest.length &&
|
|
921
|
+
caretPosition - output.length <= 5 &&
|
|
922
|
+
RdtStringUtils.isNumericCharacter(rest[caretPosition])) {
|
|
923
|
+
rest =
|
|
924
|
+
rest.substring(0, caretPosition) +
|
|
925
|
+
rest.substring(caretPosition + 1);
|
|
926
|
+
}
|
|
927
|
+
if (rest.match(/^\d{4}/)) {
|
|
928
|
+
const strVal = rest.substring(0, 4);
|
|
929
|
+
year = parseInt(strVal);
|
|
930
|
+
rest = rest.substring(4);
|
|
931
|
+
output += strVal;
|
|
932
|
+
if (!deleting) {
|
|
933
|
+
({ rest, targetCaret } = this.useUpNumbersUntilNextSeparator(rest, targetCaret, true, deleting));
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
else if (rest.match(/^\d{3}/)) {
|
|
937
|
+
output += rest.substring(0, 3);
|
|
938
|
+
rest = rest.substring(3);
|
|
939
|
+
if (output.length <= targetCaret) {
|
|
940
|
+
allComplete = false;
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
else {
|
|
944
|
+
output = rest.substring(0, 2);
|
|
945
|
+
rest = rest.substring(2);
|
|
946
|
+
if (output.length <= targetCaret) {
|
|
947
|
+
allComplete = false;
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
else if (this.cfg.yearInputMode & RdtYearInputMode.TwoDigit &&
|
|
952
|
+
rest.match(/^\d{2}/) &&
|
|
953
|
+
(this.containsNonNumericCharacters(rest.substring(2)) ||
|
|
954
|
+
i === this._parsedFormat.length - 1)) {
|
|
955
|
+
const strVal = rest.substring(0, 2);
|
|
956
|
+
const y2 = parseInt(strVal);
|
|
957
|
+
if (this.cfg.twoDigitYearInputStrategy === 'past') {
|
|
958
|
+
year = RdtDateUtils.doubleDigitYearToPast(y2);
|
|
959
|
+
}
|
|
960
|
+
else {
|
|
961
|
+
year = RdtDateUtils.doubleDigitYearToFuture(y2);
|
|
962
|
+
}
|
|
963
|
+
rest = rest.substring(2);
|
|
964
|
+
if (!deleting) {
|
|
965
|
+
({ rest, targetCaret } = this.useUpNumbersUntilNextSeparator(rest, targetCaret, true, deleting));
|
|
966
|
+
}
|
|
967
|
+
output += strVal;
|
|
968
|
+
if (this.cfg.yearInputMode & RdtYearInputMode.FourDigit &&
|
|
969
|
+
i === this._parsedFormat.length - 1) {
|
|
970
|
+
ambiguous = true;
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
else if (rest.match(/^\d/)) {
|
|
974
|
+
output += rest[0];
|
|
975
|
+
rest = rest.substring(1);
|
|
976
|
+
if (output.length <= targetCaret) {
|
|
977
|
+
allComplete = false;
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
else if (node.type === RdtFormatType.Month) {
|
|
982
|
+
const val = this.readNumber(1, 12, output, rest, targetCaret, deleting);
|
|
983
|
+
output = val.output;
|
|
984
|
+
rest = val.rest;
|
|
985
|
+
targetCaret = val.targetCaret;
|
|
986
|
+
if (val.value !== null) {
|
|
987
|
+
month = val.value;
|
|
988
|
+
// Add separator in case it's complete
|
|
989
|
+
if (val.complete && !deleting) {
|
|
990
|
+
({ rest, targetCaret } = this.useUpNumbersUntilNextSeparator(rest, targetCaret, true, deleting));
|
|
991
|
+
}
|
|
992
|
+
if (!val.complete && output.length <= targetCaret) {
|
|
993
|
+
allComplete = false;
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
else if (node.type === RdtFormatType.Day) {
|
|
998
|
+
const val = this.readNumber(1, 31, output, rest, targetCaret, deleting);
|
|
999
|
+
output = val.output;
|
|
1000
|
+
rest = val.rest;
|
|
1001
|
+
targetCaret = val.targetCaret;
|
|
1002
|
+
if (val.value !== null) {
|
|
1003
|
+
day = val.value;
|
|
1004
|
+
// Add separator in case it's complete
|
|
1005
|
+
if (val.complete && !deleting) {
|
|
1006
|
+
({ rest, targetCaret } = this.useUpNumbersUntilNextSeparator(rest, targetCaret, true, deleting));
|
|
1007
|
+
}
|
|
1008
|
+
if (!val.complete && output.length <= targetCaret) {
|
|
1009
|
+
allComplete = false;
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
let date = null;
|
|
1016
|
+
if (year !== null && month !== null && day !== null) {
|
|
1017
|
+
date = new Date(year, month - 1, day);
|
|
1018
|
+
if (date.getMonth() !== month - 1) {
|
|
1019
|
+
date = null;
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
targetCaret = Math.min(targetCaret, output.length + 1);
|
|
1023
|
+
if (!deleting) {
|
|
1024
|
+
if (caretPosition === input.length) {
|
|
1025
|
+
targetCaret = output.length;
|
|
1026
|
+
}
|
|
1027
|
+
else if (allComplete) {
|
|
1028
|
+
while (targetCaret > 0 &&
|
|
1029
|
+
output.length > targetCaret &&
|
|
1030
|
+
!RdtStringUtils.isNumericCharacter(output[targetCaret])) {
|
|
1031
|
+
targetCaret++;
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
else if (!date) {
|
|
1036
|
+
output = input;
|
|
1037
|
+
targetCaret = caretPosition;
|
|
1038
|
+
}
|
|
1039
|
+
return {
|
|
1040
|
+
prettyInput: output,
|
|
1041
|
+
date: date,
|
|
1042
|
+
complete: date !== null,
|
|
1043
|
+
caret: targetCaret,
|
|
1044
|
+
ambiguous: ambiguous || date === null,
|
|
1045
|
+
};
|
|
1046
|
+
}
|
|
1047
|
+
readNumber(min, max, output, rest, targetCaret, deleting) {
|
|
1048
|
+
const maxDigits = getDigitCount(max);
|
|
1049
|
+
let value = null;
|
|
1050
|
+
let strVal = '';
|
|
1051
|
+
let complete = false;
|
|
1052
|
+
if (!(this.cfg.leadingZeroMode & RdtLeadingZeroInputMode.NoLeadingZero)) {
|
|
1053
|
+
const regex = new RegExp(`^\\d{${maxDigits}}`);
|
|
1054
|
+
if (rest.match(regex)) {
|
|
1055
|
+
strVal = rest.substring(0, maxDigits);
|
|
1056
|
+
output += strVal;
|
|
1057
|
+
rest = rest.substring(maxDigits);
|
|
1058
|
+
value = parseInt(strVal);
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
else {
|
|
1062
|
+
let digits = rest.match(/^\d+/)?.[0] ?? '';
|
|
1063
|
+
if (digits.length > 0) {
|
|
1064
|
+
digits = digits.slice(0, maxDigits);
|
|
1065
|
+
value = parseInt(digits);
|
|
1066
|
+
if (value < min) {
|
|
1067
|
+
value = null;
|
|
1068
|
+
let nines = '9';
|
|
1069
|
+
while (digits.length + 1 > maxDigits ||
|
|
1070
|
+
parseInt(digits + nines) < min) {
|
|
1071
|
+
digits = digits.slice(0, -1);
|
|
1072
|
+
nines += '9';
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
else {
|
|
1076
|
+
while (value > max && digits.length > 0) {
|
|
1077
|
+
digits = digits.slice(0, -1);
|
|
1078
|
+
value = parseInt(digits);
|
|
1079
|
+
}
|
|
1080
|
+
if (digits.length === 0) {
|
|
1081
|
+
value = null;
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
if (digits[0] === '0' &&
|
|
1085
|
+
min !== 0 &&
|
|
1086
|
+
!(this.cfg.leadingZeroMode & RdtLeadingZeroInputMode.LeadingZero)) {
|
|
1087
|
+
value = null;
|
|
1088
|
+
digits = '';
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
output += digits;
|
|
1092
|
+
rest = rest.substring(digits.length);
|
|
1093
|
+
strVal = digits;
|
|
1094
|
+
}
|
|
1095
|
+
if (value !== null && value >= min && value <= max) {
|
|
1096
|
+
complete = strVal.length === maxDigits || value * 10 > max;
|
|
1097
|
+
({ rest, targetCaret } = this.useUpNumbersUntilNextSeparator(rest, targetCaret, complete && !deleting, deleting));
|
|
1098
|
+
return { value, complete, output, rest, targetCaret };
|
|
1099
|
+
}
|
|
1100
|
+
else {
|
|
1101
|
+
return { value: null, complete: false, output, rest, targetCaret };
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
parseFormat(cfg) {
|
|
1105
|
+
const keys = Object.keys(cfg.symbolMeta);
|
|
1106
|
+
keys.sort((a, b) => b.length - a.length);
|
|
1107
|
+
let rest = cfg.format;
|
|
1108
|
+
const result = [];
|
|
1109
|
+
while (rest.length > 0) {
|
|
1110
|
+
const indices = keys.map((key) => rest.indexOf(key));
|
|
1111
|
+
const minI = indices.indexOf(Math.min(...indices.filter((i) => i >= 0)));
|
|
1112
|
+
const minIndex = indices[minI];
|
|
1113
|
+
const minKey = keys[minI];
|
|
1114
|
+
if (minIndex > 0) {
|
|
1115
|
+
result.push({
|
|
1116
|
+
type: RdtFormatType.Constant,
|
|
1117
|
+
value: rest.substring(0, minIndex),
|
|
1118
|
+
});
|
|
1119
|
+
rest = rest.substring(minIndex);
|
|
1120
|
+
}
|
|
1121
|
+
else if (minIndex < 0) {
|
|
1122
|
+
result.push({
|
|
1123
|
+
type: RdtFormatType.Constant,
|
|
1124
|
+
value: rest,
|
|
1125
|
+
});
|
|
1126
|
+
rest = '';
|
|
1127
|
+
}
|
|
1128
|
+
else {
|
|
1129
|
+
result.push(cfg.symbolMeta[minKey]);
|
|
1130
|
+
rest = rest.substring(minIndex + minKey.length);
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
return result;
|
|
1134
|
+
}
|
|
1135
|
+
useUpNumbersUntilNextSeparator(input, targetCaret, insertSeparator, deleting) {
|
|
1136
|
+
let i = 0;
|
|
1137
|
+
while (i < input.length && RdtStringUtils.isNumericCharacter(input[i])) {
|
|
1138
|
+
i++;
|
|
1139
|
+
}
|
|
1140
|
+
if (i !== input.length) {
|
|
1141
|
+
return {
|
|
1142
|
+
rest: input.substring(i),
|
|
1143
|
+
targetCaret: targetCaret - (deleting ? i : 0),
|
|
1144
|
+
};
|
|
1145
|
+
}
|
|
1146
|
+
else if (insertSeparator) {
|
|
1147
|
+
return { rest: ' ' + input, targetCaret: targetCaret };
|
|
1148
|
+
}
|
|
1149
|
+
else {
|
|
1150
|
+
return { rest: input, targetCaret };
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
containsNonNumericCharacters(input) {
|
|
1154
|
+
return input.search(/\D/) >= 0;
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
class RdtDomUtils {
|
|
1159
|
+
static getResizeEvent$(element) {
|
|
1160
|
+
return new Observable((observer) => {
|
|
1161
|
+
const resizeObserver = new ResizeObserver((entries) => {
|
|
1162
|
+
observer.next(entries);
|
|
1163
|
+
});
|
|
1164
|
+
resizeObserver.observe(element);
|
|
1165
|
+
return () => {
|
|
1166
|
+
resizeObserver.unobserve(element);
|
|
1167
|
+
resizeObserver.disconnect();
|
|
1168
|
+
};
|
|
1169
|
+
});
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
var RdtMsOfficeAction;
|
|
1174
|
+
(function (RdtMsOfficeAction) {
|
|
1175
|
+
RdtMsOfficeAction["Edit"] = "ofe|u|";
|
|
1176
|
+
RdtMsOfficeAction["View"] = "ofv|u|";
|
|
1177
|
+
})(RdtMsOfficeAction || (RdtMsOfficeAction = {}));
|
|
1178
|
+
var RdtMsOfficeApp;
|
|
1179
|
+
(function (RdtMsOfficeApp) {
|
|
1180
|
+
RdtMsOfficeApp["Word"] = "ms-word";
|
|
1181
|
+
RdtMsOfficeApp["Excel"] = "ms-excel";
|
|
1182
|
+
RdtMsOfficeApp["PowerPoint"] = "ms-powerpoint";
|
|
1183
|
+
})(RdtMsOfficeApp || (RdtMsOfficeApp = {}));
|
|
1184
|
+
const RDT_DEFAULT_MIME_TYPE = RdtMimeType.UNKNOWN;
|
|
1185
|
+
const RDT_DEFAULT_MS_OFFICE_ACTION = RdtMsOfficeAction.View;
|
|
1186
|
+
var RdtFileSizeUnit;
|
|
1187
|
+
(function (RdtFileSizeUnit) {
|
|
1188
|
+
RdtFileSizeUnit["B"] = "B";
|
|
1189
|
+
RdtFileSizeUnit["KB"] = "KB";
|
|
1190
|
+
RdtFileSizeUnit["MB"] = "MB";
|
|
1191
|
+
RdtFileSizeUnit["GB"] = "GB";
|
|
1192
|
+
RdtFileSizeUnit["TB"] = "TB";
|
|
1193
|
+
RdtFileSizeUnit["PB"] = "PB";
|
|
1194
|
+
RdtFileSizeUnit["EB"] = "EB";
|
|
1195
|
+
RdtFileSizeUnit["ZB"] = "ZB";
|
|
1196
|
+
RdtFileSizeUnit["YB"] = "YB";
|
|
1197
|
+
})(RdtFileSizeUnit || (RdtFileSizeUnit = {}));
|
|
1198
|
+
const SORTED_FILE_SIZE_UNITS = [
|
|
1199
|
+
RdtFileSizeUnit.B,
|
|
1200
|
+
RdtFileSizeUnit.KB,
|
|
1201
|
+
RdtFileSizeUnit.MB,
|
|
1202
|
+
RdtFileSizeUnit.GB,
|
|
1203
|
+
RdtFileSizeUnit.TB,
|
|
1204
|
+
RdtFileSizeUnit.PB,
|
|
1205
|
+
RdtFileSizeUnit.EB,
|
|
1206
|
+
RdtFileSizeUnit.ZB,
|
|
1207
|
+
RdtFileSizeUnit.YB,
|
|
1208
|
+
];
|
|
1209
|
+
class RdtFileUtils {
|
|
1210
|
+
static getMsOfficeLink(url, config) {
|
|
1211
|
+
const app = config.app ?? RdtFileUtils.getMsOfficeAppByMimeType(config.mimeType);
|
|
1212
|
+
if (app) {
|
|
1213
|
+
const action = config.action ?? RDT_DEFAULT_MS_OFFICE_ACTION;
|
|
1214
|
+
return `${app}:${action}${url}`;
|
|
1215
|
+
}
|
|
1216
|
+
else {
|
|
1217
|
+
return url;
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
static openFileFromRemoteUrl(url, config) {
|
|
1221
|
+
window.open(RdtFileUtils.getMsOfficeLink(url, config));
|
|
1222
|
+
}
|
|
1223
|
+
static openFileInBrowser(stringData, mimeType) {
|
|
1224
|
+
const link = RdtFileUtils.getBase64Link(stringData, mimeType);
|
|
1225
|
+
window.open(link, '_blank');
|
|
1226
|
+
}
|
|
1227
|
+
static fileAsArrayBuffer(file) {
|
|
1228
|
+
return new Promise((resolve, reject) => {
|
|
1229
|
+
if (!file) {
|
|
1230
|
+
reject(null);
|
|
1231
|
+
}
|
|
1232
|
+
const reader = new FileReader();
|
|
1233
|
+
reader.onload = () => resolve(reader.result);
|
|
1234
|
+
reader.onerror = reject;
|
|
1235
|
+
reader.readAsArrayBuffer(file);
|
|
1236
|
+
});
|
|
1237
|
+
}
|
|
1238
|
+
static fileAsText(file, encoding) {
|
|
1239
|
+
return new Promise((resolve, reject) => {
|
|
1240
|
+
if (!file) {
|
|
1241
|
+
reject(null);
|
|
1242
|
+
}
|
|
1243
|
+
const reader = new FileReader();
|
|
1244
|
+
reader.onload = () => resolve(reader.result);
|
|
1245
|
+
reader.onerror = reject;
|
|
1246
|
+
reader.readAsText(file, encoding);
|
|
1247
|
+
});
|
|
1248
|
+
}
|
|
1249
|
+
static downloadFileFromData(stringData, filename, mimeType) {
|
|
1250
|
+
mimeType =
|
|
1251
|
+
mimeType ??
|
|
1252
|
+
RdtFileUtils.getMimeTypeFromFileName(filename) ??
|
|
1253
|
+
RdtFileUtils.getMimeTypeFromBase64(stringData);
|
|
1254
|
+
const url = RdtFileUtils.getBase64Link(stringData, mimeType);
|
|
1255
|
+
this.downloadFileFromRemoteUrl(url, filename, mimeType);
|
|
1256
|
+
}
|
|
1257
|
+
static downloadFileFromRemoteUrl(url, filename, mimeType) {
|
|
1258
|
+
mimeType = mimeType ?? RdtFileUtils.getMimeTypeFromFileName(filename);
|
|
1259
|
+
const link = document.createElement('a');
|
|
1260
|
+
link.href = url;
|
|
1261
|
+
link.download = RdtFileUtils.getFileName(filename, mimeType);
|
|
1262
|
+
link.click();
|
|
1263
|
+
}
|
|
1264
|
+
static getMimeTypeFromBase64(base64Data) {
|
|
1265
|
+
return base64Data.match(/data:(.*?);base64/)?.[1];
|
|
1266
|
+
}
|
|
1267
|
+
static getMimeTypeFromFileName(fileName) {
|
|
1268
|
+
const ext = fileName?.split('.').pop();
|
|
1269
|
+
// @ts-ignore
|
|
1270
|
+
return MIME_TYPE_BY_EXTENSION[ext];
|
|
1271
|
+
}
|
|
1272
|
+
static getFileName(filename, mimeType) {
|
|
1273
|
+
if (mimeType && mimeType !== RdtMimeType.UNKNOWN) {
|
|
1274
|
+
const ext = EXTENSION_BY_MIME_TYPE[mimeType];
|
|
1275
|
+
if (filename.endsWith(`.${ext}`)) {
|
|
1276
|
+
return filename;
|
|
1277
|
+
}
|
|
1278
|
+
else {
|
|
1279
|
+
return `${filename}.${ext}`;
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
else {
|
|
1283
|
+
return filename;
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
static getBase64Link(base64Data, mimeType) {
|
|
1287
|
+
if (base64Data.startsWith('data:')) {
|
|
1288
|
+
return base64Data;
|
|
1289
|
+
}
|
|
1290
|
+
else if (mimeType) {
|
|
1291
|
+
if (mimeType === RdtMimeType.UNKNOWN) {
|
|
1292
|
+
return `data:${RdtMimeType.BIN};base64,${base64Data}`;
|
|
1293
|
+
}
|
|
1294
|
+
else {
|
|
1295
|
+
return `data:${mimeType};base64,${base64Data}`;
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
else {
|
|
1299
|
+
console.error('Missing mime type for base64 data.');
|
|
1300
|
+
return '';
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
static getMimeTypeFromResponse(resp) {
|
|
1304
|
+
return resp.body?.type;
|
|
1305
|
+
}
|
|
1306
|
+
static getFileNameFromResponse(resp) {
|
|
1307
|
+
return (resp.headers
|
|
1308
|
+
.get('content-disposition')
|
|
1309
|
+
?.split('filename=')?.[1]
|
|
1310
|
+
?.split(';')?.[0] ?? '');
|
|
1311
|
+
}
|
|
1312
|
+
static async blobToDataUrl(file) {
|
|
1313
|
+
return new Promise((resolve, reject) => {
|
|
1314
|
+
if (!file) {
|
|
1315
|
+
reject(null);
|
|
1316
|
+
}
|
|
1317
|
+
const reader = new FileReader();
|
|
1318
|
+
reader.onload = () => resolve(reader.result);
|
|
1319
|
+
reader.onerror = reject;
|
|
1320
|
+
reader.readAsDataURL(file);
|
|
1321
|
+
});
|
|
1322
|
+
}
|
|
1323
|
+
static convertFromBytes(bytes, decimals = 2) {
|
|
1324
|
+
if (bytes === 0) {
|
|
1325
|
+
return '0 ' + RdtFileSizeUnit.B;
|
|
1326
|
+
}
|
|
1327
|
+
const k = 1024;
|
|
1328
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
1329
|
+
return (parseFloat((bytes / Math.pow(k, i)).toFixed(decimals)) +
|
|
1330
|
+
' ' +
|
|
1331
|
+
SORTED_FILE_SIZE_UNITS[i]);
|
|
1332
|
+
}
|
|
1333
|
+
static convertToBytes(amount, unit) {
|
|
1334
|
+
const k = 1024;
|
|
1335
|
+
const i = SORTED_FILE_SIZE_UNITS.indexOf(unit);
|
|
1336
|
+
return amount * Math.pow(k, i);
|
|
1337
|
+
}
|
|
1338
|
+
static fileSizeToBytes(fileSize) {
|
|
1339
|
+
const [amountStr, unitStr] = fileSize.split(' ');
|
|
1340
|
+
const amount = parseFloat(amountStr);
|
|
1341
|
+
const unit = unitStr;
|
|
1342
|
+
if (isNaN(amount) || SORTED_FILE_SIZE_UNITS.indexOf(unit) === -1) {
|
|
1343
|
+
return null;
|
|
1344
|
+
}
|
|
1345
|
+
return RdtFileUtils.convertToBytes(amount, unit);
|
|
1346
|
+
}
|
|
1347
|
+
static getMsOfficeAppByMimeType(mimeType) {
|
|
1348
|
+
switch (mimeType) {
|
|
1349
|
+
case RdtMimeType.DOC:
|
|
1350
|
+
case RdtMimeType.DOCX:
|
|
1351
|
+
case RdtMimeType.ODT:
|
|
1352
|
+
return RdtMsOfficeApp.Word;
|
|
1353
|
+
case RdtMimeType.XLS:
|
|
1354
|
+
case RdtMimeType.XLSX:
|
|
1355
|
+
case RdtMimeType.ODS:
|
|
1356
|
+
return RdtMsOfficeApp.Excel;
|
|
1357
|
+
case RdtMimeType.PPT:
|
|
1358
|
+
case RdtMimeType.PPTX:
|
|
1359
|
+
case RdtMimeType.ODP:
|
|
1360
|
+
return RdtMsOfficeApp.PowerPoint;
|
|
1361
|
+
default:
|
|
1362
|
+
return null;
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1367
|
+
/**
|
|
1368
|
+
* From @nx/devkit because it has nodejs as dependency and won't transpile.
|
|
1369
|
+
* Util function to generate different strings based off the provided name.
|
|
1370
|
+
*
|
|
1371
|
+
* Examples:
|
|
1372
|
+
*
|
|
1373
|
+
* ```typescript
|
|
1374
|
+
* names("my-name") // {name: 'my-name', className: 'MyName', propertyName: 'myName', constantName: 'MY_NAME', fileName: 'my-name'}
|
|
1375
|
+
* names("myName") // {name: 'myName', className: 'MyName', propertyName: 'myName', constantName: 'MY_NAME', fileName: 'my-name'}
|
|
1376
|
+
* ```
|
|
1377
|
+
* @param name
|
|
1378
|
+
*/
|
|
1379
|
+
function names(name) {
|
|
1380
|
+
return {
|
|
1381
|
+
name,
|
|
1382
|
+
className: toClassName(name),
|
|
1383
|
+
propertyName: toPropertyName(name),
|
|
1384
|
+
constantName: toConstantName(name),
|
|
1385
|
+
fileName: toFileName(name),
|
|
1386
|
+
};
|
|
1387
|
+
}
|
|
1388
|
+
/**
|
|
1389
|
+
* Hyphenated to UpperCamelCase
|
|
1390
|
+
*/
|
|
1391
|
+
function toClassName(str) {
|
|
1392
|
+
return toCapitalCase(toPropertyName(str));
|
|
1393
|
+
}
|
|
1394
|
+
/**
|
|
1395
|
+
* Hyphenated to lowerCamelCase
|
|
1396
|
+
*/
|
|
1397
|
+
function toPropertyName(s) {
|
|
1398
|
+
return s
|
|
1399
|
+
.replace(/([^a-zA-Z0-9])+(.)?/g, (_, __, chr) => chr ? chr.toUpperCase() : '')
|
|
1400
|
+
.replace(/[^a-zA-Z\d]/g, '')
|
|
1401
|
+
.replace(/^([A-Z])/, m => m.toLowerCase());
|
|
1402
|
+
}
|
|
1403
|
+
/**
|
|
1404
|
+
* Hyphenated to CONSTANT_CASE
|
|
1405
|
+
*/
|
|
1406
|
+
function toConstantName(s) {
|
|
1407
|
+
const normalizedS = s.toUpperCase() === s ? s.toLowerCase() : s;
|
|
1408
|
+
return toFileName(toPropertyName(normalizedS))
|
|
1409
|
+
.replace(/([^a-zA-Z0-9])/g, '_')
|
|
1410
|
+
.toUpperCase();
|
|
1411
|
+
}
|
|
1412
|
+
/**
|
|
1413
|
+
* Upper camelCase to lowercase, hyphenated
|
|
1414
|
+
*/
|
|
1415
|
+
function toFileName(s) {
|
|
1416
|
+
return s
|
|
1417
|
+
.replace(/([a-z\d])([A-Z])/g, '$1_$2')
|
|
1418
|
+
.toLowerCase()
|
|
1419
|
+
.replace(/(?!^_)[ _]/g, '-');
|
|
1420
|
+
}
|
|
1421
|
+
/**
|
|
1422
|
+
* Capitalizes the first letter of a string
|
|
1423
|
+
*/
|
|
1424
|
+
function toCapitalCase(s) {
|
|
1425
|
+
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
const BOOLEAN_KEYWORDS = ['je', 'lze'];
|
|
1429
|
+
const ID_KEYWORD = 'id';
|
|
1430
|
+
class RdtModelUtils {
|
|
1431
|
+
static inferPropertyInfo(properties, interfaceName) {
|
|
1432
|
+
// Lowercase words that interface name consists of
|
|
1433
|
+
const words = names(interfaceName).fileName.split('-');
|
|
1434
|
+
const wordMap = {};
|
|
1435
|
+
words.forEach((w) => (wordMap[w] = 1));
|
|
1436
|
+
let maxMatches = 0;
|
|
1437
|
+
// Primary key is property that shares the most words with interface name
|
|
1438
|
+
// while containing the word 'id'.
|
|
1439
|
+
// If more such properties exist, the one with shortest name is selected.
|
|
1440
|
+
let primaryKey = '';
|
|
1441
|
+
properties.forEach(({ key }) => {
|
|
1442
|
+
const propertyNameWords = names(key).fileName.split('-');
|
|
1443
|
+
let matches = 0;
|
|
1444
|
+
propertyNameWords.forEach((w) => (matches += wordMap[w] ?? 0));
|
|
1445
|
+
const isId = propertyNameWords.includes(ID_KEYWORD);
|
|
1446
|
+
if (matches > maxMatches && isId) {
|
|
1447
|
+
maxMatches = matches;
|
|
1448
|
+
primaryKey = key;
|
|
1449
|
+
}
|
|
1450
|
+
else if (matches === maxMatches && isId) {
|
|
1451
|
+
if (key.length < primaryKey.length) {
|
|
1452
|
+
primaryKey = key;
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
});
|
|
1456
|
+
const res = properties.map((pair) => {
|
|
1457
|
+
const propertyNameWords = names(pair.key).fileName.split('-');
|
|
1458
|
+
const isId = propertyNameWords.includes(ID_KEYWORD);
|
|
1459
|
+
return {
|
|
1460
|
+
key: pair.key,
|
|
1461
|
+
type: pair.type,
|
|
1462
|
+
required: true,
|
|
1463
|
+
formControlType: pair.type === 'date' ? 'string' : pair.type,
|
|
1464
|
+
primaryKey: pair.key === primaryKey,
|
|
1465
|
+
// Any other property that contains ID, but is not primary key is foreign key.
|
|
1466
|
+
// Foreign keys are to be ignored.
|
|
1467
|
+
foreignKey: isId && pair.key !== primaryKey,
|
|
1468
|
+
// If the property starts with the word 'je' and it's numeric,
|
|
1469
|
+
// then it's probably boolean.
|
|
1470
|
+
probablyBoolean: BOOLEAN_KEYWORDS.includes(propertyNameWords[0]) &&
|
|
1471
|
+
pair.type === 'number',
|
|
1472
|
+
};
|
|
1473
|
+
});
|
|
1474
|
+
return res;
|
|
1475
|
+
}
|
|
1476
|
+
static names(name) {
|
|
1477
|
+
return names(name);
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
|
|
1481
|
+
class RdtObjectUtils {
|
|
1482
|
+
static pluck(obj, path) {
|
|
1483
|
+
if (!obj) {
|
|
1484
|
+
return undefined;
|
|
1485
|
+
}
|
|
1486
|
+
const parts = Array.isArray(path) ? path : path.split('.');
|
|
1487
|
+
let current = obj;
|
|
1488
|
+
for (const key of parts) {
|
|
1489
|
+
if (current == undefined) {
|
|
1490
|
+
return undefined;
|
|
1491
|
+
}
|
|
1492
|
+
if (Array.isArray(current) && typeof key === 'string') {
|
|
1493
|
+
current = current[parseInt(key)];
|
|
1494
|
+
}
|
|
1495
|
+
else {
|
|
1496
|
+
current = current[key];
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
return current;
|
|
1500
|
+
}
|
|
1501
|
+
static notNullGuard(value) {
|
|
1502
|
+
return value != null;
|
|
1503
|
+
}
|
|
1504
|
+
static expandKey(key, value) {
|
|
1505
|
+
const parts = key.split('.');
|
|
1506
|
+
if (parts.length === 0) {
|
|
1507
|
+
return value;
|
|
1508
|
+
}
|
|
1509
|
+
const first = getObjectFromKey(parts[0]);
|
|
1510
|
+
let current = first;
|
|
1511
|
+
for (let i = 1; i < parts.length; i++) {
|
|
1512
|
+
const next = getObjectFromKey(parts[i]);
|
|
1513
|
+
current.obj[current.key] = next.obj;
|
|
1514
|
+
current = next;
|
|
1515
|
+
}
|
|
1516
|
+
current.obj[current.key] = value;
|
|
1517
|
+
return first.obj;
|
|
1518
|
+
}
|
|
1519
|
+
static someValuesTrue(obj) {
|
|
1520
|
+
const keys = Object.getOwnPropertySymbols(obj);
|
|
1521
|
+
return keys.some((key) => obj[key]);
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
function getObjectFromKey(key) {
|
|
1525
|
+
const int = parseInt(key);
|
|
1526
|
+
if (isNaN(int)) {
|
|
1527
|
+
return {
|
|
1528
|
+
obj: {},
|
|
1529
|
+
key: key,
|
|
1530
|
+
};
|
|
1531
|
+
}
|
|
1532
|
+
else {
|
|
1533
|
+
return {
|
|
1534
|
+
obj: [],
|
|
1535
|
+
key: int,
|
|
1536
|
+
};
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
|
|
1540
|
+
class RdtRandomUtils {
|
|
1541
|
+
static randomId() {
|
|
1542
|
+
return Math.random().toString(36).substring(2);
|
|
1543
|
+
}
|
|
1544
|
+
static trueFalse() {
|
|
1545
|
+
return Math.random() < 0.5;
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
|
|
1549
|
+
class RdtRxUtils {
|
|
1550
|
+
// Will repeat last value when notifier$ emits anything.
|
|
1551
|
+
static repeatLatestWhen(notifier$) {
|
|
1552
|
+
return (source) => {
|
|
1553
|
+
return combineLatest([source, notifier$.pipe(startWith(null))]).pipe(map(([val]) => val));
|
|
1554
|
+
};
|
|
1555
|
+
}
|
|
1556
|
+
static completeIfNull(source$) {
|
|
1557
|
+
return source$.pipe(switchMap((value) => (value == null ? EMPTY : of(value))));
|
|
1558
|
+
}
|
|
1559
|
+
static makeObservable(value) {
|
|
1560
|
+
return value instanceof Observable ? value : of(value);
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1563
|
+
|
|
1564
|
+
function signalToPromise(source, options) {
|
|
1565
|
+
if (ngDevMode && !options?.injector) {
|
|
1566
|
+
assertInInjectionContext(signalToPromise);
|
|
1567
|
+
}
|
|
1568
|
+
const injector = options?.injector ?? inject(Injector);
|
|
1569
|
+
return new Promise((resolve, reject) => {
|
|
1570
|
+
const watcher = effect(() => {
|
|
1571
|
+
let value;
|
|
1572
|
+
try {
|
|
1573
|
+
value = source();
|
|
1574
|
+
}
|
|
1575
|
+
catch (err) {
|
|
1576
|
+
untracked(() => reject(err));
|
|
1577
|
+
return;
|
|
1578
|
+
}
|
|
1579
|
+
untracked(() => resolve(value));
|
|
1580
|
+
}, { injector, manualCleanup: true });
|
|
1581
|
+
injector.get(DestroyRef).onDestroy(() => {
|
|
1582
|
+
watcher.destroy();
|
|
1583
|
+
});
|
|
1584
|
+
});
|
|
1585
|
+
}
|
|
1586
|
+
function signalToPromiseOnce(source, options) {
|
|
1587
|
+
const injector = options?.injector ?? inject(Injector);
|
|
1588
|
+
return new Promise((resolve, reject) => {
|
|
1589
|
+
let watcher = null;
|
|
1590
|
+
watcher = effect(() => {
|
|
1591
|
+
let value;
|
|
1592
|
+
try {
|
|
1593
|
+
value = source();
|
|
1594
|
+
}
|
|
1595
|
+
catch (err) {
|
|
1596
|
+
untracked(() => reject(err));
|
|
1597
|
+
watcher?.destroy();
|
|
1598
|
+
watcher = null;
|
|
1599
|
+
return;
|
|
1600
|
+
}
|
|
1601
|
+
untracked(() => {
|
|
1602
|
+
resolve(value);
|
|
1603
|
+
watcher?.destroy();
|
|
1604
|
+
watcher = null;
|
|
1605
|
+
});
|
|
1606
|
+
}, { injector, manualCleanup: true });
|
|
1607
|
+
const destroyRef = injector.get(DestroyRef, null);
|
|
1608
|
+
destroyRef?.onDestroy(() => {
|
|
1609
|
+
watcher?.destroy();
|
|
1610
|
+
watcher = null;
|
|
1611
|
+
});
|
|
1612
|
+
});
|
|
1613
|
+
}
|
|
1614
|
+
|
|
2
1615
|
/**
|
|
3
1616
|
* Generated bundle index. Do not edit.
|
|
4
1617
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
tslib_1.__exportStar(require("./index"), exports);
|
|
1618
|
+
|
|
1619
|
+
export { ALPHABET_KB_KEYS, ARROW, EXTENSION_BY_MIME_TYPE, KB_ALPHABET_CODES, KB_CODE, KB_KEY, MIME_TYPE_BY_EXTENSION, Month, PRIMENG_DATE_FORMAT_META, RDT_DEFAULT_MIME_TYPE, RDT_DEFAULT_MS_OFFICE_ACTION, RdtArrayUtils, RdtCombinedMimeType, RdtCssUtils, RdtDateParser, RdtDateUtils, RdtDomUtils, RdtEncoding, RdtFileSizeUnit, RdtFileUtils, RdtHTMLUtils, RdtInsertMode, RdtLeadingZeroInputMode, RdtMimeType, RdtModelUtils, RdtMsOfficeAction, RdtMsOfficeApp, RdtObjectUtils, RdtPasteMode, RdtRandomUtils, RdtRxUtils, RdtStringUtils, RdtYearInputMode, signalToPromise, signalToPromiseOnce };
|
|
8
1620
|
//# sourceMappingURL=ngrdt-utils.mjs.map
|