MathItem.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.newState = exports.STATE = exports.AbstractMathItem = exports.protoItem = void 0;
  4. function protoItem(open, math, close, n, start, end, display) {
  5. if (display === void 0) { display = null; }
  6. var item = { open: open, math: math, close: close,
  7. n: n, start: { n: start }, end: { n: end }, display: display };
  8. return item;
  9. }
  10. exports.protoItem = protoItem;
  11. var AbstractMathItem = (function () {
  12. function AbstractMathItem(math, jax, display, start, end) {
  13. if (display === void 0) { display = true; }
  14. if (start === void 0) { start = { i: 0, n: 0, delim: '' }; }
  15. if (end === void 0) { end = { i: 0, n: 0, delim: '' }; }
  16. this.root = null;
  17. this.typesetRoot = null;
  18. this.metrics = {};
  19. this.inputData = {};
  20. this.outputData = {};
  21. this._state = exports.STATE.UNPROCESSED;
  22. this.math = math;
  23. this.inputJax = jax;
  24. this.display = display;
  25. this.start = start;
  26. this.end = end;
  27. this.root = null;
  28. this.typesetRoot = null;
  29. this.metrics = {};
  30. this.inputData = {};
  31. this.outputData = {};
  32. }
  33. Object.defineProperty(AbstractMathItem.prototype, "isEscaped", {
  34. get: function () {
  35. return this.display === null;
  36. },
  37. enumerable: false,
  38. configurable: true
  39. });
  40. AbstractMathItem.prototype.render = function (document) {
  41. document.renderActions.renderMath(this, document);
  42. };
  43. AbstractMathItem.prototype.rerender = function (document, start) {
  44. if (start === void 0) { start = exports.STATE.RERENDER; }
  45. if (this.state() >= start) {
  46. this.state(start - 1);
  47. }
  48. document.renderActions.renderMath(this, document, start);
  49. };
  50. AbstractMathItem.prototype.convert = function (document, end) {
  51. if (end === void 0) { end = exports.STATE.LAST; }
  52. document.renderActions.renderConvert(this, document, end);
  53. };
  54. AbstractMathItem.prototype.compile = function (document) {
  55. if (this.state() < exports.STATE.COMPILED) {
  56. this.root = this.inputJax.compile(this, document);
  57. this.state(exports.STATE.COMPILED);
  58. }
  59. };
  60. AbstractMathItem.prototype.typeset = function (document) {
  61. if (this.state() < exports.STATE.TYPESET) {
  62. this.typesetRoot = document.outputJax[this.isEscaped ? 'escaped' : 'typeset'](this, document);
  63. this.state(exports.STATE.TYPESET);
  64. }
  65. };
  66. AbstractMathItem.prototype.updateDocument = function (_document) { };
  67. AbstractMathItem.prototype.removeFromDocument = function (_restore) {
  68. if (_restore === void 0) { _restore = false; }
  69. };
  70. AbstractMathItem.prototype.setMetrics = function (em, ex, cwidth, lwidth, scale) {
  71. this.metrics = {
  72. em: em, ex: ex,
  73. containerWidth: cwidth,
  74. lineWidth: lwidth,
  75. scale: scale
  76. };
  77. };
  78. AbstractMathItem.prototype.state = function (state, restore) {
  79. if (state === void 0) { state = null; }
  80. if (restore === void 0) { restore = false; }
  81. if (state != null) {
  82. if (state < exports.STATE.INSERTED && this._state >= exports.STATE.INSERTED) {
  83. this.removeFromDocument(restore);
  84. }
  85. if (state < exports.STATE.TYPESET && this._state >= exports.STATE.TYPESET) {
  86. this.outputData = {};
  87. }
  88. if (state < exports.STATE.COMPILED && this._state >= exports.STATE.COMPILED) {
  89. this.inputData = {};
  90. }
  91. this._state = state;
  92. }
  93. return this._state;
  94. };
  95. AbstractMathItem.prototype.reset = function (restore) {
  96. if (restore === void 0) { restore = false; }
  97. this.state(exports.STATE.UNPROCESSED, restore);
  98. };
  99. return AbstractMathItem;
  100. }());
  101. exports.AbstractMathItem = AbstractMathItem;
  102. exports.STATE = {
  103. UNPROCESSED: 0,
  104. FINDMATH: 10,
  105. COMPILED: 20,
  106. CONVERT: 100,
  107. METRICS: 110,
  108. RERENDER: 125,
  109. TYPESET: 150,
  110. INSERTED: 200,
  111. LAST: 10000
  112. };
  113. function newState(name, state) {
  114. if (name in exports.STATE) {
  115. throw Error('State ' + name + ' already exists');
  116. }
  117. exports.STATE[name] = state;
  118. }
  119. exports.newState = newState;
  120. //# sourceMappingURL=MathItem.js.map