microboard-temp 0.12.4 → 0.12.6

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.
@@ -21809,6 +21809,7 @@ class BaseItem extends Mbr {
21809
21809
  updateChildrenIds() {
21810
21810
  this.children = this.index?.items.listAll().map((item) => item.getId()) || [];
21811
21811
  }
21812
+ onParentChanged(_newParent) {}
21812
21813
  getId() {
21813
21814
  return this.id;
21814
21815
  }
@@ -21944,6 +21945,7 @@ class BaseItem extends Mbr {
21944
21945
  const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerNestingMatrix);
21945
21946
  this.board.items.index.remove(foundItem);
21946
21947
  foundItem.parent = this.getId();
21948
+ foundItem.onParentChanged(this.getId());
21947
21949
  foundItem.transformation.setLocalMatrix(localMatrix);
21948
21950
  this.index?.insert(foundItem);
21949
21951
  }
@@ -21965,6 +21967,7 @@ class BaseItem extends Mbr {
21965
21967
  const worldMatrix = foundItem.transformation.toMatrix().composeWith(containerNestingMatrix);
21966
21968
  this.index?.remove(foundItem);
21967
21969
  foundItem.parent = "Board";
21970
+ foundItem.onParentChanged("Board");
21968
21971
  foundItem.transformation.setLocalMatrix(worldMatrix);
21969
21972
  this.board.items.index.insert(foundItem);
21970
21973
  }
@@ -22437,7 +22440,7 @@ class RichText extends BaseItem {
22437
22440
  height,
22438
22441
  maxWidth: maxWidth ? maxWidth + 1 : undefined,
22439
22442
  maxHeight,
22440
- textScale: this.getScale()
22443
+ textScale: this.isInShape && !this.autoSize ? 1 : this.getScale()
22441
22444
  };
22442
22445
  }
22443
22446
  transformCanvas() {
@@ -54310,7 +54313,7 @@ class GravityEngine {
54310
54313
  G = 80;
54311
54314
  G_CENTER = 120;
54312
54315
  DAMPING = 0.92;
54313
- REPULSION = 60000;
54316
+ REPULSION = 800;
54314
54317
  TICK_MS = 33;
54315
54318
  SYNC_MS = 300;
54316
54319
  MAX_DISTANCE = 3000;
@@ -54345,13 +54348,18 @@ class GravityEngine {
54345
54348
  const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
54346
54349
  if (items.length < 1)
54347
54350
  return;
54348
- const snapshot = items.map((item) => {
54351
+ const snap = items.map((item, idx) => {
54349
54352
  const pos = item.transformation.getTranslation();
54350
54353
  const mbr = item.getMbr();
54351
54354
  const w = Math.max(mbr.getWidth(), 1);
54352
54355
  const h2 = Math.max(mbr.getHeight(), 1);
54353
54356
  return {
54357
+ idx,
54354
54358
  id: item.getId(),
54359
+ left: pos.x,
54360
+ top: pos.y,
54361
+ right: pos.x + w,
54362
+ bottom: pos.y + h2,
54355
54363
  cx: pos.x + w * 0.5,
54356
54364
  cy: pos.y + h2 * 0.5,
54357
54365
  w,
@@ -54359,16 +54367,15 @@ class GravityEngine {
54359
54367
  mass: w * h2
54360
54368
  };
54361
54369
  });
54362
- let sumX = 0;
54363
- let sumY = 0;
54364
- for (const s2 of snapshot) {
54370
+ let sumX = 0, sumY = 0;
54371
+ for (const s2 of snap) {
54365
54372
  sumX += s2.cx;
54366
54373
  sumY += s2.cy;
54367
54374
  }
54368
- const centerX = sumX / snapshot.length;
54369
- const centerY = sumY / snapshot.length;
54370
- for (let i = 0;i < snapshot.length; i++) {
54371
- const s1 = snapshot[i];
54375
+ const centerX = sumX / snap.length;
54376
+ const centerY = sumY / snap.length;
54377
+ for (let i = 0;i < snap.length; i++) {
54378
+ const s1 = snap[i];
54372
54379
  if (!this.velocities.has(s1.id)) {
54373
54380
  this.velocities.set(s1.id, { vx: 0, vy: 0 });
54374
54381
  }
@@ -54380,22 +54387,28 @@ class GravityEngine {
54380
54387
  const distCenter = Math.sqrt(dcx * dcx + dcy * dcy) + 1;
54381
54388
  ax += this.G_CENTER * dcx / distCenter;
54382
54389
  ay += this.G_CENTER * dcy / distCenter;
54383
- for (let j = 0;j < snapshot.length; j++) {
54390
+ for (let j = 0;j < snap.length; j++) {
54384
54391
  if (i === j)
54385
54392
  continue;
54386
- const s2 = snapshot[j];
54393
+ const s2 = snap[j];
54387
54394
  const dx = s2.cx - s1.cx;
54388
54395
  const dy = s2.cy - s1.cy;
54389
- const distSq = dx * dx + dy * dy;
54390
- const dist = Math.sqrt(distSq) + 0.001;
54396
+ const dist = Math.sqrt(dx * dx + dy * dy) + 0.001;
54391
54397
  if (dist > this.MAX_DISTANCE)
54392
54398
  continue;
54393
- const minDist = (s1.w + s2.w + s1.h + s2.h) * 0.25;
54394
- if (dist < minDist) {
54395
- const repAcc = this.REPULSION / (distSq + this.SOFTENING_SQ);
54396
- ax -= repAcc * dx / dist;
54397
- ay -= repAcc * dy / dist;
54399
+ const overlapping = s1.right > s2.left && s2.right > s1.left && s1.bottom > s2.top && s2.bottom > s1.top;
54400
+ if (overlapping) {
54401
+ const overlapX = Math.min(s1.right, s2.right) - Math.max(s1.left, s2.left);
54402
+ const overlapY = Math.min(s1.bottom, s2.bottom) - Math.max(s1.top, s2.top);
54403
+ if (overlapX < overlapY) {
54404
+ const sign = s1.cx < s2.cx ? -1 : 1;
54405
+ ax += sign * this.REPULSION * overlapX;
54406
+ } else {
54407
+ const sign = s1.cy < s2.cy ? -1 : 1;
54408
+ ay += sign * this.REPULSION * overlapY;
54409
+ }
54398
54410
  } else {
54411
+ const distSq = dx * dx + dy * dy;
54399
54412
  const gravAcc = this.G * s2.mass / (distSq + this.SOFTENING_SQ);
54400
54413
  ax += gravAcc * dx / dist;
54401
54414
  ay += gravAcc * dy / dist;
@@ -54437,14 +54450,7 @@ class GravityEngine {
54437
54450
  method: "applyMatrix",
54438
54451
  items: movedItems.map(({ id, dx, dy }) => ({
54439
54452
  id,
54440
- matrix: {
54441
- translateX: dx,
54442
- translateY: dy,
54443
- scaleX: 1,
54444
- scaleY: 1,
54445
- shearX: 0,
54446
- shearY: 0
54447
- }
54453
+ matrix: { translateX: dx, translateY: dy, scaleX: 1, scaleY: 1, shearX: 0, shearY: 0 }
54448
54454
  }))
54449
54455
  };
54450
54456
  this.board.events.emit(operation);
package/dist/cjs/index.js CHANGED
@@ -21809,6 +21809,7 @@ class BaseItem extends Mbr {
21809
21809
  updateChildrenIds() {
21810
21810
  this.children = this.index?.items.listAll().map((item) => item.getId()) || [];
21811
21811
  }
21812
+ onParentChanged(_newParent) {}
21812
21813
  getId() {
21813
21814
  return this.id;
21814
21815
  }
@@ -21944,6 +21945,7 @@ class BaseItem extends Mbr {
21944
21945
  const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerNestingMatrix);
21945
21946
  this.board.items.index.remove(foundItem);
21946
21947
  foundItem.parent = this.getId();
21948
+ foundItem.onParentChanged(this.getId());
21947
21949
  foundItem.transformation.setLocalMatrix(localMatrix);
21948
21950
  this.index?.insert(foundItem);
21949
21951
  }
@@ -21965,6 +21967,7 @@ class BaseItem extends Mbr {
21965
21967
  const worldMatrix = foundItem.transformation.toMatrix().composeWith(containerNestingMatrix);
21966
21968
  this.index?.remove(foundItem);
21967
21969
  foundItem.parent = "Board";
21970
+ foundItem.onParentChanged("Board");
21968
21971
  foundItem.transformation.setLocalMatrix(worldMatrix);
21969
21972
  this.board.items.index.insert(foundItem);
21970
21973
  }
@@ -22437,7 +22440,7 @@ class RichText extends BaseItem {
22437
22440
  height,
22438
22441
  maxWidth: maxWidth ? maxWidth + 1 : undefined,
22439
22442
  maxHeight,
22440
- textScale: this.getScale()
22443
+ textScale: this.isInShape && !this.autoSize ? 1 : this.getScale()
22441
22444
  };
22442
22445
  }
22443
22446
  transformCanvas() {
@@ -54310,7 +54313,7 @@ class GravityEngine {
54310
54313
  G = 80;
54311
54314
  G_CENTER = 120;
54312
54315
  DAMPING = 0.92;
54313
- REPULSION = 60000;
54316
+ REPULSION = 800;
54314
54317
  TICK_MS = 33;
54315
54318
  SYNC_MS = 300;
54316
54319
  MAX_DISTANCE = 3000;
@@ -54345,13 +54348,18 @@ class GravityEngine {
54345
54348
  const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
54346
54349
  if (items.length < 1)
54347
54350
  return;
54348
- const snapshot = items.map((item) => {
54351
+ const snap = items.map((item, idx) => {
54349
54352
  const pos = item.transformation.getTranslation();
54350
54353
  const mbr = item.getMbr();
54351
54354
  const w = Math.max(mbr.getWidth(), 1);
54352
54355
  const h2 = Math.max(mbr.getHeight(), 1);
54353
54356
  return {
54357
+ idx,
54354
54358
  id: item.getId(),
54359
+ left: pos.x,
54360
+ top: pos.y,
54361
+ right: pos.x + w,
54362
+ bottom: pos.y + h2,
54355
54363
  cx: pos.x + w * 0.5,
54356
54364
  cy: pos.y + h2 * 0.5,
54357
54365
  w,
@@ -54359,16 +54367,15 @@ class GravityEngine {
54359
54367
  mass: w * h2
54360
54368
  };
54361
54369
  });
54362
- let sumX = 0;
54363
- let sumY = 0;
54364
- for (const s2 of snapshot) {
54370
+ let sumX = 0, sumY = 0;
54371
+ for (const s2 of snap) {
54365
54372
  sumX += s2.cx;
54366
54373
  sumY += s2.cy;
54367
54374
  }
54368
- const centerX = sumX / snapshot.length;
54369
- const centerY = sumY / snapshot.length;
54370
- for (let i = 0;i < snapshot.length; i++) {
54371
- const s1 = snapshot[i];
54375
+ const centerX = sumX / snap.length;
54376
+ const centerY = sumY / snap.length;
54377
+ for (let i = 0;i < snap.length; i++) {
54378
+ const s1 = snap[i];
54372
54379
  if (!this.velocities.has(s1.id)) {
54373
54380
  this.velocities.set(s1.id, { vx: 0, vy: 0 });
54374
54381
  }
@@ -54380,22 +54387,28 @@ class GravityEngine {
54380
54387
  const distCenter = Math.sqrt(dcx * dcx + dcy * dcy) + 1;
54381
54388
  ax += this.G_CENTER * dcx / distCenter;
54382
54389
  ay += this.G_CENTER * dcy / distCenter;
54383
- for (let j = 0;j < snapshot.length; j++) {
54390
+ for (let j = 0;j < snap.length; j++) {
54384
54391
  if (i === j)
54385
54392
  continue;
54386
- const s2 = snapshot[j];
54393
+ const s2 = snap[j];
54387
54394
  const dx = s2.cx - s1.cx;
54388
54395
  const dy = s2.cy - s1.cy;
54389
- const distSq = dx * dx + dy * dy;
54390
- const dist = Math.sqrt(distSq) + 0.001;
54396
+ const dist = Math.sqrt(dx * dx + dy * dy) + 0.001;
54391
54397
  if (dist > this.MAX_DISTANCE)
54392
54398
  continue;
54393
- const minDist = (s1.w + s2.w + s1.h + s2.h) * 0.25;
54394
- if (dist < minDist) {
54395
- const repAcc = this.REPULSION / (distSq + this.SOFTENING_SQ);
54396
- ax -= repAcc * dx / dist;
54397
- ay -= repAcc * dy / dist;
54399
+ const overlapping = s1.right > s2.left && s2.right > s1.left && s1.bottom > s2.top && s2.bottom > s1.top;
54400
+ if (overlapping) {
54401
+ const overlapX = Math.min(s1.right, s2.right) - Math.max(s1.left, s2.left);
54402
+ const overlapY = Math.min(s1.bottom, s2.bottom) - Math.max(s1.top, s2.top);
54403
+ if (overlapX < overlapY) {
54404
+ const sign = s1.cx < s2.cx ? -1 : 1;
54405
+ ax += sign * this.REPULSION * overlapX;
54406
+ } else {
54407
+ const sign = s1.cy < s2.cy ? -1 : 1;
54408
+ ay += sign * this.REPULSION * overlapY;
54409
+ }
54398
54410
  } else {
54411
+ const distSq = dx * dx + dy * dy;
54399
54412
  const gravAcc = this.G * s2.mass / (distSq + this.SOFTENING_SQ);
54400
54413
  ax += gravAcc * dx / dist;
54401
54414
  ay += gravAcc * dy / dist;
@@ -54437,14 +54450,7 @@ class GravityEngine {
54437
54450
  method: "applyMatrix",
54438
54451
  items: movedItems.map(({ id, dx, dy }) => ({
54439
54452
  id,
54440
- matrix: {
54441
- translateX: dx,
54442
- translateY: dy,
54443
- scaleX: 1,
54444
- scaleY: 1,
54445
- shearX: 0,
54446
- shearY: 0
54447
- }
54453
+ matrix: { translateX: dx, translateY: dy, scaleX: 1, scaleY: 1, shearX: 0, shearY: 0 }
54448
54454
  }))
54449
54455
  };
54450
54456
  this.board.events.emit(operation);
package/dist/cjs/node.js CHANGED
@@ -24281,6 +24281,7 @@ class BaseItem extends Mbr {
24281
24281
  updateChildrenIds() {
24282
24282
  this.children = this.index?.items.listAll().map((item) => item.getId()) || [];
24283
24283
  }
24284
+ onParentChanged(_newParent) {}
24284
24285
  getId() {
24285
24286
  return this.id;
24286
24287
  }
@@ -24416,6 +24417,7 @@ class BaseItem extends Mbr {
24416
24417
  const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerNestingMatrix);
24417
24418
  this.board.items.index.remove(foundItem);
24418
24419
  foundItem.parent = this.getId();
24420
+ foundItem.onParentChanged(this.getId());
24419
24421
  foundItem.transformation.setLocalMatrix(localMatrix);
24420
24422
  this.index?.insert(foundItem);
24421
24423
  }
@@ -24437,6 +24439,7 @@ class BaseItem extends Mbr {
24437
24439
  const worldMatrix = foundItem.transformation.toMatrix().composeWith(containerNestingMatrix);
24438
24440
  this.index?.remove(foundItem);
24439
24441
  foundItem.parent = "Board";
24442
+ foundItem.onParentChanged("Board");
24440
24443
  foundItem.transformation.setLocalMatrix(worldMatrix);
24441
24444
  this.board.items.index.insert(foundItem);
24442
24445
  }
@@ -24909,7 +24912,7 @@ class RichText extends BaseItem {
24909
24912
  height,
24910
24913
  maxWidth: maxWidth ? maxWidth + 1 : undefined,
24911
24914
  maxHeight,
24912
- textScale: this.getScale()
24915
+ textScale: this.isInShape && !this.autoSize ? 1 : this.getScale()
24913
24916
  };
24914
24917
  }
24915
24918
  transformCanvas() {
@@ -56783,7 +56786,7 @@ class GravityEngine {
56783
56786
  G = 80;
56784
56787
  G_CENTER = 120;
56785
56788
  DAMPING = 0.92;
56786
- REPULSION = 60000;
56789
+ REPULSION = 800;
56787
56790
  TICK_MS = 33;
56788
56791
  SYNC_MS = 300;
56789
56792
  MAX_DISTANCE = 3000;
@@ -56818,13 +56821,18 @@ class GravityEngine {
56818
56821
  const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
56819
56822
  if (items.length < 1)
56820
56823
  return;
56821
- const snapshot = items.map((item) => {
56824
+ const snap = items.map((item, idx) => {
56822
56825
  const pos = item.transformation.getTranslation();
56823
56826
  const mbr = item.getMbr();
56824
56827
  const w = Math.max(mbr.getWidth(), 1);
56825
56828
  const h2 = Math.max(mbr.getHeight(), 1);
56826
56829
  return {
56830
+ idx,
56827
56831
  id: item.getId(),
56832
+ left: pos.x,
56833
+ top: pos.y,
56834
+ right: pos.x + w,
56835
+ bottom: pos.y + h2,
56828
56836
  cx: pos.x + w * 0.5,
56829
56837
  cy: pos.y + h2 * 0.5,
56830
56838
  w,
@@ -56832,16 +56840,15 @@ class GravityEngine {
56832
56840
  mass: w * h2
56833
56841
  };
56834
56842
  });
56835
- let sumX = 0;
56836
- let sumY = 0;
56837
- for (const s2 of snapshot) {
56843
+ let sumX = 0, sumY = 0;
56844
+ for (const s2 of snap) {
56838
56845
  sumX += s2.cx;
56839
56846
  sumY += s2.cy;
56840
56847
  }
56841
- const centerX = sumX / snapshot.length;
56842
- const centerY = sumY / snapshot.length;
56843
- for (let i = 0;i < snapshot.length; i++) {
56844
- const s1 = snapshot[i];
56848
+ const centerX = sumX / snap.length;
56849
+ const centerY = sumY / snap.length;
56850
+ for (let i = 0;i < snap.length; i++) {
56851
+ const s1 = snap[i];
56845
56852
  if (!this.velocities.has(s1.id)) {
56846
56853
  this.velocities.set(s1.id, { vx: 0, vy: 0 });
56847
56854
  }
@@ -56853,22 +56860,28 @@ class GravityEngine {
56853
56860
  const distCenter = Math.sqrt(dcx * dcx + dcy * dcy) + 1;
56854
56861
  ax += this.G_CENTER * dcx / distCenter;
56855
56862
  ay += this.G_CENTER * dcy / distCenter;
56856
- for (let j = 0;j < snapshot.length; j++) {
56863
+ for (let j = 0;j < snap.length; j++) {
56857
56864
  if (i === j)
56858
56865
  continue;
56859
- const s2 = snapshot[j];
56866
+ const s2 = snap[j];
56860
56867
  const dx = s2.cx - s1.cx;
56861
56868
  const dy = s2.cy - s1.cy;
56862
- const distSq = dx * dx + dy * dy;
56863
- const dist = Math.sqrt(distSq) + 0.001;
56869
+ const dist = Math.sqrt(dx * dx + dy * dy) + 0.001;
56864
56870
  if (dist > this.MAX_DISTANCE)
56865
56871
  continue;
56866
- const minDist = (s1.w + s2.w + s1.h + s2.h) * 0.25;
56867
- if (dist < minDist) {
56868
- const repAcc = this.REPULSION / (distSq + this.SOFTENING_SQ);
56869
- ax -= repAcc * dx / dist;
56870
- ay -= repAcc * dy / dist;
56872
+ const overlapping = s1.right > s2.left && s2.right > s1.left && s1.bottom > s2.top && s2.bottom > s1.top;
56873
+ if (overlapping) {
56874
+ const overlapX = Math.min(s1.right, s2.right) - Math.max(s1.left, s2.left);
56875
+ const overlapY = Math.min(s1.bottom, s2.bottom) - Math.max(s1.top, s2.top);
56876
+ if (overlapX < overlapY) {
56877
+ const sign = s1.cx < s2.cx ? -1 : 1;
56878
+ ax += sign * this.REPULSION * overlapX;
56879
+ } else {
56880
+ const sign = s1.cy < s2.cy ? -1 : 1;
56881
+ ay += sign * this.REPULSION * overlapY;
56882
+ }
56871
56883
  } else {
56884
+ const distSq = dx * dx + dy * dy;
56872
56885
  const gravAcc = this.G * s2.mass / (distSq + this.SOFTENING_SQ);
56873
56886
  ax += gravAcc * dx / dist;
56874
56887
  ay += gravAcc * dy / dist;
@@ -56910,14 +56923,7 @@ class GravityEngine {
56910
56923
  method: "applyMatrix",
56911
56924
  items: movedItems.map(({ id, dx, dy }) => ({
56912
56925
  id,
56913
- matrix: {
56914
- translateX: dx,
56915
- translateY: dy,
56916
- scaleX: 1,
56917
- scaleY: 1,
56918
- shearX: 0,
56919
- shearY: 0
56920
- }
56926
+ matrix: { translateX: dx, translateY: dy, scaleX: 1, scaleY: 1, shearX: 0, shearY: 0 }
56921
56927
  }))
56922
56928
  };
56923
56929
  this.board.events.emit(operation);
@@ -21638,6 +21638,7 @@ class BaseItem extends Mbr {
21638
21638
  updateChildrenIds() {
21639
21639
  this.children = this.index?.items.listAll().map((item) => item.getId()) || [];
21640
21640
  }
21641
+ onParentChanged(_newParent) {}
21641
21642
  getId() {
21642
21643
  return this.id;
21643
21644
  }
@@ -21773,6 +21774,7 @@ class BaseItem extends Mbr {
21773
21774
  const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerNestingMatrix);
21774
21775
  this.board.items.index.remove(foundItem);
21775
21776
  foundItem.parent = this.getId();
21777
+ foundItem.onParentChanged(this.getId());
21776
21778
  foundItem.transformation.setLocalMatrix(localMatrix);
21777
21779
  this.index?.insert(foundItem);
21778
21780
  }
@@ -21794,6 +21796,7 @@ class BaseItem extends Mbr {
21794
21796
  const worldMatrix = foundItem.transformation.toMatrix().composeWith(containerNestingMatrix);
21795
21797
  this.index?.remove(foundItem);
21796
21798
  foundItem.parent = "Board";
21799
+ foundItem.onParentChanged("Board");
21797
21800
  foundItem.transformation.setLocalMatrix(worldMatrix);
21798
21801
  this.board.items.index.insert(foundItem);
21799
21802
  }
@@ -22266,7 +22269,7 @@ class RichText extends BaseItem {
22266
22269
  height,
22267
22270
  maxWidth: maxWidth ? maxWidth + 1 : undefined,
22268
22271
  maxHeight,
22269
- textScale: this.getScale()
22272
+ textScale: this.isInShape && !this.autoSize ? 1 : this.getScale()
22270
22273
  };
22271
22274
  }
22272
22275
  transformCanvas() {
@@ -54139,7 +54142,7 @@ class GravityEngine {
54139
54142
  G = 80;
54140
54143
  G_CENTER = 120;
54141
54144
  DAMPING = 0.92;
54142
- REPULSION = 60000;
54145
+ REPULSION = 800;
54143
54146
  TICK_MS = 33;
54144
54147
  SYNC_MS = 300;
54145
54148
  MAX_DISTANCE = 3000;
@@ -54174,13 +54177,18 @@ class GravityEngine {
54174
54177
  const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
54175
54178
  if (items.length < 1)
54176
54179
  return;
54177
- const snapshot = items.map((item) => {
54180
+ const snap = items.map((item, idx) => {
54178
54181
  const pos = item.transformation.getTranslation();
54179
54182
  const mbr = item.getMbr();
54180
54183
  const w = Math.max(mbr.getWidth(), 1);
54181
54184
  const h2 = Math.max(mbr.getHeight(), 1);
54182
54185
  return {
54186
+ idx,
54183
54187
  id: item.getId(),
54188
+ left: pos.x,
54189
+ top: pos.y,
54190
+ right: pos.x + w,
54191
+ bottom: pos.y + h2,
54184
54192
  cx: pos.x + w * 0.5,
54185
54193
  cy: pos.y + h2 * 0.5,
54186
54194
  w,
@@ -54188,16 +54196,15 @@ class GravityEngine {
54188
54196
  mass: w * h2
54189
54197
  };
54190
54198
  });
54191
- let sumX = 0;
54192
- let sumY = 0;
54193
- for (const s2 of snapshot) {
54199
+ let sumX = 0, sumY = 0;
54200
+ for (const s2 of snap) {
54194
54201
  sumX += s2.cx;
54195
54202
  sumY += s2.cy;
54196
54203
  }
54197
- const centerX = sumX / snapshot.length;
54198
- const centerY = sumY / snapshot.length;
54199
- for (let i = 0;i < snapshot.length; i++) {
54200
- const s1 = snapshot[i];
54204
+ const centerX = sumX / snap.length;
54205
+ const centerY = sumY / snap.length;
54206
+ for (let i = 0;i < snap.length; i++) {
54207
+ const s1 = snap[i];
54201
54208
  if (!this.velocities.has(s1.id)) {
54202
54209
  this.velocities.set(s1.id, { vx: 0, vy: 0 });
54203
54210
  }
@@ -54209,22 +54216,28 @@ class GravityEngine {
54209
54216
  const distCenter = Math.sqrt(dcx * dcx + dcy * dcy) + 1;
54210
54217
  ax += this.G_CENTER * dcx / distCenter;
54211
54218
  ay += this.G_CENTER * dcy / distCenter;
54212
- for (let j = 0;j < snapshot.length; j++) {
54219
+ for (let j = 0;j < snap.length; j++) {
54213
54220
  if (i === j)
54214
54221
  continue;
54215
- const s2 = snapshot[j];
54222
+ const s2 = snap[j];
54216
54223
  const dx = s2.cx - s1.cx;
54217
54224
  const dy = s2.cy - s1.cy;
54218
- const distSq = dx * dx + dy * dy;
54219
- const dist = Math.sqrt(distSq) + 0.001;
54225
+ const dist = Math.sqrt(dx * dx + dy * dy) + 0.001;
54220
54226
  if (dist > this.MAX_DISTANCE)
54221
54227
  continue;
54222
- const minDist = (s1.w + s2.w + s1.h + s2.h) * 0.25;
54223
- if (dist < minDist) {
54224
- const repAcc = this.REPULSION / (distSq + this.SOFTENING_SQ);
54225
- ax -= repAcc * dx / dist;
54226
- ay -= repAcc * dy / dist;
54228
+ const overlapping = s1.right > s2.left && s2.right > s1.left && s1.bottom > s2.top && s2.bottom > s1.top;
54229
+ if (overlapping) {
54230
+ const overlapX = Math.min(s1.right, s2.right) - Math.max(s1.left, s2.left);
54231
+ const overlapY = Math.min(s1.bottom, s2.bottom) - Math.max(s1.top, s2.top);
54232
+ if (overlapX < overlapY) {
54233
+ const sign = s1.cx < s2.cx ? -1 : 1;
54234
+ ax += sign * this.REPULSION * overlapX;
54235
+ } else {
54236
+ const sign = s1.cy < s2.cy ? -1 : 1;
54237
+ ay += sign * this.REPULSION * overlapY;
54238
+ }
54227
54239
  } else {
54240
+ const distSq = dx * dx + dy * dy;
54228
54241
  const gravAcc = this.G * s2.mass / (distSq + this.SOFTENING_SQ);
54229
54242
  ax += gravAcc * dx / dist;
54230
54243
  ay += gravAcc * dy / dist;
@@ -54266,14 +54279,7 @@ class GravityEngine {
54266
54279
  method: "applyMatrix",
54267
54280
  items: movedItems.map(({ id, dx, dy }) => ({
54268
54281
  id,
54269
- matrix: {
54270
- translateX: dx,
54271
- translateY: dy,
54272
- scaleX: 1,
54273
- scaleY: 1,
54274
- shearX: 0,
54275
- shearY: 0
54276
- }
54282
+ matrix: { translateX: dx, translateY: dy, scaleX: 1, scaleY: 1, shearX: 0, shearY: 0 }
54277
54283
  }))
54278
54284
  };
54279
54285
  this.board.events.emit(operation);
package/dist/esm/index.js CHANGED
@@ -21631,6 +21631,7 @@ class BaseItem extends Mbr {
21631
21631
  updateChildrenIds() {
21632
21632
  this.children = this.index?.items.listAll().map((item) => item.getId()) || [];
21633
21633
  }
21634
+ onParentChanged(_newParent) {}
21634
21635
  getId() {
21635
21636
  return this.id;
21636
21637
  }
@@ -21766,6 +21767,7 @@ class BaseItem extends Mbr {
21766
21767
  const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerNestingMatrix);
21767
21768
  this.board.items.index.remove(foundItem);
21768
21769
  foundItem.parent = this.getId();
21770
+ foundItem.onParentChanged(this.getId());
21769
21771
  foundItem.transformation.setLocalMatrix(localMatrix);
21770
21772
  this.index?.insert(foundItem);
21771
21773
  }
@@ -21787,6 +21789,7 @@ class BaseItem extends Mbr {
21787
21789
  const worldMatrix = foundItem.transformation.toMatrix().composeWith(containerNestingMatrix);
21788
21790
  this.index?.remove(foundItem);
21789
21791
  foundItem.parent = "Board";
21792
+ foundItem.onParentChanged("Board");
21790
21793
  foundItem.transformation.setLocalMatrix(worldMatrix);
21791
21794
  this.board.items.index.insert(foundItem);
21792
21795
  }
@@ -22259,7 +22262,7 @@ class RichText extends BaseItem {
22259
22262
  height,
22260
22263
  maxWidth: maxWidth ? maxWidth + 1 : undefined,
22261
22264
  maxHeight,
22262
- textScale: this.getScale()
22265
+ textScale: this.isInShape && !this.autoSize ? 1 : this.getScale()
22263
22266
  };
22264
22267
  }
22265
22268
  transformCanvas() {
@@ -54132,7 +54135,7 @@ class GravityEngine {
54132
54135
  G = 80;
54133
54136
  G_CENTER = 120;
54134
54137
  DAMPING = 0.92;
54135
- REPULSION = 60000;
54138
+ REPULSION = 800;
54136
54139
  TICK_MS = 33;
54137
54140
  SYNC_MS = 300;
54138
54141
  MAX_DISTANCE = 3000;
@@ -54167,13 +54170,18 @@ class GravityEngine {
54167
54170
  const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
54168
54171
  if (items.length < 1)
54169
54172
  return;
54170
- const snapshot = items.map((item) => {
54173
+ const snap = items.map((item, idx) => {
54171
54174
  const pos = item.transformation.getTranslation();
54172
54175
  const mbr = item.getMbr();
54173
54176
  const w = Math.max(mbr.getWidth(), 1);
54174
54177
  const h2 = Math.max(mbr.getHeight(), 1);
54175
54178
  return {
54179
+ idx,
54176
54180
  id: item.getId(),
54181
+ left: pos.x,
54182
+ top: pos.y,
54183
+ right: pos.x + w,
54184
+ bottom: pos.y + h2,
54177
54185
  cx: pos.x + w * 0.5,
54178
54186
  cy: pos.y + h2 * 0.5,
54179
54187
  w,
@@ -54181,16 +54189,15 @@ class GravityEngine {
54181
54189
  mass: w * h2
54182
54190
  };
54183
54191
  });
54184
- let sumX = 0;
54185
- let sumY = 0;
54186
- for (const s2 of snapshot) {
54192
+ let sumX = 0, sumY = 0;
54193
+ for (const s2 of snap) {
54187
54194
  sumX += s2.cx;
54188
54195
  sumY += s2.cy;
54189
54196
  }
54190
- const centerX = sumX / snapshot.length;
54191
- const centerY = sumY / snapshot.length;
54192
- for (let i = 0;i < snapshot.length; i++) {
54193
- const s1 = snapshot[i];
54197
+ const centerX = sumX / snap.length;
54198
+ const centerY = sumY / snap.length;
54199
+ for (let i = 0;i < snap.length; i++) {
54200
+ const s1 = snap[i];
54194
54201
  if (!this.velocities.has(s1.id)) {
54195
54202
  this.velocities.set(s1.id, { vx: 0, vy: 0 });
54196
54203
  }
@@ -54202,22 +54209,28 @@ class GravityEngine {
54202
54209
  const distCenter = Math.sqrt(dcx * dcx + dcy * dcy) + 1;
54203
54210
  ax += this.G_CENTER * dcx / distCenter;
54204
54211
  ay += this.G_CENTER * dcy / distCenter;
54205
- for (let j = 0;j < snapshot.length; j++) {
54212
+ for (let j = 0;j < snap.length; j++) {
54206
54213
  if (i === j)
54207
54214
  continue;
54208
- const s2 = snapshot[j];
54215
+ const s2 = snap[j];
54209
54216
  const dx = s2.cx - s1.cx;
54210
54217
  const dy = s2.cy - s1.cy;
54211
- const distSq = dx * dx + dy * dy;
54212
- const dist = Math.sqrt(distSq) + 0.001;
54218
+ const dist = Math.sqrt(dx * dx + dy * dy) + 0.001;
54213
54219
  if (dist > this.MAX_DISTANCE)
54214
54220
  continue;
54215
- const minDist = (s1.w + s2.w + s1.h + s2.h) * 0.25;
54216
- if (dist < minDist) {
54217
- const repAcc = this.REPULSION / (distSq + this.SOFTENING_SQ);
54218
- ax -= repAcc * dx / dist;
54219
- ay -= repAcc * dy / dist;
54221
+ const overlapping = s1.right > s2.left && s2.right > s1.left && s1.bottom > s2.top && s2.bottom > s1.top;
54222
+ if (overlapping) {
54223
+ const overlapX = Math.min(s1.right, s2.right) - Math.max(s1.left, s2.left);
54224
+ const overlapY = Math.min(s1.bottom, s2.bottom) - Math.max(s1.top, s2.top);
54225
+ if (overlapX < overlapY) {
54226
+ const sign = s1.cx < s2.cx ? -1 : 1;
54227
+ ax += sign * this.REPULSION * overlapX;
54228
+ } else {
54229
+ const sign = s1.cy < s2.cy ? -1 : 1;
54230
+ ay += sign * this.REPULSION * overlapY;
54231
+ }
54220
54232
  } else {
54233
+ const distSq = dx * dx + dy * dy;
54221
54234
  const gravAcc = this.G * s2.mass / (distSq + this.SOFTENING_SQ);
54222
54235
  ax += gravAcc * dx / dist;
54223
54236
  ay += gravAcc * dy / dist;
@@ -54259,14 +54272,7 @@ class GravityEngine {
54259
54272
  method: "applyMatrix",
54260
54273
  items: movedItems.map(({ id, dx, dy }) => ({
54261
54274
  id,
54262
- matrix: {
54263
- translateX: dx,
54264
- translateY: dy,
54265
- scaleX: 1,
54266
- scaleY: 1,
54267
- shearX: 0,
54268
- shearY: 0
54269
- }
54275
+ matrix: { translateX: dx, translateY: dy, scaleX: 1, scaleY: 1, shearX: 0, shearY: 0 }
54270
54276
  }))
54271
54277
  };
54272
54278
  this.board.events.emit(operation);
package/dist/esm/node.js CHANGED
@@ -24098,6 +24098,7 @@ class BaseItem extends Mbr {
24098
24098
  updateChildrenIds() {
24099
24099
  this.children = this.index?.items.listAll().map((item) => item.getId()) || [];
24100
24100
  }
24101
+ onParentChanged(_newParent) {}
24101
24102
  getId() {
24102
24103
  return this.id;
24103
24104
  }
@@ -24233,6 +24234,7 @@ class BaseItem extends Mbr {
24233
24234
  const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerNestingMatrix);
24234
24235
  this.board.items.index.remove(foundItem);
24235
24236
  foundItem.parent = this.getId();
24237
+ foundItem.onParentChanged(this.getId());
24236
24238
  foundItem.transformation.setLocalMatrix(localMatrix);
24237
24239
  this.index?.insert(foundItem);
24238
24240
  }
@@ -24254,6 +24256,7 @@ class BaseItem extends Mbr {
24254
24256
  const worldMatrix = foundItem.transformation.toMatrix().composeWith(containerNestingMatrix);
24255
24257
  this.index?.remove(foundItem);
24256
24258
  foundItem.parent = "Board";
24259
+ foundItem.onParentChanged("Board");
24257
24260
  foundItem.transformation.setLocalMatrix(worldMatrix);
24258
24261
  this.board.items.index.insert(foundItem);
24259
24262
  }
@@ -24726,7 +24729,7 @@ class RichText extends BaseItem {
24726
24729
  height,
24727
24730
  maxWidth: maxWidth ? maxWidth + 1 : undefined,
24728
24731
  maxHeight,
24729
- textScale: this.getScale()
24732
+ textScale: this.isInShape && !this.autoSize ? 1 : this.getScale()
24730
24733
  };
24731
24734
  }
24732
24735
  transformCanvas() {
@@ -56600,7 +56603,7 @@ class GravityEngine {
56600
56603
  G = 80;
56601
56604
  G_CENTER = 120;
56602
56605
  DAMPING = 0.92;
56603
- REPULSION = 60000;
56606
+ REPULSION = 800;
56604
56607
  TICK_MS = 33;
56605
56608
  SYNC_MS = 300;
56606
56609
  MAX_DISTANCE = 3000;
@@ -56635,13 +56638,18 @@ class GravityEngine {
56635
56638
  const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
56636
56639
  if (items.length < 1)
56637
56640
  return;
56638
- const snapshot = items.map((item) => {
56641
+ const snap = items.map((item, idx) => {
56639
56642
  const pos = item.transformation.getTranslation();
56640
56643
  const mbr = item.getMbr();
56641
56644
  const w = Math.max(mbr.getWidth(), 1);
56642
56645
  const h2 = Math.max(mbr.getHeight(), 1);
56643
56646
  return {
56647
+ idx,
56644
56648
  id: item.getId(),
56649
+ left: pos.x,
56650
+ top: pos.y,
56651
+ right: pos.x + w,
56652
+ bottom: pos.y + h2,
56645
56653
  cx: pos.x + w * 0.5,
56646
56654
  cy: pos.y + h2 * 0.5,
56647
56655
  w,
@@ -56649,16 +56657,15 @@ class GravityEngine {
56649
56657
  mass: w * h2
56650
56658
  };
56651
56659
  });
56652
- let sumX = 0;
56653
- let sumY = 0;
56654
- for (const s2 of snapshot) {
56660
+ let sumX = 0, sumY = 0;
56661
+ for (const s2 of snap) {
56655
56662
  sumX += s2.cx;
56656
56663
  sumY += s2.cy;
56657
56664
  }
56658
- const centerX = sumX / snapshot.length;
56659
- const centerY = sumY / snapshot.length;
56660
- for (let i = 0;i < snapshot.length; i++) {
56661
- const s1 = snapshot[i];
56665
+ const centerX = sumX / snap.length;
56666
+ const centerY = sumY / snap.length;
56667
+ for (let i = 0;i < snap.length; i++) {
56668
+ const s1 = snap[i];
56662
56669
  if (!this.velocities.has(s1.id)) {
56663
56670
  this.velocities.set(s1.id, { vx: 0, vy: 0 });
56664
56671
  }
@@ -56670,22 +56677,28 @@ class GravityEngine {
56670
56677
  const distCenter = Math.sqrt(dcx * dcx + dcy * dcy) + 1;
56671
56678
  ax += this.G_CENTER * dcx / distCenter;
56672
56679
  ay += this.G_CENTER * dcy / distCenter;
56673
- for (let j = 0;j < snapshot.length; j++) {
56680
+ for (let j = 0;j < snap.length; j++) {
56674
56681
  if (i === j)
56675
56682
  continue;
56676
- const s2 = snapshot[j];
56683
+ const s2 = snap[j];
56677
56684
  const dx = s2.cx - s1.cx;
56678
56685
  const dy = s2.cy - s1.cy;
56679
- const distSq = dx * dx + dy * dy;
56680
- const dist = Math.sqrt(distSq) + 0.001;
56686
+ const dist = Math.sqrt(dx * dx + dy * dy) + 0.001;
56681
56687
  if (dist > this.MAX_DISTANCE)
56682
56688
  continue;
56683
- const minDist = (s1.w + s2.w + s1.h + s2.h) * 0.25;
56684
- if (dist < minDist) {
56685
- const repAcc = this.REPULSION / (distSq + this.SOFTENING_SQ);
56686
- ax -= repAcc * dx / dist;
56687
- ay -= repAcc * dy / dist;
56689
+ const overlapping = s1.right > s2.left && s2.right > s1.left && s1.bottom > s2.top && s2.bottom > s1.top;
56690
+ if (overlapping) {
56691
+ const overlapX = Math.min(s1.right, s2.right) - Math.max(s1.left, s2.left);
56692
+ const overlapY = Math.min(s1.bottom, s2.bottom) - Math.max(s1.top, s2.top);
56693
+ if (overlapX < overlapY) {
56694
+ const sign = s1.cx < s2.cx ? -1 : 1;
56695
+ ax += sign * this.REPULSION * overlapX;
56696
+ } else {
56697
+ const sign = s1.cy < s2.cy ? -1 : 1;
56698
+ ay += sign * this.REPULSION * overlapY;
56699
+ }
56688
56700
  } else {
56701
+ const distSq = dx * dx + dy * dy;
56689
56702
  const gravAcc = this.G * s2.mass / (distSq + this.SOFTENING_SQ);
56690
56703
  ax += gravAcc * dx / dist;
56691
56704
  ay += gravAcc * dy / dist;
@@ -56727,14 +56740,7 @@ class GravityEngine {
56727
56740
  method: "applyMatrix",
56728
56741
  items: movedItems.map(({ id, dx, dy }) => ({
56729
56742
  id,
56730
- matrix: {
56731
- translateX: dx,
56732
- translateY: dy,
56733
- scaleX: 1,
56734
- scaleY: 1,
56735
- shearX: 0,
56736
- shearY: 0
56737
- }
56743
+ matrix: { translateX: dx, translateY: dy, scaleX: 1, scaleY: 1, shearX: 0, shearY: 0 }
56738
56744
  }))
56739
56745
  };
56740
56746
  this.board.events.emit(operation);
@@ -8,7 +8,7 @@ export declare class GravityEngine {
8
8
  readonly G = 80;
9
9
  readonly G_CENTER = 120;
10
10
  readonly DAMPING = 0.92;
11
- readonly REPULSION = 60000;
11
+ readonly REPULSION = 800;
12
12
  readonly TICK_MS = 33;
13
13
  readonly SYNC_MS = 300;
14
14
  readonly MAX_DISTANCE = 3000;
@@ -47,6 +47,11 @@ export declare class BaseItem extends Mbr implements Geometry {
47
47
  static readonly HOVER_HIGHLIGHT_COLOR = "rgba(71, 120, 245, 0.7)";
48
48
  constructor(board: Board, id?: string, defaultItemData?: BaseItemData | undefined, isGroupItem?: boolean);
49
49
  updateChildrenIds(): void;
50
+ /**
51
+ * Called when this item's parent changes. Subclasses override this to
52
+ * propagate the new parent to child objects (e.g. text.parent in Sticker/Shape).
53
+ */
54
+ protected onParentChanged(_newParent: string): void;
50
55
  getId(): string;
51
56
  /**
52
57
  * Returns the parent's world matrix. For Frames, only the translation component
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "microboard-temp",
3
- "version": "0.12.4",
3
+ "version": "0.12.6",
4
4
  "description": "A flexible interactive whiteboard library",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",