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.js CHANGED
@@ -284,17 +284,154 @@ function svgNumber(value) {
284
284
  const rounded = Math.round(value * 100) / 100;
285
285
  return Number.isInteger(rounded) ? String(rounded) : String(rounded);
286
286
  }
287
- function approximateEllipsePerimeter(rx, ry) {
288
- if (rx <= 0 || ry <= 0) return 0;
289
- return Math.PI * (3 * (rx + ry) - Math.sqrt((3 * rx + ry) * (rx + 3 * ry)));
290
- }
291
- function architecturalCloudScallopCount(rx, ry, amplitude) {
292
- const perimeter = approximateEllipsePerimeter(rx, ry);
293
- const targetScallopLength = Math.max(10, amplitude * 2);
287
+ function architecturalCloudScallopCount(perimeter, amplitude) {
288
+ const targetScallopLength = Math.max(18, amplitude * 2.45);
294
289
  let count = Math.max(12, Math.round(perimeter / targetScallopLength));
295
290
  if (count % 2 === 1) count += 1;
296
291
  return count;
297
292
  }
293
+ function roundedRectMetrics(width, height, inset, radius) {
294
+ const left = inset;
295
+ const top = inset;
296
+ const right = width - inset;
297
+ const bottom = height - inset;
298
+ const rectWidth = Math.max(0, right - left);
299
+ const rectHeight = Math.max(0, bottom - top);
300
+ const normalizedRadius = Math.max(
301
+ 0,
302
+ Math.min(radius, rectWidth / 2, rectHeight / 2)
303
+ );
304
+ const centerX = width / 2;
305
+ const topHalfLength = Math.max(0, right - normalizedRadius - centerX);
306
+ const horizontalLength = Math.max(0, rectWidth - normalizedRadius * 2);
307
+ const verticalLength = Math.max(0, rectHeight - normalizedRadius * 2);
308
+ const arcLength = normalizedRadius * (Math.PI / 2);
309
+ return {
310
+ left,
311
+ top,
312
+ right,
313
+ bottom,
314
+ radius: normalizedRadius,
315
+ centerX,
316
+ topHalfLength,
317
+ horizontalLength,
318
+ verticalLength,
319
+ arcLength,
320
+ perimeter: horizontalLength * 2 + verticalLength * 2 + Math.PI * 2 * normalizedRadius
321
+ };
322
+ }
323
+ function pointOnLine(startX, startY, endX, endY, t) {
324
+ return [startX + (endX - startX) * t, startY + (endY - startY) * t];
325
+ }
326
+ function pointOnArc(centerX, centerY, radius, startAngle, endAngle, t) {
327
+ const theta = startAngle + (endAngle - startAngle) * t;
328
+ return [centerX + Math.cos(theta) * radius, centerY + Math.sin(theta) * radius];
329
+ }
330
+ function pointOnRoundedRectPath(metrics, distance) {
331
+ if (metrics.perimeter <= 0) return [metrics.centerX, metrics.top];
332
+ let remaining = (distance % metrics.perimeter + metrics.perimeter) % metrics.perimeter;
333
+ const consume = (length) => {
334
+ if (length <= 1e-9) return null;
335
+ if (remaining <= length) return remaining / length;
336
+ remaining -= length;
337
+ return null;
338
+ };
339
+ let t = consume(metrics.topHalfLength);
340
+ if (t != null) {
341
+ return pointOnLine(
342
+ metrics.centerX,
343
+ metrics.top,
344
+ metrics.right - metrics.radius,
345
+ metrics.top,
346
+ t
347
+ );
348
+ }
349
+ t = consume(metrics.arcLength);
350
+ if (t != null) {
351
+ return pointOnArc(
352
+ metrics.right - metrics.radius,
353
+ metrics.top + metrics.radius,
354
+ metrics.radius,
355
+ -Math.PI / 2,
356
+ 0,
357
+ t
358
+ );
359
+ }
360
+ t = consume(metrics.verticalLength);
361
+ if (t != null) {
362
+ return pointOnLine(
363
+ metrics.right,
364
+ metrics.top + metrics.radius,
365
+ metrics.right,
366
+ metrics.bottom - metrics.radius,
367
+ t
368
+ );
369
+ }
370
+ t = consume(metrics.arcLength);
371
+ if (t != null) {
372
+ return pointOnArc(
373
+ metrics.right - metrics.radius,
374
+ metrics.bottom - metrics.radius,
375
+ metrics.radius,
376
+ 0,
377
+ Math.PI / 2,
378
+ t
379
+ );
380
+ }
381
+ t = consume(metrics.horizontalLength);
382
+ if (t != null) {
383
+ return pointOnLine(
384
+ metrics.right - metrics.radius,
385
+ metrics.bottom,
386
+ metrics.left + metrics.radius,
387
+ metrics.bottom,
388
+ t
389
+ );
390
+ }
391
+ t = consume(metrics.arcLength);
392
+ if (t != null) {
393
+ return pointOnArc(
394
+ metrics.left + metrics.radius,
395
+ metrics.bottom - metrics.radius,
396
+ metrics.radius,
397
+ Math.PI / 2,
398
+ Math.PI,
399
+ t
400
+ );
401
+ }
402
+ t = consume(metrics.verticalLength);
403
+ if (t != null) {
404
+ return pointOnLine(
405
+ metrics.left,
406
+ metrics.bottom - metrics.radius,
407
+ metrics.left,
408
+ metrics.top + metrics.radius,
409
+ t
410
+ );
411
+ }
412
+ t = consume(metrics.arcLength);
413
+ if (t != null) {
414
+ return pointOnArc(
415
+ metrics.left + metrics.radius,
416
+ metrics.top + metrics.radius,
417
+ metrics.radius,
418
+ Math.PI,
419
+ Math.PI * 1.5,
420
+ t
421
+ );
422
+ }
423
+ t = consume(metrics.topHalfLength);
424
+ if (t != null) {
425
+ return pointOnLine(
426
+ metrics.left + metrics.radius,
427
+ metrics.top,
428
+ metrics.centerX,
429
+ metrics.top,
430
+ t
431
+ );
432
+ }
433
+ return [metrics.centerX, metrics.top];
434
+ }
298
435
  function buildRectSvg(width, height, style = DEFAULT_STROKE_STYLE) {
299
436
  return `<rect width="${width}" height="${height}" fill="none" stroke="${style.stroke}" stroke-width="${style.strokeWidth}" rx="4"${strokeOpacityAttr(style)} />`;
300
437
  }
@@ -308,33 +445,34 @@ function buildArchitecturalCloudPathD(width, height, strokeWidth = DEFAULT_STROK
308
445
  const h = Math.max(0, height);
309
446
  if (w <= 0 || h <= 0) return "";
310
447
  const inset = Math.max(0.5, strokeWidth / 2);
311
- const outerRx = Math.max(0, w / 2 - inset);
312
- const outerRy = Math.max(0, h / 2 - inset);
313
- if (outerRx <= 0 || outerRy <= 0) return "";
448
+ const outerWidth = Math.max(0, w - inset * 2);
449
+ const outerHeight = Math.max(0, h - inset * 2);
450
+ if (outerWidth <= 0 || outerHeight <= 0) return "";
314
451
  const amplitude = Math.min(
315
- outerRx * 0.45,
316
- outerRy * 0.45,
317
- Math.max(2, Math.min(8, Math.min(w, h) * 0.04))
452
+ outerWidth * 0.12,
453
+ outerHeight * 0.12,
454
+ Math.max(5, Math.min(14, Math.min(w, h) * 0.07))
318
455
  );
319
- const innerRx = Math.max(0, outerRx - amplitude);
320
- const innerRy = Math.max(0, outerRy - amplitude);
321
- const scallopCount = architecturalCloudScallopCount(innerRx, innerRy, amplitude);
322
- const angleStep = Math.PI * 2 / scallopCount;
323
- const cx = w / 2;
324
- const cy = h / 2;
325
- const startAngle = -Math.PI / 2;
326
- const pointOnEllipse = (theta, radiusX, radiusY) => [
327
- cx + Math.cos(theta) * radiusX,
328
- cy + Math.sin(theta) * radiusY
329
- ];
330
- const [startX, startY] = pointOnEllipse(startAngle, innerRx, innerRy);
456
+ const radius = Math.min(
457
+ outerWidth / 2,
458
+ outerHeight / 2,
459
+ Math.max(amplitude * 2.5, outerHeight * 0.43)
460
+ );
461
+ const outer = roundedRectMetrics(w, h, inset, radius);
462
+ const inner = roundedRectMetrics(
463
+ w,
464
+ h,
465
+ inset + amplitude,
466
+ Math.max(0, radius - amplitude)
467
+ );
468
+ const scallopCount = architecturalCloudScallopCount(outer.perimeter, amplitude);
469
+ const [startX, startY] = pointOnRoundedRectPath(inner, 0);
331
470
  const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
332
471
  for (let index = 0; index < scallopCount; index += 1) {
333
- const segmentStart = startAngle + index * angleStep;
334
- const segmentMid = segmentStart + angleStep / 2;
335
- const segmentEnd = segmentStart + angleStep;
336
- const [controlX, controlY] = pointOnEllipse(segmentMid, outerRx, outerRy);
337
- const [endX, endY] = pointOnEllipse(segmentEnd, innerRx, innerRy);
472
+ const controlDistance = (index + 0.5) / scallopCount * outer.perimeter;
473
+ const endDistance = (index + 1) / scallopCount * inner.perimeter;
474
+ const [controlX, controlY] = pointOnRoundedRectPath(outer, controlDistance);
475
+ const [endX, endY] = pointOnRoundedRectPath(inner, endDistance);
338
476
  segments.push(
339
477
  `Q${svgNumber(controlX)} ${svgNumber(controlY)} ${svgNumber(endX)} ${svgNumber(endY)}`
340
478
  );
@@ -3096,7 +3234,7 @@ function ShapeContextMenu({
3096
3234
  }
3097
3235
  return createPortal(menu, document.body);
3098
3236
  }
3099
- 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";
3237
+ 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";
3100
3238
  var base = {
3101
3239
  width: 20,
3102
3240
  height: 20,
@@ -3128,7 +3266,7 @@ function IconEllipse(props) {
3128
3266
  return /* @__PURE__ */ jsx("svg", { ...base, ...props, "aria-hidden": true, children: /* @__PURE__ */ jsx("ellipse", { cx: "12", cy: "12", rx: "9", ry: "6" }) });
3129
3267
  }
3130
3268
  function IconArchitecturalCloud(props) {
3131
- return /* @__PURE__ */ jsx("svg", { ...base, ...props, "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: architecturalCloudIconPath, transform: "translate(0 4)" }) });
3269
+ return /* @__PURE__ */ jsx("svg", { ...base, ...props, "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: architecturalCloudIconPath, transform: "translate(1 5)" }) });
3132
3270
  }
3133
3271
  function IconLine(props) {
3134
3272
  return /* @__PURE__ */ jsx("svg", { ...base, ...props, "aria-hidden": true, children: /* @__PURE__ */ jsx("line", { x1: "5", y1: "19", x2: "19", y2: "5" }) });