@hyperbook/types 0.23.2 → 0.25.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 +104 -2
- package/dist/index.js +39 -1
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -58,13 +58,33 @@ export type HyperbookPageFrontmatter = {
|
|
|
58
58
|
layout?: Layout;
|
|
59
59
|
breadcrumb?: boolean | BreadcrumbConfig;
|
|
60
60
|
navigation?: PageNavigation;
|
|
61
|
+
/**
|
|
62
|
+
* Password-protects the whole page. On a section (its index.md) this is
|
|
63
|
+
* inherited by every descendant that does not set its own.
|
|
64
|
+
*/
|
|
65
|
+
protect?: ProtectReference;
|
|
61
66
|
};
|
|
62
67
|
export type HyperbookSectionFrontmatter = Omit<HyperbookPageFrontmatter, "navigation"> & {
|
|
63
68
|
virtual?: boolean;
|
|
64
69
|
expanded?: boolean;
|
|
65
70
|
navigation?: SectionNavigation;
|
|
66
71
|
};
|
|
67
|
-
export type
|
|
72
|
+
export type ProtectInheritance = {
|
|
73
|
+
/**
|
|
74
|
+
* True when this page's `protect` came from an ancestor section rather than
|
|
75
|
+
* from its own frontmatter.
|
|
76
|
+
*/
|
|
77
|
+
protectInherited?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* href of the page or section whose frontmatter declared the protection.
|
|
80
|
+
*
|
|
81
|
+
* Everything that resolves to the same source shares one unlock, so entering
|
|
82
|
+
* a section's password opens the whole section rather than every page asking
|
|
83
|
+
* again for the same thing.
|
|
84
|
+
*/
|
|
85
|
+
protectSource?: string;
|
|
86
|
+
};
|
|
87
|
+
export type HyperbookPage = HyperbookPageFrontmatter & ProtectInheritance & {
|
|
68
88
|
isEmpty?: boolean;
|
|
69
89
|
href?: string;
|
|
70
90
|
path?: {
|
|
@@ -76,7 +96,7 @@ export type HyperbookPage = HyperbookPageFrontmatter & {
|
|
|
76
96
|
};
|
|
77
97
|
repo?: string;
|
|
78
98
|
};
|
|
79
|
-
export type HyperbookSection = HyperbookSectionFrontmatter & {
|
|
99
|
+
export type HyperbookSection = HyperbookSectionFrontmatter & ProtectInheritance & {
|
|
80
100
|
isEmpty?: boolean;
|
|
81
101
|
href?: string;
|
|
82
102
|
pages: HyperbookPage[];
|
|
@@ -84,6 +104,56 @@ export type HyperbookSection = HyperbookSectionFrontmatter & {
|
|
|
84
104
|
repo?: string;
|
|
85
105
|
};
|
|
86
106
|
export type HyperbookFrontmatter = HyperbookPageFrontmatter | HyperbookSectionFrontmatter;
|
|
107
|
+
/**
|
|
108
|
+
* How protected content is stored in the built HTML.
|
|
109
|
+
*
|
|
110
|
+
* - "encrypt": AES-256-GCM, key derived from the password with PBKDF2. The
|
|
111
|
+
* plaintext never leaves the build. Needs `crypto.subtle`, which browsers
|
|
112
|
+
* only expose in secure contexts (https or localhost).
|
|
113
|
+
* - "obfuscate": the legacy behaviour — content and password both ship in the
|
|
114
|
+
* page. Provides no protection, but works from `file://`.
|
|
115
|
+
*/
|
|
116
|
+
export type ProtectMode = "encrypt" | "obfuscate";
|
|
117
|
+
export type ProtectConfig = {
|
|
118
|
+
/** Defaults to "encrypt". */
|
|
119
|
+
mode?: ProtectMode;
|
|
120
|
+
/** PBKDF2 iterations. Defaults to 250000. */
|
|
121
|
+
iterations?: number;
|
|
122
|
+
/** Registry location, relative to the book root. Defaults to "passwords.json". */
|
|
123
|
+
passwordsFile?: string;
|
|
124
|
+
};
|
|
125
|
+
/** One named password in the registry. */
|
|
126
|
+
export type PasswordEntry = {
|
|
127
|
+
value: string;
|
|
128
|
+
/** Label shown by `hyperbook passwords` and the passwordlist directive. */
|
|
129
|
+
name?: string;
|
|
130
|
+
description?: string;
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Contents of passwords.json.
|
|
134
|
+
*
|
|
135
|
+
* Keep this file out of version control if the book is public — it holds the
|
|
136
|
+
* actual passwords. Values can also come from the environment; see the
|
|
137
|
+
* `hyperbook passwords` documentation.
|
|
138
|
+
*/
|
|
139
|
+
export type PasswordsJson = {
|
|
140
|
+
$schema?: string;
|
|
141
|
+
/** The bare string form is shorthand for `{ "value": "..." }`. */
|
|
142
|
+
passwords: {
|
|
143
|
+
[key: string]: PasswordEntry | string;
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* A password reference on a page or section, or on a `:::protect` directive.
|
|
148
|
+
* The string form is a registry key.
|
|
149
|
+
*/
|
|
150
|
+
export type ProtectReference = string | {
|
|
151
|
+
/** Key in the password registry. */
|
|
152
|
+
use?: string;
|
|
153
|
+
/** Literal password, for books that do not use a registry. */
|
|
154
|
+
password?: string;
|
|
155
|
+
description?: string;
|
|
156
|
+
};
|
|
87
157
|
export type HyperbookJson = {
|
|
88
158
|
name: string;
|
|
89
159
|
description?: string;
|
|
@@ -95,6 +165,11 @@ export type HyperbookJson = {
|
|
|
95
165
|
qrcode?: boolean;
|
|
96
166
|
toc?: boolean;
|
|
97
167
|
llms?: boolean;
|
|
168
|
+
/**
|
|
169
|
+
* Password protection behaviour. Passwords themselves live in a separate
|
|
170
|
+
* registry file so this one can stay committed.
|
|
171
|
+
*/
|
|
172
|
+
protect?: ProtectConfig;
|
|
98
173
|
breadcrumb?: boolean | BreadcrumbConfig;
|
|
99
174
|
author?: {
|
|
100
175
|
name?: string;
|
|
@@ -213,6 +288,14 @@ export interface HyperbookContext {
|
|
|
213
288
|
versioned?: boolean;
|
|
214
289
|
}): string;
|
|
215
290
|
navigation: Navigation;
|
|
291
|
+
/**
|
|
292
|
+
* Resolved password registry.
|
|
293
|
+
*
|
|
294
|
+
* Deliberately kept off `config`: the config object is serialized into the
|
|
295
|
+
* page in several places, and a password that reaches it would be published.
|
|
296
|
+
* Only the protect plugins may read this.
|
|
297
|
+
*/
|
|
298
|
+
passwords?: Record<string, PasswordEntry>;
|
|
216
299
|
/**
|
|
217
300
|
* Collects absolute paths of files inlined into the page while it is being
|
|
218
301
|
* processed, so the dev server can rebuild exactly the pages that used them.
|
|
@@ -220,6 +303,25 @@ export interface HyperbookContext {
|
|
|
220
303
|
*/
|
|
221
304
|
dependencies?: Set<string>;
|
|
222
305
|
}
|
|
306
|
+
/** One entry of a navigation level, either a page or a section. */
|
|
307
|
+
export type NavigationEntry = {
|
|
308
|
+
type: "page";
|
|
309
|
+
page: HyperbookPage;
|
|
310
|
+
} | {
|
|
311
|
+
type: "section";
|
|
312
|
+
section: HyperbookSection;
|
|
313
|
+
};
|
|
314
|
+
/**
|
|
315
|
+
* Brings the pages and the sections of one navigation level into a single
|
|
316
|
+
* order. `index` decides, across both of them, so a section can sit between
|
|
317
|
+
* two pages. Entries without an `index` fall back to pages before sections,
|
|
318
|
+
* and entries that end up equal are ordered by name.
|
|
319
|
+
*
|
|
320
|
+
* Both lists are expected to be in order already, which is what reading a
|
|
321
|
+
* hyperbook gives. They are merged rather than sorted, so the order a caller
|
|
322
|
+
* built stays intact and only the two lists are woven together.
|
|
323
|
+
*/
|
|
324
|
+
export declare const sortNavigation: (pages: HyperbookPage[], sections: HyperbookSection[]) => NavigationEntry[];
|
|
223
325
|
/**
|
|
224
326
|
* Checks whether a path is an absolute URL and therefore must be passed
|
|
225
327
|
* through untouched by `makeUrl`, instead of being resolved against the
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,45 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
+
var FALLBACK_INDEX_PAGE = 9999;
|
|
3
|
+
var FALLBACK_INDEX_SECTION = 1e4;
|
|
4
|
+
var isShownAsPage = (section) => section.navigation === "page";
|
|
5
|
+
var sortNavigation = (pages, sections) => {
|
|
6
|
+
const pageKey = (page) => ({
|
|
7
|
+
index: page.index ?? FALLBACK_INDEX_PAGE,
|
|
8
|
+
kind: 0,
|
|
9
|
+
name: page.name
|
|
10
|
+
});
|
|
11
|
+
const sectionKey = (section) => ({
|
|
12
|
+
index: section.index ?? (isShownAsPage(section) ? FALLBACK_INDEX_PAGE : FALLBACK_INDEX_SECTION),
|
|
13
|
+
kind: isShownAsPage(section) ? 0 : 1,
|
|
14
|
+
name: section.name
|
|
15
|
+
});
|
|
16
|
+
const entries = [];
|
|
17
|
+
let p = 0;
|
|
18
|
+
let s = 0;
|
|
19
|
+
while (p < pages.length || s < sections.length) {
|
|
20
|
+
if (s >= sections.length) {
|
|
21
|
+
entries.push({ type: "page", page: pages[p++] });
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (p >= pages.length) {
|
|
25
|
+
entries.push({ type: "section", section: sections[s++] });
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
const page = pageKey(pages[p]);
|
|
29
|
+
const section = sectionKey(sections[s]);
|
|
30
|
+
const takePage = page.index !== section.index ? page.index < section.index : page.kind !== section.kind ? page.kind < section.kind : page.name <= section.name;
|
|
31
|
+
if (takePage) {
|
|
32
|
+
entries.push({ type: "page", page: pages[p++] });
|
|
33
|
+
} else {
|
|
34
|
+
entries.push({ type: "section", section: sections[s++] });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return entries;
|
|
38
|
+
};
|
|
2
39
|
var URL_SCHEME = /^[a-zA-Z][a-zA-Z0-9+.-]*:/;
|
|
3
40
|
var isExternalUrl = (path) => URL_SCHEME.test(path);
|
|
4
41
|
export {
|
|
5
|
-
isExternalUrl
|
|
42
|
+
isExternalUrl,
|
|
43
|
+
sortNavigation
|
|
6
44
|
};
|
|
7
45
|
//# sourceMappingURL=index.js.map
|
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\nexport type HyperbookSectionFrontmatter = Omit<\n HyperbookPageFrontmatter,\n \"navigation\"\n> & {\n virtual?: boolean;\n expanded?: boolean;\n navigation?: SectionNavigation;\n};\n\nexport type HyperbookPage = HyperbookPageFrontmatter & {\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 isEmpty?: boolean;\n href?: string;\n pages: HyperbookPage[];\n sections: HyperbookSection[];\n repo?: string;\n};\n\nexport type HyperbookFrontmatter =\n | HyperbookPageFrontmatter\n | HyperbookSectionFrontmatter;\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 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 };\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 * 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/**\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": ";
|
|
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 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 };\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": ";AA0WA,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
|
}
|