import Moveable from "lit-moveable"; import { LitElement, html } from "lit"; import { customElement, property } from "lit/decorators.js"; import { ref, createRef } from "lit/directives/ref.js"; @customElement("lit-app") export default class App extends LitElement { resizable: any = "$preview_resizable"; keepRatio: any = "$preview_keepRatio"; throttleResize: any = "$preview_throttleResize"; renderDirections: any = "$preview_renderDirections"; widthInputRef: Ref = createRef(null); heightInputRef: Ref = createRef(null); moveableRef: Ref = createRef(null); onInput: any = (e: any) => { const ev = (e.nativeEvent || e) as InputEvent; if (typeof ev.data === "undefined") { this.moveableRef.value!.request("resizable", { offsetWidth: parseFloat(this.widthInputRef.value!.value), offsetHeight: parseFloat(this.heightInputRef.value!.value) }, true); } }; onKeyUp: any = (e: any) => { e.stopPropagation(); if (e.keyCode === 13) { this.moveableRef.value!.request("resizable", { offsetWidth: parseFloat(this.widthInputRef.value!.value), offsetHeight: parseFloat(this.heightInputRef.value!.value) }, true); } }; render() { return html `
width:   height:
Target1
`; } onResize(e) { e.target.style.width = `${e.width}px`; e.target.style.height = `${e.height}px`; e.target.style.transform = e.drag.transform; } onResizeEnd(e) { requestAnimationFrame(() => { const rect = e.moveable.getRect(); this.widthInputRef.value!.value = `${rect.offsetWidth}`; this.heightInputRef.value!.value = `${rect.offsetHeight}`; }); } }