/**
 * Webf cli compact library. used to preview Webf rendering.
 */
function setElementStyle(dom, object) {
    if (object == null)
        return;
    for (let key in object) {
        if (object.hasOwnProperty(key)) {
            dom.style[key] = object[key];
        }
    }
}
function setAttributes(dom, object) {
    for (const key in object) {
        if (object.hasOwnProperty(key)) {
            dom.setAttribute(key, object[key]);
        }
    }
}
function sleep(second) {
    return new Promise(done => setTimeout(done, second * 1000));
}
function createElementWithStyle(tag, style, child) {
    const el = document.createElement(tag);
    setElementStyle(el, style);
    if (Array.isArray(child)) {
        child.forEach(c => el.appendChild(c));
    }
    else if (child) {
        el.appendChild(child);
    }
    return el;
}
function setElementProps(el, props) {
    let keys = Object.keys(props);
    for (let key of keys) {
        if (key === 'style') {
            setElementStyle(el, props[key]);
        }
        else {
            el[key] = props[key];
        }
    }
}
function createElement(tag, props, child) {
    const el = document.createElement(tag);
    setElementProps(el, props);
    if (Array.isArray(child)) {
        child.forEach(c => el.appendChild(c));
    }
    else if (child) {
        el.appendChild(child);
    }
    return el;
}
function createViewElement(extraStyle, child) {
    return createElement('div', {
        style: {
            display: 'flex',
            position: 'relative',
            flexDirection: 'column',
            flexShrink: 0,
            alignContent: 'flex-start',
            border: '0 solid black',
            margin: 0,
            padding: 0,
            minWidth: 0,
            ...extraStyle,
        },
    }, child);
}
function createText(content) {
    return document.createTextNode(content);
}
function append(parent, child) {
    parent.appendChild(child);
}
async function matchViewportSnapshot() {
    return new Promise((resolve) => {
        requestAnimationFrame(() => {
            resolve();
        });
    });
}
async function matchElementImageSnapshot(element) {
    return Promise.resolve();
}
async function it(name, fn) {
    console.log('starting ' + name);
    if (fn.length > 0) {
        const timer = setTimeout(() => {
            throw new Error('it execute timeout of 5000ms');
        }, 5000);
        const done = () => {
            console.log('done call');
            clearTimeout(timer);
        };
        fn(done);
    }
    else {
        fn();
    }
}
function expect(value) {
    class ExpectClass {
        constructor(expected) {
            this.expected = expected;
        }
        toBe(actual) {
            if (this.expected !== actual) {
                throw new Error(`toBe(): expected is not equal with expected value: expected: ${this.expected}, actual: ${actual}`);
            }
        }
    }
    return new ExpectClass(value);
}
function xit(name, fn) {
    it(name, fn);
}
