//#region src/components/pisellFloorMapLayout/hooks/floorMapViewportPersistence.ts
/** 平面图视口（缩放 + 平移）持久化到 localStorage 的 key 前缀 */
const VIEWPORT_STORAGE_PREFIX = "pisell-floor-map-layout.viewport:";
/** 视口锁定态持久化前缀（与视口位置分开存储） */
const VIEWPORT_LOCK_STORAGE_PREFIX = "pisell-floor-map-layout.viewport-lock:";
/** 判定当前 transform 是否处于「适配视口」结果时的容差 */
const FIT_BOUNDS_MATCH_POS_EPSILON = .5;
const FIT_BOUNDS_MATCH_SCALE_EPSILON = .005;
function readPersistedViewport(key) {
	if (typeof window === "undefined") return null;
	try {
		const raw = window.localStorage.getItem(VIEWPORT_STORAGE_PREFIX + key);
		if (!raw) return null;
		const parsed = JSON.parse(raw);
		if (!parsed || typeof parsed.x !== "number" || typeof parsed.y !== "number" || typeof parsed.scale !== "number" || !Number.isFinite(parsed.x) || !Number.isFinite(parsed.y) || !Number.isFinite(parsed.scale) || parsed.scale <= 0) return null;
		return {
			x: parsed.x,
			y: parsed.y,
			scale: parsed.scale
		};
	} catch (_unused) {
		return null;
	}
}
function writePersistedViewport(key, snapshot) {
	if (typeof window === "undefined") return;
	try {
		window.localStorage.setItem(VIEWPORT_STORAGE_PREFIX + key, JSON.stringify(snapshot));
	} catch (_unused2) {}
}
function readPersistedViewportLock(key) {
	if (typeof window === "undefined") return false;
	try {
		return window.localStorage.getItem(VIEWPORT_LOCK_STORAGE_PREFIX + key) === "1";
	} catch (_unused3) {
		return false;
	}
}
function writePersistedViewportLock(key, locked) {
	if (typeof window === "undefined") return;
	try {
		if (locked) window.localStorage.setItem(VIEWPORT_LOCK_STORAGE_PREFIX + key, "1");
		else window.localStorage.removeItem(VIEWPORT_LOCK_STORAGE_PREFIX + key);
	} catch (_unused4) {}
}
//#endregion
export { FIT_BOUNDS_MATCH_POS_EPSILON, FIT_BOUNDS_MATCH_SCALE_EPSILON, readPersistedViewport, readPersistedViewportLock, writePersistedViewport, writePersistedViewportLock };
