PhysicsItems.js 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 __importDefault = (this && this.__importDefault) || function (mod) {
  18. return (mod && mod.__esModule) ? mod : { "default": mod };
  19. };
  20. Object.defineProperty(exports, "__esModule", { value: true });
  21. exports.AutoOpen = void 0;
  22. var StackItem_js_1 = require("../StackItem.js");
  23. var ParseUtil_js_1 = __importDefault(require("../ParseUtil.js"));
  24. var NodeUtil_js_1 = __importDefault(require("../NodeUtil.js"));
  25. var TexParser_js_1 = __importDefault(require("../TexParser.js"));
  26. var AutoOpen = (function (_super) {
  27. __extends(AutoOpen, _super);
  28. function AutoOpen() {
  29. var _this = _super !== null && _super.apply(this, arguments) || this;
  30. _this.openCount = 0;
  31. return _this;
  32. }
  33. Object.defineProperty(AutoOpen.prototype, "kind", {
  34. get: function () {
  35. return 'auto open';
  36. },
  37. enumerable: false,
  38. configurable: true
  39. });
  40. Object.defineProperty(AutoOpen.prototype, "isOpen", {
  41. get: function () {
  42. return true;
  43. },
  44. enumerable: false,
  45. configurable: true
  46. });
  47. AutoOpen.prototype.toMml = function () {
  48. var parser = this.factory.configuration.parser;
  49. var right = this.getProperty('right');
  50. if (this.getProperty('smash')) {
  51. var mml_1 = _super.prototype.toMml.call(this);
  52. var smash = parser.create('node', 'mpadded', [mml_1], { height: 0, depth: 0 });
  53. this.Clear();
  54. this.Push(parser.create('node', 'TeXAtom', [smash]));
  55. }
  56. if (right) {
  57. this.Push(new TexParser_js_1.default(right, parser.stack.env, parser.configuration).mml());
  58. }
  59. var mml = ParseUtil_js_1.default.fenced(this.factory.configuration, this.getProperty('open'), _super.prototype.toMml.call(this), this.getProperty('close'), this.getProperty('big'));
  60. NodeUtil_js_1.default.removeProperties(mml, 'open', 'close', 'texClass');
  61. return mml;
  62. };
  63. AutoOpen.prototype.checkItem = function (item) {
  64. if (item.isKind('mml') && item.Size() === 1) {
  65. var mml = item.toMml();
  66. if (mml.isKind('mo') && mml.getText() === this.getProperty('open')) {
  67. this.openCount++;
  68. }
  69. }
  70. var close = item.getProperty('autoclose');
  71. if (close && close === this.getProperty('close') && !this.openCount--) {
  72. if (this.getProperty('ignore')) {
  73. this.Clear();
  74. return [[], true];
  75. }
  76. return [[this.toMml()], true];
  77. }
  78. return _super.prototype.checkItem.call(this, item);
  79. };
  80. AutoOpen.errors = Object.assign(Object.create(StackItem_js_1.BaseItem.errors), {
  81. 'stop': ['ExtraOrMissingDelims', 'Extra open or missing close delimiter']
  82. });
  83. return AutoOpen;
  84. }(StackItem_js_1.BaseItem));
  85. exports.AutoOpen = AutoOpen;
  86. //# sourceMappingURL=PhysicsItems.js.map