@@ -9377,12 +9377,15 @@ var FPContainer = ({
9377
9377
onHide,
9378
9378
onShow,
9379
9379
outerStyle = { } ,
9380
+ scrollDebounceMs = 125 ,
9380
9381
style = { } ,
9381
9382
transitionTiming = 700
9382
9383
} ) => {
9384
+ const FPContainerInnerRef = import_react19 . useRef ( null ) ;
9385
+ const scrollTimer = import_react19 . useRef ( null ) ;
9386
+ const scrollY = import_react19 . useRef ( isSsr ? 0 : window . scrollY ) ;
9383
9387
const throttled = import_react19 . useRef ( false ) ;
9384
9388
const ticking = import_react19 . useRef ( false ) ;
9385
- const scrollY = import_react19 . useRef ( isSsr ? 0 : window . scrollY ) ;
9386
9389
const useOuterStyle = import_react19 . useMemo ( ( ) => ( {
9387
9390
left : 0 ,
9388
9391
position : "fixed" ,
@@ -9396,8 +9399,8 @@ var FPContainer = ({
9396
9399
right : 0 ,
9397
9400
...style
9398
9401
} ) , [ style ] ) ;
9399
- const FPContainerInnerRef = import_react19 . useRef ( null ) ;
9400
- const { ReactFPRef , slides } = import_react19 . useContext ( FPContext ) ;
9402
+ const { ReactFPRef , slides , isFullscreen } = import_react19 . useContext ( FPContext ) ;
9403
+ const [ , startTransition ] = import_react19 . useTransition ( ) ;
9401
9404
const [ pageState , setPageState ] = import_react19 . useState ( {
9402
9405
fullpageHeight : 0 ,
9403
9406
offsetHeight : 0 ,
@@ -9407,32 +9410,41 @@ var FPContainer = ({
9407
9410
translateY : 0 ,
9408
9411
viewportHeight : 0
9409
9412
} ) ;
9410
- const handleScroll = ( e ) => {
9413
+ const handleScroll = ( ) => {
9411
9414
if ( throttled . current || isSsr )
9412
9415
return ;
9413
9416
throttled . current = true ;
9414
- e . stopPropagation ( ) ;
9415
- setTimeout ( ( ) => {
9416
- throttled . current = false ;
9417
- } , transitionTiming ) ;
9418
9417
if ( ! ticking . current ) {
9419
9418
window . requestAnimationFrame ( ( ) => {
9420
9419
const newScrollY = window . scrollY ;
9421
9420
const prevScrollY = scrollY . current ;
9422
- if ( prevScrollY < newScrollY )
9421
+ if ( newScrollY === 0 )
9422
+ first ( ) ;
9423
+ else if ( window . innerHeight + Math . round ( newScrollY ) >= document . body . offsetHeight )
9424
+ last ( ) ;
9425
+ else if ( prevScrollY < newScrollY )
9423
9426
forward ( ) ;
9424
9427
else if ( prevScrollY > newScrollY )
9425
9428
back3 ( ) ;
9426
9429
if ( pageState . resetScroll || transitionTiming !== pageState . transitionTiming )
9427
- setPageState ( ( prevState ) => ( {
9428
- ...prevState ,
9429
- resetScroll : false ,
9430
- transitionTiming
9431
- } ) ) ;
9430
+ startTransition ( ( ) => {
9431
+ setPageState ( ( prevState ) => ( {
9432
+ ...prevState ,
9433
+ resetScroll : false ,
9434
+ transitionTiming
9435
+ } ) ) ;
9436
+ } ) ;
9432
9437
ticking . current = false ;
9433
9438
} ) ;
9434
9439
ticking . current = true ;
9435
9440
}
9441
+ setTimeout ( ( ) => {
9442
+ throttled . current = false ;
9443
+ } , transitionTiming ) ;
9444
+ } ;
9445
+ const bouncedHandleScroll = ( ) => {
9446
+ clearTimeout ( scrollTimer . current ) ;
9447
+ scrollTimer . current = setTimeout ( ( ) => handleScroll ( ) , scrollDebounceMs ) ;
9436
9448
} ;
9437
9449
const handleResize = ( ) => {
9438
9450
if ( ! FPContainerInnerRef . current || isSsr )
@@ -9443,11 +9455,13 @@ var FPContainer = ({
9443
9455
if ( ! ticking . current ) {
9444
9456
requestAnimationFrame ( ( ) => {
9445
9457
const fullpageHeight = FPContainerInnerRef . current . clientHeight ;
9446
- setPageState ( ( prevState ) => ( {
9447
- ...prevState ,
9448
- fullpageHeight,
9449
- viewportHeight : Math . max ( document . documentElement . clientHeight , window . innerHeight )
9450
- } ) ) ;
9458
+ startTransition ( ( ) => {
9459
+ setPageState ( ( prevState ) => ( {
9460
+ ...prevState ,
9461
+ fullpageHeight,
9462
+ viewportHeight : Math . max ( document . documentElement . clientHeight , window . innerHeight )
9463
+ } ) ) ;
9464
+ } ) ;
9451
9465
ReactFPRef . current . style . height = `${ fullpageHeight } px` ;
9452
9466
ticking . current = false ;
9453
9467
} ) ;
@@ -9496,7 +9510,9 @@ var FPContainer = ({
9496
9510
slideIndex,
9497
9511
translateY
9498
9512
} ;
9499
- setPageState ( ( prevState ) => ( { ...prevState , ...newPageState } ) ) ;
9513
+ startTransition ( ( ) => {
9514
+ setPageState ( ( prevState ) => ( { ...prevState , ...newPageState } ) ) ;
9515
+ } ) ;
9500
9516
setTimeout ( ( ) => {
9501
9517
throttled . current = false ;
9502
9518
scrollY . current = window . scrollY ;
@@ -9541,18 +9557,19 @@ var FPContainer = ({
9541
9557
import_react19 . useEffect ( ( ) => {
9542
9558
if ( isSsr )
9543
9559
return ;
9544
- window . addEventListener ( "scroll" , handleScroll , { passive : true } ) ;
9560
+ window . addEventListener ( "scroll" , bouncedHandleScroll , { passive : true } ) ;
9545
9561
window . addEventListener ( "resize" , handleResize , { passive : true } ) ;
9546
9562
document . addEventListener ( "keydown" , handleKeys , { passive : true } ) ;
9547
9563
return ( ) => {
9548
- window . removeEventListener ( "scroll" , handleScroll ) ;
9564
+ window . removeEventListener ( "scroll" , bouncedHandleScroll ) ;
9549
9565
window . removeEventListener ( "resize" , handleResize ) ;
9550
9566
document . removeEventListener ( "keydown" , handleKeys ) ;
9551
9567
} ;
9552
9568
} ) ;
9553
- import_react19 . useEffect ( ( ) => {
9569
+ import_react19 . useLayoutEffect ( ( ) => {
9554
9570
handleResize ( ) ;
9555
- } ) ;
9571
+ handleScroll ( ) ;
9572
+ } , [ isFullscreen ] ) ;
9556
9573
return jsx_runtime . jsx ( "div" , {
9557
9574
style : useOuterStyle ,
9558
9575
children : jsx_runtime . jsx ( motion2 . div , {
@@ -9573,6 +9590,7 @@ var import_react20 = __toESM(require_react());
9573
9590
var observeFn = ( el ) => el ;
9574
9591
var FPContext = import_react20 . createContext ( {
9575
9592
getIndex : ( el ) => 0 ,
9593
+ isFullscreen : false ,
9576
9594
ReactFPRef : null ,
9577
9595
slides : [ ] ,
9578
9596
subscribe : observeFn ,
@@ -9588,7 +9606,11 @@ var FPItem = ({
9588
9606
style = { } ,
9589
9607
motionProps = { }
9590
9608
} ) => {
9591
- const { subscribe, unsubscribe, getIndex } = import_react21 . useContext ( FPContext ) ;
9609
+ const useStyle2 = import_react21 . useMemo ( ( ) => ( {
9610
+ height,
9611
+ ...style
9612
+ } ) , [ style ] ) ;
9613
+ const { subscribe, unsubscribe } = import_react21 . useContext ( FPContext ) ;
9592
9614
const FPItemRef2 = import_react21 . useRef ( null ) ;
9593
9615
import_react21 . useEffect ( ( ) => {
9594
9616
subscribe ( FPItemRef2 ) ;
@@ -9598,10 +9620,7 @@ var FPItem = ({
9598
9620
} , [ ] ) ;
9599
9621
return jsx_runtime2 . jsx ( motion2 . div , {
9600
9622
className,
9601
- style : {
9602
- height,
9603
- ...style
9604
- } ,
9623
+ style : useStyle2 ,
9605
9624
ref : FPItemRef2 ,
9606
9625
...motionProps ,
9607
9626
children
@@ -9784,19 +9803,32 @@ var FullScreen = function FullScreen2(_ref) {
9784
9803
9785
9804
// src/ReactFP.tsx
9786
9805
var jsx_runtime4 = __toESM ( require_jsx_runtime ( ) ) ;
9806
+ var ImLoading = ( ) => jsx_runtime4 . jsx ( "div" , {
9807
+ style : { backgroundColor : "black" , height : "100vh" } ,
9808
+ children : "Loading"
9809
+ } ) ;
9787
9810
var ReactFP = ( {
9788
9811
children,
9789
9812
Button = FSButton ,
9790
9813
buttonStyle = { } ,
9791
9814
className = "" ,
9815
+ Fallback = ImLoading ,
9792
9816
motionProps = { } ,
9793
9817
style = { }
9794
9818
} ) => {
9795
9819
const useStyle2 = import_react23 . useMemo ( ( ) => ( {
9796
9820
position : "relative" ,
9797
9821
...style
9798
9822
} ) , [ style ] ) ;
9823
+ const useButtonStyle = import_react23 . useMemo ( ( ) => ( {
9824
+ position : "fixed" ,
9825
+ left : 10 ,
9826
+ top : 10 ,
9827
+ zIndex : 9999 ,
9828
+ ...buttonStyle
9829
+ } ) , [ buttonStyle ] ) ;
9799
9830
const [ slides , setSlides ] = import_react23 . useState ( [ ] ) ;
9831
+ const deferredSlides = import_react23 . useDeferredValue ( slides ) ;
9800
9832
const fullscreen = import_react23 . useRef ( false ) ;
9801
9833
const ReactFPRef = import_react23 . useRef ( null ) ;
9802
9834
const getIndex = ( slide ) => {
@@ -9819,19 +9851,14 @@ var ReactFP = ({
9819
9851
}
9820
9852
return void ( fullscreen . current = ! fullscreen . current ) ;
9821
9853
} ,
9822
- style : {
9823
- position : "fixed" ,
9824
- left : 10 ,
9825
- top : 10 ,
9826
- zIndex : 9999 ,
9827
- ...buttonStyle
9828
- }
9854
+ style : useButtonStyle
9829
9855
} ) ,
9830
9856
jsx_runtime4 . jsx ( FPContext . Provider , {
9831
9857
value : {
9832
9858
getIndex,
9859
+ isFullscreen : ! ! fullscreen . current ,
9833
9860
ReactFPRef,
9834
- slides,
9861
+ slides : deferredSlides ,
9835
9862
subscribe,
9836
9863
unsubscribe
9837
9864
} ,
@@ -9840,7 +9867,10 @@ var ReactFP = ({
9840
9867
ref : ReactFPRef ,
9841
9868
className,
9842
9869
...motionProps ,
9843
- children
9870
+ children : jsx_runtime4 . jsx ( import_react23 . Suspense , {
9871
+ fallback : jsx_runtime4 . jsx ( Fallback , { } ) ,
9872
+ children
9873
+ } )
9844
9874
} )
9845
9875
} )
9846
9876
]
0 commit comments