"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const tslib_es6 = require("../../../../../../../tslib@2.6.2/node_modules/tslib/tslib.es6.js");
const index = require("../index.js");
const setters = require("../utils/setters.js");
const buildStyles = require("./utils/build-styles.js");
const isCssVariable = require("../dom/utils/is-css-variable.js");
const parseDomVariant = require("../dom/utils/parse-dom-variant.js");
const transform = require("./utils/transform.js");
const scrapeMotionValues = require("./utils/scrape-motion-values.js");
const render = require("./utils/render.js");
const defaults = require("../dom/value-types/defaults.js");
const measure = require("../../projection/utils/measure.js");
function getComputedStyle(element) {
  return window.getComputedStyle(element);
}
var htmlConfig = {
  treeType: "dom",
  readValueFromInstance: function(domElement, key) {
    if (transform.isTransformProp(key)) {
      var defaultType = defaults.getDefaultValueType(key);
      return defaultType ? defaultType.default || 0 : 0;
    } else {
      var computedStyle = getComputedStyle(domElement);
      return (isCssVariable.isCSSVariable(key) ? computedStyle.getPropertyValue(key) : computedStyle[key]) || 0;
    }
  },
  sortNodePosition: function(a, b) {
    return a.compareDocumentPosition(b) & 2 ? 1 : -1;
  },
  getBaseTarget: function(props, key) {
    var _a;
    return (_a = props.style) === null || _a === void 0 ? void 0 : _a[key];
  },
  measureViewportBox: function(element, _a) {
    var transformPagePoint = _a.transformPagePoint;
    return measure.measureViewportBox(element, transformPagePoint);
  },
  /**
   * Reset the transform on the current Element. This is called as part
   * of a batched process across the entire layout tree. To remove this write
   * cycle it'd be interesting to see if it's possible to "undo" all the current
   * layout transforms up the tree in the same way this.getBoundingBoxWithoutTransforms
   * works
   */
  resetTransform: function(element, domElement, props) {
    var transformTemplate = props.transformTemplate;
    domElement.style.transform = transformTemplate ? transformTemplate({}, "") : "none";
    element.scheduleRender();
  },
  restoreTransform: function(instance, mutableState) {
    instance.style.transform = mutableState.style.transform;
  },
  removeValueFromRenderState: function(key, _a) {
    var vars = _a.vars, style = _a.style;
    delete vars[key];
    delete style[key];
  },
  /**
   * Ensure that HTML and Framer-specific value types like `px`->`%` and `Color`
   * can be animated by Motion.
   */
  makeTargetAnimatable: function(element, _a, _b, isMounted) {
    var transformValues = _b.transformValues;
    if (isMounted === void 0) {
      isMounted = true;
    }
    var transition = _a.transition, transitionEnd = _a.transitionEnd, target = tslib_es6.__rest(_a, ["transition", "transitionEnd"]);
    var origin = setters.getOrigin(target, transition || {}, element);
    if (transformValues) {
      if (transitionEnd)
        transitionEnd = transformValues(transitionEnd);
      if (target)
        target = transformValues(target);
      if (origin)
        origin = transformValues(origin);
    }
    if (isMounted) {
      setters.checkTargetForNewValues(element, target, origin);
      var parsed = parseDomVariant.parseDomVariant(element, target, origin, transitionEnd);
      transitionEnd = parsed.transitionEnd;
      target = parsed.target;
    }
    return tslib_es6.__assign({ transition, transitionEnd }, target);
  },
  scrapeMotionValuesFromProps: scrapeMotionValues.scrapeMotionValuesFromProps,
  build: function(element, renderState, latestValues, options, props) {
    if (element.isVisible !== void 0) {
      renderState.style.visibility = element.isVisible ? "visible" : "hidden";
    }
    buildStyles.buildHTMLStyles(renderState, latestValues, options, props.transformTemplate);
  },
  render: render.renderHTML
};
var htmlVisualElement = index.visualElement(htmlConfig);
exports.getComputedStyle = getComputedStyle;
exports.htmlConfig = htmlConfig;
exports.htmlVisualElement = htmlVisualElement;
//# sourceMappingURL=visual-element.js.map
