"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const frame = require("./dist-es-frameloop-frame.cjs");
const useVisualState = require("./dist-es-motion-utils-use-visual-state.cjs");
const keysTransform = require("./dist-es-render-html-utils-keys-transform.cjs");
const buildAttrs = require("./dist-es-render-svg-utils-build-attrs.cjs");
const createRenderState = require("./dist-es-render-svg-utils-create-render-state.cjs");
const isSvgTag = require("./dist-es-render-svg-utils-is-svg-tag.cjs");
const render = require("./dist-es-render-svg-utils-render.cjs");
const scrapeMotionValues = require("./dist-es-render-svg-utils-scrape-motion-values.cjs");
function updateSVGDimensions(instance, renderState) {
  try {
    renderState.dimensions = typeof instance.getBBox === "function" ? instance.getBBox() : instance.getBoundingClientRect();
  } catch (e) {
    renderState.dimensions = {
      x: 0,
      y: 0,
      width: 0,
      height: 0
    };
  }
}
const layoutProps = ["x", "y", "width", "height", "cx", "cy", "r"];
const svgMotionConfig = {
  useVisualState: useVisualState.makeUseVisualState({
    scrapeMotionValuesFromProps: scrapeMotionValues.scrapeMotionValuesFromProps,
    createRenderState: createRenderState.createSvgRenderState,
    onUpdate: ({ props, prevProps, current, renderState, latestValues }) => {
      if (!current)
        return;
      let hasTransform = !!props.drag;
      if (!hasTransform) {
        for (const key in latestValues) {
          if (keysTransform.transformProps.has(key)) {
            hasTransform = true;
            break;
          }
        }
      }
      if (!hasTransform)
        return;
      let needsMeasure = !prevProps;
      if (prevProps) {
        for (let i = 0; i < layoutProps.length; i++) {
          const key = layoutProps[i];
          if (props[key] !== prevProps[key]) {
            needsMeasure = true;
          }
        }
      }
      if (!needsMeasure)
        return;
      frame.frame.read(() => {
        updateSVGDimensions(current, renderState);
        frame.frame.render(() => {
          buildAttrs.buildSVGAttrs(renderState, latestValues, isSvgTag.isSVGTag(current.tagName), props.transformTemplate);
          render.renderSVG(current, renderState);
        });
      });
    }
  })
};
exports.svgMotionConfig = svgMotionConfig;
//# sourceMappingURL=dist-es-render-svg-config-motion.cjs.map
