@jsb188/react 1.1.10 → 1.1.12

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/utils/hooks.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { areObjectsEqual } from '@jsb188/app/utils/object.ts';
2
+ import { releaseObjectUrl, retainObjectUrl } from '@jsb188/app/utils/url_client.ts';
2
3
  import { useEffect, useMemo, useRef, useState } from 'react';
3
4
 
4
5
  /**
@@ -7,65 +8,60 @@ import { useEffect, useMemo, useRef, useState } from 'react';
7
8
  * NOTE: Do *NOT* export this function.
8
9
  */
9
10
 
10
- function getDatabaseAction(
11
- currentData: any,
12
- data: any,
13
- allowNull?: boolean,
14
- mergeCurrentData?: boolean,
15
- ): any {
16
- if (!currentData) {
17
- return {
18
- action: 'INSERT',
19
- documentData: data,
20
- };
21
- }
22
-
23
- const documentData: Record<string, any> = {};
24
-
25
- let hasChanges = false;
26
- for (const key in data) {
27
- if (Object.prototype.hasOwnProperty.call(data, key) && data[key] !== undefined) {
28
- // trim() on all string databse fields should be OK;
29
- // But if not, add an extra param.
30
- const value = typeof data[key] === 'string' ? data[key].trim() : data[key];
31
-
32
- const isNotNull = value !== null || allowNull;
33
- if (isNotNull) {
34
- documentData[key] = value;
35
- }
36
-
37
- if (
38
- // Doing loose != check instead of !== type check
39
- currentData[key] != value &&
40
- isNotNull
41
- ) {
42
- if (value && typeof value === 'object') {
43
- hasChanges = !areObjectsEqual(currentData[key], value);
44
- } else {
45
- hasChanges = true;
46
- }
47
-
48
- if (hasChanges) {
49
- break;
50
- }
51
- }
52
- }
53
- }
54
-
55
- if (mergeCurrentData) {
56
- for (const key in currentData) {
57
- if (Object.prototype.hasOwnProperty.call(currentData, key) && documentData[key] === undefined) {
58
- documentData[key] = currentData[key];
59
- }
60
- }
61
- }
62
-
63
- const action = hasChanges ? 'UPDATE' : 'NONE';
64
-
65
- return {
66
- action,
67
- documentData,
68
- };
11
+ function getDatabaseAction(currentData: any, data: any, allowNull?: boolean, mergeCurrentData?: boolean): any {
12
+ if (!currentData) {
13
+ return {
14
+ action: 'INSERT',
15
+ documentData: data,
16
+ };
17
+ }
18
+
19
+ const documentData: Record<string, any> = {};
20
+
21
+ let hasChanges = false;
22
+ for (const key in data) {
23
+ if (Object.prototype.hasOwnProperty.call(data, key) && data[key] !== undefined) {
24
+ // trim() on all string databse fields should be OK;
25
+ // But if not, add an extra param.
26
+ const value = typeof data[key] === 'string' ? data[key].trim() : data[key];
27
+
28
+ const isNotNull = value !== null || allowNull;
29
+ if (isNotNull) {
30
+ documentData[key] = value;
31
+ }
32
+
33
+ if (
34
+ // Doing loose != check instead of !== type check
35
+ currentData[key] != value &&
36
+ isNotNull
37
+ ) {
38
+ if (value && typeof value === 'object') {
39
+ hasChanges = !areObjectsEqual(currentData[key], value);
40
+ } else {
41
+ hasChanges = true;
42
+ }
43
+
44
+ if (hasChanges) {
45
+ break;
46
+ }
47
+ }
48
+ }
49
+ }
50
+
51
+ if (mergeCurrentData) {
52
+ for (const key in currentData) {
53
+ if (Object.prototype.hasOwnProperty.call(currentData, key) && documentData[key] === undefined) {
54
+ documentData[key] = currentData[key];
55
+ }
56
+ }
57
+ }
58
+
59
+ const action = hasChanges ? 'UPDATE' : 'NONE';
60
+
61
+ return {
62
+ action,
63
+ documentData,
64
+ };
69
65
  }
70
66
 
71
67
  /**
@@ -73,28 +69,28 @@ function getDatabaseAction(
73
69
  */
74
70
 
75
71
  export function formValuesAreDiff(currentValues: any, formValues: any): boolean {
76
- if (!formValues && formValues !== 0) {
77
- // If formValues are null, it's not set yet
78
- return false;
79
- }
80
-
81
- if (typeof formValues === 'object') {
82
- // for (const key in currentValues) {
83
- // if (
84
- // currentValues[key] !== formValues[key] &&
85
- // // This would not work for values with number 0, but I don't think that's an issue for any mutations right now
86
- // (currentValues[key] !== null || formValues[key] !== undefined)
87
- // ) {
88
- // console.log('DIFF!:', key, currentValues[key], formValues[key]);
89
- // return true;
90
- // }
91
- // }
92
-
93
- const result = getDatabaseAction(currentValues, formValues);
94
- return result.action !== 'NONE';
95
- }
96
-
97
- return currentValues !== formValues;
72
+ if (!formValues && formValues !== 0) {
73
+ // If formValues are null, it's not set yet
74
+ return false;
75
+ }
76
+
77
+ if (typeof formValues === 'object') {
78
+ // for (const key in currentValues) {
79
+ // if (
80
+ // currentValues[key] !== formValues[key] &&
81
+ // // This would not work for values with number 0, but I don't think that's an issue for any mutations right now
82
+ // (currentValues[key] !== null || formValues[key] !== undefined)
83
+ // ) {
84
+ // console.log('DIFF!:', key, currentValues[key], formValues[key]);
85
+ // return true;
86
+ // }
87
+ // }
88
+
89
+ const result = getDatabaseAction(currentValues, formValues, true);
90
+ return result.action !== 'NONE';
91
+ }
92
+
93
+ return currentValues !== formValues;
98
94
  }
99
95
 
100
96
  /**
@@ -102,18 +98,35 @@ export function formValuesAreDiff(currentValues: any, formValues: any): boolean
102
98
  */
103
99
 
104
100
  export function useMounted() {
105
- const mounted = useRef(true);
106
-
107
- useEffect(() => {
108
- // This is necessary, I don't know why, this hook unmounteds itself and remounts even though the dependencies are empty
109
- // NOTE: This behavior was seen in [gqlClient.ts]
110
- mounted.current = true;
111
- return () => {
112
- mounted.current = false;
113
- };
114
- }, []);
115
-
116
- return mounted;
101
+ const mounted = useRef(true);
102
+
103
+ useEffect(() => {
104
+ // This is necessary, I don't know why, this hook unmounteds itself and remounts even though the dependencies are empty
105
+ // NOTE: This behavior was seen in [gqlClient.ts]
106
+ mounted.current = true;
107
+ return () => {
108
+ mounted.current = false;
109
+ };
110
+ }, []);
111
+
112
+ return mounted;
113
+ }
114
+
115
+ /**
116
+ * Return the computer timezone after client hydration.
117
+ */
118
+
119
+ let cachedComputerTimeZone: string | null = null;
120
+
121
+ export function useComputerTimeZone() {
122
+ const [timeZone, setTimeZone] = useState<string | null>(cachedComputerTimeZone);
123
+
124
+ useEffect(() => {
125
+ cachedComputerTimeZone ??= Intl.DateTimeFormat().resolvedOptions().timeZone;
126
+ setTimeZone(cachedComputerTimeZone);
127
+ }, []);
128
+
129
+ return timeZone;
117
130
  }
118
131
 
119
132
  /**
@@ -121,26 +134,26 @@ export function useMounted() {
121
134
  */
122
135
 
123
136
  export function useWatchChange(
124
- currentValues: any,
125
- formValues: any,
126
- saving: boolean,
127
- onChangeDiff: (hasChanges: boolean, saving: boolean) => void,
128
- onDataUpdated: () => void,
137
+ currentValues: any,
138
+ formValues: any,
139
+ saving: boolean,
140
+ onChangeDiff: (hasChanges: boolean, saving: boolean) => void,
141
+ onDataUpdated: () => void,
129
142
  ) {
130
- const isDiff = useMemo(() => {
131
- return formValuesAreDiff(currentValues, formValues);
132
- }, [currentValues, formValues]);
133
-
134
- useEffect(() => {
135
- onChangeDiff(isDiff, saving);
136
- }, [isDiff, saving]);
137
-
138
- useEffect(() => {
139
- if (!saving) {
140
- // Always update, because isDiff memo() only listens to formValues (and not currentValues)
141
- onDataUpdated();
142
- }
143
- }, [saving]);
143
+ const isDiff = useMemo(() => {
144
+ return formValuesAreDiff(currentValues, formValues);
145
+ }, [currentValues, formValues]);
146
+
147
+ useEffect(() => {
148
+ onChangeDiff(isDiff, saving);
149
+ }, [isDiff, saving]);
150
+
151
+ useEffect(() => {
152
+ if (!saving) {
153
+ // Always update, because isDiff memo() only listens to formValues (and not currentValues)
154
+ onDataUpdated();
155
+ }
156
+ }, [saving]);
144
157
  }
145
158
 
146
159
  /**
@@ -148,31 +161,27 @@ export function useWatchChange(
148
161
  */
149
162
 
150
163
  export function checkPropsDiff(pp: any, np: any) {
151
- let isSame = true;
152
- for (const k in pp) {
153
- if (Object.prototype.hasOwnProperty.call(pp, k) && pp[k] !== np[k]) {
154
- console.log('Diff:', k);
155
- isSame = false;
156
- }
157
- }
158
-
159
- for (const k in np) {
160
- if (
161
- Object.prototype.hasOwnProperty.call(np, k) &&
162
- !Object.prototype.hasOwnProperty.call(pp, k) &&
163
- np[k] !== pp[k]
164
- ) {
165
- console.log('New Prop:', k);
166
- isSame = false;
167
- }
168
- }
169
-
170
- return isSame;
164
+ let isSame = true;
165
+ for (const k in pp) {
166
+ if (Object.prototype.hasOwnProperty.call(pp, k) && pp[k] !== np[k]) {
167
+ console.log('Diff:', k);
168
+ isSame = false;
169
+ }
170
+ }
171
+
172
+ for (const k in np) {
173
+ if (Object.prototype.hasOwnProperty.call(np, k) && !Object.prototype.hasOwnProperty.call(pp, k) && np[k] !== pp[k]) {
174
+ console.log('New Prop:', k);
175
+ isSame = false;
176
+ }
177
+ }
178
+
179
+ return isSame;
171
180
  }
172
181
 
173
182
  if (globalThis && globalThis.location?.origin?.indexOf('localhost') >= 0) {
174
- // @ts-ignore - Dev only shim
175
- globalThis.checkPropsDiff = checkPropsDiff;
183
+ // @ts-ignore - Dev only shim
184
+ globalThis.checkPropsDiff = checkPropsDiff;
176
185
  }
177
186
 
178
187
  /**
@@ -180,75 +189,83 @@ if (globalThis && globalThis.location?.origin?.indexOf('localhost') >= 0) {
180
189
  */
181
190
 
182
191
  export function arePropsEqualExceptChildren(pp: any, np: any) {
183
- for (const k in np) {
184
- if (
185
- Object.prototype.hasOwnProperty.call(np, k) &&
186
- k !== 'children' &&
187
- (
188
- !Object.prototype.hasOwnProperty.call(pp, k) ||
189
- np[k] !== pp[k]
190
- )
191
- ) {
192
- // console.log('DIFF:', k, pp[k], np[k]);
193
- return false;
194
- }
195
- }
196
- return true;
192
+ for (const k in np) {
193
+ if (
194
+ Object.prototype.hasOwnProperty.call(np, k) &&
195
+ k !== 'children' &&
196
+ (!Object.prototype.hasOwnProperty.call(pp, k) || np[k] !== pp[k])
197
+ ) {
198
+ // console.log('DIFF:', k, pp[k], np[k]);
199
+ return false;
200
+ }
201
+ }
202
+ return true;
197
203
  }
198
204
 
199
205
  /**
200
206
  * Keep track of visibility state change and copy props;
201
- * To be used in animation components
207
+ * To be used in animation components.
208
+ *
209
+ * You can use this hook to animate an element to fade out before returning
210
+ * null. Pass a truthy value while the element should be visible, render while
211
+ * visibility is not 0, and apply fade classes from the visibility value.
212
+ *
213
+ * Example:
214
+ *
215
+ * const [, visibility] = useAnimationVisibility(visible);
216
+ * const active = visibility >= 2;
217
+ *
218
+ * if (!visibility) {
219
+ * return null;
220
+ * }
221
+ *
222
+ * return <div className={cn('trans_op spd_2', active ? 'op_100' : 'op_0')} />;
202
223
  */
203
224
 
204
- type VisibilityValue = 0 | .5 | 1 | 2;
225
+ type VisibilityValue = 0 | 0.5 | 1 | 2;
205
226
 
206
227
  export function useAnimationVisibility<T>(
207
- props: T,
208
- onHasProps?: (hasProps: boolean) => void,
209
- ): [
210
- any,
211
- VisibilityValue,
212
- (VisibilityValue: VisibilityValue) => void,
213
- ] {
214
- const [visibility, setVisibility] = useState(0 as VisibilityValue);
215
- const [persistedProps, setPersistedProps] = useState<T>(props as T);
216
- const hasData = !!props;
217
-
218
- useEffect(() => {
219
- if (props) {
220
- setPersistedProps(props);
221
- }
222
- onHasProps?.(hasData);
223
- }, [props]);
224
-
225
- useEffect(() => {
226
- if (visibility === 1) {
227
- if (hasData) {
228
- const timer = setTimeout(() => {
229
- setVisibility(2);
230
- }, 100);
231
- return () => clearTimeout(timer);
232
- } else {
233
- const timer = setTimeout(() => {
234
- setVisibility(0);
235
- }, 300);
236
- return () => clearTimeout(timer);
237
- }
238
- } else if (visibility === .5) {
239
- const timer = setTimeout(() => {
240
- setVisibility(0);
241
- }, 300);
242
- return () => clearTimeout(timer);
243
- }
244
-
245
- const shouldBeValue = hasData ? 2 : 0;
246
- if (shouldBeValue !== visibility) {
247
- setVisibility(hasData ? 1 : .5);
248
- }
249
- }, [visibility, hasData]);
250
-
251
- return [persistedProps, visibility, setVisibility];
228
+ props: T,
229
+ onHasProps?: (hasProps: boolean) => void,
230
+ ): [any, VisibilityValue, (VisibilityValue: VisibilityValue) => void] {
231
+ const [visibility, setVisibility] = useState(0 as VisibilityValue);
232
+ const [persistedProps, setPersistedProps] = useState<T>(props as T);
233
+ const hasData = !!props;
234
+
235
+ useEffect(() => {
236
+ if (props) {
237
+ setPersistedProps(props);
238
+ }
239
+ onHasProps?.(hasData);
240
+ }, [props]);
241
+
242
+ useEffect(() => {
243
+ if (visibility === 1) {
244
+ if (hasData) {
245
+ const timer = setTimeout(() => {
246
+ setVisibility(2);
247
+ }, 100);
248
+ return () => clearTimeout(timer);
249
+ } else {
250
+ const timer = setTimeout(() => {
251
+ setVisibility(0);
252
+ }, 300);
253
+ return () => clearTimeout(timer);
254
+ }
255
+ } else if (visibility === 0.5) {
256
+ const timer = setTimeout(() => {
257
+ setVisibility(0);
258
+ }, 300);
259
+ return () => clearTimeout(timer);
260
+ }
261
+
262
+ const shouldBeValue = hasData ? 2 : 0;
263
+ if (shouldBeValue !== visibility) {
264
+ setVisibility(hasData ? 1 : 0.5);
265
+ }
266
+ }, [visibility, hasData]);
267
+
268
+ return [persistedProps, visibility, setVisibility];
252
269
  }
253
270
 
254
271
  /**
@@ -257,94 +274,192 @@ export function useAnimationVisibility<T>(
257
274
  */
258
275
 
259
276
  export function useImagesLoadStatus(
260
- imageUrls: string[],
261
- timeoutMS = 10000 // default timeout miliseconds
277
+ imageUrls: string[],
278
+ timeoutMS = 10000, // default timeout miliseconds
262
279
  ): boolean {
263
- const [loaded, setLoaded] = useState(false);
264
-
265
- useEffect(() => {
266
- if (!imageUrls || imageUrls.length === 0) {
267
- setLoaded(true);
268
- return;
269
- }
270
-
271
- let isCancelled = false;
272
- let loadedCount = 0;
273
- const timeout = setTimeout(() => {
274
- if (!isCancelled) {
275
- setLoaded(true);
276
- }
277
- }, timeoutMS);
278
-
279
- const handleLoad = () => {
280
- loadedCount += 1;
281
- if (loadedCount === imageUrls.length && !isCancelled) {
282
- clearTimeout(timeout);
283
- setLoaded(true);
284
- }
285
- };
286
-
287
- const handleError = () => {
288
- loadedCount += 1; // count errors too, so they don’t block loading
289
- if (loadedCount === imageUrls.length && !isCancelled) {
290
- clearTimeout(timeout);
291
- setLoaded(true);
292
- }
293
- };
294
-
295
- const imageElements = imageUrls.map((url) => {
296
- const img = new Image();
297
- img.onload = handleLoad;
298
- img.onerror = handleError;
299
- img.src = url;
300
- return img;
301
- });
302
-
303
- return () => {
304
- isCancelled = true;
305
- clearTimeout(timeout);
306
- // Optional: clear handlers to prevent leaks
307
- imageElements.forEach((img) => {
308
- img.onload = null;
309
- img.onerror = null;
310
- });
311
- };
312
- }, []);
313
-
314
- return loaded;
280
+ const [loaded, setLoaded] = useState(false);
281
+
282
+ useEffect(() => {
283
+ if (!imageUrls || imageUrls.length === 0) {
284
+ setLoaded(true);
285
+ return;
286
+ }
287
+
288
+ let isCancelled = false;
289
+ let loadedCount = 0;
290
+ const timeout = setTimeout(() => {
291
+ if (!isCancelled) {
292
+ setLoaded(true);
293
+ }
294
+ }, timeoutMS);
295
+
296
+ const handleLoad = () => {
297
+ loadedCount += 1;
298
+ if (loadedCount === imageUrls.length && !isCancelled) {
299
+ clearTimeout(timeout);
300
+ setLoaded(true);
301
+ }
302
+ };
303
+
304
+ const handleError = () => {
305
+ loadedCount += 1; // count errors too, so they don’t block loading
306
+ if (loadedCount === imageUrls.length && !isCancelled) {
307
+ clearTimeout(timeout);
308
+ setLoaded(true);
309
+ }
310
+ };
311
+
312
+ const imageElements = imageUrls.map((url) => {
313
+ const img = new Image();
314
+ img.onload = handleLoad;
315
+ img.onerror = handleError;
316
+ img.src = url;
317
+ return img;
318
+ });
319
+
320
+ return () => {
321
+ isCancelled = true;
322
+ clearTimeout(timeout);
323
+ // Optional: clear handlers to prevent leaks
324
+ imageElements.forEach((img) => {
325
+ img.onload = null;
326
+ img.onerror = null;
327
+ });
328
+ };
329
+ }, []);
330
+
331
+ return loaded;
332
+ }
333
+
334
+ /*
335
+ * Hold local object URLs (e.g. image previews) while mounted, so they outlive the component that created them.
336
+ */
337
+
338
+ export function useRetainedObjectUrls(urls: (string | null | undefined)[]) {
339
+ const urlsKey = urls.filter(Boolean).join('\n');
340
+
341
+ useEffect(() => {
342
+ const retainedUrls = urlsKey ? urlsKey.split('\n') : [];
343
+ for (const url of retainedUrls) {
344
+ retainObjectUrl(url);
345
+ }
346
+
347
+ return () => {
348
+ for (const url of retainedUrls) {
349
+ releaseObjectUrl(url);
350
+ }
351
+ };
352
+ }, [urlsKey]);
315
353
  }
316
354
 
317
355
  /*
318
356
  * Track whether a referenced div's scroll position has passed a pixel offset.
319
357
  */
320
358
 
321
- export function useScrollPastPosition(
322
- pixels: number,
323
- ) {
324
- const divRef = useRef<HTMLDivElement>(null);
325
- const [hasScrolledPast, setHasScrolledPast] = useState(false);
359
+ export function useScrollPastPosition(pixels: number) {
360
+ const divRef = useRef<HTMLDivElement>(null);
361
+ const [hasScrolledPast, setHasScrolledPast] = useState(false);
326
362
 
327
- useEffect(() => {
328
- const element = divRef.current;
329
- if (!element) {
330
- return;
331
- }
363
+ useEffect(() => {
364
+ const element = divRef.current;
365
+ if (!element) {
366
+ return;
367
+ }
332
368
 
333
- const handleScroll = () => {
334
- const nextValue = element.scrollTop > pixels;
369
+ const handleScroll = () => {
370
+ const nextValue = element.scrollTop > pixels;
335
371
 
336
- setHasScrolledPast((currentValue) => {
337
- return currentValue === nextValue ? currentValue : nextValue;
338
- });
339
- };
372
+ setHasScrolledPast((currentValue) => {
373
+ return currentValue === nextValue ? currentValue : nextValue;
374
+ });
375
+ };
340
376
 
341
- element.addEventListener('scroll', handleScroll, { passive: true });
342
- handleScroll();
377
+ element.addEventListener('scroll', handleScroll, { passive: true });
378
+ handleScroll();
379
+
380
+ return () => {
381
+ element.removeEventListener('scroll', handleScroll);
382
+ };
383
+ }, [pixels]);
384
+
385
+ return [divRef, hasScrolledPast] as const;
386
+ }
343
387
 
344
- return () => {
345
- element.removeEventListener('scroll', handleScroll);
346
- };
347
- }, [pixels]);
388
+ export type ScrollNavState = 'STATIC' | 'HIDDEN' | 'SHOWN';
389
+
390
+ interface ScrollNavValue {
391
+ navState: ScrollNavState;
392
+ // Whether the page is scrolled past `staticOffset` (independent of scroll direction)
393
+ pastOffset: boolean;
394
+ }
395
+
396
+ /*
397
+ * Track the state of a hide-on-scroll window nav.
398
+ * 'STATIC' from page load until the page scrolls down past `staticOffset` (the nav sits in the page flow),
399
+ * then 'HIDDEN' while scrolling down and 'SHOWN' as soon as the page scrolls back up. Once shown, the nav
400
+ * stays fixed all the way up and only returns to 'STATIC' at the very top, where the two line up.
401
+ * Scroll deltas smaller than `minDelta` are ignored so trackpad jitter does not flip the direction.
402
+ */
348
403
 
349
- return [divRef, hasScrolledPast] as const;
404
+ export function useScrollNavState(staticOffset = 0, minDelta = 4) {
405
+ const [value, setValue] = useState<ScrollNavValue>({ navState: 'STATIC', pastOffset: false });
406
+
407
+ useEffect(() => {
408
+ let lastScrollY = window.scrollY;
409
+ let frameRequested = false;
410
+
411
+ const update = () => {
412
+ frameRequested = false;
413
+ const scrollY = window.scrollY;
414
+ const delta = scrollY - lastScrollY;
415
+ const isDirectionChange = Math.abs(delta) >= minDelta;
416
+
417
+ if (isDirectionChange) {
418
+ lastScrollY = scrollY;
419
+ }
420
+
421
+ const pastOffset = scrollY > staticOffset;
422
+
423
+ const getNavState = (currentValue: ScrollNavState): ScrollNavState => {
424
+ // Negative scrollY happens during rubber-band overscroll; it counts as the top.
425
+ if (scrollY <= 0) {
426
+ return 'STATIC';
427
+ }
428
+ if (isDirectionChange) {
429
+ if (delta > 0) {
430
+ return pastOffset ? 'HIDDEN' : currentValue;
431
+ }
432
+ return currentValue === 'STATIC' ? 'STATIC' : 'SHOWN';
433
+ }
434
+ // Landed past the offset without a real scroll (e.g. restored scroll position on load)
435
+ return currentValue === 'STATIC' && pastOffset ? 'SHOWN' : currentValue;
436
+ };
437
+
438
+ setValue((currentValue) => {
439
+ const navState = getNavState(currentValue.navState);
440
+ // Keep the same object when nothing changed so scroll frames do not re-render the nav
441
+ if (navState === currentValue.navState && pastOffset === currentValue.pastOffset) {
442
+ return currentValue;
443
+ }
444
+ return { navState, pastOffset };
445
+ });
446
+ };
447
+
448
+ // Coalesce bursts of scroll events into one read per frame
449
+ const handleScroll = () => {
450
+ if (!frameRequested) {
451
+ frameRequested = true;
452
+ window.requestAnimationFrame(update);
453
+ }
454
+ };
455
+
456
+ window.addEventListener('scroll', handleScroll, { passive: true });
457
+ update();
458
+
459
+ return () => {
460
+ window.removeEventListener('scroll', handleScroll);
461
+ };
462
+ }, [staticOffset, minDelta]);
463
+
464
+ return value;
350
465
  }