canvu-react 0.3.32 → 0.3.34
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 +247 -45
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +247 -45
- package/dist/index.js.map +1 -1
- package/dist/native.cjs +247 -45
- package/dist/native.cjs.map +1 -1
- package/dist/native.js +247 -45
- package/dist/native.js.map +1 -1
- package/dist/react.cjs +250 -48
- package/dist/react.cjs.map +1 -1
- package/dist/react.js +250 -48
- 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 +247 -45
- package/dist/tldraw.cjs.map +1 -1
- package/dist/tldraw.js +247 -45
- package/dist/tldraw.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1043,24 +1043,203 @@ function svgNumber(value) {
|
|
|
1043
1043
|
const rounded = Math.round(value * 100) / 100;
|
|
1044
1044
|
return Number.isInteger(rounded) ? String(rounded) : String(rounded);
|
|
1045
1045
|
}
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1046
|
+
var ARCHITECTURAL_CLOUD_RADIUS = 38;
|
|
1047
|
+
var ARCHITECTURAL_CLOUD_TARGET_SPACING = 50;
|
|
1048
|
+
var ARCHITECTURAL_CLOUD_FLAT_RADIUS_RATIO = 0.38;
|
|
1049
|
+
var ARCHITECTURAL_CLOUD_ROUNDED_RADIUS = 72;
|
|
1050
|
+
var ARCHITECTURAL_CLOUD_ROUNDED_MIN_RADIUS = 44;
|
|
1051
|
+
var ARCHITECTURAL_CLOUD_ROUNDED_TARGET_SPACING = 98;
|
|
1052
|
+
function architecturalCloudCenterCount(edgeLength, radius) {
|
|
1053
|
+
const targetSpacing = Math.min(
|
|
1054
|
+
ARCHITECTURAL_CLOUD_TARGET_SPACING,
|
|
1055
|
+
Math.max(1, radius * 1.3)
|
|
1056
|
+
);
|
|
1057
|
+
return Math.max(2, Math.round(edgeLength / targetSpacing) + 1);
|
|
1058
|
+
}
|
|
1059
|
+
function distributeRange(start, end, count) {
|
|
1060
|
+
if (count <= 1) return [start];
|
|
1061
|
+
const step = (end - start) / (count - 1);
|
|
1062
|
+
return Array.from({ length: count }, (_, index) => start + step * index);
|
|
1063
|
+
}
|
|
1064
|
+
function lineCloudPathSegment(start, end) {
|
|
1065
|
+
const dx = end[0] - start[0];
|
|
1066
|
+
const dy = end[1] - start[1];
|
|
1067
|
+
const length = Math.hypot(dx, dy);
|
|
1068
|
+
return {
|
|
1069
|
+
length,
|
|
1070
|
+
pointAt: (t) => [start[0] + dx * t, start[1] + dy * t]
|
|
1071
|
+
};
|
|
1072
|
+
}
|
|
1073
|
+
function ellipsePoint(centerX, centerY, radiusX, radiusY, angle) {
|
|
1074
|
+
return [centerX + Math.cos(angle) * radiusX, centerY + Math.sin(angle) * radiusY];
|
|
1075
|
+
}
|
|
1076
|
+
function approximateEllipseArcLength(radiusX, radiusY, startAngle, endAngle) {
|
|
1077
|
+
const steps = Math.max(
|
|
1078
|
+
4,
|
|
1079
|
+
Math.ceil(Math.abs(endAngle - startAngle) / (Math.PI / 16))
|
|
1080
|
+
);
|
|
1081
|
+
let length = 0;
|
|
1082
|
+
let previous = ellipsePoint(0, 0, radiusX, radiusY, startAngle);
|
|
1083
|
+
for (let index = 1; index <= steps; index += 1) {
|
|
1084
|
+
const angle = startAngle + (endAngle - startAngle) * index / steps;
|
|
1085
|
+
const next = ellipsePoint(0, 0, radiusX, radiusY, angle);
|
|
1086
|
+
length += Math.hypot(next[0] - previous[0], next[1] - previous[1]);
|
|
1087
|
+
previous = next;
|
|
1088
|
+
}
|
|
1089
|
+
return length;
|
|
1090
|
+
}
|
|
1091
|
+
function ellipseCloudPathSegment(centerX, centerY, radiusX, radiusY, startAngle, endAngle) {
|
|
1092
|
+
return {
|
|
1093
|
+
length: approximateEllipseArcLength(radiusX, radiusY, startAngle, endAngle),
|
|
1094
|
+
pointAt: (t) => ellipsePoint(
|
|
1095
|
+
centerX,
|
|
1096
|
+
centerY,
|
|
1097
|
+
radiusX,
|
|
1098
|
+
radiusY,
|
|
1099
|
+
startAngle + (endAngle - startAngle) * t
|
|
1100
|
+
)
|
|
1101
|
+
};
|
|
1102
|
+
}
|
|
1103
|
+
function cloudPathPerimeter(segments) {
|
|
1104
|
+
const usableSegments = segments.filter((segment) => segment.length > 1e-9);
|
|
1105
|
+
return usableSegments.reduce((sum, segment) => sum + segment.length, 0);
|
|
1106
|
+
}
|
|
1107
|
+
function pointOnCloudPath(segments, distance) {
|
|
1108
|
+
const perimeter = cloudPathPerimeter(segments);
|
|
1109
|
+
if (perimeter <= 0) return [0, 0];
|
|
1110
|
+
let remaining = (distance % perimeter + perimeter) % perimeter;
|
|
1111
|
+
for (const segment of segments) {
|
|
1112
|
+
if (segment.length <= 1e-9) continue;
|
|
1113
|
+
if (remaining <= segment.length) {
|
|
1114
|
+
const t = remaining / segment.length;
|
|
1115
|
+
return segment.pointAt(t);
|
|
1116
|
+
}
|
|
1117
|
+
remaining -= segment.length;
|
|
1118
|
+
}
|
|
1119
|
+
const fallback = segments.find((segment) => segment.length > 1e-9);
|
|
1120
|
+
return fallback?.pointAt(0) ?? [0, 0];
|
|
1121
|
+
}
|
|
1122
|
+
function buildRoundedCapsulePathSegments(width, height, inset) {
|
|
1123
|
+
const left = inset;
|
|
1124
|
+
const top = inset;
|
|
1125
|
+
const right = width - inset;
|
|
1126
|
+
const bottom = height - inset;
|
|
1127
|
+
const capsuleWidth = Math.max(0, right - left);
|
|
1128
|
+
const capsuleHeight = Math.max(0, bottom - top);
|
|
1129
|
+
const radius = Math.min(capsuleWidth, capsuleHeight) / 2;
|
|
1130
|
+
if (radius <= 0) return [];
|
|
1131
|
+
const leftCenterX = left + radius;
|
|
1132
|
+
const rightCenterX = right - radius;
|
|
1133
|
+
const topCenterY = top + radius;
|
|
1134
|
+
const bottomCenterY = bottom - radius;
|
|
1060
1135
|
return [
|
|
1061
|
-
|
|
1062
|
-
|
|
1136
|
+
lineCloudPathSegment([leftCenterX, top], [rightCenterX, top]),
|
|
1137
|
+
ellipseCloudPathSegment(
|
|
1138
|
+
rightCenterX,
|
|
1139
|
+
topCenterY,
|
|
1140
|
+
radius,
|
|
1141
|
+
radius,
|
|
1142
|
+
-Math.PI / 2,
|
|
1143
|
+
0
|
|
1144
|
+
),
|
|
1145
|
+
lineCloudPathSegment([right, topCenterY], [right, bottomCenterY]),
|
|
1146
|
+
ellipseCloudPathSegment(
|
|
1147
|
+
rightCenterX,
|
|
1148
|
+
bottomCenterY,
|
|
1149
|
+
radius,
|
|
1150
|
+
radius,
|
|
1151
|
+
0,
|
|
1152
|
+
Math.PI / 2
|
|
1153
|
+
),
|
|
1154
|
+
lineCloudPathSegment([rightCenterX, bottom], [leftCenterX, bottom]),
|
|
1155
|
+
ellipseCloudPathSegment(
|
|
1156
|
+
leftCenterX,
|
|
1157
|
+
bottomCenterY,
|
|
1158
|
+
radius,
|
|
1159
|
+
radius,
|
|
1160
|
+
Math.PI / 2,
|
|
1161
|
+
Math.PI
|
|
1162
|
+
),
|
|
1163
|
+
lineCloudPathSegment([left, bottomCenterY], [left, topCenterY]),
|
|
1164
|
+
ellipseCloudPathSegment(
|
|
1165
|
+
leftCenterX,
|
|
1166
|
+
topCenterY,
|
|
1167
|
+
radius,
|
|
1168
|
+
radius,
|
|
1169
|
+
Math.PI,
|
|
1170
|
+
Math.PI * 1.5
|
|
1171
|
+
)
|
|
1172
|
+
];
|
|
1173
|
+
}
|
|
1174
|
+
function buildRoundedArcCloudPathD(cloudWidth, cloudHeight, center) {
|
|
1175
|
+
const minDimension = Math.min(cloudWidth, cloudHeight);
|
|
1176
|
+
const radius = Math.min(
|
|
1177
|
+
ARCHITECTURAL_CLOUD_ROUNDED_RADIUS,
|
|
1178
|
+
Math.max(ARCHITECTURAL_CLOUD_ROUNDED_MIN_RADIUS, minDimension * 0.16)
|
|
1179
|
+
);
|
|
1180
|
+
const centerPath = buildRoundedCapsulePathSegments(
|
|
1181
|
+
cloudWidth,
|
|
1182
|
+
cloudHeight,
|
|
1183
|
+
radius
|
|
1184
|
+
);
|
|
1185
|
+
const centerPerimeter = cloudPathPerimeter(centerPath);
|
|
1186
|
+
if (centerPerimeter <= 0) return "";
|
|
1187
|
+
const lobeCount = Math.max(
|
|
1188
|
+
8,
|
|
1189
|
+
Math.round(centerPerimeter / ARCHITECTURAL_CLOUD_ROUNDED_TARGET_SPACING)
|
|
1190
|
+
);
|
|
1191
|
+
const centers = Array.from(
|
|
1192
|
+
{ length: lobeCount },
|
|
1193
|
+
(_, index) => pointOnCloudPath(centerPath, centerPerimeter * index / lobeCount)
|
|
1194
|
+
);
|
|
1195
|
+
const points = centers.map((point, index) => {
|
|
1196
|
+
const previous = centers[(index - 1 + centers.length) % centers.length] ?? point;
|
|
1197
|
+
return cloudCircleIntersection(previous, point, radius, center);
|
|
1198
|
+
});
|
|
1199
|
+
const [startX, startY] = points[0] ?? [0, 0];
|
|
1200
|
+
const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
|
|
1201
|
+
for (const [endX, endY] of points.slice(1)) {
|
|
1202
|
+
segments.push(
|
|
1203
|
+
`A ${svgNumber(radius)} ${svgNumber(radius)} 0 0 1 ${svgNumber(endX)} ${svgNumber(endY)}`
|
|
1204
|
+
);
|
|
1205
|
+
}
|
|
1206
|
+
segments.push(
|
|
1207
|
+
`A ${svgNumber(radius)} ${svgNumber(radius)} 0 0 1 ${svgNumber(startX)} ${svgNumber(startY)}`
|
|
1208
|
+
);
|
|
1209
|
+
segments.push("Z");
|
|
1210
|
+
return segments.join(" ");
|
|
1211
|
+
}
|
|
1212
|
+
function cloudCircleIntersection(a, b, radius, center) {
|
|
1213
|
+
const midX = (a[0] + b[0]) / 2;
|
|
1214
|
+
const midY = (a[1] + b[1]) / 2;
|
|
1215
|
+
const dx = b[0] - a[0];
|
|
1216
|
+
const dy = b[1] - a[1];
|
|
1217
|
+
const distance = Math.hypot(dx, dy);
|
|
1218
|
+
if (distance <= 1e-9) return [midX, midY];
|
|
1219
|
+
const halfDistance = distance / 2;
|
|
1220
|
+
const offset = Math.sqrt(
|
|
1221
|
+
Math.max(0, radius * radius - halfDistance * halfDistance)
|
|
1222
|
+
);
|
|
1223
|
+
const normalX = -dy / distance;
|
|
1224
|
+
const normalY = dx / distance;
|
|
1225
|
+
const first = [midX + normalX * offset, midY + normalY * offset];
|
|
1226
|
+
const second = [
|
|
1227
|
+
midX - normalX * offset,
|
|
1228
|
+
midY - normalY * offset
|
|
1063
1229
|
];
|
|
1230
|
+
const firstDistance = (first[0] - center[0]) * (first[0] - center[0]) + (first[1] - center[1]) * (first[1] - center[1]);
|
|
1231
|
+
const secondDistance = (second[0] - center[0]) * (second[0] - center[0]) + (second[1] - center[1]) * (second[1] - center[1]);
|
|
1232
|
+
return firstDistance >= secondDistance ? first : second;
|
|
1233
|
+
}
|
|
1234
|
+
function cloudEllipseIntersection(a, b, radiusX, radiusY, center) {
|
|
1235
|
+
const scaleY = radiusX / radiusY;
|
|
1236
|
+
const [x, y] = cloudCircleIntersection(
|
|
1237
|
+
[a[0], a[1] * scaleY],
|
|
1238
|
+
[b[0], b[1] * scaleY],
|
|
1239
|
+
radiusX,
|
|
1240
|
+
[center[0], center[1] * scaleY]
|
|
1241
|
+
);
|
|
1242
|
+
return [x, y / scaleY];
|
|
1064
1243
|
}
|
|
1065
1244
|
function buildRectSvg(width, height, style = DEFAULT_STROKE_STYLE) {
|
|
1066
1245
|
return `<rect width="${width}" height="${height}" fill="none" stroke="${style.stroke}" stroke-width="${style.strokeWidth}" rx="4"${strokeOpacityAttr(style)} />`;
|
|
@@ -1074,40 +1253,63 @@ function buildArchitecturalCloudPathD(width, height, strokeWidth = DEFAULT_STROK
|
|
|
1074
1253
|
const w = Math.max(0, width);
|
|
1075
1254
|
const h = Math.max(0, height);
|
|
1076
1255
|
if (w <= 0 || h <= 0) return "";
|
|
1077
|
-
const
|
|
1078
|
-
const
|
|
1079
|
-
const
|
|
1080
|
-
if (
|
|
1081
|
-
const
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
outerRy * 0.45,
|
|
1085
|
-
Math.max(2, Math.min(7, Math.min(w, h) * 0.035))
|
|
1256
|
+
const padding = Math.max(0, strokeWidth * 2);
|
|
1257
|
+
const cloudWidth = Math.max(0, w - padding);
|
|
1258
|
+
const cloudHeight = Math.max(0, h - padding);
|
|
1259
|
+
if (cloudWidth <= 0 || cloudHeight <= 0) return "";
|
|
1260
|
+
const radiusX = Math.min(
|
|
1261
|
+
ARCHITECTURAL_CLOUD_RADIUS,
|
|
1262
|
+
cloudWidth * ARCHITECTURAL_CLOUD_FLAT_RADIUS_RATIO
|
|
1086
1263
|
);
|
|
1087
|
-
const
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
const
|
|
1093
|
-
const
|
|
1094
|
-
const
|
|
1095
|
-
const
|
|
1096
|
-
const
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1264
|
+
const radiusY = Math.min(
|
|
1265
|
+
ARCHITECTURAL_CLOUD_RADIUS,
|
|
1266
|
+
cloudHeight * ARCHITECTURAL_CLOUD_FLAT_RADIUS_RATIO
|
|
1267
|
+
);
|
|
1268
|
+
if (radiusX <= 0 || radiusY <= 0) return "";
|
|
1269
|
+
const center = [cloudWidth / 2, cloudHeight / 2];
|
|
1270
|
+
const leftCenterX = radiusX;
|
|
1271
|
+
const rightCenterX = cloudWidth - radiusX;
|
|
1272
|
+
const topCenterY = radiusY;
|
|
1273
|
+
const bottomCenterY = cloudHeight - radiusY;
|
|
1274
|
+
const horizontalCenters = distributeRange(
|
|
1275
|
+
leftCenterX,
|
|
1276
|
+
rightCenterX,
|
|
1277
|
+
architecturalCloudCenterCount(Math.max(0, rightCenterX - leftCenterX), radiusX)
|
|
1278
|
+
);
|
|
1279
|
+
const verticalCenters = distributeRange(
|
|
1280
|
+
topCenterY,
|
|
1281
|
+
bottomCenterY,
|
|
1282
|
+
architecturalCloudCenterCount(Math.max(0, bottomCenterY - topCenterY), radiusY)
|
|
1283
|
+
);
|
|
1284
|
+
if (horizontalCenters.length > 3 && verticalCenters.length > 3) {
|
|
1285
|
+
const roundedArcCloudPath = buildRoundedArcCloudPathD(
|
|
1286
|
+
cloudWidth,
|
|
1287
|
+
cloudHeight,
|
|
1288
|
+
center
|
|
1105
1289
|
);
|
|
1106
|
-
|
|
1290
|
+
if (roundedArcCloudPath !== "") return roundedArcCloudPath;
|
|
1291
|
+
}
|
|
1292
|
+
const rectangularCenters = [
|
|
1293
|
+
...horizontalCenters.map((x) => [x, topCenterY]),
|
|
1294
|
+
...verticalCenters.slice(1).map((y) => [rightCenterX, y]),
|
|
1295
|
+
...horizontalCenters.slice(0, -1).reverse().map((x) => [x, bottomCenterY]),
|
|
1296
|
+
...verticalCenters.slice(1, -1).reverse().map((y) => [leftCenterX, y])
|
|
1297
|
+
];
|
|
1298
|
+
const centers = rectangularCenters;
|
|
1299
|
+
const points = centers.map((point, index) => {
|
|
1300
|
+
const previous = centers[(index - 1 + centers.length) % centers.length] ?? point;
|
|
1301
|
+
return cloudEllipseIntersection(previous, point, radiusX, radiusY, center);
|
|
1302
|
+
});
|
|
1303
|
+
const [startX, startY] = points[0] ?? [0, 0];
|
|
1304
|
+
const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
|
|
1305
|
+
for (const [endX, endY] of points.slice(1)) {
|
|
1107
1306
|
segments.push(
|
|
1108
|
-
`
|
|
1307
|
+
`A ${svgNumber(radiusX)} ${svgNumber(radiusY)} 0 0 1 ${svgNumber(endX)} ${svgNumber(endY)}`
|
|
1109
1308
|
);
|
|
1110
1309
|
}
|
|
1310
|
+
segments.push(
|
|
1311
|
+
`A ${svgNumber(radiusX)} ${svgNumber(radiusY)} 0 0 1 ${svgNumber(startX)} ${svgNumber(startY)}`
|
|
1312
|
+
);
|
|
1111
1313
|
segments.push("Z");
|
|
1112
1314
|
return segments.join(" ");
|
|
1113
1315
|
}
|