* fix: blhost wrapper return with Promise.reject if error code !== 0 * feat: add keyboard separator line
110 lines
3.5 KiB
TypeScript
110 lines
3.5 KiB
TypeScript
import { Component, EventEmitter, Input, OnInit, Output, SimpleChanges, ChangeDetectionStrategy } from '@angular/core';
|
|
import { animate, state, trigger, style, transition } from '@angular/animations';
|
|
import { DomSanitizer, SafeStyle } from '@angular/platform-browser';
|
|
import { Module } from 'uhk-common';
|
|
|
|
import { SvgModule } from '../module';
|
|
import { SvgModuleProviderService } from '../../../services/svg-module-provider.service';
|
|
import { KeyboardLayout } from '../../../keyboard/keyboard-layout.enum';
|
|
import { SvgSeparator } from '../separator';
|
|
|
|
@Component({
|
|
selector: 'svg-keyboard',
|
|
templateUrl: './svg-keyboard.component.html',
|
|
styleUrls: ['./svg-keyboard.component.scss'],
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
animations: [
|
|
trigger('split', [
|
|
state('rotateLeft', style({
|
|
transform: 'translate(-3%, 15%) rotate(4deg) scale(0.92, 0.92)'
|
|
})),
|
|
state('rotateRight', style({
|
|
transform: 'translate(3%, 15%) rotate(-4deg) scale(0.92, 0.92)'
|
|
})),
|
|
transition('* <=> *', animate(500))
|
|
])
|
|
]
|
|
})
|
|
export class SvgKeyboardComponent implements OnInit {
|
|
@Input() moduleConfig: Module[];
|
|
@Input() keybindAnimationEnabled: boolean;
|
|
@Input() capturingEnabled: boolean;
|
|
@Input() selectedKey: { layerId: number, moduleId: number, keyId: number };
|
|
@Input() selected: boolean;
|
|
@Input() halvesSplit: boolean;
|
|
@Input() keyboardLayout = KeyboardLayout.ANSI;
|
|
@Input() description: string;
|
|
@Input() showDescription = false;
|
|
@Output() keyClick = new EventEmitter();
|
|
@Output() keyHover = new EventEmitter();
|
|
@Output() capture = new EventEmitter();
|
|
@Output() descriptionChanged = new EventEmitter<string>();
|
|
|
|
modules: SvgModule[];
|
|
viewBox: string;
|
|
moduleAnimationStates: string[];
|
|
separator: SvgSeparator;
|
|
separatorStyle: SafeStyle;
|
|
|
|
constructor(private svgModuleProvider: SvgModuleProviderService,
|
|
private sanitizer: DomSanitizer) {
|
|
this.modules = [];
|
|
this.viewBox = '-520 582 1100 470';
|
|
this.halvesSplit = false;
|
|
this.moduleAnimationStates = [];
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.setModules();
|
|
}
|
|
|
|
ngOnChanges(changes: SimpleChanges) {
|
|
if (changes.halvesSplit) {
|
|
this.updateModuleAnimationStates();
|
|
}
|
|
|
|
if (changes['keyboardLayout']) {
|
|
this.setModules();
|
|
}
|
|
}
|
|
|
|
onKeyClick(moduleId: number, keyId: number, keyTarget: HTMLElement): void {
|
|
this.keyClick.emit({
|
|
moduleId,
|
|
keyId,
|
|
keyTarget
|
|
});
|
|
}
|
|
|
|
onCapture(moduleId: number, keyId: number, captured: { code: number, left: boolean[], right: boolean[] }): void {
|
|
this.capture.emit({
|
|
moduleId,
|
|
keyId,
|
|
captured
|
|
});
|
|
}
|
|
|
|
onKeyHover(keyId: number, event: MouseEvent, over: boolean, moduleId: number): void {
|
|
this.keyHover.emit({
|
|
moduleId,
|
|
event,
|
|
over,
|
|
keyId
|
|
});
|
|
}
|
|
|
|
private updateModuleAnimationStates() {
|
|
if (this.halvesSplit) {
|
|
this.moduleAnimationStates = ['rotateRight', 'rotateLeft'];
|
|
} else {
|
|
this.moduleAnimationStates = [];
|
|
}
|
|
}
|
|
|
|
private setModules() {
|
|
this.modules = this.svgModuleProvider.getSvgModules(this.keyboardLayout);
|
|
this.separator = this.svgModuleProvider.getSvgSeparator();
|
|
this.separatorStyle = this.sanitizer.bypassSecurityTrustStyle(this.separator.style);
|
|
}
|
|
}
|