MouseExplorer.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 __read = (this && this.__read) || function (o, n) {
  18. var m = typeof Symbol === "function" && o[Symbol.iterator];
  19. if (!m) return o;
  20. var i = m.call(o), r, ar = [], e;
  21. try {
  22. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  23. }
  24. catch (error) { e = { error: error }; }
  25. finally {
  26. try {
  27. if (r && !r.done && (m = i["return"])) m.call(i);
  28. }
  29. finally { if (e) throw e.error; }
  30. }
  31. return ar;
  32. };
  33. Object.defineProperty(exports, "__esModule", { value: true });
  34. exports.FlameHoverer = exports.ContentHoverer = exports.ValueHoverer = exports.Hoverer = exports.AbstractMouseExplorer = void 0;
  35. var Region_js_1 = require("./Region.js");
  36. var Explorer_js_1 = require("./Explorer.js");
  37. require("../sre.js");
  38. var AbstractMouseExplorer = (function (_super) {
  39. __extends(AbstractMouseExplorer, _super);
  40. function AbstractMouseExplorer() {
  41. var _this = _super !== null && _super.apply(this, arguments) || this;
  42. _this.events = _super.prototype.Events.call(_this).concat([
  43. ['mouseover', _this.MouseOver.bind(_this)],
  44. ['mouseout', _this.MouseOut.bind(_this)]
  45. ]);
  46. return _this;
  47. }
  48. AbstractMouseExplorer.prototype.MouseOver = function (_event) {
  49. this.Start();
  50. };
  51. AbstractMouseExplorer.prototype.MouseOut = function (_event) {
  52. this.Stop();
  53. };
  54. return AbstractMouseExplorer;
  55. }(Explorer_js_1.AbstractExplorer));
  56. exports.AbstractMouseExplorer = AbstractMouseExplorer;
  57. var Hoverer = (function (_super) {
  58. __extends(Hoverer, _super);
  59. function Hoverer(document, region, node, nodeQuery, nodeAccess) {
  60. var _this = _super.call(this, document, region, node) || this;
  61. _this.document = document;
  62. _this.region = region;
  63. _this.node = node;
  64. _this.nodeQuery = nodeQuery;
  65. _this.nodeAccess = nodeAccess;
  66. return _this;
  67. }
  68. Hoverer.prototype.MouseOut = function (event) {
  69. if (event.clientX === this.coord[0] &&
  70. event.clientY === this.coord[1]) {
  71. return;
  72. }
  73. this.highlighter.unhighlight();
  74. this.region.Hide();
  75. _super.prototype.MouseOut.call(this, event);
  76. };
  77. Hoverer.prototype.MouseOver = function (event) {
  78. _super.prototype.MouseOver.call(this, event);
  79. var target = event.target;
  80. this.coord = [event.clientX, event.clientY];
  81. var _a = __read(this.getNode(target), 2), node = _a[0], kind = _a[1];
  82. if (!node) {
  83. return;
  84. }
  85. this.highlighter.unhighlight();
  86. this.highlighter.highlight([node]);
  87. this.region.Update(kind);
  88. this.region.Show(node, this.highlighter);
  89. };
  90. Hoverer.prototype.getNode = function (node) {
  91. var original = node;
  92. while (node && node !== this.node) {
  93. if (this.nodeQuery(node)) {
  94. return [node, this.nodeAccess(node)];
  95. }
  96. node = node.parentNode;
  97. }
  98. node = original;
  99. while (node) {
  100. if (this.nodeQuery(node)) {
  101. return [node, this.nodeAccess(node)];
  102. }
  103. var child = node.childNodes[0];
  104. node = (child && child.tagName === 'defs') ?
  105. node.childNodes[1] : child;
  106. }
  107. return [null, null];
  108. };
  109. return Hoverer;
  110. }(AbstractMouseExplorer));
  111. exports.Hoverer = Hoverer;
  112. var ValueHoverer = (function (_super) {
  113. __extends(ValueHoverer, _super);
  114. function ValueHoverer() {
  115. return _super !== null && _super.apply(this, arguments) || this;
  116. }
  117. return ValueHoverer;
  118. }(Hoverer));
  119. exports.ValueHoverer = ValueHoverer;
  120. var ContentHoverer = (function (_super) {
  121. __extends(ContentHoverer, _super);
  122. function ContentHoverer() {
  123. return _super !== null && _super.apply(this, arguments) || this;
  124. }
  125. return ContentHoverer;
  126. }(Hoverer));
  127. exports.ContentHoverer = ContentHoverer;
  128. var FlameHoverer = (function (_super) {
  129. __extends(FlameHoverer, _super);
  130. function FlameHoverer(document, _ignore, node) {
  131. var _this = _super.call(this, document, new Region_js_1.DummyRegion(document), node, function (x) { return _this.highlighter.isMactionNode(x); }, function () { }) || this;
  132. _this.document = document;
  133. _this.node = node;
  134. return _this;
  135. }
  136. return FlameHoverer;
  137. }(Hoverer));
  138. exports.FlameHoverer = FlameHoverer;
  139. //# sourceMappingURL=MouseExplorer.js.map