canvu-react 0.3.30 → 0.3.32
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 +55 -78
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +55 -78
- package/dist/index.js.map +1 -1
- package/dist/native.cjs +55 -78
- package/dist/native.cjs.map +1 -1
- package/dist/native.js +55 -78
- package/dist/native.js.map +1 -1
- package/dist/react.cjs +57 -79
- package/dist/react.cjs.map +1 -1
- package/dist/react.js +57 -79
- package/dist/react.js.map +1 -1
- package/dist/realtime.cjs +2 -1
- package/dist/realtime.cjs.map +1 -1
- package/dist/realtime.js +2 -1
- package/dist/realtime.js.map +1 -1
- package/dist/tldraw.cjs +54 -77
- package/dist/tldraw.cjs.map +1 -1
- package/dist/tldraw.js +54 -77
- package/dist/tldraw.js.map +1 -1
- package/package.json +1 -1
package/dist/native.cjs
CHANGED
|
@@ -349,40 +349,29 @@ function resolveStrokeStyle(item) {
|
|
|
349
349
|
function strokeOpacityAttr(style) {
|
|
350
350
|
return style.strokeOpacity != null ? ` stroke-opacity="${style.strokeOpacity}"` : "";
|
|
351
351
|
}
|
|
352
|
-
function clampNumber(value, min, max) {
|
|
353
|
-
return Math.min(max, Math.max(min, value));
|
|
354
|
-
}
|
|
355
352
|
function svgNumber(value) {
|
|
356
353
|
if (!Number.isFinite(value)) return "0";
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
const
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
for (let index = 1; index <= count; index += 1) {
|
|
379
|
-
const y0 = startY + step * (index - 1);
|
|
380
|
-
const y1 = index === count ? endY : startY + step * index;
|
|
381
|
-
const cy = (y0 + y1) / 2;
|
|
382
|
-
segments.push(
|
|
383
|
-
`Q${svgNumber(controlX)} ${svgNumber(cy)} ${svgNumber(x)} ${svgNumber(y1)}`
|
|
384
|
-
);
|
|
385
|
-
}
|
|
354
|
+
const rounded = Math.round(value * 100) / 100;
|
|
355
|
+
return Number.isInteger(rounded) ? String(rounded) : String(rounded);
|
|
356
|
+
}
|
|
357
|
+
function approximateEllipsePerimeter(rx, ry) {
|
|
358
|
+
if (rx <= 0 || ry <= 0) return 0;
|
|
359
|
+
return Math.PI * (3 * (rx + ry) - Math.sqrt((3 * rx + ry) * (rx + 3 * ry)));
|
|
360
|
+
}
|
|
361
|
+
function architecturalCloudScallopCount(rx, ry, amplitude) {
|
|
362
|
+
const perimeter = approximateEllipsePerimeter(rx, ry);
|
|
363
|
+
const targetScallopLength = Math.max(10, amplitude * 2);
|
|
364
|
+
let count = Math.max(12, Math.round(perimeter / targetScallopLength));
|
|
365
|
+
if (count % 2 === 1) count += 1;
|
|
366
|
+
return count;
|
|
367
|
+
}
|
|
368
|
+
function pointOnSuperellipse(centerX, centerY, radiusX, radiusY, theta, exponent) {
|
|
369
|
+
const cosTheta = Math.cos(theta);
|
|
370
|
+
const sinTheta = Math.sin(theta);
|
|
371
|
+
return [
|
|
372
|
+
centerX + Math.sign(cosTheta) * radiusX * Math.abs(cosTheta) ** (2 / exponent),
|
|
373
|
+
centerY + Math.sign(sinTheta) * radiusY * Math.abs(sinTheta) ** (2 / exponent)
|
|
374
|
+
];
|
|
386
375
|
}
|
|
387
376
|
function buildRectSvg(width, height, style = DEFAULT_STROKE_STYLE) {
|
|
388
377
|
return `<rect width="${width}" height="${height}" fill="none" stroke="${style.stroke}" stroke-width="${style.strokeWidth}" rx="4"${strokeOpacityAttr(style)} />`;
|
|
@@ -396,53 +385,41 @@ function buildArchitecturalCloudPathD(width, height, strokeWidth = DEFAULT_STROK
|
|
|
396
385
|
const w = Math.max(0, width);
|
|
397
386
|
const h = Math.max(0, height);
|
|
398
387
|
if (w <= 0 || h <= 0) return "";
|
|
399
|
-
const inset = Math.
|
|
400
|
-
const
|
|
401
|
-
const
|
|
402
|
-
|
|
403
|
-
const
|
|
404
|
-
const
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
const depth = clampNumber(Math.min(w, h) * 0.08, 2, Math.min(12, maxDepth));
|
|
409
|
-
const corner = Math.min(depth * 1.2, innerW / 2, innerH / 2);
|
|
410
|
-
const topStart = x0 + corner;
|
|
411
|
-
const topEnd = x1 - corner;
|
|
412
|
-
const rightStart = y0 + corner;
|
|
413
|
-
const rightEnd = y1 - corner;
|
|
414
|
-
const bottomStart = x1 - corner;
|
|
415
|
-
const bottomEnd = x0 + corner;
|
|
416
|
-
const leftStart = y1 - corner;
|
|
417
|
-
const leftEnd = y0 + corner;
|
|
418
|
-
const topCount = architecturalCloudScallopCount(topEnd - topStart, depth);
|
|
419
|
-
const rightCount = architecturalCloudScallopCount(rightEnd - rightStart, depth);
|
|
420
|
-
const bottomCount = architecturalCloudScallopCount(bottomStart - bottomEnd, depth);
|
|
421
|
-
const leftCount = architecturalCloudScallopCount(leftStart - leftEnd, depth);
|
|
422
|
-
const segments = [`M${svgNumber(topStart)} ${svgNumber(y0)}`];
|
|
423
|
-
appendHorizontalScallops(segments, topStart, topEnd, y0, y0 + depth, topCount);
|
|
424
|
-
segments.push(
|
|
425
|
-
`Q${svgNumber(x1)} ${svgNumber(y0)} ${svgNumber(x1)} ${svgNumber(rightStart)}`
|
|
426
|
-
);
|
|
427
|
-
appendVerticalScallops(segments, rightStart, rightEnd, x1, x1 - depth, rightCount);
|
|
428
|
-
segments.push(
|
|
429
|
-
`Q${svgNumber(x1)} ${svgNumber(y1)} ${svgNumber(bottomStart)} ${svgNumber(y1)}`
|
|
430
|
-
);
|
|
431
|
-
appendHorizontalScallops(
|
|
432
|
-
segments,
|
|
433
|
-
bottomStart,
|
|
434
|
-
bottomEnd,
|
|
435
|
-
y1,
|
|
436
|
-
y1 - depth,
|
|
437
|
-
bottomCount
|
|
438
|
-
);
|
|
439
|
-
segments.push(
|
|
440
|
-
`Q${svgNumber(x0)} ${svgNumber(y1)} ${svgNumber(x0)} ${svgNumber(leftStart)}`
|
|
441
|
-
);
|
|
442
|
-
appendVerticalScallops(segments, leftStart, leftEnd, x0, x0 + depth, leftCount);
|
|
443
|
-
segments.push(
|
|
444
|
-
`Q${svgNumber(x0)} ${svgNumber(y0)} ${svgNumber(topStart)} ${svgNumber(y0)} Z`
|
|
388
|
+
const inset = Math.max(0.5, strokeWidth / 2);
|
|
389
|
+
const outerRx = Math.max(0, w / 2 - inset);
|
|
390
|
+
const outerRy = Math.max(0, h / 2 - inset);
|
|
391
|
+
if (outerRx <= 0 || outerRy <= 0) return "";
|
|
392
|
+
const baseExponent = 3.6;
|
|
393
|
+
const amplitude = Math.min(
|
|
394
|
+
outerRx * 0.45,
|
|
395
|
+
outerRy * 0.45,
|
|
396
|
+
Math.max(2, Math.min(7, Math.min(w, h) * 0.035))
|
|
445
397
|
);
|
|
398
|
+
const innerRx = Math.max(0, outerRx - amplitude);
|
|
399
|
+
const innerRy = Math.max(0, outerRy - amplitude);
|
|
400
|
+
const scallopCount = architecturalCloudScallopCount(innerRx, innerRy, amplitude);
|
|
401
|
+
const angleStep = Math.PI * 2 / scallopCount;
|
|
402
|
+
const cx = w / 2;
|
|
403
|
+
const cy = h / 2;
|
|
404
|
+
const startAngle = -Math.PI / 2;
|
|
405
|
+
const pointOnArchitecturalCloud = (theta, radiusX, radiusY) => pointOnSuperellipse(cx, cy, radiusX, radiusY, theta, baseExponent);
|
|
406
|
+
const [startX, startY] = pointOnArchitecturalCloud(startAngle, innerRx, innerRy);
|
|
407
|
+
const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
|
|
408
|
+
for (let index = 0; index < scallopCount; index += 1) {
|
|
409
|
+
const segmentStart = startAngle + index * angleStep;
|
|
410
|
+
const segmentMid = segmentStart + angleStep / 2;
|
|
411
|
+
const segmentEnd = segmentStart + angleStep;
|
|
412
|
+
const [controlX, controlY] = pointOnArchitecturalCloud(
|
|
413
|
+
segmentMid,
|
|
414
|
+
outerRx,
|
|
415
|
+
outerRy
|
|
416
|
+
);
|
|
417
|
+
const [endX, endY] = pointOnArchitecturalCloud(segmentEnd, innerRx, innerRy);
|
|
418
|
+
segments.push(
|
|
419
|
+
`Q${svgNumber(controlX)} ${svgNumber(controlY)} ${svgNumber(endX)} ${svgNumber(endY)}`
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
segments.push("Z");
|
|
446
423
|
return segments.join(" ");
|
|
447
424
|
}
|
|
448
425
|
function buildArchitecturalCloudSvg(width, height, style = DEFAULT_STROKE_STYLE) {
|