@@ -119,38 +119,40 @@ export function customizerData() {
119119 } ;
120120
121121 if ( url . searchParams . has ( 'background' ) ) {
122- const value = url . searchParams . get ( 'background' ) ;
123- if ( value && value in values . colors ) {
122+ const backgroundParam = url . searchParams . get ( 'background' ) ;
123+ if ( backgroundParam && backgroundParam in values . colors ) {
124124 customizer . background = {
125125 kind : 'color' ,
126- value : /** @type {import('../../types/new-tab').PredefinedColor } */ ( value ) ,
126+ value : /** @type {import('../../types/new-tab').PredefinedColor } */ ( backgroundParam ) ,
127127 } ;
128- } else if ( value && value in values . gradients ) {
128+ } else if ( backgroundParam && backgroundParam in values . gradients ) {
129129 customizer . background = {
130130 kind : 'gradient' ,
131- value : /** @type {import('../../types/new-tab').PredefinedGradient } */ ( value ) ,
131+ value : /** @type {import('../../types/new-tab').PredefinedGradient } */ ( backgroundParam ) ,
132132 } ;
133- } else if ( value && value . startsWith ( 'hex:' ) ) {
134- const hex = value . slice ( 4 ) ;
133+ } else if ( backgroundParam && backgroundParam . startsWith ( 'hex:' ) ) {
134+ const hex = backgroundParam . slice ( 4 ) ;
135135 if ( hex . length === 6 || hex . length === 8 ) {
136+ const value = `#${ hex . slice ( 0 , 6 ) } ` ;
136137 customizer . background = {
137138 kind : 'hex' ,
138- value : `# ${ hex . slice ( 0 , 6 ) } ` ,
139+ value,
139140 } ;
140141 } else {
141142 console . warn ( 'invalid hex values' ) ;
142143 }
143- } else if ( value && value . startsWith ( 'userImage:' ) ) {
144- const image = value . slice ( 10 ) ;
144+ } else if ( backgroundParam && backgroundParam . startsWith ( 'userImage:' ) ) {
145+ const image = backgroundParam . slice ( 10 ) ;
145146 if ( image in values . userImages ) {
147+ const value = values . userImages [ image ] ;
146148 customizer . background = {
147149 kind : 'userImage' ,
148- value : values . userImages [ image ] ,
150+ value,
149151 } ;
150152 } else {
151153 console . warn ( 'unknown user image' ) ;
152154 }
153- } else if ( value && value === 'default' ) {
155+ } else if ( backgroundParam && backgroundParam === 'default' ) {
154156 customizer . background = { kind : 'default' } ;
155157 }
156158 }
0 commit comments