@acorex/core 16.0.2 → 17.0.1
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/common/README.md +3 -0
- package/common/countries/countries.data.d.ts +2 -0
- package/common/countries/country.d.ts +13 -0
- package/common/index.d.ts +2 -0
- package/config/README.md +3 -0
- package/config/index.d.ts +2 -0
- package/config/lib/configs.d.ts +6 -0
- package/config/lib/configs.service.d.ts +12 -0
- package/date-time/README.md +3 -0
- package/date-time/index.d.ts +10 -0
- package/date-time/lib/calendar.service.d.ts +27 -0
- package/date-time/lib/dateTime.config.d.ts +12 -0
- package/date-time/lib/datetime.class.d.ts +138 -0
- package/date-time/lib/datetime.module.d.ts +8 -0
- package/date-time/lib/datetime.pipe.d.ts +12 -0
- package/date-time/lib/formatters/datetime-formatter.d.ts +19 -0
- package/date-time/lib/formatters/timeleft-formatter.d.ts +16 -0
- package/date-time/lib/georgian.calendar.d.ts +21 -0
- package/date-time/lib/holidays.loader.d.ts +21 -0
- package/date-time/lib/jalali.calendar.d.ts +40 -0
- package/esm2022/common/acorex-core-common.mjs +5 -0
- package/esm2022/common/countries/countries.data.mjs +2625 -0
- package/esm2022/common/countries/country.mjs +2 -0
- package/esm2022/common/index.mjs +3 -0
- package/esm2022/config/acorex-core-config.mjs +5 -0
- package/esm2022/config/index.mjs +3 -0
- package/esm2022/config/lib/configs.mjs +7 -0
- package/esm2022/config/lib/configs.service.mjs +27 -0
- package/esm2022/date-time/acorex-core-date-time.mjs +5 -0
- package/esm2022/date-time/index.mjs +11 -0
- package/esm2022/date-time/lib/calendar.service.mjs +100 -0
- package/esm2022/date-time/lib/dateTime.config.mjs +50 -0
- package/esm2022/date-time/lib/datetime.class.mjs +337 -0
- package/esm2022/date-time/lib/datetime.module.mjs +27 -0
- package/esm2022/date-time/lib/datetime.pipe.mjs +29 -0
- package/esm2022/date-time/lib/formatters/datetime-formatter.mjs +32 -0
- package/esm2022/date-time/lib/formatters/timeleft-formatter.mjs +91 -0
- package/esm2022/date-time/lib/georgian.calendar.mjs +203 -0
- package/esm2022/date-time/lib/holidays.loader.mjs +13 -0
- package/esm2022/date-time/lib/jalali.calendar.mjs +440 -0
- package/esm2022/events/acorex-core-events.mjs +5 -0
- package/esm2022/events/index.mjs +3 -0
- package/esm2022/events/lib/event.service.mjs +43 -0
- package/esm2022/events/lib/event.type.mjs +6 -0
- package/esm2022/file/acorex-core-file.mjs +5 -0
- package/esm2022/file/index.mjs +7 -0
- package/esm2022/file/lib/file-download-ref.class.mjs +12 -0
- package/esm2022/file/lib/file-download-result.class.mjs +45 -0
- package/esm2022/file/lib/file-size-formatter.mjs +24 -0
- package/esm2022/file/lib/file-upload-ref.class.mjs +12 -0
- package/esm2022/file/lib/file.module.mjs +20 -0
- package/esm2022/file/lib/file.service.mjs +103 -0
- package/esm2022/format/acorex-core-format.mjs +5 -0
- package/esm2022/format/index.mjs +8 -0
- package/esm2022/format/lib/format.config.mjs +3 -0
- package/esm2022/format/lib/format.module.mjs +64 -0
- package/esm2022/format/lib/format.pipe.mjs +37 -0
- package/esm2022/format/lib/format.service.mjs +95 -0
- package/esm2022/format/lib/format.types.mjs +2 -0
- package/esm2022/format/lib/formatters/number-formatter.mjs +74 -0
- package/esm2022/format/lib/formatters/string-formatter.mjs +15 -0
- package/esm2022/image/acorex-core-image.mjs +5 -0
- package/esm2022/image/index.mjs +2 -0
- package/esm2022/image/lib/image.service.mjs +43 -0
- package/esm2022/index.mjs +2 -44
- package/esm2022/memorize/acorex-core-memorize.mjs +5 -0
- package/esm2022/memorize/index.mjs +2 -0
- package/esm2022/memorize/lib/memorize.decorator.mjs +19 -0
- package/esm2022/pipes/acorex-core-pipes.mjs +5 -0
- package/esm2022/pipes/index.mjs +2 -0
- package/esm2022/pipes/lib/safe/safe.pipe.mjs +38 -0
- package/esm2022/platform/acorex-core-platform.mjs +5 -0
- package/esm2022/platform/index.mjs +2 -0
- package/esm2022/platform/lib/platform.service.mjs +225 -0
- package/esm2022/storage/acorex-core-storage.mjs +5 -0
- package/esm2022/storage/cookie-storage.service.mjs +202 -0
- package/esm2022/storage/index.mjs +5 -0
- package/esm2022/storage/local-storage.service.mjs +58 -0
- package/esm2022/storage/session-storage.service.mjs +22 -0
- package/esm2022/storage/storage.interface.mjs +2 -0
- package/esm2022/translation/acorex-core-translation.mjs +5 -0
- package/esm2022/translation/index.mjs +9 -0
- package/esm2022/translation/lib/translation-scope.resolver.mjs +11 -0
- package/esm2022/translation/lib/translation.config.mjs +20 -0
- package/esm2022/translation/lib/translation.loader.mjs +14 -0
- package/esm2022/translation/lib/translation.module.mjs +40 -0
- package/esm2022/translation/lib/translation.service.mjs +173 -0
- package/esm2022/translation/lib/translation.types.mjs +2 -0
- package/esm2022/translation/lib/translator.directive.mjs +28 -0
- package/esm2022/translation/lib/translator.pipe.mjs +23 -0
- package/esm2022/types/acorex-core-types.mjs +5 -0
- package/esm2022/types/index.mjs +2 -0
- package/esm2022/utils/acorex-core-utils.mjs +5 -0
- package/esm2022/utils/index.mjs +6 -0
- package/esm2022/utils/lib/auto-unsubscribe.mjs +36 -0
- package/esm2022/utils/lib/color-util.mjs +111 -0
- package/esm2022/utils/lib/drawing-util.mjs +35 -0
- package/esm2022/utils/lib/html-util.mjs +39 -0
- package/esm2022/utils/lib/string-util.mjs +19 -0
- package/esm2022/validation/acorex-core-validation.mjs +5 -0
- package/esm2022/validation/index.mjs +18 -0
- package/esm2022/validation/lib/rules/between-rule.mjs +31 -0
- package/esm2022/validation/lib/rules/callback-rule.mjs +29 -0
- package/esm2022/validation/lib/rules/equal-rule.mjs +26 -0
- package/esm2022/validation/lib/rules/greater-than.mjs +29 -0
- package/esm2022/validation/lib/rules/length-rule.mjs +26 -0
- package/esm2022/validation/lib/rules/less-than-rule.mjs +29 -0
- package/esm2022/validation/lib/rules/maxlength-rule.mjs +27 -0
- package/esm2022/validation/lib/rules/minlength-rule.mjs +26 -0
- package/esm2022/validation/lib/rules/regex-rule.mjs +49 -0
- package/esm2022/validation/lib/rules/required-rule.mjs +36 -0
- package/esm2022/validation/lib/validation.config.mjs +33 -0
- package/esm2022/validation/lib/validation.module.mjs +84 -0
- package/esm2022/validation/lib/validation.service.mjs +98 -0
- package/esm2022/validation/lib/validation.types.mjs +3 -0
- package/events/README.md +3 -0
- package/events/index.d.ts +2 -0
- package/{lib/services → events/lib}/event.service.d.ts +8 -0
- package/events/lib/event.type.d.ts +5 -0
- package/fesm2022/acorex-core-common.mjs +2631 -0
- package/fesm2022/acorex-core-common.mjs.map +1 -0
- package/fesm2022/acorex-core-config.mjs +39 -0
- package/fesm2022/acorex-core-config.mjs.map +1 -0
- package/fesm2022/acorex-core-date-time.mjs +1305 -0
- package/fesm2022/acorex-core-date-time.mjs.map +1 -0
- package/fesm2022/acorex-core-events.mjs +56 -0
- package/fesm2022/acorex-core-events.mjs.map +1 -0
- package/fesm2022/acorex-core-file.mjs +214 -0
- package/fesm2022/acorex-core-file.mjs.map +1 -0
- package/fesm2022/acorex-core-format.mjs +282 -0
- package/fesm2022/acorex-core-format.mjs.map +1 -0
- package/fesm2022/acorex-core-image.mjs +50 -0
- package/fesm2022/acorex-core-image.mjs.map +1 -0
- package/fesm2022/acorex-core-memorize.mjs +26 -0
- package/fesm2022/acorex-core-memorize.mjs.map +1 -0
- package/fesm2022/acorex-core-pipes.mjs +44 -0
- package/fesm2022/acorex-core-pipes.mjs.map +1 -0
- package/fesm2022/acorex-core-platform.mjs +232 -0
- package/fesm2022/acorex-core-platform.mjs.map +1 -0
- package/fesm2022/acorex-core-storage.mjs +285 -0
- package/fesm2022/acorex-core-storage.mjs.map +1 -0
- package/fesm2022/acorex-core-translation.mjs +293 -0
- package/fesm2022/acorex-core-translation.mjs.map +1 -0
- package/fesm2022/acorex-core-types.mjs +6 -0
- package/fesm2022/acorex-core-types.mjs.map +1 -0
- package/fesm2022/acorex-core-utils.mjs +247 -0
- package/fesm2022/acorex-core-utils.mjs.map +1 -0
- package/fesm2022/acorex-core-validation.mjs +488 -0
- package/fesm2022/acorex-core-validation.mjs.map +1 -0
- package/fesm2022/acorex-core.mjs +2 -2309
- package/fesm2022/acorex-core.mjs.map +1 -1
- package/file/README.md +3 -0
- package/file/index.d.ts +6 -0
- package/file/lib/file-download-ref.class.d.ts +6 -0
- package/file/lib/file-download-result.class.d.ts +8 -0
- package/file/lib/file-size-formatter.d.ts +16 -0
- package/file/lib/file-upload-ref.class.d.ts +5 -0
- package/file/lib/file.module.d.ts +7 -0
- package/file/lib/file.service.d.ts +18 -0
- package/format/README.md +3 -0
- package/format/index.d.ts +7 -0
- package/format/lib/format.config.d.ts +5 -0
- package/format/lib/format.module.d.ts +18 -0
- package/format/lib/format.pipe.d.ts +12 -0
- package/format/lib/format.service.d.ts +43 -0
- package/format/lib/format.types.d.ts +4 -0
- package/format/lib/formatters/number-formatter.d.ts +23 -0
- package/format/lib/formatters/string-formatter.d.ts +14 -0
- package/image/README.md +3 -0
- package/image/index.d.ts +1 -0
- package/image/lib/image.service.d.ts +11 -0
- package/index.d.ts +1 -43
- package/memorize/README.md +3 -0
- package/memorize/index.d.ts +1 -0
- package/memorize/lib/memorize.decorator.d.ts +1 -0
- package/package.json +98 -5
- package/pipes/README.md +3 -0
- package/pipes/index.d.ts +1 -0
- package/pipes/lib/safe/safe.pipe.d.ts +10 -0
- package/platform/README.md +3 -0
- package/platform/index.d.ts +1 -0
- package/{lib/platform → platform/lib}/platform.service.d.ts +14 -6
- package/storage/README.md +3 -0
- package/storage/cookie-storage.service.d.ts +104 -0
- package/storage/index.d.ts +4 -0
- package/storage/local-storage.service.d.ts +16 -0
- package/storage/session-storage.service.d.ts +10 -0
- package/storage/storage.interface.d.ts +14 -0
- package/translation/README.md +3 -0
- package/translation/index.d.ts +8 -0
- package/translation/lib/translation-scope.resolver.d.ts +2 -0
- package/translation/lib/translation.config.d.ts +14 -0
- package/translation/lib/translation.loader.d.ts +14 -0
- package/translation/lib/translation.module.d.ts +8 -0
- package/translation/lib/translation.service.d.ts +31 -0
- package/translation/lib/translation.types.d.ts +10 -0
- package/translation/lib/translator.directive.d.ts +12 -0
- package/translation/lib/translator.pipe.d.ts +12 -0
- package/types/README.md +3 -0
- package/types/index.d.ts +2 -0
- package/utils/README.md +3 -0
- package/utils/index.d.ts +5 -0
- package/utils/lib/auto-unsubscribe.d.ts +12 -0
- package/utils/lib/color-util.d.ts +24 -0
- package/utils/lib/drawing-util.d.ts +18 -0
- package/utils/lib/html-util.d.ts +5 -0
- package/utils/lib/string-util.d.ts +6 -0
- package/validation/README.md +3 -0
- package/validation/index.d.ts +14 -0
- package/validation/lib/rules/between-rule.d.ts +18 -0
- package/validation/lib/rules/callback-rule.d.ts +23 -0
- package/validation/lib/rules/equal-rule.d.ts +17 -0
- package/validation/lib/rules/greater-than.d.ts +17 -0
- package/validation/lib/rules/length-rule.d.ts +17 -0
- package/validation/lib/rules/less-than-rule.d.ts +17 -0
- package/validation/lib/rules/maxlength-rule.d.ts +16 -0
- package/validation/lib/rules/minlength-rule.d.ts +16 -0
- package/validation/lib/rules/regex-rule.d.ts +17 -0
- package/validation/lib/rules/required-rule.d.ts +16 -0
- package/validation/lib/validation.config.d.ts +15 -0
- package/validation/lib/validation.module.d.ts +17 -0
- package/validation/lib/validation.service.d.ts +35 -0
- package/validation/lib/validation.types.d.ts +21 -0
- package/esm2022/lib/classes/base-page.class.mjs +0 -26
- package/esm2022/lib/classes/color.class.mjs +0 -49
- package/esm2022/lib/classes/datetime.class.mjs +0 -323
- package/esm2022/lib/classes/menu.class.mjs +0 -35
- package/esm2022/lib/classes/navigator.class.mjs +0 -2
- package/esm2022/lib/classes/popup.class.mjs +0 -2
- package/esm2022/lib/classes/promise.class.mjs +0 -21
- package/esm2022/lib/classes/sectionlist.class.mjs +0 -2
- package/esm2022/lib/classes/select.class.mjs +0 -8
- package/esm2022/lib/core.module.mjs +0 -27
- package/esm2022/lib/error/error.class.mjs +0 -2
- package/esm2022/lib/error/error.module.mjs +0 -19
- package/esm2022/lib/error/error.service.mjs +0 -22
- package/esm2022/lib/events/keyboard.mjs +0 -2
- package/esm2022/lib/http/http-error.class.mjs +0 -2
- package/esm2022/lib/http/http-events.interceptor.mjs +0 -3
- package/esm2022/lib/http/http-request.class.mjs +0 -2
- package/esm2022/lib/http/http-result.class.mjs +0 -25
- package/esm2022/lib/http/http.module.mjs +0 -35
- package/esm2022/lib/http/http.service.mjs +0 -148
- package/esm2022/lib/locale/en.json +0 -255
- package/esm2022/lib/locale/fa.json +0 -245
- package/esm2022/lib/pipe/datetime.pipe.mjs +0 -25
- package/esm2022/lib/pipe/htmlToText.pipe.mjs +0 -25
- package/esm2022/lib/platform/index.mjs +0 -2
- package/esm2022/lib/platform/platform.service.mjs +0 -152
- package/esm2022/lib/services/config.mjs +0 -29
- package/esm2022/lib/services/event.service.mjs +0 -34
- package/esm2022/lib/services/navigator.service.mjs +0 -10
- package/esm2022/lib/services/storage.service.mjs +0 -16
- package/esm2022/lib/translator/translator.mjs +0 -26
- package/esm2022/lib/translator/translator.module.mjs +0 -25
- package/esm2022/lib/translator/translator.pipe.mjs +0 -24
- package/esm2022/lib/translator/translator.service.mjs +0 -21
- package/esm2022/lib/utils/array/array-util.mjs +0 -133
- package/esm2022/lib/utils/html/html-util.mjs +0 -200
- package/esm2022/lib/utils/html/html.module.mjs +0 -19
- package/esm2022/lib/utils/math/math-util.mjs +0 -6
- package/esm2022/lib/utils/object/object-util.mjs +0 -83
- package/esm2022/lib/utils/render/on-demand-preload-strategy.service.mjs +0 -21
- package/esm2022/lib/utils/render/render.service.mjs +0 -109
- package/esm2022/lib/utils/render/rendering.module.mjs +0 -35
- package/esm2022/lib/utils/scroll/scroll.directive.mjs +0 -56
- package/esm2022/lib/utils/scroll/scroll.module.mjs +0 -19
- package/esm2022/lib/utils/separator/separator.module.mjs +0 -19
- package/esm2022/lib/utils/separator/separator.pipe.mjs +0 -33
- package/lib/classes/base-page.class.d.ts +0 -13
- package/lib/classes/color.class.d.ts +0 -17
- package/lib/classes/datetime.class.d.ts +0 -63
- package/lib/classes/menu.class.d.ts +0 -34
- package/lib/classes/navigator.class.d.ts +0 -5
- package/lib/classes/popup.class.d.ts +0 -12
- package/lib/classes/promise.class.d.ts +0 -7
- package/lib/classes/sectionlist.class.d.ts +0 -8
- package/lib/classes/select.class.d.ts +0 -7
- package/lib/core.module.d.ts +0 -9
- package/lib/error/error.class.d.ts +0 -4
- package/lib/error/error.module.d.ts +0 -7
- package/lib/error/error.service.d.ts +0 -13
- package/lib/events/keyboard.d.ts +0 -2
- package/lib/http/http-error.class.d.ts +0 -7
- package/lib/http/http-events.interceptor.d.ts +0 -10
- package/lib/http/http-request.class.d.ts +0 -14
- package/lib/http/http-result.class.d.ts +0 -11
- package/lib/http/http.module.d.ts +0 -10
- package/lib/http/http.service.d.ts +0 -23
- package/lib/pipe/datetime.pipe.d.ts +0 -8
- package/lib/pipe/htmlToText.pipe.d.ts +0 -7
- package/lib/platform/index.d.ts +0 -1
- package/lib/services/config.d.ts +0 -9
- package/lib/services/navigator.service.d.ts +0 -8
- package/lib/services/storage.service.d.ts +0 -7
- package/lib/translator/translator.d.ts +0 -9
- package/lib/translator/translator.module.d.ts +0 -8
- package/lib/translator/translator.pipe.d.ts +0 -8
- package/lib/translator/translator.service.d.ts +0 -8
- package/lib/utils/array/array-util.d.ts +0 -6
- package/lib/utils/html/html-util.d.ts +0 -62
- package/lib/utils/html/html.module.d.ts +0 -8
- package/lib/utils/math/math-util.d.ts +0 -3
- package/lib/utils/object/object-util.d.ts +0 -7
- package/lib/utils/render/on-demand-preload-strategy.service.d.ts +0 -10
- package/lib/utils/render/render.service.d.ts +0 -18
- package/lib/utils/render/rendering.module.d.ts +0 -8
- package/lib/utils/scroll/scroll.directive.d.ts +0 -18
- package/lib/utils/scroll/scroll.module.d.ts +0 -8
- package/lib/utils/separator/separator.module.d.ts +0 -8
- package/lib/utils/separator/separator.pipe.d.ts +0 -8
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { InjectionToken, inject, Injectable, Pipe, Directive, APP_INITIALIZER, NgModule } from '@angular/core';
|
|
3
|
+
import { of, BehaviorSubject, forkJoin, tap, catchError, finalize, shareReplay, map, switchMap, startWith, firstValueFrom, take } from 'rxjs';
|
|
4
|
+
import { set, get } from 'lodash-es';
|
|
5
|
+
import { AXEventService, AXEventTypes } from '@acorex/core/events';
|
|
6
|
+
|
|
7
|
+
const AX_TRANSLATION_CONFIG = new InjectionToken('AX_TRANSLATION_CONFIG', {
|
|
8
|
+
providedIn: 'root',
|
|
9
|
+
factory: () => {
|
|
10
|
+
return AXTranslationDefaultConfig;
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
const AXTranslationDefaultConfig = {
|
|
14
|
+
defaultLang: 'en',
|
|
15
|
+
defaultScope: 'common',
|
|
16
|
+
scopeResolverKey: 'scope',
|
|
17
|
+
};
|
|
18
|
+
function translationConfig(config = {}) {
|
|
19
|
+
const result = {
|
|
20
|
+
...AXTranslationDefaultConfig,
|
|
21
|
+
...config,
|
|
22
|
+
};
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
class AXTranslationLoaderDefault {
|
|
27
|
+
getTranslation(options) {
|
|
28
|
+
return of({});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const AX_TRANSLATION_LOADER = new InjectionToken('AX_TRANSLATION_LOADER', {
|
|
32
|
+
providedIn: 'root',
|
|
33
|
+
factory: () => {
|
|
34
|
+
return new AXTranslationLoaderDefault();
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
let service;
|
|
39
|
+
function translateSync(key, options) {
|
|
40
|
+
return service.translateSync(key, options);
|
|
41
|
+
}
|
|
42
|
+
class AXTranslationService {
|
|
43
|
+
/**
|
|
44
|
+
* @ignore
|
|
45
|
+
*/
|
|
46
|
+
constructor() {
|
|
47
|
+
this.loader = inject(AX_TRANSLATION_LOADER);
|
|
48
|
+
this.config = inject(AX_TRANSLATION_CONFIG);
|
|
49
|
+
this.eventService = inject(AXEventService);
|
|
50
|
+
this.translationCache = {};
|
|
51
|
+
this.ongoingRequests = new Map();
|
|
52
|
+
this.activeLang = new BehaviorSubject(this.getDefaultLang());
|
|
53
|
+
this.langChanges$ = this.activeLang.asObservable();
|
|
54
|
+
this.lastActiveLang = null;
|
|
55
|
+
service = this;
|
|
56
|
+
}
|
|
57
|
+
loadLanguagesAndScopes(languages, scopes) {
|
|
58
|
+
const requests = languages.flatMap((lang) => scopes.map((scope) => {
|
|
59
|
+
// Check if translations are already cached
|
|
60
|
+
if (this.translationCache[lang]?.[scope]) {
|
|
61
|
+
return of(this.translationCache[lang][scope]);
|
|
62
|
+
}
|
|
63
|
+
// Use the new method to handle ongoing requests and loading
|
|
64
|
+
return this.getOrLoadTranslations(lang, scope);
|
|
65
|
+
}));
|
|
66
|
+
return forkJoin(requests);
|
|
67
|
+
}
|
|
68
|
+
getOrLoadTranslations(lang, scope) {
|
|
69
|
+
const requestKey = `${lang}_${scope}`;
|
|
70
|
+
// Return existing observable if the request is already in progress
|
|
71
|
+
if (this.ongoingRequests.has(requestKey)) {
|
|
72
|
+
return this.ongoingRequests.get(requestKey);
|
|
73
|
+
}
|
|
74
|
+
// Load translations if not in cache or ongoing requests
|
|
75
|
+
const translationObservable = this.loader
|
|
76
|
+
.getTranslation({ lang, scope })
|
|
77
|
+
.pipe(tap((translations) => this.cacheTranslations(lang, scope, translations)), catchError((error) => {
|
|
78
|
+
console.error(`Error loading translations for lang: ${lang}, scope: ${scope}`, error);
|
|
79
|
+
return of(null);
|
|
80
|
+
}), finalize(() => {
|
|
81
|
+
this.eventService.emitEvent({
|
|
82
|
+
type: AXEventTypes.AXLanguageLoaded,
|
|
83
|
+
payload: lang,
|
|
84
|
+
});
|
|
85
|
+
this.ongoingRequests.delete(requestKey);
|
|
86
|
+
}), shareReplay(1));
|
|
87
|
+
this.ongoingRequests.set(requestKey, translationObservable);
|
|
88
|
+
return translationObservable;
|
|
89
|
+
}
|
|
90
|
+
cacheTranslations(lang, scope, translations) {
|
|
91
|
+
set(this.translationCache, `${lang}.${scope}`, translations);
|
|
92
|
+
}
|
|
93
|
+
getDefaultLang() {
|
|
94
|
+
return this.config.defaultLang;
|
|
95
|
+
}
|
|
96
|
+
getActiveLang() {
|
|
97
|
+
return this.activeLang.getValue();
|
|
98
|
+
}
|
|
99
|
+
setActiveLang(lang) {
|
|
100
|
+
if (lang != this.getActiveLang()) {
|
|
101
|
+
this.lastActiveLang = this.getActiveLang(); // Update last active language
|
|
102
|
+
this.activeLang.next(lang);
|
|
103
|
+
this.eventService.emitEvent({
|
|
104
|
+
type: AXEventTypes.AXLanguageChanged,
|
|
105
|
+
payload: lang,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
load(key, options = {}) {
|
|
110
|
+
const { lang = this.getActiveLang(), scope = this.config.defaultScope } = options;
|
|
111
|
+
// Function to fetch translation
|
|
112
|
+
const fetchTranslation = (language) => {
|
|
113
|
+
// Check if translations are available in the cache
|
|
114
|
+
if (this.translationCache[language]?.[scope]) {
|
|
115
|
+
return of(this.getTranslation(key, language, scope, options.params));
|
|
116
|
+
}
|
|
117
|
+
// Use the new method to handle ongoing requests and loading
|
|
118
|
+
return this.getOrLoadTranslations(language, scope).pipe(map(() => {
|
|
119
|
+
const translation = this.translationCache[language]?.[scope]?.[key] || key;
|
|
120
|
+
return this.getTranslation(translation, language, scope, options.params);
|
|
121
|
+
}), switchMap((translatedText) => {
|
|
122
|
+
if (translatedText === key && language !== this.getDefaultLang()) {
|
|
123
|
+
// If the translation is not found and the language is not default,
|
|
124
|
+
// try fetching from the default language
|
|
125
|
+
return fetchTranslation(this.getDefaultLang());
|
|
126
|
+
}
|
|
127
|
+
return of(translatedText);
|
|
128
|
+
}));
|
|
129
|
+
};
|
|
130
|
+
// First, try to fetch the translation for the requested language
|
|
131
|
+
const translationForRequestedLang = fetchTranslation(lang);
|
|
132
|
+
// If lastActiveLang is available and different from the requested language, use it as a fallback
|
|
133
|
+
if (this.lastActiveLang && this.lastActiveLang !== lang) {
|
|
134
|
+
const translationForLastActiveLang = this.getTranslation(key, this.lastActiveLang, scope, options.params);
|
|
135
|
+
return translationForRequestedLang.pipe(startWith(translationForLastActiveLang));
|
|
136
|
+
}
|
|
137
|
+
return translationForRequestedLang;
|
|
138
|
+
}
|
|
139
|
+
getTranslation(key, lang, scope, params) {
|
|
140
|
+
let translation = (get(this.translationCache, `${lang}.${scope}.${key}`) || key);
|
|
141
|
+
// Replace params like {{ name }}
|
|
142
|
+
if (params) {
|
|
143
|
+
Object.keys(params).forEach((paramKey) => {
|
|
144
|
+
const paramValue = params[paramKey];
|
|
145
|
+
translation = translation.replace(new RegExp(`{{\\s*${paramKey}\\s*}}`, 'g'), paramValue);
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
// Replace translations like {{ t('key') }}
|
|
149
|
+
const translationPattern = /{{\s*t\('([^']+)'\)\s*}}/g;
|
|
150
|
+
translation = translation.replace(translationPattern, (match, innerKey) => {
|
|
151
|
+
return this.getTranslation(innerKey, lang, scope, params);
|
|
152
|
+
});
|
|
153
|
+
return translation;
|
|
154
|
+
}
|
|
155
|
+
translate(key, options) {
|
|
156
|
+
if (options?.lang) {
|
|
157
|
+
return this.load(key, options);
|
|
158
|
+
}
|
|
159
|
+
return this.langChanges$.pipe(startWith(this.getActiveLang()), switchMap((lang) => {
|
|
160
|
+
return this.load(key, { ...options, lang: lang });
|
|
161
|
+
}));
|
|
162
|
+
}
|
|
163
|
+
async translateAsync(key, options) {
|
|
164
|
+
const { lang = this.getActiveLang(), scope = this.config.defaultScope } = options || {};
|
|
165
|
+
let translation = get(this.translationCache, `${lang}.${scope}.${key}`);
|
|
166
|
+
if (!translation) {
|
|
167
|
+
// If the translation is not in the cache, load it
|
|
168
|
+
await firstValueFrom(this.load(key, { lang, scope }).pipe(take(1)));
|
|
169
|
+
translation = get(this.translationCache, `${lang}.${scope}.${key}`);
|
|
170
|
+
}
|
|
171
|
+
// If still not available, try the last active language or default language
|
|
172
|
+
if (!translation && this.lastActiveLang) {
|
|
173
|
+
translation = get(this.translationCache, `${this.lastActiveLang}.${scope}.${key}`);
|
|
174
|
+
}
|
|
175
|
+
if (!translation) {
|
|
176
|
+
translation = get(this.translationCache, `${this.getDefaultLang()}.${scope}.${key}`);
|
|
177
|
+
}
|
|
178
|
+
// Perform parameter replacement
|
|
179
|
+
return this.getTranslation((translation || key), lang, scope, options?.params);
|
|
180
|
+
}
|
|
181
|
+
translateSync(key, options) {
|
|
182
|
+
const { lang = this.getActiveLang(), scope = this.config.defaultScope } = options || {};
|
|
183
|
+
// Check if the translation for the active language is available
|
|
184
|
+
let translation = get(this.translationCache, `${lang}.${scope}.${key}`);
|
|
185
|
+
// If not available, check lastActiveLang
|
|
186
|
+
if (!translation && this.lastActiveLang) {
|
|
187
|
+
translation = get(this.translationCache, `${this.lastActiveLang}.${scope}.${key}`);
|
|
188
|
+
}
|
|
189
|
+
// If still not available, use the default language
|
|
190
|
+
if (!translation) {
|
|
191
|
+
translation = get(this.translationCache, `${this.getDefaultLang()}.${scope}.${key}`);
|
|
192
|
+
}
|
|
193
|
+
// Perform parameter replacement
|
|
194
|
+
return this.getTranslation((translation || key), lang, scope, options?.params);
|
|
195
|
+
}
|
|
196
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.2", ngImport: i0, type: AXTranslationService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
197
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.2", ngImport: i0, type: AXTranslationService, providedIn: 'root' }); }
|
|
198
|
+
}
|
|
199
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.2", ngImport: i0, type: AXTranslationService, decorators: [{
|
|
200
|
+
type: Injectable,
|
|
201
|
+
args: [{ providedIn: 'root' }]
|
|
202
|
+
}], ctorParameters: () => [] });
|
|
203
|
+
|
|
204
|
+
class AXTranslatorPipe {
|
|
205
|
+
constructor(service) {
|
|
206
|
+
this.service = service;
|
|
207
|
+
}
|
|
208
|
+
transform(key, options) {
|
|
209
|
+
if (!key) {
|
|
210
|
+
return of(''); // Return an empty observable if the key is not provided
|
|
211
|
+
}
|
|
212
|
+
return this.service.translate(key, options);
|
|
213
|
+
}
|
|
214
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.2", ngImport: i0, type: AXTranslatorPipe, deps: [{ token: AXTranslationService }], target: i0.ɵɵFactoryTarget.Pipe }); }
|
|
215
|
+
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "17.3.2", ngImport: i0, type: AXTranslatorPipe, name: "translate" }); }
|
|
216
|
+
}
|
|
217
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.2", ngImport: i0, type: AXTranslatorPipe, decorators: [{
|
|
218
|
+
type: Pipe,
|
|
219
|
+
args: [{ name: 'translate', pure: true }]
|
|
220
|
+
}], ctorParameters: () => [{ type: AXTranslationService }] });
|
|
221
|
+
|
|
222
|
+
class AXTranslatorDirective {
|
|
223
|
+
constructor(templateRef, viewContainer, translationService) {
|
|
224
|
+
this.templateRef = templateRef;
|
|
225
|
+
this.viewContainer = viewContainer;
|
|
226
|
+
this.translationService = translationService;
|
|
227
|
+
}
|
|
228
|
+
ngOnInit() {
|
|
229
|
+
this.viewContainer.clear();
|
|
230
|
+
this.viewContainer.createEmbeddedView(this.templateRef, {
|
|
231
|
+
$implicit: (key, options) => {
|
|
232
|
+
return this.translationService.translate(key, options);
|
|
233
|
+
},
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.2", ngImport: i0, type: AXTranslatorDirective, deps: [{ token: i0.TemplateRef }, { token: i0.ViewContainerRef }, { token: AXTranslationService }], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
237
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "17.3.2", type: AXTranslatorDirective, selector: "[translate]", ngImport: i0 }); }
|
|
238
|
+
}
|
|
239
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.2", ngImport: i0, type: AXTranslatorDirective, decorators: [{
|
|
240
|
+
type: Directive,
|
|
241
|
+
args: [{
|
|
242
|
+
selector: '[translate]',
|
|
243
|
+
}]
|
|
244
|
+
}], ctorParameters: () => [{ type: i0.TemplateRef }, { type: i0.ViewContainerRef }, { type: AXTranslationService }] });
|
|
245
|
+
|
|
246
|
+
function initializeApp(translatorService, config) {
|
|
247
|
+
return () => {
|
|
248
|
+
return translatorService.loadLanguagesAndScopes(config.preloadLangs ?? [config.defaultLang], config.preloadScopes ?? [config.defaultScope]);
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
class AXTranslationModule {
|
|
252
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.2", ngImport: i0, type: AXTranslationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
253
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.3.2", ngImport: i0, type: AXTranslationModule, declarations: [AXTranslatorPipe, AXTranslatorDirective], exports: [AXTranslatorPipe, AXTranslatorDirective] }); }
|
|
254
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.3.2", ngImport: i0, type: AXTranslationModule, providers: [
|
|
255
|
+
{
|
|
256
|
+
provide: APP_INITIALIZER,
|
|
257
|
+
useFactory: initializeApp,
|
|
258
|
+
deps: [AXTranslationService, AX_TRANSLATION_CONFIG],
|
|
259
|
+
multi: true,
|
|
260
|
+
},
|
|
261
|
+
] }); }
|
|
262
|
+
}
|
|
263
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.2", ngImport: i0, type: AXTranslationModule, decorators: [{
|
|
264
|
+
type: NgModule,
|
|
265
|
+
args: [{
|
|
266
|
+
imports: [],
|
|
267
|
+
exports: [AXTranslatorPipe, AXTranslatorDirective],
|
|
268
|
+
declarations: [AXTranslatorPipe, AXTranslatorDirective],
|
|
269
|
+
providers: [
|
|
270
|
+
{
|
|
271
|
+
provide: APP_INITIALIZER,
|
|
272
|
+
useFactory: initializeApp,
|
|
273
|
+
deps: [AXTranslationService, AX_TRANSLATION_CONFIG],
|
|
274
|
+
multi: true,
|
|
275
|
+
},
|
|
276
|
+
],
|
|
277
|
+
}]
|
|
278
|
+
}] });
|
|
279
|
+
|
|
280
|
+
const loadTranslationScope = (route, state) => {
|
|
281
|
+
const translatorService = inject(AXTranslationService);
|
|
282
|
+
const config = inject(AX_TRANSLATION_CONFIG);
|
|
283
|
+
const scopeValue = route.data[config.scopeResolverKey];
|
|
284
|
+
const scopes = Array.isArray(scopeValue) ? scopeValue : [scopeValue];
|
|
285
|
+
return translatorService.loadLanguagesAndScopes([translatorService.getActiveLang()], scopes);
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Generated bundle index. Do not edit.
|
|
290
|
+
*/
|
|
291
|
+
|
|
292
|
+
export { AXTranslationDefaultConfig, AXTranslationLoaderDefault, AXTranslationModule, AXTranslationService, AXTranslatorDirective, AXTranslatorPipe, AX_TRANSLATION_CONFIG, AX_TRANSLATION_LOADER, loadTranslationScope, translateSync, translationConfig };
|
|
293
|
+
//# sourceMappingURL=acorex-core-translation.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acorex-core-translation.mjs","sources":["../../../../libs/core/translation/src/lib/translation.config.ts","../../../../libs/core/translation/src/lib/translation.loader.ts","../../../../libs/core/translation/src/lib/translation.service.ts","../../../../libs/core/translation/src/lib/translator.pipe.ts","../../../../libs/core/translation/src/lib/translator.directive.ts","../../../../libs/core/translation/src/lib/translation.module.ts","../../../../libs/core/translation/src/lib/translation-scope.resolver.ts","../../../../libs/core/translation/src/acorex-core-translation.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\nimport { AXTranslateLang, AXTranslateScope } from './translation.types';\n\nexport interface AXTranslationConfig {\n defaultLang: AXTranslateLang;\n defaultScope: AXTranslateScope;\n preloadLangs?: AXTranslateLang[];\n preloadScopes?: AXTranslateLang[];\n availableLangs?: AXTranslateLang[];\n scopeResolverKey: string;\n}\n\nexport const AX_TRANSLATION_CONFIG = new InjectionToken<AXTranslationConfig>(\n 'AX_TRANSLATION_CONFIG',\n {\n providedIn: 'root',\n factory: () => {\n return AXTranslationDefaultConfig;\n },\n }\n);\n\nexport const AXTranslationDefaultConfig: AXTranslationConfig = {\n defaultLang: 'en',\n defaultScope: 'common',\n scopeResolverKey: 'scope',\n};\n\nexport type AXPartialTranslationConfig = Partial<AXTranslationConfig>;\n\nexport function translationConfig(\n config: AXPartialTranslationConfig = {}\n): AXTranslationConfig {\n const result = {\n ...AXTranslationDefaultConfig,\n ...config,\n };\n return result;\n}\n","import { InjectionToken } from '@angular/core';\nimport {\n AXTranslateLang,\n AXTranslateScope,\n AXTranslation,\n} from './translation.types';\nimport { Observable, of } from 'rxjs';\n\nexport interface AXTranslationLoaderOptions {\n lang: AXTranslateLang;\n scope?: AXTranslateScope;\n}\n\nexport interface AXTranslationLoader {\n getTranslation(\n options: AXTranslationLoaderOptions\n ): Observable<AXTranslation>;\n}\n\nexport class AXTranslationLoaderDefault implements AXTranslationLoader {\n getTranslation(\n options: AXTranslationLoaderOptions\n ): Observable<AXTranslation> {\n return of({});\n }\n}\n\nexport const AX_TRANSLATION_LOADER = new InjectionToken<AXTranslationLoader>(\n 'AX_TRANSLATION_LOADER',\n {\n providedIn: 'root',\n factory: () => {\n return new AXTranslationLoaderDefault();\n },\n }\n);\n","import { Injectable, inject } from '@angular/core';\nimport {\n BehaviorSubject,\n Observable,\n catchError,\n finalize,\n firstValueFrom,\n forkJoin,\n map,\n of,\n shareReplay,\n startWith,\n switchMap,\n take,\n tap,\n} from 'rxjs';\nimport {\n AXTranslateHashMap,\n AXTranslateOptions,\n AXTranslateParams,\n} from './translation.types';\nimport { AX_TRANSLATION_LOADER } from './translation.loader';\nimport { set as lodashSet, get as lodashGet } from 'lodash-es';\nimport { AX_TRANSLATION_CONFIG } from './translation.config';\nimport { AXEventService, AXEventTypes } from '@acorex/core/events';\n\nlet service: AXTranslationService;\n\nexport function translateSync(\n key: string,\n options?: AXTranslateOptions\n): string {\n return service.translateSync(key, options);\n}\n\n@Injectable({ providedIn: 'root' })\nexport class AXTranslationService {\n private loader = inject(AX_TRANSLATION_LOADER);\n private config = inject(AX_TRANSLATION_CONFIG);\n\n private eventService = inject(AXEventService);\n\n private translationCache: AXTranslateHashMap<AXTranslateHashMap<string>> = {};\n private ongoingRequests: Map<string, Observable<any>> = new Map();\n\n private activeLang: BehaviorSubject<string> = new BehaviorSubject<string>(\n this.getDefaultLang()\n );\n langChanges$: Observable<string> = this.activeLang.asObservable();\n\n private lastActiveLang: string | null = null;\n\n /**\n * @ignore\n */\n constructor() {\n service = this;\n }\n\n public loadLanguagesAndScopes(\n languages: string[],\n scopes: string[]\n ): Observable<unknown> {\n const requests = languages.flatMap((lang) =>\n scopes.map((scope) => {\n // Check if translations are already cached\n if (this.translationCache[lang]?.[scope]) {\n return of(this.translationCache[lang][scope]);\n }\n\n // Use the new method to handle ongoing requests and loading\n return this.getOrLoadTranslations(lang, scope);\n })\n );\n\n return forkJoin(requests);\n }\n\n private getOrLoadTranslations(\n lang: string,\n scope: string\n ): Observable<AXTranslateHashMap<string>> {\n const requestKey = `${lang}_${scope}`;\n\n // Return existing observable if the request is already in progress\n if (this.ongoingRequests.has(requestKey)) {\n return this.ongoingRequests.get(requestKey);\n }\n\n // Load translations if not in cache or ongoing requests\n const translationObservable = this.loader\n .getTranslation({ lang, scope })\n .pipe(\n tap((translations) =>\n this.cacheTranslations(lang, scope, translations)\n ),\n catchError((error) => {\n console.error(\n `Error loading translations for lang: ${lang}, scope: ${scope}`,\n error\n );\n return of(null);\n }),\n finalize(() => {\n this.eventService.emitEvent({\n type: AXEventTypes.AXLanguageLoaded,\n payload: lang,\n });\n this.ongoingRequests.delete(requestKey);\n }),\n shareReplay(1)\n );\n\n this.ongoingRequests.set(requestKey, translationObservable);\n return translationObservable;\n }\n\n private cacheTranslations(\n lang: string,\n scope: string,\n translations: AXTranslateHashMap<string>\n ): void {\n lodashSet(this.translationCache, `${lang}.${scope}`, translations);\n }\n\n public getDefaultLang(): string {\n return this.config.defaultLang;\n }\n\n public getActiveLang(): string {\n return this.activeLang.getValue();\n }\n\n public setActiveLang(lang: string): void {\n if (lang != this.getActiveLang()) {\n this.lastActiveLang = this.getActiveLang(); // Update last active language\n this.activeLang.next(lang);\n this.eventService.emitEvent({\n type: AXEventTypes.AXLanguageChanged,\n payload: lang,\n });\n }\n }\n\n private load(\n key: string,\n options: AXTranslateOptions = {}\n ): Observable<string> {\n const { lang = this.getActiveLang(), scope = this.config.defaultScope } =\n options;\n\n // Function to fetch translation\n const fetchTranslation = (language: string): Observable<string> => {\n // Check if translations are available in the cache\n if (this.translationCache[language]?.[scope]) {\n return of(this.getTranslation(key, language, scope, options.params));\n }\n\n // Use the new method to handle ongoing requests and loading\n return this.getOrLoadTranslations(language, scope).pipe(\n map(() => {\n const translation =\n this.translationCache[language]?.[scope]?.[key] || key;\n return this.getTranslation(\n translation,\n language,\n scope,\n options.params\n );\n }),\n switchMap((translatedText) => {\n if (translatedText === key && language !== this.getDefaultLang()) {\n // If the translation is not found and the language is not default,\n // try fetching from the default language\n return fetchTranslation(this.getDefaultLang());\n }\n return of(translatedText);\n })\n );\n };\n\n // First, try to fetch the translation for the requested language\n const translationForRequestedLang = fetchTranslation(lang);\n\n // If lastActiveLang is available and different from the requested language, use it as a fallback\n if (this.lastActiveLang && this.lastActiveLang !== lang) {\n const translationForLastActiveLang = this.getTranslation(\n key,\n this.lastActiveLang,\n scope,\n options.params\n );\n return translationForRequestedLang.pipe(\n startWith(translationForLastActiveLang)\n );\n }\n\n return translationForRequestedLang;\n }\n\n private getTranslation(\n key: string,\n lang: string,\n scope: string,\n params?: AXTranslateParams\n ): string {\n let translation: string = (lodashGet(\n this.translationCache,\n `${lang}.${scope}.${key}`\n ) || key) as string;\n\n // Replace params like {{ name }}\n if (params) {\n Object.keys(params).forEach((paramKey) => {\n const paramValue = params[paramKey] as string;\n translation = translation.replace(\n new RegExp(`{{\\\\s*${paramKey}\\\\s*}}`, 'g'),\n paramValue\n );\n });\n }\n\n // Replace translations like {{ t('key') }}\n const translationPattern = /{{\\s*t\\('([^']+)'\\)\\s*}}/g;\n translation = translation.replace(translationPattern, (match, innerKey) => {\n return this.getTranslation(innerKey, lang, scope, params);\n });\n return translation;\n }\n\n public translate(\n key: string,\n options?: AXTranslateOptions\n ): Observable<string> {\n if (options?.lang) {\n return this.load(key, options);\n }\n return this.langChanges$.pipe(\n startWith(this.getActiveLang()),\n switchMap((lang) => {\n return this.load(key, { ...options, lang: lang });\n })\n );\n }\n\n public async translateAsync(\n key: string,\n options?: AXTranslateOptions\n ): Promise<string> {\n const { lang = this.getActiveLang(), scope = this.config.defaultScope } =\n options || {};\n let translation = lodashGet(\n this.translationCache,\n `${lang}.${scope}.${key}`\n );\n\n if (!translation) {\n // If the translation is not in the cache, load it\n await firstValueFrom(this.load(key, { lang, scope }).pipe(take(1)));\n translation = lodashGet(this.translationCache, `${lang}.${scope}.${key}`);\n }\n\n // If still not available, try the last active language or default language\n if (!translation && this.lastActiveLang) {\n translation = lodashGet(\n this.translationCache,\n `${this.lastActiveLang}.${scope}.${key}`\n );\n }\n if (!translation) {\n translation = lodashGet(\n this.translationCache,\n `${this.getDefaultLang()}.${scope}.${key}`\n );\n }\n\n // Perform parameter replacement\n return this.getTranslation(\n (translation || key) as any,\n lang,\n scope,\n options?.params\n );\n }\n\n public translateSync(key: string, options?: AXTranslateOptions): string {\n const { lang = this.getActiveLang(), scope = this.config.defaultScope } =\n options || {};\n\n // Check if the translation for the active language is available\n let translation = lodashGet(\n this.translationCache,\n `${lang}.${scope}.${key}`\n );\n\n // If not available, check lastActiveLang\n if (!translation && this.lastActiveLang) {\n translation = lodashGet(\n this.translationCache,\n `${this.lastActiveLang}.${scope}.${key}`\n );\n }\n\n // If still not available, use the default language\n if (!translation) {\n translation = lodashGet(\n this.translationCache,\n `${this.getDefaultLang()}.${scope}.${key}`\n );\n }\n\n // Perform parameter replacement\n return this.getTranslation(\n (translation || key) as any,\n lang,\n scope,\n options?.params\n );\n }\n}\n","import { Pipe, PipeTransform } from '@angular/core';\nimport { AXTranslationService } from './translation.service';\nimport { Observable, of } from 'rxjs';\nimport { AXTranslateOptions } from './translation.types';\n\n@Pipe({ name: 'translate', pure: true }) // The pipe can now be pure\nexport class AXTranslatorPipe implements PipeTransform {\n constructor(private service: AXTranslationService) {}\n\n transform(key: string, options?: AXTranslateOptions): Observable<string> {\n if (!key) {\n return of(''); // Return an empty observable if the key is not provided\n }\n return this.service.translate(key, options);\n }\n}\n","import {\n Directive,\n OnInit,\n TemplateRef,\n ViewContainerRef,\n} from '@angular/core';\nimport { AXTranslationService } from './translation.service';\nimport { AXTranslateOptions } from './translation.types';\n\n@Directive({\n selector: '[translate]',\n})\nexport class AXTranslatorDirective implements OnInit {\n constructor(\n private templateRef: TemplateRef<any>,\n private viewContainer: ViewContainerRef,\n private translationService: AXTranslationService\n ) {}\n\n ngOnInit() {\n this.viewContainer.clear();\n this.viewContainer.createEmbeddedView(this.templateRef, {\n $implicit: (key: string, options?: AXTranslateOptions) => {\n return this.translationService.translate(key, options);\n },\n });\n }\n}\n","import { APP_INITIALIZER, NgModule } from '@angular/core';\nimport { AXTranslatorPipe } from './translator.pipe';\nimport { AXTranslatorDirective } from './translator.directive';\nimport { AXTranslationService } from './translation.service';\nimport { Observable } from 'rxjs';\nimport {\n AXTranslationConfig,\n AX_TRANSLATION_CONFIG,\n} from './translation.config';\n\nfunction initializeApp(\n translatorService: AXTranslationService,\n config: AXTranslationConfig\n) {\n return (): Observable<any> => {\n return translatorService.loadLanguagesAndScopes(\n config.preloadLangs ?? [config.defaultLang],\n config.preloadScopes ?? [config.defaultScope]\n );\n };\n}\n\n@NgModule({\n imports: [],\n exports: [AXTranslatorPipe, AXTranslatorDirective],\n declarations: [AXTranslatorPipe, AXTranslatorDirective],\n providers: [\n {\n provide: APP_INITIALIZER,\n useFactory: initializeApp,\n deps: [AXTranslationService, AX_TRANSLATION_CONFIG],\n multi: true,\n },\n ],\n})\nexport class AXTranslationModule {}\n","import { inject } from '@angular/core';\nimport { AXTranslationService } from './translation.service';\nimport { ResolveFn } from '@angular/router';\nimport { AX_TRANSLATION_CONFIG } from './translation.config';\n\nexport const loadTranslationScope: ResolveFn<unknown> = (route, state) => {\n const translatorService = inject(AXTranslationService);\n const config = inject(AX_TRANSLATION_CONFIG);\n const scopeValue = route.data[config.scopeResolverKey];\n const scopes = Array.isArray(scopeValue) ? scopeValue : [scopeValue];\n return translatorService.loadLanguagesAndScopes(\n [translatorService.getActiveLang()],\n scopes\n );\n};\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":["lodashSet","lodashGet","i1.AXTranslationService"],"mappings":";;;;;;MAYa,qBAAqB,GAAG,IAAI,cAAc,CACrD,uBAAuB,EACvB;AACE,IAAA,UAAU,EAAE,MAAM;IAClB,OAAO,EAAE,MAAK;AACZ,QAAA,OAAO,0BAA0B,CAAC;KACnC;AACF,CAAA,EACD;AAEW,MAAA,0BAA0B,GAAwB;AAC7D,IAAA,WAAW,EAAE,IAAI;AACjB,IAAA,YAAY,EAAE,QAAQ;AACtB,IAAA,gBAAgB,EAAE,OAAO;EACzB;AAIc,SAAA,iBAAiB,CAC/B,MAAA,GAAqC,EAAE,EAAA;AAEvC,IAAA,MAAM,MAAM,GAAG;AACb,QAAA,GAAG,0BAA0B;AAC7B,QAAA,GAAG,MAAM;KACV,CAAC;AACF,IAAA,OAAO,MAAM,CA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OAAO,CAAC,UAAU,CAAC,GAAG,UAAU,GAAG,CAAC,UAAU,CAAC,CAAC;AACrE,IAAA,OAAO,iBAAiB,CAAC,sBAAsB,CAC7C,CAAC,iBAAiB,CAAC,aAAa,EAAE,CAAC,EACnC,MAAM,CACP,CAAC;AACJ;;ACdA;;AAEG;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acorex-core-types.mjs","sources":["../../../../libs/core/types/src/index.ts","../../../../libs/core/types/src/acorex-core-types.ts"],"sourcesContent":["export default {};\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":"AAAA,YAAe,EAAE;;ACAjB;;AAEG"}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { Injectable } from '@angular/core';
|
|
3
|
+
import { Subject, takeUntil } from 'rxjs';
|
|
4
|
+
import tinycolor from 'tinycolor2';
|
|
5
|
+
import tinygradient from 'tinygradient-es';
|
|
6
|
+
|
|
7
|
+
function AXAutoUnsubscriber() {
|
|
8
|
+
return function (constructor) {
|
|
9
|
+
const orig = constructor.prototype.ngOnDestroy;
|
|
10
|
+
constructor.prototype.ngOnDestroy = function () {
|
|
11
|
+
for (const prop in this) {
|
|
12
|
+
const property = this[prop];
|
|
13
|
+
if (typeof property.subscribe === 'function') {
|
|
14
|
+
property.unsubscribe();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
orig.apply();
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
class AXUnsubscriber {
|
|
22
|
+
constructor() {
|
|
23
|
+
this._destroy$ = new Subject();
|
|
24
|
+
this.takeUntilDestroy = (origin) => origin.pipe(takeUntil(this._destroy$));
|
|
25
|
+
}
|
|
26
|
+
unsubscribe() {
|
|
27
|
+
this._destroy$.next();
|
|
28
|
+
this._destroy$.complete();
|
|
29
|
+
}
|
|
30
|
+
ngOnDestroy() {
|
|
31
|
+
this.unsubscribe();
|
|
32
|
+
}
|
|
33
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.2", ngImport: i0, type: AXUnsubscriber, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
34
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.2", ngImport: i0, type: AXUnsubscriber }); }
|
|
35
|
+
}
|
|
36
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.2", ngImport: i0, type: AXUnsubscriber, decorators: [{
|
|
37
|
+
type: Injectable
|
|
38
|
+
}] });
|
|
39
|
+
|
|
40
|
+
class AXColorUtil {
|
|
41
|
+
static to(color, mode) {
|
|
42
|
+
const _color = tinycolor(color);
|
|
43
|
+
switch (mode) {
|
|
44
|
+
case 'rgba':
|
|
45
|
+
return _color.toRgb();
|
|
46
|
+
case 'hsla':
|
|
47
|
+
return _color.toHsl();
|
|
48
|
+
case 'hsva':
|
|
49
|
+
return _color.toHsv();
|
|
50
|
+
default:
|
|
51
|
+
return _color.toHex();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
static toString(color, mode = null) {
|
|
55
|
+
const _color = tinycolor(color);
|
|
56
|
+
switch (mode) {
|
|
57
|
+
case 'rgba':
|
|
58
|
+
return _color.toRgbString();
|
|
59
|
+
case 'hsla':
|
|
60
|
+
return _color.toHslString();
|
|
61
|
+
case 'hsva':
|
|
62
|
+
return _color.toHsvString();
|
|
63
|
+
case 'hex': {
|
|
64
|
+
const rgba = _color.toRgb();
|
|
65
|
+
return rgba.a != 1 ? _color.toHex8String() : _color.toHexString();
|
|
66
|
+
}
|
|
67
|
+
default: {
|
|
68
|
+
if (typeof color == 'string') {
|
|
69
|
+
if (color.toLowerCase().startsWith('#'))
|
|
70
|
+
return this.toString(color, 'hex');
|
|
71
|
+
else
|
|
72
|
+
return this.toString(color, 'rgba');
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
return this.toString(color, 'rgba');
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
static isValid(color) {
|
|
81
|
+
const _color = tinycolor(color);
|
|
82
|
+
return _color.isValid();
|
|
83
|
+
}
|
|
84
|
+
static mix(baseColor, hex, percentage) {
|
|
85
|
+
return tinycolor.mix(baseColor, hex, percentage).toString('rgb');
|
|
86
|
+
}
|
|
87
|
+
static multiply(color1, color2) {
|
|
88
|
+
const rgb1 = tinycolor(color1).toRgb();
|
|
89
|
+
const rgb2 = tinycolor(color2).toRgb();
|
|
90
|
+
rgb1.b = Math.floor((rgb1.b * rgb2.b) / 255);
|
|
91
|
+
rgb1.g = Math.floor((rgb1.g * rgb2.g) / 255);
|
|
92
|
+
rgb1.r = Math.floor((rgb1.r * rgb2.r) / 255);
|
|
93
|
+
return tinycolor('rgb ' + rgb1.r + ' ' + rgb1.g + ' ' + rgb1.b).toString('rgb');
|
|
94
|
+
}
|
|
95
|
+
static contrastToWhite(color) {
|
|
96
|
+
return tinycolor.readability('#fff', color);
|
|
97
|
+
}
|
|
98
|
+
static lighten(hex, percentage) {
|
|
99
|
+
return tinycolor(hex).lighten(percentage);
|
|
100
|
+
}
|
|
101
|
+
static darken(hex, percentage) {
|
|
102
|
+
return tinycolor(hex).darken(percentage);
|
|
103
|
+
}
|
|
104
|
+
static brighten(hex, percentage) {
|
|
105
|
+
return tinycolor(hex).brighten(percentage);
|
|
106
|
+
}
|
|
107
|
+
static saturate(hex, percentage) {
|
|
108
|
+
return tinycolor(hex).saturate(percentage);
|
|
109
|
+
}
|
|
110
|
+
static desaturate(hex) {
|
|
111
|
+
return tinycolor(hex).getLuminance();
|
|
112
|
+
}
|
|
113
|
+
static equal(color1, color2) {
|
|
114
|
+
return tinycolor.equals(color1, color2);
|
|
115
|
+
}
|
|
116
|
+
static gradient(values) {
|
|
117
|
+
return tinygradient([...values]);
|
|
118
|
+
}
|
|
119
|
+
static getLuminance(hex) {
|
|
120
|
+
return tinycolor(hex).getLuminance();
|
|
121
|
+
}
|
|
122
|
+
static xyToRgb(vX, vY) {
|
|
123
|
+
vY = vY || 0.00000000001;
|
|
124
|
+
const Y = 1;
|
|
125
|
+
const X = (Y / vY) * vX;
|
|
126
|
+
const Z = (Y / vY) * (1 - vX - vY);
|
|
127
|
+
// Convert to RGB using Wide RGB D65 conversion.
|
|
128
|
+
let rgb = [
|
|
129
|
+
X * 1.656492 - Y * 0.354851 - Z * 0.255038,
|
|
130
|
+
-X * 0.707196 + Y * 1.655397 + Z * 0.036152,
|
|
131
|
+
X * 0.051713 - Y * 0.121364 + Z * 1.01153,
|
|
132
|
+
];
|
|
133
|
+
// Apply reverse gamma correction.
|
|
134
|
+
rgb = rgb.map((x) => x <= 0.0031308
|
|
135
|
+
? 12.92 * x
|
|
136
|
+
: (1.0 + 0.055) * Math.pow(x, 1.0 / 2.4) - 0.055);
|
|
137
|
+
// Bring all negative components to zero.
|
|
138
|
+
rgb = rgb.map((x) => Math.max(0, x));
|
|
139
|
+
// If one component is greater than 1, weight components by that value.
|
|
140
|
+
const max = Math.max(...rgb);
|
|
141
|
+
if (max > 1) {
|
|
142
|
+
rgb = rgb.map((x) => x / max);
|
|
143
|
+
}
|
|
144
|
+
rgb = rgb.map((x) => Math.round(x * 255));
|
|
145
|
+
return 'rgb(' + rgb.join(',') + ')';
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// @dynamic
|
|
150
|
+
class AXDrawingUtil {
|
|
151
|
+
static collision(a, b) {
|
|
152
|
+
const ac = a.getBoundingClientRect();
|
|
153
|
+
const bc = b.getBoundingClientRect();
|
|
154
|
+
if (ac.left < bc.left + bc.width &&
|
|
155
|
+
ac.left + ac.width > bc.left &&
|
|
156
|
+
ac.top < bc.top + bc.height &&
|
|
157
|
+
ac.top + ac.height > bc.top) {
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
static isInElementBound(pos, element) {
|
|
165
|
+
const elBound = element.getBoundingClientRect();
|
|
166
|
+
return AXDrawingUtil.isInRecPoint(pos, {
|
|
167
|
+
left: elBound.x,
|
|
168
|
+
width: elBound.width,
|
|
169
|
+
top: elBound.y,
|
|
170
|
+
height: elBound.height,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
static isInRecPoint(pos, rec) {
|
|
174
|
+
return (pos.x >= rec.left &&
|
|
175
|
+
pos.x <= rec.left + rec.width &&
|
|
176
|
+
pos.y >= rec.top &&
|
|
177
|
+
pos.y <= rec.top + rec.height);
|
|
178
|
+
}
|
|
179
|
+
static convertRemToPixels(rem) {
|
|
180
|
+
return (rem * parseFloat(getComputedStyle(document.documentElement).fontSize));
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// @dynamic
|
|
185
|
+
class AXHtmlUtil {
|
|
186
|
+
static focusElement(element) {
|
|
187
|
+
const list = [
|
|
188
|
+
'button',
|
|
189
|
+
'input',
|
|
190
|
+
'[href]',
|
|
191
|
+
'select',
|
|
192
|
+
'textarea',
|
|
193
|
+
'[tabindex]',
|
|
194
|
+
].map((c) => c + ':not([tabindex="-1"])');
|
|
195
|
+
const focusable = element.querySelector(list.join(', '));
|
|
196
|
+
if (focusable) {
|
|
197
|
+
focusable.focus();
|
|
198
|
+
return focusable;
|
|
199
|
+
}
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
static blurElement(element) {
|
|
203
|
+
const list = [
|
|
204
|
+
'button',
|
|
205
|
+
'input',
|
|
206
|
+
'[href]',
|
|
207
|
+
'select',
|
|
208
|
+
'textarea',
|
|
209
|
+
'[tabindex]',
|
|
210
|
+
].map((c) => c + ':not([tabindex="-1"])');
|
|
211
|
+
const focusable = element.querySelector(list.join(', '));
|
|
212
|
+
if (focusable) {
|
|
213
|
+
focusable.blur();
|
|
214
|
+
return focusable;
|
|
215
|
+
}
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
static hasFocus(element) {
|
|
219
|
+
return element.matches(':focus-within') || element.matches(':focus');
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// @dynamic
|
|
224
|
+
class AXStringUtil {
|
|
225
|
+
static getWordBoundsAtPosition(str, position) {
|
|
226
|
+
const isSpace = (c) => /[^a-zA-Z0-9]+/i.test(c);
|
|
227
|
+
let start = position - 1;
|
|
228
|
+
while (start >= 0 && !isSpace(str[start])) {
|
|
229
|
+
start -= 1;
|
|
230
|
+
}
|
|
231
|
+
start = Math.max(0, start + 1);
|
|
232
|
+
const leftSideString = str.slice(start).match(/[a-zA-Z0-9]+/i);
|
|
233
|
+
start += leftSideString.index;
|
|
234
|
+
let end = start + leftSideString[0].length;
|
|
235
|
+
return {
|
|
236
|
+
start,
|
|
237
|
+
end,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Generated bundle index. Do not edit.
|
|
244
|
+
*/
|
|
245
|
+
|
|
246
|
+
export { AXAutoUnsubscriber, AXColorUtil, AXDrawingUtil, AXHtmlUtil, AXStringUtil, AXUnsubscriber };
|
|
247
|
+
//# sourceMappingURL=acorex-core-utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acorex-core-utils.mjs","sources":["../../../../libs/core/utils/src/lib/auto-unsubscribe.ts","../../../../libs/core/utils/src/lib/color-util.ts","../../../../libs/core/utils/src/lib/drawing-util.ts","../../../../libs/core/utils/src/lib/html-util.ts","../../../../libs/core/utils/src/lib/string-util.ts","../../../../libs/core/utils/src/acorex-core-utils.ts"],"sourcesContent":["import { Injectable, OnDestroy } from '@angular/core';\nimport { Observable, Subject, takeUntil } from 'rxjs';\n\nexport function AXAutoUnsubscriber() {\n return function (constructor) {\n const orig = constructor.prototype.ngOnDestroy;\n constructor.prototype.ngOnDestroy = function () {\n for (const prop in this) {\n const property = this[prop];\n if (typeof property.subscribe === 'function') {\n property.unsubscribe();\n }\n }\n orig.apply();\n };\n };\n}\n\n@Injectable()\nexport class AXUnsubscriber implements OnDestroy {\n private readonly _destroy$ = new Subject<void>();\n\n public readonly takeUntilDestroy = <T>(\n origin: Observable<T> | Subject<T>\n ): Observable<T> | Subject<T> => origin.pipe(takeUntil(this._destroy$));\n\n public unsubscribe(): void {\n this._destroy$.next();\n this._destroy$.complete();\n }\n\n public ngOnDestroy(): void {\n this.unsubscribe();\n }\n}\n","export type AXColorMode = 'rgba' | 'hex' | 'hsla' | 'hsva' | null;\n\nimport tinycolor, { ColorInput } from 'tinycolor2';\nimport tinygradient, { Instance } from 'tinygradient-es';\n\nexport type AXColorFormat = ColorInput;\n\nexport class AXColorUtil {\n static to(color: AXColorFormat, mode: AXColorMode): AXColorFormat {\n const _color = tinycolor(color);\n switch (mode) {\n case 'rgba':\n return _color.toRgb();\n case 'hsla':\n return _color.toHsl();\n case 'hsva':\n return _color.toHsv();\n default:\n return _color.toHex();\n }\n }\n\n static toString(color: AXColorFormat, mode: AXColorMode = null): string {\n const _color = tinycolor(color);\n switch (mode) {\n case 'rgba':\n return _color.toRgbString();\n case 'hsla':\n return _color.toHslString();\n case 'hsva':\n return _color.toHsvString();\n\n case 'hex': {\n const rgba = _color.toRgb();\n return rgba.a != 1 ? _color.toHex8String() : _color.toHexString();\n }\n default: {\n if (typeof color == 'string') {\n if (color.toLowerCase().startsWith('#'))\n return this.toString(color, 'hex');\n else return this.toString(color, 'rgba');\n } else {\n return this.toString(color, 'rgba');\n }\n }\n }\n }\n\n static isValid(color: AXColorFormat): boolean {\n const _color = tinycolor(color);\n return _color.isValid();\n }\n\n static mix(\n baseColor: AXColorFormat,\n hex: AXColorFormat,\n percentage: number\n ): string {\n return tinycolor.mix(baseColor, hex, percentage).toString('rgb');\n }\n\n static multiply(color1: AXColorFormat, color2: AXColorFormat): string {\n const rgb1 = tinycolor(color1).toRgb();\n const rgb2 = tinycolor(color2).toRgb();\n rgb1.b = Math.floor((rgb1.b * rgb2.b) / 255);\n rgb1.g = Math.floor((rgb1.g * rgb2.g) / 255);\n rgb1.r = Math.floor((rgb1.r * rgb2.r) / 255);\n return tinycolor('rgb ' + rgb1.r + ' ' + rgb1.g + ' ' + rgb1.b).toString(\n 'rgb'\n );\n }\n\n static contrastToWhite(color: AXColorFormat): number {\n return tinycolor.readability('#fff', color);\n }\n\n static lighten(hex: AXColorFormat, percentage?: number) {\n return tinycolor(hex).lighten(percentage);\n }\n\n static darken(hex: AXColorFormat, percentage?: number) {\n return tinycolor(hex).darken(percentage);\n }\n\n static brighten(hex: AXColorFormat, percentage?: number) {\n return tinycolor(hex).brighten(percentage);\n }\n\n static saturate(hex: AXColorFormat, percentage?: number) {\n return tinycolor(hex).saturate(percentage);\n }\n\n static desaturate(hex: AXColorFormat) {\n return tinycolor(hex).getLuminance();\n }\n\n static equal(color1: AXColorFormat, color2: AXColorFormat): boolean {\n return tinycolor.equals(color1, color2);\n }\n\n static gradient(\n values: unknown[] | { color: unknown; pos: number }[]\n ): Instance {\n return tinygradient([...values]);\n }\n\n static getLuminance(hex: AXColorFormat) {\n return tinycolor(hex).getLuminance();\n }\n\n static xyToRgb(vX, vY): string {\n vY = vY || 0.00000000001;\n const Y = 1;\n const X = (Y / vY) * vX;\n const Z = (Y / vY) * (1 - vX - vY);\n\n // Convert to RGB using Wide RGB D65 conversion.\n let rgb = [\n X * 1.656492 - Y * 0.354851 - Z * 0.255038,\n -X * 0.707196 + Y * 1.655397 + Z * 0.036152,\n X * 0.051713 - Y * 0.121364 + Z * 1.01153,\n ];\n\n // Apply reverse gamma correction.\n rgb = rgb.map((x) =>\n x <= 0.0031308\n ? 12.92 * x\n : (1.0 + 0.055) * Math.pow(x, 1.0 / 2.4) - 0.055\n );\n\n // Bring all negative components to zero.\n rgb = rgb.map((x) => Math.max(0, x));\n\n // If one component is greater than 1, weight components by that value.\n const max = Math.max(...rgb);\n if (max > 1) {\n rgb = rgb.map((x) => x / max);\n }\n\n rgb = rgb.map((x) => Math.round(x * 255));\n\n return 'rgb(' + rgb.join(',') + ')';\n }\n}\n","export interface AXPoint {\n x: number;\n y: number;\n}\n\nexport interface AXBoundingClientRect {\n left?: number;\n top?: number;\n width?: number;\n height?: number;\n bottom?: number;\n right?: number;\n}\n// @dynamic\nexport class AXDrawingUtil {\n static collision(a: HTMLElement, b: HTMLElement): boolean {\n const ac = a.getBoundingClientRect();\n const bc = b.getBoundingClientRect();\n\n if (\n ac.left < bc.left + bc.width &&\n ac.left + ac.width > bc.left &&\n ac.top < bc.top + bc.height &&\n ac.top + ac.height > bc.top\n ) {\n return true;\n } else {\n return false;\n }\n }\n\n static isInElementBound(pos: AXPoint, element: HTMLElement): boolean {\n const elBound = element.getBoundingClientRect();\n return AXDrawingUtil.isInRecPoint(pos, {\n left: elBound.x,\n width: elBound.width,\n top: elBound.y,\n height: elBound.height,\n });\n }\n\n static isInRecPoint(pos: AXPoint, rec: AXBoundingClientRect | any): boolean {\n return (\n pos.x >= rec.left &&\n pos.x <= rec.left + rec.width &&\n pos.y >= rec.top &&\n pos.y <= rec.top + rec.height\n );\n }\n\n static convertRemToPixels(rem: number): number {\n return (\n rem * parseFloat(getComputedStyle(document.documentElement).fontSize)\n );\n }\n}\n","// @dynamic\nexport class AXHtmlUtil {\n static focusElement(element: HTMLElement): HTMLElement {\n const list = [\n 'button',\n 'input',\n '[href]',\n 'select',\n 'textarea',\n '[tabindex]',\n ].map((c) => c + ':not([tabindex=\"-1\"])');\n const focusable = element.querySelector<HTMLElement>(list.join(', '));\n if (focusable) {\n focusable.focus();\n return focusable;\n }\n return null;\n }\n static blurElement(element: HTMLElement): HTMLElement {\n const list = [\n 'button',\n 'input',\n '[href]',\n 'select',\n 'textarea',\n '[tabindex]',\n ].map((c) => c + ':not([tabindex=\"-1\"])');\n const focusable = element.querySelector<HTMLElement>(list.join(', '));\n if (focusable) {\n focusable.blur();\n return focusable;\n }\n return null;\n }\n\n static hasFocus(element: HTMLElement) {\n return element.matches(':focus-within') || element.matches(':focus');\n }\n}\n","// @dynamic\nexport class AXStringUtil {\n static getWordBoundsAtPosition(\n str: string,\n position: number\n ): { start: number; end: number } {\n const isSpace = (c) => /[^a-zA-Z0-9]+/i.test(c);\n let start = position - 1;\n\n while (start >= 0 && !isSpace(str[start])) {\n start -= 1;\n }\n start = Math.max(0, start + 1);\n const leftSideString: any = str.slice(start).match(/[a-zA-Z0-9]+/i);\n start += leftSideString.index;\n let end = start + leftSideString[0].length;\n return {\n start,\n end,\n };\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;SAGgB,kBAAkB,GAAA;AAChC,IAAA,OAAO,UAAU,WAAW,EAAA;AAC1B,QAAA,MAAM,IAAI,GAAG,WAAW,CAAC,SAAS,CAAC,WAAW,CAAC;AAC/C,QAAA,WAAW,CAAC,SAAS,CAAC,WAAW,GAAG,YAAA;AAClC,YAAA,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE;AACvB,gBAAA,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;AAC5B,gBAAA,IAAI,OAAO,QAAQ,CAAC,SAAS,KAAK,UAAU,EAAE;oBAC5C,QAAQ,CAAC,WAAW,EAAE,CAAC;iBACxB;aACF;YACD,IAAI,CAAC,KAAK,EAAE,CAAC;AACf,SAAC,CAAC;AACJ,KAAC,CAAC;AACJ,CAAC;MAGY,cAAc,CAAA;AAD3B,IAAA,WAAA,GAAA;AAEmB,QAAA,IAAA,CAAA,SAAS,GAAG,IAAI,OAAO,EAAQ,CAAC;AAEjC,QAAA,IAAA,CAAA,gBAAgB,GAAG,CACjC,MAAkC,KACH,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;AAUzE,KAAA;IARQ,WAAW,GAAA;AAChB,QAAA,IAAI,CAAC,SAAS,CAAC,IAAI,EA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