//#region extensions/telegram/src/caption.ts
/**
* Telegram Caption Utilities
*
* Handles splitting text for media captions vs follow-up messages.
* Telegram captions have a 1024 character limit.
*/
const TELEGRAM_CAPTION_LIMIT = 1024;
/**
* Split text into caption and follow-up text
* Tries to split at natural boundaries (paragraphs, sentences)
*/
function splitTelegramCaption(text) {
	if (!text || text.length <= TELEGRAM_CAPTION_LIMIT) return {
		caption: text || "",
		followUpText: void 0,
		wasSplit: false
	};
	let splitIndex = findGoodSplitPoint(text, TELEGRAM_CAPTION_LIMIT);
	if (splitIndex <= 0) splitIndex = TELEGRAM_CAPTION_LIMIT;
	return {
		caption: text.slice(0, splitIndex).trim(),
		followUpText: text.slice(splitIndex).trim() || void 0,
		wasSplit: true
	};
}
/**
* Find a good split point near the limit
* Prefers: paragraph break > sentence break > word break
*/
function findGoodSplitPoint(text, limit) {
	const searchStart = Math.min(limit, text.length);
	const searchEnd = Math.max(0, limit - 200);
	for (let i = searchStart; i >= searchEnd; i--) if (text.slice(i - 2, i) === "\n\n") return i;
	const sentencePattern = /[.!?]\s+/g;
	let match;
	let lastMatchIndex = -1;
	while ((match = sentencePattern.exec(text)) !== null) if (match.index > searchEnd && match.index <= searchStart) lastMatchIndex = match.index + 1;
	else if (match.index > searchStart) break;
	if (lastMatchIndex > 0) return lastMatchIndex;
	for (let i = searchStart; i >= searchEnd; i--) if (text[i] === " " || text[i] === "\n") return i;
	return limit;
}
//#endregion
export { splitTelegramCaption };

//# sourceMappingURL=caption.js.map