microboard-temp 0.13.42 → 0.13.44

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.
Files changed (52) hide show
  1. package/dist/cjs/browser.js +284 -200
  2. package/dist/cjs/index.js +284 -200
  3. package/dist/cjs/node.js +284 -200
  4. package/dist/esm/browser.js +287 -203
  5. package/dist/esm/index.js +287 -203
  6. package/dist/esm/node.js +287 -203
  7. package/dist/types/Events/Log/EventsLog.d.ts +2 -2
  8. package/dist/types/Events/Log/deserializeAndApplyToList.d.ts +2 -2
  9. package/dist/types/Events/MessageRouter/boardMessageInterface.d.ts +57 -3
  10. package/dist/types/Events/MessageRouter/handleAiChatMassage.d.ts +1 -5
  11. package/dist/types/Events/MessageRouter/handleBoardEventMessage.d.ts +1 -8
  12. package/dist/types/Events/MessageRouter/handleConfirmation.d.ts +1 -6
  13. package/dist/types/Events/MessageRouter/handleCreateSnapshotRequestMessage.d.ts +2 -5
  14. package/dist/types/Events/MessageRouter/handleModeMessage.d.ts +1 -5
  15. package/dist/types/Events/MessageRouter/handlePresenceEventMessage.d.ts +1 -1
  16. package/dist/types/Events/MessageRouter/index.d.ts +0 -5
  17. package/dist/types/Items/AINode/AINode.d.ts +1 -1
  18. package/dist/types/Items/Audio/Audio.d.ts +1 -1
  19. package/dist/types/Items/BaseItem/BaseItem.d.ts +2 -2
  20. package/dist/types/Items/Comment/Comment.d.ts +1 -1
  21. package/dist/types/Items/Connector/Connector.d.ts +1 -1
  22. package/dist/types/Items/Drawing/Drawing.d.ts +1 -1
  23. package/dist/types/Items/Examples/CardGame/Card/Card.d.ts +1 -1
  24. package/dist/types/Items/Examples/CardGame/Deck/Deck.d.ts +1 -1
  25. package/dist/types/Items/Examples/CardGame/Dice/Dice.d.ts +1 -1
  26. package/dist/types/Items/Examples/CardGame/Screen/Screen.d.ts +1 -1
  27. package/dist/types/Items/Examples/Counter/Counter.d.ts +1 -1
  28. package/dist/types/Items/Examples/Star/Star.d.ts +1 -1
  29. package/dist/types/Items/Frame/Frame.d.ts +1 -1
  30. package/dist/types/Items/Group/Group.d.ts +2 -2
  31. package/dist/types/Items/Image/Image.d.ts +1 -1
  32. package/dist/types/Items/Placeholder/Placeholder.d.ts +1 -1
  33. package/dist/types/Items/RegisterItem.d.ts +2 -2
  34. package/dist/types/Items/RichText/CanvasText/index.d.ts +2 -0
  35. package/dist/types/Items/RichText/EditorContainer.d.ts +3 -2
  36. package/dist/types/Items/RichText/RichText.d.ts +1 -1
  37. package/dist/types/Items/RichText/RichTextData.d.ts +1 -1
  38. package/dist/types/Items/RichText/editorHelpers/selectionOps/setSelectionFontColor.d.ts +2 -1
  39. package/dist/types/Items/Shape/Shape.d.ts +1 -1
  40. package/dist/types/Items/Sticker/Sticker.d.ts +1 -1
  41. package/dist/types/Items/Video/Video.d.ts +1 -1
  42. package/dist/types/Presence/Events.d.ts +1 -20
  43. package/dist/types/Presence/Presence.d.ts +2 -1
  44. package/dist/types/Selection/Selection.d.ts +1 -1
  45. package/dist/types/Selection/SelectionItems.d.ts +1 -0
  46. package/dist/types/Settings.d.ts +7 -7
  47. package/dist/types/SpatialIndex/LayeredIndex/index.d.ts +12 -8
  48. package/dist/types/SpatialIndex/RTreeIndex/index.d.ts +12 -7
  49. package/dist/types/SpatialIndex/SimpleSpatialIndex.d.ts +24 -8
  50. package/dist/types/SpatialIndex/SpacialIndex.d.ts +81 -9
  51. package/dist/types/Tools/CustomTool.d.ts +3 -3
  52. package/package.json +1 -1
package/dist/esm/node.js CHANGED
@@ -4179,18 +4179,23 @@ function createEventsList(commandFactory) {
4179
4179
  return item;
4180
4180
  if (typeof item === "string")
4181
4181
  return [item];
4182
- return Object.keys(item);
4182
+ if (item && typeof item === "object")
4183
+ return Object.keys(item);
4183
4184
  }
4184
- if ("itemsMap" in op)
4185
+ if ("itemsMap" in op && op.itemsMap)
4185
4186
  return Object.keys(op.itemsMap);
4186
4187
  if ("items" in op) {
4187
4188
  const items = op.items;
4188
- if (Array.isArray(items))
4189
- return items.map((i) => typeof i === "string" ? i : i.id);
4190
- return Object.keys(items);
4189
+ if (Array.isArray(items)) {
4190
+ return items.map((i) => typeof i === "string" ? i : i.id).filter(Boolean);
4191
+ }
4192
+ if (items && typeof items === "object" && items !== null)
4193
+ return Object.keys(items);
4194
+ }
4195
+ if ("itemsOps" in op) {
4196
+ const itemsOps = op.itemsOps;
4197
+ return itemsOps.map((io) => io.item);
4191
4198
  }
4192
- if ("itemsOps" in op)
4193
- return op.itemsOps.map((io) => io.item);
4194
4199
  return [];
4195
4200
  }
4196
4201
  return {
@@ -5849,16 +5854,17 @@ var init_transformEvents = __esm(() => {
5849
5854
  function expandEvents(events) {
5850
5855
  return events.flatMap((event) => {
5851
5856
  if ("operations" in event.body) {
5852
- return event.body.operations.map((operation) => ({
5857
+ const { operations, lastKnownOrder, ...bodyWithoutOps } = event.body;
5858
+ return operations.map((operation) => ({
5853
5859
  order: event.order,
5854
5860
  body: {
5855
- eventId: operation.actualId || event.body.eventId,
5856
- userId: event.body.userId,
5857
- boardId: event.body.boardId,
5861
+ eventId: operation.actualId || bodyWithoutOps.eventId,
5862
+ userId: bodyWithoutOps.userId,
5863
+ boardId: bodyWithoutOps.boardId,
5858
5864
  operation
5859
5865
  },
5860
- userId: event.body.userId,
5861
- lastKnownOrder: "lastKnownOrder" in event ? event.lastKnownOrder : event.body.lastKnownOrder
5866
+ userId: bodyWithoutOps.userId,
5867
+ lastKnownOrder
5862
5868
  }));
5863
5869
  } else {
5864
5870
  return [event];
@@ -5970,13 +5976,15 @@ var init_insertEventsFromOtherConnectionsIntoList = __esm(() => {
5970
5976
  function deserializeAndApplyToList(events, list, board) {
5971
5977
  list.clear();
5972
5978
  for (const event of events) {
5973
- const body = event.body;
5974
- if (body.operations && Array.isArray(body.operations)) {
5975
- for (const op of body.operations) {
5979
+ if ("operations" in event.body) {
5980
+ const { operations, lastKnownOrder, ...bodyWithoutOps } = event.body;
5981
+ for (const op of operations) {
5976
5982
  const singleEvent = {
5977
- ...event,
5983
+ order: event.order,
5984
+ lastKnownOrder,
5985
+ userId: bodyWithoutOps.userId,
5978
5986
  body: {
5979
- ...event.body,
5987
+ ...bodyWithoutOps,
5980
5988
  operation: op
5981
5989
  }
5982
5990
  };
@@ -11582,7 +11590,7 @@ class RTreeIndex {
11582
11590
  this.tree.remove(item);
11583
11591
  }
11584
11592
  }
11585
- list() {
11593
+ listAll() {
11586
11594
  const containers = this.tree.all();
11587
11595
  const items = [];
11588
11596
  for (const container of containers) {
@@ -11590,7 +11598,7 @@ class RTreeIndex {
11590
11598
  }
11591
11599
  return items;
11592
11600
  }
11593
- getEnclosed(rect) {
11601
+ listEnclosedBy(rect) {
11594
11602
  return this.tree.search({
11595
11603
  minX: rect.left,
11596
11604
  minY: rect.top,
@@ -11598,7 +11606,7 @@ class RTreeIndex {
11598
11606
  maxY: rect.bottom
11599
11607
  }).filter((container) => container.item.isEnclosedBy(rect)).map((container) => container.item);
11600
11608
  }
11601
- getEnclosedOrCrossedBy(rect) {
11609
+ listEnclosedOrCrossedBy(rect) {
11602
11610
  return this.tree.search({
11603
11611
  minX: rect.left,
11604
11612
  minY: rect.top,
@@ -11606,7 +11614,7 @@ class RTreeIndex {
11606
11614
  maxY: rect.bottom
11607
11615
  }).filter((container) => container.item.isEnclosedOrCrossedBy(rect)).map((container) => container.item);
11608
11616
  }
11609
- getUnderPoint(point, tolerance = 5) {
11617
+ listUnderPoint(point, tolerance = 5) {
11610
11618
  return this.tree.search({
11611
11619
  minX: point.x,
11612
11620
  minY: point.y,
@@ -11614,7 +11622,7 @@ class RTreeIndex {
11614
11622
  maxY: point.y
11615
11623
  }).filter((container) => container.item.isUnderPoint(point, tolerance)).map((container) => container.item);
11616
11624
  }
11617
- getRectsEnclosedOrCrossedBy(rect) {
11625
+ listRectsEnclosedOrCrossedBy(rect) {
11618
11626
  return this.tree.search({
11619
11627
  minX: rect.left,
11620
11628
  minY: rect.top,
@@ -11630,9 +11638,27 @@ class RTreeIndex {
11630
11638
  maxY: rect.bottom
11631
11639
  });
11632
11640
  }
11633
- getNearestTo(point, maxItems, filter, maxDistance) {
11641
+ listNearestTo(point, maxItems, filter, maxDistance) {
11634
11642
  return knn(this.tree, point.x, point.y, maxItems, (container) => filter(container.item), maxDistance).map((container) => container.item);
11635
11643
  }
11644
+ getById(id) {
11645
+ return this.listAll().find((item) => item.getId() === id);
11646
+ }
11647
+ findById(id) {
11648
+ return this.getById(id);
11649
+ }
11650
+ getByZIndex(index) {
11651
+ return this.listAll()[index];
11652
+ }
11653
+ getLastZIndex() {
11654
+ return this.listAll().length - 1;
11655
+ }
11656
+ copy() {
11657
+ return this.listAll().map((item) => ({
11658
+ ...item.serialize(),
11659
+ id: item.getId()
11660
+ }));
11661
+ }
11636
11662
  batchInsert(batch) {
11637
11663
  for (const one of batch) {
11638
11664
  this.insert(one);
@@ -11704,35 +11730,31 @@ class LayeredIndex {
11704
11730
  isT(item) {
11705
11731
  return true;
11706
11732
  }
11707
- findById(id) {
11708
- const container = this.map.get(id);
11709
- return container ? container.item : undefined;
11710
- }
11711
- getEnclosed(rect) {
11733
+ listEnclosedBy(rect) {
11712
11734
  let items = [];
11713
11735
  for (const layer of this.layers.array) {
11714
- items = items.concat(layer.getEnclosed(rect));
11736
+ items = items.concat(layer.listEnclosedBy(rect));
11715
11737
  }
11716
11738
  return items;
11717
11739
  }
11718
- getEnclosedOrCrossedBy(rect) {
11740
+ listEnclosedOrCrossedBy(rect) {
11719
11741
  let items = [];
11720
11742
  for (const layer of this.layers.array) {
11721
- items = items.concat(layer.getEnclosedOrCrossedBy(rect));
11743
+ items = items.concat(layer.listEnclosedOrCrossedBy(rect));
11722
11744
  }
11723
11745
  return items;
11724
11746
  }
11725
- getUnderPoint(point, tolerance = 5) {
11747
+ listUnderPoint(point, tolerance = 5) {
11726
11748
  let items = [];
11727
11749
  for (const layer of this.layers.array) {
11728
- const layerItems = layer.getUnderPoint(point, tolerance);
11750
+ const layerItems = layer.listUnderPoint(point, tolerance);
11729
11751
  if (layerItems.length > 0) {
11730
11752
  items = items.concat(layerItems);
11731
11753
  }
11732
11754
  }
11733
11755
  return items;
11734
11756
  }
11735
- getRectsEnclosedOrCrossedBy(rect) {
11757
+ listRectsEnclosedOrCrossedBy(rect) {
11736
11758
  const items = [];
11737
11759
  const minMax = {
11738
11760
  minX: rect.left,
@@ -11756,10 +11778,10 @@ class LayeredIndex {
11756
11778
  }
11757
11779
  return false;
11758
11780
  }
11759
- getNearestTo(point, maxItems, filter, maxDistance) {
11781
+ listNearestTo(point, maxItems, filter, maxDistance) {
11760
11782
  let items = [];
11761
11783
  for (const layer of this.layers.array) {
11762
- items = items.concat(layer.getNearestTo(point, maxItems, filter, maxDistance));
11784
+ items = items.concat(layer.listNearestTo(point, maxItems, filter, maxDistance));
11763
11785
  }
11764
11786
  return items;
11765
11787
  }
@@ -11793,7 +11815,7 @@ class LayeredIndex {
11793
11815
  }
11794
11816
  const bounds = container.item.getMbrWithChildren();
11795
11817
  this.remove(container.item);
11796
- const inBounds = this.getRectsEnclosedOrCrossedBy(bounds);
11818
+ const inBounds = this.listRectsEnclosedOrCrossedBy(bounds);
11797
11819
  const containersInBounds = this.getContainersFromItems(inBounds);
11798
11820
  const containersAbove = [];
11799
11821
  const containerZIndex = this.getZIndex(container.item);
@@ -11821,7 +11843,7 @@ class LayeredIndex {
11821
11843
  }
11822
11844
  const bounds = container.item.getMbrWithChildren();
11823
11845
  this.remove(container.item);
11824
- const inBounds = this.getRectsEnclosedOrCrossedBy(bounds);
11846
+ const inBounds = this.listRectsEnclosedOrCrossedBy(bounds);
11825
11847
  const containersInBounds = this.getContainersFromItems(inBounds);
11826
11848
  const containersBelow = [];
11827
11849
  const containerZIndex = this.getZIndex(container.item);
@@ -11846,7 +11868,7 @@ class LayeredIndex {
11846
11868
  insert(item) {
11847
11869
  const toInsert = new Container(item.getId(), item, 0, this.getZIndex(item));
11848
11870
  const bounds = item.getMbrWithChildren();
11849
- const inBounds = this.getRectsEnclosedOrCrossedBy(bounds);
11871
+ const inBounds = this.listRectsEnclosedOrCrossedBy(bounds);
11850
11872
  if (inBounds.length === 0) {
11851
11873
  return this.insertContainer(toInsert);
11852
11874
  }
@@ -11943,13 +11965,32 @@ class LayeredIndex {
11943
11965
  return;
11944
11966
  }
11945
11967
  }
11946
- list() {
11968
+ listAll() {
11947
11969
  const items = [];
11948
11970
  for (const record of this.map) {
11949
11971
  items.push(record[1].item);
11950
11972
  }
11951
11973
  return items;
11952
11974
  }
11975
+ getById(id) {
11976
+ const container = this.map.get(id);
11977
+ return container ? container.item : undefined;
11978
+ }
11979
+ findById(id) {
11980
+ return this.getById(id);
11981
+ }
11982
+ getByZIndex(index) {
11983
+ return this.listAll()[index];
11984
+ }
11985
+ getLastZIndex() {
11986
+ return this.listAll().length - 1;
11987
+ }
11988
+ copy() {
11989
+ return this.listAll().map((item) => ({
11990
+ ...item.serialize(),
11991
+ id: item.getId()
11992
+ }));
11993
+ }
11953
11994
  batchInsert(items) {
11954
11995
  for (const item of items) {
11955
11996
  this.insert(item);
@@ -11966,11 +12007,6 @@ var init_LayeredIndex = __esm(() => {
11966
12007
  init_RTreeIndex();
11967
12008
  });
11968
12009
 
11969
- // src/Items/BaseItem/index.ts
11970
- var init_BaseItem = __esm(() => {
11971
- init_BaseItem2();
11972
- });
11973
-
11974
12010
  // src/SpatialIndex/SpacialIndex.ts
11975
12011
  function worldBoundsToLocal(container, left, top, right, bottom) {
11976
12012
  const inv = container.getNestingMatrix().getInverse();
@@ -11989,6 +12025,13 @@ function worldBoundsToLocal(container, left, top, right, bottom) {
11989
12025
  bottom: Math.max(corners[0].y, corners[1].y, corners[2].y, corners[3].y)
11990
12026
  };
11991
12027
  }
12028
+ function coerceMbr(left, top, right, bottom) {
12029
+ if (left instanceof Mbr)
12030
+ return left;
12031
+ if (typeof left === "object" && left !== null)
12032
+ return new Mbr(left.left, left.top, left.right, left.bottom);
12033
+ return new Mbr(left, top, right, bottom);
12034
+ }
11992
12035
 
11993
12036
  class SpatialIndex {
11994
12037
  subject = new Subject;
@@ -12009,6 +12052,9 @@ class SpatialIndex {
12009
12052
  this.Mbr = new Mbr;
12010
12053
  }
12011
12054
  insert(item) {
12055
+ if (this.itemsArray.includes(item) || this.getById(item.getId())) {
12056
+ return;
12057
+ }
12012
12058
  this.itemsArray.push(item);
12013
12059
  this.itemsIndex.insert(item);
12014
12060
  if (conf.isNode()) {
@@ -12037,7 +12083,7 @@ class SpatialIndex {
12037
12083
  remove(item, preserveChildren = false) {
12038
12084
  const baseItem = item;
12039
12085
  if (!preserveChildren && baseItem.index) {
12040
- baseItem.removeChildItems(baseItem.index.list());
12086
+ baseItem.removeChildItems(baseItem.index.listAll());
12041
12087
  }
12042
12088
  this.itemsArray.splice(this.itemsArray.indexOf(item), 1);
12043
12089
  this.itemsIndex.remove(item);
@@ -12080,14 +12126,14 @@ class SpatialIndex {
12080
12126
  return items.flatMap((item) => {
12081
12127
  const baseItem = item;
12082
12128
  if (baseItem.index) {
12083
- return [item, ...baseItem.index.list()];
12129
+ return [item, ...baseItem.index.listAll()];
12084
12130
  }
12085
12131
  return item;
12086
12132
  });
12087
12133
  }
12088
12134
  getItemChildren(item) {
12089
12135
  if ("index" in item && item.index) {
12090
- return item.index.list();
12136
+ return item.index.listAll();
12091
12137
  }
12092
12138
  return [];
12093
12139
  }
@@ -12238,14 +12284,14 @@ class SpatialIndex {
12238
12284
  findById(id) {
12239
12285
  return this.getById(id);
12240
12286
  }
12241
- getEnclosed(left, top, right, bottom) {
12242
- const mbr = new Mbr(left, top, right, bottom);
12243
- const items = this.itemsIndex.getEnclosed(mbr);
12287
+ listEnclosedBy(left, top, right, bottom) {
12288
+ const mbr = coerceMbr(left, top, right, bottom);
12289
+ const items = this.itemsIndex.listEnclosedBy(mbr);
12244
12290
  const children = [];
12245
12291
  const clearItems = items.filter((item) => {
12246
12292
  if ("index" in item && item.index) {
12247
- const local = worldBoundsToLocal(item, left, top, right, bottom);
12248
- children.push(...item.index.getEnclosed(local.left, local.top, local.right, local.bottom));
12293
+ const local = worldBoundsToLocal(item, mbr.left, mbr.top, mbr.right, mbr.bottom);
12294
+ children.push(...item.index.listEnclosedBy(local.left, local.top, local.right, local.bottom));
12249
12295
  if (!item.getMbr().isEnclosedBy(mbr)) {
12250
12296
  return false;
12251
12297
  }
@@ -12254,14 +12300,14 @@ class SpatialIndex {
12254
12300
  });
12255
12301
  return [...clearItems, ...children];
12256
12302
  }
12257
- getEnclosedOrCrossed(left, top, right, bottom) {
12258
- const mbr = new Mbr(left, top, right, bottom);
12259
- const items = this.itemsIndex.getEnclosedOrCrossedBy(mbr);
12303
+ listEnclosedOrCrossedBy(left, top, right, bottom) {
12304
+ const mbr = coerceMbr(left, top, right, bottom);
12305
+ const items = this.itemsIndex.listEnclosedOrCrossedBy(mbr);
12260
12306
  const children = [];
12261
12307
  const clearItems = items.filter((item) => {
12262
12308
  if ("index" in item && item.index) {
12263
- const local = worldBoundsToLocal(item, left, top, right, bottom);
12264
- children.push(...item.index.getEnclosedOrCrossed(local.left, local.top, local.right, local.bottom));
12309
+ const local = worldBoundsToLocal(item, mbr.left, mbr.top, mbr.right, mbr.bottom);
12310
+ children.push(...item.index.listEnclosedOrCrossedBy(local.left, local.top, local.right, local.bottom));
12265
12311
  if (!item.getMbr().isEnclosedOrCrossedBy(mbr)) {
12266
12312
  return false;
12267
12313
  }
@@ -12270,14 +12316,17 @@ class SpatialIndex {
12270
12316
  });
12271
12317
  return [...clearItems, ...children];
12272
12318
  }
12273
- getUnderPoint(point, tolerance = 5) {
12274
- const items = this.itemsIndex.getUnderPoint(point, tolerance);
12319
+ listRectsEnclosedOrCrossedBy(left, top, right, bottom) {
12320
+ return this.listEnclosedOrCrossedBy(left, top, right, bottom).map((item) => item.getMbr());
12321
+ }
12322
+ listUnderPoint(point, tolerance = 5) {
12323
+ const items = this.itemsIndex.listUnderPoint(point, tolerance);
12275
12324
  const children = [];
12276
12325
  const clearItems = items.filter((item) => {
12277
12326
  if ("index" in item && item.index) {
12278
12327
  const localPt = new Point(point.x, point.y);
12279
12328
  item.getNestingMatrix().getInverse().apply(localPt);
12280
- children.push(...item.index.getUnderPoint(localPt, tolerance));
12329
+ children.push(...item.index.listUnderPoint(localPt, tolerance));
12281
12330
  if (!item.getMbr().isUnderPoint(point)) {
12282
12331
  return false;
12283
12332
  }
@@ -12289,24 +12338,8 @@ class SpatialIndex {
12289
12338
  });
12290
12339
  return [...clearItems, ...children];
12291
12340
  }
12292
- getRectsEnclosedOrCrossed(left, top, right, bottom) {
12293
- const mbr = new Mbr(left, top, right, bottom);
12294
- const items = this.itemsIndex.getRectsEnclosedOrCrossedBy(mbr);
12295
- const children = [];
12296
- const clearItems = items.filter((item) => {
12297
- if ("index" in item && item.index) {
12298
- const local = worldBoundsToLocal(item, left, top, right, bottom);
12299
- children.push(...item.index.getEnclosedOrCrossed(local.left, local.top, local.right, local.bottom));
12300
- if (!item.getMbr().isEnclosedOrCrossedBy(mbr)) {
12301
- return false;
12302
- }
12303
- }
12304
- return true;
12305
- });
12306
- return [...clearItems, ...children];
12307
- }
12308
- getItemsEnclosedOrCrossed(left, top, right, bottom) {
12309
- return this.getRectsEnclosedOrCrossed(left, top, right, bottom);
12341
+ listNearestTo(point, maxItems, filter, maxDistance) {
12342
+ return this.itemsIndex.listNearestTo(point, maxItems, filter, maxDistance);
12310
12343
  }
12311
12344
  getComments() {
12312
12345
  return this.itemsArray.filter((item) => item.itemType === "Comment");
@@ -12324,7 +12357,7 @@ class SpatialIndex {
12324
12357
  const inRange = itemsWithDistance.filter((x) => x.distance <= maxDistance);
12325
12358
  return inRange.sort((a, b) => a.distance - b.distance).slice(0, maxItems).map((x) => x.item);
12326
12359
  }
12327
- list() {
12360
+ listAll() {
12328
12361
  return this.getItemsWithIncludedChildren(this.itemsArray).concat();
12329
12362
  }
12330
12363
  getZIndex(item) {
@@ -12362,10 +12395,19 @@ class Items {
12362
12395
  this.index.change(item);
12363
12396
  }
12364
12397
  listAll() {
12365
- return this.index.list();
12398
+ return this.index.listAll();
12399
+ }
12400
+ listUnderPoint(point, tolerance = 5) {
12401
+ return this.index.listUnderPoint(point, tolerance);
12402
+ }
12403
+ listEnclosedBy(left, top, right, bottom) {
12404
+ return this.index.listEnclosedBy(left, top, right, bottom);
12405
+ }
12406
+ listEnclosedOrCrossedBy(left, top, right, bottom) {
12407
+ return this.index.listEnclosedOrCrossedBy(left, top, right, bottom);
12366
12408
  }
12367
12409
  listGroupItems() {
12368
- return this.index.list().filter((item) => ("index" in item) && item.index);
12410
+ return this.index.listAll().filter((item) => ("index" in item) && item.index);
12369
12411
  }
12370
12412
  getById(id) {
12371
12413
  return this.index.getById(id);
@@ -12374,16 +12416,16 @@ class Items {
12374
12416
  return this.index.findById(id);
12375
12417
  }
12376
12418
  getEnclosed(left, top, right, bottom) {
12377
- return this.index.getEnclosed(left, top, right, bottom);
12419
+ return this.index.listEnclosedBy(left, top, right, bottom);
12378
12420
  }
12379
12421
  getEnclosedOrCrossed(left, top, right, bottom) {
12380
- return this.index.getEnclosedOrCrossed(left, top, right, bottom);
12422
+ return this.index.listEnclosedOrCrossedBy(left, top, right, bottom);
12381
12423
  }
12382
12424
  getGroupItemsEnclosedOrCrossed(left, top, right, bottom) {
12383
- return this.index.getEnclosedOrCrossed(left, top, right, bottom).filter((item) => item instanceof BaseItem && item.index);
12425
+ return this.index.listEnclosedOrCrossedBy(left, top, right, bottom).filter((item) => ("index" in item) && item.index);
12384
12426
  }
12385
12427
  getUnderPoint(point, tolerance = 5) {
12386
- return this.index.getUnderPoint(point, tolerance);
12428
+ return this.index.listUnderPoint(point, tolerance);
12387
12429
  }
12388
12430
  getMbr() {
12389
12431
  return this.index.getMbr();
@@ -12406,25 +12448,25 @@ class Items {
12406
12448
  }
12407
12449
  getInView() {
12408
12450
  const { left, top, right, bottom } = this.view.getMbr();
12409
- return this.index.getRectsEnclosedOrCrossed(left, top, right, bottom);
12451
+ return this.index.listEnclosedOrCrossedBy(left, top, right, bottom);
12410
12452
  }
12411
12453
  getItemsInView() {
12412
12454
  const { left, top, right, bottom } = this.view.getMbr();
12413
- return this.index.getItemsEnclosedOrCrossed(left, top, right, bottom);
12455
+ return this.index.listEnclosedOrCrossedBy(left, top, right, bottom);
12414
12456
  }
12415
12457
  getGroupItemsInView() {
12416
12458
  const { left, top, right, bottom } = this.view.getMbr();
12417
12459
  return this.getGroupItemsEnclosedOrCrossed(left, top, right, bottom);
12418
12460
  }
12419
12461
  getComments() {
12420
- return this.index.getComments();
12462
+ return this.listAll().filter((item) => item.itemType === "Comment");
12421
12463
  }
12422
12464
  getUnderPointer(size = 0) {
12423
12465
  const { x, y } = this.pointer.point;
12424
12466
  const unmodifiedSize = size;
12425
12467
  size = 16;
12426
- const tolerated = this.index.getEnclosedOrCrossed(x - size, y - size, x + size, y + size);
12427
- let enclosed = tolerated.some((item) => item.itemType === "Connector") ? tolerated : this.index.getEnclosedOrCrossed(x, y, x, y);
12468
+ const tolerated = this.index.listEnclosedOrCrossedBy(x - size, y - size, x + size, y + size);
12469
+ let enclosed = tolerated.some((item) => item.itemType === "Connector") ? tolerated : this.index.listEnclosedOrCrossedBy(x, y, x, y);
12428
12470
  const underPointer = this.getUnderPoint(new Point(x, y), size);
12429
12471
  if (enclosed.length === 0) {
12430
12472
  enclosed = underPointer;
@@ -12452,7 +12494,7 @@ class Items {
12452
12494
  return [];
12453
12495
  }
12454
12496
  getNearPointer(maxDistance = 100, maxItems = 10, filter = () => true) {
12455
- return this.index.getNearestTo(this.pointer.point, maxItems, filter, maxDistance);
12497
+ return this.index.listNearestTo(this.pointer.point, maxItems, filter, maxDistance);
12456
12498
  }
12457
12499
  getZIndex(item) {
12458
12500
  return this.index.getZIndex(item);
@@ -12594,7 +12636,6 @@ var init_SpacialIndex = __esm(() => {
12594
12636
  init_Point();
12595
12637
  init_Settings();
12596
12638
  init_LayeredIndex();
12597
- init_BaseItem();
12598
12639
  });
12599
12640
 
12600
12641
  // src/SpatialIndex/SimpleSpatialIndex.ts
@@ -12611,6 +12652,9 @@ class SimpleSpatialIndex {
12611
12652
  this.Mbr = new Mbr;
12612
12653
  }
12613
12654
  insert(item) {
12655
+ if (this.itemsArray.includes(item) || this.getById(item.getId())) {
12656
+ return;
12657
+ }
12614
12658
  this.itemsArray.push(item);
12615
12659
  if (this.Mbr.getWidth() === 0 && this.Mbr.getHeight() === 0) {
12616
12660
  this.Mbr = item.getMbr().copy();
@@ -12630,9 +12674,12 @@ class SimpleSpatialIndex {
12630
12674
  };
12631
12675
  remove(item, preserveChildren = false) {
12632
12676
  if (!preserveChildren && "index" in item && item.index) {
12633
- item.removeChildItems(item.index.list());
12677
+ item.removeChildItems(item.index.listAll());
12678
+ }
12679
+ const index = this.itemsArray.indexOf(item);
12680
+ if (index !== -1) {
12681
+ this.itemsArray.splice(index, 1);
12634
12682
  }
12635
- this.itemsArray.splice(this.itemsArray.indexOf(item), 1);
12636
12683
  this.Mbr = new Mbr;
12637
12684
  this.itemsArray.forEach((item2) => this.Mbr.combine([item2.getMbr()]));
12638
12685
  this.subject.publish(this.items);
@@ -12715,16 +12762,13 @@ class SimpleSpatialIndex {
12715
12762
  this.subject.publish(this.items);
12716
12763
  }
12717
12764
  getById(id) {
12718
- const item = this.itemsArray.find((item2) => item2.getId() === id);
12719
- if (item) {
12720
- return item;
12721
- }
12765
+ return this.itemsArray.find((item) => item.getId() === id);
12722
12766
  }
12723
12767
  findById(id) {
12724
12768
  return this.getById(id);
12725
12769
  }
12726
- getEnclosed(left, top, right, bottom) {
12727
- const mbr = new Mbr(left, top, right, bottom);
12770
+ listEnclosedBy(left, top, right, bottom) {
12771
+ const mbr = coerceMbr(left, top, right, bottom);
12728
12772
  const items = [];
12729
12773
  this.itemsArray.forEach((item) => {
12730
12774
  if (item.isEnclosedBy(mbr)) {
@@ -12733,8 +12777,8 @@ class SimpleSpatialIndex {
12733
12777
  });
12734
12778
  return items;
12735
12779
  }
12736
- getEnclosedOrCrossed(left, top, right, bottom) {
12737
- const mbr = new Mbr(left, top, right, bottom);
12780
+ listEnclosedOrCrossedBy(left, top, right, bottom) {
12781
+ const mbr = coerceMbr(left, top, right, bottom);
12738
12782
  const items = [];
12739
12783
  this.itemsArray.forEach((item) => {
12740
12784
  if (item.isEnclosedOrCrossedBy(mbr)) {
@@ -12743,19 +12787,30 @@ class SimpleSpatialIndex {
12743
12787
  });
12744
12788
  return items;
12745
12789
  }
12746
- getUnderPoint(point, tolerace = 5) {
12790
+ listUnderPoint(point, tolerance = 5) {
12747
12791
  const items = [];
12748
12792
  this.itemsArray.forEach((item) => {
12749
- if (item.isUnderPoint(point, tolerace)) {
12793
+ if (item.isUnderPoint(point, tolerance)) {
12750
12794
  items.push(item);
12751
12795
  }
12752
12796
  });
12753
12797
  return items;
12754
12798
  }
12799
+ listRectsEnclosedOrCrossedBy(left, top, right, bottom) {
12800
+ return this.listEnclosedOrCrossedBy(left, top, right, bottom).map((item) => item.getMbr());
12801
+ }
12802
+ listNearestTo(point, maxItems, filter, maxDistance) {
12803
+ const itemsWithDistance = this.itemsArray.filter(filter).map((item) => ({
12804
+ item,
12805
+ distance: item.getMbr().getDistanceToPoint(point)
12806
+ }));
12807
+ const inRange = itemsWithDistance.filter((x) => x.distance <= maxDistance);
12808
+ return inRange.sort((a, b) => a.distance - b.distance).slice(0, maxItems).map((x) => x.item);
12809
+ }
12755
12810
  getMbr() {
12756
12811
  return this.Mbr;
12757
12812
  }
12758
- list() {
12813
+ listAll() {
12759
12814
  return this.itemsArray.concat();
12760
12815
  }
12761
12816
  getZIndex(item) {
@@ -12827,7 +12882,7 @@ function toLocalTransformOp(op, containerMatrix, itemId) {
12827
12882
  }
12828
12883
  }
12829
12884
  var BaseItem;
12830
- var init_BaseItem2 = __esm(() => {
12885
+ var init_BaseItem = __esm(() => {
12831
12886
  init_Mbr();
12832
12887
  init_LinkTo();
12833
12888
  init_Transformation();
@@ -13026,7 +13081,10 @@ var init_BaseItem2 = __esm(() => {
13026
13081
  if (this.parent !== childId && this.getId() !== childId && !this.hasAncestor(childId)) {
13027
13082
  if (!this.index?.getById(childId) && foundItem) {
13028
13083
  const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerNestingMatrix);
13029
- this.board.items.index.remove(foundItem, true);
13084
+ const currentParentId = foundItem.parent;
13085
+ const currentParent = currentParentId !== "Board" ? this.board.items.getById(currentParentId) : undefined;
13086
+ const sourceIndex = currentParent?.index || this.board.items.index;
13087
+ sourceIndex.remove(foundItem, true);
13030
13088
  foundItem.parent = this.getId();
13031
13089
  foundItem.onParentChanged(this.getId());
13032
13090
  foundItem.transformation.setLocalMatrix(localMatrix);
@@ -13271,7 +13329,7 @@ var init_Comment = __esm(() => {
13271
13329
  init_Line2();
13272
13330
  init_esm();
13273
13331
  init_LinkTo();
13274
- init_BaseItem2();
13332
+ init_BaseItem();
13275
13333
  Comment = class Comment extends BaseItem {
13276
13334
  anchor;
13277
13335
  events;
@@ -16688,7 +16746,7 @@ var init_getListTypeAtSelectionStart = __esm(() => {
16688
16746
  });
16689
16747
 
16690
16748
  // src/Items/RichText/editorHelpers/links/setLink.ts
16691
- import { Editor as Editor11, Transforms as Transforms10 } from "slate";
16749
+ import { Editor as Editor11, Transforms as Transforms10, Text as Text6 } from "slate";
16692
16750
  var setLink = (editor, link, selection) => {
16693
16751
  if (!selection) {
16694
16752
  selectWholeText(editor);
@@ -16700,15 +16758,15 @@ var setLink = (editor, link, selection) => {
16700
16758
  }
16701
16759
  const format = link ? "rgba(71, 120, 245, 1)" : "rgb(20, 21, 26)";
16702
16760
  Transforms10.setNodes(editor, { fontColor: format }, {
16703
- match: (n) => !Editor11.isEditor(n) && n.type === "text",
16761
+ match: (n) => Text6.isText(n),
16704
16762
  split: true
16705
16763
  });
16706
- for (const [node, path2] of Editor11.nodes(editor, {
16707
- match: (n) => !Editor11.isEditor(n) && n.type === "text"
16764
+ for (const [, path2] of Editor11.nodes(editor, {
16765
+ match: (n) => Text6.isText(n)
16708
16766
  })) {
16709
16767
  const nodeRange = Editor11.range(editor, path2);
16710
16768
  Transforms10.select(editor, nodeRange);
16711
- Transforms10.setNodes(editor, { link }, { split: false, match: (n) => !Editor11.isEditor(n) && n.type === "text" });
16769
+ Transforms10.setNodes(editor, { link }, { split: false, match: (n) => Text6.isText(n) });
16712
16770
  }
16713
16771
  };
16714
16772
  var init_setLink = __esm(() => {
@@ -27392,7 +27450,7 @@ var init_setEditorFocus = () => {};
27392
27450
  import {
27393
27451
  Editor as Editor30,
27394
27452
  Element as Element9,
27395
- Text as Text6,
27453
+ Text as Text7,
27396
27454
  Transforms as Transforms20
27397
27455
  } from "slate";
27398
27456
  var isEditInProcessValue = false, counter = 0, RichText;
@@ -27415,7 +27473,7 @@ var init_RichText = __esm(() => {
27415
27473
  init_getSelectionStyles();
27416
27474
  init_setEditorFocus();
27417
27475
  init_getAllTextNodesInSelection();
27418
- init_BaseItem2();
27476
+ init_BaseItem();
27419
27477
  RichText = class RichText extends BaseItem {
27420
27478
  container;
27421
27479
  transformation;
@@ -27960,7 +28018,7 @@ var init_RichText = __esm(() => {
27960
28018
  }
27961
28019
  getMinFontSize() {
27962
28020
  const textNodes = Editor30.nodes(this.editor.editor, {
27963
- match: (n) => Text6.isText(n),
28021
+ match: (n) => Text7.isText(n),
27964
28022
  at: []
27965
28023
  });
27966
28024
  const fontSizes = [];
@@ -28381,7 +28439,7 @@ var init_AINode = __esm(() => {
28381
28439
  init_Matrix();
28382
28440
  init_Transformation();
28383
28441
  init_Settings();
28384
- init_BaseItem2();
28442
+ init_BaseItem();
28385
28443
  AINode = class AINode extends BaseItem {
28386
28444
  itemType = "AINode";
28387
28445
  parent = "Board";
@@ -28728,7 +28786,7 @@ var init_Audio = __esm(() => {
28728
28786
  init_Point();
28729
28787
  init_Line();
28730
28788
  init_Settings();
28731
- init_BaseItem2();
28789
+ init_BaseItem();
28732
28790
  AudioItem = class AudioItem extends BaseItem {
28733
28791
  events;
28734
28792
  extension;
@@ -43725,6 +43783,11 @@ var init_ShapeData = __esm(() => {
43725
43783
  ];
43726
43784
  });
43727
43785
 
43786
+ // src/Items/BaseItem/index.ts
43787
+ var init_BaseItem2 = __esm(() => {
43788
+ init_BaseItem();
43789
+ });
43790
+
43728
43791
  // src/Items/Mbr/updateRects.ts
43729
43792
  function updateRects(board, ref, mbr, verticalOffset, horizontalOffset, fit = "contextPanel") {
43730
43793
  const { selection, camera } = board;
@@ -43995,7 +44058,7 @@ var init_ControlPoint = __esm(() => {
43995
44058
  init_Transformation2();
43996
44059
  init_RichText2();
43997
44060
  init_AINode2();
43998
- init_BaseItem();
44061
+ init_BaseItem2();
43999
44062
  BoardPoint = class BoardPoint extends Point {
44000
44063
  pointType = "Board";
44001
44064
  serialize() {
@@ -44895,7 +44958,7 @@ var init_Connector = __esm(() => {
44895
44958
  init_LinkTo();
44896
44959
  init_HTMLRender();
44897
44960
  init_Settings();
44898
- init_BaseItem2();
44961
+ init_BaseItem();
44899
44962
  init_Color();
44900
44963
  init_ConnectorTypes();
44901
44964
  CONNECTOR_ANCHOR_COLOR = {
@@ -45876,7 +45939,7 @@ var init_Sticker = __esm(() => {
45876
45939
  init_SessionStorage();
45877
45940
  init_HTMLRender();
45878
45941
  init_Settings();
45879
- init_BaseItem2();
45942
+ init_BaseItem();
45880
45943
  init_Color();
45881
45944
  stickerColors = {
45882
45945
  Purple: "rgb(233, 208, 255)",
@@ -47009,7 +47072,7 @@ async function exportBoardSnapshot({
47009
47072
  context.ctx.setTransform(upscaleFactor, 0, 0, upscaleFactor, 0, 0);
47010
47073
  context.matrix.applyToContext(context.ctx);
47011
47074
  const { left, top, right, bottom } = selection;
47012
- const inView = board.items.index.getRectsEnclosedOrCrossed(left, top, right, bottom);
47075
+ const inView = board.items.index.listEnclosedOrCrossedBy(left, top, right, bottom);
47013
47076
  for (const item of inView) {
47014
47077
  item.render(context);
47015
47078
  }
@@ -47129,7 +47192,7 @@ var init_Frame = __esm(() => {
47129
47192
  init_FrameData();
47130
47193
  init_Settings();
47131
47194
  init_getResizeMatrix();
47132
- init_BaseItem();
47195
+ init_BaseItem2();
47133
47196
  init_Color();
47134
47197
  defaultFrameData = new DefaultFrameData;
47135
47198
  Frame = class Frame extends BaseItem {
@@ -47248,7 +47311,7 @@ var init_Frame = __esm(() => {
47248
47311
  return this.id;
47249
47312
  }
47250
47313
  getChildrenIds() {
47251
- return this.index?.list().map((item) => item.getId()) || [];
47314
+ return this.index?.listAll().map((item) => item.getId()) || [];
47252
47315
  }
47253
47316
  updateMbr() {
47254
47317
  const rect = this.path.getMbr().copy();
@@ -47684,7 +47747,7 @@ var init_Video = __esm(() => {
47684
47747
  init_Path2();
47685
47748
  init_Transformation2();
47686
47749
  init_Settings();
47687
- init_BaseItem2();
47750
+ init_BaseItem();
47688
47751
  init_MediaHelpers();
47689
47752
  videoIcon = conf.documentFactory.createElement("img");
47690
47753
  videoIcon.src = VIDEO_ICON_SRC;
@@ -48327,7 +48390,7 @@ var init_Drawing = __esm(() => {
48327
48390
  init_DrawingCommand();
48328
48391
  init_LinkTo();
48329
48392
  init_Settings();
48330
- init_BaseItem2();
48393
+ init_BaseItem();
48331
48394
  init_Color();
48332
48395
  Drawing = class Drawing extends BaseItem {
48333
48396
  points;
@@ -48747,7 +48810,7 @@ var init_Group = __esm(() => {
48747
48810
  init_Point();
48748
48811
  init_Transformation();
48749
48812
  init_LinkTo();
48750
- init_BaseItem2();
48813
+ init_BaseItem();
48751
48814
  Group = class Group extends BaseItem {
48752
48815
  events;
48753
48816
  linkTo;
@@ -48807,7 +48870,7 @@ var init_Group = __esm(() => {
48807
48870
  return this;
48808
48871
  }
48809
48872
  getMbr() {
48810
- const children = this.index.list();
48873
+ const children = this.index.listAll();
48811
48874
  if (children.length === 0) {
48812
48875
  return new Mbr(this.left, this.top, this.right, this.bottom);
48813
48876
  }
@@ -48847,10 +48910,10 @@ var init_Group = __esm(() => {
48847
48910
  this.getMbr();
48848
48911
  }
48849
48912
  getChildrenIds() {
48850
- return this.index.list().map((item) => item.getId());
48913
+ return this.index.listAll().map((item) => item.getId());
48851
48914
  }
48852
48915
  getChildren() {
48853
- return this.index.list();
48916
+ return this.index.listAll();
48854
48917
  }
48855
48918
  getLinkTo() {
48856
48919
  return this.linkTo.link;
@@ -48898,7 +48961,7 @@ var init_Group = __esm(() => {
48898
48961
  const ctx = context.ctx;
48899
48962
  ctx.save();
48900
48963
  this.transformation.applyToContext(ctx);
48901
- for (const child of this.index.list()) {
48964
+ for (const child of this.index.listAll()) {
48902
48965
  child.render(context);
48903
48966
  }
48904
48967
  ctx.restore();
@@ -49006,7 +49069,7 @@ function createDrawing(id, data, board) {
49006
49069
  if (!isDrawingData(data)) {
49007
49070
  throw new Error("Invalid data for Drawing");
49008
49071
  }
49009
- const drawing = new Drawing(board, [], board.events).setId(id).deserialize({ ...data, id });
49072
+ const drawing = new Drawing(board, [], board.events).setId(id).setId(id).deserialize({ ...data, id });
49010
49073
  return drawing;
49011
49074
  }
49012
49075
  function createFrame(id, data, board) {
@@ -49027,7 +49090,7 @@ function createGroup(id, data, board) {
49027
49090
  if (!isGroupData(data)) {
49028
49091
  throw new Error("Invalid data for Group");
49029
49092
  }
49030
- const group = new Group(board, board.events, data.children, id).setId(id).deserialize({ ...data, id });
49093
+ const group = new Group(board, board.events, data.childIds, id).setId(id).deserialize({ ...data, id });
49031
49094
  return group;
49032
49095
  }
49033
49096
  function isStickerData(data) {
@@ -51565,7 +51628,7 @@ function getQuickAddButtons(selection, board) {
51565
51628
  }
51566
51629
  const newMbr = new Mbr(newItemData.transformation?.translateX, newItemData.transformation?.translateY, (newItemData.transformation?.translateX || 0) + newWidth, (newItemData.transformation?.translateY || 0) + newHeight);
51567
51630
  let step = 1;
51568
- while (board.index.getItemsEnclosedOrCrossed(newMbr.left, newMbr.top, newMbr.right, newMbr.bottom).filter((item) => item.itemType !== "Connector").length > 0) {
51631
+ while (board.index.listEnclosedOrCrossedBy(newMbr.left, newMbr.top, newMbr.right, newMbr.bottom).filter((item) => item.itemType !== "Connector").length > 0) {
51569
51632
  const xDirection = step % 2 === 0 ? -1 : 1;
51570
51633
  const yDirection = newItemData.itemType === "AINode" ? -1 : xDirection;
51571
51634
  newMbr.transform(new Matrix(iterAdjustment[index2].x * xDirection * step, iterAdjustment[index2].y * yDirection * (newItemData.itemType === "AINode" ? 1 : step)));
@@ -51807,7 +51870,7 @@ function getQuickAddButtons(selection, board) {
51807
51870
  var offsets;
51808
51871
  var init_QuickAddButtons2 = __esm(() => {
51809
51872
  init_Items();
51810
- init_BaseItem2();
51873
+ init_BaseItem();
51811
51874
  init_SessionStorage();
51812
51875
  init_QuickAddButtons();
51813
51876
  init_quickAddHelpers();
@@ -52240,7 +52303,7 @@ class AlignmentHelper {
52240
52303
  var RELATIVE_ALIGNMENT_COLOR = "#4778F5";
52241
52304
  var init_RelativeAlignment = __esm(() => {
52242
52305
  init_Items();
52243
- init_BaseItem();
52306
+ init_BaseItem2();
52244
52307
  });
52245
52308
 
52246
52309
  // src/Tools/RelativeAlignment/index.ts
@@ -53841,7 +53904,7 @@ var init_AddStar = __esm(() => {
53841
53904
  // src/Items/Examples/Star/Star.ts
53842
53905
  var defaultStarData, starPath, Star2;
53843
53906
  var init_Star2 = __esm(() => {
53844
- init_BaseItem2();
53907
+ init_BaseItem();
53845
53908
  init_Point();
53846
53909
  init_Path();
53847
53910
  init_Line();
@@ -54023,7 +54086,7 @@ var init_AddCounter = __esm(() => {
54023
54086
  // src/Items/Examples/Counter/Counter.ts
54024
54087
  var defaultCounterData, COUNTER_DIMENSIONS, Counter;
54025
54088
  var init_Counter = __esm(() => {
54026
- init_BaseItem2();
54089
+ init_BaseItem();
54027
54090
  init_Point();
54028
54091
  init_Path();
54029
54092
  init_Line();
@@ -54142,7 +54205,7 @@ var init_HotkeyRegistry = __esm(() => {
54142
54205
  // src/Items/Examples/CardGame/Card/Card.ts
54143
54206
  var defaultCardData, Card;
54144
54207
  var init_Card = __esm(() => {
54145
- init_BaseItem2();
54208
+ init_BaseItem();
54146
54209
  init_Path();
54147
54210
  init_RegisterItem();
54148
54211
  init_Settings();
@@ -54392,7 +54455,7 @@ function createDeck(event, board) {
54392
54455
  if (single && single.itemType === "Deck") {
54393
54456
  return;
54394
54457
  }
54395
- const cardsOrDecks = board.selection.items.list();
54458
+ const cardsOrDecks = board.selection.items.listAll();
54396
54459
  const onlyCards = board.selection.items.isAllItemsType("Card");
54397
54460
  if (onlyCards) {
54398
54461
  const deck = new Deck(board, "");
@@ -54408,12 +54471,12 @@ function createDeck(event, board) {
54408
54471
  if (item.itemType === "Card") {
54409
54472
  cards.push(item);
54410
54473
  } else if (item.itemType === "Deck") {
54474
+ const deck = item;
54411
54475
  if (mainDeck) {
54412
- cards.push(...mainDeck.getDeck());
54413
- board.remove(mainDeck);
54414
- mainDeck = item;
54476
+ cards.push(...deck.getDeck());
54477
+ board.remove(deck);
54415
54478
  } else {
54416
- mainDeck = item;
54479
+ mainDeck = deck;
54417
54480
  }
54418
54481
  }
54419
54482
  });
@@ -54426,9 +54489,10 @@ function createDeck(event, board) {
54426
54489
  }
54427
54490
  var defaultDeckData, Deck;
54428
54491
  var init_Deck = __esm(() => {
54429
- init_BaseItem2();
54492
+ init_BaseItem();
54430
54493
  init_RegisterItem();
54431
54494
  init_Card();
54495
+ init_DrawingContext();
54432
54496
  init_Settings();
54433
54497
  init_Path2();
54434
54498
  init_HotkeyRegistry();
@@ -54447,9 +54511,9 @@ var init_Deck = __esm(() => {
54447
54511
  drawingContext = null;
54448
54512
  constructor(board, id = "") {
54449
54513
  super(board, id, defaultDeckData, true);
54450
- this.index.getUnderPoint = () => [];
54451
- this.index.getEnclosed = () => [];
54452
- this.index.getEnclosedOrCrossed = () => [];
54514
+ this.index.listUnderPoint = () => [];
54515
+ this.index.listEnclosedBy = () => [];
54516
+ this.index.listEnclosedOrCrossedBy = () => [];
54453
54517
  this.transformation.subject.subscribe(() => {
54454
54518
  this.updateMbr();
54455
54519
  this.subject.publish(this);
@@ -54471,7 +54535,7 @@ var init_Deck = __esm(() => {
54471
54535
  const canAddItem = !this.index?.getById(childId) && foundItem instanceof Card && (typeof this.isPerpendicular === "undefined" || this.isPerpendicular === foundItem.getIsRotatedPerpendicular()) && (!firstCardDimensions || firstCardDimensions.width === foundItem.getDimensions().width && firstCardDimensions.height === foundItem.getDimensions().height);
54472
54536
  if (canAddItem) {
54473
54537
  this.isPerpendicular = foundItem.getIsRotatedPerpendicular();
54474
- foundItem.transformation.setLocal(this.left + (this.index?.list().length || 0) * (this.isPerpendicular ? 0 : conf.DECK_HORIZONTAL_OFFSET), this.top + (this.index?.list().length || 0) * (this.isPerpendicular ? conf.DECK_VERTICAL_OFFSET : 0));
54538
+ foundItem.transformation.setLocal(this.left + (this.index?.listAll().length || 0) * (this.isPerpendicular ? 0 : conf.DECK_HORIZONTAL_OFFSET), this.top + (this.index?.listAll().length || 0) * (this.isPerpendicular ? conf.DECK_VERTICAL_OFFSET : 0));
54475
54539
  if (firstCard) {
54476
54540
  const { scaleX, scaleY } = foundItem.transformation.getMatrixData();
54477
54541
  const { scaleX: targetScaleX, scaleY: targetScaleY } = firstCard.transformation.getMatrixData();
@@ -54511,31 +54575,33 @@ var init_Deck = __esm(() => {
54511
54575
  this.subject.publish(this);
54512
54576
  }
54513
54577
  getDeck() {
54514
- return this.index?.list() || [];
54578
+ return this.index?.listAll() || [];
54515
54579
  }
54516
54580
  getTopCard() {
54517
- const card = this.index?.list()[this.index?.list().length - 1];
54581
+ const cards = this.index?.listAll() || [];
54582
+ const card = cards[cards.length - 1];
54518
54583
  if (card) {
54519
54584
  this.removeChildItems(card);
54520
54585
  return card;
54521
54586
  }
54522
54587
  }
54523
54588
  getCards(count) {
54524
- const cards = this.index?.list().reverse().slice(0, count);
54525
- if (cards) {
54589
+ const cards = (this.index?.listAll() || []).reverse().slice(0, count);
54590
+ if (cards.length > 0) {
54526
54591
  this.removeChildItems(cards);
54527
54592
  return cards;
54528
54593
  }
54529
54594
  }
54530
54595
  getBottomCard() {
54531
- const card = this.index?.list()[0];
54596
+ const card = this.index?.listAll()[0];
54532
54597
  if (card) {
54533
54598
  this.removeChildItems(card);
54534
54599
  return card;
54535
54600
  }
54536
54601
  }
54537
54602
  getRandomCard() {
54538
- const card = this.index?.list()[Math.floor(Math.random() * this.index?.list().length)];
54603
+ const cards = this.index?.listAll() || [];
54604
+ const card = cards[Math.floor(Math.random() * cards.length)];
54539
54605
  if (card) {
54540
54606
  this.removeChildItems(card);
54541
54607
  return card;
@@ -54545,20 +54611,20 @@ var init_Deck = __esm(() => {
54545
54611
  if (!this.index) {
54546
54612
  return;
54547
54613
  }
54548
- const shuffled = [...this.index.list()];
54614
+ const shuffled = [...this.index.listAll()];
54549
54615
  for (let i = shuffled.length - 1;i > 0; i--) {
54550
54616
  const j = Math.floor(Math.random() * (i + 1));
54551
54617
  [shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
54552
54618
  }
54553
54619
  this.emitAnimation();
54554
- this.removeChildItems(this.index.list());
54620
+ this.removeChildItems(this.index.listAll());
54555
54621
  this.addChildItems(shuffled);
54556
54622
  }
54557
54623
  flipDeck() {
54558
- if (!this.index || !this.index.list().length) {
54624
+ if (!this.index || !this.index.listAll().length) {
54559
54625
  return;
54560
54626
  }
54561
- const cards = this.index.list();
54627
+ const cards = this.index.listAll();
54562
54628
  cards[0].toggleIsOpen(cards);
54563
54629
  const reversed = [...cards].reverse();
54564
54630
  this.removeChildItems(cards);
@@ -54579,7 +54645,7 @@ var init_Deck = __esm(() => {
54579
54645
  }
54580
54646
  updateMbr() {
54581
54647
  const { translateX, translateY } = this.transformation.getMatrixData();
54582
- const items = this.index.list();
54648
+ const items = this.index.listAll();
54583
54649
  const itemsMbr = items[0]?.getMbr().combine(items.slice(1).map((item) => item.getMbr()));
54584
54650
  this.left = translateX;
54585
54651
  this.top = translateY;
@@ -54647,7 +54713,7 @@ var init_Deck = __esm(() => {
54647
54713
  }
54648
54714
  renderHTML(documentFactory) {
54649
54715
  const div = super.renderHTML(documentFactory);
54650
- const cards = this.index?.list();
54716
+ const cards = this.index?.listAll();
54651
54717
  const topCard = cards[cards.length - 1];
54652
54718
  if (!topCard) {
54653
54719
  return div;
@@ -54656,7 +54722,7 @@ var init_Deck = __esm(() => {
54656
54722
  const transform = `translate(${translateX}px, ${translateY}px) scale(1, 1)`;
54657
54723
  const topCardElement = topCard.renderHTML(documentFactory);
54658
54724
  div.appendChild(topCardElement);
54659
- const offset = ((this.index?.list().length || 0) - 1) * 2;
54725
+ const offset = ((this.index?.listAll().length || 0) - 1) * 2;
54660
54726
  topCardElement.style.transform = `translate(${offset}px, ${0}px) scale(1, 1)`;
54661
54727
  div.id = this.getId();
54662
54728
  div.style.width = `${this.getWidth()}px`;
@@ -54669,7 +54735,7 @@ var init_Deck = __esm(() => {
54669
54735
  return div;
54670
54736
  }
54671
54737
  updateCache(context) {
54672
- const cards = this.index?.list();
54738
+ const cards = this.index?.listAll();
54673
54739
  const topCard = cards[cards.length - 1];
54674
54740
  const topCardImage = topCard?.getImage();
54675
54741
  const width2 = this.getWidth();
@@ -54683,7 +54749,7 @@ var init_Deck = __esm(() => {
54683
54749
  const tempCtx = tempCanvas.getContext("2d");
54684
54750
  if (!tempCtx)
54685
54751
  return;
54686
- const tempContext = { ...context, ctx: tempCtx };
54752
+ const tempContext = new DrawingContext(context.camera, tempCtx, context.cursorCtx, context.matrix);
54687
54753
  cards.forEach((_, index2) => {
54688
54754
  topCard.render(tempContext, this.isPerpendicular ? 0 : index2 * conf.DECK_HORIZONTAL_OFFSET, this.isPerpendicular ? index2 * conf.DECK_VERTICAL_OFFSET : 0);
54689
54755
  });
@@ -54692,7 +54758,7 @@ var init_Deck = __esm(() => {
54692
54758
  this.updateMbr();
54693
54759
  }
54694
54760
  getFirstCard() {
54695
- return this.index?.list()[0];
54761
+ return this.index?.listAll()[0];
54696
54762
  }
54697
54763
  };
54698
54764
  registerItem({
@@ -54826,7 +54892,7 @@ var init_AddDice = __esm(() => {
54826
54892
  // src/Items/Examples/CardGame/Dice/Dice.ts
54827
54893
  var TIMEOUT = 2000, defaultDiceData, Dice;
54828
54894
  var init_Dice = __esm(() => {
54829
- init_BaseItem2();
54895
+ init_BaseItem();
54830
54896
  init_Items();
54831
54897
  init_RoundedRectangle();
54832
54898
  init_Items();
@@ -55227,7 +55293,7 @@ var init_AddScreen = __esm(() => {
55227
55293
  // src/Items/Examples/CardGame/Screen/Screen.ts
55228
55294
  var screenPath, defaultScreenData, Screen;
55229
55295
  var init_Screen = __esm(() => {
55230
- init_BaseItem2();
55296
+ init_BaseItem();
55231
55297
  init_RegisterItem();
55232
55298
  init_Path2();
55233
55299
  init_Line2();
@@ -55374,9 +55440,9 @@ var init_Screen = __esm(() => {
55374
55440
  applyOwnerId(ownerId) {
55375
55441
  this.ownerId = ownerId;
55376
55442
  if (!this.ownerId) {
55377
- this.index.getUnderPoint = () => [];
55378
- this.index.getEnclosed = () => [];
55379
- this.index.getEnclosedOrCrossed = () => [];
55443
+ this.index.listUnderPoint = () => [];
55444
+ this.index.listEnclosedBy = () => [];
55445
+ this.index.listEnclosedOrCrossedBy = () => [];
55380
55446
  }
55381
55447
  }
55382
55448
  transformPath() {
@@ -55399,16 +55465,17 @@ var init_Screen = __esm(() => {
55399
55465
  this.applyBackgroundUrl(this.backgroundUrl);
55400
55466
  }
55401
55467
  if (!this.ownerId) {
55402
- this.index.getUnderPoint = () => [];
55403
- this.index.getEnclosed = () => [];
55404
- this.index.getEnclosedOrCrossed = () => [];
55468
+ this.index.listUnderPoint = () => [];
55469
+ this.index.listEnclosedBy = () => [];
55470
+ this.index.listEnclosedOrCrossedBy = () => [];
55405
55471
  }
55406
55472
  this.transformPath();
55407
55473
  this.subject.publish(this);
55408
55474
  return this;
55409
55475
  }
55410
55476
  getRandomItem() {
55411
- const item = this.index?.list()[Math.floor(Math.random() * this.index?.list().length)];
55477
+ const items = this.index?.listAll() || [];
55478
+ const item = items[Math.floor(Math.random() * items.length)];
55412
55479
  if (item) {
55413
55480
  this.removeChildItems(item);
55414
55481
  return item;
@@ -55457,7 +55524,7 @@ var init_Screen2 = __esm(() => {
55457
55524
 
55458
55525
  // src/Items/index.ts
55459
55526
  var init_Items = __esm(() => {
55460
- init_BaseItem();
55527
+ init_BaseItem2();
55461
55528
  init_Point2();
55462
55529
  init_Line2();
55463
55530
  init_Curve2();
@@ -56332,7 +56399,7 @@ var init_Shape = __esm(() => {
56332
56399
  init_Connector2();
56333
56400
  init_ControlPoint();
56334
56401
  init_Settings();
56335
- init_BaseItem2();
56402
+ init_BaseItem();
56336
56403
  init_Color();
56337
56404
  defaultShapeData = new DefaultShapeData;
56338
56405
  Shapes = { ...BasicShapes, ...BPMN };
@@ -56858,7 +56925,7 @@ var init_Placeholder2 = __esm(() => {
56858
56925
  init_Transformation();
56859
56926
  init_PlaceholderCommand();
56860
56927
  init_getResizeMatrix();
56861
- init_BaseItem2();
56928
+ init_BaseItem();
56862
56929
  Placeholder2 = class Placeholder2 extends BaseItem {
56863
56930
  events;
56864
56931
  miroData;
@@ -57167,7 +57234,7 @@ var init_Image = __esm(() => {
57167
57234
  init_Placeholder2();
57168
57235
  init_LinkTo();
57169
57236
  init_Settings();
57170
- init_BaseItem2();
57237
+ init_BaseItem();
57171
57238
  init_MediaHelpers();
57172
57239
  ImageItem = class ImageItem extends BaseItem {
57173
57240
  events;
@@ -57730,10 +57797,20 @@ function handleBoardEventMessage(message, board) {
57730
57797
  if (isEventFromCurrentUser) {
57731
57798
  return;
57732
57799
  }
57733
- log.insertEventsFromOtherConnections({
57734
- ...event,
57735
- userId: Number(message.userId)
57736
- });
57800
+ if ("operations" in event.body) {
57801
+ log.insertEventsFromOtherConnections({
57802
+ ...event,
57803
+ body: {
57804
+ ...event.body,
57805
+ userId: Number(message.userId)
57806
+ }
57807
+ });
57808
+ } else {
57809
+ log.insertEventsFromOtherConnections({
57810
+ ...event,
57811
+ userId: Number(message.userId)
57812
+ });
57813
+ }
57737
57814
  const last = log.getLastConfirmed();
57738
57815
  if (last) {
57739
57816
  board.events.subject.publish(last);
@@ -57751,7 +57828,7 @@ function handleBoardSubscriptionCompletedMsg(msg, board) {
57751
57828
  handleHTMLSnapshotApplication(msg.JSONSnapshot, board);
57752
57829
  log.list.clearConfirmedRecords();
57753
57830
  }
57754
- handleBoardEventListApplication(msg.eventsSinceLastSnapshot, board);
57831
+ handleBoardEventListApplication(expandEvents(msg.eventsSinceLastSnapshot), board);
57755
57832
  board.setInterfaceType(msg.mode);
57756
57833
  board.subject.publish();
57757
57834
  onBoardLoad(board);
@@ -59963,7 +60040,7 @@ init_Settings();
59963
60040
  init_QuickAddButtons3();
59964
60041
 
59965
60042
  // src/Selection/SelectionItems.ts
59966
- init_BaseItem();
60043
+ init_BaseItem2();
59967
60044
 
59968
60045
  class SelectionItems {
59969
60046
  items = new Map;
@@ -59990,6 +60067,9 @@ class SelectionItems {
59990
60067
  list() {
59991
60068
  return Array.from(this.items.values());
59992
60069
  }
60070
+ listAll() {
60071
+ return this.list();
60072
+ }
59993
60073
  isEmpty() {
59994
60074
  return this.items.size === 0;
59995
60075
  }
@@ -60285,7 +60365,7 @@ init_RichText();
60285
60365
  init_AINode();
60286
60366
  init_Sticker();
60287
60367
  init_Frame();
60288
- init_BaseItem();
60368
+ init_BaseItem2();
60289
60369
  function handleMultipleItemsResize({
60290
60370
  board,
60291
60371
  resize,
@@ -60668,7 +60748,7 @@ init_Image();
60668
60748
  init_SessionStorage();
60669
60749
  init_Point();
60670
60750
  init_Items();
60671
- init_BaseItem();
60751
+ init_BaseItem2();
60672
60752
  function transformItems({
60673
60753
  board,
60674
60754
  selection,
@@ -63453,8 +63533,9 @@ class Board {
63453
63533
  const data = Array.from(items.children).map((el) => this.parseHTML(el));
63454
63534
  for (const parsedData of data) {
63455
63535
  if ("childrenMap" in parsedData) {
63456
- const addedFrame = this.add(this.createItem(this.getNewItemId(), parsedData.data));
63457
- const addedChildren = Object.values(parsedData.childrenMap).map((childData) => {
63536
+ const frameData = parsedData;
63537
+ const addedFrame = this.add(this.createItem(this.getNewItemId(), frameData.data));
63538
+ const addedChildren = Object.values(frameData.childrenMap).map((childData) => {
63458
63539
  const created = this.createItem(this.getNewItemId(), childData);
63459
63540
  const added = this.add(created);
63460
63541
  idsMap[childData.id] = added.getId();
@@ -63467,17 +63548,18 @@ class Board {
63467
63548
  return added;
63468
63549
  });
63469
63550
  addedFrame.addChildItems(addedChildren);
63470
- parsedData.data.children = addedChildren.map((item) => item.getId());
63471
- idsMap[parsedData.data.id] = addedFrame.getId();
63551
+ frameData.data.children = addedChildren.map((item) => item.getId());
63552
+ idsMap[frameData.data.id] = addedFrame.getId();
63472
63553
  } else {
63473
- const added = this.add(this.createItem(this.getNewItemId(), parsedData));
63554
+ const itemData = parsedData;
63555
+ const added = this.add(this.createItem(this.getNewItemId(), itemData));
63474
63556
  if (added.itemType === "Connector") {
63475
63557
  addedConnectors.push({
63476
63558
  item: added,
63477
- data: parsedData
63559
+ data: itemData
63478
63560
  });
63479
63561
  }
63480
- idsMap[parsedData.id] = added.getId();
63562
+ idsMap[itemData.id] = added.getId();
63481
63563
  }
63482
63564
  }
63483
63565
  addedConnectors.forEach((connector) => {
@@ -63521,12 +63603,13 @@ class Board {
63521
63603
  this.index.insert(item);
63522
63604
  return item;
63523
63605
  };
63524
- for (const itemData of items) {
63525
- if ("childrenMap" in itemData) {
63526
- Object.values(itemData.childrenMap).map((childData) => addItem(childData));
63527
- addItem(itemData.data);
63606
+ for (const rawItemData of items) {
63607
+ if ("childrenMap" in rawItemData) {
63608
+ const frameData = rawItemData;
63609
+ Object.values(frameData.childrenMap).map((childData) => addItem(childData));
63610
+ addItem(frameData.data);
63528
63611
  } else {
63529
- addItem(itemData);
63612
+ addItem(rawItemData);
63530
63613
  }
63531
63614
  }
63532
63615
  for (const key in createdConnectors) {
@@ -63959,8 +64042,9 @@ class Board {
63959
64042
  itemData.transformation.translateX = translateX + width2 * 10 + 10;
63960
64043
  }
63961
64044
  }
63962
- if ("children" in itemData && itemData.children?.length) {
63963
- itemData.children = itemData.children.map((childId) => newItemIdMap[childId]);
64045
+ const itemDataWithChildren = itemData;
64046
+ if ("children" in itemDataWithChildren && itemDataWithChildren.children?.length) {
64047
+ itemDataWithChildren.children = itemDataWithChildren.children.map((childId) => newItemIdMap[childId]);
63964
64048
  }
63965
64049
  newMap[newItemId] = itemData;
63966
64050
  }
@@ -64143,7 +64227,7 @@ function initI18N(i18nInstance) {
64143
64227
  // src/index.ts
64144
64228
  init_MediaHelpers();
64145
64229
  init_CreateCommand();
64146
- init_BaseItem2();
64230
+ init_BaseItem();
64147
64231
  init_Events();
64148
64232
  BaseItem.createCommand = createCommand;
64149
64233
  Events.createCommand = createCommand;