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.d.cts CHANGED
@@ -113,8 +113,9 @@ type NativeSceneRendererProps = {
113
113
  readonly camera: Camera2D;
114
114
  readonly width: number;
115
115
  readonly height: number;
116
+ readonly renderTick: number;
116
117
  };
117
- declare function NativeSceneRenderer({ items, camera, width, height, }: NativeSceneRendererProps): react_jsx_runtime.JSX.Element | null;
118
+ declare const NativeSceneRenderer: react.NamedExoticComponent<NativeSceneRendererProps>;
118
119
 
119
120
  type NativeShapeRendererProps = {
120
121
  readonly item: VectorSceneItem;
package/dist/native.d.ts CHANGED
@@ -113,8 +113,9 @@ type NativeSceneRendererProps = {
113
113
  readonly camera: Camera2D;
114
114
  readonly width: number;
115
115
  readonly height: number;
116
+ readonly renderTick: number;
116
117
  };
117
- declare function NativeSceneRenderer({ items, camera, width, height, }: NativeSceneRendererProps): react_jsx_runtime.JSX.Element | null;
118
+ declare const NativeSceneRenderer: react.NamedExoticComponent<NativeSceneRendererProps>;
118
119
 
119
120
  type NativeShapeRendererProps = {
120
121
  readonly item: VectorSceneItem;
package/dist/native.js CHANGED
@@ -3073,22 +3073,6 @@ function resolveNativeStrokePreviewStyle(tool, previewStrokeStyle) {
3073
3073
  }
3074
3074
 
3075
3075
  // src/native/native-stroke-preview.ts
3076
- var NATIVE_STROKE_PREVIEW_MAX_POINTS = 160;
3077
- function sampleNativeStrokePreviewPoints(points, maxPoints = NATIVE_STROKE_PREVIEW_MAX_POINTS) {
3078
- if (points.length <= maxPoints) return points.map((point) => ({ ...point }));
3079
- if (maxPoints <= 1) {
3080
- const last2 = points[points.length - 1];
3081
- return last2 ? [{ ...last2 }] : [];
3082
- }
3083
- const lastIndex = points.length - 1;
3084
- const last = points[lastIndex];
3085
- if (!last) return [];
3086
- const step = lastIndex / (maxPoints - 1);
3087
- return Array.from({ length: maxPoints }, (_, index) => {
3088
- const point = points[Math.round(index * step)] ?? last;
3089
- return { x: point.x, y: point.y };
3090
- });
3091
- }
3092
3076
  function buildNativeStrokePreviewPath(points) {
3093
3077
  if (points.length < 2) return null;
3094
3078
  const d = smoothFreehandPointsToPathD(points);
@@ -3919,11 +3903,12 @@ var MemoShape = memo(function MemoShape2({
3919
3903
  if (rotationTransform.length === 0) return shape;
3920
3904
  return /* @__PURE__ */ jsx(Group, { transform: rotationTransform, origin: rotationOrigin, children: shape });
3921
3905
  });
3922
- function NativeSceneRenderer({
3906
+ var NativeSceneRenderer = memo(function NativeSceneRenderer2({
3923
3907
  items,
3924
3908
  camera,
3925
3909
  width,
3926
- height
3910
+ height,
3911
+ renderTick
3927
3912
  }) {
3928
3913
  const cameraTransform = skiaCameraTransform(camera.zoom, camera.x, camera.y);
3929
3914
  const visible = cullItemsByViewport(
@@ -3932,7 +3917,7 @@ function NativeSceneRenderer({
3932
3917
  );
3933
3918
  if (width <= 0 || height <= 0) return null;
3934
3919
  return /* @__PURE__ */ jsx(Canvas, { style: { width, height }, children: /* @__PURE__ */ jsx(Group, { transform: cameraTransform, children: visible.map((item) => /* @__PURE__ */ jsx(MemoShape, { item }, item.id)) }) });
3935
- }
3920
+ });
3936
3921
 
3937
3922
  // src/native/native-style-inspector-values.ts
3938
3923
  var NATIVE_STYLE_PALETTE = [
@@ -5717,6 +5702,11 @@ var NativeVectorViewport = forwardRef(function NativeVectorViewport2({
5717
5702
  return activeItems.filter((item) => !hidden.has(item.id));
5718
5703
  }, [activeItems, eraserPreviewIds]);
5719
5704
  const showResizeHandles = interactive && selectedItems.length === 1 && !selectedItems[0]?.locked && supportsNativeResizeHandles(selectedItems[0]);
5705
+ const eraserPreviewItems = useMemo(() => {
5706
+ if (eraserPreviewIds.length === 0) return [];
5707
+ const eraserPreviewIdSet = new Set(eraserPreviewIds);
5708
+ return activeItems.filter((item) => eraserPreviewIdSet.has(item.id));
5709
+ }, [activeItems, eraserPreviewIds]);
5720
5710
  const patchSelectedItemsStrokeStyle = useCallback(
5721
5711
  (patch) => {
5722
5712
  const change = onItemsChangeRef.current;
@@ -5988,22 +5978,19 @@ var NativeVectorViewport = forwardRef(function NativeVectorViewport2({
5988
5978
  const dx = worldX - (last?.x ?? worldX);
5989
5979
  const dy = worldY - (last?.y ?? worldY);
5990
5980
  const shouldAppendPoint = Math.hypot(dx, dy) > 0.5 / cam.zoom;
5991
- if (shouldAppendPoint) {
5992
- pts.push({ x: worldX, y: worldY });
5993
- }
5981
+ if (!shouldAppendPoint) return;
5982
+ pts.push({ x: worldX, y: worldY });
5994
5983
  if (st.tool === "laser") {
5995
- if (shouldAppendPoint) {
5996
- setLaserTrail((prev) => [
5997
- ...prev,
5998
- { x: worldX, y: worldY, t: Date.now() }
5999
- ]);
6000
- }
5984
+ setLaserTrail((prev) => [
5985
+ ...prev,
5986
+ { x: worldX, y: worldY, t: Date.now() }
5987
+ ]);
6001
5988
  return;
6002
5989
  }
6003
5990
  setRealtimePlacementPreview({
6004
5991
  kind: "stroke",
6005
5992
  tool: st.tool,
6006
- points: sampleNativeStrokePreviewPoints(pts),
5993
+ points: pts.map((previewPoint) => ({ ...previewPoint })),
6007
5994
  style: { ...strokeStyleRef.current }
6008
5995
  });
6009
5996
  return;
@@ -6523,7 +6510,8 @@ var NativeVectorViewport = forwardRef(function NativeVectorViewport2({
6523
6510
  items: sceneItems,
6524
6511
  camera,
6525
6512
  width: size.width,
6526
- height: size.height
6513
+ height: size.height,
6514
+ renderTick: cameraTick
6527
6515
  }
6528
6516
  ),
6529
6517
  interactive && /* @__PURE__ */ jsx(
@@ -6537,9 +6525,7 @@ var NativeVectorViewport = forwardRef(function NativeVectorViewport2({
6537
6525
  placementPreview,
6538
6526
  laserTrail,
6539
6527
  eraserTrail,
6540
- eraserPreviewItems: activeItems.filter(
6541
- (item) => eraserPreviewIds.includes(item.id)
6542
- ),
6528
+ eraserPreviewItems,
6543
6529
  previewStrokeStyle: strokeStyleState,
6544
6530
  remotePresence
6545
6531
  }