orbital-ds 0.13.2 → 0.15.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/AGENTS.md +5 -0
- package/README.md +5 -1
- package/dist/styles.css +1 -0
- package/dist/themes/liquid.css +502 -0
- package/dist/themes/liquid.fonts.css +7 -0
- package/dist/themes/liquid.guide.md +82 -0
- package/dist/themes/liquid.meta.json +134 -0
- package/dist/themes/liquid.scoped.css +502 -0
- package/dist/themes/liquid.tokens.json +47 -0
- package/dist/ui/switch.js +1 -1
- package/package.json +2 -1
- package/scripts/brand-file.mjs +221 -0
- package/scripts/cli.mjs +111 -29
- package/scripts/init.mjs +176 -72
- package/scripts/setup.mjs +90 -10
package/dist/ui/switch.js
CHANGED
|
@@ -13,7 +13,7 @@ function Switch({
|
|
|
13
13
|
"data-slot": "switch",
|
|
14
14
|
"data-size": size,
|
|
15
15
|
className: cn(
|
|
16
|
-
"peer group/switch relative inline-flex shrink-0 items-center rounded-(--ds-radius-pill) border border-transparent transition-all duration-(--ds-motion-snap) outline-none group-has-[:focus-visible]/field-label:border-transparent group-has-[:focus-visible]/field-label:ring-0 after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring focus-visible:ring-(length:--ds-ring-width) focus-visible:ring-(--ds-ring-color) aria-invalid:border-(--ds-invalid-border) aria-invalid:ring-(length:--ds-ring-width) aria-invalid:ring-(--ds-invalid-ring) data-[size=default]:h-(--ds-switch-h) data-[size=default]:w-(--ds-switch-w) data-[size=sm]:h-(--ds-switch-h-sm) data-[size=sm]:w-(--ds-switch-w-sm) data-checked:bg-
|
|
16
|
+
"peer group/switch relative inline-flex shrink-0 items-center rounded-(--ds-radius-pill) border border-transparent transition-all duration-(--ds-motion-snap) outline-none group-has-[:focus-visible]/field-label:border-transparent group-has-[:focus-visible]/field-label:ring-0 after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring focus-visible:ring-(length:--ds-ring-width) focus-visible:ring-(--ds-ring-color) aria-invalid:border-(--ds-invalid-border) aria-invalid:ring-(length:--ds-ring-width) aria-invalid:ring-(--ds-invalid-ring) data-[size=default]:h-(--ds-switch-h) data-[size=default]:w-(--ds-switch-w) data-[size=sm]:h-(--ds-switch-h-sm) data-[size=sm]:w-(--ds-switch-w-sm) data-checked:bg-(--ds-switch-track-on) data-unchecked:bg-(--ds-switch-track-off) data-disabled:cursor-not-allowed data-disabled:opacity-(--ds-disabled-opacity)",
|
|
17
17
|
className
|
|
18
18
|
),
|
|
19
19
|
...props,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "orbital-ds",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "Sistema de diseño genérico: estructura común + temas con personalidad (qratia, zyro) + ~60 componentes sobre Base UI y Tailwind v4, con contrato verificable y legible por agentes.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"design-system",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"scripts/manifest.mjs",
|
|
34
34
|
"scripts/brand-core.mjs",
|
|
35
35
|
"scripts/setup.mjs",
|
|
36
|
+
"scripts/brand-file.mjs",
|
|
36
37
|
"scripts/i18n.mjs"
|
|
37
38
|
],
|
|
38
39
|
"exports": {
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* orbital-ds · el FICHERO DE MARCA de una app (brand.css): su bloque generado, lo que la app
|
|
3
|
+
* escribió a mano y cómo limpiarlo al cambiar de tema. Lo usan `orbital-ds-init` y `orbital-ds theme`.
|
|
4
|
+
*
|
|
5
|
+
* Al cambiar de tema, los colores escritos a mano para el tema anterior (lienzo, tinta, tarjetas,
|
|
6
|
+
* primario…) siguen ganando al tema nuevo, porque brand.css se importa después. Aquí se detectan y se
|
|
7
|
+
* desactivan (se comentan, con copia del fichero entero) sin tocar lo demás: radios, fuentes, movimiento.
|
|
8
|
+
*/
|
|
9
|
+
import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
10
|
+
import { dirname, join } from 'node:path';
|
|
11
|
+
|
|
12
|
+
export const INI = '/* orbital-ds:brand:start */';
|
|
13
|
+
export const FIN = '/* orbital-ds:brand:end */';
|
|
14
|
+
/** Recuerdo de una marca generada que se quitó al pasar a un tema fiel: permite recuperarla al volver. */
|
|
15
|
+
const OFF = /\/\* orbital-ds:brand:off \(([^)]*)\)[^*]*\*\/\n?/;
|
|
16
|
+
|
|
17
|
+
/* ═══════════════════════════════ BLOQUE GENERADO ═════════════════════════════ */
|
|
18
|
+
/** Parámetros de la marca en texto: «tema x, primario #…, modo m, secundario #…, acento #…, sin rotulador». */
|
|
19
|
+
const describir = ({ tema, primario, modo, secundario, acento, marcador = true }) =>
|
|
20
|
+
[`tema ${tema}`, `primario ${primario}`, `modo ${modo}`, secundario && `secundario ${secundario}`, acento && `acento ${acento}`, !marcador && 'sin rotulador']
|
|
21
|
+
.filter(Boolean)
|
|
22
|
+
.join(', ');
|
|
23
|
+
|
|
24
|
+
function leerParametros(txt) {
|
|
25
|
+
const p = { marcador: true };
|
|
26
|
+
for (const parte of txt.split(',').map((s) => s.trim())) {
|
|
27
|
+
const m = parte.match(/^(tema anterior|tema|primario|modo|secundario|acento)\s+(\S+)$/);
|
|
28
|
+
if (m) p[{ 'tema anterior': 'tema', tema: 'tema', primario: 'primario', modo: 'modo', secundario: 'secundario', acento: 'acento' }[m[1]]] = m[2];
|
|
29
|
+
if (parte === 'sin rotulador') p.marcador = false;
|
|
30
|
+
}
|
|
31
|
+
return p.primario ? { modo: 'full', ...p } : null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function bloqueCss(res, params) {
|
|
35
|
+
const fmt = (tokens) => Object.entries(tokens).map(([k, v]) => ` --${k}: ${v};`).join('\n');
|
|
36
|
+
return `${INI}
|
|
37
|
+
/* Generado por \`orbital-ds-init\` (${describir(params)}). Si vuelves a
|
|
38
|
+
* ejecutarlo con --update, solo se reescribe este bloque; lo que tengas fuera no se toca. */
|
|
39
|
+
:root {
|
|
40
|
+
${fmt(res.claro)}
|
|
41
|
+
}
|
|
42
|
+
.dark {
|
|
43
|
+
${fmt(res.oscuro)}
|
|
44
|
+
}
|
|
45
|
+
${FIN}
|
|
46
|
+
`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const leer = (file) => (existsSync(file) ? readFileSync(file, 'utf8') : '');
|
|
50
|
+
|
|
51
|
+
/** ¿El fichero de marca tiene un bloque generado? */
|
|
52
|
+
export const tieneBloque = (file) => { const t = leer(file); return t.includes(INI) && t.includes(FIN); };
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Marca generada que hay en el fichero: { tema, primario, modo, secundario?, acento?, marcador, activa }.
|
|
56
|
+
* `activa: false` = se quitó al pasar a un tema fiel y se recuerda para recuperarla.
|
|
57
|
+
*/
|
|
58
|
+
export function marcaGenerada(file) {
|
|
59
|
+
const t = leer(file);
|
|
60
|
+
const cab = t.match(/Generado por `orbital-ds-init` \(([^)]*)\)/);
|
|
61
|
+
if (cab && tieneBloque(file)) { const p = leerParametros(cab[1]); if (p) return { ...p, activa: true }; }
|
|
62
|
+
const off = t.match(OFF);
|
|
63
|
+
if (off) { const p = leerParametros(off[1]); if (p) return { ...p, activa: false }; }
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function escribirBloque(file, bloque) {
|
|
68
|
+
const actual = existsSync(file) ? readFileSync(file, 'utf8') : null;
|
|
69
|
+
if (actual === null) {
|
|
70
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
71
|
+
writeFileSync(file, `/*\n * MARCA de la app — fichero TUYO. Se importa DESPUÉS del tema, así que lo que pongas aquí gana.\n */\n\n${bloque}`);
|
|
72
|
+
return 'creado';
|
|
73
|
+
}
|
|
74
|
+
const base = actual.replace(OFF, '');
|
|
75
|
+
const nuevo = base.includes(INI) && base.includes(FIN)
|
|
76
|
+
? base.slice(0, base.indexOf(INI)) + bloque.trimEnd() + base.slice(base.indexOf(FIN) + FIN.length)
|
|
77
|
+
: `${base.replace(/\s*$/, '')}\n\n${bloque}`;
|
|
78
|
+
if (nuevo === actual) return 'igual';
|
|
79
|
+
writeFileSync(file, nuevo);
|
|
80
|
+
return 'actualizado';
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Quita SOLO el bloque generado (modo fiel); lo que la app tenga fuera se queda. Con `recordar`
|
|
85
|
+
* ({ params, tema }) deja una línea con la marca para que `orbital-ds theme` la recupere al volver
|
|
86
|
+
* a un tema que la admita.
|
|
87
|
+
*/
|
|
88
|
+
export function quitarBloque(file, { recordar } = {}) {
|
|
89
|
+
if (!tieneBloque(file)) return 'sin bloque';
|
|
90
|
+
const actual = readFileSync(file, 'utf8');
|
|
91
|
+
const nota = recordar
|
|
92
|
+
? `/* orbital-ds:brand:off (${describir(recordar.params).replace(/^tema /, 'tema anterior ')}) — se quitó al pasar a «${recordar.tema}», que se usa fiel. \`orbital-ds theme\` la recupera al volver a un tema que admita marca. */\n`
|
|
93
|
+
: '';
|
|
94
|
+
const antes = actual.slice(0, actual.indexOf(INI)).replace(/\s*$/, '');
|
|
95
|
+
const despues = actual.slice(actual.indexOf(FIN) + FIN.length).replace(/^\s*/, '');
|
|
96
|
+
writeFileSync(file, `${antes}\n\n${nota}${despues}`.replace(/\n{3,}/g, '\n\n').replace(/\s*$/, '\n'));
|
|
97
|
+
return 'quitado';
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/* ═══════════════════════════════ LO ESCRITO A MANO ═══════════════════════════ */
|
|
101
|
+
const VALOR_COLOR = /^(#[0-9a-f]{3,8}\b|(rgba?|hsla?|hwb|lab|lch|oklab|oklch|color|color-mix|light-dark)\(|transparent\b|currentcolor\b|white\b|black\b)/i;
|
|
102
|
+
/** Un color DENTRO del valor (sombras, degradados, bordes compuestos): también es pintura del tema. */
|
|
103
|
+
const CON_COLOR = /(#[0-9a-f]{3,8}\b|\b(rgba?|hsla?|hwb|lab|lch|oklab|oklch|color-mix)\()/i;
|
|
104
|
+
|
|
105
|
+
/** Copia del texto con los comentarios en blanco (mismas posiciones y saltos de línea). */
|
|
106
|
+
const sinComentarios = (t) => t.replace(/\/\*[\s\S]*?\*\//g, (c) => c.replace(/[^\n]/g, ' '));
|
|
107
|
+
|
|
108
|
+
/** Variables (sin --) que algún tema de `temasDir` define con un color: son «paleta», no forma. */
|
|
109
|
+
export function nombresColorTemas(temasDir) {
|
|
110
|
+
const nombres = new Set();
|
|
111
|
+
for (const f of readdirSync(temasDir).filter((n) => /^[\w-]+\.css$/.test(n) && !n.includes('.fonts.'))) {
|
|
112
|
+
const css = sinComentarios(readFileSync(join(temasDir, f), 'utf8'));
|
|
113
|
+
for (const [, k, v] of css.matchAll(/--([\w-]+)\s*:\s*([^;{}]+);/g)) if (VALOR_COLOR.test(v.trim())) nombres.add(k);
|
|
114
|
+
}
|
|
115
|
+
return nombres;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Declaraciones activas de brand.css FUERA del bloque generado:
|
|
120
|
+
* { decl: [{ name, value, color, privada, linea, ambito, inicio, fin }], primario, colores, privadas }
|
|
121
|
+
* `color`: su valor es (o lleva) un color, o el nombre es un color del tema (`nombresColor`).
|
|
122
|
+
* `privada`: variable privada de un tema (--zy-*, --lq-*…): obsoleta en cuanto cambias de tema.
|
|
123
|
+
* `primario`: el --primary escrito a mano en :root (fuera de @media), para recalcular la marca.
|
|
124
|
+
*/
|
|
125
|
+
export function analizarMarca(file, { nombresColor = new Set() } = {}) {
|
|
126
|
+
const txt = leer(file);
|
|
127
|
+
const vacio = { decl: [], primario: null, colores: [], privadas: [] };
|
|
128
|
+
if (!txt) return vacio;
|
|
129
|
+
const limpio = sinComentarios(txt);
|
|
130
|
+
const ini = txt.indexOf(INI), fin = txt.indexOf(FIN);
|
|
131
|
+
const enBloque = (i) => ini > -1 && fin > -1 && i > ini && i < fin + FIN.length;
|
|
132
|
+
const decl = [];
|
|
133
|
+
for (const m of limpio.matchAll(/(--[\w-]+)\s*:\s*([^;{}]+);/g)) {
|
|
134
|
+
if (enBloque(m.index)) continue;
|
|
135
|
+
const name = m[1], value = m[2].trim().replace(/\s+/g, ' ');
|
|
136
|
+
// Ámbito: el último selector abierto antes de la declaración (y si va dentro de un @media).
|
|
137
|
+
const previo = limpio.slice(0, m.index);
|
|
138
|
+
const selector = (previo.match(/([^{};]+)\{[^{}]*$/)?.[1] ?? '').trim();
|
|
139
|
+
const abiertos = (previo.match(/\{/g) ?? []).length - (previo.match(/\}/g) ?? []).length;
|
|
140
|
+
decl.push({
|
|
141
|
+
name,
|
|
142
|
+
value,
|
|
143
|
+
color: VALOR_COLOR.test(value) || CON_COLOR.test(value) || nombresColor.has(name.slice(2)),
|
|
144
|
+
privada: /^--[a-z]{2}-/.test(name) && !/^--(ds|tw)-/.test(name),
|
|
145
|
+
linea: previo.split('\n').length,
|
|
146
|
+
ambito: abiertos > 1 ? `${selector} (anidado)` : selector,
|
|
147
|
+
inicio: m.index,
|
|
148
|
+
fin: m.index + m[0].length,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
const prim = decl.find((d) => d.name === '--primary' && d.ambito === ':root');
|
|
152
|
+
return { decl, primario: prim?.value ?? null, colores: decl.filter((d) => d.color || d.privada), privadas: decl.filter((d) => d.privada) };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Copia de seguridad que no pisa otra: brand.css.<etiqueta>.bak, .bak2… */
|
|
156
|
+
function copiaDe(file, etiqueta) {
|
|
157
|
+
let destino = `${file}.${etiqueta}.bak`;
|
|
158
|
+
for (let n = 2; existsSync(destino); n++) destino = `${file}.${etiqueta}.bak${n}`;
|
|
159
|
+
copyFileSync(file, destino);
|
|
160
|
+
return destino;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Desactiva (comenta) las declaraciones escritas a mano que cumplen `filtro`, con copia del fichero.
|
|
165
|
+
* Solo toca líneas en las que TODAS sus declaraciones se desactivan; las demás se devuelven para
|
|
166
|
+
* revisarlas a mano. Devuelve { desactivadas, revisar, copia, huerfanas }; `huerfanas` = usos
|
|
167
|
+
* `var(--x)` de una variable que se ha quedado sin definir.
|
|
168
|
+
*/
|
|
169
|
+
export function desactivarMarca(file, filtro, { etiqueta = 'anterior', motivo = '', nombresColor } = {}) {
|
|
170
|
+
const { decl } = analizarMarca(file, { nombresColor });
|
|
171
|
+
const elegidas = decl.filter(filtro);
|
|
172
|
+
if (!elegidas.length) return { desactivadas: [], revisar: [], copia: null, huerfanas: [] };
|
|
173
|
+
const txt = readFileSync(file, 'utf8');
|
|
174
|
+
const limpio = sinComentarios(txt);
|
|
175
|
+
const lineas = txt.split('\n');
|
|
176
|
+
const lineasLimpias = limpio.split('\n');
|
|
177
|
+
const porLinea = new Map();
|
|
178
|
+
for (const d of decl) porLinea.set(d.linea, [...(porLinea.get(d.linea) ?? []), d]);
|
|
179
|
+
const desactivadas = [], revisar = [];
|
|
180
|
+
for (const d of elegidas) {
|
|
181
|
+
const enLinea = porLinea.get(d.linea);
|
|
182
|
+
const multilinea = limpio.slice(d.inicio, d.fin).includes('\n');
|
|
183
|
+
if (multilinea || enLinea.some((x) => !filtro(x))) { revisar.push(d); continue; }
|
|
184
|
+
if (desactivadas.some((x) => x.linea === d.linea)) { desactivadas.push(d); continue; }
|
|
185
|
+
const i = d.linea - 1;
|
|
186
|
+
// Un comentario que se abre en la línea y sigue en la siguiente se conserva; uno que viene de
|
|
187
|
+
// antes y se cierra aquí no se puede separar con seguridad: esa línea se revisa a mano.
|
|
188
|
+
const abierto = lineas[i].replace(/\/\*[\s\S]*?\*\//g, (c) => ' '.repeat(c.length));
|
|
189
|
+
if (abierto.includes('*/')) { revisar.push(d); continue; }
|
|
190
|
+
const cola = abierto.includes('/*') ? ` ${lineas[i].slice(abierto.indexOf('/*'))}` : '';
|
|
191
|
+
const sangria = lineas[i].match(/^\s*/)[0];
|
|
192
|
+
const decls = lineasLimpias[i].trim().replace(/\s+;/g, ';');
|
|
193
|
+
lineas[i] = `${sangria}/* ${decls} */${cola}`;
|
|
194
|
+
desactivadas.push(d);
|
|
195
|
+
}
|
|
196
|
+
if (!desactivadas.length) return { desactivadas, revisar, copia: null, huerfanas: [] };
|
|
197
|
+
const copia = copiaDe(file, etiqueta);
|
|
198
|
+
const nombreCopia = copia.split(/[\\/]/).pop();
|
|
199
|
+
const nota = `/* orbital-ds: ${desactivadas.length} variable(s) desactivada(s)${motivo ? ` ${motivo}` : ''}. Original en ${nombreCopia}. */`;
|
|
200
|
+
// La nota va justo después del comentario de cabecera (si lo hay), para que se vea al abrir el fichero.
|
|
201
|
+
let nuevo = lineas.join('\n');
|
|
202
|
+
const cab = nuevo.match(/^\s*\/\*[\s\S]*?\*\/\n/);
|
|
203
|
+
nuevo = cab ? `${cab[0]}${nota}\n${nuevo.slice(cab[0].length)}` : `${nota}\n${nuevo}`;
|
|
204
|
+
writeFileSync(file, nuevo);
|
|
205
|
+
// Reglas propias que leían una variable que ya no está definida (p. ej. `background: var(--brand-nav-active)`).
|
|
206
|
+
const vivas = new Set(analizarMarca(file, { nombresColor }).decl.map((d) => d.name));
|
|
207
|
+
const muertas = new Set(desactivadas.map((d) => d.name).filter((n) => !vivas.has(n)));
|
|
208
|
+
const huerfanas = sinComentarios(nuevo)
|
|
209
|
+
.split('\n')
|
|
210
|
+
.flatMap((l, i) => [...l.matchAll(/var\(\s*(--[\w-]+)\s*\)/g)].filter((m) => muertas.has(m[1])).map((m) => ({ name: m[1], linea: i + 1 })));
|
|
211
|
+
return { desactivadas, revisar, copia, huerfanas };
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** Cambia el `@base-theme <tema>` de la cabecera (sobre qué tema mide el doctor la marca). */
|
|
215
|
+
export function fijarTemaBase(file, tema) {
|
|
216
|
+
const t = leer(file);
|
|
217
|
+
const nuevo = t.replace(/(@base-theme\s+)[\w-]+/, `$1${tema}`);
|
|
218
|
+
if (!t || nuevo === t) return false;
|
|
219
|
+
writeFileSync(file, nuevo);
|
|
220
|
+
return true;
|
|
221
|
+
}
|
package/scripts/cli.mjs
CHANGED
|
@@ -12,11 +12,12 @@
|
|
|
12
12
|
* Las órdenes sueltas (orbital-ds-init, -doctor, -i18n) siguen funcionando: son atajos.
|
|
13
13
|
*/
|
|
14
14
|
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
15
|
-
import { dirname, join, resolve } from 'node:path';
|
|
15
|
+
import { dirname, join, relative, resolve, sep } from 'node:path';
|
|
16
16
|
import { fileURLToPath } from 'node:url';
|
|
17
17
|
import { spawnSync } from 'node:child_process';
|
|
18
18
|
|
|
19
|
-
import { detectarCssApp, yaInstalado } from './setup.mjs';
|
|
19
|
+
import { detectarCssApp, detectarMarca, importsDeTemaSueltos, temaDelCss, yaInstalado } from './setup.mjs';
|
|
20
|
+
import { analizarMarca, marcaGenerada, nombresColorTemas } from './brand-file.mjs';
|
|
20
21
|
import { estadoSkill, instalarSkill, raizApp, SKILL_NAME } from './skill.mjs';
|
|
21
22
|
|
|
22
23
|
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
@@ -66,7 +67,7 @@ Motion, gráficos, tablas, idiomas) y 4) resumen antes de escribir nada. Es la c
|
|
|
66
67
|
INICIAL: todo se cambia después en src/brand.css o volviendo a ejecutarlo.
|
|
67
68
|
|
|
68
69
|
Sin preguntas (scripts / CI)
|
|
69
|
-
--theme <tema> qratia, fractalia, tactile, zyro, friendly, twitter
|
|
70
|
+
--theme <tema> qratia, fractalia, tactile, zyro, friendly, twitter, liquid
|
|
70
71
|
--mode <modo> faithful (tema tal cual) · primary (solo tu color) · full (paleta entera)
|
|
71
72
|
--primary <color> #1D63D8, rgb(), hsl() u oklch()
|
|
72
73
|
--secondary <color> serie 2 de los gráficos y gesto del tema
|
|
@@ -76,7 +77,10 @@ Sin preguntas (scripts / CI)
|
|
|
76
77
|
--i18n rellena el espacio «orbital» de los JSON de idioma
|
|
77
78
|
--update reescribe el bloque generado de brand.css
|
|
78
79
|
--dry-run enseña el resultado sin escribir nada
|
|
79
|
-
--out <fichero> fichero de marca (por defecto src/brand.css)
|
|
80
|
+
--out <fichero> fichero de marca (por defecto el que importa tu CSS, o src/brand.css)
|
|
81
|
+
--clean <alcance> desactiva lo escrito A MANO en brand.css (se comenta, con copia .bak):
|
|
82
|
+
colors = colores y variables privadas de un tema · all = todo
|
|
83
|
+
--remember-brand (tema fiel) recuerda la marca generada para recuperarla al volver
|
|
80
84
|
|
|
81
85
|
Ejemplos
|
|
82
86
|
orbital-ds init --theme fractalia --connect --animations
|
|
@@ -87,12 +91,22 @@ Ejemplos
|
|
|
87
91
|
Cambia el import del tema en el CSS de la app y conserva lo tuyo:
|
|
88
92
|
- si tu marca se generó desde un color, la recalcula para el tema nuevo (mismo color y modo);
|
|
89
93
|
- si el tema nuevo es de un sistema corporativo (fractalia), se usa fiel;
|
|
90
|
-
- si tenías las animaciones activas, siguen activas
|
|
94
|
+
- si tenías las animaciones activas, siguen activas;
|
|
95
|
+
- quita los imports del tema anterior que la app cargue en otros ficheros (JS, HTML, otros CSS).
|
|
96
|
+
Al volver de un tema fiel a uno que admite marca, recupera la marca que tenías.
|
|
91
97
|
Sin tema, pregunta a cuál cambiar.
|
|
92
98
|
|
|
99
|
+
Colores escritos a mano en brand.css para el tema anterior (lienzo, tinta, tarjetas…) taparían al
|
|
100
|
+
nuevo. El asistente pregunta qué hacer; sin terminal, --brand lo decide (por defecto keep, con aviso):
|
|
101
|
+
--brand adapt los quita y aplica tu --primary escrito a mano sobre la paleta del tema nuevo
|
|
102
|
+
--brand clean los quita (se comentan, con copia .bak); radios y fuentes se quedan
|
|
103
|
+
--brand clean-all comenta todo lo escrito a mano
|
|
104
|
+
--brand keep los conserva
|
|
105
|
+
|
|
93
106
|
Ejemplos
|
|
94
|
-
orbital-ds theme
|
|
95
|
-
orbital-ds theme tactile
|
|
107
|
+
orbital-ds theme elegir de la lista
|
|
108
|
+
orbital-ds theme tactile
|
|
109
|
+
orbital-ds theme liquid --brand adapt`,
|
|
96
110
|
|
|
97
111
|
doctor: `orbital-ds doctor — comprobar
|
|
98
112
|
|
|
@@ -138,7 +152,6 @@ function ayuda(tema = 'general') {
|
|
|
138
152
|
console.log(AYUDA[tema] ?? AYUDA.general);
|
|
139
153
|
}
|
|
140
154
|
|
|
141
|
-
/** Lo que hay hoy en la app: tema importado, marca generada (primario, modo) y animaciones. */
|
|
142
155
|
/** Lo que falta en la raíz de la app para que las piezas de orbital-ds funcionen del todo. */
|
|
143
156
|
function avisosIntegracion(estado) {
|
|
144
157
|
const src = resolve('src');
|
|
@@ -156,6 +169,10 @@ function avisosIntegracion(estado) {
|
|
|
156
169
|
leer(src);
|
|
157
170
|
const avisos = [];
|
|
158
171
|
if (!estado.tema) avisos.push('El CSS de la app no importa ningún tema: ejecuta orbital-ds init (o orbital-ds theme).');
|
|
172
|
+
const otros = estado.sueltos;
|
|
173
|
+
if (otros.length) avisos.push(`Hay imports de tema fuera del CSS principal (${otros.map((x) => `${relative(process.cwd(), x.fichero)}:${x.linea} → ${x.tema}`).join(', ')}): con dos temas cargados gana el último. orbital-ds theme los quita.`);
|
|
174
|
+
if (estado.manual.privadas.length) avisos.push(`brand.css usa variables privadas de un tema (${estado.manual.privadas.map((d) => d.name).join(', ')}): pueden desaparecer. Usa las --ds-* públicas.`);
|
|
175
|
+
if (estado.manual.colores.length && estado.marca?.activa) avisos.push(`brand.css tiene ${estado.manual.colores.length} color(es) escritos a mano además de la marca generada: ganan a ella y al tema.`);
|
|
159
176
|
if (codigo && !/DsI18nProvider/.test(codigo)) avisos.push('No hay <DsI18nProvider> en la raíz: los textos de orbital-ds salen en inglés (orbital-ds/ui/i18n-provider).');
|
|
160
177
|
if (codigo && /\btoast\b/.test(codigo) && !/<Toaster\b/.test(codigo)) avisos.push('Se usa toast pero no hay <Toaster /> en la raíz: los avisos no se verán (orbital-ds/ui/toast).');
|
|
161
178
|
if (codigo && /useDsMotion|DsMotionProvider/.test(codigo) && !yaInstalado('motion')) avisos.push('Se usa Motion (useDsMotion/DsMotionProvider) pero el paquete motion no está instalado.');
|
|
@@ -170,7 +187,7 @@ function contexto(json) {
|
|
|
170
187
|
const manifest = JSON.parse(readFileSync(join(ROOT, 'components.manifest.json'), 'utf8'));
|
|
171
188
|
const patronesMd = join(ROOT, 'docs', 'designer', 'patrones.md');
|
|
172
189
|
const patrones = existsSync(patronesMd) ? [...readFileSync(patronesMd, 'utf8').matchAll(/^## (P\d+ · .+)$/gm)].map((m) => m[1].trim()) : [];
|
|
173
|
-
const brand =
|
|
190
|
+
const brand = estado.brand;
|
|
174
191
|
const brandVars = existsSync(brand)
|
|
175
192
|
? [...new Set([...readFileSync(brand, 'utf8').replace(/\/\*[\s\S]*?\*\//g, '').matchAll(/(--[\w-]+)\s*:/g)].map((m) => m[1]))]
|
|
176
193
|
: [];
|
|
@@ -190,8 +207,8 @@ function contexto(json) {
|
|
|
190
207
|
guia: `${docs}/dist/themes/${ficha.name}.guide.md`,
|
|
191
208
|
}
|
|
192
209
|
: null,
|
|
193
|
-
marca: estado.marca
|
|
194
|
-
brandCss: { fichero: existsSync(brand) ?
|
|
210
|
+
marca: estado.marca?.activa ? estado.marca : null,
|
|
211
|
+
brandCss: { fichero: existsSync(brand) ? relative(process.cwd(), brand).split(sep).join('/') : null, variables: brandVars, coloresAMano: estado.manual.colores.map((d) => d.name) },
|
|
195
212
|
extras: { animaciones: estado.animaciones, motion: yaInstalado('motion'), echarts: yaInstalado('echarts'), tablas: yaInstalado('@tanstack/react-table') },
|
|
196
213
|
componentes: Object.fromEntries(Object.entries(manifest.components).map(([n, c]) => [n, { import: c.import, exports: c.exports, ...(c.notes ? { notes: c.notes } : {}) }])),
|
|
197
214
|
patrones,
|
|
@@ -223,7 +240,8 @@ function contexto(json) {
|
|
|
223
240
|
}
|
|
224
241
|
L.push('', '## Marca de la app');
|
|
225
242
|
L.push(datos.marca ? `- Generada desde ${datos.marca.primario} (modo ${datos.marca.modo}, tema ${datos.marca.tema})` : '- Sin bloque generado (tema fiel o marca a mano)');
|
|
226
|
-
if (brandVars.length) L.push(`-
|
|
243
|
+
if (brandVars.length) L.push(`- ${datos.brandCss.fichero} cambia: ${brandVars.join(', ')}`);
|
|
244
|
+
if (estado.manual.colores.length) L.push(`- Colores escritos a mano (ganan al tema): ${estado.manual.colores.map((d) => d.name).join(', ')}`);
|
|
227
245
|
const sino = (v) => (v ? 'sí' : 'no');
|
|
228
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)}`);
|
|
229
247
|
L.push('', `## Componentes (${Object.keys(datos.componentes).length}) · import orbital-ds/ui/<nombre>`, Object.keys(datos.componentes).join(', '));
|
|
@@ -266,22 +284,39 @@ function ordenSkill(args) {
|
|
|
266
284
|
function estadoApp() {
|
|
267
285
|
const css = detectarCssApp();
|
|
268
286
|
const cssTxt = css && existsSync(css) ? readFileSync(css, 'utf8') : '';
|
|
269
|
-
const tema =
|
|
287
|
+
const tema = temaDelCss(css);
|
|
270
288
|
const animaciones = /orbital-ds\/motion\.css/.test(cssTxt);
|
|
271
|
-
const brand =
|
|
272
|
-
|
|
273
|
-
const
|
|
274
|
-
|
|
289
|
+
const brand = detectarMarca(css);
|
|
290
|
+
// marca.activa = false: se quitó al pasar a un tema fiel y se recuerda para recuperarla.
|
|
291
|
+
const marca = marcaGenerada(brand);
|
|
292
|
+
const manual = analizarMarca(brand, { nombresColor: nombresColorTemas(temasDir) });
|
|
293
|
+
const sueltos = importsDeTemaSueltos(css);
|
|
294
|
+
return { css, tema, animaciones, brand, marca, manual, sueltos };
|
|
275
295
|
}
|
|
276
296
|
|
|
277
|
-
/**
|
|
278
|
-
|
|
297
|
+
/** Parámetros de init para recalcular la marca generada (o recordada) en el tema nuevo. */
|
|
298
|
+
const argsMarca = (m) => [
|
|
299
|
+
'--primary', m.primario, '--mode', m.modo,
|
|
300
|
+
...(m.secundario ? ['--secondary', m.secundario] : []),
|
|
301
|
+
...(m.acento ? ['--accent', m.acento] : []),
|
|
302
|
+
...(m.marcador === false ? ['--no-marker'] : []),
|
|
303
|
+
];
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Cambiar de tema: reescribe el import del tema (y quita los que la app cargue aparte), recalcula la
|
|
307
|
+
* marca generada para el nuevo y decide qué hacer con los colores escritos A MANO para el anterior,
|
|
308
|
+
* que si no taparían al tema nuevo. `--brand adapt|clean|clean-all|keep` lo decide sin preguntar.
|
|
309
|
+
*/
|
|
310
|
+
async function cambiarTema(nuevo, args) {
|
|
279
311
|
const lista = temas();
|
|
280
312
|
const estado = estadoApp();
|
|
313
|
+
const interactivo = process.stdin.isTTY && process.stdout.isTTY;
|
|
314
|
+
const p = interactivo ? await import('@clack/prompts') : null;
|
|
315
|
+
const val = (n) => { const i = args.indexOf(`--${n}`); return i > -1 ? args[i + 1] : undefined; };
|
|
281
316
|
if (!nuevo) {
|
|
282
|
-
|
|
317
|
+
if (!p) { console.error('Indica el tema: orbital-ds theme <tema>'); process.exit(1); }
|
|
283
318
|
p.intro(` orbital-ds ${version} · cambiar de tema `);
|
|
284
|
-
if (estado.tema) p.log.info(`Tema actual: ${estado.tema}${estado.marca ? ` · marca generada desde ${estado.marca.primario} (modo ${estado.marca.modo})` : ' · sin marca generada'}`);
|
|
319
|
+
if (estado.tema) p.log.info(`Tema actual: ${estado.tema}${estado.marca?.activa ? ` · marca generada desde ${estado.marca.primario} (modo ${estado.marca.modo})` : ' · sin marca generada'}${estado.manual.colores.length ? ` · ${estado.manual.colores.length} color(es) escritos a mano en brand.css` : ''}`);
|
|
285
320
|
const v = await p.select({
|
|
286
321
|
message: '¿A qué tema cambias?',
|
|
287
322
|
initialValue: estado.tema ?? undefined,
|
|
@@ -295,12 +330,59 @@ async function cambiarTema(nuevo) {
|
|
|
295
330
|
process.exit(1);
|
|
296
331
|
}
|
|
297
332
|
const ficha = lista.find((t) => t.name === nuevo);
|
|
298
|
-
const
|
|
299
|
-
|
|
300
|
-
if (estado.
|
|
301
|
-
if (estado.
|
|
302
|
-
|
|
303
|
-
|
|
333
|
+
const fiel = ficha.branding === 'faithful';
|
|
334
|
+
const init = ['--theme', nuevo, '--connect', '--update'];
|
|
335
|
+
if (estado.css) init.push('--css', estado.css);
|
|
336
|
+
if (estado.brand) init.push('--out', estado.brand);
|
|
337
|
+
if (estado.animaciones) init.push('--animations');
|
|
338
|
+
|
|
339
|
+
// 1 · Marca generada (o recordada de un tema fiel): se recalcula para el tema nuevo.
|
|
340
|
+
if (estado.marca && !fiel) init.push(...argsMarca(estado.marca));
|
|
341
|
+
else if (estado.marca?.activa) {
|
|
342
|
+
init.push('--remember-brand');
|
|
343
|
+
console.log(`«${nuevo}» es un tema de sistema corporativo: se usa FIEL y se quita la marca generada (${estado.marca.primario}). Se recuerda: vuelve a ella al pasar a un tema que la admita.`);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// 2 · Colores escritos a mano para el tema anterior: taparían al nuevo.
|
|
347
|
+
const colores = estado.manual.colores;
|
|
348
|
+
const primManual = !estado.marca && !fiel ? estado.manual.primario : null;
|
|
349
|
+
const ejemplo = colores.slice(0, 4).map((d) => `${d.name} ${d.value}`).join(', ') + (colores.length > 4 ? `… (+${colores.length - 4})` : '');
|
|
350
|
+
let decision = val('brand');
|
|
351
|
+
if (decision && !['adapt', 'clean', 'clean-all', 'keep'].includes(decision)) { console.error(`--brand «${decision}» no válido. Usa: adapt · clean · clean-all · keep`); process.exit(1); }
|
|
352
|
+
if (colores.length && nuevo !== estado.tema && !decision) {
|
|
353
|
+
if (p) {
|
|
354
|
+
p.note(
|
|
355
|
+
[
|
|
356
|
+
`brand.css tiene ${colores.length} color(es) escritos a mano${estado.tema ? ` para «${estado.tema}»` : ''}:`,
|
|
357
|
+
` ${ejemplo}`,
|
|
358
|
+
'',
|
|
359
|
+
`brand.css va después del tema: si se quedan, «${nuevo}» no se verá con sus colores.`,
|
|
360
|
+
].join('\n'),
|
|
361
|
+
'Colores del tema anterior',
|
|
362
|
+
);
|
|
363
|
+
const opciones = [
|
|
364
|
+
...(primManual ? [{ value: 'adapt', label: 'Adaptar mi color al tema nuevo (recomendado)', hint: `quita esos colores y aplica tu primario ${primManual} sobre la paleta de «${nuevo}»` }] : []),
|
|
365
|
+
{ value: 'clean', label: `Usar los colores de «${nuevo}»${primManual ? '' : ' (recomendado)'}`, hint: 'quita esos colores (se comentan, con copia .bak); radios y fuentes se quedan' },
|
|
366
|
+
{ value: 'clean-all', label: 'Dejar brand.css limpio', hint: 'comenta todo lo escrito a mano (con copia .bak)' },
|
|
367
|
+
{ value: 'keep', label: 'Conservarlos', hint: 'seguirán tapando al tema nuevo' },
|
|
368
|
+
];
|
|
369
|
+
const v = await p.select({ message: '¿Qué hago con ellos?', initialValue: opciones[0].value, options: opciones });
|
|
370
|
+
if (p.isCancel(v)) { p.cancel('Sin cambios.'); return; }
|
|
371
|
+
decision = v;
|
|
372
|
+
} else {
|
|
373
|
+
decision = 'keep';
|
|
374
|
+
init.push('--keep-manual');
|
|
375
|
+
console.log(`Aviso: brand.css tiene ${colores.length} color(es) escritos a mano (${ejemplo}) que taparán a «${nuevo}». Se conservan.\n Para quitarlos: orbital-ds theme ${nuevo} --brand clean${primManual ? ` · para adaptar tu primario: --brand adapt` : ''}`);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
if (decision === 'adapt' && !primManual) {
|
|
379
|
+
console.error(fiel ? `«${nuevo}» se usa fiel: no admite adaptar un primario. Usa --brand clean.` : 'No hay un --primary escrito a mano en brand.css que adaptar. Usa --brand clean.');
|
|
380
|
+
process.exit(1);
|
|
381
|
+
}
|
|
382
|
+
if (decision === 'adapt') init.push('--clean', 'colors', '--primary', primManual, '--mode', 'primary');
|
|
383
|
+
if (decision === 'clean') init.push('--clean', 'colors');
|
|
384
|
+
if (decision === 'clean-all') init.push('--clean', 'all');
|
|
385
|
+
ejecutar('init.mjs', init);
|
|
304
386
|
}
|
|
305
387
|
|
|
306
388
|
async function menu() {
|
|
@@ -321,7 +403,7 @@ async function menu() {
|
|
|
321
403
|
});
|
|
322
404
|
if (p.isCancel(v)) { p.cancel('Nada que hacer.'); return; }
|
|
323
405
|
if (v === 'init') ejecutar('init.mjs', ['--wizard']);
|
|
324
|
-
if (v === 'theme') return cambiarTema(null);
|
|
406
|
+
if (v === 'theme') return cambiarTema(null, []);
|
|
325
407
|
if (v === 'doctor') ejecutar('doctor.mjs', ['--css', resolve('src/brand.css')]);
|
|
326
408
|
if (v === 'i18n') ejecutar('i18n.mjs', []);
|
|
327
409
|
if (v === 'skill') return ordenSkill([]);
|
|
@@ -342,7 +424,7 @@ switch (orden) {
|
|
|
342
424
|
ejecutar('init.mjs', resto.length ? resto : ['--wizard']);
|
|
343
425
|
break;
|
|
344
426
|
case 'theme':
|
|
345
|
-
await cambiarTema(resto.find((a) => !a.startsWith('--')) ?? null);
|
|
427
|
+
await cambiarTema(resto.find((a, i) => !a.startsWith('--') && resto[i - 1] !== '--brand') ?? null, resto);
|
|
346
428
|
break;
|
|
347
429
|
case 'doctor':
|
|
348
430
|
ejecutar('doctor.mjs', resto);
|