canvu-react 0.4.50 → 0.4.52

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
@@ -3079,22 +3079,6 @@ function resolveNativeStrokePreviewStyle(tool, previewStrokeStyle) {
3079
3079
  }
3080
3080
 
3081
3081
  // src/native/native-stroke-preview.ts
3082
- var NATIVE_STROKE_PREVIEW_MAX_POINTS = 160;
3083
- function sampleNativeStrokePreviewPoints(points, maxPoints = NATIVE_STROKE_PREVIEW_MAX_POINTS) {
3084
- if (points.length <= maxPoints) return points.map((point) => ({ ...point }));
3085
- if (maxPoints <= 1) {
3086
- const last2 = points[points.length - 1];
3087
- return last2 ? [{ ...last2 }] : [];
3088
- }
3089
- const lastIndex = points.length - 1;
3090
- const last = points[lastIndex];
3091
- if (!last) return [];
3092
- const step = lastIndex / (maxPoints - 1);
3093
- return Array.from({ length: maxPoints }, (_, index) => {
3094
- const point = points[Math.round(index * step)] ?? last;
3095
- return { x: point.x, y: point.y };
3096
- });
3097
- }
3098
3082
  function buildNativeStrokePreviewPath(points) {
3099
3083
  if (points.length < 2) return null;
3100
3084
  const d = smoothFreehandPointsToPathD(points);
@@ -3925,11 +3909,12 @@ var MemoShape = react.memo(function MemoShape2({
3925
3909
  if (rotationTransform.length === 0) return shape;
3926
3910
  return /* @__PURE__ */ jsxRuntime.jsx(reactNativeSkia.Group, { transform: rotationTransform, origin: rotationOrigin, children: shape });
3927
3911
  });
3928
- function NativeSceneRenderer({
3912
+ var NativeSceneRenderer = react.memo(function NativeSceneRenderer2({
3929
3913
  items,
3930
3914
  camera,
3931
3915
  width,
3932
- height
3916
+ height,
3917
+ renderTick
3933
3918
  }) {
3934
3919
  const cameraTransform = skiaCameraTransform(camera.zoom, camera.x, camera.y);
3935
3920
  const visible = cullItemsByViewport(
@@ -3938,7 +3923,7 @@ function NativeSceneRenderer({
3938
3923
  );
3939
3924
  if (width <= 0 || height <= 0) return null;
3940
3925
  return /* @__PURE__ */ jsxRuntime.jsx(reactNativeSkia.Canvas, { style: { width, height }, children: /* @__PURE__ */ jsxRuntime.jsx(reactNativeSkia.Group, { transform: cameraTransform, children: visible.map((item) => /* @__PURE__ */ jsxRuntime.jsx(MemoShape, { item }, item.id)) }) });
3941
- }
3926
+ });
3942
3927
 
3943
3928
  // src/native/native-style-inspector-values.ts
3944
3929
  var NATIVE_STYLE_PALETTE = [
@@ -5723,6 +5708,11 @@ var NativeVectorViewport = react.forwardRef(function NativeVectorViewport2({
5723
5708
  return activeItems.filter((item) => !hidden.has(item.id));
5724
5709
  }, [activeItems, eraserPreviewIds]);
5725
5710
  const showResizeHandles = interactive && selectedItems.length === 1 && !selectedItems[0]?.locked && supportsNativeResizeHandles(selectedItems[0]);
5711
+ const eraserPreviewItems = react.useMemo(() => {
5712
+ if (eraserPreviewIds.length === 0) return [];
5713
+ const eraserPreviewIdSet = new Set(eraserPreviewIds);
5714
+ return activeItems.filter((item) => eraserPreviewIdSet.has(item.id));
5715
+ }, [activeItems, eraserPreviewIds]);
5726
5716
  const patchSelectedItemsStrokeStyle = react.useCallback(
5727
5717
  (patch) => {
5728
5718
  const change = onItemsChangeRef.current;
@@ -5994,22 +5984,19 @@ var NativeVectorViewport = react.forwardRef(function NativeVectorViewport2({
5994
5984
  const dx = worldX - (last?.x ?? worldX);
5995
5985
  const dy = worldY - (last?.y ?? worldY);
5996
5986
  const shouldAppendPoint = Math.hypot(dx, dy) > 0.5 / cam.zoom;
5997
- if (shouldAppendPoint) {
5998
- pts.push({ x: worldX, y: worldY });
5999
- }
5987
+ if (!shouldAppendPoint) return;
5988
+ pts.push({ x: worldX, y: worldY });
6000
5989
  if (st.tool === "laser") {
6001
- if (shouldAppendPoint) {
6002
- setLaserTrail((prev) => [
6003
- ...prev,
6004
- { x: worldX, y: worldY, t: Date.now() }
6005
- ]);
6006
- }
5990
+ setLaserTrail((prev) => [
5991
+ ...prev,
5992
+ { x: worldX, y: worldY, t: Date.now() }
5993
+ ]);
6007
5994
  return;
6008
5995
  }
6009
5996
  setRealtimePlacementPreview({
6010
5997
  kind: "stroke",
6011
5998
  tool: st.tool,
6012
- points: sampleNativeStrokePreviewPoints(pts),
5999
+ points: pts.map((previewPoint) => ({ ...previewPoint })),
6013
6000
  style: { ...strokeStyleRef.current }
6014
6001
  });
6015
6002
  return;
@@ -6529,7 +6516,8 @@ var NativeVectorViewport = react.forwardRef(function NativeVectorViewport2({
6529
6516
  items: sceneItems,
6530
6517
  camera,
6531
6518
  width: size.width,
6532
- height: size.height
6519
+ height: size.height,
6520
+ renderTick: cameraTick
6533
6521
  }
6534
6522
  ),
6535
6523
  interactive && /* @__PURE__ */ jsxRuntime.jsx(
@@ -6543,9 +6531,7 @@ var NativeVectorViewport = react.forwardRef(function NativeVectorViewport2({
6543
6531
  placementPreview,
6544
6532
  laserTrail,
6545
6533
  eraserTrail,
6546
- eraserPreviewItems: activeItems.filter(
6547
- (item) => eraserPreviewIds.includes(item.id)
6548
- ),
6534
+ eraserPreviewItems,
6549
6535
  previewStrokeStyle: strokeStyleState,
6550
6536
  remotePresence
6551
6537
  }