title.js 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.title = void 0;
  4. const x6_common_1 = require("@antv/x6-common");
  5. exports.title = {
  6. qualify(title, { elem }) {
  7. // HTMLElement title is specified via an attribute (i.e. not an element)
  8. return elem instanceof SVGElement;
  9. },
  10. set(val, { elem }) {
  11. const cacheName = 'x6-title';
  12. const title = `${val}`;
  13. const cache = x6_common_1.Dom.data(elem, cacheName);
  14. if (cache == null || cache !== title) {
  15. x6_common_1.Dom.data(elem, cacheName, title);
  16. // Generally SVGTitleElement should be the first child
  17. // element of its parent.
  18. const firstChild = elem.firstChild;
  19. if (firstChild && firstChild.tagName.toUpperCase() === 'TITLE') {
  20. // Update an existing title
  21. const titleElem = firstChild;
  22. titleElem.textContent = title;
  23. }
  24. else {
  25. // Create a new title
  26. const titleNode = document.createElementNS(elem.namespaceURI, 'title');
  27. titleNode.textContent = title;
  28. elem.insertBefore(titleNode, firstChild);
  29. }
  30. }
  31. },
  32. };
  33. //# sourceMappingURL=title.js.map