From 2a83c5f174ca499ff8ac5a20635880d0417fc62a Mon Sep 17 00:00:00 2001 From: Nerwyn Singh Date: Sat, 23 Mar 2024 20:10:15 -0400 Subject: [PATCH] onEnd only call onclick center action handler if no targetTouches, and set hold back to true if there are targetTouches --- dist/android-tv-card.min.js | 2 +- src/classes/remote-touchpad.ts | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/dist/android-tv-card.min.js b/dist/android-tv-card.min.js index 2fee0d4b..6d92be70 100644 --- a/dist/android-tv-card.min.js +++ b/dist/android-tv-card.min.js @@ -283,7 +283,7 @@ opacity: 1; transition: opacity 540ms ease-in-out 0s; } - `}};e.RemoteSlider=l,i([(0,o.state)()],l.prototype,"getValueFromHass",void 0),i([(0,o.state)()],l.prototype,"showTooltip",void 0),i([(0,o.state)()],l.prototype,"sliderOn",void 0),i([(0,o.state)()],l.prototype,"currentValue",void 0),e.RemoteSlider=l=i([(0,o.customElement)("remote-slider")],l)},4448:function(t,e,n){"use strict";var i=this&&this.__decorate||function(t,e,n,i){var r,o=arguments.length,s=o<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,n,i);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(s=(o<3?r(s):o>3?r(e,n,s):r(e,n))||s);return o>3&&s&&Object.defineProperty(e,n,s),s};Object.defineProperty(e,"__esModule",{value:!0}),e.RemoteTextbox=void 0;const r=n(5595),o=n(839),s=n(5032);let a=class extends s.BaseKeyboardElement{onEnd(t){if(!this.holdMove){t.stopImmediatePropagation();const e=prompt("Text Input: ");if(e){const t={entity_id:(0,o.renderTemplate)(this.hass,this.keyboardId)};"KODI"===(0,o.renderTemplate)(this.hass,this.keyboardMode).toUpperCase()?(t.method="Input.SendText",t.text=e,t.done=!1,this.hass.callService("kodi","call_method",t)):(t.command=`input text "${e}"`,this.hass.callService("androidtv","adb_command",t))}}}};e.RemoteTextbox=a,e.RemoteTextbox=a=i([(0,r.customElement)("remote-textbox")],a)},3857:function(t,e,n){"use strict";var i=this&&this.__decorate||function(t,e,n,i){var r,o=arguments.length,s=o<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,n,i);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(s=(o<3?r(s):o>3?r(e,n,s):r(e,n))||s);return o>3&&s&&Object.defineProperty(e,n,s),s};Object.defineProperty(e,"__esModule",{value:!0}),e.RemoteTouchpad=void 0;const r=n(1814),o=n(5595),s=n(8921),a=n(9263),c=n(839),l=n(8666);let u=class extends l.BaseRemoteElement{constructor(){super(...arguments),this._rippleHandlers=new a.RippleHandlers((()=>this._ripple)),this.clickCount=0,this.hold=!1,this.holdStart=!1,this.holdMove=!1}onClick(t){var e,n;t.stopImmediatePropagation(),this.clickCount++;const i=(null===(e=this.targetTouches)||void 0===e?void 0:e.length)||1;if("double_tap_action"in this.actions&&"none"!=(0,c.renderTemplate)(this.hass,this.actions.double_tap_action.action)||"multi_double_tap_action"in this.actions&&"none"!=(0,c.renderTemplate)(this.hass,this.actions.multi_double_tap_action.action)){const t=`${this.getMultiPrefix()}double_tap_action`;if(this.clickCount>i)this.fireHapticEvent("success"),this.sendAction(t),this.endAction();else if(!this.clickTimer){const e="double_tap_window"in(null!==(n=this.actions[t])&&void 0!==n?n:{})?(0,c.renderTemplate)(this.hass,this.actions[t].double_tap_window):200;this.clickTimer=setTimeout((()=>{this.fireHapticEvent("light"),this.sendAction(`${this.getMultiPrefix()}tap_action`),this.endAction()}),e)}}else this.fireHapticEvent("light"),this.sendAction(`${this.getMultiPrefix()}tap_action`),this.endAction()}onStart(t){if(this._rippleHandlers.startPress(t),this.holdStart=!0,!this.holdAction&&"momentary_start_action"in this.actions&&"none"!=(0,c.renderTemplate)(this.hass,this.actions.momentary_start_action.action)?(this.fireHapticEvent("light"),this.buttonPressStart=performance.now(),this.sendAction("momentary_start_action")):!this.holdAction&&"momentary_end_action"in this.actions&&"none"!=(0,c.renderTemplate)(this.hass,this.actions.momentary_end_action.action)?(this.fireHapticEvent("light"),this.buttonPressStart=performance.now()):this.holdTimer||this.setHoldTimer(),"targetTouches"in t){let e=0,n=0;this.targetTouches=t.targetTouches;for(const t of this.targetTouches)e+=t.clientX,n+=t.clientY;this.initialX=e/this.targetTouches.length,this.initialY=n/this.targetTouches.length}else this.initialX=t.clientX,this.initialY=t.clientY}onEnd(t){this._rippleHandlers.endPress(),!this.holdAction&&"momentary_end_action"in this.actions&&"none"!=(0,c.renderTemplate)(this.hass,this.actions.momentary_end_action.action)?(this.buttonPressEnd=performance.now(),this.fireHapticEvent("selection"),this.sendAction("momentary_end_action"),this.endAction()):!this.holdAction&&"momentary_start_action"in this.actions&&"none"!=(0,c.renderTemplate)(this.hass,this.actions.momentary_start_action.action)?this.endAction():this.hold||this.holdMove?(t.stopImmediatePropagation(),t.preventDefault(),this.endAction()):"targetTouches"in t&&t.targetTouches.length||this.onClick(t)}onMove(t){if(!this.initialX||!this.initialY||!this.holdStart)return;let e=0,n=0;if("targetTouches"in t){this.targetTouches=t.targetTouches;for(const t of this.targetTouches)e+=t.clientX,n+=t.clientY;e/=this.targetTouches.length,n/=this.targetTouches.length}else e=t.clientX||0,n=t.clientY||0;const i=this.initialX-e,r=this.initialY-n;Math.abs(Math.abs(i)-Math.abs(r))>2&&(Math.abs(i)>Math.abs(r)?this.holdAction=i>0?"left":"right":this.holdAction=r>0?"up":"down",this.holdMove||(this.fireHapticEvent("light"),this.sendAction(`${this.getMultiPrefix()}tap_action`,this.getActions()),this.holdMove=!0,this.holdTimer&&(clearTimeout(this.holdTimer),this.holdTimer=void 0,this.setHoldTimer())))}onMouseLeave(t){this._rippleHandlers.endHover(),this.endAction()}onTouchCancel(t){this._rippleHandlers.endPress(),this.endAction()}endAction(){clearTimeout(this.holdTimer),clearInterval(this.holdInterval),clearTimeout(this.clickTimer),this.holdTimer=void 0,this.holdInterval=void 0,this.clickTimer=void 0,this.hold=!1,this.holdStart=!1,this.holdMove=!1,this.holdAction=void 0,this.clickCount=0,this.initialX=void 0,this.initialY=void 0,this.targetTouches=void 0,super.endAction()}getActions(){return this.holdAction?this.directionActions[this.holdAction]:this.actions}getMultiPrefix(){return this.targetTouches&&this.targetTouches.length>1?"multi_":""}setHoldTimer(){var t;const e=`${this.getMultiPrefix()}hold_action`,n=this.getActions(),i="hold_time"in(null!==(t=n[e])&&void 0!==t?t:{})?(0,c.renderTemplate)(this.hass,n[e].hold_time):500;this.holdTimer=setTimeout((()=>{var t,e,n,i;this.hold=!0;const r=this.getActions(),o=this.getMultiPrefix();let s="repeat"==(0,c.renderTemplate)(this.hass,null===(t=r.hold_action)||void 0===t?void 0:t.action),a="repeat_delay"in(null!==(e=r.hold_action)&&void 0!==e?e:{})?(0,c.renderTemplate)(this.hass,r.hold_action.repeat_delay):100;"multi_"==o&&"multi_hold_action"in r&&(s="repeat"==(0,c.renderTemplate)(this.hass,null===(n=r.multi_hold_action)||void 0===n?void 0:n.action),a="repeat_delay"in(null!==(i=r.multi_hold_action)&&void 0!==i?i:{})?(0,c.renderTemplate)(this.hass,r.multi_hold_action.repeat_delay):100),s?this.holdInterval||(this.holdInterval=setInterval((()=>{this.fireHapticEvent("selection"),this.sendAction(`${this.getMultiPrefix()}tap_action`,this.getActions())}),a)):(this.fireHapticEvent("medium"),this.sendAction(`${this.getMultiPrefix()}hold_action`,r))}),i)}render(){var t;const e=structuredClone(null!==(t=this.actions.style)&&void 0!==t?t:{});for(const t in e)e[t]=(0,c.renderTemplate)(this.hass,e[t]);return r.html` + `}};e.RemoteSlider=l,i([(0,o.state)()],l.prototype,"getValueFromHass",void 0),i([(0,o.state)()],l.prototype,"showTooltip",void 0),i([(0,o.state)()],l.prototype,"sliderOn",void 0),i([(0,o.state)()],l.prototype,"currentValue",void 0),e.RemoteSlider=l=i([(0,o.customElement)("remote-slider")],l)},4448:function(t,e,n){"use strict";var i=this&&this.__decorate||function(t,e,n,i){var r,o=arguments.length,s=o<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,n,i);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(s=(o<3?r(s):o>3?r(e,n,s):r(e,n))||s);return o>3&&s&&Object.defineProperty(e,n,s),s};Object.defineProperty(e,"__esModule",{value:!0}),e.RemoteTextbox=void 0;const r=n(5595),o=n(839),s=n(5032);let a=class extends s.BaseKeyboardElement{onEnd(t){if(!this.holdMove){t.stopImmediatePropagation();const e=prompt("Text Input: ");if(e){const t={entity_id:(0,o.renderTemplate)(this.hass,this.keyboardId)};"KODI"===(0,o.renderTemplate)(this.hass,this.keyboardMode).toUpperCase()?(t.method="Input.SendText",t.text=e,t.done=!1,this.hass.callService("kodi","call_method",t)):(t.command=`input text "${e}"`,this.hass.callService("androidtv","adb_command",t))}}}};e.RemoteTextbox=a,e.RemoteTextbox=a=i([(0,r.customElement)("remote-textbox")],a)},3857:function(t,e,n){"use strict";var i=this&&this.__decorate||function(t,e,n,i){var r,o=arguments.length,s=o<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,n,i);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(s=(o<3?r(s):o>3?r(e,n,s):r(e,n))||s);return o>3&&s&&Object.defineProperty(e,n,s),s};Object.defineProperty(e,"__esModule",{value:!0}),e.RemoteTouchpad=void 0;const r=n(1814),o=n(5595),s=n(8921),a=n(9263),c=n(839),l=n(8666);let u=class extends l.BaseRemoteElement{constructor(){super(...arguments),this._rippleHandlers=new a.RippleHandlers((()=>this._ripple)),this.clickCount=0,this.hold=!1,this.holdStart=!1,this.holdMove=!1}onClick(t){var e,n;t.stopImmediatePropagation(),this.clickCount++;const i=(null===(e=this.targetTouches)||void 0===e?void 0:e.length)||1;if("double_tap_action"in this.actions&&"none"!=(0,c.renderTemplate)(this.hass,this.actions.double_tap_action.action)||"multi_double_tap_action"in this.actions&&"none"!=(0,c.renderTemplate)(this.hass,this.actions.multi_double_tap_action.action)){const t=`${this.getMultiPrefix()}double_tap_action`;if(this.clickCount>i)this.fireHapticEvent("success"),this.sendAction(t),this.endAction();else if(!this.clickTimer){const e="double_tap_window"in(null!==(n=this.actions[t])&&void 0!==n?n:{})?(0,c.renderTemplate)(this.hass,this.actions[t].double_tap_window):200;this.clickTimer=setTimeout((()=>{this.fireHapticEvent("light"),this.sendAction(`${this.getMultiPrefix()}tap_action`),this.endAction()}),e)}}else this.fireHapticEvent("light"),this.sendAction(`${this.getMultiPrefix()}tap_action`),this.endAction()}onStart(t){if(this._rippleHandlers.startPress(t),this.holdStart=!0,!this.holdAction&&"momentary_start_action"in this.actions&&"none"!=(0,c.renderTemplate)(this.hass,this.actions.momentary_start_action.action)?(this.fireHapticEvent("light"),this.buttonPressStart=performance.now(),this.sendAction("momentary_start_action")):!this.holdAction&&"momentary_end_action"in this.actions&&"none"!=(0,c.renderTemplate)(this.hass,this.actions.momentary_end_action.action)?(this.fireHapticEvent("light"),this.buttonPressStart=performance.now()):this.holdTimer||this.setHoldTimer(),"targetTouches"in t){let e=0,n=0;this.targetTouches=t.targetTouches;for(const t of this.targetTouches)e+=t.clientX,n+=t.clientY;this.initialX=e/this.targetTouches.length,this.initialY=n/this.targetTouches.length}else this.initialX=t.clientX,this.initialY=t.clientY}onEnd(t){this._rippleHandlers.endPress(),!this.holdAction&&"momentary_end_action"in this.actions&&"none"!=(0,c.renderTemplate)(this.hass,this.actions.momentary_end_action.action)?(this.buttonPressEnd=performance.now(),this.fireHapticEvent("selection"),this.sendAction("momentary_end_action"),this.endAction()):!this.holdAction&&"momentary_start_action"in this.actions&&"none"!=(0,c.renderTemplate)(this.hass,this.actions.momentary_start_action.action)?this.endAction():this.hold||this.holdMove?(t.stopImmediatePropagation(),t.preventDefault(),this.endAction(),"targetTouches"in t&&t.targetTouches.length&&(this.hold=!0)):"targetTouches"in t&&t.targetTouches.length||this.onClick(t)}onMove(t){if(!this.initialX||!this.initialY||!this.holdStart)return;let e=0,n=0;if("targetTouches"in t){this.targetTouches=t.targetTouches;for(const t of this.targetTouches)e+=t.clientX,n+=t.clientY;e/=this.targetTouches.length,n/=this.targetTouches.length}else e=t.clientX||0,n=t.clientY||0;const i=this.initialX-e,r=this.initialY-n;Math.abs(Math.abs(i)-Math.abs(r))>2&&(Math.abs(i)>Math.abs(r)?this.holdAction=i>0?"left":"right":this.holdAction=r>0?"up":"down",this.holdMove||(this.fireHapticEvent("light"),this.sendAction(`${this.getMultiPrefix()}tap_action`,this.getActions()),this.holdMove=!0,this.holdTimer&&(clearTimeout(this.holdTimer),this.holdTimer=void 0,this.setHoldTimer())))}onMouseLeave(t){this._rippleHandlers.endHover(),this.endAction()}onTouchCancel(t){this._rippleHandlers.endPress(),this.endAction()}endAction(){clearTimeout(this.holdTimer),clearInterval(this.holdInterval),clearTimeout(this.clickTimer),this.holdTimer=void 0,this.holdInterval=void 0,this.clickTimer=void 0,this.hold=!1,this.holdStart=!1,this.holdMove=!1,this.holdAction=void 0,this.clickCount=0,this.initialX=void 0,this.initialY=void 0,this.targetTouches=void 0,super.endAction()}getActions(){return this.holdAction?this.directionActions[this.holdAction]:this.actions}getMultiPrefix(){return this.targetTouches&&this.targetTouches.length>1?"multi_":""}setHoldTimer(){var t;const e=`${this.getMultiPrefix()}hold_action`,n=this.getActions(),i="hold_time"in(null!==(t=n[e])&&void 0!==t?t:{})?(0,c.renderTemplate)(this.hass,n[e].hold_time):500;this.holdTimer=setTimeout((()=>{var t,e,n,i;this.hold=!0;const r=this.getActions(),o=this.getMultiPrefix();let s="repeat"==(0,c.renderTemplate)(this.hass,null===(t=r.hold_action)||void 0===t?void 0:t.action),a="repeat_delay"in(null!==(e=r.hold_action)&&void 0!==e?e:{})?(0,c.renderTemplate)(this.hass,r.hold_action.repeat_delay):100;"multi_"==o&&"multi_hold_action"in r&&(s="repeat"==(0,c.renderTemplate)(this.hass,null===(n=r.multi_hold_action)||void 0===n?void 0:n.action),a="repeat_delay"in(null!==(i=r.multi_hold_action)&&void 0!==i?i:{})?(0,c.renderTemplate)(this.hass,r.multi_hold_action.repeat_delay):100),s?this.holdInterval||(this.holdInterval=setInterval((()=>{this.fireHapticEvent("selection"),this.sendAction(`${this.getMultiPrefix()}tap_action`,this.getActions())}),a)):(this.fireHapticEvent("medium"),this.sendAction(`${this.getMultiPrefix()}hold_action`,r))}),i)}render(){var t;const e=structuredClone(null!==(t=this.actions.style)&&void 0!==t?t:{});for(const t in e)e[t]=(0,c.renderTemplate)(this.hass,e[t]);return r.html`