AutoloadConfiguration.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. "use strict";
  2. var __read = (this && this.__read) || function (o, n) {
  3. var m = typeof Symbol === "function" && o[Symbol.iterator];
  4. if (!m) return o;
  5. var i = m.call(o), r, ar = [], e;
  6. try {
  7. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  8. }
  9. catch (error) { e = { error: error }; }
  10. finally {
  11. try {
  12. if (r && !r.done && (m = i["return"])) m.call(i);
  13. }
  14. finally { if (e) throw e.error; }
  15. }
  16. return ar;
  17. };
  18. var __values = (this && this.__values) || function(o) {
  19. var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
  20. if (m) return m.call(o);
  21. if (o && typeof o.length === "number") return {
  22. next: function () {
  23. if (o && i >= o.length) o = void 0;
  24. return { value: o && o[i++], done: !o };
  25. }
  26. };
  27. throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
  28. };
  29. Object.defineProperty(exports, "__esModule", { value: true });
  30. exports.AutoloadConfiguration = void 0;
  31. var Configuration_js_1 = require("../Configuration.js");
  32. var SymbolMap_js_1 = require("../SymbolMap.js");
  33. var Symbol_js_1 = require("../Symbol.js");
  34. var RequireConfiguration_js_1 = require("../require/RequireConfiguration.js");
  35. var package_js_1 = require("../../../components/package.js");
  36. var Options_js_1 = require("../../../util/Options.js");
  37. function Autoload(parser, name, extension, isMacro) {
  38. var e_1, _a, e_2, _b;
  39. if (package_js_1.Package.packages.has(parser.options.require.prefix + extension)) {
  40. var def = parser.options.autoload[extension];
  41. var _c = __read((def.length === 2 && Array.isArray(def[0]) ? def : [def, []]), 2), macros = _c[0], envs = _c[1];
  42. try {
  43. for (var macros_1 = __values(macros), macros_1_1 = macros_1.next(); !macros_1_1.done; macros_1_1 = macros_1.next()) {
  44. var macro = macros_1_1.value;
  45. AutoloadMacros.remove(macro);
  46. }
  47. }
  48. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  49. finally {
  50. try {
  51. if (macros_1_1 && !macros_1_1.done && (_a = macros_1.return)) _a.call(macros_1);
  52. }
  53. finally { if (e_1) throw e_1.error; }
  54. }
  55. try {
  56. for (var envs_1 = __values(envs), envs_1_1 = envs_1.next(); !envs_1_1.done; envs_1_1 = envs_1.next()) {
  57. var env = envs_1_1.value;
  58. AutoloadEnvironments.remove(env);
  59. }
  60. }
  61. catch (e_2_1) { e_2 = { error: e_2_1 }; }
  62. finally {
  63. try {
  64. if (envs_1_1 && !envs_1_1.done && (_b = envs_1.return)) _b.call(envs_1);
  65. }
  66. finally { if (e_2) throw e_2.error; }
  67. }
  68. parser.string = (isMacro ? name + ' ' : '\\begin{' + name.slice(1) + '}') + parser.string.slice(parser.i);
  69. parser.i = 0;
  70. }
  71. (0, RequireConfiguration_js_1.RequireLoad)(parser, extension);
  72. }
  73. function initAutoload(config) {
  74. if (!config.options.require) {
  75. (0, Options_js_1.defaultOptions)(config.options, RequireConfiguration_js_1.RequireConfiguration.options);
  76. }
  77. }
  78. function configAutoload(config, jax) {
  79. var e_3, _a, e_4, _b, e_5, _c;
  80. var parser = jax.parseOptions;
  81. var macros = parser.handlers.get('macro');
  82. var environments = parser.handlers.get('environment');
  83. var autoload = parser.options.autoload;
  84. parser.packageData.set('autoload', { Autoload: Autoload });
  85. try {
  86. for (var _d = __values(Object.keys(autoload)), _e = _d.next(); !_e.done; _e = _d.next()) {
  87. var extension = _e.value;
  88. var def = autoload[extension];
  89. var _f = __read((def.length === 2 && Array.isArray(def[0]) ? def : [def, []]), 2), macs = _f[0], envs = _f[1];
  90. try {
  91. for (var macs_1 = (e_4 = void 0, __values(macs)), macs_1_1 = macs_1.next(); !macs_1_1.done; macs_1_1 = macs_1.next()) {
  92. var name_1 = macs_1_1.value;
  93. if (!macros.lookup(name_1) || name_1 === 'color') {
  94. AutoloadMacros.add(name_1, new Symbol_js_1.Macro(name_1, Autoload, [extension, true]));
  95. }
  96. }
  97. }
  98. catch (e_4_1) { e_4 = { error: e_4_1 }; }
  99. finally {
  100. try {
  101. if (macs_1_1 && !macs_1_1.done && (_b = macs_1.return)) _b.call(macs_1);
  102. }
  103. finally { if (e_4) throw e_4.error; }
  104. }
  105. try {
  106. for (var envs_2 = (e_5 = void 0, __values(envs)), envs_2_1 = envs_2.next(); !envs_2_1.done; envs_2_1 = envs_2.next()) {
  107. var name_2 = envs_2_1.value;
  108. if (!environments.lookup(name_2)) {
  109. AutoloadEnvironments.add(name_2, new Symbol_js_1.Macro(name_2, Autoload, [extension, false]));
  110. }
  111. }
  112. }
  113. catch (e_5_1) { e_5 = { error: e_5_1 }; }
  114. finally {
  115. try {
  116. if (envs_2_1 && !envs_2_1.done && (_c = envs_2.return)) _c.call(envs_2);
  117. }
  118. finally { if (e_5) throw e_5.error; }
  119. }
  120. }
  121. }
  122. catch (e_3_1) { e_3 = { error: e_3_1 }; }
  123. finally {
  124. try {
  125. if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
  126. }
  127. finally { if (e_3) throw e_3.error; }
  128. }
  129. if (!parser.packageData.get('require')) {
  130. RequireConfiguration_js_1.RequireConfiguration.config(config, jax);
  131. }
  132. }
  133. var AutoloadMacros = new SymbolMap_js_1.CommandMap('autoload-macros', {}, {});
  134. var AutoloadEnvironments = new SymbolMap_js_1.CommandMap('autoload-environments', {}, {});
  135. exports.AutoloadConfiguration = Configuration_js_1.Configuration.create('autoload', {
  136. handler: {
  137. macro: ['autoload-macros'],
  138. environment: ['autoload-environments']
  139. },
  140. options: {
  141. autoload: (0, Options_js_1.expandable)({
  142. action: ['toggle', 'mathtip', 'texttip'],
  143. amscd: [[], ['CD']],
  144. bbox: ['bbox'],
  145. boldsymbol: ['boldsymbol'],
  146. braket: ['bra', 'ket', 'braket', 'set', 'Bra', 'Ket', 'Braket', 'Set', 'ketbra', 'Ketbra'],
  147. bussproofs: [[], ['prooftree']],
  148. cancel: ['cancel', 'bcancel', 'xcancel', 'cancelto'],
  149. color: ['color', 'definecolor', 'textcolor', 'colorbox', 'fcolorbox'],
  150. enclose: ['enclose'],
  151. extpfeil: ['xtwoheadrightarrow', 'xtwoheadleftarrow', 'xmapsto', 'xlongequal', 'xtofrom', 'Newextarrow'],
  152. html: ['href', 'class', 'style', 'cssId'],
  153. mhchem: ['ce', 'pu'],
  154. newcommand: ['newcommand', 'renewcommand', 'newenvironment', 'renewenvironment', 'def', 'let'],
  155. unicode: ['unicode'],
  156. verb: ['verb']
  157. })
  158. },
  159. config: configAutoload,
  160. init: initAutoload,
  161. priority: 10
  162. });
  163. //# sourceMappingURL=AutoloadConfiguration.js.map