sre.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. * @fileoverview Provides the interface functionality to SRE.
  19. *
  20. * @author dpvc@mathjax.org (Davide Cervone)
  21. * @author v.sorge@mathjax.org (Volker Sorge)
  22. */
  23. import * as Api from 'speech-rule-engine/js/common/system.js';
  24. import {Walker} from 'speech-rule-engine/js/walker/walker.js';
  25. import * as WalkerFactory from 'speech-rule-engine/js/walker/walker_factory.js';
  26. import * as SpeechGeneratorFactory from 'speech-rule-engine/js/speech_generator/speech_generator_factory.js';
  27. import * as EngineConst from 'speech-rule-engine/js/common/engine_const.js';
  28. import Engine from 'speech-rule-engine/js/common/engine.js';
  29. import {ClearspeakPreferences} from 'speech-rule-engine/js/speech_rules/clearspeak_preferences.js';
  30. import {Highlighter} from 'speech-rule-engine/js/highlighter/highlighter.js';
  31. import * as HighlighterFactory from 'speech-rule-engine/js/highlighter/highlighter_factory.js';
  32. import {SpeechGenerator} from 'speech-rule-engine/js/speech_generator/speech_generator.js';
  33. import {Variables} from 'speech-rule-engine/js/common/variables.js';
  34. import MathMaps from './mathmaps.js';
  35. export namespace Sre {
  36. export type highlighter = Highlighter;
  37. export type speechGenerator = SpeechGenerator;
  38. export type walker = Walker;
  39. export const locales = Variables.LOCALES;
  40. export const sreReady = Api.engineReady;
  41. export const setupEngine = Api.setupEngine;
  42. export const engineSetup = Api.engineSetup;
  43. export const toEnriched = Api.toEnriched;
  44. export const toSpeech = Api.toSpeech;
  45. export const clearspeakPreferences = ClearspeakPreferences;
  46. export const getHighlighter = HighlighterFactory.highlighter;
  47. export const getSpeechGenerator = SpeechGeneratorFactory.generator;
  48. export const getWalker = WalkerFactory.walker;
  49. export const clearspeakStyle = () => {
  50. return EngineConst.DOMAIN_TO_STYLES['clearspeak'];
  51. };
  52. /**
  53. * Loads locales that are already included in the imported MathMaps. Defaults
  54. * to standard loading if a locale is not yet preloaded.
  55. */
  56. export const preloadLocales = async function(locale: string) {
  57. const json = MathMaps.get(locale);
  58. return json ? new Promise((res, _rej) => res(JSON.stringify(json))) :
  59. Api.localeLoader()(locale);
  60. };
  61. }
  62. /**
  63. * A promise that resolves when SRE is loaded and ready, and rejects if
  64. * SRE can't be loaded, or does not become ready within the timout period.
  65. *
  66. * @deprecated
  67. */
  68. export const sreReady = Sre.sreReady;
  69. // Setting delay stops SRE from setting itself up (and loading locales) when it
  70. // is not actually being used. As we are not yet sure in which environment we
  71. // are (browser, node) we can not use a configuration vector.
  72. Engine.getInstance().delay = true;
  73. export default Sre;