/* © Andy Bell - https://buildexcellentwebsit.es/ */ const plugin = require('tailwindcss/plugin'); const postcss = require('postcss'); const postcssJs = require('postcss-js'); const clampGenerator = require('./src/utilities/clamp-generator.js'); const tokensToTailwind = require('./src/utilities/tokens-to-tailwind.js'); // Raw design tokens const colorTokens = require('./src/_data/designTokens/colors.json'); const fontTokens = require('./src/_data/designTokens/fonts.json'); const spacingTokens = require('./src/_data/designTokens/spacing.json'); const textSizeTokens = require('./src/_data/designTokens/sizes.json'); // Process design tokens const colors = tokensToTailwind(colorTokens.items); const fontFamily = tokensToTailwind(fontTokens.items); const fontSize = tokensToTailwind(clampGenerator(textSizeTokens.items)); const spacing = tokensToTailwind(clampGenerator(spacingTokens.items)); module.exports = { content: ['./src/**/*.{html,js,md,njk,liquid,webc}'], presets: [], theme: { screens: { ltsm: {max: '39em'}, sm: '40em', md: '63em' }, colors, spacing, fontSize, fontFamily, fontWeight: { normal: 500, semi: 600, bold: 800 }, backgroundColor: ({theme}) => theme('colors'), textColor: ({theme}) => theme('colors'), margin: ({theme}) => ({ auto: 'auto', ...theme('spacing') }), padding: ({theme}) => theme('spacing') }, variantOrder: [ 'first', 'last', 'odd', 'even', 'visited', 'checked', 'empty', 'read-only', 'group-hover', 'group-focus', 'focus-within', 'hover', 'focus', 'focus-visible', 'active', 'disabled' ], // Disables Tailwind's reset etc corePlugins: { preflight: false }, plugins: [ // Generates custom property values from tailwind config plugin(function ({addComponents, config}) { let result = ''; const currentConfig = config(); const groups = [ {key: 'colors', prefix: 'color'}, {key: 'spacing', prefix: 'space'}, {key: 'fontSize', prefix: 'size'}, {key: 'fontFamily', prefix: 'font'} ]; groups.forEach(({key, prefix}) => { const group = currentConfig.theme[key]; if (!group) { return; } Object.keys(group).forEach(key => { result += `--${prefix}-${key}: ${group[key]};`; }); }); addComponents({ ':root': postcssJs.objectify(postcss.parse(result)) }); }), // Generates custom utility classes plugin(function ({addUtilities, config}) { const currentConfig = config(); const customUtilities = [ {key: 'spacing', prefix: 'flow-space', property: '--flow-space'}, {key: 'colors', prefix: 'spot-color', property: '--spot-color'} ]; customUtilities.forEach(({key, prefix, property}) => { const group = currentConfig.theme[key]; if (!group) { return; } Object.keys(group).forEach(key => { addUtilities({ [`.${prefix}-${key}`]: postcssJs.objectify( postcss.parse(`${property}: ${group[key]}`) ) }); }); }); }) ] };