SassColor
層次結構
- 值
- SassColor
索引
建構函式
訪問器
方法
建構函式
建構函式
- new
Sass (options: {Color
alpha?: null | number;
blue: null | number;
green: null | number;
red: null | number;
space?: "rgb";
}): SassColor -
建立一個 RGB 顏色。
如果
space缺失,則**僅**應使用undefined來指示未傳遞alpha。如果改為使用null,則將其視為 缺失的元件。有關詳細資訊,請參閱 重大更改。如果定義了
space併為任何元件傳遞了null,則將其視為 缺失的元件。丟擲
如果設定了
alpha且它不是null或0到1之間的一個數字,則丟擲Error。引數
-
options: {
alpha?: null | number;
blue: null | number;
green: null | number;
red: null | number;
space?: "rgb";
}-
可選alpha?: null | number -
blue: null | number
-
green: null | number
-
red: null | number
-
可選space?: "rgb"
-
返回 SassColor
-
建構函式
- new
Sass (options: {Color
alpha?: null | number;
hue: null | number;
lightness: null | number;
saturation: null | number;
space?: "hsl";
}): SassColor -
建立一個 HSL 顏色。
如果
space缺失,則**僅**應使用undefined來指示未傳遞alpha。如果改為使用null,則將其視為 缺失的元件。有關詳細資訊,請參閱 重大更改。如果定義了
space併為任何元件傳遞了null,則將其視為 缺失的元件。丟擲
如果設定了
alpha且它不是null或0到1之間的一個數字,則丟擲Error。引數
-
options: {
alpha?: null | number;
hue: null | number;
lightness: null | number;
saturation: null | number;
space?: "hsl";
}-
可選alpha?: null | number -
hue: null | number
-
lightness: null | number
-
saturation: null | number
-
可選space?: "hsl"
-
返回 SassColor
-
建構函式
- new
Sass (options: {Color
alpha?: null | number;
blackness: null | number;
hue: null | number;
space?: "hwb";
whiteness: null | number;
}): SassColor -
建立一個 HWB 顏色。
如果
space缺失,則**僅**應使用undefined來指示未傳遞alpha。如果改為使用null,則將其視為 缺失的元件。有關詳細資訊,請參閱 重大更改。如果定義了
space併為任何元件傳遞了null,則將其視為 缺失的元件。丟擲
如果設定了
alpha且它不是null或0到1之間的一個數字,則丟擲Error。引數
-
options: {
alpha?: null | number;
blackness: null | number;
hue: null | number;
space?: "hwb";
whiteness: null | number;
}-
可選alpha?: null | number -
blackness: null | number
-
hue: null | number
-
可選space?: "hwb" -
whiteness: null | number
-
返回 SassColor
-
建構函式
- new
Sass (options: {Color
a: null | number;
alpha?: null | number;
b: null | number;
lightness: null | number;
space: ColorSpaceLab;
}): SassColor -
引數
-
options: {
a: null | number;
alpha?: null | number;
b: null | number;
lightness: null | number;
space: ColorSpaceLab;
}-
a: null | number
-
可選alpha?: null | number -
b: null | number
-
lightness: null | number
-
space: ColorSpaceLab
-
返回 SassColor
-
建構函式
- new
Sass (options: {Color
alpha?: null | number;
chroma: null | number;
hue: null | number;
lightness: null | number;
space: ColorSpaceLch;
}): SassColor -
引數
-
options: {
alpha?: null | number;
chroma: null | number;
hue: null | number;
lightness: null | number;
space: ColorSpaceLch;
}-
可選alpha?: null | number -
chroma: null | number
-
hue: null | number
-
lightness: null | number
-
space: ColorSpaceLch
-
返回 SassColor
-
建構函式
- new
Sass (options: {Color
alpha?: null | number;
blue: null | number;
green: null | number;
red: null | number;
space: "display-p3" | "srgb" | "rec2020" | "a98-rgb" | "prophoto-rgb" | "srgb-linear";
}): SassColor -
在預定義的 RGB 顏色空間中建立一個顏色。
如果為任何元件傳遞了
null,則將其視為 缺失的元件。丟擲
如果設定了
alpha且它不是null或0到1之間的一個數字,則丟擲Error。引數
-
options: {
alpha?: null | number;
blue: null | number;
green: null | number;
red: null | number;
space: "display-p3" | "srgb" | "rec2020" | "a98-rgb" | "prophoto-rgb" | "srgb-linear";
}-
可選alpha?: null | number -
blue: null | number
-
green: null | number
-
red: null | number
-
space: "display-p3" | "srgb" | "rec2020" | "a98-rgb" | "prophoto-rgb" | "srgb-linear"
-
返回 SassColor
-
建構函式
- new
Sass (options: {Color
alpha?: null | number;
space: ColorSpaceXyz;
x: null | number;
y: null | number;
z: null | number;
}): SassColor -
引數
-
options: {
alpha?: null | number;
space: ColorSpaceXyz;
x: null | number;
y: null | number;
z: null | number;
}-
可選alpha?: null | number -
space: ColorSpaceXyz
-
x: null | number
-
y: null | number
-
z: null | number
-
返回 SassColor
-
訪問器
alpha
- get alpha(): number
-
此顏色的 alpha 通道,介於
0和1之間。返回 number
asList
- get asList(): List<Value>
-
此值作為列表。
所有 SassScript 值都可以用作列表。對映計為成對的列表,所有其他值計為單值列表。
返回 List<Value>
來自
immutable包 的不可變列表。
blackness
- get blackness(): number
-
返回 number
blue
- get blue(): number
-
返回 number
channels
channelsOrNull
green
- get green(): number
-
返回 number
hasBrackets
- get hasBrackets(): boolean
-
此值作為列表是否帶括號。
所有 SassScript 值都可以用作列表。對映計為成對的列表,所有其他值計為單值列表。
返回 boolean
hue
- get hue(): number
-
返回 number
isLegacy
- get isLegacy(): boolean
-
一個布林值,指示此顏色是否處於舊版色彩空間(
rgb、hsl或hwb)。返回 boolean
isTruthy
- get isTruthy(): boolean
-
該值在
@if語句和其他上下文中是否計為true。返回 boolean
lightness
- get lightness(): number
-
返回 number
realNull
red
- get red(): number
-
返回 number
saturation
- get saturation(): number
-
返回 number
separator
- get separator(): ListSeparator
-
此值的列表分隔符。
所有 SassScript 值都可以用作列表。對映計為成對的列表,所有其他值計為單值列表。
返回 ListSeparator
space
- get space(): KnownColorSpace
-
此顏色的空間名稱。
返回 KnownColorSpace
whiteness
- get whiteness(): number
-
返回 number
方法
assertBoolean
- assert
Boolean (name?: string): SassBoolean -
如果
this不是 SassBoolean,則丟擲錯誤。⚠️ 注意!
函式通常應該使用 isTruthy 而不是要求一個字面量布林值。
引數
-
可選name: string如果
this來自於一個引數,則為該引數的函式引數名稱(不帶$)。用於錯誤報告。
返回 SassBoolean
-
assertCalculation
- assert
Calculation (name?: string): SassCalculation -
如果
this不是 SassCalculation,則丟擲錯誤。引數
-
可選name: string如果
this來自於一個引數,則為該引數的函式引數名稱(不帶$)。用於錯誤報告。
返回 SassCalculation
-
assertColor
assertFunction
- assert
Function (name?: string): SassFunction -
如果
this不是 SassFunction,則丟擲錯誤。引數
-
可選name: string如果
this來自於一個引數,則為該引數的函式引數名稱(不帶$)。用於錯誤報告。
返回 SassFunction
-
assertMap
assertMixin
assertNumber
- assert
Number (name?: string): SassNumber -
如果
this不是 SassNumber,則丟擲錯誤。引數
-
可選name: string如果
this來自於一個引數,則為該引數的函式引數名稱(不帶$)。用於錯誤報告。
返回 SassNumber
-
assertString
- assert
String (name?: string): SassString -
如果
this不是 SassString,則丟擲錯誤。引數
-
可選name: string如果
this來自於一個引數,則為該引數的函式引數名稱(不帶$)。用於錯誤報告。
返回 SassString
-
change
- change(options: {
alpha: undefined | null | number;
hue: undefined | null | number;
lightness: undefined | null | number;
saturation: undefined | null | number;
} & {
space?: "hsl";
}): SassColor -
返回一個新的顏色,它是更改此顏色的一個或多個HSL 通道的結果。
丟擲
如果
space缺失且此顏色不在傳統顏色空間(rgb、hsl或hwb)中,則會引發Error。丟擲
如果設定了
alpha且它不是null或0到1之間的一個數字,則丟擲Error。引數
-
options: {
alpha: undefined | null | number;
hue: undefined | null | number;
lightness: undefined | null | number;
saturation: undefined | null | number;
} & {
space?: "hsl";
}
返回 SassColor
-
change
- change(options: {
alpha: undefined | null | number;
blackness: undefined | null | number;
hue: undefined | null | number;
whiteness: undefined | null | number;
} & {
space?: "hwb";
}): SassColor -
返回一個新的顏色,它是更改此顏色的一個或多個HWB 通道的結果。
丟擲
如果
space缺失且此顏色不在傳統顏色空間(rgb、hsl或hwb)中,則會引發Error。丟擲
如果設定了
alpha且它不是null或0到1之間的一個數字,則丟擲Error。引數
-
options: {
alpha: undefined | null | number;
blackness: undefined | null | number;
hue: undefined | null | number;
whiteness: undefined | null | number;
} & {
space?: "hwb";
}
返回 SassColor
-
change
- change(options: {
a: undefined | null | number;
alpha: undefined | null | number;
b: undefined | null | number;
lightness: undefined | null | number;
} & {
space?: ColorSpaceLab;
}): SassColor -
返回一個新的顏色,它是更改此顏色的一個或多個 Lab 通道的結果。
丟擲
如果
space缺失且此顏色不在 Lab 或 Oklab 顏色 空間中,則會引發Error。丟擲
如果設定了
alpha且它不是null或0到1之間的一個數字,則丟擲Error。引數
-
options: {
a: undefined | null | number;
alpha: undefined | null | number;
b: undefined | null | number;
lightness: undefined | null | number;
} & {
space?: ColorSpaceLab;
}
返回 SassColor
-
change
- change(options: {
alpha: undefined | null | number;
chroma: undefined | null | number;
hue: undefined | null | number;
lightness: undefined | null | number;
} & {
space?: ColorSpaceLch;
}): SassColor -
返回一個新的顏色,它是更改此顏色的一個或多個LCH 通道的結果。
丟擲
如果
space缺失且此顏色不在LCH或 Oklch 顏色 空間中,則會引發Error。丟擲
如果設定了
alpha且它不是null或0到1之間的一個數字,則丟擲Error。引數
-
options: {
alpha: undefined | null | number;
chroma: undefined | null | number;
hue: undefined | null | number;
lightness: undefined | null | number;
} & {
space?: ColorSpaceLch;
}
返回 SassColor
-
change
- change(options: {
alpha: undefined | null | number;
blue: undefined | null | number;
green: undefined | null | number;
red: undefined | null | number;
} & {
space?: ColorSpaceRgb;
}): SassColor -
返回一個新的顏色,它是更改此顏色的一個或多個RGB 通道的結果。
丟擲
如果
space缺失且此顏色不在傳統顏色空間(rgb、hsl或hwb)中,則會引發Error。丟擲
如果設定了
alpha且它不是null或0到1之間的一個數字,則丟擲Error。引數
-
options: {
alpha: undefined | null | number;
blue: undefined | null | number;
green: undefined | null | number;
red: undefined | null | number;
} & {
space?: ColorSpaceRgb;
}
返回 SassColor
-
change
- change(options: {
alpha: undefined | null | number;
x: undefined | null | number;
y: undefined | null | number;
z: undefined | null | number;
} & {
space?: ColorSpaceXyz;
}): SassColor -
返回一個新的顏色,它是更改此顏色的一個或多個XYZ 通道的結果。
丟擲
如果
space缺失且此顏色不在XYZ顏色 空間中,則會引發Error。丟擲
如果設定了
alpha且它不是null或0到1之間的一個數字,則丟擲Error。引數
-
options: {
alpha: undefined | null | number;
x: undefined | null | number;
y: undefined | null | number;
z: undefined | null | number;
} & {
space?: ColorSpaceXyz;
}
返回 SassColor
-
通道
- channel(channel: ChannelName): number
-
引數
-
channel: ChannelName
返回 number
-
通道
- channel(channel: ChannelNameHsl, options: {
space: "hsl";
}): number -
將此顏色轉換為指定的
space後,返回此顏色的單個指定channel的值,其中缺少的通道轉換為0。丟擲
如果
channel不是alpha或space中的通道,則會引發Error。引數
-
channel: ChannelNameHsl
-
options: {
space: "hsl";
}-
space: "hsl"
-
返回 number
-
通道
- channel(channel: ChannelNameHwb, options: {
space: "hwb";
}): number -
引數
-
channel: ChannelNameHwb
-
options: {
space: "hwb";
}-
space: "hwb"
-
返回 number
-
通道
- channel(channel: ChannelNameLab, options: {
space: ColorSpaceLab;
}): number -
引數
-
channel: ChannelNameLab
-
options: {
space: ColorSpaceLab;
}-
space: ColorSpaceLab
-
返回 number
-
通道
- channel(channel: ChannelNameLch, options: {
space: ColorSpaceLch;
}): number -
引數
-
channel: ChannelNameLch
-
options: {
space: ColorSpaceLch;
}-
space: ColorSpaceLch
-
返回 number
-
通道
- channel(channel: ChannelNameRgb, options: {
space: ColorSpaceRgb;
}): number -
引數
-
channel: ChannelNameRgb
-
options: {
space: ColorSpaceRgb;
}-
space: ColorSpaceRgb
-
返回 number
-
通道
- channel(channel: ChannelNameXyz, options: {
space: ColorSpaceXyz;
}): number -
引數
-
channel: ChannelNameXyz
-
options: {
space: ColorSpaceXyz;
}-
space: ColorSpaceXyz
-
返回 number
-
equals
get
- get(index: number): undefined | Value
-
返回此值作為列表中索引
index處的值,如果index對此列表無效,則返回undefined。所有 SassScript 值都可以用作列表。對映計為成對的列表,所有其他值計為單值列表。
這是
this.asList.get(index)的簡寫,儘管在某些情況下它可能更有效。⚠️ 注意!
此方法使用與
immutable包相同的索引約定:與 Sass 不同,第一個元素的索引為 0,但與 Sass 類似,負數從列表的末尾開始索引。引數
-
index: number
返回 undefined | Value
-
hashCode
interpolate
- interpolate(color2: SassColor, options?: {
method?: HueInterpolationMethod;
weight?: number;
}): SassColor -
根據 CSS 顏色 4 顏色插值過程中的
method,返回此顏色與color2之間的部分顏色。如果
method缺失並且此顏色位於矩形顏色空間(Lab、Oklab、RGB 和 XYZ 空間)中,則method預設為此顏色的顏色空間。否則,method預設為包含此顏色的顏色空間和字串“shorter”的空間分隔列表。weight是一個介於 0 和 1 之間的數字,表示結果顏色中應該包含多少此顏色。如果省略,則預設為 0.5。引數
-
color2: SassColor
-
可選options: {
method?: HueInterpolationMethod;
weight?: number;
}-
可選method?: HueInterpolationMethod -
可選weight?: number
-
返回 SassColor
-
isChannelMissing
- is
Channel (channel: ChannelName): booleanMissing -
返回一個布林值,指示給定的通道值是否為缺失通道。
引數
-
channel: ChannelName
返回 boolean
-
isChannelPowerless
- is
Channel (channel: ChannelName): booleanPowerless -
返回一個布林值,指示給定的
channel在此顏色中是否無效。這是一種為各個顏色空間定義的特殊狀態,它表示通道的值不會影響顏色的顯示方式。引數
-
channel: ChannelName
返回 boolean
-
isChannelPowerless
- is
Channel (channel: ChannelNameHsl, options?: {Powerless
space: "hsl";
}): boolean -
引數
-
channel: ChannelNameHsl
-
可選options: {
space: "hsl";
}-
space: "hsl"
-
返回 boolean
-
isChannelPowerless
- is
Channel (channel: ChannelNameHwb, options?: {Powerless
space: "hwb";
}): boolean -
引數
-
channel: ChannelNameHwb
-
可選options: {
space: "hwb";
}-
space: "hwb"
-
返回 boolean
-
isChannelPowerless
- is
Channel (channel: ChannelNameLab, options?: {Powerless
space: ColorSpaceLab;
}): boolean -
引數
-
channel: ChannelNameLab
-
可選options: {
space: ColorSpaceLab;
}-
space: ColorSpaceLab
-
返回 boolean
-
isChannelPowerless
- is
Channel (channel: ChannelNameLch, options?: {Powerless
space: ColorSpaceLch;
}): boolean -
引數
-
channel: ChannelNameLch
-
可選options: {
space: ColorSpaceLch;
}-
space: ColorSpaceLch
-
返回 boolean
-
isChannelPowerless
- is
Channel (channel: ChannelNameRgb, options?: {Powerless
space: ColorSpaceRgb;
}): boolean -
引數
-
channel: ChannelNameRgb
-
可選options: {
space: ColorSpaceRgb;
}-
space: ColorSpaceRgb
-
返回 boolean
-
isChannelPowerless
- is
Channel (channel: ChannelNameXyz, options?: {Powerless
space: ColorSpaceXyz;
}): boolean -
引數
-
channel: ChannelNameXyz
-
可選options: {
space: ColorSpaceXyz;
}-
space: ColorSpaceXyz
-
返回 boolean
-
isInGamut
- is
In (space?: KnownColorSpace): booleanGamut -
返回一個布林值,指示此顏色是否在色域內(與其一個或多個通道超出範圍相反),用於指定的
space,或者如果未指定space則為其當前顏色空間。引數
-
可選space: KnownColorSpace
返回 boolean
-
sassIndexToListIndex
- sass
Index (sassIndex: Value, name?: string): numberTo List Index -
將
sassIndex轉換為由asList返回的列表中的JavaScript樣式索引。Sass索引基於1,而JavaScript索引基於0。Sass索引也可能是負數,以便從列表的末尾進行索引。
丟擲
錯誤如果sassIndex不是數字,如果該數字不是整數,或者如果該整數不是asList的有效索引。引數
-
sassIndex: Value
作為列表的Sass樣式索引。
-
可選name: string如果
sassIndex來自引數,則其來自的函式引數名稱(不帶$),用於錯誤報告。
返回 number
-
toGamut
- to
Gamut (options: {
method: GamutMapMethod;
space?: KnownColorSpace;
}): SassColor -
返回此顏色的副本,修改後使其在指定的
space中處於色域內——或者如果未指定space則為當前顏色空間——使用method將超出色域的顏色對映到所需的色域。引數
-
options: {
method: GamutMapMethod;
space?: KnownColorSpace;
}-
method: GamutMapMethod
-
可選space?: KnownColorSpace
-
返回 SassColor
-
toSpace
- to
Space (space: KnownColorSpace): SassColor -
返回一個新顏色,它是將此顏色轉換為指定的
space的結果。引數
-
space: KnownColorSpace
返回 SassColor
-
Sass 的 顏色型別。
無論最初使用什麼表示形式來建立此顏色,其所有通道都可訪問。