@@ -185,7 +185,7 @@ module.exports = class Breakpoints {
185
185
. toLowerCase ( ) } `;
186
186
if ( this . #config. options . mediaQuery ) {
187
187
this . #customProperties. push ( {
188
- identifier : `${ baseName } -mediaQuery` ,
188
+ name : `${ baseName } -mediaQuery` ,
189
189
value : option . mediaQuery ,
190
190
} ) ;
191
191
}
@@ -194,19 +194,22 @@ module.exports = class Breakpoints {
194
194
Breakpoints . getResolutions ( option )
195
195
) {
196
196
this . #customProperties. push ( {
197
- identifier : `${ baseName } -resolution` ,
197
+ mediaFeature : "resolution" ,
198
+ name : `${ baseName } -resolution` ,
198
199
value : Breakpoints . getResolutions ( option ) ,
199
200
} ) ;
200
201
}
201
202
if ( this . #config. options . minWidth && Breakpoints . getMinWidths ( option ) ) {
202
203
this . #customProperties. push ( {
203
- identifier : `${ baseName } -minWidth` ,
204
+ mediaFeature : "minWidth" ,
205
+ name : `${ baseName } -minWidth` ,
204
206
value : Breakpoints . getMinWidths ( option ) ,
205
207
} ) ;
206
208
}
207
209
if ( this . #config. options . maxWidth && Breakpoints . getMaxWidths ( option ) ) {
208
210
this . #customProperties. push ( {
209
- identifier : `${ baseName } -maxWidth` ,
211
+ mediaFeature : "maxWidth" ,
212
+ name : `${ baseName } -maxWidth` ,
210
213
value : Breakpoints . getMaxWidths ( option ) ,
211
214
} ) ;
212
215
}
@@ -236,16 +239,19 @@ module.exports = class Breakpoints {
236
239
let string = "" ;
237
240
if ( this . #config. css . customMedia ) {
238
241
this . #customProperties. forEach ( ( customProperty ) => {
242
+ const mediaFeature = customProperty . mediaFeature
243
+ ? `${ customProperty . mediaFeature } :`
244
+ : "" ;
239
245
// For syntax see postcss-custom-media plugin or W3C draft
240
246
// Ref: https://www.npmjs.com/package/postcss-custom-media
241
247
// Ref: https://www.w3.org/TR/mediaqueries-5/#at-ruledef-custom-media
242
- string += `@custom-media --${ customProperty . identifier } (${ customProperty . value } );` ;
248
+ string += `@custom-media --${ customProperty . name } (${ mediaFeature } ${ customProperty . value } );` ;
243
249
} ) ;
244
250
}
245
251
if ( this . #config. css . customProperty ) {
246
252
string += `${ this . #config. css . element } {` ;
247
253
this . #customProperties. forEach ( ( customProperty ) => {
248
- string += `--${ customProperty . identifier } : "${ customProperty . value } ";` ;
254
+ string += `--${ customProperty . name } : "${ customProperty . value } ";` ;
249
255
} ) ;
250
256
string += `}` ;
251
257
}
@@ -262,10 +268,20 @@ module.exports = class Breakpoints {
262
268
*/
263
269
async #generateAndWriteJS( ) {
264
270
const filePath = path . resolve ( process . cwd ( ) , this . #config. js . path ) ;
265
- const strings = this . #customProperties. map (
266
- ( customProperty ) =>
267
- `"${ customProperty . identifier } ": "${ customProperty . value } "`
268
- ) ;
271
+ const stringArray = [ ] ;
272
+ this . #customProperties. forEach ( ( customProperty ) => {
273
+ const mediaFeature = customProperty . mediaFeature
274
+ ? `${ customProperty . mediaFeature } :`
275
+ : "" ;
276
+ if ( mediaFeature ) {
277
+ stringArray . push (
278
+ `"${ customProperty . name } ": "(${ mediaFeature } ${ customProperty . value } )"`
279
+ ) ;
280
+ }
281
+ stringArray . push (
282
+ `"${ customProperty . name } --raw": "${ customProperty . value } "`
283
+ ) ;
284
+ } ) ;
269
285
const prettierConfig = {
270
286
...( this . #config. prettier ?. configPath
271
287
? await Breakpoints . getPrettierConfig ( this . #config. prettier . configPath )
@@ -285,7 +301,7 @@ module.exports = class Breakpoints {
285
301
await Breakpoints . writeFile (
286
302
filePath ,
287
303
prettier . format (
288
- `const BREAKPOINTS = {${ strings . join (
304
+ `const BREAKPOINTS = {${ stringArray . join (
289
305
","
290
306
) } }; export default BREAKPOINTS;`,
291
307
prettierConfig
@@ -300,7 +316,7 @@ module.exports = class Breakpoints {
300
316
await Breakpoints . writeFile (
301
317
filePath ,
302
318
prettier . format (
303
- `module.exports = {${ strings . join ( "," ) } };` ,
319
+ `module.exports = {${ stringArray . join ( "," ) } };` ,
304
320
prettierConfig
305
321
)
306
322
) ;
@@ -339,7 +355,7 @@ module.exports = class Breakpoints {
339
355
if ( ! Number . isFinite ( width [ 2 ] ) && ! UNITS . length . includes ( width [ 4 ] ) ) {
340
356
throw new RangeError ( MESSAGES . widthRangeError ( option ) ) ;
341
357
}
342
- return `min- width: ${ width [ 2 ] } ${ width [ 4 ] } ` ;
358
+ return width [ 2 ] + width [ 4 ] ;
343
359
}
344
360
345
361
/**
@@ -360,7 +376,7 @@ module.exports = class Breakpoints {
360
376
if ( ! Number . isFinite ( width [ 2 ] ) && ! UNITS . length . includes ( width [ 4 ] ) ) {
361
377
throw new RangeError ( MESSAGES . widthRangeError ( option ) ) ;
362
378
}
363
- return `max- width: ${ width [ 2 ] } ${ width [ 4 ] } ` ;
379
+ return width [ 2 ] + width [ 4 ] ;
364
380
}
365
381
366
382
/**
@@ -389,7 +405,7 @@ module.exports = class Breakpoints {
389
405
) {
390
406
throw new RangeError ( MESSAGES . resolutionRangeError ( option ) ) ;
391
407
}
392
- return ` resolution: ${ resolution [ 1 ] } ${ resolution [ 2 ] } ` ;
408
+ return resolution [ 1 ] + resolution [ 2 ] ;
393
409
}
394
410
395
411
/**
0 commit comments