@design.estate/dees-domtools 2.2.0 → 2.3.1
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/dist_bundle/bundle.js +82 -4
- package/dist_bundle/bundle.js.map +2 -2
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/domtools.classes.scroller.d.ts +40 -0
- package/dist_ts/domtools.classes.scroller.js +92 -4
- package/package.json +1 -1
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/domtools.classes.scroller.ts +105 -7
package/dist_bundle/bundle.js
CHANGED
|
@@ -40357,16 +40357,31 @@ var lik = {
|
|
|
40357
40357
|
// ts/domtools.classes.scroller.ts
|
|
40358
40358
|
var Scroller = class {
|
|
40359
40359
|
constructor(domtoolsInstanceArg) {
|
|
40360
|
-
|
|
40361
|
-
|
|
40362
|
-
|
|
40360
|
+
// Array to store scroll callback functions.
|
|
40361
|
+
this.scrollCallbacks = [];
|
|
40362
|
+
// Lenis instance (if activated) or null.
|
|
40363
|
+
this.lenisInstance = null;
|
|
40364
|
+
// Bound handlers to allow removal from event listeners.
|
|
40365
|
+
this.handleNativeScroll = (event) => {
|
|
40366
|
+
this.executeScrollCallbacks();
|
|
40367
|
+
};
|
|
40368
|
+
this.handleLenisScroll = (info) => {
|
|
40369
|
+
this.executeScrollCallbacks();
|
|
40370
|
+
};
|
|
40371
|
+
this.sweetScroller = new import_sweet_scroll.default({});
|
|
40363
40372
|
this.domtoolsInstance = domtoolsInstanceArg;
|
|
40373
|
+
this.attachNativeScrollListener();
|
|
40364
40374
|
}
|
|
40365
|
-
|
|
40375
|
+
/**
|
|
40376
|
+
* Scrolls to a given element with options.
|
|
40377
|
+
*/
|
|
40366
40378
|
async scrollToElement(elementArg, optionsArg) {
|
|
40367
40379
|
this.sweetScroller.toElement(elementArg, optionsArg);
|
|
40368
40380
|
await dist_ts_exports2.delayFor(optionsArg.duration);
|
|
40369
40381
|
}
|
|
40382
|
+
/**
|
|
40383
|
+
* Detects whether native smooth scrolling is enabled.
|
|
40384
|
+
*/
|
|
40370
40385
|
async detectNativeSmoothScroll() {
|
|
40371
40386
|
const done = dist_ts_exports.defer();
|
|
40372
40387
|
const sampleSize = 100;
|
|
@@ -40401,6 +40416,11 @@ var Scroller = class {
|
|
|
40401
40416
|
window.addEventListener("wheel", onWheel);
|
|
40402
40417
|
return done.promise;
|
|
40403
40418
|
}
|
|
40419
|
+
/**
|
|
40420
|
+
* Enables Lenis scrolling.
|
|
40421
|
+
* If optionsArg.disableOnNativeSmoothScroll is true and native smooth scrolling is detected,
|
|
40422
|
+
* Lenis will be destroyed immediately.
|
|
40423
|
+
*/
|
|
40404
40424
|
async enableLenisScroll(optionsArg) {
|
|
40405
40425
|
const lenis = new Lenis({
|
|
40406
40426
|
autoRaf: true
|
|
@@ -40408,8 +40428,66 @@ var Scroller = class {
|
|
|
40408
40428
|
if (optionsArg?.disableOnNativeSmoothScroll) {
|
|
40409
40429
|
if (await this.detectNativeSmoothScroll()) {
|
|
40410
40430
|
lenis.destroy();
|
|
40431
|
+
return;
|
|
40411
40432
|
}
|
|
40412
40433
|
}
|
|
40434
|
+
this.lenisInstance = lenis;
|
|
40435
|
+
this.detachNativeScrollListener();
|
|
40436
|
+
this.attachLenisScrollListener();
|
|
40437
|
+
const originalDestroy = lenis.destroy.bind(lenis);
|
|
40438
|
+
lenis.destroy = () => {
|
|
40439
|
+
originalDestroy();
|
|
40440
|
+
this.detachLenisScrollListener();
|
|
40441
|
+
this.attachNativeScrollListener();
|
|
40442
|
+
this.lenisInstance = null;
|
|
40443
|
+
};
|
|
40444
|
+
}
|
|
40445
|
+
/**
|
|
40446
|
+
* Registers a callback to be executed on scroll.
|
|
40447
|
+
* @param callback A function to execute on each scroll event.
|
|
40448
|
+
*/
|
|
40449
|
+
onScroll(callback) {
|
|
40450
|
+
this.scrollCallbacks.push(callback);
|
|
40451
|
+
}
|
|
40452
|
+
/**
|
|
40453
|
+
* Executes all registered scroll callbacks concurrently.
|
|
40454
|
+
*/
|
|
40455
|
+
executeScrollCallbacks() {
|
|
40456
|
+
this.scrollCallbacks.forEach((callback) => {
|
|
40457
|
+
try {
|
|
40458
|
+
callback();
|
|
40459
|
+
} catch (error) {
|
|
40460
|
+
console.error("Error in scroll callback:", error);
|
|
40461
|
+
}
|
|
40462
|
+
});
|
|
40463
|
+
}
|
|
40464
|
+
/**
|
|
40465
|
+
* Attaches the native scroll event listener.
|
|
40466
|
+
*/
|
|
40467
|
+
attachNativeScrollListener() {
|
|
40468
|
+
window.addEventListener("scroll", this.handleNativeScroll);
|
|
40469
|
+
}
|
|
40470
|
+
/**
|
|
40471
|
+
* Detaches the native scroll event listener.
|
|
40472
|
+
*/
|
|
40473
|
+
detachNativeScrollListener() {
|
|
40474
|
+
window.removeEventListener("scroll", this.handleNativeScroll);
|
|
40475
|
+
}
|
|
40476
|
+
/**
|
|
40477
|
+
* Attaches the Lenis scroll event listener.
|
|
40478
|
+
*/
|
|
40479
|
+
attachLenisScrollListener() {
|
|
40480
|
+
if (this.lenisInstance) {
|
|
40481
|
+
this.lenisInstance.on("scroll", this.handleLenisScroll);
|
|
40482
|
+
}
|
|
40483
|
+
}
|
|
40484
|
+
/**
|
|
40485
|
+
* Detaches the Lenis scroll event listener.
|
|
40486
|
+
*/
|
|
40487
|
+
detachLenisScrollListener() {
|
|
40488
|
+
if (this.lenisInstance) {
|
|
40489
|
+
this.lenisInstance.off("scroll", this.handleLenisScroll);
|
|
40490
|
+
}
|
|
40413
40491
|
}
|
|
40414
40492
|
};
|
|
40415
40493
|
|