dom.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. "use strict";
  2. /**
  3. * @fileoverview dom
  4. * @author dengfuping_develop@163.com
  5. */
  6. Object.defineProperty(exports, "__esModule", { value: true });
  7. var tslib_1 = require("tslib");
  8. var util_1 = require("@antv/util");
  9. var constant_1 = require("../constant");
  10. var base_1 = require("./base");
  11. var Dom = /** @class */ (function (_super) {
  12. tslib_1.__extends(Dom, _super);
  13. function Dom() {
  14. var _this = _super !== null && _super.apply(this, arguments) || this;
  15. _this.type = 'dom';
  16. _this.canFill = false;
  17. _this.canStroke = false;
  18. return _this;
  19. }
  20. Dom.prototype.createPath = function (context, targetAttrs) {
  21. var attrs = this.attr();
  22. var el = this.get('el');
  23. util_1.each(targetAttrs || attrs, function (value, attr) {
  24. if (constant_1.SVG_ATTR_MAP[attr]) {
  25. el.setAttribute(constant_1.SVG_ATTR_MAP[attr], value);
  26. }
  27. });
  28. if (typeof attrs['html'] === 'function') {
  29. var element = attrs['html'].call(this, attrs);
  30. if (element instanceof Element || element instanceof HTMLDocument) {
  31. var children = el.childNodes;
  32. for (var i = children.length - 1; i >= 0; i--) {
  33. el.removeChild(children[i]);
  34. }
  35. el.appendChild(element); // append to el if it's an element
  36. }
  37. else {
  38. el.innerHTML = element; // set innerHTML
  39. }
  40. }
  41. else {
  42. el.innerHTML = attrs['html']; // set innerHTML
  43. }
  44. };
  45. return Dom;
  46. }(base_1.default));
  47. exports.default = Dom;
  48. //# sourceMappingURL=dom.js.map