"use strict";
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);
var use_image_dimensions_exports = {};
__export(use_image_dimensions_exports, {
  useImageDimensions: () => useImageDimensions
});
module.exports = __toCommonJS(use_image_dimensions_exports);
var import_react = require("react");
var import_wix_rich_content_common = require("./../../wix-rich-content-common/index.js");
const useImageDimensions = ({
  src,
  containerData,
  image
}) => {
  const [dimensions, setDimensions] = (0, import_react.useState)({
    width: void 0,
    height: void 0
  });
  const width = image?.width ?? (Number(containerData?.width?.custom) || dimensions.width);
  const height = image?.height ?? (Number(containerData?.height?.custom) || dimensions.height);
  useIsomorphicLayoutEffect(() => {
    if (typeof width === "number" && typeof height === "number") {
      return;
    }
    setDimensions({ width: void 0, height: void 0 });
    if (!src) {
      return;
    }
    const newImg = new Image();
    newImg.onload = () => setDimensions({ width: newImg.width, height: newImg.height });
    newImg.src = src;
    return () => {
      newImg.onload = null;
    };
  }, [src]);
  return {
    width,
    height
  };
};
const useIsomorphicLayoutEffect = (0, import_wix_rich_content_common.isSSR)() ? () => {
} : import_react.useLayoutEffect;
//# sourceMappingURL=use-image-dimensions.js.map
