canvu-react 0.4.55 → 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.d.cts CHANGED
@@ -4,16 +4,16 @@ import { I as IndexedDbImageStore } from './asset-hydration-F6aM5C7x.cjs';
4
4
  export { H as HydratedSceneItemsWithAssetsResult, h as hydrateSceneItemsWithAssets } from './asset-hydration-F6aM5C7x.cjs';
5
5
  import { V as VectorViewportAssetKind, a as VectorViewportAssetStore } from './asset-store-35ysK28r.cjs';
6
6
  export { b as VectorViewportAssetHydrationRequest, c as VectorViewportAssetResolveRequest, d as VectorViewportAssetResolveResult, e as VectorViewportAssetUploadRequest, f as VectorViewportAssetUploadResult } from './asset-store-35ysK28r.cjs';
7
- import { B as BoardComponentPosition, V as VectorToolDefinition, C as CustomShapePlacementOptions, a as CanvasPlugin, b as VectorSelectionInspector } from './types-uzeExFkd.cjs';
8
- export { c as CanvasPluginComponentProps, d as CanvasPluginContribution, e as CanvasPluginItemsChangeMiddlewareContext, f as CanvasPluginRenderContext, g as CanvuChromeActiveToolStyle, h as CanvuChromeContext, i as CanvuChromeContextValue, j as CanvuChromeSelectionStyleChange, k as CanvuPluginContext, l as CanvuPluginContextValue, m as CanvuPluginViewportSnapshot, P as PlacementPreview, S as SelectModeItemClickDetail, n as SelectModeItemClickResult, o as VectorCanvasSpacePosition, p as VectorSelectionInspectorProps, q as VectorViewport, r as VectorViewportHandle, s as VectorViewportProps, W as WorldPointerDownDetail, t as createCanvuPlugin, u as getBoardPositionStyle, v as useCanvuChromeContext, w as useCanvuDocumentContext, x as useCanvuPluginContext, y as useCanvuPluginContribution, z as useCanvuResolvedTools, A as useCanvuViewportContext } from './types-uzeExFkd.cjs';
7
+ import { B as BoardComponentPosition, V as VectorToolDefinition, C as CustomShapePlacementOptions, a as CanvasPlugin, b as VectorSelectionInspector } from './types-BFZpRGyr.cjs';
8
+ export { c as CanvasPluginComponentProps, d as CanvasPluginContribution, e as CanvasPluginItemsChangeMiddlewareContext, f as CanvasPluginRenderContext, g as CanvuChromeActiveToolStyle, h as CanvuChromeContext, i as CanvuChromeContextValue, j as CanvuChromeSelectionStyleChange, k as CanvuPluginContext, l as CanvuPluginContextValue, m as CanvuPluginViewportSnapshot, P as PlacementPreview, S as SelectModeItemClickDetail, n as SelectModeItemClickResult, o as VectorCanvasSpacePosition, p as VectorSelectionInspectorProps, q as VectorViewport, r as VectorViewportHandle, s as VectorViewportProps, W as WorldPointerDownDetail, t as createCanvuPlugin, u as getBoardPositionStyle, v as useCanvuChromeContext, w as useCanvuDocumentContext, x as useCanvuPluginContext, y as useCanvuPluginContribution, z as useCanvuResolvedTools, A as useCanvuViewportContext } from './types-BFZpRGyr.cjs';
9
9
  import * as react_jsx_runtime from 'react/jsx-runtime';
10
10
  import * as react from 'react';
11
11
  import { CSSProperties, ReactNode, ReactElement, SVGProps } from 'react';
12
- import { C as Camera2D } from './shape-builders-BmLS8CNh.cjs';
12
+ import { C as Camera2D } from './shape-builders-DzhCOuzo.cjs';
13
13
  import { V as VectorCanvasPersistenceAdapter, a as VectorCanvasRemoteAdapter } from './types-6HszqSa5.cjs';
14
14
  export { b as VectorCanvasSnapshot } from './types-6HszqSa5.cjs';
15
15
  import './link-item-BMV3VUCr.cjs';
16
- import './types-BOQLWyCw.cjs';
16
+ import './types-DqsqQQVf.cjs';
17
17
 
18
18
  /**
19
19
  * Extra context for each item created by {@link ingestAssetFilesToSceneItems}.
package/dist/react.d.ts CHANGED
@@ -4,16 +4,16 @@ import { I as IndexedDbImageStore } from './asset-hydration-BSjiek7Q.js';
4
4
  export { H as HydratedSceneItemsWithAssetsResult, h as hydrateSceneItemsWithAssets } from './asset-hydration-BSjiek7Q.js';
5
5
  import { V as VectorViewportAssetKind, a as VectorViewportAssetStore } from './asset-store-D_FjW_CN.js';
6
6
  export { b as VectorViewportAssetHydrationRequest, c as VectorViewportAssetResolveRequest, d as VectorViewportAssetResolveResult, e as VectorViewportAssetUploadRequest, f as VectorViewportAssetUploadResult } from './asset-store-D_FjW_CN.js';
7
- import { B as BoardComponentPosition, V as VectorToolDefinition, C as CustomShapePlacementOptions, a as CanvasPlugin, b as VectorSelectionInspector } from './types-BAEHaIYO.js';
8
- export { c as CanvasPluginComponentProps, d as CanvasPluginContribution, e as CanvasPluginItemsChangeMiddlewareContext, f as CanvasPluginRenderContext, g as CanvuChromeActiveToolStyle, h as CanvuChromeContext, i as CanvuChromeContextValue, j as CanvuChromeSelectionStyleChange, k as CanvuPluginContext, l as CanvuPluginContextValue, m as CanvuPluginViewportSnapshot, P as PlacementPreview, S as SelectModeItemClickDetail, n as SelectModeItemClickResult, o as VectorCanvasSpacePosition, p as VectorSelectionInspectorProps, q as VectorViewport, r as VectorViewportHandle, s as VectorViewportProps, W as WorldPointerDownDetail, t as createCanvuPlugin, u as getBoardPositionStyle, v as useCanvuChromeContext, w as useCanvuDocumentContext, x as useCanvuPluginContext, y as useCanvuPluginContribution, z as useCanvuResolvedTools, A as useCanvuViewportContext } from './types-BAEHaIYO.js';
7
+ import { B as BoardComponentPosition, V as VectorToolDefinition, C as CustomShapePlacementOptions, a as CanvasPlugin, b as VectorSelectionInspector } from './types-D2zesNI8.js';
8
+ export { c as CanvasPluginComponentProps, d as CanvasPluginContribution, e as CanvasPluginItemsChangeMiddlewareContext, f as CanvasPluginRenderContext, g as CanvuChromeActiveToolStyle, h as CanvuChromeContext, i as CanvuChromeContextValue, j as CanvuChromeSelectionStyleChange, k as CanvuPluginContext, l as CanvuPluginContextValue, m as CanvuPluginViewportSnapshot, P as PlacementPreview, S as SelectModeItemClickDetail, n as SelectModeItemClickResult, o as VectorCanvasSpacePosition, p as VectorSelectionInspectorProps, q as VectorViewport, r as VectorViewportHandle, s as VectorViewportProps, W as WorldPointerDownDetail, t as createCanvuPlugin, u as getBoardPositionStyle, v as useCanvuChromeContext, w as useCanvuDocumentContext, x as useCanvuPluginContext, y as useCanvuPluginContribution, z as useCanvuResolvedTools, A as useCanvuViewportContext } from './types-D2zesNI8.js';
9
9
  import * as react_jsx_runtime from 'react/jsx-runtime';
10
10
  import * as react from 'react';
11
11
  import { CSSProperties, ReactNode, ReactElement, SVGProps } from 'react';
12
- import { C as Camera2D } from './shape-builders-BCOAG0pS.js';
12
+ import { C as Camera2D } from './shape-builders-xG3A66sv.js';
13
13
  import { V as VectorCanvasPersistenceAdapter, a as VectorCanvasRemoteAdapter } from './types-BtWbGOqh.js';
14
14
  export { b as VectorCanvasSnapshot } from './types-BtWbGOqh.js';
15
15
  import './link-item-COoNNvCu.js';
16
- import './types-BMMPUak7.js';
16
+ import './types-BXa2CIrc.js';
17
17
 
18
18
  /**
19
19
  * Extra context for each item created by {@link ingestAssetFilesToSceneItems}.
package/dist/react.js CHANGED
@@ -446,198 +446,6 @@ function svgNumber(value) {
446
446
  const rounded = Math.round(value * 100) / 100;
447
447
  return Number.isInteger(rounded) ? String(rounded) : String(rounded);
448
448
  }
449
- function architecturalCloudCenterCount(edgeLength, radius) {
450
- const targetSpacing = Math.min(
451
- ARCHITECTURAL_CLOUD_TARGET_SPACING,
452
- Math.max(1, radius * 1.3)
453
- );
454
- return Math.max(2, Math.round(edgeLength / targetSpacing) + 1);
455
- }
456
- function distributeRange(start, end, count) {
457
- if (count <= 1) return [start];
458
- const step = (end - start) / (count - 1);
459
- return Array.from({ length: count }, (_, index) => start + step * index);
460
- }
461
- function lineCloudPathSegment(start, end) {
462
- const dx = end[0] - start[0];
463
- const dy = end[1] - start[1];
464
- const length = Math.hypot(dx, dy);
465
- return {
466
- length,
467
- pointAt: (t) => [start[0] + dx * t, start[1] + dy * t]
468
- };
469
- }
470
- function ellipsePoint(centerX, centerY, radiusX, radiusY, angle) {
471
- return [centerX + Math.cos(angle) * radiusX, centerY + Math.sin(angle) * radiusY];
472
- }
473
- function approximateEllipseArcLength(radiusX, radiusY, startAngle, endAngle) {
474
- const steps = Math.max(
475
- 4,
476
- Math.ceil(Math.abs(endAngle - startAngle) / (Math.PI / 16))
477
- );
478
- let length = 0;
479
- let previous = ellipsePoint(0, 0, radiusX, radiusY, startAngle);
480
- for (let index = 1; index <= steps; index += 1) {
481
- const angle = startAngle + (endAngle - startAngle) * index / steps;
482
- const next = ellipsePoint(0, 0, radiusX, radiusY, angle);
483
- length += Math.hypot(next[0] - previous[0], next[1] - previous[1]);
484
- previous = next;
485
- }
486
- return length;
487
- }
488
- function ellipseCloudPathSegment(centerX, centerY, radiusX, radiusY, startAngle, endAngle) {
489
- return {
490
- length: approximateEllipseArcLength(radiusX, radiusY, startAngle, endAngle),
491
- pointAt: (t) => ellipsePoint(
492
- centerX,
493
- centerY,
494
- radiusX,
495
- radiusY,
496
- startAngle + (endAngle - startAngle) * t
497
- )
498
- };
499
- }
500
- function cloudPathPerimeter(segments) {
501
- const usableSegments = segments.filter((segment) => segment.length > 1e-9);
502
- return usableSegments.reduce((sum, segment) => sum + segment.length, 0);
503
- }
504
- function pointOnCloudPath(segments, distance) {
505
- const perimeter = cloudPathPerimeter(segments);
506
- if (perimeter <= 0) return [0, 0];
507
- let remaining = (distance % perimeter + perimeter) % perimeter;
508
- for (const segment of segments) {
509
- if (segment.length <= 1e-9) continue;
510
- if (remaining <= segment.length) {
511
- const t = remaining / segment.length;
512
- return segment.pointAt(t);
513
- }
514
- remaining -= segment.length;
515
- }
516
- const fallback = segments.find((segment) => segment.length > 1e-9);
517
- return fallback?.pointAt(0) ?? [0, 0];
518
- }
519
- function buildRoundedCapsulePathSegments(width, height, inset) {
520
- const left = inset;
521
- const top = inset;
522
- const right = width - inset;
523
- const bottom = height - inset;
524
- const capsuleWidth = Math.max(0, right - left);
525
- const capsuleHeight = Math.max(0, bottom - top);
526
- const radius = Math.min(capsuleWidth, capsuleHeight) / 2;
527
- if (radius <= 0) return [];
528
- const leftCenterX = left + radius;
529
- const rightCenterX = right - radius;
530
- const topCenterY = top + radius;
531
- const bottomCenterY = bottom - radius;
532
- return [
533
- lineCloudPathSegment([leftCenterX, top], [rightCenterX, top]),
534
- ellipseCloudPathSegment(
535
- rightCenterX,
536
- topCenterY,
537
- radius,
538
- radius,
539
- -Math.PI / 2,
540
- 0
541
- ),
542
- lineCloudPathSegment([right, topCenterY], [right, bottomCenterY]),
543
- ellipseCloudPathSegment(
544
- rightCenterX,
545
- bottomCenterY,
546
- radius,
547
- radius,
548
- 0,
549
- Math.PI / 2
550
- ),
551
- lineCloudPathSegment([rightCenterX, bottom], [leftCenterX, bottom]),
552
- ellipseCloudPathSegment(
553
- leftCenterX,
554
- bottomCenterY,
555
- radius,
556
- radius,
557
- Math.PI / 2,
558
- Math.PI
559
- ),
560
- lineCloudPathSegment([left, bottomCenterY], [left, topCenterY]),
561
- ellipseCloudPathSegment(
562
- leftCenterX,
563
- topCenterY,
564
- radius,
565
- radius,
566
- Math.PI,
567
- Math.PI * 1.5
568
- )
569
- ];
570
- }
571
- function buildRoundedArcCloudPathD(cloudWidth, cloudHeight, center) {
572
- const minDimension = Math.min(cloudWidth, cloudHeight);
573
- const radius = Math.min(
574
- ARCHITECTURAL_CLOUD_ROUNDED_RADIUS,
575
- Math.max(ARCHITECTURAL_CLOUD_ROUNDED_MIN_RADIUS, minDimension * 0.16)
576
- );
577
- const centerPath = buildRoundedCapsulePathSegments(
578
- cloudWidth,
579
- cloudHeight,
580
- radius
581
- );
582
- const centerPerimeter = cloudPathPerimeter(centerPath);
583
- if (centerPerimeter <= 0) return "";
584
- const lobeCount = Math.max(
585
- 8,
586
- Math.round(centerPerimeter / ARCHITECTURAL_CLOUD_ROUNDED_TARGET_SPACING)
587
- );
588
- const centers = Array.from(
589
- { length: lobeCount },
590
- (_, index) => pointOnCloudPath(centerPath, centerPerimeter * index / lobeCount)
591
- );
592
- const points = centers.map((point, index) => {
593
- const previous = centers[(index - 1 + centers.length) % centers.length] ?? point;
594
- return cloudCircleIntersection(previous, point, radius, center);
595
- });
596
- const [startX, startY] = points[0] ?? [0, 0];
597
- const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
598
- for (const [endX, endY] of points.slice(1)) {
599
- segments.push(
600
- `A ${svgNumber(radius)} ${svgNumber(radius)} 0 0 1 ${svgNumber(endX)} ${svgNumber(endY)}`
601
- );
602
- }
603
- segments.push(
604
- `A ${svgNumber(radius)} ${svgNumber(radius)} 0 0 1 ${svgNumber(startX)} ${svgNumber(startY)}`
605
- );
606
- segments.push("Z");
607
- return segments.join(" ");
608
- }
609
- function cloudCircleIntersection(a, b, radius, center) {
610
- const midX = (a[0] + b[0]) / 2;
611
- const midY = (a[1] + b[1]) / 2;
612
- const dx = b[0] - a[0];
613
- const dy = b[1] - a[1];
614
- const distance = Math.hypot(dx, dy);
615
- if (distance <= 1e-9) return [midX, midY];
616
- const halfDistance = distance / 2;
617
- const offset = Math.sqrt(
618
- Math.max(0, radius * radius - halfDistance * halfDistance)
619
- );
620
- const normalX = -dy / distance;
621
- const normalY = dx / distance;
622
- const first = [midX + normalX * offset, midY + normalY * offset];
623
- const second = [
624
- midX - normalX * offset,
625
- midY - normalY * offset
626
- ];
627
- const firstDistance = (first[0] - center[0]) * (first[0] - center[0]) + (first[1] - center[1]) * (first[1] - center[1]);
628
- const secondDistance = (second[0] - center[0]) * (second[0] - center[0]) + (second[1] - center[1]) * (second[1] - center[1]);
629
- return firstDistance >= secondDistance ? first : second;
630
- }
631
- function cloudEllipseIntersection(a, b, radiusX, radiusY, center) {
632
- const scaleY = radiusX / radiusY;
633
- const [x, y] = cloudCircleIntersection(
634
- [a[0], a[1] * scaleY],
635
- [b[0], b[1] * scaleY],
636
- radiusX,
637
- [center[0], center[1] * scaleY]
638
- );
639
- return [x, y / scaleY];
640
- }
641
449
  function buildRectSvg(width, height, style = DEFAULT_STROKE_STYLE) {
642
450
  return `<rect width="${width}" height="${height}" fill="none" stroke="${style.stroke}" stroke-width="${style.strokeWidth}" rx="4"${strokeOpacityAttr(style)} />`;
643
451
  }
@@ -646,67 +454,42 @@ function buildEllipseSvg(width, height, style = DEFAULT_STROKE_STYLE) {
646
454
  const ry = height / 2;
647
455
  return `<ellipse cx="${rx}" cy="${ry}" rx="${rx}" ry="${ry}" fill="none" stroke="${style.stroke}" stroke-width="${style.strokeWidth}"${strokeOpacityAttr(style)} />`;
648
456
  }
649
- function buildArchitecturalCloudPathD(width, height, strokeWidth = DEFAULT_STROKE_STYLE.strokeWidth) {
650
- const w = Math.max(0, width);
651
- const h = Math.max(0, height);
652
- if (w <= 0 || h <= 0) return "";
457
+ function buildArchitecturalCloudPathD(width, height, strokeWidth = DEFAULT_STROKE_STYLE.strokeWidth, arcRadius = ARCHITECTURAL_CLOUD_RADIUS, bulge = 1) {
653
458
  const padding = Math.max(0, strokeWidth * 2);
654
- const cloudWidth = Math.max(0, w - padding);
655
- const cloudHeight = Math.max(0, h - padding);
656
- if (cloudWidth <= 0 || cloudHeight <= 0) return "";
657
- const radiusX = Math.min(
658
- ARCHITECTURAL_CLOUD_RADIUS,
659
- cloudWidth * ARCHITECTURAL_CLOUD_FLAT_RADIUS_RATIO
660
- );
661
- const radiusY = Math.min(
662
- ARCHITECTURAL_CLOUD_RADIUS,
663
- cloudHeight * ARCHITECTURAL_CLOUD_FLAT_RADIUS_RATIO
664
- );
665
- if (radiusX <= 0 || radiusY <= 0) return "";
666
- const center = [cloudWidth / 2, cloudHeight / 2];
667
- const leftCenterX = radiusX;
668
- const rightCenterX = cloudWidth - radiusX;
669
- const topCenterY = radiusY;
670
- const bottomCenterY = cloudHeight - radiusY;
671
- const horizontalCenters = distributeRange(
672
- leftCenterX,
673
- rightCenterX,
674
- architecturalCloudCenterCount(Math.max(0, rightCenterX - leftCenterX), radiusX)
675
- );
676
- const verticalCenters = distributeRange(
677
- topCenterY,
678
- bottomCenterY,
679
- architecturalCloudCenterCount(Math.max(0, bottomCenterY - topCenterY), radiusY)
680
- );
681
- if (horizontalCenters.length > 3 && verticalCenters.length > 3) {
682
- const roundedArcCloudPath = buildRoundedArcCloudPathD(
683
- cloudWidth,
684
- cloudHeight,
685
- center
686
- );
687
- if (roundedArcCloudPath !== "") return roundedArcCloudPath;
688
- }
689
- const rectangularCenters = [
690
- ...horizontalCenters.map((x) => [x, topCenterY]),
691
- ...verticalCenters.slice(1).map((y) => [rightCenterX, y]),
692
- ...horizontalCenters.slice(0, -1).reverse().map((x) => [x, bottomCenterY]),
693
- ...verticalCenters.slice(1, -1).reverse().map((y) => [leftCenterX, y])
459
+ const cloudWidth = Math.max(0, width - padding);
460
+ const cloudHeight = Math.max(0, height - padding);
461
+ if (cloudWidth <= 0 || cloudHeight <= 0 || arcRadius <= 0 || bulge <= 0) return "";
462
+ const offset = padding / 2;
463
+ const corners = [
464
+ [offset, offset],
465
+ [offset + cloudWidth, offset],
466
+ [offset + cloudWidth, offset + cloudHeight],
467
+ [offset, offset + cloudHeight]
694
468
  ];
695
- const centers = rectangularCenters;
696
- const points = centers.map((point, index) => {
697
- const previous = centers[(index - 1 + centers.length) % centers.length] ?? point;
698
- return cloudEllipseIntersection(previous, point, radiusX, radiusY, center);
699
- });
700
- const [startX, startY] = points[0] ?? [0, 0];
469
+ const points = [];
470
+ for (let index = 0; index < corners.length; index += 1) {
471
+ const [startX2, startY2] = corners[index] ?? [0, 0];
472
+ const [endX, endY] = corners[(index + 1) % corners.length] ?? [0, 0];
473
+ const edgeLength = Math.hypot(endX - startX2, endY - startY2);
474
+ const arcCount = Math.max(1, Math.round(edgeLength / (2 * arcRadius)));
475
+ const chord = edgeLength / arcCount;
476
+ for (let arcIndex = 1; arcIndex <= arcCount; arcIndex += 1) {
477
+ const t = arcIndex / arcCount;
478
+ points.push([
479
+ startX2 + (endX - startX2) * t,
480
+ startY2 + (endY - startY2) * t,
481
+ chord
482
+ ]);
483
+ }
484
+ }
485
+ const [startX, startY] = corners[0] ?? [0, 0];
701
486
  const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
702
- for (const [endX, endY] of points.slice(1)) {
487
+ for (const [pointX, pointY, chord] of points) {
488
+ const radius = chord / 2 * bulge;
703
489
  segments.push(
704
- `A ${svgNumber(radiusX)} ${svgNumber(radiusY)} 0 0 1 ${svgNumber(endX)} ${svgNumber(endY)}`
490
+ `A ${svgNumber(radius)} ${svgNumber(radius)} 0 0 1 ${svgNumber(pointX)} ${svgNumber(pointY)}`
705
491
  );
706
492
  }
707
- segments.push(
708
- `A ${svgNumber(radiusX)} ${svgNumber(radiusY)} 0 0 1 ${svgNumber(startX)} ${svgNumber(startY)}`
709
- );
710
493
  segments.push("Z");
711
494
  return segments.join(" ");
712
495
  }
@@ -1186,7 +969,7 @@ function createImageFromVectorTrace(id, bounds, imageVectorInnerSvg, imageVector
1186
969
  childrenSvg
1187
970
  };
1188
971
  }
1189
- 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;
972
+ var DEFAULT_STROKE_STYLE, TOOL_FREEHAND_DEFAULTS, ARCHITECTURAL_CLOUD_RADIUS;
1190
973
  var init_shape_builders = __esm({
1191
974
  "src/scene/shape-builders.ts"() {
1192
975
  init_rect();
@@ -1204,11 +987,6 @@ var init_shape_builders = __esm({
1204
987
  marker: { stroke: "#fde047", strokeWidth: 16, strokeOpacity: 0.5 }
1205
988
  };
1206
989
  ARCHITECTURAL_CLOUD_RADIUS = 38;
1207
- ARCHITECTURAL_CLOUD_TARGET_SPACING = 50;
1208
- ARCHITECTURAL_CLOUD_FLAT_RADIUS_RATIO = 0.38;
1209
- ARCHITECTURAL_CLOUD_ROUNDED_RADIUS = 72;
1210
- ARCHITECTURAL_CLOUD_ROUNDED_MIN_RADIUS = 44;
1211
- ARCHITECTURAL_CLOUD_ROUNDED_TARGET_SPACING = 98;
1212
990
  }
1213
991
  });
1214
992