@libs-ui/utils 0.2.5
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/README.md +3 -0
- package/cache.d.ts +41 -0
- package/color.d.ts +11 -0
- package/communicate-micro.d.ts +17 -0
- package/constants.d.ts +7 -0
- package/crypto-3rd.d.ts +3 -0
- package/crypto.d.ts +4 -0
- package/delete-unicode.d.ts +1 -0
- package/dom.d.ts +18 -0
- package/escape-html.d.ts +1 -0
- package/esm2022/cache.mjs +396 -0
- package/esm2022/color.mjs +81 -0
- package/esm2022/communicate-micro.mjs +143 -0
- package/esm2022/constants.mjs +8 -0
- package/esm2022/crypto-3rd.mjs +34 -0
- package/esm2022/crypto.mjs +37 -0
- package/esm2022/delete-unicode.mjs +20 -0
- package/esm2022/dom.mjs +85 -0
- package/esm2022/escape-html.mjs +12 -0
- package/esm2022/format-number.mjs +63 -0
- package/esm2022/function-check-embed-frame.mjs +10 -0
- package/esm2022/get-color-by-id.mjs +17 -0
- package/esm2022/helpers.mjs +128 -0
- package/esm2022/http-params.mjs +68 -0
- package/esm2022/index.mjs +22 -0
- package/esm2022/key-cache.mjs +19 -0
- package/esm2022/key-code.mjs +122 -0
- package/esm2022/language.mjs +7 -0
- package/esm2022/libs-ui-utils.mjs +5 -0
- package/esm2022/pattern.mjs +62 -0
- package/esm2022/remove-emoji.mjs +10 -0
- package/esm2022/url-search-params.mjs +97 -0
- package/esm2022/uuid.mjs +17 -0
- package/fesm2022/libs-ui-utils.mjs +1426 -0
- package/fesm2022/libs-ui-utils.mjs.map +1 -0
- package/format-number.d.ts +2 -0
- package/function-check-embed-frame.d.ts +2 -0
- package/get-color-by-id.d.ts +1 -0
- package/helpers.d.ts +6 -0
- package/http-params.d.ts +37 -0
- package/index.d.ts +21 -0
- package/key-cache.d.ts +1 -0
- package/key-code.d.ts +121 -0
- package/language.d.ts +5 -0
- package/package.json +26 -0
- package/pattern.d.ts +20 -0
- package/remove-emoji.d.ts +2 -0
- package/url-search-params.d.ts +25 -0
- package/uuid.d.ts +1 -0
|
@@ -0,0 +1,1426 @@
|
|
|
1
|
+
import { TemplateRef, ElementRef, signal } from '@angular/core';
|
|
2
|
+
import CryptoES from 'crypto-es';
|
|
3
|
+
import { HttpParams } from '@angular/common/http';
|
|
4
|
+
import { Subject, fromEvent, filter } from 'rxjs';
|
|
5
|
+
|
|
6
|
+
const getPlatFromBrowser = () => {
|
|
7
|
+
const userAgent = navigator.userAgent;
|
|
8
|
+
let tem;
|
|
9
|
+
let match = userAgent.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
|
|
10
|
+
if (/trident/i.test(match[1])) {
|
|
11
|
+
tem = /\brv[ :]+(\d+)/g.exec(userAgent) || [];
|
|
12
|
+
return 'IE ' + (tem[1] || '');
|
|
13
|
+
}
|
|
14
|
+
if (match[1] === 'Chrome') {
|
|
15
|
+
tem = userAgent.match(/\b(OPR|Edge)\/(\d+)/);
|
|
16
|
+
if (tem !== null) {
|
|
17
|
+
return tem.slice(1).join(' ').replace('OPR', 'Opera');
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
match = match[2] ? [match[1], match[2]] : [navigator.appName, navigator.appVersion, '-?'];
|
|
21
|
+
if ((tem = userAgent.match(/version\/(\d+)/i)) !== null) {
|
|
22
|
+
match.splice(1, 1, tem[1]);
|
|
23
|
+
}
|
|
24
|
+
return match.join(' ');
|
|
25
|
+
};
|
|
26
|
+
const cloneIBoundingClientRect = (rect) => {
|
|
27
|
+
return {
|
|
28
|
+
top: rect['top'],
|
|
29
|
+
left: rect['left'],
|
|
30
|
+
width: rect['width'],
|
|
31
|
+
height: rect['height'],
|
|
32
|
+
bottom: rect['bottom']
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
const setStyles = (el, styles, render2) => {
|
|
36
|
+
Object.keys(styles).forEach((key) => render2.setStyle(el, key, styles[key]));
|
|
37
|
+
};
|
|
38
|
+
const getViewport = (win = window) => {
|
|
39
|
+
const doc = win.document.documentElement, body = win.document.getElementsByTagName('body')[0], w = win.innerWidth || doc.clientWidth || body.clientWidth, h = win.innerHeight || doc.clientHeight || body.clientHeight;
|
|
40
|
+
return { width: w, height: h };
|
|
41
|
+
};
|
|
42
|
+
const setCaretPosition = (element, position) => {
|
|
43
|
+
if (!element || !element.setSelectionRange) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
element.focus();
|
|
47
|
+
element.setSelectionRange(position, position);
|
|
48
|
+
};
|
|
49
|
+
const checkViewInScreen = (container, element, elementScroll, maxTopLeft) => {
|
|
50
|
+
if (!container || !element) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
const rectContainer = cloneIBoundingClientRect(container.getBoundingClientRect());
|
|
54
|
+
if (elementScroll) {
|
|
55
|
+
const rectElementScroll = elementScroll.getBoundingClientRect();
|
|
56
|
+
rectContainer['left'] = rectElementScroll.left;
|
|
57
|
+
rectContainer['top'] = rectElementScroll.top;
|
|
58
|
+
}
|
|
59
|
+
const rectElement = element.getBoundingClientRect();
|
|
60
|
+
const { left, top } = rectElement;
|
|
61
|
+
const topContainer = rectContainer['top'];
|
|
62
|
+
const leftContainer = rectContainer['left'];
|
|
63
|
+
const widthContainer = rectContainer['width'];
|
|
64
|
+
const heightContainer = rectContainer['height'];
|
|
65
|
+
const scrollTopContainer = container.scrollTop;
|
|
66
|
+
const scrollLeftContainer = container.scrollLeft;
|
|
67
|
+
const limitTop = topContainer + scrollTopContainer + heightContainer;
|
|
68
|
+
const limitLeft = leftContainer + scrollLeftContainer + widthContainer;
|
|
69
|
+
const maxTopItem = top + (maxTopLeft?.top || 0);
|
|
70
|
+
const maxLeftItem = left + (maxTopLeft?.left || 0);
|
|
71
|
+
if (topContainer <= maxTopItem && maxTopItem <= limitTop && leftContainer <= maxLeftItem && maxLeftItem <= limitLeft) {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
};
|
|
76
|
+
const checkMouseOverInContainer = (mousePosition, element, rect) => {
|
|
77
|
+
if (!element && !rect) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
const rectElement = rect || element?.getBoundingClientRect() || {};
|
|
81
|
+
const { left, top, width, height } = rectElement;
|
|
82
|
+
const limitLeft = left + width;
|
|
83
|
+
const limitTop = top + height;
|
|
84
|
+
const { clientX, clientY } = mousePosition;
|
|
85
|
+
if (left <= clientX && clientX <= limitLeft && top <= clientY && clientY <= limitTop) {
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
class UtilsUrlSearchParams {
|
|
92
|
+
static instance;
|
|
93
|
+
params;
|
|
94
|
+
constructor(paramString) {
|
|
95
|
+
this.params = new Array();
|
|
96
|
+
this.params.length = 0;
|
|
97
|
+
this.params.push(...this.buildParams(paramString));
|
|
98
|
+
}
|
|
99
|
+
static getInstance() {
|
|
100
|
+
if (!this.instance) {
|
|
101
|
+
this.instance = new UtilsUrlSearchParams('');
|
|
102
|
+
}
|
|
103
|
+
return this.instance;
|
|
104
|
+
}
|
|
105
|
+
static toStringParamObject(params) {
|
|
106
|
+
const paramsArr = Object.keys(params).map(key => {
|
|
107
|
+
return {
|
|
108
|
+
key,
|
|
109
|
+
value: params[key]
|
|
110
|
+
};
|
|
111
|
+
});
|
|
112
|
+
return UtilsUrlSearchParams.ToString(paramsArr);
|
|
113
|
+
}
|
|
114
|
+
static ToString(params) {
|
|
115
|
+
let paramsStr = '';
|
|
116
|
+
params.sort((item1, item2) => item1.key.localeCompare(item2.key)).forEach((item) => {
|
|
117
|
+
const { key, value } = item;
|
|
118
|
+
paramsStr = `${paramsStr}${paramsStr ? '&' : ''}${key}=${value}`;
|
|
119
|
+
});
|
|
120
|
+
return paramsStr;
|
|
121
|
+
}
|
|
122
|
+
buildParams(paramString) {
|
|
123
|
+
const paramsBuild = new Array();
|
|
124
|
+
if (!paramString) {
|
|
125
|
+
return paramsBuild;
|
|
126
|
+
}
|
|
127
|
+
const paramsError = paramString.split('?');
|
|
128
|
+
if (paramsError.length > 2) {
|
|
129
|
+
paramString = `${paramsError[0]}?${paramsError[1]}&${paramsError.slice(2).join('&')}`;
|
|
130
|
+
}
|
|
131
|
+
const params = paramString.replace(/\S+[?]/g, '').split('&');
|
|
132
|
+
if (params) {
|
|
133
|
+
params.forEach(param => {
|
|
134
|
+
if (param.indexOf('=') < 0) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
let [key, value] = param.split('=');
|
|
138
|
+
key = key.replace(/[?&]+/g, '');
|
|
139
|
+
value = decodeURIComponent(value.replace(/\+/g, ' '));
|
|
140
|
+
if (!paramsBuild.some(param => param.key === key)) {
|
|
141
|
+
paramsBuild.push({ key, value });
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
return paramsBuild;
|
|
146
|
+
}
|
|
147
|
+
set(key, value) {
|
|
148
|
+
const paramByKey = this.params.find(param => param.key === key);
|
|
149
|
+
if (!paramByKey) {
|
|
150
|
+
this.params.push({ key, value: decodeURIComponent(value.replace(/\+/g, ' ')) });
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
paramByKey['value'] = value;
|
|
154
|
+
}
|
|
155
|
+
get(key) {
|
|
156
|
+
return this.params.find(param => param.key === key)?.value;
|
|
157
|
+
}
|
|
158
|
+
has(key) {
|
|
159
|
+
return this.params.some(param => param.key === key);
|
|
160
|
+
}
|
|
161
|
+
delete(key) {
|
|
162
|
+
const index = this.params.findIndex(param => param.key === key);
|
|
163
|
+
if (index >= 0) {
|
|
164
|
+
this.params.splice(index, 1);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
length() {
|
|
168
|
+
return this.params.length;
|
|
169
|
+
}
|
|
170
|
+
toString(params) {
|
|
171
|
+
params = params || this.params;
|
|
172
|
+
return UtilsUrlSearchParams.ToString(params);
|
|
173
|
+
}
|
|
174
|
+
getParamObject() {
|
|
175
|
+
const params = {};
|
|
176
|
+
this.params.forEach(item => {
|
|
177
|
+
params[item.key] = item.value;
|
|
178
|
+
});
|
|
179
|
+
return params;
|
|
180
|
+
}
|
|
181
|
+
compareParams(param1, param2) {
|
|
182
|
+
const params1 = this.toString(this.buildParams(param1));
|
|
183
|
+
const params2 = this.toString(this.buildParams(param2));
|
|
184
|
+
return params1 === params2;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const uuid = () => {
|
|
189
|
+
const timestamp = performance.now() * 1000;
|
|
190
|
+
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+-=[]{}|;:,.<>?/~';
|
|
191
|
+
let randomString = '';
|
|
192
|
+
for (let i = 0; i < 5; i++) {
|
|
193
|
+
randomString += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
194
|
+
}
|
|
195
|
+
const baseString = `${Math.floor(timestamp)}-${randomString}`;
|
|
196
|
+
const charArray = baseString.split('');
|
|
197
|
+
for (let i = charArray.length - 1; i > 0; i--) {
|
|
198
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
199
|
+
[charArray[i], charArray[j]] = [charArray[j], charArray[i]];
|
|
200
|
+
}
|
|
201
|
+
const shuffledString = charArray.join('');
|
|
202
|
+
return shuffledString;
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
206
|
+
const isNil = (value) => {
|
|
207
|
+
return value === null || value === undefined;
|
|
208
|
+
};
|
|
209
|
+
const isEmpty = (value) => {
|
|
210
|
+
return value === null || value === '' || value === undefined || (typeof value === 'object' && (JSON.stringify(value) === '{}' || JSON.stringify(value) === '[]'));
|
|
211
|
+
};
|
|
212
|
+
const get = (obj, path, defaultValue = undefined) => {
|
|
213
|
+
if (obj == null) {
|
|
214
|
+
return defaultValue;
|
|
215
|
+
}
|
|
216
|
+
const paths = Array.isArray(path) ? path : path.replace(/\[(\d+)]/g, '.$1').split('.');
|
|
217
|
+
for (let i = 0; i < paths.length; i++) {
|
|
218
|
+
if (obj == null || !Object.prototype.hasOwnProperty.call(obj, paths[i])) {
|
|
219
|
+
return defaultValue;
|
|
220
|
+
}
|
|
221
|
+
obj = obj[paths[i]];
|
|
222
|
+
}
|
|
223
|
+
return obj;
|
|
224
|
+
};
|
|
225
|
+
const set = (obj, path, value) => {
|
|
226
|
+
if (!obj || typeof obj !== "object") {
|
|
227
|
+
throw new Error("The first argument must be an object");
|
|
228
|
+
}
|
|
229
|
+
const pathArray = Array.isArray(path) ? path : path.replace(/\[(\d+)]/g, '.[$1]').split('.');
|
|
230
|
+
let current = obj;
|
|
231
|
+
pathArray.forEach((key, index) => {
|
|
232
|
+
if (index < pathArray.length - 1) {
|
|
233
|
+
if (!(key in current) || typeof current[key] !== "object") {
|
|
234
|
+
const nextKey = pathArray[index + 1];
|
|
235
|
+
key = key.replace(/\[(\d+)]/g, '$1');
|
|
236
|
+
current[key] = /\[(\d+)]/g.test(nextKey) ? [] : {};
|
|
237
|
+
}
|
|
238
|
+
current = current[key];
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
// Gán giá trị ở cuối đường dẫn
|
|
242
|
+
current[key] = value;
|
|
243
|
+
});
|
|
244
|
+
return obj;
|
|
245
|
+
};
|
|
246
|
+
const cloneDeep = (value) => {
|
|
247
|
+
if (value === null || typeof value !== 'object') {
|
|
248
|
+
return value;
|
|
249
|
+
}
|
|
250
|
+
if (value instanceof Date) {
|
|
251
|
+
return new Date(value.getTime());
|
|
252
|
+
}
|
|
253
|
+
if (value instanceof RegExp) {
|
|
254
|
+
return new RegExp(value.source, value.flags);
|
|
255
|
+
}
|
|
256
|
+
if (value instanceof Map) {
|
|
257
|
+
const mapCopy = new Map();
|
|
258
|
+
value.forEach((val, key) => {
|
|
259
|
+
mapCopy.set(cloneDeep(key), cloneDeep(val));
|
|
260
|
+
});
|
|
261
|
+
return mapCopy;
|
|
262
|
+
}
|
|
263
|
+
if (value instanceof Set) {
|
|
264
|
+
const setCopy = new Set();
|
|
265
|
+
value.forEach(val => {
|
|
266
|
+
setCopy.add(cloneDeep(val));
|
|
267
|
+
});
|
|
268
|
+
return setCopy;
|
|
269
|
+
}
|
|
270
|
+
if (Array.isArray(value)) {
|
|
271
|
+
return value.map(item => cloneDeep(item));
|
|
272
|
+
}
|
|
273
|
+
const result = {};
|
|
274
|
+
for (const key in value) {
|
|
275
|
+
if (value[key] instanceof TemplateRef || value[key] instanceof ElementRef || value[key] instanceof Element) {
|
|
276
|
+
result[key] = value[key];
|
|
277
|
+
continue;
|
|
278
|
+
}
|
|
279
|
+
if (Object.prototype.hasOwnProperty.call(value, key)) {
|
|
280
|
+
result[key] = cloneDeep(value[key]);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return result;
|
|
284
|
+
};
|
|
285
|
+
const generateInterface = (obj, interfaceName) => {
|
|
286
|
+
const generateType = (value) => {
|
|
287
|
+
if (value === null) {
|
|
288
|
+
return 'null';
|
|
289
|
+
}
|
|
290
|
+
const type = typeof value;
|
|
291
|
+
if (type === 'string') {
|
|
292
|
+
return 'string';
|
|
293
|
+
}
|
|
294
|
+
if (type === 'number') {
|
|
295
|
+
return 'number';
|
|
296
|
+
}
|
|
297
|
+
if (type === 'boolean') {
|
|
298
|
+
return 'boolean';
|
|
299
|
+
}
|
|
300
|
+
if (type === 'undefined') {
|
|
301
|
+
return 'any';
|
|
302
|
+
}
|
|
303
|
+
if (value instanceof Date) {
|
|
304
|
+
return 'Date';
|
|
305
|
+
}
|
|
306
|
+
if (value instanceof RegExp) {
|
|
307
|
+
return 'RegExp';
|
|
308
|
+
}
|
|
309
|
+
if (Array.isArray(value)) {
|
|
310
|
+
if (value.length === 0) {
|
|
311
|
+
return 'Array<any>';
|
|
312
|
+
}
|
|
313
|
+
return `Array<${generateType(value[0])}>`;
|
|
314
|
+
}
|
|
315
|
+
if (type === 'object') {
|
|
316
|
+
let interfaceStr = '{\n';
|
|
317
|
+
for (const key in value) {
|
|
318
|
+
if (Object.prototype.hasOwnProperty.call(value, key)) {
|
|
319
|
+
const valueType = generateType(value[key]);
|
|
320
|
+
interfaceStr += ` ${key}: ${valueType};\n`;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
interfaceStr += '}';
|
|
324
|
+
return interfaceStr;
|
|
325
|
+
}
|
|
326
|
+
return 'any';
|
|
327
|
+
};
|
|
328
|
+
const interfaceStr = `interface ${interfaceName} ${generateType(obj)}`;
|
|
329
|
+
return interfaceStr;
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
;
|
|
333
|
+
const step = 20;
|
|
334
|
+
const percent = 0.05;
|
|
335
|
+
const colorStepContrastFromOrigin = (color, stepNumber) => {
|
|
336
|
+
return colorContrastFromOrigin(color).find(item => item.step === stepNumber);
|
|
337
|
+
};
|
|
338
|
+
const colorContrastFromOrigin = (color) => {
|
|
339
|
+
const parsedColorsArray = parseColorValues(color);
|
|
340
|
+
const colors = [];
|
|
341
|
+
let calculatedShades = [];
|
|
342
|
+
let calculatedTints = [];
|
|
343
|
+
if (parsedColorsArray !== null) {
|
|
344
|
+
for (let i = 0; i < parsedColorsArray.length; i++) {
|
|
345
|
+
calculatedShades = calculateShades(parsedColorsArray[i]);
|
|
346
|
+
calculatedTints = calculateTints(parsedColorsArray[i]);
|
|
347
|
+
}
|
|
348
|
+
for (let i = 0; i <= step; i++) {
|
|
349
|
+
colors.push({ step: i * 5, label: `${i * 5}%`, dark: `#${calculatedShades[i]}`, light: `#${calculatedTints[i]}` });
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
return colors;
|
|
353
|
+
};
|
|
354
|
+
const parseColorValues = (colorValues) => {
|
|
355
|
+
let colorValuesArray = colorValues.match(/\b[0-9A-Fa-f]{3}\b|[0-9A-Fa-f]{6}\b/g);
|
|
356
|
+
if (colorValuesArray) {
|
|
357
|
+
colorValuesArray = colorValuesArray.map((item) => {
|
|
358
|
+
if (item.length === 3) {
|
|
359
|
+
let newItem = item.toString().split('');
|
|
360
|
+
newItem = newItem.reduce((acc, it) => {
|
|
361
|
+
return acc + it + it;
|
|
362
|
+
}, '');
|
|
363
|
+
return newItem;
|
|
364
|
+
}
|
|
365
|
+
return item;
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
return colorValuesArray;
|
|
369
|
+
};
|
|
370
|
+
const calculateShades = (colorValue) => {
|
|
371
|
+
return calculate(colorValue, rgbShade).concat("000000");
|
|
372
|
+
};
|
|
373
|
+
const calculateTints = (colorValue) => {
|
|
374
|
+
return calculate(colorValue, rgbTint).concat("ffffff");
|
|
375
|
+
};
|
|
376
|
+
const calculate = (colorValue, shadeOrTint) => {
|
|
377
|
+
const color = hexToRGB(colorValue);
|
|
378
|
+
const shadeValues = [];
|
|
379
|
+
for (let i = 0; i < step; i++) {
|
|
380
|
+
shadeValues[i] = rgbToHex(shadeOrTint(color, i));
|
|
381
|
+
}
|
|
382
|
+
return shadeValues;
|
|
383
|
+
};
|
|
384
|
+
const rgbShade = (rgb, i) => { return { red: rgb.red * (1 - percent * i), green: rgb.green * (1 - percent * i), blue: rgb.blue * (1 - percent * i) }; };
|
|
385
|
+
const rgbTint = (rgb, i) => { return { red: rgb.red + (255 - rgb.red) * i * percent, green: rgb.green + (255 - rgb.green) * i * percent, blue: rgb.blue + (255 - rgb.blue) * i * percent }; };
|
|
386
|
+
const rgbToHex = (rgb) => { return intToHex(rgb.red) + intToHex(rgb.green) + intToHex(rgb.blue); };
|
|
387
|
+
const hexToRGB = (colorValue) => { return { red: parseInt(colorValue.substr(0, 2), 16), green: parseInt(colorValue.substr(2, 2), 16), blue: parseInt(colorValue.substr(4, 2), 16) }; };
|
|
388
|
+
const intToHex = (rgbint) => { return pad(Math.min(Math.max(Math.round(rgbint), 0), 255).toString(16), 2); };
|
|
389
|
+
const pad = (number, length) => {
|
|
390
|
+
let str = '' + number;
|
|
391
|
+
while (str.length < length) {
|
|
392
|
+
str = '0' + str;
|
|
393
|
+
}
|
|
394
|
+
return str;
|
|
395
|
+
};
|
|
396
|
+
const listColorDefine$1 = ['#E62222', '#B81B1B', '#EB4E4E', '#F97316', '#C75C12', '#FA8F45', '#FFB700', '#CC9200', '#FFC533', '#84CC16', '#6AA312', '#9dd645', '#00BC62', '#00A757', '#33DA8A', '#06B6D4', '#1B59C4', '#4E8CF7', '#0EA5E9',
|
|
397
|
+
'#1B59C4', '#4E8CF7', '#226FF5', '#1B59C4', '#4E8CF7', '#6366F1', '#4F52C1', '#8285F4', '#5B04B3', '#49038F', '#7C36C2', '#D946EF', '#AE38BF', '#E16BF2', '#EC4899', '#BD3A7A', '#F06DAD', '#F43F5E', '#C3324B', '#F6657E', '#757380', '#5E5C66', '#918F99',
|
|
398
|
+
'#202020', '#1A1A1A', '#4D4D4D'
|
|
399
|
+
];
|
|
400
|
+
const GetColorById = (str) => {
|
|
401
|
+
let hashString = 0;
|
|
402
|
+
if (!str) {
|
|
403
|
+
return '';
|
|
404
|
+
}
|
|
405
|
+
for (let i = 0; i < str.length; i++) {
|
|
406
|
+
const char = str.charCodeAt(i);
|
|
407
|
+
hashString = ((hashString << 5) - hashString) + char;
|
|
408
|
+
hashString = hashString & hashString;
|
|
409
|
+
}
|
|
410
|
+
return listColorDefine$1[Math.abs(hashString) % listColorDefine$1.length];
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
let key$1 = '12~@#loqwsxacva(3rdhaq12';
|
|
414
|
+
const setKeyCrypto = (value) => {
|
|
415
|
+
if (value.length !== 24 && value.length !== 32) {
|
|
416
|
+
throw Error(`key.length = ${value.length}; Key phải là 1 chuỗi dài 24 hoặc 32 ký tự`);
|
|
417
|
+
}
|
|
418
|
+
key$1 = value;
|
|
419
|
+
};
|
|
420
|
+
const keyStore$1 = () => {
|
|
421
|
+
return key$1;
|
|
422
|
+
};
|
|
423
|
+
const encrypt = (plainData) => {
|
|
424
|
+
if (!keyStore$1()) {
|
|
425
|
+
throw Error("lỗi chưa setup key mã hóa");
|
|
426
|
+
}
|
|
427
|
+
const key = CryptoES.enc.Hex.parse(keyStore$1());
|
|
428
|
+
const iv = CryptoES.enc.Hex.parse(keyStore$1());
|
|
429
|
+
const mode = CryptoES.mode.CBC;
|
|
430
|
+
const padding = CryptoES.pad.Pkcs7;
|
|
431
|
+
const options = { iv: iv, mode: mode, padding: padding };
|
|
432
|
+
return CryptoES.AES.encrypt(plainData, key, options).toString();
|
|
433
|
+
};
|
|
434
|
+
const decrypt = (encryptedData) => {
|
|
435
|
+
if (!keyStore$1()) {
|
|
436
|
+
throw Error("lỗi chưa setup key mã hóa");
|
|
437
|
+
}
|
|
438
|
+
const key = CryptoES.enc.Hex.parse(keyStore$1());
|
|
439
|
+
const iv = CryptoES.enc.Hex.parse(keyStore$1());
|
|
440
|
+
const mode = CryptoES.mode.CBC;
|
|
441
|
+
const padding = CryptoES.pad.Pkcs7;
|
|
442
|
+
const options = { iv: iv, mode: mode, padding: padding };
|
|
443
|
+
return CryptoES.AES.decrypt(encryptedData, key, options).toString(CryptoES.enc.Utf8);
|
|
444
|
+
};
|
|
445
|
+
const md5 = (plainData) => {
|
|
446
|
+
return CryptoES.MD5(plainData).toString();
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
let key = '12~@#loqwsxacva(3rdhaq12';
|
|
450
|
+
const setKeyCrypto3rd = (value) => {
|
|
451
|
+
if (value.length !== 24 && value.length !== 32) {
|
|
452
|
+
throw Error(`key.length = ${value.length}; Key phải là 1 chuỗi dài 24 hoặc 32 ký tự`);
|
|
453
|
+
}
|
|
454
|
+
key = value;
|
|
455
|
+
};
|
|
456
|
+
const keyStore = () => {
|
|
457
|
+
return key;
|
|
458
|
+
};
|
|
459
|
+
const encrypt3rd = (plainData) => {
|
|
460
|
+
if (!keyStore()) {
|
|
461
|
+
throw Error("lỗi chưa setup key mã hóa");
|
|
462
|
+
}
|
|
463
|
+
const key = CryptoES.enc.Hex.parse(keyStore());
|
|
464
|
+
const iv = CryptoES.enc.Hex.parse(keyStore());
|
|
465
|
+
const mode = CryptoES.mode.CBC;
|
|
466
|
+
const padding = CryptoES.pad.Pkcs7;
|
|
467
|
+
const options = { iv: iv, mode: mode, padding: padding };
|
|
468
|
+
return CryptoES.AES.encrypt(plainData, key, options).toString();
|
|
469
|
+
};
|
|
470
|
+
const decrypt3rd = (encryptedData) => {
|
|
471
|
+
if (!keyStore()) {
|
|
472
|
+
throw Error("lỗi chưa setup key mã hóa");
|
|
473
|
+
}
|
|
474
|
+
const key = CryptoES.enc.Hex.parse(keyStore());
|
|
475
|
+
const iv = CryptoES.enc.Hex.parse(keyStore());
|
|
476
|
+
const mode = CryptoES.mode.CBC;
|
|
477
|
+
const padding = CryptoES.pad.Pkcs7;
|
|
478
|
+
const options = { iv: iv, mode: mode, padding: padding };
|
|
479
|
+
return CryptoES.AES.decrypt(encryptedData, key, options).toString(CryptoES.enc.Utf8);
|
|
480
|
+
};
|
|
481
|
+
|
|
482
|
+
class UtilsKeyCodeConstant {
|
|
483
|
+
static MAC_ENTER = 3;
|
|
484
|
+
static BACKSPACE = 8;
|
|
485
|
+
static TAB = 9;
|
|
486
|
+
static NUM_CENTER = 12;
|
|
487
|
+
static ENTER = 13;
|
|
488
|
+
static SHIFT = 16;
|
|
489
|
+
static CONTROL = 17;
|
|
490
|
+
static ALT = 18;
|
|
491
|
+
static PAUSE = 19;
|
|
492
|
+
static CAPS_LOCK = 20;
|
|
493
|
+
static ESCAPE = 27;
|
|
494
|
+
static SPACE = 32;
|
|
495
|
+
static PAGE_UP = 33;
|
|
496
|
+
static PAGE_DOWN = 34;
|
|
497
|
+
static END = 35;
|
|
498
|
+
static HOME = 36;
|
|
499
|
+
static LEFT_ARROW = 37;
|
|
500
|
+
static UP_ARROW = 38;
|
|
501
|
+
static RIGHT_ARROW = 39;
|
|
502
|
+
static DOWN_ARROW = 40;
|
|
503
|
+
static PLUS_SIGN = 43;
|
|
504
|
+
static PRINT_SCREEN = 44;
|
|
505
|
+
static INSERT = 45;
|
|
506
|
+
static DELETE = 46;
|
|
507
|
+
static ZERO = 48;
|
|
508
|
+
static ONE = 49;
|
|
509
|
+
static TWO = 50;
|
|
510
|
+
static THREE = 51;
|
|
511
|
+
static FOUR = 52;
|
|
512
|
+
static FIVE = 53;
|
|
513
|
+
static SIX = 54;
|
|
514
|
+
static SEVEN = 55;
|
|
515
|
+
static EIGHT = 56;
|
|
516
|
+
static NINE = 57;
|
|
517
|
+
static FF_SEMICOLON = 59; // Firefox (Gecko) fires this for semicolon instead of 186
|
|
518
|
+
static FF_EQUALS = 61; // Firefox (Gecko) fires this for equals instead of 187
|
|
519
|
+
static QUESTION_MARK = 63;
|
|
520
|
+
static AT_SIGN = 64;
|
|
521
|
+
static A = 65;
|
|
522
|
+
static B = 66;
|
|
523
|
+
static C = 67;
|
|
524
|
+
static D = 68;
|
|
525
|
+
static E = 69;
|
|
526
|
+
static F = 70;
|
|
527
|
+
static G = 71;
|
|
528
|
+
static H = 72;
|
|
529
|
+
static I = 73;
|
|
530
|
+
static J = 74;
|
|
531
|
+
static K = 75;
|
|
532
|
+
static L = 76;
|
|
533
|
+
static M = 77;
|
|
534
|
+
static N = 78;
|
|
535
|
+
static O = 79;
|
|
536
|
+
static P = 80;
|
|
537
|
+
static Q = 81;
|
|
538
|
+
static R = 82;
|
|
539
|
+
static S = 83;
|
|
540
|
+
static T = 84;
|
|
541
|
+
static U = 85;
|
|
542
|
+
static V = 86;
|
|
543
|
+
static W = 87;
|
|
544
|
+
static X = 88;
|
|
545
|
+
static Y = 89;
|
|
546
|
+
static Z = 90;
|
|
547
|
+
static META = 91; // WIN_KEY_LEFT
|
|
548
|
+
static MAC_WK_CMD_LEFT = 91;
|
|
549
|
+
static MAC_WK_CMD_RIGHT = 93;
|
|
550
|
+
static CONTEXT_MENU = 93;
|
|
551
|
+
static NUMPAD_ZERO = 96;
|
|
552
|
+
static NUMPAD_ONE = 97;
|
|
553
|
+
static NUMPAD_TWO = 98;
|
|
554
|
+
static NUMPAD_THREE = 99;
|
|
555
|
+
static NUMPAD_FOUR = 100;
|
|
556
|
+
static NUMPAD_FIVE = 101;
|
|
557
|
+
static NUMPAD_SIX = 102;
|
|
558
|
+
static NUMPAD_SEVEN = 103;
|
|
559
|
+
static NUMPAD_EIGHT = 104;
|
|
560
|
+
static NUMPAD_NINE = 105;
|
|
561
|
+
static NUMPAD_MULTIPLY = 106;
|
|
562
|
+
static NUMPAD_PLUS = 107;
|
|
563
|
+
static NUMPAD_MINUS = 109;
|
|
564
|
+
static NUMPAD_PERIOD = 110;
|
|
565
|
+
static NUMPAD_DIVIDE = 111;
|
|
566
|
+
static F1 = 112;
|
|
567
|
+
static F2 = 113;
|
|
568
|
+
static F3 = 114;
|
|
569
|
+
static F4 = 115;
|
|
570
|
+
static F5 = 116;
|
|
571
|
+
static F6 = 117;
|
|
572
|
+
static F7 = 118;
|
|
573
|
+
static F8 = 119;
|
|
574
|
+
static F9 = 120;
|
|
575
|
+
static F10 = 121;
|
|
576
|
+
static F11 = 122;
|
|
577
|
+
static F12 = 123;
|
|
578
|
+
static NUM_LOCK = 144;
|
|
579
|
+
static SCROLL_LOCK = 145;
|
|
580
|
+
static FIRST_MEDIA = 166;
|
|
581
|
+
static FF_MINUS = 173;
|
|
582
|
+
static MUTE = 173; // Firefox (Gecko) fires 181 for MUTE
|
|
583
|
+
static VOLUME_DOWN = 174; // Firefox (Gecko) fires 182 for VOLUME_DOWN
|
|
584
|
+
static VOLUME_UP = 175; // Firefox (Gecko) fires 183 for VOLUME_UP
|
|
585
|
+
static FF_MUTE = 181;
|
|
586
|
+
static FF_VOLUME_DOWN = 182;
|
|
587
|
+
static LAST_MEDIA = 183;
|
|
588
|
+
static FF_VOLUME_UP = 183;
|
|
589
|
+
static SEMICOLON = 186; // Firefox (Gecko) fires 59 for SEMICOLON
|
|
590
|
+
static EQUALS = 187; // Firefox (Gecko) fires 61 for EQUALS
|
|
591
|
+
static COMMA = 188;
|
|
592
|
+
static DASH = 189; // Firefox (Gecko) fires 173 for DASH/MINUS
|
|
593
|
+
static PERIOD = 190;
|
|
594
|
+
static SLASH = 191;
|
|
595
|
+
static APOSTROPHE = 192;
|
|
596
|
+
static TILDE = 192;
|
|
597
|
+
static OPEN_SQUARE_BRACKET = 219;
|
|
598
|
+
static BACKSLASH = 220;
|
|
599
|
+
static CLOSE_SQUARE_BRACKET = 221;
|
|
600
|
+
static SINGLE_QUOTE = 222;
|
|
601
|
+
static MAC_META = 224;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
605
|
+
const HttpParamsRequestInstance = (options, instance) => {
|
|
606
|
+
return new UtilsHttpParamsRequest(options, instance);
|
|
607
|
+
};
|
|
608
|
+
class UtilsHttpParamsRequest extends HttpParams {
|
|
609
|
+
params;
|
|
610
|
+
constructor(options, instance) {
|
|
611
|
+
super(options);
|
|
612
|
+
if (!instance) {
|
|
613
|
+
this.params = new HttpParams(options);
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
if (instance instanceof UtilsHttpParamsRequest) {
|
|
617
|
+
this.params = instance.getInstance();
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
620
|
+
if (instance instanceof HttpParams) {
|
|
621
|
+
this.params = instance;
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
getInstance() {
|
|
626
|
+
return this.params;
|
|
627
|
+
}
|
|
628
|
+
setInstance(instance) {
|
|
629
|
+
if (instance instanceof UtilsHttpParamsRequest) {
|
|
630
|
+
this.params = instance.getInstance();
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
if (instance instanceof HttpParams) {
|
|
634
|
+
this.params = instance;
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
set(param, value) {
|
|
639
|
+
this.params = this.params.set(param, value);
|
|
640
|
+
return this;
|
|
641
|
+
}
|
|
642
|
+
has(param) {
|
|
643
|
+
return this.params.has(param);
|
|
644
|
+
}
|
|
645
|
+
get(param) {
|
|
646
|
+
return this.params.get(param);
|
|
647
|
+
}
|
|
648
|
+
getAll(param) {
|
|
649
|
+
return this.params.getAll(param);
|
|
650
|
+
}
|
|
651
|
+
keys() {
|
|
652
|
+
return this.params.keys();
|
|
653
|
+
}
|
|
654
|
+
append(param, value) {
|
|
655
|
+
this.params = this.params.append(param, value);
|
|
656
|
+
return this;
|
|
657
|
+
}
|
|
658
|
+
appendAll(params) {
|
|
659
|
+
this.params = this.params.appendAll(params);
|
|
660
|
+
return this;
|
|
661
|
+
}
|
|
662
|
+
delete(param, value) {
|
|
663
|
+
this.params = this.params.delete(param, value);
|
|
664
|
+
return this;
|
|
665
|
+
}
|
|
666
|
+
toString() {
|
|
667
|
+
return this.params.toString();
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
class UtilsLanguageConstants {
|
|
672
|
+
static VI = 'vi';
|
|
673
|
+
static EN = 'en';
|
|
674
|
+
static defaultLang = UtilsLanguageConstants.VI;
|
|
675
|
+
}
|
|
676
|
+
;
|
|
677
|
+
|
|
678
|
+
const getKeyCacheByArrayObject = (keyCache, argumentsValue) => {
|
|
679
|
+
if (!keyCache || !argumentsValue) {
|
|
680
|
+
return '';
|
|
681
|
+
}
|
|
682
|
+
let keyBuild = `${JSON.stringify(argumentsValue.slice(1))}-key-cache-plus`;
|
|
683
|
+
if (argumentsValue && argumentsValue[0] instanceof HttpParams) {
|
|
684
|
+
const httpParams = argumentsValue[0];
|
|
685
|
+
const keys = argumentsValue[0].keys().sort((str1, str2) => str1.localeCompare(str2));
|
|
686
|
+
keys.forEach(key => {
|
|
687
|
+
keyBuild = `${keyBuild}${JSON.stringify(httpParams.get(key))}`;
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
const keyCachePlus = md5(keyBuild);
|
|
691
|
+
const keyCacheMD5 = md5(keyCache);
|
|
692
|
+
return `${keyCacheMD5}-${md5(`${keyCacheMD5}-${keyCachePlus}`)}`;
|
|
693
|
+
};
|
|
694
|
+
|
|
695
|
+
let functionCheck = () => {
|
|
696
|
+
return window.parent !== window.top;
|
|
697
|
+
};
|
|
698
|
+
const updateFunctionCheckEmbedFrame = (functionCustom) => {
|
|
699
|
+
functionCheck = functionCustom;
|
|
700
|
+
};
|
|
701
|
+
const isEmbedFrame = () => {
|
|
702
|
+
return functionCheck();
|
|
703
|
+
};
|
|
704
|
+
|
|
705
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
706
|
+
class UtilsCommunicateMicro {
|
|
707
|
+
static KEY_GET_ALL_MESSAGE = 'MICRO_SITES_ALL_MESSAGE';
|
|
708
|
+
static PREFIX_TYPE = '3RD_INTEGRATE_MICRO_SITE_';
|
|
709
|
+
static initdEvent;
|
|
710
|
+
static subs = new Map();
|
|
711
|
+
static allMessageSub = new Subject();
|
|
712
|
+
static initEvent(currentWindow) {
|
|
713
|
+
if (this.initdEvent) {
|
|
714
|
+
return;
|
|
715
|
+
}
|
|
716
|
+
this.initdEvent = true;
|
|
717
|
+
if (!this.subs.get(UtilsCommunicateMicro.KEY_GET_ALL_MESSAGE)) {
|
|
718
|
+
this.subs.set(UtilsCommunicateMicro.KEY_GET_ALL_MESSAGE, UtilsCommunicateMicro.allMessageSub);
|
|
719
|
+
}
|
|
720
|
+
fromEvent(currentWindow, 'message').subscribe(e => {
|
|
721
|
+
const event = { data: { ...e.data } };
|
|
722
|
+
const data = event.data;
|
|
723
|
+
const type = data.type;
|
|
724
|
+
if (!type) {
|
|
725
|
+
return this.allMessageSub.next(event);
|
|
726
|
+
}
|
|
727
|
+
const sub = UtilsCommunicateMicro.GetMessage(type);
|
|
728
|
+
if (!type || !data.response) {
|
|
729
|
+
return;
|
|
730
|
+
}
|
|
731
|
+
try {
|
|
732
|
+
if (type.includes(UtilsCommunicateMicro.PREFIX_TYPE)) {
|
|
733
|
+
data.response = JSON.parse(decrypt3rd(data.response));
|
|
734
|
+
sub.next(event);
|
|
735
|
+
this.allMessageSub.next(event);
|
|
736
|
+
return;
|
|
737
|
+
}
|
|
738
|
+
data.response = JSON.parse(decrypt(data.response));
|
|
739
|
+
sub.next(event);
|
|
740
|
+
this.allMessageSub.next(event);
|
|
741
|
+
}
|
|
742
|
+
catch (error) {
|
|
743
|
+
console.log(error);
|
|
744
|
+
sub.next(event);
|
|
745
|
+
this.allMessageSub.next(event);
|
|
746
|
+
}
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
static PostMessageToParent(data) {
|
|
750
|
+
data = this.convertData(data);
|
|
751
|
+
try {
|
|
752
|
+
if (isEmbedFrame()) {
|
|
753
|
+
window?.parent?.postMessage(data, "*");
|
|
754
|
+
return;
|
|
755
|
+
}
|
|
756
|
+
window?.top?.postMessage(data, "*");
|
|
757
|
+
}
|
|
758
|
+
catch (error) {
|
|
759
|
+
console.log(error);
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
static PostMessageToChildren(data) {
|
|
763
|
+
data = this.convertData(data);
|
|
764
|
+
const iframes = document.querySelectorAll("iframe");
|
|
765
|
+
Array.from(iframes).forEach(iframe => {
|
|
766
|
+
iframe?.contentWindow?.postMessage(data, '*');
|
|
767
|
+
});
|
|
768
|
+
}
|
|
769
|
+
static PostMessageToOpener(data) {
|
|
770
|
+
if (!window.opener) {
|
|
771
|
+
return;
|
|
772
|
+
}
|
|
773
|
+
data = this.convertData(data);
|
|
774
|
+
window.opener.postMessage(data, '*');
|
|
775
|
+
}
|
|
776
|
+
static convertData(data) {
|
|
777
|
+
if (!data || !data.type || !data.response) {
|
|
778
|
+
return data;
|
|
779
|
+
}
|
|
780
|
+
data = { ...data };
|
|
781
|
+
const type = data.type;
|
|
782
|
+
if (type.includes(this.PREFIX_TYPE)) {
|
|
783
|
+
try {
|
|
784
|
+
JSON.parse(decrypt3rd(data.response));
|
|
785
|
+
return data;
|
|
786
|
+
}
|
|
787
|
+
catch (error) {
|
|
788
|
+
console.log(error);
|
|
789
|
+
data.response = decrypt3rd(JSON.stringify(data.response));
|
|
790
|
+
return data;
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
try {
|
|
794
|
+
JSON.parse(decrypt(data.response));
|
|
795
|
+
return data;
|
|
796
|
+
}
|
|
797
|
+
catch (error) {
|
|
798
|
+
console.log(error);
|
|
799
|
+
data.response = decrypt(JSON.stringify(data.response));
|
|
800
|
+
return data;
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
static GetMessage(messageType) {
|
|
804
|
+
if (!this.initdEvent) {
|
|
805
|
+
throw Error("chưa khơi tạo hàm lắng nghe sự kiện, gọi UtilsCommunicateMicro.initEvent(window) tại root component");
|
|
806
|
+
}
|
|
807
|
+
if (typeof messageType === 'string') {
|
|
808
|
+
let sub = this.subs.get(messageType);
|
|
809
|
+
if (!sub) {
|
|
810
|
+
sub = new Subject();
|
|
811
|
+
this.subs.set(messageType, sub);
|
|
812
|
+
return sub;
|
|
813
|
+
}
|
|
814
|
+
return sub;
|
|
815
|
+
}
|
|
816
|
+
if (!Array.isArray(messageType) || !messageType.length) {
|
|
817
|
+
throw new Error('message type empty');
|
|
818
|
+
}
|
|
819
|
+
const types = messageType.sort().join(';');
|
|
820
|
+
let sub = this.subs.get(types);
|
|
821
|
+
if (sub) {
|
|
822
|
+
return sub;
|
|
823
|
+
}
|
|
824
|
+
sub = new Subject();
|
|
825
|
+
this.subs.set(types, sub);
|
|
826
|
+
this.initSubject(sub, messageType);
|
|
827
|
+
return sub;
|
|
828
|
+
}
|
|
829
|
+
static initSubject(subRoot, messageType) {
|
|
830
|
+
messageType.forEach(key => {
|
|
831
|
+
this.GetMessage(key).subscribe(e => {
|
|
832
|
+
subRoot.next(e);
|
|
833
|
+
});
|
|
834
|
+
});
|
|
835
|
+
}
|
|
836
|
+
postMessageToParent(data) {
|
|
837
|
+
UtilsCommunicateMicro.PostMessageToParent(data);
|
|
838
|
+
}
|
|
839
|
+
postMessageToChildren(data) {
|
|
840
|
+
UtilsCommunicateMicro.PostMessageToChildren(data);
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
/* eslint-disable no-async-promise-executor */
|
|
845
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
846
|
+
class UtilsCache {
|
|
847
|
+
static typeKeyClearLocalStorage = 'LIBS_UI_CLEAR_LOCAL_STORAGE_EVENT';
|
|
848
|
+
static listKeyKeepWhenClearALll = Array();
|
|
849
|
+
static languageKeyCache = 'SR3xQKxHgffiCevPQRralg';
|
|
850
|
+
static initdEvent;
|
|
851
|
+
static CACHE_EXPIRE_TIME_DEFAULT = 5 * 60;
|
|
852
|
+
static CACHE_EXPIRE_NONE = -1;
|
|
853
|
+
static language = signal(UtilsLanguageConstants.defaultLang);
|
|
854
|
+
static idService = uuid();
|
|
855
|
+
static storage;
|
|
856
|
+
static dbName = 'libs-ui-cache';
|
|
857
|
+
static itemIndexByKey = 'key';
|
|
858
|
+
static dbVersion = 1;
|
|
859
|
+
static db = null;
|
|
860
|
+
static init(config) {
|
|
861
|
+
if (UtilsCache.initdEvent) {
|
|
862
|
+
return;
|
|
863
|
+
}
|
|
864
|
+
UtilsCache.initdEvent = true;
|
|
865
|
+
if (config.indexedDBName) {
|
|
866
|
+
UtilsCache.dbName = config.indexedDBName;
|
|
867
|
+
}
|
|
868
|
+
if (config.typeKeyClearLocalStorage) {
|
|
869
|
+
UtilsCache.typeKeyClearLocalStorage = config.typeKeyClearLocalStorage;
|
|
870
|
+
}
|
|
871
|
+
if (config.listKeyKeepWhenClearALll) {
|
|
872
|
+
UtilsCache.listKeyKeepWhenClearALll = config.listKeyKeepWhenClearALll;
|
|
873
|
+
}
|
|
874
|
+
if (config.languageKeyCache) {
|
|
875
|
+
UtilsCache.languageKeyCache = config.languageKeyCache;
|
|
876
|
+
}
|
|
877
|
+
UtilsCommunicateMicro.GetMessage(UtilsCache.typeKeyClearLocalStorage).pipe(filter(e => e.data.response !== UtilsCache.idService)).subscribe(() => {
|
|
878
|
+
UtilsCache.ClearAll();
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
static setLang(lang) {
|
|
882
|
+
if (lang !== UtilsLanguageConstants.VI && lang !== UtilsLanguageConstants.EN) {
|
|
883
|
+
throw Error('Language support vi | en');
|
|
884
|
+
}
|
|
885
|
+
UtilsCache.language.set(lang);
|
|
886
|
+
UtilsCache.Set(UtilsCache.languageKeyCache, lang);
|
|
887
|
+
}
|
|
888
|
+
static getLang() {
|
|
889
|
+
return UtilsCache.language();
|
|
890
|
+
}
|
|
891
|
+
static openDB() {
|
|
892
|
+
return new Promise(resolve => {
|
|
893
|
+
const request = indexedDB.open(UtilsCache.dbName, UtilsCache.dbVersion);
|
|
894
|
+
request.onupgradeneeded = (event) => {
|
|
895
|
+
const db = event.target.result;
|
|
896
|
+
if (!db.objectStoreNames.contains(UtilsCache.dbName)) {
|
|
897
|
+
const objectStore = db.createObjectStore(UtilsCache.dbName, { keyPath: 'id', autoIncrement: true });
|
|
898
|
+
objectStore.createIndex(UtilsCache.itemIndexByKey, UtilsCache.itemIndexByKey, { unique: true });
|
|
899
|
+
}
|
|
900
|
+
};
|
|
901
|
+
request.onsuccess = () => {
|
|
902
|
+
UtilsCache.db = request.result;
|
|
903
|
+
setTimeout(() => {
|
|
904
|
+
UtilsCache.DeleteKeyStartWithAsync('');
|
|
905
|
+
}, 2000);
|
|
906
|
+
resolve(true);
|
|
907
|
+
};
|
|
908
|
+
request.onerror = (event) => {
|
|
909
|
+
console.error('Error opening IndexedDB:', event);
|
|
910
|
+
resolve(false);
|
|
911
|
+
};
|
|
912
|
+
});
|
|
913
|
+
}
|
|
914
|
+
static async getObjectStore() {
|
|
915
|
+
if (!UtilsCache.db) {
|
|
916
|
+
await UtilsCache.openDB();
|
|
917
|
+
}
|
|
918
|
+
const transaction = UtilsCache.db?.transaction([UtilsCache.dbName], 'readwrite');
|
|
919
|
+
return transaction?.objectStore(UtilsCache.dbName);
|
|
920
|
+
}
|
|
921
|
+
static get LocalStorage() {
|
|
922
|
+
try {
|
|
923
|
+
if (typeof window.localStorage !== 'undefined') {
|
|
924
|
+
const OS = getPlatFromBrowser();
|
|
925
|
+
if (OS.includes('Safari') && parseFloat(OS.split(' ').pop() || '0') >= 16) {
|
|
926
|
+
return this.getLocalStorageFakeOnSafari();
|
|
927
|
+
}
|
|
928
|
+
return localStorage;
|
|
929
|
+
}
|
|
930
|
+
return this.getLocalStorageFake();
|
|
931
|
+
}
|
|
932
|
+
catch (error) {
|
|
933
|
+
console.log(error);
|
|
934
|
+
return this.getLocalStorageFake();
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
static getLocalStorageFakeOnSafari() {
|
|
938
|
+
if (typeof window.localStorage !== 'undefined' && !UtilsCache.storage && Object.keys(localStorage).length) {
|
|
939
|
+
this.storage = { ...localStorage };
|
|
940
|
+
}
|
|
941
|
+
return {
|
|
942
|
+
setItem: (key, value) => {
|
|
943
|
+
localStorage.setItem(key, value);
|
|
944
|
+
this.storage[key] = value;
|
|
945
|
+
},
|
|
946
|
+
getItem: (key) => {
|
|
947
|
+
const value = localStorage.getItem(key);
|
|
948
|
+
if (value) {
|
|
949
|
+
return value;
|
|
950
|
+
}
|
|
951
|
+
if (!this.storage || isNil(this.storage[key])) {
|
|
952
|
+
return null;
|
|
953
|
+
}
|
|
954
|
+
localStorage.setItem(key, this.storage[key]);
|
|
955
|
+
return this.storage?.[key];
|
|
956
|
+
},
|
|
957
|
+
removeItem: (key) => {
|
|
958
|
+
delete this.storage?.[key];
|
|
959
|
+
localStorage.removeItem(key);
|
|
960
|
+
},
|
|
961
|
+
clear: () => {
|
|
962
|
+
this.storage = {};
|
|
963
|
+
localStorage.clear();
|
|
964
|
+
}
|
|
965
|
+
};
|
|
966
|
+
}
|
|
967
|
+
static getLocalStorageFake() {
|
|
968
|
+
if (!UtilsCache.storage) {
|
|
969
|
+
this.storage = {};
|
|
970
|
+
}
|
|
971
|
+
return {
|
|
972
|
+
setItem: (key, value) => {
|
|
973
|
+
this.storage[key] = value;
|
|
974
|
+
},
|
|
975
|
+
getItem: (key) => {
|
|
976
|
+
return this.storage?.[key];
|
|
977
|
+
},
|
|
978
|
+
removeItem: (key) => {
|
|
979
|
+
delete this.storage?.[key];
|
|
980
|
+
},
|
|
981
|
+
clear: () => {
|
|
982
|
+
this.storage = {};
|
|
983
|
+
}
|
|
984
|
+
};
|
|
985
|
+
}
|
|
986
|
+
static async GetAsync(key, default_value, isKeyMD5 = false) {
|
|
987
|
+
key = isKeyMD5 ? key : md5(key);
|
|
988
|
+
return new Promise(async (resolve, reject) => {
|
|
989
|
+
const objectStore = await UtilsCache.getObjectStore();
|
|
990
|
+
if (!objectStore) {
|
|
991
|
+
return resolve(default_value);
|
|
992
|
+
}
|
|
993
|
+
const index = objectStore.index(UtilsCache.itemIndexByKey);
|
|
994
|
+
const request = index.get(key);
|
|
995
|
+
request.onsuccess = () => {
|
|
996
|
+
if (!request.result) {
|
|
997
|
+
return resolve(default_value);
|
|
998
|
+
}
|
|
999
|
+
const data = JSON.parse(decrypt(request.result.value));
|
|
1000
|
+
if (data.expire === UtilsCache.CACHE_EXPIRE_NONE) {
|
|
1001
|
+
return resolve(data.json);
|
|
1002
|
+
}
|
|
1003
|
+
const currentMillisecond = (new Date().valueOf() / 1000);
|
|
1004
|
+
if (data.expire < currentMillisecond) {
|
|
1005
|
+
return resolve(default_value);
|
|
1006
|
+
}
|
|
1007
|
+
return resolve(data.json);
|
|
1008
|
+
};
|
|
1009
|
+
request.onerror = () => {
|
|
1010
|
+
reject(request.error);
|
|
1011
|
+
};
|
|
1012
|
+
});
|
|
1013
|
+
}
|
|
1014
|
+
static Get(key, default_value) {
|
|
1015
|
+
if (!key) {
|
|
1016
|
+
return this.GetDefaultValueBySpecificKey(key, default_value);
|
|
1017
|
+
}
|
|
1018
|
+
const cachedData = this.LocalStorage.getItem(key);
|
|
1019
|
+
if (!cachedData) {
|
|
1020
|
+
return this.GetDefaultValueBySpecificKey(key, default_value);
|
|
1021
|
+
}
|
|
1022
|
+
try {
|
|
1023
|
+
const data = JSON.parse(decrypt(cachedData));
|
|
1024
|
+
if (data.expire === UtilsCache.CACHE_EXPIRE_NONE) {
|
|
1025
|
+
return data.value;
|
|
1026
|
+
}
|
|
1027
|
+
const currentMillisecond = (new Date().valueOf() / 1000);
|
|
1028
|
+
if (data.expire < currentMillisecond) {
|
|
1029
|
+
return this.GetDefaultValueBySpecificKey(key, default_value);
|
|
1030
|
+
}
|
|
1031
|
+
return data.value;
|
|
1032
|
+
}
|
|
1033
|
+
catch (error) {
|
|
1034
|
+
console.log(error);
|
|
1035
|
+
return this.GetDefaultValueBySpecificKey(key, default_value);
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
static GetDefaultValueBySpecificKey(key, default_value) {
|
|
1039
|
+
return default_value;
|
|
1040
|
+
}
|
|
1041
|
+
static async SetAsync(key, value, expireTimeBySecond = UtilsCache.CACHE_EXPIRE_TIME_DEFAULT, isKeyMD5 = false) {
|
|
1042
|
+
return new Promise(async (resolve, reject) => {
|
|
1043
|
+
let objectStore = await UtilsCache.getObjectStore();
|
|
1044
|
+
key = isKeyMD5 ? key : md5(key);
|
|
1045
|
+
try {
|
|
1046
|
+
const currentMillisecond = expireTimeBySecond === UtilsCache.CACHE_EXPIRE_NONE ? UtilsCache.CACHE_EXPIRE_NONE : (new Date().valueOf() / 1000) + expireTimeBySecond;
|
|
1047
|
+
const data = {
|
|
1048
|
+
key: key,
|
|
1049
|
+
value: encrypt(JSON.stringify({ json: value, expire: currentMillisecond })),
|
|
1050
|
+
};
|
|
1051
|
+
if (!objectStore) {
|
|
1052
|
+
return resolve(-1);
|
|
1053
|
+
}
|
|
1054
|
+
const index = objectStore.index(UtilsCache.itemIndexByKey);
|
|
1055
|
+
const getIndexKeyRequest = index.get(key);
|
|
1056
|
+
getIndexKeyRequest.onsuccess = async () => {
|
|
1057
|
+
const item = getIndexKeyRequest.result;
|
|
1058
|
+
if (item) {
|
|
1059
|
+
await UtilsCache.ClearAsync(key, true);
|
|
1060
|
+
objectStore = await UtilsCache.getObjectStore();
|
|
1061
|
+
}
|
|
1062
|
+
if (!objectStore) {
|
|
1063
|
+
return resolve(-1);
|
|
1064
|
+
}
|
|
1065
|
+
const request = objectStore.add(data);
|
|
1066
|
+
request.onsuccess = () => {
|
|
1067
|
+
resolve(request.result);
|
|
1068
|
+
};
|
|
1069
|
+
request.onerror = () => {
|
|
1070
|
+
console.log(request.error);
|
|
1071
|
+
return resolve(-1);
|
|
1072
|
+
};
|
|
1073
|
+
};
|
|
1074
|
+
getIndexKeyRequest.onerror = (event) => {
|
|
1075
|
+
console.error('Error fetching item by name:', event.target.error);
|
|
1076
|
+
reject(event.target.error);
|
|
1077
|
+
};
|
|
1078
|
+
}
|
|
1079
|
+
catch (error) {
|
|
1080
|
+
console.log(error);
|
|
1081
|
+
resolve({});
|
|
1082
|
+
}
|
|
1083
|
+
});
|
|
1084
|
+
}
|
|
1085
|
+
static Set(key, value, expireTimeBySecond = UtilsCache.CACHE_EXPIRE_TIME_DEFAULT) {
|
|
1086
|
+
if (value === undefined || value === null || value === '') {
|
|
1087
|
+
return;
|
|
1088
|
+
}
|
|
1089
|
+
const currentMillisecond = expireTimeBySecond === UtilsCache.CACHE_EXPIRE_NONE ? UtilsCache.CACHE_EXPIRE_NONE : (new Date().valueOf() / 1000) + expireTimeBySecond;
|
|
1090
|
+
const data = {
|
|
1091
|
+
value: value,
|
|
1092
|
+
expire: currentMillisecond
|
|
1093
|
+
};
|
|
1094
|
+
try {
|
|
1095
|
+
this.LocalStorage.setItem(key, encrypt(JSON.stringify(data)));
|
|
1096
|
+
}
|
|
1097
|
+
catch (error) {
|
|
1098
|
+
console.log(error);
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
static async ClearAsync(key, isMD5 = false) {
|
|
1102
|
+
return new Promise(async (resolve) => {
|
|
1103
|
+
const objectStore = await UtilsCache.getObjectStore();
|
|
1104
|
+
if (!objectStore) {
|
|
1105
|
+
return resolve({});
|
|
1106
|
+
}
|
|
1107
|
+
const index = objectStore.index(UtilsCache.itemIndexByKey);
|
|
1108
|
+
const getRequest = index.get(isMD5 ? key : md5(key));
|
|
1109
|
+
getRequest.onsuccess = () => {
|
|
1110
|
+
const result = getRequest.result;
|
|
1111
|
+
if (result) {
|
|
1112
|
+
const deleteRequest = objectStore.delete(result.id); // Xóa theo id của item tìm được
|
|
1113
|
+
deleteRequest.onsuccess = () => {
|
|
1114
|
+
resolve({});
|
|
1115
|
+
};
|
|
1116
|
+
deleteRequest.onerror = () => {
|
|
1117
|
+
resolve({});
|
|
1118
|
+
};
|
|
1119
|
+
return;
|
|
1120
|
+
}
|
|
1121
|
+
resolve({});
|
|
1122
|
+
};
|
|
1123
|
+
getRequest.onerror = () => {
|
|
1124
|
+
resolve({});
|
|
1125
|
+
};
|
|
1126
|
+
});
|
|
1127
|
+
}
|
|
1128
|
+
static Clear(key) {
|
|
1129
|
+
if (key.includes('kc-callback-')) {
|
|
1130
|
+
return;
|
|
1131
|
+
}
|
|
1132
|
+
this.LocalStorage.removeItem(key);
|
|
1133
|
+
}
|
|
1134
|
+
static ClearAllAsync() {
|
|
1135
|
+
return new Promise((resolve, reject) => {
|
|
1136
|
+
const request = indexedDB.deleteDatabase(this.dbName);
|
|
1137
|
+
request.onsuccess = () => {
|
|
1138
|
+
console.log('Database deleted successfully');
|
|
1139
|
+
resolve(true);
|
|
1140
|
+
};
|
|
1141
|
+
request.onerror = (event) => {
|
|
1142
|
+
console.error('Error deleting database:', event.target.error);
|
|
1143
|
+
reject(event.target.error);
|
|
1144
|
+
};
|
|
1145
|
+
request.onblocked = () => {
|
|
1146
|
+
console.warn('Delete request is blocked');
|
|
1147
|
+
};
|
|
1148
|
+
});
|
|
1149
|
+
}
|
|
1150
|
+
static ClearAll() {
|
|
1151
|
+
const keys = [...UtilsCache.listKeyKeepWhenClearALll];
|
|
1152
|
+
Object.keys(this.LocalStorage).forEach(key => {
|
|
1153
|
+
if (key.includes('kc-callback-')) {
|
|
1154
|
+
keys.push(key);
|
|
1155
|
+
}
|
|
1156
|
+
});
|
|
1157
|
+
const stores = UtilsCache.GetDataByKeys(Array.from(keys));
|
|
1158
|
+
this.LocalStorage.clear();
|
|
1159
|
+
UtilsCache.SetDataByKey(stores);
|
|
1160
|
+
const data = {
|
|
1161
|
+
type: UtilsCache.typeKeyClearLocalStorage,
|
|
1162
|
+
response: {
|
|
1163
|
+
idEvent: this.idService
|
|
1164
|
+
}
|
|
1165
|
+
};
|
|
1166
|
+
UtilsCommunicateMicro.PostMessageToParent(data);
|
|
1167
|
+
}
|
|
1168
|
+
static GetDataByKeys(keys) {
|
|
1169
|
+
const stores = new Map();
|
|
1170
|
+
keys.forEach((key) => {
|
|
1171
|
+
if (key.includes('kc-callback-')) {
|
|
1172
|
+
stores.set(key, this.LocalStorage.getItem(key));
|
|
1173
|
+
return;
|
|
1174
|
+
}
|
|
1175
|
+
stores.set(key, UtilsCache.Get(key));
|
|
1176
|
+
});
|
|
1177
|
+
return stores;
|
|
1178
|
+
}
|
|
1179
|
+
static SetDataByKey(stores) {
|
|
1180
|
+
stores.forEach((value, key) => {
|
|
1181
|
+
if (key.includes('kc-callback-')) {
|
|
1182
|
+
this.LocalStorage.setItem(key, value);
|
|
1183
|
+
return;
|
|
1184
|
+
}
|
|
1185
|
+
if (key === UtilsCache.languageKeyCache) {
|
|
1186
|
+
return UtilsCache.setLang(value);
|
|
1187
|
+
}
|
|
1188
|
+
UtilsCache.Set(key, value, UtilsCache.CACHE_EXPIRE_NONE);
|
|
1189
|
+
});
|
|
1190
|
+
}
|
|
1191
|
+
static DeleteKeyStartWithAsync(keyCacheStartWith, isKeyMD5 = false) {
|
|
1192
|
+
return new Promise(async (resolve) => {
|
|
1193
|
+
const objectStore = await UtilsCache.getObjectStore();
|
|
1194
|
+
if (!objectStore) {
|
|
1195
|
+
return resolve({});
|
|
1196
|
+
}
|
|
1197
|
+
const index = objectStore.index(UtilsCache.itemIndexByKey);
|
|
1198
|
+
// Lấy tất cả các keys từ index
|
|
1199
|
+
const request = index.getAll();
|
|
1200
|
+
keyCacheStartWith = isKeyMD5 ? keyCacheStartWith : md5(keyCacheStartWith);
|
|
1201
|
+
request.onsuccess = (e) => {
|
|
1202
|
+
const data = e.target.result;
|
|
1203
|
+
if (!Array.isArray(data)) {
|
|
1204
|
+
return resolve({});
|
|
1205
|
+
}
|
|
1206
|
+
data.forEach(obj => {
|
|
1207
|
+
if (obj.key.startsWith(keyCacheStartWith)) {
|
|
1208
|
+
UtilsCache.ClearAsync(obj.key, true);
|
|
1209
|
+
}
|
|
1210
|
+
});
|
|
1211
|
+
return resolve({});
|
|
1212
|
+
};
|
|
1213
|
+
request.onerror = () => {
|
|
1214
|
+
return resolve({});
|
|
1215
|
+
};
|
|
1216
|
+
});
|
|
1217
|
+
}
|
|
1218
|
+
static DeleteKeyStartWith(keyCache, isMD5 = false) {
|
|
1219
|
+
keyCache = isMD5 ? md5(keyCache) : keyCache;
|
|
1220
|
+
const keys = Object.keys(UtilsCache.LocalStorage);
|
|
1221
|
+
if (!keys || !keys.length) {
|
|
1222
|
+
return;
|
|
1223
|
+
}
|
|
1224
|
+
keys.forEach(key => {
|
|
1225
|
+
if (key.startsWith(keyCache)) {
|
|
1226
|
+
this.Clear(key);
|
|
1227
|
+
}
|
|
1228
|
+
});
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
const formatNumber = (value) => {
|
|
1233
|
+
const lang = UtilsCache.getLang();
|
|
1234
|
+
if (lang === UtilsLanguageConstants.EN) {
|
|
1235
|
+
return `${value}`.replace(/[,]/g, '');
|
|
1236
|
+
}
|
|
1237
|
+
return `${value}`.replace(/[.]/g, '').replace(/[,]/g, '.');
|
|
1238
|
+
};
|
|
1239
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1240
|
+
const viewDataNumberByLanguage = (value, acceptNegativeValue, parseFixed = 1, ignoreFormatSeparator = false, ignoreParseFloat = false) => {
|
|
1241
|
+
const lang = UtilsCache.getLang();
|
|
1242
|
+
if (!`${value}`.trim()) {
|
|
1243
|
+
return '';
|
|
1244
|
+
}
|
|
1245
|
+
if (isNil(value) || (!acceptNegativeValue && +value <= 0)) {
|
|
1246
|
+
return 0;
|
|
1247
|
+
}
|
|
1248
|
+
if (typeof value === 'string' && !ignoreFormatSeparator) {
|
|
1249
|
+
value = formatNumber(value);
|
|
1250
|
+
}
|
|
1251
|
+
const isFloat = value.toString().includes('.');
|
|
1252
|
+
const [intStr, floatStr] = value.toString().split('.');
|
|
1253
|
+
if (!floatStr?.length) {
|
|
1254
|
+
parseFixed = 0;
|
|
1255
|
+
}
|
|
1256
|
+
const round = (value, parseFixed) => {
|
|
1257
|
+
const fixed = Math.pow(10, parseFixed);
|
|
1258
|
+
return Math.round(value * fixed) / fixed;
|
|
1259
|
+
};
|
|
1260
|
+
if (parseFixed > (floatStr?.length || 0)) {
|
|
1261
|
+
const maxParseFixed = (acceptNegativeValue && +value < 0) ? 17 : 16;
|
|
1262
|
+
const fixed = maxParseFixed - (intStr?.length || 0);
|
|
1263
|
+
parseFixed = parseFixed < fixed ? parseFixed : fixed;
|
|
1264
|
+
}
|
|
1265
|
+
if (isFloat && !ignoreParseFloat) {
|
|
1266
|
+
value = parseFloat(round(+value, parseFixed).toFixed(parseFixed));
|
|
1267
|
+
}
|
|
1268
|
+
// Xử lý không format dữ liệu phần thập phân
|
|
1269
|
+
const valueString = value.toString();
|
|
1270
|
+
const index = valueString.indexOf('.');
|
|
1271
|
+
if (index !== -1 && (parseFixed > 3 || ignoreParseFloat)) {
|
|
1272
|
+
let decimalPart = valueString.substring(index + 1, valueString.length);
|
|
1273
|
+
let int = valueString.substring(0, index + 1);
|
|
1274
|
+
if (ignoreParseFloat) {
|
|
1275
|
+
decimalPart = decimalPart.substring(0, parseFixed);
|
|
1276
|
+
}
|
|
1277
|
+
if (lang === UtilsLanguageConstants.EN) {
|
|
1278
|
+
int = int.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
1279
|
+
return `${int}${decimalPart}`;
|
|
1280
|
+
}
|
|
1281
|
+
int = int.replace('.', ',').replace(/\B(?=(\d{3})+(?!\d))/g, '.');
|
|
1282
|
+
return `${int}${decimalPart}`;
|
|
1283
|
+
}
|
|
1284
|
+
if (index === -1 || parseFixed <= 3) {
|
|
1285
|
+
if (lang === UtilsLanguageConstants.EN) {
|
|
1286
|
+
return value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
1287
|
+
}
|
|
1288
|
+
return value.toString().replace('.', ',').replace(/\B(?=(\d{3})+(?!\d))/g, '.');
|
|
1289
|
+
}
|
|
1290
|
+
};
|
|
1291
|
+
|
|
1292
|
+
const emojiPattern = () => {
|
|
1293
|
+
return /(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])/g;
|
|
1294
|
+
};
|
|
1295
|
+
const removeEmoji = (text) => {
|
|
1296
|
+
if (!text || !text.trim()) {
|
|
1297
|
+
return text;
|
|
1298
|
+
}
|
|
1299
|
+
return text.replace(emojiPattern(), '');
|
|
1300
|
+
};
|
|
1301
|
+
|
|
1302
|
+
const escapeHtml = (data) => {
|
|
1303
|
+
if (!data || typeof data !== 'string') {
|
|
1304
|
+
return data;
|
|
1305
|
+
}
|
|
1306
|
+
return data
|
|
1307
|
+
.replace(/&/g, "&")
|
|
1308
|
+
.replace(/</g, "<")
|
|
1309
|
+
.replace(/>/g, ">")
|
|
1310
|
+
.replace(/"/g, """)
|
|
1311
|
+
.replace(/'/g, "'");
|
|
1312
|
+
};
|
|
1313
|
+
|
|
1314
|
+
const deleteUnicode = (str) => {
|
|
1315
|
+
str = str.replace(/à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ/g, 'a');
|
|
1316
|
+
str = str.replace(/è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ|ễ/g, 'e');
|
|
1317
|
+
str = str.replace(/ì|í|ị|ỉ|ĩ/g, 'i');
|
|
1318
|
+
str = str.replace(/ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ/g, 'o');
|
|
1319
|
+
str = str.replace(/ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ/g, 'u');
|
|
1320
|
+
str = str.replace(/ỳ|ý|ỵ|ỷ|ỹ/g, 'y');
|
|
1321
|
+
str = str.replace(/đ/g, 'd');
|
|
1322
|
+
str = str.replace(/À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẵ/g, 'A');
|
|
1323
|
+
str = str.replace(/È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ/g, 'E');
|
|
1324
|
+
str = str.replace(/Ì|Í|Ị|Ỉ|Ĩ/g, 'I');
|
|
1325
|
+
str = str.replace(/Ò|Ó|Ọ|Ỏ|Õ|Ô|Ồ|Ố|Ộ|Ổ|Ỗ|Ơ|Ờ|Ớ|Ợ|Ở|Ỡ/g, 'O');
|
|
1326
|
+
str = str.replace(/Ù|Ú|Ụ|Ủ|Ũ|Ư|Ừ|Ứ|Ự|Ử|Ữ/g, 'U');
|
|
1327
|
+
str = str.replace(/Ỳ|Ý|Ỵ|Ỷ|Ỹ/g, 'Y');
|
|
1328
|
+
str = str.replace(/Đ/g, 'D');
|
|
1329
|
+
str = str.replace(/\u0300|\u0301|\u0303|\u0309|\u0323/g, ""); // ̀ ́ ̃ ̉ ̣ huyền, sắc, ngã, hỏi, nặng
|
|
1330
|
+
str = str.replace(/\u02C6|\u0306|\u031B/g, ""); // ˆ ̆ ̛ Â, Ê, Ă, Ơ, Ư
|
|
1331
|
+
return str.normalize();
|
|
1332
|
+
};
|
|
1333
|
+
|
|
1334
|
+
const listColorDefine = ['#E62222', '#B81B1B', '#EB4E4E', '#F97316', '#C75C12', '#FA8F45', '#FFB700', '#CC9200', '#FFC533', '#84CC16', '#6AA312', '#9dd645', '#00BC62', '#00A757', '#33DA8A', '#06B6D4', '#1B59C4', '#4E8CF7', '#0EA5E9',
|
|
1335
|
+
'#1B59C4', '#4E8CF7', '#226FF5', '#1B59C4', '#4E8CF7', '#6366F1', '#4F52C1', '#8285F4', '#5B04B3', '#49038F', '#7C36C2', '#D946EF', '#AE38BF', '#E16BF2', '#EC4899', '#BD3A7A', '#F06DAD', '#F43F5E', '#C3324B', '#F6657E', '#757380', '#5E5C66', '#918F99',
|
|
1336
|
+
'#202020', '#1A1A1A', '#4D4D4D'
|
|
1337
|
+
];
|
|
1338
|
+
const getColorById = (str) => {
|
|
1339
|
+
let hashString = 0;
|
|
1340
|
+
if (!str) {
|
|
1341
|
+
return '';
|
|
1342
|
+
}
|
|
1343
|
+
for (let i = 0; i < str.length; i++) {
|
|
1344
|
+
const char = str.charCodeAt(i);
|
|
1345
|
+
hashString = ((hashString << 5) - hashString) + char;
|
|
1346
|
+
hashString = hashString & hashString;
|
|
1347
|
+
}
|
|
1348
|
+
return listColorDefine[Math.abs(hashString) % listColorDefine.length];
|
|
1349
|
+
};
|
|
1350
|
+
|
|
1351
|
+
const ERROR_MESSAGE_EMPTY_VALID = 'i18n_valid_empty_message';
|
|
1352
|
+
const ERROR_MESSAGE_PATTEN_VALID = 'i18n_valid_pattern_message';
|
|
1353
|
+
const ERROR_MESSAGE_MIN_VALID = 'i18n_message_error_input_min_value';
|
|
1354
|
+
const ERROR_MESSAGE_MAX_VALID = 'i18n_message_error_input_max_value';
|
|
1355
|
+
const ERROR_MESSAGE_MIN_LENGTH = 'i18n_message_error_input_min_length';
|
|
1356
|
+
const ERROR_MESSAGE_MAX_LENGTH = 'i18n_message_error_input_max_length';
|
|
1357
|
+
const CHARACTER_DATA_EMPTY = '__';
|
|
1358
|
+
|
|
1359
|
+
/* eslint-disable no-useless-escape */
|
|
1360
|
+
const PATTERN_EMAIL = () => {
|
|
1361
|
+
return /^[A-z0-9]+[A-z0-9\_\.\+\-]*[A-z0-9]@[A-z0-9]+[A-z0-9\_\.\+\-]*[A-z0-9]\.[A-z0-9]+[A-z0-9\_\.\+\-]*[A-z0-9]$/;
|
|
1362
|
+
};
|
|
1363
|
+
const PATTERN_URL = () => {
|
|
1364
|
+
return /^(http|https|ftp):(\/){2}[^\s]+[.]{1}[^\s]+$/;
|
|
1365
|
+
};
|
|
1366
|
+
const PATTERN_HOST_URL = () => {
|
|
1367
|
+
return /^((https|http|ftp):[/]{2}[^/\s]+)/;
|
|
1368
|
+
};
|
|
1369
|
+
const PATTERN_DOMAIN = () => {
|
|
1370
|
+
return /^([a-zA-Z0-9])(([a-z0-9-]{1,61})?[a-z0-9]{1})?(\.[a-z0-9](([a-z0-9-]{1,61})?[a-z0-9]{1})?)?(\.[a-zA-Z]{2,4})+$/;
|
|
1371
|
+
};
|
|
1372
|
+
const PATTERN_MOBILE_PHONE = () => {
|
|
1373
|
+
return /^(\+?84|0|84)([0-9]{9})$/;
|
|
1374
|
+
};
|
|
1375
|
+
const PATTERN_PHONE = () => {
|
|
1376
|
+
return /^(\+?84|[0-9]|84)([0-9]{2,9})$/;
|
|
1377
|
+
};
|
|
1378
|
+
const PATTERN_PHONE_NORMAL = () => {
|
|
1379
|
+
return /^(\+?84|[0-9]|84)([0-9]{9,10})$/;
|
|
1380
|
+
};
|
|
1381
|
+
const PATTERN_NUMBER = () => {
|
|
1382
|
+
return /\d+/g;
|
|
1383
|
+
};
|
|
1384
|
+
const PATTERN_ENCODE_URI = () => {
|
|
1385
|
+
return /%([0-9A-F]{2})/g;
|
|
1386
|
+
};
|
|
1387
|
+
const PATTERN_NAME = () => {
|
|
1388
|
+
return /^\w+[A-Za-z\s\d]+$/;
|
|
1389
|
+
};
|
|
1390
|
+
const PATTERN_NAME_UTF8 = () => {
|
|
1391
|
+
return /^[ àáảãạăắằẵặẳâầấậẫẩđèéẻẽẹêềếểễệìíỉĩịòóỏõọôồốổỗộơờớởỡợùúủũụưừứửữựỳýỷỹÀÁẢÃẠĂẮẰẴẶẲÂẦẤẬẪẨĐÈÉẺẼẸÊỀẾỂỄỆÌÍỈĨỊÒÓỎÕỌÔỒỐỔỖỘƠỜỚỞỠỢÙÚỦŨỤƯỪỨỬỮỰỲÝỶỸA-Za-z0-9]+$/;
|
|
1392
|
+
};
|
|
1393
|
+
const PATTERN_NAME_SPECIAL = () => {
|
|
1394
|
+
return /[~!@#$%^&*()-+=<>,?\/\\:;"']/;
|
|
1395
|
+
};
|
|
1396
|
+
const PATTERN_NAME_PROFILE = () => {
|
|
1397
|
+
return /([\w\W\d\s]+)+/;
|
|
1398
|
+
};
|
|
1399
|
+
const PATTERN_EMOJI = () => {
|
|
1400
|
+
return /(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])/g;
|
|
1401
|
+
};
|
|
1402
|
+
const PATTERN_RULE_FIELD_REPLACE = () => {
|
|
1403
|
+
return /[{]{2}[a-zA-Z_-]+[}]{2}/g;
|
|
1404
|
+
};
|
|
1405
|
+
const PATTERN_GET_FIELD_BY_RULE_FIELD_REPLACE = () => {
|
|
1406
|
+
return /[a-zA-Z_-]+/g;
|
|
1407
|
+
};
|
|
1408
|
+
const PATTERN_PEM = () => {
|
|
1409
|
+
return /^(0|1):([0-9]{1,2}):(\{\{path-api\}\}):([a-zA-Z0-9\/]+)$/g;
|
|
1410
|
+
};
|
|
1411
|
+
const PATTERN_TAX = () => {
|
|
1412
|
+
return /^([0-9]){10}(-[0-9]{3})?$/;
|
|
1413
|
+
};
|
|
1414
|
+
const PATTERN_KEY = () => {
|
|
1415
|
+
return /^([0-9]){10}(-[0-9]{3})?$/;
|
|
1416
|
+
};
|
|
1417
|
+
const PATTERN_ACCOUNT = () => {
|
|
1418
|
+
return /^(?=.*@)[a-z0-9@._-]{2,63}$/;
|
|
1419
|
+
};
|
|
1420
|
+
|
|
1421
|
+
/**
|
|
1422
|
+
* Generated bundle index. Do not edit.
|
|
1423
|
+
*/
|
|
1424
|
+
|
|
1425
|
+
export { CHARACTER_DATA_EMPTY, ERROR_MESSAGE_EMPTY_VALID, ERROR_MESSAGE_MAX_LENGTH, ERROR_MESSAGE_MAX_VALID, ERROR_MESSAGE_MIN_LENGTH, ERROR_MESSAGE_MIN_VALID, ERROR_MESSAGE_PATTEN_VALID, GetColorById, HttpParamsRequestInstance, PATTERN_ACCOUNT, PATTERN_DOMAIN, PATTERN_EMAIL, PATTERN_EMOJI, PATTERN_ENCODE_URI, PATTERN_GET_FIELD_BY_RULE_FIELD_REPLACE, PATTERN_HOST_URL, PATTERN_KEY, PATTERN_MOBILE_PHONE, PATTERN_NAME, PATTERN_NAME_PROFILE, PATTERN_NAME_SPECIAL, PATTERN_NAME_UTF8, PATTERN_NUMBER, PATTERN_PEM, PATTERN_PHONE, PATTERN_PHONE_NORMAL, PATTERN_RULE_FIELD_REPLACE, PATTERN_TAX, PATTERN_URL, UtilsCache, UtilsCommunicateMicro, UtilsHttpParamsRequest, UtilsKeyCodeConstant, UtilsLanguageConstants, UtilsUrlSearchParams, checkMouseOverInContainer, checkViewInScreen, cloneDeep, cloneIBoundingClientRect, colorContrastFromOrigin, colorStepContrastFromOrigin, decrypt, decrypt3rd, deleteUnicode, emojiPattern, encrypt, encrypt3rd, escapeHtml, formatNumber, generateInterface, get, getColorById, getKeyCacheByArrayObject, getPlatFromBrowser, getViewport, isEmbedFrame, isEmpty, isNil, listColorDefine$1 as listColorDefine, md5, removeEmoji, rgbToHex, set, setCaretPosition, setKeyCrypto, setKeyCrypto3rd, setStyles, updateFunctionCheckEmbedFrame, uuid, viewDataNumberByLanguage };
|
|
1426
|
+
//# sourceMappingURL=libs-ui-utils.mjs.map
|