@tdacorp/hyle-sdk 0.21.0 → 0.22.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +110 -18
- package/dist/check-routes-bin.js +154 -42
- package/dist/{chunk-X2TLYM7Y.js → chunk-7T5EEJHK.js} +1 -1
- package/dist/chunk-DUPT6XLB.js +57 -0
- package/dist/{chunk-56Y24XBV.js → chunk-IW3TUD4G.js} +4 -3
- package/dist/{chunk-75JFLML4.js → chunk-KU7LWK4E.js} +75 -12
- package/dist/{chunk-K5VDLROQ.js → chunk-SFFBZFEN.js} +34 -1
- package/dist/{chunk-HJX57NLI.js → chunk-ZIW6FDU2.js} +246 -225
- package/dist/{client-LwzHwqpM.d.ts → client-BGjmEWhN.d.cts} +7 -1
- package/dist/{client-41fU6OY2.d.cts → client-D0LTpr3Y.d.ts} +7 -1
- package/dist/code-copy.cjs +4 -2
- package/dist/code-copy.d.cts +5 -2
- package/dist/code-copy.d.ts +5 -2
- package/dist/code-copy.js +5 -3
- package/dist/comments.cjs +11 -6
- package/dist/comments.js +11 -6
- package/dist/docs-enhance.cjs +7 -4
- package/dist/docs-enhance.d.cts +5 -3
- package/dist/docs-enhance.d.ts +5 -3
- package/dist/docs-enhance.js +8 -5
- package/dist/{embed-BUFRQboD.d.ts → embed-CbtsbZs3.d.cts} +4 -2
- package/dist/{embed-CYt-q13P.d.cts → embed-Cf_2ZR5x.d.ts} +4 -2
- package/dist/html.cjs +11 -6
- package/dist/html.d.cts +1 -1
- package/dist/html.d.ts +1 -1
- package/dist/html.js +2 -2
- package/dist/index.cjs +65 -12
- package/dist/index.d.cts +13 -11
- package/dist/index.d.ts +13 -11
- package/dist/index.js +2 -2
- package/dist/mermaid-diagram.cjs +46 -6
- package/dist/mermaid-diagram.js +15 -6
- package/dist/mermaid-image.cjs +4 -1
- package/dist/mermaid-image.js +1 -1
- package/dist/next.cjs +410 -241
- package/dist/next.d.cts +39 -17
- package/dist/next.d.ts +39 -17
- package/dist/next.js +116 -32
- package/dist/print-coordinator.js +1 -1
- package/dist/react.cjs +230 -197
- package/dist/react.d.cts +17 -6
- package/dist/react.d.ts +17 -6
- package/dist/react.js +5 -3
- package/dist/{resolve-eI1muCKL.d.cts → resolve-BnIv7aB7.d.cts} +1 -1
- package/dist/{resolve-BjAK0k_Y.d.ts → resolve-BysHtZ_i.d.ts} +1 -1
- package/dist/{sanitize-ijiWjEm9.d.cts → sanitize-BpY_AdZh.d.cts} +1 -1
- package/dist/{sanitize-ijiWjEm9.d.ts → sanitize-BpY_AdZh.d.ts} +1 -1
- package/dist/styles.css +4 -4
- package/dist/toc-spy.cjs +2 -1
- package/dist/toc-spy.js +2 -1
- package/dist/{types-3F0wqD-o.d.cts → types-D09Z072G.d.cts} +32 -1
- package/dist/{types-3F0wqD-o.d.ts → types-D09Z072G.d.ts} +32 -1
- package/dist/use-cache.cjs +53 -3
- package/dist/use-cache.d.cts +3 -3
- package/dist/use-cache.d.ts +3 -3
- package/dist/use-cache.js +3 -3
- package/package.json +3 -3
- package/dist/chunk-67IOIAVW.js +0 -35
package/dist/react.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactElement, ReactNode } from 'react';
|
|
3
|
-
import { H as HyleComponents, P as PageBaseProps, E as EngagementConfig, J as JsonLdConfig } from './embed-
|
|
4
|
-
export { A as ArticleRef, C as CalloutKind, d as CalloutProps, e as CodeBlockProps, b as EmbedHeading, f as HyleArticleView, g as HyleArticleViewProps, h as HyleListView, i as HyleListViewProps, a as HyleSlots, I as ImageProps, L as LinkProps, j as ListItemProps, M as MermaidProps, O as OgImage } from './embed-
|
|
5
|
-
export { H as HastLimitError, i as isSafeUrl, s as sanitizeHast, a as scopeId } from './sanitize-
|
|
6
|
-
import { j as ResolvedArticle, L as ListItem,
|
|
3
|
+
import { H as HyleComponents, P as PageBaseProps, E as EngagementConfig, J as JsonLdConfig } from './embed-CbtsbZs3.cjs';
|
|
4
|
+
export { A as ArticleRef, C as CalloutKind, d as CalloutProps, e as CodeBlockProps, b as EmbedHeading, f as HyleArticleView, g as HyleArticleViewProps, h as HyleListView, i as HyleListViewProps, a as HyleSlots, I as ImageProps, L as LinkProps, j as ListItemProps, M as MermaidProps, O as OgImage } from './embed-CbtsbZs3.cjs';
|
|
5
|
+
export { H as HastLimitError, i as isSafeUrl, s as sanitizeHast, a as scopeId } from './sanitize-BpY_AdZh.cjs';
|
|
6
|
+
import { j as ResolvedArticle, L as ListItem, o as TocEntry, l as ResolvedList, c as EngageListing, T as ThemeRef } from './types-D09Z072G.cjs';
|
|
7
7
|
import 'hast';
|
|
8
8
|
|
|
9
9
|
interface HastContentProps {
|
|
@@ -11,7 +11,7 @@ interface HastContentProps {
|
|
|
11
11
|
tree: unknown;
|
|
12
12
|
/** The page title; a leading body h1 that repeats it is dropped. */
|
|
13
13
|
title?: string;
|
|
14
|
-
/** The page description; a leading body paragraph that
|
|
14
|
+
/** The page description; a leading body paragraph that is exactly it is dropped. */
|
|
15
15
|
description?: string | null;
|
|
16
16
|
components?: HyleComponents;
|
|
17
17
|
locale?: string;
|
|
@@ -421,4 +421,15 @@ declare function HyleReactions(props: HyleReactionsProps): ReactElement;
|
|
|
421
421
|
|
|
422
422
|
declare function DocsPage({ article, ...base }: ArticlePageProps): ReactElement;
|
|
423
423
|
|
|
424
|
-
|
|
424
|
+
/**
|
|
425
|
+
* Links a themed workspace's stylesheet (hyle ADR 0036) from the host's own asset route (`createAssetRoute`), so a strict
|
|
426
|
+
* `style-src 'self'` and `font-src 'self'` CSP is enough. `precedence` makes React 19 put the link in the head and hold the
|
|
427
|
+
* paint until it has loaded, so there is no flash of the default theme. The URL is built from the scope and the hash alone,
|
|
428
|
+
* both checked as hex: nothing else hyle sends can become a stylesheet address. Renders nothing without a theme. The SDK's pages and embeds render it; a host
|
|
429
|
+
* that renders `HyleBody` itself passes the answer's `theme`.
|
|
430
|
+
*/
|
|
431
|
+
declare function HyleTheme({ theme }: {
|
|
432
|
+
theme?: ThemeRef | undefined;
|
|
433
|
+
}): ReactElement | null;
|
|
434
|
+
|
|
435
|
+
export { ArticlePage, type ArticlePageProps, Comments, type CommentsProps, DocsPage, EngagementConfig, HastContent, type HastContentProps, HyleBody, type HyleBodyProps, HyleComponents, HyleReactions, type HyleReactionsProps, HyleTheme, HyleToc, type HyleTocProps, JsonLdConfig, ListPage, type ListPageProps, MermaidDiagram, type MermaidDiagramProps, NotFound, type NotFoundProps, PageBaseProps, Redirecting, type RedirectingProps, type Strings, TrustedServerHtml, Unavailable, VIEWER_LABELS_EN, type ViewerLabels, holdPrintUntil, installPrintShortcut, isClampedSource, isLargeDiagram, stringsFor, stripMermaidConfig };
|
package/dist/react.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactElement, ReactNode } from 'react';
|
|
3
|
-
import { H as HyleComponents, P as PageBaseProps, E as EngagementConfig, J as JsonLdConfig } from './embed-
|
|
4
|
-
export { A as ArticleRef, C as CalloutKind, d as CalloutProps, e as CodeBlockProps, b as EmbedHeading, f as HyleArticleView, g as HyleArticleViewProps, h as HyleListView, i as HyleListViewProps, a as HyleSlots, I as ImageProps, L as LinkProps, j as ListItemProps, M as MermaidProps, O as OgImage } from './embed-
|
|
5
|
-
export { H as HastLimitError, i as isSafeUrl, s as sanitizeHast, a as scopeId } from './sanitize-
|
|
6
|
-
import { j as ResolvedArticle, L as ListItem,
|
|
3
|
+
import { H as HyleComponents, P as PageBaseProps, E as EngagementConfig, J as JsonLdConfig } from './embed-Cf_2ZR5x.js';
|
|
4
|
+
export { A as ArticleRef, C as CalloutKind, d as CalloutProps, e as CodeBlockProps, b as EmbedHeading, f as HyleArticleView, g as HyleArticleViewProps, h as HyleListView, i as HyleListViewProps, a as HyleSlots, I as ImageProps, L as LinkProps, j as ListItemProps, M as MermaidProps, O as OgImage } from './embed-Cf_2ZR5x.js';
|
|
5
|
+
export { H as HastLimitError, i as isSafeUrl, s as sanitizeHast, a as scopeId } from './sanitize-BpY_AdZh.js';
|
|
6
|
+
import { j as ResolvedArticle, L as ListItem, o as TocEntry, l as ResolvedList, c as EngageListing, T as ThemeRef } from './types-D09Z072G.js';
|
|
7
7
|
import 'hast';
|
|
8
8
|
|
|
9
9
|
interface HastContentProps {
|
|
@@ -11,7 +11,7 @@ interface HastContentProps {
|
|
|
11
11
|
tree: unknown;
|
|
12
12
|
/** The page title; a leading body h1 that repeats it is dropped. */
|
|
13
13
|
title?: string;
|
|
14
|
-
/** The page description; a leading body paragraph that
|
|
14
|
+
/** The page description; a leading body paragraph that is exactly it is dropped. */
|
|
15
15
|
description?: string | null;
|
|
16
16
|
components?: HyleComponents;
|
|
17
17
|
locale?: string;
|
|
@@ -421,4 +421,15 @@ declare function HyleReactions(props: HyleReactionsProps): ReactElement;
|
|
|
421
421
|
|
|
422
422
|
declare function DocsPage({ article, ...base }: ArticlePageProps): ReactElement;
|
|
423
423
|
|
|
424
|
-
|
|
424
|
+
/**
|
|
425
|
+
* Links a themed workspace's stylesheet (hyle ADR 0036) from the host's own asset route (`createAssetRoute`), so a strict
|
|
426
|
+
* `style-src 'self'` and `font-src 'self'` CSP is enough. `precedence` makes React 19 put the link in the head and hold the
|
|
427
|
+
* paint until it has loaded, so there is no flash of the default theme. The URL is built from the scope and the hash alone,
|
|
428
|
+
* both checked as hex: nothing else hyle sends can become a stylesheet address. Renders nothing without a theme. The SDK's pages and embeds render it; a host
|
|
429
|
+
* that renders `HyleBody` itself passes the answer's `theme`.
|
|
430
|
+
*/
|
|
431
|
+
declare function HyleTheme({ theme }: {
|
|
432
|
+
theme?: ThemeRef | undefined;
|
|
433
|
+
}): ReactElement | null;
|
|
434
|
+
|
|
435
|
+
export { ArticlePage, type ArticlePageProps, Comments, type CommentsProps, DocsPage, EngagementConfig, HastContent, type HastContentProps, HyleBody, type HyleBodyProps, HyleComponents, HyleReactions, type HyleReactionsProps, HyleTheme, HyleToc, type HyleTocProps, JsonLdConfig, ListPage, type ListPageProps, MermaidDiagram, type MermaidDiagramProps, NotFound, type NotFoundProps, PageBaseProps, Redirecting, type RedirectingProps, type Strings, TrustedServerHtml, Unavailable, VIEWER_LABELS_EN, type ViewerLabels, holdPrintUntil, installPrintShortcut, isClampedSource, isLargeDiagram, stringsFor, stripMermaidConfig };
|
package/dist/react.js
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
HyleBody,
|
|
8
8
|
HyleListView,
|
|
9
9
|
HyleReactions,
|
|
10
|
+
HyleTheme,
|
|
10
11
|
HyleToc,
|
|
11
12
|
ListPage,
|
|
12
13
|
MermaidDiagram,
|
|
@@ -19,7 +20,7 @@ import {
|
|
|
19
20
|
isClampedSource,
|
|
20
21
|
isLargeDiagram,
|
|
21
22
|
stripMermaidConfig
|
|
22
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-ZIW6FDU2.js";
|
|
23
24
|
import {
|
|
24
25
|
HastLimitError,
|
|
25
26
|
VIEWER_LABELS_EN,
|
|
@@ -27,8 +28,8 @@ import {
|
|
|
27
28
|
sanitizeHast,
|
|
28
29
|
scopeId,
|
|
29
30
|
stringsFor
|
|
30
|
-
} from "./chunk-
|
|
31
|
-
import "./chunk-
|
|
31
|
+
} from "./chunk-IW3TUD4G.js";
|
|
32
|
+
import "./chunk-DUPT6XLB.js";
|
|
32
33
|
export {
|
|
33
34
|
ArticlePage,
|
|
34
35
|
Comments,
|
|
@@ -39,6 +40,7 @@ export {
|
|
|
39
40
|
HyleBody,
|
|
40
41
|
HyleListView,
|
|
41
42
|
HyleReactions,
|
|
43
|
+
HyleTheme,
|
|
42
44
|
HyleToc,
|
|
43
45
|
ListPage,
|
|
44
46
|
MermaidDiagram,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as Resolved } from './types-
|
|
1
|
+
import { i as Resolved } from './types-D09Z072G.cjs';
|
|
2
2
|
|
|
3
3
|
/** Resolves a site path to a result. The two built-in strategies are `fetchResolver` (default) and `cachedResolver` (`@tdacorp/hyle-sdk/next/use-cache`). */
|
|
4
4
|
type HyleResolver = (path: string, locale: string | undefined, limit?: number, cursor?: string, nav?: "tree", format?: "md") => Promise<Resolved>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as Resolved } from './types-
|
|
1
|
+
import { i as Resolved } from './types-D09Z072G.js';
|
|
2
2
|
|
|
3
3
|
/** Resolves a site path to a result. The two built-in strategies are `fetchResolver` (default) and `cachedResolver` (`@tdacorp/hyle-sdk/next/use-cache`). */
|
|
4
4
|
type HyleResolver = (path: string, locale: string | undefined, limit?: number, cursor?: string, nav?: "tree", format?: "md") => Promise<Resolved>;
|
|
@@ -15,7 +15,7 @@ declare const scopeId: (id: string) => string;
|
|
|
15
15
|
declare function isSafeUrl(value: unknown, kind: "href" | "src"): boolean;
|
|
16
16
|
/**
|
|
17
17
|
* @param title when the body opens with an h1 that repeats the page title, that h1 is dropped (the page renders the title itself).
|
|
18
|
-
* @param description when the first paragraph after that h1
|
|
18
|
+
* @param description when the first paragraph after that h1 is exactly it, the paragraph is dropped (the page renders the description itself; hyle derives it from that paragraph). A paragraph that says more, as under a description hyle cut at 300 characters, is kept whole. A paragraph with an embed link is never dropped: the description can be a bare video URL.
|
|
19
19
|
* @throws HastLimitError when the tree has more than 20,000 nodes or 512 KiB of text (hyle's own renderer caps).
|
|
20
20
|
*/
|
|
21
21
|
declare function sanitizeHast(tree: unknown, title?: string, description?: string | null): Root;
|
|
@@ -15,7 +15,7 @@ declare const scopeId: (id: string) => string;
|
|
|
15
15
|
declare function isSafeUrl(value: unknown, kind: "href" | "src"): boolean;
|
|
16
16
|
/**
|
|
17
17
|
* @param title when the body opens with an h1 that repeats the page title, that h1 is dropped (the page renders the title itself).
|
|
18
|
-
* @param description when the first paragraph after that h1
|
|
18
|
+
* @param description when the first paragraph after that h1 is exactly it, the paragraph is dropped (the page renders the description itself; hyle derives it from that paragraph). A paragraph that says more, as under a description hyle cut at 300 characters, is kept whole. A paragraph with an embed link is never dropped: the description can be a bare video URL.
|
|
19
19
|
* @throws HastLimitError when the tree has more than 20,000 nodes or 512 KiB of text (hyle's own renderer caps).
|
|
20
20
|
*/
|
|
21
21
|
declare function sanitizeHast(tree: unknown, title?: string, description?: string | null): Root;
|
package/dist/styles.css
CHANGED
|
@@ -615,10 +615,10 @@ html.hyle-viewer-lock.hyle-viewer-fs{scrollbar-gutter:auto}
|
|
|
615
615
|
.hyle-cm-acts small{font-size:12px;color:var(--h-text-faint)}
|
|
616
616
|
.hyle-cm-depth{font-size:13px;color:var(--h-text-faint);padding:0 8px}
|
|
617
617
|
/* tombstones */
|
|
618
|
-
.hyle-cm[data-status="deleted"] .hyle-avatar,.hyle-cm[data-status="removed"] .hyle-avatar{background:transparent;border-style:dashed;color:var(--h-text-faint)}
|
|
619
|
-
.hyle-cm[data-status="deleted"] .hyle-cm-body,.hyle-cm[data-status="removed"] .hyle-cm-body{margin-top:0;font-style:italic;color:var(--h-text-muted)}
|
|
620
|
-
.hyle-cm[data-status="deleted"] .hyle-cm-by,.hyle-cm[data-status="removed"] .hyle-cm-by{display:none}
|
|
621
|
-
.hyle-cm[data-status="deleted"] .hyle-cm-main,.hyle-cm[data-status="removed"] .hyle-cm-main{align-self:center}
|
|
618
|
+
.hyle-cm[data-status="deleted"]>article .hyle-avatar,.hyle-cm[data-status="removed"]>article .hyle-avatar{background:transparent;border-style:dashed;color:var(--h-text-faint)}
|
|
619
|
+
.hyle-cm[data-status="deleted"]>article .hyle-cm-body,.hyle-cm[data-status="removed"]>article .hyle-cm-body{margin-top:0;font-style:italic;color:var(--h-text-muted)}
|
|
620
|
+
.hyle-cm[data-status="deleted"]>article .hyle-cm-by,.hyle-cm[data-status="removed"]>article .hyle-cm-by{display:none}
|
|
621
|
+
.hyle-cm[data-status="deleted"]>article .hyle-cm-main,.hyle-cm[data-status="removed"]>article .hyle-cm-main{align-self:center}
|
|
622
622
|
/* held for moderation (only its author sees it) */
|
|
623
623
|
.hyle-cm[data-status="held"]>article{padding:12px;margin-left:-12px;margin-right:-12px;border:1px dashed color-mix(in srgb,var(--hc-held) 55%,var(--h-border));border-radius:var(--h-radius);background:color-mix(in srgb,var(--hc-held) 7%,transparent)}
|
|
624
624
|
.hyle-cm-held{display:flex;align-items:center;gap:8px;margin-top:8px;font-size:13px;line-height:1.4;color:var(--h-text-muted)}
|
package/dist/toc-spy.cjs
CHANGED
|
@@ -33,7 +33,8 @@ function TocSpy({ ids }) {
|
|
|
33
33
|
const key = ids.join("\n");
|
|
34
34
|
(0, import_react.useEffect)(() => {
|
|
35
35
|
const links = Array.from(marker.current?.parentElement?.querySelectorAll(".hyle-toc-list a[href^='#']") ?? []);
|
|
36
|
-
const
|
|
36
|
+
const tree = marker.current?.getRootNode();
|
|
37
|
+
const headings = key.split("\n").map((id) => tree?.getElementById(id)).filter((h) => Boolean(h));
|
|
37
38
|
if (links.length === 0 || headings.length === 0 || typeof IntersectionObserver !== "function") return;
|
|
38
39
|
const update = () => {
|
|
39
40
|
let active = headings[0];
|
package/dist/toc-spy.js
CHANGED
|
@@ -10,7 +10,8 @@ function TocSpy({ ids }) {
|
|
|
10
10
|
const key = ids.join("\n");
|
|
11
11
|
useEffect(() => {
|
|
12
12
|
const links = Array.from(marker.current?.parentElement?.querySelectorAll(".hyle-toc-list a[href^='#']") ?? []);
|
|
13
|
-
const
|
|
13
|
+
const tree = marker.current?.getRootNode();
|
|
14
|
+
const headings = key.split("\n").map((id) => tree?.getElementById(id)).filter((h) => Boolean(h));
|
|
14
15
|
if (links.length === 0 || headings.length === 0 || typeof IntersectionObserver !== "function") return;
|
|
15
16
|
const update = () => {
|
|
16
17
|
let active = headings[0];
|
|
@@ -68,6 +68,17 @@ interface DocumentMetaFields {
|
|
|
68
68
|
/** Words in the rendered prose (code, title and math excluded), counted by the server. Absent from an older server. */
|
|
69
69
|
readonly word_count?: number | null;
|
|
70
70
|
}
|
|
71
|
+
/** A themed workspace's stylesheet (hyle ADR 0036, docs/cp1-spec.md section 3.10.1). Render it with `<HyleTheme>`. */
|
|
72
|
+
interface ThemeRef {
|
|
73
|
+
/** sha256 (lowercase hex) of the stylesheet; it changes exactly when the stylesheet does. */
|
|
74
|
+
readonly hash: string;
|
|
75
|
+
/** Names the workspace without revealing it (16 hex); the same for every stylesheet that workspace ever has. */
|
|
76
|
+
readonly scope: string;
|
|
77
|
+
/** The stylesheet's path on hyle (server to server; a browser gets it from the host's asset route). */
|
|
78
|
+
readonly css: string;
|
|
79
|
+
/** Font files worth preloading, as `/assets/<uuid>.woff2`. */
|
|
80
|
+
readonly preload: readonly string[];
|
|
81
|
+
}
|
|
71
82
|
interface ResolvedArticle {
|
|
72
83
|
readonly cp: 1;
|
|
73
84
|
readonly kind: "article";
|
|
@@ -98,6 +109,8 @@ interface ResolvedArticle {
|
|
|
98
109
|
/** The workspace default locale; absent from an older server. */
|
|
99
110
|
readonly default_locale?: string;
|
|
100
111
|
readonly fallback?: Fallback;
|
|
112
|
+
/** Absent without a theme and from an older server. */
|
|
113
|
+
readonly theme?: ThemeRef;
|
|
101
114
|
readonly cache: CacheInfo;
|
|
102
115
|
}
|
|
103
116
|
interface ListItem extends DocumentMetaFields {
|
|
@@ -121,6 +134,8 @@ interface ResolvedList {
|
|
|
121
134
|
readonly items: readonly ListItem[];
|
|
122
135
|
readonly next_cursor: string | null;
|
|
123
136
|
readonly fallback?: Fallback;
|
|
137
|
+
/** Absent without a theme and from an older server. */
|
|
138
|
+
readonly theme?: ThemeRef;
|
|
124
139
|
readonly cache: CacheInfo;
|
|
125
140
|
}
|
|
126
141
|
interface ResolvedRedirect {
|
|
@@ -162,6 +177,8 @@ interface Mounts {
|
|
|
162
177
|
readonly supported_locales: readonly string[];
|
|
163
178
|
readonly mounts: readonly Mount[];
|
|
164
179
|
readonly reserved: readonly string[];
|
|
180
|
+
/** Absent without a theme and from an older server. */
|
|
181
|
+
readonly theme?: ThemeRef;
|
|
165
182
|
readonly cache: CacheInfo;
|
|
166
183
|
}
|
|
167
184
|
type MountsResult = Mounts | ResolvedDisabled;
|
|
@@ -245,5 +262,19 @@ interface EngageListing {
|
|
|
245
262
|
readonly my_reactions?: readonly ReactionKind[];
|
|
246
263
|
readonly mine_held?: readonly EngageHeldComment[];
|
|
247
264
|
}
|
|
265
|
+
/** The `data` of GET /cp1/read/_preview (docs/cp1-spec.md section 3.10.2), or why there is no draft to draw. */
|
|
266
|
+
type HylePreview =
|
|
267
|
+
/** `expires_at`: when the link stops working. The article's asset addresses carry the token. */
|
|
268
|
+
{
|
|
269
|
+
readonly kind: "preview";
|
|
270
|
+
readonly expires_at: string;
|
|
271
|
+
readonly article: ResolvedArticle;
|
|
272
|
+
}
|
|
273
|
+
/** A wrong, expired or foreign token (hyle does not say which), or a document that can no longer be previewed. */
|
|
274
|
+
| {
|
|
275
|
+
readonly kind: "notfound";
|
|
276
|
+
} | {
|
|
277
|
+
readonly kind: "disabled";
|
|
278
|
+
};
|
|
248
279
|
|
|
249
|
-
export type { Alternate as A, Breadcrumb as B, CacheInfo as C, DocumentMetaFields as D, EngageComment as E, Fallback as F, ListItem as L, Mount as M, NavItem as N, ReactionCounts as R,
|
|
280
|
+
export type { Alternate as A, Breadcrumb as B, CacheInfo as C, DocumentMetaFields as D, EngageComment as E, Fallback as F, HylePreview as H, ListItem as L, Mount as M, NavItem as N, ReactionCounts as R, ThemeRef as T, VoteValue as V, ArticleContent as a, EngageHeldComment as b, EngageListing as c, Mounts as d, MountsResult as e, NavNode as f, NavTree as g, ReactionKind as h, Resolved as i, ResolvedArticle as j, ResolvedDisabled as k, ResolvedList as l, ResolvedNotFound as m, ResolvedRedirect as n, TocEntry as o };
|
|
@@ -68,6 +68,17 @@ interface DocumentMetaFields {
|
|
|
68
68
|
/** Words in the rendered prose (code, title and math excluded), counted by the server. Absent from an older server. */
|
|
69
69
|
readonly word_count?: number | null;
|
|
70
70
|
}
|
|
71
|
+
/** A themed workspace's stylesheet (hyle ADR 0036, docs/cp1-spec.md section 3.10.1). Render it with `<HyleTheme>`. */
|
|
72
|
+
interface ThemeRef {
|
|
73
|
+
/** sha256 (lowercase hex) of the stylesheet; it changes exactly when the stylesheet does. */
|
|
74
|
+
readonly hash: string;
|
|
75
|
+
/** Names the workspace without revealing it (16 hex); the same for every stylesheet that workspace ever has. */
|
|
76
|
+
readonly scope: string;
|
|
77
|
+
/** The stylesheet's path on hyle (server to server; a browser gets it from the host's asset route). */
|
|
78
|
+
readonly css: string;
|
|
79
|
+
/** Font files worth preloading, as `/assets/<uuid>.woff2`. */
|
|
80
|
+
readonly preload: readonly string[];
|
|
81
|
+
}
|
|
71
82
|
interface ResolvedArticle {
|
|
72
83
|
readonly cp: 1;
|
|
73
84
|
readonly kind: "article";
|
|
@@ -98,6 +109,8 @@ interface ResolvedArticle {
|
|
|
98
109
|
/** The workspace default locale; absent from an older server. */
|
|
99
110
|
readonly default_locale?: string;
|
|
100
111
|
readonly fallback?: Fallback;
|
|
112
|
+
/** Absent without a theme and from an older server. */
|
|
113
|
+
readonly theme?: ThemeRef;
|
|
101
114
|
readonly cache: CacheInfo;
|
|
102
115
|
}
|
|
103
116
|
interface ListItem extends DocumentMetaFields {
|
|
@@ -121,6 +134,8 @@ interface ResolvedList {
|
|
|
121
134
|
readonly items: readonly ListItem[];
|
|
122
135
|
readonly next_cursor: string | null;
|
|
123
136
|
readonly fallback?: Fallback;
|
|
137
|
+
/** Absent without a theme and from an older server. */
|
|
138
|
+
readonly theme?: ThemeRef;
|
|
124
139
|
readonly cache: CacheInfo;
|
|
125
140
|
}
|
|
126
141
|
interface ResolvedRedirect {
|
|
@@ -162,6 +177,8 @@ interface Mounts {
|
|
|
162
177
|
readonly supported_locales: readonly string[];
|
|
163
178
|
readonly mounts: readonly Mount[];
|
|
164
179
|
readonly reserved: readonly string[];
|
|
180
|
+
/** Absent without a theme and from an older server. */
|
|
181
|
+
readonly theme?: ThemeRef;
|
|
165
182
|
readonly cache: CacheInfo;
|
|
166
183
|
}
|
|
167
184
|
type MountsResult = Mounts | ResolvedDisabled;
|
|
@@ -245,5 +262,19 @@ interface EngageListing {
|
|
|
245
262
|
readonly my_reactions?: readonly ReactionKind[];
|
|
246
263
|
readonly mine_held?: readonly EngageHeldComment[];
|
|
247
264
|
}
|
|
265
|
+
/** The `data` of GET /cp1/read/_preview (docs/cp1-spec.md section 3.10.2), or why there is no draft to draw. */
|
|
266
|
+
type HylePreview =
|
|
267
|
+
/** `expires_at`: when the link stops working. The article's asset addresses carry the token. */
|
|
268
|
+
{
|
|
269
|
+
readonly kind: "preview";
|
|
270
|
+
readonly expires_at: string;
|
|
271
|
+
readonly article: ResolvedArticle;
|
|
272
|
+
}
|
|
273
|
+
/** A wrong, expired or foreign token (hyle does not say which), or a document that can no longer be previewed. */
|
|
274
|
+
| {
|
|
275
|
+
readonly kind: "notfound";
|
|
276
|
+
} | {
|
|
277
|
+
readonly kind: "disabled";
|
|
278
|
+
};
|
|
248
279
|
|
|
249
|
-
export type { Alternate as A, Breadcrumb as B, CacheInfo as C, DocumentMetaFields as D, EngageComment as E, Fallback as F, ListItem as L, Mount as M, NavItem as N, ReactionCounts as R,
|
|
280
|
+
export type { Alternate as A, Breadcrumb as B, CacheInfo as C, DocumentMetaFields as D, EngageComment as E, Fallback as F, HylePreview as H, ListItem as L, Mount as M, NavItem as N, ReactionCounts as R, ThemeRef as T, VoteValue as V, ArticleContent as a, EngageHeldComment as b, EngageListing as c, Mounts as d, MountsResult as e, NavNode as f, NavTree as g, ReactionKind as h, Resolved as i, ResolvedArticle as j, ResolvedDisabled as k, ResolvedList as l, ResolvedNotFound as m, ResolvedRedirect as n, TocEntry as o };
|
package/dist/use-cache.cjs
CHANGED
|
@@ -27,9 +27,15 @@ var import_cache = require("next/cache");
|
|
|
27
27
|
|
|
28
28
|
// src/asset-path.ts
|
|
29
29
|
var UUID = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
|
|
30
|
-
var EXTENSIONS = "png|jpg|gif|webp|svg|pdf|mp4|webm|mp3|ogg";
|
|
30
|
+
var EXTENSIONS = "png|jpg|gif|webp|svg|pdf|mp4|webm|mp3|ogg|woff2";
|
|
31
31
|
var ASSET_FILE = new RegExp(`^${UUID}(?:\\.(?:${EXTENSIONS}))?$`);
|
|
32
|
-
var
|
|
32
|
+
var THEME_FONT = new RegExp(`^/assets/${UUID}\\.woff2$`);
|
|
33
|
+
var PREVIEW_TOKEN_SOURCE = "hyle_pv_[A-Za-z0-9_-]{43}";
|
|
34
|
+
var PREVIEW_TOKEN = new RegExp(`^${PREVIEW_TOKEN_SOURCE}$`);
|
|
35
|
+
var PREVIEW_HEADER = "cp-preview";
|
|
36
|
+
var PREVIEW_PARAM = "hyle_preview";
|
|
37
|
+
var PREVIEW_QUERY_SOURCE = `\\?${PREVIEW_PARAM}=${PREVIEW_TOKEN_SOURCE}`;
|
|
38
|
+
var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)(${PREVIEW_QUERY_SOURCE})?$`, "i");
|
|
33
39
|
|
|
34
40
|
// src/errors.ts
|
|
35
41
|
var Cp1ClientError = class extends Error {
|
|
@@ -47,6 +53,30 @@ var Cp1ClientError = class extends Error {
|
|
|
47
53
|
}
|
|
48
54
|
};
|
|
49
55
|
|
|
56
|
+
// src/preview.ts
|
|
57
|
+
var ASSET_PATH = /^\/assets\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}(?:\.[a-z0-9]+)?(?= |$)/i;
|
|
58
|
+
var ASSET_PROPERTIES = ["src", "dataLight", "dataDark"];
|
|
59
|
+
var MAX_DEPTH = 200;
|
|
60
|
+
function mapNode(node, mark, depth) {
|
|
61
|
+
if (typeof node !== "object" || node === null || depth > MAX_DEPTH) return node;
|
|
62
|
+
const { properties, children } = node;
|
|
63
|
+
const marked = properties && Object.fromEntries(ASSET_PROPERTIES.filter((name) => name in properties).map((name) => [name, mark(properties[name])]));
|
|
64
|
+
return {
|
|
65
|
+
...node,
|
|
66
|
+
...properties ? { properties: { ...properties, ...marked } } : {},
|
|
67
|
+
...Array.isArray(children) ? { children: children.map((child) => mapNode(child, mark, depth + 1)) } : {}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function withPreviewAssets(article, token) {
|
|
71
|
+
const mark = (value) => typeof value === "string" ? value.replace(ASSET_PATH, (path) => `${path}?${PREVIEW_PARAM}=${token}`) : value;
|
|
72
|
+
const { publication, content } = article;
|
|
73
|
+
return {
|
|
74
|
+
...article,
|
|
75
|
+
publication: publication.cover ? { ...publication, cover: { path: String(mark(publication.cover.path)) } } : publication,
|
|
76
|
+
content: content.format === "hast" ? { ...content, tree: mapNode(content.tree, mark, 0) } : content
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
50
80
|
// src/client.ts
|
|
51
81
|
var RENDERER_VERSION = "4";
|
|
52
82
|
function applyCredential(headers, credential, method, url) {
|
|
@@ -159,8 +189,20 @@ function createHyleClient(options) {
|
|
|
159
189
|
if (data?.cp === 1 && data.kind === "push_posts" && Array.isArray(data.posts) && typeof data.complete === "boolean") return data;
|
|
160
190
|
throw failure(reply);
|
|
161
191
|
}
|
|
192
|
+
async function preview(token) {
|
|
193
|
+
if (typeof token !== "string" || !PREVIEW_TOKEN.test(token)) return { kind: "notfound" };
|
|
194
|
+
const reply = await get("/cp1/read/_preview", new URLSearchParams(), { headers: { [PREVIEW_HEADER]: token }, cache: "no-store" });
|
|
195
|
+
if (reply.status === 404 && reply.parsed?.error?.code === "NOT_FOUND") return { kind: "notfound" };
|
|
196
|
+
const data = reply.parsed?.data;
|
|
197
|
+
if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
|
|
198
|
+
const article = data?.article;
|
|
199
|
+
if (data?.cp !== 1 || data.kind !== "preview" || typeof data.expires_at !== "string" || article?.kind !== "article" || article.content?.format !== "hast" || !article.publication) throw failure(reply);
|
|
200
|
+
return { kind: "preview", expires_at: data.expires_at, article: withPreviewAssets(article, token) };
|
|
201
|
+
}
|
|
162
202
|
async function asset(file, opts = {}) {
|
|
163
203
|
if (!ASSET_FILE.test(file)) throw new TypeError("asset file must be <uuid>[.<ext>]");
|
|
204
|
+
const { previewToken } = opts;
|
|
205
|
+
if (previewToken !== void 0 && !PREVIEW_TOKEN.test(previewToken)) throw new TypeError("previewToken is not a preview token");
|
|
164
206
|
const url = `${base}/cp1/read/assets/${file}`;
|
|
165
207
|
const headers = new Headers();
|
|
166
208
|
const applied = applyCredential(headers, options, "GET", url);
|
|
@@ -169,9 +211,17 @@ function createHyleClient(options) {
|
|
|
169
211
|
const value = opts.headers?.[name];
|
|
170
212
|
if (value) headers.set(name, value);
|
|
171
213
|
}
|
|
214
|
+
if (previewToken !== void 0) headers.set(PREVIEW_HEADER, previewToken);
|
|
215
|
+
return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS), ...previewToken === void 0 ? {} : { cache: "no-store" } });
|
|
216
|
+
}
|
|
217
|
+
async function theme(opts = {}) {
|
|
218
|
+
const url = `${base}/cp1/read/theme.css`;
|
|
219
|
+
const headers = new Headers();
|
|
220
|
+
const applied = applyCredential(headers, options, "GET", url);
|
|
221
|
+
if (applied) await applied;
|
|
172
222
|
return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS) });
|
|
173
223
|
}
|
|
174
|
-
return { resolve, mounts, pushPosts, asset };
|
|
224
|
+
return { resolve, mounts, pushPosts, preview, asset, theme };
|
|
175
225
|
}
|
|
176
226
|
|
|
177
227
|
// src/tag-validation.ts
|
package/dist/use-cache.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { H as HyleAuth } from './client-
|
|
2
|
-
import { H as HyleResolver } from './resolve-
|
|
3
|
-
import './types-
|
|
1
|
+
import { H as HyleAuth } from './client-BGjmEWhN.cjs';
|
|
2
|
+
import { H as HyleResolver } from './resolve-BnIv7aB7.cjs';
|
|
3
|
+
import './types-D09Z072G.cjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* The exact caching strategy: a `'use cache'` function that fetches, then tags its own entry with the tags the response
|
package/dist/use-cache.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { H as HyleAuth } from './client-
|
|
2
|
-
import { H as HyleResolver } from './resolve-
|
|
3
|
-
import './types-
|
|
1
|
+
import { H as HyleAuth } from './client-D0LTpr3Y.js';
|
|
2
|
+
import { H as HyleResolver } from './resolve-BysHtZ_i.js';
|
|
3
|
+
import './types-D09Z072G.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* The exact caching strategy: a `'use cache'` function that fetches, then tags its own entry with the tags the response
|
package/dist/use-cache.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DEFAULT_REVALIDATE
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-7T5EEJHK.js";
|
|
4
4
|
import {
|
|
5
5
|
createHyleClient,
|
|
6
6
|
isValidCacheTag
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
7
|
+
} from "./chunk-KU7LWK4E.js";
|
|
8
|
+
import "./chunk-DUPT6XLB.js";
|
|
9
9
|
|
|
10
10
|
// src/next/use-cache.ts
|
|
11
11
|
import { cacheLife, cacheTag } from "next/cache";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tdacorp/hyle-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.2",
|
|
4
4
|
"description": "hyle SDK: a typed client for hyle's resolve endpoint, a hast renderer for React, and a Next.js catch-all page with tag-based revalidation.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -114,8 +114,8 @@
|
|
|
114
114
|
"tsup": "^8.5.1",
|
|
115
115
|
"typescript": "^5.9.3",
|
|
116
116
|
"vitest": "^4.1.10",
|
|
117
|
-
"@hyle/content": "0.
|
|
118
|
-
"@hyle/renderer": "0.5.
|
|
117
|
+
"@hyle/content": "0.10.0",
|
|
118
|
+
"@hyle/renderer": "0.5.1"
|
|
119
119
|
},
|
|
120
120
|
"keywords": [
|
|
121
121
|
"hyle",
|
package/dist/chunk-67IOIAVW.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
// src/asset-path.ts
|
|
2
|
-
var ASSET_ROUTE_PREFIX = "/api/hyle/assets";
|
|
3
|
-
var ASSET_RESERVED_PATH = "/api/hyle/*";
|
|
4
|
-
var UUID = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
|
|
5
|
-
var EXTENSIONS = "png|jpg|gif|webp|svg|pdf|mp4|webm|mp3|ogg";
|
|
6
|
-
var ASSET_FILE = new RegExp(`^${UUID}(?:\\.(?:${EXTENSIONS}))?$`);
|
|
7
|
-
var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)$`, "i");
|
|
8
|
-
function hostAssetSrc(src) {
|
|
9
|
-
const file = HYLE_ASSET_URL.exec(src)?.[1];
|
|
10
|
-
return file ? `${ASSET_ROUTE_PREFIX}/${file.toLowerCase()}` : src;
|
|
11
|
-
}
|
|
12
|
-
function hostAssetHtml(html) {
|
|
13
|
-
return html.replace(new RegExp(`(\\ssrc=")(/assets/${UUID}(?:\\.(?:${EXTENSIONS}))?)(")`, "gi"), (_m, open, url, close) => `${open}${hostAssetSrc(url)}${close}`);
|
|
14
|
-
}
|
|
15
|
-
var ASSET_CONTENT_TYPES = /* @__PURE__ */ new Set([
|
|
16
|
-
"image/png",
|
|
17
|
-
"image/jpeg",
|
|
18
|
-
"image/gif",
|
|
19
|
-
"image/webp",
|
|
20
|
-
"image/svg+xml",
|
|
21
|
-
"application/pdf",
|
|
22
|
-
"video/mp4",
|
|
23
|
-
"video/webm",
|
|
24
|
-
"audio/mpeg",
|
|
25
|
-
"audio/ogg"
|
|
26
|
-
]);
|
|
27
|
-
|
|
28
|
-
export {
|
|
29
|
-
ASSET_ROUTE_PREFIX,
|
|
30
|
-
ASSET_RESERVED_PATH,
|
|
31
|
-
ASSET_FILE,
|
|
32
|
-
hostAssetSrc,
|
|
33
|
-
hostAssetHtml,
|
|
34
|
-
ASSET_CONTENT_TYPES
|
|
35
|
-
};
|