@libs-ui/utils 0.2.306-4 → 0.2.306-6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/communicate-micro.d.ts +1 -1
- package/date.d.ts +14 -19
- package/dom.d.ts +4 -4
- package/esm2022/base64.mjs +2 -2
- package/esm2022/cache.mjs +17 -14
- package/esm2022/color.mjs +66 -14
- package/esm2022/communicate-micro.mjs +20 -16
- package/esm2022/constants.mjs +1 -1
- package/esm2022/crypto-3rd.mjs +3 -3
- package/esm2022/crypto.mjs +3 -3
- package/esm2022/date.mjs +24 -22
- package/esm2022/dom.mjs +8 -16
- package/esm2022/download.mjs +3 -3
- package/esm2022/file.mjs +22 -11
- package/esm2022/format-number.mjs +9 -6
- package/esm2022/format-text.mjs +13 -15
- package/esm2022/function-check-embed-frame.mjs +1 -1
- package/esm2022/get-smart-axis-scale.mjs +10 -10
- package/esm2022/helpers.mjs +11 -9
- package/esm2022/http-params.mjs +2 -2
- package/esm2022/index.mjs +1 -1
- package/esm2022/inject-token.mjs +2 -2
- package/esm2022/key-cache.mjs +6 -6
- package/esm2022/key-code.mjs +1 -1
- package/esm2022/language.mjs +28 -28
- package/esm2022/pattern.mjs +1 -1
- package/esm2022/random.mjs +2 -2
- package/esm2022/two-way-signal-object.mjs +22 -10
- package/esm2022/uri.mjs +9 -6
- package/esm2022/url-search-params.mjs +13 -11
- package/esm2022/uuid.mjs +2 -2
- package/esm2022/xss-filter.mjs +1 -1
- package/fesm2022/libs-ui-utils.mjs +238 -154
- package/fesm2022/libs-ui-utils.mjs.map +1 -1
- package/file.d.ts +1 -1
- package/format-text.d.ts +1 -1
- package/helpers.d.ts +3 -3
- package/http-params.d.ts +1 -1
- package/inject-token.d.ts +1 -1
- package/package.json +2 -2
- package/uri.d.ts +1 -1
|
@@ -90,7 +90,7 @@ const highlightByKeyword = (value, search, ignoreHighlight, classHightLight) =>
|
|
|
90
90
|
if (!classHightLight) {
|
|
91
91
|
classHightLight = 'bg-[#19344a] text-white';
|
|
92
92
|
}
|
|
93
|
-
keysReplace.forEach(key => {
|
|
93
|
+
keysReplace.forEach((key) => {
|
|
94
94
|
const regExp = new RegExp(key, 'gi');
|
|
95
95
|
value = value?.replace(regExp, `<span class="${classHightLight}">$&</span>`);
|
|
96
96
|
});
|
|
@@ -119,7 +119,7 @@ const formatTextCompare = (text, options) => {
|
|
|
119
119
|
if (!text) {
|
|
120
120
|
return text;
|
|
121
121
|
}
|
|
122
|
-
text = text.normalize(
|
|
122
|
+
text = text.normalize('NFC');
|
|
123
123
|
return formatByOptions(text, options);
|
|
124
124
|
};
|
|
125
125
|
const fullNameFormat = (value) => {
|
|
@@ -133,7 +133,10 @@ const capitalize = (text, options) => {
|
|
|
133
133
|
return text;
|
|
134
134
|
}
|
|
135
135
|
text = formatByOptions(text, options);
|
|
136
|
-
return text
|
|
136
|
+
return text
|
|
137
|
+
.split(' ')
|
|
138
|
+
.map((word) => firstLetterToUpperCase(word))
|
|
139
|
+
.join(' ');
|
|
137
140
|
};
|
|
138
141
|
const firstLetterToUpperCase = (text, options) => {
|
|
139
142
|
if (!text) {
|
|
@@ -159,7 +162,7 @@ const formatByOptions = (text, options) => {
|
|
|
159
162
|
text = text.toLowerCase();
|
|
160
163
|
}
|
|
161
164
|
if (options?.removeMultipleSpace) {
|
|
162
|
-
text = text.replace(/\u200B|\u00A0/g,
|
|
165
|
+
text = text.replace(/\u200B|\u00A0/g, '');
|
|
163
166
|
text = text.replace(/\s+/g, ' ');
|
|
164
167
|
}
|
|
165
168
|
if (options?.removeEmoji) {
|
|
@@ -177,12 +180,7 @@ const escapeHtml = (str) => {
|
|
|
177
180
|
if (!str || typeof str !== 'string') {
|
|
178
181
|
return str;
|
|
179
182
|
}
|
|
180
|
-
return str
|
|
181
|
-
.replace(/&/g, "&")
|
|
182
|
-
.replace(/</g, "<")
|
|
183
|
-
.replace(/>/g, ">")
|
|
184
|
-
.replace(/"/g, """)
|
|
185
|
-
.replace(/'/g, "'");
|
|
183
|
+
return str.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''');
|
|
186
184
|
};
|
|
187
185
|
const decodeEscapeHtml = (str) => {
|
|
188
186
|
const htmlTag = document.createElement('textarea');
|
|
@@ -213,9 +211,9 @@ const deleteUnicode = (str) => {
|
|
|
213
211
|
str = str.replace(/Ù|Ú|Ụ|Ủ|Ũ|Ư|Ừ|Ứ|Ự|Ử|Ữ/g, 'U');
|
|
214
212
|
str = str.replace(/Ỳ|Ý|Ỵ|Ỷ|Ỹ/g, 'Y');
|
|
215
213
|
str = str.replace(/Đ/g, 'D');
|
|
216
|
-
str = str.replace(/\u0300|\u0301|\u0303|\u0309|\u0323/g,
|
|
217
|
-
str = str.replace(/\u02C6|\u0306|\u031B/g,
|
|
218
|
-
return str.normalize(
|
|
214
|
+
str = str.replace(/\u0300|\u0301|\u0303|\u0309|\u0323/g, ''); // ̀ ́ ̃ ̉ ̣ huyền, sắc, ngã, hỏi, nặng
|
|
215
|
+
str = str.replace(/\u02C6|\u0306|\u031B/g, ''); // ˆ ̆ ̛ Â, Ê, Ă, Ơ, Ư
|
|
216
|
+
return str.normalize('NFC');
|
|
219
217
|
};
|
|
220
218
|
const removeEmoji = (text) => {
|
|
221
219
|
if (!text || !text.trim()) {
|
|
@@ -290,10 +288,7 @@ const checkViewInScreen = (container, element, elementScroll, maxTopLeft) => {
|
|
|
290
288
|
const limitLeft = leftContainer + scrollLeftContainer + widthContainer;
|
|
291
289
|
const maxTopItem = top + (maxTopLeft?.top || 0);
|
|
292
290
|
const maxLeftItem = left + (maxTopLeft?.left || 0);
|
|
293
|
-
if (topContainer <= maxTopItem &&
|
|
294
|
-
maxTopItem <= limitTop &&
|
|
295
|
-
leftContainer <= maxLeftItem &&
|
|
296
|
-
maxLeftItem <= limitLeft) {
|
|
291
|
+
if (topContainer <= maxTopItem && maxTopItem <= limitTop && leftContainer <= maxLeftItem && maxLeftItem <= limitLeft) {
|
|
297
292
|
return true;
|
|
298
293
|
}
|
|
299
294
|
return false;
|
|
@@ -307,10 +302,7 @@ const checkMouseOverInContainer = (mousePosition, element, rect) => {
|
|
|
307
302
|
const limitLeft = left + width;
|
|
308
303
|
const limitTop = top + height;
|
|
309
304
|
const { clientX, clientY } = mousePosition;
|
|
310
|
-
if (left <= clientX &&
|
|
311
|
-
clientX <= limitLeft &&
|
|
312
|
-
top <= clientY &&
|
|
313
|
-
clientY <= limitTop) {
|
|
305
|
+
if (left <= clientX && clientX <= limitLeft && top <= clientY && clientY <= limitTop) {
|
|
314
306
|
return true;
|
|
315
307
|
}
|
|
316
308
|
return false;
|
|
@@ -348,13 +340,11 @@ const getDragEventByElement = (config) => {
|
|
|
348
340
|
e.stopPropagation();
|
|
349
341
|
config.functionMouseMove?.(e);
|
|
350
342
|
}), takeUntil(mouseup));
|
|
351
|
-
return mouseDown.pipe(mergeMap((e) => config.isStartWithMouseDownEvent
|
|
352
|
-
? mousemove.pipe(startWith(e))
|
|
353
|
-
: mousemove), takeUntil(config.onDestroy), finalize(removeClass));
|
|
343
|
+
return mouseDown.pipe(mergeMap((e) => (config.isStartWithMouseDownEvent ? mousemove.pipe(startWith(e)) : mousemove)), takeUntil(config.onDestroy), finalize(removeClass));
|
|
354
344
|
};
|
|
355
345
|
const getHTMLFromQuill = async (data, options) => {
|
|
356
346
|
const { replaceNewLineTo = '<br>', replaceTagBRTo, replaceTags, replaceBrToDiv } = options || {};
|
|
357
|
-
const delta =
|
|
347
|
+
const delta = typeof data === 'string' ? await getDeltaFromHTML(data) : data;
|
|
358
348
|
if (options?.functionReplaceDelta) {
|
|
359
349
|
options.functionReplaceDelta(delta);
|
|
360
350
|
}
|
|
@@ -498,17 +488,19 @@ class UtilsUrlSearchParams {
|
|
|
498
488
|
return this.instance;
|
|
499
489
|
}
|
|
500
490
|
static toStringParamObject(params) {
|
|
501
|
-
const paramsArr = Object.keys(params).map(key => {
|
|
491
|
+
const paramsArr = Object.keys(params).map((key) => {
|
|
502
492
|
return {
|
|
503
493
|
key,
|
|
504
|
-
value: params[key]
|
|
494
|
+
value: params[key],
|
|
505
495
|
};
|
|
506
496
|
});
|
|
507
497
|
return UtilsUrlSearchParams.ToString(paramsArr);
|
|
508
498
|
}
|
|
509
499
|
static ToString(params) {
|
|
510
500
|
let paramsStr = '';
|
|
511
|
-
params
|
|
501
|
+
params
|
|
502
|
+
.sort((item1, item2) => item1.key.localeCompare(item2.key))
|
|
503
|
+
.forEach((item) => {
|
|
512
504
|
const { key, value } = item;
|
|
513
505
|
paramsStr = `${paramsStr}${paramsStr ? '&' : ''}${key}=${value}`;
|
|
514
506
|
});
|
|
@@ -525,14 +517,14 @@ class UtilsUrlSearchParams {
|
|
|
525
517
|
}
|
|
526
518
|
const params = paramString.replace(/\S+[?]/g, '').split('&');
|
|
527
519
|
if (params) {
|
|
528
|
-
params.forEach(param => {
|
|
520
|
+
params.forEach((param) => {
|
|
529
521
|
if (param.indexOf('=') < 0) {
|
|
530
522
|
return;
|
|
531
523
|
}
|
|
532
524
|
let [key, value] = param.split('=');
|
|
533
525
|
key = key.replace(/[?&]+/g, '');
|
|
534
526
|
value = decodeURIComponent(value.replace(/\+/g, ' '));
|
|
535
|
-
if (!paramsBuild.some(param => param.key === key)) {
|
|
527
|
+
if (!paramsBuild.some((param) => param.key === key)) {
|
|
536
528
|
paramsBuild.push({ key, value });
|
|
537
529
|
}
|
|
538
530
|
});
|
|
@@ -540,7 +532,7 @@ class UtilsUrlSearchParams {
|
|
|
540
532
|
return paramsBuild;
|
|
541
533
|
}
|
|
542
534
|
set(key, value) {
|
|
543
|
-
const paramByKey = this.params.find(param => param.key === key);
|
|
535
|
+
const paramByKey = this.params.find((param) => param.key === key);
|
|
544
536
|
if (!paramByKey) {
|
|
545
537
|
this.params.push({ key, value: decodeURIComponent(value.replace(/\+/g, ' ')) });
|
|
546
538
|
return;
|
|
@@ -548,13 +540,13 @@ class UtilsUrlSearchParams {
|
|
|
548
540
|
paramByKey['value'] = value;
|
|
549
541
|
}
|
|
550
542
|
get(key) {
|
|
551
|
-
return this.params.find(param => param.key === key)?.value;
|
|
543
|
+
return this.params.find((param) => param.key === key)?.value;
|
|
552
544
|
}
|
|
553
545
|
has(key) {
|
|
554
|
-
return this.params.some(param => param.key === key);
|
|
546
|
+
return this.params.some((param) => param.key === key);
|
|
555
547
|
}
|
|
556
548
|
delete(key) {
|
|
557
|
-
const index = this.params.findIndex(param => param.key === key);
|
|
549
|
+
const index = this.params.findIndex((param) => param.key === key);
|
|
558
550
|
if (index >= 0) {
|
|
559
551
|
this.params.splice(index, 1);
|
|
560
552
|
}
|
|
@@ -568,7 +560,7 @@ class UtilsUrlSearchParams {
|
|
|
568
560
|
}
|
|
569
561
|
getParamObject() {
|
|
570
562
|
const params = {};
|
|
571
|
-
this.params.forEach(item => {
|
|
563
|
+
this.params.forEach((item) => {
|
|
572
564
|
params[item.key] = item.value;
|
|
573
565
|
});
|
|
574
566
|
return params;
|
|
@@ -596,7 +588,7 @@ const keyStore$1 = () => {
|
|
|
596
588
|
};
|
|
597
589
|
const encrypt = (plainData) => {
|
|
598
590
|
if (!keyStore$1()) {
|
|
599
|
-
throw Error(
|
|
591
|
+
throw Error('lỗi chưa setup key mã hóa');
|
|
600
592
|
}
|
|
601
593
|
const key = CryptoES.enc.Hex.parse(keyStore$1());
|
|
602
594
|
const iv = CryptoES.enc.Hex.parse(keyStore$1());
|
|
@@ -607,7 +599,7 @@ const encrypt = (plainData) => {
|
|
|
607
599
|
};
|
|
608
600
|
const decrypt = (encryptedData) => {
|
|
609
601
|
if (!keyStore$1()) {
|
|
610
|
-
throw Error(
|
|
602
|
+
throw Error('lỗi chưa setup key mã hóa');
|
|
611
603
|
}
|
|
612
604
|
const key = CryptoES.enc.Hex.parse(keyStore$1());
|
|
613
605
|
const iv = CryptoES.enc.Hex.parse(keyStore$1());
|
|
@@ -653,7 +645,7 @@ const keyStore = () => {
|
|
|
653
645
|
};
|
|
654
646
|
const encrypt3rd = (plainData) => {
|
|
655
647
|
if (!keyStore()) {
|
|
656
|
-
throw Error(
|
|
648
|
+
throw Error('lỗi chưa setup key mã hóa');
|
|
657
649
|
}
|
|
658
650
|
const key = CryptoES.enc.Hex.parse(keyStore());
|
|
659
651
|
const iv = CryptoES.enc.Hex.parse(keyStore());
|
|
@@ -664,7 +656,7 @@ const encrypt3rd = (plainData) => {
|
|
|
664
656
|
};
|
|
665
657
|
const decrypt3rd = (encryptedData) => {
|
|
666
658
|
if (!keyStore()) {
|
|
667
|
-
throw Error(
|
|
659
|
+
throw Error('lỗi chưa setup key mã hóa');
|
|
668
660
|
}
|
|
669
661
|
const key = CryptoES.enc.Hex.parse(keyStore());
|
|
670
662
|
const iv = CryptoES.enc.Hex.parse(keyStore());
|
|
@@ -711,7 +703,9 @@ class UtilsCommunicateMicro {
|
|
|
711
703
|
if (!this.subs.get(COMMUNICATE_MICRO_KEY_GET_ALL_MESSAGE)) {
|
|
712
704
|
this.subs.set(COMMUNICATE_MICRO_KEY_GET_ALL_MESSAGE, UtilsCommunicateMicro.allMessageSub);
|
|
713
705
|
}
|
|
714
|
-
fromEvent(currentWindow, 'message')
|
|
706
|
+
fromEvent(currentWindow, 'message')
|
|
707
|
+
.pipe(takeUntil(onDestroy))
|
|
708
|
+
.subscribe((e) => {
|
|
715
709
|
const event = { data: { ...e.data } };
|
|
716
710
|
const data = event.data;
|
|
717
711
|
const type = data.type;
|
|
@@ -739,7 +733,9 @@ class UtilsCommunicateMicro {
|
|
|
739
733
|
this.allMessageSub.next(event);
|
|
740
734
|
}
|
|
741
735
|
});
|
|
742
|
-
UtilsCommunicateMicro.GetMessage(UtilsCache.typeKeyClearLocalStorage)
|
|
736
|
+
UtilsCommunicateMicro.GetMessage(UtilsCache.typeKeyClearLocalStorage)
|
|
737
|
+
.pipe(filter((e) => e.data.response !== UtilsCache.idService), takeUntil(onDestroy))
|
|
738
|
+
.subscribe(() => {
|
|
743
739
|
console.log('clear all cache by event');
|
|
744
740
|
UtilsCache.ClearAll();
|
|
745
741
|
});
|
|
@@ -748,10 +744,10 @@ class UtilsCommunicateMicro {
|
|
|
748
744
|
data = this.convertData(data);
|
|
749
745
|
try {
|
|
750
746
|
if (isEmbedFrame()) {
|
|
751
|
-
window?.parent?.postMessage(data,
|
|
747
|
+
window?.parent?.postMessage(data, '*');
|
|
752
748
|
return;
|
|
753
749
|
}
|
|
754
|
-
window?.top?.postMessage(data,
|
|
750
|
+
window?.top?.postMessage(data, '*');
|
|
755
751
|
}
|
|
756
752
|
catch (error) {
|
|
757
753
|
console.log(error);
|
|
@@ -759,8 +755,8 @@ class UtilsCommunicateMicro {
|
|
|
759
755
|
}
|
|
760
756
|
static PostMessageToChildren(data) {
|
|
761
757
|
data = this.convertData(data);
|
|
762
|
-
const iframes = document.querySelectorAll(
|
|
763
|
-
Array.from(iframes).forEach(iframe => {
|
|
758
|
+
const iframes = document.querySelectorAll('iframe');
|
|
759
|
+
Array.from(iframes).forEach((iframe) => {
|
|
764
760
|
iframe?.contentWindow?.postMessage(data, '*');
|
|
765
761
|
});
|
|
766
762
|
}
|
|
@@ -798,7 +794,7 @@ class UtilsCommunicateMicro {
|
|
|
798
794
|
}
|
|
799
795
|
static GetMessage(messageType) {
|
|
800
796
|
if (!this.initdEvent) {
|
|
801
|
-
throw Error(
|
|
797
|
+
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');
|
|
802
798
|
}
|
|
803
799
|
if (typeof messageType === 'string') {
|
|
804
800
|
let sub = this.subs.get(messageType);
|
|
@@ -826,8 +822,8 @@ class UtilsCommunicateMicro {
|
|
|
826
822
|
return sub;
|
|
827
823
|
}
|
|
828
824
|
static initSubject(subRoot, messageType) {
|
|
829
|
-
messageType.forEach(key => {
|
|
830
|
-
this.GetMessage(key).subscribe(e => {
|
|
825
|
+
messageType.forEach((key) => {
|
|
826
|
+
this.GetMessage(key).subscribe((e) => {
|
|
831
827
|
subRoot.next(e);
|
|
832
828
|
});
|
|
833
829
|
});
|
|
@@ -835,33 +831,33 @@ class UtilsCommunicateMicro {
|
|
|
835
831
|
}
|
|
836
832
|
|
|
837
833
|
class UtilsLanguageConstants {
|
|
838
|
-
static VI =
|
|
839
|
-
static EN =
|
|
840
|
-
static FR =
|
|
841
|
-
static DE =
|
|
842
|
-
static ES =
|
|
843
|
-
static ZH =
|
|
844
|
-
static ZH_TW =
|
|
845
|
-
static JA =
|
|
846
|
-
static KO =
|
|
847
|
-
static RU =
|
|
848
|
-
static IT =
|
|
849
|
-
static PT =
|
|
850
|
-
static TH =
|
|
851
|
-
static ID =
|
|
852
|
-
static MS =
|
|
853
|
-
static AR =
|
|
854
|
-
static HI =
|
|
855
|
-
static BN =
|
|
856
|
-
static TR =
|
|
857
|
-
static NL =
|
|
858
|
-
static KM =
|
|
859
|
-
static LO =
|
|
860
|
-
static MY =
|
|
861
|
-
static TL =
|
|
862
|
-
static CEB =
|
|
863
|
-
static JV =
|
|
864
|
-
static SU =
|
|
834
|
+
static VI = 'vi'; // Tiếng Việt
|
|
835
|
+
static EN = 'en'; // Tiếng Anh
|
|
836
|
+
static FR = 'fr'; // Tiếng Pháp
|
|
837
|
+
static DE = 'de'; // Tiếng Đức
|
|
838
|
+
static ES = 'es'; // Tiếng Tây Ban Nha
|
|
839
|
+
static ZH = 'zh'; // Tiếng Trung (Giản thể)
|
|
840
|
+
static ZH_TW = 'zh-TW'; // Tiếng Trung (Phồn thể)
|
|
841
|
+
static JA = 'ja'; // Tiếng Nhật
|
|
842
|
+
static KO = 'ko'; // Tiếng Hàn
|
|
843
|
+
static RU = 'ru'; // Tiếng Nga
|
|
844
|
+
static IT = 'it'; // Tiếng Ý
|
|
845
|
+
static PT = 'pt'; // Tiếng Bồ Đào Nha
|
|
846
|
+
static TH = 'th'; // Tiếng Thái
|
|
847
|
+
static ID = 'id'; // Tiếng Indonesia
|
|
848
|
+
static MS = 'ms'; // Tiếng Malaysia
|
|
849
|
+
static AR = 'ar'; // Tiếng Ả Rập
|
|
850
|
+
static HI = 'hi'; // Tiếng Hindi
|
|
851
|
+
static BN = 'bn'; // Tiếng Bengal
|
|
852
|
+
static TR = 'tr'; // Tiếng Thổ Nhĩ Kỳ
|
|
853
|
+
static NL = 'nl'; // Tiếng Hà Lan
|
|
854
|
+
static KM = 'km'; // Tiếng Khmer (Campuchia)
|
|
855
|
+
static LO = 'lo'; // Tiếng Lào
|
|
856
|
+
static MY = 'my'; // Tiếng Miến Điện (Myanmar)
|
|
857
|
+
static TL = 'tl'; // Tiếng Tagalog (Philippines)
|
|
858
|
+
static CEB = 'ceb'; // Tiếng Cebuano (Philippines)
|
|
859
|
+
static JV = 'jv'; // Tiếng Java (Indonesia)
|
|
860
|
+
static SU = 'su'; // Tiếng Sundanese (Indonesia)
|
|
865
861
|
// Ngôn ngữ mặc định
|
|
866
862
|
static defaultLang = UtilsLanguageConstants.VI;
|
|
867
863
|
// Danh sách các ngôn ngữ được hỗ trợ
|
|
@@ -947,7 +943,7 @@ class UtilsCache {
|
|
|
947
943
|
return this.Get(this.languageKeyCache, UtilsLanguageConstants.defaultLang);
|
|
948
944
|
}
|
|
949
945
|
static openDB() {
|
|
950
|
-
return new Promise(resolve => {
|
|
946
|
+
return new Promise((resolve) => {
|
|
951
947
|
const request = indexedDB.open(this.dbName, this.dbVersion);
|
|
952
948
|
request.onupgradeneeded = (event) => {
|
|
953
949
|
const db = event.target.result;
|
|
@@ -1019,7 +1015,7 @@ class UtilsCache {
|
|
|
1019
1015
|
clear: () => {
|
|
1020
1016
|
this.storage = {};
|
|
1021
1017
|
localStorage.clear();
|
|
1022
|
-
}
|
|
1018
|
+
},
|
|
1023
1019
|
};
|
|
1024
1020
|
}
|
|
1025
1021
|
static getLocalStorageFake() {
|
|
@@ -1038,7 +1034,7 @@ class UtilsCache {
|
|
|
1038
1034
|
},
|
|
1039
1035
|
clear: () => {
|
|
1040
1036
|
this.storage = {};
|
|
1041
|
-
}
|
|
1037
|
+
},
|
|
1042
1038
|
};
|
|
1043
1039
|
}
|
|
1044
1040
|
static async GetAsync(key, default_value, isKeyMD5 = false) {
|
|
@@ -1057,7 +1053,7 @@ class UtilsCache {
|
|
|
1057
1053
|
if (data.expire === this.CACHE_EXPIRE_NONE) {
|
|
1058
1054
|
return resolve(data.json);
|
|
1059
1055
|
}
|
|
1060
|
-
const currentMillisecond =
|
|
1056
|
+
const currentMillisecond = new Date().valueOf() / 1000;
|
|
1061
1057
|
if (data.expire < currentMillisecond) {
|
|
1062
1058
|
return resolve(default_value);
|
|
1063
1059
|
}
|
|
@@ -1070,6 +1066,7 @@ class UtilsCache {
|
|
|
1070
1066
|
});
|
|
1071
1067
|
}
|
|
1072
1068
|
static Get(key, default_value) {
|
|
1069
|
+
// support cho những file không thể inject UtilsCache
|
|
1073
1070
|
if (!key) {
|
|
1074
1071
|
return this.GetDefaultValueBySpecificKey(key, default_value);
|
|
1075
1072
|
}
|
|
@@ -1082,7 +1079,7 @@ class UtilsCache {
|
|
|
1082
1079
|
if (data.expire === this.CACHE_EXPIRE_NONE) {
|
|
1083
1080
|
return data.value ?? default_value;
|
|
1084
1081
|
}
|
|
1085
|
-
const currentMillisecond =
|
|
1082
|
+
const currentMillisecond = new Date().valueOf() / 1000;
|
|
1086
1083
|
if (data.expire < currentMillisecond) {
|
|
1087
1084
|
return this.GetDefaultValueBySpecificKey(key, default_value);
|
|
1088
1085
|
}
|
|
@@ -1097,11 +1094,12 @@ class UtilsCache {
|
|
|
1097
1094
|
return default_value;
|
|
1098
1095
|
}
|
|
1099
1096
|
static async SetAsync(key, value, expireTimeBySecond = this.CACHE_EXPIRE_TIME_DEFAULT, isKeyMD5 = false) {
|
|
1097
|
+
// support inject UtilsCache
|
|
1100
1098
|
return new Promise(async (resolve) => {
|
|
1101
1099
|
const objectStore = await this.getObjectStore();
|
|
1102
1100
|
key = isKeyMD5 ? key : md5(key);
|
|
1103
1101
|
try {
|
|
1104
|
-
const currentMillisecond = expireTimeBySecond === this.CACHE_EXPIRE_NONE ? this.CACHE_EXPIRE_NONE :
|
|
1102
|
+
const currentMillisecond = expireTimeBySecond === this.CACHE_EXPIRE_NONE ? this.CACHE_EXPIRE_NONE : new Date().valueOf() / 1000 + expireTimeBySecond;
|
|
1105
1103
|
const data = {
|
|
1106
1104
|
value: encrypt(JSON.stringify({ json: value, expire: currentMillisecond })),
|
|
1107
1105
|
};
|
|
@@ -1127,10 +1125,11 @@ class UtilsCache {
|
|
|
1127
1125
|
});
|
|
1128
1126
|
}
|
|
1129
1127
|
static Set(key, value, expireTimeBySecond = this.CACHE_EXPIRE_TIME_DEFAULT) {
|
|
1130
|
-
|
|
1128
|
+
// support cho những file không inject UtilsCache
|
|
1129
|
+
const currentMillisecond = expireTimeBySecond === this.CACHE_EXPIRE_NONE ? this.CACHE_EXPIRE_NONE : new Date().valueOf() / 1000 + expireTimeBySecond;
|
|
1131
1130
|
const data = {
|
|
1132
1131
|
value: value,
|
|
1133
|
-
expire: currentMillisecond
|
|
1132
|
+
expire: currentMillisecond,
|
|
1134
1133
|
};
|
|
1135
1134
|
try {
|
|
1136
1135
|
this.LocalStorage.setItem(key, encrypt(JSON.stringify(data)));
|
|
@@ -1185,13 +1184,13 @@ class UtilsCache {
|
|
|
1185
1184
|
const data = {
|
|
1186
1185
|
type: this.typeKeyClearLocalStorage,
|
|
1187
1186
|
response: {
|
|
1188
|
-
idEvent: this.idService
|
|
1189
|
-
}
|
|
1187
|
+
idEvent: this.idService,
|
|
1188
|
+
},
|
|
1190
1189
|
};
|
|
1191
1190
|
UtilsCommunicateMicro.PostMessageToParent(data);
|
|
1192
1191
|
}
|
|
1193
1192
|
const keys = [...this.listKeyKeepWhenClearALll];
|
|
1194
|
-
Object.keys(this.LocalStorage).forEach(key => {
|
|
1193
|
+
Object.keys(this.LocalStorage).forEach((key) => {
|
|
1195
1194
|
if (key.includes('kc-callback-')) {
|
|
1196
1195
|
keys.push(key);
|
|
1197
1196
|
}
|
|
@@ -1237,7 +1236,7 @@ class UtilsCache {
|
|
|
1237
1236
|
if (!Array.isArray(data)) {
|
|
1238
1237
|
return resolve({});
|
|
1239
1238
|
}
|
|
1240
|
-
data.forEach(obj => {
|
|
1239
|
+
data.forEach((obj) => {
|
|
1241
1240
|
if (obj[this.itemIndexByKey].startsWith(keyCacheStartWith)) {
|
|
1242
1241
|
this.ClearAsync(obj[this.itemIndexByKey], true);
|
|
1243
1242
|
}
|
|
@@ -1255,7 +1254,7 @@ class UtilsCache {
|
|
|
1255
1254
|
if (!keys || !keys.length) {
|
|
1256
1255
|
return;
|
|
1257
1256
|
}
|
|
1258
|
-
keys.forEach(key => {
|
|
1257
|
+
keys.forEach((key) => {
|
|
1259
1258
|
if (key.startsWith(keyCache)) {
|
|
1260
1259
|
this.Clear(key);
|
|
1261
1260
|
}
|
|
@@ -1287,7 +1286,7 @@ dayjs.extend(updateLocale);
|
|
|
1287
1286
|
dayjs.extend(utc);
|
|
1288
1287
|
dayjs.extend(timezone);
|
|
1289
1288
|
dayjs.extend(customParseFormat);
|
|
1290
|
-
let timeZoneSetup =
|
|
1289
|
+
let timeZoneSetup = 'Asia/Ho_Chi_Minh';
|
|
1291
1290
|
const setDefaultTimeZone = (localeZone = timeZoneSetup) => {
|
|
1292
1291
|
timeZoneSetup = localeZone;
|
|
1293
1292
|
dayjs.tz.setDefault(localeZone);
|
|
@@ -1297,23 +1296,25 @@ const updateFunctionFormatDate = (functionCustom) => {
|
|
|
1297
1296
|
functionFormatDate = functionCustom;
|
|
1298
1297
|
};
|
|
1299
1298
|
/**
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
*/
|
|
1299
|
+
* @description Lấy đối tượng dayjs theo config
|
|
1300
|
+
* @param config nếu không có config sẽ trả về đối tượng dayjs là thời gian hiện tại
|
|
1301
|
+
* @param config.date thời gian cần lấy
|
|
1302
|
+
* @param config.returnDayjsIfConfigDateNotExist true nếu muốn trả về đối tượng dayjs nếu config.date không có
|
|
1303
|
+
* @param config.utc true nếu muốn lấy thời gian UTC
|
|
1304
|
+
* @param config.formatOfDate định dạng thời gian đang được truyền vào
|
|
1305
|
+
*/
|
|
1307
1306
|
const getDayjs = (config) => {
|
|
1307
|
+
// helper cast để tránh lặp lại kiểu điều kiện ở các return
|
|
1308
|
+
const out = (v) => v;
|
|
1308
1309
|
if (!config) {
|
|
1309
|
-
return dayjs().tz();
|
|
1310
|
+
return out(dayjs().tz());
|
|
1310
1311
|
}
|
|
1311
1312
|
config.date = !config.date && config.returnDayjsIfConfigDateNotExist ? dayjs().tz() : config.date;
|
|
1312
1313
|
if (typeof config.date === 'number') {
|
|
1313
1314
|
config.date = dayjs.unix(config.date);
|
|
1314
1315
|
}
|
|
1315
1316
|
if (!config.date) {
|
|
1316
|
-
return undefined;
|
|
1317
|
+
return out(undefined);
|
|
1317
1318
|
}
|
|
1318
1319
|
let { date, utc, formatOfDate } = config;
|
|
1319
1320
|
while (isSignal(date)) {
|
|
@@ -1327,18 +1328,18 @@ const getDayjs = (config) => {
|
|
|
1327
1328
|
}
|
|
1328
1329
|
if (utc) {
|
|
1329
1330
|
if (formatOfDate) {
|
|
1330
|
-
return dayjs(date, formatOfDate).utc();
|
|
1331
|
+
return out(dayjs(date, formatOfDate).utc());
|
|
1331
1332
|
}
|
|
1332
1333
|
const dateInputIsUTC = (dayjs.isDayjs(date) && date.isUTC()) || (typeof date === 'string' && date.includes('Z'));
|
|
1333
1334
|
if (dateInputIsUTC) {
|
|
1334
|
-
return dayjs(date);
|
|
1335
|
+
return out(dayjs(date));
|
|
1335
1336
|
}
|
|
1336
|
-
return dayjs(date).utc();
|
|
1337
|
+
return out(dayjs(date).utc());
|
|
1337
1338
|
}
|
|
1338
1339
|
if (typeof date === 'string' && !date.includes('Z') && !date.includes('+')) {
|
|
1339
|
-
return (formatOfDate ? dayjs.tz(date, formatOfDate, config.localeZone || timeZoneSetup) : dayjs.tz(date, config.localeZone || timeZoneSetup));
|
|
1340
|
+
return out(formatOfDate ? dayjs.tz(date, formatOfDate, config.localeZone || timeZoneSetup) : dayjs.tz(date, config.localeZone || timeZoneSetup));
|
|
1340
1341
|
}
|
|
1341
|
-
return (formatOfDate ? dayjs(date, formatOfDate) : dayjs(date)).tz();
|
|
1342
|
+
return out((formatOfDate ? dayjs(date, formatOfDate) : dayjs(date)).tz());
|
|
1342
1343
|
};
|
|
1343
1344
|
/**
|
|
1344
1345
|
* @description Kiểm tra xem hai ngày có khác nhau không (khác ngày trong tuần)
|
|
@@ -1396,7 +1397,7 @@ const formatDate = (date, formatOutput = 'YYYY/MM/DD HH:mm', lang, formatInput)
|
|
|
1396
1397
|
date = getDayjs({ date, formatOfDate: formatInput }).locale(lang);
|
|
1397
1398
|
if (lang === 'vi') {
|
|
1398
1399
|
dayjs.updateLocale('vi', {
|
|
1399
|
-
monthsShort: 'Thg 1_Thg 2_Thg 3_Thg 4_Thg 5_Thg 6_Thg 7_Thg 8_Thg 9_Thg 10_Thg 11_Thg 12'.split('_')
|
|
1400
|
+
monthsShort: 'Thg 1_Thg 2_Thg 3_Thg 4_Thg 5_Thg 6_Thg 7_Thg 8_Thg 9_Thg 10_Thg 11_Thg 12'.split('_'),
|
|
1400
1401
|
});
|
|
1401
1402
|
}
|
|
1402
1403
|
return date.format(getFormatData(getTypeByFormat(formatOutput), lang)) || '';
|
|
@@ -1660,20 +1661,22 @@ const omitBy = (objData, predicate) => {
|
|
|
1660
1661
|
* get(undefined, 'any.path', 'fallback'); // 'fallback'
|
|
1661
1662
|
*/
|
|
1662
1663
|
const get = (obj, path, defaultValue, keepLastValueIfSignal) => {
|
|
1664
|
+
// helper cast để tránh lặp lại kiểu điều kiện ở các return
|
|
1665
|
+
const out = (v) => v;
|
|
1663
1666
|
if (isNil(obj)) {
|
|
1664
|
-
return defaultValue;
|
|
1667
|
+
return out(defaultValue);
|
|
1665
1668
|
}
|
|
1666
1669
|
while (isSignal(obj)) {
|
|
1667
1670
|
obj = obj();
|
|
1668
1671
|
}
|
|
1669
1672
|
if (path === '') {
|
|
1670
|
-
return obj;
|
|
1673
|
+
return out(obj);
|
|
1671
1674
|
}
|
|
1672
1675
|
if (obj instanceof HttpParams) {
|
|
1673
|
-
return (obj.get(`${path}`) ?? defaultValue);
|
|
1676
|
+
return out(obj.get(`${path}`) ?? defaultValue);
|
|
1674
1677
|
}
|
|
1675
1678
|
if (obj instanceof DOMRect) {
|
|
1676
|
-
return obj[path];
|
|
1679
|
+
return out(obj[path]);
|
|
1677
1680
|
}
|
|
1678
1681
|
const paths = Array.isArray(path)
|
|
1679
1682
|
? path
|
|
@@ -1692,12 +1695,12 @@ const get = (obj, path, defaultValue, keepLastValueIfSignal) => {
|
|
|
1692
1695
|
continue;
|
|
1693
1696
|
}
|
|
1694
1697
|
if (isNil(obj) || !Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
1695
|
-
return defaultValue;
|
|
1698
|
+
return out(defaultValue);
|
|
1696
1699
|
}
|
|
1697
1700
|
const val = isSignal(obj[key]) && !keepLastValueIfSignal ? obj[key]() : obj[key];
|
|
1698
1701
|
obj = val;
|
|
1699
1702
|
}
|
|
1700
|
-
return obj;
|
|
1703
|
+
return out(obj);
|
|
1701
1704
|
};
|
|
1702
1705
|
/**
|
|
1703
1706
|
* Thiết lập giá trị cho một thuộc tính trong đối tượng theo đường dẫn chỉ định
|
|
@@ -1915,7 +1918,7 @@ const keyBy = (data, key) => {
|
|
|
1915
1918
|
* // }
|
|
1916
1919
|
*/
|
|
1917
1920
|
const groupBy = (data, key) => {
|
|
1918
|
-
if (!data || !data.length || !Object.keys(get(data, '0')).length || !key) {
|
|
1921
|
+
if (!data || !data.length || !Object.keys(get(data, '[0]')).length || !key) {
|
|
1919
1922
|
return {};
|
|
1920
1923
|
}
|
|
1921
1924
|
return data.reduce((dir, nextItem) => {
|
|
@@ -2035,7 +2038,7 @@ const isEqual = (value1, value2, options) => {
|
|
|
2035
2038
|
* uniqBy(numbersSignal); // [signal(1), signal(2), signal(3), signal(5), signal(4), signal(6), signal(7)]
|
|
2036
2039
|
*/
|
|
2037
2040
|
const uniqBy = (data, key) => {
|
|
2038
|
-
if (!key || !data?.length || typeof get(data, '0') !== 'object') {
|
|
2041
|
+
if (!key || !data?.length || typeof get(data, '[0]') !== 'object') {
|
|
2039
2042
|
// Xử lý mảng chứa signal values
|
|
2040
2043
|
if (data[0] && isSignal(data[0])) {
|
|
2041
2044
|
const seen = new Set();
|
|
@@ -2101,11 +2104,10 @@ const generateInterface = (obj, interfaceName) => {
|
|
|
2101
2104
|
return interfaceStr;
|
|
2102
2105
|
};
|
|
2103
2106
|
|
|
2104
|
-
;
|
|
2105
2107
|
const step = 20;
|
|
2106
2108
|
const percent = 0.05;
|
|
2107
2109
|
const colorStepContrastFromOrigin = (color, stepNumber) => {
|
|
2108
|
-
return colorContrastFromOrigin(color).find(item => item.step === stepNumber);
|
|
2110
|
+
return colorContrastFromOrigin(color).find((item) => item.step === stepNumber);
|
|
2109
2111
|
};
|
|
2110
2112
|
const colorContrastFromOrigin = (color) => {
|
|
2111
2113
|
const parsedColorsArray = parseColorValues(color);
|
|
@@ -2140,10 +2142,10 @@ const parseColorValues = (colorValues) => {
|
|
|
2140
2142
|
return colorValuesArray;
|
|
2141
2143
|
};
|
|
2142
2144
|
const calculateShades = (colorValue) => {
|
|
2143
|
-
return calculate(colorValue, rgbShade).concat(
|
|
2145
|
+
return calculate(colorValue, rgbShade).concat('000000');
|
|
2144
2146
|
};
|
|
2145
2147
|
const calculateTints = (colorValue) => {
|
|
2146
|
-
return calculate(colorValue, rgbTint).concat(
|
|
2148
|
+
return calculate(colorValue, rgbTint).concat('ffffff');
|
|
2147
2149
|
};
|
|
2148
2150
|
const calculate = (colorValue, shadeOrTint) => {
|
|
2149
2151
|
const color = hexToRGB(colorValue);
|
|
@@ -2153,11 +2155,21 @@ const calculate = (colorValue, shadeOrTint) => {
|
|
|
2153
2155
|
}
|
|
2154
2156
|
return shadeValues;
|
|
2155
2157
|
};
|
|
2156
|
-
const rgbShade = (rgb, i) => {
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
const
|
|
2160
|
-
|
|
2158
|
+
const rgbShade = (rgb, i) => {
|
|
2159
|
+
return { red: rgb.red * (1 - percent * i), green: rgb.green * (1 - percent * i), blue: rgb.blue * (1 - percent * i) };
|
|
2160
|
+
};
|
|
2161
|
+
const rgbTint = (rgb, i) => {
|
|
2162
|
+
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 };
|
|
2163
|
+
};
|
|
2164
|
+
const rgbToHex = (rgb) => {
|
|
2165
|
+
return intToHex(rgb.red) + intToHex(rgb.green) + intToHex(rgb.blue);
|
|
2166
|
+
};
|
|
2167
|
+
const hexToRGB = (colorValue) => {
|
|
2168
|
+
return { red: parseInt(colorValue.substr(0, 2), 16), green: parseInt(colorValue.substr(2, 2), 16), blue: parseInt(colorValue.substr(4, 2), 16) };
|
|
2169
|
+
};
|
|
2170
|
+
const intToHex = (rgbint) => {
|
|
2171
|
+
return pad(Math.min(Math.max(Math.round(rgbint), 0), 255).toString(16), 2);
|
|
2172
|
+
};
|
|
2161
2173
|
const pad = (number, length) => {
|
|
2162
2174
|
let str = '' + number;
|
|
2163
2175
|
while (str.length < length) {
|
|
@@ -2165,9 +2177,52 @@ const pad = (number, length) => {
|
|
|
2165
2177
|
}
|
|
2166
2178
|
return str;
|
|
2167
2179
|
};
|
|
2168
|
-
const listColorDefine = [
|
|
2169
|
-
'#
|
|
2170
|
-
'#
|
|
2180
|
+
const listColorDefine = [
|
|
2181
|
+
'#E62222',
|
|
2182
|
+
'#B81B1B',
|
|
2183
|
+
'#EB4E4E',
|
|
2184
|
+
'#F97316',
|
|
2185
|
+
'#C75C12',
|
|
2186
|
+
'#FA8F45',
|
|
2187
|
+
'#FFB700',
|
|
2188
|
+
'#CC9200',
|
|
2189
|
+
'#FFC533',
|
|
2190
|
+
'#84CC16',
|
|
2191
|
+
'#6AA312',
|
|
2192
|
+
'#9dd645',
|
|
2193
|
+
'#00BC62',
|
|
2194
|
+
'#00A757',
|
|
2195
|
+
'#33DA8A',
|
|
2196
|
+
'#06B6D4',
|
|
2197
|
+
'#1B59C4',
|
|
2198
|
+
'#4E8CF7',
|
|
2199
|
+
'#0EA5E9',
|
|
2200
|
+
'#1B59C4',
|
|
2201
|
+
'#4E8CF7',
|
|
2202
|
+
'#226FF5',
|
|
2203
|
+
'#1B59C4',
|
|
2204
|
+
'#4E8CF7',
|
|
2205
|
+
'#6366F1',
|
|
2206
|
+
'#4F52C1',
|
|
2207
|
+
'#8285F4',
|
|
2208
|
+
'#5B04B3',
|
|
2209
|
+
'#49038F',
|
|
2210
|
+
'#7C36C2',
|
|
2211
|
+
'#D946EF',
|
|
2212
|
+
'#AE38BF',
|
|
2213
|
+
'#E16BF2',
|
|
2214
|
+
'#EC4899',
|
|
2215
|
+
'#BD3A7A',
|
|
2216
|
+
'#F06DAD',
|
|
2217
|
+
'#F43F5E',
|
|
2218
|
+
'#C3324B',
|
|
2219
|
+
'#F6657E',
|
|
2220
|
+
'#757380',
|
|
2221
|
+
'#5E5C66',
|
|
2222
|
+
'#918F99',
|
|
2223
|
+
'#202020',
|
|
2224
|
+
'#1A1A1A',
|
|
2225
|
+
'#4D4D4D',
|
|
2171
2226
|
];
|
|
2172
2227
|
const getColorById = (str) => {
|
|
2173
2228
|
let hashString = 0;
|
|
@@ -2176,7 +2231,7 @@ const getColorById = (str) => {
|
|
|
2176
2231
|
}
|
|
2177
2232
|
for (let i = 0; i < str.length; i++) {
|
|
2178
2233
|
const char = str.charCodeAt(i);
|
|
2179
|
-
hashString = (
|
|
2234
|
+
hashString = (hashString << 5) - hashString + char;
|
|
2180
2235
|
hashString = hashString & hashString;
|
|
2181
2236
|
}
|
|
2182
2237
|
return listColorDefine[Math.abs(hashString) % listColorDefine.length];
|
|
@@ -2316,8 +2371,8 @@ const getKeyCacheByArrayObject = (keyCache, argumentsValue) => {
|
|
|
2316
2371
|
keyBuild = `${keyBuild}${JSON.stringify(item)}`;
|
|
2317
2372
|
return;
|
|
2318
2373
|
}
|
|
2319
|
-
const keys = (item instanceof HttpParams ? item.keys() : Object.keys(item)).sort((
|
|
2320
|
-
keys.forEach(key => {
|
|
2374
|
+
const keys = (item instanceof HttpParams ? item.keys() : Object.keys(item)).sort((str1, str2) => str1.localeCompare(str2));
|
|
2375
|
+
keys.forEach((key) => {
|
|
2321
2376
|
if (key.toLocaleLowerCase() === 'pem') {
|
|
2322
2377
|
return;
|
|
2323
2378
|
}
|
|
@@ -2361,7 +2416,7 @@ const viewDataNumberByLanguage = (value, acceptNegativeValue, parseFixed = 1, ig
|
|
|
2361
2416
|
return Math.round(value * fixed) / fixed;
|
|
2362
2417
|
};
|
|
2363
2418
|
if (parseFixed > (floatStr?.length || 0)) {
|
|
2364
|
-
const maxParseFixed =
|
|
2419
|
+
const maxParseFixed = acceptNegativeValue && +value < 0 ? 17 : 16;
|
|
2365
2420
|
const fixed = maxParseFixed - (intStr?.length || 0);
|
|
2366
2421
|
parseFixed = parseFixed < fixed ? parseFixed : fixed;
|
|
2367
2422
|
}
|
|
@@ -2388,7 +2443,10 @@ const viewDataNumberByLanguage = (value, acceptNegativeValue, parseFixed = 1, ig
|
|
|
2388
2443
|
if (lang === UtilsLanguageConstants.EN) {
|
|
2389
2444
|
return value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
2390
2445
|
}
|
|
2391
|
-
return value
|
|
2446
|
+
return value
|
|
2447
|
+
.toString()
|
|
2448
|
+
.replace('.', ',')
|
|
2449
|
+
.replace(/\B(?=(\d{3})+(?!\d))/g, '.');
|
|
2392
2450
|
}
|
|
2393
2451
|
};
|
|
2394
2452
|
|
|
@@ -2430,12 +2488,12 @@ const convertObjectToSignal = (data, cloneDeepIfNotSignal = true, isSignalPrimit
|
|
|
2430
2488
|
return seen.get(data);
|
|
2431
2489
|
}
|
|
2432
2490
|
if (Array.isArray(data)) {
|
|
2433
|
-
seen.set(data, signal(data.map(item => convertObjectToSignal(item, cloneDeepIfNotSignal, isSignalPrimitiveType, acceptConvertObjectInnerWritableSignal, seen))));
|
|
2491
|
+
seen.set(data, signal(data.map((item) => convertObjectToSignal(item, cloneDeepIfNotSignal, isSignalPrimitiveType, acceptConvertObjectInnerWritableSignal, seen))));
|
|
2434
2492
|
return seen.get(data);
|
|
2435
2493
|
}
|
|
2436
2494
|
if (data instanceof Map) {
|
|
2437
2495
|
const mapCopy = new Map();
|
|
2438
|
-
Array.from(data.keys()).forEach(key => {
|
|
2496
|
+
Array.from(data.keys()).forEach((key) => {
|
|
2439
2497
|
mapCopy.set(key, convertObjectToSignal(data.get(key), cloneDeepIfNotSignal, isSignalPrimitiveType, acceptConvertObjectInnerWritableSignal));
|
|
2440
2498
|
});
|
|
2441
2499
|
seen.set(data, signal(mapCopy));
|
|
@@ -2448,7 +2506,19 @@ const convertObjectToSignal = (data, cloneDeepIfNotSignal = true, isSignalPrimit
|
|
|
2448
2506
|
seen.set(data, data);
|
|
2449
2507
|
for (const key in data()) {
|
|
2450
2508
|
const value = data()[key];
|
|
2451
|
-
if (value instanceof TemplateRef ||
|
|
2509
|
+
if (value instanceof TemplateRef ||
|
|
2510
|
+
value instanceof File ||
|
|
2511
|
+
value instanceof Blob ||
|
|
2512
|
+
Object.prototype.toString.call(value) === '[object File]' ||
|
|
2513
|
+
value instanceof ElementRef ||
|
|
2514
|
+
value instanceof Element ||
|
|
2515
|
+
value instanceof Date ||
|
|
2516
|
+
value instanceof RegExp ||
|
|
2517
|
+
value instanceof Set ||
|
|
2518
|
+
value instanceof Map ||
|
|
2519
|
+
value instanceof Promise ||
|
|
2520
|
+
value instanceof Observable ||
|
|
2521
|
+
value instanceof HttpParams) {
|
|
2452
2522
|
continue;
|
|
2453
2523
|
}
|
|
2454
2524
|
if (Object.prototype.hasOwnProperty.call(data(), key)) {
|
|
@@ -2483,12 +2553,12 @@ const convertSignalToObject = (data, isCloneDeep = true, seen = new WeakMap()) =
|
|
|
2483
2553
|
if (!isSignal(data[0])) {
|
|
2484
2554
|
return data;
|
|
2485
2555
|
}
|
|
2486
|
-
seen.set(data, data.map(item => convertSignalToObject(
|
|
2556
|
+
seen.set(data, data.map((item) => convertSignalToObject(isCloneDeep ? cloneDeep(item) : item, isCloneDeep, seen)));
|
|
2487
2557
|
return seen.get(data);
|
|
2488
2558
|
}
|
|
2489
2559
|
if (data instanceof Map) {
|
|
2490
2560
|
const mapCopy = new Map();
|
|
2491
|
-
Array.from(data.keys()).forEach(key => {
|
|
2561
|
+
Array.from(data.keys()).forEach((key) => {
|
|
2492
2562
|
mapCopy.set(key, convertSignalToObject(isCloneDeep ? cloneDeep(data.get(key)) : data.get(key), isCloneDeep));
|
|
2493
2563
|
});
|
|
2494
2564
|
seen.set(data, mapCopy);
|
|
@@ -2513,9 +2583,12 @@ const convertSignalToObject = (data, isCloneDeep = true, seen = new WeakMap()) =
|
|
|
2513
2583
|
|
|
2514
2584
|
const ENCODE_URI_PATTERN = /%([0-9A-F]{2})/g;
|
|
2515
2585
|
const decodeURI = (value) => {
|
|
2516
|
-
return decodeURIComponent(value
|
|
2586
|
+
return decodeURIComponent(value
|
|
2587
|
+
.split('')
|
|
2588
|
+
.map((c) => {
|
|
2517
2589
|
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
|
|
2518
|
-
})
|
|
2590
|
+
})
|
|
2591
|
+
.join(''));
|
|
2519
2592
|
};
|
|
2520
2593
|
const encodeURI = (value) => {
|
|
2521
2594
|
return encodeURIComponent(value).replace(ENCODE_URI_PATTERN, (match, p1) => {
|
|
@@ -2523,7 +2596,7 @@ const encodeURI = (value) => {
|
|
|
2523
2596
|
});
|
|
2524
2597
|
};
|
|
2525
2598
|
const endCodeUrl = (params, isBody) => {
|
|
2526
|
-
params = omitBy(params, param => param === '' || isNil(param));
|
|
2599
|
+
params = omitBy(params, (param) => param === '' || isNil(param));
|
|
2527
2600
|
let res = '';
|
|
2528
2601
|
for (const p in params) {
|
|
2529
2602
|
res += `&${p}=${encodeURIComponent(params[p])}`;
|
|
@@ -2601,7 +2674,7 @@ const downloadFileByUrl = async (fileUrl, filename, onlyOpen) => {
|
|
|
2601
2674
|
const downloadImageFromELement = (imageElement, typeFileDownload, nameFile) => {
|
|
2602
2675
|
const parentElement = imageElement?.src;
|
|
2603
2676
|
const blobData = convertBase64ToBlob(parentElement);
|
|
2604
|
-
const blob = new Blob([blobData], { type: typeFileDownload ||
|
|
2677
|
+
const blob = new Blob([blobData], { type: typeFileDownload || 'image/png' });
|
|
2605
2678
|
const url = window.URL.createObjectURL(blob);
|
|
2606
2679
|
const link = document.createElement('a');
|
|
2607
2680
|
link.href = url;
|
|
@@ -2613,12 +2686,22 @@ const LINK_IMAGE_ERROR_TOKEN_INJECT = new InjectionToken('LINK_IMAGE_ERROR_TOKEN
|
|
|
2613
2686
|
const PROCESS_BAR_STANDARD_CONFIG_DEFAULT_TOKEN_INJECT = new InjectionToken('PROCESS_BAR_STANDARD_CONFIG_DEFAULT_TOKEN_INJECT');
|
|
2614
2687
|
const PROCESS_BAR_STEPS_CONFIG_DEFAULT_TOKEN_INJECT = new InjectionToken('PROCESS_BAR_STEPS_CONFIG_DEFAULT_TOKEN_INJECT');
|
|
2615
2688
|
|
|
2616
|
-
const isTypeImage = (file) => file.type.match(/image.*/) ? true : false;
|
|
2617
|
-
const isTypeVideo = (file) => file.type.match(/video.*/) ? true : false;
|
|
2618
|
-
const isTypeAudio = (file) => file.type.match(/audio.*/) ? true : false;
|
|
2619
|
-
const isTypeFile = (file) => file instanceof File || Object.prototype.toString.call(file) === '[object File]' ? true : false;
|
|
2689
|
+
const isTypeImage = (file) => (file.type.match(/image.*/) ? true : false);
|
|
2690
|
+
const isTypeVideo = (file) => (file.type.match(/video.*/) ? true : false);
|
|
2691
|
+
const isTypeAudio = (file) => (file.type.match(/audio.*/) ? true : false);
|
|
2692
|
+
const isTypeFile = (file) => (file instanceof File || Object.prototype.toString.call(file) === '[object File]' ? true : false);
|
|
2620
2693
|
const ExcelExtList = ['xls', 'xlsx', 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'];
|
|
2621
|
-
const DocumentExtList = [
|
|
2694
|
+
const DocumentExtList = [
|
|
2695
|
+
'doc',
|
|
2696
|
+
'docx',
|
|
2697
|
+
'xls',
|
|
2698
|
+
'xlsx',
|
|
2699
|
+
'ppt',
|
|
2700
|
+
'pptx',
|
|
2701
|
+
'pdf',
|
|
2702
|
+
'json',
|
|
2703
|
+
'xml',
|
|
2704
|
+
'application/msword',
|
|
2622
2705
|
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
2623
2706
|
'application/vnd.ms-excel',
|
|
2624
2707
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
@@ -2626,7 +2709,8 @@ const DocumentExtList = ['doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'pdf', 'js
|
|
|
2626
2709
|
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
2627
2710
|
'application/pdf',
|
|
2628
2711
|
'application/json',
|
|
2629
|
-
'application/xml'
|
|
2712
|
+
'application/xml',
|
|
2713
|
+
];
|
|
2630
2714
|
const isIncludeDocumentExtList = (ext, listExt = DocumentExtList) => listExt.includes(ext) || listExt.includes(`application/${ext}`);
|
|
2631
2715
|
const ImageExtList = ['gif', 'jpg', 'jpeg', 'png', 'image/gif', 'image/jpeg', 'image/jpeg', 'image/png'];
|
|
2632
2716
|
const isIncludeImageExtList = (ext, listExt = ImageExtList) => listExt.includes(ext);
|
|
@@ -2651,7 +2735,7 @@ const getFileExtension = (file) => {
|
|
|
2651
2735
|
fileName = url.split('/').pop() || '';
|
|
2652
2736
|
set(file, 'name', fileName);
|
|
2653
2737
|
}
|
|
2654
|
-
const dots = fileName.split(
|
|
2738
|
+
const dots = fileName.split('.');
|
|
2655
2739
|
if (!dots) {
|
|
2656
2740
|
return;
|
|
2657
2741
|
}
|
|
@@ -2755,12 +2839,12 @@ const getSmartAxisScale = (originalMaxData, options) => {
|
|
|
2755
2839
|
}
|
|
2756
2840
|
const maxValuePositive = maxValue - Math.abs(minValue);
|
|
2757
2841
|
tickCount = maxValuePositive - originalMaxData > Math.abs(step) && tickCount - 1 >= minTickCount ? tickCount - 1 : tickCount;
|
|
2758
|
-
maxValue =
|
|
2842
|
+
maxValue = step * tickCount * scaleDirection - minValue * scaleDirection;
|
|
2759
2843
|
return {
|
|
2760
2844
|
stepSize: Math.abs(step),
|
|
2761
2845
|
max: maxValue,
|
|
2762
2846
|
min: minValue,
|
|
2763
|
-
tickAmount: tickCount
|
|
2847
|
+
tickAmount: tickCount,
|
|
2764
2848
|
};
|
|
2765
2849
|
}
|
|
2766
2850
|
}
|
|
@@ -2775,7 +2859,7 @@ const getSmartAxisScale = (originalMaxData, options) => {
|
|
|
2775
2859
|
stepSize: Math.abs(step),
|
|
2776
2860
|
max: maxValue,
|
|
2777
2861
|
min: 0,
|
|
2778
|
-
tickAmount: minTickCount
|
|
2862
|
+
tickAmount: minTickCount,
|
|
2779
2863
|
};
|
|
2780
2864
|
};
|
|
2781
2865
|
// Cache cho các giá trị lũy thừa 10 để tối ưu hiệu suất
|
|
@@ -2831,7 +2915,7 @@ const getStepCandidates = (maxData, minStep, minNegative, acceptStepIsTypeFloat
|
|
|
2831
2915
|
const checkAndSetNegativeSteps = (stepCandidates, acceptNegative, minNegative) => {
|
|
2832
2916
|
if (acceptNegative && minNegative < 0) {
|
|
2833
2917
|
// Tạo các step âm và thêm vào đầu danh sách
|
|
2834
|
-
const negativeSteps = [...stepCandidates].map(step => -step);
|
|
2918
|
+
const negativeSteps = [...stepCandidates].map((step) => -step);
|
|
2835
2919
|
stepCandidates.unshift(...negativeSteps);
|
|
2836
2920
|
}
|
|
2837
2921
|
};
|
|
@@ -2844,20 +2928,20 @@ const checkAndSetNegativeSteps = (stepCandidates, acceptNegative, minNegative) =
|
|
|
2844
2928
|
const validateInputs = (maxData, options) => {
|
|
2845
2929
|
// Kiểm tra maxData âm khi không chấp nhận giá trị âm
|
|
2846
2930
|
if (maxData < 0 && !options?.acceptNegative) {
|
|
2847
|
-
throw new Error(
|
|
2931
|
+
throw new Error('maxData is less than 0 and acceptNegative is false');
|
|
2848
2932
|
}
|
|
2849
2933
|
if (options?.acceptNegative) {
|
|
2850
2934
|
// Kiểm tra minNegative có được cung cấp không
|
|
2851
2935
|
if (isNil(options.minNegative)) {
|
|
2852
|
-
throw new Error(
|
|
2936
|
+
throw new Error('minNegative is required when acceptNegative is true');
|
|
2853
2937
|
}
|
|
2854
2938
|
// Kiểm tra maxData phải >= minNegative
|
|
2855
2939
|
if (maxData < options.minNegative) {
|
|
2856
|
-
throw new Error(
|
|
2940
|
+
throw new Error('maxData is less than minNegative');
|
|
2857
2941
|
}
|
|
2858
2942
|
// Kiểm tra minNegative phải là số âm
|
|
2859
2943
|
if (options.minNegative >= 0) {
|
|
2860
|
-
throw new Error(
|
|
2944
|
+
throw new Error('minNegative must be negative');
|
|
2861
2945
|
}
|
|
2862
2946
|
}
|
|
2863
2947
|
};
|
|
@@ -2877,7 +2961,7 @@ const revealString = (encoded) => {
|
|
|
2877
2961
|
const decoded = base
|
|
2878
2962
|
.split('')
|
|
2879
2963
|
.reverse()
|
|
2880
|
-
.map(c => String.fromCharCode(c.charCodeAt(0) ^ xorKey))
|
|
2964
|
+
.map((c) => String.fromCharCode(c.charCodeAt(0) ^ xorKey))
|
|
2881
2965
|
.join('');
|
|
2882
2966
|
return decoded;
|
|
2883
2967
|
};
|