orcasvn-react-diagrams 0.2.8 → 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.
@@ -1146,6 +1146,128 @@ var selectionDemoConfig = ({
1146
1146
  ],
1147
1147
  });
1148
1148
 
1149
+ var createElementVisibilitySelectionState = function () { return ({
1150
+ elements: [
1151
+ {
1152
+ id: 'policy-normal',
1153
+ position: { x: 120, y: 160 },
1154
+ size: { width: 180, height: 120 },
1155
+ shapeId: 'default',
1156
+ style: { fill: '#dbeafe', stroke: '#1d4ed8', strokeWidth: 2 },
1157
+ },
1158
+ {
1159
+ id: 'policy-unselectable',
1160
+ position: { x: 410, y: 160 },
1161
+ size: { width: 180, height: 120 },
1162
+ shapeId: 'default',
1163
+ selectable: false,
1164
+ style: { fill: '#e2e8f0', stroke: '#334155', strokeWidth: 2 },
1165
+ },
1166
+ {
1167
+ id: 'policy-hidden',
1168
+ position: { x: 700, y: 140 },
1169
+ size: { width: 180, height: 120 },
1170
+ shapeId: 'default',
1171
+ visible: false,
1172
+ style: { fill: '#fee2e2', stroke: '#dc2626', strokeWidth: 2 },
1173
+ },
1174
+ ],
1175
+ ports: [
1176
+ {
1177
+ id: 'policy-normal-port',
1178
+ elementId: 'policy-normal',
1179
+ position: { x: 180, y: 60 },
1180
+ shapeId: 'port-circle',
1181
+ },
1182
+ {
1183
+ id: 'policy-unselectable-port',
1184
+ elementId: 'policy-unselectable',
1185
+ position: { x: 0, y: 60 },
1186
+ shapeId: 'port-circle',
1187
+ },
1188
+ {
1189
+ id: 'policy-hidden-port',
1190
+ elementId: 'policy-hidden',
1191
+ position: { x: 0, y: 60 },
1192
+ shapeId: 'port-circle',
1193
+ },
1194
+ ],
1195
+ links: [
1196
+ {
1197
+ id: 'policy-visible-link',
1198
+ sourcePortId: 'policy-normal-port',
1199
+ targetPortId: 'policy-unselectable-port',
1200
+ points: [
1201
+ { x: 300, y: 220 },
1202
+ { x: 410, y: 220 },
1203
+ ],
1204
+ style: { stroke: '#2563eb', strokeWidth: 3 },
1205
+ },
1206
+ {
1207
+ id: 'policy-hidden-link',
1208
+ sourcePortId: 'policy-normal-port',
1209
+ targetPortId: 'policy-hidden-port',
1210
+ points: [
1211
+ { x: 300, y: 220 },
1212
+ { x: 700, y: 200 },
1213
+ ],
1214
+ style: { stroke: '#dc2626', strokeWidth: 3 },
1215
+ },
1216
+ ],
1217
+ texts: [
1218
+ {
1219
+ id: 'policy-tip',
1220
+ content: 'Blue node is normal. Slate node is visible but its body ignores click and marquee. Its port stays interactive. Hidden node, its port, and its attached red link stay in state but are suppressed from scene, selection, zoom-to-fit, and fit-to-content export.',
1221
+ position: { x: 80, y: 72 },
1222
+ size: { width: 760, height: 44 },
1223
+ style: { fontSize: 14, fill: '#0f172a' },
1224
+ },
1225
+ {
1226
+ id: 'policy-normal-label',
1227
+ content: 'Normal selectable element',
1228
+ position: { x: 16, y: 14 },
1229
+ ownerId: 'policy-normal',
1230
+ },
1231
+ {
1232
+ id: 'policy-unselectable-label',
1233
+ content: 'Visible but body is unselectable',
1234
+ position: { x: 16, y: 14 },
1235
+ ownerId: 'policy-unselectable',
1236
+ },
1237
+ {
1238
+ id: 'policy-hidden-label',
1239
+ content: 'Hidden in state',
1240
+ position: { x: 16, y: 14 },
1241
+ ownerId: 'policy-hidden',
1242
+ },
1243
+ ],
1244
+ }); };
1245
+ var elementVisibilitySelectionDemoConfig = {
1246
+ id: 'element-visibility-selection',
1247
+ title: 'Element Visibility + Selectability',
1248
+ description: 'QA scene for visible-but-unselectable element bodies, hidden-in-state elements, and port/link propagation. Shift + drag marquee to confirm only eligible items are collected.',
1249
+ createState: createElementVisibilitySelectionState,
1250
+ elementShapes: baseElementShapes,
1251
+ portShapes: basePortShapes,
1252
+ defaultElementShapeId: 'default',
1253
+ defaultPortShapeId: 'port-circle',
1254
+ actions: [
1255
+ {
1256
+ id: 'policy-filtered-selection',
1257
+ label: 'Try filtered API selection',
1258
+ run: function (editor) {
1259
+ editor.setSelection([
1260
+ 'policy-normal',
1261
+ 'policy-unselectable',
1262
+ 'policy-hidden',
1263
+ 'policy-unselectable-port',
1264
+ 'policy-hidden-link',
1265
+ ]);
1266
+ },
1267
+ },
1268
+ ],
1269
+ };
1270
+
1149
1271
  var createEventHandlersState = function () { return ({
1150
1272
  elements: [
1151
1273
  {
@@ -4612,6 +4734,8 @@ var ElementModel = /** @class */ (function () {
4612
4734
  this.style = data.style;
4613
4735
  this.portIds = data.portIds ? __spreadArray([], data.portIds, true) : [];
4614
4736
  this.textIds = data.textIds ? __spreadArray([], data.textIds, true) : [];
4737
+ this.visible = data.visible;
4738
+ this.selectable = data.selectable;
4615
4739
  this.parentId = (_a = data.parentId) !== null && _a !== void 0 ? _a : null;
4616
4740
  this.moveMode = data.moveMode;
4617
4741
  this.anchorCenter = data.anchorCenter;
@@ -4650,6 +4774,8 @@ var ElementModel = /** @class */ (function () {
4650
4774
  style: this.style,
4651
4775
  portIds: __spreadArray([], this.portIds, true),
4652
4776
  textIds: __spreadArray([], this.textIds, true),
4777
+ visible: this.visible,
4778
+ selectable: this.selectable,
4653
4779
  parentId: this.parentId,
4654
4780
  moveMode: this.moveMode,
4655
4781
  anchorCenter: this.anchorCenter,
@@ -5053,6 +5179,29 @@ var DiagramModel = /** @class */ (function () {
5053
5179
  DiagramModel.prototype.getElement = function (id) {
5054
5180
  return this.elements.get(id);
5055
5181
  };
5182
+ DiagramModel.prototype.isElementVisible = function (id) {
5183
+ var element = this.elements.get(id);
5184
+ if (!element)
5185
+ return false;
5186
+ if (element.visible === false)
5187
+ return false;
5188
+ var currentParentId = element.parentId;
5189
+ while (currentParentId) {
5190
+ var parent_1 = this.elements.get(currentParentId);
5191
+ if (!parent_1)
5192
+ break;
5193
+ if (parent_1.visible === false)
5194
+ return false;
5195
+ currentParentId = parent_1.parentId;
5196
+ }
5197
+ return true;
5198
+ };
5199
+ DiagramModel.prototype.isElementSelectable = function (id) {
5200
+ var element = this.elements.get(id);
5201
+ if (!element)
5202
+ return false;
5203
+ return this.isElementVisible(id) && element.selectable !== false;
5204
+ };
5056
5205
  DiagramModel.prototype.setElementLayout = function (id, layout) {
5057
5206
  var element = this.elements.get(id);
5058
5207
  if (!element)
@@ -5071,6 +5220,12 @@ var DiagramModel = /** @class */ (function () {
5071
5220
  DiagramModel.prototype.getPort = function (id) {
5072
5221
  return this.ports.get(id);
5073
5222
  };
5223
+ DiagramModel.prototype.isPortVisible = function (id) {
5224
+ var port = this.ports.get(id);
5225
+ if (!port)
5226
+ return false;
5227
+ return this.isElementVisible(port.elementId);
5228
+ };
5074
5229
  DiagramModel.prototype.getPortWorldPosition = function (id) {
5075
5230
  var port = this.ports.get(id);
5076
5231
  if (!port)
@@ -5086,6 +5241,16 @@ var DiagramModel = /** @class */ (function () {
5086
5241
  DiagramModel.prototype.getLink = function (id) {
5087
5242
  return this.links.get(id);
5088
5243
  };
5244
+ DiagramModel.prototype.isLinkVisible = function (id) {
5245
+ var link = this.links.get(id);
5246
+ if (!link)
5247
+ return false;
5248
+ var sourcePort = this.ports.get(link.sourcePortId);
5249
+ var targetPort = this.ports.get(link.targetPortId);
5250
+ var sourceVisible = sourcePort ? this.isPortVisible(sourcePort.id) : true;
5251
+ var targetVisible = targetPort ? this.isPortVisible(targetPort.id) : true;
5252
+ return sourceVisible && targetVisible;
5253
+ };
5089
5254
  DiagramModel.prototype.getLinkMidpoint = function (id) {
5090
5255
  var link = this.links.get(id);
5091
5256
  if (!link)
@@ -5095,6 +5260,23 @@ var DiagramModel = /** @class */ (function () {
5095
5260
  DiagramModel.prototype.getText = function (id) {
5096
5261
  return this.texts.get(id);
5097
5262
  };
5263
+ DiagramModel.prototype.isTextVisible = function (id) {
5264
+ var text = this.texts.get(id);
5265
+ if (!text)
5266
+ return false;
5267
+ if (!text.ownerId)
5268
+ return true;
5269
+ if (this.elements.has(text.ownerId)) {
5270
+ return this.isElementVisible(text.ownerId);
5271
+ }
5272
+ if (this.ports.has(text.ownerId)) {
5273
+ return this.isPortVisible(text.ownerId);
5274
+ }
5275
+ if (this.links.has(text.ownerId)) {
5276
+ return this.isLinkVisible(text.ownerId);
5277
+ }
5278
+ return true;
5279
+ };
5098
5280
  DiagramModel.prototype.getTextWorldPosition = function (id) {
5099
5281
  var text = this.texts.get(id);
5100
5282
  if (!text)
@@ -5283,18 +5465,18 @@ var DiagramModel = /** @class */ (function () {
5283
5465
  }
5284
5466
  var current = element;
5285
5467
  while (current === null || current === void 0 ? void 0 : current.parentId) {
5286
- var parent_1 = this.elements.get(current.parentId);
5287
- if (!parent_1)
5468
+ var parent_2 = this.elements.get(current.parentId);
5469
+ if (!parent_2)
5288
5470
  break;
5289
- var parentX = parent_1.position.x;
5290
- var parentY = parent_1.position.y;
5291
- if (parent_1.anchorCenter) {
5292
- parentX -= parent_1.size.width / 2;
5293
- parentY -= parent_1.size.height / 2;
5471
+ var parentX = parent_2.position.x;
5472
+ var parentY = parent_2.position.y;
5473
+ if (parent_2.anchorCenter) {
5474
+ parentX -= parent_2.size.width / 2;
5475
+ parentY -= parent_2.size.height / 2;
5294
5476
  }
5295
5477
  x += parentX;
5296
5478
  y += parentY;
5297
- current = parent_1;
5479
+ current = parent_2;
5298
5480
  }
5299
5481
  return { x: x, y: y };
5300
5482
  };
@@ -8409,16 +8591,38 @@ var DiagramEngine = /** @class */ (function () {
8409
8591
  this.emitEntityDeletionEvents(removal.removed);
8410
8592
  };
8411
8593
  DiagramEngine.prototype.setSelection = function (ids) {
8412
- this.selection.set(ids);
8594
+ this.selection.set(this.normalizeSelectionIds(ids));
8413
8595
  this.emitSelection();
8414
8596
  };
8415
8597
  DiagramEngine.prototype.toggleSelection = function (id) {
8416
- this.selection.toggle(id);
8598
+ var current = new Set(this.selection.get());
8599
+ if (current.has(id)) {
8600
+ current.delete(id);
8601
+ }
8602
+ else if (this.isSelectableId(id)) {
8603
+ current.add(id);
8604
+ }
8605
+ this.selection.set(Array.from(current));
8417
8606
  this.emitSelection();
8418
8607
  };
8419
8608
  DiagramEngine.prototype.getSelection = function () {
8420
8609
  return this.selection.get();
8421
8610
  };
8611
+ DiagramEngine.prototype.isElementVisible = function (id) {
8612
+ return this.model.isElementVisible(id);
8613
+ };
8614
+ DiagramEngine.prototype.isElementSelectable = function (id) {
8615
+ return this.model.isElementSelectable(id);
8616
+ };
8617
+ DiagramEngine.prototype.isPortVisible = function (id) {
8618
+ return this.model.isPortVisible(id);
8619
+ };
8620
+ DiagramEngine.prototype.isLinkVisible = function (id) {
8621
+ return this.model.isLinkVisible(id);
8622
+ };
8623
+ DiagramEngine.prototype.isTextVisible = function (id) {
8624
+ return this.model.isTextVisible(id);
8625
+ };
8422
8626
  DiagramEngine.prototype.getElementWorldPosition = function (id) {
8423
8627
  return this.model.getElementWorldPosition(id);
8424
8628
  };
@@ -8680,11 +8884,15 @@ var DiagramEngine = /** @class */ (function () {
8680
8884
  var _this = this;
8681
8885
  var _a;
8682
8886
  var allPatches = this.appendTextLayoutPatches(patches, (_a = options === null || options === void 0 ? void 0 : options.emitTextUpdated) !== null && _a !== void 0 ? _a : true);
8887
+ var selectionChanged = this.syncSelectionToPolicies();
8683
8888
  var state = this.model.toState();
8684
8889
  this.events.emit('change', { patches: allPatches, state: state });
8685
- if ((options === null || options === void 0 ? void 0 : options.render) === false)
8686
- return;
8687
- this.scheduler.requestRender(function () { return _this.renderer.render(_this.model); });
8890
+ if ((options === null || options === void 0 ? void 0 : options.render) !== false) {
8891
+ this.scheduler.requestRender(function () { return _this.renderer.render(_this.model); });
8892
+ }
8893
+ if (selectionChanged) {
8894
+ this.emitSelection();
8895
+ }
8688
8896
  };
8689
8897
  DiagramEngine.prototype.appendTextLayoutPatches = function (patches, emitTextUpdated) {
8690
8898
  var _this = this;
@@ -9130,6 +9338,31 @@ var DiagramEngine = /** @class */ (function () {
9130
9338
  });
9131
9339
  this.renderer.renderSelection(selectedIds);
9132
9340
  };
9341
+ DiagramEngine.prototype.normalizeSelectionIds = function (ids) {
9342
+ var _this = this;
9343
+ return ids.filter(function (id, index) { return ids.indexOf(id) === index && _this.isSelectableId(id); });
9344
+ };
9345
+ DiagramEngine.prototype.isSelectableId = function (id) {
9346
+ if (this.model.getElement(id))
9347
+ return this.model.isElementSelectable(id);
9348
+ if (this.model.getPort(id))
9349
+ return this.model.isPortVisible(id);
9350
+ if (this.model.getLink(id))
9351
+ return this.model.isLinkVisible(id);
9352
+ if (this.model.getText(id))
9353
+ return this.model.isTextVisible(id);
9354
+ return false;
9355
+ };
9356
+ DiagramEngine.prototype.syncSelectionToPolicies = function () {
9357
+ var current = this.selection.get();
9358
+ var normalized = this.normalizeSelectionIds(current);
9359
+ if (current.length === normalized.length &&
9360
+ current.every(function (id, index) { return id === normalized[index]; })) {
9361
+ return false;
9362
+ }
9363
+ this.selection.set(normalized);
9364
+ return true;
9365
+ };
9133
9366
  DiagramEngine.prototype.applyLayoutForParent = function (parentId, options) {
9134
9367
  return this.autoLayoutService.applyLayoutForParent(parentId, options);
9135
9368
  };
@@ -10047,7 +10280,9 @@ var KonvaRenderer = /** @class */ (function () {
10047
10280
  };
10048
10281
  KonvaRenderer.prototype.syncElements = function (model) {
10049
10282
  var _this = this;
10050
- var elements = Array.from(model.elements.values()).map(function (element, index) { return ({
10283
+ var elements = Array.from(model.elements.values())
10284
+ .filter(function (element) { return model.isElementVisible(element.id); })
10285
+ .map(function (element, index) { return ({
10051
10286
  element: element,
10052
10287
  depth: _this.getElementDepth(model, element),
10053
10288
  order: index,
@@ -10080,6 +10315,10 @@ var KonvaRenderer = /** @class */ (function () {
10080
10315
  node.setAttrs({ __depth: depth });
10081
10316
  }
10082
10317
  });
10318
+ var visibleElementIds = new Set(elements.map(function (_a) {
10319
+ var element = _a.element;
10320
+ return element.id;
10321
+ }));
10083
10322
  elements.forEach(function (_a) {
10084
10323
  var _b;
10085
10324
  var element = _a.element;
@@ -10088,7 +10327,7 @@ var KonvaRenderer = /** @class */ (function () {
10088
10327
  });
10089
10328
  Array.from(this.elementNodes.keys()).forEach(function (id) {
10090
10329
  var _a;
10091
- if (!model.elements.has(id)) {
10330
+ if (!visibleElementIds.has(id)) {
10092
10331
  var node = _this.elementNodes.get(id);
10093
10332
  (_a = node === null || node === void 0 ? void 0 : node.destroy) === null || _a === void 0 ? void 0 : _a.call(node);
10094
10333
  _this.elementNodes.delete(id);
@@ -10111,7 +10350,7 @@ var KonvaRenderer = /** @class */ (function () {
10111
10350
  };
10112
10351
  KonvaRenderer.prototype.syncPorts = function (model) {
10113
10352
  var _this = this;
10114
- var ports = Array.from(model.ports.values());
10353
+ var ports = Array.from(model.ports.values()).filter(function (port) { return model.isPortVisible(port.id); });
10115
10354
  ports.forEach(function (port) {
10116
10355
  var _a, _b, _c, _d, _e;
10117
10356
  var data = port.toData();
@@ -10129,9 +10368,10 @@ var KonvaRenderer = /** @class */ (function () {
10129
10368
  _this.updatePosition(node, position);
10130
10369
  _this.applyPortOrientation(node, data, position, model);
10131
10370
  });
10371
+ var visiblePortIds = new Set(ports.map(function (port) { return port.id; }));
10132
10372
  Array.from(this.portNodes.keys()).forEach(function (id) {
10133
10373
  var _a;
10134
- if (!model.ports.has(id)) {
10374
+ if (!visiblePortIds.has(id)) {
10135
10375
  var node = _this.portNodes.get(id);
10136
10376
  (_a = node === null || node === void 0 ? void 0 : node.destroy) === null || _a === void 0 ? void 0 : _a.call(node);
10137
10377
  _this.portNodes.delete(id);
@@ -10142,7 +10382,7 @@ var KonvaRenderer = /** @class */ (function () {
10142
10382
  };
10143
10383
  KonvaRenderer.prototype.syncLinks = function (model) {
10144
10384
  var _this = this;
10145
- var links = Array.from(model.links.values());
10385
+ var links = Array.from(model.links.values()).filter(function (link) { return model.isLinkVisible(link.id); });
10146
10386
  links.forEach(function (link) {
10147
10387
  var _a, _b;
10148
10388
  var node = _this.linkNodes.get(link.id);
@@ -10153,9 +10393,10 @@ var KonvaRenderer = /** @class */ (function () {
10153
10393
  }
10154
10394
  _this.updateLine(node, link.toData());
10155
10395
  });
10396
+ var visibleLinkIds = new Set(links.map(function (link) { return link.id; }));
10156
10397
  Array.from(this.linkNodes.keys()).forEach(function (id) {
10157
10398
  var _a;
10158
- if (!model.links.has(id)) {
10399
+ if (!visibleLinkIds.has(id)) {
10159
10400
  var node = _this.linkNodes.get(id);
10160
10401
  (_a = node === null || node === void 0 ? void 0 : node.destroy) === null || _a === void 0 ? void 0 : _a.call(node);
10161
10402
  _this.linkNodes.delete(id);
@@ -10166,7 +10407,7 @@ var KonvaRenderer = /** @class */ (function () {
10166
10407
  };
10167
10408
  KonvaRenderer.prototype.syncTexts = function (model) {
10168
10409
  var _this = this;
10169
- var texts = Array.from(model.texts.values());
10410
+ var texts = Array.from(model.texts.values()).filter(function (text) { return model.isTextVisible(text.id); });
10170
10411
  texts.forEach(function (text) {
10171
10412
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
10172
10413
  var node = _this.textNodes.get(text.id);
@@ -10255,9 +10496,10 @@ var KonvaRenderer = /** @class */ (function () {
10255
10496
  _this.textBackgroundNodes.delete(text.id);
10256
10497
  }
10257
10498
  });
10499
+ var visibleTextIds = new Set(texts.map(function (text) { return text.id; }));
10258
10500
  Array.from(this.textNodes.keys()).forEach(function (id) {
10259
10501
  var _a, _b;
10260
- if (!model.texts.has(id)) {
10502
+ if (!visibleTextIds.has(id)) {
10261
10503
  var backgroundNode = _this.textBackgroundNodes.get(id);
10262
10504
  (_a = backgroundNode === null || backgroundNode === void 0 ? void 0 : backgroundNode.destroy) === null || _a === void 0 ? void 0 : _a.call(backgroundNode);
10263
10505
  _this.textBackgroundNodes.delete(id);
@@ -11249,15 +11491,21 @@ var KonvaInteraction = /** @class */ (function () {
11249
11491
  KonvaInteraction.prototype.normalizeHit = function (hit) {
11250
11492
  if (!hit || hit.type === 'none')
11251
11493
  return null;
11252
- if (hit.type === 'port' ||
11253
- hit.type === 'link' ||
11254
- hit.type === 'text' ||
11255
- hit.type === 'resize-handle' ||
11494
+ if (hit.type === 'port') {
11495
+ return this.engine.isPortVisible(hit.id) ? hit : null;
11496
+ }
11497
+ if (hit.type === 'link') {
11498
+ return this.engine.isLinkVisible(hit.id) ? hit : null;
11499
+ }
11500
+ if (hit.type === 'text') {
11501
+ return this.engine.isTextVisible(hit.id) ? hit : null;
11502
+ }
11503
+ if (hit.type === 'resize-handle' ||
11256
11504
  hit.type === 'link-handle' ||
11257
11505
  hit.type === 'shape-hover-control') {
11258
11506
  return hit;
11259
11507
  }
11260
- return __assign(__assign({}, hit), { type: 'element' });
11508
+ return this.engine.isElementSelectable(hit.id) ? __assign(__assign({}, hit), { type: 'element' }) : null;
11261
11509
  };
11262
11510
  KonvaInteraction.prototype.resolveHit = function (point) {
11263
11511
  var _this = this;
@@ -11323,6 +11571,8 @@ var KonvaInteraction = /** @class */ (function () {
11323
11571
  var best = null;
11324
11572
  state.elements.forEach(function (element) {
11325
11573
  var _a, _b, _c;
11574
+ if (!_this.engine.isElementSelectable(element.id))
11575
+ return;
11326
11576
  var world = (_a = _this.engine.getElementWorldPosition(element.id)) !== null && _a !== void 0 ? _a : element.position;
11327
11577
  var rotation = _this.engine.getElementRotation(element.id);
11328
11578
  if (!pointInRotatedRect(point, world, element.size, rotation, (_b = element.anchorCenter) !== null && _b !== void 0 ? _b : false))
@@ -11352,6 +11602,8 @@ var KonvaInteraction = /** @class */ (function () {
11352
11602
  var bestDistance = Number.POSITIVE_INFINITY;
11353
11603
  links.forEach(function (link) {
11354
11604
  var _a, _b;
11605
+ if (!_this.engine.isLinkVisible(link.id))
11606
+ return;
11355
11607
  if (link.points.length < 2)
11356
11608
  return;
11357
11609
  var tolerance = ((_b = (_a = link.style) === null || _a === void 0 ? void 0 : _a.hitStrokeWidth) !== null && _b !== void 0 ? _b : 15) / 2;
@@ -12366,6 +12618,8 @@ var KonvaInteraction = /** @class */ (function () {
12366
12618
  };
12367
12619
  state.elements.forEach(function (element) {
12368
12620
  var _a, _b;
12621
+ if (!_this.engine.isElementSelectable(element.id))
12622
+ return;
12369
12623
  var position = (_a = _this.engine.getElementWorldPosition(element.id)) !== null && _a !== void 0 ? _a : element.position;
12370
12624
  var rotation = _this.engine.getElementRotation(element.id);
12371
12625
  var anchorCenter = (_b = element.anchorCenter) !== null && _b !== void 0 ? _b : false;
@@ -12383,6 +12637,8 @@ var KonvaInteraction = /** @class */ (function () {
12383
12637
  });
12384
12638
  state.ports.forEach(function (port) {
12385
12639
  var _a;
12640
+ if (!_this.engine.isPortVisible(port.id))
12641
+ return;
12386
12642
  var position = (_a = _this.engine.getPortWorldPosition(port.id)) !== null && _a !== void 0 ? _a : port.position;
12387
12643
  if (containsPoint(position)) {
12388
12644
  selected.add(port.id);
@@ -12390,6 +12646,8 @@ var KonvaInteraction = /** @class */ (function () {
12390
12646
  });
12391
12647
  state.texts.forEach(function (text) {
12392
12648
  var _a, _b, _c, _d, _e;
12649
+ if (!_this.engine.isTextVisible(text.id))
12650
+ return;
12393
12651
  var position = (_a = _this.engine.getTextWorldPosition(text.id)) !== null && _a !== void 0 ? _a : text.position;
12394
12652
  var width = (_c = (_b = text.size) === null || _b === void 0 ? void 0 : _b.width) !== null && _c !== void 0 ? _c : 0;
12395
12653
  var height = (_e = (_d = text.size) === null || _d === void 0 ? void 0 : _d.height) !== null && _e !== void 0 ? _e : 0;
@@ -12399,6 +12657,8 @@ var KonvaInteraction = /** @class */ (function () {
12399
12657
  }
12400
12658
  });
12401
12659
  state.links.forEach(function (link) {
12660
+ if (!_this.engine.isLinkVisible(link.id))
12661
+ return;
12402
12662
  if (link.points.length === 0)
12403
12663
  return;
12404
12664
  var xs = link.points.map(function (point) { return point.x; });
@@ -13330,13 +13590,65 @@ var resolveViewportFitOptions = function (options) {
13330
13590
  return { padding: padding, minZoom: minZoom, maxZoom: maxZoom };
13331
13591
  };
13332
13592
  var clamp = function (value, min, max) { return Math.max(min, Math.min(max, value)); };
13593
+ var isElementVisibleInState = function (elementId, elementsById) {
13594
+ var _a, _b;
13595
+ var element = elementsById.get(elementId);
13596
+ if (!element)
13597
+ return false;
13598
+ if (element.visible === false)
13599
+ return false;
13600
+ var currentParentId = (_a = element.parentId) !== null && _a !== void 0 ? _a : null;
13601
+ while (currentParentId) {
13602
+ var parent_1 = elementsById.get(currentParentId);
13603
+ if (!parent_1)
13604
+ break;
13605
+ if (parent_1.visible === false)
13606
+ return false;
13607
+ currentParentId = (_b = parent_1.parentId) !== null && _b !== void 0 ? _b : null;
13608
+ }
13609
+ return true;
13610
+ };
13611
+ var isPortVisibleInState = function (portId, portsById, elementsById) {
13612
+ var port = portsById.get(portId);
13613
+ if (!port)
13614
+ return false;
13615
+ return isElementVisibleInState(port.elementId, elementsById);
13616
+ };
13617
+ var isLinkVisibleInState = function (linkId, linksById, portsById, elementsById) {
13618
+ var link = linksById.get(linkId);
13619
+ if (!link)
13620
+ return false;
13621
+ var sourcePort = portsById.get(link.sourcePortId);
13622
+ var targetPort = portsById.get(link.targetPortId);
13623
+ var sourceVisible = sourcePort ? isPortVisibleInState(sourcePort.id, portsById, elementsById) : true;
13624
+ var targetVisible = targetPort ? isPortVisibleInState(targetPort.id, portsById, elementsById) : true;
13625
+ return sourceVisible && targetVisible;
13626
+ };
13627
+ var isTextVisibleInState = function (text, elementsById, portsById, linksById) {
13628
+ if (!text.ownerId)
13629
+ return true;
13630
+ if (elementsById.has(text.ownerId))
13631
+ return isElementVisibleInState(text.ownerId, elementsById);
13632
+ if (portsById.has(text.ownerId))
13633
+ return isPortVisibleInState(text.ownerId, portsById, elementsById);
13634
+ if (linksById.has(text.ownerId))
13635
+ return isLinkVisibleInState(text.ownerId, linksById, portsById, elementsById);
13636
+ return true;
13637
+ };
13333
13638
  var resolveStateWorldBounds = function (state) {
13334
13639
  var bounds = createBounds();
13640
+ var elementsById = new Map(state.elements.map(function (element) { return [element.id, element]; }));
13641
+ var portsById = new Map(state.ports.map(function (port) { return [port.id, port]; }));
13642
+ var linksById = new Map(state.links.map(function (link) { return [link.id, link]; }));
13335
13643
  state.elements.forEach(function (element) {
13644
+ if (!isElementVisibleInState(element.id, elementsById))
13645
+ return;
13336
13646
  includeRect(bounds, element.position.x, element.position.y, element.size.width, element.size.height);
13337
13647
  });
13338
13648
  state.ports.forEach(function (port) {
13339
13649
  var _a;
13650
+ if (!isPortVisibleInState(port.id, portsById, elementsById))
13651
+ return;
13340
13652
  var size = port.size;
13341
13653
  if (!size) {
13342
13654
  expandBounds(bounds, port.position.x, port.position.y);
@@ -13348,12 +13660,16 @@ var resolveStateWorldBounds = function (state) {
13348
13660
  includeRect(bounds, x, y, size.width, size.height);
13349
13661
  });
13350
13662
  state.links.forEach(function (link) {
13663
+ if (!isLinkVisibleInState(link.id, linksById, portsById, elementsById))
13664
+ return;
13351
13665
  link.points.forEach(function (point) {
13352
13666
  expandBounds(bounds, point.x, point.y);
13353
13667
  });
13354
13668
  });
13355
13669
  state.texts.forEach(function (text) {
13356
13670
  var _a;
13671
+ if (!isTextVisibleInState(text, elementsById, portsById, linksById))
13672
+ return;
13357
13673
  var offset = (_a = text.displayOffset) !== null && _a !== void 0 ? _a : { x: 0, y: 0 };
13358
13674
  var position = { x: text.position.x + offset.x, y: text.position.y + offset.y };
13359
13675
  var clipSize = text.displayClipSize;
@@ -13368,7 +13684,10 @@ var resolveStateWorldBounds = function (state) {
13368
13684
  };
13369
13685
  var resolveElementWorldBounds = function (state) {
13370
13686
  var bounds = createBounds();
13687
+ var elementsById = new Map(state.elements.map(function (element) { return [element.id, element]; }));
13371
13688
  state.elements.forEach(function (element) {
13689
+ if (!isElementVisibleInState(element.id, elementsById))
13690
+ return;
13372
13691
  includeRect(bounds, element.position.x, element.position.y, element.size.width, element.size.height);
13373
13692
  });
13374
13693
  return hasBounds(bounds) ? bounds : null;
@@ -16520,6 +16839,12 @@ var demoTabs = [
16520
16839
  description: selectionDemoConfig.description,
16521
16840
  Component: wrapSimpleDemo(selectionDemoConfig),
16522
16841
  },
16842
+ {
16843
+ id: elementVisibilitySelectionDemoConfig.id,
16844
+ title: elementVisibilitySelectionDemoConfig.title,
16845
+ description: elementVisibilitySelectionDemoConfig.description,
16846
+ Component: wrapSimpleDemo(elementVisibilitySelectionDemoConfig),
16847
+ },
16523
16848
  {
16524
16849
  id: eventHandlersDemoConfig.id,
16525
16850
  title: eventHandlersDemoConfig.title,