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
@@ -4184,18 +4184,23 @@ function createEventsList(commandFactory) {
4184
4184
  return item;
4185
4185
  if (typeof item === "string")
4186
4186
  return [item];
4187
- return Object.keys(item);
4187
+ if (item && typeof item === "object")
4188
+ return Object.keys(item);
4188
4189
  }
4189
- if ("itemsMap" in op)
4190
+ if ("itemsMap" in op && op.itemsMap)
4190
4191
  return Object.keys(op.itemsMap);
4191
4192
  if ("items" in op) {
4192
4193
  const items = op.items;
4193
- if (Array.isArray(items))
4194
- return items.map((i) => typeof i === "string" ? i : i.id);
4195
- return Object.keys(items);
4194
+ if (Array.isArray(items)) {
4195
+ return items.map((i) => typeof i === "string" ? i : i.id).filter(Boolean);
4196
+ }
4197
+ if (items && typeof items === "object" && items !== null)
4198
+ return Object.keys(items);
4199
+ }
4200
+ if ("itemsOps" in op) {
4201
+ const itemsOps = op.itemsOps;
4202
+ return itemsOps.map((io) => io.item);
4196
4203
  }
4197
- if ("itemsOps" in op)
4198
- return op.itemsOps.map((io) => io.item);
4199
4204
  return [];
4200
4205
  }
4201
4206
  return {
@@ -5854,16 +5859,17 @@ var init_transformEvents = __esm(() => {
5854
5859
  function expandEvents(events) {
5855
5860
  return events.flatMap((event) => {
5856
5861
  if ("operations" in event.body) {
5857
- return event.body.operations.map((operation) => ({
5862
+ const { operations, lastKnownOrder, ...bodyWithoutOps } = event.body;
5863
+ return operations.map((operation) => ({
5858
5864
  order: event.order,
5859
5865
  body: {
5860
- eventId: operation.actualId || event.body.eventId,
5861
- userId: event.body.userId,
5862
- boardId: event.body.boardId,
5866
+ eventId: operation.actualId || bodyWithoutOps.eventId,
5867
+ userId: bodyWithoutOps.userId,
5868
+ boardId: bodyWithoutOps.boardId,
5863
5869
  operation
5864
5870
  },
5865
- userId: event.body.userId,
5866
- lastKnownOrder: "lastKnownOrder" in event ? event.lastKnownOrder : event.body.lastKnownOrder
5871
+ userId: bodyWithoutOps.userId,
5872
+ lastKnownOrder
5867
5873
  }));
5868
5874
  } else {
5869
5875
  return [event];
@@ -5975,13 +5981,15 @@ var init_insertEventsFromOtherConnectionsIntoList = __esm(() => {
5975
5981
  function deserializeAndApplyToList(events, list, board) {
5976
5982
  list.clear();
5977
5983
  for (const event of events) {
5978
- const body = event.body;
5979
- if (body.operations && Array.isArray(body.operations)) {
5980
- for (const op of body.operations) {
5984
+ if ("operations" in event.body) {
5985
+ const { operations, lastKnownOrder, ...bodyWithoutOps } = event.body;
5986
+ for (const op of operations) {
5981
5987
  const singleEvent = {
5982
- ...event,
5988
+ order: event.order,
5989
+ lastKnownOrder,
5990
+ userId: bodyWithoutOps.userId,
5983
5991
  body: {
5984
- ...event.body,
5992
+ ...bodyWithoutOps,
5985
5993
  operation: op
5986
5994
  }
5987
5995
  };
@@ -11567,7 +11575,7 @@ class RTreeIndex {
11567
11575
  this.tree.remove(item);
11568
11576
  }
11569
11577
  }
11570
- list() {
11578
+ listAll() {
11571
11579
  const containers = this.tree.all();
11572
11580
  const items = [];
11573
11581
  for (const container of containers) {
@@ -11575,7 +11583,7 @@ class RTreeIndex {
11575
11583
  }
11576
11584
  return items;
11577
11585
  }
11578
- getEnclosed(rect) {
11586
+ listEnclosedBy(rect) {
11579
11587
  return this.tree.search({
11580
11588
  minX: rect.left,
11581
11589
  minY: rect.top,
@@ -11583,7 +11591,7 @@ class RTreeIndex {
11583
11591
  maxY: rect.bottom
11584
11592
  }).filter((container) => container.item.isEnclosedBy(rect)).map((container) => container.item);
11585
11593
  }
11586
- getEnclosedOrCrossedBy(rect) {
11594
+ listEnclosedOrCrossedBy(rect) {
11587
11595
  return this.tree.search({
11588
11596
  minX: rect.left,
11589
11597
  minY: rect.top,
@@ -11591,7 +11599,7 @@ class RTreeIndex {
11591
11599
  maxY: rect.bottom
11592
11600
  }).filter((container) => container.item.isEnclosedOrCrossedBy(rect)).map((container) => container.item);
11593
11601
  }
11594
- getUnderPoint(point, tolerance = 5) {
11602
+ listUnderPoint(point, tolerance = 5) {
11595
11603
  return this.tree.search({
11596
11604
  minX: point.x,
11597
11605
  minY: point.y,
@@ -11599,7 +11607,7 @@ class RTreeIndex {
11599
11607
  maxY: point.y
11600
11608
  }).filter((container) => container.item.isUnderPoint(point, tolerance)).map((container) => container.item);
11601
11609
  }
11602
- getRectsEnclosedOrCrossedBy(rect) {
11610
+ listRectsEnclosedOrCrossedBy(rect) {
11603
11611
  return this.tree.search({
11604
11612
  minX: rect.left,
11605
11613
  minY: rect.top,
@@ -11615,9 +11623,27 @@ class RTreeIndex {
11615
11623
  maxY: rect.bottom
11616
11624
  });
11617
11625
  }
11618
- getNearestTo(point, maxItems, filter, maxDistance) {
11626
+ listNearestTo(point, maxItems, filter, maxDistance) {
11619
11627
  return knn(this.tree, point.x, point.y, maxItems, (container) => filter(container.item), maxDistance).map((container) => container.item);
11620
11628
  }
11629
+ getById(id) {
11630
+ return this.listAll().find((item) => item.getId() === id);
11631
+ }
11632
+ findById(id) {
11633
+ return this.getById(id);
11634
+ }
11635
+ getByZIndex(index) {
11636
+ return this.listAll()[index];
11637
+ }
11638
+ getLastZIndex() {
11639
+ return this.listAll().length - 1;
11640
+ }
11641
+ copy() {
11642
+ return this.listAll().map((item) => ({
11643
+ ...item.serialize(),
11644
+ id: item.getId()
11645
+ }));
11646
+ }
11621
11647
  batchInsert(batch) {
11622
11648
  for (const one of batch) {
11623
11649
  this.insert(one);
@@ -11689,35 +11715,31 @@ class LayeredIndex {
11689
11715
  isT(item) {
11690
11716
  return true;
11691
11717
  }
11692
- findById(id) {
11693
- const container = this.map.get(id);
11694
- return container ? container.item : undefined;
11695
- }
11696
- getEnclosed(rect) {
11718
+ listEnclosedBy(rect) {
11697
11719
  let items = [];
11698
11720
  for (const layer of this.layers.array) {
11699
- items = items.concat(layer.getEnclosed(rect));
11721
+ items = items.concat(layer.listEnclosedBy(rect));
11700
11722
  }
11701
11723
  return items;
11702
11724
  }
11703
- getEnclosedOrCrossedBy(rect) {
11725
+ listEnclosedOrCrossedBy(rect) {
11704
11726
  let items = [];
11705
11727
  for (const layer of this.layers.array) {
11706
- items = items.concat(layer.getEnclosedOrCrossedBy(rect));
11728
+ items = items.concat(layer.listEnclosedOrCrossedBy(rect));
11707
11729
  }
11708
11730
  return items;
11709
11731
  }
11710
- getUnderPoint(point, tolerance = 5) {
11732
+ listUnderPoint(point, tolerance = 5) {
11711
11733
  let items = [];
11712
11734
  for (const layer of this.layers.array) {
11713
- const layerItems = layer.getUnderPoint(point, tolerance);
11735
+ const layerItems = layer.listUnderPoint(point, tolerance);
11714
11736
  if (layerItems.length > 0) {
11715
11737
  items = items.concat(layerItems);
11716
11738
  }
11717
11739
  }
11718
11740
  return items;
11719
11741
  }
11720
- getRectsEnclosedOrCrossedBy(rect) {
11742
+ listRectsEnclosedOrCrossedBy(rect) {
11721
11743
  const items = [];
11722
11744
  const minMax = {
11723
11745
  minX: rect.left,
@@ -11741,10 +11763,10 @@ class LayeredIndex {
11741
11763
  }
11742
11764
  return false;
11743
11765
  }
11744
- getNearestTo(point, maxItems, filter, maxDistance) {
11766
+ listNearestTo(point, maxItems, filter, maxDistance) {
11745
11767
  let items = [];
11746
11768
  for (const layer of this.layers.array) {
11747
- items = items.concat(layer.getNearestTo(point, maxItems, filter, maxDistance));
11769
+ items = items.concat(layer.listNearestTo(point, maxItems, filter, maxDistance));
11748
11770
  }
11749
11771
  return items;
11750
11772
  }
@@ -11778,7 +11800,7 @@ class LayeredIndex {
11778
11800
  }
11779
11801
  const bounds = container.item.getMbrWithChildren();
11780
11802
  this.remove(container.item);
11781
- const inBounds = this.getRectsEnclosedOrCrossedBy(bounds);
11803
+ const inBounds = this.listRectsEnclosedOrCrossedBy(bounds);
11782
11804
  const containersInBounds = this.getContainersFromItems(inBounds);
11783
11805
  const containersAbove = [];
11784
11806
  const containerZIndex = this.getZIndex(container.item);
@@ -11806,7 +11828,7 @@ class LayeredIndex {
11806
11828
  }
11807
11829
  const bounds = container.item.getMbrWithChildren();
11808
11830
  this.remove(container.item);
11809
- const inBounds = this.getRectsEnclosedOrCrossedBy(bounds);
11831
+ const inBounds = this.listRectsEnclosedOrCrossedBy(bounds);
11810
11832
  const containersInBounds = this.getContainersFromItems(inBounds);
11811
11833
  const containersBelow = [];
11812
11834
  const containerZIndex = this.getZIndex(container.item);
@@ -11831,7 +11853,7 @@ class LayeredIndex {
11831
11853
  insert(item) {
11832
11854
  const toInsert = new Container(item.getId(), item, 0, this.getZIndex(item));
11833
11855
  const bounds = item.getMbrWithChildren();
11834
- const inBounds = this.getRectsEnclosedOrCrossedBy(bounds);
11856
+ const inBounds = this.listRectsEnclosedOrCrossedBy(bounds);
11835
11857
  if (inBounds.length === 0) {
11836
11858
  return this.insertContainer(toInsert);
11837
11859
  }
@@ -11928,13 +11950,32 @@ class LayeredIndex {
11928
11950
  return;
11929
11951
  }
11930
11952
  }
11931
- list() {
11953
+ listAll() {
11932
11954
  const items = [];
11933
11955
  for (const record of this.map) {
11934
11956
  items.push(record[1].item);
11935
11957
  }
11936
11958
  return items;
11937
11959
  }
11960
+ getById(id) {
11961
+ const container = this.map.get(id);
11962
+ return container ? container.item : undefined;
11963
+ }
11964
+ findById(id) {
11965
+ return this.getById(id);
11966
+ }
11967
+ getByZIndex(index) {
11968
+ return this.listAll()[index];
11969
+ }
11970
+ getLastZIndex() {
11971
+ return this.listAll().length - 1;
11972
+ }
11973
+ copy() {
11974
+ return this.listAll().map((item) => ({
11975
+ ...item.serialize(),
11976
+ id: item.getId()
11977
+ }));
11978
+ }
11938
11979
  batchInsert(items) {
11939
11980
  for (const item of items) {
11940
11981
  this.insert(item);
@@ -11951,11 +11992,6 @@ var init_LayeredIndex = __esm(() => {
11951
11992
  init_RTreeIndex();
11952
11993
  });
11953
11994
 
11954
- // src/Items/BaseItem/index.ts
11955
- var init_BaseItem = __esm(() => {
11956
- init_BaseItem2();
11957
- });
11958
-
11959
11995
  // src/SpatialIndex/SpacialIndex.ts
11960
11996
  function worldBoundsToLocal(container, left, top, right, bottom) {
11961
11997
  const inv = container.getNestingMatrix().getInverse();
@@ -11974,6 +12010,13 @@ function worldBoundsToLocal(container, left, top, right, bottom) {
11974
12010
  bottom: Math.max(corners[0].y, corners[1].y, corners[2].y, corners[3].y)
11975
12011
  };
11976
12012
  }
12013
+ function coerceMbr(left, top, right, bottom) {
12014
+ if (left instanceof Mbr)
12015
+ return left;
12016
+ if (typeof left === "object" && left !== null)
12017
+ return new Mbr(left.left, left.top, left.right, left.bottom);
12018
+ return new Mbr(left, top, right, bottom);
12019
+ }
11977
12020
 
11978
12021
  class SpatialIndex {
11979
12022
  subject = new Subject;
@@ -11994,6 +12037,9 @@ class SpatialIndex {
11994
12037
  this.Mbr = new Mbr;
11995
12038
  }
11996
12039
  insert(item) {
12040
+ if (this.itemsArray.includes(item) || this.getById(item.getId())) {
12041
+ return;
12042
+ }
11997
12043
  this.itemsArray.push(item);
11998
12044
  this.itemsIndex.insert(item);
11999
12045
  if (conf.isNode()) {
@@ -12022,7 +12068,7 @@ class SpatialIndex {
12022
12068
  remove(item, preserveChildren = false) {
12023
12069
  const baseItem = item;
12024
12070
  if (!preserveChildren && baseItem.index) {
12025
- baseItem.removeChildItems(baseItem.index.list());
12071
+ baseItem.removeChildItems(baseItem.index.listAll());
12026
12072
  }
12027
12073
  this.itemsArray.splice(this.itemsArray.indexOf(item), 1);
12028
12074
  this.itemsIndex.remove(item);
@@ -12065,14 +12111,14 @@ class SpatialIndex {
12065
12111
  return items.flatMap((item) => {
12066
12112
  const baseItem = item;
12067
12113
  if (baseItem.index) {
12068
- return [item, ...baseItem.index.list()];
12114
+ return [item, ...baseItem.index.listAll()];
12069
12115
  }
12070
12116
  return item;
12071
12117
  });
12072
12118
  }
12073
12119
  getItemChildren(item) {
12074
12120
  if ("index" in item && item.index) {
12075
- return item.index.list();
12121
+ return item.index.listAll();
12076
12122
  }
12077
12123
  return [];
12078
12124
  }
@@ -12223,14 +12269,14 @@ class SpatialIndex {
12223
12269
  findById(id) {
12224
12270
  return this.getById(id);
12225
12271
  }
12226
- getEnclosed(left, top, right, bottom) {
12227
- const mbr = new Mbr(left, top, right, bottom);
12228
- const items = this.itemsIndex.getEnclosed(mbr);
12272
+ listEnclosedBy(left, top, right, bottom) {
12273
+ const mbr = coerceMbr(left, top, right, bottom);
12274
+ const items = this.itemsIndex.listEnclosedBy(mbr);
12229
12275
  const children = [];
12230
12276
  const clearItems = items.filter((item) => {
12231
12277
  if ("index" in item && item.index) {
12232
- const local = worldBoundsToLocal(item, left, top, right, bottom);
12233
- children.push(...item.index.getEnclosed(local.left, local.top, local.right, local.bottom));
12278
+ const local = worldBoundsToLocal(item, mbr.left, mbr.top, mbr.right, mbr.bottom);
12279
+ children.push(...item.index.listEnclosedBy(local.left, local.top, local.right, local.bottom));
12234
12280
  if (!item.getMbr().isEnclosedBy(mbr)) {
12235
12281
  return false;
12236
12282
  }
@@ -12239,14 +12285,14 @@ class SpatialIndex {
12239
12285
  });
12240
12286
  return [...clearItems, ...children];
12241
12287
  }
12242
- getEnclosedOrCrossed(left, top, right, bottom) {
12243
- const mbr = new Mbr(left, top, right, bottom);
12244
- const items = this.itemsIndex.getEnclosedOrCrossedBy(mbr);
12288
+ listEnclosedOrCrossedBy(left, top, right, bottom) {
12289
+ const mbr = coerceMbr(left, top, right, bottom);
12290
+ const items = this.itemsIndex.listEnclosedOrCrossedBy(mbr);
12245
12291
  const children = [];
12246
12292
  const clearItems = items.filter((item) => {
12247
12293
  if ("index" in item && item.index) {
12248
- const local = worldBoundsToLocal(item, left, top, right, bottom);
12249
- children.push(...item.index.getEnclosedOrCrossed(local.left, local.top, local.right, local.bottom));
12294
+ const local = worldBoundsToLocal(item, mbr.left, mbr.top, mbr.right, mbr.bottom);
12295
+ children.push(...item.index.listEnclosedOrCrossedBy(local.left, local.top, local.right, local.bottom));
12250
12296
  if (!item.getMbr().isEnclosedOrCrossedBy(mbr)) {
12251
12297
  return false;
12252
12298
  }
@@ -12255,14 +12301,17 @@ class SpatialIndex {
12255
12301
  });
12256
12302
  return [...clearItems, ...children];
12257
12303
  }
12258
- getUnderPoint(point, tolerance = 5) {
12259
- const items = this.itemsIndex.getUnderPoint(point, tolerance);
12304
+ listRectsEnclosedOrCrossedBy(left, top, right, bottom) {
12305
+ return this.listEnclosedOrCrossedBy(left, top, right, bottom).map((item) => item.getMbr());
12306
+ }
12307
+ listUnderPoint(point, tolerance = 5) {
12308
+ const items = this.itemsIndex.listUnderPoint(point, tolerance);
12260
12309
  const children = [];
12261
12310
  const clearItems = items.filter((item) => {
12262
12311
  if ("index" in item && item.index) {
12263
12312
  const localPt = new Point(point.x, point.y);
12264
12313
  item.getNestingMatrix().getInverse().apply(localPt);
12265
- children.push(...item.index.getUnderPoint(localPt, tolerance));
12314
+ children.push(...item.index.listUnderPoint(localPt, tolerance));
12266
12315
  if (!item.getMbr().isUnderPoint(point)) {
12267
12316
  return false;
12268
12317
  }
@@ -12274,24 +12323,8 @@ class SpatialIndex {
12274
12323
  });
12275
12324
  return [...clearItems, ...children];
12276
12325
  }
12277
- getRectsEnclosedOrCrossed(left, top, right, bottom) {
12278
- const mbr = new Mbr(left, top, right, bottom);
12279
- const items = this.itemsIndex.getRectsEnclosedOrCrossedBy(mbr);
12280
- const children = [];
12281
- const clearItems = items.filter((item) => {
12282
- if ("index" in item && item.index) {
12283
- const local = worldBoundsToLocal(item, left, top, right, bottom);
12284
- children.push(...item.index.getEnclosedOrCrossed(local.left, local.top, local.right, local.bottom));
12285
- if (!item.getMbr().isEnclosedOrCrossedBy(mbr)) {
12286
- return false;
12287
- }
12288
- }
12289
- return true;
12290
- });
12291
- return [...clearItems, ...children];
12292
- }
12293
- getItemsEnclosedOrCrossed(left, top, right, bottom) {
12294
- return this.getRectsEnclosedOrCrossed(left, top, right, bottom);
12326
+ listNearestTo(point, maxItems, filter, maxDistance) {
12327
+ return this.itemsIndex.listNearestTo(point, maxItems, filter, maxDistance);
12295
12328
  }
12296
12329
  getComments() {
12297
12330
  return this.itemsArray.filter((item) => item.itemType === "Comment");
@@ -12309,7 +12342,7 @@ class SpatialIndex {
12309
12342
  const inRange = itemsWithDistance.filter((x) => x.distance <= maxDistance);
12310
12343
  return inRange.sort((a, b) => a.distance - b.distance).slice(0, maxItems).map((x) => x.item);
12311
12344
  }
12312
- list() {
12345
+ listAll() {
12313
12346
  return this.getItemsWithIncludedChildren(this.itemsArray).concat();
12314
12347
  }
12315
12348
  getZIndex(item) {
@@ -12347,10 +12380,19 @@ class Items {
12347
12380
  this.index.change(item);
12348
12381
  }
12349
12382
  listAll() {
12350
- return this.index.list();
12383
+ return this.index.listAll();
12384
+ }
12385
+ listUnderPoint(point, tolerance = 5) {
12386
+ return this.index.listUnderPoint(point, tolerance);
12387
+ }
12388
+ listEnclosedBy(left, top, right, bottom) {
12389
+ return this.index.listEnclosedBy(left, top, right, bottom);
12390
+ }
12391
+ listEnclosedOrCrossedBy(left, top, right, bottom) {
12392
+ return this.index.listEnclosedOrCrossedBy(left, top, right, bottom);
12351
12393
  }
12352
12394
  listGroupItems() {
12353
- return this.index.list().filter((item) => ("index" in item) && item.index);
12395
+ return this.index.listAll().filter((item) => ("index" in item) && item.index);
12354
12396
  }
12355
12397
  getById(id) {
12356
12398
  return this.index.getById(id);
@@ -12359,16 +12401,16 @@ class Items {
12359
12401
  return this.index.findById(id);
12360
12402
  }
12361
12403
  getEnclosed(left, top, right, bottom) {
12362
- return this.index.getEnclosed(left, top, right, bottom);
12404
+ return this.index.listEnclosedBy(left, top, right, bottom);
12363
12405
  }
12364
12406
  getEnclosedOrCrossed(left, top, right, bottom) {
12365
- return this.index.getEnclosedOrCrossed(left, top, right, bottom);
12407
+ return this.index.listEnclosedOrCrossedBy(left, top, right, bottom);
12366
12408
  }
12367
12409
  getGroupItemsEnclosedOrCrossed(left, top, right, bottom) {
12368
- return this.index.getEnclosedOrCrossed(left, top, right, bottom).filter((item) => item instanceof BaseItem && item.index);
12410
+ return this.index.listEnclosedOrCrossedBy(left, top, right, bottom).filter((item) => ("index" in item) && item.index);
12369
12411
  }
12370
12412
  getUnderPoint(point, tolerance = 5) {
12371
- return this.index.getUnderPoint(point, tolerance);
12413
+ return this.index.listUnderPoint(point, tolerance);
12372
12414
  }
12373
12415
  getMbr() {
12374
12416
  return this.index.getMbr();
@@ -12391,25 +12433,25 @@ class Items {
12391
12433
  }
12392
12434
  getInView() {
12393
12435
  const { left, top, right, bottom } = this.view.getMbr();
12394
- return this.index.getRectsEnclosedOrCrossed(left, top, right, bottom);
12436
+ return this.index.listEnclosedOrCrossedBy(left, top, right, bottom);
12395
12437
  }
12396
12438
  getItemsInView() {
12397
12439
  const { left, top, right, bottom } = this.view.getMbr();
12398
- return this.index.getItemsEnclosedOrCrossed(left, top, right, bottom);
12440
+ return this.index.listEnclosedOrCrossedBy(left, top, right, bottom);
12399
12441
  }
12400
12442
  getGroupItemsInView() {
12401
12443
  const { left, top, right, bottom } = this.view.getMbr();
12402
12444
  return this.getGroupItemsEnclosedOrCrossed(left, top, right, bottom);
12403
12445
  }
12404
12446
  getComments() {
12405
- return this.index.getComments();
12447
+ return this.listAll().filter((item) => item.itemType === "Comment");
12406
12448
  }
12407
12449
  getUnderPointer(size = 0) {
12408
12450
  const { x, y } = this.pointer.point;
12409
12451
  const unmodifiedSize = size;
12410
12452
  size = 16;
12411
- const tolerated = this.index.getEnclosedOrCrossed(x - size, y - size, x + size, y + size);
12412
- let enclosed = tolerated.some((item) => item.itemType === "Connector") ? tolerated : this.index.getEnclosedOrCrossed(x, y, x, y);
12453
+ const tolerated = this.index.listEnclosedOrCrossedBy(x - size, y - size, x + size, y + size);
12454
+ let enclosed = tolerated.some((item) => item.itemType === "Connector") ? tolerated : this.index.listEnclosedOrCrossedBy(x, y, x, y);
12413
12455
  const underPointer = this.getUnderPoint(new Point(x, y), size);
12414
12456
  if (enclosed.length === 0) {
12415
12457
  enclosed = underPointer;
@@ -12437,7 +12479,7 @@ class Items {
12437
12479
  return [];
12438
12480
  }
12439
12481
  getNearPointer(maxDistance = 100, maxItems = 10, filter = () => true) {
12440
- return this.index.getNearestTo(this.pointer.point, maxItems, filter, maxDistance);
12482
+ return this.index.listNearestTo(this.pointer.point, maxItems, filter, maxDistance);
12441
12483
  }
12442
12484
  getZIndex(item) {
12443
12485
  return this.index.getZIndex(item);
@@ -12579,7 +12621,6 @@ var init_SpacialIndex = __esm(() => {
12579
12621
  init_Point();
12580
12622
  init_Settings();
12581
12623
  init_LayeredIndex();
12582
- init_BaseItem();
12583
12624
  });
12584
12625
 
12585
12626
  // src/SpatialIndex/SimpleSpatialIndex.ts
@@ -12596,6 +12637,9 @@ class SimpleSpatialIndex {
12596
12637
  this.Mbr = new Mbr;
12597
12638
  }
12598
12639
  insert(item) {
12640
+ if (this.itemsArray.includes(item) || this.getById(item.getId())) {
12641
+ return;
12642
+ }
12599
12643
  this.itemsArray.push(item);
12600
12644
  if (this.Mbr.getWidth() === 0 && this.Mbr.getHeight() === 0) {
12601
12645
  this.Mbr = item.getMbr().copy();
@@ -12615,9 +12659,12 @@ class SimpleSpatialIndex {
12615
12659
  };
12616
12660
  remove(item, preserveChildren = false) {
12617
12661
  if (!preserveChildren && "index" in item && item.index) {
12618
- item.removeChildItems(item.index.list());
12662
+ item.removeChildItems(item.index.listAll());
12663
+ }
12664
+ const index = this.itemsArray.indexOf(item);
12665
+ if (index !== -1) {
12666
+ this.itemsArray.splice(index, 1);
12619
12667
  }
12620
- this.itemsArray.splice(this.itemsArray.indexOf(item), 1);
12621
12668
  this.Mbr = new Mbr;
12622
12669
  this.itemsArray.forEach((item2) => this.Mbr.combine([item2.getMbr()]));
12623
12670
  this.subject.publish(this.items);
@@ -12700,16 +12747,13 @@ class SimpleSpatialIndex {
12700
12747
  this.subject.publish(this.items);
12701
12748
  }
12702
12749
  getById(id) {
12703
- const item = this.itemsArray.find((item2) => item2.getId() === id);
12704
- if (item) {
12705
- return item;
12706
- }
12750
+ return this.itemsArray.find((item) => item.getId() === id);
12707
12751
  }
12708
12752
  findById(id) {
12709
12753
  return this.getById(id);
12710
12754
  }
12711
- getEnclosed(left, top, right, bottom) {
12712
- const mbr = new Mbr(left, top, right, bottom);
12755
+ listEnclosedBy(left, top, right, bottom) {
12756
+ const mbr = coerceMbr(left, top, right, bottom);
12713
12757
  const items = [];
12714
12758
  this.itemsArray.forEach((item) => {
12715
12759
  if (item.isEnclosedBy(mbr)) {
@@ -12718,8 +12762,8 @@ class SimpleSpatialIndex {
12718
12762
  });
12719
12763
  return items;
12720
12764
  }
12721
- getEnclosedOrCrossed(left, top, right, bottom) {
12722
- const mbr = new Mbr(left, top, right, bottom);
12765
+ listEnclosedOrCrossedBy(left, top, right, bottom) {
12766
+ const mbr = coerceMbr(left, top, right, bottom);
12723
12767
  const items = [];
12724
12768
  this.itemsArray.forEach((item) => {
12725
12769
  if (item.isEnclosedOrCrossedBy(mbr)) {
@@ -12728,19 +12772,30 @@ class SimpleSpatialIndex {
12728
12772
  });
12729
12773
  return items;
12730
12774
  }
12731
- getUnderPoint(point, tolerace = 5) {
12775
+ listUnderPoint(point, tolerance = 5) {
12732
12776
  const items = [];
12733
12777
  this.itemsArray.forEach((item) => {
12734
- if (item.isUnderPoint(point, tolerace)) {
12778
+ if (item.isUnderPoint(point, tolerance)) {
12735
12779
  items.push(item);
12736
12780
  }
12737
12781
  });
12738
12782
  return items;
12739
12783
  }
12784
+ listRectsEnclosedOrCrossedBy(left, top, right, bottom) {
12785
+ return this.listEnclosedOrCrossedBy(left, top, right, bottom).map((item) => item.getMbr());
12786
+ }
12787
+ listNearestTo(point, maxItems, filter, maxDistance) {
12788
+ const itemsWithDistance = this.itemsArray.filter(filter).map((item) => ({
12789
+ item,
12790
+ distance: item.getMbr().getDistanceToPoint(point)
12791
+ }));
12792
+ const inRange = itemsWithDistance.filter((x) => x.distance <= maxDistance);
12793
+ return inRange.sort((a, b) => a.distance - b.distance).slice(0, maxItems).map((x) => x.item);
12794
+ }
12740
12795
  getMbr() {
12741
12796
  return this.Mbr;
12742
12797
  }
12743
- list() {
12798
+ listAll() {
12744
12799
  return this.itemsArray.concat();
12745
12800
  }
12746
12801
  getZIndex(item) {
@@ -12812,7 +12867,7 @@ function toLocalTransformOp(op, containerMatrix, itemId) {
12812
12867
  }
12813
12868
  }
12814
12869
  var BaseItem;
12815
- var init_BaseItem2 = __esm(() => {
12870
+ var init_BaseItem = __esm(() => {
12816
12871
  init_Mbr();
12817
12872
  init_LinkTo();
12818
12873
  init_Transformation();
@@ -13011,7 +13066,10 @@ var init_BaseItem2 = __esm(() => {
13011
13066
  if (this.parent !== childId && this.getId() !== childId && !this.hasAncestor(childId)) {
13012
13067
  if (!this.index?.getById(childId) && foundItem) {
13013
13068
  const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerNestingMatrix);
13014
- this.board.items.index.remove(foundItem, true);
13069
+ const currentParentId = foundItem.parent;
13070
+ const currentParent = currentParentId !== "Board" ? this.board.items.getById(currentParentId) : undefined;
13071
+ const sourceIndex = currentParent?.index || this.board.items.index;
13072
+ sourceIndex.remove(foundItem, true);
13015
13073
  foundItem.parent = this.getId();
13016
13074
  foundItem.onParentChanged(this.getId());
13017
13075
  foundItem.transformation.setLocalMatrix(localMatrix);
@@ -13256,7 +13314,7 @@ var init_Comment = __esm(() => {
13256
13314
  init_Line2();
13257
13315
  init_esm_browser();
13258
13316
  init_LinkTo();
13259
- init_BaseItem2();
13317
+ init_BaseItem();
13260
13318
  Comment = class Comment extends BaseItem {
13261
13319
  anchor;
13262
13320
  events;
@@ -16610,7 +16668,7 @@ var init_getListTypeAtSelectionStart = __esm(() => {
16610
16668
  });
16611
16669
 
16612
16670
  // src/Items/RichText/editorHelpers/links/setLink.ts
16613
- import { Editor as Editor12, Transforms as Transforms11 } from "slate";
16671
+ import { Editor as Editor12, Transforms as Transforms11, Text as Text6 } from "slate";
16614
16672
  var setLink = (editor, link, selection) => {
16615
16673
  if (!selection) {
16616
16674
  selectWholeText(editor);
@@ -16622,15 +16680,15 @@ var setLink = (editor, link, selection) => {
16622
16680
  }
16623
16681
  const format = link ? "rgba(71, 120, 245, 1)" : "rgb(20, 21, 26)";
16624
16682
  Transforms11.setNodes(editor, { fontColor: format }, {
16625
- match: (n) => !Editor12.isEditor(n) && n.type === "text",
16683
+ match: (n) => Text6.isText(n),
16626
16684
  split: true
16627
16685
  });
16628
- for (const [node, path2] of Editor12.nodes(editor, {
16629
- match: (n) => !Editor12.isEditor(n) && n.type === "text"
16686
+ for (const [, path2] of Editor12.nodes(editor, {
16687
+ match: (n) => Text6.isText(n)
16630
16688
  })) {
16631
16689
  const nodeRange = Editor12.range(editor, path2);
16632
16690
  Transforms11.select(editor, nodeRange);
16633
- Transforms11.setNodes(editor, { link }, { split: false, match: (n) => !Editor12.isEditor(n) && n.type === "text" });
16691
+ Transforms11.setNodes(editor, { link }, { split: false, match: (n) => Text6.isText(n) });
16634
16692
  }
16635
16693
  };
16636
16694
  var init_setLink = __esm(() => {
@@ -24990,7 +25048,7 @@ var init_setEditorFocus = () => {};
24990
25048
  import {
24991
25049
  Editor as Editor31,
24992
25050
  Element as Element9,
24993
- Text as Text6,
25051
+ Text as Text7,
24994
25052
  Transforms as Transforms21
24995
25053
  } from "slate";
24996
25054
  var isEditInProcessValue = false, counter = 0, RichText;
@@ -25013,7 +25071,7 @@ var init_RichText = __esm(() => {
25013
25071
  init_getSelectionStyles();
25014
25072
  init_setEditorFocus();
25015
25073
  init_getAllTextNodesInSelection();
25016
- init_BaseItem2();
25074
+ init_BaseItem();
25017
25075
  RichText = class RichText extends BaseItem {
25018
25076
  container;
25019
25077
  transformation;
@@ -25558,7 +25616,7 @@ var init_RichText = __esm(() => {
25558
25616
  }
25559
25617
  getMinFontSize() {
25560
25618
  const textNodes = Editor31.nodes(this.editor.editor, {
25561
- match: (n) => Text6.isText(n),
25619
+ match: (n) => Text7.isText(n),
25562
25620
  at: []
25563
25621
  });
25564
25622
  const fontSizes = [];
@@ -25979,7 +26037,7 @@ var init_AINode = __esm(() => {
25979
26037
  init_Matrix();
25980
26038
  init_Transformation();
25981
26039
  init_Settings();
25982
- init_BaseItem2();
26040
+ init_BaseItem();
25983
26041
  AINode = class AINode extends BaseItem {
25984
26042
  itemType = "AINode";
25985
26043
  parent = "Board";
@@ -26326,7 +26384,7 @@ var init_Audio = __esm(() => {
26326
26384
  init_Point();
26327
26385
  init_Line();
26328
26386
  init_Settings();
26329
- init_BaseItem2();
26387
+ init_BaseItem();
26330
26388
  AudioItem = class AudioItem extends BaseItem {
26331
26389
  events;
26332
26390
  extension;
@@ -41323,6 +41381,11 @@ var init_ShapeData = __esm(() => {
41323
41381
  ];
41324
41382
  });
41325
41383
 
41384
+ // src/Items/BaseItem/index.ts
41385
+ var init_BaseItem2 = __esm(() => {
41386
+ init_BaseItem();
41387
+ });
41388
+
41326
41389
  // src/Items/Mbr/updateRects.ts
41327
41390
  function updateRects(board, ref, mbr, verticalOffset, horizontalOffset, fit = "contextPanel") {
41328
41391
  const { selection, camera } = board;
@@ -41593,7 +41656,7 @@ var init_ControlPoint = __esm(() => {
41593
41656
  init_Transformation2();
41594
41657
  init_RichText2();
41595
41658
  init_AINode2();
41596
- init_BaseItem();
41659
+ init_BaseItem2();
41597
41660
  BoardPoint = class BoardPoint extends Point {
41598
41661
  pointType = "Board";
41599
41662
  serialize() {
@@ -42493,7 +42556,7 @@ var init_Connector = __esm(() => {
42493
42556
  init_LinkTo();
42494
42557
  init_HTMLRender();
42495
42558
  init_Settings();
42496
- init_BaseItem2();
42559
+ init_BaseItem();
42497
42560
  init_Color();
42498
42561
  init_ConnectorTypes();
42499
42562
  CONNECTOR_ANCHOR_COLOR = {
@@ -43474,7 +43537,7 @@ var init_Sticker = __esm(() => {
43474
43537
  init_SessionStorage();
43475
43538
  init_HTMLRender();
43476
43539
  init_Settings();
43477
- init_BaseItem2();
43540
+ init_BaseItem();
43478
43541
  init_Color();
43479
43542
  stickerColors = {
43480
43543
  Purple: "rgb(233, 208, 255)",
@@ -44607,7 +44670,7 @@ async function exportBoardSnapshot({
44607
44670
  context.ctx.setTransform(upscaleFactor, 0, 0, upscaleFactor, 0, 0);
44608
44671
  context.matrix.applyToContext(context.ctx);
44609
44672
  const { left, top, right, bottom } = selection;
44610
- const inView = board.items.index.getRectsEnclosedOrCrossed(left, top, right, bottom);
44673
+ const inView = board.items.index.listEnclosedOrCrossedBy(left, top, right, bottom);
44611
44674
  for (const item of inView) {
44612
44675
  item.render(context);
44613
44676
  }
@@ -44727,7 +44790,7 @@ var init_Frame = __esm(() => {
44727
44790
  init_FrameData();
44728
44791
  init_Settings();
44729
44792
  init_getResizeMatrix();
44730
- init_BaseItem();
44793
+ init_BaseItem2();
44731
44794
  init_Color();
44732
44795
  defaultFrameData = new DefaultFrameData;
44733
44796
  Frame = class Frame extends BaseItem {
@@ -44846,7 +44909,7 @@ var init_Frame = __esm(() => {
44846
44909
  return this.id;
44847
44910
  }
44848
44911
  getChildrenIds() {
44849
- return this.index?.list().map((item) => item.getId()) || [];
44912
+ return this.index?.listAll().map((item) => item.getId()) || [];
44850
44913
  }
44851
44914
  updateMbr() {
44852
44915
  const rect = this.path.getMbr().copy();
@@ -45282,7 +45345,7 @@ var init_Video = __esm(() => {
45282
45345
  init_Path2();
45283
45346
  init_Transformation2();
45284
45347
  init_Settings();
45285
- init_BaseItem2();
45348
+ init_BaseItem();
45286
45349
  init_MediaHelpers();
45287
45350
  videoIcon = conf.documentFactory.createElement("img");
45288
45351
  videoIcon.src = VIDEO_ICON_SRC;
@@ -45925,7 +45988,7 @@ var init_Drawing = __esm(() => {
45925
45988
  init_DrawingCommand();
45926
45989
  init_LinkTo();
45927
45990
  init_Settings();
45928
- init_BaseItem2();
45991
+ init_BaseItem();
45929
45992
  init_Color();
45930
45993
  Drawing = class Drawing extends BaseItem {
45931
45994
  points;
@@ -46345,7 +46408,7 @@ var init_Group = __esm(() => {
46345
46408
  init_Point();
46346
46409
  init_Transformation();
46347
46410
  init_LinkTo();
46348
- init_BaseItem2();
46411
+ init_BaseItem();
46349
46412
  Group = class Group extends BaseItem {
46350
46413
  events;
46351
46414
  linkTo;
@@ -46405,7 +46468,7 @@ var init_Group = __esm(() => {
46405
46468
  return this;
46406
46469
  }
46407
46470
  getMbr() {
46408
- const children = this.index.list();
46471
+ const children = this.index.listAll();
46409
46472
  if (children.length === 0) {
46410
46473
  return new Mbr(this.left, this.top, this.right, this.bottom);
46411
46474
  }
@@ -46445,10 +46508,10 @@ var init_Group = __esm(() => {
46445
46508
  this.getMbr();
46446
46509
  }
46447
46510
  getChildrenIds() {
46448
- return this.index.list().map((item) => item.getId());
46511
+ return this.index.listAll().map((item) => item.getId());
46449
46512
  }
46450
46513
  getChildren() {
46451
- return this.index.list();
46514
+ return this.index.listAll();
46452
46515
  }
46453
46516
  getLinkTo() {
46454
46517
  return this.linkTo.link;
@@ -46496,7 +46559,7 @@ var init_Group = __esm(() => {
46496
46559
  const ctx = context.ctx;
46497
46560
  ctx.save();
46498
46561
  this.transformation.applyToContext(ctx);
46499
- for (const child of this.index.list()) {
46562
+ for (const child of this.index.listAll()) {
46500
46563
  child.render(context);
46501
46564
  }
46502
46565
  ctx.restore();
@@ -46604,7 +46667,7 @@ function createDrawing(id, data, board) {
46604
46667
  if (!isDrawingData(data)) {
46605
46668
  throw new Error("Invalid data for Drawing");
46606
46669
  }
46607
- const drawing = new Drawing(board, [], board.events).setId(id).deserialize({ ...data, id });
46670
+ const drawing = new Drawing(board, [], board.events).setId(id).setId(id).deserialize({ ...data, id });
46608
46671
  return drawing;
46609
46672
  }
46610
46673
  function createFrame(id, data, board) {
@@ -46625,7 +46688,7 @@ function createGroup(id, data, board) {
46625
46688
  if (!isGroupData(data)) {
46626
46689
  throw new Error("Invalid data for Group");
46627
46690
  }
46628
- const group = new Group(board, board.events, data.children, id).setId(id).deserialize({ ...data, id });
46691
+ const group = new Group(board, board.events, data.childIds, id).setId(id).deserialize({ ...data, id });
46629
46692
  return group;
46630
46693
  }
46631
46694
  function isStickerData(data) {
@@ -49163,7 +49226,7 @@ function getQuickAddButtons(selection, board) {
49163
49226
  }
49164
49227
  const newMbr = new Mbr(newItemData.transformation?.translateX, newItemData.transformation?.translateY, (newItemData.transformation?.translateX || 0) + newWidth, (newItemData.transformation?.translateY || 0) + newHeight);
49165
49228
  let step = 1;
49166
- while (board.index.getItemsEnclosedOrCrossed(newMbr.left, newMbr.top, newMbr.right, newMbr.bottom).filter((item) => item.itemType !== "Connector").length > 0) {
49229
+ while (board.index.listEnclosedOrCrossedBy(newMbr.left, newMbr.top, newMbr.right, newMbr.bottom).filter((item) => item.itemType !== "Connector").length > 0) {
49167
49230
  const xDirection = step % 2 === 0 ? -1 : 1;
49168
49231
  const yDirection = newItemData.itemType === "AINode" ? -1 : xDirection;
49169
49232
  newMbr.transform(new Matrix(iterAdjustment[index2].x * xDirection * step, iterAdjustment[index2].y * yDirection * (newItemData.itemType === "AINode" ? 1 : step)));
@@ -49405,7 +49468,7 @@ function getQuickAddButtons(selection, board) {
49405
49468
  var offsets;
49406
49469
  var init_QuickAddButtons2 = __esm(() => {
49407
49470
  init_Items();
49408
- init_BaseItem2();
49471
+ init_BaseItem();
49409
49472
  init_SessionStorage();
49410
49473
  init_QuickAddButtons();
49411
49474
  init_quickAddHelpers();
@@ -49838,7 +49901,7 @@ class AlignmentHelper {
49838
49901
  var RELATIVE_ALIGNMENT_COLOR = "#4778F5";
49839
49902
  var init_RelativeAlignment = __esm(() => {
49840
49903
  init_Items();
49841
- init_BaseItem();
49904
+ init_BaseItem2();
49842
49905
  });
49843
49906
 
49844
49907
  // src/Tools/RelativeAlignment/index.ts
@@ -51439,7 +51502,7 @@ var init_AddStar = __esm(() => {
51439
51502
  // src/Items/Examples/Star/Star.ts
51440
51503
  var defaultStarData, starPath, Star2;
51441
51504
  var init_Star2 = __esm(() => {
51442
- init_BaseItem2();
51505
+ init_BaseItem();
51443
51506
  init_Point();
51444
51507
  init_Path();
51445
51508
  init_Line();
@@ -51621,7 +51684,7 @@ var init_AddCounter = __esm(() => {
51621
51684
  // src/Items/Examples/Counter/Counter.ts
51622
51685
  var defaultCounterData, COUNTER_DIMENSIONS, Counter;
51623
51686
  var init_Counter = __esm(() => {
51624
- init_BaseItem2();
51687
+ init_BaseItem();
51625
51688
  init_Point();
51626
51689
  init_Path();
51627
51690
  init_Line();
@@ -51740,7 +51803,7 @@ var init_HotkeyRegistry = __esm(() => {
51740
51803
  // src/Items/Examples/CardGame/Card/Card.ts
51741
51804
  var defaultCardData, Card;
51742
51805
  var init_Card = __esm(() => {
51743
- init_BaseItem2();
51806
+ init_BaseItem();
51744
51807
  init_Path();
51745
51808
  init_RegisterItem();
51746
51809
  init_Settings();
@@ -51990,7 +52053,7 @@ function createDeck(event, board) {
51990
52053
  if (single && single.itemType === "Deck") {
51991
52054
  return;
51992
52055
  }
51993
- const cardsOrDecks = board.selection.items.list();
52056
+ const cardsOrDecks = board.selection.items.listAll();
51994
52057
  const onlyCards = board.selection.items.isAllItemsType("Card");
51995
52058
  if (onlyCards) {
51996
52059
  const deck = new Deck(board, "");
@@ -52006,12 +52069,12 @@ function createDeck(event, board) {
52006
52069
  if (item.itemType === "Card") {
52007
52070
  cards.push(item);
52008
52071
  } else if (item.itemType === "Deck") {
52072
+ const deck = item;
52009
52073
  if (mainDeck) {
52010
- cards.push(...mainDeck.getDeck());
52011
- board.remove(mainDeck);
52012
- mainDeck = item;
52074
+ cards.push(...deck.getDeck());
52075
+ board.remove(deck);
52013
52076
  } else {
52014
- mainDeck = item;
52077
+ mainDeck = deck;
52015
52078
  }
52016
52079
  }
52017
52080
  });
@@ -52024,9 +52087,10 @@ function createDeck(event, board) {
52024
52087
  }
52025
52088
  var defaultDeckData, Deck;
52026
52089
  var init_Deck = __esm(() => {
52027
- init_BaseItem2();
52090
+ init_BaseItem();
52028
52091
  init_RegisterItem();
52029
52092
  init_Card();
52093
+ init_DrawingContext();
52030
52094
  init_Settings();
52031
52095
  init_Path2();
52032
52096
  init_HotkeyRegistry();
@@ -52045,9 +52109,9 @@ var init_Deck = __esm(() => {
52045
52109
  drawingContext = null;
52046
52110
  constructor(board, id = "") {
52047
52111
  super(board, id, defaultDeckData, true);
52048
- this.index.getUnderPoint = () => [];
52049
- this.index.getEnclosed = () => [];
52050
- this.index.getEnclosedOrCrossed = () => [];
52112
+ this.index.listUnderPoint = () => [];
52113
+ this.index.listEnclosedBy = () => [];
52114
+ this.index.listEnclosedOrCrossedBy = () => [];
52051
52115
  this.transformation.subject.subscribe(() => {
52052
52116
  this.updateMbr();
52053
52117
  this.subject.publish(this);
@@ -52069,7 +52133,7 @@ var init_Deck = __esm(() => {
52069
52133
  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);
52070
52134
  if (canAddItem) {
52071
52135
  this.isPerpendicular = foundItem.getIsRotatedPerpendicular();
52072
- 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));
52136
+ 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));
52073
52137
  if (firstCard) {
52074
52138
  const { scaleX, scaleY } = foundItem.transformation.getMatrixData();
52075
52139
  const { scaleX: targetScaleX, scaleY: targetScaleY } = firstCard.transformation.getMatrixData();
@@ -52109,31 +52173,33 @@ var init_Deck = __esm(() => {
52109
52173
  this.subject.publish(this);
52110
52174
  }
52111
52175
  getDeck() {
52112
- return this.index?.list() || [];
52176
+ return this.index?.listAll() || [];
52113
52177
  }
52114
52178
  getTopCard() {
52115
- const card = this.index?.list()[this.index?.list().length - 1];
52179
+ const cards = this.index?.listAll() || [];
52180
+ const card = cards[cards.length - 1];
52116
52181
  if (card) {
52117
52182
  this.removeChildItems(card);
52118
52183
  return card;
52119
52184
  }
52120
52185
  }
52121
52186
  getCards(count) {
52122
- const cards = this.index?.list().reverse().slice(0, count);
52123
- if (cards) {
52187
+ const cards = (this.index?.listAll() || []).reverse().slice(0, count);
52188
+ if (cards.length > 0) {
52124
52189
  this.removeChildItems(cards);
52125
52190
  return cards;
52126
52191
  }
52127
52192
  }
52128
52193
  getBottomCard() {
52129
- const card = this.index?.list()[0];
52194
+ const card = this.index?.listAll()[0];
52130
52195
  if (card) {
52131
52196
  this.removeChildItems(card);
52132
52197
  return card;
52133
52198
  }
52134
52199
  }
52135
52200
  getRandomCard() {
52136
- const card = this.index?.list()[Math.floor(Math.random() * this.index?.list().length)];
52201
+ const cards = this.index?.listAll() || [];
52202
+ const card = cards[Math.floor(Math.random() * cards.length)];
52137
52203
  if (card) {
52138
52204
  this.removeChildItems(card);
52139
52205
  return card;
@@ -52143,20 +52209,20 @@ var init_Deck = __esm(() => {
52143
52209
  if (!this.index) {
52144
52210
  return;
52145
52211
  }
52146
- const shuffled = [...this.index.list()];
52212
+ const shuffled = [...this.index.listAll()];
52147
52213
  for (let i = shuffled.length - 1;i > 0; i--) {
52148
52214
  const j = Math.floor(Math.random() * (i + 1));
52149
52215
  [shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
52150
52216
  }
52151
52217
  this.emitAnimation();
52152
- this.removeChildItems(this.index.list());
52218
+ this.removeChildItems(this.index.listAll());
52153
52219
  this.addChildItems(shuffled);
52154
52220
  }
52155
52221
  flipDeck() {
52156
- if (!this.index || !this.index.list().length) {
52222
+ if (!this.index || !this.index.listAll().length) {
52157
52223
  return;
52158
52224
  }
52159
- const cards = this.index.list();
52225
+ const cards = this.index.listAll();
52160
52226
  cards[0].toggleIsOpen(cards);
52161
52227
  const reversed = [...cards].reverse();
52162
52228
  this.removeChildItems(cards);
@@ -52177,7 +52243,7 @@ var init_Deck = __esm(() => {
52177
52243
  }
52178
52244
  updateMbr() {
52179
52245
  const { translateX, translateY } = this.transformation.getMatrixData();
52180
- const items = this.index.list();
52246
+ const items = this.index.listAll();
52181
52247
  const itemsMbr = items[0]?.getMbr().combine(items.slice(1).map((item) => item.getMbr()));
52182
52248
  this.left = translateX;
52183
52249
  this.top = translateY;
@@ -52245,7 +52311,7 @@ var init_Deck = __esm(() => {
52245
52311
  }
52246
52312
  renderHTML(documentFactory) {
52247
52313
  const div = super.renderHTML(documentFactory);
52248
- const cards = this.index?.list();
52314
+ const cards = this.index?.listAll();
52249
52315
  const topCard = cards[cards.length - 1];
52250
52316
  if (!topCard) {
52251
52317
  return div;
@@ -52254,7 +52320,7 @@ var init_Deck = __esm(() => {
52254
52320
  const transform = `translate(${translateX}px, ${translateY}px) scale(1, 1)`;
52255
52321
  const topCardElement = topCard.renderHTML(documentFactory);
52256
52322
  div.appendChild(topCardElement);
52257
- const offset = ((this.index?.list().length || 0) - 1) * 2;
52323
+ const offset = ((this.index?.listAll().length || 0) - 1) * 2;
52258
52324
  topCardElement.style.transform = `translate(${offset}px, ${0}px) scale(1, 1)`;
52259
52325
  div.id = this.getId();
52260
52326
  div.style.width = `${this.getWidth()}px`;
@@ -52267,7 +52333,7 @@ var init_Deck = __esm(() => {
52267
52333
  return div;
52268
52334
  }
52269
52335
  updateCache(context) {
52270
- const cards = this.index?.list();
52336
+ const cards = this.index?.listAll();
52271
52337
  const topCard = cards[cards.length - 1];
52272
52338
  const topCardImage = topCard?.getImage();
52273
52339
  const width2 = this.getWidth();
@@ -52281,7 +52347,7 @@ var init_Deck = __esm(() => {
52281
52347
  const tempCtx = tempCanvas.getContext("2d");
52282
52348
  if (!tempCtx)
52283
52349
  return;
52284
- const tempContext = { ...context, ctx: tempCtx };
52350
+ const tempContext = new DrawingContext(context.camera, tempCtx, context.cursorCtx, context.matrix);
52285
52351
  cards.forEach((_, index2) => {
52286
52352
  topCard.render(tempContext, this.isPerpendicular ? 0 : index2 * conf.DECK_HORIZONTAL_OFFSET, this.isPerpendicular ? index2 * conf.DECK_VERTICAL_OFFSET : 0);
52287
52353
  });
@@ -52290,7 +52356,7 @@ var init_Deck = __esm(() => {
52290
52356
  this.updateMbr();
52291
52357
  }
52292
52358
  getFirstCard() {
52293
- return this.index?.list()[0];
52359
+ return this.index?.listAll()[0];
52294
52360
  }
52295
52361
  };
52296
52362
  registerItem({
@@ -52424,7 +52490,7 @@ var init_AddDice = __esm(() => {
52424
52490
  // src/Items/Examples/CardGame/Dice/Dice.ts
52425
52491
  var TIMEOUT = 2000, defaultDiceData, Dice;
52426
52492
  var init_Dice = __esm(() => {
52427
- init_BaseItem2();
52493
+ init_BaseItem();
52428
52494
  init_Items();
52429
52495
  init_RoundedRectangle();
52430
52496
  init_Items();
@@ -52825,7 +52891,7 @@ var init_AddScreen = __esm(() => {
52825
52891
  // src/Items/Examples/CardGame/Screen/Screen.ts
52826
52892
  var screenPath, defaultScreenData, Screen;
52827
52893
  var init_Screen = __esm(() => {
52828
- init_BaseItem2();
52894
+ init_BaseItem();
52829
52895
  init_RegisterItem();
52830
52896
  init_Path2();
52831
52897
  init_Line2();
@@ -52972,9 +53038,9 @@ var init_Screen = __esm(() => {
52972
53038
  applyOwnerId(ownerId) {
52973
53039
  this.ownerId = ownerId;
52974
53040
  if (!this.ownerId) {
52975
- this.index.getUnderPoint = () => [];
52976
- this.index.getEnclosed = () => [];
52977
- this.index.getEnclosedOrCrossed = () => [];
53041
+ this.index.listUnderPoint = () => [];
53042
+ this.index.listEnclosedBy = () => [];
53043
+ this.index.listEnclosedOrCrossedBy = () => [];
52978
53044
  }
52979
53045
  }
52980
53046
  transformPath() {
@@ -52997,16 +53063,17 @@ var init_Screen = __esm(() => {
52997
53063
  this.applyBackgroundUrl(this.backgroundUrl);
52998
53064
  }
52999
53065
  if (!this.ownerId) {
53000
- this.index.getUnderPoint = () => [];
53001
- this.index.getEnclosed = () => [];
53002
- this.index.getEnclosedOrCrossed = () => [];
53066
+ this.index.listUnderPoint = () => [];
53067
+ this.index.listEnclosedBy = () => [];
53068
+ this.index.listEnclosedOrCrossedBy = () => [];
53003
53069
  }
53004
53070
  this.transformPath();
53005
53071
  this.subject.publish(this);
53006
53072
  return this;
53007
53073
  }
53008
53074
  getRandomItem() {
53009
- const item = this.index?.list()[Math.floor(Math.random() * this.index?.list().length)];
53075
+ const items = this.index?.listAll() || [];
53076
+ const item = items[Math.floor(Math.random() * items.length)];
53010
53077
  if (item) {
53011
53078
  this.removeChildItems(item);
53012
53079
  return item;
@@ -53055,7 +53122,7 @@ var init_Screen2 = __esm(() => {
53055
53122
 
53056
53123
  // src/Items/index.ts
53057
53124
  var init_Items = __esm(() => {
53058
- init_BaseItem();
53125
+ init_BaseItem2();
53059
53126
  init_Point2();
53060
53127
  init_Line2();
53061
53128
  init_Curve2();
@@ -53930,7 +53997,7 @@ var init_Shape = __esm(() => {
53930
53997
  init_Connector2();
53931
53998
  init_ControlPoint();
53932
53999
  init_Settings();
53933
- init_BaseItem2();
54000
+ init_BaseItem();
53934
54001
  init_Color();
53935
54002
  defaultShapeData = new DefaultShapeData;
53936
54003
  Shapes = { ...BasicShapes, ...BPMN };
@@ -54456,7 +54523,7 @@ var init_Placeholder2 = __esm(() => {
54456
54523
  init_Transformation();
54457
54524
  init_PlaceholderCommand();
54458
54525
  init_getResizeMatrix();
54459
- init_BaseItem2();
54526
+ init_BaseItem();
54460
54527
  Placeholder2 = class Placeholder2 extends BaseItem {
54461
54528
  events;
54462
54529
  miroData;
@@ -54765,7 +54832,7 @@ var init_Image = __esm(() => {
54765
54832
  init_Placeholder2();
54766
54833
  init_LinkTo();
54767
54834
  init_Settings();
54768
- init_BaseItem2();
54835
+ init_BaseItem();
54769
54836
  init_MediaHelpers();
54770
54837
  ImageItem = class ImageItem extends BaseItem {
54771
54838
  events;
@@ -55328,10 +55395,20 @@ function handleBoardEventMessage(message, board) {
55328
55395
  if (isEventFromCurrentUser) {
55329
55396
  return;
55330
55397
  }
55331
- log.insertEventsFromOtherConnections({
55332
- ...event,
55333
- userId: Number(message.userId)
55334
- });
55398
+ if ("operations" in event.body) {
55399
+ log.insertEventsFromOtherConnections({
55400
+ ...event,
55401
+ body: {
55402
+ ...event.body,
55403
+ userId: Number(message.userId)
55404
+ }
55405
+ });
55406
+ } else {
55407
+ log.insertEventsFromOtherConnections({
55408
+ ...event,
55409
+ userId: Number(message.userId)
55410
+ });
55411
+ }
55335
55412
  const last = log.getLastConfirmed();
55336
55413
  if (last) {
55337
55414
  board.events.subject.publish(last);
@@ -55349,7 +55426,7 @@ function handleBoardSubscriptionCompletedMsg(msg, board) {
55349
55426
  handleHTMLSnapshotApplication(msg.JSONSnapshot, board);
55350
55427
  log.list.clearConfirmedRecords();
55351
55428
  }
55352
- handleBoardEventListApplication(msg.eventsSinceLastSnapshot, board);
55429
+ handleBoardEventListApplication(expandEvents(msg.eventsSinceLastSnapshot), board);
55353
55430
  board.setInterfaceType(msg.mode);
55354
55431
  board.subject.publish();
55355
55432
  onBoardLoad(board);
@@ -57506,7 +57583,7 @@ init_Settings();
57506
57583
  init_QuickAddButtons3();
57507
57584
 
57508
57585
  // src/Selection/SelectionItems.ts
57509
- init_BaseItem();
57586
+ init_BaseItem2();
57510
57587
 
57511
57588
  class SelectionItems {
57512
57589
  items = new Map;
@@ -57533,6 +57610,9 @@ class SelectionItems {
57533
57610
  list() {
57534
57611
  return Array.from(this.items.values());
57535
57612
  }
57613
+ listAll() {
57614
+ return this.list();
57615
+ }
57536
57616
  isEmpty() {
57537
57617
  return this.items.size === 0;
57538
57618
  }
@@ -57828,7 +57908,7 @@ init_RichText();
57828
57908
  init_AINode();
57829
57909
  init_Sticker();
57830
57910
  init_Frame();
57831
- init_BaseItem();
57911
+ init_BaseItem2();
57832
57912
  function handleMultipleItemsResize({
57833
57913
  board,
57834
57914
  resize,
@@ -58211,7 +58291,7 @@ init_Image();
58211
58291
  init_SessionStorage();
58212
58292
  init_Point();
58213
58293
  init_Items();
58214
- init_BaseItem();
58294
+ init_BaseItem2();
58215
58295
  function transformItems({
58216
58296
  board,
58217
58297
  selection,
@@ -60996,8 +61076,9 @@ class Board {
60996
61076
  const data = Array.from(items.children).map((el) => this.parseHTML(el));
60997
61077
  for (const parsedData of data) {
60998
61078
  if ("childrenMap" in parsedData) {
60999
- const addedFrame = this.add(this.createItem(this.getNewItemId(), parsedData.data));
61000
- const addedChildren = Object.values(parsedData.childrenMap).map((childData) => {
61079
+ const frameData = parsedData;
61080
+ const addedFrame = this.add(this.createItem(this.getNewItemId(), frameData.data));
61081
+ const addedChildren = Object.values(frameData.childrenMap).map((childData) => {
61001
61082
  const created = this.createItem(this.getNewItemId(), childData);
61002
61083
  const added = this.add(created);
61003
61084
  idsMap[childData.id] = added.getId();
@@ -61010,17 +61091,18 @@ class Board {
61010
61091
  return added;
61011
61092
  });
61012
61093
  addedFrame.addChildItems(addedChildren);
61013
- parsedData.data.children = addedChildren.map((item) => item.getId());
61014
- idsMap[parsedData.data.id] = addedFrame.getId();
61094
+ frameData.data.children = addedChildren.map((item) => item.getId());
61095
+ idsMap[frameData.data.id] = addedFrame.getId();
61015
61096
  } else {
61016
- const added = this.add(this.createItem(this.getNewItemId(), parsedData));
61097
+ const itemData = parsedData;
61098
+ const added = this.add(this.createItem(this.getNewItemId(), itemData));
61017
61099
  if (added.itemType === "Connector") {
61018
61100
  addedConnectors.push({
61019
61101
  item: added,
61020
- data: parsedData
61102
+ data: itemData
61021
61103
  });
61022
61104
  }
61023
- idsMap[parsedData.id] = added.getId();
61105
+ idsMap[itemData.id] = added.getId();
61024
61106
  }
61025
61107
  }
61026
61108
  addedConnectors.forEach((connector) => {
@@ -61064,12 +61146,13 @@ class Board {
61064
61146
  this.index.insert(item);
61065
61147
  return item;
61066
61148
  };
61067
- for (const itemData of items) {
61068
- if ("childrenMap" in itemData) {
61069
- Object.values(itemData.childrenMap).map((childData) => addItem(childData));
61070
- addItem(itemData.data);
61149
+ for (const rawItemData of items) {
61150
+ if ("childrenMap" in rawItemData) {
61151
+ const frameData = rawItemData;
61152
+ Object.values(frameData.childrenMap).map((childData) => addItem(childData));
61153
+ addItem(frameData.data);
61071
61154
  } else {
61072
- addItem(itemData);
61155
+ addItem(rawItemData);
61073
61156
  }
61074
61157
  }
61075
61158
  for (const key in createdConnectors) {
@@ -61502,8 +61585,9 @@ class Board {
61502
61585
  itemData.transformation.translateX = translateX + width2 * 10 + 10;
61503
61586
  }
61504
61587
  }
61505
- if ("children" in itemData && itemData.children?.length) {
61506
- itemData.children = itemData.children.map((childId) => newItemIdMap[childId]);
61588
+ const itemDataWithChildren = itemData;
61589
+ if ("children" in itemDataWithChildren && itemDataWithChildren.children?.length) {
61590
+ itemDataWithChildren.children = itemDataWithChildren.children.map((childId) => newItemIdMap[childId]);
61507
61591
  }
61508
61592
  newMap[newItemId] = itemData;
61509
61593
  }
@@ -61686,7 +61770,7 @@ function initI18N(i18nInstance) {
61686
61770
  // src/index.ts
61687
61771
  init_MediaHelpers();
61688
61772
  init_CreateCommand();
61689
- init_BaseItem2();
61773
+ init_BaseItem();
61690
61774
  init_Events();
61691
61775
  BaseItem.createCommand = createCommand;
61692
61776
  Events.createCommand = createCommand;