import { t as _plugin_vue_export_helper_default } from "./_plugin-vue_export-helper-BmmBcIzD.js";
import { createElementBlock, createElementVNode, defineComponent, normalizeStyle, openBlock, ref, renderSlot } from "vue";
//#region src/v2/components/resize/Resize.vue?vue&type=script&setup=true&lang.ts
var draggingClassName = "scalar-dragging";
//#endregion
//#region src/v2/components/resize/Resize.vue
var Resize_default = /* @__PURE__ */ _plugin_vue_export_helper_default(/* @__PURE__ */ defineComponent({
	__name: "Resize",
	props: { width: {} },
	emits: ["update:width"],
	setup(__props, { emit: __emit }) {
		const emit = __emit;
		const isDragging = ref(false);
		const startDrag = (event) => {
			event.preventDefault();
			const startX = event.clientX;
			/** Current sidebar width when dragging starts */
			const startWidth = __props.width;
			const doDrag = (dragEvent) => {
				isDragging.value = true;
				document.body.classList.add(draggingClassName);
				let newWidth = startWidth + dragEvent.clientX - startX;
				if (newWidth > 420)
 /** Elastic effect */
				newWidth = 420 + (newWidth - 420) * .2;
				if (newWidth < 240) newWidth = 240;
				emit("update:width", newWidth);
			};
			const stopDrag = () => {
				isDragging.value = false;
				document.body.classList.remove(draggingClassName);
				document.documentElement.removeEventListener("mousemove", doDrag, false);
				document.documentElement.removeEventListener("mouseup", stopDrag, false);
				/** Reset to max width if exceeded */
				if (__props.width > 420) emit("update:width", 360);
				else if (__props.width < 240) emit("update:width", 240);
			};
			document.documentElement.addEventListener("mousemove", doDrag, false);
			document.documentElement.addEventListener("mouseup", stopDrag, false);
		};
		return (_ctx, _cache) => {
			return openBlock(), createElementBlock("div", {
				class: "relative",
				style: normalizeStyle({ width: `${__props.width}px` })
			}, [renderSlot(_ctx.$slots, "default", {}, void 0, true), createElementVNode("div", {
				class: "resizer",
				onMousedown: startDrag
			}, null, 32)], 4);
		};
	}
}), [["__scopeId", "data-v-e2c54c18"]]);
//#endregion
//#region src/v2/components/resize/use-split-resize.ts
var clamp = (value, min, max) => Math.min(max, Math.max(min, value));
/**
* Shared pointer-based resize logic for split layouts with percentage sizes.
* Use when you have both a horizontal split (e.g. left/right) and a vertical split (e.g. top/bottom).
* Only one resize is active at a time; starting another stops the previous.
*/
function useSplitResize(options) {
	const { horizontalContainerRef, verticalContainerRef, leftPaneSize, topPaneSize, horizontalMin = 20, horizontalMax = 80, verticalMin = 25, verticalMax = 75 } = options;
	let activeResizeCleanup;
	const stopActiveResize = () => {
		activeResizeCleanup?.();
		activeResizeCleanup = void 0;
	};
	const startResize = (event, onMove, cursor) => {
		event.preventDefault();
		stopActiveResize();
		const previousUserSelect = document.body.style.userSelect;
		const previousCursor = document.body.style.cursor;
		document.body.style.userSelect = "none";
		document.body.style.cursor = cursor;
		const handleMove = (moveEvent) => {
			onMove(moveEvent);
		};
		const handleUp = () => {
			stopActiveResize();
		};
		window.addEventListener("pointermove", handleMove);
		window.addEventListener("pointerup", handleUp, { once: true });
		activeResizeCleanup = () => {
			window.removeEventListener("pointermove", handleMove);
			window.removeEventListener("pointerup", handleUp);
			document.body.style.userSelect = previousUserSelect;
			document.body.style.cursor = previousCursor;
		};
	};
	const onHorizontalResizeStart = (event) => {
		const el = horizontalContainerRef.value;
		if (!el) return;
		startResize(event, (moveEvent) => {
			const rect = el.getBoundingClientRect();
			leftPaneSize.value = clamp((moveEvent.clientX - rect.left) / rect.width * 100, horizontalMin, horizontalMax);
		}, "col-resize");
	};
	const onVerticalResizeStart = (event) => {
		const el = verticalContainerRef.value;
		if (!el) return;
		startResize(event, (moveEvent) => {
			const rect = el.getBoundingClientRect();
			topPaneSize.value = clamp((moveEvent.clientY - rect.top) / rect.height * 100, verticalMin, verticalMax);
		}, "row-resize");
	};
	return {
		onHorizontalResizeStart,
		onVerticalResizeStart,
		stopActiveResize
	};
}
//#endregion
export { Resize_default as n, useSplitResize as t };

//# sourceMappingURL=resize-D2IYvVdh.js.map