import { Arr } from '@ephox/katamari';
import { Html, SugarElement, SugarNode, Traverse } from '@ephox/sugar';
const getAttrs = (elem) => {
    const attributes = elem.dom.attributes !== undefined ? elem.dom.attributes : [];
    return Arr.foldl(attributes, (b, attr) => {
        // Make class go through the class path. Do not list it as an attribute.
        if (attr.name === 'class') {
            return b;
        }
        else {
            return { ...b, [attr.name]: attr.value };
        }
    }, {});
};
const getClasses = (elem) => Array.prototype.slice.call(elem.dom.classList, 0);
const fromHtml = (html) => {
    const elem = SugarElement.fromHtml(html);
    const children = Traverse.children(elem);
    const attrs = getAttrs(elem);
    const classes = getClasses(elem);
    const contents = children.length === 0 ? {} : { innerHtml: Html.get(elem) };
    return {
        tag: SugarNode.name(elem),
        classes,
        attributes: attrs,
        ...contents
    };
};
const sketch = (sketcher, html, config) => sketcher.sketch({
    dom: fromHtml(html),
    ...config
});
const dom = (tag, classes, attributes = {}, styles = {}) => ({
    tag,
    classes,
    attributes,
    styles
});
const simple = (tag, classes, components) => ({
    dom: {
        tag,
        classes
    },
    components
});
export { getAttrs, getClasses, fromHtml, sketch, simple, dom };
//# sourceMappingURL=DomFactory.js.map