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