microboard-temp 0.11.3 → 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.
@@ -21794,15 +21794,32 @@ class BaseItem extends Mbr {
21794
21794
  getId() {
21795
21795
  return this.id;
21796
21796
  }
21797
- getWorldMatrix() {
21797
+ getParentWorldMatrix() {
21798
21798
  if (this.parent === "Board") {
21799
- return this.transformation.toMatrix();
21799
+ return new Matrix;
21800
21800
  }
21801
21801
  const container = this.board.items.getById(this.parent);
21802
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") {
21803
21813
  return this.transformation.toMatrix();
21804
21814
  }
21805
- 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;
21806
21823
  }
21807
21824
  setId(id) {
21808
21825
  this.id = id;
@@ -21885,7 +21902,7 @@ class BaseItem extends Mbr {
21885
21902
  const container = this.board.items.getById(this.parent);
21886
21903
  if (!container)
21887
21904
  return this.getMbr();
21888
- const worldMatrix = container.getWorldMatrix();
21905
+ const parentMatrix = this.getParentWorldMatrix();
21889
21906
  const local = this.getMbr();
21890
21907
  const corners = [
21891
21908
  new Point(local.left, local.top),
@@ -21894,19 +21911,19 @@ class BaseItem extends Mbr {
21894
21911
  new Point(local.left, local.bottom)
21895
21912
  ];
21896
21913
  for (const c of corners)
21897
- worldMatrix.apply(c);
21914
+ parentMatrix.apply(c);
21898
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));
21899
21916
  }
21900
21917
  applyAddChildren(childIds) {
21901
21918
  if (!this.index) {
21902
21919
  return;
21903
21920
  }
21904
- const containerWorldMatrix = this.getWorldMatrix();
21921
+ const containerNestingMatrix = this.getNestingMatrix();
21905
21922
  childIds.forEach((childId) => {
21906
21923
  const foundItem = this.board.items.getById(childId);
21907
21924
  if (this.parent !== childId && this.getId() !== childId) {
21908
21925
  if (!this.index?.getById(childId) && foundItem) {
21909
- const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerWorldMatrix);
21926
+ const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerNestingMatrix);
21910
21927
  this.board.items.index.remove(foundItem);
21911
21928
  foundItem.parent = this.getId();
21912
21929
  foundItem.transformation.setLocalMatrix(localMatrix);
@@ -21922,12 +21939,12 @@ class BaseItem extends Mbr {
21922
21939
  if (!this.index) {
21923
21940
  return;
21924
21941
  }
21925
- const containerWorldMatrix = this.getWorldMatrix();
21942
+ const containerNestingMatrix = this.getNestingMatrix();
21926
21943
  childIds.forEach((childId) => {
21927
21944
  const foundItem = this.index?.getById(childId);
21928
21945
  if (this.parent !== childId && this.getId() !== childId) {
21929
21946
  if (foundItem) {
21930
- const worldMatrix = foundItem.transformation.toMatrix().composeWith(containerWorldMatrix);
21947
+ const worldMatrix = foundItem.transformation.toMatrix().composeWith(containerNestingMatrix);
21931
21948
  this.index?.remove(foundItem);
21932
21949
  foundItem.parent = "Board";
21933
21950
  foundItem.transformation.setLocalMatrix(worldMatrix);
@@ -22047,7 +22064,7 @@ class BaseItem extends Mbr {
22047
22064
  if (this.parent !== "Board") {
22048
22065
  const container = this.board.items.getById(this.parent);
22049
22066
  if (container?.transformation) {
22050
- transformOp = toLocalTransformOp(transformOp, container.getWorldMatrix(), this.id);
22067
+ transformOp = toLocalTransformOp(transformOp, container.getNestingMatrix(), this.id);
22051
22068
  }
22052
22069
  }
22053
22070
  this.transformation.apply(transformOp);
@@ -22844,11 +22861,8 @@ class RichText extends BaseItem {
22844
22861
  const { ctx } = context;
22845
22862
  ctx.save();
22846
22863
  ctx.translate(this.left, this.top);
22847
- const shouldScale = !this.isInShape && !this.autoSize;
22848
- if (shouldScale) {
22849
- const { scaleX, scaleY } = this.transformation.getMatrixData();
22850
- ctx.scale(scaleX, scaleY);
22851
- }
22864
+ const { scaleX, scaleY } = this.transformation.getMatrixData();
22865
+ ctx.scale(scaleX, scaleY);
22852
22866
  const shouldClip = this.insideOf === "Shape" || this.insideOf === "Sticker";
22853
22867
  if (shouldClip) {
22854
22868
  ctx.clip(this.clipPath.nativePath);
@@ -41080,6 +41094,7 @@ class Frame2 extends BaseItem {
41080
41094
  scaleY = 1;
41081
41095
  translateY = 0;
41082
41096
  }
41097
+ const oldMatrix = this.transformation.toMatrix();
41083
41098
  this.transformation.scaleByTranslateBy({
41084
41099
  x: scaleX,
41085
41100
  y: scaleY
@@ -41087,6 +41102,16 @@ class Frame2 extends BaseItem {
41087
41102
  x: translateX,
41088
41103
  y: translateY
41089
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
+ }
41090
41115
  this.setLastFrameScale();
41091
41116
  res.mbr = this.getMbr();
41092
41117
  return res;
@@ -41363,8 +41388,9 @@ class Frame2 extends BaseItem {
41363
41388
  this.renderPath(context);
41364
41389
  const ctx = context.ctx;
41365
41390
  ctx.save();
41366
- this.transformation.applyToContext(ctx);
41367
- 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()) {
41368
41394
  child.render(context);
41369
41395
  }
41370
41396
  ctx.restore();
package/dist/cjs/index.js CHANGED
@@ -21794,15 +21794,32 @@ class BaseItem extends Mbr {
21794
21794
  getId() {
21795
21795
  return this.id;
21796
21796
  }
21797
- getWorldMatrix() {
21797
+ getParentWorldMatrix() {
21798
21798
  if (this.parent === "Board") {
21799
- return this.transformation.toMatrix();
21799
+ return new Matrix;
21800
21800
  }
21801
21801
  const container = this.board.items.getById(this.parent);
21802
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") {
21803
21813
  return this.transformation.toMatrix();
21804
21814
  }
21805
- 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;
21806
21823
  }
21807
21824
  setId(id) {
21808
21825
  this.id = id;
@@ -21885,7 +21902,7 @@ class BaseItem extends Mbr {
21885
21902
  const container = this.board.items.getById(this.parent);
21886
21903
  if (!container)
21887
21904
  return this.getMbr();
21888
- const worldMatrix = container.getWorldMatrix();
21905
+ const parentMatrix = this.getParentWorldMatrix();
21889
21906
  const local = this.getMbr();
21890
21907
  const corners = [
21891
21908
  new Point(local.left, local.top),
@@ -21894,19 +21911,19 @@ class BaseItem extends Mbr {
21894
21911
  new Point(local.left, local.bottom)
21895
21912
  ];
21896
21913
  for (const c of corners)
21897
- worldMatrix.apply(c);
21914
+ parentMatrix.apply(c);
21898
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));
21899
21916
  }
21900
21917
  applyAddChildren(childIds) {
21901
21918
  if (!this.index) {
21902
21919
  return;
21903
21920
  }
21904
- const containerWorldMatrix = this.getWorldMatrix();
21921
+ const containerNestingMatrix = this.getNestingMatrix();
21905
21922
  childIds.forEach((childId) => {
21906
21923
  const foundItem = this.board.items.getById(childId);
21907
21924
  if (this.parent !== childId && this.getId() !== childId) {
21908
21925
  if (!this.index?.getById(childId) && foundItem) {
21909
- const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerWorldMatrix);
21926
+ const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerNestingMatrix);
21910
21927
  this.board.items.index.remove(foundItem);
21911
21928
  foundItem.parent = this.getId();
21912
21929
  foundItem.transformation.setLocalMatrix(localMatrix);
@@ -21922,12 +21939,12 @@ class BaseItem extends Mbr {
21922
21939
  if (!this.index) {
21923
21940
  return;
21924
21941
  }
21925
- const containerWorldMatrix = this.getWorldMatrix();
21942
+ const containerNestingMatrix = this.getNestingMatrix();
21926
21943
  childIds.forEach((childId) => {
21927
21944
  const foundItem = this.index?.getById(childId);
21928
21945
  if (this.parent !== childId && this.getId() !== childId) {
21929
21946
  if (foundItem) {
21930
- const worldMatrix = foundItem.transformation.toMatrix().composeWith(containerWorldMatrix);
21947
+ const worldMatrix = foundItem.transformation.toMatrix().composeWith(containerNestingMatrix);
21931
21948
  this.index?.remove(foundItem);
21932
21949
  foundItem.parent = "Board";
21933
21950
  foundItem.transformation.setLocalMatrix(worldMatrix);
@@ -22047,7 +22064,7 @@ class BaseItem extends Mbr {
22047
22064
  if (this.parent !== "Board") {
22048
22065
  const container = this.board.items.getById(this.parent);
22049
22066
  if (container?.transformation) {
22050
- transformOp = toLocalTransformOp(transformOp, container.getWorldMatrix(), this.id);
22067
+ transformOp = toLocalTransformOp(transformOp, container.getNestingMatrix(), this.id);
22051
22068
  }
22052
22069
  }
22053
22070
  this.transformation.apply(transformOp);
@@ -22844,11 +22861,8 @@ class RichText extends BaseItem {
22844
22861
  const { ctx } = context;
22845
22862
  ctx.save();
22846
22863
  ctx.translate(this.left, this.top);
22847
- const shouldScale = !this.isInShape && !this.autoSize;
22848
- if (shouldScale) {
22849
- const { scaleX, scaleY } = this.transformation.getMatrixData();
22850
- ctx.scale(scaleX, scaleY);
22851
- }
22864
+ const { scaleX, scaleY } = this.transformation.getMatrixData();
22865
+ ctx.scale(scaleX, scaleY);
22852
22866
  const shouldClip = this.insideOf === "Shape" || this.insideOf === "Sticker";
22853
22867
  if (shouldClip) {
22854
22868
  ctx.clip(this.clipPath.nativePath);
@@ -41080,6 +41094,7 @@ class Frame2 extends BaseItem {
41080
41094
  scaleY = 1;
41081
41095
  translateY = 0;
41082
41096
  }
41097
+ const oldMatrix = this.transformation.toMatrix();
41083
41098
  this.transformation.scaleByTranslateBy({
41084
41099
  x: scaleX,
41085
41100
  y: scaleY
@@ -41087,6 +41102,16 @@ class Frame2 extends BaseItem {
41087
41102
  x: translateX,
41088
41103
  y: translateY
41089
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
+ }
41090
41115
  this.setLastFrameScale();
41091
41116
  res.mbr = this.getMbr();
41092
41117
  return res;
@@ -41363,8 +41388,9 @@ class Frame2 extends BaseItem {
41363
41388
  this.renderPath(context);
41364
41389
  const ctx = context.ctx;
41365
41390
  ctx.save();
41366
- this.transformation.applyToContext(ctx);
41367
- 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()) {
41368
41394
  child.render(context);
41369
41395
  }
41370
41396
  ctx.restore();
package/dist/cjs/node.js CHANGED
@@ -24266,15 +24266,32 @@ class BaseItem extends Mbr {
24266
24266
  getId() {
24267
24267
  return this.id;
24268
24268
  }
24269
- getWorldMatrix() {
24269
+ getParentWorldMatrix() {
24270
24270
  if (this.parent === "Board") {
24271
- return this.transformation.toMatrix();
24271
+ return new Matrix;
24272
24272
  }
24273
24273
  const container = this.board.items.getById(this.parent);
24274
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") {
24275
24285
  return this.transformation.toMatrix();
24276
24286
  }
24277
- 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;
24278
24295
  }
24279
24296
  setId(id) {
24280
24297
  this.id = id;
@@ -24357,7 +24374,7 @@ class BaseItem extends Mbr {
24357
24374
  const container = this.board.items.getById(this.parent);
24358
24375
  if (!container)
24359
24376
  return this.getMbr();
24360
- const worldMatrix = container.getWorldMatrix();
24377
+ const parentMatrix = this.getParentWorldMatrix();
24361
24378
  const local = this.getMbr();
24362
24379
  const corners = [
24363
24380
  new Point(local.left, local.top),
@@ -24366,19 +24383,19 @@ class BaseItem extends Mbr {
24366
24383
  new Point(local.left, local.bottom)
24367
24384
  ];
24368
24385
  for (const c of corners)
24369
- worldMatrix.apply(c);
24386
+ parentMatrix.apply(c);
24370
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));
24371
24388
  }
24372
24389
  applyAddChildren(childIds) {
24373
24390
  if (!this.index) {
24374
24391
  return;
24375
24392
  }
24376
- const containerWorldMatrix = this.getWorldMatrix();
24393
+ const containerNestingMatrix = this.getNestingMatrix();
24377
24394
  childIds.forEach((childId) => {
24378
24395
  const foundItem = this.board.items.getById(childId);
24379
24396
  if (this.parent !== childId && this.getId() !== childId) {
24380
24397
  if (!this.index?.getById(childId) && foundItem) {
24381
- const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerWorldMatrix);
24398
+ const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerNestingMatrix);
24382
24399
  this.board.items.index.remove(foundItem);
24383
24400
  foundItem.parent = this.getId();
24384
24401
  foundItem.transformation.setLocalMatrix(localMatrix);
@@ -24394,12 +24411,12 @@ class BaseItem extends Mbr {
24394
24411
  if (!this.index) {
24395
24412
  return;
24396
24413
  }
24397
- const containerWorldMatrix = this.getWorldMatrix();
24414
+ const containerNestingMatrix = this.getNestingMatrix();
24398
24415
  childIds.forEach((childId) => {
24399
24416
  const foundItem = this.index?.getById(childId);
24400
24417
  if (this.parent !== childId && this.getId() !== childId) {
24401
24418
  if (foundItem) {
24402
- const worldMatrix = foundItem.transformation.toMatrix().composeWith(containerWorldMatrix);
24419
+ const worldMatrix = foundItem.transformation.toMatrix().composeWith(containerNestingMatrix);
24403
24420
  this.index?.remove(foundItem);
24404
24421
  foundItem.parent = "Board";
24405
24422
  foundItem.transformation.setLocalMatrix(worldMatrix);
@@ -24519,7 +24536,7 @@ class BaseItem extends Mbr {
24519
24536
  if (this.parent !== "Board") {
24520
24537
  const container = this.board.items.getById(this.parent);
24521
24538
  if (container?.transformation) {
24522
- transformOp = toLocalTransformOp(transformOp, container.getWorldMatrix(), this.id);
24539
+ transformOp = toLocalTransformOp(transformOp, container.getNestingMatrix(), this.id);
24523
24540
  }
24524
24541
  }
24525
24542
  this.transformation.apply(transformOp);
@@ -25316,11 +25333,8 @@ class RichText extends BaseItem {
25316
25333
  const { ctx } = context;
25317
25334
  ctx.save();
25318
25335
  ctx.translate(this.left, this.top);
25319
- const shouldScale = !this.isInShape && !this.autoSize;
25320
- if (shouldScale) {
25321
- const { scaleX, scaleY } = this.transformation.getMatrixData();
25322
- ctx.scale(scaleX, scaleY);
25323
- }
25336
+ const { scaleX, scaleY } = this.transformation.getMatrixData();
25337
+ ctx.scale(scaleX, scaleY);
25324
25338
  const shouldClip = this.insideOf === "Shape" || this.insideOf === "Sticker";
25325
25339
  if (shouldClip) {
25326
25340
  ctx.clip(this.clipPath.nativePath);
@@ -43553,6 +43567,7 @@ class Frame2 extends BaseItem {
43553
43567
  scaleY = 1;
43554
43568
  translateY = 0;
43555
43569
  }
43570
+ const oldMatrix = this.transformation.toMatrix();
43556
43571
  this.transformation.scaleByTranslateBy({
43557
43572
  x: scaleX,
43558
43573
  y: scaleY
@@ -43560,6 +43575,16 @@ class Frame2 extends BaseItem {
43560
43575
  x: translateX,
43561
43576
  y: translateY
43562
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
+ }
43563
43588
  this.setLastFrameScale();
43564
43589
  res.mbr = this.getMbr();
43565
43590
  return res;
@@ -43836,8 +43861,9 @@ class Frame2 extends BaseItem {
43836
43861
  this.renderPath(context);
43837
43862
  const ctx = context.ctx;
43838
43863
  ctx.save();
43839
- this.transformation.applyToContext(ctx);
43840
- 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()) {
43841
43867
  child.render(context);
43842
43868
  }
43843
43869
  ctx.restore();
@@ -21623,15 +21623,32 @@ class BaseItem extends Mbr {
21623
21623
  getId() {
21624
21624
  return this.id;
21625
21625
  }
21626
- getWorldMatrix() {
21626
+ getParentWorldMatrix() {
21627
21627
  if (this.parent === "Board") {
21628
- return this.transformation.toMatrix();
21628
+ return new Matrix;
21629
21629
  }
21630
21630
  const container = this.board.items.getById(this.parent);
21631
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") {
21632
21642
  return this.transformation.toMatrix();
21633
21643
  }
21634
- 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;
21635
21652
  }
21636
21653
  setId(id) {
21637
21654
  this.id = id;
@@ -21714,7 +21731,7 @@ class BaseItem extends Mbr {
21714
21731
  const container = this.board.items.getById(this.parent);
21715
21732
  if (!container)
21716
21733
  return this.getMbr();
21717
- const worldMatrix = container.getWorldMatrix();
21734
+ const parentMatrix = this.getParentWorldMatrix();
21718
21735
  const local = this.getMbr();
21719
21736
  const corners = [
21720
21737
  new Point(local.left, local.top),
@@ -21723,19 +21740,19 @@ class BaseItem extends Mbr {
21723
21740
  new Point(local.left, local.bottom)
21724
21741
  ];
21725
21742
  for (const c of corners)
21726
- worldMatrix.apply(c);
21743
+ parentMatrix.apply(c);
21727
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));
21728
21745
  }
21729
21746
  applyAddChildren(childIds) {
21730
21747
  if (!this.index) {
21731
21748
  return;
21732
21749
  }
21733
- const containerWorldMatrix = this.getWorldMatrix();
21750
+ const containerNestingMatrix = this.getNestingMatrix();
21734
21751
  childIds.forEach((childId) => {
21735
21752
  const foundItem = this.board.items.getById(childId);
21736
21753
  if (this.parent !== childId && this.getId() !== childId) {
21737
21754
  if (!this.index?.getById(childId) && foundItem) {
21738
- const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerWorldMatrix);
21755
+ const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerNestingMatrix);
21739
21756
  this.board.items.index.remove(foundItem);
21740
21757
  foundItem.parent = this.getId();
21741
21758
  foundItem.transformation.setLocalMatrix(localMatrix);
@@ -21751,12 +21768,12 @@ class BaseItem extends Mbr {
21751
21768
  if (!this.index) {
21752
21769
  return;
21753
21770
  }
21754
- const containerWorldMatrix = this.getWorldMatrix();
21771
+ const containerNestingMatrix = this.getNestingMatrix();
21755
21772
  childIds.forEach((childId) => {
21756
21773
  const foundItem = this.index?.getById(childId);
21757
21774
  if (this.parent !== childId && this.getId() !== childId) {
21758
21775
  if (foundItem) {
21759
- const worldMatrix = foundItem.transformation.toMatrix().composeWith(containerWorldMatrix);
21776
+ const worldMatrix = foundItem.transformation.toMatrix().composeWith(containerNestingMatrix);
21760
21777
  this.index?.remove(foundItem);
21761
21778
  foundItem.parent = "Board";
21762
21779
  foundItem.transformation.setLocalMatrix(worldMatrix);
@@ -21876,7 +21893,7 @@ class BaseItem extends Mbr {
21876
21893
  if (this.parent !== "Board") {
21877
21894
  const container = this.board.items.getById(this.parent);
21878
21895
  if (container?.transformation) {
21879
- transformOp = toLocalTransformOp(transformOp, container.getWorldMatrix(), this.id);
21896
+ transformOp = toLocalTransformOp(transformOp, container.getNestingMatrix(), this.id);
21880
21897
  }
21881
21898
  }
21882
21899
  this.transformation.apply(transformOp);
@@ -22673,11 +22690,8 @@ class RichText extends BaseItem {
22673
22690
  const { ctx } = context;
22674
22691
  ctx.save();
22675
22692
  ctx.translate(this.left, this.top);
22676
- const shouldScale = !this.isInShape && !this.autoSize;
22677
- if (shouldScale) {
22678
- const { scaleX, scaleY } = this.transformation.getMatrixData();
22679
- ctx.scale(scaleX, scaleY);
22680
- }
22693
+ const { scaleX, scaleY } = this.transformation.getMatrixData();
22694
+ ctx.scale(scaleX, scaleY);
22681
22695
  const shouldClip = this.insideOf === "Shape" || this.insideOf === "Sticker";
22682
22696
  if (shouldClip) {
22683
22697
  ctx.clip(this.clipPath.nativePath);
@@ -40909,6 +40923,7 @@ class Frame2 extends BaseItem {
40909
40923
  scaleY = 1;
40910
40924
  translateY = 0;
40911
40925
  }
40926
+ const oldMatrix = this.transformation.toMatrix();
40912
40927
  this.transformation.scaleByTranslateBy({
40913
40928
  x: scaleX,
40914
40929
  y: scaleY
@@ -40916,6 +40931,16 @@ class Frame2 extends BaseItem {
40916
40931
  x: translateX,
40917
40932
  y: translateY
40918
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
+ }
40919
40944
  this.setLastFrameScale();
40920
40945
  res.mbr = this.getMbr();
40921
40946
  return res;
@@ -41192,8 +41217,9 @@ class Frame2 extends BaseItem {
41192
41217
  this.renderPath(context);
41193
41218
  const ctx = context.ctx;
41194
41219
  ctx.save();
41195
- this.transformation.applyToContext(ctx);
41196
- 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()) {
41197
41223
  child.render(context);
41198
41224
  }
41199
41225
  ctx.restore();
package/dist/esm/index.js CHANGED
@@ -21616,15 +21616,32 @@ class BaseItem extends Mbr {
21616
21616
  getId() {
21617
21617
  return this.id;
21618
21618
  }
21619
- getWorldMatrix() {
21619
+ getParentWorldMatrix() {
21620
21620
  if (this.parent === "Board") {
21621
- return this.transformation.toMatrix();
21621
+ return new Matrix;
21622
21622
  }
21623
21623
  const container = this.board.items.getById(this.parent);
21624
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") {
21625
21635
  return this.transformation.toMatrix();
21626
21636
  }
21627
- 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;
21628
21645
  }
21629
21646
  setId(id) {
21630
21647
  this.id = id;
@@ -21707,7 +21724,7 @@ class BaseItem extends Mbr {
21707
21724
  const container = this.board.items.getById(this.parent);
21708
21725
  if (!container)
21709
21726
  return this.getMbr();
21710
- const worldMatrix = container.getWorldMatrix();
21727
+ const parentMatrix = this.getParentWorldMatrix();
21711
21728
  const local = this.getMbr();
21712
21729
  const corners = [
21713
21730
  new Point(local.left, local.top),
@@ -21716,19 +21733,19 @@ class BaseItem extends Mbr {
21716
21733
  new Point(local.left, local.bottom)
21717
21734
  ];
21718
21735
  for (const c of corners)
21719
- worldMatrix.apply(c);
21736
+ parentMatrix.apply(c);
21720
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));
21721
21738
  }
21722
21739
  applyAddChildren(childIds) {
21723
21740
  if (!this.index) {
21724
21741
  return;
21725
21742
  }
21726
- const containerWorldMatrix = this.getWorldMatrix();
21743
+ const containerNestingMatrix = this.getNestingMatrix();
21727
21744
  childIds.forEach((childId) => {
21728
21745
  const foundItem = this.board.items.getById(childId);
21729
21746
  if (this.parent !== childId && this.getId() !== childId) {
21730
21747
  if (!this.index?.getById(childId) && foundItem) {
21731
- const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerWorldMatrix);
21748
+ const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerNestingMatrix);
21732
21749
  this.board.items.index.remove(foundItem);
21733
21750
  foundItem.parent = this.getId();
21734
21751
  foundItem.transformation.setLocalMatrix(localMatrix);
@@ -21744,12 +21761,12 @@ class BaseItem extends Mbr {
21744
21761
  if (!this.index) {
21745
21762
  return;
21746
21763
  }
21747
- const containerWorldMatrix = this.getWorldMatrix();
21764
+ const containerNestingMatrix = this.getNestingMatrix();
21748
21765
  childIds.forEach((childId) => {
21749
21766
  const foundItem = this.index?.getById(childId);
21750
21767
  if (this.parent !== childId && this.getId() !== childId) {
21751
21768
  if (foundItem) {
21752
- const worldMatrix = foundItem.transformation.toMatrix().composeWith(containerWorldMatrix);
21769
+ const worldMatrix = foundItem.transformation.toMatrix().composeWith(containerNestingMatrix);
21753
21770
  this.index?.remove(foundItem);
21754
21771
  foundItem.parent = "Board";
21755
21772
  foundItem.transformation.setLocalMatrix(worldMatrix);
@@ -21869,7 +21886,7 @@ class BaseItem extends Mbr {
21869
21886
  if (this.parent !== "Board") {
21870
21887
  const container = this.board.items.getById(this.parent);
21871
21888
  if (container?.transformation) {
21872
- transformOp = toLocalTransformOp(transformOp, container.getWorldMatrix(), this.id);
21889
+ transformOp = toLocalTransformOp(transformOp, container.getNestingMatrix(), this.id);
21873
21890
  }
21874
21891
  }
21875
21892
  this.transformation.apply(transformOp);
@@ -22666,11 +22683,8 @@ class RichText extends BaseItem {
22666
22683
  const { ctx } = context;
22667
22684
  ctx.save();
22668
22685
  ctx.translate(this.left, this.top);
22669
- const shouldScale = !this.isInShape && !this.autoSize;
22670
- if (shouldScale) {
22671
- const { scaleX, scaleY } = this.transformation.getMatrixData();
22672
- ctx.scale(scaleX, scaleY);
22673
- }
22686
+ const { scaleX, scaleY } = this.transformation.getMatrixData();
22687
+ ctx.scale(scaleX, scaleY);
22674
22688
  const shouldClip = this.insideOf === "Shape" || this.insideOf === "Sticker";
22675
22689
  if (shouldClip) {
22676
22690
  ctx.clip(this.clipPath.nativePath);
@@ -40902,6 +40916,7 @@ class Frame2 extends BaseItem {
40902
40916
  scaleY = 1;
40903
40917
  translateY = 0;
40904
40918
  }
40919
+ const oldMatrix = this.transformation.toMatrix();
40905
40920
  this.transformation.scaleByTranslateBy({
40906
40921
  x: scaleX,
40907
40922
  y: scaleY
@@ -40909,6 +40924,16 @@ class Frame2 extends BaseItem {
40909
40924
  x: translateX,
40910
40925
  y: translateY
40911
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
+ }
40912
40937
  this.setLastFrameScale();
40913
40938
  res.mbr = this.getMbr();
40914
40939
  return res;
@@ -41185,8 +41210,9 @@ class Frame2 extends BaseItem {
41185
41210
  this.renderPath(context);
41186
41211
  const ctx = context.ctx;
41187
41212
  ctx.save();
41188
- this.transformation.applyToContext(ctx);
41189
- 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()) {
41190
41216
  child.render(context);
41191
41217
  }
41192
41218
  ctx.restore();
package/dist/esm/node.js CHANGED
@@ -24083,15 +24083,32 @@ class BaseItem extends Mbr {
24083
24083
  getId() {
24084
24084
  return this.id;
24085
24085
  }
24086
- getWorldMatrix() {
24086
+ getParentWorldMatrix() {
24087
24087
  if (this.parent === "Board") {
24088
- return this.transformation.toMatrix();
24088
+ return new Matrix;
24089
24089
  }
24090
24090
  const container = this.board.items.getById(this.parent);
24091
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") {
24092
24102
  return this.transformation.toMatrix();
24093
24103
  }
24094
- 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;
24095
24112
  }
24096
24113
  setId(id) {
24097
24114
  this.id = id;
@@ -24174,7 +24191,7 @@ class BaseItem extends Mbr {
24174
24191
  const container = this.board.items.getById(this.parent);
24175
24192
  if (!container)
24176
24193
  return this.getMbr();
24177
- const worldMatrix = container.getWorldMatrix();
24194
+ const parentMatrix = this.getParentWorldMatrix();
24178
24195
  const local = this.getMbr();
24179
24196
  const corners = [
24180
24197
  new Point(local.left, local.top),
@@ -24183,19 +24200,19 @@ class BaseItem extends Mbr {
24183
24200
  new Point(local.left, local.bottom)
24184
24201
  ];
24185
24202
  for (const c of corners)
24186
- worldMatrix.apply(c);
24203
+ parentMatrix.apply(c);
24187
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));
24188
24205
  }
24189
24206
  applyAddChildren(childIds) {
24190
24207
  if (!this.index) {
24191
24208
  return;
24192
24209
  }
24193
- const containerWorldMatrix = this.getWorldMatrix();
24210
+ const containerNestingMatrix = this.getNestingMatrix();
24194
24211
  childIds.forEach((childId) => {
24195
24212
  const foundItem = this.board.items.getById(childId);
24196
24213
  if (this.parent !== childId && this.getId() !== childId) {
24197
24214
  if (!this.index?.getById(childId) && foundItem) {
24198
- const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerWorldMatrix);
24215
+ const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerNestingMatrix);
24199
24216
  this.board.items.index.remove(foundItem);
24200
24217
  foundItem.parent = this.getId();
24201
24218
  foundItem.transformation.setLocalMatrix(localMatrix);
@@ -24211,12 +24228,12 @@ class BaseItem extends Mbr {
24211
24228
  if (!this.index) {
24212
24229
  return;
24213
24230
  }
24214
- const containerWorldMatrix = this.getWorldMatrix();
24231
+ const containerNestingMatrix = this.getNestingMatrix();
24215
24232
  childIds.forEach((childId) => {
24216
24233
  const foundItem = this.index?.getById(childId);
24217
24234
  if (this.parent !== childId && this.getId() !== childId) {
24218
24235
  if (foundItem) {
24219
- const worldMatrix = foundItem.transformation.toMatrix().composeWith(containerWorldMatrix);
24236
+ const worldMatrix = foundItem.transformation.toMatrix().composeWith(containerNestingMatrix);
24220
24237
  this.index?.remove(foundItem);
24221
24238
  foundItem.parent = "Board";
24222
24239
  foundItem.transformation.setLocalMatrix(worldMatrix);
@@ -24336,7 +24353,7 @@ class BaseItem extends Mbr {
24336
24353
  if (this.parent !== "Board") {
24337
24354
  const container = this.board.items.getById(this.parent);
24338
24355
  if (container?.transformation) {
24339
- transformOp = toLocalTransformOp(transformOp, container.getWorldMatrix(), this.id);
24356
+ transformOp = toLocalTransformOp(transformOp, container.getNestingMatrix(), this.id);
24340
24357
  }
24341
24358
  }
24342
24359
  this.transformation.apply(transformOp);
@@ -25133,11 +25150,8 @@ class RichText extends BaseItem {
25133
25150
  const { ctx } = context;
25134
25151
  ctx.save();
25135
25152
  ctx.translate(this.left, this.top);
25136
- const shouldScale = !this.isInShape && !this.autoSize;
25137
- if (shouldScale) {
25138
- const { scaleX, scaleY } = this.transformation.getMatrixData();
25139
- ctx.scale(scaleX, scaleY);
25140
- }
25153
+ const { scaleX, scaleY } = this.transformation.getMatrixData();
25154
+ ctx.scale(scaleX, scaleY);
25141
25155
  const shouldClip = this.insideOf === "Shape" || this.insideOf === "Sticker";
25142
25156
  if (shouldClip) {
25143
25157
  ctx.clip(this.clipPath.nativePath);
@@ -43370,6 +43384,7 @@ class Frame2 extends BaseItem {
43370
43384
  scaleY = 1;
43371
43385
  translateY = 0;
43372
43386
  }
43387
+ const oldMatrix = this.transformation.toMatrix();
43373
43388
  this.transformation.scaleByTranslateBy({
43374
43389
  x: scaleX,
43375
43390
  y: scaleY
@@ -43377,6 +43392,16 @@ class Frame2 extends BaseItem {
43377
43392
  x: translateX,
43378
43393
  y: translateY
43379
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
+ }
43380
43405
  this.setLastFrameScale();
43381
43406
  res.mbr = this.getMbr();
43382
43407
  return res;
@@ -43653,8 +43678,9 @@ class Frame2 extends BaseItem {
43653
43678
  this.renderPath(context);
43654
43679
  const ctx = context.ctx;
43655
43680
  ctx.save();
43656
- this.transformation.applyToContext(ctx);
43657
- 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()) {
43658
43684
  child.render(context);
43659
43685
  }
43660
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "microboard-temp",
3
- "version": "0.11.3",
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",