mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-04 08:28:17 +08:00
Simplify positioned style computation
This commit is contained in:
@@ -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`
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user