canvu-react 0.3.30 → 0.3.32

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/native.js CHANGED
@@ -343,40 +343,29 @@ function resolveStrokeStyle(item) {
343
343
  function strokeOpacityAttr(style) {
344
344
  return style.strokeOpacity != null ? ` stroke-opacity="${style.strokeOpacity}"` : "";
345
345
  }
346
- function clampNumber(value, min, max) {
347
- return Math.min(max, Math.max(min, value));
348
- }
349
346
  function svgNumber(value) {
350
347
  if (!Number.isFinite(value)) return "0";
351
- return Number(value.toFixed(3)).toString();
352
- }
353
- function architecturalCloudScallopCount(length, depth) {
354
- if (length <= 1e-6) return 0;
355
- return Math.max(1, Math.round(length / Math.max(depth * 2.05, 8)));
356
- }
357
- function appendHorizontalScallops(segments, startX, endX, y, controlY, count) {
358
- if (count <= 0) return;
359
- const step = (endX - startX) / count;
360
- for (let index = 1; index <= count; index += 1) {
361
- const x0 = startX + step * (index - 1);
362
- const x1 = index === count ? endX : startX + step * index;
363
- const cx = (x0 + x1) / 2;
364
- segments.push(
365
- `Q${svgNumber(cx)} ${svgNumber(controlY)} ${svgNumber(x1)} ${svgNumber(y)}`
366
- );
367
- }
368
- }
369
- function appendVerticalScallops(segments, startY, endY, x, controlX, count) {
370
- if (count <= 0) return;
371
- const step = (endY - startY) / count;
372
- for (let index = 1; index <= count; index += 1) {
373
- const y0 = startY + step * (index - 1);
374
- const y1 = index === count ? endY : startY + step * index;
375
- const cy = (y0 + y1) / 2;
376
- segments.push(
377
- `Q${svgNumber(controlX)} ${svgNumber(cy)} ${svgNumber(x)} ${svgNumber(y1)}`
378
- );
379
- }
348
+ const rounded = Math.round(value * 100) / 100;
349
+ return Number.isInteger(rounded) ? String(rounded) : String(rounded);
350
+ }
351
+ function approximateEllipsePerimeter(rx, ry) {
352
+ if (rx <= 0 || ry <= 0) return 0;
353
+ return Math.PI * (3 * (rx + ry) - Math.sqrt((3 * rx + ry) * (rx + 3 * ry)));
354
+ }
355
+ function architecturalCloudScallopCount(rx, ry, amplitude) {
356
+ const perimeter = approximateEllipsePerimeter(rx, ry);
357
+ const targetScallopLength = Math.max(10, amplitude * 2);
358
+ let count = Math.max(12, Math.round(perimeter / targetScallopLength));
359
+ if (count % 2 === 1) count += 1;
360
+ return count;
361
+ }
362
+ function pointOnSuperellipse(centerX, centerY, radiusX, radiusY, theta, exponent) {
363
+ const cosTheta = Math.cos(theta);
364
+ const sinTheta = Math.sin(theta);
365
+ return [
366
+ centerX + Math.sign(cosTheta) * radiusX * Math.abs(cosTheta) ** (2 / exponent),
367
+ centerY + Math.sign(sinTheta) * radiusY * Math.abs(sinTheta) ** (2 / exponent)
368
+ ];
380
369
  }
381
370
  function buildRectSvg(width, height, style = DEFAULT_STROKE_STYLE) {
382
371
  return `<rect width="${width}" height="${height}" fill="none" stroke="${style.stroke}" stroke-width="${style.strokeWidth}" rx="4"${strokeOpacityAttr(style)} />`;
@@ -390,53 +379,41 @@ function buildArchitecturalCloudPathD(width, height, strokeWidth = DEFAULT_STROK
390
379
  const w = Math.max(0, width);
391
380
  const h = Math.max(0, height);
392
381
  if (w <= 0 || h <= 0) return "";
393
- const inset = Math.min(w / 2, h / 2, Math.max(0.5, strokeWidth / 2));
394
- const x0 = inset;
395
- const y0 = inset;
396
- const x1 = Math.max(x0, w - inset);
397
- const y1 = Math.max(y0, h - inset);
398
- const innerW = Math.max(0, x1 - x0);
399
- const innerH = Math.max(0, y1 - y0);
400
- if (innerW <= 0 || innerH <= 0) return "";
401
- const maxDepth = Math.max(0.5, Math.min(innerW, innerH) * 0.18);
402
- const depth = clampNumber(Math.min(w, h) * 0.08, 2, Math.min(12, maxDepth));
403
- const corner = Math.min(depth * 1.2, innerW / 2, innerH / 2);
404
- const topStart = x0 + corner;
405
- const topEnd = x1 - corner;
406
- const rightStart = y0 + corner;
407
- const rightEnd = y1 - corner;
408
- const bottomStart = x1 - corner;
409
- const bottomEnd = x0 + corner;
410
- const leftStart = y1 - corner;
411
- const leftEnd = y0 + corner;
412
- const topCount = architecturalCloudScallopCount(topEnd - topStart, depth);
413
- const rightCount = architecturalCloudScallopCount(rightEnd - rightStart, depth);
414
- const bottomCount = architecturalCloudScallopCount(bottomStart - bottomEnd, depth);
415
- const leftCount = architecturalCloudScallopCount(leftStart - leftEnd, depth);
416
- const segments = [`M${svgNumber(topStart)} ${svgNumber(y0)}`];
417
- appendHorizontalScallops(segments, topStart, topEnd, y0, y0 + depth, topCount);
418
- segments.push(
419
- `Q${svgNumber(x1)} ${svgNumber(y0)} ${svgNumber(x1)} ${svgNumber(rightStart)}`
420
- );
421
- appendVerticalScallops(segments, rightStart, rightEnd, x1, x1 - depth, rightCount);
422
- segments.push(
423
- `Q${svgNumber(x1)} ${svgNumber(y1)} ${svgNumber(bottomStart)} ${svgNumber(y1)}`
424
- );
425
- appendHorizontalScallops(
426
- segments,
427
- bottomStart,
428
- bottomEnd,
429
- y1,
430
- y1 - depth,
431
- bottomCount
432
- );
433
- segments.push(
434
- `Q${svgNumber(x0)} ${svgNumber(y1)} ${svgNumber(x0)} ${svgNumber(leftStart)}`
435
- );
436
- appendVerticalScallops(segments, leftStart, leftEnd, x0, x0 + depth, leftCount);
437
- segments.push(
438
- `Q${svgNumber(x0)} ${svgNumber(y0)} ${svgNumber(topStart)} ${svgNumber(y0)} Z`
382
+ const inset = Math.max(0.5, strokeWidth / 2);
383
+ const outerRx = Math.max(0, w / 2 - inset);
384
+ const outerRy = Math.max(0, h / 2 - inset);
385
+ if (outerRx <= 0 || outerRy <= 0) return "";
386
+ const baseExponent = 3.6;
387
+ const amplitude = Math.min(
388
+ outerRx * 0.45,
389
+ outerRy * 0.45,
390
+ Math.max(2, Math.min(7, Math.min(w, h) * 0.035))
439
391
  );
392
+ const innerRx = Math.max(0, outerRx - amplitude);
393
+ const innerRy = Math.max(0, outerRy - amplitude);
394
+ const scallopCount = architecturalCloudScallopCount(innerRx, innerRy, amplitude);
395
+ const angleStep = Math.PI * 2 / scallopCount;
396
+ const cx = w / 2;
397
+ const cy = h / 2;
398
+ const startAngle = -Math.PI / 2;
399
+ const pointOnArchitecturalCloud = (theta, radiusX, radiusY) => pointOnSuperellipse(cx, cy, radiusX, radiusY, theta, baseExponent);
400
+ const [startX, startY] = pointOnArchitecturalCloud(startAngle, innerRx, innerRy);
401
+ const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
402
+ for (let index = 0; index < scallopCount; index += 1) {
403
+ const segmentStart = startAngle + index * angleStep;
404
+ const segmentMid = segmentStart + angleStep / 2;
405
+ const segmentEnd = segmentStart + angleStep;
406
+ const [controlX, controlY] = pointOnArchitecturalCloud(
407
+ segmentMid,
408
+ outerRx,
409
+ outerRy
410
+ );
411
+ const [endX, endY] = pointOnArchitecturalCloud(segmentEnd, innerRx, innerRy);
412
+ segments.push(
413
+ `Q${svgNumber(controlX)} ${svgNumber(controlY)} ${svgNumber(endX)} ${svgNumber(endY)}`
414
+ );
415
+ }
416
+ segments.push("Z");
440
417
  return segments.join(" ");
441
418
  }
442
419
  function buildArchitecturalCloudSvg(width, height, style = DEFAULT_STROKE_STYLE) {