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/tldraw.js
CHANGED
|
@@ -222,17 +222,154 @@ function svgNumber(value) {
|
|
|
222
222
|
const rounded = Math.round(value * 100) / 100;
|
|
223
223
|
return Number.isInteger(rounded) ? String(rounded) : String(rounded);
|
|
224
224
|
}
|
|
225
|
-
function
|
|
226
|
-
|
|
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);
|
|
225
|
+
function architecturalCloudScallopCount(perimeter, amplitude) {
|
|
226
|
+
const targetScallopLength = Math.max(18, amplitude * 2.45);
|
|
232
227
|
let count = Math.max(12, Math.round(perimeter / targetScallopLength));
|
|
233
228
|
if (count % 2 === 1) count += 1;
|
|
234
229
|
return count;
|
|
235
230
|
}
|
|
231
|
+
function roundedRectMetrics(width, height, inset, radius) {
|
|
232
|
+
const left = inset;
|
|
233
|
+
const top = inset;
|
|
234
|
+
const right = width - inset;
|
|
235
|
+
const bottom = height - inset;
|
|
236
|
+
const rectWidth = Math.max(0, right - left);
|
|
237
|
+
const rectHeight = Math.max(0, bottom - top);
|
|
238
|
+
const normalizedRadius = Math.max(
|
|
239
|
+
0,
|
|
240
|
+
Math.min(radius, rectWidth / 2, rectHeight / 2)
|
|
241
|
+
);
|
|
242
|
+
const centerX = width / 2;
|
|
243
|
+
const topHalfLength = Math.max(0, right - normalizedRadius - centerX);
|
|
244
|
+
const horizontalLength = Math.max(0, rectWidth - normalizedRadius * 2);
|
|
245
|
+
const verticalLength = Math.max(0, rectHeight - normalizedRadius * 2);
|
|
246
|
+
const arcLength = normalizedRadius * (Math.PI / 2);
|
|
247
|
+
return {
|
|
248
|
+
left,
|
|
249
|
+
top,
|
|
250
|
+
right,
|
|
251
|
+
bottom,
|
|
252
|
+
radius: normalizedRadius,
|
|
253
|
+
centerX,
|
|
254
|
+
topHalfLength,
|
|
255
|
+
horizontalLength,
|
|
256
|
+
verticalLength,
|
|
257
|
+
arcLength,
|
|
258
|
+
perimeter: horizontalLength * 2 + verticalLength * 2 + Math.PI * 2 * normalizedRadius
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
function pointOnLine(startX, startY, endX, endY, t) {
|
|
262
|
+
return [startX + (endX - startX) * t, startY + (endY - startY) * t];
|
|
263
|
+
}
|
|
264
|
+
function pointOnArc(centerX, centerY, radius, startAngle, endAngle, t) {
|
|
265
|
+
const theta = startAngle + (endAngle - startAngle) * t;
|
|
266
|
+
return [centerX + Math.cos(theta) * radius, centerY + Math.sin(theta) * radius];
|
|
267
|
+
}
|
|
268
|
+
function pointOnRoundedRectPath(metrics, distance) {
|
|
269
|
+
if (metrics.perimeter <= 0) return [metrics.centerX, metrics.top];
|
|
270
|
+
let remaining = (distance % metrics.perimeter + metrics.perimeter) % metrics.perimeter;
|
|
271
|
+
const consume = (length) => {
|
|
272
|
+
if (length <= 1e-9) return null;
|
|
273
|
+
if (remaining <= length) return remaining / length;
|
|
274
|
+
remaining -= length;
|
|
275
|
+
return null;
|
|
276
|
+
};
|
|
277
|
+
let t = consume(metrics.topHalfLength);
|
|
278
|
+
if (t != null) {
|
|
279
|
+
return pointOnLine(
|
|
280
|
+
metrics.centerX,
|
|
281
|
+
metrics.top,
|
|
282
|
+
metrics.right - metrics.radius,
|
|
283
|
+
metrics.top,
|
|
284
|
+
t
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
t = consume(metrics.arcLength);
|
|
288
|
+
if (t != null) {
|
|
289
|
+
return pointOnArc(
|
|
290
|
+
metrics.right - metrics.radius,
|
|
291
|
+
metrics.top + metrics.radius,
|
|
292
|
+
metrics.radius,
|
|
293
|
+
-Math.PI / 2,
|
|
294
|
+
0,
|
|
295
|
+
t
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
t = consume(metrics.verticalLength);
|
|
299
|
+
if (t != null) {
|
|
300
|
+
return pointOnLine(
|
|
301
|
+
metrics.right,
|
|
302
|
+
metrics.top + metrics.radius,
|
|
303
|
+
metrics.right,
|
|
304
|
+
metrics.bottom - metrics.radius,
|
|
305
|
+
t
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
t = consume(metrics.arcLength);
|
|
309
|
+
if (t != null) {
|
|
310
|
+
return pointOnArc(
|
|
311
|
+
metrics.right - metrics.radius,
|
|
312
|
+
metrics.bottom - metrics.radius,
|
|
313
|
+
metrics.radius,
|
|
314
|
+
0,
|
|
315
|
+
Math.PI / 2,
|
|
316
|
+
t
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
t = consume(metrics.horizontalLength);
|
|
320
|
+
if (t != null) {
|
|
321
|
+
return pointOnLine(
|
|
322
|
+
metrics.right - metrics.radius,
|
|
323
|
+
metrics.bottom,
|
|
324
|
+
metrics.left + metrics.radius,
|
|
325
|
+
metrics.bottom,
|
|
326
|
+
t
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
t = consume(metrics.arcLength);
|
|
330
|
+
if (t != null) {
|
|
331
|
+
return pointOnArc(
|
|
332
|
+
metrics.left + metrics.radius,
|
|
333
|
+
metrics.bottom - metrics.radius,
|
|
334
|
+
metrics.radius,
|
|
335
|
+
Math.PI / 2,
|
|
336
|
+
Math.PI,
|
|
337
|
+
t
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
t = consume(metrics.verticalLength);
|
|
341
|
+
if (t != null) {
|
|
342
|
+
return pointOnLine(
|
|
343
|
+
metrics.left,
|
|
344
|
+
metrics.bottom - metrics.radius,
|
|
345
|
+
metrics.left,
|
|
346
|
+
metrics.top + metrics.radius,
|
|
347
|
+
t
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
t = consume(metrics.arcLength);
|
|
351
|
+
if (t != null) {
|
|
352
|
+
return pointOnArc(
|
|
353
|
+
metrics.left + metrics.radius,
|
|
354
|
+
metrics.top + metrics.radius,
|
|
355
|
+
metrics.radius,
|
|
356
|
+
Math.PI,
|
|
357
|
+
Math.PI * 1.5,
|
|
358
|
+
t
|
|
359
|
+
);
|
|
360
|
+
}
|
|
361
|
+
t = consume(metrics.topHalfLength);
|
|
362
|
+
if (t != null) {
|
|
363
|
+
return pointOnLine(
|
|
364
|
+
metrics.left + metrics.radius,
|
|
365
|
+
metrics.top,
|
|
366
|
+
metrics.centerX,
|
|
367
|
+
metrics.top,
|
|
368
|
+
t
|
|
369
|
+
);
|
|
370
|
+
}
|
|
371
|
+
return [metrics.centerX, metrics.top];
|
|
372
|
+
}
|
|
236
373
|
function buildRectSvg(width, height, style = DEFAULT_STROKE_STYLE) {
|
|
237
374
|
return `<rect width="${width}" height="${height}" fill="none" stroke="${style.stroke}" stroke-width="${style.strokeWidth}" rx="4"${strokeOpacityAttr(style)} />`;
|
|
238
375
|
}
|
|
@@ -246,33 +383,34 @@ function buildArchitecturalCloudPathD(width, height, strokeWidth = DEFAULT_STROK
|
|
|
246
383
|
const h = Math.max(0, height);
|
|
247
384
|
if (w <= 0 || h <= 0) return "";
|
|
248
385
|
const inset = Math.max(0.5, strokeWidth / 2);
|
|
249
|
-
const
|
|
250
|
-
const
|
|
251
|
-
if (
|
|
386
|
+
const outerWidth = Math.max(0, w - inset * 2);
|
|
387
|
+
const outerHeight = Math.max(0, h - inset * 2);
|
|
388
|
+
if (outerWidth <= 0 || outerHeight <= 0) return "";
|
|
252
389
|
const amplitude = Math.min(
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
Math.max(
|
|
390
|
+
outerWidth * 0.12,
|
|
391
|
+
outerHeight * 0.12,
|
|
392
|
+
Math.max(5, Math.min(14, Math.min(w, h) * 0.07))
|
|
393
|
+
);
|
|
394
|
+
const radius = Math.min(
|
|
395
|
+
outerWidth / 2,
|
|
396
|
+
outerHeight / 2,
|
|
397
|
+
Math.max(amplitude * 2.5, outerHeight * 0.43)
|
|
398
|
+
);
|
|
399
|
+
const outer = roundedRectMetrics(w, h, inset, radius);
|
|
400
|
+
const inner = roundedRectMetrics(
|
|
401
|
+
w,
|
|
402
|
+
h,
|
|
403
|
+
inset + amplitude,
|
|
404
|
+
Math.max(0, radius - amplitude)
|
|
256
405
|
);
|
|
257
|
-
const
|
|
258
|
-
const
|
|
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);
|
|
406
|
+
const scallopCount = architecturalCloudScallopCount(outer.perimeter, amplitude);
|
|
407
|
+
const [startX, startY] = pointOnRoundedRectPath(inner, 0);
|
|
269
408
|
const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
|
|
270
409
|
for (let index = 0; index < scallopCount; index += 1) {
|
|
271
|
-
const
|
|
272
|
-
const
|
|
273
|
-
const
|
|
274
|
-
const [
|
|
275
|
-
const [endX, endY] = pointOnEllipse(segmentEnd, innerRx, innerRy);
|
|
410
|
+
const controlDistance = (index + 0.5) / scallopCount * outer.perimeter;
|
|
411
|
+
const endDistance = (index + 1) / scallopCount * inner.perimeter;
|
|
412
|
+
const [controlX, controlY] = pointOnRoundedRectPath(outer, controlDistance);
|
|
413
|
+
const [endX, endY] = pointOnRoundedRectPath(inner, endDistance);
|
|
276
414
|
segments.push(
|
|
277
415
|
`Q${svgNumber(controlX)} ${svgNumber(controlY)} ${svgNumber(endX)} ${svgNumber(endY)}`
|
|
278
416
|
);
|