@acorex/core 6.0.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.
- package/.browserslistrc +16 -0
- package/config/ax-preset.js +186 -0
- package/config/index.ts +1 -0
- package/config/ng-package.json +6 -0
- package/config/public-api.ts +1 -0
- package/config/src/configs.ts +37 -0
- package/dateTime/index.ts +1 -0
- package/dateTime/ng-package.json +6 -0
- package/dateTime/{public-api.d.ts → public-api.ts} +1 -1
- package/dateTime/src/datetime.class.ts +452 -0
- package/dateTime/src/datetime.module.ts +29 -0
- package/dateTime/src/datetime.pipe.ts +21 -0
- package/dateTime/src/georgian.calendar.ts +205 -0
- package/dateTime/src/jalali.calendar.ts +416 -0
- package/events/index.ts +1 -0
- package/events/ng-package.json +6 -0
- package/events/public-api.ts +1 -0
- package/events/src/event.service.ts +31 -0
- package/http/index.ts +1 -0
- package/http/ng-package.json +6 -0
- package/http/{public-api.d.ts → public-api.ts} +1 -1
- package/http/src/{http-error.class.d.ts → http-error.class.ts} +2 -2
- package/http/src/{http-events.interceptor.d.ts → http-events.interceptor.ts} +7 -3
- package/http/src/{http-request.class.d.ts → http-request.class.ts} +5 -5
- package/http/src/http-result.class.ts +34 -0
- package/http/src/http.module.ts +25 -0
- package/http/src/http.service.ts +161 -0
- package/index.ts +1 -0
- package/karma.conf.js +44 -0
- package/ng-package.json +7 -0
- package/package.json +23 -106
- package/pipes/index.ts +1 -0
- package/pipes/ng-package.json +6 -0
- package/pipes/public-api.ts +2 -0
- package/pipes/src/pipes.module.ts +11 -0
- package/pipes/src/safe.pipe.ts +24 -0
- package/platform/index.ts +1 -0
- package/platform/ng-package.json +6 -0
- package/platform/public-api.ts +1 -0
- package/platform/src/platform.service.ts +207 -0
- package/public-api.ts +4 -0
- package/test.ts +27 -0
- package/translation/index.ts +1 -0
- package/translation/ng-package.json +6 -0
- package/translation/{public-api.d.ts → public-api.ts} +1 -1
- package/translation/src/translation.module.ts +12 -0
- package/translation/src/translator.pipe.ts +9 -0
- package/translation/src/translator.ts +49 -0
- package/tsconfig.lib.json +15 -0
- package/tsconfig.lib.prod.json +10 -0
- package/tsconfig.spec.json +17 -0
- package/utils/index.ts +1 -0
- package/utils/ng-package.json +6 -0
- package/utils/{public-api.d.ts → public-api.ts} +1 -1
- package/utils/src/color-util.ts +83 -0
- package/utils/src/drawing-util.ts +43 -0
- package/utils/src/object-util.ts +82 -0
- package/utils/src/string-util.ts +25 -0
- package/config/index.d.ts +0 -5
- package/config/public-api.d.ts +0 -1
- package/config/src/configs.d.ts +0 -9
- package/dateTime/index.d.ts +0 -5
- package/dateTime/src/datetime.class.d.ts +0 -100
- package/dateTime/src/datetime.module.d.ts +0 -8
- package/dateTime/src/datetime.pipe.d.ts +0 -8
- package/dateTime/src/georgian.calendar.d.ts +0 -20
- package/dateTime/src/jalali.calendar.d.ts +0 -35
- package/esm2020/acorex-core.mjs +0 -5
- package/esm2020/config/acorex-core-config.mjs +0 -5
- package/esm2020/config/public-api.mjs +0 -2
- package/esm2020/config/src/configs.mjs +0 -32
- package/esm2020/dateTime/acorex-core-dateTime.mjs +0 -5
- package/esm2020/dateTime/public-api.mjs +0 -6
- package/esm2020/dateTime/src/datetime.class.mjs +0 -295
- package/esm2020/dateTime/src/datetime.module.mjs +0 -33
- package/esm2020/dateTime/src/datetime.pipe.mjs +0 -26
- package/esm2020/dateTime/src/georgian.calendar.mjs +0 -189
- package/esm2020/dateTime/src/jalali.calendar.mjs +0 -359
- package/esm2020/events/acorex-core-events.mjs +0 -5
- package/esm2020/events/public-api.mjs +0 -2
- package/esm2020/events/src/event.service.mjs +0 -36
- package/esm2020/http/acorex-core-http.mjs +0 -5
- package/esm2020/http/public-api.mjs +0 -6
- package/esm2020/http/src/http-error.class.mjs +0 -2
- package/esm2020/http/src/http-events.interceptor.mjs +0 -3
- package/esm2020/http/src/http-request.class.mjs +0 -2
- package/esm2020/http/src/http-result.class.mjs +0 -21
- package/esm2020/http/src/http.module.mjs +0 -29
- package/esm2020/http/src/http.service.mjs +0 -147
- package/esm2020/pipes/acorex-core-pipes.mjs +0 -5
- package/esm2020/pipes/public-api.mjs +0 -3
- package/esm2020/pipes/src/pipes.module.mjs +0 -19
- package/esm2020/pipes/src/safe.pipe.mjs +0 -30
- package/esm2020/platform/acorex-core-platform.mjs +0 -5
- package/esm2020/platform/public-api.mjs +0 -2
- package/esm2020/platform/src/platform.service.mjs +0 -141
- package/esm2020/public-api.mjs +0 -5
- package/esm2020/translation/acorex-core-translation.mjs +0 -5
- package/esm2020/translation/public-api.mjs +0 -4
- package/esm2020/translation/src/translation.module.mjs +0 -18
- package/esm2020/translation/src/translator.mjs +0 -43
- package/esm2020/translation/src/translator.pipe.mjs +0 -15
- package/esm2020/utils/acorex-core-utils.mjs +0 -5
- package/esm2020/utils/public-api.mjs +0 -5
- package/esm2020/utils/src/color-util.mjs +0 -71
- package/esm2020/utils/src/drawing-util.mjs +0 -27
- package/esm2020/utils/src/object-util.mjs +0 -39
- package/esm2020/utils/src/string-util.mjs +0 -19
- package/events/index.d.ts +0 -5
- package/events/public-api.d.ts +0 -1
- package/events/src/event.service.d.ts +0 -9
- package/fesm2015/acorex-core-config.mjs +0 -39
- package/fesm2015/acorex-core-config.mjs.map +0 -1
- package/fesm2015/acorex-core-dateTime.mjs +0 -899
- package/fesm2015/acorex-core-dateTime.mjs.map +0 -1
- package/fesm2015/acorex-core-events.mjs +0 -43
- package/fesm2015/acorex-core-events.mjs.map +0 -1
- package/fesm2015/acorex-core-http.mjs +0 -201
- package/fesm2015/acorex-core-http.mjs.map +0 -1
- package/fesm2015/acorex-core-pipes.mjs +0 -53
- package/fesm2015/acorex-core-pipes.mjs.map +0 -1
- package/fesm2015/acorex-core-platform.mjs +0 -148
- package/fesm2015/acorex-core-platform.mjs.map +0 -1
- package/fesm2015/acorex-core-translation.mjs +0 -80
- package/fesm2015/acorex-core-translation.mjs.map +0 -1
- package/fesm2015/acorex-core-utils.mjs +0 -163
- package/fesm2015/acorex-core-utils.mjs.map +0 -1
- package/fesm2015/acorex-core.mjs +0 -11
- package/fesm2015/acorex-core.mjs.map +0 -1
- package/fesm2020/acorex-core-config.mjs +0 -39
- package/fesm2020/acorex-core-config.mjs.map +0 -1
- package/fesm2020/acorex-core-dateTime.mjs +0 -899
- package/fesm2020/acorex-core-dateTime.mjs.map +0 -1
- package/fesm2020/acorex-core-events.mjs +0 -43
- package/fesm2020/acorex-core-events.mjs.map +0 -1
- package/fesm2020/acorex-core-http.mjs +0 -200
- package/fesm2020/acorex-core-http.mjs.map +0 -1
- package/fesm2020/acorex-core-pipes.mjs +0 -53
- package/fesm2020/acorex-core-pipes.mjs.map +0 -1
- package/fesm2020/acorex-core-platform.mjs +0 -148
- package/fesm2020/acorex-core-platform.mjs.map +0 -1
- package/fesm2020/acorex-core-translation.mjs +0 -79
- package/fesm2020/acorex-core-translation.mjs.map +0 -1
- package/fesm2020/acorex-core-utils.mjs +0 -163
- package/fesm2020/acorex-core-utils.mjs.map +0 -1
- package/fesm2020/acorex-core.mjs +0 -11
- package/fesm2020/acorex-core.mjs.map +0 -1
- package/http/index.d.ts +0 -5
- package/http/src/http-result.class.d.ts +0 -11
- package/http/src/http.module.d.ts +0 -8
- package/http/src/http.service.d.ts +0 -23
- package/index.d.ts +0 -5
- package/pipes/index.d.ts +0 -5
- package/pipes/public-api.d.ts +0 -2
- package/pipes/src/pipes.module.d.ts +0 -8
- package/pipes/src/safe.pipe.d.ts +0 -10
- package/platform/index.d.ts +0 -5
- package/platform/public-api.d.ts +0 -1
- package/platform/src/platform.service.d.ts +0 -25
- package/public-api.d.ts +0 -1
- package/translation/index.d.ts +0 -5
- package/translation/src/translation.module.d.ts +0 -7
- package/translation/src/translator.d.ts +0 -11
- package/translation/src/translator.pipe.d.ts +0 -7
- package/utils/index.d.ts +0 -5
- package/utils/src/color-util.d.ts +0 -20
- package/utils/src/drawing-util.d.ts +0 -17
- package/utils/src/object-util.d.ts +0 -4
- package/utils/src/string-util.d.ts +0 -6
|
@@ -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
|
+
};
|
package/ng-package.json
ADDED
package/package.json
CHANGED
|
@@ -1,106 +1,23 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@acorex/core",
|
|
3
|
-
"version": "6.0.
|
|
4
|
-
"dependencies": {
|
|
5
|
-
"tslib": "^2.3.0"
|
|
6
|
-
},
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
"@angular/
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"esm2020": "esm2020/acorex-core.mjs",
|
|
25
|
-
"fesm2020": "fesm2020/acorex-core.mjs",
|
|
26
|
-
"fesm2015": "fesm2015/acorex-core.mjs",
|
|
27
|
-
"typings": "index.d.ts",
|
|
28
|
-
"exports": {
|
|
29
|
-
"./package.json": {
|
|
30
|
-
"default": "./package.json"
|
|
31
|
-
},
|
|
32
|
-
".": {
|
|
33
|
-
"types": "./index.d.ts",
|
|
34
|
-
"esm2020": "./esm2020/acorex-core.mjs",
|
|
35
|
-
"es2020": "./fesm2020/acorex-core.mjs",
|
|
36
|
-
"es2015": "./fesm2015/acorex-core.mjs",
|
|
37
|
-
"node": "./fesm2015/acorex-core.mjs",
|
|
38
|
-
"default": "./fesm2020/acorex-core.mjs"
|
|
39
|
-
},
|
|
40
|
-
"./config": {
|
|
41
|
-
"types": "./config/index.d.ts",
|
|
42
|
-
"esm2020": "./esm2020/config/acorex-core-config.mjs",
|
|
43
|
-
"es2020": "./fesm2020/acorex-core-config.mjs",
|
|
44
|
-
"es2015": "./fesm2015/acorex-core-config.mjs",
|
|
45
|
-
"node": "./fesm2015/acorex-core-config.mjs",
|
|
46
|
-
"default": "./fesm2020/acorex-core-config.mjs"
|
|
47
|
-
},
|
|
48
|
-
"./dateTime": {
|
|
49
|
-
"types": "./dateTime/index.d.ts",
|
|
50
|
-
"esm2020": "./esm2020/dateTime/acorex-core-dateTime.mjs",
|
|
51
|
-
"es2020": "./fesm2020/acorex-core-dateTime.mjs",
|
|
52
|
-
"es2015": "./fesm2015/acorex-core-dateTime.mjs",
|
|
53
|
-
"node": "./fesm2015/acorex-core-dateTime.mjs",
|
|
54
|
-
"default": "./fesm2020/acorex-core-dateTime.mjs"
|
|
55
|
-
},
|
|
56
|
-
"./events": {
|
|
57
|
-
"types": "./events/index.d.ts",
|
|
58
|
-
"esm2020": "./esm2020/events/acorex-core-events.mjs",
|
|
59
|
-
"es2020": "./fesm2020/acorex-core-events.mjs",
|
|
60
|
-
"es2015": "./fesm2015/acorex-core-events.mjs",
|
|
61
|
-
"node": "./fesm2015/acorex-core-events.mjs",
|
|
62
|
-
"default": "./fesm2020/acorex-core-events.mjs"
|
|
63
|
-
},
|
|
64
|
-
"./http": {
|
|
65
|
-
"types": "./http/index.d.ts",
|
|
66
|
-
"esm2020": "./esm2020/http/acorex-core-http.mjs",
|
|
67
|
-
"es2020": "./fesm2020/acorex-core-http.mjs",
|
|
68
|
-
"es2015": "./fesm2015/acorex-core-http.mjs",
|
|
69
|
-
"node": "./fesm2015/acorex-core-http.mjs",
|
|
70
|
-
"default": "./fesm2020/acorex-core-http.mjs"
|
|
71
|
-
},
|
|
72
|
-
"./pipes": {
|
|
73
|
-
"types": "./pipes/index.d.ts",
|
|
74
|
-
"esm2020": "./esm2020/pipes/acorex-core-pipes.mjs",
|
|
75
|
-
"es2020": "./fesm2020/acorex-core-pipes.mjs",
|
|
76
|
-
"es2015": "./fesm2015/acorex-core-pipes.mjs",
|
|
77
|
-
"node": "./fesm2015/acorex-core-pipes.mjs",
|
|
78
|
-
"default": "./fesm2020/acorex-core-pipes.mjs"
|
|
79
|
-
},
|
|
80
|
-
"./platform": {
|
|
81
|
-
"types": "./platform/index.d.ts",
|
|
82
|
-
"esm2020": "./esm2020/platform/acorex-core-platform.mjs",
|
|
83
|
-
"es2020": "./fesm2020/acorex-core-platform.mjs",
|
|
84
|
-
"es2015": "./fesm2015/acorex-core-platform.mjs",
|
|
85
|
-
"node": "./fesm2015/acorex-core-platform.mjs",
|
|
86
|
-
"default": "./fesm2020/acorex-core-platform.mjs"
|
|
87
|
-
},
|
|
88
|
-
"./translation": {
|
|
89
|
-
"types": "./translation/index.d.ts",
|
|
90
|
-
"esm2020": "./esm2020/translation/acorex-core-translation.mjs",
|
|
91
|
-
"es2020": "./fesm2020/acorex-core-translation.mjs",
|
|
92
|
-
"es2015": "./fesm2015/acorex-core-translation.mjs",
|
|
93
|
-
"node": "./fesm2015/acorex-core-translation.mjs",
|
|
94
|
-
"default": "./fesm2020/acorex-core-translation.mjs"
|
|
95
|
-
},
|
|
96
|
-
"./utils": {
|
|
97
|
-
"types": "./utils/index.d.ts",
|
|
98
|
-
"esm2020": "./esm2020/utils/acorex-core-utils.mjs",
|
|
99
|
-
"es2020": "./fesm2020/acorex-core-utils.mjs",
|
|
100
|
-
"es2015": "./fesm2015/acorex-core-utils.mjs",
|
|
101
|
-
"node": "./fesm2015/acorex-core-utils.mjs",
|
|
102
|
-
"default": "./fesm2020/acorex-core-utils.mjs"
|
|
103
|
-
}
|
|
104
|
-
},
|
|
105
|
-
"sideEffects": false
|
|
106
|
-
}
|
|
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,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 @@
|
|
|
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
package/test.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
|
|
2
|
+
|
|
3
|
+
import 'zone.js';
|
|
4
|
+
import 'zone.js/testing';
|
|
5
|
+
import { getTestBed } from '@angular/core/testing';
|
|
6
|
+
import {
|
|
7
|
+
BrowserDynamicTestingModule,
|
|
8
|
+
platformBrowserDynamicTesting
|
|
9
|
+
} from '@angular/platform-browser-dynamic/testing';
|
|
10
|
+
|
|
11
|
+
declare const require: {
|
|
12
|
+
context(path: string, deep?: boolean, filter?: RegExp): {
|
|
13
|
+
<T>(id: string): T;
|
|
14
|
+
keys(): string[];
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// First, initialize the Angular testing environment.
|
|
19
|
+
getTestBed().initTestEnvironment(
|
|
20
|
+
BrowserDynamicTestingModule,
|
|
21
|
+
platformBrowserDynamicTesting(),
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
// Then we find all the tests.
|
|
25
|
+
const context = require.context('./', true, /\.spec\.ts$/);
|
|
26
|
+
// And load the modules.
|
|
27
|
+
context.keys().forEach(context);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './public-api'
|