//#region src/jsonld.ts
const LS_RE = /\u2028/g;
const PS_RE = /\u2029/g;
/**
* XSS-safe JSON-LD serializer — security-union escape (trance escape-all + U+2028/U+2029).
* Escaping every `<` subsumes `<\/script`, `<!--`, and case/spacing variants.
*/
function serializeJsonLd(obj) {
	return JSON.stringify(obj).replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026").replace(LS_RE, "\\u2028").replace(PS_RE, "\\u2029");
}
function buildBreadcrumbList(items) {
	return {
		"@context": "https://schema.org",
		"@type": "BreadcrumbList",
		itemListElement: items.map((item, index) => ({
			"@type": "ListItem",
			position: index + 1,
			name: item.name,
			item: item.url
		}))
	};
}
function buildOrganization(input) {
	const org = {
		"@context": "https://schema.org",
		"@type": "Organization",
		name: input.name,
		url: input.url
	};
	if (input.logo) org.logo = input.logo;
	return org;
}
function buildWebSite(input) {
	const site = {
		"@context": "https://schema.org",
		"@type": "WebSite",
		name: input.name,
		url: input.url
	};
	if (input.searchUrlTemplate) site.potentialAction = {
		"@type": "SearchAction",
		target: input.searchUrlTemplate,
		"query-input": "required name=search_term_string"
	};
	return site;
}
/** Framework-agnostic inline JSON-LD script tag (serialized payload cannot break out). */
function renderJsonLdScript(obj) {
	return `<script type="application/ld+json">${serializeJsonLd(obj)}<\/script>`;
}
//#endregion
export { buildBreadcrumbList, buildOrganization, buildWebSite, renderJsonLdScript, serializeJsonLd };
