microboard-temp 0.4.10 → 0.4.12
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 +322 -22
- package/dist/cjs/index.js +322 -22
- package/dist/cjs/node.js +322 -22
- package/dist/esm/browser.js +322 -22
- package/dist/esm/index.js +322 -22
- package/dist/esm/node.js +322 -22
- package/dist/types/Camera/Camera.d.ts +0 -1
- package/dist/types/Items/Examples/CardGame/Card/AddHand.d.ts +0 -0
- package/dist/types/Items/Examples/CardGame/Card/Card.d.ts +46 -0
- package/dist/types/Items/Examples/CardGame/Card/CardOperation.d.ts +14 -0
- package/dist/types/Items/Examples/CardGame/Card/index.d.ts +1 -0
- package/dist/types/Items/Examples/CardGame/Deck/Deck.d.ts +28 -0
- package/dist/types/Items/Examples/CardGame/Deck/DeckOperation.d.ts +15 -0
- package/dist/types/Items/Examples/CardGame/Deck/index.d.ts +1 -0
- package/dist/types/Items/RegisterItem.d.ts +1 -1
- package/dist/types/Items/index.d.ts +2 -0
- package/dist/types/utils.d.ts +1 -0
- package/package.json +1 -1
package/dist/cjs/node.js
CHANGED
|
@@ -1783,6 +1783,7 @@ __export(exports_node, {
|
|
|
1783
1783
|
Drawing: () => Drawing,
|
|
1784
1784
|
DefaultTransformationData: () => DefaultTransformationData,
|
|
1785
1785
|
DefaultShapeData: () => DefaultShapeData,
|
|
1786
|
+
Deck: () => Deck,
|
|
1786
1787
|
DEFAULT_SHAPE: () => DEFAULT_SHAPE,
|
|
1787
1788
|
CubicBezier: () => CubicBezier,
|
|
1788
1789
|
Counter: () => Counter,
|
|
@@ -1790,6 +1791,7 @@ __export(exports_node, {
|
|
|
1790
1791
|
Connector: () => Connector2,
|
|
1791
1792
|
ConnectionLineWidths: () => ConnectionLineWidths,
|
|
1792
1793
|
Comment: () => Comment,
|
|
1794
|
+
Card: () => Card,
|
|
1793
1795
|
Camera: () => Camera,
|
|
1794
1796
|
CURSORS_IDLE_CLEANUP_DELAY: () => CURSORS_IDLE_CLEANUP_DELAY,
|
|
1795
1797
|
CURSORS_ANIMATION_DURATION: () => CURSORS_ANIMATION_DURATION,
|
|
@@ -48125,7 +48127,9 @@ function registerItem({
|
|
|
48125
48127
|
const { itemType } = defaultData2;
|
|
48126
48128
|
itemFactories[itemType] = createItemFactory(item, defaultData2);
|
|
48127
48129
|
itemValidators[itemType] = createItemValidator(defaultData2);
|
|
48128
|
-
|
|
48130
|
+
if (toolData) {
|
|
48131
|
+
registeredTools[toolData.name] = toolData.tool;
|
|
48132
|
+
}
|
|
48129
48133
|
itemCommandFactories[itemType] = createItemCommandFactory(itemType);
|
|
48130
48134
|
}
|
|
48131
48135
|
function createItemFactory(item, defaultData2) {
|
|
@@ -48439,6 +48443,323 @@ registerItem({
|
|
|
48439
48443
|
defaultData: defaultCounterData,
|
|
48440
48444
|
toolData: { name: "AddCounter", tool: AddCounter }
|
|
48441
48445
|
});
|
|
48446
|
+
// src/utils.ts
|
|
48447
|
+
function throttle(func, delay) {
|
|
48448
|
+
let lastCall = 0;
|
|
48449
|
+
let timeoutId = null;
|
|
48450
|
+
return function(...args) {
|
|
48451
|
+
const now = Date.now();
|
|
48452
|
+
if (lastCall + delay <= now) {
|
|
48453
|
+
lastCall = now;
|
|
48454
|
+
func(...args);
|
|
48455
|
+
if (timeoutId) {
|
|
48456
|
+
clearTimeout(timeoutId);
|
|
48457
|
+
timeoutId = null;
|
|
48458
|
+
}
|
|
48459
|
+
} else if (!timeoutId) {
|
|
48460
|
+
timeoutId = setTimeout(() => {
|
|
48461
|
+
lastCall = Date.now();
|
|
48462
|
+
timeoutId = null;
|
|
48463
|
+
func(...args);
|
|
48464
|
+
}, delay - (now - lastCall));
|
|
48465
|
+
}
|
|
48466
|
+
};
|
|
48467
|
+
}
|
|
48468
|
+
|
|
48469
|
+
// src/Items/Examples/CardGame/Card/Card.ts
|
|
48470
|
+
var defaultCardData = {
|
|
48471
|
+
itemType: "Card",
|
|
48472
|
+
isOpen: false,
|
|
48473
|
+
faceUrl: "",
|
|
48474
|
+
backsideUrl: "",
|
|
48475
|
+
isInDeck: false
|
|
48476
|
+
};
|
|
48477
|
+
var CARD_DIMENSIONS = { width: 250, height: 400 };
|
|
48478
|
+
|
|
48479
|
+
class Card extends BaseItem {
|
|
48480
|
+
subject = new Subject;
|
|
48481
|
+
faceUrl = "";
|
|
48482
|
+
backsideUrl = "";
|
|
48483
|
+
isOpen = false;
|
|
48484
|
+
isInDeck = false;
|
|
48485
|
+
throttledBringToFront;
|
|
48486
|
+
face = null;
|
|
48487
|
+
backside = null;
|
|
48488
|
+
imageToRender = null;
|
|
48489
|
+
shouldUseCustomRender = false;
|
|
48490
|
+
constructor(board, id = "", urls) {
|
|
48491
|
+
super(board, id, defaultCardData);
|
|
48492
|
+
if (urls) {
|
|
48493
|
+
this.faceUrl = urls.faceUrl;
|
|
48494
|
+
this.backsideUrl = urls.backsideUrl;
|
|
48495
|
+
this.createImages();
|
|
48496
|
+
}
|
|
48497
|
+
this.throttledBringToFront = throttle(() => {
|
|
48498
|
+
this.board.bringToFront(this);
|
|
48499
|
+
}, 1000);
|
|
48500
|
+
this.transformation.subject.subscribe(() => {
|
|
48501
|
+
this.throttledBringToFront();
|
|
48502
|
+
this.updateMbr();
|
|
48503
|
+
this.updateImageToRender();
|
|
48504
|
+
this.subject.publish(this);
|
|
48505
|
+
});
|
|
48506
|
+
this.updateMbr();
|
|
48507
|
+
}
|
|
48508
|
+
createImages() {
|
|
48509
|
+
this.face = conf.documentFactory.createElement("img");
|
|
48510
|
+
this.backside = conf.documentFactory.createElement("img");
|
|
48511
|
+
this.face.src = this.faceUrl;
|
|
48512
|
+
this.backside.src = this.backsideUrl;
|
|
48513
|
+
this.face.onload = () => {
|
|
48514
|
+
this.subject.publish(this);
|
|
48515
|
+
};
|
|
48516
|
+
this.backside.onload = () => {
|
|
48517
|
+
this.subject.publish(this);
|
|
48518
|
+
};
|
|
48519
|
+
}
|
|
48520
|
+
setIsInDeck(isInDeck) {
|
|
48521
|
+
this.emit({
|
|
48522
|
+
class: "Card",
|
|
48523
|
+
method: "setIsInDeck",
|
|
48524
|
+
item: [this.getId()],
|
|
48525
|
+
newData: { isInDeck },
|
|
48526
|
+
prevData: { isInDeck: this.isInDeck }
|
|
48527
|
+
});
|
|
48528
|
+
}
|
|
48529
|
+
updateImageToRender() {
|
|
48530
|
+
this.imageToRender = this.backside;
|
|
48531
|
+
if (this.isOpen) {
|
|
48532
|
+
this.imageToRender = this.face;
|
|
48533
|
+
}
|
|
48534
|
+
}
|
|
48535
|
+
render(context, deckRenderData) {
|
|
48536
|
+
if (this.transformationRenderBlock || this.isInDeck && !deckRenderData) {
|
|
48537
|
+
return;
|
|
48538
|
+
}
|
|
48539
|
+
const ctx = context.ctx;
|
|
48540
|
+
if (this.imageToRender && this.imageToRender.complete) {
|
|
48541
|
+
ctx.save();
|
|
48542
|
+
let left = this.left;
|
|
48543
|
+
let top = this.top;
|
|
48544
|
+
if (deckRenderData) {
|
|
48545
|
+
left = deckRenderData.left + 2 * deckRenderData.cardPosition;
|
|
48546
|
+
top = deckRenderData.top;
|
|
48547
|
+
}
|
|
48548
|
+
ctx.drawImage(this.imageToRender, left, top, CARD_DIMENSIONS.width, CARD_DIMENSIONS.height);
|
|
48549
|
+
ctx.restore();
|
|
48550
|
+
}
|
|
48551
|
+
}
|
|
48552
|
+
updateMbr() {
|
|
48553
|
+
const { translateX, translateY, scaleX, scaleY } = this.transformation.matrix;
|
|
48554
|
+
this.left = translateX;
|
|
48555
|
+
this.top = translateY;
|
|
48556
|
+
this.right = this.left + CARD_DIMENSIONS.width * scaleX;
|
|
48557
|
+
this.bottom = this.top + CARD_DIMENSIONS.height * scaleY;
|
|
48558
|
+
}
|
|
48559
|
+
getMbr() {
|
|
48560
|
+
if (this.isInDeck) {
|
|
48561
|
+
return new Mbr(1e4, 1e4, 1e4, 1e4);
|
|
48562
|
+
}
|
|
48563
|
+
return super.getMbr();
|
|
48564
|
+
}
|
|
48565
|
+
getPath() {
|
|
48566
|
+
return new Path(this.getMbr().getLines());
|
|
48567
|
+
}
|
|
48568
|
+
renderHTML(documentFactory) {
|
|
48569
|
+
const div = documentFactory.createElement("card-item");
|
|
48570
|
+
return div;
|
|
48571
|
+
}
|
|
48572
|
+
deserialize(data) {
|
|
48573
|
+
super.deserialize(data);
|
|
48574
|
+
this.updateMbr();
|
|
48575
|
+
this.createImages();
|
|
48576
|
+
this.subject.publish(this);
|
|
48577
|
+
return this;
|
|
48578
|
+
}
|
|
48579
|
+
toggleIsOpen() {
|
|
48580
|
+
this.emit({
|
|
48581
|
+
class: "Card",
|
|
48582
|
+
method: "setIsOpen",
|
|
48583
|
+
item: [this.getId()],
|
|
48584
|
+
newData: { isOpen: !this.isOpen },
|
|
48585
|
+
prevData: { isOpen: this.isOpen }
|
|
48586
|
+
});
|
|
48587
|
+
}
|
|
48588
|
+
apply(op) {
|
|
48589
|
+
super.apply(op);
|
|
48590
|
+
switch (op.class) {
|
|
48591
|
+
case "Card":
|
|
48592
|
+
switch (op.method) {
|
|
48593
|
+
case "setIsOpen":
|
|
48594
|
+
this.isOpen = op.newData.isOpen;
|
|
48595
|
+
this.updateImageToRender();
|
|
48596
|
+
break;
|
|
48597
|
+
case "setIsInDeck":
|
|
48598
|
+
this.isInDeck = op.newData.isInDeck;
|
|
48599
|
+
break;
|
|
48600
|
+
}
|
|
48601
|
+
break;
|
|
48602
|
+
}
|
|
48603
|
+
this.subject.publish(this);
|
|
48604
|
+
}
|
|
48605
|
+
}
|
|
48606
|
+
registerItem({
|
|
48607
|
+
item: Card,
|
|
48608
|
+
defaultData: defaultCardData
|
|
48609
|
+
});
|
|
48610
|
+
// src/Items/Examples/CardGame/Deck/Deck.ts
|
|
48611
|
+
var defaultDeckData = {
|
|
48612
|
+
itemType: "Deck",
|
|
48613
|
+
cardIds: []
|
|
48614
|
+
};
|
|
48615
|
+
|
|
48616
|
+
class Deck extends BaseItem {
|
|
48617
|
+
subject = new Subject;
|
|
48618
|
+
shouldUseCustomRender = false;
|
|
48619
|
+
cardIds = [];
|
|
48620
|
+
cards = [];
|
|
48621
|
+
constructor(board, id = "", defaultData2, cards) {
|
|
48622
|
+
super(board, id, defaultDeckData);
|
|
48623
|
+
if (cards) {
|
|
48624
|
+
this.cards = cards;
|
|
48625
|
+
cards.forEach((card) => card.setIsInDeck(true));
|
|
48626
|
+
this.transformation.matrix = cards[cards.length - 1].transformation.matrix;
|
|
48627
|
+
this.cardIds = cards.map((card) => card.getId());
|
|
48628
|
+
}
|
|
48629
|
+
this.transformation.subject.subscribe(() => {
|
|
48630
|
+
this.updateMbr();
|
|
48631
|
+
this.subject.publish(this);
|
|
48632
|
+
});
|
|
48633
|
+
this.updateMbr();
|
|
48634
|
+
}
|
|
48635
|
+
getDeck() {
|
|
48636
|
+
return this.cards;
|
|
48637
|
+
}
|
|
48638
|
+
getTopCard() {
|
|
48639
|
+
const cardId = this.cardIds[this.cardIds.length - 1];
|
|
48640
|
+
return this.getCards([cardId])[0];
|
|
48641
|
+
}
|
|
48642
|
+
getBottomCard() {
|
|
48643
|
+
const cardId = this.cardIds[0];
|
|
48644
|
+
return this.getCards([cardId])[0];
|
|
48645
|
+
}
|
|
48646
|
+
getRandomCard() {
|
|
48647
|
+
const cardId = this.cardIds[Math.ceil(Math.random() * this.cardIds.length) - 1];
|
|
48648
|
+
return this.getCards([cardId])[0];
|
|
48649
|
+
}
|
|
48650
|
+
getCards(cardIds) {
|
|
48651
|
+
const cards = this.findCardsOnBoard(cardIds);
|
|
48652
|
+
this.removeCards(cards);
|
|
48653
|
+
return cards;
|
|
48654
|
+
}
|
|
48655
|
+
findCardsOnBoard(cardIds) {
|
|
48656
|
+
return cardIds.map((cardId) => {
|
|
48657
|
+
return this.board.items.getById(cardId);
|
|
48658
|
+
}).filter((card) => !!card);
|
|
48659
|
+
}
|
|
48660
|
+
updateCards() {
|
|
48661
|
+
if (this.cardIds.length === this.cards.length) {
|
|
48662
|
+
return this.cards;
|
|
48663
|
+
}
|
|
48664
|
+
this.cards = this.findCardsOnBoard(this.cardIds);
|
|
48665
|
+
return this.cards;
|
|
48666
|
+
}
|
|
48667
|
+
shuffleDeck() {
|
|
48668
|
+
const shuffled = [...this.cardIds];
|
|
48669
|
+
for (let i = shuffled.length - 1;i > 0; i--) {
|
|
48670
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
48671
|
+
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
|
|
48672
|
+
}
|
|
48673
|
+
const cards = this.findCardsOnBoard(shuffled);
|
|
48674
|
+
this.addCards(cards, true);
|
|
48675
|
+
}
|
|
48676
|
+
addCards(cards, shouldReplaceExistingCards = false) {
|
|
48677
|
+
cards.forEach((card) => {
|
|
48678
|
+
card.setIsInDeck(true);
|
|
48679
|
+
});
|
|
48680
|
+
this.board.bringToFront(cards);
|
|
48681
|
+
this.emit({
|
|
48682
|
+
class: "Deck",
|
|
48683
|
+
method: "addCards",
|
|
48684
|
+
item: [this.getId()],
|
|
48685
|
+
newData: {
|
|
48686
|
+
cardIds: cards.map((card) => card.getId()),
|
|
48687
|
+
shouldReplaceExistingCards
|
|
48688
|
+
},
|
|
48689
|
+
prevData: { cardIds: this.cardIds, shouldReplaceExistingCards }
|
|
48690
|
+
});
|
|
48691
|
+
}
|
|
48692
|
+
removeCards(cards) {
|
|
48693
|
+
cards.forEach((card) => {
|
|
48694
|
+
card.setIsInDeck(false);
|
|
48695
|
+
});
|
|
48696
|
+
this.emit({
|
|
48697
|
+
class: "Deck",
|
|
48698
|
+
method: "removeCards",
|
|
48699
|
+
item: [this.getId()],
|
|
48700
|
+
newData: { cardIds: cards.map((card) => card.getId()) },
|
|
48701
|
+
prevData: { cardIds: this.cardIds }
|
|
48702
|
+
});
|
|
48703
|
+
}
|
|
48704
|
+
apply(op) {
|
|
48705
|
+
super.apply(op);
|
|
48706
|
+
switch (op.class) {
|
|
48707
|
+
case "Deck":
|
|
48708
|
+
switch (op.method) {
|
|
48709
|
+
case "addCards":
|
|
48710
|
+
if (op.newData.shouldReplaceExistingCards) {
|
|
48711
|
+
this.cardIds = op.newData.cardIds;
|
|
48712
|
+
this.cards = this.findCardsOnBoard(this.cardIds);
|
|
48713
|
+
} else {
|
|
48714
|
+
this.cardIds = [
|
|
48715
|
+
...op.newData.cardIds,
|
|
48716
|
+
...this.cardIds
|
|
48717
|
+
];
|
|
48718
|
+
this.updateCards();
|
|
48719
|
+
this.updateMbr();
|
|
48720
|
+
}
|
|
48721
|
+
break;
|
|
48722
|
+
case "removeCards":
|
|
48723
|
+
this.cardIds = this.cardIds.filter((card) => {
|
|
48724
|
+
return !op.newData.cardIds.includes(card);
|
|
48725
|
+
});
|
|
48726
|
+
this.updateCards();
|
|
48727
|
+
this.updateMbr();
|
|
48728
|
+
break;
|
|
48729
|
+
}
|
|
48730
|
+
break;
|
|
48731
|
+
}
|
|
48732
|
+
this.subject.publish(this);
|
|
48733
|
+
}
|
|
48734
|
+
updateMbr() {
|
|
48735
|
+
const { translateX, translateY, scaleX, scaleY } = this.transformation.matrix;
|
|
48736
|
+
this.left = translateX;
|
|
48737
|
+
this.top = translateY;
|
|
48738
|
+
this.right = this.left + CARD_DIMENSIONS.width * scaleX + 2 * this.cardIds.length;
|
|
48739
|
+
this.bottom = this.top + CARD_DIMENSIONS.height * scaleY;
|
|
48740
|
+
}
|
|
48741
|
+
deserialize(data) {
|
|
48742
|
+
super.deserialize(data);
|
|
48743
|
+
this.updateCards();
|
|
48744
|
+
return this;
|
|
48745
|
+
}
|
|
48746
|
+
render(context) {
|
|
48747
|
+
if (this.transformationRenderBlock) {
|
|
48748
|
+
return;
|
|
48749
|
+
}
|
|
48750
|
+
this.cards.forEach((card, index2) => {
|
|
48751
|
+
card.render(context, {
|
|
48752
|
+
top: this.top,
|
|
48753
|
+
left: this.left,
|
|
48754
|
+
cardPosition: index2 + 1
|
|
48755
|
+
});
|
|
48756
|
+
});
|
|
48757
|
+
}
|
|
48758
|
+
}
|
|
48759
|
+
registerItem({
|
|
48760
|
+
item: Deck,
|
|
48761
|
+
defaultData: defaultDeckData
|
|
48762
|
+
});
|
|
48442
48763
|
// src/Pointer/Cursor.ts
|
|
48443
48764
|
var defaultCursors = [
|
|
48444
48765
|
"default",
|
|
@@ -48951,27 +49272,6 @@ class Camera {
|
|
|
48951
49272
|
requestAnimationFrame(animate);
|
|
48952
49273
|
}
|
|
48953
49274
|
}
|
|
48954
|
-
function throttle(func, delay) {
|
|
48955
|
-
let lastCall = 0;
|
|
48956
|
-
let timeoutId = null;
|
|
48957
|
-
return function(...args) {
|
|
48958
|
-
const now = Date.now();
|
|
48959
|
-
if (lastCall + delay <= now) {
|
|
48960
|
-
lastCall = now;
|
|
48961
|
-
func(...args);
|
|
48962
|
-
if (timeoutId) {
|
|
48963
|
-
clearTimeout(timeoutId);
|
|
48964
|
-
timeoutId = null;
|
|
48965
|
-
}
|
|
48966
|
-
} else if (!timeoutId) {
|
|
48967
|
-
timeoutId = setTimeout(() => {
|
|
48968
|
-
lastCall = Date.now();
|
|
48969
|
-
timeoutId = null;
|
|
48970
|
-
func(...args);
|
|
48971
|
-
}, delay - (now - lastCall));
|
|
48972
|
-
}
|
|
48973
|
-
};
|
|
48974
|
-
}
|
|
48975
49275
|
// src/hotkeys.json
|
|
48976
49276
|
var hotkeys_default = {
|
|
48977
49277
|
select: {
|