mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-12 16:57:26 +00:00
Refactor preprocessors module
This commit is contained in:
@@ -1,18 +1,10 @@
|
||||
import { h, Component } from 'preact';
|
||||
import { bind } from '../../lib/util';
|
||||
// import * as styles from './styles.scss';
|
||||
import { bind, inputFieldValueAsNumber } from '../../lib/util';
|
||||
import { QuantizeOptions } from './quantizer';
|
||||
|
||||
type Props = {
|
||||
options: QuantizeOptions,
|
||||
onChange(newOptions: QuantizeOptions): void,
|
||||
};
|
||||
|
||||
/**
|
||||
* @param field An HTMLInputElement, but the casting is done here to tidy up onChange.
|
||||
*/
|
||||
function fieldValueAsNumber(field: any): number {
|
||||
return Number((field as HTMLInputElement).value);
|
||||
interface Props {
|
||||
options: QuantizeOptions;
|
||||
onChange(newOptions: QuantizeOptions): void;
|
||||
}
|
||||
|
||||
export default class QuantizerOptions extends Component<Props, {}> {
|
||||
@@ -21,8 +13,8 @@ export default class QuantizerOptions extends Component<Props, {}> {
|
||||
const form = (event.currentTarget as HTMLInputElement).closest('form') as HTMLFormElement;
|
||||
|
||||
const options: QuantizeOptions = {
|
||||
maxNumColors: fieldValueAsNumber(form.maxNumColors),
|
||||
dither: fieldValueAsNumber(form.dither),
|
||||
maxNumColors: inputFieldValueAsNumber(form.maxNumColors),
|
||||
dither: inputFieldValueAsNumber(form.dither),
|
||||
};
|
||||
this.props.onChange(options);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user