import type * as d from '../../declarations' ; import { DEFAULT_STYLE_MODE , normalizePath } from '@utils' ; import { dirname , isAbsolute , join , relative } from 'path' ; export const normalizeStyles = ( tagName , componentFilePath , styles ) => { styles . forEach ( ( style ) => { if ( style . modeName === DEFAULT_STYLE_MODE ) { style . styleId = tagName . toUpperCase ( ) ; } else { style . styleId = `${ tagName . toUpperCase ( ) }#${ style . modeName }` ; } if ( Array . isArray ( style . externalStyles ) ) { style . externalStyles . forEach ( ( externalStyle ) => { normalizeExternalStyle ( componentFilePath , externalStyle ) ; } ) ; } } ) ; } ; const normalizeExternalStyle = ( componentFilePath , externalStyle ) => { if ( typeof externalStyle . originalComponentPath !== 'string' || externalStyle . originalComponentPath . trim ( ) . length === 0 ) { return ; } const componentDir = dirname ( componentFilePath ) ; if ( isAbsolute ( externalStyle . originalComponentPath ) ) { externalStyle . absolutePath = normalizePath ( externalStyle . originalComponentPath ) ; externalStyle . relativePath = normalizePath ( relative ( componentDir , externalStyle . originalComponentPath ) ) ; } else { externalStyle . relativePath = normalizePath ( externalStyle . originalComponentPath ) ; externalStyle . absolutePath = normalizePath ( join ( componentDir , externalStyle . originalComponentPath ) ) ; } } ;