clean-jsdoc-theme 4.3.2 → 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.
Files changed (86) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +82 -625
  3. package/dist/publish.d.mts +287 -0
  4. package/dist/publish.d.ts +287 -0
  5. package/dist/publish.js +819 -0
  6. package/dist/publish.js.map +1 -0
  7. package/dist/publish.mjs +779 -0
  8. package/dist/publish.mjs.map +1 -0
  9. package/package.json +66 -55
  10. package/.eslintignore +0 -5
  11. package/.eslintrc.js +0 -3
  12. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -43
  13. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -27
  14. package/.github/dependabot.yml +0 -9
  15. package/.github/pull_request_template.md +0 -16
  16. package/.github/workflows/codeql.yml +0 -72
  17. package/.github/workflows/greetings.yml +0 -16
  18. package/.prettierignore +0 -2
  19. package/.prettierrc +0 -5
  20. package/.stylelintignore +0 -4
  21. package/.stylelintrc +0 -18
  22. package/.travis.yml +0 -30
  23. package/CHANGELOG.md +0 -260
  24. package/CODE_OF_CONDUCT.md +0 -76
  25. package/CODE_OF_CONDUCT_HINDI.md +0 -61
  26. package/CONTRIBUTING.md +0 -36
  27. package/SECURITY.md +0 -21
  28. package/clean-jsdoc-theme-defaults.js +0 -37
  29. package/clean-jsdoc-theme-helper.js +0 -186
  30. package/css-property-order-fix.js +0 -56
  31. package/helpers/Environment.html +0 -3
  32. package/helpers/down-arrow.js +0 -9
  33. package/jsdoc-config.json +0 -102
  34. package/minify.js +0 -72
  35. package/publish.js +0 -1110
  36. package/static/fonts/Inconsolata-Regular.ttf +0 -0
  37. package/static/fonts/OpenSans-Regular.ttf +0 -0
  38. package/static/fonts/WorkSans-Bold.ttf +0 -0
  39. package/static/scripts/core.js +0 -726
  40. package/static/scripts/core.min.js +0 -23
  41. package/static/scripts/resize.js +0 -90
  42. package/static/scripts/search.js +0 -265
  43. package/static/scripts/search.min.js +0 -6
  44. package/static/scripts/third-party/Apache-License-2.0.txt +0 -202
  45. package/static/scripts/third-party/fuse.js +0 -9
  46. package/static/scripts/third-party/hljs-line-num-original.js +0 -369
  47. package/static/scripts/third-party/hljs-line-num.js +0 -1
  48. package/static/scripts/third-party/hljs-original.js +0 -5171
  49. package/static/scripts/third-party/hljs.js +0 -1
  50. package/static/scripts/third-party/popper.js +0 -5
  51. package/static/scripts/third-party/tippy.js +0 -1
  52. package/static/scripts/third-party/tocbot.js +0 -672
  53. package/static/scripts/third-party/tocbot.min.js +0 -1
  54. package/static/styles/clean-jsdoc-theme-base.css +0 -1159
  55. package/static/styles/clean-jsdoc-theme-dark.css +0 -412
  56. package/static/styles/clean-jsdoc-theme-light.css +0 -482
  57. package/static/styles/clean-jsdoc-theme-scrollbar.css +0 -30
  58. package/static/styles/clean-jsdoc-theme-without-scrollbar.min.css +0 -1
  59. package/static/styles/clean-jsdoc-theme.min.css +0 -1
  60. package/tmpl/augments.tmpl +0 -10
  61. package/tmpl/container.tmpl +0 -208
  62. package/tmpl/details.tmpl +0 -207
  63. package/tmpl/example.tmpl +0 -3
  64. package/tmpl/examples.tmpl +0 -48
  65. package/tmpl/exceptions.tmpl +0 -32
  66. package/tmpl/icons.tmpl +0 -73
  67. package/tmpl/include-target-script-and-styles.tmpl +0 -43
  68. package/tmpl/layout.tmpl +0 -167
  69. package/tmpl/mainpage.tmpl +0 -10
  70. package/tmpl/members.tmpl +0 -42
  71. package/tmpl/method.tmpl +0 -175
  72. package/tmpl/mobile-sidebar.tmpl +0 -21
  73. package/tmpl/navbar-actions.tmpl +0 -19
  74. package/tmpl/navbar-menu.tmpl +0 -25
  75. package/tmpl/navbar.tmpl +0 -14
  76. package/tmpl/params.tmpl +0 -131
  77. package/tmpl/properties.tmpl +0 -109
  78. package/tmpl/returns.tmpl +0 -19
  79. package/tmpl/search.tmpl +0 -17
  80. package/tmpl/sidebar-items.tmpl +0 -24
  81. package/tmpl/sidebar-title.tmpl +0 -8
  82. package/tmpl/sidebar.tmpl +0 -9
  83. package/tmpl/source.tmpl +0 -13
  84. package/tmpl/toc.tmpl +0 -4
  85. package/tmpl/tutorial.tmpl +0 -32
  86. package/tmpl/type.tmpl +0 -13
@@ -0,0 +1,779 @@
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined") return require.apply(this, arguments);
5
+ throw Error('Dynamic require of "' + x + '" is not supported');
6
+ });
7
+
8
+ // src/publish.ts
9
+ import { readFile, readdir } from "fs/promises";
10
+ import { readFileSync } from "fs";
11
+ import { createHash } from "crypto";
12
+ import { basename, dirname as dirname2, extname, join as joinPath, resolve as resolvePath } from "path";
13
+ import { pathToFileURL, fileURLToPath } from "url";
14
+
15
+ // src/write-output-files.ts
16
+ import { mkdir, writeFile } from "fs/promises";
17
+ import { dirname, join } from "path";
18
+ async function writeOutputFiles(destination, files) {
19
+ for (const file of files) {
20
+ const target = join(destination, file.path);
21
+ await mkdir(dirname(target), { recursive: true });
22
+ const contents = typeof file.contents === "string" ? file.contents : Buffer.from(file.contents);
23
+ await writeFile(target, contents);
24
+ }
25
+ }
26
+
27
+ // src/publish.ts
28
+ var JSDOC_TUTORIAL_TYPE_MARKDOWN = 2;
29
+ function anchorPath() {
30
+ if (typeof __filename === "string") return __filename;
31
+ try {
32
+ const getEsmUrl = new Function(
33
+ "try { return import.meta && import.meta.url; } catch { return undefined; }"
34
+ );
35
+ const url = getEsmUrl();
36
+ if (typeof url === "string" && url.startsWith("file://")) {
37
+ return fileURLToPath(url);
38
+ }
39
+ } catch {
40
+ }
41
+ throw new Error(
42
+ "clean-jsdoc-theme: could not determine the running module path (neither __filename nor import.meta.url resolved)."
43
+ );
44
+ }
45
+ function resolvePackageDir(name) {
46
+ const start = anchorPath();
47
+ let dir = dirname2(start);
48
+ let prev = "";
49
+ while (dir !== prev) {
50
+ const candidate = resolvePath(dir, "node_modules", name);
51
+ try {
52
+ readFileSync(resolvePath(candidate, "package.json"), "utf8");
53
+ return candidate;
54
+ } catch {
55
+ }
56
+ prev = dir;
57
+ dir = dirname2(dir);
58
+ }
59
+ throw new Error(`clean-jsdoc-theme: could not locate '${name}' on disk starting from ${start}.`);
60
+ }
61
+ function resolveExportTarget(node, pkgRoot) {
62
+ if (typeof node === "string") return resolvePath(pkgRoot, node);
63
+ if (!node || typeof node !== "object") return void 0;
64
+ const o = node;
65
+ const imp = resolveExportTarget(o.import, pkgRoot);
66
+ if (imp) return imp;
67
+ if (typeof o.default === "string") return resolvePath(pkgRoot, o.default);
68
+ return void 0;
69
+ }
70
+ function resolveEsmEntry(name) {
71
+ const pkgRoot = resolvePackageDir(name);
72
+ const pkg = JSON.parse(
73
+ readFileSync(resolvePath(pkgRoot, "package.json"), "utf8")
74
+ );
75
+ const exp = pkg.exports;
76
+ if (typeof exp === "string") return resolvePath(pkgRoot, exp);
77
+ if (exp && typeof exp === "object") {
78
+ const dot = exp["."];
79
+ const target = resolveExportTarget(dot !== void 0 ? dot : exp, pkgRoot);
80
+ if (target) return target;
81
+ }
82
+ if (typeof pkg.module === "string") return resolvePath(pkgRoot, pkg.module);
83
+ if (typeof pkg.main === "string") return resolvePath(pkgRoot, pkg.main);
84
+ throw new Error(
85
+ `clean-jsdoc-theme: could not determine ESM entry file for '${name}' (no exports/module/main).`
86
+ );
87
+ }
88
+ async function loadDep(name, requiredExports) {
89
+ const entry = resolveEsmEntry(name);
90
+ const id = pathToFileURL(entry).href;
91
+ const mod = await import(id);
92
+ for (const key of requiredExports) {
93
+ if (typeof mod[key] !== "function") {
94
+ throw new Error(
95
+ `clean-jsdoc-theme: '${name}' did not export a '${key}' function (resolved from ${entry}; got keys: ${Object.keys(mod).join(", ") || "(none)"}).`
96
+ );
97
+ }
98
+ }
99
+ return mod;
100
+ }
101
+ var loadSetu = () => loadDep("@clean-jsdoc-theme/setu", ["generateSite"]);
102
+ var loadDwar = () => loadDep("@clean-jsdoc-theme/dwar", ["render", "runPagefindAgainstDir"]);
103
+ var loadUtils = () => loadDep("@clean-jsdoc-theme/utils", [
104
+ "validateThemeOpts",
105
+ "createGoogleFontResolver",
106
+ "formatDiagnostics",
107
+ "formatBuildReport",
108
+ "normalizeBasePath",
109
+ "withBase"
110
+ ]);
111
+ var loadOra = async () => {
112
+ try {
113
+ const mod = await loadDep("ora", ["default"]);
114
+ return mod.default;
115
+ } catch {
116
+ return null;
117
+ }
118
+ };
119
+ var JSDOC_OWN_OPTS = /* @__PURE__ */ new Set([
120
+ "destination",
121
+ "template",
122
+ "encoding",
123
+ "recurse",
124
+ "readme",
125
+ "package",
126
+ "tutorials",
127
+ "query",
128
+ "private",
129
+ "access",
130
+ "explain",
131
+ "debug",
132
+ "verbose",
133
+ "pedantic",
134
+ "match",
135
+ "nocolor",
136
+ "templates"
137
+ ]);
138
+ var defaultTheme = {
139
+ tokens: {
140
+ // Light palette (oklch). bg #fdfdf7 · fg #3e3e3e · border #eeeeee;
141
+ // muted/accent derived to harmonize.
142
+ colors: {
143
+ bg: "oklch(0.9924 0.0079 106.54)",
144
+ bgMuted: "oklch(0.9595 0.0079 106.55)",
145
+ fg: "oklch(0.3639 0 0)",
146
+ fgMuted: "oklch(0.5278 0 0)",
147
+ accent: "oklch(0 0 0)",
148
+ accentFg: "oklch(1 0 0)",
149
+ border: "oklch(0.9561 0 0)"
150
+ },
151
+ // Dark palette (oklch). bg #09090b · fg #9e9e9e · border #141416;
152
+ // muted/accent derived to harmonize.
153
+ darkColors: {
154
+ bg: "oklch(0.1408 0.0044 285.82)",
155
+ bgMuted: "oklch(0.2103 0.0059 285.89)",
156
+ fg: "oklch(0.6993 0 0)",
157
+ fgMuted: "oklch(0.5382 0 0)",
158
+ accent: "oklch(1 0 0)",
159
+ accentFg: "oklch(0 0 0)",
160
+ border: "oklch(0.2321 0.004 286.02)"
161
+ },
162
+ fonts: {
163
+ heading: "Source Serif 4",
164
+ body: "Roboto",
165
+ mono: "ui-monospace, SFMono-Regular, Menlo, monospace"
166
+ },
167
+ shiki: { light: "github-light", dark: "github-dark" }
168
+ },
169
+ basePath: "/"
170
+ };
171
+ function resolveTheme(opts, siteName, fonts, basePath) {
172
+ const aiPrompt = typeof opts.aiPrompt === "string" && opts.aiPrompt.trim() ? opts.aiPrompt.trim() : void 0;
173
+ const copyPage = normalizeCopyPage(opts.copyPage);
174
+ const pageNav = normalizePageNav(opts.pageNav);
175
+ const colors = normalizeColors(opts.colors);
176
+ const darkColors = normalizeColors(opts.darkColors);
177
+ return {
178
+ ...defaultTheme,
179
+ basePath,
180
+ ...aiPrompt ? { aiPrompt } : {},
181
+ ...copyPage ? { copyPage } : {},
182
+ ...pageNav ? { pageNav } : {},
183
+ tokens: {
184
+ ...defaultTheme.tokens,
185
+ colors: { ...defaultTheme.tokens.colors, ...colors ?? {} },
186
+ darkColors: { ...defaultTheme.tokens.darkColors, ...darkColors ?? {} },
187
+ fonts: {
188
+ heading: fonts.heading ?? defaultTheme.tokens.fonts.heading,
189
+ body: fonts.body ?? defaultTheme.tokens.fonts.body,
190
+ mono: fonts.mono ?? defaultTheme.tokens.fonts.mono
191
+ },
192
+ ...siteName ? { siteName } : {}
193
+ }
194
+ };
195
+ }
196
+ function nonEmptyString(value) {
197
+ return typeof value === "string" && value.trim().length > 0 ? value : void 0;
198
+ }
199
+ function contentHash(bytes) {
200
+ return createHash("sha256").update(bytes).digest("hex").slice(0, 8);
201
+ }
202
+ async function copyCustomFiles(raw, ext, hash, label, hrefForServed) {
203
+ const paths = (Array.isArray(raw) ? raw : [raw]).filter(
204
+ (p) => typeof p === "string" && p.trim().length > 0
205
+ );
206
+ const links = [];
207
+ const files = [];
208
+ const seen = /* @__PURE__ */ new Set();
209
+ for (const p of paths) {
210
+ const trimmed = p.trim();
211
+ let bytes;
212
+ try {
213
+ bytes = await readFile(resolvePath(trimmed));
214
+ } catch {
215
+ console.warn(`clean-jsdoc-theme: could not read ${label} ('${trimmed}'); skipping it.`);
216
+ continue;
217
+ }
218
+ const base = basename(trimmed, extname(trimmed)) || "custom";
219
+ const name = hash ? `${base}.${contentHash(bytes)}${ext}` : `${base}${ext}`;
220
+ const servedPath = `_assets/${name}`;
221
+ if (seen.has(servedPath)) continue;
222
+ seen.add(servedPath);
223
+ files.push({ path: servedPath, contents: bytes });
224
+ links.push(hrefForServed(servedPath));
225
+ }
226
+ return { links, files };
227
+ }
228
+ async function resolveCustomAssets(opts, hrefForServed) {
229
+ const hash = opts.hashCustomAssets !== false;
230
+ const [cssAssets, jsAssets] = await Promise.all([
231
+ copyCustomFiles(opts.customCssFile, ".css", hash, "customCssFile", hrefForServed),
232
+ copyCustomFiles(opts.customJsFile, ".js", hash, "customJsFile", hrefForServed)
233
+ ]);
234
+ const customCss = nonEmptyString(opts.customCss)?.trim();
235
+ const customJs = nonEmptyString(opts.customJs)?.trim();
236
+ return {
237
+ theme: {
238
+ ...customCss ? { customCss } : {},
239
+ ...cssAssets.links.length > 0 ? { customCssLinks: cssAssets.links } : {},
240
+ ...customJs ? { customJs } : {},
241
+ ...jsAssets.links.length > 0 ? { customJsLinks: jsAssets.links } : {}
242
+ },
243
+ files: [...cssAssets.files, ...jsAssets.files]
244
+ };
245
+ }
246
+ function isServableUrl(value) {
247
+ return /^(https?:)?\/\//i.test(value) || /^data:/i.test(value);
248
+ }
249
+ async function prepareSiteName(raw, hrefForServed) {
250
+ if (typeof raw === "string") {
251
+ const trimmed = raw.trim();
252
+ return { siteName: trimmed.length > 0 ? trimmed : void 0, files: [] };
253
+ }
254
+ if (!raw || typeof raw !== "object") return { siteName: void 0, files: [] };
255
+ const files = [];
256
+ const out = {};
257
+ if (typeof raw.alt === "string" && raw.alt.trim().length > 0) out.alt = raw.alt.trim();
258
+ for (const key of ["default", "dark", "light"]) {
259
+ const value = raw[key];
260
+ if (typeof value !== "string" || value.trim().length === 0) continue;
261
+ const v = value.trim();
262
+ if (isServableUrl(v)) {
263
+ out[key] = v;
264
+ continue;
265
+ }
266
+ try {
267
+ const abs = resolvePath(v);
268
+ const buf = await readFile(abs);
269
+ const served = `_assets/logo-${key}.${contentHash(buf)}${extname(abs)}`;
270
+ files.push({ path: served, contents: buf });
271
+ out[key] = hrefForServed(served);
272
+ } catch {
273
+ console.warn(
274
+ `clean-jsdoc-theme: could not read logo image for siteName.${key} ('${v}'); using it verbatim.`
275
+ );
276
+ out[key] = v;
277
+ }
278
+ }
279
+ const hasContent = out.default || out.dark || out.light || out.alt;
280
+ return { siteName: hasContent ? out : void 0, files };
281
+ }
282
+ async function resolvePkg(data, opts) {
283
+ if (typeof opts.package === "string" && opts.package.length > 0) {
284
+ try {
285
+ const json = await readFile(opts.package, "utf8");
286
+ const parsed = JSON.parse(json);
287
+ return pickPkgFields(parsed);
288
+ } catch {
289
+ }
290
+ }
291
+ if (typeof data === "function") {
292
+ try {
293
+ const pkgDoclets = data({ kind: "package" }).get();
294
+ if (Array.isArray(pkgDoclets) && pkgDoclets.length > 0) {
295
+ return pickPkgFields(pkgDoclets[0]);
296
+ }
297
+ } catch {
298
+ }
299
+ }
300
+ return void 0;
301
+ }
302
+ function pickPkgFields(raw) {
303
+ const pkg = {};
304
+ if (typeof raw.name === "string") pkg.name = raw.name;
305
+ if (typeof raw.version === "string") pkg.version = raw.version;
306
+ if (typeof raw.description === "string") pkg.description = raw.description;
307
+ if (typeof raw.homepage === "string") pkg.homepage = raw.homepage;
308
+ if (typeof raw.repository === "string") {
309
+ pkg.repository = raw.repository;
310
+ } else if (raw.repository && typeof raw.repository === "object" && typeof raw.repository.url === "string") {
311
+ pkg.repository = raw.repository.url;
312
+ }
313
+ return pkg;
314
+ }
315
+ function normalizeTutorials(root) {
316
+ const walk = (node) => {
317
+ const name = typeof node.name === "string" ? node.name : "";
318
+ if (!name) return null;
319
+ const title = typeof node.title === "string" && node.title.length > 0 ? node.title : name;
320
+ const content = typeof node.content === "string" ? node.content : "";
321
+ const type = node.type === JSDOC_TUTORIAL_TYPE_MARKDOWN ? "markdown" : "html";
322
+ const children2 = Array.isArray(node.children) ? node.children.map(walk).filter((t) => t !== null) : [];
323
+ return { name, title, content, type, children: children2 };
324
+ };
325
+ const children = root?.children;
326
+ if (!Array.isArray(children)) return [];
327
+ return children.map(walk).filter((t) => t !== null);
328
+ }
329
+ function outputSourceFilesEnabled(opts) {
330
+ try {
331
+ const env = __require("jsdoc/env");
332
+ if (env?.conf?.templates?.default?.outputSourceFiles === false) return false;
333
+ } catch {
334
+ }
335
+ if (opts?.templates?.default?.outputSourceFiles === false) return false;
336
+ return true;
337
+ }
338
+ function sourceLinkToCommentEnabled(opts) {
339
+ try {
340
+ const env = __require("jsdoc/env");
341
+ if (env?.conf?.templates?.default?.sourceLinkToComment === true) return true;
342
+ } catch {
343
+ }
344
+ if (opts?.templates?.default?.sourceLinkToComment === true) return true;
345
+ return false;
346
+ }
347
+ function hasMarkdownPlugin(plugins) {
348
+ if (!Array.isArray(plugins)) return false;
349
+ return plugins.some(
350
+ (p) => typeof p === "string" && /(^|[\\/])markdown(\.js)?$/i.test(p.trim())
351
+ );
352
+ }
353
+ function assertMarkdownPlugin() {
354
+ let conf;
355
+ try {
356
+ conf = __require("jsdoc/env").conf;
357
+ } catch {
358
+ return;
359
+ }
360
+ if (!conf) return;
361
+ if (!hasMarkdownPlugin(conf.plugins)) {
362
+ throw new Error(
363
+ `clean-jsdoc-theme requires JSDoc's "plugins/markdown" plugin, which renders Markdown in doclet descriptions to HTML. Add it to your jsdoc.json:
364
+
365
+ "plugins": ["plugins/markdown"]
366
+ `
367
+ );
368
+ }
369
+ }
370
+ function normalizeSectionOrder(raw) {
371
+ if (!Array.isArray(raw)) return void 0;
372
+ const out = raw.filter((s) => typeof s === "string").map((s) => s.trim()).filter((s) => s.length > 0);
373
+ return out.length > 0 ? out : void 0;
374
+ }
375
+ function normalizeMenu(raw) {
376
+ if (!Array.isArray(raw)) return void 0;
377
+ const out = [];
378
+ for (const entry of raw) {
379
+ if (!entry || typeof entry !== "object") continue;
380
+ const o = entry;
381
+ const item = {};
382
+ if (typeof o.id === "string" && o.id.trim()) item.id = o.id.trim();
383
+ if (typeof o.title === "string" && o.title.trim()) item.title = o.title.trim();
384
+ const link = typeof o.link === "string" && o.link.trim() ? o.link.trim() : typeof o.href === "string" && o.href.trim() ? o.href.trim() : void 0;
385
+ if (link) item.link = link;
386
+ if (typeof o.icon === "string" && o.icon.trim()) item.icon = o.icon.trim();
387
+ if (item.id || item.link) out.push(item);
388
+ }
389
+ return out.length > 0 ? out : void 0;
390
+ }
391
+ var COPY_PAGE_ACTIONS = [
392
+ "copy",
393
+ "view",
394
+ "claude",
395
+ "chatgpt",
396
+ "perplexity"
397
+ ];
398
+ function normalizeCopyPage(raw) {
399
+ if (raw === false) return { enabled: false };
400
+ if (raw === true || raw == null) return void 0;
401
+ if (typeof raw !== "object") return void 0;
402
+ const o = raw;
403
+ const config = {};
404
+ if (typeof o.enabled === "boolean") config.enabled = o.enabled;
405
+ if (Array.isArray(o.actions)) {
406
+ const seen = /* @__PURE__ */ new Set();
407
+ for (const a of o.actions) {
408
+ if (typeof a === "string" && COPY_PAGE_ACTIONS.includes(a)) {
409
+ seen.add(a);
410
+ }
411
+ }
412
+ config.actions = COPY_PAGE_ACTIONS.filter((a) => seen.has(a));
413
+ }
414
+ return Object.keys(config).length > 0 ? config : void 0;
415
+ }
416
+ function normalizePageNav(raw) {
417
+ if (raw === false) return { enabled: false };
418
+ if (raw === true || raw == null) return void 0;
419
+ if (typeof raw !== "object") return void 0;
420
+ const enabled = raw.enabled;
421
+ return typeof enabled === "boolean" ? { enabled } : void 0;
422
+ }
423
+ var COLOR_KEYS = ["bg", "bgMuted", "fg", "fgMuted", "accent", "accentFg", "border"];
424
+ function normalizeColors(raw) {
425
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return void 0;
426
+ const src = raw;
427
+ const out = {};
428
+ for (const key of COLOR_KEYS) {
429
+ const v = src[key];
430
+ if (typeof v === "string" && v.trim().length > 0) out[key] = v.trim();
431
+ }
432
+ return Object.keys(out).length > 0 ? out : void 0;
433
+ }
434
+ var SOURCE_EXTENSIONS = /* @__PURE__ */ new Set([".js", ".mjs", ".cjs", ".jsx", ".ts", ".mts", ".cts", ".tsx"]);
435
+ function computeRelPaths(absPaths) {
436
+ const out = /* @__PURE__ */ new Map();
437
+ if (absPaths.length === 0) return out;
438
+ const split = (p) => p.split(/[\\/]+/).filter((s) => s.length > 0);
439
+ const segLists = absPaths.map(split);
440
+ let common = segLists[0].slice(0, -1);
441
+ for (let i = 1; i < segLists.length && common.length > 0; i++) {
442
+ const segs = segLists[i];
443
+ let j = 0;
444
+ const max = Math.min(common.length, segs.length - 1);
445
+ while (j < max && common[j].toLowerCase() === segs[j].toLowerCase()) j++;
446
+ common = common.slice(0, j);
447
+ }
448
+ for (let i = 0; i < absPaths.length; i++) {
449
+ const segs = segLists[i];
450
+ const rel = common.length > 0 && segs.length > common.length ? segs.slice(common.length).join("/") : segs[segs.length - 1] ?? absPaths[i];
451
+ out.set(absPaths[i], rel);
452
+ }
453
+ return out;
454
+ }
455
+ async function collectSourceFiles(data) {
456
+ let doclets = [];
457
+ if (typeof data === "function") {
458
+ try {
459
+ doclets = data({}).get();
460
+ } catch {
461
+ try {
462
+ doclets = data().get();
463
+ } catch {
464
+ doclets = [];
465
+ }
466
+ }
467
+ }
468
+ if (!Array.isArray(doclets) || doclets.length === 0) return [];
469
+ const absSet = /* @__PURE__ */ new Set();
470
+ for (const d of doclets) {
471
+ const meta = d?.meta;
472
+ if (!meta || typeof meta.path !== "string" || typeof meta.filename !== "string") continue;
473
+ const filename = meta.filename;
474
+ const ext = extname(filename).toLowerCase();
475
+ if (ext.length > 0 && !SOURCE_EXTENSIONS.has(ext)) continue;
476
+ absSet.add(resolvePath(meta.path, filename));
477
+ }
478
+ if (absSet.size === 0) return [];
479
+ const absPaths = [...absSet];
480
+ const relPaths = computeRelPaths(absPaths);
481
+ const inputs = [];
482
+ for (const abs of absPaths) {
483
+ try {
484
+ const content = await readFile(abs, "utf8");
485
+ inputs.push({ absPath: abs, relPath: relPaths.get(abs) ?? abs, content });
486
+ } catch (err) {
487
+ console.warn(
488
+ `clean-jsdoc-theme: could not read source file '${abs}' \u2014 ${err.message}; skipping.`
489
+ );
490
+ }
491
+ }
492
+ inputs.sort((a, b) => a.relPath.localeCompare(b.relPath));
493
+ return inputs;
494
+ }
495
+ var DOC_EXTENSIONS = /* @__PURE__ */ new Map([
496
+ [".md", "markdown"],
497
+ [".markdown", "markdown"],
498
+ [".html", "html"],
499
+ [".htm", "html"]
500
+ ]);
501
+ var DOC_DIR_SKIP = /* @__PURE__ */ new Set(["node_modules", ".git", ".svn", ".hg"]);
502
+ async function collectDocs(dir) {
503
+ if (typeof dir !== "string" || dir.trim().length === 0) return [];
504
+ const root = resolvePath(dir);
505
+ const docs = [];
506
+ const walk = async (absDir, relPrefix) => {
507
+ let entries;
508
+ try {
509
+ entries = await readdir(absDir, { withFileTypes: true });
510
+ } catch {
511
+ return;
512
+ }
513
+ for (const entry of entries) {
514
+ const name = entry.name;
515
+ if (name.startsWith(".")) continue;
516
+ if (entry.isDirectory()) {
517
+ if (DOC_DIR_SKIP.has(name)) continue;
518
+ await walk(joinPath(absDir, name), relPrefix ? `${relPrefix}/${name}` : name);
519
+ continue;
520
+ }
521
+ if (!entry.isFile()) continue;
522
+ const ext = extname(name).toLowerCase();
523
+ const type = DOC_EXTENSIONS.get(ext);
524
+ if (!type) continue;
525
+ const abs = joinPath(absDir, name);
526
+ const stem = name.slice(0, name.length - ext.length);
527
+ const relPath = relPrefix ? `${relPrefix}/${stem}` : stem;
528
+ try {
529
+ const content = await readFile(abs, "utf8");
530
+ docs.push({ path: relPath, content, type });
531
+ } catch (err) {
532
+ console.warn(
533
+ `clean-jsdoc-theme: could not read doc file '${abs}' \u2014 ${err.message}; skipping.`
534
+ );
535
+ }
536
+ }
537
+ };
538
+ await walk(root, "");
539
+ docs.sort((a, b) => a.path.localeCompare(b.path));
540
+ return docs;
541
+ }
542
+ var DOC_IMAGE_RE = /(!\[[^\]]*\]\()([^)\s]+)((?:\s+"[^"]*")?\))/g;
543
+ async function resolveDocImages(docs, docsDir) {
544
+ if (docs.length === 0) return { docs, files: [], inlineSvgs: {} };
545
+ const root = resolvePath(docsDir);
546
+ const files = [];
547
+ const seenServed = /* @__PURE__ */ new Set();
548
+ const inlineSvgs = {};
549
+ const cache = /* @__PURE__ */ new Map();
550
+ const resolveOne = async (rawSrc, docDir) => {
551
+ const src = rawSrc.trim();
552
+ if (!src || isServableUrl(src) || src.startsWith("#") || src.startsWith("data:")) return null;
553
+ const abs = src.startsWith("/") ? resolvePath(src.slice(1)) : resolvePath(docDir, src);
554
+ if (cache.has(abs)) return cache.get(abs) ?? null;
555
+ let bytes;
556
+ try {
557
+ bytes = await readFile(abs);
558
+ } catch {
559
+ console.warn(
560
+ `clean-jsdoc-theme: could not read doc image '${src}' (resolved '${abs}'); leaving it as-is.`
561
+ );
562
+ cache.set(abs, null);
563
+ return null;
564
+ }
565
+ const ext = extname(abs);
566
+ const served = `_assets/${basename(abs, ext) || "asset"}.${contentHash(bytes)}${ext}`;
567
+ if (!seenServed.has(served)) {
568
+ seenServed.add(served);
569
+ files.push({ path: served, contents: bytes });
570
+ }
571
+ const href = "/" + served;
572
+ if (ext.toLowerCase() === ".svg") {
573
+ inlineSvgs[href] = bytes.toString("utf8").replace(/<svg\b/, '<svg style="max-width:100%;height:auto;display:block"');
574
+ }
575
+ cache.set(abs, href);
576
+ return href;
577
+ };
578
+ const out = [];
579
+ for (const doc of docs) {
580
+ const docDir = dirname2(resolvePath(root, doc.path));
581
+ const map = /* @__PURE__ */ new Map();
582
+ for (const m of doc.content.matchAll(DOC_IMAGE_RE)) {
583
+ const src = m[2];
584
+ if (map.has(src)) continue;
585
+ const href = await resolveOne(src, docDir);
586
+ if (href) map.set(src, href);
587
+ }
588
+ if (map.size === 0) {
589
+ out.push(doc);
590
+ continue;
591
+ }
592
+ const content = doc.content.replace(
593
+ DOC_IMAGE_RE,
594
+ (full, pre, src, post) => map.has(src) ? `${pre}${map.get(src)}${post}` : full
595
+ );
596
+ out.push({ ...doc, content });
597
+ }
598
+ return { docs: out, files, inlineSvgs };
599
+ }
600
+ function normalizeDocGroups(raw) {
601
+ return normalizeSectionOrder(raw);
602
+ }
603
+ function formatElapsed(ms) {
604
+ return ms < 1e3 ? `${ms}ms` : `${(ms / 1e3).toFixed(1)}s`;
605
+ }
606
+ function createBuildProgress(ora) {
607
+ async function stage(label, fn) {
608
+ if (!ora) return await fn();
609
+ const spinner = ora(label).start();
610
+ const begin = Date.now();
611
+ try {
612
+ const result = await fn();
613
+ spinner.succeed(`${label} (${formatElapsed(Date.now() - begin)})`);
614
+ return result;
615
+ } catch (err) {
616
+ spinner.fail(label);
617
+ throw err;
618
+ }
619
+ }
620
+ return { stage };
621
+ }
622
+ async function publish(data, opts, tutorials) {
623
+ const destination = opts.destination;
624
+ if (!destination || typeof destination !== "string") {
625
+ throw new Error(
626
+ 'clean-jsdoc-theme publish: opts.destination is required (set "opts.destination" in your jsdoc.json).'
627
+ );
628
+ }
629
+ assertMarkdownPlugin();
630
+ const color = Boolean(process.stdout.isTTY) && opts.nocolor !== true;
631
+ const docsDir = typeof opts.docs === "string" && opts.docs.trim().length > 0 ? opts.docs.trim() : void 0;
632
+ const pkgPromise = resolvePkg(data, opts);
633
+ const sourcesPromise = outputSourceFilesEnabled(opts) ? collectSourceFiles(data) : Promise.resolve([]);
634
+ const docsPromise = docsDir ? collectDocs(docsDir) : Promise.resolve([]);
635
+ const ora = opts.progress === false ? null : await loadOra();
636
+ const progress = createBuildProgress(ora);
637
+ const [
638
+ { generateSite },
639
+ { render, runPagefindAgainstDir },
640
+ {
641
+ validateThemeOpts,
642
+ createGoogleFontResolver,
643
+ formatDiagnostics,
644
+ formatBuildReport,
645
+ normalizeBasePath,
646
+ withBase
647
+ }
648
+ ] = await progress.stage(
649
+ "Loading renderer",
650
+ () => Promise.all([loadSetu(), loadDwar(), loadUtils()])
651
+ );
652
+ const basePath = normalizeBasePath(opts.basePath);
653
+ const hrefForServed = (servedPath) => withBase(basePath, "/" + servedPath);
654
+ const fontResolver = createGoogleFontResolver();
655
+ const { value, diagnostics } = await progress.stage(
656
+ "Validating options",
657
+ () => validateThemeOpts({
658
+ opts,
659
+ fontResolver,
660
+ unknownKeyPolicy: "suggest-typos",
661
+ knownNonThemeKeys: JSDOC_OWN_OPTS
662
+ })
663
+ );
664
+ const strict = opts.strict === true || opts.templates?.default?.strict === true;
665
+ if (diagnostics.list.length > 0) {
666
+ const formatted = formatDiagnostics(diagnostics, { color });
667
+ if (strict && diagnostics.hasErrors()) {
668
+ console.error(formatted);
669
+ throw new Error(
670
+ "clean-jsdoc-theme: opts validation failed in strict mode (see the diagnostics above). Fix the errors or unset `strict`."
671
+ );
672
+ }
673
+ console.log(formatted);
674
+ }
675
+ const pkg = await pkgPromise;
676
+ const readme = typeof opts.readme === "string" && opts.readme.length > 0 ? opts.readme : void 0;
677
+ const tutorialTree = normalizeTutorials(tutorials);
678
+ const sourceLinkToComment = sourceLinkToCommentEnabled(opts);
679
+ const { sources, docs, docImageFiles, inlineSvgs } = await progress.stage(
680
+ "Reading sources & docs",
681
+ async () => {
682
+ const [srcs, rawDocs] = await Promise.all([sourcesPromise, docsPromise]);
683
+ const resolved = docsDir ? await resolveDocImages(rawDocs, docsDir) : { docs: rawDocs, files: [], inlineSvgs: {} };
684
+ return {
685
+ sources: srcs,
686
+ docs: resolved.docs,
687
+ docImageFiles: resolved.files,
688
+ inlineSvgs: resolved.inlineSvgs
689
+ };
690
+ }
691
+ );
692
+ const docGroups = normalizeDocGroups(opts.docGroups);
693
+ const defaultDocGroup = typeof opts.defaultDocGroup === "string" && opts.defaultDocGroup.trim().length > 0 ? opts.defaultDocGroup.trim() : void 0;
694
+ const sectionOrder = normalizeSectionOrder(opts.sectionOrder);
695
+ const menu = normalizeMenu(opts.menu);
696
+ const clubSidebarItems = opts.clubSidebarItems === true;
697
+ const manifest = await progress.stage("Generating pages", () => generateSite(data, {
698
+ ...pkg ? { pkg } : {},
699
+ ...readme ? { readme } : {},
700
+ ...tutorialTree.length > 0 ? { tutorials: tutorialTree } : {},
701
+ ...sources.length > 0 ? { sources } : {},
702
+ ...sources.length > 0 && sourceLinkToComment ? { sourceLinkToComment } : {},
703
+ ...docs.length > 0 ? { docs } : {},
704
+ ...docGroups ? { docGroups } : {},
705
+ ...defaultDocGroup ? { defaultDocGroup } : {},
706
+ ...sectionOrder ? { sectionOrder } : {},
707
+ ...menu ? { menu } : {},
708
+ ...clubSidebarItems ? { clubSidebarItems } : {}
709
+ }));
710
+ const { siteName, files: logoFiles } = await prepareSiteName(value.siteName, hrefForServed);
711
+ const notGoogle = new Set(
712
+ diagnostics.list.filter((d) => d.code === "fonts/not-google" && d.path).map((d) => d.path)
713
+ );
714
+ const fonts = { ...value.fonts };
715
+ if (notGoogle.has("fonts.heading")) delete fonts.heading;
716
+ if (notGoogle.has("fonts.body")) delete fonts.body;
717
+ const customAssets = await resolveCustomAssets(opts, hrefForServed);
718
+ const absoluteDestination = resolvePath(destination);
719
+ const islandCacheDir = resolvePath(process.cwd(), "node_modules", ".cache", "clean-jsdoc-theme");
720
+ const result = await progress.stage(
721
+ "Rendering site",
722
+ () => render(manifest, {
723
+ theme: { ...resolveTheme(opts, siteName, fonts, basePath), ...customAssets.theme },
724
+ destination: absoluteDestination,
725
+ islandCacheDir,
726
+ inlineSvgs
727
+ })
728
+ );
729
+ const outputFiles = [...result.files, ...logoFiles, ...customAssets.files, ...docImageFiles];
730
+ await progress.stage(
731
+ "Writing files",
732
+ () => writeOutputFiles(absoluteDestination, outputFiles)
733
+ );
734
+ const zlib = await import("zlib");
735
+ const gzipSizer = (b) => zlib.gzipSync(b).length;
736
+ console.log(
737
+ formatBuildReport({
738
+ files: outputFiles,
739
+ stats: result.stats,
740
+ destination,
741
+ gzipSizer,
742
+ color
743
+ })
744
+ );
745
+ if (result.errors && result.errors.length > 0) {
746
+ console.warn(
747
+ `clean-jsdoc-theme: ${result.errors.length} page(s) failed to render and were skipped:`
748
+ );
749
+ for (const e of result.errors) {
750
+ console.warn(` - ${e.slug}: ${e.message}`);
751
+ }
752
+ }
753
+ try {
754
+ await progress.stage(
755
+ "Indexing search (pagefind)",
756
+ () => runPagefindAgainstDir(absoluteDestination)
757
+ );
758
+ } catch (err) {
759
+ console.warn(
760
+ `clean-jsdoc-theme: pagefind step skipped (optional) \u2014 ${err.message}`
761
+ );
762
+ }
763
+ }
764
+ export {
765
+ collectDocs,
766
+ computeRelPaths,
767
+ hasMarkdownPlugin,
768
+ normalizeColors,
769
+ normalizeCopyPage,
770
+ normalizeDocGroups,
771
+ normalizeMenu,
772
+ normalizePageNav,
773
+ normalizeSectionOrder,
774
+ outputSourceFilesEnabled,
775
+ publish,
776
+ resolveDocImages,
777
+ sourceLinkToCommentEnabled
778
+ };
779
+ //# sourceMappingURL=publish.mjs.map