You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//Compare the diff between the keys and the collected property values.
153
-
diff=difference(keys,expressionKeys);
154
-
155
-
//If there are missing keys, then it's a false match.
156
-
if(diff.length){
157
-
didMQMatch=false;
158
-
}
159
-
160
-
//If there is no difference, then all keys are in media query. Now we loop through the features to see it's a positive match.
161
-
else{
162
-
p.expressions.forEach(function(e){
163
-
//if the query contains this property, then we need to do a check to see if it passes the threshold. If any of the matches are false, then the media query does not pass.
164
-
varmatch=checkForMatch(e,q);
165
-
if(!match){
166
-
didMQMatch=false;
167
-
}
168
-
});
169
-
}
170
-
171
-
}
172
-
else{
173
-
didMQMatch=false;
174
-
}
175
-
176
-
//If there was a `not` in front of the media query, we need to invert the match.
177
-
didMQMatch=(p.not) ? !didMQMatch : didMQMatch;
178
-
179
-
//For each parsed mq, add a `true` or a `false` to the matches array.
180
-
matches.push(didMQMatch);
181
-
});
182
-
183
-
//if the `matches` array contains any truthy value, return true. Else, return false.
184
-
returnmatches.indexOf(true)!=-1;
185
-
}
186
-
187
-
functioncheckForMatch(exp,query){
188
-
varval=query[exp.property],
189
-
isMatch=false;
190
-
191
-
//if there's a value for this property, then we need to see if it is within the threshold
192
-
//doing an explicit undefined check here so that `0` goes through.
193
-
if(val!==undefined){
194
-
switch(exp.property){
195
-
case'device-width':
196
-
case'device-height':
197
-
case'width':
198
-
case'height':
199
-
isMatch=doesLengthPass(exp,val);
200
-
break;
201
-
202
-
case'color':
203
-
case'color-index':
204
-
case'monochrome':
205
-
isMatch=doesColorPass(exp,val);
206
-
break;
207
-
208
-
case'resolution':
209
-
isMatch=doesResolutionPass(exp,val);
210
-
break;
211
-
212
-
case'aspect-ratio':
213
-
isMatch=doesAspectRatioPass(exp,val);
214
-
break;
215
-
216
-
case'orientation':
217
-
case'scan':
218
-
isMatch=doesScanPass(exp,val);
219
-
break;
220
-
221
-
case'grid':
222
-
isMatch=doesGridPass(exp,val);
223
-
break;
224
-
225
-
}
226
-
227
-
returnisMatch;
228
-
}
229
-
230
-
//if there is not a value for the property, then we can return true.
231
-
else{
232
-
returntrue;
233
-
}
234
-
}
235
-
236
-
functioncheckMinMax(expVal,queryVal,modifier){
237
-
switch(modifier){
238
-
case'min':
239
-
//if the value we want is greater than the minimum required, then it's true.
240
-
if(expVal<=queryVal){
241
-
returntrue;
242
-
}
243
-
break;
244
-
case'max':
245
-
//if the value we want is less than or equal to the maximum required, then it's true.
246
-
if(expVal>=queryVal){
247
-
returntrue;
248
-
}
249
-
break;
250
-
default:
251
-
//sometimes we may not have a modifier. in this case, the value has to be an exact match.
252
-
if(expVal===queryVal){
253
-
returntrue;
254
-
}
255
-
break;
256
-
}
257
-
258
-
returnfalse;
259
-
}
260
-
261
-
functiondoesTypePass(parsed,value){
262
-
if(!value||value==='all'||parsed===value){
263
-
returntrue;
264
-
}
265
-
266
-
returnfalse;
267
-
}
268
-
269
-
functiondoesLengthPass(exp,val){
270
-
varexpToPx=toPx(exp.value),
271
-
valToPx=toPx(val);
272
-
273
-
returncheckMinMax(expToPx,valToPx,exp.modifier);
274
-
}
275
-
276
-
functiondoesColorPass(exp,val){
277
-
varexpInt;
278
-
279
-
//this is the (min-width: foo) and (color) use case, which means "any colored device"
0 commit comments