responsive-system 1.0.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 (40) hide show
  1. package/ARCHITECTURE.md +195 -0
  2. package/INSTALLATION.md +403 -0
  3. package/README.md +382 -0
  4. package/dist/components/LayoutSwitcher.d.ts +6 -0
  5. package/dist/components/layout/Footer.d.ts +3 -0
  6. package/dist/components/layout/Header.d.ts +3 -0
  7. package/dist/components/layout/Navigation.d.ts +3 -0
  8. package/dist/components/layout/Sidebar.d.ts +3 -0
  9. package/dist/components/layout/index.d.ts +5 -0
  10. package/dist/config/layout.d.ts +15 -0
  11. package/dist/constants/breakpoints.d.ts +19 -0
  12. package/dist/context/NavigationContext.d.ts +13 -0
  13. package/dist/context/ResponsiveLayoutContext.d.ts +22 -0
  14. package/dist/context/SidebarContext.d.ts +11 -0
  15. package/dist/context/index.d.ts +4 -0
  16. package/dist/hooks/index.d.ts +4 -0
  17. package/dist/hooks/useLayout.d.ts +27 -0
  18. package/dist/hooks/useResponsive.d.ts +7 -0
  19. package/dist/hooks/useResponsiveLayout.d.ts +64 -0
  20. package/dist/index.d.ts +11 -0
  21. package/dist/layouts/DashboardLayout.d.ts +7 -0
  22. package/dist/layouts/DefaultLayout.d.ts +7 -0
  23. package/dist/layouts/MainLayout.d.ts +12 -0
  24. package/dist/layouts/MinimalLayout.d.ts +7 -0
  25. package/dist/layouts/SidebarLayout.d.ts +7 -0
  26. package/dist/layouts/index.d.ts +6 -0
  27. package/dist/providers/ResponsiveLayoutProvider.d.ts +15 -0
  28. package/dist/providers/ResponsiveProvider.d.ts +11 -0
  29. package/dist/providers/index.d.ts +3 -0
  30. package/dist/responsive-system.cjs +9 -0
  31. package/dist/responsive-system.cjs.map +1 -0
  32. package/dist/responsive-system.mjs +580 -0
  33. package/dist/responsive-system.mjs.map +1 -0
  34. package/dist/types/responsive.d.ts +43 -0
  35. package/package.json +97 -0
  36. package/scripts/copy-types.js +46 -0
  37. package/scripts/generate-types.js +163 -0
  38. package/scripts/postinstall.js +76 -0
  39. package/src/plugin/responsiveScalePlugin.d.ts +57 -0
  40. package/src/plugin/responsiveScalePlugin.js +296 -0
@@ -0,0 +1,195 @@
1
+ # 🏗️ Arquitectura del Sistema
2
+
3
+ ## 📦 Sistema Core vs Ejemplos
4
+
5
+ ### ✅ **SISTEMA CORE (Independiente)**
6
+
7
+ Estos archivos conforman el **sistema responsivo reutilizable**. Puedes eliminar las páginas de ejemplo y el sistema seguirá funcionando.
8
+
9
+ #### **Plugin**
10
+ ```
11
+ src/plugin/
12
+ └── responsiveScalePlugin.js # ✅ Plugin de Tailwind
13
+ ```
14
+
15
+ #### **Providers**
16
+ ```
17
+ src/providers/
18
+ ├── index.ts # ✅ Barrel exports
19
+ ├── ResponsiveProvider.tsx # ✅ Provider base
20
+ └── ResponsiveLayoutProvider.tsx # ✅ Provider con layouts
21
+ ```
22
+
23
+ #### **Hooks**
24
+ ```
25
+ src/hooks/
26
+ ├── index.ts # ✅ Barrel exports
27
+ ├── useResponsive.ts # ✅ Hook responsivo
28
+ ├── useResponsiveLayout.ts # ✅ Hook unificado
29
+ └── useLayout.ts # ✅ Hook de layout
30
+ ```
31
+
32
+ #### **Layouts**
33
+ ```
34
+ src/layouts/
35
+ ├── index.ts # ✅ Barrel exports
36
+ ├── MainLayout.tsx # ✅ Layout principal
37
+ ├── DefaultLayout.tsx # ✅ Layout por defecto
38
+ ├── SidebarLayout.tsx # ✅ Layout con sidebar
39
+ ├── DashboardLayout.tsx # ✅ Layout dashboard
40
+ └── MinimalLayout.tsx # ✅ Layout mínimo
41
+ ```
42
+
43
+ #### **Componentes de Layout**
44
+ ```
45
+ src/components/layout/
46
+ ├── index.ts # ✅ Barrel exports
47
+ ├── Navigation.tsx # ✅ Navegación
48
+ ├── Sidebar.tsx # ✅ Sidebar
49
+ ├── Header.tsx # ✅ Header
50
+ └── Footer.tsx # ✅ Footer
51
+ ```
52
+
53
+ #### **Context**
54
+ ```
55
+ src/context/
56
+ ├── index.ts # ✅ Barrel exports
57
+ ├── ResponsiveLayoutContext.tsx # ✅ Context principal
58
+ ├── SidebarContext.tsx # ✅ Context del sidebar
59
+ └── NavigationContext.tsx # ✅ Context de navegación
60
+ ```
61
+
62
+ #### **Tipos**
63
+ ```
64
+ src/types/
65
+ └── responsive.ts # ✅ Tipos TypeScript
66
+ ```
67
+
68
+ #### **Constantes**
69
+ ```
70
+ src/constants/
71
+ └── breakpoints.ts # ✅ Configuración de breakpoints
72
+ ```
73
+
74
+ #### **Configuración**
75
+ ```
76
+ src/config/
77
+ └── layout.ts # ✅ Configuración de layouts
78
+ ```
79
+
80
+ #### **Componentes Auxiliares**
81
+ ```
82
+ src/components/
83
+ └── LayoutSwitcher.tsx # ✅ Selector de layouts
84
+ ```
85
+
86
+ #### **Export Principal**
87
+ ```
88
+ src/index.ts # ✅ Exportaciones del sistema
89
+ ```
90
+
91
+ ---
92
+
93
+ ### 🎨 **EJEMPLOS (Eliminables)**
94
+
95
+ Estos archivos son **solo para demostración**. Puedes eliminarlos sin afectar el sistema core.
96
+
97
+ #### **Páginas de Ejemplo**
98
+ ```
99
+ src/pages/
100
+ └── ResponsiveTestPage.tsx # ❌ Ejemplo - Suite de tests
101
+ ```
102
+
103
+ #### **Componentes de Ejemplo**
104
+ ```
105
+ src/components/
106
+ └── ResponsiveDemo.tsx # ❌ Ejemplo - Demo visual
107
+ ```
108
+
109
+ #### **App de Ejemplo**
110
+ ```
111
+ src/App.tsx # ❌ Ejemplo - Aplicación de prueba
112
+ src/main.tsx # ❌ Ejemplo - Entry point
113
+ ```
114
+
115
+ ---
116
+
117
+ ### **Paso 1: Actualizar `src/index.ts`**
118
+ ```typescript
119
+ // Eliminar estas líneas:
120
+ export { default as ResponsiveTestPage } from './pages/ResponsiveTestPage'
121
+ export { default as ResponsiveDemo } from './components/ResponsiveDemo'
122
+ ```
123
+
124
+ ### **Paso 2: Listo ✅**
125
+ El sistema core sigue funcionando perfectamente. Ahora puedes:
126
+ - Instalar el sistema en tu proyecto
127
+ - Importar solo lo que necesites: `import { ResponsiveLayoutProvider, MainLayout } from './index'`
128
+ - Usar el plugin en `tailwind.config.js`
129
+
130
+ ---
131
+
132
+ ## 📖 Uso en Tu Proyecto
133
+
134
+ ### **1. Instalar el Sistema**
135
+ ```bash
136
+ # Copiar la carpeta src/ a tu proyecto
137
+ # O publicar como paquete npm
138
+ ```
139
+
140
+ ### **2. Configurar Tailwind**
141
+ ```js
142
+ // tailwind.config.js
143
+ import responsiveScalePlugin from './src/plugin/responsiveScalePlugin.js'
144
+
145
+ export default {
146
+ plugins: [responsiveScalePlugin({ /* config */ })]
147
+ }
148
+ ```
149
+
150
+ ### **3. Crear Tu App**
151
+ ```tsx
152
+ // TuApp.tsx
153
+ import { ResponsiveLayoutProvider, MainLayout } from './index'
154
+
155
+ function TuApp() {
156
+ return (
157
+ <ResponsiveLayoutProvider defaultLayout="default">
158
+ <MainLayout>
159
+ <TuContenido />
160
+ </MainLayout>
161
+ </ResponsiveLayoutProvider>
162
+ )
163
+ }
164
+ ```
165
+
166
+ ### **4. Si Necesitas Navegación**
167
+ ```tsx
168
+ import { NavigationProvider, useNavigation } from './index'
169
+
170
+ function TuApp() {
171
+ return (
172
+ <NavigationProvider defaultPage="home">
173
+ <ResponsiveLayoutProvider defaultLayout="default">
174
+ <MainLayout>
175
+ <TuContenido />
176
+ </MainLayout>
177
+ </ResponsiveLayoutProvider>
178
+ </NavigationProvider>
179
+ )
180
+ }
181
+ ```
182
+
183
+ ---
184
+
185
+ ## 🎯 Resumen
186
+
187
+ | Tipo | Archivos | ¿Eliminable? | Función |
188
+ |------|----------|--------------|---------|
189
+ | **Sistema Core** | 30+ archivos | ❌ NO | Sistema responsivo + layouts |
190
+ | **Ejemplos** | 4 archivos | ✅ SÍ | Demostración y pruebas |
191
+
192
+ **✅ El sistema es 100% independiente de los ejemplos**
193
+ **✅ Puedes eliminar `App.tsx`, `ResponsiveDemo.tsx`, `ResponsiveTestPage.tsx` sin problemas**
194
+
195
+
@@ -0,0 +1,403 @@
1
+ # 📦 Instalación en Proyecto Existente
2
+
3
+ ## ¿Es invasivo este sistema?
4
+
5
+ **RESPUESTA CORTA: NO, es completamente modular y no invasivo.**
6
+
7
+ El sistema se divide en **2 partes independientes**:
8
+
9
+ 1. **Sistema de Auto-Scaling** (Plugin de Tailwind) - ⚠️ Requiere configuración
10
+ 2. **Sistema de Layouts** (Componentes React) - ✅ Completamente opcional
11
+
12
+ ---
13
+
14
+ ## 🎯 Nivel de Invasividad
15
+
16
+ ### ✅ **BAJO IMPACTO** - Solo Auto-Scaling
17
+
18
+ Si **solo quieres el auto-scaling** (sin layouts):
19
+
20
+ **Archivos a copiar:** `1 archivo`
21
+ ```
22
+ src/plugin/responsiveScalePlugin.js
23
+ ```
24
+
25
+ **Archivos a modificar:** `1 archivo`
26
+ ```
27
+ tailwind.config.js (agregar plugin)
28
+ ```
29
+
30
+ **¿Rompe código existente?** **NO**
31
+ - El plugin solo agrega CSS variables nuevas
32
+ - No modifica clases existentes de Tailwind
33
+ - Tu código actual sigue funcionando igual
34
+
35
+ ---
36
+
37
+ ### ⚠️ **MEDIO IMPACTO** - Con Providers
38
+
39
+ Si quieres usar **hooks** (`useResponsive`, etc.):
40
+
41
+ **Archivos a copiar:** `~10 archivos`
42
+ ```
43
+ src/plugin/responsiveScalePlugin.js
44
+ src/providers/ResponsiveProvider.tsx
45
+ src/hooks/useResponsive.ts
46
+ src/constants/breakpoints.ts
47
+ src/types/responsive.ts
48
+ ```
49
+
50
+ **Archivos a modificar:** `2 archivos`
51
+ ```
52
+ tailwind.config.js (agregar plugin)
53
+ App.tsx (envolver con provider)
54
+ ```
55
+
56
+ **¿Rompe código existente?** **NO**
57
+ - Solo necesitas agregar `<ResponsiveProvider>` en tu App
58
+ - No afecta componentes existentes
59
+ - Puedes usar solo en componentes nuevos
60
+
61
+ ---
62
+
63
+ ### 🔧 **ALTO IMPACTO** - Sistema Completo + Layouts
64
+
65
+ Si quieres **todo el sistema** (auto-scaling + layouts + hooks):
66
+
67
+ **Archivos a copiar:** `~30 archivos`
68
+
69
+ **Archivos a modificar:** `2-3 archivos`
70
+ ```
71
+ tailwind.config.js
72
+ App.tsx
73
+ package.json (si faltan dependencias)
74
+ ```
75
+
76
+ **¿Rompe código existente?** **DEPENDE**
77
+ - Si usas `MainLayout`, necesitas adaptar tu estructura
78
+ - Tus componentes existentes **NO se rompen**
79
+ - Puedes migrar progresivamente
80
+
81
+ ---
82
+
83
+ ## 📋 Guía de Instalación Paso a Paso
84
+
85
+ ### **OPCIÓN 1: Solo Auto-Scaling** ⭐ **RECOMENDADA PARA EMPEZAR**
86
+
87
+ #### 1. Copiar el plugin
88
+ ```bash
89
+ # Crear carpeta
90
+ mkdir -p src/plugin
91
+
92
+ # Copiar archivo
93
+ cp responsiveScalePlugin.js src/plugin/
94
+ ```
95
+
96
+ #### 2. Modificar `tailwind.config.js`
97
+ ```js
98
+ import responsiveScalePlugin from './src/plugin/responsiveScalePlugin.js'
99
+
100
+ export default {
101
+ content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"],
102
+ theme: {
103
+ extend: {
104
+ screens: {
105
+ 'xs': '475px',
106
+ 'sm': '640px',
107
+ 'md': '768px',
108
+ 'lg': '1024px',
109
+ 'xl': '1280px',
110
+ '2xl': '1536px',
111
+ '3xl': '1920px', // 👈 Nuevo
112
+ '4xl': '2560px', // 👈 Nuevo
113
+ '5xl': '3840px', // 👈 Nuevo (4K)
114
+ }
115
+ },
116
+ },
117
+ plugins: [
118
+ responsiveScalePlugin({
119
+ scaleProperties: {
120
+ typography: true, // font-size se escala
121
+ spacing: true, // padding, margin, gap se escalan
122
+ lineHeight: true, // line-height se escala
123
+ letterSpacing: true, // letter-spacing se escala
124
+ shadows: true, // box-shadow se escala
125
+ borderWidth: false, // border-width NO se escala (puede romper)
126
+ sizing: false, // width, height NO se escalan (puede romper)
127
+ borderRadius: false // rounded-* NO se escala (mantener fijo)
128
+ },
129
+ scales: {
130
+ xs: 1.0,
131
+ sm: 1.0,
132
+ md: 1.0,
133
+ lg: 1.0,
134
+ xl: 1.0,
135
+ '2xl': 1.05, // +5% en 1536px
136
+ '3xl': 1.15, // +15% en 1920px (Full HD)
137
+ '4xl': 1.25, // +25% en 2560px (2K)
138
+ '5xl': 1.35 // +35% en 3840px (4K)
139
+ },
140
+ breakpoints: {
141
+ xs: '475px',
142
+ sm: '640px',
143
+ md: '768px',
144
+ lg: '1024px',
145
+ xl: '1280px',
146
+ '2xl': '1536px',
147
+ '3xl': '1920px',
148
+ '4xl': '2560px',
149
+ '5xl': '3840px'
150
+ }
151
+ })
152
+ ],
153
+ }
154
+ ```
155
+
156
+ #### 3. ¡Listo! 🎉
157
+
158
+ **Ya funciona.** Ahora puedes usar:
159
+
160
+ ```tsx
161
+ // Componente existente
162
+ function MyButton() {
163
+ return (
164
+ <button className="px-4 py-2 text-base">
165
+ Click me
166
+ </button>
167
+ )
168
+ }
169
+
170
+ // En móvil: px-4 = 16px
171
+ // En 4K: px-4 = 21.6px (escalado automáticamente)
172
+ ```
173
+
174
+ **✅ Ventajas:**
175
+ - Cero cambios en tu código
176
+ - Compatible con cualquier proyecto Tailwind
177
+ - No rompe nada existente
178
+ - Puedes ajustar `scales` a tu gusto
179
+
180
+ **❌ Limitaciones:**
181
+ - No tienes acceso a hooks (`useResponsive`, `isMobile`, etc.)
182
+ - No puedes detectar breakpoints en JavaScript
183
+
184
+ ---
185
+
186
+ ### **OPCIÓN 2: Con Hooks** (Detección de Breakpoints)
187
+
188
+ Si necesitas **detectar breakpoints en JavaScript** (ej: `isMobile`, `isTablet`):
189
+
190
+ #### 1. Instalar OPCIÓN 1 primero
191
+
192
+ #### 2. Copiar archivos adicionales
193
+ ```bash
194
+ mkdir -p src/providers src/hooks src/constants src/types
195
+
196
+ # Copiar archivos core
197
+ cp ResponsiveProvider.tsx src/providers/
198
+ cp useResponsive.ts src/hooks/
199
+ cp breakpoints.ts src/constants/
200
+ cp responsive.ts src/types/
201
+ ```
202
+
203
+ #### 3. Envolver tu App
204
+ ```tsx
205
+ // App.tsx (ANTES)
206
+ function App() {
207
+ return <YourExistingApp />
208
+ }
209
+
210
+ // App.tsx (DESPUÉS)
211
+ import { ResponsiveProvider } from './providers/ResponsiveProvider'
212
+
213
+ function App() {
214
+ return (
215
+ <ResponsiveProvider>
216
+ <YourExistingApp />
217
+ </ResponsiveProvider>
218
+ )
219
+ }
220
+ ```
221
+
222
+ #### 4. Usar en componentes
223
+ ```tsx
224
+ import { useResponsive } from './hooks/useResponsive'
225
+
226
+ function MyComponent() {
227
+ const { isMobile, isTablet, currentBreakpoint } = useResponsive()
228
+
229
+ return (
230
+ <div>
231
+ {isMobile && <MobileMenu />}
232
+ {isTablet && <TabletView />}
233
+ <p>Breakpoint actual: {currentBreakpoint}</p>
234
+ </div>
235
+ )
236
+ }
237
+ ```
238
+
239
+ **✅ Ventajas adicionales:**
240
+ - Detección de breakpoints en JS
241
+ - Helpers booleanos (isMobile, isTablet, etc.)
242
+ - Condicionales responsive sin CSS
243
+
244
+ **⚠️ Consideración:**
245
+ - Agrega 1 provider a tu App
246
+ - Agrega ~50KB al bundle (hooks + context)
247
+
248
+ ---
249
+
250
+ ### **OPCIÓN 3: Sistema Completo** (Con Layouts)
251
+
252
+ Si quieres **layouts preconfigurados** (tipo Ant Design):
253
+
254
+ #### 1. Instalar OPCIÓN 2 primero
255
+
256
+ #### 2. Copiar carpetas adicionales
257
+ ```bash
258
+ mkdir -p src/layouts src/components/layout src/context
259
+
260
+ # Copiar todo el sistema de layouts
261
+ cp -r layouts/* src/layouts/
262
+ cp -r components/layout/* src/components/layout/
263
+ cp -r context/* src/context/
264
+ cp ResponsiveLayoutProvider.tsx src/providers/
265
+ cp useResponsiveLayout.ts src/hooks/
266
+ cp useLayout.ts src/hooks/
267
+ ```
268
+
269
+ #### 3. Modificar App.tsx
270
+ ```tsx
271
+ // App.tsx
272
+ import { ResponsiveLayoutProvider, MainLayout } from './index'
273
+
274
+ function App() {
275
+ return (
276
+ <ResponsiveLayoutProvider defaultLayout="default">
277
+ <MainLayout>
278
+ <YourExistingApp />
279
+ </MainLayout>
280
+ </ResponsiveLayoutProvider>
281
+ )
282
+ }
283
+ ```
284
+
285
+ #### 4. Usar layouts
286
+ ```tsx
287
+ import { useResponsiveLayout } from './hooks'
288
+
289
+ function MyPage() {
290
+ const { layout } = useResponsiveLayout()
291
+
292
+ return (
293
+ <div>
294
+ <h1>Mi Página</h1>
295
+ <p>Layout actual: {layout.current}</p>
296
+
297
+ <button onClick={() => layout.setLayout('sidebar')}>
298
+ Cambiar a Sidebar
299
+ </button>
300
+ </div>
301
+ )
302
+ }
303
+ ```
304
+
305
+ **✅ Ventajas adicionales:**
306
+ - Layouts listos para usar (Default, Sidebar, Dashboard, Minimal)
307
+ - Navbar, Sidebar, Footer incluidos
308
+ - Cambio dinámico de layout
309
+
310
+ **⚠️ Consideraciones:**
311
+ - Sistema más complejo (~30 archivos)
312
+ - Puede requerir adaptar tu estructura actual
313
+ - Si ya tienes un layout, puede generar conflictos
314
+
315
+ ---
316
+
317
+ ## 🔍 Comparación de Opciones
318
+
319
+ | Característica | Solo Plugin | Con Hooks | Completo |
320
+ |---|---|---|---|
321
+ | **Archivos a copiar** | 1 | ~8 | ~30 |
322
+ | **Archivos a modificar** | 1 | 2 | 2-3 |
323
+ | **Auto-scaling CSS** | ✅ | ✅ | ✅ |
324
+ | **Detección de breakpoints** | ❌ | ✅ | ✅ |
325
+ | **Helpers booleanos** | ❌ | ✅ | ✅ |
326
+ | **Layouts preconfigurados** | ❌ | ❌ | ✅ |
327
+ | **Cambio dinámico de layout** | ❌ | ❌ | ✅ |
328
+ | **Invasividad** | ⬇️ Baja | ⬇️ Media | ⬆️ Alta |
329
+ | **Bundle size** | +5KB | +50KB | +150KB |
330
+
331
+ ---
332
+
333
+ ## ⚡ Recomendación
334
+
335
+ ### Para un **proyecto nuevo**:
336
+ 👉 **OPCIÓN 3** (Sistema completo) - Aprovecha todo
337
+
338
+ ### Para un **proyecto existente pequeño**:
339
+ 👉 **OPCIÓN 2** (Con hooks) - Buen balance
340
+
341
+ ### Para un **proyecto existente grande/complejo**:
342
+ 👉 **OPCIÓN 1** (Solo plugin) - Mínima invasión
343
+
344
+ ---
345
+
346
+ ## 🚨 ¿Puede romper algo?
347
+
348
+ ### **NO romperá:**
349
+ - ✅ Componentes existentes
350
+ - ✅ Estilos actuales de Tailwind
351
+ - ✅ Otras librerías CSS
352
+ - ✅ Funcionalidad de la app
353
+
354
+ ### **PUEDE conflictuar con:**
355
+ - ⚠️ Otros plugins de Tailwind que modifiquen las mismas propiedades
356
+ - ⚠️ Sistemas de layout existentes (si usas OPCIÓN 3)
357
+ - ⚠️ CSS custom que dependa de valores fijos de Tailwind
358
+
359
+ ---
360
+
361
+ ## 🧪 Modo de Prueba
362
+
363
+ **Recomendación:** Prueba primero en una **rama separada**
364
+
365
+ ```bash
366
+ # Crear rama de prueba
367
+ git checkout -b test-responsive-system
368
+
369
+ # Instalar OPCIÓN 1
370
+ # ... copiar archivo y modificar config
371
+
372
+ # Probar en desarrollo
373
+ npm run dev
374
+
375
+ # Si funciona bien, mergear
376
+ git checkout main
377
+ git merge test-responsive-system
378
+ ```
379
+
380
+ ---
381
+
382
+ ## 📞 Soporte
383
+
384
+ Si encuentras problemas:
385
+
386
+ 1. Verifica que Tailwind CSS v4+ esté instalado
387
+ 2. Revisa que el plugin se esté importando correctamente
388
+ 3. Verifica que los breakpoints coincidan en `theme.extend.screens` y en el plugin
389
+ 4. Abre un issue en GitHub
390
+
391
+ ---
392
+
393
+ ## 🎯 Conclusión
394
+
395
+ **El sistema NO es invasivo** si usas solo el plugin (OPCIÓN 1).
396
+
397
+ **Es progresivamente más invasivo** si agregas hooks y layouts, pero siempre:
398
+ - ✅ Sin romper código existente
399
+ - ✅ Modular (usa solo lo que necesites)
400
+ - ✅ Fácil de remover si no te gusta
401
+
402
+ **Empieza con OPCIÓN 1, y escala según necesites.** 🚀
403
+