HTMLMathItem.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. Object.defineProperty(exports, "__esModule", { value: true });
  18. exports.HTMLMathItem = void 0;
  19. var MathItem_js_1 = require("../../core/MathItem.js");
  20. var HTMLMathItem = (function (_super) {
  21. __extends(HTMLMathItem, _super);
  22. function HTMLMathItem(math, jax, display, start, end) {
  23. if (display === void 0) { display = true; }
  24. if (start === void 0) { start = { node: null, n: 0, delim: '' }; }
  25. if (end === void 0) { end = { node: null, n: 0, delim: '' }; }
  26. return _super.call(this, math, jax, display, start, end) || this;
  27. }
  28. Object.defineProperty(HTMLMathItem.prototype, "adaptor", {
  29. get: function () {
  30. return this.inputJax.adaptor;
  31. },
  32. enumerable: false,
  33. configurable: true
  34. });
  35. HTMLMathItem.prototype.updateDocument = function (_html) {
  36. if (this.state() < MathItem_js_1.STATE.INSERTED) {
  37. if (this.inputJax.processStrings) {
  38. var node = this.start.node;
  39. if (node === this.end.node) {
  40. if (this.end.n && this.end.n < this.adaptor.value(this.end.node).length) {
  41. this.adaptor.split(this.end.node, this.end.n);
  42. }
  43. if (this.start.n) {
  44. node = this.adaptor.split(this.start.node, this.start.n);
  45. }
  46. this.adaptor.replace(this.typesetRoot, node);
  47. }
  48. else {
  49. if (this.start.n) {
  50. node = this.adaptor.split(node, this.start.n);
  51. }
  52. while (node !== this.end.node) {
  53. var next = this.adaptor.next(node);
  54. this.adaptor.remove(node);
  55. node = next;
  56. }
  57. this.adaptor.insert(this.typesetRoot, node);
  58. if (this.end.n < this.adaptor.value(node).length) {
  59. this.adaptor.split(node, this.end.n);
  60. }
  61. this.adaptor.remove(node);
  62. }
  63. }
  64. else {
  65. this.adaptor.replace(this.typesetRoot, this.start.node);
  66. }
  67. this.start.node = this.end.node = this.typesetRoot;
  68. this.start.n = this.end.n = 0;
  69. this.state(MathItem_js_1.STATE.INSERTED);
  70. }
  71. };
  72. HTMLMathItem.prototype.updateStyleSheet = function (document) {
  73. document.addStyleSheet();
  74. };
  75. HTMLMathItem.prototype.removeFromDocument = function (restore) {
  76. if (restore === void 0) { restore = false; }
  77. if (this.state() >= MathItem_js_1.STATE.TYPESET) {
  78. var adaptor = this.adaptor;
  79. var node = this.start.node;
  80. var math = adaptor.text('');
  81. if (restore) {
  82. var text = this.start.delim + this.math + this.end.delim;
  83. if (this.inputJax.processStrings) {
  84. math = adaptor.text(text);
  85. }
  86. else {
  87. var doc = adaptor.parse(text, 'text/html');
  88. math = adaptor.firstChild(adaptor.body(doc));
  89. }
  90. }
  91. if (adaptor.parent(node)) {
  92. adaptor.replace(math, node);
  93. }
  94. this.start.node = this.end.node = math;
  95. this.start.n = this.end.n = 0;
  96. }
  97. };
  98. return HTMLMathItem;
  99. }(MathItem_js_1.AbstractMathItem));
  100. exports.HTMLMathItem = HTMLMathItem;
  101. //# sourceMappingURL=HTMLMathItem.js.map