Skip to content

Commit

Permalink
Removed legacy rollup options
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdarrengriffin authored Oct 5, 2023
1 parent 2b42dc8 commit d78bbd6
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 19 deletions.
45 changes: 40 additions & 5 deletions dist/dsap.es.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,46 @@
class o {
var d = Object.defineProperty;
var h = (l, e, t) => e in l ? d(l, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : l[e] = t;
var r = (l, e, t) => (h(l, typeof e != "symbol" ? e + "" : e, t), t);
class u {
constructor() {
window.addEventListener("scroll", this.scroll.bind(this));
// Setup elems variable
r(this, "elems");
// Set the range of the viewport delta to 1000. The higher the number, the better "resolution" of the scroll delta
r(this, "maxScrollDelta", 1e3);
this.init();
}
scroll() {
console.log("scrolling");
init() {
this.elems = document.querySelectorAll("[data-dsap]"), document.documentElement.style.setProperty("--dsap-max-scroll-delta", this.maxScrollDelta), window.addEventListener(
"scroll",
// Pass scroll event through a debounce function which runs it through requestAnimationFrame to improve performance
this.debounce(this.onScroll.bind(this)),
// Ensure passive event listeners are used where possible to improve scrolling performance
{ passive: !0 }
);
}
onScroll() {
const e = window.scrollY, t = e + window.innerHeight;
this.elems.forEach((o) => {
const n = o.getBoundingClientRect().top + e, c = n + o.getBoundingClientRect().height;
let i = !1, s = !1, a = 0;
t < n ? s = !1 : e > c ? s = !0 : i = !0, i ? a = ((t - n) / (o.getBoundingClientRect().height + window.innerHeight) * this.maxScrollDelta).toFixed(0) : s && (a = this.maxScrollDelta), o.dataset.dsapIs = i ? "in" : s ? "above" : "below", i && (o.dataset.dsapSeen = !0), o.style.setProperty("--dsap-scroll-delta", a);
});
}
/**
* A debounce function that uses requestAnimationFrame
* @param {function} fn - Function to debounce
*
* Credit: https://pqina.nl/blog/applying-styles-based-on-the-user-scroll-position-with-smart-css/
*/
debounce(e) {
let t;
return (...o) => {
t && cancelAnimationFrame(t), t = requestAnimationFrame(() => {
e(...o);
});
};
}
}
export {
o as DSAP
u as DSAP
};
2 changes: 1 addition & 1 deletion dist/dsap.umd.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 0 additions & 13 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,6 @@ module.exports = defineConfig({
entry: path.resolve(__dirname, 'lib/main.js'),
name: 'dsap',
fileName: (format) => `dsap.${format}.js`,
},
// compile scss to css
rollupOptions: {
plugins: [
scss({
includePaths: ['./styles'],
output: './dist/dsap.css',
failOnError: true,
outputStyle: 'compressed',
watch: 'styles',
runtime: require('sass')
})
]
}
}
});

0 comments on commit d78bbd6

Please sign in to comment.