import { jsxs, Fragment, jsx } from "react/jsx-runtime";
import { SugaredField } from "@contember/react-binding";
const getImageFileDataExtractor = ({
  heightField,
  widthField
}) => ({
  staticRender: () => /* @__PURE__ */ jsxs(Fragment, { children: [
    !!widthField && /* @__PURE__ */ jsx(SugaredField, { field: widthField }),
    !!heightField && /* @__PURE__ */ jsx(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);
    });
  }
});
export {
  getImageFileDataExtractor
};
//# sourceMappingURL=getImageFileDataExtractor.js.map
