@tdacorp/hyle-sdk 0.9.0 → 0.12.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 (37) hide show
  1. package/README.md +111 -2
  2. package/bin/hyle-sdk-engage-keygen.mjs +3 -0
  3. package/dist/check-routes-bin.js +5 -1
  4. package/dist/{chunk-54JF4E53.js → chunk-N7ZQUAGM.js} +45 -2
  5. package/dist/chunk-R5EMI4HQ.js +61 -0
  6. package/dist/{chunk-XKR74Y5G.js → chunk-S7PCCEHP.js} +1 -1
  7. package/dist/{chunk-6LW33475.js → chunk-ZQFYH4FX.js} +538 -50
  8. package/dist/comments.cjs +1048 -0
  9. package/dist/comments.d.cts +152 -0
  10. package/dist/comments.d.ts +152 -0
  11. package/dist/comments.js +1025 -0
  12. package/dist/{types-BPPZrYOZ.d.cts → embed-DL5QIZRJ.d.ts} +44 -3
  13. package/dist/{types-C1eCQ2As.d.ts → embed-jCaSI31t.d.cts} +44 -3
  14. package/dist/engage-keygen-bin.js +67 -0
  15. package/dist/index.cjs +26 -1
  16. package/dist/index.d.cts +11 -3
  17. package/dist/index.d.ts +11 -3
  18. package/dist/index.js +5 -1
  19. package/dist/mermaid-diagram.js +9 -54
  20. package/dist/next.cjs +1010 -78
  21. package/dist/next.d.cts +163 -6
  22. package/dist/next.d.ts +163 -6
  23. package/dist/next.js +442 -14
  24. package/dist/react.cjs +340 -49
  25. package/dist/react.d.cts +112 -7
  26. package/dist/react.d.ts +112 -7
  27. package/dist/react.js +7 -1
  28. package/dist/{resolve-Dpb6Orsj.d.ts → resolve-DvmuBlpO.d.ts} +1 -1
  29. package/dist/{resolve-D2rnnho9.d.cts → resolve-f6IJ6SL9.d.cts} +1 -1
  30. package/dist/styles.css +117 -0
  31. package/dist/{types-CHxH5E0S.d.cts → types-5D6ZD0Wi.d.cts} +59 -1
  32. package/dist/{types-CHxH5E0S.d.ts → types-5D6ZD0Wi.d.ts} +59 -1
  33. package/dist/use-cache.cjs +5 -1
  34. package/dist/use-cache.d.cts +2 -2
  35. package/dist/use-cache.d.ts +2 -2
  36. package/dist/use-cache.js +2 -2
  37. package/package.json +4 -3
@@ -0,0 +1,1048 @@
1
+ "use strict";
2
+ "use client";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/react/comments.tsx
22
+ var comments_exports = {};
23
+ __export(comments_exports, {
24
+ Comments: () => Comments
25
+ });
26
+ module.exports = __toCommonJS(comments_exports);
27
+ var import_react3 = require("react");
28
+
29
+ // src/react/comments-api.ts
30
+ var CSRF_HEADER = "x-hyle-engage";
31
+ var TIMEOUT_MS = 15e3;
32
+ async function call(endpoint, method, path, body) {
33
+ try {
34
+ const res = await fetch(`${endpoint}${path}`, {
35
+ method,
36
+ credentials: "same-origin",
37
+ cache: "no-store",
38
+ headers: { accept: "application/json", [CSRF_HEADER]: "1", ...body ? { "content-type": "application/json" } : {} },
39
+ ...body ? { body: JSON.stringify(body) } : {},
40
+ signal: AbortSignal.timeout(TIMEOUT_MS)
41
+ });
42
+ let data;
43
+ try {
44
+ data = (await res.json()).data;
45
+ } catch {
46
+ }
47
+ const retry = Number(res.headers.get("retry-after"));
48
+ return { status: res.status, data, retryAfter: Number.isFinite(retry) && retry > 0 ? retry : void 0 };
49
+ } catch {
50
+ return { status: 0, data: void 0, retryAfter: void 0 };
51
+ }
52
+ }
53
+ var isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
54
+ var count = (v) => typeof v === "number" && Number.isFinite(v) && v >= 0 ? Math.trunc(v) : 0;
55
+ function toComment(raw) {
56
+ if (!isObject(raw) || typeof raw.id !== "string" || typeof raw.created_at !== "string") return void 0;
57
+ const depth = typeof raw.depth === "number" ? Math.min(4, Math.max(1, Math.trunc(raw.depth))) : 1;
58
+ const author = isObject(raw.author) && typeof raw.author.name === "string" ? raw.author.name : void 0;
59
+ const name = typeof raw.author_name === "string" ? raw.author_name : author;
60
+ const body = isObject(raw.body) && raw.body.format === "hast" ? { format: "hast", tree: raw.body.tree } : null;
61
+ const removed = raw.removed === true || body === null;
62
+ return {
63
+ id: raw.id,
64
+ parent_id: typeof raw.parent_id === "string" ? raw.parent_id : null,
65
+ depth,
66
+ author_name: name ?? null,
67
+ created_at: raw.created_at,
68
+ edited_at: typeof raw.edited_at === "string" ? raw.edited_at : null,
69
+ like_count: count(raw.like_count),
70
+ removed,
71
+ ...removed && (raw.removed_by === "moderator" || raw.removed_by === "author") ? { removed_by: raw.removed_by } : {},
72
+ body,
73
+ // 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 } : {}
75
+ };
76
+ }
77
+ function toHeld(raw) {
78
+ if (!isObject(raw) || typeof raw.id !== "string" || typeof raw.created_at !== "string" || !isObject(raw.body) || raw.body.format !== "hast") return void 0;
79
+ const author = isObject(raw.author) && typeof raw.author.name === "string" ? raw.author.name : null;
80
+ return {
81
+ id: raw.id,
82
+ parent_id: typeof raw.parent_id === "string" ? raw.parent_id : null,
83
+ depth: typeof raw.depth === "number" ? Math.min(4, Math.max(1, Math.trunc(raw.depth))) : 1,
84
+ author_name: author,
85
+ created_at: raw.created_at,
86
+ edited_at: typeof raw.edited_at === "string" ? raw.edited_at : null,
87
+ can_edit_until: typeof raw.can_edit_until === "string" ? raw.can_edit_until : null,
88
+ body: { format: "hast", tree: raw.body.tree }
89
+ };
90
+ }
91
+ function parseListing(data) {
92
+ if (!isObject(data) || data.kind !== "comments" || !Array.isArray(data.comments)) return void 0;
93
+ 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 };
96
+ }
97
+ var untilMs = (iso) => {
98
+ const t = iso ? Date.parse(iso) : NaN;
99
+ return Number.isFinite(t) ? t : void 0;
100
+ };
101
+ function buildThread(listing, localHeld) {
102
+ const byId = /* @__PURE__ */ new Map();
103
+ const roots = [];
104
+ const place = (node, parentId) => {
105
+ const parent = parentId ? byId.get(parentId) : void 0;
106
+ (parent ? parent.kids : roots).push(node);
107
+ };
108
+ for (const c of listing.comments) {
109
+ if (byId.has(c.id)) continue;
110
+ const removed = c.removed;
111
+ const node = {
112
+ id: c.id,
113
+ depth: c.depth,
114
+ status: removed ? "removed" : "visible",
115
+ removedBy: removed ? c.removed_by : void 0,
116
+ mine: !removed && c.mine === true,
117
+ canEditUntil: untilMs(c.can_edit_until),
118
+ likedByMe: !removed && c.liked_by_me === true,
119
+ name: removed ? null : c.author_name ?? null,
120
+ createdAt: c.created_at,
121
+ editedAt: c.edited_at,
122
+ likes: c.like_count,
123
+ tree: c.body?.tree,
124
+ text: void 0,
125
+ kids: []
126
+ };
127
+ place(node, c.parent_id === c.id ? null : c.parent_id);
128
+ byId.set(c.id, node);
129
+ }
130
+ const mine = [];
131
+ const addHeld = (node, parentId, oldestFirst) => {
132
+ const parent = parentId ? byId.get(parentId) : void 0;
133
+ if (parent) parent.kids.push(node);
134
+ else if (oldestFirst) mine.unshift(node);
135
+ else mine.push(node);
136
+ };
137
+ const heldIds = /* @__PURE__ */ new Set();
138
+ for (const h of listing.mine_held ?? []) {
139
+ heldIds.add(h.id);
140
+ 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);
142
+ }
143
+ if (listing.mine_held === void 0) {
144
+ for (const h of localHeld) {
145
+ if (byId.has(h.id) || heldIds.has(h.id)) continue;
146
+ 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);
148
+ }
149
+ }
150
+ return [...mine, ...roots];
151
+ }
152
+
153
+ // src/react/comments-parts.tsx
154
+ var import_react2 = require("react");
155
+
156
+ // src/react/comments-body.tsx
157
+ var import_hast_util_to_jsx_runtime = require("hast-util-to-jsx-runtime");
158
+ var import_react = require("react");
159
+ var import_jsx_runtime = require("react/jsx-runtime");
160
+
161
+ // src/asset-path.ts
162
+ var ASSET_ROUTE_PREFIX = "/api/hyle/assets";
163
+ var UUID = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
164
+ var EXTENSIONS = "png|jpg|gif|webp|svg|pdf|mp4|webm|mp3|ogg";
165
+ var ASSET_FILE = new RegExp(`^${UUID}(?:\\.(?:${EXTENSIONS}))?$`);
166
+ var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)$`, "i");
167
+ function hostAssetSrc(src) {
168
+ const file = HYLE_ASSET_URL.exec(src)?.[1];
169
+ return file ? `${ASSET_ROUTE_PREFIX}/${file.toLowerCase()}` : src;
170
+ }
171
+
172
+ // src/react/sanitize.ts
173
+ var HastLimitError = class extends Error {
174
+ constructor(message) {
175
+ super(message);
176
+ this.name = "HastLimitError";
177
+ }
178
+ };
179
+ var MAX_NODES = 2e4;
180
+ var MAX_TEXT = 512 * 1024;
181
+ var MAX_DEPTH = 128;
182
+ var MAX_SRCDOC = 64 * 1024;
183
+ var DROP = /* @__PURE__ */ new Set(["script", "style", "template", "noscript"]);
184
+ var VOID = /* @__PURE__ */ new Set(["br", "hr", "img", "input", "path"]);
185
+ var isString = (v) => typeof v === "string";
186
+ var isScalar = (v) => typeof v === "string" || typeof v === "number" || typeof v === "boolean";
187
+ var matches = (re) => (v) => typeof v === "string" && re.test(v);
188
+ var ID_PREFIX = "user-content-";
189
+ 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);
192
+ var CLASS_TOKEN = /^[A-Za-z_][\w:-]*$/;
193
+ var classTokens = (v) => {
194
+ const tokens = Array.isArray(v) ? v : typeof v === "string" ? v.split(/\s+/) : [];
195
+ return tokens.length > 0 && tokens.every((t) => typeof t === "string" && CLASS_TOKEN.test(t)) ? tokens : void 0;
196
+ };
197
+ var isClass = (v) => classTokens(v) !== void 0;
198
+ var isAlign = matches(/^(left|right|center)$/);
199
+ var isLength = matches(/^[\d.]+(em|px|%)?$/);
200
+ var STYLE_PROPS = /* @__PURE__ */ new Set(["height", "vertical-align", "margin-left", "margin-right", "margin-top", "margin-bottom", "top", "width", "min-width", "border-bottom-width", "padding-left"]);
201
+ var STYLE_LENGTH = /^(-?\d+(?:\.\d+)?)(em|px|%)?$/;
202
+ var MAX_STYLE_MAGNITUDE = 100;
203
+ function isKatexStyle(v, ctx) {
204
+ if (typeof v !== "string" || !ctx.katex) return false;
205
+ return v.split(";").filter((d) => d !== "").every((decl) => {
206
+ const [prop, value, ...extra] = decl.split(":");
207
+ if (extra.length > 0 || prop === void 0 || value === void 0) return false;
208
+ if (prop === "position") return value === "relative";
209
+ const m = STYLE_LENGTH.exec(value);
210
+ return STYLE_PROPS.has(prop) && m !== null && Math.abs(Number(m[1])) <= MAX_STYLE_MAGNITUDE;
211
+ });
212
+ }
213
+ function isSafeUrl(value, kind) {
214
+ if (typeof value !== "string") return false;
215
+ const url = value.trim();
216
+ if (url.length === 0 || /[\u0000-\u001f\u007f\\]/.test(url)) return false;
217
+ if (url.startsWith("#")) return kind === "href";
218
+ if (url.startsWith("/")) return !url.startsWith("//");
219
+ try {
220
+ const { protocol } = new URL(url);
221
+ return protocol === "https:" || protocol === "http:" || kind === "href" && protocol === "mailto:";
222
+ } catch {
223
+ return false;
224
+ }
225
+ }
226
+ var isHref = (v) => isSafeUrl(v, "href") && (typeof v !== "string" || !v.trim().startsWith("#") || isIdValue(v.trim().slice(1)));
227
+ var isSrc = (v) => isSafeUrl(v, "src");
228
+ var MERMAID_SCRIPT_URL = "https://cdnjs.cloudflare.com/ajax/libs/mermaid/11.9.0/mermaid.min.js";
229
+ var MERMAID_SRCDOC = new RegExp(
230
+ `^<!doctype html><html><head><meta charset="utf-8"></head><body><div class="mermaid">([^<]*)</div><script src="${MERMAID_SCRIPT_URL.replace(/[.]/g, "\\.")}"></script><script>mermaid\\.initialize\\(\\{ startOnLoad: true, securityLevel: "strict" \\}\\);</script></body></html>$`
231
+ );
232
+ var isMermaidSrcdoc = (v) => typeof v === "string" && v.length <= MAX_SRCDOC && MERMAID_SRCDOC.test(v);
233
+ var MERMAID_FRAME_CSP = `default-src 'none'; script-src ${MERMAID_SCRIPT_URL} 'unsafe-inline'; style-src 'unsafe-inline'; img-src data:`;
234
+ var heading = { id: isIdValue, className: isClass };
235
+ var ATTRS = new Map(
236
+ Object.entries({
237
+ p: {},
238
+ em: {},
239
+ strong: {},
240
+ del: {},
241
+ hr: {},
242
+ br: {},
243
+ sup: {},
244
+ blockquote: {},
245
+ thead: {},
246
+ tbody: {},
247
+ tr: {},
248
+ ol: {},
249
+ ul: { className: isClass },
250
+ li: { id: isIdValue, className: isClass },
251
+ h1: heading,
252
+ h2: heading,
253
+ h3: heading,
254
+ h4: heading,
255
+ h5: heading,
256
+ h6: heading,
257
+ a: { href: isHref, id: isIdValue, ariaDescribedBy: isIdValue, ariaLabel: isString, dataFootnoteRef: isScalar, dataFootnoteBackref: isScalar, className: isClass },
258
+ img: { src: isSrc, alt: isString },
259
+ table: {},
260
+ th: { scope: matches(/^(row|col|rowgroup|colgroup)$/), align: isAlign },
261
+ td: { align: isAlign },
262
+ pre: { className: isClass },
263
+ code: { className: isClass },
264
+ section: { dataFootnotes: isScalar, className: isClass },
265
+ input: { type: matches(/^checkbox$/), disabled: isScalar, checked: isScalar },
266
+ span: { className: isClass, style: isKatexStyle, ariaHidden: matches(/^(true|false)$/) },
267
+ svg: { xmlns: matches(/^http:\/\/www\.w3\.org\/2000\/svg$/), width: isLength, height: isLength, viewBox: matches(/^-?[\d.]+ -?[\d.]+ -?[\d.]+ -?[\d.]+$/), preserveAspectRatio: matches(/^[\w ]+$/) },
268
+ path: { d: matches(/^[MLCSQTAHVZmlcsqtahvz0-9.,\-\s]+$/) },
269
+ video: { src: isSrc, controls: isScalar },
270
+ audio: { src: isSrc, controls: isScalar },
271
+ // hyle's sandboxed Mermaid frame (ADR 0001). The renderer emits `sandbox` as ["allow-scripts"]; it is normalized below.
272
+ iframe: { sandbox: (v) => v === "allow-scripts" || Array.isArray(v) && v.length === 1 && v[0] === "allow-scripts", srcdoc: isMermaidSrcdoc }
273
+ })
274
+ );
275
+ var isObject2 = (v) => typeof v === "object" && v !== null;
276
+ function textOf(node, depth = 0) {
277
+ if (!isObject2(node) || depth > MAX_DEPTH) return "";
278
+ if (node.type === "text") return typeof node.value === "string" ? node.value : "";
279
+ return Array.isArray(node.children) ? node.children.map((c) => textOf(c, depth + 1)).join("") : "";
280
+ }
281
+ var CALLOUT_MARKER = /^\s*\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*/i;
282
+ var CALLOUT_KIND = { note: "note", tip: "tip", important: "warning", warning: "warning", caution: "caution" };
283
+ function toCallout(children) {
284
+ const first = children.find((c) => c.type === "element");
285
+ const lead = first?.tagName === "p" ? first.children[0] : void 0;
286
+ const marker = lead?.type === "text" ? CALLOUT_MARKER.exec(lead.value) : null;
287
+ if (!first || lead?.type !== "text" || !marker) return void 0;
288
+ const rest = lead.value.slice(marker[0].length);
289
+ const firstChildren = rest ? [{ type: "text", value: rest }, ...first.children.slice(1)] : first.children.slice(1);
290
+ const body = firstChildren.length > 0 ? [{ ...first, children: firstChildren }] : [];
291
+ const kind = CALLOUT_KIND[(marker[1] ?? "note").toLowerCase()] ?? "note";
292
+ return { type: "element", tagName: "callout", properties: { kind }, children: [...body, ...children.slice(children.indexOf(first) + 1)] };
293
+ }
294
+ function clean(node, depth, ctx, budget) {
295
+ if (!isObject2(node) || depth > MAX_DEPTH) return [];
296
+ if (++budget.nodes > MAX_NODES) throw new HastLimitError("content has too many nodes");
297
+ if (node.type === "text") {
298
+ if (typeof node.value !== "string") return [];
299
+ budget.text += node.value.length;
300
+ if (budget.text > MAX_TEXT) throw new HastLimitError("content is too large");
301
+ return [{ type: "text", value: node.value }];
302
+ }
303
+ if (node.type !== "element" || typeof node.tagName !== "string" || DROP.has(node.tagName)) return [];
304
+ const tag = node.tagName;
305
+ const rules = ATTRS.get(tag);
306
+ const own = isObject2(node.properties) ? classTokens(node.properties.className) : void 0;
307
+ const inner = tag === "span" && own?.some((t) => t === "katex" || t.startsWith("katex-")) ? { katex: true } : ctx;
308
+ const children = Array.isArray(node.children) ? node.children.flatMap((c) => clean(c, depth + 1, inner, budget)) : [];
309
+ if (!rules) return children;
310
+ const properties = {};
311
+ if (isObject2(node.properties)) {
312
+ for (const [key, value] of Object.entries(node.properties)) {
313
+ if (Object.hasOwn(rules, key) && rules[key](value, inner)) properties[key] = value;
314
+ }
315
+ }
316
+ if ((tag === "img" || tag === "video" || tag === "audio") && typeof properties.src === "string") properties.src = hostAssetSrc(properties.src);
317
+ if (tag === "iframe") {
318
+ if (properties.sandbox === void 0 || properties.srcdoc === void 0) return [];
319
+ properties.sandbox = "allow-scripts";
320
+ }
321
+ if (tag === "input") {
322
+ if (properties.type !== "checkbox") return [];
323
+ properties.disabled = true;
324
+ }
325
+ for (const key of ["id", "ariaDescribedBy"]) if (typeof properties[key] === "string") properties[key] = scopeId(properties[key]);
326
+ if (tag === "a" && typeof properties.href === "string" && properties.href.trim().startsWith("#")) properties.href = `#${scopeId(properties.href.trim().slice(1))}`;
327
+ if (tag === "blockquote") {
328
+ const callout = toCallout(children);
329
+ if (callout) return [callout];
330
+ }
331
+ const tagName = tag === "h1" ? "h2" : tag;
332
+ return [{ type: "element", tagName, properties, children: VOID.has(tag) ? [] : children }];
333
+ }
334
+ function sanitizeHast(tree, title, description) {
335
+ const raw = isObject2(tree) && tree.type === "root" && Array.isArray(tree.children) ? tree.children : [];
336
+ const elements = raw.filter((n) => isObject2(n) && n.type === "element");
337
+ const [first] = elements;
338
+ const skip = title !== void 0 && isObject2(first) && first.tagName === "h1" && textOf(first).trim() === title.trim() ? first : void 0;
339
+ const lead = elements[skip ? 1 : 0];
340
+ const repeat = description && isObject2(lead) && lead.tagName === "p" && textOf(lead).trim().startsWith(description.trim()) ? lead : void 0;
341
+ const budget = { nodes: 0, text: 0 };
342
+ return { type: "root", children: raw.filter((n) => n !== skip && n !== repeat).flatMap((n) => clean(n, 0, { katex: false }, budget)) };
343
+ }
344
+
345
+ // src/react/comments-body.tsx
346
+ var import_jsx_runtime2 = require("react/jsx-runtime");
347
+ var ALLOWED = /* @__PURE__ */ new Set(["p", "a", "em", "strong", "del", "code", "pre", "blockquote", "ul", "ol", "li", "br"]);
348
+ var LINK_REL = "nofollow ugc noopener noreferrer";
349
+ function narrow(node) {
350
+ if (node.type === "text") return [node];
351
+ if (node.type !== "element") return [];
352
+ const children = node.children.flatMap(narrow);
353
+ if (!ALLOWED.has(node.tagName)) return children;
354
+ if (node.tagName === "a") {
355
+ const href = node.properties.href;
356
+ if (!isSafeUrl(href, "href")) return children;
357
+ return [{ type: "element", tagName: "a", properties: { href: String(href), rel: LINK_REL.split(" ") }, children }];
358
+ }
359
+ return [{ type: "element", tagName: node.tagName, properties: {}, children: node.tagName === "br" ? [] : children }];
360
+ }
361
+ function CommentBody({ tree }) {
362
+ let children;
363
+ try {
364
+ children = sanitizeHast(tree).children.flatMap((n) => narrow(n));
365
+ } catch (error) {
366
+ if (error instanceof HastLimitError) return null;
367
+ throw error;
368
+ }
369
+ 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" }) });
370
+ }
371
+
372
+ // src/react/comments-markdown.ts
373
+ function inline(nodes) {
374
+ return nodes.map((node) => {
375
+ if (node.type === "text") return node.value;
376
+ if (node.type !== "element") return "";
377
+ const inner = inline(node.children);
378
+ switch (node.tagName) {
379
+ case "strong":
380
+ return `**${inner}**`;
381
+ case "em":
382
+ return `*${inner}*`;
383
+ case "del":
384
+ return `~~${inner}~~`;
385
+ case "code":
386
+ return `\`${inner}\``;
387
+ case "br":
388
+ return "\n";
389
+ case "a":
390
+ return typeof node.properties.href === "string" ? `[${inner}](${node.properties.href})` : inner;
391
+ default:
392
+ return inner;
393
+ }
394
+ }).join("");
395
+ }
396
+ function block(node, indent = "") {
397
+ if (node.type === "text") return node.value.trim() ? node.value.trim() : "";
398
+ if (node.type !== "element") return "";
399
+ const el = node;
400
+ switch (el.tagName) {
401
+ case "blockquote":
402
+ return el.children.map((c) => block(c)).filter(Boolean).join("\n\n").split("\n").map((l) => `> ${l}`.trimEnd()).join("\n");
403
+ case "pre":
404
+ return `\`\`\`
405
+ ${inline(el.children).replace(/\n$/, "")}
406
+ \`\`\``;
407
+ case "ul":
408
+ case "ol": {
409
+ let n = 0;
410
+ return el.children.filter((c) => c.type === "element" && c.tagName === "li").map((li) => `${indent}${el.tagName === "ol" ? `${++n}.` : "-"} ${li.children.map((c) => c.type === "element" && (c.tagName === "ul" || c.tagName === "ol") ? `
411
+ ${block(c, `${indent} `)}` : inline([c])).join("").trim()}`).join("\n");
412
+ }
413
+ default:
414
+ return inline(el.children).trim();
415
+ }
416
+ }
417
+ function hastToMarkdown(tree) {
418
+ try {
419
+ return sanitizeHast(tree).children.map((n) => block(n)).filter(Boolean).join("\n\n");
420
+ } catch {
421
+ return "";
422
+ }
423
+ }
424
+
425
+ // src/react/icons.tsx
426
+ var import_jsx_runtime3 = require("react/jsx-runtime");
427
+ var SHAPES = {
428
+ info: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
429
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("circle", { cx: "8", cy: "8", r: "6" }),
430
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M8 7.3V11M8 5v.1" })
431
+ ] }),
432
+ "check-circle": /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
433
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("circle", { cx: "8", cy: "8", r: "6" }),
434
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "m5.3 8.3 1.9 1.9 3.5-3.9" })
435
+ ] }),
436
+ alert: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M8 2 1.8 13h12.4zM8 6.5v3M8 11.3v.1" }),
437
+ "x-circle": /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
438
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("circle", { cx: "8", cy: "8", r: "6" }),
439
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "m5.8 5.8 4.4 4.4M10.2 5.8l-4.4 4.4" })
440
+ ] }),
441
+ calendar: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
442
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("rect", { x: "2", y: "3", width: "12", height: "11", rx: "1.3" }),
443
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M2 6.5h12M5.5 1.7v2.6M10.5 1.7v2.6" })
444
+ ] }),
445
+ globe: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
446
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("circle", { cx: "8", cy: "8", r: "6" }),
447
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M2 8h12M8 2c2 1.7 2.8 3.7 2.8 6S10 12.3 8 14M8 2C6 3.7 5.2 5.7 5.2 8S6 12.3 8 14" })
448
+ ] }),
449
+ file: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
450
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M4 1.8h5l3 3v8.4a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V2.8a1 1 0 0 1 1-1z" }),
451
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M9 1.8v3h3" })
452
+ ] }),
453
+ chev: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "m6 3.5 4.5 4.5L6 12.5" }),
454
+ "chev-down": /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "m3.5 6 4.5 4.5L12.5 6" }),
455
+ "chev-left": /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M10 3.5 5.5 8 10 12.5" }),
456
+ x: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "m4 4 8 8M12 4l-8 8" }),
457
+ 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" }),
458
+ 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" }),
459
+ clock: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
460
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("circle", { cx: "8", cy: "8", r: "6" }),
461
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M8 4.5V8l2.3 1.5" })
462
+ ] }),
463
+ ban: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
464
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("circle", { cx: "8", cy: "8", r: "6" }),
465
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "m3.8 12.2 8.4-8.4" })
466
+ ] }),
467
+ refresh: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M13 8a5 5 0 1 1-1.6-3.7M13 2.5v2.8h-2.8" })
468
+ };
469
+ function Icon({ name, className }) {
470
+ 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] });
471
+ }
472
+
473
+ // src/react/comments-parts.tsx
474
+ var import_jsx_runtime4 = require("react/jsx-runtime");
475
+ var MAX_CHARS = 4e3;
476
+ var EDIT_WINDOW_MS = 10 * 60 * 1e3;
477
+ var MAX_DEPTH2 = 4;
478
+ var fill = (template, values) => template.replace(/\{(\w+)\}/g, (_, k) => String(values[k] ?? ""));
479
+ var initials = (name) => name.trim().split(/\s+/).slice(0, 2).map((w) => [...w][0] ?? "").join("").toUpperCase() || "?";
480
+ var replyButtonId = (ui, id) => `${ui.idp}-reply-${id}`;
481
+ var nameId = (ui, id) => `${ui.idp}-${id}-n`;
482
+ function relative(iso, now, locale, s) {
483
+ const seconds = Math.round((now - Date.parse(iso)) / 1e3);
484
+ if (!Number.isFinite(seconds)) return iso;
485
+ if (seconds < 45) return s.justNow;
486
+ try {
487
+ const rtf = new Intl.RelativeTimeFormat(locale, { numeric: "auto", style: "short" });
488
+ if (seconds < 3600) return rtf.format(-Math.round(seconds / 60), "minute");
489
+ if (seconds < 86400) return rtf.format(-Math.round(seconds / 3600), "hour");
490
+ if (seconds < 30 * 86400) return rtf.format(-Math.round(seconds / 86400), "day");
491
+ return new Intl.DateTimeFormat(locale, { dateStyle: "medium" }).format(new Date(iso));
492
+ } catch {
493
+ return iso.slice(0, 10);
494
+ }
495
+ }
496
+ var absolute = (iso, locale) => {
497
+ try {
498
+ return new Intl.DateTimeFormat(locale, { dateStyle: "medium", timeStyle: "short" }).format(new Date(iso));
499
+ } catch {
500
+ return iso;
501
+ }
502
+ };
503
+ function Avatar({ name }) {
504
+ 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" }) });
505
+ }
506
+ function SignInLink({ ui, className, children }) {
507
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("a", { className, href: `#${ui.signInId}`, children });
508
+ }
509
+ function LikeButton({ ui, itemKey, serverCount, serverOn, scope }) {
510
+ const { s } = ui;
511
+ const state = ui.likes[itemKey];
512
+ const count2 = state?.count ?? serverCount;
513
+ const on = state?.on ?? serverOn;
514
+ const cls = scope === "article" ? "hyle-btn" : "hyle-cm-btn cnt";
515
+ const lead = scope === "article" ? on ? s.likedArticle : s.likeArticle : null;
516
+ const sr = scope === "article" ? ", " : s.likeComment;
517
+ const icon = /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "heart" });
518
+ if (ui.ready && !ui.me) {
519
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(SignInLink, { ui, className: cls, children: [
520
+ icon,
521
+ lead ?? null,
522
+ scope === "article" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
523
+ " ",
524
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "hyle-sr", children: s.likeArticleSignIn })
525
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "hyle-sr", children: s.likeCommentSignIn }),
526
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: count2 })
527
+ ] });
528
+ }
529
+ if (ui.banned || !ui.ready) {
530
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("button", { className: cls, type: "button", "aria-disabled": "true", children: [
531
+ icon,
532
+ lead,
533
+ scope === "article" ? " " : null,
534
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "hyle-sr", children: sr }),
535
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: count2 })
536
+ ] });
537
+ }
538
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("button", { className: cls, type: "button", "aria-pressed": on, onClick: () => ui.actions.like(itemKey, serverCount, serverOn), children: [
539
+ icon,
540
+ lead,
541
+ scope === "article" ? " " : null,
542
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "hyle-sr", children: sr }),
543
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: count2 })
544
+ ] });
545
+ }
546
+ function Composer({ ui, id, parentId, name, autoFocus, onCancel }) {
547
+ const { s } = ui;
548
+ const [text, setText] = (0, import_react2.useState)("");
549
+ const [busy, setBusy] = (0, import_react2.useState)(false);
550
+ const [error, setError] = (0, import_react2.useState)(null);
551
+ const area = (0, import_react2.useRef)(null);
552
+ const limited = ui.rateLeft > 0;
553
+ (0, import_react2.useEffect)(() => {
554
+ if (autoFocus) area.current?.focus();
555
+ }, [autoFocus]);
556
+ async function submit() {
557
+ if (busy || limited) return;
558
+ const length = [...text].length;
559
+ if (text.trim() === "" || length > MAX_CHARS) {
560
+ setError(s.tooLong);
561
+ area.current?.focus();
562
+ return;
563
+ }
564
+ setBusy(true);
565
+ setError(null);
566
+ const result = await ui.actions.post(text, parentId);
567
+ setBusy(false);
568
+ if (result.ok) {
569
+ setText("");
570
+ onCancel?.();
571
+ return;
572
+ }
573
+ if (result.reason !== "rate") setError(result.reason === "tooLong" ? s.tooLong : result.reason === "expired" ? s.expired : s.postError);
574
+ area.current?.focus();
575
+ }
576
+ const onKey = (e) => {
577
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
578
+ e.preventDefault();
579
+ void submit();
580
+ } else if (e.key === "Escape" && onCancel) {
581
+ e.preventDefault();
582
+ onCancel();
583
+ }
584
+ };
585
+ const helpId = `${id}-help`;
586
+ const errId = `${id}-err`;
587
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("form", { className: "hyle-cm-compose", onSubmit: (e) => {
588
+ e.preventDefault();
589
+ void submit();
590
+ }, children: [
591
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Avatar, { name }),
592
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { children: [
593
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("p", { className: "hyle-cm-as", children: [
594
+ s.commentingAs.split("{name}")[0],
595
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("b", { children: name }),
596
+ s.commentingAs.split("{name}")[1]
597
+ ] }),
598
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("label", { className: "hyle-sr", htmlFor: id, children: parentId ? s.replyPlaceholder : s.write }),
599
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
600
+ "textarea",
601
+ {
602
+ ref: area,
603
+ className: "hyle-cm-input",
604
+ id,
605
+ rows: 3,
606
+ maxLength: MAX_CHARS,
607
+ placeholder: parentId ? s.replyPlaceholder : s.placeholder,
608
+ value: text,
609
+ disabled: limited,
610
+ "aria-invalid": error ? true : void 0,
611
+ "aria-describedby": error ? errId : helpId,
612
+ onChange: (e) => setText(e.target.value),
613
+ onKeyDown: onKey
614
+ }
615
+ ),
616
+ error ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("p", { className: "hyle-cm-err", id: errId, role: "alert", children: [
617
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "alert" }),
618
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: error })
619
+ ] }) : null,
620
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "hyle-cm-foot", children: [
621
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "grow", id: helpId, children: limited ? fill(s.rateWait, { n: ui.rateLeft }) : s.help }),
622
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "cnt", children: fill(s.chars, { n: [...text].length, max: MAX_CHARS }) }),
623
+ onCancel ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { className: "hyle-btn sm", type: "button", onClick: onCancel, children: s.cancel }) : null,
624
+ /* @__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 })
625
+ ] })
626
+ ] })
627
+ ] });
628
+ }
629
+ function EditForm({ ui, node, initial }) {
630
+ const { s } = ui;
631
+ const [text, setText] = (0, import_react2.useState)(initial);
632
+ const [busy, setBusy] = (0, import_react2.useState)(false);
633
+ const [error, setError] = (0, import_react2.useState)(null);
634
+ const area = (0, import_react2.useRef)(null);
635
+ (0, import_react2.useEffect)(() => area.current?.focus(), []);
636
+ const id = `${ui.idp}-edit-${node.id}`;
637
+ async function save() {
638
+ if (busy) return;
639
+ setBusy(true);
640
+ setError(null);
641
+ const r = await ui.actions.save(node.id, text);
642
+ setBusy(false);
643
+ if (r.ok) return;
644
+ setError(r.reason === "tooLong" ? s.tooLong : r.reason === "closed" ? s.editClosed : r.reason === "expired" ? s.expired : r.reason === "rate" ? s.rateTitle : s.postError);
645
+ area.current?.focus();
646
+ }
647
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("form", { onSubmit: (e) => {
648
+ e.preventDefault();
649
+ void save();
650
+ }, children: [
651
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("label", { className: "hyle-sr", htmlFor: id, children: s.edit }),
652
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
653
+ "textarea",
654
+ {
655
+ ref: area,
656
+ className: "hyle-cm-input",
657
+ id,
658
+ rows: 3,
659
+ maxLength: MAX_CHARS,
660
+ value: text,
661
+ "aria-invalid": error ? true : void 0,
662
+ "aria-describedby": error ? `${id}-err` : void 0,
663
+ onChange: (e) => setText(e.target.value),
664
+ onKeyDown: (e) => {
665
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
666
+ e.preventDefault();
667
+ void save();
668
+ } else if (e.key === "Escape") {
669
+ e.preventDefault();
670
+ ui.actions.edit(null);
671
+ }
672
+ }
673
+ }
674
+ ),
675
+ error ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("p", { className: "hyle-cm-err", id: `${id}-err`, role: "alert", children: [
676
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "alert" }),
677
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: error })
678
+ ] }) : null,
679
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "hyle-cm-foot", children: [
680
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "grow" }),
681
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { className: "hyle-btn sm", type: "button", onClick: () => ui.actions.edit(null), children: s.cancel }),
682
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { className: "hyle-btn sm primary", type: "submit", "aria-disabled": busy ? true : void 0, children: s.save })
683
+ ] })
684
+ ] });
685
+ }
686
+ function Actions({ ui, node }) {
687
+ const { s } = ui;
688
+ const local = ui.own[node.id];
689
+ const mine = node.mine || !!local;
690
+ const until = node.canEditUntil ?? (local ? local.at + EDIT_WINDOW_MS : void 0);
691
+ const minutes = until === void 0 ? 0 : Math.min(10, Math.ceil((until - Math.max(ui.now, local?.at ?? 0)) / 6e4));
692
+ const canReply = node.depth < MAX_DEPTH2 && node.status === "visible";
693
+ if (ui.confirming === node.id) {
694
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "hyle-cm-acts", role: "group", "aria-label": s.deleteConfirm, children: [
695
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "hyle-cm-depth", children: s.deleteConfirm }),
696
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { className: "hyle-cm-btn danger", type: "button", onClick: () => ui.actions.remove(node.id), children: s.delete }),
697
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { className: "hyle-cm-btn", type: "button", autoFocus: true, onClick: () => ui.actions.confirm(null), children: s.keep })
698
+ ] });
699
+ }
700
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "hyle-cm-acts", children: [
701
+ node.status === "visible" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(LikeButton, { ui, itemKey: node.id, serverCount: node.likes, serverOn: node.likedByMe, scope: "comment" }) : null,
702
+ 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: [
703
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "reply" }),
704
+ s.reply
705
+ ] }) : null,
706
+ canReply && !ui.me ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(SignInLink, { ui, className: "hyle-cm-btn", children: [
707
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "reply" }),
708
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "hyle-sr", children: fill(s.replyTo, { name: node.name ?? "" }) }),
709
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "aria-hidden": "true", children: s.reply })
710
+ ] }) : null,
711
+ node.status === "visible" && node.depth >= MAX_DEPTH2 ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "hyle-cm-depth", children: s.depthEnd }) : null,
712
+ 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: [
713
+ s.edit,
714
+ " ",
715
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("small", { children: fill(s.editLeft, { n: minutes }) })
716
+ ] }) : null,
717
+ 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
718
+ ] });
719
+ }
720
+ function Thread({ ui, nodes }) {
721
+ 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)) });
722
+ }
723
+ function CommentItem({ ui, node }) {
724
+ const { s } = ui;
725
+ const li = `${ui.idp}-c-${node.id}`;
726
+ const kids = node.kids.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Thread, { ui, nodes: node.kids }) : null;
727
+ if (node.status === "removed") {
728
+ const why = node.removedBy === "moderator" ? s.removedByModerator : node.removedBy === "author" ? s.removedByAuthor : s.removed;
729
+ 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: [
730
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("article", { "aria-label": why, children: [
731
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Avatar, { name: null }),
732
+ /* @__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 }) }) })
733
+ ] }),
734
+ kids
735
+ ] });
736
+ }
737
+ const local = ui.own[node.id];
738
+ const mine = node.mine || !!local;
739
+ const editing = ui.editing === node.id && mine;
740
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("li", { className: "hyle-cm", id: li, "data-depth": node.depth, "data-status": node.status, children: [
741
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("article", { "aria-labelledby": nameId(ui, node.id), children: [
742
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Avatar, { name: node.name }),
743
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "hyle-cm-main", children: [
744
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "hyle-cm-by", children: [
745
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("b", { id: nameId(ui, node.id), tabIndex: -1, children: node.name }),
746
+ mine ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "hyle-cm-tag", children: s.you }) : null,
747
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { children: [
748
+ /* @__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) }),
749
+ node.editedAt ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
750
+ " ",
751
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "aria-hidden": "true", children: "\xB7" }),
752
+ " ",
753
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("a", { href: `#${li}`, title: absolute(node.editedAt, ui.locale), children: s.edited })
754
+ ] }) : null
755
+ ] })
756
+ ] }),
757
+ 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 }),
758
+ node.status === "held" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("p", { className: "hyle-cm-held", role: "status", children: [
759
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "clock" }),
760
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { children: [
761
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("b", { children: s.held }),
762
+ " ",
763
+ s.heldNote
764
+ ] })
765
+ ] }) : null,
766
+ editing ? null : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Actions, { ui, node }),
767
+ 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
768
+ ] })
769
+ ] }),
770
+ kids
771
+ ] });
772
+ }
773
+
774
+ // src/react/comments.tsx
775
+ var import_jsx_runtime5 = require("react/jsx-runtime");
776
+ var PAGE = 20;
777
+ var TICK_MS = 1e4;
778
+ var isObject3 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
779
+ var fill2 = (t, n) => t.replace("{n}", String(n));
780
+ function Comments({ path, endpoint, signInHref, locale, labels: s, initial, initialAt }) {
781
+ const idp = `hc${(0, import_react3.useId)().replace(/[^A-Za-z0-9]/g, "")}`;
782
+ const [session, setSession] = (0, import_react3.useState)("loading");
783
+ const [listing, setListing] = (0, import_react3.useState)(initial ?? "loading");
784
+ const [own, setOwn] = (0, import_react3.useState)({});
785
+ const [held, setHeld] = (0, import_react3.useState)([]);
786
+ const [likes, setLikes] = (0, import_react3.useState)({});
787
+ const [replyOpen, setReplyOpen] = (0, import_react3.useState)(null);
788
+ const [editing, setEditing] = (0, import_react3.useState)(null);
789
+ const [confirming, setConfirming] = (0, import_react3.useState)(null);
790
+ const [banned, setBanned] = (0, import_react3.useState)(false);
791
+ const [expired, setExpired] = (0, import_react3.useState)(false);
792
+ const [rateUntil, setRateUntil] = (0, import_react3.useState)(0);
793
+ const [now, setNow] = (0, import_react3.useState)(() => initialAt ?? Date.now());
794
+ const [live, setLive] = (0, import_react3.useState)("");
795
+ const [actionError, setActionError] = (0, import_react3.useState)(null);
796
+ const [shown, setShown] = (0, import_react3.useState)(PAGE);
797
+ const [focusId, setFocusId] = (0, import_react3.useState)(null);
798
+ const pending = (0, import_react3.useRef)(/* @__PURE__ */ new Set());
799
+ const alive = (0, import_react3.useRef)(true);
800
+ const write404 = (0, import_react3.useRef)(0);
801
+ (0, import_react3.useEffect)(() => {
802
+ alive.current = true;
803
+ return () => void (alive.current = false);
804
+ }, []);
805
+ (0, import_react3.useEffect)(() => {
806
+ if (initialAt !== void 0) setNow(Date.now());
807
+ const t = setInterval(() => setNow(Date.now()), TICK_MS);
808
+ return () => clearInterval(t);
809
+ }, [initialAt]);
810
+ (0, import_react3.useEffect)(() => {
811
+ if (rateUntil <= Date.now()) return;
812
+ const t = setTimeout(() => setNow(Date.now()), rateUntil - Date.now() + 50);
813
+ return () => clearTimeout(t);
814
+ }, [rateUntil]);
815
+ const load = (0, import_react3.useCallback)(async (silent) => {
816
+ const r = await call(endpoint, "GET", `/comments?path=${encodeURIComponent(path)}`);
817
+ if (!alive.current) return void 0;
818
+ const parsed = r.status === 200 ? parseListing(r.data) : void 0;
819
+ if (r.status === 404) setListing("off");
820
+ else if (parsed) {
821
+ setListing(parsed);
822
+ setLikes((l) => Object.fromEntries(Object.entries(l).filter(([k]) => pending.current.has(k))));
823
+ } else if (!silent) setListing("error");
824
+ return parsed;
825
+ }, [endpoint, path]);
826
+ (0, import_react3.useEffect)(() => {
827
+ setListing(initial ?? "loading");
828
+ void load(initial !== void 0);
829
+ void call(endpoint, "GET", "/session").then((r) => {
830
+ if (!alive.current) return;
831
+ const reader = isObject3(r.data) && isObject3(r.data.reader) ? r.data.reader : void 0;
832
+ setSession(r.status === 404 ? "off" : r.status === 200 && typeof reader?.name === "string" ? { name: reader.name } : null);
833
+ });
834
+ }, [endpoint, load, initial]);
835
+ (0, import_react3.useEffect)(() => {
836
+ if (!focusId) return;
837
+ const el = document.getElementById(`${idp}-${focusId}-n`);
838
+ if (el) {
839
+ el.focus();
840
+ setFocusId(null);
841
+ }
842
+ }, [focusId, listing, held, idp]);
843
+ const me = typeof session === "object" && session ? session.name : null;
844
+ const rateLeft = Math.max(0, Math.ceil((rateUntil - now) / 1e3));
845
+ const signInId = `${idp}-signin`;
846
+ function failed(status) {
847
+ if (status === 401) setExpired(true);
848
+ setActionError(status === 401 ? s.expired : s.actionError);
849
+ }
850
+ async function like(key, serverCount, serverOn) {
851
+ if (!me || banned || pending.current.has(key)) return;
852
+ const prev = likes[key] ?? { on: serverOn, count: serverCount };
853
+ const count2 = prev.count ?? serverCount;
854
+ pending.current.add(key);
855
+ setActionError(null);
856
+ setLikes((l) => ({ ...l, [key]: { on: !prev.on, count: Math.max(0, count2 + (prev.on ? -1 : 1)) } }));
857
+ const r = await call(endpoint, prev.on ? "DELETE" : "PUT", "/reactions", key === "article" ? { subject_type: "article", path } : { subject_type: "comment", comment_id: key });
858
+ pending.current.delete(key);
859
+ if (!alive.current) return;
860
+ const reaction = r.status === 200 && isObject3(r.data) && isObject3(r.data.reaction) ? r.data.reaction : void 0;
861
+ if (reaction && typeof reaction.like_count === "number") {
862
+ setLikes((l) => ({ ...l, [key]: { on: reaction.active === true, count: reaction.like_count } }));
863
+ return;
864
+ }
865
+ setLikes((l) => ({ ...l, [key]: { on: prev.on, count: count2 } }));
866
+ failed(r.status);
867
+ }
868
+ async function post(text, parentId) {
869
+ const r = await call(endpoint, "POST", "/comments", { path, body: text, ...parentId ? { parent_id: parentId } : {} });
870
+ const created = r.status === 201 && isObject3(r.data) && isObject3(r.data.comment) ? r.data.comment : void 0;
871
+ if (typeof created?.id === "string" && alive.current) {
872
+ const id = created.id;
873
+ write404.current = 0;
874
+ setOwn((o) => ({ ...o, [id]: { text, at: Date.now(), parentId } }));
875
+ setExpired(false);
876
+ if (created.status === "held") {
877
+ setHeld((h) => [{ id, parentId, text, name: me ?? "", createdAt: (/* @__PURE__ */ new Date()).toISOString() }, ...h]);
878
+ setLive(s.heldLive);
879
+ } else setLive(s.postedLive);
880
+ setShown(Number.MAX_SAFE_INTEGER);
881
+ setFocusId(id);
882
+ await load(true);
883
+ return { ok: true };
884
+ }
885
+ if (r.status === 429) {
886
+ setRateUntil(Date.now() + (r.retryAfter ?? 60) * 1e3);
887
+ setNow(Date.now());
888
+ return { ok: false, reason: "rate" };
889
+ }
890
+ if (r.status === 404) {
891
+ const [again, who] = await Promise.all([load(true), call(endpoint, "GET", "/session")]);
892
+ write404.current += 1;
893
+ const valid = who.status === 200 && isObject3(who.data) && isObject3(who.data.reader) && typeof who.data.reader.name === "string";
894
+ if (alive.current && valid && again && write404.current >= 2) setBanned(true);
895
+ return { ok: false, reason: "error" };
896
+ }
897
+ if (r.status === 401) setExpired(true);
898
+ return { ok: false, reason: r.status === 400 ? "tooLong" : r.status === 401 ? "expired" : "error" };
899
+ }
900
+ async function save(id, text) {
901
+ const r = await call(endpoint, "PATCH", `/comments/${id}`, { body: text });
902
+ if (r.status === 200 && alive.current) {
903
+ const meta = own[id];
904
+ setOwn((o) => ({ ...o, [id]: { text, at: o[id]?.at ?? Date.now(), parentId: o[id]?.parentId ?? null } }));
905
+ setHeld((h) => h.map((c) => c.id === id ? { ...c, text } : c));
906
+ setEditing(null);
907
+ setLive(s.savedLive);
908
+ setFocusId(id);
909
+ const fresh = await load(true);
910
+ 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]);
911
+ return { ok: true };
912
+ }
913
+ if (r.status === 429) {
914
+ setRateUntil(Date.now() + (r.retryAfter ?? 60) * 1e3);
915
+ setNow(Date.now());
916
+ return { ok: false, reason: "rate" };
917
+ }
918
+ if (r.status === 401) setExpired(true);
919
+ return r.status === 409 ? { ok: false, reason: "closed" } : { ok: false, reason: r.status === 400 ? "tooLong" : r.status === 401 ? "expired" : "error" };
920
+ }
921
+ async function remove(id) {
922
+ setActionError(null);
923
+ const r = await call(endpoint, "DELETE", `/comments/${id}`);
924
+ if (!alive.current) return;
925
+ setConfirming(null);
926
+ if (r.status !== 200) return failed(r.status);
927
+ setHeld((h) => h.filter((c) => c.id !== id));
928
+ setOwn(({ [id]: _gone, ...rest }) => rest);
929
+ setLive(s.deletedLive);
930
+ await load(true);
931
+ }
932
+ if (session === "off" || listing === "off") return null;
933
+ const loaded = typeof listing === "object" ? listing : void 0;
934
+ const ui = {
935
+ s,
936
+ locale,
937
+ now,
938
+ ready: session !== "loading",
939
+ me,
940
+ banned,
941
+ signInHref,
942
+ signInId,
943
+ idp,
944
+ rateLeft,
945
+ own,
946
+ likes,
947
+ replyOpen,
948
+ editing,
949
+ confirming,
950
+ actions: {
951
+ like: (k, c, on) => void like(k, c, on),
952
+ reply: (id) => {
953
+ const previous = replyOpen;
954
+ setReplyOpen(id);
955
+ if (id === null && previous) requestAnimationFrame(() => document.getElementById(replyButtonId(ui, previous))?.focus());
956
+ },
957
+ edit: setEditing,
958
+ confirm: setConfirming,
959
+ post,
960
+ save,
961
+ remove: (id) => void remove(id)
962
+ }
963
+ };
964
+ const thread = loaded ? buildThread(loaded, held) : [];
965
+ const hid = `${idp}-h`;
966
+ const canWrite = !!me && !banned;
967
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("section", { className: "hyle-comments", "aria-labelledby": hid, "data-slot-component": "Comments", children: [
968
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "hyle-cm-head", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("h2", { id: hid, children: [
969
+ s.heading,
970
+ loaded ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
971
+ " ",
972
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "hyle-cm-count", "aria-label": fill2(s.countLabel, loaded.comment_count), children: loaded.comment_count })
973
+ ] }) : null
974
+ ] }) }),
975
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "hyle-sr", role: "status", "aria-live": "polite", children: live }),
976
+ actionError ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("p", { className: "hyle-cm-err", role: "alert", children: [
977
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "alert" }),
978
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: actionError })
979
+ ] }) : null,
980
+ listing === "error" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "hyle-banner", "data-kind": "bad", role: "alert", children: [
981
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "alert" }),
982
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "hyle-bt", children: [
983
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("b", { children: s.loadError }),
984
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { children: s.loadErrorBody })
985
+ ] }),
986
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("button", { className: "hyle-btn sm", type: "button", onClick: () => {
987
+ setListing("loading");
988
+ void load(false);
989
+ }, children: [
990
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "refresh" }),
991
+ s.retry
992
+ ] })
993
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
994
+ 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,
995
+ 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: [
996
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "clock" }),
997
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "hyle-bt", children: [
998
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("b", { children: s.heldBanner }),
999
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { children: s.heldBannerBody })
1000
+ ] })
1001
+ ] }) : null,
1002
+ rateLeft > 0 ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "hyle-banner", "data-kind": "warn", children: [
1003
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "clock" }),
1004
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "hyle-bt", children: [
1005
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("b", { children: s.rateTitle }),
1006
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { children: s.rateBody })
1007
+ ] })
1008
+ ] }) : null,
1009
+ banned ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "hyle-banner", children: [
1010
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "ban" }),
1011
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "hyle-bt", children: [
1012
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("b", { children: s.bannedTitle }),
1013
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { children: s.bannedBody })
1014
+ ] })
1015
+ ] }) : null,
1016
+ session !== "loading" && (!me || expired) ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "hyle-cm-signin", id: signInId, children: [
1017
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("p", { children: [
1018
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("b", { children: s.signInTitle }),
1019
+ s.signInBody
1020
+ ] }),
1021
+ signInHref ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("a", { className: "hyle-btn primary", href: signInHref, children: s.signIn }) : null
1022
+ ] }) : null,
1023
+ canWrite ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Composer, { ui, id: `${idp}-new`, parentId: null, name: me }) : null,
1024
+ !loaded ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { role: "status", "aria-live": "polite", "aria-busy": "true", children: [
1025
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "hyle-sr", children: s.loading }),
1026
+ /* @__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: [
1027
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "hyle-sk c" }),
1028
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
1029
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "hyle-sk l", style: { width: 120 } }),
1030
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "hyle-sk l", style: { width: "100%" } }),
1031
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "hyle-sk l", style: { width: "72%" } })
1032
+ ] })
1033
+ ] }, i)) })
1034
+ ] }) : thread.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "hyle-cm-empty", children: [
1035
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("b", { children: s.empty }),
1036
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: s.emptyBody })
1037
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
1038
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Thread, { ui, nodes: thread.slice(0, shown) }),
1039
+ 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,
1040
+ loaded.truncated ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "hyle-cm-note", children: s.truncated }) : null
1041
+ ] })
1042
+ ] })
1043
+ ] });
1044
+ }
1045
+ // Annotate the CommonJS export names for ESM import in node:
1046
+ 0 && (module.exports = {
1047
+ Comments
1048
+ });