|
1 | | -import { Bar, BarChart, CartesianGrid, LabelList, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts'; |
2 | | -import minificationData from '../../../minification-benchmarks-data.json'; |
| 1 | +import { LibraryBenchmarkCard } from './components/minification/LibraryBenchmarkCard'; |
| 2 | +import { MinificationStats } from './components/minification/MinificationStats'; |
| 3 | +import { libraries } from './utils/minification-data'; |
3 | 4 |
|
4 | | -// Transform minification data for charts |
5 | | -// Get popular minifiers for comparison |
6 | | -const popularMinifiers = ['terser', 'esbuild', '@swc/core', 'uglify-js', 'oxc-minify']; |
7 | | - |
8 | | -// Get library names from the data, sorted by size (largest first) |
9 | | -const libraries = Object.entries(minificationData) |
10 | | - .map(([name, data]: [string, any]) => ({ name, size: data.size })) |
11 | | - .sort((a, b) => b.size - a.size) |
12 | | - .map(item => item.name); |
13 | | - |
14 | | -// Transform minification data for individual library charts |
15 | | -const getLibraryData = (library: string, metric: 'time' | 'compression') => { |
16 | | - const libraryData = (minificationData as any)[library]; |
17 | | - const data: any[] = []; |
18 | | - |
19 | | - popularMinifiers.forEach(minifier => { |
20 | | - const minifierData = libraryData.minified?.[minifier]; |
21 | | - if (minifierData?.result?.data) { |
22 | | - let value: number; |
23 | | - let minzippedBytes = 0; |
24 | | - if (metric === 'time') { |
25 | | - value = Math.round(minifierData.result.data.time || 0); |
26 | | - } else { |
27 | | - // compression ratio |
28 | | - const originalSize = libraryData.size; |
29 | | - minzippedBytes = minifierData.result.data.minzippedBytes || 0; |
30 | | - value = Math.round(((originalSize - minzippedBytes) / originalSize) * 100 * 10) / 10; |
31 | | - } |
32 | | - |
33 | | - data.push({ |
34 | | - name: minifier === '@swc/core' |
35 | | - ? 'SWC' |
36 | | - : minifier === 'uglify-js' |
37 | | - ? 'UglifyJS' |
38 | | - : minifier === 'oxc-minify' |
39 | | - ? 'OXC' |
40 | | - : minifier === 'esbuild' |
41 | | - ? 'ESBuild' |
42 | | - : minifier === 'terser' |
43 | | - ? 'Terser' |
44 | | - : minifier, |
45 | | - value, |
46 | | - minzippedBytes: minzippedBytes || 0, |
47 | | - fill: minifier === 'terser' |
48 | | - ? '#a78bfa' |
49 | | - : minifier === 'esbuild' |
50 | | - ? '#10b981' |
51 | | - : minifier === '@swc/core' |
52 | | - ? '#38bdf8' |
53 | | - : minifier === 'uglify-js' |
54 | | - ? '#f87171' |
55 | | - : minifier === 'oxc-minify' |
56 | | - ? '#fbbf24' |
57 | | - : '#9ca3af', |
58 | | - }); |
59 | | - } |
60 | | - }); |
61 | | - |
62 | | - // Sort data: time from smallest to largest (fastest to slowest), compression from largest to smallest (best to worst) |
63 | | - return data.sort((a, b) => metric === 'time' ? a.value - b.value : a.minzippedBytes - b.minzippedBytes); |
64 | | -}; |
65 | | - |
66 | | -interface MinificationBenchmarksProps { |
67 | | - // Remove selectedMetric and setSelectedMetric since we'll show both metrics together |
68 | | -} |
69 | | - |
70 | | -function MinificationBenchmarks({}: MinificationBenchmarksProps) { |
| 5 | +function MinificationBenchmarks() { |
71 | 6 | return ( |
72 | 7 | <> |
73 | 8 | <main className='max-w-6xl mx-auto px-8 py-8 flex flex-col gap-8'> |
74 | 9 | {/* Combined Charts for Each Library - Time and Compression Side by Side */} |
75 | 10 | <div className='flex flex-col gap-8'> |
76 | | - {libraries.map(library => { |
77 | | - const timeData = getLibraryData(library, 'time'); |
78 | | - const compressionData = getLibraryData(library, 'compression'); |
79 | | - |
80 | | - return ( |
81 | | - <div |
82 | | - key={library} |
83 | | - className='bg-white dark:bg-slate-800 border border-gray-200 dark:border-slate-700 rounded-xl px-6 py-6 shadow-sm transition-all duration-300 hover:shadow-md hover:-translate-y-0.5' |
84 | | - > |
85 | | - <h3 className='mb-4 text-xl font-bold text-slate-800 dark:text-slate-100 capitalize text-center pb-2 border-b-2 border-slate-200 dark:border-slate-700'> |
86 | | - {library} |
87 | | - </h3> |
88 | | - <div className='grid grid-cols-1 lg:grid-cols-2 gap-8 mt-4'> |
89 | | - {/* Left column - Minification Time */} |
90 | | - <div className='bg-slate-50 dark:bg-slate-900 border border-gray-200 dark:border-slate-700 rounded-lg p-4'> |
91 | | - <h4 className='mb-4 text-base font-medium text-gray-700 dark:text-gray-300 text-center pb-2 border-b border-gray-200 dark:border-gray-700'> |
92 | | - Minification Time |
93 | | - </h4> |
94 | | - <ResponsiveContainer width='100%' height={300}> |
95 | | - <BarChart data={timeData} margin={{ top: 20, right: 30, left: 20, bottom: 5 }}> |
96 | | - <CartesianGrid strokeDasharray='3 3' className='stroke-slate-200 dark:stroke-slate-700' /> |
97 | | - <XAxis |
98 | | - dataKey='name' |
99 | | - tick={{ fill: '#6b7280', fontSize: 11 }} |
100 | | - axisLine={{ stroke: '#e5e7eb' }} |
101 | | - tickLine={{ stroke: '#e5e7eb' }} |
102 | | - angle={-45} |
103 | | - textAnchor='end' |
104 | | - height={60} |
105 | | - /> |
106 | | - <YAxis |
107 | | - tick={{ fill: '#6b7280', fontSize: 11 }} |
108 | | - axisLine={{ stroke: '#e5e7eb' }} |
109 | | - tickLine={{ stroke: '#e5e7eb' }} |
110 | | - /> |
111 | | - <Tooltip |
112 | | - contentStyle={{ |
113 | | - backgroundColor: 'var(--tooltip-bg)', |
114 | | - border: '1px solid var(--tooltip-border)', |
115 | | - borderRadius: '0.5rem', |
116 | | - boxShadow: '0 4px 8px rgba(0, 0, 0, 0.1)', |
117 | | - color: 'var(--tooltip-text)', |
118 | | - }} |
119 | | - labelStyle={{ color: 'var(--tooltip-text)' }} |
120 | | - formatter={(value: any) => [`${value}ms`, 'Minification Time']} |
121 | | - /> |
122 | | - <Bar dataKey='value' fill='#60a5fa'> |
123 | | - <LabelList |
124 | | - dataKey='value' |
125 | | - position='top' |
126 | | - formatter={(label: React.ReactNode) => `${label}ms`} |
127 | | - style={{ fontSize: '12px', fill: '#6b7280' }} |
128 | | - /> |
129 | | - </Bar> |
130 | | - </BarChart> |
131 | | - </ResponsiveContainer> |
132 | | - </div> |
133 | | - |
134 | | - {/* Right column - Compression Ratio */} |
135 | | - <div className='bg-slate-50 dark:bg-slate-900 border border-gray-200 dark:border-slate-700 rounded-lg p-4'> |
136 | | - <h4 className='mb-4 text-base font-medium text-gray-700 dark:text-gray-300 text-center pb-2 border-b border-gray-200 dark:border-gray-700'> |
137 | | - Compression Ratio |
138 | | - </h4> |
139 | | - <ResponsiveContainer width='100%' height={300}> |
140 | | - <BarChart data={compressionData} margin={{ top: 20, right: 30, left: 20, bottom: 5 }}> |
141 | | - <CartesianGrid strokeDasharray='3 3' className='stroke-slate-200 dark:stroke-slate-700' /> |
142 | | - <XAxis |
143 | | - dataKey='name' |
144 | | - tick={{ fill: '#6b7280', fontSize: 11 }} |
145 | | - axisLine={{ stroke: '#e5e7eb' }} |
146 | | - tickLine={{ stroke: '#e5e7eb' }} |
147 | | - angle={-45} |
148 | | - textAnchor='end' |
149 | | - height={60} |
150 | | - /> |
151 | | - <YAxis |
152 | | - tick={{ fill: '#6b7280', fontSize: 11 }} |
153 | | - axisLine={{ stroke: '#e5e7eb' }} |
154 | | - tickLine={{ stroke: '#e5e7eb' }} |
155 | | - /> |
156 | | - <Tooltip |
157 | | - contentStyle={{ |
158 | | - backgroundColor: 'var(--tooltip-bg)', |
159 | | - border: '1px solid var(--tooltip-border)', |
160 | | - borderRadius: '0.5rem', |
161 | | - boxShadow: '0 4px 8px rgba(0, 0, 0, 0.1)', |
162 | | - color: 'var(--tooltip-text)', |
163 | | - }} |
164 | | - labelStyle={{ color: 'var(--tooltip-text)' }} |
165 | | - formatter={(value: any, _name: any, props: any) => [ |
166 | | - `${value}% (${props.payload.minzippedBytes} bytes)`, |
167 | | - 'Compression Ratio', |
168 | | - ]} |
169 | | - /> |
170 | | - <Bar dataKey='value' fill='#4ade80'> |
171 | | - <LabelList |
172 | | - dataKey='value' |
173 | | - position='top' |
174 | | - formatter={(label: React.ReactNode) => `${label}%`} |
175 | | - style={{ fontSize: '10px', fill: '#6b7280' }} |
176 | | - /> |
177 | | - </Bar> |
178 | | - </BarChart> |
179 | | - </ResponsiveContainer> |
180 | | - </div> |
181 | | - </div> |
182 | | - </div> |
183 | | - ); |
184 | | - })} |
| 11 | + {libraries.map(library => ( |
| 12 | + <LibraryBenchmarkCard key={library} library={library} /> |
| 13 | + ))} |
185 | 14 | </div> |
186 | 15 |
|
187 | | - <div className='grid grid-cols-1 md:grid-cols-2 xl:grid-cols-4 gap-6'> |
188 | | - {/* Minification statistics */} |
189 | | - <div className='bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 px-7 py-7 rounded-xl shadow-sm border-l-4 border-l-blue-500 transition-all duration-200 hover:-translate-y-0.5 hover:shadow-md'> |
190 | | - <h3 className='mb-3 text-slate-500 dark:text-slate-400 text-sm font-semibold uppercase tracking-widest'> |
191 | | - Libraries Tested |
192 | | - </h3> |
193 | | - <p className='mb-3 text-4xl font-bold text-slate-800 dark:text-slate-100 tracking-tight leading-tight'> |
194 | | - {Object.keys(minificationData).length} |
195 | | - </p> |
196 | | - <span className='text-sm font-semibold px-3 py-1.5 rounded-lg inline-flex items-center gap-1 text-emerald-700 bg-emerald-100 bg-opacity-100 border border-emerald-200 border-opacity-200'> |
197 | | - JavaScript Libraries |
198 | | - </span> |
199 | | - </div> |
200 | | - <div className='bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 px-7 py-7 rounded-xl shadow-sm border-l-4 border-l-blue-500 transition-all duration-200 hover:-translate-y-0.5 hover:shadow-md'> |
201 | | - <h3 className='mb-3 text-slate-500 dark:text-slate-400 text-sm font-semibold uppercase tracking-widest'> |
202 | | - Minifiers Compared |
203 | | - </h3> |
204 | | - <p className='mb-3 text-4xl font-bold text-slate-800 dark:text-slate-100 tracking-tight leading-tight'> |
205 | | - {popularMinifiers.length} |
206 | | - </p> |
207 | | - <span className='text-sm font-semibold px-3 py-1.5 rounded-lg inline-flex items-center gap-1 text-emerald-700 bg-emerald-100 bg-opacity-100 border border-emerald-200 border-opacity-200'> |
208 | | - Popular Tools |
209 | | - </span> |
210 | | - </div> |
211 | | - <div className='bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 px-7 py-7 rounded-xl shadow-sm border-l-4 border-l-blue-500 transition-all duration-200 hover:-translate-y-0.5 hover:shadow-md'> |
212 | | - <h3 className='mb-3 text-slate-500 dark:text-slate-400 text-sm font-semibold uppercase tracking-widest'> |
213 | | - Fastest Minifier |
214 | | - </h3> |
215 | | - <p className='mb-3 text-4xl font-bold text-slate-800 dark:text-slate-100 tracking-tight leading-tight'> |
216 | | - OXC |
217 | | - </p> |
218 | | - <span className='text-sm font-semibold px-3 py-1.5 rounded-lg inline-flex items-center gap-1 text-emerald-700 bg-emerald-100 bg-opacity-100 border border-emerald-200 border-opacity-200'> |
219 | | - Rust-based |
220 | | - </span> |
221 | | - </div> |
222 | | - <div className='bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 px-7 py-7 rounded-xl shadow-sm border-l-4 border-l-blue-500 transition-all duration-200 hover:-translate-y-0.5 hover:shadow-md'> |
223 | | - <h3 className='mb-3 text-slate-500 dark:text-slate-400 text-sm font-semibold uppercase tracking-widest'> |
224 | | - Best Compression |
225 | | - </h3> |
226 | | - <p className='mb-3 text-4xl font-bold text-slate-800 dark:text-slate-100 tracking-tight leading-tight'> |
227 | | - UglifyJS |
228 | | - </p> |
229 | | - <span className='text-sm font-semibold px-3 py-1.5 rounded-lg inline-flex items-center gap-1 text-emerald-700 bg-emerald-100 bg-opacity-100 border border-emerald-200 border-opacity-200'> |
230 | | - Traditional Leader |
231 | | - </span> |
232 | | - </div> |
233 | | - </div> |
| 16 | + <MinificationStats /> |
234 | 17 | </main> |
235 | 18 | </> |
236 | 19 | ); |
|
0 commit comments