/**
 * Minified by jsDelivr using Terser v5.19.2.
 * Original file: /npm/rgb-light-card@1.13.0/card.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
class RGBLightCard extends HTMLElement{set hass(t){this._hass=t,this.content||(this.init(),this.update()),this.setVisibility()}get isInTile(){return"RGBLightCardFeature"===this.constructor.name}init(){let t=this.attachShadow({mode:"open"});t.appendChild(RGBLightCard.getStaticCSS()),this.content=document.createElement("div"),this.content.className="wrapper",this.content.onclick=t=>t.stopPropagation(),t.appendChild(this.content)}update(){this.content.innerHTML="",this.content.appendChild(this.getDynamicCSS());for(const t of this.config.colors){const e=document.createElement("div");e.className="color";const r=document.createElement("div");r.className="color-circle",r.style.background=RGBLightCard.getCSSColor(t),r.addEventListener("click",(()=>this.applyColor(t))),e.appendChild(r);const i=document.createElement("div");i.className="color-label",i.innerHTML=t.label||"",e.appendChild(i),this.content.appendChild(e)}}getDynamicCSS(){const t=parseFloat(this.config.size)||32,e=parseFloat(this.config.label_size)||12,r=document.createElement("style");return r.textContent=`\n        .wrapper { \n            justify-content: ${RGBLightCard.getJustify(this.config.justify)};\n            margin-bottom: -${t/8}px;\n            margin-left: ${this.isInTile?-t/4:0}px;\n            margin-right: ${this.isInTile?-t/4:0}px;\n        }\n        .wrapper.hidden { display: none; }\n        .color-circle {  width: ${t}px; height: ${t}px; margin: ${t/8}px ${t/4}px ${t/4}px; }\n        .color-label { font-size: ${e}px; margin-bottom: ${t/8}px; }\n        `.replace(/\s\s+/g," "),r}static getStaticCSS(){const t=document.createElement("style");return t.textContent="\n        .wrapper { cursor: auto; display: flex; flex-wrap: wrap; }\n        .color { flex-basis: 0px; }\n        .color-circle {\n            border-radius: 50%; cursor: pointer; transition: box-shadow 0.15s ease-in-out;\n            box-shadow: 0 3px 1px -2px rgba(0,0,0,.2), 0 2px 2px 0 rgba(0,0,0,.14), 0 1px 5px 0 rgba(0,0,0,.12);\n        }\n        .color-circle:hover {\n            box-shadow: 0 5px 5px -3px rgba(0,0,0,.2), 0 8px 10px 1px rgba(0,0,0,.14), 0 3px 14px 2px rgba(0,0,0,.12)\n        }\n        .color-label {\n            color: var(--primary-text-color);\n            text-align: center;\n            overflow-wrap: anywhere;\n        }\n        ".replace(/\s\s+/g," "),t}setConfig(t){const e=RGBLightCard.ensureBackwardCompatibility(t);if(!Array.isArray(e.colors))throw new Error("You need to define an array of colors");if(e.entity&&0!==e.entity.indexOf("light."))throw new Error(`Entity '${e.entity}' must be a light`);for(const t in e.colors){const r=e.colors[t],i=r.type||"light";if(-1===["light","action"].indexOf(i))throw new Error(`Invalid type '${i}' for colors[${t}]`);if("light"===i&&!e.entity&&!r.entity_id)throw new Error(`You need to define entity or colors[${t}].entity_id`);if("light"===i&&r.entity_id&&0!==r.entity_id.indexOf("light."))throw new Error(`colors[${t}].entity_id '${r.entity_id}' must be a valid light entity`);if("action"===i&&!r.action)throw new Error(`You need to define colors[${t}].action`);if("action"===i&&2!==r.action.split(".").length)throw new Error(`colors[${t}].action '${r.action}' must be a valid action`)}this.config=e,this.content&&this.update()}applyColor(t){if(this.fireHapticFeedback(),"action"===t.type){const[e,r]=t.action.split(".");return void this._hass.callService(e,r,t.data||{})}const e={entity_id:this.config.entity,...t,icon_color:void 0,type:void 0,label:void 0};this._hass.callService("light","turn_on",e)}setVisibility(){if(this.content&&this.config&&this.config.entity&&this._hass&&this._hass.states&&this._hass.states.hasOwnProperty(this.config.entity)){const t=-1!==["off","unavailable"].indexOf(this._hass.states[this.config.entity].state),e=this.config.hide_when_off&&t;this.content.className=e?"wrapper hidden":"wrapper"}}fireHapticFeedback(){const t=new Event("haptic",{bubbles:!0,cancelable:!1,composed:!0});t.detail="light",window.dispatchEvent(t)}static ensureBackwardCompatibility(t){const e=JSON.parse(JSON.stringify(t));return e.colors&&Array.isArray(e.colors)?(e.colors=e.colors.map(((t,e)=>(t&&("call-service"===t.type&&(t.type="action"),t.service&&(t.action=t.service,delete t.service),t.service_data&&(t.data=t.service_data,delete t.service_data)),t))),e):e}static getCSSColor(t){if(t.icon_color)return t.icon_color;if(t.color_name)return t.color_name;if(t.color_temp||t.kelvin){let e=parseInt(t.color_temp,10)||Math.round(1e6/parseInt(t.kelvin,10));e=Math.max(154,Math.min(500,e));const r=327,i=[[166,209,255],[255,255,255],[255,160,0]].slice(e<r?0:1),o=[154,r,500].slice(e<r?0:1);return`rgb(${[0,1,2].map((t=>(e-o[0])*(i[1][t]-i[0][t])/(o[1]-o[0])+i[0][t])).map(Math.round).join(",")})`}if(Array.isArray(t.rgb_color)&&3===t.rgb_color.length)return`rgb(${t.rgb_color.join(",")})`;if(Array.isArray(t.rgbw_color)&&4===t.rgbw_color.length)return`rgb(${t.rgbw_color.slice(0,3).join(",")})`;if(Array.isArray(t.rgbww_color)&&5===t.rgbww_color.length)return`rgb(${t.rgbww_color.slice(0,3).join(",")})`;if(Array.isArray(t.hs_color)&&2===t.hs_color.length)return`hsl(${t.hs_color[0]},100%,${100-t.hs_color[1]/2}%)`;if(Array.isArray(t.xy_color)&&2===t.xy_color.length){return`rgb(${this.xyToRGB(t.xy_color[0],t.xy_color[1],255).join(",")})`}return t.brightness?`rgba(253,216,53,${t.brightness/255})`:t.brightness_pct?`rgba(253,216,53,${t.brightness_pct/100})`:"#7F848E"}static xyToRGB(t,e,r){let i=r/255,o=i/e*t,n=i/e*(1-t-e),a=[1.656492*o-.354851*i-.255038*n,.707196*-o+1.655397*i+.036152*n,.051713*o-.121364*i+1.01153*n];a=a.map((t=>t<=.0031308?12.92*t:1.055*Math.pow(t,1/2.4)-.055)).map((t=>Math.max(t,0)));let s=Math.max(...a);return a.map((t=>s>1?t/s:t)).map((t=>Math.floor(255*t)))}static getJustify(t){return{left:"flex-start",right:"flex-end",center:"center",between:"space-between",around:"space-around"}[t]||"flex-start"}static getSupportedEntityIds(t){return Object.values(t.states).filter((t=>t.entity_id.startsWith("light.")&&t.attributes&&t.attributes.supported_color_modes&&t.attributes.supported_color_modes.find((t=>-1!==["hs","rgb","xy"].indexOf(t))))).map((t=>t.entity_id))}static getExampleColors(){return[{rgb_color:[234,136,140],brightness:255,transition:1},{rgb_color:[251,180,139],brightness:200,transition:1},{rgb_color:[136,198,237],brightness:150,transition:1},{rgb_color:[140,231,185],brightness:100,transition:1}]}static getStubConfig(t){const e=RGBLightCard.getSupportedEntityIds(t)[0]||"light.example_light";return{type:"entities",show_header_toggle:!1,entities:[{entity:e},{type:"custom:rgb-light-card",entity:e,colors:RGBLightCard.getExampleColors()}]}}}class RGBLightCardFeature extends RGBLightCard{static getStubConfig(t,e){let r=e?e.entity_id:void 0;if(!r||!r.startsWith("light.")){r=RGBLightCard.getSupportedEntityIds(t)[0]||"light.example_light"}return{type:"custom:rgb-light-card-feature",entity:r,colors:RGBLightCard.getExampleColors()}}}customElements.define("rgb-light-card",RGBLightCard),customElements.define("rgb-light-card-feature",RGBLightCardFeature),window.customCards=window.customCards||[],window.customCards.push({type:"rgb-light-card",name:"RGB Light Card",description:"A custom card for RGB lights",preview:!0}),window.customCardFeatures=window.customCardFeatures||[],window.customCardFeatures.push({type:"rgb-light-card-feature",name:"RGB Light Card (Tile feature)",configurable:!0}),console.info("\n %c RGB Light Card %c v1.13.0 %c \n","background-color: #555;color: #fff;padding: 3px 2px 3px 3px;border-radius: 3px 0 0 3px;font-family: DejaVu Sans,Verdana,Geneva,sans-serif;text-shadow: 0 1px 0 rgba(1, 1, 1, 0.3)","background-color: #bc81e0;background-image: linear-gradient(90deg, #b65cff, #11cbfa);color: #fff;padding: 3px 3px 3px 2px;border-radius: 0 3px 3px 0;font-family: DejaVu Sans,Verdana,Geneva,sans-serif;text-shadow: 0 1px 0 rgba(1, 1, 1, 0.3)","background-color: transparent");
//# sourceMappingURL=/sm/55ae51e56325e476947f2bfa4d2c72a8a80189b806535200155f5d94b5ffb4c4.map