clean-jsdoc-theme 5.0.0 → 5.0.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.
@@ -1,5 +1,5 @@
1
- import { OutputFile, ThemeColors, CopyPageConfig, MetaTag, PageNavConfig, SiteLogo } from '@clean-jsdoc-theme/dwar';
2
- import { DocInput, MenuItem } from '@clean-jsdoc-theme/setu';
1
+ import { OutputFile, ThemeColors, CopyPageConfig, MetaTag, PageNavConfig, ThemeConfig, SiteLogo } from '@clean-jsdoc-theme/dwar';
2
+ import { DocInput, MenuItem, PlaygroundSiteConfig } from '@clean-jsdoc-theme/setu';
3
3
 
4
4
  interface JSDocOpts {
5
5
  destination?: string;
@@ -106,6 +106,16 @@ interface JSDocOpts {
106
106
  * Defaults to enabled.
107
107
  */
108
108
  pageNav?: unknown;
109
+ /**
110
+ * Code-playground config (`jsdoc.json` `"opts": { "playground": … }`). Either
111
+ * a boolean (`true` turns it on with defaults; absent/`false` = off) or an
112
+ * object `{ enableForAllExamples?, providers?, codepen?, jsfiddle?,
113
+ * codesandbox? }`. `providers` picks which of CodePen/JSFiddle/CodeSandbox an
114
+ * `@example` (or prose code block) can be opened in; the per-provider records
115
+ * hold their site-wide runtime options. When set, `@playground` tags are
116
+ * honored; when off, they're ignored (byte-identical output).
117
+ */
118
+ playground?: unknown;
109
119
  /**
110
120
  * Custom site footer (`jsdoc.json` `"opts": { "footer": … }`). Either an
111
121
  * inline HTML string (v4 parity) or `{ "file": "./footer.html" }` (read from
@@ -114,6 +124,14 @@ interface JSDocOpts {
114
124
  * Omit for the default footer.
115
125
  */
116
126
  footer?: unknown;
127
+ /**
128
+ * Favicon (`jsdoc.json` `"opts": { "favicon": "./icon.svg" }`). A path to an
129
+ * image file (`.svg`/`.png`/`.ico`/…), relative to the working dir. The bridge
130
+ * copies it to a content-hashed `_assets/` asset and emits a `<link rel="icon">`
131
+ * in every page's `<head>`. Needed for an SVG favicon (browsers only
132
+ * auto-discover a root `favicon.ico`). Omit for none.
133
+ */
134
+ favicon?: unknown;
117
135
  /**
118
136
  * Site-wide custom `<meta>` tags (`jsdoc.json` `"opts": { "meta": [...] }`). An
119
137
  * array of attribute maps — each object's key/value pairs become one `<meta>`
@@ -188,6 +206,18 @@ interface JSDocOpts {
188
206
  * the default footer renders. Exported for testing.
189
207
  */
190
208
  declare function resolveFooter(raw: unknown): Promise<string | undefined>;
209
+ /**
210
+ * Resolve `opts.favicon` (a file path) into a served `_assets/` href + the file
211
+ * to write — the bridge is the I/O layer, so dwar only sees the final URL and
212
+ * `render()` stays pure. The asset name is content-hashed (cache-busted) unless
213
+ * `hash` is off, and the source extension is preserved so dwar can derive the
214
+ * `<link>` `type`. A missing/unreadable file is warned about and dropped
215
+ * (resilient, like the logo/custom-asset paths). Exported for testing.
216
+ */
217
+ declare function resolveFavicon(raw: unknown, hash: boolean, hrefForServed: (servedPath: string) => string): Promise<{
218
+ href: string;
219
+ files: OutputFile[];
220
+ } | undefined>;
191
221
  /**
192
222
  * Validate `opts.meta` into a clean `MetaTag[]` (attribute maps), or `undefined`
193
223
  * when there's nothing usable. Accepts only an array of objects; within each,
@@ -254,6 +284,21 @@ declare function normalizeCopyPage(raw: unknown): CopyPageConfig | undefined;
254
284
  * object whose `enabled` is read when boolean.
255
285
  */
256
286
  declare function normalizePageNav(raw: unknown): PageNavConfig | undefined;
287
+ /**
288
+ * Validate `opts.playground` into its two consumer slices, or `undefined` when
289
+ * the feature is off (absent or `false`). `playground: true` / `{}` turns it on
290
+ * with defaults — every provider available, opt-in per `@playground`. The
291
+ * **`site`** slice feeds setu's `@playground` resolver (enablement + provider
292
+ * selection); the **`theme`** slice becomes `ThemeConfig.playground` (the
293
+ * site-wide per-provider runtime options dwar hands the browser island). Unknown
294
+ * providers/keys are dropped (lenient, like {@link normalizeCopyPage}). setu
295
+ * gates on the `site` slice's presence, so returning `undefined` keeps output
296
+ * byte-identical.
297
+ */
298
+ declare function normalizePlayground(raw: unknown): {
299
+ site: PlaygroundSiteConfig;
300
+ theme: NonNullable<ThemeConfig['playground']>;
301
+ } | undefined;
257
302
  /**
258
303
  * Validate a user `colors`/`darkColors` object from `jsdoc.json` into a clean
259
304
  * `Partial<ThemeColors>`: keeps only the known palette keys whose value is a
@@ -334,4 +379,4 @@ declare function overlayDocs(base: ResolvedDocs, locale: ResolvedDocs): Resolved
334
379
  declare function normalizeDocGroups(raw: unknown): string[] | undefined;
335
380
  declare function publish(data: unknown, opts: JSDocOpts, tutorials?: unknown): Promise<void>;
336
381
 
337
- export { type ResolvedDocs, collectDocs, computeRelPaths, hasMarkdownPlugin, normalizeColors, normalizeCopyPage, normalizeDocGroups, normalizeMenu, normalizeMeta, normalizePageNav, normalizeSectionOrder, outputSourceFilesEnabled, overlayDocs, publish, resolveDocImages, resolveFooter, sourceLinkToCommentEnabled };
382
+ export { type ResolvedDocs, collectDocs, computeRelPaths, hasMarkdownPlugin, normalizeColors, normalizeCopyPage, normalizeDocGroups, normalizeMenu, normalizeMeta, normalizePageNav, normalizePlayground, normalizeSectionOrder, outputSourceFilesEnabled, overlayDocs, publish, resolveDocImages, resolveFavicon, resolveFooter, sourceLinkToCommentEnabled };
package/dist/publish.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { OutputFile, ThemeColors, CopyPageConfig, MetaTag, PageNavConfig, SiteLogo } from '@clean-jsdoc-theme/dwar';
2
- import { DocInput, MenuItem } from '@clean-jsdoc-theme/setu';
1
+ import { OutputFile, ThemeColors, CopyPageConfig, MetaTag, PageNavConfig, ThemeConfig, SiteLogo } from '@clean-jsdoc-theme/dwar';
2
+ import { DocInput, MenuItem, PlaygroundSiteConfig } from '@clean-jsdoc-theme/setu';
3
3
 
4
4
  interface JSDocOpts {
5
5
  destination?: string;
@@ -106,6 +106,16 @@ interface JSDocOpts {
106
106
  * Defaults to enabled.
107
107
  */
108
108
  pageNav?: unknown;
109
+ /**
110
+ * Code-playground config (`jsdoc.json` `"opts": { "playground": … }`). Either
111
+ * a boolean (`true` turns it on with defaults; absent/`false` = off) or an
112
+ * object `{ enableForAllExamples?, providers?, codepen?, jsfiddle?,
113
+ * codesandbox? }`. `providers` picks which of CodePen/JSFiddle/CodeSandbox an
114
+ * `@example` (or prose code block) can be opened in; the per-provider records
115
+ * hold their site-wide runtime options. When set, `@playground` tags are
116
+ * honored; when off, they're ignored (byte-identical output).
117
+ */
118
+ playground?: unknown;
109
119
  /**
110
120
  * Custom site footer (`jsdoc.json` `"opts": { "footer": … }`). Either an
111
121
  * inline HTML string (v4 parity) or `{ "file": "./footer.html" }` (read from
@@ -114,6 +124,14 @@ interface JSDocOpts {
114
124
  * Omit for the default footer.
115
125
  */
116
126
  footer?: unknown;
127
+ /**
128
+ * Favicon (`jsdoc.json` `"opts": { "favicon": "./icon.svg" }`). A path to an
129
+ * image file (`.svg`/`.png`/`.ico`/…), relative to the working dir. The bridge
130
+ * copies it to a content-hashed `_assets/` asset and emits a `<link rel="icon">`
131
+ * in every page's `<head>`. Needed for an SVG favicon (browsers only
132
+ * auto-discover a root `favicon.ico`). Omit for none.
133
+ */
134
+ favicon?: unknown;
117
135
  /**
118
136
  * Site-wide custom `<meta>` tags (`jsdoc.json` `"opts": { "meta": [...] }`). An
119
137
  * array of attribute maps — each object's key/value pairs become one `<meta>`
@@ -188,6 +206,18 @@ interface JSDocOpts {
188
206
  * the default footer renders. Exported for testing.
189
207
  */
190
208
  declare function resolveFooter(raw: unknown): Promise<string | undefined>;
209
+ /**
210
+ * Resolve `opts.favicon` (a file path) into a served `_assets/` href + the file
211
+ * to write — the bridge is the I/O layer, so dwar only sees the final URL and
212
+ * `render()` stays pure. The asset name is content-hashed (cache-busted) unless
213
+ * `hash` is off, and the source extension is preserved so dwar can derive the
214
+ * `<link>` `type`. A missing/unreadable file is warned about and dropped
215
+ * (resilient, like the logo/custom-asset paths). Exported for testing.
216
+ */
217
+ declare function resolveFavicon(raw: unknown, hash: boolean, hrefForServed: (servedPath: string) => string): Promise<{
218
+ href: string;
219
+ files: OutputFile[];
220
+ } | undefined>;
191
221
  /**
192
222
  * Validate `opts.meta` into a clean `MetaTag[]` (attribute maps), or `undefined`
193
223
  * when there's nothing usable. Accepts only an array of objects; within each,
@@ -254,6 +284,21 @@ declare function normalizeCopyPage(raw: unknown): CopyPageConfig | undefined;
254
284
  * object whose `enabled` is read when boolean.
255
285
  */
256
286
  declare function normalizePageNav(raw: unknown): PageNavConfig | undefined;
287
+ /**
288
+ * Validate `opts.playground` into its two consumer slices, or `undefined` when
289
+ * the feature is off (absent or `false`). `playground: true` / `{}` turns it on
290
+ * with defaults — every provider available, opt-in per `@playground`. The
291
+ * **`site`** slice feeds setu's `@playground` resolver (enablement + provider
292
+ * selection); the **`theme`** slice becomes `ThemeConfig.playground` (the
293
+ * site-wide per-provider runtime options dwar hands the browser island). Unknown
294
+ * providers/keys are dropped (lenient, like {@link normalizeCopyPage}). setu
295
+ * gates on the `site` slice's presence, so returning `undefined` keeps output
296
+ * byte-identical.
297
+ */
298
+ declare function normalizePlayground(raw: unknown): {
299
+ site: PlaygroundSiteConfig;
300
+ theme: NonNullable<ThemeConfig['playground']>;
301
+ } | undefined;
257
302
  /**
258
303
  * Validate a user `colors`/`darkColors` object from `jsdoc.json` into a clean
259
304
  * `Partial<ThemeColors>`: keeps only the known palette keys whose value is a
@@ -334,4 +379,4 @@ declare function overlayDocs(base: ResolvedDocs, locale: ResolvedDocs): Resolved
334
379
  declare function normalizeDocGroups(raw: unknown): string[] | undefined;
335
380
  declare function publish(data: unknown, opts: JSDocOpts, tutorials?: unknown): Promise<void>;
336
381
 
337
- export { type ResolvedDocs, collectDocs, computeRelPaths, hasMarkdownPlugin, normalizeColors, normalizeCopyPage, normalizeDocGroups, normalizeMenu, normalizeMeta, normalizePageNav, normalizeSectionOrder, outputSourceFilesEnabled, overlayDocs, publish, resolveDocImages, resolveFooter, sourceLinkToCommentEnabled };
382
+ export { type ResolvedDocs, collectDocs, computeRelPaths, hasMarkdownPlugin, normalizeColors, normalizeCopyPage, normalizeDocGroups, normalizeMenu, normalizeMeta, normalizePageNav, normalizePlayground, normalizeSectionOrder, outputSourceFilesEnabled, overlayDocs, publish, resolveDocImages, resolveFavicon, resolveFooter, sourceLinkToCommentEnabled };
package/dist/publish.js CHANGED
@@ -39,11 +39,13 @@ __export(publish_exports, {
39
39
  normalizeMenu: () => normalizeMenu,
40
40
  normalizeMeta: () => normalizeMeta,
41
41
  normalizePageNav: () => normalizePageNav,
42
+ normalizePlayground: () => normalizePlayground,
42
43
  normalizeSectionOrder: () => normalizeSectionOrder,
43
44
  outputSourceFilesEnabled: () => outputSourceFilesEnabled,
44
45
  overlayDocs: () => overlayDocs,
45
46
  publish: () => publish,
46
47
  resolveDocImages: () => resolveDocImages,
48
+ resolveFavicon: () => resolveFavicon,
47
49
  resolveFooter: () => resolveFooter,
48
50
  sourceLinkToCommentEnabled: () => sourceLinkToCommentEnabled
49
51
  });
@@ -224,6 +226,7 @@ function resolveTheme(opts, siteName, fonts, basePath, locale) {
224
226
  const aiPrompt = typeof opts.aiPrompt === "string" && opts.aiPrompt.trim() ? opts.aiPrompt.trim() : void 0;
225
227
  const copyPage = normalizeCopyPage(opts.copyPage);
226
228
  const pageNav = normalizePageNav(opts.pageNav);
229
+ const playground = normalizePlayground(opts.playground);
227
230
  const colors = normalizeColors(opts.colors);
228
231
  const darkColors = normalizeColors(opts.darkColors);
229
232
  return {
@@ -232,6 +235,7 @@ function resolveTheme(opts, siteName, fonts, basePath, locale) {
232
235
  ...aiPrompt ? { aiPrompt } : {},
233
236
  ...copyPage ? { copyPage } : {},
234
237
  ...pageNav ? { pageNav } : {},
238
+ ...playground ? { playground: playground.theme } : {},
235
239
  tokens: {
236
240
  ...defaultTheme.tokens,
237
241
  colors: { ...defaultTheme.tokens.colors, ...colors ?? {} },
@@ -311,6 +315,22 @@ async function resolveFooter(raw) {
311
315
  }
312
316
  return void 0;
313
317
  }
318
+ async function resolveFavicon(raw, hash, hrefForServed) {
319
+ if (typeof raw !== "string" || raw.trim().length === 0) return void 0;
320
+ const trimmed = raw.trim();
321
+ let bytes;
322
+ try {
323
+ bytes = await (0, import_promises2.readFile)((0, import_node_path2.resolve)(trimmed));
324
+ } catch {
325
+ console.warn(`clean-jsdoc-theme: could not read favicon ('${trimmed}'); omitting it.`);
326
+ return void 0;
327
+ }
328
+ const ext = (0, import_node_path2.extname)(trimmed) || ".ico";
329
+ const base = (0, import_node_path2.basename)(trimmed, (0, import_node_path2.extname)(trimmed)) || "favicon";
330
+ const name = hash ? `${base}.${contentHash(bytes)}${ext}` : `${base}${ext}`;
331
+ const servedPath = `_assets/${name}`;
332
+ return { href: hrefForServed(servedPath), files: [{ path: servedPath, contents: bytes }] };
333
+ }
314
334
  var META_IDENTITY_ATTRS = ["name", "property", "http-equiv", "charset", "itemprop"];
315
335
  function normalizeMeta(raw) {
316
336
  if (!Array.isArray(raw)) return void 0;
@@ -477,6 +497,8 @@ function normalizeMenu(raw) {
477
497
  const link = typeof o.link === "string" && o.link.trim() ? o.link.trim() : typeof o.href === "string" && o.href.trim() ? o.href.trim() : void 0;
478
498
  if (link) item.link = link;
479
499
  if (typeof o.icon === "string" && o.icon.trim()) item.icon = o.icon.trim();
500
+ if (typeof o.target === "string" && o.target.trim()) item.target = o.target.trim();
501
+ if (typeof o.class === "string" && o.class.trim()) item.class = o.class.trim();
480
502
  if (item.id || item.link) out.push(item);
481
503
  }
482
504
  return out.length > 0 ? out : void 0;
@@ -513,7 +535,47 @@ function normalizePageNav(raw) {
513
535
  const enabled = raw.enabled;
514
536
  return typeof enabled === "boolean" ? { enabled } : void 0;
515
537
  }
516
- var COLOR_KEYS = ["bg", "bgMuted", "fg", "fgMuted", "accent", "accentFg", "border"];
538
+ var PLAYGROUND_PROVIDERS = ["codepen", "jsfiddle", "codesandbox"];
539
+ function playgroundOptionRecord(raw) {
540
+ return raw && typeof raw === "object" && !Array.isArray(raw) ? raw : void 0;
541
+ }
542
+ function normalizePlayground(raw) {
543
+ if (raw == null || raw === false) return void 0;
544
+ const o = raw === true ? {} : raw;
545
+ if (typeof o !== "object" || Array.isArray(o)) return void 0;
546
+ const obj = o;
547
+ const site = {};
548
+ if (obj.enableForAllExamples === true) site.enableForAllExamples = true;
549
+ if (Array.isArray(obj.providers)) {
550
+ const providers = [];
551
+ for (const p of obj.providers) {
552
+ if (typeof p === "string" && PLAYGROUND_PROVIDERS.includes(p) && !providers.includes(p)) {
553
+ providers.push(p);
554
+ }
555
+ }
556
+ if (providers.length > 0) site.providers = providers;
557
+ }
558
+ const theme = { enabled: true };
559
+ const codepen = playgroundOptionRecord(obj.codepen);
560
+ const jsfiddle = playgroundOptionRecord(obj.jsfiddle);
561
+ const codesandbox = playgroundOptionRecord(obj.codesandbox);
562
+ if (codepen) theme.codepen = codepen;
563
+ if (jsfiddle) theme.jsfiddle = jsfiddle;
564
+ if (codesandbox) theme.codesandbox = codesandbox;
565
+ return { site, theme };
566
+ }
567
+ var COLOR_KEYS = [
568
+ "bg",
569
+ "bgMuted",
570
+ "fg",
571
+ "fgMuted",
572
+ "accent",
573
+ "accentFg",
574
+ "border",
575
+ "codeHeaderBg",
576
+ "codeHeaderFg",
577
+ "codeHighlightBg"
578
+ ];
517
579
  function normalizeColors(raw) {
518
580
  if (!raw || typeof raw !== "object" || Array.isArray(raw)) return void 0;
519
581
  const src = raw;
@@ -861,6 +923,7 @@ async function publish(data, opts, tutorials) {
861
923
  const sectionOrder = normalizeSectionOrder(opts.sectionOrder);
862
924
  const menu = normalizeMenu(opts.menu);
863
925
  const clubSidebarItems = opts.clubSidebarItems === true;
926
+ const playground = normalizePlayground(opts.playground);
864
927
  const siteOptions = {
865
928
  ...pkg ? { pkg } : {},
866
929
  ...readme ? { readme } : {},
@@ -872,7 +935,8 @@ async function publish(data, opts, tutorials) {
872
935
  ...defaultDocGroup ? { defaultDocGroup } : {},
873
936
  ...sectionOrder ? { sectionOrder } : {},
874
937
  ...menu ? { menu } : {},
875
- ...clubSidebarItems ? { clubSidebarItems } : {}
938
+ ...clubSidebarItems ? { clubSidebarItems } : {},
939
+ ...playground ? { playground: playground.site } : {}
876
940
  };
877
941
  const manifest = await progress.stage(
878
942
  "Generating pages",
@@ -909,6 +973,7 @@ async function publish(data, opts, tutorials) {
909
973
  }
910
974
  const customAssets = await resolveCustomAssets(opts, hrefForServed);
911
975
  const footer = await resolveFooter(opts.footer);
976
+ const favicon = await resolveFavicon(opts.favicon, opts.hashCustomAssets !== false, hrefForServed);
912
977
  const meta = normalizeMeta(opts.meta);
913
978
  const absoluteDestination = (0, import_node_path2.resolve)(destination);
914
979
  const islandCacheDir = (0, import_node_path2.resolve)(process.cwd(), "node_modules", ".cache", "clean-jsdoc-theme");
@@ -919,6 +984,7 @@ async function publish(data, opts, tutorials) {
919
984
  ...resolveTheme(opts, siteName, fonts, basePath, buildSpec?.locale),
920
985
  ...customAssets.theme,
921
986
  ...footer ? { footer } : {},
987
+ ...favicon ? { favicon: favicon.href } : {},
922
988
  ...meta ? { meta } : {}
923
989
  },
924
990
  destination: absoluteDestination,
@@ -937,7 +1003,13 @@ async function publish(data, opts, tutorials) {
937
1003
  } : {}
938
1004
  })
939
1005
  );
940
- const outputFiles = [...result.files, ...logoFiles, ...customAssets.files, ...docImageFiles];
1006
+ const outputFiles = [
1007
+ ...result.files,
1008
+ ...logoFiles,
1009
+ ...customAssets.files,
1010
+ ...docImageFiles,
1011
+ ...favicon?.files ?? []
1012
+ ];
941
1013
  await progress.stage("Writing files", () => writeOutputFiles(absoluteDestination, outputFiles));
942
1014
  const zlib = await import("zlib");
943
1015
  const gzipSizer = (b) => zlib.gzipSync(b).length;
@@ -978,11 +1050,13 @@ async function publish(data, opts, tutorials) {
978
1050
  normalizeMenu,
979
1051
  normalizeMeta,
980
1052
  normalizePageNav,
1053
+ normalizePlayground,
981
1054
  normalizeSectionOrder,
982
1055
  outputSourceFilesEnabled,
983
1056
  overlayDocs,
984
1057
  publish,
985
1058
  resolveDocImages,
1059
+ resolveFavicon,
986
1060
  resolveFooter,
987
1061
  sourceLinkToCommentEnabled
988
1062
  });