Compare commits

...

8 Commits

6 changed files with 2410 additions and 2030 deletions

View File

@ -1,128 +0,0 @@
# gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: '$CI_BUILD_STAGE'
stages:
- security
- test
- release
- metadata
before_script:
- pnpm install -g pnpm
- pnpm install -g @shipzone/npmci
- npmci npm prepare
# ====================
# security stage
# ====================
# ====================
# security stage
# ====================
auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci command npm config set registry https://registry.npmjs.org
- npmci command pnpm audit --audit-level=high --prod
tags:
- lossless
- docker
allow_failure: true
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci command npm config set registry https://registry.npmjs.org
- npmci command pnpm audit --audit-level=high --dev
tags:
- lossless
- docker
allow_failure: true
# ====================
# test stage
# ====================
testStable:
stage: test
script:
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
testBuild:
stage: test
script:
- npmci node install stable
- npmci npm install
- npmci npm build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
release:
stage: release
script:
- npmci node install stable
- npmci npm publish
only:
- tags
tags:
- lossless
- docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
allow_failure: true
only:
- tags
script:
- npmci command npm install -g typescript
- npmci npm prepare
- npmci npm install
tags:
- lossless
- docker
- priv
trigger:
stage: metadata
script:
- npmci trigger
only:
- tags
tags:
- lossless
- docker
- notpriv
pages:
stage: metadata
script:
- npmci node install stable
- npmci npm install
- npmci command npm run buildDocs
tags:
- lossless
- docker
- notpriv
only:
- tags
artifacts:
expire_in: 1 week
paths:
- public
allow_failure: true

View File

@ -1,5 +1,37 @@
# Changelog # Changelog
## 2025-06-20 - 2.3.3 - fix(package.json)
Update dependency versions and add pnpm package manager field
- Update @git.zone/tsbuild from ^2.2.1 to ^2.6.4
- Update @git.zone/tsbundle from ^2.2.5 to ^2.4.0
- Update @git.zone/tstest from ^1.0.96 to ^2.3.1
- Update @push.rocks/tapbundle from ^5.5.6 to ^6.0.3
- Update @push.rocks/lik from ^6.1.0 to ^6.2.2
- Update @push.rocks/smartpromise from ^4.2.2 to ^4.2.3
- Update @push.rocks/smartrx from ^3.0.7 to ^3.0.10
- Update @push.rocks/smartstate from ^2.0.19 to ^2.0.20
- Update lenis from ^1.1.20 to ^1.3.4
- Update lit from ^3.2.1 to ^3.3.0
- Add packageManager field for pnpm
## 2025-02-01 - 2.3.2 - fix(scroller)
Rename method from scrollToElement to toElement for consistency
- Updated method name in Scroller class for better coherence with existing naming conventions.
## 2025-01-31 - 2.3.1 - fix(scroller)
Removed passive option from scroll event listener
- The 'passive: true' option was removed from the native scroll event listener attachment.
## 2025-01-31 - 2.3.0 - feat(scroller)
Enhance Scroller class with callback execution and adaptive scroll listener
- Added support for executing scroll callbacks in the Scroller class.
- Integrated adaptive scrolling mechanism using Lenis, with native smooth scrolling detection.
- Ensured seamless switching between native scroll listener and Lenis scroll listener.
## 2025-01-31 - 2.2.0 - feat(core) ## 2025-01-31 - 2.2.0 - feat(core)
Enhance scrolling capabilities by integrating Scroller class and adding lenis support Enhance scrolling capabilities by integrating Scroller class and adding lenis support

View File

@ -1,6 +1,6 @@
{ {
"name": "@design.estate/dees-domtools", "name": "@design.estate/dees-domtools",
"version": "2.2.0", "version": "2.3.3",
"private": false, "private": false,
"description": "A package providing tools to simplify complex CSS structures and web development tasks, featuring TypeScript support and integration with various web technologies.", "description": "A package providing tools to simplify complex CSS structures and web development tasks, featuring TypeScript support and integration with various web technologies.",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
@ -15,30 +15,30 @@
"buildDocs": "tsdoc" "buildDocs": "tsdoc"
}, },
"devDependencies": { "devDependencies": {
"@git.zone/tsbuild": "^2.2.1", "@git.zone/tsbuild": "^2.6.4",
"@git.zone/tsbundle": "^2.2.5", "@git.zone/tsbundle": "^2.4.0",
"@git.zone/tstest": "^1.0.96", "@git.zone/tstest": "^2.3.1",
"@push.rocks/tapbundle": "^5.5.6", "@push.rocks/tapbundle": "^6.0.3",
"@types/node": "^22.12.0" "@types/node": "^22.12.0"
}, },
"dependencies": { "dependencies": {
"@api.global/typedrequest": "^3.1.10", "@api.global/typedrequest": "^3.1.10",
"@design.estate/dees-comms": "^1.0.27", "@design.estate/dees-comms": "^1.0.27",
"@push.rocks/lik": "^6.1.0", "@push.rocks/lik": "^6.2.2",
"@push.rocks/smartdelay": "^3.0.5", "@push.rocks/smartdelay": "^3.0.5",
"@push.rocks/smartjson": "^5.0.20", "@push.rocks/smartjson": "^5.0.20",
"@push.rocks/smartmarkdown": "^3.0.3", "@push.rocks/smartmarkdown": "^3.0.3",
"@push.rocks/smartpromise": "^4.2.2", "@push.rocks/smartpromise": "^4.2.3",
"@push.rocks/smartrouter": "^1.3.2", "@push.rocks/smartrouter": "^1.3.2",
"@push.rocks/smartrx": "^3.0.7", "@push.rocks/smartrx": "^3.0.10",
"@push.rocks/smartstate": "^2.0.19", "@push.rocks/smartstate": "^2.0.20",
"@push.rocks/smartstring": "^4.0.15", "@push.rocks/smartstring": "^4.0.15",
"@push.rocks/smarturl": "^3.1.0", "@push.rocks/smarturl": "^3.1.0",
"@push.rocks/webrequest": "^3.0.37", "@push.rocks/webrequest": "^3.0.37",
"@push.rocks/websetup": "^3.0.19", "@push.rocks/websetup": "^3.0.19",
"@push.rocks/webstore": "^2.0.20", "@push.rocks/webstore": "^2.0.20",
"lenis": "^1.1.20", "lenis": "^1.3.4",
"lit": "^3.2.1", "lit": "^3.3.0",
"sweet-scroll": "^4.0.0" "sweet-scroll": "^4.0.0"
}, },
"files": [ "files": [
@ -71,5 +71,6 @@
"state management", "state management",
"routing", "routing",
"performance optimization" "performance optimization"
] ],
"packageManager": "pnpm@10.11.0+sha512.6540583f41cc5f628eb3d9773ecee802f4f9ef9923cc45b69890fb47991d4b092964694ec3a4f738a420c918a333062c8b925d312f42e4f0c263eb603551f977"
} }

4139
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@design.estate/dees-domtools', name: '@design.estate/dees-domtools',
version: '2.2.0', version: '2.3.3',
description: 'A package providing tools to simplify complex CSS structures and web development tasks, featuring TypeScript support and integration with various web technologies.' description: 'A package providing tools to simplify complex CSS structures and web development tasks, featuring TypeScript support and integration with various web technologies.'
} }

View File

@ -4,17 +4,33 @@ import * as plugins from './domtools.plugins.js';
export class Scroller { export class Scroller {
public domtoolsInstance: DomTools; public domtoolsInstance: DomTools;
constructor( // Array to store scroll callback functions.
domtoolsInstanceArg: DomTools, private scrollCallbacks: Array<() => void> = [];
) {
// Lenis instance (if activated) or null.
private lenisInstance: plugins.Lenis | null = null;
// Bound handlers to allow removal from event listeners.
private handleNativeScroll = (event: Event): void => {
this.executeScrollCallbacks();
};
private handleLenisScroll = (info: any): void => {
this.executeScrollCallbacks();
};
constructor(domtoolsInstanceArg: DomTools) {
this.domtoolsInstance = domtoolsInstanceArg; this.domtoolsInstance = domtoolsInstanceArg;
// Attach the native scroll listener by default.
this.attachNativeScrollListener();
} }
private sweetScroller = new plugins.SweetScroll({ private sweetScroller = new plugins.SweetScroll({});
/* some options */
}); // TODO: switch to scroller class
public async scrollToElement( /**
* Scrolls to a given element with options.
*/
public async toElement(
elementArg: HTMLElement, elementArg: HTMLElement,
optionsArg: Parameters<typeof this.sweetScroller.toElement>[1] optionsArg: Parameters<typeof this.sweetScroller.toElement>[1]
) { ) {
@ -22,6 +38,9 @@ export class Scroller {
await plugins.smartdelay.delayFor(optionsArg.duration); await plugins.smartdelay.delayFor(optionsArg.duration);
} }
/**
* Detects whether native smooth scrolling is enabled.
*/
public async detectNativeSmoothScroll() { public async detectNativeSmoothScroll() {
const done = plugins.smartpromise.defer<boolean>(); const done = plugins.smartpromise.defer<boolean>();
const sampleSize = 100; const sampleSize = 100;
@ -64,14 +83,93 @@ export class Scroller {
return done.promise; return done.promise;
} }
/**
* Enables Lenis scrolling.
* If optionsArg.disableOnNativeSmoothScroll is true and native smooth scrolling is detected,
* Lenis will be destroyed immediately.
*/
public async enableLenisScroll(optionsArg?: { disableOnNativeSmoothScroll?: boolean }) { public async enableLenisScroll(optionsArg?: { disableOnNativeSmoothScroll?: boolean }) {
const lenis = new plugins.Lenis({ const lenis = new plugins.Lenis({
autoRaf: true, autoRaf: true,
}); });
if (optionsArg?.disableOnNativeSmoothScroll) { if (optionsArg?.disableOnNativeSmoothScroll) {
if (await this.detectNativeSmoothScroll()) { if (await this.detectNativeSmoothScroll()) {
lenis.destroy(); lenis.destroy();
return;
} }
} }
// Activate Lenis scrolling.
this.lenisInstance = lenis;
// Switch from native scroll listener to Lenis scroll listener.
this.detachNativeScrollListener();
this.attachLenisScrollListener();
// Monkey-patch the destroy method so that when Lenis is destroyed,
// the native scroll listener is reattached.
const originalDestroy = lenis.destroy.bind(lenis);
lenis.destroy = () => {
originalDestroy();
this.detachLenisScrollListener();
this.attachNativeScrollListener();
this.lenisInstance = null;
};
} }
}
/**
* Registers a callback to be executed on scroll.
* @param callback A function to execute on each scroll event.
*/
public onScroll(callback: () => void): void {
this.scrollCallbacks.push(callback);
}
/**
* Executes all registered scroll callbacks concurrently.
*/
private executeScrollCallbacks(): void {
// Execute all callbacks in parallel.
this.scrollCallbacks.forEach((callback) => {
try {
callback();
} catch (error) {
console.error('Error in scroll callback:', error);
}
});
}
/**
* Attaches the native scroll event listener.
*/
private attachNativeScrollListener(): void {
window.addEventListener('scroll', this.handleNativeScroll);
}
/**
* Detaches the native scroll event listener.
*/
private detachNativeScrollListener(): void {
window.removeEventListener('scroll', this.handleNativeScroll);
}
/**
* Attaches the Lenis scroll event listener.
*/
private attachLenisScrollListener(): void {
if (this.lenisInstance) {
// Assuming that Lenis exposes an `on` method to listen to scroll events.
this.lenisInstance.on('scroll', this.handleLenisScroll);
}
}
/**
* Detaches the Lenis scroll event listener.
*/
private detachLenisScrollListener(): void {
if (this.lenisInstance) {
// Assuming that Lenis exposes an `off` method to remove scroll event listeners.
this.lenisInstance.off('scroll', this.handleLenisScroll);
}
}
}