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/index.js CHANGED
@@ -1038,40 +1038,29 @@ function resolveStrokeStyle(item) {
1038
1038
  function strokeOpacityAttr(style) {
1039
1039
  return style.strokeOpacity != null ? ` stroke-opacity="${style.strokeOpacity}"` : "";
1040
1040
  }
1041
- function clampNumber(value, min, max) {
1042
- return Math.min(max, Math.max(min, value));
1043
- }
1044
1041
  function svgNumber(value) {
1045
1042
  if (!Number.isFinite(value)) return "0";
1046
- return Number(value.toFixed(3)).toString();
1047
- }
1048
- function architecturalCloudScallopCount(length, depth) {
1049
- if (length <= 1e-6) return 0;
1050
- return Math.max(1, Math.round(length / Math.max(depth * 2.05, 8)));
1051
- }
1052
- function appendHorizontalScallops(segments, startX, endX, y, controlY, count) {
1053
- if (count <= 0) return;
1054
- const step = (endX - startX) / count;
1055
- for (let index = 1; index <= count; index += 1) {
1056
- const x0 = startX + step * (index - 1);
1057
- const x1 = index === count ? endX : startX + step * index;
1058
- const cx = (x0 + x1) / 2;
1059
- segments.push(
1060
- `Q${svgNumber(cx)} ${svgNumber(controlY)} ${svgNumber(x1)} ${svgNumber(y)}`
1061
- );
1062
- }
1063
- }
1064
- function appendVerticalScallops(segments, startY, endY, x, controlX, count) {
1065
- if (count <= 0) return;
1066
- const step = (endY - startY) / count;
1067
- for (let index = 1; index <= count; index += 1) {
1068
- const y0 = startY + step * (index - 1);
1069
- const y1 = index === count ? endY : startY + step * index;
1070
- const cy = (y0 + y1) / 2;
1071
- segments.push(
1072
- `Q${svgNumber(controlX)} ${svgNumber(cy)} ${svgNumber(x)} ${svgNumber(y1)}`
1073
- );
1074
- }
1043
+ const rounded = Math.round(value * 100) / 100;
1044
+ return Number.isInteger(rounded) ? String(rounded) : String(rounded);
1045
+ }
1046
+ function approximateEllipsePerimeter(rx, ry) {
1047
+ if (rx <= 0 || ry <= 0) return 0;
1048
+ return Math.PI * (3 * (rx + ry) - Math.sqrt((3 * rx + ry) * (rx + 3 * ry)));
1049
+ }
1050
+ function architecturalCloudScallopCount(rx, ry, amplitude) {
1051
+ const perimeter = approximateEllipsePerimeter(rx, ry);
1052
+ const targetScallopLength = Math.max(10, amplitude * 2);
1053
+ let count = Math.max(12, Math.round(perimeter / targetScallopLength));
1054
+ if (count % 2 === 1) count += 1;
1055
+ return count;
1056
+ }
1057
+ function pointOnSuperellipse(centerX, centerY, radiusX, radiusY, theta, exponent) {
1058
+ const cosTheta = Math.cos(theta);
1059
+ const sinTheta = Math.sin(theta);
1060
+ return [
1061
+ centerX + Math.sign(cosTheta) * radiusX * Math.abs(cosTheta) ** (2 / exponent),
1062
+ centerY + Math.sign(sinTheta) * radiusY * Math.abs(sinTheta) ** (2 / exponent)
1063
+ ];
1075
1064
  }
1076
1065
  function buildRectSvg(width, height, style = DEFAULT_STROKE_STYLE) {
1077
1066
  return `<rect width="${width}" height="${height}" fill="none" stroke="${style.stroke}" stroke-width="${style.strokeWidth}" rx="4"${strokeOpacityAttr(style)} />`;
@@ -1085,53 +1074,41 @@ function buildArchitecturalCloudPathD(width, height, strokeWidth = DEFAULT_STROK
1085
1074
  const w = Math.max(0, width);
1086
1075
  const h = Math.max(0, height);
1087
1076
  if (w <= 0 || h <= 0) return "";
1088
- const inset = Math.min(w / 2, h / 2, Math.max(0.5, strokeWidth / 2));
1089
- const x0 = inset;
1090
- const y0 = inset;
1091
- const x1 = Math.max(x0, w - inset);
1092
- const y1 = Math.max(y0, h - inset);
1093
- const innerW = Math.max(0, x1 - x0);
1094
- const innerH = Math.max(0, y1 - y0);
1095
- if (innerW <= 0 || innerH <= 0) return "";
1096
- const maxDepth = Math.max(0.5, Math.min(innerW, innerH) * 0.18);
1097
- const depth = clampNumber(Math.min(w, h) * 0.08, 2, Math.min(12, maxDepth));
1098
- const corner = Math.min(depth * 1.2, innerW / 2, innerH / 2);
1099
- const topStart = x0 + corner;
1100
- const topEnd = x1 - corner;
1101
- const rightStart = y0 + corner;
1102
- const rightEnd = y1 - corner;
1103
- const bottomStart = x1 - corner;
1104
- const bottomEnd = x0 + corner;
1105
- const leftStart = y1 - corner;
1106
- const leftEnd = y0 + corner;
1107
- const topCount = architecturalCloudScallopCount(topEnd - topStart, depth);
1108
- const rightCount = architecturalCloudScallopCount(rightEnd - rightStart, depth);
1109
- const bottomCount = architecturalCloudScallopCount(bottomStart - bottomEnd, depth);
1110
- const leftCount = architecturalCloudScallopCount(leftStart - leftEnd, depth);
1111
- const segments = [`M${svgNumber(topStart)} ${svgNumber(y0)}`];
1112
- appendHorizontalScallops(segments, topStart, topEnd, y0, y0 + depth, topCount);
1113
- segments.push(
1114
- `Q${svgNumber(x1)} ${svgNumber(y0)} ${svgNumber(x1)} ${svgNumber(rightStart)}`
1115
- );
1116
- appendVerticalScallops(segments, rightStart, rightEnd, x1, x1 - depth, rightCount);
1117
- segments.push(
1118
- `Q${svgNumber(x1)} ${svgNumber(y1)} ${svgNumber(bottomStart)} ${svgNumber(y1)}`
1119
- );
1120
- appendHorizontalScallops(
1121
- segments,
1122
- bottomStart,
1123
- bottomEnd,
1124
- y1,
1125
- y1 - depth,
1126
- bottomCount
1127
- );
1128
- segments.push(
1129
- `Q${svgNumber(x0)} ${svgNumber(y1)} ${svgNumber(x0)} ${svgNumber(leftStart)}`
1130
- );
1131
- appendVerticalScallops(segments, leftStart, leftEnd, x0, x0 + depth, leftCount);
1132
- segments.push(
1133
- `Q${svgNumber(x0)} ${svgNumber(y0)} ${svgNumber(topStart)} ${svgNumber(y0)} Z`
1077
+ const inset = Math.max(0.5, strokeWidth / 2);
1078
+ const outerRx = Math.max(0, w / 2 - inset);
1079
+ const outerRy = Math.max(0, h / 2 - inset);
1080
+ if (outerRx <= 0 || outerRy <= 0) return "";
1081
+ const baseExponent = 3.6;
1082
+ const amplitude = Math.min(
1083
+ outerRx * 0.45,
1084
+ outerRy * 0.45,
1085
+ Math.max(2, Math.min(7, Math.min(w, h) * 0.035))
1134
1086
  );
1087
+ const innerRx = Math.max(0, outerRx - amplitude);
1088
+ const innerRy = Math.max(0, outerRy - amplitude);
1089
+ const scallopCount = architecturalCloudScallopCount(innerRx, innerRy, amplitude);
1090
+ const angleStep = Math.PI * 2 / scallopCount;
1091
+ const cx = w / 2;
1092
+ const cy = h / 2;
1093
+ const startAngle = -Math.PI / 2;
1094
+ const pointOnArchitecturalCloud = (theta, radiusX, radiusY) => pointOnSuperellipse(cx, cy, radiusX, radiusY, theta, baseExponent);
1095
+ const [startX, startY] = pointOnArchitecturalCloud(startAngle, innerRx, innerRy);
1096
+ const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
1097
+ for (let index = 0; index < scallopCount; index += 1) {
1098
+ const segmentStart = startAngle + index * angleStep;
1099
+ const segmentMid = segmentStart + angleStep / 2;
1100
+ const segmentEnd = segmentStart + angleStep;
1101
+ const [controlX, controlY] = pointOnArchitecturalCloud(
1102
+ segmentMid,
1103
+ outerRx,
1104
+ outerRy
1105
+ );
1106
+ const [endX, endY] = pointOnArchitecturalCloud(segmentEnd, innerRx, innerRy);
1107
+ segments.push(
1108
+ `Q${svgNumber(controlX)} ${svgNumber(controlY)} ${svgNumber(endX)} ${svgNumber(endY)}`
1109
+ );
1110
+ }
1111
+ segments.push("Z");
1135
1112
  return segments.join(" ");
1136
1113
  }
1137
1114
  function buildArchitecturalCloudSvg(width, height, style = DEFAULT_STROKE_STYLE) {