"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const reactBinding = require("@contember/react-binding");
const getImageFileDataExtractor = ({
  heightField,
  widthField
}) => ({
  staticRender: () => /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
    !!widthField && /* @__PURE__ */ jsxRuntime.jsx(reactBinding.SugaredField, { field: widthField }),
    !!heightField && /* @__PURE__ */ jsxRuntime.jsx(reactBinding.SugaredField, { field: heightField })
  ] }),
  extractFileData: ({ objectUrl }) => {
    if (!heightField && !widthField) {
      return null;
    }
    return new Promise((resolve, reject) => {
      const image = new Image();
      image.addEventListener("load", () => {
        resolve(image);
      });
      image.addEventListener("error", (e) => {
        reject(e.message);
      });
      image.src = objectUrl;
    });
  },
  populateFields: ({ entity, extractedData }) => {
    entity.batchUpdates((getAccessor) => {
      widthField && getAccessor().getField(widthField).updateValue(extractedData.naturalWidth);
      heightField && getAccessor().getField(heightField).updateValue(extractedData.naturalHeight);
    });
  }
});
exports.getImageFileDataExtractor = getImageFileDataExtractor;
//# sourceMappingURL=getImageFileDataExtractor.cjs.map
