import type { Universe } from '@ephox/boss'; import { Optional } from '@ephox/katamari'; /** * Creates a look function that searches the current element and parent elements until * the predicate returns true * * f: item -> boolean */ const predicate = (f: (e: E) => boolean) => { return (universe: Universe, item: E): Optional => { return f(item) ? Optional.some(item) : universe.up().predicate(item, f); }; }; /** * Creates a look function that searches the current element and parent elements until * the selector is matched * * sel: selector */ const selector = (sel: string) => { return (universe: Universe, item: E): Optional => { return universe.is(item, sel) ? Optional.some(item) : universe.up().selector(item, sel); }; }; export { predicate, selector };