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/native.cjs CHANGED
@@ -424,203 +424,6 @@ function svgNumber(value) {
424
424
  return Number.isInteger(rounded) ? String(rounded) : String(rounded);
425
425
  }
426
426
  var ARCHITECTURAL_CLOUD_RADIUS = 38;
427
- var ARCHITECTURAL_CLOUD_TARGET_SPACING = 50;
428
- var ARCHITECTURAL_CLOUD_FLAT_RADIUS_RATIO = 0.38;
429
- var ARCHITECTURAL_CLOUD_ROUNDED_RADIUS = 72;
430
- var ARCHITECTURAL_CLOUD_ROUNDED_MIN_RADIUS = 44;
431
- var ARCHITECTURAL_CLOUD_ROUNDED_TARGET_SPACING = 98;
432
- function architecturalCloudCenterCount(edgeLength, radius) {
433
- const targetSpacing = Math.min(
434
- ARCHITECTURAL_CLOUD_TARGET_SPACING,
435
- Math.max(1, radius * 1.3)
436
- );
437
- return Math.max(2, Math.round(edgeLength / targetSpacing) + 1);
438
- }
439
- function distributeRange(start, end, count) {
440
- if (count <= 1) return [start];
441
- const step = (end - start) / (count - 1);
442
- return Array.from({ length: count }, (_, index) => start + step * index);
443
- }
444
- function lineCloudPathSegment(start, end) {
445
- const dx = end[0] - start[0];
446
- const dy = end[1] - start[1];
447
- const length = Math.hypot(dx, dy);
448
- return {
449
- length,
450
- pointAt: (t) => [start[0] + dx * t, start[1] + dy * t]
451
- };
452
- }
453
- function ellipsePoint(centerX, centerY, radiusX, radiusY, angle) {
454
- return [centerX + Math.cos(angle) * radiusX, centerY + Math.sin(angle) * radiusY];
455
- }
456
- function approximateEllipseArcLength(radiusX, radiusY, startAngle, endAngle) {
457
- const steps = Math.max(
458
- 4,
459
- Math.ceil(Math.abs(endAngle - startAngle) / (Math.PI / 16))
460
- );
461
- let length = 0;
462
- let previous = ellipsePoint(0, 0, radiusX, radiusY, startAngle);
463
- for (let index = 1; index <= steps; index += 1) {
464
- const angle = startAngle + (endAngle - startAngle) * index / steps;
465
- const next = ellipsePoint(0, 0, radiusX, radiusY, angle);
466
- length += Math.hypot(next[0] - previous[0], next[1] - previous[1]);
467
- previous = next;
468
- }
469
- return length;
470
- }
471
- function ellipseCloudPathSegment(centerX, centerY, radiusX, radiusY, startAngle, endAngle) {
472
- return {
473
- length: approximateEllipseArcLength(radiusX, radiusY, startAngle, endAngle),
474
- pointAt: (t) => ellipsePoint(
475
- centerX,
476
- centerY,
477
- radiusX,
478
- radiusY,
479
- startAngle + (endAngle - startAngle) * t
480
- )
481
- };
482
- }
483
- function cloudPathPerimeter(segments) {
484
- const usableSegments = segments.filter((segment) => segment.length > 1e-9);
485
- return usableSegments.reduce((sum, segment) => sum + segment.length, 0);
486
- }
487
- function pointOnCloudPath(segments, distance) {
488
- const perimeter = cloudPathPerimeter(segments);
489
- if (perimeter <= 0) return [0, 0];
490
- let remaining = (distance % perimeter + perimeter) % perimeter;
491
- for (const segment of segments) {
492
- if (segment.length <= 1e-9) continue;
493
- if (remaining <= segment.length) {
494
- const t = remaining / segment.length;
495
- return segment.pointAt(t);
496
- }
497
- remaining -= segment.length;
498
- }
499
- const fallback = segments.find((segment) => segment.length > 1e-9);
500
- return fallback?.pointAt(0) ?? [0, 0];
501
- }
502
- function buildRoundedCapsulePathSegments(width, height, inset) {
503
- const left = inset;
504
- const top = inset;
505
- const right = width - inset;
506
- const bottom = height - inset;
507
- const capsuleWidth = Math.max(0, right - left);
508
- const capsuleHeight = Math.max(0, bottom - top);
509
- const radius = Math.min(capsuleWidth, capsuleHeight) / 2;
510
- if (radius <= 0) return [];
511
- const leftCenterX = left + radius;
512
- const rightCenterX = right - radius;
513
- const topCenterY = top + radius;
514
- const bottomCenterY = bottom - radius;
515
- return [
516
- lineCloudPathSegment([leftCenterX, top], [rightCenterX, top]),
517
- ellipseCloudPathSegment(
518
- rightCenterX,
519
- topCenterY,
520
- radius,
521
- radius,
522
- -Math.PI / 2,
523
- 0
524
- ),
525
- lineCloudPathSegment([right, topCenterY], [right, bottomCenterY]),
526
- ellipseCloudPathSegment(
527
- rightCenterX,
528
- bottomCenterY,
529
- radius,
530
- radius,
531
- 0,
532
- Math.PI / 2
533
- ),
534
- lineCloudPathSegment([rightCenterX, bottom], [leftCenterX, bottom]),
535
- ellipseCloudPathSegment(
536
- leftCenterX,
537
- bottomCenterY,
538
- radius,
539
- radius,
540
- Math.PI / 2,
541
- Math.PI
542
- ),
543
- lineCloudPathSegment([left, bottomCenterY], [left, topCenterY]),
544
- ellipseCloudPathSegment(
545
- leftCenterX,
546
- topCenterY,
547
- radius,
548
- radius,
549
- Math.PI,
550
- Math.PI * 1.5
551
- )
552
- ];
553
- }
554
- function buildRoundedArcCloudPathD(cloudWidth, cloudHeight, center) {
555
- const minDimension = Math.min(cloudWidth, cloudHeight);
556
- const radius = Math.min(
557
- ARCHITECTURAL_CLOUD_ROUNDED_RADIUS,
558
- Math.max(ARCHITECTURAL_CLOUD_ROUNDED_MIN_RADIUS, minDimension * 0.16)
559
- );
560
- const centerPath = buildRoundedCapsulePathSegments(
561
- cloudWidth,
562
- cloudHeight,
563
- radius
564
- );
565
- const centerPerimeter = cloudPathPerimeter(centerPath);
566
- if (centerPerimeter <= 0) return "";
567
- const lobeCount = Math.max(
568
- 8,
569
- Math.round(centerPerimeter / ARCHITECTURAL_CLOUD_ROUNDED_TARGET_SPACING)
570
- );
571
- const centers = Array.from(
572
- { length: lobeCount },
573
- (_, index) => pointOnCloudPath(centerPath, centerPerimeter * index / lobeCount)
574
- );
575
- const points = centers.map((point, index) => {
576
- const previous = centers[(index - 1 + centers.length) % centers.length] ?? point;
577
- return cloudCircleIntersection(previous, point, radius, center);
578
- });
579
- const [startX, startY] = points[0] ?? [0, 0];
580
- const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
581
- for (const [endX, endY] of points.slice(1)) {
582
- segments.push(
583
- `A ${svgNumber(radius)} ${svgNumber(radius)} 0 0 1 ${svgNumber(endX)} ${svgNumber(endY)}`
584
- );
585
- }
586
- segments.push(
587
- `A ${svgNumber(radius)} ${svgNumber(radius)} 0 0 1 ${svgNumber(startX)} ${svgNumber(startY)}`
588
- );
589
- segments.push("Z");
590
- return segments.join(" ");
591
- }
592
- function cloudCircleIntersection(a, b, radius, center) {
593
- const midX = (a[0] + b[0]) / 2;
594
- const midY = (a[1] + b[1]) / 2;
595
- const dx = b[0] - a[0];
596
- const dy = b[1] - a[1];
597
- const distance = Math.hypot(dx, dy);
598
- if (distance <= 1e-9) return [midX, midY];
599
- const halfDistance = distance / 2;
600
- const offset = Math.sqrt(
601
- Math.max(0, radius * radius - halfDistance * halfDistance)
602
- );
603
- const normalX = -dy / distance;
604
- const normalY = dx / distance;
605
- const first = [midX + normalX * offset, midY + normalY * offset];
606
- const second = [
607
- midX - normalX * offset,
608
- midY - normalY * offset
609
- ];
610
- const firstDistance = (first[0] - center[0]) * (first[0] - center[0]) + (first[1] - center[1]) * (first[1] - center[1]);
611
- const secondDistance = (second[0] - center[0]) * (second[0] - center[0]) + (second[1] - center[1]) * (second[1] - center[1]);
612
- return firstDistance >= secondDistance ? first : second;
613
- }
614
- function cloudEllipseIntersection(a, b, radiusX, radiusY, center) {
615
- const scaleY = radiusX / radiusY;
616
- const [x, y] = cloudCircleIntersection(
617
- [a[0], a[1] * scaleY],
618
- [b[0], b[1] * scaleY],
619
- radiusX,
620
- [center[0], center[1] * scaleY]
621
- );
622
- return [x, y / scaleY];
623
- }
624
427
  function buildRectSvg(width, height, style = DEFAULT_STROKE_STYLE) {
625
428
  return `<rect width="${width}" height="${height}" fill="none" stroke="${style.stroke}" stroke-width="${style.strokeWidth}" rx="4"${strokeOpacityAttr(style)} />`;
626
429
  }
@@ -629,67 +432,42 @@ function buildEllipseSvg(width, height, style = DEFAULT_STROKE_STYLE) {
629
432
  const ry = height / 2;
630
433
  return `<ellipse cx="${rx}" cy="${ry}" rx="${rx}" ry="${ry}" fill="none" stroke="${style.stroke}" stroke-width="${style.strokeWidth}"${strokeOpacityAttr(style)} />`;
631
434
  }
632
- function buildArchitecturalCloudPathD(width, height, strokeWidth = DEFAULT_STROKE_STYLE.strokeWidth) {
633
- const w = Math.max(0, width);
634
- const h = Math.max(0, height);
635
- if (w <= 0 || h <= 0) return "";
435
+ function buildArchitecturalCloudPathD(width, height, strokeWidth = DEFAULT_STROKE_STYLE.strokeWidth, arcRadius = ARCHITECTURAL_CLOUD_RADIUS, bulge = 1) {
636
436
  const padding = Math.max(0, strokeWidth * 2);
637
- const cloudWidth = Math.max(0, w - padding);
638
- const cloudHeight = Math.max(0, h - padding);
639
- if (cloudWidth <= 0 || cloudHeight <= 0) return "";
640
- const radiusX = Math.min(
641
- ARCHITECTURAL_CLOUD_RADIUS,
642
- cloudWidth * ARCHITECTURAL_CLOUD_FLAT_RADIUS_RATIO
643
- );
644
- const radiusY = Math.min(
645
- ARCHITECTURAL_CLOUD_RADIUS,
646
- cloudHeight * ARCHITECTURAL_CLOUD_FLAT_RADIUS_RATIO
647
- );
648
- if (radiusX <= 0 || radiusY <= 0) return "";
649
- const center = [cloudWidth / 2, cloudHeight / 2];
650
- const leftCenterX = radiusX;
651
- const rightCenterX = cloudWidth - radiusX;
652
- const topCenterY = radiusY;
653
- const bottomCenterY = cloudHeight - radiusY;
654
- const horizontalCenters = distributeRange(
655
- leftCenterX,
656
- rightCenterX,
657
- architecturalCloudCenterCount(Math.max(0, rightCenterX - leftCenterX), radiusX)
658
- );
659
- const verticalCenters = distributeRange(
660
- topCenterY,
661
- bottomCenterY,
662
- architecturalCloudCenterCount(Math.max(0, bottomCenterY - topCenterY), radiusY)
663
- );
664
- if (horizontalCenters.length > 3 && verticalCenters.length > 3) {
665
- const roundedArcCloudPath = buildRoundedArcCloudPathD(
666
- cloudWidth,
667
- cloudHeight,
668
- center
669
- );
670
- if (roundedArcCloudPath !== "") return roundedArcCloudPath;
671
- }
672
- const rectangularCenters = [
673
- ...horizontalCenters.map((x) => [x, topCenterY]),
674
- ...verticalCenters.slice(1).map((y) => [rightCenterX, y]),
675
- ...horizontalCenters.slice(0, -1).reverse().map((x) => [x, bottomCenterY]),
676
- ...verticalCenters.slice(1, -1).reverse().map((y) => [leftCenterX, y])
437
+ const cloudWidth = Math.max(0, width - padding);
438
+ const cloudHeight = Math.max(0, height - padding);
439
+ if (cloudWidth <= 0 || cloudHeight <= 0 || arcRadius <= 0 || bulge <= 0) return "";
440
+ const offset = padding / 2;
441
+ const corners = [
442
+ [offset, offset],
443
+ [offset + cloudWidth, offset],
444
+ [offset + cloudWidth, offset + cloudHeight],
445
+ [offset, offset + cloudHeight]
677
446
  ];
678
- const centers = rectangularCenters;
679
- const points = centers.map((point, index) => {
680
- const previous = centers[(index - 1 + centers.length) % centers.length] ?? point;
681
- return cloudEllipseIntersection(previous, point, radiusX, radiusY, center);
682
- });
683
- const [startX, startY] = points[0] ?? [0, 0];
447
+ const points = [];
448
+ for (let index = 0; index < corners.length; index += 1) {
449
+ const [startX2, startY2] = corners[index] ?? [0, 0];
450
+ const [endX, endY] = corners[(index + 1) % corners.length] ?? [0, 0];
451
+ const edgeLength = Math.hypot(endX - startX2, endY - startY2);
452
+ const arcCount = Math.max(1, Math.round(edgeLength / (2 * arcRadius)));
453
+ const chord = edgeLength / arcCount;
454
+ for (let arcIndex = 1; arcIndex <= arcCount; arcIndex += 1) {
455
+ const t = arcIndex / arcCount;
456
+ points.push([
457
+ startX2 + (endX - startX2) * t,
458
+ startY2 + (endY - startY2) * t,
459
+ chord
460
+ ]);
461
+ }
462
+ }
463
+ const [startX, startY] = corners[0] ?? [0, 0];
684
464
  const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
685
- for (const [endX, endY] of points.slice(1)) {
465
+ for (const [pointX, pointY, chord] of points) {
466
+ const radius = chord / 2 * bulge;
686
467
  segments.push(
687
- `A ${svgNumber(radiusX)} ${svgNumber(radiusY)} 0 0 1 ${svgNumber(endX)} ${svgNumber(endY)}`
468
+ `A ${svgNumber(radius)} ${svgNumber(radius)} 0 0 1 ${svgNumber(pointX)} ${svgNumber(pointY)}`
688
469
  );
689
470
  }
690
- segments.push(
691
- `A ${svgNumber(radiusX)} ${svgNumber(radiusY)} 0 0 1 ${svgNumber(startX)} ${svgNumber(startY)}`
692
- );
693
471
  segments.push("Z");
694
472
  return segments.join(" ");
695
473
  }
@@ -5598,8 +5376,8 @@ var NATIVE_VIEWPORT_EXTERNAL_OVERLAY_Z_INDEX = 20;
5598
5376
  var NATIVE_VIEWPORT_EXTERNAL_OVERLAY_ELEVATION = 20;
5599
5377
  var LONG_PRESS_CONTEXT_MENU_MS = 520;
5600
5378
  var LONG_PRESS_CONTEXT_MENU_CANCEL_PX = 10;
5601
- var NATIVE_CONTEXT_MENU_WIDTH = 304;
5602
- var NATIVE_CONTEXT_MENU_HEIGHT = 52;
5379
+ var NATIVE_CONTEXT_MENU_WIDTH = 168;
5380
+ var NATIVE_CONTEXT_MENU_HEIGHT = 184;
5603
5381
  var NATIVE_CONTEXT_MENU_MARGIN = 12;
5604
5382
  function isPlacementTool(toolId) {
5605
5383
  return toolId === "rect" || toolId === "ellipse" || toolId === "architectural-cloud" || toolId === "line" || toolId === "arrow";
@@ -7155,9 +6933,9 @@ var styles4 = reactNative.StyleSheet.create({
7155
6933
  position: "absolute",
7156
6934
  width: NATIVE_CONTEXT_MENU_WIDTH,
7157
6935
  minHeight: NATIVE_CONTEXT_MENU_HEIGHT,
7158
- flexDirection: "row",
7159
- alignItems: "center",
7160
- justifyContent: "space-between",
6936
+ flexDirection: "column",
6937
+ alignItems: "stretch",
6938
+ justifyContent: "flex-start",
7161
6939
  padding: 4,
7162
6940
  borderRadius: 14,
7163
6941
  borderWidth: reactNative.StyleSheet.hairlineWidth,
@@ -7171,11 +6949,12 @@ var styles4 = reactNative.StyleSheet.create({
7171
6949
  zIndex: NATIVE_VIEWPORT_OVERLAY_Z_INDEX + 4
7172
6950
  },
7173
6951
  nativeSelectionContextMenuButton: {
6952
+ width: "100%",
7174
6953
  minHeight: 42,
7175
- alignItems: "center",
6954
+ alignItems: "flex-start",
7176
6955
  justifyContent: "center",
7177
6956
  borderRadius: 10,
7178
- paddingHorizontal: 10
6957
+ paddingHorizontal: 14
7179
6958
  },
7180
6959
  nativeSelectionContextMenuButtonPressed: {
7181
6960
  backgroundColor: "#f4f4f5"
@@ -7186,7 +6965,7 @@ var styles4 = reactNative.StyleSheet.create({
7186
6965
  nativeSelectionContextMenuButtonText: {
7187
6966
  color: "#18181b",
7188
6967
  fontSize: 14,
7189
- fontWeight: "700"
6968
+ fontWeight: "400"
7190
6969
  },
7191
6970
  nativeSelectionContextMenuButtonTextDisabled: {
7192
6971
  color: "#71717a"