@tdacorp/hyle-sdk 0.12.0 → 0.17.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 (43) hide show
  1. package/README.md +46 -12
  2. package/dist/check-routes-bin.js +31 -18
  3. package/dist/{chunk-S7PCCEHP.js → chunk-6VOHFFA5.js} +4 -3
  4. package/dist/{chunk-ZQFYH4FX.js → chunk-DMK4XQLU.js} +497 -327
  5. package/dist/{chunk-N7ZQUAGM.js → chunk-MGSUQBDW.js} +19 -7
  6. package/dist/{chunk-R5EMI4HQ.js → chunk-PJMJMP66.js} +3 -1
  7. package/dist/comments.cjs +6 -4
  8. package/dist/comments.js +6 -5
  9. package/dist/{diagram-viewer-DYX6R63Y.js → diagram-viewer-FJPED4SN.js} +46 -26
  10. package/dist/{embed-jCaSI31t.d.cts → embed-BmdwA2G9.d.cts} +51 -5
  11. package/dist/{embed-DL5QIZRJ.d.ts → embed-DNTZ2UXv.d.ts} +51 -5
  12. package/dist/index.cjs +19 -7
  13. package/dist/index.d.cts +15 -8
  14. package/dist/index.d.ts +15 -8
  15. package/dist/index.js +1 -1
  16. package/dist/labels-nmukKYgL.d.cts +37 -0
  17. package/dist/labels-nmukKYgL.d.ts +37 -0
  18. package/dist/mermaid-diagram.cjs +59 -30
  19. package/dist/mermaid-diagram.d.cts +4 -37
  20. package/dist/mermaid-diagram.d.ts +4 -37
  21. package/dist/mermaid-diagram.js +7 -5
  22. package/dist/mermaid-image.cjs +1382 -0
  23. package/dist/mermaid-image.d.cts +29 -0
  24. package/dist/mermaid-image.d.ts +29 -0
  25. package/dist/mermaid-image.js +94 -0
  26. package/dist/next.cjs +1235 -789
  27. package/dist/next.d.cts +149 -24
  28. package/dist/next.d.ts +149 -24
  29. package/dist/next.js +887 -612
  30. package/dist/react.cjs +336 -196
  31. package/dist/react.d.cts +39 -7
  32. package/dist/react.d.ts +39 -7
  33. package/dist/react.js +1 -1
  34. package/dist/{resolve-DvmuBlpO.d.ts → resolve-Ae7UFjsQ.d.ts} +5 -5
  35. package/dist/{resolve-f6IJ6SL9.d.cts → resolve-euZ4-aC9.d.cts} +5 -5
  36. package/dist/styles.css +11 -22
  37. package/dist/{types-5D6ZD0Wi.d.cts → types-Czt887Iv.d.cts} +32 -3
  38. package/dist/{types-5D6ZD0Wi.d.ts → types-Czt887Iv.d.ts} +32 -3
  39. package/dist/use-cache.cjs +1 -1
  40. package/dist/use-cache.d.cts +2 -2
  41. package/dist/use-cache.d.ts +2 -2
  42. package/dist/use-cache.js +2 -2
  43. package/package.json +1 -1
@@ -97,7 +97,7 @@ function createHyleClient(options) {
97
97
  const data = reply.parsed?.data;
98
98
  if (data && data.cp === 1 && typeof data.kind === "string" && KINDS.has(data.kind)) {
99
99
  const resolved = data;
100
- if (resolved.kind === "article" && resolved.content.format === "html" && opts.format !== "html") throw failure(reply);
100
+ if (resolved.kind === "article" && resolved.content.format !== "hast" && resolved.content.format !== opts.format) throw failure(reply);
101
101
  return resolved;
102
102
  }
103
103
  throw failure(reply);
@@ -317,17 +317,20 @@ function okResponse(purged) {
317
317
  // src/sitemap.ts
318
318
  var PAGE_LIMIT = 100;
319
319
  var DEFAULT_MAX_PAGES = 20;
320
- var SECTION_SLUG = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
321
320
  var UNSAFE_PATH = /[\\?#<>&"'\u0000- \u007f]/;
321
+ var LOCALE_TAG = /^[a-z]{2,3}(-[A-Za-z0-9]{2,8})*$/;
322
+ var isSitePath = (path) => typeof path === "string" && path.startsWith("/") && !path.startsWith("//") && !UNSAFE_PATH.test(path);
323
+ function safeAlternates(raw) {
324
+ const kept = (raw ?? []).filter((a) => typeof a.locale === "string" && LOCALE_TAG.test(a.locale) && isSitePath(a.canonical_path));
325
+ return kept.length > 0 ? kept.map((a) => ({ locale: a.locale, path: a.canonical_path })) : void 0;
326
+ }
322
327
  async function listPublicationPaths(options) {
323
328
  const maxPages = options.maxPages ?? DEFAULT_MAX_PAGES;
324
329
  const prefix = `${options.basePath}/`;
325
- const indexes = [options.basePath || "/"];
326
- for (const slug of options.sections ?? []) if (slug !== "posts" && SECTION_SLUG.test(slug)) indexes.push(`${options.basePath}/${slug}`);
327
330
  const found = /* @__PURE__ */ new Map();
328
331
  let complete = true;
329
332
  try {
330
- for (const index of new Set(indexes)) {
333
+ for (const index of [options.basePath || "/"]) {
331
334
  let cursor;
332
335
  for (let page = 0; page < maxPages; page++) {
333
336
  const result = await options.client.resolve({
@@ -341,7 +344,16 @@ async function listPublicationPaths(options) {
341
344
  break;
342
345
  }
343
346
  for (const item of result.items) {
344
- if (item.canonical_path.startsWith(prefix) && !UNSAFE_PATH.test(item.canonical_path)) found.set(item.canonical_path, item.published_at);
347
+ if (!item.canonical_path.startsWith(prefix) || UNSAFE_PATH.test(item.canonical_path)) continue;
348
+ const alternates = safeAlternates(item.alternates);
349
+ found.set(item.canonical_path, {
350
+ path: item.canonical_path,
351
+ publishedAt: item.published_at,
352
+ ...typeof item.updated_at === "string" ? { updatedAt: item.updated_at } : {},
353
+ ...alternates ? { alternates } : {},
354
+ title: item.title,
355
+ description: item.description
356
+ });
345
357
  }
346
358
  if (!result.next_cursor) break;
347
359
  if (page === maxPages - 1) complete = false;
@@ -351,7 +363,7 @@ async function listPublicationPaths(options) {
351
363
  } catch {
352
364
  complete = false;
353
365
  }
354
- return { paths: [...found].map(([path, publishedAt]) => ({ path, publishedAt })), complete };
366
+ return { paths: [...found.values()], complete };
355
367
  }
356
368
 
357
369
  // src/route-check.ts
@@ -1,5 +1,6 @@
1
1
  // src/react/mermaid-config.ts
2
- var MAX_MERMAID_SOURCE = 2e4;
2
+ var MAX_MERMAID_SOURCE = 1024 * 1024;
3
+ var MAX_MERMAID_EDGES = 5e3;
3
4
  function luminance(css) {
4
5
  const m = /^(rgba?)\(([^)]*)\)$|^color\(srgb ([^)]*)\)$/.exec(css.trim());
5
6
  if (!m) return void 0;
@@ -52,6 +53,7 @@ function whenNearViewport(el, onNear, Observer = globalThis.IntersectionObserver
52
53
 
53
54
  export {
54
55
  MAX_MERMAID_SOURCE,
56
+ MAX_MERMAID_EDGES,
55
57
  pickMermaidTheme,
56
58
  RENDER_TIMEOUT_MS,
57
59
  stripMermaidConfig,
package/dist/comments.cjs CHANGED
@@ -179,7 +179,7 @@ var HastLimitError = class extends Error {
179
179
  var MAX_NODES = 2e4;
180
180
  var MAX_TEXT = 512 * 1024;
181
181
  var MAX_DEPTH = 128;
182
- var MAX_SRCDOC = 64 * 1024;
182
+ var MAX_SRCDOC = 1024 * 1024;
183
183
  var DROP = /* @__PURE__ */ new Set(["script", "style", "template", "noscript"]);
184
184
  var VOID = /* @__PURE__ */ new Set(["br", "hr", "img", "input", "path"]);
185
185
  var isString = (v) => typeof v === "string";
@@ -196,6 +196,7 @@ var classTokens = (v) => {
196
196
  };
197
197
  var isClass = (v) => classTokens(v) !== void 0;
198
198
  var isAlign = matches(/^(left|right|center)$/);
199
+ var isPixels = (v) => typeof v === "number" ? Number.isInteger(v) && v > 0 : typeof v === "string" && /^[1-9]\d*$/.test(v);
199
200
  var isLength = matches(/^[\d.]+(em|px|%)?$/);
200
201
  var STYLE_PROPS = /* @__PURE__ */ new Set(["height", "vertical-align", "margin-left", "margin-right", "margin-top", "margin-bottom", "top", "width", "min-width", "border-bottom-width", "padding-left"]);
201
202
  var STYLE_LENGTH = /^(-?\d+(?:\.\d+)?)(em|px|%)?$/;
@@ -230,7 +231,8 @@ var MERMAID_SRCDOC = new RegExp(
230
231
  `^<!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>$`
231
232
  );
232
233
  var isMermaidSrcdoc = (v) => typeof v === "string" && v.length <= MAX_SRCDOC && MERMAID_SRCDOC.test(v);
233
- var MERMAID_FRAME_CSP = `default-src 'none'; script-src ${MERMAID_SCRIPT_URL} 'unsafe-inline'; style-src 'unsafe-inline'; img-src data:`;
234
+ 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})$/;
235
+ var isRenderRef = matches(RENDER_REF);
234
236
  var heading = { id: isIdValue, className: isClass };
235
237
  var ATTRS = new Map(
236
238
  Object.entries({
@@ -255,7 +257,7 @@ var ATTRS = new Map(
255
257
  h5: heading,
256
258
  h6: heading,
257
259
  a: { href: isHref, id: isIdValue, ariaDescribedBy: isIdValue, ariaLabel: isString, dataFootnoteRef: isScalar, dataFootnoteBackref: isScalar, className: isClass },
258
- img: { src: isSrc, alt: isString },
260
+ img: { src: isSrc, alt: isString, width: isPixels, height: isPixels },
259
261
  table: {},
260
262
  th: { scope: matches(/^(row|col|rowgroup|colgroup)$/), align: isAlign },
261
263
  td: { align: isAlign },
@@ -269,7 +271,7 @@ var ATTRS = new Map(
269
271
  video: { src: isSrc, controls: isScalar },
270
272
  audio: { src: isSrc, controls: isScalar },
271
273
  // hyle's sandboxed Mermaid frame (ADR 0001). The renderer emits `sandbox` as ["allow-scripts"]; it is normalized below.
272
- iframe: { sandbox: (v) => v === "allow-scripts" || Array.isArray(v) && v.length === 1 && v[0] === "allow-scripts", srcdoc: isMermaidSrcdoc }
274
+ iframe: { sandbox: (v) => v === "allow-scripts" || Array.isArray(v) && v.length === 1 && v[0] === "allow-scripts", srcdoc: isMermaidSrcdoc, dataLight: isRenderRef, dataDark: isRenderRef }
273
275
  })
274
276
  );
275
277
  var isObject2 = (v) => typeof v === "object" && v !== null;
package/dist/comments.js CHANGED
@@ -1,5 +1,4 @@
1
1
  "use client";
2
- import "./chunk-R5EMI4HQ.js";
3
2
 
4
3
  // src/react/comments.tsx
5
4
  import { useCallback, useEffect as useEffect2, useId, useRef as useRef2, useState as useState2 } from "react";
@@ -157,7 +156,7 @@ var HastLimitError = class extends Error {
157
156
  var MAX_NODES = 2e4;
158
157
  var MAX_TEXT = 512 * 1024;
159
158
  var MAX_DEPTH = 128;
160
- var MAX_SRCDOC = 64 * 1024;
159
+ var MAX_SRCDOC = 1024 * 1024;
161
160
  var DROP = /* @__PURE__ */ new Set(["script", "style", "template", "noscript"]);
162
161
  var VOID = /* @__PURE__ */ new Set(["br", "hr", "img", "input", "path"]);
163
162
  var isString = (v) => typeof v === "string";
@@ -174,6 +173,7 @@ var classTokens = (v) => {
174
173
  };
175
174
  var isClass = (v) => classTokens(v) !== void 0;
176
175
  var isAlign = matches(/^(left|right|center)$/);
176
+ var isPixels = (v) => typeof v === "number" ? Number.isInteger(v) && v > 0 : typeof v === "string" && /^[1-9]\d*$/.test(v);
177
177
  var isLength = matches(/^[\d.]+(em|px|%)?$/);
178
178
  var STYLE_PROPS = /* @__PURE__ */ new Set(["height", "vertical-align", "margin-left", "margin-right", "margin-top", "margin-bottom", "top", "width", "min-width", "border-bottom-width", "padding-left"]);
179
179
  var STYLE_LENGTH = /^(-?\d+(?:\.\d+)?)(em|px|%)?$/;
@@ -208,7 +208,8 @@ var MERMAID_SRCDOC = new RegExp(
208
208
  `^<!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>$`
209
209
  );
210
210
  var isMermaidSrcdoc = (v) => typeof v === "string" && v.length <= MAX_SRCDOC && MERMAID_SRCDOC.test(v);
211
- var MERMAID_FRAME_CSP = `default-src 'none'; script-src ${MERMAID_SCRIPT_URL} 'unsafe-inline'; style-src 'unsafe-inline'; img-src data:`;
211
+ 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})$/;
212
+ var isRenderRef = matches(RENDER_REF);
212
213
  var heading = { id: isIdValue, className: isClass };
213
214
  var ATTRS = new Map(
214
215
  Object.entries({
@@ -233,7 +234,7 @@ var ATTRS = new Map(
233
234
  h5: heading,
234
235
  h6: heading,
235
236
  a: { href: isHref, id: isIdValue, ariaDescribedBy: isIdValue, ariaLabel: isString, dataFootnoteRef: isScalar, dataFootnoteBackref: isScalar, className: isClass },
236
- img: { src: isSrc, alt: isString },
237
+ img: { src: isSrc, alt: isString, width: isPixels, height: isPixels },
237
238
  table: {},
238
239
  th: { scope: matches(/^(row|col|rowgroup|colgroup)$/), align: isAlign },
239
240
  td: { align: isAlign },
@@ -247,7 +248,7 @@ var ATTRS = new Map(
247
248
  video: { src: isSrc, controls: isScalar },
248
249
  audio: { src: isSrc, controls: isScalar },
249
250
  // hyle's sandboxed Mermaid frame (ADR 0001). The renderer emits `sandbox` as ["allow-scripts"]; it is normalized below.
250
- iframe: { sandbox: (v) => v === "allow-scripts" || Array.isArray(v) && v.length === 1 && v[0] === "allow-scripts", srcdoc: isMermaidSrcdoc }
251
+ iframe: { sandbox: (v) => v === "allow-scripts" || Array.isArray(v) && v.length === 1 && v[0] === "allow-scripts", srcdoc: isMermaidSrcdoc, dataLight: isRenderRef, dataDark: isRenderRef }
251
252
  })
252
253
  );
253
254
  var isObject2 = (v) => typeof v === "object" && v !== null;
@@ -257,6 +257,31 @@ function standaloneSvg(svg) {
257
257
  return svg.replace(open, tagText);
258
258
  }
259
259
 
260
+ // src/react/viewer/svg-css.ts
261
+ var SVG_CSS = `
262
+ svg{display:block;position:static!important;width:100%;height:100%;max-width:none!important}
263
+ .hv-n{cursor:pointer;outline:none}
264
+ .hv-n,.hv-e{transition:opacity .15s}
265
+ @media (prefers-reduced-motion:reduce){.hv-n,.hv-e{transition:none}}
266
+ :host(.hv-plain) .hv-n,:host(.hv-plain) .hv-e{transition:none}
267
+ :host(.hv-active) .hv-n:not(.hv-on),:host(.hv-active) .hv-e:not(.hv-on){opacity:var(--hv-dim)}
268
+ .hv-n:focus-visible :is(rect,polygon,circle,ellipse,path){stroke:var(--hv-focus)!important;stroke-width:calc(3px / var(--hv-k,1))!important}
269
+ .hv-n.hv-nb :is(rect,polygon,circle,ellipse,path){stroke:var(--hv-accent)!important;stroke-width:calc(2px / var(--hv-k,1))!important}
270
+ .hv-n.hv-up :is(rect,polygon,circle,ellipse,path){stroke:var(--hv-up)!important;stroke-width:calc(2.5px / var(--hv-k,1))!important}
271
+ .hv-n.hv-down :is(rect,polygon,circle,ellipse,path){stroke:var(--hv-down)!important;stroke-width:calc(2.5px / var(--hv-k,1))!important}
272
+ .hv-n.hv-sel :is(rect,polygon,circle,ellipse,path){stroke:var(--hv-accent)!important;stroke-width:calc(3.5px / var(--hv-k,1))!important}
273
+ .hv-n.hv-hit :is(rect,polygon,circle,ellipse,path){stroke:var(--hv-accent)!important;stroke-width:calc(3px / var(--hv-k,1))!important}
274
+ .hv-n.hv-cur :is(rect,polygon,circle,ellipse,path){stroke-width:calc(5px / var(--hv-k,1))!important}
275
+ text.hv-hit,text.hv-hit tspan{fill:var(--hv-accent)!important;font-weight:700}
276
+ text.hv-cur{text-decoration:underline}
277
+ path.hv-nb{stroke:var(--hv-accent)!important;stroke-width:calc(2.5px / var(--hv-k,1))!important}
278
+ path.hv-up{stroke:var(--hv-up)!important;stroke-width:calc(2.5px / var(--hv-k,1))!important}
279
+ path.hv-down{stroke:var(--hv-down)!important;stroke-width:calc(2.5px / var(--hv-k,1))!important}
280
+ path.hv-flow{stroke-dasharray:calc(7px / var(--hv-k,1)) calc(6px / var(--hv-k,1))!important;animation:hv-dash .9s linear infinite}
281
+ @keyframes hv-dash{to{stroke-dashoffset:calc(-26px / var(--hv-k,1))}}
282
+ @media (prefers-reduced-motion:reduce){path.hv-flow{animation:none}}
283
+ `;
284
+
260
285
  // src/react/viewer/view-math.ts
261
286
  var MIN_K = 0.2;
262
287
  var MAX_K = 10;
@@ -355,6 +380,7 @@ var DiagramController = class {
355
380
  constructor(o) {
356
381
  this.o = o;
357
382
  const { viewport: vp, stage, minimap } = o;
383
+ const root = this.root = stage.shadowRoot ?? stage.attachShadow({ mode: "open" });
358
384
  const on = (el, type, fn, opts) => {
359
385
  el.addEventListener(type, fn, opts);
360
386
  this.off.push(() => el.removeEventListener(type, fn, opts));
@@ -364,21 +390,16 @@ var DiagramController = class {
364
390
  on(vp, "pointermove", (e) => this.onMove(e));
365
391
  on(vp, "pointerup", (e) => this.onUp(e));
366
392
  on(vp, "pointercancel", (e) => this.onUp(e, true));
367
- on(stage, "pointerover", (e) => e.pointerType === "mouse" && !this.pointers.size && this.mouseOver(this.keyAt(e.target)));
368
- on(stage, "pointerout", (e) => e.pointerType === "mouse" && !this.pointers.size && this.mouseOver(this.keyAt(e.relatedTarget)));
369
- on(stage, "focusin", (e) => this.onFocusIn(e));
370
- on(stage, "focusout", () => this.focusLeft());
393
+ on(root, "pointerover", (e) => e.pointerType === "mouse" && !this.pointers.size && this.mouseOver(this.keyAt(e.target)));
394
+ on(root, "pointerout", (e) => e.pointerType === "mouse" && !this.pointers.size && this.mouseOver(this.keyAt(e.relatedTarget)));
395
+ on(root, "focusin", (e) => this.onFocusIn(e));
396
+ on(root, "focusout", () => this.focusLeft());
371
397
  on(minimap, "pointerdown", (e) => this.onMiniDown(e));
372
398
  on(minimap, "pointermove", (e) => this.miniDrag && this.miniTo(e));
373
399
  on(minimap, "pointerup", () => this.miniDrag = false);
374
400
  on(minimap, "pointercancel", () => this.miniDrag = false);
375
401
  this.ro = new ResizeObserver(() => this.measure());
376
402
  this.ro.observe(vp);
377
- this.watcher = new MutationObserver(() => {
378
- const now = stage.querySelector("svg");
379
- if (now && now !== this.svg && this.source) this.mount(now, this.source.markup, this.source.idPrefix);
380
- });
381
- this.watcher.observe(stage, { childList: true });
382
403
  this.measure();
383
404
  }
384
405
  o;
@@ -416,8 +437,7 @@ var DiagramController = class {
416
437
  dragging = false;
417
438
  samples = [];
418
439
  ro;
419
- watcher;
420
- source;
440
+ root;
421
441
  miniDrag = false;
422
442
  miniColors = { node: "#888", edge: "#555", view: "#0af", bg: "transparent" };
423
443
  off = [];
@@ -425,16 +445,19 @@ var DiagramController = class {
425
445
  this.anim?.stop();
426
446
  cancelAnimationFrame(this.frame);
427
447
  this.ro?.disconnect();
428
- this.watcher?.disconnect();
429
448
  for (const f of this.off) f();
430
449
  }
431
450
  // ---- mounting -----------------------------------------------------------------------------------------------------------------------
432
- /** (Re)attaches to the SVG now in the stage. A re-mount (theme change) keeps the view and a still-valid pin. */
451
+ /** Shows `markup` in the stage's shadow root and attaches to its SVG. A new SVG (theme change) keeps the view and a still-valid pin. */
452
+ show(markup, idPrefix) {
453
+ this.root.innerHTML = `<style>${SVG_CSS}</style>${markup}`;
454
+ const svg = this.root.querySelector("svg");
455
+ if (svg) this.mount(svg, markup, idPrefix);
456
+ }
433
457
  mount(svg, markup, idPrefix) {
434
458
  const size = svgSize(markup) ?? { w: svg.getBoundingClientRect().width || 600, h: svg.getBoundingClientRect().height || 400 };
435
459
  const first = this.svg === void 0;
436
460
  this.svg = svg;
437
- this.source = { markup, idPrefix };
438
461
  this.content = { x: 0, y: 0, w: size.w, h: size.h };
439
462
  this.o.stage.style.width = `${size.w}px`;
440
463
  this.o.stage.style.height = `${size.h}px`;
@@ -568,8 +591,9 @@ var DiagramController = class {
568
591
  const at = this.local(e);
569
592
  this.pointers.set(e.pointerId, at);
570
593
  if (this.pointers.size === 1) {
571
- const key = this.keyAt(e.target);
572
- this.tap = { at, key, moved: false, link: Boolean(e.target.closest?.("a")), id: e.pointerId };
594
+ const target = e.composedPath()[0];
595
+ const key = this.keyAt(target);
596
+ this.tap = { at, key, moved: false, link: Boolean(target.closest?.("a")), id: e.pointerId };
573
597
  this.start = { view: this.view, at };
574
598
  this.dragging = false;
575
599
  this.samples = [{ t: e.timeStamp, ...at }];
@@ -701,7 +725,7 @@ var DiagramController = class {
701
725
  }
702
726
  focusLeft() {
703
727
  queueMicrotask(() => {
704
- if (this.o.stage.contains(document.activeElement)) return;
728
+ if (this.root.activeElement) return;
705
729
  this.focusKey = null;
706
730
  this.refreshHot();
707
731
  });
@@ -757,7 +781,7 @@ var DiagramController = class {
757
781
  }
758
782
  /** Arrow-key traversal from the focused node. Returns false when the key was not used. */
759
783
  traverse(dir) {
760
- const el = document.activeElement?.closest?.(".hv-n") ?? null;
784
+ const el = this.root.activeElement?.closest?.(".hv-n") ?? null;
761
785
  const key = el && this.stageHas(el) ? this.keyAt(el) : null;
762
786
  if (key === null || !this.graph) return false;
763
787
  const next = pickNeighbour(this.graph, key, dir);
@@ -769,7 +793,7 @@ var DiagramController = class {
769
793
  return true;
770
794
  }
771
795
  stageHas(el) {
772
- return this.o.stage.contains(el);
796
+ return this.root.contains(el);
773
797
  }
774
798
  /** Keyboard commands of the viewer. Returns true when the key was handled (the caller then prevents the default). */
775
799
  key(e) {
@@ -783,7 +807,7 @@ var DiagramController = class {
783
807
  this.set({ ...this.view, x: this.view.x + (dir === "left" ? step : dir === "right" ? -step : 0), y: this.view.y + (dir === "up" ? step : dir === "down" ? -step : 0) });
784
808
  return true;
785
809
  }
786
- const onNode = this.keyAt(document.activeElement);
810
+ const onNode = this.keyAt(this.root.activeElement);
787
811
  switch (e.key) {
788
812
  case "+":
789
813
  case "=":
@@ -978,7 +1002,6 @@ function DiagramViewer({ svg, svgId, source, title, labels, onClose }) {
978
1002
  const [scale, setScale] = useState("2");
979
1003
  const [fullscreen, setFullscreen] = useState(false);
980
1004
  const scoped = useMemo(() => scopeSvg(svg, svgId, ownId.current), [svg, svgId]);
981
- const html = useMemo(() => ({ __html: scoped }), [scoped]);
982
1005
  const say = (message) => {
983
1006
  clearTimeout(toastTimer.current);
984
1007
  setToast(message);
@@ -1000,10 +1023,7 @@ function DiagramViewer({ svg, svgId, source, title, labels, onClose }) {
1000
1023
  ctl.current = null;
1001
1024
  };
1002
1025
  }, []);
1003
- useLayoutEffect(() => {
1004
- const el = stage.current?.querySelector("svg");
1005
- if (el) ctl.current?.mount(el, scoped, `${ownId.current}_`);
1006
- }, [scoped]);
1026
+ useLayoutEffect(() => ctl.current?.show(scoped, `${ownId.current}_`), [scoped]);
1007
1027
  useEffect(() => {
1008
1028
  const d = dialog.current;
1009
1029
  if (!d.open) d.showModal();
@@ -1112,7 +1132,7 @@ function DiagramViewer({ svg, svgId, source, title, labels, onClose }) {
1112
1132
  /* @__PURE__ */ jsx("button", { type: "button", className: "hv-btn", "aria-label": labels.close, title: `${labels.close} (Esc)`, onClick: () => dialog.current?.close(), children: /* @__PURE__ */ jsx(Glyph, { d: ICONS.close }) })
1113
1133
  ] })
1114
1134
  ] }),
1115
- /* @__PURE__ */ jsx("div", { className: "hv-view", ref: viewport, tabIndex: -1, role: "group", "aria-label": title, "aria-describedby": helpId, children: /* @__PURE__ */ jsx("div", { className: "hv-stage", ref: stage, dangerouslySetInnerHTML: html }) }),
1135
+ /* @__PURE__ */ jsx("div", { className: "hv-view", ref: viewport, tabIndex: -1, role: "group", "aria-label": title, "aria-describedby": helpId, children: /* @__PURE__ */ jsx("div", { className: "hv-stage", ref: stage }) }),
1116
1136
  /* @__PURE__ */ jsx("canvas", { className: "hv-mini", ref: minimap, width: 176, height: 120, hidden: !ui.minimap, "aria-hidden": "true" }),
1117
1137
  /* @__PURE__ */ jsxs("div", { className: "hv-foot", children: [
1118
1138
  ui.pinned ? /* @__PURE__ */ jsxs("ul", { className: "hv-legend", "aria-hidden": "true", children: [
@@ -1,5 +1,5 @@
1
1
  import { ElementType, ReactNode, ComponentType, ReactElement } from 'react';
2
- import { L as ListItem, h as ResolvedArticle } from './types-5D6ZD0Wi.cjs';
2
+ import { h as ResolvedArticle, L as ListItem } from './types-Czt887Iv.cjs';
3
3
 
4
4
  type CalloutKind = "note" | "tip" | "warning" | "caution";
5
5
  interface LinkProps {
@@ -11,6 +11,9 @@ interface LinkProps {
11
11
  interface ImageProps {
12
12
  src?: string;
13
13
  alt?: string;
14
+ /** Intrinsic pixel size when hyle knows it; pass both to the host image so the page reserves its box. */
15
+ width?: number;
16
+ height?: number;
14
17
  [prop: string]: unknown;
15
18
  }
16
19
  interface CodeBlockProps {
@@ -23,7 +26,7 @@ interface CodeBlockProps {
23
26
  interface MermaidProps {
24
27
  /** The sandboxed document hyle produced for the diagram. Render it only inside an iframe with `sandbox="allow-scripts"`. */
25
28
  srcDoc: string;
26
- /** The diagram text, extracted from `srcDoc` (at most 20,000 characters); undefined when it could not be extracted. */
29
+ /** The diagram text, extracted from `srcDoc`; undefined when it could not be extracted. */
27
30
  source: string | undefined;
28
31
  title: string;
29
32
  }
@@ -97,6 +100,47 @@ interface EngagementConfig {
97
100
  /** Where the "Sign in" button goes (the host's own sign-in). Without it a signed-out visitor sees the prompt but no button. */
98
101
  signInHref?: string | undefined;
99
102
  }
103
+ /** What the host's SEO callbacks (`ogImage`, `jsonLd.author`) receive: the parts of an article they may key on. */
104
+ interface ArticleRef {
105
+ readonly publication: ResolvedArticle["publication"];
106
+ readonly frontmatter: Record<string, unknown>;
107
+ }
108
+ /** A social card image. `url` is absolute https, or a root-relative path that is joined onto `siteOrigin`; anything else is dropped. */
109
+ interface OgImage {
110
+ readonly url: string;
111
+ readonly width?: number;
112
+ readonly height?: number;
113
+ readonly alt?: string;
114
+ /** MIME type of the image; "image/png" when unset. */
115
+ readonly type?: string;
116
+ }
117
+ /**
118
+ * Structured-data identity supplied by the host. Every `id` is used VERBATIM as a JSON-LD `@id`, so the host controls the
119
+ * exact strings its other pages already declare. Setting this object (even `{}`) switches the article graph to the full form
120
+ * (WebSite, WebPage, publisher and author nodes tied by `@id`).
121
+ */
122
+ interface JsonLdConfig {
123
+ readonly publisher?: {
124
+ readonly id: string;
125
+ readonly name: string; /** Absolute logo URL. */
126
+ readonly logo?: string;
127
+ };
128
+ /** The author; wins over `frontmatter.author` (which is only a fallback for imported documents). With an `id` the author is a shared Person node. */
129
+ readonly author?: (article: ArticleRef) => {
130
+ readonly id?: string;
131
+ readonly name: string;
132
+ readonly url?: string;
133
+ } | undefined;
134
+ /** The per-locale WebSite node the pages belong to. */
135
+ /** Prepends a site-root crumb with this name (item = the locale's home URL) to the article BreadcrumbList. Unset: no root crumb. */
136
+ readonly breadcrumbRoot?: {
137
+ readonly name: string;
138
+ };
139
+ readonly website?: (locale: string) => {
140
+ readonly id: string;
141
+ readonly name: string;
142
+ } | undefined;
143
+ }
100
144
 
101
145
  /**
102
146
  * Embeds: parts of a hyle site inside a page the host owns. Pure markup, server safe, no "use client". Unlike the pages they have
@@ -114,9 +158,11 @@ interface HyleListViewProps extends PageBaseProps {
114
158
  readonly headingLevel?: EmbedHeading | undefined;
115
159
  /** Where "View all" goes (a URL in the host's space); omit to hide it. */
116
160
  readonly moreHref?: string | undefined;
161
+ /** Where "Older posts" goes (built from the list's `next_cursor`); omit to hide it. */
162
+ readonly olderHref?: string | undefined;
117
163
  }
118
- /** Items link to `toHref(canonical_path)`: plain anchors in a flat list, newest first as hyle sent them, no grouping and no pagination. */
119
- declare function HyleListView({ items, layout, title, headingLevel, moreHref, ...base }: HyleListViewProps): ReactElement | null;
164
+ /** 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;
120
166
  interface HyleArticleViewProps extends PageBaseProps {
121
167
  readonly article: ResolvedArticle;
122
168
  /**
@@ -132,4 +178,4 @@ declare function HyleCommentsFallback({ locale }: {
132
178
  locale?: string | undefined;
133
179
  }): ReactElement;
134
180
 
135
- export { type CalloutKind as C, type EngagementConfig as E, type HyleComponents as H, type ImageProps as I, type LinkProps as L, type MermaidProps as M, type PageBaseProps as P, type HyleSlots as a, type EmbedHeading as b, HyleCommentsFallback as c, type CalloutProps as d, type CodeBlockProps as e, HyleArticleView as f, type HyleArticleViewProps as g, HyleListView as h, type HyleListViewProps as i, type ListItemProps as j };
181
+ export { type ArticleRef as A, type CalloutKind as C, type EngagementConfig as E, type HyleComponents as H, type ImageProps as I, type JsonLdConfig as J, type LinkProps as L, type MermaidProps as M, type OgImage as O, type PageBaseProps as P, type HyleSlots as a, type EmbedHeading as b, HyleCommentsFallback as c, type CalloutProps as d, type CodeBlockProps as e, HyleArticleView as f, type HyleArticleViewProps as g, HyleListView as h, type HyleListViewProps as i, type ListItemProps as j };
@@ -1,5 +1,5 @@
1
1
  import { ElementType, ReactNode, ComponentType, ReactElement } from 'react';
2
- import { L as ListItem, h as ResolvedArticle } from './types-5D6ZD0Wi.js';
2
+ import { h as ResolvedArticle, L as ListItem } from './types-Czt887Iv.js';
3
3
 
4
4
  type CalloutKind = "note" | "tip" | "warning" | "caution";
5
5
  interface LinkProps {
@@ -11,6 +11,9 @@ interface LinkProps {
11
11
  interface ImageProps {
12
12
  src?: string;
13
13
  alt?: string;
14
+ /** Intrinsic pixel size when hyle knows it; pass both to the host image so the page reserves its box. */
15
+ width?: number;
16
+ height?: number;
14
17
  [prop: string]: unknown;
15
18
  }
16
19
  interface CodeBlockProps {
@@ -23,7 +26,7 @@ interface CodeBlockProps {
23
26
  interface MermaidProps {
24
27
  /** The sandboxed document hyle produced for the diagram. Render it only inside an iframe with `sandbox="allow-scripts"`. */
25
28
  srcDoc: string;
26
- /** The diagram text, extracted from `srcDoc` (at most 20,000 characters); undefined when it could not be extracted. */
29
+ /** The diagram text, extracted from `srcDoc`; undefined when it could not be extracted. */
27
30
  source: string | undefined;
28
31
  title: string;
29
32
  }
@@ -97,6 +100,47 @@ interface EngagementConfig {
97
100
  /** Where the "Sign in" button goes (the host's own sign-in). Without it a signed-out visitor sees the prompt but no button. */
98
101
  signInHref?: string | undefined;
99
102
  }
103
+ /** What the host's SEO callbacks (`ogImage`, `jsonLd.author`) receive: the parts of an article they may key on. */
104
+ interface ArticleRef {
105
+ readonly publication: ResolvedArticle["publication"];
106
+ readonly frontmatter: Record<string, unknown>;
107
+ }
108
+ /** A social card image. `url` is absolute https, or a root-relative path that is joined onto `siteOrigin`; anything else is dropped. */
109
+ interface OgImage {
110
+ readonly url: string;
111
+ readonly width?: number;
112
+ readonly height?: number;
113
+ readonly alt?: string;
114
+ /** MIME type of the image; "image/png" when unset. */
115
+ readonly type?: string;
116
+ }
117
+ /**
118
+ * Structured-data identity supplied by the host. Every `id` is used VERBATIM as a JSON-LD `@id`, so the host controls the
119
+ * exact strings its other pages already declare. Setting this object (even `{}`) switches the article graph to the full form
120
+ * (WebSite, WebPage, publisher and author nodes tied by `@id`).
121
+ */
122
+ interface JsonLdConfig {
123
+ readonly publisher?: {
124
+ readonly id: string;
125
+ readonly name: string; /** Absolute logo URL. */
126
+ readonly logo?: string;
127
+ };
128
+ /** The author; wins over `frontmatter.author` (which is only a fallback for imported documents). With an `id` the author is a shared Person node. */
129
+ readonly author?: (article: ArticleRef) => {
130
+ readonly id?: string;
131
+ readonly name: string;
132
+ readonly url?: string;
133
+ } | undefined;
134
+ /** The per-locale WebSite node the pages belong to. */
135
+ /** Prepends a site-root crumb with this name (item = the locale's home URL) to the article BreadcrumbList. Unset: no root crumb. */
136
+ readonly breadcrumbRoot?: {
137
+ readonly name: string;
138
+ };
139
+ readonly website?: (locale: string) => {
140
+ readonly id: string;
141
+ readonly name: string;
142
+ } | undefined;
143
+ }
100
144
 
101
145
  /**
102
146
  * Embeds: parts of a hyle site inside a page the host owns. Pure markup, server safe, no "use client". Unlike the pages they have
@@ -114,9 +158,11 @@ interface HyleListViewProps extends PageBaseProps {
114
158
  readonly headingLevel?: EmbedHeading | undefined;
115
159
  /** Where "View all" goes (a URL in the host's space); omit to hide it. */
116
160
  readonly moreHref?: string | undefined;
161
+ /** Where "Older posts" goes (built from the list's `next_cursor`); omit to hide it. */
162
+ readonly olderHref?: string | undefined;
117
163
  }
118
- /** Items link to `toHref(canonical_path)`: plain anchors in a flat list, newest first as hyle sent them, no grouping and no pagination. */
119
- declare function HyleListView({ items, layout, title, headingLevel, moreHref, ...base }: HyleListViewProps): ReactElement | null;
164
+ /** 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;
120
166
  interface HyleArticleViewProps extends PageBaseProps {
121
167
  readonly article: ResolvedArticle;
122
168
  /**
@@ -132,4 +178,4 @@ declare function HyleCommentsFallback({ locale }: {
132
178
  locale?: string | undefined;
133
179
  }): ReactElement;
134
180
 
135
- export { type CalloutKind as C, type EngagementConfig as E, type HyleComponents as H, type ImageProps as I, type LinkProps as L, type MermaidProps as M, type PageBaseProps as P, type HyleSlots as a, type EmbedHeading as b, HyleCommentsFallback as c, type CalloutProps as d, type CodeBlockProps as e, HyleArticleView as f, type HyleArticleViewProps as g, HyleListView as h, type HyleListViewProps as i, type ListItemProps as j };
181
+ export { type ArticleRef as A, type CalloutKind as C, type EngagementConfig as E, type HyleComponents as H, type ImageProps as I, type JsonLdConfig as J, type LinkProps as L, type MermaidProps as M, type OgImage as O, type PageBaseProps as P, type HyleSlots as a, type EmbedHeading as b, HyleCommentsFallback as c, type CalloutProps as d, type CodeBlockProps as e, HyleArticleView as f, type HyleArticleViewProps as g, HyleListView as h, type HyleListViewProps as i, type ListItemProps as j };
package/dist/index.cjs CHANGED
@@ -143,7 +143,7 @@ function createHyleClient(options) {
143
143
  const data = reply.parsed?.data;
144
144
  if (data && data.cp === 1 && typeof data.kind === "string" && KINDS.has(data.kind)) {
145
145
  const resolved = data;
146
- if (resolved.kind === "article" && resolved.content.format === "html" && opts.format !== "html") throw failure(reply);
146
+ if (resolved.kind === "article" && resolved.content.format !== "hast" && resolved.content.format !== opts.format) throw failure(reply);
147
147
  return resolved;
148
148
  }
149
149
  throw failure(reply);
@@ -363,17 +363,20 @@ function okResponse(purged) {
363
363
  // src/sitemap.ts
364
364
  var PAGE_LIMIT = 100;
365
365
  var DEFAULT_MAX_PAGES = 20;
366
- var SECTION_SLUG = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
367
366
  var UNSAFE_PATH = /[\\?#<>&"'\u0000- \u007f]/;
367
+ var LOCALE_TAG = /^[a-z]{2,3}(-[A-Za-z0-9]{2,8})*$/;
368
+ var isSitePath = (path) => typeof path === "string" && path.startsWith("/") && !path.startsWith("//") && !UNSAFE_PATH.test(path);
369
+ function safeAlternates(raw) {
370
+ const kept = (raw ?? []).filter((a) => typeof a.locale === "string" && LOCALE_TAG.test(a.locale) && isSitePath(a.canonical_path));
371
+ return kept.length > 0 ? kept.map((a) => ({ locale: a.locale, path: a.canonical_path })) : void 0;
372
+ }
368
373
  async function listPublicationPaths(options) {
369
374
  const maxPages = options.maxPages ?? DEFAULT_MAX_PAGES;
370
375
  const prefix = `${options.basePath}/`;
371
- const indexes = [options.basePath || "/"];
372
- for (const slug of options.sections ?? []) if (slug !== "posts" && SECTION_SLUG.test(slug)) indexes.push(`${options.basePath}/${slug}`);
373
376
  const found = /* @__PURE__ */ new Map();
374
377
  let complete = true;
375
378
  try {
376
- for (const index of new Set(indexes)) {
379
+ for (const index of [options.basePath || "/"]) {
377
380
  let cursor;
378
381
  for (let page = 0; page < maxPages; page++) {
379
382
  const result = await options.client.resolve({
@@ -387,7 +390,16 @@ async function listPublicationPaths(options) {
387
390
  break;
388
391
  }
389
392
  for (const item of result.items) {
390
- if (item.canonical_path.startsWith(prefix) && !UNSAFE_PATH.test(item.canonical_path)) found.set(item.canonical_path, item.published_at);
393
+ if (!item.canonical_path.startsWith(prefix) || UNSAFE_PATH.test(item.canonical_path)) continue;
394
+ const alternates = safeAlternates(item.alternates);
395
+ found.set(item.canonical_path, {
396
+ path: item.canonical_path,
397
+ publishedAt: item.published_at,
398
+ ...typeof item.updated_at === "string" ? { updatedAt: item.updated_at } : {},
399
+ ...alternates ? { alternates } : {},
400
+ title: item.title,
401
+ description: item.description
402
+ });
391
403
  }
392
404
  if (!result.next_cursor) break;
393
405
  if (page === maxPages - 1) complete = false;
@@ -397,7 +409,7 @@ async function listPublicationPaths(options) {
397
409
  } catch {
398
410
  complete = false;
399
411
  }
400
- return { paths: [...found].map(([path, publishedAt]) => ({ path, publishedAt })), complete };
412
+ return { paths: [...found.values()], complete };
401
413
  }
402
414
 
403
415
  // src/route-check.ts