ghostCursor.js

 1var cursoreffects = function(e) {
 2    "use strict";
 3    return e.ghostCursor = function(e) {
 4        let t, i, n, o = e && e.element,
 5            s = o || document.body,
 6            h = window.innerWidth,
 7            c = window.innerHeight,
 8            l = {
 9                x: h / 2,
10                y: h / 2
11            },
12            d = [],
13            r = new Image;
14        r.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAATCAYAAACk9eypAAAAAXNSR0IArs4c6QAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAhGVYSWZNTQAqAAAACAAFARIAAwAAAAEAAQAAARoABQAAAAEAAABKARsABQAAAAEAAABSASgAAwAAAAEAAgAAh2kABAAAAAEAAABaAAAAAAAAAEgAAAABAAAASAAAAAEAA6ABAAMAAAABAAEAAKACAAQAAAABAAAADKADAAQAAAABAAAAEwAAAAAChpcNAAAACXBIWXMAAAsTAAALEwEAmpwYAAABWWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNS40LjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczp0aWZmPSJodHRwOi8vbnMuYWRvYmUuY29tL3RpZmYvMS4wLyI+CiAgICAgICAgIDx0aWZmOk9yaWVudGF0aW9uPjE8L3RpZmY6T3JpZW50YXRpb24+CiAgICAgIDwvcmRmOkRlc2NyaXB0aW9uPgogICA8L3JkZjpSREY+CjwveDp4bXBtZXRhPgpMwidZAAABqElEQVQoFY3SPUvDQBgH8BREpRHExYiDgmLFl6WC+AYmWeyLg4i7buJX8DMpOujgyxGvUYeCgzhUQUSKKLUS0+ZyptXh8Z5Ti621ekPyJHl+uftfomhaf9Ei5JyxXKfynyEA6EYcLHpwyflT958GAQ7DTABNHd8EbtDbEH2BD5QEQmi2mM8P/Iq+A0SzszEg+3sPjDnDdVEtQKQbMUidHD3xVzf6A9UDEmEm+8h9KTqTVUjT+vB53aHrCbAPiceYq1dQI1Aqv4EhMll0jzv+Y0yiRgCnLRSYyDQHVoqUXe4uKL9l+L7GXC4vkMhE6eW/AOJs9k583ORDUyXMZ8F5SVHVVnllmPNKSFagAJ5DofaqGXw/gHBYg51dIldkmknY3tguv3jOtHR4+MqAzaraJXbEhqHhcQlwGSOi5pytVQHZLN5s0WNe8HPrLYlFsO20RPHkImxsbmHdLJFI76th7Z4SeuF53hTeFLvhRCJRCTKZKxgdnRDbW+iozFJbBMw14/ElwGYc0egMBMFzT21f5Rog33Z7dX02GBm7WV5ZfT5Nn5bE3zuCDe9UxdTpNvK+5AAAAABJRU5ErkJggg==";
15        const a = window.matchMedia("(prefers-reduced-motion: reduce)");
16
17        function A() {
18            if (a.matches) return console.log("This browser has prefers reduced motion turned on, so the cursor did not init"), !1;
19            t = document.createElement("canvas"), i = t.getContext("2d"), t.style.top = "0px", t.style.left = "0px", t.style.pointerEvents = "none", o ? (t.style.position = "absolute", s.appendChild(t), t.width = s.clientWidth, t.height = s.clientHeight) : (t.style.position = "fixed", document.body.appendChild(t), t.width = h, t.height = c), s.addEventListener("mousemove", g), s.addEventListener("touchmove", m, {
20                passive: !0
21            }), s.addEventListener("touchstart", m, {
22                passive: !0
23            }), window.addEventListener("resize", u), p()
24        }
25
26        function u(e) {
27            h = window.innerWidth, c = window.innerHeight, o ? (t.width = s.clientWidth, t.height = s.clientHeight) : (t.width = h, t.height = c)
28        }
29
30        function m(e) {
31            if (e.touches.length > 0)
32                for (let t = 0; t < e.touches.length; t++) f(e.touches[t].clientX, e.touches[t].clientY, r)
33        }
34
35        function g(e) {
36            if (o) {
37                const t = s.getBoundingClientRect();
38                l.x = e.clientX - t.left, l.y = e.clientY - t.top
39            } else l.x = e.clientX, l.y = e.clientY;
40            f(l.x, l.y, r)
41        }
42
43        function f(e, t, i) {
44            d.push(new w(e, t, i))
45        }
46
47        function p() {
48            ! function() {
49                if (0 != d.length) {
50                    i.clearRect(0, 0, h, c);
51                    for (let e = 0; e < d.length; e++) d[e].update(i);
52                    for (let e = d.length - 1; e >= 0; e--) d[e].lifeSpan < 0 && d.splice(e, 1);
53                    0 == d.length && i.clearRect(0, 0, h, c)
54                }
55            }(), n = requestAnimationFrame(p)
56        }
57
58        function y() {
59            t.remove(), cancelAnimationFrame(n), s.removeEventListener("mousemove", g), s.removeEventListener("touchmove", m), s.removeEventListener("touchstart", m), window.addEventListener("resize", u)
60        }
61
62        function w(e, t, i) {
63            this.initialLifeSpan = 40, this.lifeSpan = 40, this.position = {
64                x: e,
65                y: t
66            }, this.image = i, this.update = function(e) {
67                this.lifeSpan--;
68                const t = Math.max(this.lifeSpan / this.initialLifeSpan, 0);
69                e.globalAlpha = t, e.drawImage(this.image, this.position.x, this.position.y)
70            }
71        }
72        return a.onchange = () => {
73            a.matches ? y() : A()
74        }, A(), {
75            destroy: y
76        }
77    }, Object.defineProperty(e, "__esModule", {
78        value: !0
79    }), e
80}({});