/**
* 将 mapLayer.gap 解析为像素数
*/
function gapToPx(gap) {
	if (gap === void 0) return 8;
	if (typeof gap === "number") return gap;
	const match = String(gap).match(/^(\d+(?:\.\d+)?)\s*px?$/i);
	return match ? Number(match[1]) : 8;
}
/**
* 根据 items 计算内容区像素宽高
* - cell：按格子数 + cellSize + itemGap 计算
* - pixel：按 item 的 x/y/width/height 像素取边界（仅右/下边界，用于非 floor map 或兼容）
*/
function getContentSize(items, cellSize, itemGap, itemUnit) {
	if (!items.length) {
		if (itemUnit === "pixel") return {
			contentWidth: cellSize * 4,
			contentHeight: cellSize * 3
		};
		const g = itemGap;
		return {
			contentWidth: 4 * (cellSize + g) + g,
			contentHeight: 3 * (cellSize + g) + g
		};
	}
	if (itemUnit === "pixel") {
		let maxRight = 0;
		let maxBottom = 0;
		for (const item of items) {
			var _item$width, _item$height;
			const w = (_item$width = item.width) !== null && _item$width !== void 0 ? _item$width : cellSize;
			const h = (_item$height = item.height) !== null && _item$height !== void 0 ? _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) {
		var _item$width2, _item$height2;
		const w = (_item$width2 = item.width) !== null && _item$width2 !== void 0 ? _item$width2 : 1;
		const h = (_item$height2 = item.height) !== null && _item$height2 !== void 0 ? _item$height2 : 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
	};
}
/**
* pixel 模式下取 items 包围盒（含左/上），用于画布四周扩 padding 时的尺寸与偏移
*/
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) {
		var _item$width3, _item$height3;
		const w = (_item$width3 = item.width) !== null && _item$width3 !== void 0 ? _item$width3 : cellSize;
		const h = (_item$height3 = item.height) !== null && _item$height3 !== void 0 ? _item$height3 : 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
	};
}
//#endregion
exports.gapToPx = gapToPx;
exports.getContentSize = getContentSize;
exports.getPixelBoundingBox = getPixelBoundingBox;
