diff --git a/src/folk-shape.ts b/src/folk-shape.ts index 3c9041b..5411c64 100644 --- a/src/folk-shape.ts +++ b/src/folk-shape.ts @@ -169,10 +169,13 @@ export class FolkShape extends HTMLElement { #shadow = this.attachShadow({ mode: 'open' }); #internals = this.attachInternals(); #dynamicStyles = css``; - #autoContentRect = this.getBoundingClientRect(); + #attrWidth: Dimension = 0; #attrHeight: Dimension = 0; + #rect = new TransformDOMRect(); + #previousRect = new TransformDOMRect(); + // Used for rotation handling, would love a better way to do this that avoids this clutter. #initialRotation = 0; #startAngle = 0; @@ -182,7 +185,6 @@ export class FolkShape extends HTMLElement { } set x(x) { - if (this.#rect.x === x) return; this.#previousRect.x = this.#rect.x; this.#rect.x = x; this.#requestUpdate(); @@ -193,43 +195,40 @@ export class FolkShape extends HTMLElement { } set y(y) { - if (this.#rect.y === y) return; this.#previousRect.y = this.#rect.y; this.#rect.y = y; this.#requestUpdate(); } get width(): number { - if (this.#attrWidth === 'auto') { - return this.#autoContentRect.width; - } return this.#rect.width; } set width(width: Dimension) { - if (this.#attrWidth === width) return; if (width === 'auto') { resizeObserver.observe(this, this.#onAutoResize); } else if (this.#attrWidth === 'auto' && this.#attrHeight !== 'auto') { resizeObserver.unobserve(this, this.#onAutoResize); + } else { + this.#previousRect.width = this.#rect.width; + this.#rect.width = width; } this.#attrWidth = width; this.#requestUpdate(); } get height(): number { - if (this.#attrHeight === 'auto') { - return this.#autoContentRect.height; - } - return this.#attrHeight; + return this.#rect.height; } set height(height: Dimension) { - if (this.#attrHeight === height) return; if (height === 'auto') { resizeObserver.observe(this, this.#onAutoResize); } else if (this.#attrHeight === 'auto' && this.#attrWidth !== 'auto') { resizeObserver.unobserve(this, this.#onAutoResize); + } else { + this.#previousRect.height = this.#rect.height; + this.#rect.height = height; } this.#attrHeight = height; @@ -241,15 +240,11 @@ export class FolkShape extends HTMLElement { } set rotation(rotation: number) { - if (this.#rect.rotation === rotation) return; this.#previousRect.rotation = this.#rect.rotation; this.#rect.rotation = rotation; this.#requestUpdate(); } - #rect: TransformDOMRect; - #previousRect: TransformDOMRect; - constructor() { super(); @@ -270,16 +265,11 @@ export class FolkShape extends HTMLElement {