@@ -119,38 +119,40 @@ export function customizerData() {
119
119
} ;
120
120
121
121
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 ) {
124
124
customizer . background = {
125
125
kind : 'color' ,
126
- value : /** @type {import('../../types/new-tab').PredefinedColor } */ ( value ) ,
126
+ value : /** @type {import('../../types/new-tab').PredefinedColor } */ ( backgroundParam ) ,
127
127
} ;
128
- } else if ( value && value in values . gradients ) {
128
+ } else if ( backgroundParam && backgroundParam in values . gradients ) {
129
129
customizer . background = {
130
130
kind : 'gradient' ,
131
- value : /** @type {import('../../types/new-tab').PredefinedGradient } */ ( value ) ,
131
+ value : /** @type {import('../../types/new-tab').PredefinedGradient } */ ( backgroundParam ) ,
132
132
} ;
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 ) ;
135
135
if ( hex . length === 6 || hex . length === 8 ) {
136
+ const value = `#${ hex . slice ( 0 , 6 ) } ` ;
136
137
customizer . background = {
137
138
kind : 'hex' ,
138
- value : `# ${ hex . slice ( 0 , 6 ) } ` ,
139
+ value,
139
140
} ;
140
141
} else {
141
142
console . warn ( 'invalid hex values' ) ;
142
143
}
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 ) ;
145
146
if ( image in values . userImages ) {
147
+ const value = values . userImages [ image ] ;
146
148
customizer . background = {
147
149
kind : 'userImage' ,
148
- value : values . userImages [ image ] ,
150
+ value,
149
151
} ;
150
152
} else {
151
153
console . warn ( 'unknown user image' ) ;
152
154
}
153
- } else if ( value && value === 'default' ) {
155
+ } else if ( backgroundParam && backgroundParam === 'default' ) {
154
156
customizer . background = { kind : 'default' } ;
155
157
}
156
158
}
0 commit comments