microboard-temp 0.13.19 → 0.13.21

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.
package/dist/cjs/node.js CHANGED
@@ -57079,6 +57079,7 @@ class ForceGraphEngine {
57079
57079
  tickTimer = null;
57080
57080
  syncTimer = null;
57081
57081
  lastSyncedPositions = new Map;
57082
+ activeComponents = new Map;
57082
57083
  TICK_MS = 33;
57083
57084
  SYNC_MS = 300;
57084
57085
  SOFTENING_SQ = 100 * 100;
@@ -57086,18 +57087,60 @@ class ForceGraphEngine {
57086
57087
  constructor(board) {
57087
57088
  this.board = board;
57088
57089
  }
57089
- start() {
57090
- if (this.tickTimer !== null)
57090
+ enableForGraph(startNodeId) {
57091
+ if (this.isNodeInActiveGraph(startNodeId))
57091
57092
  return;
57092
- for (const item of this.getNodes()) {
57093
- const pos = item.transformation.getTranslation();
57094
- this.lastSyncedPositions.set(item.getId(), { x: pos.x, y: pos.y });
57095
- this.velocities.set(item.getId(), { vx: 0, vy: 0 });
57093
+ const nodeIds = this.bfsComponent(startNodeId);
57094
+ const targetGap = this.calibrateTargetGap(nodeIds);
57095
+ this.activeComponents.set(startNodeId, { nodeIds, targetGap });
57096
+ for (const id of nodeIds) {
57097
+ if (!this.velocities.has(id)) {
57098
+ this.velocities.set(id, { vx: 0, vy: 0 });
57099
+ }
57100
+ const item = this.board.items.getById(id);
57101
+ if (item && !this.lastSyncedPositions.has(id)) {
57102
+ const pos = item.transformation.getTranslation();
57103
+ this.lastSyncedPositions.set(id, { x: pos.x, y: pos.y });
57104
+ }
57105
+ }
57106
+ this.ensureRunning();
57107
+ }
57108
+ disableForGraph(nodeId) {
57109
+ const compId = this.findComponentId(nodeId);
57110
+ if (!compId)
57111
+ return;
57112
+ this.activeComponents.delete(compId);
57113
+ if (this.activeComponents.size === 0) {
57114
+ this.stopTimers();
57115
+ }
57116
+ }
57117
+ isNodeInActiveGraph(nodeId) {
57118
+ return !!this.findComponentId(nodeId);
57119
+ }
57120
+ hasActiveComponents() {
57121
+ return this.activeComponents.size > 0;
57122
+ }
57123
+ wake() {
57124
+ if (this.activeComponents.size > 0 && this.tickTimer === null) {
57125
+ this.tickTimer = setInterval(() => this.tick(), this.TICK_MS);
57096
57126
  }
57097
- this.tickTimer = setInterval(() => this.tick(), this.TICK_MS);
57098
- this.syncTimer = setInterval(() => this.syncPositions(), this.SYNC_MS);
57099
57127
  }
57100
57128
  stop() {
57129
+ this.stopTimers();
57130
+ this.syncPositions();
57131
+ this.velocities.clear();
57132
+ this.lastSyncedPositions.clear();
57133
+ this.activeComponents.clear();
57134
+ }
57135
+ ensureRunning() {
57136
+ if (this.tickTimer === null) {
57137
+ this.tickTimer = setInterval(() => this.tick(), this.TICK_MS);
57138
+ }
57139
+ if (this.syncTimer === null) {
57140
+ this.syncTimer = setInterval(() => this.syncPositions(), this.SYNC_MS);
57141
+ }
57142
+ }
57143
+ stopTimers() {
57101
57144
  if (this.tickTimer !== null) {
57102
57145
  clearInterval(this.tickTimer);
57103
57146
  this.tickTimer = null;
@@ -57106,9 +57149,56 @@ class ForceGraphEngine {
57106
57149
  clearInterval(this.syncTimer);
57107
57150
  this.syncTimer = null;
57108
57151
  }
57109
- this.syncPositions();
57110
- this.velocities.clear();
57111
- this.lastSyncedPositions.clear();
57152
+ }
57153
+ findComponentId(nodeId) {
57154
+ for (const [compId, { nodeIds }] of this.activeComponents) {
57155
+ if (nodeIds.has(nodeId))
57156
+ return compId;
57157
+ }
57158
+ return;
57159
+ }
57160
+ bfsComponent(startNodeId) {
57161
+ const visited = new Set;
57162
+ const queue = [startNodeId];
57163
+ const connectors = this.getConnectors();
57164
+ while (queue.length > 0) {
57165
+ const nodeId = queue.shift();
57166
+ if (visited.has(nodeId))
57167
+ continue;
57168
+ visited.add(nodeId);
57169
+ for (const connector of connectors) {
57170
+ const { startItem, endItem } = connector.getConnectedItems();
57171
+ if (startItem?.getId() === nodeId && endItem && !visited.has(endItem.getId())) {
57172
+ queue.push(endItem.getId());
57173
+ }
57174
+ if (endItem?.getId() === nodeId && startItem && !visited.has(startItem.getId())) {
57175
+ queue.push(startItem.getId());
57176
+ }
57177
+ }
57178
+ }
57179
+ return visited;
57180
+ }
57181
+ calibrateTargetGap(nodeIds) {
57182
+ let totalMaxDim = 0;
57183
+ let count = 0;
57184
+ for (const id of nodeIds) {
57185
+ const item = this.board.items.getById(id);
57186
+ if (!item)
57187
+ continue;
57188
+ const mbr = item.getMbr();
57189
+ totalMaxDim += Math.max(mbr.getWidth(), mbr.getHeight());
57190
+ count++;
57191
+ }
57192
+ const avgMaxDim = count > 0 ? totalMaxDim / count : 100;
57193
+ return avgMaxDim * 0.3 + conf.FG_TARGET_GAP;
57194
+ }
57195
+ getActiveNodeIds() {
57196
+ const all6 = new Set;
57197
+ for (const { nodeIds } of this.activeComponents.values()) {
57198
+ for (const id of nodeIds)
57199
+ all6.add(id);
57200
+ }
57201
+ return all6;
57112
57202
  }
57113
57203
  getNodes() {
57114
57204
  return this.board.items.listAll().filter((item) => !EXCLUDED_TYPES.has(item.itemType) && !item.transformation.isLocked);
@@ -57118,8 +57208,10 @@ class ForceGraphEngine {
57118
57208
  }
57119
57209
  tick() {
57120
57210
  const dt = this.TICK_MS / 1000;
57121
- const nodes = this.getNodes();
57122
- if (nodes.length < 2)
57211
+ const activeIds = this.getActiveNodeIds();
57212
+ const allNodes = this.getNodes();
57213
+ const nodes = allNodes.filter((item) => activeIds.has(item.getId()));
57214
+ if (nodes.length < 1)
57123
57215
  return;
57124
57216
  const snapMap = new Map;
57125
57217
  for (const item of nodes) {
@@ -57160,7 +57252,9 @@ class ForceGraphEngine {
57160
57252
  const dx = s2.cx - s1.cx;
57161
57253
  const dy = s2.cy - s1.cy;
57162
57254
  const dist = Math.sqrt(dx * dx + dy * dy) + 0.001;
57163
- const targetDist = (Math.max(s1.w, s1.h) + Math.max(s2.w, s2.h)) * 0.5 + conf.FG_TARGET_GAP;
57255
+ const compId = this.findComponentId(s1.id);
57256
+ const targetGap = compId ? this.activeComponents.get(compId)?.targetGap ?? conf.FG_TARGET_GAP : conf.FG_TARGET_GAP;
57257
+ const targetDist = (Math.max(s1.w, s1.h) + Math.max(s2.w, s2.h)) * 0.5 + targetGap;
57164
57258
  const stretch = dist - targetDist;
57165
57259
  const forceMag = stretch * conf.FG_SPRING_K;
57166
57260
  const fx = dx / dist * forceMag;
@@ -57178,10 +57272,13 @@ class ForceGraphEngine {
57178
57272
  continue;
57179
57273
  const dx = s2.cx - s1.cx;
57180
57274
  const dy = s2.cy - s1.cy;
57181
- const distSq = dx * dx + dy * dy + this.SOFTENING_SQ;
57182
- const repMag = conf.FG_REPULSION / distSq;
57183
- const fx = dx * repMag;
57184
- const fy = dy * repMag;
57275
+ const centerDist = Math.sqrt(dx * dx + dy * dy) + 0.001;
57276
+ const r1 = Math.max(s1.w, s1.h) * 0.5;
57277
+ const r2 = Math.max(s2.w, s2.h) * 0.5;
57278
+ const edgeDist = Math.max(centerDist - r1 - r2, 1);
57279
+ const repMag = conf.FG_REPULSION / (edgeDist * edgeDist + this.SOFTENING_SQ);
57280
+ const fx = dx / centerDist * repMag;
57281
+ const fy = dy / centerDist * repMag;
57185
57282
  ax.set(s1.id, (ax.get(s1.id) ?? 0) - fx);
57186
57283
  ay.set(s1.id, (ay.get(s1.id) ?? 0) - fy);
57187
57284
  ax.set(s2.id, (ax.get(s2.id) ?? 0) + fx);
@@ -57218,7 +57315,8 @@ class ForceGraphEngine {
57218
57315
  }
57219
57316
  }
57220
57317
  syncPositions() {
57221
- const nodes = this.getNodes();
57318
+ const activeIds = this.getActiveNodeIds();
57319
+ const nodes = this.getNodes().filter((item) => activeIds.has(item.getId()));
57222
57320
  if (nodes.length === 0)
57223
57321
  return;
57224
57322
  const movedItems = nodes.map((item) => {
@@ -57242,11 +57340,6 @@ class ForceGraphEngine {
57242
57340
  };
57243
57341
  this.board.events.emit(operation);
57244
57342
  }
57245
- wake() {
57246
- if (this.tickTimer === null && this.syncTimer !== null) {
57247
- this.tickTimer = setInterval(() => this.tick(), this.TICK_MS);
57248
- }
57249
- }
57250
57343
  }
57251
57344
 
57252
57345
  // src/Board.ts
@@ -58322,20 +58415,22 @@ class Board {
58322
58415
  return this.gravity !== null;
58323
58416
  }
58324
58417
  forceGraph = null;
58325
- enableForceGraph() {
58326
- if (this.forceGraph)
58327
- return;
58328
- this.forceGraph = new ForceGraphEngine(this);
58329
- this.forceGraph.start();
58418
+ enableForceGraph(nodeId) {
58419
+ if (!this.forceGraph) {
58420
+ this.forceGraph = new ForceGraphEngine(this);
58421
+ }
58422
+ this.forceGraph.enableForGraph(nodeId);
58330
58423
  }
58331
- disableForceGraph() {
58424
+ disableForceGraph(nodeId) {
58332
58425
  if (!this.forceGraph)
58333
58426
  return;
58334
- this.forceGraph.stop();
58335
- this.forceGraph = null;
58427
+ this.forceGraph.disableForGraph(nodeId);
58428
+ if (!this.forceGraph.hasActiveComponents()) {
58429
+ this.forceGraph = null;
58430
+ }
58336
58431
  }
58337
- isForceGraphEnabled() {
58338
- return this.forceGraph !== null;
58432
+ isNodeInForceGraph(nodeId) {
58433
+ return this.forceGraph?.isNodeInActiveGraph(nodeId) ?? false;
58339
58434
  }
58340
58435
  wakeForceGraph() {
58341
58436
  this.forceGraph?.wake();
@@ -54435,6 +54435,7 @@ class ForceGraphEngine {
54435
54435
  tickTimer = null;
54436
54436
  syncTimer = null;
54437
54437
  lastSyncedPositions = new Map;
54438
+ activeComponents = new Map;
54438
54439
  TICK_MS = 33;
54439
54440
  SYNC_MS = 300;
54440
54441
  SOFTENING_SQ = 100 * 100;
@@ -54442,18 +54443,60 @@ class ForceGraphEngine {
54442
54443
  constructor(board) {
54443
54444
  this.board = board;
54444
54445
  }
54445
- start() {
54446
- if (this.tickTimer !== null)
54446
+ enableForGraph(startNodeId) {
54447
+ if (this.isNodeInActiveGraph(startNodeId))
54447
54448
  return;
54448
- for (const item of this.getNodes()) {
54449
- const pos = item.transformation.getTranslation();
54450
- this.lastSyncedPositions.set(item.getId(), { x: pos.x, y: pos.y });
54451
- this.velocities.set(item.getId(), { vx: 0, vy: 0 });
54449
+ const nodeIds = this.bfsComponent(startNodeId);
54450
+ const targetGap = this.calibrateTargetGap(nodeIds);
54451
+ this.activeComponents.set(startNodeId, { nodeIds, targetGap });
54452
+ for (const id of nodeIds) {
54453
+ if (!this.velocities.has(id)) {
54454
+ this.velocities.set(id, { vx: 0, vy: 0 });
54455
+ }
54456
+ const item = this.board.items.getById(id);
54457
+ if (item && !this.lastSyncedPositions.has(id)) {
54458
+ const pos = item.transformation.getTranslation();
54459
+ this.lastSyncedPositions.set(id, { x: pos.x, y: pos.y });
54460
+ }
54461
+ }
54462
+ this.ensureRunning();
54463
+ }
54464
+ disableForGraph(nodeId) {
54465
+ const compId = this.findComponentId(nodeId);
54466
+ if (!compId)
54467
+ return;
54468
+ this.activeComponents.delete(compId);
54469
+ if (this.activeComponents.size === 0) {
54470
+ this.stopTimers();
54471
+ }
54472
+ }
54473
+ isNodeInActiveGraph(nodeId) {
54474
+ return !!this.findComponentId(nodeId);
54475
+ }
54476
+ hasActiveComponents() {
54477
+ return this.activeComponents.size > 0;
54478
+ }
54479
+ wake() {
54480
+ if (this.activeComponents.size > 0 && this.tickTimer === null) {
54481
+ this.tickTimer = setInterval(() => this.tick(), this.TICK_MS);
54452
54482
  }
54453
- this.tickTimer = setInterval(() => this.tick(), this.TICK_MS);
54454
- this.syncTimer = setInterval(() => this.syncPositions(), this.SYNC_MS);
54455
54483
  }
54456
54484
  stop() {
54485
+ this.stopTimers();
54486
+ this.syncPositions();
54487
+ this.velocities.clear();
54488
+ this.lastSyncedPositions.clear();
54489
+ this.activeComponents.clear();
54490
+ }
54491
+ ensureRunning() {
54492
+ if (this.tickTimer === null) {
54493
+ this.tickTimer = setInterval(() => this.tick(), this.TICK_MS);
54494
+ }
54495
+ if (this.syncTimer === null) {
54496
+ this.syncTimer = setInterval(() => this.syncPositions(), this.SYNC_MS);
54497
+ }
54498
+ }
54499
+ stopTimers() {
54457
54500
  if (this.tickTimer !== null) {
54458
54501
  clearInterval(this.tickTimer);
54459
54502
  this.tickTimer = null;
@@ -54462,9 +54505,56 @@ class ForceGraphEngine {
54462
54505
  clearInterval(this.syncTimer);
54463
54506
  this.syncTimer = null;
54464
54507
  }
54465
- this.syncPositions();
54466
- this.velocities.clear();
54467
- this.lastSyncedPositions.clear();
54508
+ }
54509
+ findComponentId(nodeId) {
54510
+ for (const [compId, { nodeIds }] of this.activeComponents) {
54511
+ if (nodeIds.has(nodeId))
54512
+ return compId;
54513
+ }
54514
+ return;
54515
+ }
54516
+ bfsComponent(startNodeId) {
54517
+ const visited = new Set;
54518
+ const queue = [startNodeId];
54519
+ const connectors = this.getConnectors();
54520
+ while (queue.length > 0) {
54521
+ const nodeId = queue.shift();
54522
+ if (visited.has(nodeId))
54523
+ continue;
54524
+ visited.add(nodeId);
54525
+ for (const connector of connectors) {
54526
+ const { startItem, endItem } = connector.getConnectedItems();
54527
+ if (startItem?.getId() === nodeId && endItem && !visited.has(endItem.getId())) {
54528
+ queue.push(endItem.getId());
54529
+ }
54530
+ if (endItem?.getId() === nodeId && startItem && !visited.has(startItem.getId())) {
54531
+ queue.push(startItem.getId());
54532
+ }
54533
+ }
54534
+ }
54535
+ return visited;
54536
+ }
54537
+ calibrateTargetGap(nodeIds) {
54538
+ let totalMaxDim = 0;
54539
+ let count = 0;
54540
+ for (const id of nodeIds) {
54541
+ const item = this.board.items.getById(id);
54542
+ if (!item)
54543
+ continue;
54544
+ const mbr = item.getMbr();
54545
+ totalMaxDim += Math.max(mbr.getWidth(), mbr.getHeight());
54546
+ count++;
54547
+ }
54548
+ const avgMaxDim = count > 0 ? totalMaxDim / count : 100;
54549
+ return avgMaxDim * 0.3 + conf.FG_TARGET_GAP;
54550
+ }
54551
+ getActiveNodeIds() {
54552
+ const all6 = new Set;
54553
+ for (const { nodeIds } of this.activeComponents.values()) {
54554
+ for (const id of nodeIds)
54555
+ all6.add(id);
54556
+ }
54557
+ return all6;
54468
54558
  }
54469
54559
  getNodes() {
54470
54560
  return this.board.items.listAll().filter((item) => !EXCLUDED_TYPES.has(item.itemType) && !item.transformation.isLocked);
@@ -54474,8 +54564,10 @@ class ForceGraphEngine {
54474
54564
  }
54475
54565
  tick() {
54476
54566
  const dt = this.TICK_MS / 1000;
54477
- const nodes = this.getNodes();
54478
- if (nodes.length < 2)
54567
+ const activeIds = this.getActiveNodeIds();
54568
+ const allNodes = this.getNodes();
54569
+ const nodes = allNodes.filter((item) => activeIds.has(item.getId()));
54570
+ if (nodes.length < 1)
54479
54571
  return;
54480
54572
  const snapMap = new Map;
54481
54573
  for (const item of nodes) {
@@ -54516,7 +54608,9 @@ class ForceGraphEngine {
54516
54608
  const dx = s2.cx - s1.cx;
54517
54609
  const dy = s2.cy - s1.cy;
54518
54610
  const dist = Math.sqrt(dx * dx + dy * dy) + 0.001;
54519
- const targetDist = (Math.max(s1.w, s1.h) + Math.max(s2.w, s2.h)) * 0.5 + conf.FG_TARGET_GAP;
54611
+ const compId = this.findComponentId(s1.id);
54612
+ const targetGap = compId ? this.activeComponents.get(compId)?.targetGap ?? conf.FG_TARGET_GAP : conf.FG_TARGET_GAP;
54613
+ const targetDist = (Math.max(s1.w, s1.h) + Math.max(s2.w, s2.h)) * 0.5 + targetGap;
54520
54614
  const stretch = dist - targetDist;
54521
54615
  const forceMag = stretch * conf.FG_SPRING_K;
54522
54616
  const fx = dx / dist * forceMag;
@@ -54534,10 +54628,13 @@ class ForceGraphEngine {
54534
54628
  continue;
54535
54629
  const dx = s2.cx - s1.cx;
54536
54630
  const dy = s2.cy - s1.cy;
54537
- const distSq = dx * dx + dy * dy + this.SOFTENING_SQ;
54538
- const repMag = conf.FG_REPULSION / distSq;
54539
- const fx = dx * repMag;
54540
- const fy = dy * repMag;
54631
+ const centerDist = Math.sqrt(dx * dx + dy * dy) + 0.001;
54632
+ const r1 = Math.max(s1.w, s1.h) * 0.5;
54633
+ const r2 = Math.max(s2.w, s2.h) * 0.5;
54634
+ const edgeDist = Math.max(centerDist - r1 - r2, 1);
54635
+ const repMag = conf.FG_REPULSION / (edgeDist * edgeDist + this.SOFTENING_SQ);
54636
+ const fx = dx / centerDist * repMag;
54637
+ const fy = dy / centerDist * repMag;
54541
54638
  ax.set(s1.id, (ax.get(s1.id) ?? 0) - fx);
54542
54639
  ay.set(s1.id, (ay.get(s1.id) ?? 0) - fy);
54543
54640
  ax.set(s2.id, (ax.get(s2.id) ?? 0) + fx);
@@ -54574,7 +54671,8 @@ class ForceGraphEngine {
54574
54671
  }
54575
54672
  }
54576
54673
  syncPositions() {
54577
- const nodes = this.getNodes();
54674
+ const activeIds = this.getActiveNodeIds();
54675
+ const nodes = this.getNodes().filter((item) => activeIds.has(item.getId()));
54578
54676
  if (nodes.length === 0)
54579
54677
  return;
54580
54678
  const movedItems = nodes.map((item) => {
@@ -54598,11 +54696,6 @@ class ForceGraphEngine {
54598
54696
  };
54599
54697
  this.board.events.emit(operation);
54600
54698
  }
54601
- wake() {
54602
- if (this.tickTimer === null && this.syncTimer !== null) {
54603
- this.tickTimer = setInterval(() => this.tick(), this.TICK_MS);
54604
- }
54605
- }
54606
54699
  }
54607
54700
 
54608
54701
  // src/Board.ts
@@ -55678,20 +55771,22 @@ class Board {
55678
55771
  return this.gravity !== null;
55679
55772
  }
55680
55773
  forceGraph = null;
55681
- enableForceGraph() {
55682
- if (this.forceGraph)
55683
- return;
55684
- this.forceGraph = new ForceGraphEngine(this);
55685
- this.forceGraph.start();
55774
+ enableForceGraph(nodeId) {
55775
+ if (!this.forceGraph) {
55776
+ this.forceGraph = new ForceGraphEngine(this);
55777
+ }
55778
+ this.forceGraph.enableForGraph(nodeId);
55686
55779
  }
55687
- disableForceGraph() {
55780
+ disableForceGraph(nodeId) {
55688
55781
  if (!this.forceGraph)
55689
55782
  return;
55690
- this.forceGraph.stop();
55691
- this.forceGraph = null;
55783
+ this.forceGraph.disableForGraph(nodeId);
55784
+ if (!this.forceGraph.hasActiveComponents()) {
55785
+ this.forceGraph = null;
55786
+ }
55692
55787
  }
55693
- isForceGraphEnabled() {
55694
- return this.forceGraph !== null;
55788
+ isNodeInForceGraph(nodeId) {
55789
+ return this.forceGraph?.isNodeInActiveGraph(nodeId) ?? false;
55695
55790
  }
55696
55791
  wakeForceGraph() {
55697
55792
  this.forceGraph?.wake();