dom.js 1.5 KB

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