canvu-react 0.4.54 → 0.4.56

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.cjs CHANGED
@@ -453,198 +453,6 @@ function svgNumber(value) {
453
453
  const rounded = Math.round(value * 100) / 100;
454
454
  return Number.isInteger(rounded) ? String(rounded) : String(rounded);
455
455
  }
456
- function architecturalCloudCenterCount(edgeLength, radius) {
457
- const targetSpacing = Math.min(
458
- ARCHITECTURAL_CLOUD_TARGET_SPACING,
459
- Math.max(1, radius * 1.3)
460
- );
461
- return Math.max(2, Math.round(edgeLength / targetSpacing) + 1);
462
- }
463
- function distributeRange(start, end, count) {
464
- if (count <= 1) return [start];
465
- const step = (end - start) / (count - 1);
466
- return Array.from({ length: count }, (_, index) => start + step * index);
467
- }
468
- function lineCloudPathSegment(start, end) {
469
- const dx = end[0] - start[0];
470
- const dy = end[1] - start[1];
471
- const length = Math.hypot(dx, dy);
472
- return {
473
- length,
474
- pointAt: (t) => [start[0] + dx * t, start[1] + dy * t]
475
- };
476
- }
477
- function ellipsePoint(centerX, centerY, radiusX, radiusY, angle) {
478
- return [centerX + Math.cos(angle) * radiusX, centerY + Math.sin(angle) * radiusY];
479
- }
480
- function approximateEllipseArcLength(radiusX, radiusY, startAngle, endAngle) {
481
- const steps = Math.max(
482
- 4,
483
- Math.ceil(Math.abs(endAngle - startAngle) / (Math.PI / 16))
484
- );
485
- let length = 0;
486
- let previous = ellipsePoint(0, 0, radiusX, radiusY, startAngle);
487
- for (let index = 1; index <= steps; index += 1) {
488
- const angle = startAngle + (endAngle - startAngle) * index / steps;
489
- const next = ellipsePoint(0, 0, radiusX, radiusY, angle);
490
- length += Math.hypot(next[0] - previous[0], next[1] - previous[1]);
491
- previous = next;
492
- }
493
- return length;
494
- }
495
- function ellipseCloudPathSegment(centerX, centerY, radiusX, radiusY, startAngle, endAngle) {
496
- return {
497
- length: approximateEllipseArcLength(radiusX, radiusY, startAngle, endAngle),
498
- pointAt: (t) => ellipsePoint(
499
- centerX,
500
- centerY,
501
- radiusX,
502
- radiusY,
503
- startAngle + (endAngle - startAngle) * t
504
- )
505
- };
506
- }
507
- function cloudPathPerimeter(segments) {
508
- const usableSegments = segments.filter((segment) => segment.length > 1e-9);
509
- return usableSegments.reduce((sum, segment) => sum + segment.length, 0);
510
- }
511
- function pointOnCloudPath(segments, distance) {
512
- const perimeter = cloudPathPerimeter(segments);
513
- if (perimeter <= 0) return [0, 0];
514
- let remaining = (distance % perimeter + perimeter) % perimeter;
515
- for (const segment of segments) {
516
- if (segment.length <= 1e-9) continue;
517
- if (remaining <= segment.length) {
518
- const t = remaining / segment.length;
519
- return segment.pointAt(t);
520
- }
521
- remaining -= segment.length;
522
- }
523
- const fallback = segments.find((segment) => segment.length > 1e-9);
524
- return fallback?.pointAt(0) ?? [0, 0];
525
- }
526
- function buildRoundedCapsulePathSegments(width, height, inset) {
527
- const left = inset;
528
- const top = inset;
529
- const right = width - inset;
530
- const bottom = height - inset;
531
- const capsuleWidth = Math.max(0, right - left);
532
- const capsuleHeight = Math.max(0, bottom - top);
533
- const radius = Math.min(capsuleWidth, capsuleHeight) / 2;
534
- if (radius <= 0) return [];
535
- const leftCenterX = left + radius;
536
- const rightCenterX = right - radius;
537
- const topCenterY = top + radius;
538
- const bottomCenterY = bottom - radius;
539
- return [
540
- lineCloudPathSegment([leftCenterX, top], [rightCenterX, top]),
541
- ellipseCloudPathSegment(
542
- rightCenterX,
543
- topCenterY,
544
- radius,
545
- radius,
546
- -Math.PI / 2,
547
- 0
548
- ),
549
- lineCloudPathSegment([right, topCenterY], [right, bottomCenterY]),
550
- ellipseCloudPathSegment(
551
- rightCenterX,
552
- bottomCenterY,
553
- radius,
554
- radius,
555
- 0,
556
- Math.PI / 2
557
- ),
558
- lineCloudPathSegment([rightCenterX, bottom], [leftCenterX, bottom]),
559
- ellipseCloudPathSegment(
560
- leftCenterX,
561
- bottomCenterY,
562
- radius,
563
- radius,
564
- Math.PI / 2,
565
- Math.PI
566
- ),
567
- lineCloudPathSegment([left, bottomCenterY], [left, topCenterY]),
568
- ellipseCloudPathSegment(
569
- leftCenterX,
570
- topCenterY,
571
- radius,
572
- radius,
573
- Math.PI,
574
- Math.PI * 1.5
575
- )
576
- ];
577
- }
578
- function buildRoundedArcCloudPathD(cloudWidth, cloudHeight, center) {
579
- const minDimension = Math.min(cloudWidth, cloudHeight);
580
- const radius = Math.min(
581
- ARCHITECTURAL_CLOUD_ROUNDED_RADIUS,
582
- Math.max(ARCHITECTURAL_CLOUD_ROUNDED_MIN_RADIUS, minDimension * 0.16)
583
- );
584
- const centerPath = buildRoundedCapsulePathSegments(
585
- cloudWidth,
586
- cloudHeight,
587
- radius
588
- );
589
- const centerPerimeter = cloudPathPerimeter(centerPath);
590
- if (centerPerimeter <= 0) return "";
591
- const lobeCount = Math.max(
592
- 8,
593
- Math.round(centerPerimeter / ARCHITECTURAL_CLOUD_ROUNDED_TARGET_SPACING)
594
- );
595
- const centers = Array.from(
596
- { length: lobeCount },
597
- (_, index) => pointOnCloudPath(centerPath, centerPerimeter * index / lobeCount)
598
- );
599
- const points = centers.map((point, index) => {
600
- const previous = centers[(index - 1 + centers.length) % centers.length] ?? point;
601
- return cloudCircleIntersection(previous, point, radius, center);
602
- });
603
- const [startX, startY] = points[0] ?? [0, 0];
604
- const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
605
- for (const [endX, endY] of points.slice(1)) {
606
- segments.push(
607
- `A ${svgNumber(radius)} ${svgNumber(radius)} 0 0 1 ${svgNumber(endX)} ${svgNumber(endY)}`
608
- );
609
- }
610
- segments.push(
611
- `A ${svgNumber(radius)} ${svgNumber(radius)} 0 0 1 ${svgNumber(startX)} ${svgNumber(startY)}`
612
- );
613
- segments.push("Z");
614
- return segments.join(" ");
615
- }
616
- function cloudCircleIntersection(a, b, radius, center) {
617
- const midX = (a[0] + b[0]) / 2;
618
- const midY = (a[1] + b[1]) / 2;
619
- const dx = b[0] - a[0];
620
- const dy = b[1] - a[1];
621
- const distance = Math.hypot(dx, dy);
622
- if (distance <= 1e-9) return [midX, midY];
623
- const halfDistance = distance / 2;
624
- const offset = Math.sqrt(
625
- Math.max(0, radius * radius - halfDistance * halfDistance)
626
- );
627
- const normalX = -dy / distance;
628
- const normalY = dx / distance;
629
- const first = [midX + normalX * offset, midY + normalY * offset];
630
- const second = [
631
- midX - normalX * offset,
632
- midY - normalY * offset
633
- ];
634
- const firstDistance = (first[0] - center[0]) * (first[0] - center[0]) + (first[1] - center[1]) * (first[1] - center[1]);
635
- const secondDistance = (second[0] - center[0]) * (second[0] - center[0]) + (second[1] - center[1]) * (second[1] - center[1]);
636
- return firstDistance >= secondDistance ? first : second;
637
- }
638
- function cloudEllipseIntersection(a, b, radiusX, radiusY, center) {
639
- const scaleY = radiusX / radiusY;
640
- const [x, y] = cloudCircleIntersection(
641
- [a[0], a[1] * scaleY],
642
- [b[0], b[1] * scaleY],
643
- radiusX,
644
- [center[0], center[1] * scaleY]
645
- );
646
- return [x, y / scaleY];
647
- }
648
456
  function buildRectSvg(width, height, style = DEFAULT_STROKE_STYLE) {
649
457
  return `<rect width="${width}" height="${height}" fill="none" stroke="${style.stroke}" stroke-width="${style.strokeWidth}" rx="4"${strokeOpacityAttr(style)} />`;
650
458
  }
@@ -653,67 +461,42 @@ function buildEllipseSvg(width, height, style = DEFAULT_STROKE_STYLE) {
653
461
  const ry = height / 2;
654
462
  return `<ellipse cx="${rx}" cy="${ry}" rx="${rx}" ry="${ry}" fill="none" stroke="${style.stroke}" stroke-width="${style.strokeWidth}"${strokeOpacityAttr(style)} />`;
655
463
  }
656
- function buildArchitecturalCloudPathD(width, height, strokeWidth = DEFAULT_STROKE_STYLE.strokeWidth) {
657
- const w = Math.max(0, width);
658
- const h = Math.max(0, height);
659
- if (w <= 0 || h <= 0) return "";
464
+ function buildArchitecturalCloudPathD(width, height, strokeWidth = DEFAULT_STROKE_STYLE.strokeWidth, arcRadius = ARCHITECTURAL_CLOUD_RADIUS, bulge = 1) {
660
465
  const padding = Math.max(0, strokeWidth * 2);
661
- const cloudWidth = Math.max(0, w - padding);
662
- const cloudHeight = Math.max(0, h - padding);
663
- if (cloudWidth <= 0 || cloudHeight <= 0) return "";
664
- const radiusX = Math.min(
665
- ARCHITECTURAL_CLOUD_RADIUS,
666
- cloudWidth * ARCHITECTURAL_CLOUD_FLAT_RADIUS_RATIO
667
- );
668
- const radiusY = Math.min(
669
- ARCHITECTURAL_CLOUD_RADIUS,
670
- cloudHeight * ARCHITECTURAL_CLOUD_FLAT_RADIUS_RATIO
671
- );
672
- if (radiusX <= 0 || radiusY <= 0) return "";
673
- const center = [cloudWidth / 2, cloudHeight / 2];
674
- const leftCenterX = radiusX;
675
- const rightCenterX = cloudWidth - radiusX;
676
- const topCenterY = radiusY;
677
- const bottomCenterY = cloudHeight - radiusY;
678
- const horizontalCenters = distributeRange(
679
- leftCenterX,
680
- rightCenterX,
681
- architecturalCloudCenterCount(Math.max(0, rightCenterX - leftCenterX), radiusX)
682
- );
683
- const verticalCenters = distributeRange(
684
- topCenterY,
685
- bottomCenterY,
686
- architecturalCloudCenterCount(Math.max(0, bottomCenterY - topCenterY), radiusY)
687
- );
688
- if (horizontalCenters.length > 3 && verticalCenters.length > 3) {
689
- const roundedArcCloudPath = buildRoundedArcCloudPathD(
690
- cloudWidth,
691
- cloudHeight,
692
- center
693
- );
694
- if (roundedArcCloudPath !== "") return roundedArcCloudPath;
695
- }
696
- const rectangularCenters = [
697
- ...horizontalCenters.map((x) => [x, topCenterY]),
698
- ...verticalCenters.slice(1).map((y) => [rightCenterX, y]),
699
- ...horizontalCenters.slice(0, -1).reverse().map((x) => [x, bottomCenterY]),
700
- ...verticalCenters.slice(1, -1).reverse().map((y) => [leftCenterX, y])
466
+ const cloudWidth = Math.max(0, width - padding);
467
+ const cloudHeight = Math.max(0, height - padding);
468
+ if (cloudWidth <= 0 || cloudHeight <= 0 || arcRadius <= 0 || bulge <= 0) return "";
469
+ const offset = padding / 2;
470
+ const corners = [
471
+ [offset, offset],
472
+ [offset + cloudWidth, offset],
473
+ [offset + cloudWidth, offset + cloudHeight],
474
+ [offset, offset + cloudHeight]
701
475
  ];
702
- const centers = rectangularCenters;
703
- const points = centers.map((point, index) => {
704
- const previous = centers[(index - 1 + centers.length) % centers.length] ?? point;
705
- return cloudEllipseIntersection(previous, point, radiusX, radiusY, center);
706
- });
707
- const [startX, startY] = points[0] ?? [0, 0];
476
+ const points = [];
477
+ for (let index = 0; index < corners.length; index += 1) {
478
+ const [startX2, startY2] = corners[index] ?? [0, 0];
479
+ const [endX, endY] = corners[(index + 1) % corners.length] ?? [0, 0];
480
+ const edgeLength = Math.hypot(endX - startX2, endY - startY2);
481
+ const arcCount = Math.max(1, Math.round(edgeLength / (2 * arcRadius)));
482
+ const chord = edgeLength / arcCount;
483
+ for (let arcIndex = 1; arcIndex <= arcCount; arcIndex += 1) {
484
+ const t = arcIndex / arcCount;
485
+ points.push([
486
+ startX2 + (endX - startX2) * t,
487
+ startY2 + (endY - startY2) * t,
488
+ chord
489
+ ]);
490
+ }
491
+ }
492
+ const [startX, startY] = corners[0] ?? [0, 0];
708
493
  const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
709
- for (const [endX, endY] of points.slice(1)) {
494
+ for (const [pointX, pointY, chord] of points) {
495
+ const radius = chord / 2 * bulge;
710
496
  segments.push(
711
- `A ${svgNumber(radiusX)} ${svgNumber(radiusY)} 0 0 1 ${svgNumber(endX)} ${svgNumber(endY)}`
497
+ `A ${svgNumber(radius)} ${svgNumber(radius)} 0 0 1 ${svgNumber(pointX)} ${svgNumber(pointY)}`
712
498
  );
713
499
  }
714
- segments.push(
715
- `A ${svgNumber(radiusX)} ${svgNumber(radiusY)} 0 0 1 ${svgNumber(startX)} ${svgNumber(startY)}`
716
- );
717
500
  segments.push("Z");
718
501
  return segments.join(" ");
719
502
  }
@@ -1193,7 +976,7 @@ function createImageFromVectorTrace(id, bounds, imageVectorInnerSvg, imageVector
1193
976
  childrenSvg
1194
977
  };
1195
978
  }
1196
- 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;
979
+ var DEFAULT_STROKE_STYLE, TOOL_FREEHAND_DEFAULTS, ARCHITECTURAL_CLOUD_RADIUS;
1197
980
  var init_shape_builders = __esm({
1198
981
  "src/scene/shape-builders.ts"() {
1199
982
  init_rect();
@@ -1211,11 +994,6 @@ var init_shape_builders = __esm({
1211
994
  marker: { stroke: "#fde047", strokeWidth: 16, strokeOpacity: 0.5 }
1212
995
  };
1213
996
  ARCHITECTURAL_CLOUD_RADIUS = 38;
1214
- ARCHITECTURAL_CLOUD_TARGET_SPACING = 50;
1215
- ARCHITECTURAL_CLOUD_FLAT_RADIUS_RATIO = 0.38;
1216
- ARCHITECTURAL_CLOUD_ROUNDED_RADIUS = 72;
1217
- ARCHITECTURAL_CLOUD_ROUNDED_MIN_RADIUS = 44;
1218
- ARCHITECTURAL_CLOUD_ROUNDED_TARGET_SPACING = 98;
1219
997
  }
1220
998
  });
1221
999