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/react.cjs CHANGED
@@ -291,17 +291,154 @@ 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
  }
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];
441
+ }
305
442
  function buildRectSvg(width, height, style = DEFAULT_STROKE_STYLE) {
306
443
  return `<rect width="${width}" height="${height}" fill="none" stroke="${style.stroke}" stroke-width="${style.strokeWidth}" rx="4"${strokeOpacityAttr(style)} />`;
307
444
  }
@@ -315,33 +452,34 @@ function buildArchitecturalCloudPathD(width, height, strokeWidth = DEFAULT_STROK
315
452
  const h = Math.max(0, height);
316
453
  if (w <= 0 || h <= 0) return "";
317
454
  const inset = Math.max(0.5, strokeWidth / 2);
318
- const outerRx = Math.max(0, w / 2 - inset);
319
- const outerRy = Math.max(0, h / 2 - inset);
320
- if (outerRx <= 0 || outerRy <= 0) return "";
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 "";
321
458
  const amplitude = Math.min(
322
- outerRx * 0.45,
323
- outerRy * 0.45,
324
- Math.max(2, Math.min(8, Math.min(w, h) * 0.04))
459
+ outerWidth * 0.12,
460
+ outerHeight * 0.12,
461
+ Math.max(5, Math.min(14, Math.min(w, h) * 0.07))
325
462
  );
326
- const innerRx = Math.max(0, outerRx - amplitude);
327
- const innerRy = Math.max(0, outerRy - amplitude);
328
- const scallopCount = architecturalCloudScallopCount(innerRx, innerRy, amplitude);
329
- const angleStep = Math.PI * 2 / scallopCount;
330
- const cx = w / 2;
331
- const cy = h / 2;
332
- const startAngle = -Math.PI / 2;
333
- const pointOnEllipse = (theta, radiusX, radiusY) => [
334
- cx + Math.cos(theta) * radiusX,
335
- cy + Math.sin(theta) * radiusY
336
- ];
337
- const [startX, startY] = pointOnEllipse(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);
338
477
  const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
339
478
  for (let index = 0; index < scallopCount; index += 1) {
340
- const segmentStart = startAngle + index * angleStep;
341
- const segmentMid = segmentStart + angleStep / 2;
342
- const segmentEnd = segmentStart + angleStep;
343
- const [controlX, controlY] = pointOnEllipse(segmentMid, outerRx, outerRy);
344
- const [endX, endY] = pointOnEllipse(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);
345
483
  segments.push(
346
484
  `Q${svgNumber(controlX)} ${svgNumber(controlY)} ${svgNumber(endX)} ${svgNumber(endY)}`
347
485
  );
@@ -3103,7 +3241,7 @@ function ShapeContextMenu({
3103
3241
  }
3104
3242
  return reactDom.createPortal(menu, document.body);
3105
3243
  }
3106
- var architecturalCloudIconPath = "M12 8.28 Q14.33 7.17 15.86 8.78 Q18.36 8.46 18.69 10.14 Q20.69 10.71 19.72 12 Q20.69 13.29 18.69 13.86 Q18.36 15.54 15.86 15.22 Q14.33 16.83 12 15.72 Q9.67 16.83 8.14 15.22 Q5.64 15.54 5.31 13.86 Q3.31 13.29 4.28 12 Q3.31 10.71 5.31 10.14 Q5.64 8.46 8.14 8.78 Q9.67 7.17 12 8.28 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";
3107
3245
  var base = {
3108
3246
  width: 20,
3109
3247
  height: 20,
@@ -3135,7 +3273,7 @@ function IconEllipse(props) {
3135
3273
  return /* @__PURE__ */ jsxRuntime.jsx("svg", { ...base, ...props, "aria-hidden": true, children: /* @__PURE__ */ jsxRuntime.jsx("ellipse", { cx: "12", cy: "12", rx: "9", ry: "6" }) });
3136
3274
  }
3137
3275
  function IconArchitecturalCloud(props) {
3138
- return /* @__PURE__ */ jsxRuntime.jsx("svg", { ...base, ...props, "aria-hidden": true, children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: architecturalCloudIconPath, transform: "translate(0 4)" }) });
3276
+ return /* @__PURE__ */ jsxRuntime.jsx("svg", { ...base, ...props, "aria-hidden": true, children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: architecturalCloudIconPath, transform: "translate(1 5)" }) });
3139
3277
  }
3140
3278
  function IconLine(props) {
3141
3279
  return /* @__PURE__ */ jsxRuntime.jsx("svg", { ...base, ...props, "aria-hidden": true, children: /* @__PURE__ */ jsxRuntime.jsx("line", { x1: "5", y1: "19", x2: "19", y2: "5" }) });