"Fossies" - the Fresh Open Source Software Archive

Member "bulma/sass/utilities/functions.sass" (8 May 2022, 4896 Bytes) of package /linux/www/bulma-0.9.4.zip:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "functions.sass": 0.9.3_vs_0.9.4.

    1 @function mergeColorMaps($bulma-colors, $custom-colors)
    2   // We return at least Bulma's hard-coded colors
    3   $merged-colors: $bulma-colors
    4 
    5   // We want a map as input
    6   @if type-of($custom-colors) == 'map'
    7     @each $name, $components in $custom-colors
    8       // The color name should be a string
    9       // and the components either a single color
   10       // or a colors list with at least one element
   11       @if type-of($name) == 'string' and (type-of($components) == 'list' or type-of($components) == 'color') and length($components) >= 1
   12         $color-base: null
   13         $color-invert: null
   14         $color-light: null
   15         $color-dark: null
   16         $value: null
   17 
   18         // The param can either be a single color
   19         // or a list of 2 colors
   20         @if type-of($components) == 'color'
   21           $color-base: $components
   22           $color-invert: findColorInvert($color-base)
   23           $color-light: findLightColor($color-base)
   24           $color-dark: findDarkColor($color-base)
   25         @else if type-of($components) == 'list'
   26           $color-base: nth($components, 1)
   27           // If Invert, Light and Dark are provided
   28           @if length($components) > 3
   29             $color-invert: nth($components, 2)
   30             $color-light: nth($components, 3)
   31             $color-dark: nth($components, 4)
   32             // If only Invert and Light are provided
   33           @else if length($components) > 2
   34             $color-invert: nth($components, 2)
   35             $color-light: nth($components, 3)
   36             $color-dark: findDarkColor($color-base)
   37             // If only Invert is provided
   38           @else
   39             $color-invert: nth($components, 2)
   40             $color-light: findLightColor($color-base)
   41             $color-dark: findDarkColor($color-base)
   42 
   43         $value: ($color-base, $color-invert, $color-light, $color-dark)
   44 
   45         // We only want to merge the map if the color base is an actual color
   46         @if type-of($color-base) == 'color'
   47           // We merge this colors elements as map with Bulma's colors map
   48           // (we can override them this way, no multiple definition for the same name)
   49           // $merged-colors: map_merge($merged-colors, ($name: ($color-base, $color-invert, $color-light, $color-dark)))
   50           $merged-colors: map_merge($merged-colors, ($name: $value))
   51 
   52   @return $merged-colors
   53 
   54 @function powerNumber($number, $exp)
   55   $value: 1
   56   @if $exp > 0
   57     @for $i from 1 through $exp
   58       $value: $value * $number
   59   @else if $exp < 0
   60     @for $i from 1 through -$exp
   61       $value: divide($value, $number)
   62   @return $value
   63 
   64 @function colorLuminance($color)
   65   @if type-of($color) != 'color'
   66     @return 0.55
   67   $color-rgb: ('red': red($color),'green': green($color),'blue': blue($color))
   68   @each $name, $value in $color-rgb
   69     $adjusted: 0
   70     $value: divide($value, 255)
   71     @if $value < 0.03928
   72       $value: divide($value, 12.92)
   73     @else
   74       $value: divide(($value + .055), 1.055)
   75       $value: powerNumber($value, 2)
   76     $color-rgb: map-merge($color-rgb, ($name: $value))
   77   @return (map-get($color-rgb, 'red') * .2126) + (map-get($color-rgb, 'green') * .7152) + (map-get($color-rgb, 'blue') * .0722)
   78 
   79 @function findColorInvert($color)
   80   @if (colorLuminance($color) > 0.55)
   81     @return rgba(#000, 0.7)
   82   @else
   83     @return #fff
   84 
   85 @function findLightColor($color, $l: 96%)
   86   @if type-of($color) == 'color'
   87     $l: 96%
   88     @if lightness($color) > 96%
   89       $l: lightness($color)
   90     @return change-color($color, $lightness: $l)
   91   @return $background
   92 
   93 @function findDarkColor($color, $base-l: 29%)
   94   @if type-of($color) == 'color'
   95     $luminance: colorLuminance($color)
   96     $luminance-delta: (0.53 - $luminance)
   97     $target-l: round($base-l + ($luminance-delta * 53))
   98     @return change-color($color, $lightness: max($base-l, $target-l))
   99   @return $text-strong
  100 
  101 @function bulmaRgba($color, $alpha)
  102   @if type-of($color) != 'color'
  103     @return $color
  104   @return rgba($color, $alpha)
  105 
  106 @function bulmaDarken($color, $amount)
  107   @if type-of($color) != 'color'
  108     @return $color
  109   @return darken($color, $amount)
  110 
  111 @function bulmaLighten($color, $amount)
  112   @if type-of($color) != 'color'
  113     @return $color
  114   @return lighten($color, $amount)
  115 
  116 // Custom divide function by @mdo from https://github.com/twbs/bootstrap/pull/34245
  117 // Replaces old slash division deprecated in Dart Sass
  118 @function divide($dividend, $divisor, $precision: 10)
  119   $sign: if($dividend > 0 and $divisor > 0, 1, -1)
  120   $dividend: abs($dividend)
  121   $divisor: abs($divisor)
  122   $quotient: 0
  123   $remainder: $dividend
  124   @if $dividend == 0
  125     @return 0
  126   @if $divisor == 0
  127     @error "Cannot divide by 0"
  128   @if $divisor == 1
  129     @return $dividend
  130   @while $remainder >= $divisor
  131     $quotient: $quotient + 1
  132     $remainder: $remainder - $divisor
  133   @if $remainder > 0 and $precision > 0
  134     $remainder: divide($remainder * 10, $divisor, $precision - 1) * .1
  135   @return ($quotient + $remainder) * $sign