create-template-html-css 2.0.4 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/CHANGELOG.md +436 -0
  2. package/CODE-SPLITTING-GUIDE.md +274 -0
  3. package/COMPONENTS-GALLERY.html +143 -8
  4. package/HTML-VS-REACT.md +289 -0
  5. package/QUICKSTART-REACT.md +293 -0
  6. package/REACT-SUPPORT-SUMMARY.md +235 -0
  7. package/README.md +261 -12
  8. package/bin/cli.js +100 -759
  9. package/bin/commands/create.js +288 -0
  10. package/bin/commands/gallery.js +42 -0
  11. package/bin/commands/insert.js +123 -0
  12. package/bin/commands/list.js +73 -0
  13. package/package.json +10 -3
  14. package/src/component-choices.js +7 -0
  15. package/src/components-registry.js +112 -0
  16. package/src/format-utils.js +49 -0
  17. package/src/generator.js +83 -594
  18. package/src/generators/color-schemes.js +78 -0
  19. package/src/generators/color-utils.js +108 -0
  20. package/src/generators/component-filters.js +151 -0
  21. package/src/generators/html-generators.js +180 -0
  22. package/src/generators/validation.js +43 -0
  23. package/src/index.js +2 -1
  24. package/src/inserter.js +55 -233
  25. package/src/inserters/backup-utils.js +20 -0
  26. package/src/inserters/component-loader.js +68 -0
  27. package/src/inserters/html-utils.js +31 -0
  28. package/src/inserters/indentation-utils.js +90 -0
  29. package/src/inserters/validation-utils.js +49 -0
  30. package/src/react-component-choices.js +97 -0
  31. package/src/react-component-templates.js +182 -0
  32. package/src/react-file-operations.js +172 -0
  33. package/src/react-generator.js +219 -0
  34. package/src/react-templates.js +418 -0
  35. package/src/templates/basic-components-templates.js +157 -0
  36. package/src/templates/form-components-templates.js +194 -0
  37. package/src/templates/interactive-components-templates.js +139 -0
  38. package/src/utils/file-utils.js +97 -0
  39. package/src/utils/path-utils.js +32 -0
  40. package/src/utils/string-utils.js +51 -0
  41. package/src/utils/template-loader.js +91 -0
  42. package/templates/_shared/PATTERNS.md +246 -0
  43. package/templates/_shared/README.md +74 -0
  44. package/templates/_shared/base.css +18 -0
  45. package/templates/blackjack/index.html +1 -1
  46. package/templates/breakout/index.html +1 -1
  47. package/templates/connect-four/index.html +1 -1
  48. package/templates/dice-game/index.html +1 -1
  49. package/templates/flappy-bird/index.html +1 -1
  50. package/templates/pong/index.html +1 -1
  51. package/templates/skeleton/index.html +4 -4
  52. package/templates/slot-machine/index.html +1 -1
  53. package/templates/tetris/index.html +1 -1
  54. package/templates-react/README.md +126 -0
  55. package/templates-react/alert/Alert.css +158 -0
  56. package/templates-react/alert/Alert.example.jsx +106 -0
  57. package/templates-react/alert/Alert.jsx +61 -0
  58. package/templates-react/badge/Badge.css +196 -0
  59. package/templates-react/badge/Badge.example.jsx +182 -0
  60. package/templates-react/badge/Badge.jsx +44 -0
  61. package/templates-react/button/Button.css +88 -0
  62. package/templates-react/button/Button.example.jsx +40 -0
  63. package/templates-react/button/Button.jsx +29 -0
  64. package/templates-react/card/Card.css +86 -0
  65. package/templates-react/card/Card.example.jsx +49 -0
  66. package/templates-react/card/Card.jsx +35 -0
  67. package/templates-react/checkbox/Checkbox.css +217 -0
  68. package/templates-react/checkbox/Checkbox.example.jsx +141 -0
  69. package/templates-react/checkbox/Checkbox.jsx +82 -0
  70. package/templates-react/counter/Counter.css +99 -0
  71. package/templates-react/counter/Counter.example.jsx +45 -0
  72. package/templates-react/counter/Counter.jsx +70 -0
  73. package/templates-react/dropdown/Dropdown.css +237 -0
  74. package/templates-react/dropdown/Dropdown.example.jsx +98 -0
  75. package/templates-react/dropdown/Dropdown.jsx +154 -0
  76. package/templates-react/form/Form.css +128 -0
  77. package/templates-react/form/Form.example.jsx +64 -0
  78. package/templates-react/form/Form.jsx +125 -0
  79. package/templates-react/input/Input.css +113 -0
  80. package/templates-react/input/Input.example.jsx +82 -0
  81. package/templates-react/input/Input.jsx +87 -0
  82. package/templates-react/modal/Modal.css +152 -0
  83. package/templates-react/modal/Modal.example.jsx +90 -0
  84. package/templates-react/modal/Modal.jsx +46 -0
  85. package/templates-react/navbar/Navbar.css +139 -0
  86. package/templates-react/navbar/Navbar.example.jsx +37 -0
  87. package/templates-react/navbar/Navbar.jsx +62 -0
  88. package/templates-react/progress/Progress.css +247 -0
  89. package/templates-react/progress/Progress.example.jsx +244 -0
  90. package/templates-react/progress/Progress.jsx +79 -0
  91. package/templates-react/switch/Switch.css +244 -0
  92. package/templates-react/switch/Switch.example.jsx +221 -0
  93. package/templates-react/switch/Switch.jsx +98 -0
  94. package/templates-react/todo-list/TodoList.css +236 -0
  95. package/templates-react/todo-list/TodoList.example.jsx +15 -0
  96. package/templates-react/todo-list/TodoList.jsx +84 -0
  97. package/templates-react/tooltip/Tooltip.css +165 -0
  98. package/templates-react/tooltip/Tooltip.example.jsx +166 -0
  99. package/templates-react/tooltip/Tooltip.jsx +176 -0
@@ -0,0 +1,274 @@
1
+ # Code Splitting Guide 🚀
2
+
3
+ This guide explains how to use code splitting features in your React projects to reduce bundle size and improve performance.
4
+
5
+ ## What is Code Splitting?
6
+
7
+ Code splitting is a technique that splits your JavaScript bundle into smaller chunks that can be loaded on demand. This reduces the initial load time of your application by only loading the code that's needed for the current page.
8
+
9
+ ## Features
10
+
11
+ ### 1. Lazy Loading with React.lazy() and Suspense
12
+
13
+ When you enable `--lazy-load` flag, your components are loaded dynamically using React's built-in lazy loading:
14
+
15
+ ```bash
16
+ create-template create --react -c button -n my-app --lazy-load
17
+ ```
18
+
19
+ This generates an App.jsx like this:
20
+
21
+ ```jsx
22
+ import { lazy, Suspense } from 'react';
23
+ import './components/Button/Button.css';
24
+
25
+ // Component is loaded only when needed
26
+ const Button = lazy(() => import('./components/Button/Button'));
27
+
28
+ function App() {
29
+ return (
30
+ <Suspense fallback={<div className="loading">Loading...</div>}>
31
+ {/* Your component usage */}
32
+ </Suspense>
33
+ );
34
+ }
35
+
36
+ export default App;
37
+ ```
38
+
39
+ **Benefits:**
40
+ - ✅ Smaller initial bundle size
41
+ - ✅ Faster page load time
42
+ - ✅ Better performance on slow networks
43
+ - ✅ Improved user experience with loading states
44
+
45
+ ### 2. Build Optimizations
46
+
47
+ When you enable `--optimize-build` flag, your vite.config.js includes advanced optimizations:
48
+
49
+ ```bash
50
+ create-template create --react -c button -n my-app --optimize-build
51
+ ```
52
+
53
+ This generates:
54
+
55
+ ```js
56
+ import { defineConfig } from 'vite';
57
+ import react from '@vitejs/plugin-react';
58
+
59
+ export default defineConfig({
60
+ plugins: [react()],
61
+ build: {
62
+ rollupOptions: {
63
+ output: {
64
+ manualChunks: {
65
+ // Split vendor code into separate chunk
66
+ vendor: ['react', 'react-dom'],
67
+ },
68
+ },
69
+ },
70
+ minify: 'terser',
71
+ terserOptions: {
72
+ compress: {
73
+ drop_console: true, // Remove console.log in production
74
+ },
75
+ },
76
+ },
77
+ });
78
+ ```
79
+
80
+ **Benefits:**
81
+ - ✅ Vendor code (React, ReactDOM) in separate chunk
82
+ - ✅ Better caching (vendor chunk rarely changes)
83
+ - ✅ Smaller main bundle
84
+ - ✅ Console.log removal in production
85
+ - ✅ Better compression
86
+
87
+ ### 3. Combine Both for Maximum Performance
88
+
89
+ ```bash
90
+ create-template create --react -c counter -n my-app --lazy-load --optimize-build
91
+ ```
92
+
93
+ This gives you:
94
+ - Dynamic component loading
95
+ - Optimized vendor chunking
96
+ - Production-ready configuration
97
+
98
+ ## Interactive Mode
99
+
100
+ You can also enable these features interactively:
101
+
102
+ ```bash
103
+ create-template create
104
+ ```
105
+
106
+ Then answer:
107
+ - Framework: **React (JSX + CSS)**
108
+ - Project type: **Full React project**
109
+ - Component: *Choose your component*
110
+ - Name: *Your project name*
111
+ - Lazy loading: **Yes**
112
+ - Build optimizations: **Yes**
113
+
114
+ ## Performance Impact
115
+
116
+ ### Without Code Splitting
117
+ ```
118
+ bundle.js 150 KB
119
+ ├── React 45 KB
120
+ ├── ReactDOM 40 KB
121
+ └── Your App 65 KB
122
+
123
+ Initial Load: 150 KB (slower)
124
+ ```
125
+
126
+ ### With Code Splitting
127
+ ```
128
+ vendor.js 85 KB (cached)
129
+ ├── React 45 KB
130
+ └── ReactDOM 40 KB
131
+
132
+ main.js 35 KB (loaded first)
133
+ └── Core App 35 KB
134
+
135
+ Button.js 30 KB (lazy loaded)
136
+ └── Component 30 KB
137
+
138
+ Initial Load: 120 KB (faster!) ⚡
139
+ Subsequent loads: 35 KB only (vendor cached)
140
+ ```
141
+
142
+ ## Advanced Usage
143
+
144
+ ### Route-Based Code Splitting
145
+
146
+ For multi-page apps, you can extend this pattern:
147
+
148
+ ```jsx
149
+ import { lazy, Suspense } from 'react';
150
+ import { BrowserRouter, Routes, Route } from 'react-router-dom';
151
+
152
+ const Home = lazy(() => import('./pages/Home'));
153
+ const About = lazy(() => import('./pages/About'));
154
+ const Contact = lazy(() => import('./pages/Contact'));
155
+
156
+ function App() {
157
+ return (
158
+ <BrowserRouter>
159
+ <Suspense fallback={<div>Loading page...</div>}>
160
+ <Routes>
161
+ <Route path="/" element={<Home />} />
162
+ <Route path="/about" element={<About />} />
163
+ <Route path="/contact" element={<Contact />} />
164
+ </Routes>
165
+ </Suspense>
166
+ </BrowserRouter>
167
+ );
168
+ }
169
+ ```
170
+
171
+ ### Custom Loading Component
172
+
173
+ Replace the fallback with a custom loader:
174
+
175
+ ```jsx
176
+ const Spinner = () => (
177
+ <div className="spinner">
178
+ <div className="spinner-circle"></div>
179
+ </div>
180
+ );
181
+
182
+ <Suspense fallback={<Spinner />}>
183
+ <Button />
184
+ </Suspense>
185
+ ```
186
+
187
+ ## Bundle Analysis
188
+
189
+ To analyze your bundle size:
190
+
191
+ ```bash
192
+ npm install --save-dev rollup-plugin-visualizer
193
+ ```
194
+
195
+ Update vite.config.js:
196
+
197
+ ```js
198
+ import { visualizer } from 'rollup-plugin-visualizer';
199
+
200
+ export default defineConfig({
201
+ plugins: [
202
+ react(),
203
+ visualizer({
204
+ filename: './dist/stats.html',
205
+ open: true,
206
+ }),
207
+ ],
208
+ // ... rest of config
209
+ });
210
+ ```
211
+
212
+ Then run:
213
+
214
+ ```bash
215
+ npm run build
216
+ ```
217
+
218
+ This opens a visual representation of your bundle!
219
+
220
+ ## Best Practices
221
+
222
+ 1. **Always lazy load routes** in multi-page apps
223
+ 2. **Split vendor code** for better caching
224
+ 3. **Add meaningful loading states** for better UX
225
+ 4. **Analyze your bundle** to find optimization opportunities
226
+ 5. **Use lazy loading wisely** - don't split too aggressively
227
+ 6. **Test on slow networks** to verify improvements
228
+
229
+ ## Migration Guide
230
+
231
+ ### Existing Projects
232
+
233
+ To add code splitting to an existing project:
234
+
235
+ 1. **Add lazy loading to App.jsx:**
236
+
237
+ ```jsx
238
+ // Before
239
+ import Button from './components/Button/Button';
240
+
241
+ // After
242
+ import { lazy, Suspense } from 'react';
243
+ const Button = lazy(() => import('./components/Button/Button'));
244
+
245
+ // Wrap your component in Suspense
246
+ <Suspense fallback={<div>Loading...</div>}>
247
+ <Button />
248
+ </Suspense>
249
+ ```
250
+
251
+ 2. **Update vite.config.js:**
252
+
253
+ Add the build optimization section from this guide.
254
+
255
+ 3. **Test thoroughly:**
256
+
257
+ ```bash
258
+ npm run build
259
+ npm run preview
260
+ ```
261
+
262
+ ## Learn More
263
+
264
+ - [React Code Splitting](https://react.dev/reference/react/lazy)
265
+ - [Vite Build Optimizations](https://vitejs.dev/guide/build.html)
266
+ - [Web Performance](https://web.dev/performance/)
267
+
268
+ ## Examples
269
+
270
+ See the `templates-react/` directory for examples of components that can benefit from code splitting.
271
+
272
+ ---
273
+
274
+ **Happy optimizing! 🎉**
@@ -252,20 +252,24 @@
252
252
  <body>
253
253
  <div class="container">
254
254
  <header>
255
- <h1>🎨 Create Template HTML/CSS</h1>
256
- <p>Interactive Component Gallery - v2.0.0</p>
255
+ <h1>🎨 Create Template HTML/CSS ⚛️</h1>
256
+ <p>Interactive Component Gallery - v2.1.0</p>
257
257
  <div class="stats">
258
258
  <div class="stat">
259
- <div class="stat-number">46</div>
259
+ <div class="stat-number">61</div>
260
260
  <div class="stat-label">Total Templates</div>
261
261
  </div>
262
262
  <div class="stat">
263
- <div class="stat-number">16</div>
264
- <div class="stat-label">Interactive Games</div>
263
+ <div class="stat-number">15</div>
264
+ <div class="stat-label">React Components</div>
265
+ </div>
266
+ <div class="stat">
267
+ <div class="stat-number">46</div>
268
+ <div class="stat-label">HTML Templates</div>
265
269
  </div>
266
270
  <div class="stat">
267
- <div class="stat-number">30</div>
268
- <div class="stat-label">UI Components</div>
271
+ <div class="stat-number">16</div>
272
+ <div class="stat-label">Interactive Games</div>
269
273
  </div>
270
274
  </div>
271
275
  </header>
@@ -357,6 +361,137 @@
357
361
  </div>
358
362
  </div>
359
363
 
364
+ <!-- React Components -->
365
+ <div class="category" data-category="react">
366
+ <div class="category-header">
367
+ <span class="category-icon">⚛️</span>
368
+ <h2 class="category-title">React Components (NEW)</h2>
369
+ <span class="category-count">15 components</span>
370
+ </div>
371
+ <div class="components-grid">
372
+ <div class="component-card" data-name="react alert notification">
373
+ <h3 class="component-name">Alert <span class="game-badge">NEW</span></h3>
374
+ <p class="component-description">Alert/notification with 4 types (success, error, warning, info)</p>
375
+ <div class="component-command">
376
+ create-template create --react -c alert -n my-alert
377
+ <button class="copy-btn" onclick="copyCommand(this)">Copy</button>
378
+ </div>
379
+ </div>
380
+ <div class="component-card" data-name="react badge status count">
381
+ <h3 class="component-name">Badge <span class="game-badge">NEW</span></h3>
382
+ <p class="component-description">Status badge with counts, dots, and variants</p>
383
+ <div class="component-command">
384
+ create-template create --react -c badge -n my-badge
385
+ <button class="copy-btn" onclick="copyCommand(this)">Copy</button>
386
+ </div>
387
+ </div>
388
+ <div class="component-card" data-name="react button">
389
+ <h3 class="component-name">Button</h3>
390
+ <p class="component-description">Customizable button with variants and sizes</p>
391
+ <div class="component-command">
392
+ create-template create --react -c button -n my-react-button
393
+ <button class="copy-btn" onclick="copyCommand(this)">Copy</button>
394
+ </div>
395
+ </div>
396
+ <div class="component-card" data-name="react card">
397
+ <h3 class="component-name">Card</h3>
398
+ <p class="component-description">Display content in elegant card with image support</p>
399
+ <div class="component-command">
400
+ create-template create --react -c card -n my-card
401
+ <button class="copy-btn" onclick="copyCommand(this)">Copy</button>
402
+ </div>
403
+ </div>
404
+ <div class="component-card" data-name="react checkbox form input">
405
+ <h3 class="component-name">Checkbox <span class="game-badge">NEW</span></h3>
406
+ <p class="component-description">Checkbox with sizes, colors, indeterminate state</p>
407
+ <div class="component-command">
408
+ create-template create --react -c checkbox -n my-checkbox
409
+ <button class="copy-btn" onclick="copyCommand(this)">Copy</button>
410
+ </div>
411
+ </div>
412
+ <div class="component-card" data-name="react counter">
413
+ <h3 class="component-name">Counter</h3>
414
+ <p class="component-description">Interactive counter with increment/decrement</p>
415
+ <div class="component-command">
416
+ create-template create --react -c counter -n my-counter
417
+ <button class="copy-btn" onclick="copyCommand(this)">Copy</button>
418
+ </div>
419
+ </div>
420
+ <div class="component-card" data-name="react dropdown select">
421
+ <h3 class="component-name">Dropdown <span class="game-badge">NEW</span></h3>
422
+ <p class="component-description">Select dropdown with search & multi-select</p>
423
+ <div class="component-command">
424
+ create-template create --react -c dropdown -n my-dropdown
425
+ <button class="copy-btn" onclick="copyCommand(this)">Copy</button>
426
+ </div>
427
+ </div>
428
+ <div class="component-card" data-name="react form validation">
429
+ <h3 class="component-name">Form</h3>
430
+ <p class="component-description">Flexible form with validation & multiple fields</p>
431
+ <div class="component-command">
432
+ create-template create --react -c form -n my-react-form
433
+ <button class="copy-btn" onclick="copyCommand(this)">Copy</button>
434
+ </div>
435
+ </div>
436
+ <div class="component-card" data-name="react input text field">
437
+ <h3 class="component-name">Input <span class="game-badge">NEW</span></h3>
438
+ <p class="component-description">Text input with validation, icons, and states</p>
439
+ <div class="component-command">
440
+ create-template create --react -c input -n my-input
441
+ <button class="copy-btn" onclick="copyCommand(this)">Copy</button>
442
+ </div>
443
+ </div>
444
+ <div class="component-card" data-name="react modal dialog">
445
+ <h3 class="component-name">Modal</h3>
446
+ <p class="component-description">Dialog modal with overlay and close handlers</p>
447
+ <div class="component-command">
448
+ create-template create --react -c modal -n my-modal
449
+ <button class="copy-btn" onclick="copyCommand(this)">Copy</button>
450
+ </div>
451
+ </div>
452
+ <div class="component-card" data-name="react navbar navigation">
453
+ <h3 class="component-name">Navbar <span class="game-badge">NEW</span></h3>
454
+ <p class="component-description">Responsive navbar with mobile hamburger menu</p>
455
+ <div class="component-command">
456
+ create-template create --react -c navbar -n my-navbar
457
+ <button class="copy-btn" onclick="copyCommand(this)">Copy</button>
458
+ </div>
459
+ </div>
460
+ <div class="component-card" data-name="react progress bar loading">
461
+ <h3 class="component-name">Progress <span class="game-badge">NEW</span></h3>
462
+ <p class="component-description">Progress bar with variants and animations</p>
463
+ <div class="component-command">
464
+ create-template create --react -c progress -n my-progress
465
+ <button class="copy-btn" onclick="copyCommand(this)">Copy</button>
466
+ </div>
467
+ </div>
468
+ <div class="component-card" data-name="react switch toggle">
469
+ <h3 class="component-name">Switch <span class="game-badge">NEW</span></h3>
470
+ <p class="component-description">Toggle switch for on/off states</p>
471
+ <div class="component-command">
472
+ create-template create --react -c switch -n my-switch
473
+ <button class="copy-btn" onclick="copyCommand(this)">Copy</button>
474
+ </div>
475
+ </div>
476
+ <div class="component-card" data-name="react todo list">
477
+ <h3 class="component-name">Todo List</h3>
478
+ <p class="component-description">Complete todo list with CRUD operations</p>
479
+ <div class="component-command">
480
+ create-template create --react -c todo-list -n my-todos
481
+ <button class="copy-btn" onclick="copyCommand(this)">Copy</button>
482
+ </div>
483
+ </div>
484
+ <div class="component-card" data-name="react tooltip hint">
485
+ <h3 class="component-name">Tooltip <span class="game-badge">NEW</span></h3>
486
+ <p class="component-description">Contextual tooltip with positions & triggers</p>
487
+ <div class="component-command">
488
+ create-template create --react -c tooltip -n my-tooltip
489
+ <button class="copy-btn" onclick="copyCommand(this)">Copy</button>
490
+ </div>
491
+ </div>
492
+ </div>
493
+ </div>
494
+
360
495
  <!-- Authentication Forms -->
361
496
  <div class="category" data-category="auth">
362
497
  <div class="category-header">
@@ -704,7 +839,7 @@
704
839
  <a href="https://www.npmjs.com/package/create-template-html-css" target="_blank">📦 npm Package</a> |
705
840
  <a href="https://github.com/benshabbat/create-template-html-css" target="_blank">🐙 GitHub Repo</a>
706
841
  </p>
707
- <p style="margin-top: 20px; opacity: 0.8;">v2.0.0 - 46 Templates Available</p>
842
+ <p style="margin-top: 20px; opacity: 0.8;">v2.1.0 - 46 HTML Templates + 15 React Components</p>
708
843
  </footer>
709
844
  </div>
710
845