|
| 1 | +import { isHTMLElement } from '../../shared'; |
| 2 | + |
| 3 | +export const toastCssVars = { |
| 4 | + swipeMoveX: '--soybean-toast-swipe-move-x', |
| 5 | + swipeMoveY: '--soybean-toast-swipe-move-y', |
| 6 | + swipeEndX: '--soybean-toast-swipe-end-x', |
| 7 | + swipeEndY: '--soybean-toast-swipe-end-y' |
| 8 | +}; |
| 9 | + |
| 10 | +export const TOAST_DATA_SWIPE = 'data-swipe'; |
| 11 | + |
| 12 | +export const toastSwipe = { |
| 13 | + start: 'start', |
| 14 | + move: 'move', |
| 15 | + cancel: 'cancel', |
| 16 | + end: 'end' |
| 17 | +} as const; |
| 18 | + |
| 19 | +export const TOAST_SWIPE_START = 'toast.swipeStart'; |
| 20 | +export const TOAST_SWIPE_MOVE = 'toast.swipeMove'; |
| 21 | +export const TOAST_SWIPE_CANCEL = 'toast.swipeCancel'; |
| 22 | +export const TOAST_SWIPE_END = 'toast.swipeEnd'; |
| 23 | + |
| 24 | +export const VIEWPORT_NAME = 'ToastViewport'; |
| 25 | +export const VIEWPORT_DEFAULT_HOTKEY = ['F8']; |
| 26 | +export const VIEWPORT_PAUSE = 'toast.viewportPause'; |
| 27 | +export const VIEWPORT_RESUME = 'toast.viewportResume'; |
| 28 | + |
| 29 | +export function getAnnounceTextContent(container: HTMLElement) { |
| 30 | + const textContent: string[] = []; |
| 31 | + const childNodes = Array.from(container.childNodes); |
| 32 | + |
| 33 | + childNodes.forEach(node => { |
| 34 | + if (node.nodeType === node.TEXT_NODE && node.textContent) { |
| 35 | + textContent.push(node.textContent); |
| 36 | + } |
| 37 | + |
| 38 | + if (!isHTMLElement(node)) return; |
| 39 | + const isHidden = node.ariaHidden || node.hidden || node.style.display === 'none'; |
| 40 | + const isExcluded = node.dataset.soybeanToastAnnounceExclude === ''; |
| 41 | + |
| 42 | + if (isHidden) return; |
| 43 | + |
| 44 | + if (isExcluded) { |
| 45 | + const altText = node.dataset.soybeanToastAnnounceAlt; |
| 46 | + if (altText) { |
| 47 | + textContent.push(altText); |
| 48 | + } |
| 49 | + } else { |
| 50 | + textContent.push(...getAnnounceTextContent(node)); |
| 51 | + } |
| 52 | + }); |
| 53 | + // We return a collection of text rather than a single concatenated string. |
| 54 | + // This allows SR VO to naturally pause break between nodes while announcing. |
| 55 | + return textContent; |
| 56 | +} |
0 commit comments