microboard-temp 0.12.0 → 0.12.2
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/browser.js +72 -45
- package/dist/cjs/index.js +72 -45
- package/dist/cjs/node.js +72 -45
- package/dist/esm/browser.js +72 -45
- package/dist/esm/index.js +72 -45
- package/dist/esm/node.js +72 -45
- package/dist/types/Gravity/GravityEngine.d.ts +4 -2
- package/dist/types/Items/AINode/AINode.d.ts +1 -0
- package/dist/types/Items/BaseItem/BaseItem.d.ts +1 -0
- package/dist/types/Items/Comment/Comment.d.ts +1 -0
- package/dist/types/Items/RichText/RichText.d.ts +1 -2
- package/dist/types/Items/Shape/Shape.d.ts +1 -0
- package/dist/types/Items/Sticker/Sticker.d.ts +1 -0
- package/package.json +1 -1
package/dist/cjs/browser.js
CHANGED
|
@@ -18215,9 +18215,9 @@ class Transformation {
|
|
|
18215
18215
|
}, timeStamp);
|
|
18216
18216
|
}
|
|
18217
18217
|
applyMatrixSilent(matrixData) {
|
|
18218
|
-
this.previous = this.
|
|
18219
|
-
this.
|
|
18220
|
-
this.
|
|
18218
|
+
this.previous = this._matrix.copy();
|
|
18219
|
+
this._matrix.scale(matrixData.scaleX, matrixData.scaleY);
|
|
18220
|
+
this._matrix.translate(matrixData.translateX, matrixData.translateY);
|
|
18221
18221
|
this.subject.publish(this, {
|
|
18222
18222
|
class: "Transformation",
|
|
18223
18223
|
method: "applyMatrix",
|
|
@@ -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));
|
|
@@ -22200,7 +22205,6 @@ class RichText extends BaseItem {
|
|
|
22200
22205
|
_onLimitReached = () => {};
|
|
22201
22206
|
shrinkWidth = false;
|
|
22202
22207
|
prevMbr = null;
|
|
22203
|
-
worldMatrixGetter;
|
|
22204
22208
|
rtCounter = 0;
|
|
22205
22209
|
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
22210
|
super(board, id);
|
|
@@ -22423,18 +22427,7 @@ class RichText extends BaseItem {
|
|
|
22423
22427
|
top = container.top;
|
|
22424
22428
|
}
|
|
22425
22429
|
const point3 = new Point(left, top);
|
|
22426
|
-
|
|
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
|
-
}
|
|
22430
|
+
this.getParentWorldMatrix().apply(point3);
|
|
22438
22431
|
return {
|
|
22439
22432
|
point: point3,
|
|
22440
22433
|
width,
|
|
@@ -36538,6 +36531,11 @@ class AINode extends BaseItem {
|
|
|
36538
36531
|
this.linkTo.setId(id);
|
|
36539
36532
|
return this;
|
|
36540
36533
|
}
|
|
36534
|
+
onParentChanged(newParent) {
|
|
36535
|
+
if (this.text) {
|
|
36536
|
+
this.text.parent = newParent;
|
|
36537
|
+
}
|
|
36538
|
+
}
|
|
36541
36539
|
getId() {
|
|
36542
36540
|
return this.id;
|
|
36543
36541
|
}
|
|
@@ -40062,6 +40060,11 @@ class Shape extends BaseItem {
|
|
|
40062
40060
|
this.linkTo.setId(id);
|
|
40063
40061
|
return this;
|
|
40064
40062
|
}
|
|
40063
|
+
onParentChanged(newParent) {
|
|
40064
|
+
if (this.text) {
|
|
40065
|
+
this.text.parent = newParent;
|
|
40066
|
+
}
|
|
40067
|
+
}
|
|
40065
40068
|
getId() {
|
|
40066
40069
|
return this.id;
|
|
40067
40070
|
}
|
|
@@ -40594,6 +40597,11 @@ class Sticker extends BaseItem {
|
|
|
40594
40597
|
this.transformation.setId(id);
|
|
40595
40598
|
return this;
|
|
40596
40599
|
}
|
|
40600
|
+
onParentChanged(newParent) {
|
|
40601
|
+
if (this.text) {
|
|
40602
|
+
this.text.parent = newParent;
|
|
40603
|
+
}
|
|
40604
|
+
}
|
|
40597
40605
|
getId() {
|
|
40598
40606
|
return this.id;
|
|
40599
40607
|
}
|
|
@@ -41121,15 +41129,6 @@ class Frame2 extends BaseItem {
|
|
|
41121
41129
|
y: translateY
|
|
41122
41130
|
}, timeStamp);
|
|
41123
41131
|
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
41132
|
this.setLastFrameScale();
|
|
41134
41133
|
res.mbr = this.getMbr();
|
|
41135
41134
|
return res;
|
|
@@ -54297,14 +54296,18 @@ class BoardSelection {
|
|
|
54297
54296
|
}
|
|
54298
54297
|
}
|
|
54299
54298
|
// src/Gravity/GravityEngine.ts
|
|
54299
|
+
var EXCLUDED_ITEM_TYPES = new Set(["Comment", "Connector"]);
|
|
54300
|
+
|
|
54300
54301
|
class GravityEngine {
|
|
54301
54302
|
board;
|
|
54302
54303
|
velocities = new Map;
|
|
54303
54304
|
tickTimer = null;
|
|
54304
54305
|
syncTimer = null;
|
|
54305
54306
|
lastSyncedPositions = new Map;
|
|
54306
|
-
G =
|
|
54307
|
-
|
|
54307
|
+
G = 80;
|
|
54308
|
+
G_CENTER = 120;
|
|
54309
|
+
DAMPING = 0.92;
|
|
54310
|
+
REPULSION = 60000;
|
|
54308
54311
|
TICK_MS = 33;
|
|
54309
54312
|
SYNC_MS = 300;
|
|
54310
54313
|
MAX_DISTANCE = 3000;
|
|
@@ -54336,9 +54339,18 @@ class GravityEngine {
|
|
|
54336
54339
|
}
|
|
54337
54340
|
tick() {
|
|
54338
54341
|
const dt = this.TICK_MS / 1000;
|
|
54339
|
-
const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked);
|
|
54340
|
-
if (items.length <
|
|
54342
|
+
const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
|
|
54343
|
+
if (items.length < 1)
|
|
54341
54344
|
return;
|
|
54345
|
+
let sumX = 0;
|
|
54346
|
+
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;
|
|
54342
54354
|
for (const item of items) {
|
|
54343
54355
|
const id = item.getId();
|
|
54344
54356
|
if (!this.velocities.has(id)) {
|
|
@@ -54347,30 +54359,45 @@ class GravityEngine {
|
|
|
54347
54359
|
const vel = this.velocities.get(id);
|
|
54348
54360
|
const pos1 = item.transformation.getTranslation();
|
|
54349
54361
|
const mbr1 = item.getMbr();
|
|
54350
|
-
const
|
|
54351
|
-
const
|
|
54362
|
+
const w1 = mbr1.getWidth();
|
|
54363
|
+
const h1 = mbr1.getHeight();
|
|
54352
54364
|
let ax = 0;
|
|
54353
54365
|
let ay = 0;
|
|
54366
|
+
const dcx = centerX - pos1.x;
|
|
54367
|
+
const dcy = centerY - pos1.y;
|
|
54368
|
+
const distCenter = Math.sqrt(dcx * dcx + dcy * dcy) + 1;
|
|
54369
|
+
ax += this.G_CENTER * dcx / distCenter;
|
|
54370
|
+
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));
|
|
54354
54372
|
for (const other of nearby) {
|
|
54355
54373
|
const pos2 = other.transformation.getTranslation();
|
|
54356
54374
|
const mbr2 = other.getMbr();
|
|
54357
|
-
const
|
|
54358
|
-
const
|
|
54359
|
-
const
|
|
54360
|
-
const
|
|
54361
|
-
const
|
|
54362
|
-
const
|
|
54363
|
-
|
|
54364
|
-
|
|
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;
|
|
54380
|
+
const distSq = dx * dx + dy * dy;
|
|
54381
|
+
const dist = Math.sqrt(distSq) + 0.001;
|
|
54382
|
+
const minDist = (w1 + w2) * 0.5 + (h1 + h2) * 0.5;
|
|
54383
|
+
if (dist < minDist) {
|
|
54384
|
+
const repAcc = this.REPULSION / (distSq + this.SOFTENING_SQ);
|
|
54385
|
+
ax -= repAcc * dx / dist;
|
|
54386
|
+
ay -= repAcc * dy / dist;
|
|
54387
|
+
} else {
|
|
54388
|
+
const gravAcc = this.G * mass2 / (distSq + this.SOFTENING_SQ);
|
|
54389
|
+
ax += gravAcc * dx / dist;
|
|
54390
|
+
ay += gravAcc * dy / dist;
|
|
54391
|
+
}
|
|
54365
54392
|
}
|
|
54366
54393
|
vel.vx = (vel.vx + ax * dt) * this.DAMPING;
|
|
54367
54394
|
vel.vy = (vel.vy + ay * dt) * this.DAMPING;
|
|
54368
|
-
const
|
|
54369
|
-
const
|
|
54370
|
-
if (Math.abs(
|
|
54395
|
+
const moveX = vel.vx * dt;
|
|
54396
|
+
const moveY = vel.vy * dt;
|
|
54397
|
+
if (Math.abs(moveX) >= this.MIN_MOVE_PX || Math.abs(moveY) >= this.MIN_MOVE_PX) {
|
|
54371
54398
|
item.transformation.applyMatrixSilent({
|
|
54372
|
-
translateX:
|
|
54373
|
-
translateY:
|
|
54399
|
+
translateX: moveX,
|
|
54400
|
+
translateY: moveY,
|
|
54374
54401
|
scaleX: 1,
|
|
54375
54402
|
scaleY: 1,
|
|
54376
54403
|
shearX: 0,
|
|
@@ -54380,7 +54407,7 @@ class GravityEngine {
|
|
|
54380
54407
|
}
|
|
54381
54408
|
}
|
|
54382
54409
|
syncPositions() {
|
|
54383
|
-
const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked);
|
|
54410
|
+
const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
|
|
54384
54411
|
if (items.length === 0)
|
|
54385
54412
|
return;
|
|
54386
54413
|
const movedItems = items.map((item) => {
|
package/dist/cjs/index.js
CHANGED
|
@@ -18215,9 +18215,9 @@ class Transformation {
|
|
|
18215
18215
|
}, timeStamp);
|
|
18216
18216
|
}
|
|
18217
18217
|
applyMatrixSilent(matrixData) {
|
|
18218
|
-
this.previous = this.
|
|
18219
|
-
this.
|
|
18220
|
-
this.
|
|
18218
|
+
this.previous = this._matrix.copy();
|
|
18219
|
+
this._matrix.scale(matrixData.scaleX, matrixData.scaleY);
|
|
18220
|
+
this._matrix.translate(matrixData.translateX, matrixData.translateY);
|
|
18221
18221
|
this.subject.publish(this, {
|
|
18222
18222
|
class: "Transformation",
|
|
18223
18223
|
method: "applyMatrix",
|
|
@@ -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));
|
|
@@ -22200,7 +22205,6 @@ class RichText extends BaseItem {
|
|
|
22200
22205
|
_onLimitReached = () => {};
|
|
22201
22206
|
shrinkWidth = false;
|
|
22202
22207
|
prevMbr = null;
|
|
22203
|
-
worldMatrixGetter;
|
|
22204
22208
|
rtCounter = 0;
|
|
22205
22209
|
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
22210
|
super(board, id);
|
|
@@ -22423,18 +22427,7 @@ class RichText extends BaseItem {
|
|
|
22423
22427
|
top = container.top;
|
|
22424
22428
|
}
|
|
22425
22429
|
const point3 = new Point(left, top);
|
|
22426
|
-
|
|
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
|
-
}
|
|
22430
|
+
this.getParentWorldMatrix().apply(point3);
|
|
22438
22431
|
return {
|
|
22439
22432
|
point: point3,
|
|
22440
22433
|
width,
|
|
@@ -36538,6 +36531,11 @@ class AINode extends BaseItem {
|
|
|
36538
36531
|
this.linkTo.setId(id);
|
|
36539
36532
|
return this;
|
|
36540
36533
|
}
|
|
36534
|
+
onParentChanged(newParent) {
|
|
36535
|
+
if (this.text) {
|
|
36536
|
+
this.text.parent = newParent;
|
|
36537
|
+
}
|
|
36538
|
+
}
|
|
36541
36539
|
getId() {
|
|
36542
36540
|
return this.id;
|
|
36543
36541
|
}
|
|
@@ -40062,6 +40060,11 @@ class Shape extends BaseItem {
|
|
|
40062
40060
|
this.linkTo.setId(id);
|
|
40063
40061
|
return this;
|
|
40064
40062
|
}
|
|
40063
|
+
onParentChanged(newParent) {
|
|
40064
|
+
if (this.text) {
|
|
40065
|
+
this.text.parent = newParent;
|
|
40066
|
+
}
|
|
40067
|
+
}
|
|
40065
40068
|
getId() {
|
|
40066
40069
|
return this.id;
|
|
40067
40070
|
}
|
|
@@ -40594,6 +40597,11 @@ class Sticker extends BaseItem {
|
|
|
40594
40597
|
this.transformation.setId(id);
|
|
40595
40598
|
return this;
|
|
40596
40599
|
}
|
|
40600
|
+
onParentChanged(newParent) {
|
|
40601
|
+
if (this.text) {
|
|
40602
|
+
this.text.parent = newParent;
|
|
40603
|
+
}
|
|
40604
|
+
}
|
|
40597
40605
|
getId() {
|
|
40598
40606
|
return this.id;
|
|
40599
40607
|
}
|
|
@@ -41121,15 +41129,6 @@ class Frame2 extends BaseItem {
|
|
|
41121
41129
|
y: translateY
|
|
41122
41130
|
}, timeStamp);
|
|
41123
41131
|
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
41132
|
this.setLastFrameScale();
|
|
41134
41133
|
res.mbr = this.getMbr();
|
|
41135
41134
|
return res;
|
|
@@ -54297,14 +54296,18 @@ class BoardSelection {
|
|
|
54297
54296
|
}
|
|
54298
54297
|
}
|
|
54299
54298
|
// src/Gravity/GravityEngine.ts
|
|
54299
|
+
var EXCLUDED_ITEM_TYPES = new Set(["Comment", "Connector"]);
|
|
54300
|
+
|
|
54300
54301
|
class GravityEngine {
|
|
54301
54302
|
board;
|
|
54302
54303
|
velocities = new Map;
|
|
54303
54304
|
tickTimer = null;
|
|
54304
54305
|
syncTimer = null;
|
|
54305
54306
|
lastSyncedPositions = new Map;
|
|
54306
|
-
G =
|
|
54307
|
-
|
|
54307
|
+
G = 80;
|
|
54308
|
+
G_CENTER = 120;
|
|
54309
|
+
DAMPING = 0.92;
|
|
54310
|
+
REPULSION = 60000;
|
|
54308
54311
|
TICK_MS = 33;
|
|
54309
54312
|
SYNC_MS = 300;
|
|
54310
54313
|
MAX_DISTANCE = 3000;
|
|
@@ -54336,9 +54339,18 @@ class GravityEngine {
|
|
|
54336
54339
|
}
|
|
54337
54340
|
tick() {
|
|
54338
54341
|
const dt = this.TICK_MS / 1000;
|
|
54339
|
-
const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked);
|
|
54340
|
-
if (items.length <
|
|
54342
|
+
const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
|
|
54343
|
+
if (items.length < 1)
|
|
54341
54344
|
return;
|
|
54345
|
+
let sumX = 0;
|
|
54346
|
+
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;
|
|
54342
54354
|
for (const item of items) {
|
|
54343
54355
|
const id = item.getId();
|
|
54344
54356
|
if (!this.velocities.has(id)) {
|
|
@@ -54347,30 +54359,45 @@ class GravityEngine {
|
|
|
54347
54359
|
const vel = this.velocities.get(id);
|
|
54348
54360
|
const pos1 = item.transformation.getTranslation();
|
|
54349
54361
|
const mbr1 = item.getMbr();
|
|
54350
|
-
const
|
|
54351
|
-
const
|
|
54362
|
+
const w1 = mbr1.getWidth();
|
|
54363
|
+
const h1 = mbr1.getHeight();
|
|
54352
54364
|
let ax = 0;
|
|
54353
54365
|
let ay = 0;
|
|
54366
|
+
const dcx = centerX - pos1.x;
|
|
54367
|
+
const dcy = centerY - pos1.y;
|
|
54368
|
+
const distCenter = Math.sqrt(dcx * dcx + dcy * dcy) + 1;
|
|
54369
|
+
ax += this.G_CENTER * dcx / distCenter;
|
|
54370
|
+
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));
|
|
54354
54372
|
for (const other of nearby) {
|
|
54355
54373
|
const pos2 = other.transformation.getTranslation();
|
|
54356
54374
|
const mbr2 = other.getMbr();
|
|
54357
|
-
const
|
|
54358
|
-
const
|
|
54359
|
-
const
|
|
54360
|
-
const
|
|
54361
|
-
const
|
|
54362
|
-
const
|
|
54363
|
-
|
|
54364
|
-
|
|
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;
|
|
54380
|
+
const distSq = dx * dx + dy * dy;
|
|
54381
|
+
const dist = Math.sqrt(distSq) + 0.001;
|
|
54382
|
+
const minDist = (w1 + w2) * 0.5 + (h1 + h2) * 0.5;
|
|
54383
|
+
if (dist < minDist) {
|
|
54384
|
+
const repAcc = this.REPULSION / (distSq + this.SOFTENING_SQ);
|
|
54385
|
+
ax -= repAcc * dx / dist;
|
|
54386
|
+
ay -= repAcc * dy / dist;
|
|
54387
|
+
} else {
|
|
54388
|
+
const gravAcc = this.G * mass2 / (distSq + this.SOFTENING_SQ);
|
|
54389
|
+
ax += gravAcc * dx / dist;
|
|
54390
|
+
ay += gravAcc * dy / dist;
|
|
54391
|
+
}
|
|
54365
54392
|
}
|
|
54366
54393
|
vel.vx = (vel.vx + ax * dt) * this.DAMPING;
|
|
54367
54394
|
vel.vy = (vel.vy + ay * dt) * this.DAMPING;
|
|
54368
|
-
const
|
|
54369
|
-
const
|
|
54370
|
-
if (Math.abs(
|
|
54395
|
+
const moveX = vel.vx * dt;
|
|
54396
|
+
const moveY = vel.vy * dt;
|
|
54397
|
+
if (Math.abs(moveX) >= this.MIN_MOVE_PX || Math.abs(moveY) >= this.MIN_MOVE_PX) {
|
|
54371
54398
|
item.transformation.applyMatrixSilent({
|
|
54372
|
-
translateX:
|
|
54373
|
-
translateY:
|
|
54399
|
+
translateX: moveX,
|
|
54400
|
+
translateY: moveY,
|
|
54374
54401
|
scaleX: 1,
|
|
54375
54402
|
scaleY: 1,
|
|
54376
54403
|
shearX: 0,
|
|
@@ -54380,7 +54407,7 @@ class GravityEngine {
|
|
|
54380
54407
|
}
|
|
54381
54408
|
}
|
|
54382
54409
|
syncPositions() {
|
|
54383
|
-
const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked);
|
|
54410
|
+
const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
|
|
54384
54411
|
if (items.length === 0)
|
|
54385
54412
|
return;
|
|
54386
54413
|
const movedItems = items.map((item) => {
|
package/dist/cjs/node.js
CHANGED
|
@@ -20755,9 +20755,9 @@ class Transformation {
|
|
|
20755
20755
|
}, timeStamp);
|
|
20756
20756
|
}
|
|
20757
20757
|
applyMatrixSilent(matrixData) {
|
|
20758
|
-
this.previous = this.
|
|
20759
|
-
this.
|
|
20760
|
-
this.
|
|
20758
|
+
this.previous = this._matrix.copy();
|
|
20759
|
+
this._matrix.scale(matrixData.scaleX, matrixData.scaleY);
|
|
20760
|
+
this._matrix.translate(matrixData.translateX, matrixData.translateY);
|
|
20761
20761
|
this.subject.publish(this, {
|
|
20762
20762
|
class: "Transformation",
|
|
20763
20763
|
method: "applyMatrix",
|
|
@@ -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));
|
|
@@ -24672,7 +24677,6 @@ class RichText extends BaseItem {
|
|
|
24672
24677
|
_onLimitReached = () => {};
|
|
24673
24678
|
shrinkWidth = false;
|
|
24674
24679
|
prevMbr = null;
|
|
24675
|
-
worldMatrixGetter;
|
|
24676
24680
|
rtCounter = 0;
|
|
24677
24681
|
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
24682
|
super(board, id);
|
|
@@ -24895,18 +24899,7 @@ class RichText extends BaseItem {
|
|
|
24895
24899
|
top = container.top;
|
|
24896
24900
|
}
|
|
24897
24901
|
const point3 = new Point(left, top);
|
|
24898
|
-
|
|
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
|
-
}
|
|
24902
|
+
this.getParentWorldMatrix().apply(point3);
|
|
24910
24903
|
return {
|
|
24911
24904
|
point: point3,
|
|
24912
24905
|
width,
|
|
@@ -39011,6 +39004,11 @@ class AINode extends BaseItem {
|
|
|
39011
39004
|
this.linkTo.setId(id);
|
|
39012
39005
|
return this;
|
|
39013
39006
|
}
|
|
39007
|
+
onParentChanged(newParent) {
|
|
39008
|
+
if (this.text) {
|
|
39009
|
+
this.text.parent = newParent;
|
|
39010
|
+
}
|
|
39011
|
+
}
|
|
39014
39012
|
getId() {
|
|
39015
39013
|
return this.id;
|
|
39016
39014
|
}
|
|
@@ -42535,6 +42533,11 @@ class Shape extends BaseItem {
|
|
|
42535
42533
|
this.linkTo.setId(id);
|
|
42536
42534
|
return this;
|
|
42537
42535
|
}
|
|
42536
|
+
onParentChanged(newParent) {
|
|
42537
|
+
if (this.text) {
|
|
42538
|
+
this.text.parent = newParent;
|
|
42539
|
+
}
|
|
42540
|
+
}
|
|
42538
42541
|
getId() {
|
|
42539
42542
|
return this.id;
|
|
42540
42543
|
}
|
|
@@ -43067,6 +43070,11 @@ class Sticker extends BaseItem {
|
|
|
43067
43070
|
this.transformation.setId(id);
|
|
43068
43071
|
return this;
|
|
43069
43072
|
}
|
|
43073
|
+
onParentChanged(newParent) {
|
|
43074
|
+
if (this.text) {
|
|
43075
|
+
this.text.parent = newParent;
|
|
43076
|
+
}
|
|
43077
|
+
}
|
|
43070
43078
|
getId() {
|
|
43071
43079
|
return this.id;
|
|
43072
43080
|
}
|
|
@@ -43594,15 +43602,6 @@ class Frame2 extends BaseItem {
|
|
|
43594
43602
|
y: translateY
|
|
43595
43603
|
}, timeStamp);
|
|
43596
43604
|
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
43605
|
this.setLastFrameScale();
|
|
43607
43606
|
res.mbr = this.getMbr();
|
|
43608
43607
|
return res;
|
|
@@ -56770,14 +56769,18 @@ class BoardSelection {
|
|
|
56770
56769
|
}
|
|
56771
56770
|
}
|
|
56772
56771
|
// src/Gravity/GravityEngine.ts
|
|
56772
|
+
var EXCLUDED_ITEM_TYPES = new Set(["Comment", "Connector"]);
|
|
56773
|
+
|
|
56773
56774
|
class GravityEngine {
|
|
56774
56775
|
board;
|
|
56775
56776
|
velocities = new Map;
|
|
56776
56777
|
tickTimer = null;
|
|
56777
56778
|
syncTimer = null;
|
|
56778
56779
|
lastSyncedPositions = new Map;
|
|
56779
|
-
G =
|
|
56780
|
-
|
|
56780
|
+
G = 80;
|
|
56781
|
+
G_CENTER = 120;
|
|
56782
|
+
DAMPING = 0.92;
|
|
56783
|
+
REPULSION = 60000;
|
|
56781
56784
|
TICK_MS = 33;
|
|
56782
56785
|
SYNC_MS = 300;
|
|
56783
56786
|
MAX_DISTANCE = 3000;
|
|
@@ -56809,9 +56812,18 @@ class GravityEngine {
|
|
|
56809
56812
|
}
|
|
56810
56813
|
tick() {
|
|
56811
56814
|
const dt = this.TICK_MS / 1000;
|
|
56812
|
-
const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked);
|
|
56813
|
-
if (items.length <
|
|
56815
|
+
const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
|
|
56816
|
+
if (items.length < 1)
|
|
56814
56817
|
return;
|
|
56818
|
+
let sumX = 0;
|
|
56819
|
+
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;
|
|
56815
56827
|
for (const item of items) {
|
|
56816
56828
|
const id = item.getId();
|
|
56817
56829
|
if (!this.velocities.has(id)) {
|
|
@@ -56820,30 +56832,45 @@ class GravityEngine {
|
|
|
56820
56832
|
const vel = this.velocities.get(id);
|
|
56821
56833
|
const pos1 = item.transformation.getTranslation();
|
|
56822
56834
|
const mbr1 = item.getMbr();
|
|
56823
|
-
const
|
|
56824
|
-
const
|
|
56835
|
+
const w1 = mbr1.getWidth();
|
|
56836
|
+
const h1 = mbr1.getHeight();
|
|
56825
56837
|
let ax = 0;
|
|
56826
56838
|
let ay = 0;
|
|
56839
|
+
const dcx = centerX - pos1.x;
|
|
56840
|
+
const dcy = centerY - pos1.y;
|
|
56841
|
+
const distCenter = Math.sqrt(dcx * dcx + dcy * dcy) + 1;
|
|
56842
|
+
ax += this.G_CENTER * dcx / distCenter;
|
|
56843
|
+
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));
|
|
56827
56845
|
for (const other of nearby) {
|
|
56828
56846
|
const pos2 = other.transformation.getTranslation();
|
|
56829
56847
|
const mbr2 = other.getMbr();
|
|
56830
|
-
const
|
|
56831
|
-
const
|
|
56832
|
-
const
|
|
56833
|
-
const
|
|
56834
|
-
const
|
|
56835
|
-
const
|
|
56836
|
-
|
|
56837
|
-
|
|
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;
|
|
56853
|
+
const distSq = dx * dx + dy * dy;
|
|
56854
|
+
const dist = Math.sqrt(distSq) + 0.001;
|
|
56855
|
+
const minDist = (w1 + w2) * 0.5 + (h1 + h2) * 0.5;
|
|
56856
|
+
if (dist < minDist) {
|
|
56857
|
+
const repAcc = this.REPULSION / (distSq + this.SOFTENING_SQ);
|
|
56858
|
+
ax -= repAcc * dx / dist;
|
|
56859
|
+
ay -= repAcc * dy / dist;
|
|
56860
|
+
} else {
|
|
56861
|
+
const gravAcc = this.G * mass2 / (distSq + this.SOFTENING_SQ);
|
|
56862
|
+
ax += gravAcc * dx / dist;
|
|
56863
|
+
ay += gravAcc * dy / dist;
|
|
56864
|
+
}
|
|
56838
56865
|
}
|
|
56839
56866
|
vel.vx = (vel.vx + ax * dt) * this.DAMPING;
|
|
56840
56867
|
vel.vy = (vel.vy + ay * dt) * this.DAMPING;
|
|
56841
|
-
const
|
|
56842
|
-
const
|
|
56843
|
-
if (Math.abs(
|
|
56868
|
+
const moveX = vel.vx * dt;
|
|
56869
|
+
const moveY = vel.vy * dt;
|
|
56870
|
+
if (Math.abs(moveX) >= this.MIN_MOVE_PX || Math.abs(moveY) >= this.MIN_MOVE_PX) {
|
|
56844
56871
|
item.transformation.applyMatrixSilent({
|
|
56845
|
-
translateX:
|
|
56846
|
-
translateY:
|
|
56872
|
+
translateX: moveX,
|
|
56873
|
+
translateY: moveY,
|
|
56847
56874
|
scaleX: 1,
|
|
56848
56875
|
scaleY: 1,
|
|
56849
56876
|
shearX: 0,
|
|
@@ -56853,7 +56880,7 @@ class GravityEngine {
|
|
|
56853
56880
|
}
|
|
56854
56881
|
}
|
|
56855
56882
|
syncPositions() {
|
|
56856
|
-
const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked);
|
|
56883
|
+
const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
|
|
56857
56884
|
if (items.length === 0)
|
|
56858
56885
|
return;
|
|
56859
56886
|
const movedItems = items.map((item) => {
|