UNPKG

@microsoft/sp-webpart-base

Version:

SharePoint Framework support for building web parts

54 lines 2.26 kB
/** * Web part cache manager. Key is `layout index - section factor` which maps to a width in px * This is primarily used to reduce browser reflow caused by dom dimension calculations. * * @internal */ export default class WebPartWidthCacheManager { private static _sectionWidthCache; /** * Returns cached width * @param key - string in format '<layoutIndex>-<sectionFactor>' * @returns width of given sectionFactor or undefined if it does not exist. */ static get(key: string): number | undefined; /** * If key exist in cache it returns the value stored. * Otherwise, it will calculate the width of dom element and store it in the cache. * Calculating the width will cause a reflow. * * @param domElement - dom element width we want to calculate * @param key - cache's key * * @returns width of domElement */ static getOrCalculateWidth(domElement: HTMLElement, key?: string): number; /** * Removes all key-value pairs from the cache * It is used when window resizes as all section factor widths needs to be cached again. */ static clear(): void; /** * * This value is the available width of the area in which the web part can render itself. * Instead of "Element.clientWidth" which returns an integer, "getComputedStyle" returns * a number which is more accurate in sub-pixel. * This function uses getBoundingClientRect or getComputedStyle which causes * browser reflows. Please use with caution. * * @remarks * {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/clientWidth | clientWidth} * {@link https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/parseFloat | parseFloat} * {@link https://developer.mozilla.org/en/docs/Web/API/Window/getComputedStyle | getComputedStyle} * */ static calculateWebPartWidth(domElement: HTMLElement): number; /** * Caches width sectionFactor. * @param key - string in format '<layoutIndex>-<sectionFactor>' * @param width - width of canvas section factor in px */ private static _put; private constructor(); } //# sourceMappingURL=WebPartWidthCacheManager.d.ts.map