"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// packages/block-editor/src/hooks/dimensions.js
var dimensions_exports = {};
__export(dimensions_exports, {
  ALL_SIDES: () => ALL_SIDES,
  AXIAL_SIDES: () => AXIAL_SIDES,
  DIMENSIONS_SUPPORT_KEY: () => DIMENSIONS_SUPPORT_KEY,
  DimensionsPanel: () => DimensionsPanel,
  SPACING_SUPPORT_KEY: () => SPACING_SUPPORT_KEY,
  default: () => dimensions_default,
  hasDimensionsSupport: () => hasDimensionsSupport,
  useCustomSides: () => useCustomSides
});
module.exports = __toCommonJS(dimensions_exports);
var import_clsx = __toESM(require("clsx"));
var import_element = require("@wordpress/element");
var import_data = require("@wordpress/data");
var import_blocks = require("@wordpress/blocks");
var import_deprecated = __toESM(require("@wordpress/deprecated"));
var import_inspector_controls = __toESM(require("../components/inspector-controls"));
var import_global_styles = require("../components/global-styles");
var import_spacing_visualizer = require("./spacing-visualizer");
var import_store = require("../store");
var import_lock_unlock = require("../lock-unlock");
var import_utils = require("./utils");
var import_jsx_runtime = require("react/jsx-runtime");
var DIMENSIONS_SUPPORT_KEY = "dimensions";
var SPACING_SUPPORT_KEY = "spacing";
var ALL_SIDES = ["top", "right", "bottom", "left"];
var AXIAL_SIDES = ["vertical", "horizontal"];
function useVisualizer() {
  const [property, setProperty] = (0, import_element.useState)(false);
  const { hideBlockInterface, showBlockInterface } = (0, import_lock_unlock.unlock)(
    (0, import_data.useDispatch)(import_store.store)
  );
  (0, import_element.useEffect)(() => {
    if (!property) {
      showBlockInterface();
    } else {
      hideBlockInterface();
    }
  }, [property, showBlockInterface, hideBlockInterface]);
  return [property, setProperty];
}
function DimensionsInspectorControl({ children, resetAllFilter }) {
  const attributesResetAllFilter = (0, import_element.useCallback)(
    (attributes) => {
      const existingStyle = attributes.style;
      const updatedStyle = resetAllFilter(existingStyle);
      return {
        ...attributes,
        style: updatedStyle
      };
    },
    [resetAllFilter]
  );
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
    import_inspector_controls.default,
    {
      group: "dimensions",
      resetAllFilter: attributesResetAllFilter,
      children
    }
  );
}
function DimensionsPanel({ clientId, name, setAttributes, settings }) {
  const isEnabled = (0, import_global_styles.useHasDimensionsPanel)(settings);
  const value = (0, import_data.useSelect)(
    (select) => {
      if (!isEnabled) {
        return void 0;
      }
      return select(import_store.store).getBlockAttributes(clientId)?.style;
    },
    [clientId, isEnabled]
  );
  const [visualizedProperty, setVisualizedProperty] = useVisualizer();
  const onChange = (newStyle) => {
    setAttributes({
      style: (0, import_utils.cleanEmptyObject)(newStyle)
    });
  };
  if (!isEnabled) {
    return null;
  }
  const defaultDimensionsControls = (0, import_blocks.getBlockSupport)(name, [
    DIMENSIONS_SUPPORT_KEY,
    "__experimentalDefaultControls"
  ]);
  const defaultSpacingControls = (0, import_blocks.getBlockSupport)(name, [
    SPACING_SUPPORT_KEY,
    "__experimentalDefaultControls"
  ]);
  const defaultControls = {
    ...defaultDimensionsControls,
    ...defaultSpacingControls
  };
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
    /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
      import_global_styles.DimensionsPanel,
      {
        as: DimensionsInspectorControl,
        panelId: clientId,
        settings,
        value,
        onChange,
        defaultControls,
        onVisualize: setVisualizedProperty
      }
    ),
    !!settings?.spacing?.padding && visualizedProperty === "padding" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
      import_spacing_visualizer.PaddingVisualizer,
      {
        forceShow: visualizedProperty === "padding",
        clientId,
        value
      }
    ),
    !!settings?.spacing?.margin && visualizedProperty === "margin" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
      import_spacing_visualizer.MarginVisualizer,
      {
        forceShow: visualizedProperty === "margin",
        clientId,
        value
      }
    )
  ] });
}
function hasDimensionsSupport(blockName, feature = "any") {
  if (import_element.Platform.OS !== "web") {
    return false;
  }
  const support = (0, import_blocks.getBlockSupport)(blockName, DIMENSIONS_SUPPORT_KEY);
  if (support === true) {
    return true;
  }
  if (feature === "any") {
    return !!(support?.aspectRatio || !!support?.minHeight || !!support?.width);
  }
  return !!support?.[feature];
}
var dimensions_default = {
  useBlockProps,
  attributeKeys: ["minHeight", "width", "style"],
  hasSupport(name) {
    return hasDimensionsSupport(name);
  }
};
function useBlockProps({ name, minHeight, style }) {
  if (!hasDimensionsSupport(name, "aspectRatio") || (0, import_utils.shouldSkipSerialization)(name, DIMENSIONS_SUPPORT_KEY, "aspectRatio")) {
    return {};
  }
  const className = (0, import_clsx.default)({
    "has-aspect-ratio": !!style?.dimensions?.aspectRatio
  });
  const inlineStyleOverrides = {};
  if (style?.dimensions?.aspectRatio) {
    inlineStyleOverrides.minHeight = "unset";
  } else if (minHeight || style?.dimensions?.minHeight) {
    inlineStyleOverrides.aspectRatio = "unset";
  }
  return { className, style: inlineStyleOverrides };
}
function useCustomSides() {
  (0, import_deprecated.default)("wp.blockEditor.__experimentalUseCustomSides", {
    since: "6.3",
    version: "6.4"
  });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  ALL_SIDES,
  AXIAL_SIDES,
  DIMENSIONS_SUPPORT_KEY,
  DimensionsPanel,
  SPACING_SUPPORT_KEY,
  hasDimensionsSupport,
  useCustomSides
});
//# sourceMappingURL=dimensions.js.map
