@massimo-cassandro/minimo 1.41.9 → 1.41.11
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/dev-tools/design-tokens-builder/build-tokens-src/build-source-modes.mjs +1 -1
- package/dev-tools/design-tokens-builder/build-tokens-src/light-dark.mjs +3 -1
- package/dev-tools/design-tokens-builder/build-tokens-src/merge-css.mjs +57 -1
- package/package.json +1 -1
- package/src/css/headings.css +1 -1
|
@@ -83,7 +83,7 @@ export const buildSourceModes = async ({
|
|
|
83
83
|
// Legge il destFile preesistente (se c'è) PRIMA che venga eseguita qualsiasi istanza
|
|
84
84
|
// di Style Dictionary, dato che la prima a scrivere lo sovrascriverebbe.
|
|
85
85
|
if (mergeCustomProps) {
|
|
86
|
-
loadExistingCustomPropsScoped(path.join(buildPath, destFile), baseMode, mergeCustomProps, customPropsSelector);
|
|
86
|
+
loadExistingCustomPropsScoped(path.join(buildPath, destFile), baseMode, mergeCustomProps, customPropsSelector, modeNames);
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
const cssTransforms = pxToRem
|
|
@@ -24,7 +24,9 @@
|
|
|
24
24
|
`color-scheme` effettivo, indipendentemente dal fatto che la dichiarazione stessa
|
|
25
25
|
si trovi dentro una regola `@media (prefers-color-scheme: ...)` o meno.
|
|
26
26
|
|
|
27
|
-
Interazione con `mergeCustomProps`:
|
|
27
|
+
Interazione con `mergeCustomProps`: le dichiarazioni preesistenti `light-dark(X, Y)` vengono
|
|
28
|
+
scomposte in X (light) e Y (dark) già in fase di lettura (vedi loadExistingCustomPropsScoped()
|
|
29
|
+
in ../merge-css.mjs), così da non essere ricombinate annidate. Per il resto il merge
|
|
28
30
|
per modalità con le custom properties preesistenti (vedi ../merge-css.mjs)
|
|
29
31
|
viene già eseguito prima, dentro computeFinalProps() (formats/css.mjs), prima che
|
|
30
32
|
questo modulo veda le proprietà. Quindi un file preesistente scritto con la
|
|
@@ -205,6 +205,41 @@ export const loadExistingCustomProps = (absDestPath, sources = true) => {
|
|
|
205
205
|
return existingCustomProps;
|
|
206
206
|
};
|
|
207
207
|
|
|
208
|
+
/*
|
|
209
|
+
Se la coda di una dichiarazione (valore + `;` + eventuale commento finale) è interamente
|
|
210
|
+
una chiamata `light-dark(X, Y)`, restituisce le due metà con il commento finale; altrimenti
|
|
211
|
+
null. La virgola di primo livello è individuata contando la profondità delle parentesi,
|
|
212
|
+
così che argomenti come `var(--a, red)` non vengano spezzati.
|
|
213
|
+
*/
|
|
214
|
+
/** @param {string} tail @returns {{light:string, dark:string}|null} */
|
|
215
|
+
const splitLightDarkTail = (tail) => {
|
|
216
|
+
const match = /^light-dark\(/.exec(tail);
|
|
217
|
+
if (!match) return null;
|
|
218
|
+
let depth = 0;
|
|
219
|
+
let commaIdx = -1;
|
|
220
|
+
let closeIdx = -1;
|
|
221
|
+
for (let i = match[0].length - 1; i < tail.length; i++) {
|
|
222
|
+
const ch = tail[i];
|
|
223
|
+
if (ch === '(') depth++;
|
|
224
|
+
else if (ch === ')') {
|
|
225
|
+
depth--;
|
|
226
|
+
if (depth === 0) { closeIdx = i; break; }
|
|
227
|
+
} else if (ch === ',' && depth === 1) {
|
|
228
|
+
if (commaIdx !== -1) return null;
|
|
229
|
+
commaIdx = i;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (commaIdx === -1 || closeIdx === -1) return null;
|
|
233
|
+
const rest = tail.slice(closeIdx + 1);
|
|
234
|
+
if (!/^\s*;\s*(\/\*.*\*\/)?\s*$/.test(rest)) return null;
|
|
235
|
+
const suffix = rest.trim();
|
|
236
|
+
const open = match[0].length;
|
|
237
|
+
return {
|
|
238
|
+
light: `${tail.slice(open, commaIdx).trim()}${suffix}`,
|
|
239
|
+
dark: `${tail.slice(commaIdx + 1, closeIdx).trim()}${suffix}`,
|
|
240
|
+
};
|
|
241
|
+
};
|
|
242
|
+
|
|
208
243
|
/**
|
|
209
244
|
* Equivalente sourceModes di loadExistingCustomProps(): legge il file CSS di
|
|
210
245
|
* destinazione (se esiste) e memorizza una mappa nome → valore per modalità,
|
|
@@ -217,9 +252,12 @@ export const loadExistingCustomProps = (absDestPath, sources = true) => {
|
|
|
217
252
|
* array solo i file sorgente dei token corrispondenti a una delle sue voci (default: true)
|
|
218
253
|
* @param {string} [selector] il customPropsSelector con cui è stato generato il file
|
|
219
254
|
* preesistente (default: ':root' — vedi config.mjs)
|
|
255
|
+
* @param {string[]} [modeNames] chiavi di sourceModes: se includono sia `light` sia `dark`, le
|
|
256
|
+
* dichiarazioni preesistenti `light-dark(X, Y)` vengono scomposte in X (light) e Y (dark),
|
|
257
|
+
* per evitare che vengano ricombinate annidate (default: [])
|
|
220
258
|
* @returns {Record<string, Record<string,string>>|null}
|
|
221
259
|
*/
|
|
222
|
-
export const loadExistingCustomPropsScoped = (absDestPath, baseMode, sources = true, selector = ':root') => {
|
|
260
|
+
export const loadExistingCustomPropsScoped = (absDestPath, baseMode, sources = true, selector = ':root', modeNames = []) => {
|
|
223
261
|
mergeSources = sources;
|
|
224
262
|
if (!existsSync(absDestPath)) {
|
|
225
263
|
scopedExistingCustomProps = null;
|
|
@@ -234,6 +272,24 @@ export const loadExistingCustomPropsScoped = (absDestPath, baseMode, sources = t
|
|
|
234
272
|
if (mode === '__base__') continue;
|
|
235
273
|
scopedExistingCustomProps[mode] = parseCustomProps(body);
|
|
236
274
|
}
|
|
275
|
+
|
|
276
|
+
if (modeNames.includes('light') && modeNames.includes('dark')) {
|
|
277
|
+
const baseProps = scopedExistingCustomProps[baseMode] ?? {};
|
|
278
|
+
for (const [name, tail] of Object.entries(baseProps)) {
|
|
279
|
+
const halves = splitLightDarkTail(tail);
|
|
280
|
+
if (!halves) continue;
|
|
281
|
+
scopedExistingCustomProps.light ??= {};
|
|
282
|
+
scopedExistingCustomProps.dark ??= {};
|
|
283
|
+
// una voce esplicita già presente nel blocco della modalità ha la precedenza
|
|
284
|
+
scopedExistingCustomProps.light[name] ??= halves.light;
|
|
285
|
+
scopedExistingCustomProps.dark[name] ??= halves.dark;
|
|
286
|
+
// se la base è light/dark, la voce è stata appena riassegnata sopra: va comunque
|
|
287
|
+
// allineata alla propria metà
|
|
288
|
+
if (baseMode === 'light') scopedExistingCustomProps.light[name] = halves.light;
|
|
289
|
+
else if (baseMode === 'dark') scopedExistingCustomProps.dark[name] = halves.dark;
|
|
290
|
+
else delete baseProps[name];
|
|
291
|
+
}
|
|
292
|
+
}
|
|
237
293
|
return scopedExistingCustomProps;
|
|
238
294
|
};
|
|
239
295
|
|
package/package.json
CHANGED
package/src/css/headings.css
CHANGED