canvu-react 0.4.58 → 0.4.60

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
@@ -1,6 +1,6 @@
1
1
  import getStroke from 'perfect-freehand';
2
2
  import { Group, Canvas, Rect, Circle, Path, RoundedRect, Oval, DashPathEffect, Line, vec, matchFont, Text as Text$1, Image } from '@shopify/react-native-skia';
3
- import { memo, forwardRef, useState, useImperativeHandle, useRef, useEffect, useCallback, useMemo } from 'react';
3
+ import { memo, useRef, useMemo, forwardRef, useState, useImperativeHandle, useEffect, useCallback } from 'react';
4
4
  import { StyleSheet, PanResponder, View, Modal, Text, TextInput, Pressable, ScrollView, Image as Image$1 } from 'react-native';
5
5
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
6
6
 
@@ -3835,6 +3835,47 @@ function cullItemsByViewport(items, visibleWorld) {
3835
3835
  }
3836
3836
  return cullItemsByViewportSpatial(items, visibleWorld, SPATIAL_CELL_SIZE);
3837
3837
  }
3838
+
3839
+ // src/native/native-scene-culling.ts
3840
+ var NATIVE_SCENE_CULL_OVERSCAN_RATIO = 0.5;
3841
+ function expandRect(rect, ratio) {
3842
+ const safeRatio = Number.isFinite(ratio) ? Math.max(0, ratio) : 0;
3843
+ const insetX = rect.width * safeRatio;
3844
+ const insetY = rect.height * safeRatio;
3845
+ return {
3846
+ x: rect.x - insetX,
3847
+ y: rect.y - insetY,
3848
+ width: rect.width + insetX * 2,
3849
+ height: rect.height + insetY * 2
3850
+ };
3851
+ }
3852
+ function rectContainsRect(outer, inner) {
3853
+ 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;
3854
+ }
3855
+ function resolveNativeSceneVisibleItems({
3856
+ items,
3857
+ visibleWorld,
3858
+ cache,
3859
+ overscanRatio = NATIVE_SCENE_CULL_OVERSCAN_RATIO
3860
+ }) {
3861
+ if (cache && cache.items === items && rectContainsRect(cache.cullRect, visibleWorld)) {
3862
+ return {
3863
+ cache,
3864
+ visible: cache.visible
3865
+ };
3866
+ }
3867
+ const cullRect = expandRect(visibleWorld, overscanRatio);
3868
+ const visible = cullItemsByViewport(items, cullRect);
3869
+ const nextCache = {
3870
+ items,
3871
+ cullRect,
3872
+ visible
3873
+ };
3874
+ return {
3875
+ cache: nextCache,
3876
+ visible
3877
+ };
3878
+ }
3838
3879
  var MemoShape = memo(function MemoShape2({
3839
3880
  item
3840
3881
  }) {
@@ -3855,13 +3896,20 @@ var NativeSceneRenderer = memo(function NativeSceneRenderer2({
3855
3896
  height,
3856
3897
  renderTick
3857
3898
  }) {
3899
+ const visibleCacheRef = useRef(null);
3858
3900
  const cameraTransform = skiaCameraTransform(camera.zoom, camera.x, camera.y);
3859
- const visible = cullItemsByViewport(
3901
+ const resolvedVisible = resolveNativeSceneVisibleItems({
3860
3902
  items,
3861
- camera.getVisibleWorldRect(width, height)
3903
+ visibleWorld: width > 0 && height > 0 ? camera.getVisibleWorldRect(width, height) : { x: 0, y: 0, width: 0, height: 0 },
3904
+ cache: visibleCacheRef.current
3905
+ });
3906
+ visibleCacheRef.current = resolvedVisible.cache;
3907
+ const shapeElements = useMemo(
3908
+ () => resolvedVisible.visible.map((item) => /* @__PURE__ */ jsx(MemoShape, { item }, item.id)),
3909
+ [resolvedVisible.visible]
3862
3910
  );
3863
3911
  if (width <= 0 || height <= 0) return null;
3864
- return /* @__PURE__ */ jsx(Canvas, { style: { width, height }, children: /* @__PURE__ */ jsx(Group, { transform: cameraTransform, children: visible.map((item) => /* @__PURE__ */ jsx(MemoShape, { item }, item.id)) }) });
3912
+ return /* @__PURE__ */ jsx(Canvas, { style: { width, height }, children: /* @__PURE__ */ jsx(Group, { transform: cameraTransform, children: shapeElements }) });
3865
3913
  });
3866
3914
 
3867
3915
  // src/native/native-style-inspector-values.ts