canvu-react 0.3.30 → 0.3.31

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,21 @@ 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;
260
241
  }
261
242
  function buildRectSvg(width, height, style = DEFAULT_STROKE_STYLE) {
262
243
  return `<rect width="${width}" height="${height}" fill="none" stroke="${style.stroke}" stroke-width="${style.strokeWidth}" rx="4"${strokeOpacityAttr(style)} />`;
@@ -270,53 +251,39 @@ function buildArchitecturalCloudPathD(width, height, strokeWidth = DEFAULT_STROK
270
251
  const w = Math.max(0, width);
271
252
  const h = Math.max(0, height);
272
253
  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`
254
+ const inset = Math.max(0.5, strokeWidth / 2);
255
+ const outerRx = Math.max(0, w / 2 - inset);
256
+ const outerRy = Math.max(0, h / 2 - inset);
257
+ if (outerRx <= 0 || outerRy <= 0) return "";
258
+ const amplitude = Math.min(
259
+ outerRx * 0.45,
260
+ outerRy * 0.45,
261
+ Math.max(2, Math.min(8, Math.min(w, h) * 0.04))
319
262
  );
263
+ const innerRx = Math.max(0, outerRx - amplitude);
264
+ const innerRy = Math.max(0, outerRy - amplitude);
265
+ const scallopCount = architecturalCloudScallopCount(innerRx, innerRy, amplitude);
266
+ const angleStep = Math.PI * 2 / scallopCount;
267
+ const cx = w / 2;
268
+ const cy = h / 2;
269
+ const startAngle = -Math.PI / 2;
270
+ const pointOnEllipse = (theta, radiusX, radiusY) => [
271
+ cx + Math.cos(theta) * radiusX,
272
+ cy + Math.sin(theta) * radiusY
273
+ ];
274
+ const [startX, startY] = pointOnEllipse(startAngle, innerRx, innerRy);
275
+ const segments = [`M${svgNumber(startX)} ${svgNumber(startY)}`];
276
+ for (let index = 0; index < scallopCount; index += 1) {
277
+ const segmentStart = startAngle + index * angleStep;
278
+ const segmentMid = segmentStart + angleStep / 2;
279
+ const segmentEnd = segmentStart + angleStep;
280
+ const [controlX, controlY] = pointOnEllipse(segmentMid, outerRx, outerRy);
281
+ const [endX, endY] = pointOnEllipse(segmentEnd, innerRx, innerRy);
282
+ segments.push(
283
+ `Q${svgNumber(controlX)} ${svgNumber(controlY)} ${svgNumber(endX)} ${svgNumber(endY)}`
284
+ );
285
+ }
286
+ segments.push("Z");
320
287
  return segments.join(" ");
321
288
  }
322
289
  function buildArchitecturalCloudSvg(width, height, style = DEFAULT_STROKE_STYLE) {