File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed
Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change 5757 * Values can be `light`, `dark`, `high-contrast`,
5858 * or `high-contrast-dark`. Default to `light` for tests.
5959 */
60- const paletteQuery = window . location . search . match ( / p a l e t t e = ( [ a - z ] + ) / ) ;
61- const paletteHash = window . location . hash . match ( / p a l e t t e = ( [ a - z ] + ) / ) ;
60+ const validPalettes = [ 'light' , 'dark' , 'high-contrast' , 'high-contrast-dark' ] ;
61+ const paletteQuery = window . location . search . match ( / p a l e t t e = ( [ a - z - ] + ) / ) ;
62+ const paletteHash = window . location . hash . match ( / p a l e t t e = ( [ a - z - ] + ) / ) ;
6263 const darkClass = document . body ?. classList . contains ( 'ion-palette-dark' ) ? 'dark' : null ;
64+ const highContrastClass = document . body ?. classList . contains ( 'ion-palette-high-contrast' ) ? 'high-contrast' : null ;
65+ const highContrastDarkClass = darkClass && highContrastClass ? 'high-contrast-dark' : null ;
6366
64- const paletteName = paletteQuery ?. [ 1 ] || paletteHash ?. [ 1 ] || darkClass || 'light' ;
67+ let paletteName = paletteQuery ?. [ 1 ] || paletteHash ?. [ 1 ] || highContrastDarkClass || darkClass || highContrastClass || 'light' ;
68+
69+ if ( ! validPalettes . includes ( paletteName ) ) {
70+ paletteName = 'light' ;
71+ console . warn ( `Invalid palette name: ${ paletteName } . Falling back to 'light' palette.` ) ;
72+ }
6573
6674 if ( paletteName !== 'light' ) {
6775 const linkTag = document . createElement ( 'link' ) ;
You can’t perform that action at this time.
0 commit comments