@acorex/core 5.1.2 → 5.1.6

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