|
1 | 1 | import type { CodeToTokensOptions, ShikiInternal, ThemedToken, ThemedTokenWithVariants, TokensResult } from '@shikijs/types' |
2 | 2 | import { ShikiError } from '../../../types/src/error' |
3 | | -import { applyColorReplacements, getTokenStyleObject, resolveColorReplacements, stringifyTokenStyle } from '../utils' |
| 3 | +import { applyColorReplacements, getTokenStyleObject, resolveColorReplacements } from '../utils' |
4 | 4 | import { codeToTokensBase } from './code-to-tokens-base' |
5 | 5 | import { codeToTokensWithThemes } from './code-to-tokens-themes' |
6 | 6 |
|
@@ -103,27 +103,23 @@ function mergeToken( |
103 | 103 |
|
104 | 104 | // Get all style keys, for themes that missing some style, we put `inherit` to override as needed |
105 | 105 | const styleKeys = new Set(styles.flatMap(t => Object.keys(t))) |
106 | | - const mergedStyles = styles.reduce((acc, cur, idx) => { |
| 106 | + const mergedStyles: Record<string, string> = {} |
| 107 | + |
| 108 | + styles.forEach((cur, idx) => { |
107 | 109 | for (const key of styleKeys) { |
108 | 110 | const value = cur[key] || 'inherit' |
109 | 111 |
|
110 | 112 | if (idx === 0 && defaultColor) { |
111 | | - acc[key] = value |
| 113 | + mergedStyles[key] = value |
112 | 114 | } |
113 | 115 | else { |
114 | 116 | const keyName = key === 'color' ? '' : key === 'background-color' ? '-bg' : `-${key}` |
115 | 117 | const varKey = cssVariablePrefix + variantsOrder[idx] + (key === 'color' ? '' : keyName) |
116 | | - if (acc[key]) |
117 | | - acc[key] += `;${varKey}:${value}` |
118 | | - else |
119 | | - acc[key] = `${varKey}:${value}` |
| 118 | + mergedStyles[varKey] = value |
120 | 119 | } |
121 | 120 | } |
122 | | - return acc |
123 | | - }, {} as Record<string, string>) |
| 121 | + }) |
124 | 122 |
|
125 | | - token.htmlStyle = defaultColor |
126 | | - ? stringifyTokenStyle(mergedStyles) |
127 | | - : Object.values(mergedStyles).join(';') |
| 123 | + token.htmlStyle = mergedStyles |
128 | 124 | return token |
129 | 125 | } |
0 commit comments