microboard-temp 0.4.15 → 0.4.17

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.
@@ -744,6 +744,7 @@ __export(exports_browser, {
744
744
  EditorContainer: () => EditorContainer,
745
745
  DrawingContext: () => DrawingContext,
746
746
  Drawing: () => Drawing,
747
+ Dice: () => Dice,
747
748
  DefaultTransformationData: () => DefaultTransformationData,
748
749
  DefaultShapeData: () => DefaultShapeData,
749
750
  Deck: () => Deck,
@@ -46221,6 +46222,218 @@ registerItem({
46221
46222
  item: Deck,
46222
46223
  defaultData: defaultDeckData
46223
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
+
46232
+ // src/Items/Examples/CardGame/Dice/Dice.ts
46233
+ var TIMEOUT = 3000;
46234
+ var defaultDiceData = {
46235
+ itemType: "Dice",
46236
+ backgroundColor: "#000207",
46237
+ backgroundOpacity: 1,
46238
+ borderColor: "#000207",
46239
+ borderOpacity: 1,
46240
+ borderStyle: "solid",
46241
+ borderWidth: 1,
46242
+ value: 1,
46243
+ range: { min: 1, max: 6 }
46244
+ };
46245
+
46246
+ class Dice extends BaseItem {
46247
+ itemType = "Dice";
46248
+ path;
46249
+ subject = new Subject;
46250
+ borderWidth = 1;
46251
+ isRotating = false;
46252
+ value = 1;
46253
+ range = { min: 1, max: 6 };
46254
+ constructor(board, id = "") {
46255
+ super(board, id, defaultDiceData);
46256
+ this.transformPath();
46257
+ this.transformation.subject.subscribe(() => {
46258
+ this.transformPath();
46259
+ this.updateMbr();
46260
+ this.subject.publish(this);
46261
+ });
46262
+ this.updateMbr();
46263
+ }
46264
+ transformPath() {
46265
+ this.path = createRoundedRectanglePath(this).copy();
46266
+ this.path.transform(this.transformation.matrix);
46267
+ this.path.setBackgroundColor(this.backgroundColor);
46268
+ this.path.setBorderColor(this.borderColor);
46269
+ this.path.setBorderWidth(this.borderWidth);
46270
+ }
46271
+ render(context) {
46272
+ if (this.transformationRenderBlock) {
46273
+ return;
46274
+ }
46275
+ context.ctx.save();
46276
+ if (this.isRotating) {
46277
+ const now = Date.now();
46278
+ const angle = now % 1000 / 1000 * 2 * Math.PI;
46279
+ const mbr2 = this.getMbr();
46280
+ const centerX2 = (mbr2.left + mbr2.right) / 2;
46281
+ const centerY2 = (mbr2.top + mbr2.bottom) / 2;
46282
+ context.ctx.translate(centerX2, centerY2);
46283
+ context.ctx.rotate(angle);
46284
+ context.ctx.translate(-centerX2, -centerY2);
46285
+ }
46286
+ this.path.render(context);
46287
+ const mbr = this.getMbr();
46288
+ const centerX = (mbr.left + mbr.right) / 2;
46289
+ const centerY = (mbr.top + mbr.bottom) / 2;
46290
+ context.ctx.fillStyle = "black";
46291
+ context.ctx.font = `bold ${this.getHeight() / 3}px sans-serif`;
46292
+ context.ctx.textAlign = "center";
46293
+ context.ctx.textBaseline = "middle";
46294
+ context.ctx.fillText(String(this.value), centerX, centerY);
46295
+ if (this.getLinkTo()) {
46296
+ const { top, right } = this.getMbr();
46297
+ this.linkTo.render(context, top, right, this.board.camera.getScale());
46298
+ }
46299
+ context.ctx.restore();
46300
+ }
46301
+ updateMbr() {
46302
+ const { left, top, right, bottom } = this.path.getMbr();
46303
+ this.left = left;
46304
+ this.right = right;
46305
+ this.top = top;
46306
+ this.bottom = bottom;
46307
+ }
46308
+ getPath() {
46309
+ return this.path.copy();
46310
+ }
46311
+ renderHTML(documentFactory) {
46312
+ const div = documentFactory.createElement("dice-item");
46313
+ return div;
46314
+ }
46315
+ deserialize(data) {
46316
+ super.deserialize(data);
46317
+ this.transformPath();
46318
+ this.subject.publish(this);
46319
+ return this;
46320
+ }
46321
+ isClosed() {
46322
+ return true;
46323
+ }
46324
+ applyBackgroundColor(backgroundColor) {
46325
+ this.backgroundColor = backgroundColor;
46326
+ this.path.setBackgroundColor(backgroundColor);
46327
+ }
46328
+ setBackgroundColor(backgroundColor) {
46329
+ this.emit({
46330
+ class: "Dice",
46331
+ method: "setBackgroundColor",
46332
+ item: [this.getId()],
46333
+ newData: { backgroundColor },
46334
+ prevData: { backgroundColor: this.backgroundColor }
46335
+ });
46336
+ }
46337
+ applyBorderWidth(borderWidth) {
46338
+ this.borderWidth = borderWidth;
46339
+ this.path.setBorderWidth(borderWidth);
46340
+ }
46341
+ setBorderWidth(borderWidth) {
46342
+ this.emit({
46343
+ class: "Dice",
46344
+ method: "setBorderWidth",
46345
+ item: [this.getId()],
46346
+ newData: { borderWidth },
46347
+ prevData: { borderWidth: this.borderWidth }
46348
+ });
46349
+ }
46350
+ applyBorderColor(borderColor) {
46351
+ this.borderColor = borderColor;
46352
+ this.path.setBorderColor(borderColor);
46353
+ }
46354
+ setBorderColor(borderColor) {
46355
+ this.emit({
46356
+ class: "Dice",
46357
+ method: "setBorderColor",
46358
+ item: [this.getId()],
46359
+ newData: { borderColor },
46360
+ prevData: { borderColor: this.borderColor }
46361
+ });
46362
+ }
46363
+ setIsRotating(isRotating) {
46364
+ this.emit({
46365
+ class: "Dice",
46366
+ method: "setIsRotating",
46367
+ item: [this.getId()],
46368
+ newData: { isRotating },
46369
+ prevData: { isRotating: false }
46370
+ });
46371
+ }
46372
+ setValuesRange(range) {
46373
+ this.emit({
46374
+ class: "Dice",
46375
+ method: "changeValuesRange",
46376
+ item: [this.getId()],
46377
+ newData: range,
46378
+ prevData: this.range
46379
+ });
46380
+ }
46381
+ setValue(value) {
46382
+ this.emit({
46383
+ class: "Dice",
46384
+ method: "changeValue",
46385
+ item: [this.getId()],
46386
+ newData: { value },
46387
+ prevData: { value: this.value }
46388
+ });
46389
+ }
46390
+ throwDice() {
46391
+ this.setIsRotating(true);
46392
+ setTimeout(() => {
46393
+ this.setValue(Math.ceil(Math.random() * (this.range.max - this.range.min)) + this.range.min);
46394
+ this.isRotating = false;
46395
+ }, TIMEOUT);
46396
+ }
46397
+ apply(op) {
46398
+ super.apply(op);
46399
+ switch (op.class) {
46400
+ case "Dice":
46401
+ switch (op.method) {
46402
+ case "setBorderWidth":
46403
+ this.applyBorderWidth(op.newData.borderWidth);
46404
+ break;
46405
+ case "setBackgroundColor":
46406
+ this.applyBackgroundColor(op.newData.backgroundColor);
46407
+ break;
46408
+ case "setBorderColor":
46409
+ this.applyBorderColor(op.newData.borderColor);
46410
+ break;
46411
+ case "setIsRotating":
46412
+ this.isRotating = op.newData.isRotating;
46413
+ if (op.newData.isRotating) {
46414
+ setTimeout(() => {
46415
+ this.isRotating = false;
46416
+ }, TIMEOUT);
46417
+ }
46418
+ break;
46419
+ case "changeValue":
46420
+ this.value = op.newData.value;
46421
+ this.isRotating = false;
46422
+ break;
46423
+ case "changeValuesRange":
46424
+ this.range = op.newData;
46425
+ break;
46426
+ }
46427
+ break;
46428
+ }
46429
+ this.subject.publish(this);
46430
+ }
46431
+ }
46432
+ registerItem({
46433
+ item: Dice,
46434
+ defaultData: defaultDiceData,
46435
+ toolData: { name: "AddDice", tool: AddDice }
46436
+ });
46224
46437
  // src/Pointer/Cursor.ts
46225
46438
  var defaultCursors = [
46226
46439
  "default",
package/dist/cjs/index.js CHANGED
@@ -744,6 +744,7 @@ __export(exports_src, {
744
744
  EditorContainer: () => EditorContainer,
745
745
  DrawingContext: () => DrawingContext,
746
746
  Drawing: () => Drawing,
747
+ Dice: () => Dice,
747
748
  DefaultTransformationData: () => DefaultTransformationData,
748
749
  DefaultShapeData: () => DefaultShapeData,
749
750
  Deck: () => Deck,
@@ -46221,6 +46222,218 @@ registerItem({
46221
46222
  item: Deck,
46222
46223
  defaultData: defaultDeckData
46223
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
+
46232
+ // src/Items/Examples/CardGame/Dice/Dice.ts
46233
+ var TIMEOUT = 3000;
46234
+ var defaultDiceData = {
46235
+ itemType: "Dice",
46236
+ backgroundColor: "#000207",
46237
+ backgroundOpacity: 1,
46238
+ borderColor: "#000207",
46239
+ borderOpacity: 1,
46240
+ borderStyle: "solid",
46241
+ borderWidth: 1,
46242
+ value: 1,
46243
+ range: { min: 1, max: 6 }
46244
+ };
46245
+
46246
+ class Dice extends BaseItem {
46247
+ itemType = "Dice";
46248
+ path;
46249
+ subject = new Subject;
46250
+ borderWidth = 1;
46251
+ isRotating = false;
46252
+ value = 1;
46253
+ range = { min: 1, max: 6 };
46254
+ constructor(board, id = "") {
46255
+ super(board, id, defaultDiceData);
46256
+ this.transformPath();
46257
+ this.transformation.subject.subscribe(() => {
46258
+ this.transformPath();
46259
+ this.updateMbr();
46260
+ this.subject.publish(this);
46261
+ });
46262
+ this.updateMbr();
46263
+ }
46264
+ transformPath() {
46265
+ this.path = createRoundedRectanglePath(this).copy();
46266
+ this.path.transform(this.transformation.matrix);
46267
+ this.path.setBackgroundColor(this.backgroundColor);
46268
+ this.path.setBorderColor(this.borderColor);
46269
+ this.path.setBorderWidth(this.borderWidth);
46270
+ }
46271
+ render(context) {
46272
+ if (this.transformationRenderBlock) {
46273
+ return;
46274
+ }
46275
+ context.ctx.save();
46276
+ if (this.isRotating) {
46277
+ const now = Date.now();
46278
+ const angle = now % 1000 / 1000 * 2 * Math.PI;
46279
+ const mbr2 = this.getMbr();
46280
+ const centerX2 = (mbr2.left + mbr2.right) / 2;
46281
+ const centerY2 = (mbr2.top + mbr2.bottom) / 2;
46282
+ context.ctx.translate(centerX2, centerY2);
46283
+ context.ctx.rotate(angle);
46284
+ context.ctx.translate(-centerX2, -centerY2);
46285
+ }
46286
+ this.path.render(context);
46287
+ const mbr = this.getMbr();
46288
+ const centerX = (mbr.left + mbr.right) / 2;
46289
+ const centerY = (mbr.top + mbr.bottom) / 2;
46290
+ context.ctx.fillStyle = "black";
46291
+ context.ctx.font = `bold ${this.getHeight() / 3}px sans-serif`;
46292
+ context.ctx.textAlign = "center";
46293
+ context.ctx.textBaseline = "middle";
46294
+ context.ctx.fillText(String(this.value), centerX, centerY);
46295
+ if (this.getLinkTo()) {
46296
+ const { top, right } = this.getMbr();
46297
+ this.linkTo.render(context, top, right, this.board.camera.getScale());
46298
+ }
46299
+ context.ctx.restore();
46300
+ }
46301
+ updateMbr() {
46302
+ const { left, top, right, bottom } = this.path.getMbr();
46303
+ this.left = left;
46304
+ this.right = right;
46305
+ this.top = top;
46306
+ this.bottom = bottom;
46307
+ }
46308
+ getPath() {
46309
+ return this.path.copy();
46310
+ }
46311
+ renderHTML(documentFactory) {
46312
+ const div = documentFactory.createElement("dice-item");
46313
+ return div;
46314
+ }
46315
+ deserialize(data) {
46316
+ super.deserialize(data);
46317
+ this.transformPath();
46318
+ this.subject.publish(this);
46319
+ return this;
46320
+ }
46321
+ isClosed() {
46322
+ return true;
46323
+ }
46324
+ applyBackgroundColor(backgroundColor) {
46325
+ this.backgroundColor = backgroundColor;
46326
+ this.path.setBackgroundColor(backgroundColor);
46327
+ }
46328
+ setBackgroundColor(backgroundColor) {
46329
+ this.emit({
46330
+ class: "Dice",
46331
+ method: "setBackgroundColor",
46332
+ item: [this.getId()],
46333
+ newData: { backgroundColor },
46334
+ prevData: { backgroundColor: this.backgroundColor }
46335
+ });
46336
+ }
46337
+ applyBorderWidth(borderWidth) {
46338
+ this.borderWidth = borderWidth;
46339
+ this.path.setBorderWidth(borderWidth);
46340
+ }
46341
+ setBorderWidth(borderWidth) {
46342
+ this.emit({
46343
+ class: "Dice",
46344
+ method: "setBorderWidth",
46345
+ item: [this.getId()],
46346
+ newData: { borderWidth },
46347
+ prevData: { borderWidth: this.borderWidth }
46348
+ });
46349
+ }
46350
+ applyBorderColor(borderColor) {
46351
+ this.borderColor = borderColor;
46352
+ this.path.setBorderColor(borderColor);
46353
+ }
46354
+ setBorderColor(borderColor) {
46355
+ this.emit({
46356
+ class: "Dice",
46357
+ method: "setBorderColor",
46358
+ item: [this.getId()],
46359
+ newData: { borderColor },
46360
+ prevData: { borderColor: this.borderColor }
46361
+ });
46362
+ }
46363
+ setIsRotating(isRotating) {
46364
+ this.emit({
46365
+ class: "Dice",
46366
+ method: "setIsRotating",
46367
+ item: [this.getId()],
46368
+ newData: { isRotating },
46369
+ prevData: { isRotating: false }
46370
+ });
46371
+ }
46372
+ setValuesRange(range) {
46373
+ this.emit({
46374
+ class: "Dice",
46375
+ method: "changeValuesRange",
46376
+ item: [this.getId()],
46377
+ newData: range,
46378
+ prevData: this.range
46379
+ });
46380
+ }
46381
+ setValue(value) {
46382
+ this.emit({
46383
+ class: "Dice",
46384
+ method: "changeValue",
46385
+ item: [this.getId()],
46386
+ newData: { value },
46387
+ prevData: { value: this.value }
46388
+ });
46389
+ }
46390
+ throwDice() {
46391
+ this.setIsRotating(true);
46392
+ setTimeout(() => {
46393
+ this.setValue(Math.ceil(Math.random() * (this.range.max - this.range.min)) + this.range.min);
46394
+ this.isRotating = false;
46395
+ }, TIMEOUT);
46396
+ }
46397
+ apply(op) {
46398
+ super.apply(op);
46399
+ switch (op.class) {
46400
+ case "Dice":
46401
+ switch (op.method) {
46402
+ case "setBorderWidth":
46403
+ this.applyBorderWidth(op.newData.borderWidth);
46404
+ break;
46405
+ case "setBackgroundColor":
46406
+ this.applyBackgroundColor(op.newData.backgroundColor);
46407
+ break;
46408
+ case "setBorderColor":
46409
+ this.applyBorderColor(op.newData.borderColor);
46410
+ break;
46411
+ case "setIsRotating":
46412
+ this.isRotating = op.newData.isRotating;
46413
+ if (op.newData.isRotating) {
46414
+ setTimeout(() => {
46415
+ this.isRotating = false;
46416
+ }, TIMEOUT);
46417
+ }
46418
+ break;
46419
+ case "changeValue":
46420
+ this.value = op.newData.value;
46421
+ this.isRotating = false;
46422
+ break;
46423
+ case "changeValuesRange":
46424
+ this.range = op.newData;
46425
+ break;
46426
+ }
46427
+ break;
46428
+ }
46429
+ this.subject.publish(this);
46430
+ }
46431
+ }
46432
+ registerItem({
46433
+ item: Dice,
46434
+ defaultData: defaultDiceData,
46435
+ toolData: { name: "AddDice", tool: AddDice }
46436
+ });
46224
46437
  // src/Pointer/Cursor.ts
46225
46438
  var defaultCursors = [
46226
46439
  "default",
package/dist/cjs/node.js CHANGED
@@ -1781,6 +1781,7 @@ __export(exports_node, {
1781
1781
  EditorContainer: () => EditorContainer,
1782
1782
  DrawingContext: () => DrawingContext,
1783
1783
  Drawing: () => Drawing,
1784
+ Dice: () => Dice,
1784
1785
  DefaultTransformationData: () => DefaultTransformationData,
1785
1786
  DefaultShapeData: () => DefaultShapeData,
1786
1787
  Deck: () => Deck,
@@ -48761,6 +48762,218 @@ registerItem({
48761
48762
  item: Deck,
48762
48763
  defaultData: defaultDeckData
48763
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
+
48772
+ // src/Items/Examples/CardGame/Dice/Dice.ts
48773
+ var TIMEOUT = 3000;
48774
+ var defaultDiceData = {
48775
+ itemType: "Dice",
48776
+ backgroundColor: "#000207",
48777
+ backgroundOpacity: 1,
48778
+ borderColor: "#000207",
48779
+ borderOpacity: 1,
48780
+ borderStyle: "solid",
48781
+ borderWidth: 1,
48782
+ value: 1,
48783
+ range: { min: 1, max: 6 }
48784
+ };
48785
+
48786
+ class Dice extends BaseItem {
48787
+ itemType = "Dice";
48788
+ path;
48789
+ subject = new Subject;
48790
+ borderWidth = 1;
48791
+ isRotating = false;
48792
+ value = 1;
48793
+ range = { min: 1, max: 6 };
48794
+ constructor(board, id = "") {
48795
+ super(board, id, defaultDiceData);
48796
+ this.transformPath();
48797
+ this.transformation.subject.subscribe(() => {
48798
+ this.transformPath();
48799
+ this.updateMbr();
48800
+ this.subject.publish(this);
48801
+ });
48802
+ this.updateMbr();
48803
+ }
48804
+ transformPath() {
48805
+ this.path = createRoundedRectanglePath(this).copy();
48806
+ this.path.transform(this.transformation.matrix);
48807
+ this.path.setBackgroundColor(this.backgroundColor);
48808
+ this.path.setBorderColor(this.borderColor);
48809
+ this.path.setBorderWidth(this.borderWidth);
48810
+ }
48811
+ render(context) {
48812
+ if (this.transformationRenderBlock) {
48813
+ return;
48814
+ }
48815
+ context.ctx.save();
48816
+ if (this.isRotating) {
48817
+ const now = Date.now();
48818
+ const angle = now % 1000 / 1000 * 2 * Math.PI;
48819
+ const mbr2 = this.getMbr();
48820
+ const centerX2 = (mbr2.left + mbr2.right) / 2;
48821
+ const centerY2 = (mbr2.top + mbr2.bottom) / 2;
48822
+ context.ctx.translate(centerX2, centerY2);
48823
+ context.ctx.rotate(angle);
48824
+ context.ctx.translate(-centerX2, -centerY2);
48825
+ }
48826
+ this.path.render(context);
48827
+ const mbr = this.getMbr();
48828
+ const centerX = (mbr.left + mbr.right) / 2;
48829
+ const centerY = (mbr.top + mbr.bottom) / 2;
48830
+ context.ctx.fillStyle = "black";
48831
+ context.ctx.font = `bold ${this.getHeight() / 3}px sans-serif`;
48832
+ context.ctx.textAlign = "center";
48833
+ context.ctx.textBaseline = "middle";
48834
+ context.ctx.fillText(String(this.value), centerX, centerY);
48835
+ if (this.getLinkTo()) {
48836
+ const { top, right } = this.getMbr();
48837
+ this.linkTo.render(context, top, right, this.board.camera.getScale());
48838
+ }
48839
+ context.ctx.restore();
48840
+ }
48841
+ updateMbr() {
48842
+ const { left, top, right, bottom } = this.path.getMbr();
48843
+ this.left = left;
48844
+ this.right = right;
48845
+ this.top = top;
48846
+ this.bottom = bottom;
48847
+ }
48848
+ getPath() {
48849
+ return this.path.copy();
48850
+ }
48851
+ renderHTML(documentFactory) {
48852
+ const div = documentFactory.createElement("dice-item");
48853
+ return div;
48854
+ }
48855
+ deserialize(data) {
48856
+ super.deserialize(data);
48857
+ this.transformPath();
48858
+ this.subject.publish(this);
48859
+ return this;
48860
+ }
48861
+ isClosed() {
48862
+ return true;
48863
+ }
48864
+ applyBackgroundColor(backgroundColor) {
48865
+ this.backgroundColor = backgroundColor;
48866
+ this.path.setBackgroundColor(backgroundColor);
48867
+ }
48868
+ setBackgroundColor(backgroundColor) {
48869
+ this.emit({
48870
+ class: "Dice",
48871
+ method: "setBackgroundColor",
48872
+ item: [this.getId()],
48873
+ newData: { backgroundColor },
48874
+ prevData: { backgroundColor: this.backgroundColor }
48875
+ });
48876
+ }
48877
+ applyBorderWidth(borderWidth) {
48878
+ this.borderWidth = borderWidth;
48879
+ this.path.setBorderWidth(borderWidth);
48880
+ }
48881
+ setBorderWidth(borderWidth) {
48882
+ this.emit({
48883
+ class: "Dice",
48884
+ method: "setBorderWidth",
48885
+ item: [this.getId()],
48886
+ newData: { borderWidth },
48887
+ prevData: { borderWidth: this.borderWidth }
48888
+ });
48889
+ }
48890
+ applyBorderColor(borderColor) {
48891
+ this.borderColor = borderColor;
48892
+ this.path.setBorderColor(borderColor);
48893
+ }
48894
+ setBorderColor(borderColor) {
48895
+ this.emit({
48896
+ class: "Dice",
48897
+ method: "setBorderColor",
48898
+ item: [this.getId()],
48899
+ newData: { borderColor },
48900
+ prevData: { borderColor: this.borderColor }
48901
+ });
48902
+ }
48903
+ setIsRotating(isRotating) {
48904
+ this.emit({
48905
+ class: "Dice",
48906
+ method: "setIsRotating",
48907
+ item: [this.getId()],
48908
+ newData: { isRotating },
48909
+ prevData: { isRotating: false }
48910
+ });
48911
+ }
48912
+ setValuesRange(range) {
48913
+ this.emit({
48914
+ class: "Dice",
48915
+ method: "changeValuesRange",
48916
+ item: [this.getId()],
48917
+ newData: range,
48918
+ prevData: this.range
48919
+ });
48920
+ }
48921
+ setValue(value) {
48922
+ this.emit({
48923
+ class: "Dice",
48924
+ method: "changeValue",
48925
+ item: [this.getId()],
48926
+ newData: { value },
48927
+ prevData: { value: this.value }
48928
+ });
48929
+ }
48930
+ throwDice() {
48931
+ this.setIsRotating(true);
48932
+ setTimeout(() => {
48933
+ this.setValue(Math.ceil(Math.random() * (this.range.max - this.range.min)) + this.range.min);
48934
+ this.isRotating = false;
48935
+ }, TIMEOUT);
48936
+ }
48937
+ apply(op) {
48938
+ super.apply(op);
48939
+ switch (op.class) {
48940
+ case "Dice":
48941
+ switch (op.method) {
48942
+ case "setBorderWidth":
48943
+ this.applyBorderWidth(op.newData.borderWidth);
48944
+ break;
48945
+ case "setBackgroundColor":
48946
+ this.applyBackgroundColor(op.newData.backgroundColor);
48947
+ break;
48948
+ case "setBorderColor":
48949
+ this.applyBorderColor(op.newData.borderColor);
48950
+ break;
48951
+ case "setIsRotating":
48952
+ this.isRotating = op.newData.isRotating;
48953
+ if (op.newData.isRotating) {
48954
+ setTimeout(() => {
48955
+ this.isRotating = false;
48956
+ }, TIMEOUT);
48957
+ }
48958
+ break;
48959
+ case "changeValue":
48960
+ this.value = op.newData.value;
48961
+ this.isRotating = false;
48962
+ break;
48963
+ case "changeValuesRange":
48964
+ this.range = op.newData;
48965
+ break;
48966
+ }
48967
+ break;
48968
+ }
48969
+ this.subject.publish(this);
48970
+ }
48971
+ }
48972
+ registerItem({
48973
+ item: Dice,
48974
+ defaultData: defaultDiceData,
48975
+ toolData: { name: "AddDice", tool: AddDice }
48976
+ });
48764
48977
  // src/Pointer/Cursor.ts
48765
48978
  var defaultCursors = [
48766
48979
  "default",
@@ -46072,6 +46072,218 @@ 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
+
46082
+ // src/Items/Examples/CardGame/Dice/Dice.ts
46083
+ var TIMEOUT = 3000;
46084
+ var defaultDiceData = {
46085
+ itemType: "Dice",
46086
+ backgroundColor: "#000207",
46087
+ backgroundOpacity: 1,
46088
+ borderColor: "#000207",
46089
+ borderOpacity: 1,
46090
+ borderStyle: "solid",
46091
+ borderWidth: 1,
46092
+ value: 1,
46093
+ range: { min: 1, max: 6 }
46094
+ };
46095
+
46096
+ class Dice extends BaseItem {
46097
+ itemType = "Dice";
46098
+ path;
46099
+ subject = new Subject;
46100
+ borderWidth = 1;
46101
+ isRotating = false;
46102
+ value = 1;
46103
+ range = { min: 1, max: 6 };
46104
+ constructor(board, id = "") {
46105
+ super(board, id, defaultDiceData);
46106
+ this.transformPath();
46107
+ this.transformation.subject.subscribe(() => {
46108
+ this.transformPath();
46109
+ this.updateMbr();
46110
+ this.subject.publish(this);
46111
+ });
46112
+ this.updateMbr();
46113
+ }
46114
+ transformPath() {
46115
+ this.path = createRoundedRectanglePath(this).copy();
46116
+ this.path.transform(this.transformation.matrix);
46117
+ this.path.setBackgroundColor(this.backgroundColor);
46118
+ this.path.setBorderColor(this.borderColor);
46119
+ this.path.setBorderWidth(this.borderWidth);
46120
+ }
46121
+ render(context) {
46122
+ if (this.transformationRenderBlock) {
46123
+ return;
46124
+ }
46125
+ context.ctx.save();
46126
+ if (this.isRotating) {
46127
+ const now = Date.now();
46128
+ const angle = now % 1000 / 1000 * 2 * Math.PI;
46129
+ const mbr2 = this.getMbr();
46130
+ const centerX2 = (mbr2.left + mbr2.right) / 2;
46131
+ const centerY2 = (mbr2.top + mbr2.bottom) / 2;
46132
+ context.ctx.translate(centerX2, centerY2);
46133
+ context.ctx.rotate(angle);
46134
+ context.ctx.translate(-centerX2, -centerY2);
46135
+ }
46136
+ this.path.render(context);
46137
+ const mbr = this.getMbr();
46138
+ const centerX = (mbr.left + mbr.right) / 2;
46139
+ const centerY = (mbr.top + mbr.bottom) / 2;
46140
+ context.ctx.fillStyle = "black";
46141
+ context.ctx.font = `bold ${this.getHeight() / 3}px sans-serif`;
46142
+ context.ctx.textAlign = "center";
46143
+ context.ctx.textBaseline = "middle";
46144
+ context.ctx.fillText(String(this.value), centerX, centerY);
46145
+ if (this.getLinkTo()) {
46146
+ const { top, right } = this.getMbr();
46147
+ this.linkTo.render(context, top, right, this.board.camera.getScale());
46148
+ }
46149
+ context.ctx.restore();
46150
+ }
46151
+ updateMbr() {
46152
+ const { left, top, right, bottom } = this.path.getMbr();
46153
+ this.left = left;
46154
+ this.right = right;
46155
+ this.top = top;
46156
+ this.bottom = bottom;
46157
+ }
46158
+ getPath() {
46159
+ return this.path.copy();
46160
+ }
46161
+ renderHTML(documentFactory) {
46162
+ const div = documentFactory.createElement("dice-item");
46163
+ return div;
46164
+ }
46165
+ deserialize(data) {
46166
+ super.deserialize(data);
46167
+ this.transformPath();
46168
+ this.subject.publish(this);
46169
+ return this;
46170
+ }
46171
+ isClosed() {
46172
+ return true;
46173
+ }
46174
+ applyBackgroundColor(backgroundColor) {
46175
+ this.backgroundColor = backgroundColor;
46176
+ this.path.setBackgroundColor(backgroundColor);
46177
+ }
46178
+ setBackgroundColor(backgroundColor) {
46179
+ this.emit({
46180
+ class: "Dice",
46181
+ method: "setBackgroundColor",
46182
+ item: [this.getId()],
46183
+ newData: { backgroundColor },
46184
+ prevData: { backgroundColor: this.backgroundColor }
46185
+ });
46186
+ }
46187
+ applyBorderWidth(borderWidth) {
46188
+ this.borderWidth = borderWidth;
46189
+ this.path.setBorderWidth(borderWidth);
46190
+ }
46191
+ setBorderWidth(borderWidth) {
46192
+ this.emit({
46193
+ class: "Dice",
46194
+ method: "setBorderWidth",
46195
+ item: [this.getId()],
46196
+ newData: { borderWidth },
46197
+ prevData: { borderWidth: this.borderWidth }
46198
+ });
46199
+ }
46200
+ applyBorderColor(borderColor) {
46201
+ this.borderColor = borderColor;
46202
+ this.path.setBorderColor(borderColor);
46203
+ }
46204
+ setBorderColor(borderColor) {
46205
+ this.emit({
46206
+ class: "Dice",
46207
+ method: "setBorderColor",
46208
+ item: [this.getId()],
46209
+ newData: { borderColor },
46210
+ prevData: { borderColor: this.borderColor }
46211
+ });
46212
+ }
46213
+ setIsRotating(isRotating) {
46214
+ this.emit({
46215
+ class: "Dice",
46216
+ method: "setIsRotating",
46217
+ item: [this.getId()],
46218
+ newData: { isRotating },
46219
+ prevData: { isRotating: false }
46220
+ });
46221
+ }
46222
+ setValuesRange(range) {
46223
+ this.emit({
46224
+ class: "Dice",
46225
+ method: "changeValuesRange",
46226
+ item: [this.getId()],
46227
+ newData: range,
46228
+ prevData: this.range
46229
+ });
46230
+ }
46231
+ setValue(value) {
46232
+ this.emit({
46233
+ class: "Dice",
46234
+ method: "changeValue",
46235
+ item: [this.getId()],
46236
+ newData: { value },
46237
+ prevData: { value: this.value }
46238
+ });
46239
+ }
46240
+ throwDice() {
46241
+ this.setIsRotating(true);
46242
+ setTimeout(() => {
46243
+ this.setValue(Math.ceil(Math.random() * (this.range.max - this.range.min)) + this.range.min);
46244
+ this.isRotating = false;
46245
+ }, TIMEOUT);
46246
+ }
46247
+ apply(op) {
46248
+ super.apply(op);
46249
+ switch (op.class) {
46250
+ case "Dice":
46251
+ switch (op.method) {
46252
+ case "setBorderWidth":
46253
+ this.applyBorderWidth(op.newData.borderWidth);
46254
+ break;
46255
+ case "setBackgroundColor":
46256
+ this.applyBackgroundColor(op.newData.backgroundColor);
46257
+ break;
46258
+ case "setBorderColor":
46259
+ this.applyBorderColor(op.newData.borderColor);
46260
+ break;
46261
+ case "setIsRotating":
46262
+ this.isRotating = op.newData.isRotating;
46263
+ if (op.newData.isRotating) {
46264
+ setTimeout(() => {
46265
+ this.isRotating = false;
46266
+ }, TIMEOUT);
46267
+ }
46268
+ break;
46269
+ case "changeValue":
46270
+ this.value = op.newData.value;
46271
+ this.isRotating = false;
46272
+ break;
46273
+ case "changeValuesRange":
46274
+ this.range = op.newData;
46275
+ break;
46276
+ }
46277
+ break;
46278
+ }
46279
+ this.subject.publish(this);
46280
+ }
46281
+ }
46282
+ registerItem({
46283
+ item: Dice,
46284
+ defaultData: defaultDiceData,
46285
+ toolData: { name: "AddDice", tool: AddDice }
46286
+ });
46075
46287
  // src/Pointer/Cursor.ts
46076
46288
  var defaultCursors = [
46077
46289
  "default",
@@ -56181,6 +56393,7 @@ export {
56181
56393
  EditorContainer,
56182
56394
  DrawingContext,
56183
56395
  Drawing,
56396
+ Dice,
56184
56397
  DefaultTransformationData,
56185
56398
  DefaultShapeData,
56186
56399
  Deck,
package/dist/esm/index.js CHANGED
@@ -46065,6 +46065,218 @@ 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
+
46075
+ // src/Items/Examples/CardGame/Dice/Dice.ts
46076
+ var TIMEOUT = 3000;
46077
+ var defaultDiceData = {
46078
+ itemType: "Dice",
46079
+ backgroundColor: "#000207",
46080
+ backgroundOpacity: 1,
46081
+ borderColor: "#000207",
46082
+ borderOpacity: 1,
46083
+ borderStyle: "solid",
46084
+ borderWidth: 1,
46085
+ value: 1,
46086
+ range: { min: 1, max: 6 }
46087
+ };
46088
+
46089
+ class Dice extends BaseItem {
46090
+ itemType = "Dice";
46091
+ path;
46092
+ subject = new Subject;
46093
+ borderWidth = 1;
46094
+ isRotating = false;
46095
+ value = 1;
46096
+ range = { min: 1, max: 6 };
46097
+ constructor(board, id = "") {
46098
+ super(board, id, defaultDiceData);
46099
+ this.transformPath();
46100
+ this.transformation.subject.subscribe(() => {
46101
+ this.transformPath();
46102
+ this.updateMbr();
46103
+ this.subject.publish(this);
46104
+ });
46105
+ this.updateMbr();
46106
+ }
46107
+ transformPath() {
46108
+ this.path = createRoundedRectanglePath(this).copy();
46109
+ this.path.transform(this.transformation.matrix);
46110
+ this.path.setBackgroundColor(this.backgroundColor);
46111
+ this.path.setBorderColor(this.borderColor);
46112
+ this.path.setBorderWidth(this.borderWidth);
46113
+ }
46114
+ render(context) {
46115
+ if (this.transformationRenderBlock) {
46116
+ return;
46117
+ }
46118
+ context.ctx.save();
46119
+ if (this.isRotating) {
46120
+ const now = Date.now();
46121
+ const angle = now % 1000 / 1000 * 2 * Math.PI;
46122
+ const mbr2 = this.getMbr();
46123
+ const centerX2 = (mbr2.left + mbr2.right) / 2;
46124
+ const centerY2 = (mbr2.top + mbr2.bottom) / 2;
46125
+ context.ctx.translate(centerX2, centerY2);
46126
+ context.ctx.rotate(angle);
46127
+ context.ctx.translate(-centerX2, -centerY2);
46128
+ }
46129
+ this.path.render(context);
46130
+ const mbr = this.getMbr();
46131
+ const centerX = (mbr.left + mbr.right) / 2;
46132
+ const centerY = (mbr.top + mbr.bottom) / 2;
46133
+ context.ctx.fillStyle = "black";
46134
+ context.ctx.font = `bold ${this.getHeight() / 3}px sans-serif`;
46135
+ context.ctx.textAlign = "center";
46136
+ context.ctx.textBaseline = "middle";
46137
+ context.ctx.fillText(String(this.value), centerX, centerY);
46138
+ if (this.getLinkTo()) {
46139
+ const { top, right } = this.getMbr();
46140
+ this.linkTo.render(context, top, right, this.board.camera.getScale());
46141
+ }
46142
+ context.ctx.restore();
46143
+ }
46144
+ updateMbr() {
46145
+ const { left, top, right, bottom } = this.path.getMbr();
46146
+ this.left = left;
46147
+ this.right = right;
46148
+ this.top = top;
46149
+ this.bottom = bottom;
46150
+ }
46151
+ getPath() {
46152
+ return this.path.copy();
46153
+ }
46154
+ renderHTML(documentFactory) {
46155
+ const div = documentFactory.createElement("dice-item");
46156
+ return div;
46157
+ }
46158
+ deserialize(data) {
46159
+ super.deserialize(data);
46160
+ this.transformPath();
46161
+ this.subject.publish(this);
46162
+ return this;
46163
+ }
46164
+ isClosed() {
46165
+ return true;
46166
+ }
46167
+ applyBackgroundColor(backgroundColor) {
46168
+ this.backgroundColor = backgroundColor;
46169
+ this.path.setBackgroundColor(backgroundColor);
46170
+ }
46171
+ setBackgroundColor(backgroundColor) {
46172
+ this.emit({
46173
+ class: "Dice",
46174
+ method: "setBackgroundColor",
46175
+ item: [this.getId()],
46176
+ newData: { backgroundColor },
46177
+ prevData: { backgroundColor: this.backgroundColor }
46178
+ });
46179
+ }
46180
+ applyBorderWidth(borderWidth) {
46181
+ this.borderWidth = borderWidth;
46182
+ this.path.setBorderWidth(borderWidth);
46183
+ }
46184
+ setBorderWidth(borderWidth) {
46185
+ this.emit({
46186
+ class: "Dice",
46187
+ method: "setBorderWidth",
46188
+ item: [this.getId()],
46189
+ newData: { borderWidth },
46190
+ prevData: { borderWidth: this.borderWidth }
46191
+ });
46192
+ }
46193
+ applyBorderColor(borderColor) {
46194
+ this.borderColor = borderColor;
46195
+ this.path.setBorderColor(borderColor);
46196
+ }
46197
+ setBorderColor(borderColor) {
46198
+ this.emit({
46199
+ class: "Dice",
46200
+ method: "setBorderColor",
46201
+ item: [this.getId()],
46202
+ newData: { borderColor },
46203
+ prevData: { borderColor: this.borderColor }
46204
+ });
46205
+ }
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
+ setValuesRange(range) {
46216
+ this.emit({
46217
+ class: "Dice",
46218
+ method: "changeValuesRange",
46219
+ item: [this.getId()],
46220
+ newData: range,
46221
+ prevData: this.range
46222
+ });
46223
+ }
46224
+ setValue(value) {
46225
+ this.emit({
46226
+ class: "Dice",
46227
+ method: "changeValue",
46228
+ item: [this.getId()],
46229
+ newData: { value },
46230
+ prevData: { value: this.value }
46231
+ });
46232
+ }
46233
+ throwDice() {
46234
+ this.setIsRotating(true);
46235
+ setTimeout(() => {
46236
+ this.setValue(Math.ceil(Math.random() * (this.range.max - this.range.min)) + this.range.min);
46237
+ this.isRotating = false;
46238
+ }, TIMEOUT);
46239
+ }
46240
+ apply(op) {
46241
+ super.apply(op);
46242
+ switch (op.class) {
46243
+ case "Dice":
46244
+ switch (op.method) {
46245
+ case "setBorderWidth":
46246
+ this.applyBorderWidth(op.newData.borderWidth);
46247
+ break;
46248
+ case "setBackgroundColor":
46249
+ this.applyBackgroundColor(op.newData.backgroundColor);
46250
+ break;
46251
+ case "setBorderColor":
46252
+ this.applyBorderColor(op.newData.borderColor);
46253
+ break;
46254
+ case "setIsRotating":
46255
+ this.isRotating = op.newData.isRotating;
46256
+ if (op.newData.isRotating) {
46257
+ setTimeout(() => {
46258
+ this.isRotating = false;
46259
+ }, TIMEOUT);
46260
+ }
46261
+ break;
46262
+ case "changeValue":
46263
+ this.value = op.newData.value;
46264
+ this.isRotating = false;
46265
+ break;
46266
+ case "changeValuesRange":
46267
+ this.range = op.newData;
46268
+ break;
46269
+ }
46270
+ break;
46271
+ }
46272
+ this.subject.publish(this);
46273
+ }
46274
+ }
46275
+ registerItem({
46276
+ item: Dice,
46277
+ defaultData: defaultDiceData,
46278
+ toolData: { name: "AddDice", tool: AddDice }
46279
+ });
46068
46280
  // src/Pointer/Cursor.ts
46069
46281
  var defaultCursors = [
46070
46282
  "default",
@@ -56079,6 +56291,7 @@ export {
56079
56291
  EditorContainer,
56080
56292
  DrawingContext,
56081
56293
  Drawing,
56294
+ Dice,
56082
56295
  DefaultTransformationData,
56083
56296
  DefaultShapeData,
56084
56297
  Deck,
package/dist/esm/node.js CHANGED
@@ -48600,6 +48600,218 @@ 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
+
48610
+ // src/Items/Examples/CardGame/Dice/Dice.ts
48611
+ var TIMEOUT = 3000;
48612
+ var defaultDiceData = {
48613
+ itemType: "Dice",
48614
+ backgroundColor: "#000207",
48615
+ backgroundOpacity: 1,
48616
+ borderColor: "#000207",
48617
+ borderOpacity: 1,
48618
+ borderStyle: "solid",
48619
+ borderWidth: 1,
48620
+ value: 1,
48621
+ range: { min: 1, max: 6 }
48622
+ };
48623
+
48624
+ class Dice extends BaseItem {
48625
+ itemType = "Dice";
48626
+ path;
48627
+ subject = new Subject;
48628
+ borderWidth = 1;
48629
+ isRotating = false;
48630
+ value = 1;
48631
+ range = { min: 1, max: 6 };
48632
+ constructor(board, id = "") {
48633
+ super(board, id, defaultDiceData);
48634
+ this.transformPath();
48635
+ this.transformation.subject.subscribe(() => {
48636
+ this.transformPath();
48637
+ this.updateMbr();
48638
+ this.subject.publish(this);
48639
+ });
48640
+ this.updateMbr();
48641
+ }
48642
+ transformPath() {
48643
+ this.path = createRoundedRectanglePath(this).copy();
48644
+ this.path.transform(this.transformation.matrix);
48645
+ this.path.setBackgroundColor(this.backgroundColor);
48646
+ this.path.setBorderColor(this.borderColor);
48647
+ this.path.setBorderWidth(this.borderWidth);
48648
+ }
48649
+ render(context) {
48650
+ if (this.transformationRenderBlock) {
48651
+ return;
48652
+ }
48653
+ context.ctx.save();
48654
+ if (this.isRotating) {
48655
+ const now = Date.now();
48656
+ const angle = now % 1000 / 1000 * 2 * Math.PI;
48657
+ const mbr2 = this.getMbr();
48658
+ const centerX2 = (mbr2.left + mbr2.right) / 2;
48659
+ const centerY2 = (mbr2.top + mbr2.bottom) / 2;
48660
+ context.ctx.translate(centerX2, centerY2);
48661
+ context.ctx.rotate(angle);
48662
+ context.ctx.translate(-centerX2, -centerY2);
48663
+ }
48664
+ this.path.render(context);
48665
+ const mbr = this.getMbr();
48666
+ const centerX = (mbr.left + mbr.right) / 2;
48667
+ const centerY = (mbr.top + mbr.bottom) / 2;
48668
+ context.ctx.fillStyle = "black";
48669
+ context.ctx.font = `bold ${this.getHeight() / 3}px sans-serif`;
48670
+ context.ctx.textAlign = "center";
48671
+ context.ctx.textBaseline = "middle";
48672
+ context.ctx.fillText(String(this.value), centerX, centerY);
48673
+ if (this.getLinkTo()) {
48674
+ const { top, right } = this.getMbr();
48675
+ this.linkTo.render(context, top, right, this.board.camera.getScale());
48676
+ }
48677
+ context.ctx.restore();
48678
+ }
48679
+ updateMbr() {
48680
+ const { left, top, right, bottom } = this.path.getMbr();
48681
+ this.left = left;
48682
+ this.right = right;
48683
+ this.top = top;
48684
+ this.bottom = bottom;
48685
+ }
48686
+ getPath() {
48687
+ return this.path.copy();
48688
+ }
48689
+ renderHTML(documentFactory) {
48690
+ const div = documentFactory.createElement("dice-item");
48691
+ return div;
48692
+ }
48693
+ deserialize(data) {
48694
+ super.deserialize(data);
48695
+ this.transformPath();
48696
+ this.subject.publish(this);
48697
+ return this;
48698
+ }
48699
+ isClosed() {
48700
+ return true;
48701
+ }
48702
+ applyBackgroundColor(backgroundColor) {
48703
+ this.backgroundColor = backgroundColor;
48704
+ this.path.setBackgroundColor(backgroundColor);
48705
+ }
48706
+ setBackgroundColor(backgroundColor) {
48707
+ this.emit({
48708
+ class: "Dice",
48709
+ method: "setBackgroundColor",
48710
+ item: [this.getId()],
48711
+ newData: { backgroundColor },
48712
+ prevData: { backgroundColor: this.backgroundColor }
48713
+ });
48714
+ }
48715
+ applyBorderWidth(borderWidth) {
48716
+ this.borderWidth = borderWidth;
48717
+ this.path.setBorderWidth(borderWidth);
48718
+ }
48719
+ setBorderWidth(borderWidth) {
48720
+ this.emit({
48721
+ class: "Dice",
48722
+ method: "setBorderWidth",
48723
+ item: [this.getId()],
48724
+ newData: { borderWidth },
48725
+ prevData: { borderWidth: this.borderWidth }
48726
+ });
48727
+ }
48728
+ applyBorderColor(borderColor) {
48729
+ this.borderColor = borderColor;
48730
+ this.path.setBorderColor(borderColor);
48731
+ }
48732
+ setBorderColor(borderColor) {
48733
+ this.emit({
48734
+ class: "Dice",
48735
+ method: "setBorderColor",
48736
+ item: [this.getId()],
48737
+ newData: { borderColor },
48738
+ prevData: { borderColor: this.borderColor }
48739
+ });
48740
+ }
48741
+ setIsRotating(isRotating) {
48742
+ this.emit({
48743
+ class: "Dice",
48744
+ method: "setIsRotating",
48745
+ item: [this.getId()],
48746
+ newData: { isRotating },
48747
+ prevData: { isRotating: false }
48748
+ });
48749
+ }
48750
+ setValuesRange(range) {
48751
+ this.emit({
48752
+ class: "Dice",
48753
+ method: "changeValuesRange",
48754
+ item: [this.getId()],
48755
+ newData: range,
48756
+ prevData: this.range
48757
+ });
48758
+ }
48759
+ setValue(value) {
48760
+ this.emit({
48761
+ class: "Dice",
48762
+ method: "changeValue",
48763
+ item: [this.getId()],
48764
+ newData: { value },
48765
+ prevData: { value: this.value }
48766
+ });
48767
+ }
48768
+ throwDice() {
48769
+ this.setIsRotating(true);
48770
+ setTimeout(() => {
48771
+ this.setValue(Math.ceil(Math.random() * (this.range.max - this.range.min)) + this.range.min);
48772
+ this.isRotating = false;
48773
+ }, TIMEOUT);
48774
+ }
48775
+ apply(op) {
48776
+ super.apply(op);
48777
+ switch (op.class) {
48778
+ case "Dice":
48779
+ switch (op.method) {
48780
+ case "setBorderWidth":
48781
+ this.applyBorderWidth(op.newData.borderWidth);
48782
+ break;
48783
+ case "setBackgroundColor":
48784
+ this.applyBackgroundColor(op.newData.backgroundColor);
48785
+ break;
48786
+ case "setBorderColor":
48787
+ this.applyBorderColor(op.newData.borderColor);
48788
+ break;
48789
+ case "setIsRotating":
48790
+ this.isRotating = op.newData.isRotating;
48791
+ if (op.newData.isRotating) {
48792
+ setTimeout(() => {
48793
+ this.isRotating = false;
48794
+ }, TIMEOUT);
48795
+ }
48796
+ break;
48797
+ case "changeValue":
48798
+ this.value = op.newData.value;
48799
+ this.isRotating = false;
48800
+ break;
48801
+ case "changeValuesRange":
48802
+ this.range = op.newData;
48803
+ break;
48804
+ }
48805
+ break;
48806
+ }
48807
+ this.subject.publish(this);
48808
+ }
48809
+ }
48810
+ registerItem({
48811
+ item: Dice,
48812
+ defaultData: defaultDiceData,
48813
+ toolData: { name: "AddDice", tool: AddDice }
48814
+ });
48603
48815
  // src/Pointer/Cursor.ts
48604
48816
  var defaultCursors = [
48605
48817
  "default",
@@ -58714,6 +58926,7 @@ export {
58714
58926
  EditorContainer,
58715
58927
  DrawingContext,
58716
58928
  Drawing,
58929
+ Dice,
58717
58930
  DefaultTransformationData,
58718
58931
  DefaultShapeData,
58719
58932
  Deck,
@@ -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
+ }
@@ -0,0 +1 @@
1
+ export { Dice } from './Dice';
@@ -25,5 +25,6 @@ export { Star } from "./Examples/Star";
25
25
  export { Counter } from "./Examples/Counter";
26
26
  export { Card } from "./Examples/CardGame/Card";
27
27
  export { Deck } from "./Examples/CardGame/Deck";
28
+ export { Dice } from "./Examples/CardGame/Dice";
28
29
  export { Comment } from "./Comment";
29
30
  export type { HorisontalAlignment, VerticalAlignment } from "./Alignment";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "microboard-temp",
3
- "version": "0.4.15",
3
+ "version": "0.4.17",
4
4
  "description": "A flexible interactive whiteboard library",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",