UNPKG

@extjs/sencha-cmd-linux-32

Version:

Productivity and performance optimization tool for building applications with Sencha Ext JS and Sencha Touch.

166 lines (143 loc) 7.03 kB
"use strict"; var Fashion = require('../export/Base.js'); var Literal = require('../export/type/Literal.js'); var Color = require('../export/type/Color.js'); var ColorRGBA = require('../export/type/ColorRGBA.js'); var Numeric = require('../export/type/Numeric.js'); module.exports = { init(runtime) { runtime.register({ rgba: function (red, green, blue, alpha, color) { var colorInst; if (!!red && !!color) { Fashion.raise("Unsupported arguments to RGBA"); } if (color && !red) { if (color.$isFashionColor) { colorInst = color; } else { Fashion.raise("Unsupported arguments to RGBA"); } } else if (red && red.$isFashionColor) { colorInst = red; } if (colorInst) { alpha = green || alpha; colorInst = colorInst.getRGBA(); red = new Numeric(colorInst.r); green = new Numeric(colorInst.g); blue = new Numeric(colorInst.b); } if (!red || !red.$isFashionNumber) { if (red == null || red.$isFashionNull) { return Literal.Null; } Fashion.raise(red + ' is not a number for \'rgba\' red'); } if (!green || !green.$isFashionNumber) { if (green == null || green.$isFashionNull) { return Literal.Null; } Fashion.raise(green + ' is not a number for \'rgba\' green'); } if (!blue || !blue.$isFashionNumber) { if (blue == null || blue.$isFashionNull) { return Literal.Null; } Fashion.raise(blue + ' is not a number for \'rgba\' blue'); } if (!alpha || !alpha.$isFashionNumber) { if (alpha == null || alpha.$isFashionNull) { return Literal.Null; } Fashion.raise(alpha + ' is not a number for \'rgba\' alpha'); } if (red.unit == '%') { red = new Numeric(Color.constrainPercentage(red.value) / 100 * 255); } else if (red.value !== Color.constrainChannel(red.value)) { Fashion.raise('Color value ' + red + ' must be between 0 and 255 inclusive for \'rgba\''); } if (green.unit == '%') { green = new Numeric(Color.constrainPercentage(green.value) / 100 * 255); } else if (green.value !== Color.constrainChannel(green.value)) { Fashion.raise('Color value ' + green + ' must be between 0 and 255 inclusive for \'rgba\''); } if (blue.unit == '%') { blue = new Numeric(Color.constrainPercentage(blue.value) / 100 * 255); } else if (blue.value !== Color.constrainChannel(blue.value)) { Fashion.raise('Color value ' + blue + ' must be between 0 and 255 inclusive for \'rgba\''); } if (alpha.unit == '%') { alpha = new Numeric(Color.constrainPercentage(alpha.value) / 100); } else if (alpha.value !== Color.constrainAlpha(alpha.value)) { Fashion.raise('Alpha channel ' + alpha + ' must be between 0 and 1 inclusive for \'rgba\''); } return new ColorRGBA(red.value, green.value, blue.value, alpha.value); }, rgb: function (red, green, blue, color) { return this.rgba(red, green, blue, new Numeric(1), color); }, red: function (color) { if (color == null || color.$isFashionNull) { return Literal.Null; } if (color.type !== 'hsla' && color.type !== 'rgba') { Fashion.raise(color + ' is not a color for \'red\''); } return Color.component(color, 'red'); }, green: function (color) { if (color == null || color.$isFashionNull) { return Literal.Null; } if (color.type !== 'hsla' && color.type !== 'rgba') { Fashion.raise(color + ' is not a color for \'green\''); } return Color.component(color, 'green'); }, blue: function (color) { if (color == null || color.$isFashionNull) { return Literal.Null; } if (color.type !== 'hsla' && color.type !== 'rgba') { Fashion.raise(color + ' is not a color for \'blue\''); } return Color.component(color, 'blue'); }, mix: function (color_1, color_2, weight) { if (color_1 == null || color_1.$isFashionNull) { return Literal.Null; } if (color_2 == null || color_2.$isFashionNull) { return Literal.Null; } weight = (weight !== undefined) ? weight : new Numeric(50, '%'); if (color_1.type !== 'hsla' && color_1.type !== 'rgba') { Fashion.raise('arg 1 ' + color_1 + ' is not a color for \'mix\''); } if (color_2.type !== 'hsla' && color_2.type !== 'rgba') { Fashion.raise('arg 2 ' + color_2 + ' is not a color for \'mix\''); } if (weight.type !== 'number') { Fashion.raise('arg 3 ' + weight + ' is not a number for \'mix\''); } if (weight.value !== Color.constrainPercentage(weight.value)) { Fashion.raise('Weight ' + weight + ' must be between 0% and 100% for \'mix\''); } color_1 = color_1.getRGBA(); color_2 = color_2.getRGBA(); weight = weight.value / 100; var factor = (weight * 2) - 1, alpha = color_1.a - color_2.a, weight1 = (((factor * alpha == -1) ? factor : (factor + alpha) / (1 + factor * alpha)) + 1) / 2, weight2 = 1 - weight1; return new ColorRGBA( (weight1 * color_1.r) + (weight2 * color_2.r), (weight1 * color_1.g) + (weight2 * color_2.g), (weight1 * color_1.b) + (weight2 * color_2.b), (weight * color_1.a) + ((1 - weight) * color_2.a) ); } }); } };