index.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { Dom, Vector } from '@antv/x6-common';
  2. import { Registry } from '../registry';
  3. import * as patterns from './main';
  4. export class Grid {
  5. constructor() {
  6. this.patterns = {};
  7. this.root = Vector.create(Dom.createSvgDocument(), {
  8. width: '100%',
  9. height: '100%',
  10. }, [Dom.createSvgElement('defs')]).node;
  11. }
  12. add(id, elem) {
  13. const firstChild = this.root.childNodes[0];
  14. if (firstChild) {
  15. firstChild.appendChild(elem);
  16. }
  17. this.patterns[id] = elem;
  18. Vector.create('rect', {
  19. width: '100%',
  20. height: '100%',
  21. fill: `url(#${id})`,
  22. }).appendTo(this.root);
  23. }
  24. get(id) {
  25. return this.patterns[id];
  26. }
  27. has(id) {
  28. return this.patterns[id] != null;
  29. }
  30. }
  31. (function (Grid) {
  32. Grid.presets = patterns;
  33. Grid.registry = Registry.create({
  34. type: 'grid',
  35. });
  36. Grid.registry.register(Grid.presets, true);
  37. })(Grid || (Grid = {}));
  38. //# sourceMappingURL=index.js.map