canvu-react 0.3.30 → 0.3.31
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 +44 -77
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +44 -77
- package/dist/index.js.map +1 -1
- package/dist/native.cjs +44 -77
- package/dist/native.cjs.map +1 -1
- package/dist/native.js +44 -77
- package/dist/native.js.map +1 -1
- package/dist/react.cjs +46 -78
- package/dist/react.cjs.map +1 -1
- package/dist/react.js +46 -78
- 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 +44 -77
- package/dist/tldraw.cjs.map +1 -1
- package/dist/tldraw.js +44 -77
- package/dist/tldraw.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1038,40 +1038,21 @@ function resolveStrokeStyle(item) {
|
|
|
1038
1038
|
function strokeOpacityAttr(style) {
|
|
1039
1039
|
return style.strokeOpacity != null ? ` stroke-opacity="${style.strokeOpacity}"` : "";
|
|
1040
1040
|
}
|
|
1041
|
-
function clampNumber(value, min, max) {
|
|
1042
|
-
return Math.min(max, Math.max(min, value));
|
|
1043
|
-
}
|
|
1044
1041
|
function svgNumber(value) {
|
|
1045
1042
|
if (!Number.isFinite(value)) return "0";
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
function architecturalCloudScallopCount(length, depth) {
|
|
1049
|
-
if (length <= 1e-6) return 0;
|
|
1050
|
-
return Math.max(1, Math.round(length / Math.max(depth * 2.05, 8)));
|
|
1051
|
-
}
|
|
1052
|
-
function appendHorizontalScallops(segments, startX, endX, y, controlY, count) {
|
|
1053
|
-
if (count <= 0) return;
|
|
1054
|
-
const step = (endX - startX) / count;
|
|
1055
|
-
for (let index = 1; index <= count; index += 1) {
|
|
1056
|
-
const x0 = startX + step * (index - 1);
|
|
1057
|
-
const x1 = index === count ? endX : startX + step * index;
|
|
1058
|
-
const cx = (x0 + x1) / 2;
|
|
1059
|
-
segments.push(
|
|
1060
|
-
`Q${svgNumber(cx)} ${svgNumber(controlY)} ${svgNumber(x1)} ${svgNumber(y)}`
|
|
1061
|
-
);
|
|
1062
|
-
}
|
|
1043
|
+
const rounded = Math.round(value * 100) / 100;
|
|
1044
|
+
return Number.isInteger(rounded) ? String(rounded) : String(rounded);
|
|
1063
1045
|
}
|
|
1064
|
-
function
|
|
1065
|
-
if (
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
}
|
|
1046
|
+
function approximateEllipsePerimeter(rx, ry) {
|
|
1047
|
+
if (rx <= 0 || ry <= 0) return 0;
|
|
1048
|
+
return Math.PI * (3 * (rx + ry) - Math.sqrt((3 * rx + ry) * (rx + 3 * ry)));
|
|
1049
|
+
}
|
|
1050
|
+
function architecturalCloudScallopCount(rx, ry, amplitude) {
|
|
1051
|
+
const perimeter = approximateEllipsePerimeter(rx, ry);
|
|
1052
|
+
const targetScallopLength = Math.max(10, amplitude * 2);
|
|
1053
|
+
let count = Math.max(12, Math.round(perimeter / targetScallopLength));
|
|
1054
|
+
if (count % 2 === 1) count += 1;
|
|
1055
|
+
return count;
|
|
1075
1056
|
}
|
|
1076
1057
|
function buildRectSvg(width, height, style = DEFAULT_STROKE_STYLE) {
|
|
1077
1058
|
return `<rect width="${width}" height="${height}" fill="none" stroke="${style.stroke}" stroke-width="${style.strokeWidth}" rx="4"${strokeOpacityAttr(style)} />`;
|
|
@@ -1085,53 +1066,39 @@ function buildArchitecturalCloudPathD(width, height, strokeWidth = DEFAULT_STROK
|
|
|
1085
1066
|
const w = Math.max(0, width);
|
|
1086
1067
|
const h = Math.max(0, height);
|
|
1087
1068
|
if (w <= 0 || h <= 0) return "";
|
|
1088
|
-
const inset = Math.
|
|
1089
|
-
const
|
|
1090
|
-
const
|
|
1091
|
-
|
|
1092
|
-
const
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
const maxDepth = Math.max(0.5, Math.min(innerW, innerH) * 0.18);
|
|
1097
|
-
const depth = clampNumber(Math.min(w, h) * 0.08, 2, Math.min(12, maxDepth));
|
|
1098
|
-
const corner = Math.min(depth * 1.2, innerW / 2, innerH / 2);
|
|
1099
|
-
const topStart = x0 + corner;
|
|
1100
|
-
const topEnd = x1 - corner;
|
|
1101
|
-
const rightStart = y0 + corner;
|
|
1102
|
-
const rightEnd = y1 - corner;
|
|
1103
|
-
const bottomStart = x1 - corner;
|
|
1104
|
-
const bottomEnd = x0 + corner;
|
|
1105
|
-
const leftStart = y1 - corner;
|
|
1106
|
-
const leftEnd = y0 + corner;
|
|
1107
|
-
const topCount = architecturalCloudScallopCount(topEnd - topStart, depth);
|
|
1108
|
-
const rightCount = architecturalCloudScallopCount(rightEnd - rightStart, depth);
|
|
1109
|
-
const bottomCount = architecturalCloudScallopCount(bottomStart - bottomEnd, depth);
|
|
1110
|
-
const leftCount = architecturalCloudScallopCount(leftStart - leftEnd, depth);
|
|
1111
|
-
const segments = [`M${svgNumber(topStart)} ${svgNumber(y0)}`];
|
|
1112
|
-
appendHorizontalScallops(segments, topStart, topEnd, y0, y0 + depth, topCount);
|
|
1113
|
-
segments.push(
|
|
1114
|
-
`Q${svgNumber(x1)} ${svgNumber(y0)} ${svgNumber(x1)} ${svgNumber(rightStart)}`
|
|
1115
|
-
);
|
|
1116
|
-
appendVerticalScallops(segments, rightStart, rightEnd, x1, x1 - depth, rightCount);
|
|
1117
|
-
segments.push(
|
|
1118
|
-
`Q${svgNumber(x1)} ${svgNumber(y1)} ${svgNumber(bottomStart)} ${svgNumber(y1)}`
|
|
1119
|
-
);
|
|
1120
|
-
appendHorizontalScallops(
|
|
1121
|
-
segments,
|
|
1122
|
-
bottomStart,
|
|
1123
|
-
bottomEnd,
|
|
1124
|
-
y1,
|
|
1125
|
-
y1 - depth,
|
|
1126
|
-
bottomCount
|
|
1127
|
-
);
|
|
1128
|
-
segments.push(
|
|
1129
|
-
`Q${svgNumber(x0)} ${svgNumber(y1)} ${svgNumber(x0)} ${svgNumber(leftStart)}`
|
|
1130
|
-
);
|
|
1131
|
-
appendVerticalScallops(segments, leftStart, leftEnd, x0, x0 + depth, leftCount);
|
|
1132
|
-
segments.push(
|
|
1133
|
-
`Q${svgNumber(x0)} ${svgNumber(y0)} ${svgNumber(topStart)} ${svgNumber(y0)} Z`
|
|
1069
|
+
const inset = Math.max(0.5, strokeWidth / 2);
|
|
1070
|
+
const outerRx = Math.max(0, w / 2 - inset);
|
|
1071
|
+
const outerRy = Math.max(0, h / 2 - inset);
|
|
1072
|
+
if (outerRx <= 0 || outerRy <= 0) return "";
|
|
1073
|
+
const amplitude = Math.min(
|
|
1074
|
+
outerRx * 0.45,
|
|
1075
|
+
outerRy * 0.45,
|
|
1076
|
+
Math.max(2, Math.min(8, Math.min(w, h) * 0.04))
|
|
1134
1077
|
);
|
|
1078
|
+
const innerRx = Math.max(0, outerRx - amplitude);
|
|
1079
|
+
const innerRy = Math.max(0, outerRy - amplitude);
|
|
1080
|
+
const scallopCount = architecturalCloudScallopCount(innerRx, innerRy, amplitude);
|
|
1081
|
+
const angleStep = Math.PI * 2 / scallopCount;
|
|
1082
|
+
const cx = w / 2;
|
|
1083
|
+
const cy = h / 2;
|
|
1084
|
+
const startAngle = -Math.PI / 2;
|
|
1085
|
+
const pointOnEllipse = (theta, radiusX, radiusY) => [
|
|
1086
|
+
cx + Math.cos(theta) * radiusX,
|
|
1087
|
+
cy + Math.sin(theta) * radiusY
|
|
1088
|
+
];
|
|
1089
|
+
const [startX, startY] = pointOnEllipse(startAngle, innerRx, innerRy);
|
|
1090
|
+
const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
|
|
1091
|
+
for (let index = 0; index < scallopCount; index += 1) {
|
|
1092
|
+
const segmentStart = startAngle + index * angleStep;
|
|
1093
|
+
const segmentMid = segmentStart + angleStep / 2;
|
|
1094
|
+
const segmentEnd = segmentStart + angleStep;
|
|
1095
|
+
const [controlX, controlY] = pointOnEllipse(segmentMid, outerRx, outerRy);
|
|
1096
|
+
const [endX, endY] = pointOnEllipse(segmentEnd, innerRx, innerRy);
|
|
1097
|
+
segments.push(
|
|
1098
|
+
`Q${svgNumber(controlX)} ${svgNumber(controlY)} ${svgNumber(endX)} ${svgNumber(endY)}`
|
|
1099
|
+
);
|
|
1100
|
+
}
|
|
1101
|
+
segments.push("Z");
|
|
1135
1102
|
return segments.join(" ");
|
|
1136
1103
|
}
|
|
1137
1104
|
function buildArchitecturalCloudSvg(width, height, style = DEFAULT_STROKE_STYLE) {
|