canvu-react 0.3.32 → 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/index.cjs +167 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +167 -39
- package/dist/index.js.map +1 -1
- package/dist/native.cjs +167 -39
- package/dist/native.cjs.map +1 -1
- package/dist/native.js +167 -39
- package/dist/native.js.map +1 -1
- package/dist/react.cjs +168 -40
- package/dist/react.cjs.map +1 -1
- package/dist/react.js +168 -40
- package/dist/react.js.map +1 -1
- package/dist/realtime.cjs +1 -1
- package/dist/realtime.cjs.map +1 -1
- package/dist/realtime.js +1 -1
- package/dist/realtime.js.map +1 -1
- package/dist/tldraw.cjs +167 -39
- package/dist/tldraw.cjs.map +1 -1
- package/dist/tldraw.js +167 -39
- package/dist/tldraw.js.map +1 -1
- package/package.json +1 -1
package/dist/native.js
CHANGED
|
@@ -348,24 +348,153 @@ 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
|
|
352
|
-
|
|
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
|
}
|
|
362
|
-
function
|
|
363
|
-
const
|
|
364
|
-
const
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
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];
|
|
369
498
|
}
|
|
370
499
|
function buildRectSvg(width, height, style = DEFAULT_STROKE_STYLE) {
|
|
371
500
|
return `<rect width="${width}" height="${height}" fill="none" stroke="${style.stroke}" stroke-width="${style.strokeWidth}" rx="4"${strokeOpacityAttr(style)} />`;
|
|
@@ -380,35 +509,34 @@ function buildArchitecturalCloudPathD(width, height, strokeWidth = DEFAULT_STROK
|
|
|
380
509
|
const h = Math.max(0, height);
|
|
381
510
|
if (w <= 0 || h <= 0) return "";
|
|
382
511
|
const inset = Math.max(0.5, strokeWidth / 2);
|
|
383
|
-
const
|
|
384
|
-
const
|
|
385
|
-
if (
|
|
386
|
-
const baseExponent = 3.6;
|
|
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 "";
|
|
387
515
|
const amplitude = Math.min(
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
Math.max(
|
|
516
|
+
outerWidth * 0.12,
|
|
517
|
+
outerHeight * 0.12,
|
|
518
|
+
Math.max(5, Math.min(14, Math.min(w, h) * 0.07))
|
|
391
519
|
);
|
|
392
|
-
const
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
const
|
|
398
|
-
const
|
|
399
|
-
|
|
400
|
-
|
|
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);
|
|
401
534
|
const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
|
|
402
535
|
for (let index = 0; index < scallopCount; index += 1) {
|
|
403
|
-
const
|
|
404
|
-
const
|
|
405
|
-
const
|
|
406
|
-
const [
|
|
407
|
-
segmentMid,
|
|
408
|
-
outerRx,
|
|
409
|
-
outerRy
|
|
410
|
-
);
|
|
411
|
-
const [endX, endY] = pointOnArchitecturalCloud(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);
|
|
412
540
|
segments.push(
|
|
413
541
|
`Q${svgNumber(controlX)} ${svgNumber(controlY)} ${svgNumber(endX)} ${svgNumber(endY)}`
|
|
414
542
|
);
|