@acorex/core 5.8.0 → 6.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.
Files changed (115) hide show
  1. package/.browserslistrc +16 -0
  2. package/README.md +24 -24
  3. package/config/ax-preset.js +8 -26
  4. package/config/index.ts +1 -0
  5. package/config/ng-package.json +6 -0
  6. package/config/public-api.ts +1 -0
  7. package/config/src/configs.ts +37 -0
  8. package/dateTime/index.ts +1 -0
  9. package/dateTime/ng-package.json +6 -0
  10. package/dateTime/public-api.ts +5 -0
  11. package/dateTime/src/datetime.class.ts +452 -0
  12. package/dateTime/src/datetime.module.ts +29 -0
  13. package/dateTime/src/datetime.pipe.ts +21 -0
  14. package/dateTime/src/georgian.calendar.ts +205 -0
  15. package/dateTime/src/jalali.calendar.ts +416 -0
  16. package/events/index.ts +1 -0
  17. package/events/ng-package.json +6 -0
  18. package/events/public-api.ts +1 -0
  19. package/events/src/event.service.ts +31 -0
  20. package/http/index.ts +1 -0
  21. package/http/ng-package.json +6 -0
  22. package/http/public-api.ts +5 -0
  23. package/http/src/http-error.class.ts +7 -0
  24. package/http/src/http-events.interceptor.ts +14 -0
  25. package/http/src/http-request.class.ts +14 -0
  26. package/http/src/http-result.class.ts +34 -0
  27. package/http/src/http.module.ts +25 -0
  28. package/http/src/http.service.ts +161 -0
  29. package/index.ts +1 -0
  30. package/karma.conf.js +44 -0
  31. package/ng-package.json +7 -0
  32. package/package.json +23 -40
  33. package/pipes/index.ts +1 -0
  34. package/pipes/ng-package.json +6 -0
  35. package/pipes/public-api.ts +2 -0
  36. package/pipes/src/pipes.module.ts +11 -0
  37. package/pipes/src/safe.pipe.ts +24 -0
  38. package/platform/index.ts +1 -0
  39. package/platform/ng-package.json +6 -0
  40. package/platform/public-api.ts +1 -0
  41. package/platform/src/platform.service.ts +207 -0
  42. package/public-api.ts +4 -0
  43. package/test.ts +27 -0
  44. package/translation/index.ts +1 -0
  45. package/translation/ng-package.json +6 -0
  46. package/translation/public-api.ts +3 -0
  47. package/translation/src/translation.module.ts +12 -0
  48. package/translation/src/translator.pipe.ts +9 -0
  49. package/translation/src/translator.ts +49 -0
  50. package/tsconfig.lib.json +15 -0
  51. package/tsconfig.lib.prod.json +10 -0
  52. package/tsconfig.spec.json +17 -0
  53. package/utils/index.ts +1 -0
  54. package/utils/ng-package.json +6 -0
  55. package/utils/public-api.ts +4 -0
  56. package/utils/src/color-util.ts +83 -0
  57. package/utils/src/drawing-util.ts +43 -0
  58. package/utils/src/object-util.ts +82 -0
  59. package/utils/src/string-util.ts +25 -0
  60. package/esm2020/acorex-core.mjs +0 -5
  61. package/esm2020/lib/config/configs.mjs +0 -29
  62. package/esm2020/lib/core.module.mjs +0 -18
  63. package/esm2020/lib/dateTime/datetime.class.mjs +0 -295
  64. package/esm2020/lib/dateTime/datetime.module.mjs +0 -33
  65. package/esm2020/lib/dateTime/datetime.pipe.mjs +0 -26
  66. package/esm2020/lib/dateTime/georgian.calendar.mjs +0 -189
  67. package/esm2020/lib/dateTime/index.mjs +0 -6
  68. package/esm2020/lib/dateTime/jalali.calendar.mjs +0 -359
  69. package/esm2020/lib/events/event.service.mjs +0 -36
  70. package/esm2020/lib/events/index.mjs +0 -2
  71. package/esm2020/lib/hotkeys/hotkeys.service.mjs +0 -38
  72. package/esm2020/lib/hotkeys/index.mjs +0 -2
  73. package/esm2020/lib/platform/index.mjs +0 -2
  74. package/esm2020/lib/platform/platform.service.mjs +0 -138
  75. package/esm2020/lib/translation/index.mjs +0 -4
  76. package/esm2020/lib/translation/translation.module.mjs +0 -18
  77. package/esm2020/lib/translation/translator.mjs +0 -43
  78. package/esm2020/lib/translation/translator.pipe.mjs +0 -15
  79. package/esm2020/lib/utils/color-util.mjs +0 -71
  80. package/esm2020/lib/utils/drawing-util.mjs +0 -27
  81. package/esm2020/lib/utils/index.mjs +0 -6
  82. package/esm2020/lib/utils/object-util.mjs +0 -39
  83. package/esm2020/lib/utils/safe.pipe.mjs +0 -30
  84. package/esm2020/lib/utils/string-util.mjs +0 -19
  85. package/esm2020/public-api.mjs +0 -13
  86. package/fesm2015/acorex-core.mjs +0 -1405
  87. package/fesm2015/acorex-core.mjs.map +0 -1
  88. package/fesm2020/acorex-core.mjs +0 -1402
  89. package/fesm2020/acorex-core.mjs.map +0 -1
  90. package/index.d.ts +0 -5
  91. package/lib/config/configs.d.ts +0 -9
  92. package/lib/core.module.d.ts +0 -7
  93. package/lib/dateTime/datetime.class.d.ts +0 -100
  94. package/lib/dateTime/datetime.module.d.ts +0 -8
  95. package/lib/dateTime/datetime.pipe.d.ts +0 -8
  96. package/lib/dateTime/georgian.calendar.d.ts +0 -20
  97. package/lib/dateTime/index.d.ts +0 -5
  98. package/lib/dateTime/jalali.calendar.d.ts +0 -35
  99. package/lib/events/event.service.d.ts +0 -9
  100. package/lib/events/index.d.ts +0 -1
  101. package/lib/hotkeys/hotkeys.service.d.ts +0 -17
  102. package/lib/hotkeys/index.d.ts +0 -1
  103. package/lib/platform/index.d.ts +0 -1
  104. package/lib/platform/platform.service.d.ts +0 -25
  105. package/lib/translation/index.d.ts +0 -3
  106. package/lib/translation/translation.module.d.ts +0 -7
  107. package/lib/translation/translator.d.ts +0 -11
  108. package/lib/translation/translator.pipe.d.ts +0 -7
  109. package/lib/utils/color-util.d.ts +0 -20
  110. package/lib/utils/drawing-util.d.ts +0 -17
  111. package/lib/utils/index.d.ts +0 -5
  112. package/lib/utils/object-util.d.ts +0 -4
  113. package/lib/utils/safe.pipe.d.ts +0 -10
  114. package/lib/utils/string-util.d.ts +0 -6
  115. package/public-api.d.ts +0 -12
@@ -0,0 +1,5 @@
1
+ export * from './src/http-error.class';
2
+ export * from './src/http-events.interceptor';
3
+ export * from './src/http-request.class';
4
+ export * from './src/http-result.class';
5
+ export * from './src/http.module';
@@ -0,0 +1,7 @@
1
+ export interface IHttpError {
2
+ message?: string;
3
+ status?: number;
4
+ code?: string;
5
+ handled: boolean;
6
+ error: any | null
7
+ }
@@ -0,0 +1,14 @@
1
+ import { IHttpError } from './http-error.class';
2
+ import { InjectionToken } from '@angular/core';
3
+ import { AXHttpRequestOptions } from './http-request.class';
4
+
5
+ export const AX_HTTP_EVENT_INTERCEPTOR = new InjectionToken<AXHttpEventInterceptor>('ax.http.events');
6
+
7
+ export interface AXHttpEventInterceptor {
8
+ begin(request: AXHttpRequestOptions): Promise<AXHttpRequestOptions>;
9
+ success(request: AXHttpRequestOptions, result: any): Promise<any>;
10
+ complete(request: AXHttpRequestOptions);
11
+ error(request: AXHttpRequestOptions, error: IHttpError);
12
+ }
13
+
14
+
@@ -0,0 +1,14 @@
1
+ export interface AXHttpRequestOptions {
2
+ url?: any,
3
+ params?: {
4
+ [param: string]: any;
5
+ },
6
+ body?: {
7
+ [param: string]: any;
8
+ },
9
+ headers?: {
10
+ [header: string]: any;
11
+ },
12
+ method?: 'get' | 'post' | 'put' | 'delete';
13
+ responseType?: any;
14
+ }
@@ -0,0 +1,34 @@
1
+ import { IHttpError } from './http-error.class';
2
+
3
+ export class HttpResult<T> {
4
+ private _executor: (result: (e?: T) => void, error: (e?: IHttpError) => void, complete: () => void) => void;
5
+ constructor(
6
+ executor: (
7
+ result: (e?: T) => void,
8
+ error: (e?: IHttpError) => void,
9
+ complete: () => void
10
+ ) => void
11
+ ) {
12
+ this._executor = executor;
13
+ setTimeout(() => {
14
+ this._executor(this.resultAction, this.errorAction, this.completeAction);
15
+ }, 50);
16
+ }
17
+
18
+ private resultAction: (e?: T) => void;
19
+ private errorAction: (e?: IHttpError) => void;
20
+ private completeAction: () => void;
21
+
22
+ result(action: (e?: T) => void): HttpResult<T> {
23
+ this.resultAction = action;
24
+ return this;
25
+ }
26
+ error(action: (e?: IHttpError) => void): HttpResult<T> {
27
+ this.errorAction = action;
28
+ return this;
29
+ }
30
+ complete(action: () => void): HttpResult<T> {
31
+ this.completeAction = action;
32
+ return this;
33
+ }
34
+ }
@@ -0,0 +1,25 @@
1
+ import { NgModule, ModuleWithProviders } from '@angular/core';
2
+ import { CommonModule } from '@angular/common';
3
+ import { HttpClientModule } from '@angular/common/http';
4
+ import { AXHttpService } from './http.service';
5
+
6
+
7
+ @NgModule({
8
+ declarations: [],
9
+ imports: [
10
+ CommonModule,
11
+ HttpClientModule
12
+ ],
13
+ exports: [HttpClientModule],
14
+ providers: [
15
+ AXHttpService
16
+ ]
17
+ })
18
+ export class AXHttpModule {
19
+ // static forRoot(): ModuleWithProviders {
20
+ // return {
21
+ // ngModule: AXHttpModule,
22
+ // providers: [AXHttpService]
23
+ // };
24
+ // }
25
+ }
@@ -0,0 +1,161 @@
1
+ import { Injectable, Injector, InjectFlags } from '@angular/core';
2
+ import { HttpClient, HttpHeaders, HttpParams, HttpErrorResponse } from '@angular/common/http';
3
+ import { HttpResult } from './http-result.class';
4
+ import { IHttpError } from './http-error.class';
5
+ import { AXHttpRequestOptions } from './http-request.class';
6
+ import {
7
+ AX_HTTP_EVENT_INTERCEPTOR, AXHttpEventInterceptor
8
+ } from './http-events.interceptor';
9
+ // import { catchError, retry, retryWhen, mergeMap, delay, switchMap, scan, takeWhile, flatMap } from 'rxjs/operators';
10
+ // import { of, concat, throwError } from 'rxjs';
11
+
12
+
13
+ @Injectable()
14
+ export class AXHttpService {
15
+
16
+ private interceptor: AXHttpEventInterceptor;
17
+ constructor(private http: HttpClient, private injector: Injector) {
18
+ this.interceptor = this.injector.get(AX_HTTP_EVENT_INTERCEPTOR);
19
+ }
20
+
21
+
22
+ get<T>(url: string, config: AXHttpRequestOptions = {}): HttpResult<T> {
23
+ config.url = url;
24
+ config.method = "get";
25
+ return this.request(config);
26
+ }
27
+
28
+ post<T>(url: string, config: AXHttpRequestOptions = {}): HttpResult<T> {
29
+ config.url = url;
30
+ config.method = "post";
31
+ return this.request(config);
32
+ }
33
+
34
+ delete<T>(url: string, config: AXHttpRequestOptions = {}): HttpResult<T> {
35
+ config.url = url;
36
+ config.method = "delete";
37
+ return this.request(config);
38
+ }
39
+
40
+ put<T>(url: string, config: AXHttpRequestOptions = {}): HttpResult<T> {
41
+ config.url = url;
42
+ config.method = "put";
43
+ return this.request(config);
44
+ }
45
+
46
+
47
+ request<T>(config: AXHttpRequestOptions): HttpResult<T> {
48
+ return new HttpResult<T>((result?, error?, complete?) => {
49
+ this.handleBegin(config).then(c => {
50
+ this.http
51
+ //TODO: check ts error
52
+ //@ts-ignore
53
+ .request<T>(config.method, config.url, this.mapOptions(config))
54
+ //.pipe(this.retry)
55
+ .subscribe(data => {
56
+ this.handleResult(data, result, complete, config);
57
+ }, c => {
58
+ this.handleError(c, error, complete, config);
59
+ });
60
+ });
61
+ })
62
+ }
63
+
64
+
65
+ private handleResult(data, result, complete, config: AXHttpRequestOptions) {
66
+ if (this.interceptor) {
67
+ this.interceptor.success(config, data).then(c => {
68
+ if (result)
69
+ result(c);
70
+ this.handleComplete(complete, config);
71
+ });
72
+ }
73
+ else {
74
+ //
75
+ if (result)
76
+ result(data);
77
+ this.handleComplete(complete, config);
78
+ }
79
+ }
80
+
81
+ private handleBegin(config: AXHttpRequestOptions): Promise<AXHttpRequestOptions> {
82
+ return new Promise((resolve) => {
83
+ if (!config.headers)
84
+ config.headers = {};
85
+ if (!config.params)
86
+ config.params = {};
87
+ //
88
+ if (this.interceptor) {
89
+ this.interceptor.begin(config).then(c => {
90
+ resolve(c);
91
+ });
92
+ }
93
+ else {
94
+ resolve(config)
95
+ }
96
+ })
97
+ }
98
+
99
+ private handleComplete(complete: Function, config: AXHttpRequestOptions) {
100
+ if (complete)
101
+ complete();
102
+ if (this.interceptor)
103
+ this.interceptor.complete(config);
104
+ }
105
+
106
+ private handleError(c: HttpErrorResponse, error: Function, complete: Function, config: AXHttpRequestOptions) {
107
+ let r: IHttpError = {
108
+ message: c.message,
109
+ status: c.status,
110
+ code: c.status?.toString(),
111
+ handled: false,
112
+ error: c.error
113
+ }
114
+ if (error) {
115
+ error(r);
116
+ }
117
+ if (!r.handled) {
118
+ if (this.interceptor)
119
+ this.interceptor.error(config, r);
120
+ }
121
+ this.handleComplete(complete, config);
122
+ }
123
+
124
+ private mapOptions(options: AXHttpRequestOptions) {
125
+ let headers = new HttpHeaders();
126
+
127
+ for (const key in options.headers) {
128
+ if (options.headers.hasOwnProperty(key)) {
129
+ const value = options.headers[key];
130
+ headers = headers.set(key, value)
131
+ }
132
+ }
133
+ let params = new HttpParams();
134
+ for (const key in options.params) {
135
+ if (options.params.hasOwnProperty(key)) {
136
+ const value = options.params[key];
137
+ params = params.set(key, value);
138
+ }
139
+ }
140
+ return {
141
+ headers: headers,
142
+ params: params,
143
+ body: options.body,
144
+ responseType: options.responseType || 'json'
145
+ };
146
+ // if (options.method == "get") {
147
+ // return {
148
+ // headers: headers,
149
+ // params: params
150
+ // };
151
+ // }
152
+ // else {
153
+ // return {
154
+ // headers: headers,
155
+ // params: params,
156
+ // body: options.body
157
+ // };
158
+ // }
159
+ }
160
+
161
+ }
package/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './public-api'
package/karma.conf.js ADDED
@@ -0,0 +1,44 @@
1
+ // Karma configuration file, see link for more information
2
+ // https://karma-runner.github.io/1.0/config/configuration-file.html
3
+
4
+ module.exports = function (config) {
5
+ config.set({
6
+ basePath: '',
7
+ frameworks: ['jasmine', '@angular-devkit/build-angular'],
8
+ plugins: [
9
+ require('karma-jasmine'),
10
+ require('karma-chrome-launcher'),
11
+ require('karma-jasmine-html-reporter'),
12
+ require('karma-coverage'),
13
+ require('@angular-devkit/build-angular/plugins/karma')
14
+ ],
15
+ client: {
16
+ jasmine: {
17
+ // you can add configuration options for Jasmine here
18
+ // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
19
+ // for example, you can disable the random execution with `random: false`
20
+ // or set a specific seed with `seed: 4321`
21
+ },
22
+ clearContext: false // leave Jasmine Spec Runner output visible in browser
23
+ },
24
+ jasmineHtmlReporter: {
25
+ suppressAll: true // removes the duplicated traces
26
+ },
27
+ coverageReporter: {
28
+ dir: require('path').join(__dirname, '../../../coverage/acorex/core'),
29
+ subdir: '.',
30
+ reporters: [
31
+ { type: 'html' },
32
+ { type: 'text-summary' }
33
+ ]
34
+ },
35
+ reporters: ['progress', 'kjhtml'],
36
+ port: 9876,
37
+ colors: true,
38
+ logLevel: config.LOG_INFO,
39
+ autoWatch: true,
40
+ browsers: ['Chrome'],
41
+ singleRun: false,
42
+ restartOnFileChange: true
43
+ });
44
+ };
@@ -0,0 +1,7 @@
1
+ {
2
+ "$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
3
+ "dest": "../../../dist/acorex/core",
4
+ "lib": {
5
+ "entryFile": "public-api.ts"
6
+ }
7
+ }
package/package.json CHANGED
@@ -1,40 +1,23 @@
1
- {
2
- "name": "@acorex/core",
3
- "version": "5.8.0",
4
- "peerDependencies": {
5
- "@angular/common": "^13.3.7",
6
- "@angular/core": "^13.3.7",
7
- "autoprefixer": "^10.4.0",
8
- "lodash-es": "^4.17.20",
9
- "postcss-import": "^14.0.2",
10
- "postcss-nesting": "^10.0.3",
11
- "tailwind-rtl-utilities": "^3.0.5",
12
- "animated-tailwindcss": "^3.2.5",
13
- "tailwindcss": "^3.0.24",
14
- "tinycolor2": "^1.4.2",
15
- "tinygradient": "^1.1.5"
16
- },
17
- "dependencies": {
18
- "tslib": "^2.3.1"
19
- },
20
- "module": "fesm2015/acorex-core.mjs",
21
- "es2020": "fesm2020/acorex-core.mjs",
22
- "esm2020": "esm2020/acorex-core.mjs",
23
- "fesm2020": "fesm2020/acorex-core.mjs",
24
- "fesm2015": "fesm2015/acorex-core.mjs",
25
- "typings": "index.d.ts",
26
- "exports": {
27
- "./package.json": {
28
- "default": "./package.json"
29
- },
30
- ".": {
31
- "types": "./index.d.ts",
32
- "esm2020": "./esm2020/acorex-core.mjs",
33
- "es2020": "./fesm2020/acorex-core.mjs",
34
- "es2015": "./fesm2015/acorex-core.mjs",
35
- "node": "./fesm2015/acorex-core.mjs",
36
- "default": "./fesm2020/acorex-core.mjs"
37
- }
38
- },
39
- "sideEffects": false
40
- }
1
+ {
2
+ "name": "@acorex/core",
3
+ "version": "6.0.1",
4
+ "dependencies": {
5
+ "tslib": "^2.3.0"
6
+ },
7
+ "ngPackage": {},
8
+ "peerDependencies": {
9
+ "@angular/common": "^14.0.0",
10
+ "@angular/core": "^14.0.0",
11
+ "lodash-es": "^4.17.21",
12
+ "tinycolor2": "^1.4.2",
13
+ "tinygradient": "^1.1.5"
14
+ },
15
+ "peerDependenciesMeta": {
16
+ "tinycolor2": {
17
+ "optional": true
18
+ },
19
+ "tinygradient": {
20
+ "optional": true
21
+ }
22
+ }
23
+ }
package/pipes/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './public-api'
@@ -0,0 +1,6 @@
1
+ {
2
+ "$schema": "../../../../node_modules/ng-packagr/ng-package.schema.json",
3
+ "lib": {
4
+ "entryFile": "public-api.ts"
5
+ }
6
+ }
@@ -0,0 +1,2 @@
1
+ export * from './src/safe.pipe'
2
+ export * from './src/pipes.module'
@@ -0,0 +1,11 @@
1
+ import { NgModule } from '@angular/core';
2
+ import { CommonModule } from '@angular/common';
3
+ import { AXSafePipe } from './safe.pipe';
4
+
5
+ @NgModule({
6
+ declarations: [AXSafePipe],
7
+ imports: [CommonModule],
8
+ exports: [AXSafePipe],
9
+ providers: [],
10
+ })
11
+ export class AXPipesModule {}
@@ -0,0 +1,24 @@
1
+ import { Pipe, PipeTransform } from '@angular/core';
2
+ import { DomSanitizer, SafeHtml, SafeStyle, SafeScript, SafeUrl, SafeResourceUrl } from '@angular/platform-browser';
3
+
4
+ @Pipe({
5
+ name: 'safe',
6
+ pure: true
7
+ })
8
+ export class AXSafePipe implements PipeTransform {
9
+
10
+ constructor(protected sanitizer: DomSanitizer) { }
11
+
12
+ public transform(value: any, type: string): SafeHtml | SafeStyle | SafeScript | SafeUrl | SafeResourceUrl {
13
+ if (value == null || value == undefined || value == '')
14
+ return '';
15
+ switch (type) {
16
+ case 'html': return this.sanitizer.bypassSecurityTrustHtml(value);
17
+ case 'style': return this.sanitizer.bypassSecurityTrustStyle(value);
18
+ case 'script': return this.sanitizer.bypassSecurityTrustScript(value);
19
+ case 'url': return this.sanitizer.bypassSecurityTrustUrl(value);
20
+ case 'resourceUrl': return this.sanitizer.bypassSecurityTrustResourceUrl(value);
21
+ default: throw new Error(`Invalid safe type specified: ${type}`);
22
+ }
23
+ }
24
+ }
@@ -0,0 +1 @@
1
+ export * from './public-api'
@@ -0,0 +1,6 @@
1
+ {
2
+ "$schema": "../../../../node_modules/ng-packagr/ng-package.schema.json",
3
+ "lib": {
4
+ "entryFile": "public-api.ts"
5
+ }
6
+ }
@@ -0,0 +1 @@
1
+ export * from './src/platform.service';
@@ -0,0 +1,207 @@
1
+ import { Injectable } from '@angular/core';
2
+ import { fromEvent, Subject } from 'rxjs';
3
+ import { debounceTime, distinctUntilChanged } from 'rxjs/operators';
4
+
5
+ export type AXPlatforms = 'Android' | 'Desktop' | 'iOS' | 'Mobile';
6
+ export type AXBrowsers =
7
+ | 'Chrome'
8
+ | 'Safari'
9
+ | 'Edge'
10
+ | 'Firefox'
11
+ | 'Opera'
12
+ | 'MSIE';
13
+ export type AXTechnologies = 'PWA' | 'Hybrid' | 'Electron';
14
+
15
+ const isChrome = (win: Window): boolean => testUserAgent(win, /Chrome/i);
16
+
17
+ const isFirefox = (win: Window): boolean => testUserAgent(win, /Firefox/i);
18
+
19
+ const isEdge = (win: Window): boolean => testUserAgent(win, /Edge/i);
20
+
21
+ const isSafari = (win: Window): boolean => testUserAgent(win, /Safari/i);
22
+
23
+ const isOpera = (win: Window): boolean =>
24
+ testUserAgent(win, /Opera/i) || testUserAgent(win, /OPR/i);
25
+
26
+ const isMSIE = (win: Window): boolean =>
27
+ testUserAgent(win, /MSIE/i) || testUserAgent(win, /Trident/i);
28
+
29
+ const isMobileWeb = (win: Window): boolean => isMobile(win) && !isHybrid(win);
30
+
31
+ const isIpad = (win: Window) => {
32
+ // iOS 12 and below
33
+ if (testUserAgent(win, /iPad/i)) {
34
+ return true;
35
+ }
36
+
37
+ // iOS 13+
38
+ if (testUserAgent(win, /Macintosh/i) && isMobile(win)) {
39
+ return true;
40
+ }
41
+
42
+ return false;
43
+ };
44
+
45
+ const isIphone = (win: Window) => testUserAgent(win, /iPhone/i);
46
+
47
+ const isIOS = (win: Window) =>
48
+ testUserAgent(win, /iPhone|iPod/i) || isIpad(win);
49
+
50
+ const isAndroid = (win: Window) => testUserAgent(win, /android|sink/i);
51
+
52
+ const isAndroidTablet = (win: Window) => {
53
+ return isAndroid(win) && !testUserAgent(win, /mobile/i);
54
+ };
55
+
56
+ const isPhablet = (win: Window) => {
57
+ const width = win.innerWidth;
58
+ const height = win.innerHeight;
59
+ const smallest = Math.min(width, height);
60
+ const largest = Math.max(width, height);
61
+
62
+ return smallest > 390 && smallest < 520 && largest > 620 && largest < 800;
63
+ };
64
+
65
+ const isTablet = (win: Window) => {
66
+ const width = win.innerWidth;
67
+ const height = win.innerHeight;
68
+ const smallest = Math.min(width, height);
69
+ const largest = Math.max(width, height);
70
+
71
+ return (
72
+ isIpad(win) ||
73
+ isAndroidTablet(win) ||
74
+ (smallest > 460 && smallest < 820 && largest > 780 && largest < 1400)
75
+ );
76
+ };
77
+
78
+ const isMobile = (win: Window) => matchMedia(win, '(any-pointer:coarse)');
79
+
80
+ const isDesktop = (win: Window) => !isMobile(win);
81
+
82
+ const isHybrid = (win: Window) => isCordova(win) || isCapacitorNative(win);
83
+
84
+ const isCordova = (win: any): boolean =>
85
+ !!(win['cordova'] || win['phonegap'] || win['PhoneGap']);
86
+
87
+ const isCapacitorNative = (win: any): boolean => {
88
+ const capacitor = win['Capacitor'];
89
+ return !!(capacitor && capacitor.isNative);
90
+ };
91
+
92
+ const isElectron = (win: Window): boolean => testUserAgent(win, /electron/i);
93
+
94
+ const isPWA = (win: Window): boolean =>
95
+ !!(
96
+ win.matchMedia('(display-mode: standalone)').matches ||
97
+ (win.navigator as any).standalone
98
+ );
99
+
100
+ export const testUserAgent = (win: Window, expr: RegExp) =>
101
+ expr.test(win.navigator.userAgent);
102
+
103
+ const matchMedia = (win: Window, query: string): boolean =>
104
+ win.matchMedia(query).matches;
105
+
106
+ const PLATFORMS_MAP: any = {
107
+ Android: isAndroid,
108
+ iOS: isIOS,
109
+ Desktop: isDesktop,
110
+ Mobile: isMobile,
111
+ Chrome: isChrome,
112
+ Firefox: isFirefox,
113
+ Safari: isSafari,
114
+ Edge: isEdge,
115
+ Opera: isOpera,
116
+ Hybrid: isHybrid,
117
+ PWA: isPWA,
118
+ Electron: isElectron,
119
+ };
120
+
121
+ export class AXPlatformEvent {
122
+ nativeEvent!: UIEvent | Event;
123
+ source!: AXPlatform;
124
+ }
125
+
126
+ @Injectable({
127
+ providedIn: 'platform',
128
+ })
129
+ export class AXPlatform {
130
+ resize: Subject<AXPlatformEvent> = new Subject<AXPlatformEvent>();
131
+ click: Subject<AXPlatformEvent> = new Subject<AXPlatformEvent>();
132
+ scroll: Subject<AXPlatformEvent> = new Subject<AXPlatformEvent>();
133
+
134
+ isRtl(): boolean {
135
+ return (
136
+ document.dir == 'rtl' ||
137
+ document.body.dir == 'rtl' ||
138
+ document.body.style.direction == 'rtl'
139
+ );
140
+ }
141
+
142
+ isLandscape(): boolean {
143
+ return window.innerHeight < window.innerWidth;
144
+ }
145
+
146
+ isPortrate(): boolean {
147
+ return !this.isLandscape();
148
+ }
149
+
150
+ is(name: AXPlatforms | AXBrowsers | AXTechnologies): boolean {
151
+ return PLATFORMS_MAP[name](window) || false;
152
+ }
153
+
154
+ switchDarkMode() {
155
+ const _html = document.getElementsByTagName('html')[0];
156
+ _html.classList.add('ax-dark');
157
+ }
158
+
159
+ switchLightMode() {
160
+ const _html = document.getElementsByTagName('html')[0];
161
+ _html.classList.remove('ax-dark');
162
+ }
163
+
164
+ private _setFullHeightRatio() {
165
+ document
166
+ .querySelector<HTMLElement>(':root')
167
+ ?.style.setProperty('--ax-vh', window.innerHeight / 100 + 'px');
168
+ }
169
+
170
+ constructor() {
171
+ fromEvent<UIEvent>(window, 'resize')
172
+ .pipe(debounceTime(100))
173
+ .pipe(distinctUntilChanged())
174
+ .subscribe((e) => {
175
+ this.resize.next({
176
+ nativeEvent: e,
177
+ source: this,
178
+ });
179
+ //
180
+ this._setFullHeightRatio();
181
+ });
182
+
183
+ document.addEventListener(
184
+ 'click',
185
+ (e) => {
186
+ this.click.next({
187
+ nativeEvent: e,
188
+ source: this,
189
+ });
190
+ },
191
+ true
192
+ );
193
+
194
+ document.addEventListener(
195
+ 'scroll',
196
+ (e) => {
197
+ this.scroll.next({
198
+ nativeEvent: e,
199
+ source: this,
200
+ });
201
+ },
202
+ true
203
+ );
204
+ // init functions
205
+ this._setFullHeightRatio();
206
+ }
207
+ }
package/public-api.ts ADDED
@@ -0,0 +1,4 @@
1
+ /*
2
+ * Public API Surface of core
3
+ */
4
+ export const ACOREX_CORE = "@acorex/core";