diff --git a/dist/deep-press.js b/dist/deep-press.js index 813e0a6..80798cd 100644 --- a/dist/deep-press.js +++ b/dist/deep-press.js @@ -1 +1 @@ -!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=2)}([function(e,t,n){"use strict";function r(){return document.querySelector("hc-main")?document.querySelector("hc-main").hass:document.querySelector("home-assistant")?document.querySelector("home-assistant").hass:void 0}function o(e){return document.querySelector("hc-main")?document.querySelector("hc-main").provideHass(e):document.querySelector("home-assistant")?document.querySelector("home-assistant").provideHass(e):void 0}function s(){var e,t=document.querySelector("hc-main");return t?((e=t._lovelaceConfig).current_view=t._lovelacePath,e):(t=(t=(t=(t=(t=(t=(t=(t=(t=document.querySelector("home-assistant"))&&t.shadowRoot)&&t.querySelector("home-assistant-main"))&&t.shadowRoot)&&t.querySelector("app-drawer-layout partial-panel-resolver"))&&t.shadowRoot||t)&&t.querySelector("ha-panel-lovelace"))&&t.shadowRoot)&&t.querySelector("hui-root"))?((e=t.lovelace).current_view=t.___curView,e):null}async function i(e){e&&(await customElements.whenDefined(e.localName),e.updateComplete&&await e.updateComplete)}async function a(){var e=document.querySelector("hc-main");return e?(i(e=(e=e&&e.shadowRoot)&&e.querySelector("hc-lovelace")),i(e=(e=e&&e.shadowRoot)&&e.querySelector("hui-view")||e.querySelector("hui-panel-view")),e):(i(e=document.querySelector("home-assistant")),i(e=(e=e&&e.shadowRoot)&&e.querySelector("home-assistant-main")),i(e=(e=e&&e.shadowRoot)&&e.querySelector("app-drawer-layout partial-panel-resolver")),i(e=(e=e&&e.shadowRoot||e)&&e.querySelector("ha-panel-lovelace")),i(e=(e=e&&e.shadowRoot)&&e.querySelector("hui-root")),i(e=(e=e&&e.shadowRoot)&&e.querySelector("ha-app-layout")),i(e=(e=e&&e.querySelector("#view"))&&e.firstElementChild),e)}function u(){var e=document.querySelector("hc-main");return e=e?(e=(e=(e=e&&e.shadowRoot)&&e.querySelector("hc-lovelace"))&&e.shadowRoot)&&e.querySelector("hui-view")||e.querySelector("hui-panel-view"):(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=document.querySelector("home-assistant"))&&e.shadowRoot)&&e.querySelector("home-assistant-main"))&&e.shadowRoot)&&e.querySelector("app-drawer-layout partial-panel-resolver"))&&e.shadowRoot||e)&&e.querySelector("ha-panel-lovelace"))&&e.shadowRoot)&&e.querySelector("hui-root"))&&e.shadowRoot)&&e.querySelector("ha-app-layout"))&&e.querySelector("#view"))&&e.firstElementChild}async function c(){if(customElements.get("hui-view"))return!0;await customElements.whenDefined("partial-panel-resolver");const e=document.createElement("partial-panel-resolver");if(e.hass={panels:[{url_path:"tmp",component_name:"lovelace"}]},e._updateRoutes(),await e.routerOptions.routes.tmp.load(),!customElements.get("ha-panel-lovelace"))return!1;const t=document.createElement("ha-panel-lovelace");return t.hass=r(),void 0===t.hass&&(await new Promise(e=>{window.addEventListener("connection-status",t=>{console.log(t),e()},{once:!0})}),t.hass=r()),t.panel={config:{mode:null}},t._fetchConfig(),!0}n.r(t),n.d(t,"hass",function(){return r}),n.d(t,"provideHass",function(){return o}),n.d(t,"lovelace",function(){return s}),n.d(t,"async_lovelace_view",function(){return a}),n.d(t,"lovelace_view",function(){return u}),n.d(t,"load_lovelace",function(){return c})},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.scaleElement=t.setIntervalNTimes=t.removeBlur=t.getView=t.setModalBehaviour=void 0;const r=function(e,t){var n=document.querySelector("body > home-assistant").shadowRoot.querySelector("ha-more-info-dialog");n?e?(n.noCancelOnOutsideClick=!1,n.style.pointerEvents="all"):(n.noCancelOnOutsideClick=!0,n.style.pointerEvents="none"):t&&setTimeout(function(){r(e,!1)},100)};t.setModalBehaviour=r;const o=function(){return document.querySelector("body > home-assistant").shadowRoot.querySelector("home-assistant-main").shadowRoot.querySelector("app-drawer-layout > partial-panel-resolver > ha-panel-lovelace").shadowRoot.querySelector("hui-root").shadowRoot.querySelector("#view > hui-view")?document.querySelector("body > home-assistant").shadowRoot.querySelector("home-assistant-main").shadowRoot.querySelector("app-drawer-layout > partial-panel-resolver > ha-panel-lovelace").shadowRoot.querySelector("hui-root").shadowRoot.querySelector("#view > hui-view"):document.querySelector("body > home-assistant").shadowRoot.querySelector("home-assistant-main").shadowRoot.querySelector("app-drawer-layout > partial-panel-resolver > ha-panel-lovelace").shadowRoot.querySelector("hui-root").shadowRoot.querySelector("#view > hui-panel-view")};t.getView=o;t.removeBlur=function(){try{o().style.webkitFilter="blur(0px)"}catch(e){if(!(e instanceof TypeError))throw e}};const s=(e,t,n)=>{n&&setTimeout(()=>{e(),s(e,t,n-1)},t)};t.setIntervalNTimes=s;t.scaleElement=function(e,t,n){e.animations&&(t.style.transform="scale("+n+")")}},function(e,t,n){"use strict";var r,o=n(1),s=n(0),i=n(3),a=(r=n(4))&&r.__esModule?r:{default:r};const u=()=>{(0,s.lovelace)()?c():setTimeout(u,250)},c=()=>{customElements.whenDefined("card-tools").then(()=>{customElements.whenDefined("ha-card").then(()=>{const e=customElements.get("ha-card");var t=Object.assign({},{enable_unsupported:!1,animations:!0},(0,s.lovelace)().config.deep_press);if("ontouchforcechange"in document==!1&&0==t.enable_unsupported)return;["touchend","mouseup"].forEach(e=>{document.addEventListener(e,()=>{(0,o.removeBlur)(),setTimeout(function(){(0,o.setModalBehaviour)(!0,!1)},100)})});const n=function(e){return e.config?e.config:e._config?e._config:e.host?n(e.host):e.parentElement?n(e.parentElement):e.parentNode?n(e.parentNode):null};var r=e.prototype.firstUpdated;e.prototype.firstUpdated=function(e){r.apply(this,e);const o=n(this);o&&o.deep_press&&o.hold_action&&function(e,t){if(!this.querySelector(":scope >#deep-press-cover")){var n=document.createElement("div");n.setAttribute("id","deep-press-cover"),n.setAttribute("style","position: absolute; top:0; left:0; width:100%; height: 100%; overflow: visible;"),this.appendChild(n),new a.default(n,this,e,t).init()}}.call(this,t,o)},(0,i.fireEvent)("ll-rebuild",{})})})};u(),console.info("%cdeep-press\n%cVersion: 2.1.1","color: green; font-weight: bold;","")},function(e,t,n){"use strict";n.r(t),n.d(t,"fireEvent",function(){return o});var r=n(0);function o(e,t,n=null){if((e=new Event(e,{bubbles:!0,cancelable:!1,composed:!0})).detail=t||{},n)n.dispatchEvent(e);else{var o=Object(r.lovelace_view)();o&&o.dispatchEvent(e)}}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var r,o=n(1),s=n(6),i=(r=n(5))&&r.__esModule?r:{default:r};t.default=class{constructor(e,t,n,r){this.cover=e,this.root=t,this.deep_press_config=n,this.config=r,this.cover.deep_press_config=n,this.cover.config=r,this._upEvent=this.upEvent.bind(this)}downEvent(e){["touchend","mouseup"].forEach(function(e){this.cover.addEventListener(e,this._upEvent,{passive:!0})},this),this.down_event=e,e.stopPropagation();try{this.root.parentElement.dispatchEvent(new e.constructor(e.type,e))}catch(t){this.root.getRootNode().host.dispatchEvent(new e.constructor(e.type,e))}}upEvent(e){if((0,o.scaleElement)(this.deep_press_config,this.root,1),this.cover.removeEventListener(e.type,this._upEvent,{passive:!0}),this.cover.cancel||this.cover.hold){e.stopPropagation();try{this.root.parentElement.dispatchEvent(new e.constructor(e.type,e))}catch(t){this.root.getRootNode().host.dispatchEvent(new e.constructor(e.type,e))}}else"click"!=e.type&&this.root.dispatchEvent(new e.constructor(this.down_event.type,this.down_event)),this.root.dispatchEvent(new e.constructor(e.type,e)),(0,o.removeBlur)()}cancelEvent(e){this.cover.cancel=!0,(0,o.scaleElement)(this.deep_press_config,this.root,1),(0,o.removeBlur)()}init(){["touchstart","mousedown"].forEach(function(e){this.cover.addEventListener(e,this.downEvent.bind(this),{passive:!0})},this),["touchcancel","mouseout","touchmove","mousewheel","wheel","scroll"].forEach(function(e){this.cover.addEventListener(e,this.cancelEvent.bind(this),{passive:!0})},this),i.default.set(this.cover,{start:function(e){this.cancel=!1,this.event_over=!1,this.hold=!1,this.deep_press=!1,this.view=(0,o.getView)()},change:function(e,t){this.cancel||this.deep_press||e>.2&&(this.view.style.webkitFilter="blur("+i.default.map(e,.2,.5,0,10)+"px)",(0,o.scaleElement)(this.deep_press_config,this.parentElement,i.default.map(e,.2,.5,1,.5)),this.hold=!0)},startDeepPress:function(e){this.cancel||this.deep_press||(this.deep_press=!0,(0,o.scaleElement)(this.deep_press_config,this.parentElement,1),(0,s.handleClick)(this.parentElement,cardTools.hass,this.config,!0,!1),(0,o.setModalBehaviour)(!1,!0),(0,o.removeBlur)())},end:function(){(0,o.scaleElement)(this.deep_press_config,this.parentElement,1),(0,o.removeBlur)()}})}}},function(e,t,n){var r,o,s;o=[],void 0===(s="function"==typeof(r=function(){"use strict";function e(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function t(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o=function(){function e(e,t){for(var n=0;n=.5?this._startDeepPress(t):this._endDeepPress()}},{key:"runPolyfill",value:function(e){this.increment=0===h.get("polyfillSpeedUp",this.options)?1:10/h.get("polyfillSpeedUp",this.options),this.decrement=0===h.get("polyfillSpeedDown",this.options)?1:10/h.get("polyfillSpeedDown",this.options),this.setPressed(!0),this.runClosure("start",e),!1===this.runningPolyfill&&this.loopPolyfillForce(0,e)}},{key:"loopPolyfillForce",value:function(e,t){!1===this.nativeSupport&&(this.isPressed()?(this.runningPolyfill=!0,e=e+this.increment>1?1:e+this.increment,this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10)):((e=e-this.decrement<0?0:e-this.decrement)<.5&&this.isDeepPressed()&&(this.setDeepPressed(!1),this.runClosure("endDeepPress")),0===e?(this.runningPolyfill=!1,this.setPressed(!0),this._endPress()):(this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10))))}}]),e}(),u=function(r){function s(t,r,o){return n(this,s),e(this,(s.__proto__||Object.getPrototypeOf(s)).call(this,t,r,o))}return t(s,r),o(s,[{key:"bindEvents",value:function(){this.add("webkitmouseforcewillbegin",this._startPress.bind(this)),this.add("mousedown",this.support.bind(this)),this.add("webkitmouseforcechanged",this.change.bind(this)),this.add("webkitmouseforcedown",this._startDeepPress.bind(this)),this.add("webkitmouseforceup",this._endDeepPress.bind(this)),this.add("mouseleave",this._endPress.bind(this)),this.add("mouseup",this._endPress.bind(this))}},{key:"support",value:function(e){!1===this.isPressed()&&this.fail(e,this.runKey)}},{key:"change",value:function(e){this.isPressed()&&e.webkitForce>0&&this._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(p(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),s}(a),c=function(r){function s(t,r,o){return n(this,s),e(this,(s.__proto__||Object.getPrototypeOf(s)).call(this,t,r,o))}return t(s,r),o(s,[{key:"bindEvents",value:function(){w?(this.add("touchforcechange",this.start.bind(this)),this.add("touchstart",this.support.bind(this,0)),this.add("touchend",this._endPress.bind(this))):(this.add("touchstart",this.startLegacy.bind(this)),this.add("touchend",this._endPress.bind(this)))}},{key:"start",value:function(e){e.touches.length>0&&(this._startPress(e),this.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"support",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;!1===this.isPressed()&&(e<=6?(e++,setTimeout(this.support.bind(this,e,t,n),10)):this.fail(t,n))}},{key:"startLegacy",value:function(e){this.initialForce=e.touches[0].force,this.supportLegacy(0,e,this.runKey,this.initialForce)}},{key:"supportLegacy",value:function(e,t,n,r){r!==this.initialForce?(this._startPress(t),this.loopForce(t)):e<=6?(e++,setTimeout(this.supportLegacy.bind(this,e,t,n,r),10)):this.fail(t,n)}},{key:"loopForce",value:function(e){this.isPressed()&&(this.touch=this.selectTouch(e),setTimeout(this.loopForce.bind(this,e),10),this._changePress(this.touch.force,e))}},{key:"selectTouch",value:function(e){if(1===e.touches.length)return this.returnTouch(e.touches[0],e);for(var t=0;t1?this.fail(e,this.runKey):(this._startPress(e),this._changePress(e.pressure,e)))}},{key:"change",value:function(e){this.isPressed()&&e.pressure>0&&.5!==e.pressure&&(this._changePress(e.pressure,e),this.deepPress(e.pressure,e))}}]),s}(a),h={polyfill:!0,polyfillSpeedUp:1e3,polyfillSpeedDown:0,preventSelect:!0,only:null,get:function(e,t){return t.hasOwnProperty(e)?t[e]:this[e]},set:function(e){for(var t in e)e.hasOwnProperty(t)&&this.hasOwnProperty(t)&&"get"!=t&&"set"!=t&&(this[t]=e[t])}},d=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var r=document.querySelectorAll(e),o=0;o-1?r:null}};function u(e){for(var t=[],n=1;n3?0:(e-e%10!=10?1:0)*e%10]}},f=u({},d),p=function(e){return e.replace(/[|\\{()[^$+*?.-]/g,"\\$&")},m=function(e,t){for(void 0===t&&(t=2),e=String(e);e.length0?"-":"+")+m(100*Math.floor(Math.abs(t)/60)+Math.abs(t)%60,4)},Z:function(e){var t=e.getTimezoneOffset();return(t>0?"-":"+")+m(Math.floor(Math.abs(t)/60),2)+":"+m(Math.abs(t)%60,2)}},y=function(e){return+e-1},g=[null,"[1-9]\\d?"],w=[null,o],b=["isPm",o,function(e,t){var n=e.toLowerCase();return n===t.amPm[0]?0:n===t.amPm[1]?1:null}],_=["timezoneOffset","[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z?",function(e){var t=(e+"").match(/([+-]|\d\d)/gi);if(t){var n=60*+t[1]+parseInt(t[2],10);return"+"===t[0]?n:-n}return 0}],S={D:["day","[1-9]\\d?"],DD:["day","\\d\\d"],Do:["day","[1-9]\\d?"+o,function(e){return parseInt(e,10)}],M:["month","[1-9]\\d?",y],MM:["month","\\d\\d",y],YY:["year","\\d\\d",function(e){var t=+(""+(new Date).getFullYear()).substr(0,2);return+(""+(+e>68?t-1:t)+e)}],h:["hour","[1-9]\\d?",void 0,"isPm"],hh:["hour","\\d\\d",void 0,"isPm"],H:["hour","[1-9]\\d?"],HH:["hour","\\d\\d"],m:["minute","[1-9]\\d?"],mm:["minute","\\d\\d"],s:["second","[1-9]\\d?"],ss:["second","\\d\\d"],YYYY:["year","\\d{4}"],S:["millisecond","\\d",function(e){return 100*+e}],SS:["millisecond","\\d\\d",function(e){return 10*+e}],SSS:["millisecond","\\d{3}"],d:g,dd:g,ddd:w,dddd:w,MMM:["month",o,a("monthNamesShort")],MMMM:["month",o,a("monthNames")],a:b,A:b,ZZ:_,Z:_},k={default:"ddd MMM DD YYYY HH:mm:ss",shortDate:"M/D/YY",mediumDate:"MMM D, YYYY",longDate:"MMMM D, YYYY",fullDate:"dddd, MMMM D, YYYY",isoDate:"YYYY-MM-DD",isoDateTime:"YYYY-MM-DDTHH:mm:ssZ",shortTime:"HH:mm",mediumTime:"HH:mm:ss",longTime:"HH:mm:ss.SSS"};var E={format:function(e,t,n){if(void 0===t&&(t=k.default),void 0===n&&(n={}),"number"==typeof e&&(e=new Date(e)),"[object Date]"!==Object.prototype.toString.call(e)||isNaN(e.getTime()))throw new Error("Invalid Date pass to format");t=k[t]||t;var o=[];t=t.replace(s,function(e,t){return o.push(t),"@@@"});var i=u(u({},f),n);return(t=t.replace(r,function(t){return v[t](e,i)})).replace(/@@@/g,function(){return o.shift()})},parse:function(e,t,n){if(void 0===n&&(n={}),"string"!=typeof t)throw new Error("Invalid format in fecha parse");if(t=k[t]||t,e.length>1e3)return null;var o={year:(new Date).getFullYear(),month:0,day:1,hour:0,minute:0,second:0,millisecond:0,isPm:null,timezoneOffset:null},i=[],a=[],c=t.replace(s,function(e,t){return a.push(p(t)),"@@@"}),l={},h={};c=p(c).replace(r,function(e){var t=S[e],n=t[0],r=t[1],o=t[3];if(l[n])throw new Error("Invalid format. "+n+" specified twice in format");return l[n]=!0,o&&(h[o]=!0),i.push(t),"("+r+")"}),Object.keys(h).forEach(function(e){if(!l[e])throw new Error("Invalid format. "+e+" is required in specified format")}),c=c.replace(/@@@/g,function(){return a.shift()});var d=e.match(new RegExp(c,"i"));if(!d)return null;for(var m=u(u({},f),n),v=1;v=0?"past":"future";o=Math.abs(o);for(var i=0;i0?t+":"+Y(n)+":"+Y(r):n>0?n+":"+Y(r):r>0?""+r:null}function N(e){var t=P(e.attributes.remaining);if("active"===e.state){var n=(new Date).getTime(),r=new Date(e.last_changed).getTime();t=Math.max(t-(n-r)/1e3,0)}return t}var x=function(e,t,n,r){void 0===r&&(r=!1),e._themes||(e._themes={});var o=t.default_theme;("default"===n||n&&t.themes[n])&&(o=n);var s=Object.assign({},e._themes);if("default"!==o){var i=t.themes[o];Object.keys(i).forEach(function(t){var n="--"+t;e._themes[n]="",s[n]=i[t]})}if(e.updateStyles?e.updateStyles(s):window.ShadyCSS&&window.ShadyCSS.styleSubtree(e,s),r){var a=document.querySelector("meta[name=theme-color]");if(a){a.hasAttribute("default-content")||a.setAttribute("default-content",a.getAttribute("content"));var u=s["--primary-color"]||a.getAttribute("default-content");a.setAttribute("content",u)}}},F=function(e){return"function"==typeof e.getCardSize?e.getCardSize():4};function H(e){return e.substr(0,e.indexOf("."))}function I(e){return e.substr(e.indexOf(".")+1)}function L(e){var t=e.language||"en";return e.translationMetadata.translations[t]&&e.translationMetadata.translations[t].isRTL||!1}function A(e){return L(e)?"rtl":"ltr"}function j(e){return H(e.entity_id)}function U(e,t,n){if("unknown"===t.state||"unavailable"===t.state)return e("state.default."+t.state);if(t.attributes.unit_of_measurement)return t.state+" "+t.attributes.unit_of_measurement;var r=j(t);if("input_datetime"===r){var o;if(!t.attributes.has_time)return o=new Date(t.attributes.year,t.attributes.month-1,t.attributes.day),D(o,n);if(!t.attributes.has_date){var s=new Date;return o=new Date(s.getFullYear(),s.getMonth(),s.getDay(),t.attributes.hour,t.attributes.minute),T(o,n)}return o=new Date(t.attributes.year,t.attributes.month-1,t.attributes.day,t.attributes.hour,t.attributes.minute),M(o,n)}return t.attributes.device_class&&e("component."+r+".state."+t.attributes.device_class+"."+t.state)||e("component."+r+".state._."+t.state)||t.state}var z="hass:bookmark",B="lovelace",Z=["climate","cover","configurator","input_select","input_number","input_text","lock","media_player","scene","script","timer","vacuum","water_heater","weblink"],K=["alarm_control_panel","automation","camera","climate","configurator","cover","fan","group","history_graph","input_datetime","light","lock","media_player","script","sun","updater","vacuum","water_heater","weather"],V=["input_number","input_select","input_text","scene","weblink"],W=["camera","configurator","history_graph","scene"],G=["closed","locked","off"],J=new Set(["fan","input_boolean","light","switch","group","automation"]),$="°C",Q="°F",X="group.default_view",ee=function(e,t,n,r){r=r||{},n=null==n?{}:n;var o=new Event(t,{bubbles:void 0===r.bubbles||r.bubbles,cancelable:Boolean(r.cancelable),composed:void 0===r.composed||r.composed});return o.detail=n,e.dispatchEvent(o),o},te=new Set(["call-service","divider","section","weblink","cast","select"]),ne={alert:"toggle",automation:"toggle",climate:"climate",cover:"cover",fan:"toggle",group:"group",input_boolean:"toggle",input_number:"input-number",input_select:"input-select",input_text:"input-text",light:"toggle",lock:"lock",media_player:"media-player",remote:"toggle",scene:"scene",script:"script",sensor:"sensor",timer:"timer",switch:"toggle",vacuum:"toggle",water_heater:"climate",input_datetime:"input-datetime"},re=function(e,t){void 0===t&&(t=!1);var n=function(e,t){return r("hui-error-card",{type:"error",error:e,config:t})},r=function(e,t){var r=window.document.createElement(e);try{r.setConfig(t)}catch(r){return console.error(e,r),n(r.message,t)}return r};if(!e||"object"!=typeof e||!t&&!e.type)return n("No type defined",e);var o=e.type;if(o&&o.startsWith("custom:"))o=o.substr("custom:".length);else if(t)if(te.has(o))o="hui-"+o+"-row";else{if(!e.entity)return n("Invalid config given.",e);var s=e.entity.split(".",1)[0];o="hui-"+(ne[s]||"text")+"-entity-row"}else o="hui-"+o+"-card";if(customElements.get(o))return r(o,e);var i=n("Custom element doesn't exist: "+e.type+".",e);i.style.display="None";var a=setTimeout(function(){i.style.display=""},2e3);return customElements.whenDefined(e.type).then(function(){clearTimeout(a),ee(i,"ll-rebuild",{},i)}),i},oe={alert:"hass:alert",automation:"hass:playlist-play",calendar:"hass:calendar",camera:"hass:video",climate:"hass:thermostat",configurator:"hass:settings",conversation:"hass:text-to-speech",device_tracker:"hass:account",fan:"hass:fan",group:"hass:google-circles-communities",history_graph:"hass:chart-line",homeassistant:"hass:home-assistant",homekit:"hass:home-automation",image_processing:"hass:image-filter-frames",input_boolean:"hass:drawing",input_datetime:"hass:calendar-clock",input_number:"hass:ray-vertex",input_select:"hass:format-list-bulleted",input_text:"hass:textbox",light:"hass:lightbulb",mailbox:"hass:mailbox",notify:"hass:comment-alert",person:"hass:account",plant:"hass:flower",proximity:"hass:apple-safari",remote:"hass:remote",scene:"hass:google-pages",script:"hass:file-document",sensor:"hass:eye",simple_alarm:"hass:bell",sun:"hass:white-balance-sunny",switch:"hass:flash",timer:"hass:timer",updater:"hass:cloud-upload",vacuum:"hass:robot-vacuum",water_heater:"hass:thermometer",weblink:"hass:open-in-new"};function se(e,t){if(e in oe)return oe[e];switch(e){case"alarm_control_panel":switch(t){case"armed_home":return"hass:bell-plus";case"armed_night":return"hass:bell-sleep";case"disarmed":return"hass:bell-outline";case"triggered":return"hass:bell-ring";default:return"hass:bell"}case"binary_sensor":return t&&"off"===t?"hass:radiobox-blank":"hass:checkbox-marked-circle";case"cover":return"closed"===t?"hass:window-closed":"hass:window-open";case"lock":return t&&"unlocked"===t?"hass:lock-open":"hass:lock";case"media_player":return t&&"off"!==t&&"idle"!==t?"hass:cast-connected":"hass:cast";case"zwave":switch(t){case"dead":return"hass:emoticon-dead";case"sleeping":return"hass:sleep";case"initializing":return"hass:timer-sand";default:return"hass:z-wave"}default:return console.warn("Unable to find icon for domain "+e+" ("+t+")"),z}}var ie=function(e,t){var n=t.value||t,r=t.attribute?e.attributes[t.attribute]:e.state;switch(t.operator||"=="){case"==":return r===n;case"<=":return r<=n;case"<":return r=":return r>=n;case">":return r>n;case"!=":return r!==n;case"regex":return r.match(n);default:return!1}},ae=function(e){ee(window,"haptic",e)},ue=function(e,t,n){void 0===n&&(n=!1),n?history.replaceState(null,"",t):history.pushState(null,"",t),ee(window,"location-changed",{replace:n})},ce=function(e,t,n){void 0===n&&(n=!0);var r,o=H(t),s="group"===o?"homeassistant":o;switch(o){case"lock":r=n?"unlock":"lock";break;case"cover":r=n?"open_cover":"close_cover";break;default:r=n?"turn_on":"turn_off"}return e.callService(s,r,{entity_id:t})},le=function(e,t){var n=G.includes(e.states[t].state);return ce(e,t,n)},he=function(e,t,n,r){var o;if("double_tap"===r&&n.double_tap_action?o=n.double_tap_action:"hold"===r&&n.hold_action?o=n.hold_action:"tap"===r&&n.tap_action&&(o=n.tap_action),o||(o={action:"more-info"}),!o.confirmation||o.confirmation.exemptions&&o.confirmation.exemptions.some(function(e){return e.user===t.user.id})||(ae("warning"),confirm(o.confirmation.text||"Are you sure you want to "+o.action+"?")))switch(o.action){case"more-info":(n.entity||n.camera_image)&&ee(e,"hass-more-info",{entityId:n.entity?n.entity:n.camera_image});break;case"navigate":o.navigation_path&&ue(0,o.navigation_path);break;case"url":o.url_path&&window.open(o.url_path);break;case"toggle":n.entity&&(le(t,n.entity),ae("success"));break;case"call-service":if(!o.service)return void ae("failure");var s=o.service.split(".",2);t.callService(s[0],s[1],o.service_data),ae("success")}},de=function(e,t,n,r,o){var s;if(o&&n.double_tap_action?s=n.double_tap_action:r&&n.hold_action?s=n.hold_action:!r&&n.tap_action&&(s=n.tap_action),s||(s={action:"more-info"}),!s.confirmation||s.confirmation.exemptions&&s.confirmation.exemptions.some(function(e){return e.user===t.user.id})||confirm(s.confirmation.text||"Are you sure you want to "+s.action+"?"))switch(s.action){case"more-info":(s.entity||n.entity||n.camera_image)&&(ee(e,"hass-more-info",{entityId:s.entity?s.entity:n.entity?n.entity:n.camera_image}),s.haptic&&ae(s.haptic));break;case"navigate":s.navigation_path&&(ue(0,s.navigation_path),s.haptic&&ae(s.haptic));break;case"url":s.url_path&&window.open(s.url_path),s.haptic&&ae(s.haptic);break;case"toggle":n.entity&&(le(t,n.entity),s.haptic&&ae(s.haptic));break;case"call-service":if(!s.service)return;var i=s.service.split(".",2),a=i[0],u=i[1],c=Object.assign({},s.service_data);"entity"===c.entity_id&&(c.entity_id=n.entity),t.callService(a,u,c),s.haptic&&ae(s.haptic)}};function fe(e){return void 0!==e&&"none"!==e.action}function pe(e,t,n){if(t.has("config")||n)return!0;if(e.config.entity){var r=t.get("hass");return!r||r.states[e.config.entity]!==e.hass.states[e.config.entity]}return!1}function me(e){return void 0!==e&&"none"!==e.action}var ve=function(e,t,n){void 0===n&&(n=!0);var r={};t.forEach(function(t){if(G.includes(e.states[t].state)===n){var o=H(t),s=["cover","lock"].includes(o)?o:"homeassistant";s in r||(r[s]=[]),r[s].push(t)}}),Object.keys(r).forEach(function(t){var o;switch(t){case"lock":o=n?"unlock":"lock";break;case"cover":o=n?"open_cover":"close_cover";break;default:o=n?"turn_on":"turn_off"}e.callService(t,o,{entity_id:r[t]})})},ye=function(){var e=document.querySelector("home-assistant");if(e=(e=(e=(e=(e=(e=(e=(e=e&&e.shadowRoot)&&e.querySelector("home-assistant-main"))&&e.shadowRoot)&&e.querySelector("app-drawer-layout partial-panel-resolver"))&&e.shadowRoot||e)&&e.querySelector("ha-panel-lovelace"))&&e.shadowRoot)&&e.querySelector("hui-root")){var t=e.lovelace;return t.current_view=e.___curView,t}return null},ge={humidity:"hass:water-percent",illuminance:"hass:brightness-5",temperature:"hass:thermometer",pressure:"hass:gauge",power:"hass:flash",signal_strength:"hass:wifi"},we={binary_sensor:function(e){var t=e.state&&"off"===e.state;switch(e.attributes.device_class){case"battery":return t?"hass:battery":"hass:battery-outline";case"cold":return t?"hass:thermometer":"hass:snowflake";case"connectivity":return t?"hass:server-network-off":"hass:server-network";case"door":return t?"hass:door-closed":"hass:door-open";case"garage_door":return t?"hass:garage":"hass:garage-open";case"gas":case"power":case"problem":case"safety":case"smoke":return t?"hass:shield-check":"hass:alert";case"heat":return t?"hass:thermometer":"hass:fire";case"light":return t?"hass:brightness-5":"hass:brightness-7";case"lock":return t?"hass:lock":"hass:lock-open";case"moisture":return t?"hass:water-off":"hass:water";case"motion":return t?"hass:walk":"hass:run";case"occupancy":return t?"hass:home-outline":"hass:home";case"opening":return t?"hass:square":"hass:square-outline";case"plug":return t?"hass:power-plug-off":"hass:power-plug";case"presence":return t?"hass:home-outline":"hass:home";case"sound":return t?"hass:music-note-off":"hass:music-note";case"vibration":return t?"hass:crop-portrait":"hass:vibrate";case"window":return t?"hass:window-closed":"hass:window-open";default:return t?"hass:radiobox-blank":"hass:checkbox-marked-circle"}},cover:function(e){var t="closed"!==e.state;switch(e.attributes.device_class){case"garage":return t?"hass:garage-open":"hass:garage";case"door":return t?"hass:door-open":"hass:door-closed";case"shutter":return t?"hass:window-shutter-open":"hass:window-shutter";case"blind":return t?"hass:blinds-open":"hass:blinds";case"window":return t?"hass:window-open":"hass:window-closed";default:return se("cover",e.state)}},sensor:function(e){var t=e.attributes.device_class;if(t&&t in ge)return ge[t];if("battery"===t){var n=Number(e.state);if(isNaN(n))return"hass:battery-unknown";var r=10*Math.round(n/10);return r>=100?"hass:battery":r<=0?"hass:battery-alert":"hass:battery-"+r}var o=e.attributes.unit_of_measurement;return"°C"===o||"°F"===o?"hass:thermometer":se("sensor")},input_datetime:function(e){return e.attributes.has_date?e.attributes.has_time?se("input_datetime"):"hass:calendar":"hass:clock"}},be=function(e){if(!e)return z;if(e.attributes.icon)return e.attributes.icon;var t=H(e.entity_id);return t in we?we[t](e):se(t,e.state)}}]); \ No newline at end of file +!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=2)}([function(e,t,n){"use strict";function r(){return document.querySelector("hc-main")?document.querySelector("hc-main").hass:document.querySelector("home-assistant")?document.querySelector("home-assistant").hass:void 0}function o(e){return document.querySelector("hc-main")?document.querySelector("hc-main").provideHass(e):document.querySelector("home-assistant")?document.querySelector("home-assistant").provideHass(e):void 0}function s(){var e,t=document.querySelector("hc-main");return t?((e=t._lovelaceConfig).current_view=t._lovelacePath,e):(t=(t=(t=(t=(t=(t=(t=(t=(t=document.querySelector("home-assistant"))&&t.shadowRoot)&&t.querySelector("home-assistant-main"))&&t.shadowRoot)&&t.querySelector("app-drawer-layout partial-panel-resolver"))&&t.shadowRoot||t)&&t.querySelector("ha-panel-lovelace"))&&t.shadowRoot)&&t.querySelector("hui-root"))?((e=t.lovelace).current_view=t.___curView,e):null}async function i(e){e&&(await customElements.whenDefined(e.localName),e.updateComplete&&await e.updateComplete)}async function a(){var e=document.querySelector("hc-main");return e?(i(e=(e=e&&e.shadowRoot)&&e.querySelector("hc-lovelace")),i(e=(e=e&&e.shadowRoot)&&e.querySelector("hui-view")||e.querySelector("hui-panel-view")),e):(i(e=document.querySelector("home-assistant")),i(e=(e=e&&e.shadowRoot)&&e.querySelector("home-assistant-main")),i(e=(e=e&&e.shadowRoot)&&e.querySelector("app-drawer-layout partial-panel-resolver")),i(e=(e=e&&e.shadowRoot||e)&&e.querySelector("ha-panel-lovelace")),i(e=(e=e&&e.shadowRoot)&&e.querySelector("hui-root")),i(e=(e=e&&e.shadowRoot)&&e.querySelector("ha-app-layout")),i(e=(e=e&&e.querySelector("#view"))&&e.firstElementChild),e)}function u(){var e=document.querySelector("hc-main");return e=e?(e=(e=(e=e&&e.shadowRoot)&&e.querySelector("hc-lovelace"))&&e.shadowRoot)&&e.querySelector("hui-view")||e.querySelector("hui-panel-view"):(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=document.querySelector("home-assistant"))&&e.shadowRoot)&&e.querySelector("home-assistant-main"))&&e.shadowRoot)&&e.querySelector("app-drawer-layout partial-panel-resolver"))&&e.shadowRoot||e)&&e.querySelector("ha-panel-lovelace"))&&e.shadowRoot)&&e.querySelector("hui-root"))&&e.shadowRoot)&&e.querySelector("ha-app-layout"))&&e.querySelector("#view"))&&e.firstElementChild}async function c(){if(customElements.get("hui-view"))return!0;await customElements.whenDefined("partial-panel-resolver");const e=document.createElement("partial-panel-resolver");if(e.hass={panels:[{url_path:"tmp",component_name:"lovelace"}]},e._updateRoutes(),await e.routerOptions.routes.tmp.load(),!customElements.get("ha-panel-lovelace"))return!1;const t=document.createElement("ha-panel-lovelace");return t.hass=r(),void 0===t.hass&&(await new Promise(e=>{window.addEventListener("connection-status",t=>{console.log(t),e()},{once:!0})}),t.hass=r()),t.panel={config:{mode:null}},t._fetchConfig(),!0}n.r(t),n.d(t,"hass",function(){return r}),n.d(t,"provideHass",function(){return o}),n.d(t,"lovelace",function(){return s}),n.d(t,"async_lovelace_view",function(){return a}),n.d(t,"lovelace_view",function(){return u}),n.d(t,"load_lovelace",function(){return c})},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.scaleElement=t.setIntervalNTimes=t.removeBlur=t.getView=t.setModalBehaviour=void 0;const r=function(e,t){var n=document.querySelector("body > home-assistant").shadowRoot.querySelector("ha-more-info-dialog");n?e?(n.noCancelOnOutsideClick=!1,n.style.pointerEvents="all"):(n.noCancelOnOutsideClick=!0,n.style.pointerEvents="none"):t&&setTimeout(function(){r(e,!1)},100)};t.setModalBehaviour=r;const o=function(){return document.querySelector("body > home-assistant").shadowRoot.querySelector("home-assistant-main").shadowRoot.querySelector("app-drawer-layout > partial-panel-resolver > ha-panel-lovelace").shadowRoot.querySelector("hui-root").shadowRoot.querySelector("#view > hui-view")?document.querySelector("body > home-assistant").shadowRoot.querySelector("home-assistant-main").shadowRoot.querySelector("app-drawer-layout > partial-panel-resolver > ha-panel-lovelace").shadowRoot.querySelector("hui-root").shadowRoot.querySelector("#view > hui-view"):document.querySelector("body > home-assistant").shadowRoot.querySelector("home-assistant-main").shadowRoot.querySelector("app-drawer-layout > partial-panel-resolver > ha-panel-lovelace").shadowRoot.querySelector("hui-root").shadowRoot.querySelector("#view > hui-panel-view")};t.getView=o;t.removeBlur=function(){try{o().style.webkitFilter="blur(0px)"}catch(e){if(!(e instanceof TypeError))throw e}};const s=(e,t,n)=>{n&&setTimeout(()=>{e(),s(e,t,n-1)},t)};t.setIntervalNTimes=s;t.scaleElement=function(e,t,n){e.animations&&(t.style.transform="scale("+n+")")}},function(e,t,n){"use strict";var r,o=n(1),s=n(0),i=n(3),a=(r=n(4))&&r.__esModule?r:{default:r};const u=()=>{(0,s.lovelace)()?c():setTimeout(u,250)},c=()=>{customElements.whenDefined("card-tools").then(()=>{customElements.whenDefined("ha-card").then(()=>{const e=customElements.get("ha-card");var t=Object.assign({},{enable_unsupported:!1,animations:!0},(0,s.lovelace)().config.deep_press);if("ontouchforcechange"in document==!1&&0==t.enable_unsupported)return;["touchend","mouseup"].forEach(e=>{document.addEventListener(e,()=>{(0,o.removeBlur)(),setTimeout(function(){(0,o.setModalBehaviour)(!0,!1)},100)})});const n=function(e){return e.config?e.config:e._config?e._config:e.host?n(e.host):e.parentElement?n(e.parentElement):e.parentNode?n(e.parentNode):null};var r=e.prototype.firstUpdated;e.prototype.firstUpdated=function(e){r.apply(this,e);const o=n(this);o&&o.deep_press&&o.hold_action&&function(e,t){if(!this.querySelector(":scope >#deep-press-cover")){var n=document.createElement("div");n.setAttribute("id","deep-press-cover"),n.setAttribute("style","position: absolute; top:0; left:0; width:100%; height: 100%; overflow: visible;"),this.appendChild(n),new a.default(n,this,e,t).init()}}.call(this,t,o)},(0,i.fireEvent)("ll-rebuild",{})})})};u(),console.info("%cdeep-press\n%cVersion: 2.1.2","color: green; font-weight: bold;","")},function(e,t,n){"use strict";n.r(t),n.d(t,"fireEvent",function(){return o});var r=n(0);function o(e,t,n=null){if((e=new Event(e,{bubbles:!0,cancelable:!1,composed:!0})).detail=t||{},n)n.dispatchEvent(e);else{var o=Object(r.lovelace_view)();o&&o.dispatchEvent(e)}}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var r,o=n(1),s=n(6),i=(r=n(5))&&r.__esModule?r:{default:r};t.default=class{constructor(e,t,n,r){this.cover=e,this.root=t,this.deep_press_config=n,this.config=r,this.cover.deep_press_config=n,this.cover.config=r,this._upEvent=this.upEvent.bind(this)}downEvent(e){["click"].forEach(function(e){this.cover.addEventListener(e,this._upEvent,{passive:!0,capture:!0})},this),this.down_event=Object.assign({},e),e.stopPropagation(),(0,o.getView)().dispatchEvent(new e.constructor(e.type,e))}upEvent(e){if((0,o.scaleElement)(this.deep_press_config,this.root,1),this.cover.removeEventListener(e.type,this._upEvent,{passive:!0,capture:!0}),this.cover.cancel||this.cover.hold)return e.stopPropagation(),void(0,o.getView)().dispatchEvent(new e.constructor(e.type,e));"click"!=e.type&&this.root.dispatchEvent(new e.constructor(this.down_event.type,this.down_event)),this.root.dispatchEvent(new e.constructor(e.type,e)),(0,o.removeBlur)()}cancelEvent(e){this.cover.cancel=!0,(0,o.scaleElement)(this.deep_press_config,this.root,1),(0,o.removeBlur)()}init(){["touchstart","mousedown"].forEach(function(e){this.cover.addEventListener(e,this.downEvent.bind(this),{passive:!0,capture:!0})},this),["touchcancel","mouseout","touchmove","mousewheel","wheel","scroll"].forEach(function(e){this.cover.addEventListener(e,this.cancelEvent.bind(this),{passive:!0,capture:!0})},this),i.default.set(this.cover,{start:function(e){this.cancel=!1,this.event_over=!1,this.hold=!1,this.deep_press=!1,this.view=(0,o.getView)()},change:function(e,t){this.cancel||this.deep_press||e>.2&&(this.view.style.webkitFilter="blur("+i.default.map(e,.2,.5,0,10)+"px)",(0,o.scaleElement)(this.deep_press_config,this.parentElement,i.default.map(e,.2,.5,1,.5)),this.hold=!0)},startDeepPress:function(e){this.cancel||this.deep_press||(this.deep_press=!0,(0,o.scaleElement)(this.deep_press_config,this.parentElement,1),(0,s.handleClick)(this.parentElement,cardTools.hass,this.config,!0,!1),(0,o.setModalBehaviour)(!1,!0),(0,o.removeBlur)())},end:function(){(0,o.scaleElement)(this.deep_press_config,this.parentElement,1),(0,o.removeBlur)()}})}}},function(e,t,n){var r,o,s;o=[],void 0===(s="function"==typeof(r=function(){"use strict";function e(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function t(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o=function(){function e(e,t){for(var n=0;n=.5?this._startDeepPress(t):this._endDeepPress()}},{key:"runPolyfill",value:function(e){this.increment=0===h.get("polyfillSpeedUp",this.options)?1:10/h.get("polyfillSpeedUp",this.options),this.decrement=0===h.get("polyfillSpeedDown",this.options)?1:10/h.get("polyfillSpeedDown",this.options),this.setPressed(!0),this.runClosure("start",e),!1===this.runningPolyfill&&this.loopPolyfillForce(0,e)}},{key:"loopPolyfillForce",value:function(e,t){!1===this.nativeSupport&&(this.isPressed()?(this.runningPolyfill=!0,e=e+this.increment>1?1:e+this.increment,this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10)):((e=e-this.decrement<0?0:e-this.decrement)<.5&&this.isDeepPressed()&&(this.setDeepPressed(!1),this.runClosure("endDeepPress")),0===e?(this.runningPolyfill=!1,this.setPressed(!0),this._endPress()):(this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10))))}}]),e}(),u=function(r){function s(t,r,o){return n(this,s),e(this,(s.__proto__||Object.getPrototypeOf(s)).call(this,t,r,o))}return t(s,r),o(s,[{key:"bindEvents",value:function(){this.add("webkitmouseforcewillbegin",this._startPress.bind(this)),this.add("mousedown",this.support.bind(this)),this.add("webkitmouseforcechanged",this.change.bind(this)),this.add("webkitmouseforcedown",this._startDeepPress.bind(this)),this.add("webkitmouseforceup",this._endDeepPress.bind(this)),this.add("mouseleave",this._endPress.bind(this)),this.add("mouseup",this._endPress.bind(this))}},{key:"support",value:function(e){!1===this.isPressed()&&this.fail(e,this.runKey)}},{key:"change",value:function(e){this.isPressed()&&e.webkitForce>0&&this._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(p(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),s}(a),c=function(r){function s(t,r,o){return n(this,s),e(this,(s.__proto__||Object.getPrototypeOf(s)).call(this,t,r,o))}return t(s,r),o(s,[{key:"bindEvents",value:function(){w?(this.add("touchforcechange",this.start.bind(this)),this.add("touchstart",this.support.bind(this,0)),this.add("touchend",this._endPress.bind(this))):(this.add("touchstart",this.startLegacy.bind(this)),this.add("touchend",this._endPress.bind(this)))}},{key:"start",value:function(e){e.touches.length>0&&(this._startPress(e),this.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"support",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;!1===this.isPressed()&&(e<=6?(e++,setTimeout(this.support.bind(this,e,t,n),10)):this.fail(t,n))}},{key:"startLegacy",value:function(e){this.initialForce=e.touches[0].force,this.supportLegacy(0,e,this.runKey,this.initialForce)}},{key:"supportLegacy",value:function(e,t,n,r){r!==this.initialForce?(this._startPress(t),this.loopForce(t)):e<=6?(e++,setTimeout(this.supportLegacy.bind(this,e,t,n,r),10)):this.fail(t,n)}},{key:"loopForce",value:function(e){this.isPressed()&&(this.touch=this.selectTouch(e),setTimeout(this.loopForce.bind(this,e),10),this._changePress(this.touch.force,e))}},{key:"selectTouch",value:function(e){if(1===e.touches.length)return this.returnTouch(e.touches[0],e);for(var t=0;t1?this.fail(e,this.runKey):(this._startPress(e),this._changePress(e.pressure,e)))}},{key:"change",value:function(e){this.isPressed()&&e.pressure>0&&.5!==e.pressure&&(this._changePress(e.pressure,e),this.deepPress(e.pressure,e))}}]),s}(a),h={polyfill:!0,polyfillSpeedUp:1e3,polyfillSpeedDown:0,preventSelect:!0,only:null,get:function(e,t){return t.hasOwnProperty(e)?t[e]:this[e]},set:function(e){for(var t in e)e.hasOwnProperty(t)&&this.hasOwnProperty(t)&&"get"!=t&&"set"!=t&&(this[t]=e[t])}},d=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var r=document.querySelectorAll(e),o=0;o-1?r:null}};function u(e){for(var t=[],n=1;n3?0:(e-e%10!=10?1:0)*e%10]}},f=u({},d),p=function(e){return e.replace(/[|\\{()[^$+*?.-]/g,"\\$&")},m=function(e,t){for(void 0===t&&(t=2),e=String(e);e.length0?"-":"+")+m(100*Math.floor(Math.abs(t)/60)+Math.abs(t)%60,4)},Z:function(e){var t=e.getTimezoneOffset();return(t>0?"-":"+")+m(Math.floor(Math.abs(t)/60),2)+":"+m(Math.abs(t)%60,2)}},y=function(e){return+e-1},g=[null,"[1-9]\\d?"],w=[null,o],b=["isPm",o,function(e,t){var n=e.toLowerCase();return n===t.amPm[0]?0:n===t.amPm[1]?1:null}],_=["timezoneOffset","[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z?",function(e){var t=(e+"").match(/([+-]|\d\d)/gi);if(t){var n=60*+t[1]+parseInt(t[2],10);return"+"===t[0]?n:-n}return 0}],S={D:["day","[1-9]\\d?"],DD:["day","\\d\\d"],Do:["day","[1-9]\\d?"+o,function(e){return parseInt(e,10)}],M:["month","[1-9]\\d?",y],MM:["month","\\d\\d",y],YY:["year","\\d\\d",function(e){var t=+(""+(new Date).getFullYear()).substr(0,2);return+(""+(+e>68?t-1:t)+e)}],h:["hour","[1-9]\\d?",void 0,"isPm"],hh:["hour","\\d\\d",void 0,"isPm"],H:["hour","[1-9]\\d?"],HH:["hour","\\d\\d"],m:["minute","[1-9]\\d?"],mm:["minute","\\d\\d"],s:["second","[1-9]\\d?"],ss:["second","\\d\\d"],YYYY:["year","\\d{4}"],S:["millisecond","\\d",function(e){return 100*+e}],SS:["millisecond","\\d\\d",function(e){return 10*+e}],SSS:["millisecond","\\d{3}"],d:g,dd:g,ddd:w,dddd:w,MMM:["month",o,a("monthNamesShort")],MMMM:["month",o,a("monthNames")],a:b,A:b,ZZ:_,Z:_},k={default:"ddd MMM DD YYYY HH:mm:ss",shortDate:"M/D/YY",mediumDate:"MMM D, YYYY",longDate:"MMMM D, YYYY",fullDate:"dddd, MMMM D, YYYY",isoDate:"YYYY-MM-DD",isoDateTime:"YYYY-MM-DDTHH:mm:ssZ",shortTime:"HH:mm",mediumTime:"HH:mm:ss",longTime:"HH:mm:ss.SSS"};var P={format:function(e,t,n){if(void 0===t&&(t=k.default),void 0===n&&(n={}),"number"==typeof e&&(e=new Date(e)),"[object Date]"!==Object.prototype.toString.call(e)||isNaN(e.getTime()))throw new Error("Invalid Date pass to format");t=k[t]||t;var o=[];t=t.replace(s,function(e,t){return o.push(t),"@@@"});var i=u(u({},f),n);return(t=t.replace(r,function(t){return v[t](e,i)})).replace(/@@@/g,function(){return o.shift()})},parse:function(e,t,n){if(void 0===n&&(n={}),"string"!=typeof t)throw new Error("Invalid format in fecha parse");if(t=k[t]||t,e.length>1e3)return null;var o={year:(new Date).getFullYear(),month:0,day:1,hour:0,minute:0,second:0,millisecond:0,isPm:null,timezoneOffset:null},i=[],a=[],c=t.replace(s,function(e,t){return a.push(p(t)),"@@@"}),l={},h={};c=p(c).replace(r,function(e){var t=S[e],n=t[0],r=t[1],o=t[3];if(l[n])throw new Error("Invalid format. "+n+" specified twice in format");return l[n]=!0,o&&(h[o]=!0),i.push(t),"("+r+")"}),Object.keys(h).forEach(function(e){if(!l[e])throw new Error("Invalid format. "+e+" is required in specified format")}),c=c.replace(/@@@/g,function(){return a.shift()});var d=e.match(new RegExp(c,"i"));if(!d)return null;for(var m=u(u({},f),n),v=1;v=0?"past":"future";o=Math.abs(o);for(var i=0;i0?t+":"+Y(n)+":"+Y(r):n>0?n+":"+Y(r):r>0?""+r:null}function x(e){var t=D(e.attributes.remaining);if("active"===e.state){var n=(new Date).getTime(),r=new Date(e.last_changed).getTime();t=Math.max(t-(n-r)/1e3,0)}return t}var N=function(e,t,n,r){void 0===r&&(r=!1),e._themes||(e._themes={});var o=t.default_theme;("default"===n||n&&t.themes[n])&&(o=n);var s=Object.assign({},e._themes);if("default"!==o){var i=t.themes[o];Object.keys(i).forEach(function(t){var n="--"+t;e._themes[n]="",s[n]=i[t]})}if(e.updateStyles?e.updateStyles(s):window.ShadyCSS&&window.ShadyCSS.styleSubtree(e,s),r){var a=document.querySelector("meta[name=theme-color]");if(a){a.hasAttribute("default-content")||a.setAttribute("default-content",a.getAttribute("content"));var u=s["--primary-color"]||a.getAttribute("default-content");a.setAttribute("content",u)}}},F=function(e){return"function"==typeof e.getCardSize?e.getCardSize():4};function H(e){return e.substr(0,e.indexOf("."))}function I(e){return e.substr(e.indexOf(".")+1)}function L(e){var t=e.language||"en";return e.translationMetadata.translations[t]&&e.translationMetadata.translations[t].isRTL||!1}function j(e){return L(e)?"rtl":"ltr"}function A(e){return H(e.entity_id)}function U(e,t,n){if("unknown"===t.state||"unavailable"===t.state)return e("state.default."+t.state);if(t.attributes.unit_of_measurement)return t.state+" "+t.attributes.unit_of_measurement;var r=A(t);if("input_datetime"===r){var o;if(!t.attributes.has_time)return o=new Date(t.attributes.year,t.attributes.month-1,t.attributes.day),E(o,n);if(!t.attributes.has_date){var s=new Date;return o=new Date(s.getFullYear(),s.getMonth(),s.getDay(),t.attributes.hour,t.attributes.minute),T(o,n)}return o=new Date(t.attributes.year,t.attributes.month-1,t.attributes.day,t.attributes.hour,t.attributes.minute),M(o,n)}return t.attributes.device_class&&e("component."+r+".state."+t.attributes.device_class+"."+t.state)||e("component."+r+".state._."+t.state)||t.state}var z="hass:bookmark",B="lovelace",Z=["climate","cover","configurator","input_select","input_number","input_text","lock","media_player","scene","script","timer","vacuum","water_heater","weblink"],V=["alarm_control_panel","automation","camera","climate","configurator","cover","fan","group","history_graph","input_datetime","light","lock","media_player","script","sun","updater","vacuum","water_heater","weather"],K=["input_number","input_select","input_text","scene","weblink"],W=["camera","configurator","history_graph","scene"],G=["closed","locked","off"],J=new Set(["fan","input_boolean","light","switch","group","automation"]),$="°C",Q="°F",X="group.default_view",ee=function(e,t,n,r){r=r||{},n=null==n?{}:n;var o=new Event(t,{bubbles:void 0===r.bubbles||r.bubbles,cancelable:Boolean(r.cancelable),composed:void 0===r.composed||r.composed});return o.detail=n,e.dispatchEvent(o),o},te=new Set(["call-service","divider","section","weblink","cast","select"]),ne={alert:"toggle",automation:"toggle",climate:"climate",cover:"cover",fan:"toggle",group:"group",input_boolean:"toggle",input_number:"input-number",input_select:"input-select",input_text:"input-text",light:"toggle",lock:"lock",media_player:"media-player",remote:"toggle",scene:"scene",script:"script",sensor:"sensor",timer:"timer",switch:"toggle",vacuum:"toggle",water_heater:"climate",input_datetime:"input-datetime"},re=function(e,t){void 0===t&&(t=!1);var n=function(e,t){return r("hui-error-card",{type:"error",error:e,config:t})},r=function(e,t){var r=window.document.createElement(e);try{r.setConfig(t)}catch(r){return console.error(e,r),n(r.message,t)}return r};if(!e||"object"!=typeof e||!t&&!e.type)return n("No type defined",e);var o=e.type;if(o&&o.startsWith("custom:"))o=o.substr("custom:".length);else if(t)if(te.has(o))o="hui-"+o+"-row";else{if(!e.entity)return n("Invalid config given.",e);var s=e.entity.split(".",1)[0];o="hui-"+(ne[s]||"text")+"-entity-row"}else o="hui-"+o+"-card";if(customElements.get(o))return r(o,e);var i=n("Custom element doesn't exist: "+e.type+".",e);i.style.display="None";var a=setTimeout(function(){i.style.display=""},2e3);return customElements.whenDefined(e.type).then(function(){clearTimeout(a),ee(i,"ll-rebuild",{},i)}),i},oe={alert:"hass:alert",automation:"hass:playlist-play",calendar:"hass:calendar",camera:"hass:video",climate:"hass:thermostat",configurator:"hass:settings",conversation:"hass:text-to-speech",device_tracker:"hass:account",fan:"hass:fan",group:"hass:google-circles-communities",history_graph:"hass:chart-line",homeassistant:"hass:home-assistant",homekit:"hass:home-automation",image_processing:"hass:image-filter-frames",input_boolean:"hass:drawing",input_datetime:"hass:calendar-clock",input_number:"hass:ray-vertex",input_select:"hass:format-list-bulleted",input_text:"hass:textbox",light:"hass:lightbulb",mailbox:"hass:mailbox",notify:"hass:comment-alert",person:"hass:account",plant:"hass:flower",proximity:"hass:apple-safari",remote:"hass:remote",scene:"hass:google-pages",script:"hass:file-document",sensor:"hass:eye",simple_alarm:"hass:bell",sun:"hass:white-balance-sunny",switch:"hass:flash",timer:"hass:timer",updater:"hass:cloud-upload",vacuum:"hass:robot-vacuum",water_heater:"hass:thermometer",weblink:"hass:open-in-new"};function se(e,t){if(e in oe)return oe[e];switch(e){case"alarm_control_panel":switch(t){case"armed_home":return"hass:bell-plus";case"armed_night":return"hass:bell-sleep";case"disarmed":return"hass:bell-outline";case"triggered":return"hass:bell-ring";default:return"hass:bell"}case"binary_sensor":return t&&"off"===t?"hass:radiobox-blank":"hass:checkbox-marked-circle";case"cover":return"closed"===t?"hass:window-closed":"hass:window-open";case"lock":return t&&"unlocked"===t?"hass:lock-open":"hass:lock";case"media_player":return t&&"off"!==t&&"idle"!==t?"hass:cast-connected":"hass:cast";case"zwave":switch(t){case"dead":return"hass:emoticon-dead";case"sleeping":return"hass:sleep";case"initializing":return"hass:timer-sand";default:return"hass:z-wave"}default:return console.warn("Unable to find icon for domain "+e+" ("+t+")"),z}}var ie=function(e,t){var n=t.value||t,r=t.attribute?e.attributes[t.attribute]:e.state;switch(t.operator||"=="){case"==":return r===n;case"<=":return r<=n;case"<":return r=":return r>=n;case">":return r>n;case"!=":return r!==n;case"regex":return r.match(n);default:return!1}},ae=function(e){ee(window,"haptic",e)},ue=function(e,t,n){void 0===n&&(n=!1),n?history.replaceState(null,"",t):history.pushState(null,"",t),ee(window,"location-changed",{replace:n})},ce=function(e,t,n){void 0===n&&(n=!0);var r,o=H(t),s="group"===o?"homeassistant":o;switch(o){case"lock":r=n?"unlock":"lock";break;case"cover":r=n?"open_cover":"close_cover";break;default:r=n?"turn_on":"turn_off"}return e.callService(s,r,{entity_id:t})},le=function(e,t){var n=G.includes(e.states[t].state);return ce(e,t,n)},he=function(e,t,n,r){var o;if("double_tap"===r&&n.double_tap_action?o=n.double_tap_action:"hold"===r&&n.hold_action?o=n.hold_action:"tap"===r&&n.tap_action&&(o=n.tap_action),o||(o={action:"more-info"}),!o.confirmation||o.confirmation.exemptions&&o.confirmation.exemptions.some(function(e){return e.user===t.user.id})||(ae("warning"),confirm(o.confirmation.text||"Are you sure you want to "+o.action+"?")))switch(o.action){case"more-info":(n.entity||n.camera_image)&&ee(e,"hass-more-info",{entityId:n.entity?n.entity:n.camera_image});break;case"navigate":o.navigation_path&&ue(0,o.navigation_path);break;case"url":o.url_path&&window.open(o.url_path);break;case"toggle":n.entity&&(le(t,n.entity),ae("success"));break;case"call-service":if(!o.service)return void ae("failure");var s=o.service.split(".",2);t.callService(s[0],s[1],o.service_data),ae("success")}},de=function(e,t,n,r,o){var s;if(o&&n.double_tap_action?s=n.double_tap_action:r&&n.hold_action?s=n.hold_action:!r&&n.tap_action&&(s=n.tap_action),s||(s={action:"more-info"}),!s.confirmation||s.confirmation.exemptions&&s.confirmation.exemptions.some(function(e){return e.user===t.user.id})||confirm(s.confirmation.text||"Are you sure you want to "+s.action+"?"))switch(s.action){case"more-info":(s.entity||n.entity||n.camera_image)&&(ee(e,"hass-more-info",{entityId:s.entity?s.entity:n.entity?n.entity:n.camera_image}),s.haptic&&ae(s.haptic));break;case"navigate":s.navigation_path&&(ue(0,s.navigation_path),s.haptic&&ae(s.haptic));break;case"url":s.url_path&&window.open(s.url_path),s.haptic&&ae(s.haptic);break;case"toggle":n.entity&&(le(t,n.entity),s.haptic&&ae(s.haptic));break;case"call-service":if(!s.service)return;var i=s.service.split(".",2),a=i[0],u=i[1],c=Object.assign({},s.service_data);"entity"===c.entity_id&&(c.entity_id=n.entity),t.callService(a,u,c),s.haptic&&ae(s.haptic)}};function fe(e){return void 0!==e&&"none"!==e.action}function pe(e,t,n){if(t.has("config")||n)return!0;if(e.config.entity){var r=t.get("hass");return!r||r.states[e.config.entity]!==e.hass.states[e.config.entity]}return!1}function me(e){return void 0!==e&&"none"!==e.action}var ve=function(e,t,n){void 0===n&&(n=!0);var r={};t.forEach(function(t){if(G.includes(e.states[t].state)===n){var o=H(t),s=["cover","lock"].includes(o)?o:"homeassistant";s in r||(r[s]=[]),r[s].push(t)}}),Object.keys(r).forEach(function(t){var o;switch(t){case"lock":o=n?"unlock":"lock";break;case"cover":o=n?"open_cover":"close_cover";break;default:o=n?"turn_on":"turn_off"}e.callService(t,o,{entity_id:r[t]})})},ye=function(){var e=document.querySelector("home-assistant");if(e=(e=(e=(e=(e=(e=(e=(e=e&&e.shadowRoot)&&e.querySelector("home-assistant-main"))&&e.shadowRoot)&&e.querySelector("app-drawer-layout partial-panel-resolver"))&&e.shadowRoot||e)&&e.querySelector("ha-panel-lovelace"))&&e.shadowRoot)&&e.querySelector("hui-root")){var t=e.lovelace;return t.current_view=e.___curView,t}return null},ge={humidity:"hass:water-percent",illuminance:"hass:brightness-5",temperature:"hass:thermometer",pressure:"hass:gauge",power:"hass:flash",signal_strength:"hass:wifi"},we={binary_sensor:function(e){var t=e.state&&"off"===e.state;switch(e.attributes.device_class){case"battery":return t?"hass:battery":"hass:battery-outline";case"cold":return t?"hass:thermometer":"hass:snowflake";case"connectivity":return t?"hass:server-network-off":"hass:server-network";case"door":return t?"hass:door-closed":"hass:door-open";case"garage_door":return t?"hass:garage":"hass:garage-open";case"gas":case"power":case"problem":case"safety":case"smoke":return t?"hass:shield-check":"hass:alert";case"heat":return t?"hass:thermometer":"hass:fire";case"light":return t?"hass:brightness-5":"hass:brightness-7";case"lock":return t?"hass:lock":"hass:lock-open";case"moisture":return t?"hass:water-off":"hass:water";case"motion":return t?"hass:walk":"hass:run";case"occupancy":return t?"hass:home-outline":"hass:home";case"opening":return t?"hass:square":"hass:square-outline";case"plug":return t?"hass:power-plug-off":"hass:power-plug";case"presence":return t?"hass:home-outline":"hass:home";case"sound":return t?"hass:music-note-off":"hass:music-note";case"vibration":return t?"hass:crop-portrait":"hass:vibrate";case"window":return t?"hass:window-closed":"hass:window-open";default:return t?"hass:radiobox-blank":"hass:checkbox-marked-circle"}},cover:function(e){var t="closed"!==e.state;switch(e.attributes.device_class){case"garage":return t?"hass:garage-open":"hass:garage";case"door":return t?"hass:door-open":"hass:door-closed";case"shutter":return t?"hass:window-shutter-open":"hass:window-shutter";case"blind":return t?"hass:blinds-open":"hass:blinds";case"window":return t?"hass:window-open":"hass:window-closed";default:return se("cover",e.state)}},sensor:function(e){var t=e.attributes.device_class;if(t&&t in ge)return ge[t];if("battery"===t){var n=Number(e.state);if(isNaN(n))return"hass:battery-unknown";var r=10*Math.round(n/10);return r>=100?"hass:battery":r<=0?"hass:battery-alert":"hass:battery-"+r}var o=e.attributes.unit_of_measurement;return"°C"===o||"°F"===o?"hass:thermometer":se("sensor")},input_datetime:function(e){return e.attributes.has_date?e.attributes.has_time?se("input_datetime"):"hass:calendar":"hass:clock"}},be=function(e){if(!e)return z;if(e.attributes.icon)return e.attributes.icon;var t=H(e.entity_id);return t in we?we[t](e):se(t,e.state)}}]); \ No newline at end of file diff --git a/src/deep-press.js b/src/deep-press.js index 784f083..9e5103c 100644 --- a/src/deep-press.js +++ b/src/deep-press.js @@ -26,37 +26,29 @@ export default class DeepPress { downEvent(event) { // Listen for release events [ - 'touchend', - 'mouseup', - // 'click' + // 'touchend', + // 'mouseup', + 'click' ].forEach(function (eventName) { - this.cover.addEventListener(eventName, this._upEvent, { passive: true }); + this.cover.addEventListener(eventName, this._upEvent, { passive: true, capture: true }); }, this); - this.down_event = event; // Store event. Used later to simulate a click + this.down_event = Object.assign({}, event); // Store event. Used later to simulate a click /* We have to stop propagation to prevent the underlying cards actions to trigger. HOWEVER, if we stop propagation, things like swiper-card doesnt work. To solve this i redispatch the same even on the cards parent. Superhacky. */ event.stopPropagation(); - try { - this.root.parentElement.dispatchEvent(new event.constructor(event.type, event)); - } catch (TypeError) { - this.root.getRootNode().host.dispatchEvent(new event.constructor(event.type, event)); - } + getView().dispatchEvent(new event.constructor(event.type, event)); } upEvent(event) { scaleElement(this.deep_press_config, this.root, 1); - this.cover.removeEventListener(event.type, this._upEvent, { passive: true }); + this.cover.removeEventListener(event.type, this._upEvent, { passive: true, capture: true }); if (this.cover.cancel || this.cover.hold) { event.stopPropagation(); - try { - this.root.parentElement.dispatchEvent(new event.constructor(event.type, event)); - } catch (TypeError) { - this.root.getRootNode().host.dispatchEvent(new event.constructor(event.type, event)); - } + getView().dispatchEvent(new event.constructor(event.type, event)); return; } if (event.type != 'click') { @@ -78,7 +70,7 @@ export default class DeepPress { 'touchstart', 'mousedown' ].forEach(function (eventName) { - this.cover.addEventListener(eventName, this.downEvent.bind(this), { passive: true }); + this.cover.addEventListener(eventName, this.downEvent.bind(this), { passive: true, capture: true }); }, this); // Canceling events @@ -90,7 +82,7 @@ export default class DeepPress { 'wheel', 'scroll' ].forEach(function (eventName) { - this.cover.addEventListener(eventName, this.cancelEvent.bind(this), { passive: true }); + this.cover.addEventListener(eventName, this.cancelEvent.bind(this), { passive: true, capture: true }); }, this); Pressure.set(this.cover, { diff --git a/src/main.js b/src/main.js index 13896a8..4deeb8f 100644 --- a/src/main.js +++ b/src/main.js @@ -99,7 +99,7 @@ const initialize = () => { waitForLovelace() console.info( - `%cdeep-press\n%cVersion: 2.1.1`, + `%cdeep-press\n%cVersion: 2.1.2`, "color: green; font-weight: bold;", "" );