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/tldraw.js
CHANGED
|
@@ -217,40 +217,21 @@ function resolveStrokeStyle(item) {
|
|
|
217
217
|
function strokeOpacityAttr(style) {
|
|
218
218
|
return style.strokeOpacity != null ? ` stroke-opacity="${style.strokeOpacity}"` : "";
|
|
219
219
|
}
|
|
220
|
-
function clampNumber(value, min, max) {
|
|
221
|
-
return Math.min(max, Math.max(min, value));
|
|
222
|
-
}
|
|
223
220
|
function svgNumber(value) {
|
|
224
221
|
if (!Number.isFinite(value)) return "0";
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
function architecturalCloudScallopCount(length, depth) {
|
|
228
|
-
if (length <= 1e-6) return 0;
|
|
229
|
-
return Math.max(1, Math.round(length / Math.max(depth * 2.05, 8)));
|
|
230
|
-
}
|
|
231
|
-
function appendHorizontalScallops(segments, startX, endX, y, controlY, count) {
|
|
232
|
-
if (count <= 0) return;
|
|
233
|
-
const step = (endX - startX) / count;
|
|
234
|
-
for (let index = 1; index <= count; index += 1) {
|
|
235
|
-
const x0 = startX + step * (index - 1);
|
|
236
|
-
const x1 = index === count ? endX : startX + step * index;
|
|
237
|
-
const cx = (x0 + x1) / 2;
|
|
238
|
-
segments.push(
|
|
239
|
-
`Q${svgNumber(cx)} ${svgNumber(controlY)} ${svgNumber(x1)} ${svgNumber(y)}`
|
|
240
|
-
);
|
|
241
|
-
}
|
|
222
|
+
const rounded = Math.round(value * 100) / 100;
|
|
223
|
+
return Number.isInteger(rounded) ? String(rounded) : String(rounded);
|
|
242
224
|
}
|
|
243
|
-
function
|
|
244
|
-
if (
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
}
|
|
225
|
+
function approximateEllipsePerimeter(rx, ry) {
|
|
226
|
+
if (rx <= 0 || ry <= 0) return 0;
|
|
227
|
+
return Math.PI * (3 * (rx + ry) - Math.sqrt((3 * rx + ry) * (rx + 3 * ry)));
|
|
228
|
+
}
|
|
229
|
+
function architecturalCloudScallopCount(rx, ry, amplitude) {
|
|
230
|
+
const perimeter = approximateEllipsePerimeter(rx, ry);
|
|
231
|
+
const targetScallopLength = Math.max(10, amplitude * 2);
|
|
232
|
+
let count = Math.max(12, Math.round(perimeter / targetScallopLength));
|
|
233
|
+
if (count % 2 === 1) count += 1;
|
|
234
|
+
return count;
|
|
254
235
|
}
|
|
255
236
|
function buildRectSvg(width, height, style = DEFAULT_STROKE_STYLE) {
|
|
256
237
|
return `<rect width="${width}" height="${height}" fill="none" stroke="${style.stroke}" stroke-width="${style.strokeWidth}" rx="4"${strokeOpacityAttr(style)} />`;
|
|
@@ -264,53 +245,39 @@ function buildArchitecturalCloudPathD(width, height, strokeWidth = DEFAULT_STROK
|
|
|
264
245
|
const w = Math.max(0, width);
|
|
265
246
|
const h = Math.max(0, height);
|
|
266
247
|
if (w <= 0 || h <= 0) return "";
|
|
267
|
-
const inset = Math.
|
|
268
|
-
const
|
|
269
|
-
const
|
|
270
|
-
|
|
271
|
-
const
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
const maxDepth = Math.max(0.5, Math.min(innerW, innerH) * 0.18);
|
|
276
|
-
const depth = clampNumber(Math.min(w, h) * 0.08, 2, Math.min(12, maxDepth));
|
|
277
|
-
const corner = Math.min(depth * 1.2, innerW / 2, innerH / 2);
|
|
278
|
-
const topStart = x0 + corner;
|
|
279
|
-
const topEnd = x1 - corner;
|
|
280
|
-
const rightStart = y0 + corner;
|
|
281
|
-
const rightEnd = y1 - corner;
|
|
282
|
-
const bottomStart = x1 - corner;
|
|
283
|
-
const bottomEnd = x0 + corner;
|
|
284
|
-
const leftStart = y1 - corner;
|
|
285
|
-
const leftEnd = y0 + corner;
|
|
286
|
-
const topCount = architecturalCloudScallopCount(topEnd - topStart, depth);
|
|
287
|
-
const rightCount = architecturalCloudScallopCount(rightEnd - rightStart, depth);
|
|
288
|
-
const bottomCount = architecturalCloudScallopCount(bottomStart - bottomEnd, depth);
|
|
289
|
-
const leftCount = architecturalCloudScallopCount(leftStart - leftEnd, depth);
|
|
290
|
-
const segments = [`M${svgNumber(topStart)} ${svgNumber(y0)}`];
|
|
291
|
-
appendHorizontalScallops(segments, topStart, topEnd, y0, y0 + depth, topCount);
|
|
292
|
-
segments.push(
|
|
293
|
-
`Q${svgNumber(x1)} ${svgNumber(y0)} ${svgNumber(x1)} ${svgNumber(rightStart)}`
|
|
294
|
-
);
|
|
295
|
-
appendVerticalScallops(segments, rightStart, rightEnd, x1, x1 - depth, rightCount);
|
|
296
|
-
segments.push(
|
|
297
|
-
`Q${svgNumber(x1)} ${svgNumber(y1)} ${svgNumber(bottomStart)} ${svgNumber(y1)}`
|
|
298
|
-
);
|
|
299
|
-
appendHorizontalScallops(
|
|
300
|
-
segments,
|
|
301
|
-
bottomStart,
|
|
302
|
-
bottomEnd,
|
|
303
|
-
y1,
|
|
304
|
-
y1 - depth,
|
|
305
|
-
bottomCount
|
|
306
|
-
);
|
|
307
|
-
segments.push(
|
|
308
|
-
`Q${svgNumber(x0)} ${svgNumber(y1)} ${svgNumber(x0)} ${svgNumber(leftStart)}`
|
|
309
|
-
);
|
|
310
|
-
appendVerticalScallops(segments, leftStart, leftEnd, x0, x0 + depth, leftCount);
|
|
311
|
-
segments.push(
|
|
312
|
-
`Q${svgNumber(x0)} ${svgNumber(y0)} ${svgNumber(topStart)} ${svgNumber(y0)} Z`
|
|
248
|
+
const inset = Math.max(0.5, strokeWidth / 2);
|
|
249
|
+
const outerRx = Math.max(0, w / 2 - inset);
|
|
250
|
+
const outerRy = Math.max(0, h / 2 - inset);
|
|
251
|
+
if (outerRx <= 0 || outerRy <= 0) return "";
|
|
252
|
+
const amplitude = Math.min(
|
|
253
|
+
outerRx * 0.45,
|
|
254
|
+
outerRy * 0.45,
|
|
255
|
+
Math.max(2, Math.min(8, Math.min(w, h) * 0.04))
|
|
313
256
|
);
|
|
257
|
+
const innerRx = Math.max(0, outerRx - amplitude);
|
|
258
|
+
const innerRy = Math.max(0, outerRy - amplitude);
|
|
259
|
+
const scallopCount = architecturalCloudScallopCount(innerRx, innerRy, amplitude);
|
|
260
|
+
const angleStep = Math.PI * 2 / scallopCount;
|
|
261
|
+
const cx = w / 2;
|
|
262
|
+
const cy = h / 2;
|
|
263
|
+
const startAngle = -Math.PI / 2;
|
|
264
|
+
const pointOnEllipse = (theta, radiusX, radiusY) => [
|
|
265
|
+
cx + Math.cos(theta) * radiusX,
|
|
266
|
+
cy + Math.sin(theta) * radiusY
|
|
267
|
+
];
|
|
268
|
+
const [startX, startY] = pointOnEllipse(startAngle, innerRx, innerRy);
|
|
269
|
+
const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
|
|
270
|
+
for (let index = 0; index < scallopCount; index += 1) {
|
|
271
|
+
const segmentStart = startAngle + index * angleStep;
|
|
272
|
+
const segmentMid = segmentStart + angleStep / 2;
|
|
273
|
+
const segmentEnd = segmentStart + angleStep;
|
|
274
|
+
const [controlX, controlY] = pointOnEllipse(segmentMid, outerRx, outerRy);
|
|
275
|
+
const [endX, endY] = pointOnEllipse(segmentEnd, innerRx, innerRy);
|
|
276
|
+
segments.push(
|
|
277
|
+
`Q${svgNumber(controlX)} ${svgNumber(controlY)} ${svgNumber(endX)} ${svgNumber(endY)}`
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
segments.push("Z");
|
|
314
281
|
return segments.join(" ");
|
|
315
282
|
}
|
|
316
283
|
function buildArchitecturalCloudSvg(width, height, style = DEFAULT_STROKE_STYLE) {
|