reka-ui
Version:
Vue port for Radix UI Primitives.
47 lines (46 loc) • 1.92 kB
JavaScript
//#region src/Toast/utils.ts
const TOAST_SWIPE_START = "toast.swipeStart";
const TOAST_SWIPE_MOVE = "toast.swipeMove";
const TOAST_SWIPE_CANCEL = "toast.swipeCancel";
const TOAST_SWIPE_END = "toast.swipeEnd";
const VIEWPORT_PAUSE = "toast.viewportPause";
const VIEWPORT_RESUME = "toast.viewportResume";
function handleAndDispatchCustomEvent(name, handler, detail) {
const currentTarget = detail.originalEvent.currentTarget;
const event = new CustomEvent(name, {
bubbles: false,
cancelable: true,
detail
});
if (handler) currentTarget.addEventListener(name, handler, { once: true });
currentTarget.dispatchEvent(event);
}
function isDeltaInDirection(delta, direction, threshold = 0) {
const deltaX = Math.abs(delta.x);
const deltaY = Math.abs(delta.y);
const isDeltaX = deltaX > deltaY;
if (direction === "left" || direction === "right") return isDeltaX && deltaX > threshold;
else return !isDeltaX && deltaY > threshold;
}
function isHTMLElement(node) {
return node.nodeType === node.ELEMENT_NODE;
}
function getAnnounceTextContent(container) {
const textContent = [];
const childNodes = Array.from(container.childNodes);
childNodes.forEach((node) => {
if (node.nodeType === node.TEXT_NODE && node.textContent) textContent.push(node.textContent);
if (isHTMLElement(node)) {
const isHidden = node.ariaHidden || node.hidden || node.style.display === "none";
const isExcluded = node.dataset.rekaToastAnnounceExclude === "";
if (!isHidden) if (isExcluded) {
const altText = node.dataset.rekaToastAnnounceAlt;
if (altText) textContent.push(altText);
} else textContent.push(...getAnnounceTextContent(node));
}
});
return textContent;
}
//#endregion
export { TOAST_SWIPE_CANCEL, TOAST_SWIPE_END, TOAST_SWIPE_MOVE, TOAST_SWIPE_START, VIEWPORT_PAUSE, VIEWPORT_RESUME, getAnnounceTextContent, handleAndDispatchCustomEvent, isDeltaInDirection };
//# sourceMappingURL=utils.js.map