@pilotlab/lux-types
Version:
A luxurious user experience framework, developed by your friends at Pilot.
82 lines • 3.79 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var lux_is_1 = require("@pilotlab/lux-is");
var lux_animation_1 = require("@pilotlab/lux-animation");
var Types = (function () {
function Types() {
}
Object.defineProperty(Types, "tolerance", {
get: function () { return 0.0001; },
enumerable: true,
configurable: true
});
Types.isLuxType = function (instance) {
return 'key' in instance && 'value' in instance && 'dataType' in instance;
};
Types.isColor = function (instance) {
return this.isLuxType(instance) &&
'r' in instance &&
'g' in instance &&
'b' in instance &&
'a' in instance;
};
Types.isCoordinateSystem = function (instance) {
return this.isPoint(instance) && 'zMax' in instance;
};
Types.isPoint = function (instance) {
return this.isLuxType(instance) && 'x' in instance && 'y' in instance;
};
Types.isPoint3D = function (instance) {
return this.isPoint(instance) && 'z' in instance;
};
Types.isMatrix2 = function (instance) { return false; };
Types.isMatrix3 = function (instance) { return false; };
Types.isMatrix4 = function (instance) { return false; };
Types.isQuaternion = function (instance) { return false; };
Types.isRectangle = function (instance) {
return this.isPoint(instance) && this.isSize(instance);
};
Types.isSize = function (instance) {
return this.isLuxType(instance) && 'width' in instance && 'height' in instance;
};
Types.isVector = function (instance) {
return this.isPoint3D(instance) && 'w' in instance;
};
Types.goColor = function (startColor, targetColor, durationSpeed, ease, repeatCount, animationID) {
if (repeatCount === void 0) { repeatCount = 0; }
var duration = 0;
if (lux_is_1.default.notEmpty(durationSpeed) && typeof durationSpeed === 'number' && durationSpeed >= 0) {
duration = durationSpeed;
}
else if (durationSpeed instanceof lux_animation_1.Speed && durationSpeed.type === lux_animation_1.SpeedType.DURATION) {
duration = durationSpeed.duration;
}
else {
var diffR = Math.abs(targetColor.r - startColor.r);
var diffG = Math.abs(targetColor.g - startColor.g);
var diffB = Math.abs(targetColor.b - startColor.b);
var diffA = Math.abs(targetColor.a - startColor.a);
var diff = (diffR > diffG ? ((diffR > diffB ? (diffR > diffA ? diffR : diffA) : (diffB > diffA ? diffB : diffA))) : ((diffG > diffB ? (diffG > diffA ? diffG : diffA) : (diffB > diffA ? diffB : diffA))));
duration = lux_animation_1.Animation.getDuration(durationSpeed, 0, diff);
}
if (lux_is_1.default.empty(ease))
ease = lux_animation_1.Animation.validateSpeed(durationSpeed).ease;
var animation = new lux_animation_1.AnimationMultiple([
new lux_animation_1.AnimationValue(startColor.r, targetColor.r),
new lux_animation_1.AnimationValue(startColor.g, targetColor.g),
new lux_animation_1.AnimationValue(startColor.b, targetColor.b),
new lux_animation_1.AnimationValue(startColor.a, targetColor.a)
], duration, ease, repeatCount, animationID);
animation.ticked.listen(function () {
startColor.r = animation.values[0].current;
startColor.g = animation.values[1].current;
startColor.b = animation.values[2].current;
});
lux_animation_1.Animation.goAnimation(animation);
return animation;
};
return Types;
}());
exports.Types = Types;
exports.default = Types;
//# sourceMappingURL=types.js.map