clean-jsdoc-theme 5.0.0 → 5.0.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.
@@ -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;
@@ -513,7 +533,47 @@ function normalizePageNav(raw) {
513
533
  const enabled = raw.enabled;
514
534
  return typeof enabled === "boolean" ? { enabled } : void 0;
515
535
  }
516
- var COLOR_KEYS = ["bg", "bgMuted", "fg", "fgMuted", "accent", "accentFg", "border"];
536
+ var PLAYGROUND_PROVIDERS = ["codepen", "jsfiddle", "codesandbox"];
537
+ function playgroundOptionRecord(raw) {
538
+ return raw && typeof raw === "object" && !Array.isArray(raw) ? raw : void 0;
539
+ }
540
+ function normalizePlayground(raw) {
541
+ if (raw == null || raw === false) return void 0;
542
+ const o = raw === true ? {} : raw;
543
+ if (typeof o !== "object" || Array.isArray(o)) return void 0;
544
+ const obj = o;
545
+ const site = {};
546
+ if (obj.enableForAllExamples === true) site.enableForAllExamples = true;
547
+ if (Array.isArray(obj.providers)) {
548
+ const providers = [];
549
+ for (const p of obj.providers) {
550
+ if (typeof p === "string" && PLAYGROUND_PROVIDERS.includes(p) && !providers.includes(p)) {
551
+ providers.push(p);
552
+ }
553
+ }
554
+ if (providers.length > 0) site.providers = providers;
555
+ }
556
+ const theme = { enabled: true };
557
+ const codepen = playgroundOptionRecord(obj.codepen);
558
+ const jsfiddle = playgroundOptionRecord(obj.jsfiddle);
559
+ const codesandbox = playgroundOptionRecord(obj.codesandbox);
560
+ if (codepen) theme.codepen = codepen;
561
+ if (jsfiddle) theme.jsfiddle = jsfiddle;
562
+ if (codesandbox) theme.codesandbox = codesandbox;
563
+ return { site, theme };
564
+ }
565
+ var COLOR_KEYS = [
566
+ "bg",
567
+ "bgMuted",
568
+ "fg",
569
+ "fgMuted",
570
+ "accent",
571
+ "accentFg",
572
+ "border",
573
+ "codeHeaderBg",
574
+ "codeHeaderFg",
575
+ "codeHighlightBg"
576
+ ];
517
577
  function normalizeColors(raw) {
518
578
  if (!raw || typeof raw !== "object" || Array.isArray(raw)) return void 0;
519
579
  const src = raw;
@@ -861,6 +921,7 @@ async function publish(data, opts, tutorials) {
861
921
  const sectionOrder = normalizeSectionOrder(opts.sectionOrder);
862
922
  const menu = normalizeMenu(opts.menu);
863
923
  const clubSidebarItems = opts.clubSidebarItems === true;
924
+ const playground = normalizePlayground(opts.playground);
864
925
  const siteOptions = {
865
926
  ...pkg ? { pkg } : {},
866
927
  ...readme ? { readme } : {},
@@ -872,7 +933,8 @@ async function publish(data, opts, tutorials) {
872
933
  ...defaultDocGroup ? { defaultDocGroup } : {},
873
934
  ...sectionOrder ? { sectionOrder } : {},
874
935
  ...menu ? { menu } : {},
875
- ...clubSidebarItems ? { clubSidebarItems } : {}
936
+ ...clubSidebarItems ? { clubSidebarItems } : {},
937
+ ...playground ? { playground: playground.site } : {}
876
938
  };
877
939
  const manifest = await progress.stage(
878
940
  "Generating pages",
@@ -909,6 +971,7 @@ async function publish(data, opts, tutorials) {
909
971
  }
910
972
  const customAssets = await resolveCustomAssets(opts, hrefForServed);
911
973
  const footer = await resolveFooter(opts.footer);
974
+ const favicon = await resolveFavicon(opts.favicon, opts.hashCustomAssets !== false, hrefForServed);
912
975
  const meta = normalizeMeta(opts.meta);
913
976
  const absoluteDestination = (0, import_node_path2.resolve)(destination);
914
977
  const islandCacheDir = (0, import_node_path2.resolve)(process.cwd(), "node_modules", ".cache", "clean-jsdoc-theme");
@@ -919,6 +982,7 @@ async function publish(data, opts, tutorials) {
919
982
  ...resolveTheme(opts, siteName, fonts, basePath, buildSpec?.locale),
920
983
  ...customAssets.theme,
921
984
  ...footer ? { footer } : {},
985
+ ...favicon ? { favicon: favicon.href } : {},
922
986
  ...meta ? { meta } : {}
923
987
  },
924
988
  destination: absoluteDestination,
@@ -937,7 +1001,13 @@ async function publish(data, opts, tutorials) {
937
1001
  } : {}
938
1002
  })
939
1003
  );
940
- const outputFiles = [...result.files, ...logoFiles, ...customAssets.files, ...docImageFiles];
1004
+ const outputFiles = [
1005
+ ...result.files,
1006
+ ...logoFiles,
1007
+ ...customAssets.files,
1008
+ ...docImageFiles,
1009
+ ...favicon?.files ?? []
1010
+ ];
941
1011
  await progress.stage("Writing files", () => writeOutputFiles(absoluteDestination, outputFiles));
942
1012
  const zlib = await import("zlib");
943
1013
  const gzipSizer = (b) => zlib.gzipSync(b).length;
@@ -978,11 +1048,13 @@ async function publish(data, opts, tutorials) {
978
1048
  normalizeMenu,
979
1049
  normalizeMeta,
980
1050
  normalizePageNav,
1051
+ normalizePlayground,
981
1052
  normalizeSectionOrder,
982
1053
  outputSourceFilesEnabled,
983
1054
  overlayDocs,
984
1055
  publish,
985
1056
  resolveDocImages,
1057
+ resolveFavicon,
986
1058
  resolveFooter,
987
1059
  sourceLinkToCommentEnabled
988
1060
  });