//#region src/util/dataUrl.ts
/**
* Check if a string is a data URL
* @param value String to check
* @returns true if value is a data URL (starts with "data:")
*
* @example
* isDataUrl("data:image/jpeg;base64,/9j/...") // true
* isDataUrl("/9j/4AAQSkZJRg...") // false
* isDataUrl("https://example.com/image.jpg") // false
*/
function isDataUrl(value) {
	return typeof value === "string" && value.startsWith("data:") && value.length > 5;
}
/**
* Parse a data URL into its components
*
* Handles data URLs with optional parameters (e.g., charset, name):
* - `data:image/jpeg;base64,<data>` - Standard format
* - `data:image/jpeg;charset=utf-8;base64,<data>` - With charset
* - `data:image/jpeg;name=photo.jpg;base64,<data>` - With filename
*
* @param dataUrl Data URL string
* @returns Parsed components (mimeType and base64Data) or null if invalid
*
* @example
* parseDataUrl("data:image/jpeg;base64,/9j/...")
* // { mimeType: "image/jpeg", base64Data: "/9j/..." }
*
* parseDataUrl("data:image/jpeg;charset=utf-8;base64,/9j/...")
* // { mimeType: "image/jpeg", base64Data: "/9j/..." }
*
* parseDataUrl("invalid") // null
*/
function parseDataUrl(dataUrl) {
	if (!isDataUrl(dataUrl)) return null;
	const match = dataUrl.match(/^data:([^;,]+)(?:;[^,]*)?;base64,(.+)$/);
	if (!match) return null;
	return {
		mimeType: match[1].trim(),
		base64Data: match[2].trim()
	};
}
/**
* Extract base64 data from a data URL or return original if not a data URL
* Useful for providers that expect raw base64 (Anthropic, Google)
*
* @param value Data URL or raw base64 string
* @returns Raw base64 string (data URL prefix stripped if present)
*
* @example
* extractBase64FromDataUrl("data:image/jpeg;base64,/9j/...")
* // "/9j/..."
*
* extractBase64FromDataUrl("/9j/...") // "/9j/..." (unchanged)
*/
function extractBase64FromDataUrl(value) {
	const parsed = parseDataUrl(value);
	return parsed ? parsed.base64Data : value;
}
/**
* Build a data URI from a MIME type and base64 data.
*
* @param mimeType MIME type (e.g. "image/png")
* @param base64Data Raw base64-encoded data
* @returns Data URI string
*
* @example
* toDataUri("image/png", "iVBORw0KGgo...")
* // "data:image/png;base64,iVBORw0KGgo..."
*/
function toDataUri(mimeType, base64Data) {
	return `data:${mimeType};base64,${base64Data}`;
}
//#endregion
export { toDataUri as i, isDataUrl as n, parseDataUrl as r, extractBase64FromDataUrl as t };

//# sourceMappingURL=dataUrl-BI7lhJra.js.map