Explorer.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
  19. if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
  20. if (ar || !(i in from)) {
  21. if (!ar) ar = Array.prototype.slice.call(from, 0, i);
  22. ar[i] = from[i];
  23. }
  24. }
  25. return to.concat(ar || Array.prototype.slice.call(from));
  26. };
  27. var __values = (this && this.__values) || function(o) {
  28. var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
  29. if (m) return m.call(o);
  30. if (o && typeof o.length === "number") return {
  31. next: function () {
  32. if (o && i >= o.length) o = void 0;
  33. return { value: o && o[i++], done: !o };
  34. }
  35. };
  36. throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
  37. };
  38. var __importDefault = (this && this.__importDefault) || function (mod) {
  39. return (mod && mod.__esModule) ? mod : { "default": mod };
  40. };
  41. Object.defineProperty(exports, "__esModule", { value: true });
  42. exports.AbstractExplorer = void 0;
  43. var sre_js_1 = __importDefault(require("../sre.js"));
  44. var AbstractExplorer = (function () {
  45. function AbstractExplorer(document, region, node) {
  46. var _rest = [];
  47. for (var _i = 3; _i < arguments.length; _i++) {
  48. _rest[_i - 3] = arguments[_i];
  49. }
  50. this.document = document;
  51. this.region = region;
  52. this.node = node;
  53. this.stoppable = true;
  54. this.events = [];
  55. this.highlighter = this.getHighlighter();
  56. this._active = false;
  57. }
  58. AbstractExplorer.stopEvent = function (event) {
  59. if (event.preventDefault) {
  60. event.preventDefault();
  61. }
  62. else {
  63. event.returnValue = false;
  64. }
  65. if (event.stopImmediatePropagation) {
  66. event.stopImmediatePropagation();
  67. }
  68. else if (event.stopPropagation) {
  69. event.stopPropagation();
  70. }
  71. event.cancelBubble = true;
  72. };
  73. AbstractExplorer.create = function (document, region, node) {
  74. var rest = [];
  75. for (var _i = 3; _i < arguments.length; _i++) {
  76. rest[_i - 3] = arguments[_i];
  77. }
  78. var explorer = new (this.bind.apply(this, __spreadArray([void 0, document, region, node], __read(rest), false)))();
  79. return explorer;
  80. };
  81. AbstractExplorer.prototype.Events = function () {
  82. return this.events;
  83. };
  84. Object.defineProperty(AbstractExplorer.prototype, "active", {
  85. get: function () {
  86. return this._active;
  87. },
  88. set: function (flag) {
  89. this._active = flag;
  90. },
  91. enumerable: false,
  92. configurable: true
  93. });
  94. AbstractExplorer.prototype.Attach = function () {
  95. this.AddEvents();
  96. };
  97. AbstractExplorer.prototype.Detach = function () {
  98. this.RemoveEvents();
  99. };
  100. AbstractExplorer.prototype.Start = function () {
  101. this.highlighter = this.getHighlighter();
  102. this.active = true;
  103. };
  104. AbstractExplorer.prototype.Stop = function () {
  105. if (this.active) {
  106. this.region.Clear();
  107. this.region.Hide();
  108. this.active = false;
  109. }
  110. };
  111. AbstractExplorer.prototype.AddEvents = function () {
  112. var e_1, _a;
  113. try {
  114. for (var _b = __values(this.events), _c = _b.next(); !_c.done; _c = _b.next()) {
  115. var _d = __read(_c.value, 2), eventkind = _d[0], eventfunc = _d[1];
  116. this.node.addEventListener(eventkind, eventfunc);
  117. }
  118. }
  119. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  120. finally {
  121. try {
  122. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  123. }
  124. finally { if (e_1) throw e_1.error; }
  125. }
  126. };
  127. AbstractExplorer.prototype.RemoveEvents = function () {
  128. var e_2, _a;
  129. try {
  130. for (var _b = __values(this.events), _c = _b.next(); !_c.done; _c = _b.next()) {
  131. var _d = __read(_c.value, 2), eventkind = _d[0], eventfunc = _d[1];
  132. this.node.removeEventListener(eventkind, eventfunc);
  133. }
  134. }
  135. catch (e_2_1) { e_2 = { error: e_2_1 }; }
  136. finally {
  137. try {
  138. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  139. }
  140. finally { if (e_2) throw e_2.error; }
  141. }
  142. };
  143. AbstractExplorer.prototype.Update = function (force) {
  144. if (force === void 0) { force = false; }
  145. };
  146. AbstractExplorer.prototype.getHighlighter = function () {
  147. var opts = this.document.options.a11y;
  148. var foreground = { color: opts.foregroundColor.toLowerCase(),
  149. alpha: opts.foregroundOpacity / 100 };
  150. var background = { color: opts.backgroundColor.toLowerCase(),
  151. alpha: opts.backgroundOpacity / 100 };
  152. return sre_js_1.default.getHighlighter(background, foreground, { renderer: this.document.outputJax.name, browser: 'v3' });
  153. };
  154. AbstractExplorer.prototype.stopEvent = function (event) {
  155. if (this.stoppable) {
  156. AbstractExplorer.stopEvent(event);
  157. }
  158. };
  159. return AbstractExplorer;
  160. }());
  161. exports.AbstractExplorer = AbstractExplorer;
  162. //# sourceMappingURL=Explorer.js.map