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

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,103 @@ 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
+ const noop = { setText: () => {
648
+ } };
649
+ if (!ora) return await fn(noop);
650
+ const spinner = ora(label).start();
651
+ const begin = Date.now();
652
+ let current = label;
653
+ const refresh = () => {
654
+ const secs = Math.floor((Date.now() - begin) / 1e3);
655
+ spinner.text = secs > 0 ? `${current} (${secs}s)` : current;
656
+ };
657
+ const heartbeat = setInterval(refresh, 1e3);
658
+ if (typeof heartbeat.unref === "function") heartbeat.unref();
659
+ const handle = {
660
+ setText(text) {
661
+ current = text;
662
+ refresh();
663
+ }
664
+ };
665
+ try {
666
+ const result = await fn(handle);
667
+ clearInterval(heartbeat);
668
+ spinner.succeed(`${label} (${formatElapsed(Date.now() - begin)})`);
669
+ return result;
670
+ } catch (err) {
671
+ clearInterval(heartbeat);
672
+ spinner.fail(label);
673
+ throw err;
674
+ }
675
+ }
676
+ return { stage };
677
+ }
524
678
  async function publish(data, opts, tutorials) {
525
679
  const destination = opts.destination;
526
680
  if (!destination || typeof destination !== "string") {
@@ -528,6 +682,14 @@ async function publish(data, opts, tutorials) {
528
682
  'clean-jsdoc-theme publish: opts.destination is required (set "opts.destination" in your jsdoc.json).'
529
683
  );
530
684
  }
685
+ assertMarkdownPlugin();
686
+ const color = Boolean(process.stdout.isTTY) && opts.nocolor !== true;
687
+ const docsDir = typeof opts.docs === "string" && opts.docs.trim().length > 0 ? opts.docs.trim() : void 0;
688
+ const pkgPromise = resolvePkg(data, opts);
689
+ const sourcesPromise = outputSourceFilesEnabled(opts) ? collectSourceFiles(data) : Promise.resolve([]);
690
+ const docsPromise = docsDir ? collectDocs(docsDir) : Promise.resolve([]);
691
+ const ora = opts.progress === false ? null : await loadOra();
692
+ const progress = createBuildProgress(ora);
531
693
  const [
532
694
  { generateSite },
533
695
  { render, runPagefindAgainstDir },
@@ -539,17 +701,31 @@ async function publish(data, opts, tutorials) {
539
701
  normalizeBasePath,
540
702
  withBase
541
703
  }
542
- ] = await Promise.all([loadSetu(), loadDwar(), loadUtils()]);
704
+ // Loaded sequentially (not Promise.all) so the spinner can step its label
705
+ // through each module — the evaluation of these large ESM bundles is the
706
+ // single longest, most event-loop-blocking stage, so visibly naming the
707
+ // module in flight is what stops it from reading as a hang.
708
+ ] = await progress.stage("Loading renderer", async ({ setText }) => {
709
+ setText("Loading renderer (setu)");
710
+ const setu = await loadSetu();
711
+ setText("Loading renderer (dwar)");
712
+ const dwar = await loadDwar();
713
+ setText("Loading renderer (utils)");
714
+ const utils = await loadUtils();
715
+ return [setu, dwar, utils];
716
+ });
543
717
  const basePath = normalizeBasePath(opts.basePath);
544
718
  const hrefForServed = (servedPath) => withBase(basePath, "/" + servedPath);
545
719
  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;
720
+ const { value, diagnostics } = await progress.stage(
721
+ "Validating options",
722
+ () => validateThemeOpts({
723
+ opts,
724
+ fontResolver,
725
+ unknownKeyPolicy: "suggest-typos",
726
+ knownNonThemeKeys: JSDOC_OWN_OPTS
727
+ })
728
+ );
553
729
  const strict = opts.strict === true || opts.templates?.default?.strict === true;
554
730
  if (diagnostics.list.length > 0) {
555
731
  const formatted = formatDiagnostics(diagnostics, { color });
@@ -561,19 +737,29 @@ async function publish(data, opts, tutorials) {
561
737
  }
562
738
  console.log(formatted);
563
739
  }
564
- const pkg = await resolvePkg(data, opts);
740
+ const pkg = await pkgPromise;
565
741
  const readme = typeof opts.readme === "string" && opts.readme.length > 0 ? opts.readme : void 0;
566
742
  const tutorialTree = normalizeTutorials(tutorials);
567
- const sources = outputSourceFilesEnabled(opts) ? await collectSourceFiles(data) : [];
568
743
  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) : [];
744
+ const { sources, docs, docImageFiles, inlineSvgs } = await progress.stage(
745
+ "Reading sources & docs",
746
+ async () => {
747
+ const [srcs, rawDocs] = await Promise.all([sourcesPromise, docsPromise]);
748
+ const resolved = docsDir ? await resolveDocImages(rawDocs, docsDir) : { docs: rawDocs, files: [], inlineSvgs: {} };
749
+ return {
750
+ sources: srcs,
751
+ docs: resolved.docs,
752
+ docImageFiles: resolved.files,
753
+ inlineSvgs: resolved.inlineSvgs
754
+ };
755
+ }
756
+ );
571
757
  const docGroups = normalizeDocGroups(opts.docGroups);
572
758
  const defaultDocGroup = typeof opts.defaultDocGroup === "string" && opts.defaultDocGroup.trim().length > 0 ? opts.defaultDocGroup.trim() : void 0;
573
759
  const sectionOrder = normalizeSectionOrder(opts.sectionOrder);
574
760
  const menu = normalizeMenu(opts.menu);
575
761
  const clubSidebarItems = opts.clubSidebarItems === true;
576
- const manifest = generateSite(data, {
762
+ const manifest = await progress.stage("Generating pages", () => generateSite(data, {
577
763
  ...pkg ? { pkg } : {},
578
764
  ...readme ? { readme } : {},
579
765
  ...tutorialTree.length > 0 ? { tutorials: tutorialTree } : {},
@@ -585,7 +771,7 @@ async function publish(data, opts, tutorials) {
585
771
  ...sectionOrder ? { sectionOrder } : {},
586
772
  ...menu ? { menu } : {},
587
773
  ...clubSidebarItems ? { clubSidebarItems } : {}
588
- });
774
+ }));
589
775
  const { siteName, files: logoFiles } = await prepareSiteName(value.siteName, hrefForServed);
590
776
  const notGoogle = new Set(
591
777
  diagnostics.list.filter((d) => d.code === "fonts/not-google" && d.path).map((d) => d.path)
@@ -595,12 +781,21 @@ async function publish(data, opts, tutorials) {
595
781
  if (notGoogle.has("fonts.body")) delete fonts.body;
596
782
  const customAssets = await resolveCustomAssets(opts, hrefForServed);
597
783
  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);
784
+ const islandCacheDir = (0, import_node_path2.resolve)(process.cwd(), "node_modules", ".cache", "clean-jsdoc-theme");
785
+ const result = await progress.stage(
786
+ "Rendering site",
787
+ () => render(manifest, {
788
+ theme: { ...resolveTheme(opts, siteName, fonts, basePath), ...customAssets.theme },
789
+ destination: absoluteDestination,
790
+ islandCacheDir,
791
+ inlineSvgs
792
+ })
793
+ );
794
+ const outputFiles = [...result.files, ...logoFiles, ...customAssets.files, ...docImageFiles];
795
+ await progress.stage(
796
+ "Writing files",
797
+ () => writeOutputFiles(absoluteDestination, outputFiles)
798
+ );
604
799
  const zlib = await import("zlib");
605
800
  const gzipSizer = (b) => zlib.gzipSync(b).length;
606
801
  console.log(
@@ -621,21 +816,30 @@ async function publish(data, opts, tutorials) {
621
816
  }
622
817
  }
623
818
  try {
624
- await runPagefindAgainstDir(absoluteDestination);
819
+ await progress.stage(
820
+ "Indexing search (pagefind)",
821
+ () => runPagefindAgainstDir(absoluteDestination)
822
+ );
625
823
  } catch (err) {
626
- console.warn(`clean-jsdoc-theme: pagefind step skipped \u2014 ${err.message}`);
824
+ console.warn(
825
+ `clean-jsdoc-theme: pagefind step skipped (optional) \u2014 ${err.message}`
826
+ );
627
827
  }
628
828
  }
629
829
  // Annotate the CommonJS export names for ESM import in node:
630
830
  0 && (module.exports = {
631
831
  collectDocs,
632
832
  computeRelPaths,
833
+ hasMarkdownPlugin,
834
+ normalizeColors,
633
835
  normalizeCopyPage,
634
836
  normalizeDocGroups,
635
837
  normalizeMenu,
838
+ normalizePageNav,
636
839
  normalizeSectionOrder,
637
840
  outputSourceFilesEnabled,
638
841
  publish,
842
+ resolveDocImages,
639
843
  sourceLinkToCommentEnabled
640
844
  });
641
845
  //# sourceMappingURL=publish.js.map