microboard-temp 0.13.42 → 0.13.43

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 (49) hide show
  1. package/dist/cjs/browser.js +270 -195
  2. package/dist/cjs/index.js +270 -195
  3. package/dist/cjs/node.js +270 -195
  4. package/dist/esm/browser.js +270 -195
  5. package/dist/esm/index.js +270 -195
  6. package/dist/esm/node.js +270 -195
  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/RichText.d.ts +1 -1
  35. package/dist/types/Items/RichText/RichTextData.d.ts +1 -1
  36. package/dist/types/Items/Shape/Shape.d.ts +1 -1
  37. package/dist/types/Items/Sticker/Sticker.d.ts +1 -1
  38. package/dist/types/Items/Video/Video.d.ts +1 -1
  39. package/dist/types/Presence/Events.d.ts +1 -20
  40. package/dist/types/Presence/Presence.d.ts +2 -1
  41. package/dist/types/Selection/Selection.d.ts +1 -1
  42. package/dist/types/Selection/SelectionItems.d.ts +1 -0
  43. package/dist/types/Settings.d.ts +7 -7
  44. package/dist/types/SpatialIndex/LayeredIndex/index.d.ts +12 -8
  45. package/dist/types/SpatialIndex/RTreeIndex/index.d.ts +12 -7
  46. package/dist/types/SpatialIndex/SimpleSpatialIndex.d.ts +24 -8
  47. package/dist/types/SpatialIndex/SpacialIndex.d.ts +81 -9
  48. package/dist/types/Tools/CustomTool.d.ts +3 -3
  49. package/package.json +1 -1
@@ -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 {
@@ -5882,16 +5887,17 @@ var init_transformEvents = __esm(() => {
5882
5887
  function expandEvents(events) {
5883
5888
  return events.flatMap((event) => {
5884
5889
  if ("operations" in event.body) {
5885
- return event.body.operations.map((operation) => ({
5890
+ const { operations, lastKnownOrder, ...bodyWithoutOps } = event.body;
5891
+ return operations.map((operation) => ({
5886
5892
  order: event.order,
5887
5893
  body: {
5888
- eventId: operation.actualId || event.body.eventId,
5889
- userId: event.body.userId,
5890
- boardId: event.body.boardId,
5894
+ eventId: operation.actualId || bodyWithoutOps.eventId,
5895
+ userId: bodyWithoutOps.userId,
5896
+ boardId: bodyWithoutOps.boardId,
5891
5897
  operation
5892
5898
  },
5893
- userId: event.body.userId,
5894
- lastKnownOrder: "lastKnownOrder" in event ? event.lastKnownOrder : event.body.lastKnownOrder
5899
+ userId: bodyWithoutOps.userId,
5900
+ lastKnownOrder
5895
5901
  }));
5896
5902
  } else {
5897
5903
  return [event];
@@ -6003,13 +6009,15 @@ var init_insertEventsFromOtherConnectionsIntoList = __esm(() => {
6003
6009
  function deserializeAndApplyToList(events, list, board) {
6004
6010
  list.clear();
6005
6011
  for (const event of events) {
6006
- const body = event.body;
6007
- if (body.operations && Array.isArray(body.operations)) {
6008
- for (const op of body.operations) {
6012
+ if ("operations" in event.body) {
6013
+ const { operations, lastKnownOrder, ...bodyWithoutOps } = event.body;
6014
+ for (const op of operations) {
6009
6015
  const singleEvent = {
6010
- ...event,
6016
+ order: event.order,
6017
+ lastKnownOrder,
6018
+ userId: bodyWithoutOps.userId,
6011
6019
  body: {
6012
- ...event.body,
6020
+ ...bodyWithoutOps,
6013
6021
  operation: op
6014
6022
  }
6015
6023
  };
@@ -11595,7 +11603,7 @@ class RTreeIndex {
11595
11603
  this.tree.remove(item);
11596
11604
  }
11597
11605
  }
11598
- list() {
11606
+ listAll() {
11599
11607
  const containers = this.tree.all();
11600
11608
  const items = [];
11601
11609
  for (const container of containers) {
@@ -11603,7 +11611,7 @@ class RTreeIndex {
11603
11611
  }
11604
11612
  return items;
11605
11613
  }
11606
- getEnclosed(rect) {
11614
+ listEnclosedBy(rect) {
11607
11615
  return this.tree.search({
11608
11616
  minX: rect.left,
11609
11617
  minY: rect.top,
@@ -11611,7 +11619,7 @@ class RTreeIndex {
11611
11619
  maxY: rect.bottom
11612
11620
  }).filter((container) => container.item.isEnclosedBy(rect)).map((container) => container.item);
11613
11621
  }
11614
- getEnclosedOrCrossedBy(rect) {
11622
+ listEnclosedOrCrossedBy(rect) {
11615
11623
  return this.tree.search({
11616
11624
  minX: rect.left,
11617
11625
  minY: rect.top,
@@ -11619,7 +11627,7 @@ class RTreeIndex {
11619
11627
  maxY: rect.bottom
11620
11628
  }).filter((container) => container.item.isEnclosedOrCrossedBy(rect)).map((container) => container.item);
11621
11629
  }
11622
- getUnderPoint(point, tolerance = 5) {
11630
+ listUnderPoint(point, tolerance = 5) {
11623
11631
  return this.tree.search({
11624
11632
  minX: point.x,
11625
11633
  minY: point.y,
@@ -11627,7 +11635,7 @@ class RTreeIndex {
11627
11635
  maxY: point.y
11628
11636
  }).filter((container) => container.item.isUnderPoint(point, tolerance)).map((container) => container.item);
11629
11637
  }
11630
- getRectsEnclosedOrCrossedBy(rect) {
11638
+ listRectsEnclosedOrCrossedBy(rect) {
11631
11639
  return this.tree.search({
11632
11640
  minX: rect.left,
11633
11641
  minY: rect.top,
@@ -11643,9 +11651,27 @@ class RTreeIndex {
11643
11651
  maxY: rect.bottom
11644
11652
  });
11645
11653
  }
11646
- getNearestTo(point, maxItems, filter, maxDistance) {
11654
+ listNearestTo(point, maxItems, filter, maxDistance) {
11647
11655
  return knn(this.tree, point.x, point.y, maxItems, (container) => filter(container.item), maxDistance).map((container) => container.item);
11648
11656
  }
11657
+ getById(id) {
11658
+ return this.listAll().find((item) => item.getId() === id);
11659
+ }
11660
+ findById(id) {
11661
+ return this.getById(id);
11662
+ }
11663
+ getByZIndex(index) {
11664
+ return this.listAll()[index];
11665
+ }
11666
+ getLastZIndex() {
11667
+ return this.listAll().length - 1;
11668
+ }
11669
+ copy() {
11670
+ return this.listAll().map((item) => ({
11671
+ ...item.serialize(),
11672
+ id: item.getId()
11673
+ }));
11674
+ }
11649
11675
  batchInsert(batch) {
11650
11676
  for (const one of batch) {
11651
11677
  this.insert(one);
@@ -11717,35 +11743,31 @@ class LayeredIndex {
11717
11743
  isT(item) {
11718
11744
  return true;
11719
11745
  }
11720
- findById(id) {
11721
- const container = this.map.get(id);
11722
- return container ? container.item : undefined;
11723
- }
11724
- getEnclosed(rect) {
11746
+ listEnclosedBy(rect) {
11725
11747
  let items = [];
11726
11748
  for (const layer of this.layers.array) {
11727
- items = items.concat(layer.getEnclosed(rect));
11749
+ items = items.concat(layer.listEnclosedBy(rect));
11728
11750
  }
11729
11751
  return items;
11730
11752
  }
11731
- getEnclosedOrCrossedBy(rect) {
11753
+ listEnclosedOrCrossedBy(rect) {
11732
11754
  let items = [];
11733
11755
  for (const layer of this.layers.array) {
11734
- items = items.concat(layer.getEnclosedOrCrossedBy(rect));
11756
+ items = items.concat(layer.listEnclosedOrCrossedBy(rect));
11735
11757
  }
11736
11758
  return items;
11737
11759
  }
11738
- getUnderPoint(point, tolerance = 5) {
11760
+ listUnderPoint(point, tolerance = 5) {
11739
11761
  let items = [];
11740
11762
  for (const layer of this.layers.array) {
11741
- const layerItems = layer.getUnderPoint(point, tolerance);
11763
+ const layerItems = layer.listUnderPoint(point, tolerance);
11742
11764
  if (layerItems.length > 0) {
11743
11765
  items = items.concat(layerItems);
11744
11766
  }
11745
11767
  }
11746
11768
  return items;
11747
11769
  }
11748
- getRectsEnclosedOrCrossedBy(rect) {
11770
+ listRectsEnclosedOrCrossedBy(rect) {
11749
11771
  const items = [];
11750
11772
  const minMax = {
11751
11773
  minX: rect.left,
@@ -11769,10 +11791,10 @@ class LayeredIndex {
11769
11791
  }
11770
11792
  return false;
11771
11793
  }
11772
- getNearestTo(point, maxItems, filter, maxDistance) {
11794
+ listNearestTo(point, maxItems, filter, maxDistance) {
11773
11795
  let items = [];
11774
11796
  for (const layer of this.layers.array) {
11775
- items = items.concat(layer.getNearestTo(point, maxItems, filter, maxDistance));
11797
+ items = items.concat(layer.listNearestTo(point, maxItems, filter, maxDistance));
11776
11798
  }
11777
11799
  return items;
11778
11800
  }
@@ -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 containersAbove = [];
11812
11834
  const containerZIndex = this.getZIndex(container.item);
@@ -11834,7 +11856,7 @@ class LayeredIndex {
11834
11856
  }
11835
11857
  const bounds = container.item.getMbrWithChildren();
11836
11858
  this.remove(container.item);
11837
- const inBounds = this.getRectsEnclosedOrCrossedBy(bounds);
11859
+ const inBounds = this.listRectsEnclosedOrCrossedBy(bounds);
11838
11860
  const containersInBounds = this.getContainersFromItems(inBounds);
11839
11861
  const containersBelow = [];
11840
11862
  const containerZIndex = this.getZIndex(container.item);
@@ -11859,7 +11881,7 @@ class LayeredIndex {
11859
11881
  insert(item) {
11860
11882
  const toInsert = new Container(item.getId(), item, 0, this.getZIndex(item));
11861
11883
  const bounds = item.getMbrWithChildren();
11862
- const inBounds = this.getRectsEnclosedOrCrossedBy(bounds);
11884
+ const inBounds = this.listRectsEnclosedOrCrossedBy(bounds);
11863
11885
  if (inBounds.length === 0) {
11864
11886
  return this.insertContainer(toInsert);
11865
11887
  }
@@ -11956,13 +11978,32 @@ class LayeredIndex {
11956
11978
  return;
11957
11979
  }
11958
11980
  }
11959
- list() {
11981
+ listAll() {
11960
11982
  const items = [];
11961
11983
  for (const record of this.map) {
11962
11984
  items.push(record[1].item);
11963
11985
  }
11964
11986
  return items;
11965
11987
  }
11988
+ getById(id) {
11989
+ const container = this.map.get(id);
11990
+ return container ? container.item : undefined;
11991
+ }
11992
+ findById(id) {
11993
+ return this.getById(id);
11994
+ }
11995
+ getByZIndex(index) {
11996
+ return this.listAll()[index];
11997
+ }
11998
+ getLastZIndex() {
11999
+ return this.listAll().length - 1;
12000
+ }
12001
+ copy() {
12002
+ return this.listAll().map((item) => ({
12003
+ ...item.serialize(),
12004
+ id: item.getId()
12005
+ }));
12006
+ }
11966
12007
  batchInsert(items) {
11967
12008
  for (const item of items) {
11968
12009
  this.insert(item);
@@ -11979,11 +12020,6 @@ var init_LayeredIndex = __esm(() => {
11979
12020
  init_RTreeIndex();
11980
12021
  });
11981
12022
 
11982
- // src/Items/BaseItem/index.ts
11983
- var init_BaseItem = __esm(() => {
11984
- init_BaseItem2();
11985
- });
11986
-
11987
12023
  // src/SpatialIndex/SpacialIndex.ts
11988
12024
  function worldBoundsToLocal(container, left, top, right, bottom) {
11989
12025
  const inv = container.getNestingMatrix().getInverse();
@@ -12002,6 +12038,13 @@ function worldBoundsToLocal(container, left, top, right, bottom) {
12002
12038
  bottom: Math.max(corners[0].y, corners[1].y, corners[2].y, corners[3].y)
12003
12039
  };
12004
12040
  }
12041
+ function coerceMbr(left, top, right, bottom) {
12042
+ if (left instanceof Mbr)
12043
+ return left;
12044
+ if (typeof left === "object" && left !== null)
12045
+ return new Mbr(left.left, left.top, left.right, left.bottom);
12046
+ return new Mbr(left, top, right, bottom);
12047
+ }
12005
12048
 
12006
12049
  class SpatialIndex {
12007
12050
  subject = new Subject;
@@ -12050,7 +12093,7 @@ class SpatialIndex {
12050
12093
  remove(item, preserveChildren = false) {
12051
12094
  const baseItem = item;
12052
12095
  if (!preserveChildren && baseItem.index) {
12053
- baseItem.removeChildItems(baseItem.index.list());
12096
+ baseItem.removeChildItems(baseItem.index.listAll());
12054
12097
  }
12055
12098
  this.itemsArray.splice(this.itemsArray.indexOf(item), 1);
12056
12099
  this.itemsIndex.remove(item);
@@ -12093,14 +12136,14 @@ class SpatialIndex {
12093
12136
  return items.flatMap((item) => {
12094
12137
  const baseItem = item;
12095
12138
  if (baseItem.index) {
12096
- return [item, ...baseItem.index.list()];
12139
+ return [item, ...baseItem.index.listAll()];
12097
12140
  }
12098
12141
  return item;
12099
12142
  });
12100
12143
  }
12101
12144
  getItemChildren(item) {
12102
12145
  if ("index" in item && item.index) {
12103
- return item.index.list();
12146
+ return item.index.listAll();
12104
12147
  }
12105
12148
  return [];
12106
12149
  }
@@ -12251,14 +12294,14 @@ class SpatialIndex {
12251
12294
  findById(id) {
12252
12295
  return this.getById(id);
12253
12296
  }
12254
- getEnclosed(left, top, right, bottom) {
12255
- const mbr = new Mbr(left, top, right, bottom);
12256
- const items = this.itemsIndex.getEnclosed(mbr);
12297
+ listEnclosedBy(left, top, right, bottom) {
12298
+ const mbr = coerceMbr(left, top, right, bottom);
12299
+ const items = this.itemsIndex.listEnclosedBy(mbr);
12257
12300
  const children = [];
12258
12301
  const clearItems = items.filter((item) => {
12259
12302
  if ("index" in item && item.index) {
12260
- const local = worldBoundsToLocal(item, left, top, right, bottom);
12261
- children.push(...item.index.getEnclosed(local.left, local.top, local.right, local.bottom));
12303
+ const local = worldBoundsToLocal(item, mbr.left, mbr.top, mbr.right, mbr.bottom);
12304
+ children.push(...item.index.listEnclosedBy(local.left, local.top, local.right, local.bottom));
12262
12305
  if (!item.getMbr().isEnclosedBy(mbr)) {
12263
12306
  return false;
12264
12307
  }
@@ -12267,14 +12310,14 @@ class SpatialIndex {
12267
12310
  });
12268
12311
  return [...clearItems, ...children];
12269
12312
  }
12270
- getEnclosedOrCrossed(left, top, right, bottom) {
12271
- const mbr = new Mbr(left, top, right, bottom);
12272
- const items = this.itemsIndex.getEnclosedOrCrossedBy(mbr);
12313
+ listEnclosedOrCrossedBy(left, top, right, bottom) {
12314
+ const mbr = coerceMbr(left, top, right, bottom);
12315
+ const items = this.itemsIndex.listEnclosedOrCrossedBy(mbr);
12273
12316
  const children = [];
12274
12317
  const clearItems = items.filter((item) => {
12275
12318
  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));
12319
+ const local = worldBoundsToLocal(item, mbr.left, mbr.top, mbr.right, mbr.bottom);
12320
+ children.push(...item.index.listEnclosedOrCrossedBy(local.left, local.top, local.right, local.bottom));
12278
12321
  if (!item.getMbr().isEnclosedOrCrossedBy(mbr)) {
12279
12322
  return false;
12280
12323
  }
@@ -12283,14 +12326,17 @@ class SpatialIndex {
12283
12326
  });
12284
12327
  return [...clearItems, ...children];
12285
12328
  }
12286
- getUnderPoint(point, tolerance = 5) {
12287
- const items = this.itemsIndex.getUnderPoint(point, tolerance);
12329
+ listRectsEnclosedOrCrossedBy(left, top, right, bottom) {
12330
+ return this.listEnclosedOrCrossedBy(left, top, right, bottom).map((item) => item.getMbr());
12331
+ }
12332
+ listUnderPoint(point, tolerance = 5) {
12333
+ const items = this.itemsIndex.listUnderPoint(point, tolerance);
12288
12334
  const children = [];
12289
12335
  const clearItems = items.filter((item) => {
12290
12336
  if ("index" in item && item.index) {
12291
12337
  const localPt = new Point(point.x, point.y);
12292
12338
  item.getNestingMatrix().getInverse().apply(localPt);
12293
- children.push(...item.index.getUnderPoint(localPt, tolerance));
12339
+ children.push(...item.index.listUnderPoint(localPt, tolerance));
12294
12340
  if (!item.getMbr().isUnderPoint(point)) {
12295
12341
  return false;
12296
12342
  }
@@ -12302,24 +12348,8 @@ class SpatialIndex {
12302
12348
  });
12303
12349
  return [...clearItems, ...children];
12304
12350
  }
12305
- getRectsEnclosedOrCrossed(left, top, right, bottom) {
12306
- const mbr = new Mbr(left, top, right, bottom);
12307
- const items = this.itemsIndex.getRectsEnclosedOrCrossedBy(mbr);
12308
- const children = [];
12309
- const clearItems = items.filter((item) => {
12310
- if ("index" in item && item.index) {
12311
- const local = worldBoundsToLocal(item, left, top, right, bottom);
12312
- children.push(...item.index.getEnclosedOrCrossed(local.left, local.top, local.right, local.bottom));
12313
- if (!item.getMbr().isEnclosedOrCrossedBy(mbr)) {
12314
- return false;
12315
- }
12316
- }
12317
- return true;
12318
- });
12319
- return [...clearItems, ...children];
12320
- }
12321
- getItemsEnclosedOrCrossed(left, top, right, bottom) {
12322
- return this.getRectsEnclosedOrCrossed(left, top, right, bottom);
12351
+ listNearestTo(point, maxItems, filter, maxDistance) {
12352
+ return this.itemsIndex.listNearestTo(point, maxItems, filter, maxDistance);
12323
12353
  }
12324
12354
  getComments() {
12325
12355
  return this.itemsArray.filter((item) => item.itemType === "Comment");
@@ -12337,7 +12367,7 @@ class SpatialIndex {
12337
12367
  const inRange = itemsWithDistance.filter((x) => x.distance <= maxDistance);
12338
12368
  return inRange.sort((a, b) => a.distance - b.distance).slice(0, maxItems).map((x) => x.item);
12339
12369
  }
12340
- list() {
12370
+ listAll() {
12341
12371
  return this.getItemsWithIncludedChildren(this.itemsArray).concat();
12342
12372
  }
12343
12373
  getZIndex(item) {
@@ -12375,10 +12405,19 @@ class Items {
12375
12405
  this.index.change(item);
12376
12406
  }
12377
12407
  listAll() {
12378
- return this.index.list();
12408
+ return this.index.listAll();
12409
+ }
12410
+ listUnderPoint(point, tolerance = 5) {
12411
+ return this.index.listUnderPoint(point, tolerance);
12412
+ }
12413
+ listEnclosedBy(left, top, right, bottom) {
12414
+ return this.index.listEnclosedBy(left, top, right, bottom);
12415
+ }
12416
+ listEnclosedOrCrossedBy(left, top, right, bottom) {
12417
+ return this.index.listEnclosedOrCrossedBy(left, top, right, bottom);
12379
12418
  }
12380
12419
  listGroupItems() {
12381
- return this.index.list().filter((item) => ("index" in item) && item.index);
12420
+ return this.index.listAll().filter((item) => ("index" in item) && item.index);
12382
12421
  }
12383
12422
  getById(id) {
12384
12423
  return this.index.getById(id);
@@ -12387,16 +12426,16 @@ class Items {
12387
12426
  return this.index.findById(id);
12388
12427
  }
12389
12428
  getEnclosed(left, top, right, bottom) {
12390
- return this.index.getEnclosed(left, top, right, bottom);
12429
+ return this.index.listEnclosedBy(left, top, right, bottom);
12391
12430
  }
12392
12431
  getEnclosedOrCrossed(left, top, right, bottom) {
12393
- return this.index.getEnclosedOrCrossed(left, top, right, bottom);
12432
+ return this.index.listEnclosedOrCrossedBy(left, top, right, bottom);
12394
12433
  }
12395
12434
  getGroupItemsEnclosedOrCrossed(left, top, right, bottom) {
12396
- return this.index.getEnclosedOrCrossed(left, top, right, bottom).filter((item) => item instanceof BaseItem && item.index);
12435
+ return this.index.listEnclosedOrCrossedBy(left, top, right, bottom).filter((item) => ("index" in item) && item.index);
12397
12436
  }
12398
12437
  getUnderPoint(point, tolerance = 5) {
12399
- return this.index.getUnderPoint(point, tolerance);
12438
+ return this.index.listUnderPoint(point, tolerance);
12400
12439
  }
12401
12440
  getMbr() {
12402
12441
  return this.index.getMbr();
@@ -12419,25 +12458,25 @@ class Items {
12419
12458
  }
12420
12459
  getInView() {
12421
12460
  const { left, top, right, bottom } = this.view.getMbr();
12422
- return this.index.getRectsEnclosedOrCrossed(left, top, right, bottom);
12461
+ return this.index.listEnclosedOrCrossedBy(left, top, right, bottom);
12423
12462
  }
12424
12463
  getItemsInView() {
12425
12464
  const { left, top, right, bottom } = this.view.getMbr();
12426
- return this.index.getItemsEnclosedOrCrossed(left, top, right, bottom);
12465
+ return this.index.listEnclosedOrCrossedBy(left, top, right, bottom);
12427
12466
  }
12428
12467
  getGroupItemsInView() {
12429
12468
  const { left, top, right, bottom } = this.view.getMbr();
12430
12469
  return this.getGroupItemsEnclosedOrCrossed(left, top, right, bottom);
12431
12470
  }
12432
12471
  getComments() {
12433
- return this.index.getComments();
12472
+ return this.listAll().filter((item) => item.itemType === "Comment");
12434
12473
  }
12435
12474
  getUnderPointer(size = 0) {
12436
12475
  const { x, y } = this.pointer.point;
12437
12476
  const unmodifiedSize = size;
12438
12477
  size = 16;
12439
- const tolerated = this.index.getEnclosedOrCrossed(x - size, y - size, x + size, y + size);
12440
- let enclosed = tolerated.some((item) => item.itemType === "Connector") ? tolerated : this.index.getEnclosedOrCrossed(x, y, x, y);
12478
+ const tolerated = this.index.listEnclosedOrCrossedBy(x - size, y - size, x + size, y + size);
12479
+ let enclosed = tolerated.some((item) => item.itemType === "Connector") ? tolerated : this.index.listEnclosedOrCrossedBy(x, y, x, y);
12441
12480
  const underPointer = this.getUnderPoint(new Point(x, y), size);
12442
12481
  if (enclosed.length === 0) {
12443
12482
  enclosed = underPointer;
@@ -12465,7 +12504,7 @@ class Items {
12465
12504
  return [];
12466
12505
  }
12467
12506
  getNearPointer(maxDistance = 100, maxItems = 10, filter = () => true) {
12468
- return this.index.getNearestTo(this.pointer.point, maxItems, filter, maxDistance);
12507
+ return this.index.listNearestTo(this.pointer.point, maxItems, filter, maxDistance);
12469
12508
  }
12470
12509
  getZIndex(item) {
12471
12510
  return this.index.getZIndex(item);
@@ -12607,7 +12646,6 @@ var init_SpacialIndex = __esm(() => {
12607
12646
  init_Point();
12608
12647
  init_Settings();
12609
12648
  init_LayeredIndex();
12610
- init_BaseItem();
12611
12649
  });
12612
12650
 
12613
12651
  // src/SpatialIndex/SimpleSpatialIndex.ts
@@ -12643,9 +12681,12 @@ class SimpleSpatialIndex {
12643
12681
  };
12644
12682
  remove(item, preserveChildren = false) {
12645
12683
  if (!preserveChildren && "index" in item && item.index) {
12646
- item.removeChildItems(item.index.list());
12684
+ item.removeChildItems(item.index.listAll());
12685
+ }
12686
+ const index = this.itemsArray.indexOf(item);
12687
+ if (index !== -1) {
12688
+ this.itemsArray.splice(index, 1);
12647
12689
  }
12648
- this.itemsArray.splice(this.itemsArray.indexOf(item), 1);
12649
12690
  this.Mbr = new Mbr;
12650
12691
  this.itemsArray.forEach((item2) => this.Mbr.combine([item2.getMbr()]));
12651
12692
  this.subject.publish(this.items);
@@ -12728,16 +12769,13 @@ class SimpleSpatialIndex {
12728
12769
  this.subject.publish(this.items);
12729
12770
  }
12730
12771
  getById(id) {
12731
- const item = this.itemsArray.find((item2) => item2.getId() === id);
12732
- if (item) {
12733
- return item;
12734
- }
12772
+ return this.itemsArray.find((item) => item.getId() === id);
12735
12773
  }
12736
12774
  findById(id) {
12737
12775
  return this.getById(id);
12738
12776
  }
12739
- getEnclosed(left, top, right, bottom) {
12740
- const mbr = new Mbr(left, top, right, bottom);
12777
+ listEnclosedBy(left, top, right, bottom) {
12778
+ const mbr = coerceMbr(left, top, right, bottom);
12741
12779
  const items = [];
12742
12780
  this.itemsArray.forEach((item) => {
12743
12781
  if (item.isEnclosedBy(mbr)) {
@@ -12746,8 +12784,8 @@ class SimpleSpatialIndex {
12746
12784
  });
12747
12785
  return items;
12748
12786
  }
12749
- getEnclosedOrCrossed(left, top, right, bottom) {
12750
- const mbr = new Mbr(left, top, right, bottom);
12787
+ listEnclosedOrCrossedBy(left, top, right, bottom) {
12788
+ const mbr = coerceMbr(left, top, right, bottom);
12751
12789
  const items = [];
12752
12790
  this.itemsArray.forEach((item) => {
12753
12791
  if (item.isEnclosedOrCrossedBy(mbr)) {
@@ -12756,19 +12794,30 @@ class SimpleSpatialIndex {
12756
12794
  });
12757
12795
  return items;
12758
12796
  }
12759
- getUnderPoint(point, tolerace = 5) {
12797
+ listUnderPoint(point, tolerance = 5) {
12760
12798
  const items = [];
12761
12799
  this.itemsArray.forEach((item) => {
12762
- if (item.isUnderPoint(point, tolerace)) {
12800
+ if (item.isUnderPoint(point, tolerance)) {
12763
12801
  items.push(item);
12764
12802
  }
12765
12803
  });
12766
12804
  return items;
12767
12805
  }
12806
+ listRectsEnclosedOrCrossedBy(left, top, right, bottom) {
12807
+ return this.listEnclosedOrCrossedBy(left, top, right, bottom).map((item) => item.getMbr());
12808
+ }
12809
+ listNearestTo(point, maxItems, filter, maxDistance) {
12810
+ const itemsWithDistance = this.itemsArray.filter(filter).map((item) => ({
12811
+ item,
12812
+ distance: item.getMbr().getDistanceToPoint(point)
12813
+ }));
12814
+ const inRange = itemsWithDistance.filter((x) => x.distance <= maxDistance);
12815
+ return inRange.sort((a, b) => a.distance - b.distance).slice(0, maxItems).map((x) => x.item);
12816
+ }
12768
12817
  getMbr() {
12769
12818
  return this.Mbr;
12770
12819
  }
12771
- list() {
12820
+ listAll() {
12772
12821
  return this.itemsArray.concat();
12773
12822
  }
12774
12823
  getZIndex(item) {
@@ -12840,7 +12889,7 @@ function toLocalTransformOp(op, containerMatrix, itemId) {
12840
12889
  }
12841
12890
  }
12842
12891
  var BaseItem;
12843
- var init_BaseItem2 = __esm(() => {
12892
+ var init_BaseItem = __esm(() => {
12844
12893
  init_Mbr();
12845
12894
  init_LinkTo();
12846
12895
  init_Transformation();
@@ -13284,7 +13333,7 @@ var init_Comment = __esm(() => {
13284
13333
  init_Line2();
13285
13334
  init_esm_browser();
13286
13335
  init_LinkTo();
13287
- init_BaseItem2();
13336
+ init_BaseItem();
13288
13337
  Comment = class Comment extends BaseItem {
13289
13338
  anchor;
13290
13339
  events;
@@ -25075,7 +25124,7 @@ var init_RichText = __esm(() => {
25075
25124
  init_getSelectionStyles();
25076
25125
  init_setEditorFocus();
25077
25126
  init_getAllTextNodesInSelection();
25078
- init_BaseItem2();
25127
+ init_BaseItem();
25079
25128
  RichText = class RichText extends BaseItem {
25080
25129
  container;
25081
25130
  transformation;
@@ -26041,7 +26090,7 @@ var init_AINode = __esm(() => {
26041
26090
  init_Matrix();
26042
26091
  init_Transformation();
26043
26092
  init_Settings();
26044
- init_BaseItem2();
26093
+ init_BaseItem();
26045
26094
  AINode = class AINode extends BaseItem {
26046
26095
  itemType = "AINode";
26047
26096
  parent = "Board";
@@ -26388,7 +26437,7 @@ var init_Audio = __esm(() => {
26388
26437
  init_Point();
26389
26438
  init_Line();
26390
26439
  init_Settings();
26391
- init_BaseItem2();
26440
+ init_BaseItem();
26392
26441
  AudioItem = class AudioItem extends BaseItem {
26393
26442
  events;
26394
26443
  extension;
@@ -41385,6 +41434,11 @@ var init_ShapeData = __esm(() => {
41385
41434
  ];
41386
41435
  });
41387
41436
 
41437
+ // src/Items/BaseItem/index.ts
41438
+ var init_BaseItem2 = __esm(() => {
41439
+ init_BaseItem();
41440
+ });
41441
+
41388
41442
  // src/Items/Mbr/updateRects.ts
41389
41443
  function updateRects(board, ref, mbr, verticalOffset, horizontalOffset, fit = "contextPanel") {
41390
41444
  const { selection, camera } = board;
@@ -41655,7 +41709,7 @@ var init_ControlPoint = __esm(() => {
41655
41709
  init_Transformation2();
41656
41710
  init_RichText2();
41657
41711
  init_AINode2();
41658
- init_BaseItem();
41712
+ init_BaseItem2();
41659
41713
  BoardPoint = class BoardPoint extends Point {
41660
41714
  pointType = "Board";
41661
41715
  serialize() {
@@ -42555,7 +42609,7 @@ var init_Connector = __esm(() => {
42555
42609
  init_LinkTo();
42556
42610
  init_HTMLRender();
42557
42611
  init_Settings();
42558
- init_BaseItem2();
42612
+ init_BaseItem();
42559
42613
  init_Color();
42560
42614
  init_ConnectorTypes();
42561
42615
  CONNECTOR_ANCHOR_COLOR = {
@@ -43536,7 +43590,7 @@ var init_Sticker = __esm(() => {
43536
43590
  init_SessionStorage();
43537
43591
  init_HTMLRender();
43538
43592
  init_Settings();
43539
- init_BaseItem2();
43593
+ init_BaseItem();
43540
43594
  init_Color();
43541
43595
  stickerColors = {
43542
43596
  Purple: "rgb(233, 208, 255)",
@@ -44669,7 +44723,7 @@ async function exportBoardSnapshot({
44669
44723
  context.ctx.setTransform(upscaleFactor, 0, 0, upscaleFactor, 0, 0);
44670
44724
  context.matrix.applyToContext(context.ctx);
44671
44725
  const { left, top, right, bottom } = selection;
44672
- const inView = board.items.index.getRectsEnclosedOrCrossed(left, top, right, bottom);
44726
+ const inView = board.items.index.listEnclosedOrCrossedBy(left, top, right, bottom);
44673
44727
  for (const item of inView) {
44674
44728
  item.render(context);
44675
44729
  }
@@ -44789,7 +44843,7 @@ var init_Frame = __esm(() => {
44789
44843
  init_FrameData();
44790
44844
  init_Settings();
44791
44845
  init_getResizeMatrix();
44792
- init_BaseItem();
44846
+ init_BaseItem2();
44793
44847
  init_Color();
44794
44848
  defaultFrameData = new DefaultFrameData;
44795
44849
  Frame = class Frame extends BaseItem {
@@ -44908,7 +44962,7 @@ var init_Frame = __esm(() => {
44908
44962
  return this.id;
44909
44963
  }
44910
44964
  getChildrenIds() {
44911
- return this.index?.list().map((item) => item.getId()) || [];
44965
+ return this.index?.listAll().map((item) => item.getId()) || [];
44912
44966
  }
44913
44967
  updateMbr() {
44914
44968
  const rect = this.path.getMbr().copy();
@@ -45344,7 +45398,7 @@ var init_Video = __esm(() => {
45344
45398
  init_Path2();
45345
45399
  init_Transformation2();
45346
45400
  init_Settings();
45347
- init_BaseItem2();
45401
+ init_BaseItem();
45348
45402
  init_MediaHelpers();
45349
45403
  videoIcon = conf.documentFactory.createElement("img");
45350
45404
  videoIcon.src = VIDEO_ICON_SRC;
@@ -45987,7 +46041,7 @@ var init_Drawing = __esm(() => {
45987
46041
  init_DrawingCommand();
45988
46042
  init_LinkTo();
45989
46043
  init_Settings();
45990
- init_BaseItem2();
46044
+ init_BaseItem();
45991
46045
  init_Color();
45992
46046
  Drawing = class Drawing extends BaseItem {
45993
46047
  points;
@@ -46407,7 +46461,7 @@ var init_Group = __esm(() => {
46407
46461
  init_Point();
46408
46462
  init_Transformation();
46409
46463
  init_LinkTo();
46410
- init_BaseItem2();
46464
+ init_BaseItem();
46411
46465
  Group = class Group extends BaseItem {
46412
46466
  events;
46413
46467
  linkTo;
@@ -46467,7 +46521,7 @@ var init_Group = __esm(() => {
46467
46521
  return this;
46468
46522
  }
46469
46523
  getMbr() {
46470
- const children = this.index.list();
46524
+ const children = this.index.listAll();
46471
46525
  if (children.length === 0) {
46472
46526
  return new Mbr(this.left, this.top, this.right, this.bottom);
46473
46527
  }
@@ -46507,10 +46561,10 @@ var init_Group = __esm(() => {
46507
46561
  this.getMbr();
46508
46562
  }
46509
46563
  getChildrenIds() {
46510
- return this.index.list().map((item) => item.getId());
46564
+ return this.index.listAll().map((item) => item.getId());
46511
46565
  }
46512
46566
  getChildren() {
46513
- return this.index.list();
46567
+ return this.index.listAll();
46514
46568
  }
46515
46569
  getLinkTo() {
46516
46570
  return this.linkTo.link;
@@ -46558,7 +46612,7 @@ var init_Group = __esm(() => {
46558
46612
  const ctx = context.ctx;
46559
46613
  ctx.save();
46560
46614
  this.transformation.applyToContext(ctx);
46561
- for (const child of this.index.list()) {
46615
+ for (const child of this.index.listAll()) {
46562
46616
  child.render(context);
46563
46617
  }
46564
46618
  ctx.restore();
@@ -46666,7 +46720,7 @@ function createDrawing(id, data, board) {
46666
46720
  if (!isDrawingData(data)) {
46667
46721
  throw new Error("Invalid data for Drawing");
46668
46722
  }
46669
- const drawing = new Drawing(board, [], board.events).setId(id).deserialize({ ...data, id });
46723
+ const drawing = new Drawing(board, [], board.events).setId(id).setId(id).deserialize({ ...data, id });
46670
46724
  return drawing;
46671
46725
  }
46672
46726
  function createFrame(id, data, board) {
@@ -46687,7 +46741,7 @@ function createGroup(id, data, board) {
46687
46741
  if (!isGroupData(data)) {
46688
46742
  throw new Error("Invalid data for Group");
46689
46743
  }
46690
- const group = new Group(board, board.events, data.children, id).setId(id).deserialize({ ...data, id });
46744
+ const group = new Group(board, board.events, data.childIds, id).setId(id).deserialize({ ...data, id });
46691
46745
  return group;
46692
46746
  }
46693
46747
  function isStickerData(data) {
@@ -49225,7 +49279,7 @@ function getQuickAddButtons(selection, board) {
49225
49279
  }
49226
49280
  const newMbr = new Mbr(newItemData.transformation?.translateX, newItemData.transformation?.translateY, (newItemData.transformation?.translateX || 0) + newWidth, (newItemData.transformation?.translateY || 0) + newHeight);
49227
49281
  let step = 1;
49228
- while (board.index.getItemsEnclosedOrCrossed(newMbr.left, newMbr.top, newMbr.right, newMbr.bottom).filter((item) => item.itemType !== "Connector").length > 0) {
49282
+ while (board.index.listEnclosedOrCrossedBy(newMbr.left, newMbr.top, newMbr.right, newMbr.bottom).filter((item) => item.itemType !== "Connector").length > 0) {
49229
49283
  const xDirection = step % 2 === 0 ? -1 : 1;
49230
49284
  const yDirection = newItemData.itemType === "AINode" ? -1 : xDirection;
49231
49285
  newMbr.transform(new Matrix(iterAdjustment[index2].x * xDirection * step, iterAdjustment[index2].y * yDirection * (newItemData.itemType === "AINode" ? 1 : step)));
@@ -49467,7 +49521,7 @@ function getQuickAddButtons(selection, board) {
49467
49521
  var offsets;
49468
49522
  var init_QuickAddButtons2 = __esm(() => {
49469
49523
  init_Items();
49470
- init_BaseItem2();
49524
+ init_BaseItem();
49471
49525
  init_SessionStorage();
49472
49526
  init_QuickAddButtons();
49473
49527
  init_quickAddHelpers();
@@ -49900,7 +49954,7 @@ class AlignmentHelper {
49900
49954
  var RELATIVE_ALIGNMENT_COLOR = "#4778F5";
49901
49955
  var init_RelativeAlignment = __esm(() => {
49902
49956
  init_Items();
49903
- init_BaseItem();
49957
+ init_BaseItem2();
49904
49958
  });
49905
49959
 
49906
49960
  // src/Tools/RelativeAlignment/index.ts
@@ -51501,7 +51555,7 @@ var init_AddStar = __esm(() => {
51501
51555
  // src/Items/Examples/Star/Star.ts
51502
51556
  var defaultStarData, starPath, Star2;
51503
51557
  var init_Star2 = __esm(() => {
51504
- init_BaseItem2();
51558
+ init_BaseItem();
51505
51559
  init_Point();
51506
51560
  init_Path();
51507
51561
  init_Line();
@@ -51683,7 +51737,7 @@ var init_AddCounter = __esm(() => {
51683
51737
  // src/Items/Examples/Counter/Counter.ts
51684
51738
  var defaultCounterData, COUNTER_DIMENSIONS, Counter;
51685
51739
  var init_Counter = __esm(() => {
51686
- init_BaseItem2();
51740
+ init_BaseItem();
51687
51741
  init_Point();
51688
51742
  init_Path();
51689
51743
  init_Line();
@@ -51802,7 +51856,7 @@ var init_HotkeyRegistry = __esm(() => {
51802
51856
  // src/Items/Examples/CardGame/Card/Card.ts
51803
51857
  var defaultCardData, Card;
51804
51858
  var init_Card = __esm(() => {
51805
- init_BaseItem2();
51859
+ init_BaseItem();
51806
51860
  init_Path();
51807
51861
  init_RegisterItem();
51808
51862
  init_Settings();
@@ -52052,7 +52106,7 @@ function createDeck(event, board) {
52052
52106
  if (single && single.itemType === "Deck") {
52053
52107
  return;
52054
52108
  }
52055
- const cardsOrDecks = board.selection.items.list();
52109
+ const cardsOrDecks = board.selection.items.listAll();
52056
52110
  const onlyCards = board.selection.items.isAllItemsType("Card");
52057
52111
  if (onlyCards) {
52058
52112
  const deck = new Deck(board, "");
@@ -52068,12 +52122,12 @@ function createDeck(event, board) {
52068
52122
  if (item.itemType === "Card") {
52069
52123
  cards.push(item);
52070
52124
  } else if (item.itemType === "Deck") {
52125
+ const deck = item;
52071
52126
  if (mainDeck) {
52072
- cards.push(...mainDeck.getDeck());
52073
- board.remove(mainDeck);
52074
- mainDeck = item;
52127
+ cards.push(...deck.getDeck());
52128
+ board.remove(deck);
52075
52129
  } else {
52076
- mainDeck = item;
52130
+ mainDeck = deck;
52077
52131
  }
52078
52132
  }
52079
52133
  });
@@ -52086,9 +52140,10 @@ function createDeck(event, board) {
52086
52140
  }
52087
52141
  var defaultDeckData, Deck;
52088
52142
  var init_Deck = __esm(() => {
52089
- init_BaseItem2();
52143
+ init_BaseItem();
52090
52144
  init_RegisterItem();
52091
52145
  init_Card();
52146
+ init_DrawingContext();
52092
52147
  init_Settings();
52093
52148
  init_Path2();
52094
52149
  init_HotkeyRegistry();
@@ -52107,9 +52162,9 @@ var init_Deck = __esm(() => {
52107
52162
  drawingContext = null;
52108
52163
  constructor(board, id = "") {
52109
52164
  super(board, id, defaultDeckData, true);
52110
- this.index.getUnderPoint = () => [];
52111
- this.index.getEnclosed = () => [];
52112
- this.index.getEnclosedOrCrossed = () => [];
52165
+ this.index.listUnderPoint = () => [];
52166
+ this.index.listEnclosedBy = () => [];
52167
+ this.index.listEnclosedOrCrossedBy = () => [];
52113
52168
  this.transformation.subject.subscribe(() => {
52114
52169
  this.updateMbr();
52115
52170
  this.subject.publish(this);
@@ -52131,7 +52186,7 @@ var init_Deck = __esm(() => {
52131
52186
  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);
52132
52187
  if (canAddItem) {
52133
52188
  this.isPerpendicular = foundItem.getIsRotatedPerpendicular();
52134
- 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));
52189
+ 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));
52135
52190
  if (firstCard) {
52136
52191
  const { scaleX, scaleY } = foundItem.transformation.getMatrixData();
52137
52192
  const { scaleX: targetScaleX, scaleY: targetScaleY } = firstCard.transformation.getMatrixData();
@@ -52171,31 +52226,33 @@ var init_Deck = __esm(() => {
52171
52226
  this.subject.publish(this);
52172
52227
  }
52173
52228
  getDeck() {
52174
- return this.index?.list() || [];
52229
+ return this.index?.listAll() || [];
52175
52230
  }
52176
52231
  getTopCard() {
52177
- const card = this.index?.list()[this.index?.list().length - 1];
52232
+ const cards = this.index?.listAll() || [];
52233
+ const card = cards[cards.length - 1];
52178
52234
  if (card) {
52179
52235
  this.removeChildItems(card);
52180
52236
  return card;
52181
52237
  }
52182
52238
  }
52183
52239
  getCards(count) {
52184
- const cards = this.index?.list().reverse().slice(0, count);
52185
- if (cards) {
52240
+ const cards = (this.index?.listAll() || []).reverse().slice(0, count);
52241
+ if (cards.length > 0) {
52186
52242
  this.removeChildItems(cards);
52187
52243
  return cards;
52188
52244
  }
52189
52245
  }
52190
52246
  getBottomCard() {
52191
- const card = this.index?.list()[0];
52247
+ const card = this.index?.listAll()[0];
52192
52248
  if (card) {
52193
52249
  this.removeChildItems(card);
52194
52250
  return card;
52195
52251
  }
52196
52252
  }
52197
52253
  getRandomCard() {
52198
- const card = this.index?.list()[Math.floor(Math.random() * this.index?.list().length)];
52254
+ const cards = this.index?.listAll() || [];
52255
+ const card = cards[Math.floor(Math.random() * cards.length)];
52199
52256
  if (card) {
52200
52257
  this.removeChildItems(card);
52201
52258
  return card;
@@ -52205,20 +52262,20 @@ var init_Deck = __esm(() => {
52205
52262
  if (!this.index) {
52206
52263
  return;
52207
52264
  }
52208
- const shuffled = [...this.index.list()];
52265
+ const shuffled = [...this.index.listAll()];
52209
52266
  for (let i = shuffled.length - 1;i > 0; i--) {
52210
52267
  const j = Math.floor(Math.random() * (i + 1));
52211
52268
  [shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
52212
52269
  }
52213
52270
  this.emitAnimation();
52214
- this.removeChildItems(this.index.list());
52271
+ this.removeChildItems(this.index.listAll());
52215
52272
  this.addChildItems(shuffled);
52216
52273
  }
52217
52274
  flipDeck() {
52218
- if (!this.index || !this.index.list().length) {
52275
+ if (!this.index || !this.index.listAll().length) {
52219
52276
  return;
52220
52277
  }
52221
- const cards = this.index.list();
52278
+ const cards = this.index.listAll();
52222
52279
  cards[0].toggleIsOpen(cards);
52223
52280
  const reversed = [...cards].reverse();
52224
52281
  this.removeChildItems(cards);
@@ -52239,7 +52296,7 @@ var init_Deck = __esm(() => {
52239
52296
  }
52240
52297
  updateMbr() {
52241
52298
  const { translateX, translateY } = this.transformation.getMatrixData();
52242
- const items = this.index.list();
52299
+ const items = this.index.listAll();
52243
52300
  const itemsMbr = items[0]?.getMbr().combine(items.slice(1).map((item) => item.getMbr()));
52244
52301
  this.left = translateX;
52245
52302
  this.top = translateY;
@@ -52307,7 +52364,7 @@ var init_Deck = __esm(() => {
52307
52364
  }
52308
52365
  renderHTML(documentFactory) {
52309
52366
  const div = super.renderHTML(documentFactory);
52310
- const cards = this.index?.list();
52367
+ const cards = this.index?.listAll();
52311
52368
  const topCard = cards[cards.length - 1];
52312
52369
  if (!topCard) {
52313
52370
  return div;
@@ -52316,7 +52373,7 @@ var init_Deck = __esm(() => {
52316
52373
  const transform = `translate(${translateX}px, ${translateY}px) scale(1, 1)`;
52317
52374
  const topCardElement = topCard.renderHTML(documentFactory);
52318
52375
  div.appendChild(topCardElement);
52319
- const offset = ((this.index?.list().length || 0) - 1) * 2;
52376
+ const offset = ((this.index?.listAll().length || 0) - 1) * 2;
52320
52377
  topCardElement.style.transform = `translate(${offset}px, ${0}px) scale(1, 1)`;
52321
52378
  div.id = this.getId();
52322
52379
  div.style.width = `${this.getWidth()}px`;
@@ -52329,7 +52386,7 @@ var init_Deck = __esm(() => {
52329
52386
  return div;
52330
52387
  }
52331
52388
  updateCache(context) {
52332
- const cards = this.index?.list();
52389
+ const cards = this.index?.listAll();
52333
52390
  const topCard = cards[cards.length - 1];
52334
52391
  const topCardImage = topCard?.getImage();
52335
52392
  const width2 = this.getWidth();
@@ -52343,7 +52400,7 @@ var init_Deck = __esm(() => {
52343
52400
  const tempCtx = tempCanvas.getContext("2d");
52344
52401
  if (!tempCtx)
52345
52402
  return;
52346
- const tempContext = { ...context, ctx: tempCtx };
52403
+ const tempContext = new DrawingContext(context.camera, tempCtx, context.cursorCtx, context.matrix);
52347
52404
  cards.forEach((_, index2) => {
52348
52405
  topCard.render(tempContext, this.isPerpendicular ? 0 : index2 * conf.DECK_HORIZONTAL_OFFSET, this.isPerpendicular ? index2 * conf.DECK_VERTICAL_OFFSET : 0);
52349
52406
  });
@@ -52352,7 +52409,7 @@ var init_Deck = __esm(() => {
52352
52409
  this.updateMbr();
52353
52410
  }
52354
52411
  getFirstCard() {
52355
- return this.index?.list()[0];
52412
+ return this.index?.listAll()[0];
52356
52413
  }
52357
52414
  };
52358
52415
  registerItem({
@@ -52486,7 +52543,7 @@ var init_AddDice = __esm(() => {
52486
52543
  // src/Items/Examples/CardGame/Dice/Dice.ts
52487
52544
  var TIMEOUT = 2000, defaultDiceData, Dice;
52488
52545
  var init_Dice = __esm(() => {
52489
- init_BaseItem2();
52546
+ init_BaseItem();
52490
52547
  init_Items();
52491
52548
  init_RoundedRectangle();
52492
52549
  init_Items();
@@ -52887,7 +52944,7 @@ var init_AddScreen = __esm(() => {
52887
52944
  // src/Items/Examples/CardGame/Screen/Screen.ts
52888
52945
  var screenPath, defaultScreenData, Screen;
52889
52946
  var init_Screen = __esm(() => {
52890
- init_BaseItem2();
52947
+ init_BaseItem();
52891
52948
  init_RegisterItem();
52892
52949
  init_Path2();
52893
52950
  init_Line2();
@@ -53034,9 +53091,9 @@ var init_Screen = __esm(() => {
53034
53091
  applyOwnerId(ownerId) {
53035
53092
  this.ownerId = ownerId;
53036
53093
  if (!this.ownerId) {
53037
- this.index.getUnderPoint = () => [];
53038
- this.index.getEnclosed = () => [];
53039
- this.index.getEnclosedOrCrossed = () => [];
53094
+ this.index.listUnderPoint = () => [];
53095
+ this.index.listEnclosedBy = () => [];
53096
+ this.index.listEnclosedOrCrossedBy = () => [];
53040
53097
  }
53041
53098
  }
53042
53099
  transformPath() {
@@ -53059,16 +53116,17 @@ var init_Screen = __esm(() => {
53059
53116
  this.applyBackgroundUrl(this.backgroundUrl);
53060
53117
  }
53061
53118
  if (!this.ownerId) {
53062
- this.index.getUnderPoint = () => [];
53063
- this.index.getEnclosed = () => [];
53064
- this.index.getEnclosedOrCrossed = () => [];
53119
+ this.index.listUnderPoint = () => [];
53120
+ this.index.listEnclosedBy = () => [];
53121
+ this.index.listEnclosedOrCrossedBy = () => [];
53065
53122
  }
53066
53123
  this.transformPath();
53067
53124
  this.subject.publish(this);
53068
53125
  return this;
53069
53126
  }
53070
53127
  getRandomItem() {
53071
- const item = this.index?.list()[Math.floor(Math.random() * this.index?.list().length)];
53128
+ const items = this.index?.listAll() || [];
53129
+ const item = items[Math.floor(Math.random() * items.length)];
53072
53130
  if (item) {
53073
53131
  this.removeChildItems(item);
53074
53132
  return item;
@@ -53117,7 +53175,7 @@ var init_Screen2 = __esm(() => {
53117
53175
 
53118
53176
  // src/Items/index.ts
53119
53177
  var init_Items = __esm(() => {
53120
- init_BaseItem();
53178
+ init_BaseItem2();
53121
53179
  init_Point2();
53122
53180
  init_Line2();
53123
53181
  init_Curve2();
@@ -53992,7 +54050,7 @@ var init_Shape = __esm(() => {
53992
54050
  init_Connector2();
53993
54051
  init_ControlPoint();
53994
54052
  init_Settings();
53995
- init_BaseItem2();
54053
+ init_BaseItem();
53996
54054
  init_Color();
53997
54055
  defaultShapeData = new DefaultShapeData;
53998
54056
  Shapes = { ...BasicShapes, ...BPMN };
@@ -54518,7 +54576,7 @@ var init_Placeholder2 = __esm(() => {
54518
54576
  init_Transformation();
54519
54577
  init_PlaceholderCommand();
54520
54578
  init_getResizeMatrix();
54521
- init_BaseItem2();
54579
+ init_BaseItem();
54522
54580
  Placeholder2 = class Placeholder2 extends BaseItem {
54523
54581
  events;
54524
54582
  miroData;
@@ -54827,7 +54885,7 @@ var init_Image = __esm(() => {
54827
54885
  init_Placeholder2();
54828
54886
  init_LinkTo();
54829
54887
  init_Settings();
54830
- init_BaseItem2();
54888
+ init_BaseItem();
54831
54889
  init_MediaHelpers();
54832
54890
  ImageItem = class ImageItem extends BaseItem {
54833
54891
  events;
@@ -55390,10 +55448,20 @@ function handleBoardEventMessage(message, board) {
55390
55448
  if (isEventFromCurrentUser) {
55391
55449
  return;
55392
55450
  }
55393
- log.insertEventsFromOtherConnections({
55394
- ...event,
55395
- userId: Number(message.userId)
55396
- });
55451
+ if ("operations" in event.body) {
55452
+ log.insertEventsFromOtherConnections({
55453
+ ...event,
55454
+ body: {
55455
+ ...event.body,
55456
+ userId: Number(message.userId)
55457
+ }
55458
+ });
55459
+ } else {
55460
+ log.insertEventsFromOtherConnections({
55461
+ ...event,
55462
+ userId: Number(message.userId)
55463
+ });
55464
+ }
55397
55465
  const last = log.getLastConfirmed();
55398
55466
  if (last) {
55399
55467
  board.events.subject.publish(last);
@@ -55411,7 +55479,7 @@ function handleBoardSubscriptionCompletedMsg(msg, board) {
55411
55479
  handleHTMLSnapshotApplication(msg.JSONSnapshot, board);
55412
55480
  log.list.clearConfirmedRecords();
55413
55481
  }
55414
- handleBoardEventListApplication(msg.eventsSinceLastSnapshot, board);
55482
+ handleBoardEventListApplication(expandEvents(msg.eventsSinceLastSnapshot), board);
55415
55483
  board.setInterfaceType(msg.mode);
55416
55484
  board.subject.publish();
55417
55485
  onBoardLoad(board);
@@ -57763,7 +57831,7 @@ init_Settings();
57763
57831
  init_QuickAddButtons3();
57764
57832
 
57765
57833
  // src/Selection/SelectionItems.ts
57766
- init_BaseItem();
57834
+ init_BaseItem2();
57767
57835
 
57768
57836
  class SelectionItems {
57769
57837
  items = new Map;
@@ -57790,6 +57858,9 @@ class SelectionItems {
57790
57858
  list() {
57791
57859
  return Array.from(this.items.values());
57792
57860
  }
57861
+ listAll() {
57862
+ return this.list();
57863
+ }
57793
57864
  isEmpty() {
57794
57865
  return this.items.size === 0;
57795
57866
  }
@@ -58085,7 +58156,7 @@ init_RichText();
58085
58156
  init_AINode();
58086
58157
  init_Sticker();
58087
58158
  init_Frame();
58088
- init_BaseItem();
58159
+ init_BaseItem2();
58089
58160
  function handleMultipleItemsResize({
58090
58161
  board,
58091
58162
  resize,
@@ -58468,7 +58539,7 @@ init_Image();
58468
58539
  init_SessionStorage();
58469
58540
  init_Point();
58470
58541
  init_Items();
58471
- init_BaseItem();
58542
+ init_BaseItem2();
58472
58543
  function transformItems({
58473
58544
  board,
58474
58545
  selection,
@@ -61253,8 +61324,9 @@ class Board {
61253
61324
  const data = Array.from(items.children).map((el) => this.parseHTML(el));
61254
61325
  for (const parsedData of data) {
61255
61326
  if ("childrenMap" in parsedData) {
61256
- const addedFrame = this.add(this.createItem(this.getNewItemId(), parsedData.data));
61257
- const addedChildren = Object.values(parsedData.childrenMap).map((childData) => {
61327
+ const frameData = parsedData;
61328
+ const addedFrame = this.add(this.createItem(this.getNewItemId(), frameData.data));
61329
+ const addedChildren = Object.values(frameData.childrenMap).map((childData) => {
61258
61330
  const created = this.createItem(this.getNewItemId(), childData);
61259
61331
  const added = this.add(created);
61260
61332
  idsMap[childData.id] = added.getId();
@@ -61267,17 +61339,18 @@ class Board {
61267
61339
  return added;
61268
61340
  });
61269
61341
  addedFrame.addChildItems(addedChildren);
61270
- parsedData.data.children = addedChildren.map((item) => item.getId());
61271
- idsMap[parsedData.data.id] = addedFrame.getId();
61342
+ frameData.data.children = addedChildren.map((item) => item.getId());
61343
+ idsMap[frameData.data.id] = addedFrame.getId();
61272
61344
  } else {
61273
- const added = this.add(this.createItem(this.getNewItemId(), parsedData));
61345
+ const itemData = parsedData;
61346
+ const added = this.add(this.createItem(this.getNewItemId(), itemData));
61274
61347
  if (added.itemType === "Connector") {
61275
61348
  addedConnectors.push({
61276
61349
  item: added,
61277
- data: parsedData
61350
+ data: itemData
61278
61351
  });
61279
61352
  }
61280
- idsMap[parsedData.id] = added.getId();
61353
+ idsMap[itemData.id] = added.getId();
61281
61354
  }
61282
61355
  }
61283
61356
  addedConnectors.forEach((connector) => {
@@ -61321,12 +61394,13 @@ class Board {
61321
61394
  this.index.insert(item);
61322
61395
  return item;
61323
61396
  };
61324
- for (const itemData of items) {
61325
- if ("childrenMap" in itemData) {
61326
- Object.values(itemData.childrenMap).map((childData) => addItem(childData));
61327
- addItem(itemData.data);
61397
+ for (const rawItemData of items) {
61398
+ if ("childrenMap" in rawItemData) {
61399
+ const frameData = rawItemData;
61400
+ Object.values(frameData.childrenMap).map((childData) => addItem(childData));
61401
+ addItem(frameData.data);
61328
61402
  } else {
61329
- addItem(itemData);
61403
+ addItem(rawItemData);
61330
61404
  }
61331
61405
  }
61332
61406
  for (const key in createdConnectors) {
@@ -61759,8 +61833,9 @@ class Board {
61759
61833
  itemData.transformation.translateX = translateX + width2 * 10 + 10;
61760
61834
  }
61761
61835
  }
61762
- if ("children" in itemData && itemData.children?.length) {
61763
- itemData.children = itemData.children.map((childId) => newItemIdMap[childId]);
61836
+ const itemDataWithChildren = itemData;
61837
+ if ("children" in itemDataWithChildren && itemDataWithChildren.children?.length) {
61838
+ itemDataWithChildren.children = itemDataWithChildren.children.map((childId) => newItemIdMap[childId]);
61764
61839
  }
61765
61840
  newMap[newItemId] = itemData;
61766
61841
  }
@@ -61943,7 +62018,7 @@ function initI18N(i18nInstance) {
61943
62018
  // src/index.ts
61944
62019
  init_MediaHelpers();
61945
62020
  init_CreateCommand();
61946
- init_BaseItem2();
62021
+ init_BaseItem();
61947
62022
  init_Events();
61948
62023
  BaseItem.createCommand = createCommand;
61949
62024
  Events.createCommand = createCommand;