mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-18 11:39:08 +00:00
Get precision from step by default
This commit is contained in:
@@ -6,6 +6,11 @@ const UPDATE_EVENTS = ['input', 'change'];
|
|||||||
const REFLECTED_PROPERTIES = ['name', 'min', 'max', 'step', 'value', 'disabled'];
|
const REFLECTED_PROPERTIES = ['name', 'min', 'max', 'step', 'value', 'disabled'];
|
||||||
const REFLECTED_ATTRIBUTES = ['name', 'min', 'max', 'step', 'value', 'disabled'];
|
const REFLECTED_ATTRIBUTES = ['name', 'min', 'max', 'step', 'value', 'disabled'];
|
||||||
|
|
||||||
|
function getPrescision(value: string): number {
|
||||||
|
const afterDecimal = value.split('.')[1];
|
||||||
|
return afterDecimal ? afterDecimal.length : 0;
|
||||||
|
}
|
||||||
|
|
||||||
class RangeInputElement extends HTMLElement {
|
class RangeInputElement extends HTMLElement {
|
||||||
private _input: HTMLInputElement;
|
private _input: HTMLInputElement;
|
||||||
private _valueDisplay?: HTMLDivElement;
|
private _valueDisplay?: HTMLDivElement;
|
||||||
@@ -73,9 +78,9 @@ class RangeInputElement extends HTMLElement {
|
|||||||
const value = Number(this.value) || 0;
|
const value = Number(this.value) || 0;
|
||||||
const min = Number(this.min) || 0;
|
const min = Number(this.min) || 0;
|
||||||
const max = Number(this.max) || 100;
|
const max = Number(this.max) || 100;
|
||||||
const labelPrecision = Number(this.labelPrecision) || 0;
|
const labelPrecision = Number(this.labelPrecision) || getPrescision(this.step) || 0;
|
||||||
const percent = 100 * (value - min) / (max - min);
|
const percent = 100 * (value - min) / (max - min);
|
||||||
const displayValue = labelPrecision ? value.toPrecision(labelPrecision) :
|
const displayValue = labelPrecision ? value.toFixed(labelPrecision) :
|
||||||
Math.round(value).toString();
|
Math.round(value).toString();
|
||||||
|
|
||||||
this._valueDisplay!.textContent = displayValue;
|
this._valueDisplay!.textContent = displayValue;
|
||||||
|
|||||||
Reference in New Issue
Block a user