/*! ratio-ui · design system for knowledge sharing · https://github.com/losol/ratio-ui · (c) 2026 Losol AS · MPL-2.0 */
import React from "react";
//#region src/blocks/Story/utils.ts
/**
* Converts heading text to a URL-safe ID for anchor links
*
* @param text - The text to convert to an ID
* @returns A URL-safe ID string
*
* @example
* ```ts
* textToId("Hello World!") // "hello-world"
* textToId("TypeScript & React") // "typescript-react"
* ```
*/
function textToId(text) {
	return (Array.isArray(text) ? text.join("") : text).toLowerCase().replaceAll(/\s+/g, "-").replaceAll(/[^a-z0-9-]/g, "").replaceAll(/-+/g, "-").replaceAll(/^-|-$/g, "");
}
/**
* Extracts text content from React children
* Useful for generating IDs from heading elements
*
* @param children - React children to extract text from
* @returns Extracted text as string
*/
function extractTextFromChildren(children) {
	if (typeof children === "string") return children;
	if (Array.isArray(children)) return children.map(extractTextFromChildren).join("");
	if (React.isValidElement(children)) {
		const props = children.props;
		if (props.children) return extractTextFromChildren(props.children);
	}
	return "";
}
/**
* Type guard to check if a value is a valid internal link relation
*/
function isValidRelation(value) {
	return typeof value === "object" && value !== null && "slug" in value;
}
//#endregion
export { extractTextFromChildren, isValidRelation, textToId };

//# sourceMappingURL=utils.js.map