@telperion/elements 7.1.0 → 8.1.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 (116) hide show
  1. package/.build-manifest.json +12 -1
  2. package/README.md +64 -0
  3. package/custom-elements.json +1870 -129
  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/drag-drop/drag-drop-event.cjs +53 -0
  79. package/drag-drop/drag-drop-event.cjs.map +1 -0
  80. package/drag-drop/drag-drop-event.js +51 -0
  81. package/drag-drop/drag-drop-event.js.map +1 -0
  82. package/drag-drop/drag-element.cjs +44 -43
  83. package/drag-drop/drag-element.cjs.map +1 -1
  84. package/drag-drop/drag-element.js +44 -43
  85. package/drag-drop/drag-element.js.map +1 -1
  86. package/drag-drop/drag-handle-element.cjs +1 -1
  87. package/drag-drop/drag-handle-element.cjs.map +1 -1
  88. package/drag-drop/drag-handle-element.js +1 -1
  89. package/drag-drop/drag-handle-element.js.map +1 -1
  90. package/drag-drop/dropzone-element.cjs +21 -17
  91. package/drag-drop/dropzone-element.cjs.map +1 -1
  92. package/drag-drop/dropzone-element.js +21 -17
  93. package/drag-drop/dropzone-element.js.map +1 -1
  94. package/drag-drop/index.cjs +2 -2
  95. package/drag-drop/index.d.cts +136 -33
  96. package/drag-drop/index.d.ts +136 -33
  97. package/drag-drop/index.js +1 -1
  98. package/fesm/elements.mjs +1138 -65
  99. package/fesm/elements.mjs.map +1 -1
  100. package/iife/date/index.js +53 -0
  101. package/iife/date/index.js.map +1 -0
  102. package/iife/drag-drop/index.js +20 -20
  103. package/iife/drag-drop/index.js.map +1 -1
  104. package/iife/elements.js +62 -44
  105. package/iife/elements.js.map +1 -1
  106. package/index.cjs +13 -2
  107. package/index.cjs.map +1 -1
  108. package/index.d.cts +2 -1
  109. package/index.d.ts +2 -1
  110. package/index.js +6 -1
  111. package/index.js.map +1 -1
  112. package/package.json +31 -3
  113. package/drag-drop/tha-drag-event.cjs +0 -36
  114. package/drag-drop/tha-drag-event.cjs.map +0 -1
  115. package/drag-drop/tha-drag-event.js +0 -34
  116. package/drag-drop/tha-drag-event.js.map +0 -1
@@ -0,0 +1,231 @@
1
+ 'use strict';
2
+
3
+ var tslib = require('tslib');
4
+ var lit = require('lit');
5
+ var decorators_js = require('lit/decorators.js');
6
+ var format = require('./format.cjs');
7
+ var locale = require('./locale.cjs');
8
+ var parse = require('./parse.cjs');
9
+ var resolution = require('./resolution.cjs');
10
+ var styles = require('./styles.cjs');
11
+ var ticker = require('./ticker.cjs');
12
+ var zone = require('./zone.cjs');
13
+
14
+ /** Lower bound for a custom `interval`, roughly one frame. */
15
+ const MIN_INTERVAL = 16;
16
+ /** Inputs that change which instant is shown. */
17
+ const SOURCE_KEYS = ["value", "datetime", "text", "inputFormat", "locale", "timeZone"];
18
+ /**
19
+ * `<tp-date>` &mdash; a localized, optionally live date/time.
20
+ *
21
+ * - **Source** (first non-empty wins): the `value` property, the `datetime`
22
+ * attribute, the text content. Accepts ISO 8601, epoch milliseconds, or a
23
+ * numeric date in the locale's order (`22/01/2024` in `tr`); `input-format`
24
+ * pins a moment-style pattern instead.
25
+ * - **Fallback**: empty or invalid input renders the current time. Invalid
26
+ * input also sets the `invalid` attribute and fires `tp-date-invalid`.
27
+ * - **Format**: a preset (`short` / `medium` / `long` / `full`, via `Intl`),
28
+ * `relative`, or a moment-style pattern such as `DD/MM/YYYY HH:mm`.
29
+ * - **Live updates**: the current time and relative dates re-render on a
30
+ * shared, boundary-aligned clock at the cadence the format needs (each
31
+ * second for `ss`, each minute for `mm`, ...). Fixed dates in an absolute
32
+ * format never tick. Ticking pauses while the tab is hidden.
33
+ * - The text content stays in light DOM as the no-JS / pre-upgrade fallback;
34
+ * the rendered value is a `<time datetime>` in shadow DOM.
35
+ *
36
+ * @element tp-date
37
+ *
38
+ * @attr {string} [format=""] - `short`, `medium` (default), `long`, `full`, `relative`, or a moment-style pattern.
39
+ * @attr {"short" | "medium" | "long" | "full" | "none"} date-style - Presets only. Overrides the date part; `none` omits it.
40
+ * @attr {"short" | "medium" | "long" | "full" | "none"} time-style - Presets only. Overrides the time part; `none` omits it.
41
+ * @attr {string} [input-format=""] - Moment-style pattern used to parse the input, e.g. `DD/MM/YYYY`.
42
+ * @attr {string} [datetime=""] - The date to show. Takes precedence over the text content.
43
+ * @attr {string} [locale=""] - BCP 47 locale. Defaults to the nearest `lang` attribute, then the browser.
44
+ * @attr {string} [time-zone=""] - IANA time zone (`UTC`, `Europe/Istanbul`) for display and for parsing wall times. Defaults to local.
45
+ * @attr {boolean} [live=false] - Forces ticking even for a fixed date in an absolute format.
46
+ * @attr {number} [interval=0] - Custom tick period in ms. `0` derives it from the format.
47
+ * @attr {boolean} invalid - Read-only. Present when the input could not be parsed.
48
+ *
49
+ * @fires tp-date-invalid - When a non-empty input cannot be parsed. `detail: { input }`.
50
+ *
51
+ * @csspart time - The rendered `<time>` element.
52
+ *
53
+ * @cssprop --tp-date-numeric - `font-variant-numeric` of the output. Defaults to `tabular-nums`.
54
+ */
55
+ class DateElement extends lit.LitElement {
56
+ constructor() {
57
+ super(...arguments);
58
+ /** `short`, `medium` (default), `long`, `full`, `relative`, or a moment-style pattern. */
59
+ this.format = "";
60
+ /** Moment-style pattern used to parse string input. */
61
+ this.inputFormat = "";
62
+ /** The date to show as a string. Takes precedence over the text content. */
63
+ this.datetime = "";
64
+ /** BCP 47 locale. Defaults to the nearest `lang` attribute, then the browser. */
65
+ this.locale = "";
66
+ /** IANA time zone. Defaults to the local zone. */
67
+ this.timeZone = "";
68
+ /** Forces ticking even for a fixed date in an absolute format. */
69
+ this.live = false;
70
+ /** Custom tick period in ms. `0` derives it from the format. */
71
+ this.interval = 0;
72
+ /** Read-only. `true` when the input could not be parsed (the current time is shown instead). */
73
+ this.invalid = false;
74
+ /** Text content of the light DOM. */
75
+ this.text = "";
76
+ this.#now = Date.now();
77
+ this.#period = 0;
78
+ }
79
+ static { this.styles = styles.dateStyles; }
80
+ #fixed;
81
+ #now;
82
+ #observer;
83
+ #unsubscribe;
84
+ #period;
85
+ #invalidInput;
86
+ #lastInvalid;
87
+ /** The instant currently shown (the parsed input, or the current time). */
88
+ get date() {
89
+ return new Date(this.#fixed?.getTime() ?? this.#now);
90
+ }
91
+ connectedCallback() {
92
+ super.connectedCallback();
93
+ this.#observer ??= new MutationObserver(() => this.#syncText());
94
+ this.#observer.observe(this, { childList: true, characterData: true, subtree: true });
95
+ this.#syncText();
96
+ // Re-subscribe to the ticker after a reconnect.
97
+ this.requestUpdate();
98
+ }
99
+ disconnectedCallback() {
100
+ super.disconnectedCallback();
101
+ this.#observer?.disconnect();
102
+ this.#setPeriod(0);
103
+ }
104
+ willUpdate(changed) {
105
+ this.#now = Date.now();
106
+ if (SOURCE_KEYS.some(key => changed.has(key)))
107
+ this.#parse();
108
+ }
109
+ render() {
110
+ const spec = this.#spec();
111
+ const date = this.date;
112
+ const locale = this.#locale();
113
+ const timeZone = this.#timeZone();
114
+ return lit.html `<time
115
+ part="time"
116
+ datetime=${date.toISOString()}
117
+ title=${spec.kind === "relative" ? format.formatFull(date, locale, timeZone) : lit.nothing}
118
+ >${format.formatDate(date, spec, { locale, timeZone, now: this.#now })}</time
119
+ >`;
120
+ }
121
+ updated() {
122
+ this.#schedule();
123
+ if (this.#invalidInput !== undefined) {
124
+ const input = this.#invalidInput;
125
+ this.#invalidInput = undefined;
126
+ this.dispatchEvent(new CustomEvent("tp-date-invalid", { bubbles: true, composed: true, detail: { input } }));
127
+ }
128
+ }
129
+ #parse() {
130
+ const input = this.value ?? (this.datetime.trim() || this.text);
131
+ const fixed = parse.parseDate(input, {
132
+ inputFormat: this.inputFormat,
133
+ locale: this.#locale(),
134
+ timeZone: this.#timeZone(),
135
+ now: this.#now,
136
+ });
137
+ const empty = input === null || input === undefined || (typeof input === "string" && !input.trim());
138
+ const invalid = !fixed && !empty;
139
+ const key = String(input);
140
+ // Fire once per distinct invalid input, not on every re-parse.
141
+ if (invalid && key !== this.#lastInvalid)
142
+ this.#invalidInput = key;
143
+ this.#lastInvalid = invalid ? key : undefined;
144
+ this.#fixed = fixed;
145
+ this.invalid = invalid;
146
+ }
147
+ #spec() {
148
+ return format.resolveFormat(this.format, this.dateStyle, this.timeStyle);
149
+ }
150
+ #locale() {
151
+ return locale.resolveLocale(this, this.locale);
152
+ }
153
+ #timeZone() {
154
+ const zone$1 = this.timeZone.trim();
155
+ return zone$1 && zone.isValidTimeZone(zone$1) ? zone$1 : undefined;
156
+ }
157
+ /** Subscribes to the shared ticker at the cadence the current format needs, or not at all. */
158
+ #schedule() {
159
+ const spec = this.#spec();
160
+ const live = this.live || !this.#fixed || spec.kind === "relative";
161
+ if (!this.isConnected || !live)
162
+ return this.#setPeriod(0);
163
+ const interval = Number(this.interval);
164
+ this.#setPeriod(interval > 0 ? Math.max(interval, MIN_INTERVAL) : resolution.tickPeriod(spec, this.date, this.#now));
165
+ }
166
+ #setPeriod(period) {
167
+ if (period === this.#period)
168
+ return;
169
+ this.#unsubscribe?.();
170
+ this.#unsubscribe = undefined;
171
+ this.#period = period;
172
+ if (period)
173
+ this.#unsubscribe = ticker.subscribe(period, () => this.requestUpdate());
174
+ }
175
+ #syncText() {
176
+ this.text = (this.textContent ?? "").trim();
177
+ }
178
+ }
179
+ tslib.__decorate([
180
+ decorators_js.property(),
181
+ tslib.__metadata("design:type", Object)
182
+ ], DateElement.prototype, "format", void 0);
183
+ tslib.__decorate([
184
+ decorators_js.property({ attribute: "date-style" }),
185
+ tslib.__metadata("design:type", String)
186
+ ], DateElement.prototype, "dateStyle", void 0);
187
+ tslib.__decorate([
188
+ decorators_js.property({ attribute: "time-style" }),
189
+ tslib.__metadata("design:type", String)
190
+ ], DateElement.prototype, "timeStyle", void 0);
191
+ tslib.__decorate([
192
+ decorators_js.property({ attribute: "input-format" }),
193
+ tslib.__metadata("design:type", Object)
194
+ ], DateElement.prototype, "inputFormat", void 0);
195
+ tslib.__decorate([
196
+ decorators_js.property(),
197
+ tslib.__metadata("design:type", Object)
198
+ ], DateElement.prototype, "datetime", void 0);
199
+ tslib.__decorate([
200
+ decorators_js.property(),
201
+ tslib.__metadata("design:type", Object)
202
+ ], DateElement.prototype, "locale", void 0);
203
+ tslib.__decorate([
204
+ decorators_js.property({ attribute: "time-zone" }),
205
+ tslib.__metadata("design:type", Object)
206
+ ], DateElement.prototype, "timeZone", void 0);
207
+ tslib.__decorate([
208
+ decorators_js.property({ type: Boolean, reflect: true }),
209
+ tslib.__metadata("design:type", Object)
210
+ ], DateElement.prototype, "live", void 0);
211
+ tslib.__decorate([
212
+ decorators_js.property({ type: Number }),
213
+ tslib.__metadata("design:type", Object)
214
+ ], DateElement.prototype, "interval", void 0);
215
+ tslib.__decorate([
216
+ decorators_js.property({ attribute: false }),
217
+ tslib.__metadata("design:type", Object)
218
+ ], DateElement.prototype, "value", void 0);
219
+ tslib.__decorate([
220
+ decorators_js.property({ type: Boolean, reflect: true }),
221
+ tslib.__metadata("design:type", Object)
222
+ ], DateElement.prototype, "invalid", void 0);
223
+ tslib.__decorate([
224
+ decorators_js.state(),
225
+ tslib.__metadata("design:type", Object)
226
+ ], DateElement.prototype, "text", void 0);
227
+ if (!customElements.get("tp-date"))
228
+ customElements.define("tp-date", DateElement);
229
+
230
+ exports.DateElement = DateElement;
231
+ //# sourceMappingURL=date-element.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"date-element.cjs","sources":["../../../../libs/elements/src/date/date-element.ts"],"sourcesContent":[null],"names":["LitElement","dateStyles","html","formatFull","nothing","formatDate","parseDate","resolveFormat","resolveLocale","zone","isValidTimeZone","tickPeriod","subscribe","__decorate","property","state"],"mappings":";;;;;;;;;;;;;AAYA;AACA,MAAM,YAAY,GAAG,EAAE;AACvB;AACA,MAAM,WAAW,GAAG,CAAC,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,UAAU,CAAU;AAwB/F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCG;AACG,MAAO,WAAY,SAAQA,cAAU,CAAA;AAA3C,IAAA,WAAA,GAAA;;;QAKE,IAAA,CAAA,MAAM,GAAG,EAAE;;QAYX,IAAA,CAAA,WAAW,GAAG,EAAE;;QAIhB,IAAA,CAAA,QAAQ,GAAG,EAAE;;QAIb,IAAA,CAAA,MAAM,GAAG,EAAE;;QAIX,IAAA,CAAA,QAAQ,GAAG,EAAE;;QAIb,IAAA,CAAA,IAAI,GAAG,KAAK;;QAIZ,IAAA,CAAA,QAAQ,GAAG,CAAC;;QAQZ,IAAA,CAAA,OAAO,GAAG,KAAK;;QAIP,IAAA,CAAA,IAAI,GAAG,EAAE;AAGjB,QAAA,IAAA,CAAA,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE;QAGjB,IAAA,CAAA,OAAO,GAAG,CAAC;IAsHb;aA5KkB,IAAA,CAAA,MAAM,GAAGC,iBAAH,CAAc;AAkDpC,IAAA,MAAM;AACN,IAAA,IAAI;AACJ,IAAA,SAAS;AACT,IAAA,YAAY;AACZ,IAAA,OAAO;AACP,IAAA,aAAa;AACb,IAAA,YAAY;;AAGZ,IAAA,IAAI,IAAI,GAAA;AACN,QAAA,OAAO,IAAI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,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC;;AACvB,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,UAAA,EAAA,MAAA,CAAA;AAIdD,gBAAA,CAAA;IADCC,sBAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;AAC9B,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,MAAA,EAAA,MAAA,CAAA;AAIbD,gBAAA,CAAA;AADC,IAAAC,sBAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;AACd,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,UAAA,EAAA,MAAA,CAAA;AAIbD,gBAAA,CAAA;AADC,IAAAC,sBAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;;AACb,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,OAAA,EAAA,MAAA,CAAA;AAIlBD,gBAAA,CAAA;IADCC,sBAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;AAC3B,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,SAAA,EAAA,MAAA,CAAA;AAIRD,gBAAA,CAAA;AADP,IAAAE,mBAAK,EAAE;;AACU,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,MAAA,EAAA,MAAA,CAAA;AA8HpB,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC;AAAE,IAAA,cAAc,CAAC,MAAM,CAAC,SAAS,EAAE,WAAW,CAAC;;;;"}
@@ -0,0 +1,229 @@
1
+ import { __decorate, __metadata } from 'tslib';
2
+ import { LitElement, nothing, html } from 'lit';
3
+ import { property, state } from 'lit/decorators.js';
4
+ import { formatFull, formatDate, resolveFormat } from './format.js';
5
+ import { resolveLocale } from './locale.js';
6
+ import { parseDate } from './parse.js';
7
+ import { tickPeriod } from './resolution.js';
8
+ import { dateStyles } from './styles.js';
9
+ import { subscribe } from './ticker.js';
10
+ import { isValidTimeZone } from './zone.js';
11
+
12
+ /** Lower bound for a custom `interval`, roughly one frame. */
13
+ const MIN_INTERVAL = 16;
14
+ /** Inputs that change which instant is shown. */
15
+ const SOURCE_KEYS = ["value", "datetime", "text", "inputFormat", "locale", "timeZone"];
16
+ /**
17
+ * `<tp-date>` &mdash; a localized, optionally live date/time.
18
+ *
19
+ * - **Source** (first non-empty wins): the `value` property, the `datetime`
20
+ * attribute, the text content. Accepts ISO 8601, epoch milliseconds, or a
21
+ * numeric date in the locale's order (`22/01/2024` in `tr`); `input-format`
22
+ * pins a moment-style pattern instead.
23
+ * - **Fallback**: empty or invalid input renders the current time. Invalid
24
+ * input also sets the `invalid` attribute and fires `tp-date-invalid`.
25
+ * - **Format**: a preset (`short` / `medium` / `long` / `full`, via `Intl`),
26
+ * `relative`, or a moment-style pattern such as `DD/MM/YYYY HH:mm`.
27
+ * - **Live updates**: the current time and relative dates re-render on a
28
+ * shared, boundary-aligned clock at the cadence the format needs (each
29
+ * second for `ss`, each minute for `mm`, ...). Fixed dates in an absolute
30
+ * format never tick. Ticking pauses while the tab is hidden.
31
+ * - The text content stays in light DOM as the no-JS / pre-upgrade fallback;
32
+ * the rendered value is a `<time datetime>` in shadow DOM.
33
+ *
34
+ * @element tp-date
35
+ *
36
+ * @attr {string} [format=""] - `short`, `medium` (default), `long`, `full`, `relative`, or a moment-style pattern.
37
+ * @attr {"short" | "medium" | "long" | "full" | "none"} date-style - Presets only. Overrides the date part; `none` omits it.
38
+ * @attr {"short" | "medium" | "long" | "full" | "none"} time-style - Presets only. Overrides the time part; `none` omits it.
39
+ * @attr {string} [input-format=""] - Moment-style pattern used to parse the input, e.g. `DD/MM/YYYY`.
40
+ * @attr {string} [datetime=""] - The date to show. Takes precedence over the text content.
41
+ * @attr {string} [locale=""] - BCP 47 locale. Defaults to the nearest `lang` attribute, then the browser.
42
+ * @attr {string} [time-zone=""] - IANA time zone (`UTC`, `Europe/Istanbul`) for display and for parsing wall times. Defaults to local.
43
+ * @attr {boolean} [live=false] - Forces ticking even for a fixed date in an absolute format.
44
+ * @attr {number} [interval=0] - Custom tick period in ms. `0` derives it from the format.
45
+ * @attr {boolean} invalid - Read-only. Present when the input could not be parsed.
46
+ *
47
+ * @fires tp-date-invalid - When a non-empty input cannot be parsed. `detail: { input }`.
48
+ *
49
+ * @csspart time - The rendered `<time>` element.
50
+ *
51
+ * @cssprop --tp-date-numeric - `font-variant-numeric` of the output. Defaults to `tabular-nums`.
52
+ */
53
+ class DateElement extends LitElement {
54
+ constructor() {
55
+ super(...arguments);
56
+ /** `short`, `medium` (default), `long`, `full`, `relative`, or a moment-style pattern. */
57
+ this.format = "";
58
+ /** Moment-style pattern used to parse string input. */
59
+ this.inputFormat = "";
60
+ /** The date to show as a string. Takes precedence over the text content. */
61
+ this.datetime = "";
62
+ /** BCP 47 locale. Defaults to the nearest `lang` attribute, then the browser. */
63
+ this.locale = "";
64
+ /** IANA time zone. Defaults to the local zone. */
65
+ this.timeZone = "";
66
+ /** Forces ticking even for a fixed date in an absolute format. */
67
+ this.live = false;
68
+ /** Custom tick period in ms. `0` derives it from the format. */
69
+ this.interval = 0;
70
+ /** Read-only. `true` when the input could not be parsed (the current time is shown instead). */
71
+ this.invalid = false;
72
+ /** Text content of the light DOM. */
73
+ this.text = "";
74
+ this.#now = Date.now();
75
+ this.#period = 0;
76
+ }
77
+ static { this.styles = dateStyles; }
78
+ #fixed;
79
+ #now;
80
+ #observer;
81
+ #unsubscribe;
82
+ #period;
83
+ #invalidInput;
84
+ #lastInvalid;
85
+ /** The instant currently shown (the parsed input, or the current time). */
86
+ get date() {
87
+ return new Date(this.#fixed?.getTime() ?? this.#now);
88
+ }
89
+ connectedCallback() {
90
+ super.connectedCallback();
91
+ this.#observer ??= new MutationObserver(() => this.#syncText());
92
+ this.#observer.observe(this, { childList: true, characterData: true, subtree: true });
93
+ this.#syncText();
94
+ // Re-subscribe to the ticker after a reconnect.
95
+ this.requestUpdate();
96
+ }
97
+ disconnectedCallback() {
98
+ super.disconnectedCallback();
99
+ this.#observer?.disconnect();
100
+ this.#setPeriod(0);
101
+ }
102
+ willUpdate(changed) {
103
+ this.#now = Date.now();
104
+ if (SOURCE_KEYS.some(key => changed.has(key)))
105
+ this.#parse();
106
+ }
107
+ render() {
108
+ const spec = this.#spec();
109
+ const date = this.date;
110
+ const locale = this.#locale();
111
+ const timeZone = this.#timeZone();
112
+ return html `<time
113
+ part="time"
114
+ datetime=${date.toISOString()}
115
+ title=${spec.kind === "relative" ? formatFull(date, locale, timeZone) : nothing}
116
+ >${formatDate(date, spec, { locale, timeZone, now: this.#now })}</time
117
+ >`;
118
+ }
119
+ updated() {
120
+ this.#schedule();
121
+ if (this.#invalidInput !== undefined) {
122
+ const input = this.#invalidInput;
123
+ this.#invalidInput = undefined;
124
+ this.dispatchEvent(new CustomEvent("tp-date-invalid", { bubbles: true, composed: true, detail: { input } }));
125
+ }
126
+ }
127
+ #parse() {
128
+ const input = this.value ?? (this.datetime.trim() || this.text);
129
+ const fixed = parseDate(input, {
130
+ inputFormat: this.inputFormat,
131
+ locale: this.#locale(),
132
+ timeZone: this.#timeZone(),
133
+ now: this.#now,
134
+ });
135
+ const empty = input === null || input === undefined || (typeof input === "string" && !input.trim());
136
+ const invalid = !fixed && !empty;
137
+ const key = String(input);
138
+ // Fire once per distinct invalid input, not on every re-parse.
139
+ if (invalid && key !== this.#lastInvalid)
140
+ this.#invalidInput = key;
141
+ this.#lastInvalid = invalid ? key : undefined;
142
+ this.#fixed = fixed;
143
+ this.invalid = invalid;
144
+ }
145
+ #spec() {
146
+ return resolveFormat(this.format, this.dateStyle, this.timeStyle);
147
+ }
148
+ #locale() {
149
+ return resolveLocale(this, this.locale);
150
+ }
151
+ #timeZone() {
152
+ const zone = this.timeZone.trim();
153
+ return zone && isValidTimeZone(zone) ? zone : undefined;
154
+ }
155
+ /** Subscribes to the shared ticker at the cadence the current format needs, or not at all. */
156
+ #schedule() {
157
+ const spec = this.#spec();
158
+ const live = this.live || !this.#fixed || spec.kind === "relative";
159
+ if (!this.isConnected || !live)
160
+ return this.#setPeriod(0);
161
+ const interval = Number(this.interval);
162
+ this.#setPeriod(interval > 0 ? Math.max(interval, MIN_INTERVAL) : tickPeriod(spec, this.date, this.#now));
163
+ }
164
+ #setPeriod(period) {
165
+ if (period === this.#period)
166
+ return;
167
+ this.#unsubscribe?.();
168
+ this.#unsubscribe = undefined;
169
+ this.#period = period;
170
+ if (period)
171
+ this.#unsubscribe = subscribe(period, () => this.requestUpdate());
172
+ }
173
+ #syncText() {
174
+ this.text = (this.textContent ?? "").trim();
175
+ }
176
+ }
177
+ __decorate([
178
+ property(),
179
+ __metadata("design:type", Object)
180
+ ], DateElement.prototype, "format", void 0);
181
+ __decorate([
182
+ property({ attribute: "date-style" }),
183
+ __metadata("design:type", String)
184
+ ], DateElement.prototype, "dateStyle", void 0);
185
+ __decorate([
186
+ property({ attribute: "time-style" }),
187
+ __metadata("design:type", String)
188
+ ], DateElement.prototype, "timeStyle", void 0);
189
+ __decorate([
190
+ property({ attribute: "input-format" }),
191
+ __metadata("design:type", Object)
192
+ ], DateElement.prototype, "inputFormat", void 0);
193
+ __decorate([
194
+ property(),
195
+ __metadata("design:type", Object)
196
+ ], DateElement.prototype, "datetime", void 0);
197
+ __decorate([
198
+ property(),
199
+ __metadata("design:type", Object)
200
+ ], DateElement.prototype, "locale", void 0);
201
+ __decorate([
202
+ property({ attribute: "time-zone" }),
203
+ __metadata("design:type", Object)
204
+ ], DateElement.prototype, "timeZone", void 0);
205
+ __decorate([
206
+ property({ type: Boolean, reflect: true }),
207
+ __metadata("design:type", Object)
208
+ ], DateElement.prototype, "live", void 0);
209
+ __decorate([
210
+ property({ type: Number }),
211
+ __metadata("design:type", Object)
212
+ ], DateElement.prototype, "interval", void 0);
213
+ __decorate([
214
+ property({ attribute: false }),
215
+ __metadata("design:type", Object)
216
+ ], DateElement.prototype, "value", void 0);
217
+ __decorate([
218
+ property({ type: Boolean, reflect: true }),
219
+ __metadata("design:type", Object)
220
+ ], DateElement.prototype, "invalid", void 0);
221
+ __decorate([
222
+ state(),
223
+ __metadata("design:type", Object)
224
+ ], DateElement.prototype, "text", void 0);
225
+ if (!customElements.get("tp-date"))
226
+ customElements.define("tp-date", DateElement);
227
+
228
+ export { DateElement };
229
+ //# sourceMappingURL=date-element.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"date-element.js","sources":["../../../../libs/elements/src/date/date-element.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;;;AAYA;AACA,MAAM,YAAY,GAAG,EAAE;AACvB;AACA,MAAM,WAAW,GAAG,CAAC,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,UAAU,CAAU;AAwB/F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCG;AACG,MAAO,WAAY,SAAQ,UAAU,CAAA;AAA3C,IAAA,WAAA,GAAA;;;QAKE,IAAA,CAAA,MAAM,GAAG,EAAE;;QAYX,IAAA,CAAA,WAAW,GAAG,EAAE;;QAIhB,IAAA,CAAA,QAAQ,GAAG,EAAE;;QAIb,IAAA,CAAA,MAAM,GAAG,EAAE;;QAIX,IAAA,CAAA,QAAQ,GAAG,EAAE;;QAIb,IAAA,CAAA,IAAI,GAAG,KAAK;;QAIZ,IAAA,CAAA,QAAQ,GAAG,CAAC;;QAQZ,IAAA,CAAA,OAAO,GAAG,KAAK;;QAIP,IAAA,CAAA,IAAI,GAAG,EAAE;AAGjB,QAAA,IAAA,CAAA,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE;QAGjB,IAAA,CAAA,OAAO,GAAG,CAAC;IAsHb;aA5KkB,IAAA,CAAA,MAAM,GAAG,UAAH,CAAc;AAkDpC,IAAA,MAAM;AACN,IAAA,IAAI;AACJ,IAAA,SAAS;AACT,IAAA,YAAY;AACZ,IAAA,OAAO;AACP,IAAA,aAAa;AACb,IAAA,YAAY;;AAGZ,IAAA,IA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WAAW,EAAE,CAAC;;AACvB,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,UAAA,EAAA,MAAA,CAAA;AAId,UAAA,CAAA;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;AAC9B,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,MAAA,EAAA,MAAA,CAAA;AAIb,UAAA,CAAA;AADC,IAAA,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;AACd,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,UAAA,EAAA,MAAA,CAAA;AAIb,UAAA,CAAA;AADC,IAAA,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;;AACb,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,OAAA,EAAA,MAAA,CAAA;AAIlB,UAAA,CAAA;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;AAC3B,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,SAAA,EAAA,MAAA,CAAA;AAIR,UAAA,CAAA;AADP,IAAA,KAAK,EAAE;;AACU,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,MAAA,EAAA,MAAA,CAAA;AA8HpB,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC;AAAE,IAAA,cAAc,CAAC,MAAM,CAAC,SAAS,EAAE,WAAW,CAAC;;;;"}
@@ -0,0 +1,49 @@
1
+ 'use strict';
2
+
3
+ var names = require('./names.cjs');
4
+ var tokens = require('./tokens.cjs');
5
+ var zone = require('./zone.cjs');
6
+
7
+ const hour12 = (hour) => hour % 12 || 12;
8
+ const FORMATTERS = {
9
+ YYYY: ({ fields }) => (fields.year < 0 ? "-" : "") + zone.pad(fields.year, 4),
10
+ YY: ({ fields }) => zone.pad(fields.year % 100),
11
+ MMMM: ({ fields, locale }) => names.monthNames(locale, "long")[fields.month - 1],
12
+ MMM: ({ fields, locale }) => names.monthNames(locale, "short")[fields.month - 1],
13
+ MM: ({ fields }) => zone.pad(fields.month),
14
+ M: ({ fields }) => String(fields.month),
15
+ DD: ({ fields }) => zone.pad(fields.day),
16
+ D: ({ fields }) => String(fields.day),
17
+ dddd: ({ fields, locale }) => names.weekdayNames(locale, "long")[fields.weekday],
18
+ ddd: ({ fields, locale }) => names.weekdayNames(locale, "short")[fields.weekday],
19
+ d: ({ fields }) => String(fields.weekday),
20
+ HH: ({ fields }) => zone.pad(fields.hour),
21
+ H: ({ fields }) => String(fields.hour),
22
+ hh: ({ fields }) => zone.pad(hour12(fields.hour)),
23
+ h: ({ fields }) => String(hour12(fields.hour)),
24
+ mm: ({ fields }) => zone.pad(fields.minute),
25
+ m: ({ fields }) => String(fields.minute),
26
+ ss: ({ fields }) => zone.pad(fields.second),
27
+ s: ({ fields }) => String(fields.second),
28
+ SSS: ({ fields }) => zone.pad(fields.millisecond, 3),
29
+ A: ({ fields, locale }) => names.dayPeriods(locale)[fields.hour < 12 ? 0 : 1],
30
+ a: ({ fields, locale }) => names.dayPeriods(locale)[fields.hour < 12 ? 0 : 1].toLocaleLowerCase(locale),
31
+ ZZ: ({ date, timeZone }) => zone.formatOffset(zone.offsetMinutes(date, timeZone), ""),
32
+ Z: ({ date, timeZone }) => zone.formatOffset(zone.offsetMinutes(date, timeZone)),
33
+ X: ({ date }) => String(Math.floor(date.getTime() / 1000)),
34
+ x: ({ date }) => String(date.getTime()),
35
+ };
36
+ /**
37
+ * Formats `date` with a moment-style pattern (see `tokens.ts`). Numbers are
38
+ * always Latin digits; month, weekday and day-period names come from `Intl`
39
+ * in the given locale.
40
+ */
41
+ function formatPattern(date, pattern, locale, timeZone) {
42
+ const context = { date, fields: zone.getFields(date, timeZone), locale, timeZone };
43
+ return tokens.tokenize(pattern)
44
+ .map(part => ("token" in part ? FORMATTERS[part.token](context) : part.literal))
45
+ .join("");
46
+ }
47
+
48
+ exports.formatPattern = formatPattern;
49
+ //# sourceMappingURL=format-pattern.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-pattern.cjs","sources":["../../../../libs/elements/src/date/format-pattern.ts"],"sourcesContent":[null],"names":["pad","monthNames","weekdayNames","dayPeriods","formatOffset","offsetMinutes","getFields","tokenize"],"mappings":";;;;;;AAYA,MAAM,MAAM,GAAG,CAAC,IAAY,KAAK,IAAI,GAAG,EAAE,IAAI,EAAE;AAChD,MAAM,UAAU,GAAgD;AAC9D,IAAA,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,GAAG,GAAG,GAAG,EAAE,IAAIA,QAAG,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;AACxE,IAAA,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,KAAKA,QAAG,CAAC,MAAM,CAAC,IAAI,GAAG,GAAG,CAAC;IAC1C,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,KAAKC,gBAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC;IAC1E,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,KAAKA,gBAAU,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC;AAC1E,IAAA,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,KAAKD,QAAG,CAAC,MAAM,CAAC,KAAK,CAAC;AACrC,IAAA,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;AACvC,IAAA,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,KAAKA,QAAG,CAAC,MAAM,CAAC,GAAG,CAAC;AACnC,IAAA,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC;IACrC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IAAI,CAAC,EAAE,CAAC;AACb;;;;"}
@@ -0,0 +1,47 @@
1
+ import { dayPeriods, weekdayNames, monthNames } from './names.js';
2
+ import { tokenize } from './tokens.js';
3
+ import { getFields, formatOffset, offsetMinutes, pad } from './zone.js';
4
+
5
+ const hour12 = (hour) => hour % 12 || 12;
6
+ const FORMATTERS = {
7
+ YYYY: ({ fields }) => (fields.year < 0 ? "-" : "") + pad(fields.year, 4),
8
+ YY: ({ fields }) => pad(fields.year % 100),
9
+ MMMM: ({ fields, locale }) => monthNames(locale, "long")[fields.month - 1],
10
+ MMM: ({ fields, locale }) => monthNames(locale, "short")[fields.month - 1],
11
+ MM: ({ fields }) => pad(fields.month),
12
+ M: ({ fields }) => String(fields.month),
13
+ DD: ({ fields }) => pad(fields.day),
14
+ D: ({ fields }) => String(fields.day),
15
+ dddd: ({ fields, locale }) => weekdayNames(locale, "long")[fields.weekday],
16
+ ddd: ({ fields, locale }) => weekdayNames(locale, "short")[fields.weekday],
17
+ d: ({ fields }) => String(fields.weekday),
18
+ HH: ({ fields }) => pad(fields.hour),
19
+ H: ({ fields }) => String(fields.hour),
20
+ hh: ({ fields }) => pad(hour12(fields.hour)),
21
+ h: ({ fields }) => String(hour12(fields.hour)),
22
+ mm: ({ fields }) => pad(fields.minute),
23
+ m: ({ fields }) => String(fields.minute),
24
+ ss: ({ fields }) => pad(fields.second),
25
+ s: ({ fields }) => String(fields.second),
26
+ SSS: ({ fields }) => pad(fields.millisecond, 3),
27
+ A: ({ fields, locale }) => dayPeriods(locale)[fields.hour < 12 ? 0 : 1],
28
+ a: ({ fields, locale }) => dayPeriods(locale)[fields.hour < 12 ? 0 : 1].toLocaleLowerCase(locale),
29
+ ZZ: ({ date, timeZone }) => formatOffset(offsetMinutes(date, timeZone), ""),
30
+ Z: ({ date, timeZone }) => formatOffset(offsetMinutes(date, timeZone)),
31
+ X: ({ date }) => String(Math.floor(date.getTime() / 1000)),
32
+ x: ({ date }) => String(date.getTime()),
33
+ };
34
+ /**
35
+ * Formats `date` with a moment-style pattern (see `tokens.ts`). Numbers are
36
+ * always Latin digits; month, weekday and day-period names come from `Intl`
37
+ * in the given locale.
38
+ */
39
+ function formatPattern(date, pattern, locale, timeZone) {
40
+ const context = { date, fields: getFields(date, timeZone), locale, timeZone };
41
+ return tokenize(pattern)
42
+ .map(part => ("token" in part ? FORMATTERS[part.token](context) : part.literal))
43
+ .join("");
44
+ }
45
+
46
+ export { formatPattern };
47
+ //# sourceMappingURL=format-pattern.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-pattern.js","sources":["../../../../libs/elements/src/date/format-pattern.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAYA,MAAM,MAAM,GAAG,CAAC,IAAY,KAAK,IAAI,GAAG,EAAE,IAAI,EAAE;AAChD,MAAM,UAAU,GAAgD;AAC9D,IAAA,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,GAAG,GAAG,GAAG,EAAE,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;AACxE,IAAA,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,GAAG,CAAC,MAAM,CAAC,IAAI,GAAG,GAAG,CAAC;IAC1C,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC;IAC1E,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC;AAC1E,IAAA,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC;AACrC,IAAA,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,MAAM,CAAC,MAAM,C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OAAO,QAAQ,CAAC,OAAO;AACpB,SAAA,GAAG,CAAC,IAAI,KAAK,OAAO,IAAI,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC;SAC9E,IAAI,CAAC,EAAE,CAAC;AACb;;;;"}
@@ -0,0 +1,57 @@
1
+ 'use strict';
2
+
3
+ var formatPattern = require('./format-pattern.cjs');
4
+ var intl = require('./intl.cjs');
5
+ var relative = require('./relative.cjs');
6
+
7
+ const PRESETS = ["short", "medium", "long", "full"];
8
+ const DEFAULT_PRESET = "medium";
9
+ /**
10
+ * Interprets the `format`, `date-style` and `time-style` attributes.
11
+ *
12
+ * - `relative` → relative time ("3 minutes ago").
13
+ * - A preset name (`short`, `medium`, `long`, `full`) or empty → `Intl`
14
+ * `dateStyle` + `timeStyle`, each overridable (or omitted with `none`).
15
+ * - Anything else → a moment-style token pattern.
16
+ */
17
+ function resolveFormat(format, dateStyle, timeStyle) {
18
+ const value = format.trim();
19
+ if (value === "relative")
20
+ return { kind: "relative" };
21
+ if (value && !PRESETS.includes(value))
22
+ return { kind: "pattern", pattern: format };
23
+ const preset = (value || DEFAULT_PRESET);
24
+ const date = pickStyle(dateStyle, preset);
25
+ const time = pickStyle(timeStyle, preset);
26
+ // Both parts omitted would render nothing; keep the date.
27
+ if (!date && !time)
28
+ return { kind: "preset", dateStyle: preset };
29
+ return { kind: "preset", dateStyle: date, timeStyle: time };
30
+ }
31
+ function pickStyle(override, preset) {
32
+ if (override === "none")
33
+ return undefined;
34
+ return override && PRESETS.includes(override) ? override : preset;
35
+ }
36
+ /** Renders `date` according to a resolved format. */
37
+ function formatDate(date, spec, { locale, timeZone, now }) {
38
+ switch (spec.kind) {
39
+ case "relative":
40
+ return relative.formatRelative(date, now, locale);
41
+ case "pattern":
42
+ return formatPattern.formatPattern(date, spec.pattern, locale, timeZone);
43
+ case "preset":
44
+ return intl.dateTimeFormat(locale, { dateStyle: spec.dateStyle, timeStyle: spec.timeStyle, timeZone }).format(date);
45
+ }
46
+ }
47
+ /** A full, unambiguous rendering used for the tooltip of relative dates. */
48
+ function formatFull(date, locale, timeZone) {
49
+ return intl.dateTimeFormat(locale, { dateStyle: "full", timeStyle: "long", timeZone }).format(date);
50
+ }
51
+
52
+ exports.DEFAULT_PRESET = DEFAULT_PRESET;
53
+ exports.PRESETS = PRESETS;
54
+ exports.formatDate = formatDate;
55
+ exports.formatFull = formatFull;
56
+ exports.resolveFormat = resolveFormat;
57
+ //# sourceMappingURL=format.cjs.map