// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Characters that should be ignored for word highlighting when not accompanied
// by other characters.
const IGNORED_HIGHLIGHT_CHARACTERS_REGEX = /^[.,!?'"(){}\[\]]+$/;
// Opening punctuation characters that text segmentation should not end a
// sentence on if there's a valid sentence after the current sentence. This
// reduces the risk of opening punctuation characters being read out loud
// by read aloud.
const OPENING_PUNCTUATION_CHARACTERS_REGEX = /[({<[]+$/;
export function getCurrentSpeechRate() {
    let rate = chrome.readingMode.speechRate;
    // 
    // ChromeOS supports speech rates of 3.0 and 4.0, which is unsupported
    // on reading mode on Windows, Mac, and Linux. If a user has set their
    // preferences to be a voice speed of higher than 2x on ChromeOS and then
    // uses reading mode on a non-ChromeOS platform, cap the speech rate
    // at 2x.
    rate = Math.min(chrome.readingMode.speechRate, 2.0);
    // 
    return parseFloat(rate.toFixed(1));
}
// If a highlight is just white space or punctuation, we can skip
// highlighting.
export function isInvalidHighlightForWordHighlighting(textToHighlight) {
    const text = textToHighlight?.trim();
    return !text || text === '' || IGNORED_HIGHLIGHT_CHARACTERS_REGEX.test(text);
}
// If the given text ends with opening punctuation.
export function textEndsWithOpeningPunctuation(text) {
    return text.match(OPENING_PUNCTUATION_CHARACTERS_REGEX);
}
