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/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as Camera2D } from './shape-builders-BmLS8CNh.cjs';
2
- export { a as Camera2DOptions, D as DEFAULT_STROKE_STYLE, F as FreehandSvgPayload, S as StrokeStyle, b as applyStrokeToItem, c as buildArchitecturalCloudPathD, d as buildArchitecturalCloudSvg, e as buildArrowSvg, f as buildDrawDotSvg, g as buildEllipseSvg, h as buildFreehandPathSvg, i as buildLineSvg, j as buildRectSvg, k as computeFreehandSvgPayload, l as createArchitecturalCloudItem, m as createDrawDotItem, n as createEllipseItem, o as createFreehandStrokeItem, p as createImageFromVectorTrace, q as createImageItem, r as createLineItem, s as createRectangleItem, t as createShapeId, u as createTextItem, v as lineEndpointsToLocal, w as rebuildItemSvg, x as resolveStrokeStyle } from './shape-builders-BmLS8CNh.cjs';
1
+ import { C as Camera2D } from './shape-builders-DzhCOuzo.cjs';
2
+ export { a as Camera2DOptions, D as DEFAULT_STROKE_STYLE, F as FreehandSvgPayload, S as StrokeStyle, b as applyStrokeToItem, c as buildArchitecturalCloudPathD, d as buildArchitecturalCloudSvg, e as buildArrowSvg, f as buildDrawDotSvg, g as buildEllipseSvg, h as buildFreehandPathSvg, i as buildLineSvg, j as buildRectSvg, k as computeFreehandSvgPayload, l as createArchitecturalCloudItem, m as createDrawDotItem, n as createEllipseItem, o as createFreehandStrokeItem, p as createImageFromVectorTrace, q as createImageItem, r as createLineItem, s as createRectangleItem, t as createShapeId, u as createTextItem, v as lineEndpointsToLocal, w as rebuildItemSvg, x as resolveStrokeStyle } from './shape-builders-DzhCOuzo.cjs';
3
3
  import { V as VectorSceneItem, A as ArrowEndpointBinding, C as CustomShapeResizeHandles, R as Rect } from './types-fJNwEnHf.cjs';
4
4
  export { a as ArrowBindings, b as ResizeHandleId, c as VectorPathPoint, n as normalizeRect, r as rectsIntersect } from './types-fJNwEnHf.cjs';
5
5
  export { H as HydratedSceneItemsWithAssetsResult, h as hydrateSceneItemsWithAssets } from './asset-hydration-F6aM5C7x.cjs';
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as Camera2D } from './shape-builders-BCOAG0pS.js';
2
- export { a as Camera2DOptions, D as DEFAULT_STROKE_STYLE, F as FreehandSvgPayload, S as StrokeStyle, b as applyStrokeToItem, c as buildArchitecturalCloudPathD, d as buildArchitecturalCloudSvg, e as buildArrowSvg, f as buildDrawDotSvg, g as buildEllipseSvg, h as buildFreehandPathSvg, i as buildLineSvg, j as buildRectSvg, k as computeFreehandSvgPayload, l as createArchitecturalCloudItem, m as createDrawDotItem, n as createEllipseItem, o as createFreehandStrokeItem, p as createImageFromVectorTrace, q as createImageItem, r as createLineItem, s as createRectangleItem, t as createShapeId, u as createTextItem, v as lineEndpointsToLocal, w as rebuildItemSvg, x as resolveStrokeStyle } from './shape-builders-BCOAG0pS.js';
1
+ import { C as Camera2D } from './shape-builders-xG3A66sv.js';
2
+ export { a as Camera2DOptions, D as DEFAULT_STROKE_STYLE, F as FreehandSvgPayload, S as StrokeStyle, b as applyStrokeToItem, c as buildArchitecturalCloudPathD, d as buildArchitecturalCloudSvg, e as buildArrowSvg, f as buildDrawDotSvg, g as buildEllipseSvg, h as buildFreehandPathSvg, i as buildLineSvg, j as buildRectSvg, k as computeFreehandSvgPayload, l as createArchitecturalCloudItem, m as createDrawDotItem, n as createEllipseItem, o as createFreehandStrokeItem, p as createImageFromVectorTrace, q as createImageItem, r as createLineItem, s as createRectangleItem, t as createShapeId, u as createTextItem, v as lineEndpointsToLocal, w as rebuildItemSvg, x as resolveStrokeStyle } from './shape-builders-xG3A66sv.js';
3
3
  import { V as VectorSceneItem, A as ArrowEndpointBinding, C as CustomShapeResizeHandles, R as Rect } from './types-fJNwEnHf.js';
4
4
  export { a as ArrowBindings, b as ResizeHandleId, c as VectorPathPoint, n as normalizeRect, r as rectsIntersect } from './types-fJNwEnHf.js';
5
5
  export { H as HydratedSceneItemsWithAssetsResult, h as hydrateSceneItemsWithAssets } from './asset-hydration-BSjiek7Q.js';
package/dist/index.js CHANGED
@@ -1342,203 +1342,6 @@ function svgNumber(value) {
1342
1342
  return Number.isInteger(rounded) ? String(rounded) : String(rounded);
1343
1343
  }
1344
1344
  var ARCHITECTURAL_CLOUD_RADIUS = 38;
1345
- var ARCHITECTURAL_CLOUD_TARGET_SPACING = 50;
1346
- var ARCHITECTURAL_CLOUD_FLAT_RADIUS_RATIO = 0.38;
1347
- var ARCHITECTURAL_CLOUD_ROUNDED_RADIUS = 72;
1348
- var ARCHITECTURAL_CLOUD_ROUNDED_MIN_RADIUS = 44;
1349
- var ARCHITECTURAL_CLOUD_ROUNDED_TARGET_SPACING = 98;
1350
- function architecturalCloudCenterCount(edgeLength, radius) {
1351
- const targetSpacing = Math.min(
1352
- ARCHITECTURAL_CLOUD_TARGET_SPACING,
1353
- Math.max(1, radius * 1.3)
1354
- );
1355
- return Math.max(2, Math.round(edgeLength / targetSpacing) + 1);
1356
- }
1357
- function distributeRange(start, end, count) {
1358
- if (count <= 1) return [start];
1359
- const step = (end - start) / (count - 1);
1360
- return Array.from({ length: count }, (_, index) => start + step * index);
1361
- }
1362
- function lineCloudPathSegment(start, end) {
1363
- const dx = end[0] - start[0];
1364
- const dy = end[1] - start[1];
1365
- const length = Math.hypot(dx, dy);
1366
- return {
1367
- length,
1368
- pointAt: (t) => [start[0] + dx * t, start[1] + dy * t]
1369
- };
1370
- }
1371
- function ellipsePoint(centerX, centerY, radiusX, radiusY, angle) {
1372
- return [centerX + Math.cos(angle) * radiusX, centerY + Math.sin(angle) * radiusY];
1373
- }
1374
- function approximateEllipseArcLength(radiusX, radiusY, startAngle, endAngle) {
1375
- const steps = Math.max(
1376
- 4,
1377
- Math.ceil(Math.abs(endAngle - startAngle) / (Math.PI / 16))
1378
- );
1379
- let length = 0;
1380
- let previous = ellipsePoint(0, 0, radiusX, radiusY, startAngle);
1381
- for (let index = 1; index <= steps; index += 1) {
1382
- const angle = startAngle + (endAngle - startAngle) * index / steps;
1383
- const next = ellipsePoint(0, 0, radiusX, radiusY, angle);
1384
- length += Math.hypot(next[0] - previous[0], next[1] - previous[1]);
1385
- previous = next;
1386
- }
1387
- return length;
1388
- }
1389
- function ellipseCloudPathSegment(centerX, centerY, radiusX, radiusY, startAngle, endAngle) {
1390
- return {
1391
- length: approximateEllipseArcLength(radiusX, radiusY, startAngle, endAngle),
1392
- pointAt: (t) => ellipsePoint(
1393
- centerX,
1394
- centerY,
1395
- radiusX,
1396
- radiusY,
1397
- startAngle + (endAngle - startAngle) * t
1398
- )
1399
- };
1400
- }
1401
- function cloudPathPerimeter(segments) {
1402
- const usableSegments = segments.filter((segment) => segment.length > 1e-9);
1403
- return usableSegments.reduce((sum, segment) => sum + segment.length, 0);
1404
- }
1405
- function pointOnCloudPath(segments, distance) {
1406
- const perimeter = cloudPathPerimeter(segments);
1407
- if (perimeter <= 0) return [0, 0];
1408
- let remaining = (distance % perimeter + perimeter) % perimeter;
1409
- for (const segment of segments) {
1410
- if (segment.length <= 1e-9) continue;
1411
- if (remaining <= segment.length) {
1412
- const t = remaining / segment.length;
1413
- return segment.pointAt(t);
1414
- }
1415
- remaining -= segment.length;
1416
- }
1417
- const fallback = segments.find((segment) => segment.length > 1e-9);
1418
- return fallback?.pointAt(0) ?? [0, 0];
1419
- }
1420
- function buildRoundedCapsulePathSegments(width, height, inset) {
1421
- const left = inset;
1422
- const top = inset;
1423
- const right = width - inset;
1424
- const bottom = height - inset;
1425
- const capsuleWidth = Math.max(0, right - left);
1426
- const capsuleHeight = Math.max(0, bottom - top);
1427
- const radius = Math.min(capsuleWidth, capsuleHeight) / 2;
1428
- if (radius <= 0) return [];
1429
- const leftCenterX = left + radius;
1430
- const rightCenterX = right - radius;
1431
- const topCenterY = top + radius;
1432
- const bottomCenterY = bottom - radius;
1433
- return [
1434
- lineCloudPathSegment([leftCenterX, top], [rightCenterX, top]),
1435
- ellipseCloudPathSegment(
1436
- rightCenterX,
1437
- topCenterY,
1438
- radius,
1439
- radius,
1440
- -Math.PI / 2,
1441
- 0
1442
- ),
1443
- lineCloudPathSegment([right, topCenterY], [right, bottomCenterY]),
1444
- ellipseCloudPathSegment(
1445
- rightCenterX,
1446
- bottomCenterY,
1447
- radius,
1448
- radius,
1449
- 0,
1450
- Math.PI / 2
1451
- ),
1452
- lineCloudPathSegment([rightCenterX, bottom], [leftCenterX, bottom]),
1453
- ellipseCloudPathSegment(
1454
- leftCenterX,
1455
- bottomCenterY,
1456
- radius,
1457
- radius,
1458
- Math.PI / 2,
1459
- Math.PI
1460
- ),
1461
- lineCloudPathSegment([left, bottomCenterY], [left, topCenterY]),
1462
- ellipseCloudPathSegment(
1463
- leftCenterX,
1464
- topCenterY,
1465
- radius,
1466
- radius,
1467
- Math.PI,
1468
- Math.PI * 1.5
1469
- )
1470
- ];
1471
- }
1472
- function buildRoundedArcCloudPathD(cloudWidth, cloudHeight, center) {
1473
- const minDimension = Math.min(cloudWidth, cloudHeight);
1474
- const radius = Math.min(
1475
- ARCHITECTURAL_CLOUD_ROUNDED_RADIUS,
1476
- Math.max(ARCHITECTURAL_CLOUD_ROUNDED_MIN_RADIUS, minDimension * 0.16)
1477
- );
1478
- const centerPath = buildRoundedCapsulePathSegments(
1479
- cloudWidth,
1480
- cloudHeight,
1481
- radius
1482
- );
1483
- const centerPerimeter = cloudPathPerimeter(centerPath);
1484
- if (centerPerimeter <= 0) return "";
1485
- const lobeCount = Math.max(
1486
- 8,
1487
- Math.round(centerPerimeter / ARCHITECTURAL_CLOUD_ROUNDED_TARGET_SPACING)
1488
- );
1489
- const centers = Array.from(
1490
- { length: lobeCount },
1491
- (_, index) => pointOnCloudPath(centerPath, centerPerimeter * index / lobeCount)
1492
- );
1493
- const points = centers.map((point, index) => {
1494
- const previous = centers[(index - 1 + centers.length) % centers.length] ?? point;
1495
- return cloudCircleIntersection(previous, point, radius, center);
1496
- });
1497
- const [startX, startY] = points[0] ?? [0, 0];
1498
- const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
1499
- for (const [endX, endY] of points.slice(1)) {
1500
- segments.push(
1501
- `A ${svgNumber(radius)} ${svgNumber(radius)} 0 0 1 ${svgNumber(endX)} ${svgNumber(endY)}`
1502
- );
1503
- }
1504
- segments.push(
1505
- `A ${svgNumber(radius)} ${svgNumber(radius)} 0 0 1 ${svgNumber(startX)} ${svgNumber(startY)}`
1506
- );
1507
- segments.push("Z");
1508
- return segments.join(" ");
1509
- }
1510
- function cloudCircleIntersection(a, b, radius, center) {
1511
- const midX = (a[0] + b[0]) / 2;
1512
- const midY = (a[1] + b[1]) / 2;
1513
- const dx = b[0] - a[0];
1514
- const dy = b[1] - a[1];
1515
- const distance = Math.hypot(dx, dy);
1516
- if (distance <= 1e-9) return [midX, midY];
1517
- const halfDistance = distance / 2;
1518
- const offset = Math.sqrt(
1519
- Math.max(0, radius * radius - halfDistance * halfDistance)
1520
- );
1521
- const normalX = -dy / distance;
1522
- const normalY = dx / distance;
1523
- const first = [midX + normalX * offset, midY + normalY * offset];
1524
- const second = [
1525
- midX - normalX * offset,
1526
- midY - normalY * offset
1527
- ];
1528
- const firstDistance = (first[0] - center[0]) * (first[0] - center[0]) + (first[1] - center[1]) * (first[1] - center[1]);
1529
- const secondDistance = (second[0] - center[0]) * (second[0] - center[0]) + (second[1] - center[1]) * (second[1] - center[1]);
1530
- return firstDistance >= secondDistance ? first : second;
1531
- }
1532
- function cloudEllipseIntersection(a, b, radiusX, radiusY, center) {
1533
- const scaleY = radiusX / radiusY;
1534
- const [x, y] = cloudCircleIntersection(
1535
- [a[0], a[1] * scaleY],
1536
- [b[0], b[1] * scaleY],
1537
- radiusX,
1538
- [center[0], center[1] * scaleY]
1539
- );
1540
- return [x, y / scaleY];
1541
- }
1542
1345
  function buildRectSvg(width, height, style = DEFAULT_STROKE_STYLE) {
1543
1346
  return `<rect width="${width}" height="${height}" fill="none" stroke="${style.stroke}" stroke-width="${style.strokeWidth}" rx="4"${strokeOpacityAttr(style)} />`;
1544
1347
  }
@@ -1547,67 +1350,42 @@ function buildEllipseSvg(width, height, style = DEFAULT_STROKE_STYLE) {
1547
1350
  const ry = height / 2;
1548
1351
  return `<ellipse cx="${rx}" cy="${ry}" rx="${rx}" ry="${ry}" fill="none" stroke="${style.stroke}" stroke-width="${style.strokeWidth}"${strokeOpacityAttr(style)} />`;
1549
1352
  }
1550
- function buildArchitecturalCloudPathD(width, height, strokeWidth = DEFAULT_STROKE_STYLE.strokeWidth) {
1551
- const w = Math.max(0, width);
1552
- const h = Math.max(0, height);
1553
- if (w <= 0 || h <= 0) return "";
1353
+ function buildArchitecturalCloudPathD(width, height, strokeWidth = DEFAULT_STROKE_STYLE.strokeWidth, arcRadius = ARCHITECTURAL_CLOUD_RADIUS, bulge = 1) {
1554
1354
  const padding = Math.max(0, strokeWidth * 2);
1555
- const cloudWidth = Math.max(0, w - padding);
1556
- const cloudHeight = Math.max(0, h - padding);
1557
- if (cloudWidth <= 0 || cloudHeight <= 0) return "";
1558
- const radiusX = Math.min(
1559
- ARCHITECTURAL_CLOUD_RADIUS,
1560
- cloudWidth * ARCHITECTURAL_CLOUD_FLAT_RADIUS_RATIO
1561
- );
1562
- const radiusY = Math.min(
1563
- ARCHITECTURAL_CLOUD_RADIUS,
1564
- cloudHeight * ARCHITECTURAL_CLOUD_FLAT_RADIUS_RATIO
1565
- );
1566
- if (radiusX <= 0 || radiusY <= 0) return "";
1567
- const center = [cloudWidth / 2, cloudHeight / 2];
1568
- const leftCenterX = radiusX;
1569
- const rightCenterX = cloudWidth - radiusX;
1570
- const topCenterY = radiusY;
1571
- const bottomCenterY = cloudHeight - radiusY;
1572
- const horizontalCenters = distributeRange(
1573
- leftCenterX,
1574
- rightCenterX,
1575
- architecturalCloudCenterCount(Math.max(0, rightCenterX - leftCenterX), radiusX)
1576
- );
1577
- const verticalCenters = distributeRange(
1578
- topCenterY,
1579
- bottomCenterY,
1580
- architecturalCloudCenterCount(Math.max(0, bottomCenterY - topCenterY), radiusY)
1581
- );
1582
- if (horizontalCenters.length > 3 && verticalCenters.length > 3) {
1583
- const roundedArcCloudPath = buildRoundedArcCloudPathD(
1584
- cloudWidth,
1585
- cloudHeight,
1586
- center
1587
- );
1588
- if (roundedArcCloudPath !== "") return roundedArcCloudPath;
1589
- }
1590
- const rectangularCenters = [
1591
- ...horizontalCenters.map((x) => [x, topCenterY]),
1592
- ...verticalCenters.slice(1).map((y) => [rightCenterX, y]),
1593
- ...horizontalCenters.slice(0, -1).reverse().map((x) => [x, bottomCenterY]),
1594
- ...verticalCenters.slice(1, -1).reverse().map((y) => [leftCenterX, y])
1355
+ const cloudWidth = Math.max(0, width - padding);
1356
+ const cloudHeight = Math.max(0, height - padding);
1357
+ if (cloudWidth <= 0 || cloudHeight <= 0 || arcRadius <= 0 || bulge <= 0) return "";
1358
+ const offset = padding / 2;
1359
+ const corners = [
1360
+ [offset, offset],
1361
+ [offset + cloudWidth, offset],
1362
+ [offset + cloudWidth, offset + cloudHeight],
1363
+ [offset, offset + cloudHeight]
1595
1364
  ];
1596
- const centers = rectangularCenters;
1597
- const points = centers.map((point, index) => {
1598
- const previous = centers[(index - 1 + centers.length) % centers.length] ?? point;
1599
- return cloudEllipseIntersection(previous, point, radiusX, radiusY, center);
1600
- });
1601
- const [startX, startY] = points[0] ?? [0, 0];
1365
+ const points = [];
1366
+ for (let index = 0; index < corners.length; index += 1) {
1367
+ const [startX2, startY2] = corners[index] ?? [0, 0];
1368
+ const [endX, endY] = corners[(index + 1) % corners.length] ?? [0, 0];
1369
+ const edgeLength = Math.hypot(endX - startX2, endY - startY2);
1370
+ const arcCount = Math.max(1, Math.round(edgeLength / (2 * arcRadius)));
1371
+ const chord = edgeLength / arcCount;
1372
+ for (let arcIndex = 1; arcIndex <= arcCount; arcIndex += 1) {
1373
+ const t = arcIndex / arcCount;
1374
+ points.push([
1375
+ startX2 + (endX - startX2) * t,
1376
+ startY2 + (endY - startY2) * t,
1377
+ chord
1378
+ ]);
1379
+ }
1380
+ }
1381
+ const [startX, startY] = corners[0] ?? [0, 0];
1602
1382
  const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
1603
- for (const [endX, endY] of points.slice(1)) {
1383
+ for (const [pointX, pointY, chord] of points) {
1384
+ const radius = chord / 2 * bulge;
1604
1385
  segments.push(
1605
- `A ${svgNumber(radiusX)} ${svgNumber(radiusY)} 0 0 1 ${svgNumber(endX)} ${svgNumber(endY)}`
1386
+ `A ${svgNumber(radius)} ${svgNumber(radius)} 0 0 1 ${svgNumber(pointX)} ${svgNumber(pointY)}`
1606
1387
  );
1607
1388
  }
1608
- segments.push(
1609
- `A ${svgNumber(radiusX)} ${svgNumber(radiusY)} 0 0 1 ${svgNumber(startX)} ${svgNumber(startY)}`
1610
- );
1611
1389
  segments.push("Z");
1612
1390
  return segments.join(" ");
1613
1391
  }