@tdacorp/hyle-sdk 0.21.0 → 0.23.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.
Files changed (58) hide show
  1. package/README.md +141 -18
  2. package/dist/check-routes-bin.js +174 -42
  3. package/dist/{chunk-56Y24XBV.js → chunk-JHZJOJDC.js} +4 -3
  4. package/dist/{chunk-K5VDLROQ.js → chunk-SFFBZFEN.js} +34 -1
  5. package/dist/{chunk-HJX57NLI.js → chunk-UFMKLCXS.js} +246 -225
  6. package/dist/{chunk-X2TLYM7Y.js → chunk-VUML2UPD.js} +1 -1
  7. package/dist/chunk-VXARM37R.js +68 -0
  8. package/dist/{chunk-75JFLML4.js → chunk-YHXE3TGS.js} +94 -12
  9. package/dist/{client-41fU6OY2.d.cts → client--ighAWaj.d.ts} +13 -1
  10. package/dist/{client-LwzHwqpM.d.ts → client-DK-S2580.d.cts} +13 -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 +14 -6
  16. package/dist/comments.js +14 -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-XT0x_Jaa.d.cts} +4 -2
  22. package/dist/{embed-CYt-q13P.d.cts → embed-g7NT1CyB.d.ts} +4 -2
  23. package/dist/html.cjs +14 -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 +85 -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 +521 -242
  36. package/dist/next.d.cts +74 -17
  37. package/dist/next.d.ts +74 -17
  38. package/dist/next.js +207 -33
  39. package/dist/print-coordinator.js +1 -1
  40. package/dist/react.cjs +233 -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-BjAK0k_Y.d.ts → resolve-BqC9l5RH.d.ts} +1 -1
  45. package/dist/{resolve-eI1muCKL.d.cts → resolve-CiZCPysX.d.cts} +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-b9QbmEDd.d.cts} +44 -1
  52. package/dist/{types-3F0wqD-o.d.ts → types-b9QbmEDd.d.ts} +44 -1
  53. package/dist/use-cache.cjs +73 -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,7 +1,7 @@
1
1
  import {
2
2
  createHyleClient,
3
3
  isValidCacheTag
4
- } from "./chunk-75JFLML4.js";
4
+ } from "./chunk-YHXE3TGS.js";
5
5
 
6
6
  // src/next/resolve.ts
7
7
  var DEFAULT_REVALIDATE = 86400;
@@ -0,0 +1,68 @@
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|woff2";
6
+ var ASSET_FILE = new RegExp(`^${UUID}(?:\\.(?:${EXTENSIONS}))?$`);
7
+ var THEME_FILE = /^theme-([0-9a-f]{16})-([0-9a-f]{64})\.css$/;
8
+ var THEME_FONT = new RegExp(`^/assets/${UUID}\\.woff2$`);
9
+ function themeStylesheetHref({ scope, hash }) {
10
+ const file = `theme-${scope}-${hash}.css`;
11
+ return THEME_FILE.test(file) ? `${ASSET_ROUTE_PREFIX}/${file}` : void 0;
12
+ }
13
+ function themeFontHrefs(preload) {
14
+ return preload.flatMap((src) => typeof src === "string" && THEME_FONT.test(src) ? [hostAssetSrc(src)] : []);
15
+ }
16
+ var PREVIEW_TOKEN_SOURCE = "hyle_pv_[A-Za-z0-9_-]{43}";
17
+ var PREVIEW_TOKEN = new RegExp(`^${PREVIEW_TOKEN_SOURCE}$`);
18
+ var PREVIEW_HEADER = "cp-preview";
19
+ var PREVIEW_PARAM = "hyle_preview";
20
+ var PREVIEW_QUERY_SOURCE = `\\?${PREVIEW_PARAM}=${PREVIEW_TOKEN_SOURCE}`;
21
+ var PROTECTED_PARAM = "hyle_protected";
22
+ var PROTECTED_HEADER = "cp-protected";
23
+ var PROTECTED_ID = new RegExp(`^${UUID}$`);
24
+ var PROTECTED_PASSWORD = /^[A-Za-z0-9]{16}$/;
25
+ var protectedCookieName = (pageId) => `hyle_p_${pageId}`;
26
+ var PROTECTED_QUERY_SOURCE = `\\?${PROTECTED_PARAM}=${UUID}`;
27
+ var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)(${PREVIEW_QUERY_SOURCE}|${PROTECTED_QUERY_SOURCE})?$`, "i");
28
+ function hostAssetSrc(src) {
29
+ const [, file, query = ""] = HYLE_ASSET_URL.exec(src) ?? [];
30
+ return file ? `${ASSET_ROUTE_PREFIX}/${file.toLowerCase()}${query}` : src;
31
+ }
32
+ function hostAssetHtml(html) {
33
+ return html.replace(new RegExp(`(\\ssrc=")(/assets/${UUID}(?:\\.(?:${EXTENSIONS}))?)(")`, "gi"), (_m, open, url, close) => `${open}${hostAssetSrc(url)}${close}`);
34
+ }
35
+ var ASSET_CONTENT_TYPES = /* @__PURE__ */ new Set([
36
+ "image/png",
37
+ "image/jpeg",
38
+ "image/gif",
39
+ "image/webp",
40
+ "image/svg+xml",
41
+ "application/pdf",
42
+ "video/mp4",
43
+ "video/webm",
44
+ "audio/mpeg",
45
+ "audio/ogg",
46
+ "font/woff2"
47
+ ]);
48
+
49
+ export {
50
+ ASSET_ROUTE_PREFIX,
51
+ ASSET_RESERVED_PATH,
52
+ ASSET_FILE,
53
+ THEME_FILE,
54
+ themeStylesheetHref,
55
+ themeFontHrefs,
56
+ PREVIEW_TOKEN,
57
+ PREVIEW_HEADER,
58
+ PREVIEW_PARAM,
59
+ PREVIEW_QUERY_SOURCE,
60
+ PROTECTED_PARAM,
61
+ PROTECTED_HEADER,
62
+ PROTECTED_ID,
63
+ PROTECTED_PASSWORD,
64
+ protectedCookieName,
65
+ hostAssetSrc,
66
+ hostAssetHtml,
67
+ ASSET_CONTENT_TYPES
68
+ };
@@ -1,8 +1,15 @@
1
1
  import {
2
2
  ASSET_FILE,
3
3
  ASSET_RESERVED_PATH,
4
- ASSET_ROUTE_PREFIX
5
- } from "./chunk-67IOIAVW.js";
4
+ ASSET_ROUTE_PREFIX,
5
+ PREVIEW_HEADER,
6
+ PREVIEW_PARAM,
7
+ PREVIEW_TOKEN,
8
+ PROTECTED_HEADER,
9
+ PROTECTED_ID,
10
+ PROTECTED_PARAM,
11
+ PROTECTED_PASSWORD
12
+ } from "./chunk-VXARM37R.js";
6
13
 
7
14
  // src/errors.ts
8
15
  var Cp1ClientError = class extends Error {
@@ -20,6 +27,30 @@ var Cp1ClientError = class extends Error {
20
27
  }
21
28
  };
22
29
 
30
+ // src/preview.ts
31
+ 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;
32
+ var ASSET_PROPERTIES = ["src", "dataLight", "dataDark"];
33
+ var MAX_DEPTH = 200;
34
+ function mapNode(node, mark, depth) {
35
+ if (typeof node !== "object" || node === null || depth > MAX_DEPTH) return node;
36
+ const { properties, children } = node;
37
+ const marked = properties && Object.fromEntries(ASSET_PROPERTIES.filter((name) => name in properties).map((name) => [name, mark(properties[name])]));
38
+ return {
39
+ ...node,
40
+ ...properties ? { properties: { ...properties, ...marked } } : {},
41
+ ...Array.isArray(children) ? { children: children.map((child) => mapNode(child, mark, depth + 1)) } : {}
42
+ };
43
+ }
44
+ function withAssetQuery(article, query) {
45
+ const mark = (value) => typeof value === "string" ? value.replace(ASSET_PATH, (path) => `${path}?${query}`) : value;
46
+ const { publication, content } = article;
47
+ return {
48
+ ...article,
49
+ publication: publication.cover ? { ...publication, cover: { path: String(mark(publication.cover.path)) } } : publication,
50
+ content: content.format === "hast" ? { ...content, tree: mapNode(content.tree, mark, 0) } : content
51
+ };
52
+ }
53
+
23
54
  // src/client.ts
24
55
  var RENDERER_VERSION = "4";
25
56
  function applyCredential(headers, credential, method, url) {
@@ -55,6 +86,17 @@ async function readCapped(res, max) {
55
86
  }
56
87
  return Buffer.concat(chunks).toString("utf8");
57
88
  }
89
+ function isNotFoundBody(status, body) {
90
+ if (status !== 404) return false;
91
+ try {
92
+ return JSON.parse(body)?.error?.code === "NOT_FOUND";
93
+ } catch {
94
+ return false;
95
+ }
96
+ }
97
+ async function isNotFoundResponse(res) {
98
+ return isNotFoundBody(res.status, await readCapped(res, 64 * 1024).catch(() => ""));
99
+ }
58
100
  var KINDS = /* @__PURE__ */ new Set(["article", "list", "redirect", "notfound", "disabled"]);
59
101
  var isStrings = (value) => Array.isArray(value) && value.every((v) => typeof v === "string");
60
102
  function isMounts(data) {
@@ -132,8 +174,31 @@ function createHyleClient(options) {
132
174
  if (data?.cp === 1 && data.kind === "push_posts" && Array.isArray(data.posts) && typeof data.complete === "boolean") return data;
133
175
  throw failure(reply);
134
176
  }
177
+ async function preview(token) {
178
+ if (typeof token !== "string" || !PREVIEW_TOKEN.test(token)) return { kind: "notfound" };
179
+ const reply = await get("/cp1/read/_preview", new URLSearchParams(), { headers: { [PREVIEW_HEADER]: token }, cache: "no-store" });
180
+ if (reply.status === 404 && reply.parsed?.error?.code === "NOT_FOUND") return { kind: "notfound" };
181
+ const data = reply.parsed?.data;
182
+ if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
183
+ const article = data?.article;
184
+ if (data?.cp !== 1 || data.kind !== "preview" || typeof data.expires_at !== "string" || article?.kind !== "article" || article.content?.format !== "hast" || !article.publication) throw failure(reply);
185
+ return { kind: "preview", expires_at: data.expires_at, article: withAssetQuery(article, `${PREVIEW_PARAM}=${token}`) };
186
+ }
187
+ async function protectedPage(pageId, password) {
188
+ if (!PROTECTED_ID.test(pageId) || !PROTECTED_PASSWORD.test(password)) return { kind: "notfound" };
189
+ const reply = await get("/cp1/read/_protected", new URLSearchParams(), { headers: { [PROTECTED_HEADER]: `${pageId}.${password}` }, cache: "no-store" });
190
+ if (reply.status === 404 && reply.parsed?.error?.code === "NOT_FOUND") return { kind: "notfound" };
191
+ const data = reply.parsed?.data;
192
+ if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
193
+ const article = data?.article;
194
+ const expires = data?.expires_at;
195
+ if (data?.cp !== 1 || data.kind !== "protected" || typeof expires !== "string" && expires !== null || article?.kind !== "article" || article.content?.format !== "hast" || !article.publication) throw failure(reply);
196
+ return { kind: "protected", expires_at: expires, article: withAssetQuery(article, `${PROTECTED_PARAM}=${pageId}`) };
197
+ }
135
198
  async function asset(file, opts = {}) {
136
199
  if (!ASSET_FILE.test(file)) throw new TypeError("asset file must be <uuid>[.<ext>]");
200
+ const { previewToken } = opts;
201
+ if (previewToken !== void 0 && !PREVIEW_TOKEN.test(previewToken)) throw new TypeError("previewToken is not a preview token");
137
202
  const url = `${base}/cp1/read/assets/${file}`;
138
203
  const headers = new Headers();
139
204
  const applied = applyCredential(headers, options, "GET", url);
@@ -142,23 +207,34 @@ function createHyleClient(options) {
142
207
  const value = opts.headers?.[name];
143
208
  if (value) headers.set(name, value);
144
209
  }
210
+ const { protectedAccess } = opts;
211
+ if (protectedAccess !== void 0 && !(PROTECTED_ID.test(protectedAccess.pageId) && PROTECTED_PASSWORD.test(protectedAccess.password))) throw new TypeError("protectedAccess is not a page id and password");
212
+ if (previewToken !== void 0) headers.set(PREVIEW_HEADER, previewToken);
213
+ if (protectedAccess !== void 0) headers.set(PROTECTED_HEADER, `${protectedAccess.pageId}.${protectedAccess.password}`);
214
+ const uncached = previewToken !== void 0 || protectedAccess !== void 0;
215
+ return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS), ...uncached ? { 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;
145
222
  return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS) });
146
223
  }
147
- return { resolve, mounts, pushPosts, asset };
224
+ return { resolve, mounts, pushPosts, preview, protected: protectedPage, asset, theme };
148
225
  }
149
226
 
150
227
  // src/host-sync.ts
151
228
  var CONTROL_TOKEN_PREFIX = "hyle_tc_";
152
229
  var DEFAULT_TIMEOUT_MS2 = 1e4;
153
230
  var MAX_RESPONSE_BYTES = 1024 * 1024;
154
- var PATH = "/cp1/control/workspace/host-reserved-paths";
155
- async function syncHostReserved(input) {
231
+ async function put(input, path, body, read) {
156
232
  checkBaseUrl(input.baseUrl, input.allowInsecureHttp);
157
233
  if (input.token !== void 0 && !input.token.startsWith(CONTROL_TOKEN_PREFIX)) {
158
234
  throw new TypeError("syncing needs a control credential (hyle_tc_...); a target token is read-only and cannot write");
159
235
  }
160
236
  const fetchImpl = input.fetch ?? fetch;
161
- const url = `${input.baseUrl.replace(/\/+$/, "")}${PATH}`;
237
+ const url = `${input.baseUrl.replace(/\/+$/, "")}${path}`;
162
238
  const headers = new Headers({ "content-type": "application/json", "idempotency-key": `sync-${crypto.randomUUID()}` });
163
239
  await applyCredential(headers, input.auth ? { auth: input.auth, workspaceId: input.workspaceId } : { token: input.token }, "PUT", url);
164
240
  headers.set("cp-workspace", input.workspaceId);
@@ -168,7 +244,7 @@ async function syncHostReserved(input) {
168
244
  redirect: "error",
169
245
  signal: AbortSignal.timeout(input.timeoutMs ?? DEFAULT_TIMEOUT_MS2),
170
246
  headers,
171
- body: JSON.stringify({ paths: input.paths, host: input.host, build_id: input.buildId })
247
+ body: JSON.stringify(body)
172
248
  });
173
249
  const text = await readCapped(res, MAX_RESPONSE_BYTES);
174
250
  let parsed;
@@ -177,14 +253,18 @@ async function syncHostReserved(input) {
177
253
  } catch {
178
254
  parsed = void 0;
179
255
  }
180
- const data = parsed?.data;
181
- const conflicts = data?.conflicts;
182
- 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)) {
183
- return { paths: data.paths, changed: data.changed, syncedAt: data.synced_at, conflicts: { total: conflicts.total, offenders: conflicts.offenders } };
184
- }
256
+ const result = res.ok && parsed?.data ? read(parsed.data) : void 0;
257
+ if (result !== void 0) return result;
185
258
  const err = parsed?.error;
186
259
  throw new Cp1ClientError(err?.code ?? "INVALID_RESPONSE", err?.message ?? `Unexpected response from hyle (HTTP ${res.status})`, res.status, err?.request_id ?? "", err?.details);
187
260
  }
261
+ function syncHostReserved(input) {
262
+ return put(input, "/cp1/control/workspace/host-reserved-paths", { paths: input.paths, host: input.host, build_id: input.buildId }, (data) => {
263
+ const conflicts = data.conflicts;
264
+ 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;
265
+ return { paths: data.paths, changed: data.changed, syncedAt: data.synced_at, conflicts: { total: conflicts.total, offenders: conflicts.offenders } };
266
+ });
267
+ }
188
268
 
189
269
  // src/delivery-dedupe.ts
190
270
  var DeliveryDedupe = class {
@@ -724,6 +804,8 @@ function cleanDisplayName(raw) {
724
804
  export {
725
805
  Cp1ClientError,
726
806
  readCapped,
807
+ isNotFoundBody,
808
+ isNotFoundResponse,
727
809
  checkBaseUrl,
728
810
  createHyleClient,
729
811
  syncHostReserved,
@@ -1,4 +1,4 @@
1
- import { i as Resolved, e as MountsResult } from './types-3F0wqD-o.cjs';
1
+ import { j as Resolved, f as MountsResult, H as HylePreview, d as HyleProtected } from './types-b9QbmEDd.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,13 @@ 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;
190
+ /** A protected page's id and password (hyle ADR 0039): hyle then also serves that page's assets. The answer is never cached. */
191
+ readonly protectedAccess?: {
192
+ readonly pageId: string;
193
+ readonly password: string;
194
+ };
188
195
  }
189
196
  declare function createHyleClient(options: HyleClientOptions): {
190
197
  resolve: (opts: ResolveOptions) => Promise<Resolved>;
@@ -194,7 +201,12 @@ declare function createHyleClient(options: HyleClientOptions): {
194
201
  readonly cursor?: string;
195
202
  readonly init?: HyleRequestInit;
196
203
  }) => Promise<PushPage>;
204
+ preview: (token: string | undefined) => Promise<HylePreview>;
205
+ protected: (pageId: string, password: string) => Promise<HyleProtected>;
197
206
  asset: (file: string, opts?: AssetOptions) => Promise<Response>;
207
+ theme: (opts?: {
208
+ readonly timeoutMs?: number;
209
+ }) => Promise<Response>;
198
210
  };
199
211
  type HyleClient = ReturnType<typeof createHyleClient>;
200
212
 
@@ -1,4 +1,4 @@
1
- import { i as Resolved, e as MountsResult } from './types-3F0wqD-o.js';
1
+ import { j as Resolved, f as MountsResult, H as HylePreview, d as HyleProtected } from './types-b9QbmEDd.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,13 @@ 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;
190
+ /** A protected page's id and password (hyle ADR 0039): hyle then also serves that page's assets. The answer is never cached. */
191
+ readonly protectedAccess?: {
192
+ readonly pageId: string;
193
+ readonly password: string;
194
+ };
188
195
  }
189
196
  declare function createHyleClient(options: HyleClientOptions): {
190
197
  resolve: (opts: ResolveOptions) => Promise<Resolved>;
@@ -194,7 +201,12 @@ declare function createHyleClient(options: HyleClientOptions): {
194
201
  readonly cursor?: string;
195
202
  readonly init?: HyleRequestInit;
196
203
  }) => Promise<PushPage>;
204
+ preview: (token: string | undefined) => Promise<HylePreview>;
205
+ protected: (pageId: string, password: string) => Promise<HyleProtected>;
197
206
  asset: (file: string, opts?: AssetOptions) => Promise<Response>;
207
+ theme: (opts?: {
208
+ readonly timeoutMs?: number;
209
+ }) => Promise<Response>;
198
210
  };
199
211
  type HyleClient = ReturnType<typeof createHyleClient>;
200
212
 
@@ -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,20 @@ 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 PROTECTED_PARAM = "hyle_protected";
373
+ var PROTECTED_ID = new RegExp(`^${UUID}$`);
374
+ var PROTECTED_QUERY_SOURCE = `\\?${PROTECTED_PARAM}=${UUID}`;
375
+ var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)(${PREVIEW_QUERY_SOURCE}|${PROTECTED_QUERY_SOURCE})?$`, "i");
368
376
  function hostAssetSrc(src) {
369
- const file = HYLE_ASSET_URL.exec(src)?.[1];
370
- return file ? `${ASSET_ROUTE_PREFIX}/${file.toLowerCase()}` : src;
377
+ const [, file, query = ""] = HYLE_ASSET_URL.exec(src) ?? [];
378
+ return file ? `${ASSET_ROUTE_PREFIX}/${file.toLowerCase()}${query}` : src;
371
379
  }
372
380
 
373
381
  // src/react/sanitize.ts
@@ -441,7 +449,7 @@ var MERMAID_SRCDOC = new RegExp(
441
449
  `^<!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
450
  );
443
451
  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})$/;
452
+ 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
453
  var isRenderRef = matches(RENDER_REF);
446
454
  var YOUTUBE_WATCH = /^https:\/\/www\.youtube\.com\/watch\?v=([A-Za-z0-9_-]{11})$/;
447
455
  var youtubeId = (href) => typeof href === "string" ? YOUTUBE_WATCH.exec(href)?.[1] : void 0;
@@ -574,7 +582,7 @@ function sanitizeHast(tree, title, description) {
574
582
  const [first] = elements;
575
583
  const skip = title !== void 0 && isObject2(first) && first.tagName === "h1" && collapse(textOf(first)) === collapse(title) ? first : void 0;
576
584
  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;
585
+ const repeat = description && isObject2(lead) && lead.tagName === "p" && collapse(textOf(lead)) === collapse(description) && !holdsEmbed(lead) ? lead : void 0;
578
586
  const budget = { nodes: 0, text: 0 };
579
587
  return { type: "root", children: raw.filter((n) => n !== skip && n !== repeat).flatMap((n) => clean(n, 0, { katex: false }, budget)) };
580
588
  }
package/dist/comments.js CHANGED
@@ -118,12 +118,20 @@ 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 PROTECTED_PARAM = "hyle_protected";
129
+ var PROTECTED_ID = new RegExp(`^${UUID}$`);
130
+ var PROTECTED_QUERY_SOURCE = `\\?${PROTECTED_PARAM}=${UUID}`;
131
+ var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)(${PREVIEW_QUERY_SOURCE}|${PROTECTED_QUERY_SOURCE})?$`, "i");
124
132
  function hostAssetSrc(src) {
125
- const file = HYLE_ASSET_URL.exec(src)?.[1];
126
- return file ? `${ASSET_ROUTE_PREFIX}/${file.toLowerCase()}` : src;
133
+ const [, file, query = ""] = HYLE_ASSET_URL.exec(src) ?? [];
134
+ return file ? `${ASSET_ROUTE_PREFIX}/${file.toLowerCase()}${query}` : src;
127
135
  }
128
136
 
129
137
  // src/react/sanitize.ts
@@ -197,7 +205,7 @@ var MERMAID_SRCDOC = new RegExp(
197
205
  `^<!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
206
  );
199
207
  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})$/;
208
+ 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
209
  var isRenderRef = matches(RENDER_REF);
202
210
  var YOUTUBE_WATCH = /^https:\/\/www\.youtube\.com\/watch\?v=([A-Za-z0-9_-]{11})$/;
203
211
  var youtubeId = (href) => typeof href === "string" ? YOUTUBE_WATCH.exec(href)?.[1] : void 0;
@@ -330,7 +338,7 @@ function sanitizeHast(tree, title, description) {
330
338
  const [first] = elements;
331
339
  const skip = title !== void 0 && isObject2(first) && first.tagName === "h1" && collapse(textOf(first)) === collapse(title) ? first : void 0;
332
340
  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;
341
+ const repeat = description && isObject2(lead) && lead.tagName === "p" && collapse(textOf(lead)) === collapse(description) && !holdsEmbed(lead) ? lead : void 0;
334
342
  const budget = { nodes: 0, text: 0 };
335
343
  return { type: "root", children: raw.filter((n) => n !== skip && n !== repeat).flatMap((n) => clean(n, 0, { katex: false }, budget)) };
336
344
  }
@@ -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 { k as ResolvedArticle, L as ListItem, T as ThemeRef } from './types-b9QbmEDd.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
  /**