@domphy/press 0.19.0 → 0.19.1

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.
@@ -277,10 +277,53 @@ function announcementBar(config) {
277
277
  ...idAttr ? { dataId: idAttr } : {}
278
278
  };
279
279
  }
280
- function header(config) {
280
+ function localeSwitcher(ctx) {
281
+ const { config, route } = ctx;
282
+ if (!config.locales) return null;
283
+ const entries = Object.entries(config.locales);
284
+ if (entries.length <= 1) return null;
285
+ let currentKey = "/";
286
+ let barePath = route;
287
+ for (const [key] of entries) {
288
+ if (key !== "/" && route.startsWith(key.replace(/\/$/, ""))) {
289
+ currentKey = key;
290
+ barePath = route.slice(key.replace(/\/$/, "").length) || "/";
291
+ break;
292
+ }
293
+ }
294
+ const currentLocale = config.locales[currentKey];
295
+ if (!currentLocale) return null;
296
+ const links = entries.map(([key, locale]) => {
297
+ const prefix = key === "/" ? "" : key.replace(/\/$/, "");
298
+ const href = prefix + (barePath === "/" ? "/" : barePath);
299
+ return {
300
+ a: locale.label,
301
+ href,
302
+ class: `dp-locale-option${key === currentKey ? " active" : ""}`,
303
+ ...key === currentKey ? { ariaCurrent: "true" } : {},
304
+ lang: locale.lang
305
+ };
306
+ });
307
+ return {
308
+ div: [
309
+ { span: ["\u{1F310} ", currentLocale.label], class: "dp-locale-current" },
310
+ { div: links, class: "dp-locale-menu" }
311
+ ],
312
+ class: "dp-locale-switcher",
313
+ ariaLabel: "Select language"
314
+ };
315
+ }
316
+ function header(ctx) {
317
+ const { config } = ctx;
281
318
  const searchEnabled = config.themeConfig.search !== false;
282
- const logoEl = config.themeConfig.logo ? { a: [{ img: null, src: config.themeConfig.logo, alt: config.title, class: "dp-logo-img" }], href: config.base, class: "dp-logo" } : { a: config.title, href: config.base, class: "dp-logo" };
319
+ const logo = config.themeConfig.logo;
320
+ const logoInner = logo ? typeof logo === "string" ? [{ img: null, src: logo, alt: config.title, class: "dp-logo-img" }] : [
321
+ { img: null, src: logo.light, alt: config.title, class: "dp-logo-img dp-logo-light" },
322
+ { img: null, src: logo.dark, alt: config.title, class: "dp-logo-img dp-logo-dark" }
323
+ ] : [];
324
+ const logoEl = logo ? { a: logoInner, href: config.base, class: "dp-logo" } : { a: config.title, href: config.base, class: "dp-logo" };
283
325
  const socialEls = (config.themeConfig.socialLinks ?? []).map(socialLinkEl);
326
+ const localeEl = localeSwitcher(ctx);
284
327
  return {
285
328
  header: [
286
329
  logoEl,
@@ -307,6 +350,7 @@ function header(config) {
307
350
  class: "dp-search-slot"
308
351
  }] : [],
309
352
  ...socialEls,
353
+ ...localeEl ? [localeEl] : [],
310
354
  { button: "\u25D0", type: "button", class: "dp-theme-toggle", ariaLabel: "Toggle dark mode", dataThemeToggle: "" },
311
355
  { button: "\u2630", type: "button", class: "dp-menu-toggle", ariaLabel: "Toggle menu", dataMenuToggle: "" }
312
356
  ],
@@ -377,9 +421,10 @@ function tocAside(ctx) {
377
421
  const [minLevel, maxLevel] = ctx.config.themeConfig.outline?.level ?? [2, 3];
378
422
  const entries = ctx.toc.filter((e) => e.level >= minLevel && e.level <= maxLevel);
379
423
  if (entries.length === 0) return null;
424
+ const tocTitle = ctx.config.themeConfig.tocTitle ?? "On this page";
380
425
  return {
381
426
  aside: [
382
- { div: "On this page", class: "dp-aside-title" },
427
+ { div: tocTitle, class: "dp-aside-title" },
383
428
  { nav: entries.map((e) => ({ a: e.text, href: `#${e.slug}`, class: `dp-toc-${e.level}` })), class: "dp-toc" }
384
429
  ],
385
430
  class: "dp-aside"
@@ -443,7 +488,7 @@ function pageShell(ctx) {
443
488
  return {
444
489
  div: [
445
490
  ...bar ? [bar] : [],
446
- header(ctx.config),
491
+ header(ctx),
447
492
  { div: shellChildren, class: "dp-shell" },
448
493
  { footer: ctx.config.themeConfig.footerMessage ?? "", class: "dp-footer" }
449
494
  ]
@@ -483,7 +528,7 @@ function homeShell(ctx) {
483
528
  return {
484
529
  div: [
485
530
  ...bar ? [bar] : [],
486
- header(ctx.config),
531
+ header(ctx),
487
532
  { main, class: "dp-main dp-main-home" },
488
533
  { footer: ctx.config.themeConfig.footerMessage ?? "", class: "dp-footer" }
489
534
  ]
@@ -669,6 +714,47 @@ function shapeContainers(tokens) {
669
714
  output.push(token);
670
715
  continue;
671
716
  }
717
+ if (token.type === "container_card-grid_open") {
718
+ token.tag = "div";
719
+ token.attrSet("class", "custom-block card-grid");
720
+ output.push(token);
721
+ continue;
722
+ }
723
+ if (token.type === "container_card-grid_close") {
724
+ token.tag = "div";
725
+ output.push(token);
726
+ continue;
727
+ }
728
+ if (token.type === "container_card_open") {
729
+ token.tag = "div";
730
+ token.attrSet("class", "custom-block card");
731
+ const title = containerTitle(token.info.trim(), "card");
732
+ output.push(token);
733
+ if (title) output.push(...buildTitleTokens(Token, "p", "paragraph_open", "paragraph_close", "card-title", title));
734
+ continue;
735
+ }
736
+ if (token.type === "container_card_close") {
737
+ token.tag = "div";
738
+ output.push(token);
739
+ continue;
740
+ }
741
+ if (token.type === "container_link-card_open") {
742
+ const info = token.info.trim().slice("link-card".length).trim();
743
+ const linkMatch = info.match(/^\[([^\]]+)\]\(([^)]+)\)/);
744
+ const href = linkMatch ? linkMatch[2] : "#";
745
+ const title = linkMatch ? linkMatch[1] : info;
746
+ token.tag = "a";
747
+ token.attrSet("class", "custom-block link-card");
748
+ token.attrSet("href", href);
749
+ output.push(token);
750
+ if (title) output.push(...buildTitleTokens(Token, "p", "paragraph_open", "paragraph_close", "link-card-title", title));
751
+ continue;
752
+ }
753
+ if (token.type === "container_link-card_close") {
754
+ token.tag = "a";
755
+ output.push(token);
756
+ continue;
757
+ }
672
758
  if (token.type === "container_code-group_open") {
673
759
  let depth = 0, closeIndex = -1;
674
760
  for (let j = i; j < tokens.length; j++) {
@@ -726,7 +812,7 @@ function createParser(docsDir, highlight) {
726
812
  md.use(emojiPlugin);
727
813
  const noopRender = () => "";
728
814
  const ADMONITION_NAMES = Object.keys(ADMONITION_TITLES);
729
- for (const name of [...ADMONITION_NAMES, "details", "code-group", "steps"]) {
815
+ for (const name of [...ADMONITION_NAMES, "details", "code-group", "steps", "card", "card-grid", "link-card"]) {
730
816
  md.use(container, name, { render: noopRender });
731
817
  }
732
818
  md.core.ruler.push("press_containers", (state) => {
@@ -915,6 +1001,21 @@ a:hover{text-decoration:underline}
915
1001
  .dp-theme-toggle,.dp-menu-toggle{border:1px solid ${border};background:${bgSoft};color:${text};border-radius:${ts(2)};width:${ts(8.5)};height:${ts(8.5)};cursor:pointer;font-size:16px}
916
1002
  .dp-menu-toggle{display:none}
917
1003
 
1004
+ /* --------------------------------------------------------- locale switcher */
1005
+ .dp-locale-switcher{position:relative;display:flex;align-items:center}
1006
+ .dp-locale-current{color:${textSoft};font-size:13px;font-weight:500;cursor:pointer;user-select:none;padding:${ts(1)} ${ts(2)};border:1px solid ${border};border-radius:${ts(1.5)};background:${bgSoft};white-space:nowrap;display:flex;align-items:center;gap:${ts(1)}}
1007
+ .dp-locale-current::after{content:" \u25BE";font-size:10px;opacity:.6}
1008
+ .dp-locale-menu{display:none;position:absolute;top:calc(100% + ${ts(2)});right:0;background:${bgSoft};border:1px solid ${border};border-radius:${ts(2)};padding:${ts(1.5)};min-width:${ts(32)};z-index:200;flex-direction:column;gap:${ts(0.5)};box-shadow:0 4px 16px rgba(0,0,0,.1)}
1009
+ .dp-locale-switcher:hover .dp-locale-menu,.dp-locale-switcher:focus-within .dp-locale-menu{display:flex}
1010
+ .dp-locale-option{display:block;padding:${ts(1.25)} ${ts(2.5)};border-radius:${ts(1.25)};font-size:13px;color:${textSoft}}
1011
+ .dp-locale-option:hover{background:${bgMute};color:${text};text-decoration:none}
1012
+ .dp-locale-option.active{color:${brand};font-weight:600}
1013
+
1014
+ /* -------------------------------------------------- logo light/dark variant */
1015
+ [data-theme="dark"] .dp-logo-light{display:none}
1016
+ [data-theme="light"] .dp-logo-dark,.dp-logo-dark{display:none}
1017
+ [data-theme="dark"] .dp-logo-dark{display:block}
1018
+
918
1019
  /* ------------------------------------------------------------ social links */
919
1020
  .dp-social-link{display:inline-flex;align-items:center;justify-content:center;width:${ts(8.5)};height:${ts(8.5)};border-radius:${ts(2)};color:${textSoft};background:${bgSoft};border:1px solid ${border};font-size:10px;font-weight:700;flex-shrink:0}
920
1021
  .dp-social-link:hover{color:${text};border-color:${textSoft};text-decoration:none}
@@ -947,6 +1048,15 @@ a:hover{text-decoration:underline}
947
1048
  .dp-toc-3{padding-left:${ts(3)}}
948
1049
  .dp-toc-4{padding-left:${ts(6)}}
949
1050
 
1051
+ /* -------------------------------------------------- card / link-card / card-grid */
1052
+ .custom-block.card{background:${bgSoft};border:1px solid ${border};border-radius:${ts(3)};padding:${ts(5)} ${ts(6)};margin:${ts(3)} 0}
1053
+ .custom-block.card .card-title{font-size:16px;font-weight:600;color:${textStrong};margin:0 0 ${ts(2)}}
1054
+ .custom-block.card-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(${ts(56)},1fr));gap:${ts(4)};margin:${ts(4)} 0}
1055
+ a.custom-block.link-card{display:block;background:${bgSoft};border:1px solid ${border};border-radius:${ts(3)};padding:${ts(5)} ${ts(6)};margin:${ts(3)} 0;transition:border-color .15s,background .15s;text-decoration:none;color:${text}}
1056
+ a.custom-block.link-card:hover{border-color:${brand};background:${bgMute};text-decoration:none}
1057
+ a.custom-block.link-card .link-card-title{font-size:16px;font-weight:600;color:${brand};margin:0 0 ${ts(2)}}
1058
+ .custom-block.card-grid .custom-block.card,.custom-block.card-grid a.custom-block.link-card{margin:0}
1059
+
950
1060
  /* ------------------------------------------------------------------ badges */
951
1061
  .dp-badge{display:inline-block;padding:${ts(0.5)} ${ts(1.75)};border-radius:${ts(2.5)};font-size:11px;font-weight:700;line-height:1.4;white-space:nowrap;vertical-align:middle}
952
1062
  .dp-badge-tip{background:color-mix(in srgb,${brand} 12%,${bg});color:${brand}}
@@ -1281,6 +1391,10 @@ async function buildSite(options) {
1281
1391
  for (const page of localePages) {
1282
1392
  const source = readFileSync2(page.filePath, "utf8");
1283
1393
  const doc = await renderDoc(source, { filePath: page.filePath, docsDir: srcDir, repoRoot: srcDir, highlight });
1394
+ if (doc.frontmatter.draft === true) {
1395
+ console.log(` \u21B7 ${page.route} (draft, skipped)`);
1396
+ continue;
1397
+ }
1284
1398
  sanitizeStyles(doc.body);
1285
1399
  const textParts = [];
1286
1400
  flattenText(doc.body, textParts);
package/dist/cli.js CHANGED
@@ -25,7 +25,7 @@ if (command === "build") {
25
25
  const srcDir = resolve(process.cwd(), flag("--src") ?? config.srcDir ?? ".");
26
26
  const outDir = resolve(process.cwd(), flag("--out") ?? config.outDir ?? "dist");
27
27
  const publicDir = resolve(process.cwd(), "public");
28
- const { buildSite } = await import("./build-6Q2QN246.js");
28
+ const { buildSite } = await import("./build-QKFFWX4D.js");
29
29
  await buildSite({
30
30
  config: { ...config, srcDir: config.srcDir ?? ".", outDir: config.outDir ?? "dist" },
31
31
  srcDir,
@@ -39,7 +39,7 @@ if (command === "build") {
39
39
  const srcDir = resolve(process.cwd(), flag("--src") ?? config.srcDir ?? ".");
40
40
  const outDir = resolve(process.cwd(), flag("--out") ?? config.outDir ?? ".press-dev");
41
41
  const publicDir = resolve(process.cwd(), "public");
42
- const { buildSite } = await import("./build-6Q2QN246.js");
42
+ const { buildSite } = await import("./build-QKFFWX4D.js");
43
43
  const { startDevServer } = await import("./serve-LQBYPP6C.js");
44
44
  async function rebuild() {
45
45
  const start = Date.now();
package/dist/index.d.ts CHANGED
@@ -37,7 +37,11 @@ interface ThemeConfig {
37
37
  nav: NavItem[];
38
38
  /** Keys are route prefixes (e.g. "/guide/"). Longest match wins. */
39
39
  sidebar: Record<string, SidebarItem[]>;
40
- logo?: string;
40
+ /** Single URL or separate light/dark variants. */
41
+ logo?: string | {
42
+ light: string;
43
+ dark: string;
44
+ };
41
45
  search?: false | {
42
46
  placeholder?: string;
43
47
  limit?: number;
@@ -49,6 +53,8 @@ interface ThemeConfig {
49
53
  outline?: {
50
54
  level: [number, number];
51
55
  };
56
+ /** TOC section heading text. Default "On this page". */
57
+ tocTitle?: string;
52
58
  /** Enable mermaid diagrams. Pass { cdn } to override CDN URL. */
53
59
  mermaid?: boolean | {
54
60
  cdn?: string;