| 1 |
/************************************************************* |
| 2 |
* |
| 3 |
* Copyright (c) 2018-2022 The MathJax Consortium |
| 4 |
* |
| 5 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 |
* you may not use this file except in compliance with the License. |
| 7 |
* You may obtain a copy of the License at |
| 8 |
* |
| 9 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
* |
| 11 |
* Unless required by applicable law or agreed to in writing, software |
| 12 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 13 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 |
* See the License for the specific language governing permissions and |
| 15 |
* limitations under the License. |
| 16 |
*/ |
| 17 |
|
| 18 |
/** |
| 19 |
* @fileoverview Provides the interface functionality to SRE. |
| 20 |
* |
| 21 |
* @author [email protected] (Davide Cervone) |
| 22 |
* @author [email protected] (Volker Sorge) |
| 23 |
*/ |
| 24 |
|
| 25 |
import * as Api from 'speech-rule-engine/js/common/system.js'; |
| 26 |
import {Walker} from 'speech-rule-engine/js/walker/walker.js'; |
| 27 |
import * as WalkerFactory from 'speech-rule-engine/js/walker/walker_factory.js'; |
| 28 |
import * as SpeechGeneratorFactory from 'speech-rule-engine/js/speech_generator/speech_generator_factory.js'; |
| 29 |
import * as EngineConst from 'speech-rule-engine/js/common/engine_const.js'; |
| 30 |
import Engine from 'speech-rule-engine/js/common/engine.js'; |
| 31 |
import {ClearspeakPreferences} from 'speech-rule-engine/js/speech_rules/clearspeak_preferences.js'; |
| 32 |
import {Highlighter} from 'speech-rule-engine/js/highlighter/highlighter.js'; |
| 33 |
import * as HighlighterFactory from 'speech-rule-engine/js/highlighter/highlighter_factory.js'; |
| 34 |
import {SpeechGenerator} from 'speech-rule-engine/js/speech_generator/speech_generator.js'; |
| 35 |
import {Variables} from 'speech-rule-engine/js/common/variables.js'; |
| 36 |
import MathMaps from './mathmaps.js'; |
| 37 |
|
| 38 |
export namespace Sre { |
| 39 |
|
| 40 |
export type highlighter = Highlighter; |
| 41 |
|
| 42 |
export type speechGenerator = SpeechGenerator; |
| 43 |
|
| 44 |
export type walker = Walker; |
| 45 |
|
| 46 |
|
| 47 |
export const locales = Variables.LOCALES; |
| 48 |
|
| 49 |
export const sreReady = Api.engineReady; |
| 50 |
|
| 51 |
export const setupEngine = Api.setupEngine; |
| 52 |
|
| 53 |
export const engineSetup = Api.engineSetup; |
| 54 |
|
| 55 |
export const toEnriched = Api.toEnriched; |
| 56 |
|
| 57 |
export const toSpeech = Api.toSpeech; |
| 58 |
|
| 59 |
export const clearspeakPreferences = ClearspeakPreferences; |
| 60 |
|
| 61 |
export const getHighlighter = HighlighterFactory.highlighter; |
| 62 |
|
| 63 |
export const getSpeechGenerator = SpeechGeneratorFactory.generator; |
| 64 |
|
| 65 |
export const getWalker = WalkerFactory.walker; |
| 66 |
|
| 67 |
export const clearspeakStyle = () => { |
| 68 |
return EngineConst.DOMAIN_TO_STYLES['clearspeak']; |
| 69 |
}; |
| 70 |
|
| 71 |
/** |
| 72 |
* Loads locales that are already included in the imported MathMaps. Defaults |
| 73 |
* to standard loading if a locale is not yet preloaded. |
| 74 |
*/ |
| 75 |
export const preloadLocales = async function(locale: string) { |
| 76 |
const json = MathMaps.get(locale); |
| 77 |
return json ? new Promise((res, _rej) => res(JSON.stringify(json))) : |
| 78 |
Api.localeLoader()(locale); |
| 79 |
}; |
| 80 |
|
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* A promise that resolves when SRE is loaded and ready, and rejects if |
| 85 |
* SRE can't be loaded, or does not become ready within the timout period. |
| 86 |
* |
| 87 |
* @deprecated |
| 88 |
*/ |
| 89 |
export const sreReady = Sre.sreReady; |
| 90 |
|
| 91 |
// Setting delay stops SRE from setting itself up (and loading locales) when it |
| 92 |
// is not actually being used. As we are not yet sure in which environment we |
| 93 |
// are (browser, node) we can not use a configuration vector. |
| 94 |
Engine.getInstance().delay = true; |
| 95 |
|
| 96 |
export default Sre; |