SassColor
Hierarchy
- Value
- SassColor
Index
Constructors
Accessors
Methods
Constructors
constructor
- new
Sass Color(options: {
alpha?: null | number;
blue: null | number;
green: null | number;
red: null | number;
space?: "rgb";
}): SassColor -
Creates an RGB color.
If
spaceis missing, onlyundefinedshould be used to indicate thatalphaisn't passed. Ifnullis used instead, it will be treated as a missing component. See breaking changes for details.If
spaceis defined andnullis passed for any component, it will be treated as a missing component.Throws
Errorifalphais set and isn'tnullor a number between0and1.Parameters
-
options: {
alpha?: null | number;
blue: null | number;
green: null | number;
red: null | number;
space?: "rgb";
}-
Optionalalpha?: null | number -
blue: null | number
-
green: null | number
-
red: null | number
-
Optionalspace?: "rgb"
-
Returns SassColor
-
constructor
- new
Sass Color(options: {
alpha?: null | number;
hue: null | number;
lightness: null | number;
saturation: null | number;
space?: "hsl";
}): SassColor -
Creates an HSL color.
If
spaceis missing, onlyundefinedshould be used to indicate thatalphaisn't passed. Ifnullis used instead, it will be treated as a missing component. See breaking changes for details.If
spaceis defined andnullis passed for any component, it will be treated as a missing component.Throws
Errorifalphais set and isn'tnullor a number between0and1.Parameters
-
options: {
alpha?: null | number;
hue: null | number;
lightness: null | number;
saturation: null | number;
space?: "hsl";
}-
Optionalalpha?: null | number -
hue: null | number
-
lightness: null | number
-
saturation: null | number
-
Optionalspace?: "hsl"
-
Returns SassColor
-
constructor
- new
Sass Color(options: {
alpha?: null | number;
blackness: null | number;
hue: null | number;
space?: "hwb";
whiteness: null | number;
}): SassColor -
Creates an HWB color.
If
spaceis missing, onlyundefinedshould be used to indicate thatalphaisn't passed. Ifnullis used instead, it will be treated as a missing component. See breaking changes for details.If
spaceis defined andnullis passed for any component, it will be treated as a missing component.Throws
Errorifalphais set and isn'tnullor a number between0and1.Parameters
-
options: {
alpha?: null | number;
blackness: null | number;
hue: null | number;
space?: "hwb";
whiteness: null | number;
}-
Optionalalpha?: null | number -
blackness: null | number
-
hue: null | number
-
Optionalspace?: "hwb" -
whiteness: null | number
-
Returns SassColor
-
constructor
- new
Sass Color(options: {
a: null | number;
alpha?: null | number;
b: null | number;
lightness: null | number;
space: ColorSpaceLab;
}): SassColor -
If
nullis passed for any component, it will be treated as a missing component.Throws
Errorifalphais set and isn'tnullor a number between0and1.Parameters
-
options: {
a: null | number;
alpha?: null | number;
b: null | number;
lightness: null | number;
space: ColorSpaceLab;
}-
a: null | number
-
Optionalalpha?: null | number -
b: null | number
-
lightness: null | number
-
space: ColorSpaceLab
-
Returns SassColor
-
constructor
- new
Sass Color(options: {
alpha?: null | number;
chroma: null | number;
hue: null | number;
lightness: null | number;
space: ColorSpaceLch;
}): SassColor -
Creates an LCH or Oklch color.
If
nullis passed for any component, it will be treated as a missing component.Throws
Errorifalphais set and isn'tnullor a number between0and1.Parameters
-
options: {
alpha?: null | number;
chroma: null | number;
hue: null | number;
lightness: null | number;
space: ColorSpaceLch;
}-
Optionalalpha?: null | number -
chroma: null | number
-
hue: null | number
-
lightness: null | number
-
space: ColorSpaceLch
-
Returns SassColor
-
constructor
- new
Sass Color(options: {
alpha?: null | number;
blue: null | number;
green: null | number;
red: null | number;
space: "display-p3" | "srgb" | "rec2020" | "a98-rgb" | "prophoto-rgb" | "srgb-linear";
}): SassColor -
Creates a color in a predefined RGB color space.
If
nullis passed for any component, it will be treated as a missing component.Throws
Errorifalphais set and isn'tnullor a number between0and1.Parameters
-
options: {
alpha?: null | number;
blue: null | number;
green: null | number;
red: null | number;
space: "display-p3" | "srgb" | "rec2020" | "a98-rgb" | "prophoto-rgb" | "srgb-linear";
}-
Optionalalpha?: null | number -
blue: null | number
-
green: null | number
-
red: null | number
-
space: "display-p3" | "srgb" | "rec2020" | "a98-rgb" | "prophoto-rgb" | "srgb-linear"
-
Returns SassColor
-
constructor
- new
Sass Color(options: {
alpha?: null | number;
space: ColorSpaceXyz;
x: null | number;
y: null | number;
z: null | number;
}): SassColor -
Creates a color in a predefined XYZ color space.
If
nullis passed for any component, it will be treated as a missing component.Throws
Errorifalphais set and isn'tnullor a number between0and1.Parameters
-
options: {
alpha?: null | number;
space: ColorSpaceXyz;
x: null | number;
y: null | number;
z: null | number;
}-
Optionalalpha?: null | number -
space: ColorSpaceXyz
-
x: null | number
-
y: null | number
-
z: null | number
-
Returns SassColor
-
Accessors
alpha
- get alpha(): number
-
This color's alpha channel, between
0and1.Returns number
as List
- get asList(): List<Value>
-
This value as a list.
All SassScript values can be used as lists. Maps count as lists of pairs, and all other values count as single-value lists.
Returns List<Value>
An immutable List from the
immutablepackage.
blackness
- get blackness(): number
-
Returns number
blue
- get blue(): number
-
Returns number
channels
- get channels(): List<number>
-
A list of this color's channel values (excluding alpha), with missing channels converted to
0.Returns List<number>
channels Or Null
- get channelsOrNull(): List<null | number>
-
A list of this color's channel values (excluding alpha), with missing channels converted to
null.Returns List<null | number>
green
- get green(): number
-
Returns number
has Brackets
- get hasBrackets(): boolean
-
Whether this value as a list has brackets.
All SassScript values can be used as lists. Maps count as lists of pairs, and all other values count as single-value lists.
Returns boolean
hue
- get hue(): number
-
Returns number
is Legacy
- get isLegacy(): boolean
-
A boolean indicating whether this color is in a legacy color space (
rgb,hsl, orhwb).Returns boolean
is Truthy
- get isTruthy(): boolean
-
Whether the value counts as
truein an@ifstatement and other contexts.Returns boolean
lightness
- get lightness(): number
-
Returns number
real Null
red
- get red(): number
-
Returns number
saturation
- get saturation(): number
-
Returns number
separator
- get separator(): ListSeparator
-
The separator for this value as a list.
All SassScript values can be used as lists. Maps count as lists of pairs, and all other values count as single-value lists.
Returns ListSeparator
space
- get space(): KnownColorSpace
-
The name of this color's space.
Returns KnownColorSpace
whiteness
- get whiteness(): number
-
Returns number
Methods
assert Boolean
- assert
Boolean(name?: string): SassBoolean -
Throws if
thisisn't a SassBoolean.⚠️ Heads up!
Functions should generally use isTruthy rather than requiring a literal boolean.
Parameters
-
Optionalname: stringThe name of the function argument
thiscame from (without the$) if it came from an argument. Used for error reporting.
Returns SassBoolean
-
assert Calculation
- assert
Calculation(name?: string): SassCalculation -
Throws if
thisisn't a SassCalculation.Parameters
-
Optionalname: stringThe name of the function argument
thiscame from (without the$) if it came from an argument. Used for error reporting.
Returns SassCalculation
-
assert Color
assert Function
- assert
Function(name?: string): SassFunction -
Throws if
thisisn't a SassFunction.Parameters
-
Optionalname: stringThe name of the function argument
thiscame from (without the$) if it came from an argument. Used for error reporting.
Returns SassFunction
-
assert Map
assert Mixin
assert Number
- assert
Number(name?: string): SassNumber -
Throws if
thisisn't a SassNumber.Parameters
-
Optionalname: stringThe name of the function argument
thiscame from (without the$) if it came from an argument. Used for error reporting.
Returns SassNumber
-
assert String
- assert
String(name?: string): SassString -
Throws if
thisisn't a SassString.Parameters
-
Optionalname: stringThe name of the function argument
thiscame from (without the$) if it came from an argument. Used for error reporting.
Returns SassString
-
change
- change(options: {
alpha: undefined | null | number;
hue: undefined | null | number;
lightness: undefined | null | number;
saturation: undefined | null | number;
} & {
space?: "hsl";
}): SassColor -
Returns a new color that's the result of changing one or more of this color's HSL channels.
Throws
Errorifspaceis missing and this color is not in a legacy color space (rgb,hsl, orhwb).Throws
Errorifalphais set and isn'tnullor a number between0and1.Parameters
-
options: {
alpha: undefined | null | number;
hue: undefined | null | number;
lightness: undefined | null | number;
saturation: undefined | null | number;
} & {
space?: "hsl";
}
Returns SassColor
-
change
- change(options: {
alpha: undefined | null | number;
blackness: undefined | null | number;
hue: undefined | null | number;
whiteness: undefined | null | number;
} & {
space?: "hwb";
}): SassColor -
Returns a new color that's the result of changing one or more of this color's HWB channels.
Throws
Errorifspaceis missing and this color is not in a legacy color space (rgb,hsl, orhwb).Throws
Errorifalphais set and isn'tnullor a number between0and1.Parameters
-
options: {
alpha: undefined | null | number;
blackness: undefined | null | number;
hue: undefined | null | number;
whiteness: undefined | null | number;
} & {
space?: "hwb";
}
Returns SassColor
-
change
- change(options: {
a: undefined | null | number;
alpha: undefined | null | number;
b: undefined | null | number;
lightness: undefined | null | number;
} & {
space?: ColorSpaceLab;
}): SassColor -
Returns a new color that's the result of changing one or more of this color's Lab channels.
Throws
Errorifspaceis missing and this color is not in the Lab or Oklab color spaces.Throws
Errorifalphais set and isn'tnullor a number between0and1.Parameters
-
options: {
a: undefined | null | number;
alpha: undefined | null | number;
b: undefined | null | number;
lightness: undefined | null | number;
} & {
space?: ColorSpaceLab;
}
Returns SassColor
-
change
- change(options: {
alpha: undefined | null | number;
chroma: undefined | null | number;
hue: undefined | null | number;
lightness: undefined | null | number;
} & {
space?: ColorSpaceLch;
}): SassColor -
Returns a new color that's the result of changing one or more of this color's LCH channels.
Throws
Errorifspaceis missing and this color is not in the LCH or Oklch color spaces.Throws
Errorifalphais set and isn'tnullor a number between0and1.Parameters
-
options: {
alpha: undefined | null | number;
chroma: undefined | null | number;
hue: undefined | null | number;
lightness: undefined | null | number;
} & {
space?: ColorSpaceLch;
}
Returns SassColor
-
change
- change(options: {
alpha: undefined | null | number;
blue: undefined | null | number;
green: undefined | null | number;
red: undefined | null | number;
} & {
space?: ColorSpaceRgb;
}): SassColor -
Returns a new color that's the result of changing one or more of this color's RGB channels.
Throws
Errorifspaceis missing and this color is not in a legacy color space (rgb,hsl, orhwb).Throws
Errorifalphais set and isn'tnullor a number between0and1.Parameters
-
options: {
alpha: undefined | null | number;
blue: undefined | null | number;
green: undefined | null | number;
red: undefined | null | number;
} & {
space?: ColorSpaceRgb;
}
Returns SassColor
-
change
- change(options: {
alpha: undefined | null | number;
x: undefined | null | number;
y: undefined | null | number;
z: undefined | null | number;
} & {
space?: ColorSpaceXyz;
}): SassColor -
Returns a new color that's the result of changing one or more of this color's XYZ channels.
Throws
Errorifspaceis missing and this color is not in an XYZ color space.Throws
Errorifalphais set and isn'tnullor a number between0and1.Parameters
-
options: {
alpha: undefined | null | number;
x: undefined | null | number;
y: undefined | null | number;
z: undefined | null | number;
} & {
space?: ColorSpaceXyz;
}
Returns SassColor
-
channel
- channel(channel: ChannelName): number
-
Returns the value of a single specified
channelof this color, with missing channels converted to0.Throws
Errorifchannelis notalphaor a channel in this color's space.Parameters
-
channel: ChannelName
Returns number
-
channel
- channel(channel: ChannelNameHsl, options: {
space: "hsl";
}): number -
Returns the value of a single specified
channelof this color after converting this color to the specifiedspace, with missing channels converted to0.Throws
Errorifchannelis notalphaor a channel inspace.Parameters
-
channel: ChannelNameHsl
-
options: {
space: "hsl";
}-
space: "hsl"
-
Returns number
-
channel
- channel(channel: ChannelNameHwb, options: {
space: "hwb";
}): number -
Parameters
-
channel: ChannelNameHwb
-
options: {
space: "hwb";
}-
space: "hwb"
-
Returns number
-
channel
- channel(channel: ChannelNameLab, options: {
space: ColorSpaceLab;
}): number -
Parameters
-
channel: ChannelNameLab
-
options: {
space: ColorSpaceLab;
}-
space: ColorSpaceLab
-
Returns number
-
channel
- channel(channel: ChannelNameLch, options: {
space: ColorSpaceLch;
}): number -
Parameters
-
channel: ChannelNameLch
-
options: {
space: ColorSpaceLch;
}-
space: ColorSpaceLch
-
Returns number
-
channel
- channel(channel: ChannelNameRgb, options: {
space: ColorSpaceRgb;
}): number -
Parameters
-
channel: ChannelNameRgb
-
options: {
space: ColorSpaceRgb;
}-
space: ColorSpaceRgb
-
Returns number
-
channel
- channel(channel: ChannelNameXyz, options: {
space: ColorSpaceXyz;
}): number -
Parameters
-
channel: ChannelNameXyz
-
options: {
space: ColorSpaceXyz;
}-
space: ColorSpaceXyz
-
Returns number
-
equals
get
- get(index: number): undefined | Value
-
Returns the value at index
indexin this value as a list, orundefinedifindexisn't valid for this list.All SassScript values can be used as lists. Maps count as lists of pairs, and all other values count as single-value lists.
This is a shorthand for
this.asList.get(index), although it may be more efficient in some cases.⚠️ Heads up!
This method uses the same indexing conventions as the
immutablepackage: unlike Sass the index of the first element is 0, but like Sass negative numbers index from the end of the list.Parameters
-
index: number
Returns undefined | Value
-
hash Code
interpolate
- interpolate(color2: SassColor, options?: {
method?: HueInterpolationMethod;
weight?: number;
}): SassColor -
Returns a color partway between this color and
color2according tomethod, as defined by the CSS Color 4 color interpolation procedure.If
methodis missing and this color is in a rectangular color space (Lab, Oklab, RGB, and XYZ spaces),methoddefaults to the color space of this color. Otherwise,methoddefaults to a space separated list containing the color space of this color and the string "shorter".The
weightis a number between 0 and 1 that indicates how much of this color should be in the resulting color. If omitted, it defaults to 0.5.Parameters
-
color2: SassColor
-
Optionaloptions: {
method?: HueInterpolationMethod;
weight?: number;
}-
Optionalmethod?: HueInterpolationMethod -
Optionalweight?: number
-
Returns SassColor
-
is Channel Missing
- is
Channel Missing(channel: ChannelName): boolean -
Returns a boolean indicating whether a given channel value is a missing channel.
Parameters
-
channel: ChannelName
Returns boolean
-
is Channel Powerless
- is
Channel Powerless(channel: ChannelName): boolean -
Returns a boolean indicating whether a given
channelis powerless in this color. This is a special state that's defined for individual color spaces, which indicates that a channel's value won't affect how a color is displayed.Parameters
-
channel: ChannelName
Returns boolean
-
is Channel Powerless
- is
Channel Powerless(channel: ChannelNameHsl, options?: {
space: "hsl";
}): boolean -
Parameters
-
channel: ChannelNameHsl
-
Optionaloptions: {
space: "hsl";
}-
space: "hsl"
-
Returns boolean
-
is Channel Powerless
- is
Channel Powerless(channel: ChannelNameHwb, options?: {
space: "hwb";
}): boolean -
Parameters
-
channel: ChannelNameHwb
-
Optionaloptions: {
space: "hwb";
}-
space: "hwb"
-
Returns boolean
-
is Channel Powerless
- is
Channel Powerless(channel: ChannelNameLab, options?: {
space: ColorSpaceLab;
}): boolean -
Parameters
-
channel: ChannelNameLab
-
Optionaloptions: {
space: ColorSpaceLab;
}-
space: ColorSpaceLab
-
Returns boolean
-
is Channel Powerless
- is
Channel Powerless(channel: ChannelNameLch, options?: {
space: ColorSpaceLch;
}): boolean -
Parameters
-
channel: ChannelNameLch
-
Optionaloptions: {
space: ColorSpaceLch;
}-
space: ColorSpaceLch
-
Returns boolean
-
is Channel Powerless
- is
Channel Powerless(channel: ChannelNameRgb, options?: {
space: ColorSpaceRgb;
}): boolean -
Parameters
-
channel: ChannelNameRgb
-
Optionaloptions: {
space: ColorSpaceRgb;
}-
space: ColorSpaceRgb
-
Returns boolean
-
is Channel Powerless
- is
Channel Powerless(channel: ChannelNameXyz, options?: {
space: ColorSpaceXyz;
}): boolean -
Parameters
-
channel: ChannelNameXyz
-
Optionaloptions: {
space: ColorSpaceXyz;
}-
space: ColorSpaceXyz
-
Returns boolean
-
is In Gamut
- is
In Gamut(space?: KnownColorSpace): boolean -
Returns a boolean indicating whether this color is in-gamut (as opposed to having one or more of its channels out of bounds) for the specified
space, or its current color space ifspaceis not specified.Parameters
-
Optionalspace: KnownColorSpace
Returns boolean
-
sass Index To List Index
- sass
Index To List Index(sassIndex: Value, name?: string): number -
Converts
sassIndexinto a JavaScript-style index into the list returned by asList.Sass indexes are one-based, while JavaScript indexes are zero-based. Sass indexes may also be negative in order to index from the end of the list.
Throws
ErrorIfsassIndexisn't a number, if that number isn't an integer, or if that integer isn't a valid index for asList.Parameters
-
sassIndex: Value
The Sass-style index into this as a list.
-
Optionalname: stringThe name of the function argument
sassIndexcame from (without the$) if it came from an argument. Used for error reporting.
Returns number
-
to Gamut
- to
Gamut(options: {
method: GamutMapMethod;
space?: KnownColorSpace;
}): SassColor -
Returns a copy of this color, modified so it is in-gamut for the specified
space—or the current color space ifspaceis not specified—usingmethodto map out-of-gamut colors into the desired gamut.Parameters
-
options: {
method: GamutMapMethod;
space?: KnownColorSpace;
}-
method: GamutMapMethod
-
Optionalspace?: KnownColorSpace
-
Returns SassColor
-
to Space
- to
Space(space: KnownColorSpace): SassColor -
Returns a new color that's the result of converting this color to the specified
space.Parameters
-
space: KnownColorSpace
Returns SassColor
-
Sass's color type.
No matter what representation was originally used to create this color, all of its channels are accessible.