Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions packages/uniwind/src/metro/processor/color.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Color as ColorType, converter, formatHex, formatHex8, parse } from 'culori'
import { CssColor } from 'lightningcss'
import { CssColor, UnresolvedColor } from 'lightningcss'
import { Logger } from '../logger'
import { pipe } from '../utils'
import type { ProcessorBuilder } from './processor'

export class Color {
Expand All @@ -12,7 +13,7 @@ export class Color {

constructor(private readonly Processor: ProcessorBuilder) {}

processColor(color: CssColor) {
processColor(color: CssColor | UnresolvedColor) {
if (typeof color === 'string') {
const parsed = parse(color)

Expand All @@ -31,11 +32,19 @@ export class Color {
}

if (color.type === 'rgb' || color.type === 'srgb') {
const alpha = typeof color.alpha === 'number'
? color.alpha
: pipe(color.alpha)(
x => this.Processor.CSS.processValue(x),
Number,
x => isNaN(x) ? 1 : x,
)

return this.format({
r: color.r / 255,
g: color.g / 255,
b: color.b / 255,
alpha: color.alpha,
alpha,
mode: 'rgb',
})
}
Expand Down
2 changes: 2 additions & 0 deletions packages/uniwind/src/metro/processor/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ export class CSS {
return ')'
case 'light-dark':
return `rt.lightDark( ${this.processValue(declarationValue.light)}, ${this.processValue(declarationValue.dark)} )`
case 'unresolved-color':
return this.getProcessedValue(declarationValue.value)
case 'track-list':
case 'sticky':
case 'fit-content':
Expand Down
2 changes: 2 additions & 0 deletions packages/uniwind/src/metro/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
ParsedComponent,
Token,
TokenOrValue,
UnresolvedColor,
} from 'lightningcss'
import { ColorScheme, Orientation } from '../types'

Expand Down Expand Up @@ -62,6 +63,7 @@ export type DeclarationValues =
| LineDirection
| GradientItemFor_DimensionPercentageFor_LengthValue
| AbsoluteFontWeight
| UnresolvedColor

export type ProcessMetaValues = {
className?: string | null
Expand Down