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/index.cjs +247 -45
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +247 -45
- package/dist/index.js.map +1 -1
- package/dist/native.cjs +247 -45
- package/dist/native.cjs.map +1 -1
- package/dist/native.js +247 -45
- package/dist/native.js.map +1 -1
- package/dist/react.cjs +250 -48
- package/dist/react.cjs.map +1 -1
- package/dist/react.js +250 -48
- package/dist/react.js.map +1 -1
- package/dist/realtime.cjs +2 -2
- package/dist/realtime.cjs.map +1 -1
- package/dist/realtime.js +2 -2
- package/dist/realtime.js.map +1 -1
- package/dist/tldraw.cjs +247 -45
- package/dist/tldraw.cjs.map +1 -1
- package/dist/tldraw.js +247 -45
- package/dist/tldraw.js.map +1 -1
- package/package.json +1 -1
package/dist/native.cjs
CHANGED
|
@@ -354,24 +354,203 @@ function svgNumber(value) {
|
|
|
354
354
|
const rounded = Math.round(value * 100) / 100;
|
|
355
355
|
return Number.isInteger(rounded) ? String(rounded) : String(rounded);
|
|
356
356
|
}
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
357
|
+
var ARCHITECTURAL_CLOUD_RADIUS = 38;
|
|
358
|
+
var ARCHITECTURAL_CLOUD_TARGET_SPACING = 50;
|
|
359
|
+
var ARCHITECTURAL_CLOUD_FLAT_RADIUS_RATIO = 0.38;
|
|
360
|
+
var ARCHITECTURAL_CLOUD_ROUNDED_RADIUS = 72;
|
|
361
|
+
var ARCHITECTURAL_CLOUD_ROUNDED_MIN_RADIUS = 44;
|
|
362
|
+
var ARCHITECTURAL_CLOUD_ROUNDED_TARGET_SPACING = 98;
|
|
363
|
+
function architecturalCloudCenterCount(edgeLength, radius) {
|
|
364
|
+
const targetSpacing = Math.min(
|
|
365
|
+
ARCHITECTURAL_CLOUD_TARGET_SPACING,
|
|
366
|
+
Math.max(1, radius * 1.3)
|
|
367
|
+
);
|
|
368
|
+
return Math.max(2, Math.round(edgeLength / targetSpacing) + 1);
|
|
369
|
+
}
|
|
370
|
+
function distributeRange(start, end, count) {
|
|
371
|
+
if (count <= 1) return [start];
|
|
372
|
+
const step = (end - start) / (count - 1);
|
|
373
|
+
return Array.from({ length: count }, (_, index) => start + step * index);
|
|
374
|
+
}
|
|
375
|
+
function lineCloudPathSegment(start, end) {
|
|
376
|
+
const dx = end[0] - start[0];
|
|
377
|
+
const dy = end[1] - start[1];
|
|
378
|
+
const length = Math.hypot(dx, dy);
|
|
379
|
+
return {
|
|
380
|
+
length,
|
|
381
|
+
pointAt: (t) => [start[0] + dx * t, start[1] + dy * t]
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
function ellipsePoint(centerX, centerY, radiusX, radiusY, angle) {
|
|
385
|
+
return [centerX + Math.cos(angle) * radiusX, centerY + Math.sin(angle) * radiusY];
|
|
386
|
+
}
|
|
387
|
+
function approximateEllipseArcLength(radiusX, radiusY, startAngle, endAngle) {
|
|
388
|
+
const steps = Math.max(
|
|
389
|
+
4,
|
|
390
|
+
Math.ceil(Math.abs(endAngle - startAngle) / (Math.PI / 16))
|
|
391
|
+
);
|
|
392
|
+
let length = 0;
|
|
393
|
+
let previous = ellipsePoint(0, 0, radiusX, radiusY, startAngle);
|
|
394
|
+
for (let index = 1; index <= steps; index += 1) {
|
|
395
|
+
const angle = startAngle + (endAngle - startAngle) * index / steps;
|
|
396
|
+
const next = ellipsePoint(0, 0, radiusX, radiusY, angle);
|
|
397
|
+
length += Math.hypot(next[0] - previous[0], next[1] - previous[1]);
|
|
398
|
+
previous = next;
|
|
399
|
+
}
|
|
400
|
+
return length;
|
|
401
|
+
}
|
|
402
|
+
function ellipseCloudPathSegment(centerX, centerY, radiusX, radiusY, startAngle, endAngle) {
|
|
403
|
+
return {
|
|
404
|
+
length: approximateEllipseArcLength(radiusX, radiusY, startAngle, endAngle),
|
|
405
|
+
pointAt: (t) => ellipsePoint(
|
|
406
|
+
centerX,
|
|
407
|
+
centerY,
|
|
408
|
+
radiusX,
|
|
409
|
+
radiusY,
|
|
410
|
+
startAngle + (endAngle - startAngle) * t
|
|
411
|
+
)
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
function cloudPathPerimeter(segments) {
|
|
415
|
+
const usableSegments = segments.filter((segment) => segment.length > 1e-9);
|
|
416
|
+
return usableSegments.reduce((sum, segment) => sum + segment.length, 0);
|
|
417
|
+
}
|
|
418
|
+
function pointOnCloudPath(segments, distance) {
|
|
419
|
+
const perimeter = cloudPathPerimeter(segments);
|
|
420
|
+
if (perimeter <= 0) return [0, 0];
|
|
421
|
+
let remaining = (distance % perimeter + perimeter) % perimeter;
|
|
422
|
+
for (const segment of segments) {
|
|
423
|
+
if (segment.length <= 1e-9) continue;
|
|
424
|
+
if (remaining <= segment.length) {
|
|
425
|
+
const t = remaining / segment.length;
|
|
426
|
+
return segment.pointAt(t);
|
|
427
|
+
}
|
|
428
|
+
remaining -= segment.length;
|
|
429
|
+
}
|
|
430
|
+
const fallback = segments.find((segment) => segment.length > 1e-9);
|
|
431
|
+
return fallback?.pointAt(0) ?? [0, 0];
|
|
432
|
+
}
|
|
433
|
+
function buildRoundedCapsulePathSegments(width, height, inset) {
|
|
434
|
+
const left = inset;
|
|
435
|
+
const top = inset;
|
|
436
|
+
const right = width - inset;
|
|
437
|
+
const bottom = height - inset;
|
|
438
|
+
const capsuleWidth = Math.max(0, right - left);
|
|
439
|
+
const capsuleHeight = Math.max(0, bottom - top);
|
|
440
|
+
const radius = Math.min(capsuleWidth, capsuleHeight) / 2;
|
|
441
|
+
if (radius <= 0) return [];
|
|
442
|
+
const leftCenterX = left + radius;
|
|
443
|
+
const rightCenterX = right - radius;
|
|
444
|
+
const topCenterY = top + radius;
|
|
445
|
+
const bottomCenterY = bottom - radius;
|
|
371
446
|
return [
|
|
372
|
-
|
|
373
|
-
|
|
447
|
+
lineCloudPathSegment([leftCenterX, top], [rightCenterX, top]),
|
|
448
|
+
ellipseCloudPathSegment(
|
|
449
|
+
rightCenterX,
|
|
450
|
+
topCenterY,
|
|
451
|
+
radius,
|
|
452
|
+
radius,
|
|
453
|
+
-Math.PI / 2,
|
|
454
|
+
0
|
|
455
|
+
),
|
|
456
|
+
lineCloudPathSegment([right, topCenterY], [right, bottomCenterY]),
|
|
457
|
+
ellipseCloudPathSegment(
|
|
458
|
+
rightCenterX,
|
|
459
|
+
bottomCenterY,
|
|
460
|
+
radius,
|
|
461
|
+
radius,
|
|
462
|
+
0,
|
|
463
|
+
Math.PI / 2
|
|
464
|
+
),
|
|
465
|
+
lineCloudPathSegment([rightCenterX, bottom], [leftCenterX, bottom]),
|
|
466
|
+
ellipseCloudPathSegment(
|
|
467
|
+
leftCenterX,
|
|
468
|
+
bottomCenterY,
|
|
469
|
+
radius,
|
|
470
|
+
radius,
|
|
471
|
+
Math.PI / 2,
|
|
472
|
+
Math.PI
|
|
473
|
+
),
|
|
474
|
+
lineCloudPathSegment([left, bottomCenterY], [left, topCenterY]),
|
|
475
|
+
ellipseCloudPathSegment(
|
|
476
|
+
leftCenterX,
|
|
477
|
+
topCenterY,
|
|
478
|
+
radius,
|
|
479
|
+
radius,
|
|
480
|
+
Math.PI,
|
|
481
|
+
Math.PI * 1.5
|
|
482
|
+
)
|
|
483
|
+
];
|
|
484
|
+
}
|
|
485
|
+
function buildRoundedArcCloudPathD(cloudWidth, cloudHeight, center) {
|
|
486
|
+
const minDimension = Math.min(cloudWidth, cloudHeight);
|
|
487
|
+
const radius = Math.min(
|
|
488
|
+
ARCHITECTURAL_CLOUD_ROUNDED_RADIUS,
|
|
489
|
+
Math.max(ARCHITECTURAL_CLOUD_ROUNDED_MIN_RADIUS, minDimension * 0.16)
|
|
490
|
+
);
|
|
491
|
+
const centerPath = buildRoundedCapsulePathSegments(
|
|
492
|
+
cloudWidth,
|
|
493
|
+
cloudHeight,
|
|
494
|
+
radius
|
|
495
|
+
);
|
|
496
|
+
const centerPerimeter = cloudPathPerimeter(centerPath);
|
|
497
|
+
if (centerPerimeter <= 0) return "";
|
|
498
|
+
const lobeCount = Math.max(
|
|
499
|
+
8,
|
|
500
|
+
Math.round(centerPerimeter / ARCHITECTURAL_CLOUD_ROUNDED_TARGET_SPACING)
|
|
501
|
+
);
|
|
502
|
+
const centers = Array.from(
|
|
503
|
+
{ length: lobeCount },
|
|
504
|
+
(_, index) => pointOnCloudPath(centerPath, centerPerimeter * index / lobeCount)
|
|
505
|
+
);
|
|
506
|
+
const points = centers.map((point, index) => {
|
|
507
|
+
const previous = centers[(index - 1 + centers.length) % centers.length] ?? point;
|
|
508
|
+
return cloudCircleIntersection(previous, point, radius, center);
|
|
509
|
+
});
|
|
510
|
+
const [startX, startY] = points[0] ?? [0, 0];
|
|
511
|
+
const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
|
|
512
|
+
for (const [endX, endY] of points.slice(1)) {
|
|
513
|
+
segments.push(
|
|
514
|
+
`A ${svgNumber(radius)} ${svgNumber(radius)} 0 0 1 ${svgNumber(endX)} ${svgNumber(endY)}`
|
|
515
|
+
);
|
|
516
|
+
}
|
|
517
|
+
segments.push(
|
|
518
|
+
`A ${svgNumber(radius)} ${svgNumber(radius)} 0 0 1 ${svgNumber(startX)} ${svgNumber(startY)}`
|
|
519
|
+
);
|
|
520
|
+
segments.push("Z");
|
|
521
|
+
return segments.join(" ");
|
|
522
|
+
}
|
|
523
|
+
function cloudCircleIntersection(a, b, radius, center) {
|
|
524
|
+
const midX = (a[0] + b[0]) / 2;
|
|
525
|
+
const midY = (a[1] + b[1]) / 2;
|
|
526
|
+
const dx = b[0] - a[0];
|
|
527
|
+
const dy = b[1] - a[1];
|
|
528
|
+
const distance = Math.hypot(dx, dy);
|
|
529
|
+
if (distance <= 1e-9) return [midX, midY];
|
|
530
|
+
const halfDistance = distance / 2;
|
|
531
|
+
const offset = Math.sqrt(
|
|
532
|
+
Math.max(0, radius * radius - halfDistance * halfDistance)
|
|
533
|
+
);
|
|
534
|
+
const normalX = -dy / distance;
|
|
535
|
+
const normalY = dx / distance;
|
|
536
|
+
const first = [midX + normalX * offset, midY + normalY * offset];
|
|
537
|
+
const second = [
|
|
538
|
+
midX - normalX * offset,
|
|
539
|
+
midY - normalY * offset
|
|
374
540
|
];
|
|
541
|
+
const firstDistance = (first[0] - center[0]) * (first[0] - center[0]) + (first[1] - center[1]) * (first[1] - center[1]);
|
|
542
|
+
const secondDistance = (second[0] - center[0]) * (second[0] - center[0]) + (second[1] - center[1]) * (second[1] - center[1]);
|
|
543
|
+
return firstDistance >= secondDistance ? first : second;
|
|
544
|
+
}
|
|
545
|
+
function cloudEllipseIntersection(a, b, radiusX, radiusY, center) {
|
|
546
|
+
const scaleY = radiusX / radiusY;
|
|
547
|
+
const [x, y] = cloudCircleIntersection(
|
|
548
|
+
[a[0], a[1] * scaleY],
|
|
549
|
+
[b[0], b[1] * scaleY],
|
|
550
|
+
radiusX,
|
|
551
|
+
[center[0], center[1] * scaleY]
|
|
552
|
+
);
|
|
553
|
+
return [x, y / scaleY];
|
|
375
554
|
}
|
|
376
555
|
function buildRectSvg(width, height, style = DEFAULT_STROKE_STYLE) {
|
|
377
556
|
return `<rect width="${width}" height="${height}" fill="none" stroke="${style.stroke}" stroke-width="${style.strokeWidth}" rx="4"${strokeOpacityAttr(style)} />`;
|
|
@@ -385,40 +564,63 @@ function buildArchitecturalCloudPathD(width, height, strokeWidth = DEFAULT_STROK
|
|
|
385
564
|
const w = Math.max(0, width);
|
|
386
565
|
const h = Math.max(0, height);
|
|
387
566
|
if (w <= 0 || h <= 0) return "";
|
|
388
|
-
const
|
|
389
|
-
const
|
|
390
|
-
const
|
|
391
|
-
if (
|
|
392
|
-
const
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
outerRy * 0.45,
|
|
396
|
-
Math.max(2, Math.min(7, Math.min(w, h) * 0.035))
|
|
567
|
+
const padding = Math.max(0, strokeWidth * 2);
|
|
568
|
+
const cloudWidth = Math.max(0, w - padding);
|
|
569
|
+
const cloudHeight = Math.max(0, h - padding);
|
|
570
|
+
if (cloudWidth <= 0 || cloudHeight <= 0) return "";
|
|
571
|
+
const radiusX = Math.min(
|
|
572
|
+
ARCHITECTURAL_CLOUD_RADIUS,
|
|
573
|
+
cloudWidth * ARCHITECTURAL_CLOUD_FLAT_RADIUS_RATIO
|
|
397
574
|
);
|
|
398
|
-
const
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
const
|
|
404
|
-
const
|
|
405
|
-
const
|
|
406
|
-
const
|
|
407
|
-
const
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
575
|
+
const radiusY = Math.min(
|
|
576
|
+
ARCHITECTURAL_CLOUD_RADIUS,
|
|
577
|
+
cloudHeight * ARCHITECTURAL_CLOUD_FLAT_RADIUS_RATIO
|
|
578
|
+
);
|
|
579
|
+
if (radiusX <= 0 || radiusY <= 0) return "";
|
|
580
|
+
const center = [cloudWidth / 2, cloudHeight / 2];
|
|
581
|
+
const leftCenterX = radiusX;
|
|
582
|
+
const rightCenterX = cloudWidth - radiusX;
|
|
583
|
+
const topCenterY = radiusY;
|
|
584
|
+
const bottomCenterY = cloudHeight - radiusY;
|
|
585
|
+
const horizontalCenters = distributeRange(
|
|
586
|
+
leftCenterX,
|
|
587
|
+
rightCenterX,
|
|
588
|
+
architecturalCloudCenterCount(Math.max(0, rightCenterX - leftCenterX), radiusX)
|
|
589
|
+
);
|
|
590
|
+
const verticalCenters = distributeRange(
|
|
591
|
+
topCenterY,
|
|
592
|
+
bottomCenterY,
|
|
593
|
+
architecturalCloudCenterCount(Math.max(0, bottomCenterY - topCenterY), radiusY)
|
|
594
|
+
);
|
|
595
|
+
if (horizontalCenters.length > 3 && verticalCenters.length > 3) {
|
|
596
|
+
const roundedArcCloudPath = buildRoundedArcCloudPathD(
|
|
597
|
+
cloudWidth,
|
|
598
|
+
cloudHeight,
|
|
599
|
+
center
|
|
416
600
|
);
|
|
417
|
-
|
|
601
|
+
if (roundedArcCloudPath !== "") return roundedArcCloudPath;
|
|
602
|
+
}
|
|
603
|
+
const rectangularCenters = [
|
|
604
|
+
...horizontalCenters.map((x) => [x, topCenterY]),
|
|
605
|
+
...verticalCenters.slice(1).map((y) => [rightCenterX, y]),
|
|
606
|
+
...horizontalCenters.slice(0, -1).reverse().map((x) => [x, bottomCenterY]),
|
|
607
|
+
...verticalCenters.slice(1, -1).reverse().map((y) => [leftCenterX, y])
|
|
608
|
+
];
|
|
609
|
+
const centers = rectangularCenters;
|
|
610
|
+
const points = centers.map((point, index) => {
|
|
611
|
+
const previous = centers[(index - 1 + centers.length) % centers.length] ?? point;
|
|
612
|
+
return cloudEllipseIntersection(previous, point, radiusX, radiusY, center);
|
|
613
|
+
});
|
|
614
|
+
const [startX, startY] = points[0] ?? [0, 0];
|
|
615
|
+
const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
|
|
616
|
+
for (const [endX, endY] of points.slice(1)) {
|
|
418
617
|
segments.push(
|
|
419
|
-
`
|
|
618
|
+
`A ${svgNumber(radiusX)} ${svgNumber(radiusY)} 0 0 1 ${svgNumber(endX)} ${svgNumber(endY)}`
|
|
420
619
|
);
|
|
421
620
|
}
|
|
621
|
+
segments.push(
|
|
622
|
+
`A ${svgNumber(radiusX)} ${svgNumber(radiusY)} 0 0 1 ${svgNumber(startX)} ${svgNumber(startY)}`
|
|
623
|
+
);
|
|
422
624
|
segments.push("Z");
|
|
423
625
|
return segments.join(" ");
|
|
424
626
|
}
|