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.cjs CHANGED
@@ -2108,6 +2108,14 @@ async function loadSkiaImageFromHref(href) {
2108
2108
  var nativeSkiaImageCache = createNativeImageCache({
2109
2109
  loadImage: loadSkiaImageFromHref
2110
2110
  });
2111
+ function resolveNativeImageLoadingState(href, loadedImage) {
2112
+ if (loadedImage?.image) return loadedImage;
2113
+ return { href, image: null };
2114
+ }
2115
+ function resolveNativeImageRenderValue(href, loadedImage) {
2116
+ if (!href) return null;
2117
+ return loadedImage?.image ?? null;
2118
+ }
2111
2119
  function useCachedSkiaImage(href) {
2112
2120
  const [loadedImage, setLoadedImage] = react.useState(
2113
2121
  () => href ? { href, image: nativeSkiaImageCache.getCached(href) } : null
@@ -2124,7 +2132,9 @@ function useCachedSkiaImage(href) {
2124
2132
  return releaseImage;
2125
2133
  }
2126
2134
  let active = true;
2127
- setLoadedImage({ href, image: null });
2135
+ setLoadedImage(
2136
+ (currentLoadedImage) => resolveNativeImageLoadingState(href, currentLoadedImage)
2137
+ );
2128
2138
  void nativeSkiaImageCache.load(href).then(
2129
2139
  (loadedImage2) => {
2130
2140
  if (active) setLoadedImage({ href, image: loadedImage2 });
@@ -2138,8 +2148,7 @@ function useCachedSkiaImage(href) {
2138
2148
  releaseImage();
2139
2149
  };
2140
2150
  }, [href]);
2141
- if (!href || loadedImage?.href !== href) return null;
2142
- return loadedImage.image;
2151
+ return resolveNativeImageRenderValue(href, loadedImage);
2143
2152
  }
2144
2153
 
2145
2154
  // src/native/skia-transform.ts
@@ -3091,11 +3100,14 @@ function buildNativeStrokePreviewPath(points) {
3091
3100
  const d = smoothFreehandPointsToPathD(points);
3092
3101
  return d || null;
3093
3102
  }
3094
- function nativeStrokePreviewDashArray(style, tool) {
3095
- if (style.strokeDash !== "dashed" || tool !== "draw") return void 0;
3096
- const dash = Math.max(style.strokeWidth * 1.8, 4);
3097
- const gap = Math.max(style.strokeWidth * 1.4, 3);
3098
- return `${dash} ${gap}`;
3103
+ function buildNativeFreehandStrokePreviewPayload(points, style, tool) {
3104
+ if (tool === "laser") return null;
3105
+ return computeFreehandSvgPayload(
3106
+ points.map((point) => ({ x: point.x, y: point.y })),
3107
+ style,
3108
+ tool,
3109
+ true
3110
+ );
3099
3111
  }
3100
3112
 
3101
3113
  // src/native/native-vector-interactions.ts
@@ -3473,6 +3485,57 @@ function NativeInteractionOverlay({
3473
3485
  style.stroke,
3474
3486
  isLaser ? 0.85 : style.strokeOpacity
3475
3487
  );
3488
+ if (!isLaser) {
3489
+ const payload = buildNativeFreehandStrokePreviewPayload(
3490
+ p.points,
3491
+ style,
3492
+ p.tool
3493
+ );
3494
+ if (payload?.kind === "circle") {
3495
+ return /* @__PURE__ */ jsxRuntime.jsx(
3496
+ reactNativeSkia.Circle,
3497
+ {
3498
+ cx: payload.cx,
3499
+ cy: payload.cy,
3500
+ r: payload.r,
3501
+ color: colorWithOpacity(payload.fill, payload.fillOpacity),
3502
+ style: "fill",
3503
+ antiAlias: true
3504
+ }
3505
+ );
3506
+ }
3507
+ if (payload?.kind === "fillPath") {
3508
+ return /* @__PURE__ */ jsxRuntime.jsx(
3509
+ reactNativeSkia.Path,
3510
+ {
3511
+ path: payload.d,
3512
+ color: colorWithOpacity(payload.fill, payload.fillOpacity),
3513
+ style: "fill",
3514
+ fillType: "winding",
3515
+ antiAlias: true
3516
+ }
3517
+ );
3518
+ }
3519
+ if (payload?.kind === "strokePath") {
3520
+ const intervals = dashIntervalsFromStrokeDasharray3(
3521
+ payload.strokeDasharray
3522
+ );
3523
+ return /* @__PURE__ */ jsxRuntime.jsx(
3524
+ reactNativeSkia.Path,
3525
+ {
3526
+ path: payload.d,
3527
+ color: colorWithOpacity(payload.stroke, payload.strokeOpacity),
3528
+ style: "stroke",
3529
+ strokeWidth: payload.strokeWidth,
3530
+ strokeCap: "round",
3531
+ strokeJoin: "round",
3532
+ antiAlias: true,
3533
+ children: intervals ? /* @__PURE__ */ jsxRuntime.jsx(reactNativeSkia.DashPathEffect, { intervals }) : null
3534
+ }
3535
+ );
3536
+ }
3537
+ return null;
3538
+ }
3476
3539
  if (p.points.length === 1) {
3477
3540
  const point = p.points[0];
3478
3541
  if (!point) return null;
@@ -3490,8 +3553,6 @@ function NativeInteractionOverlay({
3490
3553
  }
3491
3554
  const path = buildNativeStrokePreviewPath(p.points);
3492
3555
  if (!path) return null;
3493
- const strokeDasharray = nativeStrokePreviewDashArray(style, p.tool);
3494
- const intervals = dashIntervalsFromStrokeDasharray3(strokeDasharray);
3495
3556
  return /* @__PURE__ */ jsxRuntime.jsx(
3496
3557
  reactNativeSkia.Path,
3497
3558
  {
@@ -3501,8 +3562,7 @@ function NativeInteractionOverlay({
3501
3562
  strokeWidth: style.strokeWidth,
3502
3563
  strokeCap: "round",
3503
3564
  strokeJoin: "round",
3504
- antiAlias: true,
3505
- children: intervals ? /* @__PURE__ */ jsxRuntime.jsx(reactNativeSkia.DashPathEffect, { intervals }) : null
3565
+ antiAlias: true
3506
3566
  }
3507
3567
  );
3508
3568
  }