canvu-react 0.3.33 → 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 +233 -159
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +233 -159
- package/dist/index.js.map +1 -1
- package/dist/native.cjs +233 -159
- package/dist/native.cjs.map +1 -1
- package/dist/native.js +233 -159
- package/dist/native.js.map +1 -1
- package/dist/react.cjs +236 -162
- package/dist/react.cjs.map +1 -1
- package/dist/react.js +236 -162
- 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 +235 -161
- package/dist/tldraw.cjs.map +1 -1
- package/dist/tldraw.js +235 -161
- package/dist/tldraw.js.map +1 -1
- package/package.json +1 -1
package/dist/tldraw.cjs
CHANGED
|
@@ -228,153 +228,203 @@ function svgNumber(value) {
|
|
|
228
228
|
const rounded = Math.round(value * 100) / 100;
|
|
229
229
|
return Number.isInteger(rounded) ? String(rounded) : String(rounded);
|
|
230
230
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
function
|
|
238
|
-
const
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
const bottom = height - inset;
|
|
242
|
-
const rectWidth = Math.max(0, right - left);
|
|
243
|
-
const rectHeight = Math.max(0, bottom - top);
|
|
244
|
-
const normalizedRadius = Math.max(
|
|
245
|
-
0,
|
|
246
|
-
Math.min(radius, rectWidth / 2, rectHeight / 2)
|
|
231
|
+
var ARCHITECTURAL_CLOUD_RADIUS = 38;
|
|
232
|
+
var ARCHITECTURAL_CLOUD_TARGET_SPACING = 50;
|
|
233
|
+
var ARCHITECTURAL_CLOUD_FLAT_RADIUS_RATIO = 0.38;
|
|
234
|
+
var ARCHITECTURAL_CLOUD_ROUNDED_RADIUS = 72;
|
|
235
|
+
var ARCHITECTURAL_CLOUD_ROUNDED_MIN_RADIUS = 44;
|
|
236
|
+
var ARCHITECTURAL_CLOUD_ROUNDED_TARGET_SPACING = 98;
|
|
237
|
+
function architecturalCloudCenterCount(edgeLength, radius) {
|
|
238
|
+
const targetSpacing = Math.min(
|
|
239
|
+
ARCHITECTURAL_CLOUD_TARGET_SPACING,
|
|
240
|
+
Math.max(1, radius * 1.3)
|
|
247
241
|
);
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
const
|
|
242
|
+
return Math.max(2, Math.round(edgeLength / targetSpacing) + 1);
|
|
243
|
+
}
|
|
244
|
+
function distributeRange(start, end, count) {
|
|
245
|
+
if (count <= 1) return [start];
|
|
246
|
+
const step = (end - start) / (count - 1);
|
|
247
|
+
return Array.from({ length: count }, (_, index) => start + step * index);
|
|
248
|
+
}
|
|
249
|
+
function lineCloudPathSegment(start, end) {
|
|
250
|
+
const dx = end[0] - start[0];
|
|
251
|
+
const dy = end[1] - start[1];
|
|
252
|
+
const length = Math.hypot(dx, dy);
|
|
253
253
|
return {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
right,
|
|
257
|
-
bottom,
|
|
258
|
-
radius: normalizedRadius,
|
|
259
|
-
centerX,
|
|
260
|
-
topHalfLength,
|
|
261
|
-
horizontalLength,
|
|
262
|
-
verticalLength,
|
|
263
|
-
arcLength,
|
|
264
|
-
perimeter: horizontalLength * 2 + verticalLength * 2 + Math.PI * 2 * normalizedRadius
|
|
254
|
+
length,
|
|
255
|
+
pointAt: (t) => [start[0] + dx * t, start[1] + dy * t]
|
|
265
256
|
};
|
|
266
257
|
}
|
|
267
|
-
function
|
|
268
|
-
return [
|
|
269
|
-
}
|
|
270
|
-
function
|
|
271
|
-
const
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
let
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
258
|
+
function ellipsePoint(centerX, centerY, radiusX, radiusY, angle) {
|
|
259
|
+
return [centerX + Math.cos(angle) * radiusX, centerY + Math.sin(angle) * radiusY];
|
|
260
|
+
}
|
|
261
|
+
function approximateEllipseArcLength(radiusX, radiusY, startAngle, endAngle) {
|
|
262
|
+
const steps = Math.max(
|
|
263
|
+
4,
|
|
264
|
+
Math.ceil(Math.abs(endAngle - startAngle) / (Math.PI / 16))
|
|
265
|
+
);
|
|
266
|
+
let length = 0;
|
|
267
|
+
let previous = ellipsePoint(0, 0, radiusX, radiusY, startAngle);
|
|
268
|
+
for (let index = 1; index <= steps; index += 1) {
|
|
269
|
+
const angle = startAngle + (endAngle - startAngle) * index / steps;
|
|
270
|
+
const next = ellipsePoint(0, 0, radiusX, radiusY, angle);
|
|
271
|
+
length += Math.hypot(next[0] - previous[0], next[1] - previous[1]);
|
|
272
|
+
previous = next;
|
|
273
|
+
}
|
|
274
|
+
return length;
|
|
275
|
+
}
|
|
276
|
+
function ellipseCloudPathSegment(centerX, centerY, radiusX, radiusY, startAngle, endAngle) {
|
|
277
|
+
return {
|
|
278
|
+
length: approximateEllipseArcLength(radiusX, radiusY, startAngle, endAngle),
|
|
279
|
+
pointAt: (t) => ellipsePoint(
|
|
280
|
+
centerX,
|
|
281
|
+
centerY,
|
|
282
|
+
radiusX,
|
|
283
|
+
radiusY,
|
|
284
|
+
startAngle + (endAngle - startAngle) * t
|
|
285
|
+
)
|
|
282
286
|
};
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
287
|
+
}
|
|
288
|
+
function cloudPathPerimeter(segments) {
|
|
289
|
+
const usableSegments = segments.filter((segment) => segment.length > 1e-9);
|
|
290
|
+
return usableSegments.reduce((sum, segment) => sum + segment.length, 0);
|
|
291
|
+
}
|
|
292
|
+
function pointOnCloudPath(segments, distance) {
|
|
293
|
+
const perimeter = cloudPathPerimeter(segments);
|
|
294
|
+
if (perimeter <= 0) return [0, 0];
|
|
295
|
+
let remaining = (distance % perimeter + perimeter) % perimeter;
|
|
296
|
+
for (const segment of segments) {
|
|
297
|
+
if (segment.length <= 1e-9) continue;
|
|
298
|
+
if (remaining <= segment.length) {
|
|
299
|
+
const t = remaining / segment.length;
|
|
300
|
+
return segment.pointAt(t);
|
|
301
|
+
}
|
|
302
|
+
remaining -= segment.length;
|
|
292
303
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
304
|
+
const fallback = segments.find((segment) => segment.length > 1e-9);
|
|
305
|
+
return fallback?.pointAt(0) ?? [0, 0];
|
|
306
|
+
}
|
|
307
|
+
function buildRoundedCapsulePathSegments(width, height, inset) {
|
|
308
|
+
const left = inset;
|
|
309
|
+
const top = inset;
|
|
310
|
+
const right = width - inset;
|
|
311
|
+
const bottom = height - inset;
|
|
312
|
+
const capsuleWidth = Math.max(0, right - left);
|
|
313
|
+
const capsuleHeight = Math.max(0, bottom - top);
|
|
314
|
+
const radius = Math.min(capsuleWidth, capsuleHeight) / 2;
|
|
315
|
+
if (radius <= 0) return [];
|
|
316
|
+
const leftCenterX = left + radius;
|
|
317
|
+
const rightCenterX = right - radius;
|
|
318
|
+
const topCenterY = top + radius;
|
|
319
|
+
const bottomCenterY = bottom - radius;
|
|
320
|
+
return [
|
|
321
|
+
lineCloudPathSegment([leftCenterX, top], [rightCenterX, top]),
|
|
322
|
+
ellipseCloudPathSegment(
|
|
323
|
+
rightCenterX,
|
|
324
|
+
topCenterY,
|
|
325
|
+
radius,
|
|
326
|
+
radius,
|
|
299
327
|
-Math.PI / 2,
|
|
328
|
+
0
|
|
329
|
+
),
|
|
330
|
+
lineCloudPathSegment([right, topCenterY], [right, bottomCenterY]),
|
|
331
|
+
ellipseCloudPathSegment(
|
|
332
|
+
rightCenterX,
|
|
333
|
+
bottomCenterY,
|
|
334
|
+
radius,
|
|
335
|
+
radius,
|
|
300
336
|
0,
|
|
301
|
-
|
|
302
|
-
)
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
metrics.right,
|
|
310
|
-
metrics.bottom - metrics.radius,
|
|
311
|
-
t
|
|
312
|
-
);
|
|
313
|
-
}
|
|
314
|
-
t = consume(metrics.arcLength);
|
|
315
|
-
if (t != null) {
|
|
316
|
-
return pointOnArc(
|
|
317
|
-
metrics.right - metrics.radius,
|
|
318
|
-
metrics.bottom - metrics.radius,
|
|
319
|
-
metrics.radius,
|
|
320
|
-
0,
|
|
321
|
-
Math.PI / 2,
|
|
322
|
-
t
|
|
323
|
-
);
|
|
324
|
-
}
|
|
325
|
-
t = consume(metrics.horizontalLength);
|
|
326
|
-
if (t != null) {
|
|
327
|
-
return pointOnLine(
|
|
328
|
-
metrics.right - metrics.radius,
|
|
329
|
-
metrics.bottom,
|
|
330
|
-
metrics.left + metrics.radius,
|
|
331
|
-
metrics.bottom,
|
|
332
|
-
t
|
|
333
|
-
);
|
|
334
|
-
}
|
|
335
|
-
t = consume(metrics.arcLength);
|
|
336
|
-
if (t != null) {
|
|
337
|
-
return pointOnArc(
|
|
338
|
-
metrics.left + metrics.radius,
|
|
339
|
-
metrics.bottom - metrics.radius,
|
|
340
|
-
metrics.radius,
|
|
337
|
+
Math.PI / 2
|
|
338
|
+
),
|
|
339
|
+
lineCloudPathSegment([rightCenterX, bottom], [leftCenterX, bottom]),
|
|
340
|
+
ellipseCloudPathSegment(
|
|
341
|
+
leftCenterX,
|
|
342
|
+
bottomCenterY,
|
|
343
|
+
radius,
|
|
344
|
+
radius,
|
|
341
345
|
Math.PI / 2,
|
|
346
|
+
Math.PI
|
|
347
|
+
),
|
|
348
|
+
lineCloudPathSegment([left, bottomCenterY], [left, topCenterY]),
|
|
349
|
+
ellipseCloudPathSegment(
|
|
350
|
+
leftCenterX,
|
|
351
|
+
topCenterY,
|
|
352
|
+
radius,
|
|
353
|
+
radius,
|
|
342
354
|
Math.PI,
|
|
343
|
-
|
|
344
|
-
)
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
355
|
+
Math.PI * 1.5
|
|
356
|
+
)
|
|
357
|
+
];
|
|
358
|
+
}
|
|
359
|
+
function buildRoundedArcCloudPathD(cloudWidth, cloudHeight, center) {
|
|
360
|
+
const minDimension = Math.min(cloudWidth, cloudHeight);
|
|
361
|
+
const radius = Math.min(
|
|
362
|
+
ARCHITECTURAL_CLOUD_ROUNDED_RADIUS,
|
|
363
|
+
Math.max(ARCHITECTURAL_CLOUD_ROUNDED_MIN_RADIUS, minDimension * 0.16)
|
|
364
|
+
);
|
|
365
|
+
const centerPath = buildRoundedCapsulePathSegments(
|
|
366
|
+
cloudWidth,
|
|
367
|
+
cloudHeight,
|
|
368
|
+
radius
|
|
369
|
+
);
|
|
370
|
+
const centerPerimeter = cloudPathPerimeter(centerPath);
|
|
371
|
+
if (centerPerimeter <= 0) return "";
|
|
372
|
+
const lobeCount = Math.max(
|
|
373
|
+
8,
|
|
374
|
+
Math.round(centerPerimeter / ARCHITECTURAL_CLOUD_ROUNDED_TARGET_SPACING)
|
|
375
|
+
);
|
|
376
|
+
const centers = Array.from(
|
|
377
|
+
{ length: lobeCount },
|
|
378
|
+
(_, index) => pointOnCloudPath(centerPath, centerPerimeter * index / lobeCount)
|
|
379
|
+
);
|
|
380
|
+
const points = centers.map((point, index) => {
|
|
381
|
+
const previous = centers[(index - 1 + centers.length) % centers.length] ?? point;
|
|
382
|
+
return cloudCircleIntersection(previous, point, radius, center);
|
|
383
|
+
});
|
|
384
|
+
const [startX, startY] = points[0] ?? [0, 0];
|
|
385
|
+
const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
|
|
386
|
+
for (const [endX, endY] of points.slice(1)) {
|
|
387
|
+
segments.push(
|
|
388
|
+
`A ${svgNumber(radius)} ${svgNumber(radius)} 0 0 1 ${svgNumber(endX)} ${svgNumber(endY)}`
|
|
375
389
|
);
|
|
376
390
|
}
|
|
377
|
-
|
|
391
|
+
segments.push(
|
|
392
|
+
`A ${svgNumber(radius)} ${svgNumber(radius)} 0 0 1 ${svgNumber(startX)} ${svgNumber(startY)}`
|
|
393
|
+
);
|
|
394
|
+
segments.push("Z");
|
|
395
|
+
return segments.join(" ");
|
|
396
|
+
}
|
|
397
|
+
function cloudCircleIntersection(a, b, radius, center) {
|
|
398
|
+
const midX = (a[0] + b[0]) / 2;
|
|
399
|
+
const midY = (a[1] + b[1]) / 2;
|
|
400
|
+
const dx = b[0] - a[0];
|
|
401
|
+
const dy = b[1] - a[1];
|
|
402
|
+
const distance = Math.hypot(dx, dy);
|
|
403
|
+
if (distance <= 1e-9) return [midX, midY];
|
|
404
|
+
const halfDistance = distance / 2;
|
|
405
|
+
const offset = Math.sqrt(
|
|
406
|
+
Math.max(0, radius * radius - halfDistance * halfDistance)
|
|
407
|
+
);
|
|
408
|
+
const normalX = -dy / distance;
|
|
409
|
+
const normalY = dx / distance;
|
|
410
|
+
const first = [midX + normalX * offset, midY + normalY * offset];
|
|
411
|
+
const second = [
|
|
412
|
+
midX - normalX * offset,
|
|
413
|
+
midY - normalY * offset
|
|
414
|
+
];
|
|
415
|
+
const firstDistance = (first[0] - center[0]) * (first[0] - center[0]) + (first[1] - center[1]) * (first[1] - center[1]);
|
|
416
|
+
const secondDistance = (second[0] - center[0]) * (second[0] - center[0]) + (second[1] - center[1]) * (second[1] - center[1]);
|
|
417
|
+
return firstDistance >= secondDistance ? first : second;
|
|
418
|
+
}
|
|
419
|
+
function cloudEllipseIntersection(a, b, radiusX, radiusY, center) {
|
|
420
|
+
const scaleY = radiusX / radiusY;
|
|
421
|
+
const [x, y] = cloudCircleIntersection(
|
|
422
|
+
[a[0], a[1] * scaleY],
|
|
423
|
+
[b[0], b[1] * scaleY],
|
|
424
|
+
radiusX,
|
|
425
|
+
[center[0], center[1] * scaleY]
|
|
426
|
+
);
|
|
427
|
+
return [x, y / scaleY];
|
|
378
428
|
}
|
|
379
429
|
function buildRectSvg(width, height, style = DEFAULT_STROKE_STYLE) {
|
|
380
430
|
return `<rect width="${width}" height="${height}" fill="none" stroke="${style.stroke}" stroke-width="${style.strokeWidth}" rx="4"${strokeOpacityAttr(style)} />`;
|
|
@@ -388,39 +438,63 @@ function buildArchitecturalCloudPathD(width, height, strokeWidth = DEFAULT_STROK
|
|
|
388
438
|
const w = Math.max(0, width);
|
|
389
439
|
const h = Math.max(0, height);
|
|
390
440
|
if (w <= 0 || h <= 0) return "";
|
|
391
|
-
const
|
|
392
|
-
const
|
|
393
|
-
const
|
|
394
|
-
if (
|
|
395
|
-
const
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
Math.max(5, Math.min(14, Math.min(w, h) * 0.07))
|
|
441
|
+
const padding = Math.max(0, strokeWidth * 2);
|
|
442
|
+
const cloudWidth = Math.max(0, w - padding);
|
|
443
|
+
const cloudHeight = Math.max(0, h - padding);
|
|
444
|
+
if (cloudWidth <= 0 || cloudHeight <= 0) return "";
|
|
445
|
+
const radiusX = Math.min(
|
|
446
|
+
ARCHITECTURAL_CLOUD_RADIUS,
|
|
447
|
+
cloudWidth * ARCHITECTURAL_CLOUD_FLAT_RADIUS_RATIO
|
|
399
448
|
);
|
|
400
|
-
const
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
449
|
+
const radiusY = Math.min(
|
|
450
|
+
ARCHITECTURAL_CLOUD_RADIUS,
|
|
451
|
+
cloudHeight * ARCHITECTURAL_CLOUD_FLAT_RADIUS_RATIO
|
|
452
|
+
);
|
|
453
|
+
if (radiusX <= 0 || radiusY <= 0) return "";
|
|
454
|
+
const center = [cloudWidth / 2, cloudHeight / 2];
|
|
455
|
+
const leftCenterX = radiusX;
|
|
456
|
+
const rightCenterX = cloudWidth - radiusX;
|
|
457
|
+
const topCenterY = radiusY;
|
|
458
|
+
const bottomCenterY = cloudHeight - radiusY;
|
|
459
|
+
const horizontalCenters = distributeRange(
|
|
460
|
+
leftCenterX,
|
|
461
|
+
rightCenterX,
|
|
462
|
+
architecturalCloudCenterCount(Math.max(0, rightCenterX - leftCenterX), radiusX)
|
|
404
463
|
);
|
|
405
|
-
const
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
inset + amplitude,
|
|
410
|
-
Math.max(0, radius - amplitude)
|
|
464
|
+
const verticalCenters = distributeRange(
|
|
465
|
+
topCenterY,
|
|
466
|
+
bottomCenterY,
|
|
467
|
+
architecturalCloudCenterCount(Math.max(0, bottomCenterY - topCenterY), radiusY)
|
|
411
468
|
);
|
|
412
|
-
|
|
413
|
-
|
|
469
|
+
if (horizontalCenters.length > 3 && verticalCenters.length > 3) {
|
|
470
|
+
const roundedArcCloudPath = buildRoundedArcCloudPathD(
|
|
471
|
+
cloudWidth,
|
|
472
|
+
cloudHeight,
|
|
473
|
+
center
|
|
474
|
+
);
|
|
475
|
+
if (roundedArcCloudPath !== "") return roundedArcCloudPath;
|
|
476
|
+
}
|
|
477
|
+
const rectangularCenters = [
|
|
478
|
+
...horizontalCenters.map((x) => [x, topCenterY]),
|
|
479
|
+
...verticalCenters.slice(1).map((y) => [rightCenterX, y]),
|
|
480
|
+
...horizontalCenters.slice(0, -1).reverse().map((x) => [x, bottomCenterY]),
|
|
481
|
+
...verticalCenters.slice(1, -1).reverse().map((y) => [leftCenterX, y])
|
|
482
|
+
];
|
|
483
|
+
const centers = rectangularCenters;
|
|
484
|
+
const points = centers.map((point, index) => {
|
|
485
|
+
const previous = centers[(index - 1 + centers.length) % centers.length] ?? point;
|
|
486
|
+
return cloudEllipseIntersection(previous, point, radiusX, radiusY, center);
|
|
487
|
+
});
|
|
488
|
+
const [startX, startY] = points[0] ?? [0, 0];
|
|
414
489
|
const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
|
|
415
|
-
for (
|
|
416
|
-
const controlDistance = (index + 0.5) / scallopCount * outer.perimeter;
|
|
417
|
-
const endDistance = (index + 1) / scallopCount * inner.perimeter;
|
|
418
|
-
const [controlX, controlY] = pointOnRoundedRectPath(outer, controlDistance);
|
|
419
|
-
const [endX, endY] = pointOnRoundedRectPath(inner, endDistance);
|
|
490
|
+
for (const [endX, endY] of points.slice(1)) {
|
|
420
491
|
segments.push(
|
|
421
|
-
`
|
|
492
|
+
`A ${svgNumber(radiusX)} ${svgNumber(radiusY)} 0 0 1 ${svgNumber(endX)} ${svgNumber(endY)}`
|
|
422
493
|
);
|
|
423
494
|
}
|
|
495
|
+
segments.push(
|
|
496
|
+
`A ${svgNumber(radiusX)} ${svgNumber(radiusY)} 0 0 1 ${svgNumber(startX)} ${svgNumber(startY)}`
|
|
497
|
+
);
|
|
424
498
|
segments.push("Z");
|
|
425
499
|
return segments.join(" ");
|
|
426
500
|
}
|