• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

atinc / ngx-tethys / 82f575a8-2f12-4689-80e6-398f6f1685a3

15 Aug 2024 08:19AM UTC coverage: 90.473%. Remained the same
82f575a8-2f12-4689-80e6-398f6f1685a3

push

circleci

web-flow
build: bump prettier to 3.3.3 and other deps, refactor notify use @if (#3152)

5502 of 6726 branches covered (81.8%)

Branch coverage included in aggregate %.

112 of 116 new or added lines in 57 files covered. (96.55%)

59 existing lines in 15 files now uncovered.

13254 of 14005 relevant lines covered (94.64%)

997.41 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.16
/src/core/scroll.ts
1
import { DOCUMENT } from '@angular/common';
2
import { Inject, Injectable, NgZone } from '@angular/core';
3
import { reqAnimFrame } from './request-animation';
4

5
export type EasyingFn = (t: number, b: number, c: number, d: number) => number;
6

58✔
7
function easeInOutCubic(t: number, b: number, c: number, d: number): number {
58✔
8
    const cc = c - b;
58✔
9
    let tt = t / (d / 2);
28✔
10
    if (tt < 1) {
11
        return (cc / 2) * tt * tt * tt + b;
12
    } else {
30✔
13
        return (cc / 2) * ((tt -= 2) * tt * tt + 2) + b;
14
    }
15
}
1✔
16

17
@Injectable({
13✔
18
    providedIn: 'root'
13✔
19
})
20
export class ThyScrollService {
21
    private document: Document;
×
22

63✔
23
    constructor(
61✔
24
        @Inject(DOCUMENT) document: any,
61✔
25
        private ngZone: NgZone
26
    ) {
27
        this.document = document;
2✔
28
    }
29

30
    /** Set the position of the scroll bar of `element`. */
31
    setScrollTop(element: Element | Window, topValue: number = 0): void {
8✔
32
        if (element === window) {
23✔
33
            this.document.body.scrollTop = topValue;
23✔
34
            this.document.documentElement.scrollTop = topValue;
23✔
35
        } else {
23✔
36
            (element as Element).scrollTop = topValue;
23✔
37
        }
23!
UNCOV
38
    }
×
39

40
    /** Get the position of the scoll bar of `element`. */
23✔
41
    getScroll(element?: Element | Window, top: boolean = true): number {
42
        const target = element ? element : window;
43
        const prop = top ? 'pageYOffset' : 'pageXOffset';
44
        const method = top ? 'scrollTop' : 'scrollLeft';
45
        const isWindow = target === window;
46
        let ret = isWindow ? target[prop] : target[method];
47
        if (isWindow && typeof ret !== 'number') {
48
            ret = this.document.documentElement[method];
49
        }
50
        return ret;
×
51
    }
2!
52

2✔
53
    /**
2✔
54
     * Scroll `element` to some position with animation.
2✔
55
     *
58✔
56
     * @param container container, `window` by default
58✔
57
     * @param topValue Scroll to `top`, 0 by default
58✔
58
     * @param easing Transition curve, `easeInOutCubic` by default
58✔
59
     * @param callback callback invoked when transition is done
56✔
60
     */
61
    scrollTo(container: Element | Window, topValue: number = 0, easing?: EasyingFn, callback?: () => void): void {
62
        const target = container ? container : window;
2!
63
        const scrollTop = this.getScroll(target);
64
        const startTime = Date.now();
65
        const frameFunc = () => {
2✔
66
            const timestamp = Date.now();
67
            const time = timestamp - startTime;
68
            this.setScrollTop(target, (easing || easeInOutCubic)(time, scrollTop, topValue, 450));
69
            if (time < 450) {
70
                this.ngZone.runOutsideAngular(() => reqAnimFrame(frameFunc));
71
            } else {
2✔
72
                if (callback) {
73
                    // The `frameFunc` is called within the `<root>` zone, but we have to re-enter
1✔
74
                    // the Angular zone when calling custom callback to be backwards-compatible.
75
                    this.ngZone.run(() => callback());
76
                }
77
            }
78
        };
1✔
79
        // The `requestAnimationFrame` triggers change detection, but setting
80
        // `document.scrollTop` doesn't require Angular to run `ApplicationRef.tick()`.
81
        this.ngZone.runOutsideAngular(() => reqAnimFrame(frameFunc));
82
    }
83
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc