| 1 |
//// |
| 2 |
/// Copyright (c) 2016-2020 Martin Donath <[email protected]> |
| 3 |
/// |
| 4 |
/// Permission is hereby granted, free of charge, to any person obtaining a |
| 5 |
/// copy of this software and associated documentation files (the "Software"), |
| 6 |
/// to deal in the Software without restriction, including without limitation |
| 7 |
/// the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 |
/// and/or sell copies of the Software, and to permit persons to whom the |
| 9 |
/// Software is furnished to do so, subject to the following conditions: |
| 10 |
/// |
| 11 |
/// The above copyright notice and this permission notice shall be included in |
| 12 |
/// all copies or substantial portions of the Software. |
| 13 |
/// |
| 14 |
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 |
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 |
/// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL |
| 17 |
/// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 |
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 19 |
/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 20 |
/// DEALINGS |
| 21 |
//// |
| 22 |
@use "sass:color"; |
| 23 |
@use "sass:math"; |
| 24 |
|
| 25 |
// ---------------------------------------------------------------------------- |
| 26 |
// Helpers |
| 27 |
// ---------------------------------------------------------------------------- |
| 28 |
|
| 29 |
/// |
| 30 |
/// Convert color in HEX to HSL |
| 31 |
/// |
| 32 |
@function hex2hsl($color) { |
| 33 |
@return |
| 34 |
math.round(color.channel($color, "hue", $space: hsl)), |
| 35 |
math.round(color.channel($color, "saturation", $space: hsl)), |
| 36 |
math.round(color.channel($color, "lightness", $space: hsl)); |
| 37 |
} |
| 38 |
|
| 39 |
// ---------------------------------------------------------------------------- |
| 40 |
|
| 41 |
/// |
| 42 |
/// Convert font size in px to em |
| 43 |
/// |
| 44 |
@function px2em($size, $base: 16px) { |
| 45 |
@if math.unit($size) == px { |
| 46 |
@if math.unit($base) == px { |
| 47 |
@return math.div($size, $base) * 1em; |
| 48 |
} @else { |
| 49 |
@error "Invalid base: #{$base} - unit must be 'px'"; |
| 50 |
} |
| 51 |
} @else { |
| 52 |
@error "Invalid size: #{$size} - unit must be 'px'"; |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
/// |
| 57 |
/// Convert font size in px to rem |
| 58 |
/// |
| 59 |
@function px2rem($size, $base: 20px) { |
| 60 |
@if math.unit($size) == px { |
| 61 |
@if math.unit($base) == px { |
| 62 |
@return math.div($size, $base) * 1.0rem; |
| 63 |
} @else { |
| 64 |
@error "Invalid base: #{$base} - unit must be 'px'"; |
| 65 |
} |
| 66 |
} @else { |
| 67 |
@error "Invalid size: #{$size} - unit must be 'px'"; |
| 68 |
} |
| 69 |
} |