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.
@@ -7302,6 +7302,20 @@ class TransformationCommand {
7302
7302
  getReverse() {
7303
7303
  const op = this.operation;
7304
7304
  switch (this.operation.method) {
7305
+ case "applyMatrix": {
7306
+ const op2 = this.operation;
7307
+ return mapItemsByOperation(this.transformation, () => ({
7308
+ ...op2,
7309
+ matrix: {
7310
+ translateX: -op2.matrix.translateX,
7311
+ translateY: -op2.matrix.translateY,
7312
+ scaleX: 1 / op2.matrix.scaleX,
7313
+ scaleY: 1 / op2.matrix.scaleY,
7314
+ shearX: 0,
7315
+ shearY: 0
7316
+ }
7317
+ }));
7318
+ }
7305
7319
  case "translateTo":
7306
7320
  return mapItemsByOperation(this.transformation, (transformation) => {
7307
7321
  return {
@@ -7383,7 +7397,19 @@ class TransformationCommand {
7383
7397
  return transformation.map((currTrans) => {
7384
7398
  const op2 = operation.items[currTrans.getId()];
7385
7399
  let reverseOp;
7386
- if (op2.method === "scaleByTranslateBy") {
7400
+ if (op2.method === "applyMatrix") {
7401
+ reverseOp = {
7402
+ ...op2,
7403
+ matrix: {
7404
+ translateX: -op2.matrix.translateX,
7405
+ translateY: -op2.matrix.translateY,
7406
+ scaleX: 1 / op2.matrix.scaleX,
7407
+ scaleY: 1 / op2.matrix.scaleY,
7408
+ shearX: 0,
7409
+ shearY: 0
7410
+ }
7411
+ };
7412
+ } else if (op2.method === "scaleByTranslateBy") {
7387
7413
  reverseOp = {
7388
7414
  ...op2,
7389
7415
  scale: { x: 1 / op2.scale.x, y: 1 / op2.scale.y },
@@ -7554,6 +7580,10 @@ class Transformation {
7554
7580
  apply(op) {
7555
7581
  this.previous = this.matrix.copy();
7556
7582
  switch (op.method) {
7583
+ case "applyMatrix":
7584
+ this.matrix.scale(op.matrix.scaleX, op.matrix.scaleY);
7585
+ this.matrix.translate(op.matrix.translateX, op.matrix.translateY);
7586
+ break;
7557
7587
  case "translateTo":
7558
7588
  this.applyTranslateTo(op.x, op.y);
7559
7589
  break;
@@ -7614,7 +7644,10 @@ class Transformation {
7614
7644
  this.matrix.translate(translate.x, translate.y);
7615
7645
  }
7616
7646
  applyTransformMany(op) {
7617
- if (op.method === "scaleByTranslateBy") {
7647
+ if (op.method === "applyMatrix") {
7648
+ this.matrix.scale(op.matrix.scaleX, op.matrix.scaleY);
7649
+ this.matrix.translate(op.matrix.translateX, op.matrix.translateY);
7650
+ } else if (op.method === "scaleByTranslateBy") {
7618
7651
  this.applyScaleByTranslateBy(op.scale, op.translate);
7619
7652
  } else if (op.method === "scaleBy") {
7620
7653
  this.applyScaleBy(op.x, op.y);
@@ -7681,66 +7714,75 @@ class Transformation {
7681
7714
  getId() {
7682
7715
  return this.id;
7683
7716
  }
7684
- translateTo(x, y, timeStamp) {
7685
- if (!this.id) {}
7717
+ emitMatrix(matrix, timeStamp) {
7686
7718
  this.emit({
7687
7719
  class: "Transformation",
7688
- method: "translateTo",
7720
+ method: "applyMatrix",
7689
7721
  item: [this.id],
7690
- x,
7691
- y,
7722
+ matrix,
7692
7723
  timeStamp
7693
7724
  });
7694
7725
  }
7726
+ translateTo(x, y, timeStamp) {
7727
+ if (!this.id) {}
7728
+ this.emitMatrix({
7729
+ translateX: x - this.matrix.translateX,
7730
+ translateY: y - this.matrix.translateY,
7731
+ scaleX: 1,
7732
+ scaleY: 1,
7733
+ shearX: 0,
7734
+ shearY: 0
7735
+ }, timeStamp);
7736
+ }
7695
7737
  translateBy(x, y, timeStamp) {
7696
7738
  if (!this.id) {}
7697
7739
  if (x === 0 && y === 0) {
7698
7740
  return;
7699
7741
  }
7700
- this.emit({
7701
- class: "Transformation",
7702
- method: "translateBy",
7703
- item: [this.id],
7704
- x,
7705
- y,
7706
- timeStamp
7707
- });
7742
+ this.emitMatrix({
7743
+ translateX: x,
7744
+ translateY: y,
7745
+ scaleX: 1,
7746
+ scaleY: 1,
7747
+ shearX: 0,
7748
+ shearY: 0
7749
+ }, timeStamp);
7708
7750
  }
7709
7751
  scaleTo(x, y, timeStamp) {
7710
- this.emit({
7711
- class: "Transformation",
7712
- method: "scaleTo",
7713
- item: [this.id],
7714
- x,
7715
- y,
7716
- timeStamp
7717
- });
7752
+ this.emitMatrix({
7753
+ translateX: 0,
7754
+ translateY: 0,
7755
+ scaleX: x / this.matrix.scaleX,
7756
+ scaleY: y / this.matrix.scaleY,
7757
+ shearX: 0,
7758
+ shearY: 0
7759
+ }, timeStamp);
7718
7760
  }
7719
7761
  scaleBy(x, y, timeStamp) {
7720
7762
  if (x === 0 && y === 0) {
7721
7763
  return;
7722
7764
  }
7723
- this.emit({
7724
- class: "Transformation",
7725
- method: "scaleBy",
7726
- item: [this.id],
7727
- x,
7728
- y,
7729
- timeStamp
7730
- });
7765
+ this.emitMatrix({
7766
+ translateX: 0,
7767
+ translateY: 0,
7768
+ scaleX: x,
7769
+ scaleY: y,
7770
+ shearX: 0,
7771
+ shearY: 0
7772
+ }, timeStamp);
7731
7773
  }
7732
7774
  scaleByTranslateBy(scale, translate, timeStamp) {
7733
7775
  if (scale.x === 0 && scale.y === 0 && translate.x === 0 && translate.y === 0) {
7734
7776
  return;
7735
7777
  }
7736
- this.emit({
7737
- class: "Transformation",
7738
- method: "scaleByTranslateBy",
7739
- item: [this.id],
7740
- scale,
7741
- translate,
7742
- timeStamp
7743
- });
7778
+ this.emitMatrix({
7779
+ translateX: translate.x,
7780
+ translateY: translate.y,
7781
+ scaleX: scale.x,
7782
+ scaleY: scale.y,
7783
+ shearX: 0,
7784
+ shearY: 0
7785
+ }, timeStamp);
7744
7786
  }
7745
7787
  rotateTo(degree, timeStamp) {
7746
7788
  this.emit({
@@ -7760,27 +7802,28 @@ class Transformation {
7760
7802
  timeStamp
7761
7803
  });
7762
7804
  }
7763
- scaleToRelativeTo(x, y, point, timeStamp) {
7764
- this.emit({
7765
- class: "Transformation",
7766
- method: "scaleToRelativeTo",
7767
- item: [this.id],
7768
- x,
7769
- y,
7770
- point,
7771
- timeStamp
7772
- });
7805
+ scaleToRelativeTo(x, y, _point, timeStamp) {
7806
+ this.emitMatrix({
7807
+ translateX: 0,
7808
+ translateY: 0,
7809
+ scaleX: x / this.matrix.scaleX,
7810
+ scaleY: y / this.matrix.scaleY,
7811
+ shearX: 0,
7812
+ shearY: 0
7813
+ }, timeStamp);
7773
7814
  }
7774
7815
  scaleByRelativeTo(x, y, point, timeStamp) {
7775
- this.emit({
7776
- class: "Transformation",
7777
- method: "scaleByRelativeTo",
7778
- item: [this.id],
7779
- x,
7780
- y,
7781
- point,
7782
- timeStamp
7783
- });
7816
+ const { scaleX: sx0, scaleY: sy0, translateX: tx0, translateY: ty0 } = this.matrix;
7817
+ const newSx = sx0 * x;
7818
+ const newSy = sy0 * y;
7819
+ this.emitMatrix({
7820
+ translateX: -point.x * newSx + point.x - tx0,
7821
+ translateY: -point.y * newSy + point.y - ty0,
7822
+ scaleX: x,
7823
+ scaleY: y,
7824
+ shearX: 0,
7825
+ shearY: 0
7826
+ }, timeStamp);
7784
7827
  }
7785
7828
  setIsLocked(isLocked, timestamp) {
7786
7829
  if (isLocked) {
@@ -37079,7 +37122,11 @@ class Connector2 extends BaseItem {
37079
37122
  this.transformation.subject.subscribe((_sub, op) => {
37080
37123
  if (op.method === "transformMany") {
37081
37124
  const operation = op.items[this.getId()];
37082
- if (operation.method === "scaleByTranslateBy" && (operation.scale.x !== 1 || operation.scale.y !== 1)) {
37125
+ if (operation.method === "applyMatrix") {
37126
+ if (operation.matrix.scaleX !== 1 || operation.matrix.scaleY !== 1) {
37127
+ this.scalePoints();
37128
+ }
37129
+ } else if (operation.method === "scaleByTranslateBy" && (operation.scale.x !== 1 || operation.scale.y !== 1)) {
37083
37130
  this.scalePoints();
37084
37131
  }
37085
37132
  }
@@ -49326,6 +49373,7 @@ class Camera {
49326
49373
  trackingAnimationId = null;
49327
49374
  trackingTarget = null;
49328
49375
  lastTrackingTime = null;
49376
+ springVelocity = { translateX: 0, translateY: 0, scaleX: 0, scaleY: 0, shearX: 0, shearY: 0 };
49329
49377
  constructor(boardPointer = new Pointer) {
49330
49378
  this.boardPointer = boardPointer;
49331
49379
  this.subject.subscribe((_camera) => {
@@ -49495,46 +49543,56 @@ class Camera {
49495
49543
  }
49496
49544
  this.isTrackingAnimation = true;
49497
49545
  this.lastTrackingTime = null;
49498
- const SMOOTHING = 7;
49499
- const SNAP_PX = 2;
49546
+ const STIFFNESS = 150;
49547
+ const DAMPING = 28;
49548
+ const SNAP_PX = 0.5;
49500
49549
  const SNAP_SCALE = 0.0005;
49550
+ const SNAP_VEL = 1;
49551
+ const springStep = (pos, tgt, vel, dt) => {
49552
+ const acc = STIFFNESS * (tgt - pos) - DAMPING * vel;
49553
+ const newVel = vel + acc * dt;
49554
+ return [pos + newVel * dt, newVel];
49555
+ };
49501
49556
  const loop = () => {
49502
- const t3 = this.trackingTarget;
49503
- if (!t3) {
49557
+ const tgt = this.trackingTarget;
49558
+ if (!tgt) {
49504
49559
  this.trackingAnimationId = null;
49505
49560
  this.isTrackingAnimation = false;
49506
49561
  return;
49507
49562
  }
49508
49563
  const now = performance.now();
49509
- const dt = this.lastTrackingTime !== null ? Math.min(now - this.lastTrackingTime, 50) : 16;
49564
+ const dt = Math.min(this.lastTrackingTime !== null ? now - this.lastTrackingTime : 16, 50) / 1000;
49510
49565
  this.lastTrackingTime = now;
49511
- const factor = 1 - Math.exp(-SMOOTHING * dt / 1000);
49512
- const dTx = t3.translateX - this.matrix.translateX;
49513
- const dTy = t3.translateY - this.matrix.translateY;
49514
- const dSx = t3.scaleX - this.matrix.scaleX;
49515
- const dSy = t3.scaleY - this.matrix.scaleY;
49516
- const dHx = t3.shearX - this.matrix.shearX;
49517
- const dHy = t3.shearY - this.matrix.shearY;
49518
- if (Math.abs(dTx) < SNAP_PX && Math.abs(dTy) < SNAP_PX && Math.abs(dSx) < SNAP_SCALE && Math.abs(dSy) < SNAP_SCALE) {
49519
- this.matrix.translateX = t3.translateX;
49520
- this.matrix.translateY = t3.translateY;
49521
- this.matrix.scaleX = t3.scaleX;
49522
- this.matrix.scaleY = t3.scaleY;
49523
- this.matrix.shearX = t3.shearX;
49524
- this.matrix.shearY = t3.shearY;
49566
+ const v = this.springVelocity;
49567
+ const [tx, vtx] = springStep(this.matrix.translateX, tgt.translateX, v.translateX, dt);
49568
+ const [ty, vty] = springStep(this.matrix.translateY, tgt.translateY, v.translateY, dt);
49569
+ const [sx, vsx] = springStep(this.matrix.scaleX, tgt.scaleX, v.scaleX, dt);
49570
+ const [sy, vsy] = springStep(this.matrix.scaleY, tgt.scaleY, v.scaleY, dt);
49571
+ const [hx, vhx] = springStep(this.matrix.shearX, tgt.shearX, v.shearX, dt);
49572
+ const [hy, vhy] = springStep(this.matrix.shearY, tgt.shearY, v.shearY, dt);
49573
+ this.matrix.translateX = tx;
49574
+ this.matrix.translateY = ty;
49575
+ this.matrix.scaleX = sx;
49576
+ this.matrix.scaleY = sy;
49577
+ this.matrix.shearX = hx;
49578
+ this.matrix.shearY = hy;
49579
+ this.springVelocity = { translateX: vtx, translateY: vty, scaleX: vsx, scaleY: vsy, shearX: vhx, shearY: vhy };
49580
+ this.subject.publish(this);
49581
+ 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;
49582
+ if (settled) {
49583
+ this.matrix.translateX = tgt.translateX;
49584
+ this.matrix.translateY = tgt.translateY;
49585
+ this.matrix.scaleX = tgt.scaleX;
49586
+ this.matrix.scaleY = tgt.scaleY;
49587
+ this.matrix.shearX = tgt.shearX;
49588
+ this.matrix.shearY = tgt.shearY;
49525
49589
  this.subject.publish(this);
49590
+ this.springVelocity = { translateX: 0, translateY: 0, scaleX: 0, scaleY: 0, shearX: 0, shearY: 0 };
49526
49591
  this.trackingTarget = null;
49527
49592
  this.trackingAnimationId = null;
49528
49593
  this.isTrackingAnimation = false;
49529
49594
  return;
49530
49595
  }
49531
- this.matrix.translateX += dTx * factor;
49532
- this.matrix.translateY += dTy * factor;
49533
- this.matrix.scaleX += dSx * factor;
49534
- this.matrix.scaleY += dSy * factor;
49535
- this.matrix.shearX += dHx * factor;
49536
- this.matrix.shearY += dHy * factor;
49537
- this.subject.publish(this);
49538
49596
  this.trackingAnimationId = safeRequestAnimationFrame(loop) || null;
49539
49597
  };
49540
49598
  this.trackingAnimationId = safeRequestAnimationFrame(loop) || null;
@@ -49546,6 +49604,7 @@ class Camera {
49546
49604
  }
49547
49605
  this.trackingTarget = null;
49548
49606
  this.lastTrackingTime = null;
49607
+ this.springVelocity = { translateX: 0, translateY: 0, scaleX: 0, scaleY: 0, shearX: 0, shearY: 0 };
49549
49608
  this.isTrackingAnimation = false;
49550
49609
  }
49551
49610
  useSavedSnapshot(optionalMatrix) {
@@ -51811,26 +51870,23 @@ function getRichTextTranslation({
51811
51870
  item.editor.setMaxWidth(item.getWidth() / item.transformation.getScale().x * matrix.scaleX);
51812
51871
  return {
51813
51872
  class: "Transformation",
51814
- method: "scaleByTranslateBy",
51873
+ method: "applyMatrix",
51815
51874
  item: [item.getId()],
51816
- translate: { x: matrix.translateX, y: 0 },
51817
- scale: { x: matrix.scaleX, y: matrix.scaleX }
51875
+ matrix: { translateX: matrix.translateX, translateY: 0, scaleX: matrix.scaleX, scaleY: matrix.scaleX, shearX: 0, shearY: 0 }
51818
51876
  };
51819
51877
  } else if (isHeight) {
51820
51878
  return {
51821
51879
  class: "Transformation",
51822
- method: "scaleByTranslateBy",
51880
+ method: "applyMatrix",
51823
51881
  item: [item.getId()],
51824
- translate: { x: translateX, y: translateY },
51825
- scale: { x: 1, y: 1 }
51882
+ matrix: { translateX, translateY, scaleX: 1, scaleY: 1, shearX: 0, shearY: 0 }
51826
51883
  };
51827
51884
  } else {
51828
51885
  return {
51829
51886
  class: "Transformation",
51830
- method: "scaleByTranslateBy",
51887
+ method: "applyMatrix",
51831
51888
  item: [item.getId()],
51832
- translate: { x: translateX, y: translateY },
51833
- scale: { x: matrix.scaleX, y: matrix.scaleX }
51889
+ matrix: { translateX, translateY, scaleX: matrix.scaleX, scaleY: matrix.scaleX, shearX: 0, shearY: 0 }
51834
51890
  };
51835
51891
  }
51836
51892
  }
@@ -51846,26 +51902,23 @@ function getAINodeTranslation({
51846
51902
  item.text.editor.setMaxWidth(item.text.getWidth() / item.transformation.getScale().x * matrix.scaleX);
51847
51903
  return {
51848
51904
  class: "Transformation",
51849
- method: "scaleByTranslateBy",
51905
+ method: "applyMatrix",
51850
51906
  item: [item.getId()],
51851
- translate: { x: matrix.translateX, y: 0 },
51852
- scale: { x: matrix.scaleX, y: matrix.scaleX }
51907
+ matrix: { translateX: matrix.translateX, translateY: 0, scaleX: matrix.scaleX, scaleY: matrix.scaleX, shearX: 0, shearY: 0 }
51853
51908
  };
51854
51909
  } else if (isHeight) {
51855
51910
  return {
51856
51911
  class: "Transformation",
51857
- method: "scaleByTranslateBy",
51912
+ method: "applyMatrix",
51858
51913
  item: [item.getId()],
51859
- translate: { x: translateX, y: translateY },
51860
- scale: { x: 1, y: 1 }
51914
+ matrix: { translateX, translateY, scaleX: 1, scaleY: 1, shearX: 0, shearY: 0 }
51861
51915
  };
51862
51916
  } else {
51863
51917
  return {
51864
51918
  class: "Transformation",
51865
- method: "scaleByTranslateBy",
51919
+ method: "applyMatrix",
51866
51920
  item: [item.getId()],
51867
- translate: { x: translateX, y: translateY },
51868
- scale: { x: matrix.scaleX, y: matrix.scaleX }
51921
+ matrix: { translateX, translateY, scaleX: matrix.scaleX, scaleY: matrix.scaleX, shearX: 0, shearY: 0 }
51869
51922
  };
51870
51923
  }
51871
51924
  }
@@ -51881,10 +51934,9 @@ function getItemTranslation({
51881
51934
  if (item instanceof Sticker && (isWidth || isHeight)) {
51882
51935
  return {
51883
51936
  class: "Transformation",
51884
- method: "scaleByTranslateBy",
51937
+ method: "applyMatrix",
51885
51938
  item: [item.getId()],
51886
- translate: { x: translateX, y: translateY },
51887
- scale: { x: 1, y: 1 }
51939
+ matrix: { translateX, translateY, scaleX: 1, scaleY: 1, shearX: 0, shearY: 0 }
51888
51940
  };
51889
51941
  } else {
51890
51942
  if (item instanceof Frame2 && item.getCanChangeRatio() && isShiftPressed && item.getFrameType() !== "Custom") {
@@ -51892,10 +51944,9 @@ function getItemTranslation({
51892
51944
  }
51893
51945
  return {
51894
51946
  class: "Transformation",
51895
- method: "scaleByTranslateBy",
51947
+ method: "applyMatrix",
51896
51948
  item: [item.getId()],
51897
- translate: { x: translateX, y: translateY },
51898
- scale: { x: matrix.scaleX, y: matrix.scaleY }
51949
+ matrix: { translateX, translateY, scaleX: matrix.scaleX, scaleY: matrix.scaleY, shearX: 0, shearY: 0 }
51899
51950
  };
51900
51951
  }
51901
51952
  }
@@ -54860,6 +54911,24 @@ function mergeTransformationOperations(opA, opB) {
54860
54911
  }
54861
54912
  const method = opA.method;
54862
54913
  switch (method) {
54914
+ case "applyMatrix":
54915
+ if (opB.method !== method) {
54916
+ return;
54917
+ }
54918
+ return {
54919
+ class: "Transformation",
54920
+ method: "applyMatrix",
54921
+ item: opA.item,
54922
+ matrix: {
54923
+ translateX: opA.matrix.translateX + opB.matrix.translateX,
54924
+ translateY: opA.matrix.translateY + opB.matrix.translateY,
54925
+ scaleX: opA.matrix.scaleX * opB.matrix.scaleX,
54926
+ scaleY: opA.matrix.scaleY * opB.matrix.scaleY,
54927
+ shearX: 0,
54928
+ shearY: 0
54929
+ },
54930
+ timeStamp: opB.timeStamp
54931
+ };
54863
54932
  case "translateBy":
54864
54933
  if (opB.method !== method) {
54865
54934
  return;
@@ -54971,7 +55040,23 @@ function mergeItems(opA, opB) {
54971
55040
  const items = {};
54972
55041
  Object.keys(opB.items).forEach((itemId) => {
54973
55042
  if (opA.items[itemId] !== undefined) {
54974
- if (opA.items[itemId].method === "scaleByTranslateBy") {
55043
+ if (opA.items[itemId].method === "applyMatrix" && opB.items[itemId].method === "applyMatrix") {
55044
+ const a2 = opA.items[itemId].matrix;
55045
+ const b = opB.items[itemId].matrix;
55046
+ items[itemId] = {
55047
+ class: "Transformation",
55048
+ method: "applyMatrix",
55049
+ item: [itemId],
55050
+ matrix: {
55051
+ translateX: a2.translateX + b.translateX,
55052
+ translateY: a2.translateY + b.translateY,
55053
+ scaleX: a2.scaleX * b.scaleX,
55054
+ scaleY: a2.scaleY * b.scaleY,
55055
+ shearX: 0,
55056
+ shearY: 0
55057
+ }
55058
+ };
55059
+ } else if (opA.items[itemId].method === "scaleByTranslateBy") {
54975
55060
  const newTransformation = resolve2(opA.items[itemId].scale, opA.items[itemId].translate, opB.items[itemId]);
54976
55061
  items[itemId] = {
54977
55062
  class: "Transformation",