canvu-react 0.3.34 → 0.3.35

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.
package/dist/index.cjs CHANGED
@@ -2606,20 +2606,25 @@ function markImageAsManaged(item) {
2606
2606
  };
2607
2607
  }
2608
2608
  function restackManagedImages(items) {
2609
- let anchor;
2609
+ let anchorAabbY = Infinity;
2610
+ let anchorCenterX = 0;
2610
2611
  for (const item of items) {
2611
2612
  if (!isManagedImage(item)) continue;
2612
- if (!anchor || item.bounds.y < anchor.bounds.y) anchor = item;
2613
+ const aabb = boundsAabbForRotatedItem(item);
2614
+ if (aabb.y < anchorAabbY) {
2615
+ anchorAabbY = aabb.y;
2616
+ anchorCenterX = aabb.x + aabb.width / 2;
2617
+ }
2613
2618
  }
2614
- if (!anchor) return [...items];
2615
- const anchorCenterX = anchor.bounds.x + anchor.bounds.width / 2;
2616
- const anchorTopY = anchor.bounds.y;
2617
- let cursorY = anchorTopY;
2619
+ if (!Number.isFinite(anchorAabbY)) return [...items];
2620
+ let cursorY = anchorAabbY;
2618
2621
  return items.map((item) => {
2619
2622
  if (!isManagedImage(item)) return item;
2623
+ const aabb = boundsAabbForRotatedItem(item);
2624
+ const centerY = cursorY + aabb.height / 2;
2620
2625
  const newX = anchorCenterX - item.bounds.width / 2;
2621
- const newY = cursorY;
2622
- cursorY = newY + item.bounds.height + STACK_GAP_WORLD;
2626
+ const newY = centerY - item.bounds.height / 2;
2627
+ cursorY += aabb.height + STACK_GAP_WORLD;
2623
2628
  if (item.bounds.x === newX && item.bounds.y === newY) return item;
2624
2629
  return {
2625
2630
  ...item,
@@ -2642,8 +2647,10 @@ function copyManagedImage(items, id) {
2642
2647
  return restackManagedImages(inserted);
2643
2648
  }
2644
2649
  function rotateManagedImage(items, id) {
2645
- return items.map(
2646
- (i) => i.id === id ? { ...i, rotation: ((i.rotation ?? 0) + Math.PI / 2) % (Math.PI * 2) } : i
2650
+ return restackManagedImages(
2651
+ items.map(
2652
+ (i) => i.id === id ? { ...i, rotation: ((i.rotation ?? 0) + Math.PI / 2) % (Math.PI * 2) } : i
2653
+ )
2647
2654
  );
2648
2655
  }
2649
2656
  function deleteManagedImage(items, id) {