canvu-react 0.4.16 → 0.4.17

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
@@ -3606,6 +3606,10 @@ function nativeCursorForVectorToolId(toolId) {
3606
3606
  return null;
3607
3607
  }
3608
3608
  }
3609
+ function nativeFallbackToolCursorPoint(size) {
3610
+ if (size.width <= 0 || size.height <= 0) return null;
3611
+ return { x: size.width / 2, y: size.height / 2 };
3612
+ }
3609
3613
  var MIN_PLACE_SIZE = 8;
3610
3614
  var MIN_ARROW_DRAG_PX = 8;
3611
3615
  var TAP_PX = 20;
@@ -3821,10 +3825,25 @@ var NativeVectorViewport = forwardRef(function NativeVectorViewport2({
3821
3825
  setCameraTick((n) => n + 1);
3822
3826
  onCameraChangeRef.current?.();
3823
3827
  }, []);
3824
- const onLayout = useCallback((e) => {
3825
- const { width, height } = e.nativeEvent.layout;
3826
- setSize({ width, height });
3827
- }, []);
3828
+ const onLayout = useCallback(
3829
+ (e) => {
3830
+ const { width, height } = e.nativeEvent.layout;
3831
+ const nextSize = { width, height };
3832
+ setSize(nextSize);
3833
+ if (!interactive) {
3834
+ setToolCursorPoint(null);
3835
+ return;
3836
+ }
3837
+ if (!nativeCursorForVectorToolId(toolIdRef.current)) {
3838
+ setToolCursorPoint(null);
3839
+ return;
3840
+ }
3841
+ setToolCursorPoint(
3842
+ (current) => current ?? nativeFallbackToolCursorPoint(nextSize)
3843
+ );
3844
+ },
3845
+ [interactive]
3846
+ );
3828
3847
  const updateToolCursorPoint = useCallback(
3829
3848
  (point) => {
3830
3849
  if (!interactive) return;
@@ -3836,6 +3855,25 @@ var NativeVectorViewport = forwardRef(function NativeVectorViewport2({
3836
3855
  const hideToolCursor = useCallback(() => {
3837
3856
  setToolCursorPoint(null);
3838
3857
  }, []);
3858
+ const showFallbackToolCursor = useCallback(
3859
+ (nextToolId) => {
3860
+ if (!interactive) {
3861
+ setToolCursorPoint(null);
3862
+ return;
3863
+ }
3864
+ if (!nativeCursorForVectorToolId(nextToolId)) {
3865
+ setToolCursorPoint(null);
3866
+ return;
3867
+ }
3868
+ setToolCursorPoint(
3869
+ (current) => current ?? nativeFallbackToolCursorPoint(size)
3870
+ );
3871
+ },
3872
+ [interactive, size]
3873
+ );
3874
+ useEffect(() => {
3875
+ showFallbackToolCursor(toolId);
3876
+ }, [showFallbackToolCursor, toolId]);
3839
3877
  const handlePointerMove = useCallback(
3840
3878
  (event) => {
3841
3879
  updateToolCursorPoint(screenPointFromPointerEvent(event));
@@ -4121,7 +4159,10 @@ var NativeVectorViewport = forwardRef(function NativeVectorViewport2({
4121
4159
  onPanResponderRelease: (evt) => {
4122
4160
  lastPinchDist.current = null;
4123
4161
  lastPanPoint.current = null;
4124
- hideToolCursor();
4162
+ updateToolCursorPoint({
4163
+ x: evt.nativeEvent.locationX,
4164
+ y: evt.nativeEvent.locationY
4165
+ });
4125
4166
  const st = dragStateRef.current;
4126
4167
  if (st.kind === "draw") {
4127
4168
  dragStateRef.current = { kind: "idle" };