microboard-temp 0.4.16 → 0.4.18

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.
@@ -46222,11 +46222,18 @@ registerItem({
46222
46222
  item: Deck,
46223
46223
  defaultData: defaultDeckData
46224
46224
  });
46225
+ // src/Items/Examples/CardGame/Dice/AddDice.ts
46226
+ class AddDice extends ShapeTool {
46227
+ constructor(board, name) {
46228
+ super(board, name, Dice, { cursorName: "crosshair", fixedRatio: true });
46229
+ }
46230
+ }
46231
+
46225
46232
  // src/Items/Examples/CardGame/Dice/Dice.ts
46226
46233
  var TIMEOUT = 3000;
46227
46234
  var defaultDiceData = {
46228
46235
  itemType: "Dice",
46229
- backgroundColor: "#000207",
46236
+ backgroundColor: "#FFFFFF",
46230
46237
  backgroundOpacity: 1,
46231
46238
  borderColor: "#000207",
46232
46239
  borderOpacity: 1,
@@ -46241,9 +46248,10 @@ class Dice extends BaseItem {
46241
46248
  path;
46242
46249
  subject = new Subject;
46243
46250
  borderWidth = 1;
46244
- isRotating = false;
46245
46251
  value = 1;
46246
46252
  range = { min: 1, max: 6 };
46253
+ animationFrameId;
46254
+ drawingContext = null;
46247
46255
  constructor(board, id = "") {
46248
46256
  super(board, id, defaultDiceData);
46249
46257
  this.transformPath();
@@ -46262,11 +46270,12 @@ class Dice extends BaseItem {
46262
46270
  this.path.setBorderWidth(this.borderWidth);
46263
46271
  }
46264
46272
  render(context) {
46273
+ this.drawingContext = context;
46265
46274
  if (this.transformationRenderBlock) {
46266
46275
  return;
46267
46276
  }
46268
46277
  context.ctx.save();
46269
- if (this.isRotating) {
46278
+ if (this.animationFrameId) {
46270
46279
  const now = Date.now();
46271
46280
  const angle = now % 1000 / 1000 * 2 * Math.PI;
46272
46281
  const mbr2 = this.getMbr();
@@ -46353,15 +46362,6 @@ class Dice extends BaseItem {
46353
46362
  prevData: { borderColor: this.borderColor }
46354
46363
  });
46355
46364
  }
46356
- setIsRotating(isRotating) {
46357
- this.emit({
46358
- class: "Dice",
46359
- method: "setIsRotating",
46360
- item: [this.getId()],
46361
- newData: { isRotating },
46362
- prevData: { isRotating: false }
46363
- });
46364
- }
46365
46365
  setValuesRange(range) {
46366
46366
  this.emit({
46367
46367
  class: "Dice",
@@ -46380,11 +46380,19 @@ class Dice extends BaseItem {
46380
46380
  prevData: { value: this.value }
46381
46381
  });
46382
46382
  }
46383
+ setIsRotating(isRotating) {
46384
+ this.emit({
46385
+ class: "Dice",
46386
+ method: "setIsRotating",
46387
+ item: [this.getId()],
46388
+ newData: { isRotating },
46389
+ prevData: { isRotating: false }
46390
+ });
46391
+ }
46383
46392
  throwDice() {
46384
46393
  this.setIsRotating(true);
46385
46394
  setTimeout(() => {
46386
46395
  this.setValue(Math.ceil(Math.random() * (this.range.max - this.range.min)) + this.range.min);
46387
- this.isRotating = false;
46388
46396
  }, TIMEOUT);
46389
46397
  }
46390
46398
  apply(op) {
@@ -46402,16 +46410,15 @@ class Dice extends BaseItem {
46402
46410
  this.applyBorderColor(op.newData.borderColor);
46403
46411
  break;
46404
46412
  case "setIsRotating":
46405
- this.isRotating = op.newData.isRotating;
46406
46413
  if (op.newData.isRotating) {
46414
+ this.startRotation();
46407
46415
  setTimeout(() => {
46408
- this.isRotating = false;
46416
+ this.stopRotation();
46409
46417
  }, TIMEOUT);
46410
46418
  }
46411
46419
  break;
46412
46420
  case "changeValue":
46413
46421
  this.value = op.newData.value;
46414
- this.isRotating = false;
46415
46422
  break;
46416
46423
  case "changeValuesRange":
46417
46424
  this.range = op.newData;
@@ -46421,11 +46428,29 @@ class Dice extends BaseItem {
46421
46428
  }
46422
46429
  this.subject.publish(this);
46423
46430
  }
46431
+ startRotation() {
46432
+ if (!this.animationFrameId) {
46433
+ const animate = () => {
46434
+ if (this.drawingContext) {
46435
+ this.render(this.drawingContext);
46436
+ this.animationFrameId = requestAnimationFrame(animate);
46437
+ }
46438
+ };
46439
+ this.animationFrameId = requestAnimationFrame(animate);
46440
+ }
46441
+ }
46442
+ stopRotation() {
46443
+ if (this.animationFrameId) {
46444
+ cancelAnimationFrame(this.animationFrameId);
46445
+ this.animationFrameId = undefined;
46446
+ this.drawingContext = null;
46447
+ }
46448
+ }
46424
46449
  }
46425
46450
  registerItem({
46426
46451
  item: Dice,
46427
46452
  defaultData: defaultDiceData,
46428
- toolData: { name: "AddDice", tool: ShapeTool }
46453
+ toolData: { name: "AddDice", tool: AddDice }
46429
46454
  });
46430
46455
  // src/Pointer/Cursor.ts
46431
46456
  var defaultCursors = [
package/dist/cjs/index.js CHANGED
@@ -46222,11 +46222,18 @@ registerItem({
46222
46222
  item: Deck,
46223
46223
  defaultData: defaultDeckData
46224
46224
  });
46225
+ // src/Items/Examples/CardGame/Dice/AddDice.ts
46226
+ class AddDice extends ShapeTool {
46227
+ constructor(board, name) {
46228
+ super(board, name, Dice, { cursorName: "crosshair", fixedRatio: true });
46229
+ }
46230
+ }
46231
+
46225
46232
  // src/Items/Examples/CardGame/Dice/Dice.ts
46226
46233
  var TIMEOUT = 3000;
46227
46234
  var defaultDiceData = {
46228
46235
  itemType: "Dice",
46229
- backgroundColor: "#000207",
46236
+ backgroundColor: "#FFFFFF",
46230
46237
  backgroundOpacity: 1,
46231
46238
  borderColor: "#000207",
46232
46239
  borderOpacity: 1,
@@ -46241,9 +46248,10 @@ class Dice extends BaseItem {
46241
46248
  path;
46242
46249
  subject = new Subject;
46243
46250
  borderWidth = 1;
46244
- isRotating = false;
46245
46251
  value = 1;
46246
46252
  range = { min: 1, max: 6 };
46253
+ animationFrameId;
46254
+ drawingContext = null;
46247
46255
  constructor(board, id = "") {
46248
46256
  super(board, id, defaultDiceData);
46249
46257
  this.transformPath();
@@ -46262,11 +46270,12 @@ class Dice extends BaseItem {
46262
46270
  this.path.setBorderWidth(this.borderWidth);
46263
46271
  }
46264
46272
  render(context) {
46273
+ this.drawingContext = context;
46265
46274
  if (this.transformationRenderBlock) {
46266
46275
  return;
46267
46276
  }
46268
46277
  context.ctx.save();
46269
- if (this.isRotating) {
46278
+ if (this.animationFrameId) {
46270
46279
  const now = Date.now();
46271
46280
  const angle = now % 1000 / 1000 * 2 * Math.PI;
46272
46281
  const mbr2 = this.getMbr();
@@ -46353,15 +46362,6 @@ class Dice extends BaseItem {
46353
46362
  prevData: { borderColor: this.borderColor }
46354
46363
  });
46355
46364
  }
46356
- setIsRotating(isRotating) {
46357
- this.emit({
46358
- class: "Dice",
46359
- method: "setIsRotating",
46360
- item: [this.getId()],
46361
- newData: { isRotating },
46362
- prevData: { isRotating: false }
46363
- });
46364
- }
46365
46365
  setValuesRange(range) {
46366
46366
  this.emit({
46367
46367
  class: "Dice",
@@ -46380,11 +46380,19 @@ class Dice extends BaseItem {
46380
46380
  prevData: { value: this.value }
46381
46381
  });
46382
46382
  }
46383
+ setIsRotating(isRotating) {
46384
+ this.emit({
46385
+ class: "Dice",
46386
+ method: "setIsRotating",
46387
+ item: [this.getId()],
46388
+ newData: { isRotating },
46389
+ prevData: { isRotating: false }
46390
+ });
46391
+ }
46383
46392
  throwDice() {
46384
46393
  this.setIsRotating(true);
46385
46394
  setTimeout(() => {
46386
46395
  this.setValue(Math.ceil(Math.random() * (this.range.max - this.range.min)) + this.range.min);
46387
- this.isRotating = false;
46388
46396
  }, TIMEOUT);
46389
46397
  }
46390
46398
  apply(op) {
@@ -46402,16 +46410,15 @@ class Dice extends BaseItem {
46402
46410
  this.applyBorderColor(op.newData.borderColor);
46403
46411
  break;
46404
46412
  case "setIsRotating":
46405
- this.isRotating = op.newData.isRotating;
46406
46413
  if (op.newData.isRotating) {
46414
+ this.startRotation();
46407
46415
  setTimeout(() => {
46408
- this.isRotating = false;
46416
+ this.stopRotation();
46409
46417
  }, TIMEOUT);
46410
46418
  }
46411
46419
  break;
46412
46420
  case "changeValue":
46413
46421
  this.value = op.newData.value;
46414
- this.isRotating = false;
46415
46422
  break;
46416
46423
  case "changeValuesRange":
46417
46424
  this.range = op.newData;
@@ -46421,11 +46428,29 @@ class Dice extends BaseItem {
46421
46428
  }
46422
46429
  this.subject.publish(this);
46423
46430
  }
46431
+ startRotation() {
46432
+ if (!this.animationFrameId) {
46433
+ const animate = () => {
46434
+ if (this.drawingContext) {
46435
+ this.render(this.drawingContext);
46436
+ this.animationFrameId = requestAnimationFrame(animate);
46437
+ }
46438
+ };
46439
+ this.animationFrameId = requestAnimationFrame(animate);
46440
+ }
46441
+ }
46442
+ stopRotation() {
46443
+ if (this.animationFrameId) {
46444
+ cancelAnimationFrame(this.animationFrameId);
46445
+ this.animationFrameId = undefined;
46446
+ this.drawingContext = null;
46447
+ }
46448
+ }
46424
46449
  }
46425
46450
  registerItem({
46426
46451
  item: Dice,
46427
46452
  defaultData: defaultDiceData,
46428
- toolData: { name: "AddDice", tool: ShapeTool }
46453
+ toolData: { name: "AddDice", tool: AddDice }
46429
46454
  });
46430
46455
  // src/Pointer/Cursor.ts
46431
46456
  var defaultCursors = [
package/dist/cjs/node.js CHANGED
@@ -48762,11 +48762,18 @@ registerItem({
48762
48762
  item: Deck,
48763
48763
  defaultData: defaultDeckData
48764
48764
  });
48765
+ // src/Items/Examples/CardGame/Dice/AddDice.ts
48766
+ class AddDice extends ShapeTool {
48767
+ constructor(board, name) {
48768
+ super(board, name, Dice, { cursorName: "crosshair", fixedRatio: true });
48769
+ }
48770
+ }
48771
+
48765
48772
  // src/Items/Examples/CardGame/Dice/Dice.ts
48766
48773
  var TIMEOUT = 3000;
48767
48774
  var defaultDiceData = {
48768
48775
  itemType: "Dice",
48769
- backgroundColor: "#000207",
48776
+ backgroundColor: "#FFFFFF",
48770
48777
  backgroundOpacity: 1,
48771
48778
  borderColor: "#000207",
48772
48779
  borderOpacity: 1,
@@ -48781,9 +48788,10 @@ class Dice extends BaseItem {
48781
48788
  path;
48782
48789
  subject = new Subject;
48783
48790
  borderWidth = 1;
48784
- isRotating = false;
48785
48791
  value = 1;
48786
48792
  range = { min: 1, max: 6 };
48793
+ animationFrameId;
48794
+ drawingContext = null;
48787
48795
  constructor(board, id = "") {
48788
48796
  super(board, id, defaultDiceData);
48789
48797
  this.transformPath();
@@ -48802,11 +48810,12 @@ class Dice extends BaseItem {
48802
48810
  this.path.setBorderWidth(this.borderWidth);
48803
48811
  }
48804
48812
  render(context) {
48813
+ this.drawingContext = context;
48805
48814
  if (this.transformationRenderBlock) {
48806
48815
  return;
48807
48816
  }
48808
48817
  context.ctx.save();
48809
- if (this.isRotating) {
48818
+ if (this.animationFrameId) {
48810
48819
  const now = Date.now();
48811
48820
  const angle = now % 1000 / 1000 * 2 * Math.PI;
48812
48821
  const mbr2 = this.getMbr();
@@ -48893,15 +48902,6 @@ class Dice extends BaseItem {
48893
48902
  prevData: { borderColor: this.borderColor }
48894
48903
  });
48895
48904
  }
48896
- setIsRotating(isRotating) {
48897
- this.emit({
48898
- class: "Dice",
48899
- method: "setIsRotating",
48900
- item: [this.getId()],
48901
- newData: { isRotating },
48902
- prevData: { isRotating: false }
48903
- });
48904
- }
48905
48905
  setValuesRange(range) {
48906
48906
  this.emit({
48907
48907
  class: "Dice",
@@ -48920,11 +48920,19 @@ class Dice extends BaseItem {
48920
48920
  prevData: { value: this.value }
48921
48921
  });
48922
48922
  }
48923
+ setIsRotating(isRotating) {
48924
+ this.emit({
48925
+ class: "Dice",
48926
+ method: "setIsRotating",
48927
+ item: [this.getId()],
48928
+ newData: { isRotating },
48929
+ prevData: { isRotating: false }
48930
+ });
48931
+ }
48923
48932
  throwDice() {
48924
48933
  this.setIsRotating(true);
48925
48934
  setTimeout(() => {
48926
48935
  this.setValue(Math.ceil(Math.random() * (this.range.max - this.range.min)) + this.range.min);
48927
- this.isRotating = false;
48928
48936
  }, TIMEOUT);
48929
48937
  }
48930
48938
  apply(op) {
@@ -48942,16 +48950,15 @@ class Dice extends BaseItem {
48942
48950
  this.applyBorderColor(op.newData.borderColor);
48943
48951
  break;
48944
48952
  case "setIsRotating":
48945
- this.isRotating = op.newData.isRotating;
48946
48953
  if (op.newData.isRotating) {
48954
+ this.startRotation();
48947
48955
  setTimeout(() => {
48948
- this.isRotating = false;
48956
+ this.stopRotation();
48949
48957
  }, TIMEOUT);
48950
48958
  }
48951
48959
  break;
48952
48960
  case "changeValue":
48953
48961
  this.value = op.newData.value;
48954
- this.isRotating = false;
48955
48962
  break;
48956
48963
  case "changeValuesRange":
48957
48964
  this.range = op.newData;
@@ -48961,11 +48968,29 @@ class Dice extends BaseItem {
48961
48968
  }
48962
48969
  this.subject.publish(this);
48963
48970
  }
48971
+ startRotation() {
48972
+ if (!this.animationFrameId) {
48973
+ const animate = () => {
48974
+ if (this.drawingContext) {
48975
+ this.render(this.drawingContext);
48976
+ this.animationFrameId = requestAnimationFrame(animate);
48977
+ }
48978
+ };
48979
+ this.animationFrameId = requestAnimationFrame(animate);
48980
+ }
48981
+ }
48982
+ stopRotation() {
48983
+ if (this.animationFrameId) {
48984
+ cancelAnimationFrame(this.animationFrameId);
48985
+ this.animationFrameId = undefined;
48986
+ this.drawingContext = null;
48987
+ }
48988
+ }
48964
48989
  }
48965
48990
  registerItem({
48966
48991
  item: Dice,
48967
48992
  defaultData: defaultDiceData,
48968
- toolData: { name: "AddDice", tool: ShapeTool }
48993
+ toolData: { name: "AddDice", tool: AddDice }
48969
48994
  });
48970
48995
  // src/Pointer/Cursor.ts
48971
48996
  var defaultCursors = [
@@ -46072,11 +46072,18 @@ registerItem({
46072
46072
  item: Deck,
46073
46073
  defaultData: defaultDeckData
46074
46074
  });
46075
+ // src/Items/Examples/CardGame/Dice/AddDice.ts
46076
+ class AddDice extends ShapeTool {
46077
+ constructor(board, name) {
46078
+ super(board, name, Dice, { cursorName: "crosshair", fixedRatio: true });
46079
+ }
46080
+ }
46081
+
46075
46082
  // src/Items/Examples/CardGame/Dice/Dice.ts
46076
46083
  var TIMEOUT = 3000;
46077
46084
  var defaultDiceData = {
46078
46085
  itemType: "Dice",
46079
- backgroundColor: "#000207",
46086
+ backgroundColor: "#FFFFFF",
46080
46087
  backgroundOpacity: 1,
46081
46088
  borderColor: "#000207",
46082
46089
  borderOpacity: 1,
@@ -46091,9 +46098,10 @@ class Dice extends BaseItem {
46091
46098
  path;
46092
46099
  subject = new Subject;
46093
46100
  borderWidth = 1;
46094
- isRotating = false;
46095
46101
  value = 1;
46096
46102
  range = { min: 1, max: 6 };
46103
+ animationFrameId;
46104
+ drawingContext = null;
46097
46105
  constructor(board, id = "") {
46098
46106
  super(board, id, defaultDiceData);
46099
46107
  this.transformPath();
@@ -46112,11 +46120,12 @@ class Dice extends BaseItem {
46112
46120
  this.path.setBorderWidth(this.borderWidth);
46113
46121
  }
46114
46122
  render(context) {
46123
+ this.drawingContext = context;
46115
46124
  if (this.transformationRenderBlock) {
46116
46125
  return;
46117
46126
  }
46118
46127
  context.ctx.save();
46119
- if (this.isRotating) {
46128
+ if (this.animationFrameId) {
46120
46129
  const now = Date.now();
46121
46130
  const angle = now % 1000 / 1000 * 2 * Math.PI;
46122
46131
  const mbr2 = this.getMbr();
@@ -46203,15 +46212,6 @@ class Dice extends BaseItem {
46203
46212
  prevData: { borderColor: this.borderColor }
46204
46213
  });
46205
46214
  }
46206
- setIsRotating(isRotating) {
46207
- this.emit({
46208
- class: "Dice",
46209
- method: "setIsRotating",
46210
- item: [this.getId()],
46211
- newData: { isRotating },
46212
- prevData: { isRotating: false }
46213
- });
46214
- }
46215
46215
  setValuesRange(range) {
46216
46216
  this.emit({
46217
46217
  class: "Dice",
@@ -46230,11 +46230,19 @@ class Dice extends BaseItem {
46230
46230
  prevData: { value: this.value }
46231
46231
  });
46232
46232
  }
46233
+ setIsRotating(isRotating) {
46234
+ this.emit({
46235
+ class: "Dice",
46236
+ method: "setIsRotating",
46237
+ item: [this.getId()],
46238
+ newData: { isRotating },
46239
+ prevData: { isRotating: false }
46240
+ });
46241
+ }
46233
46242
  throwDice() {
46234
46243
  this.setIsRotating(true);
46235
46244
  setTimeout(() => {
46236
46245
  this.setValue(Math.ceil(Math.random() * (this.range.max - this.range.min)) + this.range.min);
46237
- this.isRotating = false;
46238
46246
  }, TIMEOUT);
46239
46247
  }
46240
46248
  apply(op) {
@@ -46252,16 +46260,15 @@ class Dice extends BaseItem {
46252
46260
  this.applyBorderColor(op.newData.borderColor);
46253
46261
  break;
46254
46262
  case "setIsRotating":
46255
- this.isRotating = op.newData.isRotating;
46256
46263
  if (op.newData.isRotating) {
46264
+ this.startRotation();
46257
46265
  setTimeout(() => {
46258
- this.isRotating = false;
46266
+ this.stopRotation();
46259
46267
  }, TIMEOUT);
46260
46268
  }
46261
46269
  break;
46262
46270
  case "changeValue":
46263
46271
  this.value = op.newData.value;
46264
- this.isRotating = false;
46265
46272
  break;
46266
46273
  case "changeValuesRange":
46267
46274
  this.range = op.newData;
@@ -46271,11 +46278,29 @@ class Dice extends BaseItem {
46271
46278
  }
46272
46279
  this.subject.publish(this);
46273
46280
  }
46281
+ startRotation() {
46282
+ if (!this.animationFrameId) {
46283
+ const animate = () => {
46284
+ if (this.drawingContext) {
46285
+ this.render(this.drawingContext);
46286
+ this.animationFrameId = requestAnimationFrame(animate);
46287
+ }
46288
+ };
46289
+ this.animationFrameId = requestAnimationFrame(animate);
46290
+ }
46291
+ }
46292
+ stopRotation() {
46293
+ if (this.animationFrameId) {
46294
+ cancelAnimationFrame(this.animationFrameId);
46295
+ this.animationFrameId = undefined;
46296
+ this.drawingContext = null;
46297
+ }
46298
+ }
46274
46299
  }
46275
46300
  registerItem({
46276
46301
  item: Dice,
46277
46302
  defaultData: defaultDiceData,
46278
- toolData: { name: "AddDice", tool: ShapeTool }
46303
+ toolData: { name: "AddDice", tool: AddDice }
46279
46304
  });
46280
46305
  // src/Pointer/Cursor.ts
46281
46306
  var defaultCursors = [
package/dist/esm/index.js CHANGED
@@ -46065,11 +46065,18 @@ registerItem({
46065
46065
  item: Deck,
46066
46066
  defaultData: defaultDeckData
46067
46067
  });
46068
+ // src/Items/Examples/CardGame/Dice/AddDice.ts
46069
+ class AddDice extends ShapeTool {
46070
+ constructor(board, name) {
46071
+ super(board, name, Dice, { cursorName: "crosshair", fixedRatio: true });
46072
+ }
46073
+ }
46074
+
46068
46075
  // src/Items/Examples/CardGame/Dice/Dice.ts
46069
46076
  var TIMEOUT = 3000;
46070
46077
  var defaultDiceData = {
46071
46078
  itemType: "Dice",
46072
- backgroundColor: "#000207",
46079
+ backgroundColor: "#FFFFFF",
46073
46080
  backgroundOpacity: 1,
46074
46081
  borderColor: "#000207",
46075
46082
  borderOpacity: 1,
@@ -46084,9 +46091,10 @@ class Dice extends BaseItem {
46084
46091
  path;
46085
46092
  subject = new Subject;
46086
46093
  borderWidth = 1;
46087
- isRotating = false;
46088
46094
  value = 1;
46089
46095
  range = { min: 1, max: 6 };
46096
+ animationFrameId;
46097
+ drawingContext = null;
46090
46098
  constructor(board, id = "") {
46091
46099
  super(board, id, defaultDiceData);
46092
46100
  this.transformPath();
@@ -46105,11 +46113,12 @@ class Dice extends BaseItem {
46105
46113
  this.path.setBorderWidth(this.borderWidth);
46106
46114
  }
46107
46115
  render(context) {
46116
+ this.drawingContext = context;
46108
46117
  if (this.transformationRenderBlock) {
46109
46118
  return;
46110
46119
  }
46111
46120
  context.ctx.save();
46112
- if (this.isRotating) {
46121
+ if (this.animationFrameId) {
46113
46122
  const now = Date.now();
46114
46123
  const angle = now % 1000 / 1000 * 2 * Math.PI;
46115
46124
  const mbr2 = this.getMbr();
@@ -46196,15 +46205,6 @@ class Dice extends BaseItem {
46196
46205
  prevData: { borderColor: this.borderColor }
46197
46206
  });
46198
46207
  }
46199
- setIsRotating(isRotating) {
46200
- this.emit({
46201
- class: "Dice",
46202
- method: "setIsRotating",
46203
- item: [this.getId()],
46204
- newData: { isRotating },
46205
- prevData: { isRotating: false }
46206
- });
46207
- }
46208
46208
  setValuesRange(range) {
46209
46209
  this.emit({
46210
46210
  class: "Dice",
@@ -46223,11 +46223,19 @@ class Dice extends BaseItem {
46223
46223
  prevData: { value: this.value }
46224
46224
  });
46225
46225
  }
46226
+ setIsRotating(isRotating) {
46227
+ this.emit({
46228
+ class: "Dice",
46229
+ method: "setIsRotating",
46230
+ item: [this.getId()],
46231
+ newData: { isRotating },
46232
+ prevData: { isRotating: false }
46233
+ });
46234
+ }
46226
46235
  throwDice() {
46227
46236
  this.setIsRotating(true);
46228
46237
  setTimeout(() => {
46229
46238
  this.setValue(Math.ceil(Math.random() * (this.range.max - this.range.min)) + this.range.min);
46230
- this.isRotating = false;
46231
46239
  }, TIMEOUT);
46232
46240
  }
46233
46241
  apply(op) {
@@ -46245,16 +46253,15 @@ class Dice extends BaseItem {
46245
46253
  this.applyBorderColor(op.newData.borderColor);
46246
46254
  break;
46247
46255
  case "setIsRotating":
46248
- this.isRotating = op.newData.isRotating;
46249
46256
  if (op.newData.isRotating) {
46257
+ this.startRotation();
46250
46258
  setTimeout(() => {
46251
- this.isRotating = false;
46259
+ this.stopRotation();
46252
46260
  }, TIMEOUT);
46253
46261
  }
46254
46262
  break;
46255
46263
  case "changeValue":
46256
46264
  this.value = op.newData.value;
46257
- this.isRotating = false;
46258
46265
  break;
46259
46266
  case "changeValuesRange":
46260
46267
  this.range = op.newData;
@@ -46264,11 +46271,29 @@ class Dice extends BaseItem {
46264
46271
  }
46265
46272
  this.subject.publish(this);
46266
46273
  }
46274
+ startRotation() {
46275
+ if (!this.animationFrameId) {
46276
+ const animate = () => {
46277
+ if (this.drawingContext) {
46278
+ this.render(this.drawingContext);
46279
+ this.animationFrameId = requestAnimationFrame(animate);
46280
+ }
46281
+ };
46282
+ this.animationFrameId = requestAnimationFrame(animate);
46283
+ }
46284
+ }
46285
+ stopRotation() {
46286
+ if (this.animationFrameId) {
46287
+ cancelAnimationFrame(this.animationFrameId);
46288
+ this.animationFrameId = undefined;
46289
+ this.drawingContext = null;
46290
+ }
46291
+ }
46267
46292
  }
46268
46293
  registerItem({
46269
46294
  item: Dice,
46270
46295
  defaultData: defaultDiceData,
46271
- toolData: { name: "AddDice", tool: ShapeTool }
46296
+ toolData: { name: "AddDice", tool: AddDice }
46272
46297
  });
46273
46298
  // src/Pointer/Cursor.ts
46274
46299
  var defaultCursors = [
package/dist/esm/node.js CHANGED
@@ -48600,11 +48600,18 @@ registerItem({
48600
48600
  item: Deck,
48601
48601
  defaultData: defaultDeckData
48602
48602
  });
48603
+ // src/Items/Examples/CardGame/Dice/AddDice.ts
48604
+ class AddDice extends ShapeTool {
48605
+ constructor(board, name) {
48606
+ super(board, name, Dice, { cursorName: "crosshair", fixedRatio: true });
48607
+ }
48608
+ }
48609
+
48603
48610
  // src/Items/Examples/CardGame/Dice/Dice.ts
48604
48611
  var TIMEOUT = 3000;
48605
48612
  var defaultDiceData = {
48606
48613
  itemType: "Dice",
48607
- backgroundColor: "#000207",
48614
+ backgroundColor: "#FFFFFF",
48608
48615
  backgroundOpacity: 1,
48609
48616
  borderColor: "#000207",
48610
48617
  borderOpacity: 1,
@@ -48619,9 +48626,10 @@ class Dice extends BaseItem {
48619
48626
  path;
48620
48627
  subject = new Subject;
48621
48628
  borderWidth = 1;
48622
- isRotating = false;
48623
48629
  value = 1;
48624
48630
  range = { min: 1, max: 6 };
48631
+ animationFrameId;
48632
+ drawingContext = null;
48625
48633
  constructor(board, id = "") {
48626
48634
  super(board, id, defaultDiceData);
48627
48635
  this.transformPath();
@@ -48640,11 +48648,12 @@ class Dice extends BaseItem {
48640
48648
  this.path.setBorderWidth(this.borderWidth);
48641
48649
  }
48642
48650
  render(context) {
48651
+ this.drawingContext = context;
48643
48652
  if (this.transformationRenderBlock) {
48644
48653
  return;
48645
48654
  }
48646
48655
  context.ctx.save();
48647
- if (this.isRotating) {
48656
+ if (this.animationFrameId) {
48648
48657
  const now = Date.now();
48649
48658
  const angle = now % 1000 / 1000 * 2 * Math.PI;
48650
48659
  const mbr2 = this.getMbr();
@@ -48731,15 +48740,6 @@ class Dice extends BaseItem {
48731
48740
  prevData: { borderColor: this.borderColor }
48732
48741
  });
48733
48742
  }
48734
- setIsRotating(isRotating) {
48735
- this.emit({
48736
- class: "Dice",
48737
- method: "setIsRotating",
48738
- item: [this.getId()],
48739
- newData: { isRotating },
48740
- prevData: { isRotating: false }
48741
- });
48742
- }
48743
48743
  setValuesRange(range) {
48744
48744
  this.emit({
48745
48745
  class: "Dice",
@@ -48758,11 +48758,19 @@ class Dice extends BaseItem {
48758
48758
  prevData: { value: this.value }
48759
48759
  });
48760
48760
  }
48761
+ setIsRotating(isRotating) {
48762
+ this.emit({
48763
+ class: "Dice",
48764
+ method: "setIsRotating",
48765
+ item: [this.getId()],
48766
+ newData: { isRotating },
48767
+ prevData: { isRotating: false }
48768
+ });
48769
+ }
48761
48770
  throwDice() {
48762
48771
  this.setIsRotating(true);
48763
48772
  setTimeout(() => {
48764
48773
  this.setValue(Math.ceil(Math.random() * (this.range.max - this.range.min)) + this.range.min);
48765
- this.isRotating = false;
48766
48774
  }, TIMEOUT);
48767
48775
  }
48768
48776
  apply(op) {
@@ -48780,16 +48788,15 @@ class Dice extends BaseItem {
48780
48788
  this.applyBorderColor(op.newData.borderColor);
48781
48789
  break;
48782
48790
  case "setIsRotating":
48783
- this.isRotating = op.newData.isRotating;
48784
48791
  if (op.newData.isRotating) {
48792
+ this.startRotation();
48785
48793
  setTimeout(() => {
48786
- this.isRotating = false;
48794
+ this.stopRotation();
48787
48795
  }, TIMEOUT);
48788
48796
  }
48789
48797
  break;
48790
48798
  case "changeValue":
48791
48799
  this.value = op.newData.value;
48792
- this.isRotating = false;
48793
48800
  break;
48794
48801
  case "changeValuesRange":
48795
48802
  this.range = op.newData;
@@ -48799,11 +48806,29 @@ class Dice extends BaseItem {
48799
48806
  }
48800
48807
  this.subject.publish(this);
48801
48808
  }
48809
+ startRotation() {
48810
+ if (!this.animationFrameId) {
48811
+ const animate = () => {
48812
+ if (this.drawingContext) {
48813
+ this.render(this.drawingContext);
48814
+ this.animationFrameId = requestAnimationFrame(animate);
48815
+ }
48816
+ };
48817
+ this.animationFrameId = requestAnimationFrame(animate);
48818
+ }
48819
+ }
48820
+ stopRotation() {
48821
+ if (this.animationFrameId) {
48822
+ cancelAnimationFrame(this.animationFrameId);
48823
+ this.animationFrameId = undefined;
48824
+ this.drawingContext = null;
48825
+ }
48826
+ }
48802
48827
  }
48803
48828
  registerItem({
48804
48829
  item: Dice,
48805
48830
  defaultData: defaultDiceData,
48806
- toolData: { name: "AddDice", tool: ShapeTool }
48831
+ toolData: { name: "AddDice", tool: AddDice }
48807
48832
  });
48808
48833
  // src/Pointer/Cursor.ts
48809
48834
  var defaultCursors = [
@@ -0,0 +1,5 @@
1
+ import { Board } from "Board";
2
+ import { ShapeTool } from "Tools/CustomTool";
3
+ export declare class AddDice extends ShapeTool {
4
+ constructor(board: Board, name: string);
5
+ }
@@ -11,12 +11,13 @@ export declare class Dice extends BaseItem {
11
11
  private path;
12
12
  readonly subject: Subject<Dice>;
13
13
  private borderWidth;
14
- isRotating: boolean;
15
14
  value: number;
16
15
  range: {
17
16
  min: number;
18
17
  max: number;
19
18
  };
19
+ private animationFrameId?;
20
+ drawingContext: DrawingContext | null;
20
21
  constructor(board: Board, id?: string);
21
22
  private transformPath;
22
23
  render(context: DrawingContext): void;
@@ -31,12 +32,14 @@ export declare class Dice extends BaseItem {
31
32
  setBorderWidth(borderWidth: BorderWidth): void;
32
33
  private applyBorderColor;
33
34
  setBorderColor(borderColor: string): void;
34
- setIsRotating(isRotating: boolean): void;
35
35
  setValuesRange(range: {
36
36
  min: number;
37
37
  max: number;
38
38
  }): void;
39
39
  setValue(value: number): void;
40
+ setIsRotating(isRotating: boolean): void;
40
41
  throwDice(): void;
41
42
  apply(op: DiceOperation): void;
43
+ startRotation(): void;
44
+ stopRotation(): void;
42
45
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "microboard-temp",
3
- "version": "0.4.16",
3
+ "version": "0.4.18",
4
4
  "description": "A flexible interactive whiteboard library",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",