2022-05-12 16:15:44 +02:00
|
|
|
// ==========================================================================
|
2017-02-08 11:43:28 -05:00
|
|
|
// Tools / Functions
|
|
|
|
|
// ==========================================================================
|
2016-12-18 15:45:44 -05:00
|
|
|
|
2022-05-25 16:02:15 +02:00
|
|
|
// Check if the given value is a number in pixel
|
|
|
|
|
//
|
|
|
|
|
// @param {Number} $number - The value to check
|
|
|
|
|
// @return {Boolean}
|
|
|
|
|
|
|
|
|
|
@function is-pixel-number($number) {
|
|
|
|
|
@return type-of($number) == number and unit($number) == "px";
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-08 11:43:28 -05:00
|
|
|
// Converts the given pixel value to its EM quivalent.
|
|
|
|
|
//
|
|
|
|
|
// @param {Number} $size - The pixel value to convert.
|
|
|
|
|
// @param {Number} $base [$font-size] - The assumed base font size.
|
|
|
|
|
// @return {Number} Scalable pixel value in EMs.
|
2022-05-12 16:15:44 +02:00
|
|
|
|
2017-02-08 11:43:28 -05:00
|
|
|
@function em($size, $base: $font-size) {
|
2022-05-25 16:02:15 +02:00
|
|
|
@if not is-pixel-number($size) {
|
|
|
|
|
@error "`#{$size}` needs to be a number in pixel.";
|
2016-12-18 15:45:44 -05:00
|
|
|
}
|
|
|
|
|
|
2022-05-25 16:02:15 +02:00
|
|
|
@if not is-pixel-number($base) {
|
|
|
|
|
@error "`#{$base}` needs to be a number in pixel.";
|
2016-12-18 15:45:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@return ($size / $base) * 1em;
|
2016-03-11 11:02:59 -05:00
|
|
|
}
|
|
|
|
|
|
2017-02-08 11:43:28 -05:00
|
|
|
// Converts the given pixel value to its REM quivalent.
|
|
|
|
|
//
|
|
|
|
|
// @param {Number} $size - The pixel value to convert.
|
|
|
|
|
// @param {Number} $base [$font-size] - The assumed base font size.
|
|
|
|
|
// @return {Number} Scalable pixel value in REMs.
|
2022-05-12 16:15:44 +02:00
|
|
|
|
2017-02-08 11:43:28 -05:00
|
|
|
@function rem($size, $base: $font-size) {
|
2022-05-25 16:02:15 +02:00
|
|
|
|
|
|
|
|
@if not is-pixel-number($size) {
|
|
|
|
|
@error "`#{$size}` needs to be a number in pixel.";
|
2016-12-18 15:45:44 -05:00
|
|
|
}
|
|
|
|
|
|
2022-05-25 16:02:15 +02:00
|
|
|
@if not is-pixel-number($base) {
|
|
|
|
|
@error "`#{$base}` needs to be a number in pixel.";
|
2016-12-18 15:45:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@return ($size / $base) * 1rem;
|
2016-03-11 11:02:59 -05:00
|
|
|
}
|
2016-12-18 15:45:44 -05:00
|
|
|
|
2022-05-25 13:54:03 +02:00
|
|
|
// Retrieves the z-index from the {@see $layers master list}.
|
2022-05-20 11:44:42 +02:00
|
|
|
//
|
|
|
|
|
// @link on http://css-tricks.com/handling-z-index/
|
2022-05-25 13:54:03 +02:00
|
|
|
//
|
|
|
|
|
// @param {string} $layer The name of the z-index.
|
|
|
|
|
// @param {number} $modifier A positive or negative modifier to apply
|
|
|
|
|
// to the returned z-index value.
|
|
|
|
|
// @throw Error if the $layer does not exist.
|
|
|
|
|
// @throw Warning if the $modifier might overlap another master z-index.
|
|
|
|
|
// @return {number} The computed z-index of $layer and $modifier.
|
|
|
|
|
|
|
|
|
|
@function z($layer, $modifier: 0) {
|
2022-08-25 14:45:24 -04:00
|
|
|
@if not map-has-key($z-indexes, $layer) {
|
2022-05-25 13:54:03 +02:00
|
|
|
@error "Unknown master z-index layer: #{$layer}";
|
2022-05-20 11:44:42 +02:00
|
|
|
}
|
|
|
|
|
|
2022-05-25 13:54:03 +02:00
|
|
|
@if ($modifier >= 50 or $modifier <= -50) {
|
|
|
|
|
@warn "Modifier may overlap the another master z-index layer: #{$modifier}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$index: map-get($z-indexes, $layer);
|
|
|
|
|
|
|
|
|
|
@return $index + $modifier;
|
2022-05-20 11:44:42 +02:00
|
|
|
}
|
|
|
|
|
|
2017-02-08 11:43:28 -05:00
|
|
|
// Converts a number to a percentage.
|
|
|
|
|
//
|
|
|
|
|
// @alias percentage()
|
|
|
|
|
// @link http://sassdoc.com/annotations/#alias
|
|
|
|
|
// @param {Number} $number - The value to convert.
|
|
|
|
|
// @return {Number} A percentage.
|
2022-05-12 16:15:44 +02:00
|
|
|
|
2016-12-18 15:45:44 -05:00
|
|
|
@function span($number) {
|
|
|
|
|
@return percentage($number);
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-08 11:43:28 -05:00
|
|
|
// Checks if a list contains a value(s).
|
|
|
|
|
//
|
|
|
|
|
// @link https://github.com/thoughtbot/bourbon/blob/master/core/bourbon/validators/_contains.scss
|
|
|
|
|
// @param {List} $list - The list to check against.
|
|
|
|
|
// @param {List} $values - A single value or list of values to check for.
|
|
|
|
|
// @return {Boolean}
|
|
|
|
|
// @access private
|
2022-05-12 16:15:44 +02:00
|
|
|
|
2016-12-18 15:45:44 -05:00
|
|
|
@function list-contains(
|
|
|
|
|
$list,
|
|
|
|
|
$values...
|
|
|
|
|
) {
|
|
|
|
|
@each $value in $values {
|
|
|
|
|
@if type-of(index($list, $value)) != "number" {
|
|
|
|
|
@return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-08 11:43:28 -05:00
|
|
|
// Resolve whether a rule is important or not.
|
|
|
|
|
//
|
|
|
|
|
// @param {Boolean} $flag - Whether a rule is important (TRUE) or not (FALSE).
|
|
|
|
|
// @return {String|Null} Returns `!important` or NULL.
|
2022-05-12 16:15:44 +02:00
|
|
|
|
2017-02-08 11:43:28 -05:00
|
|
|
@function important($flag: false) {
|
2016-12-18 15:45:44 -05:00
|
|
|
@if ($flag == true) {
|
|
|
|
|
@return !important;
|
2022-05-25 13:54:03 +02:00
|
|
|
} @else if ($important == false) {
|
2016-12-18 15:45:44 -05:00
|
|
|
@return null;
|
|
|
|
|
} @else {
|
2022-05-12 16:15:44 +02:00
|
|
|
@error "`#{$flag}` needs to be `true` or `false`.";
|
2016-12-18 15:45:44 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-08 11:43:28 -05:00
|
|
|
// Determine if the current context is for a WYSIWYG editor.
|
|
|
|
|
//
|
|
|
|
|
// @requires {String} $context - The global context of the stylesheet.
|
|
|
|
|
// @return {Boolean} If the $context is set to "editor".
|
2022-05-12 16:15:44 +02:00
|
|
|
|
2017-02-08 11:43:28 -05:00
|
|
|
@function is-editor() {
|
2016-12-18 15:45:44 -05:00
|
|
|
@return ('editor' == $context);
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-08 11:43:28 -05:00
|
|
|
// Determine if the current context is for the front-end.
|
|
|
|
|
//
|
|
|
|
|
// @requires {String} $context - The global context of the stylesheet.
|
|
|
|
|
// @return {Boolean} If the $context is set to "frontend".
|
2022-05-12 16:15:44 +02:00
|
|
|
|
2017-02-08 11:43:28 -05:00
|
|
|
@function is-frontend() {
|
2016-12-18 15:45:44 -05:00
|
|
|
@return ('frontend' == $context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$context: 'frontend' !default;
|
2023-01-04 10:50:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Calculate grid space
|
|
|
|
|
* @param {number} $number The percentage spacer
|
|
|
|
|
* @return {number} in calc
|
|
|
|
|
*/
|
|
|
|
|
@function grid-space($percentage, $offset: 0) {
|
|
|
|
|
// @return calc(#{$percentage} * (100vw - 2 * var(--grid-margin)) - (1 - #{$percentage}) * var(--grid-gutter) + #{$offset} * var(--grid-gutter));
|
|
|
|
|
@return calc(#{$percentage} * (100vw - 2 * var(--grid-margin, 0px)) - (1 - #{$percentage}) * var(--grid-gutter, 0px) + #{$offset} * var(--grid-gutter, 0px));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Calculate vh percentage from number
|
|
|
|
|
* @param {number} $number The percentage number
|
|
|
|
|
* @return {number} in vh
|
|
|
|
|
*/
|
|
|
|
|
@function vh($number) {
|
|
|
|
|
@return calc(#{$number} * var(--vh, 1vh));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Remove the unit of a length
|
|
|
|
|
* @param {Number} $number - Number to remove unit from
|
|
|
|
|
* @return {Number} - Unitless number
|
|
|
|
|
*/
|
|
|
|
|
@function strip-unit($number) {
|
|
|
|
|
@if type-of($number) == 'number' and not unitless($number) {
|
|
|
|
|
@return $number / ($number * 0 + 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@return $number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Responsive font size
|
|
|
|
|
* @param {Number} $min-size - Minimum font size in pixel
|
|
|
|
|
* @param {Number} $max-size - Maximum font size in pixel
|
|
|
|
|
* @param {Number} $breakpoint - The breakpoint
|
|
|
|
|
* @return {Number} - Clamped font size based on breakpoint
|
|
|
|
|
*/
|
|
|
|
|
@function responsive-type($min-size, $max-size, $breakpoint) {
|
2023-01-04 14:41:25 +01:00
|
|
|
@return clamp($min-size, calc(#{strip-unit($max-size)}/#{strip-unit(#{$breakpoint})} * 100vw), $max-size);
|
2023-01-04 10:50:36 +01:00
|
|
|
}
|