PageSourceSearch

https://arred.ru/wa-apps/shop/plugins/bdg/js/jquery.colorhelpers.js?6.3.0.1791159181

js arred.ru collected 2026-10-05 00:13:34 UTC 6,575 bytes, 186 lines download raw bytes

vendor: 6,575 bytes, lines 1-186
1/* Plugin for jQuery for working with colors.
2 * 
3 * Version 1.1.
4 * 
5 * Inspiration from jQuery color animation plugin by John Resig.
6 *
7 * Released under the MIT license by Ole Laursen, October 2009.
8 *
9 * Examples:
10 *
11 *   $.color.parse("#fff").scale('rgb', 0.25).add('a', -0.5).toString()
12 *   var c = $.color.extract($("#mydiv"), 'background-color');
13 *   console.log(c.r, c.g, c.b, c.a);
14 *   $.color.make(100, 50, 25, 0.4).toString() // returns "rgba(100,50,25,0.4)"
15 *
16 * Note that .scale() and .add() return the same modified object
17 * instead of making a new one.
18 *
19 * V. 1.1: Fix error handling so e.g. parsing an empty string does
20 * produce a color rather than just crashing.
21 */ 
22
23(function($) {
24    $.color = {};
25
26    // construct color object with some convenient chainable helpers
27    $.color.make = function (r, g, b, a) {
28        var o = {};
29        o.r = r || 0;
30        o.g = g || 0;
31        o.b = b || 0;
32        o.a = a != null ? a : 1;
33
34        o.add = function (c, d) {
35            for (var i = 0; i < c.length; ++i)
36                o[c.charAt(i)] += d;
37            return o.normalize();
38        };
39        
40        o.scale = function (c, f) {
41            for (var i = 0; i < c.length; ++i)
42                o[c.charAt(i)] *= f;
43            return o.normalize();
44        };
45        
46        o.toString = function (hex) {
47            if ( hex ){
48                var c = {r:o.r.toString(16),g:o.g.toString(16),b:o.b.toString(16)},
49                    code = '#';
50                for ( p in c )
51                    code += c[p].length == 2 ? c[p] : '0'+c[p];
52                return code;
53            }
54            if (o.a >= 1.0) {
55                return "rgb("+[o.r, o.g, o.b].join(",")+")";
56            } else {
57                return "rgba("+[o.r, o.g, o.b, o.a].join(",")+")";
58            }
59        };
60
61        o.normalize = function () {
62            function clamp(min, value, max) {
63                return value < min ? min: (value > max ? max: value);
64            }
65            
66            o.r = clamp(0, parseInt(o.r), 255);
67            o.g = clamp(0, parseInt(o.g), 255);
68            o.b = clamp(0, parseInt(o.b), 255);
69            o.a = clamp(0, o.a, 1);
70            return o;
71        };
72
73        o.clone = function () {
74            return $.color.make(o.r, o.b, o.g, o.a);
75        };
76
77        return o.normalize();
78    }
79
80    // extract CSS color property from element, going up in the DOM
81    // if it's "transparent"
82    $.color.extract = function (elem, css) {
83        var c;
84        do {
85            c = elem.css(css).toLowerCase();
86            // keep going until we find an element that has color, or
87            // we hit the body
88            if (c != '' && c != 'transparent')
89                break;
90            elem = elem.parent();
91        } while (!$.nodeName(elem.get(0), "body"));
92
93        // catch Safari's way of signalling transparent
94        if (c == "rgba(0, 0, 0, 0)")
95            c = "transparent";
96        
97        return $.color.parse(c);
98    }
99    
100    // parse CSS color string (like "rgb(10, 32, 43)" or "#fff"),
101    // returns color object, if parsing failed, you get black (0, 0,
102    // 0) out
103    $.color.parse = function (str) {
104        var res, m = $.color.make;
105
106        // Look for rgb(num,num,num)
107        if (res = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(str))
108            return m(parseInt(res[1], 10), parseInt(res[2], 10), parseInt(res[3], 10));
109        
110        // Look for rgba(num,num,num,num)
111        if (res = /rgba\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]+(?:\.[0-9]+)?)\s*\)/.exec(str))
112            return m(parseInt(res[1], 10), parseInt(res[2], 10), parseInt(res[3], 10), parseFloat(res[4]));
113            
114        // Look for rgb(num%,num%,num%)
115        if (res = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(str))
116            return m(parseFloat(res[1])*2.55, parseFloat(res[2])*2.55, parseFloat(res[3])*2.55);
117
118        // Look for rgba(num%,num%,num%,num)
119        if (res = /rgba\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\s*\)/.exec(str))
120            return m(parseFloat(res[1])*2.55, parseFloat(res[2])*2.55, parseFloat(res[3])*2.55, parseFloat(res[4]));
121        
122        // Look for #a0b1c2
123        if (res = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(str))
124            return m(parseInt(res[1], 16), parseInt(res[2], 16), parseInt(res[3], 16));
125
126        // Look for #fff
127        if (res = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(str))
128            return m(parseInt(res[1]+res[1], 16), parseInt(res[2]+res[2], 16), parseInt(res[3]+res[3], 16));
129
130        // Otherwise, we're most likely dealing with a named color
131        var name = $.trim(str).toLowerCase();
132        if (name == "transparent")
133            return m(255, 255, 255, 0);
134        else {
135            // default to black
136            res = lookupColors[name] || [0, 0, 0];
137            return m(res[0], res[1], res[2]);
138        }
139    }
140    
141    var lookupColors = {
142        aqua:[0,255,255],
143        azure:[240,255,255],
144        beige:[245,245,220],
145        black:[0,0,0],
146        blue:[0,0,255],
147        brown:[165,42,42],
148        cyan:[0,255,255],
149        darkblue:[0,0,139],
150        darkcyan:[0,139,139],
151        darkgrey:[169,169,169],
152        darkgreen:[0,100,0],
153        darkkhaki:[189,183,107],
154        darkmagenta:[139,0,139],
155        darkolivegreen:[85,107,47],
156        darkorange:[255,140,0],
157        darkorchid:[153,50,204],
158        darkred:[139,0,0],
159        darksalmon:[233,150,122],
160        darkviolet:[148,0,211],
161        fuchsia:[255,0,255],
162        gold:[255,215,0],
163        green:[0,128,0],
164        indigo:[75,0,130],
165        khaki:[240,230,140],
166        lightblue:[173,216,230],
167        lightcyan:[224,255,255],
168        lightgreen:[144,238,144],
169        lightgrey:[211,211,211],
170        lightpink:[255,182,193],
171        lightyellow:[255,255,224],
172        lime:[0,255,0],
173        magenta:[255,0,255],
174        maroon:[128,0,0],
175        navy:[0,0,128],
176        olive:[128,128,0],
177        orange:[255,165,0],
178        pink:[255,192,203],
179        purple:[128,0,128],
180        violet:[128,0,128],
181        red:[255,0,0],
182        silver:[192,192,192],
183        white:[255,255,255],
184        yellow:[255,255,0]
185    };
186})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.