@shortwind/cli 0.1.0-beta.14 → 0.1.0-beta.15
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.
|
@@ -445,6 +445,21 @@ function blockSectionValues(selector) {
|
|
|
445
445
|
}
|
|
446
446
|
const THEME_LIGHT_VALUES = blockSectionValues(":root");
|
|
447
447
|
const THEME_DARK_VALUES = blockSectionValues(".dark");
|
|
448
|
+
const PREFERS_DARK_RE = /@media\s*\(\s*prefers-color-scheme\s*:\s*dark\s*\)/;
|
|
449
|
+
function darkSection(css, lines, { mediaWrapRoot = true } = {}) {
|
|
450
|
+
const out = [
|
|
451
|
+
".dark {",
|
|
452
|
+
...lines,
|
|
453
|
+
"}"
|
|
454
|
+
];
|
|
455
|
+
if (PREFERS_DARK_RE.test(css)) {
|
|
456
|
+
out.push("@media (prefers-color-scheme: dark) {");
|
|
457
|
+
if (mediaWrapRoot) out.push(" :root {", ...lines.map((l) => ` ${l}`), " }");
|
|
458
|
+
else out.push(...lines.map((l) => ` ${l}`));
|
|
459
|
+
out.push("}");
|
|
460
|
+
}
|
|
461
|
+
return out;
|
|
462
|
+
}
|
|
448
463
|
function buildThemeSupplement(css, missing) {
|
|
449
464
|
const tokens = missing.filter((t) => THEME_LIGHT_VALUES.has(t));
|
|
450
465
|
if (tokens.length === 0) return null;
|
|
@@ -457,13 +472,32 @@ function buildThemeSupplement(css, missing) {
|
|
|
457
472
|
...light,
|
|
458
473
|
"}"
|
|
459
474
|
];
|
|
460
|
-
if (dark.length > 0)
|
|
461
|
-
if (/@custom-variant\s+dark|\.dark\s*\{/.test(css)) lines.push(".dark {", ...dark, "}");
|
|
462
|
-
else if (/@media\s*\(\s*prefers-color-scheme\s*:\s*dark\s*\)/.test(css)) lines.push("@media (prefers-color-scheme: dark) {", " :root {", ...dark.map((l) => ` ${l}`), " }", "}");
|
|
463
|
-
}
|
|
475
|
+
if (dark.length > 0) lines.push(...darkSection(css, dark));
|
|
464
476
|
lines.push("@theme inline {", ...mapping, "}", "/* end shortwind theme-supplement */");
|
|
465
477
|
return lines.join("\n");
|
|
466
478
|
}
|
|
479
|
+
const DARK_CLASS_VARIANT = "@custom-variant dark (&:is(.dark *));";
|
|
480
|
+
const CUSTOM_VARIANT_RE = /@custom-variant\s+dark\b/;
|
|
481
|
+
function ensureDarkClassVariant(css) {
|
|
482
|
+
if (CUSTOM_VARIANT_RE.test(css)) return css;
|
|
483
|
+
const m = css.match(TAILWIND_IMPORT_RE);
|
|
484
|
+
if (!m) return css;
|
|
485
|
+
const at = (m.index ?? 0) + m[0].length;
|
|
486
|
+
return `${css.slice(0, at)}\n${DARK_CLASS_VARIANT}${css.slice(at)}`;
|
|
487
|
+
}
|
|
488
|
+
const DARK_PROMOTE_MARKER = "/* shortwind:dark-promote";
|
|
489
|
+
function promoteMediaDarkToClass(css) {
|
|
490
|
+
if (css.includes("/* shortwind:dark-promote")) return null;
|
|
491
|
+
const decls = [...(css.match(/@media\s*\(\s*prefers-color-scheme\s*:\s*dark\s*\)\s*\{\s*:root\s*\{([^}]*)\}/)?.[1] ?? "").matchAll(/--([\w-]+)\s*:\s*([^;]+);/g)].map((d) => ` --${d[1]}: ${d[2].trim()};`);
|
|
492
|
+
if (decls.length === 0) return null;
|
|
493
|
+
return [
|
|
494
|
+
`${DARK_PROMOTE_MARKER} — base dark tokens mirrored from your @media block so a .dark toggle drives them. */`,
|
|
495
|
+
".dark {",
|
|
496
|
+
...decls,
|
|
497
|
+
"}",
|
|
498
|
+
"/* end shortwind dark-promote */"
|
|
499
|
+
].join("\n");
|
|
500
|
+
}
|
|
467
501
|
const TONE_MARKER = "/* shortwind:tones";
|
|
468
502
|
const TONES = [
|
|
469
503
|
{
|
|
@@ -506,8 +540,7 @@ function buildToneBlock(css) {
|
|
|
506
540
|
const darkTones = TONES.filter((t) => t.darkBg && t.darkFg);
|
|
507
541
|
if (darkTones.length > 0) {
|
|
508
542
|
const darkRules = darkTones.map((t) => " " + rule(t.name, t.darkBg, t.darkFg));
|
|
509
|
-
|
|
510
|
-
else if (/@media\s*\(\s*prefers-color-scheme\s*:\s*dark\s*\)/.test(css)) lines.push("@media (prefers-color-scheme: dark) {", ...darkRules, "}");
|
|
543
|
+
lines.push(...darkSection(css, darkRules, { mediaWrapRoot: false }));
|
|
511
544
|
}
|
|
512
545
|
lines.push("/* end shortwind tones */");
|
|
513
546
|
return lines.join("\n");
|
|
@@ -708,6 +741,13 @@ async function init(options) {
|
|
|
708
741
|
themeAction = "supplemented";
|
|
709
742
|
}
|
|
710
743
|
}
|
|
744
|
+
if (theme.themePath) {
|
|
745
|
+
const css = await readFile(theme.themePath, "utf8");
|
|
746
|
+
let next = ensureDarkClassVariant(css);
|
|
747
|
+
const promote = promoteMediaDarkToClass(next);
|
|
748
|
+
if (promote) next = `${next.replace(/\s*$/, "")}\n\n${promote}\n`;
|
|
749
|
+
if (next !== css) await writeFile(theme.themePath, next);
|
|
750
|
+
}
|
|
711
751
|
let tonesPath = null;
|
|
712
752
|
let tonesAction = "skipped";
|
|
713
753
|
if (theme.themePath) {
|
|
@@ -2555,4 +2595,4 @@ function formatBenchTable(result) {
|
|
|
2555
2595
|
//#endregion
|
|
2556
2596
|
export { createRegistrySource as A, readConfig as C, init as D, cliVersion as E, extractHeader as F, rewriteHeaderSha as I, sealRecipeFile as L, detectProject as M, buildHeaderLine as N, readLockfile as O, computeBodySha as P, verifyFetchedFamily as R, installedFamilies as S, DEFAULT_REGISTRY as T, reseal as _, extractClassUsages as a, remove as b, verify as c, dev as d, BuildError as f, preset as g, ls as h, DEFAULT_CONTENT as i, resolvePresetFamilies as j, writeLockfile as k, UpgradeError as l, formatLsText as m, formatBenchTable as n, formatFindingsText as o, build as p, ALL_RULES as r, lint as s, bench as t, upgrade as u, NewFamilyError as v, renameFamilyInSource as w, add as x, newFamily as y };
|
|
2557
2597
|
|
|
2558
|
-
//# sourceMappingURL=bench-
|
|
2598
|
+
//# sourceMappingURL=bench-vo5aWJUx.js.map
|