@acorex/core 5.8.0 → 5.9.0

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 (152) hide show
  1. package/README.md +1 -1
  2. package/config/index.d.ts +5 -0
  3. package/config/public-api.d.ts +1 -0
  4. package/{lib/config → config/src}/configs.d.ts +0 -0
  5. package/dateTime/index.d.ts +5 -0
  6. package/dateTime/public-api.d.ts +5 -0
  7. package/{lib/dateTime → dateTime/src}/datetime.class.d.ts +0 -0
  8. package/{lib/dateTime → dateTime/src}/datetime.module.d.ts +0 -0
  9. package/{lib/dateTime → dateTime/src}/datetime.pipe.d.ts +0 -0
  10. package/{lib/dateTime → dateTime/src}/georgian.calendar.d.ts +0 -0
  11. package/{lib/dateTime → dateTime/src}/jalali.calendar.d.ts +0 -0
  12. package/esm2020/acorex-core.mjs +1 -1
  13. package/esm2020/config/acorex-core-config.mjs +5 -0
  14. package/esm2020/config/public-api.mjs +2 -0
  15. package/esm2020/config/src/configs.mjs +32 -0
  16. package/esm2020/dateTime/acorex-core-dateTime.mjs +5 -0
  17. package/esm2020/dateTime/public-api.mjs +6 -0
  18. package/esm2020/dateTime/src/datetime.class.mjs +295 -0
  19. package/esm2020/dateTime/src/datetime.module.mjs +33 -0
  20. package/esm2020/dateTime/src/datetime.pipe.mjs +26 -0
  21. package/esm2020/dateTime/src/georgian.calendar.mjs +189 -0
  22. package/esm2020/dateTime/src/jalali.calendar.mjs +359 -0
  23. package/esm2020/events/acorex-core-events.mjs +5 -0
  24. package/esm2020/events/public-api.mjs +2 -0
  25. package/esm2020/events/src/event.service.mjs +36 -0
  26. package/esm2020/http/acorex-core-http.mjs +5 -0
  27. package/esm2020/http/public-api.mjs +6 -0
  28. package/esm2020/http/src/http-error.class.mjs +2 -0
  29. package/esm2020/http/src/http-events.interceptor.mjs +3 -0
  30. package/esm2020/http/src/http-request.class.mjs +2 -0
  31. package/esm2020/http/src/http-result.class.mjs +21 -0
  32. package/esm2020/http/src/http.module.mjs +29 -0
  33. package/esm2020/http/src/http.service.mjs +147 -0
  34. package/esm2020/pipes/acorex-core-pipes.mjs +5 -0
  35. package/esm2020/pipes/public-api.mjs +3 -0
  36. package/esm2020/pipes/src/pipes.module.mjs +19 -0
  37. package/esm2020/pipes/src/safe.pipe.mjs +30 -0
  38. package/esm2020/platform/acorex-core-platform.mjs +5 -0
  39. package/esm2020/platform/public-api.mjs +2 -0
  40. package/esm2020/platform/src/platform.service.mjs +141 -0
  41. package/esm2020/public-api.mjs +4 -12
  42. package/esm2020/translation/acorex-core-translation.mjs +5 -0
  43. package/esm2020/translation/public-api.mjs +4 -0
  44. package/esm2020/translation/src/translation.module.mjs +18 -0
  45. package/esm2020/translation/src/translator.mjs +43 -0
  46. package/esm2020/translation/src/translator.pipe.mjs +15 -0
  47. package/esm2020/utils/acorex-core-utils.mjs +5 -0
  48. package/esm2020/utils/public-api.mjs +5 -0
  49. package/esm2020/utils/src/color-util.mjs +71 -0
  50. package/esm2020/utils/src/drawing-util.mjs +27 -0
  51. package/esm2020/utils/src/object-util.mjs +39 -0
  52. package/esm2020/utils/src/string-util.mjs +19 -0
  53. package/events/index.d.ts +5 -0
  54. package/events/public-api.d.ts +1 -0
  55. package/{lib/events → events/src}/event.service.d.ts +0 -0
  56. package/fesm2015/acorex-core-config.mjs +39 -0
  57. package/fesm2015/acorex-core-config.mjs.map +1 -0
  58. package/fesm2015/acorex-core-dateTime.mjs +899 -0
  59. package/fesm2015/acorex-core-dateTime.mjs.map +1 -0
  60. package/fesm2015/acorex-core-events.mjs +43 -0
  61. package/fesm2015/acorex-core-events.mjs.map +1 -0
  62. package/fesm2015/acorex-core-http.mjs +201 -0
  63. package/fesm2015/acorex-core-http.mjs.map +1 -0
  64. package/fesm2015/acorex-core-pipes.mjs +53 -0
  65. package/fesm2015/acorex-core-pipes.mjs.map +1 -0
  66. package/fesm2015/acorex-core-platform.mjs +148 -0
  67. package/fesm2015/acorex-core-platform.mjs.map +1 -0
  68. package/fesm2015/acorex-core-translation.mjs +80 -0
  69. package/fesm2015/acorex-core-translation.mjs.map +1 -0
  70. package/fesm2015/acorex-core-utils.mjs +163 -0
  71. package/fesm2015/acorex-core-utils.mjs.map +1 -0
  72. package/fesm2015/acorex-core.mjs +5 -1399
  73. package/fesm2015/acorex-core.mjs.map +1 -1
  74. package/fesm2020/acorex-core-config.mjs +39 -0
  75. package/fesm2020/acorex-core-config.mjs.map +1 -0
  76. package/fesm2020/acorex-core-dateTime.mjs +899 -0
  77. package/fesm2020/acorex-core-dateTime.mjs.map +1 -0
  78. package/fesm2020/acorex-core-events.mjs +43 -0
  79. package/fesm2020/acorex-core-events.mjs.map +1 -0
  80. package/fesm2020/acorex-core-http.mjs +200 -0
  81. package/fesm2020/acorex-core-http.mjs.map +1 -0
  82. package/fesm2020/acorex-core-pipes.mjs +53 -0
  83. package/fesm2020/acorex-core-pipes.mjs.map +1 -0
  84. package/fesm2020/acorex-core-platform.mjs +148 -0
  85. package/fesm2020/acorex-core-platform.mjs.map +1 -0
  86. package/fesm2020/acorex-core-translation.mjs +79 -0
  87. package/fesm2020/acorex-core-translation.mjs.map +1 -0
  88. package/fesm2020/acorex-core-utils.mjs +163 -0
  89. package/fesm2020/acorex-core-utils.mjs.map +1 -0
  90. package/fesm2020/acorex-core.mjs +5 -1396
  91. package/fesm2020/acorex-core.mjs.map +1 -1
  92. package/http/index.d.ts +5 -0
  93. package/http/public-api.d.ts +5 -0
  94. package/http/src/http-error.class.d.ts +7 -0
  95. package/http/src/http-events.interceptor.d.ts +10 -0
  96. package/http/src/http-request.class.d.ts +14 -0
  97. package/http/src/http-result.class.d.ts +11 -0
  98. package/http/src/http.module.d.ts +8 -0
  99. package/http/src/http.service.d.ts +23 -0
  100. package/package.json +78 -12
  101. package/pipes/index.d.ts +5 -0
  102. package/pipes/public-api.d.ts +2 -0
  103. package/pipes/src/pipes.module.d.ts +8 -0
  104. package/{lib/utils → pipes/src}/safe.pipe.d.ts +0 -0
  105. package/platform/index.d.ts +5 -0
  106. package/platform/public-api.d.ts +1 -0
  107. package/{lib/platform → platform/src}/platform.service.d.ts +1 -1
  108. package/public-api.d.ts +1 -12
  109. package/translation/index.d.ts +5 -0
  110. package/translation/public-api.d.ts +3 -0
  111. package/{lib/translation → translation/src}/translation.module.d.ts +0 -0
  112. package/{lib/translation → translation/src}/translator.d.ts +0 -0
  113. package/{lib/translation → translation/src}/translator.pipe.d.ts +0 -0
  114. package/utils/index.d.ts +5 -0
  115. package/utils/public-api.d.ts +4 -0
  116. package/{lib/utils → utils/src}/color-util.d.ts +0 -0
  117. package/{lib/utils → utils/src}/drawing-util.d.ts +1 -1
  118. package/{lib/utils → utils/src}/object-util.d.ts +0 -0
  119. package/{lib/utils → utils/src}/string-util.d.ts +0 -0
  120. package/config/ax-preset.js +0 -204
  121. package/esm2020/lib/config/configs.mjs +0 -29
  122. package/esm2020/lib/core.module.mjs +0 -18
  123. package/esm2020/lib/dateTime/datetime.class.mjs +0 -295
  124. package/esm2020/lib/dateTime/datetime.module.mjs +0 -33
  125. package/esm2020/lib/dateTime/datetime.pipe.mjs +0 -26
  126. package/esm2020/lib/dateTime/georgian.calendar.mjs +0 -189
  127. package/esm2020/lib/dateTime/index.mjs +0 -6
  128. package/esm2020/lib/dateTime/jalali.calendar.mjs +0 -359
  129. package/esm2020/lib/events/event.service.mjs +0 -36
  130. package/esm2020/lib/events/index.mjs +0 -2
  131. package/esm2020/lib/hotkeys/hotkeys.service.mjs +0 -38
  132. package/esm2020/lib/hotkeys/index.mjs +0 -2
  133. package/esm2020/lib/platform/index.mjs +0 -2
  134. package/esm2020/lib/platform/platform.service.mjs +0 -138
  135. package/esm2020/lib/translation/index.mjs +0 -4
  136. package/esm2020/lib/translation/translation.module.mjs +0 -18
  137. package/esm2020/lib/translation/translator.mjs +0 -43
  138. package/esm2020/lib/translation/translator.pipe.mjs +0 -15
  139. package/esm2020/lib/utils/color-util.mjs +0 -71
  140. package/esm2020/lib/utils/drawing-util.mjs +0 -27
  141. package/esm2020/lib/utils/index.mjs +0 -6
  142. package/esm2020/lib/utils/object-util.mjs +0 -39
  143. package/esm2020/lib/utils/safe.pipe.mjs +0 -30
  144. package/esm2020/lib/utils/string-util.mjs +0 -19
  145. package/lib/core.module.d.ts +0 -7
  146. package/lib/dateTime/index.d.ts +0 -5
  147. package/lib/events/index.d.ts +0 -1
  148. package/lib/hotkeys/hotkeys.service.d.ts +0 -17
  149. package/lib/hotkeys/index.d.ts +0 -1
  150. package/lib/platform/index.d.ts +0 -1
  151. package/lib/translation/index.d.ts +0 -3
  152. package/lib/utils/index.d.ts +0 -5
@@ -1,1405 +1,11 @@
1
- import * as i0 from '@angular/core';
2
- import { Pipe, NgModule, Injectable, Inject } from '@angular/core';
3
- import tinycolor from 'tinycolor2';
4
- import tinygradient from 'tinygradient';
5
- import * as i1 from '@angular/platform-browser';
6
- import * as _ from 'lodash';
7
- import { Subject, fromEvent } from 'rxjs';
8
- import { DOCUMENT } from '@angular/common';
9
- import { Observable } from 'rxjs/internal/Observable';
10
- import merge from 'lodash-es/merge';
11
- import { debounceTime, distinctUntilChanged } from 'rxjs/operators';
12
-
13
- // @dynamic
14
- class AXObjectUtil {
15
- static deepJSONClone(obj) {
16
- return obj ? JSON.parse(JSON.stringify(obj)) : null;
17
- }
18
- static deepCopy(obj) {
19
- let copy;
20
- // Handle the 3 simple types, and null or undefined
21
- if (null == obj || 'object' !== typeof obj) {
22
- return obj;
23
- }
24
- // Handle Date
25
- if (obj instanceof Date) {
26
- copy = new Date();
27
- copy.setTime(obj.getTime());
28
- return copy;
29
- }
30
- // Handle Array
31
- if (obj instanceof Array) {
32
- copy = [];
33
- for (let i = 0, len = obj.length; i < len; i++) {
34
- copy[i] = AXObjectUtil.deepCopy(obj[i]);
35
- }
36
- return copy;
37
- }
38
- // Handle Object
39
- if (obj instanceof Object) {
40
- copy = {};
41
- for (const attr in obj) {
42
- if (obj.hasOwnProperty(attr)) {
43
- copy[attr] = AXObjectUtil.deepCopy(obj[attr]);
44
- }
45
- }
46
- return copy;
47
- }
48
- throw new Error('Unable to copy obj! Its type isn\'t supported.');
49
- }
50
- }
51
-
52
- // @dynamic
53
- class AXDrawingUtil {
54
- static collision(a, b) {
55
- const ac = a.getBoundingClientRect();
56
- const bc = b.getBoundingClientRect();
57
- if (ac.left < bc.left + bc.width && ac.left + ac.width > bc.left &&
58
- ac.top < bc.top + bc.height && ac.top + ac.height > bc.top) {
59
- return true;
60
- }
61
- else {
62
- return false;
63
- }
64
- }
65
- static isInElementBound(pos, element) {
66
- const elBound = element.getBoundingClientRect();
67
- return AXDrawingUtil.isInRecPoint(pos, {
68
- left: elBound.x,
69
- width: elBound.width,
70
- top: elBound.y,
71
- height: elBound.height
72
- });
73
- }
74
- static isInRecPoint(pos, rec) {
75
- return pos.x >= rec.left && pos.x <= (rec.left + rec.width) && pos.y >= rec.top && (pos.y <= (rec.top + rec.height));
76
- }
77
- }
78
-
79
- // @dynamic
80
- class AXStringUtil {
81
- static getWordBoundsAtPosition(str, position) {
82
- const isSpace = (c) => /[^a-zA-Z0-9]+/i.test(c);
83
- let start = position - 1;
84
- while (start >= 0 && !isSpace(str[start])) {
85
- start -= 1;
86
- }
87
- start = Math.max(0, start + 1);
88
- const leftSideString = str.slice(start).match(/[a-zA-Z0-9]+/i);
89
- start += leftSideString.index;
90
- let end = start + leftSideString[0].length;
91
- return {
92
- start,
93
- end
94
- };
95
- }
96
- }
97
-
98
- class AXColorUtil {
99
- static to(color, mode) {
100
- const _color = tinycolor(color);
101
- switch (mode) {
102
- case 'rgba':
103
- ;
104
- return _color.toRgb();
105
- case 'hsla':
106
- return _color.toHsl();
107
- case 'hsva':
108
- return _color.toHsv();
109
- default:
110
- return _color.toHex();
111
- }
112
- }
113
- ;
114
- static toString(color, mode) {
115
- const _color = tinycolor(color);
116
- switch (mode) {
117
- case 'rgba':
118
- return _color.toRgbString();
119
- case 'hsla':
120
- return _color.toHslString();
121
- case 'hsva':
122
- return _color.toHsvString();
123
- default:
124
- return _color.toHexString();
125
- }
126
- }
127
- ;
128
- static mix(baseColor, hex, percentage) {
129
- return tinycolor.mix(baseColor, hex, percentage).toString('rgb');
130
- }
131
- static multiply(color1, color2) {
132
- let rgb1 = tinycolor(color1).toRgb();
133
- let rgb2 = tinycolor(color2).toRgb();
134
- rgb1.b = Math.floor(rgb1.b * rgb2.b / 255);
135
- rgb1.g = Math.floor(rgb1.g * rgb2.g / 255);
136
- rgb1.r = Math.floor(rgb1.r * rgb2.r / 255);
137
- return tinycolor('rgb ' + rgb1.r + ' ' + rgb1.g + ' ' + rgb1.b).toString('rgb');
138
- }
139
- static toHexSting(color) {
140
- const _color = tinycolor(color);
141
- return _color.toHexString();
142
- }
143
- ;
144
- static toRGBString(color) {
145
- const _color = tinycolor(color);
146
- return _color.toRgbString();
147
- }
148
- ;
149
- static contrastToWhite(color) {
150
- return tinycolor.readability("#fff", color);
151
- }
152
- ;
153
- static lighten(hex, percentage) {
154
- return tinycolor(hex).lighten(percentage);
155
- }
156
- static darken(hex, percentage) {
157
- return tinycolor(hex).darken(percentage);
158
- }
159
- static equal(color1, color2) {
160
- return tinycolor.equals(color1, color2);
161
- }
162
- static gradient(values) {
163
- return tinygradient([...values]);
164
- }
165
- }
166
-
167
- class AXSafePipe {
168
- constructor(sanitizer) {
169
- this.sanitizer = sanitizer;
170
- }
171
- transform(value, type) {
172
- if (value == null || value == undefined || value == '')
173
- return null;
174
- switch (type) {
175
- case 'html': return this.sanitizer.bypassSecurityTrustHtml(value);
176
- case 'style': return this.sanitizer.bypassSecurityTrustStyle(value);
177
- case 'script': return this.sanitizer.bypassSecurityTrustScript(value);
178
- case 'url': return this.sanitizer.bypassSecurityTrustUrl(value);
179
- case 'resourceUrl': return this.sanitizer.bypassSecurityTrustResourceUrl(value);
180
- default: throw new Error(`Invalid safe type specified: ${type}`);
181
- }
182
- }
183
- }
184
- AXSafePipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.0", ngImport: i0, type: AXSafePipe, deps: [{ token: i1.DomSanitizer }], target: i0.ɵɵFactoryTarget.Pipe });
185
- AXSafePipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "14.0.0", ngImport: i0, type: AXSafePipe, name: "safe" });
186
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.0", ngImport: i0, type: AXSafePipe, decorators: [{
187
- type: Pipe,
188
- args: [{
189
- name: 'safe',
190
- pure: true
191
- }]
192
- }], ctorParameters: function () { return [{ type: i1.DomSanitizer }]; } });
193
-
194
- class AXCoreModule {
195
- }
196
- AXCoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.0", ngImport: i0, type: AXCoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
197
- AXCoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.0.0", ngImport: i0, type: AXCoreModule, declarations: [AXSafePipe], exports: [AXSafePipe] });
198
- AXCoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.0.0", ngImport: i0, type: AXCoreModule, providers: [] });
199
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.0", ngImport: i0, type: AXCoreModule, decorators: [{
200
- type: NgModule,
201
- args: [{
202
- imports: [],
203
- exports: [AXSafePipe],
204
- declarations: [AXSafePipe],
205
- providers: [],
206
- }]
207
- }] });
208
-
209
- // @dynamic
210
- class AXConfig {
211
- static get onChange() {
212
- return AXConfig.dataChangeSubject.asObservable();
213
- }
214
- static set(arg1, arg2) {
215
- if (arg1 && typeof arg1 == 'string') {
216
- _.set(AXConfig.dataModel, arg1, arg2);
217
- AXConfig.dataChangeSubject.next(AXConfig.dataModel);
218
- return;
219
- }
220
- if (arg1 && typeof arg1 == 'object') {
221
- _.merge(AXConfig.dataModel, arg1);
222
- AXConfig.dataChangeSubject.next(AXConfig.dataModel);
223
- return;
224
- }
225
- if (!arg1 && !arg2) {
226
- return AXConfig.dataChangeSubject.asObservable();
227
- }
228
- }
229
- static get(path, defaultValue) {
230
- return _.get(AXConfig.dataModel, path, defaultValue);
231
- }
232
- }
233
- AXConfig.dataModel = {};
234
- AXConfig.dataChangeSubject = new Subject();
235
-
236
- // @dynamic
237
- class AXDateTime {
238
- constructor(value = new Date(), calendar = AXConfig.get(`dateTime.calendar`)) {
239
- this._formatKeys = {
240
- ss: () => this.pad(this.date.getSeconds(), 2),
241
- s: () => this.date.getSeconds().toString(),
242
- //
243
- dd: () => this.pad(this.calendar.dayOfMonth(this.date), 2),
244
- d: () => this.calendar.dayOfMonth(this.date).toString(),
245
- //
246
- mm: () => this.pad(this.date.getMinutes(), 2),
247
- m: () => this.date.getMinutes().toString(),
248
- //
249
- MMMM: () => this.calendar.monthNames[this.calendar.monthOfYear(this.date) - 1],
250
- MMM: () => this.calendar.monthShortNames[this.calendar.monthOfYear(this.date) - 1],
251
- MM: () => this.pad(this.calendar.monthOfYear(this.date), 2),
252
- //
253
- DDDD: () => this.calendar.dayNames[this.calendar.dayOfWeek(this.date) - 1],
254
- DDD: () => this.calendar.dayShortNames[this.calendar.dayOfWeek(this.date) - 1],
255
- //
256
- yyyy: () => this.calendar.year(this.date).toString(),
257
- YYYY: () => this.calendar.year(this.date).toString(),
258
- yy: () => this.calendar.year(this.date).toString().substring(2),
259
- YY: () => this.calendar.year(this.date).toString().substring(2),
260
- //
261
- HH: () => this.pad(this.date.getHours(), 2),
262
- H: () => this.date.getHours().toString(),
263
- //
264
- hh: () => this.pad((this.date.getHours() % 12 || 12), 2),
265
- h: () => (this.date.getHours() % 12 || 12).toString(),
266
- //
267
- A: () => (this.date.getHours() < 12) ? 'am' : 'pm',
268
- a: () => (this.date.getHours() < 12) ? 'am' : 'pm',
269
- };
270
- this._calendar = AXDateTime.resolveCalendar(calendar);
271
- if (value instanceof Date) {
272
- this._date = value;
273
- }
274
- else {
275
- //TODO: parse jalali
276
- this._date = new Date(value);
277
- }
278
- }
279
- static convert(value, calendar = AXConfig.get('dateTime.calendar')) {
280
- let date;
281
- if (typeof value === 'string' || value instanceof String) {
282
- date = new AXDateTime(value, calendar);
283
- }
284
- else if (value instanceof Date) {
285
- date = new AXDateTime(value, calendar);
286
- }
287
- else if (value instanceof AXDateTime) {
288
- date = new AXDateTime(value.date, calendar);
289
- }
290
- return date;
291
- }
292
- static from(value = {
293
- calendar: AXConfig.get('dateTime.calendar'),
294
- year: 1,
295
- month: 1,
296
- date: 1,
297
- hours: 0,
298
- minutes: 0,
299
- seconds: 0,
300
- ms: 0
301
- }) {
302
- // let date: AXDateTime = new AXDateTime(new Date(), value.calendar);
303
- // date.set('year', value.year);
304
- // date.set('month', value.month);
305
- // date.set('day', value.date);
306
- // date.set('hour', value.hours);
307
- // date.set('minute', value.minutes);
308
- // date.set('second', value.seconds);
309
- // date.set('ms', value.ms);
310
- return AXDateTime.resolveCalendar(value.calendar).create(value);
311
- }
312
- static resolveCalendar(calendar) {
313
- return typeof calendar == 'string'
314
- ? AXConfig.get(`dateTime.calendars.${calendar}`)
315
- : calendar;
316
- }
317
- get date() {
318
- return this._date;
319
- }
320
- get calendar() {
321
- return this._calendar;
322
- }
323
- clone() {
324
- return new AXDateTime(this.date, this.calendar);
325
- }
326
- get dayOfMonth() {
327
- return this._calendar.dayOfMonth(this.date);
328
- }
329
- get dayOfYear() {
330
- return this._calendar.dayOfYear(this.date);
331
- }
332
- get dayOfWeek() {
333
- return this._calendar.dayOfWeek(this.date);
334
- }
335
- get hour() {
336
- return this._date.getHours();
337
- }
338
- get minute() {
339
- return this._date.getMinutes();
340
- }
341
- get second() {
342
- return this._date.getSeconds();
343
- }
344
- get year() {
345
- return this._calendar.year(this.date);
346
- }
347
- get monthOfYear() {
348
- return this._calendar.monthOfYear(this.date);
349
- }
350
- get weekOfYear() {
351
- return this._calendar.weekOfYear(this.date);
352
- }
353
- get month() {
354
- return new AXCalendarMonth(this);
355
- }
356
- add(unit, amount) {
357
- return this._calendar.add(this.date, unit, amount);
358
- }
359
- set(unit = 'day', value) {
360
- return this._calendar.set(this.date, unit, value);
361
- }
362
- duration(end, unit = 'day') {
363
- const range = new AXDateTimeRange(this, AXDateTime.convert(end, this.calendar.name()));
364
- return range.duration();
365
- }
366
- startOf(unit = 'day') {
367
- return this._calendar.startOf(this.date, unit);
368
- }
369
- endOf(unit = 'day') {
370
- return this._calendar.endOf(this.date, unit);
371
- }
372
- format(format = AXConfig.get('dateTime.shortDateFormat')) {
373
- const re = new RegExp(_.orderBy(Object.keys(this._formatKeys), c => c.length, ['desc']).join("|"), "gi");
374
- return format.replace(re, (matched) => {
375
- return this._formatKeys[matched]();
376
- });
377
- }
378
- pad(n, width, z = '0') {
379
- n = n + '';
380
- return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
381
- }
382
- toString(format = AXConfig.get('dateTime.shortDateFormat')) {
383
- return this.format(format);
384
- }
385
- equal(value, unit = 'day') {
386
- return this.compare(value, unit) == 0;
387
- }
388
- compare(value, unit = 'day') {
389
- const val = AXDateTime.convert(value, this.calendar.name());
390
- const func = (v1, v2) => {
391
- if (v1 == v2) {
392
- return 0;
393
- }
394
- else if (v1 > v2) {
395
- return 1;
396
- }
397
- else {
398
- return -1;
399
- }
400
- };
401
- let p = 0;
402
- switch (unit) {
403
- case 'year':
404
- return func(this.year, val.year);
405
- case 'week':
406
- p = this.compare(val, 'year');
407
- return p == 0 ? func(this.weekOfYear, val.weekOfYear) : p;
408
- case 'month':
409
- p = this.compare(val, 'year');
410
- return p == 0 ? func(this.monthOfYear, val.monthOfYear) : p;
411
- case 'day':
412
- p = this.compare(val, 'year');
413
- return p == 0 ? func(this.dayOfYear, val.dayOfYear) : p;
414
- case 'hour':
415
- p = this.compare(val, 'day');
416
- return p == 0 ? func(this.hour, val.hour) : p;
417
- case 'minute':
418
- p = this.compare(val, 'hour');
419
- return p == 0 ? func(this.minute, val.minute) : p;
420
- case 'second':
421
- p = this.compare(val, 'minute');
422
- return p == 0 ? func(this.second, val.second) : p;
423
- default:
424
- return func(this.date.getTime(), val.date.getTime());
425
- }
426
- }
427
- convert(calendar) {
428
- return AXDateTime.convert(this, calendar);
429
- }
430
- }
431
- class AXCalendarMonth {
432
- constructor(date) {
433
- this.index = date.date.getMonth();
434
- this.name = date.format('MMMM');
435
- this.range = new AXDateTimeRange(new AXDateTime(date.startOf('month').date, date.calendar), new AXDateTime(date.endOf('month').date, date.calendar));
436
- }
437
- get range() {
438
- return this._range;
439
- }
440
- set range(v) {
441
- this._range = v;
442
- }
443
- }
444
- class AXDateTimeRange {
445
- constructor(startTime, endTime) {
446
- this._startTime = startTime;
447
- this._endTime = endTime;
448
- }
449
- get startTime() {
450
- return this._startTime;
451
- }
452
- get endTime() {
453
- return this._endTime;
454
- }
455
- duration() {
456
- const result = {
457
- miliseconds: 0,
458
- seconds: 0,
459
- minutes: 0,
460
- hours: 0,
461
- days: 0,
462
- months: 0,
463
- years: 0,
464
- total: {
465
- miliseconds: 0,
466
- seconds: 0,
467
- minutes: 0,
468
- hours: 0,
469
- days: 0,
470
- weeks: 0,
471
- months: 0,
472
- years: 0,
473
- },
474
- };
475
- const one_second = 1000;
476
- const one_min = one_second * 60;
477
- const one_hour = one_min * 60;
478
- const one_day = one_hour * 24;
479
- const one_week = one_day * 7;
480
- const one_year = 365.25 * one_day;
481
- const one_month = one_year / 12;
482
- const startTime = this._startTime.date.getTime();
483
- const endTime = this._endTime.date.getTime();
484
- const diff = Math.abs(endTime - startTime);
485
- //
486
- result.total.miliseconds = diff;
487
- result.total.seconds = Number((diff / one_second).toFixed(2));
488
- result.total.minutes = Number((diff / one_min).toFixed(2));
489
- result.total.hours = Number((diff / one_hour).toFixed(2));
490
- result.total.days = Number((diff / one_day).toFixed(2));
491
- result.total.weeks = Number((diff / one_week).toFixed(2));
492
- //
493
- // let months = (this.endTime.year - this.startTime.year) * 12;
494
- // months += this.endTime.monthOfYear - this.startTime.monthOfYear + 1;
495
- // if (this.endTime.dayOfYear < this.startTime.dayOfYear) {
496
- // months--;
497
- // }
498
- // result.total.months = Math.abs(months);
499
- // TODO: review
500
- result.total.months = Number((diff / one_month).toFixed(2));
501
- result.total.years = Number((diff / one_year).toFixed(2));
502
- //
503
- result.miliseconds = result.total.miliseconds % 1000;
504
- result.seconds = Number((result.total.seconds % 60).toFixed(0));
505
- result.minutes = Number((result.total.minutes % 60).toFixed(0));
506
- result.hours = Number((result.total.hours % 24).toFixed(0));
507
- // TODO: review
508
- result.days = Number((result.total.days % 30.4).toFixed(0));
509
- result.months = Number((result.total.months % 12).toFixed(0));
510
- result.years = Number(result.total.years.toFixed(0));
511
- return result;
512
- }
513
- enumurate(unit = 'day', amount = 1) {
514
- // TODO: setptemper savingtime issue
515
- const result = [];
516
- let item = this._startTime.clone();
517
- while (item.compare(this._endTime, unit) < 1) {
518
- result.push(item);
519
- item = item.add(unit, amount);
520
- }
521
- return result;
522
- }
523
- includes(value, unit = 'day') {
524
- // TODO: ??
525
- return true;
526
- }
527
- }
528
-
529
- class AXDateTimePipe {
530
- constructor() { }
531
- transform(value, format, calendar) {
532
- if (value == null) {
533
- return '';
534
- }
535
- const date = value instanceof AXDateTime ? value.clone() : AXDateTime.convert(value, calendar);
536
- if (!format) {
537
- return date.format(AXConfig.get('dateTime.shortDateFormat'));
538
- }
539
- else {
540
- return date.format(format);
541
- }
542
- }
543
- }
544
- AXDateTimePipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.0", ngImport: i0, type: AXDateTimePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
545
- AXDateTimePipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "14.0.0", ngImport: i0, type: AXDateTimePipe, name: "axDate" });
546
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.0", ngImport: i0, type: AXDateTimePipe, decorators: [{
547
- type: Pipe,
548
- args: [{ name: 'axDate' }]
549
- }], ctorParameters: function () { return []; } });
550
-
551
- class GeorgianCalendar {
552
- constructor() {
553
- this.monthNames = [
554
- "January", "February", "March",
555
- "April", "May", "June", "July",
556
- "August", "September", "October",
557
- "November", "December"
558
- ];
559
- this.monthShortNames = [
560
- "Jan", "Feb", "Mar",
561
- "Apr", "May", "Jun", "Jul",
562
- "Aug", "Sep", "Oct",
563
- "Nov", "Dec"
564
- ];
565
- this.dayNames = [
566
- "Sunday", "Monday", "Tuesday", "Wednesday",
567
- "Thursday", "Friday", "Saturday"
568
- ];
569
- this.dayShortNames = [
570
- "Sun", "Mon", "Tue", "Wed",
571
- "Thu", "Fri", "Sat"
572
- ];
573
- }
574
- create(value) {
575
- return new AXDateTime(new Date(value.year, value.month - 1, value.date, value.hours || 0, value.minutes || 0, value.seconds || 0, value.ms || 0), this.name());
576
- }
577
- name() {
578
- return 'gregorian';
579
- }
580
- dayOfMonth(date) {
581
- return date.getDate();
582
- }
583
- dayOfYear(date) {
584
- let result = 0;
585
- let m = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
586
- if (this.isLeap(date)) {
587
- m[1] = 29;
588
- }
589
- for (let i = 0; i < date.getMonth(); i++) {
590
- result = result + m[i];
591
- }
592
- result += date.getDate();
593
- return result;
594
- }
595
- dayOfWeek(date) {
596
- return date.getDay() + 1;
597
- }
598
- weekOfYear(date) {
599
- const firstDay = new AXDateTime(date).startOf('year');
600
- return Math.ceil((((date.getTime() - firstDay.date.getTime()) / 86400000) + firstDay.date.getDay() + 1) / 7);
601
- }
602
- year(date) {
603
- return date.getFullYear();
604
- }
605
- monthOfYear(date) {
606
- return date.getMonth() + 1;
607
- }
608
- add(date, unit, amount) {
609
- let value = date.valueOf();
610
- switch (unit) {
611
- case 'second':
612
- value += 1000 * amount;
613
- break;
614
- case 'minute':
615
- value += 60000 * amount;
616
- break;
617
- case 'hour':
618
- value += 3600000 * amount;
619
- break;
620
- case 'month':
621
- const v = new Date(value);
622
- var mo = date.getMonth();
623
- var yr = date.getFullYear();
624
- mo = (mo + amount) % 12;
625
- if (0 > mo) {
626
- yr += (date.getMonth() + amount - mo - 12) / 12;
627
- mo += 12;
628
- }
629
- else
630
- yr += ((date.getMonth() + amount - mo) / 12);
631
- v.setMonth(mo);
632
- v.setFullYear(yr);
633
- value = v.valueOf();
634
- break;
635
- case 'week':
636
- value += 7 * 86400000 * amount;
637
- break;
638
- case 'year':
639
- const yv = new Date(value);
640
- yv.setFullYear(yv.getFullYear() + amount);
641
- value = yv.valueOf();
642
- break;
643
- case 'day':
644
- default:
645
- value += 86400000 * amount;
646
- }
647
- return new AXDateTime(new Date(value), this.name());
648
- }
649
- set(date, unit, value) {
650
- const clone = new Date(date.valueOf());
651
- switch (unit) {
652
- case 'second':
653
- clone.setHours(clone.getHours(), clone.getMinutes(), value, clone.getMilliseconds());
654
- break;
655
- case 'minute':
656
- clone.setHours(clone.getHours(), value, clone.getSeconds(), clone.getMilliseconds());
657
- break;
658
- case 'hour':
659
- clone.setHours(value, clone.getMinutes(), clone.getSeconds(), clone.getMilliseconds());
660
- break;
661
- default:
662
- case 'day':
663
- clone.setDate(value);
664
- break;
665
- case "week":
666
- break;
667
- case "month":
668
- clone.setMonth(Math.max(0, value - 1));
669
- break;
670
- case "year":
671
- clone.setFullYear(value);
672
- break;
673
- }
674
- return new AXDateTime(clone, this.name());
675
- }
676
- startOf(date, unit) {
677
- const clone = new Date(date.valueOf());
678
- switch (unit) {
679
- case 'second':
680
- clone.setHours(clone.getHours(), clone.getMinutes(), clone.getSeconds(), 0);
681
- return new AXDateTime(clone, this.name());
682
- case 'minute':
683
- clone.setHours(clone.getHours(), clone.getMinutes(), 0, 0);
684
- return new AXDateTime(clone, this.name());
685
- case 'hour':
686
- clone.setHours(clone.getHours(), 0, 0, 0);
687
- return new AXDateTime(clone, this.name());
688
- default:
689
- case 'day':
690
- clone.setHours(0, 0, 0, 0);
691
- return new AXDateTime(clone, this.name());
692
- case "week":
693
- const index = 0;
694
- const start = index >= 0 ? index : 0;
695
- const day = clone.getDay();
696
- const diff = clone.getDate() - day + (start > day ? start - 7 : start);
697
- clone.setDate(diff);
698
- return new AXDateTime(clone, this.name()).startOf('day');
699
- case "month":
700
- clone.setDate(1);
701
- return new AXDateTime(clone, this.name()).startOf('day');
702
- case "year":
703
- clone.setMonth(0);
704
- clone.setDate(1);
705
- return new AXDateTime(clone, this.name()).startOf('day');
706
- }
707
- }
708
- endOf(date, unit) {
709
- const clone = new Date(date.valueOf());
710
- switch (unit) {
711
- case 'second':
712
- clone.setHours(clone.getHours(), clone.getMinutes(), clone.getSeconds(), 999);
713
- return new AXDateTime(clone, this.name());
714
- case 'minute':
715
- clone.setHours(clone.getHours(), clone.getMinutes(), 59, 999);
716
- return new AXDateTime(clone, this.name());
717
- case 'hour':
718
- clone.setHours(clone.getHours(), 59, 59, 999);
719
- return new AXDateTime(clone, this.name());
720
- default:
721
- case 'day':
722
- clone.setHours(23, 59, 59, 999);
723
- return new AXDateTime(clone, this.name());
724
- case 'week':
725
- return this.startOf(date, 'week').add('day', 6).endOf('day');
726
- case 'month':
727
- return new AXDateTime(new Date(date.getFullYear(), date.getMonth() + 1, 0), this.name()).endOf('day');
728
- case "year":
729
- clone.setMonth(11);
730
- return new AXDateTime(clone, this.name()).endOf('month');
731
- }
732
- }
733
- isLeap(date) {
734
- let leapYear = new Date(date.getFullYear(), 1, 29);
735
- return leapYear.getDate() == 29;
736
- }
737
- }
738
-
739
- class JalaliCalendar {
740
- constructor() {
741
- this.monthNames = ("فروردین_اردیبهشت_خرداد_تیر_مرداد_شهریور_مهر_آبان_آذر_دی_بهمن_اسفند").split("_");
742
- this.monthShortNames = ("فروردین_اردیبهشت_خرداد_تیر_مرداد_شهریور_مهر_آبان_آذر_دی_بهمن_اسفند").split("_");
743
- this.dayNames = ("شنبه_یکشنبه_دوشنبه_سه شنبه_چهارشنبه_پنج شنبه_جمعه").split("_");
744
- this.dayShortNames = "ش_ی_د_س_چ_پ_ج".split("_");
745
- }
746
- create(value) {
747
- const a = this.toGregorian(value.year, value.month, value.date);
748
- return new AXDateTime(new Date(a.getFullYear(), a.getMonth(), a.getDate(), value.hours || 0, value.minutes || 0, value.seconds || 0, value.ms || 0), this.name());
749
- }
750
- name() {
751
- return 'jalali';
752
- }
753
- dayOfMonth(date) {
754
- return this.toJalali(date).day;
755
- }
756
- dayOfYear(date) {
757
- const j = this.toJalali(date);
758
- return (j.month <= 6 ? ((j.month - 1) * 31) : ((6 * 31) + (j.month - 7) * 30)) + j.day;
759
- }
760
- dayOfWeek(date) {
761
- return date.getDay() == 6 ? 1 : date.getDay() + 2;
762
- }
763
- weekOfYear(date) {
764
- //TODO : apply jalali
765
- const firstDay = new AXDateTime(date).startOf('year');
766
- return Math.ceil((((date.getTime() - firstDay.date.getTime()) / 86400000) + firstDay.date.getDay() + 1) / 7);
767
- }
768
- year(date) {
769
- return this.toJalali(date).year;
770
- }
771
- monthOfYear(date) {
772
- return this.toJalali(date).month;
773
- }
774
- add(date, unit, amount) {
775
- let value = date.valueOf();
776
- switch (unit) {
777
- case 'second':
778
- value += 1000 * amount;
779
- break;
780
- case 'minute':
781
- value += 60000 * amount;
782
- break;
783
- case 'hour':
784
- value += 3600000 * amount;
785
- break;
786
- case 'month':
787
- {
788
- const v = new Date(value);
789
- let jd = this.dayOfMonth(date);
790
- let jm = this.monthOfYear(date);
791
- let jy = this.year(date);
792
- const nm = (jm + amount);
793
- const ny = (nm % 12) ? Math.floor(nm / 12) : 0;
794
- jy += ny;
795
- jm = nm - (ny * 12);
796
- const vv = this.toGregorian(jy, jm, jd);
797
- v.setFullYear(vv.getFullYear());
798
- v.setMonth(vv.getMonth());
799
- v.setDate(vv.getDate());
800
- value = v.valueOf();
801
- break;
802
- }
803
- case 'week':
804
- value += 7 * 86400000 * amount;
805
- break;
806
- case 'year':
807
- {
808
- // const v = new Date(value);
809
- // v.setFullYear(v.getFullYear() + amount);
810
- // value = v.valueOf();
811
- // break
812
- const v = new Date(value);
813
- let jd = this.dayOfMonth(date);
814
- let jm = this.monthOfYear(date);
815
- let jy = this.year(date);
816
- const vv = this.toGregorian(jy + amount, jm, jd);
817
- v.setFullYear(vv.getFullYear());
818
- v.setMonth(vv.getMonth());
819
- v.setDate(vv.getDate());
820
- value = v.valueOf();
821
- break;
822
- }
823
- case 'day':
824
- default:
825
- value += 86400000 * amount;
826
- }
827
- return new AXDateTime(new Date(value), this.name());
828
- }
829
- set(date, unit, value) {
830
- const clone = new Date(date.valueOf());
831
- const jDate = this.toJalali(clone);
832
- switch (unit) {
833
- case 'second':
834
- clone.setHours(clone.getHours(), clone.getMinutes(), value, clone.getMilliseconds());
835
- break;
836
- case 'minute':
837
- clone.setHours(clone.getHours(), value, clone.getSeconds(), clone.getMilliseconds());
838
- break;
839
- case 'hour':
840
- clone.setHours(value, clone.getMinutes(), clone.getSeconds(), clone.getMilliseconds());
841
- break;
842
- default:
843
- case 'day':
844
- const gDate = this.toGregorian(jDate.year, jDate.month, value);
845
- clone.setDate(gDate.getDate());
846
- break;
847
- case "week":
848
- break;
849
- case "month":
850
- const gDate2 = this.toGregorian(jDate.year, value, jDate.day);
851
- clone.setMonth(gDate2.getMonth());
852
- break;
853
- case "year":
854
- const gDate3 = this.toGregorian(value, jDate.month, jDate.day);
855
- clone.setFullYear(gDate3.getFullYear());
856
- break;
857
- }
858
- return new AXDateTime(clone, this.name());
859
- }
860
- startOf(date, unit) {
861
- const clone = new Date(date.valueOf());
862
- switch (unit) {
863
- case 'second':
864
- clone.setHours(clone.getHours(), clone.getMinutes(), clone.getSeconds(), 0);
865
- return new AXDateTime(clone, this.name());
866
- case 'minute':
867
- clone.setHours(clone.getHours(), clone.getMinutes(), 0, 0);
868
- return new AXDateTime(clone, this.name());
869
- case 'hour':
870
- clone.setHours(clone.getHours(), 0, 0, 0);
871
- return new AXDateTime(clone, this.name());
872
- default:
873
- case 'day':
874
- clone.setHours(0, 0, 0, 0);
875
- return new AXDateTime(clone, this.name());
876
- case "week":
877
- return new AXDateTime(clone, this.name()).add('day', -this.dayOfWeek(clone) + 1).startOf('day');
878
- case "month":
879
- {
880
- const jy = this.year(date);
881
- const jm = this.monthOfYear(date);
882
- const gDate = this.toGregorian(jy, jm, 1);
883
- return new AXDateTime(gDate, this.name()).startOf('day');
884
- }
885
- case "year":
886
- {
887
- const jy = this.year(date);
888
- const gDate = this.toGregorian(jy, 1, 1);
889
- return new AXDateTime(gDate, this.name()).startOf('day');
890
- }
891
- }
892
- }
893
- endOf(date, unit) {
894
- const clone = new Date(date.valueOf());
895
- switch (unit) {
896
- case 'second':
897
- clone.setHours(clone.getHours(), clone.getMinutes(), clone.getSeconds(), 999);
898
- return new AXDateTime(clone, this.name());
899
- case 'minute':
900
- clone.setHours(clone.getHours(), clone.getMinutes(), 59, 999);
901
- return new AXDateTime(clone, this.name());
902
- case 'hour':
903
- clone.setHours(clone.getHours(), 59, 59, 999);
904
- return new AXDateTime(clone, this.name());
905
- default:
906
- case 'day':
907
- clone.setHours(23, 59, 59, 999);
908
- return new AXDateTime(clone, this.name());
909
- case 'week':
910
- {
911
- return this.startOf(date, 'week').add('day', 6).endOf('day');
912
- }
913
- case 'month':
914
- {
915
- const jy = this.year(date);
916
- const jm = this.monthOfYear(date);
917
- const jd = this.monthLength(jy, jm);
918
- const gDate = this.toGregorian(jy, jm, jd);
919
- return new AXDateTime(gDate, this.name()).endOf('day');
920
- }
921
- case "year":
922
- let jy = this.year(date);
923
- const gDate = this.toGregorian(jy, 12, this.monthLength(jy, 12));
924
- return new AXDateTime(gDate, this.name()).endOf('day');
925
- }
926
- }
927
- toJalali(date) {
928
- const gy = date.getFullYear();
929
- const gm = date.getMonth() + 1;
930
- const gd = date.getDate();
931
- const r = this.d2j(this.g2d(gy, gm, gd));
932
- return {
933
- year: r.jy,
934
- month: r.jm,
935
- day: r.jd,
936
- };
937
- }
938
- /*
939
- Converts a Jalaali date to Gregorian.
940
- */
941
- toGregorian(jy, jm, jd) {
942
- const g = this.d2g(this.j2d(jy, jm, jd));
943
- return new Date(g.gy, g.gm - 1, g.gd);
944
- }
945
- /*
946
- Checks whether a Jalaali date is valid or not.
947
- */
948
- isValid(jy, jm, jd) {
949
- return jy >= -61 && jy <= 3177 &&
950
- jm >= 1 && jm <= 12 &&
951
- jd >= 1 && jd <= this.monthLength(jy, jm);
952
- }
953
- /*
954
- Is this a leap year or not?
955
- */
956
- isLeapYear(jy) {
957
- return this.jalCal(jy).leap === 0;
958
- }
959
- /*
960
- Number of days in a given month in a Jalaali year.
961
- */
962
- monthLength(jy, jm) {
963
- if (jm <= 6)
964
- return 31;
965
- if (jm <= 11)
966
- return 30;
967
- if (this.isLeapYear(jy))
968
- return 30;
969
- return 29;
970
- }
971
- jalCal(jy) {
972
- // Jalaali years starting the 33-year rule.
973
- let breaks = [-61, 9, 38, 199, 426, 686, 756, 818, 1111, 1181, 1210,
974
- 1635, 2060, 2097, 2192, 2262, 2324, 2394, 2456, 3178
975
- ], bl = breaks.length, gy = jy + 621, leapJ = -14, jp = breaks[0], jm, jump, leap, leapG, march, n, i;
976
- if (jy < jp || jy >= breaks[bl - 1])
977
- throw new Error('Invalid Jalaali year ' + jy);
978
- // Find the limiting years for the Jalaali year jy.
979
- for (i = 1; i < bl; i += 1) {
980
- jm = breaks[i];
981
- jump = jm - jp;
982
- if (jy < jm)
983
- break;
984
- leapJ = leapJ + this.div(jump, 33) * 8 + this.div(this.mod(jump, 33), 4);
985
- jp = jm;
986
- }
987
- n = jy - jp;
988
- // Find the number of leap years from AD 621 to the beginning
989
- // of the current Jalaali year in the Persian calendar.
990
- leapJ = leapJ + this.div(n, 33) * 8 + this.div(this.mod(n, 33) + 3, 4);
991
- if (this.mod(jump, 33) === 4 && jump - n === 4)
992
- leapJ += 1;
993
- // And the same in the Gregorian calendar (until the year gy).
994
- leapG = this.div(gy, 4) - this.div((this.div(gy, 100) + 1) * 3, 4) - 150;
995
- // Determine the Gregorian date of Farvardin the 1st.
996
- march = 20 + leapJ - leapG;
997
- // Find how many years have passed since the last leap year.
998
- if (jump - n < 6)
999
- n = n - jump + this.div(jump + 4, 33) * 33;
1000
- leap = this.mod(this.mod(n + 1, 33) - 1, 4);
1001
- if (leap === -1) {
1002
- leap = 4;
1003
- }
1004
- return {
1005
- leap: leap,
1006
- gy: gy,
1007
- march: march
1008
- };
1009
- }
1010
- /*
1011
- Converts a date of the Jalaali calendar to the Julian Day number.
1012
- @param jy Jalaali year (1 to 3100)
1013
- @param jm Jalaali month (1 to 12)
1014
- @param jd Jalaali day (1 to 29/31)
1015
- @return Julian Day number
1016
- */
1017
- j2d(jy, jm, jd) {
1018
- let r = this.jalCal(jy);
1019
- return this.g2d(r.gy, 3, r.march) + (jm - 1) * 31 - this.div(jm, 7) * (jm - 7) + jd - 1;
1020
- }
1021
- /*
1022
- Converts the Julian Day number to a date in the Jalaali calendar.
1023
- @param jdn Julian Day number
1024
- @return
1025
- jy: Jalaali year (1 to 3100)
1026
- jm: Jalaali month (1 to 12)
1027
- jd: Jalaali day (1 to 29/31)
1028
- */
1029
- d2j(jdn) {
1030
- let gy = this.d2g(jdn).gy // Calculate Gregorian year (gy).
1031
- , jy = gy - 621, r = this.jalCal(jy), jdn1f = this.g2d(gy, 3, r.march), jd, jm, k;
1032
- // Find number of days that passed since 1 Farvardin.
1033
- k = jdn - jdn1f;
1034
- if (k >= 0) {
1035
- if (k <= 185) {
1036
- // The first 6 months.
1037
- jm = 1 + this.div(k, 31);
1038
- jd = this.mod(k, 31) + 1;
1039
- return {
1040
- jy: jy,
1041
- jm: jm,
1042
- jd: jd
1043
- };
1044
- }
1045
- else {
1046
- // The remaining months.
1047
- k -= 186;
1048
- }
1049
- }
1050
- else {
1051
- // Previous Jalaali year.
1052
- jy -= 1;
1053
- k += 179;
1054
- if (r.leap === 1)
1055
- k += 1;
1056
- }
1057
- jm = 7 + this.div(k, 30);
1058
- jd = this.mod(k, 30) + 1;
1059
- return {
1060
- jy: jy,
1061
- jm: jm,
1062
- jd: jd
1063
- };
1064
- }
1065
- g2d(gy, gm, gd) {
1066
- let d = this.div((gy + this.div(gm - 8, 6) + 100100) * 1461, 4)
1067
- + this.div(153 * this.mod(gm + 9, 12) + 2, 5)
1068
- + gd - 34840408;
1069
- d = d - this.div(this.div(gy + 100100 + this.div(gm - 8, 6), 100) * 3, 4) + 752;
1070
- return d;
1071
- }
1072
- d2g(jdn) {
1073
- let j, i, gd, gm, gy;
1074
- j = 4 * jdn + 139361631;
1075
- j = j + this.div(this.div(4 * jdn + 183187720, 146097) * 3, 4) * 4 - 3908;
1076
- i = this.div(this.mod(j, 1461), 4) * 5 + 308;
1077
- gd = this.div(this.mod(i, 153), 5) + 1;
1078
- gm = this.mod(this.div(i, 153), 12) + 1;
1079
- gy = this.div(j, 1461) - 100100 + this.div(8 - gm, 6);
1080
- return {
1081
- gy: gy,
1082
- gm: gm,
1083
- gd: gd
1084
- };
1085
- }
1086
- /*
1087
- Utility helper functions.
1088
- */
1089
- div(a, b) {
1090
- return ~~(a / b);
1091
- }
1092
- mod(a, b) {
1093
- return a - ~~(a / b) * b;
1094
- }
1095
- }
1096
-
1097
- class AXDateTimeModule {
1098
- constructor() {
1099
- AXConfig.set({
1100
- dateTime: {
1101
- calendars: {
1102
- jalali: new JalaliCalendar(),
1103
- gregorian: new GeorgianCalendar()
1104
- },
1105
- calendar: 'gregorian',
1106
- shortDateFormat: 'DDDD, d MMM yyyy'
1107
- }
1108
- });
1109
- }
1110
- }
1111
- AXDateTimeModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.0", ngImport: i0, type: AXDateTimeModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1112
- AXDateTimeModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.0.0", ngImport: i0, type: AXDateTimeModule, declarations: [AXDateTimePipe], exports: [AXDateTimePipe] });
1113
- AXDateTimeModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.0.0", ngImport: i0, type: AXDateTimeModule, providers: [] });
1114
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.0", ngImport: i0, type: AXDateTimeModule, decorators: [{
1115
- type: NgModule,
1116
- args: [{
1117
- imports: [],
1118
- exports: [AXDateTimePipe],
1119
- declarations: [AXDateTimePipe],
1120
- providers: [],
1121
- }]
1122
- }], ctorParameters: function () { return []; } });
1123
-
1124
- class AXEventService {
1125
- constructor() {
1126
- this.list = [];
1127
- }
1128
- broadcast(key, options) {
1129
- const d = this.list.find(c => c.key === key);
1130
- if (d) {
1131
- d.events.forEach(c => {
1132
- c(options);
1133
- });
1134
- }
1135
- }
1136
- on(key, callback) {
1137
- let d = this.list.find(c => c.key === key);
1138
- if (!d) {
1139
- d = { key, events: [] };
1140
- this.list.push(d);
1141
- }
1142
- d.events.push(callback);
1143
- }
1144
- destroy(key, callback) {
1145
- const d = this.list.find(c => c.key === key);
1146
- if (d) {
1147
- d.events = [];
1148
- }
1149
- }
1150
- }
1151
- AXEventService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.0", ngImport: i0, type: AXEventService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1152
- AXEventService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.0", ngImport: i0, type: AXEventService, providedIn: 'root' });
1153
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.0", ngImport: i0, type: AXEventService, decorators: [{
1154
- type: Injectable,
1155
- args: [{ providedIn: 'root' }]
1156
- }] });
1157
-
1158
- class AXHotkeysService {
1159
- constructor(eventManager, document) {
1160
- this.eventManager = eventManager;
1161
- this.document = document;
1162
- this.defaults = {
1163
- element: this.document
1164
- };
1165
- }
1166
- addShortcut(options) {
1167
- const merged = Object.assign(Object.assign({}, this.defaults), options);
1168
- const event = `keydown.${merged.keys}`;
1169
- return new Observable(observer => {
1170
- const handler = (e) => {
1171
- e.preventDefault();
1172
- observer.next(e);
1173
- };
1174
- const dispose = this.eventManager.addEventListener(merged.element, event, handler);
1175
- return () => {
1176
- dispose();
1177
- };
1178
- });
1179
- }
1180
- }
1181
- AXHotkeysService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.0", ngImport: i0, type: AXHotkeysService, deps: [{ token: i1.EventManager }, { token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable });
1182
- AXHotkeysService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.0", ngImport: i0, type: AXHotkeysService, providedIn: 'root' });
1183
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.0", ngImport: i0, type: AXHotkeysService, decorators: [{
1184
- type: Injectable,
1185
- args: [{ providedIn: 'root' }]
1186
- }], ctorParameters: function () {
1187
- return [{ type: i1.EventManager }, { type: Document, decorators: [{
1188
- type: Inject,
1189
- args: [DOCUMENT]
1190
- }] }];
1191
- } });
1192
-
1193
- // @dynamic
1194
- class AXTranslator {
1195
- static get onChange() {
1196
- return AXTranslator.dataChangeSubject.asObservable();
1197
- }
1198
- static load(lang, value) {
1199
- if (typeof value === 'object') {
1200
- if (!AXTranslator[`__data__${lang}`]) {
1201
- AXTranslator[`__data__${lang}`] = {};
1202
- }
1203
- AXTranslator[`__data__${lang}`] = merge(AXTranslator[`__data__${lang}`], value);
1204
- }
1205
- }
1206
- static use(lang) {
1207
- AXTranslator.lang = lang;
1208
- }
1209
- static get(key, arg1, arg2) {
1210
- const lang = arg1 && typeof arg1 == 'string' ? arg1 : AXTranslator.lang;
1211
- const params = arg1 && typeof arg1 == 'object' ? arg1 : arg2;
1212
- let result = _.get(AXTranslator[`__data__${lang}`], key, key);
1213
- const vars = typeof (result) == 'string' ? result === null || result === void 0 ? void 0 : result.match(this._varsRegx) : [];
1214
- if (vars === null || vars === void 0 ? void 0 : vars.length) {
1215
- vars.forEach(v => {
1216
- var _a;
1217
- const varKey = ((_a = v.match(this._varNameRegx)) === null || _a === void 0 ? void 0 : _a.length) ? v.match(this._varNameRegx)[0] : null;
1218
- if (varKey) {
1219
- const p = _.get(params, varKey) || this.get(varKey, lang);
1220
- if (p) {
1221
- result = result.replace(v, p);
1222
- }
1223
- }
1224
- });
1225
- }
1226
- return typeof (result) == 'string' ? result : JSON.stringify(result);
1227
- }
1228
- }
1229
- AXTranslator.lang = 'en';
1230
- AXTranslator.dataChangeSubject = new Subject();
1231
- AXTranslator._varsRegx = /((\$\{[a-zA-Z_0-9\.]+\})+)/gm;
1232
- AXTranslator._varNameRegx = /[a-zA-Z_0-9\.]+/gm;
1233
-
1234
- class AXTranslatorPipe {
1235
- transform(value, arg1, arg2) {
1236
- return AXTranslator.get(value, arg1, arg2);
1237
- }
1238
- }
1239
- AXTranslatorPipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.0", ngImport: i0, type: AXTranslatorPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
1240
- AXTranslatorPipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "14.0.0", ngImport: i0, type: AXTranslatorPipe, name: "trans" });
1241
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.0", ngImport: i0, type: AXTranslatorPipe, decorators: [{
1242
- type: Pipe,
1243
- args: [{ name: 'trans', pure: true }]
1244
- }] });
1245
-
1246
- class AXTranslationModule {
1247
- }
1248
- AXTranslationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.0", ngImport: i0, type: AXTranslationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1249
- AXTranslationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.0.0", ngImport: i0, type: AXTranslationModule, declarations: [AXTranslatorPipe], exports: [AXTranslatorPipe] });
1250
- AXTranslationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.0.0", ngImport: i0, type: AXTranslationModule, providers: [] });
1251
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.0", ngImport: i0, type: AXTranslationModule, decorators: [{
1252
- type: NgModule,
1253
- args: [{
1254
- imports: [],
1255
- exports: [AXTranslatorPipe],
1256
- declarations: [AXTranslatorPipe],
1257
- providers: [],
1258
- }]
1259
- }] });
1260
-
1261
- const isChrome = (win) => testUserAgent(win, /Chrome/i);
1262
- const isFirefox = (win) => testUserAgent(win, /Firefox/i);
1263
- const isEdge = (win) => testUserAgent(win, /Edge/i);
1264
- const isSafari = (win) => testUserAgent(win, /Safari/i);
1265
- const isOpera = (win) => testUserAgent(win, /Opera/i) || testUserAgent(win, /OPR/i);
1266
- const isMSIE = (win) => testUserAgent(win, /MSIE/i) || testUserAgent(win, /Trident/i);
1267
- const isMobileWeb = (win) => isMobile(win) && !isHybrid(win);
1268
- const isIpad = (win) => {
1269
- // iOS 12 and below
1270
- if (testUserAgent(win, /iPad/i)) {
1271
- return true;
1272
- }
1273
- // iOS 13+
1274
- if (testUserAgent(win, /Macintosh/i) && isMobile(win)) {
1275
- return true;
1276
- }
1277
- return false;
1278
- };
1279
- const isIphone = (win) => testUserAgent(win, /iPhone/i);
1280
- const isIOS = (win) => testUserAgent(win, /iPhone|iPod/i) || isIpad(win);
1281
- const isAndroid = (win) => testUserAgent(win, /android|sink/i);
1282
- const isAndroidTablet = (win) => {
1283
- return isAndroid(win) && !testUserAgent(win, /mobile/i);
1284
- };
1285
- const isPhablet = (win) => {
1286
- const width = win.innerWidth;
1287
- const height = win.innerHeight;
1288
- const smallest = Math.min(width, height);
1289
- const largest = Math.max(width, height);
1290
- return (smallest > 390 && smallest < 520) &&
1291
- (largest > 620 && largest < 800);
1292
- };
1293
- const isTablet = (win) => {
1294
- const width = win.innerWidth;
1295
- const height = win.innerHeight;
1296
- const smallest = Math.min(width, height);
1297
- const largest = Math.max(width, height);
1298
- return (isIpad(win) ||
1299
- isAndroidTablet(win) ||
1300
- ((smallest > 460 && smallest < 820) &&
1301
- (largest > 780 && largest < 1400)));
1302
- };
1303
- const isMobile = (win) => matchMedia(win, '(any-pointer:coarse)');
1304
- const isDesktop = (win) => !isMobile(win);
1305
- const isHybrid = (win) => isCordova(win) || isCapacitorNative(win);
1306
- const isCordova = (win) => !!(win['cordova'] || win['phonegap'] || win['PhoneGap']);
1307
- const isCapacitorNative = (win) => {
1308
- const capacitor = win['Capacitor'];
1309
- return !!(capacitor && capacitor.isNative);
1310
- };
1311
- const isElectron = (win) => testUserAgent(win, /electron/i);
1312
- const isPWA = (win) => !!(win.matchMedia('(display-mode: standalone)').matches || win.navigator.standalone);
1313
- const testUserAgent = (win, expr) => expr.test(win.navigator.userAgent);
1314
- const matchMedia = (win, query) => win.matchMedia(query).matches;
1315
- const PLATFORMS_MAP = {
1316
- 'Android': isAndroid,
1317
- 'iOS': isIOS,
1318
- 'Desktop': isDesktop,
1319
- 'Mobile': isMobile,
1320
- 'Chrome': isChrome,
1321
- 'Firefox': isFirefox,
1322
- 'Safari': isSafari,
1323
- 'Edge': isEdge,
1324
- 'Opera': isOpera,
1325
- 'Hybrid': isHybrid,
1326
- 'PWA': isPWA,
1327
- 'Electron': isElectron,
1328
- };
1329
- class AXPlatformEvent {
1330
- }
1331
- class AXPlatform {
1332
- constructor() {
1333
- this.resize = new Subject();
1334
- this.click = new Subject();
1335
- this.scroll = new Subject();
1336
- fromEvent(window, 'resize')
1337
- .pipe(debounceTime(100))
1338
- .pipe(distinctUntilChanged())
1339
- .subscribe((e) => {
1340
- this.resize.next({
1341
- nativeEvent: e,
1342
- source: this
1343
- });
1344
- //
1345
- this._setFullHeightRatio();
1346
- });
1347
- document.addEventListener('click', (e) => {
1348
- this.click.next({
1349
- nativeEvent: e,
1350
- source: this
1351
- });
1352
- }, true);
1353
- document.addEventListener('scroll', (e) => {
1354
- this.scroll.next({
1355
- nativeEvent: e,
1356
- source: this
1357
- });
1358
- }, true);
1359
- // init functions
1360
- this._setFullHeightRatio();
1361
- }
1362
- isRtl() {
1363
- return document.dir == 'rtl' || document.body.dir == 'rtl' || document.body.style.direction == 'rtl';
1364
- }
1365
- isLandscape() {
1366
- return window.innerHeight < window.innerWidth;
1367
- }
1368
- isPortrate() {
1369
- return !this.isLandscape();
1370
- }
1371
- is(name) {
1372
- return PLATFORMS_MAP[name](window) || false;
1373
- }
1374
- switchDarkMode() {
1375
- const _html = document.getElementsByTagName("html")[0];
1376
- _html.classList.add('ax-dark');
1377
- }
1378
- switchLightMode() {
1379
- const _html = document.getElementsByTagName("html")[0];
1380
- _html.classList.remove('ax-dark');
1381
- }
1382
- _setFullHeightRatio() {
1383
- document.querySelector(':root').style.setProperty('--ax-vh', window.innerHeight / 100 + 'px');
1384
- }
1385
- }
1386
- AXPlatform.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.0", ngImport: i0, type: AXPlatform, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1387
- AXPlatform.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.0", ngImport: i0, type: AXPlatform, providedIn: 'platform' });
1388
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.0", ngImport: i0, type: AXPlatform, decorators: [{
1389
- type: Injectable,
1390
- args: [{
1391
- providedIn: 'platform',
1392
- }]
1393
- }], ctorParameters: function () { return []; } });
1394
-
1395
- /**
1396
- * Public API refrences of core libraries
1397
- * @module @acorex/core
1398
- */
1
+ /*
2
+ * Public API Surface of core
3
+ */
4
+ const ACOREX_CORE = "@acorex/core";
1399
5
 
1400
6
  /**
1401
7
  * Generated bundle index. Do not edit.
1402
8
  */
1403
9
 
1404
- export { AXCalendarMonth, AXColorUtil, AXConfig, AXCoreModule, AXDateTime, AXDateTimeModule, AXDateTimePipe, AXDateTimeRange, AXDrawingUtil, AXEventService, AXHotkeysService, AXObjectUtil, AXPlatform, AXPlatformEvent, AXSafePipe, AXStringUtil, AXTranslationModule, AXTranslator, AXTranslatorPipe, GeorgianCalendar, JalaliCalendar, testUserAgent };
10
+ export { ACOREX_CORE };
1405
11
  //# sourceMappingURL=acorex-core.mjs.map