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.
@@ -37181,12 +37181,19 @@ class Shape extends BaseItem {
37181
37181
  this.shapeType = data.shapeType;
37182
37182
  this.initPath();
37183
37183
  }
37184
+ if (data.linkTo) {
37185
+ this.linkTo.deserialize(data.linkTo);
37186
+ }
37184
37187
  this.backgroundColor = data.backgroundColor ?? this.backgroundColor;
37185
37188
  this.backgroundOpacity = data.backgroundOpacity ?? this.backgroundOpacity;
37186
37189
  this.borderColor = data.borderColor ?? this.borderColor;
37187
37190
  this.borderOpacity = data.borderOpacity ?? this.borderOpacity;
37188
37191
  this.borderStyle = data.borderStyle ?? this.borderStyle;
37189
37192
  this.borderWidth = data.borderWidth ?? this.borderWidth;
37193
+ if (data.transformation) {
37194
+ this.transformation.deserialize(data.transformation);
37195
+ this.transformPath();
37196
+ }
37190
37197
  if (data.text) {
37191
37198
  this.text.deserialize(data.text);
37192
37199
  }
@@ -45431,7 +45438,9 @@ function registerItem({
45431
45438
  const { itemType } = defaultData2;
45432
45439
  itemFactories[itemType] = createItemFactory(item, defaultData2);
45433
45440
  itemValidators[itemType] = createItemValidator(defaultData2);
45434
- registeredTools[toolData.name] = toolData.tool;
45441
+ if (toolData) {
45442
+ registeredTools[toolData.name] = toolData.tool;
45443
+ }
45435
45444
  itemCommandFactories[itemType] = createItemCommandFactory(itemType);
45436
45445
  }
45437
45446
  function createItemFactory(item, defaultData2) {
@@ -45745,6 +45754,318 @@ registerItem({
45745
45754
  defaultData: defaultCounterData,
45746
45755
  toolData: { name: "AddCounter", tool: AddCounter }
45747
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
+ name: "",
45785
+ isInDeck: false
45786
+ };
45787
+ var CARD_DIMENSIONS = { width: 250, height: 400 };
45788
+
45789
+ class Card extends BaseItem {
45790
+ subject = new Subject;
45791
+ name = "";
45792
+ isOpen = false;
45793
+ isInDeck = false;
45794
+ throttledBringToFront;
45795
+ image = null;
45796
+ backside = null;
45797
+ imageToRender = null;
45798
+ shouldUseCustomRender = false;
45799
+ constructor(board, id = "", defaultData2, name) {
45800
+ super(board, id, defaultCardData);
45801
+ this.name = name;
45802
+ this.createImages();
45803
+ this.throttledBringToFront = throttle(() => {
45804
+ this.board.bringToFront(this);
45805
+ }, 1000);
45806
+ this.transformation.subject.subscribe(() => {
45807
+ this.throttledBringToFront();
45808
+ this.updateMbr();
45809
+ this.updateImageToRender();
45810
+ this.subject.publish(this);
45811
+ });
45812
+ this.updateMbr();
45813
+ }
45814
+ createImages() {
45815
+ this.image = conf.documentFactory.createElement("img");
45816
+ this.backside = conf.documentFactory.createElement("img");
45817
+ this.image.src = `/Assets/Cards/${this.name}.png`;
45818
+ this.backside.src = `/Assets/Cards/backside.png`;
45819
+ this.image.onload = () => {
45820
+ this.subject.publish(this);
45821
+ };
45822
+ this.backside.onload = () => {
45823
+ this.subject.publish(this);
45824
+ };
45825
+ }
45826
+ setIsInDeck(isInDeck) {
45827
+ this.emit({
45828
+ class: "Card",
45829
+ method: "setIsInDeck",
45830
+ item: [this.getId()],
45831
+ newData: { isInDeck },
45832
+ prevData: { isInDeck: this.isInDeck }
45833
+ });
45834
+ }
45835
+ updateImageToRender() {
45836
+ this.imageToRender = this.backside;
45837
+ if (this.isOpen) {
45838
+ this.imageToRender = this.image;
45839
+ }
45840
+ }
45841
+ render(context, deckRenderData) {
45842
+ if (this.transformationRenderBlock || this.isInDeck && !deckRenderData) {
45843
+ return;
45844
+ }
45845
+ const ctx = context.ctx;
45846
+ if (this.imageToRender && this.imageToRender.complete) {
45847
+ ctx.save();
45848
+ let left = this.left;
45849
+ let top = this.top;
45850
+ if (deckRenderData) {
45851
+ left = deckRenderData.left + 2 * deckRenderData.cardPosition;
45852
+ top = deckRenderData.top;
45853
+ }
45854
+ ctx.drawImage(this.imageToRender, left, top, CARD_DIMENSIONS.width, CARD_DIMENSIONS.height);
45855
+ ctx.restore();
45856
+ }
45857
+ }
45858
+ updateMbr() {
45859
+ const { translateX, translateY, scaleX, scaleY } = this.transformation.matrix;
45860
+ this.left = translateX;
45861
+ this.top = translateY;
45862
+ this.right = this.left + CARD_DIMENSIONS.width * scaleX;
45863
+ this.bottom = this.top + CARD_DIMENSIONS.height * scaleY;
45864
+ }
45865
+ getMbr() {
45866
+ if (this.isInDeck) {
45867
+ return new Mbr(1e4, 1e4, 1e4, 1e4);
45868
+ }
45869
+ return super.getMbr();
45870
+ }
45871
+ getPath() {
45872
+ return new Path(this.getMbr().getLines());
45873
+ }
45874
+ renderHTML(documentFactory) {
45875
+ const div = documentFactory.createElement("card-item");
45876
+ return div;
45877
+ }
45878
+ deserialize(data) {
45879
+ super.deserialize(data);
45880
+ this.updateMbr();
45881
+ this.createImages();
45882
+ this.subject.publish(this);
45883
+ return this;
45884
+ }
45885
+ toggleIsOpen() {
45886
+ this.emit({
45887
+ class: "Card",
45888
+ method: "setIsOpen",
45889
+ item: [this.getId()],
45890
+ newData: { isOpen: !this.isOpen },
45891
+ prevData: { isOpen: this.isOpen }
45892
+ });
45893
+ }
45894
+ apply(op) {
45895
+ super.apply(op);
45896
+ switch (op.class) {
45897
+ case "Card":
45898
+ switch (op.method) {
45899
+ case "setIsOpen":
45900
+ this.isOpen = op.newData.isOpen;
45901
+ this.updateImageToRender();
45902
+ break;
45903
+ case "setIsInDeck":
45904
+ this.isInDeck = op.newData.isInDeck;
45905
+ break;
45906
+ }
45907
+ break;
45908
+ }
45909
+ this.subject.publish(this);
45910
+ }
45911
+ }
45912
+ registerItem({
45913
+ item: Card,
45914
+ defaultData: defaultCardData
45915
+ });
45916
+ // src/Items/Examples/CardGame/Deck/Deck.ts
45917
+ var defaultDeckData = {
45918
+ itemType: "Deck",
45919
+ cardIds: []
45920
+ };
45921
+
45922
+ class Deck extends BaseItem {
45923
+ subject = new Subject;
45924
+ shouldUseCustomRender = false;
45925
+ cardIds = [];
45926
+ cards = [];
45927
+ constructor(board, id = "", defaultData2, cards) {
45928
+ super(board, id, defaultDeckData);
45929
+ if (cards) {
45930
+ this.cards = cards;
45931
+ cards.forEach((card) => card.setIsInDeck(true));
45932
+ this.transformation.matrix = cards[cards.length - 1].transformation.matrix;
45933
+ this.cardIds = cards.map((card) => card.getId());
45934
+ }
45935
+ this.transformation.subject.subscribe(() => {
45936
+ this.updateMbr();
45937
+ this.subject.publish(this);
45938
+ });
45939
+ this.updateMbr();
45940
+ }
45941
+ getDeck() {
45942
+ return this.cards;
45943
+ }
45944
+ getTopCard() {
45945
+ const cardId = this.cardIds[this.cardIds.length - 1];
45946
+ return this.getCards([cardId])[0];
45947
+ }
45948
+ getBottomCard() {
45949
+ const cardId = this.cardIds[0];
45950
+ return this.getCards([cardId])[0];
45951
+ }
45952
+ getRandomCard() {
45953
+ const cardId = this.cardIds[Math.ceil(Math.random() * this.cardIds.length) - 1];
45954
+ return this.getCards([cardId])[0];
45955
+ }
45956
+ getCards(cardIds) {
45957
+ const cards = this.findCardsOnBoard(cardIds);
45958
+ this.removeCards(cards);
45959
+ return cards;
45960
+ }
45961
+ findCardsOnBoard(cardIds) {
45962
+ return cardIds.map((cardId) => {
45963
+ return this.board.items.getById(cardId);
45964
+ }).filter((card) => !!card);
45965
+ }
45966
+ updateCards() {
45967
+ if (this.cardIds.length === this.cards.length) {
45968
+ return this.cards;
45969
+ }
45970
+ this.cards = this.findCardsOnBoard(this.cardIds);
45971
+ return this.cards;
45972
+ }
45973
+ shuffleDeck() {
45974
+ const shuffled = [...this.cardIds];
45975
+ for (let i = shuffled.length - 1;i > 0; i--) {
45976
+ const j = Math.floor(Math.random() * (i + 1));
45977
+ [shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
45978
+ }
45979
+ const cards = this.findCardsOnBoard(shuffled);
45980
+ this.addCards(cards, true);
45981
+ }
45982
+ addCards(cards, shouldReplaceExistingCards = false) {
45983
+ cards.forEach((card) => {
45984
+ card.setIsInDeck(true);
45985
+ });
45986
+ this.board.bringToFront(cards);
45987
+ this.emit({
45988
+ class: "Deck",
45989
+ method: "addCards",
45990
+ item: [this.getId()],
45991
+ newData: {
45992
+ cardIds: cards.map((card) => card.getId()),
45993
+ shouldReplaceExistingCards
45994
+ },
45995
+ prevData: { cardIds: this.cardIds, shouldReplaceExistingCards }
45996
+ });
45997
+ }
45998
+ removeCards(cards) {
45999
+ cards.forEach((card) => {
46000
+ card.setIsInDeck(false);
46001
+ });
46002
+ this.emit({
46003
+ class: "Deck",
46004
+ method: "removeCards",
46005
+ item: [this.getId()],
46006
+ newData: { cardIds: cards.map((card) => card.getId()) },
46007
+ prevData: { cardIds: this.cardIds }
46008
+ });
46009
+ }
46010
+ apply(op) {
46011
+ super.apply(op);
46012
+ switch (op.class) {
46013
+ case "Deck":
46014
+ switch (op.method) {
46015
+ case "addCards":
46016
+ if (op.newData.shouldReplaceExistingCards) {
46017
+ this.cardIds = op.newData.cardIds;
46018
+ this.cards = this.findCardsOnBoard(this.cardIds);
46019
+ } else {
46020
+ this.cardIds = [
46021
+ ...op.newData.cardIds,
46022
+ ...this.cardIds
46023
+ ];
46024
+ this.updateCards();
46025
+ this.updateMbr();
46026
+ }
46027
+ break;
46028
+ case "removeCards":
46029
+ this.cardIds = this.cardIds.filter((card) => {
46030
+ return !op.newData.cardIds.includes(card);
46031
+ });
46032
+ this.updateCards();
46033
+ this.updateMbr();
46034
+ break;
46035
+ }
46036
+ break;
46037
+ }
46038
+ this.subject.publish(this);
46039
+ }
46040
+ updateMbr() {
46041
+ const { translateX, translateY, scaleX, scaleY } = this.transformation.matrix;
46042
+ this.left = translateX;
46043
+ this.top = translateY;
46044
+ this.right = this.left + CARD_DIMENSIONS.width * scaleX + 2 * this.cardIds.length;
46045
+ this.bottom = this.top + CARD_DIMENSIONS.height * scaleY;
46046
+ }
46047
+ deserialize(data) {
46048
+ super.deserialize(data);
46049
+ this.updateCards();
46050
+ return this;
46051
+ }
46052
+ render(context) {
46053
+ if (this.transformationRenderBlock) {
46054
+ return;
46055
+ }
46056
+ this.cards.forEach((card, index2) => {
46057
+ card.render(context, {
46058
+ top: this.top,
46059
+ left: this.left,
46060
+ cardPosition: index2 + 1
46061
+ });
46062
+ });
46063
+ }
46064
+ }
46065
+ registerItem({
46066
+ item: Deck,
46067
+ defaultData: defaultDeckData
46068
+ });
45748
46069
  // src/Pointer/Cursor.ts
45749
46070
  var defaultCursors = [
45750
46071
  "default",
@@ -46257,27 +46578,6 @@ class Camera {
46257
46578
  requestAnimationFrame(animate);
46258
46579
  }
46259
46580
  }
46260
- function throttle(func, delay) {
46261
- let lastCall = 0;
46262
- let timeoutId = null;
46263
- return function(...args) {
46264
- const now = Date.now();
46265
- if (lastCall + delay <= now) {
46266
- lastCall = now;
46267
- func(...args);
46268
- if (timeoutId) {
46269
- clearTimeout(timeoutId);
46270
- timeoutId = null;
46271
- }
46272
- } else if (!timeoutId) {
46273
- timeoutId = setTimeout(() => {
46274
- lastCall = Date.now();
46275
- timeoutId = null;
46276
- func(...args);
46277
- }, delay - (now - lastCall));
46278
- }
46279
- };
46280
- }
46281
46581
  // src/hotkeys.json
46282
46582
  var hotkeys_default = {
46283
46583
  select: {
@@ -55877,6 +56177,7 @@ export {
55877
56177
  Drawing,
55878
56178
  DefaultTransformationData,
55879
56179
  DefaultShapeData,
56180
+ Deck,
55880
56181
  DEFAULT_SHAPE,
55881
56182
  CubicBezier,
55882
56183
  Counter,
@@ -55884,6 +56185,7 @@ export {
55884
56185
  Connector2 as Connector,
55885
56186
  ConnectionLineWidths,
55886
56187
  Comment,
56188
+ Card,
55887
56189
  Camera,
55888
56190
  CURSORS_IDLE_CLEANUP_DELAY,
55889
56191
  CURSORS_ANIMATION_DURATION,