PageSourceSearch

https://americanafilmfest.com/wp-content/plugins/rdv-timetable/packages/color-mix/colormix-2.0.0.js?ver=6.9.9

js americanafilmfest.com collected 2026-10-02 12:18:28 UTC 17,092 bytes, 458 lines download raw bytes

1
2/*!
3 * ColorMix JavaScript Library v2.0.0
4 * http://color-mix.it
5 *
6 * Copyright 2013 @ Florent SCHILDKNECHT
7 *
8 * Date: 2014-03-29
9 */
10var ColorMix;
11
12ColorMix = (function() {
13  "use strict";
14  var Color, ColorSpace, _gradient;
15  _gradient = [
16    {
17      reference: 0,
18      color: {
19        red: 0,
20        green: 0,
21        blue: 0
22      }
23    }, {
24      reference: 100,
25      color: {
26        red: 255,
27        green: 255,
28        blue: 255
29      }
30    }
31  ];
32  Color = function(R, G, B) {
33    this.red = 0;
34    this.green = 0;
35    this.blue = 0;
36    if (R !== void 0) {
37      if (G !== void 0 && B !== void 0) {
38        this.setRed(parseInt(R));
39        this.setGreen(parseInt(G));
40        this.setBlue(parseInt(B));
41      } else if (typeof R === 'string') {
42        this.fromHex(R);
43      }
44    }
45    return this;
46  };
47  ColorSpace = (function() {
48    return {
49      RGB: function(R, G, B) {
50        if (R === void 0 || G === void 0 || B === void 0) {
51          throw 'Invalid parameter(s) provided for "ColorMix.ColorSpace.RGB()"';
52        }
53        return {
54          'red': isNaN(parseInt(R)) ? 0 : parseInt(R),
55          'green': isNaN(parseInt(G)) ? 0 : parseInt(G),
56          'blue': isNaN(parseInt(B)) ? 0 : parseInt(B)
57        };
58      },
59      XYZ: function(X, Y, Z) {
60        if (X === void 0 || Y === void 0 || Z === void 0) {
61          throw 'Invalid parameter(s) provided for "ColorMix.ColorSpace.XYZ()"';
62        }
63        return {
64          'x': isNaN(parseFloat(X)) ? 0.0 : parseFloat(X),
65          'y': isNaN(parseFloat(Y)) ? 0.0 : parseFloat(Y),
66          'z': isNaN(parseFloat(Z)) ? 0.0 : parseFloat(Z)
67        };
68      },
69      HSL: function(H, S, L) {
70        if (H === void 0 || S === void 0 || L === void 0) {
71          throw 'Invalid parameter(s) provided for "ColorMix.ColorSpace.HSL()"';
72        }
73        return {
74          'hue': isNaN(parseInt(H)) ? 0.0 : parseInt(H),
75          'sat': isNaN(parseInt(S)) ? 0.0 : parseInt(S),
76          'lig': isNaN(parseInt(L)) ? 0.0 : parseInt(L)
77        };
78      },
79      Lab: function(L, a, b) {
80        if (L === void 0 || a === void 0 || b === void 0) {
81          throw 'Invalid parameter(s) provided for "ColorMix.ColorSpace.Lab()"';
82        }
83        return {
84          'L': isNaN(parseFloat(L)) ? 0.0 : parseFloat(L),
85          'a': isNaN(parseFloat(a)) ? 0.0 : parseFloat(a),
86          'b': isNaN(parseFloat(b)) ? 0.0 : parseFloat(b)
87        };
88      },
89      RGBtoXYZ: function(R, G, B) {
90        var RGB, blue, green, red;
91        if (R !== void 0 && G !== void 0 && B !== void 0) {
92          RGB = new this.RGB(R, G, B);
93        } else if (R !== void 0 && typeof R === 'object' && R.red !== void 0 && R.green !== void 0 && R.blue !== void 0) {
94          RGB = new this.RGB(R.red, R.green, R.blue);
95        } else {
96          throw 'Invalid parameter(s) provided for "ColorMix.ColorSpace.RGBtoXYZ()".';
97        }
98        red = parseFloat(RGB.red / 255);
99        green = parseFloat(RGB.green / 255);
100        blue = parseFloat(RGB.blue / 255);
101        red = 100 * (red > 0.04045 ? Math.pow((red + 0.055) / 1.055, 2.4) : red /= 12.92);
102        green = 100 * (green > 0.04045 ? Math.pow((green + 0.055) / 1.055, 2.4) : green /= 12.92);
103        blue = 100 * (blue > 0.04045 ? Math.pow((blue + 0.055) / 1.055, 2.4) : blue /= 12.92);
104        return new this.XYZ(red * 0.4124 + green * 0.3576 + blue * 0.1805, red * 0.2126 + green * 0.7152 + blue * 0.0722, red * 0.0193 + green * 0.1192 + blue * 0.9505);
105      },
106      XYZtoRGB: function(X, Y, Z) {
107        var XYZ, blue, green, red, x, y, z;
108        if (X !== void 0 && Y !== void 0 && Z !== void 0) {
109          XYZ = new this.XYZ(X, Y, Z);
110        } else if (X !== void 0 && typeof X === 'object' && X.x !== void 0 && X.y !== void 0 && X.z !== void 0) {
111          XYZ = new this.XYZ(X.x, X.y, X.z);
112        } else {
113          throw 'Invalid parameter(s) provided for "ColorMix.ColorSpace.XYZtoRGB()".';
114        }
115        x = XYZ.x / 100;
116        y = XYZ.y / 100;
117        z = XYZ.z / 100;
118        red = x * 3.2406 + y * -1.5372 + z * -0.4986;
119        green = x * -0.9689 + y * 1.8758 + z * 0.0415;
120        blue = x * 0.0557 + y * -0.2040 + z * 1.0570;
121        red = 255 * (red > 0.0031308 ? 1.055 * (Math.pow(red, 1 / 2.4)) - 0.055 : red *= 12.92);
122        green = 255 * (green > 0.0031308 ? 1.055 * (Math.pow(green, 1 / 2.4)) - 0.055 : green *= 12.92);
123        blue = 255 * (blue > 0.0031308 ? 1.055 * (Math.pow(blue, 1 / 2.4)) - 0.055 : blue *= 12.92);
124        return new this.RGB(Math.round(red), Math.round(green), Math.round(blue));
125      },
126      RGBtoHSL: function(R, G, B) {
127        var H, L, RGB, S, blue, d, green, max, min, red, _ref;
128        if (R !== void 0 && G !== void 0 && B !== void 0) {
129          RGB = new this.RGB(R, G, B);
130        } else if (R !== void 0 && typeof R === 'object' && R.red !== void 0 && R.green !== void 0 && R.blue !== void 0) {
131          RGB = new this.RGB(R.red, R.green, R.blue);
132        } else {
133          throw 'Invalid parameter(s) provided for "ColorMix.ColorSpace.RGBtoXYZ()".';
134        }
135        red = RGB.red / 255;
136        green = RGB.green / 255;
137        blue = RGB.blue / 255;
138        max = Math.max(red, green, blue);
139        min = Math.min(red, green, blue);
140        L = (max + min) / 2;
141        if (max === min) {
142          H = S = 0;
143        } else {
144          d = max - min;
145          if (L > 0.5) {
146            S = d / (2 - max - min);
147          } else {
148            S = d / (max + min);
149          }
150          switch (max) {
151            case 'red':
152              H = (green - blue) / d + ((_ref = green < blue) != null ? _ref : {
153                6: 0
154              });
155              break;
156            case 'green':
157              H = (blue - red) / d + 2;
158              break;
159            case 'blue':
160              H = (red - green) / d + 4;
161              break;
162          }
163          H /= 6;
164        }
165        return new this.HSL(Math.floor(H * 360), Math.floor(S * 100), Math.floor(L * 100));
166      },
167      XYZtoLab: function(X, Y, Z) {
168        var XYZ, x, y, z;
169        if (X !== void 0 && Y !== void 0 && Z !== void 0) {
170          XYZ = new this.XYZ(X, Y, Z);
171        } else if (X !== void 0 && typeof X === 'object' && X.x !== void 0 && X.y !== void 0 && X.z !== void 0) {
172          XYZ = new this.XYZ(X.x, X.y, X.z);
173        } else {
174          throw 'Invalid parameter(s) provided for "ColorMix.ColorSpace.XYZtoLab()".';
175        }
176        x = XYZ.x / 95.047;
177        y = XYZ.y / 100.000;
178        z = XYZ.z / 108.883;
179        x = x > 0.008856 ? Math.pow(x, 1 / 3) : (7.787 * x) + 16 / 116;
180        y = y > 0.008856 ? Math.pow(y, 1 / 3) : (7.787 * y) + 16 / 116;
181        z = z > 0.008856 ? Math.pow(z, 1 / 3) : (7.787 * z) + 16 / 116;
182        return new this.Lab((116 * y) - 16, 500 * (x - y), 200 * (y - z));
183      },
184      LabtoXYZ: function(L, a, b) {
185        var Lab, X, Y, Z;
186        if (L !== void 0 && a !== void 0 && b !== void 0) {
187          Lab = new this.Lab(L, a, b);
188        } else if (L !== void 0 && typeof L === 'object' && L.L !== void 0 && L.a !== void 0 && L.b !== void 0) {
189          Lab = new this.Lab(L.L, L.a, L.b);
190        } else {
191          throw 'Invalid parameter(s) provided for "ColorMix.ColorSpace.LabtoXYZ()".';
192        }
193        Y = (Lab.L + 16) / 116;
194        X = Lab.a / 500 + Y;
195        Z = Y - Lab.b / 200;
196        Y = Math.pow(Y, 3) > 0.008856 ? Math.pow(Y, 3) : (Y - 16 / 116) / 7.787;
197        X = Math.pow(X, 3) > 0.008856 ? Math.pow(X, 3) : (X - 16 / 116) / 7.787;
198        Z = Math.pow(Z, 3) > 0.008856 ? Math.pow(Z, 3) : (Z - 16 / 116) / 7.787;
199        return new this.XYZ(X * 95.047, Y * 100.000, Z * 108.883);
200      },
201      RGBtoLab: function(R, G, B) {
202        if (R === void 0 || G === void 0 || B === void 0) {
203          throw 'Invalid parameter(s) provided for "ColorMix.ColorSpace.RGBtoLab()"';
204        }
205        return this.XYZtoLab(this.RGBtoXYZ(R, G, B));
206      },
207      LabtoRGB: function(L, a, b) {
208        if (L === void 0 || a === void 0 || b === void 0) {
209          throw 'Invalid parameter(s) provided for "ColorMix.ColorSpace.LabtoRGB()"';
210        }
211        return this.XYZtoRGB(this.LabtoXYZ(L, a, b));
212      }
213    };
214  })();
215  Color.prototype = {
216    fromHex: function(hex) {
217      var blue, green, red;
218      hex = String(hex) || '';
219      if (hex.length > 0) {
220        if (hex[0] === '#') {
221          hex = hex.slice(1);
222        }
223        if (hex.length === 3) {
224          hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
225        }
226        red = parseInt(hex.slice(0, 2), 16);
227        green = parseInt(hex.slice(2, 4), 16);
228        blue = parseInt(hex.slice(4, 6), 16);
229        this.setRed(isNaN(red) ? 0 : red);
230        this.setGreen(isNaN(green) ? 0 : green);
231        this.setBlue(isNaN(blue) ? 0 : blue);
232      } else {
233        this.setRed(0);
234        this.setGreen(0);
235        this.setBlue(0);
236      }
237      return this;
238    },
239    setRed: function(R) {
240      if (R !== void 0) {
241        this.red = Math.min(255, Math.max(0, parseInt(R)));
242      }
243      return this;
244    },
245    getRed: function() {
246      return this.red;
247    },
248    setGreen: function(G) {
249      if (G !== void 0) {
250        this.green = Math.min(255, Math.max(0, parseInt(G)));
251      }
252      return this;
253    },
254    getGreen: function() {
255      return this.green;
256    },
257    setBlue: function(B) {
258      if (B !== void 0) {
259        this.blue = Math.min(255, Math.max(0, parseInt(B)));
260      }
261      return this;
262    },
263    getBlue: function() {
264      return this.blue;
265    },
266    toString: function(mode) {
267      var HSL;
268      switch (mode) {
269        case 'rgb':
270          return 'rgb(' + this.red + ', ' + this.green + ', ' + this.blue + ')';
271        case 'rgba':
272          return 'rgba(' + this.red + ', ' + this.green + ', ' + this.blue + ', 1)';
273        case 'hsl':
274          HSL = ColorMix.ColorSpace.RGBtoHSL(this.red, this.green, this.blue);
275          return 'hsl(' + HSL.hue + ', ' + HSL.sat + '%, ' + HSL.lig + '%)';
276        case 'hsla':
277          HSL = ColorMix.ColorSpace.RGBtoHSL(this.red, this.green, this.blue);
278          return 'hsla(' + HSL.hue + ', ' + HSL.sat + '%, ' + HSL.lig + '%, 1)';
279        default:
280          return '#' + ((1 << 24) + (this.red << 16) + (this.green << 8) + this.blue).toString(16).slice(1);
281      }
282    },
283    useAsBackground: function(selector) {
284      var DOMelts, elts, i;
285      if (typeof selector === 'object' && selector !== null) {
286        if (selector.css) {
287          selector.css('background-color', 'rgb(' + this.red + ', ' + this.green + ', ' + this.blue + ')');
288        }
289      } else {
290        selector = String(selector);
291        if (selector.length > 0) {
292          if (window.jQuery !== void 0) {
293            window.jQuery(selector).css('background-color', 'rgb(' + this.red + ', ' + this.green + ', ' + this.blue + ')');
294          } else {
295            if (typeof selector === 'string') {
296              switch (selector[0]) {
297                case '#':
298                  elts = document.getElementById(selector);
299                  break;
300                case '.':
301                  if (document.getElementsByClassName) {
302                    elts = document.getElementsByClassName(selector);
303                  } else {
304                    elts = [];
305                    DOMelts = document.getElementsByTagName('*');
306                    i = DOMelts.length;
307                    while (i--) {
308                      if (DOMelts[i].className === selector.slice(1)) {
309                        elts.push(DOMelts[i])();
310                      }
311                    }
312                  }
313                  break;
314                default:
315                  elts = document.getElementsByTagName(selector);
316                  break;
317              }
318            }
319            i = elts.length;
320            while (i--) {
321              (elts[i].style['background-color'] = 'rgb(' + this.red + ', ' + this.green + ', ' + this.blue + ')')();
322            }
323          }
324        }
325      }
326      return this;
327    },
328    useAsColor: function(selector) {
329      var DOMelts, elts, i;
330      if (typeof selector === 'object' && selector !== null) {
331        if (selector.css) {
332          selector.css('color', 'rgb(' + this.red + ', ' + this.green + ', ' + this.blue + ')');
333        }
334      } else {
335        selector = String(selector);
336        if (selector.length > 0) {
337          if (window.jQuery !== void 0) {
338            window.jQuery(selector).css('color', 'rgb(' + this.red + ', ' + this.green + ', ' + this.blue + ')');
339          } else {
340            if (typeof selector === 'string') {
341              switch (selector[0]) {
342                case '#':
343                  elts = document.getElementById(selector);
344                  break;
345                case '.':
346                  if (document.getElementsByClassName) {
347                    elts = document.getElementsByClassName(selector);
348                  } else {
349                    elts = [];
350                    DOMelts = document.getElementsByTagName('*');
351                    i = DOMelts.length;
352                    while (i--) {
353                      if (DOMelts[i].className === selector.slice(1)) {
354                        elts.push(DOMelts[i])();
355                      }
356                    }
357                  }
358                  break;
359                default:
360                  elts = document.getElementsByTagName(selector);
361              }
362            }
363            i = elts.length;
364            while (i--) {
365              (elts[i].style['color'] = 'rgb(' + this.red + ', ' + this.green + ', ' + this.blue + ')')();
366            }
367          }
368        }
369      }
370      return this;
371    }
372  };
373  return {
374    Color: Color,
375    ColorSpace: ColorSpace,
376    mix: function(colors, percents) {
377      var L, Lab, P, RGB, a, b, i;
378      if (colors === void 0 || Object.prototype.toString.call(colors) !== '[object Array]') {
379        throw '"ColorMix.mix()" first parameter should be an array of ColorMix.Color objects';
380      }
381      if (percents === void 0) {
382        percents = [];
383        i = colors.length;
384        while (i--) {
385          percents[i] = 100 / colors.length;
386        }
387      } else if (Object.prototype.toString.call(percents) !== '[object Array]') {
388        throw '"ColorMix.mix()" second parameter should be an array of percents. (nnumber values)';
389      }
390      if (colors.length !== percents.length) {
391        throw '"ColorMix.mix()" parameters should be arrays of the same size !';
392      }
393      i = colors.length;
394      L = 0;
395      a = 0;
396      b = 0;
397      P = 0;
398      while (i--) {
399        if (!(colors[i] instanceof ColorMix.Color)) {
400          throw '"ColorMix.mix()" color at index: ' + i + ' should be an instance of ColorMix.Color() object !';
401        }
402        P += percents[i];
403        if (P > 100) {
404          throw 'Invalid "ColorMix.mix()" second parameter: the sum of all the percents array items should be 100.';
405        }
406        Lab = ColorMix.ColorSpace.RGBtoLab(colors[i].getRed(), colors[i].getGreen(), colors[i].getBlue());
407        L += Lab.L * percents[i] / 100;
408        a += Lab.a * percents[i] / 100;
409        b += Lab.b * percents[i] / 100;
410      }
411      if (P !== 100) {
412        throw 'Invalid "ColorMix.mix()" second parameter: the sum of all the percents array items should be 100.';
413      }
414      RGB = ColorMix.ColorSpace.LabtoRGB(L, a, b);
415      return new ColorMix.Color(RGB.red, RGB.green, RGB.blue);
416    },
417    setGradient: function(newGradient) {
418      if (newGradient !== void 0 && Object.prototype.toString.call(newGradient) === '[object Array]') {
419        _gradient = newGradient;
420      }
421      return this;
422    },
423    getGradient: function() {
424      return _gradient;
425    },
426    blend: function(reference) {
427      var C1, C2, l, next, previous, step;
428      if (reference === void 0) {
429        throw 'Missing "ColorMix.blend()" first parameter.';
430      }
431      reference = parseInt(reference);
432      if (isNaN(reference)) {
433        throw 'Invalid "ColorMix.blend()" first parameter: you should provide a number.';
434      }
435      l = _gradient.length;
436      previous = _gradient[0];
437      next = _gradient[l - 1];
438      if (reference <= previous.reference) {
439        return new ColorMix.Color(previous.color.red, previous.color.green, previous.color.blue);
440      } else if (reference >= next.reference) {
441        return new ColorMix.Color(next.color.red, next.color.green, next.color.blue);
442      }
443      while (l--) {
444        step = _gradient[l];
445        if (step.reference <= reference && step.reference > previous.reference) {
446          previous = step;
447        } else if (step.reference >= reference && step.reference < next.reference) {
448          next = step;
449        }
450      }
451      C1 = new ColorMix.Color(previous.color.red, previous.color.green, previous.color.blue);
452      C2 = new ColorMix.Color(next.color.red, next.color.green, next.color.blue);
453      previous.percent = Math.abs(100 / ((previous.reference - next.reference) / (reference - next.reference)));
454      next.percent = 100 - previous.percent;
455      return new ColorMix.mix([C1, C2], [previous.percent, next.percent]);
456    }
457  };
458})();

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.