html_highlighter.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.HtmlHighlighter = void 0;
  4. const DomUtil = require("../common/dom_util.js");
  5. const abstract_highlighter_js_1 = require("./abstract_highlighter.js");
  6. class HtmlHighlighter extends abstract_highlighter_js_1.AbstractHighlighter {
  7. constructor() {
  8. super();
  9. this.mactionName = 'maction';
  10. }
  11. highlightNode(node) {
  12. const info = {
  13. node: node,
  14. foreground: node.style.color,
  15. position: node.style.position
  16. };
  17. const color = this.color.rgb();
  18. node.style.color = color.foreground;
  19. node.style.position = 'relative';
  20. const bbox = node.bbox;
  21. if (bbox && bbox.w) {
  22. const vpad = 0.05;
  23. const hpad = 0;
  24. const span = DomUtil.createElement('span');
  25. const left = parseFloat(node.style.paddingLeft || '0');
  26. span.style.backgroundColor = color.background;
  27. span.style.opacity = color.alphaback.toString();
  28. span.style.display = 'inline-block';
  29. span.style.height = bbox.h + bbox.d + 2 * vpad + 'em';
  30. span.style.verticalAlign = -bbox.d + 'em';
  31. span.style.marginTop = span.style.marginBottom = -vpad + 'em';
  32. span.style.width = bbox.w + 2 * hpad + 'em';
  33. span.style.marginLeft = left - hpad + 'em';
  34. span.style.marginRight = -bbox.w - hpad - left + 'em';
  35. node.parentNode.insertBefore(span, node);
  36. info.box = span;
  37. }
  38. return info;
  39. }
  40. unhighlightNode(info) {
  41. const node = info.node;
  42. node.style.color = info.foreground;
  43. node.style.position = info.position;
  44. if (info.box) {
  45. info.box.parentNode.removeChild(info.box);
  46. }
  47. }
  48. }
  49. exports.HtmlHighlighter = HtmlHighlighter;