@@ -2,6 +2,7 @@ import type { CSSObject, Preset } from '@unocss/core'
22import type { Theme } from '@unocss/preset-mini'
33import type { TypographyCompatibilityOptions } from './types/compatibilityOptions'
44import { definePreset , toEscapedSelector } from '@unocss/core'
5+ import { alphaPlaceholders } from '@unocss/rule-utils'
56import { getElements , getPreflights } from './preflights'
67
78/**
@@ -100,28 +101,49 @@ export const presetTypography = definePreset((options?: TypographyOptions): Pres
100101 return
101102
102103 const colorObject = typeof baseColor === 'object' ? baseColor : { }
103- return {
104- '--un-prose-body' : colorObject [ 700 ] ?? baseColor ,
105- '--un-prose-headings' : colorObject [ 900 ] ?? baseColor ,
106- '--un-prose-links' : colorObject [ 900 ] ?? baseColor ,
107- '--un-prose-lists' : colorObject [ 400 ] ?? baseColor ,
108- '--un-prose-hr' : colorObject [ 200 ] ?? baseColor ,
109- '--un-prose-captions' : colorObject [ 500 ] ?? baseColor ,
110- '--un-prose-code' : colorObject [ 900 ] ?? baseColor ,
111- '--un-prose-borders' : colorObject [ 200 ] ?? baseColor ,
112- '--un-prose-bg-soft' : colorObject [ 100 ] ?? baseColor ,
113-
104+ const TagColorMap = {
105+ 'body' : 700 ,
106+ 'headings' : 900 ,
107+ 'links' : 900 ,
108+ 'lists' : 400 ,
109+ 'hr' : 200 ,
110+ 'captions' : 500 ,
111+ 'code' : 900 ,
112+ 'borders' : 200 ,
113+ 'bg-soft' : 100 ,
114114 // invert colors (dark mode)
115- '--un-prose-invert-body' : colorObject [ 200 ] ?? baseColor ,
116- '--un-prose-invert-headings' : colorObject [ 100 ] ?? baseColor ,
117- '--un-prose-invert-links' : colorObject [ 100 ] ?? baseColor ,
118- '--un-prose-invert-lists' : colorObject [ 500 ] ?? baseColor ,
119- '--un-prose-invert-hr' : colorObject [ 700 ] ?? baseColor ,
120- '--un-prose-invert-captions' : colorObject [ 400 ] ?? baseColor ,
121- '--un-prose-invert-code' : colorObject [ 100 ] ?? baseColor ,
122- '--un-prose-invert-borders' : colorObject [ 700 ] ?? baseColor ,
123- '--un-prose-invert-bg-soft' : colorObject [ 800 ] ?? baseColor ,
115+ 'invert-body' : 200 ,
116+ 'invert-headings' : 100 ,
117+ 'invert-links' : 100 ,
118+ 'invert-lists' : 500 ,
119+ 'invert-hr' : 700 ,
120+ 'invert-captions' : 400 ,
121+ 'invert-code' : 100 ,
122+ 'invert-borders' : 700 ,
123+ 'invert-bg-soft' : 800 ,
124+ }
125+
126+ const result : any = { }
127+
128+ for ( const key in TagColorMap ) {
129+ const value = TagColorMap [ key as keyof typeof TagColorMap ]
130+ const color = colorObject [ value ] ?? baseColor
131+ let hasAlpha = false
132+
133+ for ( const placeholder of alphaPlaceholders ) {
134+ if ( color . includes ( placeholder ) ) {
135+ hasAlpha = true
136+ result [ `--un-prose-${ key } -opacity` ] = 1
137+ result [ `--un-prose-${ key } ` ] = color . replace ( placeholder , `var(--un-prose-${ key } -opacity)` )
138+ break
139+ }
140+ }
141+
142+ if ( ! hasAlpha )
143+ result [ `--un-prose-${ key } ` ] = color
124144 }
145+
146+ return result
125147 } ,
126148 { layer : 'typography' } ,
127149 ] ,
0 commit comments