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/react.cjs CHANGED
@@ -291,24 +291,153 @@ function svgNumber(value) {
291
291
  const rounded = Math.round(value * 100) / 100;
292
292
  return Number.isInteger(rounded) ? String(rounded) : String(rounded);
293
293
  }
294
- function approximateEllipsePerimeter(rx, ry) {
295
- if (rx <= 0 || ry <= 0) return 0;
296
- return Math.PI * (3 * (rx + ry) - Math.sqrt((3 * rx + ry) * (rx + 3 * ry)));
297
- }
298
- function architecturalCloudScallopCount(rx, ry, amplitude) {
299
- const perimeter = approximateEllipsePerimeter(rx, ry);
300
- const targetScallopLength = Math.max(10, amplitude * 2);
294
+ function architecturalCloudScallopCount(perimeter, amplitude) {
295
+ const targetScallopLength = Math.max(18, amplitude * 2.45);
301
296
  let count = Math.max(12, Math.round(perimeter / targetScallopLength));
302
297
  if (count % 2 === 1) count += 1;
303
298
  return count;
304
299
  }
305
- function pointOnSuperellipse(centerX, centerY, radiusX, radiusY, theta, exponent) {
306
- const cosTheta = Math.cos(theta);
307
- const sinTheta = Math.sin(theta);
308
- return [
309
- centerX + Math.sign(cosTheta) * radiusX * Math.abs(cosTheta) ** (2 / exponent),
310
- centerY + Math.sign(sinTheta) * radiusY * Math.abs(sinTheta) ** (2 / exponent)
311
- ];
300
+ function roundedRectMetrics(width, height, inset, radius) {
301
+ const left = inset;
302
+ const top = inset;
303
+ const right = width - inset;
304
+ const bottom = height - inset;
305
+ const rectWidth = Math.max(0, right - left);
306
+ const rectHeight = Math.max(0, bottom - top);
307
+ const normalizedRadius = Math.max(
308
+ 0,
309
+ Math.min(radius, rectWidth / 2, rectHeight / 2)
310
+ );
311
+ const centerX = width / 2;
312
+ const topHalfLength = Math.max(0, right - normalizedRadius - centerX);
313
+ const horizontalLength = Math.max(0, rectWidth - normalizedRadius * 2);
314
+ const verticalLength = Math.max(0, rectHeight - normalizedRadius * 2);
315
+ const arcLength = normalizedRadius * (Math.PI / 2);
316
+ return {
317
+ left,
318
+ top,
319
+ right,
320
+ bottom,
321
+ radius: normalizedRadius,
322
+ centerX,
323
+ topHalfLength,
324
+ horizontalLength,
325
+ verticalLength,
326
+ arcLength,
327
+ perimeter: horizontalLength * 2 + verticalLength * 2 + Math.PI * 2 * normalizedRadius
328
+ };
329
+ }
330
+ function pointOnLine(startX, startY, endX, endY, t) {
331
+ return [startX + (endX - startX) * t, startY + (endY - startY) * t];
332
+ }
333
+ function pointOnArc(centerX, centerY, radius, startAngle, endAngle, t) {
334
+ const theta = startAngle + (endAngle - startAngle) * t;
335
+ return [centerX + Math.cos(theta) * radius, centerY + Math.sin(theta) * radius];
336
+ }
337
+ function pointOnRoundedRectPath(metrics, distance) {
338
+ if (metrics.perimeter <= 0) return [metrics.centerX, metrics.top];
339
+ let remaining = (distance % metrics.perimeter + metrics.perimeter) % metrics.perimeter;
340
+ const consume = (length) => {
341
+ if (length <= 1e-9) return null;
342
+ if (remaining <= length) return remaining / length;
343
+ remaining -= length;
344
+ return null;
345
+ };
346
+ let t = consume(metrics.topHalfLength);
347
+ if (t != null) {
348
+ return pointOnLine(
349
+ metrics.centerX,
350
+ metrics.top,
351
+ metrics.right - metrics.radius,
352
+ metrics.top,
353
+ t
354
+ );
355
+ }
356
+ t = consume(metrics.arcLength);
357
+ if (t != null) {
358
+ return pointOnArc(
359
+ metrics.right - metrics.radius,
360
+ metrics.top + metrics.radius,
361
+ metrics.radius,
362
+ -Math.PI / 2,
363
+ 0,
364
+ t
365
+ );
366
+ }
367
+ t = consume(metrics.verticalLength);
368
+ if (t != null) {
369
+ return pointOnLine(
370
+ metrics.right,
371
+ metrics.top + metrics.radius,
372
+ metrics.right,
373
+ metrics.bottom - metrics.radius,
374
+ t
375
+ );
376
+ }
377
+ t = consume(metrics.arcLength);
378
+ if (t != null) {
379
+ return pointOnArc(
380
+ metrics.right - metrics.radius,
381
+ metrics.bottom - metrics.radius,
382
+ metrics.radius,
383
+ 0,
384
+ Math.PI / 2,
385
+ t
386
+ );
387
+ }
388
+ t = consume(metrics.horizontalLength);
389
+ if (t != null) {
390
+ return pointOnLine(
391
+ metrics.right - metrics.radius,
392
+ metrics.bottom,
393
+ metrics.left + metrics.radius,
394
+ metrics.bottom,
395
+ t
396
+ );
397
+ }
398
+ t = consume(metrics.arcLength);
399
+ if (t != null) {
400
+ return pointOnArc(
401
+ metrics.left + metrics.radius,
402
+ metrics.bottom - metrics.radius,
403
+ metrics.radius,
404
+ Math.PI / 2,
405
+ Math.PI,
406
+ t
407
+ );
408
+ }
409
+ t = consume(metrics.verticalLength);
410
+ if (t != null) {
411
+ return pointOnLine(
412
+ metrics.left,
413
+ metrics.bottom - metrics.radius,
414
+ metrics.left,
415
+ metrics.top + metrics.radius,
416
+ t
417
+ );
418
+ }
419
+ t = consume(metrics.arcLength);
420
+ if (t != null) {
421
+ return pointOnArc(
422
+ metrics.left + metrics.radius,
423
+ metrics.top + metrics.radius,
424
+ metrics.radius,
425
+ Math.PI,
426
+ Math.PI * 1.5,
427
+ t
428
+ );
429
+ }
430
+ t = consume(metrics.topHalfLength);
431
+ if (t != null) {
432
+ return pointOnLine(
433
+ metrics.left + metrics.radius,
434
+ metrics.top,
435
+ metrics.centerX,
436
+ metrics.top,
437
+ t
438
+ );
439
+ }
440
+ return [metrics.centerX, metrics.top];
312
441
  }
313
442
  function buildRectSvg(width, height, style = DEFAULT_STROKE_STYLE) {
314
443
  return `<rect width="${width}" height="${height}" fill="none" stroke="${style.stroke}" stroke-width="${style.strokeWidth}" rx="4"${strokeOpacityAttr(style)} />`;
@@ -323,35 +452,34 @@ function buildArchitecturalCloudPathD(width, height, strokeWidth = DEFAULT_STROK
323
452
  const h = Math.max(0, height);
324
453
  if (w <= 0 || h <= 0) return "";
325
454
  const inset = Math.max(0.5, strokeWidth / 2);
326
- const outerRx = Math.max(0, w / 2 - inset);
327
- const outerRy = Math.max(0, h / 2 - inset);
328
- if (outerRx <= 0 || outerRy <= 0) return "";
329
- const baseExponent = 3.6;
455
+ const outerWidth = Math.max(0, w - inset * 2);
456
+ const outerHeight = Math.max(0, h - inset * 2);
457
+ if (outerWidth <= 0 || outerHeight <= 0) return "";
330
458
  const amplitude = Math.min(
331
- outerRx * 0.45,
332
- outerRy * 0.45,
333
- Math.max(2, Math.min(7, Math.min(w, h) * 0.035))
459
+ outerWidth * 0.12,
460
+ outerHeight * 0.12,
461
+ Math.max(5, Math.min(14, Math.min(w, h) * 0.07))
334
462
  );
335
- const innerRx = Math.max(0, outerRx - amplitude);
336
- const innerRy = Math.max(0, outerRy - amplitude);
337
- const scallopCount = architecturalCloudScallopCount(innerRx, innerRy, amplitude);
338
- const angleStep = Math.PI * 2 / scallopCount;
339
- const cx = w / 2;
340
- const cy = h / 2;
341
- const startAngle = -Math.PI / 2;
342
- const pointOnArchitecturalCloud = (theta, radiusX, radiusY) => pointOnSuperellipse(cx, cy, radiusX, radiusY, theta, baseExponent);
343
- const [startX, startY] = pointOnArchitecturalCloud(startAngle, innerRx, innerRy);
463
+ const radius = Math.min(
464
+ outerWidth / 2,
465
+ outerHeight / 2,
466
+ Math.max(amplitude * 2.5, outerHeight * 0.43)
467
+ );
468
+ const outer = roundedRectMetrics(w, h, inset, radius);
469
+ const inner = roundedRectMetrics(
470
+ w,
471
+ h,
472
+ inset + amplitude,
473
+ Math.max(0, radius - amplitude)
474
+ );
475
+ const scallopCount = architecturalCloudScallopCount(outer.perimeter, amplitude);
476
+ const [startX, startY] = pointOnRoundedRectPath(inner, 0);
344
477
  const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
345
478
  for (let index = 0; index < scallopCount; index += 1) {
346
- const segmentStart = startAngle + index * angleStep;
347
- const segmentMid = segmentStart + angleStep / 2;
348
- const segmentEnd = segmentStart + angleStep;
349
- const [controlX, controlY] = pointOnArchitecturalCloud(
350
- segmentMid,
351
- outerRx,
352
- outerRy
353
- );
354
- const [endX, endY] = pointOnArchitecturalCloud(segmentEnd, innerRx, innerRy);
479
+ const controlDistance = (index + 0.5) / scallopCount * outer.perimeter;
480
+ const endDistance = (index + 1) / scallopCount * inner.perimeter;
481
+ const [controlX, controlY] = pointOnRoundedRectPath(outer, controlDistance);
482
+ const [endX, endY] = pointOnRoundedRectPath(inner, endDistance);
355
483
  segments.push(
356
484
  `Q${svgNumber(controlX)} ${svgNumber(controlY)} ${svgNumber(endX)} ${svgNumber(endY)}`
357
485
  );
@@ -3113,7 +3241,7 @@ function ShapeContextMenu({
3113
3241
  }
3114
3242
  return reactDom.createPortal(menu, document.body);
3115
3243
  }
3116
- var architecturalCloudIconPath = "M11 3 Q15.72 1.11 16.44 3.31 Q19.25 2.05 18.39 4.28 Q20.81 4.17 19 7 Q20.81 9.83 18.39 9.72 Q19.25 11.95 16.44 10.69 Q15.72 12.89 11 11 Q6.28 12.89 5.56 10.69 Q2.75 11.95 3.61 9.72 Q1.19 9.83 3 7 Q1.19 4.17 3.61 4.28 Q2.75 2.05 5.56 3.31 Q6.28 1.11 11 3 Z";
3244
+ var architecturalCloudIconPath = "M11 2.44 Q13.3 1 14.84 2.44 Q17.84 1.4 18.41 3.47 Q20.8 4.72 19.56 7 Q20.8 9.28 18.41 10.53 Q17.84 12.6 14.84 11.56 Q13.3 13 11 11.56 Q8.7 13 7.16 11.56 Q4.16 12.6 3.59 10.53 Q1.2 9.28 2.44 7 Q1.2 4.72 3.59 3.47 Q4.16 1.4 7.16 2.44 Q8.7 1 11 2.44 Z";
3117
3245
  var base = {
3118
3246
  width: 20,
3119
3247
  height: 20,