reka-ui
Version:
Vue port for Radix UI Primitives.
55 lines (53 loc) • 2.05 kB
JavaScript
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;
}
export { TOAST_SWIPE_END as T, VIEWPORT_PAUSE as V, VIEWPORT_RESUME as a, TOAST_SWIPE_CANCEL as b, TOAST_SWIPE_MOVE as c, TOAST_SWIPE_START as d, getAnnounceTextContent as g, handleAndDispatchCustomEvent as h, isDeltaInDirection as i };
//# sourceMappingURL=utils.js.map