orbital-ds 0.14.0 → 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 +97 -93
- package/dist/styles.css +1041 -1041
- package/dist/themes/liquid.css +502 -500
- package/dist/themes/liquid.fonts.css +7 -7
- package/dist/themes/liquid.guide.md +82 -73
- package/dist/themes/liquid.meta.json +134 -134
- package/dist/themes/liquid.scoped.css +502 -500
- package/dist/ui/badge.d.ts +1 -1
- package/dist/ui/bubble.d.ts +1 -1
- package/dist/ui/button.d.ts +1 -1
- package/dist/ui/item.d.ts +1 -1
- package/dist/ui/marker.d.ts +1 -1
- package/dist/ui/sparkline.d.ts +1 -1
- package/dist/ui/status-badge.d.ts +2 -2
- package/dist/ui/tabs.d.ts +1 -1
- package/package.json +181 -180
- package/scripts/brand-file.mjs +221 -0
- package/scripts/cli.mjs +452 -370
- package/scripts/init.mjs +176 -72
- package/scripts/setup.mjs +90 -10
|
@@ -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
|
+
}
|