@justeattakeaway/pie-css 0.30.0 → 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@justeattakeaway/pie-css",
3
- "version": "0.30.0",
3
+ "version": "0.31.0",
4
4
  "description": "A styling library that provides both a shared collection of ready to use CSS styles to be used across JET web front-ends, and SCSS-based style helpers for our PIE Web Component library.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,7 +1,6 @@
1
1
  //
2
2
  // !IMPORTANT: This file is a copy of the original include-media SCSS library
3
3
  // !DO NOT directly edit this file/
4
- //
5
4
  // _ _ _ _ _
6
5
  // (_) | | | | | (_)
7
6
  // _ _ __ ___| |_ _ __| | ___ _ __ ___ ___ __| |_ __ _
@@ -178,50 +177,10 @@ $im-no-media-breakpoint: 'desktop' !default;
178
177
  $im-no-media-expressions: ('screen', 'portrait', 'landscape') !default;
179
178
 
180
179
  ////
181
- /// Cross-engine logging engine
182
- /// @author Kitty Giraudel
180
+ /// Determines whether a list of conditions is intercepted by the static breakpoint.
183
181
  /// @access private
184
182
  ////
185
183
 
186
- ///
187
- /// Log a message either with `@error` if supported
188
- /// else with `@warn`, using `feature-exists('at-error')`
189
- /// to detect support.
190
- ///
191
- /// @param {String} $message - Message to log
192
- ///
193
- @function im-log($message) {
194
- @if meta.feature-exists('at-error') {
195
- @error $message;
196
- } @else {
197
- @warn $message;
198
-
199
- $_: noop();
200
- }
201
-
202
- @return $message;
203
- }
204
-
205
- ///
206
- /// Wrapper mixin for the log function so it can be used with a more friendly
207
- /// API than `@if im-log('..') {}` or `$_: im-log('..')`. Basically, use the function
208
- /// within functions because it is not possible to include a mixin in a function
209
- /// and use the mixin everywhere else because it's much more elegant.
210
- ///
211
- /// @param {String} $message - Message to log
212
- ///
213
- @mixin log($message) {
214
- @if im-log($message) {
215
- }
216
- }
217
-
218
- ///
219
- /// Function with no `@return` called next to `@warn` in Sass 3.3
220
- /// to trigger a compiling error and stop the process.
221
- ///
222
- @function noop() {
223
- }
224
-
225
184
  ///
226
185
  /// Determines whether a list of conditions is intercepted by the static breakpoint.
227
186
  ///
@@ -233,8 +192,7 @@ $im-no-media-expressions: ('screen', 'portrait', 'landscape') !default;
233
192
  $no-media-breakpoint-value: map.get($breakpoints, $im-no-media-breakpoint);
234
193
 
235
194
  @if not $no-media-breakpoint-value {
236
- @if im-log('`#{$im-no-media-breakpoint}` is not a valid breakpoint.') {
237
- }
195
+ @error '#{$im-no-media-breakpoint}` is not a valid breakpoint.';
238
196
  }
239
197
 
240
198
  @each $condition in $conditions {
@@ -276,12 +234,7 @@ $im-no-media-expressions: ('screen', 'portrait', 'landscape') !default;
276
234
  }
277
235
  }
278
236
 
279
- // It is not possible to include a mixin inside a function, so we have to
280
- // rely on the `im-log(..)` function rather than the `log(..)` mixin. Because
281
- // functions cannot be called anywhere in Sass, we need to hack the call in
282
- // a dummy variable, such as `$_`. If anybody ever raise a scoping issue with
283
- // Sass 3.3, change this line in `@if im-log(..) {}` instead.
284
- $_: im-log('No operator found in `#{$expression}`.');
237
+ @error 'No operator found in `#{$expression}`.';
285
238
  }
286
239
 
287
240
  ///
@@ -295,6 +248,7 @@ $im-no-media-expressions: ('screen', 'portrait', 'landscape') !default;
295
248
  @function get-expression-dimension($expression, $operator) {
296
249
  $operator-index: string.index($expression, $operator);
297
250
  $parsed-dimension: string.slice($expression, 0, $operator-index - 1);
251
+ $parsed-dimension: str-trim($parsed-dimension);
298
252
  $dimension: 'width';
299
253
 
300
254
  @if string.length($parsed-dimension) > 0 {
@@ -312,7 +266,11 @@ $im-no-media-expressions: ('screen', 'portrait', 'landscape') !default;
312
266
  /// @return {String} - `min` or `max`
313
267
  ///
314
268
  @function get-expression-prefix($operator) {
315
- @return if(list.index(('<', '<=', '≤'), $operator), 'max', 'min');
269
+ @if list.index(('<', '<=', '≤'), $operator) {
270
+ @return 'max';
271
+ } @else {
272
+ @return 'min';
273
+ }
316
274
  }
317
275
 
318
276
  ///
@@ -326,22 +284,18 @@ $im-no-media-expressions: ('screen', 'portrait', 'landscape') !default;
326
284
  @function get-expression-value($expression, $operator) {
327
285
  $operator-index: string.index($expression, $operator);
328
286
  $value: string.slice($expression, $operator-index + string.length($operator));
287
+ $trimmedValue: str-trim($value);
329
288
 
330
- @if map.has-key($breakpoints, $value) {
331
- $value: map.get($breakpoints, $value);
289
+ @if map.has-key($breakpoints, $trimmedValue) {
290
+ $value: map.get($breakpoints, $trimmedValue);
332
291
  } @else {
333
- $value: to-number($value);
292
+ $value: to-number($trimmedValue);
334
293
  }
335
294
 
336
295
  $interval: map.get($unit-intervals, math.unit($value));
337
296
 
338
297
  @if not $interval {
339
- // It is not possible to include a mixin inside a function, so we have to
340
- // rely on the `im-log(..)` function rather than the `log(..)` mixin. Because
341
- // functions cannot be called anywhere in Sass, we need to hack the call in
342
- // a dummy variable, such as `$_`. If anybody ever raise a scoping issue with
343
- // Sass 3.3, change this line in `@if im-log(..) {}` instead.
344
- $_: im-log('Unknown unit `#{math.unit($value)}`.');
298
+ @error 'Unknown unit `#{math.unit($value)}`.';
345
299
  }
346
300
 
347
301
  @if $operator == '>' {
@@ -418,7 +372,7 @@ $im-no-media-expressions: ('screen', 'portrait', 'landscape') !default;
418
372
  @if meta.type-of($value) == 'number' {
419
373
  @return $value;
420
374
  } @else if meta.type-of($value) != 'string' {
421
- $_: im-log('Value for `to-number` should be a number or a string.');
375
+ @error 'Value for `to-number` should be a number or a string.';
422
376
  }
423
377
 
424
378
  $first-character: string.slice($value, 1, 1);
@@ -439,15 +393,20 @@ $im-no-media-expressions: ('screen', 'portrait', 'landscape') !default;
439
393
  );
440
394
 
441
395
  // Remove +/- sign if present at first character
442
- @if $first-character == '+' or $first-character == '-' {
396
+ @if ($first-character == '+' or $first-character == '-') {
443
397
  $value: string.slice($value, 2);
444
398
  }
445
399
 
400
+ $sign: 1;
401
+ @if $minus {
402
+ $sign: -1;
403
+ }
404
+
446
405
  @for $i from 1 through string.length($value) {
447
406
  $character: string.slice($value, $i, $i);
448
407
 
449
408
  @if not(list.index(map.keys($numbers), $character) or $character == '.') {
450
- @return to-length(if($minus, -$result, $result), string.slice($value, $i));
409
+ @return to-length($sign * $result, string.slice($value, $i));
451
410
  }
452
411
 
453
412
  @if $character == '.' {
@@ -460,7 +419,7 @@ $im-no-media-expressions: ('screen', 'portrait', 'landscape') !default;
460
419
  }
461
420
  }
462
421
 
463
- @return if($minus, -$result, $result);
422
+ @return $sign * $result;
464
423
  }
465
424
 
466
425
  ///
@@ -491,12 +450,36 @@ $im-no-media-expressions: ('screen', 'portrait', 'landscape') !default;
491
450
  );
492
451
 
493
452
  @if not list.index(map.keys($units), $unit) {
494
- $_: im-log('Invalid unit `#{$unit}`.');
453
+ @error 'Invalid unit `#{$unit}`.';
495
454
  }
496
455
 
497
456
  @return $value * map.get($units, $unit);
498
457
  }
499
458
 
459
+ ////
460
+ /// String trim
461
+ /// @author Jack McNicol
462
+ /// @access private
463
+ ////
464
+
465
+ ///
466
+ /// Trims a string of leading and trailing spaces
467
+ ///
468
+ /// @param {String} $string - Value to be trimmed
469
+ ///
470
+ /// @return {String}
471
+ ///
472
+
473
+ @function str-trim($string) {
474
+ @if (string.slice($string, 1, 1) == ' ') {
475
+ @return str-trim(string.slice($string, 2));
476
+ } @else if (string.slice($string, string.length($string), -1) == ' ') {
477
+ @return str-trim(string.slice($string, 1, -2));
478
+ } @else {
479
+ @return $string;
480
+ }
481
+ }
482
+
500
483
  ///
501
484
  /// This mixin aims at redefining the configuration just for the scope of
502
485
  /// the call. It is helpful when having a component needing an extended
@@ -585,10 +568,11 @@ $im-no-media-expressions: ('screen', 'portrait', 'landscape') !default;
585
568
  (not $im-media-support and im-intercepts-static-breakpoint($conditions...))
586
569
  {
587
570
  @content;
588
- } @else if $im-media-support and list.length($conditions) > 0 {
571
+ } @else if ($im-media-support and list.length($conditions) > 0) {
589
572
  @media #{string.unquote(parse-expression(list.nth($conditions, 1)))} {
590
573
  // Recursive call
591
- @include media(slice($conditions, 2)...) {
574
+ $sliced-conditions: slice($conditions, 2);
575
+ @include media($sliced-conditions...) {
592
576
  @content;
593
577
  }
594
578
  }