@telperion/elements 7.1.0 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/.build-manifest.json +12 -1
  2. package/README.md +31 -0
  3. package/custom-elements.json +1672 -0
  4. package/date/date-element.cjs +231 -0
  5. package/date/date-element.cjs.map +1 -0
  6. package/date/date-element.js +229 -0
  7. package/date/date-element.js.map +1 -0
  8. package/date/format-pattern.cjs +49 -0
  9. package/date/format-pattern.cjs.map +1 -0
  10. package/date/format-pattern.js +47 -0
  11. package/date/format-pattern.js.map +1 -0
  12. package/date/format.cjs +57 -0
  13. package/date/format.cjs.map +1 -0
  14. package/date/format.js +51 -0
  15. package/date/format.js.map +1 -0
  16. package/date/index.cjs +17 -0
  17. package/date/index.cjs.map +1 -0
  18. package/date/index.d.cts +171 -0
  19. package/date/index.d.ts +171 -0
  20. package/date/index.js +6 -0
  21. package/date/index.js.map +1 -0
  22. package/date/intl.cjs +36 -0
  23. package/date/intl.cjs.map +1 -0
  24. package/date/intl.js +32 -0
  25. package/date/intl.js.map +1 -0
  26. package/date/locale.cjs +36 -0
  27. package/date/locale.cjs.map +1 -0
  28. package/date/locale.js +34 -0
  29. package/date/locale.js.map +1 -0
  30. package/date/names.cjs +41 -0
  31. package/date/names.cjs.map +1 -0
  32. package/date/names.js +37 -0
  33. package/date/names.js.map +1 -0
  34. package/date/parse-fields.cjs +80 -0
  35. package/date/parse-fields.cjs.map +1 -0
  36. package/date/parse-fields.js +75 -0
  37. package/date/parse-fields.js.map +1 -0
  38. package/date/parse-iso.cjs +41 -0
  39. package/date/parse-iso.cjs.map +1 -0
  40. package/date/parse-iso.js +39 -0
  41. package/date/parse-iso.js.map +1 -0
  42. package/date/parse-numeric.cjs +53 -0
  43. package/date/parse-numeric.cjs.map +1 -0
  44. package/date/parse-numeric.js +50 -0
  45. package/date/parse-numeric.js.map +1 -0
  46. package/date/parse-pattern.cjs +123 -0
  47. package/date/parse-pattern.cjs.map +1 -0
  48. package/date/parse-pattern.js +121 -0
  49. package/date/parse-pattern.js.map +1 -0
  50. package/date/parse.cjs +35 -0
  51. package/date/parse.cjs.map +1 -0
  52. package/date/parse.js +33 -0
  53. package/date/parse.js.map +1 -0
  54. package/date/relative.cjs +47 -0
  55. package/date/relative.cjs.map +1 -0
  56. package/date/relative.js +44 -0
  57. package/date/relative.js.map +1 -0
  58. package/date/resolution.cjs +62 -0
  59. package/date/resolution.cjs.map +1 -0
  60. package/date/resolution.js +59 -0
  61. package/date/resolution.js.map +1 -0
  62. package/date/styles.cjs +21 -0
  63. package/date/styles.cjs.map +1 -0
  64. package/date/styles.js +19 -0
  65. package/date/styles.js.map +1 -0
  66. package/date/ticker.cjs +71 -0
  67. package/date/ticker.cjs.map +1 -0
  68. package/date/ticker.js +69 -0
  69. package/date/ticker.js.map +1 -0
  70. package/date/tokens.cjs +94 -0
  71. package/date/tokens.cjs.map +1 -0
  72. package/date/tokens.js +91 -0
  73. package/date/tokens.js.map +1 -0
  74. package/date/zone.cjs +110 -0
  75. package/date/zone.cjs.map +1 -0
  76. package/date/zone.js +101 -0
  77. package/date/zone.js.map +1 -0
  78. package/fesm/elements.mjs +1053 -2
  79. package/fesm/elements.mjs.map +1 -1
  80. package/iife/date/index.js +53 -0
  81. package/iife/date/index.js.map +1 -0
  82. package/iife/elements.js +52 -34
  83. package/iife/elements.js.map +1 -1
  84. package/index.cjs +11 -0
  85. package/index.cjs.map +1 -1
  86. package/index.d.cts +1 -0
  87. package/index.d.ts +1 -0
  88. package/index.js +5 -0
  89. package/index.js.map +1 -1
  90. package/package.json +31 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.cjs","sources":["../../../../libs/elements/src/date/format.ts"],"sourcesContent":[null],"names":["formatRelative","formatPattern","dateTimeFormat"],"mappings":";;;;;;AAKO,MAAM,OAAO,GAAyB,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM;AACxE,MAAM,cAA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2BAAa,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC;AAC5D,QAAA,KAAK,QAAQ;YACX,OAAOC,mBAAc,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC;;AAEpH;AAEA;SACgB,UAAU,CAAC,IAAU,EAAE,MAAe,EAAE,QAAiB,EAAA;IACvE,OAAOA,mBAAc,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC;AAChG;;;;;;;;"}
package/date/format.js ADDED
@@ -0,0 +1,51 @@
1
+ import { formatPattern } from './format-pattern.js';
2
+ import { dateTimeFormat } from './intl.js';
3
+ import { formatRelative } from './relative.js';
4
+
5
+ const PRESETS = ["short", "medium", "long", "full"];
6
+ const DEFAULT_PRESET = "medium";
7
+ /**
8
+ * Interprets the `format`, `date-style` and `time-style` attributes.
9
+ *
10
+ * - `relative` → relative time ("3 minutes ago").
11
+ * - A preset name (`short`, `medium`, `long`, `full`) or empty → `Intl`
12
+ * `dateStyle` + `timeStyle`, each overridable (or omitted with `none`).
13
+ * - Anything else → a moment-style token pattern.
14
+ */
15
+ function resolveFormat(format, dateStyle, timeStyle) {
16
+ const value = format.trim();
17
+ if (value === "relative")
18
+ return { kind: "relative" };
19
+ if (value && !PRESETS.includes(value))
20
+ return { kind: "pattern", pattern: format };
21
+ const preset = (value || DEFAULT_PRESET);
22
+ const date = pickStyle(dateStyle, preset);
23
+ const time = pickStyle(timeStyle, preset);
24
+ // Both parts omitted would render nothing; keep the date.
25
+ if (!date && !time)
26
+ return { kind: "preset", dateStyle: preset };
27
+ return { kind: "preset", dateStyle: date, timeStyle: time };
28
+ }
29
+ function pickStyle(override, preset) {
30
+ if (override === "none")
31
+ return undefined;
32
+ return override && PRESETS.includes(override) ? override : preset;
33
+ }
34
+ /** Renders `date` according to a resolved format. */
35
+ function formatDate(date, spec, { locale, timeZone, now }) {
36
+ switch (spec.kind) {
37
+ case "relative":
38
+ return formatRelative(date, now, locale);
39
+ case "pattern":
40
+ return formatPattern(date, spec.pattern, locale, timeZone);
41
+ case "preset":
42
+ return dateTimeFormat(locale, { dateStyle: spec.dateStyle, timeStyle: spec.timeStyle, timeZone }).format(date);
43
+ }
44
+ }
45
+ /** A full, unambiguous rendering used for the tooltip of relative dates. */
46
+ function formatFull(date, locale, timeZone) {
47
+ return dateTimeFormat(locale, { dateStyle: "full", timeStyle: "long", timeZone }).format(date);
48
+ }
49
+
50
+ export { DEFAULT_PRESET, PRESETS, formatDate, formatFull, resolveFormat };
51
+ //# sourceMappingURL=format.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.js","sources":["../../../../libs/elements/src/date/format.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAKO,MAAM,OAAO,GAAyB,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM;AACxE,MAAM,cAAc,GAAc;AAezC;;;;;;;AAOG;SACa,aAAa,CAAC,MAAc,EAAE,SAA6B,EAAE,SAA6B,EAAA;AACxG,IAAA,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,EAAE;IAE3B,IAAI,KAAK,KAAK,UAAU;AAAE,QAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE;IAErD,IAAI,KAAK,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAkB,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE;AAE/F,IAAA,MAAM,MAAM,IAAI,KAAK,IAAI,cAAc,CAAc;IACrD,MAAM,IAAI,GAAG,SAAS,CAAC,SAAS,EAAE,MAAM,CAAC;IACzC,MAAM,IAAI,GAAG,SAAS,CAAC,SAAS,E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,17 @@
1
+ 'use strict';
2
+
3
+ var dateElement = require('./date-element.cjs');
4
+ var format = require('./format.cjs');
5
+ var formatPattern = require('./format-pattern.cjs');
6
+ var relative = require('./relative.cjs');
7
+ var parse = require('./parse.cjs');
8
+
9
+
10
+
11
+ exports.DateElement = dateElement.DateElement;
12
+ exports.formatDate = format.formatDate;
13
+ exports.resolveFormat = format.resolveFormat;
14
+ exports.formatPattern = formatPattern.formatPattern;
15
+ exports.formatRelative = relative.formatRelative;
16
+ exports.parseDate = parse.parseDate;
17
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;"}
@@ -0,0 +1,171 @@
1
+ import { LitElement, PropertyValues } from 'lit';
2
+
3
+ /** `Intl.DateTimeFormat` style used by the preset formats (`short`, `medium`, `long`, `full`). */
4
+ type DateStyle = "short" | "medium" | "long" | "full";
5
+ /** Per-part override for presets: a style, or `none` to omit that part. */
6
+ type DateStyleOverride = DateStyle | "none";
7
+ /** Accepted by the `value` property. Strings are parsed like the text content. */
8
+ type DateInput = Date | number | string;
9
+ /** `detail` of the `tp-date-invalid` event. */
10
+ interface DateInvalidEventDetail {
11
+ /** The input that could not be parsed. */
12
+ input: string;
13
+ }
14
+
15
+ declare global {
16
+ interface HTMLElementTagNameMap {
17
+ /**
18
+ * A localized date/time. The date comes from the text content (or the
19
+ * `datetime` attribute / `value` property); empty or invalid input shows
20
+ * the current time, kept live.
21
+ *
22
+ * @example
23
+ * ```html
24
+ * <tp-date format="DD MMMM YYYY">2024-01-22</tp-date>
25
+ * <tp-date format="HH:mm:ss"></tp-date>
26
+ * <tp-date format="relative" datetime="2024-01-22T14:30:00Z"></tp-date>
27
+ * ```
28
+ */
29
+ "tp-date": DateElement;
30
+ }
31
+ interface HTMLElementEventMap {
32
+ "tp-date-invalid": CustomEvent<DateInvalidEventDetail>;
33
+ }
34
+ }
35
+ /**
36
+ * `<tp-date>` &mdash; a localized, optionally live date/time.
37
+ *
38
+ * - **Source** (first non-empty wins): the `value` property, the `datetime`
39
+ * attribute, the text content. Accepts ISO 8601, epoch milliseconds, or a
40
+ * numeric date in the locale's order (`22/01/2024` in `tr`); `input-format`
41
+ * pins a moment-style pattern instead.
42
+ * - **Fallback**: empty or invalid input renders the current time. Invalid
43
+ * input also sets the `invalid` attribute and fires `tp-date-invalid`.
44
+ * - **Format**: a preset (`short` / `medium` / `long` / `full`, via `Intl`),
45
+ * `relative`, or a moment-style pattern such as `DD/MM/YYYY HH:mm`.
46
+ * - **Live updates**: the current time and relative dates re-render on a
47
+ * shared, boundary-aligned clock at the cadence the format needs (each
48
+ * second for `ss`, each minute for `mm`, ...). Fixed dates in an absolute
49
+ * format never tick. Ticking pauses while the tab is hidden.
50
+ * - The text content stays in light DOM as the no-JS / pre-upgrade fallback;
51
+ * the rendered value is a `<time datetime>` in shadow DOM.
52
+ *
53
+ * @element tp-date
54
+ *
55
+ * @attr {string} [format=""] - `short`, `medium` (default), `long`, `full`, `relative`, or a moment-style pattern.
56
+ * @attr {"short" | "medium" | "long" | "full" | "none"} date-style - Presets only. Overrides the date part; `none` omits it.
57
+ * @attr {"short" | "medium" | "long" | "full" | "none"} time-style - Presets only. Overrides the time part; `none` omits it.
58
+ * @attr {string} [input-format=""] - Moment-style pattern used to parse the input, e.g. `DD/MM/YYYY`.
59
+ * @attr {string} [datetime=""] - The date to show. Takes precedence over the text content.
60
+ * @attr {string} [locale=""] - BCP 47 locale. Defaults to the nearest `lang` attribute, then the browser.
61
+ * @attr {string} [time-zone=""] - IANA time zone (`UTC`, `Europe/Istanbul`) for display and for parsing wall times. Defaults to local.
62
+ * @attr {boolean} [live=false] - Forces ticking even for a fixed date in an absolute format.
63
+ * @attr {number} [interval=0] - Custom tick period in ms. `0` derives it from the format.
64
+ * @attr {boolean} invalid - Read-only. Present when the input could not be parsed.
65
+ *
66
+ * @fires tp-date-invalid - When a non-empty input cannot be parsed. `detail: { input }`.
67
+ *
68
+ * @csspart time - The rendered `<time>` element.
69
+ *
70
+ * @cssprop --tp-date-numeric - `font-variant-numeric` of the output. Defaults to `tabular-nums`.
71
+ */
72
+ declare class DateElement extends LitElement {
73
+ #private;
74
+ static styles: any;
75
+ /** `short`, `medium` (default), `long`, `full`, `relative`, or a moment-style pattern. */
76
+ format: string;
77
+ /** Presets only. Overrides the date part; `none` omits it. */
78
+ dateStyle?: DateStyleOverride;
79
+ /** Presets only. Overrides the time part; `none` omits it. */
80
+ timeStyle?: DateStyleOverride;
81
+ /** Moment-style pattern used to parse string input. */
82
+ inputFormat: string;
83
+ /** The date to show as a string. Takes precedence over the text content. */
84
+ datetime: string;
85
+ /** BCP 47 locale. Defaults to the nearest `lang` attribute, then the browser. */
86
+ locale: string;
87
+ /** IANA time zone. Defaults to the local zone. */
88
+ timeZone: string;
89
+ /** Forces ticking even for a fixed date in an absolute format. */
90
+ live: boolean;
91
+ /** Custom tick period in ms. `0` derives it from the format. */
92
+ interval: number;
93
+ /** The date as a `Date`, epoch ms or string. Takes precedence over `datetime` and the text content. */
94
+ value?: DateInput;
95
+ /** Read-only. `true` when the input could not be parsed (the current time is shown instead). */
96
+ invalid: boolean;
97
+ /** Text content of the light DOM. */
98
+ private text;
99
+ /** The instant currently shown (the parsed input, or the current time). */
100
+ get date(): Date;
101
+ connectedCallback(): void;
102
+ disconnectedCallback(): void;
103
+ protected willUpdate(changed: PropertyValues<this>): void;
104
+ protected render(): unknown;
105
+ protected updated(): void;
106
+ }
107
+
108
+ /** A parsed `format` attribute. */
109
+ type FormatSpec = {
110
+ kind: "relative";
111
+ } | {
112
+ kind: "pattern";
113
+ pattern: string;
114
+ } | {
115
+ kind: "preset";
116
+ dateStyle?: DateStyle;
117
+ timeStyle?: DateStyle;
118
+ };
119
+ interface FormatOptions {
120
+ locale?: string;
121
+ timeZone?: string;
122
+ /** Reference time for relative formatting. */
123
+ now: number;
124
+ }
125
+ /**
126
+ * Interprets the `format`, `date-style` and `time-style` attributes.
127
+ *
128
+ * - `relative` → relative time ("3 minutes ago").
129
+ * - A preset name (`short`, `medium`, `long`, `full`) or empty → `Intl`
130
+ * `dateStyle` + `timeStyle`, each overridable (or omitted with `none`).
131
+ * - Anything else → a moment-style token pattern.
132
+ */
133
+ declare function resolveFormat(format: string, dateStyle?: DateStyleOverride, timeStyle?: DateStyleOverride): FormatSpec;
134
+ /** Renders `date` according to a resolved format. */
135
+ declare function formatDate(date: Date, spec: FormatSpec, { locale, timeZone, now }: FormatOptions): string;
136
+
137
+ /**
138
+ * Formats `date` with a moment-style pattern (see `tokens.ts`). Numbers are
139
+ * always Latin digits; month, weekday and day-period names come from `Intl`
140
+ * in the given locale.
141
+ */
142
+ declare function formatPattern(date: Date, pattern: string, locale?: string, timeZone?: string): string;
143
+
144
+ /**
145
+ * Formats `date` relative to `now` ("3 minutes ago", "in 2 days", "now").
146
+ * Picks the largest unit that fits and truncates toward zero, so "5 minutes
147
+ * ago" holds until the sixth minute has passed.
148
+ */
149
+ declare function formatRelative(date: Date, now: number, locale?: string): string;
150
+
151
+ interface ParseOptions {
152
+ /** Moment-style pattern. When set, it is the only format tried. */
153
+ inputFormat?: string;
154
+ locale?: string;
155
+ /** Zone for wall times without an explicit offset. Local when unset. */
156
+ timeZone?: string;
157
+ /** Reference time for defaults (missing year, time-only input). */
158
+ now: number;
159
+ }
160
+ /**
161
+ * Parses a date input. Returns `undefined` for empty or invalid input.
162
+ *
163
+ * - `Date` → used as is (if valid). `number` → epoch milliseconds.
164
+ * - Strings with `inputFormat` → that pattern only.
165
+ * - Other strings → ISO 8601 / epoch ms, then a numeric date in the locale's
166
+ * day/month/year order (`22/01/2024`, `22.01.2024 14:30`).
167
+ */
168
+ declare function parseDate(input: DateInput | null | undefined, options: ParseOptions): Date | undefined;
169
+
170
+ export { DateElement, formatDate, formatPattern, formatRelative, parseDate, resolveFormat };
171
+ export type { DateInput, DateInvalidEventDetail, DateStyle, DateStyleOverride, FormatOptions, FormatSpec, ParseOptions };
@@ -0,0 +1,171 @@
1
+ import { LitElement, PropertyValues } from 'lit';
2
+
3
+ /** `Intl.DateTimeFormat` style used by the preset formats (`short`, `medium`, `long`, `full`). */
4
+ type DateStyle = "short" | "medium" | "long" | "full";
5
+ /** Per-part override for presets: a style, or `none` to omit that part. */
6
+ type DateStyleOverride = DateStyle | "none";
7
+ /** Accepted by the `value` property. Strings are parsed like the text content. */
8
+ type DateInput = Date | number | string;
9
+ /** `detail` of the `tp-date-invalid` event. */
10
+ interface DateInvalidEventDetail {
11
+ /** The input that could not be parsed. */
12
+ input: string;
13
+ }
14
+
15
+ declare global {
16
+ interface HTMLElementTagNameMap {
17
+ /**
18
+ * A localized date/time. The date comes from the text content (or the
19
+ * `datetime` attribute / `value` property); empty or invalid input shows
20
+ * the current time, kept live.
21
+ *
22
+ * @example
23
+ * ```html
24
+ * <tp-date format="DD MMMM YYYY">2024-01-22</tp-date>
25
+ * <tp-date format="HH:mm:ss"></tp-date>
26
+ * <tp-date format="relative" datetime="2024-01-22T14:30:00Z"></tp-date>
27
+ * ```
28
+ */
29
+ "tp-date": DateElement;
30
+ }
31
+ interface HTMLElementEventMap {
32
+ "tp-date-invalid": CustomEvent<DateInvalidEventDetail>;
33
+ }
34
+ }
35
+ /**
36
+ * `<tp-date>` &mdash; a localized, optionally live date/time.
37
+ *
38
+ * - **Source** (first non-empty wins): the `value` property, the `datetime`
39
+ * attribute, the text content. Accepts ISO 8601, epoch milliseconds, or a
40
+ * numeric date in the locale's order (`22/01/2024` in `tr`); `input-format`
41
+ * pins a moment-style pattern instead.
42
+ * - **Fallback**: empty or invalid input renders the current time. Invalid
43
+ * input also sets the `invalid` attribute and fires `tp-date-invalid`.
44
+ * - **Format**: a preset (`short` / `medium` / `long` / `full`, via `Intl`),
45
+ * `relative`, or a moment-style pattern such as `DD/MM/YYYY HH:mm`.
46
+ * - **Live updates**: the current time and relative dates re-render on a
47
+ * shared, boundary-aligned clock at the cadence the format needs (each
48
+ * second for `ss`, each minute for `mm`, ...). Fixed dates in an absolute
49
+ * format never tick. Ticking pauses while the tab is hidden.
50
+ * - The text content stays in light DOM as the no-JS / pre-upgrade fallback;
51
+ * the rendered value is a `<time datetime>` in shadow DOM.
52
+ *
53
+ * @element tp-date
54
+ *
55
+ * @attr {string} [format=""] - `short`, `medium` (default), `long`, `full`, `relative`, or a moment-style pattern.
56
+ * @attr {"short" | "medium" | "long" | "full" | "none"} date-style - Presets only. Overrides the date part; `none` omits it.
57
+ * @attr {"short" | "medium" | "long" | "full" | "none"} time-style - Presets only. Overrides the time part; `none` omits it.
58
+ * @attr {string} [input-format=""] - Moment-style pattern used to parse the input, e.g. `DD/MM/YYYY`.
59
+ * @attr {string} [datetime=""] - The date to show. Takes precedence over the text content.
60
+ * @attr {string} [locale=""] - BCP 47 locale. Defaults to the nearest `lang` attribute, then the browser.
61
+ * @attr {string} [time-zone=""] - IANA time zone (`UTC`, `Europe/Istanbul`) for display and for parsing wall times. Defaults to local.
62
+ * @attr {boolean} [live=false] - Forces ticking even for a fixed date in an absolute format.
63
+ * @attr {number} [interval=0] - Custom tick period in ms. `0` derives it from the format.
64
+ * @attr {boolean} invalid - Read-only. Present when the input could not be parsed.
65
+ *
66
+ * @fires tp-date-invalid - When a non-empty input cannot be parsed. `detail: { input }`.
67
+ *
68
+ * @csspart time - The rendered `<time>` element.
69
+ *
70
+ * @cssprop --tp-date-numeric - `font-variant-numeric` of the output. Defaults to `tabular-nums`.
71
+ */
72
+ declare class DateElement extends LitElement {
73
+ #private;
74
+ static styles: any;
75
+ /** `short`, `medium` (default), `long`, `full`, `relative`, or a moment-style pattern. */
76
+ format: string;
77
+ /** Presets only. Overrides the date part; `none` omits it. */
78
+ dateStyle?: DateStyleOverride;
79
+ /** Presets only. Overrides the time part; `none` omits it. */
80
+ timeStyle?: DateStyleOverride;
81
+ /** Moment-style pattern used to parse string input. */
82
+ inputFormat: string;
83
+ /** The date to show as a string. Takes precedence over the text content. */
84
+ datetime: string;
85
+ /** BCP 47 locale. Defaults to the nearest `lang` attribute, then the browser. */
86
+ locale: string;
87
+ /** IANA time zone. Defaults to the local zone. */
88
+ timeZone: string;
89
+ /** Forces ticking even for a fixed date in an absolute format. */
90
+ live: boolean;
91
+ /** Custom tick period in ms. `0` derives it from the format. */
92
+ interval: number;
93
+ /** The date as a `Date`, epoch ms or string. Takes precedence over `datetime` and the text content. */
94
+ value?: DateInput;
95
+ /** Read-only. `true` when the input could not be parsed (the current time is shown instead). */
96
+ invalid: boolean;
97
+ /** Text content of the light DOM. */
98
+ private text;
99
+ /** The instant currently shown (the parsed input, or the current time). */
100
+ get date(): Date;
101
+ connectedCallback(): void;
102
+ disconnectedCallback(): void;
103
+ protected willUpdate(changed: PropertyValues<this>): void;
104
+ protected render(): unknown;
105
+ protected updated(): void;
106
+ }
107
+
108
+ /** A parsed `format` attribute. */
109
+ type FormatSpec = {
110
+ kind: "relative";
111
+ } | {
112
+ kind: "pattern";
113
+ pattern: string;
114
+ } | {
115
+ kind: "preset";
116
+ dateStyle?: DateStyle;
117
+ timeStyle?: DateStyle;
118
+ };
119
+ interface FormatOptions {
120
+ locale?: string;
121
+ timeZone?: string;
122
+ /** Reference time for relative formatting. */
123
+ now: number;
124
+ }
125
+ /**
126
+ * Interprets the `format`, `date-style` and `time-style` attributes.
127
+ *
128
+ * - `relative` → relative time ("3 minutes ago").
129
+ * - A preset name (`short`, `medium`, `long`, `full`) or empty → `Intl`
130
+ * `dateStyle` + `timeStyle`, each overridable (or omitted with `none`).
131
+ * - Anything else → a moment-style token pattern.
132
+ */
133
+ declare function resolveFormat(format: string, dateStyle?: DateStyleOverride, timeStyle?: DateStyleOverride): FormatSpec;
134
+ /** Renders `date` according to a resolved format. */
135
+ declare function formatDate(date: Date, spec: FormatSpec, { locale, timeZone, now }: FormatOptions): string;
136
+
137
+ /**
138
+ * Formats `date` with a moment-style pattern (see `tokens.ts`). Numbers are
139
+ * always Latin digits; month, weekday and day-period names come from `Intl`
140
+ * in the given locale.
141
+ */
142
+ declare function formatPattern(date: Date, pattern: string, locale?: string, timeZone?: string): string;
143
+
144
+ /**
145
+ * Formats `date` relative to `now` ("3 minutes ago", "in 2 days", "now").
146
+ * Picks the largest unit that fits and truncates toward zero, so "5 minutes
147
+ * ago" holds until the sixth minute has passed.
148
+ */
149
+ declare function formatRelative(date: Date, now: number, locale?: string): string;
150
+
151
+ interface ParseOptions {
152
+ /** Moment-style pattern. When set, it is the only format tried. */
153
+ inputFormat?: string;
154
+ locale?: string;
155
+ /** Zone for wall times without an explicit offset. Local when unset. */
156
+ timeZone?: string;
157
+ /** Reference time for defaults (missing year, time-only input). */
158
+ now: number;
159
+ }
160
+ /**
161
+ * Parses a date input. Returns `undefined` for empty or invalid input.
162
+ *
163
+ * - `Date` → used as is (if valid). `number` → epoch milliseconds.
164
+ * - Strings with `inputFormat` → that pattern only.
165
+ * - Other strings → ISO 8601 / epoch ms, then a numeric date in the locale's
166
+ * day/month/year order (`22/01/2024`, `22.01.2024 14:30`).
167
+ */
168
+ declare function parseDate(input: DateInput | null | undefined, options: ParseOptions): Date | undefined;
169
+
170
+ export { DateElement, formatDate, formatPattern, formatRelative, parseDate, resolveFormat };
171
+ export type { DateInput, DateInvalidEventDetail, DateStyle, DateStyleOverride, FormatOptions, FormatSpec, ParseOptions };
package/date/index.js ADDED
@@ -0,0 +1,6 @@
1
+ export { DateElement } from './date-element.js';
2
+ export { formatDate, resolveFormat } from './format.js';
3
+ export { formatPattern } from './format-pattern.js';
4
+ export { formatRelative } from './relative.js';
5
+ export { parseDate } from './parse.js';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
package/date/intl.cjs ADDED
@@ -0,0 +1,36 @@
1
+ 'use strict';
2
+
3
+ const dateTimeFormats = new Map();
4
+ const relativeTimeFormats = new Map();
5
+ /**
6
+ * Cached `Intl.DateTimeFormat`. Constructing formatters is the expensive part
7
+ * of `Intl`, and live dates re-format on every tick.
8
+ */
9
+ function dateTimeFormat(locale, options) {
10
+ const key = `${locale ?? ""}|${JSON.stringify(options)}`;
11
+ let format = dateTimeFormats.get(key);
12
+ if (!format) {
13
+ format = new Intl.DateTimeFormat(locale, options);
14
+ dateTimeFormats.set(key, format);
15
+ }
16
+ return format;
17
+ }
18
+ /** Cached `Intl.RelativeTimeFormat` with `numeric: "auto"` ("yesterday", "now"). */
19
+ function relativeTimeFormat(locale) {
20
+ const key = locale ?? "";
21
+ let format = relativeTimeFormats.get(key);
22
+ if (!format) {
23
+ format = new Intl.RelativeTimeFormat(locale, { numeric: "auto" });
24
+ relativeTimeFormats.set(key, format);
25
+ }
26
+ return format;
27
+ }
28
+ /** Returns the value of the first part of `type`, if any. */
29
+ function partValue(parts, type) {
30
+ return parts.find(part => part.type === type)?.value;
31
+ }
32
+
33
+ exports.dateTimeFormat = dateTimeFormat;
34
+ exports.partValue = partValue;
35
+ exports.relativeTimeFormat = relativeTimeFormat;
36
+ //# sourceMappingURL=intl.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intl.cjs","sources":["../../../../libs/elements/src/date/intl.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAAA,MAAM,eAAe,GAAG,IAAI,GAAG,EAA+B;AAC9D,MAAM,mBAAmB,GAAG,IAAI,GAAG,EAAmC;AAEtE;;;AAGG;AACG,SAAU,cAAc,CAAC,MAA0B,EAAE,OAAmC,EAAA;AAC5F,IAAA,MAAM,GAAG,GAAG,CAAA,EAAG,MAAM,IAAI,EAAE,CAAA,CAAA,EAAI,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE;IACxD,IAAI,MAAM,GAAG,eAAe,CAAC,GAAG,CAAC,GAAG,CAAC;IAErC,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,GAAG,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC;AACjD,QAAA,eAAe,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC;IAClC;AAEA,IAAA,OAAO,MAAM;AACf;AAEA;AACM,SAAU,kBAAkB,CAAC,MAA0B,EAAA;AAC3D,IAAA,MAAM,GAAG,GAAG,MAAM,IAAI,EAAE;IACxB,IAAI,MAAM,GAAG,mBAAmB,CAAC,GAAG,CAAC,GAAG,CAAC;IAEzC,IAAI,CAAC,MAAM,EAAE;AACX,QAAA,MAAM,GAAG,IAAI,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;AACjE,QAAA,mBAAmB,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC;IACtC;AAEA,IAAA,OAAO,MAAM;AACf;AAEA;AACM,SAAU,SAAS,CAAC,KAAgC,EAAE,IAAkC,EAAA;AAC5F,IAAA,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,EAAE,KAAK;AACtD;;;;;;"}
package/date/intl.js ADDED
@@ -0,0 +1,32 @@
1
+ const dateTimeFormats = new Map();
2
+ const relativeTimeFormats = new Map();
3
+ /**
4
+ * Cached `Intl.DateTimeFormat`. Constructing formatters is the expensive part
5
+ * of `Intl`, and live dates re-format on every tick.
6
+ */
7
+ function dateTimeFormat(locale, options) {
8
+ const key = `${locale ?? ""}|${JSON.stringify(options)}`;
9
+ let format = dateTimeFormats.get(key);
10
+ if (!format) {
11
+ format = new Intl.DateTimeFormat(locale, options);
12
+ dateTimeFormats.set(key, format);
13
+ }
14
+ return format;
15
+ }
16
+ /** Cached `Intl.RelativeTimeFormat` with `numeric: "auto"` ("yesterday", "now"). */
17
+ function relativeTimeFormat(locale) {
18
+ const key = locale ?? "";
19
+ let format = relativeTimeFormats.get(key);
20
+ if (!format) {
21
+ format = new Intl.RelativeTimeFormat(locale, { numeric: "auto" });
22
+ relativeTimeFormats.set(key, format);
23
+ }
24
+ return format;
25
+ }
26
+ /** Returns the value of the first part of `type`, if any. */
27
+ function partValue(parts, type) {
28
+ return parts.find(part => part.type === type)?.value;
29
+ }
30
+
31
+ export { dateTimeFormat, partValue, relativeTimeFormat };
32
+ //# sourceMappingURL=intl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intl.js","sources":["../../../../libs/elements/src/date/intl.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA,MAAM,eAAe,GAAG,IAAI,GAAG,EAA+B;AAC9D,MAAM,mBAAmB,GAAG,IAAI,GAAG,EAAmC;AAEtE;;;AAGG;AACG,SAAU,cAAc,CAAC,MAA0B,EAAE,OAAmC,EAAA;AAC5F,IAAA,MAAM,GAAG,GAAG,CAAA,EAAG,MAAM,IAAI,EAAE,CAAA,CAAA,EAAI,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE;IACxD,IAAI,MAAM,GAAG,eAAe,CAAC,GAAG,CAAC,GAAG,CAAC;IAErC,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,GAAG,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC;AACjD,QAAA,eAAe,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC;IAClC;AAEA,IAAA,OAAO,MAAM;AACf;AAEA;AACM,SAAU,kBAAkB,CAAC,MAA0B,EAAA;AAC3D,IAAA,MAAM,GAAG,GAAG,MAAM,IAAI,EAAE;IACxB,IAAI,MAAM,GAAG,mBAAmB,CAAC,GAAG,CAAC,GAAG,CAAC;IAEzC,IAAI,CAAC,MAAM,EAAE;AACX,QAAA,MAAM,GAAG,IAAI,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;AACjE,QAAA,mBAAmB,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC;IACtC;AAEA,IAAA,OAAO,MAAM;AACf;AAEA;AACM,SAAU,SAAS,CAAC,KAAgC,EAAE,IAAkC,EAAA;AAC5F,IAAA,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,EAAE,KAAK;AACtD;;;;"}
@@ -0,0 +1,36 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Resolves the locale for an element: its `locale` attribute, then the
5
+ * nearest `lang` attribute (crossing shadow roots), then the browser default
6
+ * (`undefined`). Invalid tags are skipped.
7
+ */
8
+ function resolveLocale(host, explicit) {
9
+ return canonical(explicit) ?? canonical(closestLang(host));
10
+ }
11
+ function closestLang(host) {
12
+ let node = host;
13
+ while (node) {
14
+ if (node instanceof Element) {
15
+ const lang = node.closest("[lang]")?.getAttribute("lang");
16
+ if (lang)
17
+ return lang;
18
+ }
19
+ const root = node.getRootNode();
20
+ node = root instanceof ShadowRoot ? root.host : null;
21
+ }
22
+ return "";
23
+ }
24
+ function canonical(tag) {
25
+ if (!tag?.trim())
26
+ return undefined;
27
+ try {
28
+ return Intl.getCanonicalLocales(tag.trim())[0];
29
+ }
30
+ catch {
31
+ return undefined;
32
+ }
33
+ }
34
+
35
+ exports.resolveLocale = resolveLocale;
36
+ //# sourceMappingURL=locale.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locale.cjs","sources":["../../../../libs/elements/src/date/locale.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAAA;;;;AAIG;AACG,SAAU,aAAa,CAAC,IAAa,EAAE,QAAgB,EAAA;AAC3D,IAAA,OAAO,SAAS,CAAC,QAAQ,CAAC,IAAI,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;AAC5D;AAEA,SAAS,WAAW,CAAC,IAAa,EAAA;IAChC,IAAI,IAAI,GAAgB,IAAI;IAE5B,OAAO,IAAI,EAAE;AACX,QAAA,IAAI,IAAI,YAAY,OAAO,EAAE;AAC3B,YAAA,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,YAAY,CAAC,MAAM,CAAC;AAEzD,YAAA,IAAI,IAAI;AAAE,gBAAA,OAAO,IAAI;QACvB;AAEA,QAAA,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE;AAC/B,QAAA,IAAI,GAAG,IAAI,YAAY,UAAU,GAAG,IAAI,CAAC,IAAI,GAAG,IAAI;IACtD;AAEA,IAAA,OAAO,EAAE;AACX;AAEA,SAAS,SAAS,CAAC,GAA8B,EAAA;AAC/C,IAAA,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE;AAAE,QAAA,OAAO,SAAS;AAElC,IAAA,IAAI;AACF,QAAA,OAAO,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAChD;AAAE,IAAA,MAAM;AACN,QAAA,OAAO,SAAS;IAClB;AACF;;;;"}
package/date/locale.js ADDED
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Resolves the locale for an element: its `locale` attribute, then the
3
+ * nearest `lang` attribute (crossing shadow roots), then the browser default
4
+ * (`undefined`). Invalid tags are skipped.
5
+ */
6
+ function resolveLocale(host, explicit) {
7
+ return canonical(explicit) ?? canonical(closestLang(host));
8
+ }
9
+ function closestLang(host) {
10
+ let node = host;
11
+ while (node) {
12
+ if (node instanceof Element) {
13
+ const lang = node.closest("[lang]")?.getAttribute("lang");
14
+ if (lang)
15
+ return lang;
16
+ }
17
+ const root = node.getRootNode();
18
+ node = root instanceof ShadowRoot ? root.host : null;
19
+ }
20
+ return "";
21
+ }
22
+ function canonical(tag) {
23
+ if (!tag?.trim())
24
+ return undefined;
25
+ try {
26
+ return Intl.getCanonicalLocales(tag.trim())[0];
27
+ }
28
+ catch {
29
+ return undefined;
30
+ }
31
+ }
32
+
33
+ export { resolveLocale };
34
+ //# sourceMappingURL=locale.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locale.js","sources":["../../../../libs/elements/src/date/locale.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA;;;;AAIG;AACG,SAAU,aAAa,CAAC,IAAa,EAAE,QAAgB,EAAA;AAC3D,IAAA,OAAO,SAAS,CAAC,QAAQ,CAAC,IAAI,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;AAC5D;AAEA,SAAS,WAAW,CAAC,IAAa,EAAA;IAChC,IAAI,IAAI,GAAgB,IAAI;IAE5B,OAAO,IAAI,EAAE;AACX,QAAA,IAAI,IAAI,YAAY,OAAO,EAAE;AAC3B,YAAA,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,YAAY,CAAC,MAAM,CAAC;AAEzD,YAAA,IAAI,IAAI;AAAE,gBAAA,OAAO,IAAI;QACvB;AAEA,QAAA,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE;AAC/B,QAAA,IAAI,GAAG,IAAI,YAAY,UAAU,GAAG,IAAI,CAAC,IAAI,GAAG,IAAI;IACtD;AAEA,IAAA,OAAO,EAAE;AACX;AAEA,SAAS,SAAS,CAAC,GAA8B,EAAA;AAC/C,IAAA,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE;AAAE,QAAA,OAAO,SAAS;AAElC,IAAA,IAAI;AACF,QAAA,OAAO,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAChD;AAAE,IAAA,MAAM;AACN,QAAA,OAAO,SAAS;IAClB;AACF;;;;"}
package/date/names.cjs ADDED
@@ -0,0 +1,41 @@
1
+ 'use strict';
2
+
3
+ var intl = require('./intl.cjs');
4
+
5
+ const cache = new Map();
6
+ function cached(key, build) {
7
+ let names = cache.get(key);
8
+ if (!names) {
9
+ names = build();
10
+ cache.set(key, names);
11
+ }
12
+ return names;
13
+ }
14
+ /** Localized month names, January first. Uses the "format" form (as in "22 January"). */
15
+ function monthNames(locale, width) {
16
+ return cached(`month|${locale}|${width}`, () => {
17
+ const format = intl.dateTimeFormat(locale, { timeZone: "UTC", day: "numeric", month: width });
18
+ return Array.from({ length: 12 }, (_, month) => intl.partValue(format.formatToParts(Date.UTC(2000, month, 15)), "month") ?? "");
19
+ });
20
+ }
21
+ /** Localized weekday names, Sunday first. */
22
+ function weekdayNames(locale, width) {
23
+ return cached(`weekday|${locale}|${width}`, () => {
24
+ const format = intl.dateTimeFormat(locale, { timeZone: "UTC", weekday: width });
25
+ // 2000-01-02 was a Sunday.
26
+ return Array.from({ length: 7 }, (_, day) => format.format(Date.UTC(2000, 0, 2 + day)));
27
+ });
28
+ }
29
+ /** Localized day periods as `[am, pm]`. Falls back to `AM` / `PM`. */
30
+ function dayPeriods(locale) {
31
+ return cached(`period|${locale}`, () => {
32
+ const format = intl.dateTimeFormat(locale, { timeZone: "UTC", hour: "numeric", hourCycle: "h12" });
33
+ const read = (hour, fallback) => intl.partValue(format.formatToParts(Date.UTC(2000, 0, 1, hour)), "dayPeriod") ?? fallback;
34
+ return [read(9, "AM"), read(21, "PM")];
35
+ });
36
+ }
37
+
38
+ exports.dayPeriods = dayPeriods;
39
+ exports.monthNames = monthNames;
40
+ exports.weekdayNames = weekdayNames;
41
+ //# sourceMappingURL=names.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"names.cjs","sources":["../../../../libs/elements/src/date/names.ts"],"sourcesContent":[null],"names":["dateTimeFormat","partValue"],"mappings":";;;;AAIA,MAAM,KAAK,GAAG,IAAI,GAAG,EAAoB;AAEzC,SAAS,MAAM,CAAC,GAAW,EAAE,KAAqB,EAAA;IAChD,IAAI,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC;IAE1B,IAAI,CAAC,KAAK,EAAE;QACV,KAAK,GAAG,KAAK,EAAE;AACf,QAAA,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC;IACvB;AAEA,IAAA,OAAO,KAAK;AACd;AAEA;AACM,SAAU,UAAU,CAAC,MAA0B,EAAE,KAAgB,EAAA;IACrE,OAAO,MAAM,CAAC,CAAA,MAAA,EAAS,MAAM,IAAI,KAAK,CAAA,CAAE,EAAE,MAAK;QAC7C,MAAM,MAAM,G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