"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 element_imperative_handle_exports = {};
__export(element_imperative_handle_exports, {
  ElementImperativeHandle: () => ElementImperativeHandle,
  isDomNodeHandle: () => isDomNodeHandle
});
module.exports = __toCommonJS(element_imperative_handle_exports);
var import_box_models2 = require("../../state/modules/box-models");
var import_prop_controller_handles = require("../../state/modules/prop-controller-handles");
class ElementImperativeHandle {
  getCurrent = () => null;
  lastPropControllers = null;
  callback(getCurrent) {
    const current = this.getCurrent();
    if (current === null)
      this.setPropControllers(null);
    this.getCurrent = getCurrent;
    if (this.lastPropControllers !== null)
      this.setPropControllers(this.lastPropControllers);
  }
  getBoxModel() {
    const current = this.getCurrent();
    return (0, import_box_models2.isMeasurable)(current) ? (0, import_box_models2.measure)(current) : null;
  }
  setPropControllers(propControllers) {
    const current = this.getCurrent();
    if ((0, import_prop_controller_handles.isPropControllersHandle)(current))
      current.setPropControllers(propControllers);
    this.lastPropControllers = propControllers;
  }
  getDomNode() {
    const current = this.getCurrent();
    if (isDomNodeHandle(current))
      return current.getDomNode();
    return current instanceof Element ? current : null;
  }
}
function isDomNodeHandle(value) {
  if (typeof value === "object" && value !== null && "getDomNode" in value && typeof value.getDomNode === "function") {
    return true;
  }
  return false;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  ElementImperativeHandle,
  isDomNodeHandle
});
//# sourceMappingURL=element-imperative-handle.js.map