'use strict';

var isCssVariable = require('../../animation/utils/is-css-variable.js');
var keysTransform = require('../utils/keys-transform.js');
var parseTransform = require('../dom/parse-transform.js');
var measure = require('../../projection/utils/measure.js');
var DOMVisualElement = require('../dom/DOMVisualElement.js');
var buildStyles = require('./utils/build-styles.js');
var render = require('./utils/render.js');
var scrapeMotionValues = require('./utils/scrape-motion-values.js');

function getComputedStyle(element) {
    return window.getComputedStyle(element);
}
class HTMLVisualElement extends DOMVisualElement.DOMVisualElement {
    constructor() {
        super(...arguments);
        this.type = "html";
        this.renderInstance = render.renderHTML;
    }
    readValueFromInstance(instance, key) {
        if (keysTransform.transformProps.has(key)) {
            return this.projection?.isProjecting
                ? parseTransform.defaultTransformValue(key)
                : parseTransform.readTransformValue(instance, key);
        }
        else {
            const computedStyle = getComputedStyle(instance);
            const value = (isCssVariable.isCSSVariableName(key)
                ? computedStyle.getPropertyValue(key)
                : computedStyle[key]) || 0;
            return typeof value === "string" ? value.trim() : value;
        }
    }
    measureInstanceViewportBox(instance, { transformPagePoint }) {
        return measure.measureViewportBox(instance, transformPagePoint);
    }
    build(renderState, latestValues, props) {
        buildStyles.buildHTMLStyles(renderState, latestValues, props.transformTemplate);
    }
    scrapeMotionValuesFromProps(props, prevProps, visualElement) {
        return scrapeMotionValues.scrapeMotionValuesFromProps(props, prevProps, visualElement);
    }
}

exports.HTMLVisualElement = HTMLVisualElement;
exports.getComputedStyle = getComputedStyle;
