microboard-temp 0.12.1 → 0.12.3

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.
@@ -19367,13 +19367,18 @@ class Comment {
19367
19367
  userId
19368
19368
  });
19369
19369
  }
19370
+ _syncing = false;
19370
19371
  transform() {
19372
+ if (this._syncing)
19373
+ return;
19374
+ this._syncing = true;
19371
19375
  const { translateX, translateY } = this.transformation.getMatrixData();
19372
19376
  if (translateX && translateY) {
19373
19377
  this.anchor = new Point(translateX, translateY);
19374
19378
  } else {
19375
19379
  this.transformation.setLocal(this.anchor.x, this.anchor.y);
19376
19380
  }
19381
+ this._syncing = false;
19377
19382
  }
19378
19383
  getUnreadMessages(userId = ANONYMOUS_ID) {
19379
19384
  const unreadMessages = this.thread.filter((mes) => mes && !mes.readers.includes(userId));
@@ -19478,6 +19483,9 @@ class Comment {
19478
19483
  }
19479
19484
  addOnRemoveCallback(_cb) {}
19480
19485
  onRemove() {}
19486
+ highlightMbr() {}
19487
+ clearHighlightMbr() {}
19488
+ renderHoverHighlight(_context) {}
19481
19489
  render(context) {}
19482
19490
  renderHTML(documentFactory) {
19483
19491
  const div = documentFactory.createElement("comment-item");
@@ -22200,7 +22208,6 @@ class RichText extends BaseItem {
22200
22208
  _onLimitReached = () => {};
22201
22209
  shrinkWidth = false;
22202
22210
  prevMbr = null;
22203
- worldMatrixGetter;
22204
22211
  rtCounter = 0;
22205
22212
  constructor(board, container, id = "", transformation = new Transformation(id, board.events), linkTo, placeholderText = conf.i18n?.t("board.textPlaceholder"), isInShape = false, autoSize = false, insideOf, initialTextStyles = conf.DEFAULT_TEXT_STYLES) {
22206
22213
  super(board, id);
@@ -22423,18 +22430,7 @@ class RichText extends BaseItem {
22423
22430
  top = container.top;
22424
22431
  }
22425
22432
  const point3 = new Point(left, top);
22426
- if (this.worldMatrixGetter) {
22427
- this.worldMatrixGetter().apply(point3);
22428
- } else if (this.isInShape) {
22429
- const item = this.board.items.getById(this.id);
22430
- if (item) {
22431
- item.getParentWorldMatrix().apply(point3);
22432
- } else {
22433
- this.getParentWorldMatrix().apply(point3);
22434
- }
22435
- } else {
22436
- this.getParentWorldMatrix().apply(point3);
22437
- }
22433
+ this.getParentWorldMatrix().apply(point3);
22438
22434
  return {
22439
22435
  point: point3,
22440
22436
  width,
@@ -36538,6 +36534,11 @@ class AINode extends BaseItem {
36538
36534
  this.linkTo.setId(id);
36539
36535
  return this;
36540
36536
  }
36537
+ onParentChanged(newParent) {
36538
+ if (this.text) {
36539
+ this.text.parent = newParent;
36540
+ }
36541
+ }
36541
36542
  getId() {
36542
36543
  return this.id;
36543
36544
  }
@@ -40062,6 +40063,11 @@ class Shape extends BaseItem {
40062
40063
  this.linkTo.setId(id);
40063
40064
  return this;
40064
40065
  }
40066
+ onParentChanged(newParent) {
40067
+ if (this.text) {
40068
+ this.text.parent = newParent;
40069
+ }
40070
+ }
40065
40071
  getId() {
40066
40072
  return this.id;
40067
40073
  }
@@ -40594,6 +40600,11 @@ class Sticker extends BaseItem {
40594
40600
  this.transformation.setId(id);
40595
40601
  return this;
40596
40602
  }
40603
+ onParentChanged(newParent) {
40604
+ if (this.text) {
40605
+ this.text.parent = newParent;
40606
+ }
40607
+ }
40597
40608
  getId() {
40598
40609
  return this.id;
40599
40610
  }
@@ -41121,15 +41132,6 @@ class Frame2 extends BaseItem {
41121
41132
  y: translateY
41122
41133
  }, timeStamp);
41123
41134
  const newMatrix = this.transformation.toMatrix();
41124
- if (newMatrix.translateX !== oldMatrix.translateX || newMatrix.translateY !== oldMatrix.translateY) {
41125
- const dx = newMatrix.translateX - oldMatrix.translateX;
41126
- const dy = newMatrix.translateY - oldMatrix.translateY;
41127
- this.index?.list().forEach((child) => {
41128
- if (child instanceof BaseItem) {
41129
- child.transformation.translateBy(-dx, -dy, timeStamp);
41130
- }
41131
- });
41132
- }
41133
41135
  this.setLastFrameScale();
41134
41136
  res.mbr = this.getMbr();
41135
41137
  return res;
@@ -54297,14 +54299,18 @@ class BoardSelection {
54297
54299
  }
54298
54300
  }
54299
54301
  // src/Gravity/GravityEngine.ts
54302
+ var EXCLUDED_ITEM_TYPES = new Set(["Comment", "Connector"]);
54303
+
54300
54304
  class GravityEngine {
54301
54305
  board;
54302
54306
  velocities = new Map;
54303
54307
  tickTimer = null;
54304
54308
  syncTimer = null;
54305
54309
  lastSyncedPositions = new Map;
54306
- G = 500;
54307
- DAMPING = 0.98;
54310
+ G = 80;
54311
+ G_CENTER = 120;
54312
+ DAMPING = 0.92;
54313
+ REPULSION = 60000;
54308
54314
  TICK_MS = 33;
54309
54315
  SYNC_MS = 300;
54310
54316
  MAX_DISTANCE = 3000;
@@ -54336,41 +54342,67 @@ class GravityEngine {
54336
54342
  }
54337
54343
  tick() {
54338
54344
  const dt = this.TICK_MS / 1000;
54339
- const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked);
54340
- if (items.length < 2)
54345
+ const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
54346
+ if (items.length < 1)
54341
54347
  return;
54348
+ let sumX = 0;
54349
+ let sumY = 0;
54350
+ for (const item of items) {
54351
+ const mbr = item.getMbr();
54352
+ sumX += mbr.left + mbr.getWidth() * 0.5;
54353
+ sumY += mbr.top + mbr.getHeight() * 0.5;
54354
+ }
54355
+ const centerX = sumX / items.length;
54356
+ const centerY = sumY / items.length;
54342
54357
  for (const item of items) {
54343
54358
  const id = item.getId();
54344
54359
  if (!this.velocities.has(id)) {
54345
54360
  this.velocities.set(id, { vx: 0, vy: 0 });
54346
54361
  }
54347
54362
  const vel = this.velocities.get(id);
54348
- const pos1 = item.transformation.getTranslation();
54349
54363
  const mbr1 = item.getMbr();
54350
- const mass1 = mbr1.getWidth() * mbr1.getHeight();
54351
- const nearby = this.board.items.getEnclosedOrCrossed(pos1.x - this.MAX_DISTANCE, pos1.y - this.MAX_DISTANCE, pos1.x + this.MAX_DISTANCE * 2, pos1.y + this.MAX_DISTANCE * 2).filter((other) => other.getId() !== id);
54364
+ const w1 = mbr1.getWidth();
54365
+ const h1 = mbr1.getHeight();
54352
54366
  let ax = 0;
54353
54367
  let ay = 0;
54368
+ const cx1 = mbr1.left + w1 * 0.5;
54369
+ const cy1 = mbr1.top + h1 * 0.5;
54370
+ const dcx = centerX - cx1;
54371
+ const dcy = centerY - cy1;
54372
+ const distCenter = Math.sqrt(dcx * dcx + dcy * dcy) + 1;
54373
+ ax += this.G_CENTER * dcx / distCenter;
54374
+ ay += this.G_CENTER * dcy / distCenter;
54375
+ const nearby = this.board.items.getEnclosedOrCrossed(cx1 - this.MAX_DISTANCE, cy1 - this.MAX_DISTANCE, cx1 + this.MAX_DISTANCE * 2, cy1 + this.MAX_DISTANCE * 2).filter((other) => other.getId() !== id && !EXCLUDED_ITEM_TYPES.has(other.itemType));
54354
54376
  for (const other of nearby) {
54355
- const pos2 = other.transformation.getTranslation();
54356
54377
  const mbr2 = other.getMbr();
54357
- const mass2 = mbr2.getWidth() * mbr2.getHeight();
54358
- const dx2 = pos2.x - pos1.x;
54359
- const dy2 = pos2.y - pos1.y;
54360
- const distSq = dx2 * dx2 + dy2 * dy2 + this.SOFTENING_SQ;
54361
- const dist = Math.sqrt(distSq);
54362
- const acc = this.G * mass2 / distSq;
54363
- ax += acc * dx2 / dist;
54364
- ay += acc * dy2 / dist;
54378
+ const w2 = mbr2.getWidth();
54379
+ const h2 = mbr2.getHeight();
54380
+ const mass2 = w2 * h2;
54381
+ const cx2 = mbr2.left + w2 * 0.5;
54382
+ const cy2 = mbr2.top + h2 * 0.5;
54383
+ const dx = cx2 - cx1;
54384
+ const dy = cy2 - cy1;
54385
+ const distSq = dx * dx + dy * dy;
54386
+ const dist = Math.sqrt(distSq) + 0.001;
54387
+ const minDist = (w1 + w2) * 0.5 + (h1 + h2) * 0.5;
54388
+ if (dist < minDist) {
54389
+ const repAcc = this.REPULSION / (distSq + this.SOFTENING_SQ);
54390
+ ax -= repAcc * dx / dist;
54391
+ ay -= repAcc * dy / dist;
54392
+ } else {
54393
+ const gravAcc = this.G * mass2 / (distSq + this.SOFTENING_SQ);
54394
+ ax += gravAcc * dx / dist;
54395
+ ay += gravAcc * dy / dist;
54396
+ }
54365
54397
  }
54366
54398
  vel.vx = (vel.vx + ax * dt) * this.DAMPING;
54367
54399
  vel.vy = (vel.vy + ay * dt) * this.DAMPING;
54368
- const dx = vel.vx * dt;
54369
- const dy = vel.vy * dt;
54370
- if (Math.abs(dx) >= this.MIN_MOVE_PX || Math.abs(dy) >= this.MIN_MOVE_PX) {
54400
+ const moveX = vel.vx * dt;
54401
+ const moveY = vel.vy * dt;
54402
+ if (Math.abs(moveX) >= this.MIN_MOVE_PX || Math.abs(moveY) >= this.MIN_MOVE_PX) {
54371
54403
  item.transformation.applyMatrixSilent({
54372
- translateX: dx,
54373
- translateY: dy,
54404
+ translateX: moveX,
54405
+ translateY: moveY,
54374
54406
  scaleX: 1,
54375
54407
  scaleY: 1,
54376
54408
  shearX: 0,
@@ -54380,7 +54412,7 @@ class GravityEngine {
54380
54412
  }
54381
54413
  }
54382
54414
  syncPositions() {
54383
- const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked);
54415
+ const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
54384
54416
  if (items.length === 0)
54385
54417
  return;
54386
54418
  const movedItems = items.map((item) => {
package/dist/cjs/index.js CHANGED
@@ -19367,13 +19367,18 @@ class Comment {
19367
19367
  userId
19368
19368
  });
19369
19369
  }
19370
+ _syncing = false;
19370
19371
  transform() {
19372
+ if (this._syncing)
19373
+ return;
19374
+ this._syncing = true;
19371
19375
  const { translateX, translateY } = this.transformation.getMatrixData();
19372
19376
  if (translateX && translateY) {
19373
19377
  this.anchor = new Point(translateX, translateY);
19374
19378
  } else {
19375
19379
  this.transformation.setLocal(this.anchor.x, this.anchor.y);
19376
19380
  }
19381
+ this._syncing = false;
19377
19382
  }
19378
19383
  getUnreadMessages(userId = ANONYMOUS_ID) {
19379
19384
  const unreadMessages = this.thread.filter((mes) => mes && !mes.readers.includes(userId));
@@ -19478,6 +19483,9 @@ class Comment {
19478
19483
  }
19479
19484
  addOnRemoveCallback(_cb) {}
19480
19485
  onRemove() {}
19486
+ highlightMbr() {}
19487
+ clearHighlightMbr() {}
19488
+ renderHoverHighlight(_context) {}
19481
19489
  render(context) {}
19482
19490
  renderHTML(documentFactory) {
19483
19491
  const div = documentFactory.createElement("comment-item");
@@ -22200,7 +22208,6 @@ class RichText extends BaseItem {
22200
22208
  _onLimitReached = () => {};
22201
22209
  shrinkWidth = false;
22202
22210
  prevMbr = null;
22203
- worldMatrixGetter;
22204
22211
  rtCounter = 0;
22205
22212
  constructor(board, container, id = "", transformation = new Transformation(id, board.events), linkTo, placeholderText = conf.i18n?.t("board.textPlaceholder"), isInShape = false, autoSize = false, insideOf, initialTextStyles = conf.DEFAULT_TEXT_STYLES) {
22206
22213
  super(board, id);
@@ -22423,18 +22430,7 @@ class RichText extends BaseItem {
22423
22430
  top = container.top;
22424
22431
  }
22425
22432
  const point3 = new Point(left, top);
22426
- if (this.worldMatrixGetter) {
22427
- this.worldMatrixGetter().apply(point3);
22428
- } else if (this.isInShape) {
22429
- const item = this.board.items.getById(this.id);
22430
- if (item) {
22431
- item.getParentWorldMatrix().apply(point3);
22432
- } else {
22433
- this.getParentWorldMatrix().apply(point3);
22434
- }
22435
- } else {
22436
- this.getParentWorldMatrix().apply(point3);
22437
- }
22433
+ this.getParentWorldMatrix().apply(point3);
22438
22434
  return {
22439
22435
  point: point3,
22440
22436
  width,
@@ -36538,6 +36534,11 @@ class AINode extends BaseItem {
36538
36534
  this.linkTo.setId(id);
36539
36535
  return this;
36540
36536
  }
36537
+ onParentChanged(newParent) {
36538
+ if (this.text) {
36539
+ this.text.parent = newParent;
36540
+ }
36541
+ }
36541
36542
  getId() {
36542
36543
  return this.id;
36543
36544
  }
@@ -40062,6 +40063,11 @@ class Shape extends BaseItem {
40062
40063
  this.linkTo.setId(id);
40063
40064
  return this;
40064
40065
  }
40066
+ onParentChanged(newParent) {
40067
+ if (this.text) {
40068
+ this.text.parent = newParent;
40069
+ }
40070
+ }
40065
40071
  getId() {
40066
40072
  return this.id;
40067
40073
  }
@@ -40594,6 +40600,11 @@ class Sticker extends BaseItem {
40594
40600
  this.transformation.setId(id);
40595
40601
  return this;
40596
40602
  }
40603
+ onParentChanged(newParent) {
40604
+ if (this.text) {
40605
+ this.text.parent = newParent;
40606
+ }
40607
+ }
40597
40608
  getId() {
40598
40609
  return this.id;
40599
40610
  }
@@ -41121,15 +41132,6 @@ class Frame2 extends BaseItem {
41121
41132
  y: translateY
41122
41133
  }, timeStamp);
41123
41134
  const newMatrix = this.transformation.toMatrix();
41124
- if (newMatrix.translateX !== oldMatrix.translateX || newMatrix.translateY !== oldMatrix.translateY) {
41125
- const dx = newMatrix.translateX - oldMatrix.translateX;
41126
- const dy = newMatrix.translateY - oldMatrix.translateY;
41127
- this.index?.list().forEach((child) => {
41128
- if (child instanceof BaseItem) {
41129
- child.transformation.translateBy(-dx, -dy, timeStamp);
41130
- }
41131
- });
41132
- }
41133
41135
  this.setLastFrameScale();
41134
41136
  res.mbr = this.getMbr();
41135
41137
  return res;
@@ -54297,14 +54299,18 @@ class BoardSelection {
54297
54299
  }
54298
54300
  }
54299
54301
  // src/Gravity/GravityEngine.ts
54302
+ var EXCLUDED_ITEM_TYPES = new Set(["Comment", "Connector"]);
54303
+
54300
54304
  class GravityEngine {
54301
54305
  board;
54302
54306
  velocities = new Map;
54303
54307
  tickTimer = null;
54304
54308
  syncTimer = null;
54305
54309
  lastSyncedPositions = new Map;
54306
- G = 500;
54307
- DAMPING = 0.98;
54310
+ G = 80;
54311
+ G_CENTER = 120;
54312
+ DAMPING = 0.92;
54313
+ REPULSION = 60000;
54308
54314
  TICK_MS = 33;
54309
54315
  SYNC_MS = 300;
54310
54316
  MAX_DISTANCE = 3000;
@@ -54336,41 +54342,67 @@ class GravityEngine {
54336
54342
  }
54337
54343
  tick() {
54338
54344
  const dt = this.TICK_MS / 1000;
54339
- const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked);
54340
- if (items.length < 2)
54345
+ const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
54346
+ if (items.length < 1)
54341
54347
  return;
54348
+ let sumX = 0;
54349
+ let sumY = 0;
54350
+ for (const item of items) {
54351
+ const mbr = item.getMbr();
54352
+ sumX += mbr.left + mbr.getWidth() * 0.5;
54353
+ sumY += mbr.top + mbr.getHeight() * 0.5;
54354
+ }
54355
+ const centerX = sumX / items.length;
54356
+ const centerY = sumY / items.length;
54342
54357
  for (const item of items) {
54343
54358
  const id = item.getId();
54344
54359
  if (!this.velocities.has(id)) {
54345
54360
  this.velocities.set(id, { vx: 0, vy: 0 });
54346
54361
  }
54347
54362
  const vel = this.velocities.get(id);
54348
- const pos1 = item.transformation.getTranslation();
54349
54363
  const mbr1 = item.getMbr();
54350
- const mass1 = mbr1.getWidth() * mbr1.getHeight();
54351
- const nearby = this.board.items.getEnclosedOrCrossed(pos1.x - this.MAX_DISTANCE, pos1.y - this.MAX_DISTANCE, pos1.x + this.MAX_DISTANCE * 2, pos1.y + this.MAX_DISTANCE * 2).filter((other) => other.getId() !== id);
54364
+ const w1 = mbr1.getWidth();
54365
+ const h1 = mbr1.getHeight();
54352
54366
  let ax = 0;
54353
54367
  let ay = 0;
54368
+ const cx1 = mbr1.left + w1 * 0.5;
54369
+ const cy1 = mbr1.top + h1 * 0.5;
54370
+ const dcx = centerX - cx1;
54371
+ const dcy = centerY - cy1;
54372
+ const distCenter = Math.sqrt(dcx * dcx + dcy * dcy) + 1;
54373
+ ax += this.G_CENTER * dcx / distCenter;
54374
+ ay += this.G_CENTER * dcy / distCenter;
54375
+ const nearby = this.board.items.getEnclosedOrCrossed(cx1 - this.MAX_DISTANCE, cy1 - this.MAX_DISTANCE, cx1 + this.MAX_DISTANCE * 2, cy1 + this.MAX_DISTANCE * 2).filter((other) => other.getId() !== id && !EXCLUDED_ITEM_TYPES.has(other.itemType));
54354
54376
  for (const other of nearby) {
54355
- const pos2 = other.transformation.getTranslation();
54356
54377
  const mbr2 = other.getMbr();
54357
- const mass2 = mbr2.getWidth() * mbr2.getHeight();
54358
- const dx2 = pos2.x - pos1.x;
54359
- const dy2 = pos2.y - pos1.y;
54360
- const distSq = dx2 * dx2 + dy2 * dy2 + this.SOFTENING_SQ;
54361
- const dist = Math.sqrt(distSq);
54362
- const acc = this.G * mass2 / distSq;
54363
- ax += acc * dx2 / dist;
54364
- ay += acc * dy2 / dist;
54378
+ const w2 = mbr2.getWidth();
54379
+ const h2 = mbr2.getHeight();
54380
+ const mass2 = w2 * h2;
54381
+ const cx2 = mbr2.left + w2 * 0.5;
54382
+ const cy2 = mbr2.top + h2 * 0.5;
54383
+ const dx = cx2 - cx1;
54384
+ const dy = cy2 - cy1;
54385
+ const distSq = dx * dx + dy * dy;
54386
+ const dist = Math.sqrt(distSq) + 0.001;
54387
+ const minDist = (w1 + w2) * 0.5 + (h1 + h2) * 0.5;
54388
+ if (dist < minDist) {
54389
+ const repAcc = this.REPULSION / (distSq + this.SOFTENING_SQ);
54390
+ ax -= repAcc * dx / dist;
54391
+ ay -= repAcc * dy / dist;
54392
+ } else {
54393
+ const gravAcc = this.G * mass2 / (distSq + this.SOFTENING_SQ);
54394
+ ax += gravAcc * dx / dist;
54395
+ ay += gravAcc * dy / dist;
54396
+ }
54365
54397
  }
54366
54398
  vel.vx = (vel.vx + ax * dt) * this.DAMPING;
54367
54399
  vel.vy = (vel.vy + ay * dt) * this.DAMPING;
54368
- const dx = vel.vx * dt;
54369
- const dy = vel.vy * dt;
54370
- if (Math.abs(dx) >= this.MIN_MOVE_PX || Math.abs(dy) >= this.MIN_MOVE_PX) {
54400
+ const moveX = vel.vx * dt;
54401
+ const moveY = vel.vy * dt;
54402
+ if (Math.abs(moveX) >= this.MIN_MOVE_PX || Math.abs(moveY) >= this.MIN_MOVE_PX) {
54371
54403
  item.transformation.applyMatrixSilent({
54372
- translateX: dx,
54373
- translateY: dy,
54404
+ translateX: moveX,
54405
+ translateY: moveY,
54374
54406
  scaleX: 1,
54375
54407
  scaleY: 1,
54376
54408
  shearX: 0,
@@ -54380,7 +54412,7 @@ class GravityEngine {
54380
54412
  }
54381
54413
  }
54382
54414
  syncPositions() {
54383
- const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked);
54415
+ const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
54384
54416
  if (items.length === 0)
54385
54417
  return;
54386
54418
  const movedItems = items.map((item) => {
package/dist/cjs/node.js CHANGED
@@ -21906,13 +21906,18 @@ class Comment {
21906
21906
  userId
21907
21907
  });
21908
21908
  }
21909
+ _syncing = false;
21909
21910
  transform() {
21911
+ if (this._syncing)
21912
+ return;
21913
+ this._syncing = true;
21910
21914
  const { translateX, translateY } = this.transformation.getMatrixData();
21911
21915
  if (translateX && translateY) {
21912
21916
  this.anchor = new Point(translateX, translateY);
21913
21917
  } else {
21914
21918
  this.transformation.setLocal(this.anchor.x, this.anchor.y);
21915
21919
  }
21920
+ this._syncing = false;
21916
21921
  }
21917
21922
  getUnreadMessages(userId = ANONYMOUS_ID) {
21918
21923
  const unreadMessages = this.thread.filter((mes) => mes && !mes.readers.includes(userId));
@@ -22017,6 +22022,9 @@ class Comment {
22017
22022
  }
22018
22023
  addOnRemoveCallback(_cb) {}
22019
22024
  onRemove() {}
22025
+ highlightMbr() {}
22026
+ clearHighlightMbr() {}
22027
+ renderHoverHighlight(_context) {}
22020
22028
  render(context) {}
22021
22029
  renderHTML(documentFactory) {
22022
22030
  const div = documentFactory.createElement("comment-item");
@@ -24672,7 +24680,6 @@ class RichText extends BaseItem {
24672
24680
  _onLimitReached = () => {};
24673
24681
  shrinkWidth = false;
24674
24682
  prevMbr = null;
24675
- worldMatrixGetter;
24676
24683
  rtCounter = 0;
24677
24684
  constructor(board, container, id = "", transformation = new Transformation(id, board.events), linkTo, placeholderText = conf.i18n?.t("board.textPlaceholder"), isInShape = false, autoSize = false, insideOf, initialTextStyles = conf.DEFAULT_TEXT_STYLES) {
24678
24685
  super(board, id);
@@ -24895,18 +24902,7 @@ class RichText extends BaseItem {
24895
24902
  top = container.top;
24896
24903
  }
24897
24904
  const point3 = new Point(left, top);
24898
- if (this.worldMatrixGetter) {
24899
- this.worldMatrixGetter().apply(point3);
24900
- } else if (this.isInShape) {
24901
- const item = this.board.items.getById(this.id);
24902
- if (item) {
24903
- item.getParentWorldMatrix().apply(point3);
24904
- } else {
24905
- this.getParentWorldMatrix().apply(point3);
24906
- }
24907
- } else {
24908
- this.getParentWorldMatrix().apply(point3);
24909
- }
24905
+ this.getParentWorldMatrix().apply(point3);
24910
24906
  return {
24911
24907
  point: point3,
24912
24908
  width,
@@ -39011,6 +39007,11 @@ class AINode extends BaseItem {
39011
39007
  this.linkTo.setId(id);
39012
39008
  return this;
39013
39009
  }
39010
+ onParentChanged(newParent) {
39011
+ if (this.text) {
39012
+ this.text.parent = newParent;
39013
+ }
39014
+ }
39014
39015
  getId() {
39015
39016
  return this.id;
39016
39017
  }
@@ -42535,6 +42536,11 @@ class Shape extends BaseItem {
42535
42536
  this.linkTo.setId(id);
42536
42537
  return this;
42537
42538
  }
42539
+ onParentChanged(newParent) {
42540
+ if (this.text) {
42541
+ this.text.parent = newParent;
42542
+ }
42543
+ }
42538
42544
  getId() {
42539
42545
  return this.id;
42540
42546
  }
@@ -43067,6 +43073,11 @@ class Sticker extends BaseItem {
43067
43073
  this.transformation.setId(id);
43068
43074
  return this;
43069
43075
  }
43076
+ onParentChanged(newParent) {
43077
+ if (this.text) {
43078
+ this.text.parent = newParent;
43079
+ }
43080
+ }
43070
43081
  getId() {
43071
43082
  return this.id;
43072
43083
  }
@@ -43594,15 +43605,6 @@ class Frame2 extends BaseItem {
43594
43605
  y: translateY
43595
43606
  }, timeStamp);
43596
43607
  const newMatrix = this.transformation.toMatrix();
43597
- if (newMatrix.translateX !== oldMatrix.translateX || newMatrix.translateY !== oldMatrix.translateY) {
43598
- const dx = newMatrix.translateX - oldMatrix.translateX;
43599
- const dy = newMatrix.translateY - oldMatrix.translateY;
43600
- this.index?.list().forEach((child) => {
43601
- if (child instanceof BaseItem) {
43602
- child.transformation.translateBy(-dx, -dy, timeStamp);
43603
- }
43604
- });
43605
- }
43606
43608
  this.setLastFrameScale();
43607
43609
  res.mbr = this.getMbr();
43608
43610
  return res;
@@ -56770,14 +56772,18 @@ class BoardSelection {
56770
56772
  }
56771
56773
  }
56772
56774
  // src/Gravity/GravityEngine.ts
56775
+ var EXCLUDED_ITEM_TYPES = new Set(["Comment", "Connector"]);
56776
+
56773
56777
  class GravityEngine {
56774
56778
  board;
56775
56779
  velocities = new Map;
56776
56780
  tickTimer = null;
56777
56781
  syncTimer = null;
56778
56782
  lastSyncedPositions = new Map;
56779
- G = 500;
56780
- DAMPING = 0.98;
56783
+ G = 80;
56784
+ G_CENTER = 120;
56785
+ DAMPING = 0.92;
56786
+ REPULSION = 60000;
56781
56787
  TICK_MS = 33;
56782
56788
  SYNC_MS = 300;
56783
56789
  MAX_DISTANCE = 3000;
@@ -56809,41 +56815,67 @@ class GravityEngine {
56809
56815
  }
56810
56816
  tick() {
56811
56817
  const dt = this.TICK_MS / 1000;
56812
- const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked);
56813
- if (items.length < 2)
56818
+ const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
56819
+ if (items.length < 1)
56814
56820
  return;
56821
+ let sumX = 0;
56822
+ let sumY = 0;
56823
+ for (const item of items) {
56824
+ const mbr = item.getMbr();
56825
+ sumX += mbr.left + mbr.getWidth() * 0.5;
56826
+ sumY += mbr.top + mbr.getHeight() * 0.5;
56827
+ }
56828
+ const centerX = sumX / items.length;
56829
+ const centerY = sumY / items.length;
56815
56830
  for (const item of items) {
56816
56831
  const id = item.getId();
56817
56832
  if (!this.velocities.has(id)) {
56818
56833
  this.velocities.set(id, { vx: 0, vy: 0 });
56819
56834
  }
56820
56835
  const vel = this.velocities.get(id);
56821
- const pos1 = item.transformation.getTranslation();
56822
56836
  const mbr1 = item.getMbr();
56823
- const mass1 = mbr1.getWidth() * mbr1.getHeight();
56824
- const nearby = this.board.items.getEnclosedOrCrossed(pos1.x - this.MAX_DISTANCE, pos1.y - this.MAX_DISTANCE, pos1.x + this.MAX_DISTANCE * 2, pos1.y + this.MAX_DISTANCE * 2).filter((other) => other.getId() !== id);
56837
+ const w1 = mbr1.getWidth();
56838
+ const h1 = mbr1.getHeight();
56825
56839
  let ax = 0;
56826
56840
  let ay = 0;
56841
+ const cx1 = mbr1.left + w1 * 0.5;
56842
+ const cy1 = mbr1.top + h1 * 0.5;
56843
+ const dcx = centerX - cx1;
56844
+ const dcy = centerY - cy1;
56845
+ const distCenter = Math.sqrt(dcx * dcx + dcy * dcy) + 1;
56846
+ ax += this.G_CENTER * dcx / distCenter;
56847
+ ay += this.G_CENTER * dcy / distCenter;
56848
+ const nearby = this.board.items.getEnclosedOrCrossed(cx1 - this.MAX_DISTANCE, cy1 - this.MAX_DISTANCE, cx1 + this.MAX_DISTANCE * 2, cy1 + this.MAX_DISTANCE * 2).filter((other) => other.getId() !== id && !EXCLUDED_ITEM_TYPES.has(other.itemType));
56827
56849
  for (const other of nearby) {
56828
- const pos2 = other.transformation.getTranslation();
56829
56850
  const mbr2 = other.getMbr();
56830
- const mass2 = mbr2.getWidth() * mbr2.getHeight();
56831
- const dx2 = pos2.x - pos1.x;
56832
- const dy2 = pos2.y - pos1.y;
56833
- const distSq = dx2 * dx2 + dy2 * dy2 + this.SOFTENING_SQ;
56834
- const dist = Math.sqrt(distSq);
56835
- const acc = this.G * mass2 / distSq;
56836
- ax += acc * dx2 / dist;
56837
- ay += acc * dy2 / dist;
56851
+ const w2 = mbr2.getWidth();
56852
+ const h2 = mbr2.getHeight();
56853
+ const mass2 = w2 * h2;
56854
+ const cx2 = mbr2.left + w2 * 0.5;
56855
+ const cy2 = mbr2.top + h2 * 0.5;
56856
+ const dx = cx2 - cx1;
56857
+ const dy = cy2 - cy1;
56858
+ const distSq = dx * dx + dy * dy;
56859
+ const dist = Math.sqrt(distSq) + 0.001;
56860
+ const minDist = (w1 + w2) * 0.5 + (h1 + h2) * 0.5;
56861
+ if (dist < minDist) {
56862
+ const repAcc = this.REPULSION / (distSq + this.SOFTENING_SQ);
56863
+ ax -= repAcc * dx / dist;
56864
+ ay -= repAcc * dy / dist;
56865
+ } else {
56866
+ const gravAcc = this.G * mass2 / (distSq + this.SOFTENING_SQ);
56867
+ ax += gravAcc * dx / dist;
56868
+ ay += gravAcc * dy / dist;
56869
+ }
56838
56870
  }
56839
56871
  vel.vx = (vel.vx + ax * dt) * this.DAMPING;
56840
56872
  vel.vy = (vel.vy + ay * dt) * this.DAMPING;
56841
- const dx = vel.vx * dt;
56842
- const dy = vel.vy * dt;
56843
- if (Math.abs(dx) >= this.MIN_MOVE_PX || Math.abs(dy) >= this.MIN_MOVE_PX) {
56873
+ const moveX = vel.vx * dt;
56874
+ const moveY = vel.vy * dt;
56875
+ if (Math.abs(moveX) >= this.MIN_MOVE_PX || Math.abs(moveY) >= this.MIN_MOVE_PX) {
56844
56876
  item.transformation.applyMatrixSilent({
56845
- translateX: dx,
56846
- translateY: dy,
56877
+ translateX: moveX,
56878
+ translateY: moveY,
56847
56879
  scaleX: 1,
56848
56880
  scaleY: 1,
56849
56881
  shearX: 0,
@@ -56853,7 +56885,7 @@ class GravityEngine {
56853
56885
  }
56854
56886
  }
56855
56887
  syncPositions() {
56856
- const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked);
56888
+ const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
56857
56889
  if (items.length === 0)
56858
56890
  return;
56859
56891
  const movedItems = items.map((item) => {