var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/PisellProcedure/hooks/useElementSize.ts
var useElementSize_exports = {};
__export(useElementSize_exports, {
  useElementSize: () => useElementSize
});
module.exports = __toCommonJS(useElementSize_exports);
var import_react = require("react");
var useElementSize = ({
  selector,
  enabled = true,
  defaultWidth = 0,
  defaultHeight = 0,
  debounceMs = 100
}) => {
  const [size, setSize] = (0, import_react.useState)({
    width: defaultWidth,
    height: defaultHeight
  });
  const handScale = () => {
    var _a;
    const bodyTransform = (_a = getComputedStyle(document.body)) == null ? void 0 : _a.transform;
    let scaleY = 1;
    let scaleX = 1;
    if (bodyTransform !== "none") {
      const matrix = new DOMMatrix(bodyTransform);
      scaleX = matrix.a;
      scaleY = matrix.d;
    }
    return { scaleX, scaleY };
  };
  (0, import_react.useLayoutEffect)(() => {
    if (!enabled || typeof window === "undefined" || typeof document === "undefined") {
      return;
    }
    if (!selector || !selector.trim()) {
      setSize({ width: defaultWidth, height: defaultHeight });
      return;
    }
    const handleResize = () => {
      setTimeout(() => {
        let element = null;
        try {
          element = document.querySelector(selector);
          const rect = element == null ? void 0 : element.getBoundingClientRect();
          if (rect) {
            const { scaleX } = handScale();
            const elementWidth = (element == null ? void 0 : element.clientWidth) || 0;
            const scaledWidth = elementWidth * scaleX;
            const width = Math.round(scaledWidth * 100) / 100;
            const height = Math.round((rect == null ? void 0 : rect.height) * 100) / 100;
            setSize({ width, height });
          }
        } catch (error) {
          setSize({ width: defaultWidth, height: defaultHeight });
          return;
        }
      }, debounceMs);
    };
    handleResize();
    window.addEventListener("resize", handleResize);
    return () => {
      window.removeEventListener("resize", handleResize);
    };
  }, [selector, enabled, defaultWidth, defaultHeight, debounceMs]);
  return size;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  useElementSize
});
