<commit_before>import { Arr, Obj, Result } from '@ephox/katamari';
import { Element, Node, Text, Traverse } from '@ephox/sugar';

import { SimpleOrSketchSpec } from '../../api/component/SpecTypes';
import { getAttrs, getClasses } from './DomFactory';

import { Text as DomText, Node as DomNode } from '@ephox/dom-globals';

const readText = (elem: Element<DomText>) => {
  const text = Text.get(elem);
  return text.trim().length > 0 ? [ { text } ] : [ ];
};

const readChildren = <T extends DomNode> (elem: Element<T>) => {
  if (Node.isText(elem)) {
    return readText(elem);
  } else if (Node.isComment(elem)) {
    return [ ];
  } else {
    const attributes = getAttrs(elem);
    const classes = getClasses(elem);
    const children = Traverse.children(elem);

    const components = Arr.bind(children, (child) => {
      if (Node.isText(child)) { return readText(child); } else { return readChildren(child); }
    });

    return [{
      dom: {
        tag: Node.name(elem),
        ...(Obj.keys(attributes).length > 0 ? {attributes} : {}),
        ...(classes.length > 0 ? {classes} : {})
      },
      components
    }];
  }
};

const read = <T extends DomNode> (elem: Element<T>): SimpleOrSketchSpec => {
  const attributes = getAttrs(elem);
  const classes = getClasses(elem);

  const children = Traverse.children(elem);

  const components = Arr.bind(children, (child) => {
    return readChildren(child);
  }) as SimpleOrSketchSpec[];

  return {
    dom: {
      tag: Node.name(elem),
      ...(Obj.keys(attributes).length > 0 ? {attributes} : {}),
      ...(classes.length > 0 ? {classes} : {})
    },
    components
  };
};

const readHtml = (html: string): Result<SimpleOrSketchSpec, string> => {
  const elem = Element.fromHtml(html);
  return Node.isText(elem) ? Result.error('Template text must contain an element!') : Result.value(
    read(elem)<commit_msg>Simplified type signature.<commit_after>import { Arr, Obj, Result } from '@ephox/katamari';
import { Element, Node, Text, Traverse } from '@ephox/sugar';

import { SimpleOrSketchSpec } from '../../api/component/SpecTypes';
import { getAttrs, getClasses } from './DomFactory';

import { Text as DomText, Node as DomNode } from '@ephox/dom-globals';

const readText = (elem: Element<DomText>) => {
  const text = Text.get(elem);
  return text.trim().length > 0 ? [ { text } ] : [ ];
};

const readChildren = (elem: Element<DomNode>) => {
  if (Node.isText(elem)) {
    return readText(elem);
  } else if (Node.isComment(elem)) {
    return [ ];
  } else {
    const attributes = getAttrs(elem);
    const classes = getClasses(elem);
    const children = Traverse.children(elem);

    const components = Arr.bind(children, (child) => {
      if (Node.isText(child)) { return readText(child); } else { return readChildren(child); }
    });

    return [{
      dom: {
        tag: Node.name(elem),
        ...(Obj.keys(attributes).length > 0 ? {attributes} : {}),
        ...(classes.length > 0 ? {classes} : {})
      },
      components
    }];
  }
};

const read = (elem: Element<DomNode>): SimpleOrSketchSpec => {
  const attributes = getAttrs(elem);
  const classes = getClasses(elem);

  const children = Traverse.children(elem);

  const components = Arr.bind(children, (child) => {
    return readChildren(child);
  }) as SimpleOrSketchSpec[];

  return {
    dom: {
      tag: Node.name(elem),
      ...(Obj.keys(attributes).length > 0 ? {attributes} : {}),
      ...(classes.length > 0 ? {classes} : {})
    },
    components
  };
};

const readHtml = (html: string): Result<SimpleOrSketchSpec, string> => {
  const elem = Element.fromHtml(html);
  return Node.isText(elem) ? Result.error('Template text must contain an element!') : Result.value(
    read(elem)
{'fraction_non_alphanumeric': 0.1688450253400907, 'fraction_numerical': 0.002667377967457989, 'mean_word_length': 3.251700680272109, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5936383', 'n_tokens_mistral': 1201, 'n_tokens_neox': 1199, 'n_words': 283}