@extjs/sencha-cmd-linux-32
Version:
Productivity and performance optimization tool for building applications with Sencha Ext JS and Sencha Touch.
99 lines (81 loc) • 3.9 kB
JavaScript
;
var Fashion = require('../export/Base.js');
var Literal = require('../export/type/Literal.js');
var Color = require('../export/type/Color.js');
var Numeric = require('../export/type/Numeric.js');
module.exports = {
init(runtime) {
runtime.register({
alpha: function (color) {
if (color && color.$isFashionNumber) {
return new Literal('alpha(' + color.toString() + ')');
}
color = Array.isArray(color) ? color[0] : color;
if (color && color.$isFashionLiteral) {
return color;
}
if (color.type !== 'hsla' && color.type !== 'rgba') {
Fashion.raise(color + ' is not a color for \'alpha\'');
}
return Color.component(color, 'alpha');
},
opacity: function (color) {
if (color && color.$isFashionNumber) {
return new Literal('opacity(' + color.toString() + ')');
}
color = Array.isArray(color) ? color[0] : color;
if (color && color.$isFashionLiteral) {
return color;
}
if (color.type !== 'hsla' && color.type !== 'rgba') {
Fashion.raise(color + ' is not a color for \'opacity\'');
}
return Color.component(color, 'alpha');
},
opacify: function (color, amount) {
if (color.type !== 'hsla' && color.type !== 'rgba') {
Fashion.raise(color + ' is not a color for \'opacify\'');
}
if (amount.type !== 'number') {
Fashion.raise(amount + ' is not a number for \'opacify\'');
}
if (amount.unit == '%') {
if (amount.value !== Color.constrainPercentage(amount.value)) {
Fashion.raise('Amount ' + amount + ' must be between 0% and 100% for \'opacify\'');
}
amount = new Numeric(amount.value / 100);
} else if (amount.value !== Color.constrainAlpha(amount.value)) {
Fashion.raise('Amount ' + amount + ' must be between 0 and 1 for \'opacify\'');
}
var rgba = color.getRGBA().clone();
rgba.a = Math.min(((rgba.a * 100) + (amount.value * 100)) / 100, 1);
return rgba;
},
transparentize: function (color, amount) {
if (color.type !== 'hsla' && color.type !== 'rgba') {
Fashion.raise(color + ' is not a color for \'transparentize\'');
}
if (amount.type !== 'number') {
Fashion.raise(amount + ' is not a number for \'transparentize\'');
}
if (amount.unit == '%') {
if (amount.value !== Color.constrainPercentage(amount.value)) {
Fashion.raise('Amount ' + amount + ' must be between 0% and 100% for \'transparentize\'');
}
amount = new Numeric(amount.value / 100);
} else if (amount.value !== Color.constrainAlpha(amount.value)) {
Fashion.raise('Amount ' + amount + ' must be between 0 and 1 for \'transparentize\'');
}
var rgba = color.getRGBA().clone();
rgba.a = Math.max(((rgba.a * 100) - (amount.value * 100)) / 100, 0);
return rgba;
},
fade_in: function (color, amount) {
return this.opacify(color, amount);
},
fade_out: function (color, amount) {
return this.transparentize(color, amount);
}
});
}
};