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/react.cjs
CHANGED
|
@@ -291,24 +291,153 @@ function svgNumber(value) {
|
|
|
291
291
|
const rounded = Math.round(value * 100) / 100;
|
|
292
292
|
return Number.isInteger(rounded) ? String(rounded) : String(rounded);
|
|
293
293
|
}
|
|
294
|
-
function
|
|
295
|
-
|
|
296
|
-
return Math.PI * (3 * (rx + ry) - Math.sqrt((3 * rx + ry) * (rx + 3 * ry)));
|
|
297
|
-
}
|
|
298
|
-
function architecturalCloudScallopCount(rx, ry, amplitude) {
|
|
299
|
-
const perimeter = approximateEllipsePerimeter(rx, ry);
|
|
300
|
-
const targetScallopLength = Math.max(10, amplitude * 2);
|
|
294
|
+
function architecturalCloudScallopCount(perimeter, amplitude) {
|
|
295
|
+
const targetScallopLength = Math.max(18, amplitude * 2.45);
|
|
301
296
|
let count = Math.max(12, Math.round(perimeter / targetScallopLength));
|
|
302
297
|
if (count % 2 === 1) count += 1;
|
|
303
298
|
return count;
|
|
304
299
|
}
|
|
305
|
-
function
|
|
306
|
-
const
|
|
307
|
-
const
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
300
|
+
function roundedRectMetrics(width, height, inset, radius) {
|
|
301
|
+
const left = inset;
|
|
302
|
+
const top = inset;
|
|
303
|
+
const right = width - inset;
|
|
304
|
+
const bottom = height - inset;
|
|
305
|
+
const rectWidth = Math.max(0, right - left);
|
|
306
|
+
const rectHeight = Math.max(0, bottom - top);
|
|
307
|
+
const normalizedRadius = Math.max(
|
|
308
|
+
0,
|
|
309
|
+
Math.min(radius, rectWidth / 2, rectHeight / 2)
|
|
310
|
+
);
|
|
311
|
+
const centerX = width / 2;
|
|
312
|
+
const topHalfLength = Math.max(0, right - normalizedRadius - centerX);
|
|
313
|
+
const horizontalLength = Math.max(0, rectWidth - normalizedRadius * 2);
|
|
314
|
+
const verticalLength = Math.max(0, rectHeight - normalizedRadius * 2);
|
|
315
|
+
const arcLength = normalizedRadius * (Math.PI / 2);
|
|
316
|
+
return {
|
|
317
|
+
left,
|
|
318
|
+
top,
|
|
319
|
+
right,
|
|
320
|
+
bottom,
|
|
321
|
+
radius: normalizedRadius,
|
|
322
|
+
centerX,
|
|
323
|
+
topHalfLength,
|
|
324
|
+
horizontalLength,
|
|
325
|
+
verticalLength,
|
|
326
|
+
arcLength,
|
|
327
|
+
perimeter: horizontalLength * 2 + verticalLength * 2 + Math.PI * 2 * normalizedRadius
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
function pointOnLine(startX, startY, endX, endY, t) {
|
|
331
|
+
return [startX + (endX - startX) * t, startY + (endY - startY) * t];
|
|
332
|
+
}
|
|
333
|
+
function pointOnArc(centerX, centerY, radius, startAngle, endAngle, t) {
|
|
334
|
+
const theta = startAngle + (endAngle - startAngle) * t;
|
|
335
|
+
return [centerX + Math.cos(theta) * radius, centerY + Math.sin(theta) * radius];
|
|
336
|
+
}
|
|
337
|
+
function pointOnRoundedRectPath(metrics, distance) {
|
|
338
|
+
if (metrics.perimeter <= 0) return [metrics.centerX, metrics.top];
|
|
339
|
+
let remaining = (distance % metrics.perimeter + metrics.perimeter) % metrics.perimeter;
|
|
340
|
+
const consume = (length) => {
|
|
341
|
+
if (length <= 1e-9) return null;
|
|
342
|
+
if (remaining <= length) return remaining / length;
|
|
343
|
+
remaining -= length;
|
|
344
|
+
return null;
|
|
345
|
+
};
|
|
346
|
+
let t = consume(metrics.topHalfLength);
|
|
347
|
+
if (t != null) {
|
|
348
|
+
return pointOnLine(
|
|
349
|
+
metrics.centerX,
|
|
350
|
+
metrics.top,
|
|
351
|
+
metrics.right - metrics.radius,
|
|
352
|
+
metrics.top,
|
|
353
|
+
t
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
t = consume(metrics.arcLength);
|
|
357
|
+
if (t != null) {
|
|
358
|
+
return pointOnArc(
|
|
359
|
+
metrics.right - metrics.radius,
|
|
360
|
+
metrics.top + metrics.radius,
|
|
361
|
+
metrics.radius,
|
|
362
|
+
-Math.PI / 2,
|
|
363
|
+
0,
|
|
364
|
+
t
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
t = consume(metrics.verticalLength);
|
|
368
|
+
if (t != null) {
|
|
369
|
+
return pointOnLine(
|
|
370
|
+
metrics.right,
|
|
371
|
+
metrics.top + metrics.radius,
|
|
372
|
+
metrics.right,
|
|
373
|
+
metrics.bottom - metrics.radius,
|
|
374
|
+
t
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
t = consume(metrics.arcLength);
|
|
378
|
+
if (t != null) {
|
|
379
|
+
return pointOnArc(
|
|
380
|
+
metrics.right - metrics.radius,
|
|
381
|
+
metrics.bottom - metrics.radius,
|
|
382
|
+
metrics.radius,
|
|
383
|
+
0,
|
|
384
|
+
Math.PI / 2,
|
|
385
|
+
t
|
|
386
|
+
);
|
|
387
|
+
}
|
|
388
|
+
t = consume(metrics.horizontalLength);
|
|
389
|
+
if (t != null) {
|
|
390
|
+
return pointOnLine(
|
|
391
|
+
metrics.right - metrics.radius,
|
|
392
|
+
metrics.bottom,
|
|
393
|
+
metrics.left + metrics.radius,
|
|
394
|
+
metrics.bottom,
|
|
395
|
+
t
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
t = consume(metrics.arcLength);
|
|
399
|
+
if (t != null) {
|
|
400
|
+
return pointOnArc(
|
|
401
|
+
metrics.left + metrics.radius,
|
|
402
|
+
metrics.bottom - metrics.radius,
|
|
403
|
+
metrics.radius,
|
|
404
|
+
Math.PI / 2,
|
|
405
|
+
Math.PI,
|
|
406
|
+
t
|
|
407
|
+
);
|
|
408
|
+
}
|
|
409
|
+
t = consume(metrics.verticalLength);
|
|
410
|
+
if (t != null) {
|
|
411
|
+
return pointOnLine(
|
|
412
|
+
metrics.left,
|
|
413
|
+
metrics.bottom - metrics.radius,
|
|
414
|
+
metrics.left,
|
|
415
|
+
metrics.top + metrics.radius,
|
|
416
|
+
t
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
t = consume(metrics.arcLength);
|
|
420
|
+
if (t != null) {
|
|
421
|
+
return pointOnArc(
|
|
422
|
+
metrics.left + metrics.radius,
|
|
423
|
+
metrics.top + metrics.radius,
|
|
424
|
+
metrics.radius,
|
|
425
|
+
Math.PI,
|
|
426
|
+
Math.PI * 1.5,
|
|
427
|
+
t
|
|
428
|
+
);
|
|
429
|
+
}
|
|
430
|
+
t = consume(metrics.topHalfLength);
|
|
431
|
+
if (t != null) {
|
|
432
|
+
return pointOnLine(
|
|
433
|
+
metrics.left + metrics.radius,
|
|
434
|
+
metrics.top,
|
|
435
|
+
metrics.centerX,
|
|
436
|
+
metrics.top,
|
|
437
|
+
t
|
|
438
|
+
);
|
|
439
|
+
}
|
|
440
|
+
return [metrics.centerX, metrics.top];
|
|
312
441
|
}
|
|
313
442
|
function buildRectSvg(width, height, style = DEFAULT_STROKE_STYLE) {
|
|
314
443
|
return `<rect width="${width}" height="${height}" fill="none" stroke="${style.stroke}" stroke-width="${style.strokeWidth}" rx="4"${strokeOpacityAttr(style)} />`;
|
|
@@ -323,35 +452,34 @@ function buildArchitecturalCloudPathD(width, height, strokeWidth = DEFAULT_STROK
|
|
|
323
452
|
const h = Math.max(0, height);
|
|
324
453
|
if (w <= 0 || h <= 0) return "";
|
|
325
454
|
const inset = Math.max(0.5, strokeWidth / 2);
|
|
326
|
-
const
|
|
327
|
-
const
|
|
328
|
-
if (
|
|
329
|
-
const baseExponent = 3.6;
|
|
455
|
+
const outerWidth = Math.max(0, w - inset * 2);
|
|
456
|
+
const outerHeight = Math.max(0, h - inset * 2);
|
|
457
|
+
if (outerWidth <= 0 || outerHeight <= 0) return "";
|
|
330
458
|
const amplitude = Math.min(
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
Math.max(
|
|
459
|
+
outerWidth * 0.12,
|
|
460
|
+
outerHeight * 0.12,
|
|
461
|
+
Math.max(5, Math.min(14, Math.min(w, h) * 0.07))
|
|
334
462
|
);
|
|
335
|
-
const
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
const
|
|
341
|
-
const
|
|
342
|
-
|
|
343
|
-
|
|
463
|
+
const radius = Math.min(
|
|
464
|
+
outerWidth / 2,
|
|
465
|
+
outerHeight / 2,
|
|
466
|
+
Math.max(amplitude * 2.5, outerHeight * 0.43)
|
|
467
|
+
);
|
|
468
|
+
const outer = roundedRectMetrics(w, h, inset, radius);
|
|
469
|
+
const inner = roundedRectMetrics(
|
|
470
|
+
w,
|
|
471
|
+
h,
|
|
472
|
+
inset + amplitude,
|
|
473
|
+
Math.max(0, radius - amplitude)
|
|
474
|
+
);
|
|
475
|
+
const scallopCount = architecturalCloudScallopCount(outer.perimeter, amplitude);
|
|
476
|
+
const [startX, startY] = pointOnRoundedRectPath(inner, 0);
|
|
344
477
|
const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
|
|
345
478
|
for (let index = 0; index < scallopCount; index += 1) {
|
|
346
|
-
const
|
|
347
|
-
const
|
|
348
|
-
const
|
|
349
|
-
const [
|
|
350
|
-
segmentMid,
|
|
351
|
-
outerRx,
|
|
352
|
-
outerRy
|
|
353
|
-
);
|
|
354
|
-
const [endX, endY] = pointOnArchitecturalCloud(segmentEnd, innerRx, innerRy);
|
|
479
|
+
const controlDistance = (index + 0.5) / scallopCount * outer.perimeter;
|
|
480
|
+
const endDistance = (index + 1) / scallopCount * inner.perimeter;
|
|
481
|
+
const [controlX, controlY] = pointOnRoundedRectPath(outer, controlDistance);
|
|
482
|
+
const [endX, endY] = pointOnRoundedRectPath(inner, endDistance);
|
|
355
483
|
segments.push(
|
|
356
484
|
`Q${svgNumber(controlX)} ${svgNumber(controlY)} ${svgNumber(endX)} ${svgNumber(endY)}`
|
|
357
485
|
);
|
|
@@ -3113,7 +3241,7 @@ function ShapeContextMenu({
|
|
|
3113
3241
|
}
|
|
3114
3242
|
return reactDom.createPortal(menu, document.body);
|
|
3115
3243
|
}
|
|
3116
|
-
var architecturalCloudIconPath = "M11
|
|
3244
|
+
var architecturalCloudIconPath = "M11 2.44 Q13.3 1 14.84 2.44 Q17.84 1.4 18.41 3.47 Q20.8 4.72 19.56 7 Q20.8 9.28 18.41 10.53 Q17.84 12.6 14.84 11.56 Q13.3 13 11 11.56 Q8.7 13 7.16 11.56 Q4.16 12.6 3.59 10.53 Q1.2 9.28 2.44 7 Q1.2 4.72 3.59 3.47 Q4.16 1.4 7.16 2.44 Q8.7 1 11 2.44 Z";
|
|
3117
3245
|
var base = {
|
|
3118
3246
|
width: 20,
|
|
3119
3247
|
height: 20,
|