microboard-temp 0.11.2 → 0.11.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.
@@ -17752,9 +17752,15 @@ class TransformationCommand {
17752
17752
  transformation;
17753
17753
  operation;
17754
17754
  reverse;
17755
- constructor(transformation, operation) {
17755
+ itemsMap = new Map;
17756
+ constructor(transformation, operation, items) {
17756
17757
  this.transformation = transformation;
17757
17758
  this.operation = operation;
17759
+ if (items) {
17760
+ for (const item of items) {
17761
+ this.itemsMap.set(item.transformation, item);
17762
+ }
17763
+ }
17758
17764
  this.reverse = this.getReverse();
17759
17765
  }
17760
17766
  merge(op) {
@@ -17764,12 +17770,22 @@ class TransformationCommand {
17764
17770
  }
17765
17771
  apply() {
17766
17772
  for (const transformation of this.transformation) {
17767
- transformation.apply(this.operation);
17773
+ const item = this.itemsMap.get(transformation);
17774
+ if (item) {
17775
+ item.apply(this.operation);
17776
+ } else {
17777
+ transformation.apply(this.operation);
17778
+ }
17768
17779
  }
17769
17780
  }
17770
17781
  revert() {
17771
- this.reverse.forEach(({ item, operation }) => {
17772
- item.apply(operation);
17782
+ this.reverse.forEach(({ item: transformation, operation }) => {
17783
+ const item = this.itemsMap.get(transformation);
17784
+ if (item) {
17785
+ item.apply(operation);
17786
+ } else {
17787
+ transformation.apply(operation);
17788
+ }
17773
17789
  });
17774
17790
  }
17775
17791
  getReverse() {
@@ -19754,7 +19770,7 @@ function createRichTextCommand(items, operation, board) {
19754
19770
  }
19755
19771
  }
19756
19772
  function createTransformationCommand(items, operation) {
19757
- return new TransformationCommand(items.map((item) => item.transformation), operation);
19773
+ return new TransformationCommand(items.map((item) => item.transformation), operation, items);
19758
19774
  }
19759
19775
  function createLinkToCommand(items, operation) {
19760
19776
  return new LinkToCommand(items.map((item) => item.linkTo), operation);
@@ -21778,15 +21794,32 @@ class BaseItem extends Mbr {
21778
21794
  getId() {
21779
21795
  return this.id;
21780
21796
  }
21781
- getWorldMatrix() {
21797
+ getParentWorldMatrix() {
21782
21798
  if (this.parent === "Board") {
21783
- return this.transformation.toMatrix();
21799
+ return new Matrix;
21784
21800
  }
21785
21801
  const container = this.board.items.getById(this.parent);
21786
21802
  if (!container) {
21803
+ return new Matrix;
21804
+ }
21805
+ const matrix = container.getWorldMatrix();
21806
+ if (container.itemType === "Frame") {
21807
+ return new Matrix(matrix.translateX, matrix.translateY, 1, 1, 0, 0);
21808
+ }
21809
+ return matrix;
21810
+ }
21811
+ getWorldMatrix() {
21812
+ if (this.parent === "Board") {
21787
21813
  return this.transformation.toMatrix();
21788
21814
  }
21789
- return this.transformation.toMatrix().composeWith(container.getWorldMatrix());
21815
+ return this.transformation.toMatrix().composeWith(this.getParentWorldMatrix());
21816
+ }
21817
+ getNestingMatrix() {
21818
+ const matrix = this.getWorldMatrix();
21819
+ if (this.itemType === "Frame") {
21820
+ return new Matrix(matrix.translateX, matrix.translateY, 1, 1, 0, 0);
21821
+ }
21822
+ return matrix;
21790
21823
  }
21791
21824
  setId(id) {
21792
21825
  this.id = id;
@@ -21869,7 +21902,7 @@ class BaseItem extends Mbr {
21869
21902
  const container = this.board.items.getById(this.parent);
21870
21903
  if (!container)
21871
21904
  return this.getMbr();
21872
- const worldMatrix = container.getWorldMatrix();
21905
+ const parentMatrix = this.getParentWorldMatrix();
21873
21906
  const local = this.getMbr();
21874
21907
  const corners = [
21875
21908
  new Point(local.left, local.top),
@@ -21878,19 +21911,19 @@ class BaseItem extends Mbr {
21878
21911
  new Point(local.left, local.bottom)
21879
21912
  ];
21880
21913
  for (const c of corners)
21881
- worldMatrix.apply(c);
21914
+ parentMatrix.apply(c);
21882
21915
  return new Mbr(Math.min(corners[0].x, corners[1].x, corners[2].x, corners[3].x), Math.min(corners[0].y, corners[1].y, corners[2].y, corners[3].y), Math.max(corners[0].x, corners[1].x, corners[2].x, corners[3].x), Math.max(corners[0].y, corners[1].y, corners[2].y, corners[3].y));
21883
21916
  }
21884
21917
  applyAddChildren(childIds) {
21885
21918
  if (!this.index) {
21886
21919
  return;
21887
21920
  }
21888
- const containerWorldMatrix = this.getWorldMatrix();
21921
+ const containerNestingMatrix = this.getNestingMatrix();
21889
21922
  childIds.forEach((childId) => {
21890
21923
  const foundItem = this.board.items.getById(childId);
21891
21924
  if (this.parent !== childId && this.getId() !== childId) {
21892
21925
  if (!this.index?.getById(childId) && foundItem) {
21893
- const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerWorldMatrix);
21926
+ const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerNestingMatrix);
21894
21927
  this.board.items.index.remove(foundItem);
21895
21928
  foundItem.parent = this.getId();
21896
21929
  foundItem.transformation.setLocalMatrix(localMatrix);
@@ -21906,12 +21939,12 @@ class BaseItem extends Mbr {
21906
21939
  if (!this.index) {
21907
21940
  return;
21908
21941
  }
21909
- const containerWorldMatrix = this.getWorldMatrix();
21942
+ const containerNestingMatrix = this.getNestingMatrix();
21910
21943
  childIds.forEach((childId) => {
21911
21944
  const foundItem = this.index?.getById(childId);
21912
21945
  if (this.parent !== childId && this.getId() !== childId) {
21913
21946
  if (foundItem) {
21914
- const worldMatrix = foundItem.transformation.toMatrix().composeWith(containerWorldMatrix);
21947
+ const worldMatrix = foundItem.transformation.toMatrix().composeWith(containerNestingMatrix);
21915
21948
  this.index?.remove(foundItem);
21916
21949
  foundItem.parent = "Board";
21917
21950
  foundItem.transformation.setLocalMatrix(worldMatrix);
@@ -22031,7 +22064,7 @@ class BaseItem extends Mbr {
22031
22064
  if (this.parent !== "Board") {
22032
22065
  const container = this.board.items.getById(this.parent);
22033
22066
  if (container?.transformation) {
22034
- transformOp = toLocalTransformOp(transformOp, container.getWorldMatrix(), this.id);
22067
+ transformOp = toLocalTransformOp(transformOp, container.getNestingMatrix(), this.id);
22035
22068
  }
22036
22069
  }
22037
22070
  this.transformation.apply(transformOp);
@@ -22828,11 +22861,8 @@ class RichText extends BaseItem {
22828
22861
  const { ctx } = context;
22829
22862
  ctx.save();
22830
22863
  ctx.translate(this.left, this.top);
22831
- const shouldScale = !this.isInShape && !this.autoSize;
22832
- if (shouldScale) {
22833
- const { scaleX, scaleY } = this.transformation.getMatrixData();
22834
- ctx.scale(scaleX, scaleY);
22835
- }
22864
+ const { scaleX, scaleY } = this.transformation.getMatrixData();
22865
+ ctx.scale(scaleX, scaleY);
22836
22866
  const shouldClip = this.insideOf === "Shape" || this.insideOf === "Sticker";
22837
22867
  if (shouldClip) {
22838
22868
  ctx.clip(this.clipPath.nativePath);
@@ -41064,6 +41094,7 @@ class Frame2 extends BaseItem {
41064
41094
  scaleY = 1;
41065
41095
  translateY = 0;
41066
41096
  }
41097
+ const oldMatrix = this.transformation.toMatrix();
41067
41098
  this.transformation.scaleByTranslateBy({
41068
41099
  x: scaleX,
41069
41100
  y: scaleY
@@ -41071,6 +41102,16 @@ class Frame2 extends BaseItem {
41071
41102
  x: translateX,
41072
41103
  y: translateY
41073
41104
  }, timeStamp);
41105
+ const newMatrix = this.transformation.toMatrix();
41106
+ if (newMatrix.translateX !== oldMatrix.translateX || newMatrix.translateY !== oldMatrix.translateY) {
41107
+ const dx = newMatrix.translateX - oldMatrix.translateX;
41108
+ const dy = newMatrix.translateY - oldMatrix.translateY;
41109
+ this.index?.list().forEach((child) => {
41110
+ if (child instanceof BaseItem) {
41111
+ child.transformation.translateBy(-dx, -dy, timeStamp);
41112
+ }
41113
+ });
41114
+ }
41074
41115
  this.setLastFrameScale();
41075
41116
  res.mbr = this.getMbr();
41076
41117
  return res;
@@ -41347,8 +41388,9 @@ class Frame2 extends BaseItem {
41347
41388
  this.renderPath(context);
41348
41389
  const ctx = context.ctx;
41349
41390
  ctx.save();
41350
- this.transformation.applyToContext(ctx);
41351
- for (const child of this.index.list()) {
41391
+ const { translateX, translateY } = this.getWorldMatrix();
41392
+ ctx.translate(translateX, translateY);
41393
+ for (const child of this.index.items.listAll()) {
41352
41394
  child.render(context);
41353
41395
  }
41354
41396
  ctx.restore();
package/dist/cjs/index.js CHANGED
@@ -17752,9 +17752,15 @@ class TransformationCommand {
17752
17752
  transformation;
17753
17753
  operation;
17754
17754
  reverse;
17755
- constructor(transformation, operation) {
17755
+ itemsMap = new Map;
17756
+ constructor(transformation, operation, items) {
17756
17757
  this.transformation = transformation;
17757
17758
  this.operation = operation;
17759
+ if (items) {
17760
+ for (const item of items) {
17761
+ this.itemsMap.set(item.transformation, item);
17762
+ }
17763
+ }
17758
17764
  this.reverse = this.getReverse();
17759
17765
  }
17760
17766
  merge(op) {
@@ -17764,12 +17770,22 @@ class TransformationCommand {
17764
17770
  }
17765
17771
  apply() {
17766
17772
  for (const transformation of this.transformation) {
17767
- transformation.apply(this.operation);
17773
+ const item = this.itemsMap.get(transformation);
17774
+ if (item) {
17775
+ item.apply(this.operation);
17776
+ } else {
17777
+ transformation.apply(this.operation);
17778
+ }
17768
17779
  }
17769
17780
  }
17770
17781
  revert() {
17771
- this.reverse.forEach(({ item, operation }) => {
17772
- item.apply(operation);
17782
+ this.reverse.forEach(({ item: transformation, operation }) => {
17783
+ const item = this.itemsMap.get(transformation);
17784
+ if (item) {
17785
+ item.apply(operation);
17786
+ } else {
17787
+ transformation.apply(operation);
17788
+ }
17773
17789
  });
17774
17790
  }
17775
17791
  getReverse() {
@@ -19754,7 +19770,7 @@ function createRichTextCommand(items, operation, board) {
19754
19770
  }
19755
19771
  }
19756
19772
  function createTransformationCommand(items, operation) {
19757
- return new TransformationCommand(items.map((item) => item.transformation), operation);
19773
+ return new TransformationCommand(items.map((item) => item.transformation), operation, items);
19758
19774
  }
19759
19775
  function createLinkToCommand(items, operation) {
19760
19776
  return new LinkToCommand(items.map((item) => item.linkTo), operation);
@@ -21778,15 +21794,32 @@ class BaseItem extends Mbr {
21778
21794
  getId() {
21779
21795
  return this.id;
21780
21796
  }
21781
- getWorldMatrix() {
21797
+ getParentWorldMatrix() {
21782
21798
  if (this.parent === "Board") {
21783
- return this.transformation.toMatrix();
21799
+ return new Matrix;
21784
21800
  }
21785
21801
  const container = this.board.items.getById(this.parent);
21786
21802
  if (!container) {
21803
+ return new Matrix;
21804
+ }
21805
+ const matrix = container.getWorldMatrix();
21806
+ if (container.itemType === "Frame") {
21807
+ return new Matrix(matrix.translateX, matrix.translateY, 1, 1, 0, 0);
21808
+ }
21809
+ return matrix;
21810
+ }
21811
+ getWorldMatrix() {
21812
+ if (this.parent === "Board") {
21787
21813
  return this.transformation.toMatrix();
21788
21814
  }
21789
- return this.transformation.toMatrix().composeWith(container.getWorldMatrix());
21815
+ return this.transformation.toMatrix().composeWith(this.getParentWorldMatrix());
21816
+ }
21817
+ getNestingMatrix() {
21818
+ const matrix = this.getWorldMatrix();
21819
+ if (this.itemType === "Frame") {
21820
+ return new Matrix(matrix.translateX, matrix.translateY, 1, 1, 0, 0);
21821
+ }
21822
+ return matrix;
21790
21823
  }
21791
21824
  setId(id) {
21792
21825
  this.id = id;
@@ -21869,7 +21902,7 @@ class BaseItem extends Mbr {
21869
21902
  const container = this.board.items.getById(this.parent);
21870
21903
  if (!container)
21871
21904
  return this.getMbr();
21872
- const worldMatrix = container.getWorldMatrix();
21905
+ const parentMatrix = this.getParentWorldMatrix();
21873
21906
  const local = this.getMbr();
21874
21907
  const corners = [
21875
21908
  new Point(local.left, local.top),
@@ -21878,19 +21911,19 @@ class BaseItem extends Mbr {
21878
21911
  new Point(local.left, local.bottom)
21879
21912
  ];
21880
21913
  for (const c of corners)
21881
- worldMatrix.apply(c);
21914
+ parentMatrix.apply(c);
21882
21915
  return new Mbr(Math.min(corners[0].x, corners[1].x, corners[2].x, corners[3].x), Math.min(corners[0].y, corners[1].y, corners[2].y, corners[3].y), Math.max(corners[0].x, corners[1].x, corners[2].x, corners[3].x), Math.max(corners[0].y, corners[1].y, corners[2].y, corners[3].y));
21883
21916
  }
21884
21917
  applyAddChildren(childIds) {
21885
21918
  if (!this.index) {
21886
21919
  return;
21887
21920
  }
21888
- const containerWorldMatrix = this.getWorldMatrix();
21921
+ const containerNestingMatrix = this.getNestingMatrix();
21889
21922
  childIds.forEach((childId) => {
21890
21923
  const foundItem = this.board.items.getById(childId);
21891
21924
  if (this.parent !== childId && this.getId() !== childId) {
21892
21925
  if (!this.index?.getById(childId) && foundItem) {
21893
- const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerWorldMatrix);
21926
+ const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerNestingMatrix);
21894
21927
  this.board.items.index.remove(foundItem);
21895
21928
  foundItem.parent = this.getId();
21896
21929
  foundItem.transformation.setLocalMatrix(localMatrix);
@@ -21906,12 +21939,12 @@ class BaseItem extends Mbr {
21906
21939
  if (!this.index) {
21907
21940
  return;
21908
21941
  }
21909
- const containerWorldMatrix = this.getWorldMatrix();
21942
+ const containerNestingMatrix = this.getNestingMatrix();
21910
21943
  childIds.forEach((childId) => {
21911
21944
  const foundItem = this.index?.getById(childId);
21912
21945
  if (this.parent !== childId && this.getId() !== childId) {
21913
21946
  if (foundItem) {
21914
- const worldMatrix = foundItem.transformation.toMatrix().composeWith(containerWorldMatrix);
21947
+ const worldMatrix = foundItem.transformation.toMatrix().composeWith(containerNestingMatrix);
21915
21948
  this.index?.remove(foundItem);
21916
21949
  foundItem.parent = "Board";
21917
21950
  foundItem.transformation.setLocalMatrix(worldMatrix);
@@ -22031,7 +22064,7 @@ class BaseItem extends Mbr {
22031
22064
  if (this.parent !== "Board") {
22032
22065
  const container = this.board.items.getById(this.parent);
22033
22066
  if (container?.transformation) {
22034
- transformOp = toLocalTransformOp(transformOp, container.getWorldMatrix(), this.id);
22067
+ transformOp = toLocalTransformOp(transformOp, container.getNestingMatrix(), this.id);
22035
22068
  }
22036
22069
  }
22037
22070
  this.transformation.apply(transformOp);
@@ -22828,11 +22861,8 @@ class RichText extends BaseItem {
22828
22861
  const { ctx } = context;
22829
22862
  ctx.save();
22830
22863
  ctx.translate(this.left, this.top);
22831
- const shouldScale = !this.isInShape && !this.autoSize;
22832
- if (shouldScale) {
22833
- const { scaleX, scaleY } = this.transformation.getMatrixData();
22834
- ctx.scale(scaleX, scaleY);
22835
- }
22864
+ const { scaleX, scaleY } = this.transformation.getMatrixData();
22865
+ ctx.scale(scaleX, scaleY);
22836
22866
  const shouldClip = this.insideOf === "Shape" || this.insideOf === "Sticker";
22837
22867
  if (shouldClip) {
22838
22868
  ctx.clip(this.clipPath.nativePath);
@@ -41064,6 +41094,7 @@ class Frame2 extends BaseItem {
41064
41094
  scaleY = 1;
41065
41095
  translateY = 0;
41066
41096
  }
41097
+ const oldMatrix = this.transformation.toMatrix();
41067
41098
  this.transformation.scaleByTranslateBy({
41068
41099
  x: scaleX,
41069
41100
  y: scaleY
@@ -41071,6 +41102,16 @@ class Frame2 extends BaseItem {
41071
41102
  x: translateX,
41072
41103
  y: translateY
41073
41104
  }, timeStamp);
41105
+ const newMatrix = this.transformation.toMatrix();
41106
+ if (newMatrix.translateX !== oldMatrix.translateX || newMatrix.translateY !== oldMatrix.translateY) {
41107
+ const dx = newMatrix.translateX - oldMatrix.translateX;
41108
+ const dy = newMatrix.translateY - oldMatrix.translateY;
41109
+ this.index?.list().forEach((child) => {
41110
+ if (child instanceof BaseItem) {
41111
+ child.transformation.translateBy(-dx, -dy, timeStamp);
41112
+ }
41113
+ });
41114
+ }
41074
41115
  this.setLastFrameScale();
41075
41116
  res.mbr = this.getMbr();
41076
41117
  return res;
@@ -41347,8 +41388,9 @@ class Frame2 extends BaseItem {
41347
41388
  this.renderPath(context);
41348
41389
  const ctx = context.ctx;
41349
41390
  ctx.save();
41350
- this.transformation.applyToContext(ctx);
41351
- for (const child of this.index.list()) {
41391
+ const { translateX, translateY } = this.getWorldMatrix();
41392
+ ctx.translate(translateX, translateY);
41393
+ for (const child of this.index.items.listAll()) {
41352
41394
  child.render(context);
41353
41395
  }
41354
41396
  ctx.restore();
package/dist/cjs/node.js CHANGED
@@ -20292,9 +20292,15 @@ class TransformationCommand {
20292
20292
  transformation;
20293
20293
  operation;
20294
20294
  reverse;
20295
- constructor(transformation, operation) {
20295
+ itemsMap = new Map;
20296
+ constructor(transformation, operation, items) {
20296
20297
  this.transformation = transformation;
20297
20298
  this.operation = operation;
20299
+ if (items) {
20300
+ for (const item of items) {
20301
+ this.itemsMap.set(item.transformation, item);
20302
+ }
20303
+ }
20298
20304
  this.reverse = this.getReverse();
20299
20305
  }
20300
20306
  merge(op) {
@@ -20304,12 +20310,22 @@ class TransformationCommand {
20304
20310
  }
20305
20311
  apply() {
20306
20312
  for (const transformation of this.transformation) {
20307
- transformation.apply(this.operation);
20313
+ const item = this.itemsMap.get(transformation);
20314
+ if (item) {
20315
+ item.apply(this.operation);
20316
+ } else {
20317
+ transformation.apply(this.operation);
20318
+ }
20308
20319
  }
20309
20320
  }
20310
20321
  revert() {
20311
- this.reverse.forEach(({ item, operation }) => {
20312
- item.apply(operation);
20322
+ this.reverse.forEach(({ item: transformation, operation }) => {
20323
+ const item = this.itemsMap.get(transformation);
20324
+ if (item) {
20325
+ item.apply(operation);
20326
+ } else {
20327
+ transformation.apply(operation);
20328
+ }
20313
20329
  });
20314
20330
  }
20315
20331
  getReverse() {
@@ -22293,7 +22309,7 @@ function createRichTextCommand(items, operation, board) {
22293
22309
  }
22294
22310
  }
22295
22311
  function createTransformationCommand(items, operation) {
22296
- return new TransformationCommand(items.map((item) => item.transformation), operation);
22312
+ return new TransformationCommand(items.map((item) => item.transformation), operation, items);
22297
22313
  }
22298
22314
  function createLinkToCommand(items, operation) {
22299
22315
  return new LinkToCommand(items.map((item) => item.linkTo), operation);
@@ -24250,15 +24266,32 @@ class BaseItem extends Mbr {
24250
24266
  getId() {
24251
24267
  return this.id;
24252
24268
  }
24253
- getWorldMatrix() {
24269
+ getParentWorldMatrix() {
24254
24270
  if (this.parent === "Board") {
24255
- return this.transformation.toMatrix();
24271
+ return new Matrix;
24256
24272
  }
24257
24273
  const container = this.board.items.getById(this.parent);
24258
24274
  if (!container) {
24275
+ return new Matrix;
24276
+ }
24277
+ const matrix = container.getWorldMatrix();
24278
+ if (container.itemType === "Frame") {
24279
+ return new Matrix(matrix.translateX, matrix.translateY, 1, 1, 0, 0);
24280
+ }
24281
+ return matrix;
24282
+ }
24283
+ getWorldMatrix() {
24284
+ if (this.parent === "Board") {
24259
24285
  return this.transformation.toMatrix();
24260
24286
  }
24261
- return this.transformation.toMatrix().composeWith(container.getWorldMatrix());
24287
+ return this.transformation.toMatrix().composeWith(this.getParentWorldMatrix());
24288
+ }
24289
+ getNestingMatrix() {
24290
+ const matrix = this.getWorldMatrix();
24291
+ if (this.itemType === "Frame") {
24292
+ return new Matrix(matrix.translateX, matrix.translateY, 1, 1, 0, 0);
24293
+ }
24294
+ return matrix;
24262
24295
  }
24263
24296
  setId(id) {
24264
24297
  this.id = id;
@@ -24341,7 +24374,7 @@ class BaseItem extends Mbr {
24341
24374
  const container = this.board.items.getById(this.parent);
24342
24375
  if (!container)
24343
24376
  return this.getMbr();
24344
- const worldMatrix = container.getWorldMatrix();
24377
+ const parentMatrix = this.getParentWorldMatrix();
24345
24378
  const local = this.getMbr();
24346
24379
  const corners = [
24347
24380
  new Point(local.left, local.top),
@@ -24350,19 +24383,19 @@ class BaseItem extends Mbr {
24350
24383
  new Point(local.left, local.bottom)
24351
24384
  ];
24352
24385
  for (const c of corners)
24353
- worldMatrix.apply(c);
24386
+ parentMatrix.apply(c);
24354
24387
  return new Mbr(Math.min(corners[0].x, corners[1].x, corners[2].x, corners[3].x), Math.min(corners[0].y, corners[1].y, corners[2].y, corners[3].y), Math.max(corners[0].x, corners[1].x, corners[2].x, corners[3].x), Math.max(corners[0].y, corners[1].y, corners[2].y, corners[3].y));
24355
24388
  }
24356
24389
  applyAddChildren(childIds) {
24357
24390
  if (!this.index) {
24358
24391
  return;
24359
24392
  }
24360
- const containerWorldMatrix = this.getWorldMatrix();
24393
+ const containerNestingMatrix = this.getNestingMatrix();
24361
24394
  childIds.forEach((childId) => {
24362
24395
  const foundItem = this.board.items.getById(childId);
24363
24396
  if (this.parent !== childId && this.getId() !== childId) {
24364
24397
  if (!this.index?.getById(childId) && foundItem) {
24365
- const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerWorldMatrix);
24398
+ const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerNestingMatrix);
24366
24399
  this.board.items.index.remove(foundItem);
24367
24400
  foundItem.parent = this.getId();
24368
24401
  foundItem.transformation.setLocalMatrix(localMatrix);
@@ -24378,12 +24411,12 @@ class BaseItem extends Mbr {
24378
24411
  if (!this.index) {
24379
24412
  return;
24380
24413
  }
24381
- const containerWorldMatrix = this.getWorldMatrix();
24414
+ const containerNestingMatrix = this.getNestingMatrix();
24382
24415
  childIds.forEach((childId) => {
24383
24416
  const foundItem = this.index?.getById(childId);
24384
24417
  if (this.parent !== childId && this.getId() !== childId) {
24385
24418
  if (foundItem) {
24386
- const worldMatrix = foundItem.transformation.toMatrix().composeWith(containerWorldMatrix);
24419
+ const worldMatrix = foundItem.transformation.toMatrix().composeWith(containerNestingMatrix);
24387
24420
  this.index?.remove(foundItem);
24388
24421
  foundItem.parent = "Board";
24389
24422
  foundItem.transformation.setLocalMatrix(worldMatrix);
@@ -24503,7 +24536,7 @@ class BaseItem extends Mbr {
24503
24536
  if (this.parent !== "Board") {
24504
24537
  const container = this.board.items.getById(this.parent);
24505
24538
  if (container?.transformation) {
24506
- transformOp = toLocalTransformOp(transformOp, container.getWorldMatrix(), this.id);
24539
+ transformOp = toLocalTransformOp(transformOp, container.getNestingMatrix(), this.id);
24507
24540
  }
24508
24541
  }
24509
24542
  this.transformation.apply(transformOp);
@@ -25300,11 +25333,8 @@ class RichText extends BaseItem {
25300
25333
  const { ctx } = context;
25301
25334
  ctx.save();
25302
25335
  ctx.translate(this.left, this.top);
25303
- const shouldScale = !this.isInShape && !this.autoSize;
25304
- if (shouldScale) {
25305
- const { scaleX, scaleY } = this.transformation.getMatrixData();
25306
- ctx.scale(scaleX, scaleY);
25307
- }
25336
+ const { scaleX, scaleY } = this.transformation.getMatrixData();
25337
+ ctx.scale(scaleX, scaleY);
25308
25338
  const shouldClip = this.insideOf === "Shape" || this.insideOf === "Sticker";
25309
25339
  if (shouldClip) {
25310
25340
  ctx.clip(this.clipPath.nativePath);
@@ -43537,6 +43567,7 @@ class Frame2 extends BaseItem {
43537
43567
  scaleY = 1;
43538
43568
  translateY = 0;
43539
43569
  }
43570
+ const oldMatrix = this.transformation.toMatrix();
43540
43571
  this.transformation.scaleByTranslateBy({
43541
43572
  x: scaleX,
43542
43573
  y: scaleY
@@ -43544,6 +43575,16 @@ class Frame2 extends BaseItem {
43544
43575
  x: translateX,
43545
43576
  y: translateY
43546
43577
  }, timeStamp);
43578
+ const newMatrix = this.transformation.toMatrix();
43579
+ if (newMatrix.translateX !== oldMatrix.translateX || newMatrix.translateY !== oldMatrix.translateY) {
43580
+ const dx = newMatrix.translateX - oldMatrix.translateX;
43581
+ const dy = newMatrix.translateY - oldMatrix.translateY;
43582
+ this.index?.list().forEach((child) => {
43583
+ if (child instanceof BaseItem) {
43584
+ child.transformation.translateBy(-dx, -dy, timeStamp);
43585
+ }
43586
+ });
43587
+ }
43547
43588
  this.setLastFrameScale();
43548
43589
  res.mbr = this.getMbr();
43549
43590
  return res;
@@ -43820,8 +43861,9 @@ class Frame2 extends BaseItem {
43820
43861
  this.renderPath(context);
43821
43862
  const ctx = context.ctx;
43822
43863
  ctx.save();
43823
- this.transformation.applyToContext(ctx);
43824
- for (const child of this.index.list()) {
43864
+ const { translateX, translateY } = this.getWorldMatrix();
43865
+ ctx.translate(translateX, translateY);
43866
+ for (const child of this.index.items.listAll()) {
43825
43867
  child.render(context);
43826
43868
  }
43827
43869
  ctx.restore();
@@ -17581,9 +17581,15 @@ class TransformationCommand {
17581
17581
  transformation;
17582
17582
  operation;
17583
17583
  reverse;
17584
- constructor(transformation, operation) {
17584
+ itemsMap = new Map;
17585
+ constructor(transformation, operation, items) {
17585
17586
  this.transformation = transformation;
17586
17587
  this.operation = operation;
17588
+ if (items) {
17589
+ for (const item of items) {
17590
+ this.itemsMap.set(item.transformation, item);
17591
+ }
17592
+ }
17587
17593
  this.reverse = this.getReverse();
17588
17594
  }
17589
17595
  merge(op) {
@@ -17593,12 +17599,22 @@ class TransformationCommand {
17593
17599
  }
17594
17600
  apply() {
17595
17601
  for (const transformation of this.transformation) {
17596
- transformation.apply(this.operation);
17602
+ const item = this.itemsMap.get(transformation);
17603
+ if (item) {
17604
+ item.apply(this.operation);
17605
+ } else {
17606
+ transformation.apply(this.operation);
17607
+ }
17597
17608
  }
17598
17609
  }
17599
17610
  revert() {
17600
- this.reverse.forEach(({ item, operation }) => {
17601
- item.apply(operation);
17611
+ this.reverse.forEach(({ item: transformation, operation }) => {
17612
+ const item = this.itemsMap.get(transformation);
17613
+ if (item) {
17614
+ item.apply(operation);
17615
+ } else {
17616
+ transformation.apply(operation);
17617
+ }
17602
17618
  });
17603
17619
  }
17604
17620
  getReverse() {
@@ -19583,7 +19599,7 @@ function createRichTextCommand(items, operation, board) {
19583
19599
  }
19584
19600
  }
19585
19601
  function createTransformationCommand(items, operation) {
19586
- return new TransformationCommand(items.map((item) => item.transformation), operation);
19602
+ return new TransformationCommand(items.map((item) => item.transformation), operation, items);
19587
19603
  }
19588
19604
  function createLinkToCommand(items, operation) {
19589
19605
  return new LinkToCommand(items.map((item) => item.linkTo), operation);
@@ -21607,15 +21623,32 @@ class BaseItem extends Mbr {
21607
21623
  getId() {
21608
21624
  return this.id;
21609
21625
  }
21610
- getWorldMatrix() {
21626
+ getParentWorldMatrix() {
21611
21627
  if (this.parent === "Board") {
21612
- return this.transformation.toMatrix();
21628
+ return new Matrix;
21613
21629
  }
21614
21630
  const container = this.board.items.getById(this.parent);
21615
21631
  if (!container) {
21632
+ return new Matrix;
21633
+ }
21634
+ const matrix = container.getWorldMatrix();
21635
+ if (container.itemType === "Frame") {
21636
+ return new Matrix(matrix.translateX, matrix.translateY, 1, 1, 0, 0);
21637
+ }
21638
+ return matrix;
21639
+ }
21640
+ getWorldMatrix() {
21641
+ if (this.parent === "Board") {
21616
21642
  return this.transformation.toMatrix();
21617
21643
  }
21618
- return this.transformation.toMatrix().composeWith(container.getWorldMatrix());
21644
+ return this.transformation.toMatrix().composeWith(this.getParentWorldMatrix());
21645
+ }
21646
+ getNestingMatrix() {
21647
+ const matrix = this.getWorldMatrix();
21648
+ if (this.itemType === "Frame") {
21649
+ return new Matrix(matrix.translateX, matrix.translateY, 1, 1, 0, 0);
21650
+ }
21651
+ return matrix;
21619
21652
  }
21620
21653
  setId(id) {
21621
21654
  this.id = id;
@@ -21698,7 +21731,7 @@ class BaseItem extends Mbr {
21698
21731
  const container = this.board.items.getById(this.parent);
21699
21732
  if (!container)
21700
21733
  return this.getMbr();
21701
- const worldMatrix = container.getWorldMatrix();
21734
+ const parentMatrix = this.getParentWorldMatrix();
21702
21735
  const local = this.getMbr();
21703
21736
  const corners = [
21704
21737
  new Point(local.left, local.top),
@@ -21707,19 +21740,19 @@ class BaseItem extends Mbr {
21707
21740
  new Point(local.left, local.bottom)
21708
21741
  ];
21709
21742
  for (const c of corners)
21710
- worldMatrix.apply(c);
21743
+ parentMatrix.apply(c);
21711
21744
  return new Mbr(Math.min(corners[0].x, corners[1].x, corners[2].x, corners[3].x), Math.min(corners[0].y, corners[1].y, corners[2].y, corners[3].y), Math.max(corners[0].x, corners[1].x, corners[2].x, corners[3].x), Math.max(corners[0].y, corners[1].y, corners[2].y, corners[3].y));
21712
21745
  }
21713
21746
  applyAddChildren(childIds) {
21714
21747
  if (!this.index) {
21715
21748
  return;
21716
21749
  }
21717
- const containerWorldMatrix = this.getWorldMatrix();
21750
+ const containerNestingMatrix = this.getNestingMatrix();
21718
21751
  childIds.forEach((childId) => {
21719
21752
  const foundItem = this.board.items.getById(childId);
21720
21753
  if (this.parent !== childId && this.getId() !== childId) {
21721
21754
  if (!this.index?.getById(childId) && foundItem) {
21722
- const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerWorldMatrix);
21755
+ const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerNestingMatrix);
21723
21756
  this.board.items.index.remove(foundItem);
21724
21757
  foundItem.parent = this.getId();
21725
21758
  foundItem.transformation.setLocalMatrix(localMatrix);
@@ -21735,12 +21768,12 @@ class BaseItem extends Mbr {
21735
21768
  if (!this.index) {
21736
21769
  return;
21737
21770
  }
21738
- const containerWorldMatrix = this.getWorldMatrix();
21771
+ const containerNestingMatrix = this.getNestingMatrix();
21739
21772
  childIds.forEach((childId) => {
21740
21773
  const foundItem = this.index?.getById(childId);
21741
21774
  if (this.parent !== childId && this.getId() !== childId) {
21742
21775
  if (foundItem) {
21743
- const worldMatrix = foundItem.transformation.toMatrix().composeWith(containerWorldMatrix);
21776
+ const worldMatrix = foundItem.transformation.toMatrix().composeWith(containerNestingMatrix);
21744
21777
  this.index?.remove(foundItem);
21745
21778
  foundItem.parent = "Board";
21746
21779
  foundItem.transformation.setLocalMatrix(worldMatrix);
@@ -21860,7 +21893,7 @@ class BaseItem extends Mbr {
21860
21893
  if (this.parent !== "Board") {
21861
21894
  const container = this.board.items.getById(this.parent);
21862
21895
  if (container?.transformation) {
21863
- transformOp = toLocalTransformOp(transformOp, container.getWorldMatrix(), this.id);
21896
+ transformOp = toLocalTransformOp(transformOp, container.getNestingMatrix(), this.id);
21864
21897
  }
21865
21898
  }
21866
21899
  this.transformation.apply(transformOp);
@@ -22657,11 +22690,8 @@ class RichText extends BaseItem {
22657
22690
  const { ctx } = context;
22658
22691
  ctx.save();
22659
22692
  ctx.translate(this.left, this.top);
22660
- const shouldScale = !this.isInShape && !this.autoSize;
22661
- if (shouldScale) {
22662
- const { scaleX, scaleY } = this.transformation.getMatrixData();
22663
- ctx.scale(scaleX, scaleY);
22664
- }
22693
+ const { scaleX, scaleY } = this.transformation.getMatrixData();
22694
+ ctx.scale(scaleX, scaleY);
22665
22695
  const shouldClip = this.insideOf === "Shape" || this.insideOf === "Sticker";
22666
22696
  if (shouldClip) {
22667
22697
  ctx.clip(this.clipPath.nativePath);
@@ -40893,6 +40923,7 @@ class Frame2 extends BaseItem {
40893
40923
  scaleY = 1;
40894
40924
  translateY = 0;
40895
40925
  }
40926
+ const oldMatrix = this.transformation.toMatrix();
40896
40927
  this.transformation.scaleByTranslateBy({
40897
40928
  x: scaleX,
40898
40929
  y: scaleY
@@ -40900,6 +40931,16 @@ class Frame2 extends BaseItem {
40900
40931
  x: translateX,
40901
40932
  y: translateY
40902
40933
  }, timeStamp);
40934
+ const newMatrix = this.transformation.toMatrix();
40935
+ if (newMatrix.translateX !== oldMatrix.translateX || newMatrix.translateY !== oldMatrix.translateY) {
40936
+ const dx = newMatrix.translateX - oldMatrix.translateX;
40937
+ const dy = newMatrix.translateY - oldMatrix.translateY;
40938
+ this.index?.list().forEach((child) => {
40939
+ if (child instanceof BaseItem) {
40940
+ child.transformation.translateBy(-dx, -dy, timeStamp);
40941
+ }
40942
+ });
40943
+ }
40903
40944
  this.setLastFrameScale();
40904
40945
  res.mbr = this.getMbr();
40905
40946
  return res;
@@ -41176,8 +41217,9 @@ class Frame2 extends BaseItem {
41176
41217
  this.renderPath(context);
41177
41218
  const ctx = context.ctx;
41178
41219
  ctx.save();
41179
- this.transformation.applyToContext(ctx);
41180
- for (const child of this.index.list()) {
41220
+ const { translateX, translateY } = this.getWorldMatrix();
41221
+ ctx.translate(translateX, translateY);
41222
+ for (const child of this.index.items.listAll()) {
41181
41223
  child.render(context);
41182
41224
  }
41183
41225
  ctx.restore();
package/dist/esm/index.js CHANGED
@@ -17574,9 +17574,15 @@ class TransformationCommand {
17574
17574
  transformation;
17575
17575
  operation;
17576
17576
  reverse;
17577
- constructor(transformation, operation) {
17577
+ itemsMap = new Map;
17578
+ constructor(transformation, operation, items) {
17578
17579
  this.transformation = transformation;
17579
17580
  this.operation = operation;
17581
+ if (items) {
17582
+ for (const item of items) {
17583
+ this.itemsMap.set(item.transformation, item);
17584
+ }
17585
+ }
17580
17586
  this.reverse = this.getReverse();
17581
17587
  }
17582
17588
  merge(op) {
@@ -17586,12 +17592,22 @@ class TransformationCommand {
17586
17592
  }
17587
17593
  apply() {
17588
17594
  for (const transformation of this.transformation) {
17589
- transformation.apply(this.operation);
17595
+ const item = this.itemsMap.get(transformation);
17596
+ if (item) {
17597
+ item.apply(this.operation);
17598
+ } else {
17599
+ transformation.apply(this.operation);
17600
+ }
17590
17601
  }
17591
17602
  }
17592
17603
  revert() {
17593
- this.reverse.forEach(({ item, operation }) => {
17594
- item.apply(operation);
17604
+ this.reverse.forEach(({ item: transformation, operation }) => {
17605
+ const item = this.itemsMap.get(transformation);
17606
+ if (item) {
17607
+ item.apply(operation);
17608
+ } else {
17609
+ transformation.apply(operation);
17610
+ }
17595
17611
  });
17596
17612
  }
17597
17613
  getReverse() {
@@ -19576,7 +19592,7 @@ function createRichTextCommand(items, operation, board) {
19576
19592
  }
19577
19593
  }
19578
19594
  function createTransformationCommand(items, operation) {
19579
- return new TransformationCommand(items.map((item) => item.transformation), operation);
19595
+ return new TransformationCommand(items.map((item) => item.transformation), operation, items);
19580
19596
  }
19581
19597
  function createLinkToCommand(items, operation) {
19582
19598
  return new LinkToCommand(items.map((item) => item.linkTo), operation);
@@ -21600,15 +21616,32 @@ class BaseItem extends Mbr {
21600
21616
  getId() {
21601
21617
  return this.id;
21602
21618
  }
21603
- getWorldMatrix() {
21619
+ getParentWorldMatrix() {
21604
21620
  if (this.parent === "Board") {
21605
- return this.transformation.toMatrix();
21621
+ return new Matrix;
21606
21622
  }
21607
21623
  const container = this.board.items.getById(this.parent);
21608
21624
  if (!container) {
21625
+ return new Matrix;
21626
+ }
21627
+ const matrix = container.getWorldMatrix();
21628
+ if (container.itemType === "Frame") {
21629
+ return new Matrix(matrix.translateX, matrix.translateY, 1, 1, 0, 0);
21630
+ }
21631
+ return matrix;
21632
+ }
21633
+ getWorldMatrix() {
21634
+ if (this.parent === "Board") {
21609
21635
  return this.transformation.toMatrix();
21610
21636
  }
21611
- return this.transformation.toMatrix().composeWith(container.getWorldMatrix());
21637
+ return this.transformation.toMatrix().composeWith(this.getParentWorldMatrix());
21638
+ }
21639
+ getNestingMatrix() {
21640
+ const matrix = this.getWorldMatrix();
21641
+ if (this.itemType === "Frame") {
21642
+ return new Matrix(matrix.translateX, matrix.translateY, 1, 1, 0, 0);
21643
+ }
21644
+ return matrix;
21612
21645
  }
21613
21646
  setId(id) {
21614
21647
  this.id = id;
@@ -21691,7 +21724,7 @@ class BaseItem extends Mbr {
21691
21724
  const container = this.board.items.getById(this.parent);
21692
21725
  if (!container)
21693
21726
  return this.getMbr();
21694
- const worldMatrix = container.getWorldMatrix();
21727
+ const parentMatrix = this.getParentWorldMatrix();
21695
21728
  const local = this.getMbr();
21696
21729
  const corners = [
21697
21730
  new Point(local.left, local.top),
@@ -21700,19 +21733,19 @@ class BaseItem extends Mbr {
21700
21733
  new Point(local.left, local.bottom)
21701
21734
  ];
21702
21735
  for (const c of corners)
21703
- worldMatrix.apply(c);
21736
+ parentMatrix.apply(c);
21704
21737
  return new Mbr(Math.min(corners[0].x, corners[1].x, corners[2].x, corners[3].x), Math.min(corners[0].y, corners[1].y, corners[2].y, corners[3].y), Math.max(corners[0].x, corners[1].x, corners[2].x, corners[3].x), Math.max(corners[0].y, corners[1].y, corners[2].y, corners[3].y));
21705
21738
  }
21706
21739
  applyAddChildren(childIds) {
21707
21740
  if (!this.index) {
21708
21741
  return;
21709
21742
  }
21710
- const containerWorldMatrix = this.getWorldMatrix();
21743
+ const containerNestingMatrix = this.getNestingMatrix();
21711
21744
  childIds.forEach((childId) => {
21712
21745
  const foundItem = this.board.items.getById(childId);
21713
21746
  if (this.parent !== childId && this.getId() !== childId) {
21714
21747
  if (!this.index?.getById(childId) && foundItem) {
21715
- const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerWorldMatrix);
21748
+ const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerNestingMatrix);
21716
21749
  this.board.items.index.remove(foundItem);
21717
21750
  foundItem.parent = this.getId();
21718
21751
  foundItem.transformation.setLocalMatrix(localMatrix);
@@ -21728,12 +21761,12 @@ class BaseItem extends Mbr {
21728
21761
  if (!this.index) {
21729
21762
  return;
21730
21763
  }
21731
- const containerWorldMatrix = this.getWorldMatrix();
21764
+ const containerNestingMatrix = this.getNestingMatrix();
21732
21765
  childIds.forEach((childId) => {
21733
21766
  const foundItem = this.index?.getById(childId);
21734
21767
  if (this.parent !== childId && this.getId() !== childId) {
21735
21768
  if (foundItem) {
21736
- const worldMatrix = foundItem.transformation.toMatrix().composeWith(containerWorldMatrix);
21769
+ const worldMatrix = foundItem.transformation.toMatrix().composeWith(containerNestingMatrix);
21737
21770
  this.index?.remove(foundItem);
21738
21771
  foundItem.parent = "Board";
21739
21772
  foundItem.transformation.setLocalMatrix(worldMatrix);
@@ -21853,7 +21886,7 @@ class BaseItem extends Mbr {
21853
21886
  if (this.parent !== "Board") {
21854
21887
  const container = this.board.items.getById(this.parent);
21855
21888
  if (container?.transformation) {
21856
- transformOp = toLocalTransformOp(transformOp, container.getWorldMatrix(), this.id);
21889
+ transformOp = toLocalTransformOp(transformOp, container.getNestingMatrix(), this.id);
21857
21890
  }
21858
21891
  }
21859
21892
  this.transformation.apply(transformOp);
@@ -22650,11 +22683,8 @@ class RichText extends BaseItem {
22650
22683
  const { ctx } = context;
22651
22684
  ctx.save();
22652
22685
  ctx.translate(this.left, this.top);
22653
- const shouldScale = !this.isInShape && !this.autoSize;
22654
- if (shouldScale) {
22655
- const { scaleX, scaleY } = this.transformation.getMatrixData();
22656
- ctx.scale(scaleX, scaleY);
22657
- }
22686
+ const { scaleX, scaleY } = this.transformation.getMatrixData();
22687
+ ctx.scale(scaleX, scaleY);
22658
22688
  const shouldClip = this.insideOf === "Shape" || this.insideOf === "Sticker";
22659
22689
  if (shouldClip) {
22660
22690
  ctx.clip(this.clipPath.nativePath);
@@ -40886,6 +40916,7 @@ class Frame2 extends BaseItem {
40886
40916
  scaleY = 1;
40887
40917
  translateY = 0;
40888
40918
  }
40919
+ const oldMatrix = this.transformation.toMatrix();
40889
40920
  this.transformation.scaleByTranslateBy({
40890
40921
  x: scaleX,
40891
40922
  y: scaleY
@@ -40893,6 +40924,16 @@ class Frame2 extends BaseItem {
40893
40924
  x: translateX,
40894
40925
  y: translateY
40895
40926
  }, timeStamp);
40927
+ const newMatrix = this.transformation.toMatrix();
40928
+ if (newMatrix.translateX !== oldMatrix.translateX || newMatrix.translateY !== oldMatrix.translateY) {
40929
+ const dx = newMatrix.translateX - oldMatrix.translateX;
40930
+ const dy = newMatrix.translateY - oldMatrix.translateY;
40931
+ this.index?.list().forEach((child) => {
40932
+ if (child instanceof BaseItem) {
40933
+ child.transformation.translateBy(-dx, -dy, timeStamp);
40934
+ }
40935
+ });
40936
+ }
40896
40937
  this.setLastFrameScale();
40897
40938
  res.mbr = this.getMbr();
40898
40939
  return res;
@@ -41169,8 +41210,9 @@ class Frame2 extends BaseItem {
41169
41210
  this.renderPath(context);
41170
41211
  const ctx = context.ctx;
41171
41212
  ctx.save();
41172
- this.transformation.applyToContext(ctx);
41173
- for (const child of this.index.list()) {
41213
+ const { translateX, translateY } = this.getWorldMatrix();
41214
+ ctx.translate(translateX, translateY);
41215
+ for (const child of this.index.items.listAll()) {
41174
41216
  child.render(context);
41175
41217
  }
41176
41218
  ctx.restore();
package/dist/esm/node.js CHANGED
@@ -20109,9 +20109,15 @@ class TransformationCommand {
20109
20109
  transformation;
20110
20110
  operation;
20111
20111
  reverse;
20112
- constructor(transformation, operation) {
20112
+ itemsMap = new Map;
20113
+ constructor(transformation, operation, items) {
20113
20114
  this.transformation = transformation;
20114
20115
  this.operation = operation;
20116
+ if (items) {
20117
+ for (const item of items) {
20118
+ this.itemsMap.set(item.transformation, item);
20119
+ }
20120
+ }
20115
20121
  this.reverse = this.getReverse();
20116
20122
  }
20117
20123
  merge(op) {
@@ -20121,12 +20127,22 @@ class TransformationCommand {
20121
20127
  }
20122
20128
  apply() {
20123
20129
  for (const transformation of this.transformation) {
20124
- transformation.apply(this.operation);
20130
+ const item = this.itemsMap.get(transformation);
20131
+ if (item) {
20132
+ item.apply(this.operation);
20133
+ } else {
20134
+ transformation.apply(this.operation);
20135
+ }
20125
20136
  }
20126
20137
  }
20127
20138
  revert() {
20128
- this.reverse.forEach(({ item, operation }) => {
20129
- item.apply(operation);
20139
+ this.reverse.forEach(({ item: transformation, operation }) => {
20140
+ const item = this.itemsMap.get(transformation);
20141
+ if (item) {
20142
+ item.apply(operation);
20143
+ } else {
20144
+ transformation.apply(operation);
20145
+ }
20130
20146
  });
20131
20147
  }
20132
20148
  getReverse() {
@@ -22110,7 +22126,7 @@ function createRichTextCommand(items, operation, board) {
22110
22126
  }
22111
22127
  }
22112
22128
  function createTransformationCommand(items, operation) {
22113
- return new TransformationCommand(items.map((item) => item.transformation), operation);
22129
+ return new TransformationCommand(items.map((item) => item.transformation), operation, items);
22114
22130
  }
22115
22131
  function createLinkToCommand(items, operation) {
22116
22132
  return new LinkToCommand(items.map((item) => item.linkTo), operation);
@@ -24067,15 +24083,32 @@ class BaseItem extends Mbr {
24067
24083
  getId() {
24068
24084
  return this.id;
24069
24085
  }
24070
- getWorldMatrix() {
24086
+ getParentWorldMatrix() {
24071
24087
  if (this.parent === "Board") {
24072
- return this.transformation.toMatrix();
24088
+ return new Matrix;
24073
24089
  }
24074
24090
  const container = this.board.items.getById(this.parent);
24075
24091
  if (!container) {
24092
+ return new Matrix;
24093
+ }
24094
+ const matrix = container.getWorldMatrix();
24095
+ if (container.itemType === "Frame") {
24096
+ return new Matrix(matrix.translateX, matrix.translateY, 1, 1, 0, 0);
24097
+ }
24098
+ return matrix;
24099
+ }
24100
+ getWorldMatrix() {
24101
+ if (this.parent === "Board") {
24076
24102
  return this.transformation.toMatrix();
24077
24103
  }
24078
- return this.transformation.toMatrix().composeWith(container.getWorldMatrix());
24104
+ return this.transformation.toMatrix().composeWith(this.getParentWorldMatrix());
24105
+ }
24106
+ getNestingMatrix() {
24107
+ const matrix = this.getWorldMatrix();
24108
+ if (this.itemType === "Frame") {
24109
+ return new Matrix(matrix.translateX, matrix.translateY, 1, 1, 0, 0);
24110
+ }
24111
+ return matrix;
24079
24112
  }
24080
24113
  setId(id) {
24081
24114
  this.id = id;
@@ -24158,7 +24191,7 @@ class BaseItem extends Mbr {
24158
24191
  const container = this.board.items.getById(this.parent);
24159
24192
  if (!container)
24160
24193
  return this.getMbr();
24161
- const worldMatrix = container.getWorldMatrix();
24194
+ const parentMatrix = this.getParentWorldMatrix();
24162
24195
  const local = this.getMbr();
24163
24196
  const corners = [
24164
24197
  new Point(local.left, local.top),
@@ -24167,19 +24200,19 @@ class BaseItem extends Mbr {
24167
24200
  new Point(local.left, local.bottom)
24168
24201
  ];
24169
24202
  for (const c of corners)
24170
- worldMatrix.apply(c);
24203
+ parentMatrix.apply(c);
24171
24204
  return new Mbr(Math.min(corners[0].x, corners[1].x, corners[2].x, corners[3].x), Math.min(corners[0].y, corners[1].y, corners[2].y, corners[3].y), Math.max(corners[0].x, corners[1].x, corners[2].x, corners[3].x), Math.max(corners[0].y, corners[1].y, corners[2].y, corners[3].y));
24172
24205
  }
24173
24206
  applyAddChildren(childIds) {
24174
24207
  if (!this.index) {
24175
24208
  return;
24176
24209
  }
24177
- const containerWorldMatrix = this.getWorldMatrix();
24210
+ const containerNestingMatrix = this.getNestingMatrix();
24178
24211
  childIds.forEach((childId) => {
24179
24212
  const foundItem = this.board.items.getById(childId);
24180
24213
  if (this.parent !== childId && this.getId() !== childId) {
24181
24214
  if (!this.index?.getById(childId) && foundItem) {
24182
- const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerWorldMatrix);
24215
+ const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerNestingMatrix);
24183
24216
  this.board.items.index.remove(foundItem);
24184
24217
  foundItem.parent = this.getId();
24185
24218
  foundItem.transformation.setLocalMatrix(localMatrix);
@@ -24195,12 +24228,12 @@ class BaseItem extends Mbr {
24195
24228
  if (!this.index) {
24196
24229
  return;
24197
24230
  }
24198
- const containerWorldMatrix = this.getWorldMatrix();
24231
+ const containerNestingMatrix = this.getNestingMatrix();
24199
24232
  childIds.forEach((childId) => {
24200
24233
  const foundItem = this.index?.getById(childId);
24201
24234
  if (this.parent !== childId && this.getId() !== childId) {
24202
24235
  if (foundItem) {
24203
- const worldMatrix = foundItem.transformation.toMatrix().composeWith(containerWorldMatrix);
24236
+ const worldMatrix = foundItem.transformation.toMatrix().composeWith(containerNestingMatrix);
24204
24237
  this.index?.remove(foundItem);
24205
24238
  foundItem.parent = "Board";
24206
24239
  foundItem.transformation.setLocalMatrix(worldMatrix);
@@ -24320,7 +24353,7 @@ class BaseItem extends Mbr {
24320
24353
  if (this.parent !== "Board") {
24321
24354
  const container = this.board.items.getById(this.parent);
24322
24355
  if (container?.transformation) {
24323
- transformOp = toLocalTransformOp(transformOp, container.getWorldMatrix(), this.id);
24356
+ transformOp = toLocalTransformOp(transformOp, container.getNestingMatrix(), this.id);
24324
24357
  }
24325
24358
  }
24326
24359
  this.transformation.apply(transformOp);
@@ -25117,11 +25150,8 @@ class RichText extends BaseItem {
25117
25150
  const { ctx } = context;
25118
25151
  ctx.save();
25119
25152
  ctx.translate(this.left, this.top);
25120
- const shouldScale = !this.isInShape && !this.autoSize;
25121
- if (shouldScale) {
25122
- const { scaleX, scaleY } = this.transformation.getMatrixData();
25123
- ctx.scale(scaleX, scaleY);
25124
- }
25153
+ const { scaleX, scaleY } = this.transformation.getMatrixData();
25154
+ ctx.scale(scaleX, scaleY);
25125
25155
  const shouldClip = this.insideOf === "Shape" || this.insideOf === "Sticker";
25126
25156
  if (shouldClip) {
25127
25157
  ctx.clip(this.clipPath.nativePath);
@@ -43354,6 +43384,7 @@ class Frame2 extends BaseItem {
43354
43384
  scaleY = 1;
43355
43385
  translateY = 0;
43356
43386
  }
43387
+ const oldMatrix = this.transformation.toMatrix();
43357
43388
  this.transformation.scaleByTranslateBy({
43358
43389
  x: scaleX,
43359
43390
  y: scaleY
@@ -43361,6 +43392,16 @@ class Frame2 extends BaseItem {
43361
43392
  x: translateX,
43362
43393
  y: translateY
43363
43394
  }, timeStamp);
43395
+ const newMatrix = this.transformation.toMatrix();
43396
+ if (newMatrix.translateX !== oldMatrix.translateX || newMatrix.translateY !== oldMatrix.translateY) {
43397
+ const dx = newMatrix.translateX - oldMatrix.translateX;
43398
+ const dy = newMatrix.translateY - oldMatrix.translateY;
43399
+ this.index?.list().forEach((child) => {
43400
+ if (child instanceof BaseItem) {
43401
+ child.transformation.translateBy(-dx, -dy, timeStamp);
43402
+ }
43403
+ });
43404
+ }
43364
43405
  this.setLastFrameScale();
43365
43406
  res.mbr = this.getMbr();
43366
43407
  return res;
@@ -43637,8 +43678,9 @@ class Frame2 extends BaseItem {
43637
43678
  this.renderPath(context);
43638
43679
  const ctx = context.ctx;
43639
43680
  ctx.save();
43640
- this.transformation.applyToContext(ctx);
43641
- for (const child of this.index.list()) {
43681
+ const { translateX, translateY } = this.getWorldMatrix();
43682
+ ctx.translate(translateX, translateY);
43683
+ for (const child of this.index.items.listAll()) {
43642
43684
  child.render(context);
43643
43685
  }
43644
43686
  ctx.restore();
@@ -47,12 +47,23 @@ export declare class BaseItem extends Mbr implements Geometry {
47
47
  constructor(board: Board, id?: string, defaultItemData?: BaseItemData | undefined, isGroupItem?: boolean);
48
48
  updateChildrenIds(): void;
49
49
  getId(): string;
50
+ /**
51
+ * Returns the parent's world matrix. For Frames, only the translation component
52
+ * is returned to ensure children are not affected by frame scaling.
53
+ */
54
+ getParentWorldMatrix(): Matrix;
50
55
  /**
51
56
  * Returns the full world-space matrix by walking up the parent chain.
52
57
  * For top-level items (parent === "Board") this is identical to the item's
53
- * own transformation matrix. For nested items it is parentWorld × localMatrix.
58
+ * own transformation matrix. For nested items it is parentTransform × localMatrix.
59
+ * Note: Frames act as non-scaling containers.
54
60
  */
55
61
  getWorldMatrix(): Matrix;
62
+ /**
63
+ * Returns the matrix used for nesting children. For Frames, this is only
64
+ * the translation part. For other items it is the full world matrix.
65
+ */
66
+ getNestingMatrix(): Matrix;
56
67
  setId(id: string): this;
57
68
  getChildrenIds(): string[] | null;
58
69
  addChildItems(children: BaseItem[]): void;
@@ -1,6 +1,11 @@
1
1
  import { Transformation } from "./Transformation";
2
2
  import { TransformationOperation } from "./TransformationOperations";
3
- import { Command } from "../../Events";
3
+ import { Command, Operation } from "../../Events";
4
+ /** Minimal interface to avoid circular import with BaseItem/Item */
5
+ interface TransformableItem {
6
+ apply(op: Operation): void;
7
+ transformation: Transformation;
8
+ }
4
9
  export declare class TransformationCommand implements Command {
5
10
  private transformation;
6
11
  private operation;
@@ -8,7 +13,9 @@ export declare class TransformationCommand implements Command {
8
13
  item: Transformation;
9
14
  operation: TransformationOperation;
10
15
  }[];
11
- constructor(transformation: Transformation[], operation: TransformationOperation);
16
+ /** Map from Transformation → Item, populated when items are passed to the constructor. */
17
+ private itemsMap;
18
+ constructor(transformation: Transformation[], operation: TransformationOperation, items?: TransformableItem[]);
12
19
  merge(op: TransformationOperation): this;
13
20
  apply(): void;
14
21
  revert(): void;
@@ -17,3 +24,4 @@ export declare class TransformationCommand implements Command {
17
24
  operation: TransformationOperation;
18
25
  }[];
19
26
  }
27
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "microboard-temp",
3
- "version": "0.11.2",
3
+ "version": "0.11.4",
4
4
  "description": "A flexible interactive whiteboard library",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",