import { F as versionForDisplay, _ as isInContainer, z as Logger } from "./util-CsmUMRtR.js";
import { l as createParserProgram } from "./asset-DBj3nifv.js";
import { t as build } from "./build-re0kdc5z.js";
import { r as runCliCommand } from "./entry-util-Bh1ksaYK.js";
import upath from "upath";
import process from "node:process";
import { Command, Option } from "commander";
//#region src/commands/build.parser.ts
function setupBuildParserProgram() {
	const targets = [];
	const outputOptionProcessor = (value, previous) => {
		const last = targets.at(-1);
		if (!last || "path" in last) targets.push({ path: value });
		else last.path = value;
		return [...previous ?? [], value];
	};
	const formatOptionProcessor = (value, previous) => {
		const last = targets.at(-1);
		if (!last || "format" in last) targets.push({ format: value });
		else last.format = value;
		return [...previous ?? [], value];
	};
	const program = new Command();
	program.name("vivliostyle build").description("build and create PDF file").arguments("[input]").option("-c, --config <config_file>", "path to vivliostyle.config.js [vivliostyle.config.js]").option("-o, --output <path>", `specify output file name or directory [<title>.pdf]
This option can be specified multiple, then each -o options can be supplied one -f option.
ex: -o output1 -f webpub -o output2.pdf -f pdf`, outputOptionProcessor).option("-f, --format <format>", `specify output format corresponding output target
If an extension is specified on -o option, this field will be inferenced automatically.`, formatOptionProcessor).option("-s, --size <size>", `output pdf size
preset: A5, A4, A3, B5, B4, JIS-B5, JIS-B4, letter, legal, ledger
custom(comma separated): 182mm,257mm or 8.5in,11in`).option("-m, --crop-marks", "print crop marks").option("--bleed <bleed>", "extent of the bleed area for printing with crop marks [3mm]").option("--crop-offset <offset>", "distance between the edge of the trim size and the edge of the media size. [auto (13mm + bleed)]").option("--css <CSS>", "custom style CSS code. (ex: \":root {--my-color: lime;}\")").option("--style <stylesheet>", "Additional stylesheet for Vivliostyle viewer.").option("--user-style <user_stylesheet>", "Additional user stylesheet for Vivliostyle viewer.").option("-d, --single-doc", "single HTML document input").option("-p, --press-ready", `make generated PDF compatible with press ready PDF/X-1a [false]
This option is equivalent with "--preflight press-ready"`).option("-t, --timeout <seconds>", `timeout limit for waiting Vivliostyle process [300]`, validateTimeoutFlag).option("-T, --theme <theme...>", "theme path or package name").option("--title <title>", "title").option("--author <author>", "author").option("-l, --language <language>", "language").addOption(new Option("--reading-progression <direction>", "Direction of reading progression").choices(["ltr", "rtl"])).addOption(new Option("--render-mode <mode>", "if docker is set, Vivliostyle tries to render PDF on Docker container [local] (note: `docker` is deprecated, see https://github.com/vivliostyle/vivliostyle-cli/issues/823)").choices(["local", "docker"])).addOption(new Option("--preflight <mode>", "apply the process to generate PDF for printing").choices(["press-ready", "press-ready-local"])).option("--preflight-option <options...>", `options for preflight process (ex: gray-scale, enforce-outline)
Please refer the document of press-ready for further information.
https://github.com/vibranthq/press-ready`).option("--cmyk", "convert device-cmyk() colors to CMYK in the output PDF").addOption(new Option("--sandbox", `launch chrome with sandbox`).hideHelp()).option("--executable-browser <path>", "specify a path of executable browser you installed").option("--image <image>", "specify a docker image to render").option("--viewer <URL>", `specify a URL of displaying viewer instead of vivliostyle-cli's one
It is useful that using own viewer that has staging features. (ex: https://vivliostyle.vercel.app/)`).option("--viewer-param <parameters>", `specify viewer parameters. (ex: "allowScripts=false&pixelRatio=16")`).addOption(new Option("--browser <browser>", `Specify a browser type and version to launch the Vivliostyle viewer (ex: chrome@129, firefox) [chrome]`)).addOption(new Option("--proxy-server <proxyServer>", `HTTP/SOCK proxy server url for underlying Playwright`)).addOption(new Option("--proxy-bypass <proxyBypass>", `optional comma-separated domains to bypass proxy`)).addOption(new Option("--proxy-user <proxyUser>", `optional username for HTTP proxy authentication`)).addOption(new Option("--proxy-pass <proxyPass>", `optional password for HTTP proxy authentication`)).addOption(new Option("--log-level <level>", "specify a log level of console outputs").choices([
		"silent",
		"info",
		"verbose",
		"debug"
	]).default("info")).addOption(new Option("--ignore-https-errors", `true to ignore HTTPS errors when Playwright browser opens a new page`)).option("--host <host>", "IP address the server should listen on").option("--port <port>", "port the server should listen on", parseInt).option("--no-enable-static-serve", "disable static file serving").option("--vite-config-file <path>", "Vite config file path").option("--no-vite-config-file", "ignore Vite config file even if it exists").version(versionForDisplay, "-v, --version").action((_arg, option) => {
		const invalid = targets.find((it) => !("path" in it));
		if (invalid) throw new Error(`Couldn't find the output option corresponding --format ${invalid.format} option. Please check the command options.`);
		option.output = targets;
	});
	return program;
}
function validateTimeoutFlag(val) {
	return Number.isFinite(+val) ? +val * 1e3 : void 0;
}
const parseBuildCommand = createParserProgram({
	setupProgram: setupBuildParserProgram,
	parseArgs: (options, [input]) => {
		if (input && !options.config && upath.basename(input).startsWith("vivliostyle.config")) return {
			...options,
			config: input
		};
		return {
			...options,
			input
		};
	}
});
//#endregion
//#region src/commands/build.runner.ts
async function runBuildCli(argv) {
	await runCliCommand(async (cliSignal) => {
		let inlineConfig = parseBuildCommand(argv);
		let containerForkMode = false;
		if (isInContainer() && process.env.VS_CLI_BUILD_PDF_OPTIONS) {
			inlineConfig = JSON.parse(process.env.VS_CLI_BUILD_PDF_OPTIONS);
			containerForkMode = true;
			Logger.debug("bypassedPdfBuilderOption %O", inlineConfig);
		}
		await build({
			...inlineConfig,
			signal: cliSignal
		}, { containerForkMode });
	});
}
//#endregion
export { runBuildCli as t };

//# sourceMappingURL=build.runner-D2aPDESZ.js.map