canvu-react 0.3.31 → 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 +168 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +168 -30
- package/dist/index.js.map +1 -1
- package/dist/native.cjs +168 -30
- package/dist/native.cjs.map +1 -1
- package/dist/native.js +168 -30
- package/dist/native.js.map +1 -1
- package/dist/react.cjs +170 -32
- package/dist/react.cjs.map +1 -1
- package/dist/react.js +170 -32
- package/dist/react.js.map +1 -1
- package/dist/realtime.cjs +2 -2
- package/dist/realtime.cjs.map +1 -1
- package/dist/realtime.js +2 -2
- package/dist/realtime.js.map +1 -1
- package/dist/tldraw.cjs +168 -30
- package/dist/tldraw.cjs.map +1 -1
- package/dist/tldraw.js +168 -30
- package/dist/tldraw.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1050,17 +1050,154 @@ function svgNumber(value) {
|
|
|
1050
1050
|
const rounded = Math.round(value * 100) / 100;
|
|
1051
1051
|
return Number.isInteger(rounded) ? String(rounded) : String(rounded);
|
|
1052
1052
|
}
|
|
1053
|
-
function
|
|
1054
|
-
|
|
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);
|
|
1053
|
+
function architecturalCloudScallopCount(perimeter, amplitude) {
|
|
1054
|
+
const targetScallopLength = Math.max(18, amplitude * 2.45);
|
|
1060
1055
|
let count = Math.max(12, Math.round(perimeter / targetScallopLength));
|
|
1061
1056
|
if (count % 2 === 1) count += 1;
|
|
1062
1057
|
return count;
|
|
1063
1058
|
}
|
|
1059
|
+
function roundedRectMetrics(width, height, inset, radius) {
|
|
1060
|
+
const left = inset;
|
|
1061
|
+
const top = inset;
|
|
1062
|
+
const right = width - inset;
|
|
1063
|
+
const bottom = height - inset;
|
|
1064
|
+
const rectWidth = Math.max(0, right - left);
|
|
1065
|
+
const rectHeight = Math.max(0, bottom - top);
|
|
1066
|
+
const normalizedRadius = Math.max(
|
|
1067
|
+
0,
|
|
1068
|
+
Math.min(radius, rectWidth / 2, rectHeight / 2)
|
|
1069
|
+
);
|
|
1070
|
+
const centerX = width / 2;
|
|
1071
|
+
const topHalfLength = Math.max(0, right - normalizedRadius - centerX);
|
|
1072
|
+
const horizontalLength = Math.max(0, rectWidth - normalizedRadius * 2);
|
|
1073
|
+
const verticalLength = Math.max(0, rectHeight - normalizedRadius * 2);
|
|
1074
|
+
const arcLength = normalizedRadius * (Math.PI / 2);
|
|
1075
|
+
return {
|
|
1076
|
+
left,
|
|
1077
|
+
top,
|
|
1078
|
+
right,
|
|
1079
|
+
bottom,
|
|
1080
|
+
radius: normalizedRadius,
|
|
1081
|
+
centerX,
|
|
1082
|
+
topHalfLength,
|
|
1083
|
+
horizontalLength,
|
|
1084
|
+
verticalLength,
|
|
1085
|
+
arcLength,
|
|
1086
|
+
perimeter: horizontalLength * 2 + verticalLength * 2 + Math.PI * 2 * normalizedRadius
|
|
1087
|
+
};
|
|
1088
|
+
}
|
|
1089
|
+
function pointOnLine(startX, startY, endX, endY, t) {
|
|
1090
|
+
return [startX + (endX - startX) * t, startY + (endY - startY) * t];
|
|
1091
|
+
}
|
|
1092
|
+
function pointOnArc(centerX, centerY, radius, startAngle, endAngle, t) {
|
|
1093
|
+
const theta = startAngle + (endAngle - startAngle) * t;
|
|
1094
|
+
return [centerX + Math.cos(theta) * radius, centerY + Math.sin(theta) * radius];
|
|
1095
|
+
}
|
|
1096
|
+
function pointOnRoundedRectPath(metrics, distance) {
|
|
1097
|
+
if (metrics.perimeter <= 0) return [metrics.centerX, metrics.top];
|
|
1098
|
+
let remaining = (distance % metrics.perimeter + metrics.perimeter) % metrics.perimeter;
|
|
1099
|
+
const consume = (length) => {
|
|
1100
|
+
if (length <= 1e-9) return null;
|
|
1101
|
+
if (remaining <= length) return remaining / length;
|
|
1102
|
+
remaining -= length;
|
|
1103
|
+
return null;
|
|
1104
|
+
};
|
|
1105
|
+
let t = consume(metrics.topHalfLength);
|
|
1106
|
+
if (t != null) {
|
|
1107
|
+
return pointOnLine(
|
|
1108
|
+
metrics.centerX,
|
|
1109
|
+
metrics.top,
|
|
1110
|
+
metrics.right - metrics.radius,
|
|
1111
|
+
metrics.top,
|
|
1112
|
+
t
|
|
1113
|
+
);
|
|
1114
|
+
}
|
|
1115
|
+
t = consume(metrics.arcLength);
|
|
1116
|
+
if (t != null) {
|
|
1117
|
+
return pointOnArc(
|
|
1118
|
+
metrics.right - metrics.radius,
|
|
1119
|
+
metrics.top + metrics.radius,
|
|
1120
|
+
metrics.radius,
|
|
1121
|
+
-Math.PI / 2,
|
|
1122
|
+
0,
|
|
1123
|
+
t
|
|
1124
|
+
);
|
|
1125
|
+
}
|
|
1126
|
+
t = consume(metrics.verticalLength);
|
|
1127
|
+
if (t != null) {
|
|
1128
|
+
return pointOnLine(
|
|
1129
|
+
metrics.right,
|
|
1130
|
+
metrics.top + metrics.radius,
|
|
1131
|
+
metrics.right,
|
|
1132
|
+
metrics.bottom - metrics.radius,
|
|
1133
|
+
t
|
|
1134
|
+
);
|
|
1135
|
+
}
|
|
1136
|
+
t = consume(metrics.arcLength);
|
|
1137
|
+
if (t != null) {
|
|
1138
|
+
return pointOnArc(
|
|
1139
|
+
metrics.right - metrics.radius,
|
|
1140
|
+
metrics.bottom - metrics.radius,
|
|
1141
|
+
metrics.radius,
|
|
1142
|
+
0,
|
|
1143
|
+
Math.PI / 2,
|
|
1144
|
+
t
|
|
1145
|
+
);
|
|
1146
|
+
}
|
|
1147
|
+
t = consume(metrics.horizontalLength);
|
|
1148
|
+
if (t != null) {
|
|
1149
|
+
return pointOnLine(
|
|
1150
|
+
metrics.right - metrics.radius,
|
|
1151
|
+
metrics.bottom,
|
|
1152
|
+
metrics.left + metrics.radius,
|
|
1153
|
+
metrics.bottom,
|
|
1154
|
+
t
|
|
1155
|
+
);
|
|
1156
|
+
}
|
|
1157
|
+
t = consume(metrics.arcLength);
|
|
1158
|
+
if (t != null) {
|
|
1159
|
+
return pointOnArc(
|
|
1160
|
+
metrics.left + metrics.radius,
|
|
1161
|
+
metrics.bottom - metrics.radius,
|
|
1162
|
+
metrics.radius,
|
|
1163
|
+
Math.PI / 2,
|
|
1164
|
+
Math.PI,
|
|
1165
|
+
t
|
|
1166
|
+
);
|
|
1167
|
+
}
|
|
1168
|
+
t = consume(metrics.verticalLength);
|
|
1169
|
+
if (t != null) {
|
|
1170
|
+
return pointOnLine(
|
|
1171
|
+
metrics.left,
|
|
1172
|
+
metrics.bottom - metrics.radius,
|
|
1173
|
+
metrics.left,
|
|
1174
|
+
metrics.top + metrics.radius,
|
|
1175
|
+
t
|
|
1176
|
+
);
|
|
1177
|
+
}
|
|
1178
|
+
t = consume(metrics.arcLength);
|
|
1179
|
+
if (t != null) {
|
|
1180
|
+
return pointOnArc(
|
|
1181
|
+
metrics.left + metrics.radius,
|
|
1182
|
+
metrics.top + metrics.radius,
|
|
1183
|
+
metrics.radius,
|
|
1184
|
+
Math.PI,
|
|
1185
|
+
Math.PI * 1.5,
|
|
1186
|
+
t
|
|
1187
|
+
);
|
|
1188
|
+
}
|
|
1189
|
+
t = consume(metrics.topHalfLength);
|
|
1190
|
+
if (t != null) {
|
|
1191
|
+
return pointOnLine(
|
|
1192
|
+
metrics.left + metrics.radius,
|
|
1193
|
+
metrics.top,
|
|
1194
|
+
metrics.centerX,
|
|
1195
|
+
metrics.top,
|
|
1196
|
+
t
|
|
1197
|
+
);
|
|
1198
|
+
}
|
|
1199
|
+
return [metrics.centerX, metrics.top];
|
|
1200
|
+
}
|
|
1064
1201
|
function buildRectSvg(width, height, style = DEFAULT_STROKE_STYLE) {
|
|
1065
1202
|
return `<rect width="${width}" height="${height}" fill="none" stroke="${style.stroke}" stroke-width="${style.strokeWidth}" rx="4"${strokeOpacityAttr(style)} />`;
|
|
1066
1203
|
}
|
|
@@ -1074,33 +1211,34 @@ function buildArchitecturalCloudPathD(width, height, strokeWidth = DEFAULT_STROK
|
|
|
1074
1211
|
const h = Math.max(0, height);
|
|
1075
1212
|
if (w <= 0 || h <= 0) return "";
|
|
1076
1213
|
const inset = Math.max(0.5, strokeWidth / 2);
|
|
1077
|
-
const
|
|
1078
|
-
const
|
|
1079
|
-
if (
|
|
1214
|
+
const outerWidth = Math.max(0, w - inset * 2);
|
|
1215
|
+
const outerHeight = Math.max(0, h - inset * 2);
|
|
1216
|
+
if (outerWidth <= 0 || outerHeight <= 0) return "";
|
|
1080
1217
|
const amplitude = Math.min(
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
Math.max(
|
|
1218
|
+
outerWidth * 0.12,
|
|
1219
|
+
outerHeight * 0.12,
|
|
1220
|
+
Math.max(5, Math.min(14, Math.min(w, h) * 0.07))
|
|
1084
1221
|
);
|
|
1085
|
-
const
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
const
|
|
1091
|
-
const
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1222
|
+
const radius = Math.min(
|
|
1223
|
+
outerWidth / 2,
|
|
1224
|
+
outerHeight / 2,
|
|
1225
|
+
Math.max(amplitude * 2.5, outerHeight * 0.43)
|
|
1226
|
+
);
|
|
1227
|
+
const outer = roundedRectMetrics(w, h, inset, radius);
|
|
1228
|
+
const inner = roundedRectMetrics(
|
|
1229
|
+
w,
|
|
1230
|
+
h,
|
|
1231
|
+
inset + amplitude,
|
|
1232
|
+
Math.max(0, radius - amplitude)
|
|
1233
|
+
);
|
|
1234
|
+
const scallopCount = architecturalCloudScallopCount(outer.perimeter, amplitude);
|
|
1235
|
+
const [startX, startY] = pointOnRoundedRectPath(inner, 0);
|
|
1097
1236
|
const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
|
|
1098
1237
|
for (let index = 0; index < scallopCount; index += 1) {
|
|
1099
|
-
const
|
|
1100
|
-
const
|
|
1101
|
-
const
|
|
1102
|
-
const [
|
|
1103
|
-
const [endX, endY] = pointOnEllipse(segmentEnd, innerRx, innerRy);
|
|
1238
|
+
const controlDistance = (index + 0.5) / scallopCount * outer.perimeter;
|
|
1239
|
+
const endDistance = (index + 1) / scallopCount * inner.perimeter;
|
|
1240
|
+
const [controlX, controlY] = pointOnRoundedRectPath(outer, controlDistance);
|
|
1241
|
+
const [endX, endY] = pointOnRoundedRectPath(inner, endDistance);
|
|
1104
1242
|
segments.push(
|
|
1105
1243
|
`Q${svgNumber(controlX)} ${svgNumber(controlY)} ${svgNumber(endX)} ${svgNumber(endY)}`
|
|
1106
1244
|
);
|