// Register functions
@function gtkalpha($color, $opacity) {
  @if $color=="currentColor" {
    @return unquote("alpha(#{$color}, #{$opacity})");
  } @else {
    @return rgba($color, $opacity);
  }
}

// inspired from transition() function at https://gitlab.gnome.org/GNOME/gtk/-/blob/master/gtk/gtkcsscolorvalue.c#L320-346
@function blend($start, $end, $multiplier) {
  @return $start + ($end - $start) * $multiplier;
}

// inspired from mix() function at https://gitlab.gnome.org/GNOME/gtk/-/blob/master/gtk/gtkcsscolorvalue.c#L320-346
@function gtkmix($color1, $color2, $multiplier) {
  $alpha: blend(alpha($color1), alpha($color2), $multiplier);
  
  @if $alpha<=0 {
    @return rgba(0, 0, 0, $alpha);
  } @else {
    $red: blend(red($color1) * alpha($color1), red($color2) * alpha($color2), $multiplier) / $alpha;
    $green: blend(green($color1) * alpha($color1), green($color2) * alpha($color2), $multiplier) / $alpha;
    $blue: blend(blue($color1) * alpha($color1), blue($color2) * alpha($color2), $multiplier) / $alpha;
    
    @return rgba($red, $green, $blue, $alpha);
  }
}

// inspired from shade() function at https://gitlab.gnome.org/GNOME/gtk/-/blob/master/gtk/gtkhsla.c#L168-185
@function gtkshade($color, $multiplier) {
  $new: hsla(hue($color), saturation($color) * $multiplier, lightness($color) * $multiplier, alpha($color));
  @return $new;
}

@function gtkscale($filename, $extension) {
  @return -gtk-scaled(url($filename + $extension), url($filename + "@2" + $extension));
}
