@koine/dom 1.0.101 → 1.0.103

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/node/scrollTo.js CHANGED
@@ -10,22 +10,34 @@ var off_1 = require("./off");
10
10
  *
11
11
  * @param offset - offset to scroll to
12
12
  * @param callback - callback function
13
+ * @param [fallbackTimeout] - this appears to be needed in some hard to reproduce scenario on safari, where the callback seem to be never called
14
+ * @param [behavior="smooth"]
13
15
  */
14
- function scrollTo(offset, callback) {
15
- var fixedOffset = offset.toFixed();
16
+ function scrollTo(destination, callback, fallbackTimeout, behavior) {
17
+ var fixedDestination = destination.toFixed();
16
18
  if (callback) {
19
+ var callbackFired_1 = false;
17
20
  var onScroll_1 = function () {
18
- if (window.pageYOffset.toFixed() === fixedOffset) {
21
+ if (window.pageYOffset.toFixed() === fixedDestination) {
19
22
  (0, off_1.off)(window, "scroll", onScroll_1);
23
+ callbackFired_1 = true;
20
24
  callback();
21
25
  }
22
26
  };
23
27
  (0, on_1.on)(window, "scroll", onScroll_1);
24
28
  onScroll_1();
29
+ if (fallbackTimeout) {
30
+ setTimeout(function () {
31
+ if (!callbackFired_1) {
32
+ (0, off_1.off)(window, "scroll", onScroll_1);
33
+ callback();
34
+ }
35
+ }, fallbackTimeout);
36
+ }
25
37
  }
26
38
  window.scrollTo({
27
- top: offset,
28
- behavior: "smooth",
39
+ top: destination,
40
+ behavior: behavior || "smooth",
29
41
  });
30
42
  }
31
43
  exports.scrollTo = scrollTo;
package/package.json CHANGED
@@ -4,12 +4,12 @@
4
4
  "main": "./node/index.js",
5
5
  "typings": "./index.d.ts",
6
6
  "dependencies": {
7
- "@koine/utils": "1.0.101",
7
+ "@koine/utils": "1.0.103",
8
8
  "ts-debounce": "^4.0.0",
9
9
  "tslib": "^2.4.0"
10
10
  },
11
11
  "peerDependencies": {},
12
- "version": "1.0.101",
12
+ "version": "1.0.103",
13
13
  "module": "./index.js",
14
14
  "types": "./index.d.ts"
15
15
  }
package/scrollTo.d.ts CHANGED
@@ -5,6 +5,8 @@
5
5
  *
6
6
  * @param offset - offset to scroll to
7
7
  * @param callback - callback function
8
+ * @param [fallbackTimeout] - this appears to be needed in some hard to reproduce scenario on safari, where the callback seem to be never called
9
+ * @param [behavior="smooth"]
8
10
  */
9
- export declare function scrollTo(offset: number, callback?: () => void): void;
11
+ export declare function scrollTo(destination: number, callback?: () => void, fallbackTimeout?: number, behavior?: ScrollBehavior): void;
10
12
  export default scrollTo;
package/scrollTo.js CHANGED
@@ -7,22 +7,34 @@ import { off } from "./off";
7
7
  *
8
8
  * @param offset - offset to scroll to
9
9
  * @param callback - callback function
10
+ * @param [fallbackTimeout] - this appears to be needed in some hard to reproduce scenario on safari, where the callback seem to be never called
11
+ * @param [behavior="smooth"]
10
12
  */
11
- export function scrollTo(offset, callback) {
12
- var fixedOffset = offset.toFixed();
13
+ export function scrollTo(destination, callback, fallbackTimeout, behavior) {
14
+ var fixedDestination = destination.toFixed();
13
15
  if (callback) {
16
+ var callbackFired_1 = false;
14
17
  var onScroll_1 = function () {
15
- if (window.pageYOffset.toFixed() === fixedOffset) {
18
+ if (window.pageYOffset.toFixed() === fixedDestination) {
16
19
  off(window, "scroll", onScroll_1);
20
+ callbackFired_1 = true;
17
21
  callback();
18
22
  }
19
23
  };
20
24
  on(window, "scroll", onScroll_1);
21
25
  onScroll_1();
26
+ if (fallbackTimeout) {
27
+ setTimeout(function () {
28
+ if (!callbackFired_1) {
29
+ off(window, "scroll", onScroll_1);
30
+ callback();
31
+ }
32
+ }, fallbackTimeout);
33
+ }
22
34
  }
23
35
  window.scrollTo({
24
- top: offset,
25
- behavior: "smooth",
36
+ top: destination,
37
+ behavior: behavior || "smooth",
26
38
  });
27
39
  }
28
40
  export default scrollTo;