import type { CSSEntries , CSSObject , DynamicMatcher , Rule , RuleContext } from '@unocss/core' ; import type { Theme } from '../theme' ; import { cornerMap , directionMap , handler as h , parseColor } from '../utils' ; export const borders = [ [ /^(?:border|b)()(?:-(.+))?$/ , handlerBorder ] , [ /^(?:border|b)-([xy])(?:-(.+))?$/ , handlerBorder ] , [ /^(?:border|b)-([rltbse])(?:-(.+))?$/ , handlerBorder ] , [ /^(?:border|b)-(block|inline)(?:-(.+))?$/ , handlerBorder ] , [ /^(?:border|b)-([bi][se])(?:-(.+))?$/ , handlerBorder ] , [ /^(?:border|b)-()(?:width|size)-(.+)$/ , handlerBorderSize ] , [ /^(?:border|b)-([xy])-(?:width|size)-(.+)$/ , handlerBorderSize ] , [ /^(?:border|b)-([rltbse])-(?:width|size)-(.+)$/ , handlerBorderSize ] , [ /^(?:border|b)-(block|inline)-(?:width|size)-(.+)$/ , handlerBorderSize ] , [ /^(?:border|b)-([bi][se])-(?:width|size)-(.+)$/ , handlerBorderSize ] , [ /^(?:border|b)-()(?:color-)?(.+)$/ , handlerBorderColor ] , [ /^(?:border|b)-([xy])-(?:color-)?(.+)$/ , handlerBorderColor ] , [ /^(?:border|b)-([rltbse])-(?:color-)?(.+)$/ , handlerBorderColor ] , [ /^(?:border|b)-(block|inline)-(?:color-)?(.+)$/ , handlerBorderColor ] , [ /^(?:border|b)-([bi][se])-(?:color-)?(.+)$/ , handlerBorderColor ] , [ /^(?:border|b)-()op(?:acity)?-?(.+)$/ , handlerBorderOpacity ] , [ /^(?:border|b)-([xy])-op(?:acity)?-?(.+)$/ , handlerBorderOpacity ] , [ /^(?:border|b)-([rltbse])-op(?:acity)?-?(.+)$/ , handlerBorderOpacity ] , [ /^(?:border|b)-(block|inline)-op(?:acity)?-?(.+)$/ , handlerBorderOpacity ] , [ /^(?:border|b)-([bi][se])-op(?:acity)?-?(.+)$/ , handlerBorderOpacity ] , [ /^(?:border-)?(?:rounded|rd)()(?:-(.+))?$/ , handlerRounded ] , [ /^(?:border-)?(?:rounded|rd)-([rltb])(?:-(.+))?$/ , handlerRounded ] , [ /^(?:border-)?(?:rounded|rd)-([rltb]{2})(?:-(.+))?$/ , handlerRounded ] , [ /^(?:border-)?(?:rounded|rd)-([bi][se])(?:-(.+))?$/ , handlerRounded ] , [ /^(?:border-)?(?:rounded|rd)-([bi][se]-[bi][se])(?:-(.+))?$/ , handlerRounded ] , [ 'border-solid' , { 'border-style' : 'solid' } ] , [ 'border-dashed' , { 'border-style' : 'dashed' } ] , [ 'border-dotted' , { 'border-style' : 'dotted' } ] , [ 'border-double' , { 'border-style' : 'double' } ] , [ 'border-hidden' , { 'border-style' : 'hidden' } ] , [ 'border-none' , { 'border-style' : 'none' } ] , ] ; const borderHasColor = ( color , { theme } ) => { return color !== undefined && ! ! parseColor ( color , theme ) ?. color ; } ; const borderColorResolver = ( direction ) : DynamicMatcher => ( [ , body ] , { theme } ) : CSSObject | undefined => { const data = parseColor ( body , theme ) ; if ( ! data ) return ; const { alpha , opacity , color , rgba } = data ; if ( ! color ) return ; if ( rgba ) { if ( alpha != null ) { return { [ `border${ direction }-color` ] : `rgba(${ rgba . join ( ',' ) })` , } ; } else { if ( direction === '' ) { return { '--un-border-opacity' : ( opacity && h . cssvar ( opacity ) ) ?? 1 , [ `border${ direction }-color` ] : `rgba(${ rgba . join ( ',' ) },var(--un-border${ direction }-opacity))` , } ; } else { return { '--un-border-opacity' : ( opacity && h . cssvar ( opacity ) ) ?? 1 , [ `--un-border${ direction }-opacity` ] : 'var(--un-border-opacity)' , [ `border${ direction }-color` ] : `rgba(${ rgba . join ( ',' ) },var(--un-border${ direction }-opacity))` , } ; } } } else { return { [ `border${ direction }-color` ] : color . replace ( '%alpha' , `${ alpha || 1 }` ) , } ; } } ; function handlerBorder ( m ) { const borderSizes = handlerBorderSize ( m ) ; if ( borderSizes ) { return [ ... borderSizes , [ 'border-style' , 'solid' ] , ] ; } } function handlerBorderSize ( [ , a = '' , b = '1' ] ) { const v = h . bracket . cssvar . px ( b ) ; if ( a in directionMap && v != null ) return directionMap [ a ] . map ( i => [ `border${ i }-width` , v ] ) ; } function handlerBorderColor ( [ , a = '' , c ] , ctx ) { if ( a in directionMap && borderHasColor ( c , ctx ) ) { return Object . assign ( { } , ... directionMap [ a ] . map ( i => borderColorResolver ( i ) ( [ '' , c ] , ctx ) ) ) ; } } function handlerBorderOpacity ( [ , a = '' , opacity ] ) { const v = h . bracket . percent ( opacity ) ; if ( a in directionMap && v != null ) return directionMap [ a ] . map ( i => [ `--un-border${ i }-opacity` , v ] ) ; } function handlerRounded ( [ , a = '' , s = 'DEFAULT' ] , { theme } ) { const v = theme . borderRadius ?. [ s ] || h . bracket . cssvar . fraction . rem ( s ) ; if ( a in cornerMap && v != null ) return cornerMap [ a ] . map ( i => [ `border${ i }-radius` , v ] ) ; }