import { B as isUnicodeSupported, V as randomBookSymbol, r as cliVersion, z as Logger } from "./util-CsmUMRtR.js";
import { a as _usingCtx, c as warnDeprecatedConfig, o as loadVivliostyleConfig, u as setupConfigFromFlags } from "./asset-DBj3nifv.js";
import { _ as mergeConfig, g as resolveTaskConfig, i as getViewerFullUrl, t as createViteServer, v as mergeInlineConfig } from "./server-CbkA4XCo.js";
import { t as resolveViteConfig } from "./vite-C-mM5_eo.js";
import { blueBright, cyan, dim } from "yoctocolors";
import terminalLink from "terminal-link";
//#region src/core/preview.ts
async function preview(inlineConfig) {
	Logger.setLogOptions(inlineConfig);
	Logger.debug("preview > inlineConfig %O", inlineConfig);
	let vivliostyleConfig = await loadVivliostyleConfig(inlineConfig) ?? setupConfigFromFlags(inlineConfig);
	warnDeprecatedConfig(vivliostyleConfig);
	vivliostyleConfig = mergeInlineConfig(vivliostyleConfig, inlineConfig);
	const { tasks, inlineOptions } = vivliostyleConfig;
	Logger.debug("preview > vivliostyleConfig %O", vivliostyleConfig);
	let config = resolveTaskConfig(tasks[0], inlineOptions);
	Logger.debug("preview > config %O", config);
	let server;
	let url;
	try {
		var _usingCtx$1 = _usingCtx();
		_usingCtx$1.u(Logger.startLogging("Start preview"));
		const viteConfig = await resolveViteConfig({
			...config,
			mode: "preview"
		});
		server = await createViteServer({
			config,
			viteConfig,
			inlineConfig,
			mode: "preview"
		});
		if (server.httpServer) {
			await server.listen();
			vivliostyleConfig = mergeConfig(vivliostyleConfig, {
				temporaryFilePrefix: config.temporaryFilePrefix,
				server: server.config.server
			});
			config = resolveTaskConfig(vivliostyleConfig.tasks[0], vivliostyleConfig.inlineOptions);
		}
		url = await getViewerFullUrl(config);
	} catch (_) {
		_usingCtx$1.e = _;
	} finally {
		_usingCtx$1.d();
	}
	if (server.httpServer) Logger.log(`
${cyan(`Vivliostyle CLI v${cliVersion}`)}
${blueBright("║")} ${isUnicodeSupported ? `${randomBookSymbol} ` : ""}Up and running (press Ctrl+C to quit)
${blueBright("╙─")} ${dim(`Preview URL: ${terminalLink(url, url, { fallback: () => url })}`)}
`);
	return server;
}
//#endregion
export { preview as t };

//# sourceMappingURL=preview-BEB_iy9U.js.map