UNPKG

@synergy-design-system/components

Version:

This package provides the base of the Synergy Design System as native web components. It uses [lit](https://www.lit.dev) and parts of [shoelace](https://shoelace.style/). Synergy officially supports the latest two versions of all major browsers (as define

82 lines (79 loc) 2.12 kB
import { resize_observer_styles_default } from "./chunk.OI3HOOCT.js"; import { watch } from "./chunk.BVZQ6QSY.js"; import { component_styles_default } from "./chunk.NLYVOJGK.js"; import { SynergyElement } from "./chunk.3THJTCRO.js"; import { __decorateClass } from "./chunk.Z4XV3SMG.js"; // src/components/resize-observer/resize-observer.component.ts import { html } from "lit"; import { property } from "lit/decorators.js"; var SynResizeObserver = class extends SynergyElement { constructor() { super(...arguments); this.observedElements = []; this.disabled = false; } connectedCallback() { super.connectedCallback(); this.resizeObserver = new ResizeObserver((entries) => { this.emit("syn-resize", { detail: { entries } }); }); if (!this.disabled) { this.startObserver(); } } disconnectedCallback() { super.disconnectedCallback(); this.stopObserver(); } handleSlotChange() { if (!this.disabled) { this.startObserver(); } } startObserver() { const slot = this.shadowRoot.querySelector("slot"); if (slot !== null) { const elements = slot.assignedElements({ flatten: true }); this.observedElements.forEach((el) => this.resizeObserver.unobserve(el)); this.observedElements = []; elements.forEach((el) => { this.resizeObserver.observe(el); this.observedElements.push(el); }); } } stopObserver() { this.resizeObserver.disconnect(); } handleDisabledChange() { if (this.disabled) { this.stopObserver(); } else { this.startObserver(); } } render() { return html` <slot @slotchange=${this.handleSlotChange}></slot> `; } }; SynResizeObserver.styles = [component_styles_default, resize_observer_styles_default]; __decorateClass([ property({ type: Boolean, reflect: true }) ], SynResizeObserver.prototype, "disabled", 2); __decorateClass([ watch("disabled", { waitUntilFirstUpdate: true }) ], SynResizeObserver.prototype, "handleDisabledChange", 1); export { SynResizeObserver }; //# sourceMappingURL=chunk.IDRBXAJB.js.map