microboard-temp 0.5.136 → 0.5.138

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/node.js CHANGED
@@ -8339,6 +8339,20 @@ class TransformationCommand {
8339
8339
  getReverse() {
8340
8340
  const op = this.operation;
8341
8341
  switch (this.operation.method) {
8342
+ case "applyMatrix": {
8343
+ const op2 = this.operation;
8344
+ return mapItemsByOperation(this.transformation, () => ({
8345
+ ...op2,
8346
+ matrix: {
8347
+ translateX: -op2.matrix.translateX,
8348
+ translateY: -op2.matrix.translateY,
8349
+ scaleX: 1 / op2.matrix.scaleX,
8350
+ scaleY: 1 / op2.matrix.scaleY,
8351
+ shearX: 0,
8352
+ shearY: 0
8353
+ }
8354
+ }));
8355
+ }
8342
8356
  case "translateTo":
8343
8357
  return mapItemsByOperation(this.transformation, (transformation) => {
8344
8358
  return {
@@ -8420,7 +8434,19 @@ class TransformationCommand {
8420
8434
  return transformation.map((currTrans) => {
8421
8435
  const op2 = operation.items[currTrans.getId()];
8422
8436
  let reverseOp;
8423
- if (op2.method === "scaleByTranslateBy") {
8437
+ if (op2.method === "applyMatrix") {
8438
+ reverseOp = {
8439
+ ...op2,
8440
+ matrix: {
8441
+ translateX: -op2.matrix.translateX,
8442
+ translateY: -op2.matrix.translateY,
8443
+ scaleX: 1 / op2.matrix.scaleX,
8444
+ scaleY: 1 / op2.matrix.scaleY,
8445
+ shearX: 0,
8446
+ shearY: 0
8447
+ }
8448
+ };
8449
+ } else if (op2.method === "scaleByTranslateBy") {
8424
8450
  reverseOp = {
8425
8451
  ...op2,
8426
8452
  scale: { x: 1 / op2.scale.x, y: 1 / op2.scale.y },
@@ -8591,6 +8617,10 @@ class Transformation {
8591
8617
  apply(op) {
8592
8618
  this.previous = this.matrix.copy();
8593
8619
  switch (op.method) {
8620
+ case "applyMatrix":
8621
+ this.matrix.scale(op.matrix.scaleX, op.matrix.scaleY);
8622
+ this.matrix.translate(op.matrix.translateX, op.matrix.translateY);
8623
+ break;
8594
8624
  case "translateTo":
8595
8625
  this.applyTranslateTo(op.x, op.y);
8596
8626
  break;
@@ -8651,7 +8681,10 @@ class Transformation {
8651
8681
  this.matrix.translate(translate.x, translate.y);
8652
8682
  }
8653
8683
  applyTransformMany(op) {
8654
- if (op.method === "scaleByTranslateBy") {
8684
+ if (op.method === "applyMatrix") {
8685
+ this.matrix.scale(op.matrix.scaleX, op.matrix.scaleY);
8686
+ this.matrix.translate(op.matrix.translateX, op.matrix.translateY);
8687
+ } else if (op.method === "scaleByTranslateBy") {
8655
8688
  this.applyScaleByTranslateBy(op.scale, op.translate);
8656
8689
  } else if (op.method === "scaleBy") {
8657
8690
  this.applyScaleBy(op.x, op.y);
@@ -8718,66 +8751,75 @@ class Transformation {
8718
8751
  getId() {
8719
8752
  return this.id;
8720
8753
  }
8721
- translateTo(x, y, timeStamp) {
8722
- if (!this.id) {}
8754
+ emitMatrix(matrix, timeStamp) {
8723
8755
  this.emit({
8724
8756
  class: "Transformation",
8725
- method: "translateTo",
8757
+ method: "applyMatrix",
8726
8758
  item: [this.id],
8727
- x,
8728
- y,
8759
+ matrix,
8729
8760
  timeStamp
8730
8761
  });
8731
8762
  }
8763
+ translateTo(x, y, timeStamp) {
8764
+ if (!this.id) {}
8765
+ this.emitMatrix({
8766
+ translateX: x - this.matrix.translateX,
8767
+ translateY: y - this.matrix.translateY,
8768
+ scaleX: 1,
8769
+ scaleY: 1,
8770
+ shearX: 0,
8771
+ shearY: 0
8772
+ }, timeStamp);
8773
+ }
8732
8774
  translateBy(x, y, timeStamp) {
8733
8775
  if (!this.id) {}
8734
8776
  if (x === 0 && y === 0) {
8735
8777
  return;
8736
8778
  }
8737
- this.emit({
8738
- class: "Transformation",
8739
- method: "translateBy",
8740
- item: [this.id],
8741
- x,
8742
- y,
8743
- timeStamp
8744
- });
8779
+ this.emitMatrix({
8780
+ translateX: x,
8781
+ translateY: y,
8782
+ scaleX: 1,
8783
+ scaleY: 1,
8784
+ shearX: 0,
8785
+ shearY: 0
8786
+ }, timeStamp);
8745
8787
  }
8746
8788
  scaleTo(x, y, timeStamp) {
8747
- this.emit({
8748
- class: "Transformation",
8749
- method: "scaleTo",
8750
- item: [this.id],
8751
- x,
8752
- y,
8753
- timeStamp
8754
- });
8789
+ this.emitMatrix({
8790
+ translateX: 0,
8791
+ translateY: 0,
8792
+ scaleX: x / this.matrix.scaleX,
8793
+ scaleY: y / this.matrix.scaleY,
8794
+ shearX: 0,
8795
+ shearY: 0
8796
+ }, timeStamp);
8755
8797
  }
8756
8798
  scaleBy(x, y, timeStamp) {
8757
8799
  if (x === 0 && y === 0) {
8758
8800
  return;
8759
8801
  }
8760
- this.emit({
8761
- class: "Transformation",
8762
- method: "scaleBy",
8763
- item: [this.id],
8764
- x,
8765
- y,
8766
- timeStamp
8767
- });
8802
+ this.emitMatrix({
8803
+ translateX: 0,
8804
+ translateY: 0,
8805
+ scaleX: x,
8806
+ scaleY: y,
8807
+ shearX: 0,
8808
+ shearY: 0
8809
+ }, timeStamp);
8768
8810
  }
8769
8811
  scaleByTranslateBy(scale, translate, timeStamp) {
8770
8812
  if (scale.x === 0 && scale.y === 0 && translate.x === 0 && translate.y === 0) {
8771
8813
  return;
8772
8814
  }
8773
- this.emit({
8774
- class: "Transformation",
8775
- method: "scaleByTranslateBy",
8776
- item: [this.id],
8777
- scale,
8778
- translate,
8779
- timeStamp
8780
- });
8815
+ this.emitMatrix({
8816
+ translateX: translate.x,
8817
+ translateY: translate.y,
8818
+ scaleX: scale.x,
8819
+ scaleY: scale.y,
8820
+ shearX: 0,
8821
+ shearY: 0
8822
+ }, timeStamp);
8781
8823
  }
8782
8824
  rotateTo(degree, timeStamp) {
8783
8825
  this.emit({
@@ -8797,27 +8839,28 @@ class Transformation {
8797
8839
  timeStamp
8798
8840
  });
8799
8841
  }
8800
- scaleToRelativeTo(x, y, point, timeStamp) {
8801
- this.emit({
8802
- class: "Transformation",
8803
- method: "scaleToRelativeTo",
8804
- item: [this.id],
8805
- x,
8806
- y,
8807
- point,
8808
- timeStamp
8809
- });
8842
+ scaleToRelativeTo(x, y, _point, timeStamp) {
8843
+ this.emitMatrix({
8844
+ translateX: 0,
8845
+ translateY: 0,
8846
+ scaleX: x / this.matrix.scaleX,
8847
+ scaleY: y / this.matrix.scaleY,
8848
+ shearX: 0,
8849
+ shearY: 0
8850
+ }, timeStamp);
8810
8851
  }
8811
8852
  scaleByRelativeTo(x, y, point, timeStamp) {
8812
- this.emit({
8813
- class: "Transformation",
8814
- method: "scaleByRelativeTo",
8815
- item: [this.id],
8816
- x,
8817
- y,
8818
- point,
8819
- timeStamp
8820
- });
8853
+ const { scaleX: sx0, scaleY: sy0, translateX: tx0, translateY: ty0 } = this.matrix;
8854
+ const newSx = sx0 * x;
8855
+ const newSy = sy0 * y;
8856
+ this.emitMatrix({
8857
+ translateX: -point.x * newSx + point.x - tx0,
8858
+ translateY: -point.y * newSy + point.y - ty0,
8859
+ scaleX: x,
8860
+ scaleY: y,
8861
+ shearX: 0,
8862
+ shearY: 0
8863
+ }, timeStamp);
8821
8864
  }
8822
8865
  setIsLocked(isLocked, timestamp) {
8823
8866
  if (isLocked) {
@@ -39552,7 +39595,11 @@ class Connector2 extends BaseItem {
39552
39595
  this.transformation.subject.subscribe((_sub, op) => {
39553
39596
  if (op.method === "transformMany") {
39554
39597
  const operation = op.items[this.getId()];
39555
- if (operation.method === "scaleByTranslateBy" && (operation.scale.x !== 1 || operation.scale.y !== 1)) {
39598
+ if (operation.method === "applyMatrix") {
39599
+ if (operation.matrix.scaleX !== 1 || operation.matrix.scaleY !== 1) {
39600
+ this.scalePoints();
39601
+ }
39602
+ } else if (operation.method === "scaleByTranslateBy" && (operation.scale.x !== 1 || operation.scale.y !== 1)) {
39556
39603
  this.scalePoints();
39557
39604
  }
39558
39605
  }
@@ -51799,6 +51846,7 @@ class Camera {
51799
51846
  trackingAnimationId = null;
51800
51847
  trackingTarget = null;
51801
51848
  lastTrackingTime = null;
51849
+ springVelocity = { translateX: 0, translateY: 0, scaleX: 0, scaleY: 0, shearX: 0, shearY: 0 };
51802
51850
  constructor(boardPointer = new Pointer) {
51803
51851
  this.boardPointer = boardPointer;
51804
51852
  this.subject.subscribe((_camera) => {
@@ -51968,46 +52016,56 @@ class Camera {
51968
52016
  }
51969
52017
  this.isTrackingAnimation = true;
51970
52018
  this.lastTrackingTime = null;
51971
- const SMOOTHING = 7;
51972
- const SNAP_PX = 2;
52019
+ const STIFFNESS = 150;
52020
+ const DAMPING = 28;
52021
+ const SNAP_PX = 0.5;
51973
52022
  const SNAP_SCALE = 0.0005;
52023
+ const SNAP_VEL = 1;
52024
+ const springStep = (pos, tgt, vel, dt) => {
52025
+ const acc = STIFFNESS * (tgt - pos) - DAMPING * vel;
52026
+ const newVel = vel + acc * dt;
52027
+ return [pos + newVel * dt, newVel];
52028
+ };
51974
52029
  const loop = () => {
51975
- const t3 = this.trackingTarget;
51976
- if (!t3) {
52030
+ const tgt = this.trackingTarget;
52031
+ if (!tgt) {
51977
52032
  this.trackingAnimationId = null;
51978
52033
  this.isTrackingAnimation = false;
51979
52034
  return;
51980
52035
  }
51981
52036
  const now = performance.now();
51982
- const dt = this.lastTrackingTime !== null ? Math.min(now - this.lastTrackingTime, 50) : 16;
52037
+ const dt = Math.min(this.lastTrackingTime !== null ? now - this.lastTrackingTime : 16, 50) / 1000;
51983
52038
  this.lastTrackingTime = now;
51984
- const factor = 1 - Math.exp(-SMOOTHING * dt / 1000);
51985
- const dTx = t3.translateX - this.matrix.translateX;
51986
- const dTy = t3.translateY - this.matrix.translateY;
51987
- const dSx = t3.scaleX - this.matrix.scaleX;
51988
- const dSy = t3.scaleY - this.matrix.scaleY;
51989
- const dHx = t3.shearX - this.matrix.shearX;
51990
- const dHy = t3.shearY - this.matrix.shearY;
51991
- if (Math.abs(dTx) < SNAP_PX && Math.abs(dTy) < SNAP_PX && Math.abs(dSx) < SNAP_SCALE && Math.abs(dSy) < SNAP_SCALE) {
51992
- this.matrix.translateX = t3.translateX;
51993
- this.matrix.translateY = t3.translateY;
51994
- this.matrix.scaleX = t3.scaleX;
51995
- this.matrix.scaleY = t3.scaleY;
51996
- this.matrix.shearX = t3.shearX;
51997
- this.matrix.shearY = t3.shearY;
52039
+ const v = this.springVelocity;
52040
+ const [tx, vtx] = springStep(this.matrix.translateX, tgt.translateX, v.translateX, dt);
52041
+ const [ty, vty] = springStep(this.matrix.translateY, tgt.translateY, v.translateY, dt);
52042
+ const [sx, vsx] = springStep(this.matrix.scaleX, tgt.scaleX, v.scaleX, dt);
52043
+ const [sy, vsy] = springStep(this.matrix.scaleY, tgt.scaleY, v.scaleY, dt);
52044
+ const [hx, vhx] = springStep(this.matrix.shearX, tgt.shearX, v.shearX, dt);
52045
+ const [hy, vhy] = springStep(this.matrix.shearY, tgt.shearY, v.shearY, dt);
52046
+ this.matrix.translateX = tx;
52047
+ this.matrix.translateY = ty;
52048
+ this.matrix.scaleX = sx;
52049
+ this.matrix.scaleY = sy;
52050
+ this.matrix.shearX = hx;
52051
+ this.matrix.shearY = hy;
52052
+ this.springVelocity = { translateX: vtx, translateY: vty, scaleX: vsx, scaleY: vsy, shearX: vhx, shearY: vhy };
52053
+ this.subject.publish(this);
52054
+ const settled = Math.abs(tgt.translateX - tx) < SNAP_PX && Math.abs(tgt.translateY - ty) < SNAP_PX && Math.abs(tgt.scaleX - sx) < SNAP_SCALE && Math.abs(vtx) < SNAP_VEL && Math.abs(vty) < SNAP_VEL;
52055
+ if (settled) {
52056
+ this.matrix.translateX = tgt.translateX;
52057
+ this.matrix.translateY = tgt.translateY;
52058
+ this.matrix.scaleX = tgt.scaleX;
52059
+ this.matrix.scaleY = tgt.scaleY;
52060
+ this.matrix.shearX = tgt.shearX;
52061
+ this.matrix.shearY = tgt.shearY;
51998
52062
  this.subject.publish(this);
52063
+ this.springVelocity = { translateX: 0, translateY: 0, scaleX: 0, scaleY: 0, shearX: 0, shearY: 0 };
51999
52064
  this.trackingTarget = null;
52000
52065
  this.trackingAnimationId = null;
52001
52066
  this.isTrackingAnimation = false;
52002
52067
  return;
52003
52068
  }
52004
- this.matrix.translateX += dTx * factor;
52005
- this.matrix.translateY += dTy * factor;
52006
- this.matrix.scaleX += dSx * factor;
52007
- this.matrix.scaleY += dSy * factor;
52008
- this.matrix.shearX += dHx * factor;
52009
- this.matrix.shearY += dHy * factor;
52010
- this.subject.publish(this);
52011
52069
  this.trackingAnimationId = safeRequestAnimationFrame(loop) || null;
52012
52070
  };
52013
52071
  this.trackingAnimationId = safeRequestAnimationFrame(loop) || null;
@@ -52019,6 +52077,7 @@ class Camera {
52019
52077
  }
52020
52078
  this.trackingTarget = null;
52021
52079
  this.lastTrackingTime = null;
52080
+ this.springVelocity = { translateX: 0, translateY: 0, scaleX: 0, scaleY: 0, shearX: 0, shearY: 0 };
52022
52081
  this.isTrackingAnimation = false;
52023
52082
  }
52024
52083
  useSavedSnapshot(optionalMatrix) {
@@ -54284,26 +54343,23 @@ function getRichTextTranslation({
54284
54343
  item.editor.setMaxWidth(item.getWidth() / item.transformation.getScale().x * matrix.scaleX);
54285
54344
  return {
54286
54345
  class: "Transformation",
54287
- method: "scaleByTranslateBy",
54346
+ method: "applyMatrix",
54288
54347
  item: [item.getId()],
54289
- translate: { x: matrix.translateX, y: 0 },
54290
- scale: { x: matrix.scaleX, y: matrix.scaleX }
54348
+ matrix: { translateX: matrix.translateX, translateY: 0, scaleX: matrix.scaleX, scaleY: matrix.scaleX, shearX: 0, shearY: 0 }
54291
54349
  };
54292
54350
  } else if (isHeight) {
54293
54351
  return {
54294
54352
  class: "Transformation",
54295
- method: "scaleByTranslateBy",
54353
+ method: "applyMatrix",
54296
54354
  item: [item.getId()],
54297
- translate: { x: translateX, y: translateY },
54298
- scale: { x: 1, y: 1 }
54355
+ matrix: { translateX, translateY, scaleX: 1, scaleY: 1, shearX: 0, shearY: 0 }
54299
54356
  };
54300
54357
  } else {
54301
54358
  return {
54302
54359
  class: "Transformation",
54303
- method: "scaleByTranslateBy",
54360
+ method: "applyMatrix",
54304
54361
  item: [item.getId()],
54305
- translate: { x: translateX, y: translateY },
54306
- scale: { x: matrix.scaleX, y: matrix.scaleX }
54362
+ matrix: { translateX, translateY, scaleX: matrix.scaleX, scaleY: matrix.scaleX, shearX: 0, shearY: 0 }
54307
54363
  };
54308
54364
  }
54309
54365
  }
@@ -54319,26 +54375,23 @@ function getAINodeTranslation({
54319
54375
  item.text.editor.setMaxWidth(item.text.getWidth() / item.transformation.getScale().x * matrix.scaleX);
54320
54376
  return {
54321
54377
  class: "Transformation",
54322
- method: "scaleByTranslateBy",
54378
+ method: "applyMatrix",
54323
54379
  item: [item.getId()],
54324
- translate: { x: matrix.translateX, y: 0 },
54325
- scale: { x: matrix.scaleX, y: matrix.scaleX }
54380
+ matrix: { translateX: matrix.translateX, translateY: 0, scaleX: matrix.scaleX, scaleY: matrix.scaleX, shearX: 0, shearY: 0 }
54326
54381
  };
54327
54382
  } else if (isHeight) {
54328
54383
  return {
54329
54384
  class: "Transformation",
54330
- method: "scaleByTranslateBy",
54385
+ method: "applyMatrix",
54331
54386
  item: [item.getId()],
54332
- translate: { x: translateX, y: translateY },
54333
- scale: { x: 1, y: 1 }
54387
+ matrix: { translateX, translateY, scaleX: 1, scaleY: 1, shearX: 0, shearY: 0 }
54334
54388
  };
54335
54389
  } else {
54336
54390
  return {
54337
54391
  class: "Transformation",
54338
- method: "scaleByTranslateBy",
54392
+ method: "applyMatrix",
54339
54393
  item: [item.getId()],
54340
- translate: { x: translateX, y: translateY },
54341
- scale: { x: matrix.scaleX, y: matrix.scaleX }
54394
+ matrix: { translateX, translateY, scaleX: matrix.scaleX, scaleY: matrix.scaleX, shearX: 0, shearY: 0 }
54342
54395
  };
54343
54396
  }
54344
54397
  }
@@ -54354,10 +54407,9 @@ function getItemTranslation({
54354
54407
  if (item instanceof Sticker && (isWidth || isHeight)) {
54355
54408
  return {
54356
54409
  class: "Transformation",
54357
- method: "scaleByTranslateBy",
54410
+ method: "applyMatrix",
54358
54411
  item: [item.getId()],
54359
- translate: { x: translateX, y: translateY },
54360
- scale: { x: 1, y: 1 }
54412
+ matrix: { translateX, translateY, scaleX: 1, scaleY: 1, shearX: 0, shearY: 0 }
54361
54413
  };
54362
54414
  } else {
54363
54415
  if (item instanceof Frame2 && item.getCanChangeRatio() && isShiftPressed && item.getFrameType() !== "Custom") {
@@ -54365,10 +54417,9 @@ function getItemTranslation({
54365
54417
  }
54366
54418
  return {
54367
54419
  class: "Transformation",
54368
- method: "scaleByTranslateBy",
54420
+ method: "applyMatrix",
54369
54421
  item: [item.getId()],
54370
- translate: { x: translateX, y: translateY },
54371
- scale: { x: matrix.scaleX, y: matrix.scaleY }
54422
+ matrix: { translateX, translateY, scaleX: matrix.scaleX, scaleY: matrix.scaleY, shearX: 0, shearY: 0 }
54372
54423
  };
54373
54424
  }
54374
54425
  }
@@ -57333,6 +57384,24 @@ function mergeTransformationOperations(opA, opB) {
57333
57384
  }
57334
57385
  const method = opA.method;
57335
57386
  switch (method) {
57387
+ case "applyMatrix":
57388
+ if (opB.method !== method) {
57389
+ return;
57390
+ }
57391
+ return {
57392
+ class: "Transformation",
57393
+ method: "applyMatrix",
57394
+ item: opA.item,
57395
+ matrix: {
57396
+ translateX: opA.matrix.translateX + opB.matrix.translateX,
57397
+ translateY: opA.matrix.translateY + opB.matrix.translateY,
57398
+ scaleX: opA.matrix.scaleX * opB.matrix.scaleX,
57399
+ scaleY: opA.matrix.scaleY * opB.matrix.scaleY,
57400
+ shearX: 0,
57401
+ shearY: 0
57402
+ },
57403
+ timeStamp: opB.timeStamp
57404
+ };
57336
57405
  case "translateBy":
57337
57406
  if (opB.method !== method) {
57338
57407
  return;
@@ -57444,7 +57513,23 @@ function mergeItems(opA, opB) {
57444
57513
  const items = {};
57445
57514
  Object.keys(opB.items).forEach((itemId) => {
57446
57515
  if (opA.items[itemId] !== undefined) {
57447
- if (opA.items[itemId].method === "scaleByTranslateBy") {
57516
+ if (opA.items[itemId].method === "applyMatrix" && opB.items[itemId].method === "applyMatrix") {
57517
+ const a2 = opA.items[itemId].matrix;
57518
+ const b = opB.items[itemId].matrix;
57519
+ items[itemId] = {
57520
+ class: "Transformation",
57521
+ method: "applyMatrix",
57522
+ item: [itemId],
57523
+ matrix: {
57524
+ translateX: a2.translateX + b.translateX,
57525
+ translateY: a2.translateY + b.translateY,
57526
+ scaleX: a2.scaleX * b.scaleX,
57527
+ scaleY: a2.scaleY * b.scaleY,
57528
+ shearX: 0,
57529
+ shearY: 0
57530
+ }
57531
+ };
57532
+ } else if (opA.items[itemId].method === "scaleByTranslateBy") {
57448
57533
  const newTransformation = resolve2(opA.items[itemId].scale, opA.items[itemId].translate, opB.items[itemId]);
57449
57534
  items[itemId] = {
57450
57535
  class: "Transformation",