@hyperbook/types 0.23.1 → 0.24.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
@@ -169,6 +169,16 @@ export type HyperbookJson = {
169
169
  db?: string;
170
170
  height?: string | number;
171
171
  };
172
+ emoji?: ElementConfig & {
173
+ /**
174
+ * How emojis are rendered.
175
+ * - "native": Emojis are kept as text and drawn with the emoji font of
176
+ * the reader's operating system (default).
177
+ * - "twemoji": Emojis are replaced with Twemoji images, so they look the
178
+ * same on every platform.
179
+ */
180
+ style?: "native" | "twemoji";
181
+ };
172
182
  };
173
183
  };
174
184
  export type LanguageString = Partial<Record<Language, string>>;
@@ -210,4 +220,29 @@ export interface HyperbookContext {
210
220
  */
211
221
  dependencies?: Set<string>;
212
222
  }
223
+ /** One entry of a navigation level, either a page or a section. */
224
+ export type NavigationEntry = {
225
+ type: "page";
226
+ page: HyperbookPage;
227
+ } | {
228
+ type: "section";
229
+ section: HyperbookSection;
230
+ };
231
+ /**
232
+ * Brings the pages and the sections of one navigation level into a single
233
+ * order. `index` decides, across both of them, so a section can sit between
234
+ * two pages. Entries without an `index` fall back to pages before sections,
235
+ * and entries that end up equal are ordered by name.
236
+ *
237
+ * Both lists are expected to be in order already, which is what reading a
238
+ * hyperbook gives. They are merged rather than sorted, so the order a caller
239
+ * built stays intact and only the two lists are woven together.
240
+ */
241
+ export declare const sortNavigation: (pages: HyperbookPage[], sections: HyperbookSection[]) => NavigationEntry[];
242
+ /**
243
+ * Checks whether a path is an absolute URL and therefore must be passed
244
+ * through untouched by `makeUrl`, instead of being resolved against the
245
+ * hyperbook's base path.
246
+ */
247
+ export declare const isExternalUrl: (path: string) => boolean;
213
248
  export {};
package/dist/index.js CHANGED
@@ -1 +1,45 @@
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
+ };
39
+ var URL_SCHEME = /^[a-zA-Z][a-zA-Z0-9+.-]*:/;
40
+ var isExternalUrl = (path) => URL_SCHEME.test(path);
41
+ export {
42
+ isExternalUrl,
43
+ sortNavigation
44
+ };
1
45
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": [],
4
- "sourcesContent": [],
5
- "mappings": "",
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/** 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": ";AA+QA,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.23.1",
3
+ "version": "0.24.0",
4
4
  "author": "Mike Barkmin",
5
5
  "homepage": "https://github.com/openpatch/hyperbook#readme",
6
6
  "license": "MIT",