microboard-temp 0.12.2 → 0.12.4

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.
@@ -19483,6 +19483,9 @@ class Comment {
19483
19483
  }
19484
19484
  addOnRemoveCallback(_cb) {}
19485
19485
  onRemove() {}
19486
+ highlightMbr() {}
19487
+ clearHighlightMbr() {}
19488
+ renderHoverHighlight(_context) {}
19486
19489
  render(context) {}
19487
19490
  renderHTML(documentFactory) {
19488
19491
  const div = documentFactory.createElement("comment-item");
@@ -54342,50 +54345,58 @@ class GravityEngine {
54342
54345
  const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
54343
54346
  if (items.length < 1)
54344
54347
  return;
54348
+ const snapshot = items.map((item) => {
54349
+ const pos = item.transformation.getTranslation();
54350
+ const mbr = item.getMbr();
54351
+ const w = Math.max(mbr.getWidth(), 1);
54352
+ const h2 = Math.max(mbr.getHeight(), 1);
54353
+ return {
54354
+ id: item.getId(),
54355
+ cx: pos.x + w * 0.5,
54356
+ cy: pos.y + h2 * 0.5,
54357
+ w,
54358
+ h: h2,
54359
+ mass: w * h2
54360
+ };
54361
+ });
54345
54362
  let sumX = 0;
54346
54363
  let sumY = 0;
54347
- for (const item of items) {
54348
- const pos = item.transformation.getTranslation();
54349
- sumX += pos.x;
54350
- sumY += pos.y;
54351
- }
54352
- const centerX = sumX / items.length;
54353
- const centerY = sumY / items.length;
54354
- for (const item of items) {
54355
- const id = item.getId();
54356
- if (!this.velocities.has(id)) {
54357
- this.velocities.set(id, { vx: 0, vy: 0 });
54358
- }
54359
- const vel = this.velocities.get(id);
54360
- const pos1 = item.transformation.getTranslation();
54361
- const mbr1 = item.getMbr();
54362
- const w1 = mbr1.getWidth();
54363
- const h1 = mbr1.getHeight();
54364
+ for (const s2 of snapshot) {
54365
+ sumX += s2.cx;
54366
+ sumY += s2.cy;
54367
+ }
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];
54372
+ if (!this.velocities.has(s1.id)) {
54373
+ this.velocities.set(s1.id, { vx: 0, vy: 0 });
54374
+ }
54375
+ const vel = this.velocities.get(s1.id);
54364
54376
  let ax = 0;
54365
54377
  let ay = 0;
54366
- const dcx = centerX - pos1.x;
54367
- const dcy = centerY - pos1.y;
54378
+ const dcx = centerX - s1.cx;
54379
+ const dcy = centerY - s1.cy;
54368
54380
  const distCenter = Math.sqrt(dcx * dcx + dcy * dcy) + 1;
54369
54381
  ax += this.G_CENTER * dcx / distCenter;
54370
54382
  ay += this.G_CENTER * dcy / distCenter;
54371
- 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 && !EXCLUDED_ITEM_TYPES.has(other.itemType));
54372
- for (const other of nearby) {
54373
- const pos2 = other.transformation.getTranslation();
54374
- const mbr2 = other.getMbr();
54375
- const w2 = mbr2.getWidth();
54376
- const h2 = mbr2.getHeight();
54377
- const mass2 = w2 * h2;
54378
- const dx = pos2.x - pos1.x;
54379
- const dy = pos2.y - pos1.y;
54383
+ for (let j = 0;j < snapshot.length; j++) {
54384
+ if (i === j)
54385
+ continue;
54386
+ const s2 = snapshot[j];
54387
+ const dx = s2.cx - s1.cx;
54388
+ const dy = s2.cy - s1.cy;
54380
54389
  const distSq = dx * dx + dy * dy;
54381
54390
  const dist = Math.sqrt(distSq) + 0.001;
54382
- const minDist = (w1 + w2) * 0.5 + (h1 + h2) * 0.5;
54391
+ if (dist > this.MAX_DISTANCE)
54392
+ continue;
54393
+ const minDist = (s1.w + s2.w + s1.h + s2.h) * 0.25;
54383
54394
  if (dist < minDist) {
54384
54395
  const repAcc = this.REPULSION / (distSq + this.SOFTENING_SQ);
54385
54396
  ax -= repAcc * dx / dist;
54386
54397
  ay -= repAcc * dy / dist;
54387
54398
  } else {
54388
- const gravAcc = this.G * mass2 / (distSq + this.SOFTENING_SQ);
54399
+ const gravAcc = this.G * s2.mass / (distSq + this.SOFTENING_SQ);
54389
54400
  ax += gravAcc * dx / dist;
54390
54401
  ay += gravAcc * dy / dist;
54391
54402
  }
@@ -54395,7 +54406,7 @@ class GravityEngine {
54395
54406
  const moveX = vel.vx * dt;
54396
54407
  const moveY = vel.vy * dt;
54397
54408
  if (Math.abs(moveX) >= this.MIN_MOVE_PX || Math.abs(moveY) >= this.MIN_MOVE_PX) {
54398
- item.transformation.applyMatrixSilent({
54409
+ items[i].transformation.applyMatrixSilent({
54399
54410
  translateX: moveX,
54400
54411
  translateY: moveY,
54401
54412
  scaleX: 1,
package/dist/cjs/index.js CHANGED
@@ -19483,6 +19483,9 @@ class Comment {
19483
19483
  }
19484
19484
  addOnRemoveCallback(_cb) {}
19485
19485
  onRemove() {}
19486
+ highlightMbr() {}
19487
+ clearHighlightMbr() {}
19488
+ renderHoverHighlight(_context) {}
19486
19489
  render(context) {}
19487
19490
  renderHTML(documentFactory) {
19488
19491
  const div = documentFactory.createElement("comment-item");
@@ -54342,50 +54345,58 @@ class GravityEngine {
54342
54345
  const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
54343
54346
  if (items.length < 1)
54344
54347
  return;
54348
+ const snapshot = items.map((item) => {
54349
+ const pos = item.transformation.getTranslation();
54350
+ const mbr = item.getMbr();
54351
+ const w = Math.max(mbr.getWidth(), 1);
54352
+ const h2 = Math.max(mbr.getHeight(), 1);
54353
+ return {
54354
+ id: item.getId(),
54355
+ cx: pos.x + w * 0.5,
54356
+ cy: pos.y + h2 * 0.5,
54357
+ w,
54358
+ h: h2,
54359
+ mass: w * h2
54360
+ };
54361
+ });
54345
54362
  let sumX = 0;
54346
54363
  let sumY = 0;
54347
- for (const item of items) {
54348
- const pos = item.transformation.getTranslation();
54349
- sumX += pos.x;
54350
- sumY += pos.y;
54351
- }
54352
- const centerX = sumX / items.length;
54353
- const centerY = sumY / items.length;
54354
- for (const item of items) {
54355
- const id = item.getId();
54356
- if (!this.velocities.has(id)) {
54357
- this.velocities.set(id, { vx: 0, vy: 0 });
54358
- }
54359
- const vel = this.velocities.get(id);
54360
- const pos1 = item.transformation.getTranslation();
54361
- const mbr1 = item.getMbr();
54362
- const w1 = mbr1.getWidth();
54363
- const h1 = mbr1.getHeight();
54364
+ for (const s2 of snapshot) {
54365
+ sumX += s2.cx;
54366
+ sumY += s2.cy;
54367
+ }
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];
54372
+ if (!this.velocities.has(s1.id)) {
54373
+ this.velocities.set(s1.id, { vx: 0, vy: 0 });
54374
+ }
54375
+ const vel = this.velocities.get(s1.id);
54364
54376
  let ax = 0;
54365
54377
  let ay = 0;
54366
- const dcx = centerX - pos1.x;
54367
- const dcy = centerY - pos1.y;
54378
+ const dcx = centerX - s1.cx;
54379
+ const dcy = centerY - s1.cy;
54368
54380
  const distCenter = Math.sqrt(dcx * dcx + dcy * dcy) + 1;
54369
54381
  ax += this.G_CENTER * dcx / distCenter;
54370
54382
  ay += this.G_CENTER * dcy / distCenter;
54371
- 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 && !EXCLUDED_ITEM_TYPES.has(other.itemType));
54372
- for (const other of nearby) {
54373
- const pos2 = other.transformation.getTranslation();
54374
- const mbr2 = other.getMbr();
54375
- const w2 = mbr2.getWidth();
54376
- const h2 = mbr2.getHeight();
54377
- const mass2 = w2 * h2;
54378
- const dx = pos2.x - pos1.x;
54379
- const dy = pos2.y - pos1.y;
54383
+ for (let j = 0;j < snapshot.length; j++) {
54384
+ if (i === j)
54385
+ continue;
54386
+ const s2 = snapshot[j];
54387
+ const dx = s2.cx - s1.cx;
54388
+ const dy = s2.cy - s1.cy;
54380
54389
  const distSq = dx * dx + dy * dy;
54381
54390
  const dist = Math.sqrt(distSq) + 0.001;
54382
- const minDist = (w1 + w2) * 0.5 + (h1 + h2) * 0.5;
54391
+ if (dist > this.MAX_DISTANCE)
54392
+ continue;
54393
+ const minDist = (s1.w + s2.w + s1.h + s2.h) * 0.25;
54383
54394
  if (dist < minDist) {
54384
54395
  const repAcc = this.REPULSION / (distSq + this.SOFTENING_SQ);
54385
54396
  ax -= repAcc * dx / dist;
54386
54397
  ay -= repAcc * dy / dist;
54387
54398
  } else {
54388
- const gravAcc = this.G * mass2 / (distSq + this.SOFTENING_SQ);
54399
+ const gravAcc = this.G * s2.mass / (distSq + this.SOFTENING_SQ);
54389
54400
  ax += gravAcc * dx / dist;
54390
54401
  ay += gravAcc * dy / dist;
54391
54402
  }
@@ -54395,7 +54406,7 @@ class GravityEngine {
54395
54406
  const moveX = vel.vx * dt;
54396
54407
  const moveY = vel.vy * dt;
54397
54408
  if (Math.abs(moveX) >= this.MIN_MOVE_PX || Math.abs(moveY) >= this.MIN_MOVE_PX) {
54398
- item.transformation.applyMatrixSilent({
54409
+ items[i].transformation.applyMatrixSilent({
54399
54410
  translateX: moveX,
54400
54411
  translateY: moveY,
54401
54412
  scaleX: 1,
package/dist/cjs/node.js CHANGED
@@ -22022,6 +22022,9 @@ class Comment {
22022
22022
  }
22023
22023
  addOnRemoveCallback(_cb) {}
22024
22024
  onRemove() {}
22025
+ highlightMbr() {}
22026
+ clearHighlightMbr() {}
22027
+ renderHoverHighlight(_context) {}
22025
22028
  render(context) {}
22026
22029
  renderHTML(documentFactory) {
22027
22030
  const div = documentFactory.createElement("comment-item");
@@ -56815,50 +56818,58 @@ class GravityEngine {
56815
56818
  const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
56816
56819
  if (items.length < 1)
56817
56820
  return;
56821
+ const snapshot = items.map((item) => {
56822
+ const pos = item.transformation.getTranslation();
56823
+ const mbr = item.getMbr();
56824
+ const w = Math.max(mbr.getWidth(), 1);
56825
+ const h2 = Math.max(mbr.getHeight(), 1);
56826
+ return {
56827
+ id: item.getId(),
56828
+ cx: pos.x + w * 0.5,
56829
+ cy: pos.y + h2 * 0.5,
56830
+ w,
56831
+ h: h2,
56832
+ mass: w * h2
56833
+ };
56834
+ });
56818
56835
  let sumX = 0;
56819
56836
  let sumY = 0;
56820
- for (const item of items) {
56821
- const pos = item.transformation.getTranslation();
56822
- sumX += pos.x;
56823
- sumY += pos.y;
56824
- }
56825
- const centerX = sumX / items.length;
56826
- const centerY = sumY / items.length;
56827
- for (const item of items) {
56828
- const id = item.getId();
56829
- if (!this.velocities.has(id)) {
56830
- this.velocities.set(id, { vx: 0, vy: 0 });
56831
- }
56832
- const vel = this.velocities.get(id);
56833
- const pos1 = item.transformation.getTranslation();
56834
- const mbr1 = item.getMbr();
56835
- const w1 = mbr1.getWidth();
56836
- const h1 = mbr1.getHeight();
56837
+ for (const s2 of snapshot) {
56838
+ sumX += s2.cx;
56839
+ sumY += s2.cy;
56840
+ }
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];
56845
+ if (!this.velocities.has(s1.id)) {
56846
+ this.velocities.set(s1.id, { vx: 0, vy: 0 });
56847
+ }
56848
+ const vel = this.velocities.get(s1.id);
56837
56849
  let ax = 0;
56838
56850
  let ay = 0;
56839
- const dcx = centerX - pos1.x;
56840
- const dcy = centerY - pos1.y;
56851
+ const dcx = centerX - s1.cx;
56852
+ const dcy = centerY - s1.cy;
56841
56853
  const distCenter = Math.sqrt(dcx * dcx + dcy * dcy) + 1;
56842
56854
  ax += this.G_CENTER * dcx / distCenter;
56843
56855
  ay += this.G_CENTER * dcy / distCenter;
56844
- 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 && !EXCLUDED_ITEM_TYPES.has(other.itemType));
56845
- for (const other of nearby) {
56846
- const pos2 = other.transformation.getTranslation();
56847
- const mbr2 = other.getMbr();
56848
- const w2 = mbr2.getWidth();
56849
- const h2 = mbr2.getHeight();
56850
- const mass2 = w2 * h2;
56851
- const dx = pos2.x - pos1.x;
56852
- const dy = pos2.y - pos1.y;
56856
+ for (let j = 0;j < snapshot.length; j++) {
56857
+ if (i === j)
56858
+ continue;
56859
+ const s2 = snapshot[j];
56860
+ const dx = s2.cx - s1.cx;
56861
+ const dy = s2.cy - s1.cy;
56853
56862
  const distSq = dx * dx + dy * dy;
56854
56863
  const dist = Math.sqrt(distSq) + 0.001;
56855
- const minDist = (w1 + w2) * 0.5 + (h1 + h2) * 0.5;
56864
+ if (dist > this.MAX_DISTANCE)
56865
+ continue;
56866
+ const minDist = (s1.w + s2.w + s1.h + s2.h) * 0.25;
56856
56867
  if (dist < minDist) {
56857
56868
  const repAcc = this.REPULSION / (distSq + this.SOFTENING_SQ);
56858
56869
  ax -= repAcc * dx / dist;
56859
56870
  ay -= repAcc * dy / dist;
56860
56871
  } else {
56861
- const gravAcc = this.G * mass2 / (distSq + this.SOFTENING_SQ);
56872
+ const gravAcc = this.G * s2.mass / (distSq + this.SOFTENING_SQ);
56862
56873
  ax += gravAcc * dx / dist;
56863
56874
  ay += gravAcc * dy / dist;
56864
56875
  }
@@ -56868,7 +56879,7 @@ class GravityEngine {
56868
56879
  const moveX = vel.vx * dt;
56869
56880
  const moveY = vel.vy * dt;
56870
56881
  if (Math.abs(moveX) >= this.MIN_MOVE_PX || Math.abs(moveY) >= this.MIN_MOVE_PX) {
56871
- item.transformation.applyMatrixSilent({
56882
+ items[i].transformation.applyMatrixSilent({
56872
56883
  translateX: moveX,
56873
56884
  translateY: moveY,
56874
56885
  scaleX: 1,
@@ -19312,6 +19312,9 @@ class Comment {
19312
19312
  }
19313
19313
  addOnRemoveCallback(_cb) {}
19314
19314
  onRemove() {}
19315
+ highlightMbr() {}
19316
+ clearHighlightMbr() {}
19317
+ renderHoverHighlight(_context) {}
19315
19318
  render(context) {}
19316
19319
  renderHTML(documentFactory) {
19317
19320
  const div = documentFactory.createElement("comment-item");
@@ -54171,50 +54174,58 @@ class GravityEngine {
54171
54174
  const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
54172
54175
  if (items.length < 1)
54173
54176
  return;
54177
+ const snapshot = items.map((item) => {
54178
+ const pos = item.transformation.getTranslation();
54179
+ const mbr = item.getMbr();
54180
+ const w = Math.max(mbr.getWidth(), 1);
54181
+ const h2 = Math.max(mbr.getHeight(), 1);
54182
+ return {
54183
+ id: item.getId(),
54184
+ cx: pos.x + w * 0.5,
54185
+ cy: pos.y + h2 * 0.5,
54186
+ w,
54187
+ h: h2,
54188
+ mass: w * h2
54189
+ };
54190
+ });
54174
54191
  let sumX = 0;
54175
54192
  let sumY = 0;
54176
- for (const item of items) {
54177
- const pos = item.transformation.getTranslation();
54178
- sumX += pos.x;
54179
- sumY += pos.y;
54180
- }
54181
- const centerX = sumX / items.length;
54182
- const centerY = sumY / items.length;
54183
- for (const item of items) {
54184
- const id = item.getId();
54185
- if (!this.velocities.has(id)) {
54186
- this.velocities.set(id, { vx: 0, vy: 0 });
54187
- }
54188
- const vel = this.velocities.get(id);
54189
- const pos1 = item.transformation.getTranslation();
54190
- const mbr1 = item.getMbr();
54191
- const w1 = mbr1.getWidth();
54192
- const h1 = mbr1.getHeight();
54193
+ for (const s2 of snapshot) {
54194
+ sumX += s2.cx;
54195
+ sumY += s2.cy;
54196
+ }
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];
54201
+ if (!this.velocities.has(s1.id)) {
54202
+ this.velocities.set(s1.id, { vx: 0, vy: 0 });
54203
+ }
54204
+ const vel = this.velocities.get(s1.id);
54193
54205
  let ax = 0;
54194
54206
  let ay = 0;
54195
- const dcx = centerX - pos1.x;
54196
- const dcy = centerY - pos1.y;
54207
+ const dcx = centerX - s1.cx;
54208
+ const dcy = centerY - s1.cy;
54197
54209
  const distCenter = Math.sqrt(dcx * dcx + dcy * dcy) + 1;
54198
54210
  ax += this.G_CENTER * dcx / distCenter;
54199
54211
  ay += this.G_CENTER * dcy / distCenter;
54200
- 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 && !EXCLUDED_ITEM_TYPES.has(other.itemType));
54201
- for (const other of nearby) {
54202
- const pos2 = other.transformation.getTranslation();
54203
- const mbr2 = other.getMbr();
54204
- const w2 = mbr2.getWidth();
54205
- const h2 = mbr2.getHeight();
54206
- const mass2 = w2 * h2;
54207
- const dx = pos2.x - pos1.x;
54208
- const dy = pos2.y - pos1.y;
54212
+ for (let j = 0;j < snapshot.length; j++) {
54213
+ if (i === j)
54214
+ continue;
54215
+ const s2 = snapshot[j];
54216
+ const dx = s2.cx - s1.cx;
54217
+ const dy = s2.cy - s1.cy;
54209
54218
  const distSq = dx * dx + dy * dy;
54210
54219
  const dist = Math.sqrt(distSq) + 0.001;
54211
- const minDist = (w1 + w2) * 0.5 + (h1 + h2) * 0.5;
54220
+ if (dist > this.MAX_DISTANCE)
54221
+ continue;
54222
+ const minDist = (s1.w + s2.w + s1.h + s2.h) * 0.25;
54212
54223
  if (dist < minDist) {
54213
54224
  const repAcc = this.REPULSION / (distSq + this.SOFTENING_SQ);
54214
54225
  ax -= repAcc * dx / dist;
54215
54226
  ay -= repAcc * dy / dist;
54216
54227
  } else {
54217
- const gravAcc = this.G * mass2 / (distSq + this.SOFTENING_SQ);
54228
+ const gravAcc = this.G * s2.mass / (distSq + this.SOFTENING_SQ);
54218
54229
  ax += gravAcc * dx / dist;
54219
54230
  ay += gravAcc * dy / dist;
54220
54231
  }
@@ -54224,7 +54235,7 @@ class GravityEngine {
54224
54235
  const moveX = vel.vx * dt;
54225
54236
  const moveY = vel.vy * dt;
54226
54237
  if (Math.abs(moveX) >= this.MIN_MOVE_PX || Math.abs(moveY) >= this.MIN_MOVE_PX) {
54227
- item.transformation.applyMatrixSilent({
54238
+ items[i].transformation.applyMatrixSilent({
54228
54239
  translateX: moveX,
54229
54240
  translateY: moveY,
54230
54241
  scaleX: 1,
package/dist/esm/index.js CHANGED
@@ -19305,6 +19305,9 @@ class Comment {
19305
19305
  }
19306
19306
  addOnRemoveCallback(_cb) {}
19307
19307
  onRemove() {}
19308
+ highlightMbr() {}
19309
+ clearHighlightMbr() {}
19310
+ renderHoverHighlight(_context) {}
19308
19311
  render(context) {}
19309
19312
  renderHTML(documentFactory) {
19310
19313
  const div = documentFactory.createElement("comment-item");
@@ -54164,50 +54167,58 @@ class GravityEngine {
54164
54167
  const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
54165
54168
  if (items.length < 1)
54166
54169
  return;
54170
+ const snapshot = items.map((item) => {
54171
+ const pos = item.transformation.getTranslation();
54172
+ const mbr = item.getMbr();
54173
+ const w = Math.max(mbr.getWidth(), 1);
54174
+ const h2 = Math.max(mbr.getHeight(), 1);
54175
+ return {
54176
+ id: item.getId(),
54177
+ cx: pos.x + w * 0.5,
54178
+ cy: pos.y + h2 * 0.5,
54179
+ w,
54180
+ h: h2,
54181
+ mass: w * h2
54182
+ };
54183
+ });
54167
54184
  let sumX = 0;
54168
54185
  let sumY = 0;
54169
- for (const item of items) {
54170
- const pos = item.transformation.getTranslation();
54171
- sumX += pos.x;
54172
- sumY += pos.y;
54173
- }
54174
- const centerX = sumX / items.length;
54175
- const centerY = sumY / items.length;
54176
- for (const item of items) {
54177
- const id = item.getId();
54178
- if (!this.velocities.has(id)) {
54179
- this.velocities.set(id, { vx: 0, vy: 0 });
54180
- }
54181
- const vel = this.velocities.get(id);
54182
- const pos1 = item.transformation.getTranslation();
54183
- const mbr1 = item.getMbr();
54184
- const w1 = mbr1.getWidth();
54185
- const h1 = mbr1.getHeight();
54186
+ for (const s2 of snapshot) {
54187
+ sumX += s2.cx;
54188
+ sumY += s2.cy;
54189
+ }
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];
54194
+ if (!this.velocities.has(s1.id)) {
54195
+ this.velocities.set(s1.id, { vx: 0, vy: 0 });
54196
+ }
54197
+ const vel = this.velocities.get(s1.id);
54186
54198
  let ax = 0;
54187
54199
  let ay = 0;
54188
- const dcx = centerX - pos1.x;
54189
- const dcy = centerY - pos1.y;
54200
+ const dcx = centerX - s1.cx;
54201
+ const dcy = centerY - s1.cy;
54190
54202
  const distCenter = Math.sqrt(dcx * dcx + dcy * dcy) + 1;
54191
54203
  ax += this.G_CENTER * dcx / distCenter;
54192
54204
  ay += this.G_CENTER * dcy / distCenter;
54193
- 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 && !EXCLUDED_ITEM_TYPES.has(other.itemType));
54194
- for (const other of nearby) {
54195
- const pos2 = other.transformation.getTranslation();
54196
- const mbr2 = other.getMbr();
54197
- const w2 = mbr2.getWidth();
54198
- const h2 = mbr2.getHeight();
54199
- const mass2 = w2 * h2;
54200
- const dx = pos2.x - pos1.x;
54201
- const dy = pos2.y - pos1.y;
54205
+ for (let j = 0;j < snapshot.length; j++) {
54206
+ if (i === j)
54207
+ continue;
54208
+ const s2 = snapshot[j];
54209
+ const dx = s2.cx - s1.cx;
54210
+ const dy = s2.cy - s1.cy;
54202
54211
  const distSq = dx * dx + dy * dy;
54203
54212
  const dist = Math.sqrt(distSq) + 0.001;
54204
- const minDist = (w1 + w2) * 0.5 + (h1 + h2) * 0.5;
54213
+ if (dist > this.MAX_DISTANCE)
54214
+ continue;
54215
+ const minDist = (s1.w + s2.w + s1.h + s2.h) * 0.25;
54205
54216
  if (dist < minDist) {
54206
54217
  const repAcc = this.REPULSION / (distSq + this.SOFTENING_SQ);
54207
54218
  ax -= repAcc * dx / dist;
54208
54219
  ay -= repAcc * dy / dist;
54209
54220
  } else {
54210
- const gravAcc = this.G * mass2 / (distSq + this.SOFTENING_SQ);
54221
+ const gravAcc = this.G * s2.mass / (distSq + this.SOFTENING_SQ);
54211
54222
  ax += gravAcc * dx / dist;
54212
54223
  ay += gravAcc * dy / dist;
54213
54224
  }
@@ -54217,7 +54228,7 @@ class GravityEngine {
54217
54228
  const moveX = vel.vx * dt;
54218
54229
  const moveY = vel.vy * dt;
54219
54230
  if (Math.abs(moveX) >= this.MIN_MOVE_PX || Math.abs(moveY) >= this.MIN_MOVE_PX) {
54220
- item.transformation.applyMatrixSilent({
54231
+ items[i].transformation.applyMatrixSilent({
54221
54232
  translateX: moveX,
54222
54233
  translateY: moveY,
54223
54234
  scaleX: 1,
package/dist/esm/node.js CHANGED
@@ -21839,6 +21839,9 @@ class Comment {
21839
21839
  }
21840
21840
  addOnRemoveCallback(_cb) {}
21841
21841
  onRemove() {}
21842
+ highlightMbr() {}
21843
+ clearHighlightMbr() {}
21844
+ renderHoverHighlight(_context) {}
21842
21845
  render(context) {}
21843
21846
  renderHTML(documentFactory) {
21844
21847
  const div = documentFactory.createElement("comment-item");
@@ -56632,50 +56635,58 @@ class GravityEngine {
56632
56635
  const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
56633
56636
  if (items.length < 1)
56634
56637
  return;
56638
+ const snapshot = items.map((item) => {
56639
+ const pos = item.transformation.getTranslation();
56640
+ const mbr = item.getMbr();
56641
+ const w = Math.max(mbr.getWidth(), 1);
56642
+ const h2 = Math.max(mbr.getHeight(), 1);
56643
+ return {
56644
+ id: item.getId(),
56645
+ cx: pos.x + w * 0.5,
56646
+ cy: pos.y + h2 * 0.5,
56647
+ w,
56648
+ h: h2,
56649
+ mass: w * h2
56650
+ };
56651
+ });
56635
56652
  let sumX = 0;
56636
56653
  let sumY = 0;
56637
- for (const item of items) {
56638
- const pos = item.transformation.getTranslation();
56639
- sumX += pos.x;
56640
- sumY += pos.y;
56641
- }
56642
- const centerX = sumX / items.length;
56643
- const centerY = sumY / items.length;
56644
- for (const item of items) {
56645
- const id = item.getId();
56646
- if (!this.velocities.has(id)) {
56647
- this.velocities.set(id, { vx: 0, vy: 0 });
56648
- }
56649
- const vel = this.velocities.get(id);
56650
- const pos1 = item.transformation.getTranslation();
56651
- const mbr1 = item.getMbr();
56652
- const w1 = mbr1.getWidth();
56653
- const h1 = mbr1.getHeight();
56654
+ for (const s2 of snapshot) {
56655
+ sumX += s2.cx;
56656
+ sumY += s2.cy;
56657
+ }
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];
56662
+ if (!this.velocities.has(s1.id)) {
56663
+ this.velocities.set(s1.id, { vx: 0, vy: 0 });
56664
+ }
56665
+ const vel = this.velocities.get(s1.id);
56654
56666
  let ax = 0;
56655
56667
  let ay = 0;
56656
- const dcx = centerX - pos1.x;
56657
- const dcy = centerY - pos1.y;
56668
+ const dcx = centerX - s1.cx;
56669
+ const dcy = centerY - s1.cy;
56658
56670
  const distCenter = Math.sqrt(dcx * dcx + dcy * dcy) + 1;
56659
56671
  ax += this.G_CENTER * dcx / distCenter;
56660
56672
  ay += this.G_CENTER * dcy / distCenter;
56661
- 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 && !EXCLUDED_ITEM_TYPES.has(other.itemType));
56662
- for (const other of nearby) {
56663
- const pos2 = other.transformation.getTranslation();
56664
- const mbr2 = other.getMbr();
56665
- const w2 = mbr2.getWidth();
56666
- const h2 = mbr2.getHeight();
56667
- const mass2 = w2 * h2;
56668
- const dx = pos2.x - pos1.x;
56669
- const dy = pos2.y - pos1.y;
56673
+ for (let j = 0;j < snapshot.length; j++) {
56674
+ if (i === j)
56675
+ continue;
56676
+ const s2 = snapshot[j];
56677
+ const dx = s2.cx - s1.cx;
56678
+ const dy = s2.cy - s1.cy;
56670
56679
  const distSq = dx * dx + dy * dy;
56671
56680
  const dist = Math.sqrt(distSq) + 0.001;
56672
- const minDist = (w1 + w2) * 0.5 + (h1 + h2) * 0.5;
56681
+ if (dist > this.MAX_DISTANCE)
56682
+ continue;
56683
+ const minDist = (s1.w + s2.w + s1.h + s2.h) * 0.25;
56673
56684
  if (dist < minDist) {
56674
56685
  const repAcc = this.REPULSION / (distSq + this.SOFTENING_SQ);
56675
56686
  ax -= repAcc * dx / dist;
56676
56687
  ay -= repAcc * dy / dist;
56677
56688
  } else {
56678
- const gravAcc = this.G * mass2 / (distSq + this.SOFTENING_SQ);
56689
+ const gravAcc = this.G * s2.mass / (distSq + this.SOFTENING_SQ);
56679
56690
  ax += gravAcc * dx / dist;
56680
56691
  ay += gravAcc * dy / dist;
56681
56692
  }
@@ -56685,7 +56696,7 @@ class GravityEngine {
56685
56696
  const moveX = vel.vx * dt;
56686
56697
  const moveY = vel.vy * dt;
56687
56698
  if (Math.abs(moveX) >= this.MIN_MOVE_PX || Math.abs(moveY) >= this.MIN_MOVE_PX) {
56688
- item.transformation.applyMatrixSilent({
56699
+ items[i].transformation.applyMatrixSilent({
56689
56700
  translateX: moveX,
56690
56701
  translateY: moveY,
56691
56702
  scaleX: 1,
@@ -104,6 +104,9 @@ export declare class Comment implements Geometry {
104
104
  handleNesting(_item: unknown): boolean;
105
105
  addOnRemoveCallback(_cb: () => void): void;
106
106
  onRemove(): void;
107
+ highlightMbr(): void;
108
+ clearHighlightMbr(): void;
109
+ renderHoverHighlight(_context: DrawingContext): void;
107
110
  render(context: DrawingContext): void;
108
111
  renderHTML(documentFactory: DocumentFactory): HTMLElement;
109
112
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "microboard-temp",
3
- "version": "0.12.2",
3
+ "version": "0.12.4",
4
4
  "description": "A flexible interactive whiteboard library",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",