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/react.cjs CHANGED
@@ -286,40 +286,29 @@ function resolveStrokeStyle(item) {
286
286
  function strokeOpacityAttr(style) {
287
287
  return style.strokeOpacity != null ? ` stroke-opacity="${style.strokeOpacity}"` : "";
288
288
  }
289
- function clampNumber(value, min, max) {
290
- return Math.min(max, Math.max(min, value));
291
- }
292
289
  function svgNumber(value) {
293
290
  if (!Number.isFinite(value)) return "0";
294
- return Number(value.toFixed(3)).toString();
295
- }
296
- function architecturalCloudScallopCount(length, depth) {
297
- if (length <= 1e-6) return 0;
298
- return Math.max(1, Math.round(length / Math.max(depth * 2.05, 8)));
299
- }
300
- function appendHorizontalScallops(segments, startX, endX, y, controlY, count) {
301
- if (count <= 0) return;
302
- const step = (endX - startX) / count;
303
- for (let index = 1; index <= count; index += 1) {
304
- const x0 = startX + step * (index - 1);
305
- const x1 = index === count ? endX : startX + step * index;
306
- const cx = (x0 + x1) / 2;
307
- segments.push(
308
- `Q${svgNumber(cx)} ${svgNumber(controlY)} ${svgNumber(x1)} ${svgNumber(y)}`
309
- );
310
- }
311
- }
312
- function appendVerticalScallops(segments, startY, endY, x, controlX, count) {
313
- if (count <= 0) return;
314
- const step = (endY - startY) / count;
315
- for (let index = 1; index <= count; index += 1) {
316
- const y0 = startY + step * (index - 1);
317
- const y1 = index === count ? endY : startY + step * index;
318
- const cy = (y0 + y1) / 2;
319
- segments.push(
320
- `Q${svgNumber(controlX)} ${svgNumber(cy)} ${svgNumber(x)} ${svgNumber(y1)}`
321
- );
322
- }
291
+ const rounded = Math.round(value * 100) / 100;
292
+ return Number.isInteger(rounded) ? String(rounded) : String(rounded);
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);
301
+ let count = Math.max(12, Math.round(perimeter / targetScallopLength));
302
+ if (count % 2 === 1) count += 1;
303
+ return count;
304
+ }
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
+ ];
323
312
  }
324
313
  function buildRectSvg(width, height, style = DEFAULT_STROKE_STYLE) {
325
314
  return `<rect width="${width}" height="${height}" fill="none" stroke="${style.stroke}" stroke-width="${style.strokeWidth}" rx="4"${strokeOpacityAttr(style)} />`;
@@ -333,53 +322,41 @@ function buildArchitecturalCloudPathD(width, height, strokeWidth = DEFAULT_STROK
333
322
  const w = Math.max(0, width);
334
323
  const h = Math.max(0, height);
335
324
  if (w <= 0 || h <= 0) return "";
336
- const inset = Math.min(w / 2, h / 2, Math.max(0.5, strokeWidth / 2));
337
- const x0 = inset;
338
- const y0 = inset;
339
- const x1 = Math.max(x0, w - inset);
340
- const y1 = Math.max(y0, h - inset);
341
- const innerW = Math.max(0, x1 - x0);
342
- const innerH = Math.max(0, y1 - y0);
343
- if (innerW <= 0 || innerH <= 0) return "";
344
- const maxDepth = Math.max(0.5, Math.min(innerW, innerH) * 0.18);
345
- const depth = clampNumber(Math.min(w, h) * 0.08, 2, Math.min(12, maxDepth));
346
- const corner = Math.min(depth * 1.2, innerW / 2, innerH / 2);
347
- const topStart = x0 + corner;
348
- const topEnd = x1 - corner;
349
- const rightStart = y0 + corner;
350
- const rightEnd = y1 - corner;
351
- const bottomStart = x1 - corner;
352
- const bottomEnd = x0 + corner;
353
- const leftStart = y1 - corner;
354
- const leftEnd = y0 + corner;
355
- const topCount = architecturalCloudScallopCount(topEnd - topStart, depth);
356
- const rightCount = architecturalCloudScallopCount(rightEnd - rightStart, depth);
357
- const bottomCount = architecturalCloudScallopCount(bottomStart - bottomEnd, depth);
358
- const leftCount = architecturalCloudScallopCount(leftStart - leftEnd, depth);
359
- const segments = [`M${svgNumber(topStart)} ${svgNumber(y0)}`];
360
- appendHorizontalScallops(segments, topStart, topEnd, y0, y0 + depth, topCount);
361
- segments.push(
362
- `Q${svgNumber(x1)} ${svgNumber(y0)} ${svgNumber(x1)} ${svgNumber(rightStart)}`
363
- );
364
- appendVerticalScallops(segments, rightStart, rightEnd, x1, x1 - depth, rightCount);
365
- segments.push(
366
- `Q${svgNumber(x1)} ${svgNumber(y1)} ${svgNumber(bottomStart)} ${svgNumber(y1)}`
367
- );
368
- appendHorizontalScallops(
369
- segments,
370
- bottomStart,
371
- bottomEnd,
372
- y1,
373
- y1 - depth,
374
- bottomCount
375
- );
376
- segments.push(
377
- `Q${svgNumber(x0)} ${svgNumber(y1)} ${svgNumber(x0)} ${svgNumber(leftStart)}`
378
- );
379
- appendVerticalScallops(segments, leftStart, leftEnd, x0, x0 + depth, leftCount);
380
- segments.push(
381
- `Q${svgNumber(x0)} ${svgNumber(y0)} ${svgNumber(topStart)} ${svgNumber(y0)} Z`
325
+ 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;
330
+ 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))
382
334
  );
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);
344
+ const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
345
+ 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);
355
+ segments.push(
356
+ `Q${svgNumber(controlX)} ${svgNumber(controlY)} ${svgNumber(endX)} ${svgNumber(endY)}`
357
+ );
358
+ }
359
+ segments.push("Z");
383
360
  return segments.join(" ");
384
361
  }
385
362
  function buildArchitecturalCloudSvg(width, height, style = DEFAULT_STROKE_STYLE) {
@@ -3136,6 +3113,7 @@ function ShapeContextMenu({
3136
3113
  }
3137
3114
  return reactDom.createPortal(menu, document.body);
3138
3115
  }
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";
3139
3117
  var base = {
3140
3118
  width: 20,
3141
3119
  height: 20,
@@ -3167,7 +3145,7 @@ function IconEllipse(props) {
3167
3145
  return /* @__PURE__ */ jsxRuntime.jsx("svg", { ...base, ...props, "aria-hidden": true, children: /* @__PURE__ */ jsxRuntime.jsx("ellipse", { cx: "12", cy: "12", rx: "9", ry: "6" }) });
3168
3146
  }
3169
3147
  function IconArchitecturalCloud(props) {
3170
- return /* @__PURE__ */ jsxRuntime.jsx("svg", { ...base, ...props, "aria-hidden": true, children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M6.5 7.5Q4.4 7.5 4.4 9.4Q3 9.9 3 11.6Q3 13.5 5.2 13.5Q5.8 16 8.3 15.2Q9.2 17.2 11.3 15.7Q12.8 17 14.3 15.5Q16.5 16.4 17 14Q20.7 13.7 20.2 10.9Q21 8.5 18 8.3Q17.2 5.9 14.8 6.7Q13.2 5.2 11.5 6.5Q9.1 5.1 7.8 7.2Q7.2 7.2 6.5 7.5Z" }) });
3148
+ return /* @__PURE__ */ jsxRuntime.jsx("svg", { ...base, ...props, "aria-hidden": true, children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: architecturalCloudIconPath, transform: "translate(1 5)" }) });
3171
3149
  }
3172
3150
  function IconLine(props) {
3173
3151
  return /* @__PURE__ */ jsxRuntime.jsx("svg", { ...base, ...props, "aria-hidden": true, children: /* @__PURE__ */ jsxRuntime.jsx("line", { x1: "5", y1: "19", x2: "19", y2: "5" }) });