canvu-react 0.4.48 → 0.4.50

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
@@ -2102,6 +2102,14 @@ async function loadSkiaImageFromHref(href) {
2102
2102
  var nativeSkiaImageCache = createNativeImageCache({
2103
2103
  loadImage: loadSkiaImageFromHref
2104
2104
  });
2105
+ function resolveNativeImageLoadingState(href, loadedImage) {
2106
+ if (loadedImage?.image) return loadedImage;
2107
+ return { href, image: null };
2108
+ }
2109
+ function resolveNativeImageRenderValue(href, loadedImage) {
2110
+ if (!href) return null;
2111
+ return loadedImage?.image ?? null;
2112
+ }
2105
2113
  function useCachedSkiaImage(href) {
2106
2114
  const [loadedImage, setLoadedImage] = useState(
2107
2115
  () => href ? { href, image: nativeSkiaImageCache.getCached(href) } : null
@@ -2118,7 +2126,9 @@ function useCachedSkiaImage(href) {
2118
2126
  return releaseImage;
2119
2127
  }
2120
2128
  let active = true;
2121
- setLoadedImage({ href, image: null });
2129
+ setLoadedImage(
2130
+ (currentLoadedImage) => resolveNativeImageLoadingState(href, currentLoadedImage)
2131
+ );
2122
2132
  void nativeSkiaImageCache.load(href).then(
2123
2133
  (loadedImage2) => {
2124
2134
  if (active) setLoadedImage({ href, image: loadedImage2 });
@@ -2132,8 +2142,7 @@ function useCachedSkiaImage(href) {
2132
2142
  releaseImage();
2133
2143
  };
2134
2144
  }, [href]);
2135
- if (!href || loadedImage?.href !== href) return null;
2136
- return loadedImage.image;
2145
+ return resolveNativeImageRenderValue(href, loadedImage);
2137
2146
  }
2138
2147
 
2139
2148
  // src/native/skia-transform.ts
@@ -3085,11 +3094,14 @@ function buildNativeStrokePreviewPath(points) {
3085
3094
  const d = smoothFreehandPointsToPathD(points);
3086
3095
  return d || null;
3087
3096
  }
3088
- function nativeStrokePreviewDashArray(style, tool) {
3089
- if (style.strokeDash !== "dashed" || tool !== "draw") return void 0;
3090
- const dash = Math.max(style.strokeWidth * 1.8, 4);
3091
- const gap = Math.max(style.strokeWidth * 1.4, 3);
3092
- return `${dash} ${gap}`;
3097
+ function buildNativeFreehandStrokePreviewPayload(points, style, tool) {
3098
+ if (tool === "laser") return null;
3099
+ return computeFreehandSvgPayload(
3100
+ points.map((point) => ({ x: point.x, y: point.y })),
3101
+ style,
3102
+ tool,
3103
+ true
3104
+ );
3093
3105
  }
3094
3106
 
3095
3107
  // src/native/native-vector-interactions.ts
@@ -3467,6 +3479,57 @@ function NativeInteractionOverlay({
3467
3479
  style.stroke,
3468
3480
  isLaser ? 0.85 : style.strokeOpacity
3469
3481
  );
3482
+ if (!isLaser) {
3483
+ const payload = buildNativeFreehandStrokePreviewPayload(
3484
+ p.points,
3485
+ style,
3486
+ p.tool
3487
+ );
3488
+ if (payload?.kind === "circle") {
3489
+ return /* @__PURE__ */ jsx(
3490
+ Circle,
3491
+ {
3492
+ cx: payload.cx,
3493
+ cy: payload.cy,
3494
+ r: payload.r,
3495
+ color: colorWithOpacity(payload.fill, payload.fillOpacity),
3496
+ style: "fill",
3497
+ antiAlias: true
3498
+ }
3499
+ );
3500
+ }
3501
+ if (payload?.kind === "fillPath") {
3502
+ return /* @__PURE__ */ jsx(
3503
+ Path,
3504
+ {
3505
+ path: payload.d,
3506
+ color: colorWithOpacity(payload.fill, payload.fillOpacity),
3507
+ style: "fill",
3508
+ fillType: "winding",
3509
+ antiAlias: true
3510
+ }
3511
+ );
3512
+ }
3513
+ if (payload?.kind === "strokePath") {
3514
+ const intervals = dashIntervalsFromStrokeDasharray3(
3515
+ payload.strokeDasharray
3516
+ );
3517
+ return /* @__PURE__ */ jsx(
3518
+ Path,
3519
+ {
3520
+ path: payload.d,
3521
+ color: colorWithOpacity(payload.stroke, payload.strokeOpacity),
3522
+ style: "stroke",
3523
+ strokeWidth: payload.strokeWidth,
3524
+ strokeCap: "round",
3525
+ strokeJoin: "round",
3526
+ antiAlias: true,
3527
+ children: intervals ? /* @__PURE__ */ jsx(DashPathEffect, { intervals }) : null
3528
+ }
3529
+ );
3530
+ }
3531
+ return null;
3532
+ }
3470
3533
  if (p.points.length === 1) {
3471
3534
  const point = p.points[0];
3472
3535
  if (!point) return null;
@@ -3484,8 +3547,6 @@ function NativeInteractionOverlay({
3484
3547
  }
3485
3548
  const path = buildNativeStrokePreviewPath(p.points);
3486
3549
  if (!path) return null;
3487
- const strokeDasharray = nativeStrokePreviewDashArray(style, p.tool);
3488
- const intervals = dashIntervalsFromStrokeDasharray3(strokeDasharray);
3489
3550
  return /* @__PURE__ */ jsx(
3490
3551
  Path,
3491
3552
  {
@@ -3495,8 +3556,7 @@ function NativeInteractionOverlay({
3495
3556
  strokeWidth: style.strokeWidth,
3496
3557
  strokeCap: "round",
3497
3558
  strokeJoin: "round",
3498
- antiAlias: true,
3499
- children: intervals ? /* @__PURE__ */ jsx(DashPathEffect, { intervals }) : null
3559
+ antiAlias: true
3500
3560
  }
3501
3561
  );
3502
3562
  }