import { Optional, Type } from '@ephox/katamari'; import type { SugarElement } from '../api/node/SugarElement'; type TestFn = (e: SugarElement) => boolean; type ScopeTestFn = (scope: SugarElement, a: T) => scope is SugarElement; type AncestorFn = (scope: SugarElement, predicate: T, isRoot?: TestFn) => Optional>; export default (is: ScopeTestFn, ancestor: AncestorFn, scope: SugarElement, a: T, isRoot?: TestFn): Optional> => { if (is(scope, a)) { return Optional.some(scope); } else if (Type.isFunction(isRoot) && isRoot(scope)) { return Optional.none>(); } else { return ancestor(scope, a, isRoot); } };