import { frame } from "./dist-es-frameloop-frame.js";
import { makeUseVisualState } from "./dist-es-motion-utils-use-visual-state.js";
import { transformProps } from "./dist-es-render-html-utils-keys-transform.js";
import { buildSVGAttrs } from "./dist-es-render-svg-utils-build-attrs.js";
import { createSvgRenderState } from "./dist-es-render-svg-utils-create-render-state.js";
import { isSVGTag } from "./dist-es-render-svg-utils-is-svg-tag.js";
import { renderSVG } from "./dist-es-render-svg-utils-render.js";
import { scrapeMotionValuesFromProps } from "./dist-es-render-svg-utils-scrape-motion-values.js";
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: makeUseVisualState({
    scrapeMotionValuesFromProps,
    createRenderState: createSvgRenderState,
    onUpdate: ({ props, prevProps, current, renderState, latestValues }) => {
      if (!current)
        return;
      let hasTransform = !!props.drag;
      if (!hasTransform) {
        for (const key in latestValues) {
          if (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.read(() => {
        updateSVGDimensions(current, renderState);
        frame.render(() => {
          buildSVGAttrs(renderState, latestValues, isSVGTag(current.tagName), props.transformTemplate);
          renderSVG(current, renderState);
        });
      });
    }
  })
};
export {
  svgMotionConfig
};
//# sourceMappingURL=dist-es-render-svg-config-motion.js.map
