//#region src/preview/previewSettings.ts
const STORAGE_KEY_PRESENTATION_MODE = "ef-preview-presentation-mode";
const STORAGE_KEY_RENDER_MODE = "ef-preview-render-mode";
const STORAGE_KEY_RESOLUTION_SCALE = "ef-preview-resolution-scale";
const STORAGE_KEY_SHOW_STATS = "ef-preview-show-stats";
const STORAGE_KEY_SHOW_THUMBNAIL_TIMESTAMPS = "ef-preview-show-thumbnail-timestamps";
/**
* Cached detection result for native HTML-in-Canvas API availability.
* This is separate from the user preference - it detects browser capability.
*/
let _nativeApiAvailable = null;
/**
* Detect if the native HTML-in-Canvas API (drawElementImage) is available in this browser.
* This checks browser capability, not user preference.
*
* The API is available in Chrome Canary with chrome://flags/#canvas-draw-element
* @see https://github.com/WICG/html-in-canvas
*/
function isNativeCanvasApiAvailable() {
	if (_nativeApiAvailable === null) {
		const ctx = document.createElement("canvas").getContext("2d");
		_nativeApiAvailable = ctx !== null && "drawElementImage" in ctx;
	}
	return _nativeApiAvailable;
}
/**
* Get the current preview presentation mode.
* Defaults to "dom" if not set.
*/
function getPreviewPresentationMode() {
	try {
		const stored = localStorage.getItem(STORAGE_KEY_PRESENTATION_MODE);
		if (stored === "dom" || stored === "canvas") return stored;
		return "dom";
	} catch {
		return "dom";
	}
}
/**
* Set the preview presentation mode.
* Persists to localStorage and dispatches a change event.
*/
function setPreviewPresentationMode(mode) {
	try {
		localStorage.setItem(STORAGE_KEY_PRESENTATION_MODE, mode);
	} catch {}
	window.dispatchEvent(new CustomEvent("ef-preview-settings-changed", { detail: { presentationMode: mode } }));
}
/**
* Get the current render mode for HTML-to-canvas capture.
* Defaults to "native" if available, otherwise "foreignObject".
*
* Checks EF_NATIVE_RENDER URL parameter to force native mode when set.
*/
function getRenderMode() {
	try {
		if (new URLSearchParams(window.location.search).get("EF_NATIVE_RENDER") === "1") return isNativeCanvasApiAvailable() ? "native" : "foreignObject";
	} catch {}
	try {
		const stored = localStorage.getItem(STORAGE_KEY_RENDER_MODE);
		if (stored === "foreignObject" || stored === "native") return stored;
		return isNativeCanvasApiAvailable() ? "native" : "foreignObject";
	} catch {
		return isNativeCanvasApiAvailable() ? "native" : "foreignObject";
	}
}
/**
* Set the render mode for HTML-to-canvas capture.
* Persists to localStorage and dispatches a change event.
*/
function setRenderMode(mode) {
	try {
		localStorage.setItem(STORAGE_KEY_RENDER_MODE, mode);
	} catch {}
	window.dispatchEvent(new CustomEvent("ef-preview-settings-changed", { detail: { renderMode: mode } }));
}
/**
* Valid numeric resolution scale values.
*/
const VALID_NUMERIC_SCALES = [
	1,
	.75,
	.5,
	.25
];
/**
* Get the current preview resolution scale.
* Defaults to 1 (full resolution) if not set.
*/
function getPreviewResolutionScale() {
	try {
		const stored = localStorage.getItem(STORAGE_KEY_RESOLUTION_SCALE);
		if (stored !== null) {
			if (stored === "auto") return "auto";
			const parsed = parseFloat(stored);
			if (VALID_NUMERIC_SCALES.includes(parsed)) return parsed;
		}
		return 1;
	} catch {
		return 1;
	}
}
/**
* Get whether performance stats should be shown.
* Defaults to false (stats hidden by default).
*/
function getShowStats() {
	try {
		return localStorage.getItem(STORAGE_KEY_SHOW_STATS) === "true";
	} catch {
		return false;
	}
}
/**
* Set whether performance stats should be shown.
* Persists to localStorage and dispatches a change event.
*/
function setShowStats(enabled) {
	try {
		localStorage.setItem(STORAGE_KEY_SHOW_STATS, String(enabled));
	} catch {}
	window.dispatchEvent(new CustomEvent("ef-preview-settings-changed", { detail: { showStats: enabled } }));
}
/**
* Get whether thumbnail timestamps should be shown.
* Defaults to false (timestamps hidden by default).
*/
function getShowThumbnailTimestamps() {
	try {
		return localStorage.getItem(STORAGE_KEY_SHOW_THUMBNAIL_TIMESTAMPS) === "true";
	} catch {
		return false;
	}
}
/**
* Set whether thumbnail timestamps should be shown.
* Persists to localStorage and dispatches a change event.
*/
function setShowThumbnailTimestamps(enabled) {
	try {
		localStorage.setItem(STORAGE_KEY_SHOW_THUMBNAIL_TIMESTAMPS, String(enabled));
	} catch {}
	window.dispatchEvent(new CustomEvent("ef-preview-settings-changed", { detail: { showThumbnailTimestamps: enabled } }));
}

//#endregion
export { getPreviewPresentationMode, getPreviewResolutionScale, getRenderMode, getShowStats, getShowThumbnailTimestamps, isNativeCanvasApiAvailable, setPreviewPresentationMode, setRenderMode, setShowStats, setShowThumbnailTimestamps };
//# sourceMappingURL=previewSettings.js.map