1
+ @charset " UTF-8" ; // Fixes an issue where Ruby locale is not set properly
2
+ // See https://github.com/sass-mq/sass-mq/pull/10
3
+
4
+ /// Base font size on the `<body>` element
5
+ ///
6
+ /// Do not override this value, or things will break
7
+ ///
8
+ /// @link https://github.com/sass-mq/sass-mq/issues/122
9
+ /// @deprecated This setting will be removed in sass-mq v6.0.0
10
+ /// @access private
11
+ /// @type Number (unit)
12
+ $mq-base-font-size : 16px !default ;
13
+
14
+ /// Responsive mode
15
+ ///
16
+ /// Set to `false` to enable support for browsers that do not support @media queries,
17
+ /// (IE <= 8, Firefox <= 3, Opera <= 9)
18
+ ///
19
+ /// You could create a stylesheet served exclusively to older browsers,
20
+ /// where @media queries are rasterized
21
+ ///
22
+ /// @example scss
23
+ /// // old-ie.scss
24
+ /// $mq-responsive : false;
25
+ /// @import 'main'; // @media queries in this file will be rasterized up to $mq-static-breakpoint
26
+ /// // larger breakpoints will be ignored
27
+ ///
28
+ /// @type Boolean
29
+ /// @link https://github.com/sass-mq/sass-mq#responsive-mode-off Disabled responsive mode documentation
30
+ $mq-responsive : true !default ;
31
+
32
+ /// Breakpoint list
33
+ ///
34
+ /// Name your breakpoints in a way that creates a ubiquitous language
35
+ /// across team members. It will improve communication between
36
+ /// stakeholders, designers, developers, and testers.
37
+ ///
38
+ /// @type Map
39
+ /// @link https://github.com/sass-mq/sass-mq#seeing-the-currently-active-breakpoint Full documentation and examples
40
+ $mq-breakpoints : (
41
+ mobile : 320px ,
42
+ tablet : 740px ,
43
+ desktop : 980px ,
44
+ wide : 1300px
45
+ ) !default ;
46
+
47
+ /// Static breakpoint (for fixed-width layouts)
48
+ ///
49
+ /// Define the breakpoint from $mq-breakpoints that should
50
+ /// be used as the target width for the fixed-width layout
51
+ /// (i.e. when $mq-responsive is set to 'false') in a old-ie.scss
52
+ ///
53
+ /// @example scss
54
+ /// // tablet-only.scss
55
+ /// //
56
+ /// // Ignore all styles above tablet breakpoint,
57
+ /// // and fix the styles (such as the layout) at tablet width
58
+ /// $mq-responsive : false;
59
+ /// $mq-static-breakpoint : tablet;
60
+ /// @import 'main'; // @media queries in this file will be rasterized up to tablet
61
+ /// // larger breakpoints will be ignored
62
+ ///
63
+ /// @type String
64
+ /// @link https://github.com/sass-mq/sass-mq#adding-custom-breakpoints Full documentation and examples
65
+ $mq-static-breakpoint : desktop !default ;
66
+
67
+ /// Show breakpoints in the top right corner
68
+ ///
69
+ /// If you want to display the currently active breakpoint in the top
70
+ /// right corner of your site during development, add the breakpoints
71
+ /// to this list, ordered by width. For example: (mobile, tablet, desktop).
72
+ ///
73
+ /// @example scss
74
+ /// $mq-show-breakpoints : (mobile, tablet, desktop);
75
+ /// @import 'path/to/mq';
76
+ ///
77
+ /// @type map
78
+ $mq-show-breakpoints : () !default ;
79
+
80
+ /// Customize the media type (for example: `@media screen` or `@media print`)
81
+ /// By default sass-mq uses an "all" media type (`@media all and …`)
82
+ ///
83
+ /// @type String
84
+ /// @link https://github.com/sass-mq/sass-mq#changing-media-type Full documentation and examples
85
+ $mq-media-type : all !default ;
86
+
87
+ /// Convert pixels to ems
88
+ ///
89
+ /// @param {Number} $px - value to convert
90
+ /// @ignore @param {Number} $base-font-size [$mq-base-font-size] - `<body>` font size (deprecated)
91
+ ///
92
+ /// @example scss
93
+ /// $font-size-in-ems : mq-px2em (16px );
94
+ /// p { font-size : mq-px2em (16px ); }
95
+ ///
96
+ /// @requires $mq-base-font-size
97
+ /// @returns {Number}
98
+ @function mq-px2em($px, $base-font-size: $mq-base-font-size) {
99
+ @if ($mq-base-font-size != 16px ) {
100
+ @warn " Overriding $mq-base-font-size will break things, see https://github.com/sass-mq/sass-mq/issues/122." ;
101
+ }
102
+ @if ($base-font-size != 16px ) {
103
+ @warn " The $base-font-size argument will be removed in sass-mq v6.0.0, as overriding it breaks things, see https://github.com/sass-mq/sass-mq/issues/122." ;
104
+ }
105
+ @if unitless ($px ) {
106
+ @warn " Assuming #{$px } to be in pixels, attempting to convert it into pixels." ;
107
+ @return mq-px2em ($px * 1px , $base-font-size );
108
+ } @else if unit ($px ) == em {
109
+ @return $px ;
110
+ }
111
+ @return ($px / $base-font-size ) * 1em ;
112
+ }
113
+
114
+ /// Get a breakpoint's width
115
+ ///
116
+ /// @param {String} $name - Name of the breakpoint. One of $mq-breakpoints
117
+ ///
118
+ /// @example scss
119
+ /// $tablet-width : mq-get-breakpoint-width (tablet );
120
+ /// @media (min-width: mq-get-breakpoint-width(desktop)) {}
121
+ ///
122
+ /// @requires {Variable} $mq-breakpoints
123
+ ///
124
+ /// @returns {Number} Value in pixels
125
+ @function mq-get-breakpoint-width ($name , $breakpoints : $mq-breakpoints ) {
126
+ @if map-has-key ($breakpoints , $name ) {
127
+ @return map-get ($breakpoints , $name );
128
+ } @else {
129
+ @warn " Breakpoint #{$name } wasn't found in $breakpoints." ;
130
+ }
131
+ }
132
+
133
+ /// Media Query mixin
134
+ ///
135
+ /// @param {String | Boolean} $from [false] - One of $mq-breakpoints
136
+ /// @param {String | Boolean} $until [false] - One of $mq-breakpoints
137
+ /// @param {String | Boolean} $and [false] - Additional media query parameters
138
+ /// @param {String} $media-type [$mq-media-type] - Media type: screen, print…
139
+ ///
140
+ /// @ignore Undocumented API, for advanced use only:
141
+ /// @ignore @param {Map} $breakpoints [$mq-breakpoints]
142
+ /// @ignore @param {String} $static-breakpoint [$mq-static-breakpoint]
143
+ ///
144
+ /// @content styling rules, wrapped into a @media query when $responsive is true
145
+ ///
146
+ /// @requires {Variable} $mq-media-type
147
+ /// @requires {Variable} $mq-breakpoints
148
+ /// @requires {Variable} $mq-static-breakpoint
149
+ /// @requires {function} mq-px2em
150
+ /// @requires {function} mq-get-breakpoint-width
151
+ ///
152
+ /// @link https://github.com/sass-mq/sass-mq#responsive-mode-on-default Full documentation and examples
153
+ ///
154
+ /// @example scss
155
+ /// .element {
156
+ /// @include mq($from: mobile) {
157
+ /// color: red;
158
+ /// }
159
+ /// @include mq($until: tablet) {
160
+ /// color: blue;
161
+ /// }
162
+ /// @include mq(mobile, tablet) {
163
+ /// color: green;
164
+ /// }
165
+ /// @include mq($from: tablet, $and: '(orientation: landscape)') {
166
+ /// color: teal;
167
+ /// }
168
+ /// @include mq(950px) {
169
+ /// color: hotpink;
170
+ /// }
171
+ /// @include mq(tablet, $media-type: screen) {
172
+ /// color: hotpink;
173
+ /// }
174
+ /// // Advanced use:
175
+ /// $my-breakpoints: (L: 900px, XL: 1200px);
176
+ /// @include mq(L, $breakpoints: $my-breakpoints, $static-breakpoint: L) {
177
+ /// color: hotpink;
178
+ /// }
179
+ /// }
180
+ @mixin mq (
181
+ $from : false,
182
+ $until : false,
183
+ $and : false,
184
+ $media-type : $mq-media-type ,
185
+ $breakpoints : $mq-breakpoints ,
186
+ $responsive : $mq-responsive ,
187
+ $static-breakpoint : $mq-static-breakpoint
188
+ ) {
189
+ $min-width : 0 ;
190
+ $max-width : 0 ;
191
+ $media-query : ' ' ;
192
+
193
+ // From: this breakpoint (inclusive)
194
+ @if $from {
195
+ @if type-of ($from ) == number {
196
+ $min-width : mq-px2em ($from );
197
+ } @else {
198
+ $min-width : mq-px2em (mq-get-breakpoint-width ($from , $breakpoints ));
199
+ }
200
+ }
201
+
202
+ // Until: that breakpoint (exclusive)
203
+ @if $until {
204
+ @if type-of ($until ) == number {
205
+ $max-width : mq-px2em ($until );
206
+ } @else {
207
+ $max-width : mq-px2em (mq-get-breakpoint-width ($until , $breakpoints )) - .01em ;
208
+ }
209
+ }
210
+
211
+ // Responsive support is disabled, rasterize the output outside @media blocks
212
+ // The browser will rely on the cascade itself.
213
+ @if $responsive == false {
214
+ $static-breakpoint-width : mq-get-breakpoint-width ($static-breakpoint , $breakpoints );
215
+ $target-width : mq-px2em ($static-breakpoint-width );
216
+
217
+ // Output only rules that start at or span our target width
218
+ @if (
219
+ $and == false
220
+ and $min-width <= $target-width
221
+ and (
222
+ $until == false or $max-width >= $target-width
223
+ )
224
+ and $media-type != ' print'
225
+ ) {
226
+ @content ;
227
+ }
228
+ }
229
+
230
+ // Responsive support is enabled, output rules inside @media queries
231
+ @else {
232
+ @if $min-width != 0 { $media-query : ' #{$media-query } and (min-width: #{$min-width } )' ; }
233
+ @if $max-width != 0 { $media-query : ' #{$media-query } and (max-width: #{$max-width } )' ; }
234
+ @if $and { $media-query : ' #{$media-query } and #{$and } ' ; }
235
+
236
+ // Remove unnecessary media query prefix 'all and '
237
+ @if ($media-type == ' all' and $media-query != ' ' ) {
238
+ $media-type : ' ' ;
239
+ $media-query : str-slice (unquote ($media-query ), 6 );
240
+ }
241
+
242
+ @media #{$media-type + $media-query } {
243
+ @content ;
244
+ }
245
+ }
246
+ }
247
+
248
+ /// Quick sort
249
+ ///
250
+ /// @author Sam Richards
251
+ /// @access private
252
+ /// @param {List} $list - List to sort
253
+ /// @returns {List} Sorted List
254
+ @function _mq-quick-sort ($list ) {
255
+ $less : ();
256
+ $equal : ();
257
+ $large : ();
258
+
259
+ @if length ($list ) > 1 {
260
+ $seed : nth ($list , ceil (length ($list ) / 2 ));
261
+
262
+ @each $item in $list {
263
+ @if ($item == $seed ) {
264
+ $equal : append ($equal , $item );
265
+ } @else if ($item < $seed ) {
266
+ $less : append ($less , $item );
267
+ } @else if ($item > $seed ) {
268
+ $large : append ($large , $item );
269
+ }
270
+ }
271
+
272
+ @return join (join (_mq-quick-sort ($less ), $equal ), _mq-quick-sort ($large ));
273
+ }
274
+
275
+ @return $list ;
276
+ }
277
+
278
+ /// Sort a map by values (works with numbers only)
279
+ ///
280
+ /// @access private
281
+ /// @param {Map} $map - Map to sort
282
+ /// @returns {Map} Map sorted by value
283
+ @function _mq-map-sort-by-value ($map ) {
284
+ $map-sorted : ();
285
+ $map-keys : map-keys ($map );
286
+ $map-values : map-values ($map );
287
+ $map-values-sorted : _mq-quick-sort ($map-values );
288
+
289
+ // Reorder key/value pairs based on key values
290
+ @each $value in $map-values-sorted {
291
+ $index : index ($map-values , $value );
292
+ $key : nth ($map-keys , $index );
293
+ $map-sorted : map-merge ($map-sorted , ($key : $value ));
294
+
295
+ // Unset the value in $map-values to prevent the loop
296
+ // from finding the same index twice
297
+ $map-values : set-nth ($map-values , $index , 0 );
298
+ }
299
+
300
+ @return $map-sorted ;
301
+ }
302
+
303
+ /// Add a breakpoint
304
+ ///
305
+ /// @param {String} $name - Name of the breakpoint
306
+ /// @param {Number} $width - Width of the breakpoint
307
+ ///
308
+ /// @requires {Variable} $mq-breakpoints
309
+ ///
310
+ /// @example scss
311
+ /// @include mq-add-breakpoint(tvscreen, 1920px);
312
+ /// @include mq(tvscreen) {}
313
+ @mixin mq-add-breakpoint ($name , $width ) {
314
+ $new-breakpoint : ($name : $width );
315
+ $mq-breakpoints : map-merge ($mq-breakpoints , $new-breakpoint ) !global;
316
+ $mq-breakpoints : _mq-map-sort-by-value ($mq-breakpoints ) !global;
317
+ }
318
+
319
+ /// Show the active breakpoint in the top right corner of the viewport
320
+ /// @link https://github.com/sass-mq/sass-mq#seeing-the-currently-active-breakpoint
321
+ ///
322
+ /// @param {List} $show-breakpoints [$mq-show-breakpoints] - List of breakpoints to show in the top right corner
323
+ /// @param {Map} $breakpoints [$mq-breakpoints] - Breakpoint names and sizes
324
+ ///
325
+ /// @requires {Variable} $mq-breakpoints
326
+ /// @requires {Variable} $mq-show-breakpoints
327
+ ///
328
+ /// @example scss
329
+ /// // Show breakpoints using global settings
330
+ /// @include mq-show-breakpoints;
331
+ ///
332
+ /// // Show breakpoints using custom settings
333
+ /// @include mq-show-breakpoints((L, XL), (S: 300px, L: 800px, XL: 1200px));
334
+ @mixin mq-show-breakpoints ($show-breakpoints : $mq-show-breakpoints , $breakpoints : $mq-breakpoints ) {
335
+ body :before {
336
+ background-color : #FCF8E3 ;
337
+ border-bottom : 1px solid #FBEED5 ;
338
+ border-left : 1px solid #FBEED5 ;
339
+ color : #C09853 ;
340
+ font : small-caption ;
341
+ padding : 3px 6px ;
342
+ pointer-events : none ;
343
+ position : fixed ;
344
+ right : 0 ;
345
+ top : 0 ;
346
+ z-index : 100 ;
347
+
348
+ // Loop through the breakpoints that should be shown
349
+ @each $show-breakpoint in $show-breakpoints {
350
+ $width : mq-get-breakpoint-width ($show-breakpoint , $breakpoints );
351
+ @include mq ($show-breakpoint , $breakpoints : $breakpoints ) {
352
+ content : " #{$show-breakpoint } ≥ #{$width } (#{mq-px2em ($width )} )" ;
353
+ }
354
+ }
355
+ }
356
+ }
357
+
358
+ @if length ($mq-show-breakpoints ) > 0 {
359
+ @include mq-show-breakpoints ;
360
+ }
0 commit comments