@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.
Files changed (169) hide show
  1. package/.browserslistrc +16 -0
  2. package/config/ax-preset.js +186 -0
  3. package/config/index.ts +1 -0
  4. package/config/ng-package.json +6 -0
  5. package/config/public-api.ts +1 -0
  6. package/config/src/configs.ts +37 -0
  7. package/dateTime/index.ts +1 -0
  8. package/dateTime/ng-package.json +6 -0
  9. package/dateTime/{public-api.d.ts → public-api.ts} +1 -1
  10. package/dateTime/src/datetime.class.ts +452 -0
  11. package/dateTime/src/datetime.module.ts +29 -0
  12. package/dateTime/src/datetime.pipe.ts +21 -0
  13. package/dateTime/src/georgian.calendar.ts +205 -0
  14. package/dateTime/src/jalali.calendar.ts +416 -0
  15. package/events/index.ts +1 -0
  16. package/events/ng-package.json +6 -0
  17. package/events/public-api.ts +1 -0
  18. package/events/src/event.service.ts +31 -0
  19. package/http/index.ts +1 -0
  20. package/http/ng-package.json +6 -0
  21. package/http/{public-api.d.ts → public-api.ts} +1 -1
  22. package/http/src/{http-error.class.d.ts → http-error.class.ts} +2 -2
  23. package/http/src/{http-events.interceptor.d.ts → http-events.interceptor.ts} +7 -3
  24. package/http/src/{http-request.class.d.ts → http-request.class.ts} +5 -5
  25. package/http/src/http-result.class.ts +34 -0
  26. package/http/src/http.module.ts +25 -0
  27. package/http/src/http.service.ts +161 -0
  28. package/index.ts +1 -0
  29. package/karma.conf.js +44 -0
  30. package/ng-package.json +7 -0
  31. package/package.json +23 -106
  32. package/pipes/index.ts +1 -0
  33. package/pipes/ng-package.json +6 -0
  34. package/pipes/public-api.ts +2 -0
  35. package/pipes/src/pipes.module.ts +11 -0
  36. package/pipes/src/safe.pipe.ts +24 -0
  37. package/platform/index.ts +1 -0
  38. package/platform/ng-package.json +6 -0
  39. package/platform/public-api.ts +1 -0
  40. package/platform/src/platform.service.ts +207 -0
  41. package/public-api.ts +4 -0
  42. package/test.ts +27 -0
  43. package/translation/index.ts +1 -0
  44. package/translation/ng-package.json +6 -0
  45. package/translation/{public-api.d.ts → public-api.ts} +1 -1
  46. package/translation/src/translation.module.ts +12 -0
  47. package/translation/src/translator.pipe.ts +9 -0
  48. package/translation/src/translator.ts +49 -0
  49. package/tsconfig.lib.json +15 -0
  50. package/tsconfig.lib.prod.json +10 -0
  51. package/tsconfig.spec.json +17 -0
  52. package/utils/index.ts +1 -0
  53. package/utils/ng-package.json +6 -0
  54. package/utils/{public-api.d.ts → public-api.ts} +1 -1
  55. package/utils/src/color-util.ts +83 -0
  56. package/utils/src/drawing-util.ts +43 -0
  57. package/utils/src/object-util.ts +82 -0
  58. package/utils/src/string-util.ts +25 -0
  59. package/config/index.d.ts +0 -5
  60. package/config/public-api.d.ts +0 -1
  61. package/config/src/configs.d.ts +0 -9
  62. package/dateTime/index.d.ts +0 -5
  63. package/dateTime/src/datetime.class.d.ts +0 -100
  64. package/dateTime/src/datetime.module.d.ts +0 -8
  65. package/dateTime/src/datetime.pipe.d.ts +0 -8
  66. package/dateTime/src/georgian.calendar.d.ts +0 -20
  67. package/dateTime/src/jalali.calendar.d.ts +0 -35
  68. package/esm2020/acorex-core.mjs +0 -5
  69. package/esm2020/config/acorex-core-config.mjs +0 -5
  70. package/esm2020/config/public-api.mjs +0 -2
  71. package/esm2020/config/src/configs.mjs +0 -32
  72. package/esm2020/dateTime/acorex-core-dateTime.mjs +0 -5
  73. package/esm2020/dateTime/public-api.mjs +0 -6
  74. package/esm2020/dateTime/src/datetime.class.mjs +0 -295
  75. package/esm2020/dateTime/src/datetime.module.mjs +0 -33
  76. package/esm2020/dateTime/src/datetime.pipe.mjs +0 -26
  77. package/esm2020/dateTime/src/georgian.calendar.mjs +0 -189
  78. package/esm2020/dateTime/src/jalali.calendar.mjs +0 -359
  79. package/esm2020/events/acorex-core-events.mjs +0 -5
  80. package/esm2020/events/public-api.mjs +0 -2
  81. package/esm2020/events/src/event.service.mjs +0 -36
  82. package/esm2020/http/acorex-core-http.mjs +0 -5
  83. package/esm2020/http/public-api.mjs +0 -6
  84. package/esm2020/http/src/http-error.class.mjs +0 -2
  85. package/esm2020/http/src/http-events.interceptor.mjs +0 -3
  86. package/esm2020/http/src/http-request.class.mjs +0 -2
  87. package/esm2020/http/src/http-result.class.mjs +0 -21
  88. package/esm2020/http/src/http.module.mjs +0 -29
  89. package/esm2020/http/src/http.service.mjs +0 -147
  90. package/esm2020/pipes/acorex-core-pipes.mjs +0 -5
  91. package/esm2020/pipes/public-api.mjs +0 -3
  92. package/esm2020/pipes/src/pipes.module.mjs +0 -19
  93. package/esm2020/pipes/src/safe.pipe.mjs +0 -30
  94. package/esm2020/platform/acorex-core-platform.mjs +0 -5
  95. package/esm2020/platform/public-api.mjs +0 -2
  96. package/esm2020/platform/src/platform.service.mjs +0 -141
  97. package/esm2020/public-api.mjs +0 -5
  98. package/esm2020/translation/acorex-core-translation.mjs +0 -5
  99. package/esm2020/translation/public-api.mjs +0 -4
  100. package/esm2020/translation/src/translation.module.mjs +0 -18
  101. package/esm2020/translation/src/translator.mjs +0 -43
  102. package/esm2020/translation/src/translator.pipe.mjs +0 -15
  103. package/esm2020/utils/acorex-core-utils.mjs +0 -5
  104. package/esm2020/utils/public-api.mjs +0 -5
  105. package/esm2020/utils/src/color-util.mjs +0 -71
  106. package/esm2020/utils/src/drawing-util.mjs +0 -27
  107. package/esm2020/utils/src/object-util.mjs +0 -39
  108. package/esm2020/utils/src/string-util.mjs +0 -19
  109. package/events/index.d.ts +0 -5
  110. package/events/public-api.d.ts +0 -1
  111. package/events/src/event.service.d.ts +0 -9
  112. package/fesm2015/acorex-core-config.mjs +0 -39
  113. package/fesm2015/acorex-core-config.mjs.map +0 -1
  114. package/fesm2015/acorex-core-dateTime.mjs +0 -899
  115. package/fesm2015/acorex-core-dateTime.mjs.map +0 -1
  116. package/fesm2015/acorex-core-events.mjs +0 -43
  117. package/fesm2015/acorex-core-events.mjs.map +0 -1
  118. package/fesm2015/acorex-core-http.mjs +0 -201
  119. package/fesm2015/acorex-core-http.mjs.map +0 -1
  120. package/fesm2015/acorex-core-pipes.mjs +0 -53
  121. package/fesm2015/acorex-core-pipes.mjs.map +0 -1
  122. package/fesm2015/acorex-core-platform.mjs +0 -148
  123. package/fesm2015/acorex-core-platform.mjs.map +0 -1
  124. package/fesm2015/acorex-core-translation.mjs +0 -80
  125. package/fesm2015/acorex-core-translation.mjs.map +0 -1
  126. package/fesm2015/acorex-core-utils.mjs +0 -163
  127. package/fesm2015/acorex-core-utils.mjs.map +0 -1
  128. package/fesm2015/acorex-core.mjs +0 -11
  129. package/fesm2015/acorex-core.mjs.map +0 -1
  130. package/fesm2020/acorex-core-config.mjs +0 -39
  131. package/fesm2020/acorex-core-config.mjs.map +0 -1
  132. package/fesm2020/acorex-core-dateTime.mjs +0 -899
  133. package/fesm2020/acorex-core-dateTime.mjs.map +0 -1
  134. package/fesm2020/acorex-core-events.mjs +0 -43
  135. package/fesm2020/acorex-core-events.mjs.map +0 -1
  136. package/fesm2020/acorex-core-http.mjs +0 -200
  137. package/fesm2020/acorex-core-http.mjs.map +0 -1
  138. package/fesm2020/acorex-core-pipes.mjs +0 -53
  139. package/fesm2020/acorex-core-pipes.mjs.map +0 -1
  140. package/fesm2020/acorex-core-platform.mjs +0 -148
  141. package/fesm2020/acorex-core-platform.mjs.map +0 -1
  142. package/fesm2020/acorex-core-translation.mjs +0 -79
  143. package/fesm2020/acorex-core-translation.mjs.map +0 -1
  144. package/fesm2020/acorex-core-utils.mjs +0 -163
  145. package/fesm2020/acorex-core-utils.mjs.map +0 -1
  146. package/fesm2020/acorex-core.mjs +0 -11
  147. package/fesm2020/acorex-core.mjs.map +0 -1
  148. package/http/index.d.ts +0 -5
  149. package/http/src/http-result.class.d.ts +0 -11
  150. package/http/src/http.module.d.ts +0 -8
  151. package/http/src/http.service.d.ts +0 -23
  152. package/index.d.ts +0 -5
  153. package/pipes/index.d.ts +0 -5
  154. package/pipes/public-api.d.ts +0 -2
  155. package/pipes/src/pipes.module.d.ts +0 -8
  156. package/pipes/src/safe.pipe.d.ts +0 -10
  157. package/platform/index.d.ts +0 -5
  158. package/platform/public-api.d.ts +0 -1
  159. package/platform/src/platform.service.d.ts +0 -25
  160. package/public-api.d.ts +0 -1
  161. package/translation/index.d.ts +0 -5
  162. package/translation/src/translation.module.d.ts +0 -7
  163. package/translation/src/translator.d.ts +0 -11
  164. package/translation/src/translator.pipe.d.ts +0 -7
  165. package/utils/index.d.ts +0 -5
  166. package/utils/src/color-util.d.ts +0 -20
  167. package/utils/src/drawing-util.d.ts +0 -17
  168. package/utils/src/object-util.d.ts +0 -4
  169. 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
+ };
@@ -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,106 +1,23 @@
1
- {
2
- "name": "@acorex/core",
3
- "version": "6.0.0",
4
- "dependencies": {
5
- "tslib": "^2.3.0"
6
- },
7
- "peerDependencies": {
8
- "@angular/common": "^14.0.0",
9
- "@angular/core": "^14.0.0",
10
- "lodash-es": "^4.17.21",
11
- "tinycolor2": "^1.4.2",
12
- "tinygradient": "^1.1.5"
13
- },
14
- "peerDependenciesMeta": {
15
- "tinycolor2": {
16
- "optional": true
17
- },
18
- "tinygradient": {
19
- "optional": true
20
- }
21
- },
22
- "module": "fesm2015/acorex-core.mjs",
23
- "es2020": "fesm2020/acorex-core.mjs",
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,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";
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'
@@ -0,0 +1,6 @@
1
+ {
2
+ "$schema": "../../../../node_modules/ng-packagr/ng-package.schema.json",
3
+ "lib": {
4
+ "entryFile": "public-api.ts"
5
+ }
6
+ }
@@ -1,3 +1,3 @@
1
1
  export * from './src/translator';
2
2
  export * from './src/translator.pipe';
3
- export * from './src/translation.module';
3
+ export * from './src/translation.module';