@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.
Files changed (58) hide show
  1. package/README.md +110 -18
  2. package/dist/check-routes-bin.js +154 -42
  3. package/dist/{chunk-X2TLYM7Y.js → chunk-7T5EEJHK.js} +1 -1
  4. package/dist/chunk-DUPT6XLB.js +57 -0
  5. package/dist/{chunk-56Y24XBV.js → chunk-IW3TUD4G.js} +4 -3
  6. package/dist/{chunk-75JFLML4.js → chunk-KU7LWK4E.js} +75 -12
  7. package/dist/{chunk-K5VDLROQ.js → chunk-SFFBZFEN.js} +34 -1
  8. package/dist/{chunk-HJX57NLI.js → chunk-ZIW6FDU2.js} +246 -225
  9. package/dist/{client-LwzHwqpM.d.ts → client-BGjmEWhN.d.cts} +7 -1
  10. package/dist/{client-41fU6OY2.d.cts → client-D0LTpr3Y.d.ts} +7 -1
  11. package/dist/code-copy.cjs +4 -2
  12. package/dist/code-copy.d.cts +5 -2
  13. package/dist/code-copy.d.ts +5 -2
  14. package/dist/code-copy.js +5 -3
  15. package/dist/comments.cjs +11 -6
  16. package/dist/comments.js +11 -6
  17. package/dist/docs-enhance.cjs +7 -4
  18. package/dist/docs-enhance.d.cts +5 -3
  19. package/dist/docs-enhance.d.ts +5 -3
  20. package/dist/docs-enhance.js +8 -5
  21. package/dist/{embed-BUFRQboD.d.ts → embed-CbtsbZs3.d.cts} +4 -2
  22. package/dist/{embed-CYt-q13P.d.cts → embed-Cf_2ZR5x.d.ts} +4 -2
  23. package/dist/html.cjs +11 -6
  24. package/dist/html.d.cts +1 -1
  25. package/dist/html.d.ts +1 -1
  26. package/dist/html.js +2 -2
  27. package/dist/index.cjs +65 -12
  28. package/dist/index.d.cts +13 -11
  29. package/dist/index.d.ts +13 -11
  30. package/dist/index.js +2 -2
  31. package/dist/mermaid-diagram.cjs +46 -6
  32. package/dist/mermaid-diagram.js +15 -6
  33. package/dist/mermaid-image.cjs +4 -1
  34. package/dist/mermaid-image.js +1 -1
  35. package/dist/next.cjs +410 -241
  36. package/dist/next.d.cts +39 -17
  37. package/dist/next.d.ts +39 -17
  38. package/dist/next.js +116 -32
  39. package/dist/print-coordinator.js +1 -1
  40. package/dist/react.cjs +230 -197
  41. package/dist/react.d.cts +17 -6
  42. package/dist/react.d.ts +17 -6
  43. package/dist/react.js +5 -3
  44. package/dist/{resolve-eI1muCKL.d.cts → resolve-BnIv7aB7.d.cts} +1 -1
  45. package/dist/{resolve-BjAK0k_Y.d.ts → resolve-BysHtZ_i.d.ts} +1 -1
  46. package/dist/{sanitize-ijiWjEm9.d.cts → sanitize-BpY_AdZh.d.cts} +1 -1
  47. package/dist/{sanitize-ijiWjEm9.d.ts → sanitize-BpY_AdZh.d.ts} +1 -1
  48. package/dist/styles.css +4 -4
  49. package/dist/toc-spy.cjs +2 -1
  50. package/dist/toc-spy.js +2 -1
  51. package/dist/{types-3F0wqD-o.d.cts → types-D09Z072G.d.cts} +32 -1
  52. package/dist/{types-3F0wqD-o.d.ts → types-D09Z072G.d.ts} +32 -1
  53. package/dist/use-cache.cjs +53 -3
  54. package/dist/use-cache.d.cts +3 -3
  55. package/dist/use-cache.d.ts +3 -3
  56. package/dist/use-cache.js +3 -3
  57. package/package.json +3 -3
  58. package/dist/chunk-67IOIAVW.js +0 -35
@@ -1,4 +1,4 @@
1
- import { i as Resolved, e as MountsResult } from './types-3F0wqD-o.js';
1
+ import { i as Resolved, e as MountsResult, H as HylePreview } from './types-D09Z072G.cjs';
2
2
 
3
3
  /** docs/cp1-spec.md section 5.3.3: `hyle.push/1`, the whole-post delivery of a path in push mode (ADR 0025). */
4
4
  declare const MAX_PUSH_BODY_BYTES: number;
@@ -185,6 +185,8 @@ interface AssetOptions {
185
185
  };
186
186
  /** Abort after this many milliseconds, body included. Default: the client's `timeoutMs`. */
187
187
  readonly timeoutMs?: number;
188
+ /** A draft preview's token (hyle ADR 0037): hyle then also serves the assets that draft names. The answer is never cached. */
189
+ readonly previewToken?: string;
188
190
  }
189
191
  declare function createHyleClient(options: HyleClientOptions): {
190
192
  resolve: (opts: ResolveOptions) => Promise<Resolved>;
@@ -194,7 +196,11 @@ declare function createHyleClient(options: HyleClientOptions): {
194
196
  readonly cursor?: string;
195
197
  readonly init?: HyleRequestInit;
196
198
  }) => Promise<PushPage>;
199
+ preview: (token: string | undefined) => Promise<HylePreview>;
197
200
  asset: (file: string, opts?: AssetOptions) => Promise<Response>;
201
+ theme: (opts?: {
202
+ readonly timeoutMs?: number;
203
+ }) => Promise<Response>;
198
204
  };
199
205
  type HyleClient = ReturnType<typeof createHyleClient>;
200
206
 
@@ -1,4 +1,4 @@
1
- import { i as Resolved, e as MountsResult } from './types-3F0wqD-o.cjs';
1
+ import { i as Resolved, e as MountsResult, H as HylePreview } from './types-D09Z072G.js';
2
2
 
3
3
  /** docs/cp1-spec.md section 5.3.3: `hyle.push/1`, the whole-post delivery of a path in push mode (ADR 0025). */
4
4
  declare const MAX_PUSH_BODY_BYTES: number;
@@ -185,6 +185,8 @@ interface AssetOptions {
185
185
  };
186
186
  /** Abort after this many milliseconds, body included. Default: the client's `timeoutMs`. */
187
187
  readonly timeoutMs?: number;
188
+ /** A draft preview's token (hyle ADR 0037): hyle then also serves the assets that draft names. The answer is never cached. */
189
+ readonly previewToken?: string;
188
190
  }
189
191
  declare function createHyleClient(options: HyleClientOptions): {
190
192
  resolve: (opts: ResolveOptions) => Promise<Resolved>;
@@ -194,7 +196,11 @@ declare function createHyleClient(options: HyleClientOptions): {
194
196
  readonly cursor?: string;
195
197
  readonly init?: HyleRequestInit;
196
198
  }) => Promise<PushPage>;
199
+ preview: (token: string | undefined) => Promise<HylePreview>;
197
200
  asset: (file: string, opts?: AssetOptions) => Promise<Response>;
201
+ theme: (opts?: {
202
+ readonly timeoutMs?: number;
203
+ }) => Promise<Response>;
198
204
  };
199
205
  type HyleClient = ReturnType<typeof createHyleClient>;
200
206
 
@@ -25,10 +25,12 @@ __export(code_copy_exports, {
25
25
  });
26
26
  module.exports = __toCommonJS(code_copy_exports);
27
27
  var import_react = require("react");
28
+ var import_jsx_runtime = require("react/jsx-runtime");
28
29
  var RESET_MS = 1500;
29
30
  function CodeCopy({ rootId, copyLabel, copiedLabel, blockedLabel }) {
31
+ const marker = (0, import_react.useRef)(null);
30
32
  (0, import_react.useEffect)(() => {
31
- const root = document.getElementById(rootId);
33
+ const root = marker.current?.getRootNode()?.getElementById(rootId);
32
34
  if (!root) return;
33
35
  const timers = /* @__PURE__ */ new Map();
34
36
  const show = (button, state) => {
@@ -64,7 +66,7 @@ function CodeCopy({ rootId, copyLabel, copiedLabel, blockedLabel }) {
64
66
  for (const timer of timers.values()) window.clearTimeout(timer);
65
67
  };
66
68
  }, [rootId, copyLabel, copiedLabel, blockedLabel]);
67
- return null;
69
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { ref: marker, hidden: true });
68
70
  }
69
71
  // Annotate the CommonJS export names for ESM import in node:
70
72
  0 && (module.exports = {
@@ -1,3 +1,5 @@
1
+ import { ReactElement } from 'react';
2
+
1
3
  interface CodeCopyProps {
2
4
  /** The `id` of the body whose code blocks this island serves. */
3
5
  rootId: string;
@@ -8,8 +10,9 @@ interface CodeCopyProps {
8
10
  /**
9
11
  * One delegated click listener for every `figure.hyle-codeblock` copy button under `rootId`: writes the block's code to the
10
12
  * clipboard, then shows and announces "copied" or "blocked" for a moment. A successful copy also dispatches a bubbling
11
- * `hyle:code-copied` event on the figure, for a host that counts copies. Renders nothing; the buttons are server HTML.
13
+ * `hyle:code-copied` event on the figure, for a host that counts copies. The buttons are server HTML; the one element it
14
+ * renders is a hidden marker, whose tree (the document or a shadow root) is where the body is looked up.
12
15
  */
13
- declare function CodeCopy({ rootId, copyLabel, copiedLabel, blockedLabel }: CodeCopyProps): null;
16
+ declare function CodeCopy({ rootId, copyLabel, copiedLabel, blockedLabel }: CodeCopyProps): ReactElement;
14
17
 
15
18
  export { CodeCopy, type CodeCopyProps };
@@ -1,3 +1,5 @@
1
+ import { ReactElement } from 'react';
2
+
1
3
  interface CodeCopyProps {
2
4
  /** The `id` of the body whose code blocks this island serves. */
3
5
  rootId: string;
@@ -8,8 +10,9 @@ interface CodeCopyProps {
8
10
  /**
9
11
  * One delegated click listener for every `figure.hyle-codeblock` copy button under `rootId`: writes the block's code to the
10
12
  * clipboard, then shows and announces "copied" or "blocked" for a moment. A successful copy also dispatches a bubbling
11
- * `hyle:code-copied` event on the figure, for a host that counts copies. Renders nothing; the buttons are server HTML.
13
+ * `hyle:code-copied` event on the figure, for a host that counts copies. The buttons are server HTML; the one element it
14
+ * renders is a hidden marker, whose tree (the document or a shadow root) is where the body is looked up.
12
15
  */
13
- declare function CodeCopy({ rootId, copyLabel, copiedLabel, blockedLabel }: CodeCopyProps): null;
16
+ declare function CodeCopy({ rootId, copyLabel, copiedLabel, blockedLabel }: CodeCopyProps): ReactElement;
14
17
 
15
18
  export { CodeCopy, type CodeCopyProps };
package/dist/code-copy.js CHANGED
@@ -1,11 +1,13 @@
1
1
  "use client";
2
2
 
3
3
  // src/react/code-copy.tsx
4
- import { useEffect } from "react";
4
+ import { useEffect, useRef } from "react";
5
+ import { jsx } from "react/jsx-runtime";
5
6
  var RESET_MS = 1500;
6
7
  function CodeCopy({ rootId, copyLabel, copiedLabel, blockedLabel }) {
8
+ const marker = useRef(null);
7
9
  useEffect(() => {
8
- const root = document.getElementById(rootId);
10
+ const root = marker.current?.getRootNode()?.getElementById(rootId);
9
11
  if (!root) return;
10
12
  const timers = /* @__PURE__ */ new Map();
11
13
  const show = (button, state) => {
@@ -41,7 +43,7 @@ function CodeCopy({ rootId, copyLabel, copiedLabel, blockedLabel }) {
41
43
  for (const timer of timers.values()) window.clearTimeout(timer);
42
44
  };
43
45
  }, [rootId, copyLabel, copiedLabel, blockedLabel]);
44
- return null;
46
+ return /* @__PURE__ */ jsx("span", { ref: marker, hidden: true });
45
47
  }
46
48
  export {
47
49
  CodeCopy
package/dist/comments.cjs CHANGED
@@ -362,12 +362,17 @@ var import_jsx_runtime = require("react/jsx-runtime");
362
362
  // src/asset-path.ts
363
363
  var ASSET_ROUTE_PREFIX = "/api/hyle/assets";
364
364
  var UUID = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
365
- var EXTENSIONS = "png|jpg|gif|webp|svg|pdf|mp4|webm|mp3|ogg";
365
+ var EXTENSIONS = "png|jpg|gif|webp|svg|pdf|mp4|webm|mp3|ogg|woff2";
366
366
  var ASSET_FILE = new RegExp(`^${UUID}(?:\\.(?:${EXTENSIONS}))?$`);
367
- var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)$`, "i");
367
+ var THEME_FONT = new RegExp(`^/assets/${UUID}\\.woff2$`);
368
+ var PREVIEW_TOKEN_SOURCE = "hyle_pv_[A-Za-z0-9_-]{43}";
369
+ var PREVIEW_TOKEN = new RegExp(`^${PREVIEW_TOKEN_SOURCE}$`);
370
+ var PREVIEW_PARAM = "hyle_preview";
371
+ var PREVIEW_QUERY_SOURCE = `\\?${PREVIEW_PARAM}=${PREVIEW_TOKEN_SOURCE}`;
372
+ var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)(${PREVIEW_QUERY_SOURCE})?$`, "i");
368
373
  function hostAssetSrc(src) {
369
- const file = HYLE_ASSET_URL.exec(src)?.[1];
370
- return file ? `${ASSET_ROUTE_PREFIX}/${file.toLowerCase()}` : src;
374
+ const [, file, query = ""] = HYLE_ASSET_URL.exec(src) ?? [];
375
+ return file ? `${ASSET_ROUTE_PREFIX}/${file.toLowerCase()}${query}` : src;
371
376
  }
372
377
 
373
378
  // src/react/sanitize.ts
@@ -441,7 +446,7 @@ var MERMAID_SRCDOC = new RegExp(
441
446
  `^<!doctype html><html><head><meta charset="utf-8"></head><body><div class="mermaid">([^<]*)</div><script src="${MERMAID_SCRIPT_URL.replace(/[.]/g, "\\.")}"></script><script>mermaid\\.initialize\\(\\{ startOnLoad: true, securityLevel: "strict" \\}\\);</script></body></html>$`
442
447
  );
443
448
  var isMermaidSrcdoc = (v) => typeof v === "string" && v.length <= MAX_SRCDOC && MERMAID_SRCDOC.test(v);
444
- var RENDER_REF = /^(\/assets\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\.svg) ([1-9]\d{0,5}) ([1-9]\d{0,5})$/;
449
+ var RENDER_REF = new RegExp(`^(/assets/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\\.svg(?:${PREVIEW_QUERY_SOURCE})?) ([1-9]\\d{0,5}) ([1-9]\\d{0,5})$`);
445
450
  var isRenderRef = matches(RENDER_REF);
446
451
  var YOUTUBE_WATCH = /^https:\/\/www\.youtube\.com\/watch\?v=([A-Za-z0-9_-]{11})$/;
447
452
  var youtubeId = (href) => typeof href === "string" ? YOUTUBE_WATCH.exec(href)?.[1] : void 0;
@@ -574,7 +579,7 @@ function sanitizeHast(tree, title, description) {
574
579
  const [first] = elements;
575
580
  const skip = title !== void 0 && isObject2(first) && first.tagName === "h1" && collapse(textOf(first)) === collapse(title) ? first : void 0;
576
581
  const lead = elements[skip ? 1 : 0];
577
- const repeat = description && isObject2(lead) && lead.tagName === "p" && collapse(textOf(lead)).startsWith(collapse(description)) && !holdsEmbed(lead) ? lead : void 0;
582
+ const repeat = description && isObject2(lead) && lead.tagName === "p" && collapse(textOf(lead)) === collapse(description) && !holdsEmbed(lead) ? lead : void 0;
578
583
  const budget = { nodes: 0, text: 0 };
579
584
  return { type: "root", children: raw.filter((n) => n !== skip && n !== repeat).flatMap((n) => clean(n, 0, { katex: false }, budget)) };
580
585
  }
package/dist/comments.js CHANGED
@@ -118,12 +118,17 @@ import { jsx, jsxs } from "react/jsx-runtime";
118
118
  // src/asset-path.ts
119
119
  var ASSET_ROUTE_PREFIX = "/api/hyle/assets";
120
120
  var UUID = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
121
- var EXTENSIONS = "png|jpg|gif|webp|svg|pdf|mp4|webm|mp3|ogg";
121
+ var EXTENSIONS = "png|jpg|gif|webp|svg|pdf|mp4|webm|mp3|ogg|woff2";
122
122
  var ASSET_FILE = new RegExp(`^${UUID}(?:\\.(?:${EXTENSIONS}))?$`);
123
- var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)$`, "i");
123
+ var THEME_FONT = new RegExp(`^/assets/${UUID}\\.woff2$`);
124
+ var PREVIEW_TOKEN_SOURCE = "hyle_pv_[A-Za-z0-9_-]{43}";
125
+ var PREVIEW_TOKEN = new RegExp(`^${PREVIEW_TOKEN_SOURCE}$`);
126
+ var PREVIEW_PARAM = "hyle_preview";
127
+ var PREVIEW_QUERY_SOURCE = `\\?${PREVIEW_PARAM}=${PREVIEW_TOKEN_SOURCE}`;
128
+ var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)(${PREVIEW_QUERY_SOURCE})?$`, "i");
124
129
  function hostAssetSrc(src) {
125
- const file = HYLE_ASSET_URL.exec(src)?.[1];
126
- return file ? `${ASSET_ROUTE_PREFIX}/${file.toLowerCase()}` : src;
130
+ const [, file, query = ""] = HYLE_ASSET_URL.exec(src) ?? [];
131
+ return file ? `${ASSET_ROUTE_PREFIX}/${file.toLowerCase()}${query}` : src;
127
132
  }
128
133
 
129
134
  // src/react/sanitize.ts
@@ -197,7 +202,7 @@ var MERMAID_SRCDOC = new RegExp(
197
202
  `^<!doctype html><html><head><meta charset="utf-8"></head><body><div class="mermaid">([^<]*)</div><script src="${MERMAID_SCRIPT_URL.replace(/[.]/g, "\\.")}"></script><script>mermaid\\.initialize\\(\\{ startOnLoad: true, securityLevel: "strict" \\}\\);</script></body></html>$`
198
203
  );
199
204
  var isMermaidSrcdoc = (v) => typeof v === "string" && v.length <= MAX_SRCDOC && MERMAID_SRCDOC.test(v);
200
- var RENDER_REF = /^(\/assets\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\.svg) ([1-9]\d{0,5}) ([1-9]\d{0,5})$/;
205
+ var RENDER_REF = new RegExp(`^(/assets/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\\.svg(?:${PREVIEW_QUERY_SOURCE})?) ([1-9]\\d{0,5}) ([1-9]\\d{0,5})$`);
201
206
  var isRenderRef = matches(RENDER_REF);
202
207
  var YOUTUBE_WATCH = /^https:\/\/www\.youtube\.com\/watch\?v=([A-Za-z0-9_-]{11})$/;
203
208
  var youtubeId = (href) => typeof href === "string" ? YOUTUBE_WATCH.exec(href)?.[1] : void 0;
@@ -330,7 +335,7 @@ function sanitizeHast(tree, title, description) {
330
335
  const [first] = elements;
331
336
  const skip = title !== void 0 && isObject2(first) && first.tagName === "h1" && collapse(textOf(first)) === collapse(title) ? first : void 0;
332
337
  const lead = elements[skip ? 1 : 0];
333
- const repeat = description && isObject2(lead) && lead.tagName === "p" && collapse(textOf(lead)).startsWith(collapse(description)) && !holdsEmbed(lead) ? lead : void 0;
338
+ const repeat = description && isObject2(lead) && lead.tagName === "p" && collapse(textOf(lead)) === collapse(description) && !holdsEmbed(lead) ? lead : void 0;
334
339
  const budget = { nodes: 0, text: 0 };
335
340
  return { type: "root", children: raw.filter((n) => n !== skip && n !== repeat).flatMap((n) => clean(n, 0, { katex: false }, budget)) };
336
341
  }
@@ -25,6 +25,7 @@ __export(docs_enhance_exports, {
25
25
  });
26
26
  module.exports = __toCommonJS(docs_enhance_exports);
27
27
  var import_react = require("react");
28
+ var import_jsx_runtime = require("react/jsx-runtime");
28
29
  var REACHED_SLACK = 24 + 8;
29
30
  function stickyTop(root) {
30
31
  return Number.parseFloat(getComputedStyle(root).getPropertyValue("--h-sticky-top")) || 0;
@@ -43,10 +44,12 @@ function revealCurrent(nav) {
43
44
  if (a.top < b.top || a.bottom > b.bottom) nav.scrollTop += a.top - b.top - b.height / 3;
44
45
  }
45
46
  function DocsEnhance({ headingIds, rootId }) {
47
+ const marker = (0, import_react.useRef)(null);
46
48
  const key = headingIds.join("\n");
47
49
  (0, import_react.useEffect)(() => {
48
- const root = document.getElementById(rootId);
49
- if (!root) return;
50
+ const tree = marker.current?.getRootNode();
51
+ const root = tree?.getElementById(rootId);
52
+ if (!tree || !root) return;
50
53
  const nav = root.querySelector(".hyle-nav-d");
51
54
  const cleanups = [];
52
55
  if (nav) {
@@ -67,7 +70,7 @@ function DocsEnhance({ headingIds, rootId }) {
67
70
  nav.addEventListener("click", onClick);
68
71
  cleanups.push(() => (nav.removeEventListener("toggle", onToggle), nav.removeEventListener("click", onClick)));
69
72
  }
70
- const headings = headingIds.map((id) => document.getElementById(id)).filter((h) => h !== null);
73
+ const headings = headingIds.map((id) => tree.getElementById(id)).filter((h) => h !== null);
71
74
  const end = root.querySelector(".hyle-docs-end");
72
75
  if (headings.length > 0 && typeof IntersectionObserver === "function") {
73
76
  let endVisible = false;
@@ -89,7 +92,7 @@ function DocsEnhance({ headingIds, rootId }) {
89
92
  }
90
93
  return () => cleanups.forEach((fn) => fn());
91
94
  }, [key, rootId]);
92
- return null;
95
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { ref: marker, hidden: true });
93
96
  }
94
97
  // Annotate the CommonJS export names for ESM import in node:
95
98
  0 && (module.exports = {
@@ -1,6 +1,8 @@
1
+ import { ReactElement } from 'react';
2
+
1
3
  /**
2
- * Progressive enhancement for DocsPage. It renders nothing and receives only the heading ids and the root element's id: the
3
- * page works without it (the tree is `<details>`, the drawer is a `popover`), and this adds three things, with no dependency:
4
+ * Progressive enhancement for DocsPage. It renders only a hidden marker (whose tree, the document or a shadow root, is where
5
+ * the ids are looked up) and receives only the heading ids and the root element's id: the page works without it (the tree is `<details>`, the drawer is a `popover`), and this adds three things, with no dependency:
4
6
  * scroll-spy for the on-page TOC (IntersectionObserver on the headings plus one on the end of the article, `aria-current="location"`
5
7
  * set on the DOM links so it never re-renders), the current page scrolled into view in the sidebar, and the drawer closing
6
8
  * when a link in it is followed (a client-side navigation does not reload the page, so the popover would stay open).
@@ -11,6 +13,6 @@ interface DocsEnhanceProps {
11
13
  /** The `id` of `.hyle-docs`. */
12
14
  rootId: string;
13
15
  }
14
- declare function DocsEnhance({ headingIds, rootId }: DocsEnhanceProps): null;
16
+ declare function DocsEnhance({ headingIds, rootId }: DocsEnhanceProps): ReactElement;
15
17
 
16
18
  export { DocsEnhance, type DocsEnhanceProps };
@@ -1,6 +1,8 @@
1
+ import { ReactElement } from 'react';
2
+
1
3
  /**
2
- * Progressive enhancement for DocsPage. It renders nothing and receives only the heading ids and the root element's id: the
3
- * page works without it (the tree is `<details>`, the drawer is a `popover`), and this adds three things, with no dependency:
4
+ * Progressive enhancement for DocsPage. It renders only a hidden marker (whose tree, the document or a shadow root, is where
5
+ * the ids are looked up) and receives only the heading ids and the root element's id: the page works without it (the tree is `<details>`, the drawer is a `popover`), and this adds three things, with no dependency:
4
6
  * scroll-spy for the on-page TOC (IntersectionObserver on the headings plus one on the end of the article, `aria-current="location"`
5
7
  * set on the DOM links so it never re-renders), the current page scrolled into view in the sidebar, and the drawer closing
6
8
  * when a link in it is followed (a client-side navigation does not reload the page, so the popover would stay open).
@@ -11,6 +13,6 @@ interface DocsEnhanceProps {
11
13
  /** The `id` of `.hyle-docs`. */
12
14
  rootId: string;
13
15
  }
14
- declare function DocsEnhance({ headingIds, rootId }: DocsEnhanceProps): null;
16
+ declare function DocsEnhance({ headingIds, rootId }: DocsEnhanceProps): ReactElement;
15
17
 
16
18
  export { DocsEnhance, type DocsEnhanceProps };
@@ -1,7 +1,8 @@
1
1
  "use client";
2
2
 
3
3
  // src/react/docs-enhance.tsx
4
- import { useEffect } from "react";
4
+ import { useEffect, useRef } from "react";
5
+ import { jsx } from "react/jsx-runtime";
5
6
  var REACHED_SLACK = 24 + 8;
6
7
  function stickyTop(root) {
7
8
  return Number.parseFloat(getComputedStyle(root).getPropertyValue("--h-sticky-top")) || 0;
@@ -20,10 +21,12 @@ function revealCurrent(nav) {
20
21
  if (a.top < b.top || a.bottom > b.bottom) nav.scrollTop += a.top - b.top - b.height / 3;
21
22
  }
22
23
  function DocsEnhance({ headingIds, rootId }) {
24
+ const marker = useRef(null);
23
25
  const key = headingIds.join("\n");
24
26
  useEffect(() => {
25
- const root = document.getElementById(rootId);
26
- if (!root) return;
27
+ const tree = marker.current?.getRootNode();
28
+ const root = tree?.getElementById(rootId);
29
+ if (!tree || !root) return;
27
30
  const nav = root.querySelector(".hyle-nav-d");
28
31
  const cleanups = [];
29
32
  if (nav) {
@@ -44,7 +47,7 @@ function DocsEnhance({ headingIds, rootId }) {
44
47
  nav.addEventListener("click", onClick);
45
48
  cleanups.push(() => (nav.removeEventListener("toggle", onToggle), nav.removeEventListener("click", onClick)));
46
49
  }
47
- const headings = headingIds.map((id) => document.getElementById(id)).filter((h) => h !== null);
50
+ const headings = headingIds.map((id) => tree.getElementById(id)).filter((h) => h !== null);
48
51
  const end = root.querySelector(".hyle-docs-end");
49
52
  if (headings.length > 0 && typeof IntersectionObserver === "function") {
50
53
  let endVisible = false;
@@ -66,7 +69,7 @@ function DocsEnhance({ headingIds, rootId }) {
66
69
  }
67
70
  return () => cleanups.forEach((fn) => fn());
68
71
  }, [key, rootId]);
69
- return null;
72
+ return /* @__PURE__ */ jsx("span", { ref: marker, hidden: true });
70
73
  }
71
74
  export {
72
75
  DocsEnhance
@@ -1,5 +1,5 @@
1
1
  import { ElementType, ReactNode, ComponentType, ReactElement } from 'react';
2
- import { j as ResolvedArticle, L as ListItem } from './types-3F0wqD-o.js';
2
+ import { j as ResolvedArticle, L as ListItem, T as ThemeRef } from './types-D09Z072G.cjs';
3
3
 
4
4
  type CalloutKind = "note" | "tip" | "important" | "warning" | "caution";
5
5
  interface LinkProps {
@@ -160,9 +160,11 @@ interface HyleListViewProps extends PageBaseProps {
160
160
  readonly moreHref?: string | undefined;
161
161
  /** Where "Older posts" goes (built from the list's `next_cursor`); omit to hide it. */
162
162
  readonly olderHref?: string | undefined;
163
+ /** The list answer's `theme`, so an embedded list is styled like the workspace's pages. */
164
+ readonly theme?: ThemeRef | undefined;
163
165
  }
164
166
  /** Items link to `toHref(canonical_path)`: plain anchors in a flat list, newest first as hyle sent them, no grouping. Pagination is only the optional `olderHref` link. */
165
- declare function HyleListView({ items, layout, title, headingLevel, moreHref, olderHref, ...base }: HyleListViewProps): ReactElement | null;
167
+ declare function HyleListView({ items, layout, title, headingLevel, moreHref, olderHref, theme, ...base }: HyleListViewProps): ReactElement | null;
166
168
  interface HyleArticleViewProps extends PageBaseProps {
167
169
  readonly article: ResolvedArticle;
168
170
  /**
@@ -1,5 +1,5 @@
1
1
  import { ElementType, ReactNode, ComponentType, ReactElement } from 'react';
2
- import { j as ResolvedArticle, L as ListItem } from './types-3F0wqD-o.cjs';
2
+ import { j as ResolvedArticle, L as ListItem, T as ThemeRef } from './types-D09Z072G.js';
3
3
 
4
4
  type CalloutKind = "note" | "tip" | "important" | "warning" | "caution";
5
5
  interface LinkProps {
@@ -160,9 +160,11 @@ interface HyleListViewProps extends PageBaseProps {
160
160
  readonly moreHref?: string | undefined;
161
161
  /** Where "Older posts" goes (built from the list's `next_cursor`); omit to hide it. */
162
162
  readonly olderHref?: string | undefined;
163
+ /** The list answer's `theme`, so an embedded list is styled like the workspace's pages. */
164
+ readonly theme?: ThemeRef | undefined;
163
165
  }
164
166
  /** Items link to `toHref(canonical_path)`: plain anchors in a flat list, newest first as hyle sent them, no grouping. Pagination is only the optional `olderHref` link. */
165
- declare function HyleListView({ items, layout, title, headingLevel, moreHref, olderHref, ...base }: HyleListViewProps): ReactElement | null;
167
+ declare function HyleListView({ items, layout, title, headingLevel, moreHref, olderHref, theme, ...base }: HyleListViewProps): ReactElement | null;
166
168
  interface HyleArticleViewProps extends PageBaseProps {
167
169
  readonly article: ResolvedArticle;
168
170
  /**
package/dist/html.cjs CHANGED
@@ -29,12 +29,17 @@ var import_hast_util_to_html = require("hast-util-to-html");
29
29
  // src/asset-path.ts
30
30
  var ASSET_ROUTE_PREFIX = "/api/hyle/assets";
31
31
  var UUID = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
32
- var EXTENSIONS = "png|jpg|gif|webp|svg|pdf|mp4|webm|mp3|ogg";
32
+ var EXTENSIONS = "png|jpg|gif|webp|svg|pdf|mp4|webm|mp3|ogg|woff2";
33
33
  var ASSET_FILE = new RegExp(`^${UUID}(?:\\.(?:${EXTENSIONS}))?$`);
34
- var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)$`, "i");
34
+ var THEME_FONT = new RegExp(`^/assets/${UUID}\\.woff2$`);
35
+ var PREVIEW_TOKEN_SOURCE = "hyle_pv_[A-Za-z0-9_-]{43}";
36
+ var PREVIEW_TOKEN = new RegExp(`^${PREVIEW_TOKEN_SOURCE}$`);
37
+ var PREVIEW_PARAM = "hyle_preview";
38
+ var PREVIEW_QUERY_SOURCE = `\\?${PREVIEW_PARAM}=${PREVIEW_TOKEN_SOURCE}`;
39
+ var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)(${PREVIEW_QUERY_SOURCE})?$`, "i");
35
40
  function hostAssetSrc(src) {
36
- const file = HYLE_ASSET_URL.exec(src)?.[1];
37
- return file ? `${ASSET_ROUTE_PREFIX}/${file.toLowerCase()}` : src;
41
+ const [, file, query = ""] = HYLE_ASSET_URL.exec(src) ?? [];
42
+ return file ? `${ASSET_ROUTE_PREFIX}/${file.toLowerCase()}${query}` : src;
38
43
  }
39
44
 
40
45
  // src/react/sanitize.ts
@@ -112,7 +117,7 @@ var ENTITIES = { "&#x3c;": "<", "&#x26;": "&", "&lt;": "<", "&gt;": ">", "&amp;"
112
117
  function mermaidSource(srcDoc) {
113
118
  return MERMAID_SRCDOC.exec(srcDoc)?.[1]?.replace(/&(?:#x3c|#x26|#x27|lt|gt|amp|quot);/gi, (e) => ENTITIES[e.toLowerCase()]);
114
119
  }
115
- var RENDER_REF = /^(\/assets\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\.svg) ([1-9]\d{0,5}) ([1-9]\d{0,5})$/;
120
+ var RENDER_REF = new RegExp(`^(/assets/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\\.svg(?:${PREVIEW_QUERY_SOURCE})?) ([1-9]\\d{0,5}) ([1-9]\\d{0,5})$`);
116
121
  var isRenderRef = matches(RENDER_REF);
117
122
  var YOUTUBE_WATCH = /^https:\/\/www\.youtube\.com\/watch\?v=([A-Za-z0-9_-]{11})$/;
118
123
  var youtubeId = (href) => typeof href === "string" ? YOUTUBE_WATCH.exec(href)?.[1] : void 0;
@@ -245,7 +250,7 @@ function sanitizeHast(tree, title, description) {
245
250
  const [first] = elements;
246
251
  const skip = title !== void 0 && isObject(first) && first.tagName === "h1" && collapse(textOf(first)) === collapse(title) ? first : void 0;
247
252
  const lead = elements[skip ? 1 : 0];
248
- const repeat = description && isObject(lead) && lead.tagName === "p" && collapse(textOf(lead)).startsWith(collapse(description)) && !holdsEmbed(lead) ? lead : void 0;
253
+ const repeat = description && isObject(lead) && lead.tagName === "p" && collapse(textOf(lead)) === collapse(description) && !holdsEmbed(lead) ? lead : void 0;
249
254
  const budget = { nodes: 0, text: 0 };
250
255
  return { type: "root", children: raw.filter((n) => n !== skip && n !== repeat).flatMap((n) => clean(n, 0, { katex: false }, budget)) };
251
256
  }
package/dist/html.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- export { H as HastLimitError } from './sanitize-ijiWjEm9.cjs';
1
+ export { H as HastLimitError } from './sanitize-BpY_AdZh.cjs';
2
2
  import 'hast';
3
3
 
4
4
  interface HastToHtmlOptions {
package/dist/html.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { H as HastLimitError } from './sanitize-ijiWjEm9.js';
1
+ export { H as HastLimitError } from './sanitize-BpY_AdZh.js';
2
2
  import 'hast';
3
3
 
4
4
  interface HastToHtmlOptions {
package/dist/html.js CHANGED
@@ -3,8 +3,8 @@ import {
3
3
  mermaidSource,
4
4
  sanitizeHast,
5
5
  stringsFor
6
- } from "./chunk-56Y24XBV.js";
7
- import "./chunk-67IOIAVW.js";
6
+ } from "./chunk-IW3TUD4G.js";
7
+ import "./chunk-DUPT6XLB.js";
8
8
 
9
9
  // src/html.ts
10
10
  import { toHtml } from "hast-util-to-html";
package/dist/index.cjs CHANGED
@@ -51,9 +51,15 @@ module.exports = __toCommonJS(src_exports);
51
51
  var ASSET_ROUTE_PREFIX = "/api/hyle/assets";
52
52
  var ASSET_RESERVED_PATH = "/api/hyle/*";
53
53
  var UUID = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
54
- var EXTENSIONS = "png|jpg|gif|webp|svg|pdf|mp4|webm|mp3|ogg";
54
+ var EXTENSIONS = "png|jpg|gif|webp|svg|pdf|mp4|webm|mp3|ogg|woff2";
55
55
  var ASSET_FILE = new RegExp(`^${UUID}(?:\\.(?:${EXTENSIONS}))?$`);
56
- var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)$`, "i");
56
+ var THEME_FONT = new RegExp(`^/assets/${UUID}\\.woff2$`);
57
+ var PREVIEW_TOKEN_SOURCE = "hyle_pv_[A-Za-z0-9_-]{43}";
58
+ var PREVIEW_TOKEN = new RegExp(`^${PREVIEW_TOKEN_SOURCE}$`);
59
+ var PREVIEW_HEADER = "cp-preview";
60
+ var PREVIEW_PARAM = "hyle_preview";
61
+ var PREVIEW_QUERY_SOURCE = `\\?${PREVIEW_PARAM}=${PREVIEW_TOKEN_SOURCE}`;
62
+ var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)(${PREVIEW_QUERY_SOURCE})?$`, "i");
57
63
 
58
64
  // src/errors.ts
59
65
  var Cp1ClientError = class extends Error {
@@ -71,6 +77,30 @@ var Cp1ClientError = class extends Error {
71
77
  }
72
78
  };
73
79
 
80
+ // src/preview.ts
81
+ 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;
82
+ var ASSET_PROPERTIES = ["src", "dataLight", "dataDark"];
83
+ var MAX_DEPTH = 200;
84
+ function mapNode(node, mark, depth) {
85
+ if (typeof node !== "object" || node === null || depth > MAX_DEPTH) return node;
86
+ const { properties, children } = node;
87
+ const marked = properties && Object.fromEntries(ASSET_PROPERTIES.filter((name) => name in properties).map((name) => [name, mark(properties[name])]));
88
+ return {
89
+ ...node,
90
+ ...properties ? { properties: { ...properties, ...marked } } : {},
91
+ ...Array.isArray(children) ? { children: children.map((child) => mapNode(child, mark, depth + 1)) } : {}
92
+ };
93
+ }
94
+ function withPreviewAssets(article, token) {
95
+ const mark = (value) => typeof value === "string" ? value.replace(ASSET_PATH, (path) => `${path}?${PREVIEW_PARAM}=${token}`) : value;
96
+ const { publication, content } = article;
97
+ return {
98
+ ...article,
99
+ publication: publication.cover ? { ...publication, cover: { path: String(mark(publication.cover.path)) } } : publication,
100
+ content: content.format === "hast" ? { ...content, tree: mapNode(content.tree, mark, 0) } : content
101
+ };
102
+ }
103
+
74
104
  // src/client.ts
75
105
  var RENDERER_VERSION = "4";
76
106
  function applyCredential(headers, credential, method, url) {
@@ -183,8 +213,20 @@ function createHyleClient(options) {
183
213
  if (data?.cp === 1 && data.kind === "push_posts" && Array.isArray(data.posts) && typeof data.complete === "boolean") return data;
184
214
  throw failure(reply);
185
215
  }
216
+ async function preview(token) {
217
+ if (typeof token !== "string" || !PREVIEW_TOKEN.test(token)) return { kind: "notfound" };
218
+ const reply = await get("/cp1/read/_preview", new URLSearchParams(), { headers: { [PREVIEW_HEADER]: token }, cache: "no-store" });
219
+ if (reply.status === 404 && reply.parsed?.error?.code === "NOT_FOUND") return { kind: "notfound" };
220
+ const data = reply.parsed?.data;
221
+ if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
222
+ const article = data?.article;
223
+ if (data?.cp !== 1 || data.kind !== "preview" || typeof data.expires_at !== "string" || article?.kind !== "article" || article.content?.format !== "hast" || !article.publication) throw failure(reply);
224
+ return { kind: "preview", expires_at: data.expires_at, article: withPreviewAssets(article, token) };
225
+ }
186
226
  async function asset(file, opts = {}) {
187
227
  if (!ASSET_FILE.test(file)) throw new TypeError("asset file must be <uuid>[.<ext>]");
228
+ const { previewToken } = opts;
229
+ if (previewToken !== void 0 && !PREVIEW_TOKEN.test(previewToken)) throw new TypeError("previewToken is not a preview token");
188
230
  const url = `${base}/cp1/read/assets/${file}`;
189
231
  const headers = new Headers();
190
232
  const applied = applyCredential(headers, options, "GET", url);
@@ -193,23 +235,30 @@ function createHyleClient(options) {
193
235
  const value = opts.headers?.[name];
194
236
  if (value) headers.set(name, value);
195
237
  }
238
+ if (previewToken !== void 0) headers.set(PREVIEW_HEADER, previewToken);
239
+ return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS), ...previewToken === void 0 ? {} : { cache: "no-store" } });
240
+ }
241
+ async function theme(opts = {}) {
242
+ const url = `${base}/cp1/read/theme.css`;
243
+ const headers = new Headers();
244
+ const applied = applyCredential(headers, options, "GET", url);
245
+ if (applied) await applied;
196
246
  return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS) });
197
247
  }
198
- return { resolve, mounts, pushPosts, asset };
248
+ return { resolve, mounts, pushPosts, preview, asset, theme };
199
249
  }
200
250
 
201
251
  // src/host-sync.ts
202
252
  var CONTROL_TOKEN_PREFIX = "hyle_tc_";
203
253
  var DEFAULT_TIMEOUT_MS2 = 1e4;
204
254
  var MAX_RESPONSE_BYTES = 1024 * 1024;
205
- var PATH = "/cp1/control/workspace/host-reserved-paths";
206
- async function syncHostReserved(input) {
255
+ async function put(input, path, body, read) {
207
256
  checkBaseUrl(input.baseUrl, input.allowInsecureHttp);
208
257
  if (input.token !== void 0 && !input.token.startsWith(CONTROL_TOKEN_PREFIX)) {
209
258
  throw new TypeError("syncing needs a control credential (hyle_tc_...); a target token is read-only and cannot write");
210
259
  }
211
260
  const fetchImpl = input.fetch ?? fetch;
212
- const url = `${input.baseUrl.replace(/\/+$/, "")}${PATH}`;
261
+ const url = `${input.baseUrl.replace(/\/+$/, "")}${path}`;
213
262
  const headers = new Headers({ "content-type": "application/json", "idempotency-key": `sync-${crypto.randomUUID()}` });
214
263
  await applyCredential(headers, input.auth ? { auth: input.auth, workspaceId: input.workspaceId } : { token: input.token }, "PUT", url);
215
264
  headers.set("cp-workspace", input.workspaceId);
@@ -219,7 +268,7 @@ async function syncHostReserved(input) {
219
268
  redirect: "error",
220
269
  signal: AbortSignal.timeout(input.timeoutMs ?? DEFAULT_TIMEOUT_MS2),
221
270
  headers,
222
- body: JSON.stringify({ paths: input.paths, host: input.host, build_id: input.buildId })
271
+ body: JSON.stringify(body)
223
272
  });
224
273
  const text = await readCapped(res, MAX_RESPONSE_BYTES);
225
274
  let parsed;
@@ -228,14 +277,18 @@ async function syncHostReserved(input) {
228
277
  } catch {
229
278
  parsed = void 0;
230
279
  }
231
- const data = parsed?.data;
232
- const conflicts = data?.conflicts;
233
- if (res.ok && data && Array.isArray(data.paths) && typeof data.changed === "boolean" && typeof data.synced_at === "string" && typeof conflicts?.total === "number" && Array.isArray(conflicts.offenders)) {
234
- return { paths: data.paths, changed: data.changed, syncedAt: data.synced_at, conflicts: { total: conflicts.total, offenders: conflicts.offenders } };
235
- }
280
+ const result = res.ok && parsed?.data ? read(parsed.data) : void 0;
281
+ if (result !== void 0) return result;
236
282
  const err = parsed?.error;
237
283
  throw new Cp1ClientError(err?.code ?? "INVALID_RESPONSE", err?.message ?? `Unexpected response from hyle (HTTP ${res.status})`, res.status, err?.request_id ?? "", err?.details);
238
284
  }
285
+ function syncHostReserved(input) {
286
+ return put(input, "/cp1/control/workspace/host-reserved-paths", { paths: input.paths, host: input.host, build_id: input.buildId }, (data) => {
287
+ const conflicts = data.conflicts;
288
+ if (!Array.isArray(data.paths) || typeof data.changed !== "boolean" || typeof data.synced_at !== "string" || typeof conflicts?.total !== "number" || !Array.isArray(conflicts.offenders)) return void 0;
289
+ return { paths: data.paths, changed: data.changed, syncedAt: data.synced_at, conflicts: { total: conflicts.total, offenders: conflicts.offenders } };
290
+ });
291
+ }
239
292
 
240
293
  // src/delivery-dedupe.ts
241
294
  var DeliveryDedupe = class {