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/tldraw.cjs CHANGED
@@ -223,40 +223,29 @@ function resolveStrokeStyle(item) {
223
223
  function strokeOpacityAttr(style) {
224
224
  return style.strokeOpacity != null ? ` stroke-opacity="${style.strokeOpacity}"` : "";
225
225
  }
226
- function clampNumber(value, min, max) {
227
- return Math.min(max, Math.max(min, value));
228
- }
229
226
  function svgNumber(value) {
230
227
  if (!Number.isFinite(value)) return "0";
231
- return Number(value.toFixed(3)).toString();
232
- }
233
- function architecturalCloudScallopCount(length, depth) {
234
- if (length <= 1e-6) return 0;
235
- return Math.max(1, Math.round(length / Math.max(depth * 2.05, 8)));
236
- }
237
- function appendHorizontalScallops(segments, startX, endX, y, controlY, count) {
238
- if (count <= 0) return;
239
- const step = (endX - startX) / count;
240
- for (let index = 1; index <= count; index += 1) {
241
- const x0 = startX + step * (index - 1);
242
- const x1 = index === count ? endX : startX + step * index;
243
- const cx = (x0 + x1) / 2;
244
- segments.push(
245
- `Q${svgNumber(cx)} ${svgNumber(controlY)} ${svgNumber(x1)} ${svgNumber(y)}`
246
- );
247
- }
228
+ const rounded = Math.round(value * 100) / 100;
229
+ return Number.isInteger(rounded) ? String(rounded) : String(rounded);
248
230
  }
249
- function appendVerticalScallops(segments, startY, endY, x, controlX, count) {
250
- if (count <= 0) return;
251
- const step = (endY - startY) / count;
252
- for (let index = 1; index <= count; index += 1) {
253
- const y0 = startY + step * (index - 1);
254
- const y1 = index === count ? endY : startY + step * index;
255
- const cy = (y0 + y1) / 2;
256
- segments.push(
257
- `Q${svgNumber(controlX)} ${svgNumber(cy)} ${svgNumber(x)} ${svgNumber(y1)}`
258
- );
259
- }
231
+ function approximateEllipsePerimeter(rx, ry) {
232
+ if (rx <= 0 || ry <= 0) return 0;
233
+ return Math.PI * (3 * (rx + ry) - Math.sqrt((3 * rx + ry) * (rx + 3 * ry)));
234
+ }
235
+ function architecturalCloudScallopCount(rx, ry, amplitude) {
236
+ const perimeter = approximateEllipsePerimeter(rx, ry);
237
+ const targetScallopLength = Math.max(10, amplitude * 2);
238
+ let count = Math.max(12, Math.round(perimeter / targetScallopLength));
239
+ if (count % 2 === 1) count += 1;
240
+ return count;
241
+ }
242
+ function pointOnSuperellipse(centerX, centerY, radiusX, radiusY, theta, exponent) {
243
+ const cosTheta = Math.cos(theta);
244
+ const sinTheta = Math.sin(theta);
245
+ return [
246
+ centerX + Math.sign(cosTheta) * radiusX * Math.abs(cosTheta) ** (2 / exponent),
247
+ centerY + Math.sign(sinTheta) * radiusY * Math.abs(sinTheta) ** (2 / exponent)
248
+ ];
260
249
  }
261
250
  function buildRectSvg(width, height, style = DEFAULT_STROKE_STYLE) {
262
251
  return `<rect width="${width}" height="${height}" fill="none" stroke="${style.stroke}" stroke-width="${style.strokeWidth}" rx="4"${strokeOpacityAttr(style)} />`;
@@ -270,53 +259,41 @@ function buildArchitecturalCloudPathD(width, height, strokeWidth = DEFAULT_STROK
270
259
  const w = Math.max(0, width);
271
260
  const h = Math.max(0, height);
272
261
  if (w <= 0 || h <= 0) return "";
273
- const inset = Math.min(w / 2, h / 2, Math.max(0.5, strokeWidth / 2));
274
- const x0 = inset;
275
- const y0 = inset;
276
- const x1 = Math.max(x0, w - inset);
277
- const y1 = Math.max(y0, h - inset);
278
- const innerW = Math.max(0, x1 - x0);
279
- const innerH = Math.max(0, y1 - y0);
280
- if (innerW <= 0 || innerH <= 0) return "";
281
- const maxDepth = Math.max(0.5, Math.min(innerW, innerH) * 0.18);
282
- const depth = clampNumber(Math.min(w, h) * 0.08, 2, Math.min(12, maxDepth));
283
- const corner = Math.min(depth * 1.2, innerW / 2, innerH / 2);
284
- const topStart = x0 + corner;
285
- const topEnd = x1 - corner;
286
- const rightStart = y0 + corner;
287
- const rightEnd = y1 - corner;
288
- const bottomStart = x1 - corner;
289
- const bottomEnd = x0 + corner;
290
- const leftStart = y1 - corner;
291
- const leftEnd = y0 + corner;
292
- const topCount = architecturalCloudScallopCount(topEnd - topStart, depth);
293
- const rightCount = architecturalCloudScallopCount(rightEnd - rightStart, depth);
294
- const bottomCount = architecturalCloudScallopCount(bottomStart - bottomEnd, depth);
295
- const leftCount = architecturalCloudScallopCount(leftStart - leftEnd, depth);
296
- const segments = [`M${svgNumber(topStart)} ${svgNumber(y0)}`];
297
- appendHorizontalScallops(segments, topStart, topEnd, y0, y0 + depth, topCount);
298
- segments.push(
299
- `Q${svgNumber(x1)} ${svgNumber(y0)} ${svgNumber(x1)} ${svgNumber(rightStart)}`
300
- );
301
- appendVerticalScallops(segments, rightStart, rightEnd, x1, x1 - depth, rightCount);
302
- segments.push(
303
- `Q${svgNumber(x1)} ${svgNumber(y1)} ${svgNumber(bottomStart)} ${svgNumber(y1)}`
304
- );
305
- appendHorizontalScallops(
306
- segments,
307
- bottomStart,
308
- bottomEnd,
309
- y1,
310
- y1 - depth,
311
- bottomCount
312
- );
313
- segments.push(
314
- `Q${svgNumber(x0)} ${svgNumber(y1)} ${svgNumber(x0)} ${svgNumber(leftStart)}`
315
- );
316
- appendVerticalScallops(segments, leftStart, leftEnd, x0, x0 + depth, leftCount);
317
- segments.push(
318
- `Q${svgNumber(x0)} ${svgNumber(y0)} ${svgNumber(topStart)} ${svgNumber(y0)} Z`
262
+ const inset = Math.max(0.5, strokeWidth / 2);
263
+ const outerRx = Math.max(0, w / 2 - inset);
264
+ const outerRy = Math.max(0, h / 2 - inset);
265
+ if (outerRx <= 0 || outerRy <= 0) return "";
266
+ const baseExponent = 3.6;
267
+ const amplitude = Math.min(
268
+ outerRx * 0.45,
269
+ outerRy * 0.45,
270
+ Math.max(2, Math.min(7, Math.min(w, h) * 0.035))
319
271
  );
272
+ const innerRx = Math.max(0, outerRx - amplitude);
273
+ const innerRy = Math.max(0, outerRy - amplitude);
274
+ const scallopCount = architecturalCloudScallopCount(innerRx, innerRy, amplitude);
275
+ const angleStep = Math.PI * 2 / scallopCount;
276
+ const cx = w / 2;
277
+ const cy = h / 2;
278
+ const startAngle = -Math.PI / 2;
279
+ const pointOnArchitecturalCloud = (theta, radiusX, radiusY) => pointOnSuperellipse(cx, cy, radiusX, radiusY, theta, baseExponent);
280
+ const [startX, startY] = pointOnArchitecturalCloud(startAngle, innerRx, innerRy);
281
+ const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
282
+ for (let index = 0; index < scallopCount; index += 1) {
283
+ const segmentStart = startAngle + index * angleStep;
284
+ const segmentMid = segmentStart + angleStep / 2;
285
+ const segmentEnd = segmentStart + angleStep;
286
+ const [controlX, controlY] = pointOnArchitecturalCloud(
287
+ segmentMid,
288
+ outerRx,
289
+ outerRy
290
+ );
291
+ const [endX, endY] = pointOnArchitecturalCloud(segmentEnd, innerRx, innerRy);
292
+ segments.push(
293
+ `Q${svgNumber(controlX)} ${svgNumber(controlY)} ${svgNumber(endX)} ${svgNumber(endY)}`
294
+ );
295
+ }
296
+ segments.push("Z");
320
297
  return segments.join(" ");
321
298
  }
322
299
  function buildArchitecturalCloudSvg(width, height, style = DEFAULT_STROKE_STYLE) {