(dest)
| 15 | import {round, cssColorToRgb, colorToGrayScale} from './utils'; |
| 16 | |
| 17 | function createOutputColors(dest) { |
| 18 | if (dest) dest = document.getElementById(dest); |
| 19 | |
| 20 | let wcagFormula = document.getElementById('themeWCAG').value; |
| 21 | let swatchesOutputs = document.getElementById('swatchesOutputs'); |
| 22 | let themeOutputs = document.getElementById('themeOutputs'); |
| 23 | swatchesOutputs.classList = 'hideSwatchLuminosity hideSwatchContrast'; |
| 24 | |
| 25 | let theme = _theme.contrastColors; |
| 26 | let themeBackgroundColor; |
| 27 | if (_theme.output === 'RGB' || _theme.output === 'HEX') { |
| 28 | themeBackgroundColor = theme[0].background; |
| 29 | } else { |
| 30 | // First, make the color an RGB color |
| 31 | themeBackgroundColor = cssColorToRgb(theme[0].background); |
| 32 | } |
| 33 | |
| 34 | let themeBackgroundColorArray = [d3.rgb(themeBackgroundColor).r, d3.rgb(themeBackgroundColor).g, d3.rgb(themeBackgroundColor).b]; |
| 35 | const backgroundLum = _theme.lightness; |
| 36 | |
| 37 | let themeColorArray = []; |
| 38 | |
| 39 | themeOutputs.style.backgroundColor = themeBackgroundColor; |
| 40 | let destinations = dest ? [dest] : [themeOutputs, swatchesOutputs]; |
| 41 | // Iterate each color from theme except 1st object (background) |
| 42 | destinations.map((dest) => { |
| 43 | dest.innerHTML = ' '; |
| 44 | |
| 45 | // Ignore first theme item (background color) when making swatches for |
| 46 | // the Swatch tab. Only create the background color in the Theme preview |
| 47 | // Only grab one color (i=1, i<2) to show in UI, which will be turned grayscale |
| 48 | let length = dest === swatchesOutputs ? 2 : theme.length; |
| 49 | for (let i = dest === swatchesOutputs ? 1 : 0; i < length; i++) { |
| 50 | let wrapper = document.createElement('div'); |
| 51 | wrapper.className = 'themeOutputItem'; |
| 52 | |
| 53 | let swatchWrapper = document.createElement('div'); |
| 54 | swatchWrapper.className = 'themeOutputColor'; |
| 55 | let colorName = theme[i].name; |
| 56 | let outerTextColor = backgroundLum > 50 ? '#000000' : '#ffffff'; |
| 57 | // Iterate each color value |
| 58 | if (theme[i].values) { |
| 59 | let p = document.createElement('p'); |
| 60 | p.className = 'spectrum-Heading spectrum-Heading--sizeXXS themeOutputItem--Heading'; |
| 61 | p.style.color = outerTextColor; |
| 62 | p.innerHTML = theme[i].name; |
| 63 | |
| 64 | if (dest === themeOutputs) { |
| 65 | wrapper.appendChild(p); |
| 66 | } |
| 67 | |
| 68 | for (let j = 0; j < theme[i].values.length; j++) { |
| 69 | // for each value object |
| 70 | let originalValue = theme[i].values[j].value; // output value of color |
| 71 | let formattedName = colorName.replace(/\s+/g, ''); // these names will have had spaces removed already |
| 72 | let swatchName = theme[i].values[j].name.replace(formattedName, ''); |
| 73 | |
| 74 | let colorForTransform; |
no test coverage detected