const chunkOffsetSpaceFor = (chunk) => {
    if (chunk.alignment?.boundaryOffsetMode)
        return chunk.alignment.boundaryOffsetMode;
    const mathOffsetSpace = chunk.mathAlignment?.speech.boundaryOffsetSpace;
    if (mathOffsetSpace)
        return mathOffsetSpace;
    return "plain-spoken-text";
};
const mathAlignmentsFor = (chunk) => {
    if (chunk.mathAlignments?.length)
        return chunk.mathAlignments;
    if (chunk.mathAlignment && chunk.sourceElement) {
        return [{ element: chunk.sourceElement, alignment: chunk.mathAlignment }];
    }
    return [];
};
export const normalizeSpeechChunks = (args) => {
    const sourceChunks = args.chunks && args.chunks.length
        ? args.chunks
        : [
            {
                speechText: args.speechText || "",
                visibleText: args.visibleText || args.speechText || "",
                sourceElement: args.sourceElement || args.contentRoot,
                regionElement: args.regionElement || args.sourceElement || args.contentRoot,
                regionRange: args.regionRange,
                visibleMap: args.visibleMap,
            },
        ];
    return sourceChunks.map((chunk, index) => ({
        id: `tts-chunk-${index}`,
        speechText: chunk.speechText,
        visibleText: chunk.visibleText,
        sourceElement: chunk.sourceElement,
        contentRoot: args.contentRoot,
        regionElement: chunk.regionElement ?? chunk.sourceElement,
        regionRange: chunk.regionRange,
        visibleMap: chunk.visibleMap,
        catalogAlignment: chunk.alignment,
        mathAlignments: mathAlignmentsFor(chunk),
        offsetSpace: chunkOffsetSpaceFor(chunk),
    }));
};
//# sourceMappingURL=normalize-speech-chunks.js.map