InterpolationMethod.fromValue constructor

InterpolationMethod.fromValue(
  1. Value value, [
  2. String? name
])

Parses a SassScript value representing an interpolation method, not beginning with "in".

Throws a SassScriptException if value isn't a valid interpolation method. If value came from a function argument, name is the argument name (without the $). This is used for error reporting.

Implementation

factory InterpolationMethod.fromValue(Value value, [String? name]) {
  var list = value.assertCommonListStyle(name, allowSlash: false);
  if (list.isEmpty) {
    throw SassScriptException(
        'Expected a color interpolation method, got an empty list.', name);
  }

  var space = ColorSpace.fromName(
      (list.first.assertString(name)..assertUnquoted(name)).text, name);
  if (list.length == 1) return InterpolationMethod(space);

  var hueMethod = HueInterpolationMethod._fromValue(list[1], name);
  if (list.length == 2) {
    throw SassScriptException(
        'Expected unquoted string "hue" after $value.', name);
  } else if ((list[2].assertString(name)..assertUnquoted(name))
          .text
          .toLowerCase() !=
      'hue') {
    throw SassScriptException(
        'Expected unquoted string "hue" at the end of $value, was ${list[2]}.',
        name);
  } else if (list.length > 3) {
    throw SassScriptException(
        'Expected nothing after "hue" in $value.', name);
  } else if (!space.isPolar) {
    throw SassScriptException(
        'Hue interpolation method "$hueMethod hue" may not be set for '
        'rectangular color space $space.',
        name);
  }

  return InterpolationMethod(space, hueMethod);
}