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);

// src/components/pisellFloorMapLayout/utils/layoutMeasurements.ts
var layoutMeasurements_exports = {};
__export(layoutMeasurements_exports, {
  DEFAULT_CELL_SIZE: () => DEFAULT_CELL_SIZE,
  DEFAULT_ITEM_GAP: () => DEFAULT_ITEM_GAP,
  gapToPx: () => gapToPx,
  getContentSize: () => getContentSize,
  getPixelBoundingBox: () => getPixelBoundingBox
});
module.exports = __toCommonJS(layoutMeasurements_exports);
var DEFAULT_CELL_SIZE = 64;
var DEFAULT_ITEM_GAP = 8;
function gapToPx(gap) {
  if (gap === void 0) return DEFAULT_ITEM_GAP;
  if (typeof gap === "number") return gap;
  const match = String(gap).match(/^(\d+(?:\.\d+)?)\s*px?$/i);
  return match ? Number(match[1]) : DEFAULT_ITEM_GAP;
}
function getContentSize(items, cellSize, itemGap, itemUnit) {
  if (!items.length) {
    if (itemUnit === "pixel") {
      return { contentWidth: cellSize * 4, contentHeight: cellSize * 3 };
    }
    const g2 = itemGap;
    return {
      contentWidth: 4 * (cellSize + g2) + g2,
      contentHeight: 3 * (cellSize + g2) + g2
    };
  }
  if (itemUnit === "pixel") {
    let maxRight = 0;
    let maxBottom = 0;
    for (const item of items) {
      const w = item.width ?? cellSize;
      const h = item.height ?? cellSize;
      maxRight = Math.max(maxRight, item.x + w);
      maxBottom = Math.max(maxBottom, item.y + h);
    }
    return { contentWidth: maxRight, contentHeight: maxBottom };
  }
  let maxX = 0;
  let maxY = 0;
  for (const item of items) {
    const w = item.width ?? 1;
    const h = item.height ?? 1;
    maxX = Math.max(maxX, item.x + w);
    maxY = Math.max(maxY, item.y + h);
  }
  const g = itemGap;
  return {
    contentWidth: maxX * (cellSize + g) + g,
    contentHeight: maxY * (cellSize + g) + g
  };
}
function getPixelBoundingBox(items, cellSize) {
  if (!items.length) return null;
  let minLeft = Infinity;
  let minTop = Infinity;
  let maxRight = -Infinity;
  let maxBottom = -Infinity;
  for (const item of items) {
    const w = item.width ?? cellSize;
    const h = item.height ?? cellSize;
    minLeft = Math.min(minLeft, item.x);
    minTop = Math.min(minTop, item.y);
    maxRight = Math.max(maxRight, item.x + w);
    maxBottom = Math.max(maxBottom, item.y + h);
  }
  return { minLeft, minTop, maxRight, maxBottom };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  DEFAULT_CELL_SIZE,
  DEFAULT_ITEM_GAP,
  gapToPx,
  getContentSize,
  getPixelBoundingBox
});
