diff --git a/custom_components/browser_mod/browser_mod.js b/custom_components/browser_mod/browser_mod.js index 864a6fd..92ce671 100644 --- a/custom_components/browser_mod/browser_mod.js +++ b/custom_components/browser_mod/browser_mod.js @@ -1,3 +1,64 @@ +/*! ***************************************************************************** +Copyright (c) Microsoft Corporation. + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. +***************************************************************************** */ + +function __decorate(decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +} + +/** + * @license + * Copyright 2019 Google LLC + * SPDX-License-Identifier: BSD-3-Clause + */ +const t$2=window.ShadowRoot&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,e$5=Symbol(),n$4=new Map;class s$3{constructor(t,n){if(this._$cssResult$=!0,n!==e$5)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t;}get styleSheet(){let e=n$4.get(this.cssText);return t$2&&void 0===e&&(n$4.set(this.cssText,e=new CSSStyleSheet),e.replaceSync(this.cssText)),e}toString(){return this.cssText}}const o$4=t=>new s$3("string"==typeof t?t:t+"",e$5),r$2=(t,...n)=>{const o=1===t.length?t[0]:n.reduce(((e,n,s)=>e+(t=>{if(!0===t._$cssResult$)return t.cssText;if("number"==typeof t)return t;throw Error("Value passed to 'css' function must be a 'css' function result: "+t+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(n)+t[s+1]),t[0]);return new s$3(o,e$5)},i$3=(e,n)=>{t$2?e.adoptedStyleSheets=n.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet)):n.forEach((t=>{const n=document.createElement("style"),s=window.litNonce;void 0!==s&&n.setAttribute("nonce",s),n.textContent=t.cssText,e.appendChild(n);}));},S$1=t$2?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const n of t.cssRules)e+=n.cssText;return o$4(e)})(t):t; + +/** + * @license + * Copyright 2017 Google LLC + * SPDX-License-Identifier: BSD-3-Clause + */var s$2;const e$4=window.trustedTypes,r$1=e$4?e$4.emptyScript:"",h$1=window.reactiveElementPolyfillSupport,o$3={toAttribute(t,i){switch(i){case Boolean:t=t?r$1:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t);}return t},fromAttribute(t,i){let s=t;switch(i){case Boolean:s=null!==t;break;case Number:s=null===t?null:Number(t);break;case Object:case Array:try{s=JSON.parse(t);}catch(t){s=null;}}return s}},n$3=(t,i)=>i!==t&&(i==i||t==t),l$2={attribute:!0,type:String,converter:o$3,reflect:!1,hasChanged:n$3};class a$1 extends HTMLElement{constructor(){super(),this._$Et=new Map,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Ei=null,this.o();}static addInitializer(t){var i;null!==(i=this.l)&&void 0!==i||(this.l=[]),this.l.push(t);}static get observedAttributes(){this.finalize();const t=[];return this.elementProperties.forEach(((i,s)=>{const e=this._$Eh(s,i);void 0!==e&&(this._$Eu.set(e,s),t.push(e));})),t}static createProperty(t,i=l$2){if(i.state&&(i.attribute=!1),this.finalize(),this.elementProperties.set(t,i),!i.noAccessor&&!this.prototype.hasOwnProperty(t)){const s="symbol"==typeof t?Symbol():"__"+t,e=this.getPropertyDescriptor(t,s,i);void 0!==e&&Object.defineProperty(this.prototype,t,e);}}static getPropertyDescriptor(t,i,s){return {get(){return this[i]},set(e){const r=this[t];this[i]=e,this.requestUpdate(t,r,s);},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)||l$2}static finalize(){if(this.hasOwnProperty("finalized"))return !1;this.finalized=!0;const t=Object.getPrototypeOf(this);if(t.finalize(),this.elementProperties=new Map(t.elementProperties),this._$Eu=new Map,this.hasOwnProperty("properties")){const t=this.properties,i=[...Object.getOwnPropertyNames(t),...Object.getOwnPropertySymbols(t)];for(const s of i)this.createProperty(s,t[s]);}return this.elementStyles=this.finalizeStyles(this.styles),!0}static finalizeStyles(i){const s=[];if(Array.isArray(i)){const e=new Set(i.flat(1/0).reverse());for(const i of e)s.unshift(S$1(i));}else void 0!==i&&s.push(S$1(i));return s}static _$Eh(t,i){const s=i.attribute;return !1===s?void 0:"string"==typeof s?s:"string"==typeof t?t.toLowerCase():void 0}o(){var t;this._$Ep=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$Em(),this.requestUpdate(),null===(t=this.constructor.l)||void 0===t||t.forEach((t=>t(this)));}addController(t){var i,s;(null!==(i=this._$Eg)&&void 0!==i?i:this._$Eg=[]).push(t),void 0!==this.renderRoot&&this.isConnected&&(null===(s=t.hostConnected)||void 0===s||s.call(t));}removeController(t){var i;null===(i=this._$Eg)||void 0===i||i.splice(this._$Eg.indexOf(t)>>>0,1);}_$Em(){this.constructor.elementProperties.forEach(((t,i)=>{this.hasOwnProperty(i)&&(this._$Et.set(i,this[i]),delete this[i]);}));}createRenderRoot(){var t;const s=null!==(t=this.shadowRoot)&&void 0!==t?t:this.attachShadow(this.constructor.shadowRootOptions);return i$3(s,this.constructor.elementStyles),s}connectedCallback(){var t;void 0===this.renderRoot&&(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),null===(t=this._$Eg)||void 0===t||t.forEach((t=>{var i;return null===(i=t.hostConnected)||void 0===i?void 0:i.call(t)}));}enableUpdating(t){}disconnectedCallback(){var t;null===(t=this._$Eg)||void 0===t||t.forEach((t=>{var i;return null===(i=t.hostDisconnected)||void 0===i?void 0:i.call(t)}));}attributeChangedCallback(t,i,s){this._$AK(t,s);}_$ES(t,i,s=l$2){var e,r;const h=this.constructor._$Eh(t,s);if(void 0!==h&&!0===s.reflect){const n=(null!==(r=null===(e=s.converter)||void 0===e?void 0:e.toAttribute)&&void 0!==r?r:o$3.toAttribute)(i,s.type);this._$Ei=t,null==n?this.removeAttribute(h):this.setAttribute(h,n),this._$Ei=null;}}_$AK(t,i){var s,e,r;const h=this.constructor,n=h._$Eu.get(t);if(void 0!==n&&this._$Ei!==n){const t=h.getPropertyOptions(n),l=t.converter,a=null!==(r=null!==(e=null===(s=l)||void 0===s?void 0:s.fromAttribute)&&void 0!==e?e:"function"==typeof l?l:null)&&void 0!==r?r:o$3.fromAttribute;this._$Ei=n,this[n]=a(i,t.type),this._$Ei=null;}}requestUpdate(t,i,s){let e=!0;void 0!==t&&(((s=s||this.constructor.getPropertyOptions(t)).hasChanged||n$3)(this[t],i)?(this._$AL.has(t)||this._$AL.set(t,i),!0===s.reflect&&this._$Ei!==t&&(void 0===this._$EC&&(this._$EC=new Map),this._$EC.set(t,s))):e=!1),!this.isUpdatePending&&e&&(this._$Ep=this._$E_());}async _$E_(){this.isUpdatePending=!0;try{await this._$Ep;}catch(t){Promise.reject(t);}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){var t;if(!this.isUpdatePending)return;this.hasUpdated,this._$Et&&(this._$Et.forEach(((t,i)=>this[i]=t)),this._$Et=void 0);let i=!1;const s=this._$AL;try{i=this.shouldUpdate(s),i?(this.willUpdate(s),null===(t=this._$Eg)||void 0===t||t.forEach((t=>{var i;return null===(i=t.hostUpdate)||void 0===i?void 0:i.call(t)})),this.update(s)):this._$EU();}catch(t){throw i=!1,this._$EU(),t}i&&this._$AE(s);}willUpdate(t){}_$AE(t){var i;null===(i=this._$Eg)||void 0===i||i.forEach((t=>{var i;return null===(i=t.hostUpdated)||void 0===i?void 0:i.call(t)})),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t);}_$EU(){this._$AL=new Map,this.isUpdatePending=!1;}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$Ep}shouldUpdate(t){return !0}update(t){void 0!==this._$EC&&(this._$EC.forEach(((t,i)=>this._$ES(i,this[i],t))),this._$EC=void 0),this._$EU();}updated(t){}firstUpdated(t){}}a$1.finalized=!0,a$1.elementProperties=new Map,a$1.elementStyles=[],a$1.shadowRootOptions={mode:"open"},null==h$1||h$1({ReactiveElement:a$1}),(null!==(s$2=globalThis.reactiveElementVersions)&&void 0!==s$2?s$2:globalThis.reactiveElementVersions=[]).push("1.3.1"); + +/** + * @license + * Copyright 2017 Google LLC + * SPDX-License-Identifier: BSD-3-Clause + */ +var t$1;const i$2=globalThis.trustedTypes,s$1=i$2?i$2.createPolicy("lit-html",{createHTML:t=>t}):void 0,e$3=`lit$${(Math.random()+"").slice(9)}$`,o$2="?"+e$3,n$2=`<${o$2}>`,l$1=document,h=(t="")=>l$1.createComment(t),r=t=>null===t||"object"!=typeof t&&"function"!=typeof t,d=Array.isArray,u=t=>{var i;return d(t)||"function"==typeof(null===(i=t)||void 0===i?void 0:i[Symbol.iterator])},c=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,v=/-->/g,a=/>/g,f=/>|[ \n \r](?:([^\s"'>=/]+)([ \n \r]*=[ \n \r]*(?:[^ \n \r"'`<>=]|("|')|))|$)/g,_=/'/g,m=/"/g,g=/^(?:script|style|textarea|title)$/i,p=t=>(i,...s)=>({_$litType$:t,strings:i,values:s}),$=p(1),b=Symbol.for("lit-noChange"),w=Symbol.for("lit-nothing"),T=new WeakMap,x=(t,i,s)=>{var e,o;const n=null!==(e=null==s?void 0:s.renderBefore)&&void 0!==e?e:i;let l=n._$litPart$;if(void 0===l){const t=null!==(o=null==s?void 0:s.renderBefore)&&void 0!==o?o:null;n._$litPart$=l=new N(i.insertBefore(h(),t),t,void 0,null!=s?s:{});}return l._$AI(t),l},A=l$1.createTreeWalker(l$1,129,null,!1),C=(t,i)=>{const o=t.length-1,l=[];let h,r=2===i?"":"",d=c;for(let i=0;i"===u[0]?(d=null!=h?h:c,p=-1):void 0===u[1]?p=-2:(p=d.lastIndex-u[2].length,o=u[1],d=void 0===u[3]?f:'"'===u[3]?m:_):d===m||d===_?d=f:d===v||d===a?d=c:(d=f,h=void 0);const y=d===f&&t[i+1].startsWith("/>")?" ":"";r+=d===c?s+n$2:p>=0?(l.push(o),s.slice(0,p)+"$lit$"+s.slice(p)+e$3+y):s+e$3+(-2===p?(l.push(void 0),i):y);}const u=r+(t[o]||"")+(2===i?"":"");if(!Array.isArray(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return [void 0!==s$1?s$1.createHTML(u):u,l]};class E{constructor({strings:t,_$litType$:s},n){let l;this.parts=[];let r=0,d=0;const u=t.length-1,c=this.parts,[v,a]=C(t,s);if(this.el=E.createElement(v,n),A.currentNode=this.el.content,2===s){const t=this.el.content,i=t.firstChild;i.remove(),t.append(...i.childNodes);}for(;null!==(l=A.nextNode())&&c.length0){l.textContent=i$2?i$2.emptyScript:"";for(let i=0;i2||""!==s[0]||""!==s[1]?(this._$AH=Array(s.length-1).fill(new String),this.strings=s):this._$AH=w;}get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}_$AI(t,i=this,s,e){const o=this.strings;let n=!1;if(void 0===o)t=P(this,t,i,0),n=!r(t)||t!==this._$AH&&t!==b,n&&(this._$AH=t);else {const e=t;let l,h;for(t=o[0],l=0;l"method"===e.kind&&e.descriptor&&!("value"in e.descriptor)?{...e,finisher(n){n.createProperty(e.key,i);}}:{kind:"field",key:Symbol(),placement:"own",descriptor:{},originalKey:e.key,initializer(){"function"==typeof e.initializer&&(this[e.key]=e.initializer.call(this));},finisher(n){n.createProperty(e.key,i);}};function e$2(e){return (n,t)=>void 0!==t?((i,e,n)=>{e.constructor.createProperty(n,i);})(e,n,t):i$1(e,n)} + +/** + * @license + * Copyright 2021 Google LLC + * SPDX-License-Identifier: BSD-3-Clause + */var n;null!=(null===(n=window.HTMLSlotElement)||void 0===n?void 0:n.prototype.assignedElements)?(o,n)=>o.assignedElements(n):(o,n)=>o.assignedNodes(n).filter((o=>o.nodeType===Node.ELEMENT_NODE)); + const ID_STORAGE_KEY$1 = 'lovelace-player-device-id'; function _deviceID() { if(!localStorage[ID_STORAGE_KEY$1]) @@ -29,13 +90,6 @@ if(params.get('deviceID')) { setDeviceID(params.get('deviceID')); } -function ha_element() { - if(document.querySelector("hc-main")) - return document.querySelector("hc-main"); - if(document.querySelector("home-assistant")) - return document.querySelector("home-assistant"); -} - async function hass_loaded() { await Promise.race([ customElements.whenDefined("home-assistant"), @@ -43,25 +97,6 @@ async function hass_loaded() { ]); return true; } - -function hass$1() { - if(document.querySelector('hc-main')) - return document.querySelector('hc-main').hass; - - if(document.querySelector('home-assistant')) - return document.querySelector('home-assistant').hass; - - return undefined; -} -function provideHass$1(element) { - if(document.querySelector('hc-main')) - return document.querySelector('hc-main').provideHass(element); - - if(document.querySelector('home-assistant')) - return document.querySelector("home-assistant").provideHass(element); - - return undefined; -} function lovelace_view() { var root = document.querySelector("hc-main"); if(root) { @@ -88,72 +123,6 @@ function lovelace_view() { return root; } -async function load_lovelace() { - if(customElements.get("hui-view")) return true; - - await customElements.whenDefined("partial-panel-resolver"); - const ppr = document.createElement("partial-panel-resolver"); - ppr.hass = {panels: [{ - url_path: "tmp", - "component_name": "lovelace", - }]}; - ppr._updateRoutes(); - await ppr.routerOptions.routes.tmp.load(); - if(!customElements.get("ha-panel-lovelace")) return false; - const p = document.createElement("ha-panel-lovelace"); - p.hass = hass$1(); - if(p.hass === undefined) { - await new Promise(resolve => { - window.addEventListener('connection-status', (ev) => { - resolve(); - }, {once: true}); - }); - p.hass = hass$1(); - } - p.panel = {config: {mode: null}}; - p._fetchConfig(); - return true; -} - -async function _selectTree(root, path, all=false) { - let el = root; - if(typeof(path) === "string") { - path = path.split(/(\$| )/); - } - if(path[path.length-1] === "") - path.pop(); - for(const [i, p] of path.entries()) { - if(!p.trim().length) continue; - if(!el) return null; - if(el.localName && el.localName.includes("-")) - await customElements.whenDefined(el.localName); - if(el.updateComplete) - await el.updateComplete; - if(p === "$") - if(all && i == path.length-1) - el = [el.shadowRoot]; - else - el = el.shadowRoot; - else - if(all && i == path.length-1) - el = el.querySelectorAll(p); - else - el = el.querySelector(p); - } - return el; -} - -async function selectTree(root, path, all=false, timeout=10000) { - return Promise.race([ - _selectTree(root, path, all), - new Promise((_, reject) => setTimeout(() => reject(new Error('timeout')), timeout)) - ]).catch((err) => { - if(!err.message || err.message !== "timeout") - throw(err); - return null; - }); -} - function fireEvent(ev, detail, entity=null) { ev = new Event(ev, { bubbles: true, @@ -169,311 +138,6 @@ function fireEvent(ev, detail, entity=null) { } } -let helpers = window.cardHelpers; -new Promise(async (resolve, reject) => { - if(helpers) resolve(); - - const updateHelpers = async () => { - helpers = await window.loadCardHelpers(); - window.cardHelpers = helpers; - resolve(); - }; - - if(window.loadCardHelpers) { - updateHelpers(); - } else { - // If loadCardHelpers didn't exist, force load lovelace and try once more. - window.addEventListener("load", async () => { - load_lovelace(); - if(window.loadCardHelpers) { - updateHelpers(); - } - }); - } -}); - -async function popUp(title, card, large=false, style={}, fullscreen=false) { - if(!customElements.get("card-tools-popup")) - { - const LitElement = customElements.get('home-assistant-main') - ? Object.getPrototypeOf(customElements.get('home-assistant-main')) - : Object.getPrototypeOf(customElements.get('hui-view')); - const html = LitElement.prototype.html; - const css = LitElement.prototype.css; - - class CardToolsPopup extends LitElement { - - static get properties() { - return { - open: {}, - large: {reflect: true, type: Boolean}, - hass: {}, - }; - } - - updated(changedProperties) { - if(changedProperties.has("hass")) { - if(this.card) - this.card.hass = this.hass; - } - } - - closeDialog() { - this.open = false; - } - - async _makeCard() { - const helpers = await window.loadCardHelpers(); - this.card = await helpers.createCardElement(this._card); - this.card.hass = this.hass; - this.requestUpdate(); - } - - async _applyStyles() { - let el = await selectTree(this, "$ ha-dialog"); - customElements.whenDefined("card-mod").then(async () => { - if(!el) return; - const cm = customElements.get("card-mod"); - cm.applyToElement(el, "more-info", this._style, {config: this._card}, [], false); - }); - - } - - async showDialog(title, card, large=false, style={}, fullscreen=false) { - this.title = title; - this._card = card; - this.large = large; - this._style = style; - this.fullscreen = !!fullscreen; - this._makeCard(); - await this.updateComplete; - this.open = true; - await this._applyStyles(); - } - - _enlarge() { - this.large = !this.large; - } - - render() { - if(!this.open) { - return html``; - } - - return html` - - ${this.fullscreen - ? html`
` - : html` - - - - -
- ${this.title} -
-
- `} -
- ${this.card} -
-
- ` - } - - static get styles() { - return css` - ha-dialog { - --mdc-dialog-min-width: 400px; - --mdc-dialog-max-width: 600px; - --mdc-dialog-heading-ink-color: var(--primary-text-color); - --mdc-dialog-content-ink-color: var(--primary-text-color); - --justify-action-buttons: space-between; - } - @media all and (max-width: 450px), all and (max-height: 500px) { - ha-dialog { - --mdc-dialog-min-width: 100vw; - --mdc-dialog-max-width: 100vw; - --mdc-dialog-min-height: 100%; - --mdc-dialog-max-height: 100%; - --mdc-shape-medium: 0px; - --vertial-align-dialog: flex-end; - } - } - - app-toolbar { - flex-shrink: 0; - color: var(--primary-text-color); - background-color: var(--secondary-background-color); - } - - app-toolbar mwc-icon-button ha-icon { - display: flex; - } - - .main-title { - margin-left: 16px; - line-height: 1.3em; - max-height: 2.6em; - overflow: hidden; - display: -webkit-box; - -webkit-line-clamp: 2; - -webkit-box-orient: vertical; - text-overflow: ellipsis; - } - .content { - margin: -20px -24px; - } - - @media all and (max-width: 450px), all and (max-height: 500px) { - app-toolbar { - background-color: var(--app-header-background-color); - color: var(--app-header-text-color, white); - } - } - - @media all and (min-width: 451px) and (min-height: 501px) { - ha-dialog { - --mdc-dialog-max-width: 90vw; - } - - .content { - width: 400px; - } - :host([large]) .content { - width: calc(90vw - 48px); - } - - :host([large]) app-toolbar { - max-width: calc(90vw - 32px); - } - } - `; - } - - } - customElements.define("card-tools-popup", CardToolsPopup); - } - - const root = document.querySelector("home-assistant") || document.querySelector("hc-root"); - - if(!root) return; - let el = await selectTree(root, "$ card-tools-popup"); - if(!el) { - el = document.createElement("card-tools-popup"); - const mi = root.shadowRoot.querySelector("ha-more-info-dialog"); - if(mi) - root.shadowRoot.insertBefore(el,mi); - else - root.shadowRoot.appendChild(el); - provideHass$1(el); - } - - if(!window._moreInfoDialogListener) { - const listener = async (ev) => { - if(ev.state && "cardToolsPopup" in ev.state) { - if(ev.state.cardToolsPopup) { - const {title, card, large, style, fullscreen} = ev.state.params; - popUp(title, card, large, style, fullscreen); - } else { - el.closeDialog(); - } - } - }; - - window.addEventListener("popstate", listener); - window._moreInfoDialogListener = true; - } - - history.replaceState( { - cardToolsPopup: false, - }, - "" - ); - - history.pushState( { - cardToolsPopup: true, - params: {title, card, large, style, fullscreen}, - }, - "" - ); - - el.showDialog(title, card, large, style, fullscreen); - -} - -/*! ***************************************************************************** -Copyright (c) Microsoft Corporation. - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH -REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -PERFORMANCE OF THIS SOFTWARE. -***************************************************************************** */ - -function __decorate(decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -} - -/** - * @license - * Copyright 2019 Google LLC - * SPDX-License-Identifier: BSD-3-Clause - */ -const t$1=window.ShadowRoot&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,e$3=Symbol(),n$4=new Map;class s$3{constructor(t,n){if(this._$cssResult$=!0,n!==e$3)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t;}get styleSheet(){let e=n$4.get(this.cssText);return t$1&&void 0===e&&(n$4.set(this.cssText,e=new CSSStyleSheet),e.replaceSync(this.cssText)),e}toString(){return this.cssText}}const o$3=t=>new s$3("string"==typeof t?t:t+"",e$3),r$2=(t,...n)=>{const o=1===t.length?t[0]:n.reduce(((e,n,s)=>e+(t=>{if(!0===t._$cssResult$)return t.cssText;if("number"==typeof t)return t;throw Error("Value passed to 'css' function must be a 'css' function result: "+t+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(n)+t[s+1]),t[0]);return new s$3(o,e$3)},i$2=(e,n)=>{t$1?e.adoptedStyleSheets=n.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet)):n.forEach((t=>{const n=document.createElement("style"),s=window.litNonce;void 0!==s&&n.setAttribute("nonce",s),n.textContent=t.cssText,e.appendChild(n);}));},S$1=t$1?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const n of t.cssRules)e+=n.cssText;return o$3(e)})(t):t; - -/** - * @license - * Copyright 2017 Google LLC - * SPDX-License-Identifier: BSD-3-Clause - */var s$2;const e$2=window.trustedTypes,r$1=e$2?e$2.emptyScript:"",h$1=window.reactiveElementPolyfillSupport,o$2={toAttribute(t,i){switch(i){case Boolean:t=t?r$1:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t);}return t},fromAttribute(t,i){let s=t;switch(i){case Boolean:s=null!==t;break;case Number:s=null===t?null:Number(t);break;case Object:case Array:try{s=JSON.parse(t);}catch(t){s=null;}}return s}},n$3=(t,i)=>i!==t&&(i==i||t==t),l$2={attribute:!0,type:String,converter:o$2,reflect:!1,hasChanged:n$3};class a$1 extends HTMLElement{constructor(){super(),this._$Et=new Map,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Ei=null,this.o();}static addInitializer(t){var i;null!==(i=this.l)&&void 0!==i||(this.l=[]),this.l.push(t);}static get observedAttributes(){this.finalize();const t=[];return this.elementProperties.forEach(((i,s)=>{const e=this._$Eh(s,i);void 0!==e&&(this._$Eu.set(e,s),t.push(e));})),t}static createProperty(t,i=l$2){if(i.state&&(i.attribute=!1),this.finalize(),this.elementProperties.set(t,i),!i.noAccessor&&!this.prototype.hasOwnProperty(t)){const s="symbol"==typeof t?Symbol():"__"+t,e=this.getPropertyDescriptor(t,s,i);void 0!==e&&Object.defineProperty(this.prototype,t,e);}}static getPropertyDescriptor(t,i,s){return {get(){return this[i]},set(e){const r=this[t];this[i]=e,this.requestUpdate(t,r,s);},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)||l$2}static finalize(){if(this.hasOwnProperty("finalized"))return !1;this.finalized=!0;const t=Object.getPrototypeOf(this);if(t.finalize(),this.elementProperties=new Map(t.elementProperties),this._$Eu=new Map,this.hasOwnProperty("properties")){const t=this.properties,i=[...Object.getOwnPropertyNames(t),...Object.getOwnPropertySymbols(t)];for(const s of i)this.createProperty(s,t[s]);}return this.elementStyles=this.finalizeStyles(this.styles),!0}static finalizeStyles(i){const s=[];if(Array.isArray(i)){const e=new Set(i.flat(1/0).reverse());for(const i of e)s.unshift(S$1(i));}else void 0!==i&&s.push(S$1(i));return s}static _$Eh(t,i){const s=i.attribute;return !1===s?void 0:"string"==typeof s?s:"string"==typeof t?t.toLowerCase():void 0}o(){var t;this._$Ep=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$Em(),this.requestUpdate(),null===(t=this.constructor.l)||void 0===t||t.forEach((t=>t(this)));}addController(t){var i,s;(null!==(i=this._$Eg)&&void 0!==i?i:this._$Eg=[]).push(t),void 0!==this.renderRoot&&this.isConnected&&(null===(s=t.hostConnected)||void 0===s||s.call(t));}removeController(t){var i;null===(i=this._$Eg)||void 0===i||i.splice(this._$Eg.indexOf(t)>>>0,1);}_$Em(){this.constructor.elementProperties.forEach(((t,i)=>{this.hasOwnProperty(i)&&(this._$Et.set(i,this[i]),delete this[i]);}));}createRenderRoot(){var t;const s=null!==(t=this.shadowRoot)&&void 0!==t?t:this.attachShadow(this.constructor.shadowRootOptions);return i$2(s,this.constructor.elementStyles),s}connectedCallback(){var t;void 0===this.renderRoot&&(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),null===(t=this._$Eg)||void 0===t||t.forEach((t=>{var i;return null===(i=t.hostConnected)||void 0===i?void 0:i.call(t)}));}enableUpdating(t){}disconnectedCallback(){var t;null===(t=this._$Eg)||void 0===t||t.forEach((t=>{var i;return null===(i=t.hostDisconnected)||void 0===i?void 0:i.call(t)}));}attributeChangedCallback(t,i,s){this._$AK(t,s);}_$ES(t,i,s=l$2){var e,r;const h=this.constructor._$Eh(t,s);if(void 0!==h&&!0===s.reflect){const n=(null!==(r=null===(e=s.converter)||void 0===e?void 0:e.toAttribute)&&void 0!==r?r:o$2.toAttribute)(i,s.type);this._$Ei=t,null==n?this.removeAttribute(h):this.setAttribute(h,n),this._$Ei=null;}}_$AK(t,i){var s,e,r;const h=this.constructor,n=h._$Eu.get(t);if(void 0!==n&&this._$Ei!==n){const t=h.getPropertyOptions(n),l=t.converter,a=null!==(r=null!==(e=null===(s=l)||void 0===s?void 0:s.fromAttribute)&&void 0!==e?e:"function"==typeof l?l:null)&&void 0!==r?r:o$2.fromAttribute;this._$Ei=n,this[n]=a(i,t.type),this._$Ei=null;}}requestUpdate(t,i,s){let e=!0;void 0!==t&&(((s=s||this.constructor.getPropertyOptions(t)).hasChanged||n$3)(this[t],i)?(this._$AL.has(t)||this._$AL.set(t,i),!0===s.reflect&&this._$Ei!==t&&(void 0===this._$EC&&(this._$EC=new Map),this._$EC.set(t,s))):e=!1),!this.isUpdatePending&&e&&(this._$Ep=this._$E_());}async _$E_(){this.isUpdatePending=!0;try{await this._$Ep;}catch(t){Promise.reject(t);}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){var t;if(!this.isUpdatePending)return;this.hasUpdated,this._$Et&&(this._$Et.forEach(((t,i)=>this[i]=t)),this._$Et=void 0);let i=!1;const s=this._$AL;try{i=this.shouldUpdate(s),i?(this.willUpdate(s),null===(t=this._$Eg)||void 0===t||t.forEach((t=>{var i;return null===(i=t.hostUpdate)||void 0===i?void 0:i.call(t)})),this.update(s)):this._$EU();}catch(t){throw i=!1,this._$EU(),t}i&&this._$AE(s);}willUpdate(t){}_$AE(t){var i;null===(i=this._$Eg)||void 0===i||i.forEach((t=>{var i;return null===(i=t.hostUpdated)||void 0===i?void 0:i.call(t)})),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t);}_$EU(){this._$AL=new Map,this.isUpdatePending=!1;}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$Ep}shouldUpdate(t){return !0}update(t){void 0!==this._$EC&&(this._$EC.forEach(((t,i)=>this._$ES(i,this[i],t))),this._$EC=void 0),this._$EU();}updated(t){}firstUpdated(t){}}a$1.finalized=!0,a$1.elementProperties=new Map,a$1.elementStyles=[],a$1.shadowRootOptions={mode:"open"},null==h$1||h$1({ReactiveElement:a$1}),(null!==(s$2=globalThis.reactiveElementVersions)&&void 0!==s$2?s$2:globalThis.reactiveElementVersions=[]).push("1.3.1"); - -/** - * @license - * Copyright 2017 Google LLC - * SPDX-License-Identifier: BSD-3-Clause - */ -var t;const i$1=globalThis.trustedTypes,s$1=i$1?i$1.createPolicy("lit-html",{createHTML:t=>t}):void 0,e$1=`lit$${(Math.random()+"").slice(9)}$`,o$1="?"+e$1,n$2=`<${o$1}>`,l$1=document,h=(t="")=>l$1.createComment(t),r=t=>null===t||"object"!=typeof t&&"function"!=typeof t,d=Array.isArray,u=t=>{var i;return d(t)||"function"==typeof(null===(i=t)||void 0===i?void 0:i[Symbol.iterator])},c=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,v=/-->/g,a=/>/g,f=/>|[ \n \r](?:([^\s"'>=/]+)([ \n \r]*=[ \n \r]*(?:[^ \n \r"'`<>=]|("|')|))|$)/g,_=/'/g,m=/"/g,g=/^(?:script|style|textarea|title)$/i,p=t=>(i,...s)=>({_$litType$:t,strings:i,values:s}),$=p(1),b=Symbol.for("lit-noChange"),w=Symbol.for("lit-nothing"),T=new WeakMap,x=(t,i,s)=>{var e,o;const n=null!==(e=null==s?void 0:s.renderBefore)&&void 0!==e?e:i;let l=n._$litPart$;if(void 0===l){const t=null!==(o=null==s?void 0:s.renderBefore)&&void 0!==o?o:null;n._$litPart$=l=new N(i.insertBefore(h(),t),t,void 0,null!=s?s:{});}return l._$AI(t),l},A=l$1.createTreeWalker(l$1,129,null,!1),C=(t,i)=>{const o=t.length-1,l=[];let h,r=2===i?"":"",d=c;for(let i=0;i"===u[0]?(d=null!=h?h:c,p=-1):void 0===u[1]?p=-2:(p=d.lastIndex-u[2].length,o=u[1],d=void 0===u[3]?f:'"'===u[3]?m:_):d===m||d===_?d=f:d===v||d===a?d=c:(d=f,h=void 0);const y=d===f&&t[i+1].startsWith("/>")?" ":"";r+=d===c?s+n$2:p>=0?(l.push(o),s.slice(0,p)+"$lit$"+s.slice(p)+e$1+y):s+e$1+(-2===p?(l.push(void 0),i):y);}const u=r+(t[o]||"")+(2===i?"":"");if(!Array.isArray(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return [void 0!==s$1?s$1.createHTML(u):u,l]};class E{constructor({strings:t,_$litType$:s},n){let l;this.parts=[];let r=0,d=0;const u=t.length-1,c=this.parts,[v,a]=C(t,s);if(this.el=E.createElement(v,n),A.currentNode=this.el.content,2===s){const t=this.el.content,i=t.firstChild;i.remove(),t.append(...i.childNodes);}for(;null!==(l=A.nextNode())&&c.length0){l.textContent=i$1?i$1.emptyScript:"";for(let i=0;i2||""!==s[0]||""!==s[1]?(this._$AH=Array(s.length-1).fill(new String),this.strings=s):this._$AH=w;}get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}_$AI(t,i=this,s,e){const o=this.strings;let n=!1;if(void 0===o)t=P(this,t,i,0),n=!r(t)||t!==this._$AH&&t!==b,n&&(this._$AH=t);else {const e=t;let l,h;for(t=o[0],l=0;l"method"===e.kind&&e.descriptor&&!("value"in e.descriptor)?{...e,finisher(n){n.createProperty(e.key,i);}}:{kind:"field",key:Symbol(),placement:"own",descriptor:{},originalKey:e.key,initializer(){"function"==typeof e.initializer&&(this[e.key]=e.initializer.call(this));},finisher(n){n.createProperty(e.key,i);}};function e(e){return (n,t)=>void 0!==t?((i,e,n)=>{e.constructor.createProperty(n,i);})(e,n,t):i(e,n)} - -/** - * @license - * Copyright 2021 Google LLC - * SPDX-License-Identifier: BSD-3-Clause - */var n;null!=(null===(n=window.HTMLSlotElement)||void 0===n?void 0:n.prototype.assignedElements)?(o,n)=>o.assignedElements(n):(o,n)=>o.assignedNodes(n).filter((o=>o.nodeType===Node.ELEMENT_NODE)); - class BrowserPlayerEditor extends s { setConfig(config) { } render() { @@ -607,7 +271,7 @@ class BrowserPlayer extends s { } } __decorate([ - e() + e$2() ], BrowserPlayer.prototype, "hass", void 0); (async () => { await hass_loaded(); @@ -615,7 +279,7 @@ __decorate([ customElements.define("browser-player", BrowserPlayer); })(); -async function _hass_base_el() { +async function hass_base_el() { await Promise.race([ customElements.whenDefined("home-assistant"), customElements.whenDefined("hc-main"), @@ -628,15 +292,29 @@ async function _hass_base_el() { return document.querySelector(element); } async function hass() { - const base = await _hass_base_el(); + const base = await hass_base_el(); while (!base.hass) await new Promise((r) => window.setTimeout(r, 100)); return base.hass; } async function provideHass(el) { - const base = await _hass_base_el(); + const base = await hass_base_el(); base.provideHass(el); -} +} +const loadLoadCardHelpers = async () => { + var _a, _b, _c; + if (window.loadCardHelpers !== undefined) + return; + await customElements.whenDefined("partial-panel-resolver"); + const ppResolver = document.createElement("partial-panel-resolver"); + const routes = ppResolver.getRoutes([ + { + component_name: "lovelace", + url_path: "a", + }, + ]); + await ((_c = (_b = (_a = routes === null || routes === void 0 ? void 0 : routes.routes) === null || _a === void 0 ? void 0 : _a.a) === null || _b === void 0 ? void 0 : _b.load) === null || _c === void 0 ? void 0 : _c.call(_b)); +}; const ID_STORAGE_KEY = "browser_mod-device-id"; const ConnectionMixin = (SuperClass) => { @@ -888,134 +566,7 @@ const ScreenSaverMixin = (SuperClass) => { } } return ScreenSaverMixinClass; -}; -// export const BrowserModScreensaverMixin = (C) => -// class extends C { -// constructor() { -// super(); -// this._blackout_panel = document.createElement("div"); -// this._screenSaver = undefined; -// this._screenSaverTimer = undefined; -// this._screenSaverTimeOut = 0; -// this._screenSaver = { -// fn: undefined, -// clearfn: undefined, -// timer: undefined, -// timeout: undefined, -// listeners: {}, -// active: false, -// }; -// this._blackout_panel.style.cssText = ` -// position: fixed; -// left: 0; -// top: 0; -// padding: 0; -// margin: 0; -// width: 100%; -// height: 100%; -// background: black; -// display: none; -// `; -// document.body.appendChild(this._blackout_panel); -// } -// screensaver_set(fn, clearfn, time) { -// this._ss_clear(); -// this._screenSaver = { -// fn, -// clearfn, -// timer: undefined, -// timeout: time, -// listeners: {}, -// active: false, -// }; -// const l = () => this.screensaver_update(); -// for (const event of ["mousemove", "mousedown", "keydown", "touchstart"]) { -// window.addEventListener(event, l); -// this._screenSaver.listeners[event] = l; -// } -// this._screenSaver.timer = window.setTimeout( -// () => this._ss_run(), -// time * 1000 -// ); -// } -// screensaver_update() { -// if (this._screenSaver.active) { -// this.screensaver_stop(); -// } else { -// window.clearTimeout(this._screenSaver.timer); -// this._screenSaver.timer = window.setTimeout( -// () => this._ss_run(), -// this._screenSaver.timeout * 1000 -// ); -// } -// } -// screensaver_stop() { -// this._ss_clear(); -// this._screenSaver.active = false; -// if (this._screenSaver.clearfn) this._screenSaver.clearfn(); -// if (this._screenSaver.timeout) { -// this.screensaver_set( -// this._screenSaver.fn, -// this._screenSaver.clearfn, -// this._screenSaver.timeout -// ); -// } -// } -// _ss_clear() { -// window.clearTimeout(this._screenSaverTimer); -// for (const [k, v] of Object.entries(this._screenSaver.listeners)) { -// window.removeEventListener(k as any, v as any); -// } -// } -// _ss_run() { -// this._screenSaver.active = true; -// this._screenSaver.fn(); -// } -// do_blackout(timeout) { -// this.screensaver_set( -// () => { -// if (this.isFully) { -// if (this.config.screensaver) window.fully.startScreensaver(); -// else window.fully.turnScreenOff(true); -// } else { -// this._blackout_panel.style.display = "block"; -// } -// this.screen_update(); -// }, -// () => { -// if ((this._blackout_panel.style.display = "block")) -// this._blackout_panel.style.display = "none"; -// if (this.isFully) { -// if (!window.fully.getScreenOn()) window.fully.turnScreenOn(); -// window.fully.stopScreensaver(); -// } -// this.screen_update(); -// }, -// timeout || 0 -// ); -// } -// no_blackout() { -// if (this.isFully) { -// window.fully.turnScreenOn(); -// window.fully.stopScreensaver(); -// } -// this.screensaver_stop(); -// } -// screen_update() { -// this.sendUpdate({ -// screen: { -// blackout: this.isFully -// ? this.fully_screensaver !== undefined -// ? this.fully_screensaver -// : !window.fully.getScreenOn() -// : Boolean(this._blackout_panel.style.display === "block"), -// brightness: this.isFully -// ? window.fully.getScreenBrightness() -// : undefined, -// }, -// }); -// } -// }; +}; const MediaPlayerMixin = (SuperClass) => { return class MediaPlayerMixinClass extends SuperClass { @@ -1315,11 +866,244 @@ const BrowserStateMixin = (SuperClass) => { }; update(); } - do_navigate(path) { - if (!path) - return; - history.pushState(null, "", path); - fireEvent("location-changed", {}, ha_element()); + }; +}; + +/** + * @license + * Copyright 2017 Google LLC + * SPDX-License-Identifier: BSD-3-Clause + */ +const t={ATTRIBUTE:1,CHILD:2,PROPERTY:3,BOOLEAN_ATTRIBUTE:4,EVENT:5,ELEMENT:6},e$1=t=>(...e)=>({_$litDirective$:t,values:e});class i{constructor(t){}get _$AU(){return this._$AM._$AU}_$AT(t,e,i){this._$Ct=t,this._$AM=e,this._$Ci=i;}_$AS(t,e){return this.update(t,e)}update(t,e){return this.render(...e)}} + +/** + * @license + * Copyright 2017 Google LLC + * SPDX-License-Identifier: BSD-3-Clause + */class e extends i{constructor(i){if(super(i),this.it=w,i.type!==t.CHILD)throw Error(this.constructor.directiveName+"() can only be used in child bindings")}render(r){if(r===w||null==r)return this.ft=void 0,this.it=r;if(r===b)return r;if("string"!=typeof r)throw Error(this.constructor.directiveName+"() called with a non-string value");if(r===this.it)return this.ft;this.it=r;const s=[r];return s.raw=s,this.ft={_$litType$:this.constructor.resultType,strings:s,values:[]}}}e.directiveName="unsafeHTML",e.resultType=1;const o=e$1(e); + +class BrowserModPopup extends s { + closeDialog() { + this.open = false; + } + openDialog() { + this.open = true; + } + async setupDialog(title, content, { primary_action = undefined, secondary_action = undefined, dismissable = true, }) { + this.dismissable = dismissable; + this.title = title; + if (content && typeof content === "object") { + // Create a card from config in content + this.card = true; + const helpers = await window.loadCardHelpers(); + const card = await helpers.createCardElement(content); + card.hass = window.browser_mod.hass; + provideHass(card); + this.content = card; + } + else { + // Basic HTML content + this.content = o(content); + } + if (primary_action) { + this.primary_action = primary_action; + this.secondary_action = secondary_action; + this.actions = ""; + } + else { + this.primary_action = undefined; + this.secondary_action = undefined; + this.actions = undefined; + } + } + _primary_clicked() { + var _a, _b; + this.closeDialog(); + (_b = (_a = this.primary_action) === null || _a === void 0 ? void 0 : _a.callback) === null || _b === void 0 ? void 0 : _b.call(_a); + } + _secondary_clicked() { + var _a, _b; + this.closeDialog(); + (_b = (_a = this.secondary_action) === null || _a === void 0 ? void 0 : _a.callback) === null || _b === void 0 ? void 0 : _b.call(_a); + } + render() { + if (!this.open) + return $ ``; + return $ ` + + ${this.title + ? $ ` + + ${this.dismissable + ? $ ` + + + + ` + : ""} +
${this.title}
+
+ ` + : $ ``} + +
${this.content}
+ + ${this.primary_action !== undefined + ? $ ` + + ` + : ""} + ${this.secondary_action !== undefined + ? $ ` + + ` + : ""} +
+ `; + } + static get styles() { + return r$2 ` + ha-dialog { + --mdc-dialog-min-width: 400px; + --mdc-dialog-max-width: 600px; + --mdc-dialog-heading-ink-color: var(--primary-text-color); + --mdc-dialog-content-ink-color: var(--primary-text-color); + --justify-action-buttons: space-between; + + --mdc-dialog-box-shadow: 0px 0px 0px var(--ha-card-border-width, 1px) + var(--ha-card-border-color, var(--divider-color, #e0e0e0)); + --ha-dialog-border-radius: 8px; + --mdc-theme-surface: var( + --ha-card-background, + var(--card-background-color, white) + ); + } + + app-toolbar { + flex-shrink: 0; + color: var(--primary-text-color); + background-color: var(--sidebar-background-color); + } + ha-icon-button > * { + display: flex; + } + .main-title { + margin-left: 16px; + line-height: 1.3em; + max-height: 2.6em; + overflow: hidden; + text-overflow: ellipsis; + } + .content { + margin: -20px -24px; + padding: 20px 24px; + } + + :host([card]) .content { + padding: 0; + } + :host([actions]) .content { + border-bottom: 1px solid var(--divider-color); + } + + @media all and (max-width: 450px), all and (max-height: 500px) { + ha-dialog { + --mdc-dialog-min-width: 100vw; + --mdc-dialog-max-width: 100vw; + --mdc-dialog-min-height: 100%; + --mdc-dialog-max-height: 100%; + --mdc-shape-medium: 0px; + --vertial-align-dialog: flex-end; + } + } + `; + } +} +__decorate([ + e$2() +], BrowserModPopup.prototype, "open", void 0); +__decorate([ + e$2() +], BrowserModPopup.prototype, "content", void 0); +__decorate([ + e$2() +], BrowserModPopup.prototype, "title", void 0); +__decorate([ + e$2({ reflect: true }) +], BrowserModPopup.prototype, "actions", void 0); +__decorate([ + e$2({ reflect: true }) +], BrowserModPopup.prototype, "card", void 0); +__decorate([ + e$2() +], BrowserModPopup.prototype, "primary_action", void 0); +__decorate([ + e$2() +], BrowserModPopup.prototype, "secondary_action", void 0); +__decorate([ + e$2() +], BrowserModPopup.prototype, "dismissable", void 0); +customElements.define("browser-mod-popup", BrowserModPopup); +const PopupMixin = (SuperClass) => { + return class PopupMixinClass extends SuperClass { + constructor() { + super(); + loadLoadCardHelpers(); + this._popupEl = document.createElement("browser-mod-popup"); + document.body.append(this._popupEl); + // const historyListener = async (ev) => { + // const popupState = ev.state?.browserModPopup; + // if (popupState) { + // if (popupState.open) { + // this._popupEl.setupDialog(...popupState.args); + // this._popupEl.openDialog(); + // } else { + // this._popupEl.closeDialog(); + // } + // } + // }; + // window.addEventListener("popstate", historyListener); + } + showPopup(...args) { + // if (history.state?.browserModPopup === undefined) { + // history.replaceState( + // { + // browserModPopup: { + // open: false, + // }, + // }, + // "" + // ); + // } + // history.pushState( + // { + // browserModPopup: { + // open: true, + // args, + // }, + // }, + // "" + // ); + this._popupEl.setupDialog(...args); + this._popupEl.openDialog(); + } + closePopup(...args) { + this._popupEl.closeDialog(); } }; }; @@ -1363,99 +1147,29 @@ var pjson = { dependencies: dependencies }; -// export class BrowserMod extends ext(BrowserModConnection, [ -// BrowserModBrowserMixin, -// BrowserModPopupsMixin, -// BrowserModScreensaverMixin, -// BrowserModCameraMixin, -// FullyKioskMixin, -// BrowserModMediaPlayerMixin, -// ]) { -class BrowserMod extends BrowserStateMixin(CameraMixin(MediaPlayerMixin(ScreenSaverMixin(FullyMixin(RequireInteractMixin(ConnectionMixin(EventTarget))))))) { +/* + TODO: + - Popups + - Commands + - Tweaks + */ +class BrowserMod extends PopupMixin(BrowserStateMixin(CameraMixin(MediaPlayerMixin(ScreenSaverMixin(FullyMixin(RequireInteractMixin(ConnectionMixin(EventTarget)))))))) { constructor() { super(); - this.entity_id = deviceID.replace("-", "_"); - this.cast = document.querySelector("hc-main") !== null; this.connect(); - document.body.addEventListener("ll-custom", (ev) => { - if (ev.detail.browser_mod) { - this.msg_callback(ev.detail.browser_mod); - } - }); + // document.body.addEventListener("ll-custom", (ev) => { + // if ((ev as CustomEvent).detail.browser_mod) { + // this.msg_callback((ev as CustomEvent).detail.browser_mod); + // } + // }); console.info(`%cBROWSER_MOD ${pjson.version} IS INSTALLED - %cDeviceID: ${deviceID}`, "color: green; font-weight: bold", ""); - } - async msg_callback(msg) { - const handlers = { - update: (msg) => this.update(msg), - debug: (msg) => this.debug(msg), - play: (msg) => this.player_play(msg.media_content_id), - pause: (msg) => this.player_pause(), - stop: (msg) => this.player_stop(), - "set-volume": (msg) => this.player_set_volume(msg.volume_level), - mute: (msg) => this.player_mute(msg.mute), - toast: (msg) => this.do_toast(msg.message, msg.duration), - popup: (msg) => this.do_popup(msg), - "close-popup": (msg) => this.do_close_popup(), - "more-info": (msg) => this.do_more_info(msg.entity_id, msg.large), - navigate: (msg) => this.do_navigate(msg.navigation_path), - "set-theme": (msg) => this.set_theme(msg), - "lovelace-reload": (msg) => this.lovelace_reload(msg), - "window-reload": () => window.location.reload(), - blackout: (msg) => this.do_blackout(msg.time ? parseInt(msg.time) : undefined), - "no-blackout": (msg) => { - if (msg.brightness && this.isFully) { - window.fully.setScreenBrightness(msg.brightness); - } - this.no_blackout(); - }, - "call-service": (msg) => this.call_service(msg), - commands: async (msg) => { - for (const m of msg.commands) { - await this.msg_callback(m); - } - }, - delay: async (msg) => await new Promise((resolve) => { - window.setTimeout(resolve, msg.seconds * 1000); - }), - }; - await handlers[msg.command.replace("_", "-")](msg); - } - debug(msg) { - popUp(`deviceID`, { type: "markdown", content: `# ${deviceID}` }); - alert(deviceID); - } - set_theme(msg) { - if (!msg.theme) - msg.theme = "default"; - fireEvent("settheme", { theme: msg.theme }, ha_element()); - } - lovelace_reload(msg) { - const ll = lovelace_view(); - if (ll) - fireEvent("config-refresh", {}, ll); - } - call_service(msg) { - const _replaceThis = (data) => { - if (data === "this") - return deviceID; - if (Array.isArray(data)) - return data.map(_replaceThis); - if (data.constructor == Object) { - for (const key in data) - data[key] = _replaceThis(data[key]); - } - return data; - }; - const [domain, service] = msg.service.split(".", 2); - let service_data = _replaceThis(JSON.parse(JSON.stringify(msg.service_data))); - this.hass.callService(domain, service, service_data); + %cDeviceID: ${this.deviceID}`, "color: green; font-weight: bold", ""); } } -(async () => { - await hass_loaded(); - if (!window.browser_mod) - window.browser_mod = new BrowserMod(); -})(); +// (async () => { +// await hass_loaded(); +if (!window.browser_mod) + window.browser_mod = new BrowserMod(); +// })(); export { BrowserMod }; diff --git a/custom_components/browser_mod/browser_mod_panel.js b/custom_components/browser_mod/browser_mod_panel.js index 3779410..b65993b 100644 --- a/custom_components/browser_mod/browser_mod_panel.js +++ b/custom_components/browser_mod/browser_mod_panel.js @@ -65,6 +65,7 @@ const loadDevTools = async () => { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l; if (customElements.get("ha-config-dashboard")) return; + await customElements.whenDefined("partial-panel-resolver"); const ppResolver = document.createElement("partial-panel-resolver"); const routes = ppResolver.getRoutes([ { @@ -73,6 +74,7 @@ const loadDevTools = async () => { }, ]); await ((_c = (_b = (_a = routes === null || routes === void 0 ? void 0 : routes.routes) === null || _a === void 0 ? void 0 : _a.a) === null || _b === void 0 ? void 0 : _b.load) === null || _c === void 0 ? void 0 : _c.call(_b)); + await customElements.whenDefined("ha-panel-config"); const configRouter = document.createElement("ha-panel-config"); await ((_g = (_f = (_e = (_d = configRouter === null || configRouter === void 0 ? void 0 : configRouter.routerOptions) === null || _d === void 0 ? void 0 : _d.routes) === null || _e === void 0 ? void 0 : _e.dashboard) === null || _f === void 0 ? void 0 : _f.load) === null || _g === void 0 ? void 0 : _g.call(_f)); // Load ha-config-dashboard await ((_l = (_k = (_j = (_h = configRouter === null || configRouter === void 0 ? void 0 : configRouter.routerOptions) === null || _h === void 0 ? void 0 : _h.routes) === null || _j === void 0 ? void 0 : _j.cloud) === null || _k === void 0 ? void 0 : _k.load) === null || _l === void 0 ? void 0 : _l.call(_k)); // Load ha-settings-row @@ -96,13 +98,29 @@ loadDevTools().then(() => { } unregister_device(ev) { const deviceID = ev.currentTarget.deviceID; - if (deviceID === window.browser_mod.deviceID) - window.browser_mod.registered = false; - else - window.browser_mod.connection.sendMessage({ - type: "browser_mod/unregister", - deviceID, - }); + const unregisterCallback = () => { + console.log(deviceID, window.browser_mod.deviceID); + if (deviceID === window.browser_mod.deviceID) { + console.log("Unregister self"); + window.browser_mod.registered = false; + } + else { + window.browser_mod.connection.sendMessage({ + type: "browser_mod/unregister", + deviceID, + }); + } + }; + window.browser_mod.showPopup("Unregister device", `Are you sure you want to unregister device ${deviceID}?`, { + dismissable: false, + primary_action: { + label: "Yes", + callback: unregisterCallback, + }, + secondary_action: { + label: "No", + }, + }); } firstUpdated() { window.browser_mod.addEventListener("browser-mod-config-update", () => this.requestUpdate()); diff --git a/custom_components/browser_mod/device.py b/custom_components/browser_mod/device.py index 50840e8..7f7ff5e 100644 --- a/custom_components/browser_mod/device.py +++ b/custom_components/browser_mod/device.py @@ -112,7 +112,7 @@ class BrowserModDevice: dr = device_registry.async_get(hass) er = entity_registry.async_get(hass) - for e in self.entities.items(): + for e in self.entities.values(): er.async_remove(e.entity_id) self.entities = {} @@ -137,5 +137,5 @@ def getDevice(hass, deviceID, *, create=True): def deleteDevice(hass, deviceID): devices = hass.data[DOMAIN]["devices"] if deviceID in devices: - devices["deviceID"].delete() - del devices["deviceID"] + devices[deviceID].delete(hass) + del devices[deviceID] diff --git a/js/config_panel/helpers.ts b/js/config_panel/helpers.ts index c37b865..d780231 100644 --- a/js/config_panel/helpers.ts +++ b/js/config_panel/helpers.ts @@ -2,6 +2,8 @@ // Also provides ha-settings-row export const loadDevTools = async () => { if (customElements.get("ha-config-dashboard")) return; + + await customElements.whenDefined("partial-panel-resolver"); const ppResolver = document.createElement("partial-panel-resolver"); const routes = (ppResolver as any).getRoutes([ { @@ -10,6 +12,7 @@ export const loadDevTools = async () => { }, ]); await routes?.routes?.a?.load?.(); + await customElements.whenDefined("ha-panel-config"); const configRouter = document.createElement("ha-panel-config"); await (configRouter as any)?.routerOptions?.routes?.dashboard?.load?.(); // Load ha-config-dashboard await (configRouter as any)?.routerOptions?.routes?.cloud?.load?.(); // Load ha-settings-row diff --git a/js/config_panel/main.ts b/js/config_panel/main.ts index 35a8671..9c5aa68 100644 --- a/js/config_panel/main.ts +++ b/js/config_panel/main.ts @@ -23,13 +23,34 @@ loadDevTools().then(() => { unregister_device(ev) { const deviceID = ev.currentTarget.deviceID; - if (deviceID === window.browser_mod.deviceID) - window.browser_mod.registered = false; - else - window.browser_mod.connection.sendMessage({ - type: "browser_mod/unregister", - deviceID, - }); + + const unregisterCallback = () => { + console.log(deviceID, window.browser_mod.deviceID); + if (deviceID === window.browser_mod.deviceID) { + console.log("Unregister self"); + window.browser_mod.registered = false; + } else { + window.browser_mod.connection.sendMessage({ + type: "browser_mod/unregister", + deviceID, + }); + } + }; + + window.browser_mod.showPopup( + "Unregister device", + `Are you sure you want to unregister device ${deviceID}?`, + { + dismissable: false, + primary_action: { + label: "Yes", + callback: unregisterCallback, + }, + secondary_action: { + label: "No", + }, + } + ); } firstUpdated() { diff --git a/js/helpers.ts b/js/helpers.ts index cca423f..c7755fe 100644 --- a/js/helpers.ts +++ b/js/helpers.ts @@ -1,4 +1,4 @@ -const TIMEOUT_ERROR = "SLECTTREE-TIMEOUT"; +const TIMEOUT_ERROR = "SELECTTREE-TIMEOUT"; async function _await_el(el) { if (el.localName?.includes("-")) @@ -36,7 +36,7 @@ export async function selectTree(root, path, all = false, timeout = 10000) { }); } -async function _hass_base_el() { +export async function hass_base_el() { await Promise.race([ customElements.whenDefined("home-assistant"), customElements.whenDefined("hc-main"), @@ -52,12 +52,26 @@ async function _hass_base_el() { } export async function hass() { - const base: any = await _hass_base_el(); + const base: any = await hass_base_el(); while (!base.hass) await new Promise((r) => window.setTimeout(r, 100)); return base.hass; } export async function provideHass(el) { - const base: any = await _hass_base_el(); + const base: any = await hass_base_el(); base.provideHass(el); } + +export const loadLoadCardHelpers = async () => { + if (window.loadCardHelpers !== undefined) return; + + await customElements.whenDefined("partial-panel-resolver"); + const ppResolver = document.createElement("partial-panel-resolver"); + const routes = (ppResolver as any).getRoutes([ + { + component_name: "lovelace", + url_path: "a", + }, + ]); + await routes?.routes?.a?.load?.(); +}; diff --git a/js/plugin/browser.ts b/js/plugin/browser.ts index 4e4746d..bf3d3af 100644 --- a/js/plugin/browser.ts +++ b/js/plugin/browser.ts @@ -1,6 +1,3 @@ -import { fireEvent } from "card-tools/src/event"; -import { ha_element } from "card-tools/src/hass"; - export const BrowserStateMixin = (SuperClass) => { return class BrowserStateMixinClass extends SuperClass { constructor() { @@ -41,10 +38,10 @@ export const BrowserStateMixin = (SuperClass) => { update(); } - do_navigate(path) { - if (!path) return; - history.pushState(null, "", path); - fireEvent("location-changed", {}, ha_element()); - } + // do_navigate(path) { + // if (!path) return; + // history.pushState(null, "", path); + // fireEvent("location-changed", {}, ha_element()); + // } }; }; diff --git a/js/plugin/main.ts b/js/plugin/main.ts index cbb1c69..de1ffff 100644 --- a/js/plugin/main.ts +++ b/js/plugin/main.ts @@ -1,8 +1,3 @@ -import { deviceID } from "card-tools/src/deviceID"; -import { lovelace_view } from "card-tools/src/hass"; -import { popUp } from "card-tools/src/popup"; -import { fireEvent } from "card-tools/src/event"; -import { ha_element, hass_loaded } from "card-tools/src/hass"; import "./browser-player"; // import { BrowserModConnection } from "./connection"; @@ -12,145 +7,141 @@ import { MediaPlayerMixin } from "./mediaPlayer"; import { CameraMixin } from "./camera"; import { RequireInteractMixin } from "./require-interact"; import { FullyMixin } from "./fullyKiosk"; -import { BrowserModPopupsMixin } from "./popups"; import { BrowserStateMixin } from "./browser"; +import "./popups"; +import { PopupMixin } from "./popups"; import pjson from "../../package.json"; -const ext = (baseClass, mixins) => - mixins.reduceRight((base, mixin) => mixin(base), baseClass); - -// export class BrowserMod extends ext(BrowserModConnection, [ -// BrowserModBrowserMixin, -// BrowserModPopupsMixin, -// BrowserModScreensaverMixin, -// BrowserModCameraMixin, -// FullyKioskMixin, -// BrowserModMediaPlayerMixin, -// ]) { -export class BrowserMod extends BrowserStateMixin( - CameraMixin( - MediaPlayerMixin( - ScreenSaverMixin( - FullyMixin(RequireInteractMixin(ConnectionMixin(EventTarget))) +/* + TODO: + - Popups + - Commands + - Tweaks + */ +export class BrowserMod extends PopupMixin( + BrowserStateMixin( + CameraMixin( + MediaPlayerMixin( + ScreenSaverMixin( + FullyMixin(RequireInteractMixin(ConnectionMixin(EventTarget))) + ) ) ) ) ) { constructor() { super(); - this.entity_id = deviceID.replace("-", "_"); - this.cast = document.querySelector("hc-main") !== null; this.connect(); - document.body.addEventListener("ll-custom", (ev) => { - if ((ev as CustomEvent).detail.browser_mod) { - this.msg_callback((ev as CustomEvent).detail.browser_mod); - } - }); + // document.body.addEventListener("ll-custom", (ev) => { + // if ((ev as CustomEvent).detail.browser_mod) { + // this.msg_callback((ev as CustomEvent).detail.browser_mod); + // } + // }); console.info( `%cBROWSER_MOD ${pjson.version} IS INSTALLED - %cDeviceID: ${deviceID}`, + %cDeviceID: ${this.deviceID}`, "color: green; font-weight: bold", "" ); } - async msg_callback(msg) { - const handlers = { - update: (msg) => this.update(msg), - debug: (msg) => this.debug(msg), + // async msg_callback(msg) { + // const handlers = { + // update: (msg) => this.update(msg), + // debug: (msg) => this.debug(msg), - play: (msg) => this.player_play(msg.media_content_id), - pause: (msg) => this.player_pause(), - stop: (msg) => this.player_stop(), - "set-volume": (msg) => this.player_set_volume(msg.volume_level), - mute: (msg) => this.player_mute(msg.mute), + // play: (msg) => this.player_play(msg.media_content_id), + // pause: (msg) => this.player_pause(), + // stop: (msg) => this.player_stop(), + // "set-volume": (msg) => this.player_set_volume(msg.volume_level), + // mute: (msg) => this.player_mute(msg.mute), - toast: (msg) => this.do_toast(msg.message, msg.duration), - popup: (msg) => this.do_popup(msg), - "close-popup": (msg) => this.do_close_popup(), - "more-info": (msg) => this.do_more_info(msg.entity_id, msg.large), + // toast: (msg) => this.do_toast(msg.message, msg.duration), + // popup: (msg) => this.do_popup(msg), + // "close-popup": (msg) => this.do_close_popup(), + // "more-info": (msg) => this.do_more_info(msg.entity_id, msg.large), - navigate: (msg) => this.do_navigate(msg.navigation_path), - "set-theme": (msg) => this.set_theme(msg), - "lovelace-reload": (msg) => this.lovelace_reload(msg), - "window-reload": () => window.location.reload(), + // navigate: (msg) => this.do_navigate(msg.navigation_path), + // "set-theme": (msg) => this.set_theme(msg), + // "lovelace-reload": (msg) => this.lovelace_reload(msg), + // "window-reload": () => window.location.reload(), - blackout: (msg) => - this.do_blackout(msg.time ? parseInt(msg.time) : undefined), - "no-blackout": (msg) => { - if (msg.brightness && this.isFully) { - (window as any).fully.setScreenBrightness(msg.brightness); - } - this.no_blackout(); - }, + // blackout: (msg) => + // this.do_blackout(msg.time ? parseInt(msg.time) : undefined), + // "no-blackout": (msg) => { + // if (msg.brightness && this.isFully) { + // (window as any).fully.setScreenBrightness(msg.brightness); + // } + // this.no_blackout(); + // }, - "call-service": (msg) => this.call_service(msg), - commands: async (msg) => { - for (const m of msg.commands) { - await this.msg_callback(m); - } - }, - delay: async (msg) => - await new Promise((resolve) => { - window.setTimeout(resolve, msg.seconds * 1000); - }), - }; + // "call-service": (msg) => this.call_service(msg), + // commands: async (msg) => { + // for (const m of msg.commands) { + // await this.msg_callback(m); + // } + // }, + // delay: async (msg) => + // await new Promise((resolve) => { + // window.setTimeout(resolve, msg.seconds * 1000); + // }), + // }; - await handlers[msg.command.replace("_", "-")](msg); - } - - debug(msg) { - popUp(`deviceID`, { type: "markdown", content: `# ${deviceID}` }); - alert(deviceID); - } - - set_theme(msg) { - if (!msg.theme) msg.theme = "default"; - fireEvent("settheme", { theme: msg.theme }, ha_element()); - } - - lovelace_reload(msg) { - const ll = lovelace_view(); - if (ll) fireEvent("config-refresh", {}, ll); - } - - call_service(msg) { - const _replaceThis = (data) => { - if (data === "this") return deviceID; - if (Array.isArray(data)) return data.map(_replaceThis); - if (data.constructor == Object) { - for (const key in data) data[key] = _replaceThis(data[key]); - } - return data; - }; - const [domain, service] = msg.service.split(".", 2); - let service_data = _replaceThis( - JSON.parse(JSON.stringify(msg.service_data)) - ); - this.hass.callService(domain, service, service_data); - } - - // update(msg = null) { - // if (msg) { - // if (msg.name) { - // this.entity_id = msg.name.toLowerCase(); - // } - // if (msg.camera && !this.isFully) { - // this.setup_camera(); - // } - // this.config = { ...this.config, ...msg }; - // } - // this.player_update(); - // this.fully_update(); - // this.screen_update(); - // this.sensor_update(); + // await handlers[msg.command.replace("_", "-")](msg); // } + + // debug(msg) { + // popUp(`deviceID`, { type: "markdown", content: `# ${deviceID}` }); + // alert(deviceID); + // } + + // set_theme(msg) { + // if (!msg.theme) msg.theme = "default"; + // fireEvent("settheme", { theme: msg.theme }, ha_element()); + // } + + // lovelace_reload(msg) { + // const ll = lovelace_view(); + // if (ll) fireEvent("config-refresh", {}, ll); + // } + + // call_service(msg) { + // const _replaceThis = (data) => { + // if (data === "this") return deviceID; + // if (Array.isArray(data)) return data.map(_replaceThis); + // if (data.constructor == Object) { + // for (const key in data) data[key] = _replaceThis(data[key]); + // } + // return data; + // }; + // const [domain, service] = msg.service.split(".", 2); + // let service_data = _replaceThis( + // JSON.parse(JSON.stringify(msg.service_data)) + // ); + // this.hass.callService(domain, service, service_data); + // } + + // // update(msg = null) { + // // if (msg) { + // // if (msg.name) { + // // this.entity_id = msg.name.toLowerCase(); + // // } + // // if (msg.camera && !this.isFully) { + // // this.setup_camera(); + // // } + // // this.config = { ...this.config, ...msg }; + // // } + // // this.player_update(); + // // this.fully_update(); + // // this.screen_update(); + // // this.sensor_update(); + // // } } -(async () => { - await hass_loaded(); +// (async () => { +// await hass_loaded(); - if (!window.browser_mod) window.browser_mod = new BrowserMod(); -})(); +if (!window.browser_mod) window.browser_mod = new BrowserMod(); +// })(); diff --git a/js/plugin/popups.ts b/js/plugin/popups.ts index 1d69670..c12553b 100644 --- a/js/plugin/popups.ts +++ b/js/plugin/popups.ts @@ -1,85 +1,235 @@ -import { fireEvent } from "card-tools/src/event"; -import { load_lovelace, lovelace, ha_element } from "card-tools/src/hass"; -import { moreInfo } from "card-tools/src/more-info"; -import { closePopUp, popUp } from "card-tools/src/popup"; +import { LitElement, html, css } from "lit"; +import { property } from "lit/decorators.js"; +import { unsafeHTML } from "lit/directives/unsafe-html.js"; +import { provideHass, loadLoadCardHelpers } from "../helpers"; + +class BrowserModPopup extends LitElement { + @property() open; + @property() content; + @property() title; + @property({ reflect: true }) actions; + @property({ reflect: true }) card; + @property() primary_action; + @property() secondary_action; + @property() dismissable; + + closeDialog() { + this.open = false; + } + + openDialog() { + this.open = true; + } + + async setupDialog( + title, + content, + { + primary_action = undefined, + secondary_action = undefined, + dismissable = true, + } + ) { + this.dismissable = dismissable; + this.title = title; + if (content && typeof content === "object") { + // Create a card from config in content + this.card = true; + const helpers = await window.loadCardHelpers(); + const card = await helpers.createCardElement(content); + card.hass = window.browser_mod.hass; + provideHass(card); + this.content = card; + } else { + // Basic HTML content + this.content = unsafeHTML(content); + } + if (primary_action) { + this.primary_action = primary_action; + this.secondary_action = secondary_action; + this.actions = ""; + } else { + this.primary_action = undefined; + this.secondary_action = undefined; + this.actions = undefined; + } + } + + _primary_clicked() { + this.closeDialog(); + const eval2 = eval; + this.primary_action?.callback?.(); + } + _secondary_clicked() { + this.closeDialog(); + const eval2 = eval; + this.secondary_action?.callback?.(); + } + + render() { + if (!this.open) return html``; + + return html` + + ${this.title + ? html` + + ${this.dismissable + ? html` + + + + ` + : ""} +
${this.title}
+
+ ` + : html``} + +
${this.content}
+ + ${this.primary_action !== undefined + ? html` + + ` + : ""} + ${this.secondary_action !== undefined + ? html` + + ` + : ""} +
+ `; + } + + static get styles() { + return css` + ha-dialog { + --mdc-dialog-min-width: 400px; + --mdc-dialog-max-width: 600px; + --mdc-dialog-heading-ink-color: var(--primary-text-color); + --mdc-dialog-content-ink-color: var(--primary-text-color); + --justify-action-buttons: space-between; + + --mdc-dialog-box-shadow: 0px 0px 0px var(--ha-card-border-width, 1px) + var(--ha-card-border-color, var(--divider-color, #e0e0e0)); + --ha-dialog-border-radius: 8px; + --mdc-theme-surface: var( + --ha-card-background, + var(--card-background-color, white) + ); + } + + app-toolbar { + flex-shrink: 0; + color: var(--primary-text-color); + background-color: var(--sidebar-background-color); + } + ha-icon-button > * { + display: flex; + } + .main-title { + margin-left: 16px; + line-height: 1.3em; + max-height: 2.6em; + overflow: hidden; + text-overflow: ellipsis; + } + .content { + margin: -20px -24px; + padding: 20px 24px; + } + + :host([card]) .content { + padding: 0; + } + :host([actions]) .content { + border-bottom: 1px solid var(--divider-color); + } + + @media all and (max-width: 450px), all and (max-height: 500px) { + ha-dialog { + --mdc-dialog-min-width: 100vw; + --mdc-dialog-max-width: 100vw; + --mdc-dialog-min-height: 100%; + --mdc-dialog-max-height: 100%; + --mdc-shape-medium: 0px; + --vertial-align-dialog: flex-end; + } + } + `; + } +} + +customElements.define("browser-mod-popup", BrowserModPopup); + +export const PopupMixin = (SuperClass) => { + return class PopupMixinClass extends SuperClass { + private _popupEl: any; -export const BrowserModPopupsMixin = (C) => - class extends C { constructor() { super(); - if (document.querySelector("home-assistant")) - document - .querySelector("home-assistant") - .addEventListener("hass-more-info", (ev) => this._popup_card(ev)); - const isCast = document.querySelector("hc-main") !== null; - if (!isCast) load_lovelace(); + loadLoadCardHelpers(); + + this._popupEl = document.createElement("browser-mod-popup"); + document.body.append(this._popupEl); + + // const historyListener = async (ev) => { + // const popupState = ev.state?.browserModPopup; + // if (popupState) { + // if (popupState.open) { + // this._popupEl.setupDialog(...popupState.args); + // this._popupEl.openDialog(); + // } else { + // this._popupEl.closeDialog(); + // } + // } + // }; + // window.addEventListener("popstate", historyListener); } - _popup_card(ev) { - if (!lovelace()) return; - if (!ev.detail || !ev.detail.entityId) return; - const data = { - ...lovelace().config.popup_cards, - ...lovelace().config.views[lovelace().current_view].popup_cards, - }; - const d = data[ev.detail.entityId]; - if (!d) return; - - this.do_popup(d); - window.setTimeout(() => { - fireEvent("hass-more-info", { entityID: "." }, ha_element()); - }, 50); + showPopup(...args) { + // if (history.state?.browserModPopup === undefined) { + // history.replaceState( + // { + // browserModPopup: { + // open: false, + // }, + // }, + // "" + // ); + // } + // history.pushState( + // { + // browserModPopup: { + // open: true, + // args, + // }, + // }, + // "" + // ); + this._popupEl.setupDialog(...args); + this._popupEl.openDialog(); } - do_popup(cfg) { - if (!(cfg.title || cfg.auto_close || cfg.hide_header)) { - console.error( - "browser_mod: popup: Must specify title, auto_close or hide_header." - ); - return; - } - if (!cfg.card) { - console.error("browser_mod: popup: No card specified"); - return; - } - - const open = () => { - popUp( - cfg.title, - cfg.card, - cfg.large, - cfg.style, - cfg.auto_close || cfg.hide_header - ); - }; - - if (cfg.auto_close) { - this.screensaver_set(open, closePopUp, cfg.time); - } else { - open(); - } - } - - do_close_popup() { - this.screensaver_stop(); - closePopUp(); - } - - do_more_info(entity_id, large) { - if (!entity_id) return; - moreInfo(entity_id, large); - } - - do_toast(message, duration) { - if (!message) return; - fireEvent( - "hass-notification", - { - message, - duration: parseInt(duration), - }, - ha_element() - ); + closePopup(...args) { + this._popupEl.closeDialog(); } }; +}; diff --git a/js/plugin/screensaver.ts b/js/plugin/screensaver.ts index b18cef2..81b61d5 100644 --- a/js/plugin/screensaver.ts +++ b/js/plugin/screensaver.ts @@ -95,142 +95,3 @@ export const ScreenSaverMixin = (SuperClass) => { } return ScreenSaverMixinClass; }; - -// export const BrowserModScreensaverMixin = (C) => -// class extends C { -// constructor() { -// super(); -// this._blackout_panel = document.createElement("div"); - -// this._screenSaver = undefined; -// this._screenSaverTimer = undefined; -// this._screenSaverTimeOut = 0; - -// this._screenSaver = { -// fn: undefined, -// clearfn: undefined, -// timer: undefined, -// timeout: undefined, -// listeners: {}, -// active: false, -// }; - -// this._blackout_panel.style.cssText = ` -// position: fixed; -// left: 0; -// top: 0; -// padding: 0; -// margin: 0; -// width: 100%; -// height: 100%; -// background: black; -// display: none; -// `; -// document.body.appendChild(this._blackout_panel); -// } - -// screensaver_set(fn, clearfn, time) { -// this._ss_clear(); -// this._screenSaver = { -// fn, -// clearfn, -// timer: undefined, -// timeout: time, -// listeners: {}, -// active: false, -// }; -// const l = () => this.screensaver_update(); -// for (const event of ["mousemove", "mousedown", "keydown", "touchstart"]) { -// window.addEventListener(event, l); -// this._screenSaver.listeners[event] = l; -// } -// this._screenSaver.timer = window.setTimeout( -// () => this._ss_run(), -// time * 1000 -// ); -// } - -// screensaver_update() { -// if (this._screenSaver.active) { -// this.screensaver_stop(); -// } else { -// window.clearTimeout(this._screenSaver.timer); -// this._screenSaver.timer = window.setTimeout( -// () => this._ss_run(), -// this._screenSaver.timeout * 1000 -// ); -// } -// } - -// screensaver_stop() { -// this._ss_clear(); -// this._screenSaver.active = false; -// if (this._screenSaver.clearfn) this._screenSaver.clearfn(); -// if (this._screenSaver.timeout) { -// this.screensaver_set( -// this._screenSaver.fn, -// this._screenSaver.clearfn, -// this._screenSaver.timeout -// ); -// } -// } - -// _ss_clear() { -// window.clearTimeout(this._screenSaverTimer); -// for (const [k, v] of Object.entries(this._screenSaver.listeners)) { -// window.removeEventListener(k as any, v as any); -// } -// } - -// _ss_run() { -// this._screenSaver.active = true; -// this._screenSaver.fn(); -// } - -// do_blackout(timeout) { -// this.screensaver_set( -// () => { -// if (this.isFully) { -// if (this.config.screensaver) window.fully.startScreensaver(); -// else window.fully.turnScreenOff(true); -// } else { -// this._blackout_panel.style.display = "block"; -// } -// this.screen_update(); -// }, -// () => { -// if ((this._blackout_panel.style.display = "block")) -// this._blackout_panel.style.display = "none"; -// if (this.isFully) { -// if (!window.fully.getScreenOn()) window.fully.turnScreenOn(); -// window.fully.stopScreensaver(); -// } -// this.screen_update(); -// }, -// timeout || 0 -// ); -// } - -// no_blackout() { -// if (this.isFully) { -// window.fully.turnScreenOn(); -// window.fully.stopScreensaver(); -// } -// this.screensaver_stop(); -// } - -// screen_update() { -// this.sendUpdate({ -// screen: { -// blackout: this.isFully -// ? this.fully_screensaver !== undefined -// ? this.fully_screensaver -// : !window.fully.getScreenOn() -// : Boolean(this._blackout_panel.style.display === "block"), -// brightness: this.isFully -// ? window.fully.getScreenBrightness() -// : undefined, -// }, -// }); -// } -// }; diff --git a/js/plugin/types.ts b/js/plugin/types.ts index 270b2b0..0f694bb 100644 --- a/js/plugin/types.ts +++ b/js/plugin/types.ts @@ -33,5 +33,6 @@ declare global { fully?: FullyKiosk; hassConnection?: Promise; customCards?: [{}?]; + loadCardHelpers?: { () }; } }