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