UNPKG

@dvcol/neo-svelte

Version:

Neomorphic ui library for svelte 5

35 lines (34 loc) 1.11 kB
import { getClickableAncestor, isClickable } from '@dvcol/common-utils/common/element'; export const NeoCursorPointerType = { Mouse: 'mouse', Touch: 'touch', Pen: 'pen', }; export const NeoCursorType = { Snap: 'snap', Text: 'text', Auto: 'auto', None: 'none', }; export function getClosestClickable(element, boundary) { return getClickableAncestor(element, boundary, (el) => { if (el.getAttribute('data-neo-cursor') === 'false' || el.getAttribute('data-neo-cursor') === 'none') return false; if (el.getAttribute('data-neo-cursor') === 'snap') return true; return isClickable(el); }); } export function getFirstDataNeoCursor(element, boundary) { if (!element) return; if (typeof boundary === 'function' && boundary() === element) return; if (boundary === element) return; if (element.hasAttribute('data-neo-cursor')) return element.getAttribute('data-neo-cursor'); if (!element.parentElement) return; return getFirstDataNeoCursor(element.parentElement, boundary); }