11import type { CSSEntries , DynamicMatcher , Preset , RuleContext } from 'unocss'
22import { cornerMap , directionSize , h } from '@unocss/preset-wind4/utils'
33
4+ // Track warnings to avoid duplicates
5+ const warnedClasses = new Set < string > ( )
6+
7+ function warnOnce ( message : string , key : string ) {
8+ if ( ! warnedClasses . has ( key ) ) {
9+ warnedClasses . add ( key )
10+ // oxlint-disable-next-line no-console -- warn logging
11+ console . warn ( message )
12+ }
13+ }
14+
15+ /** Reset warning state (for testing) */
16+ export function resetRtlWarnings ( ) {
17+ warnedClasses . clear ( )
18+ }
19+
420const directionMap : Record < string , string [ ] > = {
521 'l' : [ '-left' ] ,
622 'r' : [ '-right' ] ,
@@ -30,9 +46,9 @@ function directionSizeRTL(
3046 const defaultMap = { l : 'is' , r : 'ie' }
3147 const map = prefixMap || defaultMap
3248 const replacement = map [ direction as 'l' | 'r' ]
33- // oxlint-disable-next-line no-console -- warn logging
34- console . warn (
49+ warnOnce (
3550 `[RTL] Avoid using '${ match } '. Use '${ match . replace ( direction === 'l' ? 'l' : 'r' , replacement ) } ' instead.` ,
51+ match ,
3652 )
3753 return matcher ( [ match , replacement , size ] , context )
3854 }
@@ -83,9 +99,9 @@ export function presetRtl(): Preset {
8399 ( [ , direction , size ] , context ) => {
84100 if ( ! size ) return undefined
85101 const replacement = direction === 'left' ? 'inset-is' : 'inset-ie'
86- // oxlint-disable-next-line no-console -- warn logging
87- console . warn (
102+ warnOnce (
88103 `[RTL] Avoid using '${ direction } -${ size } '. Use '${ replacement } -${ size } ' instead.` ,
104+ `${ direction } -${ size } ` ,
89105 )
90106 return directionSize ( 'inset' ) ( [ '' , direction === 'left' ? 'is' : 'ie' , size ] , context )
91107 } ,
@@ -95,8 +111,10 @@ export function presetRtl(): Preset {
95111 / ^ t e x t - ( l e f t | r i g h t ) $ / ,
96112 ( [ , direction ] ) => {
97113 const replacement = direction === 'left' ? 'start' : 'end'
98- // oxlint-disable-next-line no-console -- warn logging
99- console . warn ( `[RTL] Avoid using 'text-${ direction } '. Use 'text-${ replacement } ' instead.` )
114+ warnOnce (
115+ `[RTL] Avoid using 'text-${ direction } '. Use 'text-${ replacement } ' instead.` ,
116+ `text-${ direction } ` ,
117+ )
100118 return { 'text-align' : replacement }
101119 } ,
102120 { autocomplete : 'text-(left|right)' } ,
@@ -112,9 +130,9 @@ export function presetRtl(): Preset {
112130 }
113131 const replacement = replacementMap [ direction ]
114132 if ( ! replacement ) return undefined
115- // oxlint-disable-next-line no-console -- warn logging
116- console . warn (
133+ warnOnce (
117134 `[RTL] Avoid using 'rounded-${ direction } '. Use 'rounded-${ replacement } ' instead.` ,
135+ `rounded-${ direction } ` ,
118136 )
119137 return handlerRounded ( [ '' , replacement , size ?? 'DEFAULT' ] , context )
120138 } ,
@@ -124,9 +142,9 @@ export function presetRtl(): Preset {
124142 args => {
125143 const [ _ , direction , size ] = args
126144 const replacement = direction === 'l' ? 'is' : 'ie'
127- // oxlint-disable-next-line no-console -- warn logging
128- console . warn (
145+ warnOnce (
129146 `[RTL] Avoid using 'border-${ direction } '. Use 'border-${ replacement } ' instead.` ,
147+ `border-${ direction } ` ,
130148 )
131149 return handlerBorderSize ( [ '' , replacement , size || '1' ] )
132150 } ,
0 commit comments