microboard-temp 0.4.10 → 0.4.11
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 +317 -22
- package/dist/cjs/index.js +317 -22
- package/dist/cjs/node.js +317 -22
- package/dist/esm/browser.js +317 -22
- package/dist/esm/index.js +317 -22
- package/dist/esm/node.js +317 -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 +42 -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/browser.js
CHANGED
|
@@ -746,6 +746,7 @@ __export(exports_browser, {
|
|
|
746
746
|
Drawing: () => Drawing,
|
|
747
747
|
DefaultTransformationData: () => DefaultTransformationData,
|
|
748
748
|
DefaultShapeData: () => DefaultShapeData,
|
|
749
|
+
Deck: () => Deck,
|
|
749
750
|
DEFAULT_SHAPE: () => DEFAULT_SHAPE,
|
|
750
751
|
CubicBezier: () => CubicBezier,
|
|
751
752
|
Counter: () => Counter,
|
|
@@ -753,6 +754,7 @@ __export(exports_browser, {
|
|
|
753
754
|
Connector: () => Connector2,
|
|
754
755
|
ConnectionLineWidths: () => ConnectionLineWidths,
|
|
755
756
|
Comment: () => Comment,
|
|
757
|
+
Card: () => Card,
|
|
756
758
|
Camera: () => Camera,
|
|
757
759
|
CURSORS_IDLE_CLEANUP_DELAY: () => CURSORS_IDLE_CLEANUP_DELAY,
|
|
758
760
|
CURSORS_ANIMATION_DURATION: () => CURSORS_ANIMATION_DURATION,
|
|
@@ -45585,7 +45587,9 @@ function registerItem({
|
|
|
45585
45587
|
const { itemType } = defaultData2;
|
|
45586
45588
|
itemFactories[itemType] = createItemFactory(item, defaultData2);
|
|
45587
45589
|
itemValidators[itemType] = createItemValidator(defaultData2);
|
|
45588
|
-
|
|
45590
|
+
if (toolData) {
|
|
45591
|
+
registeredTools[toolData.name] = toolData.tool;
|
|
45592
|
+
}
|
|
45589
45593
|
itemCommandFactories[itemType] = createItemCommandFactory(itemType);
|
|
45590
45594
|
}
|
|
45591
45595
|
function createItemFactory(item, defaultData2) {
|
|
@@ -45899,6 +45903,318 @@ registerItem({
|
|
|
45899
45903
|
defaultData: defaultCounterData,
|
|
45900
45904
|
toolData: { name: "AddCounter", tool: AddCounter }
|
|
45901
45905
|
});
|
|
45906
|
+
// src/utils.ts
|
|
45907
|
+
function throttle(func, delay) {
|
|
45908
|
+
let lastCall = 0;
|
|
45909
|
+
let timeoutId = null;
|
|
45910
|
+
return function(...args) {
|
|
45911
|
+
const now = Date.now();
|
|
45912
|
+
if (lastCall + delay <= now) {
|
|
45913
|
+
lastCall = now;
|
|
45914
|
+
func(...args);
|
|
45915
|
+
if (timeoutId) {
|
|
45916
|
+
clearTimeout(timeoutId);
|
|
45917
|
+
timeoutId = null;
|
|
45918
|
+
}
|
|
45919
|
+
} else if (!timeoutId) {
|
|
45920
|
+
timeoutId = setTimeout(() => {
|
|
45921
|
+
lastCall = Date.now();
|
|
45922
|
+
timeoutId = null;
|
|
45923
|
+
func(...args);
|
|
45924
|
+
}, delay - (now - lastCall));
|
|
45925
|
+
}
|
|
45926
|
+
};
|
|
45927
|
+
}
|
|
45928
|
+
|
|
45929
|
+
// src/Items/Examples/CardGame/Card/Card.ts
|
|
45930
|
+
var defaultCardData = {
|
|
45931
|
+
itemType: "Card",
|
|
45932
|
+
isOpen: false,
|
|
45933
|
+
name: "",
|
|
45934
|
+
isInDeck: false
|
|
45935
|
+
};
|
|
45936
|
+
var CARD_DIMENSIONS = { width: 250, height: 400 };
|
|
45937
|
+
|
|
45938
|
+
class Card extends BaseItem {
|
|
45939
|
+
subject = new Subject;
|
|
45940
|
+
name = "";
|
|
45941
|
+
isOpen = false;
|
|
45942
|
+
isInDeck = false;
|
|
45943
|
+
throttledBringToFront;
|
|
45944
|
+
image = null;
|
|
45945
|
+
backside = null;
|
|
45946
|
+
imageToRender = null;
|
|
45947
|
+
shouldUseCustomRender = false;
|
|
45948
|
+
constructor(board, id = "", defaultData2, name) {
|
|
45949
|
+
super(board, id, defaultCardData);
|
|
45950
|
+
this.name = name;
|
|
45951
|
+
this.createImages();
|
|
45952
|
+
this.throttledBringToFront = throttle(() => {
|
|
45953
|
+
this.board.bringToFront(this);
|
|
45954
|
+
}, 1000);
|
|
45955
|
+
this.transformation.subject.subscribe(() => {
|
|
45956
|
+
this.throttledBringToFront();
|
|
45957
|
+
this.updateMbr();
|
|
45958
|
+
this.updateImageToRender();
|
|
45959
|
+
this.subject.publish(this);
|
|
45960
|
+
});
|
|
45961
|
+
this.updateMbr();
|
|
45962
|
+
}
|
|
45963
|
+
createImages() {
|
|
45964
|
+
this.image = conf.documentFactory.createElement("img");
|
|
45965
|
+
this.backside = conf.documentFactory.createElement("img");
|
|
45966
|
+
this.image.src = `/Assets/Cards/${this.name}.png`;
|
|
45967
|
+
this.backside.src = `/Assets/Cards/backside.png`;
|
|
45968
|
+
this.image.onload = () => {
|
|
45969
|
+
this.subject.publish(this);
|
|
45970
|
+
};
|
|
45971
|
+
this.backside.onload = () => {
|
|
45972
|
+
this.subject.publish(this);
|
|
45973
|
+
};
|
|
45974
|
+
}
|
|
45975
|
+
setIsInDeck(isInDeck) {
|
|
45976
|
+
this.emit({
|
|
45977
|
+
class: "Card",
|
|
45978
|
+
method: "setIsInDeck",
|
|
45979
|
+
item: [this.getId()],
|
|
45980
|
+
newData: { isInDeck },
|
|
45981
|
+
prevData: { isInDeck: this.isInDeck }
|
|
45982
|
+
});
|
|
45983
|
+
}
|
|
45984
|
+
updateImageToRender() {
|
|
45985
|
+
this.imageToRender = this.backside;
|
|
45986
|
+
if (this.isOpen) {
|
|
45987
|
+
this.imageToRender = this.image;
|
|
45988
|
+
}
|
|
45989
|
+
}
|
|
45990
|
+
render(context, deckRenderData) {
|
|
45991
|
+
if (this.transformationRenderBlock || this.isInDeck && !deckRenderData) {
|
|
45992
|
+
return;
|
|
45993
|
+
}
|
|
45994
|
+
const ctx = context.ctx;
|
|
45995
|
+
if (this.imageToRender && this.imageToRender.complete) {
|
|
45996
|
+
ctx.save();
|
|
45997
|
+
let left = this.left;
|
|
45998
|
+
let top = this.top;
|
|
45999
|
+
if (deckRenderData) {
|
|
46000
|
+
left = deckRenderData.left + 2 * deckRenderData.cardPosition;
|
|
46001
|
+
top = deckRenderData.top;
|
|
46002
|
+
}
|
|
46003
|
+
ctx.drawImage(this.imageToRender, left, top, CARD_DIMENSIONS.width, CARD_DIMENSIONS.height);
|
|
46004
|
+
ctx.restore();
|
|
46005
|
+
}
|
|
46006
|
+
}
|
|
46007
|
+
updateMbr() {
|
|
46008
|
+
const { translateX, translateY, scaleX, scaleY } = this.transformation.matrix;
|
|
46009
|
+
this.left = translateX;
|
|
46010
|
+
this.top = translateY;
|
|
46011
|
+
this.right = this.left + CARD_DIMENSIONS.width * scaleX;
|
|
46012
|
+
this.bottom = this.top + CARD_DIMENSIONS.height * scaleY;
|
|
46013
|
+
}
|
|
46014
|
+
getMbr() {
|
|
46015
|
+
if (this.isInDeck) {
|
|
46016
|
+
return new Mbr(1e4, 1e4, 1e4, 1e4);
|
|
46017
|
+
}
|
|
46018
|
+
return super.getMbr();
|
|
46019
|
+
}
|
|
46020
|
+
getPath() {
|
|
46021
|
+
return new Path(this.getMbr().getLines());
|
|
46022
|
+
}
|
|
46023
|
+
renderHTML(documentFactory) {
|
|
46024
|
+
const div = documentFactory.createElement("card-item");
|
|
46025
|
+
return div;
|
|
46026
|
+
}
|
|
46027
|
+
deserialize(data) {
|
|
46028
|
+
super.deserialize(data);
|
|
46029
|
+
this.updateMbr();
|
|
46030
|
+
this.createImages();
|
|
46031
|
+
this.subject.publish(this);
|
|
46032
|
+
return this;
|
|
46033
|
+
}
|
|
46034
|
+
toggleIsOpen() {
|
|
46035
|
+
this.emit({
|
|
46036
|
+
class: "Card",
|
|
46037
|
+
method: "setIsOpen",
|
|
46038
|
+
item: [this.getId()],
|
|
46039
|
+
newData: { isOpen: !this.isOpen },
|
|
46040
|
+
prevData: { isOpen: this.isOpen }
|
|
46041
|
+
});
|
|
46042
|
+
}
|
|
46043
|
+
apply(op) {
|
|
46044
|
+
super.apply(op);
|
|
46045
|
+
switch (op.class) {
|
|
46046
|
+
case "Card":
|
|
46047
|
+
switch (op.method) {
|
|
46048
|
+
case "setIsOpen":
|
|
46049
|
+
this.isOpen = op.newData.isOpen;
|
|
46050
|
+
this.updateImageToRender();
|
|
46051
|
+
break;
|
|
46052
|
+
case "setIsInDeck":
|
|
46053
|
+
this.isInDeck = op.newData.isInDeck;
|
|
46054
|
+
break;
|
|
46055
|
+
}
|
|
46056
|
+
break;
|
|
46057
|
+
}
|
|
46058
|
+
this.subject.publish(this);
|
|
46059
|
+
}
|
|
46060
|
+
}
|
|
46061
|
+
registerItem({
|
|
46062
|
+
item: Card,
|
|
46063
|
+
defaultData: defaultCardData
|
|
46064
|
+
});
|
|
46065
|
+
// src/Items/Examples/CardGame/Deck/Deck.ts
|
|
46066
|
+
var defaultDeckData = {
|
|
46067
|
+
itemType: "Deck",
|
|
46068
|
+
cardIds: []
|
|
46069
|
+
};
|
|
46070
|
+
|
|
46071
|
+
class Deck extends BaseItem {
|
|
46072
|
+
subject = new Subject;
|
|
46073
|
+
shouldUseCustomRender = false;
|
|
46074
|
+
cardIds = [];
|
|
46075
|
+
cards = [];
|
|
46076
|
+
constructor(board, id = "", defaultData2, cards) {
|
|
46077
|
+
super(board, id, defaultDeckData);
|
|
46078
|
+
if (cards) {
|
|
46079
|
+
this.cards = cards;
|
|
46080
|
+
cards.forEach((card) => card.setIsInDeck(true));
|
|
46081
|
+
this.transformation.matrix = cards[cards.length - 1].transformation.matrix;
|
|
46082
|
+
this.cardIds = cards.map((card) => card.getId());
|
|
46083
|
+
}
|
|
46084
|
+
this.transformation.subject.subscribe(() => {
|
|
46085
|
+
this.updateMbr();
|
|
46086
|
+
this.subject.publish(this);
|
|
46087
|
+
});
|
|
46088
|
+
this.updateMbr();
|
|
46089
|
+
}
|
|
46090
|
+
getDeck() {
|
|
46091
|
+
return this.cards;
|
|
46092
|
+
}
|
|
46093
|
+
getTopCard() {
|
|
46094
|
+
const cardId = this.cardIds[this.cardIds.length - 1];
|
|
46095
|
+
return this.getCards([cardId])[0];
|
|
46096
|
+
}
|
|
46097
|
+
getBottomCard() {
|
|
46098
|
+
const cardId = this.cardIds[0];
|
|
46099
|
+
return this.getCards([cardId])[0];
|
|
46100
|
+
}
|
|
46101
|
+
getRandomCard() {
|
|
46102
|
+
const cardId = this.cardIds[Math.ceil(Math.random() * this.cardIds.length) - 1];
|
|
46103
|
+
return this.getCards([cardId])[0];
|
|
46104
|
+
}
|
|
46105
|
+
getCards(cardIds) {
|
|
46106
|
+
const cards = this.findCardsOnBoard(cardIds);
|
|
46107
|
+
this.removeCards(cards);
|
|
46108
|
+
return cards;
|
|
46109
|
+
}
|
|
46110
|
+
findCardsOnBoard(cardIds) {
|
|
46111
|
+
return cardIds.map((cardId) => {
|
|
46112
|
+
return this.board.items.getById(cardId);
|
|
46113
|
+
}).filter((card) => !!card);
|
|
46114
|
+
}
|
|
46115
|
+
updateCards() {
|
|
46116
|
+
if (this.cardIds.length === this.cards.length) {
|
|
46117
|
+
return this.cards;
|
|
46118
|
+
}
|
|
46119
|
+
this.cards = this.findCardsOnBoard(this.cardIds);
|
|
46120
|
+
return this.cards;
|
|
46121
|
+
}
|
|
46122
|
+
shuffleDeck() {
|
|
46123
|
+
const shuffled = [...this.cardIds];
|
|
46124
|
+
for (let i = shuffled.length - 1;i > 0; i--) {
|
|
46125
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
46126
|
+
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
|
|
46127
|
+
}
|
|
46128
|
+
const cards = this.findCardsOnBoard(shuffled);
|
|
46129
|
+
this.addCards(cards, true);
|
|
46130
|
+
}
|
|
46131
|
+
addCards(cards, shouldReplaceExistingCards = false) {
|
|
46132
|
+
cards.forEach((card) => {
|
|
46133
|
+
card.setIsInDeck(true);
|
|
46134
|
+
});
|
|
46135
|
+
this.board.bringToFront(cards);
|
|
46136
|
+
this.emit({
|
|
46137
|
+
class: "Deck",
|
|
46138
|
+
method: "addCards",
|
|
46139
|
+
item: [this.getId()],
|
|
46140
|
+
newData: {
|
|
46141
|
+
cardIds: cards.map((card) => card.getId()),
|
|
46142
|
+
shouldReplaceExistingCards
|
|
46143
|
+
},
|
|
46144
|
+
prevData: { cardIds: this.cardIds, shouldReplaceExistingCards }
|
|
46145
|
+
});
|
|
46146
|
+
}
|
|
46147
|
+
removeCards(cards) {
|
|
46148
|
+
cards.forEach((card) => {
|
|
46149
|
+
card.setIsInDeck(false);
|
|
46150
|
+
});
|
|
46151
|
+
this.emit({
|
|
46152
|
+
class: "Deck",
|
|
46153
|
+
method: "removeCards",
|
|
46154
|
+
item: [this.getId()],
|
|
46155
|
+
newData: { cardIds: cards.map((card) => card.getId()) },
|
|
46156
|
+
prevData: { cardIds: this.cardIds }
|
|
46157
|
+
});
|
|
46158
|
+
}
|
|
46159
|
+
apply(op) {
|
|
46160
|
+
super.apply(op);
|
|
46161
|
+
switch (op.class) {
|
|
46162
|
+
case "Deck":
|
|
46163
|
+
switch (op.method) {
|
|
46164
|
+
case "addCards":
|
|
46165
|
+
if (op.newData.shouldReplaceExistingCards) {
|
|
46166
|
+
this.cardIds = op.newData.cardIds;
|
|
46167
|
+
this.cards = this.findCardsOnBoard(this.cardIds);
|
|
46168
|
+
} else {
|
|
46169
|
+
this.cardIds = [
|
|
46170
|
+
...op.newData.cardIds,
|
|
46171
|
+
...this.cardIds
|
|
46172
|
+
];
|
|
46173
|
+
this.updateCards();
|
|
46174
|
+
this.updateMbr();
|
|
46175
|
+
}
|
|
46176
|
+
break;
|
|
46177
|
+
case "removeCards":
|
|
46178
|
+
this.cardIds = this.cardIds.filter((card) => {
|
|
46179
|
+
return !op.newData.cardIds.includes(card);
|
|
46180
|
+
});
|
|
46181
|
+
this.updateCards();
|
|
46182
|
+
this.updateMbr();
|
|
46183
|
+
break;
|
|
46184
|
+
}
|
|
46185
|
+
break;
|
|
46186
|
+
}
|
|
46187
|
+
this.subject.publish(this);
|
|
46188
|
+
}
|
|
46189
|
+
updateMbr() {
|
|
46190
|
+
const { translateX, translateY, scaleX, scaleY } = this.transformation.matrix;
|
|
46191
|
+
this.left = translateX;
|
|
46192
|
+
this.top = translateY;
|
|
46193
|
+
this.right = this.left + CARD_DIMENSIONS.width * scaleX + 2 * this.cardIds.length;
|
|
46194
|
+
this.bottom = this.top + CARD_DIMENSIONS.height * scaleY;
|
|
46195
|
+
}
|
|
46196
|
+
deserialize(data) {
|
|
46197
|
+
super.deserialize(data);
|
|
46198
|
+
this.updateCards();
|
|
46199
|
+
return this;
|
|
46200
|
+
}
|
|
46201
|
+
render(context) {
|
|
46202
|
+
if (this.transformationRenderBlock) {
|
|
46203
|
+
return;
|
|
46204
|
+
}
|
|
46205
|
+
this.cards.forEach((card, index2) => {
|
|
46206
|
+
card.render(context, {
|
|
46207
|
+
top: this.top,
|
|
46208
|
+
left: this.left,
|
|
46209
|
+
cardPosition: index2 + 1
|
|
46210
|
+
});
|
|
46211
|
+
});
|
|
46212
|
+
}
|
|
46213
|
+
}
|
|
46214
|
+
registerItem({
|
|
46215
|
+
item: Deck,
|
|
46216
|
+
defaultData: defaultDeckData
|
|
46217
|
+
});
|
|
45902
46218
|
// src/Pointer/Cursor.ts
|
|
45903
46219
|
var defaultCursors = [
|
|
45904
46220
|
"default",
|
|
@@ -46411,27 +46727,6 @@ class Camera {
|
|
|
46411
46727
|
requestAnimationFrame(animate);
|
|
46412
46728
|
}
|
|
46413
46729
|
}
|
|
46414
|
-
function throttle(func, delay) {
|
|
46415
|
-
let lastCall = 0;
|
|
46416
|
-
let timeoutId = null;
|
|
46417
|
-
return function(...args) {
|
|
46418
|
-
const now = Date.now();
|
|
46419
|
-
if (lastCall + delay <= now) {
|
|
46420
|
-
lastCall = now;
|
|
46421
|
-
func(...args);
|
|
46422
|
-
if (timeoutId) {
|
|
46423
|
-
clearTimeout(timeoutId);
|
|
46424
|
-
timeoutId = null;
|
|
46425
|
-
}
|
|
46426
|
-
} else if (!timeoutId) {
|
|
46427
|
-
timeoutId = setTimeout(() => {
|
|
46428
|
-
lastCall = Date.now();
|
|
46429
|
-
timeoutId = null;
|
|
46430
|
-
func(...args);
|
|
46431
|
-
}, delay - (now - lastCall));
|
|
46432
|
-
}
|
|
46433
|
-
};
|
|
46434
|
-
}
|
|
46435
46730
|
// src/hotkeys.json
|
|
46436
46731
|
var hotkeys_default = {
|
|
46437
46732
|
select: {
|