canvu-react 0.3.32 → 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/tldraw.js CHANGED
@@ -222,24 +222,153 @@ 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 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);
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
  }
236
- function pointOnSuperellipse(centerX, centerY, radiusX, radiusY, theta, exponent) {
237
- const cosTheta = Math.cos(theta);
238
- const sinTheta = Math.sin(theta);
239
- return [
240
- centerX + Math.sign(cosTheta) * radiusX * Math.abs(cosTheta) ** (2 / exponent),
241
- centerY + Math.sign(sinTheta) * radiusY * Math.abs(sinTheta) ** (2 / exponent)
242
- ];
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];
243
372
  }
244
373
  function buildRectSvg(width, height, style = DEFAULT_STROKE_STYLE) {
245
374
  return `<rect width="${width}" height="${height}" fill="none" stroke="${style.stroke}" stroke-width="${style.strokeWidth}" rx="4"${strokeOpacityAttr(style)} />`;
@@ -254,35 +383,34 @@ function buildArchitecturalCloudPathD(width, height, strokeWidth = DEFAULT_STROK
254
383
  const h = Math.max(0, height);
255
384
  if (w <= 0 || h <= 0) return "";
256
385
  const inset = Math.max(0.5, strokeWidth / 2);
257
- const outerRx = Math.max(0, w / 2 - inset);
258
- const outerRy = Math.max(0, h / 2 - inset);
259
- if (outerRx <= 0 || outerRy <= 0) return "";
260
- const baseExponent = 3.6;
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 "";
261
389
  const amplitude = Math.min(
262
- outerRx * 0.45,
263
- outerRy * 0.45,
264
- Math.max(2, Math.min(7, Math.min(w, h) * 0.035))
390
+ outerWidth * 0.12,
391
+ outerHeight * 0.12,
392
+ Math.max(5, Math.min(14, Math.min(w, h) * 0.07))
265
393
  );
266
- const innerRx = Math.max(0, outerRx - amplitude);
267
- const innerRy = Math.max(0, outerRy - amplitude);
268
- const scallopCount = architecturalCloudScallopCount(innerRx, innerRy, amplitude);
269
- const angleStep = Math.PI * 2 / scallopCount;
270
- const cx = w / 2;
271
- const cy = h / 2;
272
- const startAngle = -Math.PI / 2;
273
- const pointOnArchitecturalCloud = (theta, radiusX, radiusY) => pointOnSuperellipse(cx, cy, radiusX, radiusY, theta, baseExponent);
274
- const [startX, startY] = pointOnArchitecturalCloud(startAngle, innerRx, innerRy);
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)
405
+ );
406
+ const scallopCount = architecturalCloudScallopCount(outer.perimeter, amplitude);
407
+ const [startX, startY] = pointOnRoundedRectPath(inner, 0);
275
408
  const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
276
409
  for (let index = 0; index < scallopCount; index += 1) {
277
- const segmentStart = startAngle + index * angleStep;
278
- const segmentMid = segmentStart + angleStep / 2;
279
- const segmentEnd = segmentStart + angleStep;
280
- const [controlX, controlY] = pointOnArchitecturalCloud(
281
- segmentMid,
282
- outerRx,
283
- outerRy
284
- );
285
- const [endX, endY] = pointOnArchitecturalCloud(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);
286
414
  segments.push(
287
415
  `Q${svgNumber(controlX)} ${svgNumber(controlY)} ${svgNumber(endX)} ${svgNumber(endY)}`
288
416
  );