import plugin from 'tailwindcss/plugin' ; import corePlugins from './corePlugins' ; import { escape } from './util' ; import { createExpandThemeConfig } from './defaultConfig' ; import type { TailwindConfig } from 'tailwindcss/tailwind-config' ; import type { IPresetOption } from './types' ; const emptyVariants = corePlugins . reduce < Record < string , any [ ] > > ( ( acc , cur ) => { acc [ cur ] = [ ] ; return acc ; } , { } ) ; export function createPreset ( option ? ) { const expandThemeConfig = createExpandThemeConfig ( option ) ; return { purge : { content : [ './public/index.html' , './src/**/*.{vue,js,ts,jsx,tsx,wxml}' ] } , darkMode : false , important : true , corePlugins , theme : { screens : { } , ... expandThemeConfig , extend : { } } , variants : { ... emptyVariants , extend : { } } , plugins : [ plugin ( function ( { addUtilities , e , config } ) { function escapeUtilities ( path , prefix , attrKey ) { const utilities = Object . entries ( config ( path ) ) . reduce < Record < string , any > [ ] > ( ( acc , [ key , value ] ) => { if ( path === 'theme.margin' && key [ 0 ] === '-' ) { return acc ; } const str = escape ( `${ prefix }${ key }` ) ; if ( typeof attrKey === 'function' ) { const fn = attrKey ; acc . push ( { [ `.${ e ( str ) }` ] : fn ( value as string ) } ) ; } else { acc . push ( { [ `.${ e ( str ) }` ] : { [ attrKey ] : `${ value }` } } ) ; } return acc ; } , [ ] ) ; addUtilities ( utilities ) ; } escapeUtilities ( 'theme.height' , 'h-' , 'height' ) ; escapeUtilities ( 'theme.margin' , 'm-' , 'margin' ) ; escapeUtilities ( 'theme.margin' , 'my-' , ( value ) => { return { 'margin-top' : `${ value }` , 'margin-bottom' : `${ value }` } ; } ) ; escapeUtilities ( 'theme.margin' , 'mx-' , ( value ) => { return { 'margin-left' : `${ value }` , 'margin-right' : `${ value }` } ; } ) ; escapeUtilities ( 'theme.margin' , 'mt-' , 'margin-top' ) ; escapeUtilities ( 'theme.margin' , 'mr-' , 'margin-right' ) ; escapeUtilities ( 'theme.margin' , 'mb-' , 'margin-bottom' ) ; escapeUtilities ( 'theme.margin' , 'ml-' , 'margin-left' ) ; escapeUtilities ( 'theme.maxHeight' , 'max-h-' , 'max-height' ) ; escapeUtilities ( 'theme.padding' , 'p-' , 'padding' ) ; escapeUtilities ( 'theme.padding' , 'py-' , ( value ) => { return { 'padding-top' : `${ value }` , 'padding-bottom' : `${ value }` } ; } ) ; escapeUtilities ( 'theme.padding' , 'px-' , ( value ) => { return { 'padding-left' : `${ value }` , 'padding-right' : `${ value }` } ; } ) ; escapeUtilities ( 'theme.padding' , 'pt-' , 'padding-top' ) ; escapeUtilities ( 'theme.padding' , 'pr-' , 'padding-right' ) ; escapeUtilities ( 'theme.padding' , 'pb-' , 'padding-bottom' ) ; escapeUtilities ( 'theme.padding' , 'pl-' , 'padding-left' ) ; escapeUtilities ( 'theme.width' , 'w-' , 'width' ) ; } ) ] } ; } export default createPreset ( ) ;