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.js
CHANGED
|
@@ -284,24 +284,153 @@ 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
|
-
return Math.PI * (3 * (rx + ry) - Math.sqrt((3 * rx + ry) * (rx + 3 * ry)));
|
|
290
|
-
}
|
|
291
|
-
function architecturalCloudScallopCount(rx, ry, amplitude) {
|
|
292
|
-
const perimeter = approximateEllipsePerimeter(rx, ry);
|
|
293
|
-
const targetScallopLength = Math.max(10, amplitude * 2);
|
|
287
|
+
function architecturalCloudScallopCount(perimeter, amplitude) {
|
|
288
|
+
const targetScallopLength = Math.max(18, amplitude * 2.45);
|
|
294
289
|
let count = Math.max(12, Math.round(perimeter / targetScallopLength));
|
|
295
290
|
if (count % 2 === 1) count += 1;
|
|
296
291
|
return count;
|
|
297
292
|
}
|
|
298
|
-
function
|
|
299
|
-
const
|
|
300
|
-
const
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
293
|
+
function roundedRectMetrics(width, height, inset, radius) {
|
|
294
|
+
const left = inset;
|
|
295
|
+
const top = inset;
|
|
296
|
+
const right = width - inset;
|
|
297
|
+
const bottom = height - inset;
|
|
298
|
+
const rectWidth = Math.max(0, right - left);
|
|
299
|
+
const rectHeight = Math.max(0, bottom - top);
|
|
300
|
+
const normalizedRadius = Math.max(
|
|
301
|
+
0,
|
|
302
|
+
Math.min(radius, rectWidth / 2, rectHeight / 2)
|
|
303
|
+
);
|
|
304
|
+
const centerX = width / 2;
|
|
305
|
+
const topHalfLength = Math.max(0, right - normalizedRadius - centerX);
|
|
306
|
+
const horizontalLength = Math.max(0, rectWidth - normalizedRadius * 2);
|
|
307
|
+
const verticalLength = Math.max(0, rectHeight - normalizedRadius * 2);
|
|
308
|
+
const arcLength = normalizedRadius * (Math.PI / 2);
|
|
309
|
+
return {
|
|
310
|
+
left,
|
|
311
|
+
top,
|
|
312
|
+
right,
|
|
313
|
+
bottom,
|
|
314
|
+
radius: normalizedRadius,
|
|
315
|
+
centerX,
|
|
316
|
+
topHalfLength,
|
|
317
|
+
horizontalLength,
|
|
318
|
+
verticalLength,
|
|
319
|
+
arcLength,
|
|
320
|
+
perimeter: horizontalLength * 2 + verticalLength * 2 + Math.PI * 2 * normalizedRadius
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
function pointOnLine(startX, startY, endX, endY, t) {
|
|
324
|
+
return [startX + (endX - startX) * t, startY + (endY - startY) * t];
|
|
325
|
+
}
|
|
326
|
+
function pointOnArc(centerX, centerY, radius, startAngle, endAngle, t) {
|
|
327
|
+
const theta = startAngle + (endAngle - startAngle) * t;
|
|
328
|
+
return [centerX + Math.cos(theta) * radius, centerY + Math.sin(theta) * radius];
|
|
329
|
+
}
|
|
330
|
+
function pointOnRoundedRectPath(metrics, distance) {
|
|
331
|
+
if (metrics.perimeter <= 0) return [metrics.centerX, metrics.top];
|
|
332
|
+
let remaining = (distance % metrics.perimeter + metrics.perimeter) % metrics.perimeter;
|
|
333
|
+
const consume = (length) => {
|
|
334
|
+
if (length <= 1e-9) return null;
|
|
335
|
+
if (remaining <= length) return remaining / length;
|
|
336
|
+
remaining -= length;
|
|
337
|
+
return null;
|
|
338
|
+
};
|
|
339
|
+
let t = consume(metrics.topHalfLength);
|
|
340
|
+
if (t != null) {
|
|
341
|
+
return pointOnLine(
|
|
342
|
+
metrics.centerX,
|
|
343
|
+
metrics.top,
|
|
344
|
+
metrics.right - metrics.radius,
|
|
345
|
+
metrics.top,
|
|
346
|
+
t
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
t = consume(metrics.arcLength);
|
|
350
|
+
if (t != null) {
|
|
351
|
+
return pointOnArc(
|
|
352
|
+
metrics.right - metrics.radius,
|
|
353
|
+
metrics.top + metrics.radius,
|
|
354
|
+
metrics.radius,
|
|
355
|
+
-Math.PI / 2,
|
|
356
|
+
0,
|
|
357
|
+
t
|
|
358
|
+
);
|
|
359
|
+
}
|
|
360
|
+
t = consume(metrics.verticalLength);
|
|
361
|
+
if (t != null) {
|
|
362
|
+
return pointOnLine(
|
|
363
|
+
metrics.right,
|
|
364
|
+
metrics.top + metrics.radius,
|
|
365
|
+
metrics.right,
|
|
366
|
+
metrics.bottom - metrics.radius,
|
|
367
|
+
t
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
t = consume(metrics.arcLength);
|
|
371
|
+
if (t != null) {
|
|
372
|
+
return pointOnArc(
|
|
373
|
+
metrics.right - metrics.radius,
|
|
374
|
+
metrics.bottom - metrics.radius,
|
|
375
|
+
metrics.radius,
|
|
376
|
+
0,
|
|
377
|
+
Math.PI / 2,
|
|
378
|
+
t
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
t = consume(metrics.horizontalLength);
|
|
382
|
+
if (t != null) {
|
|
383
|
+
return pointOnLine(
|
|
384
|
+
metrics.right - metrics.radius,
|
|
385
|
+
metrics.bottom,
|
|
386
|
+
metrics.left + metrics.radius,
|
|
387
|
+
metrics.bottom,
|
|
388
|
+
t
|
|
389
|
+
);
|
|
390
|
+
}
|
|
391
|
+
t = consume(metrics.arcLength);
|
|
392
|
+
if (t != null) {
|
|
393
|
+
return pointOnArc(
|
|
394
|
+
metrics.left + metrics.radius,
|
|
395
|
+
metrics.bottom - metrics.radius,
|
|
396
|
+
metrics.radius,
|
|
397
|
+
Math.PI / 2,
|
|
398
|
+
Math.PI,
|
|
399
|
+
t
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
t = consume(metrics.verticalLength);
|
|
403
|
+
if (t != null) {
|
|
404
|
+
return pointOnLine(
|
|
405
|
+
metrics.left,
|
|
406
|
+
metrics.bottom - metrics.radius,
|
|
407
|
+
metrics.left,
|
|
408
|
+
metrics.top + metrics.radius,
|
|
409
|
+
t
|
|
410
|
+
);
|
|
411
|
+
}
|
|
412
|
+
t = consume(metrics.arcLength);
|
|
413
|
+
if (t != null) {
|
|
414
|
+
return pointOnArc(
|
|
415
|
+
metrics.left + metrics.radius,
|
|
416
|
+
metrics.top + metrics.radius,
|
|
417
|
+
metrics.radius,
|
|
418
|
+
Math.PI,
|
|
419
|
+
Math.PI * 1.5,
|
|
420
|
+
t
|
|
421
|
+
);
|
|
422
|
+
}
|
|
423
|
+
t = consume(metrics.topHalfLength);
|
|
424
|
+
if (t != null) {
|
|
425
|
+
return pointOnLine(
|
|
426
|
+
metrics.left + metrics.radius,
|
|
427
|
+
metrics.top,
|
|
428
|
+
metrics.centerX,
|
|
429
|
+
metrics.top,
|
|
430
|
+
t
|
|
431
|
+
);
|
|
432
|
+
}
|
|
433
|
+
return [metrics.centerX, metrics.top];
|
|
305
434
|
}
|
|
306
435
|
function buildRectSvg(width, height, style = DEFAULT_STROKE_STYLE) {
|
|
307
436
|
return `<rect width="${width}" height="${height}" fill="none" stroke="${style.stroke}" stroke-width="${style.strokeWidth}" rx="4"${strokeOpacityAttr(style)} />`;
|
|
@@ -316,35 +445,34 @@ function buildArchitecturalCloudPathD(width, height, strokeWidth = DEFAULT_STROK
|
|
|
316
445
|
const h = Math.max(0, height);
|
|
317
446
|
if (w <= 0 || h <= 0) return "";
|
|
318
447
|
const inset = Math.max(0.5, strokeWidth / 2);
|
|
319
|
-
const
|
|
320
|
-
const
|
|
321
|
-
if (
|
|
322
|
-
const baseExponent = 3.6;
|
|
448
|
+
const outerWidth = Math.max(0, w - inset * 2);
|
|
449
|
+
const outerHeight = Math.max(0, h - inset * 2);
|
|
450
|
+
if (outerWidth <= 0 || outerHeight <= 0) return "";
|
|
323
451
|
const amplitude = Math.min(
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
Math.max(
|
|
452
|
+
outerWidth * 0.12,
|
|
453
|
+
outerHeight * 0.12,
|
|
454
|
+
Math.max(5, Math.min(14, Math.min(w, h) * 0.07))
|
|
327
455
|
);
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
const
|
|
334
|
-
const
|
|
335
|
-
|
|
336
|
-
|
|
456
|
+
const radius = Math.min(
|
|
457
|
+
outerWidth / 2,
|
|
458
|
+
outerHeight / 2,
|
|
459
|
+
Math.max(amplitude * 2.5, outerHeight * 0.43)
|
|
460
|
+
);
|
|
461
|
+
const outer = roundedRectMetrics(w, h, inset, radius);
|
|
462
|
+
const inner = roundedRectMetrics(
|
|
463
|
+
w,
|
|
464
|
+
h,
|
|
465
|
+
inset + amplitude,
|
|
466
|
+
Math.max(0, radius - amplitude)
|
|
467
|
+
);
|
|
468
|
+
const scallopCount = architecturalCloudScallopCount(outer.perimeter, amplitude);
|
|
469
|
+
const [startX, startY] = pointOnRoundedRectPath(inner, 0);
|
|
337
470
|
const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
|
|
338
471
|
for (let index = 0; index < scallopCount; index += 1) {
|
|
339
|
-
const
|
|
340
|
-
const
|
|
341
|
-
const
|
|
342
|
-
const [
|
|
343
|
-
segmentMid,
|
|
344
|
-
outerRx,
|
|
345
|
-
outerRy
|
|
346
|
-
);
|
|
347
|
-
const [endX, endY] = pointOnArchitecturalCloud(segmentEnd, innerRx, innerRy);
|
|
472
|
+
const controlDistance = (index + 0.5) / scallopCount * outer.perimeter;
|
|
473
|
+
const endDistance = (index + 1) / scallopCount * inner.perimeter;
|
|
474
|
+
const [controlX, controlY] = pointOnRoundedRectPath(outer, controlDistance);
|
|
475
|
+
const [endX, endY] = pointOnRoundedRectPath(inner, endDistance);
|
|
348
476
|
segments.push(
|
|
349
477
|
`Q${svgNumber(controlX)} ${svgNumber(controlY)} ${svgNumber(endX)} ${svgNumber(endY)}`
|
|
350
478
|
);
|
|
@@ -3106,7 +3234,7 @@ function ShapeContextMenu({
|
|
|
3106
3234
|
}
|
|
3107
3235
|
return createPortal(menu, document.body);
|
|
3108
3236
|
}
|
|
3109
|
-
var architecturalCloudIconPath = "M11
|
|
3237
|
+
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";
|
|
3110
3238
|
var base = {
|
|
3111
3239
|
width: 20,
|
|
3112
3240
|
height: 20,
|