@tdacorp/hyle-sdk 0.17.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 (92) hide show
  1. package/README.md +261 -42
  2. package/dist/check-routes-bin.js +190 -53
  3. package/dist/{chunk-6VOHFFA5.js → chunk-7T5EEJHK.js} +2 -2
  4. package/dist/chunk-DUPT6XLB.js +57 -0
  5. package/dist/chunk-IW3TUD4G.js +841 -0
  6. package/dist/{chunk-MGSUQBDW.js → chunk-KU7LWK4E.js} +249 -24
  7. package/dist/{chunk-BUJFMR3M.js → chunk-QVYQM5R2.js} +15 -6
  8. package/dist/chunk-SFFBZFEN.js +178 -0
  9. package/dist/chunk-U74B7AUG.js +398 -0
  10. package/dist/chunk-ZIW6FDU2.js +1126 -0
  11. package/dist/client-BGjmEWhN.d.cts +207 -0
  12. package/dist/client-D0LTpr3Y.d.ts +207 -0
  13. package/dist/code-copy.cjs +74 -0
  14. package/dist/code-copy.d.cts +18 -0
  15. package/dist/code-copy.d.ts +18 -0
  16. package/dist/code-copy.js +50 -0
  17. package/dist/comments.cjs +738 -280
  18. package/dist/comments.d.cts +66 -3
  19. package/dist/comments.d.ts +66 -3
  20. package/dist/comments.js +419 -331
  21. package/dist/{diagram-viewer-FJPED4SN.js → diagram-viewer-XY3CG75U.js} +62 -21
  22. package/dist/docs-enhance.cjs +7 -4
  23. package/dist/docs-enhance.d.cts +5 -3
  24. package/dist/docs-enhance.d.ts +5 -3
  25. package/dist/docs-enhance.js +8 -5
  26. package/dist/{embed-DNTZ2UXv.d.ts → embed-CbtsbZs3.d.cts} +5 -3
  27. package/dist/{embed-BmdwA2G9.d.cts → embed-Cf_2ZR5x.d.ts} +5 -3
  28. package/dist/fragment-alias.cjs +51 -0
  29. package/dist/fragment-alias.d.cts +7 -0
  30. package/dist/fragment-alias.d.ts +7 -0
  31. package/dist/fragment-alias.js +27 -0
  32. package/dist/html.cjs +886 -0
  33. package/dist/html.d.cts +20 -0
  34. package/dist/html.d.ts +20 -0
  35. package/dist/html.js +45 -0
  36. package/dist/index.cjs +244 -24
  37. package/dist/index.d.cts +22 -68
  38. package/dist/index.d.ts +22 -68
  39. package/dist/index.js +12 -2
  40. package/dist/{labels-nmukKYgL.d.cts → labels-CrA-iqTN.d.cts} +9 -0
  41. package/dist/{labels-nmukKYgL.d.ts → labels-CrA-iqTN.d.ts} +9 -0
  42. package/dist/mermaid-diagram.cjs +441 -125
  43. package/dist/mermaid-diagram.d.cts +23 -7
  44. package/dist/mermaid-diagram.d.ts +23 -7
  45. package/dist/mermaid-diagram.js +213 -51
  46. package/dist/mermaid-image.cjs +137 -60
  47. package/dist/mermaid-image.d.cts +4 -3
  48. package/dist/mermaid-image.d.ts +4 -3
  49. package/dist/mermaid-image.js +27 -28
  50. package/dist/next.cjs +836 -304
  51. package/dist/next.d.cts +45 -20
  52. package/dist/next.d.ts +45 -20
  53. package/dist/next.js +151 -40
  54. package/dist/print-coordinator.cjs +157 -0
  55. package/dist/print-coordinator.d.cts +27 -0
  56. package/dist/print-coordinator.d.ts +27 -0
  57. package/dist/print-coordinator.js +83 -0
  58. package/dist/react.cjs +603 -240
  59. package/dist/react.d.cts +148 -30
  60. package/dist/react.d.ts +148 -30
  61. package/dist/react.js +26 -4
  62. package/dist/reactions.cjs +653 -0
  63. package/dist/reactions.d.cts +27 -0
  64. package/dist/reactions.d.ts +27 -0
  65. package/dist/reactions.js +364 -0
  66. package/dist/{resolve-euZ4-aC9.d.cts → resolve-BnIv7aB7.d.cts} +2 -2
  67. package/dist/{resolve-Ae7UFjsQ.d.ts → resolve-BysHtZ_i.d.ts} +2 -2
  68. package/dist/revalidation-callback-BQl77tQR.d.cts +75 -0
  69. package/dist/revalidation-callback-BQl77tQR.d.ts +75 -0
  70. package/dist/sanitize-BpY_AdZh.d.cts +23 -0
  71. package/dist/sanitize-BpY_AdZh.d.ts +23 -0
  72. package/dist/styles.css +100 -29
  73. package/dist/toc-spy.cjs +60 -0
  74. package/dist/toc-spy.d.cts +15 -0
  75. package/dist/toc-spy.d.ts +15 -0
  76. package/dist/toc-spy.js +36 -0
  77. package/dist/{types-Czt887Iv.d.cts → types-D09Z072G.d.cts} +57 -2
  78. package/dist/{types-Czt887Iv.d.ts → types-D09Z072G.d.ts} +57 -2
  79. package/dist/use-cache.cjs +89 -13
  80. package/dist/use-cache.d.cts +12 -5
  81. package/dist/use-cache.d.ts +12 -5
  82. package/dist/use-cache.js +8 -8
  83. package/dist/youtube-facade.cjs +50 -0
  84. package/dist/youtube-facade.d.cts +17 -0
  85. package/dist/youtube-facade.d.ts +17 -0
  86. package/dist/youtube-facade.js +26 -0
  87. package/package.json +16 -3
  88. package/dist/chunk-67IOIAVW.js +0 -35
  89. package/dist/chunk-DMK4XQLU.js +0 -1556
  90. package/dist/chunk-PJMJMP66.js +0 -63
  91. package/dist/revalidation-callback-D7Ms_Puz.d.cts +0 -42
  92. package/dist/revalidation-callback-D7Ms_Puz.d.ts +0 -42
package/dist/comments.js CHANGED
@@ -1,134 +1,114 @@
1
1
  "use client";
2
+ import {
3
+ Icon,
4
+ ReactionBar,
5
+ arrangeThread,
6
+ arrivesAs,
7
+ call,
8
+ fetchNext,
9
+ fetchPages,
10
+ isObject,
11
+ isSortable,
12
+ kindName,
13
+ nextVote,
14
+ stillUnseen,
15
+ useReactions
16
+ } from "./chunk-U74B7AUG.js";
2
17
 
3
18
  // src/react/comments.tsx
4
- import { useCallback, useEffect as useEffect2, useId, useRef as useRef2, useState as useState2 } from "react";
19
+ import { useEffect as useEffect3, useId, useRef as useRef4, useState as useState4 } from "react";
5
20
 
6
- // src/react/comments-api.ts
7
- var CSRF_HEADER = "x-hyle-engage";
8
- var TIMEOUT_MS = 15e3;
9
- async function call(endpoint, method, path, body) {
10
- try {
11
- const res = await fetch(`${endpoint}${path}`, {
12
- method,
13
- credentials: "same-origin",
14
- cache: "no-store",
15
- headers: { accept: "application/json", [CSRF_HEADER]: "1", ...body ? { "content-type": "application/json" } : {} },
16
- ...body ? { body: JSON.stringify(body) } : {},
17
- signal: AbortSignal.timeout(TIMEOUT_MS)
18
- });
19
- let data;
20
- try {
21
- data = (await res.json()).data;
22
- } catch {
23
- }
24
- const retry = Number(res.headers.get("retry-after"));
25
- return { status: res.status, data, retryAfter: Number.isFinite(retry) && retry > 0 ? retry : void 0 };
26
- } catch {
27
- return { status: 0, data: void 0, retryAfter: void 0 };
28
- }
29
- }
30
- var isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
31
- var count = (v) => typeof v === "number" && Number.isFinite(v) && v >= 0 ? Math.trunc(v) : 0;
32
- function toComment(raw) {
33
- if (!isObject(raw) || typeof raw.id !== "string" || typeof raw.created_at !== "string") return void 0;
34
- const depth = typeof raw.depth === "number" ? Math.min(4, Math.max(1, Math.trunc(raw.depth))) : 1;
35
- const author = isObject(raw.author) && typeof raw.author.name === "string" ? raw.author.name : void 0;
36
- const name = typeof raw.author_name === "string" ? raw.author_name : author;
37
- const body = isObject(raw.body) && raw.body.format === "hast" ? { format: "hast", tree: raw.body.tree } : null;
38
- const removed = raw.removed === true || body === null;
39
- return {
40
- id: raw.id,
41
- parent_id: typeof raw.parent_id === "string" ? raw.parent_id : null,
42
- depth,
43
- author_name: name ?? null,
44
- created_at: raw.created_at,
45
- edited_at: typeof raw.edited_at === "string" ? raw.edited_at : null,
46
- like_count: count(raw.like_count),
47
- removed,
48
- ...removed && (raw.removed_by === "moderator" || raw.removed_by === "author") ? { removed_by: raw.removed_by } : {},
49
- body,
50
- // Viewer members exist only on a live comment of a viewer-aware listing; a tombstone never carries them.
51
- ...!removed && typeof raw.mine === "boolean" ? { mine: raw.mine, liked_by_me: raw.liked_by_me === true, can_edit_until: typeof raw.can_edit_until === "string" ? raw.can_edit_until : null } : {}
52
- };
53
- }
54
- function toHeld(raw) {
55
- if (!isObject(raw) || typeof raw.id !== "string" || typeof raw.created_at !== "string" || !isObject(raw.body) || raw.body.format !== "hast") return void 0;
56
- const author = isObject(raw.author) && typeof raw.author.name === "string" ? raw.author.name : null;
57
- return {
58
- id: raw.id,
59
- parent_id: typeof raw.parent_id === "string" ? raw.parent_id : null,
60
- depth: typeof raw.depth === "number" ? Math.min(4, Math.max(1, Math.trunc(raw.depth))) : 1,
61
- author_name: author,
62
- created_at: raw.created_at,
63
- edited_at: typeof raw.edited_at === "string" ? raw.edited_at : null,
64
- can_edit_until: typeof raw.can_edit_until === "string" ? raw.can_edit_until : null,
65
- body: { format: "hast", tree: raw.body.tree }
66
- };
67
- }
68
- function parseListing(data) {
69
- if (!isObject(data) || data.kind !== "comments" || !Array.isArray(data.comments)) return void 0;
70
- const comments = data.comments.map(toComment).filter((c) => c !== void 0);
71
- const viewer = Array.isArray(data.mine_held) ? { liked_by_me: data.liked_by_me === true, mine_held: data.mine_held.slice(0, 5).map(toHeld).filter((h) => h !== void 0) } : {};
72
- return { cp: 1, kind: "comments", publication_id: String(data.publication_id ?? ""), comment_count: count(data.comment_count), like_count: count(data.like_count), truncated: data.truncated === true, comments, ...viewer };
73
- }
74
- var untilMs = (iso) => {
75
- const t = iso ? Date.parse(iso) : NaN;
76
- return Number.isFinite(t) ? t : void 0;
77
- };
78
- function buildThread(listing, localHeld) {
79
- const byId = /* @__PURE__ */ new Map();
80
- const roots = [];
81
- const place = (node, parentId) => {
82
- const parent = parentId ? byId.get(parentId) : void 0;
83
- (parent ? parent.kids : roots).push(node);
84
- };
85
- for (const c of listing.comments) {
86
- if (byId.has(c.id)) continue;
87
- const removed = c.removed;
88
- const node = {
89
- id: c.id,
90
- depth: c.depth,
91
- status: removed ? "removed" : "visible",
92
- removedBy: removed ? c.removed_by : void 0,
93
- mine: !removed && c.mine === true,
94
- canEditUntil: untilMs(c.can_edit_until),
95
- likedByMe: !removed && c.liked_by_me === true,
96
- name: removed ? null : c.author_name ?? null,
97
- createdAt: c.created_at,
98
- editedAt: c.edited_at,
99
- likes: c.like_count,
100
- tree: c.body?.tree,
101
- text: void 0,
102
- kids: []
103
- };
104
- place(node, c.parent_id === c.id ? null : c.parent_id);
105
- byId.set(c.id, node);
106
- }
107
- const mine = [];
108
- const addHeld = (node, parentId, oldestFirst) => {
109
- const parent = parentId ? byId.get(parentId) : void 0;
110
- if (parent) parent.kids.push(node);
111
- else if (oldestFirst) mine.unshift(node);
112
- else mine.push(node);
113
- };
114
- const heldIds = /* @__PURE__ */ new Set();
115
- for (const h of listing.mine_held ?? []) {
116
- heldIds.add(h.id);
117
- const parent = h.parent_id ? byId.get(h.parent_id) : void 0;
118
- addHeld({ id: h.id, depth: Math.min(4, (parent?.depth ?? h.depth - 1) + 1), status: "held", removedBy: void 0, mine: true, canEditUntil: untilMs(h.can_edit_until), likedByMe: false, name: h.author_name, createdAt: h.created_at, editedAt: h.edited_at, likes: 0, tree: h.body?.tree, text: void 0, kids: [] }, h.parent_id, true);
119
- }
120
- if (listing.mine_held === void 0) {
121
- for (const h of localHeld) {
122
- if (byId.has(h.id) || heldIds.has(h.id)) continue;
123
- const parent = h.parentId ? byId.get(h.parentId) : void 0;
124
- addHeld({ id: h.id, depth: Math.min(4, (parent?.depth ?? 0) + 1), status: "held", removedBy: void 0, mine: true, canEditUntil: void 0, likedByMe: false, name: h.name, createdAt: h.createdAt, editedAt: null, likes: 0, tree: void 0, text: h.text, kids: [] }, h.parentId, false);
125
- }
126
- }
127
- return [...mine, ...roots];
21
+ // src/react/comments-listing.ts
22
+ import { useCallback, useEffect, useRef, useState } from "react";
23
+ function useCommentListing(endpoint, path, initial, active, onFresh, onReset) {
24
+ const [listing, setListing] = useState(initial ?? "loading");
25
+ const [order, setOrder] = useState("newest");
26
+ const [served, setServed] = useState(void 0);
27
+ const data = useRef({ listing: initial, order: "newest", pages: 1, sort: void 0 });
28
+ const legacy = useRef(false);
29
+ const queue = useRef(Promise.resolve());
30
+ const generation = useRef(0);
31
+ const callbacks = useRef({ onFresh, onReset });
32
+ callbacks.current = { onFresh, onReset };
33
+ const enqueue = useCallback((op) => {
34
+ const mine = generation.current;
35
+ const stale = () => mine !== generation.current;
36
+ const job = queue.current.then(() => stale() ? void 0 : op(stale));
37
+ queue.current = job.catch(() => void 0);
38
+ return job;
39
+ }, []);
40
+ const commit = useCallback((next) => {
41
+ data.current = next;
42
+ setListing(next.listing);
43
+ setOrder(next.order);
44
+ setServed(next.sort);
45
+ }, []);
46
+ const learn = useCallback((asked, r) => {
47
+ if (asked === "newest" && r.listing && r.sort === void 0) legacy.current = true;
48
+ return r;
49
+ }, []);
50
+ const reload = useCallback(
51
+ (silent) => enqueue(async (stale) => {
52
+ const { order: current, pages } = data.current;
53
+ const r = learn(current, await fetchPages(endpoint, path, current, pages, legacy.current));
54
+ if (stale()) return void 0;
55
+ if (r.status === 404) setListing("off");
56
+ else if (r.listing) {
57
+ commit({ listing: r.listing, order: current, pages: r.pages, sort: r.sort });
58
+ callbacks.current.onFresh(r.listing);
59
+ } else if (!silent) setListing("error");
60
+ return r.listing;
61
+ }),
62
+ [endpoint, path, enqueue, commit, learn]
63
+ );
64
+ const sort = useCallback(
65
+ (next) => enqueue(async (stale) => {
66
+ if (next === data.current.order) return next;
67
+ const r = learn(next, await fetchPages(endpoint, path, next, 1, legacy.current));
68
+ if (stale()) return void 0;
69
+ if (!r.listing) return data.current.order;
70
+ commit({ listing: r.listing, order: next, pages: 1, sort: r.sort });
71
+ callbacks.current.onFresh(r.listing);
72
+ return next;
73
+ }),
74
+ [endpoint, path, enqueue, commit, learn]
75
+ );
76
+ const more = useCallback(
77
+ () => enqueue(async (stale) => {
78
+ const { listing: before, order: current, pages, sort: wire } = data.current;
79
+ if (!before?.next_cursor) return void 0;
80
+ const r = await fetchNext(endpoint, path, current, { listing: before, pages, sort: wire }, legacy.current);
81
+ if (stale()) return void 0;
82
+ if (r.restarted) learn(current, r);
83
+ if (!r.listing) return { ok: false };
84
+ const known = new Set(before.comments.map((c) => c.id));
85
+ commit({ listing: r.listing, order: current, pages: r.pages, sort: r.sort });
86
+ if (r.restarted) callbacks.current.onFresh(r.listing);
87
+ return { ok: true, listing: r.listing, sort: r.sort, added: new Set(r.listing.comments.filter((c) => !c.removed && !known.has(c.id)).map((c) => c.id)) };
88
+ }),
89
+ [endpoint, path, enqueue, commit, learn]
90
+ );
91
+ useEffect(() => {
92
+ data.current = { listing: initial, order: "newest", pages: 1, sort: void 0 };
93
+ legacy.current = false;
94
+ queue.current = Promise.resolve();
95
+ setListing(initial ?? "loading");
96
+ setOrder("newest");
97
+ setServed(void 0);
98
+ callbacks.current.onReset();
99
+ return () => void (generation.current += 1);
100
+ }, [endpoint, path, initial]);
101
+ useEffect(() => {
102
+ if (active) void reload(initial !== void 0);
103
+ }, [active, reload, initial]);
104
+ return { listing, order, served, reload, sort, more, retry: () => {
105
+ setListing("loading");
106
+ void reload(false);
107
+ } };
128
108
  }
129
109
 
130
110
  // src/react/comments-parts.tsx
131
- import { useEffect, useRef, useState } from "react";
111
+ import { useEffect as useEffect2, useRef as useRef3, useState as useState3 } from "react";
132
112
 
133
113
  // src/react/comments-body.tsx
134
114
  import { toJsxRuntime } from "hast-util-to-jsx-runtime";
@@ -138,12 +118,17 @@ import { jsx, jsxs } from "react/jsx-runtime";
138
118
  // src/asset-path.ts
139
119
  var ASSET_ROUTE_PREFIX = "/api/hyle/assets";
140
120
  var UUID = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
141
- 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";
142
122
  var ASSET_FILE = new RegExp(`^${UUID}(?:\\.(?:${EXTENSIONS}))?$`);
143
- 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");
144
129
  function hostAssetSrc(src) {
145
- const file = HYLE_ASSET_URL.exec(src)?.[1];
146
- 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;
147
132
  }
148
133
 
149
134
  // src/react/sanitize.ts
@@ -164,8 +149,15 @@ var isScalar = (v) => typeof v === "string" || typeof v === "number" || typeof v
164
149
  var matches = (re) => (v) => typeof v === "string" && re.test(v);
165
150
  var ID_PREFIX = "user-content-";
166
151
  var scopeId = (id) => id.startsWith(ID_PREFIX) ? id : ID_PREFIX + id;
167
- var ID_BODY = /^[\p{L}\p{N}_:.-]{1,180}$/u;
168
- var isIdValue = (v) => typeof v === "string" && ID_BODY.test(v.startsWith(ID_PREFIX) ? v.slice(ID_PREFIX.length) : v);
152
+ var ID_BODY = /^[\p{L}\p{M}\p{N}\p{Pc}:.-]{1,180}$/u;
153
+ function isIdValue(v) {
154
+ if (typeof v !== "string") return false;
155
+ try {
156
+ return ID_BODY.test(decodeURIComponent(v.startsWith(ID_PREFIX) ? v.slice(ID_PREFIX.length) : v));
157
+ } catch {
158
+ return false;
159
+ }
160
+ }
169
161
  var CLASS_TOKEN = /^[A-Za-z_][\w:-]*$/;
170
162
  var classTokens = (v) => {
171
163
  const tokens = Array.isArray(v) ? v : typeof v === "string" ? v.split(/\s+/) : [];
@@ -178,6 +170,7 @@ var isLength = matches(/^[\d.]+(em|px|%)?$/);
178
170
  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
171
  var STYLE_LENGTH = /^(-?\d+(?:\.\d+)?)(em|px|%)?$/;
180
172
  var MAX_STYLE_MAGNITUDE = 100;
173
+ var MAX_MARGIN_MAGNITUDE = 20;
181
174
  function isKatexStyle(v, ctx) {
182
175
  if (typeof v !== "string" || !ctx.katex) return false;
183
176
  return v.split(";").filter((d) => d !== "").every((decl) => {
@@ -185,7 +178,8 @@ function isKatexStyle(v, ctx) {
185
178
  if (extra.length > 0 || prop === void 0 || value === void 0) return false;
186
179
  if (prop === "position") return value === "relative";
187
180
  const m = STYLE_LENGTH.exec(value);
188
- return STYLE_PROPS.has(prop) && m !== null && Math.abs(Number(m[1])) <= MAX_STYLE_MAGNITUDE;
181
+ const max = prop.startsWith("margin-") ? MAX_MARGIN_MAGNITUDE : MAX_STYLE_MAGNITUDE;
182
+ return STYLE_PROPS.has(prop) && m !== null && Math.abs(Number(m[1])) <= max;
189
183
  });
190
184
  }
191
185
  function isSafeUrl(value, kind) {
@@ -208,8 +202,10 @@ var MERMAID_SRCDOC = new RegExp(
208
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>$`
209
203
  );
210
204
  var isMermaidSrcdoc = (v) => typeof v === "string" && v.length <= MAX_SRCDOC && MERMAID_SRCDOC.test(v);
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})$/;
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})$`);
212
206
  var isRenderRef = matches(RENDER_REF);
207
+ var YOUTUBE_WATCH = /^https:\/\/www\.youtube\.com\/watch\?v=([A-Za-z0-9_-]{11})$/;
208
+ var youtubeId = (href) => typeof href === "string" ? YOUTUBE_WATCH.exec(href)?.[1] : void 0;
213
209
  var heading = { id: isIdValue, className: isClass };
214
210
  var ATTRS = new Map(
215
211
  Object.entries({
@@ -225,6 +221,7 @@ var ATTRS = new Map(
225
221
  tbody: {},
226
222
  tr: {},
227
223
  ol: {},
224
+ kbd: {},
228
225
  ul: { className: isClass },
229
226
  li: { id: isIdValue, className: isClass },
230
227
  h1: heading,
@@ -233,8 +230,8 @@ var ATTRS = new Map(
233
230
  h4: heading,
234
231
  h5: heading,
235
232
  h6: heading,
236
- a: { href: isHref, id: isIdValue, ariaDescribedBy: isIdValue, ariaLabel: isString, dataFootnoteRef: isScalar, dataFootnoteBackref: isScalar, className: isClass },
237
- img: { src: isSrc, alt: isString, width: isPixels, height: isPixels },
233
+ a: { href: isHref, id: isIdValue, ariaDescribedBy: isIdValue, ariaLabel: isString, dataFootnoteRef: isScalar, dataFootnoteBackref: isScalar, dataEmbed: matches(/^youtube$/), className: isClass },
234
+ img: { src: isSrc, alt: isString, title: isString, width: isPixels, height: isPixels },
238
235
  table: {},
239
236
  th: { scope: matches(/^(row|col|rowgroup|colgroup)$/), align: isAlign },
240
237
  td: { align: isAlign },
@@ -257,8 +254,10 @@ function textOf(node, depth = 0) {
257
254
  if (node.type === "text") return typeof node.value === "string" ? node.value : "";
258
255
  return Array.isArray(node.children) ? node.children.map((c) => textOf(c, depth + 1)).join("") : "";
259
256
  }
257
+ var holdsEmbed = (node, depth = 0) => isObject2(node) && depth <= MAX_DEPTH && (isObject2(node.properties) && "dataEmbed" in node.properties || Array.isArray(node.children) && node.children.some((c) => holdsEmbed(c, depth + 1)));
258
+ var collapse = (text) => text.replace(/\s+/g, " ").trim();
260
259
  var CALLOUT_MARKER = /^\s*\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*/i;
261
- var CALLOUT_KIND = { note: "note", tip: "tip", important: "warning", warning: "warning", caution: "caution" };
260
+ var CALLOUT_KIND = { note: "note", tip: "tip", important: "important", warning: "warning", caution: "caution" };
262
261
  function toCallout(children) {
263
262
  const first = children.find((c) => c.type === "element");
264
263
  const lead = first?.tagName === "p" ? first.children[0] : void 0;
@@ -270,6 +269,21 @@ function toCallout(children) {
270
269
  const kind = CALLOUT_KIND[(marker[1] ?? "note").toLowerCase()] ?? "note";
271
270
  return { type: "element", tagName: "callout", properties: { kind }, children: [...body, ...children.slice(children.indexOf(first) + 1)] };
272
271
  }
272
+ var isBlank = (node) => node.type === "text" && node.value.trim() === "";
273
+ function soleElement(children) {
274
+ const [only, ...more] = children.filter((c) => !isBlank(c));
275
+ return more.length === 0 && only?.type === "element" ? only : void 0;
276
+ }
277
+ function toFigure(children) {
278
+ const only = soleElement(children);
279
+ const img = only?.tagName === "a" ? soleElement(only.children) : only;
280
+ if (!only || img?.tagName !== "img" || typeof img.properties.src !== "string") return void 0;
281
+ const { title, ...properties } = img.properties;
282
+ const bare = { ...img, properties };
283
+ const media = only === img ? bare : { ...only, children: [bare] };
284
+ const caption = typeof title === "string" && title.trim() ? [{ type: "element", tagName: "figcaption", properties: {}, children: [{ type: "text", value: title }] }] : [];
285
+ return { type: "element", tagName: "figure", properties: { dataSlotComponent: "Image" }, children: [media, ...caption] };
286
+ }
273
287
  function clean(node, depth, ctx, budget) {
274
288
  if (!isObject2(node) || depth > MAX_DEPTH) return [];
275
289
  if (++budget.nodes > MAX_NODES) throw new HastLimitError("content has too many nodes");
@@ -303,6 +317,11 @@ function clean(node, depth, ctx, budget) {
303
317
  }
304
318
  for (const key of ["id", "ariaDescribedBy"]) if (typeof properties[key] === "string") properties[key] = scopeId(properties[key]);
305
319
  if (tag === "a" && typeof properties.href === "string" && properties.href.trim().startsWith("#")) properties.href = `#${scopeId(properties.href.trim().slice(1))}`;
320
+ if (tag === "a" && properties.dataEmbed !== void 0 && youtubeId(properties.href) === void 0) delete properties.dataEmbed;
321
+ if (tag === "p") {
322
+ const figure = toFigure(children);
323
+ if (figure) return [figure];
324
+ }
306
325
  if (tag === "blockquote") {
307
326
  const callout = toCallout(children);
308
327
  if (callout) return [callout];
@@ -314,9 +333,9 @@ function sanitizeHast(tree, title, description) {
314
333
  const raw = isObject2(tree) && tree.type === "root" && Array.isArray(tree.children) ? tree.children : [];
315
334
  const elements = raw.filter((n) => isObject2(n) && n.type === "element");
316
335
  const [first] = elements;
317
- const skip = title !== void 0 && isObject2(first) && first.tagName === "h1" && textOf(first).trim() === title.trim() ? first : void 0;
336
+ const skip = title !== void 0 && isObject2(first) && first.tagName === "h1" && collapse(textOf(first)) === collapse(title) ? first : void 0;
318
337
  const lead = elements[skip ? 1 : 0];
319
- const repeat = description && isObject2(lead) && lead.tagName === "p" && textOf(lead).trim().startsWith(description.trim()) ? lead : void 0;
338
+ const repeat = description && isObject2(lead) && lead.tagName === "p" && collapse(textOf(lead)) === collapse(description) && !holdsEmbed(lead) ? lead : void 0;
320
339
  const budget = { nodes: 0, text: 0 };
321
340
  return { type: "root", children: raw.filter((n) => n !== skip && n !== repeat).flatMap((n) => clean(n, 0, { katex: false }, budget)) };
322
341
  }
@@ -401,56 +420,58 @@ function hastToMarkdown(tree) {
401
420
  }
402
421
  }
403
422
 
404
- // src/react/icons.tsx
405
- import { Fragment as Fragment2, jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
406
- var SHAPES = {
407
- info: /* @__PURE__ */ jsxs2(Fragment2, { children: [
408
- /* @__PURE__ */ jsx3("circle", { cx: "8", cy: "8", r: "6" }),
409
- /* @__PURE__ */ jsx3("path", { d: "M8 7.3V11M8 5v.1" })
410
- ] }),
411
- "check-circle": /* @__PURE__ */ jsxs2(Fragment2, { children: [
412
- /* @__PURE__ */ jsx3("circle", { cx: "8", cy: "8", r: "6" }),
413
- /* @__PURE__ */ jsx3("path", { d: "m5.3 8.3 1.9 1.9 3.5-3.9" })
414
- ] }),
415
- alert: /* @__PURE__ */ jsx3("path", { d: "M8 2 1.8 13h12.4zM8 6.5v3M8 11.3v.1" }),
416
- "x-circle": /* @__PURE__ */ jsxs2(Fragment2, { children: [
417
- /* @__PURE__ */ jsx3("circle", { cx: "8", cy: "8", r: "6" }),
418
- /* @__PURE__ */ jsx3("path", { d: "m5.8 5.8 4.4 4.4M10.2 5.8l-4.4 4.4" })
419
- ] }),
420
- calendar: /* @__PURE__ */ jsxs2(Fragment2, { children: [
421
- /* @__PURE__ */ jsx3("rect", { x: "2", y: "3", width: "12", height: "11", rx: "1.3" }),
422
- /* @__PURE__ */ jsx3("path", { d: "M2 6.5h12M5.5 1.7v2.6M10.5 1.7v2.6" })
423
- ] }),
424
- globe: /* @__PURE__ */ jsxs2(Fragment2, { children: [
425
- /* @__PURE__ */ jsx3("circle", { cx: "8", cy: "8", r: "6" }),
426
- /* @__PURE__ */ jsx3("path", { d: "M2 8h12M8 2c2 1.7 2.8 3.7 2.8 6S10 12.3 8 14M8 2C6 3.7 5.2 5.7 5.2 8S6 12.3 8 14" })
427
- ] }),
428
- file: /* @__PURE__ */ jsxs2(Fragment2, { children: [
429
- /* @__PURE__ */ jsx3("path", { d: "M4 1.8h5l3 3v8.4a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V2.8a1 1 0 0 1 1-1z" }),
430
- /* @__PURE__ */ jsx3("path", { d: "M9 1.8v3h3" })
431
- ] }),
432
- chev: /* @__PURE__ */ jsx3("path", { d: "m6 3.5 4.5 4.5L6 12.5" }),
433
- "chev-down": /* @__PURE__ */ jsx3("path", { d: "m3.5 6 4.5 4.5L12.5 6" }),
434
- "chev-left": /* @__PURE__ */ jsx3("path", { d: "M10 3.5 5.5 8 10 12.5" }),
435
- x: /* @__PURE__ */ jsx3("path", { d: "m4 4 8 8M12 4l-8 8" }),
436
- heart: /* @__PURE__ */ jsx3("path", { d: "M8 13.5S2.2 10 2.2 6.1A3 3 0 0 1 8 5a3 3 0 0 1 5.8 1.1C13.8 10 8 13.5 8 13.5z" }),
437
- reply: /* @__PURE__ */ jsx3("path", { d: "M6.5 3.5 2.5 7.5l4 4M2.5 7.5h6a5 5 0 0 1 5 5" }),
438
- clock: /* @__PURE__ */ jsxs2(Fragment2, { children: [
439
- /* @__PURE__ */ jsx3("circle", { cx: "8", cy: "8", r: "6" }),
440
- /* @__PURE__ */ jsx3("path", { d: "M8 4.5V8l2.3 1.5" })
441
- ] }),
442
- ban: /* @__PURE__ */ jsxs2(Fragment2, { children: [
443
- /* @__PURE__ */ jsx3("circle", { cx: "8", cy: "8", r: "6" }),
444
- /* @__PURE__ */ jsx3("path", { d: "m3.8 12.2 8.4-8.4" })
445
- ] }),
446
- refresh: /* @__PURE__ */ jsx3("path", { d: "M13 8a5 5 0 1 1-1.6-3.7M13 2.5v2.8h-2.8" })
447
- };
448
- function Icon({ name, className }) {
449
- return /* @__PURE__ */ jsx3("svg", { className: className ? `hyle-ic ${className}` : "hyle-ic", viewBox: "0 0 16 16", "aria-hidden": "true", children: SHAPES[name] });
423
+ // src/react/comments-votes.tsx
424
+ import { useRef as useRef2, useState as useState2 } from "react";
425
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
426
+ function useVotes(endpoint) {
427
+ const [overlay, setOverlay] = useState2({});
428
+ const pending = useRef2(/* @__PURE__ */ new Set());
429
+ async function cast(id, current, clicked) {
430
+ if (pending.current.has(id)) return void 0;
431
+ const next = nextVote(current, clicked);
432
+ pending.current.add(id);
433
+ setOverlay((o) => ({ ...o, [id]: next }));
434
+ const r = await call(endpoint, next.value === null ? "DELETE" : "PUT", "/votes", next.value === null ? { comment_id: id } : { comment_id: id, value: next.value });
435
+ pending.current.delete(id);
436
+ const vote = r.status === 200 && isObject(r.data) && isObject(r.data.vote) ? r.data.vote : void 0;
437
+ if (vote && Number.isSafeInteger(vote.score)) {
438
+ const state = { value: vote.value === 1 || vote.value === -1 ? vote.value : null, score: vote.score };
439
+ setOverlay((o) => ({ ...o, [id]: state }));
440
+ return { ok: true, state };
441
+ }
442
+ setOverlay((o) => ({ ...o, [id]: current }));
443
+ return { ok: false, status: r.status };
444
+ }
445
+ function settle(listing) {
446
+ const known = new Set(listing.comments.filter((c) => c.my_vote !== void 0).map((c) => c.id));
447
+ setOverlay((o) => Object.fromEntries(Object.entries(o).flatMap(([id, v]) => pending.current.has(id) ? [[id, v]] : v.value !== null && !known.has(id) ? [[id, { value: v.value }]] : [])));
448
+ }
449
+ return { overlay, cast, settle, reset: () => setOverlay({}) };
450
+ }
451
+ function VoteButtons({ s, name, state, own, access, signInHref, onVote }) {
452
+ function arrow(value) {
453
+ if (own) return null;
454
+ const icon = /* @__PURE__ */ jsx3(Icon, { name: value === 1 ? "chev-up" : "chev-down" });
455
+ const label = value === 1 ? s.upvote : s.downvote;
456
+ if (access === "out") return /* @__PURE__ */ jsxs2("a", { className: "hyle-cm-btn", href: signInHref, children: [
457
+ icon,
458
+ /* @__PURE__ */ jsx3("span", { className: "hyle-sr", children: value === 1 ? s.upvoteSignIn : s.downvoteSignIn })
459
+ ] });
460
+ if (access !== "in") return /* @__PURE__ */ jsx3("button", { className: "hyle-cm-btn", type: "button", "aria-disabled": "true", "aria-label": label, children: icon });
461
+ return /* @__PURE__ */ jsx3("button", { className: "hyle-cm-btn", type: "button", "aria-label": label, "aria-pressed": state.value === value, onClick: () => onVote(value), children: icon });
462
+ }
463
+ return /* @__PURE__ */ jsxs2("span", { className: "hyle-cm-votes", role: "group", "aria-label": s.votesOn.replace("{name}", () => name), children: [
464
+ arrow(1),
465
+ /* @__PURE__ */ jsxs2("span", { className: "hyle-cm-score", children: [
466
+ /* @__PURE__ */ jsx3("span", { className: "hyle-sr", children: s.score.replace("{n}", String(state.score)) }),
467
+ /* @__PURE__ */ jsx3("span", { "aria-hidden": "true", children: state.score })
468
+ ] }),
469
+ arrow(-1)
470
+ ] });
450
471
  }
451
472
 
452
473
  // src/react/comments-parts.tsx
453
- import { Fragment as Fragment3, jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
474
+ import { Fragment as Fragment2, jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
454
475
  var MAX_CHARS = 4e3;
455
476
  var EDIT_WINDOW_MS = 10 * 60 * 1e3;
456
477
  var MAX_DEPTH2 = 4;
@@ -458,6 +479,7 @@ var fill = (template, values) => template.replace(/\{(\w+)\}/g, (_, k) => String
458
479
  var initials = (name) => name.trim().split(/\s+/).slice(0, 2).map((w) => [...w][0] ?? "").join("").toUpperCase() || "?";
459
480
  var replyButtonId = (ui, id) => `${ui.idp}-reply-${id}`;
460
481
  var nameId = (ui, id) => `${ui.idp}-${id}-n`;
482
+ var accessOf = (ui) => !ui.ready ? "pending" : !ui.me ? "out" : ui.banned ? "blocked" : "in";
461
483
  function relative(iso, now, locale, s) {
462
484
  const seconds = Math.round((now - Date.parse(iso)) / 1e3);
463
485
  if (!Number.isFinite(seconds)) return iso;
@@ -485,51 +507,14 @@ function Avatar({ name }) {
485
507
  function SignInLink({ ui, className, children }) {
486
508
  return /* @__PURE__ */ jsx4("a", { className, href: `#${ui.signInId}`, children });
487
509
  }
488
- function LikeButton({ ui, itemKey, serverCount, serverOn, scope }) {
489
- const { s } = ui;
490
- const state = ui.likes[itemKey];
491
- const count2 = state?.count ?? serverCount;
492
- const on = state?.on ?? serverOn;
493
- const cls = scope === "article" ? "hyle-btn" : "hyle-cm-btn cnt";
494
- const lead = scope === "article" ? on ? s.likedArticle : s.likeArticle : null;
495
- const sr = scope === "article" ? ", " : s.likeComment;
496
- const icon = /* @__PURE__ */ jsx4(Icon, { name: "heart" });
497
- if (ui.ready && !ui.me) {
498
- return /* @__PURE__ */ jsxs3(SignInLink, { ui, className: cls, children: [
499
- icon,
500
- lead ?? null,
501
- scope === "article" ? /* @__PURE__ */ jsxs3(Fragment3, { children: [
502
- " ",
503
- /* @__PURE__ */ jsx4("span", { className: "hyle-sr", children: s.likeArticleSignIn })
504
- ] }) : /* @__PURE__ */ jsx4("span", { className: "hyle-sr", children: s.likeCommentSignIn }),
505
- /* @__PURE__ */ jsx4("span", { children: count2 })
506
- ] });
507
- }
508
- if (ui.banned || !ui.ready) {
509
- return /* @__PURE__ */ jsxs3("button", { className: cls, type: "button", "aria-disabled": "true", children: [
510
- icon,
511
- lead,
512
- scope === "article" ? " " : null,
513
- /* @__PURE__ */ jsx4("span", { className: "hyle-sr", children: sr }),
514
- /* @__PURE__ */ jsx4("span", { children: count2 })
515
- ] });
516
- }
517
- return /* @__PURE__ */ jsxs3("button", { className: cls, type: "button", "aria-pressed": on, onClick: () => ui.actions.like(itemKey, serverCount, serverOn), children: [
518
- icon,
519
- lead,
520
- scope === "article" ? " " : null,
521
- /* @__PURE__ */ jsx4("span", { className: "hyle-sr", children: sr }),
522
- /* @__PURE__ */ jsx4("span", { children: count2 })
523
- ] });
524
- }
525
510
  function Composer({ ui, id, parentId, name, autoFocus, onCancel }) {
526
511
  const { s } = ui;
527
- const [text, setText] = useState("");
528
- const [busy, setBusy] = useState(false);
529
- const [error, setError] = useState(null);
530
- const area = useRef(null);
512
+ const [text, setText] = useState3("");
513
+ const [busy, setBusy] = useState3(false);
514
+ const [error, setError] = useState3(null);
515
+ const area = useRef3(null);
531
516
  const limited = ui.rateLeft > 0;
532
- useEffect(() => {
517
+ useEffect2(() => {
533
518
  if (autoFocus) area.current?.focus();
534
519
  }, [autoFocus]);
535
520
  async function submit() {
@@ -607,11 +592,11 @@ function Composer({ ui, id, parentId, name, autoFocus, onCancel }) {
607
592
  }
608
593
  function EditForm({ ui, node, initial }) {
609
594
  const { s } = ui;
610
- const [text, setText] = useState(initial);
611
- const [busy, setBusy] = useState(false);
612
- const [error, setError] = useState(null);
613
- const area = useRef(null);
614
- useEffect(() => area.current?.focus(), []);
595
+ const [text, setText] = useState3(initial);
596
+ const [busy, setBusy] = useState3(false);
597
+ const [error, setError] = useState3(null);
598
+ const area = useRef3(null);
599
+ useEffect2(() => area.current?.focus(), []);
615
600
  const id = `${ui.idp}-edit-${node.id}`;
616
601
  async function save() {
617
602
  if (busy) return;
@@ -669,15 +654,18 @@ function Actions({ ui, node }) {
669
654
  const until = node.canEditUntil ?? (local ? local.at + EDIT_WINDOW_MS : void 0);
670
655
  const minutes = until === void 0 ? 0 : Math.min(10, Math.ceil((until - Math.max(ui.now, local?.at ?? 0)) / 6e4));
671
656
  const canReply = node.depth < MAX_DEPTH2 && node.status === "visible";
657
+ const vote = ui.votes[node.id];
658
+ const shownVote = { value: vote ? vote.value : node.myVote ?? null, score: vote?.score ?? node.score ?? 0 };
672
659
  if (ui.confirming === node.id) {
673
660
  return /* @__PURE__ */ jsxs3("div", { className: "hyle-cm-acts", role: "group", "aria-label": s.deleteConfirm, children: [
674
661
  /* @__PURE__ */ jsx4("span", { className: "hyle-cm-depth", children: s.deleteConfirm }),
675
662
  /* @__PURE__ */ jsx4("button", { className: "hyle-cm-btn danger", type: "button", onClick: () => ui.actions.remove(node.id), children: s.delete }),
676
663
  /* @__PURE__ */ jsx4("button", { className: "hyle-cm-btn", type: "button", autoFocus: true, onClick: () => ui.actions.confirm(null), children: s.keep })
677
- ] });
664
+ ] }, "confirm");
678
665
  }
679
666
  return /* @__PURE__ */ jsxs3("div", { className: "hyle-cm-acts", children: [
680
- node.status === "visible" ? /* @__PURE__ */ jsx4(LikeButton, { ui, itemKey: node.id, serverCount: node.likes, serverOn: node.likedByMe, scope: "comment" }) : null,
667
+ node.status === "visible" && node.score !== void 0 ? /* @__PURE__ */ jsx4(VoteButtons, { s, name: node.name ?? "", state: shownVote, own: mine, access: accessOf(ui), signInHref: `#${ui.signInId}`, onVote: (clicked) => ui.actions.vote(node.id, shownVote, clicked) }) : null,
668
+ node.status === "visible" ? /* @__PURE__ */ jsx4(ReactionBar, { s, scope: "comment", subject: node.id, likes: node.likes, counts: node.reactions, likedByMe: node.likedByMe, mine: node.myReactions, overlay: ui.reactions, access: accessOf(ui), signInHref: `#${ui.signInId}`, onToggle: (kind, count, on) => ui.actions.react(node.id, kind, count, on) }) : null,
681
669
  canReply && ui.me && !ui.banned ? /* @__PURE__ */ jsxs3("button", { className: "hyle-cm-btn", type: "button", id: replyButtonId(ui, node.id), "aria-label": fill(s.replyTo, { name: node.name ?? "" }), "aria-expanded": ui.replyOpen === node.id, onClick: () => ui.actions.reply(ui.replyOpen === node.id ? null : node.id), children: [
682
670
  /* @__PURE__ */ jsx4(Icon, { name: "reply" }),
683
671
  s.reply
@@ -725,7 +713,7 @@ function CommentItem({ ui, node }) {
725
713
  mine ? /* @__PURE__ */ jsx4("span", { className: "hyle-cm-tag", children: s.you }) : null,
726
714
  /* @__PURE__ */ jsxs3("span", { children: [
727
715
  /* @__PURE__ */ jsx4("time", { dateTime: node.createdAt, title: absolute(node.createdAt, ui.locale), children: relative(node.createdAt, ui.now, ui.locale, s) }),
728
- node.editedAt ? /* @__PURE__ */ jsxs3(Fragment3, { children: [
716
+ node.editedAt ? /* @__PURE__ */ jsxs3(Fragment2, { children: [
729
717
  " ",
730
718
  /* @__PURE__ */ jsx4("span", { "aria-hidden": "true", children: "\xB7" }),
731
719
  " ",
@@ -733,7 +721,7 @@ function CommentItem({ ui, node }) {
733
721
  ] }) : null
734
722
  ] })
735
723
  ] }),
736
- editing ? /* @__PURE__ */ jsx4(EditForm, { ui, node, initial: local?.text ?? node.text ?? hastToMarkdown(node.tree) }) : node.text !== void 0 ? /* @__PURE__ */ jsx4("div", { className: "hyle-cm-body", children: /* @__PURE__ */ jsx4("p", { style: { whiteSpace: "pre-wrap" }, children: node.text }) }) : /* @__PURE__ */ jsx4(CommentBody, { tree: node.tree }),
724
+ editing ? /* @__PURE__ */ jsx4(EditForm, { ui, node, initial: local?.text ?? node.text ?? hastToMarkdown(node.tree) }) : node.text !== void 0 ? /* @__PURE__ */ jsx4("div", { className: "hyle-cm-body", children: /* @__PURE__ */ jsx4("p", { style: { whiteSpace: "pre-wrap" }, children: node.text }) }) : node.unrenderable ? /* @__PURE__ */ jsx4("div", { className: "hyle-cm-body", children: /* @__PURE__ */ jsx4("p", { children: s.unrenderable }) }) : /* @__PURE__ */ jsx4(CommentBody, { tree: node.tree }),
737
725
  node.status === "held" ? /* @__PURE__ */ jsxs3("p", { className: "hyle-cm-held", role: "status", children: [
738
726
  /* @__PURE__ */ jsx4(Icon, { name: "clock" }),
739
727
  /* @__PURE__ */ jsxs3("span", { children: [
@@ -751,114 +739,179 @@ function CommentItem({ ui, node }) {
751
739
  }
752
740
 
753
741
  // src/react/comments.tsx
754
- import { Fragment as Fragment4, jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
742
+ import { Fragment as Fragment3, jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
755
743
  var PAGE = 20;
756
744
  var TICK_MS = 1e4;
757
- var isObject3 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
745
+ var NEAR = "600px 0px";
746
+ var firstOf = (nodes, wanted) => {
747
+ for (const n of nodes) {
748
+ const found = wanted.has(n.id) ? n.id : firstOf(n.kids, wanted);
749
+ if (found) return found;
750
+ }
751
+ return void 0;
752
+ };
758
753
  var fill2 = (t, n) => t.replace("{n}", String(n));
759
- function Comments({ path, endpoint, signInHref, locale, labels: s, initial, initialAt }) {
754
+ var readerOf = (data) => {
755
+ const reader = isObject(data) && isObject(data.reader) ? data.reader : void 0;
756
+ if (typeof reader?.name !== "string") return void 0;
757
+ return { id: typeof reader.id === "string" ? reader.id : reader.name, name: reader.name };
758
+ };
759
+ function Comments(props) {
760
+ const [readers, setReaders] = useState4(0);
761
+ return /* @__PURE__ */ jsx5(ArticleComments, { ...props, onNewReader: () => setReaders((n) => n + 1) }, `${props.endpoint}
762
+ ${props.path}
763
+ ${readers}`);
764
+ }
765
+ function ArticleComments({ path, endpoint, signInHref, locale, labels: s, initial, initialAt, lazy = false, articleReactions = true, onNewReader }) {
760
766
  const idp = `hc${useId().replace(/[^A-Za-z0-9]/g, "")}`;
761
- const [session, setSession] = useState2("loading");
762
- const [listing, setListing] = useState2(initial ?? "loading");
763
- const [own, setOwn] = useState2({});
764
- const [held, setHeld] = useState2([]);
765
- const [likes, setLikes] = useState2({});
766
- const [replyOpen, setReplyOpen] = useState2(null);
767
- const [editing, setEditing] = useState2(null);
768
- const [confirming, setConfirming] = useState2(null);
769
- const [banned, setBanned] = useState2(false);
770
- const [expired, setExpired] = useState2(false);
771
- const [rateUntil, setRateUntil] = useState2(0);
772
- const [now, setNow] = useState2(() => initialAt ?? Date.now());
773
- const [live, setLive] = useState2("");
774
- const [actionError, setActionError] = useState2(null);
775
- const [shown, setShown] = useState2(PAGE);
776
- const [focusId, setFocusId] = useState2(null);
777
- const pending = useRef2(/* @__PURE__ */ new Set());
778
- const alive = useRef2(true);
779
- const write404 = useRef2(0);
780
- useEffect2(() => {
767
+ const [session, setSession] = useState4("loading");
768
+ const [own, setOwn] = useState4({});
769
+ const [held, setHeld] = useState4([]);
770
+ const [unseen, setUnseen] = useState4([]);
771
+ const [replyOpen, setReplyOpen] = useState4(null);
772
+ const [editing, setEditing] = useState4(null);
773
+ const [confirming, setConfirming] = useState4(null);
774
+ const [banned, setBanned] = useState4(false);
775
+ const [expired, setExpired] = useState4(false);
776
+ const [rateUntil, setRateUntil] = useState4(0);
777
+ const [now, setNow] = useState4(() => initialAt ?? Date.now());
778
+ const [live, setLive] = useState4("");
779
+ const [actionError, setActionError] = useState4(null);
780
+ const [shown, setShown] = useState4(PAGE);
781
+ const [focusId, setFocusId] = useState4(null);
782
+ const [near, setNear] = useState4(!lazy);
783
+ const [chosen, setChosen] = useState4("newest");
784
+ const [loadingMore, setLoadingMore] = useState4(false);
785
+ const [moreFailed, setMoreFailed] = useState4(false);
786
+ const root = useRef4(null);
787
+ const sortClicks = useRef4(0);
788
+ const reactions = useReactions(endpoint, path);
789
+ const votes = useVotes(endpoint);
790
+ const { listing, order, served, reload, sort, more, retry } = useCommentListing(
791
+ endpoint,
792
+ path,
793
+ initial,
794
+ near,
795
+ (fresh) => {
796
+ reactions.settle(fresh);
797
+ votes.settle(fresh);
798
+ },
799
+ () => {
800
+ reactions.reset();
801
+ votes.reset();
802
+ setUnseen([]);
803
+ setChosen("newest");
804
+ setLoadingMore(false);
805
+ setMoreFailed(false);
806
+ }
807
+ );
808
+ const alive = useRef4(true);
809
+ const write404 = useRef4(0);
810
+ useEffect3(() => {
781
811
  alive.current = true;
782
812
  return () => void (alive.current = false);
783
813
  }, []);
784
- useEffect2(() => {
814
+ useEffect3(() => {
785
815
  if (initialAt !== void 0) setNow(Date.now());
786
816
  const t = setInterval(() => setNow(Date.now()), TICK_MS);
787
817
  return () => clearInterval(t);
788
818
  }, [initialAt]);
789
- useEffect2(() => {
819
+ useEffect3(() => {
790
820
  if (rateUntil <= Date.now()) return;
791
821
  const t = setTimeout(() => setNow(Date.now()), rateUntil - Date.now() + 50);
792
822
  return () => clearTimeout(t);
793
823
  }, [rateUntil]);
794
- const load = useCallback(async (silent) => {
795
- const r = await call(endpoint, "GET", `/comments?path=${encodeURIComponent(path)}`);
796
- if (!alive.current) return void 0;
797
- const parsed = r.status === 200 ? parseListing(r.data) : void 0;
798
- if (r.status === 404) setListing("off");
799
- else if (parsed) {
800
- setListing(parsed);
801
- setLikes((l) => Object.fromEntries(Object.entries(l).filter(([k]) => pending.current.has(k))));
802
- } else if (!silent) setListing("error");
803
- return parsed;
804
- }, [endpoint, path]);
805
- useEffect2(() => {
806
- setListing(initial ?? "loading");
807
- void load(initial !== void 0);
824
+ useEffect3(() => {
825
+ if (near) return;
826
+ const el = root.current;
827
+ if (!el || typeof IntersectionObserver === "undefined") return setNear(true);
828
+ const observer = new IntersectionObserver((entries) => entries.some((e) => e.isIntersecting) && setNear(true), { rootMargin: NEAR });
829
+ observer.observe(el);
830
+ return () => observer.disconnect();
831
+ }, [near]);
832
+ useEffect3(() => {
833
+ if (!near) return;
808
834
  void call(endpoint, "GET", "/session").then((r) => {
809
835
  if (!alive.current) return;
810
- const reader = isObject3(r.data) && isObject3(r.data.reader) ? r.data.reader : void 0;
811
- setSession(r.status === 404 ? "off" : r.status === 200 && typeof reader?.name === "string" ? { name: reader.name } : null);
836
+ const reader = r.status === 200 ? readerOf(r.data) : void 0;
837
+ setSession(r.status === 404 ? "off" : reader ?? null);
812
838
  });
813
- }, [endpoint, load, initial]);
814
- useEffect2(() => {
839
+ }, [endpoint, near]);
840
+ useEffect3(() => {
841
+ if (typeof listing === "object") setUnseen((u) => stillUnseen(u, listing));
842
+ }, [listing]);
843
+ useEffect3(() => {
815
844
  if (!focusId) return;
816
845
  const el = document.getElementById(`${idp}-${focusId}-n`);
817
846
  if (el) {
818
847
  el.focus();
819
848
  setFocusId(null);
820
849
  }
821
- }, [focusId, listing, held, idp]);
822
- const me = typeof session === "object" && session ? session.name : null;
850
+ }, [focusId, listing, held, unseen, idp]);
851
+ const signedIn = typeof session === "object" ? session : null;
852
+ const me = signedIn?.name ?? null;
823
853
  const rateLeft = Math.max(0, Math.ceil((rateUntil - now) / 1e3));
824
854
  const signInId = `${idp}-signin`;
825
- function failed(status) {
855
+ async function recheck(status) {
856
+ if (status !== 401 && !expired) return;
857
+ const r = await call(endpoint, "GET", "/session");
858
+ const reader = r.status === 200 ? readerOf(r.data) : void 0;
859
+ if (alive.current && reader && reader.id !== signedIn?.id) onNewReader();
860
+ }
861
+ function failed(status, refusal) {
826
862
  if (status === 401) setExpired(true);
827
- setActionError(status === 401 ? s.expired : s.actionError);
863
+ setActionError(status === 401 ? s.expired : status === 429 ? s.slowDown : refusal ?? s.actionError);
828
864
  }
829
- async function like(key, serverCount, serverOn) {
830
- if (!me || banned || pending.current.has(key)) return;
831
- const prev = likes[key] ?? { on: serverOn, count: serverCount };
832
- const count2 = prev.count ?? serverCount;
833
- pending.current.add(key);
865
+ async function react(subject, kind, count, on) {
866
+ if (!me || banned) return;
834
867
  setActionError(null);
835
- setLikes((l) => ({ ...l, [key]: { on: !prev.on, count: Math.max(0, count2 + (prev.on ? -1 : 1)) } }));
836
- const r = await call(endpoint, prev.on ? "DELETE" : "PUT", "/reactions", key === "article" ? { subject_type: "article", path } : { subject_type: "comment", comment_id: key });
837
- pending.current.delete(key);
838
- if (!alive.current) return;
839
- const reaction = r.status === 200 && isObject3(r.data) && isObject3(r.data.reaction) ? r.data.reaction : void 0;
840
- if (reaction && typeof reaction.like_count === "number") {
841
- setLikes((l) => ({ ...l, [key]: { on: reaction.active === true, count: reaction.like_count } }));
842
- return;
868
+ const r = await reactions.toggle(subject, kind, count, on);
869
+ if (!r || !alive.current) return;
870
+ void recheck(r.ok ? 200 : r.status);
871
+ if (!r.ok) return failed(r.status);
872
+ setLive((r.on ? s.reactionAddedLive : s.reactionRemovedLive).replace("{kind}", kindName(s, kind)));
873
+ }
874
+ async function vote(id, current, clicked) {
875
+ if (!me || banned) return;
876
+ setActionError(null);
877
+ const r = await votes.cast(id, current, clicked);
878
+ if (!r || !alive.current) return;
879
+ void recheck(r.ok ? 200 : r.status);
880
+ if (!r.ok) return failed(r.status, r.status === 400 ? s.voteRefused : void 0);
881
+ setLive(fill2(r.state.value === 1 ? s.upvotedLive : r.state.value === -1 ? s.downvotedLive : s.voteRemovedLive, r.state.score));
882
+ }
883
+ async function choose(next) {
884
+ if (next === chosen) return;
885
+ const click = sortClicks.current += 1;
886
+ setChosen(next);
887
+ setActionError(null);
888
+ setMoreFailed(false);
889
+ const showing = await sort(next);
890
+ if (!alive.current || click !== sortClicks.current || showing === void 0) return;
891
+ if (showing !== next) {
892
+ setChosen(showing);
893
+ return setActionError(s.sortError);
843
894
  }
844
- setLikes((l) => ({ ...l, [key]: { on: prev.on, count: count2 } }));
845
- failed(r.status);
895
+ setShown(PAGE);
896
+ setLive(next === "top" ? s.sortedTopLive : s.sortedNewestLive);
846
897
  }
847
898
  async function post(text, parentId) {
848
899
  const r = await call(endpoint, "POST", "/comments", { path, body: text, ...parentId ? { parent_id: parentId } : {} });
849
- const created = r.status === 201 && isObject3(r.data) && isObject3(r.data.comment) ? r.data.comment : void 0;
900
+ void recheck(r.status);
901
+ const created = r.status === 201 && isObject(r.data) && isObject(r.data.comment) ? r.data.comment : void 0;
850
902
  if (typeof created?.id === "string" && alive.current) {
851
903
  const id = created.id;
852
904
  write404.current = 0;
853
905
  setOwn((o) => ({ ...o, [id]: { text, at: Date.now(), parentId } }));
854
906
  setExpired(false);
855
- if (created.status === "held") {
856
- setHeld((h) => [{ id, parentId, text, name: me ?? "", createdAt: (/* @__PURE__ */ new Date()).toISOString() }, ...h]);
857
- setLive(s.heldLive);
858
- } else setLive(s.postedLive);
907
+ const status = created.status === "held" ? "held" : "visible";
908
+ const local = { id, parentId, text, name: me ?? "", createdAt: (/* @__PURE__ */ new Date()).toISOString() };
909
+ setUnseen((u) => [{ ...local, status }, ...u]);
910
+ if (status === "held") setHeld((h) => [local, ...h]);
911
+ setLive(status === "held" ? s.heldLive : s.postedLive);
859
912
  setShown(Number.MAX_SAFE_INTEGER);
860
913
  setFocusId(id);
861
- await load(true);
914
+ await reload(true);
862
915
  return { ok: true };
863
916
  }
864
917
  if (r.status === 429) {
@@ -867,10 +920,11 @@ function Comments({ path, endpoint, signInHref, locale, labels: s, initial, init
867
920
  return { ok: false, reason: "rate" };
868
921
  }
869
922
  if (r.status === 404) {
870
- const [again, who] = await Promise.all([load(true), call(endpoint, "GET", "/session")]);
923
+ const [again, who] = await Promise.all([reload(true), call(endpoint, "GET", "/session")]);
871
924
  write404.current += 1;
872
- const valid = who.status === 200 && isObject3(who.data) && isObject3(who.data.reader) && typeof who.data.reader.name === "string";
873
- if (alive.current && valid && again && write404.current >= 2) setBanned(true);
925
+ const reader = who.status === 200 ? readerOf(who.data) : void 0;
926
+ if (alive.current && reader && reader.id !== signedIn?.id) onNewReader();
927
+ else if (alive.current && reader && again && write404.current >= 2) setBanned(true);
874
928
  return { ok: false, reason: "error" };
875
929
  }
876
930
  if (r.status === 401) setExpired(true);
@@ -878,15 +932,20 @@ function Comments({ path, endpoint, signInHref, locale, labels: s, initial, init
878
932
  }
879
933
  async function save(id, text) {
880
934
  const r = await call(endpoint, "PATCH", `/comments/${id}`, { body: text });
935
+ void recheck(r.status);
881
936
  if (r.status === 200 && alive.current) {
882
937
  const meta = own[id];
883
938
  setOwn((o) => ({ ...o, [id]: { text, at: o[id]?.at ?? Date.now(), parentId: o[id]?.parentId ?? null } }));
884
939
  setHeld((h) => h.map((c) => c.id === id ? { ...c, text } : c));
940
+ setUnseen((u) => u.map((c) => c.id === id ? { ...c, text } : c));
885
941
  setEditing(null);
886
942
  setLive(s.savedLive);
887
943
  setFocusId(id);
888
- const fresh = await load(true);
889
- if (fresh && !fresh.comments.some((c) => c.id === id)) setHeld((h) => h.some((c) => c.id === id) ? h : [{ id, parentId: meta?.parentId ?? null, text, name: me ?? "", createdAt: (/* @__PURE__ */ new Date()).toISOString() }, ...h]);
944
+ const fresh = await reload(true);
945
+ if (fresh && !fresh.truncated && !fresh.next_cursor && !fresh.comments.some((c) => c.id === id)) {
946
+ setUnseen((u) => u.filter((c) => c.id !== id));
947
+ setHeld((h) => h.some((c) => c.id === id) ? h : [{ id, parentId: meta?.parentId ?? null, text, name: me ?? "", createdAt: (/* @__PURE__ */ new Date()).toISOString() }, ...h]);
948
+ }
890
949
  return { ok: true };
891
950
  }
892
951
  if (r.status === 429) {
@@ -901,15 +960,38 @@ function Comments({ path, endpoint, signInHref, locale, labels: s, initial, init
901
960
  setActionError(null);
902
961
  const r = await call(endpoint, "DELETE", `/comments/${id}`);
903
962
  if (!alive.current) return;
963
+ void recheck(r.status);
904
964
  setConfirming(null);
905
965
  if (r.status !== 200) return failed(r.status);
906
966
  setHeld((h) => h.filter((c) => c.id !== id));
967
+ setUnseen((u) => u.filter((c) => c.id !== id));
907
968
  setOwn(({ [id]: _gone, ...rest }) => rest);
908
969
  setLive(s.deletedLive);
909
- await load(true);
970
+ await reload(true);
910
971
  }
911
- if (session === "off" || listing === "off") return null;
912
972
  const loaded = typeof listing === "object" ? listing : void 0;
973
+ const sortable = !!loaded && isSortable(loaded);
974
+ const thread = loaded ? arrangeThread(loaded, served, held, unseen) : [];
975
+ const oldestFirstPages = !!loaded && arrivesAs(loaded, served) === void 0;
976
+ async function showMore() {
977
+ if (thread.length > shown) {
978
+ setShown(shown + PAGE);
979
+ setFocusId(thread.slice(shown).find((n) => n.status !== "removed")?.id ?? null);
980
+ return;
981
+ }
982
+ if (loadingMore) return;
983
+ setLoadingMore(true);
984
+ setMoreFailed(false);
985
+ const r = await more();
986
+ if (!alive.current) return;
987
+ setLoadingMore(false);
988
+ if (!r) return;
989
+ if (!r.ok) return setMoreFailed(true);
990
+ setShown(arrivesAs(r.listing, r.sort) === void 0 ? Number.MAX_SAFE_INTEGER : Math.min(shown, thread.length) + PAGE);
991
+ setFocusId(firstOf(arrangeThread(r.listing, r.sort, held, unseen), r.added) ?? null);
992
+ setLive(fill2(s.loadedLive, r.added.size));
993
+ }
994
+ if (session === "off" || listing === "off") return null;
913
995
  const ui = {
914
996
  s,
915
997
  locale,
@@ -917,17 +999,18 @@ function Comments({ path, endpoint, signInHref, locale, labels: s, initial, init
917
999
  ready: session !== "loading",
918
1000
  me,
919
1001
  banned,
920
- signInHref,
921
1002
  signInId,
922
1003
  idp,
923
1004
  rateLeft,
924
1005
  own,
925
- likes,
1006
+ reactions: reactions.overlay,
1007
+ votes: votes.overlay,
926
1008
  replyOpen,
927
1009
  editing,
928
1010
  confirming,
929
1011
  actions: {
930
- like: (k, c, on) => void like(k, c, on),
1012
+ react: (subject, kind, count, on) => void react(subject, kind, count, on),
1013
+ vote: (id, current, clicked) => void vote(id, current, clicked),
931
1014
  reply: (id) => {
932
1015
  const previous = replyOpen;
933
1016
  setReplyOpen(id);
@@ -940,17 +1023,20 @@ function Comments({ path, endpoint, signInHref, locale, labels: s, initial, init
940
1023
  remove: (id) => void remove(id)
941
1024
  }
942
1025
  };
943
- const thread = loaded ? buildThread(loaded, held) : [];
944
1026
  const hid = `${idp}-h`;
945
1027
  const canWrite = !!me && !banned;
946
- return /* @__PURE__ */ jsxs4("section", { className: "hyle-comments", "aria-labelledby": hid, "data-slot-component": "Comments", children: [
947
- /* @__PURE__ */ jsx5("div", { className: "hyle-cm-head", children: /* @__PURE__ */ jsxs4("h2", { id: hid, children: [
948
- s.heading,
949
- loaded ? /* @__PURE__ */ jsxs4(Fragment4, { children: [
950
- " ",
951
- /* @__PURE__ */ jsx5("span", { className: "hyle-cm-count", "aria-label": fill2(s.countLabel, loaded.comment_count), children: loaded.comment_count })
952
- ] }) : null
953
- ] }) }),
1028
+ const unfetched = !!loaded?.next_cursor;
1029
+ return /* @__PURE__ */ jsxs4("section", { className: "hyle-comments", ref: root, "aria-labelledby": hid, "data-slot-component": "Comments", children: [
1030
+ /* @__PURE__ */ jsxs4("div", { className: "hyle-cm-head", children: [
1031
+ /* @__PURE__ */ jsxs4("h2", { id: hid, children: [
1032
+ s.heading,
1033
+ loaded ? /* @__PURE__ */ jsxs4(Fragment3, { children: [
1034
+ " ",
1035
+ /* @__PURE__ */ jsx5("span", { className: "hyle-cm-count", "aria-label": fill2(s.countLabel, loaded.comment_count), children: loaded.comment_count })
1036
+ ] }) : null
1037
+ ] }),
1038
+ sortable && (order === "top" || thread.length > 1) ? /* @__PURE__ */ jsx5("div", { className: "hyle-cm-sort", role: "group", "aria-label": s.sort, children: ["newest", "top"].map((o) => /* @__PURE__ */ jsx5("button", { className: "hyle-cm-btn", type: "button", "aria-pressed": chosen === o, onClick: () => void choose(o), children: o === "top" ? s.sortTop : s.sortNewest }, o)) }) : null
1039
+ ] }),
954
1040
  /* @__PURE__ */ jsx5("p", { className: "hyle-sr", role: "status", "aria-live": "polite", children: live }),
955
1041
  actionError ? /* @__PURE__ */ jsxs4("p", { className: "hyle-cm-err", role: "alert", children: [
956
1042
  /* @__PURE__ */ jsx5(Icon, { name: "alert" }),
@@ -962,15 +1048,12 @@ function Comments({ path, endpoint, signInHref, locale, labels: s, initial, init
962
1048
  /* @__PURE__ */ jsx5("b", { children: s.loadError }),
963
1049
  /* @__PURE__ */ jsx5("p", { children: s.loadErrorBody })
964
1050
  ] }),
965
- /* @__PURE__ */ jsxs4("button", { className: "hyle-btn sm", type: "button", onClick: () => {
966
- setListing("loading");
967
- void load(false);
968
- }, children: [
1051
+ /* @__PURE__ */ jsxs4("button", { className: "hyle-btn sm", type: "button", onClick: retry, children: [
969
1052
  /* @__PURE__ */ jsx5(Icon, { name: "refresh" }),
970
1053
  s.retry
971
1054
  ] })
972
- ] }) : /* @__PURE__ */ jsxs4(Fragment4, { children: [
973
- loaded ? /* @__PURE__ */ jsx5("div", { className: "hyle-react", children: /* @__PURE__ */ jsx5(LikeButton, { ui, itemKey: "article", serverCount: loaded.like_count, serverOn: loaded.liked_by_me === true, scope: "article" }) }) : null,
1055
+ ] }) : /* @__PURE__ */ jsxs4(Fragment3, { children: [
1056
+ loaded && articleReactions ? /* @__PURE__ */ jsx5("div", { className: "hyle-react", children: /* @__PURE__ */ jsx5(ReactionBar, { s, scope: "article", subject: "article", likes: loaded.like_count, counts: loaded.reaction_counts, likedByMe: loaded.liked_by_me === true, mine: loaded.my_reactions, overlay: reactions.overlay, access: accessOf(ui), signInHref: `#${signInId}`, onToggle: (kind, count, on) => void react("article", kind, count, on) }) }) : null,
974
1057
  held.length > 0 || (loaded?.mine_held?.length ?? 0) > 0 ? /* @__PURE__ */ jsxs4("div", { className: "hyle-banner", "data-kind": "warn", role: "status", children: [
975
1058
  /* @__PURE__ */ jsx5(Icon, { name: "clock" }),
976
1059
  /* @__PURE__ */ jsxs4("div", { className: "hyle-bt", children: [
@@ -1013,10 +1096,15 @@ function Comments({ path, endpoint, signInHref, locale, labels: s, initial, init
1013
1096
  ] }) : thread.length === 0 ? /* @__PURE__ */ jsxs4("div", { className: "hyle-cm-empty", children: [
1014
1097
  /* @__PURE__ */ jsx5("b", { children: s.empty }),
1015
1098
  /* @__PURE__ */ jsx5("span", { children: s.emptyBody })
1016
- ] }) : /* @__PURE__ */ jsxs4(Fragment4, { children: [
1099
+ ] }) : /* @__PURE__ */ jsxs4(Fragment3, { children: [
1100
+ sortable && oldestFirstPages && unfetched ? /* @__PURE__ */ jsx5("p", { className: "hyle-cm-note", children: s.newerLater }) : null,
1017
1101
  /* @__PURE__ */ jsx5(Thread, { ui, nodes: thread.slice(0, shown) }),
1018
- thread.length > shown ? /* @__PURE__ */ jsx5("div", { className: "hyle-cm-more", children: /* @__PURE__ */ jsx5("button", { className: "hyle-btn", type: "button", onClick: () => setShown((n) => n + PAGE), children: s.more }) }) : null,
1019
- loaded.truncated ? /* @__PURE__ */ jsx5("p", { className: "hyle-cm-note", children: s.truncated }) : null
1102
+ moreFailed ? /* @__PURE__ */ jsxs4("p", { className: "hyle-cm-err", role: "alert", children: [
1103
+ /* @__PURE__ */ jsx5(Icon, { name: "alert" }),
1104
+ /* @__PURE__ */ jsx5("span", { children: s.moreError })
1105
+ ] }) : null,
1106
+ thread.length > shown || unfetched ? /* @__PURE__ */ jsx5("div", { className: "hyle-cm-more", children: /* @__PURE__ */ jsx5("button", { className: "hyle-btn", type: "button", "aria-disabled": loadingMore || void 0, "aria-busy": loadingMore || void 0, onClick: () => void showMore(), children: s.more }) }) : null,
1107
+ loaded.truncated && !unfetched ? /* @__PURE__ */ jsx5("p", { className: "hyle-cm-note", children: s.truncated }) : null
1020
1108
  ] })
1021
1109
  ] })
1022
1110
  ] });