bulma/sass/utilities/functions.sass

63 lines
2.3 KiB
Sass
Raw Normal View History

2018-04-08 13:38:59 +00:00
@function mergeColorMaps($bulma-colors, $custom-colors)
// we return at least bulma hardcoded colors
$merged-colors: $bulma-colors
2018-04-08 15:06:57 +00:00
// we want a map as input
@if type-of($custom-colors) == 'map'
@each $name, $components in $custom-colors
// color name should be a string and colors pair a list with at least one element
@if type-of($name) == 'string' and (type-of($components) == 'list' or type-of($components) == 'color') and length($components) >= 1
2018-04-08 13:38:59 +00:00
$color-base: null
2018-04-08 15:06:57 +00:00
// the param can either be a single color
// or a list of 2 colors
2018-04-08 13:38:59 +00:00
@if type-of($components) == 'color'
$color-base: $components
@else if type-of($components) == 'list'
$color-base: nth($components, 1)
2018-04-08 15:06:57 +00:00
$color-invert: null
2018-04-08 15:06:57 +00:00
// is an inverted color provided in the list
@if length($components) > 1
$color-invert: nth($components, 2)
2018-04-08 15:06:57 +00:00
// we only want a color as base color
@if type-of($color-base) == 'color'
// if inverted color is not provided or is not a color we compute it
@if type-of($color-invert) != 'color'
$color-invert: findColorInvert($color-base)
2018-04-08 15:06:57 +00:00
// we merge this colors elements as map with bulma colors (we can override them this way, no multiple definition for the same name)
$merged-colors: map_merge($merged-colors, ($name: ($color-base, $color-invert)))
2018-04-08 15:06:57 +00:00
@return $merged-colors
2016-01-24 00:03:43 +00:00
@function powerNumber($number, $exp)
$value: 1
@if $exp > 0
@for $i from 1 through $exp
$value: $value * $number
@else if $exp < 0
@for $i from 1 through -$exp
$value: $value / $number
@return $value
@function colorLuminance($color)
$color-rgb: ('red': red($color),'green': green($color),'blue': blue($color))
@each $name, $value in $color-rgb
2016-01-24 00:03:43 +00:00
$adjusted: 0
$value: $value / 255
@if $value < 0.03928
$value: $value / 12.92
@else
$value: ($value + .055) / 1.055
$value: powerNumber($value, 2)
$color-rgb: map-merge($color-rgb, ($name: $value))
@return (map-get($color-rgb, 'red') * .2126) + (map-get($color-rgb, 'green') * .7152) + (map-get($color-rgb, 'blue') * .0722)
2016-01-24 00:03:43 +00:00
@function findColorInvert($color)
2016-09-25 16:44:01 +00:00
@if (colorLuminance($color) > 0.55)
2016-10-30 10:41:53 +00:00
@return rgba(#000, 0.7)
2016-01-24 00:03:43 +00:00
@else
2016-10-30 10:41:53 +00:00
@return #fff