microboard-temp 0.11.3 → 0.11.5

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.
@@ -20932,7 +20932,7 @@ class LayeredIndex {
20932
20932
 
20933
20933
  // src/SpatialIndex/SpacialIndex.ts
20934
20934
  function worldBoundsToLocal(container, left, top, right, bottom) {
20935
- const inv = container.getWorldMatrix().getInverse();
20935
+ const inv = container.getNestingMatrix().getInverse();
20936
20936
  const corners = [
20937
20937
  new Point(left, top),
20938
20938
  new Point(right, top),
@@ -21227,7 +21227,7 @@ class SpatialIndex {
21227
21227
  const clearItems = items.filter((item) => {
21228
21228
  if ("index" in item && item.index) {
21229
21229
  const localPt = new Point(point3.x, point3.y);
21230
- item.getWorldMatrix().getInverse().apply(localPt);
21230
+ item.getNestingMatrix().getInverse().apply(localPt);
21231
21231
  children.push(...item.index.getUnderPoint(localPt, tolerance));
21232
21232
  if (!item.getMbr().isUnderPoint(point3)) {
21233
21233
  return false;
@@ -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);
@@ -41080,6 +41097,7 @@ class Frame2 extends BaseItem {
41080
41097
  scaleY = 1;
41081
41098
  translateY = 0;
41082
41099
  }
41100
+ const oldMatrix = this.transformation.toMatrix();
41083
41101
  this.transformation.scaleByTranslateBy({
41084
41102
  x: scaleX,
41085
41103
  y: scaleY
@@ -41087,6 +41105,16 @@ class Frame2 extends BaseItem {
41087
41105
  x: translateX,
41088
41106
  y: translateY
41089
41107
  }, timeStamp);
41108
+ const newMatrix = this.transformation.toMatrix();
41109
+ if (newMatrix.translateX !== oldMatrix.translateX || newMatrix.translateY !== oldMatrix.translateY) {
41110
+ const dx = newMatrix.translateX - oldMatrix.translateX;
41111
+ const dy = newMatrix.translateY - oldMatrix.translateY;
41112
+ this.index?.list().forEach((child) => {
41113
+ if (child instanceof BaseItem) {
41114
+ child.transformation.translateBy(-dx, -dy, timeStamp);
41115
+ }
41116
+ });
41117
+ }
41090
41118
  this.setLastFrameScale();
41091
41119
  res.mbr = this.getMbr();
41092
41120
  return res;
@@ -41363,8 +41391,9 @@ class Frame2 extends BaseItem {
41363
41391
  this.renderPath(context);
41364
41392
  const ctx = context.ctx;
41365
41393
  ctx.save();
41366
- this.transformation.applyToContext(ctx);
41367
- for (const child of this.index.list()) {
41394
+ const { translateX, translateY } = this.getWorldMatrix();
41395
+ ctx.translate(translateX, translateY);
41396
+ for (const child of this.index.items.listAll()) {
41368
41397
  child.render(context);
41369
41398
  }
41370
41399
  ctx.restore();
package/dist/cjs/index.js CHANGED
@@ -20932,7 +20932,7 @@ class LayeredIndex {
20932
20932
 
20933
20933
  // src/SpatialIndex/SpacialIndex.ts
20934
20934
  function worldBoundsToLocal(container, left, top, right, bottom) {
20935
- const inv = container.getWorldMatrix().getInverse();
20935
+ const inv = container.getNestingMatrix().getInverse();
20936
20936
  const corners = [
20937
20937
  new Point(left, top),
20938
20938
  new Point(right, top),
@@ -21227,7 +21227,7 @@ class SpatialIndex {
21227
21227
  const clearItems = items.filter((item) => {
21228
21228
  if ("index" in item && item.index) {
21229
21229
  const localPt = new Point(point3.x, point3.y);
21230
- item.getWorldMatrix().getInverse().apply(localPt);
21230
+ item.getNestingMatrix().getInverse().apply(localPt);
21231
21231
  children.push(...item.index.getUnderPoint(localPt, tolerance));
21232
21232
  if (!item.getMbr().isUnderPoint(point3)) {
21233
21233
  return false;
@@ -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);
@@ -41080,6 +41097,7 @@ class Frame2 extends BaseItem {
41080
41097
  scaleY = 1;
41081
41098
  translateY = 0;
41082
41099
  }
41100
+ const oldMatrix = this.transformation.toMatrix();
41083
41101
  this.transformation.scaleByTranslateBy({
41084
41102
  x: scaleX,
41085
41103
  y: scaleY
@@ -41087,6 +41105,16 @@ class Frame2 extends BaseItem {
41087
41105
  x: translateX,
41088
41106
  y: translateY
41089
41107
  }, timeStamp);
41108
+ const newMatrix = this.transformation.toMatrix();
41109
+ if (newMatrix.translateX !== oldMatrix.translateX || newMatrix.translateY !== oldMatrix.translateY) {
41110
+ const dx = newMatrix.translateX - oldMatrix.translateX;
41111
+ const dy = newMatrix.translateY - oldMatrix.translateY;
41112
+ this.index?.list().forEach((child) => {
41113
+ if (child instanceof BaseItem) {
41114
+ child.transformation.translateBy(-dx, -dy, timeStamp);
41115
+ }
41116
+ });
41117
+ }
41090
41118
  this.setLastFrameScale();
41091
41119
  res.mbr = this.getMbr();
41092
41120
  return res;
@@ -41363,8 +41391,9 @@ class Frame2 extends BaseItem {
41363
41391
  this.renderPath(context);
41364
41392
  const ctx = context.ctx;
41365
41393
  ctx.save();
41366
- this.transformation.applyToContext(ctx);
41367
- for (const child of this.index.list()) {
41394
+ const { translateX, translateY } = this.getWorldMatrix();
41395
+ ctx.translate(translateX, translateY);
41396
+ for (const child of this.index.items.listAll()) {
41368
41397
  child.render(context);
41369
41398
  }
41370
41399
  ctx.restore();
package/dist/cjs/node.js CHANGED
@@ -23404,7 +23404,7 @@ class LayeredIndex {
23404
23404
 
23405
23405
  // src/SpatialIndex/SpacialIndex.ts
23406
23406
  function worldBoundsToLocal(container, left, top, right, bottom) {
23407
- const inv = container.getWorldMatrix().getInverse();
23407
+ const inv = container.getNestingMatrix().getInverse();
23408
23408
  const corners = [
23409
23409
  new Point(left, top),
23410
23410
  new Point(right, top),
@@ -23699,7 +23699,7 @@ class SpatialIndex {
23699
23699
  const clearItems = items.filter((item) => {
23700
23700
  if ("index" in item && item.index) {
23701
23701
  const localPt = new Point(point3.x, point3.y);
23702
- item.getWorldMatrix().getInverse().apply(localPt);
23702
+ item.getNestingMatrix().getInverse().apply(localPt);
23703
23703
  children.push(...item.index.getUnderPoint(localPt, tolerance));
23704
23704
  if (!item.getMbr().isUnderPoint(point3)) {
23705
23705
  return false;
@@ -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);
@@ -43553,6 +43570,7 @@ class Frame2 extends BaseItem {
43553
43570
  scaleY = 1;
43554
43571
  translateY = 0;
43555
43572
  }
43573
+ const oldMatrix = this.transformation.toMatrix();
43556
43574
  this.transformation.scaleByTranslateBy({
43557
43575
  x: scaleX,
43558
43576
  y: scaleY
@@ -43560,6 +43578,16 @@ class Frame2 extends BaseItem {
43560
43578
  x: translateX,
43561
43579
  y: translateY
43562
43580
  }, timeStamp);
43581
+ const newMatrix = this.transformation.toMatrix();
43582
+ if (newMatrix.translateX !== oldMatrix.translateX || newMatrix.translateY !== oldMatrix.translateY) {
43583
+ const dx = newMatrix.translateX - oldMatrix.translateX;
43584
+ const dy = newMatrix.translateY - oldMatrix.translateY;
43585
+ this.index?.list().forEach((child) => {
43586
+ if (child instanceof BaseItem) {
43587
+ child.transformation.translateBy(-dx, -dy, timeStamp);
43588
+ }
43589
+ });
43590
+ }
43563
43591
  this.setLastFrameScale();
43564
43592
  res.mbr = this.getMbr();
43565
43593
  return res;
@@ -43836,8 +43864,9 @@ class Frame2 extends BaseItem {
43836
43864
  this.renderPath(context);
43837
43865
  const ctx = context.ctx;
43838
43866
  ctx.save();
43839
- this.transformation.applyToContext(ctx);
43840
- for (const child of this.index.list()) {
43867
+ const { translateX, translateY } = this.getWorldMatrix();
43868
+ ctx.translate(translateX, translateY);
43869
+ for (const child of this.index.items.listAll()) {
43841
43870
  child.render(context);
43842
43871
  }
43843
43872
  ctx.restore();
@@ -20761,7 +20761,7 @@ class LayeredIndex {
20761
20761
 
20762
20762
  // src/SpatialIndex/SpacialIndex.ts
20763
20763
  function worldBoundsToLocal(container, left, top, right, bottom) {
20764
- const inv = container.getWorldMatrix().getInverse();
20764
+ const inv = container.getNestingMatrix().getInverse();
20765
20765
  const corners = [
20766
20766
  new Point(left, top),
20767
20767
  new Point(right, top),
@@ -21056,7 +21056,7 @@ class SpatialIndex {
21056
21056
  const clearItems = items.filter((item) => {
21057
21057
  if ("index" in item && item.index) {
21058
21058
  const localPt = new Point(point3.x, point3.y);
21059
- item.getWorldMatrix().getInverse().apply(localPt);
21059
+ item.getNestingMatrix().getInverse().apply(localPt);
21060
21060
  children.push(...item.index.getUnderPoint(localPt, tolerance));
21061
21061
  if (!item.getMbr().isUnderPoint(point3)) {
21062
21062
  return false;
@@ -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);
@@ -40909,6 +40926,7 @@ class Frame2 extends BaseItem {
40909
40926
  scaleY = 1;
40910
40927
  translateY = 0;
40911
40928
  }
40929
+ const oldMatrix = this.transformation.toMatrix();
40912
40930
  this.transformation.scaleByTranslateBy({
40913
40931
  x: scaleX,
40914
40932
  y: scaleY
@@ -40916,6 +40934,16 @@ class Frame2 extends BaseItem {
40916
40934
  x: translateX,
40917
40935
  y: translateY
40918
40936
  }, timeStamp);
40937
+ const newMatrix = this.transformation.toMatrix();
40938
+ if (newMatrix.translateX !== oldMatrix.translateX || newMatrix.translateY !== oldMatrix.translateY) {
40939
+ const dx = newMatrix.translateX - oldMatrix.translateX;
40940
+ const dy = newMatrix.translateY - oldMatrix.translateY;
40941
+ this.index?.list().forEach((child) => {
40942
+ if (child instanceof BaseItem) {
40943
+ child.transformation.translateBy(-dx, -dy, timeStamp);
40944
+ }
40945
+ });
40946
+ }
40919
40947
  this.setLastFrameScale();
40920
40948
  res.mbr = this.getMbr();
40921
40949
  return res;
@@ -41192,8 +41220,9 @@ class Frame2 extends BaseItem {
41192
41220
  this.renderPath(context);
41193
41221
  const ctx = context.ctx;
41194
41222
  ctx.save();
41195
- this.transformation.applyToContext(ctx);
41196
- for (const child of this.index.list()) {
41223
+ const { translateX, translateY } = this.getWorldMatrix();
41224
+ ctx.translate(translateX, translateY);
41225
+ for (const child of this.index.items.listAll()) {
41197
41226
  child.render(context);
41198
41227
  }
41199
41228
  ctx.restore();
package/dist/esm/index.js CHANGED
@@ -20754,7 +20754,7 @@ class LayeredIndex {
20754
20754
 
20755
20755
  // src/SpatialIndex/SpacialIndex.ts
20756
20756
  function worldBoundsToLocal(container, left, top, right, bottom) {
20757
- const inv = container.getWorldMatrix().getInverse();
20757
+ const inv = container.getNestingMatrix().getInverse();
20758
20758
  const corners = [
20759
20759
  new Point(left, top),
20760
20760
  new Point(right, top),
@@ -21049,7 +21049,7 @@ class SpatialIndex {
21049
21049
  const clearItems = items.filter((item) => {
21050
21050
  if ("index" in item && item.index) {
21051
21051
  const localPt = new Point(point3.x, point3.y);
21052
- item.getWorldMatrix().getInverse().apply(localPt);
21052
+ item.getNestingMatrix().getInverse().apply(localPt);
21053
21053
  children.push(...item.index.getUnderPoint(localPt, tolerance));
21054
21054
  if (!item.getMbr().isUnderPoint(point3)) {
21055
21055
  return false;
@@ -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);
@@ -40902,6 +40919,7 @@ class Frame2 extends BaseItem {
40902
40919
  scaleY = 1;
40903
40920
  translateY = 0;
40904
40921
  }
40922
+ const oldMatrix = this.transformation.toMatrix();
40905
40923
  this.transformation.scaleByTranslateBy({
40906
40924
  x: scaleX,
40907
40925
  y: scaleY
@@ -40909,6 +40927,16 @@ class Frame2 extends BaseItem {
40909
40927
  x: translateX,
40910
40928
  y: translateY
40911
40929
  }, timeStamp);
40930
+ const newMatrix = this.transformation.toMatrix();
40931
+ if (newMatrix.translateX !== oldMatrix.translateX || newMatrix.translateY !== oldMatrix.translateY) {
40932
+ const dx = newMatrix.translateX - oldMatrix.translateX;
40933
+ const dy = newMatrix.translateY - oldMatrix.translateY;
40934
+ this.index?.list().forEach((child) => {
40935
+ if (child instanceof BaseItem) {
40936
+ child.transformation.translateBy(-dx, -dy, timeStamp);
40937
+ }
40938
+ });
40939
+ }
40912
40940
  this.setLastFrameScale();
40913
40941
  res.mbr = this.getMbr();
40914
40942
  return res;
@@ -41185,8 +41213,9 @@ class Frame2 extends BaseItem {
41185
41213
  this.renderPath(context);
41186
41214
  const ctx = context.ctx;
41187
41215
  ctx.save();
41188
- this.transformation.applyToContext(ctx);
41189
- for (const child of this.index.list()) {
41216
+ const { translateX, translateY } = this.getWorldMatrix();
41217
+ ctx.translate(translateX, translateY);
41218
+ for (const child of this.index.items.listAll()) {
41190
41219
  child.render(context);
41191
41220
  }
41192
41221
  ctx.restore();
package/dist/esm/node.js CHANGED
@@ -23221,7 +23221,7 @@ class LayeredIndex {
23221
23221
 
23222
23222
  // src/SpatialIndex/SpacialIndex.ts
23223
23223
  function worldBoundsToLocal(container, left, top, right, bottom) {
23224
- const inv = container.getWorldMatrix().getInverse();
23224
+ const inv = container.getNestingMatrix().getInverse();
23225
23225
  const corners = [
23226
23226
  new Point(left, top),
23227
23227
  new Point(right, top),
@@ -23516,7 +23516,7 @@ class SpatialIndex {
23516
23516
  const clearItems = items.filter((item) => {
23517
23517
  if ("index" in item && item.index) {
23518
23518
  const localPt = new Point(point3.x, point3.y);
23519
- item.getWorldMatrix().getInverse().apply(localPt);
23519
+ item.getNestingMatrix().getInverse().apply(localPt);
23520
23520
  children.push(...item.index.getUnderPoint(localPt, tolerance));
23521
23521
  if (!item.getMbr().isUnderPoint(point3)) {
23522
23522
  return false;
@@ -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);
@@ -43370,6 +43387,7 @@ class Frame2 extends BaseItem {
43370
43387
  scaleY = 1;
43371
43388
  translateY = 0;
43372
43389
  }
43390
+ const oldMatrix = this.transformation.toMatrix();
43373
43391
  this.transformation.scaleByTranslateBy({
43374
43392
  x: scaleX,
43375
43393
  y: scaleY
@@ -43377,6 +43395,16 @@ class Frame2 extends BaseItem {
43377
43395
  x: translateX,
43378
43396
  y: translateY
43379
43397
  }, timeStamp);
43398
+ const newMatrix = this.transformation.toMatrix();
43399
+ if (newMatrix.translateX !== oldMatrix.translateX || newMatrix.translateY !== oldMatrix.translateY) {
43400
+ const dx = newMatrix.translateX - oldMatrix.translateX;
43401
+ const dy = newMatrix.translateY - oldMatrix.translateY;
43402
+ this.index?.list().forEach((child) => {
43403
+ if (child instanceof BaseItem) {
43404
+ child.transformation.translateBy(-dx, -dy, timeStamp);
43405
+ }
43406
+ });
43407
+ }
43380
43408
  this.setLastFrameScale();
43381
43409
  res.mbr = this.getMbr();
43382
43410
  return res;
@@ -43653,8 +43681,9 @@ class Frame2 extends BaseItem {
43653
43681
  this.renderPath(context);
43654
43682
  const ctx = context.ctx;
43655
43683
  ctx.save();
43656
- this.transformation.applyToContext(ctx);
43657
- for (const child of this.index.list()) {
43684
+ const { translateX, translateY } = this.getWorldMatrix();
43685
+ ctx.translate(translateX, translateY);
43686
+ for (const child of this.index.items.listAll()) {
43658
43687
  child.render(context);
43659
43688
  }
43660
43689
  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.5",
4
4
  "description": "A flexible interactive whiteboard library",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",