canvu-react 0.4.46 → 0.4.47

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
@@ -3026,6 +3026,35 @@ function resolveNativeStrokePreviewStyle(tool, previewStrokeStyle) {
3026
3026
  };
3027
3027
  }
3028
3028
 
3029
+ // src/native/native-stroke-preview.ts
3030
+ var NATIVE_STROKE_PREVIEW_MAX_POINTS = 160;
3031
+ function sampleNativeStrokePreviewPoints(points, maxPoints = NATIVE_STROKE_PREVIEW_MAX_POINTS) {
3032
+ if (points.length <= maxPoints) return points.map((point) => ({ ...point }));
3033
+ if (maxPoints <= 1) {
3034
+ const last2 = points[points.length - 1];
3035
+ return last2 ? [{ ...last2 }] : [];
3036
+ }
3037
+ const lastIndex = points.length - 1;
3038
+ const last = points[lastIndex];
3039
+ if (!last) return [];
3040
+ const step = lastIndex / (maxPoints - 1);
3041
+ return Array.from({ length: maxPoints }, (_, index) => {
3042
+ const point = points[Math.round(index * step)] ?? last;
3043
+ return { x: point.x, y: point.y };
3044
+ });
3045
+ }
3046
+ function buildNativeStrokePreviewPath(points) {
3047
+ if (points.length < 2) return null;
3048
+ const d = smoothFreehandPointsToPathD(points);
3049
+ return d || null;
3050
+ }
3051
+ function nativeStrokePreviewDashArray(style, tool) {
3052
+ if (style.strokeDash !== "dashed" || tool !== "draw") return void 0;
3053
+ const dash = Math.max(style.strokeWidth * 1.8, 4);
3054
+ const gap = Math.max(style.strokeWidth * 1.4, 3);
3055
+ return `${dash} ${gap}`;
3056
+ }
3057
+
3029
3058
  // src/native/native-vector-interactions.ts
3030
3059
  var NATIVE_SELECTION_HANDLE_HIT_RADIUS_PX = 24;
3031
3060
  function nativeItemPlacementBounds(item) {
@@ -3397,58 +3426,42 @@ function NativeInteractionOverlay({
3397
3426
  p.tool,
3398
3427
  p.style ?? previewStrokeStyle
3399
3428
  );
3400
- const payload = computeFreehandSvgPayload(
3401
- p.points,
3402
- style,
3403
- isLaser ? "draw" : p.tool,
3404
- p.points.length === 2
3429
+ const strokeColor = colorWithOpacity(
3430
+ style.stroke,
3431
+ isLaser ? 0.85 : style.strokeOpacity
3405
3432
  );
3406
- if (!payload) return null;
3407
- if (payload.kind === "circle") {
3433
+ if (p.points.length === 1) {
3434
+ const point = p.points[0];
3435
+ if (!point) return null;
3408
3436
  return /* @__PURE__ */ jsx(
3409
3437
  Circle,
3410
3438
  {
3411
- cx: payload.cx,
3412
- cy: payload.cy,
3413
- r: payload.r,
3414
- color: colorWithOpacity(payload.fill, payload.fillOpacity),
3415
- style: "fill",
3416
- antiAlias: true
3417
- }
3418
- );
3419
- }
3420
- if (payload.kind === "fillPath") {
3421
- return /* @__PURE__ */ jsx(
3422
- Path,
3423
- {
3424
- path: payload.d,
3425
- color: colorWithOpacity(payload.fill, payload.fillOpacity),
3439
+ cx: point.x,
3440
+ cy: point.y,
3441
+ r: Math.max(0.5, style.strokeWidth / 2),
3442
+ color: strokeColor,
3426
3443
  style: "fill",
3427
- fillType: "winding",
3428
3444
  antiAlias: true
3429
3445
  }
3430
3446
  );
3431
3447
  }
3432
- if (payload.kind === "strokePath") {
3433
- const intervals = dashIntervalsFromStrokeDasharray3(payload.strokeDasharray);
3434
- return /* @__PURE__ */ jsx(
3435
- Path,
3436
- {
3437
- path: payload.d,
3438
- color: colorWithOpacity(
3439
- payload.stroke,
3440
- isLaser ? 0.85 : payload.strokeOpacity
3441
- ),
3442
- style: "stroke",
3443
- strokeWidth: payload.strokeWidth,
3444
- strokeCap: "round",
3445
- strokeJoin: "round",
3446
- antiAlias: true,
3447
- children: intervals ? /* @__PURE__ */ jsx(DashPathEffect, { intervals }) : null
3448
- }
3449
- );
3450
- }
3451
- return null;
3448
+ const path = buildNativeStrokePreviewPath(p.points);
3449
+ if (!path) return null;
3450
+ const strokeDasharray = nativeStrokePreviewDashArray(style, p.tool);
3451
+ const intervals = dashIntervalsFromStrokeDasharray3(strokeDasharray);
3452
+ return /* @__PURE__ */ jsx(
3453
+ Path,
3454
+ {
3455
+ path,
3456
+ color: strokeColor,
3457
+ style: "stroke",
3458
+ strokeWidth: style.strokeWidth,
3459
+ strokeCap: "round",
3460
+ strokeJoin: "round",
3461
+ antiAlias: true,
3462
+ children: intervals ? /* @__PURE__ */ jsx(DashPathEffect, { intervals }) : null
3463
+ }
3464
+ );
3452
3465
  }
3453
3466
  return null;
3454
3467
  }, [placementPreview, previewStrokeStyle, overlayStrokeWorld, marqueeDashWorld]);
@@ -5890,7 +5903,7 @@ var NativeVectorViewport = forwardRef(function NativeVectorViewport2({
5890
5903
  setRealtimePlacementPreview({
5891
5904
  kind: "stroke",
5892
5905
  tool: st.tool,
5893
- points: [...pts],
5906
+ points: sampleNativeStrokePreviewPoints(pts),
5894
5907
  style: { ...strokeStyleRef.current }
5895
5908
  });
5896
5909
  return;