canvu-react 0.3.31 → 0.3.33

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.js CHANGED
@@ -348,17 +348,154 @@ function svgNumber(value) {
348
348
  const rounded = Math.round(value * 100) / 100;
349
349
  return Number.isInteger(rounded) ? String(rounded) : String(rounded);
350
350
  }
351
- function approximateEllipsePerimeter(rx, ry) {
352
- if (rx <= 0 || ry <= 0) return 0;
353
- return Math.PI * (3 * (rx + ry) - Math.sqrt((3 * rx + ry) * (rx + 3 * ry)));
354
- }
355
- function architecturalCloudScallopCount(rx, ry, amplitude) {
356
- const perimeter = approximateEllipsePerimeter(rx, ry);
357
- const targetScallopLength = Math.max(10, amplitude * 2);
351
+ function architecturalCloudScallopCount(perimeter, amplitude) {
352
+ const targetScallopLength = Math.max(18, amplitude * 2.45);
358
353
  let count = Math.max(12, Math.round(perimeter / targetScallopLength));
359
354
  if (count % 2 === 1) count += 1;
360
355
  return count;
361
356
  }
357
+ function roundedRectMetrics(width, height, inset, radius) {
358
+ const left = inset;
359
+ const top = inset;
360
+ const right = width - inset;
361
+ const bottom = height - inset;
362
+ const rectWidth = Math.max(0, right - left);
363
+ const rectHeight = Math.max(0, bottom - top);
364
+ const normalizedRadius = Math.max(
365
+ 0,
366
+ Math.min(radius, rectWidth / 2, rectHeight / 2)
367
+ );
368
+ const centerX = width / 2;
369
+ const topHalfLength = Math.max(0, right - normalizedRadius - centerX);
370
+ const horizontalLength = Math.max(0, rectWidth - normalizedRadius * 2);
371
+ const verticalLength = Math.max(0, rectHeight - normalizedRadius * 2);
372
+ const arcLength = normalizedRadius * (Math.PI / 2);
373
+ return {
374
+ left,
375
+ top,
376
+ right,
377
+ bottom,
378
+ radius: normalizedRadius,
379
+ centerX,
380
+ topHalfLength,
381
+ horizontalLength,
382
+ verticalLength,
383
+ arcLength,
384
+ perimeter: horizontalLength * 2 + verticalLength * 2 + Math.PI * 2 * normalizedRadius
385
+ };
386
+ }
387
+ function pointOnLine(startX, startY, endX, endY, t) {
388
+ return [startX + (endX - startX) * t, startY + (endY - startY) * t];
389
+ }
390
+ function pointOnArc(centerX, centerY, radius, startAngle, endAngle, t) {
391
+ const theta = startAngle + (endAngle - startAngle) * t;
392
+ return [centerX + Math.cos(theta) * radius, centerY + Math.sin(theta) * radius];
393
+ }
394
+ function pointOnRoundedRectPath(metrics, distance) {
395
+ if (metrics.perimeter <= 0) return [metrics.centerX, metrics.top];
396
+ let remaining = (distance % metrics.perimeter + metrics.perimeter) % metrics.perimeter;
397
+ const consume = (length) => {
398
+ if (length <= 1e-9) return null;
399
+ if (remaining <= length) return remaining / length;
400
+ remaining -= length;
401
+ return null;
402
+ };
403
+ let t = consume(metrics.topHalfLength);
404
+ if (t != null) {
405
+ return pointOnLine(
406
+ metrics.centerX,
407
+ metrics.top,
408
+ metrics.right - metrics.radius,
409
+ metrics.top,
410
+ t
411
+ );
412
+ }
413
+ t = consume(metrics.arcLength);
414
+ if (t != null) {
415
+ return pointOnArc(
416
+ metrics.right - metrics.radius,
417
+ metrics.top + metrics.radius,
418
+ metrics.radius,
419
+ -Math.PI / 2,
420
+ 0,
421
+ t
422
+ );
423
+ }
424
+ t = consume(metrics.verticalLength);
425
+ if (t != null) {
426
+ return pointOnLine(
427
+ metrics.right,
428
+ metrics.top + metrics.radius,
429
+ metrics.right,
430
+ metrics.bottom - metrics.radius,
431
+ t
432
+ );
433
+ }
434
+ t = consume(metrics.arcLength);
435
+ if (t != null) {
436
+ return pointOnArc(
437
+ metrics.right - metrics.radius,
438
+ metrics.bottom - metrics.radius,
439
+ metrics.radius,
440
+ 0,
441
+ Math.PI / 2,
442
+ t
443
+ );
444
+ }
445
+ t = consume(metrics.horizontalLength);
446
+ if (t != null) {
447
+ return pointOnLine(
448
+ metrics.right - metrics.radius,
449
+ metrics.bottom,
450
+ metrics.left + metrics.radius,
451
+ metrics.bottom,
452
+ t
453
+ );
454
+ }
455
+ t = consume(metrics.arcLength);
456
+ if (t != null) {
457
+ return pointOnArc(
458
+ metrics.left + metrics.radius,
459
+ metrics.bottom - metrics.radius,
460
+ metrics.radius,
461
+ Math.PI / 2,
462
+ Math.PI,
463
+ t
464
+ );
465
+ }
466
+ t = consume(metrics.verticalLength);
467
+ if (t != null) {
468
+ return pointOnLine(
469
+ metrics.left,
470
+ metrics.bottom - metrics.radius,
471
+ metrics.left,
472
+ metrics.top + metrics.radius,
473
+ t
474
+ );
475
+ }
476
+ t = consume(metrics.arcLength);
477
+ if (t != null) {
478
+ return pointOnArc(
479
+ metrics.left + metrics.radius,
480
+ metrics.top + metrics.radius,
481
+ metrics.radius,
482
+ Math.PI,
483
+ Math.PI * 1.5,
484
+ t
485
+ );
486
+ }
487
+ t = consume(metrics.topHalfLength);
488
+ if (t != null) {
489
+ return pointOnLine(
490
+ metrics.left + metrics.radius,
491
+ metrics.top,
492
+ metrics.centerX,
493
+ metrics.top,
494
+ t
495
+ );
496
+ }
497
+ return [metrics.centerX, metrics.top];
498
+ }
362
499
  function buildRectSvg(width, height, style = DEFAULT_STROKE_STYLE) {
363
500
  return `<rect width="${width}" height="${height}" fill="none" stroke="${style.stroke}" stroke-width="${style.strokeWidth}" rx="4"${strokeOpacityAttr(style)} />`;
364
501
  }
@@ -372,33 +509,34 @@ function buildArchitecturalCloudPathD(width, height, strokeWidth = DEFAULT_STROK
372
509
  const h = Math.max(0, height);
373
510
  if (w <= 0 || h <= 0) return "";
374
511
  const inset = Math.max(0.5, strokeWidth / 2);
375
- const outerRx = Math.max(0, w / 2 - inset);
376
- const outerRy = Math.max(0, h / 2 - inset);
377
- if (outerRx <= 0 || outerRy <= 0) return "";
512
+ const outerWidth = Math.max(0, w - inset * 2);
513
+ const outerHeight = Math.max(0, h - inset * 2);
514
+ if (outerWidth <= 0 || outerHeight <= 0) return "";
378
515
  const amplitude = Math.min(
379
- outerRx * 0.45,
380
- outerRy * 0.45,
381
- Math.max(2, Math.min(8, Math.min(w, h) * 0.04))
516
+ outerWidth * 0.12,
517
+ outerHeight * 0.12,
518
+ Math.max(5, Math.min(14, Math.min(w, h) * 0.07))
382
519
  );
383
- const innerRx = Math.max(0, outerRx - amplitude);
384
- const innerRy = Math.max(0, outerRy - amplitude);
385
- const scallopCount = architecturalCloudScallopCount(innerRx, innerRy, amplitude);
386
- const angleStep = Math.PI * 2 / scallopCount;
387
- const cx = w / 2;
388
- const cy = h / 2;
389
- const startAngle = -Math.PI / 2;
390
- const pointOnEllipse = (theta, radiusX, radiusY) => [
391
- cx + Math.cos(theta) * radiusX,
392
- cy + Math.sin(theta) * radiusY
393
- ];
394
- const [startX, startY] = pointOnEllipse(startAngle, innerRx, innerRy);
520
+ const radius = Math.min(
521
+ outerWidth / 2,
522
+ outerHeight / 2,
523
+ Math.max(amplitude * 2.5, outerHeight * 0.43)
524
+ );
525
+ const outer = roundedRectMetrics(w, h, inset, radius);
526
+ const inner = roundedRectMetrics(
527
+ w,
528
+ h,
529
+ inset + amplitude,
530
+ Math.max(0, radius - amplitude)
531
+ );
532
+ const scallopCount = architecturalCloudScallopCount(outer.perimeter, amplitude);
533
+ const [startX, startY] = pointOnRoundedRectPath(inner, 0);
395
534
  const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
396
535
  for (let index = 0; index < scallopCount; index += 1) {
397
- const segmentStart = startAngle + index * angleStep;
398
- const segmentMid = segmentStart + angleStep / 2;
399
- const segmentEnd = segmentStart + angleStep;
400
- const [controlX, controlY] = pointOnEllipse(segmentMid, outerRx, outerRy);
401
- const [endX, endY] = pointOnEllipse(segmentEnd, innerRx, innerRy);
536
+ const controlDistance = (index + 0.5) / scallopCount * outer.perimeter;
537
+ const endDistance = (index + 1) / scallopCount * inner.perimeter;
538
+ const [controlX, controlY] = pointOnRoundedRectPath(outer, controlDistance);
539
+ const [endX, endY] = pointOnRoundedRectPath(inner, endDistance);
402
540
  segments.push(
403
541
  `Q${svgNumber(controlX)} ${svgNumber(controlY)} ${svgNumber(endX)} ${svgNumber(endY)}`
404
542
  );