//#region src-js/libs/apis.ts
const CACHES = {
	prettier: null,
	tailwindPlugin: null,
	tailwindSorter: null,
	oxfmtPlugin: null
};
async function loadPrettier() {
	if (!CACHES.prettier) {
		CACHES.prettier = await import("./prettier-CU6WrYtk.js");
		const { formatOptionsHiddenDefaults } = CACHES.prettier.__internal;
		formatOptionsHiddenDefaults.parentParser = null;
		formatOptionsHiddenDefaults.__onHtmlRoot = null;
		formatOptionsHiddenDefaults.__inJsTemplate = null;
	}
	return CACHES.prettier;
}
/**
* TODO: Plugins support
* - Read `plugins` field
* - Load plugins dynamically and parse `languages` field
* - Map file extensions and filenames to Prettier parsers
*
* @returns Array of loaded plugin's `languages` info
*/
async function resolvePlugins() {
	return [];
}
/**
* Format non-js file
*
* @returns Formatted code
*/
async function formatFile({ code, options }) {
	const prettier = CACHES.prettier ?? await loadPrettier();
	if ("_useTailwindPlugin" in options) await setupTailwindPlugin(options);
	if ("_oxfmtPluginOptionsJson" in options) await setupOxfmtPlugin(options);
	return prettier.format(code, options);
}
/**
* Format non-js code snippets into formatted string.
* Mainly used for formatting code fences within JSDoc,
* and is also used as a temporary fallback for html-in-js.
*
* @returns Formatted code snippet
*/
async function formatEmbeddedCode({ code, options }) {
	const prettier = CACHES.prettier ?? await loadPrettier();
	if ("_useTailwindPlugin" in options) await setupTailwindPlugin(options);
	return prettier.format(code, options);
}
/**
* Format non-js code snippets into Prettier `Doc` JSON strings.
*
* This makes our printer correctly handle `printWidth` even for embedded code.
* - For gql-in-js, `texts` contains multiple parts split by `${}` in a template literal
* - For others, `texts` always contains a single string with `${}` parts replaced by placeholders
* However, this function does not need to be aware of that,
* as it simply formats each text part independently and returns an array of formatted parts.
*
* @returns Doc JSON strings
*/
async function formatEmbeddedDoc({ texts, options }) {
	const prettier = CACHES.prettier ?? await loadPrettier();
	if ("_useTailwindPlugin" in options) await setupTailwindPlugin(options);
	return Promise.all(texts.map(async (text) => {
		const metadata = {};
		if (options.parser === "html" || options.parser === "angular") {
			options.parentParser = "OXFMT";
			options.__onHtmlRoot = (root) => metadata.htmlHasMultipleRootElements = (root.children?.length ?? 0) > 1;
		}
		if (options.parser === "markdown") options.__inJsTemplate = true;
		const doc = await prettier.__debug.printToDoc(text, options);
		const symbolToNumber = /* @__PURE__ */ new Map();
		let nextId = 1;
		return JSON.stringify([doc, metadata], (_key, value) => {
			if (typeof value === "symbol") {
				if (!symbolToNumber.has(value)) symbolToNumber.set(value, nextId++);
				return symbolToNumber.get(value);
			}
			if (value === -Infinity) return "__NEGATIVE_INFINITY__";
			return value;
		});
	}));
}
async function loadTailwindPlugin() {
	if (!CACHES.tailwindPlugin) CACHES.tailwindPlugin = await import("./dist-CKaxC7ER.js");
	return CACHES.tailwindPlugin;
}
/**
* Load Tailwind CSS plugin.
* Option mapping (sortTailwindcss.xxx → tailwindXxx) is also done in Rust side.
*/
async function setupTailwindPlugin(options) {
	const tailwindPlugin = CACHES.tailwindPlugin ?? await loadTailwindPlugin();
	options.plugins ??= [];
	options.plugins.push(tailwindPlugin);
}
async function loadTailwindSorter() {
	if (!CACHES.tailwindSorter) CACHES.tailwindSorter = await import("./sorter-QhZPi-JI.js");
	return CACHES.tailwindSorter;
}
/**
* Process Tailwind CSS classes found in JS/TS files in batch.
* @param args - Object containing classes and options (filepath is in options.filepath)
* @returns Array of sorted class strings (same order/length as input)
*/
async function sortTailwindClasses({ classes, options }) {
	const { createSorter } = CACHES.tailwindSorter ?? await loadTailwindSorter();
	return (await createSorter({
		filepath: options.filepath,
		stylesheetPath: options.tailwindStylesheet,
		configPath: options.tailwindConfig,
		preserveWhitespace: options.tailwindPreserveWhitespace,
		preserveDuplicates: options.tailwindPreserveDuplicates
	})).sortClassAttributes(classes);
}
async function loadOxfmtPlugin() {
	if (!CACHES.oxfmtPlugin) CACHES.oxfmtPlugin = await import("./prettier-plugin-oxfmt-CLoiASgP.js");
	return CACHES.oxfmtPlugin;
}
/**
* Load oxfmt plugin for js-in-xxx parsers.
*/
async function setupOxfmtPlugin(options) {
	const oxcPlugin = CACHES.oxfmtPlugin ?? await loadOxfmtPlugin();
	options.plugins ??= [];
	options.plugins.push(oxcPlugin);
}
//#endregion
export { sortTailwindClasses as a, resolvePlugins as i, formatEmbeddedDoc as n, formatFile as r, formatEmbeddedCode as t };
