diff --git a/src/web/components/button.ts b/src/web/components/button.ts index e160fa8..849c735 100644 --- a/src/web/components/button.ts +++ b/src/web/components/button.ts @@ -1,5 +1,5 @@ import {LitElement, html, css} from "lit"; -import {customElement, property, state} from "lit/decorators.js"; +import {customElement, property, query, state} from "lit/decorators.js"; import withSharedStyles from "../theme"; @@ -11,20 +11,48 @@ export default class NyanoButton extends LitElement { @state() private pressed = false; + @query("#btn") + private btn: HTMLButtonElement; + protected render() { return html` `; } + private handleMouseDown(e: MouseEvent) { + this.updateTransformOrigin(e); + this.btn.addEventListener("mousemove", this.updateTransformOrigin); + this.pressed = true; + } + + private handleMouseLeave() { + this.pressed = false; + this.btn.removeEventListener("mousemove", this.updateTransformOrigin); + } + + private updateTransformOrigin = (e: MouseEvent) => { + const rect = this.btn.getBoundingClientRect(); + const center = { + x: rect.width / 2, + y: rect.height / 2, + }; + const origin = { + x: center.x + (e.clientX - rect.x - center.x) / 2, + y: center.y + (e.clientY - rect.y - center.y) / 2, + }; + this.btn.style.transformOrigin = `${origin.x}px ${origin.y}px`; + } + static get styles() { return withSharedStyles(css` :host {