ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
161 lines • 21.8 kB
JavaScript
/**
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
*/
import { Directive, EventEmitter, Output } from '@angular/core';
import { fromEvent, Subscription } from 'rxjs';
import * as i0 from "@angular/core";
const MIN_SWIPE_DISTANCE = 0.1;
const STOP_SWIPE_DISTANCE = 0.01;
const REFRESH_INTERVAL = 20;
const SPEED_OFF_MULTIPLE = 0.995 ** REFRESH_INTERVAL;
export class NzTabScrollListDirective {
constructor(ngZone, elementRef) {
this.ngZone = ngZone;
this.elementRef = elementRef;
this.lastWheelDirection = null;
this.lastWheelTimestamp = 0;
this.lastTimestamp = 0;
this.lastTimeDiff = 0;
this.lastMixedWheel = 0;
this.lastWheelPrevent = false;
this.touchPosition = null;
this.lastOffset = null;
this.motion = -1;
this.unsubscribe = () => void 0;
this.offsetChange = new EventEmitter();
this.tabScroll = new EventEmitter();
this.onTouchEnd = (e) => {
if (!this.touchPosition) {
return;
}
const lastOffset = this.lastOffset;
const lastTimeDiff = this.lastTimeDiff;
this.lastOffset = this.touchPosition = null;
if (lastOffset) {
const distanceX = lastOffset.x / lastTimeDiff;
const distanceY = lastOffset.y / lastTimeDiff;
const absX = Math.abs(distanceX);
const absY = Math.abs(distanceY);
// Skip swipe if low distance
if (Math.max(absX, absY) < MIN_SWIPE_DISTANCE) {
return;
}
let currentX = distanceX;
let currentY = distanceY;
this.motion = window.setInterval(() => {
if (Math.abs(currentX) < STOP_SWIPE_DISTANCE && Math.abs(currentY) < STOP_SWIPE_DISTANCE) {
window.clearInterval(this.motion);
return;
}
currentX *= SPEED_OFF_MULTIPLE;
currentY *= SPEED_OFF_MULTIPLE;
this.onOffset(currentX * REFRESH_INTERVAL, currentY * REFRESH_INTERVAL, e);
}, REFRESH_INTERVAL);
}
};
this.onTouchMove = (e) => {
if (!this.touchPosition) {
return;
}
e.preventDefault();
const { screenX, screenY } = e.touches[0];
const offsetX = screenX - this.touchPosition.x;
const offsetY = screenY - this.touchPosition.y;
this.onOffset(offsetX, offsetY, e);
const now = Date.now();
this.lastTimeDiff = now - this.lastTimestamp;
this.lastTimestamp = now;
this.lastOffset = { x: offsetX, y: offsetY };
this.touchPosition = { x: screenX, y: screenY };
};
this.onTouchStart = (e) => {
const { screenX, screenY } = e.touches[0];
this.touchPosition = { x: screenX, y: screenY };
window.clearInterval(this.motion);
};
this.onWheel = (e) => {
const { deltaX, deltaY } = e;
let mixed;
const absX = Math.abs(deltaX);
const absY = Math.abs(deltaY);
if (absX === absY) {
mixed = this.lastWheelDirection === 'x' ? deltaX : deltaY;
}
else if (absX > absY) {
mixed = deltaX;
this.lastWheelDirection = 'x';
}
else {
mixed = deltaY;
this.lastWheelDirection = 'y';
}
// Optimize mac touch scroll
const now = Date.now();
const absMixed = Math.abs(mixed);
if (now - this.lastWheelTimestamp > 100 || absMixed - this.lastMixedWheel > 10) {
this.lastWheelPrevent = false;
}
this.onOffset(-mixed, -mixed, e);
if (e.defaultPrevented || this.lastWheelPrevent) {
this.lastWheelPrevent = true;
}
this.lastWheelTimestamp = now;
this.lastMixedWheel = absMixed;
};
}
ngOnInit() {
this.unsubscribe = this.ngZone.runOutsideAngular(() => {
const el = this.elementRef.nativeElement;
const wheel$ = fromEvent(el, 'wheel');
const touchstart$ = fromEvent(el, 'touchstart');
const touchmove$ = fromEvent(el, 'touchmove');
const touchend$ = fromEvent(el, 'touchend');
const subscription = new Subscription();
subscription.add(this.subscribeWrap('wheel', wheel$, this.onWheel));
subscription.add(this.subscribeWrap('touchstart', touchstart$, this.onTouchStart));
subscription.add(this.subscribeWrap('touchmove', touchmove$, this.onTouchMove));
subscription.add(this.subscribeWrap('touchend', touchend$, this.onTouchEnd));
return () => {
subscription.unsubscribe();
};
});
}
subscribeWrap(type, observable, handler) {
return observable.subscribe(event => {
this.tabScroll.emit({
type,
event
});
if (!event.defaultPrevented) {
handler(event);
}
});
}
onOffset(x, y, event) {
this.ngZone.run(() => {
this.offsetChange.emit({
x,
y,
event
});
});
}
ngOnDestroy() {
this.unsubscribe();
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.4", ngImport: i0, type: NzTabScrollListDirective, deps: [{ token: i0.NgZone }, { token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive }); }
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "17.3.4", type: NzTabScrollListDirective, isStandalone: true, selector: "[nzTabScrollList]", outputs: { offsetChange: "offsetChange", tabScroll: "tabScroll" }, ngImport: i0 }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.4", ngImport: i0, type: NzTabScrollListDirective, decorators: [{
type: Directive,
args: [{
selector: '[nzTabScrollList]',
standalone: true
}]
}], ctorParameters: () => [{ type: i0.NgZone }, { type: i0.ElementRef }], propDecorators: { offsetChange: [{
type: Output
}], tabScroll: [{
type: Output
}] } });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFiLXNjcm9sbC1saXN0LmRpcmVjdGl2ZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL2NvbXBvbmVudHMvdGFicy90YWItc2Nyb2xsLWxpc3QuZGlyZWN0aXZlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7R0FHRztBQUVILE9BQU8sRUFBRSxTQUFTLEVBQWMsWUFBWSxFQUE2QixNQUFNLEVBQUUsTUFBTSxlQUFlLENBQUM7QUFDdkcsT0FBTyxFQUFFLFNBQVMsRUFBYyxZQUFZLEVBQUUsTUFBTSxNQUFNLENBQUM7O0FBUzNELE1BQU0sa0JBQWtCLEdBQUcsR0FBRyxDQUFDO0FBQy9CLE1BQU0sbUJBQW1CLEdBQUcsSUFBSSxDQUFDO0FBQ2pDLE1BQU0sZ0JBQW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