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/index.cjs
CHANGED
|
@@ -1045,40 +1045,29 @@ 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
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
const
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
for (let index = 1; index <= count; index += 1) {
|
|
1075
|
-
const y0 = startY + step * (index - 1);
|
|
1076
|
-
const y1 = index === count ? endY : startY + step * index;
|
|
1077
|
-
const cy = (y0 + y1) / 2;
|
|
1078
|
-
segments.push(
|
|
1079
|
-
`Q${svgNumber(controlX)} ${svgNumber(cy)} ${svgNumber(x)} ${svgNumber(y1)}`
|
|
1080
|
-
);
|
|
1081
|
-
}
|
|
1050
|
+
const rounded = Math.round(value * 100) / 100;
|
|
1051
|
+
return Number.isInteger(rounded) ? String(rounded) : String(rounded);
|
|
1052
|
+
}
|
|
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;
|
|
1063
|
+
}
|
|
1064
|
+
function pointOnSuperellipse(centerX, centerY, radiusX, radiusY, theta, exponent) {
|
|
1065
|
+
const cosTheta = Math.cos(theta);
|
|
1066
|
+
const sinTheta = Math.sin(theta);
|
|
1067
|
+
return [
|
|
1068
|
+
centerX + Math.sign(cosTheta) * radiusX * Math.abs(cosTheta) ** (2 / exponent),
|
|
1069
|
+
centerY + Math.sign(sinTheta) * radiusY * Math.abs(sinTheta) ** (2 / exponent)
|
|
1070
|
+
];
|
|
1082
1071
|
}
|
|
1083
1072
|
function buildRectSvg(width, height, style = DEFAULT_STROKE_STYLE) {
|
|
1084
1073
|
return `<rect width="${width}" height="${height}" fill="none" stroke="${style.stroke}" stroke-width="${style.strokeWidth}" rx="4"${strokeOpacityAttr(style)} />`;
|
|
@@ -1092,53 +1081,41 @@ function buildArchitecturalCloudPathD(width, height, strokeWidth = DEFAULT_STROK
|
|
|
1092
1081
|
const w = Math.max(0, width);
|
|
1093
1082
|
const h = Math.max(0, height);
|
|
1094
1083
|
if (w <= 0 || h <= 0) return "";
|
|
1095
|
-
const inset = Math.
|
|
1096
|
-
const
|
|
1097
|
-
const
|
|
1098
|
-
|
|
1099
|
-
const
|
|
1100
|
-
const
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
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`
|
|
1084
|
+
const inset = Math.max(0.5, strokeWidth / 2);
|
|
1085
|
+
const outerRx = Math.max(0, w / 2 - inset);
|
|
1086
|
+
const outerRy = Math.max(0, h / 2 - inset);
|
|
1087
|
+
if (outerRx <= 0 || outerRy <= 0) return "";
|
|
1088
|
+
const baseExponent = 3.6;
|
|
1089
|
+
const amplitude = Math.min(
|
|
1090
|
+
outerRx * 0.45,
|
|
1091
|
+
outerRy * 0.45,
|
|
1092
|
+
Math.max(2, Math.min(7, Math.min(w, h) * 0.035))
|
|
1141
1093
|
);
|
|
1094
|
+
const innerRx = Math.max(0, outerRx - amplitude);
|
|
1095
|
+
const innerRy = Math.max(0, outerRy - amplitude);
|
|
1096
|
+
const scallopCount = architecturalCloudScallopCount(innerRx, innerRy, amplitude);
|
|
1097
|
+
const angleStep = Math.PI * 2 / scallopCount;
|
|
1098
|
+
const cx = w / 2;
|
|
1099
|
+
const cy = h / 2;
|
|
1100
|
+
const startAngle = -Math.PI / 2;
|
|
1101
|
+
const pointOnArchitecturalCloud = (theta, radiusX, radiusY) => pointOnSuperellipse(cx, cy, radiusX, radiusY, theta, baseExponent);
|
|
1102
|
+
const [startX, startY] = pointOnArchitecturalCloud(startAngle, innerRx, innerRy);
|
|
1103
|
+
const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
|
|
1104
|
+
for (let index = 0; index < scallopCount; index += 1) {
|
|
1105
|
+
const segmentStart = startAngle + index * angleStep;
|
|
1106
|
+
const segmentMid = segmentStart + angleStep / 2;
|
|
1107
|
+
const segmentEnd = segmentStart + angleStep;
|
|
1108
|
+
const [controlX, controlY] = pointOnArchitecturalCloud(
|
|
1109
|
+
segmentMid,
|
|
1110
|
+
outerRx,
|
|
1111
|
+
outerRy
|
|
1112
|
+
);
|
|
1113
|
+
const [endX, endY] = pointOnArchitecturalCloud(segmentEnd, innerRx, innerRy);
|
|
1114
|
+
segments.push(
|
|
1115
|
+
`Q${svgNumber(controlX)} ${svgNumber(controlY)} ${svgNumber(endX)} ${svgNumber(endY)}`
|
|
1116
|
+
);
|
|
1117
|
+
}
|
|
1118
|
+
segments.push("Z");
|
|
1142
1119
|
return segments.join(" ");
|
|
1143
1120
|
}
|
|
1144
1121
|
function buildArchitecturalCloudSvg(width, height, style = DEFAULT_STROKE_STYLE) {
|