-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
css-color-parser : allow color channels to be normalized individually (…
- Loading branch information
1 parent
1b74068
commit 2247887
Showing
26 changed files
with
701 additions
and
743 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
packages/css-color-parser/dist/functions/color-normalize-channel-values.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import type { ColorData } from '../color-data'; | ||
import { CSSToken, TokenNumber } from '@csstools/css-tokenizer'; | ||
export declare function normalize_Color_ChannelValues(tokens: Array<CSSToken>, colorData: ColorData): Array<TokenNumber> | false; | ||
import { CSSToken } from '@csstools/css-tokenizer'; | ||
export declare function normalize_Color_ChannelValues(token: CSSToken, index: number, colorData: ColorData): CSSToken | false; |
5 changes: 2 additions & 3 deletions
5
packages/css-color-parser/dist/functions/hsl-normalize-channel-values.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import type { ColorData } from '../color-data'; | ||
import type { TokenNumber } from '@csstools/css-tokenizer'; | ||
import { CSSToken } from '@csstools/css-tokenizer'; | ||
export declare function normalize_legacy_HSL_ChannelValues(tokens: Array<CSSToken>, colorData: ColorData): Array<TokenNumber> | false; | ||
export declare function normalize_modern_HSL_ChannelValues(tokens: Array<CSSToken>, colorData: ColorData): Array<TokenNumber> | false; | ||
export declare function normalize_legacy_HSL_ChannelValues(token: CSSToken, index: number, colorData: ColorData): CSSToken | false; | ||
export declare function normalize_modern_HSL_ChannelValues(token: CSSToken, index: number, colorData: ColorData): CSSToken | false; |
3 changes: 1 addition & 2 deletions
3
packages/css-color-parser/dist/functions/hwb-normalize-channel-values.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import type { ColorData } from '../color-data'; | ||
import type { TokenNumber } from '@csstools/css-tokenizer'; | ||
import { CSSToken } from '@csstools/css-tokenizer'; | ||
export declare function normalize_HWB_ChannelValues(tokens: Array<CSSToken>, colorData: ColorData): Array<TokenNumber> | false; | ||
export declare function normalize_HWB_ChannelValues(token: CSSToken, index: number, colorData: ColorData): CSSToken | false; |
3 changes: 1 addition & 2 deletions
3
packages/css-color-parser/dist/functions/lab-normalize-channel-values.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import type { ColorData } from '../color-data'; | ||
import type { TokenNumber } from '@csstools/css-tokenizer'; | ||
import { CSSToken } from '@csstools/css-tokenizer'; | ||
export declare function normalize_Lab_ChannelValues(tokens: Array<CSSToken>, colorData: ColorData): Array<TokenNumber> | false; | ||
export declare function normalize_Lab_ChannelValues(token: CSSToken, index: number, colorData: ColorData): CSSToken | false; |
3 changes: 1 addition & 2 deletions
3
packages/css-color-parser/dist/functions/lch-normalize-channel-values.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import type { ColorData } from '../color-data'; | ||
import type { TokenNumber } from '@csstools/css-tokenizer'; | ||
import { CSSToken } from '@csstools/css-tokenizer'; | ||
export declare function normalize_LCH_ChannelValues(tokens: Array<CSSToken>, colorData: ColorData): Array<TokenNumber> | false; | ||
export declare function normalize_LCH_ChannelValues(token: CSSToken, index: number, colorData: ColorData): CSSToken | false; |
3 changes: 1 addition & 2 deletions
3
packages/css-color-parser/dist/functions/normalize-channel-values.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import type { ColorData } from '../color-data'; | ||
import type { TokenNumber } from '@csstools/css-tokenizer'; | ||
import { CSSToken } from '@csstools/css-tokenizer'; | ||
export type normalizeChannelValuesFn = (tokens: Array<CSSToken>, colorData: ColorData) => Array<TokenNumber> | false; | ||
export type normalizeChannelValuesFn = (token: CSSToken, index: number, colorData: ColorData) => CSSToken | false; |
3 changes: 1 addition & 2 deletions
3
packages/css-color-parser/dist/functions/oklab-normalize-channel-values.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import type { ColorData } from '../color-data'; | ||
import type { TokenNumber } from '@csstools/css-tokenizer'; | ||
import { CSSToken } from '@csstools/css-tokenizer'; | ||
export declare function normalize_OKLab_ChannelValues(tokens: Array<CSSToken>, colorData: ColorData): Array<TokenNumber> | false; | ||
export declare function normalize_OKLab_ChannelValues(token: CSSToken, index: number, colorData: ColorData): CSSToken | false; |
3 changes: 1 addition & 2 deletions
3
packages/css-color-parser/dist/functions/oklch-normalize-channel-values.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import type { ColorData } from '../color-data'; | ||
import type { TokenNumber } from '@csstools/css-tokenizer'; | ||
import { CSSToken } from '@csstools/css-tokenizer'; | ||
export declare function normalize_OKLCH_ChannelValues(tokens: Array<CSSToken>, colorData: ColorData): Array<TokenNumber> | false; | ||
export declare function normalize_OKLCH_ChannelValues(token: CSSToken, index: number, colorData: ColorData): CSSToken | false; |
5 changes: 2 additions & 3 deletions
5
packages/css-color-parser/dist/functions/rgb-normalize-channel-values.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import type { ColorData } from '../color-data'; | ||
import type { TokenNumber } from '@csstools/css-tokenizer'; | ||
import { CSSToken } from '@csstools/css-tokenizer'; | ||
export declare function normalize_legacy_sRGB_ChannelValues(tokens: Array<CSSToken>, colorData: ColorData): Array<TokenNumber> | false; | ||
export declare function normalize_modern_sRGB_ChannelValues(tokens: Array<CSSToken>, colorData: ColorData): Array<TokenNumber> | false; | ||
export declare function normalize_legacy_sRGB_ChannelValues(token: CSSToken, index: number, colorData: ColorData): CSSToken | false; | ||
export declare function normalize_modern_sRGB_ChannelValues(token: CSSToken, index: number, colorData: ColorData): CSSToken | false; |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
111 changes: 50 additions & 61 deletions
111
packages/css-color-parser/src/functions/color-normalize-channel-values.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,68 @@ | ||
import type { ColorData } from '../color-data'; | ||
import { CSSToken, NumberType, TokenNumber, TokenType } from '@csstools/css-tokenizer'; | ||
import { CSSToken, NumberType, TokenType } from '@csstools/css-tokenizer'; | ||
import { SyntaxFlag } from '../color-data'; | ||
import { normalize } from './normalize'; | ||
import { toLowerCaseAZ } from '../util/to-lower-case-a-z'; | ||
|
||
export function normalize_Color_ChannelValues(tokens: Array<CSSToken>, colorData: ColorData): Array<TokenNumber> | false { | ||
const result: Array<TokenNumber> = []; | ||
export function normalize_Color_ChannelValues(token: CSSToken, index: number, colorData: ColorData): CSSToken | false { | ||
if (token[0] === TokenType.Ident && toLowerCaseAZ(token[4].value) === 'none') { | ||
colorData.syntaxFlags.add(SyntaxFlag.HasNoneKeywords); | ||
|
||
for (let index = 0; index < tokens.length; index++) { | ||
const token = tokens[index]; | ||
|
||
if (token[0] === TokenType.Ident && toLowerCaseAZ(token[4].value) === 'none') { | ||
colorData.syntaxFlags.add(SyntaxFlag.HasNoneKeywords); | ||
return [ | ||
TokenType.Number, | ||
'none', | ||
token[2], | ||
token[3], | ||
{ | ||
value: NaN, | ||
type: NumberType.Number, | ||
}, | ||
]; | ||
} | ||
|
||
result.push([ | ||
TokenType.Number, | ||
'none', | ||
token[2], | ||
token[3], | ||
{ | ||
value: NaN, | ||
type: NumberType.Number, | ||
}, | ||
]); | ||
continue; | ||
if (token[0] === TokenType.Percentage) { | ||
if (index !== 3) { | ||
colorData.syntaxFlags.add(SyntaxFlag.HasPercentageValues); | ||
} | ||
|
||
if (token[0] === TokenType.Percentage) { | ||
if (index !== 3) { | ||
colorData.syntaxFlags.add(SyntaxFlag.HasPercentageValues); | ||
} | ||
|
||
let value = normalize(token[4].value, 100, -Infinity, Infinity); | ||
if (index === 3) { | ||
value = normalize(token[4].value, 100, 0, 1); | ||
} | ||
|
||
result.push([ | ||
TokenType.Number, | ||
value.toString(), | ||
token[2], | ||
token[3], | ||
{ | ||
value: value, | ||
type: NumberType.Number, | ||
}, | ||
]); | ||
continue; | ||
let value = normalize(token[4].value, 100, -Infinity, Infinity); | ||
if (index === 3) { | ||
value = normalize(token[4].value, 100, 0, 1); | ||
} | ||
|
||
if (token[0] === TokenType.Number) { | ||
if (index !== 3) { | ||
colorData.syntaxFlags.add(SyntaxFlag.HasNumberValues); | ||
} | ||
return [ | ||
TokenType.Number, | ||
value.toString(), | ||
token[2], | ||
token[3], | ||
{ | ||
value: value, | ||
type: NumberType.Number, | ||
}, | ||
]; | ||
} | ||
|
||
let value = normalize(token[4].value, 1, -Infinity, Infinity); | ||
if (index === 3) { | ||
value = normalize(token[4].value, 1, 0, 1); | ||
} | ||
if (token[0] === TokenType.Number) { | ||
if (index !== 3) { | ||
colorData.syntaxFlags.add(SyntaxFlag.HasNumberValues); | ||
} | ||
|
||
result.push([ | ||
TokenType.Number, | ||
value.toString(), | ||
token[2], | ||
token[3], | ||
{ | ||
value: value, | ||
type: NumberType.Number, | ||
}, | ||
]); | ||
continue; | ||
let value = normalize(token[4].value, 1, -Infinity, Infinity); | ||
if (index === 3) { | ||
value = normalize(token[4].value, 1, 0, 1); | ||
} | ||
|
||
return false; | ||
return [ | ||
TokenType.Number, | ||
value.toString(), | ||
token[2], | ||
token[3], | ||
{ | ||
value: value, | ||
type: NumberType.Number, | ||
}, | ||
]; | ||
} | ||
|
||
return result; | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.