()
| 99 | } |
| 100 | |
| 101 | function createTokensOutput() { |
| 102 | let paramsOutput = document.getElementById('themeTokensParams'); |
| 103 | let themeName = getThemeName(); |
| 104 | |
| 105 | let themeObj = {}; |
| 106 | let contrastText = _theme.contrast != 1 ? `, contrast of ${_theme.contrast * 100}%` : ''; |
| 107 | let saturationText = _theme.saturation != 100 ? `, saturation of ${_theme.saturation}%` : ''; |
| 108 | themeObj['description'] = `Color theme tokens at lightness of ${_theme.lightness}%${contrastText}${saturationText}`; |
| 109 | |
| 110 | const textLowContrast = 'Do not use for UI elements or text.'; |
| 111 | const textLarge = 'Color can be used for UI elements or large text.'; |
| 112 | const textSmall = 'Color can be used for small text.'; |
| 113 | |
| 114 | let contrastColors = _theme.contrastColors; |
| 115 | let backgroundColor = _theme.contrastColors[0].background; |
| 116 | |
| 117 | let backgroundColorObj = { |
| 118 | $value: backgroundColor, |
| 119 | $type: 'color', |
| 120 | $description: `UI background color. All color contrasts evaluated and generated against this color.` |
| 121 | }; |
| 122 | themeObj['Background'] = backgroundColorObj; |
| 123 | |
| 124 | let formulaString = _theme.formula === 'wcag2' ? 'WCAG 2.x (relative luminance)' : 'WCAG 3 (APCA)'; |
| 125 | let largeText = _theme.formula === 'wcag3' ? 60 : 3; |
| 126 | let smallText = _theme.formula === 'wcag3' ? 75 : 4.5; |
| 127 | |
| 128 | for (let i = 1; i < contrastColors.length; i++) { |
| 129 | let thisColor = contrastColors[i]; |
| 130 | for (let j = 0; j < thisColor.values.length; j++) { |
| 131 | let color = thisColor.values[j]; |
| 132 | let descriptionText = color.contrast < largeText ? textLowContrast : color.contrast >= largeText && color.contrast < smallText ? textLarge : textSmall; |
| 133 | |
| 134 | let colorObj = { |
| 135 | $value: color.value, |
| 136 | $type: 'color', |
| 137 | $description: `${descriptionText} ${formulaString} contrast is ${color.contrast}:1 against background ${backgroundColor}` |
| 138 | }; |
| 139 | themeObj[color.name] = colorObj; |
| 140 | } |
| 141 | } |
| 142 | let tokenObj = { |
| 143 | [themeName]: themeObj |
| 144 | }; |
| 145 | |
| 146 | const highlightedCode = hljs.highlight(JSON.stringify(tokenObj, null, 2), { |
| 147 | language: 'javascript' |
| 148 | }).value; |
| 149 | paramsOutput.innerHTML = highlightedCode; |
| 150 | } |
| 151 | |
| 152 | outputFormatPicker.addEventListener('change', createOutputParameters); |
| 153 | createOutputParameters(); |
no test coverage detected