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/react.js
CHANGED
|
@@ -284,25 +284,198 @@ function svgNumber(value) {
|
|
|
284
284
|
const rounded = Math.round(value * 100) / 100;
|
|
285
285
|
return Number.isInteger(rounded) ? String(rounded) : String(rounded);
|
|
286
286
|
}
|
|
287
|
-
function
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
if (count
|
|
296
|
-
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
const
|
|
287
|
+
function architecturalCloudCenterCount(edgeLength, radius) {
|
|
288
|
+
const targetSpacing = Math.min(
|
|
289
|
+
ARCHITECTURAL_CLOUD_TARGET_SPACING,
|
|
290
|
+
Math.max(1, radius * 1.3)
|
|
291
|
+
);
|
|
292
|
+
return Math.max(2, Math.round(edgeLength / targetSpacing) + 1);
|
|
293
|
+
}
|
|
294
|
+
function distributeRange(start, end, count) {
|
|
295
|
+
if (count <= 1) return [start];
|
|
296
|
+
const step = (end - start) / (count - 1);
|
|
297
|
+
return Array.from({ length: count }, (_, index) => start + step * index);
|
|
298
|
+
}
|
|
299
|
+
function lineCloudPathSegment(start, end) {
|
|
300
|
+
const dx = end[0] - start[0];
|
|
301
|
+
const dy = end[1] - start[1];
|
|
302
|
+
const length = Math.hypot(dx, dy);
|
|
303
|
+
return {
|
|
304
|
+
length,
|
|
305
|
+
pointAt: (t) => [start[0] + dx * t, start[1] + dy * t]
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
function ellipsePoint(centerX, centerY, radiusX, radiusY, angle) {
|
|
309
|
+
return [centerX + Math.cos(angle) * radiusX, centerY + Math.sin(angle) * radiusY];
|
|
310
|
+
}
|
|
311
|
+
function approximateEllipseArcLength(radiusX, radiusY, startAngle, endAngle) {
|
|
312
|
+
const steps = Math.max(
|
|
313
|
+
4,
|
|
314
|
+
Math.ceil(Math.abs(endAngle - startAngle) / (Math.PI / 16))
|
|
315
|
+
);
|
|
316
|
+
let length = 0;
|
|
317
|
+
let previous = ellipsePoint(0, 0, radiusX, radiusY, startAngle);
|
|
318
|
+
for (let index = 1; index <= steps; index += 1) {
|
|
319
|
+
const angle = startAngle + (endAngle - startAngle) * index / steps;
|
|
320
|
+
const next = ellipsePoint(0, 0, radiusX, radiusY, angle);
|
|
321
|
+
length += Math.hypot(next[0] - previous[0], next[1] - previous[1]);
|
|
322
|
+
previous = next;
|
|
323
|
+
}
|
|
324
|
+
return length;
|
|
325
|
+
}
|
|
326
|
+
function ellipseCloudPathSegment(centerX, centerY, radiusX, radiusY, startAngle, endAngle) {
|
|
327
|
+
return {
|
|
328
|
+
length: approximateEllipseArcLength(radiusX, radiusY, startAngle, endAngle),
|
|
329
|
+
pointAt: (t) => ellipsePoint(
|
|
330
|
+
centerX,
|
|
331
|
+
centerY,
|
|
332
|
+
radiusX,
|
|
333
|
+
radiusY,
|
|
334
|
+
startAngle + (endAngle - startAngle) * t
|
|
335
|
+
)
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
function cloudPathPerimeter(segments) {
|
|
339
|
+
const usableSegments = segments.filter((segment) => segment.length > 1e-9);
|
|
340
|
+
return usableSegments.reduce((sum, segment) => sum + segment.length, 0);
|
|
341
|
+
}
|
|
342
|
+
function pointOnCloudPath(segments, distance) {
|
|
343
|
+
const perimeter = cloudPathPerimeter(segments);
|
|
344
|
+
if (perimeter <= 0) return [0, 0];
|
|
345
|
+
let remaining = (distance % perimeter + perimeter) % perimeter;
|
|
346
|
+
for (const segment of segments) {
|
|
347
|
+
if (segment.length <= 1e-9) continue;
|
|
348
|
+
if (remaining <= segment.length) {
|
|
349
|
+
const t = remaining / segment.length;
|
|
350
|
+
return segment.pointAt(t);
|
|
351
|
+
}
|
|
352
|
+
remaining -= segment.length;
|
|
353
|
+
}
|
|
354
|
+
const fallback = segments.find((segment) => segment.length > 1e-9);
|
|
355
|
+
return fallback?.pointAt(0) ?? [0, 0];
|
|
356
|
+
}
|
|
357
|
+
function buildRoundedCapsulePathSegments(width, height, inset) {
|
|
358
|
+
const left = inset;
|
|
359
|
+
const top = inset;
|
|
360
|
+
const right = width - inset;
|
|
361
|
+
const bottom = height - inset;
|
|
362
|
+
const capsuleWidth = Math.max(0, right - left);
|
|
363
|
+
const capsuleHeight = Math.max(0, bottom - top);
|
|
364
|
+
const radius = Math.min(capsuleWidth, capsuleHeight) / 2;
|
|
365
|
+
if (radius <= 0) return [];
|
|
366
|
+
const leftCenterX = left + radius;
|
|
367
|
+
const rightCenterX = right - radius;
|
|
368
|
+
const topCenterY = top + radius;
|
|
369
|
+
const bottomCenterY = bottom - radius;
|
|
301
370
|
return [
|
|
302
|
-
|
|
303
|
-
|
|
371
|
+
lineCloudPathSegment([leftCenterX, top], [rightCenterX, top]),
|
|
372
|
+
ellipseCloudPathSegment(
|
|
373
|
+
rightCenterX,
|
|
374
|
+
topCenterY,
|
|
375
|
+
radius,
|
|
376
|
+
radius,
|
|
377
|
+
-Math.PI / 2,
|
|
378
|
+
0
|
|
379
|
+
),
|
|
380
|
+
lineCloudPathSegment([right, topCenterY], [right, bottomCenterY]),
|
|
381
|
+
ellipseCloudPathSegment(
|
|
382
|
+
rightCenterX,
|
|
383
|
+
bottomCenterY,
|
|
384
|
+
radius,
|
|
385
|
+
radius,
|
|
386
|
+
0,
|
|
387
|
+
Math.PI / 2
|
|
388
|
+
),
|
|
389
|
+
lineCloudPathSegment([rightCenterX, bottom], [leftCenterX, bottom]),
|
|
390
|
+
ellipseCloudPathSegment(
|
|
391
|
+
leftCenterX,
|
|
392
|
+
bottomCenterY,
|
|
393
|
+
radius,
|
|
394
|
+
radius,
|
|
395
|
+
Math.PI / 2,
|
|
396
|
+
Math.PI
|
|
397
|
+
),
|
|
398
|
+
lineCloudPathSegment([left, bottomCenterY], [left, topCenterY]),
|
|
399
|
+
ellipseCloudPathSegment(
|
|
400
|
+
leftCenterX,
|
|
401
|
+
topCenterY,
|
|
402
|
+
radius,
|
|
403
|
+
radius,
|
|
404
|
+
Math.PI,
|
|
405
|
+
Math.PI * 1.5
|
|
406
|
+
)
|
|
304
407
|
];
|
|
305
408
|
}
|
|
409
|
+
function buildRoundedArcCloudPathD(cloudWidth, cloudHeight, center) {
|
|
410
|
+
const minDimension = Math.min(cloudWidth, cloudHeight);
|
|
411
|
+
const radius = Math.min(
|
|
412
|
+
ARCHITECTURAL_CLOUD_ROUNDED_RADIUS,
|
|
413
|
+
Math.max(ARCHITECTURAL_CLOUD_ROUNDED_MIN_RADIUS, minDimension * 0.16)
|
|
414
|
+
);
|
|
415
|
+
const centerPath = buildRoundedCapsulePathSegments(
|
|
416
|
+
cloudWidth,
|
|
417
|
+
cloudHeight,
|
|
418
|
+
radius
|
|
419
|
+
);
|
|
420
|
+
const centerPerimeter = cloudPathPerimeter(centerPath);
|
|
421
|
+
if (centerPerimeter <= 0) return "";
|
|
422
|
+
const lobeCount = Math.max(
|
|
423
|
+
8,
|
|
424
|
+
Math.round(centerPerimeter / ARCHITECTURAL_CLOUD_ROUNDED_TARGET_SPACING)
|
|
425
|
+
);
|
|
426
|
+
const centers = Array.from(
|
|
427
|
+
{ length: lobeCount },
|
|
428
|
+
(_, index) => pointOnCloudPath(centerPath, centerPerimeter * index / lobeCount)
|
|
429
|
+
);
|
|
430
|
+
const points = centers.map((point, index) => {
|
|
431
|
+
const previous = centers[(index - 1 + centers.length) % centers.length] ?? point;
|
|
432
|
+
return cloudCircleIntersection(previous, point, radius, center);
|
|
433
|
+
});
|
|
434
|
+
const [startX, startY] = points[0] ?? [0, 0];
|
|
435
|
+
const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
|
|
436
|
+
for (const [endX, endY] of points.slice(1)) {
|
|
437
|
+
segments.push(
|
|
438
|
+
`A ${svgNumber(radius)} ${svgNumber(radius)} 0 0 1 ${svgNumber(endX)} ${svgNumber(endY)}`
|
|
439
|
+
);
|
|
440
|
+
}
|
|
441
|
+
segments.push(
|
|
442
|
+
`A ${svgNumber(radius)} ${svgNumber(radius)} 0 0 1 ${svgNumber(startX)} ${svgNumber(startY)}`
|
|
443
|
+
);
|
|
444
|
+
segments.push("Z");
|
|
445
|
+
return segments.join(" ");
|
|
446
|
+
}
|
|
447
|
+
function cloudCircleIntersection(a, b, radius, center) {
|
|
448
|
+
const midX = (a[0] + b[0]) / 2;
|
|
449
|
+
const midY = (a[1] + b[1]) / 2;
|
|
450
|
+
const dx = b[0] - a[0];
|
|
451
|
+
const dy = b[1] - a[1];
|
|
452
|
+
const distance = Math.hypot(dx, dy);
|
|
453
|
+
if (distance <= 1e-9) return [midX, midY];
|
|
454
|
+
const halfDistance = distance / 2;
|
|
455
|
+
const offset = Math.sqrt(
|
|
456
|
+
Math.max(0, radius * radius - halfDistance * halfDistance)
|
|
457
|
+
);
|
|
458
|
+
const normalX = -dy / distance;
|
|
459
|
+
const normalY = dx / distance;
|
|
460
|
+
const first = [midX + normalX * offset, midY + normalY * offset];
|
|
461
|
+
const second = [
|
|
462
|
+
midX - normalX * offset,
|
|
463
|
+
midY - normalY * offset
|
|
464
|
+
];
|
|
465
|
+
const firstDistance = (first[0] - center[0]) * (first[0] - center[0]) + (first[1] - center[1]) * (first[1] - center[1]);
|
|
466
|
+
const secondDistance = (second[0] - center[0]) * (second[0] - center[0]) + (second[1] - center[1]) * (second[1] - center[1]);
|
|
467
|
+
return firstDistance >= secondDistance ? first : second;
|
|
468
|
+
}
|
|
469
|
+
function cloudEllipseIntersection(a, b, radiusX, radiusY, center) {
|
|
470
|
+
const scaleY = radiusX / radiusY;
|
|
471
|
+
const [x, y] = cloudCircleIntersection(
|
|
472
|
+
[a[0], a[1] * scaleY],
|
|
473
|
+
[b[0], b[1] * scaleY],
|
|
474
|
+
radiusX,
|
|
475
|
+
[center[0], center[1] * scaleY]
|
|
476
|
+
);
|
|
477
|
+
return [x, y / scaleY];
|
|
478
|
+
}
|
|
306
479
|
function buildRectSvg(width, height, style = DEFAULT_STROKE_STYLE) {
|
|
307
480
|
return `<rect width="${width}" height="${height}" fill="none" stroke="${style.stroke}" stroke-width="${style.strokeWidth}" rx="4"${strokeOpacityAttr(style)} />`;
|
|
308
481
|
}
|
|
@@ -315,40 +488,63 @@ function buildArchitecturalCloudPathD(width, height, strokeWidth = DEFAULT_STROK
|
|
|
315
488
|
const w = Math.max(0, width);
|
|
316
489
|
const h = Math.max(0, height);
|
|
317
490
|
if (w <= 0 || h <= 0) return "";
|
|
318
|
-
const
|
|
319
|
-
const
|
|
320
|
-
const
|
|
321
|
-
if (
|
|
322
|
-
const
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
outerRy * 0.45,
|
|
326
|
-
Math.max(2, Math.min(7, Math.min(w, h) * 0.035))
|
|
491
|
+
const padding = Math.max(0, strokeWidth * 2);
|
|
492
|
+
const cloudWidth = Math.max(0, w - padding);
|
|
493
|
+
const cloudHeight = Math.max(0, h - padding);
|
|
494
|
+
if (cloudWidth <= 0 || cloudHeight <= 0) return "";
|
|
495
|
+
const radiusX = Math.min(
|
|
496
|
+
ARCHITECTURAL_CLOUD_RADIUS,
|
|
497
|
+
cloudWidth * ARCHITECTURAL_CLOUD_FLAT_RADIUS_RATIO
|
|
327
498
|
);
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
const
|
|
334
|
-
const
|
|
335
|
-
const
|
|
336
|
-
const
|
|
337
|
-
const
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
499
|
+
const radiusY = Math.min(
|
|
500
|
+
ARCHITECTURAL_CLOUD_RADIUS,
|
|
501
|
+
cloudHeight * ARCHITECTURAL_CLOUD_FLAT_RADIUS_RATIO
|
|
502
|
+
);
|
|
503
|
+
if (radiusX <= 0 || radiusY <= 0) return "";
|
|
504
|
+
const center = [cloudWidth / 2, cloudHeight / 2];
|
|
505
|
+
const leftCenterX = radiusX;
|
|
506
|
+
const rightCenterX = cloudWidth - radiusX;
|
|
507
|
+
const topCenterY = radiusY;
|
|
508
|
+
const bottomCenterY = cloudHeight - radiusY;
|
|
509
|
+
const horizontalCenters = distributeRange(
|
|
510
|
+
leftCenterX,
|
|
511
|
+
rightCenterX,
|
|
512
|
+
architecturalCloudCenterCount(Math.max(0, rightCenterX - leftCenterX), radiusX)
|
|
513
|
+
);
|
|
514
|
+
const verticalCenters = distributeRange(
|
|
515
|
+
topCenterY,
|
|
516
|
+
bottomCenterY,
|
|
517
|
+
architecturalCloudCenterCount(Math.max(0, bottomCenterY - topCenterY), radiusY)
|
|
518
|
+
);
|
|
519
|
+
if (horizontalCenters.length > 3 && verticalCenters.length > 3) {
|
|
520
|
+
const roundedArcCloudPath = buildRoundedArcCloudPathD(
|
|
521
|
+
cloudWidth,
|
|
522
|
+
cloudHeight,
|
|
523
|
+
center
|
|
346
524
|
);
|
|
347
|
-
|
|
525
|
+
if (roundedArcCloudPath !== "") return roundedArcCloudPath;
|
|
526
|
+
}
|
|
527
|
+
const rectangularCenters = [
|
|
528
|
+
...horizontalCenters.map((x) => [x, topCenterY]),
|
|
529
|
+
...verticalCenters.slice(1).map((y) => [rightCenterX, y]),
|
|
530
|
+
...horizontalCenters.slice(0, -1).reverse().map((x) => [x, bottomCenterY]),
|
|
531
|
+
...verticalCenters.slice(1, -1).reverse().map((y) => [leftCenterX, y])
|
|
532
|
+
];
|
|
533
|
+
const centers = rectangularCenters;
|
|
534
|
+
const points = centers.map((point, index) => {
|
|
535
|
+
const previous = centers[(index - 1 + centers.length) % centers.length] ?? point;
|
|
536
|
+
return cloudEllipseIntersection(previous, point, radiusX, radiusY, center);
|
|
537
|
+
});
|
|
538
|
+
const [startX, startY] = points[0] ?? [0, 0];
|
|
539
|
+
const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
|
|
540
|
+
for (const [endX, endY] of points.slice(1)) {
|
|
348
541
|
segments.push(
|
|
349
|
-
`
|
|
542
|
+
`A ${svgNumber(radiusX)} ${svgNumber(radiusY)} 0 0 1 ${svgNumber(endX)} ${svgNumber(endY)}`
|
|
350
543
|
);
|
|
351
544
|
}
|
|
545
|
+
segments.push(
|
|
546
|
+
`A ${svgNumber(radiusX)} ${svgNumber(radiusY)} 0 0 1 ${svgNumber(startX)} ${svgNumber(startY)}`
|
|
547
|
+
);
|
|
352
548
|
segments.push("Z");
|
|
353
549
|
return segments.join(" ");
|
|
354
550
|
}
|
|
@@ -786,7 +982,7 @@ function createImageFromVectorTrace(id, bounds, imageVectorInnerSvg, imageVector
|
|
|
786
982
|
childrenSvg
|
|
787
983
|
};
|
|
788
984
|
}
|
|
789
|
-
var DEFAULT_STROKE_STYLE, TOOL_FREEHAND_DEFAULTS;
|
|
985
|
+
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;
|
|
790
986
|
var init_shape_builders = __esm({
|
|
791
987
|
"src/scene/shape-builders.ts"() {
|
|
792
988
|
init_rect();
|
|
@@ -802,6 +998,12 @@ var init_shape_builders = __esm({
|
|
|
802
998
|
brush: { strokeWidth: 10 },
|
|
803
999
|
marker: { stroke: "#fde047", strokeWidth: 16, strokeOpacity: 0.5 }
|
|
804
1000
|
};
|
|
1001
|
+
ARCHITECTURAL_CLOUD_RADIUS = 38;
|
|
1002
|
+
ARCHITECTURAL_CLOUD_TARGET_SPACING = 50;
|
|
1003
|
+
ARCHITECTURAL_CLOUD_FLAT_RADIUS_RATIO = 0.38;
|
|
1004
|
+
ARCHITECTURAL_CLOUD_ROUNDED_RADIUS = 72;
|
|
1005
|
+
ARCHITECTURAL_CLOUD_ROUNDED_MIN_RADIUS = 44;
|
|
1006
|
+
ARCHITECTURAL_CLOUD_ROUNDED_TARGET_SPACING = 98;
|
|
805
1007
|
}
|
|
806
1008
|
});
|
|
807
1009
|
|
|
@@ -3106,7 +3308,7 @@ function ShapeContextMenu({
|
|
|
3106
3308
|
}
|
|
3107
3309
|
return createPortal(menu, document.body);
|
|
3108
3310
|
}
|
|
3109
|
-
var architecturalCloudIconPath = "
|
|
3311
|
+
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";
|
|
3110
3312
|
var base = {
|
|
3111
3313
|
width: 20,
|
|
3112
3314
|
height: 20,
|
|
@@ -3138,7 +3340,7 @@ function IconEllipse(props) {
|
|
|
3138
3340
|
return /* @__PURE__ */ jsx("svg", { ...base, ...props, "aria-hidden": true, children: /* @__PURE__ */ jsx("ellipse", { cx: "12", cy: "12", rx: "9", ry: "6" }) });
|
|
3139
3341
|
}
|
|
3140
3342
|
function IconArchitecturalCloud(props) {
|
|
3141
|
-
return /* @__PURE__ */ jsx("svg", { ...base, ...props, "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: architecturalCloudIconPath
|
|
3343
|
+
return /* @__PURE__ */ jsx("svg", { ...base, ...props, "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: architecturalCloudIconPath }) });
|
|
3142
3344
|
}
|
|
3143
3345
|
function IconLine(props) {
|
|
3144
3346
|
return /* @__PURE__ */ jsx("svg", { ...base, ...props, "aria-hidden": true, children: /* @__PURE__ */ jsx("line", { x1: "5", y1: "19", x2: "19", y2: "5" }) });
|