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/index.js CHANGED
@@ -4177,18 +4177,23 @@ function createEventsList(commandFactory) {
4177
4177
  return item;
4178
4178
  if (typeof item === "string")
4179
4179
  return [item];
4180
- return Object.keys(item);
4180
+ if (item && typeof item === "object")
4181
+ return Object.keys(item);
4181
4182
  }
4182
- if ("itemsMap" in op)
4183
+ if ("itemsMap" in op && op.itemsMap)
4183
4184
  return Object.keys(op.itemsMap);
4184
4185
  if ("items" in op) {
4185
4186
  const items = op.items;
4186
- if (Array.isArray(items))
4187
- return items.map((i) => typeof i === "string" ? i : i.id);
4188
- return Object.keys(items);
4187
+ if (Array.isArray(items)) {
4188
+ return items.map((i) => typeof i === "string" ? i : i.id).filter(Boolean);
4189
+ }
4190
+ if (items && typeof items === "object" && items !== null)
4191
+ return Object.keys(items);
4192
+ }
4193
+ if ("itemsOps" in op) {
4194
+ const itemsOps = op.itemsOps;
4195
+ return itemsOps.map((io) => io.item);
4189
4196
  }
4190
- if ("itemsOps" in op)
4191
- return op.itemsOps.map((io) => io.item);
4192
4197
  return [];
4193
4198
  }
4194
4199
  return {
@@ -5847,16 +5852,17 @@ var init_transformEvents = __esm(() => {
5847
5852
  function expandEvents(events) {
5848
5853
  return events.flatMap((event) => {
5849
5854
  if ("operations" in event.body) {
5850
- return event.body.operations.map((operation) => ({
5855
+ const { operations, lastKnownOrder, ...bodyWithoutOps } = event.body;
5856
+ return operations.map((operation) => ({
5851
5857
  order: event.order,
5852
5858
  body: {
5853
- eventId: operation.actualId || event.body.eventId,
5854
- userId: event.body.userId,
5855
- boardId: event.body.boardId,
5859
+ eventId: operation.actualId || bodyWithoutOps.eventId,
5860
+ userId: bodyWithoutOps.userId,
5861
+ boardId: bodyWithoutOps.boardId,
5856
5862
  operation
5857
5863
  },
5858
- userId: event.body.userId,
5859
- lastKnownOrder: "lastKnownOrder" in event ? event.lastKnownOrder : event.body.lastKnownOrder
5864
+ userId: bodyWithoutOps.userId,
5865
+ lastKnownOrder
5860
5866
  }));
5861
5867
  } else {
5862
5868
  return [event];
@@ -5968,13 +5974,15 @@ var init_insertEventsFromOtherConnectionsIntoList = __esm(() => {
5968
5974
  function deserializeAndApplyToList(events, list, board) {
5969
5975
  list.clear();
5970
5976
  for (const event of events) {
5971
- const body = event.body;
5972
- if (body.operations && Array.isArray(body.operations)) {
5973
- for (const op of body.operations) {
5977
+ if ("operations" in event.body) {
5978
+ const { operations, lastKnownOrder, ...bodyWithoutOps } = event.body;
5979
+ for (const op of operations) {
5974
5980
  const singleEvent = {
5975
- ...event,
5981
+ order: event.order,
5982
+ lastKnownOrder,
5983
+ userId: bodyWithoutOps.userId,
5976
5984
  body: {
5977
- ...event.body,
5985
+ ...bodyWithoutOps,
5978
5986
  operation: op
5979
5987
  }
5980
5988
  };
@@ -11560,7 +11568,7 @@ class RTreeIndex {
11560
11568
  this.tree.remove(item);
11561
11569
  }
11562
11570
  }
11563
- list() {
11571
+ listAll() {
11564
11572
  const containers = this.tree.all();
11565
11573
  const items = [];
11566
11574
  for (const container of containers) {
@@ -11568,7 +11576,7 @@ class RTreeIndex {
11568
11576
  }
11569
11577
  return items;
11570
11578
  }
11571
- getEnclosed(rect) {
11579
+ listEnclosedBy(rect) {
11572
11580
  return this.tree.search({
11573
11581
  minX: rect.left,
11574
11582
  minY: rect.top,
@@ -11576,7 +11584,7 @@ class RTreeIndex {
11576
11584
  maxY: rect.bottom
11577
11585
  }).filter((container) => container.item.isEnclosedBy(rect)).map((container) => container.item);
11578
11586
  }
11579
- getEnclosedOrCrossedBy(rect) {
11587
+ listEnclosedOrCrossedBy(rect) {
11580
11588
  return this.tree.search({
11581
11589
  minX: rect.left,
11582
11590
  minY: rect.top,
@@ -11584,7 +11592,7 @@ class RTreeIndex {
11584
11592
  maxY: rect.bottom
11585
11593
  }).filter((container) => container.item.isEnclosedOrCrossedBy(rect)).map((container) => container.item);
11586
11594
  }
11587
- getUnderPoint(point, tolerance = 5) {
11595
+ listUnderPoint(point, tolerance = 5) {
11588
11596
  return this.tree.search({
11589
11597
  minX: point.x,
11590
11598
  minY: point.y,
@@ -11592,7 +11600,7 @@ class RTreeIndex {
11592
11600
  maxY: point.y
11593
11601
  }).filter((container) => container.item.isUnderPoint(point, tolerance)).map((container) => container.item);
11594
11602
  }
11595
- getRectsEnclosedOrCrossedBy(rect) {
11603
+ listRectsEnclosedOrCrossedBy(rect) {
11596
11604
  return this.tree.search({
11597
11605
  minX: rect.left,
11598
11606
  minY: rect.top,
@@ -11608,9 +11616,27 @@ class RTreeIndex {
11608
11616
  maxY: rect.bottom
11609
11617
  });
11610
11618
  }
11611
- getNearestTo(point, maxItems, filter, maxDistance) {
11619
+ listNearestTo(point, maxItems, filter, maxDistance) {
11612
11620
  return knn(this.tree, point.x, point.y, maxItems, (container) => filter(container.item), maxDistance).map((container) => container.item);
11613
11621
  }
11622
+ getById(id) {
11623
+ return this.listAll().find((item) => item.getId() === id);
11624
+ }
11625
+ findById(id) {
11626
+ return this.getById(id);
11627
+ }
11628
+ getByZIndex(index) {
11629
+ return this.listAll()[index];
11630
+ }
11631
+ getLastZIndex() {
11632
+ return this.listAll().length - 1;
11633
+ }
11634
+ copy() {
11635
+ return this.listAll().map((item) => ({
11636
+ ...item.serialize(),
11637
+ id: item.getId()
11638
+ }));
11639
+ }
11614
11640
  batchInsert(batch) {
11615
11641
  for (const one of batch) {
11616
11642
  this.insert(one);
@@ -11682,35 +11708,31 @@ class LayeredIndex {
11682
11708
  isT(item) {
11683
11709
  return true;
11684
11710
  }
11685
- findById(id) {
11686
- const container = this.map.get(id);
11687
- return container ? container.item : undefined;
11688
- }
11689
- getEnclosed(rect) {
11711
+ listEnclosedBy(rect) {
11690
11712
  let items = [];
11691
11713
  for (const layer of this.layers.array) {
11692
- items = items.concat(layer.getEnclosed(rect));
11714
+ items = items.concat(layer.listEnclosedBy(rect));
11693
11715
  }
11694
11716
  return items;
11695
11717
  }
11696
- getEnclosedOrCrossedBy(rect) {
11718
+ listEnclosedOrCrossedBy(rect) {
11697
11719
  let items = [];
11698
11720
  for (const layer of this.layers.array) {
11699
- items = items.concat(layer.getEnclosedOrCrossedBy(rect));
11721
+ items = items.concat(layer.listEnclosedOrCrossedBy(rect));
11700
11722
  }
11701
11723
  return items;
11702
11724
  }
11703
- getUnderPoint(point, tolerance = 5) {
11725
+ listUnderPoint(point, tolerance = 5) {
11704
11726
  let items = [];
11705
11727
  for (const layer of this.layers.array) {
11706
- const layerItems = layer.getUnderPoint(point, tolerance);
11728
+ const layerItems = layer.listUnderPoint(point, tolerance);
11707
11729
  if (layerItems.length > 0) {
11708
11730
  items = items.concat(layerItems);
11709
11731
  }
11710
11732
  }
11711
11733
  return items;
11712
11734
  }
11713
- getRectsEnclosedOrCrossedBy(rect) {
11735
+ listRectsEnclosedOrCrossedBy(rect) {
11714
11736
  const items = [];
11715
11737
  const minMax = {
11716
11738
  minX: rect.left,
@@ -11734,10 +11756,10 @@ class LayeredIndex {
11734
11756
  }
11735
11757
  return false;
11736
11758
  }
11737
- getNearestTo(point, maxItems, filter, maxDistance) {
11759
+ listNearestTo(point, maxItems, filter, maxDistance) {
11738
11760
  let items = [];
11739
11761
  for (const layer of this.layers.array) {
11740
- items = items.concat(layer.getNearestTo(point, maxItems, filter, maxDistance));
11762
+ items = items.concat(layer.listNearestTo(point, maxItems, filter, maxDistance));
11741
11763
  }
11742
11764
  return items;
11743
11765
  }
@@ -11771,7 +11793,7 @@ class LayeredIndex {
11771
11793
  }
11772
11794
  const bounds = container.item.getMbrWithChildren();
11773
11795
  this.remove(container.item);
11774
- const inBounds = this.getRectsEnclosedOrCrossedBy(bounds);
11796
+ const inBounds = this.listRectsEnclosedOrCrossedBy(bounds);
11775
11797
  const containersInBounds = this.getContainersFromItems(inBounds);
11776
11798
  const containersAbove = [];
11777
11799
  const containerZIndex = this.getZIndex(container.item);
@@ -11799,7 +11821,7 @@ class LayeredIndex {
11799
11821
  }
11800
11822
  const bounds = container.item.getMbrWithChildren();
11801
11823
  this.remove(container.item);
11802
- const inBounds = this.getRectsEnclosedOrCrossedBy(bounds);
11824
+ const inBounds = this.listRectsEnclosedOrCrossedBy(bounds);
11803
11825
  const containersInBounds = this.getContainersFromItems(inBounds);
11804
11826
  const containersBelow = [];
11805
11827
  const containerZIndex = this.getZIndex(container.item);
@@ -11824,7 +11846,7 @@ class LayeredIndex {
11824
11846
  insert(item) {
11825
11847
  const toInsert = new Container(item.getId(), item, 0, this.getZIndex(item));
11826
11848
  const bounds = item.getMbrWithChildren();
11827
- const inBounds = this.getRectsEnclosedOrCrossedBy(bounds);
11849
+ const inBounds = this.listRectsEnclosedOrCrossedBy(bounds);
11828
11850
  if (inBounds.length === 0) {
11829
11851
  return this.insertContainer(toInsert);
11830
11852
  }
@@ -11921,13 +11943,32 @@ class LayeredIndex {
11921
11943
  return;
11922
11944
  }
11923
11945
  }
11924
- list() {
11946
+ listAll() {
11925
11947
  const items = [];
11926
11948
  for (const record of this.map) {
11927
11949
  items.push(record[1].item);
11928
11950
  }
11929
11951
  return items;
11930
11952
  }
11953
+ getById(id) {
11954
+ const container = this.map.get(id);
11955
+ return container ? container.item : undefined;
11956
+ }
11957
+ findById(id) {
11958
+ return this.getById(id);
11959
+ }
11960
+ getByZIndex(index) {
11961
+ return this.listAll()[index];
11962
+ }
11963
+ getLastZIndex() {
11964
+ return this.listAll().length - 1;
11965
+ }
11966
+ copy() {
11967
+ return this.listAll().map((item) => ({
11968
+ ...item.serialize(),
11969
+ id: item.getId()
11970
+ }));
11971
+ }
11931
11972
  batchInsert(items) {
11932
11973
  for (const item of items) {
11933
11974
  this.insert(item);
@@ -11944,11 +11985,6 @@ var init_LayeredIndex = __esm(() => {
11944
11985
  init_RTreeIndex();
11945
11986
  });
11946
11987
 
11947
- // src/Items/BaseItem/index.ts
11948
- var init_BaseItem = __esm(() => {
11949
- init_BaseItem2();
11950
- });
11951
-
11952
11988
  // src/SpatialIndex/SpacialIndex.ts
11953
11989
  function worldBoundsToLocal(container, left, top, right, bottom) {
11954
11990
  const inv = container.getNestingMatrix().getInverse();
@@ -11967,6 +12003,13 @@ function worldBoundsToLocal(container, left, top, right, bottom) {
11967
12003
  bottom: Math.max(corners[0].y, corners[1].y, corners[2].y, corners[3].y)
11968
12004
  };
11969
12005
  }
12006
+ function coerceMbr(left, top, right, bottom) {
12007
+ if (left instanceof Mbr)
12008
+ return left;
12009
+ if (typeof left === "object" && left !== null)
12010
+ return new Mbr(left.left, left.top, left.right, left.bottom);
12011
+ return new Mbr(left, top, right, bottom);
12012
+ }
11970
12013
 
11971
12014
  class SpatialIndex {
11972
12015
  subject = new Subject;
@@ -11987,6 +12030,9 @@ class SpatialIndex {
11987
12030
  this.Mbr = new Mbr;
11988
12031
  }
11989
12032
  insert(item) {
12033
+ if (this.itemsArray.includes(item) || this.getById(item.getId())) {
12034
+ return;
12035
+ }
11990
12036
  this.itemsArray.push(item);
11991
12037
  this.itemsIndex.insert(item);
11992
12038
  if (conf.isNode()) {
@@ -12015,7 +12061,7 @@ class SpatialIndex {
12015
12061
  remove(item, preserveChildren = false) {
12016
12062
  const baseItem = item;
12017
12063
  if (!preserveChildren && baseItem.index) {
12018
- baseItem.removeChildItems(baseItem.index.list());
12064
+ baseItem.removeChildItems(baseItem.index.listAll());
12019
12065
  }
12020
12066
  this.itemsArray.splice(this.itemsArray.indexOf(item), 1);
12021
12067
  this.itemsIndex.remove(item);
@@ -12058,14 +12104,14 @@ class SpatialIndex {
12058
12104
  return items.flatMap((item) => {
12059
12105
  const baseItem = item;
12060
12106
  if (baseItem.index) {
12061
- return [item, ...baseItem.index.list()];
12107
+ return [item, ...baseItem.index.listAll()];
12062
12108
  }
12063
12109
  return item;
12064
12110
  });
12065
12111
  }
12066
12112
  getItemChildren(item) {
12067
12113
  if ("index" in item && item.index) {
12068
- return item.index.list();
12114
+ return item.index.listAll();
12069
12115
  }
12070
12116
  return [];
12071
12117
  }
@@ -12216,14 +12262,14 @@ class SpatialIndex {
12216
12262
  findById(id) {
12217
12263
  return this.getById(id);
12218
12264
  }
12219
- getEnclosed(left, top, right, bottom) {
12220
- const mbr = new Mbr(left, top, right, bottom);
12221
- const items = this.itemsIndex.getEnclosed(mbr);
12265
+ listEnclosedBy(left, top, right, bottom) {
12266
+ const mbr = coerceMbr(left, top, right, bottom);
12267
+ const items = this.itemsIndex.listEnclosedBy(mbr);
12222
12268
  const children = [];
12223
12269
  const clearItems = items.filter((item) => {
12224
12270
  if ("index" in item && item.index) {
12225
- const local = worldBoundsToLocal(item, left, top, right, bottom);
12226
- children.push(...item.index.getEnclosed(local.left, local.top, local.right, local.bottom));
12271
+ const local = worldBoundsToLocal(item, mbr.left, mbr.top, mbr.right, mbr.bottom);
12272
+ children.push(...item.index.listEnclosedBy(local.left, local.top, local.right, local.bottom));
12227
12273
  if (!item.getMbr().isEnclosedBy(mbr)) {
12228
12274
  return false;
12229
12275
  }
@@ -12232,14 +12278,14 @@ class SpatialIndex {
12232
12278
  });
12233
12279
  return [...clearItems, ...children];
12234
12280
  }
12235
- getEnclosedOrCrossed(left, top, right, bottom) {
12236
- const mbr = new Mbr(left, top, right, bottom);
12237
- const items = this.itemsIndex.getEnclosedOrCrossedBy(mbr);
12281
+ listEnclosedOrCrossedBy(left, top, right, bottom) {
12282
+ const mbr = coerceMbr(left, top, right, bottom);
12283
+ const items = this.itemsIndex.listEnclosedOrCrossedBy(mbr);
12238
12284
  const children = [];
12239
12285
  const clearItems = items.filter((item) => {
12240
12286
  if ("index" in item && item.index) {
12241
- const local = worldBoundsToLocal(item, left, top, right, bottom);
12242
- children.push(...item.index.getEnclosedOrCrossed(local.left, local.top, local.right, local.bottom));
12287
+ const local = worldBoundsToLocal(item, mbr.left, mbr.top, mbr.right, mbr.bottom);
12288
+ children.push(...item.index.listEnclosedOrCrossedBy(local.left, local.top, local.right, local.bottom));
12243
12289
  if (!item.getMbr().isEnclosedOrCrossedBy(mbr)) {
12244
12290
  return false;
12245
12291
  }
@@ -12248,14 +12294,17 @@ class SpatialIndex {
12248
12294
  });
12249
12295
  return [...clearItems, ...children];
12250
12296
  }
12251
- getUnderPoint(point, tolerance = 5) {
12252
- const items = this.itemsIndex.getUnderPoint(point, tolerance);
12297
+ listRectsEnclosedOrCrossedBy(left, top, right, bottom) {
12298
+ return this.listEnclosedOrCrossedBy(left, top, right, bottom).map((item) => item.getMbr());
12299
+ }
12300
+ listUnderPoint(point, tolerance = 5) {
12301
+ const items = this.itemsIndex.listUnderPoint(point, tolerance);
12253
12302
  const children = [];
12254
12303
  const clearItems = items.filter((item) => {
12255
12304
  if ("index" in item && item.index) {
12256
12305
  const localPt = new Point(point.x, point.y);
12257
12306
  item.getNestingMatrix().getInverse().apply(localPt);
12258
- children.push(...item.index.getUnderPoint(localPt, tolerance));
12307
+ children.push(...item.index.listUnderPoint(localPt, tolerance));
12259
12308
  if (!item.getMbr().isUnderPoint(point)) {
12260
12309
  return false;
12261
12310
  }
@@ -12267,24 +12316,8 @@ class SpatialIndex {
12267
12316
  });
12268
12317
  return [...clearItems, ...children];
12269
12318
  }
12270
- getRectsEnclosedOrCrossed(left, top, right, bottom) {
12271
- const mbr = new Mbr(left, top, right, bottom);
12272
- const items = this.itemsIndex.getRectsEnclosedOrCrossedBy(mbr);
12273
- const children = [];
12274
- const clearItems = items.filter((item) => {
12275
- if ("index" in item && item.index) {
12276
- const local = worldBoundsToLocal(item, left, top, right, bottom);
12277
- children.push(...item.index.getEnclosedOrCrossed(local.left, local.top, local.right, local.bottom));
12278
- if (!item.getMbr().isEnclosedOrCrossedBy(mbr)) {
12279
- return false;
12280
- }
12281
- }
12282
- return true;
12283
- });
12284
- return [...clearItems, ...children];
12285
- }
12286
- getItemsEnclosedOrCrossed(left, top, right, bottom) {
12287
- return this.getRectsEnclosedOrCrossed(left, top, right, bottom);
12319
+ listNearestTo(point, maxItems, filter, maxDistance) {
12320
+ return this.itemsIndex.listNearestTo(point, maxItems, filter, maxDistance);
12288
12321
  }
12289
12322
  getComments() {
12290
12323
  return this.itemsArray.filter((item) => item.itemType === "Comment");
@@ -12302,7 +12335,7 @@ class SpatialIndex {
12302
12335
  const inRange = itemsWithDistance.filter((x) => x.distance <= maxDistance);
12303
12336
  return inRange.sort((a, b) => a.distance - b.distance).slice(0, maxItems).map((x) => x.item);
12304
12337
  }
12305
- list() {
12338
+ listAll() {
12306
12339
  return this.getItemsWithIncludedChildren(this.itemsArray).concat();
12307
12340
  }
12308
12341
  getZIndex(item) {
@@ -12340,10 +12373,19 @@ class Items {
12340
12373
  this.index.change(item);
12341
12374
  }
12342
12375
  listAll() {
12343
- return this.index.list();
12376
+ return this.index.listAll();
12377
+ }
12378
+ listUnderPoint(point, tolerance = 5) {
12379
+ return this.index.listUnderPoint(point, tolerance);
12380
+ }
12381
+ listEnclosedBy(left, top, right, bottom) {
12382
+ return this.index.listEnclosedBy(left, top, right, bottom);
12383
+ }
12384
+ listEnclosedOrCrossedBy(left, top, right, bottom) {
12385
+ return this.index.listEnclosedOrCrossedBy(left, top, right, bottom);
12344
12386
  }
12345
12387
  listGroupItems() {
12346
- return this.index.list().filter((item) => ("index" in item) && item.index);
12388
+ return this.index.listAll().filter((item) => ("index" in item) && item.index);
12347
12389
  }
12348
12390
  getById(id) {
12349
12391
  return this.index.getById(id);
@@ -12352,16 +12394,16 @@ class Items {
12352
12394
  return this.index.findById(id);
12353
12395
  }
12354
12396
  getEnclosed(left, top, right, bottom) {
12355
- return this.index.getEnclosed(left, top, right, bottom);
12397
+ return this.index.listEnclosedBy(left, top, right, bottom);
12356
12398
  }
12357
12399
  getEnclosedOrCrossed(left, top, right, bottom) {
12358
- return this.index.getEnclosedOrCrossed(left, top, right, bottom);
12400
+ return this.index.listEnclosedOrCrossedBy(left, top, right, bottom);
12359
12401
  }
12360
12402
  getGroupItemsEnclosedOrCrossed(left, top, right, bottom) {
12361
- return this.index.getEnclosedOrCrossed(left, top, right, bottom).filter((item) => item instanceof BaseItem && item.index);
12403
+ return this.index.listEnclosedOrCrossedBy(left, top, right, bottom).filter((item) => ("index" in item) && item.index);
12362
12404
  }
12363
12405
  getUnderPoint(point, tolerance = 5) {
12364
- return this.index.getUnderPoint(point, tolerance);
12406
+ return this.index.listUnderPoint(point, tolerance);
12365
12407
  }
12366
12408
  getMbr() {
12367
12409
  return this.index.getMbr();
@@ -12384,25 +12426,25 @@ class Items {
12384
12426
  }
12385
12427
  getInView() {
12386
12428
  const { left, top, right, bottom } = this.view.getMbr();
12387
- return this.index.getRectsEnclosedOrCrossed(left, top, right, bottom);
12429
+ return this.index.listEnclosedOrCrossedBy(left, top, right, bottom);
12388
12430
  }
12389
12431
  getItemsInView() {
12390
12432
  const { left, top, right, bottom } = this.view.getMbr();
12391
- return this.index.getItemsEnclosedOrCrossed(left, top, right, bottom);
12433
+ return this.index.listEnclosedOrCrossedBy(left, top, right, bottom);
12392
12434
  }
12393
12435
  getGroupItemsInView() {
12394
12436
  const { left, top, right, bottom } = this.view.getMbr();
12395
12437
  return this.getGroupItemsEnclosedOrCrossed(left, top, right, bottom);
12396
12438
  }
12397
12439
  getComments() {
12398
- return this.index.getComments();
12440
+ return this.listAll().filter((item) => item.itemType === "Comment");
12399
12441
  }
12400
12442
  getUnderPointer(size = 0) {
12401
12443
  const { x, y } = this.pointer.point;
12402
12444
  const unmodifiedSize = size;
12403
12445
  size = 16;
12404
- const tolerated = this.index.getEnclosedOrCrossed(x - size, y - size, x + size, y + size);
12405
- let enclosed = tolerated.some((item) => item.itemType === "Connector") ? tolerated : this.index.getEnclosedOrCrossed(x, y, x, y);
12446
+ const tolerated = this.index.listEnclosedOrCrossedBy(x - size, y - size, x + size, y + size);
12447
+ let enclosed = tolerated.some((item) => item.itemType === "Connector") ? tolerated : this.index.listEnclosedOrCrossedBy(x, y, x, y);
12406
12448
  const underPointer = this.getUnderPoint(new Point(x, y), size);
12407
12449
  if (enclosed.length === 0) {
12408
12450
  enclosed = underPointer;
@@ -12430,7 +12472,7 @@ class Items {
12430
12472
  return [];
12431
12473
  }
12432
12474
  getNearPointer(maxDistance = 100, maxItems = 10, filter = () => true) {
12433
- return this.index.getNearestTo(this.pointer.point, maxItems, filter, maxDistance);
12475
+ return this.index.listNearestTo(this.pointer.point, maxItems, filter, maxDistance);
12434
12476
  }
12435
12477
  getZIndex(item) {
12436
12478
  return this.index.getZIndex(item);
@@ -12572,7 +12614,6 @@ var init_SpacialIndex = __esm(() => {
12572
12614
  init_Point();
12573
12615
  init_Settings();
12574
12616
  init_LayeredIndex();
12575
- init_BaseItem();
12576
12617
  });
12577
12618
 
12578
12619
  // src/SpatialIndex/SimpleSpatialIndex.ts
@@ -12589,6 +12630,9 @@ class SimpleSpatialIndex {
12589
12630
  this.Mbr = new Mbr;
12590
12631
  }
12591
12632
  insert(item) {
12633
+ if (this.itemsArray.includes(item) || this.getById(item.getId())) {
12634
+ return;
12635
+ }
12592
12636
  this.itemsArray.push(item);
12593
12637
  if (this.Mbr.getWidth() === 0 && this.Mbr.getHeight() === 0) {
12594
12638
  this.Mbr = item.getMbr().copy();
@@ -12608,9 +12652,12 @@ class SimpleSpatialIndex {
12608
12652
  };
12609
12653
  remove(item, preserveChildren = false) {
12610
12654
  if (!preserveChildren && "index" in item && item.index) {
12611
- item.removeChildItems(item.index.list());
12655
+ item.removeChildItems(item.index.listAll());
12656
+ }
12657
+ const index = this.itemsArray.indexOf(item);
12658
+ if (index !== -1) {
12659
+ this.itemsArray.splice(index, 1);
12612
12660
  }
12613
- this.itemsArray.splice(this.itemsArray.indexOf(item), 1);
12614
12661
  this.Mbr = new Mbr;
12615
12662
  this.itemsArray.forEach((item2) => this.Mbr.combine([item2.getMbr()]));
12616
12663
  this.subject.publish(this.items);
@@ -12693,16 +12740,13 @@ class SimpleSpatialIndex {
12693
12740
  this.subject.publish(this.items);
12694
12741
  }
12695
12742
  getById(id) {
12696
- const item = this.itemsArray.find((item2) => item2.getId() === id);
12697
- if (item) {
12698
- return item;
12699
- }
12743
+ return this.itemsArray.find((item) => item.getId() === id);
12700
12744
  }
12701
12745
  findById(id) {
12702
12746
  return this.getById(id);
12703
12747
  }
12704
- getEnclosed(left, top, right, bottom) {
12705
- const mbr = new Mbr(left, top, right, bottom);
12748
+ listEnclosedBy(left, top, right, bottom) {
12749
+ const mbr = coerceMbr(left, top, right, bottom);
12706
12750
  const items = [];
12707
12751
  this.itemsArray.forEach((item) => {
12708
12752
  if (item.isEnclosedBy(mbr)) {
@@ -12711,8 +12755,8 @@ class SimpleSpatialIndex {
12711
12755
  });
12712
12756
  return items;
12713
12757
  }
12714
- getEnclosedOrCrossed(left, top, right, bottom) {
12715
- const mbr = new Mbr(left, top, right, bottom);
12758
+ listEnclosedOrCrossedBy(left, top, right, bottom) {
12759
+ const mbr = coerceMbr(left, top, right, bottom);
12716
12760
  const items = [];
12717
12761
  this.itemsArray.forEach((item) => {
12718
12762
  if (item.isEnclosedOrCrossedBy(mbr)) {
@@ -12721,19 +12765,30 @@ class SimpleSpatialIndex {
12721
12765
  });
12722
12766
  return items;
12723
12767
  }
12724
- getUnderPoint(point, tolerace = 5) {
12768
+ listUnderPoint(point, tolerance = 5) {
12725
12769
  const items = [];
12726
12770
  this.itemsArray.forEach((item) => {
12727
- if (item.isUnderPoint(point, tolerace)) {
12771
+ if (item.isUnderPoint(point, tolerance)) {
12728
12772
  items.push(item);
12729
12773
  }
12730
12774
  });
12731
12775
  return items;
12732
12776
  }
12777
+ listRectsEnclosedOrCrossedBy(left, top, right, bottom) {
12778
+ return this.listEnclosedOrCrossedBy(left, top, right, bottom).map((item) => item.getMbr());
12779
+ }
12780
+ listNearestTo(point, maxItems, filter, maxDistance) {
12781
+ const itemsWithDistance = this.itemsArray.filter(filter).map((item) => ({
12782
+ item,
12783
+ distance: item.getMbr().getDistanceToPoint(point)
12784
+ }));
12785
+ const inRange = itemsWithDistance.filter((x) => x.distance <= maxDistance);
12786
+ return inRange.sort((a, b) => a.distance - b.distance).slice(0, maxItems).map((x) => x.item);
12787
+ }
12733
12788
  getMbr() {
12734
12789
  return this.Mbr;
12735
12790
  }
12736
- list() {
12791
+ listAll() {
12737
12792
  return this.itemsArray.concat();
12738
12793
  }
12739
12794
  getZIndex(item) {
@@ -12805,7 +12860,7 @@ function toLocalTransformOp(op, containerMatrix, itemId) {
12805
12860
  }
12806
12861
  }
12807
12862
  var BaseItem;
12808
- var init_BaseItem2 = __esm(() => {
12863
+ var init_BaseItem = __esm(() => {
12809
12864
  init_Mbr();
12810
12865
  init_LinkTo();
12811
12866
  init_Transformation();
@@ -13004,7 +13059,10 @@ var init_BaseItem2 = __esm(() => {
13004
13059
  if (this.parent !== childId && this.getId() !== childId && !this.hasAncestor(childId)) {
13005
13060
  if (!this.index?.getById(childId) && foundItem) {
13006
13061
  const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerNestingMatrix);
13007
- this.board.items.index.remove(foundItem, true);
13062
+ const currentParentId = foundItem.parent;
13063
+ const currentParent = currentParentId !== "Board" ? this.board.items.getById(currentParentId) : undefined;
13064
+ const sourceIndex = currentParent?.index || this.board.items.index;
13065
+ sourceIndex.remove(foundItem, true);
13008
13066
  foundItem.parent = this.getId();
13009
13067
  foundItem.onParentChanged(this.getId());
13010
13068
  foundItem.transformation.setLocalMatrix(localMatrix);
@@ -13249,7 +13307,7 @@ var init_Comment = __esm(() => {
13249
13307
  init_Line2();
13250
13308
  init_esm_browser();
13251
13309
  init_LinkTo();
13252
- init_BaseItem2();
13310
+ init_BaseItem();
13253
13311
  Comment = class Comment extends BaseItem {
13254
13312
  anchor;
13255
13313
  events;
@@ -16603,7 +16661,7 @@ var init_getListTypeAtSelectionStart = __esm(() => {
16603
16661
  });
16604
16662
 
16605
16663
  // src/Items/RichText/editorHelpers/links/setLink.ts
16606
- import { Editor as Editor12, Transforms as Transforms11 } from "slate";
16664
+ import { Editor as Editor12, Transforms as Transforms11, Text as Text6 } from "slate";
16607
16665
  var setLink = (editor, link, selection) => {
16608
16666
  if (!selection) {
16609
16667
  selectWholeText(editor);
@@ -16615,15 +16673,15 @@ var setLink = (editor, link, selection) => {
16615
16673
  }
16616
16674
  const format = link ? "rgba(71, 120, 245, 1)" : "rgb(20, 21, 26)";
16617
16675
  Transforms11.setNodes(editor, { fontColor: format }, {
16618
- match: (n) => !Editor12.isEditor(n) && n.type === "text",
16676
+ match: (n) => Text6.isText(n),
16619
16677
  split: true
16620
16678
  });
16621
- for (const [node, path2] of Editor12.nodes(editor, {
16622
- match: (n) => !Editor12.isEditor(n) && n.type === "text"
16679
+ for (const [, path2] of Editor12.nodes(editor, {
16680
+ match: (n) => Text6.isText(n)
16623
16681
  })) {
16624
16682
  const nodeRange = Editor12.range(editor, path2);
16625
16683
  Transforms11.select(editor, nodeRange);
16626
- Transforms11.setNodes(editor, { link }, { split: false, match: (n) => !Editor12.isEditor(n) && n.type === "text" });
16684
+ Transforms11.setNodes(editor, { link }, { split: false, match: (n) => Text6.isText(n) });
16627
16685
  }
16628
16686
  };
16629
16687
  var init_setLink = __esm(() => {
@@ -24983,7 +25041,7 @@ var init_setEditorFocus = () => {};
24983
25041
  import {
24984
25042
  Editor as Editor31,
24985
25043
  Element as Element9,
24986
- Text as Text6,
25044
+ Text as Text7,
24987
25045
  Transforms as Transforms21
24988
25046
  } from "slate";
24989
25047
  var isEditInProcessValue = false, counter = 0, RichText;
@@ -25006,7 +25064,7 @@ var init_RichText = __esm(() => {
25006
25064
  init_getSelectionStyles();
25007
25065
  init_setEditorFocus();
25008
25066
  init_getAllTextNodesInSelection();
25009
- init_BaseItem2();
25067
+ init_BaseItem();
25010
25068
  RichText = class RichText extends BaseItem {
25011
25069
  container;
25012
25070
  transformation;
@@ -25551,7 +25609,7 @@ var init_RichText = __esm(() => {
25551
25609
  }
25552
25610
  getMinFontSize() {
25553
25611
  const textNodes = Editor31.nodes(this.editor.editor, {
25554
- match: (n) => Text6.isText(n),
25612
+ match: (n) => Text7.isText(n),
25555
25613
  at: []
25556
25614
  });
25557
25615
  const fontSizes = [];
@@ -25972,7 +26030,7 @@ var init_AINode = __esm(() => {
25972
26030
  init_Matrix();
25973
26031
  init_Transformation();
25974
26032
  init_Settings();
25975
- init_BaseItem2();
26033
+ init_BaseItem();
25976
26034
  AINode = class AINode extends BaseItem {
25977
26035
  itemType = "AINode";
25978
26036
  parent = "Board";
@@ -26319,7 +26377,7 @@ var init_Audio = __esm(() => {
26319
26377
  init_Point();
26320
26378
  init_Line();
26321
26379
  init_Settings();
26322
- init_BaseItem2();
26380
+ init_BaseItem();
26323
26381
  AudioItem = class AudioItem extends BaseItem {
26324
26382
  events;
26325
26383
  extension;
@@ -41316,6 +41374,11 @@ var init_ShapeData = __esm(() => {
41316
41374
  ];
41317
41375
  });
41318
41376
 
41377
+ // src/Items/BaseItem/index.ts
41378
+ var init_BaseItem2 = __esm(() => {
41379
+ init_BaseItem();
41380
+ });
41381
+
41319
41382
  // src/Items/Mbr/updateRects.ts
41320
41383
  function updateRects(board, ref, mbr, verticalOffset, horizontalOffset, fit = "contextPanel") {
41321
41384
  const { selection, camera } = board;
@@ -41586,7 +41649,7 @@ var init_ControlPoint = __esm(() => {
41586
41649
  init_Transformation2();
41587
41650
  init_RichText2();
41588
41651
  init_AINode2();
41589
- init_BaseItem();
41652
+ init_BaseItem2();
41590
41653
  BoardPoint = class BoardPoint extends Point {
41591
41654
  pointType = "Board";
41592
41655
  serialize() {
@@ -42486,7 +42549,7 @@ var init_Connector = __esm(() => {
42486
42549
  init_LinkTo();
42487
42550
  init_HTMLRender();
42488
42551
  init_Settings();
42489
- init_BaseItem2();
42552
+ init_BaseItem();
42490
42553
  init_Color();
42491
42554
  init_ConnectorTypes();
42492
42555
  CONNECTOR_ANCHOR_COLOR = {
@@ -43467,7 +43530,7 @@ var init_Sticker = __esm(() => {
43467
43530
  init_SessionStorage();
43468
43531
  init_HTMLRender();
43469
43532
  init_Settings();
43470
- init_BaseItem2();
43533
+ init_BaseItem();
43471
43534
  init_Color();
43472
43535
  stickerColors = {
43473
43536
  Purple: "rgb(233, 208, 255)",
@@ -44600,7 +44663,7 @@ async function exportBoardSnapshot({
44600
44663
  context.ctx.setTransform(upscaleFactor, 0, 0, upscaleFactor, 0, 0);
44601
44664
  context.matrix.applyToContext(context.ctx);
44602
44665
  const { left, top, right, bottom } = selection;
44603
- const inView = board.items.index.getRectsEnclosedOrCrossed(left, top, right, bottom);
44666
+ const inView = board.items.index.listEnclosedOrCrossedBy(left, top, right, bottom);
44604
44667
  for (const item of inView) {
44605
44668
  item.render(context);
44606
44669
  }
@@ -44720,7 +44783,7 @@ var init_Frame = __esm(() => {
44720
44783
  init_FrameData();
44721
44784
  init_Settings();
44722
44785
  init_getResizeMatrix();
44723
- init_BaseItem();
44786
+ init_BaseItem2();
44724
44787
  init_Color();
44725
44788
  defaultFrameData = new DefaultFrameData;
44726
44789
  Frame = class Frame extends BaseItem {
@@ -44839,7 +44902,7 @@ var init_Frame = __esm(() => {
44839
44902
  return this.id;
44840
44903
  }
44841
44904
  getChildrenIds() {
44842
- return this.index?.list().map((item) => item.getId()) || [];
44905
+ return this.index?.listAll().map((item) => item.getId()) || [];
44843
44906
  }
44844
44907
  updateMbr() {
44845
44908
  const rect = this.path.getMbr().copy();
@@ -45275,7 +45338,7 @@ var init_Video = __esm(() => {
45275
45338
  init_Path2();
45276
45339
  init_Transformation2();
45277
45340
  init_Settings();
45278
- init_BaseItem2();
45341
+ init_BaseItem();
45279
45342
  init_MediaHelpers();
45280
45343
  videoIcon = conf.documentFactory.createElement("img");
45281
45344
  videoIcon.src = VIDEO_ICON_SRC;
@@ -45918,7 +45981,7 @@ var init_Drawing = __esm(() => {
45918
45981
  init_DrawingCommand();
45919
45982
  init_LinkTo();
45920
45983
  init_Settings();
45921
- init_BaseItem2();
45984
+ init_BaseItem();
45922
45985
  init_Color();
45923
45986
  Drawing = class Drawing extends BaseItem {
45924
45987
  points;
@@ -46338,7 +46401,7 @@ var init_Group = __esm(() => {
46338
46401
  init_Point();
46339
46402
  init_Transformation();
46340
46403
  init_LinkTo();
46341
- init_BaseItem2();
46404
+ init_BaseItem();
46342
46405
  Group = class Group extends BaseItem {
46343
46406
  events;
46344
46407
  linkTo;
@@ -46398,7 +46461,7 @@ var init_Group = __esm(() => {
46398
46461
  return this;
46399
46462
  }
46400
46463
  getMbr() {
46401
- const children = this.index.list();
46464
+ const children = this.index.listAll();
46402
46465
  if (children.length === 0) {
46403
46466
  return new Mbr(this.left, this.top, this.right, this.bottom);
46404
46467
  }
@@ -46438,10 +46501,10 @@ var init_Group = __esm(() => {
46438
46501
  this.getMbr();
46439
46502
  }
46440
46503
  getChildrenIds() {
46441
- return this.index.list().map((item) => item.getId());
46504
+ return this.index.listAll().map((item) => item.getId());
46442
46505
  }
46443
46506
  getChildren() {
46444
- return this.index.list();
46507
+ return this.index.listAll();
46445
46508
  }
46446
46509
  getLinkTo() {
46447
46510
  return this.linkTo.link;
@@ -46489,7 +46552,7 @@ var init_Group = __esm(() => {
46489
46552
  const ctx = context.ctx;
46490
46553
  ctx.save();
46491
46554
  this.transformation.applyToContext(ctx);
46492
- for (const child of this.index.list()) {
46555
+ for (const child of this.index.listAll()) {
46493
46556
  child.render(context);
46494
46557
  }
46495
46558
  ctx.restore();
@@ -46597,7 +46660,7 @@ function createDrawing(id, data, board) {
46597
46660
  if (!isDrawingData(data)) {
46598
46661
  throw new Error("Invalid data for Drawing");
46599
46662
  }
46600
- const drawing = new Drawing(board, [], board.events).setId(id).deserialize({ ...data, id });
46663
+ const drawing = new Drawing(board, [], board.events).setId(id).setId(id).deserialize({ ...data, id });
46601
46664
  return drawing;
46602
46665
  }
46603
46666
  function createFrame(id, data, board) {
@@ -46618,7 +46681,7 @@ function createGroup(id, data, board) {
46618
46681
  if (!isGroupData(data)) {
46619
46682
  throw new Error("Invalid data for Group");
46620
46683
  }
46621
- const group = new Group(board, board.events, data.children, id).setId(id).deserialize({ ...data, id });
46684
+ const group = new Group(board, board.events, data.childIds, id).setId(id).deserialize({ ...data, id });
46622
46685
  return group;
46623
46686
  }
46624
46687
  function isStickerData(data) {
@@ -49156,7 +49219,7 @@ function getQuickAddButtons(selection, board) {
49156
49219
  }
49157
49220
  const newMbr = new Mbr(newItemData.transformation?.translateX, newItemData.transformation?.translateY, (newItemData.transformation?.translateX || 0) + newWidth, (newItemData.transformation?.translateY || 0) + newHeight);
49158
49221
  let step = 1;
49159
- while (board.index.getItemsEnclosedOrCrossed(newMbr.left, newMbr.top, newMbr.right, newMbr.bottom).filter((item) => item.itemType !== "Connector").length > 0) {
49222
+ while (board.index.listEnclosedOrCrossedBy(newMbr.left, newMbr.top, newMbr.right, newMbr.bottom).filter((item) => item.itemType !== "Connector").length > 0) {
49160
49223
  const xDirection = step % 2 === 0 ? -1 : 1;
49161
49224
  const yDirection = newItemData.itemType === "AINode" ? -1 : xDirection;
49162
49225
  newMbr.transform(new Matrix(iterAdjustment[index2].x * xDirection * step, iterAdjustment[index2].y * yDirection * (newItemData.itemType === "AINode" ? 1 : step)));
@@ -49398,7 +49461,7 @@ function getQuickAddButtons(selection, board) {
49398
49461
  var offsets;
49399
49462
  var init_QuickAddButtons2 = __esm(() => {
49400
49463
  init_Items();
49401
- init_BaseItem2();
49464
+ init_BaseItem();
49402
49465
  init_SessionStorage();
49403
49466
  init_QuickAddButtons();
49404
49467
  init_quickAddHelpers();
@@ -49831,7 +49894,7 @@ class AlignmentHelper {
49831
49894
  var RELATIVE_ALIGNMENT_COLOR = "#4778F5";
49832
49895
  var init_RelativeAlignment = __esm(() => {
49833
49896
  init_Items();
49834
- init_BaseItem();
49897
+ init_BaseItem2();
49835
49898
  });
49836
49899
 
49837
49900
  // src/Tools/RelativeAlignment/index.ts
@@ -51432,7 +51495,7 @@ var init_AddStar = __esm(() => {
51432
51495
  // src/Items/Examples/Star/Star.ts
51433
51496
  var defaultStarData, starPath, Star2;
51434
51497
  var init_Star2 = __esm(() => {
51435
- init_BaseItem2();
51498
+ init_BaseItem();
51436
51499
  init_Point();
51437
51500
  init_Path();
51438
51501
  init_Line();
@@ -51614,7 +51677,7 @@ var init_AddCounter = __esm(() => {
51614
51677
  // src/Items/Examples/Counter/Counter.ts
51615
51678
  var defaultCounterData, COUNTER_DIMENSIONS, Counter;
51616
51679
  var init_Counter = __esm(() => {
51617
- init_BaseItem2();
51680
+ init_BaseItem();
51618
51681
  init_Point();
51619
51682
  init_Path();
51620
51683
  init_Line();
@@ -51733,7 +51796,7 @@ var init_HotkeyRegistry = __esm(() => {
51733
51796
  // src/Items/Examples/CardGame/Card/Card.ts
51734
51797
  var defaultCardData, Card;
51735
51798
  var init_Card = __esm(() => {
51736
- init_BaseItem2();
51799
+ init_BaseItem();
51737
51800
  init_Path();
51738
51801
  init_RegisterItem();
51739
51802
  init_Settings();
@@ -51983,7 +52046,7 @@ function createDeck(event, board) {
51983
52046
  if (single && single.itemType === "Deck") {
51984
52047
  return;
51985
52048
  }
51986
- const cardsOrDecks = board.selection.items.list();
52049
+ const cardsOrDecks = board.selection.items.listAll();
51987
52050
  const onlyCards = board.selection.items.isAllItemsType("Card");
51988
52051
  if (onlyCards) {
51989
52052
  const deck = new Deck(board, "");
@@ -51999,12 +52062,12 @@ function createDeck(event, board) {
51999
52062
  if (item.itemType === "Card") {
52000
52063
  cards.push(item);
52001
52064
  } else if (item.itemType === "Deck") {
52065
+ const deck = item;
52002
52066
  if (mainDeck) {
52003
- cards.push(...mainDeck.getDeck());
52004
- board.remove(mainDeck);
52005
- mainDeck = item;
52067
+ cards.push(...deck.getDeck());
52068
+ board.remove(deck);
52006
52069
  } else {
52007
- mainDeck = item;
52070
+ mainDeck = deck;
52008
52071
  }
52009
52072
  }
52010
52073
  });
@@ -52017,9 +52080,10 @@ function createDeck(event, board) {
52017
52080
  }
52018
52081
  var defaultDeckData, Deck;
52019
52082
  var init_Deck = __esm(() => {
52020
- init_BaseItem2();
52083
+ init_BaseItem();
52021
52084
  init_RegisterItem();
52022
52085
  init_Card();
52086
+ init_DrawingContext();
52023
52087
  init_Settings();
52024
52088
  init_Path2();
52025
52089
  init_HotkeyRegistry();
@@ -52038,9 +52102,9 @@ var init_Deck = __esm(() => {
52038
52102
  drawingContext = null;
52039
52103
  constructor(board, id = "") {
52040
52104
  super(board, id, defaultDeckData, true);
52041
- this.index.getUnderPoint = () => [];
52042
- this.index.getEnclosed = () => [];
52043
- this.index.getEnclosedOrCrossed = () => [];
52105
+ this.index.listUnderPoint = () => [];
52106
+ this.index.listEnclosedBy = () => [];
52107
+ this.index.listEnclosedOrCrossedBy = () => [];
52044
52108
  this.transformation.subject.subscribe(() => {
52045
52109
  this.updateMbr();
52046
52110
  this.subject.publish(this);
@@ -52062,7 +52126,7 @@ var init_Deck = __esm(() => {
52062
52126
  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);
52063
52127
  if (canAddItem) {
52064
52128
  this.isPerpendicular = foundItem.getIsRotatedPerpendicular();
52065
- 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));
52129
+ 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));
52066
52130
  if (firstCard) {
52067
52131
  const { scaleX, scaleY } = foundItem.transformation.getMatrixData();
52068
52132
  const { scaleX: targetScaleX, scaleY: targetScaleY } = firstCard.transformation.getMatrixData();
@@ -52102,31 +52166,33 @@ var init_Deck = __esm(() => {
52102
52166
  this.subject.publish(this);
52103
52167
  }
52104
52168
  getDeck() {
52105
- return this.index?.list() || [];
52169
+ return this.index?.listAll() || [];
52106
52170
  }
52107
52171
  getTopCard() {
52108
- const card = this.index?.list()[this.index?.list().length - 1];
52172
+ const cards = this.index?.listAll() || [];
52173
+ const card = cards[cards.length - 1];
52109
52174
  if (card) {
52110
52175
  this.removeChildItems(card);
52111
52176
  return card;
52112
52177
  }
52113
52178
  }
52114
52179
  getCards(count) {
52115
- const cards = this.index?.list().reverse().slice(0, count);
52116
- if (cards) {
52180
+ const cards = (this.index?.listAll() || []).reverse().slice(0, count);
52181
+ if (cards.length > 0) {
52117
52182
  this.removeChildItems(cards);
52118
52183
  return cards;
52119
52184
  }
52120
52185
  }
52121
52186
  getBottomCard() {
52122
- const card = this.index?.list()[0];
52187
+ const card = this.index?.listAll()[0];
52123
52188
  if (card) {
52124
52189
  this.removeChildItems(card);
52125
52190
  return card;
52126
52191
  }
52127
52192
  }
52128
52193
  getRandomCard() {
52129
- const card = this.index?.list()[Math.floor(Math.random() * this.index?.list().length)];
52194
+ const cards = this.index?.listAll() || [];
52195
+ const card = cards[Math.floor(Math.random() * cards.length)];
52130
52196
  if (card) {
52131
52197
  this.removeChildItems(card);
52132
52198
  return card;
@@ -52136,20 +52202,20 @@ var init_Deck = __esm(() => {
52136
52202
  if (!this.index) {
52137
52203
  return;
52138
52204
  }
52139
- const shuffled = [...this.index.list()];
52205
+ const shuffled = [...this.index.listAll()];
52140
52206
  for (let i = shuffled.length - 1;i > 0; i--) {
52141
52207
  const j = Math.floor(Math.random() * (i + 1));
52142
52208
  [shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
52143
52209
  }
52144
52210
  this.emitAnimation();
52145
- this.removeChildItems(this.index.list());
52211
+ this.removeChildItems(this.index.listAll());
52146
52212
  this.addChildItems(shuffled);
52147
52213
  }
52148
52214
  flipDeck() {
52149
- if (!this.index || !this.index.list().length) {
52215
+ if (!this.index || !this.index.listAll().length) {
52150
52216
  return;
52151
52217
  }
52152
- const cards = this.index.list();
52218
+ const cards = this.index.listAll();
52153
52219
  cards[0].toggleIsOpen(cards);
52154
52220
  const reversed = [...cards].reverse();
52155
52221
  this.removeChildItems(cards);
@@ -52170,7 +52236,7 @@ var init_Deck = __esm(() => {
52170
52236
  }
52171
52237
  updateMbr() {
52172
52238
  const { translateX, translateY } = this.transformation.getMatrixData();
52173
- const items = this.index.list();
52239
+ const items = this.index.listAll();
52174
52240
  const itemsMbr = items[0]?.getMbr().combine(items.slice(1).map((item) => item.getMbr()));
52175
52241
  this.left = translateX;
52176
52242
  this.top = translateY;
@@ -52238,7 +52304,7 @@ var init_Deck = __esm(() => {
52238
52304
  }
52239
52305
  renderHTML(documentFactory) {
52240
52306
  const div = super.renderHTML(documentFactory);
52241
- const cards = this.index?.list();
52307
+ const cards = this.index?.listAll();
52242
52308
  const topCard = cards[cards.length - 1];
52243
52309
  if (!topCard) {
52244
52310
  return div;
@@ -52247,7 +52313,7 @@ var init_Deck = __esm(() => {
52247
52313
  const transform = `translate(${translateX}px, ${translateY}px) scale(1, 1)`;
52248
52314
  const topCardElement = topCard.renderHTML(documentFactory);
52249
52315
  div.appendChild(topCardElement);
52250
- const offset = ((this.index?.list().length || 0) - 1) * 2;
52316
+ const offset = ((this.index?.listAll().length || 0) - 1) * 2;
52251
52317
  topCardElement.style.transform = `translate(${offset}px, ${0}px) scale(1, 1)`;
52252
52318
  div.id = this.getId();
52253
52319
  div.style.width = `${this.getWidth()}px`;
@@ -52260,7 +52326,7 @@ var init_Deck = __esm(() => {
52260
52326
  return div;
52261
52327
  }
52262
52328
  updateCache(context) {
52263
- const cards = this.index?.list();
52329
+ const cards = this.index?.listAll();
52264
52330
  const topCard = cards[cards.length - 1];
52265
52331
  const topCardImage = topCard?.getImage();
52266
52332
  const width2 = this.getWidth();
@@ -52274,7 +52340,7 @@ var init_Deck = __esm(() => {
52274
52340
  const tempCtx = tempCanvas.getContext("2d");
52275
52341
  if (!tempCtx)
52276
52342
  return;
52277
- const tempContext = { ...context, ctx: tempCtx };
52343
+ const tempContext = new DrawingContext(context.camera, tempCtx, context.cursorCtx, context.matrix);
52278
52344
  cards.forEach((_, index2) => {
52279
52345
  topCard.render(tempContext, this.isPerpendicular ? 0 : index2 * conf.DECK_HORIZONTAL_OFFSET, this.isPerpendicular ? index2 * conf.DECK_VERTICAL_OFFSET : 0);
52280
52346
  });
@@ -52283,7 +52349,7 @@ var init_Deck = __esm(() => {
52283
52349
  this.updateMbr();
52284
52350
  }
52285
52351
  getFirstCard() {
52286
- return this.index?.list()[0];
52352
+ return this.index?.listAll()[0];
52287
52353
  }
52288
52354
  };
52289
52355
  registerItem({
@@ -52417,7 +52483,7 @@ var init_AddDice = __esm(() => {
52417
52483
  // src/Items/Examples/CardGame/Dice/Dice.ts
52418
52484
  var TIMEOUT = 2000, defaultDiceData, Dice;
52419
52485
  var init_Dice = __esm(() => {
52420
- init_BaseItem2();
52486
+ init_BaseItem();
52421
52487
  init_Items();
52422
52488
  init_RoundedRectangle();
52423
52489
  init_Items();
@@ -52818,7 +52884,7 @@ var init_AddScreen = __esm(() => {
52818
52884
  // src/Items/Examples/CardGame/Screen/Screen.ts
52819
52885
  var screenPath, defaultScreenData, Screen;
52820
52886
  var init_Screen = __esm(() => {
52821
- init_BaseItem2();
52887
+ init_BaseItem();
52822
52888
  init_RegisterItem();
52823
52889
  init_Path2();
52824
52890
  init_Line2();
@@ -52965,9 +53031,9 @@ var init_Screen = __esm(() => {
52965
53031
  applyOwnerId(ownerId) {
52966
53032
  this.ownerId = ownerId;
52967
53033
  if (!this.ownerId) {
52968
- this.index.getUnderPoint = () => [];
52969
- this.index.getEnclosed = () => [];
52970
- this.index.getEnclosedOrCrossed = () => [];
53034
+ this.index.listUnderPoint = () => [];
53035
+ this.index.listEnclosedBy = () => [];
53036
+ this.index.listEnclosedOrCrossedBy = () => [];
52971
53037
  }
52972
53038
  }
52973
53039
  transformPath() {
@@ -52990,16 +53056,17 @@ var init_Screen = __esm(() => {
52990
53056
  this.applyBackgroundUrl(this.backgroundUrl);
52991
53057
  }
52992
53058
  if (!this.ownerId) {
52993
- this.index.getUnderPoint = () => [];
52994
- this.index.getEnclosed = () => [];
52995
- this.index.getEnclosedOrCrossed = () => [];
53059
+ this.index.listUnderPoint = () => [];
53060
+ this.index.listEnclosedBy = () => [];
53061
+ this.index.listEnclosedOrCrossedBy = () => [];
52996
53062
  }
52997
53063
  this.transformPath();
52998
53064
  this.subject.publish(this);
52999
53065
  return this;
53000
53066
  }
53001
53067
  getRandomItem() {
53002
- const item = this.index?.list()[Math.floor(Math.random() * this.index?.list().length)];
53068
+ const items = this.index?.listAll() || [];
53069
+ const item = items[Math.floor(Math.random() * items.length)];
53003
53070
  if (item) {
53004
53071
  this.removeChildItems(item);
53005
53072
  return item;
@@ -53048,7 +53115,7 @@ var init_Screen2 = __esm(() => {
53048
53115
 
53049
53116
  // src/Items/index.ts
53050
53117
  var init_Items = __esm(() => {
53051
- init_BaseItem();
53118
+ init_BaseItem2();
53052
53119
  init_Point2();
53053
53120
  init_Line2();
53054
53121
  init_Curve2();
@@ -53923,7 +53990,7 @@ var init_Shape = __esm(() => {
53923
53990
  init_Connector2();
53924
53991
  init_ControlPoint();
53925
53992
  init_Settings();
53926
- init_BaseItem2();
53993
+ init_BaseItem();
53927
53994
  init_Color();
53928
53995
  defaultShapeData = new DefaultShapeData;
53929
53996
  Shapes = { ...BasicShapes, ...BPMN };
@@ -54449,7 +54516,7 @@ var init_Placeholder2 = __esm(() => {
54449
54516
  init_Transformation();
54450
54517
  init_PlaceholderCommand();
54451
54518
  init_getResizeMatrix();
54452
- init_BaseItem2();
54519
+ init_BaseItem();
54453
54520
  Placeholder2 = class Placeholder2 extends BaseItem {
54454
54521
  events;
54455
54522
  miroData;
@@ -54758,7 +54825,7 @@ var init_Image = __esm(() => {
54758
54825
  init_Placeholder2();
54759
54826
  init_LinkTo();
54760
54827
  init_Settings();
54761
- init_BaseItem2();
54828
+ init_BaseItem();
54762
54829
  init_MediaHelpers();
54763
54830
  ImageItem = class ImageItem extends BaseItem {
54764
54831
  events;
@@ -55321,10 +55388,20 @@ function handleBoardEventMessage(message, board) {
55321
55388
  if (isEventFromCurrentUser) {
55322
55389
  return;
55323
55390
  }
55324
- log.insertEventsFromOtherConnections({
55325
- ...event,
55326
- userId: Number(message.userId)
55327
- });
55391
+ if ("operations" in event.body) {
55392
+ log.insertEventsFromOtherConnections({
55393
+ ...event,
55394
+ body: {
55395
+ ...event.body,
55396
+ userId: Number(message.userId)
55397
+ }
55398
+ });
55399
+ } else {
55400
+ log.insertEventsFromOtherConnections({
55401
+ ...event,
55402
+ userId: Number(message.userId)
55403
+ });
55404
+ }
55328
55405
  const last = log.getLastConfirmed();
55329
55406
  if (last) {
55330
55407
  board.events.subject.publish(last);
@@ -55342,7 +55419,7 @@ function handleBoardSubscriptionCompletedMsg(msg, board) {
55342
55419
  handleHTMLSnapshotApplication(msg.JSONSnapshot, board);
55343
55420
  log.list.clearConfirmedRecords();
55344
55421
  }
55345
- handleBoardEventListApplication(msg.eventsSinceLastSnapshot, board);
55422
+ handleBoardEventListApplication(expandEvents(msg.eventsSinceLastSnapshot), board);
55346
55423
  board.setInterfaceType(msg.mode);
55347
55424
  board.subject.publish();
55348
55425
  onBoardLoad(board);
@@ -57499,7 +57576,7 @@ init_Settings();
57499
57576
  init_QuickAddButtons3();
57500
57577
 
57501
57578
  // src/Selection/SelectionItems.ts
57502
- init_BaseItem();
57579
+ init_BaseItem2();
57503
57580
 
57504
57581
  class SelectionItems {
57505
57582
  items = new Map;
@@ -57526,6 +57603,9 @@ class SelectionItems {
57526
57603
  list() {
57527
57604
  return Array.from(this.items.values());
57528
57605
  }
57606
+ listAll() {
57607
+ return this.list();
57608
+ }
57529
57609
  isEmpty() {
57530
57610
  return this.items.size === 0;
57531
57611
  }
@@ -57821,7 +57901,7 @@ init_RichText();
57821
57901
  init_AINode();
57822
57902
  init_Sticker();
57823
57903
  init_Frame();
57824
- init_BaseItem();
57904
+ init_BaseItem2();
57825
57905
  function handleMultipleItemsResize({
57826
57906
  board,
57827
57907
  resize,
@@ -58204,7 +58284,7 @@ init_Image();
58204
58284
  init_SessionStorage();
58205
58285
  init_Point();
58206
58286
  init_Items();
58207
- init_BaseItem();
58287
+ init_BaseItem2();
58208
58288
  function transformItems({
58209
58289
  board,
58210
58290
  selection,
@@ -60989,8 +61069,9 @@ class Board {
60989
61069
  const data = Array.from(items.children).map((el) => this.parseHTML(el));
60990
61070
  for (const parsedData of data) {
60991
61071
  if ("childrenMap" in parsedData) {
60992
- const addedFrame = this.add(this.createItem(this.getNewItemId(), parsedData.data));
60993
- const addedChildren = Object.values(parsedData.childrenMap).map((childData) => {
61072
+ const frameData = parsedData;
61073
+ const addedFrame = this.add(this.createItem(this.getNewItemId(), frameData.data));
61074
+ const addedChildren = Object.values(frameData.childrenMap).map((childData) => {
60994
61075
  const created = this.createItem(this.getNewItemId(), childData);
60995
61076
  const added = this.add(created);
60996
61077
  idsMap[childData.id] = added.getId();
@@ -61003,17 +61084,18 @@ class Board {
61003
61084
  return added;
61004
61085
  });
61005
61086
  addedFrame.addChildItems(addedChildren);
61006
- parsedData.data.children = addedChildren.map((item) => item.getId());
61007
- idsMap[parsedData.data.id] = addedFrame.getId();
61087
+ frameData.data.children = addedChildren.map((item) => item.getId());
61088
+ idsMap[frameData.data.id] = addedFrame.getId();
61008
61089
  } else {
61009
- const added = this.add(this.createItem(this.getNewItemId(), parsedData));
61090
+ const itemData = parsedData;
61091
+ const added = this.add(this.createItem(this.getNewItemId(), itemData));
61010
61092
  if (added.itemType === "Connector") {
61011
61093
  addedConnectors.push({
61012
61094
  item: added,
61013
- data: parsedData
61095
+ data: itemData
61014
61096
  });
61015
61097
  }
61016
- idsMap[parsedData.id] = added.getId();
61098
+ idsMap[itemData.id] = added.getId();
61017
61099
  }
61018
61100
  }
61019
61101
  addedConnectors.forEach((connector) => {
@@ -61057,12 +61139,13 @@ class Board {
61057
61139
  this.index.insert(item);
61058
61140
  return item;
61059
61141
  };
61060
- for (const itemData of items) {
61061
- if ("childrenMap" in itemData) {
61062
- Object.values(itemData.childrenMap).map((childData) => addItem(childData));
61063
- addItem(itemData.data);
61142
+ for (const rawItemData of items) {
61143
+ if ("childrenMap" in rawItemData) {
61144
+ const frameData = rawItemData;
61145
+ Object.values(frameData.childrenMap).map((childData) => addItem(childData));
61146
+ addItem(frameData.data);
61064
61147
  } else {
61065
- addItem(itemData);
61148
+ addItem(rawItemData);
61066
61149
  }
61067
61150
  }
61068
61151
  for (const key in createdConnectors) {
@@ -61495,8 +61578,9 @@ class Board {
61495
61578
  itemData.transformation.translateX = translateX + width2 * 10 + 10;
61496
61579
  }
61497
61580
  }
61498
- if ("children" in itemData && itemData.children?.length) {
61499
- itemData.children = itemData.children.map((childId) => newItemIdMap[childId]);
61581
+ const itemDataWithChildren = itemData;
61582
+ if ("children" in itemDataWithChildren && itemDataWithChildren.children?.length) {
61583
+ itemDataWithChildren.children = itemDataWithChildren.children.map((childId) => newItemIdMap[childId]);
61500
61584
  }
61501
61585
  newMap[newItemId] = itemData;
61502
61586
  }
@@ -61679,7 +61763,7 @@ function initI18N(i18nInstance) {
61679
61763
  // src/index.ts
61680
61764
  init_MediaHelpers();
61681
61765
  init_CreateCommand();
61682
- init_BaseItem2();
61766
+ init_BaseItem();
61683
61767
  init_Events();
61684
61768
  BaseItem.createCommand = createCommand;
61685
61769
  Events.createCommand = createCommand;