Simplify positioned style computation

This commit is contained in:
barsdeveloper
2022-10-18 20:25:42 +02:00
parent e8a35c81d0
commit 14d376d447
13 changed files with 127 additions and 133 deletions

View File

@@ -11,17 +11,25 @@ export default class IFromToPositionedTemplate extends ITemplate {
/** @param {Map} changedProperties */
update(changedProperties) {
super.update(changedProperties)
if (changedProperties.has("initialPositionX")) {
this.element.style.setProperty("--ueb-from-x", `${Math.round(this.element.initialPositionX)}`)
const [fromX, fromY, toX, toY] = [
Math.round(this.element.fromX),
Math.round(this.element.fromY),
Math.round(this.element.toX),
Math.round(this.element.toY),
]
const [left, top, width, height] = [
Math.min(fromX, toX),
Math.min(fromY, toY),
Math.abs(fromX - toX),
Math.abs(fromY - toY),
]
if (changedProperties.has("fromX") || changedProperties.has("toX")) {
this.element.style.left = `${left}px`
this.element.style.width = `${width}px`
}
if (changedProperties.has("initialPositionY")) {
this.element.style.setProperty("--ueb-from-y", `${Math.round(this.element.initialPositionY)}`)
}
if (changedProperties.has("finaPositionX")) {
this.element.style.setProperty("--ueb-to-x", `${Math.round(this.element.finaPositionX)}`)
}
if (changedProperties.has("finaPositionY")) {
this.element.style.setProperty("--ueb-to-y", `${Math.round(this.element.finaPositionY)}`)
if (changedProperties.has("fromY") || changedProperties.has("toY")) {
this.element.style.top = `${top}px`
this.element.style.height = `${height}px`
}
}