UNPKG

@progress/kendo-angular-common

Version:

Kendo UI for Angular - Utility Package

66 lines (65 loc) 2.14 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ import { EventEmitter } from '@angular/core'; import { isDocumentAvailable } from '../utils'; export class ResizeService { resizeBatchService; resize = new EventEmitter(); acceptedSize = false; lastWidth; lastHeight; state = 0 /* ServiceState.Initial */; parentElement; constructor(resizeBatchService) { this.resizeBatchService = resizeBatchService; } acceptSize(size = this.measure()) { this.lastWidth = size.width; this.lastHeight = size.height; this.acceptedSize = true; } checkChanges() { if (!isDocumentAvailable()) { return; } if (this.state === 0 /* ServiceState.Initial */) { this.state = 1 /* ServiceState.Initializing */; // batch initial measure this.resizeBatchService.schedule(this, this.init); } } destroy() { this.resizeBatchService.cancel(this); } checkSize() { if (!this.parentElement) { return false; } const { width, height } = this.measure(); const sameSize = width === this.lastWidth && height === this.lastHeight; if (sameSize) { return false; } this.lastWidth = width; this.lastHeight = height; this.acceptedSize = false; this.resize.emit({ width, height }); return true; } initSize() { const size = this.measure(); this.lastWidth = size.width; this.lastHeight = size.height; } measure() { let width = 0; let height = 0; if (this.parentElement) { height = this.parentElement.offsetHeight; width = this.parentElement.offsetWidth; } return { height, width }; } }