import { Obj } from '@ephox/katamari'; import type { SugarElement } from '../node/SugarElement'; import * as Node from '../node/SugarNode'; import * as Css from './Css'; import * as Direction from './Direction'; type Alignment = 'left' | 'right' | 'justify' | 'center' | 'match-parent'; const normal = (value: Alignment) => (_element: SugarElement): Alignment => value; const lookups: Record) => string> = { 'start': Direction.onDirection('left', 'right'), 'end': Direction.onDirection('right', 'left'), 'justify': normal('justify'), 'center': normal('center'), 'match-parent': normal('match-parent') }; const getAlignment = (element: SugarElement, property: string): string => { const raw = Css.get(element, property); return Obj.get(lookups, raw) .map((f) => f(element)) .getOr(raw); }; const hasAlignment = (element: SugarElement | SugarElement, property: string, value: string): boolean => Node.isText(element) ? false : getAlignment(element, property) === value; export { hasAlignment };