feat(core): Enhance scrolling capabilities by integrating Scroller class and adding lenis support
This commit is contained in:
parent
0683378e39
commit
eb1ac75e49
@ -1,5 +1,13 @@
|
||||
# Changelog
|
||||
|
||||
## 2025-01-31 - 2.2.0 - feat(core)
|
||||
Enhance scrolling capabilities by integrating Scroller class and adding lenis support
|
||||
|
||||
- Replaced SweetScroll setup in domtools.classes.domtools.ts with Scroller class.
|
||||
- Moved SweetScroll initialization and methods to new Scroller class.
|
||||
- Added lenis support in the Scroller class for enhanced scrolling capabilities.
|
||||
- Updated dev and dependencies versions in package.json.
|
||||
|
||||
## 2025-01-09 - 2.1.1 - fix(themamanager)
|
||||
Fixed automatic global theme change subscription for background updates.
|
||||
|
||||
|
13
package.json
13
package.json
@ -15,11 +15,11 @@
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@git.zone/tsbuild": "^2.2.0",
|
||||
"@git.zone/tsbundle": "^2.1.0",
|
||||
"@git.zone/tstest": "^1.0.90",
|
||||
"@push.rocks/tapbundle": "^5.5.4",
|
||||
"@types/node": "^22.10.5"
|
||||
"@git.zone/tsbuild": "^2.2.1",
|
||||
"@git.zone/tsbundle": "^2.2.5",
|
||||
"@git.zone/tstest": "^1.0.96",
|
||||
"@push.rocks/tapbundle": "^5.5.6",
|
||||
"@types/node": "^22.12.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@api.global/typedrequest": "^3.1.10",
|
||||
@ -28,7 +28,7 @@
|
||||
"@push.rocks/smartdelay": "^3.0.5",
|
||||
"@push.rocks/smartjson": "^5.0.20",
|
||||
"@push.rocks/smartmarkdown": "^3.0.3",
|
||||
"@push.rocks/smartpromise": "^4.1.0",
|
||||
"@push.rocks/smartpromise": "^4.2.2",
|
||||
"@push.rocks/smartrouter": "^1.3.2",
|
||||
"@push.rocks/smartrx": "^3.0.7",
|
||||
"@push.rocks/smartstate": "^2.0.19",
|
||||
@ -37,6 +37,7 @@
|
||||
"@push.rocks/webrequest": "^3.0.37",
|
||||
"@push.rocks/websetup": "^3.0.19",
|
||||
"@push.rocks/webstore": "^2.0.20",
|
||||
"lenis": "^1.1.20",
|
||||
"lit": "^3.2.1",
|
||||
"sweet-scroll": "^4.0.0"
|
||||
},
|
||||
|
2988
pnpm-lock.yaml
generated
2988
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@design.estate/dees-domtools',
|
||||
version: '2.1.1',
|
||||
version: '2.2.0',
|
||||
description: 'A package providing tools to simplify complex CSS structures and web development tasks, featuring TypeScript support and integration with various web technologies.'
|
||||
}
|
||||
|
@ -93,9 +93,7 @@ export class DomTools {
|
||||
};
|
||||
|
||||
public deesComms = new plugins.deesComms.DeesComms();
|
||||
public scroller = new plugins.SweetScroll({
|
||||
/* some options */
|
||||
}); // TODO: switch to scroller class
|
||||
public scroller = new Scroller(this);
|
||||
public themeManager = new ThemeManager(this);
|
||||
public keyboard = new Keyboard(document.body);
|
||||
|
||||
|
@ -1,5 +1,77 @@
|
||||
import type { DomTools } from './domtools.classes.domtools.js';
|
||||
import * as plugins from './domtools.plugins.js';
|
||||
|
||||
export class Scroller {
|
||||
// TODO: move sweet scroll over to here;
|
||||
public domtoolsInstance: DomTools;
|
||||
|
||||
constructor(
|
||||
domtoolsInstanceArg: DomTools,
|
||||
) {
|
||||
this.domtoolsInstance = domtoolsInstanceArg;
|
||||
}
|
||||
|
||||
private sweetScroller = new plugins.SweetScroll({
|
||||
/* some options */
|
||||
}); // TODO: switch to scroller class
|
||||
|
||||
public async scrollToElement(
|
||||
elementArg: HTMLElement,
|
||||
optionsArg: Parameters<typeof this.sweetScroller.toElement>[1]
|
||||
) {
|
||||
this.sweetScroller.toElement(elementArg, optionsArg);
|
||||
await plugins.smartdelay.delayFor(optionsArg.duration);
|
||||
}
|
||||
|
||||
public async detectNativeSmoothScroll() {
|
||||
const done = plugins.smartpromise.defer<boolean>();
|
||||
const sampleSize = 100;
|
||||
const acceptableDeltaDifference = 3;
|
||||
const minimumSmoothRatio = 0.75;
|
||||
|
||||
const eventDeltas: number[] = [];
|
||||
|
||||
function onWheel(event: WheelEvent) {
|
||||
eventDeltas.push(event.deltaY);
|
||||
|
||||
if (eventDeltas.length >= sampleSize) {
|
||||
window.removeEventListener('wheel', onWheel);
|
||||
analyzeEvents();
|
||||
}
|
||||
}
|
||||
|
||||
function analyzeEvents() {
|
||||
const totalDiffs = eventDeltas.length - 1;
|
||||
let smallDiffCount = 0;
|
||||
|
||||
for (let i = 0; i < totalDiffs; i++) {
|
||||
const diff = Math.abs(eventDeltas[i + 1] - eventDeltas[i]);
|
||||
if (diff <= acceptableDeltaDifference) {
|
||||
smallDiffCount++;
|
||||
}
|
||||
}
|
||||
|
||||
const smoothRatio = smallDiffCount / totalDiffs;
|
||||
if (smoothRatio >= minimumSmoothRatio) {
|
||||
console.log('Smooth scrolling detected.');
|
||||
done.resolve(true);
|
||||
} else {
|
||||
console.log('Smooth scrolling NOT detected.');
|
||||
done.resolve(false);
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('wheel', onWheel);
|
||||
return done.promise;
|
||||
}
|
||||
|
||||
public async enableLenisScroll(optionsArg?: { disableOnNativeSmoothScroll?: boolean }) {
|
||||
const lenis = new plugins.Lenis({
|
||||
autoRaf: true,
|
||||
});
|
||||
if (optionsArg?.disableOnNativeSmoothScroll) {
|
||||
if (await this.detectNativeSmoothScroll()) {
|
||||
lenis.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -49,6 +49,7 @@ export {
|
||||
};
|
||||
|
||||
// third party scope
|
||||
import Lenis from 'lenis'
|
||||
import SweetScroll from 'sweet-scroll';
|
||||
|
||||
export { SweetScroll };
|
||||
export { Lenis, SweetScroll };
|
||||
|
Loading…
x
Reference in New Issue
Block a user