import type { Nullable } from 'jodit/types'; import type { CommitStyle } from '../commit-style'; import { Dom } from 'jodit/core/dom'; import { isNormalNode } from './is-normal-node'; import { isSuitElement } from './is-suit-element'; /** * Checks if child elements are suitable for applying styles. * An element is suitable for us only if it is the only significant child. * If the child matches then returns it. * @example * `selected` * @private */ export function getSuitChild( style: CommitStyle, font: HTMLElement ): Nullable { let { firstChild: child } = font; while (child && !isNormalNode(child)) { child = child.nextSibling; if (!child) { return null; } } if ( child && !Dom.next(child, isNormalNode, font) && isSuitElement(style, child, false) ) { return child; } return null; }