const MinusSignWidthsForDigits = {
3: 6,
4: 5,
5: 6,
6: 5
};
const WidthsForDigits = {
3: 27,
4: 35,
5: 46,
6: 54
}
class TimeLabel extends LayoutNode
{
constructor(type)
{
super(`<div role="text" class="time-label"></div>`);
this._type = type;
this.setValueWithNumberOfDigits(0, 4);
}
// Public
get value()
{
return this._value;
}
setValueWithNumberOfDigits(value, numberOfDigits)
{
this._value = value;
this._numberOfDigits = numberOfDigits;
this.width = WidthsForDigits[this._numberOfDigits] + (this._type === TimeLabel.Types.Remaining && !isNaN(this._value) ? MinusSignWidthsForDigits[this._numberOfDigits] : 0);
this.markDirtyProperty("value");
}
// Protected
commitProperty(propertyName)
{
if (propertyName === "value") {
this.element.textContent = this._formattedTime();
const timeAsString = formattedStringForDuration(this.value);
const ariaLabel = (this._type === TimeLabel.Types.Remaining) ? UIString("Remaining") : UIString("Elapsed");
this.element.setAttribute("aria-label", `${ariaLabel}: ${timeAsString}`);
if (this.parent instanceof TimeControl)
this.parent.updateScrubberLabel();
}
else
super.commitProperty(propertyName);
}
// Private
_formattedTime()
{
if (isNaN(this._value))
return "--:--";
const time = formatTimeByUnit(this._value);
let timeComponents;
if (this._numberOfDigits == 3)
timeComponents = [time.minutes, doubleDigits(time.seconds)];
else if (this._numberOfDigits == 4)
timeComponents = [doubleDigits(time.minutes), doubleDigits(time.seconds)];
else if (this._numberOfDigits == 5)
timeComponents = [time.hours, doubleDigits(time.minutes), doubleDigits(time.seconds)];
else if (this._numberOfDigits == 6)
timeComponents = [doubleDigits(time.hours), doubleDigits(time.minutes), doubleDigits(time.seconds)];
return (this._type === TimeLabel.Types.Remaining ? "-" : "") + timeComponents.join(":");
}
}
function doubleDigits(x)
{
if (x < 10)
return `0${x}`;
return `${x}`;
}
TimeLabel.Types = {
Elapsed: 0,
Remaining: 1
};