canvu-react 0.3.33 → 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/react.js CHANGED
@@ -284,153 +284,197 @@ function svgNumber(value) {
284
284
  const rounded = Math.round(value * 100) / 100;
285
285
  return Number.isInteger(rounded) ? String(rounded) : String(rounded);
286
286
  }
287
- function architecturalCloudScallopCount(perimeter, amplitude) {
288
- const targetScallopLength = Math.max(18, amplitude * 2.45);
289
- let count = Math.max(12, Math.round(perimeter / targetScallopLength));
290
- if (count % 2 === 1) count += 1;
291
- return count;
292
- }
293
- function roundedRectMetrics(width, height, inset, radius) {
294
- const left = inset;
295
- const top = inset;
296
- const right = width - inset;
297
- const bottom = height - inset;
298
- const rectWidth = Math.max(0, right - left);
299
- const rectHeight = Math.max(0, bottom - top);
300
- const normalizedRadius = Math.max(
301
- 0,
302
- Math.min(radius, rectWidth / 2, rectHeight / 2)
287
+ function architecturalCloudCenterCount(edgeLength, radius) {
288
+ const targetSpacing = Math.min(
289
+ ARCHITECTURAL_CLOUD_TARGET_SPACING,
290
+ Math.max(1, radius * 1.3)
303
291
  );
304
- const centerX = width / 2;
305
- const topHalfLength = Math.max(0, right - normalizedRadius - centerX);
306
- const horizontalLength = Math.max(0, rectWidth - normalizedRadius * 2);
307
- const verticalLength = Math.max(0, rectHeight - normalizedRadius * 2);
308
- const arcLength = normalizedRadius * (Math.PI / 2);
292
+ return Math.max(2, Math.round(edgeLength / targetSpacing) + 1);
293
+ }
294
+ function distributeRange(start, end, count) {
295
+ if (count <= 1) return [start];
296
+ const step = (end - start) / (count - 1);
297
+ return Array.from({ length: count }, (_, index) => start + step * index);
298
+ }
299
+ function lineCloudPathSegment(start, end) {
300
+ const dx = end[0] - start[0];
301
+ const dy = end[1] - start[1];
302
+ const length = Math.hypot(dx, dy);
309
303
  return {
310
- left,
311
- top,
312
- right,
313
- bottom,
314
- radius: normalizedRadius,
315
- centerX,
316
- topHalfLength,
317
- horizontalLength,
318
- verticalLength,
319
- arcLength,
320
- perimeter: horizontalLength * 2 + verticalLength * 2 + Math.PI * 2 * normalizedRadius
304
+ length,
305
+ pointAt: (t) => [start[0] + dx * t, start[1] + dy * t]
321
306
  };
322
307
  }
323
- function pointOnLine(startX, startY, endX, endY, t) {
324
- return [startX + (endX - startX) * t, startY + (endY - startY) * t];
308
+ function ellipsePoint(centerX, centerY, radiusX, radiusY, angle) {
309
+ return [centerX + Math.cos(angle) * radiusX, centerY + Math.sin(angle) * radiusY];
325
310
  }
326
- function pointOnArc(centerX, centerY, radius, startAngle, endAngle, t) {
327
- const theta = startAngle + (endAngle - startAngle) * t;
328
- return [centerX + Math.cos(theta) * radius, centerY + Math.sin(theta) * radius];
311
+ function approximateEllipseArcLength(radiusX, radiusY, startAngle, endAngle) {
312
+ const steps = Math.max(
313
+ 4,
314
+ Math.ceil(Math.abs(endAngle - startAngle) / (Math.PI / 16))
315
+ );
316
+ let length = 0;
317
+ let previous = ellipsePoint(0, 0, radiusX, radiusY, startAngle);
318
+ for (let index = 1; index <= steps; index += 1) {
319
+ const angle = startAngle + (endAngle - startAngle) * index / steps;
320
+ const next = ellipsePoint(0, 0, radiusX, radiusY, angle);
321
+ length += Math.hypot(next[0] - previous[0], next[1] - previous[1]);
322
+ previous = next;
323
+ }
324
+ return length;
329
325
  }
330
- function pointOnRoundedRectPath(metrics, distance) {
331
- if (metrics.perimeter <= 0) return [metrics.centerX, metrics.top];
332
- let remaining = (distance % metrics.perimeter + metrics.perimeter) % metrics.perimeter;
333
- const consume = (length) => {
334
- if (length <= 1e-9) return null;
335
- if (remaining <= length) return remaining / length;
336
- remaining -= length;
337
- return null;
326
+ function ellipseCloudPathSegment(centerX, centerY, radiusX, radiusY, startAngle, endAngle) {
327
+ return {
328
+ length: approximateEllipseArcLength(radiusX, radiusY, startAngle, endAngle),
329
+ pointAt: (t) => ellipsePoint(
330
+ centerX,
331
+ centerY,
332
+ radiusX,
333
+ radiusY,
334
+ startAngle + (endAngle - startAngle) * t
335
+ )
338
336
  };
339
- let t = consume(metrics.topHalfLength);
340
- if (t != null) {
341
- return pointOnLine(
342
- metrics.centerX,
343
- metrics.top,
344
- metrics.right - metrics.radius,
345
- metrics.top,
346
- t
347
- );
337
+ }
338
+ function cloudPathPerimeter(segments) {
339
+ const usableSegments = segments.filter((segment) => segment.length > 1e-9);
340
+ return usableSegments.reduce((sum, segment) => sum + segment.length, 0);
341
+ }
342
+ function pointOnCloudPath(segments, distance) {
343
+ const perimeter = cloudPathPerimeter(segments);
344
+ if (perimeter <= 0) return [0, 0];
345
+ let remaining = (distance % perimeter + perimeter) % perimeter;
346
+ for (const segment of segments) {
347
+ if (segment.length <= 1e-9) continue;
348
+ if (remaining <= segment.length) {
349
+ const t = remaining / segment.length;
350
+ return segment.pointAt(t);
351
+ }
352
+ remaining -= segment.length;
348
353
  }
349
- t = consume(metrics.arcLength);
350
- if (t != null) {
351
- return pointOnArc(
352
- metrics.right - metrics.radius,
353
- metrics.top + metrics.radius,
354
- metrics.radius,
354
+ const fallback = segments.find((segment) => segment.length > 1e-9);
355
+ return fallback?.pointAt(0) ?? [0, 0];
356
+ }
357
+ function buildRoundedCapsulePathSegments(width, height, inset) {
358
+ const left = inset;
359
+ const top = inset;
360
+ const right = width - inset;
361
+ const bottom = height - inset;
362
+ const capsuleWidth = Math.max(0, right - left);
363
+ const capsuleHeight = Math.max(0, bottom - top);
364
+ const radius = Math.min(capsuleWidth, capsuleHeight) / 2;
365
+ if (radius <= 0) return [];
366
+ const leftCenterX = left + radius;
367
+ const rightCenterX = right - radius;
368
+ const topCenterY = top + radius;
369
+ const bottomCenterY = bottom - radius;
370
+ return [
371
+ lineCloudPathSegment([leftCenterX, top], [rightCenterX, top]),
372
+ ellipseCloudPathSegment(
373
+ rightCenterX,
374
+ topCenterY,
375
+ radius,
376
+ radius,
355
377
  -Math.PI / 2,
378
+ 0
379
+ ),
380
+ lineCloudPathSegment([right, topCenterY], [right, bottomCenterY]),
381
+ ellipseCloudPathSegment(
382
+ rightCenterX,
383
+ bottomCenterY,
384
+ radius,
385
+ radius,
356
386
  0,
357
- t
358
- );
359
- }
360
- t = consume(metrics.verticalLength);
361
- if (t != null) {
362
- return pointOnLine(
363
- metrics.right,
364
- metrics.top + metrics.radius,
365
- metrics.right,
366
- metrics.bottom - metrics.radius,
367
- t
368
- );
369
- }
370
- t = consume(metrics.arcLength);
371
- if (t != null) {
372
- return pointOnArc(
373
- metrics.right - metrics.radius,
374
- metrics.bottom - metrics.radius,
375
- metrics.radius,
376
- 0,
377
- Math.PI / 2,
378
- t
379
- );
380
- }
381
- t = consume(metrics.horizontalLength);
382
- if (t != null) {
383
- return pointOnLine(
384
- metrics.right - metrics.radius,
385
- metrics.bottom,
386
- metrics.left + metrics.radius,
387
- metrics.bottom,
388
- t
389
- );
390
- }
391
- t = consume(metrics.arcLength);
392
- if (t != null) {
393
- return pointOnArc(
394
- metrics.left + metrics.radius,
395
- metrics.bottom - metrics.radius,
396
- metrics.radius,
387
+ Math.PI / 2
388
+ ),
389
+ lineCloudPathSegment([rightCenterX, bottom], [leftCenterX, bottom]),
390
+ ellipseCloudPathSegment(
391
+ leftCenterX,
392
+ bottomCenterY,
393
+ radius,
394
+ radius,
397
395
  Math.PI / 2,
396
+ Math.PI
397
+ ),
398
+ lineCloudPathSegment([left, bottomCenterY], [left, topCenterY]),
399
+ ellipseCloudPathSegment(
400
+ leftCenterX,
401
+ topCenterY,
402
+ radius,
403
+ radius,
398
404
  Math.PI,
399
- t
400
- );
401
- }
402
- t = consume(metrics.verticalLength);
403
- if (t != null) {
404
- return pointOnLine(
405
- metrics.left,
406
- metrics.bottom - metrics.radius,
407
- metrics.left,
408
- metrics.top + metrics.radius,
409
- t
410
- );
411
- }
412
- t = consume(metrics.arcLength);
413
- if (t != null) {
414
- return pointOnArc(
415
- metrics.left + metrics.radius,
416
- metrics.top + metrics.radius,
417
- metrics.radius,
418
- Math.PI,
419
- Math.PI * 1.5,
420
- t
421
- );
422
- }
423
- t = consume(metrics.topHalfLength);
424
- if (t != null) {
425
- return pointOnLine(
426
- metrics.left + metrics.radius,
427
- metrics.top,
428
- metrics.centerX,
429
- metrics.top,
430
- t
405
+ Math.PI * 1.5
406
+ )
407
+ ];
408
+ }
409
+ function buildRoundedArcCloudPathD(cloudWidth, cloudHeight, center) {
410
+ const minDimension = Math.min(cloudWidth, cloudHeight);
411
+ const radius = Math.min(
412
+ ARCHITECTURAL_CLOUD_ROUNDED_RADIUS,
413
+ Math.max(ARCHITECTURAL_CLOUD_ROUNDED_MIN_RADIUS, minDimension * 0.16)
414
+ );
415
+ const centerPath = buildRoundedCapsulePathSegments(
416
+ cloudWidth,
417
+ cloudHeight,
418
+ radius
419
+ );
420
+ const centerPerimeter = cloudPathPerimeter(centerPath);
421
+ if (centerPerimeter <= 0) return "";
422
+ const lobeCount = Math.max(
423
+ 8,
424
+ Math.round(centerPerimeter / ARCHITECTURAL_CLOUD_ROUNDED_TARGET_SPACING)
425
+ );
426
+ const centers = Array.from(
427
+ { length: lobeCount },
428
+ (_, index) => pointOnCloudPath(centerPath, centerPerimeter * index / lobeCount)
429
+ );
430
+ const points = centers.map((point, index) => {
431
+ const previous = centers[(index - 1 + centers.length) % centers.length] ?? point;
432
+ return cloudCircleIntersection(previous, point, radius, center);
433
+ });
434
+ const [startX, startY] = points[0] ?? [0, 0];
435
+ const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
436
+ for (const [endX, endY] of points.slice(1)) {
437
+ segments.push(
438
+ `A ${svgNumber(radius)} ${svgNumber(radius)} 0 0 1 ${svgNumber(endX)} ${svgNumber(endY)}`
431
439
  );
432
440
  }
433
- return [metrics.centerX, metrics.top];
441
+ segments.push(
442
+ `A ${svgNumber(radius)} ${svgNumber(radius)} 0 0 1 ${svgNumber(startX)} ${svgNumber(startY)}`
443
+ );
444
+ segments.push("Z");
445
+ return segments.join(" ");
446
+ }
447
+ function cloudCircleIntersection(a, b, radius, center) {
448
+ const midX = (a[0] + b[0]) / 2;
449
+ const midY = (a[1] + b[1]) / 2;
450
+ const dx = b[0] - a[0];
451
+ const dy = b[1] - a[1];
452
+ const distance = Math.hypot(dx, dy);
453
+ if (distance <= 1e-9) return [midX, midY];
454
+ const halfDistance = distance / 2;
455
+ const offset = Math.sqrt(
456
+ Math.max(0, radius * radius - halfDistance * halfDistance)
457
+ );
458
+ const normalX = -dy / distance;
459
+ const normalY = dx / distance;
460
+ const first = [midX + normalX * offset, midY + normalY * offset];
461
+ const second = [
462
+ midX - normalX * offset,
463
+ midY - normalY * offset
464
+ ];
465
+ const firstDistance = (first[0] - center[0]) * (first[0] - center[0]) + (first[1] - center[1]) * (first[1] - center[1]);
466
+ const secondDistance = (second[0] - center[0]) * (second[0] - center[0]) + (second[1] - center[1]) * (second[1] - center[1]);
467
+ return firstDistance >= secondDistance ? first : second;
468
+ }
469
+ function cloudEllipseIntersection(a, b, radiusX, radiusY, center) {
470
+ const scaleY = radiusX / radiusY;
471
+ const [x, y] = cloudCircleIntersection(
472
+ [a[0], a[1] * scaleY],
473
+ [b[0], b[1] * scaleY],
474
+ radiusX,
475
+ [center[0], center[1] * scaleY]
476
+ );
477
+ return [x, y / scaleY];
434
478
  }
435
479
  function buildRectSvg(width, height, style = DEFAULT_STROKE_STYLE) {
436
480
  return `<rect width="${width}" height="${height}" fill="none" stroke="${style.stroke}" stroke-width="${style.strokeWidth}" rx="4"${strokeOpacityAttr(style)} />`;
@@ -444,39 +488,63 @@ function buildArchitecturalCloudPathD(width, height, strokeWidth = DEFAULT_STROK
444
488
  const w = Math.max(0, width);
445
489
  const h = Math.max(0, height);
446
490
  if (w <= 0 || h <= 0) return "";
447
- const inset = Math.max(0.5, strokeWidth / 2);
448
- const outerWidth = Math.max(0, w - inset * 2);
449
- const outerHeight = Math.max(0, h - inset * 2);
450
- if (outerWidth <= 0 || outerHeight <= 0) return "";
451
- const amplitude = Math.min(
452
- outerWidth * 0.12,
453
- outerHeight * 0.12,
454
- Math.max(5, Math.min(14, Math.min(w, h) * 0.07))
491
+ const padding = Math.max(0, strokeWidth * 2);
492
+ const cloudWidth = Math.max(0, w - padding);
493
+ const cloudHeight = Math.max(0, h - padding);
494
+ if (cloudWidth <= 0 || cloudHeight <= 0) return "";
495
+ const radiusX = Math.min(
496
+ ARCHITECTURAL_CLOUD_RADIUS,
497
+ cloudWidth * ARCHITECTURAL_CLOUD_FLAT_RADIUS_RATIO
455
498
  );
456
- const radius = Math.min(
457
- outerWidth / 2,
458
- outerHeight / 2,
459
- Math.max(amplitude * 2.5, outerHeight * 0.43)
499
+ const radiusY = Math.min(
500
+ ARCHITECTURAL_CLOUD_RADIUS,
501
+ cloudHeight * ARCHITECTURAL_CLOUD_FLAT_RADIUS_RATIO
502
+ );
503
+ if (radiusX <= 0 || radiusY <= 0) return "";
504
+ const center = [cloudWidth / 2, cloudHeight / 2];
505
+ const leftCenterX = radiusX;
506
+ const rightCenterX = cloudWidth - radiusX;
507
+ const topCenterY = radiusY;
508
+ const bottomCenterY = cloudHeight - radiusY;
509
+ const horizontalCenters = distributeRange(
510
+ leftCenterX,
511
+ rightCenterX,
512
+ architecturalCloudCenterCount(Math.max(0, rightCenterX - leftCenterX), radiusX)
460
513
  );
461
- const outer = roundedRectMetrics(w, h, inset, radius);
462
- const inner = roundedRectMetrics(
463
- w,
464
- h,
465
- inset + amplitude,
466
- Math.max(0, radius - amplitude)
514
+ const verticalCenters = distributeRange(
515
+ topCenterY,
516
+ bottomCenterY,
517
+ architecturalCloudCenterCount(Math.max(0, bottomCenterY - topCenterY), radiusY)
467
518
  );
468
- const scallopCount = architecturalCloudScallopCount(outer.perimeter, amplitude);
469
- const [startX, startY] = pointOnRoundedRectPath(inner, 0);
519
+ if (horizontalCenters.length > 3 && verticalCenters.length > 3) {
520
+ const roundedArcCloudPath = buildRoundedArcCloudPathD(
521
+ cloudWidth,
522
+ cloudHeight,
523
+ center
524
+ );
525
+ if (roundedArcCloudPath !== "") return roundedArcCloudPath;
526
+ }
527
+ const rectangularCenters = [
528
+ ...horizontalCenters.map((x) => [x, topCenterY]),
529
+ ...verticalCenters.slice(1).map((y) => [rightCenterX, y]),
530
+ ...horizontalCenters.slice(0, -1).reverse().map((x) => [x, bottomCenterY]),
531
+ ...verticalCenters.slice(1, -1).reverse().map((y) => [leftCenterX, y])
532
+ ];
533
+ const centers = rectangularCenters;
534
+ const points = centers.map((point, index) => {
535
+ const previous = centers[(index - 1 + centers.length) % centers.length] ?? point;
536
+ return cloudEllipseIntersection(previous, point, radiusX, radiusY, center);
537
+ });
538
+ const [startX, startY] = points[0] ?? [0, 0];
470
539
  const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
471
- for (let index = 0; index < scallopCount; index += 1) {
472
- const controlDistance = (index + 0.5) / scallopCount * outer.perimeter;
473
- const endDistance = (index + 1) / scallopCount * inner.perimeter;
474
- const [controlX, controlY] = pointOnRoundedRectPath(outer, controlDistance);
475
- const [endX, endY] = pointOnRoundedRectPath(inner, endDistance);
540
+ for (const [endX, endY] of points.slice(1)) {
476
541
  segments.push(
477
- `Q${svgNumber(controlX)} ${svgNumber(controlY)} ${svgNumber(endX)} ${svgNumber(endY)}`
542
+ `A ${svgNumber(radiusX)} ${svgNumber(radiusY)} 0 0 1 ${svgNumber(endX)} ${svgNumber(endY)}`
478
543
  );
479
544
  }
545
+ segments.push(
546
+ `A ${svgNumber(radiusX)} ${svgNumber(radiusY)} 0 0 1 ${svgNumber(startX)} ${svgNumber(startY)}`
547
+ );
480
548
  segments.push("Z");
481
549
  return segments.join(" ");
482
550
  }
@@ -914,7 +982,7 @@ function createImageFromVectorTrace(id, bounds, imageVectorInnerSvg, imageVector
914
982
  childrenSvg
915
983
  };
916
984
  }
917
- var DEFAULT_STROKE_STYLE, TOOL_FREEHAND_DEFAULTS;
985
+ var DEFAULT_STROKE_STYLE, TOOL_FREEHAND_DEFAULTS, ARCHITECTURAL_CLOUD_RADIUS, ARCHITECTURAL_CLOUD_TARGET_SPACING, ARCHITECTURAL_CLOUD_FLAT_RADIUS_RATIO, ARCHITECTURAL_CLOUD_ROUNDED_RADIUS, ARCHITECTURAL_CLOUD_ROUNDED_MIN_RADIUS, ARCHITECTURAL_CLOUD_ROUNDED_TARGET_SPACING;
918
986
  var init_shape_builders = __esm({
919
987
  "src/scene/shape-builders.ts"() {
920
988
  init_rect();
@@ -930,6 +998,12 @@ var init_shape_builders = __esm({
930
998
  brush: { strokeWidth: 10 },
931
999
  marker: { stroke: "#fde047", strokeWidth: 16, strokeOpacity: 0.5 }
932
1000
  };
1001
+ ARCHITECTURAL_CLOUD_RADIUS = 38;
1002
+ ARCHITECTURAL_CLOUD_TARGET_SPACING = 50;
1003
+ ARCHITECTURAL_CLOUD_FLAT_RADIUS_RATIO = 0.38;
1004
+ ARCHITECTURAL_CLOUD_ROUNDED_RADIUS = 72;
1005
+ ARCHITECTURAL_CLOUD_ROUNDED_MIN_RADIUS = 44;
1006
+ ARCHITECTURAL_CLOUD_ROUNDED_TARGET_SPACING = 98;
933
1007
  }
934
1008
  });
935
1009
 
@@ -1744,6 +1818,67 @@ function useCanvuChromeContext() {
1744
1818
  return useContext(CanvuChromeContext);
1745
1819
  }
1746
1820
 
1821
+ // src/math/item-transform.ts
1822
+ init_rect();
1823
+ function getItemRotationRad(item) {
1824
+ return item.rotation ?? 0;
1825
+ }
1826
+ function itemLocalToWorld(lx, ly, itemX, itemY, w, h, rotationRad) {
1827
+ const c = { x: w / 2, y: h / 2 };
1828
+ const dlx = lx - c.x;
1829
+ const dly = ly - c.y;
1830
+ const cos = Math.cos(rotationRad);
1831
+ const sin = Math.sin(rotationRad);
1832
+ return {
1833
+ x: itemX + c.x + cos * dlx - sin * dly,
1834
+ y: itemY + c.y + sin * dlx + cos * dly
1835
+ };
1836
+ }
1837
+ function worldToItemLocal(wx, wy, itemX, itemY, w, h, rotationRad) {
1838
+ const c = { x: w / 2, y: h / 2 };
1839
+ const vx = wx - itemX;
1840
+ const vy = wy - itemY;
1841
+ const dx = vx - c.x;
1842
+ const dy = vy - c.y;
1843
+ const cos = Math.cos(-rotationRad);
1844
+ const sin = Math.sin(-rotationRad);
1845
+ const lx = cos * dx - sin * dy;
1846
+ const ly = sin * dx + cos * dy;
1847
+ return { x: c.x + lx, y: c.y + ly };
1848
+ }
1849
+ function itemPivotWorld(item) {
1850
+ const r = normalizeRect(item.bounds);
1851
+ return { x: r.x + r.width / 2, y: r.y + r.height / 2 };
1852
+ }
1853
+ function boundsAabbForRotatedItem(item) {
1854
+ const rot = getItemRotationRad(item);
1855
+ if (Math.abs(rot) < 1e-12 && item.bounds.width >= 0 && item.bounds.height >= 0) {
1856
+ return item.bounds;
1857
+ }
1858
+ const r = normalizeRect(item.bounds);
1859
+ if (Math.abs(rot) < 1e-12) {
1860
+ return r;
1861
+ }
1862
+ const corners = [
1863
+ [0, 0],
1864
+ [r.width, 0],
1865
+ [r.width, r.height],
1866
+ [0, r.height]
1867
+ ];
1868
+ let minX = Infinity;
1869
+ let minY = Infinity;
1870
+ let maxX = -Infinity;
1871
+ let maxY = -Infinity;
1872
+ for (const [lx, ly] of corners) {
1873
+ const p = itemLocalToWorld(lx, ly, item.x, item.y, r.width, r.height, rot);
1874
+ minX = Math.min(minX, p.x);
1875
+ minY = Math.min(minY, p.y);
1876
+ maxX = Math.max(maxX, p.x);
1877
+ maxY = Math.max(maxY, p.y);
1878
+ }
1879
+ return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };
1880
+ }
1881
+
1747
1882
  // src/scene/clone-item.ts
1748
1883
  init_shape_builders();
1749
1884
  function cloneVectorSceneItemWithNewId(item) {
@@ -1783,20 +1918,25 @@ function markImageAsManaged(item) {
1783
1918
  };
1784
1919
  }
1785
1920
  function restackManagedImages(items) {
1786
- let anchor;
1921
+ let anchorAabbY = Infinity;
1922
+ let anchorCenterX = 0;
1787
1923
  for (const item of items) {
1788
1924
  if (!isManagedImage(item)) continue;
1789
- if (!anchor || item.bounds.y < anchor.bounds.y) anchor = item;
1925
+ const aabb = boundsAabbForRotatedItem(item);
1926
+ if (aabb.y < anchorAabbY) {
1927
+ anchorAabbY = aabb.y;
1928
+ anchorCenterX = aabb.x + aabb.width / 2;
1929
+ }
1790
1930
  }
1791
- if (!anchor) return [...items];
1792
- const anchorCenterX = anchor.bounds.x + anchor.bounds.width / 2;
1793
- const anchorTopY = anchor.bounds.y;
1794
- let cursorY = anchorTopY;
1931
+ if (!Number.isFinite(anchorAabbY)) return [...items];
1932
+ let cursorY = anchorAabbY;
1795
1933
  return items.map((item) => {
1796
1934
  if (!isManagedImage(item)) return item;
1935
+ const aabb = boundsAabbForRotatedItem(item);
1936
+ const centerY = cursorY + aabb.height / 2;
1797
1937
  const newX = anchorCenterX - item.bounds.width / 2;
1798
- const newY = cursorY;
1799
- cursorY = newY + item.bounds.height + STACK_GAP_WORLD;
1938
+ const newY = centerY - item.bounds.height / 2;
1939
+ cursorY += aabb.height + STACK_GAP_WORLD;
1800
1940
  if (item.bounds.x === newX && item.bounds.y === newY) return item;
1801
1941
  return {
1802
1942
  ...item,
@@ -1816,8 +1956,10 @@ function copyManagedImage(items, id) {
1816
1956
  return restackManagedImages(inserted);
1817
1957
  }
1818
1958
  function rotateManagedImage(items, id) {
1819
- return items.map(
1820
- (i) => i.id === id ? { ...i, rotation: ((i.rotation ?? 0) + Math.PI / 2) % (Math.PI * 2) } : i
1959
+ return restackManagedImages(
1960
+ items.map(
1961
+ (i) => i.id === id ? { ...i, rotation: ((i.rotation ?? 0) + Math.PI / 2) % (Math.PI * 2) } : i
1962
+ )
1821
1963
  );
1822
1964
  }
1823
1965
  function deleteManagedImage(items, id) {
@@ -2264,69 +2406,6 @@ function getBoardPositionStyle(position, inset = 12, zIndex = 40) {
2264
2406
  return base2;
2265
2407
  }
2266
2408
  }
2267
-
2268
- // src/math/item-transform.ts
2269
- init_rect();
2270
- function getItemRotationRad(item) {
2271
- return item.rotation ?? 0;
2272
- }
2273
- function itemLocalToWorld(lx, ly, itemX, itemY, w, h, rotationRad) {
2274
- const c = { x: w / 2, y: h / 2 };
2275
- const dlx = lx - c.x;
2276
- const dly = ly - c.y;
2277
- const cos = Math.cos(rotationRad);
2278
- const sin = Math.sin(rotationRad);
2279
- return {
2280
- x: itemX + c.x + cos * dlx - sin * dly,
2281
- y: itemY + c.y + sin * dlx + cos * dly
2282
- };
2283
- }
2284
- function worldToItemLocal(wx, wy, itemX, itemY, w, h, rotationRad) {
2285
- const c = { x: w / 2, y: h / 2 };
2286
- const vx = wx - itemX;
2287
- const vy = wy - itemY;
2288
- const dx = vx - c.x;
2289
- const dy = vy - c.y;
2290
- const cos = Math.cos(-rotationRad);
2291
- const sin = Math.sin(-rotationRad);
2292
- const lx = cos * dx - sin * dy;
2293
- const ly = sin * dx + cos * dy;
2294
- return { x: c.x + lx, y: c.y + ly };
2295
- }
2296
- function itemPivotWorld(item) {
2297
- const r = normalizeRect(item.bounds);
2298
- return { x: r.x + r.width / 2, y: r.y + r.height / 2 };
2299
- }
2300
- function boundsAabbForRotatedItem(item) {
2301
- const rot = getItemRotationRad(item);
2302
- if (Math.abs(rot) < 1e-12 && item.bounds.width >= 0 && item.bounds.height >= 0) {
2303
- return item.bounds;
2304
- }
2305
- const r = normalizeRect(item.bounds);
2306
- if (Math.abs(rot) < 1e-12) {
2307
- return r;
2308
- }
2309
- const corners = [
2310
- [0, 0],
2311
- [r.width, 0],
2312
- [r.width, r.height],
2313
- [0, r.height]
2314
- ];
2315
- let minX = Infinity;
2316
- let minY = Infinity;
2317
- let maxX = -Infinity;
2318
- let maxY = -Infinity;
2319
- for (const [lx, ly] of corners) {
2320
- const p = itemLocalToWorld(lx, ly, item.x, item.y, r.width, r.height, rot);
2321
- minX = Math.min(minX, p.x);
2322
- minY = Math.min(minY, p.y);
2323
- maxX = Math.max(maxX, p.x);
2324
- maxY = Math.max(maxY, p.y);
2325
- }
2326
- return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };
2327
- }
2328
-
2329
- // src/react/navmenu/minimap.tsx
2330
2409
  init_rect();
2331
2410
  var NavMenuMinimapSlotContext = createContext(null);
2332
2411
  function noop() {
@@ -3234,7 +3313,7 @@ function ShapeContextMenu({
3234
3313
  }
3235
3314
  return createPortal(menu, document.body);
3236
3315
  }
3237
- var architecturalCloudIconPath = "M11 2.44 Q13.3 1 14.84 2.44 Q17.84 1.4 18.41 3.47 Q20.8 4.72 19.56 7 Q20.8 9.28 18.41 10.53 Q17.84 12.6 14.84 11.56 Q13.3 13 11 11.56 Q8.7 13 7.16 11.56 Q4.16 12.6 3.59 10.53 Q1.2 9.28 2.44 7 Q1.2 4.72 3.59 3.47 Q4.16 1.4 7.16 2.44 Q8.7 1 11 2.44 Z";
3316
+ var architecturalCloudIconPath = "M1.5 12 A 4.94 5.23 0 0 1 9.07 6 A 4.94 5.23 0 0 1 14.93 6 A 4.94 5.23 0 0 1 22.5 12 A 4.94 5.23 0 0 1 14.93 18 A 4.94 5.23 0 0 1 9.07 18 A 4.94 5.23 0 0 1 1.5 12 Z";
3238
3317
  var base = {
3239
3318
  width: 20,
3240
3319
  height: 20,
@@ -3266,7 +3345,7 @@ function IconEllipse(props) {
3266
3345
  return /* @__PURE__ */ jsx("svg", { ...base, ...props, "aria-hidden": true, children: /* @__PURE__ */ jsx("ellipse", { cx: "12", cy: "12", rx: "9", ry: "6" }) });
3267
3346
  }
3268
3347
  function IconArchitecturalCloud(props) {
3269
- return /* @__PURE__ */ jsx("svg", { ...base, ...props, "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: architecturalCloudIconPath, transform: "translate(1 5)" }) });
3348
+ return /* @__PURE__ */ jsx("svg", { ...base, ...props, "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: architecturalCloudIconPath }) });
3270
3349
  }
3271
3350
  function IconLine(props) {
3272
3351
  return /* @__PURE__ */ jsx("svg", { ...base, ...props, "aria-hidden": true, children: /* @__PURE__ */ jsx("line", { x1: "5", y1: "19", x2: "19", y2: "5" }) });