index.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. "use strict";
  2. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  3. if (k2 === undefined) k2 = k;
  4. var desc = Object.getOwnPropertyDescriptor(m, k);
  5. if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
  6. desc = { enumerable: true, get: function() { return m[k]; } };
  7. }
  8. Object.defineProperty(o, k2, desc);
  9. }) : (function(o, m, k, k2) {
  10. if (k2 === undefined) k2 = k;
  11. o[k2] = m[k];
  12. }));
  13. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  14. Object.defineProperty(o, "default", { enumerable: true, value: v });
  15. }) : function(o, v) {
  16. o["default"] = v;
  17. });
  18. var __importStar = (this && this.__importStar) || function (mod) {
  19. if (mod && mod.__esModule) return mod;
  20. var result = {};
  21. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  22. __setModuleDefault(result, mod);
  23. return result;
  24. };
  25. Object.defineProperty(exports, "__esModule", { value: true });
  26. exports.Grid = void 0;
  27. const x6_common_1 = require("@antv/x6-common");
  28. const registry_1 = require("../registry");
  29. const patterns = __importStar(require("./main"));
  30. class Grid {
  31. constructor() {
  32. this.patterns = {};
  33. this.root = x6_common_1.Vector.create(x6_common_1.Dom.createSvgDocument(), {
  34. width: '100%',
  35. height: '100%',
  36. }, [x6_common_1.Dom.createSvgElement('defs')]).node;
  37. }
  38. add(id, elem) {
  39. const firstChild = this.root.childNodes[0];
  40. if (firstChild) {
  41. firstChild.appendChild(elem);
  42. }
  43. this.patterns[id] = elem;
  44. x6_common_1.Vector.create('rect', {
  45. width: '100%',
  46. height: '100%',
  47. fill: `url(#${id})`,
  48. }).appendTo(this.root);
  49. }
  50. get(id) {
  51. return this.patterns[id];
  52. }
  53. has(id) {
  54. return this.patterns[id] != null;
  55. }
  56. }
  57. exports.Grid = Grid;
  58. (function (Grid) {
  59. Grid.presets = patterns;
  60. Grid.registry = registry_1.Registry.create({
  61. type: 'grid',
  62. });
  63. Grid.registry.register(Grid.presets, true);
  64. })(Grid = exports.Grid || (exports.Grid = {}));
  65. //# sourceMappingURL=index.js.map