@hyperbook/types 0.26.0 → 0.28.0

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/index.d.ts CHANGED
@@ -1,6 +1,25 @@
1
1
  type ElementConfig = {
2
2
  version?: string;
3
3
  };
4
+ export type ElementAssetConfig = ElementConfig & {
5
+ /** Use the default CDN (true), a custom HTTP(S) asset base URL, or local assets (false). Defaults to true for PyIDE and false for other elements. */
6
+ cdn?: boolean | string;
7
+ };
8
+ /** Small integration files retained locally when an element uses a CDN. */
9
+ export declare const elementCoreFiles: {
10
+ blockflow: string[];
11
+ onlineide: string[];
12
+ sqlide: string[];
13
+ excalidraw: string[];
14
+ openscad: string[];
15
+ geogebra: string[];
16
+ pyide: string[];
17
+ typst: string[];
18
+ };
19
+ export type DownloadableElement = keyof typeof elementCoreFiles;
20
+ /** Files whose presence shows that an element's full runtime is available locally. */
21
+ export declare const elementRuntimeFiles: Record<DownloadableElement, string[]>;
22
+ export declare function elementCdn(config: HyperbookJson, element: string): boolean | string;
4
23
  export type Script = string | {
5
24
  type?: "module" | "plain/text";
6
25
  src: string;
@@ -229,13 +248,18 @@ export type HyperbookJson = {
229
248
  bypassInline?: boolean;
230
249
  showLineNumbers?: boolean;
231
250
  };
232
- excalidraw?: ElementConfig & {
251
+ blockflow?: ElementAssetConfig;
252
+ geogebra?: ElementAssetConfig;
253
+ openscad?: ElementAssetConfig;
254
+ pyide?: ElementAssetConfig;
255
+ typst?: ElementAssetConfig;
256
+ excalidraw?: ElementAssetConfig & {
233
257
  autoZoom?: boolean;
234
258
  center?: boolean;
235
259
  aspectRatio?: string;
236
260
  edit?: boolean;
237
261
  };
238
- onlineide?: ElementConfig & {
262
+ onlineide?: ElementAssetConfig & {
239
263
  height?: string | number;
240
264
  outputWidth?: string;
241
265
  };
@@ -243,7 +267,7 @@ export type HyperbookJson = {
243
267
  height?: string;
244
268
  settings?: string;
245
269
  };
246
- sqlide?: ElementConfig & {
270
+ sqlide?: ElementAssetConfig & {
247
271
  db?: string;
248
272
  height?: string | number;
249
273
  };
package/dist/index.js CHANGED
@@ -1,4 +1,52 @@
1
1
  // src/index.ts
2
+ var elementCoreFiles = {
3
+ blockflow: [],
4
+ onlineide: ["style.css"],
5
+ sqlide: ["client.js", "style.css"],
6
+ excalidraw: ["client.js", "style.css"],
7
+ openscad: ["client.js", "worker.js", "style.css"],
8
+ geogebra: ["client.js", "geogebra-web-component.js", "style.css"],
9
+ pyide: ["client.js", "python-friendly-error-messages.js", "style.css"],
10
+ typst: ["client.js", "style.css"]
11
+ };
12
+ var elementRuntimeFiles = {
13
+ blockflow: ["player.html"],
14
+ onlineide: ["include/online-ide-embedded.js"],
15
+ sqlide: ["include/sql-ide-embedded.js"],
16
+ excalidraw: ["hyperbook-excalidraw.umd.js"],
17
+ geogebra: ["GeoGebra/deployggb.js"],
18
+ pyide: ["pyodide/pyodide.js", "pyodide/pyodide-lock.json"],
19
+ typst: [
20
+ "typst-bundle.js",
21
+ "typst-compiler.wasm",
22
+ "fonts/LibertinusSerif-Regular.otf"
23
+ ],
24
+ openscad: [
25
+ "openscad.wasm",
26
+ "libraries/BOSL2.zip",
27
+ "fonts/Roboto-Regular.ttf"
28
+ ]
29
+ };
30
+ function elementCdn(config, element) {
31
+ if (!Object.prototype.hasOwnProperty.call(elementCoreFiles, element))
32
+ return false;
33
+ const value = config.elements?.[element]?.cdn;
34
+ if (value === void 0) return element === "pyide";
35
+ if (value === false) return false;
36
+ if (value === true) return true;
37
+ if (typeof value === "string") {
38
+ try {
39
+ const url = new URL(value);
40
+ if (["http:", "https:"].includes(url.protocol) && !url.search && !url.hash) {
41
+ return url.href.replace(/\/?$/, "/");
42
+ }
43
+ } catch {
44
+ }
45
+ }
46
+ throw new Error(
47
+ `elements.${element}.cdn must be a boolean or an absolute HTTP(S) base URL without a query or fragment.`
48
+ );
49
+ }
2
50
  var FALLBACK_INDEX_PAGE = 9999;
3
51
  var FALLBACK_INDEX_SECTION = 1e4;
4
52
  var isShownAsPage = (section) => section.navigation === "page";
@@ -39,6 +87,9 @@ var sortNavigation = (pages, sections) => {
39
87
  var URL_SCHEME = /^[a-zA-Z][a-zA-Z0-9+.-]*:/;
40
88
  var isExternalUrl = (path) => URL_SCHEME.test(path);
41
89
  export {
90
+ elementCdn,
91
+ elementCoreFiles,
92
+ elementRuntimeFiles,
42
93
  isExternalUrl,
43
94
  sortNavigation
44
95
  };
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts"],
4
- "sourcesContent": ["type ElementConfig = {\n version?: string;\n};\n\nexport type Script =\n | string\n | {\n type?: \"module\" | \"plain/text\";\n src: string;\n crossorigin?: boolean;\n position: \"head\" | \"body\";\n versioned?: boolean;\n };\n\nexport type LinkWithLinks = {\n label: string;\n icon?: string;\n links: Link[];\n};\n\nexport type LinkWithHref = {\n label: string;\n icon?: string;\n href: string;\n};\n\nexport type Link = LinkWithHref | LinkWithLinks;\n\nexport type Navigation = {\n next: HyperbookPage | null;\n previous: HyperbookPage | null;\n current: HyperbookPage | null;\n pages: HyperbookPage[];\n sections: HyperbookSection[];\n glossary: HyperbookPage[];\n};\n\nexport type Term = {\n name: string;\n href: string;\n};\n\nexport type Glossary = Record<string, Term[]>;\n\nexport type Language = \"de\" | \"en\" | \"fr\" | \"es\" | \"it\" | \"pt\" | \"nl\";\n\nexport type Layout = \"default\" | \"wide\" | \"standalone\";\n\nexport type BreadcrumbConfig = {\n home?: string;\n separator?: string;\n};\n\nexport type PageNavigation = \"default\" | \"hidden\";\n\nexport type SectionNavigation =\n | \"default\"\n | \"hidden\"\n | \"virtual\"\n | \"page\"\n | \"expanded\";\n\nexport type HyperbookPageFrontmatter = {\n name: string;\n title?: string;\n permaid?: string;\n lang?: Language;\n qrcode?: boolean;\n description?: string;\n keywords?: string[];\n scripts?: string[];\n styles?: string[];\n index?: number;\n hide?: boolean;\n toc?: boolean;\n next?: string;\n prev?: string;\n layout?: Layout;\n breadcrumb?: boolean | BreadcrumbConfig;\n navigation?: PageNavigation;\n /**\n * Password-protects the whole page. On a section (its index.md) this is\n * inherited by every descendant that does not set its own.\n */\n protect?: ProtectReference;\n};\n\nexport type HyperbookSectionFrontmatter = Omit<\n HyperbookPageFrontmatter,\n \"navigation\"\n> & {\n virtual?: boolean;\n expanded?: boolean;\n navigation?: SectionNavigation;\n};\n\nexport type ProtectInheritance = {\n /**\n * True when this page's `protect` came from an ancestor section rather than\n * from its own frontmatter.\n */\n protectInherited?: boolean;\n /**\n * href of the page or section whose frontmatter declared the protection.\n *\n * Everything that resolves to the same source shares one unlock, so entering\n * a section's password opens the whole section rather than every page asking\n * again for the same thing.\n */\n protectSource?: string;\n};\n\nexport type HyperbookPage = HyperbookPageFrontmatter &\n ProtectInheritance & {\n isEmpty?: boolean;\n href?: string;\n path?: {\n directory: string;\n relative: string;\n absolute: string;\n href: string | null;\n permalink: string | null;\n };\n repo?: string;\n};\n\nexport type HyperbookSection = HyperbookSectionFrontmatter &\n ProtectInheritance & {\n isEmpty?: boolean;\n href?: string;\n pages: HyperbookPage[];\n sections: HyperbookSection[];\n repo?: string;\n };\n\nexport type HyperbookFrontmatter =\n | HyperbookPageFrontmatter\n | HyperbookSectionFrontmatter;\n\n/**\n * How protected content is stored in the built HTML.\n *\n * - \"encrypt\": AES-256-GCM, key derived from the password with PBKDF2. The\n * plaintext never leaves the build. Needs `crypto.subtle`, which browsers\n * only expose in secure contexts (https or localhost).\n * - \"obfuscate\": the legacy behaviour \u2014 content and password both ship in the\n * page. Provides no protection, but works from `file://`.\n */\nexport type ProtectMode = \"encrypt\" | \"obfuscate\";\n\nexport type ProtectConfig = {\n /** Defaults to \"encrypt\". */\n mode?: ProtectMode;\n /** PBKDF2 iterations. Defaults to 250000. */\n iterations?: number;\n /** Registry location, relative to the book root. Defaults to \"passwords.json\". */\n passwordsFile?: string;\n};\n\n/** One named password in the registry. */\nexport type PasswordEntry = {\n value: string;\n /** Label shown by `hyperbook passwords` and the passwordlist directive. */\n name?: string;\n description?: string;\n};\n\n/**\n * Contents of passwords.json.\n *\n * Keep this file out of version control if the book is public \u2014 it holds the\n * actual passwords. Values can also come from the environment; see the\n * `hyperbook passwords` documentation.\n */\nexport type PasswordsJson = {\n $schema?: string;\n /** The bare string form is shorthand for `{ \"value\": \"...\" }`. */\n passwords: { [key: string]: PasswordEntry | string };\n};\n\n/**\n * A password reference on a page or section, or on a `:::protect` directive.\n * The string form is a registry key.\n */\nexport type ProtectReference =\n | string\n | {\n /** Key in the password registry. */\n use?: string;\n /** Literal password, for books that do not use a registry. */\n password?: string;\n /** Human-readable label for this protected content in password lists. */\n name?: string;\n description?: string;\n };\n\nexport type HyperbookJson = {\n name: string;\n description?: string;\n logo?: string;\n allowDangerousHtml?: boolean;\n trailingSlash?: boolean;\n importExport?: boolean;\n search?: boolean;\n qrcode?: boolean;\n toc?: boolean;\n llms?: boolean;\n /**\n * Password protection behaviour. Passwords themselves live in a separate\n * registry file so this one can stay committed.\n */\n protect?: ProtectConfig;\n breadcrumb?: boolean | BreadcrumbConfig;\n author?: {\n name?: string;\n url?: string;\n };\n /**\n * Controls how the Hyperbook version is displayed.\n * - \"text\": Shows version below the \"Powered by Hyperbook\" label.\n * - \"tooltip\": Shows version on hover of the \"Powered by Hyperbook\" label.\n * - \"console\": Outputs version as ASCII art in the browser console (default).\n */\n version?: \"text\" | \"tooltip\" | \"console\";\n font?: string;\n fonts?: {\n heading?: string;\n body?: string;\n code?: string;\n };\n scripts?: string[];\n styles?: string[];\n colors?: {\n /**\n * @format color-hex\n */\n brand?: string;\n /**\n * @format color-hex\n */\n brandDark?: string;\n /**\n * @format color-hex\n */\n brandText?: string;\n inverted?: boolean;\n };\n basePath?: string;\n license?: string;\n language?: Language;\n repo?:\n | string\n | {\n url: string;\n label: string;\n };\n links?: Link[];\n cloud?: {\n url: string;\n id: string;\n };\n elements?: {\n bookmarks?: false | ElementConfig;\n code?: ElementConfig & {\n theme?:\n | {\n dark: string;\n light: string;\n }\n | string;\n bypassInline?: boolean;\n showLineNumbers?: boolean;\n };\n excalidraw?: ElementConfig & {\n autoZoom?: boolean;\n center?: boolean;\n aspectRatio?: string;\n edit?: boolean;\n };\n onlineide?: ElementConfig & {\n height?: string | number;\n outputWidth?: string;\n };\n kirimoto?: ElementConfig & {\n height?: string;\n settings?: string;\n };\n sqlide?: ElementConfig & {\n db?: string;\n height?: string | number;\n };\n emoji?: ElementConfig & {\n /**\n * How emojis are rendered.\n * - \"native\": Emojis are kept as text and drawn with the emoji font of\n * the reader's operating system (default).\n * - \"twemoji\": Emojis are replaced with Twemoji images, so they look the\n * same on every platform.\n */\n style?: \"native\" | \"twemoji\";\n };\n };\n};\n\nexport type LanguageString = Partial<Record<Language, string>>;\n\nexport type HyperlibraryJson = {\n name: string | LanguageString;\n library: {\n src: string;\n basePath: string;\n icon?: string;\n name?: string | LanguageString;\n }[];\n basePath?: string;\n};\n\nexport type Hyperproject = {\n name: string | LanguageString;\n basePath?: string;\n icon?: string;\n src: string;\n} & ({ type: \"book\" } | { type: \"library\"; projects: Hyperproject[] });\n\nexport interface HyperbookContext {\n root: string;\n config: HyperbookJson;\n library?: HyperlibraryJson;\n project?: Hyperproject;\n version?: string;\n makeUrl(\n path: string | string[],\n base: \"public\" | \"book\" | \"archive\" | \"glossary\" | \"assets\",\n page?: HyperbookPage,\n options?: {\n versioned?: boolean;\n },\n ): string;\n navigation: Navigation;\n /**\n * Resolved password registry.\n *\n * Deliberately kept off `config`: the config object is serialized into the\n * page in several places, and a password that reaches it would be published.\n * Only the protect plugins may read this.\n */\n passwords?: Record<string, PasswordEntry>;\n /**\n * Collects absolute paths of files inlined into the page while it is being\n * processed, so the dev server can rebuild exactly the pages that used them.\n * Only set during a build that tracks dependencies.\n */\n dependencies?: Set<string>;\n}\n\n/** One entry of a navigation level, either a page or a section. */\nexport type NavigationEntry =\n | { type: \"page\"; page: HyperbookPage }\n | { type: \"section\"; section: HyperbookSection };\n\n/**\n * Pages and sections without an index keep their old order, pages first. A\n * section that is shown as a page is one of the pages here, because that is\n * how it is rendered.\n */\nconst FALLBACK_INDEX_PAGE = 9999;\nconst FALLBACK_INDEX_SECTION = 10000;\n\nconst isShownAsPage = (section: HyperbookSection): boolean =>\n section.navigation === \"page\";\n\n/**\n * Brings the pages and the sections of one navigation level into a single\n * order. `index` decides, across both of them, so a section can sit between\n * two pages. Entries without an `index` fall back to pages before sections,\n * and entries that end up equal are ordered by name.\n *\n * Both lists are expected to be in order already, which is what reading a\n * hyperbook gives. They are merged rather than sorted, so the order a caller\n * built stays intact and only the two lists are woven together.\n */\nexport const sortNavigation = (\n pages: HyperbookPage[],\n sections: HyperbookSection[],\n): NavigationEntry[] => {\n const pageKey = (page: HyperbookPage) => ({\n index: page.index ?? FALLBACK_INDEX_PAGE,\n kind: 0,\n name: page.name,\n });\n const sectionKey = (section: HyperbookSection) => ({\n index:\n section.index ??\n (isShownAsPage(section) ? FALLBACK_INDEX_PAGE : FALLBACK_INDEX_SECTION),\n kind: isShownAsPage(section) ? 0 : 1,\n name: section.name,\n });\n\n const entries: NavigationEntry[] = [];\n let p = 0;\n let s = 0;\n\n while (p < pages.length || s < sections.length) {\n if (s >= sections.length) {\n entries.push({ type: \"page\", page: pages[p++] });\n continue;\n }\n if (p >= pages.length) {\n entries.push({ type: \"section\", section: sections[s++] });\n continue;\n }\n\n const page = pageKey(pages[p]);\n const section = sectionKey(sections[s]);\n const takePage =\n page.index !== section.index\n ? page.index < section.index\n : page.kind !== section.kind\n ? page.kind < section.kind\n : page.name <= section.name;\n\n if (takePage) {\n entries.push({ type: \"page\", page: pages[p++] });\n } else {\n entries.push({ type: \"section\", section: sections[s++] });\n }\n }\n\n return entries;\n};\n\n/**\n * Matches a URI scheme at the start of a string, as defined by RFC 3986.\n * This covers `https://` and `data:` as well as schemes without an authority\n * like `mailto:`, `tel:` or `sms:`.\n */\nconst URL_SCHEME = /^[a-zA-Z][a-zA-Z0-9+.-]*:/;\n\n/**\n * Checks whether a path is an absolute URL and therefore must be passed\n * through untouched by `makeUrl`, instead of being resolved against the\n * hyperbook's base path.\n */\nexport const isExternalUrl = (path: string): boolean => URL_SCHEME.test(path);\n"],
5
- "mappings": ";AA6WA,IAAM,sBAAsB;AAC5B,IAAM,yBAAyB;AAE/B,IAAM,gBAAgB,CAAC,YACrB,QAAQ,eAAe;AAYlB,IAAM,iBAAiB,CAC5B,OACA,aACsB;AACtB,QAAM,UAAU,CAAC,UAAyB;AAAA,IACxC,OAAO,KAAK,SAAS;AAAA,IACrB,MAAM;AAAA,IACN,MAAM,KAAK;AAAA,EACb;AACA,QAAM,aAAa,CAAC,aAA+B;AAAA,IACjD,OACE,QAAQ,UACP,cAAc,OAAO,IAAI,sBAAsB;AAAA,IAClD,MAAM,cAAc,OAAO,IAAI,IAAI;AAAA,IACnC,MAAM,QAAQ;AAAA,EAChB;AAEA,QAAM,UAA6B,CAAC;AACpC,MAAI,IAAI;AACR,MAAI,IAAI;AAER,SAAO,IAAI,MAAM,UAAU,IAAI,SAAS,QAAQ;AAC9C,QAAI,KAAK,SAAS,QAAQ;AACxB,cAAQ,KAAK,EAAE,MAAM,QAAQ,MAAM,MAAM,GAAG,EAAE,CAAC;AAC/C;AAAA,IACF;AACA,QAAI,KAAK,MAAM,QAAQ;AACrB,cAAQ,KAAK,EAAE,MAAM,WAAW,SAAS,SAAS,GAAG,EAAE,CAAC;AACxD;AAAA,IACF;AAEA,UAAM,OAAO,QAAQ,MAAM,CAAC,CAAC;AAC7B,UAAM,UAAU,WAAW,SAAS,CAAC,CAAC;AACtC,UAAM,WACJ,KAAK,UAAU,QAAQ,QACnB,KAAK,QAAQ,QAAQ,QACrB,KAAK,SAAS,QAAQ,OACpB,KAAK,OAAO,QAAQ,OACpB,KAAK,QAAQ,QAAQ;AAE7B,QAAI,UAAU;AACZ,cAAQ,KAAK,EAAE,MAAM,QAAQ,MAAM,MAAM,GAAG,EAAE,CAAC;AAAA,IACjD,OAAO;AACL,cAAQ,KAAK,EAAE,MAAM,WAAW,SAAS,SAAS,GAAG,EAAE,CAAC;AAAA,IAC1D;AAAA,EACF;AAEA,SAAO;AACT;AAOA,IAAM,aAAa;AAOZ,IAAM,gBAAgB,CAAC,SAA0B,WAAW,KAAK,IAAI;",
4
+ "sourcesContent": ["type ElementConfig = {\n version?: string;\n};\n\nexport type ElementAssetConfig = ElementConfig & {\n /** Use the default CDN (true), a custom HTTP(S) asset base URL, or local assets (false). Defaults to true for PyIDE and false for other elements. */\n cdn?: boolean | string;\n};\n\n/** Small integration files retained locally when an element uses a CDN. */\nexport const elementCoreFiles = {\n blockflow: [] as string[],\n onlineide: [\"style.css\"],\n sqlide: [\"client.js\", \"style.css\"],\n excalidraw: [\"client.js\", \"style.css\"],\n openscad: [\"client.js\", \"worker.js\", \"style.css\"],\n geogebra: [\"client.js\", \"geogebra-web-component.js\", \"style.css\"],\n pyide: [\"client.js\", \"python-friendly-error-messages.js\", \"style.css\"],\n typst: [\"client.js\", \"style.css\"],\n} satisfies Record<string, string[]>;\n\nexport type DownloadableElement = keyof typeof elementCoreFiles;\n\n/** Files whose presence shows that an element's full runtime is available locally. */\nexport const elementRuntimeFiles: Record<DownloadableElement, string[]> = {\n blockflow: [\"player.html\"],\n onlineide: [\"include/online-ide-embedded.js\"],\n sqlide: [\"include/sql-ide-embedded.js\"],\n excalidraw: [\"hyperbook-excalidraw.umd.js\"],\n geogebra: [\"GeoGebra/deployggb.js\"],\n pyide: [\"pyodide/pyodide.js\", \"pyodide/pyodide-lock.json\"],\n typst: [\n \"typst-bundle.js\",\n \"typst-compiler.wasm\",\n \"fonts/LibertinusSerif-Regular.otf\",\n ],\n openscad: [\n \"openscad.wasm\",\n \"libraries/BOSL2.zip\",\n \"fonts/Roboto-Regular.ttf\",\n ],\n};\n\nexport function elementCdn(\n config: HyperbookJson,\n element: string,\n): boolean | string {\n if (!Object.prototype.hasOwnProperty.call(elementCoreFiles, element))\n return false;\n const value = config.elements?.[element as DownloadableElement]?.cdn;\n if (value === undefined) return element === \"pyide\";\n if (value === false) return false;\n if (value === true) return true;\n if (typeof value === \"string\") {\n try {\n const url = new URL(value);\n if (\n [\"http:\", \"https:\"].includes(url.protocol) &&\n !url.search &&\n !url.hash\n ) {\n return url.href.replace(/\\/?$/, \"/\");\n }\n } catch {}\n }\n throw new Error(\n `elements.${element}.cdn must be a boolean or an absolute HTTP(S) base URL without a query or fragment.`,\n );\n}\n\nexport type Script =\n | string\n | {\n type?: \"module\" | \"plain/text\";\n src: string;\n crossorigin?: boolean;\n position: \"head\" | \"body\";\n versioned?: boolean;\n };\n\nexport type LinkWithLinks = {\n label: string;\n icon?: string;\n links: Link[];\n};\n\nexport type LinkWithHref = {\n label: string;\n icon?: string;\n href: string;\n};\n\nexport type Link = LinkWithHref | LinkWithLinks;\n\nexport type Navigation = {\n next: HyperbookPage | null;\n previous: HyperbookPage | null;\n current: HyperbookPage | null;\n pages: HyperbookPage[];\n sections: HyperbookSection[];\n glossary: HyperbookPage[];\n};\n\nexport type Term = {\n name: string;\n href: string;\n};\n\nexport type Glossary = Record<string, Term[]>;\n\nexport type Language = \"de\" | \"en\" | \"fr\" | \"es\" | \"it\" | \"pt\" | \"nl\";\n\nexport type Layout = \"default\" | \"wide\" | \"standalone\";\n\nexport type BreadcrumbConfig = {\n home?: string;\n separator?: string;\n};\n\nexport type PageNavigation = \"default\" | \"hidden\";\n\nexport type SectionNavigation =\n \"default\" | \"hidden\" | \"virtual\" | \"page\" | \"expanded\";\n\nexport type HyperbookPageFrontmatter = {\n name: string;\n title?: string;\n permaid?: string;\n lang?: Language;\n qrcode?: boolean;\n description?: string;\n keywords?: string[];\n scripts?: string[];\n styles?: string[];\n index?: number;\n hide?: boolean;\n toc?: boolean;\n next?: string;\n prev?: string;\n layout?: Layout;\n breadcrumb?: boolean | BreadcrumbConfig;\n navigation?: PageNavigation;\n /**\n * Password-protects the whole page. On a section (its index.md) this is\n * inherited by every descendant that does not set its own.\n */\n protect?: ProtectReference;\n};\n\nexport type HyperbookSectionFrontmatter = Omit<\n HyperbookPageFrontmatter,\n \"navigation\"\n> & {\n virtual?: boolean;\n expanded?: boolean;\n navigation?: SectionNavigation;\n};\n\nexport type ProtectInheritance = {\n /**\n * True when this page's `protect` came from an ancestor section rather than\n * from its own frontmatter.\n */\n protectInherited?: boolean;\n /**\n * href of the page or section whose frontmatter declared the protection.\n *\n * Everything that resolves to the same source shares one unlock, so entering\n * a section's password opens the whole section rather than every page asking\n * again for the same thing.\n */\n protectSource?: string;\n};\n\nexport type HyperbookPage = HyperbookPageFrontmatter &\n ProtectInheritance & {\n isEmpty?: boolean;\n href?: string;\n path?: {\n directory: string;\n relative: string;\n absolute: string;\n href: string | null;\n permalink: string | null;\n };\n repo?: string;\n };\n\nexport type HyperbookSection = HyperbookSectionFrontmatter &\n ProtectInheritance & {\n isEmpty?: boolean;\n href?: string;\n pages: HyperbookPage[];\n sections: HyperbookSection[];\n repo?: string;\n };\n\nexport type HyperbookFrontmatter =\n HyperbookPageFrontmatter | HyperbookSectionFrontmatter;\n\n/**\n * How protected content is stored in the built HTML.\n *\n * - \"encrypt\": AES-256-GCM, key derived from the password with PBKDF2. The\n * plaintext never leaves the build. Needs `crypto.subtle`, which browsers\n * only expose in secure contexts (https or localhost).\n * - \"obfuscate\": the legacy behaviour \u2014 content and password both ship in the\n * page. Provides no protection, but works from `file://`.\n */\nexport type ProtectMode = \"encrypt\" | \"obfuscate\";\n\nexport type ProtectConfig = {\n /** Defaults to \"encrypt\". */\n mode?: ProtectMode;\n /** PBKDF2 iterations. Defaults to 250000. */\n iterations?: number;\n /** Registry location, relative to the book root. Defaults to \"passwords.json\". */\n passwordsFile?: string;\n};\n\n/** One named password in the registry. */\nexport type PasswordEntry = {\n value: string;\n /** Label shown by `hyperbook passwords` and the passwordlist directive. */\n name?: string;\n description?: string;\n};\n\n/**\n * Contents of passwords.json.\n *\n * Keep this file out of version control if the book is public \u2014 it holds the\n * actual passwords. Values can also come from the environment; see the\n * `hyperbook passwords` documentation.\n */\nexport type PasswordsJson = {\n $schema?: string;\n /** The bare string form is shorthand for `{ \"value\": \"...\" }`. */\n passwords: { [key: string]: PasswordEntry | string };\n};\n\n/**\n * A password reference on a page or section, or on a `:::protect` directive.\n * The string form is a registry key.\n */\nexport type ProtectReference =\n | string\n | {\n /** Key in the password registry. */\n use?: string;\n /** Literal password, for books that do not use a registry. */\n password?: string;\n /** Human-readable label for this protected content in password lists. */\n name?: string;\n description?: string;\n };\n\nexport type HyperbookJson = {\n name: string;\n description?: string;\n logo?: string;\n allowDangerousHtml?: boolean;\n trailingSlash?: boolean;\n importExport?: boolean;\n search?: boolean;\n qrcode?: boolean;\n toc?: boolean;\n llms?: boolean;\n /**\n * Password protection behaviour. Passwords themselves live in a separate\n * registry file so this one can stay committed.\n */\n protect?: ProtectConfig;\n breadcrumb?: boolean | BreadcrumbConfig;\n author?: {\n name?: string;\n url?: string;\n };\n /**\n * Controls how the Hyperbook version is displayed.\n * - \"text\": Shows version below the \"Powered by Hyperbook\" label.\n * - \"tooltip\": Shows version on hover of the \"Powered by Hyperbook\" label.\n * - \"console\": Outputs version as ASCII art in the browser console (default).\n */\n version?: \"text\" | \"tooltip\" | \"console\";\n font?: string;\n fonts?: {\n heading?: string;\n body?: string;\n code?: string;\n };\n scripts?: string[];\n styles?: string[];\n colors?: {\n /**\n * @format color-hex\n */\n brand?: string;\n /**\n * @format color-hex\n */\n brandDark?: string;\n /**\n * @format color-hex\n */\n brandText?: string;\n inverted?: boolean;\n };\n basePath?: string;\n license?: string;\n language?: Language;\n repo?:\n | string\n | {\n url: string;\n label: string;\n };\n links?: Link[];\n cloud?: {\n url: string;\n id: string;\n };\n elements?: {\n bookmarks?: false | ElementConfig;\n code?: ElementConfig & {\n theme?:\n | {\n dark: string;\n light: string;\n }\n | string;\n bypassInline?: boolean;\n showLineNumbers?: boolean;\n };\n blockflow?: ElementAssetConfig;\n geogebra?: ElementAssetConfig;\n openscad?: ElementAssetConfig;\n pyide?: ElementAssetConfig;\n typst?: ElementAssetConfig;\n excalidraw?: ElementAssetConfig & {\n autoZoom?: boolean;\n center?: boolean;\n aspectRatio?: string;\n edit?: boolean;\n };\n onlineide?: ElementAssetConfig & {\n height?: string | number;\n outputWidth?: string;\n };\n kirimoto?: ElementConfig & {\n height?: string;\n settings?: string;\n };\n sqlide?: ElementAssetConfig & {\n db?: string;\n height?: string | number;\n };\n emoji?: ElementConfig & {\n /**\n * How emojis are rendered.\n * - \"native\": Emojis are kept as text and drawn with the emoji font of\n * the reader's operating system (default).\n * - \"twemoji\": Emojis are replaced with Twemoji images, so they look the\n * same on every platform.\n */\n style?: \"native\" | \"twemoji\";\n };\n };\n};\n\nexport type LanguageString = Partial<Record<Language, string>>;\n\nexport type HyperlibraryJson = {\n name: string | LanguageString;\n library: {\n src: string;\n basePath: string;\n icon?: string;\n name?: string | LanguageString;\n }[];\n basePath?: string;\n};\n\nexport type Hyperproject = {\n name: string | LanguageString;\n basePath?: string;\n icon?: string;\n src: string;\n} & ({ type: \"book\" } | { type: \"library\"; projects: Hyperproject[] });\n\nexport interface HyperbookContext {\n root: string;\n config: HyperbookJson;\n library?: HyperlibraryJson;\n project?: Hyperproject;\n version?: string;\n makeUrl(\n path: string | string[],\n base: \"public\" | \"book\" | \"archive\" | \"glossary\" | \"assets\",\n page?: HyperbookPage,\n options?: {\n versioned?: boolean;\n },\n ): string;\n navigation: Navigation;\n /**\n * Resolved password registry.\n *\n * Deliberately kept off `config`: the config object is serialized into the\n * page in several places, and a password that reaches it would be published.\n * Only the protect plugins may read this.\n */\n passwords?: Record<string, PasswordEntry>;\n /**\n * Collects absolute paths of files inlined into the page while it is being\n * processed, so the dev server can rebuild exactly the pages that used them.\n * Only set during a build that tracks dependencies.\n */\n dependencies?: Set<string>;\n}\n\n/** One entry of a navigation level, either a page or a section. */\nexport type NavigationEntry =\n | { type: \"page\"; page: HyperbookPage }\n | { type: \"section\"; section: HyperbookSection };\n\n/**\n * Pages and sections without an index keep their old order, pages first. A\n * section that is shown as a page is one of the pages here, because that is\n * how it is rendered.\n */\nconst FALLBACK_INDEX_PAGE = 9999;\nconst FALLBACK_INDEX_SECTION = 10000;\n\nconst isShownAsPage = (section: HyperbookSection): boolean =>\n section.navigation === \"page\";\n\n/**\n * Brings the pages and the sections of one navigation level into a single\n * order. `index` decides, across both of them, so a section can sit between\n * two pages. Entries without an `index` fall back to pages before sections,\n * and entries that end up equal are ordered by name.\n *\n * Both lists are expected to be in order already, which is what reading a\n * hyperbook gives. They are merged rather than sorted, so the order a caller\n * built stays intact and only the two lists are woven together.\n */\nexport const sortNavigation = (\n pages: HyperbookPage[],\n sections: HyperbookSection[],\n): NavigationEntry[] => {\n const pageKey = (page: HyperbookPage) => ({\n index: page.index ?? FALLBACK_INDEX_PAGE,\n kind: 0,\n name: page.name,\n });\n const sectionKey = (section: HyperbookSection) => ({\n index:\n section.index ??\n (isShownAsPage(section) ? FALLBACK_INDEX_PAGE : FALLBACK_INDEX_SECTION),\n kind: isShownAsPage(section) ? 0 : 1,\n name: section.name,\n });\n\n const entries: NavigationEntry[] = [];\n let p = 0;\n let s = 0;\n\n while (p < pages.length || s < sections.length) {\n if (s >= sections.length) {\n entries.push({ type: \"page\", page: pages[p++] });\n continue;\n }\n if (p >= pages.length) {\n entries.push({ type: \"section\", section: sections[s++] });\n continue;\n }\n\n const page = pageKey(pages[p]);\n const section = sectionKey(sections[s]);\n const takePage =\n page.index !== section.index\n ? page.index < section.index\n : page.kind !== section.kind\n ? page.kind < section.kind\n : page.name <= section.name;\n\n if (takePage) {\n entries.push({ type: \"page\", page: pages[p++] });\n } else {\n entries.push({ type: \"section\", section: sections[s++] });\n }\n }\n\n return entries;\n};\n\n/**\n * Matches a URI scheme at the start of a string, as defined by RFC 3986.\n * This covers `https://` and `data:` as well as schemes without an authority\n * like `mailto:`, `tel:` or `sms:`.\n */\nconst URL_SCHEME = /^[a-zA-Z][a-zA-Z0-9+.-]*:/;\n\n/**\n * Checks whether a path is an absolute URL and therefore must be passed\n * through untouched by `makeUrl`, instead of being resolved against the\n * hyperbook's base path.\n */\nexport const isExternalUrl = (path: string): boolean => URL_SCHEME.test(path);\n"],
5
+ "mappings": ";AAUO,IAAM,mBAAmB;AAAA,EAC9B,WAAW,CAAC;AAAA,EACZ,WAAW,CAAC,WAAW;AAAA,EACvB,QAAQ,CAAC,aAAa,WAAW;AAAA,EACjC,YAAY,CAAC,aAAa,WAAW;AAAA,EACrC,UAAU,CAAC,aAAa,aAAa,WAAW;AAAA,EAChD,UAAU,CAAC,aAAa,6BAA6B,WAAW;AAAA,EAChE,OAAO,CAAC,aAAa,qCAAqC,WAAW;AAAA,EACrE,OAAO,CAAC,aAAa,WAAW;AAClC;AAKO,IAAM,sBAA6D;AAAA,EACxE,WAAW,CAAC,aAAa;AAAA,EACzB,WAAW,CAAC,gCAAgC;AAAA,EAC5C,QAAQ,CAAC,6BAA6B;AAAA,EACtC,YAAY,CAAC,6BAA6B;AAAA,EAC1C,UAAU,CAAC,uBAAuB;AAAA,EAClC,OAAO,CAAC,sBAAsB,2BAA2B;AAAA,EACzD,OAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,UAAU;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEO,SAAS,WACd,QACA,SACkB;AAClB,MAAI,CAAC,OAAO,UAAU,eAAe,KAAK,kBAAkB,OAAO;AACjE,WAAO;AACT,QAAM,QAAQ,OAAO,WAAW,OAA8B,GAAG;AACjE,MAAI,UAAU,OAAW,QAAO,YAAY;AAC5C,MAAI,UAAU,MAAO,QAAO;AAC5B,MAAI,UAAU,KAAM,QAAO;AAC3B,MAAI,OAAO,UAAU,UAAU;AAC7B,QAAI;AACF,YAAM,MAAM,IAAI,IAAI,KAAK;AACzB,UACE,CAAC,SAAS,QAAQ,EAAE,SAAS,IAAI,QAAQ,KACzC,CAAC,IAAI,UACL,CAAC,IAAI,MACL;AACA,eAAO,IAAI,KAAK,QAAQ,QAAQ,GAAG;AAAA,MACrC;AAAA,IACF,QAAQ;AAAA,IAAC;AAAA,EACX;AACA,QAAM,IAAI;AAAA,IACR,YAAY,OAAO;AAAA,EACrB;AACF;AA2WA,IAAM,sBAAsB;AAC5B,IAAM,yBAAyB;AAE/B,IAAM,gBAAgB,CAAC,YACrB,QAAQ,eAAe;AAYlB,IAAM,iBAAiB,CAC5B,OACA,aACsB;AACtB,QAAM,UAAU,CAAC,UAAyB;AAAA,IACxC,OAAO,KAAK,SAAS;AAAA,IACrB,MAAM;AAAA,IACN,MAAM,KAAK;AAAA,EACb;AACA,QAAM,aAAa,CAAC,aAA+B;AAAA,IACjD,OACE,QAAQ,UACP,cAAc,OAAO,IAAI,sBAAsB;AAAA,IAClD,MAAM,cAAc,OAAO,IAAI,IAAI;AAAA,IACnC,MAAM,QAAQ;AAAA,EAChB;AAEA,QAAM,UAA6B,CAAC;AACpC,MAAI,IAAI;AACR,MAAI,IAAI;AAER,SAAO,IAAI,MAAM,UAAU,IAAI,SAAS,QAAQ;AAC9C,QAAI,KAAK,SAAS,QAAQ;AACxB,cAAQ,KAAK,EAAE,MAAM,QAAQ,MAAM,MAAM,GAAG,EAAE,CAAC;AAC/C;AAAA,IACF;AACA,QAAI,KAAK,MAAM,QAAQ;AACrB,cAAQ,KAAK,EAAE,MAAM,WAAW,SAAS,SAAS,GAAG,EAAE,CAAC;AACxD;AAAA,IACF;AAEA,UAAM,OAAO,QAAQ,MAAM,CAAC,CAAC;AAC7B,UAAM,UAAU,WAAW,SAAS,CAAC,CAAC;AACtC,UAAM,WACJ,KAAK,UAAU,QAAQ,QACnB,KAAK,QAAQ,QAAQ,QACrB,KAAK,SAAS,QAAQ,OACpB,KAAK,OAAO,QAAQ,OACpB,KAAK,QAAQ,QAAQ;AAE7B,QAAI,UAAU;AACZ,cAAQ,KAAK,EAAE,MAAM,QAAQ,MAAM,MAAM,GAAG,EAAE,CAAC;AAAA,IACjD,OAAO;AACL,cAAQ,KAAK,EAAE,MAAM,WAAW,SAAS,SAAS,GAAG,EAAE,CAAC;AAAA,IAC1D;AAAA,EACF;AAEA,SAAO;AACT;AAOA,IAAM,aAAa;AAOZ,IAAM,gBAAgB,CAAC,SAA0B,WAAW,KAAK,IAAI;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperbook/types",
3
- "version": "0.26.0",
3
+ "version": "0.28.0",
4
4
  "author": "Mike Barkmin",
5
5
  "homepage": "https://github.com/openpatch/hyperbook#readme",
6
6
  "license": "MIT",