UNPKG

@extjs/sencha-cmd-linux-32

Version:

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

220 lines (194 loc) 9.28 kB
"use strict"; var Fashion = require('../export/Base.js'); var Color = require('../export/type/Color.js'); var ColorRGBA = require('../export/type/ColorRGBA.js'); var ColorHSLA = require('../export/type/ColorHSLA.js'); var Numeric = require('../export/type/Numeric.js'); var Literal = require('../export/type/Literal.js'); module.exports = { init(runtime) { runtime.register({ hsla: function (hue, saturation, lightness, alpha) { if (arguments.length != 4) { Fashion.raise('Wrong number of arguments (' + arguments.length + ' for 4) for \'hsla\''); } if (!hue.$isFashionNumber) { Fashion.raise(hue + ' is not a number for \'hsla\''); } if (!saturation.$isFashionNumber) { Fashion.raise(saturation + ' is not a number for \'hsla\''); } if (!lightness.$isFashionNumber) { Fashion.raise(lightness + ' is not a number for \'hsla\''); } if (!alpha.$isFashionNumber) { Fashion.raise(alpha + ' is not a number for \'hsla\''); } if (saturation.value !== Color.constrainPercentage(saturation.value)) { Fashion.raise('Saturation ' + saturation + ' must be between 0% and 100% for \'hsla\''); } if (lightness.value !== Color.constrainPercentage(lightness.value)) { Fashion.raise('Lightness ' + lightness + ' must be between 0% and 100% for \'hsla\''); } if (alpha.value !== Color.constrainAlpha(alpha.value)) { Fashion.raise('Alpha channel ' + alpha + ' must be between 0 and 1 for \'hsla\''); } return new ColorHSLA(hue.value, saturation.value, lightness.value, alpha.value); }, hsl: function (hue, saturation, lightness) { var len = arguments.length; if (len != 3) { Fashion.raise('Wrong number of arguments (' + len + ' for 3) for \'hsl\''); } return this.hsla(hue, saturation, lightness, new Numeric(1)); }, hue: 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 \'hue\''); } return Color.component(color, 'hue'); }, saturation: 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 \'saturation\''); } return Color.component(color, 'saturation'); }, lightness: 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 \'lightness\''); } return Color.component(color, 'lightness'); }, adjust_hue: function (color, degrees) { if (color == null || color.$isFashionNull) { return Literal.Null; } if (color.type !== 'hsla' && color.type !== 'rgba') { Fashion.raise(color + ' is not a color for \'adjust-hue\''); } if (degrees.type !== 'number') { Fashion.raise(degrees + ' is not a number for \'adjust-hue\''); } //if (degrees.value < -360 || degrees.value > 360) { // Fashion.raise('Amount ' + degrees + ' must be between 0deg and 360deg for \'adjust-hue\''); //} return Color.adjust(color, 'hue', degrees); }, lighten: function (color, amount) { if (color == null || color.$isFashionNull) { return Literal.Null; } if (color.type !== 'hsla' && color.type !== 'rgba') { Fashion.raise(color + ' is not a color for \'lighten\''); } if (amount.type !== 'number') { Fashion.raise(amount + ' is not a number for \'lighten\''); } if (amount.value !== Color.constrainPercentage(amount.value)) { Fashion.raise('Amount ' + amount + ' must be between 0% and 100% for \'lighten\''); } return Color.adjust(color, 'lightness', amount); }, darken: function (color, amount) { if (color == null || color.$isFashionNull) { return Literal.Null; } if (color.type !== 'hsla' && color.type !== 'rgba') { Fashion.raise(color + ' is not a color for \'darken\''); } if (amount.type !== 'number') { Fashion.raise(amount + ' is not a number for \'darken\''); } if (amount.value !== Color.constrainPercentage(amount.value)) { Fashion.raise('Amount ' + amount + ' must be between 0% and 100% for \'darken\''); } amount = amount.clone(); amount.value *= -1; return Color.adjust(color, 'lightness', amount); }, saturate: function (color, amount) { if (color == null || color.$isFashionNull) { return Literal.Null; } if (!amount) { return new Literal('saturate(' + color.toString() + ')'); } if (color.type !== 'hsla' && color.type !== 'rgba') { Fashion.raise(color + ' is not a color for \'saturate\''); } if (amount.type !== 'number') { Fashion.raise(amount + ' is not a number for \'saturate\''); } if (amount.value !== Color.constrainPercentage(amount.value)) { Fashion.raise('Amount ' + amount + ' must be between 0% and 100% for \'saturate\''); } return Color.adjust(color, 'saturation', amount); }, desaturate: function (color, amount) { if (color == null || color.$isFashionNull) { return Literal.Null; } if (color.type !== 'hsla' && color.type !== 'rgba') { Fashion.raise(color + ' is not a color for \'desaturate\''); } if (amount.type !== 'number') { Fashion.raise(amount + ' is not a number for \'desaturate\''); } if (amount.value !== Color.constrainPercentage(amount.value)) { Fashion.raise('Amount ' + amount + ' must be between 0% and 100% for \'desaturate\''); } amount.value *= -1; return Color.adjust(color, 'saturation', amount); }, grayscale: function (color) { if (color == null || color.$isFashionNull) { return Literal.Null; } if (color.$isFashionNumber) { return new Literal('grayscale(' + color.toString() + ')'); } if (color.type !== 'hsla' && color.type !== 'rgba') { Fashion.raise(color + ' is not a color for \'grayscale\''); } return this.desaturate(color, new Numeric(100, '%')); }, complement: 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 \'complement\''); } return this.adjust_hue(color, new Numeric(180, 'deg')); }, invert: function (color) { if (color == null || color.$isFashionNull) { return Literal.Null; } if (color.$isFashionNumber) { return new Literal('invert(' + color.toString() + ')'); } if (color.type !== 'hsla' && color.type !== 'rgba') { Fashion.raise(color + ' is not a color for \'invert\''); } color = color.getRGBA(); return new ColorRGBA( 255 - color.r, 255 - color.g, 255 - color.b, color.a ); } }); } }