From 0b662a38e978c8817a87e5d03696c496716311c4 Mon Sep 17 00:00:00 2001 From: Ian Richardson Date: Sat, 2 Nov 2019 21:59:24 -0600 Subject: [PATCH] housekeeping --- LICENSE | 2 +- README.md | 8 +- dist/restriction-card.js | 36 +- hacs.json | 4 + package.json | 88 ++-- ...rective.ts => action-handler-directive.ts} | 73 ++-- src/const.ts | 2 +- src/restriction-card.ts | 41 +- yarn.lock | 411 +++++++++--------- 9 files changed, 330 insertions(+), 335 deletions(-) create mode 100644 hacs.json rename src/{long-press-directive.ts => action-handler-directive.ts} (70%) diff --git a/LICENSE b/LICENSE index 6893c34..89ad0ba 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2019 Custom cards for Home Assistant +Copyright (c) 2019 Ian Richardson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 521043c..90f362d 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ This card is not to be used as a means to truly protect an instance. Someone wit [![GitHub Release][releases-shield]][releases] [![License][license-shield]](LICENSE.md) +[![hacs_badge](https://img.shields.io/badge/HACS-Default-orange.svg?style=for-the-badge)](https://github.com/custom-components/hacs) ![Project Maintenance][maintenance-shield] [![GitHub Activity][commits-shield]][commits] @@ -23,12 +24,11 @@ Hey dude! Help me out for a couple of :beers: or a :coffee:! ## Installation -This card is available in the [HACS (Home Assistant Community Store)](https://hacs.netlify.com) - -In your `resources` section add +Use [HACS](https://hacs.xyz) or follow this [guide](https://github.com/thomasloven/hass-config/wiki/Lovelace-Plugins) ```yaml -- url: /community_plugin/restriction-card/restriction-card.js +resources: + url: /local/roku-card.js type: module ``` diff --git a/dist/restriction-card.js b/dist/restriction-card.js index 56222c3..7ee0a48 100644 --- a/dist/restriction-card.js +++ b/dist/restriction-card.js @@ -25,7 +25,7 @@ function t(t,e,i,n){var s,o=arguments.length,r=o<3?e:null===n?n=Object.getOwnPro * 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 e=new WeakMap,i=t=>(...i)=>{const n=t(...i);return e.set(n,!0),n},n=t=>"function"==typeof t&&e.has(t),s=void 0!==window.customElements&&void 0!==window.customElements.polyfillWrapFlushCallback,o=(t,e,i=null)=>{for(;e!==i;){const i=e.nextSibling;t.removeChild(e),e=i}},r={},a={},c=`{{lit-${String(Math.random()).slice(2)}}}`,l=`\x3c!--${c}--\x3e`,h=new RegExp(`${c}|${l}`),d="$lit$";class u{constructor(t,e){this.parts=[],this.element=e;const i=[],n=[],s=document.createTreeWalker(e.content,133,null,!1);let o=0,r=-1,a=0;const{strings:l,values:{length:u}}=t;for(;a0;){const e=l[a],i=g.exec(e)[2],n=i.toLowerCase()+d,s=t.getAttribute(n);t.removeAttribute(n);const o=s.split(h);this.parts.push({type:"attribute",index:r,name:i,strings:o}),a+=o.length-1}}"TEMPLATE"===t.tagName&&(n.push(t),s.currentNode=t.content)}else if(3===t.nodeType){const e=t.data;if(e.indexOf(c)>=0){const n=t.parentNode,s=e.split(h),o=s.length-1;for(let e=0;e{const i=t.length-e.length;return i>=0&&t.slice(i)===e},m=t=>-1!==t.index,f=()=>document.createComment(""),g=/([ \x09\x0a\x0c\x0d])([^\0-\x1F\x7F-\x9F "'>=/]+)([ \x09\x0a\x0c\x0d]*=[ \x09\x0a\x0c\x0d]*(?:[^ \x09\x0a\x0c\x0d"'`<>=]*|"[^"]*|'[^']*))$/; + */}const e=new WeakMap,i=t=>(...i)=>{const n=t(...i);return e.set(n,!0),n},n=t=>"function"==typeof t&&e.has(t),s=void 0!==window.customElements&&void 0!==window.customElements.polyfillWrapFlushCallback,o=(t,e,i=null)=>{for(;e!==i;){const i=e.nextSibling;t.removeChild(e),e=i}},r={},a={},c=`{{lit-${String(Math.random()).slice(2)}}}`,l=`\x3c!--${c}--\x3e`,d=new RegExp(`${c}|${l}`),h="$lit$";class u{constructor(t,e){this.parts=[],this.element=e;const i=[],n=[],s=document.createTreeWalker(e.content,133,null,!1);let o=0,r=-1,a=0;const{strings:l,values:{length:u}}=t;for(;a0;){const e=l[a],i=g.exec(e)[2],n=i.toLowerCase()+h,s=t.getAttribute(n);t.removeAttribute(n);const o=s.split(d);this.parts.push({type:"attribute",index:r,name:i,strings:o}),a+=o.length-1}}"TEMPLATE"===t.tagName&&(n.push(t),s.currentNode=t.content)}else if(3===t.nodeType){const e=t.data;if(e.indexOf(c)>=0){const n=t.parentNode,s=e.split(d),o=s.length-1;for(let e=0;e{const i=t.length-e.length;return i>=0&&t.slice(i)===e},m=t=>-1!==t.index,f=()=>document.createComment(""),g=/([ \x09\x0a\x0c\x0d])([^\0-\x1F\x7F-\x9F "'>=/]+)([ \x09\x0a\x0c\x0d]*=[ \x09\x0a\x0c\x0d]*(?:[^ \x09\x0a\x0c\x0d"'`<>=]*|"[^"]*|'[^']*))$/; /** * @license * Copyright (c) 2017 The Polymer Project Authors. All rights reserved. @@ -52,7 +52,7 @@ class _{constructor(t,e,i){this.__parts=[],this.template=t,this.processor=e,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 y=` ${c} `;class v{constructor(t,e,i,n){this.strings=t,this.values=e,this.type=i,this.processor=n}getHTML(){const t=this.strings.length-1;let e="",i=!1;for(let n=0;n-1||i)&&-1===t.indexOf("--\x3e",s+1);const o=g.exec(t);e+=null===o?t+(i?y:l):t.substr(0,o.index)+o[1]+o[2]+d+o[3]+c}return e+=this.strings[t]}getTemplateElement(){const t=document.createElement("template");return t.innerHTML=this.getHTML(),t}} + */const y=` ${c} `;class v{constructor(t,e,i,n){this.strings=t,this.values=e,this.type=i,this.processor=n}getHTML(){const t=this.strings.length-1;let e="",i=!1;for(let n=0;n-1||i)&&-1===t.indexOf("--\x3e",s+1);const o=g.exec(t);e+=null===o?t+(i?y:l):t.substr(0,o.index)+o[1]+o[2]+h+o[3]+c}return e+=this.strings[t]}getTemplateElement(){const t=document.createElement("template");return t.innerHTML=this.getHTML(),t}} /** * @license * Copyright (c) 2017 The Polymer Project Authors. All rights reserved. @@ -65,7 +65,7 @@ class _{constructor(t,e,i){this.__parts=[],this.template=t,this.processor=e,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 w=t=>null===t||!("object"==typeof t||"function"==typeof t),S=t=>Array.isArray(t)||!(!t||!t[Symbol.iterator]);class b{constructor(t,e,i){this.dirty=!0,this.element=t,this.name=e,this.strings=i,this.parts=[];for(let t=0;tthis.handleEvent(t)}setValue(t){this.__pendingValue=t}commit(){for(;n(this.__pendingValue);){const t=this.__pendingValue;this.__pendingValue=r,t(this)}if(this.__pendingValue===r)return;const t=this.__pendingValue,e=this.value,i=null==t||null!=e&&(t.capture!==e.capture||t.once!==e.once||t.passive!==e.passive),s=null!=t&&(null==e||i);i&&this.element.removeEventListener(this.eventName,this.__boundHandleEvent,this.__options),s&&(this.__options=M(t),this.element.addEventListener(this.eventName,this.__boundHandleEvent,this.__options)),this.value=t,this.__pendingValue=r}handleEvent(t){"function"==typeof this.value?this.value.call(this.eventContext||this.element,t):this.value.handleEvent(t)}}const M=t=>t&&(N?{capture:t.capture,passive:t.passive,once:t.once}:t.capture); + */const w=t=>null===t||!("object"==typeof t||"function"==typeof t),S=t=>Array.isArray(t)||!(!t||!t[Symbol.iterator]);class b{constructor(t,e,i){this.dirty=!0,this.element=t,this.name=e,this.strings=i,this.parts=[];for(let t=0;tthis.handleEvent(t)}setValue(t){this.__pendingValue=t}commit(){for(;n(this.__pendingValue);){const t=this.__pendingValue;this.__pendingValue=r,t(this)}if(this.__pendingValue===r)return;const t=this.__pendingValue,e=this.value,i=null==t||null!=e&&(t.capture!==e.capture||t.once!==e.once||t.passive!==e.passive),s=null!=t&&(null==e||i);i&&this.element.removeEventListener(this.eventName,this.__boundHandleEvent,this.__options),s&&(this.__options=M(t),this.element.addEventListener(this.eventName,this.__boundHandleEvent,this.__options)),this.value=t,this.__pendingValue=r}handleEvent(t){"function"==typeof this.value?this.value.call(this.eventContext||this.element,t):this.value.handleEvent(t)}}const M=t=>t&&(E?{capture:t.capture,passive:t.passive,once:t.once}:t.capture); /** * @license * Copyright (c) 2017 The Polymer Project Authors. All rights reserved. @@ -78,7 +78,7 @@ class _{constructor(t,e,i){this.__parts=[],this.template=t,this.processor=e,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 A=new class{handleAttributeExpressions(t,e,i,n){const s=e[0];if("."===s){return new C(t,e.slice(1),i).parts}return"@"===s?[new T(t,e.slice(1),n.eventContext)]:"?"===s?[new k(t,e.slice(1),i)]:new b(t,e,i).parts}handleTextExpression(t){return new P(t)}}; + */const A=new class{handleAttributeExpressions(t,e,i,n){const s=e[0];if("."===s){return new k(t,e.slice(1),i).parts}return"@"===s?[new T(t,e.slice(1),n.eventContext)]:"?"===s?[new C(t,e.slice(1),i)]:new b(t,e,i).parts}handleTextExpression(t){return new P(t)}}; /** * @license * Copyright (c) 2017 The Polymer Project Authors. All rights reserved. @@ -131,7 +131,7 @@ class _{constructor(t,e,i){this.__parts=[],this.template=t,this.processor=e,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 H(t,e){const{element:{content:i},parts:n}=t,s=document.createTreeWalker(i,Y,null,!1);let o=U(n),r=n[o],a=-1,c=0;const l=[];let h=null;for(;s.nextNode();){a++;const t=s.currentNode;for(t.previousSibling===h&&(h=null),e.has(t)&&(l.push(t),null===h&&(h=t)),null!==h&&c++;void 0!==r&&r.index===a;)r.index=null!==h?-1:r.index-c,r=n[o=U(n,o)]}l.forEach(t=>t.parentNode.removeChild(t))}const L=t=>{let e=11===t.nodeType?0:1;const i=document.createTreeWalker(t,Y,null,!1);for(;i.nextNode();)e++;return e},U=(t,e=-1)=>{for(let i=e+1;it.parentNode.removeChild(t))}const L=t=>{let e=11===t.nodeType?0:1;const i=document.createTreeWalker(t,Y,null,!1);for(;i.nextNode();)e++;return e},U=(t,e=-1)=>{for(let i=e+1;i`${t}--${e}`;let $=!0;void 0===window.ShadyCSS?$=!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."),$=!1);const z=t=>e=>{const i=j(e.type,t);let n=R.get(i);void 0===n&&(n={stringsArray:new WeakMap,keyString:new Map},R.set(i,n));let s=n.stringsArray.get(e.strings);if(void 0!==s)return s;const o=e.strings.join(c);if(void 0===(s=n.keyString.get(o))){const i=e.getTemplateElement();$&&window.ShadyCSS.prepareTemplateDom(i,t),s=new u(e,i),n.keyString.set(o,s)}return n.stringsArray.set(e.strings,s),s},F=["html","svg"],I=new Set,q=(t,e,i)=>{I.add(t);const n=i?i.element:document.createElement("template"),s=e.querySelectorAll("style"),{length:o}=s;if(0===o)return void window.ShadyCSS.prepareTemplateStyles(n,t);const r=document.createElement("style");for(let t=0;t{F.forEach(e=>{const i=R.get(j(e,t));void 0!==i&&i.keyString.forEach(t=>{const{element:{content:e}}=t,i=new Set;Array.from(e.querySelectorAll("style")).forEach(t=>{i.add(t)}),H(t,i)})})})(t);const a=n.content;i?function(t,e,i=null){const{element:{content:n},parts:s}=t;if(null==i)return void n.appendChild(e);const o=document.createTreeWalker(n,Y,null,!1);let r=U(s),a=0,c=-1;for(;o.nextNode();){for(c++,o.currentNode===i&&(a=L(e),i.parentNode.insertBefore(e,i));-1!==r&&s[r].index===c;){if(a>0){for(;-1!==r;)s[r].index+=a,r=U(s,r);return}r=U(s,r)}}}(i,r,a.firstChild):a.insertBefore(r,a.firstChild),window.ShadyCSS.prepareTemplateStyles(n,t);const c=a.querySelector("style");if(window.ShadyCSS.nativeShadow&&null!==c)e.insertBefore(c.cloneNode(!0),e.firstChild);else if(i){a.insertBefore(r,a.firstChild);const t=new Set;t.add(r),H(i,t)}};window.JSCompiler_renameProperty=(t,e)=>t;const B={toAttribute(t,e){switch(e){case Boolean:return t?"":null;case Object:case Array:return null==t?t:JSON.stringify(t)}return t},fromAttribute(t,e){switch(e){case Boolean:return null!==t;case Number:return null===t?null:Number(t);case Object:case Array:return JSON.parse(t)}return t}},W=(t,e)=>e!==t&&(e==e||t==t),J={attribute:!0,type:String,converter:B,reflect:!1,hasChanged:W},Z=Promise.resolve(!0),X=1,G=4,K=8,Q=16,tt=32,et="finalized";class it extends HTMLElement{constructor(){super(),this._updateState=0,this._instanceProperties=void 0,this._updatePromise=Z,this._hasConnectedResolver=void 0,this._changedProperties=new Map,this._reflectingProperties=void 0,this.initialize()}static get observedAttributes(){this.finalize();const t=[];return this._classProperties.forEach((e,i)=>{const n=this._attributeNameForProperty(i,e);void 0!==n&&(this._attributeToPropertyMap.set(n,i),t.push(n))}),t}static _ensureClassProperties(){if(!this.hasOwnProperty(JSCompiler_renameProperty("_classProperties",this))){this._classProperties=new Map;const t=Object.getPrototypeOf(this)._classProperties;void 0!==t&&t.forEach((t,e)=>this._classProperties.set(e,t))}}static createProperty(t,e=J){if(this._ensureClassProperties(),this._classProperties.set(t,e),e.noAccessor||this.prototype.hasOwnProperty(t))return;const i="symbol"==typeof t?Symbol():`__${t}`;Object.defineProperty(this.prototype,t,{get(){return this[i]},set(e){const n=this[t];this[i]=e,this._requestUpdate(t,n)},configurable:!0,enumerable:!0})}static finalize(){const t=Object.getPrototypeOf(this);if(t.hasOwnProperty(et)||t.finalize(),this[et]=!0,this._ensureClassProperties(),this._attributeToPropertyMap=new Map,this.hasOwnProperty(JSCompiler_renameProperty("properties",this))){const t=this.properties,e=[...Object.getOwnPropertyNames(t),..."function"==typeof Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(t):[]];for(const i of e)this.createProperty(i,t[i])}}static _attributeNameForProperty(t,e){const i=e.attribute;return!1===i?void 0:"string"==typeof i?i:"string"==typeof t?t.toLowerCase():void 0}static _valueHasChanged(t,e,i=W){return i(t,e)}static _propertyValueFromAttribute(t,e){const i=e.type,n=e.converter||B,s="function"==typeof n?n:n.fromAttribute;return s?s(t,i):t}static _propertyValueToAttribute(t,e){if(void 0===e.reflect)return;const i=e.type,n=e.converter;return(n&&n.toAttribute||B.toAttribute)(t,i)}initialize(){this._saveInstanceProperties(),this._requestUpdate()}_saveInstanceProperties(){this.constructor._classProperties.forEach((t,e)=>{if(this.hasOwnProperty(e)){const t=this[e];delete this[e],this._instanceProperties||(this._instanceProperties=new Map),this._instanceProperties.set(e,t)}})}_applyInstanceProperties(){this._instanceProperties.forEach((t,e)=>this[e]=t),this._instanceProperties=void 0}connectedCallback(){this._updateState=this._updateState|tt,this._hasConnectedResolver&&(this._hasConnectedResolver(),this._hasConnectedResolver=void 0)}disconnectedCallback(){}attributeChangedCallback(t,e,i){e!==i&&this._attributeToProperty(t,i)}_propertyToAttribute(t,e,i=J){const n=this.constructor,s=n._attributeNameForProperty(t,i);if(void 0!==s){const t=n._propertyValueToAttribute(e,i);if(void 0===t)return;this._updateState=this._updateState|K,null==t?this.removeAttribute(s):this.setAttribute(s,t),this._updateState=this._updateState&~K}}_attributeToProperty(t,e){if(this._updateState&K)return;const i=this.constructor,n=i._attributeToPropertyMap.get(t);if(void 0!==n){const t=i._classProperties.get(n)||J;this._updateState=this._updateState|Q,this[n]=i._propertyValueFromAttribute(e,t),this._updateState=this._updateState&~Q}}_requestUpdate(t,e){let i=!0;if(void 0!==t){const n=this.constructor,s=n._classProperties.get(t)||J;n._valueHasChanged(this[t],e,s.hasChanged)?(this._changedProperties.has(t)||this._changedProperties.set(t,e),!0!==s.reflect||this._updateState&Q||(void 0===this._reflectingProperties&&(this._reflectingProperties=new Map),this._reflectingProperties.set(t,s))):i=!1}!this._hasRequestedUpdate&&i&&this._enqueueUpdate()}requestUpdate(t,e){return this._requestUpdate(t,e),this.updateComplete}async _enqueueUpdate(){let t,e;this._updateState=this._updateState|G;const i=this._updatePromise;this._updatePromise=new Promise((i,n)=>{t=i,e=n});try{await i}catch(t){}this._hasConnected||await new Promise(t=>this._hasConnectedResolver=t);try{const t=this.performUpdate();null!=t&&await t}catch(t){e(t)}t(!this._hasRequestedUpdate)}get _hasConnected(){return this._updateState&tt}get _hasRequestedUpdate(){return this._updateState&G}get hasUpdated(){return this._updateState&X}performUpdate(){this._instanceProperties&&this._applyInstanceProperties();let t=!1;const e=this._changedProperties;try{(t=this.shouldUpdate(e))&&this.update(e)}catch(e){throw t=!1,e}finally{this._markUpdated()}t&&(this._updateState&X||(this._updateState=this._updateState|X,this.firstUpdated(e)),this.updated(e))}_markUpdated(){this._changedProperties=new Map,this._updateState=this._updateState&~G}get updateComplete(){return this._getUpdateComplete()}_getUpdateComplete(){return this._updatePromise}shouldUpdate(t){return!0}update(t){void 0!==this._reflectingProperties&&this._reflectingProperties.size>0&&(this._reflectingProperties.forEach((t,e)=>this._propertyToAttribute(e,this[e],t)),this._reflectingProperties=void 0)}updated(t){}firstUpdated(t){}}it[et]=!0; +const j=(t,e)=>`${t}--${e}`;let z=!0;void 0===window.ShadyCSS?z=!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."),z=!1);const $=t=>e=>{const i=j(e.type,t);let n=R.get(i);void 0===n&&(n={stringsArray:new WeakMap,keyString:new Map},R.set(i,n));let s=n.stringsArray.get(e.strings);if(void 0!==s)return s;const o=e.strings.join(c);if(void 0===(s=n.keyString.get(o))){const i=e.getTemplateElement();z&&window.ShadyCSS.prepareTemplateDom(i,t),s=new u(e,i),n.keyString.set(o,s)}return n.stringsArray.set(e.strings,s),s},F=["html","svg"],I=new Set,q=(t,e,i)=>{I.add(t);const n=i?i.element:document.createElement("template"),s=e.querySelectorAll("style"),{length:o}=s;if(0===o)return void window.ShadyCSS.prepareTemplateStyles(n,t);const r=document.createElement("style");for(let t=0;t{F.forEach(e=>{const i=R.get(j(e,t));void 0!==i&&i.keyString.forEach(t=>{const{element:{content:e}}=t,i=new Set;Array.from(e.querySelectorAll("style")).forEach(t=>{i.add(t)}),H(t,i)})})})(t);const a=n.content;i?function(t,e,i=null){const{element:{content:n},parts:s}=t;if(null==i)return void n.appendChild(e);const o=document.createTreeWalker(n,Y,null,!1);let r=U(s),a=0,c=-1;for(;o.nextNode();){for(c++,o.currentNode===i&&(a=L(e),i.parentNode.insertBefore(e,i));-1!==r&&s[r].index===c;){if(a>0){for(;-1!==r;)s[r].index+=a,r=U(s,r);return}r=U(s,r)}}}(i,r,a.firstChild):a.insertBefore(r,a.firstChild),window.ShadyCSS.prepareTemplateStyles(n,t);const c=a.querySelector("style");if(window.ShadyCSS.nativeShadow&&null!==c)e.insertBefore(c.cloneNode(!0),e.firstChild);else if(i){a.insertBefore(r,a.firstChild);const t=new Set;t.add(r),H(i,t)}};window.JSCompiler_renameProperty=(t,e)=>t;const B={toAttribute(t,e){switch(e){case Boolean:return t?"":null;case Object:case Array:return null==t?t:JSON.stringify(t)}return t},fromAttribute(t,e){switch(e){case Boolean:return null!==t;case Number:return null===t?null:Number(t);case Object:case Array:return JSON.parse(t)}return t}},W=(t,e)=>e!==t&&(e==e||t==t),J={attribute:!0,type:String,converter:B,reflect:!1,hasChanged:W},Z=Promise.resolve(!0),X=1,G=4,K=8,Q=16,tt=32,et="finalized";class it extends HTMLElement{constructor(){super(),this._updateState=0,this._instanceProperties=void 0,this._updatePromise=Z,this._hasConnectedResolver=void 0,this._changedProperties=new Map,this._reflectingProperties=void 0,this.initialize()}static get observedAttributes(){this.finalize();const t=[];return this._classProperties.forEach((e,i)=>{const n=this._attributeNameForProperty(i,e);void 0!==n&&(this._attributeToPropertyMap.set(n,i),t.push(n))}),t}static _ensureClassProperties(){if(!this.hasOwnProperty(JSCompiler_renameProperty("_classProperties",this))){this._classProperties=new Map;const t=Object.getPrototypeOf(this)._classProperties;void 0!==t&&t.forEach((t,e)=>this._classProperties.set(e,t))}}static createProperty(t,e=J){if(this._ensureClassProperties(),this._classProperties.set(t,e),e.noAccessor||this.prototype.hasOwnProperty(t))return;const i="symbol"==typeof t?Symbol():`__${t}`;Object.defineProperty(this.prototype,t,{get(){return this[i]},set(e){const n=this[t];this[i]=e,this._requestUpdate(t,n)},configurable:!0,enumerable:!0})}static finalize(){const t=Object.getPrototypeOf(this);if(t.hasOwnProperty(et)||t.finalize(),this[et]=!0,this._ensureClassProperties(),this._attributeToPropertyMap=new Map,this.hasOwnProperty(JSCompiler_renameProperty("properties",this))){const t=this.properties,e=[...Object.getOwnPropertyNames(t),..."function"==typeof Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(t):[]];for(const i of e)this.createProperty(i,t[i])}}static _attributeNameForProperty(t,e){const i=e.attribute;return!1===i?void 0:"string"==typeof i?i:"string"==typeof t?t.toLowerCase():void 0}static _valueHasChanged(t,e,i=W){return i(t,e)}static _propertyValueFromAttribute(t,e){const i=e.type,n=e.converter||B,s="function"==typeof n?n:n.fromAttribute;return s?s(t,i):t}static _propertyValueToAttribute(t,e){if(void 0===e.reflect)return;const i=e.type,n=e.converter;return(n&&n.toAttribute||B.toAttribute)(t,i)}initialize(){this._saveInstanceProperties(),this._requestUpdate()}_saveInstanceProperties(){this.constructor._classProperties.forEach((t,e)=>{if(this.hasOwnProperty(e)){const t=this[e];delete this[e],this._instanceProperties||(this._instanceProperties=new Map),this._instanceProperties.set(e,t)}})}_applyInstanceProperties(){this._instanceProperties.forEach((t,e)=>this[e]=t),this._instanceProperties=void 0}connectedCallback(){this._updateState=this._updateState|tt,this._hasConnectedResolver&&(this._hasConnectedResolver(),this._hasConnectedResolver=void 0)}disconnectedCallback(){}attributeChangedCallback(t,e,i){e!==i&&this._attributeToProperty(t,i)}_propertyToAttribute(t,e,i=J){const n=this.constructor,s=n._attributeNameForProperty(t,i);if(void 0!==s){const t=n._propertyValueToAttribute(e,i);if(void 0===t)return;this._updateState=this._updateState|K,null==t?this.removeAttribute(s):this.setAttribute(s,t),this._updateState=this._updateState&~K}}_attributeToProperty(t,e){if(this._updateState&K)return;const i=this.constructor,n=i._attributeToPropertyMap.get(t);if(void 0!==n){const t=i._classProperties.get(n)||J;this._updateState=this._updateState|Q,this[n]=i._propertyValueFromAttribute(e,t),this._updateState=this._updateState&~Q}}_requestUpdate(t,e){let i=!0;if(void 0!==t){const n=this.constructor,s=n._classProperties.get(t)||J;n._valueHasChanged(this[t],e,s.hasChanged)?(this._changedProperties.has(t)||this._changedProperties.set(t,e),!0!==s.reflect||this._updateState&Q||(void 0===this._reflectingProperties&&(this._reflectingProperties=new Map),this._reflectingProperties.set(t,s))):i=!1}!this._hasRequestedUpdate&&i&&this._enqueueUpdate()}requestUpdate(t,e){return this._requestUpdate(t,e),this.updateComplete}async _enqueueUpdate(){let t,e;this._updateState=this._updateState|G;const i=this._updatePromise;this._updatePromise=new Promise((i,n)=>{t=i,e=n});try{await i}catch(t){}this._hasConnected||await new Promise(t=>this._hasConnectedResolver=t);try{const t=this.performUpdate();null!=t&&await t}catch(t){e(t)}t(!this._hasRequestedUpdate)}get _hasConnected(){return this._updateState&tt}get _hasRequestedUpdate(){return this._updateState&G}get hasUpdated(){return this._updateState&X}performUpdate(){this._instanceProperties&&this._applyInstanceProperties();let t=!1;const e=this._changedProperties;try{(t=this.shouldUpdate(e))&&this.update(e)}catch(e){throw t=!1,e}finally{this._markUpdated()}t&&(this._updateState&X||(this._updateState=this._updateState|X,this.firstUpdated(e)),this.updated(e))}_markUpdated(){this._changedProperties=new Map,this._updateState=this._updateState&~G}get updateComplete(){return this._getUpdateComplete()}_getUpdateComplete(){return this._updatePromise}shouldUpdate(t){return!0}update(t){void 0!==this._reflectingProperties&&this._reflectingProperties.size>0&&(this._reflectingProperties.forEach((t,e)=>this._propertyToAttribute(e,this[e],t)),this._reflectingProperties=void 0)}updated(t){}firstUpdated(t){}}it[et]=!0; /** * @license * Copyright (c) 2017 The Polymer Project Authors. All rights reserved. @@ -183,7 +183,7 @@ 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.2.1");const ht=t=>t.flat?t.flat(1/0):function t(e,i=[]){for(let n=0,s=e.length;n(t.add(e),t),new Set).forEach(t=>e.unshift(t))}else t&&e.push(t);return e}initialize(){super.initialize(),this.renderRoot=this.createRenderRoot(),window.ShadowRoot&&this.renderRoot instanceof window.ShadowRoot&&this.adoptStyles()}createRenderRoot(){return this.attachShadow({mode:"open"})}adoptStyles(){const t=this.constructor._styles;0!==t.length&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeShadow?rt?this.renderRoot.adoptedStyleSheets=t.map(t=>t.styleSheet):this._needsShimAdoptedStyleSheets=!0:window.ShadyCSS.ScopingShim.prepareAdoptedCssText(t.map(t=>t.cssText),this.localName))}connectedCallback(){super.connectedCallback(),this.hasUpdated&&void 0!==window.ShadyCSS&&window.ShadyCSS.styleElement(this)}update(t){super.update(t);const e=this.render();e instanceof v&&this.constructor.render(e,this.renderRoot,{scopeName:this.localName,eventContext:this}),this._needsShimAdoptedStyleSheets&&(this._needsShimAdoptedStyleSheets=!1,this.constructor._styles.forEach(t=>{const e=document.createElement("style");e.textContent=t.cssText,this.renderRoot.appendChild(e)}))}render(){}}dt.finalized=!0,dt.render=(t,e,i)=>{if(!i||"object"!=typeof i||!i.scopeName)throw new Error("The `scopeName` option is required.");const n=i.scopeName,s=V.has(e),r=$&&11===e.nodeType&&!!e.host,a=r&&!I.has(n),c=a?document.createDocumentFragment():e;if(((t,e,i)=>{let n=V.get(e);void 0===n&&(o(e,e.firstChild),V.set(e,n=new P(Object.assign({templateFactory:D},i))),n.appendInto(e)),n.setValue(t),n.commit()})(t,c,Object.assign({templateFactory:z(n)},i)),a){const t=V.get(c);V.delete(c);const i=t.value instanceof _?t.value.template:void 0;q(n,c,i),o(e,e.firstChild),e.appendChild(c),V.set(e,t)}!s&&r&&window.ShadyCSS.styleElement(e.host)}; +(window.litElementVersions||(window.litElementVersions=[])).push("2.2.1");const dt=t=>t.flat?t.flat(1/0):function t(e,i=[]){for(let n=0,s=e.length;n(t.add(e),t),new Set).forEach(t=>e.unshift(t))}else t&&e.push(t);return e}initialize(){super.initialize(),this.renderRoot=this.createRenderRoot(),window.ShadowRoot&&this.renderRoot instanceof window.ShadowRoot&&this.adoptStyles()}createRenderRoot(){return this.attachShadow({mode:"open"})}adoptStyles(){const t=this.constructor._styles;0!==t.length&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeShadow?rt?this.renderRoot.adoptedStyleSheets=t.map(t=>t.styleSheet):this._needsShimAdoptedStyleSheets=!0:window.ShadyCSS.ScopingShim.prepareAdoptedCssText(t.map(t=>t.cssText),this.localName))}connectedCallback(){super.connectedCallback(),this.hasUpdated&&void 0!==window.ShadyCSS&&window.ShadyCSS.styleElement(this)}update(t){super.update(t);const e=this.render();e instanceof v&&this.constructor.render(e,this.renderRoot,{scopeName:this.localName,eventContext:this}),this._needsShimAdoptedStyleSheets&&(this._needsShimAdoptedStyleSheets=!1,this.constructor._styles.forEach(t=>{const e=document.createElement("style");e.textContent=t.cssText,this.renderRoot.appendChild(e)}))}render(){}}ht.finalized=!0,ht.render=(t,e,i)=>{if(!i||"object"!=typeof i||!i.scopeName)throw new Error("The `scopeName` option is required.");const n=i.scopeName,s=V.has(e),r=z&&11===e.nodeType&&!!e.host,a=r&&!I.has(n),c=a?document.createDocumentFragment():e;if(((t,e,i)=>{let n=V.get(e);void 0===n&&(o(e,e.firstChild),V.set(e,n=new P(Object.assign({templateFactory:D},i))),n.appendInto(e)),n.setValue(t),n.commit()})(t,c,Object.assign({templateFactory:$(n)},i)),a){const t=V.get(c);V.delete(c);const i=t.value instanceof _?t.value.template:void 0;q(n,c,i),o(e,e.firstChild),e.appendChild(c),V.set(e,t)}!s&&r&&window.ShadyCSS.styleElement(e.host)}; /** * @license * Copyright (c) 2018 The Polymer Project Authors. All rights reserved. @@ -197,14 +197,12 @@ found at http://polymer.github.io/PATENTS.txt * subject to an additional IP rights grant found at * http://polymer.github.io/PATENTS.txt */ -const ut=new WeakMap,pt=i(t=>e=>{if(!(e instanceof x)||e instanceof E||"class"!==e.committer.name||e.committer.parts.length>1)throw new Error("The `classMap` directive must be used in the `class` attribute and must be the only part in the attribute.");const{committer:i}=e,{element:n}=i;ut.has(e)||(n.className=i.strings.join(" "));const{classList:s}=n,o=ut.get(e);for(const e in o)e in t||s.remove(e);for(const e in t){const i=t[e];if(!o||i!==o[e]){s[i?"add":"remove"](e)}}ut.set(e,t)});var mt={},ft=/d{1,4}|M{1,4}|YY(?:YY)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g,gt="[^\\s]+",_t=/\[([^]*?)\]/gm,yt=function(){};function vt(t,e){for(var i=[],n=0,s=t.length;n3?0:(t-t%10!=10)*t%10]}};var Ct={D:function(t){return t.getDate()},DD:function(t){return St(t.getDate())},Do:function(t,e){return e.DoFn(t.getDate())},d:function(t){return t.getDay()},dd:function(t){return St(t.getDay())},ddd:function(t,e){return e.dayNamesShort[t.getDay()]},dddd:function(t,e){return e.dayNames[t.getDay()]},M:function(t){return t.getMonth()+1},MM:function(t){return St(t.getMonth()+1)},MMM:function(t,e){return e.monthNamesShort[t.getMonth()]},MMMM:function(t,e){return e.monthNames[t.getMonth()]},YY:function(t){return St(String(t.getFullYear()),4).substr(2)},YYYY:function(t){return St(t.getFullYear(),4)},h:function(t){return t.getHours()%12||12},hh:function(t){return St(t.getHours()%12||12)},H:function(t){return t.getHours()},HH:function(t){return St(t.getHours())},m:function(t){return t.getMinutes()},mm:function(t){return St(t.getMinutes())},s:function(t){return t.getSeconds()},ss:function(t){return St(t.getSeconds())},S:function(t){return Math.round(t.getMilliseconds()/100)},SS:function(t){return St(Math.round(t.getMilliseconds()/10),2)},SSS:function(t){return St(t.getMilliseconds(),3)},a:function(t,e){return t.getHours()<12?e.amPm[0]:e.amPm[1]},A:function(t,e){return t.getHours()<12?e.amPm[0].toUpperCase():e.amPm[1].toUpperCase()},ZZ:function(t){var e=t.getTimezoneOffset();return(e>0?"-":"+")+St(100*Math.floor(Math.abs(e)/60)+Math.abs(e)%60,4)}},Et={D:["\\d\\d?",function(t,e){t.day=e}],Do:["\\d\\d?"+gt,function(t,e){t.day=parseInt(e,10)}],M:["\\d\\d?",function(t,e){t.month=e-1}],YY:["\\d\\d?",function(t,e){var i=+(""+(new Date).getFullYear()).substr(0,2);t.year=""+(e>68?i-1:i)+e}],h:["\\d\\d?",function(t,e){t.hour=e}],m:["\\d\\d?",function(t,e){t.minute=e}],s:["\\d\\d?",function(t,e){t.second=e}],YYYY:["\\d{4}",function(t,e){t.year=e}],S:["\\d",function(t,e){t.millisecond=100*e}],SS:["\\d{2}",function(t,e){t.millisecond=10*e}],SSS:["\\d{3}",function(t,e){t.millisecond=e}],d:["\\d\\d?",yt],ddd:[gt,yt],MMM:[gt,wt("monthNamesShort")],MMMM:[gt,wt("monthNames")],a:[gt,function(t,e,i){var n=e.toLowerCase();n===i.amPm[0]?t.isPm=!1:n===i.amPm[1]&&(t.isPm=!0)}],ZZ:["[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z",function(t,e){var i,n=(e+"").match(/([+-]|\d\d)/gi);n&&(i=60*n[1]+parseInt(n[2],10),t.timezoneOffset="+"===n[0]?i:-i)}]};Et.dd=Et.d,Et.dddd=Et.ddd,Et.DD=Et.D,Et.mm=Et.m,Et.hh=Et.H=Et.HH=Et.h,Et.MM=Et.M,Et.ss=Et.s,Et.A=Et.a,mt.masks={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",shortTime:"HH:mm",mediumTime:"HH:mm:ss",longTime:"HH:mm:ss.SSS"},mt.format=function(t,e,i){var n=i||mt.i18n;if("number"==typeof t&&(t=new Date(t)),"[object Date]"!==Object.prototype.toString.call(t)||isNaN(t.getTime()))throw new Error("Invalid Date in fecha.format");e=mt.masks[e]||e||mt.masks.default;var s=[];return(e=(e=e.replace(_t,(function(t,e){return s.push(e),"@@@"}))).replace(ft,(function(e){return e in Ct?Ct[e](t,n):e.slice(1,e.length-1)}))).replace(/@@@/g,(function(){return s.shift()}))},mt.parse=function(t,e,i){var n=i||mt.i18n;if("string"!=typeof e)throw new Error("Invalid format in fecha.parse");if(e=mt.masks[e]||e,t.length>1e3)return null;var s={},o=[],r=[];e=e.replace(_t,(function(t,e){return r.push(e),"@@@"}));var a,c=(a=e,a.replace(/[|\\{()[^$+*?.-]/g,"\\$&")).replace(ft,(function(t){if(Et[t]){var e=Et[t];return o.push(e[1]),"("+e[0]+")"}return t}));c=c.replace(/@@@/g,(function(){return r.shift()}));var l=t.match(new RegExp(c,"i"));if(!l)return null;for(var h=1;h=":return n>=i;case">":return n>i;case"!=":return n!==i;case"regex":return n.match(i);default:return!1}};const Dt="ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0;class Rt extends HTMLElement{constructor(){super(),this.holdTime=500,this.ripple=document.createElement("mwc-ripple"),this.timer=void 0,this.held=!1,this.cooldownStart=!1,this.cooldownEnd=!1}connectedCallback(){Object.assign(this.style,{position:"absolute",width:Dt?"100px":"50px",height:Dt?"100px":"50px",transform:"translate(-50%, -50%)",pointerEvents:"none"}),this.appendChild(this.ripple),this.ripple.primary=!0,["touchcancel","mouseout","mouseup","touchmove","mousewheel","wheel","scroll"].forEach(t=>{document.addEventListener(t,()=>{clearTimeout(this.timer),this.stopAnimation(),this.timer=void 0},{passive:!0})})}bind(t,e){if(t.longPress)return;t.longPress=!0,t.addEventListener("contextmenu",t=>{const e=t||window.event;return e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),e.cancelBubble=!0,e.returnValue=!1,!1});const i=t=>{if(this.cooldownStart)return;let e,i;this.held=!1,t.touches?(e=t.touches[0].pageX,i=t.touches[0].pageY):(e=t.pageX,i=t.pageY),this.timer=window.setTimeout(()=>{this.startAnimation(e,i),this.held=!0},this.holdTime),this.cooldownStart=!0,window.setTimeout(()=>this.cooldownStart=!1,100)},n=i=>{this.cooldownEnd||["touchend","touchcancel"].includes(i.type)&&void 0===this.timer||(clearTimeout(this.timer),this.stopAnimation(),this.timer=void 0,this.held?t.dispatchEvent(new Event("ha-hold")):e.hasDoubleClick?1===i.detail?this.dblClickTimeout=window.setTimeout(()=>{t.dispatchEvent(new Event("ha-click"))},250):(clearTimeout(this.dblClickTimeout),t.dispatchEvent(new Event("ha-dblclick"))):t.dispatchEvent(new Event("ha-click")),this.cooldownEnd=!0,window.setTimeout(()=>this.cooldownEnd=!1,100))};t.addEventListener("touchstart",i,{passive:!0}),t.addEventListener("touchend",n),t.addEventListener("touchcancel",n),window.navigator.userAgent.match(/iPhone OS 13_/)||(t.addEventListener("mousedown",i,{passive:!0}),t.addEventListener("click",n))}startAnimation(t,e){Object.assign(this.style,{left:`${t}px`,top:`${e}px`,display:null}),this.ripple.disabled=!1,this.ripple.active=!0,this.ripple.unbounded=!0}stopAnimation(){this.ripple.active=!1,this.ripple.disabled=!0,this.style.display="none"}}customElements.define("long-press-restriction",Rt);const Vt=(t,e)=>{const i=(()=>{const t=document.body;if(t.querySelector("long-press-restriction"))return t.querySelector("long-press-restriction");const e=document.createElement("long-press-restriction");return t.appendChild(e),e})();i&&i.bind(t,e)},Ot=i((t={})=>e=>{Vt(e.committer.element,t)});console.info("%c RESTRICTION-CARD \n%c Version 1.1.1 ","color: orange; font-weight: bold; background: black","color: white; font-weight: bold; background: dimgray");let Yt=class extends dt{set hass(t){this._hass=t;const e=this.shadowRoot.querySelector("#card > *");e&&(e.hass=t)}getCardSize(){const t=this.shadowRoot.querySelector("#card > *");return t&&"function"==typeof(e=t).getCardSize?e.getCardSize():1;var e}setConfig(t){if(!t.card)throw new Error("Error in card configuration.");if(t.restrictions&&t.restrictions.pin&&!t.restrictions.pin.code)throw new Error("A pin code is required for pin restrictions");this._config=Object.assign({duration:5,action:"tap"},t)}shouldUpdate(t){const e=t.get("hass");return!(!t.has("config")&&e)||!!(this._config&&this._config.condition&&this._config.condition.entity)&&e.states[this._config.condition.entity]!==this._hass.states[this._config.condition.entity]}render(){return this._config&&this._hass?this._config.restrictions&&this._matchRestriction(this._config.restrictions.hide)?O``:O` +const ut=new WeakMap,pt=i(t=>e=>{if(!(e instanceof x)||e instanceof N||"class"!==e.committer.name||e.committer.parts.length>1)throw new Error("The `classMap` directive must be used in the `class` attribute and must be the only part in the attribute.");const{committer:i}=e,{element:n}=i;ut.has(e)||(n.className=i.strings.join(" "));const{classList:s}=n,o=ut.get(e);for(const e in o)e in t||s.remove(e);for(const e in t){const i=t[e];if(!o||i!==o[e]){s[i?"add":"remove"](e)}}ut.set(e,t)});var mt={},ft=/d{1,4}|M{1,4}|YY(?:YY)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g,gt="[^\\s]+",_t=/\[([^]*?)\]/gm,yt=function(){};function vt(t,e){for(var i=[],n=0,s=t.length;n3?0:(t-t%10!=10)*t%10]}};var kt={D:function(t){return t.getDate()},DD:function(t){return St(t.getDate())},Do:function(t,e){return e.DoFn(t.getDate())},d:function(t){return t.getDay()},dd:function(t){return St(t.getDay())},ddd:function(t,e){return e.dayNamesShort[t.getDay()]},dddd:function(t,e){return e.dayNames[t.getDay()]},M:function(t){return t.getMonth()+1},MM:function(t){return St(t.getMonth()+1)},MMM:function(t,e){return e.monthNamesShort[t.getMonth()]},MMMM:function(t,e){return e.monthNames[t.getMonth()]},YY:function(t){return St(String(t.getFullYear()),4).substr(2)},YYYY:function(t){return St(t.getFullYear(),4)},h:function(t){return t.getHours()%12||12},hh:function(t){return St(t.getHours()%12||12)},H:function(t){return t.getHours()},HH:function(t){return St(t.getHours())},m:function(t){return t.getMinutes()},mm:function(t){return St(t.getMinutes())},s:function(t){return t.getSeconds()},ss:function(t){return St(t.getSeconds())},S:function(t){return Math.round(t.getMilliseconds()/100)},SS:function(t){return St(Math.round(t.getMilliseconds()/10),2)},SSS:function(t){return St(t.getMilliseconds(),3)},a:function(t,e){return t.getHours()<12?e.amPm[0]:e.amPm[1]},A:function(t,e){return t.getHours()<12?e.amPm[0].toUpperCase():e.amPm[1].toUpperCase()},ZZ:function(t){var e=t.getTimezoneOffset();return(e>0?"-":"+")+St(100*Math.floor(Math.abs(e)/60)+Math.abs(e)%60,4)}},Nt={D:["\\d\\d?",function(t,e){t.day=e}],Do:["\\d\\d?"+gt,function(t,e){t.day=parseInt(e,10)}],M:["\\d\\d?",function(t,e){t.month=e-1}],YY:["\\d\\d?",function(t,e){var i=+(""+(new Date).getFullYear()).substr(0,2);t.year=""+(e>68?i-1:i)+e}],h:["\\d\\d?",function(t,e){t.hour=e}],m:["\\d\\d?",function(t,e){t.minute=e}],s:["\\d\\d?",function(t,e){t.second=e}],YYYY:["\\d{4}",function(t,e){t.year=e}],S:["\\d",function(t,e){t.millisecond=100*e}],SS:["\\d{2}",function(t,e){t.millisecond=10*e}],SSS:["\\d{3}",function(t,e){t.millisecond=e}],d:["\\d\\d?",yt],ddd:[gt,yt],MMM:[gt,wt("monthNamesShort")],MMMM:[gt,wt("monthNames")],a:[gt,function(t,e,i){var n=e.toLowerCase();n===i.amPm[0]?t.isPm=!1:n===i.amPm[1]&&(t.isPm=!0)}],ZZ:["[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z",function(t,e){var i,n=(e+"").match(/([+-]|\d\d)/gi);n&&(i=60*n[1]+parseInt(n[2],10),t.timezoneOffset="+"===n[0]?i:-i)}]};Nt.dd=Nt.d,Nt.dddd=Nt.ddd,Nt.DD=Nt.D,Nt.mm=Nt.m,Nt.hh=Nt.H=Nt.HH=Nt.h,Nt.MM=Nt.M,Nt.ss=Nt.s,Nt.A=Nt.a,mt.masks={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",shortTime:"HH:mm",mediumTime:"HH:mm:ss",longTime:"HH:mm:ss.SSS"},mt.format=function(t,e,i){var n=i||mt.i18n;if("number"==typeof t&&(t=new Date(t)),"[object Date]"!==Object.prototype.toString.call(t)||isNaN(t.getTime()))throw new Error("Invalid Date in fecha.format");e=mt.masks[e]||e||mt.masks.default;var s=[];return(e=(e=e.replace(_t,(function(t,e){return s.push(e),"@@@"}))).replace(ft,(function(e){return e in kt?kt[e](t,n):e.slice(1,e.length-1)}))).replace(/@@@/g,(function(){return s.shift()}))},mt.parse=function(t,e,i){var n=i||mt.i18n;if("string"!=typeof e)throw new Error("Invalid format in fecha.parse");if(e=mt.masks[e]||e,t.length>1e3)return null;var s={},o=[],r=[];e=e.replace(_t,(function(t,e){return r.push(e),"@@@"}));var a,c=(a=e,a.replace(/[|\\{()[^$+*?.-]/g,"\\$&")).replace(ft,(function(t){if(Nt[t]){var e=Nt[t];return o.push(e[1]),"("+e[0]+")"}return t}));c=c.replace(/@@@/g,(function(){return r.shift()}));var l=t.match(new RegExp(c,"i"));if(!l)return null;for(var d=1;d=":return n>=i;case">":return n>i;case"!=":return n!==i;case"regex":return n.match(i);default:return!1}};const Dt="ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0;class Rt extends HTMLElement{constructor(){super(),this.holdTime=500,this.ripple=document.createElement("mwc-ripple"),this.timer=void 0,this.held=!1,this.cooldownStart=!1,this.cooldownEnd=!1}connectedCallback(){Object.assign(this.style,{position:"absolute",width:Dt?"100px":"50px",height:Dt?"100px":"50px",transform:"translate(-50%, -50%)",pointerEvents:"none"}),this.appendChild(this.ripple),this.ripple.primary=!0,["touchcancel","mouseout","mouseup","touchmove","mousewheel","wheel","scroll"].forEach(t=>{document.addEventListener(t,()=>{clearTimeout(this.timer),this.stopAnimation(),this.timer=void 0},{passive:!0})})}bind(t,e){if(t.actionHandler)return;t.actionHandler=!0,t.addEventListener("contextmenu",t=>{const e=t||window.event;return e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),e.cancelBubble=!0,e.returnValue=!1,!1});const i=t=>{if(this.cooldownStart)return;let i,n;this.held=!1,t.touches?(i=t.touches[0].pageX,n=t.touches[0].pageY):(i=t.pageX,n=t.pageY),e.hasHold&&(this.timer=window.setTimeout(()=>{this.startAnimation(i,n),this.held=!0},this.holdTime)),this.cooldownStart=!0,window.setTimeout(()=>this.cooldownStart=!1,100)},n=i=>{this.cooldownEnd||["touchend","touchcancel"].includes(i.type)&&void 0===this.timer||(clearTimeout(this.timer),this.stopAnimation(),this.timer=void 0,this.held?Et(t,"action",{action:"hold"}):e.hasDoubleTap?1===i.detail?this.dblClickTimeout=window.setTimeout(()=>{Et(t,"action",{action:"tap"})},250):(clearTimeout(this.dblClickTimeout),Et(t,"action",{action:"double_tap"})):Et(t,"action",{action:"tap"}),this.cooldownEnd=!0,window.setTimeout(()=>this.cooldownEnd=!1,100))};t.addEventListener("touchstart",i,{passive:!0}),t.addEventListener("touchend",n),t.addEventListener("touchcancel",n),window.navigator.userAgent.match(/iPhone OS 13_/)||(t.addEventListener("mousedown",i,{passive:!0}),t.addEventListener("click",n))}startAnimation(t,e){Object.assign(this.style,{left:`${t}px`,top:`${e}px`,display:null}),this.ripple.disabled=!1,this.ripple.active=!0,this.ripple.unbounded=!0}stopAnimation(){this.ripple.active=!1,this.ripple.disabled=!0,this.style.display="none"}}customElements.define("action-handler-restriction",Rt);const Vt=(t,e)=>{const i=(()=>{const t=document.body;if(t.querySelector("action-handler-restriction"))return t.querySelector("action-handler-restriction");const e=document.createElement("action-handler-restriction");return t.appendChild(e),e})();i&&i.bind(t,e)},Ot=i((t={})=>e=>{Vt(e.committer.element,t)});console.info("%c RESTRICTION-CARD \n%c Version 1.1.2 ","color: orange; font-weight: bold; background: black","color: white; font-weight: bold; background: dimgray");let Yt=class extends ht{set hass(t){this._hass=t;const e=this.shadowRoot.querySelector("#card > *");e&&(e.hass=t)}getCardSize(){const t=this.shadowRoot.querySelector("#card > *");return t&&"function"==typeof(e=t).getCardSize?e.getCardSize():1;var e}setConfig(t){if(!t.card)throw new Error("Error in card configuration.");if(t.restrictions&&t.restrictions.pin&&!t.restrictions.pin.code)throw new Error("A pin code is required for pin restrictions");this._config=Object.assign({duration:5,action:"tap"},t)}shouldUpdate(t){const e=t.get("hass");return!(!t.has("config")&&e)||!!(this._config&&this._config.condition&&this._config.condition.entity)&&e.states[this._config.condition.entity]!==this._hass.states[this._config.condition.entity]}render(){return this._config&&this._hass?this._config.restrictions&&this._matchRestriction(this._config.restrictions.hide)?O``:O`
${this._config.exemptions&&this._config.exemptions.some(t=>t.user===this._hass.user.id)||this._config.condition&&!At(this._hass.states[this._config.condition.entity],this._config.condition)?"":O`
@@ -217,11 +215,11 @@ const ut=new WeakMap,pt=i(t=>e=>{if(!(e instanceof x)||e instanceof E||"class"!= `} ${this.renderCard(this._config.card)}
- `:O``}renderCard(t){const e=Mt(t,this._config.row);return this._hass&&(e.hass=this._hass),O` + `:O``}renderCard(t){const e=function(t,e){void 0===e&&(e=!1);var i=function(t,e){return n("hui-error-card",{type:"error",error:t,config:e})},n=function(t,e){var n=window.document.createElement(t);try{n.setConfig(e)}catch(n){return console.error(t,n),i(n.message,e)}return n};if(!t||"object"!=typeof t||!e&&!t.type)return i("No type defined",t);var s=t.type;if(s&&s.startsWith("custom:"))s=s.substr("custom:".length);else if(e)if(Tt.has(s))s="hui-"+s+"-row";else{if(!t.entity)return i("Invalid config given.",t);var o=t.entity.split(".",1)[0];s="hui-"+(Mt[o]||"text")+"-entity-row"}else s="hui-"+s+"-card";if(customElements.get(s))return n(s,t);var r=i("Custom element doesn't exist: "+t.type+".",t);r.style.display="None";var a=setTimeout((function(){r.style.display=""}),2e3);return customElements.whenDefined(t.type).then((function(){clearTimeout(a),Et(r,"ll-rebuild",{},r)})),r}(t,this._config.row);return this._hass&&(e.hass=this._hass),O`
${e}
- `}_matchRestriction(t){return t&&(!t.exemptions||!t.exemptions.some(t=>t.user===this._hass.user.id))&&(!t.condition||At(this._hass.states[t.condition.entity],t.condition))}_handleClick(){"tap"===this._config.action&&this._handleRestriction()}_handleDblClick(){"double_tap"===this._config.action&&this._handleRestriction()}_handleHold(){"hold"===this._config.action&&this._handleRestriction()}_handleRestriction(){const t=this.shadowRoot.getElementById("lock");if(this._config.restrictions){if(this._matchRestriction(this._config.restrictions.block))return this._config.restrictions.block.text&&alert(this._config.restrictions.block.text),t.classList.add("invalid"),void window.setTimeout(()=>{t&&t.classList.remove("invalid")},3e3);if(this._matchRestriction(this._config.restrictions.pin)){if(prompt(this._config.restrictions.pin.text||"Input pin code")!=this._config.restrictions.pin.code)return t.classList.add("invalid"),void window.setTimeout(()=>{t&&t.classList.remove("invalid")},3e3)}if(this._matchRestriction(this._config.restrictions.confirm)&&!confirm(this._config.restrictions.confirm.text||"Are you sure you want to unlock?"))return}const e=this.shadowRoot.getElementById("overlay");e.style.setProperty("pointer-events","none"),t.classList.add("hidden"),window.setTimeout(()=>{e.style.setProperty("pointer-events",""),t&&t.classList.remove("hidden")},1e3*this._config.duration)}static get styles(){return lt` + `}_matchRestriction(t){return t&&(!t.exemptions||!t.exemptions.some(t=>t.user===this._hass.user.id))&&(!t.condition||At(this._hass.states[t.condition.entity],t.condition))}_handleAction(t){this._config.action===t.detail.action&&this._handleRestriction()}_handleRestriction(){const t=this.shadowRoot.getElementById("lock");if(this._config.restrictions){if(this._matchRestriction(this._config.restrictions.block))return this._config.restrictions.block.text&&alert(this._config.restrictions.block.text),t.classList.add("invalid"),void window.setTimeout(()=>{t&&t.classList.remove("invalid")},3e3);if(this._matchRestriction(this._config.restrictions.pin)){if(prompt(this._config.restrictions.pin.text||"Input pin code")!=this._config.restrictions.pin.code)return t.classList.add("invalid"),void window.setTimeout(()=>{t&&t.classList.remove("invalid")},3e3)}if(this._matchRestriction(this._config.restrictions.confirm)&&!confirm(this._config.restrictions.confirm.text||"Are you sure you want to unlock?"))return}const e=this.shadowRoot.getElementById("overlay");e.style.setProperty("pointer-events","none"),t.classList.add("hidden"),window.setTimeout(()=>{e.style.setProperty("pointer-events",""),t&&t.classList.remove("hidden")},1e3*this._config.duration)}static get styles(){return lt` :host { display: block; position: relative; @@ -243,8 +241,14 @@ const ut=new WeakMap,pt=i(t=>e=>{if(!(e instanceof x)||e instanceof E||"class"!= ); --lock-margin-left: var(--restriction-lock-margin-left, 0px); --lock-row-margin-left: var(--restriction-lock-row-margin-left, 24px); - --lock-icon-height: var(--restriction-lock-icon-height, var(--iron-icon-height, 24px)); - --lock-icon-width: var(--restriction-lock-icon-width, var(--iron-icon-width, 24px)); + --lock-icon-height: var( + --restriction-lock-icon-height, + var(--iron-icon-height, 24px) + ); + --lock-icon-width: var( + --restriction-lock-icon-width, + var(--iron-icon-width, 24px) + ); } ha-icon { --iron-icon-height: var(--lock-icon-height); diff --git a/hacs.json b/hacs.json new file mode 100644 index 0000000..4c50cf1 --- /dev/null +++ b/hacs.json @@ -0,0 +1,4 @@ +{ + "name": "Restriction Card", + "render_readme": true +} \ No newline at end of file diff --git a/package.json b/package.json index 4498cff..a395ec9 100644 --- a/package.json +++ b/package.json @@ -1,46 +1,46 @@ { - "name": "restriction-card", - "version": "1.0.0", - "description": "Lovelace restriction-card", - "keywords": [ - "home-assistant", - "homeassistant", - "hass", - "automation", - "lovelace", - "custom-cards" - ], - "module": "restriction-card.js", - "repository": "git@github.com:custom_cards/restriction-card.git", - "author": "BoilerPlate ", - "license": "MIT", - "dependencies": { - "custom-card-helpers": "^1.3.0", - "home-assistant-js-websocket": "^4.3.1", - "lit-element": "^2.2.1" - }, - "devDependencies": { - "@babel/core": "^7.5.5", - "@babel/plugin-proposal-class-properties": "^7.5.5", - "@babel/plugin-proposal-decorators": "^7.4.0", - "@typescript-eslint/eslint-plugin": "^2.0.0", - "@typescript-eslint/parser": "^2.0.0", - "eslint": "^6.2.2", - "eslint-config-airbnb-base": "^14.0.0", - "eslint-plugin-import": "^2.18.2", - "prettier": "^1.18.2", - "rollup": "^1.20.2", - "rollup-plugin-babel": "^4.3.3", - "rollup-plugin-node-resolve": "^5.2.0", - "rollup-plugin-terser": "^5.1.1", - "rollup-plugin-typescript2": "^0.23.0", - "rollup-plugin-uglify": "^6.0.2", - "typescript": "^3.5.3" - }, - "scripts": { - "start": "rollup -c --watch", - "build": "npm run lint && npm run rollup", - "lint": "eslint src/*.ts", - "rollup": "rollup -c" - } + "name": "restriction-card", + "version": "1.0.0", + "description": "Lovelace restriction-card", + "keywords": [ + "home-assistant", + "homeassistant", + "hass", + "automation", + "lovelace", + "custom-cards" + ], + "module": "restriction-card.js", + "repository": "git@github.com:custom_cards/restriction-card.git", + "author": "BoilerPlate ", + "license": "MIT", + "dependencies": { + "custom-card-helpers": "^1.3.5", + "home-assistant-js-websocket": "^4.4.0", + "lit-element": "^2.2.1" + }, + "devDependencies": { + "@babel/core": "^7.6.4", + "@babel/plugin-proposal-class-properties": "^7.5.5", + "@babel/plugin-proposal-decorators": "^7.4.0", + "@typescript-eslint/eslint-plugin": "^2.6.0", + "@typescript-eslint/parser": "^2.6.0", + "eslint": "^6.6.0", + "eslint-config-airbnb-base": "^14.0.0", + "eslint-plugin-import": "^2.18.2", + "prettier": "^1.18.2", + "rollup": "^1.26.0", + "rollup-plugin-babel": "^4.3.3", + "rollup-plugin-node-resolve": "^5.2.0", + "rollup-plugin-terser": "^5.1.2", + "rollup-plugin-typescript2": "^0.24.3", + "rollup-plugin-uglify": "^6.0.3", + "typescript": "^3.6.4" + }, + "scripts": { + "start": "rollup -c --watch", + "build": "npm run lint && npm run rollup", + "lint": "eslint src/*.ts", + "rollup": "rollup -c" + } } diff --git a/src/long-press-directive.ts b/src/action-handler-directive.ts similarity index 70% rename from src/long-press-directive.ts rename to src/action-handler-directive.ts index 3cc143d..da19788 100644 --- a/src/long-press-directive.ts +++ b/src/action-handler-directive.ts @@ -1,20 +1,20 @@ import { directive, PropertyPart } from "lit-html"; -import { LongPressOptions } from "./types"; +import { fireEvent, ActionHandlerOptions } from "custom-card-helpers"; const isTouch = "ontouchstart" in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0; -interface LongPress extends HTMLElement { +interface ActionHandler extends HTMLElement { holdTime: number; bind(element: Element, options): void; } -interface LongPressElement extends Element { - longPress?: boolean; +interface ActionHandlerElement extends Element { + actionHandler?: boolean; } -class LongPress extends HTMLElement implements LongPress { +class ActionHandler extends HTMLElement implements ActionHandler { public holdTime: number; public ripple: any; protected timer: number | undefined; @@ -66,11 +66,11 @@ class LongPress extends HTMLElement implements LongPress { }); } - public bind(element: LongPressElement, options) { - if (element.longPress) { + public bind(element: ActionHandlerElement, options) { + if (element.actionHandler) { return; } - element.longPress = true; + element.actionHandler = true; element.addEventListener("contextmenu", (ev: Event) => { const e = ev || window.event; @@ -99,10 +99,13 @@ class LongPress extends HTMLElement implements LongPress { x = (ev as MouseEvent).pageX; y = (ev as MouseEvent).pageY; } - this.timer = window.setTimeout(() => { - this.startAnimation(x, y); - this.held = true; - }, this.holdTime); + + if (options.hasHold) { + this.timer = window.setTimeout(() => { + this.startAnimation(x, y); + this.held = true; + }, this.holdTime); + } this.cooldownStart = true; window.setTimeout(() => (this.cooldownStart = false), 100); @@ -120,18 +123,18 @@ class LongPress extends HTMLElement implements LongPress { this.stopAnimation(); this.timer = undefined; if (this.held) { - element.dispatchEvent(new Event("ha-hold")); - } else if (options.hasDoubleClick) { + fireEvent(element as HTMLElement, "action", { action: "hold" }); + } else if (options.hasDoubleTap) { if ((ev as MouseEvent).detail === 1) { this.dblClickTimeout = window.setTimeout(() => { - element.dispatchEvent(new Event("ha-click")); + fireEvent(element as HTMLElement, "action", { action: "tap" }); }, 250); } else { clearTimeout(this.dblClickTimeout); - element.dispatchEvent(new Event("ha-dblclick")); + fireEvent(element as HTMLElement, "action", { action: "double_tap" }); } } else { - element.dispatchEvent(new Event("ha-click")); + fireEvent(element as HTMLElement, "action", { action: "tap" }); } this.cooldownEnd = true; window.setTimeout(() => (this.cooldownEnd = false), 100); @@ -142,7 +145,7 @@ class LongPress extends HTMLElement implements LongPress { element.addEventListener("touchcancel", clickEnd); // iOS 13 sends a complete normal touchstart-touchend series of events followed by a mousedown-click series. - // That might be a bug, but until it's fixed, this should make long-press work. + // That might be a bug, but until it's fixed, this should make action-handler work. // If it's not a bug that is fixed, this might need updating with the next iOS version. // Note that all events (both touch and mouse) must be listened for in order to work on computers with both mouse and touchscreen. const isIOS13 = window.navigator.userAgent.match(/iPhone OS 13_/); @@ -170,33 +173,33 @@ class LongPress extends HTMLElement implements LongPress { } } -customElements.define("long-press-restriction", LongPress); +customElements.define("action-handler-restriction", ActionHandler); -const getLongPress = (): LongPress => { +const geActionHandler = (): ActionHandler => { const body = document.body; - if (body.querySelector("long-press-restriction")) { - return body.querySelector("long-press-restriction") as LongPress; + if (body.querySelector("action-handler-restriction")) { + return body.querySelector("action-handler-restriction") as ActionHandler; } - const longpress = document.createElement("long-press-restriction"); - body.appendChild(longpress); + const actionhandler = document.createElement("action-handler-restriction"); + body.appendChild(actionhandler); - return longpress as LongPress; + return actionhandler as ActionHandler; }; -export const longPressBind = ( - element: LongPressElement, - options: LongPressOptions +export const actionHandlerBind = ( + element: ActionHandlerElement, + options: ActionHandlerOptions ) => { - const longpress: LongPress = getLongPress(); - if (!longpress) { + const actionhandler: ActionHandler = geActionHandler(); + if (!actionhandler) { return; } - longpress.bind(element, options); + actionhandler.bind(element, options); }; -export const longPress = directive( - (options: LongPressOptions = {}) => (part: PropertyPart) => { - longPressBind(part.committer.element, options); +export const actionHandler = directive( + (options: ActionHandlerOptions = {}) => (part: PropertyPart) => { + actionHandlerBind(part.committer.element, options); } -); +); \ No newline at end of file diff --git a/src/const.ts b/src/const.ts index 1be3746..866f8ba 100644 --- a/src/const.ts +++ b/src/const.ts @@ -1 +1 @@ -export const CARD_VERSION = '1.1.1'; \ No newline at end of file +export const CARD_VERSION = '1.1.2'; \ No newline at end of file diff --git a/src/restriction-card.ts b/src/restriction-card.ts index bcaaf74..3c41317 100644 --- a/src/restriction-card.ts +++ b/src/restriction-card.ts @@ -19,14 +19,14 @@ import { LovelaceCardConfig, evaluateFilter } from "custom-card-helpers"; -import { longPress } from "./long-press-directive"; import { CARD_VERSION } from "./const"; +import { actionHandler } from "./action-handler-directive"; /* eslint no-console: 0 */ console.info( `%c RESTRICTION-CARD \n%c Version ${CARD_VERSION} `, - 'color: orange; font-weight: bold; background: black', - 'color: white; font-weight: bold; background: dimgray', + "color: orange; font-weight: bold; background: black", + "color: white; font-weight: bold; background: dimgray" ); @customElement("restriction-card") @@ -113,11 +113,10 @@ class RestrictionCard extends LitElement implements LovelaceCard { ? "" : html`