ngwr 16.7.1 → 16.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.
- package/charts/donut-chart/styles/_index.scss +9 -3
- package/charts/meter-group/styles/_index.scss +8 -1
- package/charts/sparkline/styles/_index.scss +6 -3
- package/command-palette/styles/_index.scss +10 -0
- package/descriptions/styles/_index.scss +91 -0
- package/fesm2022/ngwr-anchor.mjs +48 -10
- package/fesm2022/ngwr-anchor.mjs.map +1 -1
- package/fesm2022/ngwr-carousel.mjs +3 -2
- package/fesm2022/ngwr-carousel.mjs.map +1 -1
- package/fesm2022/ngwr-charts-calendar-heatmap.mjs +3 -1
- package/fesm2022/ngwr-charts-calendar-heatmap.mjs.map +1 -1
- package/fesm2022/ngwr-charts-core.mjs +17 -0
- package/fesm2022/ngwr-charts-core.mjs.map +1 -1
- package/fesm2022/ngwr-charts-donut-chart-testing.mjs +27 -0
- package/fesm2022/ngwr-charts-donut-chart-testing.mjs.map +1 -1
- package/fesm2022/ngwr-charts-donut-chart.mjs +54 -6
- package/fesm2022/ngwr-charts-donut-chart.mjs.map +1 -1
- package/fesm2022/ngwr-charts-meter-group-testing.mjs +27 -0
- package/fesm2022/ngwr-charts-meter-group-testing.mjs.map +1 -1
- package/fesm2022/ngwr-charts-meter-group.mjs +54 -6
- package/fesm2022/ngwr-charts-meter-group.mjs.map +1 -1
- package/fesm2022/ngwr-charts-sparkline-testing.mjs +27 -0
- package/fesm2022/ngwr-charts-sparkline-testing.mjs.map +1 -1
- package/fesm2022/ngwr-charts-sparkline.mjs +45 -4
- package/fesm2022/ngwr-charts-sparkline.mjs.map +1 -1
- package/fesm2022/ngwr-checkbox.mjs +38 -3
- package/fesm2022/ngwr-checkbox.mjs.map +1 -1
- package/fesm2022/ngwr-color-picker-testing.mjs.map +1 -1
- package/fesm2022/ngwr-color-picker.mjs +4 -3
- package/fesm2022/ngwr-color-picker.mjs.map +1 -1
- package/fesm2022/ngwr-command-palette.mjs +39 -19
- package/fesm2022/ngwr-command-palette.mjs.map +1 -1
- package/fesm2022/ngwr-compare.mjs +4 -0
- package/fesm2022/ngwr-compare.mjs.map +1 -1
- package/fesm2022/ngwr-context-menu.mjs +7 -2
- package/fesm2022/ngwr-context-menu.mjs.map +1 -1
- package/fesm2022/ngwr-cookie.mjs +6 -3
- package/fesm2022/ngwr-cookie.mjs.map +1 -1
- package/fesm2022/ngwr-date-stamp-testing.mjs +3 -0
- package/fesm2022/ngwr-date-stamp-testing.mjs.map +1 -1
- package/fesm2022/ngwr-date-stamp.mjs +81 -4
- package/fesm2022/ngwr-date-stamp.mjs.map +1 -1
- package/fesm2022/ngwr-date.mjs +16 -2
- package/fesm2022/ngwr-date.mjs.map +1 -1
- package/fesm2022/ngwr-density.mjs +4 -3
- package/fesm2022/ngwr-density.mjs.map +1 -1
- package/fesm2022/ngwr-descriptions.mjs +77 -20
- package/fesm2022/ngwr-descriptions.mjs.map +1 -1
- package/fesm2022/ngwr-dialog.mjs +10 -7
- package/fesm2022/ngwr-dialog.mjs.map +1 -1
- package/fesm2022/ngwr-directives.mjs +12 -0
- package/fesm2022/ngwr-directives.mjs.map +1 -1
- package/fesm2022/ngwr-drawer.mjs +14 -8
- package/fesm2022/ngwr-drawer.mjs.map +1 -1
- package/fesm2022/ngwr-editor.mjs +1 -0
- package/fesm2022/ngwr-editor.mjs.map +1 -1
- package/fesm2022/ngwr-file-upload.mjs +4 -5
- package/fesm2022/ngwr-file-upload.mjs.map +1 -1
- package/fesm2022/ngwr-form.mjs.map +1 -1
- package/fesm2022/ngwr-hotkey.mjs +10 -5
- package/fesm2022/ngwr-hotkey.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-ar.mjs +18 -5
- package/fesm2022/ngwr-i18n-ar.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-cs.mjs +18 -5
- package/fesm2022/ngwr-i18n-cs.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-de.mjs +18 -5
- package/fesm2022/ngwr-i18n-de.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-en.mjs +18 -5
- package/fesm2022/ngwr-i18n-en.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-es.mjs +18 -5
- package/fesm2022/ngwr-i18n-es.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-fr.mjs +18 -5
- package/fesm2022/ngwr-i18n-fr.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-he.mjs +18 -5
- package/fesm2022/ngwr-i18n-he.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-hi.mjs +18 -5
- package/fesm2022/ngwr-i18n-hi.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-id.mjs +18 -5
- package/fesm2022/ngwr-i18n-id.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-it.mjs +18 -5
- package/fesm2022/ngwr-i18n-it.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-ja.mjs +18 -5
- package/fesm2022/ngwr-i18n-ja.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-kk.mjs +18 -5
- package/fesm2022/ngwr-i18n-kk.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-ko.mjs +18 -5
- package/fesm2022/ngwr-i18n-ko.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-nl.mjs +18 -5
- package/fesm2022/ngwr-i18n-nl.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-pl.mjs +18 -5
- package/fesm2022/ngwr-i18n-pl.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-pt.mjs +18 -5
- package/fesm2022/ngwr-i18n-pt.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-ru.mjs +18 -5
- package/fesm2022/ngwr-i18n-ru.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-sv.mjs +18 -5
- package/fesm2022/ngwr-i18n-sv.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-tr.mjs +18 -5
- package/fesm2022/ngwr-i18n-tr.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-uk.mjs +18 -5
- package/fesm2022/ngwr-i18n-uk.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-vi.mjs +18 -5
- package/fesm2022/ngwr-i18n-vi.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-zh-tw.mjs +18 -5
- package/fesm2022/ngwr-i18n-zh-tw.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-zh.mjs +18 -5
- package/fesm2022/ngwr-i18n-zh.mjs.map +1 -1
- package/fesm2022/ngwr-i18n.mjs +7 -6
- package/fesm2022/ngwr-i18n.mjs.map +1 -1
- package/fesm2022/ngwr-image-cropper-testing.mjs +33 -0
- package/fesm2022/ngwr-image-cropper-testing.mjs.map +1 -1
- package/fesm2022/ngwr-image-cropper.mjs +536 -30
- package/fesm2022/ngwr-image-cropper.mjs.map +1 -1
- package/fesm2022/ngwr-input-number.mjs +33 -10
- package/fesm2022/ngwr-input-number.mjs.map +1 -1
- package/fesm2022/ngwr-input-otp.mjs +24 -10
- package/fesm2022/ngwr-input-otp.mjs.map +1 -1
- package/fesm2022/ngwr-input.mjs +2 -2
- package/fesm2022/ngwr-input.mjs.map +1 -1
- package/fesm2022/ngwr-knob.mjs +5 -0
- package/fesm2022/ngwr-knob.mjs.map +1 -1
- package/fesm2022/ngwr-lightbox.mjs +5 -3
- package/fesm2022/ngwr-lightbox.mjs.map +1 -1
- package/fesm2022/ngwr-mention.mjs +2 -0
- package/fesm2022/ngwr-mention.mjs.map +1 -1
- package/fesm2022/ngwr-meta.mjs +43 -8
- package/fesm2022/ngwr-meta.mjs.map +1 -1
- package/fesm2022/ngwr-overlay.mjs +51 -2
- package/fesm2022/ngwr-overlay.mjs.map +1 -1
- package/fesm2022/ngwr-pagination.mjs +1 -1
- package/fesm2022/ngwr-pagination.mjs.map +1 -1
- package/fesm2022/ngwr-pipes.mjs +160 -8
- package/fesm2022/ngwr-pipes.mjs.map +1 -1
- package/fesm2022/ngwr-popconfirm.mjs +2 -2
- package/fesm2022/ngwr-popconfirm.mjs.map +1 -1
- package/fesm2022/ngwr-qr.mjs +65 -7
- package/fesm2022/ngwr-qr.mjs.map +1 -1
- package/fesm2022/ngwr-schema-form.mjs +2 -2
- package/fesm2022/ngwr-schema-form.mjs.map +1 -1
- package/fesm2022/ngwr-scroll.mjs +1 -2
- package/fesm2022/ngwr-scroll.mjs.map +1 -1
- package/fesm2022/ngwr-slider.mjs +22 -17
- package/fesm2022/ngwr-slider.mjs.map +1 -1
- package/fesm2022/ngwr-speed-dial.mjs +30 -1
- package/fesm2022/ngwr-speed-dial.mjs.map +1 -1
- package/fesm2022/ngwr-statistic.mjs +1 -1
- package/fesm2022/ngwr-stepper-testing.mjs +7 -1
- package/fesm2022/ngwr-stepper-testing.mjs.map +1 -1
- package/fesm2022/ngwr-stepper.mjs +55 -4
- package/fesm2022/ngwr-stepper.mjs.map +1 -1
- package/fesm2022/ngwr-switch.mjs +33 -3
- package/fesm2022/ngwr-switch.mjs.map +1 -1
- package/fesm2022/ngwr-timeline.mjs +4 -0
- package/fesm2022/ngwr-timeline.mjs.map +1 -1
- package/fesm2022/ngwr-toolbar.mjs +171 -16
- package/fesm2022/ngwr-toolbar.mjs.map +1 -1
- package/fesm2022/ngwr-tour.mjs +8 -3
- package/fesm2022/ngwr-tour.mjs.map +1 -1
- package/fesm2022/ngwr-transfer.mjs +3 -2
- package/fesm2022/ngwr-transfer.mjs.map +1 -1
- package/fesm2022/ngwr-tree.mjs +1 -1
- package/fesm2022/ngwr-utils.mjs +46 -8
- package/fesm2022/ngwr-utils.mjs.map +1 -1
- package/fesm2022/ngwr-version.mjs +1 -1
- package/fesm2022/ngwr-version.mjs.map +1 -1
- package/fesm2022/ngwr-virtual-scroll.mjs +2 -2
- package/fesm2022/ngwr-virtual-scroll.mjs.map +1 -1
- package/i18n/ar.json +18 -5
- package/i18n/cs.json +18 -5
- package/i18n/de.json +18 -5
- package/i18n/en.json +18 -5
- package/i18n/es.json +18 -5
- package/i18n/fr.json +18 -5
- package/i18n/he.json +18 -5
- package/i18n/hi.json +18 -5
- package/i18n/id.json +18 -5
- package/i18n/it.json +18 -5
- package/i18n/ja.json +18 -5
- package/i18n/kk.json +18 -5
- package/i18n/ko.json +18 -5
- package/i18n/nl.json +18 -5
- package/i18n/pl.json +18 -5
- package/i18n/pt.json +18 -5
- package/i18n/ru.json +18 -5
- package/i18n/sv.json +18 -5
- package/i18n/tr.json +18 -5
- package/i18n/uk.json +18 -5
- package/i18n/vi.json +18 -5
- package/i18n/zh-TW.json +18 -5
- package/i18n/zh.json +18 -5
- package/image-cropper/styles/_index.scss +30 -1
- package/llms-full.txt +9 -9
- package/package.json +1 -1
- package/schematics/use/rule.js +1 -0
- package/schematics/use/symbol-map.json +2 -0
- package/skills/ngwr/SKILL.md +2 -2
- package/stepper/styles/_index.scss +33 -0
- package/tour/styles/_index.scss +11 -7
- package/types/ngwr-anchor.d.ts +14 -1
- package/types/ngwr-charts-donut-chart-testing.d.ts +32 -3
- package/types/ngwr-charts-donut-chart.d.ts +45 -6
- package/types/ngwr-charts-meter-group-testing.d.ts +29 -1
- package/types/ngwr-charts-meter-group.d.ts +43 -4
- package/types/ngwr-charts-sparkline-testing.d.ts +32 -2
- package/types/ngwr-charts-sparkline.d.ts +42 -3
- package/types/ngwr-checkbox.d.ts +14 -0
- package/types/ngwr-color-picker-testing.d.ts +1 -1
- package/types/ngwr-command-palette.d.ts +2 -1
- package/types/ngwr-date-stamp-testing.d.ts +2 -0
- package/types/ngwr-date-stamp.d.ts +41 -2
- package/types/ngwr-date.d.ts +3 -1
- package/types/ngwr-descriptions.d.ts +33 -5
- package/types/ngwr-dialog.d.ts +11 -6
- package/types/ngwr-directives.d.ts +1 -0
- package/types/ngwr-drawer.d.ts +12 -4
- package/types/ngwr-file-upload.d.ts +1 -1
- package/types/ngwr-form.d.ts +4 -0
- package/types/ngwr-hotkey.d.ts +2 -0
- package/types/ngwr-image-cropper-testing.d.ts +33 -1
- package/types/ngwr-image-cropper.d.ts +214 -6
- package/types/ngwr-input-number.d.ts +14 -2
- package/types/ngwr-input-otp.d.ts +2 -0
- package/types/ngwr-lightbox.d.ts +1 -0
- package/types/ngwr-meta.d.ts +13 -1
- package/types/ngwr-overlay.d.ts +20 -1
- package/types/ngwr-pipes.d.ts +125 -1
- package/types/ngwr-qr.d.ts +17 -0
- package/types/ngwr-slider.d.ts +3 -1
- package/types/ngwr-speed-dial.d.ts +10 -0
- package/types/ngwr-stepper-testing.d.ts +10 -0
- package/types/ngwr-stepper.d.ts +47 -1
- package/types/ngwr-switch.d.ts +13 -0
- package/types/ngwr-toolbar.d.ts +27 -0
- package/types/ngwr-transfer.d.ts +2 -0
- package/types/ngwr-utils.d.ts +61 -2
- package/types/ngwr-version.d.ts +1 -1
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as i0 from "@angular/core";
|
|
2
|
-
import { Component, ViewEncapsulation, booleanAttribute, computed, inject, input } from "@angular/core";
|
|
2
|
+
import { Component, Injector, ViewEncapsulation, afterNextRender, booleanAttribute, computed, effect, inject, input, linkedSignal } from "@angular/core";
|
|
3
3
|
import { wrCheckStyles } from "ngwr/utils";
|
|
4
4
|
import { useI18nText } from "ngwr/i18n";
|
|
5
|
-
import { WR_DATE_STAMP_DEFAULTS, WrDateAdapter, wrIsDateOnly, wrIsNamedFormat, wrParseDate } from "ngwr/date";
|
|
5
|
+
import { WR_DATE_STAMP_DEFAULTS, WrDateAdapter, wrDateLocale, wrIsDateOnly, wrIsNamedFormat, wrParseDate } from "ngwr/date";
|
|
6
|
+
import { wrFormatRelativeTime } from "ngwr/pipes";
|
|
6
7
|
/**
|
|
7
8
|
* @license
|
|
8
9
|
*
|
|
@@ -16,9 +17,28 @@ function withSeconds(format) {
|
|
|
16
17
|
function pad(n, width = 2) {
|
|
17
18
|
return String(n).padStart(width, "0");
|
|
18
19
|
}
|
|
20
|
+
const SECOND = 1e3;
|
|
21
|
+
const MINUTE = 60 * SECOND;
|
|
22
|
+
const HOUR = 60 * MINUTE;
|
|
23
|
+
const DAY = 24 * HOUR;
|
|
24
|
+
function untilNextText(distance) {
|
|
25
|
+
const size = Math.abs(distance);
|
|
26
|
+
const step = size < MINUTE ? SECOND : size < HOUR ? MINUTE : size < DAY ? HOUR : DAY;
|
|
27
|
+
return distance > 0 ? size % step + 1 : step - size % step;
|
|
28
|
+
}
|
|
19
29
|
var WrDateStamp = class WrDateStamp {
|
|
20
30
|
constructor() {
|
|
21
31
|
if (typeof ngDevMode === "undefined" || ngDevMode) wrCheckStyles("date-stamp");
|
|
32
|
+
const injector = inject(Injector);
|
|
33
|
+
afterNextRender(() => {
|
|
34
|
+
effect((onCleanup) => {
|
|
35
|
+
this.now();
|
|
36
|
+
const delay = this.untilNextText(Date.now());
|
|
37
|
+
if (delay === null) return;
|
|
38
|
+
const timer = setTimeout(() => this.now.set(Date.now()), delay);
|
|
39
|
+
onCleanup(() => clearTimeout(timer));
|
|
40
|
+
}, { injector });
|
|
41
|
+
});
|
|
22
42
|
}
|
|
23
43
|
defaults = inject(WR_DATE_STAMP_DEFAULTS);
|
|
24
44
|
value = input(null, ...ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []);
|
|
@@ -32,6 +52,10 @@ var WrDateStamp = class WrDateStamp {
|
|
|
32
52
|
...ngDevMode ? { debugName: "todayTimeOnly" } : /* istanbul ignore next */ {},
|
|
33
53
|
transform: booleanAttribute
|
|
34
54
|
});
|
|
55
|
+
relative = input(this.defaults.relative ?? false, {
|
|
56
|
+
...ngDevMode ? { debugName: "relative" } : /* istanbul ignore next */ {},
|
|
57
|
+
transform: booleanAttribute
|
|
58
|
+
});
|
|
35
59
|
epochUnit = input(null, ...ngDevMode ? [{ debugName: "epochUnit" }] : /* istanbul ignore next */ []);
|
|
36
60
|
emptyLabel = input(null, ...ngDevMode ? [{ debugName: "emptyLabel" }] : /* istanbul ignore next */ []);
|
|
37
61
|
resolvedEmptyLabel = useI18nText(this.emptyLabel, "copyValue.empty", "-");
|
|
@@ -45,6 +69,8 @@ var WrDateStamp = class WrDateStamp {
|
|
|
45
69
|
});
|
|
46
70
|
if (date === null) return null;
|
|
47
71
|
if (wrIsDateOnly(value)) return {
|
|
72
|
+
at: date,
|
|
73
|
+
dayOnly: true,
|
|
48
74
|
iso: `${pad(date.getFullYear(), 4)}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`,
|
|
49
75
|
date: this.adapter.format(date, this.dateFormat()),
|
|
50
76
|
time: null
|
|
@@ -52,11 +78,47 @@ var WrDateStamp = class WrDateStamp {
|
|
|
52
78
|
const zoned = this.adapter.zoned();
|
|
53
79
|
const timeFormat = this.timeFormat();
|
|
54
80
|
return {
|
|
81
|
+
at: date,
|
|
82
|
+
dayOnly: false,
|
|
55
83
|
iso: date.toISOString(),
|
|
56
84
|
date: this.todayTimeOnly() && zoned.isSameDay(date, zoned.today()) ? null : zoned.format(date, this.dateFormat()),
|
|
57
85
|
time: zoned.format(date, this.seconds() ? withSeconds(timeFormat) : timeFormat)
|
|
58
86
|
};
|
|
59
87
|
}, ...ngDevMode ? [{ debugName: "parts" }] : /* istanbul ignore next */ []);
|
|
88
|
+
locale = wrDateLocale();
|
|
89
|
+
now = linkedSignal(() => {
|
|
90
|
+
this.value();
|
|
91
|
+
this.relative();
|
|
92
|
+
return Date.now();
|
|
93
|
+
}, ...ngDevMode ? [{ debugName: "now" }] : /* istanbul ignore next */ []);
|
|
94
|
+
today = computed(() => {
|
|
95
|
+
const zoned = this.adapter.zoned();
|
|
96
|
+
const now = new Date(this.now());
|
|
97
|
+
return zoned.createDate(zoned.getYear(now), zoned.getMonth(now), zoned.getDate(now));
|
|
98
|
+
}, ...ngDevMode ? [{ debugName: "today" }] : /* istanbul ignore next */ []);
|
|
99
|
+
relativeText = computed(() => {
|
|
100
|
+
const stamp = this.parts();
|
|
101
|
+
if (stamp === null || !this.relative()) return null;
|
|
102
|
+
if (!stamp.dayOnly) return wrFormatRelativeTime(stamp.at, this.locale(), { now: this.now() });
|
|
103
|
+
const zoned = this.adapter.zoned();
|
|
104
|
+
const today = this.today();
|
|
105
|
+
const local = new Date(zoned.getYear(today), zoned.getMonth(today), zoned.getDate(today));
|
|
106
|
+
return wrFormatRelativeTime(this.value(), this.locale(), { now: local });
|
|
107
|
+
}, ...ngDevMode ? [{ debugName: "relativeText" }] : /* istanbul ignore next */ []);
|
|
108
|
+
title = computed(() => {
|
|
109
|
+
const stamp = this.parts();
|
|
110
|
+
if (stamp === null || !this.relative()) return null;
|
|
111
|
+
return [stamp.date, stamp.time].filter((line) => line !== null).join(", ");
|
|
112
|
+
}, ...ngDevMode ? [{ debugName: "title" }] : /* istanbul ignore next */ []);
|
|
113
|
+
untilNextText(now) {
|
|
114
|
+
const stamp = this.parts();
|
|
115
|
+
if (stamp === null || !this.relative()) return null;
|
|
116
|
+
if (!stamp.dayOnly) return untilNextText(stamp.at.getTime() - now);
|
|
117
|
+
const zoned = this.adapter.zoned();
|
|
118
|
+
const today = this.today();
|
|
119
|
+
const next = zoned.createDate(zoned.getYear(today), zoned.getMonth(today), zoned.getDate(today) + 1);
|
|
120
|
+
return Math.max(1, next.getTime() - now);
|
|
121
|
+
}
|
|
60
122
|
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
61
123
|
minVersion: "12.0.0",
|
|
62
124
|
version: "22.3.0",
|
|
@@ -107,6 +169,13 @@ var WrDateStamp = class WrDateStamp {
|
|
|
107
169
|
isRequired: false,
|
|
108
170
|
transformFunction: null
|
|
109
171
|
},
|
|
172
|
+
relative: {
|
|
173
|
+
classPropertyName: "relative",
|
|
174
|
+
publicName: "relative",
|
|
175
|
+
isSignal: true,
|
|
176
|
+
isRequired: false,
|
|
177
|
+
transformFunction: null
|
|
178
|
+
},
|
|
110
179
|
epochUnit: {
|
|
111
180
|
classPropertyName: "epochUnit",
|
|
112
181
|
publicName: "epochUnit",
|
|
@@ -127,7 +196,7 @@ var WrDateStamp = class WrDateStamp {
|
|
|
127
196
|
classAttribute: "wr-date-stamp"
|
|
128
197
|
},
|
|
129
198
|
ngImport: i0,
|
|
130
|
-
template: "@if (parts(); as stamp) {\n <time class=\"wr-date-stamp__value\" [attr.datetime]=\"stamp.iso\">\n @if (stamp.date !== null) {\n
|
|
199
|
+
template: "@if (parts(); as stamp) {\n <time class=\"wr-date-stamp__value\" [attr.datetime]=\"stamp.iso\" [attr.title]=\"title()\">\n @if (relativeText(); as text) {\n <span class=\"wr-date-stamp__relative\">{{ text }}</span>\n } @else {\n @if (stamp.date !== null) {\n <span class=\"wr-date-stamp__date\">{{ stamp.date }}</span>\n }\n @if (stamp.time !== null) {\n <span class=\"wr-date-stamp__time\">{{ stamp.time }}</span>\n }\n }\n </time>\n} @else {\n <span class=\"wr-date-stamp__empty\">{{ resolvedEmptyLabel() }}</span>\n}\n",
|
|
131
200
|
encapsulation: i0.ViewEncapsulation.None
|
|
132
201
|
});
|
|
133
202
|
};
|
|
@@ -145,7 +214,7 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
145
214
|
class: "wr-date-stamp",
|
|
146
215
|
"[class.wr-date-stamp--empty]": "parts() === null"
|
|
147
216
|
},
|
|
148
|
-
template: "@if (parts(); as stamp) {\n <time class=\"wr-date-stamp__value\" [attr.datetime]=\"stamp.iso\">\n @if (stamp.date !== null) {\n
|
|
217
|
+
template: "@if (parts(); as stamp) {\n <time class=\"wr-date-stamp__value\" [attr.datetime]=\"stamp.iso\" [attr.title]=\"title()\">\n @if (relativeText(); as text) {\n <span class=\"wr-date-stamp__relative\">{{ text }}</span>\n } @else {\n @if (stamp.date !== null) {\n <span class=\"wr-date-stamp__date\">{{ stamp.date }}</span>\n }\n @if (stamp.time !== null) {\n <span class=\"wr-date-stamp__time\">{{ stamp.time }}</span>\n }\n }\n </time>\n} @else {\n <span class=\"wr-date-stamp__empty\">{{ resolvedEmptyLabel() }}</span>\n}\n"
|
|
149
218
|
}]
|
|
150
219
|
}],
|
|
151
220
|
ctorParameters: () => [],
|
|
@@ -190,6 +259,14 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
190
259
|
required: false
|
|
191
260
|
}]
|
|
192
261
|
}],
|
|
262
|
+
relative: [{
|
|
263
|
+
type: i0.Input,
|
|
264
|
+
args: [{
|
|
265
|
+
isSignal: true,
|
|
266
|
+
alias: "relative",
|
|
267
|
+
required: false
|
|
268
|
+
}]
|
|
269
|
+
}],
|
|
193
270
|
epochUnit: [{
|
|
194
271
|
type: i0.Input,
|
|
195
272
|
args: [{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ngwr-date-stamp.mjs","names":[],"sources":["../../../projects/lib/date-stamp/date-stamp.ts","../../../projects/lib/date-stamp/date-stamp.html"],"sourcesContent":["/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { Component, ViewEncapsulation, booleanAttribute, computed, inject, input } from '@angular/core';\n\nimport {\n type WrDateFormat,\n type WrEpochUnit,\n WR_DATE_STAMP_DEFAULTS,\n WrDateAdapter,\n wrIsDateOnly,\n wrIsNamedFormat,\n wrParseDate,\n} from 'ngwr/date';\nimport { useI18nText } from 'ngwr/i18n';\nimport { wrCheckStyles } from 'ngwr/utils';\n\ninterface Stamp {\n readonly iso: string;\n readonly date: string | null;\n readonly time: string | null;\n}\n\n/** The format with seconds: the `Seconds` twin of a named key, `ss` after the minutes of a token string. */\nfunction withSeconds(format: string): string {\n if (wrIsNamedFormat(format)) return /^(?:time|shortDateTime)(?:12h|24h)?$/.test(format) ? `${format}Seconds` : format;\n return format.includes('ss') ? format : format.replace('mm', 'mm:ss');\n}\n\nfunction pad(n: number, width = 2): string {\n return String(n).padStart(width, '0');\n}\n\n/**\n * A moment in two lines, for a table cell: the date over the time.\n *\n * Both lines are written by the date adapter, so they are in the interface\n * language and, for an instant, on the wall clock of\n * `withDates({ timeZone })`, and they follow both at runtime. The value is read\n * as `wrDate` reads it: a `Date`, an epoch number or a string, under the\n * `epochUnit` and `zonelessIn` of `withDates()`. A date-only string\n * (`'2026-11-12'`) is a day, so it shows the date line alone and does not\n * shift with the zone.\n *\n * `withDates({ stamp })` sets the formats, `todayTimeOnly` and `seconds` for\n * every stamp of the app; an input set here wins.\n *\n * The lines sit in one `<time>` whose `datetime` is the instant in ISO 8601,\n * or the day for a date-only string. `null`, `undefined`, `''` and a value\n * that is not a date are empty: the component shows `emptyLabel`.\n *\n * @example\n * ```html\n * <wr-date-stamp [value]=\"row.createdAt\" />\n * <wr-date-stamp [value]=\"row.createdAt\" dateFormat=\"d MMM yyyy\" timeFormat=\"time24hSeconds\" />\n * <wr-date-stamp [value]=\"message.sentAt\" todayTimeOnly seconds />\n * ```\n *\n * @see https://ngwr.dev/reference/components/date-stamp\n */\n@Component({\n selector: 'wr-date-stamp',\n templateUrl: './date-stamp.html',\n encapsulation: ViewEncapsulation.None,\n host: { class: 'wr-date-stamp', '[class.wr-date-stamp--empty]': 'parts() === null' },\n})\nexport class WrDateStamp {\n constructor() {\n if (typeof ngDevMode === 'undefined' || ngDevMode) wrCheckStyles('date-stamp');\n }\n\n private readonly defaults = inject(WR_DATE_STAMP_DEFAULTS);\n\n /**\n * The moment shown: a `Date`, an epoch number, or a string `wrParseDate`\n * reads. `null`, `undefined`, `''` and a value that is not a date are empty.\n *\n * @default null\n */\n readonly value = input<Date | string | number | null | undefined>(null);\n\n /**\n * Format of the first line: a named key or a token string (`'d MMM yyyy'`).\n * `withDates({ stamp })` changes the default.\n *\n * @default 'mediumDate'\n */\n readonly dateFormat = input<WrDateFormat | (string & {})>(this.defaults.dateFormat ?? 'mediumDate');\n\n /**\n * Format of the second line: a named key (`'time24hSeconds'`) or a token\n * string (`'HH:mm'`). `withDates({ stamp })` changes the default.\n *\n * @default 'time'\n */\n readonly timeFormat = input<WrDateFormat | (string & {})>(this.defaults.timeFormat ?? 'time');\n\n /**\n * Write the seconds in the time line: `'time'` is read as `'timeSeconds'`\n * and `'HH:mm'` as `'HH:mm:ss'`. A format that already has them is left\n * alone. `withDates({ stamp })` changes the default.\n *\n * @default false\n */\n readonly seconds = input(this.defaults.seconds ?? false, { transform: booleanAttribute });\n\n /**\n * Show the time alone for a value from today. Today is the day in the\n * display zone, read when the stamp renders: one left on screen past\n * midnight keeps its single line. A date-only value keeps its date.\n * `withDates({ stamp })` changes the default.\n *\n * @default false\n */\n readonly todayTimeOnly = input(this.defaults.todayTimeOnly ?? false, { transform: booleanAttribute });\n\n /**\n * What a number in `value` counts since the epoch: `'ms'`, `'us'`, `'s'` or\n * `'auto'`, by size. `null` follows `withDates({ epochUnit })`.\n *\n * @default null\n */\n readonly epochUnit = input<WrEpochUnit | null>(null);\n\n /** What stands in for an empty value. Falls back to `copyValue.empty`, then `'-'`. */\n readonly emptyLabel = input<string | null>(null);\n\n // The key `wr-copy-value` reads: one placeholder for an empty cell, whatever fills the cell.\n protected readonly resolvedEmptyLabel = useI18nText(this.emptyLabel, 'copyValue.empty', '-');\n\n private readonly adapter = inject<WrDateAdapter<Date>>(WrDateAdapter);\n\n protected readonly parts = computed<Stamp | null>(() => {\n const value = this.value();\n const epochUnit = this.epochUnit();\n const date = wrParseDate(value, { ...this.adapter.parseOptions(), ...(epochUnit ? { epochUnit } : {}) });\n if (date === null) return null;\n\n if (wrIsDateOnly(value)) {\n return {\n iso: `${pad(date.getFullYear(), 4)}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`,\n date: this.adapter.format(date, this.dateFormat()),\n time: null,\n };\n }\n\n const zoned = this.adapter.zoned();\n const timeFormat = this.timeFormat();\n return {\n iso: date.toISOString(),\n date: this.todayTimeOnly() && zoned.isSameDay(date, zoned.today()) ? null : zoned.format(date, this.dateFormat()),\n time: zoned.format(date, this.seconds() ? withSeconds(timeFormat) : timeFormat),\n };\n });\n}\n","@if (parts(); as stamp) {\n <time class=\"wr-date-stamp__value\" [attr.datetime]=\"stamp.iso\">\n @if (stamp.date !== null) {\n <span class=\"wr-date-stamp__date\">{{ stamp.date }}</span>\n }\n @if (stamp.time !== null) {\n <span class=\"wr-date-stamp__time\">{{ stamp.time }}</span>\n }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BAAA;IAAA,YAAA;IAAA,UAAA;IAAA,YAAA;IAAA,mBAAA;GAAA;GAAA,YAAA;IAAA,mBAAA;IAAA,YAAA;IAAA,UAAA;IAAA,YAAA;IAAA,mBAAA;GAAA;GAAA,SAAA;IAAA,mBAAA;IAAA,YAAA;IAAA,UAAA;IAAA,YAAA;IAAA,mBAAA;GAAA;GAAA,eAAA;IAAA,mBAAA;IAAA,YAAA;IAAA,UAAA;IAAA,YAAA;IAAA,mBAAA;GAAA;GAAA,WAAA;IAAA,mBAAA;IAAA,YAAA;IAAA,UAAA;IAAA,YAAA;IAAA,mBAAA;GAAA;GAAA,YAAA;IAAA,mBAAA;IAAA,YAAA;IAAA,UAAA;IAAA,YAAA;IAAA,mBAAA;GAAA;EAAA;EAAA,MAAA;GAAA,YAAA,EAAA,8BAAA,mBAAA;GAAA,gBAAA;EAAA;EAAA,UAAA;EAAA,UCtExB;EAYA,eAAA,GAAA,kBAAA;CAAA,CAAA;;AD0Da,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAW,YAAA,CAAA;EANvB,MAAA;EACW,MAAA,CAAA;GAAA,UAAA;GAAe,eAEV,kBAAkB;GAAI,MAC/B;IAAE,OAAO;IAAiB,gCAAgC;GAAkB;GAAE,UAAA;EAAA,CAAA"}
|
|
1
|
+
{"version":3,"file":"ngwr-date-stamp.mjs","names":[],"sources":["../../../projects/lib/date-stamp/date-stamp.ts","../../../projects/lib/date-stamp/date-stamp.html"],"sourcesContent":["/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport {\n Component,\n Injector,\n ViewEncapsulation,\n afterNextRender,\n booleanAttribute,\n computed,\n effect,\n inject,\n input,\n linkedSignal,\n} from '@angular/core';\n\nimport {\n type WrDateFormat,\n type WrEpochUnit,\n WR_DATE_STAMP_DEFAULTS,\n WrDateAdapter,\n wrDateLocale,\n wrIsDateOnly,\n wrIsNamedFormat,\n wrParseDate,\n} from 'ngwr/date';\nimport { useI18nText } from 'ngwr/i18n';\nimport { wrFormatRelativeTime } from 'ngwr/pipes';\nimport { wrCheckStyles } from 'ngwr/utils';\n\ninterface Stamp {\n readonly at: Date;\n readonly dayOnly: boolean;\n readonly iso: string;\n readonly date: string | null;\n readonly time: string | null;\n}\n\n/** The format with seconds: the `Seconds` twin of a named key, `ss` after the minutes of a token string. */\nfunction withSeconds(format: string): string {\n if (wrIsNamedFormat(format)) return /^(?:time|shortDateTime)(?:12h|24h)?$/.test(format) ? `${format}Seconds` : format;\n return format.includes('ss') ? format : format.replace('mm', 'mm:ss');\n}\n\nfunction pad(n: number, width = 2): string {\n return String(n).padStart(width, '0');\n}\n\nconst SECOND = 1000;\nconst MINUTE = 60 * SECOND;\nconst HOUR = 60 * MINUTE;\nconst DAY = 24 * HOUR;\n\n/**\n * Milliseconds until the relative text of an instant `distance` away changes:\n * the next whole second under a minute, minute under an hour, hour under a\n * day, then day. `wrFormatRelativeTime` cuts the count, so the text of a past\n * value moves on a whole step and the text of a coming one right after it.\n */\nfunction untilNextText(distance: number): number {\n const size = Math.abs(distance);\n const step = size < MINUTE ? SECOND : size < HOUR ? MINUTE : size < DAY ? HOUR : DAY;\n return distance > 0 ? (size % step) + 1 : step - (size % step);\n}\n\n/**\n * A moment in two lines, for a table cell: the date over the time.\n *\n * Both lines are written by the date adapter, so they are in the interface\n * language and, for an instant, on the wall clock of\n * `withDates({ timeZone })`, and they follow both at runtime. The value is read\n * as `wrDate` reads it: a `Date`, an epoch number or a string, under the\n * `epochUnit` and `zonelessIn` of `withDates()`. A date-only string\n * (`'2026-11-12'`) is a day, so it shows the date line alone and does not\n * shift with the zone.\n *\n * `relative` shows how far the moment is from now instead (\"5 minutes ago\"),\n * and keeps that text current on a timer. The date and the time stay in the\n * `title` of the `<time>`.\n *\n * `withDates({ stamp })` sets the formats, `todayTimeOnly`, `seconds` and\n * `relative` for every stamp of the app; an input set here wins.\n *\n * The lines sit in one `<time>` whose `datetime` is the instant in ISO 8601,\n * or the day for a date-only string. `null`, `undefined`, `''` and a value\n * that is not a date are empty: the component shows `emptyLabel`.\n *\n * @example\n * ```html\n * <wr-date-stamp [value]=\"row.createdAt\" />\n * <wr-date-stamp [value]=\"row.createdAt\" dateFormat=\"d MMM yyyy\" timeFormat=\"time24hSeconds\" />\n * <wr-date-stamp [value]=\"message.sentAt\" todayTimeOnly seconds />\n * <wr-date-stamp [value]=\"comment.createdAt\" relative />\n * ```\n *\n * @see https://ngwr.dev/reference/components/date-stamp\n */\n@Component({\n selector: 'wr-date-stamp',\n templateUrl: './date-stamp.html',\n encapsulation: ViewEncapsulation.None,\n host: { class: 'wr-date-stamp', '[class.wr-date-stamp--empty]': 'parts() === null' },\n})\nexport class WrDateStamp {\n constructor() {\n if (typeof ngDevMode === 'undefined' || ngDevMode) wrCheckStyles('date-stamp');\n\n // The browser only, and after the first paint: the server renders the text once and keeps no timer.\n const injector = inject(Injector);\n afterNextRender(() => {\n effect(\n onCleanup => {\n // Re-armed by each tick. Measured from the real clock, not the sample: a restart for\n // another reason (a new format) must not push the next change a whole step away.\n this.now();\n const delay = this.untilNextText(Date.now());\n if (delay === null) return;\n const timer = setTimeout(() => this.now.set(Date.now()), delay);\n onCleanup(() => clearTimeout(timer));\n },\n { injector }\n );\n });\n }\n\n private readonly defaults = inject(WR_DATE_STAMP_DEFAULTS);\n\n /**\n * The moment shown: a `Date`, an epoch number, or a string `wrParseDate`\n * reads. `null`, `undefined`, `''` and a value that is not a date are empty.\n *\n * @default null\n */\n readonly value = input<Date | string | number | null | undefined>(null);\n\n /**\n * Format of the first line: a named key or a token string (`'d MMM yyyy'`).\n * `withDates({ stamp })` changes the default.\n *\n * @default 'mediumDate'\n */\n readonly dateFormat = input<WrDateFormat | (string & {})>(this.defaults.dateFormat ?? 'mediumDate');\n\n /**\n * Format of the second line: a named key (`'time24hSeconds'`) or a token\n * string (`'HH:mm'`). `withDates({ stamp })` changes the default.\n *\n * @default 'time'\n */\n readonly timeFormat = input<WrDateFormat | (string & {})>(this.defaults.timeFormat ?? 'time');\n\n /**\n * Write the seconds in the time line: `'time'` is read as `'timeSeconds'`\n * and `'HH:mm'` as `'HH:mm:ss'`. A format that already has them is left\n * alone. `withDates({ stamp })` changes the default.\n *\n * @default false\n */\n readonly seconds = input(this.defaults.seconds ?? false, { transform: booleanAttribute });\n\n /**\n * Show the time alone for a value from today. Today is the day in the\n * display zone, read when the stamp renders: one left on screen past\n * midnight keeps its single line. A date-only value keeps its date.\n * `withDates({ stamp })` changes the default.\n *\n * @default false\n */\n readonly todayTimeOnly = input(this.defaults.todayTimeOnly ?? false, { transform: booleanAttribute });\n\n /**\n * Show how far the moment is from now (\"5 minutes ago\", \"tomorrow\") in\n * place of the two lines, as `wrFormatRelativeTime` writes it, in the\n * language the stamp formats in. The text is kept current: it is written\n * again each second under a minute, each minute under an hour, each hour\n * under a day and each day after that, from a timer that starts after the\n * first render and never on the server. The date and the time move to the\n * `title` of the `<time>`. A date-only value is compared as a day (\"today\",\n * \"yesterday\"). `withDates({ stamp })` changes the default.\n *\n * @default false\n */\n readonly relative = input(this.defaults.relative ?? false, { transform: booleanAttribute });\n\n /**\n * What a number in `value` counts since the epoch: `'ms'`, `'us'`, `'s'` or\n * `'auto'`, by size. `null` follows `withDates({ epochUnit })`.\n *\n * @default null\n */\n readonly epochUnit = input<WrEpochUnit | null>(null);\n\n /** What stands in for an empty value. Falls back to `copyValue.empty`, then `'-'`. */\n readonly emptyLabel = input<string | null>(null);\n\n // The key `wr-copy-value` reads: one placeholder for an empty cell, whatever fills the cell.\n protected readonly resolvedEmptyLabel = useI18nText(this.emptyLabel, 'copyValue.empty', '-');\n\n private readonly adapter = inject<WrDateAdapter<Date>>(WrDateAdapter);\n\n protected readonly parts = computed<Stamp | null>(() => {\n const value = this.value();\n const epochUnit = this.epochUnit();\n const date = wrParseDate(value, { ...this.adapter.parseOptions(), ...(epochUnit ? { epochUnit } : {}) });\n if (date === null) return null;\n\n if (wrIsDateOnly(value)) {\n return {\n at: date,\n dayOnly: true,\n iso: `${pad(date.getFullYear(), 4)}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`,\n date: this.adapter.format(date, this.dateFormat()),\n time: null,\n };\n }\n\n const zoned = this.adapter.zoned();\n const timeFormat = this.timeFormat();\n return {\n at: date,\n dayOnly: false,\n iso: date.toISOString(),\n date: this.todayTimeOnly() && zoned.isSameDay(date, zoned.today()) ? null : zoned.format(date, this.dateFormat()),\n time: zoned.format(date, this.seconds() ? withSeconds(timeFormat) : timeFormat),\n };\n });\n private readonly locale = wrDateLocale();\n\n /**\n * The current time the relative text is measured from. The timer moves it,\n * and a new value or `relative` turned on reads the clock again: a stamp of\n * last year ticks once a day, and must not measure the next value from then.\n */\n private readonly now = linkedSignal(() => {\n this.value();\n this.relative();\n return Date.now();\n });\n\n /** Midnight of today in the display zone, which a date-only value is compared with. */\n private readonly today = computed(() => {\n const zoned = this.adapter.zoned();\n const now = new Date(this.now());\n return zoned.createDate(zoned.getYear(now), zoned.getMonth(now), zoned.getDate(now));\n });\n\n protected readonly relativeText = computed<string | null>(() => {\n const stamp = this.parts();\n if (stamp === null || !this.relative()) return null;\n if (!stamp.dayOnly) return wrFormatRelativeTime(stamp.at, this.locale(), { now: this.now() });\n\n // A day is not moved by the zone: it is compared with the zone's today as two local days.\n const zoned = this.adapter.zoned();\n const today = this.today();\n const local = new Date(zoned.getYear(today), zoned.getMonth(today), zoned.getDate(today));\n return wrFormatRelativeTime(this.value(), this.locale(), { now: local });\n });\n\n /** The two lines as one, for the `title` a relative stamp keeps them in. */\n protected readonly title = computed<string | null>(() => {\n const stamp = this.parts();\n if (stamp === null || !this.relative()) return null;\n return [stamp.date, stamp.time].filter(line => line !== null).join(', ');\n });\n\n /** Milliseconds to the next change of the relative text, `null` when there is none to keep current. */\n private untilNextText(now: number): number | null {\n const stamp = this.parts();\n if (stamp === null || !this.relative()) return null;\n if (!stamp.dayOnly) return untilNextText(stamp.at.getTime() - now);\n // Built, not added: on a day whose midnight the zone skips, `addDays` would keep the 01:00 it starts at.\n const zoned = this.adapter.zoned();\n const today = this.today();\n const next = zoned.createDate(zoned.getYear(today), zoned.getMonth(today), zoned.getDate(today) + 1);\n return Math.max(1, next.getTime() - now);\n }\n}\n","@if (parts(); as stamp) {\n <time class=\"wr-date-stamp__value\" [attr.datetime]=\"stamp.iso\" [attr.title]=\"title()\">\n @if (relativeText(); as text) {\n <span class=\"wr-date-stamp__relative\">{{ text }}</span>\n } @else {\n @if (stamp.date !== null) {\n <span class=\"wr-date-stamp__date\">{{ stamp.date }}</span>\n }\n @if (stamp.time !== null) {\n <span class=\"wr-date-stamp__time\">{{ stamp.time }}</span>\n }\n }\n </time>\n} @else {\n <span class=\"wr-date-stamp__empty\">{{ resolvedEmptyLabel() }}</span>\n}\n"],"mappings":";;;;;;;;;;;;AA2CA,SAAS,YAAY,QAAc;CACjC,IAAI,gBAAgB,MAAM,GAAG,OAAO,uCAAuC,KAAK,MAAM,IAAI,GAAG,OAAM,WAAY;CAC/G,OAAO,OAAO,SAAS,IAAI,IAAI,SAAS,OAAO,QAAQ,MAAM,OAAO;AACtE;AAEA,SAAS,IAAI,GAAW,QAAQ,GAAC;CAC/B,OAAO,OAAO,CAAC,CAAC,CAAC,SAAS,OAAO,GAAG;AACtC;AAEA,MAAM,SAAS;AACf,MAAM,SAAS,KAAK;AACpB,MAAM,OAAO,KAAK;AAClB,MAAM,MAAM,KAAK;AAQjB,SAAS,cAAc,UAAgB;CACrC,MAAM,OAAO,KAAK,IAAI,QAAQ;CAC9B,MAAM,OAAO,OAAO,SAAS,SAAS,OAAO,OAAO,SAAS,OAAO,MAAM,OAAO;CACjF,OAAO,WAAW,IAAK,OAAO,OAAQ,IAAI,OAAQ,OAAO;AAC3D;AAwCA,IAAa,cAAb,MAAa,YAAW;CACtB,cAAA;EACE,IAAI,OAAO,cAAc,eAAe,WAAW,cAAc,YAAY;EAG7E,MAAM,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AAA,CAAA;EANvB,MAAA;EACW,MAAA,CAAA;GAAA,UAAA;GAAe,eAEV,kBAAkB;GAAI,MAC/B;IAAE,OAAO;IAAiB,gCAAgC;GAAkB;GAAE,UAAA;EAAA,CAAA"}
|
package/fesm2022/ngwr-date.mjs
CHANGED
|
@@ -214,6 +214,8 @@ function digitsToNumber(text, numerals) {
|
|
|
214
214
|
function isAllDigits(text, numerals) {
|
|
215
215
|
return text.length > 0 && !Number.isNaN(digitsToNumber(text, numerals));
|
|
216
216
|
}
|
|
217
|
+
const SUNDAY_REGIONS = new Set("AG AS BD BR BS BT BW BZ CA CO DM DO ET GT GU HK HN ID IL IN JM JP KE KH KR LA MH MM MO MT MX MZ NI NP PA PE PH PK PR PT PY SA SG SV TH TT TW UM US VE VI WS YE ZA ZW".split(" "));
|
|
218
|
+
const SATURDAY_REGIONS = new Set("AF BH DJ DZ EG IQ IR JO KW LY OM QA SD SY".split(" "));
|
|
217
219
|
const SHORT_DATE = {
|
|
218
220
|
year: "numeric",
|
|
219
221
|
month: "numeric",
|
|
@@ -552,11 +554,23 @@ var WrNativeDateAdapter = class WrNativeDateAdapter extends WrDateAdapter {
|
|
|
552
554
|
return this.parseWithTokens(raw, formatKeyOrString);
|
|
553
555
|
}
|
|
554
556
|
getFirstDayOfWeek() {
|
|
557
|
+
let region;
|
|
555
558
|
try {
|
|
556
|
-
const
|
|
559
|
+
const locale = new Intl.Locale(this.locale);
|
|
560
|
+
const info = locale.getWeekInfo?.() ?? locale.weekInfo;
|
|
557
561
|
if (info && typeof info.firstDay === "number") return info.firstDay % 7;
|
|
562
|
+
region = locale.maximize().region;
|
|
558
563
|
} catch {}
|
|
559
|
-
|
|
564
|
+
if (!region) for (const part of this.locale.split(/[-_]/).slice(1)) {
|
|
565
|
+
if (part.length === 1) break;
|
|
566
|
+
if (/^[a-z]{2}$/i.test(part)) {
|
|
567
|
+
region = part.toUpperCase();
|
|
568
|
+
break;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
if (region && SUNDAY_REGIONS.has(region)) return 0;
|
|
572
|
+
if (region && SATURDAY_REGIONS.has(region)) return 6;
|
|
573
|
+
return 1;
|
|
560
574
|
}
|
|
561
575
|
intlOptions(options) {
|
|
562
576
|
return {
|