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