UNPKG

@progress/kendo-angular-pager

Version:
125 lines (124 loc) 4.24 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ import { isDocumentAvailable } from "@progress/kendo-angular-common"; /** * @hidden */ export const DEFAULT_PAGE_SIZE_VALUES = [5, 10, 20].map(n => ({ text: String(n), value: n })); /** * @hidden */ const focusableDirectiveSelector = '[kendoPagerFocusable]'; /** * @hidden */ export const getAllFocusableChildren = (parent) => { return parent.querySelectorAll(focusableDirectiveSelector); }; /** * @hidden */ export const focusableSelector = [ 'a[href]:not([disabled]):not([aria-hidden="true"])', 'area[href]:not([disabled]):not([aria-hidden="true"])', 'input:not([disabled]):not([aria-hidden="true"])', 'select:not([disabled]):not([aria-hidden="true"])', 'textarea:not([disabled]):not([aria-hidden="true"])', 'button:not([aria-hidden="true"])', 'iframe:not([disabled])', 'object:not([disabled])', 'embed:not([disabled])', '*[tabindex]:not([disabled]):not([aria-hidden="true"])', '*[contenteditable]:not([disabled]):not([contenteditable="false"])' ].join(','); /** * @hidden */ export const DEFAULT_SIZE = 'medium'; const SIZES = { small: 'sm', medium: 'md', large: 'lg' }; /** * @hidden * * Returns the styling classes to be added and removed */ export const getStylingClasses = (componentType, stylingOption, previousValue, newValue) => { switch (stylingOption) { case 'size': return { toRemove: `k-${componentType}-${SIZES[previousValue]}`, toAdd: newValue !== 'none' ? `k-${componentType}-${SIZES[newValue]}` : '' }; default: break; } }; /** * @hidden */ export const calculatePadding = (element) => { if (!element || !isDocumentAvailable()) { return { padding: 0, gapNumbersSizes: 0, gapSizesInfo: 0 }; } const computedStyle = window.getComputedStyle(element); const paddingLeft = parseInt(computedStyle.paddingLeft, 10) || 0; const paddingRight = parseInt(computedStyle.paddingRight, 10) || 0; const padding = (paddingLeft + paddingRight) * 1.2; // account for rounding errors const style = getComputedStyle(document.documentElement); const gapNumbersSizes = 2 * (parseFloat(style.getPropertyValue('--kendo-spacing-3\\.5') || '0.875rem') * (parseFloat(getComputedStyle(document.documentElement).fontSize) || 16)); // convert rem to px const gapSizesInfo = gapNumbersSizes; return { padding, gapNumbersSizes, gapSizesInfo }; }; /** * @hidden */ export const calculateGap = (element) => { if (!element || !isDocumentAvailable()) { return 0; } const computedStyle = window.getComputedStyle(element); return parseFloat(computedStyle.gap) || 0; }; /** * @hidden */ export const createMeasurementSpan = (renderer, container, className) => { const span = renderer.createElement('span'); renderer.appendChild(container, span); renderer.addClass(span, className); return span; }; /** * @hidden */ export const copyComputedStyles = (renderer, source, destination) => { const computedStyle = getComputedStyle(source); const importantStyles = [ 'font-family', 'font-size', 'font-weight', 'font-style', 'letter-spacing', 'text-transform', 'white-space', 'word-spacing', 'padding-left', 'padding-right', 'margin-left', 'margin-right', 'border-left-width', 'border-right-width', 'box-sizing' ]; importantStyles.forEach(style => { renderer.setStyle(destination, style, computedStyle.getPropertyValue(style)); }); }; /** * * @hidden */ export const positionOffScreen = (renderer, element) => { renderer.setStyle(element, 'position', 'absolute'); renderer.setStyle(element, 'visibility', 'hidden'); renderer.setStyle(element, 'left', '-9999px'); renderer.setStyle(element, 'top', '-9999px'); renderer.setStyle(element, 'display', 'flex'); };