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