import { AnnotationGeneratorStrategyAbstract } from './annotation-generator-strategy.abstract';
/** Handle code annotation */
export class CodeAnnotationHandler extends AnnotationGeneratorStrategyAbstract {
  /**
   * @inheritDoc
   */
  canHandle(targetDto) {
    return targetDto.name === 'RTETextNode';
  }
  /**
   * Handle annotation.
   *
   * @param {HTMLElement} element - Current elements.
   * @param {VegaRTETextAnnotations} parentAnnotations - Parent annotations.
   * @returns {VegaRTETextAnnotations} - Annotation.
   */
  handle(element, parentAnnotations = {}) {
    return this.isCode(element) || parentAnnotations.code ? { code: true } : {};
  }
  /**
   * Is code element.
   *
   * @param {HTMLElement} element - current element.
   * @returns {boolean} - boolean.
   */
  isCode(element) {
    return (element.classList.contains('v-rte--code') ||
      element.nodeName === 'CODE' ||
      element.nodeName === 'PRE' ||
      element.style.fontFamily === 'monospace' ||
      element.style.fontFamily.replace(/["']/g, '') === 'Roboto Mono');
  }
}
