diff --git a/README.md b/README.md index f432149..12f2d42 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ You can add global options to ```deep_press``` at the root of your lovelace conf | Name | Type | Requirement | Description | Default | ---- | ---- | ------- | ----------- | ------- | enable_unsupported | boolean | **Optional** | Enable on unsupported devices | false +| animations | boolean | **Optional** | The harder you press, the smaller the div gets | true ### Example Configuration ```yaml diff --git a/dist/deep-press.js b/dist/deep-press.js index 4f435fb..3f98cfd 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=0)}([function(e,t,n){"use strict";var r,o=n(2),i=(r=n(1))&&r.__esModule?r:{default:r};customElements.whenDefined("card-tools").then(()=>{let e=customElements.get("card-tools");const t=customElements.get("ha-card");var n=Object.assign({},{enable_unsupported:!1},e.lovelace.config.deep_press);if("ontouchforcechange"in document==!1&&0==n.enable_unsupported)return;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)};if(["touchend","mouseup"].forEach(e=>{document.addEventListener(e,()=>{!function(){try{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").style.webkitFilter="blur(0px)"}catch(e){if(!(e instanceof TypeError))throw e}}(),setTimeout(function(){r(!0,!1)},100)})}),"ontouchstart"in document.documentElement)var s=["touchstart","touchend","click"];else s=["mousedown","mouseup","click"];const a=function(e){s.forEach(function(t){!function(e,t){var n=document.createEvent("MouseEvents");n.initEvent(t,!0,!0),e.dispatchEvent(n)}(e,t)})};function u(e){this.cancel||(this.view.style.webkitFilter="blur(0px)",this.hold||this.event_over||a(e),this.event_over=!0,this.hold=!1,this.deep_press=!1)}const c=function(t,n){t.querySelector(":scope >#deep-press-cover")||(t.config=n,t.cover=document.createElement("div"),t.cover.setAttribute("id","deep-press-cover"),t.cover.setAttribute("style","position:absolute; top:0; left:0; width:100%; height: 100%;"),t.appendChild(t.cover),["touchstart","mousedown","click"].forEach(function(e){t.cover.addEventListener(e,function(e){(function(e,t){t.stopPropagation();try{e.parentElement.dispatchEvent(new t.constructor(t.type,t))}catch(n){e.getRootNode().host.dispatchEvent(new t.constructor(t.type,t))}}).call(this,t,e)},{passive:!0})}),["touchend","mouseup"].forEach(function(e){t.cover.addEventListener(e,function(e){u.call(this,t,e)},{passive:!0})}),["touchcancel","mouseout","touchmove","mousewheel","wheel","scroll"].forEach(function(e){t.cover.addEventListener(e,function(e){(function(e){this.cancel=!0;try{this.view.style.webkitFilter="blur(0px)"}catch(e){}}).call(this,e)},{passive:!0})}),i.default.set(t.cover,{start:function(e){(function(){this.cancel=!1,this.event_over=!1,this.hold=!1,this.deep_press=!1,this.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")}).call(this)},change:function(e,t){(function(e){this.cancel||this.deep_press||e>.2&&(this.view.style.webkitFilter="blur("+i.default.map(e,.2,.5,0,10)+"px)",this.hold=!0)}).call(this,e)},startDeepPress:function(n){(function(t){this.cancel||this.deep_press||(this.deep_press=!0,(0,o.handleClick)(t,e.hass,t.config,!0,!1),r(!1,!0))}).call(this,t)},end:function(){u.call(this,t),this.view.style.webkitFilter="blur(0px)"}}))},l=function(e){return e.config?e.config:e._config?e._config:e.host?l(e.host):e.parentElement?l(e.parentElement):e.parentNode?l(e.parentNode):null};var h=t.prototype.update;t.prototype.update=function(e){h.apply(this,e);const t=l(this);t&&t.deep_press&&t.hold_action&&c(this,t)}}),console.info("%cdeep-press\n%cVersion: 1.2.5","color: green; font-weight: bold;","")},function(e,t,n){var r,o,i;o=[],void 0===(i="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 i(t,r,o){return n(this,i),e(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,t,r,o))}return t(i,r),o(i,[{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}}]),i}(a),c=function(r){function i(t,r,o){return n(this,i),e(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,t,r,o))}return t(i,r),o(i,[{key:"bindEvents",value:function(){b?(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))}}]),i}(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;o3?0:(e-e%10!=10)*e%10]}};var m={D:function(e){return e.getDate()},DD:function(e){return l(e.getDate())},Do:function(e,t){return t.DoFn(e.getDate())},d:function(e){return e.getDay()},dd:function(e){return l(e.getDay())},ddd:function(e,t){return t.dayNamesShort[e.getDay()]},dddd:function(e,t){return t.dayNames[e.getDay()]},M:function(e){return e.getMonth()+1},MM:function(e){return l(e.getMonth()+1)},MMM:function(e,t){return t.monthNamesShort[e.getMonth()]},MMMM:function(e,t){return t.monthNames[e.getMonth()]},YY:function(e){return l(String(e.getFullYear()),4).substr(2)},YYYY:function(e){return l(e.getFullYear(),4)},h:function(e){return e.getHours()%12||12},hh:function(e){return l(e.getHours()%12||12)},H:function(e){return e.getHours()},HH:function(e){return l(e.getHours())},m:function(e){return e.getMinutes()},mm:function(e){return l(e.getMinutes())},s:function(e){return e.getSeconds()},ss:function(e){return l(e.getSeconds())},S:function(e){return Math.round(e.getMilliseconds()/100)},SS:function(e){return l(Math.round(e.getMilliseconds()/10),2)},SSS:function(e){return l(e.getMilliseconds(),3)},a:function(e,t){return e.getHours()<12?t.amPm[0]:t.amPm[1]},A:function(e,t){return e.getHours()<12?t.amPm[0].toUpperCase():t.amPm[1].toUpperCase()},ZZ:function(e){var t=e.getTimezoneOffset();return(t>0?"-":"+")+l(100*Math.floor(Math.abs(t)/60)+Math.abs(t)%60,4)}},v={D:["\\d\\d?",function(e,t){e.day=t}],Do:["\\d\\d?"+i,function(e,t){e.day=parseInt(t,10)}],M:["\\d\\d?",function(e,t){e.month=t-1}],YY:["\\d\\d?",function(e,t){var n=+(""+(new Date).getFullYear()).substr(0,2);e.year=""+(t>68?n-1:n)+t}],h:["\\d\\d?",function(e,t){e.hour=t}],m:["\\d\\d?",function(e,t){e.minute=t}],s:["\\d\\d?",function(e,t){e.second=t}],YYYY:["\\d{4}",function(e,t){e.year=t}],S:["\\d",function(e,t){e.millisecond=100*t}],SS:["\\d{2}",function(e,t){e.millisecond=10*t}],SSS:["\\d{3}",function(e,t){e.millisecond=t}],d:["\\d\\d?",a],ddd:[i,a],MMM:[i,c("monthNamesShort")],MMMM:[i,c("monthNames")],a:[i,function(e,t,n){var r=t.toLowerCase();r===n.amPm[0]?e.isPm=!1:r===n.amPm[1]&&(e.isPm=!0)}],ZZ:["[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z",function(e,t){var n,r=(t+"").match(/([+-]|\d\d)/gi);r&&(n=60*r[1]+parseInt(r[2],10),e.timezoneOffset="+"===r[0]?n:-n)}]};v.dd=v.d,v.dddd=v.ddd,v.DD=v.D,v.mm=v.m,v.hh=v.H=v.HH=v.h,v.MM=v.M,v.ss=v.s,v.A=v.a,r.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"},r.format=function(e,t,n){var i=n||r.i18n;if("number"==typeof e&&(e=new Date(e)),"[object Date]"!==Object.prototype.toString.call(e)||isNaN(e.getTime()))throw new Error("Invalid Date in fecha.format");t=r.masks[t]||t||r.masks.default;var a=[];return(t=(t=t.replace(s,function(e,t){return a.push(t),"@@@"})).replace(o,function(t){return t in m?m[t](e,i):t.slice(1,t.length-1)})).replace(/@@@/g,function(){return a.shift()})},r.parse=function(e,t,n){var i=n||r.i18n;if("string"!=typeof t)throw new Error("Invalid format in fecha.parse");if(t=r.masks[t]||t,e.length>1e3)return null;var a={},u=[],c=[];t=t.replace(s,function(e,t){return c.push(t),"@@@"});var l,h=(l=t,l.replace(/[|\\{()[^$+*?.-]/g,"\\$&")).replace(o,function(e){if(v[e]){var t=v[e];return u.push(t[1]),"("+t[0]+")"}return e});h=h.replace(/@@@/g,function(){return c.shift()});var d=e.match(new RegExp(h,"i"));if(!d)return null;for(var f=1;f=0?"past":"future";o=Math.abs(o);for(var s=0;s0?t+":"+E(n)+":"+E(r):n>0?n+":"+E(r):r>0?""+r:null}function M(e){var t=g(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 T=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 i=Object.assign({},e._themes);if("default"!==o){var s=t.themes[o];Object.keys(s).forEach(function(t){var n="--"+t;e._themes[n]="",i[n]=s[t]})}if(e.updateStyles?e.updateStyles(i):window.ShadyCSS&&window.ShadyCSS.styleSubtree(e,i),r){var a=document.querySelector("meta[name=theme-color]");if(a){a.hasAttribute("default-content")||a.setAttribute("default-content",a.getAttribute("content"));var u=i["--primary-color"]||a.getAttribute("default-content");a.setAttribute("content",u)}}};function O(e){return e.substr(0,e.indexOf("."))}function C(e){return e.substr(e.indexOf(".")+1)}function Y(e){var t=e.language||"en";return e.translationMetadata.translations[t]&&e.translationMetadata.translations[t].isRTL||!1}function x(e){return Y(e)?"rtl":"ltr"}function L(e){return O(e.entity_id)}function F(e,t,n){var r,o=L(t);if("binary_sensor"===o)t.attributes.device_class&&(r=e("state."+o+"."+t.attributes.device_class+"."+t.state)),r||(r=e("state."+o+".default."+t.state));else if(t.attributes.unit_of_measurement&&!["unknown","unavailable"].includes(t.state))r=t.state+" "+t.attributes.unit_of_measurement;else if("input_datetime"===o){var i;if(t.attributes.has_time)if(t.attributes.has_date)i=new Date(t.attributes.year,t.attributes.month-1,t.attributes.day,t.attributes.hour,t.attributes.minute),r=w(i,n);else{var s=new Date;i=new Date(s.getFullYear(),s.getMonth(),s.getDay(),t.attributes.hour,t.attributes.minute),r=_(i,n)}else i=new Date(t.attributes.year,t.attributes.month-1,t.attributes.day),r=b(i,n)}else r="zwave"===o?["initializing","dead"].includes(t.state)?e("state.zwave.query_stage."+t.state,"query_stage",t.attributes.query_stage):e("state.zwave.default."+t.state):e("state."+o+"."+t.state);return r||(r=e("state.default."+t.state)||e("component."+o+".state."+t.state)||t.state),r}var R="hass:bookmark",N="lovelace",A=["climate","cover","configurator","input_select","input_number","input_text","lock","media_player","scene","script","timer","vacuum","water_heater","weblink"],H=["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"],I=["input_number","input_select","input_text","scene","weblink"],j=["camera","configurator","history_graph","scene"],q=["closed","locked","off"],U=new Set(["fan","input_boolean","light","switch","group","automation"]),z="°C",K="°F",Z="group.default_view",V=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},W=function(e){var t=function(e,t){return n("hui-error-card",{type:"error",error:e,config:t})},n=function(e,n){var r=window.document.createElement(e);try{r.setConfig(n)}catch(r){return console.error(e,r),t(r.message,n)}return r};if(!e||"object"!=typeof e||!e.type||!e.type.startsWith("custom:"))return t("No type configured",e);var r=e.type.substr("custom:".length);if(customElements.get(r))return n(r,e);var o=t("Custom element doesn't exist: "+e.type+".",e);o.style.display="None";var i=setTimeout(function(){o.style.display=""},2e3);return customElements.whenDefined(e.type).then(function(){clearTimeout(i),V(o,"ll-rebuild",{},o)}),o},B={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 J(e,t){if(e in B)return B[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+")"),R}}var G=function(e,t){V(e,"haptic",t)},X=function(e,t,n){void 0===n&&(n=!1),n?history.replaceState(null,"",t):history.pushState(null,"",t),V(window,"location-changed",{replace:n})},$=function(e,t,n){void 0===n&&(n=!0);var r,o=O(t),i="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(i,r,{entity_id:t})},Q=function(e,t){var n=q.includes(e.states[t].state);return $(e,t,n)},ee=function(e,t,n,r,o){var i;switch(o&&n.dbltap_action?i=n.dbltap_action:r&&n.hold_action?i=n.hold_action:!r&&n.tap_action&&(i=n.tap_action),i||(i={action:"more-info"}),i.action){case"more-info":(n.entity||n.camera_image)&&(V(e,"hass-more-info",{entityId:i.entity?i.entity:n.entity?n.entity:n.camera_image}),i.haptic&&G(e,i.haptic));break;case"navigate":i.navigation_path&&(X(0,i.navigation_path),i.haptic&&G(e,i.haptic));break;case"url":i.url&&window.open(i.url),i.haptic&&G(e,i.haptic);break;case"toggle":n.entity&&(Q(t,n.entity),i.haptic&&G(e,i.haptic));break;case"call-service":if(!i.service)return;var s=i.service.split(".",2),a=s[0],u=s[1],c=Object.assign({},i.service_data);"entity"===c.entity_id&&(c.entity_id=n.entity),t.callService(a,u,c),i.haptic&&G(e,i.haptic)}};function te(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}const ne=new WeakMap;String(Math.random()).slice(2);try{const e={get capture(){return!1}};window.addEventListener("test",e,e),window.removeEventListener("test",e,e)}catch(e){}(window.litHtmlVersions||(window.litHtmlVersions=[])).push("1.0.0");var re="ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0,oe=function(e){function t(){e.call(this),this.holdTime=500,this.ripple=document.createElement("paper-ripple"),this.timer=void 0,this.held=!1,this.cooldownStart=!1,this.cooldownEnd=!1,this.nbClicks=0}return e&&(t.__proto__=e),(t.prototype=Object.create(e&&e.prototype)).constructor=t,t.prototype.connectedCallback=function(){var e=this;Object.assign(this.style,{borderRadius:"50%",position:"absolute",width:re?"100px":"50px",height:re?"100px":"50px",transform:"translate(-50%, -50%)",pointerEvents:"none"}),this.appendChild(this.ripple),this.ripple.style.color="#03a9f4",this.ripple.style.color="var(--primary-color)",["touchcancel","mouseout","mouseup","touchmove","mousewheel","wheel","scroll"].forEach(function(t){document.addEventListener(t,function(){clearTimeout(e.timer),e.stopAnimation(),e.timer=void 0},{passive:!0})})},t.prototype.bind=function(e){var t=this;if(!e.longPress){e.longPress=!0,e.addEventListener("contextmenu",function(e){var t=e||window.event;return t.preventDefault&&t.preventDefault(),t.stopPropagation&&t.stopPropagation(),t.cancelBubble=!0,t.returnValue=!1,!1});var n=function(n){var r,o;t.cooldownStart||(t.held=!1,n.touches?(r=n.touches[0].pageX,o=n.touches[0].pageY):(r=n.pageX,o=n.pageY),t.timer=window.setTimeout(function(){t.startAnimation(r,o),t.held=!0,e.repeat&&!e.isRepeating&&(e.isRepeating=!0,t.repeatTimeout=setInterval(function(){e.dispatchEvent(new Event("ha-hold"))},e.repeat))},t.holdTime),t.cooldownStart=!0,window.setTimeout(function(){return t.cooldownStart=!1},100))},r=function(n){t.cooldownEnd||["touchend","touchcancel"].includes(n.type)&&void 0===t.timer?e.isRepeating&&t.repeatTimeout&&(clearInterval(t.repeatTimeout),e.isRepeating=!1):(clearTimeout(t.timer),e.isRepeating&&t.repeatTimeout&&clearInterval(t.repeatTimeout),e.isRepeating=!1,t.stopAnimation(),t.timer=void 0,t.held?e.repeat||e.dispatchEvent(new Event("ha-hold")):e.hasDblClick?0===t.nbClicks?(t.nbClicks+=1,t.dblClickTimeout=window.setTimeout(function(){1===t.nbClicks&&(t.nbClicks=0,e.dispatchEvent(new Event("ha-click")))},250)):(t.nbClicks=0,clearTimeout(t.dblClickTimeout),e.dispatchEvent(new Event("ha-dblclick"))):e.dispatchEvent(new Event("ha-click")),t.cooldownEnd=!0,window.setTimeout(function(){return t.cooldownEnd=!1},100))};e.addEventListener("touchstart",n,{passive:!0}),e.addEventListener("touchend",r),e.addEventListener("touchcancel",r),e.addEventListener("mousedown",n,{passive:!0}),e.addEventListener("click",r)}},t.prototype.startAnimation=function(e,t){Object.assign(this.style,{left:e+"px",top:t+"px",display:null}),this.ripple.holdDown=!0,this.ripple.simulatedRipple()},t.prototype.stopAnimation=function(){this.ripple.holdDown=!1,this.style.display="none"},t}(HTMLElement);customElements.get("long-press-custom-card-helpers")||customElements.define("long-press-custom-card-helpers",oe);var ie=function(e){var t=function(){var e=document.body;if(e.querySelector("long-press-custom-card-helpers"))return e.querySelector("long-press-custom-card-helpers");var t=document.createElement("long-press-custom-card-helpers");return e.appendChild(t),t}();t&&t.bind(e)},se=(e=>(...e)=>{const t=function(){return function(e){ie(e.committer.element)}}(...e);return ne.set(t,!0),t})(),ae=function(e,t,n){void 0===n&&(n=!0);var r={};t.forEach(function(t){if(q.includes(e.states[t].state)===n){var o=O(t),i=["cover","lock"].includes(o)?o:"homeassistant";i in r||(r[i]=[]),r[i].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]})})},ue=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}}]); \ 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=1)}([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 i=(e,t,n)=>{n&&setTimeout(()=>{e(),i(e,t,n-1)},t)};t.setIntervalNTimes=i;t.scaleElement=function(e,t,n){e.animations&&(t.style.transform="scale("+n+")")}},function(e,t,n){"use strict";var r,o=n(0),i=(r=n(2))&&r.__esModule?r:{default:r};customElements.whenDefined("card-tools").then(()=>{let e=customElements.get("card-tools");const t=customElements.get("ha-card");var n=Object.assign({},{enable_unsupported:!1,animations:!0},e.lovelace.config.deep_press);if("ontouchforcechange"in document==!1&&0==n.enable_unsupported)return;["touchend","mouseup"].forEach(e=>{document.addEventListener(e,()=>{(0,o.removeBlur)(),setTimeout(function(){(0,o.setModalBehaviour)(!0,!1)},100)})});const r=function(e){return e.config?e.config:e._config?e._config:e.host?r(e.host):e.parentElement?r(e.parentElement):e.parentNode?r(e.parentNode):null};var s=t.prototype.update;t.prototype.update=function(e){s.apply(this,e);const t=r(this);t&&t.deep_press&&t.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%; transition: all 2s ease-in-out; overflow: visible;"),this.appendChild(n),new i.default(n,this,e,t).init()}}.call(this,n,t)}}),console.info("%cdeep-press\n%cVersion: 2.0.0","color: green; font-weight: bold;","")},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var r,o=n(0),i=n(4),s=(r=n(3))&&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","click"].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),s.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("+s.default.map(e,.2,.5,0,10)+"px)",(0,o.scaleElement)(this.deep_press_config,this.parentElement,s.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,i.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,i;o=[],void 0===(i="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 i(t,r,o){return n(this,i),e(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,t,r,o))}return t(i,r),o(i,[{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}}]),i}(a),c=function(r){function i(t,r,o){return n(this,i),e(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,t,r,o))}return t(i,r),o(i,[{key:"bindEvents",value:function(){_?(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))}}]),i}(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;o3?0:(e-e%10!=10)*e%10]}};var m={D:function(e){return e.getDate()},DD:function(e){return l(e.getDate())},Do:function(e,t){return t.DoFn(e.getDate())},d:function(e){return e.getDay()},dd:function(e){return l(e.getDay())},ddd:function(e,t){return t.dayNamesShort[e.getDay()]},dddd:function(e,t){return t.dayNames[e.getDay()]},M:function(e){return e.getMonth()+1},MM:function(e){return l(e.getMonth()+1)},MMM:function(e,t){return t.monthNamesShort[e.getMonth()]},MMMM:function(e,t){return t.monthNames[e.getMonth()]},YY:function(e){return l(String(e.getFullYear()),4).substr(2)},YYYY:function(e){return l(e.getFullYear(),4)},h:function(e){return e.getHours()%12||12},hh:function(e){return l(e.getHours()%12||12)},H:function(e){return e.getHours()},HH:function(e){return l(e.getHours())},m:function(e){return e.getMinutes()},mm:function(e){return l(e.getMinutes())},s:function(e){return e.getSeconds()},ss:function(e){return l(e.getSeconds())},S:function(e){return Math.round(e.getMilliseconds()/100)},SS:function(e){return l(Math.round(e.getMilliseconds()/10),2)},SSS:function(e){return l(e.getMilliseconds(),3)},a:function(e,t){return e.getHours()<12?t.amPm[0]:t.amPm[1]},A:function(e,t){return e.getHours()<12?t.amPm[0].toUpperCase():t.amPm[1].toUpperCase()},ZZ:function(e){var t=e.getTimezoneOffset();return(t>0?"-":"+")+l(100*Math.floor(Math.abs(t)/60)+Math.abs(t)%60,4)}},v={D:["\\d\\d?",function(e,t){e.day=t}],Do:["\\d\\d?"+i,function(e,t){e.day=parseInt(t,10)}],M:["\\d\\d?",function(e,t){e.month=t-1}],YY:["\\d\\d?",function(e,t){var n=+(""+(new Date).getFullYear()).substr(0,2);e.year=""+(t>68?n-1:n)+t}],h:["\\d\\d?",function(e,t){e.hour=t}],m:["\\d\\d?",function(e,t){e.minute=t}],s:["\\d\\d?",function(e,t){e.second=t}],YYYY:["\\d{4}",function(e,t){e.year=t}],S:["\\d",function(e,t){e.millisecond=100*t}],SS:["\\d{2}",function(e,t){e.millisecond=10*t}],SSS:["\\d{3}",function(e,t){e.millisecond=t}],d:["\\d\\d?",a],ddd:[i,a],MMM:[i,c("monthNamesShort")],MMMM:[i,c("monthNames")],a:[i,function(e,t,n){var r=t.toLowerCase();r===n.amPm[0]?e.isPm=!1:r===n.amPm[1]&&(e.isPm=!0)}],ZZ:["[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z",function(e,t){var n,r=(t+"").match(/([+-]|\d\d)/gi);r&&(n=60*r[1]+parseInt(r[2],10),e.timezoneOffset="+"===r[0]?n:-n)}]};v.dd=v.d,v.dddd=v.ddd,v.DD=v.D,v.mm=v.m,v.hh=v.H=v.HH=v.h,v.MM=v.M,v.ss=v.s,v.A=v.a,r.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"},r.format=function(e,t,n){var i=n||r.i18n;if("number"==typeof e&&(e=new Date(e)),"[object Date]"!==Object.prototype.toString.call(e)||isNaN(e.getTime()))throw new Error("Invalid Date in fecha.format");t=r.masks[t]||t||r.masks.default;var a=[];return(t=(t=t.replace(s,function(e,t){return a.push(t),"@@@"})).replace(o,function(t){return t in m?m[t](e,i):t.slice(1,t.length-1)})).replace(/@@@/g,function(){return a.shift()})},r.parse=function(e,t,n){var i=n||r.i18n;if("string"!=typeof t)throw new Error("Invalid format in fecha.parse");if(t=r.masks[t]||t,e.length>1e3)return null;var a={},u=[],c=[];t=t.replace(s,function(e,t){return c.push(t),"@@@"});var l,h=(l=t,l.replace(/[|\\{()[^$+*?.-]/g,"\\$&")).replace(o,function(e){if(v[e]){var t=v[e];return u.push(t[1]),"("+t[0]+")"}return e});h=h.replace(/@@@/g,function(){return c.shift()});var d=e.match(new RegExp(h,"i"));if(!d)return null;for(var f=1;f=0?"past":"future";o=Math.abs(o);for(var s=0;s0?t+":"+D(n)+":"+D(r):n>0?n+":"+D(r):r>0?""+r:null}function M(e){var t=g(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 T=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 i=Object.assign({},e._themes);if("default"!==o){var s=t.themes[o];Object.keys(s).forEach(function(t){var n="--"+t;e._themes[n]="",i[n]=s[t]})}if(e.updateStyles?e.updateStyles(i):window.ShadyCSS&&window.ShadyCSS.styleSubtree(e,i),r){var a=document.querySelector("meta[name=theme-color]");if(a){a.hasAttribute("default-content")||a.setAttribute("default-content",a.getAttribute("content"));var u=i["--primary-color"]||a.getAttribute("default-content");a.setAttribute("content",u)}}},O=function(e){return"function"==typeof e.getCardSize?e.getCardSize():1};function Y(e){return e.substr(0,e.indexOf("."))}function C(e){return e.substr(e.indexOf(".")+1)}var x=function(e){return e.substr(e.indexOf(".")+1)};function N(e){var t=e.language||"en";return e.translationMetadata.translations[t]&&e.translationMetadata.translations[t].isRTL||!1}function R(e){return N(e)?"rtl":"ltr"}function F(e){return Y(e.entity_id)}function q(e,t,n){var r,o=F(t);if("binary_sensor"===o)t.attributes.device_class&&(r=e("state."+o+"."+t.attributes.device_class+"."+t.state)),r||(r=e("state."+o+".default."+t.state));else if(t.attributes.unit_of_measurement&&!["unknown","unavailable"].includes(t.state))r=t.state+" "+t.attributes.unit_of_measurement;else if("input_datetime"===o){var i;if(t.attributes.has_time)if(t.attributes.has_date)i=new Date(t.attributes.year,t.attributes.month-1,t.attributes.day,t.attributes.hour,t.attributes.minute),r=b(i,n);else{var s=new Date;i=new Date(s.getFullYear(),s.getMonth(),s.getDay(),t.attributes.hour,t.attributes.minute),r=w(i,n)}else i=new Date(t.attributes.year,t.attributes.month-1,t.attributes.day),r=_(i,n)}else r="zwave"===o?["initializing","dead"].includes(t.state)?e("state.zwave.query_stage."+t.state,"query_stage",t.attributes.query_stage):e("state.zwave.default."+t.state):e("state."+o+"."+t.state);return r||(r=e("state.default."+t.state)||e("component."+o+".state."+t.state)||t.state),r}var A=function(e){return void 0===e.attributes.friendly_name?x(e.entity_id).replace(/_/g," "):e.attributes.friendly_name||""},I="hass:bookmark",L="lovelace",H=["climate","cover","configurator","input_select","input_number","input_text","lock","media_player","scene","script","timer","vacuum","water_heater","weblink"],j=["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"],U=["input_number","input_select","input_text","scene","weblink"],z=["camera","configurator","history_graph","scene"],B=["closed","locked","off"],K=new Set(["fan","input_boolean","light","switch","group","automation"]),Z="°C",V="°F",W="group.default_view",J=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},G=new Set(["call-service","divider","section","weblink","cast","select"]),$={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"},Q=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(G.has(o))o="hui-"+o+"-row";else{if(!e.entity)return n("Invalid config given.",e);var i=e.entity.split(".",1)[0];o="hui-"+($[i]||"text")+"-entity-row"}else o="hui-"+o+"-card";if(customElements.get(o))return r(o,e);var s=n("Custom element doesn't exist: "+e.type+".",e);s.style.display="None";var a=setTimeout(function(){s.style.display=""},2e3);return customElements.whenDefined(e.type).then(function(){clearTimeout(a),J(s,"ll-rebuild",{},s)}),s},X={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 ee(e,t){if(e in X)return X[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+")"),I}}var te=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}},ne=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},re=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"))return e.shadowRoot},oe=function(e){J(window,"haptic",e)},ie=function(e,t,n){void 0===n&&(n=!1),n?history.replaceState(null,"",t):history.pushState(null,"",t),J(window,"location-changed",{replace:n})},se=function(e,t,n){void 0===n&&(n=!0);var r,o=Y(t),i="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(i,r,{entity_id:t})},ae=function(e,t){var n=B.includes(e.states[t].state);return se(e,t,n)},ue=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})||(oe("warning"),confirm(o.confirmation.text||"Are you sure you want to "+o.action+"?")))switch(o.action){case"more-info":(n.entity||n.camera_image)&&J(e,"hass-more-info",{entityId:n.entity?n.entity:n.camera_image});break;case"navigate":o.navigation_path&&ie(0,o.navigation_path);break;case"url":o.url_path&&window.open(o.url_path);break;case"toggle":n.entity&&(ae(t,n.entity),oe("success"));break;case"call-service":if(!o.service)return void oe("failure");var i=o.service.split(".",2);t.callService(i[0],i[1],o.service_data),oe("success")}},ce=function(e,t,n,r,o){var i;if(o&&n.double_tap_action?i=n.double_tap_action:r&&n.hold_action?i=n.hold_action:!r&&n.tap_action&&(i=n.tap_action),i||(i={action:"more-info"}),!i.confirmation||i.confirmation.exemptions&&i.confirmation.exemptions.some(function(e){return e.user===t.user.id})||confirm(i.confirmation.text||"Are you sure you want to "+i.action+"?"))switch(i.action){case"more-info":(n.entity||n.camera_image)&&(J(e,"hass-more-info",{entityId:i.entity?i.entity:n.entity?n.entity:n.camera_image}),i.haptic&&oe(i.haptic));break;case"navigate":i.navigation_path&&(ie(0,i.navigation_path),i.haptic&&oe(i.haptic));break;case"url":i.url_path&&window.open(i.url_path),i.haptic&&oe(i.haptic);break;case"toggle":n.entity&&(ae(t,n.entity),i.haptic&&oe(i.haptic));break;case"call-service":if(!i.service)return;var s=i.service.split(".",2),a=s[0],u=s[1],c=Object.assign({},i.service_data);"entity"===c.entity_id&&(c.entity_id=n.entity),t.callService(a,u,c),i.haptic&&oe(i.haptic)}};function le(e){return void 0!==e&&"none"!==e.action}function he(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 de(e){return void 0!==e&&"none"!==e.action}var fe=function(e,t,n){void 0===n&&(n=!0);var r={};t.forEach(function(t){if(B.includes(e.states[t].state)===n){var o=Y(t),i=["cover","lock"].includes(o)?o:"homeassistant";i in r||(r[i]=[]),r[i].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]})})}}]); \ No newline at end of file diff --git a/package.json b/package.json index c7e04bb..0a98ae5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "deep-press", - "version": "1.0.0", + "version": "2.0.0", "description": "Adds deep press (3D touch) to Lovelace cards", "main": "src/deep-press.js", "scripts": { @@ -25,6 +25,7 @@ "devDependencies": { "@babel/core": "^7.3.4", "@babel/plugin-transform-template-literals": "^7.2.0", + "@babel/plugin-proposal-class-properties": "^7.1.0", "@babel/preset-env": "^7.3.4", "babel-loader": "^8.0.5", "url-loader": "^1.1.2", @@ -32,7 +33,7 @@ "webpack-cli": "^3.3.6" }, "dependencies": { - "custom-card-helpers": "^1.2.2", + "custom-card-helpers": "^1.3.2", "pressure": "^2.1.2", "forceify": "latest" } diff --git a/src/deep-press.js b/src/deep-press.js index e9413d5..2b515a0 100644 --- a/src/deep-press.js +++ b/src/deep-press.js @@ -1,197 +1,85 @@ +import { + setModalBehaviour, + removeBlur, + getView, + scaleElement +} from './helpers' + import { handleClick } from 'custom-card-helpers'; import Pressure from 'pressure'; -customElements.whenDefined('card-tools').then(() => { - let cardTools = customElements.get('card-tools'); - const HaCard = customElements.get('ha-card'); +export default class DeepPress { + constructor(cover, root, deep_press_config, config) { + this.cover = cover; + this.root = root; + this.deep_press_config = deep_press_config; + this.config = config; + this.cover.deep_press_config = deep_press_config; + this.cover.config = config; - // Set global config - const defaults = { - enable_unsupported: false, - }; - var config = Object.assign({}, defaults, cardTools.lovelace.config.deep_press); - - if ('ontouchforcechange' in document === false && config.enable_unsupported == false) { - return; // disable if device doesnt support force-touch + this._upEvent = this.upEvent.bind(this); } - const setModalBehaviour = function (enable_clicks, retry) { - var modal = document.querySelector("body > home-assistant").shadowRoot.querySelector("ha-more-info-dialog"); - if (modal) { - if (enable_clicks) { - modal.noCancelOnOutsideClick = false; - modal.style.pointerEvents = "all"; - } else { - modal.noCancelOnOutsideClick = true; - modal.style.pointerEvents = "none"; - } - } else { - if (retry) { //retry once, needed for popup cards that load slowly - setTimeout(function () { - setModalBehaviour(enable_clicks, false); - }, 100); - } - } - }; - - const removeBlur = function () { - try { - 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") - .style.webkitFilter = 'blur(0px)'; - } catch (err) { - if (!(err instanceof TypeError)) { - throw err - } - } - }; - - [ - 'touchend', - 'mouseup', - ].forEach((ev) => { - document.addEventListener(ev, - () => { - removeBlur(); - setTimeout(function () { - setModalBehaviour(true, false); - }, 100); - } - ); - }); - - if ("ontouchstart" in document.documentElement) { - var clickEventList = [ - 'touchstart', + downEvent(event) { + // Listen for release events + [ 'touchend', - 'click' - ] - } else { - var clickEventList = [ - 'mousedown', 'mouseup', 'click' - ] - } - - const simulateClick = function (targetNode) { - function triggerEvent(targetNode, eventType) { - var clickEvent = document.createEvent('MouseEvents'); - clickEvent.initEvent(eventType, true, true); - targetNode.dispatchEvent(clickEvent); - } - clickEventList.forEach(function (eventType) { - triggerEvent(targetNode, eventType); - }); - }; + ].forEach(function (eventName) { + this.cover.addEventListener(eventName, this._upEvent, { passive: true }); + }, this); - const startEvent = function (root, event) { + this.down_event = 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 { - root.parentElement.dispatchEvent(new event.constructor(event.type, event)); + this.root.parentElement.dispatchEvent(new event.constructor(event.type, event)); } catch (TypeError) { - root.getRootNode().host.dispatchEvent(new event.constructor(event.type, event)); - } - - }; - - function _start() { - this.cancel = false; - this.event_over = false; - this.hold = false; - this.deep_press = false; - this.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"); - }; - - function _change(force) { - if (this.cancel || this.deep_press) { - return + this.root.getRootNode().host.dispatchEvent(new event.constructor(event.type, event)); } - if (force > 0.2) { - this.view.style.webkitFilter = 'blur(' + Pressure.map(force, 0.2, 0.5, 0, 10) + 'px)'; - this.hold = true; - }; - }; + } - function _deep(root) { - if (this.cancel) { - return - } - if (!this.deep_press) { - this.deep_press = true; - handleClick(root, cardTools.hass, root.config, true, false); - setModalBehaviour(false, true); - }; - }; + upEvent(event) { + scaleElement(this.deep_press_config, this.root, 1); + this.cover.removeEventListener(event.type, this._upEvent, { passive: true }); - function _end(root) { - if (this.cancel) { - return + 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)); + } + return; } - this.view.style.webkitFilter = 'blur(0px)'; - // If hold wasnt detected, simulate a click on the element to trigger default actions of the underlying card - if (!this.hold && !this.event_over) { - simulateClick(root); + if (event.type != 'click') { + this.root.dispatchEvent(new event.constructor(this.down_event.type, this.down_event)); }; - this.event_over = true; - this.hold = false; - this.deep_press = false; - }; - - function _cancel(event) { - this.cancel = true; - try { - this.view.style.webkitFilter = 'blur(0px)'; // Undefined at start - } catch (TypeError) { - } + this.root.dispatchEvent(new event.constructor(event.type, event)); + removeBlur(); } - const addCover = function (root, config) { - // Check if cover is already applied - if (root.querySelector(":scope >#deep-press-cover")) - return; - - root.config = config - // Create a cover which captures the deep press - root.cover = document.createElement("div"); - root.cover.setAttribute("id", "deep-press-cover"); - root.cover.setAttribute( - "style", - "position:absolute; top:0; left:0; width:100%; height: 100%;" - ); - root.appendChild(root.cover); + cancelEvent(event) { + this.cover.cancel = true; + scaleElement(this.deep_press_config, this.root, 1); + removeBlur(); + } - // Start events + init() { + // Down events [ 'touchstart', - 'mousedown', - 'click' + 'mousedown' ].forEach(function (eventName) { - root.cover.addEventListener(eventName, function (event) { startEvent.call(this, root, event); }, { passive: true }); - }); - - // End events - [ - 'touchend', - 'mouseup' - ].forEach(function (eventName) { - root.cover.addEventListener(eventName, function (event) { _end.call(this, root, event); }, { passive: true }); - }); + this.cover.addEventListener(eventName, this.downEvent.bind(this), { passive: true }); + }, this); // Canceling events [ @@ -202,56 +90,46 @@ customElements.whenDefined('card-tools').then(() => { 'wheel', 'scroll' ].forEach(function (eventName) { - root.cover.addEventListener(eventName, function (event) { _cancel.call(this, event); }, { passive: true }); - }); + this.cover.addEventListener(eventName, this.cancelEvent.bind(this), { passive: true }); + }, this); - Pressure.set(root.cover, { + Pressure.set(this.cover, { start: function (event) { - _start.call(this); + this.cancel = false; + this.event_over = false; + this.hold = false; + this.deep_press = false; + this.view = getView(); }, change: function (force, event) { - _change.call(this, force); + if (this.cancel || this.deep_press) { + return + } + if (force > 0.2) { + this.view.style.webkitFilter = 'blur(' + Pressure.map(force, 0.2, 0.5, 0, 10) + 'px)'; + scaleElement(this.deep_press_config, this.parentElement, Pressure.map(force, 0.2, 0.5, 1, 0.5)); + this.hold = true; + }; }, startDeepPress: function (event) { - _deep.call(this, root); + if (this.cancel) { + return + } + if (!this.deep_press) { + this.deep_press = true; + scaleElement(this.deep_press_config, this.parentElement, 1); + handleClick(this.parentElement, cardTools.hass, this.config, true, false); + setModalBehaviour(false, true); + removeBlur(); + }; }, end: function () { - _end.call(this, root) - this.view.style.webkitFilter = 'blur(0px)'; + scaleElement(this.deep_press_config, this.parentElement, 1); + removeBlur(); }, }); } - - const findConfig = function (node) { - if (node.config) - return node.config; - if (node._config) - return node._config; - if (node.host) - return findConfig(node.host); - if (node.parentElement) - return findConfig(node.parentElement); - if (node.parentNode) - return findConfig(node.parentNode); - return null; - }; - - var cached_update = HaCard.prototype.update; - HaCard.prototype.update = function (e) { - // Call the original update method, then create cover element - cached_update.apply(this, e); - const card_config = findConfig(this); - if (card_config && card_config.deep_press && card_config.hold_action) { - addCover(this, card_config); - } - }; -}); - -console.info( - `%cdeep-press\n%cVersion: 1.2.5`, - "color: green; font-weight: bold;", - "" -); +}; diff --git a/src/helpers.js b/src/helpers.js index 8e7fdc0..421beb1 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -17,17 +17,49 @@ export const setModalBehaviour = function (enable_clicks, retry) { } }; -export const removeBlur = function () { - try { - document.querySelector("body > home-assistant") +export const getView = 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") - .style.webkitFilter = 'blur(0px)'; + .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"); +} + +export const removeBlur = function () { + try { + getView().style.webkitFilter = 'blur(0px)'; } catch (err) { if (!(err instanceof TypeError)) { throw err } } }; + +export const setIntervalNTimes = (fn, delay, times) => { + if (!times) return; + + setTimeout(() => { + fn(); + setIntervalNTimes(fn, delay, times - 1) + }, delay); +}; + + +export const scaleElement = function (config, element, scale) { + if (config.animations) { + element.style.transform = "scale(" + scale + ")"; + }; +}; diff --git a/src/main.js b/src/main.js index 892214d..9dc3d86 100644 --- a/src/main.js +++ b/src/main.js @@ -1,6 +1,6 @@ import { setModalBehaviour, - removeBlur + removeBlur, } from './helpers' import DeepPress from './deep-press' @@ -12,10 +12,11 @@ customElements.whenDefined('card-tools').then(() => { // Set global config const defaults = { enable_unsupported: false, + animations: true, }; - var config = Object.assign({}, defaults, cardTools.lovelace.config.deep_press); + var deep_press_config = Object.assign({}, defaults, cardTools.lovelace.config.deep_press); - if ('ontouchforcechange' in document === false && config.enable_unsupported == false) { + if ('ontouchforcechange' in document === false && deep_press_config.enable_unsupported == false) { return; // disable if device doesnt support force-touch } @@ -47,7 +48,7 @@ customElements.whenDefined('card-tools').then(() => { return null; }; - function addCover(config) { + function addCover(deep_press_config, card_config) { // Check if cover is already applied if (this.querySelector(":scope >#deep-press-cover")) return; @@ -57,11 +58,12 @@ customElements.whenDefined('card-tools').then(() => { cover.setAttribute("id", "deep-press-cover"); cover.setAttribute( "style", - "position:absolute; top:0; left:0; width:100%; height: 100%;" + "position:absolute; top:0; left:0; width:100%; height: 100%; transition: all 2s ease-in-out; overflow: visible;" ); this.appendChild(cover); - DeepPress.init.call(cover, this, config); + var deepPress = new DeepPress(cover, this, deep_press_config, card_config); + deepPress.init(); }; var cached_update = HaCard.prototype.update; @@ -70,13 +72,13 @@ customElements.whenDefined('card-tools').then(() => { cached_update.apply(this, e); const card_config = findConfig(this); if (card_config && card_config.deep_press && card_config.hold_action) { - addCover.call(this, card_config); + addCover.call(this, deep_press_config, card_config); }; }; }); console.info( - `%cdeep-press\n%cVersion: 1.2.5`, + `%cdeep-press\n%cVersion: 2.0.0`, "color: green; font-weight: bold;", "" );