@pilotlab/lux-tools
Version:
A luxurious user experience framework, developed by your friends at Pilot.
46 lines • 2.04 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const is_1 = require("@pilotlab/is");
const signals_1 = require("@pilotlab/signals");
const rangeScale_1 = require("./rangeScale");
const rangeScaleBase_1 = require("./rangeScaleBase");
class RangeScaleManager extends rangeScaleBase_1.default {
constructor(inputMin = 0, inputMax = 1, ease) {
super(inputMin, inputMax, ease);
this._outputRanges = new Map();
this.updated = new signals_1.Signal();
}
get outputRanges() { return this._outputRanges; }
addOutputRange(name, outputMin, outputMax) {
let interpolatorValue = new rangeScale_1.default(this.p_inputMin, this.p_inputMax, outputMin, outputMax, this.p_ease);
this._outputRanges.set(name, interpolatorValue);
return interpolatorValue;
}
update(inputValue, isValueNormalized = false) {
if (isValueNormalized)
inputValue = this.unnormalizeInput(inputValue, false);
if (inputValue === this.p_lastInputRaw)
return;
this.p_lastInputRaw = inputValue;
this.p_lastInputNormalized = this.normalizeInput(inputValue);
this.p_checkInputPreviousRaw(inputValue);
this._outputRanges.forEach((scalerValues, name) => {
scalerValues.output(inputValue, false, false, false, false);
return true;
});
this.updated.dispatch(this.progress);
}
output(name, isConstrain = true, isNormalizeReturnValue = false, isInvertReturnValue = false) {
let scaler = this._outputRanges.get(name);
if (is_1.default.empty(scaler))
return null;
let returnValue = scaler.normalizeOutput(scaler.value, isConstrain, isInvertReturnValue);
if (isNormalizeReturnValue)
return returnValue;
else
return scaler.unnormalizeOutput(returnValue, false, false);
}
}
exports.RangeScaleManager = RangeScaleManager;
exports.default = RangeScaleManager;
//# sourceMappingURL=rangeScaleManager.js.map