@aurodesignsystem-dev/auro-datetime 0.0.0-pr92.0 → 0.0.0-pr93.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/demo/api.md +116 -142
- package/demo/api.min.js +606 -1
- package/demo/index.md +12 -16
- package/demo/index.min.js +606 -1
- package/demo/readme.md +116 -0
- package/package.json +1 -1
- package/demo/auro-datetime.min.js +0 -608
|
@@ -1,608 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Alaska Air. All right reserved. Licensed under the Apache-2.0 license
|
|
2
|
-
// See LICENSE in the project root for license information.
|
|
3
|
-
|
|
4
|
-
// ---------------------------------------------------------------------
|
|
5
|
-
|
|
6
|
-
/* eslint-disable line-comment-position, no-inline-comments, no-confusing-arrow, no-nested-ternary, implicit-arrow-linebreak */
|
|
7
|
-
|
|
8
|
-
class AuroLibraryRuntimeUtils {
|
|
9
|
-
|
|
10
|
-
/* eslint-disable jsdoc/require-param */
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* This will register a new custom element with the browser.
|
|
14
|
-
* @param {String} name - The name of the custom element.
|
|
15
|
-
* @param {Object} componentClass - The class to register as a custom element.
|
|
16
|
-
* @returns {void}
|
|
17
|
-
*/
|
|
18
|
-
registerComponent(name, componentClass) {
|
|
19
|
-
if (!customElements.get(name)) {
|
|
20
|
-
customElements.define(name, class extends componentClass {});
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Finds and returns the closest HTML Element based on a selector.
|
|
26
|
-
* @returns {void}
|
|
27
|
-
*/
|
|
28
|
-
closestElement(
|
|
29
|
-
selector, // selector like in .closest()
|
|
30
|
-
base = this, // extra functionality to skip a parent
|
|
31
|
-
__Closest = (el, found = el && el.closest(selector)) =>
|
|
32
|
-
!el || el === document || el === window
|
|
33
|
-
? null // standard .closest() returns null for non-found selectors also
|
|
34
|
-
: found
|
|
35
|
-
? found // found a selector INside this element
|
|
36
|
-
: __Closest(el.getRootNode().host) // recursion!! break out to parent DOM
|
|
37
|
-
) {
|
|
38
|
-
return __Closest(base);
|
|
39
|
-
}
|
|
40
|
-
/* eslint-enable jsdoc/require-param */
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* If the element passed is registered with a different tag name than what is passed in, the tag name is added as an attribute to the element.
|
|
44
|
-
* @param {Object} elem - The element to check.
|
|
45
|
-
* @param {String} tagName - The name of the Auro component to check for or add as an attribute.
|
|
46
|
-
* @returns {void}
|
|
47
|
-
*/
|
|
48
|
-
handleComponentTagRename(elem, tagName) {
|
|
49
|
-
const tag = tagName.toLowerCase();
|
|
50
|
-
const elemTag = elem.tagName.toLowerCase();
|
|
51
|
-
|
|
52
|
-
if (elemTag !== tag) {
|
|
53
|
-
elem.setAttribute(tag, true);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Validates if an element is a specific Auro component.
|
|
59
|
-
* @param {Object} elem - The element to validate.
|
|
60
|
-
* @param {String} tagName - The name of the Auro component to check against.
|
|
61
|
-
* @returns {Boolean} - Returns true if the element is the specified Auro component.
|
|
62
|
-
*/
|
|
63
|
-
elementMatch(elem, tagName) {
|
|
64
|
-
const tag = tagName.toLowerCase();
|
|
65
|
-
const elemTag = elem.tagName.toLowerCase();
|
|
66
|
-
|
|
67
|
-
return elemTag === tag || elem.hasAttribute(tag);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Gets the text content of a named slot.
|
|
72
|
-
* @returns {String}
|
|
73
|
-
* @private
|
|
74
|
-
*/
|
|
75
|
-
getSlotText(elem, name) {
|
|
76
|
-
const slot = elem.shadowRoot?.querySelector(`slot[name="${name}"]`);
|
|
77
|
-
const nodes = slot?.assignedNodes({ flatten: true }) || [];
|
|
78
|
-
const text = nodes.map(n => n.textContent?.trim()).join(' ').trim();
|
|
79
|
-
|
|
80
|
-
return text || null;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* @license
|
|
86
|
-
* Copyright 2019 Google LLC
|
|
87
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
88
|
-
*/
|
|
89
|
-
const t$1=globalThis,e$2=t$1.ShadowRoot&&(void 0===t$1.ShadyCSS||t$1.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,s$2=Symbol(),o$3=new WeakMap;let n$2 = class n{constructor(t,e,o){if(this._$cssResult$=true,o!==s$2)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e;}get styleSheet(){let t=this.o;const s=this.t;if(e$2&&void 0===t){const e=void 0!==s&&1===s.length;e&&(t=o$3.get(s)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),e&&o$3.set(s,t));}return t}toString(){return this.cssText}};const r$2=t=>new n$2("string"==typeof t?t:t+"",void 0,s$2),S$1=(s,o)=>{if(e$2)s.adoptedStyleSheets=o.map(t=>t instanceof CSSStyleSheet?t:t.styleSheet);else for(const e of o){const o=document.createElement("style"),n=t$1.litNonce;void 0!==n&&o.setAttribute("nonce",n),o.textContent=e.cssText,s.appendChild(o);}},c$2=e$2?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const s of t.cssRules)e+=s.cssText;return r$2(e)})(t):t;
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* @license
|
|
93
|
-
* Copyright 2017 Google LLC
|
|
94
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
95
|
-
*/const{is:i$2,defineProperty:e$1,getOwnPropertyDescriptor:h$1,getOwnPropertyNames:r$1,getOwnPropertySymbols:o$2,getPrototypeOf:n$1}=Object,a$1=globalThis,c$1=a$1.trustedTypes,l$1=c$1?c$1.emptyScript:"",p$1=a$1.reactiveElementPolyfillSupport,d$1=(t,s)=>t,u$1={toAttribute(t,s){switch(s){case Boolean:t=t?l$1:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t);}return t},fromAttribute(t,s){let i=t;switch(s){case Boolean:i=null!==t;break;case Number:i=null===t?null:Number(t);break;case Object:case Array:try{i=JSON.parse(t);}catch(t){i=null;}}return i}},f$1=(t,s)=>!i$2(t,s),b$1={attribute:true,type:String,converter:u$1,reflect:false,useDefault:false,hasChanged:f$1};Symbol.metadata??=Symbol("metadata"),a$1.litPropertyMetadata??=new WeakMap;let y$1 = class y extends HTMLElement{static addInitializer(t){this._$Ei(),(this.l??=[]).push(t);}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(t,s=b$1){if(s.state&&(s.attribute=false),this._$Ei(),this.prototype.hasOwnProperty(t)&&((s=Object.create(s)).wrapped=true),this.elementProperties.set(t,s),!s.noAccessor){const i=Symbol(),h=this.getPropertyDescriptor(t,i,s);void 0!==h&&e$1(this.prototype,t,h);}}static getPropertyDescriptor(t,s,i){const{get:e,set:r}=h$1(this.prototype,t)??{get(){return this[s]},set(t){this[s]=t;}};return {get:e,set(s){const h=e?.call(this);r?.call(this,s),this.requestUpdate(t,h,i);},configurable:true,enumerable:true}}static getPropertyOptions(t){return this.elementProperties.get(t)??b$1}static _$Ei(){if(this.hasOwnProperty(d$1("elementProperties")))return;const t=n$1(this);t.finalize(),void 0!==t.l&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties);}static finalize(){if(this.hasOwnProperty(d$1("finalized")))return;if(this.finalized=true,this._$Ei(),this.hasOwnProperty(d$1("properties"))){const t=this.properties,s=[...r$1(t),...o$2(t)];for(const i of s)this.createProperty(i,t[i]);}const t=this[Symbol.metadata];if(null!==t){const s=litPropertyMetadata.get(t);if(void 0!==s)for(const[t,i]of s)this.elementProperties.set(t,i);}this._$Eh=new Map;for(const[t,s]of this.elementProperties){const i=this._$Eu(t,s);void 0!==i&&this._$Eh.set(i,t);}this.elementStyles=this.finalizeStyles(this.styles);}static finalizeStyles(s){const i=[];if(Array.isArray(s)){const e=new Set(s.flat(1/0).reverse());for(const s of e)i.unshift(c$2(s));}else void 0!==s&&i.push(c$2(s));return i}static _$Eu(t,s){const i=s.attribute;return false===i?void 0:"string"==typeof i?i:"string"==typeof t?t.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=false,this.hasUpdated=false,this._$Em=null,this._$Ev();}_$Ev(){this._$ES=new Promise(t=>this.enableUpdating=t),this._$AL=new Map,this._$E_(),this.requestUpdate(),this.constructor.l?.forEach(t=>t(this));}addController(t){(this._$EO??=new Set).add(t),void 0!==this.renderRoot&&this.isConnected&&t.hostConnected?.();}removeController(t){this._$EO?.delete(t);}_$E_(){const t=new Map,s=this.constructor.elementProperties;for(const i of s.keys())this.hasOwnProperty(i)&&(t.set(i,this[i]),delete this[i]);t.size>0&&(this._$Ep=t);}createRenderRoot(){const t=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return S$1(t,this.constructor.elementStyles),t}connectedCallback(){this.renderRoot??=this.createRenderRoot(),this.enableUpdating(true),this._$EO?.forEach(t=>t.hostConnected?.());}enableUpdating(t){}disconnectedCallback(){this._$EO?.forEach(t=>t.hostDisconnected?.());}attributeChangedCallback(t,s,i){this._$AK(t,i);}_$ET(t,s){const i=this.constructor.elementProperties.get(t),e=this.constructor._$Eu(t,i);if(void 0!==e&&true===i.reflect){const h=(void 0!==i.converter?.toAttribute?i.converter:u$1).toAttribute(s,i.type);this._$Em=t,null==h?this.removeAttribute(e):this.setAttribute(e,h),this._$Em=null;}}_$AK(t,s){const i=this.constructor,e=i._$Eh.get(t);if(void 0!==e&&this._$Em!==e){const t=i.getPropertyOptions(e),h="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==t.converter?.fromAttribute?t.converter:u$1;this._$Em=e;const r=h.fromAttribute(s,t.type);this[e]=r??this._$Ej?.get(e)??r,this._$Em=null;}}requestUpdate(t,s,i,e=false,h){if(void 0!==t){const r=this.constructor;if(false===e&&(h=this[t]),i??=r.getPropertyOptions(t),!((i.hasChanged??f$1)(h,s)||i.useDefault&&i.reflect&&h===this._$Ej?.get(t)&&!this.hasAttribute(r._$Eu(t,i))))return;this.C(t,s,i);} false===this.isUpdatePending&&(this._$ES=this._$EP());}C(t,s,{useDefault:i,reflect:e,wrapped:h},r){i&&!(this._$Ej??=new Map).has(t)&&(this._$Ej.set(t,r??s??this[t]),true!==h||void 0!==r)||(this._$AL.has(t)||(this.hasUpdated||i||(s=void 0),this._$AL.set(t,s)),true===e&&this._$Em!==t&&(this._$Eq??=new Set).add(t));}async _$EP(){this.isUpdatePending=true;try{await this._$ES;}catch(t){Promise.reject(t);}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??=this.createRenderRoot(),this._$Ep){for(const[t,s]of this._$Ep)this[t]=s;this._$Ep=void 0;}const t=this.constructor.elementProperties;if(t.size>0)for(const[s,i]of t){const{wrapped:t}=i,e=this[s];true!==t||this._$AL.has(s)||void 0===e||this.C(s,void 0,i,e);}}let t=false;const s=this._$AL;try{t=this.shouldUpdate(s),t?(this.willUpdate(s),this._$EO?.forEach(t=>t.hostUpdate?.()),this.update(s)):this._$EM();}catch(s){throw t=false,this._$EM(),s}t&&this._$AE(s);}willUpdate(t){}_$AE(t){this._$EO?.forEach(t=>t.hostUpdated?.()),this.hasUpdated||(this.hasUpdated=true,this.firstUpdated(t)),this.updated(t);}_$EM(){this._$AL=new Map,this.isUpdatePending=false;}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(t){return true}update(t){this._$Eq&&=this._$Eq.forEach(t=>this._$ET(t,this[t])),this._$EM();}updated(t){}firstUpdated(t){}};y$1.elementStyles=[],y$1.shadowRootOptions={mode:"open"},y$1[d$1("elementProperties")]=new Map,y$1[d$1("finalized")]=new Map,p$1?.({ReactiveElement:y$1}),(a$1.reactiveElementVersions??=[]).push("2.1.2");
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* @license
|
|
99
|
-
* Copyright 2017 Google LLC
|
|
100
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
101
|
-
*/
|
|
102
|
-
const t=globalThis,i$1=t=>t,s$1=t.trustedTypes,e=s$1?s$1.createPolicy("lit-html",{createHTML:t=>t}):void 0,h="$lit$",o$1=`lit$${Math.random().toFixed(9).slice(2)}$`,n="?"+o$1,r=`<${n}>`,l=document,c=()=>l.createComment(""),a=t=>null===t||"object"!=typeof t&&"function"!=typeof t,u=Array.isArray,d=t=>u(t)||"function"==typeof t?.[Symbol.iterator],f="[ \t\n\f\r]",v=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,_=/-->/g,m=/>/g,p=RegExp(`>|${f}(?:([^\\s"'>=/]+)(${f}*=${f}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`,"g"),g=/'/g,$=/"/g,y=/^(?:script|style|textarea|title)$/i,x=t=>(i,...s)=>({_$litType$:t,strings:i,values:s}),b=x(1),E=Symbol.for("lit-noChange"),A=Symbol.for("lit-nothing"),C=new WeakMap,P=l.createTreeWalker(l,129);function V(t,i){if(!u(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==e?e.createHTML(i):i}const N=(t,i)=>{const s=t.length-1,e=[];let n,l=2===i?"<svg>":3===i?"<math>":"",c=v;for(let i=0;i<s;i++){const s=t[i];let a,u,d=-1,f=0;for(;f<s.length&&(c.lastIndex=f,u=c.exec(s),null!==u);)f=c.lastIndex,c===v?"!--"===u[1]?c=_:void 0!==u[1]?c=m:void 0!==u[2]?(y.test(u[2])&&(n=RegExp("</"+u[2],"g")),c=p):void 0!==u[3]&&(c=p):c===p?">"===u[0]?(c=n??v,d=-1):void 0===u[1]?d=-2:(d=c.lastIndex-u[2].length,a=u[1],c=void 0===u[3]?p:'"'===u[3]?$:g):c===$||c===g?c=p:c===_||c===m?c=v:(c=p,n=void 0);const x=c===p&&t[i+1].startsWith("/>")?" ":"";l+=c===v?s+r:d>=0?(e.push(a),s.slice(0,d)+h+s.slice(d)+o$1+x):s+o$1+(-2===d?i:x);}return [V(t,l+(t[s]||"<?>")+(2===i?"</svg>":3===i?"</math>":"")),e]};class S{constructor({strings:t,_$litType$:i},e){let r;this.parts=[];let l=0,a=0;const u=t.length-1,d=this.parts,[f,v]=N(t,i);if(this.el=S.createElement(f,e),P.currentNode=this.el.content,2===i||3===i){const t=this.el.content.firstChild;t.replaceWith(...t.childNodes);}for(;null!==(r=P.nextNode())&&d.length<u;){if(1===r.nodeType){if(r.hasAttributes())for(const t of r.getAttributeNames())if(t.endsWith(h)){const i=v[a++],s=r.getAttribute(t).split(o$1),e=/([.?@])?(.*)/.exec(i);d.push({type:1,index:l,name:e[2],strings:s,ctor:"."===e[1]?I:"?"===e[1]?L:"@"===e[1]?z:H}),r.removeAttribute(t);}else t.startsWith(o$1)&&(d.push({type:6,index:l}),r.removeAttribute(t));if(y.test(r.tagName)){const t=r.textContent.split(o$1),i=t.length-1;if(i>0){r.textContent=s$1?s$1.emptyScript:"";for(let s=0;s<i;s++)r.append(t[s],c()),P.nextNode(),d.push({type:2,index:++l});r.append(t[i],c());}}}else if(8===r.nodeType)if(r.data===n)d.push({type:2,index:l});else {let t=-1;for(;-1!==(t=r.data.indexOf(o$1,t+1));)d.push({type:7,index:l}),t+=o$1.length-1;}l++;}}static createElement(t,i){const s=l.createElement("template");return s.innerHTML=t,s}}function M(t,i,s=t,e){if(i===E)return i;let h=void 0!==e?s._$Co?.[e]:s._$Cl;const o=a(i)?void 0:i._$litDirective$;return h?.constructor!==o&&(h?._$AO?.(false),void 0===o?h=void 0:(h=new o(t),h._$AT(t,s,e)),void 0!==e?(s._$Co??=[])[e]=h:s._$Cl=h),void 0!==h&&(i=M(t,h._$AS(t,i.values),h,e)),i}class R{constructor(t,i){this._$AV=[],this._$AN=void 0,this._$AD=t,this._$AM=i;}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(t){const{el:{content:i},parts:s}=this._$AD,e=(t?.creationScope??l).importNode(i,true);P.currentNode=e;let h=P.nextNode(),o=0,n=0,r=s[0];for(;void 0!==r;){if(o===r.index){let i;2===r.type?i=new k(h,h.nextSibling,this,t):1===r.type?i=new r.ctor(h,r.name,r.strings,this,t):6===r.type&&(i=new Z(h,this,t)),this._$AV.push(i),r=s[++n];}o!==r?.index&&(h=P.nextNode(),o++);}return P.currentNode=l,e}p(t){let i=0;for(const s of this._$AV) void 0!==s&&(void 0!==s.strings?(s._$AI(t,s,i),i+=s.strings.length-2):s._$AI(t[i])),i++;}}class k{get _$AU(){return this._$AM?._$AU??this._$Cv}constructor(t,i,s,e){this.type=2,this._$AH=A,this._$AN=void 0,this._$AA=t,this._$AB=i,this._$AM=s,this.options=e,this._$Cv=e?.isConnected??true;}get parentNode(){let t=this._$AA.parentNode;const i=this._$AM;return void 0!==i&&11===t?.nodeType&&(t=i.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,i=this){t=M(this,t,i),a(t)?t===A||null==t||""===t?(this._$AH!==A&&this._$AR(),this._$AH=A):t!==this._$AH&&t!==E&&this._(t):void 0!==t._$litType$?this.$(t):void 0!==t.nodeType?this.T(t):d(t)?this.k(t):this._(t);}O(t){return this._$AA.parentNode.insertBefore(t,this._$AB)}T(t){this._$AH!==t&&(this._$AR(),this._$AH=this.O(t));}_(t){this._$AH!==A&&a(this._$AH)?this._$AA.nextSibling.data=t:this.T(l.createTextNode(t)),this._$AH=t;}$(t){const{values:i,_$litType$:s}=t,e="number"==typeof s?this._$AC(t):(void 0===s.el&&(s.el=S.createElement(V(s.h,s.h[0]),this.options)),s);if(this._$AH?._$AD===e)this._$AH.p(i);else {const t=new R(e,this),s=t.u(this.options);t.p(i),this.T(s),this._$AH=t;}}_$AC(t){let i=C.get(t.strings);return void 0===i&&C.set(t.strings,i=new S(t)),i}k(t){u(this._$AH)||(this._$AH=[],this._$AR());const i=this._$AH;let s,e=0;for(const h of t)e===i.length?i.push(s=new k(this.O(c()),this.O(c()),this,this.options)):s=i[e],s._$AI(h),e++;e<i.length&&(this._$AR(s&&s._$AB.nextSibling,e),i.length=e);}_$AR(t=this._$AA.nextSibling,s){for(this._$AP?.(false,true,s);t!==this._$AB;){const s=i$1(t).nextSibling;i$1(t).remove(),t=s;}}setConnected(t){ void 0===this._$AM&&(this._$Cv=t,this._$AP?.(t));}}class H{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(t,i,s,e,h){this.type=1,this._$AH=A,this._$AN=void 0,this.element=t,this.name=i,this._$AM=e,this.options=h,s.length>2||""!==s[0]||""!==s[1]?(this._$AH=Array(s.length-1).fill(new String),this.strings=s):this._$AH=A;}_$AI(t,i=this,s,e){const h=this.strings;let o=false;if(void 0===h)t=M(this,t,i,0),o=!a(t)||t!==this._$AH&&t!==E,o&&(this._$AH=t);else {const e=t;let n,r;for(t=h[0],n=0;n<h.length-1;n++)r=M(this,e[s+n],i,n),r===E&&(r=this._$AH[n]),o||=!a(r)||r!==this._$AH[n],r===A?t=A:t!==A&&(t+=(r??"")+h[n+1]),this._$AH[n]=r;}o&&!e&&this.j(t);}j(t){t===A?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,t??"");}}class I extends H{constructor(){super(...arguments),this.type=3;}j(t){this.element[this.name]=t===A?void 0:t;}}class L extends H{constructor(){super(...arguments),this.type=4;}j(t){this.element.toggleAttribute(this.name,!!t&&t!==A);}}class z extends H{constructor(t,i,s,e,h){super(t,i,s,e,h),this.type=5;}_$AI(t,i=this){if((t=M(this,t,i,0)??A)===E)return;const s=this._$AH,e=t===A&&s!==A||t.capture!==s.capture||t.once!==s.once||t.passive!==s.passive,h=t!==A&&(s===A||e);e&&this.element.removeEventListener(this.name,this,s),h&&this.element.addEventListener(this.name,this,t),this._$AH=t;}handleEvent(t){"function"==typeof this._$AH?this._$AH.call(this.options?.host??this.element,t):this._$AH.handleEvent(t);}}class Z{constructor(t,i,s){this.element=t,this.type=6,this._$AN=void 0,this._$AM=i,this.options=s;}get _$AU(){return this._$AM._$AU}_$AI(t){M(this,t);}}const B=t.litHtmlPolyfillSupport;B?.(S,k),(t.litHtmlVersions??=[]).push("3.3.2");const D=(t,i,s)=>{const e=s?.renderBefore??i;let h=e._$litPart$;if(void 0===h){const t=s?.renderBefore??null;e._$litPart$=h=new k(i.insertBefore(c(),t),t,void 0,s??{});}return h._$AI(t),h};
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* @license
|
|
106
|
-
* Copyright 2017 Google LLC
|
|
107
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
108
|
-
*/const s=globalThis;class i extends y$1{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0;}createRenderRoot(){const t=super.createRenderRoot();return this.renderOptions.renderBefore??=t.firstChild,t}update(t){const r=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=D(r,this.renderRoot,this.renderOptions);}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(true);}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(false);}render(){return E}}i._$litElement$=true,i["finalized"]=true,s.litElementHydrateSupport?.({LitElement:i});const o=s.litElementPolyfillSupport;o?.({LitElement:i});(s.litElementVersions??=[]).push("4.2.2");
|
|
109
|
-
|
|
110
|
-
// Copyright (c) 2020 Alaska Airlines. All right reserved. Licensed under the Apache-2.0 license
|
|
111
|
-
// See LICENSE in the project root for license information.
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const ISO_8601_REGEX =
|
|
115
|
-
/^(\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?)?)(Z|[+-]\d{2}:\d{2})?$/u;
|
|
116
|
-
|
|
117
|
-
// See https://git.io/JJ6SJ for "How to document your components using JSDoc"
|
|
118
|
-
/**
|
|
119
|
-
* The `auro-datetime` element is for the purposes of providing an easy to use date and time API.
|
|
120
|
-
* @customElement auro-datetime
|
|
121
|
-
*
|
|
122
|
-
* @slot pre - Content that comes before the `post` content
|
|
123
|
-
* @slot post - Content that comes after the `pre` content
|
|
124
|
-
*/
|
|
125
|
-
|
|
126
|
-
// build the component class
|
|
127
|
-
class AuroDatetime extends i {
|
|
128
|
-
constructor() {
|
|
129
|
-
super();
|
|
130
|
-
|
|
131
|
-
this._initializeDefaults();
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
_initializeDefaults() {
|
|
135
|
-
this.weekday = "short";
|
|
136
|
-
this.month = "short";
|
|
137
|
-
this.locale = "en-US";
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Tracks invalid locale inputs already warned about, so a parent that
|
|
141
|
-
* re-renders with the same bad value doesn't flood the console.
|
|
142
|
-
* @private
|
|
143
|
-
*/
|
|
144
|
-
this._warnedLocales = new Set();
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Tracks invalid timeZone inputs already warned about. Same dedup
|
|
148
|
-
* pattern as `_warnedLocales`.
|
|
149
|
-
* @private
|
|
150
|
-
*/
|
|
151
|
-
this._warnedTimeZones = new Set();
|
|
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
|
-
|
|
160
|
-
/**
|
|
161
|
-
* @private
|
|
162
|
-
*/
|
|
163
|
-
this._effectiveLocale = this._resolveLocale(this.locale);
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* @private
|
|
167
|
-
*/
|
|
168
|
-
this._effectiveTimeZone = this._resolveTimeZone(this.timezone);
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* @private
|
|
172
|
-
*/
|
|
173
|
-
this.runtimeUtils = new AuroLibraryRuntimeUtils();
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Validate and canonicalize a BCP 47 locale tag. Falls back to "en-US"
|
|
178
|
-
* for empty or invalid input. The first invalid value seen per element
|
|
179
|
-
* is logged via `console.warn`; subsequent identical inputs are silent.
|
|
180
|
-
*
|
|
181
|
-
* @private
|
|
182
|
-
* @param {string} input - User-supplied locale tag.
|
|
183
|
-
* @returns {string} Canonical locale tag (e.g. "en-GB"), or "en-US" on fallback.
|
|
184
|
-
*/
|
|
185
|
-
_resolveLocale(input) {
|
|
186
|
-
if (!input) {
|
|
187
|
-
return "en-US";
|
|
188
|
-
}
|
|
189
|
-
try {
|
|
190
|
-
return Intl.getCanonicalLocales(input)[0];
|
|
191
|
-
} catch {
|
|
192
|
-
if (this._warnedLocales && !this._warnedLocales.has(input)) {
|
|
193
|
-
this._warnedLocales.add(input);
|
|
194
|
-
console.warn(
|
|
195
|
-
`auro-datetime: "${input}" is not a valid BCP 47 locale tag. Falling back to "en-US".`,
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
return "en-US";
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Validate an IANA timezone identifier. Invalid input warns once per
|
|
204
|
-
* unique value per element and resolves to `undefined`, which makes
|
|
205
|
-
* the rest of `_resolveInputDate` behave as if `timezone` was never
|
|
206
|
-
* specified — i.e. wall-clock display from the input components.
|
|
207
|
-
*
|
|
208
|
-
* Without this guard, a typo like `"US/Pacfic"` would cause
|
|
209
|
-
* `Intl.DateTimeFormat` / `toLocaleString` to throw `RangeError` at
|
|
210
|
-
* render time and crash the component.
|
|
211
|
-
*
|
|
212
|
-
* Note: when `value` is also unset, the wall-clock branch resolves to
|
|
213
|
-
* "today's date in the viewer's machine zone," which is viewer-
|
|
214
|
-
* dependent. This narrow case is the only scenario where two viewers
|
|
215
|
-
* see different output for the same component; the warning surfaces
|
|
216
|
-
* the typo so the developer can fix it.
|
|
217
|
-
*
|
|
218
|
-
* @private
|
|
219
|
-
* @param {string | undefined} input - Consumer-supplied timezone.
|
|
220
|
-
* @returns {string | undefined} Valid timezone, or undefined on fallback.
|
|
221
|
-
*/
|
|
222
|
-
_resolveTimeZone(input) {
|
|
223
|
-
if (!input) {
|
|
224
|
-
return undefined;
|
|
225
|
-
}
|
|
226
|
-
try {
|
|
227
|
-
// Constructing the formatter is enough to surface a RangeError;
|
|
228
|
-
// we don't need to format anything yet.
|
|
229
|
-
new Intl.DateTimeFormat(undefined, { timeZone: input });
|
|
230
|
-
return input;
|
|
231
|
-
} catch {
|
|
232
|
-
if (this._warnedTimeZones && !this._warnedTimeZones.has(input)) {
|
|
233
|
-
this._warnedTimeZones.add(input);
|
|
234
|
-
console.warn(
|
|
235
|
-
`auro-datetime: "${input}" is not a valid IANA timezone. Falling back to viewer-local.`,
|
|
236
|
-
);
|
|
237
|
-
}
|
|
238
|
-
return undefined;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
connectedCallback() {
|
|
243
|
-
super.connectedCallback();
|
|
244
|
-
|
|
245
|
-
this.dateTemplate = {
|
|
246
|
-
weekday: this.weekday,
|
|
247
|
-
year: "numeric",
|
|
248
|
-
month: this.month,
|
|
249
|
-
day: "numeric",
|
|
250
|
-
};
|
|
251
|
-
|
|
252
|
-
this.timeTemplate = {
|
|
253
|
-
hour: "2-digit",
|
|
254
|
-
minute: "2-digit",
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
// function to define props used within the scope of this component
|
|
259
|
-
static get properties() {
|
|
260
|
-
return {
|
|
261
|
-
// ...super.properties,
|
|
262
|
-
|
|
263
|
-
/**
|
|
264
|
-
* BCP 47 language tag for locale-aware date/time formatting (e.g. 'en-GB', 'de-DE', 'ja-JP').
|
|
265
|
-
* @type {string}
|
|
266
|
-
* @default 'en-US'
|
|
267
|
-
*/
|
|
268
|
-
locale: { type: String },
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* Defines format of month
|
|
272
|
-
* @type {'short' | 'long'}
|
|
273
|
-
* @default 'short'
|
|
274
|
-
*/
|
|
275
|
-
month: { type: String },
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* Pass in string to define [timezone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
|
|
279
|
-
* When set, the moment described by `value` is converted into this IANA zone for display.
|
|
280
|
-
* When unset, the wall-clock time from the input string is rendered as-is.
|
|
281
|
-
*/
|
|
282
|
-
timezone: { type: String },
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
* Defines type of data to render
|
|
286
|
-
* @type {'date' | 'time' | 'year' | 'month' | 'weekday' | 'day' | 'numeric'}
|
|
287
|
-
*/
|
|
288
|
-
type: { type: String },
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* ISO 8601 date or date-time string. Examples:
|
|
292
|
-
* - `2022-07-14T08:00:00-07:00` (with offset)
|
|
293
|
-
* - `2022-07-14T08:00:00Z` (UTC)
|
|
294
|
-
* - `2022-07-14T08:00:00` (no offset)
|
|
295
|
-
* - `2022-07-14` (date only)
|
|
296
|
-
*
|
|
297
|
-
* When omitted, the component renders today's date.
|
|
298
|
-
* Invalid input is logged as a warning and renders nothing.
|
|
299
|
-
*/
|
|
300
|
-
value: { type: String },
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* Defines format of weekday
|
|
304
|
-
* @type {'short' | 'long'}
|
|
305
|
-
* @default 'short'
|
|
306
|
-
*/
|
|
307
|
-
weekday: { type: String },
|
|
308
|
-
};
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
/**
|
|
312
|
-
* This will register this element with the browser.
|
|
313
|
-
* @param {string} [name="auro-datetime"] - The name of the element that you want to register.
|
|
314
|
-
*
|
|
315
|
-
* @example
|
|
316
|
-
* AuroDatetime.register("custom-datetime") // this will register this element to <custom-datetime/>
|
|
317
|
-
*
|
|
318
|
-
*/
|
|
319
|
-
static register(name = "auro-datetime") {
|
|
320
|
-
AuroLibraryRuntimeUtils.prototype.registerComponent(name, AuroDatetime);
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
willUpdate(changedProperties) {
|
|
324
|
-
if (changedProperties.has("locale")) {
|
|
325
|
-
this._effectiveLocale = this._resolveLocale(this.locale);
|
|
326
|
-
}
|
|
327
|
-
if (changedProperties.has("timezone")) {
|
|
328
|
-
this._effectiveTimeZone = this._resolveTimeZone(this.timezone);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
firstUpdated() {
|
|
333
|
-
// Add the tag name as an attribute if it is different than the component name
|
|
334
|
-
this.runtimeUtils.handleComponentTagRename(this, "auro-datetime");
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
/**
|
|
338
|
-
* Construct a UTC Date that, when displayed in the given IANA timezone,
|
|
339
|
-
* shows the supplied wall-clock components. Used when `value` has no
|
|
340
|
-
* offset but `timeZone` is set — the wall-clock is interpreted as being
|
|
341
|
-
* in the target zone rather than the viewer's local zone.
|
|
342
|
-
*
|
|
343
|
-
* Algorithm: parse the wall-clock as if it were UTC (a "naive" Date),
|
|
344
|
-
* ask Intl what that moment looks like in the target zone, and use the
|
|
345
|
-
* delta between the two to recover the true UTC moment.
|
|
346
|
-
*
|
|
347
|
-
* @private
|
|
348
|
-
* @param {string} localISO - ISO string with no offset, e.g. "2022-07-14T08:00:00".
|
|
349
|
-
* @param {string} timeZone - IANA zone, e.g. "US/Eastern".
|
|
350
|
-
* @returns {Date}
|
|
351
|
-
*/
|
|
352
|
-
_zonedWallClockToUtc(localISO, timeZone) {
|
|
353
|
-
const naiveUtc = new Date(`${localISO}Z`);
|
|
354
|
-
const parts = new Intl.DateTimeFormat("en-US", {
|
|
355
|
-
timeZone,
|
|
356
|
-
hourCycle: "h23",
|
|
357
|
-
year: "numeric",
|
|
358
|
-
month: "2-digit",
|
|
359
|
-
day: "2-digit",
|
|
360
|
-
hour: "2-digit",
|
|
361
|
-
minute: "2-digit",
|
|
362
|
-
second: "2-digit",
|
|
363
|
-
}).formatToParts(naiveUtc);
|
|
364
|
-
const lookup = Object.fromEntries(
|
|
365
|
-
parts.filter((p) => p.type !== "literal").map((p) => [p.type, p.value]),
|
|
366
|
-
);
|
|
367
|
-
const seenInZone = new Date(
|
|
368
|
-
`${lookup.year}-${lookup.month}-${lookup.day}T${lookup.hour}:${lookup.minute}:${lookup.second}Z`,
|
|
369
|
-
);
|
|
370
|
-
const offsetMs = naiveUtc.getTime() - seenInZone.getTime();
|
|
371
|
-
return new Date(naiveUtc.getTime() + offsetMs);
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
/**
|
|
375
|
-
* Resolve the `value` and `timezone` attributes into a Date and an optional
|
|
376
|
-
* timeZone option for `Intl.DateTimeFormat`.
|
|
377
|
-
*
|
|
378
|
-
* Behavior:
|
|
379
|
-
* - `value` omitted (null/undefined): returns today's date. `timezone`
|
|
380
|
-
* (if any) is honored.
|
|
381
|
-
* - `value` invalid (including empty string ""): warns and returns
|
|
382
|
-
* `{ date: null }`. Empty is *not* the same as omitted — Lit reflects
|
|
383
|
-
* `value=""` as the empty string, which is not a valid ISO 8601
|
|
384
|
-
* form, so we surface it as a typo rather than silently rendering
|
|
385
|
-
* today's date.
|
|
386
|
-
* - `timezone` set + input has offset/Z: parses as an absolute moment
|
|
387
|
-
* (offset honored) and asks `toLocaleString` to convert into the target zone.
|
|
388
|
-
* - `timezone` set + input has no offset: interprets the wall-clock as
|
|
389
|
-
* being in the target zone, so display in that zone matches the input
|
|
390
|
-
* verbatim. This is viewer-independent.
|
|
391
|
-
* - Default (no `timezone`): strips the offset/Z from the input and treats
|
|
392
|
-
* the remaining wall-clock components as local time, so they render verbatim.
|
|
393
|
-
*
|
|
394
|
-
* @private
|
|
395
|
-
* @returns {{ date: Date | null, timeZoneOption: string | undefined }}
|
|
396
|
-
*/
|
|
397
|
-
_resolveInputDate() {
|
|
398
|
-
const resolvedTz = this._effectiveTimeZone;
|
|
399
|
-
|
|
400
|
-
// Only true "omitted" inputs (null/undefined) get the today's-date
|
|
401
|
-
// treatment. Empty string falls through to ISO validation, which will
|
|
402
|
-
// fail and produce the documented warn + empty render.
|
|
403
|
-
if (this.value == null) {
|
|
404
|
-
return { date: new Date(), timeZoneOption: resolvedTz };
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
const match = this.value.match(ISO_8601_REGEX);
|
|
408
|
-
if (!match) {
|
|
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
|
-
}
|
|
415
|
-
return { date: null, timeZoneOption: undefined };
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
const localPart = match[1];
|
|
419
|
-
const hasOffset = Boolean(match[2]);
|
|
420
|
-
|
|
421
|
-
// The regex permits an offset/Z suffix on a bare date (e.g. "2020-09-22Z"
|
|
422
|
-
// or "2020-09-22-07:00"). Those forms are not valid ISO 8601 — an offset
|
|
423
|
-
// is only meaningful with a time component — and the wall-clock branch
|
|
424
|
-
// would silently drop the offset, producing surprising output. Reject
|
|
425
|
-
// them up front so the consumer sees a warning.
|
|
426
|
-
if (hasOffset && !localPart.includes("T")) {
|
|
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
|
-
}
|
|
433
|
-
return { date: null, timeZoneOption: undefined };
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
const normalized = localPart.includes("T")
|
|
437
|
-
? localPart
|
|
438
|
-
: `${localPart}T00:00:00`;
|
|
439
|
-
|
|
440
|
-
// The regex only validates string shape, not value ranges — "2022-99-99"
|
|
441
|
-
// matches but produces an Invalid Date. Detect that and treat it like
|
|
442
|
-
// any other malformed input so render falls back to the documented
|
|
443
|
-
// empty output instead of "Invalid Date" or a thrown RangeError from
|
|
444
|
-
// downstream Intl calls.
|
|
445
|
-
const buildDate = () => {
|
|
446
|
-
if (resolvedTz && !hasOffset) {
|
|
447
|
-
return this._zonedWallClockToUtc(normalized, resolvedTz);
|
|
448
|
-
}
|
|
449
|
-
if (resolvedTz && hasOffset) {
|
|
450
|
-
return new Date(this.value);
|
|
451
|
-
}
|
|
452
|
-
// Wall-clock: keep the components in the input verbatim. JS parses
|
|
453
|
-
// bare "YYYY-MM-DD" as UTC midnight, which shifts the date in the
|
|
454
|
-
// viewer's timezone; appending a time forces local-time parsing.
|
|
455
|
-
return new Date(normalized);
|
|
456
|
-
};
|
|
457
|
-
|
|
458
|
-
const date = buildDate();
|
|
459
|
-
if (Number.isNaN(date.getTime())) {
|
|
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
|
-
}
|
|
466
|
-
return { date: null, timeZoneOption: undefined };
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
return { date, timeZoneOption: resolvedTz };
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
/**
|
|
473
|
-
* Internal function to generate full date string.
|
|
474
|
-
* @private
|
|
475
|
-
* @returns {string} - Date string.
|
|
476
|
-
*/
|
|
477
|
-
humanDate() {
|
|
478
|
-
const { date, timeZoneOption } = this._resolveInputDate();
|
|
479
|
-
if (!date) {
|
|
480
|
-
return "";
|
|
481
|
-
}
|
|
482
|
-
const template = { ...this.dateTemplate };
|
|
483
|
-
if (timeZoneOption) {
|
|
484
|
-
template.timeZone = timeZoneOption;
|
|
485
|
-
}
|
|
486
|
-
return date.toLocaleString(this._effectiveLocale, template);
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
/**
|
|
490
|
-
* Internal function to format a single date part (year/month/weekday/day).
|
|
491
|
-
* @private
|
|
492
|
-
* @returns {string} - Date string.
|
|
493
|
-
*/
|
|
494
|
-
humanDateConversion() {
|
|
495
|
-
const { date, timeZoneOption } = this._resolveInputDate();
|
|
496
|
-
if (!date) {
|
|
497
|
-
return "";
|
|
498
|
-
}
|
|
499
|
-
const template = {};
|
|
500
|
-
if (timeZoneOption) {
|
|
501
|
-
template.timeZone = timeZoneOption;
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
switch (this.type) {
|
|
505
|
-
case "day":
|
|
506
|
-
template.day = "numeric";
|
|
507
|
-
break;
|
|
508
|
-
case "month":
|
|
509
|
-
template.month = this.month;
|
|
510
|
-
break;
|
|
511
|
-
case "year":
|
|
512
|
-
template.year = "numeric";
|
|
513
|
-
break;
|
|
514
|
-
case "weekday":
|
|
515
|
-
template.weekday = this.weekday;
|
|
516
|
-
break;
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
return date.toLocaleString(this._effectiveLocale, template);
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
/**
|
|
523
|
-
* Internal function to generate numeric date string MM/DD/YYYY.
|
|
524
|
-
* @private
|
|
525
|
-
* @returns {string} - Date string.
|
|
526
|
-
*/
|
|
527
|
-
numericDate() {
|
|
528
|
-
const { date, timeZoneOption } = this._resolveInputDate();
|
|
529
|
-
if (!date) {
|
|
530
|
-
return "";
|
|
531
|
-
}
|
|
532
|
-
const template = { ...this.dateTemplate, month: "numeric" };
|
|
533
|
-
Reflect.deleteProperty(template, "weekday");
|
|
534
|
-
if (timeZoneOption) {
|
|
535
|
-
template.timeZone = timeZoneOption;
|
|
536
|
-
}
|
|
537
|
-
return date.toLocaleString(this._effectiveLocale, template);
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
/**
|
|
541
|
-
* Internal function to generate standard time string.
|
|
542
|
-
* @private
|
|
543
|
-
* @returns {string} - Time string.
|
|
544
|
-
*/
|
|
545
|
-
humanTime() {
|
|
546
|
-
const { date, timeZoneOption } = this._resolveInputDate();
|
|
547
|
-
if (!date) {
|
|
548
|
-
return "";
|
|
549
|
-
}
|
|
550
|
-
const template = { ...this.timeTemplate };
|
|
551
|
-
if (timeZoneOption) {
|
|
552
|
-
template.timeZone = timeZoneOption;
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
const formatted = date.toLocaleString(this._effectiveLocale, template);
|
|
556
|
-
|
|
557
|
-
// Detect a 12-hour rendered output by the presence of a Latin-script
|
|
558
|
-
// period marker. The pattern matches `am`, `pm`, `a.m.`, `p.m.`
|
|
559
|
-
// (case-insensitive), so it catches en-US (`PM`), en-AU/hi-IN (`pm`),
|
|
560
|
-
// and en-CA/es-MX (`p.m.`) alike. Non-Latin period markers (ko `오후`,
|
|
561
|
-
// ar `م`, zh-TW `下午`) have no ASCII a/p+m chars and correctly fall
|
|
562
|
-
// through unchanged. 24h locales (en-GB, de-DE, fr-FR, ja-JP …) also
|
|
563
|
-
// fall through, preserving their leading zeros.
|
|
564
|
-
if (!/[ap]\.?m\.?/iu.test(formatted)) {
|
|
565
|
-
return formatted;
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
return formatted.replace(/^0+/u, "").toLowerCase();
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
/**
|
|
572
|
-
* Internal function UI decision.
|
|
573
|
-
* @private
|
|
574
|
-
* @returns {string} - String determined by `type` (or full date if no type set).
|
|
575
|
-
*/
|
|
576
|
-
whichDate() {
|
|
577
|
-
switch (this.type) {
|
|
578
|
-
case "date":
|
|
579
|
-
return this.humanDate();
|
|
580
|
-
case "time":
|
|
581
|
-
return this.humanTime();
|
|
582
|
-
case "year":
|
|
583
|
-
case "month":
|
|
584
|
-
case "weekday":
|
|
585
|
-
case "day":
|
|
586
|
-
return this.humanDateConversion();
|
|
587
|
-
case "numeric":
|
|
588
|
-
return this.numericDate();
|
|
589
|
-
default:
|
|
590
|
-
return this.humanDate();
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
// When using auroElement, use the following attribute and function when hiding content from screen readers.
|
|
595
|
-
// aria-hidden="${this.hideAudible(this.hiddenAudible)}"
|
|
596
|
-
|
|
597
|
-
// function that renders the HTML and CSS into the scope of the component
|
|
598
|
-
render() {
|
|
599
|
-
return b`
|
|
600
|
-
<slot name="pre"></slot>
|
|
601
|
-
<span class="yield">${this.whichDate()}</span>
|
|
602
|
-
<slot name="post"></slot>
|
|
603
|
-
<slot></slot>
|
|
604
|
-
`;
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
export { AuroDatetime as A };
|