orbital-ds 0.13.0 → 0.13.1
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/AGENTS.md +1 -1
- package/components.manifest.json +1906 -1906
- package/contract.json +1 -1
- package/dist/styles.css +2 -0
- package/dist/themes/friendly.css +9 -12
- package/dist/themes/friendly.scoped.css +9 -12
- package/dist/themes/tactile.css +10 -5
- package/dist/themes/tactile.scoped.css +10 -5
- package/dist/themes/twitter.css +6 -11
- package/dist/themes/twitter.scoped.css +6 -11
- package/dist/themes/zyro.css +8 -25
- package/dist/themes/zyro.scoped.css +8 -25
- package/dist/ui/attachment.d.ts +1 -1
- package/dist/ui/button.d.ts +1 -1
- package/dist/ui/button.js +4 -4
- package/dist/ui/input-group.d.ts +1 -1
- package/dist/ui/item.d.ts +1 -1
- package/dist/ui/marker.d.ts +1 -1
- package/docs/adr/0002-sistemas-corporativos-al-modelo.md +1 -1
- package/package.json +1 -1
- package/scripts/doctor.mjs +578 -578
package/scripts/doctor.mjs
CHANGED
|
@@ -1,578 +1,578 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* orbital-ds doctor — comprueba que el sistema se cumple.
|
|
4
|
-
*
|
|
5
|
-
* 1. CONTRATO: cada tema (themes/*.css) define en :root todos los tokens de
|
|
6
|
-
* contract.json y la fuente `--ds-font-sans`. En .dark solo avisa.
|
|
7
|
-
* 2. REPETIDOS: ninguna variable se define dos veces en el mismo bloque.
|
|
8
|
-
* 3. SOMBRAS: «sin sombra» es `0 0 #0000`, nunca `none` (una variable con
|
|
9
|
-
* `none` invalida todo el box-shadow, anillo de foco incluido).
|
|
10
|
-
* 4. FUGAS: el tema base (contract.baseTheme) está aplicado siempre; todo tema
|
|
11
|
-
* con ámbito debe definir cada `--ds-*` que defina el base, o su valor se
|
|
12
|
-
* colaría al cambiar de tema.
|
|
13
|
-
* 5. VALORES FIJOS: ningún componente (ui/*.tsx) escribe colores, z-index,
|
|
14
|
-
* duraciones ni sombras a mano; todo sale de tokens.
|
|
15
|
-
* 6. API PÚBLICA: no desaparece ningún componente ni export respecto a
|
|
16
|
-
* components.manifest.json (huella de la última versión). Lo nuevo solo avisa.
|
|
17
|
-
* 7. PERSONALIDAD: las reglas de un tema solo usan variables y estilizan familias
|
|
18
|
-
* completas de piezas (contract.slotFamilies). Error si la ficha del tema dice
|
|
19
|
-
* `"conformance": "strict"`; aviso en los demás.
|
|
20
|
-
*
|
|
21
|
-
* Uso:
|
|
22
|
-
* node scripts/doctor.mjs # temas y componentes del paquete
|
|
23
|
-
* node scripts/doctor.mjs --css app.css # además, un CSS de una app (repetidos)
|
|
24
|
-
*
|
|
25
|
-
* Sale con código 1 si hay errores (los avisos no fallan).
|
|
26
|
-
*/
|
|
27
|
-
import { readFileSync, readdirSync, existsSync } from 'node:fs';
|
|
28
|
-
import { join, dirname, resolve } from 'node:path';
|
|
29
|
-
import { fileURLToPath } from 'node:url';
|
|
30
|
-
|
|
31
|
-
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
32
|
-
const contract = JSON.parse(readFileSync(join(ROOT, 'contract.json'), 'utf8'));
|
|
33
|
-
|
|
34
|
-
const errors = [];
|
|
35
|
-
const warnings = [];
|
|
36
|
-
const read = (p) => readFileSync(p, 'utf8');
|
|
37
|
-
const stripComments = (css) => css.replace(/\/\*[\s\S]*?\*\//g, '');
|
|
38
|
-
|
|
39
|
-
/** Cuerpo de cada bloque `selector { ... }` (respeta llaves anidadas). */
|
|
40
|
-
function blocks(css, selectorRe) {
|
|
41
|
-
const out = [];
|
|
42
|
-
const re = new RegExp(selectorRe.source + '\\s*\\{', 'g');
|
|
43
|
-
let m;
|
|
44
|
-
while ((m = re.exec(css))) {
|
|
45
|
-
let depth = 1;
|
|
46
|
-
let i = re.lastIndex;
|
|
47
|
-
const start = i;
|
|
48
|
-
while (i < css.length && depth > 0) {
|
|
49
|
-
if (css[i] === '{') depth++;
|
|
50
|
-
else if (css[i] === '}') depth--;
|
|
51
|
-
i++;
|
|
52
|
-
}
|
|
53
|
-
out.push(css.slice(start, i - 1));
|
|
54
|
-
re.lastIndex = i;
|
|
55
|
-
}
|
|
56
|
-
return out;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/** Declaraciones `--x: valor;` del nivel superior de un bloque (no las anidadas). */
|
|
60
|
-
function declarations(body) {
|
|
61
|
-
let depth = 0;
|
|
62
|
-
let top = '';
|
|
63
|
-
for (const ch of body) {
|
|
64
|
-
if (ch === '{') depth++;
|
|
65
|
-
else if (ch === '}') depth--;
|
|
66
|
-
else if (depth === 0) top += ch;
|
|
67
|
-
}
|
|
68
|
-
return [...top.matchAll(/(^|[;\s])(--[a-z0-9-]+)\s*:\s*([^;]*);?/gi)].map((m) => ({ name: m[2], value: m[3].trim() }));
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/** Variables --ds-* que la estructura del paquete define (las que una app puede usar). */
|
|
72
|
-
/** CSS de la estructura: src/ en el repo; dist/ en el paquete instalado (npm no publica src/). */
|
|
73
|
-
const STRUCTURE_CSS = existsSync(join(ROOT, 'src/styles.css')) ? join(ROOT, 'src/styles.css') : join(ROOT, 'dist/styles.css');
|
|
74
|
-
|
|
75
|
-
function knownDsVars() {
|
|
76
|
-
return new Set([...read(STRUCTURE_CSS).matchAll(/(--ds-[a-z0-9-]+)\s*:/g)].map((m) => m[1]));
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// El grupo de marca debe ser coherente con el contrato: cada variable, o es del contrato, o es --ds-*.
|
|
80
|
-
for (const t of contract.brand?.tokens ?? []) {
|
|
81
|
-
const inContract =
|
|
82
|
-
contract.root.includes(t.name) ||
|
|
83
|
-
contract.fonts.includes(t.name) ||
|
|
84
|
-
(t.name.startsWith('ds-') && knownDsVars().has(`--${t.name}`));
|
|
85
|
-
if (!inContract) errors.push(`contrato: la variable de marca --${t.name} ni es del contrato ni la define la estructura`);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const themeInfo = {}; // nombre → { rootVars:Set, darkVars:Set }
|
|
89
|
-
|
|
90
|
-
function checkTheme(file, name) {
|
|
91
|
-
const label = `tema ${name}`;
|
|
92
|
-
const css = stripComments(read(file));
|
|
93
|
-
const roots = blocks(css, /(?:^|[\s}])\:root/);
|
|
94
|
-
const darks = blocks(css, /(?:^|[\s}])\.dark/);
|
|
95
|
-
|
|
96
|
-
const rootDecl = roots.flatMap(declarations);
|
|
97
|
-
const darkDecl = darks.flatMap(declarations);
|
|
98
|
-
const rootVars = new Set(rootDecl.map((d) => d.name));
|
|
99
|
-
const darkVars = new Set(darkDecl.map((d) => d.name));
|
|
100
|
-
themeInfo[name] = { rootVars, darkVars };
|
|
101
|
-
|
|
102
|
-
for (const t of contract.root) {
|
|
103
|
-
if (!rootVars.has(`--${t}`)) errors.push(`${label}: falta el token obligatorio --${t} en :root`);
|
|
104
|
-
}
|
|
105
|
-
for (const f of contract.fonts) {
|
|
106
|
-
if (!rootVars.has(`--${f}`)) errors.push(`${label}: falta la fuente --${f} en :root`);
|
|
107
|
-
}
|
|
108
|
-
if (darks.length) {
|
|
109
|
-
for (const t of contract.dark.avisar_si_falta) {
|
|
110
|
-
if (!darkVars.has(`--${t}`)) warnings.push(`${label}: .dark no redefine --${t} (hereda el valor claro)`);
|
|
111
|
-
}
|
|
112
|
-
} else {
|
|
113
|
-
warnings.push(`${label}: no define piel .dark`);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// Repetidos (solo declaraciones del nivel superior de cada bloque)
|
|
117
|
-
for (const [kind, list] of [[':root', roots], ['.dark', darks]]) {
|
|
118
|
-
list.forEach((body, idx) => {
|
|
119
|
-
const seen = new Map();
|
|
120
|
-
for (const d of declarations(body)) seen.set(d.name, (seen.get(d.name) ?? 0) + 1);
|
|
121
|
-
for (const [v, n] of seen) {
|
|
122
|
-
if (n > 1) errors.push(`${label}: ${v} definido ${n} veces en el mismo bloque ${kind} (#${idx + 1})`);
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// Sombras: `none` invalida el box-shadow
|
|
128
|
-
for (const d of [...rootDecl, ...darkDecl]) {
|
|
129
|
-
if (/^--ds-(?:shadow|sidebar-shadow)/.test(d.name) && /^none$/i.test(d.value)) {
|
|
130
|
-
errors.push(`${label}: ${d.name}: none — usa «0 0 #0000» (none invalida todo el box-shadow)`);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// 1+2+3) temas
|
|
136
|
-
const themesDir = join(ROOT, existsSync(join(ROOT, 'src/themes')) ? 'src/themes' : 'dist/themes');
|
|
137
|
-
const themeFiles = readdirSync(themesDir).filter(
|
|
138
|
-
(n) => n.endsWith('.css') && !n.endsWith('.fonts.css') && !n.endsWith('.scoped.css'),
|
|
139
|
-
);
|
|
140
|
-
for (const f of themeFiles) checkTheme(join(themesDir, f), f.replace(/\.css$/, ''));
|
|
141
|
-
|
|
142
|
-
// 1b) documentación de cada tema: guía de diseño (.guide.md) + ficha legible por máquina (.meta.json)
|
|
143
|
-
const META_CLAVES = ['name', 'label', 'essence', 'signature', 'fonts', 'palette', 'references', 'status', 'guide'];
|
|
144
|
-
for (const f of themeFiles) {
|
|
145
|
-
const t = f.replace(/\.css$/, '');
|
|
146
|
-
if (!existsSync(join(themesDir, `${t}.guide.md`))) errors.push(`tema ${t}: falta ${t}.guide.md (guía de diseño)`);
|
|
147
|
-
const metaPath = join(themesDir, `${t}.meta.json`);
|
|
148
|
-
if (!existsSync(metaPath)) { errors.push(`tema ${t}: falta ${t}.meta.json (ficha del tema)`); continue; }
|
|
149
|
-
let meta;
|
|
150
|
-
try { meta = JSON.parse(read(metaPath)); } catch { errors.push(`tema ${t}: ${t}.meta.json no es JSON válido`); continue; }
|
|
151
|
-
for (const k of META_CLAVES) if (!(k in meta)) errors.push(`tema ${t}: ${t}.meta.json no define «${k}»`);
|
|
152
|
-
if (meta.name !== t) errors.push(`tema ${t}: ${t}.meta.json tiene name «${meta.name}»`);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// 1d) PESOS CARGADOS: cada --ds-*-weight que pide el tema (o hereda de la estructura) debe
|
|
156
|
-
// estar entre los que cargan sus fuentes (<tema>.fonts.css, Google Fonts). Si no, el
|
|
157
|
-
// navegador pinta otro peso (500 sin cargar se ve 400) y el aspecto no es el del tema.
|
|
158
|
-
// Temas con fuentes del sistema (sin @import de Google Fonts): no se comprueba.
|
|
159
|
-
{
|
|
160
|
-
const estructura = read(STRUCTURE_CSS);
|
|
161
|
-
const pesosBase = {};
|
|
162
|
-
for (const [, k, v] of estructura.matchAll(/(--ds-[\w-]*weight)\s*:\s*([^;]+);/g)) if (!(k in pesosBase)) pesosBase[k] = v.trim();
|
|
163
|
-
for (const f of themeFiles) {
|
|
164
|
-
const t = f.replace(/\.css$/, '');
|
|
165
|
-
const fontsPath = join(themesDir, `${t}.fonts.css`);
|
|
166
|
-
if (!existsSync(fontsPath)) continue;
|
|
167
|
-
const url = (read(fontsPath).match(/fonts\.googleapis\.com\/css2\?([^'")]+)/) ?? [])[1];
|
|
168
|
-
if (!url) continue;
|
|
169
|
-
const cargados = [];
|
|
170
|
-
for (const [, fam] of url.matchAll(/family=([^&]+)/g)) {
|
|
171
|
-
const [, ejes = '', tuplas = ''] = fam.match(/:([^@]+)@(.+)$/) ?? [];
|
|
172
|
-
const i = ejes.split(',').indexOf('wght');
|
|
173
|
-
if (i < 0) { cargados.push([400, 400]); continue; }
|
|
174
|
-
for (const tupla of tuplas.split(';')) {
|
|
175
|
-
const v = tupla.split(',')[i] ?? '';
|
|
176
|
-
const [a, b = a] = v.split('..').map(Number);
|
|
177
|
-
if (Number.isFinite(a)) cargados.push([a, b]);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
if (!cargados.length) continue;
|
|
181
|
-
const css = read(join(themesDir, f)).replace(/\/\*[\s\S]*?\*\//g, '');
|
|
182
|
-
const pesos = { ...pesosBase };
|
|
183
|
-
for (const [, cuerpo] of css.matchAll(/:root\s*\{([^{}]*)\}/g)) for (const [, k, v] of cuerpo.matchAll(/(--ds-[\w-]*weight)\s*:\s*([^;]+);/g)) pesos[k] = v.trim();
|
|
184
|
-
const valor = (v, n = 0) => { const m = v.match(/^var\((--[\w-]+)(?:,\s*([^)]+))?\)$/); return m && n < 8 ? valor(pesos[m[1]] ?? m[2] ?? '', n + 1) : v; };
|
|
185
|
-
for (const [k, v] of Object.entries(pesos)) {
|
|
186
|
-
const p = Number(valor(v));
|
|
187
|
-
if (!Number.isFinite(p)) continue;
|
|
188
|
-
if (!cargados.some(([a, b]) => p >= a && p <= b))
|
|
189
|
-
warnings.push(`tema ${t}: ${k} = ${p}, pero ${t}.fonts.css no carga ese peso (carga ${[...new Set(cargados.map(([a, b]) => (a === b ? a : `${a}–${b}`)))].join(', ')}): el navegador pintará otro`);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
// 1e) MOVIMIENTO AUTOMÁTICO: cada --ds-enter-<grupo> del tema es del catálogo de motion.css
|
|
195
|
-
// (@keyframes ds-auto-*) o `none`, y la ficha lo declara igual en motion.auto.<grupo>.
|
|
196
|
-
// Coherencia mecánica; el criterio estético (que el tipo encaje con el tema) es de la revisión.
|
|
197
|
-
{
|
|
198
|
-
const motionCss = existsSync(join(ROOT, 'src/motion.css')) ? join(ROOT, 'src/motion.css') : join(ROOT, 'dist/motion.css');
|
|
199
|
-
if (existsSync(motionCss)) {
|
|
200
|
-
const catalogo = new Set([...read(motionCss).matchAll(/@keyframes\s+(ds-auto-[\w-]+)/g)].map((m) => m[1]));
|
|
201
|
-
catalogo.add('none');
|
|
202
|
-
for (const f of themeFiles) {
|
|
203
|
-
const t = f.replace(/\.css$/, '');
|
|
204
|
-
const css = read(join(themesDir, f)).replace(/\/\*[\s\S]*?\*\//g, '');
|
|
205
|
-
const valores = {};
|
|
206
|
-
for (const [, cuerpo] of css.matchAll(/:root\s*\{([^{}]*)\}/g))
|
|
207
|
-
for (const [, g, v] of cuerpo.matchAll(/--ds-enter-([\w-]+)\s*:\s*([^;]+);/g)) valores[g] = v.trim();
|
|
208
|
-
let auto = {};
|
|
209
|
-
try { auto = JSON.parse(read(join(themesDir, `${t}.meta.json`))).motion?.auto ?? {}; } catch { /* lo avisa 1b */ }
|
|
210
|
-
for (const [g, v] of Object.entries(valores)) {
|
|
211
|
-
if (!catalogo.has(v)) errors.push(`tema ${t}: --ds-enter-${g} = «${v}» no es del catálogo (${[...catalogo].join(', ')})`);
|
|
212
|
-
if (auto[g] !== v) errors.push(`tema ${t}: --ds-enter-${g} = «${v}» pero su ficha dice motion.auto.${g} = «${auto[g] ?? '—'}»`);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// 1c) CONTRASTE de los textos de estado: info, danger, warning, success y neutral
|
|
219
|
-
// sobre su fondo suave (compuesto sobre el lienzo), mínimo WCAG AA 4.5:1, en claro y oscuro.
|
|
220
|
-
// No incluye `link` ni `primary-foreground`: dependen de colores de marca fijados por la
|
|
221
|
-
// identidad (p. ej. el azul de Twitter), y se documentan como limitación en la guía del tema.
|
|
222
|
-
{
|
|
223
|
-
const parseColor = (raw) => {
|
|
224
|
-
const v = raw.replace(/\s+/g, ' ').trim();
|
|
225
|
-
let m = v.match(/^#([0-9a-f]{3,8})$/i);
|
|
226
|
-
if (m) {
|
|
227
|
-
let h = m[1];
|
|
228
|
-
if (h.length === 3) h = [...h].map((c) => c + c).join('');
|
|
229
|
-
return { r: parseInt(h.slice(0, 2), 16), g: parseInt(h.slice(2, 4), 16), b: parseInt(h.slice(4, 6), 16), a: h.length === 8 ? parseInt(h.slice(6, 8), 16) / 255 : 1 };
|
|
230
|
-
}
|
|
231
|
-
m = v.match(/^rgba?\(([^)]+)\)$/i);
|
|
232
|
-
if (m) { const p = m[1].split(/[ ,/]+/).filter(Boolean).map(Number); return { r: p[0], g: p[1], b: p[2], a: p[3] ?? 1 }; }
|
|
233
|
-
m = v.match(/^oklch\(\s*([\d.]+%?)\s+([\d.]+)\s+([\d.]+)(?:\s*\/\s*([\d.]+%?))?\s*\)$/i);
|
|
234
|
-
if (m) {
|
|
235
|
-
const L = m[1].endsWith('%') ? parseFloat(m[1]) / 100 : +m[1];
|
|
236
|
-
const C = +m[2], H = (+m[3] * Math.PI) / 180;
|
|
237
|
-
const a = C * Math.cos(H), b = C * Math.sin(H);
|
|
238
|
-
const l = (L + 0.3963377774 * a + 0.2158037573 * b) ** 3;
|
|
239
|
-
const mm = (L - 0.1055613458 * a - 0.0638541728 * b) ** 3;
|
|
240
|
-
const s = (L - 0.0894841775 * a - 1.291485548 * b) ** 3;
|
|
241
|
-
const lin = [4.0767416621 * l - 3.3077115913 * mm + 0.2309699292 * s, -1.2684380046 * l + 2.6097574011 * mm - 0.3413193965 * s, -0.0041960863 * l - 0.7034186147 * mm + 1.707614701 * s];
|
|
242
|
-
const g = (x) => Math.round(255 * Math.min(1, Math.max(0, x <= 0.0031308 ? 12.92 * x : 1.055 * x ** (1 / 2.4) - 0.055)));
|
|
243
|
-
const al = m[4] ? (m[4].endsWith('%') ? parseFloat(m[4]) / 100 : +m[4]) : 1;
|
|
244
|
-
return { r: g(lin[0]), g: g(lin[1]), b: g(lin[2]), a: al };
|
|
245
|
-
}
|
|
246
|
-
return null;
|
|
247
|
-
};
|
|
248
|
-
const lum = ({ r, g, b }) => {
|
|
249
|
-
const f = (c) => { c /= 255; return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4; };
|
|
250
|
-
return 0.2126 * f(r) + 0.7152 * f(g) + 0.0722 * f(b);
|
|
251
|
-
};
|
|
252
|
-
const over = (fg, bg) => ({ r: fg.r * fg.a + bg.r * (1 - fg.a), g: fg.g * fg.a + bg.g * (1 - fg.a), b: fg.b * fg.a + bg.b * (1 - fg.a), a: 1 });
|
|
253
|
-
const ratio = (x, y) => { const [p, q] = [lum(x), lum(y)].sort((u, w) => w - u); return (p + 0.05) / (q + 0.05); };
|
|
254
|
-
const varsDe = (css, selector) => {
|
|
255
|
-
const m = new RegExp(`(^|\\n)${selector}\\s*\\{`).exec(css);
|
|
256
|
-
if (!m) return {};
|
|
257
|
-
let i = m.index + m[0].length, d = 1, j = i;
|
|
258
|
-
while (d && j < css.length) { if (css[j] === '{') d++; else if (css[j] === '}') d--; j++; }
|
|
259
|
-
const out = {};
|
|
260
|
-
for (const mm of css.slice(i, j - 1).matchAll(/--([\w-]+):\s*([^;]+);/g)) out[mm[1]] = mm[2];
|
|
261
|
-
return out;
|
|
262
|
-
};
|
|
263
|
-
// Qué se mide: cada tema y, con `--css`, la marca/variante de la app ENCIMA de su tema base
|
|
264
|
-
// (`--theme <t>` o un comentario `@base-theme <t>` en el fichero).
|
|
265
|
-
const objetivos = themeFiles.map((f) => {
|
|
266
|
-
const css = stripComments(read(join(themesDir, f)));
|
|
267
|
-
const tema = f.replace(/\.css$/, '');
|
|
268
|
-
return { tema, etiqueta: `tema ${tema}`, claro: varsDe(css, ':root'), oscuro: varsDe(css, '\\.dark') };
|
|
269
|
-
});
|
|
270
|
-
const iCss = process.argv.indexOf('--css');
|
|
271
|
-
if (iCss > -1 && process.argv[iCss + 1]) {
|
|
272
|
-
const crudo = read(resolve(process.argv[iCss + 1]));
|
|
273
|
-
const iTheme = process.argv.indexOf('--theme');
|
|
274
|
-
const base = (iTheme > -1 && process.argv[iTheme + 1]) || crudo.match(/@base-theme\s+([\w-]+)/)?.[1] || null;
|
|
275
|
-
const t = base && objetivos.find((o) => o.tema === base);
|
|
276
|
-
const app = stripComments(crudo);
|
|
277
|
-
if (t) {
|
|
278
|
-
objetivos.push({
|
|
279
|
-
tema: base,
|
|
280
|
-
etiqueta: `marca ${process.argv[iCss + 1]} (sobre ${base})`,
|
|
281
|
-
claro: { ...t.claro, ...varsDe(app, ':root') },
|
|
282
|
-
oscuro: { ...t.oscuro, ...varsDe(app, '\\.dark') },
|
|
283
|
-
});
|
|
284
|
-
} else {
|
|
285
|
-
warnings.push('app css: no sé sobre qué tema medir el contraste; pasa --theme <tema> o pon «@base-theme <tema>» en el fichero');
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
for (const { tema, etiqueta, claro, oscuro } of objetivos) {
|
|
289
|
-
// Resuelve `var(--x)` (y `var(--x, respaldo)`) dentro del mismo tema: un color derivado
|
|
290
|
-
// de otro (p. ej. `--sidebar-primary: var(--primary)`) también se mide.
|
|
291
|
-
const resolver = (vars) => {
|
|
292
|
-
const out = {};
|
|
293
|
-
for (const [k, v0] of Object.entries(vars)) {
|
|
294
|
-
let v = v0.trim();
|
|
295
|
-
for (let n = 0; n < 8; n++) {
|
|
296
|
-
const m = v.match(/^var\(--([\w-]+)(?:\s*,\s*([\s\S]+))?\)$/);
|
|
297
|
-
if (!m) break;
|
|
298
|
-
v = (vars[m[1]] ?? m[2] ?? '').trim();
|
|
299
|
-
}
|
|
300
|
-
out[k] = v;
|
|
301
|
-
}
|
|
302
|
-
return out;
|
|
303
|
-
};
|
|
304
|
-
for (const [piel, vars] of [['claro', resolver(claro)], ['oscuro', resolver({ ...claro, ...oscuro })]]) {
|
|
305
|
-
const lienzo = parseColor(vars.background ?? '#fff');
|
|
306
|
-
if (!lienzo) continue;
|
|
307
|
-
let excepciones = [];
|
|
308
|
-
try { excepciones = JSON.parse(read(join(themesDir, `${tema}.meta.json`))).a11y?.exceptions ?? []; } catch { /* sin ficha: lo avisa 1b */ }
|
|
309
|
-
for (const estado of ['info', 'danger', 'warning', 'success', 'neutral']) {
|
|
310
|
-
// Texto sobre el fondo suave: --ds-on-soft si el tema lo define (tinta); si no, el color del estado.
|
|
311
|
-
const tinta = vars['ds-on-soft'];
|
|
312
|
-
const fg = parseColor(tinta || vars[estado] || '');
|
|
313
|
-
const suave = vars[`${estado}-soft`] && parseColor(vars[`${estado}-soft`]);
|
|
314
|
-
if (!fg || !suave) continue;
|
|
315
|
-
const fondo = over(suave, over(lienzo, { r: 255, g: 255, b: 255, a: 1 }));
|
|
316
|
-
const r = ratio(over(fg, fondo), fondo);
|
|
317
|
-
if (r < 4.5) {
|
|
318
|
-
const msg = `${etiqueta} (${piel}): ${tinta ? '--ds-on-soft' : estado} sobre ${estado}-soft = ${r.toFixed(2)}:1 (mínimo 4.5:1)`;
|
|
319
|
-
if (excepciones.includes(`${estado}/${estado}-soft`)) warnings.push(`${msg} — excepción declarada en la ficha`);
|
|
320
|
-
else errors.push(`${msg}; corrígelo o decláralo en ${tema}.meta.json → a11y.exceptions ("${estado}/${estado}-soft")`);
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
// Pares principales de texto sobre su superficie. AA (4.5:1) es el mínimo exigible; las
|
|
325
|
-
// excepciones deben estar declaradas en `<tema>.meta.json` → `a11y.exceptions` ("fg/bg").
|
|
326
|
-
// AAA (7:1) es el objetivo del texto del cuerpo: solo avisa, y solo con `--aaa`.
|
|
327
|
-
const PARES = [
|
|
328
|
-
['foreground', 'background'], ['card-foreground', 'card'], ['popover-foreground', 'popover'],
|
|
329
|
-
['primary-foreground', 'primary'], ['secondary-foreground', 'secondary'],
|
|
330
|
-
['muted-foreground', 'background'], ['muted-foreground', 'card'],
|
|
331
|
-
['sidebar-foreground', 'sidebar'], ['sidebar-primary-foreground', 'sidebar-primary'],
|
|
332
|
-
['destructive-foreground', 'destructive'],
|
|
333
|
-
];
|
|
334
|
-
const blanco = { r: 255, g: 255, b: 255, a: 1 };
|
|
335
|
-
for (const [fgName, bgName] of PARES) {
|
|
336
|
-
const fgRaw = vars[fgName] && parseColor(vars[fgName]);
|
|
337
|
-
const bgRaw = vars[bgName] && parseColor(vars[bgName]);
|
|
338
|
-
if (!fgRaw || !bgRaw) continue;
|
|
339
|
-
const bg = over(bgRaw, over(lienzo, blanco));
|
|
340
|
-
const r = ratio(over(fgRaw, bg), bg);
|
|
341
|
-
const par = `${fgName}/${bgName}`;
|
|
342
|
-
if (r < 4.5) {
|
|
343
|
-
const msg = `${etiqueta} (${piel}): ${par} = ${r.toFixed(2)}:1 (mínimo AA 4.5:1)`;
|
|
344
|
-
if (excepciones.includes(par)) warnings.push(`${msg} — excepción declarada en la ficha`);
|
|
345
|
-
else errors.push(`${msg}; corrígelo o decláralo en ${tema}.meta.json → a11y.exceptions`);
|
|
346
|
-
} else if (process.argv.includes('--aaa') && r < 7 && (par === 'foreground/background' || par === 'card-foreground/card')) {
|
|
347
|
-
warnings.push(`${etiqueta} (${piel}): ${par} = ${r.toFixed(2)}:1 (objetivo AAA 7:1 para el texto del cuerpo)`);
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
// 4) fugas desde el tema base
|
|
355
|
-
const base = contract.baseTheme;
|
|
356
|
-
if (base && themeInfo[base]) {
|
|
357
|
-
const baseDs = [...themeInfo[base].rootVars].filter((v) => v.startsWith('--ds-'));
|
|
358
|
-
for (const [name, info] of Object.entries(themeInfo)) {
|
|
359
|
-
if (name === base) continue;
|
|
360
|
-
for (const v of baseDs) {
|
|
361
|
-
if (!info.rootVars.has(v)) {
|
|
362
|
-
errors.push(`tema ${name}: no define ${v}, que sí define el tema base «${base}» — su valor se colaría al cambiar de tema`);
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
// 7) PERSONALIDAD: solo variables y familias completas.
|
|
369
|
-
// a) Una regla de personalidad (cualquier propiedad que no sea `--x`) no escribe
|
|
370
|
-
// medidas, colores, pesos, opacidades ni duraciones: pide un hueco a una variable.
|
|
371
|
-
// b) Si estiliza una pieza de una familia (contract.slotFamilies), estiliza todas.
|
|
372
|
-
// Error en los temas con `"conformance": "strict"` en su ficha; aviso en los demás.
|
|
373
|
-
{
|
|
374
|
-
/** Declaraciones de propiedades normales (no `--x`) de un CSS, con su selector. */
|
|
375
|
-
const propertyDecls = (css) => {
|
|
376
|
-
const out = [];
|
|
377
|
-
const stack = [];
|
|
378
|
-
let buf = '';
|
|
379
|
-
for (const ch of css) {
|
|
380
|
-
if (ch === '{') { stack.push(buf.trim()); buf = ''; }
|
|
381
|
-
else if (ch === ';' || ch === '}') {
|
|
382
|
-
const d = buf.trim();
|
|
383
|
-
const m = d.match(/^([a-z-]+)\s*:\s*([\s\S]+)$/i);
|
|
384
|
-
if (stack.length && m && !d.startsWith('--')) out.push({ selector: stack.at(-1), prop: m[1], value: m[2].trim() });
|
|
385
|
-
buf = '';
|
|
386
|
-
if (ch === '}') stack.pop();
|
|
387
|
-
} else buf += ch;
|
|
388
|
-
}
|
|
389
|
-
return out;
|
|
390
|
-
};
|
|
391
|
-
const LITERALES = [
|
|
392
|
-
{ re: /(?<![\w.-])\d*\.?\d+(?:px|rem|em|ch|vh|vw)\b/g, why: 'medida' },
|
|
393
|
-
{ re: /#[0-9a-f]{3,8}\b/gi, why: 'color' },
|
|
394
|
-
{ re: /\b(?:rgba?|hsla?|oklch|oklab)\(/gi, why: 'color' },
|
|
395
|
-
{ re: /(?<![\w.-])\d*\.?\d+m?s\b/g, why: 'duración' },
|
|
396
|
-
];
|
|
397
|
-
const NUMERICAS = { 'font-weight': 'peso', opacity: 'opacidad', 'z-index': 'capa', 'line-height': 'interlineado' };
|
|
398
|
-
const familias = Object.entries(contract.slotFamilies?.families ?? {});
|
|
399
|
-
for (const f of themeFiles) {
|
|
400
|
-
const tema = f.replace(/\.css$/, '');
|
|
401
|
-
let estricto = false;
|
|
402
|
-
try { estricto = JSON.parse(read(join(themesDir, `${tema}.meta.json`))).conformance === 'strict'; } catch { /* lo avisa 1b */ }
|
|
403
|
-
const report = (msg) => (estricto ? errors : warnings).push(`tema ${tema}: ${msg}`);
|
|
404
|
-
const decls = propertyDecls(stripComments(read(join(themesDir, f))));
|
|
405
|
-
|
|
406
|
-
const vistos = new Set();
|
|
407
|
-
for (const { selector, prop, value } of decls) {
|
|
408
|
-
const sinVar = value.replace(/var\([^()]*(?:\([^()]*\)[^()]*)*\)/g, '');
|
|
409
|
-
const hits = LITERALES.flatMap((r) => (sinVar.match(r.re) ?? []).map((h) => `${r.why} ${h}`));
|
|
410
|
-
if (NUMERICAS[prop] && /^\d*\.?\d+$/.test(value)) hits.push(`${NUMERICAS[prop]} ${value}`);
|
|
411
|
-
for (const h of hits) {
|
|
412
|
-
const clave = `${selector}|${prop}|${h}`;
|
|
413
|
-
if (vistos.has(clave)) continue;
|
|
414
|
-
vistos.add(clave);
|
|
415
|
-
report(`personalidad con valor fijo (${h}) en «${prop}» de ${selector.replace(/\s+/g, ' ')} — usa una variable`);
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
// c) Huecos públicos (contract.slotTokens): pintar esa propiedad de esa pieza con otra cosa
|
|
420
|
-
// que su hueco es rodearlo; se rellena el hueco en las VARIABLES del tema.
|
|
421
|
-
const huecos = contract.slotTokens?.slots ?? {};
|
|
422
|
-
for (const { selector, prop, value } of decls) {
|
|
423
|
-
for (const [, slot] of selector.matchAll(/data-slot=['"]?([\w-]+)/g)) {
|
|
424
|
-
const token = huecos[slot]?.[prop];
|
|
425
|
-
if (!token || value.includes(`var(${token})`)) continue;
|
|
426
|
-
const clave = `hueco|${slot}|${prop}`;
|
|
427
|
-
if (vistos.has(clave)) continue;
|
|
428
|
-
vistos.add(clave);
|
|
429
|
-
//
|
|
430
|
-
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
const estilizados = new Set(decls.flatMap((d) => [...d.selector.matchAll(/data-slot=['"]?([\w-]+)/g)].map((m) => m[1])));
|
|
435
|
-
for (const [familia, slots] of familias) {
|
|
436
|
-
const tiene = slots.filter((s) => estilizados.has(s));
|
|
437
|
-
if (!tiene.length || tiene.length === slots.length) continue;
|
|
438
|
-
const faltan = slots.filter((s) => !estilizados.has(s));
|
|
439
|
-
report(`familia «${familia}» incompleta: estiliza ${tiene.join(', ')} pero no ${faltan.join(', ')}`);
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
// 8) ESCAPARATE: cada componente tiene su demo (showcase/src/demos/<componente>.tsx), para
|
|
445
|
-
// que todo se pueda ver con cada tema. Solo en el repo del paquete (no en una app).
|
|
446
|
-
{
|
|
447
|
-
const demosDir = join(ROOT, 'showcase/src/demos');
|
|
448
|
-
const uiDir8 = join(ROOT, 'src/ui');
|
|
449
|
-
if (existsSync(demosDir) && existsSync(uiDir8)) {
|
|
450
|
-
const demos = new Set(readdirSync(demosDir).filter((n) => n.endsWith('.tsx')).map((n) => n.replace(/\.tsx$/, '')));
|
|
451
|
-
const faltan = readdirSync(uiDir8).filter((n) => n.endsWith('.tsx')).map((n) => n.replace(/\.tsx$/, '')).filter((n) => !demos.has(n));
|
|
452
|
-
if (faltan.length) errors.push(`escaparate: componentes sin demo en showcase/src/demos/ (${faltan.join(', ')})`);
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
// CSS de una app (opcional)
|
|
457
|
-
const cssArgIdx = process.argv.indexOf('--css');
|
|
458
|
-
if (cssArgIdx > -1 && process.argv[cssArgIdx + 1]) {
|
|
459
|
-
const css = stripComments(read(resolve(process.argv[cssArgIdx + 1])));
|
|
460
|
-
blocks(css, /(?:^|[\s}])\:root/).forEach((body, idx) => {
|
|
461
|
-
const seen = new Map();
|
|
462
|
-
for (const d of declarations(body)) seen.set(d.name, (seen.get(d.name) ?? 0) + 1);
|
|
463
|
-
for (const [v, n] of seen) if (n > 1) errors.push(`app css: ${v} definido ${n} veces en :root (#${idx + 1})`);
|
|
464
|
-
// Una variable --ds-* que el paquete ya no tiene: la marca la ignoraría en silencio.
|
|
465
|
-
const known = knownDsVars();
|
|
466
|
-
for (const d of declarations(body)) {
|
|
467
|
-
if (d.name.startsWith('--ds-') && !known.has(d.name)) {
|
|
468
|
-
errors.push(`app css: ${d.name} no existe en orbital-ds (¿renombrada o retirada? mira docs/CONTRACT.md)`);
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
});
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
// 5) valores fijos en componentes
|
|
475
|
-
const NO_HARDCODE = [
|
|
476
|
-
{ re: /#[0-9a-fA-F]{3,8}\b/g, why: 'color hexadecimal', skip: ['chart.tsx'] },
|
|
477
|
-
{ re: /\b(?:rgb|rgba|hsl|hsla|oklch)\((?!from_)/g, why: 'color literal' },
|
|
478
|
-
{ re: /(?<![\w-])z-(?!0(?![\w-]))\d+(?![\w-])/g, why: 'z-index numérico (usa --ds-z-*)' },
|
|
479
|
-
{ re: /(?<![\w-])duration-(?!0(?![\w-]))\d+(?![\w-])/g, why: 'duración fija (usa --ds-motion-*)' },
|
|
480
|
-
{ re: /(?<![a-zA-Z0-9.-])\d*\.?\d+m?s(?=[\])_,\s])/g, why: 'duración dentro de un valor arbitrario (usa --ds-motion-*)' },
|
|
481
|
-
{ re: /(?<![\w-])ease-\[(?:cubic-bezier|steps)\(/g, why: 'curva de aceleración escrita (usa ease-(--ds-ease-*))' },
|
|
482
|
-
{ re: /(?<![\w-])z-\[[^\]]*\d{2,}/g, why: 'capa numérica dentro de un valor arbitrario (usa --ds-z-*)' },
|
|
483
|
-
// i18n: los textos que ve o escucha el usuario salen de useDsMessages() (orbital-ds/lib/i18n).
|
|
484
|
-
{ re: /aria-(?:label|roledescription)="[A-Za-z][^"]*"/g, why: 'texto accesible escrito a mano (usa useDsMessages)' },
|
|
485
|
-
{ re: /sr-only">[^<{]*[A-Za-z][^<{]*</g, why: 'texto para lector de pantalla escrito a mano (usa useDsMessages)' },
|
|
486
|
-
{ re: /\?\?\s*"[A-Z][^"]*"/g, why: 'texto por defecto escrito a mano (usa useDsMessages)' },
|
|
487
|
-
{ re: /(?<![\w-])(?:title|description|text|placeholder)\s*=\s*"[A-Z][^"]*"/g, why: 'texto de interfaz escrito a mano (usa useDsMessages)' },
|
|
488
|
-
{ re: /(?<![\w-])(?:bg|text|border)-(?:black|white)(?:\/\d+)?(?![\w-])/g, why: 'color fijo (usa un token de color)' },
|
|
489
|
-
{ re: /(?<![\w-])shadow-(?:xs|sm|md|lg|xl|2xl)(?![\w-])/g, why: 'sombra de la escala Tailwind (usa shadow-card/control/raised/overlay/popover)' },
|
|
490
|
-
{ re: /(?<![\w-])text-\[\d+px\]/g, why: 'tamaño de texto arbitrario (usa la escala estándar)' },
|
|
491
|
-
{ re: /(?<![\w-])rounded-(?:3xl|4xl)(?![\w-])/g, why: 'radio fuera de la rampa (usa rounded-control/overlay o la rampa sm…2xl)' },
|
|
492
|
-
{ re: /(?<![\w-])(?:bg|text|border|ring|fill|stroke)-(?:red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose|slate|gray|zinc|neutral|stone)-\d{2,3}(?![\w-])/g, why: 'color de la paleta Tailwind (usa tokens del tema)' },
|
|
493
|
-
];
|
|
494
|
-
|
|
495
|
-
const uiDir = join(ROOT, 'src/ui');
|
|
496
|
-
if (existsSync(uiDir)) {
|
|
497
|
-
for (const f of readdirSync(uiDir).filter((n) => n.endsWith('.tsx'))) {
|
|
498
|
-
const lines = read(join(uiDir, f)).split(/\r?\n/);
|
|
499
|
-
lines.forEach((line, i) => {
|
|
500
|
-
const code = line.replace(/\/\/.*$/, '');
|
|
501
|
-
for (const rule of NO_HARDCODE) {
|
|
502
|
-
if (rule.skip?.includes(f)) continue;
|
|
503
|
-
const hits = code.match(rule.re);
|
|
504
|
-
if (hits) errors.push(`ui/${f}:${i + 1}: ${rule.why} → ${[...new Set(hits)].join(', ')}`);
|
|
505
|
-
}
|
|
506
|
-
});
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
// 5b) UI DE UNA APP (--ui <carpeta>): el código de las vistas no se sale del sistema. Mismas reglas
|
|
511
|
-
// visuales que los componentes (sin las de textos: la app tiene su i18n) y tres propias de una app.
|
|
512
|
-
// Son las comprobaciones mecánicas del diseñador (docs/designer/revision.md, apartado A).
|
|
513
|
-
{
|
|
514
|
-
const i = process.argv.indexOf('--ui');
|
|
515
|
-
if (i > -1 && process.argv[i + 1]) {
|
|
516
|
-
const base = resolve(process.argv[i + 1]);
|
|
517
|
-
const VISUALES = NO_HARDCODE.filter((r) => !/texto/.test(r.why));
|
|
518
|
-
const APP = [
|
|
519
|
-
{ re: /(?<![\w-])(?:-?(?:p|px|py|pt|pb|ps|pe|pl|pr|m|mx|my|mt|mb|ms|me|ml|mr|gap|gap-x|gap-y|w|h|min-w|min-h|max-w|max-h|size|top|bottom|left|right|start|end|inset|leading|tracking|rounded|border)-\[-?\d*\.?\d+(?:px|rem|em)\])/g, why: 'medida arbitraria (usa la escala, un token --ds-* o la variante del componente)' },
|
|
520
|
-
{ re: /(?<![\w-])(?:rounded|shadow|font|bg|text|border|ring)-\[(?!var\(|--|length:var|color:var)[^\]]+\]/g, why: 'valor arbitrario visual (usa un token del tema)' },
|
|
521
|
-
{ cadenas: true, re: /(?<=^|\s)![a-z][\w:/()[\]-]*/g, why: '!important en una clase (no se pelea con la librería: ajusta en brand.css o abre un hueco)' },
|
|
522
|
-
{ re: /<(?:button|input|select|textarea)\b(?![^>]*data-slot)/g, why: 'control nativo suelto (usa Button, Input, Select/NativeSelect o Textarea de orbital-ds)' },
|
|
523
|
-
];
|
|
524
|
-
const ficheros = [];
|
|
525
|
-
const recorrer = (d) => {
|
|
526
|
-
if (!existsSync(d)) return;
|
|
527
|
-
for (const n of readdirSync(d, { withFileTypes: true })) {
|
|
528
|
-
if (n.name === 'node_modules' || n.name.startsWith('.')) continue;
|
|
529
|
-
const p = join(d, n.name);
|
|
530
|
-
if (n.isDirectory()) recorrer(p);
|
|
531
|
-
else if (/\.(tsx|jsx)$/.test(n.name)) ficheros.push(p);
|
|
532
|
-
}
|
|
533
|
-
};
|
|
534
|
-
recorrer(base);
|
|
535
|
-
if (!ficheros.length) warnings.push(`ui: no hay ficheros .tsx/.jsx en ${process.argv[i + 1]}`);
|
|
536
|
-
for (const f of ficheros) {
|
|
537
|
-
read(f).split(/\r?\n/).forEach((line, n) => {
|
|
538
|
-
const code = line.replace(/\/\/.*$/, '');
|
|
539
|
-
// Las reglas «de cadenas» solo miran dentro de literales ("…", '…', `…`): así `{!loading && …}` no cuenta.
|
|
540
|
-
const cadenas = [...code.matchAll(/"([^"]*)"|'([^']*)'|`([^`]*)`/g)].map((m) => m[1] ?? m[2] ?? m[3]);
|
|
541
|
-
for (const rule of [...VISUALES, ...APP]) {
|
|
542
|
-
const hits = rule.cadenas ? cadenas.flatMap((c) => c.match(rule.re) ?? []) : code.match(rule.re);
|
|
543
|
-
if (hits?.length) errors.push(`ui ${f.replace(process.cwd(), '.').split('\\').join('/')}:${n + 1}: ${rule.why} → ${[...new Set(hits)].join(', ')}`);
|
|
544
|
-
}
|
|
545
|
-
});
|
|
546
|
-
}
|
|
547
|
-
if (ficheros.length) console.log(`ui: ${ficheros.length} fichero(s) revisados en ${process.argv[i + 1]}`);
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
// 6) API pública frente a la huella commiteada
|
|
552
|
-
const manifestPath = join(ROOT, 'components.manifest.json');
|
|
553
|
-
if (existsSync(manifestPath) && existsSync(uiDir)) {
|
|
554
|
-
const { buildManifest } = await import('./manifest.mjs');
|
|
555
|
-
const before = JSON.parse(read(manifestPath)).components;
|
|
556
|
-
const now = buildManifest().components;
|
|
557
|
-
for (const [name, comp] of Object.entries(before)) {
|
|
558
|
-
if (!now[name]) {
|
|
559
|
-
errors.push(`API pública: desaparece el componente «${name}» (¿versión mayor? regenera con pnpm manifest)`);
|
|
560
|
-
continue;
|
|
561
|
-
}
|
|
562
|
-
for (const e of comp.exports) {
|
|
563
|
-
if (!now[name].exports.includes(e)) {
|
|
564
|
-
errors.push(`API pública: «${name}» ya no exporta ${e} (¿versión mayor? regenera con pnpm manifest)`);
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
const added = Object.keys(now).filter((n) => !before[n]);
|
|
569
|
-
if (added.length) warnings.push(`API pública: componentes nuevos sin registrar en el manifiesto (${added.join(', ')}); ejecuta pnpm manifest`);
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
for (const w of warnings) console.log(`AVISO ${w}`);
|
|
573
|
-
for (const e of errors) console.log(`ERROR ${e}`);
|
|
574
|
-
if (errors.length) {
|
|
575
|
-
console.log(`\ndoctor: ${errors.length} error(es), ${warnings.length} aviso(s)`);
|
|
576
|
-
process.exit(1);
|
|
577
|
-
}
|
|
578
|
-
console.log(`doctor: contrato, repetidos, sombras, fugas, valores fijos y API pública correctos (${warnings.length} aviso(s)).`);
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* orbital-ds doctor — comprueba que el sistema se cumple.
|
|
4
|
+
*
|
|
5
|
+
* 1. CONTRATO: cada tema (themes/*.css) define en :root todos los tokens de
|
|
6
|
+
* contract.json y la fuente `--ds-font-sans`. En .dark solo avisa.
|
|
7
|
+
* 2. REPETIDOS: ninguna variable se define dos veces en el mismo bloque.
|
|
8
|
+
* 3. SOMBRAS: «sin sombra» es `0 0 #0000`, nunca `none` (una variable con
|
|
9
|
+
* `none` invalida todo el box-shadow, anillo de foco incluido).
|
|
10
|
+
* 4. FUGAS: el tema base (contract.baseTheme) está aplicado siempre; todo tema
|
|
11
|
+
* con ámbito debe definir cada `--ds-*` que defina el base, o su valor se
|
|
12
|
+
* colaría al cambiar de tema.
|
|
13
|
+
* 5. VALORES FIJOS: ningún componente (ui/*.tsx) escribe colores, z-index,
|
|
14
|
+
* duraciones ni sombras a mano; todo sale de tokens.
|
|
15
|
+
* 6. API PÚBLICA: no desaparece ningún componente ni export respecto a
|
|
16
|
+
* components.manifest.json (huella de la última versión). Lo nuevo solo avisa.
|
|
17
|
+
* 7. PERSONALIDAD: las reglas de un tema solo usan variables y estilizan familias
|
|
18
|
+
* completas de piezas (contract.slotFamilies). Error si la ficha del tema dice
|
|
19
|
+
* `"conformance": "strict"`; aviso en los demás.
|
|
20
|
+
*
|
|
21
|
+
* Uso:
|
|
22
|
+
* node scripts/doctor.mjs # temas y componentes del paquete
|
|
23
|
+
* node scripts/doctor.mjs --css app.css # además, un CSS de una app (repetidos)
|
|
24
|
+
*
|
|
25
|
+
* Sale con código 1 si hay errores (los avisos no fallan).
|
|
26
|
+
*/
|
|
27
|
+
import { readFileSync, readdirSync, existsSync } from 'node:fs';
|
|
28
|
+
import { join, dirname, resolve } from 'node:path';
|
|
29
|
+
import { fileURLToPath } from 'node:url';
|
|
30
|
+
|
|
31
|
+
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
32
|
+
const contract = JSON.parse(readFileSync(join(ROOT, 'contract.json'), 'utf8'));
|
|
33
|
+
|
|
34
|
+
const errors = [];
|
|
35
|
+
const warnings = [];
|
|
36
|
+
const read = (p) => readFileSync(p, 'utf8');
|
|
37
|
+
const stripComments = (css) => css.replace(/\/\*[\s\S]*?\*\//g, '');
|
|
38
|
+
|
|
39
|
+
/** Cuerpo de cada bloque `selector { ... }` (respeta llaves anidadas). */
|
|
40
|
+
function blocks(css, selectorRe) {
|
|
41
|
+
const out = [];
|
|
42
|
+
const re = new RegExp(selectorRe.source + '\\s*\\{', 'g');
|
|
43
|
+
let m;
|
|
44
|
+
while ((m = re.exec(css))) {
|
|
45
|
+
let depth = 1;
|
|
46
|
+
let i = re.lastIndex;
|
|
47
|
+
const start = i;
|
|
48
|
+
while (i < css.length && depth > 0) {
|
|
49
|
+
if (css[i] === '{') depth++;
|
|
50
|
+
else if (css[i] === '}') depth--;
|
|
51
|
+
i++;
|
|
52
|
+
}
|
|
53
|
+
out.push(css.slice(start, i - 1));
|
|
54
|
+
re.lastIndex = i;
|
|
55
|
+
}
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Declaraciones `--x: valor;` del nivel superior de un bloque (no las anidadas). */
|
|
60
|
+
function declarations(body) {
|
|
61
|
+
let depth = 0;
|
|
62
|
+
let top = '';
|
|
63
|
+
for (const ch of body) {
|
|
64
|
+
if (ch === '{') depth++;
|
|
65
|
+
else if (ch === '}') depth--;
|
|
66
|
+
else if (depth === 0) top += ch;
|
|
67
|
+
}
|
|
68
|
+
return [...top.matchAll(/(^|[;\s])(--[a-z0-9-]+)\s*:\s*([^;]*);?/gi)].map((m) => ({ name: m[2], value: m[3].trim() }));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Variables --ds-* que la estructura del paquete define (las que una app puede usar). */
|
|
72
|
+
/** CSS de la estructura: src/ en el repo; dist/ en el paquete instalado (npm no publica src/). */
|
|
73
|
+
const STRUCTURE_CSS = existsSync(join(ROOT, 'src/styles.css')) ? join(ROOT, 'src/styles.css') : join(ROOT, 'dist/styles.css');
|
|
74
|
+
|
|
75
|
+
function knownDsVars() {
|
|
76
|
+
return new Set([...read(STRUCTURE_CSS).matchAll(/(--ds-[a-z0-9-]+)\s*:/g)].map((m) => m[1]));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// El grupo de marca debe ser coherente con el contrato: cada variable, o es del contrato, o es --ds-*.
|
|
80
|
+
for (const t of contract.brand?.tokens ?? []) {
|
|
81
|
+
const inContract =
|
|
82
|
+
contract.root.includes(t.name) ||
|
|
83
|
+
contract.fonts.includes(t.name) ||
|
|
84
|
+
(t.name.startsWith('ds-') && knownDsVars().has(`--${t.name}`));
|
|
85
|
+
if (!inContract) errors.push(`contrato: la variable de marca --${t.name} ni es del contrato ni la define la estructura`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const themeInfo = {}; // nombre → { rootVars:Set, darkVars:Set }
|
|
89
|
+
|
|
90
|
+
function checkTheme(file, name) {
|
|
91
|
+
const label = `tema ${name}`;
|
|
92
|
+
const css = stripComments(read(file));
|
|
93
|
+
const roots = blocks(css, /(?:^|[\s}])\:root/);
|
|
94
|
+
const darks = blocks(css, /(?:^|[\s}])\.dark/);
|
|
95
|
+
|
|
96
|
+
const rootDecl = roots.flatMap(declarations);
|
|
97
|
+
const darkDecl = darks.flatMap(declarations);
|
|
98
|
+
const rootVars = new Set(rootDecl.map((d) => d.name));
|
|
99
|
+
const darkVars = new Set(darkDecl.map((d) => d.name));
|
|
100
|
+
themeInfo[name] = { rootVars, darkVars };
|
|
101
|
+
|
|
102
|
+
for (const t of contract.root) {
|
|
103
|
+
if (!rootVars.has(`--${t}`)) errors.push(`${label}: falta el token obligatorio --${t} en :root`);
|
|
104
|
+
}
|
|
105
|
+
for (const f of contract.fonts) {
|
|
106
|
+
if (!rootVars.has(`--${f}`)) errors.push(`${label}: falta la fuente --${f} en :root`);
|
|
107
|
+
}
|
|
108
|
+
if (darks.length) {
|
|
109
|
+
for (const t of contract.dark.avisar_si_falta) {
|
|
110
|
+
if (!darkVars.has(`--${t}`)) warnings.push(`${label}: .dark no redefine --${t} (hereda el valor claro)`);
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
warnings.push(`${label}: no define piel .dark`);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Repetidos (solo declaraciones del nivel superior de cada bloque)
|
|
117
|
+
for (const [kind, list] of [[':root', roots], ['.dark', darks]]) {
|
|
118
|
+
list.forEach((body, idx) => {
|
|
119
|
+
const seen = new Map();
|
|
120
|
+
for (const d of declarations(body)) seen.set(d.name, (seen.get(d.name) ?? 0) + 1);
|
|
121
|
+
for (const [v, n] of seen) {
|
|
122
|
+
if (n > 1) errors.push(`${label}: ${v} definido ${n} veces en el mismo bloque ${kind} (#${idx + 1})`);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Sombras: `none` invalida el box-shadow
|
|
128
|
+
for (const d of [...rootDecl, ...darkDecl]) {
|
|
129
|
+
if (/^--ds-(?:shadow|sidebar-shadow)/.test(d.name) && /^none$/i.test(d.value)) {
|
|
130
|
+
errors.push(`${label}: ${d.name}: none — usa «0 0 #0000» (none invalida todo el box-shadow)`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// 1+2+3) temas
|
|
136
|
+
const themesDir = join(ROOT, existsSync(join(ROOT, 'src/themes')) ? 'src/themes' : 'dist/themes');
|
|
137
|
+
const themeFiles = readdirSync(themesDir).filter(
|
|
138
|
+
(n) => n.endsWith('.css') && !n.endsWith('.fonts.css') && !n.endsWith('.scoped.css'),
|
|
139
|
+
);
|
|
140
|
+
for (const f of themeFiles) checkTheme(join(themesDir, f), f.replace(/\.css$/, ''));
|
|
141
|
+
|
|
142
|
+
// 1b) documentación de cada tema: guía de diseño (.guide.md) + ficha legible por máquina (.meta.json)
|
|
143
|
+
const META_CLAVES = ['name', 'label', 'essence', 'signature', 'fonts', 'palette', 'references', 'status', 'guide'];
|
|
144
|
+
for (const f of themeFiles) {
|
|
145
|
+
const t = f.replace(/\.css$/, '');
|
|
146
|
+
if (!existsSync(join(themesDir, `${t}.guide.md`))) errors.push(`tema ${t}: falta ${t}.guide.md (guía de diseño)`);
|
|
147
|
+
const metaPath = join(themesDir, `${t}.meta.json`);
|
|
148
|
+
if (!existsSync(metaPath)) { errors.push(`tema ${t}: falta ${t}.meta.json (ficha del tema)`); continue; }
|
|
149
|
+
let meta;
|
|
150
|
+
try { meta = JSON.parse(read(metaPath)); } catch { errors.push(`tema ${t}: ${t}.meta.json no es JSON válido`); continue; }
|
|
151
|
+
for (const k of META_CLAVES) if (!(k in meta)) errors.push(`tema ${t}: ${t}.meta.json no define «${k}»`);
|
|
152
|
+
if (meta.name !== t) errors.push(`tema ${t}: ${t}.meta.json tiene name «${meta.name}»`);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// 1d) PESOS CARGADOS: cada --ds-*-weight que pide el tema (o hereda de la estructura) debe
|
|
156
|
+
// estar entre los que cargan sus fuentes (<tema>.fonts.css, Google Fonts). Si no, el
|
|
157
|
+
// navegador pinta otro peso (500 sin cargar se ve 400) y el aspecto no es el del tema.
|
|
158
|
+
// Temas con fuentes del sistema (sin @import de Google Fonts): no se comprueba.
|
|
159
|
+
{
|
|
160
|
+
const estructura = read(STRUCTURE_CSS);
|
|
161
|
+
const pesosBase = {};
|
|
162
|
+
for (const [, k, v] of estructura.matchAll(/(--ds-[\w-]*weight)\s*:\s*([^;]+);/g)) if (!(k in pesosBase)) pesosBase[k] = v.trim();
|
|
163
|
+
for (const f of themeFiles) {
|
|
164
|
+
const t = f.replace(/\.css$/, '');
|
|
165
|
+
const fontsPath = join(themesDir, `${t}.fonts.css`);
|
|
166
|
+
if (!existsSync(fontsPath)) continue;
|
|
167
|
+
const url = (read(fontsPath).match(/fonts\.googleapis\.com\/css2\?([^'")]+)/) ?? [])[1];
|
|
168
|
+
if (!url) continue;
|
|
169
|
+
const cargados = [];
|
|
170
|
+
for (const [, fam] of url.matchAll(/family=([^&]+)/g)) {
|
|
171
|
+
const [, ejes = '', tuplas = ''] = fam.match(/:([^@]+)@(.+)$/) ?? [];
|
|
172
|
+
const i = ejes.split(',').indexOf('wght');
|
|
173
|
+
if (i < 0) { cargados.push([400, 400]); continue; }
|
|
174
|
+
for (const tupla of tuplas.split(';')) {
|
|
175
|
+
const v = tupla.split(',')[i] ?? '';
|
|
176
|
+
const [a, b = a] = v.split('..').map(Number);
|
|
177
|
+
if (Number.isFinite(a)) cargados.push([a, b]);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
if (!cargados.length) continue;
|
|
181
|
+
const css = read(join(themesDir, f)).replace(/\/\*[\s\S]*?\*\//g, '');
|
|
182
|
+
const pesos = { ...pesosBase };
|
|
183
|
+
for (const [, cuerpo] of css.matchAll(/:root\s*\{([^{}]*)\}/g)) for (const [, k, v] of cuerpo.matchAll(/(--ds-[\w-]*weight)\s*:\s*([^;]+);/g)) pesos[k] = v.trim();
|
|
184
|
+
const valor = (v, n = 0) => { const m = v.match(/^var\((--[\w-]+)(?:,\s*([^)]+))?\)$/); return m && n < 8 ? valor(pesos[m[1]] ?? m[2] ?? '', n + 1) : v; };
|
|
185
|
+
for (const [k, v] of Object.entries(pesos)) {
|
|
186
|
+
const p = Number(valor(v));
|
|
187
|
+
if (!Number.isFinite(p)) continue;
|
|
188
|
+
if (!cargados.some(([a, b]) => p >= a && p <= b))
|
|
189
|
+
warnings.push(`tema ${t}: ${k} = ${p}, pero ${t}.fonts.css no carga ese peso (carga ${[...new Set(cargados.map(([a, b]) => (a === b ? a : `${a}–${b}`)))].join(', ')}): el navegador pintará otro`);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// 1e) MOVIMIENTO AUTOMÁTICO: cada --ds-enter-<grupo> del tema es del catálogo de motion.css
|
|
195
|
+
// (@keyframes ds-auto-*) o `none`, y la ficha lo declara igual en motion.auto.<grupo>.
|
|
196
|
+
// Coherencia mecánica; el criterio estético (que el tipo encaje con el tema) es de la revisión.
|
|
197
|
+
{
|
|
198
|
+
const motionCss = existsSync(join(ROOT, 'src/motion.css')) ? join(ROOT, 'src/motion.css') : join(ROOT, 'dist/motion.css');
|
|
199
|
+
if (existsSync(motionCss)) {
|
|
200
|
+
const catalogo = new Set([...read(motionCss).matchAll(/@keyframes\s+(ds-auto-[\w-]+)/g)].map((m) => m[1]));
|
|
201
|
+
catalogo.add('none');
|
|
202
|
+
for (const f of themeFiles) {
|
|
203
|
+
const t = f.replace(/\.css$/, '');
|
|
204
|
+
const css = read(join(themesDir, f)).replace(/\/\*[\s\S]*?\*\//g, '');
|
|
205
|
+
const valores = {};
|
|
206
|
+
for (const [, cuerpo] of css.matchAll(/:root\s*\{([^{}]*)\}/g))
|
|
207
|
+
for (const [, g, v] of cuerpo.matchAll(/--ds-enter-([\w-]+)\s*:\s*([^;]+);/g)) valores[g] = v.trim();
|
|
208
|
+
let auto = {};
|
|
209
|
+
try { auto = JSON.parse(read(join(themesDir, `${t}.meta.json`))).motion?.auto ?? {}; } catch { /* lo avisa 1b */ }
|
|
210
|
+
for (const [g, v] of Object.entries(valores)) {
|
|
211
|
+
if (!catalogo.has(v)) errors.push(`tema ${t}: --ds-enter-${g} = «${v}» no es del catálogo (${[...catalogo].join(', ')})`);
|
|
212
|
+
if (auto[g] !== v) errors.push(`tema ${t}: --ds-enter-${g} = «${v}» pero su ficha dice motion.auto.${g} = «${auto[g] ?? '—'}»`);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// 1c) CONTRASTE de los textos de estado: info, danger, warning, success y neutral
|
|
219
|
+
// sobre su fondo suave (compuesto sobre el lienzo), mínimo WCAG AA 4.5:1, en claro y oscuro.
|
|
220
|
+
// No incluye `link` ni `primary-foreground`: dependen de colores de marca fijados por la
|
|
221
|
+
// identidad (p. ej. el azul de Twitter), y se documentan como limitación en la guía del tema.
|
|
222
|
+
{
|
|
223
|
+
const parseColor = (raw) => {
|
|
224
|
+
const v = raw.replace(/\s+/g, ' ').trim();
|
|
225
|
+
let m = v.match(/^#([0-9a-f]{3,8})$/i);
|
|
226
|
+
if (m) {
|
|
227
|
+
let h = m[1];
|
|
228
|
+
if (h.length === 3) h = [...h].map((c) => c + c).join('');
|
|
229
|
+
return { r: parseInt(h.slice(0, 2), 16), g: parseInt(h.slice(2, 4), 16), b: parseInt(h.slice(4, 6), 16), a: h.length === 8 ? parseInt(h.slice(6, 8), 16) / 255 : 1 };
|
|
230
|
+
}
|
|
231
|
+
m = v.match(/^rgba?\(([^)]+)\)$/i);
|
|
232
|
+
if (m) { const p = m[1].split(/[ ,/]+/).filter(Boolean).map(Number); return { r: p[0], g: p[1], b: p[2], a: p[3] ?? 1 }; }
|
|
233
|
+
m = v.match(/^oklch\(\s*([\d.]+%?)\s+([\d.]+)\s+([\d.]+)(?:\s*\/\s*([\d.]+%?))?\s*\)$/i);
|
|
234
|
+
if (m) {
|
|
235
|
+
const L = m[1].endsWith('%') ? parseFloat(m[1]) / 100 : +m[1];
|
|
236
|
+
const C = +m[2], H = (+m[3] * Math.PI) / 180;
|
|
237
|
+
const a = C * Math.cos(H), b = C * Math.sin(H);
|
|
238
|
+
const l = (L + 0.3963377774 * a + 0.2158037573 * b) ** 3;
|
|
239
|
+
const mm = (L - 0.1055613458 * a - 0.0638541728 * b) ** 3;
|
|
240
|
+
const s = (L - 0.0894841775 * a - 1.291485548 * b) ** 3;
|
|
241
|
+
const lin = [4.0767416621 * l - 3.3077115913 * mm + 0.2309699292 * s, -1.2684380046 * l + 2.6097574011 * mm - 0.3413193965 * s, -0.0041960863 * l - 0.7034186147 * mm + 1.707614701 * s];
|
|
242
|
+
const g = (x) => Math.round(255 * Math.min(1, Math.max(0, x <= 0.0031308 ? 12.92 * x : 1.055 * x ** (1 / 2.4) - 0.055)));
|
|
243
|
+
const al = m[4] ? (m[4].endsWith('%') ? parseFloat(m[4]) / 100 : +m[4]) : 1;
|
|
244
|
+
return { r: g(lin[0]), g: g(lin[1]), b: g(lin[2]), a: al };
|
|
245
|
+
}
|
|
246
|
+
return null;
|
|
247
|
+
};
|
|
248
|
+
const lum = ({ r, g, b }) => {
|
|
249
|
+
const f = (c) => { c /= 255; return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4; };
|
|
250
|
+
return 0.2126 * f(r) + 0.7152 * f(g) + 0.0722 * f(b);
|
|
251
|
+
};
|
|
252
|
+
const over = (fg, bg) => ({ r: fg.r * fg.a + bg.r * (1 - fg.a), g: fg.g * fg.a + bg.g * (1 - fg.a), b: fg.b * fg.a + bg.b * (1 - fg.a), a: 1 });
|
|
253
|
+
const ratio = (x, y) => { const [p, q] = [lum(x), lum(y)].sort((u, w) => w - u); return (p + 0.05) / (q + 0.05); };
|
|
254
|
+
const varsDe = (css, selector) => {
|
|
255
|
+
const m = new RegExp(`(^|\\n)${selector}\\s*\\{`).exec(css);
|
|
256
|
+
if (!m) return {};
|
|
257
|
+
let i = m.index + m[0].length, d = 1, j = i;
|
|
258
|
+
while (d && j < css.length) { if (css[j] === '{') d++; else if (css[j] === '}') d--; j++; }
|
|
259
|
+
const out = {};
|
|
260
|
+
for (const mm of css.slice(i, j - 1).matchAll(/--([\w-]+):\s*([^;]+);/g)) out[mm[1]] = mm[2];
|
|
261
|
+
return out;
|
|
262
|
+
};
|
|
263
|
+
// Qué se mide: cada tema y, con `--css`, la marca/variante de la app ENCIMA de su tema base
|
|
264
|
+
// (`--theme <t>` o un comentario `@base-theme <t>` en el fichero).
|
|
265
|
+
const objetivos = themeFiles.map((f) => {
|
|
266
|
+
const css = stripComments(read(join(themesDir, f)));
|
|
267
|
+
const tema = f.replace(/\.css$/, '');
|
|
268
|
+
return { tema, etiqueta: `tema ${tema}`, claro: varsDe(css, ':root'), oscuro: varsDe(css, '\\.dark') };
|
|
269
|
+
});
|
|
270
|
+
const iCss = process.argv.indexOf('--css');
|
|
271
|
+
if (iCss > -1 && process.argv[iCss + 1]) {
|
|
272
|
+
const crudo = read(resolve(process.argv[iCss + 1]));
|
|
273
|
+
const iTheme = process.argv.indexOf('--theme');
|
|
274
|
+
const base = (iTheme > -1 && process.argv[iTheme + 1]) || crudo.match(/@base-theme\s+([\w-]+)/)?.[1] || null;
|
|
275
|
+
const t = base && objetivos.find((o) => o.tema === base);
|
|
276
|
+
const app = stripComments(crudo);
|
|
277
|
+
if (t) {
|
|
278
|
+
objetivos.push({
|
|
279
|
+
tema: base,
|
|
280
|
+
etiqueta: `marca ${process.argv[iCss + 1]} (sobre ${base})`,
|
|
281
|
+
claro: { ...t.claro, ...varsDe(app, ':root') },
|
|
282
|
+
oscuro: { ...t.oscuro, ...varsDe(app, '\\.dark') },
|
|
283
|
+
});
|
|
284
|
+
} else {
|
|
285
|
+
warnings.push('app css: no sé sobre qué tema medir el contraste; pasa --theme <tema> o pon «@base-theme <tema>» en el fichero');
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
for (const { tema, etiqueta, claro, oscuro } of objetivos) {
|
|
289
|
+
// Resuelve `var(--x)` (y `var(--x, respaldo)`) dentro del mismo tema: un color derivado
|
|
290
|
+
// de otro (p. ej. `--sidebar-primary: var(--primary)`) también se mide.
|
|
291
|
+
const resolver = (vars) => {
|
|
292
|
+
const out = {};
|
|
293
|
+
for (const [k, v0] of Object.entries(vars)) {
|
|
294
|
+
let v = v0.trim();
|
|
295
|
+
for (let n = 0; n < 8; n++) {
|
|
296
|
+
const m = v.match(/^var\(--([\w-]+)(?:\s*,\s*([\s\S]+))?\)$/);
|
|
297
|
+
if (!m) break;
|
|
298
|
+
v = (vars[m[1]] ?? m[2] ?? '').trim();
|
|
299
|
+
}
|
|
300
|
+
out[k] = v;
|
|
301
|
+
}
|
|
302
|
+
return out;
|
|
303
|
+
};
|
|
304
|
+
for (const [piel, vars] of [['claro', resolver(claro)], ['oscuro', resolver({ ...claro, ...oscuro })]]) {
|
|
305
|
+
const lienzo = parseColor(vars.background ?? '#fff');
|
|
306
|
+
if (!lienzo) continue;
|
|
307
|
+
let excepciones = [];
|
|
308
|
+
try { excepciones = JSON.parse(read(join(themesDir, `${tema}.meta.json`))).a11y?.exceptions ?? []; } catch { /* sin ficha: lo avisa 1b */ }
|
|
309
|
+
for (const estado of ['info', 'danger', 'warning', 'success', 'neutral']) {
|
|
310
|
+
// Texto sobre el fondo suave: --ds-on-soft si el tema lo define (tinta); si no, el color del estado.
|
|
311
|
+
const tinta = vars['ds-on-soft'];
|
|
312
|
+
const fg = parseColor(tinta || vars[estado] || '');
|
|
313
|
+
const suave = vars[`${estado}-soft`] && parseColor(vars[`${estado}-soft`]);
|
|
314
|
+
if (!fg || !suave) continue;
|
|
315
|
+
const fondo = over(suave, over(lienzo, { r: 255, g: 255, b: 255, a: 1 }));
|
|
316
|
+
const r = ratio(over(fg, fondo), fondo);
|
|
317
|
+
if (r < 4.5) {
|
|
318
|
+
const msg = `${etiqueta} (${piel}): ${tinta ? '--ds-on-soft' : estado} sobre ${estado}-soft = ${r.toFixed(2)}:1 (mínimo 4.5:1)`;
|
|
319
|
+
if (excepciones.includes(`${estado}/${estado}-soft`)) warnings.push(`${msg} — excepción declarada en la ficha`);
|
|
320
|
+
else errors.push(`${msg}; corrígelo o decláralo en ${tema}.meta.json → a11y.exceptions ("${estado}/${estado}-soft")`);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// Pares principales de texto sobre su superficie. AA (4.5:1) es el mínimo exigible; las
|
|
325
|
+
// excepciones deben estar declaradas en `<tema>.meta.json` → `a11y.exceptions` ("fg/bg").
|
|
326
|
+
// AAA (7:1) es el objetivo del texto del cuerpo: solo avisa, y solo con `--aaa`.
|
|
327
|
+
const PARES = [
|
|
328
|
+
['foreground', 'background'], ['card-foreground', 'card'], ['popover-foreground', 'popover'],
|
|
329
|
+
['primary-foreground', 'primary'], ['secondary-foreground', 'secondary'],
|
|
330
|
+
['muted-foreground', 'background'], ['muted-foreground', 'card'],
|
|
331
|
+
['sidebar-foreground', 'sidebar'], ['sidebar-primary-foreground', 'sidebar-primary'],
|
|
332
|
+
['destructive-foreground', 'destructive'],
|
|
333
|
+
];
|
|
334
|
+
const blanco = { r: 255, g: 255, b: 255, a: 1 };
|
|
335
|
+
for (const [fgName, bgName] of PARES) {
|
|
336
|
+
const fgRaw = vars[fgName] && parseColor(vars[fgName]);
|
|
337
|
+
const bgRaw = vars[bgName] && parseColor(vars[bgName]);
|
|
338
|
+
if (!fgRaw || !bgRaw) continue;
|
|
339
|
+
const bg = over(bgRaw, over(lienzo, blanco));
|
|
340
|
+
const r = ratio(over(fgRaw, bg), bg);
|
|
341
|
+
const par = `${fgName}/${bgName}`;
|
|
342
|
+
if (r < 4.5) {
|
|
343
|
+
const msg = `${etiqueta} (${piel}): ${par} = ${r.toFixed(2)}:1 (mínimo AA 4.5:1)`;
|
|
344
|
+
if (excepciones.includes(par)) warnings.push(`${msg} — excepción declarada en la ficha`);
|
|
345
|
+
else errors.push(`${msg}; corrígelo o decláralo en ${tema}.meta.json → a11y.exceptions`);
|
|
346
|
+
} else if (process.argv.includes('--aaa') && r < 7 && (par === 'foreground/background' || par === 'card-foreground/card')) {
|
|
347
|
+
warnings.push(`${etiqueta} (${piel}): ${par} = ${r.toFixed(2)}:1 (objetivo AAA 7:1 para el texto del cuerpo)`);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// 4) fugas desde el tema base
|
|
355
|
+
const base = contract.baseTheme;
|
|
356
|
+
if (base && themeInfo[base]) {
|
|
357
|
+
const baseDs = [...themeInfo[base].rootVars].filter((v) => v.startsWith('--ds-'));
|
|
358
|
+
for (const [name, info] of Object.entries(themeInfo)) {
|
|
359
|
+
if (name === base) continue;
|
|
360
|
+
for (const v of baseDs) {
|
|
361
|
+
if (!info.rootVars.has(v)) {
|
|
362
|
+
errors.push(`tema ${name}: no define ${v}, que sí define el tema base «${base}» — su valor se colaría al cambiar de tema`);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// 7) PERSONALIDAD: solo variables y familias completas.
|
|
369
|
+
// a) Una regla de personalidad (cualquier propiedad que no sea `--x`) no escribe
|
|
370
|
+
// medidas, colores, pesos, opacidades ni duraciones: pide un hueco a una variable.
|
|
371
|
+
// b) Si estiliza una pieza de una familia (contract.slotFamilies), estiliza todas.
|
|
372
|
+
// Error en los temas con `"conformance": "strict"` en su ficha; aviso en los demás.
|
|
373
|
+
{
|
|
374
|
+
/** Declaraciones de propiedades normales (no `--x`) de un CSS, con su selector. */
|
|
375
|
+
const propertyDecls = (css) => {
|
|
376
|
+
const out = [];
|
|
377
|
+
const stack = [];
|
|
378
|
+
let buf = '';
|
|
379
|
+
for (const ch of css) {
|
|
380
|
+
if (ch === '{') { stack.push(buf.trim()); buf = ''; }
|
|
381
|
+
else if (ch === ';' || ch === '}') {
|
|
382
|
+
const d = buf.trim();
|
|
383
|
+
const m = d.match(/^([a-z-]+)\s*:\s*([\s\S]+)$/i);
|
|
384
|
+
if (stack.length && m && !d.startsWith('--')) out.push({ selector: stack.at(-1), prop: m[1], value: m[2].trim() });
|
|
385
|
+
buf = '';
|
|
386
|
+
if (ch === '}') stack.pop();
|
|
387
|
+
} else buf += ch;
|
|
388
|
+
}
|
|
389
|
+
return out;
|
|
390
|
+
};
|
|
391
|
+
const LITERALES = [
|
|
392
|
+
{ re: /(?<![\w.-])\d*\.?\d+(?:px|rem|em|ch|vh|vw)\b/g, why: 'medida' },
|
|
393
|
+
{ re: /#[0-9a-f]{3,8}\b/gi, why: 'color' },
|
|
394
|
+
{ re: /\b(?:rgba?|hsla?|oklch|oklab)\(/gi, why: 'color' },
|
|
395
|
+
{ re: /(?<![\w.-])\d*\.?\d+m?s\b/g, why: 'duración' },
|
|
396
|
+
];
|
|
397
|
+
const NUMERICAS = { 'font-weight': 'peso', opacity: 'opacidad', 'z-index': 'capa', 'line-height': 'interlineado' };
|
|
398
|
+
const familias = Object.entries(contract.slotFamilies?.families ?? {});
|
|
399
|
+
for (const f of themeFiles) {
|
|
400
|
+
const tema = f.replace(/\.css$/, '');
|
|
401
|
+
let estricto = false;
|
|
402
|
+
try { estricto = JSON.parse(read(join(themesDir, `${tema}.meta.json`))).conformance === 'strict'; } catch { /* lo avisa 1b */ }
|
|
403
|
+
const report = (msg) => (estricto ? errors : warnings).push(`tema ${tema}: ${msg}`);
|
|
404
|
+
const decls = propertyDecls(stripComments(read(join(themesDir, f))));
|
|
405
|
+
|
|
406
|
+
const vistos = new Set();
|
|
407
|
+
for (const { selector, prop, value } of decls) {
|
|
408
|
+
const sinVar = value.replace(/var\([^()]*(?:\([^()]*\)[^()]*)*\)/g, '');
|
|
409
|
+
const hits = LITERALES.flatMap((r) => (sinVar.match(r.re) ?? []).map((h) => `${r.why} ${h}`));
|
|
410
|
+
if (NUMERICAS[prop] && /^\d*\.?\d+$/.test(value)) hits.push(`${NUMERICAS[prop]} ${value}`);
|
|
411
|
+
for (const h of hits) {
|
|
412
|
+
const clave = `${selector}|${prop}|${h}`;
|
|
413
|
+
if (vistos.has(clave)) continue;
|
|
414
|
+
vistos.add(clave);
|
|
415
|
+
report(`personalidad con valor fijo (${h}) en «${prop}» de ${selector.replace(/\s+/g, ' ')} — usa una variable`);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
// c) Huecos públicos (contract.slotTokens): pintar esa propiedad de esa pieza con otra cosa
|
|
420
|
+
// que su hueco es rodearlo; se rellena el hueco en las VARIABLES del tema.
|
|
421
|
+
const huecos = contract.slotTokens?.slots ?? {};
|
|
422
|
+
for (const { selector, prop, value } of decls) {
|
|
423
|
+
for (const [, slot] of selector.matchAll(/data-slot=['"]?([\w-]+)/g)) {
|
|
424
|
+
const token = huecos[slot]?.[prop];
|
|
425
|
+
if (!token || value.includes(`var(${token})`)) continue;
|
|
426
|
+
const clave = `hueco|${slot}|${prop}`;
|
|
427
|
+
if (vistos.has(clave)) continue;
|
|
428
|
+
vistos.add(clave);
|
|
429
|
+
// Error en los temas «strict», aviso en los demás (ADR 0002, F1b: todos los temas ya rellenan sus huecos).
|
|
430
|
+
report(`pinta «${prop}» de ${slot} con «${value}» en vez de rellenar su hueco ${token} — define ${token} en las variables y quita la regla`);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
const estilizados = new Set(decls.flatMap((d) => [...d.selector.matchAll(/data-slot=['"]?([\w-]+)/g)].map((m) => m[1])));
|
|
435
|
+
for (const [familia, slots] of familias) {
|
|
436
|
+
const tiene = slots.filter((s) => estilizados.has(s));
|
|
437
|
+
if (!tiene.length || tiene.length === slots.length) continue;
|
|
438
|
+
const faltan = slots.filter((s) => !estilizados.has(s));
|
|
439
|
+
report(`familia «${familia}» incompleta: estiliza ${tiene.join(', ')} pero no ${faltan.join(', ')}`);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
// 8) ESCAPARATE: cada componente tiene su demo (showcase/src/demos/<componente>.tsx), para
|
|
445
|
+
// que todo se pueda ver con cada tema. Solo en el repo del paquete (no en una app).
|
|
446
|
+
{
|
|
447
|
+
const demosDir = join(ROOT, 'showcase/src/demos');
|
|
448
|
+
const uiDir8 = join(ROOT, 'src/ui');
|
|
449
|
+
if (existsSync(demosDir) && existsSync(uiDir8)) {
|
|
450
|
+
const demos = new Set(readdirSync(demosDir).filter((n) => n.endsWith('.tsx')).map((n) => n.replace(/\.tsx$/, '')));
|
|
451
|
+
const faltan = readdirSync(uiDir8).filter((n) => n.endsWith('.tsx')).map((n) => n.replace(/\.tsx$/, '')).filter((n) => !demos.has(n));
|
|
452
|
+
if (faltan.length) errors.push(`escaparate: componentes sin demo en showcase/src/demos/ (${faltan.join(', ')})`);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
// CSS de una app (opcional)
|
|
457
|
+
const cssArgIdx = process.argv.indexOf('--css');
|
|
458
|
+
if (cssArgIdx > -1 && process.argv[cssArgIdx + 1]) {
|
|
459
|
+
const css = stripComments(read(resolve(process.argv[cssArgIdx + 1])));
|
|
460
|
+
blocks(css, /(?:^|[\s}])\:root/).forEach((body, idx) => {
|
|
461
|
+
const seen = new Map();
|
|
462
|
+
for (const d of declarations(body)) seen.set(d.name, (seen.get(d.name) ?? 0) + 1);
|
|
463
|
+
for (const [v, n] of seen) if (n > 1) errors.push(`app css: ${v} definido ${n} veces en :root (#${idx + 1})`);
|
|
464
|
+
// Una variable --ds-* que el paquete ya no tiene: la marca la ignoraría en silencio.
|
|
465
|
+
const known = knownDsVars();
|
|
466
|
+
for (const d of declarations(body)) {
|
|
467
|
+
if (d.name.startsWith('--ds-') && !known.has(d.name)) {
|
|
468
|
+
errors.push(`app css: ${d.name} no existe en orbital-ds (¿renombrada o retirada? mira docs/CONTRACT.md)`);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// 5) valores fijos en componentes
|
|
475
|
+
const NO_HARDCODE = [
|
|
476
|
+
{ re: /#[0-9a-fA-F]{3,8}\b/g, why: 'color hexadecimal', skip: ['chart.tsx'] },
|
|
477
|
+
{ re: /\b(?:rgb|rgba|hsl|hsla|oklch)\((?!from_)/g, why: 'color literal' },
|
|
478
|
+
{ re: /(?<![\w-])z-(?!0(?![\w-]))\d+(?![\w-])/g, why: 'z-index numérico (usa --ds-z-*)' },
|
|
479
|
+
{ re: /(?<![\w-])duration-(?!0(?![\w-]))\d+(?![\w-])/g, why: 'duración fija (usa --ds-motion-*)' },
|
|
480
|
+
{ re: /(?<![a-zA-Z0-9.-])\d*\.?\d+m?s(?=[\])_,\s])/g, why: 'duración dentro de un valor arbitrario (usa --ds-motion-*)' },
|
|
481
|
+
{ re: /(?<![\w-])ease-\[(?:cubic-bezier|steps)\(/g, why: 'curva de aceleración escrita (usa ease-(--ds-ease-*))' },
|
|
482
|
+
{ re: /(?<![\w-])z-\[[^\]]*\d{2,}/g, why: 'capa numérica dentro de un valor arbitrario (usa --ds-z-*)' },
|
|
483
|
+
// i18n: los textos que ve o escucha el usuario salen de useDsMessages() (orbital-ds/lib/i18n).
|
|
484
|
+
{ re: /aria-(?:label|roledescription)="[A-Za-z][^"]*"/g, why: 'texto accesible escrito a mano (usa useDsMessages)' },
|
|
485
|
+
{ re: /sr-only">[^<{]*[A-Za-z][^<{]*</g, why: 'texto para lector de pantalla escrito a mano (usa useDsMessages)' },
|
|
486
|
+
{ re: /\?\?\s*"[A-Z][^"]*"/g, why: 'texto por defecto escrito a mano (usa useDsMessages)' },
|
|
487
|
+
{ re: /(?<![\w-])(?:title|description|text|placeholder)\s*=\s*"[A-Z][^"]*"/g, why: 'texto de interfaz escrito a mano (usa useDsMessages)' },
|
|
488
|
+
{ re: /(?<![\w-])(?:bg|text|border)-(?:black|white)(?:\/\d+)?(?![\w-])/g, why: 'color fijo (usa un token de color)' },
|
|
489
|
+
{ re: /(?<![\w-])shadow-(?:xs|sm|md|lg|xl|2xl)(?![\w-])/g, why: 'sombra de la escala Tailwind (usa shadow-card/control/raised/overlay/popover)' },
|
|
490
|
+
{ re: /(?<![\w-])text-\[\d+px\]/g, why: 'tamaño de texto arbitrario (usa la escala estándar)' },
|
|
491
|
+
{ re: /(?<![\w-])rounded-(?:3xl|4xl)(?![\w-])/g, why: 'radio fuera de la rampa (usa rounded-control/overlay o la rampa sm…2xl)' },
|
|
492
|
+
{ re: /(?<![\w-])(?:bg|text|border|ring|fill|stroke)-(?:red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose|slate|gray|zinc|neutral|stone)-\d{2,3}(?![\w-])/g, why: 'color de la paleta Tailwind (usa tokens del tema)' },
|
|
493
|
+
];
|
|
494
|
+
|
|
495
|
+
const uiDir = join(ROOT, 'src/ui');
|
|
496
|
+
if (existsSync(uiDir)) {
|
|
497
|
+
for (const f of readdirSync(uiDir).filter((n) => n.endsWith('.tsx'))) {
|
|
498
|
+
const lines = read(join(uiDir, f)).split(/\r?\n/);
|
|
499
|
+
lines.forEach((line, i) => {
|
|
500
|
+
const code = line.replace(/\/\/.*$/, '');
|
|
501
|
+
for (const rule of NO_HARDCODE) {
|
|
502
|
+
if (rule.skip?.includes(f)) continue;
|
|
503
|
+
const hits = code.match(rule.re);
|
|
504
|
+
if (hits) errors.push(`ui/${f}:${i + 1}: ${rule.why} → ${[...new Set(hits)].join(', ')}`);
|
|
505
|
+
}
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// 5b) UI DE UNA APP (--ui <carpeta>): el código de las vistas no se sale del sistema. Mismas reglas
|
|
511
|
+
// visuales que los componentes (sin las de textos: la app tiene su i18n) y tres propias de una app.
|
|
512
|
+
// Son las comprobaciones mecánicas del diseñador (docs/designer/revision.md, apartado A).
|
|
513
|
+
{
|
|
514
|
+
const i = process.argv.indexOf('--ui');
|
|
515
|
+
if (i > -1 && process.argv[i + 1]) {
|
|
516
|
+
const base = resolve(process.argv[i + 1]);
|
|
517
|
+
const VISUALES = NO_HARDCODE.filter((r) => !/texto/.test(r.why));
|
|
518
|
+
const APP = [
|
|
519
|
+
{ re: /(?<![\w-])(?:-?(?:p|px|py|pt|pb|ps|pe|pl|pr|m|mx|my|mt|mb|ms|me|ml|mr|gap|gap-x|gap-y|w|h|min-w|min-h|max-w|max-h|size|top|bottom|left|right|start|end|inset|leading|tracking|rounded|border)-\[-?\d*\.?\d+(?:px|rem|em)\])/g, why: 'medida arbitraria (usa la escala, un token --ds-* o la variante del componente)' },
|
|
520
|
+
{ re: /(?<![\w-])(?:rounded|shadow|font|bg|text|border|ring)-\[(?!var\(|--|length:var|color:var)[^\]]+\]/g, why: 'valor arbitrario visual (usa un token del tema)' },
|
|
521
|
+
{ cadenas: true, re: /(?<=^|\s)![a-z][\w:/()[\]-]*/g, why: '!important en una clase (no se pelea con la librería: ajusta en brand.css o abre un hueco)' },
|
|
522
|
+
{ re: /<(?:button|input|select|textarea)\b(?![^>]*data-slot)/g, why: 'control nativo suelto (usa Button, Input, Select/NativeSelect o Textarea de orbital-ds)' },
|
|
523
|
+
];
|
|
524
|
+
const ficheros = [];
|
|
525
|
+
const recorrer = (d) => {
|
|
526
|
+
if (!existsSync(d)) return;
|
|
527
|
+
for (const n of readdirSync(d, { withFileTypes: true })) {
|
|
528
|
+
if (n.name === 'node_modules' || n.name.startsWith('.')) continue;
|
|
529
|
+
const p = join(d, n.name);
|
|
530
|
+
if (n.isDirectory()) recorrer(p);
|
|
531
|
+
else if (/\.(tsx|jsx)$/.test(n.name)) ficheros.push(p);
|
|
532
|
+
}
|
|
533
|
+
};
|
|
534
|
+
recorrer(base);
|
|
535
|
+
if (!ficheros.length) warnings.push(`ui: no hay ficheros .tsx/.jsx en ${process.argv[i + 1]}`);
|
|
536
|
+
for (const f of ficheros) {
|
|
537
|
+
read(f).split(/\r?\n/).forEach((line, n) => {
|
|
538
|
+
const code = line.replace(/\/\/.*$/, '');
|
|
539
|
+
// Las reglas «de cadenas» solo miran dentro de literales ("…", '…', `…`): así `{!loading && …}` no cuenta.
|
|
540
|
+
const cadenas = [...code.matchAll(/"([^"]*)"|'([^']*)'|`([^`]*)`/g)].map((m) => m[1] ?? m[2] ?? m[3]);
|
|
541
|
+
for (const rule of [...VISUALES, ...APP]) {
|
|
542
|
+
const hits = rule.cadenas ? cadenas.flatMap((c) => c.match(rule.re) ?? []) : code.match(rule.re);
|
|
543
|
+
if (hits?.length) errors.push(`ui ${f.replace(process.cwd(), '.').split('\\').join('/')}:${n + 1}: ${rule.why} → ${[...new Set(hits)].join(', ')}`);
|
|
544
|
+
}
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
if (ficheros.length) console.log(`ui: ${ficheros.length} fichero(s) revisados en ${process.argv[i + 1]}`);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
// 6) API pública frente a la huella commiteada
|
|
552
|
+
const manifestPath = join(ROOT, 'components.manifest.json');
|
|
553
|
+
if (existsSync(manifestPath) && existsSync(uiDir)) {
|
|
554
|
+
const { buildManifest } = await import('./manifest.mjs');
|
|
555
|
+
const before = JSON.parse(read(manifestPath)).components;
|
|
556
|
+
const now = buildManifest().components;
|
|
557
|
+
for (const [name, comp] of Object.entries(before)) {
|
|
558
|
+
if (!now[name]) {
|
|
559
|
+
errors.push(`API pública: desaparece el componente «${name}» (¿versión mayor? regenera con pnpm manifest)`);
|
|
560
|
+
continue;
|
|
561
|
+
}
|
|
562
|
+
for (const e of comp.exports) {
|
|
563
|
+
if (!now[name].exports.includes(e)) {
|
|
564
|
+
errors.push(`API pública: «${name}» ya no exporta ${e} (¿versión mayor? regenera con pnpm manifest)`);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
const added = Object.keys(now).filter((n) => !before[n]);
|
|
569
|
+
if (added.length) warnings.push(`API pública: componentes nuevos sin registrar en el manifiesto (${added.join(', ')}); ejecuta pnpm manifest`);
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
for (const w of warnings) console.log(`AVISO ${w}`);
|
|
573
|
+
for (const e of errors) console.log(`ERROR ${e}`);
|
|
574
|
+
if (errors.length) {
|
|
575
|
+
console.log(`\ndoctor: ${errors.length} error(es), ${warnings.length} aviso(s)`);
|
|
576
|
+
process.exit(1);
|
|
577
|
+
}
|
|
578
|
+
console.log(`doctor: contrato, repetidos, sombras, fugas, valores fijos y API pública correctos (${warnings.length} aviso(s)).`);
|