system_external.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.SystemExternal = void 0;
  4. const variables_js_1 = require("./variables.js");
  5. class SystemExternal {
  6. static nodeRequire() {
  7. return eval('require');
  8. }
  9. static extRequire(library) {
  10. if (typeof process !== 'undefined' && typeof require !== 'undefined') {
  11. return SystemExternal.nodeRequire()(library);
  12. }
  13. return null;
  14. }
  15. }
  16. exports.SystemExternal = SystemExternal;
  17. SystemExternal.windowSupported = (() => !(typeof window === 'undefined'))();
  18. SystemExternal.documentSupported = (() => SystemExternal.windowSupported &&
  19. !(typeof window.document === 'undefined'))();
  20. SystemExternal.xmldom = SystemExternal.documentSupported
  21. ? window
  22. : SystemExternal.extRequire('@xmldom/xmldom');
  23. SystemExternal.document = SystemExternal.documentSupported
  24. ? window.document
  25. : new SystemExternal.xmldom.DOMImplementation().createDocument('', '', 0);
  26. SystemExternal.xpath = SystemExternal.documentSupported
  27. ? document
  28. : (function () {
  29. const window = { document: {}, XPathResult: {} };
  30. const wgx = SystemExternal.extRequire('wicked-good-xpath');
  31. wgx.install(window);
  32. window.document.XPathResult = window.XPathResult;
  33. return window.document;
  34. })();
  35. SystemExternal.mathmapsIePath = 'https://cdn.jsdelivr.net/npm/sre-mathmaps-ie@' +
  36. variables_js_1.Variables.VERSION +
  37. 'mathmaps_ie.js';
  38. SystemExternal.fs = SystemExternal.documentSupported
  39. ? null
  40. : SystemExternal.extRequire('fs');
  41. SystemExternal.url = variables_js_1.Variables.url;
  42. SystemExternal.jsonPath = (function () {
  43. if (SystemExternal.documentSupported) {
  44. return SystemExternal.url;
  45. }
  46. if (process.env.SRE_JSON_PATH || global.SRE_JSON_PATH) {
  47. return process.env.SRE_JSON_PATH || global.SRE_JSON_PATH;
  48. }
  49. try {
  50. const path = SystemExternal.nodeRequire().resolve('speech-rule-engine');
  51. return path.replace(/sre\.js$/, '') + 'mathmaps';
  52. }
  53. catch (_err) {
  54. }
  55. try {
  56. const path = SystemExternal.nodeRequire().resolve('.');
  57. return path.replace(/sre\.js$/, '') + 'mathmaps';
  58. }
  59. catch (_err) {
  60. }
  61. return typeof __dirname !== 'undefined'
  62. ? __dirname + (__dirname.match(/lib?$/) ? '/mathmaps' : '/lib/mathmaps')
  63. : process.cwd() + '/lib/mathmaps';
  64. })();
  65. SystemExternal.WGXpath = variables_js_1.Variables.WGXpath;
  66. SystemExternal.wgxpath = null;
  67. exports.default = SystemExternal;