@vibrant/generator-default
Advanced tools
Comparing version 3.0.0 to 3.1.0-0
@@ -5,3 +5,2 @@ "use strict"; | ||
var converter_1 = require("@vibrant/color/lib/converter"); | ||
var defaults = require("lodash/defaults"); | ||
var DefaultOpts = { | ||
@@ -21,3 +20,3 @@ targetDarkLuma: 0.26, | ||
weightLuma: 6.5, | ||
weightPopulation: 0.5, | ||
weightPopulation: 0.5 | ||
}; | ||
@@ -78,20 +77,27 @@ function _findMaxPopulation(swatches) { | ||
function _generateVariationColors(swatches, maxPopulation, opts) { | ||
var palette = {}; | ||
var palette = { | ||
Vibrant: null, | ||
DarkVibrant: null, | ||
LightVibrant: null, | ||
Muted: null, | ||
DarkMuted: null, | ||
LightMuted: null | ||
}; | ||
// mVibrantSwatch = findColor(TARGET_NORMAL_LUMA, MIN_NORMAL_LUMA, MAX_NORMAL_LUMA, | ||
// TARGET_VIBRANT_SATURATION, MIN_VIBRANT_SATURATION, 1f); | ||
// TARGET_VIBRANT_SATURATION, MIN_VIBRANT_SATURATION, 1f) | ||
palette.Vibrant = _findColorVariation(palette, swatches, maxPopulation, opts.targetNormalLuma, opts.minNormalLuma, opts.maxNormalLuma, opts.targetVibrantSaturation, opts.minVibrantSaturation, 1, opts); | ||
// mLightVibrantSwatch = findColor(TARGET_LIGHT_LUMA, MIN_LIGHT_LUMA, 1f, | ||
// TARGET_VIBRANT_SATURATION, MIN_VIBRANT_SATURATION, 1f); | ||
// TARGET_VIBRANT_SATURATION, MIN_VIBRANT_SATURATION, 1f) | ||
palette.LightVibrant = _findColorVariation(palette, swatches, maxPopulation, opts.targetLightLuma, opts.minLightLuma, 1, opts.targetVibrantSaturation, opts.minVibrantSaturation, 1, opts); | ||
// mDarkVibrantSwatch = findColor(TARGET_DARK_LUMA, 0f, MAX_DARK_LUMA, | ||
// TARGET_VIBRANT_SATURATION, MIN_VIBRANT_SATURATION, 1f); | ||
// TARGET_VIBRANT_SATURATION, MIN_VIBRANT_SATURATION, 1f) | ||
palette.DarkVibrant = _findColorVariation(palette, swatches, maxPopulation, opts.targetDarkLuma, 0, opts.maxDarkLuma, opts.targetVibrantSaturation, opts.minVibrantSaturation, 1, opts); | ||
// mMutedSwatch = findColor(TARGET_NORMAL_LUMA, MIN_NORMAL_LUMA, MAX_NORMAL_LUMA, | ||
// TARGET_MUTED_SATURATION, 0f, MAX_MUTED_SATURATION); | ||
// TARGET_MUTED_SATURATION, 0f, MAX_MUTED_SATURATION) | ||
palette.Muted = _findColorVariation(palette, swatches, maxPopulation, opts.targetNormalLuma, opts.minNormalLuma, opts.maxNormalLuma, opts.targetMutesSaturation, 0, opts.maxMutesSaturation, opts); | ||
// mLightMutedColor = findColor(TARGET_LIGHT_LUMA, MIN_LIGHT_LUMA, 1f, | ||
// TARGET_MUTED_SATURATION, 0f, MAX_MUTED_SATURATION); | ||
// TARGET_MUTED_SATURATION, 0f, MAX_MUTED_SATURATION) | ||
palette.LightMuted = _findColorVariation(palette, swatches, maxPopulation, opts.targetLightLuma, opts.minLightLuma, 1, opts.targetMutesSaturation, 0, opts.maxMutesSaturation, opts); | ||
// mDarkMutedSwatch = findColor(TARGET_DARK_LUMA, 0f, MAX_DARK_LUMA, | ||
// TARGET_MUTED_SATURATION, 0f, MAX_MUTED_SATURATION); | ||
// TARGET_MUTED_SATURATION, 0f, MAX_MUTED_SATURATION) | ||
palette.DarkMuted = _findColorVariation(palette, swatches, maxPopulation, opts.targetDarkLuma, 0, opts.maxDarkLuma, opts.targetMutesSaturation, 0, opts.maxMutesSaturation, opts); | ||
@@ -101,15 +107,52 @@ return palette; | ||
function _generateEmptySwatches(palette, maxPopulation, opts) { | ||
if (palette.Vibrant === null && palette.DarkVibrant !== null) { | ||
var _a = palette.DarkVibrant.getHsl(), h = _a[0], s = _a[1], l = _a[2]; | ||
if (!palette.Vibrant && !palette.DarkVibrant && !palette.LightVibrant) { | ||
if (!palette.DarkVibrant && palette.DarkMuted) { | ||
var _a = palette.DarkMuted.getHsl(), h = _a[0], s = _a[1], l = _a[2]; | ||
l = opts.targetDarkLuma; | ||
palette.DarkVibrant = new color_1.Swatch(converter_1.hslToRgb(h, s, l), 0); | ||
} | ||
if (!palette.LightVibrant && palette.LightMuted) { | ||
var _b = palette.LightMuted.getHsl(), h = _b[0], s = _b[1], l = _b[2]; | ||
l = opts.targetDarkLuma; | ||
palette.DarkVibrant = new color_1.Swatch(converter_1.hslToRgb(h, s, l), 0); | ||
} | ||
} | ||
if (!palette.Vibrant && palette.DarkVibrant) { | ||
var _c = palette.DarkVibrant.getHsl(), h = _c[0], s = _c[1], l = _c[2]; | ||
l = opts.targetNormalLuma; | ||
palette.Vibrant = new color_1.Swatch(converter_1.hslToRgb(h, s, l), 0); | ||
} | ||
if (palette.DarkVibrant === null && palette.Vibrant !== null) { | ||
var _b = palette.Vibrant.getHsl(), h = _b[0], s = _b[1], l = _b[2]; | ||
else if (!palette.Vibrant && palette.LightVibrant) { | ||
var _d = palette.LightVibrant.getHsl(), h = _d[0], s = _d[1], l = _d[2]; | ||
l = opts.targetNormalLuma; | ||
palette.Vibrant = new color_1.Swatch(converter_1.hslToRgb(h, s, l), 0); | ||
} | ||
if (!palette.DarkVibrant && palette.Vibrant) { | ||
var _e = palette.Vibrant.getHsl(), h = _e[0], s = _e[1], l = _e[2]; | ||
l = opts.targetDarkLuma; | ||
palette.DarkVibrant = new color_1.Swatch(converter_1.hslToRgb(h, s, l), 0); | ||
} | ||
if (!palette.LightVibrant && palette.Vibrant) { | ||
var _f = palette.Vibrant.getHsl(), h = _f[0], s = _f[1], l = _f[2]; | ||
l = opts.targetLightLuma; | ||
palette.LightVibrant = new color_1.Swatch(converter_1.hslToRgb(h, s, l), 0); | ||
} | ||
if (!palette.Muted && palette.Vibrant) { | ||
var _g = palette.Vibrant.getHsl(), h = _g[0], s = _g[1], l = _g[2]; | ||
l = opts.targetMutesSaturation; | ||
palette.Muted = new color_1.Swatch(converter_1.hslToRgb(h, s, l), 0); | ||
} | ||
if (!palette.DarkMuted && palette.DarkVibrant) { | ||
var _h = palette.DarkVibrant.getHsl(), h = _h[0], s = _h[1], l = _h[2]; | ||
l = opts.targetMutesSaturation; | ||
palette.DarkMuted = new color_1.Swatch(converter_1.hslToRgb(h, s, l), 0); | ||
} | ||
if (!palette.LightMuted && palette.LightVibrant) { | ||
var _j = palette.LightVibrant.getHsl(), h = _j[0], s = _j[1], l = _j[2]; | ||
l = opts.targetMutesSaturation; | ||
palette.LightMuted = new color_1.Swatch(converter_1.hslToRgb(h, s, l), 0); | ||
} | ||
} | ||
var DefaultGenerator = function (swatches, opts) { | ||
opts = defaults({}, opts, DefaultOpts); | ||
opts = Object.assign({}, DefaultOpts, opts); | ||
var maxPopulation = _findMaxPopulation(swatches); | ||
@@ -116,0 +159,0 @@ var palette = _generateVariationColors(swatches, maxPopulation, opts); |
{ | ||
"name": "@vibrant/generator-default", | ||
"version": "3.0.0", | ||
"version": "3.1.0-0", | ||
"description": "Default generator that generates the original vibrant palette", | ||
"scripts": { | ||
"build:module": "tsc", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
@@ -11,12 +10,17 @@ }, | ||
"types": "lib/index.d.ts", | ||
"author": "", | ||
"license": "ISC", | ||
"author": { | ||
"name": "akfish", | ||
"email": "akfish@gmail.com" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/akfish/node-vibrant/issues" | ||
}, | ||
"homepage": "https://github.com/akfish/node-vibrant", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@vibrant/color": "^3.0.0", | ||
"@vibrant/generator": "^3.0.0", | ||
"lodash": "^4.17.4" | ||
"@vibrant/generator": "^3.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/lodash": "^4.14.86", | ||
"typescript": "latest" | ||
"typescript": "^3.2.2" | ||
}, | ||
@@ -23,0 +27,0 @@ "publishConfig": { |
388
src/index.ts
import { Swatch, Palette } from '@vibrant/color' | ||
import { Generator } from '@vibrant/generator' | ||
import { hslToRgb } from '@vibrant/color/lib/converter' | ||
import defaults = require('lodash/defaults') | ||
interface DefaultGeneratorOptions { | ||
targetDarkLuma: number, | ||
maxDarkLuma: number, | ||
minLightLuma: number, | ||
targetLightLuma: number, | ||
minNormalLuma: number, | ||
targetNormalLuma: number, | ||
maxNormalLuma: number, | ||
targetMutesSaturation: number, | ||
maxMutesSaturation: number, | ||
targetVibrantSaturation: number, | ||
minVibrantSaturation: number, | ||
weightSaturation: number, | ||
weightLuma: number, | ||
weightPopulation: number | ||
targetDarkLuma: number, | ||
maxDarkLuma: number, | ||
minLightLuma: number, | ||
targetLightLuma: number, | ||
minNormalLuma: number, | ||
targetNormalLuma: number, | ||
maxNormalLuma: number, | ||
targetMutesSaturation: number, | ||
maxMutesSaturation: number, | ||
targetVibrantSaturation: number, | ||
minVibrantSaturation: number, | ||
weightSaturation: number, | ||
weightLuma: number, | ||
weightPopulation: number | ||
} | ||
const DefaultOpts: DefaultGeneratorOptions = { | ||
targetDarkLuma: 0.26, | ||
maxDarkLuma: 0.45, | ||
minLightLuma: 0.55, | ||
targetLightLuma: 0.74, | ||
minNormalLuma: 0.3, | ||
targetNormalLuma: 0.5, | ||
maxNormalLuma: 0.7, | ||
targetMutesSaturation: 0.3, | ||
maxMutesSaturation: 0.4, | ||
targetVibrantSaturation: 1.0, | ||
minVibrantSaturation: 0.35, | ||
weightSaturation: 3, | ||
weightLuma: 6.5, | ||
weightPopulation: 0.5, | ||
targetDarkLuma: 0.26, | ||
maxDarkLuma: 0.45, | ||
minLightLuma: 0.55, | ||
targetLightLuma: 0.74, | ||
minNormalLuma: 0.3, | ||
targetNormalLuma: 0.5, | ||
maxNormalLuma: 0.7, | ||
targetMutesSaturation: 0.3, | ||
maxMutesSaturation: 0.4, | ||
targetVibrantSaturation: 1.0, | ||
minVibrantSaturation: 0.35, | ||
weightSaturation: 3, | ||
weightLuma: 6.5, | ||
weightPopulation: 0.5 | ||
} | ||
function _findMaxPopulation(swatches: Array<Swatch>): number { | ||
let p = 0 | ||
function _findMaxPopulation (swatches: Array<Swatch>): number { | ||
let p = 0 | ||
swatches.forEach((s) => { | ||
p = Math.max(p, s.getPopulation()) | ||
}) | ||
swatches.forEach((s) => { | ||
p = Math.max(p, s.getPopulation()) | ||
}) | ||
return p | ||
return p | ||
} | ||
function _isAlreadySelected(palette: Palette, s: Swatch): boolean { | ||
return palette.Vibrant === s | ||
|| palette.DarkVibrant === s | ||
|| palette.LightVibrant === s | ||
|| palette.Muted === s | ||
|| palette.DarkMuted === s | ||
|| palette.LightMuted === s | ||
function _isAlreadySelected (palette: Palette, s: Swatch): boolean { | ||
return palette.Vibrant === s | ||
|| palette.DarkVibrant === s | ||
|| palette.LightVibrant === s | ||
|| palette.Muted === s | ||
|| palette.DarkMuted === s | ||
|| palette.LightMuted === s | ||
} | ||
function _createComparisonValue( | ||
saturation: number, targetSaturation: number, | ||
luma: number, targetLuma: number, | ||
population: number, maxPopulation: number, opts: DefaultGeneratorOptions): number { | ||
function _createComparisonValue ( | ||
saturation: number, targetSaturation: number, | ||
luma: number, targetLuma: number, | ||
population: number, maxPopulation: number, opts: DefaultGeneratorOptions): number { | ||
function weightedMean(...values: number[]) { | ||
let sum = 0 | ||
let weightSum = 0 | ||
for (let i = 0; i < values.length; i += 2) { | ||
let value = values[i] | ||
let weight = values[i + 1] | ||
sum += value * weight | ||
weightSum += weight | ||
} | ||
return sum / weightSum | ||
function weightedMean (...values: number[]) { | ||
let sum = 0 | ||
let weightSum = 0 | ||
for (let i = 0; i < values.length; i += 2) { | ||
let value = values[i] | ||
let weight = values[i + 1] | ||
sum += value * weight | ||
weightSum += weight | ||
} | ||
function invertDiff(value: number, targetValue: number): number { | ||
return 1 - Math.abs(value - targetValue) | ||
} | ||
return sum / weightSum | ||
} | ||
return weightedMean( | ||
invertDiff(saturation, targetSaturation), opts.weightSaturation, | ||
invertDiff(luma, targetLuma), opts.weightLuma, | ||
population / maxPopulation, opts.weightPopulation | ||
) | ||
function invertDiff (value: number, targetValue: number): number { | ||
return 1 - Math.abs(value - targetValue) | ||
} | ||
return weightedMean( | ||
invertDiff(saturation, targetSaturation), opts.weightSaturation, | ||
invertDiff(luma, targetLuma), opts.weightLuma, | ||
population / maxPopulation, opts.weightPopulation | ||
) | ||
} | ||
function _findColorVariation(palette: Palette, swatches: Array<Swatch>, maxPopulation: number, | ||
targetLuma: number, | ||
minLuma: number, | ||
maxLuma: number, | ||
targetSaturation: number, | ||
minSaturation: number, | ||
maxSaturation: number, | ||
opts: DefaultGeneratorOptions): Swatch { | ||
function _findColorVariation (palette: Palette, swatches: Array<Swatch>, maxPopulation: number, | ||
targetLuma: number, | ||
minLuma: number, | ||
maxLuma: number, | ||
targetSaturation: number, | ||
minSaturation: number, | ||
maxSaturation: number, | ||
opts: DefaultGeneratorOptions): Swatch | null { | ||
let max: Swatch = null | ||
let maxValue = 0 | ||
let max: Swatch | null = null | ||
let maxValue = 0 | ||
swatches.forEach((swatch) => { | ||
let [, s, l] = swatch.getHsl() | ||
swatches.forEach((swatch) => { | ||
let [, s, l] = swatch.getHsl() | ||
if (s >= minSaturation && s <= maxSaturation | ||
&& l >= minLuma && l <= maxLuma | ||
&& !_isAlreadySelected(palette, swatch) | ||
) { | ||
let value = _createComparisonValue(s, targetSaturation, l, targetLuma, swatch.getPopulation(), maxPopulation, opts) | ||
if (s >= minSaturation && s <= maxSaturation | ||
&& l >= minLuma && l <= maxLuma | ||
&& !_isAlreadySelected(palette, swatch) | ||
) { | ||
let value = _createComparisonValue(s, targetSaturation, l, targetLuma, swatch.getPopulation(), maxPopulation, opts) | ||
if (max === null || value > maxValue) { | ||
max = swatch | ||
maxValue = value | ||
} | ||
if (max === null || value > maxValue) { | ||
max = swatch | ||
maxValue = value | ||
} | ||
} | ||
}) | ||
} | ||
}) | ||
return max | ||
return max | ||
} | ||
function _generateVariationColors(swatches: Array<Swatch>, maxPopulation: number, opts: DefaultGeneratorOptions): Palette { | ||
let palette: Palette = {} | ||
// mVibrantSwatch = findColor(TARGET_NORMAL_LUMA, MIN_NORMAL_LUMA, MAX_NORMAL_LUMA, | ||
// TARGET_VIBRANT_SATURATION, MIN_VIBRANT_SATURATION, 1f); | ||
palette.Vibrant = _findColorVariation(palette, swatches, maxPopulation, | ||
opts.targetNormalLuma, | ||
opts.minNormalLuma, | ||
opts.maxNormalLuma, | ||
opts.targetVibrantSaturation, | ||
opts.minVibrantSaturation, | ||
1, | ||
opts | ||
) | ||
// mLightVibrantSwatch = findColor(TARGET_LIGHT_LUMA, MIN_LIGHT_LUMA, 1f, | ||
// TARGET_VIBRANT_SATURATION, MIN_VIBRANT_SATURATION, 1f); | ||
palette.LightVibrant = _findColorVariation(palette, swatches, maxPopulation, | ||
opts.targetLightLuma, | ||
opts.minLightLuma, | ||
1, | ||
opts.targetVibrantSaturation, | ||
opts.minVibrantSaturation, | ||
1, | ||
opts | ||
) | ||
// mDarkVibrantSwatch = findColor(TARGET_DARK_LUMA, 0f, MAX_DARK_LUMA, | ||
// TARGET_VIBRANT_SATURATION, MIN_VIBRANT_SATURATION, 1f); | ||
palette.DarkVibrant = _findColorVariation(palette, swatches, maxPopulation, | ||
opts.targetDarkLuma, | ||
0, | ||
opts.maxDarkLuma, | ||
opts.targetVibrantSaturation, | ||
opts.minVibrantSaturation, | ||
1, | ||
opts | ||
) | ||
// mMutedSwatch = findColor(TARGET_NORMAL_LUMA, MIN_NORMAL_LUMA, MAX_NORMAL_LUMA, | ||
// TARGET_MUTED_SATURATION, 0f, MAX_MUTED_SATURATION); | ||
palette.Muted = _findColorVariation(palette, swatches, maxPopulation, | ||
opts.targetNormalLuma, | ||
opts.minNormalLuma, | ||
opts.maxNormalLuma, | ||
opts.targetMutesSaturation, | ||
0, | ||
opts.maxMutesSaturation, | ||
opts | ||
) | ||
// mLightMutedColor = findColor(TARGET_LIGHT_LUMA, MIN_LIGHT_LUMA, 1f, | ||
// TARGET_MUTED_SATURATION, 0f, MAX_MUTED_SATURATION); | ||
palette.LightMuted = _findColorVariation(palette, swatches, maxPopulation, | ||
opts.targetLightLuma, | ||
opts.minLightLuma, | ||
1, | ||
opts.targetMutesSaturation, | ||
0, | ||
opts.maxMutesSaturation, | ||
opts | ||
) | ||
// mDarkMutedSwatch = findColor(TARGET_DARK_LUMA, 0f, MAX_DARK_LUMA, | ||
// TARGET_MUTED_SATURATION, 0f, MAX_MUTED_SATURATION); | ||
palette.DarkMuted = _findColorVariation(palette, swatches, maxPopulation, | ||
opts.targetDarkLuma, | ||
0, | ||
opts.maxDarkLuma, | ||
opts.targetMutesSaturation, | ||
0, | ||
opts.maxMutesSaturation, | ||
opts | ||
) | ||
return palette | ||
function _generateVariationColors (swatches: Array<Swatch>, maxPopulation: number, opts: DefaultGeneratorOptions): Palette { | ||
let palette: Palette = { | ||
Vibrant: null, | ||
DarkVibrant: null, | ||
LightVibrant: null, | ||
Muted: null, | ||
DarkMuted: null, | ||
LightMuted: null | ||
} | ||
// mVibrantSwatch = findColor(TARGET_NORMAL_LUMA, MIN_NORMAL_LUMA, MAX_NORMAL_LUMA, | ||
// TARGET_VIBRANT_SATURATION, MIN_VIBRANT_SATURATION, 1f) | ||
palette.Vibrant = _findColorVariation(palette, swatches, maxPopulation, | ||
opts.targetNormalLuma, | ||
opts.minNormalLuma, | ||
opts.maxNormalLuma, | ||
opts.targetVibrantSaturation, | ||
opts.minVibrantSaturation, | ||
1, | ||
opts | ||
) | ||
// mLightVibrantSwatch = findColor(TARGET_LIGHT_LUMA, MIN_LIGHT_LUMA, 1f, | ||
// TARGET_VIBRANT_SATURATION, MIN_VIBRANT_SATURATION, 1f) | ||
palette.LightVibrant = _findColorVariation(palette, swatches, maxPopulation, | ||
opts.targetLightLuma, | ||
opts.minLightLuma, | ||
1, | ||
opts.targetVibrantSaturation, | ||
opts.minVibrantSaturation, | ||
1, | ||
opts | ||
) | ||
// mDarkVibrantSwatch = findColor(TARGET_DARK_LUMA, 0f, MAX_DARK_LUMA, | ||
// TARGET_VIBRANT_SATURATION, MIN_VIBRANT_SATURATION, 1f) | ||
palette.DarkVibrant = _findColorVariation(palette, swatches, maxPopulation, | ||
opts.targetDarkLuma, | ||
0, | ||
opts.maxDarkLuma, | ||
opts.targetVibrantSaturation, | ||
opts.minVibrantSaturation, | ||
1, | ||
opts | ||
) | ||
// mMutedSwatch = findColor(TARGET_NORMAL_LUMA, MIN_NORMAL_LUMA, MAX_NORMAL_LUMA, | ||
// TARGET_MUTED_SATURATION, 0f, MAX_MUTED_SATURATION) | ||
palette.Muted = _findColorVariation(palette, swatches, maxPopulation, | ||
opts.targetNormalLuma, | ||
opts.minNormalLuma, | ||
opts.maxNormalLuma, | ||
opts.targetMutesSaturation, | ||
0, | ||
opts.maxMutesSaturation, | ||
opts | ||
) | ||
// mLightMutedColor = findColor(TARGET_LIGHT_LUMA, MIN_LIGHT_LUMA, 1f, | ||
// TARGET_MUTED_SATURATION, 0f, MAX_MUTED_SATURATION) | ||
palette.LightMuted = _findColorVariation(palette, swatches, maxPopulation, | ||
opts.targetLightLuma, | ||
opts.minLightLuma, | ||
1, | ||
opts.targetMutesSaturation, | ||
0, | ||
opts.maxMutesSaturation, | ||
opts | ||
) | ||
// mDarkMutedSwatch = findColor(TARGET_DARK_LUMA, 0f, MAX_DARK_LUMA, | ||
// TARGET_MUTED_SATURATION, 0f, MAX_MUTED_SATURATION) | ||
palette.DarkMuted = _findColorVariation(palette, swatches, maxPopulation, | ||
opts.targetDarkLuma, | ||
0, | ||
opts.maxDarkLuma, | ||
opts.targetMutesSaturation, | ||
0, | ||
opts.maxMutesSaturation, | ||
opts | ||
) | ||
return palette | ||
} | ||
function _generateEmptySwatches(palette: Palette, maxPopulation: number, opts: DefaultGeneratorOptions): void { | ||
if (palette.Vibrant === null && palette.DarkVibrant !== null) { | ||
let [h, s, l] = palette.DarkVibrant.getHsl() | ||
l = opts.targetNormalLuma | ||
palette.Vibrant = new Swatch(hslToRgb(h, s, l), 0) | ||
function _generateEmptySwatches (palette: Palette, maxPopulation: number, opts: DefaultGeneratorOptions): void { | ||
if (!palette.Vibrant && !palette.DarkVibrant && !palette.LightVibrant) { | ||
if (!palette.DarkVibrant && palette.DarkMuted) { | ||
let [h, s, l] = palette.DarkMuted.getHsl() | ||
l = opts.targetDarkLuma | ||
palette.DarkVibrant = new Swatch(hslToRgb(h, s, l), 0) | ||
} | ||
if (palette.DarkVibrant === null && palette.Vibrant !== null) { | ||
let [h, s, l] = palette.Vibrant.getHsl() | ||
l = opts.targetDarkLuma | ||
palette.DarkVibrant = new Swatch(hslToRgb(h, s, l), 0) | ||
if (!palette.LightVibrant && palette.LightMuted) { | ||
let [h, s, l] = palette.LightMuted.getHsl() | ||
l = opts.targetDarkLuma | ||
palette.DarkVibrant = new Swatch(hslToRgb(h, s, l), 0) | ||
} | ||
} | ||
if (!palette.Vibrant && palette.DarkVibrant) { | ||
let [h, s, l] = palette.DarkVibrant.getHsl() | ||
l = opts.targetNormalLuma | ||
palette.Vibrant = new Swatch(hslToRgb(h, s, l), 0) | ||
} else if (!palette.Vibrant && palette.LightVibrant) { | ||
let [h, s, l] = palette.LightVibrant.getHsl() | ||
l = opts.targetNormalLuma | ||
palette.Vibrant = new Swatch(hslToRgb(h, s, l), 0) | ||
} | ||
if (!palette.DarkVibrant && palette.Vibrant) { | ||
let [h, s, l] = palette.Vibrant.getHsl() | ||
l = opts.targetDarkLuma | ||
palette.DarkVibrant = new Swatch(hslToRgb(h, s, l), 0) | ||
} | ||
if (!palette.LightVibrant && palette.Vibrant) { | ||
let [h, s, l] = palette.Vibrant.getHsl() | ||
l = opts.targetLightLuma | ||
palette.LightVibrant = new Swatch(hslToRgb(h, s, l), 0) | ||
} | ||
if (!palette.Muted && palette.Vibrant) { | ||
let [h, s, l] = palette.Vibrant.getHsl() | ||
l = opts.targetMutesSaturation | ||
palette.Muted = new Swatch(hslToRgb(h, s, l), 0) | ||
} | ||
if (!palette.DarkMuted && palette.DarkVibrant) { | ||
let [h, s, l] = palette.DarkVibrant.getHsl() | ||
l = opts.targetMutesSaturation | ||
palette.DarkMuted = new Swatch(hslToRgb(h, s, l), 0) | ||
} | ||
if (!palette.LightMuted && palette.LightVibrant) { | ||
let [h, s, l] = palette.LightVibrant.getHsl() | ||
l = opts.targetMutesSaturation | ||
palette.LightMuted = new Swatch(hslToRgb(h, s, l), 0) | ||
} | ||
} | ||
const DefaultGenerator: Generator = (swatches: Array<Swatch>, opts?: DefaultGeneratorOptions): Palette => { | ||
opts = <DefaultGeneratorOptions>defaults({}, opts, DefaultOpts) | ||
let maxPopulation = _findMaxPopulation(swatches) | ||
opts = Object.assign({}, DefaultOpts, opts) | ||
let maxPopulation = _findMaxPopulation(swatches) | ||
let palette = _generateVariationColors(swatches, maxPopulation, opts) | ||
_generateEmptySwatches(palette, maxPopulation, opts) | ||
let palette = _generateVariationColors(swatches, maxPopulation, opts) | ||
_generateEmptySwatches(palette, maxPopulation, opts) | ||
return palette | ||
return palette | ||
} | ||
export default DefaultGenerator | ||
export default DefaultGenerator |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
24790
2
1
394
0
6
1
1
1
1
7
- Removedlodash@^4.17.4
- Removedlodash@4.17.21(transitive)