mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-12 08:47:31 +00:00
Merge pull request #813 from samal-rasmussen/keyboard-shortcuts
This commit is contained in:
@@ -68,6 +68,8 @@ export default class TwoUp extends HTMLElement {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
window.addEventListener('keydown', event => this._onKeyDown(event));
|
||||||
}
|
}
|
||||||
|
|
||||||
connectedCallback() {
|
connectedCallback() {
|
||||||
@@ -94,6 +96,29 @@ export default class TwoUp extends HTMLElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// KeyDown event handler
|
||||||
|
private _onKeyDown(event: KeyboardEvent) {
|
||||||
|
if (event.code === 'Digit1' || event.code === 'Numpad1') {
|
||||||
|
this._position = 0;
|
||||||
|
this._relativePosition = 0;
|
||||||
|
this._setPosition();
|
||||||
|
} else if (event.code === 'Digit2' || event.code === 'Numpad2') {
|
||||||
|
const dimensionAxis = this.orientation === 'vertical' ? 'height' : 'width';
|
||||||
|
const bounds = this.getBoundingClientRect();
|
||||||
|
|
||||||
|
this._position = bounds[dimensionAxis] / 2;
|
||||||
|
this._relativePosition = (this._position / bounds[dimensionAxis]) / 2;
|
||||||
|
this._setPosition();
|
||||||
|
} else if (event.code === 'Digit3' || event.code === 'Numpad3') {
|
||||||
|
const dimensionAxis = this.orientation === 'vertical' ? 'height' : 'width';
|
||||||
|
const bounds = this.getBoundingClientRect();
|
||||||
|
|
||||||
|
this._position = bounds[dimensionAxis];
|
||||||
|
this._relativePosition = this._position / bounds[dimensionAxis];
|
||||||
|
this._setPosition();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private _resetPosition() {
|
private _resetPosition() {
|
||||||
// Set the initial position of the handle.
|
// Set the initial position of the handle.
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user