canvu-react 0.3.32 → 0.3.34

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
@@ -291,25 +291,198 @@ function svgNumber(value) {
291
291
  const rounded = Math.round(value * 100) / 100;
292
292
  return Number.isInteger(rounded) ? String(rounded) : String(rounded);
293
293
  }
294
- function approximateEllipsePerimeter(rx, ry) {
295
- if (rx <= 0 || ry <= 0) return 0;
296
- return Math.PI * (3 * (rx + ry) - Math.sqrt((3 * rx + ry) * (rx + 3 * ry)));
297
- }
298
- function architecturalCloudScallopCount(rx, ry, amplitude) {
299
- const perimeter = approximateEllipsePerimeter(rx, ry);
300
- const targetScallopLength = Math.max(10, amplitude * 2);
301
- let count = Math.max(12, Math.round(perimeter / targetScallopLength));
302
- if (count % 2 === 1) count += 1;
303
- return count;
304
- }
305
- function pointOnSuperellipse(centerX, centerY, radiusX, radiusY, theta, exponent) {
306
- const cosTheta = Math.cos(theta);
307
- const sinTheta = Math.sin(theta);
294
+ function architecturalCloudCenterCount(edgeLength, radius) {
295
+ const targetSpacing = Math.min(
296
+ ARCHITECTURAL_CLOUD_TARGET_SPACING,
297
+ Math.max(1, radius * 1.3)
298
+ );
299
+ return Math.max(2, Math.round(edgeLength / targetSpacing) + 1);
300
+ }
301
+ function distributeRange(start, end, count) {
302
+ if (count <= 1) return [start];
303
+ const step = (end - start) / (count - 1);
304
+ return Array.from({ length: count }, (_, index) => start + step * index);
305
+ }
306
+ function lineCloudPathSegment(start, end) {
307
+ const dx = end[0] - start[0];
308
+ const dy = end[1] - start[1];
309
+ const length = Math.hypot(dx, dy);
310
+ return {
311
+ length,
312
+ pointAt: (t) => [start[0] + dx * t, start[1] + dy * t]
313
+ };
314
+ }
315
+ function ellipsePoint(centerX, centerY, radiusX, radiusY, angle) {
316
+ return [centerX + Math.cos(angle) * radiusX, centerY + Math.sin(angle) * radiusY];
317
+ }
318
+ function approximateEllipseArcLength(radiusX, radiusY, startAngle, endAngle) {
319
+ const steps = Math.max(
320
+ 4,
321
+ Math.ceil(Math.abs(endAngle - startAngle) / (Math.PI / 16))
322
+ );
323
+ let length = 0;
324
+ let previous = ellipsePoint(0, 0, radiusX, radiusY, startAngle);
325
+ for (let index = 1; index <= steps; index += 1) {
326
+ const angle = startAngle + (endAngle - startAngle) * index / steps;
327
+ const next = ellipsePoint(0, 0, radiusX, radiusY, angle);
328
+ length += Math.hypot(next[0] - previous[0], next[1] - previous[1]);
329
+ previous = next;
330
+ }
331
+ return length;
332
+ }
333
+ function ellipseCloudPathSegment(centerX, centerY, radiusX, radiusY, startAngle, endAngle) {
334
+ return {
335
+ length: approximateEllipseArcLength(radiusX, radiusY, startAngle, endAngle),
336
+ pointAt: (t) => ellipsePoint(
337
+ centerX,
338
+ centerY,
339
+ radiusX,
340
+ radiusY,
341
+ startAngle + (endAngle - startAngle) * t
342
+ )
343
+ };
344
+ }
345
+ function cloudPathPerimeter(segments) {
346
+ const usableSegments = segments.filter((segment) => segment.length > 1e-9);
347
+ return usableSegments.reduce((sum, segment) => sum + segment.length, 0);
348
+ }
349
+ function pointOnCloudPath(segments, distance) {
350
+ const perimeter = cloudPathPerimeter(segments);
351
+ if (perimeter <= 0) return [0, 0];
352
+ let remaining = (distance % perimeter + perimeter) % perimeter;
353
+ for (const segment of segments) {
354
+ if (segment.length <= 1e-9) continue;
355
+ if (remaining <= segment.length) {
356
+ const t = remaining / segment.length;
357
+ return segment.pointAt(t);
358
+ }
359
+ remaining -= segment.length;
360
+ }
361
+ const fallback = segments.find((segment) => segment.length > 1e-9);
362
+ return fallback?.pointAt(0) ?? [0, 0];
363
+ }
364
+ function buildRoundedCapsulePathSegments(width, height, inset) {
365
+ const left = inset;
366
+ const top = inset;
367
+ const right = width - inset;
368
+ const bottom = height - inset;
369
+ const capsuleWidth = Math.max(0, right - left);
370
+ const capsuleHeight = Math.max(0, bottom - top);
371
+ const radius = Math.min(capsuleWidth, capsuleHeight) / 2;
372
+ if (radius <= 0) return [];
373
+ const leftCenterX = left + radius;
374
+ const rightCenterX = right - radius;
375
+ const topCenterY = top + radius;
376
+ const bottomCenterY = bottom - radius;
308
377
  return [
309
- centerX + Math.sign(cosTheta) * radiusX * Math.abs(cosTheta) ** (2 / exponent),
310
- centerY + Math.sign(sinTheta) * radiusY * Math.abs(sinTheta) ** (2 / exponent)
378
+ lineCloudPathSegment([leftCenterX, top], [rightCenterX, top]),
379
+ ellipseCloudPathSegment(
380
+ rightCenterX,
381
+ topCenterY,
382
+ radius,
383
+ radius,
384
+ -Math.PI / 2,
385
+ 0
386
+ ),
387
+ lineCloudPathSegment([right, topCenterY], [right, bottomCenterY]),
388
+ ellipseCloudPathSegment(
389
+ rightCenterX,
390
+ bottomCenterY,
391
+ radius,
392
+ radius,
393
+ 0,
394
+ Math.PI / 2
395
+ ),
396
+ lineCloudPathSegment([rightCenterX, bottom], [leftCenterX, bottom]),
397
+ ellipseCloudPathSegment(
398
+ leftCenterX,
399
+ bottomCenterY,
400
+ radius,
401
+ radius,
402
+ Math.PI / 2,
403
+ Math.PI
404
+ ),
405
+ lineCloudPathSegment([left, bottomCenterY], [left, topCenterY]),
406
+ ellipseCloudPathSegment(
407
+ leftCenterX,
408
+ topCenterY,
409
+ radius,
410
+ radius,
411
+ Math.PI,
412
+ Math.PI * 1.5
413
+ )
311
414
  ];
312
415
  }
416
+ function buildRoundedArcCloudPathD(cloudWidth, cloudHeight, center) {
417
+ const minDimension = Math.min(cloudWidth, cloudHeight);
418
+ const radius = Math.min(
419
+ ARCHITECTURAL_CLOUD_ROUNDED_RADIUS,
420
+ Math.max(ARCHITECTURAL_CLOUD_ROUNDED_MIN_RADIUS, minDimension * 0.16)
421
+ );
422
+ const centerPath = buildRoundedCapsulePathSegments(
423
+ cloudWidth,
424
+ cloudHeight,
425
+ radius
426
+ );
427
+ const centerPerimeter = cloudPathPerimeter(centerPath);
428
+ if (centerPerimeter <= 0) return "";
429
+ const lobeCount = Math.max(
430
+ 8,
431
+ Math.round(centerPerimeter / ARCHITECTURAL_CLOUD_ROUNDED_TARGET_SPACING)
432
+ );
433
+ const centers = Array.from(
434
+ { length: lobeCount },
435
+ (_, index) => pointOnCloudPath(centerPath, centerPerimeter * index / lobeCount)
436
+ );
437
+ const points = centers.map((point, index) => {
438
+ const previous = centers[(index - 1 + centers.length) % centers.length] ?? point;
439
+ return cloudCircleIntersection(previous, point, radius, center);
440
+ });
441
+ const [startX, startY] = points[0] ?? [0, 0];
442
+ const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
443
+ for (const [endX, endY] of points.slice(1)) {
444
+ segments.push(
445
+ `A ${svgNumber(radius)} ${svgNumber(radius)} 0 0 1 ${svgNumber(endX)} ${svgNumber(endY)}`
446
+ );
447
+ }
448
+ segments.push(
449
+ `A ${svgNumber(radius)} ${svgNumber(radius)} 0 0 1 ${svgNumber(startX)} ${svgNumber(startY)}`
450
+ );
451
+ segments.push("Z");
452
+ return segments.join(" ");
453
+ }
454
+ function cloudCircleIntersection(a, b, radius, center) {
455
+ const midX = (a[0] + b[0]) / 2;
456
+ const midY = (a[1] + b[1]) / 2;
457
+ const dx = b[0] - a[0];
458
+ const dy = b[1] - a[1];
459
+ const distance = Math.hypot(dx, dy);
460
+ if (distance <= 1e-9) return [midX, midY];
461
+ const halfDistance = distance / 2;
462
+ const offset = Math.sqrt(
463
+ Math.max(0, radius * radius - halfDistance * halfDistance)
464
+ );
465
+ const normalX = -dy / distance;
466
+ const normalY = dx / distance;
467
+ const first = [midX + normalX * offset, midY + normalY * offset];
468
+ const second = [
469
+ midX - normalX * offset,
470
+ midY - normalY * offset
471
+ ];
472
+ const firstDistance = (first[0] - center[0]) * (first[0] - center[0]) + (first[1] - center[1]) * (first[1] - center[1]);
473
+ const secondDistance = (second[0] - center[0]) * (second[0] - center[0]) + (second[1] - center[1]) * (second[1] - center[1]);
474
+ return firstDistance >= secondDistance ? first : second;
475
+ }
476
+ function cloudEllipseIntersection(a, b, radiusX, radiusY, center) {
477
+ const scaleY = radiusX / radiusY;
478
+ const [x, y] = cloudCircleIntersection(
479
+ [a[0], a[1] * scaleY],
480
+ [b[0], b[1] * scaleY],
481
+ radiusX,
482
+ [center[0], center[1] * scaleY]
483
+ );
484
+ return [x, y / scaleY];
485
+ }
313
486
  function buildRectSvg(width, height, style = DEFAULT_STROKE_STYLE) {
314
487
  return `<rect width="${width}" height="${height}" fill="none" stroke="${style.stroke}" stroke-width="${style.strokeWidth}" rx="4"${strokeOpacityAttr(style)} />`;
315
488
  }
@@ -322,40 +495,63 @@ function buildArchitecturalCloudPathD(width, height, strokeWidth = DEFAULT_STROK
322
495
  const w = Math.max(0, width);
323
496
  const h = Math.max(0, height);
324
497
  if (w <= 0 || h <= 0) return "";
325
- const inset = Math.max(0.5, strokeWidth / 2);
326
- const outerRx = Math.max(0, w / 2 - inset);
327
- const outerRy = Math.max(0, h / 2 - inset);
328
- if (outerRx <= 0 || outerRy <= 0) return "";
329
- const baseExponent = 3.6;
330
- const amplitude = Math.min(
331
- outerRx * 0.45,
332
- outerRy * 0.45,
333
- Math.max(2, Math.min(7, Math.min(w, h) * 0.035))
498
+ const padding = Math.max(0, strokeWidth * 2);
499
+ const cloudWidth = Math.max(0, w - padding);
500
+ const cloudHeight = Math.max(0, h - padding);
501
+ if (cloudWidth <= 0 || cloudHeight <= 0) return "";
502
+ const radiusX = Math.min(
503
+ ARCHITECTURAL_CLOUD_RADIUS,
504
+ cloudWidth * ARCHITECTURAL_CLOUD_FLAT_RADIUS_RATIO
334
505
  );
335
- const innerRx = Math.max(0, outerRx - amplitude);
336
- const innerRy = Math.max(0, outerRy - amplitude);
337
- const scallopCount = architecturalCloudScallopCount(innerRx, innerRy, amplitude);
338
- const angleStep = Math.PI * 2 / scallopCount;
339
- const cx = w / 2;
340
- const cy = h / 2;
341
- const startAngle = -Math.PI / 2;
342
- const pointOnArchitecturalCloud = (theta, radiusX, radiusY) => pointOnSuperellipse(cx, cy, radiusX, radiusY, theta, baseExponent);
343
- const [startX, startY] = pointOnArchitecturalCloud(startAngle, innerRx, innerRy);
344
- const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
345
- for (let index = 0; index < scallopCount; index += 1) {
346
- const segmentStart = startAngle + index * angleStep;
347
- const segmentMid = segmentStart + angleStep / 2;
348
- const segmentEnd = segmentStart + angleStep;
349
- const [controlX, controlY] = pointOnArchitecturalCloud(
350
- segmentMid,
351
- outerRx,
352
- outerRy
506
+ const radiusY = Math.min(
507
+ ARCHITECTURAL_CLOUD_RADIUS,
508
+ cloudHeight * ARCHITECTURAL_CLOUD_FLAT_RADIUS_RATIO
509
+ );
510
+ if (radiusX <= 0 || radiusY <= 0) return "";
511
+ const center = [cloudWidth / 2, cloudHeight / 2];
512
+ const leftCenterX = radiusX;
513
+ const rightCenterX = cloudWidth - radiusX;
514
+ const topCenterY = radiusY;
515
+ const bottomCenterY = cloudHeight - radiusY;
516
+ const horizontalCenters = distributeRange(
517
+ leftCenterX,
518
+ rightCenterX,
519
+ architecturalCloudCenterCount(Math.max(0, rightCenterX - leftCenterX), radiusX)
520
+ );
521
+ const verticalCenters = distributeRange(
522
+ topCenterY,
523
+ bottomCenterY,
524
+ architecturalCloudCenterCount(Math.max(0, bottomCenterY - topCenterY), radiusY)
525
+ );
526
+ if (horizontalCenters.length > 3 && verticalCenters.length > 3) {
527
+ const roundedArcCloudPath = buildRoundedArcCloudPathD(
528
+ cloudWidth,
529
+ cloudHeight,
530
+ center
353
531
  );
354
- const [endX, endY] = pointOnArchitecturalCloud(segmentEnd, innerRx, innerRy);
532
+ if (roundedArcCloudPath !== "") return roundedArcCloudPath;
533
+ }
534
+ const rectangularCenters = [
535
+ ...horizontalCenters.map((x) => [x, topCenterY]),
536
+ ...verticalCenters.slice(1).map((y) => [rightCenterX, y]),
537
+ ...horizontalCenters.slice(0, -1).reverse().map((x) => [x, bottomCenterY]),
538
+ ...verticalCenters.slice(1, -1).reverse().map((y) => [leftCenterX, y])
539
+ ];
540
+ const centers = rectangularCenters;
541
+ const points = centers.map((point, index) => {
542
+ const previous = centers[(index - 1 + centers.length) % centers.length] ?? point;
543
+ return cloudEllipseIntersection(previous, point, radiusX, radiusY, center);
544
+ });
545
+ const [startX, startY] = points[0] ?? [0, 0];
546
+ const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
547
+ for (const [endX, endY] of points.slice(1)) {
355
548
  segments.push(
356
- `Q${svgNumber(controlX)} ${svgNumber(controlY)} ${svgNumber(endX)} ${svgNumber(endY)}`
549
+ `A ${svgNumber(radiusX)} ${svgNumber(radiusY)} 0 0 1 ${svgNumber(endX)} ${svgNumber(endY)}`
357
550
  );
358
551
  }
552
+ segments.push(
553
+ `A ${svgNumber(radiusX)} ${svgNumber(radiusY)} 0 0 1 ${svgNumber(startX)} ${svgNumber(startY)}`
554
+ );
359
555
  segments.push("Z");
360
556
  return segments.join(" ");
361
557
  }
@@ -793,7 +989,7 @@ function createImageFromVectorTrace(id, bounds, imageVectorInnerSvg, imageVector
793
989
  childrenSvg
794
990
  };
795
991
  }
796
- var DEFAULT_STROKE_STYLE, TOOL_FREEHAND_DEFAULTS;
992
+ 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;
797
993
  var init_shape_builders = __esm({
798
994
  "src/scene/shape-builders.ts"() {
799
995
  init_rect();
@@ -809,6 +1005,12 @@ var init_shape_builders = __esm({
809
1005
  brush: { strokeWidth: 10 },
810
1006
  marker: { stroke: "#fde047", strokeWidth: 16, strokeOpacity: 0.5 }
811
1007
  };
1008
+ ARCHITECTURAL_CLOUD_RADIUS = 38;
1009
+ ARCHITECTURAL_CLOUD_TARGET_SPACING = 50;
1010
+ ARCHITECTURAL_CLOUD_FLAT_RADIUS_RATIO = 0.38;
1011
+ ARCHITECTURAL_CLOUD_ROUNDED_RADIUS = 72;
1012
+ ARCHITECTURAL_CLOUD_ROUNDED_MIN_RADIUS = 44;
1013
+ ARCHITECTURAL_CLOUD_ROUNDED_TARGET_SPACING = 98;
812
1014
  }
813
1015
  });
814
1016
 
@@ -3113,7 +3315,7 @@ function ShapeContextMenu({
3113
3315
  }
3114
3316
  return reactDom.createPortal(menu, document.body);
3115
3317
  }
3116
- var architecturalCloudIconPath = "M11 3 Q15.72 1.11 16.44 3.31 Q19.25 2.05 18.39 4.28 Q20.81 4.17 19 7 Q20.81 9.83 18.39 9.72 Q19.25 11.95 16.44 10.69 Q15.72 12.89 11 11 Q6.28 12.89 5.56 10.69 Q2.75 11.95 3.61 9.72 Q1.19 9.83 3 7 Q1.19 4.17 3.61 4.28 Q2.75 2.05 5.56 3.31 Q6.28 1.11 11 3 Z";
3318
+ 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";
3117
3319
  var base = {
3118
3320
  width: 20,
3119
3321
  height: 20,
@@ -3145,7 +3347,7 @@ function IconEllipse(props) {
3145
3347
  return /* @__PURE__ */ jsxRuntime.jsx("svg", { ...base, ...props, "aria-hidden": true, children: /* @__PURE__ */ jsxRuntime.jsx("ellipse", { cx: "12", cy: "12", rx: "9", ry: "6" }) });
3146
3348
  }
3147
3349
  function IconArchitecturalCloud(props) {
3148
- return /* @__PURE__ */ jsxRuntime.jsx("svg", { ...base, ...props, "aria-hidden": true, children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: architecturalCloudIconPath, transform: "translate(1 5)" }) });
3350
+ return /* @__PURE__ */ jsxRuntime.jsx("svg", { ...base, ...props, "aria-hidden": true, children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: architecturalCloudIconPath }) });
3149
3351
  }
3150
3352
  function IconLine(props) {
3151
3353
  return /* @__PURE__ */ jsxRuntime.jsx("svg", { ...base, ...props, "aria-hidden": true, children: /* @__PURE__ */ jsxRuntime.jsx("line", { x1: "5", y1: "19", x2: "19", y2: "5" }) });