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
space
is missing, onlyundefined
should be used to indicate thatalpha
isn't passed. Ifnull
is used instead, it will be treated as a missing component. See breaking changes for details.If
space
is defined andnull
is passed for any component, it will be treated as a missing component.Throws
Error
ifalpha
is set and isn'tnull
or a number between0
and1
.Parameters
-
options: {
alpha?: null | number;
blue: null | number;
green: null | number;
red: null | number;
space?: "rgb";
}-
Optional
alpha?: null | number -
blue: null | number
-
green: null | number
-
red: null | number
-
Optional
space?: "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
space
is missing, onlyundefined
should be used to indicate thatalpha
isn't passed. Ifnull
is used instead, it will be treated as a missing component. See breaking changes for details.If
space
is defined andnull
is passed for any component, it will be treated as a missing component.Throws
Error
ifalpha
is set and isn'tnull
or a number between0
and1
.Parameters
-
options: {
alpha?: null | number;
hue: null | number;
lightness: null | number;
saturation: null | number;
space?: "hsl";
}-
Optional
alpha?: null | number -
hue: null | number
-
lightness: null | number
-
saturation: null | number
-
Optional
space?: "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
space
is missing, onlyundefined
should be used to indicate thatalpha
isn't passed. Ifnull
is used instead, it will be treated as a missing component. See breaking changes for details.If
space
is defined andnull
is passed for any component, it will be treated as a missing component.Throws
Error
ifalpha
is set and isn'tnull
or a number between0
and1
.Parameters
-
options: {
alpha?: null | number;
blackness: null | number;
hue: null | number;
space?: "hwb";
whiteness: null | number;
}-
Optional
alpha?: null | number -
blackness: null | number
-
hue: null | number
-
Optional
space?: "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
null
is passed for any component, it will be treated as a missing component.Throws
Error
ifalpha
is set and isn'tnull
or a number between0
and1
.Parameters
-
options: {
a: null | number;
alpha?: null | number;
b: null | number;
lightness: null | number;
space: ColorSpaceLab;
}-
a: null | number
-
Optional
alpha?: 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
null
is passed for any component, it will be treated as a missing component.Throws
Error
ifalpha
is set and isn'tnull
or a number between0
and1
.Parameters
-
options: {
alpha?: null | number;
chroma: null | number;
hue: null | number;
lightness: null | number;
space: ColorSpaceLch;
}-
Optional
alpha?: 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
null
is passed for any component, it will be treated as a missing component.Throws
Error
ifalpha
is set and isn'tnull
or a number between0
and1
.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";
}-
Optional
alpha?: 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
null
is passed for any component, it will be treated as a missing component.Throws
Error
ifalpha
is set and isn'tnull
or a number between0
and1
.Parameters
-
options: {
alpha?: null | number;
space: ColorSpaceXyz;
x: null | number;
y: null | number;
z: null | number;
}-
Optional
alpha?: 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
0
and1
.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
immutable
package.
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
true
in an@if
statement 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
this
isn't a SassBoolean.⚠️ Heads up!
Functions should generally use isTruthy rather than requiring a literal boolean.
Parameters
-
Optional
name: stringThe name of the function argument
this
came from (without the$
) if it came from an argument. Used for error reporting.
Returns SassBoolean
-
assert Calculation
- assert
Calculation(name?: string): SassCalculation -
Throws if
this
isn't a SassCalculation.Parameters
-
Optional
name: stringThe name of the function argument
this
came 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
this
isn't a SassFunction.Parameters
-
Optional
name: stringThe name of the function argument
this
came 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
this
isn't a SassNumber.Parameters
-
Optional
name: stringThe name of the function argument
this
came from (without the$
) if it came from an argument. Used for error reporting.
Returns SassNumber
-
assert String
- assert
String(name?: string): SassString -
Throws if
this
isn't a SassString.Parameters
-
Optional
name: stringThe name of the function argument
this
came 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
Error
ifspace
is missing and this color is not in a legacy color space (rgb
,hsl
, orhwb
).Throws
Error
ifalpha
is set and isn'tnull
or a number between0
and1
.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
Error
ifspace
is missing and this color is not in a legacy color space (rgb
,hsl
, orhwb
).Throws
Error
ifalpha
is set and isn'tnull
or a number between0
and1
.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
Error
ifspace
is missing and this color is not in the Lab or Oklab color spaces.Throws
Error
ifalpha
is set and isn'tnull
or a number between0
and1
.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
Error
ifspace
is missing and this color is not in the LCH or Oklch color spaces.Throws
Error
ifalpha
is set and isn'tnull
or a number between0
and1
.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
Error
ifspace
is missing and this color is not in a legacy color space (rgb
,hsl
, orhwb
).Throws
Error
ifalpha
is set and isn'tnull
or a number between0
and1
.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
Error
ifspace
is missing and this color is not in an XYZ color space.Throws
Error
ifalpha
is set and isn'tnull
or a number between0
and1
.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
channel
of this color, with missing channels converted to0
.Throws
Error
ifchannel
is notalpha
or 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
channel
of this color after converting this color to the specifiedspace
, with missing channels converted to0
.Throws
Error
ifchannel
is notalpha
or 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
index
in this value as a list, orundefined
ifindex
isn'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
immutable
package: 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
color2
according tomethod
, as defined by the CSS Color 4 color interpolation procedure.If
method
is missing and this color is in a rectangular color space (Lab, Oklab, RGB, and XYZ spaces),method
defaults to the color space of this color. Otherwise,method
defaults to a space separated list containing the color space of this color and the string "shorter".The
weight
is 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
-
Optional
options: {
method?: HueInterpolationMethod;
weight?: number;
}-
Optional
method?: HueInterpolationMethod -
Optional
weight?: 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
channel
is 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
-
Optional
options: {
space: "hsl";
}-
space: "hsl"
-
Returns boolean
-
is Channel Powerless
- is
Channel Powerless(channel: ChannelNameHwb, options?: {
space: "hwb";
}): boolean -
Parameters
-
channel: ChannelNameHwb
-
Optional
options: {
space: "hwb";
}-
space: "hwb"
-
Returns boolean
-
is Channel Powerless
- is
Channel Powerless(channel: ChannelNameLab, options?: {
space: ColorSpaceLab;
}): boolean -
Parameters
-
channel: ChannelNameLab
-
Optional
options: {
space: ColorSpaceLab;
}-
space: ColorSpaceLab
-
Returns boolean
-
is Channel Powerless
- is
Channel Powerless(channel: ChannelNameLch, options?: {
space: ColorSpaceLch;
}): boolean -
Parameters
-
channel: ChannelNameLch
-
Optional
options: {
space: ColorSpaceLch;
}-
space: ColorSpaceLch
-
Returns boolean
-
is Channel Powerless
- is
Channel Powerless(channel: ChannelNameRgb, options?: {
space: ColorSpaceRgb;
}): boolean -
Parameters
-
channel: ChannelNameRgb
-
Optional
options: {
space: ColorSpaceRgb;
}-
space: ColorSpaceRgb
-
Returns boolean
-
is Channel Powerless
- is
Channel Powerless(channel: ChannelNameXyz, options?: {
space: ColorSpaceXyz;
}): boolean -
Parameters
-
channel: ChannelNameXyz
-
Optional
options: {
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 ifspace
is not specified.Parameters
-
Optional
space: KnownColorSpace
Returns boolean
-
sass Index To List Index
- sass
Index To List Index(sassIndex: Value, name?: string): number -
Converts
sassIndex
into 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
Error
IfsassIndex
isn'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.
-
Optional
name: stringThe name of the function argument
sassIndex
came 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 ifspace
is not specified—usingmethod
to map out-of-gamut colors into the desired gamut.Parameters
-
options: {
method: GamutMapMethod;
space?: KnownColorSpace;
}-
method: GamutMapMethod
-
Optional
space?: 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.