microboard-temp 0.4.68 → 0.4.70

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/esm/node.js CHANGED
@@ -50099,8 +50099,7 @@ var defaultCardData = {
50099
50099
  itemType: "Card",
50100
50100
  isOpen: false,
50101
50101
  faceUrl: "",
50102
- backsideUrl: "",
50103
- isInDeck: false
50102
+ backsideUrl: ""
50104
50103
  };
50105
50104
  var CARD_DIMENSIONS = { width: 250, height: 400 };
50106
50105
 
@@ -50109,7 +50108,6 @@ class Card extends BaseItem {
50109
50108
  faceUrl = "";
50110
50109
  backsideUrl = "";
50111
50110
  isOpen = false;
50112
- isInDeck = false;
50113
50111
  throttledBringToFront;
50114
50112
  face = null;
50115
50113
  backside = null;
@@ -50145,35 +50143,20 @@ class Card extends BaseItem {
50145
50143
  };
50146
50144
  this.updateImageToRender();
50147
50145
  }
50148
- setIsInDeck(isInDeck) {
50149
- this.emit({
50150
- class: "Card",
50151
- method: "setIsInDeck",
50152
- item: [this.getId()],
50153
- newData: { isInDeck },
50154
- prevData: { isInDeck: this.isInDeck }
50155
- });
50156
- }
50157
50146
  updateImageToRender() {
50158
50147
  this.imageToRender = this.backside;
50159
50148
  if (this.isOpen) {
50160
50149
  this.imageToRender = this.face;
50161
50150
  }
50162
50151
  }
50163
- render(context, deckRenderData) {
50164
- if (this.transformationRenderBlock || this.isInDeck && !deckRenderData) {
50152
+ render(context) {
50153
+ if (this.transformationRenderBlock) {
50165
50154
  return;
50166
50155
  }
50167
50156
  const ctx = context.ctx;
50168
50157
  if (this.imageToRender && this.imageToRender.complete) {
50169
50158
  ctx.save();
50170
- let left = this.left;
50171
- let top = this.top;
50172
- if (deckRenderData) {
50173
- left = deckRenderData.left + 2 * deckRenderData.cardPosition;
50174
- top = deckRenderData.top;
50175
- }
50176
- ctx.drawImage(this.imageToRender, left, top, CARD_DIMENSIONS.width, CARD_DIMENSIONS.height);
50159
+ ctx.drawImage(this.imageToRender, this.left, this.top, CARD_DIMENSIONS.width, CARD_DIMENSIONS.height);
50177
50160
  ctx.restore();
50178
50161
  }
50179
50162
  }
@@ -50184,12 +50167,6 @@ class Card extends BaseItem {
50184
50167
  this.right = this.left + CARD_DIMENSIONS.width * scaleX;
50185
50168
  this.bottom = this.top + CARD_DIMENSIONS.height * scaleY;
50186
50169
  }
50187
- getMbr() {
50188
- if (this.isInDeck) {
50189
- return new Mbr(1e4, 1e4, 1e4, 1e4);
50190
- }
50191
- return super.getMbr();
50192
- }
50193
50170
  getPath() {
50194
50171
  return new Path(this.getMbr().getLines());
50195
50172
  }
@@ -50222,9 +50199,6 @@ class Card extends BaseItem {
50222
50199
  this.isOpen = op.newData.isOpen;
50223
50200
  this.updateImageToRender();
50224
50201
  break;
50225
- case "setIsInDeck":
50226
- this.isInDeck = op.newData.isInDeck;
50227
- break;
50228
50202
  }
50229
50203
  break;
50230
50204
  }
@@ -50237,22 +50211,17 @@ registerItem({
50237
50211
  });
50238
50212
  // src/Items/Examples/CardGame/Deck/Deck.ts
50239
50213
  var defaultDeckData = {
50240
- itemType: "Deck",
50241
- cardIds: []
50214
+ itemType: "Deck"
50242
50215
  };
50243
50216
 
50244
50217
  class Deck extends BaseItem {
50245
50218
  subject = new Subject;
50246
50219
  shouldUseCustomRender = false;
50247
- cardIds = [];
50248
- cards = [];
50249
50220
  constructor(board, id = "", defaultData2, cards) {
50250
- super(board, id, defaultDeckData);
50221
+ super(board, id, defaultDeckData, true);
50251
50222
  if (cards) {
50252
- this.cards = cards;
50253
- cards.forEach((card) => card.setIsInDeck(true));
50254
50223
  this.transformation.matrix = cards[cards.length - 1].transformation.matrix;
50255
- this.cardIds = cards.map((card) => card.getId());
50224
+ this.applyAddChildren(cards.map((card) => card.getId()));
50256
50225
  }
50257
50226
  this.transformation.subject.subscribe(() => {
50258
50227
  this.updateMbr();
@@ -50260,128 +50229,113 @@ class Deck extends BaseItem {
50260
50229
  });
50261
50230
  this.updateMbr();
50262
50231
  }
50232
+ applyAddChildren(childIds) {
50233
+ if (!this.index) {
50234
+ return;
50235
+ }
50236
+ childIds.forEach((childId) => {
50237
+ const foundItem = this.board.items.getById(childId);
50238
+ if (this.parent !== childId && this.getId() !== childId) {
50239
+ if (!this.index?.getById(childId) && foundItem && foundItem.itemType === "Card") {
50240
+ foundItem.transformation.apply({
50241
+ class: "Transformation",
50242
+ method: "translateTo",
50243
+ item: [this.id],
50244
+ x: this.left + (this.index?.list().length || 0) * 2,
50245
+ y: this.top
50246
+ });
50247
+ foundItem.parent = this.getId();
50248
+ this.board.items.index.remove(foundItem);
50249
+ this.index?.insert(foundItem);
50250
+ }
50251
+ }
50252
+ });
50253
+ this.updateMbr();
50254
+ this.subject.publish(this);
50255
+ }
50256
+ applyRemoveChildren(childIds) {
50257
+ if (!this.index) {
50258
+ return;
50259
+ }
50260
+ childIds.forEach((childId) => {
50261
+ const foundItem = this.index?.getById(childId);
50262
+ if (this.parent !== childId && this.getId() !== childId) {
50263
+ if (foundItem) {
50264
+ foundItem.transformation.apply({
50265
+ class: "Transformation",
50266
+ method: "translateTo",
50267
+ item: [this.id],
50268
+ x: this.left,
50269
+ y: this.top - this.getHeight() / 2
50270
+ });
50271
+ foundItem.parent = "Board";
50272
+ this.index?.remove(foundItem);
50273
+ this.board.items.index.insert(foundItem);
50274
+ }
50275
+ }
50276
+ });
50277
+ this.updateMbr();
50278
+ this.subject.publish(this);
50279
+ }
50263
50280
  getDeck() {
50264
- return this.cards;
50281
+ return this.index?.list() || [];
50265
50282
  }
50266
50283
  getTopCard() {
50267
- const cardId = this.cardIds[this.cardIds.length - 1];
50268
- return this.getCards([cardId])[0];
50284
+ const card = this.index?.list()[this.index?.list().length - 1];
50285
+ if (card) {
50286
+ this.removeChildItems(card);
50287
+ return card;
50288
+ }
50269
50289
  }
50270
50290
  getBottomCard() {
50271
- const cardId = this.cardIds[0];
50272
- return this.getCards([cardId])[0];
50291
+ const card = this.index?.list()[0];
50292
+ if (card) {
50293
+ this.removeChildItems(card);
50294
+ return card;
50295
+ }
50273
50296
  }
50274
50297
  getRandomCard() {
50275
- const cardId = this.cardIds[Math.ceil(Math.random() * this.cardIds.length) - 1];
50276
- return this.getCards([cardId])[0];
50277
- }
50278
- getCards(cardIds) {
50279
- const cards = this.findCardsOnBoard(cardIds);
50280
- this.removeCards(cards);
50281
- return cards;
50282
- }
50283
- findCardsOnBoard(cardIds) {
50284
- return cardIds.map((cardId) => {
50285
- return this.board.items.getById(cardId);
50286
- }).filter((card) => !!card);
50287
- }
50288
- updateCards() {
50289
- if (this.cardIds.length === this.cards.length) {
50290
- return this.cards;
50298
+ const card = this.index?.list()[Math.floor(Math.random() * this.index?.list().length)];
50299
+ if (card) {
50300
+ this.removeChildItems(card);
50301
+ return card;
50291
50302
  }
50292
- this.cards = this.findCardsOnBoard(this.cardIds);
50293
- return this.cards;
50294
50303
  }
50295
50304
  shuffleDeck() {
50296
- const shuffled = [...this.cardIds];
50305
+ if (!this.index) {
50306
+ return;
50307
+ }
50308
+ const shuffled = [...this.index.list()];
50297
50309
  for (let i = shuffled.length - 1;i > 0; i--) {
50298
50310
  const j = Math.floor(Math.random() * (i + 1));
50299
50311
  [shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
50300
50312
  }
50301
- const cards = this.findCardsOnBoard(shuffled);
50302
- this.addCards(cards, true);
50303
- }
50304
- addCards(cards, shouldReplaceExistingCards = false) {
50305
- cards.forEach((card) => {
50306
- card.setIsInDeck(true);
50307
- });
50308
- this.board.bringToFront(cards);
50309
- this.emit({
50310
- class: "Deck",
50311
- method: "addCards",
50312
- item: [this.getId()],
50313
- newData: {
50314
- cardIds: cards.map((card) => card.getId()),
50315
- shouldReplaceExistingCards
50316
- },
50317
- prevData: { cardIds: this.cardIds, shouldReplaceExistingCards }
50318
- });
50319
- }
50320
- removeCards(cards) {
50321
- cards.forEach((card) => {
50322
- card.setIsInDeck(false);
50323
- });
50324
- this.emit({
50325
- class: "Deck",
50326
- method: "removeCards",
50327
- item: [this.getId()],
50328
- newData: { cardIds: cards.map((card) => card.getId()) },
50329
- prevData: { cardIds: this.cardIds }
50330
- });
50313
+ this.index.clear();
50314
+ shuffled.forEach((card) => this.index.insert(card));
50331
50315
  }
50332
50316
  apply(op) {
50333
50317
  super.apply(op);
50334
- switch (op.class) {
50335
- case "Deck":
50336
- switch (op.method) {
50337
- case "addCards":
50338
- if (op.newData.shouldReplaceExistingCards) {
50339
- this.cardIds = op.newData.cardIds;
50340
- this.cards = this.findCardsOnBoard(this.cardIds);
50341
- } else {
50342
- this.cardIds = [
50343
- ...op.newData.cardIds,
50344
- ...this.cardIds
50345
- ];
50346
- this.updateCards();
50347
- this.updateMbr();
50348
- }
50349
- break;
50350
- case "removeCards":
50351
- this.cardIds = this.cardIds.filter((card) => {
50352
- return !op.newData.cardIds.includes(card);
50353
- });
50354
- this.updateCards();
50355
- this.updateMbr();
50356
- break;
50357
- }
50358
- break;
50359
- }
50360
50318
  this.subject.publish(this);
50361
50319
  }
50362
50320
  updateMbr() {
50363
- const { translateX, translateY, scaleX, scaleY } = this.transformation.matrix;
50321
+ const { translateX, translateY } = this.transformation.matrix;
50322
+ const { right, bottom } = this.index.getMbr();
50364
50323
  this.left = translateX;
50365
50324
  this.top = translateY;
50366
- this.right = this.left + CARD_DIMENSIONS.width * scaleX + 2 * this.cardIds.length;
50367
- this.bottom = this.top + CARD_DIMENSIONS.height * scaleY;
50325
+ this.right = right;
50326
+ this.bottom = bottom;
50368
50327
  }
50369
50328
  deserialize(data) {
50370
50329
  super.deserialize(data);
50371
- this.updateCards();
50330
+ this.updateMbr();
50331
+ this.subject.publish(this);
50372
50332
  return this;
50373
50333
  }
50374
50334
  render(context) {
50375
50335
  if (this.transformationRenderBlock) {
50376
50336
  return;
50377
50337
  }
50378
- this.cards.forEach((card, index2) => {
50379
- card.render(context, {
50380
- top: this.top,
50381
- left: this.left,
50382
- cardPosition: index2 + 1
50383
- });
50384
- });
50338
+ super.render(context);
50385
50339
  }
50386
50340
  }
50387
50341
  registerItem({
@@ -50697,6 +50651,8 @@ class Hand extends BaseItem {
50697
50651
  ownerId;
50698
50652
  subject = new Subject;
50699
50653
  path;
50654
+ borderWidth = 1;
50655
+ backgroundColor = "#FFFFFF";
50700
50656
  constructor(board, id = "", ownerId = "") {
50701
50657
  super(board, id, defaultHandData, true);
50702
50658
  this.ownerId = ownerId;
@@ -50710,8 +50666,74 @@ class Hand extends BaseItem {
50710
50666
  }
50711
50667
  apply(op) {
50712
50668
  super.apply(op);
50669
+ switch (op.class) {
50670
+ case "Hand":
50671
+ switch (op.method) {
50672
+ case "setBorderWidth":
50673
+ this.applyBorderWidth(op.newData.borderWidth);
50674
+ break;
50675
+ case "setBackgroundColor":
50676
+ this.applyBackgroundColor(op.newData.backgroundColor);
50677
+ break;
50678
+ case "setBorderColor":
50679
+ this.applyBorderColor(op.newData.borderColor);
50680
+ break;
50681
+ }
50682
+ break;
50683
+ }
50713
50684
  this.subject.publish(this);
50714
50685
  }
50686
+ getBackgroundColor() {
50687
+ return this.backgroundColor;
50688
+ }
50689
+ getBorderStyle() {
50690
+ return this.borderStyle;
50691
+ }
50692
+ getStrokeColor() {
50693
+ return this.borderColor;
50694
+ }
50695
+ getStrokeWidth() {
50696
+ return this.borderWidth;
50697
+ }
50698
+ applyBackgroundColor(backgroundColor) {
50699
+ this.backgroundColor = backgroundColor;
50700
+ this.path.setBackgroundColor(backgroundColor);
50701
+ }
50702
+ setBackgroundColor(backgroundColor) {
50703
+ this.emit({
50704
+ class: "Dice",
50705
+ method: "setBackgroundColor",
50706
+ item: [this.getId()],
50707
+ newData: { backgroundColor },
50708
+ prevData: { backgroundColor: this.backgroundColor }
50709
+ });
50710
+ }
50711
+ applyBorderWidth(borderWidth) {
50712
+ this.borderWidth = borderWidth;
50713
+ this.path.setBorderWidth(borderWidth);
50714
+ }
50715
+ setBorderWidth(borderWidth) {
50716
+ this.emit({
50717
+ class: "Dice",
50718
+ method: "setBorderWidth",
50719
+ item: [this.getId()],
50720
+ newData: { borderWidth },
50721
+ prevData: { borderWidth: this.borderWidth }
50722
+ });
50723
+ }
50724
+ applyBorderColor(borderColor) {
50725
+ this.borderColor = borderColor;
50726
+ this.path.setBorderColor(borderColor);
50727
+ }
50728
+ setBorderColor(borderColor) {
50729
+ this.emit({
50730
+ class: "Dice",
50731
+ method: "setBorderColor",
50732
+ item: [this.getId()],
50733
+ newData: { borderColor },
50734
+ prevData: { borderColor: this.borderColor }
50735
+ });
50736
+ }
50715
50737
  applyOwnerId(ownerId) {
50716
50738
  this.ownerId = ownerId;
50717
50739
  }
@@ -50720,6 +50742,7 @@ class Hand extends BaseItem {
50720
50742
  this.path.transform(this.transformation.matrix);
50721
50743
  this.path.setBackgroundColor(this.backgroundColor);
50722
50744
  this.path.setBorderColor(this.borderColor);
50745
+ this.path.setBorderWidth(this.borderWidth);
50723
50746
  }
50724
50747
  updateMbr() {
50725
50748
  const { left, top, right, bottom } = this.path.getMbr();
@@ -6,12 +6,6 @@ import { Path } from "Items/Path/Path";
6
6
  import { Subject } from "Subject";
7
7
  import { Paths } from "Items/Path/Paths";
8
8
  import { CardOperation } from "Items/Examples/CardGame/Card/CardOperation";
9
- import { Mbr } from "Items/Mbr/Mbr";
10
- export type DeckRenderData = {
11
- left: number;
12
- top: number;
13
- cardPosition: number;
14
- };
15
9
  export declare const defaultCardData: BaseItemData;
16
10
  export declare const CARD_DIMENSIONS: {
17
11
  width: number;
@@ -22,7 +16,6 @@ export declare class Card extends BaseItem {
22
16
  private faceUrl;
23
17
  private backsideUrl;
24
18
  private isOpen;
25
- private isInDeck;
26
19
  private throttledBringToFront;
27
20
  face: HTMLImageElement | null;
28
21
  backside: HTMLImageElement | null;
@@ -33,11 +26,9 @@ export declare class Card extends BaseItem {
33
26
  backsideUrl: string;
34
27
  });
35
28
  createImages(): void;
36
- setIsInDeck(isInDeck: boolean): void;
37
29
  updateImageToRender(): void;
38
- render(context: DrawingContext, deckRenderData?: DeckRenderData): void;
30
+ render(context: DrawingContext): void;
39
31
  updateMbr(): void;
40
- getMbr(): Mbr;
41
32
  getPath(): Path | Paths;
42
33
  renderHTML(documentFactory: DocumentFactory): HTMLElement;
43
34
  deserialize(data: SerializedItemData): this;
@@ -8,19 +8,14 @@ export declare const defaultDeckData: BaseItemData;
8
8
  export declare class Deck extends BaseItem {
9
9
  readonly subject: Subject<Deck>;
10
10
  shouldUseCustomRender: boolean;
11
- cardIds: string[];
12
- cards: Card[];
13
11
  constructor(board: Board, id?: string, defaultData?: BaseItemData, cards?: Card[]);
12
+ applyAddChildren(childIds: string[]): void;
13
+ applyRemoveChildren(childIds: string[]): void;
14
14
  getDeck(): Card[];
15
15
  getTopCard(): Card | undefined;
16
16
  getBottomCard(): Card | undefined;
17
17
  getRandomCard(): Card | undefined;
18
- private getCards;
19
- private findCardsOnBoard;
20
- updateCards(): Card[];
21
18
  shuffleDeck(): void;
22
- addCards(cards: Card[], shouldReplaceExistingCards?: boolean): void;
23
- removeCards(cards: Card[]): void;
24
19
  apply(op: DeckOperation): void;
25
20
  updateMbr(): void;
26
21
  deserialize(data: SerializedItemData): this;
@@ -2,14 +2,27 @@ import { BaseItem, BaseItemData, SerializedItemData } from "Items/BaseItem/BaseI
2
2
  import { Board } from "Board";
3
3
  import { Subject } from "Subject";
4
4
  import { DrawingContext } from "Items/DrawingContext";
5
- import { DeckOperation } from "Items/Examples/CardGame/Deck/DeckOperation";
5
+ import { BorderWidth } from "../../../Path";
6
+ import { HandOperation } from "./HandOperation";
6
7
  export declare const defaultHandData: BaseItemData;
7
8
  export declare class Hand extends BaseItem {
8
9
  private ownerId;
9
10
  readonly subject: Subject<Hand>;
10
11
  private path;
12
+ private borderWidth;
13
+ backgroundColor: string;
11
14
  constructor(board: Board, id?: string, ownerId?: string);
12
- apply(op: DeckOperation): void;
15
+ apply(op: HandOperation): void;
16
+ getBackgroundColor(): string;
17
+ getBorderStyle(): string;
18
+ getStrokeColor(): string;
19
+ getStrokeWidth(): number;
20
+ private applyBackgroundColor;
21
+ setBackgroundColor(backgroundColor: string): void;
22
+ private applyBorderWidth;
23
+ setBorderWidth(borderWidth: BorderWidth): void;
24
+ private applyBorderColor;
25
+ setBorderColor(borderColor: string): void;
13
26
  applyOwnerId(ownerId: string): void;
14
27
  private transformPath;
15
28
  updateMbr(): void;
@@ -0,0 +1,21 @@
1
+ import { BaseOperation } from "Events/EventsOperations";
2
+ export type HandOperation = SetBackgroundColor | SetBorderColor | SetBorderWidth;
3
+ interface SetBackgroundColor extends BaseOperation<{
4
+ backgroundColor: string;
5
+ }> {
6
+ class: "Hand";
7
+ method: "setBackgroundColor";
8
+ }
9
+ interface SetBorderColor extends BaseOperation<{
10
+ borderColor: string;
11
+ }> {
12
+ class: "Hand";
13
+ method: "setBorderColor";
14
+ }
15
+ export interface SetBorderWidth extends BaseOperation<{
16
+ borderWidth: number;
17
+ }> {
18
+ class: "Hand";
19
+ method: "setBorderWidth";
20
+ }
21
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "microboard-temp",
3
- "version": "0.4.68",
3
+ "version": "0.4.70",
4
4
  "description": "A flexible interactive whiteboard library",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",