@tdacorp/hyle-sdk 0.17.0 → 0.21.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 (86) hide show
  1. package/README.md +155 -28
  2. package/dist/check-routes-bin.js +38 -13
  3. package/dist/chunk-56Y24XBV.js +840 -0
  4. package/dist/{chunk-MGSUQBDW.js → chunk-75JFLML4.js} +176 -14
  5. package/dist/chunk-HJX57NLI.js +1105 -0
  6. package/dist/chunk-K5VDLROQ.js +145 -0
  7. package/dist/{chunk-BUJFMR3M.js → chunk-QVYQM5R2.js} +15 -6
  8. package/dist/chunk-U74B7AUG.js +398 -0
  9. package/dist/{chunk-6VOHFFA5.js → chunk-X2TLYM7Y.js} +2 -2
  10. package/dist/client-41fU6OY2.d.cts +201 -0
  11. package/dist/client-LwzHwqpM.d.ts +201 -0
  12. package/dist/code-copy.cjs +72 -0
  13. package/dist/code-copy.d.cts +15 -0
  14. package/dist/code-copy.d.ts +15 -0
  15. package/dist/code-copy.js +48 -0
  16. package/dist/comments.cjs +728 -275
  17. package/dist/comments.d.cts +66 -3
  18. package/dist/comments.d.ts +66 -3
  19. package/dist/comments.js +409 -326
  20. package/dist/{diagram-viewer-FJPED4SN.js → diagram-viewer-XY3CG75U.js} +62 -21
  21. package/dist/{embed-BmdwA2G9.d.cts → embed-BUFRQboD.d.ts} +2 -2
  22. package/dist/{embed-DNTZ2UXv.d.ts → embed-CYt-q13P.d.cts} +2 -2
  23. package/dist/fragment-alias.cjs +51 -0
  24. package/dist/fragment-alias.d.cts +7 -0
  25. package/dist/fragment-alias.d.ts +7 -0
  26. package/dist/fragment-alias.js +27 -0
  27. package/dist/html.cjs +881 -0
  28. package/dist/html.d.cts +20 -0
  29. package/dist/html.d.ts +20 -0
  30. package/dist/html.js +45 -0
  31. package/dist/index.cjs +181 -14
  32. package/dist/index.d.cts +14 -62
  33. package/dist/index.d.ts +14 -62
  34. package/dist/index.js +11 -1
  35. package/dist/{labels-nmukKYgL.d.ts → labels-CrA-iqTN.d.cts} +9 -0
  36. package/dist/{labels-nmukKYgL.d.cts → labels-CrA-iqTN.d.ts} +9 -0
  37. package/dist/mermaid-diagram.cjs +401 -125
  38. package/dist/mermaid-diagram.d.cts +23 -7
  39. package/dist/mermaid-diagram.d.ts +23 -7
  40. package/dist/mermaid-diagram.js +204 -51
  41. package/dist/mermaid-image.cjs +134 -60
  42. package/dist/mermaid-image.d.cts +4 -3
  43. package/dist/mermaid-image.d.ts +4 -3
  44. package/dist/mermaid-image.js +27 -28
  45. package/dist/next.cjs +627 -264
  46. package/dist/next.d.cts +11 -8
  47. package/dist/next.d.ts +11 -8
  48. package/dist/next.js +39 -12
  49. package/dist/print-coordinator.cjs +157 -0
  50. package/dist/print-coordinator.d.cts +27 -0
  51. package/dist/print-coordinator.d.ts +27 -0
  52. package/dist/print-coordinator.js +83 -0
  53. package/dist/react.cjs +556 -226
  54. package/dist/react.d.cts +136 -29
  55. package/dist/react.d.ts +136 -29
  56. package/dist/react.js +23 -3
  57. package/dist/reactions.cjs +653 -0
  58. package/dist/reactions.d.cts +27 -0
  59. package/dist/reactions.d.ts +27 -0
  60. package/dist/reactions.js +364 -0
  61. package/dist/{resolve-Ae7UFjsQ.d.ts → resolve-BjAK0k_Y.d.ts} +2 -2
  62. package/dist/{resolve-euZ4-aC9.d.cts → resolve-eI1muCKL.d.cts} +2 -2
  63. package/dist/revalidation-callback-BQl77tQR.d.cts +75 -0
  64. package/dist/revalidation-callback-BQl77tQR.d.ts +75 -0
  65. package/dist/sanitize-ijiWjEm9.d.cts +23 -0
  66. package/dist/sanitize-ijiWjEm9.d.ts +23 -0
  67. package/dist/styles.css +96 -25
  68. package/dist/toc-spy.cjs +59 -0
  69. package/dist/toc-spy.d.cts +15 -0
  70. package/dist/toc-spy.d.ts +15 -0
  71. package/dist/toc-spy.js +35 -0
  72. package/dist/{types-Czt887Iv.d.cts → types-3F0wqD-o.d.cts} +26 -2
  73. package/dist/{types-Czt887Iv.d.ts → types-3F0wqD-o.d.ts} +26 -2
  74. package/dist/use-cache.cjs +37 -11
  75. package/dist/use-cache.d.cts +12 -5
  76. package/dist/use-cache.d.ts +12 -5
  77. package/dist/use-cache.js +7 -7
  78. package/dist/youtube-facade.cjs +50 -0
  79. package/dist/youtube-facade.d.cts +17 -0
  80. package/dist/youtube-facade.d.ts +17 -0
  81. package/dist/youtube-facade.js +26 -0
  82. package/package.json +16 -3
  83. package/dist/chunk-DMK4XQLU.js +0 -1556
  84. package/dist/chunk-PJMJMP66.js +0 -63
  85. package/dist/revalidation-callback-D7Ms_Puz.d.cts +0 -42
  86. package/dist/revalidation-callback-D7Ms_Puz.d.ts +0 -42
package/dist/comments.cjs CHANGED
@@ -24,12 +24,27 @@ __export(comments_exports, {
24
24
  Comments: () => Comments
25
25
  });
26
26
  module.exports = __toCommonJS(comments_exports);
27
- var import_react3 = require("react");
27
+ var import_react6 = require("react");
28
28
 
29
29
  // src/react/comments-api.ts
30
30
  var CSRF_HEADER = "x-hyle-engage";
31
31
  var TIMEOUT_MS = 15e3;
32
- async function call(endpoint, method, path, body) {
32
+ var reading = /* @__PURE__ */ new Map();
33
+ function call(endpoint, method, path, body) {
34
+ if (method !== "GET") {
35
+ reading.clear();
36
+ return send(endpoint, method, path, body).finally(() => reading.clear());
37
+ }
38
+ const key = `${endpoint}${path}`;
39
+ const shared = reading.get(key);
40
+ if (shared) return shared;
41
+ const request = send(endpoint, method, path).finally(() => {
42
+ if (reading.get(key) === request) reading.delete(key);
43
+ });
44
+ reading.set(key, request);
45
+ return request;
46
+ }
47
+ async function send(endpoint, method, path, body) {
33
48
  try {
34
49
  const res = await fetch(`${endpoint}${path}`, {
35
50
  method,
@@ -50,8 +65,17 @@ async function call(endpoint, method, path, body) {
50
65
  return { status: 0, data: void 0, retryAfter: void 0 };
51
66
  }
52
67
  }
68
+ var REACTION_KINDS = ["like", "love", "insightful", "celebrate"];
69
+ var isCursor = (v) => typeof v === "string" && /^[A-Za-z0-9_-]{1,200}$/.test(v);
53
70
  var isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
54
71
  var count = (v) => typeof v === "number" && Number.isFinite(v) && v >= 0 ? Math.trunc(v) : 0;
72
+ function parseCounts(v) {
73
+ if (!isObject(v)) return void 0;
74
+ return Object.fromEntries(REACTION_KINDS.map((kind) => [kind, count(v[kind])]).filter(([, n]) => n > 0));
75
+ }
76
+ var toVote = (v) => v === 1 || v === -1 ? v : null;
77
+ var toUnrenderable = (v) => v === true ? { unrenderable: true } : {};
78
+ var toMine = (v) => Array.isArray(v) ? { my_reactions: REACTION_KINDS.filter((kind) => v.includes(kind)) } : {};
55
79
  function toComment(raw) {
56
80
  if (!isObject(raw) || typeof raw.id !== "string" || typeof raw.created_at !== "string") return void 0;
57
81
  const depth = typeof raw.depth === "number" ? Math.min(4, Math.max(1, Math.trunc(raw.depth))) : 1;
@@ -59,6 +83,7 @@ function toComment(raw) {
59
83
  const name = typeof raw.author_name === "string" ? raw.author_name : author;
60
84
  const body = isObject(raw.body) && raw.body.format === "hast" ? { format: "hast", tree: raw.body.tree } : null;
61
85
  const removed = raw.removed === true || body === null;
86
+ const reactions = parseCounts(raw.reaction_counts);
62
87
  return {
63
88
  id: raw.id,
64
89
  parent_id: typeof raw.parent_id === "string" ? raw.parent_id : null,
@@ -67,11 +92,14 @@ function toComment(raw) {
67
92
  created_at: raw.created_at,
68
93
  edited_at: typeof raw.edited_at === "string" ? raw.edited_at : null,
69
94
  like_count: count(raw.like_count),
95
+ ...Number.isSafeInteger(raw.score) ? { score: raw.score } : {},
96
+ ...reactions ? { reaction_counts: reactions } : {},
70
97
  removed,
71
98
  ...removed && (raw.removed_by === "moderator" || raw.removed_by === "author") ? { removed_by: raw.removed_by } : {},
99
+ ...removed ? {} : toUnrenderable(raw.unrenderable),
72
100
  body,
73
101
  // Viewer members exist only on a live comment of a viewer-aware listing; a tombstone never carries them.
74
- ...!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 } : {}
102
+ ...!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, ..."my_vote" in raw ? { my_vote: toVote(raw.my_vote) } : {}, ...toMine(raw.my_reactions) } : {}
75
103
  };
76
104
  }
77
105
  function toHeld(raw) {
@@ -85,20 +113,59 @@ function toHeld(raw) {
85
113
  created_at: raw.created_at,
86
114
  edited_at: typeof raw.edited_at === "string" ? raw.edited_at : null,
87
115
  can_edit_until: typeof raw.can_edit_until === "string" ? raw.can_edit_until : null,
116
+ ...toUnrenderable(raw.unrenderable),
88
117
  body: { format: "hast", tree: raw.body.tree }
89
118
  };
90
119
  }
91
120
  function parseListing(data) {
92
121
  if (!isObject(data) || data.kind !== "comments" || !Array.isArray(data.comments)) return void 0;
93
122
  const comments = data.comments.map(toComment).filter((c) => c !== void 0);
94
- 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) } : {};
95
- 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 };
123
+ const viewer = Array.isArray(data.mine_held) ? { liked_by_me: data.liked_by_me === true, ...toMine(data.my_reactions), mine_held: data.mine_held.slice(0, 5).map(toHeld).filter((h) => h !== void 0) } : {};
124
+ const reactions = parseCounts(data.reaction_counts);
125
+ return { cp: 1, kind: "comments", publication_id: String(data.publication_id ?? ""), comment_count: count(data.comment_count), like_count: count(data.like_count), ...reactions ? { reaction_counts: reactions } : {}, truncated: data.truncated === true, next_cursor: isCursor(data.next_cursor) ? data.next_cursor : null, comments, ...viewer };
126
+ }
127
+ async function fetchPage(endpoint, path, sort, cursor) {
128
+ const query = new URLSearchParams({ path, ...cursor ? { cursor } : {}, ...sort ? { sort } : {} });
129
+ const r = await call(endpoint, "GET", `/comments?${query}`);
130
+ let listing = r.status === 200 ? parseListing(r.data) : void 0;
131
+ if (listing?.next_cursor && (listing.comments.length === 0 || listing.next_cursor === cursor)) listing = { ...listing, next_cursor: null };
132
+ return { status: r.status, listing, pages: listing ? 1 : 0, sort };
133
+ }
134
+ async function fetchPages(endpoint, path, order, pages, legacy = false) {
135
+ let out = await fetchPage(endpoint, path, order === "top" ? "top" : legacy ? void 0 : "new");
136
+ if (out.status === 400 && out.sort === "new") out = await fetchPage(endpoint, path, void 0);
137
+ while (out.listing?.next_cursor && out.pages < pages) {
138
+ const next = await fetchPage(endpoint, path, out.sort, out.listing.next_cursor);
139
+ if (!next.listing) return { ...next, status: next.status === 404 ? 502 : next.status, pages: 0 };
140
+ out = { ...next, listing: mergeListings(out.listing, next.listing), pages: out.pages + 1 };
141
+ }
142
+ return out;
143
+ }
144
+ async function fetchNext(endpoint, path, order, loaded, legacy = false) {
145
+ const next = await fetchPage(endpoint, path, loaded.sort, loaded.listing.next_cursor ?? void 0);
146
+ if (next.status === 400) return { ...await fetchPages(endpoint, path, order, loaded.pages + 1, legacy), restarted: true };
147
+ return { ...next, ...next.listing ? { listing: mergeListings(loaded.listing, next.listing), pages: loaded.pages + 1 } : {}, restarted: false };
148
+ }
149
+ var viewerOf = ({ mine, liked_by_me, my_reactions, can_edit_until, my_vote }) => mine === void 0 ? {} : { mine, liked_by_me: liked_by_me === true, ...my_reactions ? { my_reactions } : {}, can_edit_until: can_edit_until ?? null, ...my_vote === void 0 ? {} : { my_vote } };
150
+ function mergeListings(earlier, later) {
151
+ const byId = new Map(earlier.comments.map((c) => [c.id, c]));
152
+ for (const c of later.comments) {
153
+ const old = byId.get(c.id);
154
+ byId.set(c.id, old && !c.removed ? { ...viewerOf(old), ...c } : c);
155
+ }
156
+ const { liked_by_me, my_reactions, mine_held } = earlier;
157
+ const viewer = !later.mine_held && mine_held ? { liked_by_me: liked_by_me === true, ...my_reactions ? { my_reactions } : {}, mine_held } : {};
158
+ return { ...later, ...viewer, comments: [...byId.values()] };
159
+ }
160
+ function nextVote(current, clicked) {
161
+ const value = current.value === clicked ? null : clicked;
162
+ return { value, score: current.score - (current.value ?? 0) + (value ?? 0) };
96
163
  }
97
164
  var untilMs = (iso) => {
98
165
  const t = iso ? Date.parse(iso) : NaN;
99
166
  return Number.isFinite(t) ? t : void 0;
100
167
  };
101
- function buildThread(listing, localHeld) {
168
+ function buildThread(listing, localHeld, unseen = [], newestOnTop = false) {
102
169
  const byId = /* @__PURE__ */ new Map();
103
170
  const roots = [];
104
171
  const place = (node, parentId) => {
@@ -116,11 +183,16 @@ function buildThread(listing, localHeld) {
116
183
  mine: !removed && c.mine === true,
117
184
  canEditUntil: untilMs(c.can_edit_until),
118
185
  likedByMe: !removed && c.liked_by_me === true,
186
+ myReactions: removed ? void 0 : c.my_reactions,
119
187
  name: removed ? null : c.author_name ?? null,
120
188
  createdAt: c.created_at,
121
189
  editedAt: c.edited_at,
122
190
  likes: c.like_count,
191
+ score: c.score,
192
+ myVote: c.my_vote,
193
+ reactions: c.reaction_counts,
123
194
  tree: c.body?.tree,
195
+ unrenderable: c.unrenderable,
124
196
  text: void 0,
125
197
  kids: []
126
198
  };
@@ -138,24 +210,153 @@ function buildThread(listing, localHeld) {
138
210
  for (const h of listing.mine_held ?? []) {
139
211
  heldIds.add(h.id);
140
212
  const parent = h.parent_id ? byId.get(h.parent_id) : void 0;
141
- 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);
213
+ 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, unrenderable: h.unrenderable, text: void 0, kids: [] }, h.parent_id, true);
142
214
  }
143
215
  if (listing.mine_held === void 0) {
144
216
  for (const h of localHeld) {
145
217
  if (byId.has(h.id) || heldIds.has(h.id)) continue;
146
218
  const parent = h.parentId ? byId.get(h.parentId) : void 0;
147
- 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);
219
+ addHeld(localNode(h, "held", parent), h.parentId, false);
148
220
  }
149
221
  }
222
+ for (const u of [...unseen].reverse()) {
223
+ if (byId.has(u.id) || heldIds.has(u.id) || u.status === "held" && listing.mine_held === void 0) continue;
224
+ const parent = u.parentId ? byId.get(u.parentId) : void 0;
225
+ const node = localNode(u, u.status, parent);
226
+ if (u.status === "held") addHeld(node, u.parentId, true);
227
+ else if (parent) parent.kids.push(node);
228
+ else if (newestOnTop) roots.unshift(node);
229
+ else roots.push(node);
230
+ byId.set(u.id, node);
231
+ }
150
232
  return [...mine, ...roots];
151
233
  }
234
+ var localNode = (c, status, parent) => ({
235
+ id: c.id,
236
+ depth: Math.min(4, (parent?.depth ?? 0) + 1),
237
+ status,
238
+ removedBy: void 0,
239
+ mine: true,
240
+ canEditUntil: void 0,
241
+ likedByMe: false,
242
+ name: c.name,
243
+ createdAt: c.createdAt,
244
+ editedAt: null,
245
+ likes: 0,
246
+ tree: void 0,
247
+ text: c.text,
248
+ kids: []
249
+ });
250
+ var isSortable = (listing) => listing.comments.some((c) => c.score !== void 0);
251
+ var arrivesAs = (listing, sort) => isSortable(listing) ? sort : void 0;
252
+ function arrangeThread(listing, sort, localHeld, unseen) {
253
+ const from = arrivesAs(listing, sort);
254
+ const thread = buildThread(listing, localHeld, unseen, from === "new");
255
+ return isSortable(listing) && from === void 0 ? newestFirst(thread) : thread;
256
+ }
257
+ function stillUnseen(unseen, listing) {
258
+ const listed = new Set([...listing.comments, ...listing.mine_held ?? []].map((c) => c.id));
259
+ return unseen.some((c) => listed.has(c.id)) ? unseen.filter((c) => !listed.has(c.id)) : unseen;
260
+ }
261
+ function newestFirst(thread) {
262
+ return [...thread.filter((n) => n.status === "held"), ...thread.filter((n) => n.status !== "held").reverse()];
263
+ }
264
+
265
+ // src/react/comments-listing.ts
266
+ var import_react = require("react");
267
+ function useCommentListing(endpoint, path, initial, active, onFresh, onReset) {
268
+ const [listing, setListing] = (0, import_react.useState)(initial ?? "loading");
269
+ const [order, setOrder] = (0, import_react.useState)("newest");
270
+ const [served, setServed] = (0, import_react.useState)(void 0);
271
+ const data = (0, import_react.useRef)({ listing: initial, order: "newest", pages: 1, sort: void 0 });
272
+ const legacy = (0, import_react.useRef)(false);
273
+ const queue = (0, import_react.useRef)(Promise.resolve());
274
+ const generation = (0, import_react.useRef)(0);
275
+ const callbacks = (0, import_react.useRef)({ onFresh, onReset });
276
+ callbacks.current = { onFresh, onReset };
277
+ const enqueue = (0, import_react.useCallback)((op) => {
278
+ const mine = generation.current;
279
+ const stale = () => mine !== generation.current;
280
+ const job = queue.current.then(() => stale() ? void 0 : op(stale));
281
+ queue.current = job.catch(() => void 0);
282
+ return job;
283
+ }, []);
284
+ const commit = (0, import_react.useCallback)((next) => {
285
+ data.current = next;
286
+ setListing(next.listing);
287
+ setOrder(next.order);
288
+ setServed(next.sort);
289
+ }, []);
290
+ const learn = (0, import_react.useCallback)((asked, r) => {
291
+ if (asked === "newest" && r.listing && r.sort === void 0) legacy.current = true;
292
+ return r;
293
+ }, []);
294
+ const reload = (0, import_react.useCallback)(
295
+ (silent) => enqueue(async (stale) => {
296
+ const { order: current, pages } = data.current;
297
+ const r = learn(current, await fetchPages(endpoint, path, current, pages, legacy.current));
298
+ if (stale()) return void 0;
299
+ if (r.status === 404) setListing("off");
300
+ else if (r.listing) {
301
+ commit({ listing: r.listing, order: current, pages: r.pages, sort: r.sort });
302
+ callbacks.current.onFresh(r.listing);
303
+ } else if (!silent) setListing("error");
304
+ return r.listing;
305
+ }),
306
+ [endpoint, path, enqueue, commit, learn]
307
+ );
308
+ const sort = (0, import_react.useCallback)(
309
+ (next) => enqueue(async (stale) => {
310
+ if (next === data.current.order) return next;
311
+ const r = learn(next, await fetchPages(endpoint, path, next, 1, legacy.current));
312
+ if (stale()) return void 0;
313
+ if (!r.listing) return data.current.order;
314
+ commit({ listing: r.listing, order: next, pages: 1, sort: r.sort });
315
+ callbacks.current.onFresh(r.listing);
316
+ return next;
317
+ }),
318
+ [endpoint, path, enqueue, commit, learn]
319
+ );
320
+ const more = (0, import_react.useCallback)(
321
+ () => enqueue(async (stale) => {
322
+ const { listing: before, order: current, pages, sort: wire } = data.current;
323
+ if (!before?.next_cursor) return void 0;
324
+ const r = await fetchNext(endpoint, path, current, { listing: before, pages, sort: wire }, legacy.current);
325
+ if (stale()) return void 0;
326
+ if (r.restarted) learn(current, r);
327
+ if (!r.listing) return { ok: false };
328
+ const known = new Set(before.comments.map((c) => c.id));
329
+ commit({ listing: r.listing, order: current, pages: r.pages, sort: r.sort });
330
+ if (r.restarted) callbacks.current.onFresh(r.listing);
331
+ 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)) };
332
+ }),
333
+ [endpoint, path, enqueue, commit, learn]
334
+ );
335
+ (0, import_react.useEffect)(() => {
336
+ data.current = { listing: initial, order: "newest", pages: 1, sort: void 0 };
337
+ legacy.current = false;
338
+ queue.current = Promise.resolve();
339
+ setListing(initial ?? "loading");
340
+ setOrder("newest");
341
+ setServed(void 0);
342
+ callbacks.current.onReset();
343
+ return () => void (generation.current += 1);
344
+ }, [endpoint, path, initial]);
345
+ (0, import_react.useEffect)(() => {
346
+ if (active) void reload(initial !== void 0);
347
+ }, [active, reload, initial]);
348
+ return { listing, order, served, reload, sort, more, retry: () => {
349
+ setListing("loading");
350
+ void reload(false);
351
+ } };
352
+ }
152
353
 
153
354
  // src/react/comments-parts.tsx
154
- var import_react2 = require("react");
355
+ var import_react5 = require("react");
155
356
 
156
357
  // src/react/comments-body.tsx
157
358
  var import_hast_util_to_jsx_runtime = require("hast-util-to-jsx-runtime");
158
- var import_react = require("react");
359
+ var import_react2 = require("react");
159
360
  var import_jsx_runtime = require("react/jsx-runtime");
160
361
 
161
362
  // src/asset-path.ts
@@ -187,8 +388,15 @@ var isScalar = (v) => typeof v === "string" || typeof v === "number" || typeof v
187
388
  var matches = (re) => (v) => typeof v === "string" && re.test(v);
188
389
  var ID_PREFIX = "user-content-";
189
390
  var scopeId = (id) => id.startsWith(ID_PREFIX) ? id : ID_PREFIX + id;
190
- var ID_BODY = /^[\p{L}\p{N}_:.-]{1,180}$/u;
191
- var isIdValue = (v) => typeof v === "string" && ID_BODY.test(v.startsWith(ID_PREFIX) ? v.slice(ID_PREFIX.length) : v);
391
+ var ID_BODY = /^[\p{L}\p{M}\p{N}\p{Pc}:.-]{1,180}$/u;
392
+ function isIdValue(v) {
393
+ if (typeof v !== "string") return false;
394
+ try {
395
+ return ID_BODY.test(decodeURIComponent(v.startsWith(ID_PREFIX) ? v.slice(ID_PREFIX.length) : v));
396
+ } catch {
397
+ return false;
398
+ }
399
+ }
192
400
  var CLASS_TOKEN = /^[A-Za-z_][\w:-]*$/;
193
401
  var classTokens = (v) => {
194
402
  const tokens = Array.isArray(v) ? v : typeof v === "string" ? v.split(/\s+/) : [];
@@ -201,6 +409,7 @@ var isLength = matches(/^[\d.]+(em|px|%)?$/);
201
409
  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"]);
202
410
  var STYLE_LENGTH = /^(-?\d+(?:\.\d+)?)(em|px|%)?$/;
203
411
  var MAX_STYLE_MAGNITUDE = 100;
412
+ var MAX_MARGIN_MAGNITUDE = 20;
204
413
  function isKatexStyle(v, ctx) {
205
414
  if (typeof v !== "string" || !ctx.katex) return false;
206
415
  return v.split(";").filter((d) => d !== "").every((decl) => {
@@ -208,7 +417,8 @@ function isKatexStyle(v, ctx) {
208
417
  if (extra.length > 0 || prop === void 0 || value === void 0) return false;
209
418
  if (prop === "position") return value === "relative";
210
419
  const m = STYLE_LENGTH.exec(value);
211
- return STYLE_PROPS.has(prop) && m !== null && Math.abs(Number(m[1])) <= MAX_STYLE_MAGNITUDE;
420
+ const max = prop.startsWith("margin-") ? MAX_MARGIN_MAGNITUDE : MAX_STYLE_MAGNITUDE;
421
+ return STYLE_PROPS.has(prop) && m !== null && Math.abs(Number(m[1])) <= max;
212
422
  });
213
423
  }
214
424
  function isSafeUrl(value, kind) {
@@ -233,6 +443,8 @@ var MERMAID_SRCDOC = new RegExp(
233
443
  var isMermaidSrcdoc = (v) => typeof v === "string" && v.length <= MAX_SRCDOC && MERMAID_SRCDOC.test(v);
234
444
  var RENDER_REF = /^(\/assets\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\.svg) ([1-9]\d{0,5}) ([1-9]\d{0,5})$/;
235
445
  var isRenderRef = matches(RENDER_REF);
446
+ var YOUTUBE_WATCH = /^https:\/\/www\.youtube\.com\/watch\?v=([A-Za-z0-9_-]{11})$/;
447
+ var youtubeId = (href) => typeof href === "string" ? YOUTUBE_WATCH.exec(href)?.[1] : void 0;
236
448
  var heading = { id: isIdValue, className: isClass };
237
449
  var ATTRS = new Map(
238
450
  Object.entries({
@@ -248,6 +460,7 @@ var ATTRS = new Map(
248
460
  tbody: {},
249
461
  tr: {},
250
462
  ol: {},
463
+ kbd: {},
251
464
  ul: { className: isClass },
252
465
  li: { id: isIdValue, className: isClass },
253
466
  h1: heading,
@@ -256,8 +469,8 @@ var ATTRS = new Map(
256
469
  h4: heading,
257
470
  h5: heading,
258
471
  h6: heading,
259
- a: { href: isHref, id: isIdValue, ariaDescribedBy: isIdValue, ariaLabel: isString, dataFootnoteRef: isScalar, dataFootnoteBackref: isScalar, className: isClass },
260
- img: { src: isSrc, alt: isString, width: isPixels, height: isPixels },
472
+ a: { href: isHref, id: isIdValue, ariaDescribedBy: isIdValue, ariaLabel: isString, dataFootnoteRef: isScalar, dataFootnoteBackref: isScalar, dataEmbed: matches(/^youtube$/), className: isClass },
473
+ img: { src: isSrc, alt: isString, title: isString, width: isPixels, height: isPixels },
261
474
  table: {},
262
475
  th: { scope: matches(/^(row|col|rowgroup|colgroup)$/), align: isAlign },
263
476
  td: { align: isAlign },
@@ -280,8 +493,10 @@ function textOf(node, depth = 0) {
280
493
  if (node.type === "text") return typeof node.value === "string" ? node.value : "";
281
494
  return Array.isArray(node.children) ? node.children.map((c) => textOf(c, depth + 1)).join("") : "";
282
495
  }
496
+ 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)));
497
+ var collapse = (text) => text.replace(/\s+/g, " ").trim();
283
498
  var CALLOUT_MARKER = /^\s*\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*/i;
284
- var CALLOUT_KIND = { note: "note", tip: "tip", important: "warning", warning: "warning", caution: "caution" };
499
+ var CALLOUT_KIND = { note: "note", tip: "tip", important: "important", warning: "warning", caution: "caution" };
285
500
  function toCallout(children) {
286
501
  const first = children.find((c) => c.type === "element");
287
502
  const lead = first?.tagName === "p" ? first.children[0] : void 0;
@@ -293,6 +508,21 @@ function toCallout(children) {
293
508
  const kind = CALLOUT_KIND[(marker[1] ?? "note").toLowerCase()] ?? "note";
294
509
  return { type: "element", tagName: "callout", properties: { kind }, children: [...body, ...children.slice(children.indexOf(first) + 1)] };
295
510
  }
511
+ var isBlank = (node) => node.type === "text" && node.value.trim() === "";
512
+ function soleElement(children) {
513
+ const [only, ...more] = children.filter((c) => !isBlank(c));
514
+ return more.length === 0 && only?.type === "element" ? only : void 0;
515
+ }
516
+ function toFigure(children) {
517
+ const only = soleElement(children);
518
+ const img = only?.tagName === "a" ? soleElement(only.children) : only;
519
+ if (!only || img?.tagName !== "img" || typeof img.properties.src !== "string") return void 0;
520
+ const { title, ...properties } = img.properties;
521
+ const bare = { ...img, properties };
522
+ const media = only === img ? bare : { ...only, children: [bare] };
523
+ const caption = typeof title === "string" && title.trim() ? [{ type: "element", tagName: "figcaption", properties: {}, children: [{ type: "text", value: title }] }] : [];
524
+ return { type: "element", tagName: "figure", properties: { dataSlotComponent: "Image" }, children: [media, ...caption] };
525
+ }
296
526
  function clean(node, depth, ctx, budget) {
297
527
  if (!isObject2(node) || depth > MAX_DEPTH) return [];
298
528
  if (++budget.nodes > MAX_NODES) throw new HastLimitError("content has too many nodes");
@@ -326,6 +556,11 @@ function clean(node, depth, ctx, budget) {
326
556
  }
327
557
  for (const key of ["id", "ariaDescribedBy"]) if (typeof properties[key] === "string") properties[key] = scopeId(properties[key]);
328
558
  if (tag === "a" && typeof properties.href === "string" && properties.href.trim().startsWith("#")) properties.href = `#${scopeId(properties.href.trim().slice(1))}`;
559
+ if (tag === "a" && properties.dataEmbed !== void 0 && youtubeId(properties.href) === void 0) delete properties.dataEmbed;
560
+ if (tag === "p") {
561
+ const figure = toFigure(children);
562
+ if (figure) return [figure];
563
+ }
329
564
  if (tag === "blockquote") {
330
565
  const callout = toCallout(children);
331
566
  if (callout) return [callout];
@@ -337,9 +572,9 @@ function sanitizeHast(tree, title, description) {
337
572
  const raw = isObject2(tree) && tree.type === "root" && Array.isArray(tree.children) ? tree.children : [];
338
573
  const elements = raw.filter((n) => isObject2(n) && n.type === "element");
339
574
  const [first] = elements;
340
- const skip = title !== void 0 && isObject2(first) && first.tagName === "h1" && textOf(first).trim() === title.trim() ? first : void 0;
575
+ const skip = title !== void 0 && isObject2(first) && first.tagName === "h1" && collapse(textOf(first)) === collapse(title) ? first : void 0;
341
576
  const lead = elements[skip ? 1 : 0];
342
- const repeat = description && isObject2(lead) && lead.tagName === "p" && textOf(lead).trim().startsWith(description.trim()) ? lead : void 0;
577
+ const repeat = description && isObject2(lead) && lead.tagName === "p" && collapse(textOf(lead)).startsWith(collapse(description)) && !holdsEmbed(lead) ? lead : void 0;
343
578
  const budget = { nodes: 0, text: 0 };
344
579
  return { type: "root", children: raw.filter((n) => n !== skip && n !== repeat).flatMap((n) => clean(n, 0, { katex: false }, budget)) };
345
580
  }
@@ -368,7 +603,7 @@ function CommentBody({ tree }) {
368
603
  if (error instanceof HastLimitError) return null;
369
604
  throw error;
370
605
  }
371
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "hyle-cm-body", children: (0, import_hast_util_to_jsx_runtime.toJsxRuntime)({ type: "root", children }, { Fragment: import_react.Fragment, jsx: import_jsx_runtime.jsx, jsxs: import_jsx_runtime.jsxs, elementAttributeNameCase: "react", stylePropertyNameCase: "dom" }) });
606
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "hyle-cm-body", children: (0, import_hast_util_to_jsx_runtime.toJsxRuntime)({ type: "root", children }, { Fragment: import_react2.Fragment, jsx: import_jsx_runtime.jsx, jsxs: import_jsx_runtime.jsxs, elementAttributeNameCase: "react", stylePropertyNameCase: "dom" }) });
372
607
  }
373
608
 
374
609
  // src/react/comments-markdown.ts
@@ -424,6 +659,9 @@ function hastToMarkdown(tree) {
424
659
  }
425
660
  }
426
661
 
662
+ // src/react/comments-votes.tsx
663
+ var import_react3 = require("react");
664
+
427
665
  // src/react/icons.tsx
428
666
  var import_jsx_runtime3 = require("react/jsx-runtime");
429
667
  var SHAPES = {
@@ -453,9 +691,16 @@ var SHAPES = {
453
691
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M9 1.8v3h3" })
454
692
  ] }),
455
693
  chev: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "m6 3.5 4.5 4.5L6 12.5" }),
694
+ "chev-up": /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "m3.5 10 4.5-4.5L12.5 10" }),
456
695
  "chev-down": /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "m3.5 6 4.5 4.5L12.5 6" }),
457
696
  "chev-left": /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M10 3.5 5.5 8 10 12.5" }),
458
697
  x: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "m4 4 8 8M12 4l-8 8" }),
698
+ important: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M3 2.5h10a1 1 0 0 1 1 1v7a1 1 0 0 1-1 1H8l-3.5 2.8v-2.8H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 1-1zM8 5v2.8M8 9.5v.1" }),
699
+ copy: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
700
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("rect", { x: "5.5", y: "5.5", width: "8", height: "8", rx: "1.3" }),
701
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M10.5 5.5v-2a1 1 0 0 0-1-1h-6a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2" })
702
+ ] }),
703
+ check: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "m3 8.5 3.2 3L13 4.5" }),
459
704
  heart: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("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" }),
460
705
  reply: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M6.5 3.5 2.5 7.5l4 4M2.5 7.5h6a5 5 0 0 1 5 5" }),
461
706
  clock: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
@@ -472,8 +717,149 @@ function Icon({ name, className }) {
472
717
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("svg", { className: className ? `hyle-ic ${className}` : "hyle-ic", viewBox: "0 0 16 16", "aria-hidden": "true", children: SHAPES[name] });
473
718
  }
474
719
 
475
- // src/react/comments-parts.tsx
720
+ // src/react/comments-votes.tsx
476
721
  var import_jsx_runtime4 = require("react/jsx-runtime");
722
+ function useVotes(endpoint) {
723
+ const [overlay, setOverlay] = (0, import_react3.useState)({});
724
+ const pending = (0, import_react3.useRef)(/* @__PURE__ */ new Set());
725
+ async function cast(id, current, clicked) {
726
+ if (pending.current.has(id)) return void 0;
727
+ const next = nextVote(current, clicked);
728
+ pending.current.add(id);
729
+ setOverlay((o) => ({ ...o, [id]: next }));
730
+ const r = await call(endpoint, next.value === null ? "DELETE" : "PUT", "/votes", next.value === null ? { comment_id: id } : { comment_id: id, value: next.value });
731
+ pending.current.delete(id);
732
+ const vote = r.status === 200 && isObject(r.data) && isObject(r.data.vote) ? r.data.vote : void 0;
733
+ if (vote && Number.isSafeInteger(vote.score)) {
734
+ const state = { value: vote.value === 1 || vote.value === -1 ? vote.value : null, score: vote.score };
735
+ setOverlay((o) => ({ ...o, [id]: state }));
736
+ return { ok: true, state };
737
+ }
738
+ setOverlay((o) => ({ ...o, [id]: current }));
739
+ return { ok: false, status: r.status };
740
+ }
741
+ function settle(listing) {
742
+ const known = new Set(listing.comments.filter((c) => c.my_vote !== void 0).map((c) => c.id));
743
+ 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 }]] : [])));
744
+ }
745
+ return { overlay, cast, settle, reset: () => setOverlay({}) };
746
+ }
747
+ function VoteButtons({ s, name, state, own, access, signInHref, onVote }) {
748
+ function arrow(value) {
749
+ if (own) return null;
750
+ const icon = /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: value === 1 ? "chev-up" : "chev-down" });
751
+ const label = value === 1 ? s.upvote : s.downvote;
752
+ if (access === "out") return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("a", { className: "hyle-cm-btn", href: signInHref, children: [
753
+ icon,
754
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "hyle-sr", children: value === 1 ? s.upvoteSignIn : s.downvoteSignIn })
755
+ ] });
756
+ if (access !== "in") return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { className: "hyle-cm-btn", type: "button", "aria-disabled": "true", "aria-label": label, children: icon });
757
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { className: "hyle-cm-btn", type: "button", "aria-label": label, "aria-pressed": state.value === value, onClick: () => onVote(value), children: icon });
758
+ }
759
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "hyle-cm-votes", role: "group", "aria-label": s.votesOn.replace("{name}", () => name), children: [
760
+ arrow(1),
761
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "hyle-cm-score", children: [
762
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "hyle-sr", children: s.score.replace("{n}", String(state.score)) }),
763
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "aria-hidden": "true", children: state.score })
764
+ ] }),
765
+ arrow(-1)
766
+ ] });
767
+ }
768
+
769
+ // src/react/reaction-bar.tsx
770
+ var import_react4 = require("react");
771
+ var import_jsx_runtime5 = require("react/jsx-runtime");
772
+ var reactionKey = (subject, kind) => `${subject}:${kind}`;
773
+ var kindName = (s, kind) => ({ like: s.reactionLike, love: s.reactionLove, insightful: s.reactionInsightful, celebrate: s.reactionCelebrate })[kind];
774
+ function settleReactions(overlay, pending, listing) {
775
+ const told = new Set(listing.comments.filter((c) => c.my_reactions).map((c) => c.id));
776
+ if (listing.my_reactions) told.add("article");
777
+ return Object.fromEntries(Object.entries(overlay).flatMap(([key, v]) => {
778
+ if (pending.has(key)) return [[key, v]];
779
+ return v.on && !key.endsWith(":like") && !told.has(key.slice(0, key.lastIndexOf(":"))) ? [[key, { on: true }]] : [];
780
+ }));
781
+ }
782
+ function useReactions(endpoint, path) {
783
+ const [overlay, setOverlay] = (0, import_react4.useState)({});
784
+ const pending = (0, import_react4.useRef)(/* @__PURE__ */ new Set());
785
+ async function toggle(subject, kind, count2, on) {
786
+ const key = reactionKey(subject, kind);
787
+ if (pending.current.has(key)) return void 0;
788
+ const before = { on: overlay[key]?.on ?? on, count: overlay[key]?.count ?? count2 };
789
+ pending.current.add(key);
790
+ setOverlay((o) => ({ ...o, [key]: { on: !before.on, count: Math.max(0, before.count + (before.on ? -1 : 1)) } }));
791
+ const target = subject === "article" ? { subject_type: "article", path } : { subject_type: "comment", comment_id: subject };
792
+ const r = await call(endpoint, before.on ? "DELETE" : "PUT", "/reactions", kind === "like" ? target : { ...target, kind });
793
+ pending.current.delete(key);
794
+ const reaction = r.status === 200 && isObject(r.data) && isObject(r.data.reaction) ? r.data.reaction : void 0;
795
+ const counts = parseCounts(reaction?.counts);
796
+ const settled = counts ? counts[kind] ?? 0 : kind === "like" && typeof reaction?.like_count === "number" ? reaction.like_count : void 0;
797
+ if (reaction && settled !== void 0) {
798
+ const active = reaction.active === true;
799
+ setOverlay((o) => ({ ...o, [key]: { on: active, count: settled } }));
800
+ return { ok: true, on: active };
801
+ }
802
+ setOverlay((o) => ({ ...o, [key]: before }));
803
+ return { ok: false, status: r.status };
804
+ }
805
+ const settle = (listing) => setOverlay((o) => settleReactions(o, pending.current, listing));
806
+ return { overlay, toggle, settle, reset: () => setOverlay({}) };
807
+ }
808
+ function ReactionBar({ s, scope, subject, likes, counts, likedByMe, mine, overlay, access, signInHref, onToggle }) {
809
+ const [open, setOpen] = (0, import_react4.useState)(false);
810
+ const first = (0, import_react4.useRef)(null);
811
+ const trigger = (0, import_react4.useRef)(null);
812
+ (0, import_react4.useEffect)(() => {
813
+ if (open) first.current?.focus();
814
+ }, [open]);
815
+ const base = scope === "article" ? "hyle-btn" : "hyle-cm-btn cnt";
816
+ function button(kind) {
817
+ const state = overlay[reactionKey(subject, kind)];
818
+ const server = kind === "like" ? likes : counts?.[kind] ?? 0;
819
+ const serverOn = mine ? mine.includes(kind) : kind === "like" && likedByMe;
820
+ const count2 = state?.count ?? server;
821
+ const on = state?.on ?? serverOn;
822
+ if (kind !== "like" && !open && !state && count2 === 0) return null;
823
+ const out = access === "out";
824
+ const content = kind !== "like" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
825
+ out ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "hyle-sr", children: s.reactionSignIn }) : null,
826
+ kindName(s, kind),
827
+ " ",
828
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: count2 })
829
+ ] }) : scope === "article" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
830
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "heart" }),
831
+ out ? s.likeArticle : on ? s.likedArticle : s.likeArticle,
832
+ " ",
833
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "hyle-sr", children: out ? s.likeArticleSignIn : ", " }),
834
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: count2 })
835
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
836
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "heart" }),
837
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "hyle-sr", children: out ? s.likeCommentSignIn : s.likeComment }),
838
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: count2 })
839
+ ] });
840
+ const cls = kind === "like" ? base : `${base} chip`;
841
+ if (out && signInHref) return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("a", { className: cls, href: signInHref, children: content }, kind);
842
+ if (access !== "in") return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { className: cls, type: "button", "aria-disabled": "true", children: content }, kind);
843
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { ref: kind === "love" ? first : void 0, className: cls, type: "button", "aria-pressed": on, onClick: () => {
844
+ setOpen(false);
845
+ onToggle(kind, server, serverOn);
846
+ }, children: content }, kind);
847
+ }
848
+ if (!counts) return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_jsx_runtime5.Fragment, { children: button("like") });
849
+ const onKey = (e) => {
850
+ if (e.key !== "Escape" || !open) return;
851
+ e.preventDefault();
852
+ setOpen(false);
853
+ trigger.current?.focus();
854
+ };
855
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "hyle-reaction-set", role: "group", "aria-label": s.reactions, onKeyDown: onKey, children: [
856
+ REACTION_KINDS.map(button),
857
+ access === "in" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { ref: trigger, className: scope === "article" ? "hyle-btn" : "hyle-cm-btn", type: "button", "aria-expanded": open, onClick: () => setOpen((v) => !v), children: s.react }) : null
858
+ ] });
859
+ }
860
+
861
+ // src/react/comments-parts.tsx
862
+ var import_jsx_runtime6 = require("react/jsx-runtime");
477
863
  var MAX_CHARS = 4e3;
478
864
  var EDIT_WINDOW_MS = 10 * 60 * 1e3;
479
865
  var MAX_DEPTH2 = 4;
@@ -481,6 +867,7 @@ var fill = (template, values) => template.replace(/\{(\w+)\}/g, (_, k) => String
481
867
  var initials = (name) => name.trim().split(/\s+/).slice(0, 2).map((w) => [...w][0] ?? "").join("").toUpperCase() || "?";
482
868
  var replyButtonId = (ui, id) => `${ui.idp}-reply-${id}`;
483
869
  var nameId = (ui, id) => `${ui.idp}-${id}-n`;
870
+ var accessOf = (ui) => !ui.ready ? "pending" : !ui.me ? "out" : ui.banned ? "blocked" : "in";
484
871
  function relative(iso, now, locale, s) {
485
872
  const seconds = Math.round((now - Date.parse(iso)) / 1e3);
486
873
  if (!Number.isFinite(seconds)) return iso;
@@ -503,56 +890,19 @@ var absolute = (iso, locale) => {
503
890
  }
504
891
  };
505
892
  function Avatar({ name }) {
506
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "hyle-avatar", "aria-hidden": "true", children: name ? initials(name) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "ban" }) });
893
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "hyle-avatar", "aria-hidden": "true", children: name ? initials(name) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Icon, { name: "ban" }) });
507
894
  }
508
895
  function SignInLink({ ui, className, children }) {
509
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("a", { className, href: `#${ui.signInId}`, children });
510
- }
511
- function LikeButton({ ui, itemKey, serverCount, serverOn, scope }) {
512
- const { s } = ui;
513
- const state = ui.likes[itemKey];
514
- const count2 = state?.count ?? serverCount;
515
- const on = state?.on ?? serverOn;
516
- const cls = scope === "article" ? "hyle-btn" : "hyle-cm-btn cnt";
517
- const lead = scope === "article" ? on ? s.likedArticle : s.likeArticle : null;
518
- const sr = scope === "article" ? ", " : s.likeComment;
519
- const icon = /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "heart" });
520
- if (ui.ready && !ui.me) {
521
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(SignInLink, { ui, className: cls, children: [
522
- icon,
523
- lead ?? null,
524
- scope === "article" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
525
- " ",
526
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "hyle-sr", children: s.likeArticleSignIn })
527
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "hyle-sr", children: s.likeCommentSignIn }),
528
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: count2 })
529
- ] });
530
- }
531
- if (ui.banned || !ui.ready) {
532
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("button", { className: cls, type: "button", "aria-disabled": "true", children: [
533
- icon,
534
- lead,
535
- scope === "article" ? " " : null,
536
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "hyle-sr", children: sr }),
537
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: count2 })
538
- ] });
539
- }
540
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("button", { className: cls, type: "button", "aria-pressed": on, onClick: () => ui.actions.like(itemKey, serverCount, serverOn), children: [
541
- icon,
542
- lead,
543
- scope === "article" ? " " : null,
544
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "hyle-sr", children: sr }),
545
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: count2 })
546
- ] });
896
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("a", { className, href: `#${ui.signInId}`, children });
547
897
  }
548
898
  function Composer({ ui, id, parentId, name, autoFocus, onCancel }) {
549
899
  const { s } = ui;
550
- const [text, setText] = (0, import_react2.useState)("");
551
- const [busy, setBusy] = (0, import_react2.useState)(false);
552
- const [error, setError] = (0, import_react2.useState)(null);
553
- const area = (0, import_react2.useRef)(null);
900
+ const [text, setText] = (0, import_react5.useState)("");
901
+ const [busy, setBusy] = (0, import_react5.useState)(false);
902
+ const [error, setError] = (0, import_react5.useState)(null);
903
+ const area = (0, import_react5.useRef)(null);
554
904
  const limited = ui.rateLeft > 0;
555
- (0, import_react2.useEffect)(() => {
905
+ (0, import_react5.useEffect)(() => {
556
906
  if (autoFocus) area.current?.focus();
557
907
  }, [autoFocus]);
558
908
  async function submit() {
@@ -586,19 +936,19 @@ function Composer({ ui, id, parentId, name, autoFocus, onCancel }) {
586
936
  };
587
937
  const helpId = `${id}-help`;
588
938
  const errId = `${id}-err`;
589
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("form", { className: "hyle-cm-compose", onSubmit: (e) => {
939
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("form", { className: "hyle-cm-compose", onSubmit: (e) => {
590
940
  e.preventDefault();
591
941
  void submit();
592
942
  }, children: [
593
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Avatar, { name }),
594
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { children: [
595
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("p", { className: "hyle-cm-as", children: [
943
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Avatar, { name }),
944
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { children: [
945
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("p", { className: "hyle-cm-as", children: [
596
946
  s.commentingAs.split("{name}")[0],
597
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("b", { children: name }),
947
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("b", { children: name }),
598
948
  s.commentingAs.split("{name}")[1]
599
949
  ] }),
600
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("label", { className: "hyle-sr", htmlFor: id, children: parentId ? s.replyPlaceholder : s.write }),
601
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
950
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("label", { className: "hyle-sr", htmlFor: id, children: parentId ? s.replyPlaceholder : s.write }),
951
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
602
952
  "textarea",
603
953
  {
604
954
  ref: area,
@@ -615,26 +965,26 @@ function Composer({ ui, id, parentId, name, autoFocus, onCancel }) {
615
965
  onKeyDown: onKey
616
966
  }
617
967
  ),
618
- error ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("p", { className: "hyle-cm-err", id: errId, role: "alert", children: [
619
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "alert" }),
620
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: error })
968
+ error ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("p", { className: "hyle-cm-err", id: errId, role: "alert", children: [
969
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Icon, { name: "alert" }),
970
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: error })
621
971
  ] }) : null,
622
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "hyle-cm-foot", children: [
623
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "grow", id: helpId, children: limited ? fill(s.rateWait, { n: ui.rateLeft }) : s.help }),
624
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "cnt", children: fill(s.chars, { n: [...text].length, max: MAX_CHARS }) }),
625
- onCancel ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { className: "hyle-btn sm", type: "button", onClick: onCancel, children: s.cancel }) : null,
626
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { className: "hyle-btn primary", type: "submit", "aria-disabled": busy || limited ? true : void 0, "aria-busy": busy || void 0, children: busy ? s.posting : parentId ? s.reply : s.post })
972
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "hyle-cm-foot", children: [
973
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "grow", id: helpId, children: limited ? fill(s.rateWait, { n: ui.rateLeft }) : s.help }),
974
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "cnt", children: fill(s.chars, { n: [...text].length, max: MAX_CHARS }) }),
975
+ onCancel ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { className: "hyle-btn sm", type: "button", onClick: onCancel, children: s.cancel }) : null,
976
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { className: "hyle-btn primary", type: "submit", "aria-disabled": busy || limited ? true : void 0, "aria-busy": busy || void 0, children: busy ? s.posting : parentId ? s.reply : s.post })
627
977
  ] })
628
978
  ] })
629
979
  ] });
630
980
  }
631
981
  function EditForm({ ui, node, initial }) {
632
982
  const { s } = ui;
633
- const [text, setText] = (0, import_react2.useState)(initial);
634
- const [busy, setBusy] = (0, import_react2.useState)(false);
635
- const [error, setError] = (0, import_react2.useState)(null);
636
- const area = (0, import_react2.useRef)(null);
637
- (0, import_react2.useEffect)(() => area.current?.focus(), []);
983
+ const [text, setText] = (0, import_react5.useState)(initial);
984
+ const [busy, setBusy] = (0, import_react5.useState)(false);
985
+ const [error, setError] = (0, import_react5.useState)(null);
986
+ const area = (0, import_react5.useRef)(null);
987
+ (0, import_react5.useEffect)(() => area.current?.focus(), []);
638
988
  const id = `${ui.idp}-edit-${node.id}`;
639
989
  async function save() {
640
990
  if (busy) return;
@@ -646,12 +996,12 @@ function EditForm({ ui, node, initial }) {
646
996
  setError(r.reason === "tooLong" ? s.tooLong : r.reason === "closed" ? s.editClosed : r.reason === "expired" ? s.expired : r.reason === "rate" ? s.rateTitle : s.postError);
647
997
  area.current?.focus();
648
998
  }
649
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("form", { onSubmit: (e) => {
999
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("form", { onSubmit: (e) => {
650
1000
  e.preventDefault();
651
1001
  void save();
652
1002
  }, children: [
653
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("label", { className: "hyle-sr", htmlFor: id, children: s.edit }),
654
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1003
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("label", { className: "hyle-sr", htmlFor: id, children: s.edit }),
1004
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
655
1005
  "textarea",
656
1006
  {
657
1007
  ref: area,
@@ -674,14 +1024,14 @@ function EditForm({ ui, node, initial }) {
674
1024
  }
675
1025
  }
676
1026
  ),
677
- error ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("p", { className: "hyle-cm-err", id: `${id}-err`, role: "alert", children: [
678
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "alert" }),
679
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: error })
1027
+ error ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("p", { className: "hyle-cm-err", id: `${id}-err`, role: "alert", children: [
1028
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Icon, { name: "alert" }),
1029
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: error })
680
1030
  ] }) : null,
681
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "hyle-cm-foot", children: [
682
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "grow" }),
683
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { className: "hyle-btn sm", type: "button", onClick: () => ui.actions.edit(null), children: s.cancel }),
684
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { className: "hyle-btn sm primary", type: "submit", "aria-disabled": busy ? true : void 0, children: s.save })
1031
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "hyle-cm-foot", children: [
1032
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "grow" }),
1033
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { className: "hyle-btn sm", type: "button", onClick: () => ui.actions.edit(null), children: s.cancel }),
1034
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { className: "hyle-btn sm primary", type: "submit", "aria-disabled": busy ? true : void 0, children: s.save })
685
1035
  ] })
686
1036
  ] });
687
1037
  }
@@ -692,46 +1042,49 @@ function Actions({ ui, node }) {
692
1042
  const until = node.canEditUntil ?? (local ? local.at + EDIT_WINDOW_MS : void 0);
693
1043
  const minutes = until === void 0 ? 0 : Math.min(10, Math.ceil((until - Math.max(ui.now, local?.at ?? 0)) / 6e4));
694
1044
  const canReply = node.depth < MAX_DEPTH2 && node.status === "visible";
1045
+ const vote = ui.votes[node.id];
1046
+ const shownVote = { value: vote ? vote.value : node.myVote ?? null, score: vote?.score ?? node.score ?? 0 };
695
1047
  if (ui.confirming === node.id) {
696
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "hyle-cm-acts", role: "group", "aria-label": s.deleteConfirm, children: [
697
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "hyle-cm-depth", children: s.deleteConfirm }),
698
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { className: "hyle-cm-btn danger", type: "button", onClick: () => ui.actions.remove(node.id), children: s.delete }),
699
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { className: "hyle-cm-btn", type: "button", autoFocus: true, onClick: () => ui.actions.confirm(null), children: s.keep })
700
- ] });
1048
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "hyle-cm-acts", role: "group", "aria-label": s.deleteConfirm, children: [
1049
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "hyle-cm-depth", children: s.deleteConfirm }),
1050
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { className: "hyle-cm-btn danger", type: "button", onClick: () => ui.actions.remove(node.id), children: s.delete }),
1051
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { className: "hyle-cm-btn", type: "button", autoFocus: true, onClick: () => ui.actions.confirm(null), children: s.keep })
1052
+ ] }, "confirm");
701
1053
  }
702
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "hyle-cm-acts", children: [
703
- node.status === "visible" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(LikeButton, { ui, itemKey: node.id, serverCount: node.likes, serverOn: node.likedByMe, scope: "comment" }) : null,
704
- canReply && ui.me && !ui.banned ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("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: [
705
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "reply" }),
1054
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "hyle-cm-acts", children: [
1055
+ node.status === "visible" && node.score !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(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,
1056
+ node.status === "visible" ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(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, count2, on) => ui.actions.react(node.id, kind, count2, on) }) : null,
1057
+ canReply && ui.me && !ui.banned ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("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: [
1058
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Icon, { name: "reply" }),
706
1059
  s.reply
707
1060
  ] }) : null,
708
- canReply && !ui.me ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(SignInLink, { ui, className: "hyle-cm-btn", children: [
709
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "reply" }),
710
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "hyle-sr", children: fill(s.replyTo, { name: node.name ?? "" }) }),
711
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "aria-hidden": "true", children: s.reply })
1061
+ canReply && !ui.me ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(SignInLink, { ui, className: "hyle-cm-btn", children: [
1062
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Icon, { name: "reply" }),
1063
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "hyle-sr", children: fill(s.replyTo, { name: node.name ?? "" }) }),
1064
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { "aria-hidden": "true", children: s.reply })
712
1065
  ] }) : null,
713
- node.status === "visible" && node.depth >= MAX_DEPTH2 ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "hyle-cm-depth", children: s.depthEnd }) : null,
714
- mine && !ui.banned && minutes > 0 ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("button", { className: "hyle-cm-btn", type: "button", onClick: () => ui.actions.edit(node.id), children: [
1066
+ node.status === "visible" && node.depth >= MAX_DEPTH2 ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "hyle-cm-depth", children: s.depthEnd }) : null,
1067
+ mine && !ui.banned && minutes > 0 ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("button", { className: "hyle-cm-btn", type: "button", onClick: () => ui.actions.edit(node.id), children: [
715
1068
  s.edit,
716
1069
  " ",
717
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("small", { children: fill(s.editLeft, { n: minutes }) })
1070
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("small", { children: fill(s.editLeft, { n: minutes }) })
718
1071
  ] }) : null,
719
- mine && !ui.banned ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { className: "hyle-cm-btn danger", type: "button", onClick: () => ui.actions.confirm(node.id), children: s.delete }) : null
1072
+ mine && !ui.banned ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { className: "hyle-cm-btn danger", type: "button", onClick: () => ui.actions.confirm(node.id), children: s.delete }) : null
720
1073
  ] });
721
1074
  }
722
1075
  function Thread({ ui, nodes }) {
723
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("ol", { className: "hyle-cm-list", role: "list", children: nodes.map((node) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CommentItem, { ui, node }, node.id)) });
1076
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("ol", { className: "hyle-cm-list", role: "list", children: nodes.map((node) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CommentItem, { ui, node }, node.id)) });
724
1077
  }
725
1078
  function CommentItem({ ui, node }) {
726
1079
  const { s } = ui;
727
1080
  const li = `${ui.idp}-c-${node.id}`;
728
- const kids = node.kids.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Thread, { ui, nodes: node.kids }) : null;
1081
+ const kids = node.kids.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Thread, { ui, nodes: node.kids }) : null;
729
1082
  if (node.status === "removed") {
730
1083
  const why = node.removedBy === "moderator" ? s.removedByModerator : node.removedBy === "author" ? s.removedByAuthor : s.removed;
731
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("li", { className: "hyle-cm", id: li, "data-depth": node.depth, "data-status": "removed", "data-removed-by": node.removedBy, children: [
732
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("article", { "aria-label": why, children: [
733
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Avatar, { name: null }),
734
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "hyle-cm-main", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "hyle-cm-body", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { children: why }) }) })
1084
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("li", { className: "hyle-cm", id: li, "data-depth": node.depth, "data-status": "removed", "data-removed-by": node.removedBy, children: [
1085
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("article", { "aria-label": why, children: [
1086
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Avatar, { name: null }),
1087
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "hyle-cm-main", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "hyle-cm-body", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { children: why }) }) })
735
1088
  ] }),
736
1089
  kids
737
1090
  ] });
@@ -739,34 +1092,34 @@ function CommentItem({ ui, node }) {
739
1092
  const local = ui.own[node.id];
740
1093
  const mine = node.mine || !!local;
741
1094
  const editing = ui.editing === node.id && mine;
742
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("li", { className: "hyle-cm", id: li, "data-depth": node.depth, "data-status": node.status, children: [
743
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("article", { "aria-labelledby": nameId(ui, node.id), children: [
744
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Avatar, { name: node.name }),
745
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "hyle-cm-main", children: [
746
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "hyle-cm-by", children: [
747
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("b", { id: nameId(ui, node.id), tabIndex: -1, children: node.name }),
748
- mine ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "hyle-cm-tag", children: s.you }) : null,
749
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { children: [
750
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("time", { dateTime: node.createdAt, title: absolute(node.createdAt, ui.locale), children: relative(node.createdAt, ui.now, ui.locale, s) }),
751
- node.editedAt ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
1095
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("li", { className: "hyle-cm", id: li, "data-depth": node.depth, "data-status": node.status, children: [
1096
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("article", { "aria-labelledby": nameId(ui, node.id), children: [
1097
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Avatar, { name: node.name }),
1098
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "hyle-cm-main", children: [
1099
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "hyle-cm-by", children: [
1100
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("b", { id: nameId(ui, node.id), tabIndex: -1, children: node.name }),
1101
+ mine ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "hyle-cm-tag", children: s.you }) : null,
1102
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { children: [
1103
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("time", { dateTime: node.createdAt, title: absolute(node.createdAt, ui.locale), children: relative(node.createdAt, ui.now, ui.locale, s) }),
1104
+ node.editedAt ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
752
1105
  " ",
753
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "aria-hidden": "true", children: "\xB7" }),
1106
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { "aria-hidden": "true", children: "\xB7" }),
754
1107
  " ",
755
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("a", { href: `#${li}`, title: absolute(node.editedAt, ui.locale), children: s.edited })
1108
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("a", { href: `#${li}`, title: absolute(node.editedAt, ui.locale), children: s.edited })
756
1109
  ] }) : null
757
1110
  ] })
758
1111
  ] }),
759
- editing ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(EditForm, { ui, node, initial: local?.text ?? node.text ?? hastToMarkdown(node.tree) }) : node.text !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "hyle-cm-body", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { style: { whiteSpace: "pre-wrap" }, children: node.text }) }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CommentBody, { tree: node.tree }),
760
- node.status === "held" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("p", { className: "hyle-cm-held", role: "status", children: [
761
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "clock" }),
762
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { children: [
763
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("b", { children: s.held }),
1112
+ editing ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(EditForm, { ui, node, initial: local?.text ?? node.text ?? hastToMarkdown(node.tree) }) : node.text !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "hyle-cm-body", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { style: { whiteSpace: "pre-wrap" }, children: node.text }) }) : node.unrenderable ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "hyle-cm-body", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { children: s.unrenderable }) }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CommentBody, { tree: node.tree }),
1113
+ node.status === "held" ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("p", { className: "hyle-cm-held", role: "status", children: [
1114
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Icon, { name: "clock" }),
1115
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { children: [
1116
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("b", { children: s.held }),
764
1117
  " ",
765
1118
  s.heldNote
766
1119
  ] })
767
1120
  ] }) : null,
768
- editing ? null : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Actions, { ui, node }),
769
- ui.replyOpen === node.id && ui.me ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Composer, { ui, id: `${ui.idp}-rc-${node.id}`, parentId: node.id, name: ui.me, autoFocus: true, onCancel: () => ui.actions.reply(null) }) : null
1121
+ editing ? null : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Actions, { ui, node }),
1122
+ ui.replyOpen === node.id && ui.me ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Composer, { ui, id: `${ui.idp}-rc-${node.id}`, parentId: node.id, name: ui.me, autoFocus: true, onCancel: () => ui.actions.reply(null) }) : null
770
1123
  ] })
771
1124
  ] }),
772
1125
  kids
@@ -774,114 +1127,179 @@ function CommentItem({ ui, node }) {
774
1127
  }
775
1128
 
776
1129
  // src/react/comments.tsx
777
- var import_jsx_runtime5 = require("react/jsx-runtime");
1130
+ var import_jsx_runtime7 = require("react/jsx-runtime");
778
1131
  var PAGE = 20;
779
1132
  var TICK_MS = 1e4;
780
- var isObject3 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
1133
+ var NEAR = "600px 0px";
1134
+ var firstOf = (nodes, wanted) => {
1135
+ for (const n of nodes) {
1136
+ const found = wanted.has(n.id) ? n.id : firstOf(n.kids, wanted);
1137
+ if (found) return found;
1138
+ }
1139
+ return void 0;
1140
+ };
781
1141
  var fill2 = (t, n) => t.replace("{n}", String(n));
782
- function Comments({ path, endpoint, signInHref, locale, labels: s, initial, initialAt }) {
783
- const idp = `hc${(0, import_react3.useId)().replace(/[^A-Za-z0-9]/g, "")}`;
784
- const [session, setSession] = (0, import_react3.useState)("loading");
785
- const [listing, setListing] = (0, import_react3.useState)(initial ?? "loading");
786
- const [own, setOwn] = (0, import_react3.useState)({});
787
- const [held, setHeld] = (0, import_react3.useState)([]);
788
- const [likes, setLikes] = (0, import_react3.useState)({});
789
- const [replyOpen, setReplyOpen] = (0, import_react3.useState)(null);
790
- const [editing, setEditing] = (0, import_react3.useState)(null);
791
- const [confirming, setConfirming] = (0, import_react3.useState)(null);
792
- const [banned, setBanned] = (0, import_react3.useState)(false);
793
- const [expired, setExpired] = (0, import_react3.useState)(false);
794
- const [rateUntil, setRateUntil] = (0, import_react3.useState)(0);
795
- const [now, setNow] = (0, import_react3.useState)(() => initialAt ?? Date.now());
796
- const [live, setLive] = (0, import_react3.useState)("");
797
- const [actionError, setActionError] = (0, import_react3.useState)(null);
798
- const [shown, setShown] = (0, import_react3.useState)(PAGE);
799
- const [focusId, setFocusId] = (0, import_react3.useState)(null);
800
- const pending = (0, import_react3.useRef)(/* @__PURE__ */ new Set());
801
- const alive = (0, import_react3.useRef)(true);
802
- const write404 = (0, import_react3.useRef)(0);
803
- (0, import_react3.useEffect)(() => {
1142
+ var readerOf = (data) => {
1143
+ const reader = isObject(data) && isObject(data.reader) ? data.reader : void 0;
1144
+ if (typeof reader?.name !== "string") return void 0;
1145
+ return { id: typeof reader.id === "string" ? reader.id : reader.name, name: reader.name };
1146
+ };
1147
+ function Comments(props) {
1148
+ const [readers, setReaders] = (0, import_react6.useState)(0);
1149
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ArticleComments, { ...props, onNewReader: () => setReaders((n) => n + 1) }, `${props.endpoint}
1150
+ ${props.path}
1151
+ ${readers}`);
1152
+ }
1153
+ function ArticleComments({ path, endpoint, signInHref, locale, labels: s, initial, initialAt, lazy = false, articleReactions = true, onNewReader }) {
1154
+ const idp = `hc${(0, import_react6.useId)().replace(/[^A-Za-z0-9]/g, "")}`;
1155
+ const [session, setSession] = (0, import_react6.useState)("loading");
1156
+ const [own, setOwn] = (0, import_react6.useState)({});
1157
+ const [held, setHeld] = (0, import_react6.useState)([]);
1158
+ const [unseen, setUnseen] = (0, import_react6.useState)([]);
1159
+ const [replyOpen, setReplyOpen] = (0, import_react6.useState)(null);
1160
+ const [editing, setEditing] = (0, import_react6.useState)(null);
1161
+ const [confirming, setConfirming] = (0, import_react6.useState)(null);
1162
+ const [banned, setBanned] = (0, import_react6.useState)(false);
1163
+ const [expired, setExpired] = (0, import_react6.useState)(false);
1164
+ const [rateUntil, setRateUntil] = (0, import_react6.useState)(0);
1165
+ const [now, setNow] = (0, import_react6.useState)(() => initialAt ?? Date.now());
1166
+ const [live, setLive] = (0, import_react6.useState)("");
1167
+ const [actionError, setActionError] = (0, import_react6.useState)(null);
1168
+ const [shown, setShown] = (0, import_react6.useState)(PAGE);
1169
+ const [focusId, setFocusId] = (0, import_react6.useState)(null);
1170
+ const [near, setNear] = (0, import_react6.useState)(!lazy);
1171
+ const [chosen, setChosen] = (0, import_react6.useState)("newest");
1172
+ const [loadingMore, setLoadingMore] = (0, import_react6.useState)(false);
1173
+ const [moreFailed, setMoreFailed] = (0, import_react6.useState)(false);
1174
+ const root = (0, import_react6.useRef)(null);
1175
+ const sortClicks = (0, import_react6.useRef)(0);
1176
+ const reactions = useReactions(endpoint, path);
1177
+ const votes = useVotes(endpoint);
1178
+ const { listing, order, served, reload, sort, more, retry } = useCommentListing(
1179
+ endpoint,
1180
+ path,
1181
+ initial,
1182
+ near,
1183
+ (fresh) => {
1184
+ reactions.settle(fresh);
1185
+ votes.settle(fresh);
1186
+ },
1187
+ () => {
1188
+ reactions.reset();
1189
+ votes.reset();
1190
+ setUnseen([]);
1191
+ setChosen("newest");
1192
+ setLoadingMore(false);
1193
+ setMoreFailed(false);
1194
+ }
1195
+ );
1196
+ const alive = (0, import_react6.useRef)(true);
1197
+ const write404 = (0, import_react6.useRef)(0);
1198
+ (0, import_react6.useEffect)(() => {
804
1199
  alive.current = true;
805
1200
  return () => void (alive.current = false);
806
1201
  }, []);
807
- (0, import_react3.useEffect)(() => {
1202
+ (0, import_react6.useEffect)(() => {
808
1203
  if (initialAt !== void 0) setNow(Date.now());
809
1204
  const t = setInterval(() => setNow(Date.now()), TICK_MS);
810
1205
  return () => clearInterval(t);
811
1206
  }, [initialAt]);
812
- (0, import_react3.useEffect)(() => {
1207
+ (0, import_react6.useEffect)(() => {
813
1208
  if (rateUntil <= Date.now()) return;
814
1209
  const t = setTimeout(() => setNow(Date.now()), rateUntil - Date.now() + 50);
815
1210
  return () => clearTimeout(t);
816
1211
  }, [rateUntil]);
817
- const load = (0, import_react3.useCallback)(async (silent) => {
818
- const r = await call(endpoint, "GET", `/comments?path=${encodeURIComponent(path)}`);
819
- if (!alive.current) return void 0;
820
- const parsed = r.status === 200 ? parseListing(r.data) : void 0;
821
- if (r.status === 404) setListing("off");
822
- else if (parsed) {
823
- setListing(parsed);
824
- setLikes((l) => Object.fromEntries(Object.entries(l).filter(([k]) => pending.current.has(k))));
825
- } else if (!silent) setListing("error");
826
- return parsed;
827
- }, [endpoint, path]);
828
- (0, import_react3.useEffect)(() => {
829
- setListing(initial ?? "loading");
830
- void load(initial !== void 0);
1212
+ (0, import_react6.useEffect)(() => {
1213
+ if (near) return;
1214
+ const el = root.current;
1215
+ if (!el || typeof IntersectionObserver === "undefined") return setNear(true);
1216
+ const observer = new IntersectionObserver((entries) => entries.some((e) => e.isIntersecting) && setNear(true), { rootMargin: NEAR });
1217
+ observer.observe(el);
1218
+ return () => observer.disconnect();
1219
+ }, [near]);
1220
+ (0, import_react6.useEffect)(() => {
1221
+ if (!near) return;
831
1222
  void call(endpoint, "GET", "/session").then((r) => {
832
1223
  if (!alive.current) return;
833
- const reader = isObject3(r.data) && isObject3(r.data.reader) ? r.data.reader : void 0;
834
- setSession(r.status === 404 ? "off" : r.status === 200 && typeof reader?.name === "string" ? { name: reader.name } : null);
1224
+ const reader = r.status === 200 ? readerOf(r.data) : void 0;
1225
+ setSession(r.status === 404 ? "off" : reader ?? null);
835
1226
  });
836
- }, [endpoint, load, initial]);
837
- (0, import_react3.useEffect)(() => {
1227
+ }, [endpoint, near]);
1228
+ (0, import_react6.useEffect)(() => {
1229
+ if (typeof listing === "object") setUnseen((u) => stillUnseen(u, listing));
1230
+ }, [listing]);
1231
+ (0, import_react6.useEffect)(() => {
838
1232
  if (!focusId) return;
839
1233
  const el = document.getElementById(`${idp}-${focusId}-n`);
840
1234
  if (el) {
841
1235
  el.focus();
842
1236
  setFocusId(null);
843
1237
  }
844
- }, [focusId, listing, held, idp]);
845
- const me = typeof session === "object" && session ? session.name : null;
1238
+ }, [focusId, listing, held, unseen, idp]);
1239
+ const signedIn = typeof session === "object" ? session : null;
1240
+ const me = signedIn?.name ?? null;
846
1241
  const rateLeft = Math.max(0, Math.ceil((rateUntil - now) / 1e3));
847
1242
  const signInId = `${idp}-signin`;
848
- function failed(status) {
1243
+ async function recheck(status) {
1244
+ if (status !== 401 && !expired) return;
1245
+ const r = await call(endpoint, "GET", "/session");
1246
+ const reader = r.status === 200 ? readerOf(r.data) : void 0;
1247
+ if (alive.current && reader && reader.id !== signedIn?.id) onNewReader();
1248
+ }
1249
+ function failed(status, refusal) {
849
1250
  if (status === 401) setExpired(true);
850
- setActionError(status === 401 ? s.expired : s.actionError);
1251
+ setActionError(status === 401 ? s.expired : status === 429 ? s.slowDown : refusal ?? s.actionError);
851
1252
  }
852
- async function like(key, serverCount, serverOn) {
853
- if (!me || banned || pending.current.has(key)) return;
854
- const prev = likes[key] ?? { on: serverOn, count: serverCount };
855
- const count2 = prev.count ?? serverCount;
856
- pending.current.add(key);
1253
+ async function react(subject, kind, count2, on) {
1254
+ if (!me || banned) return;
857
1255
  setActionError(null);
858
- setLikes((l) => ({ ...l, [key]: { on: !prev.on, count: Math.max(0, count2 + (prev.on ? -1 : 1)) } }));
859
- const r = await call(endpoint, prev.on ? "DELETE" : "PUT", "/reactions", key === "article" ? { subject_type: "article", path } : { subject_type: "comment", comment_id: key });
860
- pending.current.delete(key);
861
- if (!alive.current) return;
862
- const reaction = r.status === 200 && isObject3(r.data) && isObject3(r.data.reaction) ? r.data.reaction : void 0;
863
- if (reaction && typeof reaction.like_count === "number") {
864
- setLikes((l) => ({ ...l, [key]: { on: reaction.active === true, count: reaction.like_count } }));
865
- return;
1256
+ const r = await reactions.toggle(subject, kind, count2, on);
1257
+ if (!r || !alive.current) return;
1258
+ void recheck(r.ok ? 200 : r.status);
1259
+ if (!r.ok) return failed(r.status);
1260
+ setLive((r.on ? s.reactionAddedLive : s.reactionRemovedLive).replace("{kind}", kindName(s, kind)));
1261
+ }
1262
+ async function vote(id, current, clicked) {
1263
+ if (!me || banned) return;
1264
+ setActionError(null);
1265
+ const r = await votes.cast(id, current, clicked);
1266
+ if (!r || !alive.current) return;
1267
+ void recheck(r.ok ? 200 : r.status);
1268
+ if (!r.ok) return failed(r.status, r.status === 400 ? s.voteRefused : void 0);
1269
+ setLive(fill2(r.state.value === 1 ? s.upvotedLive : r.state.value === -1 ? s.downvotedLive : s.voteRemovedLive, r.state.score));
1270
+ }
1271
+ async function choose(next) {
1272
+ if (next === chosen) return;
1273
+ const click = sortClicks.current += 1;
1274
+ setChosen(next);
1275
+ setActionError(null);
1276
+ setMoreFailed(false);
1277
+ const showing = await sort(next);
1278
+ if (!alive.current || click !== sortClicks.current || showing === void 0) return;
1279
+ if (showing !== next) {
1280
+ setChosen(showing);
1281
+ return setActionError(s.sortError);
866
1282
  }
867
- setLikes((l) => ({ ...l, [key]: { on: prev.on, count: count2 } }));
868
- failed(r.status);
1283
+ setShown(PAGE);
1284
+ setLive(next === "top" ? s.sortedTopLive : s.sortedNewestLive);
869
1285
  }
870
1286
  async function post(text, parentId) {
871
1287
  const r = await call(endpoint, "POST", "/comments", { path, body: text, ...parentId ? { parent_id: parentId } : {} });
872
- const created = r.status === 201 && isObject3(r.data) && isObject3(r.data.comment) ? r.data.comment : void 0;
1288
+ void recheck(r.status);
1289
+ const created = r.status === 201 && isObject(r.data) && isObject(r.data.comment) ? r.data.comment : void 0;
873
1290
  if (typeof created?.id === "string" && alive.current) {
874
1291
  const id = created.id;
875
1292
  write404.current = 0;
876
1293
  setOwn((o) => ({ ...o, [id]: { text, at: Date.now(), parentId } }));
877
1294
  setExpired(false);
878
- if (created.status === "held") {
879
- setHeld((h) => [{ id, parentId, text, name: me ?? "", createdAt: (/* @__PURE__ */ new Date()).toISOString() }, ...h]);
880
- setLive(s.heldLive);
881
- } else setLive(s.postedLive);
1295
+ const status = created.status === "held" ? "held" : "visible";
1296
+ const local = { id, parentId, text, name: me ?? "", createdAt: (/* @__PURE__ */ new Date()).toISOString() };
1297
+ setUnseen((u) => [{ ...local, status }, ...u]);
1298
+ if (status === "held") setHeld((h) => [local, ...h]);
1299
+ setLive(status === "held" ? s.heldLive : s.postedLive);
882
1300
  setShown(Number.MAX_SAFE_INTEGER);
883
1301
  setFocusId(id);
884
- await load(true);
1302
+ await reload(true);
885
1303
  return { ok: true };
886
1304
  }
887
1305
  if (r.status === 429) {
@@ -890,10 +1308,11 @@ function Comments({ path, endpoint, signInHref, locale, labels: s, initial, init
890
1308
  return { ok: false, reason: "rate" };
891
1309
  }
892
1310
  if (r.status === 404) {
893
- const [again, who] = await Promise.all([load(true), call(endpoint, "GET", "/session")]);
1311
+ const [again, who] = await Promise.all([reload(true), call(endpoint, "GET", "/session")]);
894
1312
  write404.current += 1;
895
- const valid = who.status === 200 && isObject3(who.data) && isObject3(who.data.reader) && typeof who.data.reader.name === "string";
896
- if (alive.current && valid && again && write404.current >= 2) setBanned(true);
1313
+ const reader = who.status === 200 ? readerOf(who.data) : void 0;
1314
+ if (alive.current && reader && reader.id !== signedIn?.id) onNewReader();
1315
+ else if (alive.current && reader && again && write404.current >= 2) setBanned(true);
897
1316
  return { ok: false, reason: "error" };
898
1317
  }
899
1318
  if (r.status === 401) setExpired(true);
@@ -901,15 +1320,20 @@ function Comments({ path, endpoint, signInHref, locale, labels: s, initial, init
901
1320
  }
902
1321
  async function save(id, text) {
903
1322
  const r = await call(endpoint, "PATCH", `/comments/${id}`, { body: text });
1323
+ void recheck(r.status);
904
1324
  if (r.status === 200 && alive.current) {
905
1325
  const meta = own[id];
906
1326
  setOwn((o) => ({ ...o, [id]: { text, at: o[id]?.at ?? Date.now(), parentId: o[id]?.parentId ?? null } }));
907
1327
  setHeld((h) => h.map((c) => c.id === id ? { ...c, text } : c));
1328
+ setUnseen((u) => u.map((c) => c.id === id ? { ...c, text } : c));
908
1329
  setEditing(null);
909
1330
  setLive(s.savedLive);
910
1331
  setFocusId(id);
911
- const fresh = await load(true);
912
- 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]);
1332
+ const fresh = await reload(true);
1333
+ if (fresh && !fresh.truncated && !fresh.next_cursor && !fresh.comments.some((c) => c.id === id)) {
1334
+ setUnseen((u) => u.filter((c) => c.id !== id));
1335
+ setHeld((h) => h.some((c) => c.id === id) ? h : [{ id, parentId: meta?.parentId ?? null, text, name: me ?? "", createdAt: (/* @__PURE__ */ new Date()).toISOString() }, ...h]);
1336
+ }
913
1337
  return { ok: true };
914
1338
  }
915
1339
  if (r.status === 429) {
@@ -924,15 +1348,38 @@ function Comments({ path, endpoint, signInHref, locale, labels: s, initial, init
924
1348
  setActionError(null);
925
1349
  const r = await call(endpoint, "DELETE", `/comments/${id}`);
926
1350
  if (!alive.current) return;
1351
+ void recheck(r.status);
927
1352
  setConfirming(null);
928
1353
  if (r.status !== 200) return failed(r.status);
929
1354
  setHeld((h) => h.filter((c) => c.id !== id));
1355
+ setUnseen((u) => u.filter((c) => c.id !== id));
930
1356
  setOwn(({ [id]: _gone, ...rest }) => rest);
931
1357
  setLive(s.deletedLive);
932
- await load(true);
1358
+ await reload(true);
933
1359
  }
934
- if (session === "off" || listing === "off") return null;
935
1360
  const loaded = typeof listing === "object" ? listing : void 0;
1361
+ const sortable = !!loaded && isSortable(loaded);
1362
+ const thread = loaded ? arrangeThread(loaded, served, held, unseen) : [];
1363
+ const oldestFirstPages = !!loaded && arrivesAs(loaded, served) === void 0;
1364
+ async function showMore() {
1365
+ if (thread.length > shown) {
1366
+ setShown(shown + PAGE);
1367
+ setFocusId(thread.slice(shown).find((n) => n.status !== "removed")?.id ?? null);
1368
+ return;
1369
+ }
1370
+ if (loadingMore) return;
1371
+ setLoadingMore(true);
1372
+ setMoreFailed(false);
1373
+ const r = await more();
1374
+ if (!alive.current) return;
1375
+ setLoadingMore(false);
1376
+ if (!r) return;
1377
+ if (!r.ok) return setMoreFailed(true);
1378
+ setShown(arrivesAs(r.listing, r.sort) === void 0 ? Number.MAX_SAFE_INTEGER : Math.min(shown, thread.length) + PAGE);
1379
+ setFocusId(firstOf(arrangeThread(r.listing, r.sort, held, unseen), r.added) ?? null);
1380
+ setLive(fill2(s.loadedLive, r.added.size));
1381
+ }
1382
+ if (session === "off" || listing === "off") return null;
936
1383
  const ui = {
937
1384
  s,
938
1385
  locale,
@@ -940,17 +1387,18 @@ function Comments({ path, endpoint, signInHref, locale, labels: s, initial, init
940
1387
  ready: session !== "loading",
941
1388
  me,
942
1389
  banned,
943
- signInHref,
944
1390
  signInId,
945
1391
  idp,
946
1392
  rateLeft,
947
1393
  own,
948
- likes,
1394
+ reactions: reactions.overlay,
1395
+ votes: votes.overlay,
949
1396
  replyOpen,
950
1397
  editing,
951
1398
  confirming,
952
1399
  actions: {
953
- like: (k, c, on) => void like(k, c, on),
1400
+ react: (subject, kind, count2, on) => void react(subject, kind, count2, on),
1401
+ vote: (id, current, clicked) => void vote(id, current, clicked),
954
1402
  reply: (id) => {
955
1403
  const previous = replyOpen;
956
1404
  setReplyOpen(id);
@@ -963,83 +1411,88 @@ function Comments({ path, endpoint, signInHref, locale, labels: s, initial, init
963
1411
  remove: (id) => void remove(id)
964
1412
  }
965
1413
  };
966
- const thread = loaded ? buildThread(loaded, held) : [];
967
1414
  const hid = `${idp}-h`;
968
1415
  const canWrite = !!me && !banned;
969
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("section", { className: "hyle-comments", "aria-labelledby": hid, "data-slot-component": "Comments", children: [
970
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "hyle-cm-head", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("h2", { id: hid, children: [
971
- s.heading,
972
- loaded ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
973
- " ",
974
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "hyle-cm-count", "aria-label": fill2(s.countLabel, loaded.comment_count), children: loaded.comment_count })
975
- ] }) : null
976
- ] }) }),
977
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "hyle-sr", role: "status", "aria-live": "polite", children: live }),
978
- actionError ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("p", { className: "hyle-cm-err", role: "alert", children: [
979
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "alert" }),
980
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: actionError })
1416
+ const unfetched = !!loaded?.next_cursor;
1417
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("section", { className: "hyle-comments", ref: root, "aria-labelledby": hid, "data-slot-component": "Comments", children: [
1418
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-cm-head", children: [
1419
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("h2", { id: hid, children: [
1420
+ s.heading,
1421
+ loaded ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
1422
+ " ",
1423
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "hyle-cm-count", "aria-label": fill2(s.countLabel, loaded.comment_count), children: loaded.comment_count })
1424
+ ] }) : null
1425
+ ] }),
1426
+ sortable && (order === "top" || thread.length > 1) ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "hyle-cm-sort", role: "group", "aria-label": s.sort, children: ["newest", "top"].map((o) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("button", { className: "hyle-cm-btn", type: "button", "aria-pressed": chosen === o, onClick: () => void choose(o), children: o === "top" ? s.sortTop : s.sortNewest }, o)) }) : null
1427
+ ] }),
1428
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "hyle-sr", role: "status", "aria-live": "polite", children: live }),
1429
+ actionError ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("p", { className: "hyle-cm-err", role: "alert", children: [
1430
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "alert" }),
1431
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { children: actionError })
981
1432
  ] }) : null,
982
- listing === "error" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "hyle-banner", "data-kind": "bad", role: "alert", children: [
983
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "alert" }),
984
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "hyle-bt", children: [
985
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("b", { children: s.loadError }),
986
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { children: s.loadErrorBody })
1433
+ listing === "error" ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-banner", "data-kind": "bad", role: "alert", children: [
1434
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "alert" }),
1435
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-bt", children: [
1436
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("b", { children: s.loadError }),
1437
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { children: s.loadErrorBody })
987
1438
  ] }),
988
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("button", { className: "hyle-btn sm", type: "button", onClick: () => {
989
- setListing("loading");
990
- void load(false);
991
- }, children: [
992
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "refresh" }),
1439
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("button", { className: "hyle-btn sm", type: "button", onClick: retry, children: [
1440
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "refresh" }),
993
1441
  s.retry
994
1442
  ] })
995
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
996
- loaded ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "hyle-react", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(LikeButton, { ui, itemKey: "article", serverCount: loaded.like_count, serverOn: loaded.liked_by_me === true, scope: "article" }) }) : null,
997
- held.length > 0 || (loaded?.mine_held?.length ?? 0) > 0 ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "hyle-banner", "data-kind": "warn", role: "status", children: [
998
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "clock" }),
999
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "hyle-bt", children: [
1000
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("b", { children: s.heldBanner }),
1001
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { children: s.heldBannerBody })
1443
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
1444
+ loaded && articleReactions ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "hyle-react", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(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, count2, on) => void react("article", kind, count2, on) }) }) : null,
1445
+ held.length > 0 || (loaded?.mine_held?.length ?? 0) > 0 ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-banner", "data-kind": "warn", role: "status", children: [
1446
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "clock" }),
1447
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-bt", children: [
1448
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("b", { children: s.heldBanner }),
1449
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { children: s.heldBannerBody })
1002
1450
  ] })
1003
1451
  ] }) : null,
1004
- rateLeft > 0 ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "hyle-banner", "data-kind": "warn", children: [
1005
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "clock" }),
1006
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "hyle-bt", children: [
1007
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("b", { children: s.rateTitle }),
1008
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { children: s.rateBody })
1452
+ rateLeft > 0 ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-banner", "data-kind": "warn", children: [
1453
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "clock" }),
1454
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-bt", children: [
1455
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("b", { children: s.rateTitle }),
1456
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { children: s.rateBody })
1009
1457
  ] })
1010
1458
  ] }) : null,
1011
- banned ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "hyle-banner", children: [
1012
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "ban" }),
1013
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "hyle-bt", children: [
1014
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("b", { children: s.bannedTitle }),
1015
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { children: s.bannedBody })
1459
+ banned ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-banner", children: [
1460
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "ban" }),
1461
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-bt", children: [
1462
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("b", { children: s.bannedTitle }),
1463
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { children: s.bannedBody })
1016
1464
  ] })
1017
1465
  ] }) : null,
1018
- session !== "loading" && (!me || expired) ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "hyle-cm-signin", id: signInId, children: [
1019
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("p", { children: [
1020
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("b", { children: s.signInTitle }),
1466
+ session !== "loading" && (!me || expired) ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-cm-signin", id: signInId, children: [
1467
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("p", { children: [
1468
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("b", { children: s.signInTitle }),
1021
1469
  s.signInBody
1022
1470
  ] }),
1023
- signInHref ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("a", { className: "hyle-btn primary", href: signInHref, children: s.signIn }) : null
1471
+ signInHref ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("a", { className: "hyle-btn primary", href: signInHref, children: s.signIn }) : null
1024
1472
  ] }) : null,
1025
- canWrite ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Composer, { ui, id: `${idp}-new`, parentId: null, name: me }) : null,
1026
- !loaded ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { role: "status", "aria-live": "polite", "aria-busy": "true", children: [
1027
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "hyle-sr", children: s.loading }),
1028
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { "aria-hidden": "true", children: [0, 1, 2].map((i) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "hyle-cm-sk", children: [
1029
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "hyle-sk c" }),
1030
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
1031
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "hyle-sk l", style: { width: 120 } }),
1032
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "hyle-sk l", style: { width: "100%" } }),
1033
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "hyle-sk l", style: { width: "72%" } })
1473
+ canWrite ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Composer, { ui, id: `${idp}-new`, parentId: null, name: me }) : null,
1474
+ !loaded ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { role: "status", "aria-live": "polite", "aria-busy": "true", children: [
1475
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "hyle-sr", children: s.loading }),
1476
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { "aria-hidden": "true", children: [0, 1, 2].map((i) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-cm-sk", children: [
1477
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "hyle-sk c" }),
1478
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { children: [
1479
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "hyle-sk l", style: { width: 120 } }),
1480
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "hyle-sk l", style: { width: "100%" } }),
1481
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "hyle-sk l", style: { width: "72%" } })
1034
1482
  ] })
1035
1483
  ] }, i)) })
1036
- ] }) : thread.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "hyle-cm-empty", children: [
1037
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("b", { children: s.empty }),
1038
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: s.emptyBody })
1039
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
1040
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Thread, { ui, nodes: thread.slice(0, shown) }),
1041
- thread.length > shown ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "hyle-cm-more", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { className: "hyle-btn", type: "button", onClick: () => setShown((n) => n + PAGE), children: s.more }) }) : null,
1042
- loaded.truncated ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "hyle-cm-note", children: s.truncated }) : null
1484
+ ] }) : thread.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-cm-empty", children: [
1485
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("b", { children: s.empty }),
1486
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { children: s.emptyBody })
1487
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
1488
+ sortable && oldestFirstPages && unfetched ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "hyle-cm-note", children: s.newerLater }) : null,
1489
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Thread, { ui, nodes: thread.slice(0, shown) }),
1490
+ moreFailed ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("p", { className: "hyle-cm-err", role: "alert", children: [
1491
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "alert" }),
1492
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { children: s.moreError })
1493
+ ] }) : null,
1494
+ thread.length > shown || unfetched ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "hyle-cm-more", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("button", { className: "hyle-btn", type: "button", "aria-disabled": loadingMore || void 0, "aria-busy": loadingMore || void 0, onClick: () => void showMore(), children: s.more }) }) : null,
1495
+ loaded.truncated && !unfetched ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "hyle-cm-note", children: s.truncated }) : null
1043
1496
  ] })
1044
1497
  ] })
1045
1498
  ] });