9f1a7ae4f4e677bbe50a59f32a2c58d3.json
22.6 KB
{"ast":null,"code":"// randomColor by David Merfield under the CC0 license\n// https://github.com/davidmerfield/randomColor/\nimport { TinyColor } from './index';\nexport function random(options) {\n if (options === void 0) {\n options = {};\n } // Check if we need to generate multiple colors\n\n\n if (options.count !== undefined && options.count !== null) {\n var totalColors = options.count;\n var colors = [];\n options.count = undefined;\n\n while (totalColors > colors.length) {\n // Since we're generating multiple colors,\n // incremement the seed. Otherwise we'd just\n // generate the same color each time...\n options.count = null;\n\n if (options.seed) {\n options.seed += 1;\n }\n\n colors.push(random(options));\n }\n\n options.count = totalColors;\n return colors;\n } // First we pick a hue (H)\n\n\n var h = pickHue(options.hue, options.seed); // Then use H to determine saturation (S)\n\n var s = pickSaturation(h, options); // Then use S and H to determine brightness (B).\n\n var v = pickBrightness(h, s, options);\n var res = {\n h: h,\n s: s,\n v: v\n };\n\n if (options.alpha !== undefined) {\n res.a = options.alpha;\n } // Then we return the HSB color in the desired format\n\n\n return new TinyColor(res);\n}\n\nfunction pickHue(hue, seed) {\n var hueRange = getHueRange(hue);\n var res = randomWithin(hueRange, seed); // Instead of storing red as two seperate ranges,\n // we group them, using negative numbers\n\n if (res < 0) {\n res = 360 + res;\n }\n\n return res;\n}\n\nfunction pickSaturation(hue, options) {\n if (options.hue === 'monochrome') {\n return 0;\n }\n\n if (options.luminosity === 'random') {\n return randomWithin([0, 100], options.seed);\n }\n\n var saturationRange = getColorInfo(hue).saturationRange;\n var sMin = saturationRange[0];\n var sMax = saturationRange[1];\n\n switch (options.luminosity) {\n case 'bright':\n sMin = 55;\n break;\n\n case 'dark':\n sMin = sMax - 10;\n break;\n\n case 'light':\n sMax = 55;\n break;\n\n default:\n break;\n }\n\n return randomWithin([sMin, sMax], options.seed);\n}\n\nfunction pickBrightness(H, S, options) {\n var bMin = getMinimumBrightness(H, S);\n var bMax = 100;\n\n switch (options.luminosity) {\n case 'dark':\n bMax = bMin + 20;\n break;\n\n case 'light':\n bMin = (bMax + bMin) / 2;\n break;\n\n case 'random':\n bMin = 0;\n bMax = 100;\n break;\n\n default:\n break;\n }\n\n return randomWithin([bMin, bMax], options.seed);\n}\n\nfunction getMinimumBrightness(H, S) {\n var lowerBounds = getColorInfo(H).lowerBounds;\n\n for (var i = 0; i < lowerBounds.length - 1; i++) {\n var s1 = lowerBounds[i][0];\n var v1 = lowerBounds[i][1];\n var s2 = lowerBounds[i + 1][0];\n var v2 = lowerBounds[i + 1][1];\n\n if (S >= s1 && S <= s2) {\n var m = (v2 - v1) / (s2 - s1);\n var b = v1 - m * s1;\n return m * S + b;\n }\n }\n\n return 0;\n}\n\nfunction getHueRange(colorInput) {\n var num = parseInt(colorInput, 10);\n\n if (!Number.isNaN(num) && num < 360 && num > 0) {\n return [num, num];\n }\n\n if (typeof colorInput === 'string') {\n var namedColor = bounds.find(function (n) {\n return n.name === colorInput;\n });\n\n if (namedColor) {\n var color = defineColor(namedColor);\n\n if (color.hueRange) {\n return color.hueRange;\n }\n }\n\n var parsed = new TinyColor(colorInput);\n\n if (parsed.isValid) {\n var hue = parsed.toHsv().h;\n return [hue, hue];\n }\n }\n\n return [0, 360];\n}\n\nfunction getColorInfo(hue) {\n // Maps red colors to make picking hue easier\n if (hue >= 334 && hue <= 360) {\n hue -= 360;\n }\n\n for (var _i = 0, bounds_1 = bounds; _i < bounds_1.length; _i++) {\n var bound = bounds_1[_i];\n var color = defineColor(bound);\n\n if (color.hueRange && hue >= color.hueRange[0] && hue <= color.hueRange[1]) {\n return color;\n }\n }\n\n throw Error('Color not found');\n}\n\nfunction randomWithin(range, seed) {\n if (seed === undefined) {\n return Math.floor(range[0] + Math.random() * (range[1] + 1 - range[0]));\n } // Seeded random algorithm from http://indiegamr.com/generate-repeatable-random-numbers-in-js/\n\n\n var max = range[1] || 1;\n var min = range[0] || 0;\n seed = (seed * 9301 + 49297) % 233280;\n var rnd = seed / 233280.0;\n return Math.floor(min + rnd * (max - min));\n}\n\nfunction defineColor(bound) {\n var sMin = bound.lowerBounds[0][0];\n var sMax = bound.lowerBounds[bound.lowerBounds.length - 1][0];\n var bMin = bound.lowerBounds[bound.lowerBounds.length - 1][1];\n var bMax = bound.lowerBounds[0][1];\n return {\n name: bound.name,\n hueRange: bound.hueRange,\n lowerBounds: bound.lowerBounds,\n saturationRange: [sMin, sMax],\n brightnessRange: [bMin, bMax]\n };\n}\n/**\n * @hidden\n */\n\n\nexport var bounds = [{\n name: 'monochrome',\n hueRange: null,\n lowerBounds: [[0, 0], [100, 0]]\n}, {\n name: 'red',\n hueRange: [-26, 18],\n lowerBounds: [[20, 100], [30, 92], [40, 89], [50, 85], [60, 78], [70, 70], [80, 60], [90, 55], [100, 50]]\n}, {\n name: 'orange',\n hueRange: [19, 46],\n lowerBounds: [[20, 100], [30, 93], [40, 88], [50, 86], [60, 85], [70, 70], [100, 70]]\n}, {\n name: 'yellow',\n hueRange: [47, 62],\n lowerBounds: [[25, 100], [40, 94], [50, 89], [60, 86], [70, 84], [80, 82], [90, 80], [100, 75]]\n}, {\n name: 'green',\n hueRange: [63, 178],\n lowerBounds: [[30, 100], [40, 90], [50, 85], [60, 81], [70, 74], [80, 64], [90, 50], [100, 40]]\n}, {\n name: 'blue',\n hueRange: [179, 257],\n lowerBounds: [[20, 100], [30, 86], [40, 80], [50, 74], [60, 60], [70, 52], [80, 44], [90, 39], [100, 35]]\n}, {\n name: 'purple',\n hueRange: [258, 282],\n lowerBounds: [[20, 100], [30, 87], [40, 79], [50, 70], [60, 65], [70, 59], [80, 52], [90, 45], [100, 42]]\n}, {\n name: 'pink',\n hueRange: [283, 334],\n lowerBounds: [[20, 100], [30, 90], [40, 86], [60, 84], [80, 80], [90, 75], [100, 73]]\n}];","map":{"version":3,"sources":["C:/Users/kkwan_000/Desktop/git/2017110269/minsung/node_modules/@ctrl/tinycolor/dist/module/random.js"],"names":["TinyColor","random","options","count","undefined","totalColors","colors","length","seed","push","h","pickHue","hue","s","pickSaturation","v","pickBrightness","res","alpha","a","hueRange","getHueRange","randomWithin","luminosity","saturationRange","getColorInfo","sMin","sMax","H","S","bMin","getMinimumBrightness","bMax","lowerBounds","i","s1","v1","s2","v2","m","b","colorInput","num","parseInt","Number","isNaN","namedColor","bounds","find","n","name","color","defineColor","parsed","isValid","toHsv","_i","bounds_1","bound","Error","range","Math","floor","max","min","rnd","brightnessRange"],"mappings":"AAAA;AACA;AACA,SAASA,SAAT,QAA0B,SAA1B;AACA,OAAO,SAASC,MAAT,CAAgBC,OAAhB,EAAyB;AAC5B,MAAIA,OAAO,KAAK,KAAK,CAArB,EAAwB;AAAEA,IAAAA,OAAO,GAAG,EAAV;AAAe,GADb,CAE5B;;;AACA,MAAIA,OAAO,CAACC,KAAR,KAAkBC,SAAlB,IACAF,OAAO,CAACC,KAAR,KAAkB,IADtB,EAC4B;AACxB,QAAIE,WAAW,GAAGH,OAAO,CAACC,KAA1B;AACA,QAAIG,MAAM,GAAG,EAAb;AACAJ,IAAAA,OAAO,CAACC,KAAR,GAAgBC,SAAhB;;AACA,WAAOC,WAAW,GAAGC,MAAM,CAACC,MAA5B,EAAoC;AAChC;AACA;AACA;AACAL,MAAAA,OAAO,CAACC,KAAR,GAAgB,IAAhB;;AACA,UAAID,OAAO,CAACM,IAAZ,EAAkB;AACdN,QAAAA,OAAO,CAACM,IAAR,IAAgB,CAAhB;AACH;;AACDF,MAAAA,MAAM,CAACG,IAAP,CAAYR,MAAM,CAACC,OAAD,CAAlB;AACH;;AACDA,IAAAA,OAAO,CAACC,KAAR,GAAgBE,WAAhB;AACA,WAAOC,MAAP;AACH,GApB2B,CAqB5B;;;AACA,MAAII,CAAC,GAAGC,OAAO,CAACT,OAAO,CAACU,GAAT,EAAcV,OAAO,CAACM,IAAtB,CAAf,CAtB4B,CAuB5B;;AACA,MAAIK,CAAC,GAAGC,cAAc,CAACJ,CAAD,EAAIR,OAAJ,CAAtB,CAxB4B,CAyB5B;;AACA,MAAIa,CAAC,GAAGC,cAAc,CAACN,CAAD,EAAIG,CAAJ,EA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AEI9B,EAAAA,QAAQ,EAAE,CAAC,GAAD,EAAM,GAAN,CAFd;AAGIa,EAAAA,WAAW,EAAE,CACT,CAAC,EAAD,EAAK,GAAL,CADS,EAET,CAAC,EAAD,EAAK,EAAL,CAFS,EAGT,CAAC,EAAD,EAAK,EAAL,CAHS,EAIT,CAAC,EAAD,EAAK,EAAL,CAJS,EAKT,CAAC,EAAD,EAAK,EAAL,CALS,EAMT,CAAC,EAAD,EAAK,EAAL,CANS,EAOT,CAAC,GAAD,EAAM,EAAN,CAPS;AAHjB,CA/FgB,CAAb","sourcesContent":["// randomColor by David Merfield under the CC0 license\n// https://github.com/davidmerfield/randomColor/\nimport { TinyColor } from './index';\nexport function random(options) {\n if (options === void 0) { options = {}; }\n // Check if we need to generate multiple colors\n if (options.count !== undefined &&\n options.count !== null) {\n var totalColors = options.count;\n var colors = [];\n options.count = undefined;\n while (totalColors > colors.length) {\n // Since we're generating multiple colors,\n // incremement the seed. Otherwise we'd just\n // generate the same color each time...\n options.count = null;\n if (options.seed) {\n options.seed += 1;\n }\n colors.push(random(options));\n }\n options.count = totalColors;\n return colors;\n }\n // First we pick a hue (H)\n var h = pickHue(options.hue, options.seed);\n // Then use H to determine saturation (S)\n var s = pickSaturation(h, options);\n // Then use S and H to determine brightness (B).\n var v = pickBrightness(h, s, options);\n var res = { h: h, s: s, v: v };\n if (options.alpha !== undefined) {\n res.a = options.alpha;\n }\n // Then we return the HSB color in the desired format\n return new TinyColor(res);\n}\nfunction pickHue(hue, seed) {\n var hueRange = getHueRange(hue);\n var res = randomWithin(hueRange, seed);\n // Instead of storing red as two seperate ranges,\n // we group them, using negative numbers\n if (res < 0) {\n res = 360 + res;\n }\n return res;\n}\nfunction pickSaturation(hue, options) {\n if (options.hue === 'monochrome') {\n return 0;\n }\n if (options.luminosity === 'random') {\n return randomWithin([0, 100], options.seed);\n }\n var saturationRange = getColorInfo(hue).saturationRange;\n var sMin = saturationRange[0];\n var sMax = saturationRange[1];\n switch (options.luminosity) {\n case 'bright':\n sMin = 55;\n break;\n case 'dark':\n sMin = sMax - 10;\n break;\n case 'light':\n sMax = 55;\n break;\n default:\n break;\n }\n return randomWithin([sMin, sMax], options.seed);\n}\nfunction pickBrightness(H, S, options) {\n var bMin = getMinimumBrightness(H, S);\n var bMax = 100;\n switch (options.luminosity) {\n case 'dark':\n bMax = bMin + 20;\n break;\n case 'light':\n bMin = (bMax + bMin) / 2;\n break;\n case 'random':\n bMin = 0;\n bMax = 100;\n break;\n default:\n break;\n }\n return randomWithin([bMin, bMax], options.seed);\n}\nfunction getMinimumBrightness(H, S) {\n var lowerBounds = getColorInfo(H).lowerBounds;\n for (var i = 0; i < lowerBounds.length - 1; i++) {\n var s1 = lowerBounds[i][0];\n var v1 = lowerBounds[i][1];\n var s2 = lowerBounds[i + 1][0];\n var v2 = lowerBounds[i + 1][1];\n if (S >= s1 && S <= s2) {\n var m = (v2 - v1) / (s2 - s1);\n var b = v1 - m * s1;\n return m * S + b;\n }\n }\n return 0;\n}\nfunction getHueRange(colorInput) {\n var num = parseInt(colorInput, 10);\n if (!Number.isNaN(num) && num < 360 && num > 0) {\n return [num, num];\n }\n if (typeof colorInput === 'string') {\n var namedColor = bounds.find(function (n) { return n.name === colorInput; });\n if (namedColor) {\n var color = defineColor(namedColor);\n if (color.hueRange) {\n return color.hueRange;\n }\n }\n var parsed = new TinyColor(colorInput);\n if (parsed.isValid) {\n var hue = parsed.toHsv().h;\n return [hue, hue];\n }\n }\n return [0, 360];\n}\nfunction getColorInfo(hue) {\n // Maps red colors to make picking hue easier\n if (hue >= 334 && hue <= 360) {\n hue -= 360;\n }\n for (var _i = 0, bounds_1 = bounds; _i < bounds_1.length; _i++) {\n var bound = bounds_1[_i];\n var color = defineColor(bound);\n if (color.hueRange && hue >= color.hueRange[0] && hue <= color.hueRange[1]) {\n return color;\n }\n }\n throw Error('Color not found');\n}\nfunction randomWithin(range, seed) {\n if (seed === undefined) {\n return Math.floor(range[0] + Math.random() * (range[1] + 1 - range[0]));\n }\n // Seeded random algorithm from http://indiegamr.com/generate-repeatable-random-numbers-in-js/\n var max = range[1] || 1;\n var min = range[0] || 0;\n seed = (seed * 9301 + 49297) % 233280;\n var rnd = seed / 233280.0;\n return Math.floor(min + rnd * (max - min));\n}\nfunction defineColor(bound) {\n var sMin = bound.lowerBounds[0][0];\n var sMax = bound.lowerBounds[bound.lowerBounds.length - 1][0];\n var bMin = bound.lowerBounds[bound.lowerBounds.length - 1][1];\n var bMax = bound.lowerBounds[0][1];\n return {\n name: bound.name,\n hueRange: bound.hueRange,\n lowerBounds: bound.lowerBounds,\n saturationRange: [sMin, sMax],\n brightnessRange: [bMin, bMax],\n };\n}\n/**\n * @hidden\n */\nexport var bounds = [\n {\n name: 'monochrome',\n hueRange: null,\n lowerBounds: [\n [0, 0],\n [100, 0],\n ],\n },\n {\n name: 'red',\n hueRange: [-26, 18],\n lowerBounds: [\n [20, 100],\n [30, 92],\n [40, 89],\n [50, 85],\n [60, 78],\n [70, 70],\n [80, 60],\n [90, 55],\n [100, 50],\n ],\n },\n {\n name: 'orange',\n hueRange: [19, 46],\n lowerBounds: [\n [20, 100],\n [30, 93],\n [40, 88],\n [50, 86],\n [60, 85],\n [70, 70],\n [100, 70],\n ],\n },\n {\n name: 'yellow',\n hueRange: [47, 62],\n lowerBounds: [\n [25, 100],\n [40, 94],\n [50, 89],\n [60, 86],\n [70, 84],\n [80, 82],\n [90, 80],\n [100, 75],\n ],\n },\n {\n name: 'green',\n hueRange: [63, 178],\n lowerBounds: [\n [30, 100],\n [40, 90],\n [50, 85],\n [60, 81],\n [70, 74],\n [80, 64],\n [90, 50],\n [100, 40],\n ],\n },\n {\n name: 'blue',\n hueRange: [179, 257],\n lowerBounds: [\n [20, 100],\n [30, 86],\n [40, 80],\n [50, 74],\n [60, 60],\n [70, 52],\n [80, 44],\n [90, 39],\n [100, 35],\n ],\n },\n {\n name: 'purple',\n hueRange: [258, 282],\n lowerBounds: [\n [20, 100],\n [30, 87],\n [40, 79],\n [50, 70],\n [60, 65],\n [70, 59],\n [80, 52],\n [90, 45],\n [100, 42],\n ],\n },\n {\n name: 'pink',\n hueRange: [283, 334],\n lowerBounds: [\n [20, 100],\n [30, 90],\n [40, 86],\n [60, 84],\n [80, 80],\n [90, 75],\n [100, 73],\n ],\n },\n];\n"]},"metadata":{},"sourceType":"module"}