From 35a5f62b88e85a5d191aa7b78ea4c4cebb762b6b Mon Sep 17 00:00:00 2001 From: Graham McMicken Date: Mon, 18 Oct 2021 23:47:31 -0700 Subject: [PATCH 1/8] Add enum values to playlist_type To support additional personalized playlists from spotcast. --- src/types.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/types.ts b/src/types.ts index 58ba4ce..b5746ac 100755 --- a/src/types.ts +++ b/src/types.ts @@ -10,6 +10,10 @@ export enum PlaylistType { default = 'default', featured = 'featured', discover_weekly = 'discover-weekly', + recently_played = 'recently-played', + jump_back_in = 'jump-back-in', + your_top_mixes = 'your-top-mixes[0]', + more_of_what_you_like = 'home-personalized[more-of-what-you-like]', } export enum ConfigEntry { From faf8765e81424b953416639ddd59c916d5940999 Mon Sep 17 00:00:00 2001 From: Graham McMicken Date: Mon, 18 Oct 2021 23:48:37 -0700 Subject: [PATCH 2/8] Add compiled dist/spotify-card.js --- dist/spotify-card.js | 169 +++++++++++++++++++++---------------------- 1 file changed, 84 insertions(+), 85 deletions(-) diff --git a/dist/spotify-card.js b/dist/spotify-card.js index 9b3faa1..0fb0f1c 100644 --- a/dist/spotify-card.js +++ b/dist/spotify-card.js @@ -39,7 +39,7 @@ function e(e,t,i,n){var s,a=arguments.length,o=a<3?t:null===n?n=Object.getOwnPro * subject to an additional IP rights grant found at * http://polymer.github.io/PATENTS.txt */ -const g=new WeakMap,v=e=>"function"==typeof e&&g.has(e),_={},m={}; +const g=new WeakMap,v=e=>"function"==typeof e&&g.has(e),_={},y={}; /** * @license * Copyright (c) 2017 The Polymer Project Authors. All rights reserved. @@ -53,7 +53,7 @@ const g=new WeakMap,v=e=>"function"==typeof e&&g.has(e),_={},m={}; * subject to an additional IP rights grant found at * http://polymer.github.io/PATENTS.txt */ -class f{constructor(e,t,i){this.__parts=[],this.template=e,this.processor=t,this.options=i}update(e){let t=0;for(const i of this.__parts)void 0!==i&&i.setValue(e[t]),t++;for(const e of this.__parts)void 0!==e&&e.commit()}_clone(){const e=t?this.template.element.content.cloneNode(!0):document.importNode(this.template.element.content,!0),i=[],n=this.template.parts,s=document.createTreeWalker(e,133,null,!1);let a,o=0,r=0,c=s.nextNode();for(;o-1||i)&&-1===e.indexOf("--\x3e",o+1);const r=d.exec(e);t+=null===r?e+(i?y:s):e.substr(0,r.index)+r[1]+r[2]+"$lit$"+r[3]+n}return t+=this.strings[e],t}getTemplateElement(){const e=document.createElement("template");return e.innerHTML=this.getHTML(),e}} + */const f=` ${n} `;class w{constructor(e,t,i,n){this.strings=e,this.values=t,this.type=i,this.processor=n}getHTML(){const e=this.strings.length-1;let t="",i=!1;for(let a=0;a-1||i)&&-1===e.indexOf("--\x3e",o+1);const r=d.exec(e);t+=null===r?e+(i?f:s):e.substr(0,r.index)+r[1]+r[2]+"$lit$"+r[3]+n}return t+=this.strings[e],t}getTemplateElement(){const e=document.createElement("template");return e.innerHTML=this.getHTML(),e}} /** * @license * Copyright (c) 2017 The Polymer Project Authors. All rights reserved. @@ -79,7 +79,7 @@ class f{constructor(e,t,i){this.__parts=[],this.template=e,this.processor=t,this * Code distributed by Google as part of the polymer project is also * subject to an additional IP rights grant found at * http://polymer.github.io/PATENTS.txt - */const b=e=>null===e||!("object"==typeof e||"function"==typeof e),S=e=>Array.isArray(e)||!(!e||!e[Symbol.iterator]);class C{constructor(e,t,i){this.dirty=!0,this.element=e,this.name=t,this.strings=i,this.parts=[];for(let e=0;e{try{const e={get capture(){return V=!0,!1}};window.addEventListener("test",e,e),window.removeEventListener("test",e,e)}catch(e){}})();class M{constructor(e,t,i){this.value=void 0,this.__pendingValue=void 0,this.element=e,this.eventName=t,this.eventContext=i,this.__boundHandleEvent=e=>this.handleEvent(e)}setValue(e){this.__pendingValue=e}commit(){for(;v(this.__pendingValue);){const e=this.__pendingValue;this.__pendingValue=_,e(this)}if(this.__pendingValue===_)return;const e=this.__pendingValue,t=this.value,i=null==e||null!=t&&(e.capture!==t.capture||e.once!==t.once||e.passive!==t.passive),n=null!=e&&(null==t||i);i&&this.element.removeEventListener(this.eventName,this.__boundHandleEvent,this.__options),n&&(this.__options=E(e),this.element.addEventListener(this.eventName,this.__boundHandleEvent,this.__options)),this.value=e,this.__pendingValue=_}handleEvent(e){"function"==typeof this.value?this.value.call(this.eventContext||this.element,e):this.value.handleEvent(e)}}const E=e=>e&&(V?{capture:e.capture,passive:e.passive,once:e.once}:e.capture) + */const b=e=>null===e||!("object"==typeof e||"function"==typeof e),S=e=>Array.isArray(e)||!(!e||!e[Symbol.iterator]);class C{constructor(e,t,i){this.dirty=!0,this.element=e,this.name=t,this.strings=i,this.parts=[];for(let e=0;e{try{const e={get capture(){return D=!0,!1}};window.addEventListener("test",e,e),window.removeEventListener("test",e,e)}catch(e){}})();class E{constructor(e,t,i){this.value=void 0,this.__pendingValue=void 0,this.element=e,this.eventName=t,this.eventContext=i,this.__boundHandleEvent=e=>this.handleEvent(e)}setValue(e){this.__pendingValue=e}commit(){for(;v(this.__pendingValue);){const e=this.__pendingValue;this.__pendingValue=_,e(this)}if(this.__pendingValue===_)return;const e=this.__pendingValue,t=this.value,i=null==e||null!=t&&(e.capture!==t.capture||e.once!==t.once||e.passive!==t.passive),n=null!=e&&(null==t||i);i&&this.element.removeEventListener(this.eventName,this.__boundHandleEvent,this.__options),n&&(this.__options=A(e),this.element.addEventListener(this.eventName,this.__boundHandleEvent,this.__options)),this.value=e,this.__pendingValue=_}handleEvent(e){"function"==typeof this.value?this.value.call(this.eventContext||this.element,e):this.value.handleEvent(e)}}const A=e=>e&&(D?{capture:e.capture,passive:e.passive,once:e.once}:e.capture) /** * @license * Copyright (c) 2017 The Polymer Project Authors. All rights reserved. @@ -92,7 +92,7 @@ class f{constructor(e,t,i){this.__parts=[],this.template=e,this.processor=t,this * Code distributed by Google as part of the polymer project is also * subject to an additional IP rights grant found at * http://polymer.github.io/PATENTS.txt - */;function T(e){let t=A.get(e.type);void 0===t&&(t={stringsArray:new WeakMap,keyString:new Map},A.set(e.type,t));let i=t.stringsArray.get(e.strings);if(void 0!==i)return i;const s=e.strings.join(n);return i=t.keyString.get(s),void 0===i&&(i=new o(e,e.getTemplateElement()),t.keyString.set(s,i)),t.stringsArray.set(e.strings,i),i}const A=new Map,N=new WeakMap; + */;function T(e){let t=O.get(e.type);void 0===t&&(t={stringsArray:new WeakMap,keyString:new Map},O.set(e.type,t));let i=t.stringsArray.get(e.strings);if(void 0!==i)return i;const s=e.strings.join(n);return i=t.keyString.get(s),void 0===i&&(i=new o(e,e.getTemplateElement()),t.keyString.set(s,i)),t.stringsArray.set(e.strings,i),i}const O=new Map,N=new WeakMap; /** * @license * Copyright (c) 2017 The Polymer Project Authors. All rights reserved. @@ -105,7 +105,7 @@ class f{constructor(e,t,i){this.__parts=[],this.template=e,this.processor=t,this * Code distributed by Google as part of the polymer project is also * subject to an additional IP rights grant found at * http://polymer.github.io/PATENTS.txt - */const O=new + */const z=new /** * @license * Copyright (c) 2017 The Polymer Project Authors. All rights reserved. @@ -119,7 +119,7 @@ class f{constructor(e,t,i){this.__parts=[],this.template=e,this.processor=t,this * subject to an additional IP rights grant found at * http://polymer.github.io/PATENTS.txt */ -class{handleAttributeExpressions(e,t,i,n){const s=t[0];if("."===s){return new P(e,t.slice(1),i).parts}if("@"===s)return[new M(e,t.slice(1),n.eventContext)];if("?"===s)return[new k(e,t.slice(1),i)];return new C(e,t,i).parts}handleTextExpression(e){return new x(e)}}; +class{handleAttributeExpressions(e,t,i,n){const s=t[0];if("."===s){return new P(e,t.slice(1),i).parts}if("@"===s)return[new E(e,t.slice(1),n.eventContext)];if("?"===s)return[new k(e,t.slice(1),i)];return new C(e,t,i).parts}handleTextExpression(e){return new x(e)}}; /** * @license * Copyright (c) 2017 The Polymer Project Authors. All rights reserved. @@ -132,7 +132,7 @@ class{handleAttributeExpressions(e,t,i,n){const s=t[0];if("."===s){return new P( * Code distributed by Google as part of the polymer project is also * subject to an additional IP rights grant found at * http://polymer.github.io/PATENTS.txt - */"undefined"!=typeof window&&(window.litHtmlVersions||(window.litHtmlVersions=[])).push("1.2.1");const H=(e,...t)=>new w(e,t,"html",O) + */"undefined"!=typeof window&&(window.litHtmlVersions||(window.litHtmlVersions=[])).push("1.2.1");const M=(e,...t)=>new w(e,t,"html",z) /** * @license * Copyright (c) 2017 The Polymer Project Authors. All rights reserved. @@ -145,7 +145,7 @@ class{handleAttributeExpressions(e,t,i,n){const s=t[0];if("."===s){return new P( * Code distributed by Google as part of the polymer project is also * subject to an additional IP rights grant found at * http://polymer.github.io/PATENTS.txt - */,z=(e,t)=>`${e}--${t}`;let L=!0;void 0===window.ShadyCSS?L=!1:void 0===window.ShadyCSS.prepareTemplateDom&&(console.warn("Incompatible ShadyCSS version detected. Please update to at least @webcomponents/webcomponentsjs@2.0.2 and @webcomponents/shadycss@1.3.1."),L=!1);const j=e=>t=>{const i=z(t.type,e);let s=A.get(i);void 0===s&&(s={stringsArray:new WeakMap,keyString:new Map},A.set(i,s));let a=s.stringsArray.get(t.strings);if(void 0!==a)return a;const r=t.strings.join(n);if(a=s.keyString.get(r),void 0===a){const i=t.getTemplateElement();L&&window.ShadyCSS.prepareTemplateDom(i,e),a=new o(t,i),s.keyString.set(r,a)}return s.stringsArray.set(t.strings,a),a},U=["html","svg"],R=new Set,Y=(e,t,i)=>{R.add(e);const n=i?i.element:document.createElement("template"),s=t.querySelectorAll("style"),{length:a}=s;if(0===a)return void window.ShadyCSS.prepareTemplateStyles(n,e);const o=document.createElement("style");for(let e=0;e{U.forEach(t=>{const i=A.get(z(t,e));void 0!==i&&i.keyString.forEach(e=>{const{element:{content:t}}=e,i=new Set;Array.from(t.querySelectorAll("style")).forEach(e=>{i.add(e)}),h(e,i)})})})(e);const r=n.content;i?function(e,t,i=null){const{element:{content:n},parts:s}=e;if(null==i)return void n.appendChild(t);const a=document.createTreeWalker(n,133,null,!1);let o=u(s),r=0,l=-1;for(;a.nextNode();)for(l++,a.currentNode===i&&(r=p(t),i.parentNode.insertBefore(t,i));-1!==o&&s[o].index===l;){if(r>0){for(;-1!==o;)s[o].index+=r,o=u(s,o);return}o=u(s,o)}}(i,o,r.firstChild):r.insertBefore(o,r.firstChild),window.ShadyCSS.prepareTemplateStyles(n,e);const l=r.querySelector("style");if(window.ShadyCSS.nativeShadow&&null!==l)t.insertBefore(l.cloneNode(!0),t.firstChild);else if(i){r.insertBefore(o,r.firstChild);const e=new Set;e.add(o),h(i,e)}};window.JSCompiler_renameProperty=(e,t)=>e;const F={toAttribute(e,t){switch(t){case Boolean:return e?"":null;case Object:case Array:return null==e?e:JSON.stringify(e)}return e},fromAttribute(e,t){switch(t){case Boolean:return null!==e;case Number:return null===e?null:Number(e);case Object:case Array:return JSON.parse(e)}return e}},W=(e,t)=>t!==e&&(t==t||e==e),I={attribute:!0,type:String,converter:F,reflect:!1,hasChanged:W};class G extends HTMLElement{constructor(){super(),this._updateState=0,this._instanceProperties=void 0,this._updatePromise=new Promise(e=>this._enableUpdatingResolver=e),this._changedProperties=new Map,this._reflectingProperties=void 0,this.initialize()}static get observedAttributes(){this.finalize();const e=[];return this._classProperties.forEach((t,i)=>{const n=this._attributeNameForProperty(i,t);void 0!==n&&(this._attributeToPropertyMap.set(n,i),e.push(n))}),e}static _ensureClassProperties(){if(!this.hasOwnProperty(JSCompiler_renameProperty("_classProperties",this))){this._classProperties=new Map;const e=Object.getPrototypeOf(this)._classProperties;void 0!==e&&e.forEach((e,t)=>this._classProperties.set(t,e))}}static createProperty(e,t=I){if(this._ensureClassProperties(),this._classProperties.set(e,t),t.noAccessor||this.prototype.hasOwnProperty(e))return;const i="symbol"==typeof e?Symbol():"__"+e,n=this.getPropertyDescriptor(e,i,t);void 0!==n&&Object.defineProperty(this.prototype,e,n)}static getPropertyDescriptor(e,t,i){return{get(){return this[t]},set(i){const n=this[e];this[t]=i,this._requestUpdate(e,n)},configurable:!0,enumerable:!0}}static getPropertyOptions(e){return this._classProperties&&this._classProperties.get(e)||I}static finalize(){const e=Object.getPrototypeOf(this);if(e.hasOwnProperty("finalized")||e.finalize(),this.finalized=!0,this._ensureClassProperties(),this._attributeToPropertyMap=new Map,this.hasOwnProperty(JSCompiler_renameProperty("properties",this))){const e=this.properties,t=[...Object.getOwnPropertyNames(e),..."function"==typeof Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(e):[]];for(const i of t)this.createProperty(i,e[i])}}static _attributeNameForProperty(e,t){const i=t.attribute;return!1===i?void 0:"string"==typeof i?i:"string"==typeof e?e.toLowerCase():void 0}static _valueHasChanged(e,t,i=W){return i(e,t)}static _propertyValueFromAttribute(e,t){const i=t.type,n=t.converter||F,s="function"==typeof n?n:n.fromAttribute;return s?s(e,i):e}static _propertyValueToAttribute(e,t){if(void 0===t.reflect)return;const i=t.type,n=t.converter;return(n&&n.toAttribute||F.toAttribute)(e,i)}initialize(){this._saveInstanceProperties(),this._requestUpdate()}_saveInstanceProperties(){this.constructor._classProperties.forEach((e,t)=>{if(this.hasOwnProperty(t)){const e=this[t];delete this[t],this._instanceProperties||(this._instanceProperties=new Map),this._instanceProperties.set(t,e)}})}_applyInstanceProperties(){this._instanceProperties.forEach((e,t)=>this[t]=e),this._instanceProperties=void 0}connectedCallback(){this.enableUpdating()}enableUpdating(){void 0!==this._enableUpdatingResolver&&(this._enableUpdatingResolver(),this._enableUpdatingResolver=void 0)}disconnectedCallback(){}attributeChangedCallback(e,t,i){t!==i&&this._attributeToProperty(e,i)}_propertyToAttribute(e,t,i=I){const n=this.constructor,s=n._attributeNameForProperty(e,i);if(void 0!==s){const e=n._propertyValueToAttribute(t,i);if(void 0===e)return;this._updateState=8|this._updateState,null==e?this.removeAttribute(s):this.setAttribute(s,e),this._updateState=-9&this._updateState}}_attributeToProperty(e,t){if(8&this._updateState)return;const i=this.constructor,n=i._attributeToPropertyMap.get(e);if(void 0!==n){const e=i.getPropertyOptions(n);this._updateState=16|this._updateState,this[n]=i._propertyValueFromAttribute(t,e),this._updateState=-17&this._updateState}}_requestUpdate(e,t){let i=!0;if(void 0!==e){const n=this.constructor,s=n.getPropertyOptions(e);n._valueHasChanged(this[e],t,s.hasChanged)?(this._changedProperties.has(e)||this._changedProperties.set(e,t),!0!==s.reflect||16&this._updateState||(void 0===this._reflectingProperties&&(this._reflectingProperties=new Map),this._reflectingProperties.set(e,s))):i=!1}!this._hasRequestedUpdate&&i&&(this._updatePromise=this._enqueueUpdate())}requestUpdate(e,t){return this._requestUpdate(e,t),this.updateComplete}async _enqueueUpdate(){this._updateState=4|this._updateState;try{await this._updatePromise}catch(e){}const e=this.performUpdate();return null!=e&&await e,!this._hasRequestedUpdate}get _hasRequestedUpdate(){return 4&this._updateState}get hasUpdated(){return 1&this._updateState}performUpdate(){this._instanceProperties&&this._applyInstanceProperties();let e=!1;const t=this._changedProperties;try{e=this.shouldUpdate(t),e?this.update(t):this._markUpdated()}catch(t){throw e=!1,this._markUpdated(),t}e&&(1&this._updateState||(this._updateState=1|this._updateState,this.firstUpdated(t)),this.updated(t))}_markUpdated(){this._changedProperties=new Map,this._updateState=-5&this._updateState}get updateComplete(){return this._getUpdateComplete()}_getUpdateComplete(){return this._updatePromise}shouldUpdate(e){return!0}update(e){void 0!==this._reflectingProperties&&this._reflectingProperties.size>0&&(this._reflectingProperties.forEach((e,t)=>this._propertyToAttribute(t,this[t],e)),this._reflectingProperties=void 0),this._markUpdated()}updated(e){}firstUpdated(e){}}G.finalized=!0; + */,H=(e,t)=>`${e}--${t}`;let L=!0;void 0===window.ShadyCSS?L=!1:void 0===window.ShadyCSS.prepareTemplateDom&&(console.warn("Incompatible ShadyCSS version detected. Please update to at least @webcomponents/webcomponentsjs@2.0.2 and @webcomponents/shadycss@1.3.1."),L=!1);const j=e=>t=>{const i=H(t.type,e);let s=O.get(i);void 0===s&&(s={stringsArray:new WeakMap,keyString:new Map},O.set(i,s));let a=s.stringsArray.get(t.strings);if(void 0!==a)return a;const r=t.strings.join(n);if(a=s.keyString.get(r),void 0===a){const i=t.getTemplateElement();L&&window.ShadyCSS.prepareTemplateDom(i,e),a=new o(t,i),s.keyString.set(r,a)}return s.stringsArray.set(t.strings,a),a},U=["html","svg"],R=new Set,W=(e,t,i)=>{R.add(e);const n=i?i.element:document.createElement("template"),s=t.querySelectorAll("style"),{length:a}=s;if(0===a)return void window.ShadyCSS.prepareTemplateStyles(n,e);const o=document.createElement("style");for(let e=0;e{U.forEach(t=>{const i=O.get(H(t,e));void 0!==i&&i.keyString.forEach(e=>{const{element:{content:t}}=e,i=new Set;Array.from(t.querySelectorAll("style")).forEach(e=>{i.add(e)}),h(e,i)})})})(e);const r=n.content;i?function(e,t,i=null){const{element:{content:n},parts:s}=e;if(null==i)return void n.appendChild(t);const a=document.createTreeWalker(n,133,null,!1);let o=u(s),r=0,l=-1;for(;a.nextNode();)for(l++,a.currentNode===i&&(r=p(t),i.parentNode.insertBefore(t,i));-1!==o&&s[o].index===l;){if(r>0){for(;-1!==o;)s[o].index+=r,o=u(s,o);return}o=u(s,o)}}(i,o,r.firstChild):r.insertBefore(o,r.firstChild),window.ShadyCSS.prepareTemplateStyles(n,e);const l=r.querySelector("style");if(window.ShadyCSS.nativeShadow&&null!==l)t.insertBefore(l.cloneNode(!0),t.firstChild);else if(i){r.insertBefore(o,r.firstChild);const e=new Set;e.add(o),h(i,e)}};window.JSCompiler_renameProperty=(e,t)=>e;const F={toAttribute(e,t){switch(t){case Boolean:return e?"":null;case Object:case Array:return null==e?e:JSON.stringify(e)}return e},fromAttribute(e,t){switch(t){case Boolean:return null!==e;case Number:return null===e?null:Number(e);case Object:case Array:return JSON.parse(e)}return e}},I=(e,t)=>t!==e&&(t==t||e==e),G={attribute:!0,type:String,converter:F,reflect:!1,hasChanged:I};class q extends HTMLElement{constructor(){super(),this._updateState=0,this._instanceProperties=void 0,this._updatePromise=new Promise(e=>this._enableUpdatingResolver=e),this._changedProperties=new Map,this._reflectingProperties=void 0,this.initialize()}static get observedAttributes(){this.finalize();const e=[];return this._classProperties.forEach((t,i)=>{const n=this._attributeNameForProperty(i,t);void 0!==n&&(this._attributeToPropertyMap.set(n,i),e.push(n))}),e}static _ensureClassProperties(){if(!this.hasOwnProperty(JSCompiler_renameProperty("_classProperties",this))){this._classProperties=new Map;const e=Object.getPrototypeOf(this)._classProperties;void 0!==e&&e.forEach((e,t)=>this._classProperties.set(t,e))}}static createProperty(e,t=G){if(this._ensureClassProperties(),this._classProperties.set(e,t),t.noAccessor||this.prototype.hasOwnProperty(e))return;const i="symbol"==typeof e?Symbol():"__"+e,n=this.getPropertyDescriptor(e,i,t);void 0!==n&&Object.defineProperty(this.prototype,e,n)}static getPropertyDescriptor(e,t,i){return{get(){return this[t]},set(i){const n=this[e];this[t]=i,this._requestUpdate(e,n)},configurable:!0,enumerable:!0}}static getPropertyOptions(e){return this._classProperties&&this._classProperties.get(e)||G}static finalize(){const e=Object.getPrototypeOf(this);if(e.hasOwnProperty("finalized")||e.finalize(),this.finalized=!0,this._ensureClassProperties(),this._attributeToPropertyMap=new Map,this.hasOwnProperty(JSCompiler_renameProperty("properties",this))){const e=this.properties,t=[...Object.getOwnPropertyNames(e),..."function"==typeof Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(e):[]];for(const i of t)this.createProperty(i,e[i])}}static _attributeNameForProperty(e,t){const i=t.attribute;return!1===i?void 0:"string"==typeof i?i:"string"==typeof e?e.toLowerCase():void 0}static _valueHasChanged(e,t,i=I){return i(e,t)}static _propertyValueFromAttribute(e,t){const i=t.type,n=t.converter||F,s="function"==typeof n?n:n.fromAttribute;return s?s(e,i):e}static _propertyValueToAttribute(e,t){if(void 0===t.reflect)return;const i=t.type,n=t.converter;return(n&&n.toAttribute||F.toAttribute)(e,i)}initialize(){this._saveInstanceProperties(),this._requestUpdate()}_saveInstanceProperties(){this.constructor._classProperties.forEach((e,t)=>{if(this.hasOwnProperty(t)){const e=this[t];delete this[t],this._instanceProperties||(this._instanceProperties=new Map),this._instanceProperties.set(t,e)}})}_applyInstanceProperties(){this._instanceProperties.forEach((e,t)=>this[t]=e),this._instanceProperties=void 0}connectedCallback(){this.enableUpdating()}enableUpdating(){void 0!==this._enableUpdatingResolver&&(this._enableUpdatingResolver(),this._enableUpdatingResolver=void 0)}disconnectedCallback(){}attributeChangedCallback(e,t,i){t!==i&&this._attributeToProperty(e,i)}_propertyToAttribute(e,t,i=G){const n=this.constructor,s=n._attributeNameForProperty(e,i);if(void 0!==s){const e=n._propertyValueToAttribute(t,i);if(void 0===e)return;this._updateState=8|this._updateState,null==e?this.removeAttribute(s):this.setAttribute(s,e),this._updateState=-9&this._updateState}}_attributeToProperty(e,t){if(8&this._updateState)return;const i=this.constructor,n=i._attributeToPropertyMap.get(e);if(void 0!==n){const e=i.getPropertyOptions(n);this._updateState=16|this._updateState,this[n]=i._propertyValueFromAttribute(t,e),this._updateState=-17&this._updateState}}_requestUpdate(e,t){let i=!0;if(void 0!==e){const n=this.constructor,s=n.getPropertyOptions(e);n._valueHasChanged(this[e],t,s.hasChanged)?(this._changedProperties.has(e)||this._changedProperties.set(e,t),!0!==s.reflect||16&this._updateState||(void 0===this._reflectingProperties&&(this._reflectingProperties=new Map),this._reflectingProperties.set(e,s))):i=!1}!this._hasRequestedUpdate&&i&&(this._updatePromise=this._enqueueUpdate())}requestUpdate(e,t){return this._requestUpdate(e,t),this.updateComplete}async _enqueueUpdate(){this._updateState=4|this._updateState;try{await this._updatePromise}catch(e){}const e=this.performUpdate();return null!=e&&await e,!this._hasRequestedUpdate}get _hasRequestedUpdate(){return 4&this._updateState}get hasUpdated(){return 1&this._updateState}performUpdate(){this._instanceProperties&&this._applyInstanceProperties();let e=!1;const t=this._changedProperties;try{e=this.shouldUpdate(t),e?this.update(t):this._markUpdated()}catch(t){throw e=!1,this._markUpdated(),t}e&&(1&this._updateState||(this._updateState=1|this._updateState,this.firstUpdated(t)),this.updated(t))}_markUpdated(){this._changedProperties=new Map,this._updateState=-5&this._updateState}get updateComplete(){return this._getUpdateComplete()}_getUpdateComplete(){return this._updatePromise}shouldUpdate(e){return!0}update(e){void 0!==this._reflectingProperties&&this._reflectingProperties.size>0&&(this._reflectingProperties.forEach((e,t)=>this._propertyToAttribute(t,this[t],e)),this._reflectingProperties=void 0),this._markUpdated()}updated(e){}firstUpdated(e){}}q.finalized=!0; /** * @license * Copyright (c) 2017 The Polymer Project Authors. All rights reserved. @@ -159,7 +159,7 @@ class{handleAttributeExpressions(e,t,i,n){const s=t[0];if("."===s){return new P( * subject to an additional IP rights grant found at * http://polymer.github.io/PATENTS.txt */ -const q=e=>t=>"function"==typeof t?((e,t)=>(window.customElements.define(e,t),t))(e,t):((e,t)=>{const{kind:i,elements:n}=t;return{kind:i,elements:n,finisher(t){window.customElements.define(e,t)}}})(e,t),B=(e,t)=>"method"===t.kind&&t.descriptor&&!("value"in t.descriptor)?Object.assign(Object.assign({},t),{finisher(i){i.createProperty(t.key,e)}}):{kind:"field",key:Symbol(),placement:"own",descriptor:{},initializer(){"function"==typeof t.initializer&&(this[t.key]=t.initializer.call(this))},finisher(i){i.createProperty(t.key,e)}};function Z(e){return(t,i)=>void 0!==i?((e,t,i)=>{t.constructor.createProperty(i,e)})(e,t,i):B(e,t)}function K(e){return Z({attribute:!1,hasChanged:null==e?void 0:e.hasChanged})} +const B=e=>t=>"function"==typeof t?((e,t)=>(window.customElements.define(e,t),t))(e,t):((e,t)=>{const{kind:i,elements:n}=t;return{kind:i,elements:n,finisher(t){window.customElements.define(e,t)}}})(e,t),K=(e,t)=>"method"===t.kind&&t.descriptor&&!("value"in t.descriptor)?Object.assign(Object.assign({},t),{finisher(i){i.createProperty(t.key,e)}}):{kind:"field",key:Symbol(),placement:"own",descriptor:{},initializer(){"function"==typeof t.initializer&&(this[t.key]=t.initializer.call(this))},finisher(i){i.createProperty(t.key,e)}};function Z(e){return(t,i)=>void 0!==i?((e,t,i)=>{t.constructor.createProperty(i,e)})(e,t,i):K(e,t)}function J(e){return Z({attribute:!1,hasChanged:null==e?void 0:e.hasChanged})} /** @license Copyright (c) 2019 The Polymer Project Authors. All rights reserved. @@ -169,7 +169,7 @@ http://polymer.github.io/AUTHORS.txt The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by Google as part of the polymer project is also subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt -*/const J="adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,Q=Symbol();class X{constructor(e,t){if(t!==Q)throw new Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=e}get styleSheet(){return void 0===this._styleSheet&&(J?(this._styleSheet=new CSSStyleSheet,this._styleSheet.replaceSync(this.cssText)):this._styleSheet=null),this._styleSheet}toString(){return this.cssText}}const ee=(e,...t)=>{const i=t.reduce((t,i,n)=>t+(e=>{if(e instanceof X)return e.cssText;if("number"==typeof e)return e;throw new Error(`Value passed to 'css' function must be a 'css' function result: ${e}. Use 'unsafeCSS' to pass non-literal values, but\n take care to ensure page security.`)})(i)+e[n+1],e[0]);return new X(i,Q)}; +*/const Y="adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,Q=Symbol();class X{constructor(e,t){if(t!==Q)throw new Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=e}get styleSheet(){return void 0===this._styleSheet&&(Y?(this._styleSheet=new CSSStyleSheet,this._styleSheet.replaceSync(this.cssText)):this._styleSheet=null),this._styleSheet}toString(){return this.cssText}}const ee=(e,...t)=>{const i=t.reduce((t,i,n)=>t+(e=>{if(e instanceof X)return e.cssText;if("number"==typeof e)return e;throw new Error(`Value passed to 'css' function must be a 'css' function result: ${e}. Use 'unsafeCSS' to pass non-literal values, but\n take care to ensure page security.`)})(i)+e[n+1],e[0]);return new X(i,Q)}; /** * @license * Copyright (c) 2017 The Polymer Project Authors. All rights reserved. @@ -183,11 +183,11 @@ found at http://polymer.github.io/PATENTS.txt * subject to an additional IP rights grant found at * http://polymer.github.io/PATENTS.txt */ -(window.litElementVersions||(window.litElementVersions=[])).push("2.3.1");const te={};class ie extends G{static getStyles(){return this.styles}static _getUniqueStyles(){if(this.hasOwnProperty(JSCompiler_renameProperty("_styles",this)))return;const e=this.getStyles();if(void 0===e)this._styles=[];else if(Array.isArray(e)){const t=(e,i)=>e.reduceRight((e,i)=>Array.isArray(i)?t(i,e):(e.add(i),e),i),i=t(e,new Set),n=[];i.forEach(e=>n.unshift(e)),this._styles=n}else this._styles=[e]}initialize(){super.initialize(),this.constructor._getUniqueStyles(),this.renderRoot=this.createRenderRoot(),window.ShadowRoot&&this.renderRoot instanceof window.ShadowRoot&&this.adoptStyles()}createRenderRoot(){return this.attachShadow({mode:"open"})}adoptStyles(){const e=this.constructor._styles;0!==e.length&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeShadow?J?this.renderRoot.adoptedStyleSheets=e.map(e=>e.styleSheet):this._needsShimAdoptedStyleSheets=!0:window.ShadyCSS.ScopingShim.prepareAdoptedCssText(e.map(e=>e.cssText),this.localName))}connectedCallback(){super.connectedCallback(),this.hasUpdated&&void 0!==window.ShadyCSS&&window.ShadyCSS.styleElement(this)}update(e){const t=this.render();super.update(e),t!==te&&this.constructor.render(t,this.renderRoot,{scopeName:this.localName,eventContext:this}),this._needsShimAdoptedStyleSheets&&(this._needsShimAdoptedStyleSheets=!1,this.constructor._styles.forEach(e=>{const t=document.createElement("style");t.textContent=e.cssText,this.renderRoot.appendChild(t)}))}render(){return te}}ie.finalized=!0,ie.render=(e,t,n)=>{if(!n||"object"!=typeof n||!n.scopeName)throw new Error("The `scopeName` option is required.");const s=n.scopeName,a=N.has(t),o=L&&11===t.nodeType&&!!t.host,r=o&&!R.has(s),l=r?document.createDocumentFragment():t;if(((e,t,n)=>{let s=N.get(t);void 0===s&&(i(t,t.firstChild),N.set(t,s=new x(Object.assign({templateFactory:T},n))),s.appendInto(t)),s.setValue(e),s.commit()})(e,l,Object.assign({templateFactory:j(s)},n)),r){const e=N.get(l);N.delete(l);const n=e.value instanceof f?e.value.template:void 0;Y(s,l,n),i(t,t.firstChild),t.appendChild(l),N.set(t,e)}!a&&o&&window.ShadyCSS.styleElement(t.host)};var ne,se,ae;function oe(e){return"currently_playing_type"in e}!function(e){e.Grid="grid",e.List="list"}(ne||(ne={})),function(e){e.default="default",e.featured="featured",e.discover_weekly="discover-weekly"}(se||(se={})),function(e){e[e.Name=0]="Name",e[e.Account=1]="Account",e[e.Spotify_Entity=2]="Spotify_Entity",e[e.Country_Code=3]="Country_Code",e[e.Limit=4]="Limit",e[e.Playlist_Type=5]="Playlist_Type",e[e.Always_Play_Random_Song=6]="Always_Play_Random_Song",e[e.Height=7]="Height",e[e.Display_Style=8]="Display_Style",e[e.Grid_Covers_Per_Row=9]="Grid_Covers_Per_Row",e[e.Grid_Center_Covers=10]="Grid_Center_Covers",e[e.Grid_Show_Title=11]="Grid_Show_Title",e[e.Hide_Warning=12]="Hide_Warning",e[e.Default_Device=13]="Default_Device",e[e.Filter_Devices=14]="Filter_Devices",e[e.Known_Connect_Devices=15]="Known_Connect_Devices",e[e.Include_Playlists=16]="Include_Playlists",e[e.Hide_Connect_Devices=17]="Hide_Connect_Devices",e[e.Hide_Chromecast_Devices=18]="Hide_Chromecast_Devices",e[e.Hide_Top_Header=19]="Hide_Top_Header",e[e.Hide_Currently_Playing=20]="Hide_Currently_Playing",e[e.Hide_Playback_Controls=21]="Hide_Playback_Controls"}(ae||(ae={}));var re=/d{1,4}|M{1,4}|YY(?:YY)?|S{1,3}|Do|ZZ|Z|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g,le="[^\\s]+",ce=/\[([^]*?)\]/gm;function de(e,t){for(var i=[],n=0,s=e.length;n-1?n:null}};function pe(e){for(var t=[],i=1;i3?0:(e-e%10!=10?1:0)*e%10]}},me=pe({},_e),fe=function(e,t){for(void 0===t&&(t=2),e=String(e);e.length0?"-":"+")+fe(100*Math.floor(Math.abs(t)/60)+Math.abs(t)%60,4)},Z:function(e){var t=e.getTimezoneOffset();return(t>0?"-":"+")+fe(Math.floor(Math.abs(t)/60),2)+":"+fe(Math.abs(t)%60,2)}},we=function(e){return+e-1},be=[null,"[1-9]\\d?"],Se=[null,le],Ce=["isPm",le,function(e,t){var i=e.toLowerCase();return i===t.amPm[0]?0:i===t.amPm[1]?1:null}],$e=["timezoneOffset","[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z?",function(e){var t=(e+"").match(/([+-]|\d\d)/gi);if(t){var i=60*+t[1]+parseInt(t[2],10);return"+"===t[0]?i:-i}return 0}],xe=(he("monthNamesShort"),he("monthNames"),{default:"ddd MMM DD YYYY HH:mm:ss",shortDate:"M/D/YY",mediumDate:"MMM D, YYYY",longDate:"MMMM D, YYYY",fullDate:"dddd, MMMM D, YYYY",isoDate:"YYYY-MM-DD",isoDateTime:"YYYY-MM-DDTHH:mm:ssZ",shortTime:"HH:mm",mediumTime:"HH:mm:ss",longTime:"HH:mm:ss.SSS"});var ke=function(e,t,i){if(void 0===t&&(t=xe.default),void 0===i&&(i={}),"number"==typeof e&&(e=new Date(e)),"[object Date]"!==Object.prototype.toString.call(e)||isNaN(e.getTime()))throw new Error("Invalid Date pass to format");var n=[];t=(t=xe[t]||t).replace(ce,(function(e,t){return n.push(t),"@@@"}));var s=pe(pe({},me),i);return(t=t.replace(re,(function(t){return ye[t](e,s)}))).replace(/@@@/g,(function(){return n.shift()}))},Pe=(function(){try{(new Date).toLocaleDateString("i")}catch(e){return"RangeError"===e.name}}(),function(){try{(new Date).toLocaleString("i")}catch(e){return"RangeError"===e.name}}(),function(){try{(new Date).toLocaleTimeString("i")}catch(e){return"RangeError"===e.name}}(),function(e,t,i,n){n=n||{},i=null==i?{}:i;var s=new Event(t,{bubbles:void 0===n.bubbles||n.bubbles,cancelable:Boolean(n.cancelable),composed:void 0===n.composed||n.composed});return s.detail=i,e.dispatchEvent(s),s}),De={version:"Version",description:"A custom card for displaying Spotify-Playlist and starting playback",invalid_configuration:"Invalid configuration",show_warning:"Show Warning",show_missing_spotcast:"Spotcast integration has to be installed for this component to work",show_missing_spotify:"Spotify integration has to be installed for playback information",choose_player:"Choose player"},Ve={general:"General",general_description:"General settings for this card",appearance:"Appearance",appearance_description:"Customize the style, icon, etc",advanced:"Advanced",advanced_description:"Customize advanced settings",hide_warning:"Hide warnings",playlist_type:"Playlist Type",limit:"Amount of playlists shown",height:"Height of card",country_code:"Country Code",always_play_random_song:"Always play random song when starting playback",title:"Title of card",display_style:"Display Style",grid_covers_per_row:"Number of covers per row",grid_center_covers:"Center Covers",grid_show_title:"Show album title in grid view",account:"Account",spotify_entity:"Spotify media player entity",default_device:"Default device name",filter_devices:"Hide devices (see documentation under 'Advanced usage')",known_connect_devices:"Known Spotify Connect devices (see documentation under 'Advanced usage')",known_connect_device_id:"Device id",known_connect_device_name:"Device name",known_connect_device_entity_id:"Media player entity",known_connect_device_add:"Add currently playing device",known_connect_device_remove:"Remove",include_playlists:"Filter playlists to show (see documentation under 'Advanced usage')",hide_connect_devices:"Hide all Spotify Connect Devices",hide_chromecast_devices:"Hide all Chromecast Devices",hide_top_header:"Hide header",hide_currently_playing:"Hide currently playing",hide_playback_controls:"Hide playback controls"},Me={common:De,settings:Ve},Ee={version:"Version",description:"Eine Karte um Spotify-Playlist anzuzeigen und abzuspielen",invalid_configuration:"Ungültige Konfiguration",show_warning:"Warnung",show_missing_spotcast:"Die Spotcast-Integration muss installiert sein, damit diese Karte funktioniert",show_missing_spotify:"Die Spotify-Integration muss installiert sein, damit der Spotify-Status angezeigt werden kann",choose_player:"Player auswählen"},Te={general:"Generell",general_description:"Generelle Einstellungen",appearance:"Aussehen",appearance_description:"Passe den Stil und anderes an",hide_warning:"Verstecke Warnhinweise",playlist_type:"Playlist Typ",limit:"Anzahl an angezeigten Playlisten",height:"Höhe der Karte",country_code:"Länder-Code",always_play_random_song:"Spiele immer einen zufälligen Song beim Starten der Wiedergabe ab",title:"Titel der Karte",display_style:"Anzeige-Stil",grid_covers_per_row:"Anzahl an Albenbildern pro Reihe",grid_show_title:"Zeige Albumtitel in Grid-View",account:"Account",spotify_entity:"Spotify media player entity",default_device:"Standart Gerätename",filter_devices:"Verstecke Geräte (siehe Dokumentation unter 'Advanced usage')",hide_connect_devices:"Verstecke alle Spotify Connect Geräte",hide_chromecast_devices:"Verstecke alle Chromecast Geräte",hide_top_header:"Verstecke Kopfzeile",hide_currently_playing:"Verstecke die Anzeige des aktuellen Liedes",hide_playback_controls:"Verstecke Wiedergabesteuerung"},Ae={common:Ee,settings:Te},Ne={version:"Version",description:"A custom card for displaying Spotify-Playlist and starting playback",invalid_configuration:"Invalid configuration",show_warning:"Show Warning",show_missing_spotcast:"Spotcast integration has to be installed for this component to work",show_missing_spotify:"Spotify integration has to be installed for playback information"},Oe={general:"General",general_description:"General settings for this card",appearance:"Appearance",appearance_description:"Customize the style, icon, etc",hide_warning:"Hide warnings",playlist_type:"Playlist Type",limit:"Amount of playlists shown",height:"Height of card",country_code:"Country Code for featured playlists",always_play_random_song:"Always play random song when starting playback",title:"Title of card",display_style:"Display Style",grid_covers_per_row:"Number of covers per row",account:"Account",filter_out_cast_devices:"Filter out chromecast devices",spotify_entity:"Spotify media player entity",default_device:"Default device name"},He={common:Ne,settings:Oe};const ze={en:Object.freeze({__proto__:null,common:De,settings:Ve,default:Me}),de:Object.freeze({__proto__:null,common:Ee,settings:Te,default:Ae}),se:Object.freeze({__proto__:null,common:Ne,settings:Oe,default:He})};function Le(e,t="",i=""){const n=e.split(".")[0],s=e.split(".")[1],a=(localStorage.getItem("selectedLanguage")||navigator.language.split("-")[0]||"en").replace(/['"]+/g,"").replace("-","_");let o;try{o=ze[a][n][s]}catch(e){o=ze.en[n][s]}return void 0===o&&(o=ze.en[n][s]),""!==t&&""!==i&&(o=o.replace(t,i)),o}const je={general:{icon:"tune",name:Le("settings.general"),secondary:Le("settings.general_description"),show:!0},appearance:{icon:"palette",name:Le("settings.appearance"),secondary:Le("settings.appearance_description"),show:!1},advanced:{icon:"pencil",name:Le("settings.advanced"),secondary:Le("settings.advanced_description"),show:!1}};let Ue=class extends ie{constructor(){super(...arguments),this.accounts=[],this.chromecast_devices=[]}async connectedCallback(){super.connectedCallback();const e=await this.hass.callWS({type:"spotcast/accounts"});this.accounts=e;const t=await this.hass.callWS({type:"spotcast/castdevices"});this.chromecast_devices=null==t?void 0:t.map(e=>e.friendly_name)}setConfig(e){this.config=e}getMediaPlayerEntities(){return Object.values(this.hass.states).filter(e=>e.entity_id.match("media_player[.]")).map(e=>e.entity_id)}_toggleOption(e){this._toggleThing(e,je)}_toggleThing(e,t){const i=!t[e.target.option].show;for(const[e]of Object.entries(t))t[e].show=!1;t[e.target.option].show=i,this._toggle=!this._toggle}valueChanged(e){var t,i;if(!this.config||!this.hass||null===e.target.offsetParent)return;const{target:n}=e;if(!n.value||this["_"+n.configValue]!==n.value){if(n.configValue)if(!1===n.checked||""===n.value){const e=Object.assign({},this.config);delete e[n.configValue],this.config=e}else{let e=n.configValue,s=n.value;if("height"==e||"limit"==e)s=Number(s);else if("filter_devices"==e)s=s.split(",").map(e=>e.trim()).filter(e=>""!=e);else if("include_playlists"==e)s=s.split(",").map(e=>e.trim()).filter(e=>""!=e);else if(e.startsWith("known_connect_devices")){const n=e.split(":")[1],a=e.split(":")[0].split(".")[1];s=(null!==(i=null===(t=this.config)||void 0===t?void 0:t.known_connect_devices)&&void 0!==i?i:[]).map((e,t)=>t==n?Object.assign(Object.assign({},e),{[a]:s}):e),e="known_connect_devices"}this.config=Object.assign(Object.assign({},this.config),{[e]:void 0!==n.checked?n.checked:s})}Pe(this,"config-changed",{config:this.config})}}async addKnownConnectDevice(){var e,t,i,n,s;let a=void 0;try{a=await this.hass.callWS({type:"spotcast/player",account:null===(e=this.config)||void 0===e?void 0:e.account})}catch(e){console.error("Failed to fetch player",e)}this.config&&(this.config=Object.assign(Object.assign({},this.config),{known_connect_devices:(null!==(t=this.config.known_connect_devices)&&void 0!==t?t:[]).concat([{id:null!==(n=null===(i=null==a?void 0:a.device)||void 0===i?void 0:i.id)&&void 0!==n?n:"",name:null!==(s=null==a?void 0:a.device.name)&&void 0!==s?s:""}])}),Pe(this,"config-changed",{config:this.config}))}removeKnownConnectDevice(e){var t;this.config&&(this.config=Object.assign(Object.assign({},this.config),{known_connect_devices:(null!==(t=this.config.known_connect_devices)&&void 0!==t?t:[]).filter((t,i)=>i!=e)}),Pe(this,"config-changed",{config:this.config}))}getValue(e){var t,i,n,s,a,o,r,l,c,d,h,p,u,g,v,_,m,f,y,w,b,S,C,$,x,k,P,D,V,M,E,T,A,N,O,H,z,L,j,U,R,Y,F,W;switch(e){case ae.Name:return null!==(i=null===(t=this.config)||void 0===t?void 0:t.name)&&void 0!==i?i:"";case ae.Account:return null!==(s=null===(n=this.config)||void 0===n?void 0:n.account)&&void 0!==s?s:"default";case ae.Spotify_Entity:const e=this.getMediaPlayerEntities().filter(e=>e.includes("spotify"));return null!==(o=null===(a=this.config)||void 0===a?void 0:a.spotify_entity)&&void 0!==o?o:e.length>0?e[0]:"";case ae.Country_Code:return null!==(l=null===(r=this.config)||void 0===r?void 0:r.country_code)&&void 0!==l?l:"";case ae.Limit:return null!==(d=null===(c=this.config)||void 0===c?void 0:c.limit)&&void 0!==d?d:10;case ae.Playlist_Type:return null!==(p=null===(h=this.config)||void 0===h?void 0:h.playlist_type)&&void 0!==p?p:"default";case ae.Always_Play_Random_Song:return null!==(g=null===(u=this.config)||void 0===u?void 0:u.always_play_random_song)&&void 0!==g&&g;case ae.Height:return null!==(_=null===(v=this.config)||void 0===v?void 0:v.height)&&void 0!==_?_:"";case ae.Display_Style:return null!==(f=null===(m=this.config)||void 0===m?void 0:m.display_style)&&void 0!==f?f:"list";case ae.Grid_Covers_Per_Row:return null!==(w=null===(y=this.config)||void 0===y?void 0:y.grid_covers_per_row)&&void 0!==w?w:5;case ae.Grid_Center_Covers:return null!==(S=null===(b=this.config)||void 0===b?void 0:b.grid_center_covers)&&void 0!==S&&S;case ae.Hide_Warning:return null!==($=null===(C=this.config)||void 0===C?void 0:C.hide_warning)&&void 0!==$&&$;case ae.Default_Device:return null!==(k=null===(x=this.config)||void 0===x?void 0:x.default_device)&&void 0!==k?k:"";case ae.Filter_Devices:return null!==(V=null===(D=null===(P=this.config)||void 0===P?void 0:P.filter_devices)||void 0===D?void 0:D.toString())&&void 0!==V?V:"";case ae.Known_Connect_Devices:return null!==(E=null===(M=this.config)||void 0===M?void 0:M.known_connect_devices)&&void 0!==E?E:[];case ae.Include_Playlists:return null!==(N=null===(A=null===(T=this.config)||void 0===T?void 0:T.include_playlists)||void 0===A?void 0:A.toString())&&void 0!==N?N:"";case ae.Hide_Connect_Devices:return null!==(H=null===(O=this.config)||void 0===O?void 0:O.hide_connect_devices)&&void 0!==H&&H;case ae.Hide_Chromecast_Devices:return null!==(L=null===(z=this.config)||void 0===z?void 0:z.hide_chromecast_devices)&&void 0!==L&&L;case ae.Hide_Top_Header:return null!==(U=null===(j=this.config)||void 0===j?void 0:j.hide_top_header)&&void 0!==U&&U;case ae.Hide_Currently_Playing:return null!==(Y=null===(R=this.config)||void 0===R?void 0:R.hide_currently_playing)&&void 0!==Y&&Y;case ae.Hide_Playback_Controls:return null!==(W=null===(F=this.config)||void 0===F?void 0:F.hide_playback_controls)&&void 0!==W&&W}}renderGeneral(){const e=this.getMediaPlayerEntities();return H` +(window.litElementVersions||(window.litElementVersions=[])).push("2.3.1");const te={};class ie extends q{static getStyles(){return this.styles}static _getUniqueStyles(){if(this.hasOwnProperty(JSCompiler_renameProperty("_styles",this)))return;const e=this.getStyles();if(void 0===e)this._styles=[];else if(Array.isArray(e)){const t=(e,i)=>e.reduceRight((e,i)=>Array.isArray(i)?t(i,e):(e.add(i),e),i),i=t(e,new Set),n=[];i.forEach(e=>n.unshift(e)),this._styles=n}else this._styles=[e]}initialize(){super.initialize(),this.constructor._getUniqueStyles(),this.renderRoot=this.createRenderRoot(),window.ShadowRoot&&this.renderRoot instanceof window.ShadowRoot&&this.adoptStyles()}createRenderRoot(){return this.attachShadow({mode:"open"})}adoptStyles(){const e=this.constructor._styles;0!==e.length&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeShadow?Y?this.renderRoot.adoptedStyleSheets=e.map(e=>e.styleSheet):this._needsShimAdoptedStyleSheets=!0:window.ShadyCSS.ScopingShim.prepareAdoptedCssText(e.map(e=>e.cssText),this.localName))}connectedCallback(){super.connectedCallback(),this.hasUpdated&&void 0!==window.ShadyCSS&&window.ShadyCSS.styleElement(this)}update(e){const t=this.render();super.update(e),t!==te&&this.constructor.render(t,this.renderRoot,{scopeName:this.localName,eventContext:this}),this._needsShimAdoptedStyleSheets&&(this._needsShimAdoptedStyleSheets=!1,this.constructor._styles.forEach(e=>{const t=document.createElement("style");t.textContent=e.cssText,this.renderRoot.appendChild(t)}))}render(){return te}}ie.finalized=!0,ie.render=(e,t,n)=>{if(!n||"object"!=typeof n||!n.scopeName)throw new Error("The `scopeName` option is required.");const s=n.scopeName,a=N.has(t),o=L&&11===t.nodeType&&!!t.host,r=o&&!R.has(s),l=r?document.createDocumentFragment():t;if(((e,t,n)=>{let s=N.get(t);void 0===s&&(i(t,t.firstChild),N.set(t,s=new x(Object.assign({templateFactory:T},n))),s.appendInto(t)),s.setValue(e),s.commit()})(e,l,Object.assign({templateFactory:j(s)},n)),r){const e=N.get(l);N.delete(l);const n=e.value instanceof m?e.value.template:void 0;W(s,l,n),i(t,t.firstChild),t.appendChild(l),N.set(t,e)}!a&&o&&window.ShadyCSS.styleElement(t.host)};var ne,se,ae;function oe(e){return"currently_playing_type"in e}!function(e){e.Grid="grid",e.List="list"}(ne||(ne={})),function(e){e.default="default",e.featured="featured",e.discover_weekly="discover-weekly",e.recently_played="recently-played",e.jump_back_in="jump-back-in",e.your_top_mixes="your-top-mixes[0]",e.more_of_what_you_like="home-personalized[more-of-what-you-like]"}(se||(se={})),function(e){e[e.Name=0]="Name",e[e.Account=1]="Account",e[e.Spotify_Entity=2]="Spotify_Entity",e[e.Country_Code=3]="Country_Code",e[e.Limit=4]="Limit",e[e.Playlist_Type=5]="Playlist_Type",e[e.Always_Play_Random_Song=6]="Always_Play_Random_Song",e[e.Height=7]="Height",e[e.Display_Style=8]="Display_Style",e[e.Grid_Covers_Per_Row=9]="Grid_Covers_Per_Row",e[e.Grid_Center_Covers=10]="Grid_Center_Covers",e[e.Grid_Show_Title=11]="Grid_Show_Title",e[e.Hide_Warning=12]="Hide_Warning",e[e.Default_Device=13]="Default_Device",e[e.Filter_Devices=14]="Filter_Devices",e[e.Known_Connect_Devices=15]="Known_Connect_Devices",e[e.Include_Playlists=16]="Include_Playlists",e[e.Hide_Connect_Devices=17]="Hide_Connect_Devices",e[e.Hide_Chromecast_Devices=18]="Hide_Chromecast_Devices",e[e.Hide_Top_Header=19]="Hide_Top_Header",e[e.Hide_Currently_Playing=20]="Hide_Currently_Playing",e[e.Hide_Playback_Controls=21]="Hide_Playback_Controls"}(ae||(ae={}));var re="[^\\s]+";function le(e,t){for(var i=[],n=0,s=e.length;n-1?n:null}};function de(e){for(var t=[],i=1;i3?0:(e-e%10!=10?1:0)*e%10]}},ve=(de({},ge),function(e){return+e-1}),_e=[null,"[1-9]\\d?"],ye=[null,re],me=["isPm",re,function(e,t){var i=e.toLowerCase();return i===t.amPm[0]?0:i===t.amPm[1]?1:null}],fe=["timezoneOffset","[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z?",function(e){var t=(e+"").match(/([+-]|\d\d)/gi);if(t){var i=60*+t[1]+parseInt(t[2],10);return"+"===t[0]?i:-i}return 0}];ce("monthNamesShort"),ce("monthNames");!function(){try{(new Date).toLocaleDateString("i")}catch(e){return"RangeError"===e.name}}(),function(){try{(new Date).toLocaleString("i")}catch(e){return"RangeError"===e.name}}(),function(){try{(new Date).toLocaleTimeString("i")}catch(e){return"RangeError"===e.name}}();var we=function(e,t,i,n){n=n||{},i=null==i?{}:i;var s=new Event(t,{bubbles:void 0===n.bubbles||n.bubbles,cancelable:Boolean(n.cancelable),composed:void 0===n.composed||n.composed});return s.detail=i,e.dispatchEvent(s),s},be={version:"Version",description:"A custom card for displaying Spotify-Playlist and starting playback",invalid_configuration:"Invalid configuration",show_warning:"Show Warning",show_missing_spotcast:"Spotcast integration has to be installed for this component to work",show_missing_spotify:"Spotify integration has to be installed for playback information",choose_player:"Choose player"},Se={general:"General",general_description:"General settings for this card",appearance:"Appearance",appearance_description:"Customize the style, icon, etc",advanced:"Advanced",advanced_description:"Customize advanced settings",hide_warning:"Hide warnings",playlist_type:"Playlist Type",limit:"Amount of playlists shown",height:"Height of card",country_code:"Country Code",always_play_random_song:"Always play random song when starting playback",title:"Title of card",display_style:"Display Style",grid_covers_per_row:"Number of covers per row",grid_center_covers:"Center Covers",grid_show_title:"Show album title in grid view",account:"Account",spotify_entity:"Spotify media player entity",default_device:"Default device name",filter_devices:"Hide devices (see documentation under 'Advanced usage')",known_connect_devices:"Known Spotify Connect devices (see documentation under 'Advanced usage')",known_connect_device_id:"Device id",known_connect_device_name:"Device name",known_connect_device_entity_id:"Media player entity",known_connect_device_add:"Add currently playing device",known_connect_device_remove:"Remove",include_playlists:"Filter playlists to show (see documentation under 'Advanced usage')",hide_connect_devices:"Hide all Spotify Connect Devices",hide_chromecast_devices:"Hide all Chromecast Devices",hide_top_header:"Hide header",hide_currently_playing:"Hide currently playing",hide_playback_controls:"Hide playback controls"},Ce={common:be,settings:Se},$e={version:"Version",description:"Eine Karte um Spotify-Playlist anzuzeigen und abzuspielen",invalid_configuration:"Ungültige Konfiguration",show_warning:"Warnung",show_missing_spotcast:"Die Spotcast-Integration muss installiert sein, damit diese Karte funktioniert",show_missing_spotify:"Die Spotify-Integration muss installiert sein, damit der Spotify-Status angezeigt werden kann",choose_player:"Player auswählen"},xe={general:"Generell",general_description:"Generelle Einstellungen",appearance:"Aussehen",appearance_description:"Passe den Stil und anderes an",hide_warning:"Verstecke Warnhinweise",playlist_type:"Playlist Typ",limit:"Anzahl an angezeigten Playlisten",height:"Höhe der Karte",country_code:"Länder-Code",always_play_random_song:"Spiele immer einen zufälligen Song beim Starten der Wiedergabe ab",title:"Titel der Karte",display_style:"Anzeige-Stil",grid_covers_per_row:"Anzahl an Albenbildern pro Reihe",grid_show_title:"Zeige Albumtitel in Grid-View",account:"Account",spotify_entity:"Spotify media player entity",default_device:"Standart Gerätename",filter_devices:"Verstecke Geräte (siehe Dokumentation unter 'Advanced usage')",hide_connect_devices:"Verstecke alle Spotify Connect Geräte",hide_chromecast_devices:"Verstecke alle Chromecast Geräte",hide_top_header:"Verstecke Kopfzeile",hide_currently_playing:"Verstecke die Anzeige des aktuellen Liedes",hide_playback_controls:"Verstecke Wiedergabesteuerung"},ke={common:$e,settings:xe},Pe={version:"Version",description:"A custom card for displaying Spotify-Playlist and starting playback",invalid_configuration:"Invalid configuration",show_warning:"Show Warning",show_missing_spotcast:"Spotcast integration has to be installed for this component to work",show_missing_spotify:"Spotify integration has to be installed for playback information"},Ve={general:"General",general_description:"General settings for this card",appearance:"Appearance",appearance_description:"Customize the style, icon, etc",hide_warning:"Hide warnings",playlist_type:"Playlist Type",limit:"Amount of playlists shown",height:"Height of card",country_code:"Country Code for featured playlists",always_play_random_song:"Always play random song when starting playback",title:"Title of card",display_style:"Display Style",grid_covers_per_row:"Number of covers per row",account:"Account",filter_out_cast_devices:"Filter out chromecast devices",spotify_entity:"Spotify media player entity",default_device:"Default device name"},De={common:Pe,settings:Ve};const Ee={en:Object.freeze({__proto__:null,common:be,settings:Se,default:Ce}),de:Object.freeze({__proto__:null,common:$e,settings:xe,default:ke}),se:Object.freeze({__proto__:null,common:Pe,settings:Ve,default:De})};function Ae(e,t="",i=""){const n=e.split(".")[0],s=e.split(".")[1],a=(localStorage.getItem("selectedLanguage")||navigator.language.split("-")[0]||"en").replace(/['"]+/g,"").replace("-","_");let o;try{o=Ee[a][n][s]}catch(e){o=Ee.en[n][s]}return void 0===o&&(o=Ee.en[n][s]),""!==t&&""!==i&&(o=o.replace(t,i)),o}const Te={general:{icon:"tune",name:Ae("settings.general"),secondary:Ae("settings.general_description"),show:!0},appearance:{icon:"palette",name:Ae("settings.appearance"),secondary:Ae("settings.appearance_description"),show:!1},advanced:{icon:"pencil",name:Ae("settings.advanced"),secondary:Ae("settings.advanced_description"),show:!1}};let Oe=class extends ie{constructor(){super(...arguments),this.accounts=[],this.chromecast_devices=[]}async connectedCallback(){super.connectedCallback();const e=await this.hass.callWS({type:"spotcast/accounts"});this.accounts=e;const t=await this.hass.callWS({type:"spotcast/castdevices"});this.chromecast_devices=null==t?void 0:t.map(e=>e.friendly_name)}setConfig(e){this.config=e}getMediaPlayerEntities(){return Object.values(this.hass.states).filter(e=>e.entity_id.match("media_player[.]")).map(e=>e.entity_id)}_toggleOption(e){this._toggleThing(e,Te)}_toggleThing(e,t){const i=!t[e.target.option].show;for(const[e]of Object.entries(t))t[e].show=!1;t[e.target.option].show=i,this._toggle=!this._toggle}valueChanged(e){var t,i;if(!this.config||!this.hass||null===e.target.offsetParent)return;const{target:n}=e;if(!n.value||this["_"+n.configValue]!==n.value){if(n.configValue)if(!1===n.checked||""===n.value){const e=Object.assign({},this.config);delete e[n.configValue],this.config=e}else{let e=n.configValue,s=n.value;if("height"==e||"limit"==e)s=Number(s);else if("filter_devices"==e)s=s.split(",").map(e=>e.trim()).filter(e=>""!=e);else if("include_playlists"==e)s=s.split(",").map(e=>e.trim()).filter(e=>""!=e);else if(e.startsWith("known_connect_devices")){const n=e.split(":")[1],a=e.split(":")[0].split(".")[1];s=(null!==(i=null===(t=this.config)||void 0===t?void 0:t.known_connect_devices)&&void 0!==i?i:[]).map((e,t)=>t==n?Object.assign(Object.assign({},e),{[a]:s}):e),e="known_connect_devices"}this.config=Object.assign(Object.assign({},this.config),{[e]:void 0!==n.checked?n.checked:s})}we(this,"config-changed",{config:this.config})}}async addKnownConnectDevice(){var e,t,i,n,s;let a=void 0;try{a=await this.hass.callWS({type:"spotcast/player",account:null===(e=this.config)||void 0===e?void 0:e.account})}catch(e){console.error("Failed to fetch player",e)}this.config&&(this.config=Object.assign(Object.assign({},this.config),{known_connect_devices:(null!==(t=this.config.known_connect_devices)&&void 0!==t?t:[]).concat([{id:null!==(n=null===(i=null==a?void 0:a.device)||void 0===i?void 0:i.id)&&void 0!==n?n:"",name:null!==(s=null==a?void 0:a.device.name)&&void 0!==s?s:""}])}),we(this,"config-changed",{config:this.config}))}removeKnownConnectDevice(e){var t;this.config&&(this.config=Object.assign(Object.assign({},this.config),{known_connect_devices:(null!==(t=this.config.known_connect_devices)&&void 0!==t?t:[]).filter((t,i)=>i!=e)}),we(this,"config-changed",{config:this.config}))}getValue(e){var t,i,n,s,a,o,r,l,c,d,h,p,u,g,v,_,y,m,f,w,b,S,C,$,x,k,P,V,D,E,A,T,O,N,z,M,H,L,j,U,R,W,F,I;switch(e){case ae.Name:return null!==(i=null===(t=this.config)||void 0===t?void 0:t.name)&&void 0!==i?i:"";case ae.Account:return null!==(s=null===(n=this.config)||void 0===n?void 0:n.account)&&void 0!==s?s:"default";case ae.Spotify_Entity:const e=this.getMediaPlayerEntities().filter(e=>e.includes("spotify"));return null!==(o=null===(a=this.config)||void 0===a?void 0:a.spotify_entity)&&void 0!==o?o:e.length>0?e[0]:"";case ae.Country_Code:return null!==(l=null===(r=this.config)||void 0===r?void 0:r.country_code)&&void 0!==l?l:"";case ae.Limit:return null!==(d=null===(c=this.config)||void 0===c?void 0:c.limit)&&void 0!==d?d:10;case ae.Playlist_Type:return null!==(p=null===(h=this.config)||void 0===h?void 0:h.playlist_type)&&void 0!==p?p:"default";case ae.Always_Play_Random_Song:return null!==(g=null===(u=this.config)||void 0===u?void 0:u.always_play_random_song)&&void 0!==g&&g;case ae.Height:return null!==(_=null===(v=this.config)||void 0===v?void 0:v.height)&&void 0!==_?_:"";case ae.Display_Style:return null!==(m=null===(y=this.config)||void 0===y?void 0:y.display_style)&&void 0!==m?m:"list";case ae.Grid_Covers_Per_Row:return null!==(w=null===(f=this.config)||void 0===f?void 0:f.grid_covers_per_row)&&void 0!==w?w:5;case ae.Grid_Center_Covers:return null!==(S=null===(b=this.config)||void 0===b?void 0:b.grid_center_covers)&&void 0!==S&&S;case ae.Hide_Warning:return null!==($=null===(C=this.config)||void 0===C?void 0:C.hide_warning)&&void 0!==$&&$;case ae.Default_Device:return null!==(k=null===(x=this.config)||void 0===x?void 0:x.default_device)&&void 0!==k?k:"";case ae.Filter_Devices:return null!==(D=null===(V=null===(P=this.config)||void 0===P?void 0:P.filter_devices)||void 0===V?void 0:V.toString())&&void 0!==D?D:"";case ae.Known_Connect_Devices:return null!==(A=null===(E=this.config)||void 0===E?void 0:E.known_connect_devices)&&void 0!==A?A:[];case ae.Include_Playlists:return null!==(N=null===(O=null===(T=this.config)||void 0===T?void 0:T.include_playlists)||void 0===O?void 0:O.toString())&&void 0!==N?N:"";case ae.Hide_Connect_Devices:return null!==(M=null===(z=this.config)||void 0===z?void 0:z.hide_connect_devices)&&void 0!==M&&M;case ae.Hide_Chromecast_Devices:return null!==(L=null===(H=this.config)||void 0===H?void 0:H.hide_chromecast_devices)&&void 0!==L&&L;case ae.Hide_Top_Header:return null!==(U=null===(j=this.config)||void 0===j?void 0:j.hide_top_header)&&void 0!==U&&U;case ae.Hide_Currently_Playing:return null!==(W=null===(R=this.config)||void 0===R?void 0:R.hide_currently_playing)&&void 0!==W&&W;case ae.Hide_Playback_Controls:return null!==(I=null===(F=this.config)||void 0===F?void 0:F.hide_playback_controls)&&void 0!==I&&I}}renderGeneral(){const e=this.getMediaPlayerEntities();return M`
- ${this.accounts.map(e=>H` ${e} `)} + ${this.accounts.map(e=>M` ${e} `)} - ${e.map(e=>H` ${e} `)} + ${e.map(e=>M` ${e} `)}
- ${Object.values(se).map(e=>H` ${e} `)} + ${Object.values(se).map(e=>M` ${e} `)}
- +
- `}renderAppearance(){return H` + `}renderAppearance(){return M`
- + - +
- + - +
- ${Object.values(ne).map(e=>H` ${e} `)} + ${Object.values(ne).map(e=>M` ${e} `)}
- +
- `}renderAdvanced(){const e=this.getMediaPlayerEntities();return H` + `}renderAdvanced(){const e=this.getMediaPlayerEntities();return M`
- + - +
-

${Le("settings.known_connect_devices")}

+

${Ae("settings.known_connect_devices")}

+ title=${Ae("settings.known_connect_device_add")}>
- ${this.getValue(ae.Known_Connect_Devices).map((t,i)=>H`
+ ${this.getValue(ae.Known_Connect_Devices).map((t,i)=>M`
- ${e.map(e=>H` ${e} `)} + ${e.map(e=>M` ${e} `)} this.removeKnownConnectDevice(i)} icon="hass:close" - title=${Le("settings.known_connect_device_remove")}> + title=${Ae("settings.known_connect_device_remove")}>
`)}
- `}render(){return this.hass?H` + `}render(){return this.hass?M`
- -
${je.general.name}
-
${je.general.secondary}
+ +
${Te.general.name}
+
${Te.general.secondary}
- ${je.general.show?this.renderGeneral():""} + ${Te.general.show?this.renderGeneral():""}
- -
${je.appearance.name}
-
${je.appearance.secondary}
+ +
${Te.appearance.name}
+
${Te.appearance.secondary}
- ${je.appearance.show?this.renderAppearance():""} + ${Te.appearance.show?this.renderAppearance():""}
- -
${je.advanced.name}
-
${je.advanced.secondary}
+ +
${Te.advanced.name}
+
${Te.advanced.secondary}
- ${je.advanced.show?this.renderAdvanced():""} + ${Te.advanced.show?this.renderAdvanced():""}
- `:H``}static get styles(){return ee` + `:M``}static get styles(){return ee` .option { padding: 4px 0px; cursor: pointer; @@ -468,7 +468,7 @@ found at http://polymer.github.io/PATENTS.txt .hidden { display: none; } - `}};e([Z({type:Object})],Ue.prototype,"hass",void 0),e([K()],Ue.prototype,"config",void 0),e([K()],Ue.prototype,"_toggle",void 0),e([K()],Ue.prototype,"chromecast_devices",void 0),Ue=e([q("spotify-card-editor")],Ue);class Re{constructor(e){this.state_ttl=4e3,this.last_state_update_time=0,this.loading=!1,this.parent=e}is_loading(){return setTimeout(this.set_loading_off,100),this.loading}set_loading_off(){this.loading=!1}is_loaded(){return 0!==this.parent.playlists.length}getPlaybackOptions(e){return{uri:e,force_playback:"playing"==this.parent.getSpotifyEntityState(),random_song:this.parent.config.always_play_random_song||!1,account:this.parent.config.account}}playUri(e){const t=this.getCurrentPlayer();if(t)this.playUriOnConnectDevice(t.id,e);else{const t=this.parent.config.default_device;if(t)this.startPlaybackOnDevice(t,e);else{if(!(this.parent.devices.length>0))throw new Error("No device available for playback");{const t=this.parent.devices[0].name;this.startPlaybackOnDevice(t,e)}}}}startPlaybackOnDevice(e,t){var i;const n=this.parent.devices.filter(t=>t.name==e),s=null===(i=this.parent.config.known_connect_devices)||void 0===i?void 0:i.filter(t=>t.name==e);if(n.length>0)return this.playUriOnConnectDevice(n[0].id,t);if(s&&s.length>0)return this.playUriOnConnectDevice(s[0].id,t);{const i=this.parent.chromecast_devices.filter(t=>t.friendly_name==e);if(i.length>0)return this.playUriOnCastDevice(i[0].friendly_name,t);throw new Error("Could not find device: "+e)}}transferPlaybackToCastDevice(e){this.parent.hass.callService("spotcast","start",{device_name:e,force_playback:!0,account:this.parent.config.account})}transferPlaybackToConnectDevice(e){this.parent.hass.callService("spotcast","start",{spotify_device_id:e,force_playback:!0,account:this.parent.config.account})}playUriOnCastDevice(e,t){const i=Object.assign(Object.assign({},this.getPlaybackOptions(t)),{device_name:e});this.parent.hass.callService("spotcast","start",i)}playUriOnConnectDevice(e,t){const i=Object.assign(Object.assign({},this.getPlaybackOptions(t)),{spotify_device_id:e});this.parent.hass.callService("spotcast","start",i)}async updateState(){if(!((new Date).getTime()-this.last_state_update_time(e.indexOf(":")<0&&(e="name:".concat(e)),{key:e.split(":",1)[0],pattern:new RegExp(e.slice(e.indexOf(":")+1).trim())})))&&void 0!==t?t:[],s=n.items.filter(e=>i.some(t=>t.pattern.test(e[t.key])));this.parent.playlists=s}else this.parent.playlists=n.items}catch(e){if(!(e instanceof SyntaxError))throw Error("Failed to filter playlists: "+e);this.parent.playlists=n.items}}catch(e){throw Error("Failed to fetch playlists: "+e)}finally{this.loading=!1}}}const Ye=e=>{let t=[];function i(i,n){e=n?i:Object.assign(Object.assign({},e),i);let s=t;for(let t=0;t(t.push(e),()=>{!function(e){let i=[];for(let n=0;n{if(e[t])return e[t];let s,a=0,o=Ye();const r=()=>i(e).then(e=>o.setState(e,!0)),l=()=>r().catch(t=>{if(e.connected)throw t});return e[t]={get state(){return o.state},refresh:r,subscribe(t){a++,1===a&&(n&&(s=n(e,o)),e.addEventListener("ready",l),l());const i=o.subscribe(t);return void 0!==o.state&&setTimeout(()=>t(o.state),0),()=>{i(),a--,a||(s&&s.then(e=>{e()}),e.removeEventListener("ready",r))}}},e[t]},We=e=>e.sendMessagePromise({type:"get_states"});function Ie(e,t){if(void 0===e)return null;const{domain:i,service:n}=t.data;return{[i]:Object.assign({},e[i],{[n]:{description:"",fields:{}}})}}function Ge(e,t){if(void 0===e)return null;const{domain:i,service:n}=t.data,s=e[i];if(!s||!(n in s))return null;const a={};return Object.keys(s).forEach(e=>{e!==n&&(a[e]=s[e])}),{[i]:a}}const qe=e=>e.sendMessagePromise({type:"get_services"}),Be=(e,t)=>Promise.all([e.subscribeEvents(t.action(Ie),"service_registered"),e.subscribeEvents(t.action(Ge),"service_removed")]).then(e=>()=>e.forEach(e=>e()));async function Ze(e){const t=await We(e),i={};for(let e=0;ee.subscribeEvents(e=>function(e,t){const i=e.state;if(void 0===i)return;const{entity_id:n,new_state:s}=t.data;if(s)e.setState({[s.entity_id]:s});else{const t=Object.assign({},i);delete t[n],e.setState(t,!0)}}(t,e),"state_changed"),Je=(e,t)=>(e=>Fe(e,"_ent",Ze,Ke))(e).subscribe(t);var Qe;function Xe(e,t){if(!t||!oe(t)&&!oe(e)&&e.length!=t.length)return!0;for(const i in e)if(e[i].id!=t[i].id)return!0;return!1}function et(e,t){return!t||!e||(e.state!=t.state||e.attributes.shuffle!=t.attributes.shuffle||e.attributes.media_title!=t.attributes.media_title||e.attributes.media_artist!=t.attributes.media_artist||e.attributes.volume_level!=t.attributes.volume_level)}console.info(`%c SPOTIFY-CARD \n%c ${Le("common.version")} 2.4.0 `,"color: orange; font-weight: bold; background: black","color: white; font-weight: bold; background: dimgray"),window.customCards=window.customCards||[],window.customCards.push({type:"spotify-card",name:"Spotify Card",description:Le("common.description"),preview:!0});let tt=Qe=class extends ie{constructor(){super(),this.playlists=[],this.devices=[],this.chromecast_devices=[],this._spotify_installed=!1,this._fetch_time_out=0,this._last_volume_set_time=0,this.spotcast_connector=new Re(this)}static async getConfigElement(){return document.createElement("spotify-card-editor")}static getStubConfig(){return{}}setConfig(e){let t="";if(e.playlist_type&&!Object.values(se).includes(e.playlist_type.toLowerCase())&&(t="playlist_type"),e.display_style&&!Object.values(ne).includes(e.display_style.toLowerCase())&&(t="display_style"),e.show_error||""!=t)throw new Error(Le("common.invalid_configuration")+": "+t);this.config=e}connectedCallback(){super.connectedCallback(),this.doSubscribeEntities(),this.updateSpotcast()}doSubscribeEntities(){var e;(null===(e=this.hass)||void 0===e?void 0:e.connection)&&!this._unsubscribe_entitites&&this.isConnected&&(this._unsubscribe_entitites=Je(this.hass.connection,e=>this.entitiesUpdated(e)))}entitiesUpdated(e){let t=!1;for(const i in e)i.startsWith("media_player")&&(i==this.config.spotify_entity||!this.config.spotify_entity&&i.startsWith("media_player.spotify")?(this._spotify_installed=!0,this._spotify_state=e[i]):i==this._connect_player_entity_id&&(this._connect_player_state=e[i]),t=!0);t&&!document.hidden&&this.updateSpotcast()}updateSpotcast(){this._fetch_time_out&&clearTimeout(this._fetch_time_out),this._fetch_time_out=setTimeout(async()=>{this.hass&&this.isSpotcastInstalled()&&!this.spotcast_connector.is_loading()&&(await this.spotcast_connector.updateState(),await this.spotcast_connector.fetchPlaylists())},500)}disconnectedCallback(){super.disconnectedCallback(),this._unsubscribe_entitites&&(this._unsubscribe_entitites(),this._unsubscribe_entitites=void 0)}updated(e){var t,i,n;if(super.updated(e),this.updateComplete.then(()=>{for(const e of this.renderRoot.querySelectorAll("[data-spotify-image-url]")){const t=new Image;t.onload=function(t){var i;null===(i=e.firstElementChild)||void 0===i||i.replaceWith(t.srcElement)},e.dataset.spotifyImageUrl&&(t.src=e.dataset.spotifyImageUrl)}}),e.has("player")&&(null===(t=this.player)||void 0===t?void 0:t.device)&&this.player.device.id!=(null===(n=null===(i=e.get("player"))||void 0===i?void 0:i.device)||void 0===n?void 0:n.id)){console.log("player device changed",this.player.device.id);const[,e]=this.getFilteredDevices(),t=e.find(e=>{var t;return e.id==(null===(t=this.player)||void 0===t?void 0:t.device.id)});this._connect_player_entity_id=t?t.entity_id:void 0,this._connect_player_state=void 0}}getDisplayStyle(){var e;return"grid"==(null===(e=this.config.display_style)||void 0===e?void 0:e.toLowerCase())?ne.Grid:ne.List}getPlayingState(){var e,t;return this._connect_player_state?"playing"==this._connect_player_state.state:null!==(t="playing"==(null===(e=this._spotify_state)||void 0===e?void 0:e.state))&&void 0!==t&&t}getShuffleState(){var e,t;return this._connect_player_state?this._connect_player_state.attributes.shuffle:null!==(t=null===(e=this.player)||void 0===e?void 0:e.shuffle_state)&&void 0!==t&&t}getSpotifyEntityState(){return this._spotify_state?this._spotify_state.state:""}getMediaAttribute(e){var t,i,n;return null!==(i=null===(t=this._connect_player_state)||void 0===t?void 0:t.attributes[e])&&void 0!==i?i:null===(n=this._spotify_state)||void 0===n?void 0:n.attributes[e]}isSpotcastInstalled(){var e,t;return!(!(null===(e=this.hass)||void 0===e?void 0:e.connection)||void 0===(t=this.hass.connection,Fe(t,"_srv",qe,Be)).state.spotcast)}checkIfAllowedToShow(e){var t,i;const n=null!==(i=null===(t=this.config.filter_devices)||void 0===t?void 0:t.map(e=>new RegExp(e+"$")))&&void 0!==i?i:[];for(const t of n)if(t.test("name"in e?e.name:e.friendly_name))return!1;return!0}getDefaultDevice(){let[e,t,i]=this.getFilteredDevices();if(e=e.filter(e=>e.name==this.config.default_device),t=t.filter(e=>e.name==this.config.default_device),i=i.filter(e=>e.friendly_name==this.config.default_device),e.length>0||t.length>0||i.length>0)return this.config.default_device}getFilteredDevices(){var e;return[this.config.hide_connect_devices?[]:this.devices.filter(this.checkIfAllowedToShow,this),null!==(e=this.config.known_connect_devices)&&void 0!==e?e:[],this.config.hide_chromecast_devices?[]:this.chromecast_devices.filter(this.checkIfAllowedToShow,this)]}getPlaylists(){return this.playlists}isThisPlaylistPlaying(e){var t;return(null===(t=this._spotify_state)||void 0===t?void 0:t.attributes.media_playlist)===e.name}startUri(e,t){var i;const n=e.target;let s;switch(n.localName){case"img":s=null===(i=n.parentElement)||void 0===i?void 0:i.parentElement;break;case"div":s=n;break;case"p":s=n.parentElement;break;default:console.log(n)}s.classList.add("loading"),setTimeout(()=>{s.classList.remove("loading")},1e4),this.spotcast_connector.playUri(t)}onShuffleSelect(e){var t,i;this.hass.callService("media_player","shuffle_set",{entity_id:null===(i=null!==(t=this._connect_player_state)&&void 0!==t?t:this._spotify_state)||void 0===i?void 0:i.entity_id,shuffle:!this.getShuffleState()});let n=e.target.parentElement;"svg"==(null==n?void 0:n.localName)&&(n=n.parentElement),(null==n?void 0:n.classList.contains("shuffle"))?n.classList.remove("shuffle"):null==n||n.classList.add("shuffle")}handleMediaEvent(e,t){var i;e.stopPropagation(),this._spotify_state&&this.hass.callService("media_player",t,{entity_id:(null!==(i=this._connect_player_state)&&void 0!==i?i:this._spotify_state).entity_id})}getVolume(){var e,t,i;return 100*(null===(i=null===(t=null!==(e=this._connect_player_state)&&void 0!==e?e:this._spotify_state)||void 0===t?void 0:t.attributes)||void 0===i?void 0:i.volume_level)}shouldUpdate(e){let t=!0;return e.forEach((e,i)=>{if("_spotify_state"==i||"_connect_player_state"==i){(new Date).getTime()-this._last_volume_set_time<500&&(t=!1)}}),t}handleVolumeChanged(e){var t,i;if(e.stopPropagation(),this._spotify_state){this.hass.callService("media_player","volume_set",{entity_id:null===(i=null!==(t=this._connect_player_state)&&void 0!==t?t:this._spotify_state)||void 0===i?void 0:i.entity_id,volume_level:e.target.value/100});const n=new Date;this._last_volume_set_time=n.getTime()}}confirmDeviceSelection(e){var t;const i=e.target;null===(t=null==i?void 0:i.parentElement)||void 0===t||t.classList.add("dropdown-content-hide"),setTimeout(()=>{var e;null===(e=null==i?void 0:i.parentElement)||void 0===e||e.classList.remove("dropdown-content-hide")},1e3)}spotifyDeviceSelected(e,t){this.confirmDeviceSelection(e);if(this.spotcast_connector.getCurrentPlayer())return this.spotcast_connector.transferPlaybackToConnectDevice(t.id);const i=this.playlists[0];console.log("spotifyDeviceSelected playing first playlist"),this.spotcast_connector.playUriOnConnectDevice(t.id,i.uri)}knownSpotifyConnectDeviceSelected(e,t){this.confirmDeviceSelection(e);if(this.spotcast_connector.getCurrentPlayer())return this.spotcast_connector.transferPlaybackToConnectDevice(t.id);const i=this.playlists[0];console.log("knownSpotifyConnectDeviceSelected playing first playlist"),this.spotcast_connector.playUriOnConnectDevice(t.id,i.uri)}chromecastDeviceSelected(e,t){this.confirmDeviceSelection(e);if(this.spotcast_connector.getCurrentPlayer())return this.spotcast_connector.transferPlaybackToCastDevice(t.friendly_name);const i=this.playlists[0];console.log("chromecastDeviceSelected playing first playlist"),this.spotcast_connector.playUriOnCastDevice(t.friendly_name,i.uri)}getCurrentPlayer(){return this.spotcast_connector.getCurrentPlayer()}render(){var e,t,i;let n=H``;this.isSpotcastInstalled()||(n=this.showWarning(Le("common.show_missing_spotcast")));let s=H`
Loading...
`;if(this.spotcast_connector.is_loaded())switch(this.getDisplayStyle()){case ne.Grid:s=this.generateGridView();break;default:s=this.generateListView()}const a=H``,o=this.generateDeviceList();return M` ${this.config.hide_warning?"":n} ${this.config.hide_top_header?null:a} - ${this._spotify_state&&!this.config.hide_currently_playing&&this.getMediaAttribute("media_title")&&this.getMediaAttribute("media_artist")?H`
+ ${this._spotify_state&&!this.config.hide_currently_playing&&this.getMediaAttribute("media_title")&&this.getMediaAttribute("media_artist")?M`
${this.getMediaAttribute("media_title")} - ${this.getMediaAttribute("media_artist")}
`:null}
${s}
@@ -502,22 +502,22 @@ found at http://polymer.github.io/PATENTS.txt stroke="null" /> - ${null!==(i=null!==(t=null===(e=this.getCurrentPlayer())||void 0===e?void 0:e.name)&&void 0!==t?t:this.getDefaultDevice())&&void 0!==i?i:Le("common.choose_player")} + ${null!==(i=null!==(t=null===(e=this.getCurrentPlayer())||void 0===e?void 0:e.name)&&void 0!==t?t:this.getDefaultDevice())&&void 0!==i?i:Ae("common.choose_player")}
`)}return M`
${e}
`}generateGridView(){var e;const t=[],i=this.getPlaylists();for(let n=0;nthis.startUri(e,s.uri)}>
- ${this.config.grid_show_title?H`
${s.name}
`:null} + ${this.config.grid_show_title?M`
${s.name}
`:null}
-
`)}const n=this.config.grid_covers_per_row?this.config.grid_covers_per_row:3;return H`
+
`)}const n=this.config.grid_covers_per_row?this.config.grid_covers_per_row:3;return M`
${t} -
`}onPauseSelect(e){this.handleMediaEvent(e,"media_pause")}onResumeSelect(e){this.handleMediaEvent(e,"media_play")}onNextSelect(e){this.handleMediaEvent(e,"media_next_track")}onPrevSelect(e){this.handleMediaEvent(e,"media_previous_track")}showWarning(e){return H`${e}`}static get styles(){return[Qe.generalStyles,Qe.listStyles,Qe.gridStyles]}};tt.generalStyles=ee` +
`}onPauseSelect(e){this.handleMediaEvent(e,"media_pause")}onResumeSelect(e){this.handleMediaEvent(e,"media_play")}onNextSelect(e){this.handleMediaEvent(e,"media_next_track")}onPrevSelect(e){this.handleMediaEvent(e,"media_previous_track")}showWarning(e){return M`${e}`}static get styles(){return[Ge.generalStyles,Ge.listStyles,Ge.gridStyles]}};Ke.generalStyles=ee` *:focus { outline: none; } @@ -842,7 +842,7 @@ found at http://polymer.github.io/PATENTS.txt .list-item.loading { animation-name: loading-list; } - `,tt.listStyles=ee` + `,Ke.listStyles=ee` ha-card { --list-item-height: 3em; --placeholder-padding: 4px; @@ -891,7 +891,7 @@ found at http://polymer.github.io/PATENTS.txt .list-item > p { margin: 0 0.5em 0 0.5em; } - `,tt.gridStyles=ee` + `,Ke.gridStyles=ee` .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(30%, 1fr)); @@ -942,5 +942,4 @@ found at http://polymer.github.io/PATENTS.txt rgba(var(--rgb-primary-text-color), 0.6) ); } - `,e([Z({type:Object})],tt.prototype,"config",void 0),e([Z({hasChanged:Xe})],tt.prototype,"playlists",void 0),e([Z({hasChanged:Xe})],tt.prototype,"devices",void 0),e([Z({hasChanged:Xe})],tt.prototype,"chromecast_devices",void 0),e([Z({hasChanged:Xe})],tt.prototype,"player",void 0),e([K({hasChanged:et})],tt.prototype,"_spotify_state",void 0),e([K({hasChanged:et})],tt.prototype,"_connect_player_state",void 0),tt=Qe=e([q("spotify-card")],tt);export{tt as SpotifyCard,Xe as hasChangedCustom,et as hasChangedMediaPlayer}; -//# sourceMappingURL=spotify-card.js.map + `,e([Z({type:Object})],Ke.prototype,"config",void 0),e([Z({hasChanged:qe})],Ke.prototype,"playlists",void 0),e([Z({hasChanged:qe})],Ke.prototype,"devices",void 0),e([Z({hasChanged:qe})],Ke.prototype,"chromecast_devices",void 0),e([Z({hasChanged:qe})],Ke.prototype,"player",void 0),e([J({hasChanged:Be})],Ke.prototype,"_spotify_state",void 0),e([J({hasChanged:Be})],Ke.prototype,"_connect_player_state",void 0),Ke=Ge=e([B("spotify-card")],Ke);export{Ke as SpotifyCard,qe as hasChangedCustom,Be as hasChangedMediaPlayer}; From f69f1db9f2947f11f86ac0d39e630e5b1067898c Mon Sep 17 00:00:00 2001 From: Graham McMicken Date: Mon, 7 Nov 2022 21:09:43 -0800 Subject: [PATCH 3/8] Skip on-click event for device selection --- src/spotify-card.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/spotify-card.ts b/src/spotify-card.ts index 1e72aa7..7648cf6 100755 --- a/src/spotify-card.ts +++ b/src/spotify-card.ts @@ -418,7 +418,7 @@ export class SpotifyCard extends LitElement { } private spotifyDeviceSelected(elem: MouseEvent, device: ConnectDevice): void { - this.confirmDeviceSelection(elem); + this.confirmDeviceSelection(elem); return; const current_player = this.spotcast_connector.getCurrentPlayer(); if (current_player) { return this.spotcast_connector.transferPlaybackToConnectDevice(device.id); @@ -429,7 +429,7 @@ export class SpotifyCard extends LitElement { } private knownSpotifyConnectDeviceSelected(elem: MouseEvent, device: KnownConnectDevice): void { - this.confirmDeviceSelection(elem); + this.confirmDeviceSelection(elem); return; const current_player = this.spotcast_connector.getCurrentPlayer(); if (current_player) { return this.spotcast_connector.transferPlaybackToConnectDevice(device.id); @@ -440,7 +440,7 @@ export class SpotifyCard extends LitElement { } private chromecastDeviceSelected(elem: MouseEvent, device: ChromecastDevice): void { - this.confirmDeviceSelection(elem); + this.confirmDeviceSelection(elem); return; const current_player = this.spotcast_connector.getCurrentPlayer(); if (current_player) { return this.spotcast_connector.transferPlaybackToCastDevice(device.friendly_name); From 915adc9ba45683632ea61eea703a73bddcafa7f4 Mon Sep 17 00:00:00 2001 From: Graham McMicken Date: Mon, 7 Nov 2022 21:20:04 -0800 Subject: [PATCH 4/8] Skip on-click event for device selection --- dist/spotify-card.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/spotify-card.js b/dist/spotify-card.js index 0fb0f1c..b7cec4f 100644 --- a/dist/spotify-card.js +++ b/dist/spotify-card.js @@ -468,7 +468,7 @@ found at http://polymer.github.io/PATENTS.txt .hidden { display: none; } - `}};e([Z({type:Object})],Oe.prototype,"hass",void 0),e([J()],Oe.prototype,"config",void 0),e([J()],Oe.prototype,"_toggle",void 0),e([J()],Oe.prototype,"chromecast_devices",void 0),Oe=e([B("spotify-card-editor")],Oe);class Ne{constructor(e){this.state_ttl=4e3,this.last_state_update_time=0,this.loading=!1,this.parent=e}is_loading(){return setTimeout(this.set_loading_off,100),this.loading}set_loading_off(){this.loading=!1}is_loaded(){return 0!==this.parent.playlists.length}getPlaybackOptions(e){return{uri:e,force_playback:"playing"==this.parent.getSpotifyEntityState(),random_song:this.parent.config.always_play_random_song||!1,account:this.parent.config.account}}playUri(e){const t=this.getCurrentPlayer();if(t)this.playUriOnConnectDevice(t.id,e);else{const t=this.parent.config.default_device;if(t)this.startPlaybackOnDevice(t,e);else{if(!(this.parent.devices.length>0))throw new Error("No device available for playback");{const t=this.parent.devices[0].name;this.startPlaybackOnDevice(t,e)}}}}startPlaybackOnDevice(e,t){var i;const n=this.parent.devices.filter(t=>t.name==e),s=null===(i=this.parent.config.known_connect_devices)||void 0===i?void 0:i.filter(t=>t.name==e);if(n.length>0)return this.playUriOnConnectDevice(n[0].id,t);if(s&&s.length>0)return this.playUriOnConnectDevice(s[0].id,t);{const i=this.parent.chromecast_devices.filter(t=>t.friendly_name==e);if(i.length>0)return this.playUriOnCastDevice(i[0].friendly_name,t);throw new Error("Could not find device: "+e)}}transferPlaybackToCastDevice(e){this.parent.hass.callService("spotcast","start",{device_name:e,force_playback:!0,account:this.parent.config.account})}transferPlaybackToConnectDevice(e){this.parent.hass.callService("spotcast","start",{spotify_device_id:e,force_playback:!0,account:this.parent.config.account})}playUriOnCastDevice(e,t){const i=Object.assign(Object.assign({},this.getPlaybackOptions(t)),{device_name:e});this.parent.hass.callService("spotcast","start",i)}playUriOnConnectDevice(e,t){const i=Object.assign(Object.assign({},this.getPlaybackOptions(t)),{spotify_device_id:e});this.parent.hass.callService("spotcast","start",i)}async updateState(){if(!((new Date).getTime()-this.last_state_update_time(e.indexOf(":")<0&&(e="name:".concat(e)),{key:e.split(":",1)[0],pattern:new RegExp(e.slice(e.indexOf(":")+1).trim())})))&&void 0!==t?t:[],s=n.items.filter(e=>i.some(t=>t.pattern.test(e[t.key])));this.parent.playlists=s}else this.parent.playlists=n.items}catch(e){if(!(e instanceof SyntaxError))throw Error("Failed to filter playlists: "+e);this.parent.playlists=n.items}}catch(e){throw Error("Failed to fetch playlists: "+e)}finally{this.loading=!1}}}const ze=e=>{let t=[];function i(i,n){e=n?i:Object.assign(Object.assign({},e),i);let s=t;for(let t=0;t(t.push(e),()=>{!function(e){let i=[];for(let n=0;n{if(e[t])return e[t];let s,a=0,o=ze();const r=()=>i(e).then(e=>o.setState(e,!0)),l=()=>r().catch(t=>{if(e.connected)throw t});return e[t]={get state(){return o.state},refresh:r,subscribe(t){a++,1===a&&(n&&(s=n(e,o)),e.addEventListener("ready",l),l());const i=o.subscribe(t);return void 0!==o.state&&setTimeout(()=>t(o.state),0),()=>{i(),a--,a||(s&&s.then(e=>{e()}),e.removeEventListener("ready",r))}}},e[t]},He=e=>e.sendMessagePromise({type:"get_states"});function Le(e,t){if(void 0===e)return null;const{domain:i,service:n}=t.data;return{[i]:Object.assign({},e[i],{[n]:{description:"",fields:{}}})}}function je(e,t){if(void 0===e)return null;const{domain:i,service:n}=t.data,s=e[i];if(!s||!(n in s))return null;const a={};return Object.keys(s).forEach(e=>{e!==n&&(a[e]=s[e])}),{[i]:a}}const Ue=e=>e.sendMessagePromise({type:"get_services"}),Re=(e,t)=>Promise.all([e.subscribeEvents(t.action(Le),"service_registered"),e.subscribeEvents(t.action(je),"service_removed")]).then(e=>()=>e.forEach(e=>e()));async function We(e){const t=await He(e),i={};for(let e=0;ee.subscribeEvents(e=>function(e,t){const i=e.state;if(void 0===i)return;const{entity_id:n,new_state:s}=t.data;if(s)e.setState({[s.entity_id]:s});else{const t=Object.assign({},i);delete t[n],e.setState(t,!0)}}(t,e),"state_changed"),Ie=(e,t)=>(e=>Me(e,"_ent",We,Fe))(e).subscribe(t);var Ge;function qe(e,t){if(!t||!oe(t)&&!oe(e)&&e.length!=t.length)return!0;for(const i in e)if(e[i].id!=t[i].id)return!0;return!1}function Be(e,t){return!t||!e||(e.state!=t.state||e.attributes.shuffle!=t.attributes.shuffle||e.attributes.media_title!=t.attributes.media_title||e.attributes.media_artist!=t.attributes.media_artist||e.attributes.volume_level!=t.attributes.volume_level)}console.info(`%c SPOTIFY-CARD \n%c ${Ae("common.version")} 2.4.0 `,"color: orange; font-weight: bold; background: black","color: white; font-weight: bold; background: dimgray"),window.customCards=window.customCards||[],window.customCards.push({type:"spotify-card",name:"Spotify Card",description:Ae("common.description"),preview:!0});let Ke=Ge=class extends ie{constructor(){super(),this.playlists=[],this.devices=[],this.chromecast_devices=[],this._spotify_installed=!1,this._fetch_time_out=0,this._last_volume_set_time=0,this.spotcast_connector=new Ne(this)}static async getConfigElement(){return document.createElement("spotify-card-editor")}static getStubConfig(){return{}}setConfig(e){let t="";if(e.playlist_type&&!Object.values(se).includes(e.playlist_type.toLowerCase())&&(t="playlist_type"),e.display_style&&!Object.values(ne).includes(e.display_style.toLowerCase())&&(t="display_style"),e.show_error||""!=t)throw new Error(Ae("common.invalid_configuration")+": "+t);this.config=e}connectedCallback(){super.connectedCallback(),this.doSubscribeEntities(),this.updateSpotcast()}doSubscribeEntities(){var e;(null===(e=this.hass)||void 0===e?void 0:e.connection)&&!this._unsubscribe_entitites&&this.isConnected&&(this._unsubscribe_entitites=Ie(this.hass.connection,e=>this.entitiesUpdated(e)))}entitiesUpdated(e){let t=!1;for(const i in e)i.startsWith("media_player")&&(i==this.config.spotify_entity||!this.config.spotify_entity&&i.startsWith("media_player.spotify")?(this._spotify_installed=!0,this._spotify_state=e[i]):i==this._connect_player_entity_id&&(this._connect_player_state=e[i]),t=!0);t&&!document.hidden&&this.updateSpotcast()}updateSpotcast(){this._fetch_time_out&&clearTimeout(this._fetch_time_out),this._fetch_time_out=setTimeout(async()=>{this.hass&&this.isSpotcastInstalled()&&!this.spotcast_connector.is_loading()&&(await this.spotcast_connector.updateState(),await this.spotcast_connector.fetchPlaylists())},500)}disconnectedCallback(){super.disconnectedCallback(),this._unsubscribe_entitites&&(this._unsubscribe_entitites(),this._unsubscribe_entitites=void 0)}updated(e){var t,i,n;if(super.updated(e),this.updateComplete.then(()=>{for(const e of this.renderRoot.querySelectorAll("[data-spotify-image-url]")){const t=new Image;t.onload=function(t){var i;null===(i=e.firstElementChild)||void 0===i||i.replaceWith(t.srcElement)},e.dataset.spotifyImageUrl&&(t.src=e.dataset.spotifyImageUrl)}}),e.has("player")&&(null===(t=this.player)||void 0===t?void 0:t.device)&&this.player.device.id!=(null===(n=null===(i=e.get("player"))||void 0===i?void 0:i.device)||void 0===n?void 0:n.id)){console.log("player device changed",this.player.device.id);const[,e]=this.getFilteredDevices(),t=e.find(e=>{var t;return e.id==(null===(t=this.player)||void 0===t?void 0:t.device.id)});this._connect_player_entity_id=t?t.entity_id:void 0,this._connect_player_state=void 0}}getDisplayStyle(){var e;return"grid"==(null===(e=this.config.display_style)||void 0===e?void 0:e.toLowerCase())?ne.Grid:ne.List}getPlayingState(){var e,t;return this._connect_player_state?"playing"==this._connect_player_state.state:null!==(t="playing"==(null===(e=this._spotify_state)||void 0===e?void 0:e.state))&&void 0!==t&&t}getShuffleState(){var e,t;return this._connect_player_state?this._connect_player_state.attributes.shuffle:null!==(t=null===(e=this.player)||void 0===e?void 0:e.shuffle_state)&&void 0!==t&&t}getSpotifyEntityState(){return this._spotify_state?this._spotify_state.state:""}getMediaAttribute(e){var t,i,n;return null!==(i=null===(t=this._connect_player_state)||void 0===t?void 0:t.attributes[e])&&void 0!==i?i:null===(n=this._spotify_state)||void 0===n?void 0:n.attributes[e]}isSpotcastInstalled(){var e,t;return!(!(null===(e=this.hass)||void 0===e?void 0:e.connection)||void 0===(t=this.hass.connection,Me(t,"_srv",Ue,Re)).state.spotcast)}checkIfAllowedToShow(e){var t,i;const n=null!==(i=null===(t=this.config.filter_devices)||void 0===t?void 0:t.map(e=>new RegExp(e+"$")))&&void 0!==i?i:[];for(const t of n)if(t.test("name"in e?e.name:e.friendly_name))return!1;return!0}getDefaultDevice(){let[e,t,i]=this.getFilteredDevices();if(e=e.filter(e=>e.name==this.config.default_device),t=t.filter(e=>e.name==this.config.default_device),i=i.filter(e=>e.friendly_name==this.config.default_device),e.length>0||t.length>0||i.length>0)return this.config.default_device}getFilteredDevices(){var e;return[this.config.hide_connect_devices?[]:this.devices.filter(this.checkIfAllowedToShow,this),null!==(e=this.config.known_connect_devices)&&void 0!==e?e:[],this.config.hide_chromecast_devices?[]:this.chromecast_devices.filter(this.checkIfAllowedToShow,this)]}getPlaylists(){return this.playlists}isThisPlaylistPlaying(e){var t;return(null===(t=this._spotify_state)||void 0===t?void 0:t.attributes.media_playlist)===e.name}startUri(e,t){var i;const n=e.target;let s;switch(n.localName){case"img":s=null===(i=n.parentElement)||void 0===i?void 0:i.parentElement;break;case"div":s=n;break;case"p":s=n.parentElement;break;default:console.log(n)}s.classList.add("loading"),setTimeout(()=>{s.classList.remove("loading")},1e4),this.spotcast_connector.playUri(t)}onShuffleSelect(e){var t,i;this.hass.callService("media_player","shuffle_set",{entity_id:null===(i=null!==(t=this._connect_player_state)&&void 0!==t?t:this._spotify_state)||void 0===i?void 0:i.entity_id,shuffle:!this.getShuffleState()});let n=e.target.parentElement;"svg"==(null==n?void 0:n.localName)&&(n=n.parentElement),(null==n?void 0:n.classList.contains("shuffle"))?n.classList.remove("shuffle"):null==n||n.classList.add("shuffle")}handleMediaEvent(e,t){var i;e.stopPropagation(),this._spotify_state&&this.hass.callService("media_player",t,{entity_id:(null!==(i=this._connect_player_state)&&void 0!==i?i:this._spotify_state).entity_id})}getVolume(){var e,t,i;return 100*(null===(i=null===(t=null!==(e=this._connect_player_state)&&void 0!==e?e:this._spotify_state)||void 0===t?void 0:t.attributes)||void 0===i?void 0:i.volume_level)}shouldUpdate(e){let t=!0;return e.forEach((e,i)=>{if("_spotify_state"==i||"_connect_player_state"==i){(new Date).getTime()-this._last_volume_set_time<500&&(t=!1)}}),t}handleVolumeChanged(e){var t,i;if(e.stopPropagation(),this._spotify_state){this.hass.callService("media_player","volume_set",{entity_id:null===(i=null!==(t=this._connect_player_state)&&void 0!==t?t:this._spotify_state)||void 0===i?void 0:i.entity_id,volume_level:e.target.value/100});const n=new Date;this._last_volume_set_time=n.getTime()}}confirmDeviceSelection(e){var t;const i=e.target;null===(t=null==i?void 0:i.parentElement)||void 0===t||t.classList.add("dropdown-content-hide"),setTimeout(()=>{var e;null===(e=null==i?void 0:i.parentElement)||void 0===e||e.classList.remove("dropdown-content-hide")},1e3)}spotifyDeviceSelected(e,t){this.confirmDeviceSelection(e);if(this.spotcast_connector.getCurrentPlayer())return this.spotcast_connector.transferPlaybackToConnectDevice(t.id);const i=this.playlists[0];console.log("spotifyDeviceSelected playing first playlist"),this.spotcast_connector.playUriOnConnectDevice(t.id,i.uri)}knownSpotifyConnectDeviceSelected(e,t){this.confirmDeviceSelection(e);if(this.spotcast_connector.getCurrentPlayer())return this.spotcast_connector.transferPlaybackToConnectDevice(t.id);const i=this.playlists[0];console.log("knownSpotifyConnectDeviceSelected playing first playlist"),this.spotcast_connector.playUriOnConnectDevice(t.id,i.uri)}chromecastDeviceSelected(e,t){this.confirmDeviceSelection(e);if(this.spotcast_connector.getCurrentPlayer())return this.spotcast_connector.transferPlaybackToCastDevice(t.friendly_name);const i=this.playlists[0];console.log("chromecastDeviceSelected playing first playlist"),this.spotcast_connector.playUriOnCastDevice(t.friendly_name,i.uri)}getCurrentPlayer(){return this.spotcast_connector.getCurrentPlayer()}render(){var e,t,i;let n=M``;this.isSpotcastInstalled()||(n=this.showWarning(Ae("common.show_missing_spotcast")));let s=M`
Loading...
`;if(this.spotcast_connector.is_loaded())switch(this.getDisplayStyle()){case ne.Grid:s=this.generateGridView();break;default:s=this.generateListView()}const a=M`