clean-jsdoc-theme 5.0.0-alpha.1 → 5.0.0-alpha.2

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/dist/publish.js CHANGED
@@ -32,12 +32,16 @@ var publish_exports = {};
32
32
  __export(publish_exports, {
33
33
  collectDocs: () => collectDocs,
34
34
  computeRelPaths: () => computeRelPaths,
35
+ hasMarkdownPlugin: () => hasMarkdownPlugin,
36
+ normalizeColors: () => normalizeColors,
35
37
  normalizeCopyPage: () => normalizeCopyPage,
36
38
  normalizeDocGroups: () => normalizeDocGroups,
37
39
  normalizeMenu: () => normalizeMenu,
40
+ normalizePageNav: () => normalizePageNav,
38
41
  normalizeSectionOrder: () => normalizeSectionOrder,
39
42
  outputSourceFilesEnabled: () => outputSourceFilesEnabled,
40
43
  publish: () => publish,
44
+ resolveDocImages: () => resolveDocImages,
41
45
  sourceLinkToCommentEnabled: () => sourceLinkToCommentEnabled
42
46
  });
43
47
  module.exports = __toCommonJS(publish_exports);
@@ -93,25 +97,26 @@ function resolvePackageDir(name) {
93
97
  }
94
98
  throw new Error(`clean-jsdoc-theme: could not locate '${name}' on disk starting from ${start}.`);
95
99
  }
100
+ function resolveExportTarget(node, pkgRoot) {
101
+ if (typeof node === "string") return (0, import_node_path2.resolve)(pkgRoot, node);
102
+ if (!node || typeof node !== "object") return void 0;
103
+ const o = node;
104
+ const imp = resolveExportTarget(o.import, pkgRoot);
105
+ if (imp) return imp;
106
+ if (typeof o.default === "string") return (0, import_node_path2.resolve)(pkgRoot, o.default);
107
+ return void 0;
108
+ }
96
109
  function resolveEsmEntry(name) {
97
110
  const pkgRoot = resolvePackageDir(name);
98
111
  const pkg = JSON.parse(
99
112
  (0, import_node_fs.readFileSync)((0, import_node_path2.resolve)(pkgRoot, "package.json"), "utf8")
100
113
  );
101
114
  const exp = pkg.exports;
115
+ if (typeof exp === "string") return (0, import_node_path2.resolve)(pkgRoot, exp);
102
116
  if (exp && typeof exp === "object") {
103
117
  const dot = exp["."];
104
- if (typeof dot === "string") return (0, import_node_path2.resolve)(pkgRoot, dot);
105
- if (dot && typeof dot === "object") {
106
- const imp = dot.import;
107
- if (typeof imp === "string") return (0, import_node_path2.resolve)(pkgRoot, imp);
108
- if (imp && typeof imp === "object") {
109
- const def2 = imp.default;
110
- if (typeof def2 === "string") return (0, import_node_path2.resolve)(pkgRoot, def2);
111
- }
112
- const def = dot.default;
113
- if (typeof def === "string") return (0, import_node_path2.resolve)(pkgRoot, def);
114
- }
118
+ const target = resolveExportTarget(dot !== void 0 ? dot : exp, pkgRoot);
119
+ if (target) return target;
115
120
  }
116
121
  if (typeof pkg.module === "string") return (0, import_node_path2.resolve)(pkgRoot, pkg.module);
117
122
  if (typeof pkg.main === "string") return (0, import_node_path2.resolve)(pkgRoot, pkg.main);
@@ -142,6 +147,14 @@ var loadUtils = () => loadDep("@clean-jsdoc-theme/utils", [
142
147
  "normalizeBasePath",
143
148
  "withBase"
144
149
  ]);
150
+ var loadOra = async () => {
151
+ try {
152
+ const mod = await loadDep("ora", ["default"]);
153
+ return mod.default;
154
+ } catch {
155
+ return null;
156
+ }
157
+ };
145
158
  var JSDOC_OWN_OPTS = /* @__PURE__ */ new Set([
146
159
  "destination",
147
160
  "template",
@@ -197,13 +210,19 @@ var defaultTheme = {
197
210
  function resolveTheme(opts, siteName, fonts, basePath) {
198
211
  const aiPrompt = typeof opts.aiPrompt === "string" && opts.aiPrompt.trim() ? opts.aiPrompt.trim() : void 0;
199
212
  const copyPage = normalizeCopyPage(opts.copyPage);
213
+ const pageNav = normalizePageNav(opts.pageNav);
214
+ const colors = normalizeColors(opts.colors);
215
+ const darkColors = normalizeColors(opts.darkColors);
200
216
  return {
201
217
  ...defaultTheme,
202
218
  basePath,
203
219
  ...aiPrompt ? { aiPrompt } : {},
204
220
  ...copyPage ? { copyPage } : {},
221
+ ...pageNav ? { pageNav } : {},
205
222
  tokens: {
206
223
  ...defaultTheme.tokens,
224
+ colors: { ...defaultTheme.tokens.colors, ...colors ?? {} },
225
+ darkColors: { ...defaultTheme.tokens.darkColors, ...darkColors ?? {} },
207
226
  fonts: {
208
227
  heading: fonts.heading ?? defaultTheme.tokens.fonts.heading,
209
228
  body: fonts.body ?? defaultTheme.tokens.fonts.body,
@@ -286,7 +305,7 @@ async function prepareSiteName(raw, hrefForServed) {
286
305
  try {
287
306
  const abs = (0, import_node_path2.resolve)(v);
288
307
  const buf = await (0, import_promises2.readFile)(abs);
289
- const served = `_assets/logo-${key}${(0, import_node_path2.extname)(abs)}`;
308
+ const served = `_assets/logo-${key}.${contentHash(buf)}${(0, import_node_path2.extname)(abs)}`;
290
309
  files.push({ path: served, contents: buf });
291
310
  out[key] = hrefForServed(served);
292
311
  } catch {
@@ -364,6 +383,29 @@ function sourceLinkToCommentEnabled(opts) {
364
383
  if (opts?.templates?.default?.sourceLinkToComment === true) return true;
365
384
  return false;
366
385
  }
386
+ function hasMarkdownPlugin(plugins) {
387
+ if (!Array.isArray(plugins)) return false;
388
+ return plugins.some(
389
+ (p) => typeof p === "string" && /(^|[\\/])markdown(\.js)?$/i.test(p.trim())
390
+ );
391
+ }
392
+ function assertMarkdownPlugin() {
393
+ let conf;
394
+ try {
395
+ conf = require("jsdoc/env").conf;
396
+ } catch {
397
+ return;
398
+ }
399
+ if (!conf) return;
400
+ if (!hasMarkdownPlugin(conf.plugins)) {
401
+ throw new Error(
402
+ `clean-jsdoc-theme requires JSDoc's "plugins/markdown" plugin, which renders Markdown in doclet descriptions to HTML. Add it to your jsdoc.json:
403
+
404
+ "plugins": ["plugins/markdown"]
405
+ `
406
+ );
407
+ }
408
+ }
367
409
  function normalizeSectionOrder(raw) {
368
410
  if (!Array.isArray(raw)) return void 0;
369
411
  const out = raw.filter((s) => typeof s === "string").map((s) => s.trim()).filter((s) => s.length > 0);
@@ -410,6 +452,24 @@ function normalizeCopyPage(raw) {
410
452
  }
411
453
  return Object.keys(config).length > 0 ? config : void 0;
412
454
  }
455
+ function normalizePageNav(raw) {
456
+ if (raw === false) return { enabled: false };
457
+ if (raw === true || raw == null) return void 0;
458
+ if (typeof raw !== "object") return void 0;
459
+ const enabled = raw.enabled;
460
+ return typeof enabled === "boolean" ? { enabled } : void 0;
461
+ }
462
+ var COLOR_KEYS = ["bg", "bgMuted", "fg", "fgMuted", "accent", "accentFg", "border"];
463
+ function normalizeColors(raw) {
464
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return void 0;
465
+ const src = raw;
466
+ const out = {};
467
+ for (const key of COLOR_KEYS) {
468
+ const v = src[key];
469
+ if (typeof v === "string" && v.trim().length > 0) out[key] = v.trim();
470
+ }
471
+ return Object.keys(out).length > 0 ? out : void 0;
472
+ }
413
473
  var SOURCE_EXTENSIONS = /* @__PURE__ */ new Set([".js", ".mjs", ".cjs", ".jsx", ".ts", ".mts", ".cts", ".tsx"]);
414
474
  function computeRelPaths(absPaths) {
415
475
  const out = /* @__PURE__ */ new Map();
@@ -518,9 +578,86 @@ async function collectDocs(dir) {
518
578
  docs.sort((a, b) => a.path.localeCompare(b.path));
519
579
  return docs;
520
580
  }
581
+ var DOC_IMAGE_RE = /(!\[[^\]]*\]\()([^)\s]+)((?:\s+"[^"]*")?\))/g;
582
+ async function resolveDocImages(docs, docsDir) {
583
+ if (docs.length === 0) return { docs, files: [], inlineSvgs: {} };
584
+ const root = (0, import_node_path2.resolve)(docsDir);
585
+ const files = [];
586
+ const seenServed = /* @__PURE__ */ new Set();
587
+ const inlineSvgs = {};
588
+ const cache = /* @__PURE__ */ new Map();
589
+ const resolveOne = async (rawSrc, docDir) => {
590
+ const src = rawSrc.trim();
591
+ if (!src || isServableUrl(src) || src.startsWith("#") || src.startsWith("data:")) return null;
592
+ const abs = src.startsWith("/") ? (0, import_node_path2.resolve)(src.slice(1)) : (0, import_node_path2.resolve)(docDir, src);
593
+ if (cache.has(abs)) return cache.get(abs) ?? null;
594
+ let bytes;
595
+ try {
596
+ bytes = await (0, import_promises2.readFile)(abs);
597
+ } catch {
598
+ console.warn(
599
+ `clean-jsdoc-theme: could not read doc image '${src}' (resolved '${abs}'); leaving it as-is.`
600
+ );
601
+ cache.set(abs, null);
602
+ return null;
603
+ }
604
+ const ext = (0, import_node_path2.extname)(abs);
605
+ const served = `_assets/${(0, import_node_path2.basename)(abs, ext) || "asset"}.${contentHash(bytes)}${ext}`;
606
+ if (!seenServed.has(served)) {
607
+ seenServed.add(served);
608
+ files.push({ path: served, contents: bytes });
609
+ }
610
+ const href = "/" + served;
611
+ if (ext.toLowerCase() === ".svg") {
612
+ inlineSvgs[href] = bytes.toString("utf8").replace(/<svg\b/, '<svg style="max-width:100%;height:auto;display:block"');
613
+ }
614
+ cache.set(abs, href);
615
+ return href;
616
+ };
617
+ const out = [];
618
+ for (const doc of docs) {
619
+ const docDir = (0, import_node_path2.dirname)((0, import_node_path2.resolve)(root, doc.path));
620
+ const map = /* @__PURE__ */ new Map();
621
+ for (const m of doc.content.matchAll(DOC_IMAGE_RE)) {
622
+ const src = m[2];
623
+ if (map.has(src)) continue;
624
+ const href = await resolveOne(src, docDir);
625
+ if (href) map.set(src, href);
626
+ }
627
+ if (map.size === 0) {
628
+ out.push(doc);
629
+ continue;
630
+ }
631
+ const content = doc.content.replace(
632
+ DOC_IMAGE_RE,
633
+ (full, pre, src, post) => map.has(src) ? `${pre}${map.get(src)}${post}` : full
634
+ );
635
+ out.push({ ...doc, content });
636
+ }
637
+ return { docs: out, files, inlineSvgs };
638
+ }
521
639
  function normalizeDocGroups(raw) {
522
640
  return normalizeSectionOrder(raw);
523
641
  }
642
+ function formatElapsed(ms) {
643
+ return ms < 1e3 ? `${ms}ms` : `${(ms / 1e3).toFixed(1)}s`;
644
+ }
645
+ function createBuildProgress(ora) {
646
+ async function stage(label, fn) {
647
+ if (!ora) return await fn();
648
+ const spinner = ora(label).start();
649
+ const begin = Date.now();
650
+ try {
651
+ const result = await fn();
652
+ spinner.succeed(`${label} (${formatElapsed(Date.now() - begin)})`);
653
+ return result;
654
+ } catch (err) {
655
+ spinner.fail(label);
656
+ throw err;
657
+ }
658
+ }
659
+ return { stage };
660
+ }
524
661
  async function publish(data, opts, tutorials) {
525
662
  const destination = opts.destination;
526
663
  if (!destination || typeof destination !== "string") {
@@ -528,6 +665,14 @@ async function publish(data, opts, tutorials) {
528
665
  'clean-jsdoc-theme publish: opts.destination is required (set "opts.destination" in your jsdoc.json).'
529
666
  );
530
667
  }
668
+ assertMarkdownPlugin();
669
+ const color = Boolean(process.stdout.isTTY) && opts.nocolor !== true;
670
+ const docsDir = typeof opts.docs === "string" && opts.docs.trim().length > 0 ? opts.docs.trim() : void 0;
671
+ const pkgPromise = resolvePkg(data, opts);
672
+ const sourcesPromise = outputSourceFilesEnabled(opts) ? collectSourceFiles(data) : Promise.resolve([]);
673
+ const docsPromise = docsDir ? collectDocs(docsDir) : Promise.resolve([]);
674
+ const ora = opts.progress === false ? null : await loadOra();
675
+ const progress = createBuildProgress(ora);
531
676
  const [
532
677
  { generateSite },
533
678
  { render, runPagefindAgainstDir },
@@ -539,17 +684,22 @@ async function publish(data, opts, tutorials) {
539
684
  normalizeBasePath,
540
685
  withBase
541
686
  }
542
- ] = await Promise.all([loadSetu(), loadDwar(), loadUtils()]);
687
+ ] = await progress.stage(
688
+ "Loading renderer",
689
+ () => Promise.all([loadSetu(), loadDwar(), loadUtils()])
690
+ );
543
691
  const basePath = normalizeBasePath(opts.basePath);
544
692
  const hrefForServed = (servedPath) => withBase(basePath, "/" + servedPath);
545
693
  const fontResolver = createGoogleFontResolver();
546
- const { value, diagnostics } = await validateThemeOpts({
547
- opts,
548
- fontResolver,
549
- unknownKeyPolicy: "suggest-typos",
550
- knownNonThemeKeys: JSDOC_OWN_OPTS
551
- });
552
- const color = Boolean(process.stdout.isTTY) && opts.nocolor !== true;
694
+ const { value, diagnostics } = await progress.stage(
695
+ "Validating options",
696
+ () => validateThemeOpts({
697
+ opts,
698
+ fontResolver,
699
+ unknownKeyPolicy: "suggest-typos",
700
+ knownNonThemeKeys: JSDOC_OWN_OPTS
701
+ })
702
+ );
553
703
  const strict = opts.strict === true || opts.templates?.default?.strict === true;
554
704
  if (diagnostics.list.length > 0) {
555
705
  const formatted = formatDiagnostics(diagnostics, { color });
@@ -561,19 +711,29 @@ async function publish(data, opts, tutorials) {
561
711
  }
562
712
  console.log(formatted);
563
713
  }
564
- const pkg = await resolvePkg(data, opts);
714
+ const pkg = await pkgPromise;
565
715
  const readme = typeof opts.readme === "string" && opts.readme.length > 0 ? opts.readme : void 0;
566
716
  const tutorialTree = normalizeTutorials(tutorials);
567
- const sources = outputSourceFilesEnabled(opts) ? await collectSourceFiles(data) : [];
568
717
  const sourceLinkToComment = sourceLinkToCommentEnabled(opts);
569
- const docsDir = typeof opts.docs === "string" && opts.docs.trim().length > 0 ? opts.docs.trim() : void 0;
570
- const docs = docsDir ? await collectDocs(docsDir) : [];
718
+ const { sources, docs, docImageFiles, inlineSvgs } = await progress.stage(
719
+ "Reading sources & docs",
720
+ async () => {
721
+ const [srcs, rawDocs] = await Promise.all([sourcesPromise, docsPromise]);
722
+ const resolved = docsDir ? await resolveDocImages(rawDocs, docsDir) : { docs: rawDocs, files: [], inlineSvgs: {} };
723
+ return {
724
+ sources: srcs,
725
+ docs: resolved.docs,
726
+ docImageFiles: resolved.files,
727
+ inlineSvgs: resolved.inlineSvgs
728
+ };
729
+ }
730
+ );
571
731
  const docGroups = normalizeDocGroups(opts.docGroups);
572
732
  const defaultDocGroup = typeof opts.defaultDocGroup === "string" && opts.defaultDocGroup.trim().length > 0 ? opts.defaultDocGroup.trim() : void 0;
573
733
  const sectionOrder = normalizeSectionOrder(opts.sectionOrder);
574
734
  const menu = normalizeMenu(opts.menu);
575
735
  const clubSidebarItems = opts.clubSidebarItems === true;
576
- const manifest = generateSite(data, {
736
+ const manifest = await progress.stage("Generating pages", () => generateSite(data, {
577
737
  ...pkg ? { pkg } : {},
578
738
  ...readme ? { readme } : {},
579
739
  ...tutorialTree.length > 0 ? { tutorials: tutorialTree } : {},
@@ -585,7 +745,7 @@ async function publish(data, opts, tutorials) {
585
745
  ...sectionOrder ? { sectionOrder } : {},
586
746
  ...menu ? { menu } : {},
587
747
  ...clubSidebarItems ? { clubSidebarItems } : {}
588
- });
748
+ }));
589
749
  const { siteName, files: logoFiles } = await prepareSiteName(value.siteName, hrefForServed);
590
750
  const notGoogle = new Set(
591
751
  diagnostics.list.filter((d) => d.code === "fonts/not-google" && d.path).map((d) => d.path)
@@ -595,12 +755,21 @@ async function publish(data, opts, tutorials) {
595
755
  if (notGoogle.has("fonts.body")) delete fonts.body;
596
756
  const customAssets = await resolveCustomAssets(opts, hrefForServed);
597
757
  const absoluteDestination = (0, import_node_path2.resolve)(destination);
598
- const result = await render(manifest, {
599
- theme: { ...resolveTheme(opts, siteName, fonts, basePath), ...customAssets.theme },
600
- destination: absoluteDestination
601
- });
602
- const outputFiles = [...result.files, ...logoFiles, ...customAssets.files];
603
- await writeOutputFiles(absoluteDestination, outputFiles);
758
+ const islandCacheDir = (0, import_node_path2.resolve)(process.cwd(), "node_modules", ".cache", "clean-jsdoc-theme");
759
+ const result = await progress.stage(
760
+ "Rendering site",
761
+ () => render(manifest, {
762
+ theme: { ...resolveTheme(opts, siteName, fonts, basePath), ...customAssets.theme },
763
+ destination: absoluteDestination,
764
+ islandCacheDir,
765
+ inlineSvgs
766
+ })
767
+ );
768
+ const outputFiles = [...result.files, ...logoFiles, ...customAssets.files, ...docImageFiles];
769
+ await progress.stage(
770
+ "Writing files",
771
+ () => writeOutputFiles(absoluteDestination, outputFiles)
772
+ );
604
773
  const zlib = await import("zlib");
605
774
  const gzipSizer = (b) => zlib.gzipSync(b).length;
606
775
  console.log(
@@ -621,21 +790,30 @@ async function publish(data, opts, tutorials) {
621
790
  }
622
791
  }
623
792
  try {
624
- await runPagefindAgainstDir(absoluteDestination);
793
+ await progress.stage(
794
+ "Indexing search (pagefind)",
795
+ () => runPagefindAgainstDir(absoluteDestination)
796
+ );
625
797
  } catch (err) {
626
- console.warn(`clean-jsdoc-theme: pagefind step skipped \u2014 ${err.message}`);
798
+ console.warn(
799
+ `clean-jsdoc-theme: pagefind step skipped (optional) \u2014 ${err.message}`
800
+ );
627
801
  }
628
802
  }
629
803
  // Annotate the CommonJS export names for ESM import in node:
630
804
  0 && (module.exports = {
631
805
  collectDocs,
632
806
  computeRelPaths,
807
+ hasMarkdownPlugin,
808
+ normalizeColors,
633
809
  normalizeCopyPage,
634
810
  normalizeDocGroups,
635
811
  normalizeMenu,
812
+ normalizePageNav,
636
813
  normalizeSectionOrder,
637
814
  outputSourceFilesEnabled,
638
815
  publish,
816
+ resolveDocImages,
639
817
  sourceLinkToCommentEnabled
640
818
  });
641
819
  //# sourceMappingURL=publish.js.map