const cssProps = [ 'color' , 'border-color' , 'background-color' , 'flex-grow' , 'flex' , 'flex-shrink' , 'caret-color' , 'font' , 'gap' , 'opacity' , 'visibility' , 'z-index' , 'font-weight' , 'zoom' , 'text-shadow' , 'transform' , 'box-shadow' , 'backround-position' , 'left' , 'right' , 'top' , 'bottom' , 'object-position' , 'max-height' , 'min-height' , 'max-width' , 'min-width' , 'height' , 'width' , 'border-width' , 'margin' , 'padding' , 'outline-width' , 'outline-offset' , 'font-size' , 'line-height' , 'text-indent' , 'vertical-align' , 'border-spacing' , 'letter-spacing' , 'word-spacing' , 'stroke' , 'filter' , 'backdrop-filter' , 'fill' , 'mask' , 'mask-size' , 'mask-border' , 'clip-path' , 'clip' , ] ; const numberWithUnitRE = /^(-?[0-9.]+)(px|pt|pc|rem|em|%|vh|vw|in|cm|mm|ex|ch|vmin|vmax)?$/i ; const numberRE = /^(-?[0-9.]+)$/i ; const unitOnlyRE = /^(px)$/i ; function round ( n ) { return n . toFixed ( 10 ) . replace ( /\.0+$/ , '' ) . replace ( /(\.\d+?)0+$/ , '$1' ) ; } export function numberWithUnit ( str ) { const match = str . match ( numberWithUnitRE ) ; if ( ! match ) return ; const [ , n , unit ] = match ; const num = parseFloat ( n ) ; if ( unit && ! Number . isNaN ( num ) ) return `${ round ( num ) }${ unit }` ; } export function auto ( str ) { if ( str === 'auto' || str === 'a' ) return 'auto' ; } export function rem ( str ) { if ( str . match ( unitOnlyRE ) ) return `1${ str }` ; const match = str . match ( numberWithUnitRE ) ; if ( ! match ) return ; const [ , n , unit ] = match ; const num = parseFloat ( n ) ; if ( ! Number . isNaN ( num ) ) return unit ? `${ round ( num ) }${ unit }` : `${ round ( num / 4 ) }rem` ; } export function px ( str ) { if ( str . match ( unitOnlyRE ) ) return `1${ str }` ; const match = str . match ( numberWithUnitRE ) ; if ( ! match ) return ; const [ , n , unit ] = match ; const num = parseFloat ( n ) ; if ( ! Number . isNaN ( num ) ) return unit ? `${ round ( num ) }${ unit }` : `${ round ( num ) }px` ; } export function number ( str ) { if ( ! numberRE . test ( str ) ) return ; const num = parseFloat ( str ) ; if ( ! Number . isNaN ( num ) ) return round ( num ) ; } export function percent ( str ) { if ( str . endsWith ( '%' ) ) str = str . slice ( 0 , - 1 ) ; const num = parseFloat ( str ) ; if ( ! Number . isNaN ( num ) ) return `${ round ( num / 100 ) }` ; } export function fraction ( str ) { if ( str === 'full' ) return '100%' ; const [ left , right ] = str . split ( '/' ) ; const num = parseFloat ( left ) / parseFloat ( right ) ; if ( ! Number . isNaN ( num ) ) return `${ round ( num * 100 ) }%` ; } export function bracket ( str ) { if ( str && str [ 0 ] === '[' && str [ str . length - 1 ] === ']' ) { return str . slice ( 1 , - 1 ) . replace ( /(url\(.*?\))/g , v => v . replace ( /_/g , '\\_' ) ) . replace ( /(?<!\\)_/g , ' ' ) . replace ( /calc\((.*)/g , ( v ) => { return v . replace ( /(-?\d*\.?\d(?!\b-.+[,)](?![^+\-/*])\D)(?:%|[a-z]+)?|\))([+\-/*])/g , '$1 $2 ' ) ; } ) ; } } export function cssvar ( str ) { if ( str . startsWith ( '$' ) ) return `var(--${ str . slice ( 1 ) })` ; } export function time ( str ) { const match = str . match ( /^(-?[0-9.]+)(s|ms)?$/i ) ; if ( ! match ) return ; const [ , n , unit ] = match ; const num = parseFloat ( n ) ; if ( ! Number . isNaN ( num ) ) return unit ? `${ round ( num ) }${ unit }` : `${ round ( num ) }ms` ; } export function degree ( str ) { const match = str . match ( /^(-?[0-9.]+)(deg|rad|grad|turn)?$/i ) ; if ( ! match ) return ; const [ , n , unit ] = match ; const num = parseFloat ( n ) ; if ( ! Number . isNaN ( num ) ) return unit ? `${ round ( num ) }${ unit }` : `${ round ( num ) }deg` ; } export function global ( str ) { if ( [ 'inherit' , 'initial' , 'revert' , 'unset' ] . includes ( str ) ) return str ; } export function properties ( str ) { for ( const prop of str . split ( ',' ) ) { if ( ! cssProps . includes ( prop ) ) return ; } return str ; }