@theforce/angular
Version:
Angular library for TheForce hand tracking
141 lines (134 loc) • 5.73 kB
JavaScript
import * as i0 from '@angular/core';
import { Injectable, Input, Component, Directive, NgModule } from '@angular/core';
import { HandTracker } from '@theforce/core';
import { BehaviorSubject } from 'rxjs';
import { CommonModule } from '@angular/common';
class HandTrackerService {
ngZone;
handTracker = null;
handLandmarksSubject = new BehaviorSubject([]);
isTracking = false;
constructor(ngZone) {
this.ngZone = ngZone;
}
get handLandmarks$() {
return this.handLandmarksSubject.asObservable();
}
get tracking() {
return this.isTracking;
}
async initialize(config = {}) {
this.handTracker = new HandTracker(config);
this.handTracker.onResults((results) => {
this.ngZone.run(() => {
this.handLandmarksSubject.next(results.multiHandLandmarks || []);
});
});
}
async start(config) {
if (this.isTracking) {
return;
}
if (!this.handTracker) {
await this.initialize(config);
}
if (this.handTracker) {
await this.handTracker.start();
this.isTracking = true;
}
}
async stop() {
if (!this.isTracking || !this.handTracker) {
return;
}
await this.handTracker.stop();
this.isTracking = false;
this.handLandmarksSubject.next([]);
}
async restart(config) {
await this.stop();
await this.start(config);
}
getTracker() {
return this.handTracker;
}
ngOnDestroy() {
if (this.handTracker) {
this.handTracker.stop();
this.handTracker = null;
}
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.6", ngImport: i0, type: HandTrackerService, deps: [{ token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Injectable });
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.6", ngImport: i0, type: HandTrackerService, providedIn: 'root' });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.6", ngImport: i0, type: HandTrackerService, decorators: [{
type: Injectable,
args: [{
providedIn: 'root'
}]
}], ctorParameters: () => [{ type: i0.NgZone }] });
class HandTrackerComponent {
handTrackerService;
options = {};
constructor(handTrackerService) {
this.handTrackerService = handTrackerService;
}
async ngOnInit() {
await this.handTrackerService.initialize(this.options);
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.6", ngImport: i0, type: HandTrackerComponent, deps: [{ token: HandTrackerService }], target: i0.ɵɵFactoryTarget.Component });
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.1.6", type: HandTrackerComponent, isStandalone: true, selector: "force-hand-tracker", inputs: { options: "options" }, ngImport: i0, template: `
<video #video style="display: none;"></video>
<ng-content></ng-content>
`, isInline: true });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.6", ngImport: i0, type: HandTrackerComponent, decorators: [{
type: Component,
args: [{
selector: 'force-hand-tracker',
template: `
<video #video style="display: none;"></video>
<ng-content></ng-content>
`
}]
}], ctorParameters: () => [{ type: HandTrackerService }], propDecorators: { options: [{
type: Input
}] } });
class HoverableDirective {
elementRef;
constructor(elementRef) {
this.elementRef = elementRef;
this.elementRef.nativeElement.classList.add('force-hoverable');
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.6", ngImport: i0, type: HoverableDirective, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive });
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.1.6", type: HoverableDirective, isStandalone: true, selector: "[forceHoverable]", ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.6", ngImport: i0, type: HoverableDirective, decorators: [{
type: Directive,
args: [{
selector: '[forceHoverable]'
}]
}], ctorParameters: () => [{ type: i0.ElementRef }] });
class HandTrackerModule {
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.6", ngImport: i0, type: HandTrackerModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.1.6", ngImport: i0, type: HandTrackerModule, imports: [CommonModule] });
static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.1.6", ngImport: i0, type: HandTrackerModule, providers: [
HandTrackerService
], imports: [CommonModule] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.6", ngImport: i0, type: HandTrackerModule, decorators: [{
type: NgModule,
args: [{
imports: [
CommonModule
],
providers: [
HandTrackerService
]
}]
}] });
/**
* Generated bundle index. Do not edit.
*/
export { HandTrackerComponent, HandTrackerModule, HandTrackerService, HoverableDirective };
//# sourceMappingURL=theforce-angular.mjs.map