UNPKG

@progress/kendo-angular-utils

Version:

Kendo UI Angular utils component

91 lines (90 loc) 2.8 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ function isDocumentNode(container) { return container.nodeType === 9; } /** * @hidden */ export const getAction = (event, draggable) => { return { event: event, payload: draggable }; }; /** * @hidden */ export const dragTargetTransition = 'transform .3s ease-in-out'; /** * @hidden */ export const isPresent = (value) => value !== null && value !== undefined; /** * @hidden */ export function closestBySelector(element, selector) { if (element.closest) { return element.closest(selector); } const matches = Element.prototype.matches ? (el, sel) => el.matches(sel) : (el, sel) => el.msMatchesSelector(sel); let node = element; while (node && !isDocumentNode(node)) { if (matches(node, selector)) { return node; } node = node.parentNode; } } /** * @hidden */ export const intersect = (element, candidates) => { let max = 0; let result = null; candidates.forEach((candidate) => { if (candidate && element) { const ration = getRatio(element, candidate); if (ration > max) { max = ration; result = candidate; } } }); return result; }; const getRatio = (element, target) => { const elementRect = element.getBoundingClientRect(); const targetRect = target.getBoundingClientRect(); const top = Math.max(targetRect.top, elementRect.top); const left = Math.max(targetRect.left, elementRect.left); const right = Math.min(targetRect.left + targetRect.width, elementRect.left + elementRect.width); const bottom = Math.min(targetRect.top + targetRect.height, elementRect.top + elementRect.height); const width = right - left; const height = bottom - top; if (left < right && top < bottom) { const targetArea = targetRect.width * targetRect.height; const entryArea = elementRect.width * elementRect.height; const intersectionArea = width * height; const intersectionRatio = intersectionArea / (targetArea + entryArea - intersectionArea); return Number(intersectionRatio.toFixed(4)); } return 0; }; /** * @hidden */ export const setElementStyles = (renderer, elem, styles) => { const props = Object.keys(styles); props.forEach(p => { renderer.setStyle(elem, p, styles[p]); }); }; /** * @hidden */ export const noop = () => { };