orbital-ds 0.22.0 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/scripts/cli.mjs CHANGED
@@ -210,7 +210,7 @@ function contexto(json) {
210
210
  marca: estado.marca?.activa ? estado.marca : null,
211
211
  brandCss: { fichero: existsSync(brand) ? relative(process.cwd(), brand).split(sep).join('/') : null, variables: brandVars, coloresAMano: estado.manual.colores.map((d) => d.name) },
212
212
  extras: { animaciones: estado.animaciones, motion: yaInstalado('motion'), echarts: yaInstalado('echarts'), tablas: yaInstalado('@tanstack/react-table') },
213
- componentes: Object.fromEntries(Object.entries(manifest.components).map(([n, c]) => [n, { import: c.import, exports: c.exports, ...(c.notes ? { notes: c.notes } : {}) }])),
213
+ componentes: Object.fromEntries(Object.entries(manifest.components).map(([n, c]) => [n, { import: c.import, exports: c.exports, ...(c.presets ? { presets: c.presets } : {}), ...(c.notes ? { notes: c.notes } : {}) }])),
214
214
  patrones,
215
215
  documentacion: {
216
216
  reglas: `${docs}/AGENTS.md`,
@@ -245,6 +245,11 @@ function contexto(json) {
245
245
  const sino = (v) => (v ? 'sí' : 'no');
246
246
  L.push('', '## Extras', `- Animaciones del tema: ${sino(datos.extras.animaciones)} · Motion: ${sino(datos.extras.motion)} · ECharts: ${sino(datos.extras.echarts)} · TanStack Table: ${sino(datos.extras.tablas)}`);
247
247
  L.push('', `## Componentes (${Object.keys(datos.componentes).length}) · import orbital-ds/ui/<nombre>`, Object.keys(datos.componentes).join(', '));
248
+ const conPresets = Object.entries(datos.componentes).filter(([, c]) => c.presets);
249
+ if (conPresets.length) {
250
+ L.push('', '### Presets (valor por defecto con *)');
251
+ for (const [n, c] of conPresets) L.push(`- ${n}: ${c.presets.values.map((v) => (v === c.presets.default ? `${v}*` : v)).join(' · ')}`);
252
+ }
248
253
  const conNotas = Object.entries(datos.componentes).filter(([, c]) => c.notes);
249
254
  if (conNotas.length) {
250
255
  L.push('', '### Notas de uso');
@@ -70,6 +70,12 @@ function declarations(body) {
70
70
 
71
71
  /** Variables --ds-* que la estructura del paquete define (las que una app puede usar). */
72
72
  /** CSS de la estructura: src/ en el repo; dist/ en el paquete instalado (npm no publica src/). */
73
+ // Objetivo táctil mínimo WCAG 2.5.8 (AA): ningún control mide menos de 1,5rem (24 px).
74
+ {
75
+ const css = existsSync(join(ROOT, 'src/styles.css')) ? readFileSync(join(ROOT, 'src/styles.css'), 'utf8') : '';
76
+ for (const m of css.matchAll(/--ds-control-h-(xs|sm|md|lg)\s*:\s*([\d.]+)rem/g))
77
+ if (parseFloat(m[2]) < 1.5) errors.push(`accesibilidad: --ds-control-h-${m[1]} = ${m[2]}rem queda bajo el objetivo táctil mínimo de 1.5rem (WCAG 2.5.8)`);
78
+ }
73
79
  const STRUCTURE_CSS = existsSync(join(ROOT, 'src/styles.css')) ? join(ROOT, 'src/styles.css') : join(ROOT, 'dist/styles.css');
74
80
 
75
81
  function knownDsVars() {
@@ -463,6 +469,13 @@ if (base && themeInfo[base]) {
463
469
  if (!/preset\??:/.test(src)) continue;
464
470
  if (!/data-preset=/.test(src)) errors.push(`ui/${f}: tiene prop preset pero no emite data-preset`);
465
471
  if (!/@note/.test(src)) errors.push(`ui/${f}: tiene prop preset pero ningún @note que explique cuándo usar cada uno`);
472
+ {
473
+ // El catálogo del manifiesto lee el tipo y el valor por defecto de la firma: tienen que coincidir.
474
+ const vals = [...(src.match(/type \w*Preset\s*=\s*([^;]+);/)?.[1] ?? '').matchAll(/"([^"]+)"/g)].map((x) => x[1]);
475
+ const def = src.match(/^\s*preset\s*=\s*"([a-z-]+)",?\s*$/m)?.[1];
476
+ if (!def) errors.push(`ui/${f}: el preset no tiene valor por defecto en la firma (preset = "…")`);
477
+ else if (!vals.includes(def)) errors.push(`ui/${f}: el preset por defecto «${def}» no está en su tipo (${vals.join(", ")})`);
478
+ }
466
479
  for (const m of src.matchAll(/type \w*Preset\s*=\s*([^;]+);/g)) {
467
480
  for (const v of m[1].matchAll(/"([^"]+)"/g)) {
468
481
  if (!/^[a-z]+(-[a-z]+)*$/.test(v[1])) errors.push(`ui/${f}: valor de preset «${v[1]}» fuera del estándar (inglés, minúsculas, kebab-case)`);
@@ -507,6 +520,8 @@ const NO_HARDCODE = [
507
520
  { re: /(?<![\w-])(?:bg|text|border)-(?:black|white)(?:\/\d+)?(?![\w-])/g, why: 'color fijo (usa un token de color)' },
508
521
  { re: /(?<![\w-])shadow-(?:xs|sm|md|lg|xl|2xl)(?![\w-])/g, why: 'sombra de la escala Tailwind (usa shadow-card/control/raised/overlay/popover)' },
509
522
  { re: /(?<![\w-])text-\[\d+px\]/g, why: 'tamaño de texto arbitrario (usa la escala estándar)' },
523
+ { re: /(?<![\w-])text-\[(?:0?\.[0-6]\d*|0?\.7[0-4]\d*)rem\]/g, why: 'texto menor de 0,75rem (12 px): ilegible; usa text-xs como mínimo' },
524
+ { re: /@\[\d+px\]/g, why: 'container query en px (usa rem: respeta el tamaño de letra de la persona)' },
510
525
  { re: /(?<![\w-])rounded-(?:3xl|4xl)(?![\w-])/g, why: 'radio fuera de la rampa (usa rounded-control/overlay o la rampa sm…2xl)' },
511
526
  { 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)' },
512
527
  ];
@@ -1,85 +1,100 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Manifiesto de componentes de orbital-ds (`components.manifest.json`).
4
- *
5
- * Lo leen los agentes de IA (qué hay, cómo se importa, qué `data-slot` expone,
6
- * qué dependencias opcionales pide) y `pnpm check:ds` lo usa como HUELLA de la API
7
- * pública: si desaparece un componente o un export respecto al manifiesto
8
- * commiteado, doctor falla salvo que se haga una versión mayor.
9
- *
10
- * node scripts/manifest.mjs # regenera components.manifest.json
11
- */
12
- import { readFileSync, readdirSync, writeFileSync, existsSync } from 'node:fs';
13
- import { join, dirname, resolve } from 'node:path';
14
- import { fileURLToPath } from 'node:url';
15
-
16
- const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');
17
- const UI = join(ROOT, 'src/ui');
18
-
19
- // Dependencias que SIEMPRE están (peers obligatorios): no se listan como opcionales.
20
- const REQUIRED = new Set([
21
- 'react', 'react-dom', 'class-variance-authority', 'clsx', 'tailwind-merge', 'lucide-react',
22
- ]);
23
-
24
- function parseExports(src) {
25
- const names = new Set();
26
- for (const m of src.matchAll(/export\s*\{([^}]*)\}/g)) {
27
- for (const part of m[1].split(',')) {
28
- const n = part.trim().split(/\s+as\s+/i).pop()?.trim();
29
- if (n) names.add(n);
30
- }
31
- }
32
- for (const m of src.matchAll(/export\s+(?:async\s+)?(?:function|const|class)\s+([A-Za-z0-9_]+)/g)) names.add(m[1]);
33
- return [...names].sort();
34
- }
35
-
36
- function parseSlots(src) {
37
- return [...new Set([...src.matchAll(/data-slot="([a-z0-9-]+)"/g)].map((m) => m[1]))].sort();
38
- }
39
-
40
- /** Reglas de uso escritas en el componente con `@note …` (una por línea): van al manifiesto. */
41
- function parseNotes(src) {
42
- return [...src.matchAll(/@note\s+([^\r\n]+)/g)].map((m) => m[1].replace(/\s*\*\/\s*$/, '').trim());
43
- }
44
-
45
- function parseOptionalPeers(src) {
46
- const peers = new Set();
47
- for (const m of src.matchAll(/from\s+"([^"]+)"/g)) {
48
- const spec = m[1];
49
- if (spec.startsWith('.')) continue;
50
- const pkg = spec.startsWith('@') ? spec.split('/').slice(0, 2).join('/') : spec.split('/')[0];
51
- if (pkg === '@base-ui/react' || REQUIRED.has(pkg)) continue;
52
- peers.add(pkg);
53
- }
54
- return [...peers].sort();
55
- }
56
-
57
- export function buildManifest() {
58
- const components = {};
59
- for (const f of readdirSync(UI).filter((n) => n.endsWith('.tsx')).sort()) {
60
- const src = readFileSync(join(UI, f), 'utf8');
61
- const name = f.replace(/\.tsx$/, '');
62
- components[name] = {
63
- import: `orbital-ds/ui/${name}`,
64
- exports: parseExports(src),
65
- slots: parseSlots(src),
66
- optionalPeers: parseOptionalPeers(src),
67
- ...(parseNotes(src).length ? { notes: parseNotes(src) } : {}),
68
- };
69
- }
70
- const pkg = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf8'));
71
- return {
72
- package: pkg.name,
73
- version: pkg.version,
74
- engine: '@base-ui/react',
75
- docs: ['README.md', 'docs/CONTRACT.md', 'AGENTS.md', 'contract.json'],
76
- components,
77
- };
78
- }
79
-
80
- if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
81
- const out = join(ROOT, 'components.manifest.json');
82
- const manifest = buildManifest();
83
- writeFileSync(out, JSON.stringify(manifest, null, 2) + '\n');
84
- console.log(`manifest: ${Object.keys(manifest.components).length} componentes → components.manifest.json`);
85
- }
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Manifiesto de componentes de orbital-ds (`components.manifest.json`).
4
+ *
5
+ * Lo leen los agentes de IA (qué hay, cómo se importa, qué `data-slot` expone,
6
+ * qué dependencias opcionales pide) y `pnpm check:ds` lo usa como HUELLA de la API
7
+ * pública: si desaparece un componente o un export respecto al manifiesto
8
+ * commiteado, doctor falla salvo que se haga una versión mayor.
9
+ *
10
+ * node scripts/manifest.mjs # regenera components.manifest.json
11
+ */
12
+ import { readFileSync, readdirSync, writeFileSync, existsSync } from 'node:fs';
13
+ import { join, dirname, resolve } from 'node:path';
14
+ import { fileURLToPath } from 'node:url';
15
+
16
+ const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');
17
+ const UI = join(ROOT, 'src/ui');
18
+
19
+ // Dependencias que SIEMPRE están (peers obligatorios): no se listan como opcionales.
20
+ const REQUIRED = new Set([
21
+ 'react', 'react-dom', 'class-variance-authority', 'clsx', 'tailwind-merge', 'lucide-react',
22
+ ]);
23
+
24
+ function parseExports(src) {
25
+ const names = new Set();
26
+ for (const m of src.matchAll(/export\s*\{([^}]*)\}/g)) {
27
+ for (const part of m[1].split(',')) {
28
+ const n = part.trim().split(/\s+as\s+/i).pop()?.trim();
29
+ if (n) names.add(n);
30
+ }
31
+ }
32
+ for (const m of src.matchAll(/export\s+(?:async\s+)?(?:function|const|class)\s+([A-Za-z0-9_]+)/g)) names.add(m[1]);
33
+ return [...names].sort();
34
+ }
35
+
36
+ function parseSlots(src) {
37
+ return [...new Set([...src.matchAll(/data-slot="([a-z0-9-]+)"/g)].map((m) => m[1]))].sort();
38
+ }
39
+
40
+ /** Reglas de uso escritas en el componente con `@note …` (una por línea): van al manifiesto. */
41
+ function parseNotes(src) {
42
+ return [...src.matchAll(/@note\s+([^\r\n]+)/g)].map((m) => m[1].replace(/\s*\*\/\s*$/, '').trim());
43
+ }
44
+
45
+ /**
46
+ * Presets: valores del tipo XPreset, el valor por defecto (preset = "x") y, si la cabecera del
47
+ * componente lo describe (una línea "valor intención"), su intención. Es el catálogo que lee un agente.
48
+ */
49
+ function parsePresets(src) {
50
+ const t = src.match(/type\s+\w*Preset\s*=\s*((?:"[a-z-]+"\s*\|?\s*)+);?/);
51
+ if (!t) return null;
52
+ const values = [...t[1].matchAll(/"([a-z-]+)"/g)].map((m) => m[1]);
53
+ const def = src.match(/^\s*preset\s*=\s*"([a-z-]+)",?\s*$/m)?.[1] ?? null;
54
+ const intent = {};
55
+ for (const m of src.matchAll(/^\s*\*\s+([a-z-]+)\s{2,}(\S[^\r\n]*)$/gm)) if (values.includes(m[1])) intent[m[1]] = m[2].trim();
56
+ return { values, default: def, ...(Object.keys(intent).length ? { intent } : {}) };
57
+ }
58
+
59
+ function parseOptionalPeers(src) {
60
+ const peers = new Set();
61
+ for (const m of src.matchAll(/from\s+"([^"]+)"/g)) {
62
+ const spec = m[1];
63
+ if (spec.startsWith('.')) continue;
64
+ const pkg = spec.startsWith('@') ? spec.split('/').slice(0, 2).join('/') : spec.split('/')[0];
65
+ if (pkg === '@base-ui/react' || REQUIRED.has(pkg)) continue;
66
+ peers.add(pkg);
67
+ }
68
+ return [...peers].sort();
69
+ }
70
+
71
+ export function buildManifest() {
72
+ const components = {};
73
+ for (const f of readdirSync(UI).filter((n) => n.endsWith('.tsx')).sort()) {
74
+ const src = readFileSync(join(UI, f), 'utf8');
75
+ const name = f.replace(/\.tsx$/, '');
76
+ components[name] = {
77
+ import: `orbital-ds/ui/${name}`,
78
+ exports: parseExports(src),
79
+ slots: parseSlots(src),
80
+ optionalPeers: parseOptionalPeers(src),
81
+ ...(parsePresets(src) ? { presets: parsePresets(src) } : {}),
82
+ ...(parseNotes(src).length ? { notes: parseNotes(src) } : {}),
83
+ };
84
+ }
85
+ const pkg = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf8'));
86
+ return {
87
+ package: pkg.name,
88
+ version: pkg.version,
89
+ engine: '@base-ui/react',
90
+ docs: ['README.md', 'docs/CONTRACT.md', 'AGENTS.md', 'contract.json'],
91
+ components,
92
+ };
93
+ }
94
+
95
+ if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
96
+ const out = join(ROOT, 'components.manifest.json');
97
+ const manifest = buildManifest();
98
+ writeFileSync(out, JSON.stringify(manifest, null, 2) + '\n');
99
+ console.log(`manifest: ${Object.keys(manifest.components).length} componentes → components.manifest.json`);
100
+ }