canvu-react 0.4.58 → 0.4.59

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
@@ -3841,6 +3841,47 @@ function cullItemsByViewport(items, visibleWorld) {
3841
3841
  }
3842
3842
  return cullItemsByViewportSpatial(items, visibleWorld, SPATIAL_CELL_SIZE);
3843
3843
  }
3844
+
3845
+ // src/native/native-scene-culling.ts
3846
+ var NATIVE_SCENE_CULL_OVERSCAN_RATIO = 0.5;
3847
+ function expandRect(rect, ratio) {
3848
+ const safeRatio = Number.isFinite(ratio) ? Math.max(0, ratio) : 0;
3849
+ const insetX = rect.width * safeRatio;
3850
+ const insetY = rect.height * safeRatio;
3851
+ return {
3852
+ x: rect.x - insetX,
3853
+ y: rect.y - insetY,
3854
+ width: rect.width + insetX * 2,
3855
+ height: rect.height + insetY * 2
3856
+ };
3857
+ }
3858
+ function rectContainsRect(outer, inner) {
3859
+ return inner.x >= outer.x && inner.y >= outer.y && inner.x + inner.width <= outer.x + outer.width && inner.y + inner.height <= outer.y + outer.height;
3860
+ }
3861
+ function resolveNativeSceneVisibleItems({
3862
+ items,
3863
+ visibleWorld,
3864
+ cache,
3865
+ overscanRatio = NATIVE_SCENE_CULL_OVERSCAN_RATIO
3866
+ }) {
3867
+ if (cache && cache.items === items && rectContainsRect(cache.cullRect, visibleWorld)) {
3868
+ return {
3869
+ cache,
3870
+ visible: cache.visible
3871
+ };
3872
+ }
3873
+ const cullRect = expandRect(visibleWorld, overscanRatio);
3874
+ const visible = cullItemsByViewport(items, cullRect);
3875
+ const nextCache = {
3876
+ items,
3877
+ cullRect,
3878
+ visible
3879
+ };
3880
+ return {
3881
+ cache: nextCache,
3882
+ visible
3883
+ };
3884
+ }
3844
3885
  var MemoShape = react.memo(function MemoShape2({
3845
3886
  item
3846
3887
  }) {
@@ -3861,13 +3902,20 @@ var NativeSceneRenderer = react.memo(function NativeSceneRenderer2({
3861
3902
  height,
3862
3903
  renderTick
3863
3904
  }) {
3905
+ const visibleCacheRef = react.useRef(null);
3864
3906
  const cameraTransform = skiaCameraTransform(camera.zoom, camera.x, camera.y);
3865
- const visible = cullItemsByViewport(
3907
+ const resolvedVisible = resolveNativeSceneVisibleItems({
3866
3908
  items,
3867
- camera.getVisibleWorldRect(width, height)
3909
+ visibleWorld: width > 0 && height > 0 ? camera.getVisibleWorldRect(width, height) : { x: 0, y: 0, width: 0, height: 0 },
3910
+ cache: visibleCacheRef.current
3911
+ });
3912
+ visibleCacheRef.current = resolvedVisible.cache;
3913
+ const shapeElements = react.useMemo(
3914
+ () => resolvedVisible.visible.map((item) => /* @__PURE__ */ jsxRuntime.jsx(MemoShape, { item }, item.id)),
3915
+ [resolvedVisible.visible]
3868
3916
  );
3869
3917
  if (width <= 0 || height <= 0) return null;
3870
- 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)) }) });
3918
+ return /* @__PURE__ */ jsxRuntime.jsx(reactNativeSkia.Canvas, { style: { width, height }, children: /* @__PURE__ */ jsxRuntime.jsx(reactNativeSkia.Group, { transform: cameraTransform, children: shapeElements }) });
3871
3919
  });
3872
3920
 
3873
3921
  // src/native/native-style-inspector-values.ts