microboard-temp 0.4.88 → 0.4.90

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.
@@ -47836,8 +47836,10 @@ class Card extends BaseItem {
47836
47836
  this.throttledBringToFront = throttle(() => {
47837
47837
  this.board.bringToFront(this);
47838
47838
  }, 1000);
47839
- this.transformation.subject.subscribe(() => {
47840
- this.throttledBringToFront();
47839
+ this.transformation.subject.subscribe((_, op) => {
47840
+ if (this.parent === "Board" && op.method === "translateBy" || op.method === "transformMany" && !Object.keys(op.items).length) {
47841
+ this.throttledBringToFront();
47842
+ }
47841
47843
  this.updateMbr();
47842
47844
  this.subject.publish(this);
47843
47845
  });
@@ -47926,6 +47928,8 @@ var defaultDeckData = {
47926
47928
  class Deck extends BaseItem {
47927
47929
  subject = new Subject;
47928
47930
  shouldUseCustomRender = false;
47931
+ cachedCanvas = null;
47932
+ isCacheDirty = true;
47929
47933
  constructor(board, id = "") {
47930
47934
  super(board, id, defaultDeckData, true);
47931
47935
  this.index.getUnderPoint = () => [];
@@ -48023,6 +48027,9 @@ class Deck extends BaseItem {
48023
48027
  }
48024
48028
  apply(op) {
48025
48029
  super.apply(op);
48030
+ if (op.class === "Deck") {
48031
+ this.isCacheDirty = true;
48032
+ }
48026
48033
  this.subject.publish(this);
48027
48034
  }
48028
48035
  updateMbr() {
@@ -48044,7 +48051,27 @@ class Deck extends BaseItem {
48044
48051
  if (this.transformationRenderBlock) {
48045
48052
  return;
48046
48053
  }
48047
- super.render(context);
48054
+ const ctx = context.ctx;
48055
+ if (this.isCacheDirty || !this.cachedCanvas) {
48056
+ this.updateCache(context);
48057
+ this.isCacheDirty = false;
48058
+ }
48059
+ if (this.cachedCanvas) {
48060
+ ctx.save();
48061
+ ctx.drawImage(this.cachedCanvas, this.left, this.top);
48062
+ ctx.restore();
48063
+ }
48064
+ }
48065
+ updateCache(context) {
48066
+ const tempCanvas = document.createElement("canvas");
48067
+ tempCanvas.width = this.getWidth();
48068
+ tempCanvas.height = this.getHeight();
48069
+ const tempCtx = tempCanvas.getContext("2d");
48070
+ if (!tempCtx)
48071
+ return;
48072
+ const tempContext = { ...context, ctx: tempCtx };
48073
+ this.index?.render(tempContext);
48074
+ this.cachedCanvas = tempCanvas;
48048
48075
  }
48049
48076
  }
48050
48077
  registerItem({
package/dist/cjs/index.js CHANGED
@@ -47836,8 +47836,10 @@ class Card extends BaseItem {
47836
47836
  this.throttledBringToFront = throttle(() => {
47837
47837
  this.board.bringToFront(this);
47838
47838
  }, 1000);
47839
- this.transformation.subject.subscribe(() => {
47840
- this.throttledBringToFront();
47839
+ this.transformation.subject.subscribe((_, op) => {
47840
+ if (this.parent === "Board" && op.method === "translateBy" || op.method === "transformMany" && !Object.keys(op.items).length) {
47841
+ this.throttledBringToFront();
47842
+ }
47841
47843
  this.updateMbr();
47842
47844
  this.subject.publish(this);
47843
47845
  });
@@ -47926,6 +47928,8 @@ var defaultDeckData = {
47926
47928
  class Deck extends BaseItem {
47927
47929
  subject = new Subject;
47928
47930
  shouldUseCustomRender = false;
47931
+ cachedCanvas = null;
47932
+ isCacheDirty = true;
47929
47933
  constructor(board, id = "") {
47930
47934
  super(board, id, defaultDeckData, true);
47931
47935
  this.index.getUnderPoint = () => [];
@@ -48023,6 +48027,9 @@ class Deck extends BaseItem {
48023
48027
  }
48024
48028
  apply(op) {
48025
48029
  super.apply(op);
48030
+ if (op.class === "Deck") {
48031
+ this.isCacheDirty = true;
48032
+ }
48026
48033
  this.subject.publish(this);
48027
48034
  }
48028
48035
  updateMbr() {
@@ -48044,7 +48051,27 @@ class Deck extends BaseItem {
48044
48051
  if (this.transformationRenderBlock) {
48045
48052
  return;
48046
48053
  }
48047
- super.render(context);
48054
+ const ctx = context.ctx;
48055
+ if (this.isCacheDirty || !this.cachedCanvas) {
48056
+ this.updateCache(context);
48057
+ this.isCacheDirty = false;
48058
+ }
48059
+ if (this.cachedCanvas) {
48060
+ ctx.save();
48061
+ ctx.drawImage(this.cachedCanvas, this.left, this.top);
48062
+ ctx.restore();
48063
+ }
48064
+ }
48065
+ updateCache(context) {
48066
+ const tempCanvas = document.createElement("canvas");
48067
+ tempCanvas.width = this.getWidth();
48068
+ tempCanvas.height = this.getHeight();
48069
+ const tempCtx = tempCanvas.getContext("2d");
48070
+ if (!tempCtx)
48071
+ return;
48072
+ const tempContext = { ...context, ctx: tempCtx };
48073
+ this.index?.render(tempContext);
48074
+ this.cachedCanvas = tempCanvas;
48048
48075
  }
48049
48076
  }
48050
48077
  registerItem({
package/dist/cjs/node.js CHANGED
@@ -50309,8 +50309,10 @@ class Card extends BaseItem {
50309
50309
  this.throttledBringToFront = throttle(() => {
50310
50310
  this.board.bringToFront(this);
50311
50311
  }, 1000);
50312
- this.transformation.subject.subscribe(() => {
50313
- this.throttledBringToFront();
50312
+ this.transformation.subject.subscribe((_, op) => {
50313
+ if (this.parent === "Board" && op.method === "translateBy" || op.method === "transformMany" && !Object.keys(op.items).length) {
50314
+ this.throttledBringToFront();
50315
+ }
50314
50316
  this.updateMbr();
50315
50317
  this.subject.publish(this);
50316
50318
  });
@@ -50399,6 +50401,8 @@ var defaultDeckData = {
50399
50401
  class Deck extends BaseItem {
50400
50402
  subject = new Subject;
50401
50403
  shouldUseCustomRender = false;
50404
+ cachedCanvas = null;
50405
+ isCacheDirty = true;
50402
50406
  constructor(board, id = "") {
50403
50407
  super(board, id, defaultDeckData, true);
50404
50408
  this.index.getUnderPoint = () => [];
@@ -50496,6 +50500,9 @@ class Deck extends BaseItem {
50496
50500
  }
50497
50501
  apply(op) {
50498
50502
  super.apply(op);
50503
+ if (op.class === "Deck") {
50504
+ this.isCacheDirty = true;
50505
+ }
50499
50506
  this.subject.publish(this);
50500
50507
  }
50501
50508
  updateMbr() {
@@ -50517,7 +50524,27 @@ class Deck extends BaseItem {
50517
50524
  if (this.transformationRenderBlock) {
50518
50525
  return;
50519
50526
  }
50520
- super.render(context);
50527
+ const ctx = context.ctx;
50528
+ if (this.isCacheDirty || !this.cachedCanvas) {
50529
+ this.updateCache(context);
50530
+ this.isCacheDirty = false;
50531
+ }
50532
+ if (this.cachedCanvas) {
50533
+ ctx.save();
50534
+ ctx.drawImage(this.cachedCanvas, this.left, this.top);
50535
+ ctx.restore();
50536
+ }
50537
+ }
50538
+ updateCache(context) {
50539
+ const tempCanvas = document.createElement("canvas");
50540
+ tempCanvas.width = this.getWidth();
50541
+ tempCanvas.height = this.getHeight();
50542
+ const tempCtx = tempCanvas.getContext("2d");
50543
+ if (!tempCtx)
50544
+ return;
50545
+ const tempContext = { ...context, ctx: tempCtx };
50546
+ this.index?.render(tempContext);
50547
+ this.cachedCanvas = tempCanvas;
50521
50548
  }
50522
50549
  }
50523
50550
  registerItem({
@@ -47685,8 +47685,10 @@ class Card extends BaseItem {
47685
47685
  this.throttledBringToFront = throttle(() => {
47686
47686
  this.board.bringToFront(this);
47687
47687
  }, 1000);
47688
- this.transformation.subject.subscribe(() => {
47689
- this.throttledBringToFront();
47688
+ this.transformation.subject.subscribe((_, op) => {
47689
+ if (this.parent === "Board" && op.method === "translateBy" || op.method === "transformMany" && !Object.keys(op.items).length) {
47690
+ this.throttledBringToFront();
47691
+ }
47690
47692
  this.updateMbr();
47691
47693
  this.subject.publish(this);
47692
47694
  });
@@ -47775,6 +47777,8 @@ var defaultDeckData = {
47775
47777
  class Deck extends BaseItem {
47776
47778
  subject = new Subject;
47777
47779
  shouldUseCustomRender = false;
47780
+ cachedCanvas = null;
47781
+ isCacheDirty = true;
47778
47782
  constructor(board, id = "") {
47779
47783
  super(board, id, defaultDeckData, true);
47780
47784
  this.index.getUnderPoint = () => [];
@@ -47872,6 +47876,9 @@ class Deck extends BaseItem {
47872
47876
  }
47873
47877
  apply(op) {
47874
47878
  super.apply(op);
47879
+ if (op.class === "Deck") {
47880
+ this.isCacheDirty = true;
47881
+ }
47875
47882
  this.subject.publish(this);
47876
47883
  }
47877
47884
  updateMbr() {
@@ -47893,7 +47900,27 @@ class Deck extends BaseItem {
47893
47900
  if (this.transformationRenderBlock) {
47894
47901
  return;
47895
47902
  }
47896
- super.render(context);
47903
+ const ctx = context.ctx;
47904
+ if (this.isCacheDirty || !this.cachedCanvas) {
47905
+ this.updateCache(context);
47906
+ this.isCacheDirty = false;
47907
+ }
47908
+ if (this.cachedCanvas) {
47909
+ ctx.save();
47910
+ ctx.drawImage(this.cachedCanvas, this.left, this.top);
47911
+ ctx.restore();
47912
+ }
47913
+ }
47914
+ updateCache(context) {
47915
+ const tempCanvas = document.createElement("canvas");
47916
+ tempCanvas.width = this.getWidth();
47917
+ tempCanvas.height = this.getHeight();
47918
+ const tempCtx = tempCanvas.getContext("2d");
47919
+ if (!tempCtx)
47920
+ return;
47921
+ const tempContext = { ...context, ctx: tempCtx };
47922
+ this.index?.render(tempContext);
47923
+ this.cachedCanvas = tempCanvas;
47897
47924
  }
47898
47925
  }
47899
47926
  registerItem({
package/dist/esm/index.js CHANGED
@@ -47678,8 +47678,10 @@ class Card extends BaseItem {
47678
47678
  this.throttledBringToFront = throttle(() => {
47679
47679
  this.board.bringToFront(this);
47680
47680
  }, 1000);
47681
- this.transformation.subject.subscribe(() => {
47682
- this.throttledBringToFront();
47681
+ this.transformation.subject.subscribe((_, op) => {
47682
+ if (this.parent === "Board" && op.method === "translateBy" || op.method === "transformMany" && !Object.keys(op.items).length) {
47683
+ this.throttledBringToFront();
47684
+ }
47683
47685
  this.updateMbr();
47684
47686
  this.subject.publish(this);
47685
47687
  });
@@ -47768,6 +47770,8 @@ var defaultDeckData = {
47768
47770
  class Deck extends BaseItem {
47769
47771
  subject = new Subject;
47770
47772
  shouldUseCustomRender = false;
47773
+ cachedCanvas = null;
47774
+ isCacheDirty = true;
47771
47775
  constructor(board, id = "") {
47772
47776
  super(board, id, defaultDeckData, true);
47773
47777
  this.index.getUnderPoint = () => [];
@@ -47865,6 +47869,9 @@ class Deck extends BaseItem {
47865
47869
  }
47866
47870
  apply(op) {
47867
47871
  super.apply(op);
47872
+ if (op.class === "Deck") {
47873
+ this.isCacheDirty = true;
47874
+ }
47868
47875
  this.subject.publish(this);
47869
47876
  }
47870
47877
  updateMbr() {
@@ -47886,7 +47893,27 @@ class Deck extends BaseItem {
47886
47893
  if (this.transformationRenderBlock) {
47887
47894
  return;
47888
47895
  }
47889
- super.render(context);
47896
+ const ctx = context.ctx;
47897
+ if (this.isCacheDirty || !this.cachedCanvas) {
47898
+ this.updateCache(context);
47899
+ this.isCacheDirty = false;
47900
+ }
47901
+ if (this.cachedCanvas) {
47902
+ ctx.save();
47903
+ ctx.drawImage(this.cachedCanvas, this.left, this.top);
47904
+ ctx.restore();
47905
+ }
47906
+ }
47907
+ updateCache(context) {
47908
+ const tempCanvas = document.createElement("canvas");
47909
+ tempCanvas.width = this.getWidth();
47910
+ tempCanvas.height = this.getHeight();
47911
+ const tempCtx = tempCanvas.getContext("2d");
47912
+ if (!tempCtx)
47913
+ return;
47914
+ const tempContext = { ...context, ctx: tempCtx };
47915
+ this.index?.render(tempContext);
47916
+ this.cachedCanvas = tempCanvas;
47890
47917
  }
47891
47918
  }
47892
47919
  registerItem({
package/dist/esm/node.js CHANGED
@@ -50146,8 +50146,10 @@ class Card extends BaseItem {
50146
50146
  this.throttledBringToFront = throttle(() => {
50147
50147
  this.board.bringToFront(this);
50148
50148
  }, 1000);
50149
- this.transformation.subject.subscribe(() => {
50150
- this.throttledBringToFront();
50149
+ this.transformation.subject.subscribe((_, op) => {
50150
+ if (this.parent === "Board" && op.method === "translateBy" || op.method === "transformMany" && !Object.keys(op.items).length) {
50151
+ this.throttledBringToFront();
50152
+ }
50151
50153
  this.updateMbr();
50152
50154
  this.subject.publish(this);
50153
50155
  });
@@ -50236,6 +50238,8 @@ var defaultDeckData = {
50236
50238
  class Deck extends BaseItem {
50237
50239
  subject = new Subject;
50238
50240
  shouldUseCustomRender = false;
50241
+ cachedCanvas = null;
50242
+ isCacheDirty = true;
50239
50243
  constructor(board, id = "") {
50240
50244
  super(board, id, defaultDeckData, true);
50241
50245
  this.index.getUnderPoint = () => [];
@@ -50333,6 +50337,9 @@ class Deck extends BaseItem {
50333
50337
  }
50334
50338
  apply(op) {
50335
50339
  super.apply(op);
50340
+ if (op.class === "Deck") {
50341
+ this.isCacheDirty = true;
50342
+ }
50336
50343
  this.subject.publish(this);
50337
50344
  }
50338
50345
  updateMbr() {
@@ -50354,7 +50361,27 @@ class Deck extends BaseItem {
50354
50361
  if (this.transformationRenderBlock) {
50355
50362
  return;
50356
50363
  }
50357
- super.render(context);
50364
+ const ctx = context.ctx;
50365
+ if (this.isCacheDirty || !this.cachedCanvas) {
50366
+ this.updateCache(context);
50367
+ this.isCacheDirty = false;
50368
+ }
50369
+ if (this.cachedCanvas) {
50370
+ ctx.save();
50371
+ ctx.drawImage(this.cachedCanvas, this.left, this.top);
50372
+ ctx.restore();
50373
+ }
50374
+ }
50375
+ updateCache(context) {
50376
+ const tempCanvas = document.createElement("canvas");
50377
+ tempCanvas.width = this.getWidth();
50378
+ tempCanvas.height = this.getHeight();
50379
+ const tempCtx = tempCanvas.getContext("2d");
50380
+ if (!tempCtx)
50381
+ return;
50382
+ const tempContext = { ...context, ctx: tempCtx };
50383
+ this.index?.render(tempContext);
50384
+ this.cachedCanvas = tempCanvas;
50358
50385
  }
50359
50386
  }
50360
50387
  registerItem({
@@ -8,6 +8,8 @@ export declare const defaultDeckData: BaseItemData;
8
8
  export declare class Deck extends BaseItem {
9
9
  readonly subject: Subject<Deck>;
10
10
  shouldUseCustomRender: boolean;
11
+ private cachedCanvas;
12
+ private isCacheDirty;
11
13
  constructor(board: Board, id?: string);
12
14
  applyAddChildren(childIds: string[]): void;
13
15
  applyRemoveChildren(childIds: string[]): void;
@@ -20,4 +22,5 @@ export declare class Deck extends BaseItem {
20
22
  updateMbr(): void;
21
23
  deserialize(data: SerializedItemData): this;
22
24
  render(context: DrawingContext): void;
25
+ private updateCache;
23
26
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "microboard-temp",
3
- "version": "0.4.88",
3
+ "version": "0.4.90",
4
4
  "description": "A flexible interactive whiteboard library",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",