@aurodesignsystem-dev/auro-datetime 0.0.0-pr62.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.
@@ -0,0 +1,366 @@
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
+ /**
72
+ * @license
73
+ * Copyright 2019 Google LLC
74
+ * SPDX-License-Identifier: BSD-3-Clause
75
+ */
76
+ 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;
77
+
78
+ /**
79
+ * @license
80
+ * Copyright 2017 Google LLC
81
+ * SPDX-License-Identifier: BSD-3-Clause
82
+ */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={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){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}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,this[e]=h.fromAttribute(s,t.type)??this._$Ej?.get(e)??null,this._$Em=null;}}requestUpdate(t,s,i){if(void 0!==t){const e=this.constructor,h=this[t];if(i??=e.getPropertyOptions(t),!((i.hasChanged??f$1)(h,s)||i.useDefault&&i.reflect&&h===this._$Ej?.get(t)&&!this.hasAttribute(e._$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.0");
83
+
84
+ /**
85
+ * @license
86
+ * Copyright 2017 Google LLC
87
+ * SPDX-License-Identifier: BSD-3-Clause
88
+ */
89
+ const t=globalThis,i$1=t.trustedTypes,s$1=i$1?i$1.createPolicy("lit-html",{createHTML:t=>t}):void 0,e="$lit$",h=`lit$${Math.random().toFixed(9).slice(2)}$`,o$1="?"+h,n=`<${o$1}>`,r=document,l=()=>r.createComment(""),c=t=>null===t||"object"!=typeof t&&"function"!=typeof t,a=Array.isArray,u=t=>a(t)||"function"==typeof t?.[Symbol.iterator],d="[ \t\n\f\r]",f=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,v=/-->/g,_=/>/g,m=RegExp(`>|${d}(?:([^\\s"'>=/]+)(${d}*=${d}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`,"g"),p=/'/g,g=/"/g,$=/^(?:script|style|textarea|title)$/i,y=t=>(i,...s)=>({_$litType$:t,strings:i,values:s}),x=y(1),T=Symbol.for("lit-noChange"),E=Symbol.for("lit-nothing"),A=new WeakMap,C=r.createTreeWalker(r,129);function P(t,i){if(!a(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==s$1?s$1.createHTML(i):i}const V=(t,i)=>{const s=t.length-1,o=[];let r,l=2===i?"<svg>":3===i?"<math>":"",c=f;for(let i=0;i<s;i++){const s=t[i];let a,u,d=-1,y=0;for(;y<s.length&&(c.lastIndex=y,u=c.exec(s),null!==u);)y=c.lastIndex,c===f?"!--"===u[1]?c=v:void 0!==u[1]?c=_:void 0!==u[2]?($.test(u[2])&&(r=RegExp("</"+u[2],"g")),c=m):void 0!==u[3]&&(c=m):c===m?">"===u[0]?(c=r??f,d=-1):void 0===u[1]?d=-2:(d=c.lastIndex-u[2].length,a=u[1],c=void 0===u[3]?m:'"'===u[3]?g:p):c===g||c===p?c=m:c===v||c===_?c=f:(c=m,r=void 0);const x=c===m&&t[i+1].startsWith("/>")?" ":"";l+=c===f?s+n:d>=0?(o.push(a),s.slice(0,d)+e+s.slice(d)+h+x):s+h+(-2===d?i:x);}return [P(t,l+(t[s]||"<?>")+(2===i?"</svg>":3===i?"</math>":"")),o]};class N{constructor({strings:t,_$litType$:s},n){let r;this.parts=[];let c=0,a=0;const u=t.length-1,d=this.parts,[f,v]=V(t,s);if(this.el=N.createElement(f,n),C.currentNode=this.el.content,2===s||3===s){const t=this.el.content.firstChild;t.replaceWith(...t.childNodes);}for(;null!==(r=C.nextNode())&&d.length<u;){if(1===r.nodeType){if(r.hasAttributes())for(const t of r.getAttributeNames())if(t.endsWith(e)){const i=v[a++],s=r.getAttribute(t).split(h),e=/([.?@])?(.*)/.exec(i);d.push({type:1,index:c,name:e[2],strings:s,ctor:"."===e[1]?H:"?"===e[1]?I:"@"===e[1]?L:k}),r.removeAttribute(t);}else t.startsWith(h)&&(d.push({type:6,index:c}),r.removeAttribute(t));if($.test(r.tagName)){const t=r.textContent.split(h),s=t.length-1;if(s>0){r.textContent=i$1?i$1.emptyScript:"";for(let i=0;i<s;i++)r.append(t[i],l()),C.nextNode(),d.push({type:2,index:++c});r.append(t[s],l());}}}else if(8===r.nodeType)if(r.data===o$1)d.push({type:2,index:c});else {let t=-1;for(;-1!==(t=r.data.indexOf(h,t+1));)d.push({type:7,index:c}),t+=h.length-1;}c++;}}static createElement(t,i){const s=r.createElement("template");return s.innerHTML=t,s}}function S(t,i,s=t,e){if(i===T)return i;let h=void 0!==e?s._$Co?.[e]:s._$Cl;const o=c(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=S(t,h._$AS(t,i.values),h,e)),i}class M{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??r).importNode(i,true);C.currentNode=e;let h=C.nextNode(),o=0,n=0,l=s[0];for(;void 0!==l;){if(o===l.index){let i;2===l.type?i=new R(h,h.nextSibling,this,t):1===l.type?i=new l.ctor(h,l.name,l.strings,this,t):6===l.type&&(i=new z(h,this,t)),this._$AV.push(i),l=s[++n];}o!==l?.index&&(h=C.nextNode(),o++);}return C.currentNode=r,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 R{get _$AU(){return this._$AM?._$AU??this._$Cv}constructor(t,i,s,e){this.type=2,this._$AH=E,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=S(this,t,i),c(t)?t===E||null==t||""===t?(this._$AH!==E&&this._$AR(),this._$AH=E):t!==this._$AH&&t!==T&&this._(t):void 0!==t._$litType$?this.$(t):void 0!==t.nodeType?this.T(t):u(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!==E&&c(this._$AH)?this._$AA.nextSibling.data=t:this.T(r.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=N.createElement(P(s.h,s.h[0]),this.options)),s);if(this._$AH?._$AD===e)this._$AH.p(i);else {const t=new M(e,this),s=t.u(this.options);t.p(i),this.T(s),this._$AH=t;}}_$AC(t){let i=A.get(t.strings);return void 0===i&&A.set(t.strings,i=new N(t)),i}k(t){a(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 R(this.O(l()),this.O(l()),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,i){for(this._$AP?.(false,true,i);t&&t!==this._$AB;){const i=t.nextSibling;t.remove(),t=i;}}setConnected(t){ void 0===this._$AM&&(this._$Cv=t,this._$AP?.(t));}}class k{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(t,i,s,e,h){this.type=1,this._$AH=E,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=E;}_$AI(t,i=this,s,e){const h=this.strings;let o=false;if(void 0===h)t=S(this,t,i,0),o=!c(t)||t!==this._$AH&&t!==T,o&&(this._$AH=t);else {const e=t;let n,r;for(t=h[0],n=0;n<h.length-1;n++)r=S(this,e[s+n],i,n),r===T&&(r=this._$AH[n]),o||=!c(r)||r!==this._$AH[n],r===E?t=E:t!==E&&(t+=(r??"")+h[n+1]),this._$AH[n]=r;}o&&!e&&this.j(t);}j(t){t===E?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,t??"");}}class H extends k{constructor(){super(...arguments),this.type=3;}j(t){this.element[this.name]=t===E?void 0:t;}}class I extends k{constructor(){super(...arguments),this.type=4;}j(t){this.element.toggleAttribute(this.name,!!t&&t!==E);}}class L extends k{constructor(t,i,s,e,h){super(t,i,s,e,h),this.type=5;}_$AI(t,i=this){if((t=S(this,t,i,0)??E)===T)return;const s=this._$AH,e=t===E&&s!==E||t.capture!==s.capture||t.once!==s.once||t.passive!==s.passive,h=t!==E&&(s===E||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){S(this,t);}}const j=t.litHtmlPolyfillSupport;j?.(N,R),(t.litHtmlVersions??=[]).push("3.3.0");const B=(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 R(i.insertBefore(l(),t),t,void 0,s??{});}return h._$AI(t),h};
90
+
91
+ /**
92
+ * @license
93
+ * Copyright 2017 Google LLC
94
+ * SPDX-License-Identifier: BSD-3-Clause
95
+ */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=B(r,this.renderRoot,this.renderOptions);}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(true);}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(false);}render(){return T}}i._$litElement$=true,i["finalized"]=true,s.litElementHydrateSupport?.({LitElement:i});const o=s.litElementPolyfillSupport;o?.({LitElement:i});(s.litElementVersions??=[]).push("4.2.0");
96
+
97
+ // Copyright (c) 2020 Alaska Airlines. All right reserved. Licensed under the Apache-2.0 license
98
+ // See LICENSE in the project root for license information.
99
+
100
+
101
+ // If using auroElement base class
102
+ // See instructions for importing auroElement base class https://git.io/JULq4
103
+ // import { html, css } from "lit";
104
+ // import AuroElement from '@aurodesignsystem/orion-web-core-style-sheets/dist/auroElement/auroElement';
105
+
106
+ // See https://git.io/JJ6SJ for "How to document your components using JSDoc"
107
+ /**
108
+ * The auro-datetime custom element is for the purposes of providing an easy to use date and time API.
109
+ *
110
+ * @attr {String} type - Define type of data to render. Options are `[date, time, year, month, weekday, day, numeric, tzDate, tzTime]`
111
+ * @attr {String} utc - Pass in ISO 8601 UTC formatted time code
112
+ * @attr {String} weekday - Display long version of weekday. Option `[long]`
113
+ * @attr {String} month - Display long version of month. Option `[long]`
114
+ * @attr {String} timeZone - Pass in string to define [timeZone](https://docs.trifacta.com/display/DP/Supported+Time+Zone+Values)
115
+ * @attr {String} setDate - Pass in string to set date
116
+ * @attr {Boolean} cap - Capitalize AM or PM designation
117
+ * @slot pre - Content that comes before the `post` content
118
+ * @slot post - Content that comes after the `pre` content
119
+ */
120
+
121
+ // build the component class
122
+ class AuroDatetime extends i {
123
+ constructor() {
124
+ super();
125
+
126
+ this.weekday = "short";
127
+ this.month = "short";
128
+
129
+ /**
130
+ * @private
131
+ */
132
+ this.runtimeUtils = new AuroLibraryRuntimeUtils();
133
+ }
134
+
135
+ connectedCallback() {
136
+ super.connectedCallback();
137
+
138
+ this.dateTemplate = {
139
+ weekday: this.weekday,
140
+ year: "numeric",
141
+ month: this.month,
142
+ day: "numeric",
143
+ };
144
+
145
+ this.timeTemplate = {
146
+ hour: "2-digit",
147
+ minute: "2-digit",
148
+ timeZone: this.timeZone,
149
+ };
150
+
151
+ this.template = {};
152
+ }
153
+
154
+ // function to define props used within the scope of this component
155
+ static get properties() {
156
+ return {
157
+ // ...super.properties,
158
+ type: { type: String },
159
+ utc: { type: String },
160
+ weekday: { type: String },
161
+ month: { type: String },
162
+ timeZone: { type: String },
163
+ setDate: { type: String },
164
+ cap: { type: Boolean },
165
+ };
166
+ }
167
+
168
+ /**
169
+ * This will register this element with the browser.
170
+ * @param {string} [name="auro-datetime"] - The name of element that you want to register to.
171
+ *
172
+ * @example
173
+ * AuroDatetime.register("custom-datetime") // this will register this element to <custom-datetime/>
174
+ *
175
+ */
176
+ static register(name = "auro-datetime") {
177
+ AuroLibraryRuntimeUtils.prototype.registerComponent(name, AuroDatetime);
178
+ }
179
+
180
+ firstUpdated() {
181
+ // Add the tag name as an attribute if it is different than the component name
182
+ this.runtimeUtils.handleComponentTagRename(this, "auro-datetime");
183
+ }
184
+
185
+ /**
186
+ * Internal function generate date string.
187
+ * @private
188
+ * @returns {string} - Date string.
189
+ */
190
+ humanDate() {
191
+ let newDate = new Date();
192
+
193
+ if (this.utc) {
194
+ this.dateTemplate.timeZone = "UTC";
195
+ newDate = new Date(this.utc);
196
+ } else if (this.setDate) {
197
+ newDate = new Date(this.setDate);
198
+ }
199
+
200
+ return newDate.toLocaleString("en-us", this.dateTemplate);
201
+ }
202
+
203
+ /**
204
+ * Internal function to determine new Date object based on input type.
205
+ * @private
206
+ * @returns {string} - Date string.
207
+ */
208
+ humanDateConversion() {
209
+ let newDate = new Date();
210
+
211
+ if (this.utc) {
212
+ this.template.timeZone = "UTC";
213
+ newDate = new Date(this.utc);
214
+ } else if (this.setDate) {
215
+ newDate = new Date(this.setDate);
216
+ }
217
+
218
+ switch (this.type) {
219
+ case "day":
220
+ this.template.day = "numeric";
221
+ break;
222
+ case "month":
223
+ this.template.month = this.month;
224
+ break;
225
+ case "year":
226
+ this.template.year = "numeric";
227
+ break;
228
+ case "weekday":
229
+ this.template.weekday = this.weekday;
230
+ break;
231
+
232
+ default:
233
+ this.template.weekday = this.template;
234
+ }
235
+
236
+ return newDate.toLocaleString("en-us", this.template);
237
+ }
238
+
239
+ /**
240
+ * Internal function generate numeric date string 00/00/0000.
241
+ * @private
242
+ * @returns {string} - Date string.
243
+ */
244
+ numericDate() {
245
+ this.dateTemplate.month = "numeric";
246
+ Reflect.deleteProperty(this.dateTemplate, "weekday");
247
+ let newDate = new Date();
248
+
249
+ if (this.utc) {
250
+ this.dateTemplate.timeZone = "UTC";
251
+ newDate = new Date(this.utc);
252
+ } else if (this.setDate) {
253
+ newDate = new Date(this.setDate);
254
+ }
255
+
256
+ return newDate.toLocaleString("en-us", this.dateTemplate);
257
+ }
258
+
259
+ /**
260
+ * Internal function generate standard time string.
261
+ * @private
262
+ * @returns {string} - Time string.
263
+ */
264
+ humanTime() {
265
+ let newTime = new Date();
266
+
267
+ if (this.utc) {
268
+ this.timeTemplate.timeZone = "UTC";
269
+ newTime = new Date(this.utc);
270
+ } else if (this.setDate) {
271
+ newTime = new Date(this.setDate);
272
+ }
273
+
274
+ if (this.cap) {
275
+ return newTime
276
+ .toLocaleString("en-us", this.timeTemplate)
277
+ .replace(/^0+/u, "");
278
+ }
279
+
280
+ return newTime
281
+ .toLocaleString("en-us", this.timeTemplate)
282
+ .replace(/^0+/u, "")
283
+ .toLowerCase();
284
+ }
285
+
286
+ /**
287
+ * Internal function to generate proper time zone local.
288
+ * @private
289
+ * @returns {string} - Date/Time zone string.
290
+ * @param {string} template - Determines which template model to use.
291
+ */
292
+ tzTime(template) {
293
+ const scrubNumber = -6;
294
+ const scrubTimeZone = this.setDate.slice(0, scrubNumber);
295
+ const newDateTime = new Date(scrubTimeZone);
296
+
297
+ if (this.cap) {
298
+ return newDateTime.toLocaleString("en-us", template).replace(/^0+/u, "");
299
+ }
300
+
301
+ return newDateTime
302
+ .toLocaleString("en-us", template)
303
+ .replace(/^0+/u, "")
304
+ .replace("AM", "am")
305
+ .replace("PM", "pm");
306
+ }
307
+
308
+ /**
309
+ * Internal function UI decision.
310
+ * @private
311
+ * @returns {function} - Function determines which style of date data to show.
312
+ */
313
+ whichDate() {
314
+ let result = "";
315
+
316
+ switch (this.type) {
317
+ case "date":
318
+ result = this.humanDate();
319
+ break;
320
+ case "tzDate":
321
+ result = this.tzTime(this.dateTemplate);
322
+ break;
323
+ case "tzTime":
324
+ result = this.tzTime(this.timeTemplate);
325
+ break;
326
+ case "time":
327
+ result = this.humanTime();
328
+ break;
329
+ case "year":
330
+ case "month":
331
+ case "weekday":
332
+ case "day":
333
+ result = this.humanDateConversion();
334
+ break;
335
+ case "numeric":
336
+ result = this.numericDate();
337
+ break;
338
+ default:
339
+ this.humanDate();
340
+ }
341
+
342
+ if (this.setDate && !this.type) {
343
+ return this.humanDate();
344
+ }
345
+ if (this.utc && !this.type) {
346
+ return this.humanDate();
347
+ }
348
+
349
+ return result;
350
+ }
351
+
352
+ // When using auroElement, use the following attribute and function when hiding content from screen readers.
353
+ // aria-hidden="${this.hideAudible(this.hiddenAudible)}"
354
+
355
+ // function that renders the HTML and CSS into the scope of the component
356
+ render() {
357
+ return x`
358
+ <slot name="pre"></slot>
359
+ <span class="yield">${this.whichDate()}</span>
360
+ <slot name="post"></slot>
361
+ <slot></slot>
362
+ `;
363
+ }
364
+ }
365
+
366
+ export { AuroDatetime as A };
@@ -0,0 +1,56 @@
1
+ <!--
2
+ Copyright (c) Alaska Air. All right reserved. Licensed under the Apache-2.0 license
3
+ See LICENSE in the project root for license information.
4
+
5
+ HTML in this document is standardized and NOT to be edited.
6
+ All demo code should be added/edited in ./demo/index.md
7
+
8
+ With the exception of adding custom elements if needed for the demo.
9
+
10
+ ----------------------- DO NOT EDIT -----------------------------
11
+
12
+ -->
13
+
14
+ <!DOCTYPE html>
15
+ <html lang="en">
16
+ <head>
17
+ <meta charset="UTF-8" />
18
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
19
+ <title>Auro Web Component Demo | auro-datetime</title>
20
+
21
+ <!-- Prism.js Stylesheet -->
22
+ <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/prismjs@1.24.1/themes/prism.css"/>
23
+
24
+ <!-- Legacy reference is still needed to support auro-datetime's use of legacy token values at this time -->
25
+ <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/design-tokens@latest/dist/legacy/auro-classic/CSSCustomProperties.css"/>
26
+
27
+ <!-- Design Token Alaska Theme -->
28
+ <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/design-tokens@latest/dist/themes/alaska/CSSCustomProperties--alaska.min.css"/>
29
+
30
+ <!-- Webcore Stylesheet Alaska Theme -->
31
+ <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/webcorestylesheets@latest/dist/bundled/themes/alaska.global.min.css" />
32
+
33
+ <!-- Demo Specific Styles -->
34
+ <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/webcorestylesheets@latest/dist/demoWrapper.css" />
35
+ <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/webcorestylesheets@latest/dist/elementDemoStyles.css" />
36
+ </head>
37
+ <body class="auro-markdown">
38
+ <main></main>
39
+
40
+ <script type="module">
41
+ import 'https://cdn.jsdelivr.net/npm/marked@latest/marked.min.js';
42
+ import 'https://cdn.jsdelivr.net/npm/prismjs@latest/prism.js';
43
+ fetch('./index.md')
44
+ .then((response) => response.text())
45
+ .then((text) => {
46
+ const rawHtml = marked.parse(text);
47
+ document.querySelector('main').innerHTML = rawHtml;
48
+ Prism.highlightAll();
49
+ });
50
+ </script>
51
+ <script type="module" data-demo-script="true" src="./index.min.js"></script>
52
+
53
+ <!-- If additional elements are needed for the demo, add them here. -->
54
+ <script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-accordion@latest/dist/auro-accordion__bundled.js" type="module"></script>
55
+ </body>
56
+ </html>
package/demo/index.js ADDED
@@ -0,0 +1,5 @@
1
+ /* eslint-disable jsdoc/require-jsdoc, no-magic-numbers, no-param-reassign */
2
+ import { AuroDatetime } from "../src/index";
3
+
4
+ AuroDatetime.register();
5
+ AuroDatetime.register("custom-datetime");
package/demo/index.md ADDED
@@ -0,0 +1,93 @@
1
+ <!--
2
+ The index.md file is a compiled document. No edits should be made directly to this file.
3
+ README.md is created by running `npm run build:docs`.
4
+ This file is generated based on a template fetched from `./docs/partials/index.md`
5
+ -->
6
+
7
+ # Datetime
8
+
9
+ <!-- AURO-GENERATED-CONTENT:START (FILE:src=../docs/partials/description.md) -->
10
+ <!-- The below content is automatically added from ../docs/partials/description.md -->
11
+ The `<auro-datetime>` custom element makes it really easy to add dates to your web app with a simple HTML API.
12
+ <!-- AURO-GENERATED-CONTENT:END -->
13
+
14
+ ## auro-datetime use cases
15
+
16
+ <!-- AURO-GENERATED-CONTENT:START (FILE:src=../docs/partials/useCases.md) -->
17
+ <!-- The below content is automatically added from ../docs/partials/useCases.md -->
18
+ The `<auro-datetime>` element should be used in situations where users may:
19
+
20
+ * A date and/or time is required
21
+ <!-- AURO-GENERATED-CONTENT:END -->
22
+
23
+ ## Example(s)
24
+
25
+ ### Basic Date
26
+
27
+ <div class="exampleWrapper">
28
+ <!-- AURO-GENERATED-CONTENT:START (FILE:src=../apiExamples/basic.html) -->
29
+ <!-- The below content is automatically added from ../apiExamples/basic.html -->
30
+ <auro-datetime type="date"></auro-datetime>
31
+ <!-- AURO-GENERATED-CONTENT:END -->
32
+ </div>
33
+ <auro-accordion alignRight>
34
+ <span slot="trigger">See code</span>
35
+ <!-- AURO-GENERATED-CONTENT:START (CODE:src=../apiExamples/basic.html) -->
36
+ <!-- The below code snippet is automatically added from ../apiExamples/basic.html -->
37
+
38
+ ```html
39
+ <auro-datetime type="date"></auro-datetime>
40
+ ```
41
+ <!-- AURO-GENERATED-CONTENT:END -->
42
+ </auro-accordion>
43
+
44
+ ### Basic Time
45
+
46
+ <div class="exampleWrapper">
47
+ <!-- AURO-GENERATED-CONTENT:START (FILE:src=../apiExamples/basicTime.html) -->
48
+ <!-- The below content is automatically added from ../apiExamples/basicTime.html -->
49
+ <auro-datetime type="time"></auro-datetime>
50
+ <!-- AURO-GENERATED-CONTENT:END -->
51
+ </div>
52
+ <auro-accordion alignRight>
53
+ <span slot="trigger">See code</span>
54
+ <!-- AURO-GENERATED-CONTENT:START (CODE:src=../apiExamples/basicTime.html) -->
55
+ <!-- The below code snippet is automatically added from ../apiExamples/basicTime.html -->
56
+
57
+ ```html
58
+ <auro-datetime type="time"></auro-datetime>
59
+ ```
60
+ <!-- AURO-GENERATED-CONTENT:END -->
61
+ </auro-accordion>
62
+ Having a closing statement about your example helps to really complete the thought with your reader.
63
+
64
+ ## Recommended Use and Version Control
65
+
66
+ There are two important parts of every Auro component. The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes">class</a> and the custom element. The class is exported and then used as part of defining the Web Component. When importing this component as described in the <a href="#install">install</a> section, the class is imported and the `auro-datetime` custom element is defined automatically.
67
+
68
+ To protect from versioning conflicts with other instances of the component being loaded, it is recommended to use our `AuroDatetime.register(name)` method and pass in a unique name.
69
+
70
+ ```js
71
+ import { AuroDatetime } from '@aurodesignsystem/auro-datetime/class';
72
+
73
+ AuroDatetime.register('custom-datetime');
74
+ ```
75
+
76
+ This will create a new custom element that you can use in your HTML that will function identically to the `auro-datetime` element.
77
+
78
+ <div class="exampleWrapper">
79
+ <!-- AURO-GENERATED-CONTENT:START (FILE:src=../apiExamples/custom.html) -->
80
+ <!-- The below content is automatically added from ../apiExamples/custom.html -->
81
+ <custom-datetime type="date"></custom-datetime>
82
+ <!-- AURO-GENERATED-CONTENT:END -->
83
+ </div>
84
+ <auro-accordion alignRight>
85
+ <span slot="trigger">See code</span>
86
+ <!-- AURO-GENERATED-CONTENT:START (CODE:src=../apiExamples/custom.html) -->
87
+ <!-- The below code snippet is automatically added from ../apiExamples/custom.html -->
88
+
89
+ ```html
90
+ <custom-datetime type="date"></custom-datetime>
91
+ ```
92
+ <!-- AURO-GENERATED-CONTENT:END -->
93
+ </auro-accordion>
@@ -0,0 +1,6 @@
1
+ import { A as AuroDatetime } from './auro-datetime.min.js';
2
+
3
+ /* eslint-disable jsdoc/require-jsdoc, no-magic-numbers, no-param-reassign */
4
+
5
+ AuroDatetime.register();
6
+ AuroDatetime.register("custom-datetime");
@@ -0,0 +1,6 @@
1
+ import{LitElement as e,html as t}from"lit";class a{registerComponent(e,t){customElements.get(e)||customElements.define(e,class extends t{})}closestElement(e,t=this,a=(t,s=t&&t.closest(e))=>t&&t!==document&&t!==window?s||a(t.getRootNode().host):null){return a(t)}handleComponentTagRename(e,t){const a=t.toLowerCase();e.tagName.toLowerCase()!==a&&e.setAttribute(a,!0)}elementMatch(e,t){const a=t.toLowerCase();return e.tagName.toLowerCase()===a||e.hasAttribute(a)}}class s extends e{constructor(){super(),this.weekday="short",this.month="short",this.runtimeUtils=new a}connectedCallback(){super.connectedCallback(),this.dateTemplate={weekday:this.weekday,year:"numeric",month:this.month,day:"numeric"},this.timeTemplate={hour:"2-digit",minute:"2-digit",timeZone:this.timeZone},this.template={}}static get properties(){return{type:{type:String},utc:{type:String},weekday:{type:String},month:{type:String},timeZone:{type:String},setDate:{type:String},cap:{type:Boolean}}}static register(e="auro-datetime"){a.prototype.registerComponent(e,s)}firstUpdated(){this.runtimeUtils.handleComponentTagRename(this,"auro-datetime")}humanDate(){let e=new Date;return this.utc?(this.dateTemplate.timeZone="UTC",e=new Date(this.utc)):this.setDate&&(e=new Date(this.setDate)),e.toLocaleString("en-us",this.dateTemplate)}humanDateConversion(){let e=new Date;switch(this.utc?(this.template.timeZone="UTC",e=new Date(this.utc)):this.setDate&&(e=new Date(this.setDate)),this.type){case"day":this.template.day="numeric";break;case"month":this.template.month=this.month;break;case"year":this.template.year="numeric";break;case"weekday":this.template.weekday=this.weekday;break;default:this.template.weekday=this.template}return e.toLocaleString("en-us",this.template)}numericDate(){this.dateTemplate.month="numeric",Reflect.deleteProperty(this.dateTemplate,"weekday");let e=new Date;return this.utc?(this.dateTemplate.timeZone="UTC",e=new Date(this.utc)):this.setDate&&(e=new Date(this.setDate)),e.toLocaleString("en-us",this.dateTemplate)}humanTime(){let e=new Date;return this.utc?(this.timeTemplate.timeZone="UTC",e=new Date(this.utc)):this.setDate&&(e=new Date(this.setDate)),this.cap?e.toLocaleString("en-us",this.timeTemplate).replace(/^0+/u,""):e.toLocaleString("en-us",this.timeTemplate).replace(/^0+/u,"").toLowerCase()}tzTime(e){const t=this.setDate.slice(0,-6),a=new Date(t);return this.cap?a.toLocaleString("en-us",e).replace(/^0+/u,""):a.toLocaleString("en-us",e).replace(/^0+/u,"").replace("AM","am").replace("PM","pm")}whichDate(){let e="";switch(this.type){case"date":e=this.humanDate();break;case"tzDate":e=this.tzTime(this.dateTemplate);break;case"tzTime":e=this.tzTime(this.timeTemplate);break;case"time":e=this.humanTime();break;case"year":case"month":case"weekday":case"day":e=this.humanDateConversion();break;case"numeric":e=this.numericDate();break;default:this.humanDate()}return this.setDate&&!this.type||this.utc&&!this.type?this.humanDate():e}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{s as A};
@@ -0,0 +1,10 @@
1
+ import { LitElement, html } from 'lit';
2
+
3
+ class a{registerComponent(e,t){customElements.get(e)||customElements.define(e,class extends t{});}closestElement(e,t=this,a=(t,s=t&&t.closest(e))=>t&&t!==document&&t!==window?s||a(t.getRootNode().host):null){return a(t)}handleComponentTagRename(e,t){const a=t.toLowerCase();e.tagName.toLowerCase()!==a&&e.setAttribute(a,true);}elementMatch(e,t){const a=t.toLowerCase();return e.tagName.toLowerCase()===a||e.hasAttribute(a)}}class s extends LitElement{constructor(){super(),this.weekday="short",this.month="short",this.runtimeUtils=new a;}connectedCallback(){super.connectedCallback(),this.dateTemplate={weekday:this.weekday,year:"numeric",month:this.month,day:"numeric"},this.timeTemplate={hour:"2-digit",minute:"2-digit",timeZone:this.timeZone},this.template={};}static get properties(){return {type:{type:String},utc:{type:String},weekday:{type:String},month:{type:String},timeZone:{type:String},setDate:{type:String},cap:{type:Boolean}}}static register(e="auro-datetime"){a.prototype.registerComponent(e,s);}firstUpdated(){this.runtimeUtils.handleComponentTagRename(this,"auro-datetime");}humanDate(){let e=new Date;return this.utc?(this.dateTemplate.timeZone="UTC",e=new Date(this.utc)):this.setDate&&(e=new Date(this.setDate)),e.toLocaleString("en-us",this.dateTemplate)}humanDateConversion(){let e=new Date;switch(this.utc?(this.template.timeZone="UTC",e=new Date(this.utc)):this.setDate&&(e=new Date(this.setDate)),this.type){case "day":this.template.day="numeric";break;case "month":this.template.month=this.month;break;case "year":this.template.year="numeric";break;case "weekday":this.template.weekday=this.weekday;break;default:this.template.weekday=this.template;}return e.toLocaleString("en-us",this.template)}numericDate(){this.dateTemplate.month="numeric",Reflect.deleteProperty(this.dateTemplate,"weekday");let e=new Date;return this.utc?(this.dateTemplate.timeZone="UTC",e=new Date(this.utc)):this.setDate&&(e=new Date(this.setDate)),e.toLocaleString("en-us",this.dateTemplate)}humanTime(){let e=new Date;return this.utc?(this.timeTemplate.timeZone="UTC",e=new Date(this.utc)):this.setDate&&(e=new Date(this.setDate)),this.cap?e.toLocaleString("en-us",this.timeTemplate).replace(/^0+/u,""):e.toLocaleString("en-us",this.timeTemplate).replace(/^0+/u,"").toLowerCase()}tzTime(e){const t=this.setDate.slice(0,-6),a=new Date(t);return this.cap?a.toLocaleString("en-us",e).replace(/^0+/u,""):a.toLocaleString("en-us",e).replace(/^0+/u,"").replace("AM","am").replace("PM","pm")}whichDate(){let e="";switch(this.type){case "date":e=this.humanDate();break;case "tzDate":e=this.tzTime(this.dateTemplate);break;case "tzTime":e=this.tzTime(this.timeTemplate);break;case "time":e=this.humanTime();break;case "year":case "month":case "weekday":case "day":e=this.humanDateConversion();break;case "numeric":e=this.numericDate();break;default:this.humanDate();}return this.setDate&&!this.type||this.utc&&!this.type?this.humanDate():e}render(){return html`
4
+ <slot name="pre"></slot>
5
+ <span class="yield">${this.whichDate()}</span>
6
+ <slot name="post"></slot>
7
+ <slot></slot>
8
+ `}}
9
+
10
+ export { s as AuroDatetime };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export{A as AuroDatetime}from"./auro-datetime-CpzZl80P.js";import"lit";
@@ -0,0 +1 @@
1
+ import{A as r}from"./auro-datetime-CpzZl80P.js";import"lit";r.register();