@@ -7,6 +7,42 @@ import type { ThemeVariables } from './TypeUtil.js'
77
88const PREFIX_VAR = '--apkt'
99
10+ function normalizeThemeVariables ( themeVariables ?: ThemeVariables ) : Record < string , string | number > {
11+ if ( ! themeVariables ) {
12+ return { }
13+ }
14+
15+ const normalized : Record < string , string | number > = { }
16+
17+ normalized [ 'font-family' ] =
18+ themeVariables [ '--apkt-font-family' ] ?? themeVariables [ '--w3m-font-family' ] ?? 'KHTeka'
19+
20+ normalized [ 'accent' ] =
21+ themeVariables [ '--apkt-accent' ] ?? themeVariables [ '--w3m-accent' ] ?? '#0988F0'
22+
23+ normalized [ 'color-mix' ] =
24+ themeVariables [ '--apkt-color-mix' ] ?? themeVariables [ '--w3m-color-mix' ] ?? '#000'
25+
26+ normalized [ 'color-mix-strength' ] =
27+ themeVariables [ '--apkt-color-mix-strength' ] ?? themeVariables [ '--w3m-color-mix-strength' ] ?? 0
28+
29+ normalized [ 'font-size-master' ] =
30+ themeVariables [ '--apkt-font-size-master' ] ?? themeVariables [ '--w3m-font-size-master' ] ?? '10px'
31+
32+ normalized [ 'border-radius-master' ] =
33+ themeVariables [ '--apkt-border-radius-master' ] ??
34+ themeVariables [ '--w3m-border-radius-master' ] ??
35+ '4px'
36+
37+ if ( themeVariables [ '--apkt-z-index' ] !== undefined ) {
38+ normalized [ 'z-index' ] = themeVariables [ '--apkt-z-index' ]
39+ } else if ( themeVariables [ '--w3m-z-index' ] !== undefined ) {
40+ normalized [ 'z-index' ] = themeVariables [ '--w3m-z-index' ]
41+ }
42+
43+ return normalized
44+ }
45+
1046export const ThemeHelperUtil = {
1147 /**
1248 * Recursively transforms a nested styles object into a new object with CSS variable strings.
@@ -142,15 +178,16 @@ export const ThemeHelperUtil = {
142178 return { }
143179 }
144180
181+ const normalized = normalizeThemeVariables ( themeVariables )
145182 const variables : Record < string , string > = { }
146183
147- // Set default values and user overrides
148- variables [ '--w3m-font-family' ] = themeVariables [ '--w3m- font-family'] || 'KHTeka'
149- variables [ '--w3m-accent' ] = themeVariables [ '--w3m- accent'] || '#0988F0'
150- variables [ '--w3m-color-mix' ] = themeVariables [ '--w3m- color-mix'] || '#000'
151- variables [ '--w3m-color-mix-strength' ] = `${ themeVariables [ '--w3m- color-mix-strength'] || 0 } %`
152- variables [ '--w3m-font-size-master' ] = themeVariables [ '--w3m- font-size-master'] || '10px'
153- variables [ '--w3m-border-radius-master' ] = themeVariables [ '--w3m- border-radius-master'] || '4px'
184+ // Set default values and user overrides (keep --w3m-* names for backwards compatibility)
185+ variables [ '--w3m-font-family' ] = normalized [ ' font-family'] as string
186+ variables [ '--w3m-accent' ] = normalized [ ' accent'] as string
187+ variables [ '--w3m-color-mix' ] = normalized [ ' color-mix'] as string
188+ variables [ '--w3m-color-mix-strength' ] = `${ normalized [ ' color-mix-strength'] } %`
189+ variables [ '--w3m-font-size-master' ] = normalized [ ' font-size-master'] as string
190+ variables [ '--w3m-border-radius-master' ] = normalized [ ' border-radius-master'] as string
154191
155192 return variables
156193 } ,
@@ -163,23 +200,24 @@ export const ThemeHelperUtil = {
163200 return { }
164201 }
165202
203+ const normalized = normalizeThemeVariables ( themeVariables )
166204 const overrides : Record < string , string > = { }
167205
168- // Map --w3m- accent to accent-related --apkt variables
169- if ( themeVariables [ '--w3m-accent' ] ) {
170- const accentColor = themeVariables [ '--w3m- accent']
206+ // Map accent to accent-related --apkt variables (check both prefixes)
207+ if ( themeVariables [ '--apkt-accent' ] || themeVariables [ '-- w3m-accent'] ) {
208+ const accentColor = normalized [ ' accent'] as string
171209 overrides [ '--apkt-tokens-core-iconAccentPrimary' ] = accentColor
172210 overrides [ '--apkt-tokens-core-borderAccentPrimary' ] = accentColor
173211 overrides [ '--apkt-tokens-core-textAccentPrimary' ] = accentColor
174212 overrides [ '--apkt-tokens-core-backgroundAccentPrimary' ] = accentColor
175213 }
176214
177- if ( themeVariables [ '--w3m-font-family' ] ) {
178- overrides [ '--apkt-fontFamily-regular' ] = themeVariables [ '--w3m- font-family']
215+ if ( themeVariables [ '--apkt-font-family' ] || themeVariables [ '-- w3m-font-family'] ) {
216+ overrides [ '--apkt-fontFamily-regular' ] = normalized [ ' font-family'] as string
179217 }
180218
181- if ( themeVariables [ '--w3m- z-index'] ) {
182- overrides [ '--apkt-tokens-core-zIndex' ] = `${ themeVariables [ '--w3m- z-index'] } `
219+ if ( normalized [ ' z-index'] !== undefined ) {
220+ overrides [ '--apkt-tokens-core-zIndex' ] = `${ normalized [ ' z-index'] } `
183221 }
184222
185223 return overrides
@@ -193,10 +231,11 @@ export const ThemeHelperUtil = {
193231 return { }
194232 }
195233
234+ const normalized = normalizeThemeVariables ( themeVariables )
196235 const scaledVars : Record < string , string > = { }
197236
198- if ( themeVariables [ '--w3m-font-size-master' ] ) {
199- const masterSize = parseFloat ( themeVariables [ '--w3m- font-size-master'] . replace ( 'px' , '' ) )
237+ if ( themeVariables [ '--apkt-font-size-master' ] || themeVariables [ '-- w3m-font-size-master'] ) {
238+ const masterSize = parseFloat ( ( normalized [ ' font-size-master'] as string ) . replace ( 'px' , '' ) )
200239
201240 // 50px default
202241 scaledVars [ '--apkt-textSize-h1' ] = `${ Number ( masterSize ) * 5 } px`
@@ -218,10 +257,13 @@ export const ThemeHelperUtil = {
218257 scaledVars [ '--apkt-textSize-small' ] = `${ Number ( masterSize ) * 1.2 } px`
219258 }
220259
221- // Scale border radius based on --w3m-border-radius-master
222- if ( themeVariables [ '--w3m-border-radius-master' ] ) {
260+ // Scale border radius based on --apkt-border-radius-master or --w3m-border-radius-master
261+ if (
262+ themeVariables [ '--apkt-border-radius-master' ] ||
263+ themeVariables [ '--w3m-border-radius-master' ]
264+ ) {
223265 const masterRadius = parseFloat (
224- themeVariables [ '--w3m- border-radius-master'] . replace ( 'px' , '' )
266+ ( normalized [ ' border-radius-master'] as string ) . replace ( 'px' , '' )
225267 )
226268
227269 // 4px default
@@ -371,12 +413,10 @@ export const ThemeHelperUtil = {
371413 'var(--apkt-tokens-core-backgroundAccentPrimary-base)'
372414 }
373415
374- if ( ! themeVariables ?. [ '--w3m-color-mix' ] || ! themeVariables [ '--w3m-color-mix-strength' ] ) {
375- return colorMixVariables
376- }
377-
378- const colorMix = themeVariables [ '--w3m-color-mix' ]
379- const strength = themeVariables [ '--w3m-color-mix-strength' ]
416+ // Use normalized values to respect --apkt-* precedence
417+ const normalized = normalizeThemeVariables ( themeVariables )
418+ const colorMix = normalized [ 'color-mix' ]
419+ const strength = normalized [ 'color-mix-strength' ]
380420
381421 if ( ! strength || strength === 0 ) {
382422 return colorMixVariables
0 commit comments