mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-15 01:59:57 +00:00
Ensure that mins can't be greater than maxs
This commit is contained in:
@@ -82,9 +82,37 @@ export default class AVIFEncoderOptions extends Component<Props, State> {
|
|||||||
'checked' in formEl ? formEl.checked : !!formEl.value :
|
'checked' in formEl ? formEl.checked : !!formEl.value :
|
||||||
Number(formEl.value);
|
Number(formEl.value);
|
||||||
|
|
||||||
|
const newState: Partial<State> = {
|
||||||
|
[prop]: newVal,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Ensure that min cannot be greater than max
|
||||||
|
switch (prop) {
|
||||||
|
case 'maxQuality':
|
||||||
|
if (newVal < this.state.minQuality) {
|
||||||
|
newState.minQuality = newVal as number;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'minQuality':
|
||||||
|
if (newVal > this.state.maxQuality) {
|
||||||
|
newState.maxQuality = newVal as number;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'maxAlphaQuality':
|
||||||
|
if (newVal < this.state.minAlphaQuality) {
|
||||||
|
newState.minAlphaQuality = newVal as number;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'minAlphaQuality':
|
||||||
|
if (newVal > this.state.maxAlphaQuality) {
|
||||||
|
newState.maxAlphaQuality = newVal as number;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
const optionState = {
|
const optionState = {
|
||||||
...this.state,
|
...this.state,
|
||||||
[prop]: newVal,
|
...newState,
|
||||||
};
|
};
|
||||||
|
|
||||||
const maxQuantizer = optionState.lossless ? 0 : (maxQuant - optionState.minQuality);
|
const maxQuantizer = optionState.lossless ? 0 : (maxQuant - optionState.minQuality);
|
||||||
@@ -107,8 +135,8 @@ export default class AVIFEncoderOptions extends Component<Props, State> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.setState(
|
this.setState(
|
||||||
// Type cheating: I'm assuming that prop is present and is the correct type.
|
// It isn't clear to me why I have to cast this :)
|
||||||
{ [prop]: newVal, options: newOptions } as unknown as State,
|
newState as State,
|
||||||
);
|
);
|
||||||
|
|
||||||
this.props.onChange(newOptions);
|
this.props.onChange(newOptions);
|
||||||
|
|||||||
Reference in New Issue
Block a user