BaseConfiguration.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. };
  9. return function (d, b) {
  10. if (typeof b !== "function" && b !== null)
  11. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  12. extendStatics(d, b);
  13. function __() { this.constructor = d; }
  14. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  15. };
  16. })();
  17. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  18. if (k2 === undefined) k2 = k;
  19. var desc = Object.getOwnPropertyDescriptor(m, k);
  20. if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
  21. desc = { enumerable: true, get: function() { return m[k]; } };
  22. }
  23. Object.defineProperty(o, k2, desc);
  24. }) : (function(o, m, k, k2) {
  25. if (k2 === undefined) k2 = k;
  26. o[k2] = m[k];
  27. }));
  28. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  29. Object.defineProperty(o, "default", { enumerable: true, value: v });
  30. }) : function(o, v) {
  31. o["default"] = v;
  32. });
  33. var __importStar = (this && this.__importStar) || function (mod) {
  34. if (mod && mod.__esModule) return mod;
  35. var result = {};
  36. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  37. __setModuleDefault(result, mod);
  38. return result;
  39. };
  40. var __values = (this && this.__values) || function(o) {
  41. var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
  42. if (m) return m.call(o);
  43. if (o && typeof o.length === "number") return {
  44. next: function () {
  45. if (o && i >= o.length) o = void 0;
  46. return { value: o && o[i++], done: !o };
  47. }
  48. };
  49. throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
  50. };
  51. var __importDefault = (this && this.__importDefault) || function (mod) {
  52. return (mod && mod.__esModule) ? mod : { "default": mod };
  53. };
  54. var _a;
  55. Object.defineProperty(exports, "__esModule", { value: true });
  56. exports.BaseConfiguration = exports.BaseTags = exports.Other = void 0;
  57. var Configuration_js_1 = require("../Configuration.js");
  58. var MapHandler_js_1 = require("../MapHandler.js");
  59. var TexError_js_1 = __importDefault(require("../TexError.js"));
  60. var NodeUtil_js_1 = __importDefault(require("../NodeUtil.js"));
  61. var SymbolMap_js_1 = require("../SymbolMap.js");
  62. var bitem = __importStar(require("./BaseItems.js"));
  63. var Tags_js_1 = require("../Tags.js");
  64. require("./BaseMappings.js");
  65. var OperatorDictionary_js_1 = require("../../../core/MmlTree/OperatorDictionary.js");
  66. new SymbolMap_js_1.CharacterMap('remap', null, {
  67. '-': '\u2212',
  68. '*': '\u2217',
  69. '`': '\u2018'
  70. });
  71. function Other(parser, char) {
  72. var font = parser.stack.env['font'];
  73. var def = font ?
  74. { mathvariant: parser.stack.env['font'] } : {};
  75. var remap = MapHandler_js_1.MapHandler.getMap('remap').lookup(char);
  76. var range = (0, OperatorDictionary_js_1.getRange)(char);
  77. var type = (range ? range[3] : 'mo');
  78. var mo = parser.create('token', type, def, (remap ? remap.char : char));
  79. range[4] && mo.attributes.set('mathvariant', range[4]);
  80. if (type === 'mo') {
  81. NodeUtil_js_1.default.setProperty(mo, 'fixStretchy', true);
  82. parser.configuration.addNode('fixStretchy', mo);
  83. }
  84. parser.Push(mo);
  85. }
  86. exports.Other = Other;
  87. function csUndefined(_parser, name) {
  88. throw new TexError_js_1.default('UndefinedControlSequence', 'Undefined control sequence %1', '\\' + name);
  89. }
  90. function envUndefined(_parser, env) {
  91. throw new TexError_js_1.default('UnknownEnv', 'Unknown environment \'%1\'', env);
  92. }
  93. function filterNonscript(_a) {
  94. var e_1, _b;
  95. var data = _a.data;
  96. try {
  97. for (var _c = __values(data.getList('nonscript')), _d = _c.next(); !_d.done; _d = _c.next()) {
  98. var mml = _d.value;
  99. if (mml.attributes.get('scriptlevel') > 0) {
  100. var parent_1 = mml.parent;
  101. parent_1.childNodes.splice(parent_1.childIndex(mml), 1);
  102. data.removeFromList(mml.kind, [mml]);
  103. if (mml.isKind('mrow')) {
  104. var mstyle = mml.childNodes[0];
  105. data.removeFromList('mstyle', [mstyle]);
  106. data.removeFromList('mspace', mstyle.childNodes[0].childNodes);
  107. }
  108. }
  109. else if (mml.isKind('mrow')) {
  110. mml.parent.replaceChild(mml.childNodes[0], mml);
  111. data.removeFromList('mrow', [mml]);
  112. }
  113. }
  114. }
  115. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  116. finally {
  117. try {
  118. if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
  119. }
  120. finally { if (e_1) throw e_1.error; }
  121. }
  122. }
  123. var BaseTags = (function (_super) {
  124. __extends(BaseTags, _super);
  125. function BaseTags() {
  126. return _super !== null && _super.apply(this, arguments) || this;
  127. }
  128. return BaseTags;
  129. }(Tags_js_1.AbstractTags));
  130. exports.BaseTags = BaseTags;
  131. exports.BaseConfiguration = Configuration_js_1.Configuration.create('base', {
  132. handler: {
  133. character: ['command', 'special', 'letter', 'digit'],
  134. delimiter: ['delimiter'],
  135. macro: ['delimiter', 'macros', 'mathchar0mi', 'mathchar0mo', 'mathchar7'],
  136. environment: ['environment']
  137. },
  138. fallback: {
  139. character: Other,
  140. macro: csUndefined,
  141. environment: envUndefined
  142. },
  143. items: (_a = {},
  144. _a[bitem.StartItem.prototype.kind] = bitem.StartItem,
  145. _a[bitem.StopItem.prototype.kind] = bitem.StopItem,
  146. _a[bitem.OpenItem.prototype.kind] = bitem.OpenItem,
  147. _a[bitem.CloseItem.prototype.kind] = bitem.CloseItem,
  148. _a[bitem.PrimeItem.prototype.kind] = bitem.PrimeItem,
  149. _a[bitem.SubsupItem.prototype.kind] = bitem.SubsupItem,
  150. _a[bitem.OverItem.prototype.kind] = bitem.OverItem,
  151. _a[bitem.LeftItem.prototype.kind] = bitem.LeftItem,
  152. _a[bitem.Middle.prototype.kind] = bitem.Middle,
  153. _a[bitem.RightItem.prototype.kind] = bitem.RightItem,
  154. _a[bitem.BeginItem.prototype.kind] = bitem.BeginItem,
  155. _a[bitem.EndItem.prototype.kind] = bitem.EndItem,
  156. _a[bitem.StyleItem.prototype.kind] = bitem.StyleItem,
  157. _a[bitem.PositionItem.prototype.kind] = bitem.PositionItem,
  158. _a[bitem.CellItem.prototype.kind] = bitem.CellItem,
  159. _a[bitem.MmlItem.prototype.kind] = bitem.MmlItem,
  160. _a[bitem.FnItem.prototype.kind] = bitem.FnItem,
  161. _a[bitem.NotItem.prototype.kind] = bitem.NotItem,
  162. _a[bitem.NonscriptItem.prototype.kind] = bitem.NonscriptItem,
  163. _a[bitem.DotsItem.prototype.kind] = bitem.DotsItem,
  164. _a[bitem.ArrayItem.prototype.kind] = bitem.ArrayItem,
  165. _a[bitem.EqnArrayItem.prototype.kind] = bitem.EqnArrayItem,
  166. _a[bitem.EquationItem.prototype.kind] = bitem.EquationItem,
  167. _a),
  168. options: {
  169. maxMacros: 1000,
  170. baseURL: (typeof (document) === 'undefined' ||
  171. document.getElementsByTagName('base').length === 0) ?
  172. '' : String(document.location).replace(/#.*$/, '')
  173. },
  174. tags: {
  175. base: BaseTags
  176. },
  177. postprocessors: [[filterNonscript, -4]]
  178. });
  179. //# sourceMappingURL=BaseConfiguration.js.map