@smakss/react-scroll-direction 1.0.5 → 2.0.0

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/esm/index.js CHANGED
@@ -1,1249 +1,83 @@
1
- import { useState, useEffect } from 'react';
2
-
3
- function getDefaultExportFromCjs (x) {
4
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
5
- }
6
-
7
- var propTypes = {exports: {}};
8
-
9
- var reactIs = {exports: {}};
10
-
11
- var reactIs_production_min = {};
12
-
13
- /** @license React v16.13.1
14
- * react-is.production.min.js
1
+ import { useState, useCallback, useEffect } from 'react';
2
+
3
+ /** Enumeration for axis values */
4
+ var Axis;
5
+ (function (Axis) {
6
+ Axis["X"] = "x";
7
+ Axis["Y"] = "y";
8
+ })(Axis || (Axis = {}));
9
+ /** Enumeration for direction values */
10
+ var Direction;
11
+ (function (Direction) {
12
+ Direction["Up"] = "up";
13
+ Direction["Down"] = "down";
14
+ Direction["Left"] = "left";
15
+ Direction["Right"] = "right";
16
+ Direction["Still"] = "still";
17
+ })(Direction || (Direction = {}));
18
+ /**
19
+ * useDetectScroll hook.
15
20
  *
16
- * Copyright (c) Facebook, Inc. and its affiliates.
21
+ * This hook provides a mechanism to detect the scroll direction.
22
+ * It will return the scroll direction as a string (up, down, left, right, or still) based on user scrolling.
17
23
  *
18
- * This source code is licensed under the MIT license found in the
19
- * LICENSE file in the root directory of this source tree.
20
- */
21
-
22
- var hasRequiredReactIs_production_min;
23
-
24
- function requireReactIs_production_min () {
25
- if (hasRequiredReactIs_production_min) return reactIs_production_min;
26
- hasRequiredReactIs_production_min = 1;
27
- var b="function"===typeof Symbol&&Symbol.for,c=b?Symbol.for("react.element"):60103,d=b?Symbol.for("react.portal"):60106,e=b?Symbol.for("react.fragment"):60107,f=b?Symbol.for("react.strict_mode"):60108,g=b?Symbol.for("react.profiler"):60114,h=b?Symbol.for("react.provider"):60109,k=b?Symbol.for("react.context"):60110,l=b?Symbol.for("react.async_mode"):60111,m=b?Symbol.for("react.concurrent_mode"):60111,n=b?Symbol.for("react.forward_ref"):60112,p=b?Symbol.for("react.suspense"):60113,q=b?
28
- Symbol.for("react.suspense_list"):60120,r=b?Symbol.for("react.memo"):60115,t=b?Symbol.for("react.lazy"):60116,v=b?Symbol.for("react.block"):60121,w=b?Symbol.for("react.fundamental"):60117,x=b?Symbol.for("react.responder"):60118,y=b?Symbol.for("react.scope"):60119;
29
- function z(a){if("object"===typeof a&&null!==a){var u=a.$$typeof;switch(u){case c:switch(a=a.type,a){case l:case m:case e:case g:case f:case p:return a;default:switch(a=a&&a.$$typeof,a){case k:case n:case t:case r:case h:return a;default:return u}}case d:return u}}}function A(a){return z(a)===m}reactIs_production_min.AsyncMode=l;reactIs_production_min.ConcurrentMode=m;reactIs_production_min.ContextConsumer=k;reactIs_production_min.ContextProvider=h;reactIs_production_min.Element=c;reactIs_production_min.ForwardRef=n;reactIs_production_min.Fragment=e;reactIs_production_min.Lazy=t;reactIs_production_min.Memo=r;reactIs_production_min.Portal=d;
30
- reactIs_production_min.Profiler=g;reactIs_production_min.StrictMode=f;reactIs_production_min.Suspense=p;reactIs_production_min.isAsyncMode=function(a){return A(a)||z(a)===l};reactIs_production_min.isConcurrentMode=A;reactIs_production_min.isContextConsumer=function(a){return z(a)===k};reactIs_production_min.isContextProvider=function(a){return z(a)===h};reactIs_production_min.isElement=function(a){return "object"===typeof a&&null!==a&&a.$$typeof===c};reactIs_production_min.isForwardRef=function(a){return z(a)===n};reactIs_production_min.isFragment=function(a){return z(a)===e};reactIs_production_min.isLazy=function(a){return z(a)===t};
31
- reactIs_production_min.isMemo=function(a){return z(a)===r};reactIs_production_min.isPortal=function(a){return z(a)===d};reactIs_production_min.isProfiler=function(a){return z(a)===g};reactIs_production_min.isStrictMode=function(a){return z(a)===f};reactIs_production_min.isSuspense=function(a){return z(a)===p};
32
- reactIs_production_min.isValidElementType=function(a){return "string"===typeof a||"function"===typeof a||a===e||a===m||a===g||a===f||a===p||a===q||"object"===typeof a&&null!==a&&(a.$$typeof===t||a.$$typeof===r||a.$$typeof===h||a.$$typeof===k||a.$$typeof===n||a.$$typeof===w||a.$$typeof===x||a.$$typeof===y||a.$$typeof===v)};reactIs_production_min.typeOf=z;
33
- return reactIs_production_min;
34
- }
35
-
36
- var reactIs_development = {};
37
-
38
- /** @license React v16.13.1
39
- * react-is.development.js
24
+ * @example
40
25
  *
41
- * Copyright (c) Facebook, Inc. and its affiliates.
26
+ * import useDetectScroll, { Axis, Direction } from './useDetectScroll';
42
27
  *
43
- * This source code is licensed under the MIT license found in the
44
- * LICENSE file in the root directory of this source tree.
45
- */
46
-
47
- var hasRequiredReactIs_development;
48
-
49
- function requireReactIs_development () {
50
- if (hasRequiredReactIs_development) return reactIs_development;
51
- hasRequiredReactIs_development = 1;
52
-
53
-
54
-
55
- if (process.env.NODE_ENV !== "production") {
56
- (function() {
57
-
58
- // The Symbol used to tag the ReactElement-like types. If there is no native Symbol
59
- // nor polyfill, then a plain number is used for performance.
60
- var hasSymbol = typeof Symbol === 'function' && Symbol.for;
61
- var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7;
62
- var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca;
63
- var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb;
64
- var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc;
65
- var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2;
66
- var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd;
67
- var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace; // TODO: We don't use AsyncMode or ConcurrentMode anymore. They were temporary
68
- // (unstable) APIs that have been removed. Can we remove the symbols?
69
-
70
- var REACT_ASYNC_MODE_TYPE = hasSymbol ? Symbol.for('react.async_mode') : 0xeacf;
71
- var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf;
72
- var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
73
- var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1;
74
- var REACT_SUSPENSE_LIST_TYPE = hasSymbol ? Symbol.for('react.suspense_list') : 0xead8;
75
- var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
76
- var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4;
77
- var REACT_BLOCK_TYPE = hasSymbol ? Symbol.for('react.block') : 0xead9;
78
- var REACT_FUNDAMENTAL_TYPE = hasSymbol ? Symbol.for('react.fundamental') : 0xead5;
79
- var REACT_RESPONDER_TYPE = hasSymbol ? Symbol.for('react.responder') : 0xead6;
80
- var REACT_SCOPE_TYPE = hasSymbol ? Symbol.for('react.scope') : 0xead7;
81
-
82
- function isValidElementType(type) {
83
- return typeof type === 'string' || typeof type === 'function' || // Note: its typeof might be other than 'symbol' or 'number' if it's a polyfill.
84
- type === REACT_FRAGMENT_TYPE || type === REACT_CONCURRENT_MODE_TYPE || type === REACT_PROFILER_TYPE || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || type === REACT_SUSPENSE_LIST_TYPE || typeof type === 'object' && type !== null && (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE || type.$$typeof === REACT_FUNDAMENTAL_TYPE || type.$$typeof === REACT_RESPONDER_TYPE || type.$$typeof === REACT_SCOPE_TYPE || type.$$typeof === REACT_BLOCK_TYPE);
85
- }
86
-
87
- function typeOf(object) {
88
- if (typeof object === 'object' && object !== null) {
89
- var $$typeof = object.$$typeof;
90
-
91
- switch ($$typeof) {
92
- case REACT_ELEMENT_TYPE:
93
- var type = object.type;
94
-
95
- switch (type) {
96
- case REACT_ASYNC_MODE_TYPE:
97
- case REACT_CONCURRENT_MODE_TYPE:
98
- case REACT_FRAGMENT_TYPE:
99
- case REACT_PROFILER_TYPE:
100
- case REACT_STRICT_MODE_TYPE:
101
- case REACT_SUSPENSE_TYPE:
102
- return type;
103
-
104
- default:
105
- var $$typeofType = type && type.$$typeof;
106
-
107
- switch ($$typeofType) {
108
- case REACT_CONTEXT_TYPE:
109
- case REACT_FORWARD_REF_TYPE:
110
- case REACT_LAZY_TYPE:
111
- case REACT_MEMO_TYPE:
112
- case REACT_PROVIDER_TYPE:
113
- return $$typeofType;
114
-
115
- default:
116
- return $$typeof;
117
- }
118
-
119
- }
120
-
121
- case REACT_PORTAL_TYPE:
122
- return $$typeof;
123
- }
124
- }
125
-
126
- return undefined;
127
- } // AsyncMode is deprecated along with isAsyncMode
128
-
129
- var AsyncMode = REACT_ASYNC_MODE_TYPE;
130
- var ConcurrentMode = REACT_CONCURRENT_MODE_TYPE;
131
- var ContextConsumer = REACT_CONTEXT_TYPE;
132
- var ContextProvider = REACT_PROVIDER_TYPE;
133
- var Element = REACT_ELEMENT_TYPE;
134
- var ForwardRef = REACT_FORWARD_REF_TYPE;
135
- var Fragment = REACT_FRAGMENT_TYPE;
136
- var Lazy = REACT_LAZY_TYPE;
137
- var Memo = REACT_MEMO_TYPE;
138
- var Portal = REACT_PORTAL_TYPE;
139
- var Profiler = REACT_PROFILER_TYPE;
140
- var StrictMode = REACT_STRICT_MODE_TYPE;
141
- var Suspense = REACT_SUSPENSE_TYPE;
142
- var hasWarnedAboutDeprecatedIsAsyncMode = false; // AsyncMode should be deprecated
143
-
144
- function isAsyncMode(object) {
145
- {
146
- if (!hasWarnedAboutDeprecatedIsAsyncMode) {
147
- hasWarnedAboutDeprecatedIsAsyncMode = true; // Using console['warn'] to evade Babel and ESLint
148
-
149
- console['warn']('The ReactIs.isAsyncMode() alias has been deprecated, ' + 'and will be removed in React 17+. Update your code to use ' + 'ReactIs.isConcurrentMode() instead. It has the exact same API.');
150
- }
151
- }
152
-
153
- return isConcurrentMode(object) || typeOf(object) === REACT_ASYNC_MODE_TYPE;
154
- }
155
- function isConcurrentMode(object) {
156
- return typeOf(object) === REACT_CONCURRENT_MODE_TYPE;
157
- }
158
- function isContextConsumer(object) {
159
- return typeOf(object) === REACT_CONTEXT_TYPE;
160
- }
161
- function isContextProvider(object) {
162
- return typeOf(object) === REACT_PROVIDER_TYPE;
163
- }
164
- function isElement(object) {
165
- return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
166
- }
167
- function isForwardRef(object) {
168
- return typeOf(object) === REACT_FORWARD_REF_TYPE;
169
- }
170
- function isFragment(object) {
171
- return typeOf(object) === REACT_FRAGMENT_TYPE;
172
- }
173
- function isLazy(object) {
174
- return typeOf(object) === REACT_LAZY_TYPE;
175
- }
176
- function isMemo(object) {
177
- return typeOf(object) === REACT_MEMO_TYPE;
178
- }
179
- function isPortal(object) {
180
- return typeOf(object) === REACT_PORTAL_TYPE;
181
- }
182
- function isProfiler(object) {
183
- return typeOf(object) === REACT_PROFILER_TYPE;
184
- }
185
- function isStrictMode(object) {
186
- return typeOf(object) === REACT_STRICT_MODE_TYPE;
187
- }
188
- function isSuspense(object) {
189
- return typeOf(object) === REACT_SUSPENSE_TYPE;
190
- }
191
-
192
- reactIs_development.AsyncMode = AsyncMode;
193
- reactIs_development.ConcurrentMode = ConcurrentMode;
194
- reactIs_development.ContextConsumer = ContextConsumer;
195
- reactIs_development.ContextProvider = ContextProvider;
196
- reactIs_development.Element = Element;
197
- reactIs_development.ForwardRef = ForwardRef;
198
- reactIs_development.Fragment = Fragment;
199
- reactIs_development.Lazy = Lazy;
200
- reactIs_development.Memo = Memo;
201
- reactIs_development.Portal = Portal;
202
- reactIs_development.Profiler = Profiler;
203
- reactIs_development.StrictMode = StrictMode;
204
- reactIs_development.Suspense = Suspense;
205
- reactIs_development.isAsyncMode = isAsyncMode;
206
- reactIs_development.isConcurrentMode = isConcurrentMode;
207
- reactIs_development.isContextConsumer = isContextConsumer;
208
- reactIs_development.isContextProvider = isContextProvider;
209
- reactIs_development.isElement = isElement;
210
- reactIs_development.isForwardRef = isForwardRef;
211
- reactIs_development.isFragment = isFragment;
212
- reactIs_development.isLazy = isLazy;
213
- reactIs_development.isMemo = isMemo;
214
- reactIs_development.isPortal = isPortal;
215
- reactIs_development.isProfiler = isProfiler;
216
- reactIs_development.isStrictMode = isStrictMode;
217
- reactIs_development.isSuspense = isSuspense;
218
- reactIs_development.isValidElementType = isValidElementType;
219
- reactIs_development.typeOf = typeOf;
220
- })();
221
- }
222
- return reactIs_development;
223
- }
224
-
225
- var hasRequiredReactIs;
226
-
227
- function requireReactIs () {
228
- if (hasRequiredReactIs) return reactIs.exports;
229
- hasRequiredReactIs = 1;
230
-
231
- if (process.env.NODE_ENV === 'production') {
232
- reactIs.exports = requireReactIs_production_min();
233
- } else {
234
- reactIs.exports = requireReactIs_development();
235
- }
236
- return reactIs.exports;
237
- }
238
-
239
- /*
240
- object-assign
241
- (c) Sindre Sorhus
242
- @license MIT
243
- */
244
-
245
- var objectAssign;
246
- var hasRequiredObjectAssign;
247
-
248
- function requireObjectAssign () {
249
- if (hasRequiredObjectAssign) return objectAssign;
250
- hasRequiredObjectAssign = 1;
251
- /* eslint-disable no-unused-vars */
252
- var getOwnPropertySymbols = Object.getOwnPropertySymbols;
253
- var hasOwnProperty = Object.prototype.hasOwnProperty;
254
- var propIsEnumerable = Object.prototype.propertyIsEnumerable;
255
-
256
- function toObject(val) {
257
- if (val === null || val === undefined) {
258
- throw new TypeError('Object.assign cannot be called with null or undefined');
259
- }
260
-
261
- return Object(val);
262
- }
263
-
264
- function shouldUseNative() {
265
- try {
266
- if (!Object.assign) {
267
- return false;
268
- }
269
-
270
- // Detect buggy property enumeration order in older V8 versions.
271
-
272
- // https://bugs.chromium.org/p/v8/issues/detail?id=4118
273
- var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
274
- test1[5] = 'de';
275
- if (Object.getOwnPropertyNames(test1)[0] === '5') {
276
- return false;
277
- }
278
-
279
- // https://bugs.chromium.org/p/v8/issues/detail?id=3056
280
- var test2 = {};
281
- for (var i = 0; i < 10; i++) {
282
- test2['_' + String.fromCharCode(i)] = i;
283
- }
284
- var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
285
- return test2[n];
286
- });
287
- if (order2.join('') !== '0123456789') {
288
- return false;
289
- }
290
-
291
- // https://bugs.chromium.org/p/v8/issues/detail?id=3056
292
- var test3 = {};
293
- 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
294
- test3[letter] = letter;
295
- });
296
- if (Object.keys(Object.assign({}, test3)).join('') !==
297
- 'abcdefghijklmnopqrst') {
298
- return false;
299
- }
300
-
301
- return true;
302
- } catch (err) {
303
- // We don't expect any of the above to throw, but better to be safe.
304
- return false;
305
- }
306
- }
307
-
308
- objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
309
- var from;
310
- var to = toObject(target);
311
- var symbols;
312
-
313
- for (var s = 1; s < arguments.length; s++) {
314
- from = Object(arguments[s]);
315
-
316
- for (var key in from) {
317
- if (hasOwnProperty.call(from, key)) {
318
- to[key] = from[key];
319
- }
320
- }
321
-
322
- if (getOwnPropertySymbols) {
323
- symbols = getOwnPropertySymbols(from);
324
- for (var i = 0; i < symbols.length; i++) {
325
- if (propIsEnumerable.call(from, symbols[i])) {
326
- to[symbols[i]] = from[symbols[i]];
327
- }
328
- }
329
- }
330
- }
331
-
332
- return to;
333
- };
334
- return objectAssign;
335
- }
336
-
337
- /**
338
- * Copyright (c) 2013-present, Facebook, Inc.
28
+ * function App() {
29
+ * const scrollDirection = useDetectScroll({
30
+ * thr: 100,
31
+ * axis: Axis.Y,
32
+ * scrollUp: Direction.Up,
33
+ * scrollDown: Direction.Down,
34
+ * still: Direction.Still
35
+ * });
339
36
  *
340
- * This source code is licensed under the MIT license found in the
341
- * LICENSE file in the root directory of this source tree.
342
- */
343
-
344
- var ReactPropTypesSecret_1;
345
- var hasRequiredReactPropTypesSecret;
346
-
347
- function requireReactPropTypesSecret () {
348
- if (hasRequiredReactPropTypesSecret) return ReactPropTypesSecret_1;
349
- hasRequiredReactPropTypesSecret = 1;
350
-
351
- var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
352
-
353
- ReactPropTypesSecret_1 = ReactPropTypesSecret;
354
- return ReactPropTypesSecret_1;
355
- }
356
-
357
- var has;
358
- var hasRequiredHas;
359
-
360
- function requireHas () {
361
- if (hasRequiredHas) return has;
362
- hasRequiredHas = 1;
363
- has = Function.call.bind(Object.prototype.hasOwnProperty);
364
- return has;
365
- }
366
-
367
- /**
368
- * Copyright (c) 2013-present, Facebook, Inc.
37
+ * return (
38
+ * <div>
39
+ * <p>Current scroll direction: {scrollDirection}</p>
40
+ * </div>
41
+ * );
42
+ * }
369
43
  *
370
- * This source code is licensed under the MIT license found in the
371
- * LICENSE file in the root directory of this source tree.
372
- */
373
-
374
- var checkPropTypes_1;
375
- var hasRequiredCheckPropTypes;
376
-
377
- function requireCheckPropTypes () {
378
- if (hasRequiredCheckPropTypes) return checkPropTypes_1;
379
- hasRequiredCheckPropTypes = 1;
380
-
381
- var printWarning = function() {};
382
-
383
- if (process.env.NODE_ENV !== 'production') {
384
- var ReactPropTypesSecret = requireReactPropTypesSecret();
385
- var loggedTypeFailures = {};
386
- var has = requireHas();
387
-
388
- printWarning = function(text) {
389
- var message = 'Warning: ' + text;
390
- if (typeof console !== 'undefined') {
391
- console.error(message);
392
- }
393
- try {
394
- // --- Welcome to debugging React ---
395
- // This error was thrown as a convenience so that you can use this stack
396
- // to find the callsite that caused this warning to fire.
397
- throw new Error(message);
398
- } catch (x) { /**/ }
399
- };
400
- }
401
-
402
- /**
403
- * Assert that the values match with the type specs.
404
- * Error messages are memorized and will only be shown once.
405
- *
406
- * @param {object} typeSpecs Map of name to a ReactPropType
407
- * @param {object} values Runtime values that need to be type-checked
408
- * @param {string} location e.g. "prop", "context", "child context"
409
- * @param {string} componentName Name of the component for error messages.
410
- * @param {?Function} getStack Returns the component stack.
411
- * @private
412
- */
413
- function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
414
- if (process.env.NODE_ENV !== 'production') {
415
- for (var typeSpecName in typeSpecs) {
416
- if (has(typeSpecs, typeSpecName)) {
417
- var error;
418
- // Prop type validation may throw. In case they do, we don't want to
419
- // fail the render phase where it didn't fail before. So we log it.
420
- // After these have been cleaned up, we'll let them throw.
421
- try {
422
- // This is intentionally an invariant that gets caught. It's the same
423
- // behavior as without this statement except with a better message.
424
- if (typeof typeSpecs[typeSpecName] !== 'function') {
425
- var err = Error(
426
- (componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' +
427
- 'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.' +
428
- 'This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.'
429
- );
430
- err.name = 'Invariant Violation';
431
- throw err;
432
- }
433
- error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret);
434
- } catch (ex) {
435
- error = ex;
436
- }
437
- if (error && !(error instanceof Error)) {
438
- printWarning(
439
- (componentName || 'React class') + ': type specification of ' +
440
- location + ' `' + typeSpecName + '` is invalid; the type checker ' +
441
- 'function must return `null` or an `Error` but returned a ' + typeof error + '. ' +
442
- 'You may have forgotten to pass an argument to the type checker ' +
443
- 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' +
444
- 'shape all require an argument).'
445
- );
446
- }
447
- if (error instanceof Error && !(error.message in loggedTypeFailures)) {
448
- // Only monitor this failure once because there tends to be a lot of the
449
- // same error.
450
- loggedTypeFailures[error.message] = true;
451
-
452
- var stack = getStack ? getStack() : '';
453
-
454
- printWarning(
455
- 'Failed ' + location + ' type: ' + error.message + (stack != null ? stack : '')
456
- );
457
- }
458
- }
459
- }
460
- }
461
- }
462
-
463
- /**
464
- * Resets warning cache when testing.
465
- *
466
- * @private
467
- */
468
- checkPropTypes.resetWarningCache = function() {
469
- if (process.env.NODE_ENV !== 'production') {
470
- loggedTypeFailures = {};
471
- }
472
- };
473
-
474
- checkPropTypes_1 = checkPropTypes;
475
- return checkPropTypes_1;
476
- }
477
-
478
- /**
479
- * Copyright (c) 2013-present, Facebook, Inc.
44
+ * @param {ScrollProps} props - The properties related to scrolling.
45
+ * @property {number} props.thr - The threshold value which the scroll difference must exceed to update scroll direction.
46
+ * @property {Axis} props.axis - The axis along which to detect scroll. Can be 'x' or 'y'.
47
+ * @property {Direction} props.scrollUp - The direction to set when scrolling up or left. By default, 'up' for y-axis and 'left' for x-axis.
48
+ * @property {Direction} props.scrollDown - The direction to set when scrolling down or right. By default, 'down' for y-axis and 'right' for x-axis.
49
+ * @property {Direction} props.still - The direction to set when there is no scrolling. By default, 'still'.
480
50
  *
481
- * This source code is licensed under the MIT license found in the
482
- * LICENSE file in the root directory of this source tree.
51
+ * @returns {Direction} - The current direction of scrolling.
483
52
  */
484
-
485
- var factoryWithTypeCheckers;
486
- var hasRequiredFactoryWithTypeCheckers;
487
-
488
- function requireFactoryWithTypeCheckers () {
489
- if (hasRequiredFactoryWithTypeCheckers) return factoryWithTypeCheckers;
490
- hasRequiredFactoryWithTypeCheckers = 1;
491
-
492
- var ReactIs = requireReactIs();
493
- var assign = requireObjectAssign();
494
-
495
- var ReactPropTypesSecret = requireReactPropTypesSecret();
496
- var has = requireHas();
497
- var checkPropTypes = requireCheckPropTypes();
498
-
499
- var printWarning = function() {};
500
-
501
- if (process.env.NODE_ENV !== 'production') {
502
- printWarning = function(text) {
503
- var message = 'Warning: ' + text;
504
- if (typeof console !== 'undefined') {
505
- console.error(message);
506
- }
507
- try {
508
- // --- Welcome to debugging React ---
509
- // This error was thrown as a convenience so that you can use this stack
510
- // to find the callsite that caused this warning to fire.
511
- throw new Error(message);
512
- } catch (x) {}
513
- };
514
- }
515
-
516
- function emptyFunctionThatReturnsNull() {
517
- return null;
518
- }
519
-
520
- factoryWithTypeCheckers = function(isValidElement, throwOnDirectAccess) {
521
- /* global Symbol */
522
- var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
523
- var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec.
524
-
525
- /**
526
- * Returns the iterator method function contained on the iterable object.
527
- *
528
- * Be sure to invoke the function with the iterable as context:
529
- *
530
- * var iteratorFn = getIteratorFn(myIterable);
531
- * if (iteratorFn) {
532
- * var iterator = iteratorFn.call(myIterable);
533
- * ...
534
- * }
535
- *
536
- * @param {?object} maybeIterable
537
- * @return {?function}
538
- */
539
- function getIteratorFn(maybeIterable) {
540
- var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]);
541
- if (typeof iteratorFn === 'function') {
542
- return iteratorFn;
543
- }
544
- }
545
-
546
- /**
547
- * Collection of methods that allow declaration and validation of props that are
548
- * supplied to React components. Example usage:
549
- *
550
- * var Props = require('ReactPropTypes');
551
- * var MyArticle = React.createClass({
552
- * propTypes: {
553
- * // An optional string prop named "description".
554
- * description: Props.string,
555
- *
556
- * // A required enum prop named "category".
557
- * category: Props.oneOf(['News','Photos']).isRequired,
558
- *
559
- * // A prop named "dialog" that requires an instance of Dialog.
560
- * dialog: Props.instanceOf(Dialog).isRequired
561
- * },
562
- * render: function() { ... }
563
- * });
564
- *
565
- * A more formal specification of how these methods are used:
566
- *
567
- * type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...)
568
- * decl := ReactPropTypes.{type}(.isRequired)?
569
- *
570
- * Each and every declaration produces a function with the same signature. This
571
- * allows the creation of custom validation functions. For example:
572
- *
573
- * var MyLink = React.createClass({
574
- * propTypes: {
575
- * // An optional string or URI prop named "href".
576
- * href: function(props, propName, componentName) {
577
- * var propValue = props[propName];
578
- * if (propValue != null && typeof propValue !== 'string' &&
579
- * !(propValue instanceof URI)) {
580
- * return new Error(
581
- * 'Expected a string or an URI for ' + propName + ' in ' +
582
- * componentName
583
- * );
584
- * }
585
- * }
586
- * },
587
- * render: function() {...}
588
- * });
589
- *
590
- * @internal
591
- */
592
-
593
- var ANONYMOUS = '<<anonymous>>';
594
-
595
- // Important!
596
- // Keep this list in sync with production version in `./factoryWithThrowingShims.js`.
597
- var ReactPropTypes = {
598
- array: createPrimitiveTypeChecker('array'),
599
- bigint: createPrimitiveTypeChecker('bigint'),
600
- bool: createPrimitiveTypeChecker('boolean'),
601
- func: createPrimitiveTypeChecker('function'),
602
- number: createPrimitiveTypeChecker('number'),
603
- object: createPrimitiveTypeChecker('object'),
604
- string: createPrimitiveTypeChecker('string'),
605
- symbol: createPrimitiveTypeChecker('symbol'),
606
-
607
- any: createAnyTypeChecker(),
608
- arrayOf: createArrayOfTypeChecker,
609
- element: createElementTypeChecker(),
610
- elementType: createElementTypeTypeChecker(),
611
- instanceOf: createInstanceTypeChecker,
612
- node: createNodeChecker(),
613
- objectOf: createObjectOfTypeChecker,
614
- oneOf: createEnumTypeChecker,
615
- oneOfType: createUnionTypeChecker,
616
- shape: createShapeTypeChecker,
617
- exact: createStrictShapeTypeChecker,
618
- };
619
-
620
- /**
621
- * inlined Object.is polyfill to avoid requiring consumers ship their own
622
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
623
- */
624
- /*eslint-disable no-self-compare*/
625
- function is(x, y) {
626
- // SameValue algorithm
627
- if (x === y) {
628
- // Steps 1-5, 7-10
629
- // Steps 6.b-6.e: +0 != -0
630
- return x !== 0 || 1 / x === 1 / y;
631
- } else {
632
- // Step 6.a: NaN == NaN
633
- return x !== x && y !== y;
634
- }
635
- }
636
- /*eslint-enable no-self-compare*/
637
-
638
- /**
639
- * We use an Error-like object for backward compatibility as people may call
640
- * PropTypes directly and inspect their output. However, we don't use real
641
- * Errors anymore. We don't inspect their stack anyway, and creating them
642
- * is prohibitively expensive if they are created too often, such as what
643
- * happens in oneOfType() for any type before the one that matched.
644
- */
645
- function PropTypeError(message, data) {
646
- this.message = message;
647
- this.data = data && typeof data === 'object' ? data: {};
648
- this.stack = '';
649
- }
650
- // Make `instanceof Error` still work for returned errors.
651
- PropTypeError.prototype = Error.prototype;
652
-
653
- function createChainableTypeChecker(validate) {
654
- if (process.env.NODE_ENV !== 'production') {
655
- var manualPropTypeCallCache = {};
656
- var manualPropTypeWarningCount = 0;
657
- }
658
- function checkType(isRequired, props, propName, componentName, location, propFullName, secret) {
659
- componentName = componentName || ANONYMOUS;
660
- propFullName = propFullName || propName;
661
-
662
- if (secret !== ReactPropTypesSecret) {
663
- if (throwOnDirectAccess) {
664
- // New behavior only for users of `prop-types` package
665
- var err = new Error(
666
- 'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +
667
- 'Use `PropTypes.checkPropTypes()` to call them. ' +
668
- 'Read more at http://fb.me/use-check-prop-types'
669
- );
670
- err.name = 'Invariant Violation';
671
- throw err;
672
- } else if (process.env.NODE_ENV !== 'production' && typeof console !== 'undefined') {
673
- // Old behavior for people using React.PropTypes
674
- var cacheKey = componentName + ':' + propName;
675
- if (
676
- !manualPropTypeCallCache[cacheKey] &&
677
- // Avoid spamming the console because they are often not actionable except for lib authors
678
- manualPropTypeWarningCount < 3
679
- ) {
680
- printWarning(
681
- 'You are manually calling a React.PropTypes validation ' +
682
- 'function for the `' + propFullName + '` prop on `' + componentName + '`. This is deprecated ' +
683
- 'and will throw in the standalone `prop-types` package. ' +
684
- 'You may be seeing this warning due to a third-party PropTypes ' +
685
- 'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.'
686
- );
687
- manualPropTypeCallCache[cacheKey] = true;
688
- manualPropTypeWarningCount++;
689
- }
690
- }
691
- }
692
- if (props[propName] == null) {
693
- if (isRequired) {
694
- if (props[propName] === null) {
695
- return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.'));
696
- }
697
- return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.'));
698
- }
699
- return null;
700
- } else {
701
- return validate(props, propName, componentName, location, propFullName);
702
- }
703
- }
704
-
705
- var chainedCheckType = checkType.bind(null, false);
706
- chainedCheckType.isRequired = checkType.bind(null, true);
707
-
708
- return chainedCheckType;
709
- }
710
-
711
- function createPrimitiveTypeChecker(expectedType) {
712
- function validate(props, propName, componentName, location, propFullName, secret) {
713
- var propValue = props[propName];
714
- var propType = getPropType(propValue);
715
- if (propType !== expectedType) {
716
- // `propValue` being instance of, say, date/regexp, pass the 'object'
717
- // check, but we can offer a more precise error message here rather than
718
- // 'of type `object`'.
719
- var preciseType = getPreciseType(propValue);
720
-
721
- return new PropTypeError(
722
- 'Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.'),
723
- {expectedType: expectedType}
724
- );
725
- }
726
- return null;
727
- }
728
- return createChainableTypeChecker(validate);
729
- }
730
-
731
- function createAnyTypeChecker() {
732
- return createChainableTypeChecker(emptyFunctionThatReturnsNull);
733
- }
734
-
735
- function createArrayOfTypeChecker(typeChecker) {
736
- function validate(props, propName, componentName, location, propFullName) {
737
- if (typeof typeChecker !== 'function') {
738
- return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.');
739
- }
740
- var propValue = props[propName];
741
- if (!Array.isArray(propValue)) {
742
- var propType = getPropType(propValue);
743
- return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.'));
744
- }
745
- for (var i = 0; i < propValue.length; i++) {
746
- var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']', ReactPropTypesSecret);
747
- if (error instanceof Error) {
748
- return error;
749
- }
750
- }
751
- return null;
752
- }
753
- return createChainableTypeChecker(validate);
754
- }
755
-
756
- function createElementTypeChecker() {
757
- function validate(props, propName, componentName, location, propFullName) {
758
- var propValue = props[propName];
759
- if (!isValidElement(propValue)) {
760
- var propType = getPropType(propValue);
761
- return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.'));
762
- }
763
- return null;
764
- }
765
- return createChainableTypeChecker(validate);
766
- }
767
-
768
- function createElementTypeTypeChecker() {
769
- function validate(props, propName, componentName, location, propFullName) {
770
- var propValue = props[propName];
771
- if (!ReactIs.isValidElementType(propValue)) {
772
- var propType = getPropType(propValue);
773
- return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement type.'));
774
- }
775
- return null;
776
- }
777
- return createChainableTypeChecker(validate);
778
- }
779
-
780
- function createInstanceTypeChecker(expectedClass) {
781
- function validate(props, propName, componentName, location, propFullName) {
782
- if (!(props[propName] instanceof expectedClass)) {
783
- var expectedClassName = expectedClass.name || ANONYMOUS;
784
- var actualClassName = getClassName(props[propName]);
785
- return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.'));
786
- }
787
- return null;
788
- }
789
- return createChainableTypeChecker(validate);
790
- }
791
-
792
- function createEnumTypeChecker(expectedValues) {
793
- if (!Array.isArray(expectedValues)) {
794
- if (process.env.NODE_ENV !== 'production') {
795
- if (arguments.length > 1) {
796
- printWarning(
797
- 'Invalid arguments supplied to oneOf, expected an array, got ' + arguments.length + ' arguments. ' +
798
- 'A common mistake is to write oneOf(x, y, z) instead of oneOf([x, y, z]).'
799
- );
800
- } else {
801
- printWarning('Invalid argument supplied to oneOf, expected an array.');
802
- }
803
- }
804
- return emptyFunctionThatReturnsNull;
805
- }
806
-
807
- function validate(props, propName, componentName, location, propFullName) {
808
- var propValue = props[propName];
809
- for (var i = 0; i < expectedValues.length; i++) {
810
- if (is(propValue, expectedValues[i])) {
811
- return null;
812
- }
813
- }
814
-
815
- var valuesString = JSON.stringify(expectedValues, function replacer(key, value) {
816
- var type = getPreciseType(value);
817
- if (type === 'symbol') {
818
- return String(value);
819
- }
820
- return value;
821
- });
822
- return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of value `' + String(propValue) + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.'));
823
- }
824
- return createChainableTypeChecker(validate);
825
- }
826
-
827
- function createObjectOfTypeChecker(typeChecker) {
828
- function validate(props, propName, componentName, location, propFullName) {
829
- if (typeof typeChecker !== 'function') {
830
- return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.');
831
- }
832
- var propValue = props[propName];
833
- var propType = getPropType(propValue);
834
- if (propType !== 'object') {
835
- return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.'));
836
- }
837
- for (var key in propValue) {
838
- if (has(propValue, key)) {
839
- var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret);
840
- if (error instanceof Error) {
841
- return error;
842
- }
843
- }
844
- }
845
- return null;
846
- }
847
- return createChainableTypeChecker(validate);
848
- }
849
-
850
- function createUnionTypeChecker(arrayOfTypeCheckers) {
851
- if (!Array.isArray(arrayOfTypeCheckers)) {
852
- process.env.NODE_ENV !== 'production' ? printWarning('Invalid argument supplied to oneOfType, expected an instance of array.') : void 0;
853
- return emptyFunctionThatReturnsNull;
854
- }
855
-
856
- for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
857
- var checker = arrayOfTypeCheckers[i];
858
- if (typeof checker !== 'function') {
859
- printWarning(
860
- 'Invalid argument supplied to oneOfType. Expected an array of check functions, but ' +
861
- 'received ' + getPostfixForTypeWarning(checker) + ' at index ' + i + '.'
862
- );
863
- return emptyFunctionThatReturnsNull;
864
- }
865
- }
866
-
867
- function validate(props, propName, componentName, location, propFullName) {
868
- var expectedTypes = [];
869
- for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
870
- var checker = arrayOfTypeCheckers[i];
871
- var checkerResult = checker(props, propName, componentName, location, propFullName, ReactPropTypesSecret);
872
- if (checkerResult == null) {
873
- return null;
874
- }
875
- if (checkerResult.data && has(checkerResult.data, 'expectedType')) {
876
- expectedTypes.push(checkerResult.data.expectedType);
877
- }
878
- }
879
- var expectedTypesMessage = (expectedTypes.length > 0) ? ', expected one of type [' + expectedTypes.join(', ') + ']': '';
880
- return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`' + expectedTypesMessage + '.'));
881
- }
882
- return createChainableTypeChecker(validate);
883
- }
884
-
885
- function createNodeChecker() {
886
- function validate(props, propName, componentName, location, propFullName) {
887
- if (!isNode(props[propName])) {
888
- return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.'));
889
- }
890
- return null;
891
- }
892
- return createChainableTypeChecker(validate);
893
- }
894
-
895
- function invalidValidatorError(componentName, location, propFullName, key, type) {
896
- return new PropTypeError(
897
- (componentName || 'React class') + ': ' + location + ' type `' + propFullName + '.' + key + '` is invalid; ' +
898
- 'it must be a function, usually from the `prop-types` package, but received `' + type + '`.'
899
- );
900
- }
901
-
902
- function createShapeTypeChecker(shapeTypes) {
903
- function validate(props, propName, componentName, location, propFullName) {
904
- var propValue = props[propName];
905
- var propType = getPropType(propValue);
906
- if (propType !== 'object') {
907
- return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
908
- }
909
- for (var key in shapeTypes) {
910
- var checker = shapeTypes[key];
911
- if (typeof checker !== 'function') {
912
- return invalidValidatorError(componentName, location, propFullName, key, getPreciseType(checker));
913
- }
914
- var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret);
915
- if (error) {
916
- return error;
917
- }
918
- }
919
- return null;
920
- }
921
- return createChainableTypeChecker(validate);
922
- }
923
-
924
- function createStrictShapeTypeChecker(shapeTypes) {
925
- function validate(props, propName, componentName, location, propFullName) {
926
- var propValue = props[propName];
927
- var propType = getPropType(propValue);
928
- if (propType !== 'object') {
929
- return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
930
- }
931
- // We need to check all keys in case some are required but missing from props.
932
- var allKeys = assign({}, props[propName], shapeTypes);
933
- for (var key in allKeys) {
934
- var checker = shapeTypes[key];
935
- if (has(shapeTypes, key) && typeof checker !== 'function') {
936
- return invalidValidatorError(componentName, location, propFullName, key, getPreciseType(checker));
937
- }
938
- if (!checker) {
939
- return new PropTypeError(
940
- 'Invalid ' + location + ' `' + propFullName + '` key `' + key + '` supplied to `' + componentName + '`.' +
941
- '\nBad object: ' + JSON.stringify(props[propName], null, ' ') +
942
- '\nValid keys: ' + JSON.stringify(Object.keys(shapeTypes), null, ' ')
943
- );
944
- }
945
- var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret);
946
- if (error) {
947
- return error;
948
- }
949
- }
950
- return null;
951
- }
952
-
953
- return createChainableTypeChecker(validate);
954
- }
955
-
956
- function isNode(propValue) {
957
- switch (typeof propValue) {
958
- case 'number':
959
- case 'string':
960
- case 'undefined':
961
- return true;
962
- case 'boolean':
963
- return !propValue;
964
- case 'object':
965
- if (Array.isArray(propValue)) {
966
- return propValue.every(isNode);
967
- }
968
- if (propValue === null || isValidElement(propValue)) {
969
- return true;
970
- }
971
-
972
- var iteratorFn = getIteratorFn(propValue);
973
- if (iteratorFn) {
974
- var iterator = iteratorFn.call(propValue);
975
- var step;
976
- if (iteratorFn !== propValue.entries) {
977
- while (!(step = iterator.next()).done) {
978
- if (!isNode(step.value)) {
979
- return false;
980
- }
981
- }
982
- } else {
983
- // Iterator will provide entry [k,v] tuples rather than values.
984
- while (!(step = iterator.next()).done) {
985
- var entry = step.value;
986
- if (entry) {
987
- if (!isNode(entry[1])) {
988
- return false;
989
- }
990
- }
991
- }
992
- }
993
- } else {
994
- return false;
995
- }
996
-
997
- return true;
998
- default:
999
- return false;
1000
- }
1001
- }
1002
-
1003
- function isSymbol(propType, propValue) {
1004
- // Native Symbol.
1005
- if (propType === 'symbol') {
1006
- return true;
1007
- }
1008
-
1009
- // falsy value can't be a Symbol
1010
- if (!propValue) {
1011
- return false;
1012
- }
1013
-
1014
- // 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol'
1015
- if (propValue['@@toStringTag'] === 'Symbol') {
1016
- return true;
1017
- }
1018
-
1019
- // Fallback for non-spec compliant Symbols which are polyfilled.
1020
- if (typeof Symbol === 'function' && propValue instanceof Symbol) {
1021
- return true;
1022
- }
1023
-
1024
- return false;
1025
- }
1026
-
1027
- // Equivalent of `typeof` but with special handling for array and regexp.
1028
- function getPropType(propValue) {
1029
- var propType = typeof propValue;
1030
- if (Array.isArray(propValue)) {
1031
- return 'array';
1032
- }
1033
- if (propValue instanceof RegExp) {
1034
- // Old webkits (at least until Android 4.0) return 'function' rather than
1035
- // 'object' for typeof a RegExp. We'll normalize this here so that /bla/
1036
- // passes PropTypes.object.
1037
- return 'object';
1038
- }
1039
- if (isSymbol(propType, propValue)) {
1040
- return 'symbol';
1041
- }
1042
- return propType;
1043
- }
1044
-
1045
- // This handles more types than `getPropType`. Only used for error messages.
1046
- // See `createPrimitiveTypeChecker`.
1047
- function getPreciseType(propValue) {
1048
- if (typeof propValue === 'undefined' || propValue === null) {
1049
- return '' + propValue;
1050
- }
1051
- var propType = getPropType(propValue);
1052
- if (propType === 'object') {
1053
- if (propValue instanceof Date) {
1054
- return 'date';
1055
- } else if (propValue instanceof RegExp) {
1056
- return 'regexp';
1057
- }
1058
- }
1059
- return propType;
1060
- }
1061
-
1062
- // Returns a string that is postfixed to a warning about an invalid type.
1063
- // For example, "undefined" or "of type array"
1064
- function getPostfixForTypeWarning(value) {
1065
- var type = getPreciseType(value);
1066
- switch (type) {
1067
- case 'array':
1068
- case 'object':
1069
- return 'an ' + type;
1070
- case 'boolean':
1071
- case 'date':
1072
- case 'regexp':
1073
- return 'a ' + type;
1074
- default:
1075
- return type;
1076
- }
1077
- }
1078
-
1079
- // Returns class name of the object, if any.
1080
- function getClassName(propValue) {
1081
- if (!propValue.constructor || !propValue.constructor.name) {
1082
- return ANONYMOUS;
1083
- }
1084
- return propValue.constructor.name;
1085
- }
1086
-
1087
- ReactPropTypes.checkPropTypes = checkPropTypes;
1088
- ReactPropTypes.resetWarningCache = checkPropTypes.resetWarningCache;
1089
- ReactPropTypes.PropTypes = ReactPropTypes;
1090
-
1091
- return ReactPropTypes;
1092
- };
1093
- return factoryWithTypeCheckers;
1094
- }
1095
-
1096
- /**
1097
- * Copyright (c) 2013-present, Facebook, Inc.
1098
- *
1099
- * This source code is licensed under the MIT license found in the
1100
- * LICENSE file in the root directory of this source tree.
1101
- */
1102
-
1103
- var factoryWithThrowingShims;
1104
- var hasRequiredFactoryWithThrowingShims;
1105
-
1106
- function requireFactoryWithThrowingShims () {
1107
- if (hasRequiredFactoryWithThrowingShims) return factoryWithThrowingShims;
1108
- hasRequiredFactoryWithThrowingShims = 1;
1109
-
1110
- var ReactPropTypesSecret = requireReactPropTypesSecret();
1111
-
1112
- function emptyFunction() {}
1113
- function emptyFunctionWithReset() {}
1114
- emptyFunctionWithReset.resetWarningCache = emptyFunction;
1115
-
1116
- factoryWithThrowingShims = function() {
1117
- function shim(props, propName, componentName, location, propFullName, secret) {
1118
- if (secret === ReactPropTypesSecret) {
1119
- // It is still safe when called from React.
1120
- return;
1121
- }
1122
- var err = new Error(
1123
- 'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +
1124
- 'Use PropTypes.checkPropTypes() to call them. ' +
1125
- 'Read more at http://fb.me/use-check-prop-types'
1126
- );
1127
- err.name = 'Invariant Violation';
1128
- throw err;
1129
- } shim.isRequired = shim;
1130
- function getShim() {
1131
- return shim;
1132
- } // Important!
1133
- // Keep this list in sync with production version in `./factoryWithTypeCheckers.js`.
1134
- var ReactPropTypes = {
1135
- array: shim,
1136
- bigint: shim,
1137
- bool: shim,
1138
- func: shim,
1139
- number: shim,
1140
- object: shim,
1141
- string: shim,
1142
- symbol: shim,
1143
-
1144
- any: shim,
1145
- arrayOf: getShim,
1146
- element: shim,
1147
- elementType: shim,
1148
- instanceOf: getShim,
1149
- node: shim,
1150
- objectOf: getShim,
1151
- oneOf: getShim,
1152
- oneOfType: getShim,
1153
- shape: getShim,
1154
- exact: getShim,
1155
-
1156
- checkPropTypes: emptyFunctionWithReset,
1157
- resetWarningCache: emptyFunction
1158
- };
1159
-
1160
- ReactPropTypes.PropTypes = ReactPropTypes;
1161
-
1162
- return ReactPropTypes;
1163
- };
1164
- return factoryWithThrowingShims;
1165
- }
1166
-
1167
- /**
1168
- * Copyright (c) 2013-present, Facebook, Inc.
1169
- *
1170
- * This source code is licensed under the MIT license found in the
1171
- * LICENSE file in the root directory of this source tree.
1172
- */
1173
-
1174
- if (process.env.NODE_ENV !== 'production') {
1175
- var ReactIs = requireReactIs();
1176
-
1177
- // By explicitly using `prop-types` you are opting into new development behavior.
1178
- // http://fb.me/prop-types-in-prod
1179
- var throwOnDirectAccess = true;
1180
- propTypes.exports = requireFactoryWithTypeCheckers()(ReactIs.isElement, throwOnDirectAccess);
1181
- } else {
1182
- // By explicitly using `prop-types` you are opting into new production behavior.
1183
- // http://fb.me/prop-types-in-prod
1184
- propTypes.exports = requireFactoryWithThrowingShims()();
1185
- }
1186
-
1187
- var propTypesExports = propTypes.exports;
1188
- var PropTypes = /*@__PURE__*/getDefaultExportFromCjs(propTypesExports);
1189
-
1190
53
  function useDetectScroll(props) {
1191
- const {
1192
- thr = 0,
1193
- axis = "y",
1194
- scrollUp = axis === "y" ? "up" : "left",
1195
- scrollDown = axis === "y" ? "down" : "right",
1196
- still = "still",
1197
- } = props;
1198
- const [scrollDir, setScrollDir] = useState(still);
1199
-
1200
- useEffect(() => {
1201
- const threshold = thr > 0 ? thr : 0;
54
+ const { thr = 0, axis = Axis.Y, scrollUp = axis === Axis.Y ? Direction.Up : Direction.Left, scrollDown = axis === Axis.Y ? Direction.Down : Direction.Right, still = Direction.Still, } = props;
55
+ const [scrollDir, setScrollDir] = useState(still);
56
+ const threshold = Math.max(0, thr);
1202
57
  let ticking = false;
1203
- let lastScroll = undefined;
1204
-
1205
- axis === "y"
1206
- ? (lastScroll = window.pageYOffset)
1207
- : (lastScroll = window.pageXOffset);
1208
-
1209
- const updateScrollDir = () => {
1210
- let scroll = undefined;
1211
-
1212
- axis === "y"
1213
- ? (scroll = window.pageYOffset)
1214
- : (scroll = window.pageXOffset);
1215
-
1216
- if (Math.abs(scroll - lastScroll) < threshold) {
58
+ let lastScroll = axis === Axis.Y ? window.scrollY : window.scrollX;
59
+ /** Function to update scroll direction */
60
+ const updateScrollDir = useCallback(() => {
61
+ const scroll = axis === Axis.Y ? window.scrollY : window.scrollX;
62
+ if (Math.abs(scroll - lastScroll) >= threshold) {
63
+ setScrollDir(scroll > lastScroll ? scrollDown : scrollUp);
64
+ lastScroll = Math.max(0, scroll);
65
+ }
1217
66
  ticking = false;
1218
- return;
1219
- }
1220
- setScrollDir(scroll > lastScroll ? scrollDown : scrollUp);
1221
- lastScroll = scroll > 0 ? scrollY : 0;
1222
- ticking = false;
1223
- };
1224
-
1225
- const onScroll = () => {
1226
- if (!ticking) {
1227
- window.requestAnimationFrame(updateScrollDir);
1228
- ticking = true;
1229
- }
1230
- };
1231
-
1232
- window.addEventListener("scroll", onScroll);
1233
-
1234
- return () => window.removeEventListener("scroll", onScroll);
1235
- }, [scrollDir]);
1236
-
1237
- return [scrollDir];
67
+ }, [axis, threshold, scrollDown, scrollUp]);
68
+ useEffect(() => {
69
+ /** Function to handle onScroll event */
70
+ const onScroll = () => {
71
+ if (!ticking) {
72
+ window.requestAnimationFrame(updateScrollDir);
73
+ ticking = true;
74
+ }
75
+ };
76
+ window.addEventListener("scroll", onScroll);
77
+ return () => window.removeEventListener("scroll", onScroll);
78
+ }, [updateScrollDir]);
79
+ return scrollDir;
1238
80
  }
1239
81
 
1240
- useDetectScroll.propTypes = {
1241
- thr: PropTypes.number,
1242
- axis: PropTypes.string,
1243
- scrollUp: PropTypes.string,
1244
- scrollDown: PropTypes.string,
1245
- still: PropTypes.string,
1246
- };
1247
-
1248
82
  export { useDetectScroll };
1249
83
  //# sourceMappingURL=index.js.map