Back to home page

EIC code displayed by LXR

 
 

    


Warning, /iDDS/monitor/data/scss/bootstrap/_functions.scss is written in an unsupported language. File is not indexed.

0001 // Bootstrap functions
0002 //
0003 // Utility mixins and functions for evaluating source code across our variables, maps, and mixins.
0004 
0005 // Ascending
0006 // Used to evaluate Sass maps like our grid breakpoints.
0007 @mixin _assert-ascending($map, $map-name) {
0008   $prev-key: null;
0009   $prev-num: null;
0010   @each $key, $num in $map {
0011     @if $prev-num == null or unit($num) == "%" or unit($prev-num) == "%" {
0012       // Do nothing
0013     } @else if not comparable($prev-num, $num) {
0014       @warn "Potentially invalid value for #{$map-name}: This map must be in ascending order, but key '#{$key}' has value #{$num} whose unit makes it incomparable to #{$prev-num}, the value of the previous key '#{$prev-key}' !";
0015     } @else if $prev-num >= $num {
0016       @warn "Invalid value for #{$map-name}: This map must be in ascending order, but key '#{$key}' has value #{$num} which isn't greater than #{$prev-num}, the value of the previous key '#{$prev-key}' !";
0017     }
0018     $prev-key: $key;
0019     $prev-num: $num;
0020   }
0021 }
0022 
0023 // Starts at zero
0024 // Used to ensure the min-width of the lowest breakpoint starts at 0.
0025 @mixin _assert-starts-at-zero($map, $map-name: "$grid-breakpoints") {
0026   @if length($map) > 0 {
0027     $values: map-values($map);
0028     $first-value: nth($values, 1);
0029     @if $first-value != 0 {
0030       @warn "First breakpoint in #{$map-name} must start at 0, but starts at #{$first-value}.";
0031     }
0032   }
0033 }
0034 
0035 // Internal Bootstrap function to turn maps into its negative variant.
0036 // It prefixes the keys with `n` and makes the value negative.
0037 @function negativify-map($map) {
0038   $result: ();
0039   @each $key, $value in $map {
0040     @if $key != 0 {
0041       $result: map-merge($result, ("n" + $key: (-$value)));
0042     }
0043   }
0044   @return $result;
0045 }
0046 
0047 // Get multiple keys from a sass map
0048 @function map-get-multiple($map, $values) {
0049   $result: ();
0050   @each $key, $value in $map {
0051     @if (index($values, $key) != null) {
0052       $result: map-merge($result, ($key: $value));
0053     }
0054   }
0055   @return $result;
0056 }
0057 
0058 // Replace `$search` with `$replace` in `$string`
0059 // Used on our SVG icon backgrounds for custom forms.
0060 //
0061 // @author Hugo Giraudel
0062 // @param {String} $string - Initial string
0063 // @param {String} $search - Substring to replace
0064 // @param {String} $replace ('') - New value
0065 // @return {String} - Updated string
0066 @function str-replace($string, $search, $replace: "") {
0067   $index: str-index($string, $search);
0068 
0069   @if $index {
0070     @return str-slice($string, 1, $index - 1) + $replace + str-replace(str-slice($string, $index + str-length($search)), $search, $replace);
0071   }
0072 
0073   @return $string;
0074 }
0075 
0076 // See https://codepen.io/kevinweber/pen/dXWoRw
0077 //
0078 // Requires the use of quotes around data URIs.
0079 
0080 @function escape-svg($string) {
0081   @if str-index($string, "data:image/svg+xml") {
0082     @each $char, $encoded in $escaped-characters {
0083       // Do not escape the url brackets
0084       @if str-index($string, "url(") == 1 {
0085         $string: url("#{str-replace(str-slice($string, 6, -3), $char, $encoded)}");
0086       } @else {
0087         $string: str-replace($string, $char, $encoded);
0088       }
0089     }
0090   }
0091 
0092   @return $string;
0093 }
0094 
0095 // Color contrast
0096 // See https://github.com/twbs/bootstrap/pull/30168
0097 
0098 // A list of pre-calculated numbers of pow(($value / 255 + .055) / 1.055, 2.4). (from 0 to 255)
0099 // stylelint-disable-next-line scss/dollar-variable-default, scss/dollar-variable-pattern
0100 $_luminance-list: .0008 .001 .0011 .0013 .0015 .0017 .002 .0022 .0025 .0027 .003 .0033 .0037 .004 .0044 .0048 .0052 .0056 .006 .0065 .007 .0075 .008 .0086 .0091 .0097 .0103 .011 .0116 .0123 .013 .0137 .0144 .0152 .016 .0168 .0176 .0185 .0194 .0203 .0212 .0222 .0232 .0242 .0252 .0262 .0273 .0284 .0296 .0307 .0319 .0331 .0343 .0356 .0369 .0382 .0395 .0409 .0423 .0437 .0452 .0467 .0482 .0497 .0513 .0529 .0545 .0561 .0578 .0595 .0612 .063 .0648 .0666 .0685 .0704 .0723 .0742 .0762 .0782 .0802 .0823 .0844 .0865 .0887 .0908 .0931 .0953 .0976 .0999 .1022 .1046 .107 .1095 .1119 .1144 .117 .1195 .1221 .1248 .1274 .1301 .1329 .1356 .1384 .1413 .1441 .147 .15 .1529 .1559 .159 .162 .1651 .1683 .1714 .1746 .1779 .1812 .1845 .1878 .1912 .1946 .1981 .2016 .2051 .2086 .2122 .2159 .2195 .2232 .227 .2307 .2346 .2384 .2423 .2462 .2502 .2542 .2582 .2623 .2664 .2705 .2747 .2789 .2831 .2874 .2918 .2961 .3005 .305 .3095 .314 .3185 .3231 .3278 .3325 .3372 .3419 .3467 .3515 .3564 .3613 .3663 .3712 .3763 .3813 .3864 .3916 .3968 .402 .4072 .4125 .4179 .4233 .4287 .4342 .4397 .4452 .4508 .4564 .4621 .4678 .4735 .4793 .4851 .491 .4969 .5029 .5089 .5149 .521 .5271 .5333 .5395 .5457 .552 .5583 .5647 .5711 .5776 .5841 .5906 .5972 .6038 .6105 .6172 .624 .6308 .6376 .6445 .6514 .6584 .6654 .6724 .6795 .6867 .6939 .7011 .7084 .7157 .7231 .7305 .7379 .7454 .7529 .7605 .7682 .7758 .7835 .7913 .7991 .807 .8148 .8228 .8308 .8388 .8469 .855 .8632 .8714 .8796 .8879 .8963 .9047 .9131 .9216 .9301 .9387 .9473 .956 .9647 .9734 .9823 .9911 1;
0101 
0102 @function color-contrast($background, $color-contrast-dark: $color-contrast-dark, $color-contrast-light: $color-contrast-light, $min-contrast-ratio: $min-contrast-ratio) {
0103   $foregrounds: $color-contrast-light, $color-contrast-dark, $white, $black;
0104   $max-ratio: 0;
0105   $max-ratio-color: null;
0106 
0107   @each $color in $foregrounds {
0108     $contrast-ratio: contrast-ratio($background, $color);
0109     @if $contrast-ratio > $min-contrast-ratio {
0110       @return $color;
0111     } @else if $contrast-ratio > $max-ratio {
0112       $max-ratio: $contrast-ratio;
0113       $max-ratio-color: $color;
0114     }
0115   }
0116 
0117   @warn "Found no color leading to #{$min-contrast-ratio}:1 contrast ratio against #{$background}...";
0118 
0119   @return $max-ratio-color;
0120 }
0121 
0122 @function contrast-ratio($background, $foreground: $color-contrast-light) {
0123   $l1: luminance($background);
0124   $l2: luminance(opaque($background, $foreground));
0125 
0126   @return if($l1 > $l2, ($l1 + .05) / ($l2 + .05), ($l2 + .05) / ($l1 + .05));
0127 }
0128 
0129 // Return WCAG2.0 relative luminance
0130 // See https://www.w3.org/WAI/GL/wiki/Relative_luminance
0131 // See https://www.w3.org/TR/WCAG20-TECHS/G17.html#G17-tests
0132 @function luminance($color) {
0133   $rgb: (
0134     "r": red($color),
0135     "g": green($color),
0136     "b": blue($color)
0137   );
0138 
0139   @each $name, $value in $rgb {
0140     $value: if($value / 255 < .03928, $value / 255 / 12.92, nth($_luminance-list, $value + 1));
0141     $rgb: map-merge($rgb, ($name: $value));
0142   }
0143 
0144   @return (map-get($rgb, "r") * .2126) + (map-get($rgb, "g") * .7152) + (map-get($rgb, "b") * .0722);
0145 }
0146 
0147 // Return opaque color
0148 // opaque(#fff, rgba(0, 0, 0, .5)) => #808080
0149 @function opaque($background, $foreground) {
0150   @return mix(rgba($foreground, 1), $background, opacity($foreground) * 100);
0151 }
0152 
0153 // scss-docs-start color-functions
0154 // Tint a color: mix a color with white
0155 @function tint-color($color, $weight) {
0156   @return mix(white, $color, $weight);
0157 }
0158 
0159 // Shade a color: mix a color with black
0160 @function shade-color($color, $weight) {
0161   @return mix(black, $color, $weight);
0162 }
0163 
0164 // Shade the color if the weight is positive, else tint it
0165 @function shift-color($color, $weight) {
0166   @return if($weight > 0, shade-color($color, $weight), tint-color($color, -$weight));
0167 }
0168 // scss-docs-end color-functions
0169 
0170 // Return valid calc
0171 @function add($value1, $value2, $return-calc: true) {
0172   @if $value1 == null {
0173     @return $value2;
0174   }
0175 
0176   @if $value2 == null {
0177     @return $value1;
0178   }
0179 
0180   @if type-of($value1) == number and type-of($value2) == number and comparable($value1, $value2) {
0181     @return $value1 + $value2;
0182   }
0183 
0184   @return if($return-calc == true, calc(#{$value1} + #{$value2}), $value1 + unquote(" + ") + $value2);
0185 }
0186 
0187 @function subtract($value1, $value2, $return-calc: true) {
0188   @if $value1 == null and $value2 == null {
0189     @return null;
0190   }
0191 
0192   @if $value1 == null {
0193     @return -$value2;
0194   }
0195 
0196   @if $value2 == null {
0197     @return $value1;
0198   }
0199 
0200   @if type-of($value1) == number and type-of($value2) == number and comparable($value1, $value2) {
0201     @return $value1 - $value2;
0202   }
0203 
0204   @return if($return-calc == true, calc(#{$value1} - #{$value2}), $value1 + unquote(" - ") + $value2);
0205 }