orcasvn-react-diagrams 0.2.7 → 0.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +7 -12
  3. package/ai/api-contract.json +16 -0
  4. package/ai/invariants.json +8 -0
  5. package/ai/manifest.json +1 -1
  6. package/dist/cjs/examples.js +604 -39
  7. package/dist/cjs/index.js +227 -28
  8. package/dist/cjs/types/api/types.d.ts +2 -0
  9. package/dist/cjs/types/displaybox/demos/elementVisibilitySelectionDemo.d.ts +4 -0
  10. package/dist/cjs/types/engine/DiagramEngine.d.ts +8 -0
  11. package/dist/cjs/types/models/DiagramModel.d.ts +5 -0
  12. package/dist/cjs/types/models/ElementModel.d.ts +2 -0
  13. package/dist/esm/examples.js +604 -39
  14. package/dist/esm/examples.js.map +1 -1
  15. package/dist/esm/index.js +227 -28
  16. package/dist/esm/index.js.map +1 -1
  17. package/dist/esm/types/api/types.d.ts +2 -0
  18. package/dist/esm/types/displaybox/demos/elementVisibilitySelectionDemo.d.ts +4 -0
  19. package/dist/esm/types/engine/DiagramEngine.d.ts +8 -0
  20. package/dist/esm/types/models/DiagramModel.d.ts +5 -0
  21. package/dist/esm/types/models/ElementModel.d.ts +2 -0
  22. package/dist/examples.d.ts +2 -0
  23. package/dist/index.d.ts +9 -0
  24. package/docs/API_CONTRACT.md +16 -1
  25. package/docs/CAPABILITIES.md +1 -0
  26. package/docs/COMMANDS_EVENTS.md +3 -1
  27. package/docs/DOCUMENTATION_WORKFLOW.md +3 -1
  28. package/docs/INTEGRATION_PLAYBOOK.md +1 -0
  29. package/docs/PORTING_CHECKLIST.md +1 -0
  30. package/docs/STATE_INVARIANTS.md +9 -1
  31. package/package.json +1 -1
  32. package/src/displaybox/demos/AutoLayoutDemoTab.tsx +11 -5
  33. package/src/displaybox/demos/autoLayoutDemo.ts +233 -0
  34. package/src/displaybox/demos/basicDemo.ts +6 -6
  35. package/src/displaybox/demos/elementVisibilitySelectionDemo.ts +128 -0
  36. package/src/displaybox/demos/index.tsx +14 -7
  37. package/src/displaybox/demos/selectionDemo.ts +12 -12
package/dist/esm/index.js CHANGED
@@ -85,6 +85,8 @@ var ElementModel = /** @class */ (function () {
85
85
  this.style = data.style;
86
86
  this.portIds = data.portIds ? __spreadArray([], data.portIds, true) : [];
87
87
  this.textIds = data.textIds ? __spreadArray([], data.textIds, true) : [];
88
+ this.visible = data.visible;
89
+ this.selectable = data.selectable;
88
90
  this.parentId = (_a = data.parentId) !== null && _a !== void 0 ? _a : null;
89
91
  this.moveMode = data.moveMode;
90
92
  this.anchorCenter = data.anchorCenter;
@@ -123,6 +125,8 @@ var ElementModel = /** @class */ (function () {
123
125
  style: this.style,
124
126
  portIds: __spreadArray([], this.portIds, true),
125
127
  textIds: __spreadArray([], this.textIds, true),
128
+ visible: this.visible,
129
+ selectable: this.selectable,
126
130
  parentId: this.parentId,
127
131
  moveMode: this.moveMode,
128
132
  anchorCenter: this.anchorCenter,
@@ -526,6 +530,29 @@ var DiagramModel = /** @class */ (function () {
526
530
  DiagramModel.prototype.getElement = function (id) {
527
531
  return this.elements.get(id);
528
532
  };
533
+ DiagramModel.prototype.isElementVisible = function (id) {
534
+ var element = this.elements.get(id);
535
+ if (!element)
536
+ return false;
537
+ if (element.visible === false)
538
+ return false;
539
+ var currentParentId = element.parentId;
540
+ while (currentParentId) {
541
+ var parent_1 = this.elements.get(currentParentId);
542
+ if (!parent_1)
543
+ break;
544
+ if (parent_1.visible === false)
545
+ return false;
546
+ currentParentId = parent_1.parentId;
547
+ }
548
+ return true;
549
+ };
550
+ DiagramModel.prototype.isElementSelectable = function (id) {
551
+ var element = this.elements.get(id);
552
+ if (!element)
553
+ return false;
554
+ return this.isElementVisible(id) && element.selectable !== false;
555
+ };
529
556
  DiagramModel.prototype.setElementLayout = function (id, layout) {
530
557
  var element = this.elements.get(id);
531
558
  if (!element)
@@ -544,6 +571,12 @@ var DiagramModel = /** @class */ (function () {
544
571
  DiagramModel.prototype.getPort = function (id) {
545
572
  return this.ports.get(id);
546
573
  };
574
+ DiagramModel.prototype.isPortVisible = function (id) {
575
+ var port = this.ports.get(id);
576
+ if (!port)
577
+ return false;
578
+ return this.isElementVisible(port.elementId);
579
+ };
547
580
  DiagramModel.prototype.getPortWorldPosition = function (id) {
548
581
  var port = this.ports.get(id);
549
582
  if (!port)
@@ -559,6 +592,16 @@ var DiagramModel = /** @class */ (function () {
559
592
  DiagramModel.prototype.getLink = function (id) {
560
593
  return this.links.get(id);
561
594
  };
595
+ DiagramModel.prototype.isLinkVisible = function (id) {
596
+ var link = this.links.get(id);
597
+ if (!link)
598
+ return false;
599
+ var sourcePort = this.ports.get(link.sourcePortId);
600
+ var targetPort = this.ports.get(link.targetPortId);
601
+ var sourceVisible = sourcePort ? this.isPortVisible(sourcePort.id) : true;
602
+ var targetVisible = targetPort ? this.isPortVisible(targetPort.id) : true;
603
+ return sourceVisible && targetVisible;
604
+ };
562
605
  DiagramModel.prototype.getLinkMidpoint = function (id) {
563
606
  var link = this.links.get(id);
564
607
  if (!link)
@@ -568,6 +611,23 @@ var DiagramModel = /** @class */ (function () {
568
611
  DiagramModel.prototype.getText = function (id) {
569
612
  return this.texts.get(id);
570
613
  };
614
+ DiagramModel.prototype.isTextVisible = function (id) {
615
+ var text = this.texts.get(id);
616
+ if (!text)
617
+ return false;
618
+ if (!text.ownerId)
619
+ return true;
620
+ if (this.elements.has(text.ownerId)) {
621
+ return this.isElementVisible(text.ownerId);
622
+ }
623
+ if (this.ports.has(text.ownerId)) {
624
+ return this.isPortVisible(text.ownerId);
625
+ }
626
+ if (this.links.has(text.ownerId)) {
627
+ return this.isLinkVisible(text.ownerId);
628
+ }
629
+ return true;
630
+ };
571
631
  DiagramModel.prototype.getTextWorldPosition = function (id) {
572
632
  var text = this.texts.get(id);
573
633
  if (!text)
@@ -756,18 +816,18 @@ var DiagramModel = /** @class */ (function () {
756
816
  }
757
817
  var current = element;
758
818
  while (current === null || current === void 0 ? void 0 : current.parentId) {
759
- var parent_1 = this.elements.get(current.parentId);
760
- if (!parent_1)
819
+ var parent_2 = this.elements.get(current.parentId);
820
+ if (!parent_2)
761
821
  break;
762
- var parentX = parent_1.position.x;
763
- var parentY = parent_1.position.y;
764
- if (parent_1.anchorCenter) {
765
- parentX -= parent_1.size.width / 2;
766
- parentY -= parent_1.size.height / 2;
822
+ var parentX = parent_2.position.x;
823
+ var parentY = parent_2.position.y;
824
+ if (parent_2.anchorCenter) {
825
+ parentX -= parent_2.size.width / 2;
826
+ parentY -= parent_2.size.height / 2;
767
827
  }
768
828
  x += parentX;
769
829
  y += parentY;
770
- current = parent_1;
830
+ current = parent_2;
771
831
  }
772
832
  return { x: x, y: y };
773
833
  };
@@ -2439,6 +2499,8 @@ var AutoLayoutService = /** @class */ (function () {
2439
2499
  return this.applyResolvedLayout(parentId, parent, desiredPositions, desiredSizes, {
2440
2500
  width: newParentWidth,
2441
2501
  height: newParentHeight,
2502
+ }, {
2503
+ preserveResizedLayoutParentSize: true,
2442
2504
  });
2443
2505
  };
2444
2506
  AutoLayoutService.prototype.resolveGridCellWidths = function (rowInnerWidth, weights) {
@@ -2448,7 +2510,7 @@ var AutoLayoutService = /** @class */ (function () {
2448
2510
  var safeWeights = weights.map(function (weight) { return _this.clampGridUnits(weight); });
2449
2511
  return this.distributeWeightedSizes(Math.max(0, rowInnerWidth), safeWeights);
2450
2512
  };
2451
- AutoLayoutService.prototype.applyResolvedLayout = function (parentId, parent, desiredPositions, desiredSizes, parentSize) {
2513
+ AutoLayoutService.prototype.applyResolvedLayout = function (parentId, parent, desiredPositions, desiredSizes, parentSize, options) {
2452
2514
  var _this = this;
2453
2515
  var _a;
2454
2516
  var patches = [];
@@ -2467,7 +2529,7 @@ var AutoLayoutService = /** @class */ (function () {
2467
2529
  var resizePatches = _this.commandQueue.run(createResizeElementCommand(childId, fittedSize), _this.model);
2468
2530
  patches.push.apply(patches, resizePatches);
2469
2531
  movedPortIds.push.apply(movedPortIds, _this.collectElementPortIds(childId));
2470
- var nested = _this.applyLayoutForParent(childId);
2532
+ var nested = _this.applyLayoutForParent(childId, (options === null || options === void 0 ? void 0 : options.preserveResizedLayoutParentSize) ? { preserveParentSize: true } : undefined);
2471
2533
  patches.push.apply(patches, nested.patches);
2472
2534
  movedPortIds.push.apply(movedPortIds, nested.movedPortIds);
2473
2535
  }
@@ -4328,16 +4390,38 @@ var DiagramEngine = /** @class */ (function () {
4328
4390
  this.emitEntityDeletionEvents(removal.removed);
4329
4391
  };
4330
4392
  DiagramEngine.prototype.setSelection = function (ids) {
4331
- this.selection.set(ids);
4393
+ this.selection.set(this.normalizeSelectionIds(ids));
4332
4394
  this.emitSelection();
4333
4395
  };
4334
4396
  DiagramEngine.prototype.toggleSelection = function (id) {
4335
- this.selection.toggle(id);
4397
+ var current = new Set(this.selection.get());
4398
+ if (current.has(id)) {
4399
+ current.delete(id);
4400
+ }
4401
+ else if (this.isSelectableId(id)) {
4402
+ current.add(id);
4403
+ }
4404
+ this.selection.set(Array.from(current));
4336
4405
  this.emitSelection();
4337
4406
  };
4338
4407
  DiagramEngine.prototype.getSelection = function () {
4339
4408
  return this.selection.get();
4340
4409
  };
4410
+ DiagramEngine.prototype.isElementVisible = function (id) {
4411
+ return this.model.isElementVisible(id);
4412
+ };
4413
+ DiagramEngine.prototype.isElementSelectable = function (id) {
4414
+ return this.model.isElementSelectable(id);
4415
+ };
4416
+ DiagramEngine.prototype.isPortVisible = function (id) {
4417
+ return this.model.isPortVisible(id);
4418
+ };
4419
+ DiagramEngine.prototype.isLinkVisible = function (id) {
4420
+ return this.model.isLinkVisible(id);
4421
+ };
4422
+ DiagramEngine.prototype.isTextVisible = function (id) {
4423
+ return this.model.isTextVisible(id);
4424
+ };
4341
4425
  DiagramEngine.prototype.getElementWorldPosition = function (id) {
4342
4426
  return this.model.getElementWorldPosition(id);
4343
4427
  };
@@ -4599,11 +4683,15 @@ var DiagramEngine = /** @class */ (function () {
4599
4683
  var _this = this;
4600
4684
  var _a;
4601
4685
  var allPatches = this.appendTextLayoutPatches(patches, (_a = options === null || options === void 0 ? void 0 : options.emitTextUpdated) !== null && _a !== void 0 ? _a : true);
4686
+ var selectionChanged = this.syncSelectionToPolicies();
4602
4687
  var state = this.model.toState();
4603
4688
  this.events.emit('change', { patches: allPatches, state: state });
4604
- if ((options === null || options === void 0 ? void 0 : options.render) === false)
4605
- return;
4606
- this.scheduler.requestRender(function () { return _this.renderer.render(_this.model); });
4689
+ if ((options === null || options === void 0 ? void 0 : options.render) !== false) {
4690
+ this.scheduler.requestRender(function () { return _this.renderer.render(_this.model); });
4691
+ }
4692
+ if (selectionChanged) {
4693
+ this.emitSelection();
4694
+ }
4607
4695
  };
4608
4696
  DiagramEngine.prototype.appendTextLayoutPatches = function (patches, emitTextUpdated) {
4609
4697
  var _this = this;
@@ -5049,6 +5137,31 @@ var DiagramEngine = /** @class */ (function () {
5049
5137
  });
5050
5138
  this.renderer.renderSelection(selectedIds);
5051
5139
  };
5140
+ DiagramEngine.prototype.normalizeSelectionIds = function (ids) {
5141
+ var _this = this;
5142
+ return ids.filter(function (id, index) { return ids.indexOf(id) === index && _this.isSelectableId(id); });
5143
+ };
5144
+ DiagramEngine.prototype.isSelectableId = function (id) {
5145
+ if (this.model.getElement(id))
5146
+ return this.model.isElementSelectable(id);
5147
+ if (this.model.getPort(id))
5148
+ return this.model.isPortVisible(id);
5149
+ if (this.model.getLink(id))
5150
+ return this.model.isLinkVisible(id);
5151
+ if (this.model.getText(id))
5152
+ return this.model.isTextVisible(id);
5153
+ return false;
5154
+ };
5155
+ DiagramEngine.prototype.syncSelectionToPolicies = function () {
5156
+ var current = this.selection.get();
5157
+ var normalized = this.normalizeSelectionIds(current);
5158
+ if (current.length === normalized.length &&
5159
+ current.every(function (id, index) { return id === normalized[index]; })) {
5160
+ return false;
5161
+ }
5162
+ this.selection.set(normalized);
5163
+ return true;
5164
+ };
5052
5165
  DiagramEngine.prototype.applyLayoutForParent = function (parentId, options) {
5053
5166
  return this.autoLayoutService.applyLayoutForParent(parentId, options);
5054
5167
  };
@@ -6001,7 +6114,9 @@ var KonvaRenderer = /** @class */ (function () {
6001
6114
  };
6002
6115
  KonvaRenderer.prototype.syncElements = function (model) {
6003
6116
  var _this = this;
6004
- var elements = Array.from(model.elements.values()).map(function (element, index) { return ({
6117
+ var elements = Array.from(model.elements.values())
6118
+ .filter(function (element) { return model.isElementVisible(element.id); })
6119
+ .map(function (element, index) { return ({
6005
6120
  element: element,
6006
6121
  depth: _this.getElementDepth(model, element),
6007
6122
  order: index,
@@ -6034,6 +6149,10 @@ var KonvaRenderer = /** @class */ (function () {
6034
6149
  node.setAttrs({ __depth: depth });
6035
6150
  }
6036
6151
  });
6152
+ var visibleElementIds = new Set(elements.map(function (_a) {
6153
+ var element = _a.element;
6154
+ return element.id;
6155
+ }));
6037
6156
  elements.forEach(function (_a) {
6038
6157
  var _b;
6039
6158
  var element = _a.element;
@@ -6042,7 +6161,7 @@ var KonvaRenderer = /** @class */ (function () {
6042
6161
  });
6043
6162
  Array.from(this.elementNodes.keys()).forEach(function (id) {
6044
6163
  var _a;
6045
- if (!model.elements.has(id)) {
6164
+ if (!visibleElementIds.has(id)) {
6046
6165
  var node = _this.elementNodes.get(id);
6047
6166
  (_a = node === null || node === void 0 ? void 0 : node.destroy) === null || _a === void 0 ? void 0 : _a.call(node);
6048
6167
  _this.elementNodes.delete(id);
@@ -6065,7 +6184,7 @@ var KonvaRenderer = /** @class */ (function () {
6065
6184
  };
6066
6185
  KonvaRenderer.prototype.syncPorts = function (model) {
6067
6186
  var _this = this;
6068
- var ports = Array.from(model.ports.values());
6187
+ var ports = Array.from(model.ports.values()).filter(function (port) { return model.isPortVisible(port.id); });
6069
6188
  ports.forEach(function (port) {
6070
6189
  var _a, _b, _c, _d, _e;
6071
6190
  var data = port.toData();
@@ -6083,9 +6202,10 @@ var KonvaRenderer = /** @class */ (function () {
6083
6202
  _this.updatePosition(node, position);
6084
6203
  _this.applyPortOrientation(node, data, position, model);
6085
6204
  });
6205
+ var visiblePortIds = new Set(ports.map(function (port) { return port.id; }));
6086
6206
  Array.from(this.portNodes.keys()).forEach(function (id) {
6087
6207
  var _a;
6088
- if (!model.ports.has(id)) {
6208
+ if (!visiblePortIds.has(id)) {
6089
6209
  var node = _this.portNodes.get(id);
6090
6210
  (_a = node === null || node === void 0 ? void 0 : node.destroy) === null || _a === void 0 ? void 0 : _a.call(node);
6091
6211
  _this.portNodes.delete(id);
@@ -6096,7 +6216,7 @@ var KonvaRenderer = /** @class */ (function () {
6096
6216
  };
6097
6217
  KonvaRenderer.prototype.syncLinks = function (model) {
6098
6218
  var _this = this;
6099
- var links = Array.from(model.links.values());
6219
+ var links = Array.from(model.links.values()).filter(function (link) { return model.isLinkVisible(link.id); });
6100
6220
  links.forEach(function (link) {
6101
6221
  var _a, _b;
6102
6222
  var node = _this.linkNodes.get(link.id);
@@ -6107,9 +6227,10 @@ var KonvaRenderer = /** @class */ (function () {
6107
6227
  }
6108
6228
  _this.updateLine(node, link.toData());
6109
6229
  });
6230
+ var visibleLinkIds = new Set(links.map(function (link) { return link.id; }));
6110
6231
  Array.from(this.linkNodes.keys()).forEach(function (id) {
6111
6232
  var _a;
6112
- if (!model.links.has(id)) {
6233
+ if (!visibleLinkIds.has(id)) {
6113
6234
  var node = _this.linkNodes.get(id);
6114
6235
  (_a = node === null || node === void 0 ? void 0 : node.destroy) === null || _a === void 0 ? void 0 : _a.call(node);
6115
6236
  _this.linkNodes.delete(id);
@@ -6120,7 +6241,7 @@ var KonvaRenderer = /** @class */ (function () {
6120
6241
  };
6121
6242
  KonvaRenderer.prototype.syncTexts = function (model) {
6122
6243
  var _this = this;
6123
- var texts = Array.from(model.texts.values());
6244
+ var texts = Array.from(model.texts.values()).filter(function (text) { return model.isTextVisible(text.id); });
6124
6245
  texts.forEach(function (text) {
6125
6246
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
6126
6247
  var node = _this.textNodes.get(text.id);
@@ -6209,9 +6330,10 @@ var KonvaRenderer = /** @class */ (function () {
6209
6330
  _this.textBackgroundNodes.delete(text.id);
6210
6331
  }
6211
6332
  });
6333
+ var visibleTextIds = new Set(texts.map(function (text) { return text.id; }));
6212
6334
  Array.from(this.textNodes.keys()).forEach(function (id) {
6213
6335
  var _a, _b;
6214
- if (!model.texts.has(id)) {
6336
+ if (!visibleTextIds.has(id)) {
6215
6337
  var backgroundNode = _this.textBackgroundNodes.get(id);
6216
6338
  (_a = backgroundNode === null || backgroundNode === void 0 ? void 0 : backgroundNode.destroy) === null || _a === void 0 ? void 0 : _a.call(backgroundNode);
6217
6339
  _this.textBackgroundNodes.delete(id);
@@ -7214,15 +7336,21 @@ var KonvaInteraction = /** @class */ (function () {
7214
7336
  KonvaInteraction.prototype.normalizeHit = function (hit) {
7215
7337
  if (!hit || hit.type === 'none')
7216
7338
  return null;
7217
- if (hit.type === 'port' ||
7218
- hit.type === 'link' ||
7219
- hit.type === 'text' ||
7220
- hit.type === 'resize-handle' ||
7339
+ if (hit.type === 'port') {
7340
+ return this.engine.isPortVisible(hit.id) ? hit : null;
7341
+ }
7342
+ if (hit.type === 'link') {
7343
+ return this.engine.isLinkVisible(hit.id) ? hit : null;
7344
+ }
7345
+ if (hit.type === 'text') {
7346
+ return this.engine.isTextVisible(hit.id) ? hit : null;
7347
+ }
7348
+ if (hit.type === 'resize-handle' ||
7221
7349
  hit.type === 'link-handle' ||
7222
7350
  hit.type === 'shape-hover-control') {
7223
7351
  return hit;
7224
7352
  }
7225
- return __assign(__assign({}, hit), { type: 'element' });
7353
+ return this.engine.isElementSelectable(hit.id) ? __assign(__assign({}, hit), { type: 'element' }) : null;
7226
7354
  };
7227
7355
  KonvaInteraction.prototype.resolveHit = function (point) {
7228
7356
  var _this = this;
@@ -7288,6 +7416,8 @@ var KonvaInteraction = /** @class */ (function () {
7288
7416
  var best = null;
7289
7417
  state.elements.forEach(function (element) {
7290
7418
  var _a, _b, _c;
7419
+ if (!_this.engine.isElementSelectable(element.id))
7420
+ return;
7291
7421
  var world = (_a = _this.engine.getElementWorldPosition(element.id)) !== null && _a !== void 0 ? _a : element.position;
7292
7422
  var rotation = _this.engine.getElementRotation(element.id);
7293
7423
  if (!pointInRotatedRect(point, world, element.size, rotation, (_b = element.anchorCenter) !== null && _b !== void 0 ? _b : false))
@@ -7317,6 +7447,8 @@ var KonvaInteraction = /** @class */ (function () {
7317
7447
  var bestDistance = Number.POSITIVE_INFINITY;
7318
7448
  links.forEach(function (link) {
7319
7449
  var _a, _b;
7450
+ if (!_this.engine.isLinkVisible(link.id))
7451
+ return;
7320
7452
  if (link.points.length < 2)
7321
7453
  return;
7322
7454
  var tolerance = ((_b = (_a = link.style) === null || _a === void 0 ? void 0 : _a.hitStrokeWidth) !== null && _b !== void 0 ? _b : 15) / 2;
@@ -8331,6 +8463,8 @@ var KonvaInteraction = /** @class */ (function () {
8331
8463
  };
8332
8464
  state.elements.forEach(function (element) {
8333
8465
  var _a, _b;
8466
+ if (!_this.engine.isElementSelectable(element.id))
8467
+ return;
8334
8468
  var position = (_a = _this.engine.getElementWorldPosition(element.id)) !== null && _a !== void 0 ? _a : element.position;
8335
8469
  var rotation = _this.engine.getElementRotation(element.id);
8336
8470
  var anchorCenter = (_b = element.anchorCenter) !== null && _b !== void 0 ? _b : false;
@@ -8348,6 +8482,8 @@ var KonvaInteraction = /** @class */ (function () {
8348
8482
  });
8349
8483
  state.ports.forEach(function (port) {
8350
8484
  var _a;
8485
+ if (!_this.engine.isPortVisible(port.id))
8486
+ return;
8351
8487
  var position = (_a = _this.engine.getPortWorldPosition(port.id)) !== null && _a !== void 0 ? _a : port.position;
8352
8488
  if (containsPoint(position)) {
8353
8489
  selected.add(port.id);
@@ -8355,6 +8491,8 @@ var KonvaInteraction = /** @class */ (function () {
8355
8491
  });
8356
8492
  state.texts.forEach(function (text) {
8357
8493
  var _a, _b, _c, _d, _e;
8494
+ if (!_this.engine.isTextVisible(text.id))
8495
+ return;
8358
8496
  var position = (_a = _this.engine.getTextWorldPosition(text.id)) !== null && _a !== void 0 ? _a : text.position;
8359
8497
  var width = (_c = (_b = text.size) === null || _b === void 0 ? void 0 : _b.width) !== null && _c !== void 0 ? _c : 0;
8360
8498
  var height = (_e = (_d = text.size) === null || _d === void 0 ? void 0 : _d.height) !== null && _e !== void 0 ? _e : 0;
@@ -8364,6 +8502,8 @@ var KonvaInteraction = /** @class */ (function () {
8364
8502
  }
8365
8503
  });
8366
8504
  state.links.forEach(function (link) {
8505
+ if (!_this.engine.isLinkVisible(link.id))
8506
+ return;
8367
8507
  if (link.points.length === 0)
8368
8508
  return;
8369
8509
  var xs = link.points.map(function (point) { return point.x; });
@@ -9295,13 +9435,65 @@ var resolveViewportFitOptions = function (options) {
9295
9435
  return { padding: padding, minZoom: minZoom, maxZoom: maxZoom };
9296
9436
  };
9297
9437
  var clamp = function (value, min, max) { return Math.max(min, Math.min(max, value)); };
9438
+ var isElementVisibleInState = function (elementId, elementsById) {
9439
+ var _a, _b;
9440
+ var element = elementsById.get(elementId);
9441
+ if (!element)
9442
+ return false;
9443
+ if (element.visible === false)
9444
+ return false;
9445
+ var currentParentId = (_a = element.parentId) !== null && _a !== void 0 ? _a : null;
9446
+ while (currentParentId) {
9447
+ var parent_1 = elementsById.get(currentParentId);
9448
+ if (!parent_1)
9449
+ break;
9450
+ if (parent_1.visible === false)
9451
+ return false;
9452
+ currentParentId = (_b = parent_1.parentId) !== null && _b !== void 0 ? _b : null;
9453
+ }
9454
+ return true;
9455
+ };
9456
+ var isPortVisibleInState = function (portId, portsById, elementsById) {
9457
+ var port = portsById.get(portId);
9458
+ if (!port)
9459
+ return false;
9460
+ return isElementVisibleInState(port.elementId, elementsById);
9461
+ };
9462
+ var isLinkVisibleInState = function (linkId, linksById, portsById, elementsById) {
9463
+ var link = linksById.get(linkId);
9464
+ if (!link)
9465
+ return false;
9466
+ var sourcePort = portsById.get(link.sourcePortId);
9467
+ var targetPort = portsById.get(link.targetPortId);
9468
+ var sourceVisible = sourcePort ? isPortVisibleInState(sourcePort.id, portsById, elementsById) : true;
9469
+ var targetVisible = targetPort ? isPortVisibleInState(targetPort.id, portsById, elementsById) : true;
9470
+ return sourceVisible && targetVisible;
9471
+ };
9472
+ var isTextVisibleInState = function (text, elementsById, portsById, linksById) {
9473
+ if (!text.ownerId)
9474
+ return true;
9475
+ if (elementsById.has(text.ownerId))
9476
+ return isElementVisibleInState(text.ownerId, elementsById);
9477
+ if (portsById.has(text.ownerId))
9478
+ return isPortVisibleInState(text.ownerId, portsById, elementsById);
9479
+ if (linksById.has(text.ownerId))
9480
+ return isLinkVisibleInState(text.ownerId, linksById, portsById, elementsById);
9481
+ return true;
9482
+ };
9298
9483
  var resolveStateWorldBounds = function (state) {
9299
9484
  var bounds = createBounds();
9485
+ var elementsById = new Map(state.elements.map(function (element) { return [element.id, element]; }));
9486
+ var portsById = new Map(state.ports.map(function (port) { return [port.id, port]; }));
9487
+ var linksById = new Map(state.links.map(function (link) { return [link.id, link]; }));
9300
9488
  state.elements.forEach(function (element) {
9489
+ if (!isElementVisibleInState(element.id, elementsById))
9490
+ return;
9301
9491
  includeRect(bounds, element.position.x, element.position.y, element.size.width, element.size.height);
9302
9492
  });
9303
9493
  state.ports.forEach(function (port) {
9304
9494
  var _a;
9495
+ if (!isPortVisibleInState(port.id, portsById, elementsById))
9496
+ return;
9305
9497
  var size = port.size;
9306
9498
  if (!size) {
9307
9499
  expandBounds(bounds, port.position.x, port.position.y);
@@ -9313,12 +9505,16 @@ var resolveStateWorldBounds = function (state) {
9313
9505
  includeRect(bounds, x, y, size.width, size.height);
9314
9506
  });
9315
9507
  state.links.forEach(function (link) {
9508
+ if (!isLinkVisibleInState(link.id, linksById, portsById, elementsById))
9509
+ return;
9316
9510
  link.points.forEach(function (point) {
9317
9511
  expandBounds(bounds, point.x, point.y);
9318
9512
  });
9319
9513
  });
9320
9514
  state.texts.forEach(function (text) {
9321
9515
  var _a;
9516
+ if (!isTextVisibleInState(text, elementsById, portsById, linksById))
9517
+ return;
9322
9518
  var offset = (_a = text.displayOffset) !== null && _a !== void 0 ? _a : { x: 0, y: 0 };
9323
9519
  var position = { x: text.position.x + offset.x, y: text.position.y + offset.y };
9324
9520
  var clipSize = text.displayClipSize;
@@ -9333,7 +9529,10 @@ var resolveStateWorldBounds = function (state) {
9333
9529
  };
9334
9530
  var resolveElementWorldBounds = function (state) {
9335
9531
  var bounds = createBounds();
9532
+ var elementsById = new Map(state.elements.map(function (element) { return [element.id, element]; }));
9336
9533
  state.elements.forEach(function (element) {
9534
+ if (!isElementVisibleInState(element.id, elementsById))
9535
+ return;
9337
9536
  includeRect(bounds, element.position.x, element.position.y, element.size.width, element.size.height);
9338
9537
  });
9339
9538
  return hasBounds(bounds) ? bounds : null;