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