cache.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.Cache = void 0;
  4. const x6_common_1 = require("@antv/x6-common");
  5. const util_1 = require("../util");
  6. class Cache {
  7. constructor(view) {
  8. this.view = view;
  9. this.clean();
  10. }
  11. clean() {
  12. if (this.elemCache) {
  13. this.elemCache.dispose();
  14. }
  15. this.elemCache = new x6_common_1.Dictionary();
  16. this.pathCache = {};
  17. }
  18. get(elem) {
  19. const cache = this.elemCache;
  20. if (!cache.has(elem)) {
  21. this.elemCache.set(elem, {});
  22. }
  23. return this.elemCache.get(elem);
  24. }
  25. getData(elem) {
  26. const meta = this.get(elem);
  27. if (!meta.data) {
  28. meta.data = {};
  29. }
  30. return meta.data;
  31. }
  32. getMatrix(elem) {
  33. const meta = this.get(elem);
  34. if (meta.matrix == null) {
  35. const target = this.view.container;
  36. meta.matrix = x6_common_1.Dom.getTransformToParentElement(elem, target);
  37. }
  38. return x6_common_1.Dom.createSVGMatrix(meta.matrix);
  39. }
  40. getShape(elem) {
  41. const meta = this.get(elem);
  42. if (meta.shape == null) {
  43. meta.shape = util_1.Util.toGeometryShape(elem);
  44. }
  45. return meta.shape.clone();
  46. }
  47. getBoundingRect(elem) {
  48. const meta = this.get(elem);
  49. if (meta.boundingRect == null) {
  50. meta.boundingRect = util_1.Util.getBBoxV2(elem);
  51. }
  52. return meta.boundingRect.clone();
  53. }
  54. }
  55. exports.Cache = Cache;
  56. //# sourceMappingURL=cache.js.map