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/esm/browser.js
CHANGED
|
@@ -45438,7 +45438,9 @@ function registerItem({
|
|
|
45438
45438
|
const { itemType } = defaultData2;
|
|
45439
45439
|
itemFactories[itemType] = createItemFactory(item, defaultData2);
|
|
45440
45440
|
itemValidators[itemType] = createItemValidator(defaultData2);
|
|
45441
|
-
|
|
45441
|
+
if (toolData) {
|
|
45442
|
+
registeredTools[toolData.name] = toolData.tool;
|
|
45443
|
+
}
|
|
45442
45444
|
itemCommandFactories[itemType] = createItemCommandFactory(itemType);
|
|
45443
45445
|
}
|
|
45444
45446
|
function createItemFactory(item, defaultData2) {
|
|
@@ -45752,6 +45754,323 @@ registerItem({
|
|
|
45752
45754
|
defaultData: defaultCounterData,
|
|
45753
45755
|
toolData: { name: "AddCounter", tool: AddCounter }
|
|
45754
45756
|
});
|
|
45757
|
+
// src/utils.ts
|
|
45758
|
+
function throttle(func, delay) {
|
|
45759
|
+
let lastCall = 0;
|
|
45760
|
+
let timeoutId = null;
|
|
45761
|
+
return function(...args) {
|
|
45762
|
+
const now = Date.now();
|
|
45763
|
+
if (lastCall + delay <= now) {
|
|
45764
|
+
lastCall = now;
|
|
45765
|
+
func(...args);
|
|
45766
|
+
if (timeoutId) {
|
|
45767
|
+
clearTimeout(timeoutId);
|
|
45768
|
+
timeoutId = null;
|
|
45769
|
+
}
|
|
45770
|
+
} else if (!timeoutId) {
|
|
45771
|
+
timeoutId = setTimeout(() => {
|
|
45772
|
+
lastCall = Date.now();
|
|
45773
|
+
timeoutId = null;
|
|
45774
|
+
func(...args);
|
|
45775
|
+
}, delay - (now - lastCall));
|
|
45776
|
+
}
|
|
45777
|
+
};
|
|
45778
|
+
}
|
|
45779
|
+
|
|
45780
|
+
// src/Items/Examples/CardGame/Card/Card.ts
|
|
45781
|
+
var defaultCardData = {
|
|
45782
|
+
itemType: "Card",
|
|
45783
|
+
isOpen: false,
|
|
45784
|
+
faceUrl: "",
|
|
45785
|
+
backsideUrl: "",
|
|
45786
|
+
isInDeck: false
|
|
45787
|
+
};
|
|
45788
|
+
var CARD_DIMENSIONS = { width: 250, height: 400 };
|
|
45789
|
+
|
|
45790
|
+
class Card extends BaseItem {
|
|
45791
|
+
subject = new Subject;
|
|
45792
|
+
faceUrl = "";
|
|
45793
|
+
backsideUrl = "";
|
|
45794
|
+
isOpen = false;
|
|
45795
|
+
isInDeck = false;
|
|
45796
|
+
throttledBringToFront;
|
|
45797
|
+
face = null;
|
|
45798
|
+
backside = null;
|
|
45799
|
+
imageToRender = null;
|
|
45800
|
+
shouldUseCustomRender = false;
|
|
45801
|
+
constructor(board, id = "", urls) {
|
|
45802
|
+
super(board, id, defaultCardData);
|
|
45803
|
+
if (urls) {
|
|
45804
|
+
this.faceUrl = urls.faceUrl;
|
|
45805
|
+
this.backsideUrl = urls.backsideUrl;
|
|
45806
|
+
this.createImages();
|
|
45807
|
+
}
|
|
45808
|
+
this.throttledBringToFront = throttle(() => {
|
|
45809
|
+
this.board.bringToFront(this);
|
|
45810
|
+
}, 1000);
|
|
45811
|
+
this.transformation.subject.subscribe(() => {
|
|
45812
|
+
this.throttledBringToFront();
|
|
45813
|
+
this.updateMbr();
|
|
45814
|
+
this.updateImageToRender();
|
|
45815
|
+
this.subject.publish(this);
|
|
45816
|
+
});
|
|
45817
|
+
this.updateMbr();
|
|
45818
|
+
}
|
|
45819
|
+
createImages() {
|
|
45820
|
+
this.face = conf.documentFactory.createElement("img");
|
|
45821
|
+
this.backside = conf.documentFactory.createElement("img");
|
|
45822
|
+
this.face.src = this.faceUrl;
|
|
45823
|
+
this.backside.src = this.backsideUrl;
|
|
45824
|
+
this.face.onload = () => {
|
|
45825
|
+
this.subject.publish(this);
|
|
45826
|
+
};
|
|
45827
|
+
this.backside.onload = () => {
|
|
45828
|
+
this.subject.publish(this);
|
|
45829
|
+
};
|
|
45830
|
+
}
|
|
45831
|
+
setIsInDeck(isInDeck) {
|
|
45832
|
+
this.emit({
|
|
45833
|
+
class: "Card",
|
|
45834
|
+
method: "setIsInDeck",
|
|
45835
|
+
item: [this.getId()],
|
|
45836
|
+
newData: { isInDeck },
|
|
45837
|
+
prevData: { isInDeck: this.isInDeck }
|
|
45838
|
+
});
|
|
45839
|
+
}
|
|
45840
|
+
updateImageToRender() {
|
|
45841
|
+
this.imageToRender = this.backside;
|
|
45842
|
+
if (this.isOpen) {
|
|
45843
|
+
this.imageToRender = this.face;
|
|
45844
|
+
}
|
|
45845
|
+
}
|
|
45846
|
+
render(context, deckRenderData) {
|
|
45847
|
+
if (this.transformationRenderBlock || this.isInDeck && !deckRenderData) {
|
|
45848
|
+
return;
|
|
45849
|
+
}
|
|
45850
|
+
const ctx = context.ctx;
|
|
45851
|
+
if (this.imageToRender && this.imageToRender.complete) {
|
|
45852
|
+
ctx.save();
|
|
45853
|
+
let left = this.left;
|
|
45854
|
+
let top = this.top;
|
|
45855
|
+
if (deckRenderData) {
|
|
45856
|
+
left = deckRenderData.left + 2 * deckRenderData.cardPosition;
|
|
45857
|
+
top = deckRenderData.top;
|
|
45858
|
+
}
|
|
45859
|
+
ctx.drawImage(this.imageToRender, left, top, CARD_DIMENSIONS.width, CARD_DIMENSIONS.height);
|
|
45860
|
+
ctx.restore();
|
|
45861
|
+
}
|
|
45862
|
+
}
|
|
45863
|
+
updateMbr() {
|
|
45864
|
+
const { translateX, translateY, scaleX, scaleY } = this.transformation.matrix;
|
|
45865
|
+
this.left = translateX;
|
|
45866
|
+
this.top = translateY;
|
|
45867
|
+
this.right = this.left + CARD_DIMENSIONS.width * scaleX;
|
|
45868
|
+
this.bottom = this.top + CARD_DIMENSIONS.height * scaleY;
|
|
45869
|
+
}
|
|
45870
|
+
getMbr() {
|
|
45871
|
+
if (this.isInDeck) {
|
|
45872
|
+
return new Mbr(1e4, 1e4, 1e4, 1e4);
|
|
45873
|
+
}
|
|
45874
|
+
return super.getMbr();
|
|
45875
|
+
}
|
|
45876
|
+
getPath() {
|
|
45877
|
+
return new Path(this.getMbr().getLines());
|
|
45878
|
+
}
|
|
45879
|
+
renderHTML(documentFactory) {
|
|
45880
|
+
const div = documentFactory.createElement("card-item");
|
|
45881
|
+
return div;
|
|
45882
|
+
}
|
|
45883
|
+
deserialize(data) {
|
|
45884
|
+
super.deserialize(data);
|
|
45885
|
+
this.updateMbr();
|
|
45886
|
+
this.createImages();
|
|
45887
|
+
this.subject.publish(this);
|
|
45888
|
+
return this;
|
|
45889
|
+
}
|
|
45890
|
+
toggleIsOpen() {
|
|
45891
|
+
this.emit({
|
|
45892
|
+
class: "Card",
|
|
45893
|
+
method: "setIsOpen",
|
|
45894
|
+
item: [this.getId()],
|
|
45895
|
+
newData: { isOpen: !this.isOpen },
|
|
45896
|
+
prevData: { isOpen: this.isOpen }
|
|
45897
|
+
});
|
|
45898
|
+
}
|
|
45899
|
+
apply(op) {
|
|
45900
|
+
super.apply(op);
|
|
45901
|
+
switch (op.class) {
|
|
45902
|
+
case "Card":
|
|
45903
|
+
switch (op.method) {
|
|
45904
|
+
case "setIsOpen":
|
|
45905
|
+
this.isOpen = op.newData.isOpen;
|
|
45906
|
+
this.updateImageToRender();
|
|
45907
|
+
break;
|
|
45908
|
+
case "setIsInDeck":
|
|
45909
|
+
this.isInDeck = op.newData.isInDeck;
|
|
45910
|
+
break;
|
|
45911
|
+
}
|
|
45912
|
+
break;
|
|
45913
|
+
}
|
|
45914
|
+
this.subject.publish(this);
|
|
45915
|
+
}
|
|
45916
|
+
}
|
|
45917
|
+
registerItem({
|
|
45918
|
+
item: Card,
|
|
45919
|
+
defaultData: defaultCardData
|
|
45920
|
+
});
|
|
45921
|
+
// src/Items/Examples/CardGame/Deck/Deck.ts
|
|
45922
|
+
var defaultDeckData = {
|
|
45923
|
+
itemType: "Deck",
|
|
45924
|
+
cardIds: []
|
|
45925
|
+
};
|
|
45926
|
+
|
|
45927
|
+
class Deck extends BaseItem {
|
|
45928
|
+
subject = new Subject;
|
|
45929
|
+
shouldUseCustomRender = false;
|
|
45930
|
+
cardIds = [];
|
|
45931
|
+
cards = [];
|
|
45932
|
+
constructor(board, id = "", defaultData2, cards) {
|
|
45933
|
+
super(board, id, defaultDeckData);
|
|
45934
|
+
if (cards) {
|
|
45935
|
+
this.cards = cards;
|
|
45936
|
+
cards.forEach((card) => card.setIsInDeck(true));
|
|
45937
|
+
this.transformation.matrix = cards[cards.length - 1].transformation.matrix;
|
|
45938
|
+
this.cardIds = cards.map((card) => card.getId());
|
|
45939
|
+
}
|
|
45940
|
+
this.transformation.subject.subscribe(() => {
|
|
45941
|
+
this.updateMbr();
|
|
45942
|
+
this.subject.publish(this);
|
|
45943
|
+
});
|
|
45944
|
+
this.updateMbr();
|
|
45945
|
+
}
|
|
45946
|
+
getDeck() {
|
|
45947
|
+
return this.cards;
|
|
45948
|
+
}
|
|
45949
|
+
getTopCard() {
|
|
45950
|
+
const cardId = this.cardIds[this.cardIds.length - 1];
|
|
45951
|
+
return this.getCards([cardId])[0];
|
|
45952
|
+
}
|
|
45953
|
+
getBottomCard() {
|
|
45954
|
+
const cardId = this.cardIds[0];
|
|
45955
|
+
return this.getCards([cardId])[0];
|
|
45956
|
+
}
|
|
45957
|
+
getRandomCard() {
|
|
45958
|
+
const cardId = this.cardIds[Math.ceil(Math.random() * this.cardIds.length) - 1];
|
|
45959
|
+
return this.getCards([cardId])[0];
|
|
45960
|
+
}
|
|
45961
|
+
getCards(cardIds) {
|
|
45962
|
+
const cards = this.findCardsOnBoard(cardIds);
|
|
45963
|
+
this.removeCards(cards);
|
|
45964
|
+
return cards;
|
|
45965
|
+
}
|
|
45966
|
+
findCardsOnBoard(cardIds) {
|
|
45967
|
+
return cardIds.map((cardId) => {
|
|
45968
|
+
return this.board.items.getById(cardId);
|
|
45969
|
+
}).filter((card) => !!card);
|
|
45970
|
+
}
|
|
45971
|
+
updateCards() {
|
|
45972
|
+
if (this.cardIds.length === this.cards.length) {
|
|
45973
|
+
return this.cards;
|
|
45974
|
+
}
|
|
45975
|
+
this.cards = this.findCardsOnBoard(this.cardIds);
|
|
45976
|
+
return this.cards;
|
|
45977
|
+
}
|
|
45978
|
+
shuffleDeck() {
|
|
45979
|
+
const shuffled = [...this.cardIds];
|
|
45980
|
+
for (let i = shuffled.length - 1;i > 0; i--) {
|
|
45981
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
45982
|
+
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
|
|
45983
|
+
}
|
|
45984
|
+
const cards = this.findCardsOnBoard(shuffled);
|
|
45985
|
+
this.addCards(cards, true);
|
|
45986
|
+
}
|
|
45987
|
+
addCards(cards, shouldReplaceExistingCards = false) {
|
|
45988
|
+
cards.forEach((card) => {
|
|
45989
|
+
card.setIsInDeck(true);
|
|
45990
|
+
});
|
|
45991
|
+
this.board.bringToFront(cards);
|
|
45992
|
+
this.emit({
|
|
45993
|
+
class: "Deck",
|
|
45994
|
+
method: "addCards",
|
|
45995
|
+
item: [this.getId()],
|
|
45996
|
+
newData: {
|
|
45997
|
+
cardIds: cards.map((card) => card.getId()),
|
|
45998
|
+
shouldReplaceExistingCards
|
|
45999
|
+
},
|
|
46000
|
+
prevData: { cardIds: this.cardIds, shouldReplaceExistingCards }
|
|
46001
|
+
});
|
|
46002
|
+
}
|
|
46003
|
+
removeCards(cards) {
|
|
46004
|
+
cards.forEach((card) => {
|
|
46005
|
+
card.setIsInDeck(false);
|
|
46006
|
+
});
|
|
46007
|
+
this.emit({
|
|
46008
|
+
class: "Deck",
|
|
46009
|
+
method: "removeCards",
|
|
46010
|
+
item: [this.getId()],
|
|
46011
|
+
newData: { cardIds: cards.map((card) => card.getId()) },
|
|
46012
|
+
prevData: { cardIds: this.cardIds }
|
|
46013
|
+
});
|
|
46014
|
+
}
|
|
46015
|
+
apply(op) {
|
|
46016
|
+
super.apply(op);
|
|
46017
|
+
switch (op.class) {
|
|
46018
|
+
case "Deck":
|
|
46019
|
+
switch (op.method) {
|
|
46020
|
+
case "addCards":
|
|
46021
|
+
if (op.newData.shouldReplaceExistingCards) {
|
|
46022
|
+
this.cardIds = op.newData.cardIds;
|
|
46023
|
+
this.cards = this.findCardsOnBoard(this.cardIds);
|
|
46024
|
+
} else {
|
|
46025
|
+
this.cardIds = [
|
|
46026
|
+
...op.newData.cardIds,
|
|
46027
|
+
...this.cardIds
|
|
46028
|
+
];
|
|
46029
|
+
this.updateCards();
|
|
46030
|
+
this.updateMbr();
|
|
46031
|
+
}
|
|
46032
|
+
break;
|
|
46033
|
+
case "removeCards":
|
|
46034
|
+
this.cardIds = this.cardIds.filter((card) => {
|
|
46035
|
+
return !op.newData.cardIds.includes(card);
|
|
46036
|
+
});
|
|
46037
|
+
this.updateCards();
|
|
46038
|
+
this.updateMbr();
|
|
46039
|
+
break;
|
|
46040
|
+
}
|
|
46041
|
+
break;
|
|
46042
|
+
}
|
|
46043
|
+
this.subject.publish(this);
|
|
46044
|
+
}
|
|
46045
|
+
updateMbr() {
|
|
46046
|
+
const { translateX, translateY, scaleX, scaleY } = this.transformation.matrix;
|
|
46047
|
+
this.left = translateX;
|
|
46048
|
+
this.top = translateY;
|
|
46049
|
+
this.right = this.left + CARD_DIMENSIONS.width * scaleX + 2 * this.cardIds.length;
|
|
46050
|
+
this.bottom = this.top + CARD_DIMENSIONS.height * scaleY;
|
|
46051
|
+
}
|
|
46052
|
+
deserialize(data) {
|
|
46053
|
+
super.deserialize(data);
|
|
46054
|
+
this.updateCards();
|
|
46055
|
+
return this;
|
|
46056
|
+
}
|
|
46057
|
+
render(context) {
|
|
46058
|
+
if (this.transformationRenderBlock) {
|
|
46059
|
+
return;
|
|
46060
|
+
}
|
|
46061
|
+
this.cards.forEach((card, index2) => {
|
|
46062
|
+
card.render(context, {
|
|
46063
|
+
top: this.top,
|
|
46064
|
+
left: this.left,
|
|
46065
|
+
cardPosition: index2 + 1
|
|
46066
|
+
});
|
|
46067
|
+
});
|
|
46068
|
+
}
|
|
46069
|
+
}
|
|
46070
|
+
registerItem({
|
|
46071
|
+
item: Deck,
|
|
46072
|
+
defaultData: defaultDeckData
|
|
46073
|
+
});
|
|
45755
46074
|
// src/Pointer/Cursor.ts
|
|
45756
46075
|
var defaultCursors = [
|
|
45757
46076
|
"default",
|
|
@@ -46264,27 +46583,6 @@ class Camera {
|
|
|
46264
46583
|
requestAnimationFrame(animate);
|
|
46265
46584
|
}
|
|
46266
46585
|
}
|
|
46267
|
-
function throttle(func, delay) {
|
|
46268
|
-
let lastCall = 0;
|
|
46269
|
-
let timeoutId = null;
|
|
46270
|
-
return function(...args) {
|
|
46271
|
-
const now = Date.now();
|
|
46272
|
-
if (lastCall + delay <= now) {
|
|
46273
|
-
lastCall = now;
|
|
46274
|
-
func(...args);
|
|
46275
|
-
if (timeoutId) {
|
|
46276
|
-
clearTimeout(timeoutId);
|
|
46277
|
-
timeoutId = null;
|
|
46278
|
-
}
|
|
46279
|
-
} else if (!timeoutId) {
|
|
46280
|
-
timeoutId = setTimeout(() => {
|
|
46281
|
-
lastCall = Date.now();
|
|
46282
|
-
timeoutId = null;
|
|
46283
|
-
func(...args);
|
|
46284
|
-
}, delay - (now - lastCall));
|
|
46285
|
-
}
|
|
46286
|
-
};
|
|
46287
|
-
}
|
|
46288
46586
|
// src/hotkeys.json
|
|
46289
46587
|
var hotkeys_default = {
|
|
46290
46588
|
select: {
|
|
@@ -55884,6 +56182,7 @@ export {
|
|
|
55884
56182
|
Drawing,
|
|
55885
56183
|
DefaultTransformationData,
|
|
55886
56184
|
DefaultShapeData,
|
|
56185
|
+
Deck,
|
|
55887
56186
|
DEFAULT_SHAPE,
|
|
55888
56187
|
CubicBezier,
|
|
55889
56188
|
Counter,
|
|
@@ -55891,6 +56190,7 @@ export {
|
|
|
55891
56190
|
Connector2 as Connector,
|
|
55892
56191
|
ConnectionLineWidths,
|
|
55893
56192
|
Comment,
|
|
56193
|
+
Card,
|
|
55894
56194
|
Camera,
|
|
55895
56195
|
CURSORS_IDLE_CLEANUP_DELAY,
|
|
55896
56196
|
CURSORS_ANIMATION_DURATION,
|