@taiga-ui/cdk
Version:
Base library for creating Angular components and applications using Taiga UI principles regarding of actual visual appearance
49 lines (44 loc) • 2.76 kB
JavaScript
import * as i0 from '@angular/core';
import { inject, Injectable, Directive } from '@angular/core';
import { outputFromObservable } from '@angular/core/rxjs-interop';
import { DOCUMENT } from '@angular/common';
import { tuiTypedFromEvent } from '@taiga-ui/cdk/observables';
import { tuiInjectElement } from '@taiga-ui/cdk/utils/dom';
import { Observable, merge, switchMap, filter, map, pairwise, takeUntil, repeat } from 'rxjs';
class TuiPanService extends Observable {
constructor() {
const el = tuiInjectElement();
const doc = inject(DOCUMENT);
super((subscriber) => merge(tuiTypedFromEvent(el, 'touchstart', { passive: true }), tuiTypedFromEvent(el, 'mousedown'))
.pipe(switchMap(() => merge(tuiTypedFromEvent(doc, 'touchmove', { passive: true }).pipe(filter(({ touches }) => touches.length < 2), map(({ touches }) => touches[0])), tuiTypedFromEvent(doc, 'mousemove'))), pairwise(), map(([first, second]) => {
const deltaX = (second?.clientX ?? 0) - (first?.clientX ?? 0);
const deltaY = (second?.clientY ?? 0) - (first?.clientY ?? 0);
return [deltaX, deltaY];
}), takeUntil(merge(tuiTypedFromEvent(doc, 'touchend'), tuiTypedFromEvent(doc, 'mouseup'))), repeat())
.subscribe(subscriber));
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: TuiPanService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: TuiPanService }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: TuiPanService, decorators: [{
type: Injectable
}], ctorParameters: () => [] });
class TuiPan {
constructor() {
this.tuiPan = outputFromObservable(inject(TuiPanService));
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: TuiPan, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.25", type: TuiPan, isStandalone: true, selector: "[tuiPan]", outputs: { tuiPan: "tuiPan" }, providers: [TuiPanService], ngImport: i0 }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: TuiPan, decorators: [{
type: Directive,
args: [{
selector: '[tuiPan]',
providers: [TuiPanService],
}]
}] });
/**
* Generated bundle index. Do not edit.
*/
export { TuiPan, TuiPanService };
//# sourceMappingURL=taiga-ui-cdk-directives-pan.mjs.map