@aurodesignsystem/auro-hyperlink
Version:
auro-hyperlink HTML custom element
941 lines (812 loc) • 219 kB
JavaScript
/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const t$2=globalThis,e$5=t$2.ShadowRoot&&(void 0===t$2.ShadyCSS||t$2.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,s$4=Symbol(),o$7=new WeakMap;let n$5 = class n{constructor(t,e,o){if(this._$cssResult$=true,o!==s$4)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$5&&void 0===t){const e=void 0!==s&&1===s.length;e&&(t=o$7.get(s)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),e&&o$7.set(s,t));}return t}toString(){return this.cssText}};const r$3=t=>new n$5("string"==typeof t?t:t+"",void 0,s$4),i$5=(t,...e)=>{const o=1===t.length?t[0]:e.reduce(((e,s,o)=>e+(t=>{if(true===t._$cssResult$)return t.cssText;if("number"==typeof t)return t;throw Error("Value passed to 'css' function must be a 'css' function result: "+t+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(s)+t[o+1]),t[0]);return new n$5(o,t,s$4)},S$1=(s,o)=>{if(e$5)s.adoptedStyleSheets=o.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet));else for(const e of o){const o=document.createElement("style"),n=t$2.litNonce;void 0!==n&&o.setAttribute("nonce",n),o.textContent=e.cssText,s.appendChild(o);}},c$3=e$5?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const s of t.cssRules)e+=s.cssText;return r$3(e)})(t):t;
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/const{is:i$4,defineProperty:e$4,getOwnPropertyDescriptor:h$3,getOwnPropertyNames:r$2,getOwnPropertySymbols:o$6,getPrototypeOf:n$4}=Object,a$2=globalThis,c$2=a$2.trustedTypes,l$2=c$2?c$2.emptyScript:"",p$1=a$2.reactiveElementPolyfillSupport,d$1=(t,s)=>t,u$2={toAttribute(t,s){switch(s){case Boolean:t=t?l$2: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$3=(t,s)=>!i$4(t,s),b={attribute:true,type:String,converter:u$2,reflect:false,useDefault:false,hasChanged:f$3};Symbol.metadata??=Symbol("metadata"),a$2.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$4(this.prototype,t,h);}}static getPropertyDescriptor(t,s,i){const{get:e,set:r}=h$3(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$4(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$2(t),...o$6(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$3(s));}else void 0!==s&&i.push(c$3(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$2).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$2;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$3)(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$2.reactiveElementVersions??=[]).push("2.1.0");
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const t$1=globalThis,i$3=t$1.trustedTypes,s$3=i$3?i$3.createPolicy("lit-html",{createHTML:t=>t}):void 0,e$3="$lit$",h$2=`lit$${Math.random().toFixed(9).slice(2)}$`,o$5="?"+h$2,n$3=`<${o$5}>`,r$1=document,l$1=()=>r$1.createComment(""),c$1=t=>null===t||"object"!=typeof t&&"function"!=typeof t,a$1=Array.isArray,u$1=t=>a$1(t)||"function"==typeof t?.[Symbol.iterator],d="[ \t\n\f\r]",f$2=/<(?:(!--|\/[^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$1.createTreeWalker(r$1,129);function P(t,i){if(!a$1(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==s$3?s$3.createHTML(i):i}const V=(t,i)=>{const s=t.length-1,o=[];let r,l=2===i?"<svg>":3===i?"<math>":"",c=f$2;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$2?"!--"===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$2,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$2:(c=m,r=void 0);const x=c===m&&t[i+1].startsWith("/>")?" ":"";l+=c===f$2?s+n$3:d>=0?(o.push(a),s.slice(0,d)+e$3+s.slice(d)+h$2+x):s+h$2+(-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$3)){const i=v[a++],s=r.getAttribute(t).split(h$2),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$2)&&(d.push({type:6,index:c}),r.removeAttribute(t));if($.test(r.tagName)){const t=r.textContent.split(h$2),s=t.length-1;if(s>0){r.textContent=i$3?i$3.emptyScript:"";for(let i=0;i<s;i++)r.append(t[i],l$1()),C.nextNode(),d.push({type:2,index:++c});r.append(t[s],l$1());}}}else if(8===r.nodeType)if(r.data===o$5)d.push({type:2,index:c});else {let t=-1;for(;-1!==(t=r.data.indexOf(h$2,t+1));)d.push({type:7,index:c}),t+=h$2.length-1;}c++;}}static createElement(t,i){const s=r$1.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$1(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$1).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$1,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$1(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$1(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$1(this._$AH)?this._$AA.nextSibling.data=t:this.T(r$1.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$1(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$1()),this.O(l$1()),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$1(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$1(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$1.litHtmlPolyfillSupport;j?.(N,R),(t$1.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$1(),t),t,void 0,s??{});}return h._$AI(t),h};
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/const s$2=globalThis;let i$2 = 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$2._$litElement$=true,i$2["finalized"]=true,s$2.litElementHydrateSupport?.({LitElement:i$2});const o$4=s$2.litElementPolyfillSupport;o$4?.({LitElement:i$2});(s$2.litElementVersions??=[]).push("4.2.0");
/**
* @license
* Copyright 2020 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const a=Symbol.for(""),o$3=t=>{if(t?.r===a)return t?._$litStatic$},s$1=t=>({_$litStatic$:t,r:a}),i$1=(t,...r)=>({_$litStatic$:r.reduce(((r,e,a)=>r+(t=>{if(void 0!==t._$litStatic$)return t._$litStatic$;throw Error(`Value passed to 'literal' function must be a 'literal' result: ${t}. Use 'unsafeStatic' to pass non-literal values, but\n take care to ensure page security.`)})(e)+t[a+1]),t[0]),r:a}),l=new Map,n$2=t=>(r,...e)=>{const a=e.length;let s,i;const n=[],u=[];let c,$=0,f=false;for(;$<a;){for(c=r[$];$<a&&void 0!==(i=e[$],s=o$3(i));)c+=s+r[++$],f=true;$!==a&&u.push(i),n.push(c),$++;}if($===a&&n.push(r[a]),f){const t=n.join("$$lit$$");void 0===(r=l.get(t))&&(n.raw=n,l.set(t,r=n)),e=u;}return t(r,...e)},u=n$2(x);
/**
* @license
* Copyright 2020 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/const f$1=o=>void 0===o.strings;
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const t={ATTRIBUTE:1,CHILD:2},e$2=t=>(...e)=>({_$litDirective$:t,values:e});class i{constructor(t){}get _$AU(){return this._$AM._$AU}_$AT(t,e,i){this._$Ct=t,this._$AM=e,this._$Ci=i;}_$AS(t,e){return this.update(t,e)}update(t,e){return this.render(...e)}}
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/const s=(i,t)=>{const e=i._$AN;if(void 0===e)return false;for(const i of e)i._$AO?.(t,false),s(i,t);return true},o$2=i=>{let t,e;do{if(void 0===(t=i._$AM))break;e=t._$AN,e.delete(i),i=t;}while(0===e?.size)},r=i=>{for(let t;t=i._$AM;i=t){let e=t._$AN;if(void 0===e)t._$AN=e=new Set;else if(e.has(i))break;e.add(i),c(t);}};function h$1(i){ void 0!==this._$AN?(o$2(this),this._$AM=i,r(this)):this._$AM=i;}function n$1(i,t=false,e=0){const r=this._$AH,h=this._$AN;if(void 0!==h&&0!==h.size)if(t)if(Array.isArray(r))for(let i=e;i<r.length;i++)s(r[i],false),o$2(r[i]);else null!=r&&(s(r,false),o$2(r));else s(this,i);}const c=i=>{i.type==t.CHILD&&(i._$AP??=n$1,i._$AQ??=h$1);};class f extends i{constructor(){super(...arguments),this._$AN=void 0;}_$AT(i,t,e){super._$AT(i,t,e),r(this),this.isConnected=i._$AU;}_$AO(i,t=true){i!==this.isConnected&&(this.isConnected=i,i?this.reconnected?.():this.disconnected?.()),t&&(s(this,i),o$2(this));}setValue(t){if(f$1(this._$Ct))this._$Ct._$AI(t,this);else {const i=[...this._$Ct._$AH];i[this._$Ci]=t,this._$Ct._$AI(i,this,0);}}disconnected(){}reconnected(){}}
/**
* @license
* Copyright 2020 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/const e$1=()=>new h;class h{}const o$1=new WeakMap,n=e$2(class extends f{render(i){return E}update(i,[s]){const e=s!==this.G;return e&&void 0!==this.G&&this.rt(void 0),(e||this.lt!==this.ct)&&(this.G=s,this.ht=i.options?.host,this.rt(this.ct=i.element)),E}rt(t){if(this.isConnected||(t=void 0),"function"==typeof this.G){const i=this.ht??globalThis;let s=o$1.get(i);void 0===s&&(s=new WeakMap,o$1.set(i,s)),void 0!==s.get(this.G)&&this.G.call(this.ht,void 0),s.set(this.G,t),void 0!==t&&this.G.call(this.ht,t);}else this.G.value=t;}get lt(){return "function"==typeof this.G?o$1.get(this.ht??globalThis)?.get(this.G):this.G?.value}disconnected(){this.lt===this.ct&&this.rt(void 0);}reconnected(){this.rt(this.ct);}});
/**
* @license
* Copyright 2018 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/const o=o=>o??E;
/**
* @license
* Copyright 2018 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/const e=e$2(class extends i{constructor(t$1){if(super(t$1),t$1.type!==t.ATTRIBUTE||"class"!==t$1.name||t$1.strings?.length>2)throw Error("`classMap()` can only be used in the `class` attribute and must be the only part in the attribute.")}render(t){return " "+Object.keys(t).filter((s=>t[s])).join(" ")+" "}update(s,[i]){if(void 0===this.st){this.st=new Set,void 0!==s.strings&&(this.nt=new Set(s.strings.join(" ").split(/\s/).filter((t=>""!==t))));for(const t in i)i[t]&&!this.nt?.has(t)&&this.st.add(t);return this.render(i)}const r=s.element.classList;for(const t of this.st)t in i||(r.remove(t),this.st.delete(t));for(const t in i){const s=!!i[t];s===this.st.has(t)||this.nt?.has(t)||(s?(r.add(t),this.st.add(t)):(r.remove(t),this.st.delete(t)));}return T}});
let AuroElement$2 = class AuroElement extends i$2 {
static get properties() {
return {
/**
* Defines the language of an element.
* @default {'default'}
*/
layout: {
type: String,
attribute: "layout",
reflect: true
},
shape: {
type: String,
attribute: "shape",
reflect: true
},
size: {
type: String,
attribute: "size",
reflect: true
},
onDark: {
type: Boolean,
attribute: "ondark",
reflect: true
}
};
}
};
// Copyright (c) Alaska Air. All right reserved. Licensed under the Apache-2.0 license
// See LICENSE in the project root for license information.
// ---------------------------------------------------------------------
/* eslint-disable line-comment-position, no-inline-comments, no-confusing-arrow, no-nested-ternary, implicit-arrow-linebreak */
class AuroLibraryRuntimeUtils {
/* eslint-disable jsdoc/require-param */
/**
* This will register a new custom element with the browser.
* @param {String} name - The name of the custom element.
* @param {Object} componentClass - The class to register as a custom element.
* @returns {void}
*/
registerComponent(name, componentClass) {
if (!customElements.get(name)) {
customElements.define(name, class extends componentClass {});
}
}
/**
* Finds and returns the closest HTML Element based on a selector.
* @returns {void}
*/
closestElement(
selector, // selector like in .closest()
base = this, // extra functionality to skip a parent
__Closest = (el, found = el && el.closest(selector)) =>
!el || el === document || el === window
? null // standard .closest() returns null for non-found selectors also
: found
? found // found a selector INside this element
: __Closest(el.getRootNode().host) // recursion!! break out to parent DOM
) {
return __Closest(base);
}
/* eslint-enable jsdoc/require-param */
/**
* 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.
* @param {Object} elem - The element to check.
* @param {String} tagName - The name of the Auro component to check for or add as an attribute.
* @returns {void}
*/
handleComponentTagRename(elem, tagName) {
const tag = tagName.toLowerCase();
const elemTag = elem.tagName.toLowerCase();
if (elemTag !== tag) {
elem.setAttribute(tag, true);
}
}
/**
* Validates if an element is a specific Auro component.
* @param {Object} elem - The element to validate.
* @param {String} tagName - The name of the Auro component to check against.
* @returns {Boolean} - Returns true if the element is the specified Auro component.
*/
elementMatch(elem, tagName) {
const tag = tagName.toLowerCase();
const elemTag = elem.tagName.toLowerCase();
return elemTag === tag || elem.hasAttribute(tag);
}
}
var externalLink = {"svg":"<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" aria-labelledby=\"external-link-stroke__title external-link-stroke__desc\" class=\"ico_squareLarge\" role=\"img\" style=\"min-width:var(--auro-size-lg, var(--ds-size-300, 1.5rem));height:var(--auro-size-lg, var(--ds-size-300, 1.5rem));fill:currentColor\" viewBox=\"0 0 24 24\" part=\"svg\"><title id=\"external-link-stroke__title\">Link to external site.</title><desc id=\"external-link-stroke__desc\">This indicates a link to an external site that may not follow the same accessibility or privacy policies as Alaska Airlines. By selecting a partner link you agree to share your data with these sites.</desc><path d=\"M7 6.25h5a.75.75 0 0 1 .102 1.494L12 7.75H7a1.25 1.25 0 0 0-1.244 1.123L5.75 9v8c0 .648.492 1.18 1.122 1.244L7 18.25h8a1.25 1.25 0 0 0 1.244-1.122L16.25 17v-5a.75.75 0 0 1 1.493-.101l.007.101v5a2.75 2.75 0 0 1-2.582 2.745L15 19.75H7a2.75 2.75 0 0 1-2.745-2.582L4.25 17V9a2.75 2.75 0 0 1 2.582-2.745zh5zm12.025-2 .125.015.11.032.128.061c.18.108.317.29.353.522l.009.12v5a.75.75 0 0 1-1.493.102L18.25 10V6.811l-6.72 6.72a.75.75 0 0 1-1.133-.977l.073-.084 6.718-6.72H14a.75.75 0 0 1-.743-.648L13.25 5a.75.75 0 0 1 .648-.743L14 4.25z\"/></svg>"};
var newWindow = {"svg":"<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" aria-labelledby=\"new-window-stroke__title new-window-stroke__desc\" class=\"ico_squareLarge\" role=\"img\" style=\"min-width:var(--auro-size-lg, var(--ds-size-300, 1.5rem));height:var(--auro-size-lg, var(--ds-size-300, 1.5rem));fill:currentColor\" viewBox=\"0 0 24 24\" part=\"svg\"><title id=\"new-window-stroke__title\">Link will open a new tab or window.</title><desc id=\"new-window-stroke__desc\">Notice indicator to alert users that action will result in the browser opening a new tab or window.</desc><path fill-rule=\"evenodd\" d=\"M20.246 5.687a2.063 2.063 0 0 0-2.058-1.937H8.813l-.126.004A2.063 2.063 0 0 0 6.75 5.813v.937H6.5l-.168.005A2.75 2.75 0 0 0 3.75 9.5v8l.005.168A2.75 2.75 0 0 0 6.5 20.25h8l.168-.005A2.75 2.75 0 0 0 17.25 17.5v-.25h.938l.125-.004a2.063 2.063 0 0 0 1.937-2.058V5.813zM15.75 17.25H8.813a2.063 2.063 0 0 1-2.06-1.937l-.003-.126V8.25H6.5a1.25 1.25 0 0 0-1.244 1.123L5.25 9.5v8c0 .648.492 1.18 1.122 1.244l.128.006h8a1.25 1.25 0 0 0 1.243-1.122l.007-.128zm-6.625-12h8.75l.09.005a.875.875 0 0 1 .785.87v8.75l-.005.09a.875.875 0 0 1-.87.785h-8.75l-.09-.005a.875.875 0 0 1-.785-.87v-8.75l.005-.09a.875.875 0 0 1 .87-.785m4.28 1.757L13.507 7c.38 0 .693.3.743.69l.007.11-.007 1.938h2c.38 0 .694.301.743.691l.007.108c0 .405-.282.74-.648.792l-.102.007h-2.001l.001 1.865c0 .404-.282.739-.648.792L13.5 14c-.38 0-.694-.3-.743-.69l-.007-.11-.001-1.864H10.75c-.38 0-.694-.3-.743-.69L10 10.537c0-.404.282-.738.648-.791l.102-.008h2l.007-1.939c0-.404.282-.739.648-.792\"/></svg>"};
// Copyright (c) Alaska Air. All right reserved. Licensed under the Apache-2.0 license
// See LICENSE in the project root for license information.
// build the component class
class ComponentBase extends AuroElement$2 {
constructor() {
super();
this.download = false;
this.relative = false;
this.ondark = false;
this.variant = 'primary';
/**
* @private
*/
this.layout = this.type === 'cta' ? 'block' : null;
/**
* @private
*/
this.shape = this.type === 'cta' ? 'rounded' : null;
/**
* @private
*/
this.size = this.type === 'cta' ? 'md' : null;
/**
* @private
*/
this.defaultReferrerPolicy = 'strict-origin-when-cross-origin';
/**
* @private
*/
this.ariapressed = 'false';
/**
* @private
*/
this.tabIsActive = 'false';
/**
* @private
*/
this.runtimeUtils = new AuroLibraryRuntimeUtils();
/*
If the component requires a touch detection,
please use this function to determine if a user is
actively touching a device, versus detecting if
the device is touch enables or a handheld device.
Also uncomment the touch detection lib above
*/
this.addEventListener('touchstart', function() {
this.classList.add('is-touching');
});
}
// function to define props used within the scope of this component
static get properties() {
return {
...super.properties,
/**
* Defines the URL of the linked page.
*/
href: {
type: String,
reflect: true
},
/**
* Defines the relationship between the current document and the linked document.
*/
rel: {
type: String,
reflect: true
},
/**
* Defines where to open the linked document.
*/
target: {
type: String,
reflect: true
},
/**
* If true, the linked resource will be downloaded when the hyperlink is clicked.
*/
download: {
type: Boolean,
reflect: true
},
/**
* If true, the auto URL re-write feature will be disabled.
*/
relative: {
type: Boolean,
reflect: true
},
/**
* If true, the hyperlink will be styled for use on a dark background.
*/
ondark: { type: Boolean },
/**
* Defines the type of hyperlink; accepts `nav` or `cta`.
*/
type: {
type: String,
reflect: true
},
/**
* If true and `type="cta"`, the hyperlink will have a fluid-width UI.
*/
fluid: { type: Boolean },
/**
* If true, sets `strict-origin-when-cross-origin` to control the referrer information sent with requests.
*/
referrerpolicy: {
type: Boolean,
reflect: true
},
/**
* Sets button variant option.
* @default primary
*/
variant: {
type: String,
reflect: true
},
};
}
firstUpdated() {
// Add the tag name as an attribute if it is different than the component name
this.runtimeUtils.handleComponentTagRename(this, 'auro-hyperlink');
}
/**
* Returns a safe URI based on the provided `href` and `relative` parameters.
* If `href` is truthy, it generates a safe URL using the `safeUrl` function.
* Otherwise, it returns an empty string.
*
* @example
* // Assuming this.href = 'http://example.com' and this.relative = false
* this.safeUri; // Returns 'http://example.com'
*
* @example
* // Assuming this.href = '' or this.href = null
* this.safeUri; // Returns ''
*
* @returns {string} The safe URI or an empty string.
*/
get safeUri() {
return this.href ? this.safeUrl(this.href, this.relative) : '';
}
/**
* Checks whether the provided URI (if available) includes the 'http' protocol.
* If the URI is truthy, it examines whether it contains 'http'.
* Otherwise, it returns false.
*
* @example
* // Assuming this.href = 'http://example.com'
* this.includesDomain; // Returns true
*
* @example
* // Assuming this.href = '/path/to/file'
* this.includesDomain; // Returns false
*
* @example
* // Assuming this.href = '' or this.href = null
* this.includesDomain; // Returns false
*
* @private
* @returns {boolean} True if the URI includes 'http', false otherwise.
*/
get includesDomain() {
return this.href ? this.safeUri.includes('http') : false;
}
/**
* Generates a safe URL based on the provided `href` and `relative` parameters.
* If `href` is falsy, it returns `undefined`.
*
* @example
* // Assuming href = 'http://example.com' and relative = false
* this.safeUrl(href, relative); // Returns 'https://example.com'
*
* @example
* // Assuming href = '/path/to/file' and relative = true
* this.safeUrl(href, relative); // Returns '/path/to/file'
*
* @example
* // Assuming href = 'javascript:alert("Hello")'
* this.safeUrl(href, relative); // Returns undefined
*
* @private
* @param {string} href - The original URL.
* @param {boolean} relative - Indicates whether the URL is relative.
* @returns {string|undefined} The safe URL or `undefined`.
*/
safeUrl(href, relative) {
if (!href) {
return undefined;
}
const url = new URL(href, 'https://www.alaskaair.com');
switch (url.protocol) {
case 'tel:':
case 'sms:':
case 'mailto:':
return href;
// Specifically want to render NO shadowDOM for the following refs
case 'javascript:':
case 'data:':
case 'vbscript:':
return undefined;
default:
if (!relative) {
url.protocol = 'https:';
return url.href;
} else {
return href.replace(/^[^:]+:/, "");
}
}
}
/**
* Generates an HTML element containing an SVG icon based on the provided `svgContent`.
*
* @example
* // Assuming svgContent = '<svg><path d="..."/></svg>'
* this.generateIconHtml(svgContent); // Returns HTML element containing the SVG icon
*
* @private
* @param {string} svgContent - The SVG content to be embedded.
* @returns {Element} The HTML element containing the SVG icon.
*/
generateIconHtml(svgContent) {
const dom = new DOMParser().parseFromString(svgContent, 'text/html');
const svg = dom.body.firstChild;
svg.setAttribute('slot', 'svg');
return u`<${this.iconTag} customColor customSvg part="targetIcon">${svg}</${this.iconTag}>`;
}
/**
* Generates an icon HTML element based on the target attribute.
*
* @example
* // Assuming target = '_blank' and this.safeUri = 'http://alaskaair.com'
* this.targetIcon(target); // Returns HTML element containing the new window icon
*
* @example
* // Assuming target = '_blank' and this.safeUri = 'http://external.com'
* this.targetIcon(target); // Returns HTML element containing the external link icon
*
* @example
* // Assuming target = '_self' or this.safeUri = '/relative/path'
* this.targetIcon(target); // Returns undefined
*
* @private
* @param {string} target - The target attribute of the anchor element.
* @returns {HTMLElement|undefined} The HTML element containing the icon, or undefined if no icon is generated.
*/
targetIcon(target) {
/**
* Checks if a URL's domain is from the 'alaskaair.com' domain or its subdomains.
* @param {string} url - The URL to check.
* @returns {boolean} Returns true if the URL's domain is 'alaskaair.com' or one of its subdomains, otherwise false.
*/
const isAlaskaAirDomain = (url) => {
const urlObject = new URL(url);
return urlObject.hostname.endsWith('.alaskaair.com');
};
// If target is '_blank' and the URL's domain is 'alaskaair.com' or one of its subdomains, return icon for new window
if (target === '_blank' && isAlaskaAirDomain(this.safeUri)) {
return this.generateIconHtml(newWindow.svg);
} else if (target === '_blank' && !isAlaskaAirDomain(this.safeUri) && this.includesDomain) {
// If target is '_blank' and the URL does not belong to 'alaskaair.com' or its subdomains but contains a domain, return icon for external link
return this.generateIconHtml(externalLink.svg);
}
return undefined;
}
/**
* Returns the state of a tab as a string.
*
* @example
* // Assuming tabIsActive = true
* this.getTabState(tabIsActive); // Returns 'is-active'
*
* @example
* // Assuming tabIsActive = false
* this.getTabState(tabIsActive); // Returns ''
*
* @private
* @param {boolean} tabIsActive - Indicates whether the tab is active.
* @returns {string} 'is-active' if the tab is active, otherwise an empty string.
*/
getTabState(tabIsActive) {
return tabIsActive === true ? "is-active" : '';
}
/**
* Gets the rel attribute value based on target and rel values.
*
* @example
* // Assuming target = '_blank', rel = 'noFollow', and this.safeUri = 'http://alaskaair.com'
* this.getRelType(target, rel); // Returns 'noFollow'
*
* @example
* // Assuming target = '_blank', rel = undefined, this.safeUri = 'http://alaskaair.com', and this.includesDomain = true
* this.getRelType(target, rel); // Returns undefined
*
* @example
* // Assuming target = '_blank', rel = undefined, this.safeUri = 'http://external.com', this.includesDomain = true, and this.referrerpolicy = undefined
* this.getRelType(target, rel); // Returns 'noOpener noReferrer'
*
* @example
* // Assuming target = '_blank', rel = undefined, this.safeUri = 'http://external.com', this.includesDomain = true, and this.referrerpolicy = 'no-referrer'
* this.getRelType(target, rel); // Returns 'external'
*
* @private
* @param {string} target - The target attribute of the anchor element.
* @param {string} rel - The rel attribute of the anchor element.
* @returns {string|undefined} The rel attribute value or undefined if not applicable.
*/
getRelType(target, rel) {
if (rel) {
return rel;
}
if (target === '_blank' && this.safeUri.includes('alaskaair.com')) {
return rel;
}
if (target === '_blank' && this.includesDomain && !this.rel && !this.referrerpolicy) {
return 'noOpener noReferrer';
}
if (target === '_blank' && this.referrerpolicy) {
return 'external';
}
return undefined;
}
/**
* Sets the ARIA pressed state based on user interactions.
*
* @example
* // Assuming ariaPressed = false and user performs a mousedown event
* this.ariaPressedState(ariaPressed); // Returns true
*
* @example
* // Assuming ariaPressed = true and user performs a mouseup event
* this.ariaPressedState(ariaPressed); // Returns false
*
* @example
* // Assuming ariaPressed = false and user performs a keydown event with 'Enter' or 'Space'
* this.ariaPressedState(ariaPressed); // Returns true
*
* @example
* // Assuming ariaPressed = true and user performs a keyup event
* this.ariaPressedState(ariaPressed); // Returns false
*
* @private
* @param {boolean} ariaPressed - The initial value of the ARIA pressed state.
* @returns {boolean} The updated ARIA pressed state.
*/
ariaPressedState(ariaPressed) {
const ariaToggle = function (event) {
const ariaPressedNode = this.shadowRoot.querySelector('[aria-pressed]');
ariaPressedNode.setAttribute("aria-pressed", 'false');
if (event.type === 'mousedown') {
ariaPressedNode.ariaPressed = true;
} else {
ariaPressedNode.ariaPressed = false;
}
if (event.type === 'keydown') {
if (event.code === 'Enter' || event.code === 'Space') {
ariaPressedNode.ariaPressed = true;
} else {
ariaPressedNode.ariaPressed = false;
}
}
};
// Add event listeners
this.addEventListener('mousedown', ariaToggle);
this.addEventListener('mouseup', ariaToggle);
this.addEventListener('keydown', ariaToggle);
this.addEventListener('keyup', ariaToggle);
return ariaPressed;
}
// function renders HTML and CSS into the scope of the component
render() {
return this.getMarkup();
}
}
// Copyright (c) Alaska Air. All right reserved. Licensed under the Apache-2.0 license
// See LICENSE in the project root for license information.
class AuroDependencyVersioning {
/**
* Generates a unique string to be used for child auro element naming.
* @private
* @param {string} baseName - Defines the first part of the unique element name.
* @param {string} version - Version of the component that will be appended to the baseName.
* @returns {string} - Unique string to be used for naming.
*/
generateElementName(baseName, version) {
let result = baseName;
result += '-';
result += version.replace(/[.]/g, '_');
return result;
}
/**
* Generates a unique string to be used for child auro element naming.
* @param {string} baseName - Defines the first part of the unique element name.
* @param {string} version - Version of the component that will be appended to the baseName.
* @returns {string} - Unique string to be used for naming.
*/
generateTag(baseName, version, tagClass) {
const elementName = this.generateElementName(baseName, version);
const tag = i$1`${s$1(elementName)}`;
if (!customElements.get(elementName)) {
customElements.define(elementName, class extends tagClass {});
}
return tag;
}
}
/**
* Private module-level WeakMap to hold MutationObservers for each host element.
*/
const _observers$1 = new WeakMap();
/**
* Private module-level WeakMap to hold attribute matchers and targets for each host element.
* Structure: {
* host: {
* matchers: Set<Function>,
* targets: Map<HTMLElement, Map<Function, {removeOriginal: boolean, currentAttributes: Map<string, string>}>>
* }
* }
*/
const _transportConfig$1 = new WeakMap();
/**
* Transfers all matching attributes from a host element to a target element and observes for future changes.
*
* @param {Object} params - The parameters for the function.
* @param {HTMLElement} params.host - The host element from which attributes will be transported.
* @param {HTMLElement} params.target - The target element to which attributes will be transported.
* @param {boolean} [params.removeOriginal=true] - Whether to remove the attributes from the host element.
* @param {boolean} [params.observe=true] - Whether to attach a MutationObserver to the host element.
* @returns {Function} A function to detach the observer when no longer needed.
* @throws {TypeError} If the host or target parameters are not instances of HTMLElement.
*/
const transportAttributes$1 = ({ host, target, match, removeOriginal = true }) => {
// Guard Clause: Ensure host is valid HTMLElement instance
if (typeof host !== 'object' || !(host instanceof HTMLElement)) {
throw new TypeError('a11yUtilities.js | transportAttributes | The "host" parameter must be an instance of HTMLElement.');
}
// Guard Clause: Ensure target is valid HTMLElement instance
if (typeof target !== 'object' || !(target instanceof HTMLElement)) {
throw new TypeError('a11yUtilities.js | transportAttributes | The "target" parameter must be an instance of HTMLElement.');
}
// Guard Clause: Ensure match is a function
if (typeof match !== 'function') {
throw new TypeError('a11yUtilities.js | transportAttributes | The "match" parameter must be a function.');
}
// Guard Clause: Ensure removeOriginal is a boolean
if (typeof removeOriginal !== 'boolean') {
throw new TypeError('a11yUtilities.js | transportAttributes | The "removeOriginal" parameter must be a boolean.');
}
// Register this transport and get cleanup function
return _registerTransport$1({
host,
target,
matcher: match,
removeOriginal
});
};
/**
* Registers a matcher and target for a host element and attaches an observer if needed.
*
* @param {Object} params - The parameters object.
* @param {HTMLElement} params.host - The host element to observe.
* @param {HTMLElement} params.target - The target element to receive attributes.
* @param {Function} params.matcher - Function that determines which attributes to transport.
* @param {boolean} [params.removeOriginal=true] - Whether to remove original attributes.
* @returns {Function} Function to detach the specific matcher and target pairing.
* @private
*/
const _registerTransport$1 = ({ host, target, matcher, removeOriginal = true }) => {
// Initialize config for this host if it doesn't exist
if (!_transportConfig$1.has(host)) {
_transportConfig$1.set(host, {
matchers: new Set(),
targets: new Map()
});
}
const config = _transportConfig$1.get(host);
// Add the matcher to the set of matchers for this host
config.matchers.add(matcher);
// Initialize target entry if it doesn't exist
if (!config.targets.has(target)) {
config.targets.set(target, new Map());
}
// Store the matcher with its removeOriginal setting for this target
config.targets.get(target).set(matcher, {
removeOriginal,
currentAttributes: new Map()
});
// Perform initial attribute transport
_transportAttributes$1({ host, target, matcher, removeOriginal });
// Attach observer
_attachObserver$1(host);
// Return cleanup function and utility functions
return {
cleanup: () => _cleanupTransport$1(host, target, matcher),
getObservedAttributes: () => _getObservedAttributes$1(host, target, matcher),
getObservedAttribute: (attr) => _getObservedAttribute$1(host, target, matcher, attr),
}
};
/**
* Cleans up resources associated with a specific matcher and target for a host element.
*
* @param {HTMLElement} host - The host element.
* @param {HTMLElement} target - The target element.
* @param {Function} matcher - The matcher function.
* @private
*/
const _cleanupTransport$1 = (host, target, matcher) => {
const config = _transportConfig$1.get(host);
if (!config) return;
// Remove this matcher from this target
const targetMatchers = config.targets.get(target);
if (targetMatchers) {
targetMatchers.delete(matcher);
// If this target has no more matchers, remove it
if (targetMatchers.size === 0) {
config.targets.delete(target);
}
}
// Check if this matcher is still used by any target
let matcherStillUsed = false;
for (const matcherMap of config.targets.values()) {
if (matcherMap.has(matcher)) {
matcherStillUsed = true;
break;
}
}
// If not used anymore, remove from matchers set
if (!matcherStillUsed) {
config.matchers.delete(matcher);
}
// If no more targets or matchers, detach observer
if (config.targets.size === 0 || config.matchers.size === 0) {
_detachObserver$1(host);
}
};
/**
* Generic function to transport attributes from a host element to a target element.
*
* @param {Object} params - The parameters object.
* @param {HTMLElement} params.host - The host element from which to transport attributes.
* @param {HTMLElement} params.target - The target element to which attributes will be transported.
* @param {Function} params.matcher - Function that takes an attribute name and returns true if it should be transported.
* @param {boolean} [params.removeOriginal=true] - Whether to remove original attributes from host.
* @returns {void}
* @private
*/
const _transportAttributes$1 = ({ host, target, matcher, removeOriginal = true }) => {
// Get a list of all matching attributes on the host element and their values
const matchingAttributes = host.getAttributeNames()
.filter(attr => matcher(attr))
.reduce((acc, attr) => {
acc[attr] = host.getAttribute(attr);
return acc;
}, {});
// Move matching attributes to the target element, removing them from the host if removeOriginal is true
Object.entries(matchingAttributes).forEach(([key, value]) => {
_setObservedAttribute$1(host, target, matcher, key, value);
target.setAttribute(key, value);
if (removeOriginal) {
host.removeAttribute(key);
}
});
};
/**
* Attaches a MutationObserver to the host element to monitor attribute changes.
*
* @param {HTMLElement} host - The element to observe for attribute changes.
* @returns {MutationObserver} The observer instance.
* @private
*/
const _attachObserver$1 = (host) => {
// If an observer for this host already exists, return it
if (_observers$1.has(host)) {
return _observers$1.get(host);
}
// Create a new MutationObserver
const observer = new MutationObserver((mutations) => {
const config = _transportConfig$1.get(host);
if (!config) return;
// For each mutation affecting attributes
mutations
.filter(mutation => mutation.type === 'attributes')
.forEach(mutation => {
const attributeName = mutation.attributeName;
// Find matchers that care about this attribute
for (const matcher of config.matchers) {
if (matcher(attributeName)) {
// For each target that uses this matcher
for (const [target, matcherConfigs] of config.targets.entries()) {
if (matcherConfigs.has(matcher)) {
const { removeOriginal } = matcherConfigs.get(matcher);
_transportAttributes$1({
host,
target,
matcher,
removeOriginal
});
}
}
}
}
});
});
// Start observing attribute changes
observer.observe(host, { attributes: true });
// Store the observer
_observers$1.set(host, observer);
return observer;
};
/**
* Detaches and cleans up the MutationObserver for a given host element.
*
* @param {HTMLElement} host - The element whose observer should be detached.
* @private
*/
const _detachObserver$1 = (host) => {
if (_observers$1.has(host)) {
const observer = _observers$1.get(host);
observer.disconnect();
_observers$1.delete(host);
}
// Clean up the transport config as well
if (_transportConfig$1.has(host)) {
_transportConfig$1.delete(host);
}
};
/**
* Gets the matcher configuration for a specific host, target, and matcher.
* @param {HTMLElement} host - The host element.
* @param {HTMLElement} target - The target element.
* @param {Function} matcher - The matcher function.
* @returns {Object|undefined} The matcher configuration if found.
* @private
*/
const _getMatcherConfig$1 = (host, target, matcher) => {
const config = _transportConfig$1.get(host);
if (!config) return undefined;
const targetMatchers = config.targets.get(target);
if (!targetMatchers) return undefined;
return targetMatchers.get(matcher);
};
/**
* Sets an observed attribute value.
* @param {HTMLElement} host - The host element.
* @param {HTMLElement} target - The target element.
* @param {Function} matcher - The matcher function.
* @param {string} key - The attribute name.
* @param {string} value - The attribute value.
* @private
*/
const _setObservedAttribute$1 = (host, target, matcher, key, value) => {
const matcherConfig = _getMatcherConfig$1(host, target, matcher);
if (matcherConfig) {
matcherConfig.currentAttributes.set(key, value);
}
};
const _getObservedAttribute$1 = (host, target, matcher, attr) => {
const matcherConfig = _getMatcherConfig$1(host, target, matcher);
if (matcherConfig) return matcherConfig.currentAttributes.get(attr);
return undefined;
};
const _getObservedAttributes$1 = (host, target, matcher) => {
const matcherConfig = _getMa