microboard-temp 0.4.9 → 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.
@@ -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,
@@ -37328,12 +37330,19 @@ class Shape extends BaseItem {
37328
37330
  this.shapeType = data.shapeType;
37329
37331
  this.initPath();
37330
37332
  }
37333
+ if (data.linkTo) {
37334
+ this.linkTo.deserialize(data.linkTo);
37335
+ }
37331
37336
  this.backgroundColor = data.backgroundColor ?? this.backgroundColor;
37332
37337
  this.backgroundOpacity = data.backgroundOpacity ?? this.backgroundOpacity;
37333
37338
  this.borderColor = data.borderColor ?? this.borderColor;
37334
37339
  this.borderOpacity = data.borderOpacity ?? this.borderOpacity;
37335
37340
  this.borderStyle = data.borderStyle ?? this.borderStyle;
37336
37341
  this.borderWidth = data.borderWidth ?? this.borderWidth;
37342
+ if (data.transformation) {
37343
+ this.transformation.deserialize(data.transformation);
37344
+ this.transformPath();
37345
+ }
37337
37346
  if (data.text) {
37338
37347
  this.text.deserialize(data.text);
37339
37348
  }
@@ -45578,7 +45587,9 @@ function registerItem({
45578
45587
  const { itemType } = defaultData2;
45579
45588
  itemFactories[itemType] = createItemFactory(item, defaultData2);
45580
45589
  itemValidators[itemType] = createItemValidator(defaultData2);
45581
- registeredTools[toolData.name] = toolData.tool;
45590
+ if (toolData) {
45591
+ registeredTools[toolData.name] = toolData.tool;
45592
+ }
45582
45593
  itemCommandFactories[itemType] = createItemCommandFactory(itemType);
45583
45594
  }
45584
45595
  function createItemFactory(item, defaultData2) {
@@ -45892,6 +45903,318 @@ registerItem({
45892
45903
  defaultData: defaultCounterData,
45893
45904
  toolData: { name: "AddCounter", tool: AddCounter }
45894
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
+ });
45895
46218
  // src/Pointer/Cursor.ts
45896
46219
  var defaultCursors = [
45897
46220
  "default",
@@ -46404,27 +46727,6 @@ class Camera {
46404
46727
  requestAnimationFrame(animate);
46405
46728
  }
46406
46729
  }
46407
- function throttle(func, delay) {
46408
- let lastCall = 0;
46409
- let timeoutId = null;
46410
- return function(...args) {
46411
- const now = Date.now();
46412
- if (lastCall + delay <= now) {
46413
- lastCall = now;
46414
- func(...args);
46415
- if (timeoutId) {
46416
- clearTimeout(timeoutId);
46417
- timeoutId = null;
46418
- }
46419
- } else if (!timeoutId) {
46420
- timeoutId = setTimeout(() => {
46421
- lastCall = Date.now();
46422
- timeoutId = null;
46423
- func(...args);
46424
- }, delay - (now - lastCall));
46425
- }
46426
- };
46427
- }
46428
46730
  // src/hotkeys.json
46429
46731
  var hotkeys_default = {
46430
46732
  select: {