@aurodesignsystem-dev/auro-datetime 0.0.0-pr82.7 → 0.0.0-pr82.9
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/demo/api.md +9 -9
- package/demo/auro-datetime.min.js +42 -18
- package/dist/auro-datetime-39FU0ZIU.js +6 -0
- package/dist/index.d.ts +6 -6
- package/dist/index.js +1 -1
- package/dist/registered.js +1 -1
- package/package.json +1 -1
- package/dist/auro-datetime-Cq0WDk5L.js +0 -6
package/demo/api.md
CHANGED
|
@@ -11,7 +11,7 @@ The `auro-datetime` element is for the purposes of providing an easy to use date
|
|
|
11
11
|
| ---------- | ---------- | --------- | ------------------------------------------------------------------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
12
12
|
| locale | locale | | string | `en-US` | BCP 47 language tag for locale-aware date/time formatting (e.g. 'en-GB', 'de-DE', 'ja-JP'). |
|
|
13
13
|
| month | month | | `short` \| `long` | `short` | Defines format of month |
|
|
14
|
-
|
|
|
14
|
+
| timezone | timezone | | string | | Pass in string to define [timezone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).<br>When set, the moment described by `value` is converted into this IANA zone for display.<br>When unset, the wall-clock time from the input string is rendered as-is. |
|
|
15
15
|
| type | type | | `date` \| `time` \| `year` \| `month` \| `weekday` \| `day` \| `numeric` | | Defines type of data to render |
|
|
16
16
|
| value | value | | string | | ISO 8601 date or date-time string. Examples:<br>- `2022-07-14T08:00:00-07:00` (with offset)<br>- `2022-07-14T08:00:00Z` (UTC)<br>- `2022-07-14T08:00:00` (no offset)<br>- `2022-07-14` (date only)<br><br>When omitted, the component renders today's date.<br>Invalid input is logged as a warning and renders nothing. |
|
|
17
17
|
| weekday | weekday | | `short` \| `long` | `short` | Defines format of weekday |
|
|
@@ -229,7 +229,7 @@ Using the `auro-datetime` element with `type=numeric` will return the **current
|
|
|
229
229
|
|
|
230
230
|
#### Wall-clock display from offset
|
|
231
231
|
|
|
232
|
-
When the `value` attribute contains a timezone offset (or `Z`) and no `
|
|
232
|
+
When the `value` attribute contains a timezone offset (or `Z`) and no `timezone` attribute is set, the component renders the **wall-clock** components from the input verbatim. This is the right behavior for displaying local airport time on a flight schedule, where the offset describes the location of the flight rather than the viewer.
|
|
233
233
|
|
|
234
234
|
Example using `2022-07-13T21:35:00-07:00`. The same string is rendered identically regardless of the viewer's location.
|
|
235
235
|
|
|
@@ -254,7 +254,7 @@ Example using `2022-07-13T21:35:00-07:00`. The same string is rendered identical
|
|
|
254
254
|
|
|
255
255
|
### UTC (Zulu) input
|
|
256
256
|
|
|
257
|
-
The `value` attribute also accepts ISO 8601 strings ending in the `Z` designator. Without a `
|
|
257
|
+
The `value` attribute also accepts ISO 8601 strings ending in the `Z` designator. Without a `timezone` attribute, the wall-clock components are rendered as written. To convert into a viewer-meaningful timezone, also set `timezone` (see the timezone example).
|
|
258
258
|
|
|
259
259
|
<div class="exampleWrapper">
|
|
260
260
|
<!-- AURO-GENERATED-CONTENT:START (FILE:src=../apiExamples/utc.html) -->
|
|
@@ -277,19 +277,19 @@ The `value` attribute also accepts ISO 8601 strings ending in the `Z` designator
|
|
|
277
277
|
<!-- AURO-GENERATED-CONTENT:END -->
|
|
278
278
|
</auro-accordion>
|
|
279
279
|
|
|
280
|
-
### Combining `value` and `
|
|
280
|
+
### Combining `value` and `timezone`
|
|
281
281
|
|
|
282
|
-
How the `
|
|
282
|
+
How the `timezone` attribute composes with the input depends on whether `value` carries an offset:
|
|
283
283
|
|
|
284
|
-
- **`value` has an offset (or `Z`):** the offset anchors the absolute moment; `
|
|
285
|
-
- **`value` has no offset:** the wall-clock is interpreted as being in `
|
|
284
|
+
- **`value` has an offset (or `Z`):** the offset anchors the absolute moment; `timezone` is the display zone. Example: `value="2022-07-14T08:00:00-04:00" timezone="US/Pacific"` renders as `5:00 am` (8am Eastern → 5am Pacific).
|
|
285
|
+
- **`value` has no offset:** the wall-clock is interpreted as being in `timezone`, so display in that same zone matches the input verbatim. Example: `value="2022-07-14T08:00:00" timezone="US/Eastern"` renders as `8:00 am` regardless of where the viewer is. This is the recommended shape when consumers know the source zone but don't have an offset readily available (e.g. flight-schedule data keyed by airport).
|
|
286
286
|
|
|
287
|
-
#### Invalid `
|
|
287
|
+
#### Invalid `timezone` and `locale` values
|
|
288
288
|
|
|
289
289
|
Both attributes are validated up-front. Invalid inputs do **not** crash the component — they fall back gracefully and log a `console.warn` (deduplicated per element):
|
|
290
290
|
|
|
291
291
|
- **Invalid `locale`** (e.g. `"xx-INVALID-tag"`) → falls back to `"en-US"`.
|
|
292
|
-
- **Invalid `
|
|
292
|
+
- **Invalid `timezone`** (e.g. `"US/Pacfic"` typo) → falls back to behaving as if `timezone` was not specified. With `value` set, that means wall-clock display from the input components — visually the same string for every viewer. With `value` unset, that means the current time in the viewer's machine zone. The warning surfaces the typo so the developer can fix it.
|
|
293
293
|
|
|
294
294
|
## Slot Examples
|
|
295
295
|
|
|
@@ -150,11 +150,23 @@ class AuroDatetime extends i {
|
|
|
150
150
|
*/
|
|
151
151
|
this._warnedTimeZones = new Set();
|
|
152
152
|
|
|
153
|
+
/**
|
|
154
|
+
* Tracks invalid value inputs already warned about. Same dedup
|
|
155
|
+
* pattern as `_warnedLocales`.
|
|
156
|
+
* @private
|
|
157
|
+
*/
|
|
158
|
+
this._warnedValues = new Set();
|
|
159
|
+
|
|
153
160
|
/**
|
|
154
161
|
* @private
|
|
155
162
|
*/
|
|
156
163
|
this._effectiveLocale = this._resolveLocale(this.locale);
|
|
157
164
|
|
|
165
|
+
/**
|
|
166
|
+
* @private
|
|
167
|
+
*/
|
|
168
|
+
this._effectiveTimeZone = this._resolveTimeZone(this.timezone);
|
|
169
|
+
|
|
158
170
|
/**
|
|
159
171
|
* @private
|
|
160
172
|
*/
|
|
@@ -190,7 +202,7 @@ class AuroDatetime extends i {
|
|
|
190
202
|
/**
|
|
191
203
|
* Validate an IANA timezone identifier. Invalid input warns once per
|
|
192
204
|
* unique value per element and resolves to `undefined`, which makes
|
|
193
|
-
* the rest of `_resolveInputDate` behave as if `
|
|
205
|
+
* the rest of `_resolveInputDate` behave as if `timezone` was never
|
|
194
206
|
* specified — i.e. wall-clock display from the input components.
|
|
195
207
|
*
|
|
196
208
|
* Without this guard, a typo like `"US/Pacfic"` would cause
|
|
@@ -263,11 +275,11 @@ class AuroDatetime extends i {
|
|
|
263
275
|
month: { type: String },
|
|
264
276
|
|
|
265
277
|
/**
|
|
266
|
-
* Pass in string to define [
|
|
278
|
+
* Pass in string to define [timezone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
|
|
267
279
|
* When set, the moment described by `value` is converted into this IANA zone for display.
|
|
268
280
|
* When unset, the wall-clock time from the input string is rendered as-is.
|
|
269
281
|
*/
|
|
270
|
-
|
|
282
|
+
timezone: { type: String },
|
|
271
283
|
|
|
272
284
|
/**
|
|
273
285
|
* Defines type of data to render
|
|
@@ -312,6 +324,9 @@ class AuroDatetime extends i {
|
|
|
312
324
|
if (changedProperties.has("locale")) {
|
|
313
325
|
this._effectiveLocale = this._resolveLocale(this.locale);
|
|
314
326
|
}
|
|
327
|
+
if (changedProperties.has("timezone")) {
|
|
328
|
+
this._effectiveTimeZone = this._resolveTimeZone(this.timezone);
|
|
329
|
+
}
|
|
315
330
|
}
|
|
316
331
|
|
|
317
332
|
firstUpdated() {
|
|
@@ -357,30 +372,30 @@ class AuroDatetime extends i {
|
|
|
357
372
|
}
|
|
358
373
|
|
|
359
374
|
/**
|
|
360
|
-
* Resolve the `value` and `
|
|
375
|
+
* Resolve the `value` and `timezone` attributes into a Date and an optional
|
|
361
376
|
* timeZone option for `Intl.DateTimeFormat`.
|
|
362
377
|
*
|
|
363
378
|
* Behavior:
|
|
364
|
-
* - `value` omitted (null/undefined): returns today's date. `
|
|
379
|
+
* - `value` omitted (null/undefined): returns today's date. `timezone`
|
|
365
380
|
* (if any) is honored.
|
|
366
381
|
* - `value` invalid (including empty string ""): warns and returns
|
|
367
382
|
* `{ date: null }`. Empty is *not* the same as omitted — Lit reflects
|
|
368
383
|
* `value=""` as the empty string, which is not a valid ISO 8601
|
|
369
384
|
* form, so we surface it as a typo rather than silently rendering
|
|
370
385
|
* today's date.
|
|
371
|
-
* - `
|
|
386
|
+
* - `timezone` set + input has offset/Z: parses as an absolute moment
|
|
372
387
|
* (offset honored) and asks `toLocaleString` to convert into the target zone.
|
|
373
|
-
* - `
|
|
388
|
+
* - `timezone` set + input has no offset: interprets the wall-clock as
|
|
374
389
|
* being in the target zone, so display in that zone matches the input
|
|
375
390
|
* verbatim. This is viewer-independent.
|
|
376
|
-
* - Default (no `
|
|
391
|
+
* - Default (no `timezone`): strips the offset/Z from the input and treats
|
|
377
392
|
* the remaining wall-clock components as local time, so they render verbatim.
|
|
378
393
|
*
|
|
379
394
|
* @private
|
|
380
395
|
* @returns {{ date: Date | null, timeZoneOption: string | undefined }}
|
|
381
396
|
*/
|
|
382
397
|
_resolveInputDate() {
|
|
383
|
-
const resolvedTz = this.
|
|
398
|
+
const resolvedTz = this._effectiveTimeZone;
|
|
384
399
|
|
|
385
400
|
// Only true "omitted" inputs (null/undefined) get the today's-date
|
|
386
401
|
// treatment. Empty string falls through to ISO validation, which will
|
|
@@ -391,9 +406,12 @@ class AuroDatetime extends i {
|
|
|
391
406
|
|
|
392
407
|
const match = this.value.match(ISO_8601_REGEX);
|
|
393
408
|
if (!match) {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
409
|
+
if (!this._warnedValues.has(this.value)) {
|
|
410
|
+
this._warnedValues.add(this.value);
|
|
411
|
+
console.warn(
|
|
412
|
+
`auro-datetime: "${this.value}" is not a valid ISO 8601 string.`,
|
|
413
|
+
);
|
|
414
|
+
}
|
|
397
415
|
return { date: null, timeZoneOption: undefined };
|
|
398
416
|
}
|
|
399
417
|
|
|
@@ -406,9 +424,12 @@ class AuroDatetime extends i {
|
|
|
406
424
|
// would silently drop the offset, producing surprising output. Reject
|
|
407
425
|
// them up front so the consumer sees a warning.
|
|
408
426
|
if (hasOffset && !localPart.includes("T")) {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
427
|
+
if (!this._warnedValues.has(this.value)) {
|
|
428
|
+
this._warnedValues.add(this.value);
|
|
429
|
+
console.warn(
|
|
430
|
+
`auro-datetime: "${this.value}" is not a valid ISO 8601 string (offset/Z requires a time component).`,
|
|
431
|
+
);
|
|
432
|
+
}
|
|
412
433
|
return { date: null, timeZoneOption: undefined };
|
|
413
434
|
}
|
|
414
435
|
|
|
@@ -436,9 +457,12 @@ class AuroDatetime extends i {
|
|
|
436
457
|
|
|
437
458
|
const date = buildDate();
|
|
438
459
|
if (Number.isNaN(date.getTime())) {
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
460
|
+
if (!this._warnedValues.has(this.value)) {
|
|
461
|
+
this._warnedValues.add(this.value);
|
|
462
|
+
console.warn(
|
|
463
|
+
`auro-datetime: "${this.value}" is not a valid ISO 8601 date.`,
|
|
464
|
+
);
|
|
465
|
+
}
|
|
442
466
|
return { date: null, timeZoneOption: undefined };
|
|
443
467
|
}
|
|
444
468
|
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{LitElement as e,html as t}from"lit";class i{registerComponent(e,t){customElements.get(e)||customElements.define(e,class extends t{})}closestElement(e,t=this,i=(t,a=t&&t.closest(e))=>t&&t!==document&&t!==window?a||i(t.getRootNode().host):null){return i(t)}handleComponentTagRename(e,t){const i=t.toLowerCase();e.tagName.toLowerCase()!==i&&e.setAttribute(i,!0)}elementMatch(e,t){const i=t.toLowerCase();return e.tagName.toLowerCase()===i||e.hasAttribute(i)}getSlotText(e,t){const i=e.shadowRoot?.querySelector(`slot[name="${t}"]`);return(i?.assignedNodes({flatten:!0})||[]).map(e=>e.textContent?.trim()).join(" ").trim()||null}}const a=/^(\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?)?)(Z|[+-]\d{2}:\d{2})?$/u;class n extends e{constructor(){super(),this._initializeDefaults()}_initializeDefaults(){this.weekday="short",this.month="short",this.locale="en-US",this._warnedLocales=new Set,this._warnedTimeZones=new Set,this._warnedValues=new Set,this._effectiveLocale=this._resolveLocale(this.locale),this._effectiveTimeZone=this._resolveTimeZone(this.timezone),this.runtimeUtils=new i}_resolveLocale(e){if(!e)return"en-US";try{return Intl.getCanonicalLocales(e)[0]}catch{return this._warnedLocales&&!this._warnedLocales.has(e)&&(this._warnedLocales.add(e),console.warn(`auro-datetime: "${e}" is not a valid BCP 47 locale tag. Falling back to "en-US".`)),"en-US"}}_resolveTimeZone(e){if(e)try{return new Intl.DateTimeFormat(void 0,{timeZone:e}),e}catch{return void(this._warnedTimeZones&&!this._warnedTimeZones.has(e)&&(this._warnedTimeZones.add(e),console.warn(`auro-datetime: "${e}" is not a valid IANA timezone. Falling back to viewer-local.`)))}}connectedCallback(){super.connectedCallback(),this.dateTemplate={weekday:this.weekday,year:"numeric",month:this.month,day:"numeric"},this.timeTemplate={hour:"2-digit",minute:"2-digit"}}static get properties(){return{locale:{type:String},month:{type:String},timezone:{type:String},type:{type:String},value:{type:String},weekday:{type:String}}}static register(e="auro-datetime"){i.prototype.registerComponent(e,n)}willUpdate(e){e.has("locale")&&(this._effectiveLocale=this._resolveLocale(this.locale)),e.has("timezone")&&(this._effectiveTimeZone=this._resolveTimeZone(this.timezone))}firstUpdated(){this.runtimeUtils.handleComponentTagRename(this,"auro-datetime")}_zonedWallClockToUtc(e,t){const i=new Date(`${e}Z`),a=new Intl.DateTimeFormat("en-US",{timeZone:t,hourCycle:"h23",year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}).formatToParts(i),n=Object.fromEntries(a.filter(e=>"literal"!==e.type).map(e=>[e.type,e.value])),o=new Date(`${n.year}-${n.month}-${n.day}T${n.hour}:${n.minute}:${n.second}Z`),s=i.getTime()-o.getTime();return new Date(i.getTime()+s)}_resolveInputDate(){const e=this._effectiveTimeZone;if(null==this.value)return{date:new Date,timeZoneOption:e};const t=this.value.match(a);if(!t)return this._warnedValues.has(this.value)||(this._warnedValues.add(this.value),console.warn(`auro-datetime: "${this.value}" is not a valid ISO 8601 string.`)),{date:null,timeZoneOption:void 0};const i=t[1],n=Boolean(t[2]);if(n&&!i.includes("T"))return this._warnedValues.has(this.value)||(this._warnedValues.add(this.value),console.warn(`auro-datetime: "${this.value}" is not a valid ISO 8601 string (offset/Z requires a time component).`)),{date:null,timeZoneOption:void 0};const o=i.includes("T")?i:`${i}T00:00:00`,s=(()=>e&&!n?this._zonedWallClockToUtc(o,e):e&&n?new Date(this.value):new Date(o))();return Number.isNaN(s.getTime())?(this._warnedValues.has(this.value)||(this._warnedValues.add(this.value),console.warn(`auro-datetime: "${this.value}" is not a valid ISO 8601 date.`)),{date:null,timeZoneOption:void 0}):{date:s,timeZoneOption:e}}humanDate(){const{date:e,timeZoneOption:t}=this._resolveInputDate();if(!e)return"";const i={...this.dateTemplate};return t&&(i.timeZone=t),e.toLocaleString(this._effectiveLocale,i)}humanDateConversion(){const{date:e,timeZoneOption:t}=this._resolveInputDate();if(!e)return"";const i={};switch(t&&(i.timeZone=t),this.type){case"day":i.day="numeric";break;case"month":i.month=this.month;break;case"year":i.year="numeric";break;case"weekday":i.weekday=this.weekday}return e.toLocaleString(this._effectiveLocale,i)}numericDate(){const{date:e,timeZoneOption:t}=this._resolveInputDate();if(!e)return"";const i={...this.dateTemplate,month:"numeric"};return Reflect.deleteProperty(i,"weekday"),t&&(i.timeZone=t),e.toLocaleString(this._effectiveLocale,i)}humanTime(){const{date:e,timeZoneOption:t}=this._resolveInputDate();if(!e)return"";const i={...this.timeTemplate};t&&(i.timeZone=t);const a=e.toLocaleString(this._effectiveLocale,i);return/[ap]\.?m\.?/iu.test(a)?a.replace(/^0+/u,"").toLowerCase():a}whichDate(){switch(this.type){case"date":default:return this.humanDate();case"time":return this.humanTime();case"year":case"month":case"weekday":case"day":return this.humanDateConversion();case"numeric":return this.numericDate()}}render(){return t`
|
|
2
|
+
<slot name="pre"></slot>
|
|
3
|
+
<span class="yield">${this.whichDate()}</span>
|
|
4
|
+
<slot name="post"></slot>
|
|
5
|
+
<slot></slot>
|
|
6
|
+
`}}export{n as A};
|
package/dist/index.d.ts
CHANGED
|
@@ -77,10 +77,10 @@ export type AuroDatetimeProps = {
|
|
|
77
77
|
locale?: AuroDatetime["locale"];
|
|
78
78
|
/** Defines format of month */
|
|
79
79
|
month?: AuroDatetime["month"];
|
|
80
|
-
/** Pass in string to define [
|
|
80
|
+
/** Pass in string to define [timezone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
|
|
81
81
|
When set, the moment described by `value` is converted into this IANA zone for display.
|
|
82
82
|
When unset, the wall-clock time from the input string is rendered as-is. */
|
|
83
|
-
|
|
83
|
+
timezone?: AuroDatetime["timezone"];
|
|
84
84
|
/** Defines type of data to render */
|
|
85
85
|
type?: AuroDatetime["type"];
|
|
86
86
|
/** ISO 8601 date or date-time string. Examples:
|
|
@@ -101,10 +101,10 @@ export type AuroDatetimeSolidJsProps = {
|
|
|
101
101
|
"prop:locale"?: AuroDatetime["locale"];
|
|
102
102
|
/** Defines format of month */
|
|
103
103
|
"prop:month"?: AuroDatetime["month"];
|
|
104
|
-
/** Pass in string to define [
|
|
104
|
+
/** Pass in string to define [timezone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
|
|
105
105
|
When set, the moment described by `value` is converted into this IANA zone for display.
|
|
106
106
|
When unset, the wall-clock time from the input string is rendered as-is. */
|
|
107
|
-
"prop:
|
|
107
|
+
"prop:timezone"?: AuroDatetime["timezone"];
|
|
108
108
|
/** Defines type of data to render */
|
|
109
109
|
"prop:type"?: AuroDatetime["type"];
|
|
110
110
|
/** ISO 8601 date or date-time string. Examples:
|
|
@@ -135,7 +135,7 @@ export type CustomElements = {
|
|
|
135
135
|
*
|
|
136
136
|
* - `locale`: BCP 47 language tag for locale-aware date/time formatting (e.g. 'en-GB', 'de-DE', 'ja-JP').
|
|
137
137
|
* - `month`: Defines format of month
|
|
138
|
-
* - `
|
|
138
|
+
* - `timezone`: Pass in string to define [timezone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
|
|
139
139
|
* When set, the moment described by `value` is converted into this IANA zone for display.
|
|
140
140
|
* When unset, the wall-clock time from the input string is rendered as-is.
|
|
141
141
|
* - `type`: Defines type of data to render
|
|
@@ -178,7 +178,7 @@ export type CustomElementsSolidJs = {
|
|
|
178
178
|
*
|
|
179
179
|
* - `locale`: BCP 47 language tag for locale-aware date/time formatting (e.g. 'en-GB', 'de-DE', 'ja-JP').
|
|
180
180
|
* - `month`: Defines format of month
|
|
181
|
-
* - `
|
|
181
|
+
* - `timezone`: Pass in string to define [timezone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
|
|
182
182
|
* When set, the moment described by `value` is converted into this IANA zone for display.
|
|
183
183
|
* When unset, the wall-clock time from the input string is rendered as-is.
|
|
184
184
|
* - `type`: Defines type of data to render
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{A as AuroDatetime}from"./auro-datetime-
|
|
1
|
+
export{A as AuroDatetime}from"./auro-datetime-39FU0ZIU.js";import"lit";
|
package/dist/registered.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{A as r}from"./auro-datetime-
|
|
1
|
+
import{A as r}from"./auro-datetime-39FU0ZIU.js";import"lit";r.register();
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"================================================================================"
|
|
8
8
|
],
|
|
9
9
|
"name": "@aurodesignsystem-dev/auro-datetime",
|
|
10
|
-
"version": "0.0.0-pr82.
|
|
10
|
+
"version": "0.0.0-pr82.9",
|
|
11
11
|
"description": "auro-datetime HTML custom element",
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import{LitElement as e,html as t}from"lit";class n{registerComponent(e,t){customElements.get(e)||customElements.define(e,class extends t{})}closestElement(e,t=this,n=(t,i=t&&t.closest(e))=>t&&t!==document&&t!==window?i||n(t.getRootNode().host):null){return n(t)}handleComponentTagRename(e,t){const n=t.toLowerCase();e.tagName.toLowerCase()!==n&&e.setAttribute(n,!0)}elementMatch(e,t){const n=t.toLowerCase();return e.tagName.toLowerCase()===n||e.hasAttribute(n)}getSlotText(e,t){const n=e.shadowRoot?.querySelector(`slot[name="${t}"]`);return(n?.assignedNodes({flatten:!0})||[]).map(e=>e.textContent?.trim()).join(" ").trim()||null}}const i=/^(\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?)?)(Z|[+-]\d{2}:\d{2})?$/u;class a extends e{constructor(){super(),this._initializeDefaults()}_initializeDefaults(){this.weekday="short",this.month="short",this.locale="en-US",this._warnedLocales=new Set,this._warnedTimeZones=new Set,this._effectiveLocale=this._resolveLocale(this.locale),this.runtimeUtils=new n}_resolveLocale(e){if(!e)return"en-US";try{return Intl.getCanonicalLocales(e)[0]}catch{return this._warnedLocales&&!this._warnedLocales.has(e)&&(this._warnedLocales.add(e),console.warn(`auro-datetime: "${e}" is not a valid BCP 47 locale tag. Falling back to "en-US".`)),"en-US"}}_resolveTimeZone(e){if(e)try{return new Intl.DateTimeFormat(void 0,{timeZone:e}),e}catch{return void(this._warnedTimeZones&&!this._warnedTimeZones.has(e)&&(this._warnedTimeZones.add(e),console.warn(`auro-datetime: "${e}" is not a valid IANA timezone. Falling back to viewer-local.`)))}}connectedCallback(){super.connectedCallback(),this.dateTemplate={weekday:this.weekday,year:"numeric",month:this.month,day:"numeric"},this.timeTemplate={hour:"2-digit",minute:"2-digit"}}static get properties(){return{locale:{type:String},month:{type:String},timeZone:{type:String},type:{type:String},value:{type:String},weekday:{type:String}}}static register(e="auro-datetime"){n.prototype.registerComponent(e,a)}willUpdate(e){e.has("locale")&&(this._effectiveLocale=this._resolveLocale(this.locale))}firstUpdated(){this.runtimeUtils.handleComponentTagRename(this,"auro-datetime")}_zonedWallClockToUtc(e,t){const n=new Date(`${e}Z`),i=new Intl.DateTimeFormat("en-US",{timeZone:t,hourCycle:"h23",year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}).formatToParts(n),a=Object.fromEntries(i.filter(e=>"literal"!==e.type).map(e=>[e.type,e.value])),o=new Date(`${a.year}-${a.month}-${a.day}T${a.hour}:${a.minute}:${a.second}Z`),s=n.getTime()-o.getTime();return new Date(n.getTime()+s)}_resolveInputDate(){const e=this._resolveTimeZone(this.timeZone);if(null==this.value)return{date:new Date,timeZoneOption:e};const t=this.value.match(i);if(!t)return console.warn(`auro-datetime: "${this.value}" is not a valid ISO 8601 string.`),{date:null,timeZoneOption:void 0};const n=t[1],a=Boolean(t[2]);if(a&&!n.includes("T"))return console.warn(`auro-datetime: "${this.value}" is not a valid ISO 8601 string (offset/Z requires a time component).`),{date:null,timeZoneOption:void 0};const o=n.includes("T")?n:`${n}T00:00:00`,s=(()=>e&&!a?this._zonedWallClockToUtc(o,e):e&&a?new Date(this.value):new Date(o))();return Number.isNaN(s.getTime())?(console.warn(`auro-datetime: "${this.value}" is not a valid ISO 8601 date.`),{date:null,timeZoneOption:void 0}):{date:s,timeZoneOption:e}}humanDate(){const{date:e,timeZoneOption:t}=this._resolveInputDate();if(!e)return"";const n={...this.dateTemplate};return t&&(n.timeZone=t),e.toLocaleString(this._effectiveLocale,n)}humanDateConversion(){const{date:e,timeZoneOption:t}=this._resolveInputDate();if(!e)return"";const n={};switch(t&&(n.timeZone=t),this.type){case"day":n.day="numeric";break;case"month":n.month=this.month;break;case"year":n.year="numeric";break;case"weekday":n.weekday=this.weekday}return e.toLocaleString(this._effectiveLocale,n)}numericDate(){const{date:e,timeZoneOption:t}=this._resolveInputDate();if(!e)return"";const n={...this.dateTemplate,month:"numeric"};return Reflect.deleteProperty(n,"weekday"),t&&(n.timeZone=t),e.toLocaleString(this._effectiveLocale,n)}humanTime(){const{date:e,timeZoneOption:t}=this._resolveInputDate();if(!e)return"";const n={...this.timeTemplate};t&&(n.timeZone=t);const i=e.toLocaleString(this._effectiveLocale,n);return/[ap]\.?m\.?/iu.test(i)?i.replace(/^0+/u,"").toLowerCase():i}whichDate(){switch(this.type){case"date":default:return this.humanDate();case"time":return this.humanTime();case"year":case"month":case"weekday":case"day":return this.humanDateConversion();case"numeric":return this.numericDate()}}render(){return t`
|
|
2
|
-
<slot name="pre"></slot>
|
|
3
|
-
<span class="yield">${this.whichDate()}</span>
|
|
4
|
-
<slot name="post"></slot>
|
|
5
|
-
<slot></slot>
|
|
6
|
-
`}}export{a as A};
|