Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 1... Línea 1...
1
// stylelint-disable property-blacklist, scss/dollar-variable-default
1
// stylelint-disable scss/dimension-no-non-numeric-values
Línea 2... Línea 2...
2
 
2
 
3
// SCSS RFS mixin
3
// SCSS RFS mixin
4
//
4
//
5
// Automated responsive font sizes
5
// Automated responsive values for font sizes, paddings, margins and much more
6
//
6
//
Línea 7... Línea 7...
7
// Licensed under MIT (https://github.com/twbs/rfs/blob/v8.x/LICENSE)
7
// Licensed under MIT (https://github.com/twbs/rfs/blob/main/LICENSE)
Línea 8... Línea 8...
8
 
8
 
9
// Configuration
9
// Configuration
10
 
10
 
Línea 11... Línea 11...
11
// Base font size
11
// Base value
12
$rfs-base-font-size: 1.25rem !default;
12
$rfs-base-value: 1.25rem !default;
13
$rfs-font-size-unit: rem !default;
13
$rfs-unit: rem !default;
Línea 14... Línea 14...
14
 
14
 
15
@if $rfs-font-size-unit != rem and $rfs-font-size-unit != px {
15
@if $rfs-unit != rem and $rfs-unit != px {
16
  @error "`#{$rfs-font-size-unit}` is not a valid unit for $rfs-font-size-unit. Use `px` or `rem`.";
16
  @error "`#{$rfs-unit}` is not a valid unit for $rfs-unit. Use `px` or `rem`.";
Línea 17... Línea 17...
17
}
17
}
18
 
18
 
19
// Breakpoint at where font-size starts decreasing if screen width is smaller
19
// Breakpoint at where values start decreasing if screen width is smaller
Línea 20... Línea 20...
20
$rfs-breakpoint: 1200px !default;
20
$rfs-breakpoint: 1200px !default;
21
$rfs-breakpoint-unit: px !default;
21
$rfs-breakpoint-unit: px !default;
Línea 22... Línea 22...
22
 
22
 
23
@if $rfs-breakpoint-unit != px and $rfs-breakpoint-unit != em and $rfs-breakpoint-unit != rem {
23
@if $rfs-breakpoint-unit != px and $rfs-breakpoint-unit != em and $rfs-breakpoint-unit != rem {
Línea 24... Línea 24...
24
  @error "`#{$rfs-breakpoint-unit}` is not a valid unit for $rfs-breakpoint-unit. Use `px`, `em` or `rem`.";
24
  @error "`#{$rfs-breakpoint-unit}` is not a valid unit for $rfs-breakpoint-unit. Use `px`, `em` or `rem`.";
25
}
25
}
26
 
26
 
Línea -... Línea 27...
-
 
27
// Resize values based on screen height and width
-
 
28
$rfs-two-dimensional: false !default;
-
 
29
 
27
// Resize font size based on screen height and width
30
// Factor of decrease
28
$rfs-two-dimensional: false !default;
31
$rfs-factor: 10 !default;
Línea 29... Línea 32...
29
 
32
 
30
// Factor of decrease
33
@if type-of($rfs-factor) != number or $rfs-factor <= 1 {
Línea 31... Línea 34...
31
$rfs-factor: 10 !default;
34
  @error "`#{$rfs-factor}` is not a valid  $rfs-factor, it must be greater than 1.";
32
 
35
}
Línea 33... Línea 36...
33
@if type-of($rfs-factor) != "number" or $rfs-factor <= 1 {
36
 
34
  @error "`#{$rfs-factor}` is not a valid  $rfs-factor, it must be greater than 1.";
37
// Mode. Possibilities: "min-media-query", "max-media-query"
Línea 35... Línea 38...
35
}
38
$rfs-mode: min-media-query !default;
36
 
39
 
Línea 37... Línea 40...
37
// Generate enable or disable classes. Possibilities: false, "enable" or "disable"
40
// Generate enable or disable classes. Possibilities: false, "enable" or "disable"
38
$rfs-class: false !default;
41
$rfs-class: false !default;
39
 
42
 
40
// 1 rem = $rfs-rem-value px
43
// 1 rem = $rfs-rem-value px
Línea 89... Línea 92...
89
    $result: $result * map-get($unit-map, $dividend-unit);
92
    $result: $result * map-get($unit-map, $dividend-unit);
90
  }
93
  }
91
  @return $result;
94
  @return $result;
92
}
95
}
Línea 93... Línea 96...
93
 
96
 
94
// Remove px-unit from $rfs-base-font-size for calculations
97
// Remove px-unit from $rfs-base-value for calculations
95
@if $rfs-base-font-size-unit == "px" {
98
@if $rfs-base-value-unit == px {
96
  $rfs-base-font-size: divide($rfs-base-font-size, $rfs-base-font-size * 0 + 1);
99
  $rfs-base-value: divide($rfs-base-value, $rfs-base-value * 0 + 1);
97
}
100
}
98
@else if $rfs-base-font-size-unit == "rem" {
101
@else if $rfs-base-value-unit == rem {
99
  $rfs-base-font-size: divide($rfs-base-font-size, divide($rfs-base-font-size * 0 + 1, $rfs-rem-value));
102
  $rfs-base-value: divide($rfs-base-value, divide($rfs-base-value * 0 + 1, $rfs-rem-value));
Línea 100... Línea 103...
100
}
103
}
101
 
104
 
Línea 102... Línea 105...
102
// Cache $rfs-breakpoint unit to prevent multiple calls
105
// Cache $rfs-breakpoint unit to prevent multiple calls
103
$rfs-breakpoint-unit-cache: unit($rfs-breakpoint);
106
$rfs-breakpoint-unit-cache: unit($rfs-breakpoint);
104
 
107
 
105
// Remove unit from $rfs-breakpoint for calculations
108
// Remove unit from $rfs-breakpoint for calculations
106
@if $rfs-breakpoint-unit-cache == "px" {
109
@if $rfs-breakpoint-unit-cache == px {
107
  $rfs-breakpoint: divide($rfs-breakpoint, $rfs-breakpoint * 0 + 1);
110
  $rfs-breakpoint: divide($rfs-breakpoint, $rfs-breakpoint * 0 + 1);
108
}
111
}
Línea -... Línea 112...
-
 
112
@else if $rfs-breakpoint-unit-cache == rem or $rfs-breakpoint-unit-cache == "em" {
-
 
113
  $rfs-breakpoint: divide($rfs-breakpoint, divide($rfs-breakpoint * 0 + 1, $rfs-rem-value));
-
 
114
}
-
 
115
 
-
 
116
// Calculate the media query value
109
@else if $rfs-breakpoint-unit-cache == "rem" or $rfs-breakpoint-unit-cache == "em" {
117
$rfs-mq-value: if($rfs-breakpoint-unit == px, #{$rfs-breakpoint}px, #{divide($rfs-breakpoint, $rfs-rem-value)}#{$rfs-breakpoint-unit});
110
  $rfs-breakpoint: divide($rfs-breakpoint, divide($rfs-breakpoint * 0 + 1, $rfs-rem-value));
118
$rfs-mq-property-width: if($rfs-mode == max-media-query, max-width, min-width);
111
}
119
$rfs-mq-property-height: if($rfs-mode == max-media-query, max-height, min-height);
-
 
120
 
112
 
121
// Internal mixin used to determine which media query needs to be used
-
 
122
@mixin _rfs-media-query {
-
 
123
  @if $rfs-two-dimensional {
113
// Internal mixin that adds disable classes to the selector if needed.
124
    @if $rfs-mode == max-media-query {
114
@mixin _rfs-disable-class {
125
      @media (#{$rfs-mq-property-width}: #{$rfs-mq-value}), (#{$rfs-mq-property-height}: #{$rfs-mq-value}) {
115
  @if $rfs-class == "disable" {
126
        @content;
116
    // Adding an extra class increases specificity, which prevents the media query to override the font size
127
      }
-
 
128
    }
117
    &,
129
    @else {
118
    .disable-responsive-font-size &,
130
      @media (#{$rfs-mq-property-width}: #{$rfs-mq-value}) and (#{$rfs-mq-property-height}: #{$rfs-mq-value}) {
119
    &.disable-responsive-font-size {
131
        @content;
-
 
132
      }
120
      @content;
133
    }
-
 
134
  }
121
    }
135
  @else {
122
  }
136
    @media (#{$rfs-mq-property-width}: #{$rfs-mq-value}) {
Línea 123... Línea 137...
123
  @else {
137
      @content;
124
    @content;
138
    }
125
  }
139
  }
-
 
140
}
-
 
141
 
126
}
142
// Internal mixin that adds disable classes to the selector if needed.
127
 
143
@mixin _rfs-rule {
128
// Internal mixin that adds enable classes to the selector if needed.
144
  @if $rfs-class == disable and $rfs-mode == max-media-query {
129
@mixin _rfs-enable-class {
145
    // Adding an extra class increases specificity, which prevents the media query to override the property
130
  @if $rfs-class == "enable" {
146
    &,
-
 
147
    .disable-rfs &,
-
 
148
    &.disable-rfs {
-
 
149
      @content;
-
 
150
    }
-
 
151
  }
131
    .enable-responsive-font-size &,
152
  @else if $rfs-class == enable and $rfs-mode == min-media-query {
132
    &.enable-responsive-font-size {
153
    .enable-rfs &,
133
      @content;
154
    &.enable-rfs {
134
    }
155
      @content;
Línea 135... Línea 156...
135
  }
156
    }
136
  @else {
157
  } @else {
-
 
158
    @content;
137
    @content;
159
  }
138
  }
160
}
139
}
161
 
140
 
162
// Internal mixin that adds enable classes to the selector if needed.
-
 
163
@mixin _rfs-media-query-rule {
-
 
164
 
-
 
165
  @if $rfs-class == enable {
-
 
166
    @if $rfs-mode == min-media-query {
-
 
167
      @content;
-
 
168
    }
-
 
169
 
141
// Internal mixin used to determine which media query needs to be used
170
    @include _rfs-media-query () {
142
@mixin _rfs-media-query($mq-value) {
171
      .enable-rfs &,
-
 
172
      &.enable-rfs {
-
 
173
        @content;
-
 
174
      }
-
 
175
    }
-
 
176
  }
-
 
177
  @else {
143
  @if $rfs-two-dimensional {
178
    @if $rfs-class == disable and $rfs-mode == min-media-query {
144
    @media (max-width: #{$mq-value}), (max-height: #{$mq-value}) {
179
      .disable-rfs &,
145
      @content;
180
      &.disable-rfs {
146
    }
181
        @content;
147
  }
182
      }
Línea 148... Línea 183...
148
  @else {
183
    }
149
    @media (max-width: #{$mq-value}) {
184
    @include _rfs-media-query () {
150
      @content;
185
      @content;
151
    }
186
    }
152
  }
187
  }
153
}
188
}
154
 
-
 
155
// Responsive font size mixin
189
 
156
@mixin rfs($fs, $important: false) {
-
 
157
  // Cache $fs unit
-
 
158
  $fs-unit: if(type-of($fs) == "number", unit($fs), false);
190
// Helper function to get the formatted non-responsive value
159
 
-
 
160
  // Add !important suffix if needed
-
 
161
  $rfs-suffix: if($important, " !important", "");
191
@function rfs-value($values) {
162
 
192
  // Convert to list
163
  // If $fs isn't a number (like inherit) or $fs has a unit (not px or rem, like 1.5em) or $ is 0, just print the value
193
  $values: if(type-of($values) != list, ($values,), $values);
164
  @if not $fs-unit or $fs-unit != "" and $fs-unit != "px" and $fs-unit != "rem" or $fs == 0 {
194
 
165
    font-size: #{$fs}#{$rfs-suffix};
-
 
166
  }
-
 
167
  @else {
195
  $val: "";
168
    // Remove unit from $fs for calculations
-
 
169
    @if $fs-unit == "px" {
196
 
170
      $fs: divide($fs, $fs * 0 + 1);
197
  // Loop over each value and calculate value
Línea -... Línea 198...
-
 
198
  @each $value in $values {
-
 
199
    @if $value == 0 {
171
    }
200
      $val: $val + " 0";
-
 
201
    }
-
 
202
    @else {
-
 
203
      // Cache $value unit
172
    @else if $fs-unit == "rem" {
204
      $unit: if(type-of($value) == "number", unit($value), false);
-
 
205
 
-
 
206
      @if $unit == px {
173
      $fs: divide($fs, divide($fs * 0 + 1, $rfs-rem-value));
207
        // Convert to rem if needed
-
 
208
        $val: $val + " " + if($rfs-unit == rem, #{divide($value, $value * 0 + $rfs-rem-value)}rem, $value);
174
    }
209
      }
175
 
210
      @else if $unit == rem {
176
    // Set default font size
-
 
177
    $rfs-static: if($rfs-font-size-unit == rem, #{divide($fs, $rfs-rem-value)}rem, #{$fs}px);
-
 
Línea 178... Línea 211...
178
 
211
        // Convert to px if needed
179
    // Only add the media query if the font size is bigger than the minimum font size
212
        $val: $val + " " + if($rfs-unit == px, #{divide($value, $value * 0 + 1) * $rfs-rem-value}px, $value);
-
 
213
      } @else {
Línea -... Línea 214...
-
 
214
        // If $value isn't a number (like inherit) or $value has a unit (not px or rem, like 1.5em) or $ is 0, just print the value
-
 
215
        $val: $val + " " + $value;
-
 
216
      }
-
 
217
    }
-
 
218
  }
-
 
219
 
-
 
220
  // Remove first space
-
 
221
  @return unquote(str-slice($val, 2));
-
 
222
}
-
 
223
 
-
 
224
// Helper function to get the responsive value calculated by RFS
-
 
225
@function rfs-fluid-value($values) {
180
    @if $fs <= $rfs-base-font-size or not $enable-responsive-font-sizes {
226
  // Convert to list
-
 
227
  $values: if(type-of($values) != list, ($values,), $values);
-
 
228
 
-
 
229
  $val: "";
-
 
230
 
-
 
231
  // Loop over each value and calculate value
-
 
232
  @each $value in $values {
-
 
233
    @if $value == 0 {
-
 
234
      $val: $val + " 0";
-
 
235
    } @else {
-
 
236
      // Cache $value unit
-
 
237
      $unit: if(type-of($value) == "number", unit($value), false);
181
      font-size: #{$rfs-static}#{$rfs-suffix};
238
 
-
 
239
      // If $value isn't a number (like inherit) or $value has a unit (not px or rem, like 1.5em) or $ is 0, just print the value
-
 
240
      @if not $unit or $unit != px and $unit != rem {
-
 
241
        $val: $val + " " + $value;
-
 
242
      } @else {
Línea 182... Línea 243...
182
    }
243
        // Remove unit from $value for calculations
183
    @else {
244
        $value: divide($value, $value * 0 + if($unit == px, 1, divide(1, $rfs-rem-value)));
Línea 184... Línea 245...
184
      // Calculate the minimum font size for $fs
245
 
185
      $fs-min: $rfs-base-font-size + divide($fs - $rfs-base-font-size, $rfs-factor);
246
        // Only add the media query if the value is greater than the minimum value
Línea 186... Línea 247...
186
 
247
        @if abs($value) <= $rfs-base-value or not $enable-rfs {
187
      // Calculate difference between $fs and the minimum font size
248
          $val: $val + " " + if($rfs-unit == rem, #{divide($value, $rfs-rem-value)}rem, #{$value}px);
Línea 188... Línea 249...
188
      $fs-diff: $fs - $fs-min;
249
        }
189
 
250
        @else {
Línea 190... Línea 251...
190
      // Base font-size formatting
251
          // Calculate the minimum value
191
      $min-width: if($rfs-font-size-unit == rem, #{divide($fs-min, $rfs-rem-value)}rem, #{$fs-min}px);
252
          $value-min: $rfs-base-value + divide(abs($value) - $rfs-base-value, $rfs-factor);
192
 
-
 
Línea 193... Línea 253...
193
      // Use `vmin` if two-dimensional is enabled
253
 
194
      $variable-unit: if($rfs-two-dimensional, vmin, vw);
254
          // Calculate difference between $value and the minimum value
195
 
-
 
196
      // Calculate the variable width between 0 and $rfs-breakpoint
255
          $value-diff: abs($value) - $value-min;
-
 
256
 
-
 
257
          // Base value formatting
-
 
258
          $min-width: if($rfs-unit == rem, #{divide($value-min, $rfs-rem-value)}rem, #{$value-min}px);
-
 
259
 
-
 
260
          // Use negative value if needed
-
 
261
          $min-width: if($value < 0, -$min-width, $min-width);
-
 
262
 
-
 
263
          // Use `vmin` if two-dimensional is enabled
-
 
264
          $variable-unit: if($rfs-two-dimensional, vmin, vw);
-
 
265
 
-
 
266
          // Calculate the variable width between 0 and $rfs-breakpoint
-
 
267
          $variable-width: #{divide($value-diff * 100, $rfs-breakpoint)}#{$variable-unit};
-
 
268
 
-
 
269
          // Return the calculated value
-
 
270
          $val: $val + " calc(" + $min-width + if($value < 0, " - ", " + ") + $variable-width + ")";
-
 
271
        }
-
 
272
      }
-
 
273
    }
-
 
274
  }
-
 
275
 
-
 
276
  // Remove first space
Línea 197... Línea 277...
197
      $variable-width: #{divide($fs-diff * 100, $rfs-breakpoint)}#{$variable-unit};
277
  @return unquote(str-slice($val, 2));
198
 
278
}
199
      // Set the calculated font-size
279
 
-
 
280
// RFS mixin
-
 
281
@mixin rfs($values, $property: font-size) {
-
 
282
  @if $values != null {
-
 
283
    $val: rfs-value($values);
200
      $rfs-fluid: calc(#{$min-width} + #{$variable-width}) #{$rfs-suffix};
284
    $fluid-val: rfs-fluid-value($values);
201
 
285
 
202
      // Breakpoint formatting
286
    // Do not print the media query if responsive & non-responsive values are the same
Línea 203... Línea 287...
203
      $mq-value: if($rfs-breakpoint-unit == px, #{$rfs-breakpoint}px, #{divide($rfs-breakpoint, $rfs-rem-value)}#{$rfs-breakpoint-unit});
287
    @if $val == $fluid-val {
204
 
288
      #{$property}: $val;
-
 
289
    }
-
 
290
    @else {
-
 
291
      @include _rfs-rule () {
-
 
292
        #{$property}: if($rfs-mode == max-media-query, $val, $fluid-val);
205
      @include _rfs-disable-class {
293
 
-
 
294
        // Include safari iframe resize fix if needed
-
 
295
        min-width: if($rfs-safari-iframe-resize-bug-fix, (0 * 1vw), null);
-
 
296
      }
-
 
297
 
-
 
298
      @include _rfs-media-query-rule () {
-
 
299
        #{$property}: if($rfs-mode == max-media-query, $fluid-val, $val);
-
 
300
      }
-
 
301
    }
-
 
302
  }
-
 
303
}
-
 
304
 
-
 
305
// Shorthand helper mixins
-
 
306
@mixin font-size($value) {
-
 
307
  @include rfs($value);
-
 
308
}
-
 
309
 
-
 
310
@mixin padding($value) {
-
 
311
  @include rfs($value, padding);
-
 
312
}
-
 
313
 
-
 
314
@mixin padding-top($value) {
-
 
315
  @include rfs($value, padding-top);
-
 
316
}
-
 
317
 
-
 
318
@mixin padding-right($value) {
-
 
319
  @include rfs($value, padding-right);
-
 
320
}
-
 
321
 
-
 
322
@mixin padding-bottom($value) {
-
 
323
  @include rfs($value, padding-bottom);
-
 
324
}
-
 
325
 
206
        font-size: #{$rfs-static}#{$rfs-suffix};
326
@mixin padding-left($value) {
Línea 207... Línea 327...
207
      }
327
  @include rfs($value, padding-left);
208
 
328
}
209
      @include _rfs-media-query($mq-value) {
329