2016-09-04 17:11:58 +02:00
|
|
|
////
|
2020-02-10 12:34:58 +01:00
|
|
|
/// Copyright (c) 2016-2020 Martin Donath <martin.donath@squidfunk.com>
|
2016-09-04 17:11:58 +02:00
|
|
|
///
|
|
|
|
/// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
/// copy of this software and associated documentation files (the "Software"),
|
|
|
|
/// to deal in the Software without restriction, including without limitation
|
|
|
|
/// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
/// and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
/// Software is furnished to do so, subject to the following conditions:
|
|
|
|
///
|
|
|
|
/// The above copyright notice and this permission notice shall be included in
|
|
|
|
/// all copies or substantial portions of the Software.
|
|
|
|
///
|
|
|
|
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
/// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
/// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
/// DEALINGS
|
|
|
|
////
|
2016-01-28 23:27:15 +01:00
|
|
|
|
2016-09-04 17:32:12 +02:00
|
|
|
// ----------------------------------------------------------------------------
|
2016-10-06 12:14:33 +02:00
|
|
|
// Helpers
|
2016-09-04 17:32:12 +02:00
|
|
|
// ----------------------------------------------------------------------------
|
2016-01-28 23:27:15 +01:00
|
|
|
|
2020-05-25 17:19:42 +02:00
|
|
|
///
|
|
|
|
/// Strip units from a number
|
|
|
|
///
|
|
|
|
@function strip-units($number) {
|
|
|
|
@return $number / ($number * 0 + 1);
|
|
|
|
}
|
|
|
|
|
2020-02-25 20:25:05 +01:00
|
|
|
///
|
|
|
|
/// Convert color in HEX to HSL
|
|
|
|
///
|
2020-05-25 17:19:42 +02:00
|
|
|
/// Note, that we need to strip the `deg` units from the `hue` value, as they
|
|
|
|
/// were added in Color Level 4, which not all browsers support.
|
|
|
|
///
|
2020-02-25 20:25:05 +01:00
|
|
|
@function hex2hsl($color) {
|
|
|
|
@return
|
2020-05-25 17:19:42 +02:00
|
|
|
round(strip-units(hue($color))),
|
2020-02-25 20:25:05 +01:00
|
|
|
round(saturation($color)),
|
|
|
|
round(lightness($color));
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2016-09-04 17:32:12 +02:00
|
|
|
///
|
2020-02-24 18:07:50 +01:00
|
|
|
/// Convert font size in px to em
|
2016-09-04 17:32:12 +02:00
|
|
|
///
|
2016-08-07 18:01:56 +02:00
|
|
|
@function px2em($size, $base: 16px) {
|
|
|
|
@if unit($size) == px {
|
2016-09-08 22:29:26 +02:00
|
|
|
@if unit($base) == px {
|
2017-01-01 15:59:44 +01:00
|
|
|
@return ($size / $base) * 1em;
|
2016-09-08 22:29:26 +02:00
|
|
|
} @else {
|
|
|
|
@error "Invalid base: #{$base} - unit must be 'px'";
|
|
|
|
}
|
2016-08-07 18:01:56 +02:00
|
|
|
} @else {
|
2016-09-08 22:29:26 +02:00
|
|
|
@error "Invalid size: #{$size} - unit must be 'px'";
|
2016-01-28 23:27:15 +01:00
|
|
|
}
|
|
|
|
}
|
2019-02-12 19:13:08 +01:00
|
|
|
|
|
|
|
///
|
2020-02-24 18:07:50 +01:00
|
|
|
/// Convert font size in px to rem
|
2019-02-12 19:13:08 +01:00
|
|
|
///
|
|
|
|
@function px2rem($size, $base: 20px) {
|
|
|
|
@if unit($size) == px {
|
|
|
|
@if unit($base) == px {
|
|
|
|
@return ($size / $base) * 1.0rem;
|
|
|
|
} @else {
|
|
|
|
@error "Invalid base: #{$base} - unit must be 'px'";
|
|
|
|
}
|
|
|
|
} @else {
|
|
|
|
@error "Invalid size: #{$size} - unit must be 'px'";
|
|
|
|
}
|
|
|
|
}
|