├── demos ├── laravel │ ├── public │ │ ├── favicon.ico │ │ ├── robots.txt │ │ ├── index.php │ │ └── .htaccess │ ├── database │ │ ├── .gitignore │ │ ├── seeders │ │ │ └── DatabaseSeeder.php │ │ ├── migrations │ │ │ ├── 0001_01_01_000001_create_cache_table.php │ │ │ ├── 0001_01_01_000000_create_users_table.php │ │ │ └── 0001_01_01_000002_create_jobs_table.php │ │ └── factories │ │ │ └── UserFactory.php │ ├── resources │ │ ├── js │ │ │ ├── app.js │ │ │ └── bootstrap.js │ │ ├── css │ │ │ └── app.css │ │ └── views │ │ │ ├── components │ │ │ └── useclassy-test.blade.php │ │ │ └── welcome.blade.php │ ├── bootstrap │ │ ├── cache │ │ │ └── .gitignore │ │ ├── providers.php │ │ └── app.php │ ├── storage │ │ ├── app │ │ │ ├── private │ │ │ │ └── .gitignore │ │ │ ├── public │ │ │ │ └── .gitignore │ │ │ └── .gitignore │ │ └── framework │ │ │ ├── sessions │ │ │ └── .gitignore │ │ │ ├── testing │ │ │ └── .gitignore │ │ │ ├── views │ │ │ └── .gitignore │ │ │ ├── cache │ │ │ ├── data │ │ │ │ └── .gitignore │ │ │ └── .gitignore │ │ │ └── .gitignore │ ├── app │ │ ├── Http │ │ │ └── Controllers │ │ │ │ └── Controller.php │ │ ├── Providers │ │ │ └── AppServiceProvider.php │ │ └── Models │ │ │ └── User.php │ ├── routes │ │ ├── web.php │ │ └── console.php │ ├── tests │ │ ├── TestCase.php │ │ ├── Unit │ │ │ └── ExampleTest.php │ │ └── Feature │ │ │ └── ExampleTest.php │ ├── .gitattributes │ ├── .editorconfig │ ├── .gitignore │ ├── vite.config.js │ ├── artisan │ ├── package.json │ ├── config │ │ ├── services.php │ │ ├── filesystems.php │ │ ├── cache.php │ │ ├── mail.php │ │ ├── queue.php │ │ ├── auth.php │ │ ├── app.php │ │ ├── logging.php │ │ ├── database.php │ │ └── session.php │ ├── phpunit.xml │ ├── .env.example │ ├── composer.json │ └── README.md ├── vue │ ├── public │ │ ├── robots.txt │ │ └── favicon.png │ ├── assets │ │ └── main.css │ ├── server │ │ └── tsconfig.json │ ├── app │ │ ├── components │ │ │ ├── Code.vue │ │ │ ├── CodeBlock.vue │ │ │ ├── StepNumber.vue │ │ │ ├── Step.vue │ │ │ └── ClassExample.vue │ │ ├── assets │ │ │ └── main.css │ │ └── app.vue │ ├── tsconfig.json │ ├── .gitignore │ ├── nuxt.config.ts │ └── package.json └── react │ ├── src │ ├── vite-env.d.ts │ ├── main.css │ ├── react.d.ts │ ├── main.tsx │ ├── App.tsx │ └── assets │ │ └── react.svg │ ├── tsconfig.json │ ├── .gitignore │ ├── index.html │ ├── vite.config.ts │ ├── tsconfig.node.json │ ├── eslint.config.js │ ├── tsconfig.app.json │ ├── package.json │ ├── public │ └── vite.svg │ └── README.md ├── pnpm-workspace.yaml ├── vitest.config.js ├── tsconfig.node.json ├── .npmignore ├── .gitignore ├── eslint.config.js ├── tsconfig.json ├── .github └── workflows │ ├── ci.yml │ └── nuxthub.yml ├── vite.config.ts ├── LICENSE ├── .cursor └── rules │ ├── file-processing.mdc │ ├── useclassy-plugin.mdc │ └── development-principles.mdc ├── src ├── types.d.ts ├── react.ts ├── tests │ ├── malformed-js.test.ts │ ├── blade.test.ts │ └── utils.test.ts ├── blade.ts ├── utils.ts ├── core.ts └── index.ts ├── package.json ├── README.md └── CHANGELOG.md /demos/laravel/public/favicon.ico: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /demos/vue/public/robots.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /demos/laravel/database/.gitignore: -------------------------------------------------------------------------------- 1 | *.sqlite* 2 | -------------------------------------------------------------------------------- /demos/laravel/resources/js/app.js: -------------------------------------------------------------------------------- 1 | import './bootstrap' 2 | -------------------------------------------------------------------------------- /demos/laravel/bootstrap/cache/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /demos/laravel/public/robots.txt: -------------------------------------------------------------------------------- 1 | User-agent: * 2 | Disallow: 3 | -------------------------------------------------------------------------------- /pnpm-workspace.yaml: -------------------------------------------------------------------------------- 1 | packages: 2 | - '.' 3 | - 'demos/*' 4 | -------------------------------------------------------------------------------- /demos/laravel/storage/app/private/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /demos/laravel/storage/app/public/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /demos/laravel/storage/framework/sessions/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /demos/laravel/storage/framework/testing/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /demos/laravel/storage/framework/views/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /demos/react/src/vite-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /demos/laravel/storage/framework/cache/data/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /demos/laravel/storage/framework/cache/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !data/ 3 | !.gitignore 4 | -------------------------------------------------------------------------------- /demos/vue/assets/main.css: -------------------------------------------------------------------------------- 1 | @import "tailwindcss/preflight"; 2 | @tailwind utilities; -------------------------------------------------------------------------------- /demos/laravel/storage/app/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !private/ 3 | !public/ 4 | !.gitignore 5 | -------------------------------------------------------------------------------- /demos/vue/server/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../.nuxt/tsconfig.server.json" 3 | } 4 | -------------------------------------------------------------------------------- /demos/vue/public/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrmybtlr/useclassy/HEAD/demos/vue/public/favicon.png -------------------------------------------------------------------------------- /demos/laravel/bootstrap/providers.php: -------------------------------------------------------------------------------- 1 | 2 |
5 | 6 |
7 | 8 | -------------------------------------------------------------------------------- /demos/laravel/tests/TestCase.php: -------------------------------------------------------------------------------- 1 | { 5 | [key: `class:${string}`]: string; 6 | [key: `className:${string}`]: string; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /vitest.config.js: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vitest/config' 2 | 3 | export default defineConfig({ 4 | test: { 5 | globals: true, 6 | environment: 'jsdom', 7 | include: ['**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], 8 | }, 9 | }) 10 | -------------------------------------------------------------------------------- /demos/laravel/.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | 3 | *.blade.php diff=html 4 | *.css diff=css 5 | *.html diff=html 6 | *.md diff=markdown 7 | *.php diff=php 8 | 9 | /.github export-ignore 10 | CHANGELOG.md export-ignore 11 | .styleci.yml export-ignore 12 | -------------------------------------------------------------------------------- /demos/laravel/routes/console.php: -------------------------------------------------------------------------------- 1 | comment(Inspiring::quote()); 8 | })->purpose('Display an inspiring quote'); 9 | -------------------------------------------------------------------------------- /tsconfig.node.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true, 4 | "skipLibCheck": true, 5 | "module": "ESNext", 6 | "moduleResolution": "bundler", 7 | "allowSyntheticDefaultImports": true 8 | }, 9 | "include": ["vite.config.ts"] 10 | } -------------------------------------------------------------------------------- /demos/vue/app/components/CodeBlock.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 12 | 13 | -------------------------------------------------------------------------------- /demos/react/src/main.tsx: -------------------------------------------------------------------------------- 1 | import { StrictMode } from "react"; 2 | import { createRoot } from "react-dom/client"; 3 | import "./main.css"; 4 | import App from "./App.tsx"; 5 | 6 | createRoot(document.getElementById("root")!).render( 7 | 8 | 9 | 10 | ); 11 | -------------------------------------------------------------------------------- /demos/vue/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | // https://nuxt.com/docs/guide/concepts/typescript 3 | "extends": "./.nuxt/tsconfig.json", 4 | "compilerOptions": { 5 | "allowImportingTsExtensions": true, 6 | "noEmit": true 7 | }, 8 | "include": ["app/**/*.ts", "app/**/*.tsx", "app/**/*.vue", "nuxt.config.ts"] 9 | } 10 | -------------------------------------------------------------------------------- /demos/vue/app/components/StepNumber.vue: -------------------------------------------------------------------------------- 1 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /demos/laravel/tests/Unit/ExampleTest.php: -------------------------------------------------------------------------------- 1 | assertTrue(true); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /demos/laravel/.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | indent_size = 4 7 | indent_style = space 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | 14 | [*.{yml,yaml}] 15 | indent_size = 2 16 | 17 | [docker-compose.yml] 18 | indent_size = 4 19 | -------------------------------------------------------------------------------- /demos/vue/.gitignore: -------------------------------------------------------------------------------- 1 | # Nuxt dev/build outputs 2 | .output 3 | .data 4 | .nuxt 5 | .nitro 6 | .cache 7 | dist 8 | 9 | # Node dependencies 10 | node_modules 11 | 12 | # Logs 13 | logs 14 | *.log 15 | 16 | # Misc 17 | .DS_Store 18 | .fleet 19 | .idea 20 | 21 | # Local env files 22 | .env 23 | .env.* 24 | !.env.example 25 | # Generated Classy files 26 | .classy/ 27 | 28 | .wrangler -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # Development files 2 | .git/ 3 | .github/ 4 | .vscode/ 5 | .cursor/ 6 | node_modules/ 7 | demos/ 8 | src/ 9 | tests/ 10 | .gitignore 11 | .npmrc 12 | *.log 13 | 14 | # Configuration files 15 | .eslintrc* 16 | .prettierrc* 17 | tsconfig*.json 18 | vite.config.ts 19 | vitest.config.js 20 | pnpm-workspace.yaml 21 | pnpm-lock.yaml 22 | 23 | # Demo and test files 24 | **/*.test.ts 25 | **/*.spec.ts -------------------------------------------------------------------------------- /demos/react/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | dist 12 | dist-ssr 13 | *.local 14 | 15 | # Editor directories and files 16 | .vscode/* 17 | !.vscode/extensions.json 18 | .idea 19 | .DS_Store 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | 26 | # Generated Classy files 27 | .classy/ 28 | -------------------------------------------------------------------------------- /demos/react/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Vite + React + TS 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /demos/laravel/.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | .DS_Store 3 | .env 4 | .env.backup 5 | .env.production 6 | .phpactor.json 7 | .phpunit.result.cache 8 | /.fleet 9 | /.idea 10 | /.nova 11 | /.phpunit.cache 12 | /.vscode 13 | /.zed 14 | /auth.json 15 | /node_modules 16 | /public/build 17 | /public/hot 18 | /public/storage 19 | /storage/*.key 20 | /storage/pail 21 | /vendor 22 | Homestead.json 23 | Homestead.yaml 24 | Thumbs.db 25 | 26 | # Generated Classy files 27 | .classy/ 28 | -------------------------------------------------------------------------------- /demos/vue/nuxt.config.ts: -------------------------------------------------------------------------------- 1 | import useClassy from '../../src/index.ts' 2 | import tailwindcss from '@tailwindcss/vite' 3 | 4 | export default defineNuxtConfig({ 5 | 6 | modules: ['@nuxt/fonts', '@nuxthub/core'], 7 | 8 | devtools: { 9 | enabled: true, 10 | }, 11 | 12 | future: { 13 | compatibilityVersion: 4, 14 | }, 15 | 16 | css: ['~/assets/main.css'], 17 | 18 | vite: { 19 | plugins: [useClassy({ debug: true }), tailwindcss()], 20 | }, 21 | }) 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Nuxt dev/build outputs 2 | .output 3 | .data 4 | .cache 5 | dist 6 | 7 | # Node dependencies 8 | node_modules 9 | 10 | # Logs 11 | logs 12 | *.log 13 | 14 | # Misc 15 | .DS_Store 16 | .fleet 17 | .idea 18 | 19 | # Local env files 20 | .env 21 | .env.* 22 | !.env.example 23 | node_modules/.pnpm/@babel+compat-data@7.26.8/node_modules/@babel/compat-data/plugin-bugfixes.js 24 | 25 | # VSCode 26 | .vscode 27 | 28 | # Generated Classy files 29 | .classy/ 30 | coverage/* -------------------------------------------------------------------------------- /demos/laravel/tests/Feature/ExampleTest.php: -------------------------------------------------------------------------------- 1 | get('/'); 16 | 17 | $response->assertStatus(200); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /demos/laravel/vite.config.js: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite' 2 | import laravel from 'laravel-vite-plugin' 3 | import useClassy from '../../src/index.ts' 4 | import tailwindcss from '@tailwindcss/vite' 5 | 6 | export default defineConfig({ 7 | plugins: [ 8 | useClassy({ 9 | language: 'blade', 10 | debug: true, 11 | }), 12 | laravel({ 13 | input: ['resources/css/app.css', 'resources/js/app.js'], 14 | }), 15 | tailwindcss(), 16 | ], 17 | }) 18 | -------------------------------------------------------------------------------- /demos/laravel/app/Providers/AppServiceProvider.php: -------------------------------------------------------------------------------- 1 | handleCommand(new ArgvInput); 17 | 18 | exit($status); 19 | -------------------------------------------------------------------------------- /demos/laravel/resources/css/app.css: -------------------------------------------------------------------------------- 1 | @import 'tailwindcss'; 2 | 3 | @source '../../vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php'; 4 | @source '../../storage/framework/views/*.php'; 5 | @source "../../.classy/output.classy.html"; 6 | @source '../**/*.blade.php'; 7 | @source '../**/*.js'; 8 | @source '../**/*.html'; 9 | 10 | @theme { 11 | --font-sans: 'Instrument Sans', ui-sans-serif, system-ui, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 12 | 'Segoe UI Symbol', 'Noto Color Emoji'; 13 | } -------------------------------------------------------------------------------- /demos/laravel/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/package.json", 3 | "private": true, 4 | "type": "module", 5 | "scripts": { 6 | "build": "vite build", 7 | "dev": "vite" 8 | }, 9 | "devDependencies": { 10 | "@tailwindcss/vite": "^4.1.12", 11 | "axios": "^1.8.2", 12 | "concurrently": "^9.0.1", 13 | "laravel-vite-plugin": "^2.0.0", 14 | "prettier-plugin-blade": "^2.1.21", 15 | "tailwindcss": "^4.0.0", 16 | "vite": "^7.0.0" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /demos/react/vite.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from "vite"; 2 | import react from "@vitejs/plugin-react"; 3 | import useClassy from "../../src/index.ts"; 4 | import tailwindcss from "@tailwindcss/vite"; 5 | import path from "path"; 6 | 7 | export default defineConfig({ 8 | plugins: [ 9 | react(), 10 | useClassy({ language: "react", debug: true }), 11 | tailwindcss(), 12 | ], 13 | server: { 14 | port: 3001, 15 | }, 16 | resolve: { 17 | alias: { 18 | "@": path.resolve(__dirname, "./src"), 19 | }, 20 | }, 21 | }); 22 | -------------------------------------------------------------------------------- /demos/laravel/database/seeders/DatabaseSeeder.php: -------------------------------------------------------------------------------- 1 | create(); 17 | 18 | User::factory()->create([ 19 | 'name' => 'Test User', 20 | 'email' => 'test@example.com', 21 | ]); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /demos/laravel/bootstrap/app.php: -------------------------------------------------------------------------------- 1 | withRouting( 9 | web: __DIR__.'/../routes/web.php', 10 | commands: __DIR__.'/../routes/console.php', 11 | health: '/up', 12 | ) 13 | ->withMiddleware(function (Middleware $middleware): void { 14 | // 15 | }) 16 | ->withExceptions(function (Exceptions $exceptions): void { 17 | // 18 | })->create(); 19 | -------------------------------------------------------------------------------- /demos/react/src/App.tsx: -------------------------------------------------------------------------------- 1 | import { twMerge } from "tailwind-merge"; 2 | 3 | function App() { 4 | return ( 5 |
6 |

11 | React Demo 12 |

13 | 14 |
18 | Tailwind Merge 19 |
20 |
21 | ); 22 | } 23 | 24 | export default App; 25 | -------------------------------------------------------------------------------- /demos/laravel/public/index.php: -------------------------------------------------------------------------------- 1 | handleRequest(Request::capture()); 21 | -------------------------------------------------------------------------------- /demos/vue/app/components/Step.vue: -------------------------------------------------------------------------------- 1 | 13 | 14 | 23 | -------------------------------------------------------------------------------- /eslint.config.js: -------------------------------------------------------------------------------- 1 | import globals from 'globals' 2 | // import pluginJs from "@eslint/js" 3 | import tseslint from 'typescript-eslint' 4 | import stylistic from '@stylistic/eslint-plugin' 5 | 6 | /** @type {import('eslint').Linter.Config[]} */ 7 | 8 | export default [ 9 | ...tseslint.configs.recommended, 10 | 11 | { 12 | files: ['**/*.{js,mjs,cjs,ts}'], 13 | languageOptions: { globals: globals.browser }, 14 | plugins: { 15 | '@stylistic': stylistic, 16 | }, 17 | rules: { 18 | ...stylistic.configs['recommended-flat'].rules, 19 | 'function-paren-newline': ['error', 'multiline-arguments'], 20 | }, 21 | }, 22 | ] 23 | -------------------------------------------------------------------------------- /demos/laravel/resources/views/components/useclassy-test.blade.php: -------------------------------------------------------------------------------- 1 |
3 |
4 | 10 |
11 |
-------------------------------------------------------------------------------- /demos/react/tsconfig.node.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo", 4 | "target": "ES2022", 5 | "lib": ["ES2023"], 6 | "module": "ESNext", 7 | "skipLibCheck": true, 8 | 9 | /* Bundler mode */ 10 | "moduleResolution": "bundler", 11 | "allowImportingTsExtensions": true, 12 | "isolatedModules": true, 13 | "moduleDetection": "force", 14 | "noEmit": true, 15 | 16 | /* Linting */ 17 | "strict": true, 18 | "noUnusedLocals": true, 19 | "noUnusedParameters": true, 20 | "noFallthroughCasesInSwitch": true, 21 | "noUncheckedSideEffectImports": true 22 | }, 23 | "include": ["vite.config.ts"] 24 | } 25 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2020", 4 | "useDefineForClassFields": true, 5 | "module": "ESNext", 6 | "lib": ["ES2020", "DOM", "DOM.Iterable"], 7 | "skipLibCheck": true, 8 | 9 | /* Bundler mode */ 10 | "moduleResolution": "bundler", 11 | "allowImportingTsExtensions": true, 12 | "resolveJsonModule": true, 13 | "isolatedModules": true, 14 | "noEmit": true, 15 | "jsx": "react-jsx", 16 | "types": ["react"], 17 | 18 | /* Linting */ 19 | "strict": true, 20 | "noUnusedLocals": true, 21 | "noUnusedParameters": true, 22 | "noFallthroughCasesInSwitch": true 23 | }, 24 | "include": ["src"], 25 | "references": [{ "path": "./tsconfig.node.json" }] 26 | } -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | 8 | pull_request: 9 | branches: 10 | - main 11 | 12 | jobs: 13 | test: 14 | runs-on: ${{ matrix.os }} 15 | 16 | strategy: 17 | matrix: 18 | os: [ubuntu-latest, macos-latest] 19 | node-version: ['18.x', '20.x'] 20 | fail-fast: false 21 | 22 | steps: 23 | - uses: actions/checkout@v4 24 | 25 | - name: Use Node.js ${{ matrix.node-version }} 26 | uses: actions/setup-node@v4 27 | with: 28 | node-version: ${{ matrix.node-version }} 29 | 30 | - name: Install dependencies 31 | run: npm install 32 | 33 | - name: Run tests 34 | run: npm test 35 | -------------------------------------------------------------------------------- /vite.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite' 2 | import { resolve } from 'path' 3 | import dts from 'vite-plugin-dts' 4 | 5 | export default defineConfig({ 6 | build: { 7 | lib: { 8 | entry: { 9 | index: resolve(__dirname, 'src/index.ts'), 10 | react: resolve(__dirname, 'src/react.ts'), 11 | }, 12 | formats: ['es', 'cjs'], 13 | fileName: (format, entryName) => 14 | `${entryName}.${format === 'es' ? 'js' : 'cjs'}`, 15 | }, 16 | rollupOptions: { 17 | external: ['vite', 'react', 'path', 'fs', 'crypto'], 18 | output: { 19 | preserveModules: true, 20 | exports: 'named', 21 | }, 22 | }, 23 | }, 24 | plugins: [ 25 | dts({ 26 | include: ['src/**/*.ts'], 27 | exclude: ['**/*.test.ts'], 28 | copyDtsFiles: true, 29 | }), 30 | ], 31 | }) 32 | -------------------------------------------------------------------------------- /demos/laravel/public/.htaccess: -------------------------------------------------------------------------------- 1 | 2 | 3 | Options -MultiViews -Indexes 4 | 5 | 6 | RewriteEngine On 7 | 8 | # Handle Authorization Header 9 | RewriteCond %{HTTP:Authorization} . 10 | RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] 11 | 12 | # Handle X-XSRF-Token Header 13 | RewriteCond %{HTTP:x-xsrf-token} . 14 | RewriteRule .* - [E=HTTP_X_XSRF_TOKEN:%{HTTP:X-XSRF-Token}] 15 | 16 | # Redirect Trailing Slashes If Not A Folder... 17 | RewriteCond %{REQUEST_FILENAME} !-d 18 | RewriteCond %{REQUEST_URI} (.+)/$ 19 | RewriteRule ^ %1 [L,R=301] 20 | 21 | # Send Requests To Front Controller... 22 | RewriteCond %{REQUEST_FILENAME} !-d 23 | RewriteCond %{REQUEST_FILENAME} !-f 24 | RewriteRule ^ index.php [L] 25 | 26 | -------------------------------------------------------------------------------- /demos/react/eslint.config.js: -------------------------------------------------------------------------------- 1 | import js from '@eslint/js' 2 | import globals from 'globals' 3 | import reactHooks from 'eslint-plugin-react-hooks' 4 | import reactRefresh from 'eslint-plugin-react-refresh' 5 | import tseslint from 'typescript-eslint' 6 | 7 | export default tseslint.config( 8 | { ignores: ['dist'] }, 9 | { 10 | extends: [js.configs.recommended, ...tseslint.configs.recommended], 11 | files: ['**/*.{ts,tsx}'], 12 | languageOptions: { 13 | ecmaVersion: 2020, 14 | globals: globals.browser, 15 | }, 16 | plugins: { 17 | 'react-hooks': reactHooks, 18 | 'react-refresh': reactRefresh, 19 | }, 20 | rules: { 21 | ...reactHooks.configs.recommended.rules, 22 | 'react-refresh/only-export-components': [ 23 | 'warn', 24 | { allowConstantExport: true }, 25 | ], 26 | }, 27 | }, 28 | ) 29 | -------------------------------------------------------------------------------- /.github/workflows/nuxthub.yml: -------------------------------------------------------------------------------- 1 | name: Deploy to NuxtHub 2 | on: push 3 | 4 | jobs: 5 | deploy: 6 | name: "Deploy to NuxtHub" 7 | runs-on: ubuntu-latest 8 | permissions: 9 | contents: read 10 | id-token: write 11 | 12 | steps: 13 | - uses: actions/checkout@v4 14 | 15 | - name: Install pnpm 16 | uses: pnpm/action-setup@v4 17 | with: 18 | version: 10 19 | 20 | - name: Install Node.js 21 | uses: actions/setup-node@v4 22 | with: 23 | node-version: 22 24 | cache: 'pnpm' 25 | 26 | - name: Install dependencies 27 | run: pnpm install 28 | 29 | - name: Ensure NuxtHub module is installed 30 | run: pnpx nuxthub@latest ensure 31 | 32 | - name: Build & Deploy to NuxtHub 33 | uses: nuxt-hub/action@v2 34 | with: 35 | project-key: useclassy-com-9ggt 36 | -------------------------------------------------------------------------------- /demos/react/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo", 4 | "target": "ES2020", 5 | "useDefineForClassFields": true, 6 | "lib": ["ES2020", "DOM", "DOM.Iterable"], 7 | "module": "ESNext", 8 | "skipLibCheck": true, 9 | 10 | /* Bundler mode */ 11 | "moduleResolution": "bundler", 12 | "allowImportingTsExtensions": true, 13 | "isolatedModules": true, 14 | "moduleDetection": "force", 15 | "noEmit": true, 16 | "jsx": "react-jsx", 17 | 18 | /* Linting */ 19 | "strict": true, 20 | "noUnusedLocals": true, 21 | "noUnusedParameters": true, 22 | "noFallthroughCasesInSwitch": true, 23 | "noUncheckedSideEffectImports": true, 24 | 25 | /* Path Aliases */ 26 | "baseUrl": ".", 27 | "paths": { 28 | "@/*": ["src/*"] 29 | } 30 | }, 31 | "include": ["src"] 32 | } 33 | -------------------------------------------------------------------------------- /demos/vue/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "useclassy-vue", 3 | "private": true, 4 | "type": "module", 5 | "scripts": { 6 | "build": "nuxt build", 7 | "dev": "nuxt dev", 8 | "generate": "nuxt generate", 9 | "preview": "nuxt preview", 10 | "postinstall": "nuxt prepare", 11 | "deploy": "pnpm build && npx nuxthub deploy" 12 | }, 13 | "dependencies": { 14 | "@nuxt/fonts": "^0.11.4", 15 | "@nuxt/ui": "^3.2.0", 16 | "vite-plugin-useclassy": "workspace:*", 17 | "vue": "latest", 18 | "vue-router": "latest" 19 | }, 20 | "devDependencies": { 21 | "@nuxthub/core": "0.9.0", 22 | "@tailwindcss/vite": "4.1.12", 23 | "nuxt": "^3.17.5", 24 | "tailwindcss": "4.1.4", 25 | "tailwindcss-motion": "^1.1.1", 26 | "wrangler": "^4.22.0" 27 | }, 28 | "packageManager": "pnpm@9.14.4+sha512.c8180b3fbe4e4bca02c94234717896b5529740a6cbadf19fa78254270403ea2f27d4e1d46a08a0f56c89b63dc8ebfd3ee53326da720273794e6200fcf0d184ab" 29 | } -------------------------------------------------------------------------------- /demos/react/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-demo", 3 | "private": true, 4 | "version": "0.0.0", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite", 8 | "build": "tsc && vite build", 9 | "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", 10 | "preview": "vite preview" 11 | }, 12 | "dependencies": { 13 | "react": "^18.2.0", 14 | "react-dom": "^18.2.0", 15 | "tailwind-merge": "^3.2.0", 16 | "tailwindcss": "4.1.4", 17 | "vite-plugin-useclassy": "workspace:*" 18 | }, 19 | "devDependencies": { 20 | "@tailwindcss/vite": "4.1.12", 21 | "@types/react": "^18.2.0", 22 | "@types/react-dom": "^18.2.0", 23 | "@typescript-eslint/eslint-plugin": "^8.31.1", 24 | "@typescript-eslint/parser": "^8.31.1", 25 | "@vitejs/plugin-react": "^4.4.1", 26 | "eslint": "^9.26.0", 27 | "eslint-plugin-react-hooks": "^5.2.0", 28 | "eslint-plugin-react-refresh": "^0.4.20", 29 | "typescript": "^5.8.3", 30 | "vite": "^7.0.0" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /demos/laravel/database/migrations/0001_01_01_000001_create_cache_table.php: -------------------------------------------------------------------------------- 1 | string('key')->primary(); 16 | $table->mediumText('value'); 17 | $table->integer('expiration'); 18 | }); 19 | 20 | Schema::create('cache_locks', function (Blueprint $table) { 21 | $table->string('key')->primary(); 22 | $table->string('owner'); 23 | $table->integer('expiration'); 24 | }); 25 | } 26 | 27 | /** 28 | * Reverse the migrations. 29 | */ 30 | public function down(): void 31 | { 32 | Schema::dropIfExists('cache'); 33 | Schema::dropIfExists('cache_locks'); 34 | } 35 | }; 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 Jeremy Butler 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /demos/laravel/config/services.php: -------------------------------------------------------------------------------- 1 | [ 18 | 'token' => env('POSTMARK_TOKEN'), 19 | ], 20 | 21 | 'resend' => [ 22 | 'key' => env('RESEND_KEY'), 23 | ], 24 | 25 | 'ses' => [ 26 | 'key' => env('AWS_ACCESS_KEY_ID'), 27 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 28 | 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), 29 | ], 30 | 31 | 'slack' => [ 32 | 'notifications' => [ 33 | 'bot_user_oauth_token' => env('SLACK_BOT_USER_OAUTH_TOKEN'), 34 | 'channel' => env('SLACK_BOT_USER_DEFAULT_CHANNEL'), 35 | ], 36 | ], 37 | 38 | ]; 39 | -------------------------------------------------------------------------------- /demos/vue/app/assets/main.css: -------------------------------------------------------------------------------- 1 | @import "tailwindcss"; 2 | @source "./../../.classy/output.classy.html"; 3 | @plugin "tailwindcss-motion"; 4 | 5 | body { 6 | @apply bg-zinc-950 text-white; 7 | } 8 | 9 | .font-serif { 10 | font-family: "Playfair Display", serif; 11 | } 12 | 13 | .font-sans { 14 | font-family: "Inter", sans-serif; 15 | } 16 | 17 | .font-mono { 18 | font-family: "Fira Code", monospace; 19 | } 20 | 21 | code { 22 | @apply block text-sm/[1.9em] font-mono px-4 py-3; 23 | } 24 | 25 | /* A better container */ 26 | .container { 27 | width: 100%; 28 | max-width: 720px; 29 | margin-left: auto; 30 | margin-right: auto; 31 | padding-left: calc(env(safe-area-inset-left, 0rem) + 1.1rem); 32 | padding-right: calc(env(safe-area-inset-right, 0rem) + 1.1rem); 33 | } 34 | 35 | @media screen and (min-width: 768px) { 36 | .container { 37 | padding-left: calc(env(safe-area-inset-left, 0rem) + 2rem); 38 | padding-right: calc(env(safe-area-inset-right, 0rem) + 2rem); 39 | } 40 | } 41 | 42 | @media screen and (min-width: 1280px) { 43 | .container { 44 | padding-left: calc(env(safe-area-inset-left, 0rem) + 3rem); 45 | padding-right: calc(env(safe-area-inset-right, 0rem) + 3rem); 46 | } 47 | } -------------------------------------------------------------------------------- /demos/laravel/app/Models/User.php: -------------------------------------------------------------------------------- 1 | */ 13 | use HasFactory, Notifiable; 14 | 15 | /** 16 | * The attributes that are mass assignable. 17 | * 18 | * @var list 19 | */ 20 | protected $fillable = [ 21 | 'name', 22 | 'email', 23 | 'password', 24 | ]; 25 | 26 | /** 27 | * The attributes that should be hidden for serialization. 28 | * 29 | * @var list 30 | */ 31 | protected $hidden = [ 32 | 'password', 33 | 'remember_token', 34 | ]; 35 | 36 | /** 37 | * Get the attributes that should be cast. 38 | * 39 | * @return array 40 | */ 41 | protected function casts(): array 42 | { 43 | return [ 44 | 'email_verified_at' => 'datetime', 45 | 'password' => 'hashed', 46 | ]; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /demos/laravel/resources/views/welcome.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Laravel 8 | @vite(['resources/css/app.css', 'resources/js/app.js']) 9 | 10 | 11 | 13 | 14 |
16 |
17 |

Let's get started with UseClassy

18 |

19 | Laravel has an incredibly rich ecosystem. 20 | UseClassy makes 21 | Tailwind even better! 22 |

23 |
24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /demos/laravel/database/factories/UserFactory.php: -------------------------------------------------------------------------------- 1 | 11 | */ 12 | class UserFactory extends Factory 13 | { 14 | /** 15 | * The current password being used by the factory. 16 | */ 17 | protected static ?string $password; 18 | 19 | /** 20 | * Define the model's default state. 21 | * 22 | * @return array 23 | */ 24 | public function definition(): array 25 | { 26 | return [ 27 | 'name' => fake()->name(), 28 | 'email' => fake()->unique()->safeEmail(), 29 | 'email_verified_at' => now(), 30 | 'password' => static::$password ??= Hash::make('password'), 31 | 'remember_token' => Str::random(10), 32 | ]; 33 | } 34 | 35 | /** 36 | * Indicate that the model's email address should be unverified. 37 | */ 38 | public function unverified(): static 39 | { 40 | return $this->state(fn (array $attributes) => [ 41 | 'email_verified_at' => null, 42 | ]); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /.cursor/rules/file-processing.mdc: -------------------------------------------------------------------------------- 1 | --- 2 | description: 3 | globs: 4 | alwaysApply: true 5 | --- 6 | # File Processing Logic 7 | 8 | The UseClassy plugin carefully manages which files it processes through the `shouldProcessFile` function in [src/useClassy.ts](mdc:src/useClassy.ts). 9 | 10 | ## File Filtering Rules 11 | 12 | 1. **Supported Extensions** 13 | - Only processes: `.vue`, `.ts`, `.tsx`, `.js`, `.jsx`, `.html`, `.blade.php` 14 | - Defined in `SUPPORTED_FILES` constant 15 | 16 | 2. **Ignored Paths** 17 | - Skips files in directories listed in `.gitignore` 18 | - Skips `node_modules` directory 19 | - Ignores virtual files (containing `virtual:`) 20 | - Ignores runtime files (containing `runtime`) 21 | - Skips files containing null bytes (`\0`) 22 | 23 | ## Processing Flow 24 | 25 | 1. First checks if file is in ignored directories 26 | 2. Then validates file extension against supported list 27 | 3. Finally applies special case exclusions (node_modules, virtual files, etc.) 28 | 29 | ## Example 30 | 31 | ```typescript 32 | // Will process: 33 | src/components/Button.vue 34 | src/pages/Home.tsx 35 | 36 | // Will skip: 37 | node_modules/react/index.js 38 | .vite/deps/virtual:react.js 39 | src/styles.css 40 | ``` 41 | 42 | The plugin maintains a cache of processed files to improve performance during development. 43 | -------------------------------------------------------------------------------- /demos/laravel/phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | tests/Unit 10 | 11 | 12 | tests/Feature 13 | 14 | 15 | 16 | 17 | app 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /demos/laravel/.env.example: -------------------------------------------------------------------------------- 1 | APP_NAME=Laravel 2 | APP_ENV=local 3 | APP_KEY= 4 | APP_DEBUG=true 5 | APP_URL=http://localhost 6 | 7 | APP_LOCALE=en 8 | APP_FALLBACK_LOCALE=en 9 | APP_FAKER_LOCALE=en_US 10 | 11 | APP_MAINTENANCE_DRIVER=file 12 | # APP_MAINTENANCE_STORE=database 13 | 14 | PHP_CLI_SERVER_WORKERS=4 15 | 16 | BCRYPT_ROUNDS=12 17 | 18 | LOG_CHANNEL=stack 19 | LOG_STACK=single 20 | LOG_DEPRECATIONS_CHANNEL=null 21 | LOG_LEVEL=debug 22 | 23 | DB_CONNECTION=sqlite 24 | # DB_HOST=127.0.0.1 25 | # DB_PORT=3306 26 | # DB_DATABASE=laravel 27 | # DB_USERNAME=root 28 | # DB_PASSWORD= 29 | 30 | SESSION_DRIVER=database 31 | SESSION_LIFETIME=120 32 | SESSION_ENCRYPT=false 33 | SESSION_PATH=/ 34 | SESSION_DOMAIN=null 35 | 36 | BROADCAST_CONNECTION=log 37 | FILESYSTEM_DISK=local 38 | QUEUE_CONNECTION=database 39 | 40 | CACHE_STORE=database 41 | # CACHE_PREFIX= 42 | 43 | MEMCACHED_HOST=127.0.0.1 44 | 45 | REDIS_CLIENT=phpredis 46 | REDIS_HOST=127.0.0.1 47 | REDIS_PASSWORD=null 48 | REDIS_PORT=6379 49 | 50 | MAIL_MAILER=log 51 | MAIL_SCHEME=null 52 | MAIL_HOST=127.0.0.1 53 | MAIL_PORT=2525 54 | MAIL_USERNAME=null 55 | MAIL_PASSWORD=null 56 | MAIL_FROM_ADDRESS="hello@example.com" 57 | MAIL_FROM_NAME="${APP_NAME}" 58 | 59 | AWS_ACCESS_KEY_ID= 60 | AWS_SECRET_ACCESS_KEY= 61 | AWS_DEFAULT_REGION=us-east-1 62 | AWS_BUCKET= 63 | AWS_USE_PATH_STYLE_ENDPOINT=false 64 | 65 | VITE_APP_NAME="${APP_NAME}" 66 | -------------------------------------------------------------------------------- /demos/react/public/vite.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /demos/laravel/database/migrations/0001_01_01_000000_create_users_table.php: -------------------------------------------------------------------------------- 1 | id(); 16 | $table->string('name'); 17 | $table->string('email')->unique(); 18 | $table->timestamp('email_verified_at')->nullable(); 19 | $table->string('password'); 20 | $table->rememberToken(); 21 | $table->timestamps(); 22 | }); 23 | 24 | Schema::create('password_reset_tokens', function (Blueprint $table) { 25 | $table->string('email')->primary(); 26 | $table->string('token'); 27 | $table->timestamp('created_at')->nullable(); 28 | }); 29 | 30 | Schema::create('sessions', function (Blueprint $table) { 31 | $table->string('id')->primary(); 32 | $table->foreignId('user_id')->nullable()->index(); 33 | $table->string('ip_address', 45)->nullable(); 34 | $table->text('user_agent')->nullable(); 35 | $table->longText('payload'); 36 | $table->integer('last_activity')->index(); 37 | }); 38 | } 39 | 40 | /** 41 | * Reverse the migrations. 42 | */ 43 | public function down(): void 44 | { 45 | Schema::dropIfExists('users'); 46 | Schema::dropIfExists('password_reset_tokens'); 47 | Schema::dropIfExists('sessions'); 48 | } 49 | }; 50 | -------------------------------------------------------------------------------- /.cursor/rules/useclassy-plugin.mdc: -------------------------------------------------------------------------------- 1 | --- 2 | description: 3 | globs: 4 | alwaysApply: true 5 | --- 6 | # UseClassy Vite Plugin Guide 7 | 8 | The UseClassy Vite plugin transforms class modifier attributes into Tailwind JIT-compatible class names. The main implementation is in [src/useClassy.ts](mdc:src/useClassy.ts). 9 | 10 | ## Core Functionality 11 | 12 | The plugin watches for attributes like: 13 | ```html 14 |
15 | ``` 16 | 17 | And transforms them into: 18 | ```html 19 |
20 | ``` 21 | 22 | This works with both Vue (`class`) and React (`className`) syntax. 23 | 24 | ## Key Components 25 | 26 | 1. **File Processing** 27 | - Processes `.vue`, `.ts`, `.tsx`, `.js`, `.jsx`, `.html`, and `.blade.php` files 28 | - Skips `node_modules`, virtual files, and runtime files 29 | - Respects `.gitignore` patterns 30 | 31 | 2. **Class Transformations** 32 | - Handles state modifiers (hover, focus, active, etc.) 33 | - Supports responsive modifiers (sm, md, lg, xl, 2xl) 34 | - Combines multiple class attributes 35 | - Works with nested modifiers (e.g., `sm:hover`, `lg:focus`) 36 | 37 | 3. **Framework Support** 38 | - Vue: Uses `class` attribute 39 | - React: Uses `className` attribute 40 | - Automatically detects framework based on file extension 41 | 42 | ## Usage Example 43 | 44 | ```html 45 | 46 |
52 | 53 | 54 |
55 | ``` 56 | 57 | The plugin integrates with Tailwind's JIT compiler, allowing for dynamic class generation based on your modifiers. 58 | -------------------------------------------------------------------------------- /src/types.d.ts: -------------------------------------------------------------------------------- 1 | import { HTMLAttributes, DetailedHTMLProps } from 'react' 2 | import type { ViteDevServer } from 'vite' 3 | 4 | type VariantClassNames = { 5 | [key: `class${string}`]: string 6 | [key: `className${string}`]: string 7 | } 8 | 9 | export type DivWithVariants = DetailedHTMLProps< 10 | HTMLAttributes, 11 | HTMLDivElement 12 | > & 13 | VariantClassNames 14 | 15 | // Plugin-specific types 16 | export interface ClassyOptions { 17 | /** 18 | * Framework language to use for class attribute 19 | * @default "vue" 20 | */ 21 | language?: 'vue' | 'react' | 'blade' 22 | 23 | /** 24 | * Directory to output the generated class file 25 | * @default ".classy" 26 | */ 27 | outputDir?: string 28 | 29 | /** 30 | * Filename for the generated class file 31 | * @default "output.classy.jsx" 32 | */ 33 | outputFileName?: string 34 | 35 | /** 36 | * Files to watch for changes 37 | * @default [".vue", ".tsx", ".jsx", ".html", ".blade.php"] 38 | */ 39 | files?: string[] 40 | 41 | /** 42 | * Auto-inject imports for classy functions 43 | * @default false 44 | */ 45 | autoImport?: boolean 46 | 47 | /** 48 | * Debug mode 49 | * @default false 50 | */ 51 | debug?: boolean 52 | } 53 | 54 | // Helper interface to represent Vite's dev server with the properties we need 55 | export interface ViteServer extends ViteDevServer { 56 | watcher: { 57 | on: (event: string, callback: (filePath: string) => void) => void 58 | add: (file: string) => void 59 | } 60 | middlewares: { 61 | use: (path: string, handler: (req: import('http').IncomingMessage, res: import('http').ServerResponse) => void) => void 62 | } 63 | httpServer: { 64 | once: (event: string, callback: () => void) => void 65 | } | null 66 | } 67 | 68 | // Type for React component props that can use class variants 69 | export type ClassyProps = TProps & { 70 | [key: `class:${string}`]: string 71 | [key: `className:${string}`]: string 72 | className?: string 73 | } 74 | -------------------------------------------------------------------------------- /demos/laravel/database/migrations/0001_01_01_000002_create_jobs_table.php: -------------------------------------------------------------------------------- 1 | id(); 16 | $table->string('queue')->index(); 17 | $table->longText('payload'); 18 | $table->unsignedTinyInteger('attempts'); 19 | $table->unsignedInteger('reserved_at')->nullable(); 20 | $table->unsignedInteger('available_at'); 21 | $table->unsignedInteger('created_at'); 22 | }); 23 | 24 | Schema::create('job_batches', function (Blueprint $table) { 25 | $table->string('id')->primary(); 26 | $table->string('name'); 27 | $table->integer('total_jobs'); 28 | $table->integer('pending_jobs'); 29 | $table->integer('failed_jobs'); 30 | $table->longText('failed_job_ids'); 31 | $table->mediumText('options')->nullable(); 32 | $table->integer('cancelled_at')->nullable(); 33 | $table->integer('created_at'); 34 | $table->integer('finished_at')->nullable(); 35 | }); 36 | 37 | Schema::create('failed_jobs', function (Blueprint $table) { 38 | $table->id(); 39 | $table->string('uuid')->unique(); 40 | $table->text('connection'); 41 | $table->text('queue'); 42 | $table->longText('payload'); 43 | $table->longText('exception'); 44 | $table->timestamp('failed_at')->useCurrent(); 45 | }); 46 | } 47 | 48 | /** 49 | * Reverse the migrations. 50 | */ 51 | public function down(): void 52 | { 53 | Schema::dropIfExists('jobs'); 54 | Schema::dropIfExists('job_batches'); 55 | Schema::dropIfExists('failed_jobs'); 56 | } 57 | }; 58 | -------------------------------------------------------------------------------- /demos/react/README.md: -------------------------------------------------------------------------------- 1 | # React + TypeScript + Vite 2 | 3 | This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. 4 | 5 | Currently, two official plugins are available: 6 | 7 | - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) for Fast Refresh 8 | - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh 9 | 10 | ## Expanding the ESLint configuration 11 | 12 | If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules: 13 | 14 | ```js 15 | export default tseslint.config({ 16 | extends: [ 17 | // Remove ...tseslint.configs.recommended and replace with this 18 | ...tseslint.configs.recommendedTypeChecked, 19 | // Alternatively, use this for stricter rules 20 | ...tseslint.configs.strictTypeChecked, 21 | // Optionally, add this for stylistic rules 22 | ...tseslint.configs.stylisticTypeChecked, 23 | ], 24 | languageOptions: { 25 | // other options... 26 | parserOptions: { 27 | project: ['./tsconfig.node.json', './tsconfig.app.json'], 28 | tsconfigRootDir: import.meta.dirname, 29 | }, 30 | }, 31 | }) 32 | ``` 33 | 34 | You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules: 35 | 36 | ```js 37 | // eslint.config.js 38 | import reactX from 'eslint-plugin-react-x' 39 | import reactDom from 'eslint-plugin-react-dom' 40 | 41 | export default tseslint.config({ 42 | plugins: { 43 | // Add the react-x and react-dom plugins 44 | 'react-x': reactX, 45 | 'react-dom': reactDom, 46 | }, 47 | rules: { 48 | // other rules... 49 | // Enable its recommended typescript rules 50 | ...reactX.configs['recommended-typescript'].rules, 51 | ...reactDom.configs.recommended.rules, 52 | }, 53 | }) 54 | ``` 55 | -------------------------------------------------------------------------------- /.cursor/rules/development-principles.mdc: -------------------------------------------------------------------------------- 1 | --- 2 | description: 3 | globs: 4 | alwaysApply: true 5 | --- 6 | # Development Principles 7 | 8 | The UseClassy plugin follows strict development principles to maintain high performance, type safety, and minimal complexity. The core implementation in [src/useClassy.ts](mdc:src/useClassy.ts) demonstrates these principles. 9 | 10 | ## Performance First 11 | 12 | 1. **Vite Integration** 13 | - Direct integration with Vite's plugin system 14 | - Uses Vite's built-in file watching and caching 15 | - Avoids redundant file processing 16 | - Maintains minimal memory footprint 17 | 18 | 2. **Efficient Processing** 19 | - Uses regex-based transformations for speed 20 | - Implements caching to avoid reprocessing unchanged files 21 | - Skips unnecessary file reads and transformations 22 | - Processes files only when needed during development 23 | 24 | ## TypeScript Best Practices 25 | 26 | 1. **Strong Typing** 27 | - All functions and interfaces are fully typed 28 | - No `any` types unless absolutely necessary 29 | - Extensive use of TypeScript interfaces for plugin options 30 | - Type guards for safe runtime checks 31 | 32 | 2. **Type Safety** 33 | - Strict null checks enabled 34 | - Explicit return types on public functions 35 | - Proper error handling with type checking 36 | - No type assertions unless unavoidable 37 | 38 | ## Minimal Surface Area 39 | 40 | 1. **Code Organization** 41 | - Single primary file for core logic 42 | - Functions are small and focused 43 | - Clear separation of concerns 44 | - Minimal internal state 45 | 46 | 2. **Zero Dependencies** 47 | - Only uses Node.js built-in modules (fs, path, crypto) 48 | - No external runtime dependencies 49 | - Vite as only peer dependency 50 | - Reduces security and maintenance burden 51 | 52 | ## Example of Principles 53 | 54 | ```typescript 55 | // Bad: Multiple dependencies, complex logic 56 | import _ from 'lodash'; 57 | import globby from 'globby'; 58 | function processFiles(pattern: any) { ... } 59 | 60 | // Good: Built-in modules, clear types, focused logic 61 | import { readFileSync } from 'fs'; 62 | import { join } from 'path'; 63 | function processFile(filePath: string): string { ... } 64 | ``` 65 | 66 | These principles ensure the plugin remains fast, reliable, and maintainable while keeping the codebase small and focused. 67 | -------------------------------------------------------------------------------- /src/react.ts: -------------------------------------------------------------------------------- 1 | import { useMemo, DependencyList } from 'react' 2 | 3 | /** 4 | * A custom React hook for combining class names 5 | * This is similar to the classnames package but optimized for react and memoization 6 | */ 7 | export function useClassy(...args: (string | Record | (string | Record)[])[]): string { 8 | const deps: DependencyList = useMemo( 9 | () => 10 | args.map(arg => (typeof arg === 'object' ? JSON.stringify(arg) : arg)), 11 | [JSON.stringify(args)], 12 | ) 13 | 14 | return useMemo(() => { 15 | // Process each argument 16 | return args 17 | .map((arg) => { 18 | // Handle strings directly 19 | if (typeof arg === 'string') return arg 20 | 21 | // Handle objects (conditionally apply classes) 22 | if (arg && typeof arg === 'object' && !Array.isArray(arg)) { 23 | return Object.entries(arg) 24 | .filter(([, value]) => Boolean(value)) 25 | .map(([key]) => key) 26 | .join(' ') 27 | } 28 | 29 | // Handle arrays by recursively flattening 30 | if (Array.isArray(arg)) { 31 | return arg 32 | .map(item => (typeof item === 'string' ? item : '')) 33 | .filter(Boolean) 34 | .join(' ') 35 | } 36 | 37 | return '' 38 | }) 39 | .filter(Boolean) 40 | .join(' ') 41 | }, deps) 42 | } 43 | 44 | /** 45 | * A simple function for combining class names without hooks 46 | * Can be used in cases where hooks aren't appropriate 47 | */ 48 | export function classy(...args: (string | Record | (string | Record)[])[]): string { 49 | return args 50 | .map((arg) => { 51 | // Handle strings directly 52 | if (typeof arg === 'string') return arg 53 | 54 | // Handle objects (conditionally apply classes) 55 | if (arg && typeof arg === 'object' && !Array.isArray(arg)) { 56 | return Object.entries(arg) 57 | .filter(([, value]) => Boolean(value)) 58 | .map(([key]) => key) 59 | .join(' ') 60 | } 61 | 62 | // Handle arrays by flattening 63 | if (Array.isArray(arg)) { 64 | return arg 65 | .map(item => (typeof item === 'string' ? item : '')) 66 | .filter(Boolean) 67 | .join(' ') 68 | } 69 | 70 | return '' 71 | }) 72 | .filter(Boolean) 73 | .join(' ') 74 | } 75 | -------------------------------------------------------------------------------- /demos/laravel/config/filesystems.php: -------------------------------------------------------------------------------- 1 | env('FILESYSTEM_DISK', 'local'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Filesystem Disks 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Below you may configure as many filesystem disks as necessary, and you 24 | | may even configure multiple disks for the same driver. Examples for 25 | | most supported storage drivers are configured here for reference. 26 | | 27 | | Supported drivers: "local", "ftp", "sftp", "s3" 28 | | 29 | */ 30 | 31 | 'disks' => [ 32 | 33 | 'local' => [ 34 | 'driver' => 'local', 35 | 'root' => storage_path('app/private'), 36 | 'serve' => true, 37 | 'throw' => false, 38 | 'report' => false, 39 | ], 40 | 41 | 'public' => [ 42 | 'driver' => 'local', 43 | 'root' => storage_path('app/public'), 44 | 'url' => env('APP_URL').'/storage', 45 | 'visibility' => 'public', 46 | 'throw' => false, 47 | 'report' => false, 48 | ], 49 | 50 | 's3' => [ 51 | 'driver' => 's3', 52 | 'key' => env('AWS_ACCESS_KEY_ID'), 53 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 54 | 'region' => env('AWS_DEFAULT_REGION'), 55 | 'bucket' => env('AWS_BUCKET'), 56 | 'url' => env('AWS_URL'), 57 | 'endpoint' => env('AWS_ENDPOINT'), 58 | 'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false), 59 | 'throw' => false, 60 | 'report' => false, 61 | ], 62 | 63 | ], 64 | 65 | /* 66 | |-------------------------------------------------------------------------- 67 | | Symbolic Links 68 | |-------------------------------------------------------------------------- 69 | | 70 | | Here you may configure the symbolic links that will be created when the 71 | | `storage:link` Artisan command is executed. The array keys should be 72 | | the locations of the links and the values should be their targets. 73 | | 74 | */ 75 | 76 | 'links' => [ 77 | public_path('storage') => storage_path('app/public'), 78 | ], 79 | 80 | ]; 81 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vite-plugin-useclassy", 3 | "version": "2.6.0", 4 | "description": "UseClassy automatically appends class attributes to your components and lets you separate media queries, hover states, and other styles.", 5 | "scripts": { 6 | "dev": "pnpm -r dev", 7 | "test": "vitest run src/*", 8 | "test:watch": "vitest src/*", 9 | "release:major": "changelogen --release --major && pnpm publish", 10 | "release:minor": "changelogen --release --minor && pnpm publish", 11 | "release:patch": "changelogen --release --patch && pnpm publish", 12 | "build": "vite build", 13 | "build:website": "pnpm i --no-frozen-lockfile && cd demos/vue && pnpm run build", 14 | "prepublishOnly": "pnpm run build" 15 | }, 16 | "keywords": [ 17 | "vite-plugin", 18 | "useclassy", 19 | "classy", 20 | "tailwind", 21 | "css", 22 | "vue", 23 | "nuxt", 24 | "react", 25 | "next" 26 | ], 27 | "license": "MIT", 28 | "homepage": "https://github.com/jrmybtlr/useclassy#readme", 29 | "bugs": "https://github.com/jrmybtlr/useclassy/issues", 30 | "author": "Jeremy Butler ", 31 | "contributors": [ 32 | { 33 | "name": "Jeremy Butler", 34 | "email": "jeremy@jeremymbutler.com", 35 | "url": "https://github.com/jrmybtlr" 36 | } 37 | ], 38 | "files": [ 39 | "dist" 40 | ], 41 | "main": "dist/index.js", 42 | "type": "module", 43 | "types": "dist/index.d.ts", 44 | "exports": { 45 | ".": { 46 | "types": "./dist/index.d.ts", 47 | "import": "./dist/index.js", 48 | "require": "./dist/index.cjs" 49 | }, 50 | "./react": { 51 | "types": "./dist/react.d.ts", 52 | "import": "./dist/react.js", 53 | "require": "./dist/react.cjs" 54 | } 55 | }, 56 | "repository": { 57 | "type": "git", 58 | "url": "git+https://github.com/jrmybtlr/useclassy.git" 59 | }, 60 | "devDependencies": { 61 | "@eslint/js": "^9.30.0", 62 | "@stylistic/eslint-plugin": "^4.4.1", 63 | "@types/react": "^18.3.23", 64 | "@typescript-eslint/eslint-plugin": "^8.35.0", 65 | "@typescript-eslint/parser": "^8.35.0", 66 | "@vitest/coverage-v8": "^3.2.4", 67 | "@vitest/ui": "^3.2.4", 68 | "changelogen": "^0.5.7", 69 | "eslint": "^9.30.0", 70 | "globals": "^16.2.0", 71 | "jsdom": "^26.1.0", 72 | "typescript": "^5.8.3", 73 | "typescript-eslint": "^8.35.0", 74 | "vite": "^7.0.0", 75 | "vite-plugin-dts": "^3.9.1", 76 | "vite-plugin-inspect": "^11.3.0", 77 | "vitest": "^3.2.4" 78 | }, 79 | "peerDependencies": { 80 | "react": "^16.8.0 || ^17.0.0 || ^18.0.0", 81 | "vite": "^5.0.0 || ^6.0.0 || ^7.0.0" 82 | }, 83 | "resolutions": { 84 | "debug": "4.3.4", 85 | "supports-color": "8.1.1" 86 | }, 87 | "dependencies": { 88 | "arktype": "^2.1.20" 89 | } 90 | } -------------------------------------------------------------------------------- /demos/laravel/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://getcomposer.org/schema.json", 3 | "name": "laravel/laravel", 4 | "type": "project", 5 | "description": "The skeleton application for the Laravel framework.", 6 | "keywords": [ 7 | "laravel", 8 | "framework" 9 | ], 10 | "license": "MIT", 11 | "require": { 12 | "php": "^8.2", 13 | "laravel/framework": "^12.0", 14 | "laravel/tinker": "^2.10.1", 15 | "useclassy/laravel": "*" 16 | }, 17 | "require-dev": { 18 | "fakerphp/faker": "^1.23", 19 | "laravel/pail": "^1.2.2", 20 | "laravel/pint": "^1.24", 21 | "laravel/sail": "^1.41", 22 | "mockery/mockery": "^1.6", 23 | "nunomaduro/collision": "^8.6", 24 | "phpunit/phpunit": "^11.5.3" 25 | }, 26 | "autoload": { 27 | "psr-4": { 28 | "App\\": "app/", 29 | "Database\\Factories\\": "database/factories/", 30 | "Database\\Seeders\\": "database/seeders/" 31 | } 32 | }, 33 | "autoload-dev": { 34 | "psr-4": { 35 | "Tests\\": "tests/" 36 | } 37 | }, 38 | "scripts": { 39 | "post-autoload-dump": [ 40 | "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump", 41 | "@php artisan package:discover --ansi" 42 | ], 43 | "post-update-cmd": [ 44 | "@php artisan vendor:publish --tag=laravel-assets --ansi --force" 45 | ], 46 | "post-root-package-install": [ 47 | "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"" 48 | ], 49 | "post-create-project-cmd": [ 50 | "@php artisan key:generate --ansi", 51 | "@php -r \"file_exists('database/database.sqlite') || touch('database/database.sqlite');\"", 52 | "@php artisan migrate --graceful --ansi" 53 | ], 54 | "dev": [ 55 | "Composer\\Config::disableProcessTimeout", 56 | "npx concurrently -c \"#93c5fd,#c4b5fd,#fb7185,#fdba74\" \"php artisan serve\" \"php artisan queue:listen --tries=1\" \"php artisan pail --timeout=0\" \"npm run dev\" --names=server,queue,logs,vite" 57 | ], 58 | "test": [ 59 | "@php artisan config:clear --ansi", 60 | "@php artisan test" 61 | ] 62 | }, 63 | "extra": { 64 | "laravel": { 65 | "dont-discover": [] 66 | } 67 | }, 68 | "config": { 69 | "optimize-autoloader": true, 70 | "preferred-install": "dist", 71 | "sort-packages": true, 72 | "allow-plugins": { 73 | "pestphp/pest-plugin": true, 74 | "php-http/discovery": true 75 | } 76 | }, 77 | "repositories": [ 78 | { 79 | "type": "path", 80 | "url": "../../../useclassy-laravel" 81 | } 82 | ], 83 | "minimum-stability": "dev", 84 | "prefer-stable": true 85 | } 86 | -------------------------------------------------------------------------------- /demos/vue/app/components/ClassExample.vue: -------------------------------------------------------------------------------- 1 | 67 | 68 | 91 | -------------------------------------------------------------------------------- /src/tests/malformed-js.test.ts: -------------------------------------------------------------------------------- 1 | import { describe, it, expect } from 'vitest' 2 | import { mergeClassAttributes } from '../core' 3 | 4 | describe('Malformed JavaScript Generation', () => { 5 | it('should not generate malformed JavaScript when merging function calls with static classes', () => { 6 | // This is the problematic case that generates malformed JavaScript 7 | const input = '
Content
' 8 | 9 | const result = mergeClassAttributes(input, 'className') 10 | 11 | console.log('Input:', input) 12 | console.log('Output:', result) 13 | 14 | // The current implementation generates: 15 | // className={getClassNames(), `flex`)} 16 | // This is invalid JavaScript syntax! 17 | 18 | // It should generate valid JavaScript instead 19 | expect(result).not.toContain('getClassNames(), `flex`)') 20 | expect(result).toContain('className=') 21 | expect(result).toContain('flex') 22 | expect(result).toContain('getClassNames') 23 | 24 | // The result should be valid JavaScript syntax 25 | // Valid options would be: 26 | // 1. className={`flex ${getClassNames()}`} 27 | // 2. className={getClassNames('flex')} (if function supports parameters) 28 | // 3. className={getClassNames()} with flex handled separately 29 | }) 30 | 31 | it('should handle function calls with parameters correctly', () => { 32 | const input = '
Content
' 33 | 34 | const result = mergeClassAttributes(input, 'className') 35 | 36 | console.log('Input:', input) 37 | console.log('Output:', result) 38 | 39 | // Should not generate malformed syntax like: getClassNames(theme), `flex`) 40 | expect(result).not.toContain('getClassNames(theme), `flex`)') 41 | expect(result).toContain('className=') 42 | expect(result).toContain('flex') 43 | expect(result).toContain('getClassNames(theme') 44 | }) 45 | 46 | it('should handle complex function calls without breaking syntax', () => { 47 | const input = '
Content
' 48 | 49 | const result = mergeClassAttributes(input, 'className') 50 | 51 | console.log('Input:', input) 52 | console.log('Output:', result) 53 | 54 | // Should not generate malformed syntax 55 | expect(result).not.toMatch(/getClassNames\([^)]+\), `[^`]+`\)/) 56 | expect(result).toContain('className=') 57 | expect(result).toContain('flex') 58 | expect(result).toContain('getClassNames(theme, isActive ? "active" : "inactive"') 59 | }) 60 | 61 | it('should handle template literals correctly', () => { 62 | const input = '
Content
' 63 | 64 | const result = mergeClassAttributes(input, 'className') 65 | 66 | console.log('Input:', input) 67 | console.log('Output:', result) 68 | 69 | // Should merge template literals properly 70 | expect(result).toContain('className=') 71 | expect(result).toContain('flex') 72 | expect(result).toContain('baseClass') 73 | expect(result).toContain('active ?') 74 | }) 75 | }) 76 | -------------------------------------------------------------------------------- /demos/laravel/README.md: -------------------------------------------------------------------------------- 1 | # Laravel UseClassy Demo 2 | 3 | This demo showcases UseClassy integration with Laravel and Blade templates. UseClassy automatically transforms `class:modifier="value"` syntax into standard Tailwind classes. 4 | 5 | ## What UseClassy Does 6 | 7 | UseClassy transforms this Blade syntax: 8 | ```blade 9 |

Hello World

13 | ``` 14 | 15 | Into this rendered HTML: 16 | ```html 17 |

Hello World

18 | ``` 19 | 20 | ## Setup 21 | 22 | 1. **Install dependencies:** 23 | ```bash 24 | npm install 25 | composer install 26 | ``` 27 | 28 | 2. **Install UseClassy Laravel package:** 29 | ```bash 30 | composer require useclassy/laravel 31 | ``` 32 | 33 | 3. **Environment setup:** 34 | ```bash 35 | cp .env.example .env 36 | php artisan key:generate 37 | ``` 38 | 39 | 4. **Run development servers:** 40 | ```bash 41 | # Terminal 1: Laravel server 42 | php artisan serve 43 | 44 | # Terminal 2: Vite dev server 45 | npm run dev 46 | ``` 47 | 48 | 5. **Visit the demo:** 49 | - Laravel app: http://localhost:8000 50 | - Vite dev server: http://localhost:5173 51 | 52 | ## How It Works 53 | 54 | 1. **Laravel Integration**: The `useclassy/laravel` Composer package automatically: 55 | - Registers via Laravel's package auto-discovery 56 | - Hooks into Blade compiler to transform UseClassy syntax 57 | - No manual PHP setup required! 58 | 59 | 2. **Blade Transformation**: The service provider transforms `class:modifier="value"` syntax during template compilation. 60 | 61 | 3. **Vite Integration**: The Vite plugin: 62 | - Scans `.blade.php` files for UseClassy classes 63 | - Generates a `.classy/output.classy.html` file for Tailwind JIT 64 | - Watches for changes and triggers hot reloads 65 | 66 | ## Configuration 67 | 68 | The Vite configuration in `vite.config.js`: 69 | 70 | ```javascript 71 | import useClassy from 'vite-plugin-useclassy' 72 | 73 | export default defineConfig({ 74 | plugins: [ 75 | useClassy({ 76 | language: 'blade', // Enables Laravel integration 77 | debug: true, // Shows setup logs 78 | }), 79 | // ... other plugins 80 | ], 81 | }) 82 | ``` 83 | 84 | ## Demo Features 85 | 86 | The demo showcases: 87 | - ✅ Responsive modifiers: `class:lg="text-2xl"` 88 | - ✅ Hover states: `class:hover="underline"` 89 | - ✅ Dark mode: `class:dark="bg-gray-800"` 90 | - ✅ Multiple modifiers on one element 91 | - ✅ Hot reloading when editing Blade files 92 | - ✅ Automatic Tailwind JIT compilation 93 | 94 | ## File Structure 95 | 96 | ``` 97 | demos/laravel/ 98 | ├── resources/views/ 99 | │ └── welcome.blade.php # Demo template 100 | ├── vite.config.js # UseClassy config 101 | └── .classy/ 102 | └── output.classy.html # Generated classes 103 | ``` 104 | 105 | The Laravel service provider is provided by the `useclassy/laravel` Composer package. 106 | 107 | ## Laravel Documentation 108 | 109 | For more information about Laravel itself, see the [Laravel documentation](https://laravel.com/docs). -------------------------------------------------------------------------------- /demos/react/src/assets/react.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /demos/laravel/config/cache.php: -------------------------------------------------------------------------------- 1 | env('CACHE_STORE', 'database'), 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Cache Stores 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may define all of the cache "stores" for your application as 26 | | well as their drivers. You may even define multiple stores for the 27 | | same cache driver to group types of items stored in your caches. 28 | | 29 | | Supported drivers: "array", "database", "file", "memcached", 30 | | "redis", "dynamodb", "octane", "null" 31 | | 32 | */ 33 | 34 | 'stores' => [ 35 | 36 | 'array' => [ 37 | 'driver' => 'array', 38 | 'serialize' => false, 39 | ], 40 | 41 | 'database' => [ 42 | 'driver' => 'database', 43 | 'connection' => env('DB_CACHE_CONNECTION'), 44 | 'table' => env('DB_CACHE_TABLE', 'cache'), 45 | 'lock_connection' => env('DB_CACHE_LOCK_CONNECTION'), 46 | 'lock_table' => env('DB_CACHE_LOCK_TABLE'), 47 | ], 48 | 49 | 'file' => [ 50 | 'driver' => 'file', 51 | 'path' => storage_path('framework/cache/data'), 52 | 'lock_path' => storage_path('framework/cache/data'), 53 | ], 54 | 55 | 'memcached' => [ 56 | 'driver' => 'memcached', 57 | 'persistent_id' => env('MEMCACHED_PERSISTENT_ID'), 58 | 'sasl' => [ 59 | env('MEMCACHED_USERNAME'), 60 | env('MEMCACHED_PASSWORD'), 61 | ], 62 | 'options' => [ 63 | // Memcached::OPT_CONNECT_TIMEOUT => 2000, 64 | ], 65 | 'servers' => [ 66 | [ 67 | 'host' => env('MEMCACHED_HOST', '127.0.0.1'), 68 | 'port' => env('MEMCACHED_PORT', 11211), 69 | 'weight' => 100, 70 | ], 71 | ], 72 | ], 73 | 74 | 'redis' => [ 75 | 'driver' => 'redis', 76 | 'connection' => env('REDIS_CACHE_CONNECTION', 'cache'), 77 | 'lock_connection' => env('REDIS_CACHE_LOCK_CONNECTION', 'default'), 78 | ], 79 | 80 | 'dynamodb' => [ 81 | 'driver' => 'dynamodb', 82 | 'key' => env('AWS_ACCESS_KEY_ID'), 83 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 84 | 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), 85 | 'table' => env('DYNAMODB_CACHE_TABLE', 'cache'), 86 | 'endpoint' => env('DYNAMODB_ENDPOINT'), 87 | ], 88 | 89 | 'octane' => [ 90 | 'driver' => 'octane', 91 | ], 92 | 93 | ], 94 | 95 | /* 96 | |-------------------------------------------------------------------------- 97 | | Cache Key Prefix 98 | |-------------------------------------------------------------------------- 99 | | 100 | | When utilizing the APC, database, memcached, Redis, and DynamoDB cache 101 | | stores, there might be other applications using the same cache. For 102 | | that reason, you may prefix every cache key to avoid collisions. 103 | | 104 | */ 105 | 106 | 'prefix' => env('CACHE_PREFIX', Str::slug((string) env('APP_NAME', 'laravel')).'-cache-'), 107 | 108 | ]; 109 | -------------------------------------------------------------------------------- /demos/laravel/config/mail.php: -------------------------------------------------------------------------------- 1 | env('MAIL_MAILER', 'log'), 18 | 19 | /* 20 | |-------------------------------------------------------------------------- 21 | | Mailer Configurations 22 | |-------------------------------------------------------------------------- 23 | | 24 | | Here you may configure all of the mailers used by your application plus 25 | | their respective settings. Several examples have been configured for 26 | | you and you are free to add your own as your application requires. 27 | | 28 | | Laravel supports a variety of mail "transport" drivers that can be used 29 | | when delivering an email. You may specify which one you're using for 30 | | your mailers below. You may also add additional mailers if needed. 31 | | 32 | | Supported: "smtp", "sendmail", "mailgun", "ses", "ses-v2", 33 | | "postmark", "resend", "log", "array", 34 | | "failover", "roundrobin" 35 | | 36 | */ 37 | 38 | 'mailers' => [ 39 | 40 | 'smtp' => [ 41 | 'transport' => 'smtp', 42 | 'scheme' => env('MAIL_SCHEME'), 43 | 'url' => env('MAIL_URL'), 44 | 'host' => env('MAIL_HOST', '127.0.0.1'), 45 | 'port' => env('MAIL_PORT', 2525), 46 | 'username' => env('MAIL_USERNAME'), 47 | 'password' => env('MAIL_PASSWORD'), 48 | 'timeout' => null, 49 | 'local_domain' => env('MAIL_EHLO_DOMAIN', parse_url((string) env('APP_URL', 'http://localhost'), PHP_URL_HOST)), 50 | ], 51 | 52 | 'ses' => [ 53 | 'transport' => 'ses', 54 | ], 55 | 56 | 'postmark' => [ 57 | 'transport' => 'postmark', 58 | // 'message_stream_id' => env('POSTMARK_MESSAGE_STREAM_ID'), 59 | // 'client' => [ 60 | // 'timeout' => 5, 61 | // ], 62 | ], 63 | 64 | 'resend' => [ 65 | 'transport' => 'resend', 66 | ], 67 | 68 | 'sendmail' => [ 69 | 'transport' => 'sendmail', 70 | 'path' => env('MAIL_SENDMAIL_PATH', '/usr/sbin/sendmail -bs -i'), 71 | ], 72 | 73 | 'log' => [ 74 | 'transport' => 'log', 75 | 'channel' => env('MAIL_LOG_CHANNEL'), 76 | ], 77 | 78 | 'array' => [ 79 | 'transport' => 'array', 80 | ], 81 | 82 | 'failover' => [ 83 | 'transport' => 'failover', 84 | 'mailers' => [ 85 | 'smtp', 86 | 'log', 87 | ], 88 | 'retry_after' => 60, 89 | ], 90 | 91 | 'roundrobin' => [ 92 | 'transport' => 'roundrobin', 93 | 'mailers' => [ 94 | 'ses', 95 | 'postmark', 96 | ], 97 | 'retry_after' => 60, 98 | ], 99 | 100 | ], 101 | 102 | /* 103 | |-------------------------------------------------------------------------- 104 | | Global "From" Address 105 | |-------------------------------------------------------------------------- 106 | | 107 | | You may wish for all emails sent by your application to be sent from 108 | | the same address. Here you may specify a name and address that is 109 | | used globally for all emails that are sent by your application. 110 | | 111 | */ 112 | 113 | 'from' => [ 114 | 'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'), 115 | 'name' => env('MAIL_FROM_NAME', 'Example'), 116 | ], 117 | 118 | ]; 119 | -------------------------------------------------------------------------------- /demos/laravel/config/queue.php: -------------------------------------------------------------------------------- 1 | env('QUEUE_CONNECTION', 'database'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Queue Connections 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Here you may configure the connection options for every queue backend 24 | | used by your application. An example configuration is provided for 25 | | each backend supported by Laravel. You're also free to add more. 26 | | 27 | | Drivers: "sync", "database", "beanstalkd", "sqs", "redis", "null" 28 | | 29 | */ 30 | 31 | 'connections' => [ 32 | 33 | 'sync' => [ 34 | 'driver' => 'sync', 35 | ], 36 | 37 | 'database' => [ 38 | 'driver' => 'database', 39 | 'connection' => env('DB_QUEUE_CONNECTION'), 40 | 'table' => env('DB_QUEUE_TABLE', 'jobs'), 41 | 'queue' => env('DB_QUEUE', 'default'), 42 | 'retry_after' => (int) env('DB_QUEUE_RETRY_AFTER', 90), 43 | 'after_commit' => false, 44 | ], 45 | 46 | 'beanstalkd' => [ 47 | 'driver' => 'beanstalkd', 48 | 'host' => env('BEANSTALKD_QUEUE_HOST', 'localhost'), 49 | 'queue' => env('BEANSTALKD_QUEUE', 'default'), 50 | 'retry_after' => (int) env('BEANSTALKD_QUEUE_RETRY_AFTER', 90), 51 | 'block_for' => 0, 52 | 'after_commit' => false, 53 | ], 54 | 55 | 'sqs' => [ 56 | 'driver' => 'sqs', 57 | 'key' => env('AWS_ACCESS_KEY_ID'), 58 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 59 | 'prefix' => env('SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'), 60 | 'queue' => env('SQS_QUEUE', 'default'), 61 | 'suffix' => env('SQS_SUFFIX'), 62 | 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), 63 | 'after_commit' => false, 64 | ], 65 | 66 | 'redis' => [ 67 | 'driver' => 'redis', 68 | 'connection' => env('REDIS_QUEUE_CONNECTION', 'default'), 69 | 'queue' => env('REDIS_QUEUE', 'default'), 70 | 'retry_after' => (int) env('REDIS_QUEUE_RETRY_AFTER', 90), 71 | 'block_for' => null, 72 | 'after_commit' => false, 73 | ], 74 | 75 | ], 76 | 77 | /* 78 | |-------------------------------------------------------------------------- 79 | | Job Batching 80 | |-------------------------------------------------------------------------- 81 | | 82 | | The following options configure the database and table that store job 83 | | batching information. These options can be updated to any database 84 | | connection and table which has been defined by your application. 85 | | 86 | */ 87 | 88 | 'batching' => [ 89 | 'database' => env('DB_CONNECTION', 'sqlite'), 90 | 'table' => 'job_batches', 91 | ], 92 | 93 | /* 94 | |-------------------------------------------------------------------------- 95 | | Failed Queue Jobs 96 | |-------------------------------------------------------------------------- 97 | | 98 | | These options configure the behavior of failed queue job logging so you 99 | | can control how and where failed jobs are stored. Laravel ships with 100 | | support for storing failed jobs in a simple file or in a database. 101 | | 102 | | Supported drivers: "database-uuids", "dynamodb", "file", "null" 103 | | 104 | */ 105 | 106 | 'failed' => [ 107 | 'driver' => env('QUEUE_FAILED_DRIVER', 'database-uuids'), 108 | 'database' => env('DB_CONNECTION', 'sqlite'), 109 | 'table' => 'failed_jobs', 110 | ], 111 | 112 | ]; 113 | -------------------------------------------------------------------------------- /demos/laravel/config/auth.php: -------------------------------------------------------------------------------- 1 | [ 17 | 'guard' => env('AUTH_GUARD', 'web'), 18 | 'passwords' => env('AUTH_PASSWORD_BROKER', 'users'), 19 | ], 20 | 21 | /* 22 | |-------------------------------------------------------------------------- 23 | | Authentication Guards 24 | |-------------------------------------------------------------------------- 25 | | 26 | | Next, you may define every authentication guard for your application. 27 | | Of course, a great default configuration has been defined for you 28 | | which utilizes session storage plus the Eloquent user provider. 29 | | 30 | | All authentication guards have a user provider, which defines how the 31 | | users are actually retrieved out of your database or other storage 32 | | system used by the application. Typically, Eloquent is utilized. 33 | | 34 | | Supported: "session" 35 | | 36 | */ 37 | 38 | 'guards' => [ 39 | 'web' => [ 40 | 'driver' => 'session', 41 | 'provider' => 'users', 42 | ], 43 | ], 44 | 45 | /* 46 | |-------------------------------------------------------------------------- 47 | | User Providers 48 | |-------------------------------------------------------------------------- 49 | | 50 | | All authentication guards have a user provider, which defines how the 51 | | users are actually retrieved out of your database or other storage 52 | | system used by the application. Typically, Eloquent is utilized. 53 | | 54 | | If you have multiple user tables or models you may configure multiple 55 | | providers to represent the model / table. These providers may then 56 | | be assigned to any extra authentication guards you have defined. 57 | | 58 | | Supported: "database", "eloquent" 59 | | 60 | */ 61 | 62 | 'providers' => [ 63 | 'users' => [ 64 | 'driver' => 'eloquent', 65 | 'model' => env('AUTH_MODEL', App\Models\User::class), 66 | ], 67 | 68 | // 'users' => [ 69 | // 'driver' => 'database', 70 | // 'table' => 'users', 71 | // ], 72 | ], 73 | 74 | /* 75 | |-------------------------------------------------------------------------- 76 | | Resetting Passwords 77 | |-------------------------------------------------------------------------- 78 | | 79 | | These configuration options specify the behavior of Laravel's password 80 | | reset functionality, including the table utilized for token storage 81 | | and the user provider that is invoked to actually retrieve users. 82 | | 83 | | The expiry time is the number of minutes that each reset token will be 84 | | considered valid. This security feature keeps tokens short-lived so 85 | | they have less time to be guessed. You may change this as needed. 86 | | 87 | | The throttle setting is the number of seconds a user must wait before 88 | | generating more password reset tokens. This prevents the user from 89 | | quickly generating a very large amount of password reset tokens. 90 | | 91 | */ 92 | 93 | 'passwords' => [ 94 | 'users' => [ 95 | 'provider' => 'users', 96 | 'table' => env('AUTH_PASSWORD_RESET_TOKEN_TABLE', 'password_reset_tokens'), 97 | 'expire' => 60, 98 | 'throttle' => 60, 99 | ], 100 | ], 101 | 102 | /* 103 | |-------------------------------------------------------------------------- 104 | | Password Confirmation Timeout 105 | |-------------------------------------------------------------------------- 106 | | 107 | | Here you may define the number of seconds before a password confirmation 108 | | window expires and users are asked to re-enter their password via the 109 | | confirmation screen. By default, the timeout lasts for three hours. 110 | | 111 | */ 112 | 113 | 'password_timeout' => env('AUTH_PASSWORD_TIMEOUT', 10800), 114 | 115 | ]; 116 | -------------------------------------------------------------------------------- /demos/laravel/config/app.php: -------------------------------------------------------------------------------- 1 | env('APP_NAME', 'Laravel'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Application Environment 21 | |-------------------------------------------------------------------------- 22 | | 23 | | This value determines the "environment" your application is currently 24 | | running in. This may determine how you prefer to configure various 25 | | services the application utilizes. Set this in your ".env" file. 26 | | 27 | */ 28 | 29 | 'env' => env('APP_ENV', 'production'), 30 | 31 | /* 32 | |-------------------------------------------------------------------------- 33 | | Application Debug Mode 34 | |-------------------------------------------------------------------------- 35 | | 36 | | When your application is in debug mode, detailed error messages with 37 | | stack traces will be shown on every error that occurs within your 38 | | application. If disabled, a simple generic error page is shown. 39 | | 40 | */ 41 | 42 | 'debug' => (bool) env('APP_DEBUG', false), 43 | 44 | /* 45 | |-------------------------------------------------------------------------- 46 | | Application URL 47 | |-------------------------------------------------------------------------- 48 | | 49 | | This URL is used by the console to properly generate URLs when using 50 | | the Artisan command line tool. You should set this to the root of 51 | | the application so that it's available within Artisan commands. 52 | | 53 | */ 54 | 55 | 'url' => env('APP_URL', 'http://localhost'), 56 | 57 | /* 58 | |-------------------------------------------------------------------------- 59 | | Application Timezone 60 | |-------------------------------------------------------------------------- 61 | | 62 | | Here you may specify the default timezone for your application, which 63 | | will be used by the PHP date and date-time functions. The timezone 64 | | is set to "UTC" by default as it is suitable for most use cases. 65 | | 66 | */ 67 | 68 | 'timezone' => 'UTC', 69 | 70 | /* 71 | |-------------------------------------------------------------------------- 72 | | Application Locale Configuration 73 | |-------------------------------------------------------------------------- 74 | | 75 | | The application locale determines the default locale that will be used 76 | | by Laravel's translation / localization methods. This option can be 77 | | set to any locale for which you plan to have translation strings. 78 | | 79 | */ 80 | 81 | 'locale' => env('APP_LOCALE', 'en'), 82 | 83 | 'fallback_locale' => env('APP_FALLBACK_LOCALE', 'en'), 84 | 85 | 'faker_locale' => env('APP_FAKER_LOCALE', 'en_US'), 86 | 87 | /* 88 | |-------------------------------------------------------------------------- 89 | | Encryption Key 90 | |-------------------------------------------------------------------------- 91 | | 92 | | This key is utilized by Laravel's encryption services and should be set 93 | | to a random, 32 character string to ensure that all encrypted values 94 | | are secure. You should do this prior to deploying the application. 95 | | 96 | */ 97 | 98 | 'cipher' => 'AES-256-CBC', 99 | 100 | 'key' => env('APP_KEY'), 101 | 102 | 'previous_keys' => [ 103 | ...array_filter( 104 | explode(',', (string) env('APP_PREVIOUS_KEYS', '')) 105 | ), 106 | ], 107 | 108 | /* 109 | |-------------------------------------------------------------------------- 110 | | Maintenance Mode Driver 111 | |-------------------------------------------------------------------------- 112 | | 113 | | These configuration options determine the driver used to determine and 114 | | manage Laravel's "maintenance mode" status. The "cache" driver will 115 | | allow maintenance mode to be controlled across multiple machines. 116 | | 117 | | Supported drivers: "file", "cache" 118 | | 119 | */ 120 | 121 | 'maintenance' => [ 122 | 'driver' => env('APP_MAINTENANCE_DRIVER', 'file'), 123 | 'store' => env('APP_MAINTENANCE_STORE', 'database'), 124 | ], 125 | 126 | ]; 127 | -------------------------------------------------------------------------------- /demos/laravel/config/logging.php: -------------------------------------------------------------------------------- 1 | env('LOG_CHANNEL', 'stack'), 22 | 23 | /* 24 | |-------------------------------------------------------------------------- 25 | | Deprecations Log Channel 26 | |-------------------------------------------------------------------------- 27 | | 28 | | This option controls the log channel that should be used to log warnings 29 | | regarding deprecated PHP and library features. This allows you to get 30 | | your application ready for upcoming major versions of dependencies. 31 | | 32 | */ 33 | 34 | 'deprecations' => [ 35 | 'channel' => env('LOG_DEPRECATIONS_CHANNEL', 'null'), 36 | 'trace' => env('LOG_DEPRECATIONS_TRACE', false), 37 | ], 38 | 39 | /* 40 | |-------------------------------------------------------------------------- 41 | | Log Channels 42 | |-------------------------------------------------------------------------- 43 | | 44 | | Here you may configure the log channels for your application. Laravel 45 | | utilizes the Monolog PHP logging library, which includes a variety 46 | | of powerful log handlers and formatters that you're free to use. 47 | | 48 | | Available drivers: "single", "daily", "slack", "syslog", 49 | | "errorlog", "monolog", "custom", "stack" 50 | | 51 | */ 52 | 53 | 'channels' => [ 54 | 55 | 'stack' => [ 56 | 'driver' => 'stack', 57 | 'channels' => explode(',', (string) env('LOG_STACK', 'single')), 58 | 'ignore_exceptions' => false, 59 | ], 60 | 61 | 'single' => [ 62 | 'driver' => 'single', 63 | 'path' => storage_path('logs/laravel.log'), 64 | 'level' => env('LOG_LEVEL', 'debug'), 65 | 'replace_placeholders' => true, 66 | ], 67 | 68 | 'daily' => [ 69 | 'driver' => 'daily', 70 | 'path' => storage_path('logs/laravel.log'), 71 | 'level' => env('LOG_LEVEL', 'debug'), 72 | 'days' => env('LOG_DAILY_DAYS', 14), 73 | 'replace_placeholders' => true, 74 | ], 75 | 76 | 'slack' => [ 77 | 'driver' => 'slack', 78 | 'url' => env('LOG_SLACK_WEBHOOK_URL'), 79 | 'username' => env('LOG_SLACK_USERNAME', 'Laravel Log'), 80 | 'emoji' => env('LOG_SLACK_EMOJI', ':boom:'), 81 | 'level' => env('LOG_LEVEL', 'critical'), 82 | 'replace_placeholders' => true, 83 | ], 84 | 85 | 'papertrail' => [ 86 | 'driver' => 'monolog', 87 | 'level' => env('LOG_LEVEL', 'debug'), 88 | 'handler' => env('LOG_PAPERTRAIL_HANDLER', SyslogUdpHandler::class), 89 | 'handler_with' => [ 90 | 'host' => env('PAPERTRAIL_URL'), 91 | 'port' => env('PAPERTRAIL_PORT'), 92 | 'connectionString' => 'tls://'.env('PAPERTRAIL_URL').':'.env('PAPERTRAIL_PORT'), 93 | ], 94 | 'processors' => [PsrLogMessageProcessor::class], 95 | ], 96 | 97 | 'stderr' => [ 98 | 'driver' => 'monolog', 99 | 'level' => env('LOG_LEVEL', 'debug'), 100 | 'handler' => StreamHandler::class, 101 | 'handler_with' => [ 102 | 'stream' => 'php://stderr', 103 | ], 104 | 'formatter' => env('LOG_STDERR_FORMATTER'), 105 | 'processors' => [PsrLogMessageProcessor::class], 106 | ], 107 | 108 | 'syslog' => [ 109 | 'driver' => 'syslog', 110 | 'level' => env('LOG_LEVEL', 'debug'), 111 | 'facility' => env('LOG_SYSLOG_FACILITY', LOG_USER), 112 | 'replace_placeholders' => true, 113 | ], 114 | 115 | 'errorlog' => [ 116 | 'driver' => 'errorlog', 117 | 'level' => env('LOG_LEVEL', 'debug'), 118 | 'replace_placeholders' => true, 119 | ], 120 | 121 | 'null' => [ 122 | 'driver' => 'monolog', 123 | 'handler' => NullHandler::class, 124 | ], 125 | 126 | 'emergency' => [ 127 | 'path' => storage_path('logs/laravel.log'), 128 | ], 129 | 130 | ], 131 | 132 | ]; 133 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🎩 UseClassy 2 | 3 | UseClassy transforms Tailwind variant attributes (`class:hover="..."`) into standard Tailwind classes (`hover:...`). This allows for cleaner component markup by separating base classes from stateful or responsive variants. 4 | 5 | ## Features 6 | 7 | - Transforms attributes like `class:hover="text-blue-500"` to standard `class="hover:text-blue-500"`. 8 | - Supports chaining modifiers like `class:dark:hover="text-blue-500"`. 9 | - Works seamlessly with React (`className`) and Vue/HTML (`class`). 10 | - Integrates with Vite's build process and dev server. No runtime overhead. 11 | - Smart Caching: Avoids reprocessing unchanged files during development. 12 | - Runs before Tailwind JIT compiler with HMR and TailwindMerge support. 13 | 14 | ## Installation 15 | 16 | ```bash 17 | # npm 18 | npm install vite-plugin-useclassy --save-dev 19 | 20 | # yarn 21 | yarn add vite-plugin-useclassy -D 22 | 23 | # pnpm 24 | pnpm add vite-plugin-useclassy -D 25 | ``` 26 | 27 | ## Vite Configuration 28 | 29 | Add `useClassy` to your Vite plugins. It's recommended that you place it before Tailwind or other CSS processing plugins. 30 | 31 | ```ts 32 | // vite.config.ts 33 | import useClassy from "vite-plugin-useclassy"; 34 | 35 | export default { 36 | plugins: [ 37 | useClassy({ 38 | language: "react", // or 'vue' or 'blade' 39 | 40 | // Optional: Customize the output directory. Defaults to '.classy'. 41 | // outputDir: '.classy', 42 | 43 | // Optional: Customize output file name. Defaults to 'output.classy.html'. 44 | // outputFileName: 'generated-classes.html' 45 | 46 | // Optional: Enable debugging. Defaults to false. 47 | // debug: true, 48 | }), 49 | // ... other plugins 50 | ], 51 | }; 52 | ``` 53 | 54 | ## React Usage (`className`) 55 | 56 | ### Variant Attributes 57 | 58 | ```tsx 59 | // Input (using class:variant attributes) 60 |