import type { Variant } from '@unocss/core' ; import type { Theme } from '../theme' ; const regexCache = { } ; export const variantBreakpoints = ( matcher , { theme } ) => { const variantEntries = Object . entries ( theme . breakpoints || { } ) . map ( ( [ point , size ] , idx ) => [ point , size , idx ] ) ; for ( const [ point , size , idx ] of variantEntries ) { if ( ! regexCache [ point ] ) regexCache [ point ] = new RegExp ( `^((?:[al]t-)?${ point }[:-])` ) ; const match = matcher . match ( regexCache [ point ] ) ; if ( ! match ) continue ; const [ , pre ] = match ; const m = matcher . slice ( pre . length ) ; if ( m === 'container' ) continue ; let direction = 'min' ; let order = 1000 ; if ( pre . startsWith ( 'lt-' ) ) { direction = 'max' ; order -= ( idx + 1 ) ; } else { order += ( idx + 1 ) ; } if ( pre . startsWith ( 'at-' ) && idx < variantEntries . length - 1 ) { return { matcher : m , parent : [ `@media (min-width: ${ size }) and (max-width: ${ variantEntries [ idx + 1 ] [ 1 ] })` , order ] , } ; } return { matcher : m , parent : [ `@media (${ direction }-width: ${ size })` , order ] , } ; } } ;