@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
@@ -0,0 +1,653 @@
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/reactions.tsx
22
+ var reactions_exports = {};
23
+ __export(reactions_exports, {
24
+ HyleReactions: () => HyleReactions
25
+ });
26
+ module.exports = __toCommonJS(reactions_exports);
27
+ var import_react2 = require("react");
28
+
29
+ // src/react/comments-api.ts
30
+ var CSRF_HEADER = "x-hyle-engage";
31
+ var TIMEOUT_MS = 15e3;
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) {
48
+ try {
49
+ const res = await fetch(`${endpoint}${path}`, {
50
+ method,
51
+ credentials: "same-origin",
52
+ cache: "no-store",
53
+ headers: { accept: "application/json", [CSRF_HEADER]: "1", ...body ? { "content-type": "application/json" } : {} },
54
+ ...body ? { body: JSON.stringify(body) } : {},
55
+ signal: AbortSignal.timeout(TIMEOUT_MS)
56
+ });
57
+ let data;
58
+ try {
59
+ data = (await res.json()).data;
60
+ } catch {
61
+ }
62
+ const retry = Number(res.headers.get("retry-after"));
63
+ return { status: res.status, data, retryAfter: Number.isFinite(retry) && retry > 0 ? retry : void 0 };
64
+ } catch {
65
+ return { status: 0, data: void 0, retryAfter: void 0 };
66
+ }
67
+ }
68
+ var REACTION_KINDS = ["like", "love", "insightful", "celebrate"];
69
+ var isCursor = (v) => typeof v === "string" && /^[A-Za-z0-9_-]{1,200}$/.test(v);
70
+ var isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
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)) } : {};
79
+ function toComment(raw) {
80
+ if (!isObject(raw) || typeof raw.id !== "string" || typeof raw.created_at !== "string") return void 0;
81
+ const depth = typeof raw.depth === "number" ? Math.min(4, Math.max(1, Math.trunc(raw.depth))) : 1;
82
+ const author = isObject(raw.author) && typeof raw.author.name === "string" ? raw.author.name : void 0;
83
+ const name = typeof raw.author_name === "string" ? raw.author_name : author;
84
+ const body = isObject(raw.body) && raw.body.format === "hast" ? { format: "hast", tree: raw.body.tree } : null;
85
+ const removed = raw.removed === true || body === null;
86
+ const reactions = parseCounts(raw.reaction_counts);
87
+ return {
88
+ id: raw.id,
89
+ parent_id: typeof raw.parent_id === "string" ? raw.parent_id : null,
90
+ depth,
91
+ author_name: name ?? null,
92
+ created_at: raw.created_at,
93
+ edited_at: typeof raw.edited_at === "string" ? raw.edited_at : null,
94
+ like_count: count(raw.like_count),
95
+ ...Number.isSafeInteger(raw.score) ? { score: raw.score } : {},
96
+ ...reactions ? { reaction_counts: reactions } : {},
97
+ removed,
98
+ ...removed && (raw.removed_by === "moderator" || raw.removed_by === "author") ? { removed_by: raw.removed_by } : {},
99
+ ...removed ? {} : toUnrenderable(raw.unrenderable),
100
+ body,
101
+ // Viewer members exist only on a live comment of a viewer-aware listing; a tombstone never carries them.
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) } : {}
103
+ };
104
+ }
105
+ function toHeld(raw) {
106
+ if (!isObject(raw) || typeof raw.id !== "string" || typeof raw.created_at !== "string" || !isObject(raw.body) || raw.body.format !== "hast") return void 0;
107
+ const author = isObject(raw.author) && typeof raw.author.name === "string" ? raw.author.name : null;
108
+ return {
109
+ id: raw.id,
110
+ parent_id: typeof raw.parent_id === "string" ? raw.parent_id : null,
111
+ depth: typeof raw.depth === "number" ? Math.min(4, Math.max(1, Math.trunc(raw.depth))) : 1,
112
+ author_name: author,
113
+ created_at: raw.created_at,
114
+ edited_at: typeof raw.edited_at === "string" ? raw.edited_at : null,
115
+ can_edit_until: typeof raw.can_edit_until === "string" ? raw.can_edit_until : null,
116
+ ...toUnrenderable(raw.unrenderable),
117
+ body: { format: "hast", tree: raw.body.tree }
118
+ };
119
+ }
120
+ function parseListing(data) {
121
+ if (!isObject(data) || data.kind !== "comments" || !Array.isArray(data.comments)) return void 0;
122
+ const comments = data.comments.map(toComment).filter((c) => c !== void 0);
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
+ 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 } };
145
+ function mergeListings(earlier, later) {
146
+ const byId = new Map(earlier.comments.map((c) => [c.id, c]));
147
+ for (const c of later.comments) {
148
+ const old = byId.get(c.id);
149
+ byId.set(c.id, old && !c.removed ? { ...viewerOf(old), ...c } : c);
150
+ }
151
+ const { liked_by_me, my_reactions, mine_held } = earlier;
152
+ const viewer = !later.mine_held && mine_held ? { liked_by_me: liked_by_me === true, ...my_reactions ? { my_reactions } : {}, mine_held } : {};
153
+ return { ...later, ...viewer, comments: [...byId.values()] };
154
+ }
155
+
156
+ // src/react/comments-labels.ts
157
+ var COMMENT_LABELS_EN = {
158
+ heading: "Comments",
159
+ countLabel: "{n} comments",
160
+ likeArticle: "Like this article",
161
+ likedArticle: "Liked",
162
+ likeArticleSignIn: "(sign in), ",
163
+ likeComment: "Like this comment, ",
164
+ likeCommentSignIn: "Sign in to like this comment, ",
165
+ signInTitle: "Sign in to join the discussion",
166
+ signInBody: "Anyone can read. To comment or like, sign in.",
167
+ signIn: "Sign in",
168
+ commentingAs: "Commenting as {name}",
169
+ write: "Write a comment",
170
+ placeholder: "Add to the discussion",
171
+ help: "Markdown: links, emphasis, code and quotes.",
172
+ chars: "{n} / {max}",
173
+ post: "Post comment",
174
+ posting: "Posting",
175
+ reply: "Reply",
176
+ replyTo: "Reply to {name}",
177
+ replyPlaceholder: "Write a reply",
178
+ cancel: "Cancel",
179
+ edit: "Edit",
180
+ editLeft: "({n} min left)",
181
+ save: "Save",
182
+ delete: "Delete",
183
+ deleteConfirm: "Delete this comment?",
184
+ keep: "Keep",
185
+ you: "You",
186
+ edited: "edited",
187
+ removed: "This comment was removed.",
188
+ removedByModerator: "This comment was removed by a moderator.",
189
+ removedByAuthor: "This comment was deleted by its author.",
190
+ unrenderable: "This comment cannot be displayed.",
191
+ depthEnd: "Replies end at this depth",
192
+ held: "Awaiting approval.",
193
+ heldBanner: "Thanks, your comment is awaiting approval",
194
+ heldBannerBody: "New commenters may be reviewed first. You will see it here, marked as pending, until a moderator approves it. Nobody else can see it yet.",
195
+ heldNote: "Only you can see this until a moderator approves it.",
196
+ heldLive: "Comment awaiting approval",
197
+ postedLive: "Comment posted",
198
+ deletedLive: "Comment deleted",
199
+ savedLive: "Comment saved",
200
+ empty: "No comments yet",
201
+ emptyBody: "Start the discussion. Comments may be reviewed before they appear.",
202
+ loading: "Loading comments",
203
+ loadError: "Comments could not be loaded",
204
+ loadErrorBody: "The article is fine. The comments service did not answer.",
205
+ retry: "Try again",
206
+ postError: "Your comment was not posted. We kept your text, so nothing is lost. Check your connection and try again.",
207
+ tooLong: "That comment is too long or empty. Comments are 1 to 4000 characters.",
208
+ editClosed: "Comments can be edited for ten minutes after posting. That time has passed.",
209
+ actionError: "That did not go through. Please try again.",
210
+ rateTitle: "You are commenting too quickly",
211
+ rateBody: "Please wait before posting again. Your draft is kept in the box below.",
212
+ rateWait: "You can post again in {n} seconds.",
213
+ bannedTitle: "You cannot comment right now",
214
+ bannedBody: "Commenting is not available for your account on this site. You can still read every comment. If you think this is a mistake, contact the site team.",
215
+ expired: "Your session ended. Sign in again to post. Your text is kept.",
216
+ more: "Load more comments",
217
+ truncated: "Only the first part of this discussion is shown.",
218
+ justNow: "just now",
219
+ react: "React",
220
+ reactions: "Reactions",
221
+ reactionLike: "Like",
222
+ reactionLove: "Love",
223
+ reactionInsightful: "Insightful",
224
+ reactionCelebrate: "Celebrate",
225
+ reactionSignIn: "Sign in to react, ",
226
+ reactionAddedLive: "{kind} reaction added",
227
+ reactionRemovedLive: "{kind} reaction removed",
228
+ reactionsLoading: "Loading reactions",
229
+ reactionsError: "Reactions could not be loaded",
230
+ votesOn: "Votes on the comment by {name}",
231
+ score: "Score {n}",
232
+ upvote: "Upvote",
233
+ downvote: "Downvote",
234
+ upvoteSignIn: "Sign in to upvote",
235
+ downvoteSignIn: "Sign in to downvote",
236
+ upvotedLive: "Upvoted. Score {n}",
237
+ downvotedLive: "Downvoted. Score {n}",
238
+ voteRemovedLive: "Vote removed. Score {n}",
239
+ voteRefused: "That vote was not accepted. You cannot vote on your own comment.",
240
+ slowDown: "Too many actions in a short time. Wait a moment and try again.",
241
+ sort: "Sort comments",
242
+ sortNewest: "Newest",
243
+ sortTop: "Top",
244
+ sortedNewestLive: "Showing newest comments first",
245
+ sortedTopLive: "Showing top comments first",
246
+ sortError: "The comments could not be sorted. Please try again.",
247
+ newerLater: "Newer comments appear after you load more.",
248
+ moreError: "More comments could not be loaded. Please try again.",
249
+ loadedLive: "{n} comments loaded"
250
+ };
251
+ var COMMENT_LABELS_FR = {
252
+ heading: "Commentaires",
253
+ countLabel: "{n} commentaires",
254
+ likeArticle: "Aimer cet article",
255
+ likedArticle: "Aim\xE9",
256
+ likeArticleSignIn: "(connexion requise), ",
257
+ likeComment: "Aimer ce commentaire, ",
258
+ likeCommentSignIn: "Connectez-vous pour aimer ce commentaire, ",
259
+ signInTitle: "Connectez-vous pour participer \xE0 la discussion",
260
+ signInBody: "Tout le monde peut lire. Pour commenter ou aimer, connectez-vous.",
261
+ signIn: "Se connecter",
262
+ commentingAs: "Vous commentez en tant que {name}",
263
+ write: "\xC9crire un commentaire",
264
+ placeholder: "Participez \xE0 la discussion",
265
+ help: "Markdown : liens, emphase, code et citations.",
266
+ chars: "{n} / {max}",
267
+ post: "Publier le commentaire",
268
+ posting: "Publication",
269
+ reply: "R\xE9pondre",
270
+ replyTo: "R\xE9pondre \xE0 {name}",
271
+ replyPlaceholder: "\xC9crire une r\xE9ponse",
272
+ cancel: "Annuler",
273
+ edit: "Modifier",
274
+ editLeft: "({n} min restantes)",
275
+ save: "Enregistrer",
276
+ delete: "Supprimer",
277
+ deleteConfirm: "Supprimer ce commentaire ?",
278
+ keep: "Conserver",
279
+ you: "Vous",
280
+ edited: "modifi\xE9",
281
+ removed: "Ce commentaire a \xE9t\xE9 retir\xE9.",
282
+ removedByModerator: "Ce commentaire a \xE9t\xE9 retir\xE9 par un mod\xE9rateur.",
283
+ removedByAuthor: "Ce commentaire a \xE9t\xE9 supprim\xE9 par son auteur.",
284
+ unrenderable: "Ce commentaire ne peut pas \xEAtre affich\xE9.",
285
+ depthEnd: "Les r\xE9ponses s'arr\xEAtent \xE0 ce niveau",
286
+ held: "En attente d'approbation.",
287
+ heldBanner: "Merci, votre commentaire est en attente d'approbation",
288
+ heldBannerBody: "Les nouveaux commentaires peuvent \xEAtre relus d'abord. Vous le voyez ici, marqu\xE9 en attente, jusqu'\xE0 son approbation par un mod\xE9rateur. Personne d'autre ne peut le voir.",
289
+ heldNote: "Vous seul le voyez tant qu'un mod\xE9rateur ne l'a pas approuv\xE9.",
290
+ heldLive: "Commentaire en attente d'approbation",
291
+ postedLive: "Commentaire publi\xE9",
292
+ deletedLive: "Commentaire supprim\xE9",
293
+ savedLive: "Commentaire enregistr\xE9",
294
+ empty: "Aucun commentaire pour l'instant",
295
+ emptyBody: "Lancez la discussion. Les commentaires peuvent \xEAtre relus avant d'appara\xEEtre.",
296
+ loading: "Chargement des commentaires",
297
+ loadError: "Les commentaires n'ont pas pu \xEAtre charg\xE9s",
298
+ loadErrorBody: "L'article est intact. Le service de commentaires n'a pas r\xE9pondu.",
299
+ retry: "R\xE9essayer",
300
+ postError: "Votre commentaire n'a pas \xE9t\xE9 publi\xE9. Votre texte est conserv\xE9. V\xE9rifiez votre connexion et r\xE9essayez.",
301
+ tooLong: "Ce commentaire est trop long ou vide. Un commentaire compte de 1 \xE0 4000 caract\xE8res.",
302
+ editClosed: "Un commentaire peut \xEAtre modifi\xE9 pendant dix minutes apr\xE8s sa publication. Ce d\xE9lai est \xE9coul\xE9.",
303
+ actionError: "L'action a \xE9chou\xE9. R\xE9essayez.",
304
+ rateTitle: "Vous commentez trop vite",
305
+ rateBody: "Patientez avant de publier \xE0 nouveau. Votre brouillon est conserv\xE9 dans la zone ci-dessous.",
306
+ rateWait: "Vous pourrez publier \xE0 nouveau dans {n} secondes.",
307
+ bannedTitle: "Vous ne pouvez pas commenter pour le moment",
308
+ bannedBody: "Les commentaires ne sont pas disponibles pour votre compte sur ce site. Vous pouvez toujours tout lire. Si vous pensez \xE0 une erreur, contactez l'\xE9quipe du site.",
309
+ expired: "Votre session a expir\xE9. Reconnectez-vous pour publier. Votre texte est conserv\xE9.",
310
+ more: "Charger plus de commentaires",
311
+ truncated: "Seul le d\xE9but de cette discussion est affich\xE9.",
312
+ justNow: "\xE0 l'instant",
313
+ react: "R\xE9agir",
314
+ reactions: "R\xE9actions",
315
+ reactionLike: "J'aime",
316
+ reactionLove: "J'adore",
317
+ reactionInsightful: "Instructif",
318
+ reactionCelebrate: "Bravo",
319
+ reactionSignIn: "Connectez-vous pour r\xE9agir, ",
320
+ reactionAddedLive: "R\xE9action {kind} ajout\xE9e",
321
+ reactionRemovedLive: "R\xE9action {kind} retir\xE9e",
322
+ reactionsLoading: "Chargement des r\xE9actions",
323
+ reactionsError: "Les r\xE9actions n'ont pas pu \xEAtre charg\xE9es",
324
+ votesOn: "Votes sur le commentaire de {name}",
325
+ score: "Score {n}",
326
+ upvote: "Voter pour",
327
+ downvote: "Voter contre",
328
+ upvoteSignIn: "Connectez-vous pour voter pour",
329
+ downvoteSignIn: "Connectez-vous pour voter contre",
330
+ upvotedLive: "Vote pour enregistr\xE9. Score {n}",
331
+ downvotedLive: "Vote contre enregistr\xE9. Score {n}",
332
+ voteRemovedLive: "Vote retir\xE9. Score {n}",
333
+ voteRefused: "Ce vote a \xE9t\xE9 refus\xE9. Vous ne pouvez pas voter pour votre propre commentaire.",
334
+ slowDown: "Trop d'actions en peu de temps. Patientez un instant et r\xE9essayez.",
335
+ sort: "Trier les commentaires",
336
+ sortNewest: "R\xE9cents",
337
+ sortTop: "Meilleurs",
338
+ sortedNewestLive: "Commentaires les plus r\xE9cents en premier",
339
+ sortedTopLive: "Meilleurs commentaires en premier",
340
+ sortError: "Les commentaires n'ont pas pu \xEAtre tri\xE9s. R\xE9essayez.",
341
+ newerLater: "Les commentaires plus r\xE9cents apparaissent apr\xE8s le chargement de la suite.",
342
+ moreError: "La suite des commentaires n'a pas pu \xEAtre charg\xE9e. R\xE9essayez.",
343
+ loadedLive: "{n} commentaires charg\xE9s"
344
+ };
345
+ var COMMENT_LABELS_ES = {
346
+ heading: "Comentarios",
347
+ countLabel: "{n} comentarios",
348
+ likeArticle: "Me gusta este art\xEDculo",
349
+ likedArticle: "Te gusta",
350
+ likeArticleSignIn: "(inicia sesi\xF3n), ",
351
+ likeComment: "Me gusta este comentario, ",
352
+ likeCommentSignIn: "Inicia sesi\xF3n para dar me gusta a este comentario, ",
353
+ signInTitle: "Inicia sesi\xF3n para unirte a la conversaci\xF3n",
354
+ signInBody: "Todos pueden leer. Para comentar o dar me gusta, inicia sesi\xF3n.",
355
+ signIn: "Iniciar sesi\xF3n",
356
+ commentingAs: "Comentando como {name}",
357
+ write: "Escribe un comentario",
358
+ placeholder: "A\xF1ade a la conversaci\xF3n",
359
+ help: "Markdown: enlaces, \xE9nfasis, c\xF3digo y citas.",
360
+ chars: "{n} / {max}",
361
+ post: "Publicar comentario",
362
+ posting: "Publicando",
363
+ reply: "Responder",
364
+ replyTo: "Responder a {name}",
365
+ replyPlaceholder: "Escribe una respuesta",
366
+ cancel: "Cancelar",
367
+ edit: "Editar",
368
+ editLeft: "(quedan {n} min)",
369
+ save: "Guardar",
370
+ delete: "Eliminar",
371
+ deleteConfirm: "\xBFEliminar este comentario?",
372
+ keep: "Conservar",
373
+ you: "T\xFA",
374
+ edited: "editado",
375
+ removed: "Este comentario fue eliminado.",
376
+ removedByModerator: "Un moderador elimin\xF3 este comentario.",
377
+ removedByAuthor: "Su autor elimin\xF3 este comentario.",
378
+ unrenderable: "Este comentario no se puede mostrar.",
379
+ depthEnd: "Las respuestas terminan en este nivel",
380
+ held: "Pendiente de aprobaci\xF3n.",
381
+ heldBanner: "Gracias, tu comentario est\xE1 pendiente de aprobaci\xF3n",
382
+ heldBannerBody: "Los comentarios nuevos pueden revisarse primero. Lo ves aqu\xED, marcado como pendiente, hasta que un moderador lo apruebe. Nadie m\xE1s puede verlo todav\xEDa.",
383
+ heldNote: "Solo t\xFA lo ves hasta que un moderador lo apruebe.",
384
+ heldLive: "Comentario pendiente de aprobaci\xF3n",
385
+ postedLive: "Comentario publicado",
386
+ deletedLive: "Comentario eliminado",
387
+ savedLive: "Comentario guardado",
388
+ empty: "A\xFAn no hay comentarios",
389
+ emptyBody: "Empieza la conversaci\xF3n. Los comentarios pueden revisarse antes de aparecer.",
390
+ loading: "Cargando comentarios",
391
+ loadError: "No se pudieron cargar los comentarios",
392
+ loadErrorBody: "El art\xEDculo est\xE1 bien. El servicio de comentarios no respondi\xF3.",
393
+ retry: "Reintentar",
394
+ postError: "Tu comentario no se public\xF3. Hemos conservado tu texto. Revisa tu conexi\xF3n e int\xE9ntalo de nuevo.",
395
+ tooLong: "Ese comentario es demasiado largo o est\xE1 vac\xEDo. Los comentarios tienen de 1 a 4000 caracteres.",
396
+ editClosed: "Un comentario puede editarse durante diez minutos tras publicarlo. Ese tiempo ya pas\xF3.",
397
+ actionError: "No se pudo completar. Int\xE9ntalo de nuevo.",
398
+ rateTitle: "Est\xE1s comentando demasiado r\xE1pido",
399
+ rateBody: "Espera antes de publicar de nuevo. Tu borrador se conserva en el cuadro de abajo.",
400
+ rateWait: "Podr\xE1s publicar de nuevo en {n} segundos.",
401
+ bannedTitle: "No puedes comentar por ahora",
402
+ bannedBody: "Los comentarios no est\xE1n disponibles para tu cuenta en este sitio. A\xFAn puedes leerlos todos. Si crees que es un error, contacta con el equipo del sitio.",
403
+ expired: "Tu sesi\xF3n termin\xF3. Inicia sesi\xF3n de nuevo para publicar. Tu texto se conserva.",
404
+ more: "Cargar m\xE1s comentarios",
405
+ truncated: "Solo se muestra la primera parte de esta conversaci\xF3n.",
406
+ justNow: "ahora mismo",
407
+ react: "Reaccionar",
408
+ reactions: "Reacciones",
409
+ reactionLike: "Me gusta",
410
+ reactionLove: "Me encanta",
411
+ reactionInsightful: "Interesante",
412
+ reactionCelebrate: "Celebrar",
413
+ reactionSignIn: "Inicia sesi\xF3n para reaccionar, ",
414
+ reactionAddedLive: "Reacci\xF3n {kind} a\xF1adida",
415
+ reactionRemovedLive: "Reacci\xF3n {kind} eliminada",
416
+ reactionsLoading: "Cargando reacciones",
417
+ reactionsError: "No se pudieron cargar las reacciones",
418
+ votesOn: "Votos del comentario de {name}",
419
+ score: "Puntuaci\xF3n {n}",
420
+ upvote: "Votar a favor",
421
+ downvote: "Votar en contra",
422
+ upvoteSignIn: "Inicia sesi\xF3n para votar a favor",
423
+ downvoteSignIn: "Inicia sesi\xF3n para votar en contra",
424
+ upvotedLive: "Voto a favor registrado. Puntuaci\xF3n {n}",
425
+ downvotedLive: "Voto en contra registrado. Puntuaci\xF3n {n}",
426
+ voteRemovedLive: "Voto retirado. Puntuaci\xF3n {n}",
427
+ voteRefused: "No se acept\xF3 el voto. No puedes votar tu propio comentario.",
428
+ slowDown: "Demasiadas acciones en poco tiempo. Espera un momento e int\xE9ntalo de nuevo.",
429
+ sort: "Ordenar comentarios",
430
+ sortNewest: "Recientes",
431
+ sortTop: "Destacados",
432
+ sortedNewestLive: "Comentarios m\xE1s recientes primero",
433
+ sortedTopLive: "Comentarios destacados primero",
434
+ sortError: "No se pudieron ordenar los comentarios. Int\xE9ntalo de nuevo.",
435
+ newerLater: "Los comentarios m\xE1s recientes aparecen al cargar m\xE1s.",
436
+ moreError: "No se pudieron cargar m\xE1s comentarios. Int\xE9ntalo de nuevo.",
437
+ loadedLive: "{n} comentarios cargados"
438
+ };
439
+ function commentLabelsFor(locale) {
440
+ const language = locale.slice(0, 2).toLowerCase();
441
+ return language === "fr" ? COMMENT_LABELS_FR : language === "es" ? COMMENT_LABELS_ES : COMMENT_LABELS_EN;
442
+ }
443
+
444
+ // src/react/icons.tsx
445
+ var import_jsx_runtime = require("react/jsx-runtime");
446
+ var SHAPES = {
447
+ info: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
448
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "8", cy: "8", r: "6" }),
449
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M8 7.3V11M8 5v.1" })
450
+ ] }),
451
+ "check-circle": /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
452
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "8", cy: "8", r: "6" }),
453
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "m5.3 8.3 1.9 1.9 3.5-3.9" })
454
+ ] }),
455
+ alert: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M8 2 1.8 13h12.4zM8 6.5v3M8 11.3v.1" }),
456
+ "x-circle": /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
457
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "8", cy: "8", r: "6" }),
458
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "m5.8 5.8 4.4 4.4M10.2 5.8l-4.4 4.4" })
459
+ ] }),
460
+ calendar: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
461
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: "2", y: "3", width: "12", height: "11", rx: "1.3" }),
462
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M2 6.5h12M5.5 1.7v2.6M10.5 1.7v2.6" })
463
+ ] }),
464
+ globe: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
465
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "8", cy: "8", r: "6" }),
466
+ /* @__PURE__ */ (0, import_jsx_runtime.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" })
467
+ ] }),
468
+ file: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
469
+ /* @__PURE__ */ (0, import_jsx_runtime.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" }),
470
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M9 1.8v3h3" })
471
+ ] }),
472
+ chev: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "m6 3.5 4.5 4.5L6 12.5" }),
473
+ "chev-up": /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "m3.5 10 4.5-4.5L12.5 10" }),
474
+ "chev-down": /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "m3.5 6 4.5 4.5L12.5 6" }),
475
+ "chev-left": /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M10 3.5 5.5 8 10 12.5" }),
476
+ x: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "m4 4 8 8M12 4l-8 8" }),
477
+ important: /* @__PURE__ */ (0, import_jsx_runtime.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" }),
478
+ copy: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
479
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: "5.5", y: "5.5", width: "8", height: "8", rx: "1.3" }),
480
+ /* @__PURE__ */ (0, import_jsx_runtime.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" })
481
+ ] }),
482
+ check: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "m3 8.5 3.2 3L13 4.5" }),
483
+ heart: /* @__PURE__ */ (0, import_jsx_runtime.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" }),
484
+ reply: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M6.5 3.5 2.5 7.5l4 4M2.5 7.5h6a5 5 0 0 1 5 5" }),
485
+ clock: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
486
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "8", cy: "8", r: "6" }),
487
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M8 4.5V8l2.3 1.5" })
488
+ ] }),
489
+ ban: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
490
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "8", cy: "8", r: "6" }),
491
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "m3.8 12.2 8.4-8.4" })
492
+ ] }),
493
+ refresh: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M13 8a5 5 0 1 1-1.6-3.7M13 2.5v2.8h-2.8" })
494
+ };
495
+ function Icon({ name, className }) {
496
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { className: className ? `hyle-ic ${className}` : "hyle-ic", viewBox: "0 0 16 16", "aria-hidden": "true", children: SHAPES[name] });
497
+ }
498
+
499
+ // src/react/reaction-bar.tsx
500
+ var import_react = require("react");
501
+ var import_jsx_runtime2 = require("react/jsx-runtime");
502
+ var reactionKey = (subject, kind) => `${subject}:${kind}`;
503
+ var kindName = (s, kind) => ({ like: s.reactionLike, love: s.reactionLove, insightful: s.reactionInsightful, celebrate: s.reactionCelebrate })[kind];
504
+ function settleReactions(overlay, pending, listing) {
505
+ const told = new Set(listing.comments.filter((c) => c.my_reactions).map((c) => c.id));
506
+ if (listing.my_reactions) told.add("article");
507
+ return Object.fromEntries(Object.entries(overlay).flatMap(([key, v]) => {
508
+ if (pending.has(key)) return [[key, v]];
509
+ return v.on && !key.endsWith(":like") && !told.has(key.slice(0, key.lastIndexOf(":"))) ? [[key, { on: true }]] : [];
510
+ }));
511
+ }
512
+ function useReactions(endpoint, path) {
513
+ const [overlay, setOverlay] = (0, import_react.useState)({});
514
+ const pending = (0, import_react.useRef)(/* @__PURE__ */ new Set());
515
+ async function toggle(subject, kind, count2, on) {
516
+ const key = reactionKey(subject, kind);
517
+ if (pending.current.has(key)) return void 0;
518
+ const before = { on: overlay[key]?.on ?? on, count: overlay[key]?.count ?? count2 };
519
+ pending.current.add(key);
520
+ setOverlay((o) => ({ ...o, [key]: { on: !before.on, count: Math.max(0, before.count + (before.on ? -1 : 1)) } }));
521
+ const target = subject === "article" ? { subject_type: "article", path } : { subject_type: "comment", comment_id: subject };
522
+ const r = await call(endpoint, before.on ? "DELETE" : "PUT", "/reactions", kind === "like" ? target : { ...target, kind });
523
+ pending.current.delete(key);
524
+ const reaction = r.status === 200 && isObject(r.data) && isObject(r.data.reaction) ? r.data.reaction : void 0;
525
+ const counts = parseCounts(reaction?.counts);
526
+ const settled = counts ? counts[kind] ?? 0 : kind === "like" && typeof reaction?.like_count === "number" ? reaction.like_count : void 0;
527
+ if (reaction && settled !== void 0) {
528
+ const active = reaction.active === true;
529
+ setOverlay((o) => ({ ...o, [key]: { on: active, count: settled } }));
530
+ return { ok: true, on: active };
531
+ }
532
+ setOverlay((o) => ({ ...o, [key]: before }));
533
+ return { ok: false, status: r.status };
534
+ }
535
+ const settle = (listing) => setOverlay((o) => settleReactions(o, pending.current, listing));
536
+ return { overlay, toggle, settle, reset: () => setOverlay({}) };
537
+ }
538
+ function ReactionBar({ s, scope, subject, likes, counts, likedByMe, mine, overlay, access, signInHref, onToggle }) {
539
+ const [open, setOpen] = (0, import_react.useState)(false);
540
+ const first = (0, import_react.useRef)(null);
541
+ const trigger = (0, import_react.useRef)(null);
542
+ (0, import_react.useEffect)(() => {
543
+ if (open) first.current?.focus();
544
+ }, [open]);
545
+ const base = scope === "article" ? "hyle-btn" : "hyle-cm-btn cnt";
546
+ function button(kind) {
547
+ const state = overlay[reactionKey(subject, kind)];
548
+ const server = kind === "like" ? likes : counts?.[kind] ?? 0;
549
+ const serverOn = mine ? mine.includes(kind) : kind === "like" && likedByMe;
550
+ const count2 = state?.count ?? server;
551
+ const on = state?.on ?? serverOn;
552
+ if (kind !== "like" && !open && !state && count2 === 0) return null;
553
+ const out = access === "out";
554
+ const content = kind !== "like" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
555
+ out ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "hyle-sr", children: s.reactionSignIn }) : null,
556
+ kindName(s, kind),
557
+ " ",
558
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: count2 })
559
+ ] }) : scope === "article" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
560
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { name: "heart" }),
561
+ out ? s.likeArticle : on ? s.likedArticle : s.likeArticle,
562
+ " ",
563
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "hyle-sr", children: out ? s.likeArticleSignIn : ", " }),
564
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: count2 })
565
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
566
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { name: "heart" }),
567
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "hyle-sr", children: out ? s.likeCommentSignIn : s.likeComment }),
568
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: count2 })
569
+ ] });
570
+ const cls = kind === "like" ? base : `${base} chip`;
571
+ if (out && signInHref) return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("a", { className: cls, href: signInHref, children: content }, kind);
572
+ if (access !== "in") return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { className: cls, type: "button", "aria-disabled": "true", children: content }, kind);
573
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { ref: kind === "love" ? first : void 0, className: cls, type: "button", "aria-pressed": on, onClick: () => {
574
+ setOpen(false);
575
+ onToggle(kind, server, serverOn);
576
+ }, children: content }, kind);
577
+ }
578
+ if (!counts) return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: button("like") });
579
+ const onKey = (e) => {
580
+ if (e.key !== "Escape" || !open) return;
581
+ e.preventDefault();
582
+ setOpen(false);
583
+ trigger.current?.focus();
584
+ };
585
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "hyle-reaction-set", role: "group", "aria-label": s.reactions, onKeyDown: onKey, children: [
586
+ REACTION_KINDS.map(button),
587
+ access === "in" ? /* @__PURE__ */ (0, import_jsx_runtime2.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
588
+ ] });
589
+ }
590
+
591
+ // src/react/reactions.tsx
592
+ var import_jsx_runtime3 = require("react/jsx-runtime");
593
+ function HyleReactions(props) {
594
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ArticleReactions, { ...props }, `${props.engagement.endpoint ?? ""}
595
+ ${props.path}`);
596
+ }
597
+ function ArticleReactions({ path, engagement, locale = "en" }) {
598
+ const endpoint = engagement.endpoint ?? "/api/hyle/engage";
599
+ const s = commentLabelsFor(locale);
600
+ const [session, setSession] = (0, import_react2.useState)("loading");
601
+ const [listing, setListing] = (0, import_react2.useState)("loading");
602
+ const [live, setLive] = (0, import_react2.useState)("");
603
+ const [error, setError] = (0, import_react2.useState)(null);
604
+ const [attempt, setAttempt] = (0, import_react2.useState)(0);
605
+ const reactions = useReactions(endpoint, path);
606
+ (0, import_react2.useEffect)(() => {
607
+ let current = true;
608
+ setListing("loading");
609
+ setError(null);
610
+ reactions.reset();
611
+ void fetchPages(endpoint, path, "newest", 1).then((r) => current && setListing(r.status === 404 ? "off" : r.listing ?? "error"));
612
+ void call(endpoint, "GET", "/session").then((r) => {
613
+ if (!current) return;
614
+ const signedIn = r.status === 200 && isObject(r.data) && isObject(r.data.reader) && typeof r.data.reader.name === "string";
615
+ setSession(r.status === 404 ? "off" : signedIn ? "in" : "out");
616
+ });
617
+ return () => void (current = false);
618
+ }, [endpoint, path, attempt]);
619
+ async function react(kind, count2, on) {
620
+ setError(null);
621
+ const r = await reactions.toggle("article", kind, count2, on);
622
+ if (!r) return;
623
+ if (r.ok) return setLive((r.on ? s.reactionAddedLive : s.reactionRemovedLive).replace("{kind}", kindName(s, kind)));
624
+ if (r.status === 401) setSession("out");
625
+ setError(r.status === 401 ? s.expired : r.status === 429 ? s.slowDown : s.actionError);
626
+ }
627
+ if (session === "off" || listing === "off") return null;
628
+ const access = session === "loading" ? "pending" : session;
629
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "hyle hyle-reactions", "data-slot-component": "HyleReactions", children: [
630
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "hyle-sr", role: "status", "aria-live": "polite", children: live }),
631
+ listing === "loading" ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "hyle-react", "aria-busy": "true", children: [
632
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "hyle-sr", children: s.reactionsLoading }),
633
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "hyle-sk", "aria-hidden": "true" })
634
+ ] }) : listing === "error" ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "hyle-react", children: [
635
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("p", { className: "hyle-cm-err", role: "alert", children: [
636
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Icon, { name: "alert" }),
637
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: s.reactionsError })
638
+ ] }),
639
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("button", { className: "hyle-btn sm", type: "button", onClick: () => setAttempt((n) => n + 1), children: [
640
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Icon, { name: "refresh" }),
641
+ s.retry
642
+ ] })
643
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "hyle-react", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ReactionBar, { s, scope: "article", subject: "article", likes: listing.like_count, counts: listing.reaction_counts, likedByMe: listing.liked_by_me === true, mine: listing.my_reactions, overlay: reactions.overlay, access, signInHref: engagement.signInHref, onToggle: (kind, count2, on) => void react(kind, count2, on) }) }),
644
+ error ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("p", { className: "hyle-cm-err", role: "alert", children: [
645
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Icon, { name: "alert" }),
646
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: error })
647
+ ] }) : null
648
+ ] });
649
+ }
650
+ // Annotate the CommonJS export names for ESM import in node:
651
+ 0 && (module.exports = {
652
+ HyleReactions
653
+ });