@pilotlab/lux-attributes
Version:
A luxurious user experience framework, developed by your friends at Pilot.
114 lines • 5.38 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 (start, target, durationSpeed, ease, repeatCount, animationKey) {
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(target.r - start.r);
var diffG = Math.abs(target.g - start.g);
var diffB = Math.abs(target.b - start.b);
var diffA = Math.abs(target.a - start.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.Animation([
new lux_animation_1.AnimationValue(start.r, target.r),
new lux_animation_1.AnimationValue(start.g, target.g),
new lux_animation_1.AnimationValue(start.b, target.b),
new lux_animation_1.AnimationValue(start.a, target.a)
], duration, ease, repeatCount, animationKey);
animation.ticked.listen(function () {
start.r = animation.values[0].current;
start.g = animation.values[1].current;
start.b = animation.values[2].current;
start.a = animation.values[3].current;
});
lux_animation_1.Animation.goAnimation(animation);
return animation;
};
Types.goPoint = function (start, target, durationSpeed, ease, repeatCount, animationKey) {
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 diffX = Math.abs(target.x - start.x);
var diffY = Math.abs(target.y - start.y);
var diffZ = Math.abs(target.z - start.z);
var diff = (diffX > diffZ ? ((diffX > diffY ? diffX : diffY)) : ((diffZ > diffY ? diffZ : diffY)));
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.Animation([
new lux_animation_1.AnimationValue(start.x, target.x),
new lux_animation_1.AnimationValue(start.y, target.y),
new lux_animation_1.AnimationValue(start.z, target.z),
], duration, ease, repeatCount, animationKey);
animation.ticked.listen(function () {
start.x = animation.values[0].current;
start.y = animation.values[1].current;
start.z = animation.values[2].current;
});
lux_animation_1.Animation.goAnimation(animation);
return animation;
};
return Types;
}());
exports.Types = Types;
exports.default = Types;
//# sourceMappingURL=types.js.map