@r2digisolutions/components 0.25.14 → 0.25.16
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.
- package/README.md +19 -0
- package/dist/components/organisms/FileUploader/FileUploader.svelte +6 -5
- package/dist/styles.css +4 -311
- package/dist/theme.css +310 -0
- package/dist/vite.d.ts +30 -0
- package/dist/vite.js +172 -0
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -85,6 +85,25 @@ Los componentes usan clases de Tailwind 4. En la app consumidora basta con impor
|
|
|
85
85
|
|
|
86
86
|
Ese import registra tokens (`border-border`, `bg-surface`, …) y hace que Tailwind escanee los `.svelte` del paquete. Sin él, las utilidades pueden faltar o `--border` no estar definido.
|
|
87
87
|
|
|
88
|
+
#### CSS más pequeño en producción (opcional)
|
|
89
|
+
|
|
90
|
+
Por defecto Tailwind escanea **todos** los componentes del paquete, aunque la app use unos pocos. El plugin de Vite `componentSources()` hace que, en `vite build`, solo escanee los componentes que la app importa (y sus dependencias internas). El CSS de la app no cambia:
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
// vite.config.ts
|
|
94
|
+
import { componentSources } from '@r2digisolutions/components/vite';
|
|
95
|
+
import tailwindcss from '@tailwindcss/vite';
|
|
96
|
+
|
|
97
|
+
export default defineConfig({
|
|
98
|
+
plugins: [componentSources(), tailwindcss(), sveltekit()] // antes de tailwindcss()
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
- Lee los `import { … } from '@r2digisolutions/components'` de `src/` (cambia las carpetas con `componentSources({ dirs: ['src', 'otra'] })`).
|
|
103
|
+
- Si encuentra un import que no puede analizar (`import * as`, imports dinámicos o subrutas internas), avisa en el build y vuelve a escanear el paquete entero, así que nunca deja clases sin generar.
|
|
104
|
+
- En `vite dev` no hace nada: se escanea todo.
|
|
105
|
+
- Si solo quieres los tokens sin escanear nada: `@import '@r2digisolutions/components/theme.css';`.
|
|
106
|
+
|
|
88
107
|
## Tema: modo + paleta
|
|
89
108
|
|
|
90
109
|
Hay dos ejes independientes en `<html>`:
|
|
@@ -87,6 +87,8 @@
|
|
|
87
87
|
|
|
88
88
|
const labelId = $derived(`${id}-label`);
|
|
89
89
|
const helperId = $derived(`${id}-helper`);
|
|
90
|
+
// The visible dropzone text must be part of its accessible name (WCAG 2.5.3 Label in Name).
|
|
91
|
+
const dropzoneContentId = $derived(`${id}-dropzone-content`);
|
|
90
92
|
const errorId = $derived(`${id}-error`);
|
|
91
93
|
const maxBytes = $derived(maxSizeMb * 1024 * 1024);
|
|
92
94
|
|
|
@@ -318,10 +320,8 @@
|
|
|
318
320
|
<div
|
|
319
321
|
role="button"
|
|
320
322
|
tabindex={disabled ? -1 : 0}
|
|
321
|
-
aria-labelledby={resolvedLabel ? labelId :
|
|
322
|
-
aria-describedby={
|
|
323
|
-
.filter(Boolean)
|
|
324
|
-
.join(' ') || undefined}
|
|
323
|
+
aria-labelledby={resolvedLabel ? `${labelId} ${dropzoneContentId}` : dropzoneContentId}
|
|
324
|
+
aria-describedby={errorMessage ? errorId : undefined}
|
|
325
325
|
aria-disabled={disabled || undefined}
|
|
326
326
|
ondragenter={handleDragEnter}
|
|
327
327
|
ondragover={handleDragOver}
|
|
@@ -346,6 +346,7 @@
|
|
|
346
346
|
]}
|
|
347
347
|
>
|
|
348
348
|
<div
|
|
349
|
+
id={dropzoneContentId}
|
|
349
350
|
class={[
|
|
350
351
|
'flex',
|
|
351
352
|
vertical
|
|
@@ -398,7 +399,7 @@
|
|
|
398
399
|
{#if resolvedHelperText}
|
|
399
400
|
<p
|
|
400
401
|
id={helperId}
|
|
401
|
-
class={['mt-0.5 leading-relaxed text-secondary text-
|
|
402
|
+
class={['mt-0.5 leading-relaxed text-secondary text-xs', vertical && 'text-center']}
|
|
402
403
|
>
|
|
403
404
|
{resolvedHelperText}
|
|
404
405
|
</p>
|
package/dist/styles.css
CHANGED
|
@@ -1,314 +1,7 @@
|
|
|
1
|
+
/* Theme, base and utilities. Use `componentSources()` from `@r2digisolutions/components/vite`
|
|
2
|
+
to scan only the components an app imports instead of the whole package. */
|
|
3
|
+
@import './theme.css';
|
|
4
|
+
|
|
1
5
|
/* Scan this package so consumers only need to @import this file (no extra @source) */
|
|
2
6
|
@source './components/**/*.{svelte,js}';
|
|
3
7
|
@source './utils/**/*.{svelte,js}';
|
|
4
|
-
|
|
5
|
-
/* Match theme tokens (:root.dark) — not prefers-color-scheme alone */
|
|
6
|
-
@custom-variant dark (&:where(.dark, .dark *));
|
|
7
|
-
|
|
8
|
-
/* ─────────────────────────────────────────────────────────────────────────────
|
|
9
|
-
R2DigiSolutions Design System — Tailwind 4 @theme
|
|
10
|
-
─────────────────────────────────────────────────────────────────────────── */
|
|
11
|
-
|
|
12
|
-
@theme {
|
|
13
|
-
/* Brand colors */
|
|
14
|
-
--color-brand-50: oklch(97% 0.02 265);
|
|
15
|
-
--color-brand-100: oklch(93% 0.05 265);
|
|
16
|
-
--color-brand-200: oklch(86% 0.1 265);
|
|
17
|
-
--color-brand-300: oklch(76% 0.15 265);
|
|
18
|
-
--color-brand-400: oklch(65% 0.2 265);
|
|
19
|
-
--color-brand-500: oklch(55% 0.25 265);
|
|
20
|
-
--color-brand-600: oklch(47% 0.26 265);
|
|
21
|
-
--color-brand-700: oklch(39% 0.24 265);
|
|
22
|
-
--color-brand-800: oklch(31% 0.2 265);
|
|
23
|
-
--color-brand-900: oklch(22% 0.14 265);
|
|
24
|
-
--color-brand-950: oklch(15% 0.08 265);
|
|
25
|
-
|
|
26
|
-
/* Semantic surface tokens */
|
|
27
|
-
--color-surface: var(--surface);
|
|
28
|
-
--color-surface-elevated: var(--surface-elevated);
|
|
29
|
-
--color-surface-overlay: var(--surface-overlay);
|
|
30
|
-
--color-border: var(--border);
|
|
31
|
-
--color-border-strong: var(--border-strong);
|
|
32
|
-
--color-text-primary: var(--text-primary);
|
|
33
|
-
--color-text-secondary: var(--text-secondary);
|
|
34
|
-
--color-text-muted: var(--text-muted);
|
|
35
|
-
--color-text-inverse: var(--text-inverse);
|
|
36
|
-
|
|
37
|
-
/* Typography */
|
|
38
|
-
--font-sans: 'Inter', ui-sans-serif, system-ui, sans-serif;
|
|
39
|
-
--font-mono: 'JetBrains Mono', ui-monospace, monospace;
|
|
40
|
-
|
|
41
|
-
/* Radii */
|
|
42
|
-
--radius-sm: 0.375rem;
|
|
43
|
-
--radius-md: 0.5rem;
|
|
44
|
-
--radius-lg: 0.75rem;
|
|
45
|
-
--radius-xl: 1rem;
|
|
46
|
-
--radius-2xl: 1.5rem;
|
|
47
|
-
--radius-full: 9999px;
|
|
48
|
-
|
|
49
|
-
/* Shadows */
|
|
50
|
-
--shadow-sm: 0 1px 3px 0 oklch(0% 0 0 / 0.08), 0 1px 2px -1px oklch(0% 0 0 / 0.06);
|
|
51
|
-
--shadow-md: 0 4px 6px -1px oklch(0% 0 0 / 0.1), 0 2px 4px -2px oklch(0% 0 0 / 0.08);
|
|
52
|
-
--shadow-lg: 0 10px 15px -3px oklch(0% 0 0 / 0.12), 0 4px 6px -4px oklch(0% 0 0 / 0.08);
|
|
53
|
-
--shadow-xl: 0 20px 25px -5px oklch(0% 0 0 / 0.14), 0 8px 10px -6px oklch(0% 0 0 / 0.08);
|
|
54
|
-
|
|
55
|
-
/* Transitions */
|
|
56
|
-
--ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
|
|
57
|
-
--ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/* ─────────────────────────────────────────────────────────────────────────────
|
|
61
|
-
Gray palette — <html data-theme="slate" | "neutral">
|
|
62
|
-
slate (default): cool indigo cast (hue 265)
|
|
63
|
-
neutral: chroma 0, same family as Tailwind `neutral`
|
|
64
|
-
─────────────────────────────────────────────────────────────────────────── */
|
|
65
|
-
|
|
66
|
-
:root {
|
|
67
|
-
--r2-gray-h: 265;
|
|
68
|
-
--r2-gray-c: 0.02;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
:root[data-theme='slate'] {
|
|
72
|
-
--r2-gray-h: 265;
|
|
73
|
-
--r2-gray-c: 0.02;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
:root[data-theme='neutral'] {
|
|
77
|
-
--r2-gray-h: 0;
|
|
78
|
-
--r2-gray-c: 0;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/* ─────────────────────────────────────────────────────────────────────────────
|
|
82
|
-
Light mode (default)
|
|
83
|
-
─────────────────────────────────────────────────────────────────────────── */
|
|
84
|
-
|
|
85
|
-
:root {
|
|
86
|
-
color-scheme: light;
|
|
87
|
-
|
|
88
|
-
--surface: oklch(99% calc(var(--r2-gray-c) * 0.25) var(--r2-gray-h));
|
|
89
|
-
--surface-elevated: oklch(100% 0 0);
|
|
90
|
-
--surface-overlay: oklch(97% calc(var(--r2-gray-c) * 0.5) var(--r2-gray-h));
|
|
91
|
-
--border: oklch(88% var(--r2-gray-c) var(--r2-gray-h));
|
|
92
|
-
--border-strong: oklch(75% calc(var(--r2-gray-c) * 2) var(--r2-gray-h));
|
|
93
|
-
--text-primary: oklch(15% var(--r2-gray-c) var(--r2-gray-h));
|
|
94
|
-
--text-secondary: oklch(35% calc(var(--r2-gray-c) * 1.5) var(--r2-gray-h));
|
|
95
|
-
--text-muted: oklch(45% var(--r2-gray-c) var(--r2-gray-h));
|
|
96
|
-
--text-inverse: oklch(99% 0 0);
|
|
97
|
-
|
|
98
|
-
/* Alert tones */
|
|
99
|
-
--alert-info-bg: oklch(96% 0.03 240);
|
|
100
|
-
--alert-info-border: oklch(82% 0.06 240);
|
|
101
|
-
--alert-info-fg: oklch(28% 0.08 240);
|
|
102
|
-
--alert-info-muted: oklch(40% 0.06 240);
|
|
103
|
-
--alert-info-icon: oklch(52% 0.14 240);
|
|
104
|
-
--alert-info-accent: oklch(55% 0.16 240);
|
|
105
|
-
|
|
106
|
-
--alert-success-bg: oklch(96% 0.04 150);
|
|
107
|
-
--alert-success-border: oklch(82% 0.07 150);
|
|
108
|
-
--alert-success-fg: oklch(28% 0.08 150);
|
|
109
|
-
--alert-success-muted: oklch(38% 0.06 150);
|
|
110
|
-
--alert-success-icon: oklch(50% 0.14 150);
|
|
111
|
-
--alert-success-accent: oklch(55% 0.16 150);
|
|
112
|
-
|
|
113
|
-
--alert-warning-bg: oklch(96% 0.05 85);
|
|
114
|
-
--alert-warning-border: oklch(84% 0.1 85);
|
|
115
|
-
--alert-warning-fg: oklch(30% 0.08 75);
|
|
116
|
-
--alert-warning-muted: oklch(42% 0.07 75);
|
|
117
|
-
--alert-warning-icon: oklch(58% 0.15 75);
|
|
118
|
-
--alert-warning-accent: oklch(68% 0.16 75);
|
|
119
|
-
|
|
120
|
-
--alert-error-bg: oklch(96% 0.03 25);
|
|
121
|
-
--alert-error-border: oklch(84% 0.08 25);
|
|
122
|
-
--alert-error-fg: oklch(30% 0.1 25);
|
|
123
|
-
--alert-error-muted: oklch(42% 0.08 25);
|
|
124
|
-
--alert-error-icon: oklch(55% 0.18 25);
|
|
125
|
-
--alert-error-accent: oklch(58% 0.2 25);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/* ─────────────────────────────────────────────────────────────────────────────
|
|
129
|
-
Dark mode
|
|
130
|
-
─────────────────────────────────────────────────────────────────────────── */
|
|
131
|
-
|
|
132
|
-
:root.dark {
|
|
133
|
-
color-scheme: dark;
|
|
134
|
-
|
|
135
|
-
--surface: oklch(14% var(--r2-gray-c) var(--r2-gray-h));
|
|
136
|
-
--surface-elevated: oklch(18% calc(var(--r2-gray-c) * 1.25) var(--r2-gray-h));
|
|
137
|
-
--surface-overlay: oklch(20% calc(var(--r2-gray-c) * 1.5) var(--r2-gray-h));
|
|
138
|
-
--border: oklch(28% calc(var(--r2-gray-c) * 1.5) var(--r2-gray-h));
|
|
139
|
-
--border-strong: oklch(40% calc(var(--r2-gray-c) * 2) var(--r2-gray-h));
|
|
140
|
-
--text-primary: oklch(96% calc(var(--r2-gray-c) * 0.5) var(--r2-gray-h));
|
|
141
|
-
--text-secondary: oklch(75% calc(var(--r2-gray-c) * 1.5) var(--r2-gray-h));
|
|
142
|
-
--text-muted: oklch(72% calc(var(--r2-gray-c) * 1.5) var(--r2-gray-h));
|
|
143
|
-
--text-inverse: oklch(15% var(--r2-gray-c) var(--r2-gray-h));
|
|
144
|
-
|
|
145
|
-
/* Alert tones */
|
|
146
|
-
--alert-info-bg: oklch(24% 0.04 240);
|
|
147
|
-
--alert-info-border: oklch(38% 0.06 240);
|
|
148
|
-
--alert-info-fg: oklch(92% 0.03 240);
|
|
149
|
-
--alert-info-muted: oklch(78% 0.04 240);
|
|
150
|
-
--alert-info-icon: oklch(72% 0.12 240);
|
|
151
|
-
--alert-info-accent: oklch(65% 0.14 240);
|
|
152
|
-
|
|
153
|
-
--alert-success-bg: oklch(24% 0.04 150);
|
|
154
|
-
--alert-success-border: oklch(38% 0.06 150);
|
|
155
|
-
--alert-success-fg: oklch(92% 0.03 150);
|
|
156
|
-
--alert-success-muted: oklch(78% 0.04 150);
|
|
157
|
-
--alert-success-icon: oklch(72% 0.12 150);
|
|
158
|
-
--alert-success-accent: oklch(65% 0.14 150);
|
|
159
|
-
|
|
160
|
-
--alert-warning-bg: oklch(25% 0.04 85);
|
|
161
|
-
--alert-warning-border: oklch(40% 0.07 85);
|
|
162
|
-
--alert-warning-fg: oklch(93% 0.03 85);
|
|
163
|
-
--alert-warning-muted: oklch(80% 0.04 85);
|
|
164
|
-
--alert-warning-icon: oklch(78% 0.12 85);
|
|
165
|
-
--alert-warning-accent: oklch(72% 0.14 85);
|
|
166
|
-
|
|
167
|
-
--alert-error-bg: oklch(24% 0.05 25);
|
|
168
|
-
--alert-error-border: oklch(40% 0.08 25);
|
|
169
|
-
--alert-error-fg: oklch(93% 0.03 25);
|
|
170
|
-
--alert-error-muted: oklch(80% 0.04 25);
|
|
171
|
-
--alert-error-icon: oklch(72% 0.14 25);
|
|
172
|
-
--alert-error-accent: oklch(65% 0.18 25);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/* ─────────────────────────────────────────────────────────────────────────────
|
|
176
|
-
Base styles
|
|
177
|
-
─────────────────────────────────────────────────────────────────────────── */
|
|
178
|
-
|
|
179
|
-
@layer base {
|
|
180
|
-
*,
|
|
181
|
-
*::before,
|
|
182
|
-
*::after {
|
|
183
|
-
box-sizing: border-box;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
html {
|
|
187
|
-
-webkit-text-size-adjust: 100%;
|
|
188
|
-
-webkit-font-smoothing: antialiased;
|
|
189
|
-
-moz-osx-font-smoothing: grayscale;
|
|
190
|
-
scroll-behavior: smooth;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
body {
|
|
194
|
-
margin: 0;
|
|
195
|
-
background-color: var(--surface);
|
|
196
|
-
color: var(--text-primary);
|
|
197
|
-
font-family: var(--font-sans);
|
|
198
|
-
line-height: 1.6;
|
|
199
|
-
transition:
|
|
200
|
-
background-color 0.2s var(--ease-smooth),
|
|
201
|
-
color 0.2s var(--ease-smooth);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/* Focus visible styles */
|
|
205
|
-
:focus-visible {
|
|
206
|
-
outline: 2px solid oklch(55% 0.25 265);
|
|
207
|
-
outline-offset: 2px;
|
|
208
|
-
border-radius: var(--radius-sm);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/* Selection */
|
|
212
|
-
::selection {
|
|
213
|
-
background-color: oklch(55% 0.25 265 / 0.25);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/* ─────────────────────────────────────────────────────────────────────────────
|
|
218
|
-
Utility layer
|
|
219
|
-
─────────────────────────────────────────────────────────────────────────── */
|
|
220
|
-
|
|
221
|
-
@layer utilities {
|
|
222
|
-
/* Touch-friendly minimum tap target */
|
|
223
|
-
.touch-target {
|
|
224
|
-
min-height: 44px;
|
|
225
|
-
min-width: 44px;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/* Smooth transitions */
|
|
229
|
-
.transition-smooth {
|
|
230
|
-
transition: all 0.2s var(--ease-smooth);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
.transition-spring {
|
|
234
|
-
transition: all 0.3s var(--ease-spring);
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
/* Glass morphism */
|
|
238
|
-
.glass {
|
|
239
|
-
backdrop-filter: blur(12px) saturate(180%);
|
|
240
|
-
background-color: oklch(100% 0 0 / 0.08);
|
|
241
|
-
border: 1px solid oklch(100% 0 0 / 0.12);
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
.dark .glass {
|
|
245
|
-
background-color: oklch(0% 0 0 / 0.2);
|
|
246
|
-
border-color: oklch(100% 0 0 / 0.08);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/* Surface utilities */
|
|
250
|
-
.bg-surface {
|
|
251
|
-
background-color: var(--surface);
|
|
252
|
-
}
|
|
253
|
-
.bg-surface-elevated {
|
|
254
|
-
background-color: var(--surface-elevated);
|
|
255
|
-
}
|
|
256
|
-
.bg-surface-overlay {
|
|
257
|
-
background-color: var(--surface-overlay);
|
|
258
|
-
}
|
|
259
|
-
.border-surface {
|
|
260
|
-
border-color: var(--surface);
|
|
261
|
-
}
|
|
262
|
-
.border-surface-elevated {
|
|
263
|
-
border-color: var(--surface-elevated);
|
|
264
|
-
}
|
|
265
|
-
.border-surface-overlay {
|
|
266
|
-
border-color: var(--surface-overlay);
|
|
267
|
-
}
|
|
268
|
-
.border-border {
|
|
269
|
-
border-color: var(--border);
|
|
270
|
-
}
|
|
271
|
-
.border-border-strong {
|
|
272
|
-
border-color: var(--border-strong);
|
|
273
|
-
}
|
|
274
|
-
.text-primary {
|
|
275
|
-
color: var(--text-primary);
|
|
276
|
-
}
|
|
277
|
-
.text-secondary {
|
|
278
|
-
color: var(--text-secondary);
|
|
279
|
-
}
|
|
280
|
-
.text-muted {
|
|
281
|
-
color: var(--text-muted);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
/* SVG chart labels — Tailwind fill-* needs these (text-* alone does not paint <text>) */
|
|
285
|
-
.fill-primary {
|
|
286
|
-
fill: var(--text-primary);
|
|
287
|
-
}
|
|
288
|
-
.fill-secondary {
|
|
289
|
-
fill: var(--text-secondary);
|
|
290
|
-
}
|
|
291
|
-
.fill-muted {
|
|
292
|
-
fill: var(--text-muted);
|
|
293
|
-
}
|
|
294
|
-
.stroke-border {
|
|
295
|
-
stroke: var(--border);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
/* Autocompletado del navegador: sin esto pinta un bloque gris/amarillo
|
|
300
|
-
que no sigue la superficie del campo. */
|
|
301
|
-
input:-webkit-autofill,
|
|
302
|
-
input:-webkit-autofill:hover,
|
|
303
|
-
input:-webkit-autofill:focus,
|
|
304
|
-
textarea:-webkit-autofill,
|
|
305
|
-
textarea:-webkit-autofill:hover,
|
|
306
|
-
textarea:-webkit-autofill:focus,
|
|
307
|
-
select:-webkit-autofill,
|
|
308
|
-
select:-webkit-autofill:hover,
|
|
309
|
-
select:-webkit-autofill:focus {
|
|
310
|
-
-webkit-text-fill-color: var(--text-primary);
|
|
311
|
-
caret-color: var(--text-primary);
|
|
312
|
-
box-shadow: inset 0 0 0 1000px var(--surface-elevated);
|
|
313
|
-
transition: background-color 99999s ease-out;
|
|
314
|
-
}
|
package/dist/theme.css
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
/* Match theme tokens (:root.dark) — not prefers-color-scheme alone */
|
|
2
|
+
@custom-variant dark (&:where(.dark, .dark *));
|
|
3
|
+
|
|
4
|
+
/* ─────────────────────────────────────────────────────────────────────────────
|
|
5
|
+
R2DigiSolutions Design System — Tailwind 4 @theme
|
|
6
|
+
─────────────────────────────────────────────────────────────────────────── */
|
|
7
|
+
|
|
8
|
+
@theme {
|
|
9
|
+
/* Brand colors */
|
|
10
|
+
--color-brand-50: oklch(97% 0.02 265);
|
|
11
|
+
--color-brand-100: oklch(93% 0.05 265);
|
|
12
|
+
--color-brand-200: oklch(86% 0.1 265);
|
|
13
|
+
--color-brand-300: oklch(76% 0.15 265);
|
|
14
|
+
--color-brand-400: oklch(65% 0.2 265);
|
|
15
|
+
--color-brand-500: oklch(55% 0.25 265);
|
|
16
|
+
--color-brand-600: oklch(47% 0.26 265);
|
|
17
|
+
--color-brand-700: oklch(39% 0.24 265);
|
|
18
|
+
--color-brand-800: oklch(31% 0.2 265);
|
|
19
|
+
--color-brand-900: oklch(22% 0.14 265);
|
|
20
|
+
--color-brand-950: oklch(15% 0.08 265);
|
|
21
|
+
|
|
22
|
+
/* Semantic surface tokens */
|
|
23
|
+
--color-surface: var(--surface);
|
|
24
|
+
--color-surface-elevated: var(--surface-elevated);
|
|
25
|
+
--color-surface-overlay: var(--surface-overlay);
|
|
26
|
+
--color-border: var(--border);
|
|
27
|
+
--color-border-strong: var(--border-strong);
|
|
28
|
+
--color-text-primary: var(--text-primary);
|
|
29
|
+
--color-text-secondary: var(--text-secondary);
|
|
30
|
+
--color-text-muted: var(--text-muted);
|
|
31
|
+
--color-text-inverse: var(--text-inverse);
|
|
32
|
+
|
|
33
|
+
/* Typography */
|
|
34
|
+
--font-sans: 'Inter', ui-sans-serif, system-ui, sans-serif;
|
|
35
|
+
--font-mono: 'JetBrains Mono', ui-monospace, monospace;
|
|
36
|
+
|
|
37
|
+
/* Radii */
|
|
38
|
+
--radius-sm: 0.375rem;
|
|
39
|
+
--radius-md: 0.5rem;
|
|
40
|
+
--radius-lg: 0.75rem;
|
|
41
|
+
--radius-xl: 1rem;
|
|
42
|
+
--radius-2xl: 1.5rem;
|
|
43
|
+
--radius-full: 9999px;
|
|
44
|
+
|
|
45
|
+
/* Shadows */
|
|
46
|
+
--shadow-sm: 0 1px 3px 0 oklch(0% 0 0 / 0.08), 0 1px 2px -1px oklch(0% 0 0 / 0.06);
|
|
47
|
+
--shadow-md: 0 4px 6px -1px oklch(0% 0 0 / 0.1), 0 2px 4px -2px oklch(0% 0 0 / 0.08);
|
|
48
|
+
--shadow-lg: 0 10px 15px -3px oklch(0% 0 0 / 0.12), 0 4px 6px -4px oklch(0% 0 0 / 0.08);
|
|
49
|
+
--shadow-xl: 0 20px 25px -5px oklch(0% 0 0 / 0.14), 0 8px 10px -6px oklch(0% 0 0 / 0.08);
|
|
50
|
+
|
|
51
|
+
/* Transitions */
|
|
52
|
+
--ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
|
|
53
|
+
--ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/* ─────────────────────────────────────────────────────────────────────────────
|
|
57
|
+
Gray palette — <html data-theme="slate" | "neutral">
|
|
58
|
+
slate (default): cool indigo cast (hue 265)
|
|
59
|
+
neutral: chroma 0, same family as Tailwind `neutral`
|
|
60
|
+
─────────────────────────────────────────────────────────────────────────── */
|
|
61
|
+
|
|
62
|
+
:root {
|
|
63
|
+
--r2-gray-h: 265;
|
|
64
|
+
--r2-gray-c: 0.02;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
:root[data-theme='slate'] {
|
|
68
|
+
--r2-gray-h: 265;
|
|
69
|
+
--r2-gray-c: 0.02;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
:root[data-theme='neutral'] {
|
|
73
|
+
--r2-gray-h: 0;
|
|
74
|
+
--r2-gray-c: 0;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/* ─────────────────────────────────────────────────────────────────────────────
|
|
78
|
+
Light mode (default)
|
|
79
|
+
─────────────────────────────────────────────────────────────────────────── */
|
|
80
|
+
|
|
81
|
+
:root {
|
|
82
|
+
color-scheme: light;
|
|
83
|
+
|
|
84
|
+
--surface: oklch(99% calc(var(--r2-gray-c) * 0.25) var(--r2-gray-h));
|
|
85
|
+
--surface-elevated: oklch(100% 0 0);
|
|
86
|
+
--surface-overlay: oklch(97% calc(var(--r2-gray-c) * 0.5) var(--r2-gray-h));
|
|
87
|
+
--border: oklch(88% var(--r2-gray-c) var(--r2-gray-h));
|
|
88
|
+
--border-strong: oklch(75% calc(var(--r2-gray-c) * 2) var(--r2-gray-h));
|
|
89
|
+
--text-primary: oklch(15% var(--r2-gray-c) var(--r2-gray-h));
|
|
90
|
+
--text-secondary: oklch(35% calc(var(--r2-gray-c) * 1.5) var(--r2-gray-h));
|
|
91
|
+
--text-muted: oklch(45% var(--r2-gray-c) var(--r2-gray-h));
|
|
92
|
+
--text-inverse: oklch(99% 0 0);
|
|
93
|
+
|
|
94
|
+
/* Alert tones */
|
|
95
|
+
--alert-info-bg: oklch(96% 0.03 240);
|
|
96
|
+
--alert-info-border: oklch(82% 0.06 240);
|
|
97
|
+
--alert-info-fg: oklch(28% 0.08 240);
|
|
98
|
+
--alert-info-muted: oklch(40% 0.06 240);
|
|
99
|
+
--alert-info-icon: oklch(52% 0.14 240);
|
|
100
|
+
--alert-info-accent: oklch(55% 0.16 240);
|
|
101
|
+
|
|
102
|
+
--alert-success-bg: oklch(96% 0.04 150);
|
|
103
|
+
--alert-success-border: oklch(82% 0.07 150);
|
|
104
|
+
--alert-success-fg: oklch(28% 0.08 150);
|
|
105
|
+
--alert-success-muted: oklch(38% 0.06 150);
|
|
106
|
+
--alert-success-icon: oklch(50% 0.14 150);
|
|
107
|
+
--alert-success-accent: oklch(55% 0.16 150);
|
|
108
|
+
|
|
109
|
+
--alert-warning-bg: oklch(96% 0.05 85);
|
|
110
|
+
--alert-warning-border: oklch(84% 0.1 85);
|
|
111
|
+
--alert-warning-fg: oklch(30% 0.08 75);
|
|
112
|
+
--alert-warning-muted: oklch(42% 0.07 75);
|
|
113
|
+
--alert-warning-icon: oklch(58% 0.15 75);
|
|
114
|
+
--alert-warning-accent: oklch(68% 0.16 75);
|
|
115
|
+
|
|
116
|
+
--alert-error-bg: oklch(96% 0.03 25);
|
|
117
|
+
--alert-error-border: oklch(84% 0.08 25);
|
|
118
|
+
--alert-error-fg: oklch(30% 0.1 25);
|
|
119
|
+
--alert-error-muted: oklch(42% 0.08 25);
|
|
120
|
+
--alert-error-icon: oklch(55% 0.18 25);
|
|
121
|
+
--alert-error-accent: oklch(58% 0.2 25);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/* ─────────────────────────────────────────────────────────────────────────────
|
|
125
|
+
Dark mode
|
|
126
|
+
─────────────────────────────────────────────────────────────────────────── */
|
|
127
|
+
|
|
128
|
+
:root.dark {
|
|
129
|
+
color-scheme: dark;
|
|
130
|
+
|
|
131
|
+
--surface: oklch(14% var(--r2-gray-c) var(--r2-gray-h));
|
|
132
|
+
--surface-elevated: oklch(18% calc(var(--r2-gray-c) * 1.25) var(--r2-gray-h));
|
|
133
|
+
--surface-overlay: oklch(20% calc(var(--r2-gray-c) * 1.5) var(--r2-gray-h));
|
|
134
|
+
--border: oklch(28% calc(var(--r2-gray-c) * 1.5) var(--r2-gray-h));
|
|
135
|
+
--border-strong: oklch(40% calc(var(--r2-gray-c) * 2) var(--r2-gray-h));
|
|
136
|
+
--text-primary: oklch(96% calc(var(--r2-gray-c) * 0.5) var(--r2-gray-h));
|
|
137
|
+
--text-secondary: oklch(75% calc(var(--r2-gray-c) * 1.5) var(--r2-gray-h));
|
|
138
|
+
--text-muted: oklch(72% calc(var(--r2-gray-c) * 1.5) var(--r2-gray-h));
|
|
139
|
+
--text-inverse: oklch(15% var(--r2-gray-c) var(--r2-gray-h));
|
|
140
|
+
|
|
141
|
+
/* Alert tones */
|
|
142
|
+
--alert-info-bg: oklch(24% 0.04 240);
|
|
143
|
+
--alert-info-border: oklch(38% 0.06 240);
|
|
144
|
+
--alert-info-fg: oklch(92% 0.03 240);
|
|
145
|
+
--alert-info-muted: oklch(78% 0.04 240);
|
|
146
|
+
--alert-info-icon: oklch(72% 0.12 240);
|
|
147
|
+
--alert-info-accent: oklch(65% 0.14 240);
|
|
148
|
+
|
|
149
|
+
--alert-success-bg: oklch(24% 0.04 150);
|
|
150
|
+
--alert-success-border: oklch(38% 0.06 150);
|
|
151
|
+
--alert-success-fg: oklch(92% 0.03 150);
|
|
152
|
+
--alert-success-muted: oklch(78% 0.04 150);
|
|
153
|
+
--alert-success-icon: oklch(72% 0.12 150);
|
|
154
|
+
--alert-success-accent: oklch(65% 0.14 150);
|
|
155
|
+
|
|
156
|
+
--alert-warning-bg: oklch(25% 0.04 85);
|
|
157
|
+
--alert-warning-border: oklch(40% 0.07 85);
|
|
158
|
+
--alert-warning-fg: oklch(93% 0.03 85);
|
|
159
|
+
--alert-warning-muted: oklch(80% 0.04 85);
|
|
160
|
+
--alert-warning-icon: oklch(78% 0.12 85);
|
|
161
|
+
--alert-warning-accent: oklch(72% 0.14 85);
|
|
162
|
+
|
|
163
|
+
--alert-error-bg: oklch(24% 0.05 25);
|
|
164
|
+
--alert-error-border: oklch(40% 0.08 25);
|
|
165
|
+
--alert-error-fg: oklch(93% 0.03 25);
|
|
166
|
+
--alert-error-muted: oklch(80% 0.04 25);
|
|
167
|
+
--alert-error-icon: oklch(72% 0.14 25);
|
|
168
|
+
--alert-error-accent: oklch(65% 0.18 25);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/* ─────────────────────────────────────────────────────────────────────────────
|
|
172
|
+
Base styles
|
|
173
|
+
─────────────────────────────────────────────────────────────────────────── */
|
|
174
|
+
|
|
175
|
+
@layer base {
|
|
176
|
+
*,
|
|
177
|
+
*::before,
|
|
178
|
+
*::after {
|
|
179
|
+
box-sizing: border-box;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
html {
|
|
183
|
+
-webkit-text-size-adjust: 100%;
|
|
184
|
+
-webkit-font-smoothing: antialiased;
|
|
185
|
+
-moz-osx-font-smoothing: grayscale;
|
|
186
|
+
scroll-behavior: smooth;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
body {
|
|
190
|
+
margin: 0;
|
|
191
|
+
background-color: var(--surface);
|
|
192
|
+
color: var(--text-primary);
|
|
193
|
+
font-family: var(--font-sans);
|
|
194
|
+
line-height: 1.6;
|
|
195
|
+
transition:
|
|
196
|
+
background-color 0.2s var(--ease-smooth),
|
|
197
|
+
color 0.2s var(--ease-smooth);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/* Focus visible styles */
|
|
201
|
+
:focus-visible {
|
|
202
|
+
outline: 2px solid oklch(55% 0.25 265);
|
|
203
|
+
outline-offset: 2px;
|
|
204
|
+
border-radius: var(--radius-sm);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/* Selection */
|
|
208
|
+
::selection {
|
|
209
|
+
background-color: oklch(55% 0.25 265 / 0.25);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/* ─────────────────────────────────────────────────────────────────────────────
|
|
214
|
+
Utility layer
|
|
215
|
+
─────────────────────────────────────────────────────────────────────────── */
|
|
216
|
+
|
|
217
|
+
@layer utilities {
|
|
218
|
+
/* Touch-friendly minimum tap target */
|
|
219
|
+
.touch-target {
|
|
220
|
+
min-height: 44px;
|
|
221
|
+
min-width: 44px;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/* Smooth transitions */
|
|
225
|
+
.transition-smooth {
|
|
226
|
+
transition: all 0.2s var(--ease-smooth);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
.transition-spring {
|
|
230
|
+
transition: all 0.3s var(--ease-spring);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/* Glass morphism */
|
|
234
|
+
.glass {
|
|
235
|
+
backdrop-filter: blur(12px) saturate(180%);
|
|
236
|
+
background-color: oklch(100% 0 0 / 0.08);
|
|
237
|
+
border: 1px solid oklch(100% 0 0 / 0.12);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
.dark .glass {
|
|
241
|
+
background-color: oklch(0% 0 0 / 0.2);
|
|
242
|
+
border-color: oklch(100% 0 0 / 0.08);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/* Surface utilities */
|
|
246
|
+
.bg-surface {
|
|
247
|
+
background-color: var(--surface);
|
|
248
|
+
}
|
|
249
|
+
.bg-surface-elevated {
|
|
250
|
+
background-color: var(--surface-elevated);
|
|
251
|
+
}
|
|
252
|
+
.bg-surface-overlay {
|
|
253
|
+
background-color: var(--surface-overlay);
|
|
254
|
+
}
|
|
255
|
+
.border-surface {
|
|
256
|
+
border-color: var(--surface);
|
|
257
|
+
}
|
|
258
|
+
.border-surface-elevated {
|
|
259
|
+
border-color: var(--surface-elevated);
|
|
260
|
+
}
|
|
261
|
+
.border-surface-overlay {
|
|
262
|
+
border-color: var(--surface-overlay);
|
|
263
|
+
}
|
|
264
|
+
.border-border {
|
|
265
|
+
border-color: var(--border);
|
|
266
|
+
}
|
|
267
|
+
.border-border-strong {
|
|
268
|
+
border-color: var(--border-strong);
|
|
269
|
+
}
|
|
270
|
+
.text-primary {
|
|
271
|
+
color: var(--text-primary);
|
|
272
|
+
}
|
|
273
|
+
.text-secondary {
|
|
274
|
+
color: var(--text-secondary);
|
|
275
|
+
}
|
|
276
|
+
.text-muted {
|
|
277
|
+
color: var(--text-muted);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/* SVG chart labels — Tailwind fill-* needs these (text-* alone does not paint <text>) */
|
|
281
|
+
.fill-primary {
|
|
282
|
+
fill: var(--text-primary);
|
|
283
|
+
}
|
|
284
|
+
.fill-secondary {
|
|
285
|
+
fill: var(--text-secondary);
|
|
286
|
+
}
|
|
287
|
+
.fill-muted {
|
|
288
|
+
fill: var(--text-muted);
|
|
289
|
+
}
|
|
290
|
+
.stroke-border {
|
|
291
|
+
stroke: var(--border);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/* Autocompletado del navegador: sin esto pinta un bloque gris/amarillo
|
|
296
|
+
que no sigue la superficie del campo. */
|
|
297
|
+
input:-webkit-autofill,
|
|
298
|
+
input:-webkit-autofill:hover,
|
|
299
|
+
input:-webkit-autofill:focus,
|
|
300
|
+
textarea:-webkit-autofill,
|
|
301
|
+
textarea:-webkit-autofill:hover,
|
|
302
|
+
textarea:-webkit-autofill:focus,
|
|
303
|
+
select:-webkit-autofill,
|
|
304
|
+
select:-webkit-autofill:hover,
|
|
305
|
+
select:-webkit-autofill:focus {
|
|
306
|
+
-webkit-text-fill-color: var(--text-primary);
|
|
307
|
+
caret-color: var(--text-primary);
|
|
308
|
+
box-shadow: inset 0 0 0 1000px var(--surface-elevated);
|
|
309
|
+
transition: background-color 99999s ease-out;
|
|
310
|
+
}
|
package/dist/vite.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
export type ComponentSourcesResult = {
|
|
3
|
+
files: string[];
|
|
4
|
+
} | {
|
|
5
|
+
reason: string;
|
|
6
|
+
};
|
|
7
|
+
export interface ComponentSourcesOptions {
|
|
8
|
+
/** Directories, relative to the Vite root, holding the code that imports components. Default `['src']`. */
|
|
9
|
+
dirs?: string[];
|
|
10
|
+
}
|
|
11
|
+
/** Component names a source file imports from the package, or why that can't be known statically. */
|
|
12
|
+
export declare function packageUsage(code: string): {
|
|
13
|
+
names: string[];
|
|
14
|
+
} | {
|
|
15
|
+
reason: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Library files (`.svelte`/`.js`) reachable from the components the given app files import.
|
|
19
|
+
* Returns a reason instead when usage can't be determined, so callers keep scanning the whole package.
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolveComponentSources(appFiles: Iterable<string>, packageDir: string): ComponentSourcesResult;
|
|
22
|
+
/** Swaps the whole-package stylesheet for the theme plus one `@source` per used library file. */
|
|
23
|
+
export declare function scopeStylesImport(css: string, files: string[]): string | null;
|
|
24
|
+
/**
|
|
25
|
+
* Production builds only: Tailwind scans just the library components the app imports (and their
|
|
26
|
+
* dependencies) instead of all of them, which shrinks the generated CSS. The app keeps
|
|
27
|
+
* `@import '@r2digisolutions/components/styles.css';`; place this plugin before `tailwindcss()`.
|
|
28
|
+
* If an import can't be analysed statically it falls back to scanning the whole package.
|
|
29
|
+
*/
|
|
30
|
+
export declare function componentSources(options?: ComponentSourcesOptions): Plugin;
|
package/dist/vite.js
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
const PACKAGE = '@r2digisolutions/components';
|
|
5
|
+
const PLUGIN_NAME = 'r2digisolutions:component-sources';
|
|
6
|
+
const STYLES_IMPORT = /@import\s+(['"])@r2digisolutions\/components\/styles\.css\1\s*;/;
|
|
7
|
+
const APP_FILE = /\.(?:svelte|[cm]?[jt]sx?)$/;
|
|
8
|
+
const LIBRARY_FILE = /\.(?:svelte|js)$/;
|
|
9
|
+
/** Subpaths that carry no components (stylesheets and this plugin). */
|
|
10
|
+
const NEUTRAL_SUBPATHS = new Set(['styles.css', 'theme.css', 'vite']);
|
|
11
|
+
const PACKAGE_IMPORT = /\b(import|export)\s+(type\s+)?((?:[\w$]+\s*,\s*)?\{[^}]*\}|\*(?:\s*as\s+[\w$]+)?|[\w$]+)\s*from\s*(['"])@r2digisolutions\/components(?:\/([^'"]+))?\4/g;
|
|
12
|
+
const DYNAMIC_PACKAGE_IMPORT = /\bimport\s*\(\s*(['"])@r2digisolutions\/components(?:\/([^'"]*))?\1/g;
|
|
13
|
+
const SIDE_EFFECT_PACKAGE_IMPORT = /\bimport\s*(['"])@r2digisolutions\/components(?:\/([^'"]*))?\1/g;
|
|
14
|
+
const INDEX_REEXPORT = /export\s+(type\s+)?\{([^}]*)\}\s*from\s*['"]([^'"]+)['"]/g;
|
|
15
|
+
const INDEX_DECLARATION = /export\s+(?:async\s+)?(?:const|let|var|function\*?|class)\s+([A-Za-z_$][\w$]*)/g;
|
|
16
|
+
const RELATIVE_IMPORT = /(?:\bfrom\s*|\bimport\s*\(?\s*)(['"])(\.{1,2}\/[^'"]+)\1/g;
|
|
17
|
+
function importedNames(clause) {
|
|
18
|
+
const named = /^\{([^}]*)\}$/.exec(clause.trim());
|
|
19
|
+
if (!named)
|
|
20
|
+
return null;
|
|
21
|
+
return named[1]
|
|
22
|
+
.split(',')
|
|
23
|
+
.map((part) => part.trim())
|
|
24
|
+
.filter((part) => part && !part.startsWith('type '))
|
|
25
|
+
.map((part) => part.split(/\s+as\s+/)[0].trim());
|
|
26
|
+
}
|
|
27
|
+
/** Component names a source file imports from the package, or why that can't be known statically. */
|
|
28
|
+
export function packageUsage(code) {
|
|
29
|
+
const names = [];
|
|
30
|
+
for (const [, , typeOnly, clause, , subpath] of code.matchAll(PACKAGE_IMPORT)) {
|
|
31
|
+
if (typeOnly)
|
|
32
|
+
continue;
|
|
33
|
+
if (subpath !== undefined) {
|
|
34
|
+
if (NEUTRAL_SUBPATHS.has(subpath))
|
|
35
|
+
continue;
|
|
36
|
+
return { reason: `import of "${PACKAGE}/${subpath}"` };
|
|
37
|
+
}
|
|
38
|
+
const clauseNames = importedNames(clause);
|
|
39
|
+
if (!clauseNames)
|
|
40
|
+
return { reason: `"${clause.trim()}" imported from "${PACKAGE}"` };
|
|
41
|
+
names.push(...clauseNames);
|
|
42
|
+
}
|
|
43
|
+
for (const pattern of [DYNAMIC_PACKAGE_IMPORT, SIDE_EFFECT_PACKAGE_IMPORT])
|
|
44
|
+
for (const [, , subpath] of code.matchAll(pattern))
|
|
45
|
+
if (subpath === undefined || !NEUTRAL_SUBPATHS.has(subpath))
|
|
46
|
+
return { reason: `dynamic or side-effect import of "${PACKAGE}"` };
|
|
47
|
+
return { names };
|
|
48
|
+
}
|
|
49
|
+
function exportMap(packageDir) {
|
|
50
|
+
const indexFile = path.join(packageDir, 'index.js');
|
|
51
|
+
const index = readFileSync(indexFile, 'utf8');
|
|
52
|
+
const exports = new Map();
|
|
53
|
+
for (const [, typeOnly, clause, specifier] of index.matchAll(INDEX_REEXPORT)) {
|
|
54
|
+
if (typeOnly)
|
|
55
|
+
continue;
|
|
56
|
+
const file = path.resolve(packageDir, specifier);
|
|
57
|
+
for (const part of clause.split(',')) {
|
|
58
|
+
const entry = part.trim();
|
|
59
|
+
if (!entry || entry.startsWith('type '))
|
|
60
|
+
continue;
|
|
61
|
+
const [local, exported = local] = entry.split(/\s+as\s+/).map((name) => name.trim());
|
|
62
|
+
exports.set(exported, file);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
for (const [, name] of index.matchAll(INDEX_DECLARATION))
|
|
66
|
+
exports.set(name, indexFile);
|
|
67
|
+
return exports;
|
|
68
|
+
}
|
|
69
|
+
function resolveRelative(from, specifier) {
|
|
70
|
+
const base = path.resolve(path.dirname(from), specifier);
|
|
71
|
+
for (const candidate of [base, `${base}.js`, path.join(base, 'index.js')])
|
|
72
|
+
if (existsSync(candidate) && statSync(candidate).isFile())
|
|
73
|
+
return candidate;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Library files (`.svelte`/`.js`) reachable from the components the given app files import.
|
|
77
|
+
* Returns a reason instead when usage can't be determined, so callers keep scanning the whole package.
|
|
78
|
+
*/
|
|
79
|
+
export function resolveComponentSources(appFiles, packageDir) {
|
|
80
|
+
const names = new Set();
|
|
81
|
+
for (const file of appFiles) {
|
|
82
|
+
const usage = packageUsage(readFileSync(file, 'utf8'));
|
|
83
|
+
if ('reason' in usage)
|
|
84
|
+
return { reason: `${usage.reason} in ${file}` };
|
|
85
|
+
usage.names.forEach((name) => names.add(name));
|
|
86
|
+
}
|
|
87
|
+
const exports = exportMap(packageDir);
|
|
88
|
+
const reached = new Set();
|
|
89
|
+
const visit = (file) => {
|
|
90
|
+
if (reached.has(file))
|
|
91
|
+
return;
|
|
92
|
+
reached.add(file);
|
|
93
|
+
if (!LIBRARY_FILE.test(file))
|
|
94
|
+
return;
|
|
95
|
+
for (const [, , specifier] of readFileSync(file, 'utf8').matchAll(RELATIVE_IMPORT)) {
|
|
96
|
+
const target = resolveRelative(file, specifier);
|
|
97
|
+
if (target)
|
|
98
|
+
visit(target);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
for (const name of names) {
|
|
102
|
+
const file = exports.get(name);
|
|
103
|
+
if (!file)
|
|
104
|
+
return { reason: `"${name}" is not exported by ${PACKAGE}` };
|
|
105
|
+
visit(file);
|
|
106
|
+
}
|
|
107
|
+
return { files: [...reached].filter((file) => LIBRARY_FILE.test(file)).sort() };
|
|
108
|
+
}
|
|
109
|
+
/** Swaps the whole-package stylesheet for the theme plus one `@source` per used library file. */
|
|
110
|
+
export function scopeStylesImport(css, files) {
|
|
111
|
+
if (!STYLES_IMPORT.test(css))
|
|
112
|
+
return null;
|
|
113
|
+
const sources = files.map((file) => `@source ${JSON.stringify(file.split(path.sep).join('/'))};`);
|
|
114
|
+
return `${css.replace(STYLES_IMPORT, `@import '${PACKAGE}/theme.css';`)}\n${sources.join('\n')}\n`;
|
|
115
|
+
}
|
|
116
|
+
function listFiles(dir) {
|
|
117
|
+
if (!existsSync(dir))
|
|
118
|
+
return [];
|
|
119
|
+
return readdirSync(dir, { recursive: true })
|
|
120
|
+
.filter((file) => APP_FILE.test(file) && !file.split(path.sep).includes('node_modules'))
|
|
121
|
+
.map((file) => path.join(dir, file));
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Production builds only: Tailwind scans just the library components the app imports (and their
|
|
125
|
+
* dependencies) instead of all of them, which shrinks the generated CSS. The app keeps
|
|
126
|
+
* `@import '@r2digisolutions/components/styles.css';`; place this plugin before `tailwindcss()`.
|
|
127
|
+
* If an import can't be analysed statically it falls back to scanning the whole package.
|
|
128
|
+
*/
|
|
129
|
+
export function componentSources(options = {}) {
|
|
130
|
+
const packageDir = path.dirname(fileURLToPath(import.meta.url));
|
|
131
|
+
let root = process.cwd();
|
|
132
|
+
let result;
|
|
133
|
+
let log = console.log;
|
|
134
|
+
let warn = console.warn;
|
|
135
|
+
const resolve = () => {
|
|
136
|
+
if (result)
|
|
137
|
+
return result;
|
|
138
|
+
const files = (options.dirs ?? ['src']).flatMap((dir) => listFiles(path.resolve(root, dir)));
|
|
139
|
+
result = resolveComponentSources(files, packageDir);
|
|
140
|
+
if ('files' in result)
|
|
141
|
+
log(`[${PLUGIN_NAME}] Tailwind scans ${result.files.length} library files`);
|
|
142
|
+
else
|
|
143
|
+
warn(`[${PLUGIN_NAME}] scanning the whole package: ${result.reason}`);
|
|
144
|
+
return result;
|
|
145
|
+
};
|
|
146
|
+
return {
|
|
147
|
+
name: PLUGIN_NAME,
|
|
148
|
+
apply: 'build',
|
|
149
|
+
enforce: 'pre',
|
|
150
|
+
configResolved(config) {
|
|
151
|
+
root = config.root;
|
|
152
|
+
log = (message) => config.logger.info(message);
|
|
153
|
+
warn = (message) => config.logger.warn(message);
|
|
154
|
+
const own = config.plugins.findIndex((plugin) => plugin.name === PLUGIN_NAME);
|
|
155
|
+
const tailwind = config.plugins.findIndex((plugin) => plugin.name.startsWith('@tailwindcss/vite:generate'));
|
|
156
|
+
if (tailwind !== -1 && tailwind < own)
|
|
157
|
+
warn(`[${PLUGIN_NAME}] has no effect: register componentSources() before tailwindcss()`);
|
|
158
|
+
},
|
|
159
|
+
transform: {
|
|
160
|
+
// Hook filter (Vite 6.3+): skips the JS round-trip for every non-matching module.
|
|
161
|
+
filter: { id: /\.css(?:$|\?)/, code: `${PACKAGE}/styles.css` },
|
|
162
|
+
handler(code, id) {
|
|
163
|
+
if (!/\.css(?:$|\?)/.test(id) || !STYLES_IMPORT.test(code))
|
|
164
|
+
return;
|
|
165
|
+
const sources = resolve();
|
|
166
|
+
if (!('files' in sources))
|
|
167
|
+
return;
|
|
168
|
+
return { code: scopeStylesImport(code, sources.files) ?? code, map: null };
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@r2digisolutions/components",
|
|
3
|
-
"version": "0.25.
|
|
3
|
+
"version": "0.25.16",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "R2DigiSolutions Svelte 5 component library — Atomic Design, Tailwind 4, Light/Dark mode",
|
|
6
6
|
"license": "MIT",
|
|
@@ -49,7 +49,12 @@
|
|
|
49
49
|
"types": "./dist/index.d.ts",
|
|
50
50
|
"svelte": "./dist/index.js"
|
|
51
51
|
},
|
|
52
|
-
"./styles.css": "./dist/styles.css"
|
|
52
|
+
"./styles.css": "./dist/styles.css",
|
|
53
|
+
"./theme.css": "./dist/theme.css",
|
|
54
|
+
"./vite": {
|
|
55
|
+
"types": "./dist/vite.d.ts",
|
|
56
|
+
"default": "./dist/vite.js"
|
|
57
|
+
}
|
|
53
58
|
},
|
|
54
59
|
"peerDependencies": {
|
|
55
60
|
"@lucide/svelte": ">=0.400.0",
|