import { getConfig } from './helpers' ; export function connect ( strings ) { return Array . isArray ( strings ) ? new RegExp ( strings . map ( i => `(${ i })` ) . join ( '|' ) ) : new RegExp ( strings ) ; } export function allowAttr ( type ) { return type ? [ 'html' , 'js' ] . includes ( type ) : true ; } const classPattern = String . raw `(\s+class(Name)?\s*=\s*{?\s*["'\`])[^"'\`]*$` ; const emmetPattern = String . raw `\.\S*$` ; const applyPattern = String . raw `@apply\s+[^;]*$` ; const windiPattern = String . raw `\Wwindi\`[^\`]*$` ; const htmlPattern = getConfig ( 'windicss.enableEmmetCompletion' ) ? [ classPattern , applyPattern , emmetPattern , windiPattern ] : [ classPattern , applyPattern , windiPattern ] ; export const applyRegex = new RegExp ( applyPattern ) ; export const patterns = { 'html' : connect ( htmlPattern ) , 'js' : connect ( htmlPattern ) , 'css' : connect ( applyPattern ) , } ; export const fileTypes = { 'css' : { type : 'css' , } , 'scss' : { type : 'css' , } , 'sass' : { type : 'css' , } , 'less' : { type : 'css' , } , 'postcss' : { type : 'css' , } , 'javascript' : { type : 'js' , } , 'javascriptreact' : { type : 'js' , } , 'typescriptreact' : { type : 'js' , } , 'html' : { type : 'html' , } , 'php' : { type : 'html' , } , 'vue' : { type : 'html' , pattern : /(\s+(v-bind)?:class\s*=\s*["][{[][^"]*$)|(\s+(v-bind)?:class\s*=\s*['][{[][^']*$)/ , } , 'svelte' : { type : 'html' , pattern : /(\s+class:\S*$)|((\s+class\s*=\s*["]\s*{?\s*)[^"]*$)|((\s+class\s*=\s*[']\s*{?\s*)[^']*$)|((\s+class\s*=\s*[`]\s*{?\s*)[^`]*$)/ , } , } ; if ( getConfig ( 'windicss.includeLanguages' ) ) { const config = getConfig < { [ key ] : ( string | { type ? : string ; patterns ? : string [ ] ; } ) ; } > ( 'windicss.includeLanguages' ) ; if ( config ) { Object . entries ( config ) . map ( ( [ key , value ] ) => { if ( typeof value === 'string' ) { fileTypes [ key ] = { type : value in patterns ? value : 'css' } ; } else { const pattern = ( value . patterns === undefined || value . patterns . length === 0 ) ? undefined : value . patterns ; if ( key in fileTypes ) { fileTypes [ key ] = { type : value . type || fileTypes [ key ] . type , pattern : fileTypes [ key ] . pattern ? pattern ? connect ( [ ( fileTypes [ key ] . pattern as RegExp ) . source , ... pattern ] ) : fileTypes [ key ] . pattern : pattern ? connect ( [ ... pattern ] ) : undefined } ; } else if ( value . type && value . type in fileTypes ) { fileTypes [ key ] = { type : value . type || fileTypes [ value . type ] . type , pattern : fileTypes [ value . type ] . pattern ? pattern ? connect ( [ ( fileTypes [ value . type ] . pattern as RegExp ) . source , ... pattern ] ) : fileTypes [ value . type ] . pattern : pattern ? connect ( [ ... pattern ] ) : undefined } ; } } } ) ; } }