@haklex/rich-renderer-linkcard 0.0.40 → 0.0.41

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.
@@ -0,0 +1,1398 @@
1
+ import { jsxs, jsx, Fragment } from "react/jsx-runtime";
2
+ import { Star, Globe } from "lucide-react";
3
+ import { useMemo, createContext, use, useState, useCallback, useRef, useEffect } from "react";
4
+ import { useInView } from "react-intersection-observer";
5
+ import { vars } from "@haklex/rich-style-token";
6
+ const arxivPlugin = {
7
+ name: "arxiv",
8
+ displayName: "arXiv Paper",
9
+ priority: 80,
10
+ typeClass: "academic",
11
+ matchUrl(url) {
12
+ if (url.hostname !== "arxiv.org") return null;
13
+ const match = url.pathname.match(/\/(abs|pdf)\/(\d{4}\.\d+(?:v\d+)?)/i);
14
+ if (!match) return null;
15
+ return { id: match[2].toLowerCase(), fullUrl: url.toString() };
16
+ },
17
+ isValidId(id) {
18
+ return /^\d{4}\.\d+(?:v\d+)?$/.test(id);
19
+ },
20
+ async fetch(id) {
21
+ const response = await fetch(
22
+ `https://export.arxiv.org/api/query?id_list=${id}`
23
+ );
24
+ const text = await response.text();
25
+ const parser = new DOMParser();
26
+ const xmlDoc = parser.parseFromString(text, "application/xml");
27
+ const entry = xmlDoc.getElementsByTagName("entry")[0];
28
+ const title2 = entry.getElementsByTagName("title")[0].textContent;
29
+ const authors = entry.getElementsByTagName("author");
30
+ const authorNames = Array.from(authors).map(
31
+ (author) => author.getElementsByTagName("name")[0].textContent
32
+ );
33
+ return {
34
+ title: /* @__PURE__ */ jsxs("span", { style: { display: "flex", alignItems: "center", gap: "8px" }, children: [
35
+ /* @__PURE__ */ jsx("span", { style: { flex: 1 }, children: title2 }),
36
+ /* @__PURE__ */ jsx("span", { style: { flexShrink: 0 }, children: /* @__PURE__ */ jsx(
37
+ "span",
38
+ {
39
+ style: {
40
+ display: "inline-flex",
41
+ alignItems: "center",
42
+ gap: "4px",
43
+ fontSize: vars.typography.fontSizeMd,
44
+ color: "#fb923c"
45
+ },
46
+ children: /* @__PURE__ */ jsx("span", { style: { fontFamily: "sans-serif", fontWeight: 500 }, children: id })
47
+ }
48
+ ) })
49
+ ] }),
50
+ desc: authorNames.length > 1 ? `${authorNames[0]} et al.` : authorNames[0]
51
+ };
52
+ }
53
+ };
54
+ function toCamelCase(str) {
55
+ return str.replaceAll(/_([a-z])/g, (_, c) => c.toUpperCase());
56
+ }
57
+ function camelcaseKeys(obj) {
58
+ if (Array.isArray(obj)) return obj.map(camelcaseKeys);
59
+ if (obj !== null && typeof obj === "object") {
60
+ return Object.fromEntries(
61
+ Object.entries(obj).map(([k, v]) => [toCamelCase(k), camelcaseKeys(v)])
62
+ );
63
+ }
64
+ return obj;
65
+ }
66
+ async function fetchJsonWithContext(url, context, provider, init) {
67
+ const providerAdapter = provider && context?.adapters ? context.adapters[provider] : void 0;
68
+ if (providerAdapter) {
69
+ return providerAdapter.request(url, init);
70
+ }
71
+ if (context?.fetchJson) {
72
+ return context.fetchJson(url, init);
73
+ }
74
+ const response = await fetch(url, init);
75
+ if (!response.ok) {
76
+ throw new Error(`Request failed: ${response.status}`);
77
+ }
78
+ return response.json();
79
+ }
80
+ async function fetchGitHubApi(url, context) {
81
+ const path = url.replace("https://api.github.com", "");
82
+ return fetchJsonWithContext(
83
+ `https://api.github.com${path}`,
84
+ context,
85
+ "github"
86
+ );
87
+ }
88
+ const LanguageToColorMap = {
89
+ typescript: "#2b7489",
90
+ javascript: "#f1e05a",
91
+ html: "#e34c26",
92
+ java: "#b07219",
93
+ go: "#00add8",
94
+ vue: "#2c3e50",
95
+ css: "#563d7c",
96
+ yaml: "#cb171e",
97
+ json: "#292929",
98
+ markdown: "#083fa1",
99
+ csharp: "#178600",
100
+ "c#": "#178600",
101
+ c: "#555555",
102
+ cpp: "#f34b7d",
103
+ "c++": "#f34b7d",
104
+ python: "#3572a5",
105
+ lua: "#000080",
106
+ vimscript: "#199f4b",
107
+ shell: "#89e051",
108
+ dockerfile: "#384d54",
109
+ ruby: "#701516",
110
+ php: "#4f5d95",
111
+ lisp: "#3fb68b",
112
+ kotlin: "#F18E33",
113
+ rust: "#dea584",
114
+ dart: "#00B4AB",
115
+ swift: "#ffac45",
116
+ "objective-c": "#438eff",
117
+ "objective-c++": "#6866fb",
118
+ r: "#198ce7",
119
+ matlab: "#e16737",
120
+ scala: "#c22d40",
121
+ sql: "#e38c00",
122
+ perl: "#0298c3"
123
+ };
124
+ const bangumiTypeMap = {
125
+ subject: "subjects",
126
+ character: "characters",
127
+ person: "persons"
128
+ };
129
+ const allowedBangumiTypes = Object.keys(bangumiTypeMap);
130
+ function hslToHex(h, s, l) {
131
+ s /= 100;
132
+ l /= 100;
133
+ const a = s * Math.min(l, 1 - l);
134
+ const f = (n) => {
135
+ const k = (n + h / 30) % 12;
136
+ const color = l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
137
+ return Math.round(255 * color).toString(16).padStart(2, "0");
138
+ };
139
+ return `#${f(0)}${f(8)}${f(4)}`;
140
+ }
141
+ function generateColor(str, saturation = [30, 35], lightness = [60, 70]) {
142
+ let hash = 0;
143
+ for (let i = 0; i < str.length; i++) {
144
+ hash = str.charCodeAt(i) + ((hash << 5) - hash);
145
+ }
146
+ const sRange = saturation[1] - saturation[0] + 1;
147
+ const lRange = lightness[1] - lightness[0] + 1;
148
+ const h = Math.abs(hash) % 360;
149
+ const s = saturation[0] + Math.abs(hash >> 8) % sRange;
150
+ const l = lightness[0] + Math.abs(hash >> 16) % lRange;
151
+ return hslToHex(h, s, l);
152
+ }
153
+ function stripMarkdown(text) {
154
+ return text.replaceAll(/!\[.*?\]\(.*?\)/g, "").replaceAll(/\[([^\]]*)\]\(.*?\)/g, "$1").replaceAll(/[*_~`#>]/g, "").replaceAll(/\n+/g, " ").trim();
155
+ }
156
+ function getDifficultyColor(difficulty) {
157
+ switch (difficulty) {
158
+ case "Easy":
159
+ return "#00BFA5";
160
+ case "Medium":
161
+ return "#FFA726";
162
+ case "Hard":
163
+ return "#F44336";
164
+ default:
165
+ return "#757575";
166
+ }
167
+ }
168
+ const leetcodePlugin = {
169
+ name: "leetcode",
170
+ displayName: "LeetCode",
171
+ priority: 65,
172
+ typeClass: "wide",
173
+ provider: "leetcode",
174
+ matchUrl(url) {
175
+ if (url.hostname !== "leetcode.cn" && url.hostname !== "leetcode.com")
176
+ return null;
177
+ const parts = url.pathname.split("/").filter(Boolean);
178
+ if (parts[0] !== "problems" || !parts[1]) return null;
179
+ return { id: parts[1], fullUrl: url.toString() };
180
+ },
181
+ isValidId(id) {
182
+ return typeof id === "string" && id.length > 0;
183
+ },
184
+ async fetch(id, _meta, context) {
185
+ const body = {
186
+ query: `query questionData($titleSlug: String!) {
187
+ question(titleSlug: $titleSlug) {translatedTitle
188
+ difficulty
189
+ likes
190
+ topicTags { translatedName
191
+ }
192
+ stats
193
+ }
194
+ }
195
+ `,
196
+ variables: { titleSlug: id }
197
+ };
198
+ const questionData = await fetchJsonWithContext(
199
+ "https://leetcode.cn/graphql/",
200
+ context,
201
+ "leetcode",
202
+ {
203
+ method: "POST",
204
+ headers: { "Content-Type": "application/json" },
205
+ body: JSON.stringify(body)
206
+ }
207
+ );
208
+ const questionTitleData = camelcaseKeys(questionData.data.question);
209
+ const stats = JSON.parse(questionTitleData.stats);
210
+ return {
211
+ title: /* @__PURE__ */ jsxs("span", { style: { display: "flex", alignItems: "center", gap: "8px" }, children: [
212
+ /* @__PURE__ */ jsx("span", { style: { flex: 1 }, children: questionTitleData.translatedTitle }),
213
+ /* @__PURE__ */ jsx("span", { style: { flexShrink: 0 }, children: questionTitleData.likes > 0 && /* @__PURE__ */ jsxs(
214
+ "span",
215
+ {
216
+ style: {
217
+ display: "inline-flex",
218
+ alignItems: "center",
219
+ gap: "4px",
220
+ fontSize: vars.typography.fontSizeMd,
221
+ color: "#fb923c"
222
+ },
223
+ children: [
224
+ "👍",
225
+ /* @__PURE__ */ jsx("span", { style: { fontFamily: "sans-serif", fontWeight: 500 }, children: questionTitleData.likes })
226
+ ]
227
+ }
228
+ ) })
229
+ ] }),
230
+ desc: /* @__PURE__ */ jsxs(Fragment, { children: [
231
+ /* @__PURE__ */ jsx(
232
+ "span",
233
+ {
234
+ style: {
235
+ marginRight: "16px",
236
+ fontWeight: "bold",
237
+ color: getDifficultyColor(questionTitleData.difficulty)
238
+ },
239
+ children: questionTitleData.difficulty
240
+ }
241
+ ),
242
+ /* @__PURE__ */ jsx("span", { style: { overflow: "hidden" }, children: questionTitleData.topicTags.map((tag) => tag.translatedName).join(" / ") }),
243
+ /* @__PURE__ */ jsxs("span", { style: { float: "right", overflow: "hidden" }, children: [
244
+ "AR: ",
245
+ stats.acRate
246
+ ] })
247
+ ] }),
248
+ image: "https://upload.wikimedia.org/wikipedia/commons/1/19/LeetCode_logo_black.png",
249
+ color: getDifficultyColor(questionTitleData.difficulty)
250
+ };
251
+ }
252
+ };
253
+ const githubCommitPlugin = {
254
+ name: "gh-commit",
255
+ displayName: "GitHub Commit",
256
+ priority: 95,
257
+ typeClass: "github",
258
+ provider: "github",
259
+ matchUrl(url) {
260
+ if (url.hostname !== "github.com") return null;
261
+ const parts = url.pathname.split("/").filter(Boolean);
262
+ if (parts.length < 4 || parts[2] !== "commit") return null;
263
+ const [owner, repo, , commitId] = parts;
264
+ return {
265
+ id: `${owner}/${repo}/commit/${commitId}`,
266
+ fullUrl: url.toString()
267
+ };
268
+ },
269
+ isValidId(id) {
270
+ const parts = id.split("/");
271
+ return parts.length === 4 && parts.every((p) => p.length > 0) && parts[2] === "commit";
272
+ },
273
+ async fetch(id, _meta, context) {
274
+ const [owner, repo, , commitId] = id.split("/");
275
+ const response = await fetchGitHubApi(
276
+ `https://api.github.com/repos/${owner}/${repo}/commits/${commitId}`,
277
+ context
278
+ );
279
+ const data = camelcaseKeys(response);
280
+ return {
281
+ title: /* @__PURE__ */ jsx("span", { style: { fontWeight: "normal" }, children: data.commit.message.replace(/Signed-off-by:.+/s, "").trim() }),
282
+ desc: /* @__PURE__ */ jsxs(
283
+ "span",
284
+ {
285
+ style: {
286
+ display: "flex",
287
+ flexWrap: "wrap",
288
+ alignItems: "center",
289
+ gap: "4px 12px",
290
+ fontFamily: vars.typography.fontMono
291
+ },
292
+ children: [
293
+ /* @__PURE__ */ jsxs(
294
+ "span",
295
+ {
296
+ style: {
297
+ display: "inline-flex",
298
+ alignItems: "center",
299
+ gap: "8px"
300
+ },
301
+ children: [
302
+ /* @__PURE__ */ jsxs("span", { style: { color: "#238636" }, children: [
303
+ "+",
304
+ data.stats.additions
305
+ ] }),
306
+ /* @__PURE__ */ jsxs("span", { style: { color: "#f85149" }, children: [
307
+ "-",
308
+ data.stats.deletions
309
+ ] })
310
+ ]
311
+ }
312
+ ),
313
+ /* @__PURE__ */ jsx("span", { style: { fontSize: vars.typography.fontSizeMd }, children: data.sha.slice(0, 7) }),
314
+ /* @__PURE__ */ jsxs("span", { style: { fontSize: vars.typography.fontSizeMd, opacity: 0.8 }, children: [
315
+ owner,
316
+ "/",
317
+ repo
318
+ ] })
319
+ ]
320
+ }
321
+ ),
322
+ image: data.author?.avatarUrl
323
+ };
324
+ }
325
+ };
326
+ const githubDiscussionPlugin = {
327
+ name: "gh-discussion",
328
+ displayName: "GitHub Discussion",
329
+ priority: 95,
330
+ typeClass: "github",
331
+ provider: "github",
332
+ matchUrl(url) {
333
+ if (url.hostname !== "github.com") return null;
334
+ if (!url.pathname.includes("/discussions/")) return null;
335
+ const parts = url.pathname.split("/").filter(Boolean);
336
+ if (parts.length < 4 || parts[2] !== "discussions") return null;
337
+ const discussionNumber = parts[3];
338
+ if (!/^\d+$/.test(discussionNumber)) return null;
339
+ const [owner, repo] = parts;
340
+ return {
341
+ id: `${owner}/${repo}/${discussionNumber}`,
342
+ fullUrl: url.toString()
343
+ };
344
+ },
345
+ isValidId(id) {
346
+ const parts = id.split("/");
347
+ return parts.length === 3 && parts.every((p) => p.length > 0) && /^\d+$/.test(parts[2]);
348
+ },
349
+ async fetch(id, _meta, context) {
350
+ const [owner, repo, discussionNumber] = id.split("/");
351
+ const response = await fetchGitHubApi(
352
+ `https://api.github.com/repos/${owner}/${repo}/discussions/${discussionNumber}`,
353
+ context
354
+ );
355
+ const data = camelcaseKeys(response);
356
+ const categoryName = data.category?.name || "Discussion";
357
+ return {
358
+ title: `Discussion: ${data.title}`,
359
+ desc: /* @__PURE__ */ jsxs(
360
+ "span",
361
+ {
362
+ style: {
363
+ display: "flex",
364
+ flexWrap: "wrap",
365
+ alignItems: "center",
366
+ gap: "4px 12px",
367
+ fontFamily: vars.typography.fontMono
368
+ },
369
+ children: [
370
+ /* @__PURE__ */ jsx(
371
+ "span",
372
+ {
373
+ style: {
374
+ borderRadius: "4px",
375
+ backgroundColor: "rgba(128,128,128,0.15)",
376
+ padding: "2px 6px",
377
+ fontSize: vars.typography.fontSizeXs
378
+ },
379
+ children: categoryName
380
+ }
381
+ ),
382
+ /* @__PURE__ */ jsxs("span", { style: { fontSize: vars.typography.fontSizeMd, opacity: 0.8 }, children: [
383
+ "#",
384
+ discussionNumber,
385
+ " · ",
386
+ owner,
387
+ "/",
388
+ repo
389
+ ] })
390
+ ]
391
+ }
392
+ ),
393
+ image: data.user?.avatarUrl
394
+ };
395
+ }
396
+ };
397
+ const stateColors = {
398
+ open: "#238636",
399
+ closed: "#f85149"
400
+ };
401
+ const stateTextMap$1 = {
402
+ open: "Open",
403
+ closed: "Closed"
404
+ };
405
+ const githubIssuePlugin = {
406
+ name: "gh-issue",
407
+ displayName: "GitHub Issue",
408
+ priority: 95,
409
+ typeClass: "github",
410
+ provider: "github",
411
+ matchUrl(url) {
412
+ if (url.hostname !== "github.com") return null;
413
+ if (!url.pathname.includes("/issues/")) return null;
414
+ const parts = url.pathname.split("/").filter(Boolean);
415
+ if (parts.length < 4 || parts[2] !== "issues") return null;
416
+ const issueNumber = parts[3];
417
+ if (!/^\d+$/.test(issueNumber)) return null;
418
+ const [owner, repo] = parts;
419
+ return { id: `${owner}/${repo}/${issueNumber}`, fullUrl: url.toString() };
420
+ },
421
+ isValidId(id) {
422
+ const parts = id.split("/");
423
+ return parts.length === 3 && parts.every((p) => p.length > 0) && /^\d+$/.test(parts[2]);
424
+ },
425
+ async fetch(id, _meta, context) {
426
+ const [owner, repo, issueNumber] = id.split("/");
427
+ const response = await fetchGitHubApi(
428
+ `https://api.github.com/repos/${owner}/${repo}/issues/${issueNumber}`,
429
+ context
430
+ );
431
+ const data = camelcaseKeys(response);
432
+ const color = stateColors[data.state] || "#6b7280";
433
+ const stateText = stateTextMap$1[data.state] || data.state;
434
+ return {
435
+ title: `Issue: ${data.title}`,
436
+ color,
437
+ desc: /* @__PURE__ */ jsxs(
438
+ "span",
439
+ {
440
+ style: {
441
+ display: "flex",
442
+ flexWrap: "wrap",
443
+ alignItems: "center",
444
+ gap: "4px 12px",
445
+ fontFamily: vars.typography.fontMono
446
+ },
447
+ children: [
448
+ /* @__PURE__ */ jsx("span", { style: { color }, children: stateText }),
449
+ /* @__PURE__ */ jsxs("span", { style: { fontSize: vars.typography.fontSizeMd, opacity: 0.8 }, children: [
450
+ "#",
451
+ issueNumber,
452
+ " · ",
453
+ owner,
454
+ "/",
455
+ repo
456
+ ] })
457
+ ]
458
+ }
459
+ ),
460
+ image: data.user?.avatarUrl
461
+ };
462
+ }
463
+ };
464
+ const getPrState = (data) => {
465
+ if (data.merged) return "merged";
466
+ return data.state;
467
+ };
468
+ const stateColorMap = {
469
+ open: "#238636",
470
+ merged: "#8957e5",
471
+ closed: "#f85149"
472
+ };
473
+ const stateTextMap = {
474
+ open: "Open",
475
+ merged: "Merged",
476
+ closed: "Closed"
477
+ };
478
+ const githubPrPlugin = {
479
+ name: "gh-pr",
480
+ displayName: "GitHub Pull Request",
481
+ priority: 95,
482
+ typeClass: "github",
483
+ provider: "github",
484
+ matchUrl(url) {
485
+ if (url.hostname !== "github.com") return null;
486
+ if (!url.pathname.includes("/pull/")) return null;
487
+ const parts = url.pathname.split("/").filter(Boolean);
488
+ if (parts.length < 4 || parts[2] !== "pull") return null;
489
+ const [owner, repo, , prNumber] = parts;
490
+ return { id: `${owner}/${repo}/${prNumber}`, fullUrl: url.toString() };
491
+ },
492
+ isValidId(id) {
493
+ const parts = id.split("/");
494
+ return parts.length === 3 && parts.every((p) => p.length > 0);
495
+ },
496
+ async fetch(id, _meta, context) {
497
+ const [owner, repo, prNumber] = id.split("/");
498
+ const response = await fetchGitHubApi(
499
+ `https://api.github.com/repos/${owner}/${repo}/pulls/${prNumber}`,
500
+ context
501
+ );
502
+ const data = camelcaseKeys(response);
503
+ const state = getPrState(data);
504
+ const color = stateColorMap[state];
505
+ const stateText = stateTextMap[state];
506
+ return {
507
+ title: `PR: ${data.title}`,
508
+ color,
509
+ desc: /* @__PURE__ */ jsxs(
510
+ "span",
511
+ {
512
+ style: {
513
+ display: "flex",
514
+ flexWrap: "wrap",
515
+ alignItems: "center",
516
+ gap: "4px 12px",
517
+ fontFamily: vars.typography.fontMono
518
+ },
519
+ children: [
520
+ /* @__PURE__ */ jsx("span", { style: { color }, children: stateText }),
521
+ /* @__PURE__ */ jsxs(
522
+ "span",
523
+ {
524
+ style: {
525
+ display: "inline-flex",
526
+ alignItems: "center",
527
+ gap: "8px",
528
+ whiteSpace: "nowrap"
529
+ },
530
+ children: [
531
+ /* @__PURE__ */ jsxs("span", { style: { color: "#238636" }, children: [
532
+ "+",
533
+ data.additions
534
+ ] }),
535
+ /* @__PURE__ */ jsxs("span", { style: { color: "#f85149" }, children: [
536
+ "-",
537
+ data.deletions
538
+ ] })
539
+ ]
540
+ }
541
+ ),
542
+ /* @__PURE__ */ jsxs("span", { style: { fontSize: vars.typography.fontSizeMd, opacity: 0.8 }, children: [
543
+ owner,
544
+ "/",
545
+ repo
546
+ ] })
547
+ ]
548
+ }
549
+ ),
550
+ image: data.user.avatarUrl
551
+ };
552
+ }
553
+ };
554
+ function formatStargazers(n) {
555
+ return n.toLocaleString("en-US");
556
+ }
557
+ const githubRepoPlugin = {
558
+ name: "gh-repo",
559
+ displayName: "GitHub Repository",
560
+ priority: 100,
561
+ typeClass: "github",
562
+ provider: "github",
563
+ matchUrl(url) {
564
+ if (url.hostname !== "github.com") return null;
565
+ const parts = url.pathname.split("/").filter(Boolean);
566
+ if (parts.length !== 2) return null;
567
+ const [owner, repo] = parts;
568
+ if (!owner || !repo) return null;
569
+ return { id: `${owner}/${repo}`, fullUrl: url.toString() };
570
+ },
571
+ isValidId(id) {
572
+ const parts = id.split("/");
573
+ return parts.length === 2 && parts[0].length > 0 && parts[1].length > 0;
574
+ },
575
+ async fetch(id, _meta, context) {
576
+ const [owner, repo] = id.split("/");
577
+ const response = await fetchGitHubApi(
578
+ `https://api.github.com/repos/${owner}/${repo}`,
579
+ context
580
+ );
581
+ const data = camelcaseKeys(response);
582
+ return {
583
+ title: /* @__PURE__ */ jsxs("span", { style: { display: "flex", alignItems: "center", gap: "8px" }, children: [
584
+ /* @__PURE__ */ jsx("span", { style: { flex: 1 }, children: data.name }),
585
+ /* @__PURE__ */ jsx("span", { style: { flexShrink: 0 }, children: data.stargazersCount > 0 && /* @__PURE__ */ jsxs(
586
+ "span",
587
+ {
588
+ style: {
589
+ display: "inline-flex",
590
+ alignItems: "center",
591
+ gap: "4px",
592
+ fontSize: vars.typography.fontSizeMd,
593
+ color: "#fb923c"
594
+ },
595
+ children: [
596
+ /* @__PURE__ */ jsx(Star, { size: 14, strokeWidth: 2, "aria-hidden": true }),
597
+ /* @__PURE__ */ jsx("span", { style: { fontFamily: "sans-serif", fontWeight: 500 }, children: formatStargazers(data.stargazersCount) })
598
+ ]
599
+ }
600
+ ) })
601
+ ] }),
602
+ desc: data.description,
603
+ image: data.owner.avatarUrl,
604
+ color: LanguageToColorMap[data.language?.toLowerCase()]
605
+ };
606
+ }
607
+ };
608
+ const bangumiPlugin = {
609
+ name: "bangumi",
610
+ displayName: "Bangumi",
611
+ priority: 70,
612
+ typeClass: "media",
613
+ provider: "bangumi",
614
+ matchUrl(url) {
615
+ if (url.hostname !== "bgm.tv" && url.hostname !== "bangumi.tv") return null;
616
+ const parts = url.pathname.split("/").filter(Boolean);
617
+ if (parts.length < 2) return null;
618
+ const [type, realId] = parts;
619
+ if (!allowedBangumiTypes.includes(type)) return null;
620
+ return { id: `${type}/${realId}`, fullUrl: url.toString(), meta: { type } };
621
+ },
622
+ isValidId(id) {
623
+ const [type, realId] = id.split("/");
624
+ return allowedBangumiTypes.includes(type) && realId?.length > 0;
625
+ },
626
+ async fetch(id, _meta, context) {
627
+ const [type, realId] = id.split("/");
628
+ const json = await fetchJsonWithContext(
629
+ `https://api.bgm.tv/v0/${bangumiTypeMap[type]}/${realId}`,
630
+ context,
631
+ "bangumi"
632
+ );
633
+ let title2 = "";
634
+ let originalTitle = "";
635
+ if (type === "subject") {
636
+ if (json.name_cn && json.name_cn !== json.name && json.name_cn !== "") {
637
+ title2 = json.name_cn;
638
+ originalTitle = json.name;
639
+ } else {
640
+ title2 = json.name;
641
+ originalTitle = json.name;
642
+ }
643
+ } else if (type === "character" || type === "person") {
644
+ const { infobox } = json;
645
+ infobox.forEach(
646
+ (item) => {
647
+ if (item.key === "简体中文名") {
648
+ title2 = typeof item.value === "string" ? item.value : item.value[0].v;
649
+ } else if (item.key === "别名") {
650
+ const aliases = item.value;
651
+ aliases.forEach((alias) => {
652
+ originalTitle += `${alias.v} / `;
653
+ });
654
+ originalTitle = originalTitle.slice(0, -3);
655
+ }
656
+ }
657
+ );
658
+ }
659
+ const starStyle = {
660
+ display: "inline-flex",
661
+ flexShrink: 0,
662
+ alignItems: "center",
663
+ gap: "4px",
664
+ alignSelf: "center",
665
+ fontSize: vars.typography.fontSizeXs,
666
+ color: "#fb923c"
667
+ };
668
+ return {
669
+ title: /* @__PURE__ */ jsxs(
670
+ "span",
671
+ {
672
+ style: {
673
+ display: "flex",
674
+ flexWrap: "wrap",
675
+ alignItems: "flex-end",
676
+ gap: "8px"
677
+ },
678
+ children: [
679
+ /* @__PURE__ */ jsx("span", { children: title2 }),
680
+ title2 !== originalTitle && /* @__PURE__ */ jsxs(
681
+ "span",
682
+ {
683
+ style: { fontSize: vars.typography.fontSizeMd, opacity: 0.7 },
684
+ children: [
685
+ "(",
686
+ originalTitle,
687
+ ")"
688
+ ]
689
+ }
690
+ ),
691
+ type === "subject" && /* @__PURE__ */ jsxs(
692
+ "span",
693
+ {
694
+ style: {
695
+ display: "inline-flex",
696
+ flexShrink: 0,
697
+ alignItems: "center",
698
+ gap: "12px",
699
+ alignSelf: "center"
700
+ },
701
+ children: [
702
+ /* @__PURE__ */ jsxs("span", { style: starStyle, children: [
703
+ "★",
704
+ /* @__PURE__ */ jsx("span", { style: { fontFamily: "sans-serif", fontWeight: 500 }, children: json.rating.score > 0 && json.rating.score.toFixed(1) })
705
+ ] }),
706
+ /* @__PURE__ */ jsxs("span", { style: starStyle, children: [
707
+ "☆",
708
+ /* @__PURE__ */ jsx("span", { style: { fontFamily: "sans-serif", fontWeight: 500 }, children: json.collection && json.collection.on_hold + json.collection.dropped + json.collection.wish + json.collection.collect + json.collection.doing })
709
+ ] })
710
+ ]
711
+ }
712
+ ),
713
+ (type === "character" || type === "person") && /* @__PURE__ */ jsxs("span", { style: starStyle, children: [
714
+ "☆",
715
+ /* @__PURE__ */ jsx("span", { style: { fontFamily: "sans-serif", fontWeight: 500 }, children: json.stat.collects > 0 && json.stat.collects })
716
+ ] })
717
+ ]
718
+ }
719
+ ),
720
+ desc: /* @__PURE__ */ jsx("span", { style: { overflow: "visible", whiteSpace: "pre-wrap" }, children: json.summary }),
721
+ image: json.images.grid,
722
+ color: generateColor(title2),
723
+ classNames: {
724
+ image: "link-card__image--poster",
725
+ cardRoot: "link-card--reversed"
726
+ }
727
+ };
728
+ }
729
+ };
730
+ const neteaseMusicPlugin = {
731
+ name: "netease-music-song",
732
+ displayName: "Netease Music Song",
733
+ priority: 60,
734
+ typeClass: "wide",
735
+ provider: "netease-music",
736
+ matchUrl(url) {
737
+ if (url.hostname !== "music.163.com") return null;
738
+ if (!url.pathname.includes("/song") && !url.hash.includes("/song"))
739
+ return null;
740
+ const urlString = url.toString().replaceAll("/#/", "/");
741
+ const _url = new URL(urlString);
742
+ const id = _url.searchParams.get("id");
743
+ if (!id) return null;
744
+ return { id, fullUrl: url.toString() };
745
+ },
746
+ isValidId(id) {
747
+ return id.length > 0;
748
+ },
749
+ async fetch(id, _meta, context) {
750
+ const songData = await fetchJsonWithContext(
751
+ `https://music.163.com/song/${id}`,
752
+ context,
753
+ "netease-music"
754
+ );
755
+ const songInfo = songData.songs[0];
756
+ const albumInfo = songInfo.al;
757
+ const singerInfo = songInfo.ar;
758
+ return {
759
+ title: /* @__PURE__ */ jsxs(Fragment, { children: [
760
+ /* @__PURE__ */ jsx("span", { children: songInfo.name }),
761
+ songInfo.tns && /* @__PURE__ */ jsx(
762
+ "span",
763
+ {
764
+ style: {
765
+ marginLeft: "8px",
766
+ fontSize: vars.typography.fontSizeMd,
767
+ color: "#a1a1aa"
768
+ },
769
+ children: songInfo.tns[0]
770
+ }
771
+ )
772
+ ] }),
773
+ desc: /* @__PURE__ */ jsxs(Fragment, { children: [
774
+ /* @__PURE__ */ jsxs("span", { style: { display: "block" }, children: [
775
+ /* @__PURE__ */ jsx("span", { style: { fontWeight: "bold" }, children: "歌手:" }),
776
+ /* @__PURE__ */ jsx("span", { children: singerInfo.map((p) => p.name).join(" / ") })
777
+ ] }),
778
+ /* @__PURE__ */ jsxs("span", { style: { display: "block" }, children: [
779
+ /* @__PURE__ */ jsx("span", { style: { fontWeight: "bold" }, children: "专辑:" }),
780
+ /* @__PURE__ */ jsx("span", { children: albumInfo.name })
781
+ ] })
782
+ ] }),
783
+ image: albumInfo.picUrl,
784
+ color: "#e72d2c"
785
+ };
786
+ }
787
+ };
788
+ const qqMusicPlugin = {
789
+ name: "qq-music-song",
790
+ displayName: "QQ Music Song",
791
+ priority: 60,
792
+ typeClass: "wide",
793
+ provider: "qq-music",
794
+ matchUrl(url) {
795
+ if (url.hostname !== "y.qq.com") return null;
796
+ if (!url.pathname.includes("/songDetail/")) return null;
797
+ const parts = url.pathname.split("/");
798
+ const songDetailIndex = parts.indexOf("songDetail");
799
+ if (songDetailIndex === -1 || !parts[songDetailIndex + 1]) return null;
800
+ return { id: parts[songDetailIndex + 1], fullUrl: url.toString() };
801
+ },
802
+ isValidId(id) {
803
+ return typeof id === "string" && id.length > 0;
804
+ },
805
+ async fetch(id, _meta, context) {
806
+ const songData = await fetchJsonWithContext(
807
+ `https://y.qq.com/song/${id}`,
808
+ context,
809
+ "qq-music"
810
+ );
811
+ const songInfo = songData.data[0];
812
+ const albumId = songInfo.album.mid;
813
+ return {
814
+ title: /* @__PURE__ */ jsxs(Fragment, { children: [
815
+ /* @__PURE__ */ jsx("span", { children: songInfo.title }),
816
+ songInfo.subtitle && /* @__PURE__ */ jsx(
817
+ "span",
818
+ {
819
+ style: {
820
+ marginLeft: "8px",
821
+ fontSize: vars.typography.fontSizeMd,
822
+ color: "#a1a1aa"
823
+ },
824
+ children: songInfo.subtitle
825
+ }
826
+ )
827
+ ] }),
828
+ desc: /* @__PURE__ */ jsxs(Fragment, { children: [
829
+ /* @__PURE__ */ jsxs("span", { style: { display: "block" }, children: [
830
+ /* @__PURE__ */ jsx("span", { style: { fontWeight: "bold" }, children: "歌手:" }),
831
+ /* @__PURE__ */ jsx("span", { children: songInfo.singer.map((p) => p.name).join(" / ") })
832
+ ] }),
833
+ /* @__PURE__ */ jsxs("span", { style: { display: "block" }, children: [
834
+ /* @__PURE__ */ jsx("span", { style: { fontWeight: "bold" }, children: "专辑:" }),
835
+ /* @__PURE__ */ jsx("span", { children: songInfo.album.name })
836
+ ] })
837
+ ] }),
838
+ image: `https://y.gtimg.cn/music/photo_new/T002R300x300M000${albumId}.jpg?max_age=2592000`,
839
+ color: "#31c27c"
840
+ };
841
+ }
842
+ };
843
+ const TMDB_LANGUAGE_BY_LOCALE = {
844
+ zh: "zh-CN",
845
+ en: "en-US",
846
+ ja: "ja-JP"
847
+ };
848
+ const getCurrentLocale = () => {
849
+ if (typeof document !== "undefined") {
850
+ const lang = document.documentElement?.lang?.trim();
851
+ if (lang) return lang;
852
+ }
853
+ if (typeof window !== "undefined") {
854
+ const firstSegment = window.location.pathname.split("/").find((s) => s.length > 0);
855
+ if (firstSegment) return firstSegment;
856
+ }
857
+ return "en";
858
+ };
859
+ const tmdbPlugin = {
860
+ name: "tmdb",
861
+ displayName: "The Movie Database",
862
+ priority: 70,
863
+ typeClass: "media",
864
+ provider: "tmdb",
865
+ matchUrl(url) {
866
+ if (!url.hostname.includes("themoviedb.org")) return null;
867
+ const parts = url.pathname.split("/").filter(Boolean);
868
+ if (parts.length < 2) return null;
869
+ const [type, realId] = parts;
870
+ const canParsedTypes = ["tv", "movie"];
871
+ if (!canParsedTypes.includes(type) || !realId) return null;
872
+ return { id: `${type}/${realId}`, fullUrl: url.toString(), meta: { type } };
873
+ },
874
+ isValidId(id) {
875
+ const [type, realId] = id.split("/");
876
+ const canParsedTypes = ["tv", "movie"];
877
+ return canParsedTypes.includes(type) && realId?.length > 0;
878
+ },
879
+ async fetch(id, _meta, context) {
880
+ const [type, realId] = id.split("/");
881
+ const locale = getCurrentLocale();
882
+ const userLanguage = TMDB_LANGUAGE_BY_LOCALE[locale] || (typeof navigator !== "undefined" ? navigator.language : "en-US") || "en-US";
883
+ const json = await fetchJsonWithContext(
884
+ `https://api.themoviedb.org/3/${type}/${realId}?language=${userLanguage}`,
885
+ context,
886
+ "tmdb"
887
+ );
888
+ const title2 = type === "tv" ? json.name : json.title;
889
+ const originalTitle = type === "tv" ? json.original_name : json.original_title;
890
+ return {
891
+ title: /* @__PURE__ */ jsxs(
892
+ "span",
893
+ {
894
+ style: {
895
+ display: "flex",
896
+ flexWrap: "wrap",
897
+ alignItems: "flex-end",
898
+ gap: "8px"
899
+ },
900
+ children: [
901
+ /* @__PURE__ */ jsx("span", { children: title2 }),
902
+ title2 !== originalTitle && /* @__PURE__ */ jsxs(
903
+ "span",
904
+ {
905
+ style: { fontSize: vars.typography.fontSizeMd, opacity: 0.7 },
906
+ children: [
907
+ "(",
908
+ originalTitle,
909
+ ")"
910
+ ]
911
+ }
912
+ ),
913
+ /* @__PURE__ */ jsxs(
914
+ "span",
915
+ {
916
+ style: {
917
+ display: "inline-flex",
918
+ flexShrink: 0,
919
+ alignItems: "center",
920
+ gap: "4px",
921
+ alignSelf: "center",
922
+ fontSize: vars.typography.fontSizeXs,
923
+ color: "#fb923c"
924
+ },
925
+ children: [
926
+ "★",
927
+ /* @__PURE__ */ jsx("span", { style: { fontFamily: "sans-serif", fontWeight: 500 }, children: json.vote_average > 0 && json.vote_average.toFixed(1) })
928
+ ]
929
+ }
930
+ )
931
+ ]
932
+ }
933
+ ),
934
+ desc: /* @__PURE__ */ jsx("span", { style: { overflow: "visible", whiteSpace: "pre-wrap" }, children: json.overview }),
935
+ image: `https://image.tmdb.org/t/p/w500${json.poster_path}`,
936
+ color: generateColor(title2 || originalTitle || id),
937
+ classNames: {
938
+ image: "link-card__image--poster",
939
+ cardRoot: "link-card--reversed"
940
+ }
941
+ };
942
+ }
943
+ };
944
+ function createMxSpacePlugin(config) {
945
+ const webHost = new URL(config.webUrl).hostname;
946
+ return {
947
+ name: "self",
948
+ displayName: "MxSpace Article",
949
+ priority: 10,
950
+ provider: "mx-space",
951
+ matchUrl(url) {
952
+ if (webHost !== url.hostname) return null;
953
+ if (!url.pathname.startsWith("/posts/") && !url.pathname.startsWith("/notes/")) {
954
+ return null;
955
+ }
956
+ return { id: url.pathname.slice(1), fullUrl: url.toString() };
957
+ },
958
+ isValidId(id) {
959
+ const [type, ...rest] = id.split("/");
960
+ if (type !== "posts" && type !== "notes") return false;
961
+ if (type === "posts") return rest.length === 2;
962
+ return rest.length === 1;
963
+ },
964
+ async fetch(id, _meta, context) {
965
+ const [type, ...rest] = id.split("/");
966
+ let data = { title: "", text: "" };
967
+ if (type === "posts") {
968
+ const [cate, slug] = rest;
969
+ data = await fetchJsonWithContext(
970
+ `posts/${cate}/${slug}`,
971
+ context,
972
+ "mx-space"
973
+ );
974
+ } else if (type === "notes") {
975
+ const [nid] = rest;
976
+ const response = await fetchJsonWithContext(
977
+ `notes/${nid}`,
978
+ context,
979
+ "mx-space"
980
+ );
981
+ data = response.data || response;
982
+ }
983
+ const coverImage = data.cover || data.meta?.cover;
984
+ const spotlightColor = generateColor(data.title);
985
+ return {
986
+ title: data.title,
987
+ desc: data.summary || `${stripMarkdown(data.text).slice(0, 50)}...`,
988
+ image: coverImage || data.images?.[0]?.src,
989
+ color: spotlightColor
990
+ };
991
+ }
992
+ };
993
+ }
994
+ const mxSpacePlugin = {
995
+ name: "self",
996
+ displayName: "MxSpace Article",
997
+ priority: 10,
998
+ provider: "mx-space",
999
+ matchUrl(_url) {
1000
+ return null;
1001
+ },
1002
+ isValidId(id) {
1003
+ const [type, ...rest] = id.split("/");
1004
+ if (type !== "posts" && type !== "notes") return false;
1005
+ if (type === "posts") return rest.length === 2;
1006
+ return rest.length === 1;
1007
+ },
1008
+ async fetch(id, _meta, context) {
1009
+ const [type, ...rest] = id.split("/");
1010
+ let data = { title: "", text: "" };
1011
+ if (type === "posts") {
1012
+ const [cate, slug] = rest;
1013
+ data = await fetchJsonWithContext(
1014
+ `posts/${cate}/${slug}`,
1015
+ context,
1016
+ "mx-space"
1017
+ );
1018
+ } else if (type === "notes") {
1019
+ const [nid] = rest;
1020
+ const response = await fetchJsonWithContext(
1021
+ `notes/${nid}`,
1022
+ context,
1023
+ "mx-space"
1024
+ );
1025
+ data = response.data || response;
1026
+ }
1027
+ const coverImage = data.cover || data.meta?.cover;
1028
+ const spotlightColor = generateColor(data.title);
1029
+ return {
1030
+ title: data.title,
1031
+ desc: data.summary || `${stripMarkdown(data.text).slice(0, 50)}...`,
1032
+ image: coverImage || data.images?.[0]?.src,
1033
+ color: spotlightColor
1034
+ };
1035
+ }
1036
+ };
1037
+ const plugins = [
1038
+ githubRepoPlugin,
1039
+ githubCommitPlugin,
1040
+ githubPrPlugin,
1041
+ githubIssuePlugin,
1042
+ githubDiscussionPlugin,
1043
+ arxivPlugin,
1044
+ tmdbPlugin,
1045
+ bangumiPlugin,
1046
+ qqMusicPlugin,
1047
+ neteaseMusicPlugin,
1048
+ leetcodePlugin,
1049
+ mxSpacePlugin
1050
+ ].sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
1051
+ function getPluginByName(name) {
1052
+ return plugins.find((p) => p.name === name);
1053
+ }
1054
+ const pluginMap = new Map(
1055
+ plugins.map((p) => [p.name, p])
1056
+ );
1057
+ function matchUrl(url, pluginRegistry = plugins) {
1058
+ try {
1059
+ const parsed = new URL(url);
1060
+ for (const plugin of pluginRegistry) {
1061
+ const match = plugin.matchUrl(parsed);
1062
+ if (match) return { plugin, match };
1063
+ }
1064
+ } catch {
1065
+ }
1066
+ return null;
1067
+ }
1068
+ function useUrlMatcher(url, pluginRegistry = plugins) {
1069
+ return useMemo(() => {
1070
+ if (!url) return null;
1071
+ return matchUrl(url, pluginRegistry);
1072
+ }, [url, pluginRegistry]);
1073
+ }
1074
+ var semanticClassNames = { card: "link-card", cardShortDesc: "link-card--short-desc", cardSkeleton: "link-card--skeleton", cardError: "link-card--error", bg: "link-card__bg", image: "link-card__image", icon: "link-card__icon", content: "link-card__content", title: "link-card__title", titleText: "link-card__title-text", desc: "link-card__desc", desc2: "link-card__desc-2", editWrapper: "rich-link-card-edit-wrapper", editPanel: "rich-link-card-edit-panel", editUrlRow: "rich-link-card-edit-url-row", editLinkIcon: "rich-link-card-edit-link-icon", editInput: "rich-link-card-edit-input", editActions: "rich-link-card-edit-actions", editActionButton: "rich-link-card-edit-action-btn", editActionButtonEnd: "rich-link-card-edit-action-btn--end" };
1075
+ var card = "_13weebv0";
1076
+ var cardShortDesc = "_13weebv1";
1077
+ var bg = "_13weebv2";
1078
+ var image = "_13weebv3";
1079
+ var icon = "_13weebv5";
1080
+ var content = "_13weebv6";
1081
+ var title = "_13weebv7";
1082
+ var titleText = "_13weebv8";
1083
+ var desc = "_13weebva";
1084
+ var desc2 = "_13weebvb";
1085
+ var cardSkeleton = "_13weebvj";
1086
+ var cardError = "_13weebvl";
1087
+ var editWrapper = "_13weebvm";
1088
+ var editPanel = "_13weebvn";
1089
+ var editUrlRow = "_13weebvo";
1090
+ var editLinkIcon = "_13weebvp";
1091
+ var editInput = "_13weebvr";
1092
+ var editActions = "_13weebvs";
1093
+ var editActionButton = "_13weebvt";
1094
+ var editActionButtonEnd = "_13weebvu";
1095
+ var typeCardModifier = { media: "_13weebvg", github: "_13weebvh", academic: "_13weebvi", wide: "_13weebve", full: "_13weebvf" };
1096
+ var semanticTypeClassNames = { media: "link-card--media", github: "link-card--github", academic: "link-card--academic", wide: "link-card--wide", full: "link-card--full" };
1097
+ var semanticClassToStyle = { "link-card--short-desc": "_13weebv1", "link-card--skeleton": "_13weebvj", "link-card--error": "_13weebvl", "link-card--reversed": "_13weebvd", "link-card--wide": "_13weebve", "link-card--full": "_13weebvf", "link-card--media": "_13weebvg", "link-card--github": "_13weebvh", "link-card--academic": "_13weebvi", "link-card__image--poster": "_13weebv4" };
1098
+ const ctx = createContext(void 0);
1099
+ const LinkCardFetchProvider = ctx.Provider;
1100
+ function useLinkCardFetchContext() {
1101
+ return use(ctx);
1102
+ }
1103
+ function useCardFetcher(options) {
1104
+ const { source, plugin, id, fallbackUrl, enabled = true, context } = options;
1105
+ const [loading, setLoading] = useState(true);
1106
+ const [isError, setIsError] = useState(false);
1107
+ const [fullUrl] = useState(fallbackUrl || "javascript:;");
1108
+ const [cardInfo, setCardInfo] = useState();
1109
+ const isValid = useMemo(() => {
1110
+ if (!enabled || !plugin) return false;
1111
+ return plugin.isValidId(id);
1112
+ }, [plugin, enabled, id]);
1113
+ const fetchInfo = useCallback(async () => {
1114
+ if (!plugin || !isValid) return;
1115
+ setLoading(true);
1116
+ setIsError(false);
1117
+ try {
1118
+ const data = await plugin.fetch(id, void 0, context);
1119
+ setCardInfo(data);
1120
+ } catch (err) {
1121
+ console.error(
1122
+ `[LinkCard] Error fetching ${source || plugin.name} data:`,
1123
+ err
1124
+ );
1125
+ setIsError(true);
1126
+ } finally {
1127
+ setLoading(false);
1128
+ }
1129
+ }, [context, plugin, isValid, id, source]);
1130
+ const { ref } = useInView({
1131
+ triggerOnce: true,
1132
+ onChange(inView) {
1133
+ if (!inView || !enabled) return;
1134
+ fetchInfo();
1135
+ }
1136
+ });
1137
+ return {
1138
+ loading,
1139
+ isError,
1140
+ cardInfo,
1141
+ fullUrl,
1142
+ isValid,
1143
+ ref
1144
+ };
1145
+ }
1146
+ function LinkCardSkeleton({
1147
+ source,
1148
+ className
1149
+ }) {
1150
+ const plugin = source ? pluginMap.get(source) : void 0;
1151
+ const typeClass = plugin?.typeClass;
1152
+ const typeStyleClass = typeClass ? typeCardModifier[typeClass] : "";
1153
+ const typeSemanticClass = typeClass ? semanticTypeClassNames[typeClass] : "";
1154
+ return /* @__PURE__ */ jsxs(
1155
+ "span",
1156
+ {
1157
+ "data-hide-print": true,
1158
+ "data-source": source || void 0,
1159
+ className: [
1160
+ card,
1161
+ semanticClassNames.card,
1162
+ cardSkeleton,
1163
+ semanticClassNames.cardSkeleton,
1164
+ typeStyleClass,
1165
+ typeSemanticClass,
1166
+ className
1167
+ ].filter(Boolean).join(" "),
1168
+ children: [
1169
+ /* @__PURE__ */ jsx("span", { className: `${image} ${semanticClassNames.image}` }),
1170
+ /* @__PURE__ */ jsxs(
1171
+ "span",
1172
+ {
1173
+ className: `${content} ${semanticClassNames.content}`,
1174
+ children: [
1175
+ /* @__PURE__ */ jsx("span", { className: `${title} ${semanticClassNames.title}`, children: /* @__PURE__ */ jsx(
1176
+ "span",
1177
+ {
1178
+ className: `${titleText} ${semanticClassNames.titleText}`
1179
+ }
1180
+ ) }),
1181
+ /* @__PURE__ */ jsx("span", { className: `${desc} ${semanticClassNames.desc}` }),
1182
+ /* @__PURE__ */ jsx(
1183
+ "span",
1184
+ {
1185
+ className: `${desc} ${semanticClassNames.desc} ${desc2} ${semanticClassNames.desc2}`
1186
+ }
1187
+ )
1188
+ ]
1189
+ }
1190
+ )
1191
+ ]
1192
+ }
1193
+ );
1194
+ }
1195
+ function FallbackIcon({ favicon }) {
1196
+ const [faviconFailed, setFaviconFailed] = useState(false);
1197
+ return /* @__PURE__ */ jsx("span", { className: `${icon} ${semanticClassNames.icon}`, children: favicon && !faviconFailed ? /* @__PURE__ */ jsx("img", { src: favicon, alt: "", onError: () => setFaviconFailed(true) }) : /* @__PURE__ */ jsx(Globe, { "aria-hidden": "true" }) });
1198
+ }
1199
+ function mapSemanticClasses(classNames) {
1200
+ if (!classNames) return "";
1201
+ return classNames.split(/\s+/).filter(Boolean).map(
1202
+ (cls) => semanticClassToStyle[cls] ? `${semanticClassToStyle[cls]} ${cls}` : cls
1203
+ ).join(" ");
1204
+ }
1205
+ const LinkCardRenderer = (props) => {
1206
+ const {
1207
+ url,
1208
+ title: title$1,
1209
+ description,
1210
+ favicon,
1211
+ image: image$1,
1212
+ source: explicitSource,
1213
+ id: explicitId,
1214
+ className,
1215
+ plugins: plugins$1 = plugins,
1216
+ fetchContext: fetchContextProp
1217
+ } = props;
1218
+ const contextValue = useLinkCardFetchContext();
1219
+ const fetchContext = fetchContextProp ?? contextValue;
1220
+ const pluginMap2 = useMemo(
1221
+ () => new Map(plugins$1.map((plugin) => [plugin.name, plugin])),
1222
+ [plugins$1]
1223
+ );
1224
+ const urlMatch = useUrlMatcher(
1225
+ !explicitSource || !explicitId ? url : void 0,
1226
+ plugins$1
1227
+ );
1228
+ const source = explicitSource || urlMatch?.plugin.name;
1229
+ const id = explicitId || urlMatch?.match.id;
1230
+ const matchedFullUrl = urlMatch?.match.fullUrl;
1231
+ const useDynamicFetch = !!source && !!id;
1232
+ const selectedPlugin = source ? pluginMap2.get(source) : void 0;
1233
+ const { loading, isError, cardInfo, fullUrl, isValid, ref } = useCardFetcher({
1234
+ source,
1235
+ plugin: selectedPlugin,
1236
+ id: id || "",
1237
+ fallbackUrl: matchedFullUrl || url,
1238
+ enabled: useDynamicFetch,
1239
+ context: fetchContext
1240
+ });
1241
+ const typeClass = selectedPlugin?.typeClass;
1242
+ const typeStyleClass = typeClass ? typeCardModifier[typeClass] : "";
1243
+ const typeSemanticClass = typeClass ? semanticTypeClassNames[typeClass] : "";
1244
+ const finalTitle = cardInfo?.title || title$1 || url;
1245
+ const finalDesc = cardInfo?.desc || description;
1246
+ const finalImage = cardInfo?.image || image$1;
1247
+ const finalColor = cardInfo?.color;
1248
+ const classNames = cardInfo?.classNames || {};
1249
+ const mappedCardRootClass = mapSemanticClasses(classNames.cardRoot);
1250
+ const mappedImageClass = mapSemanticClasses(classNames.image);
1251
+ const [shortDesc, setShortDesc] = useState(false);
1252
+ const descRef = useRef(null);
1253
+ useEffect(() => {
1254
+ const el = descRef.current;
1255
+ if (!el || !finalDesc) {
1256
+ setShortDesc(false);
1257
+ return;
1258
+ }
1259
+ const style = getComputedStyle(el);
1260
+ const lineHeight = Number.parseFloat(style.lineHeight) || 1.5 * 14;
1261
+ const maxTwoLines = lineHeight * 2;
1262
+ setShortDesc(el.scrollHeight <= maxTwoLines + 1);
1263
+ }, [finalDesc, finalTitle]);
1264
+ if (useDynamicFetch && !isValid) {
1265
+ return null;
1266
+ }
1267
+ if (useDynamicFetch && loading) {
1268
+ return /* @__PURE__ */ jsx(
1269
+ "a",
1270
+ {
1271
+ "data-hide-print": true,
1272
+ ref,
1273
+ href: fullUrl,
1274
+ target: "_blank",
1275
+ rel: "noopener noreferrer",
1276
+ children: /* @__PURE__ */ jsx(LinkCardSkeleton, { source })
1277
+ }
1278
+ );
1279
+ }
1280
+ const hasImage = !!finalImage;
1281
+ const showImagePlaceholder = useDynamicFetch && isError && !hasImage;
1282
+ return /* @__PURE__ */ jsxs(
1283
+ "a",
1284
+ {
1285
+ "data-hide-print": true,
1286
+ ref: useDynamicFetch ? ref : void 0,
1287
+ className: [
1288
+ card,
1289
+ semanticClassNames.card,
1290
+ typeStyleClass,
1291
+ typeSemanticClass,
1292
+ shortDesc && cardShortDesc,
1293
+ shortDesc && semanticClassNames.cardShortDesc,
1294
+ useDynamicFetch && (loading || isError) && cardSkeleton,
1295
+ useDynamicFetch && (loading || isError) && semanticClassNames.cardSkeleton,
1296
+ useDynamicFetch && isError && cardError,
1297
+ useDynamicFetch && isError && semanticClassNames.cardError,
1298
+ "not-prose",
1299
+ className,
1300
+ mappedCardRootClass
1301
+ ].filter(Boolean).join(" "),
1302
+ "data-source": source || void 0,
1303
+ href: useDynamicFetch ? fullUrl : url,
1304
+ target: "_blank",
1305
+ rel: "noopener noreferrer",
1306
+ style: {
1307
+ borderColor: finalColor ? `${finalColor}30` : void 0
1308
+ },
1309
+ children: [
1310
+ finalColor && /* @__PURE__ */ jsx(
1311
+ "div",
1312
+ {
1313
+ className: `${bg} ${semanticClassNames.bg}`,
1314
+ style: {
1315
+ backgroundColor: finalColor,
1316
+ opacity: 0.04
1317
+ }
1318
+ }
1319
+ ),
1320
+ hasImage || showImagePlaceholder ? /* @__PURE__ */ jsx(
1321
+ "span",
1322
+ {
1323
+ className: [
1324
+ image,
1325
+ semanticClassNames.image,
1326
+ mappedImageClass
1327
+ ].filter(Boolean).join(" "),
1328
+ "data-image": finalImage || "",
1329
+ style: {
1330
+ backgroundImage: finalImage ? `url(${finalImage})` : void 0
1331
+ }
1332
+ }
1333
+ ) : /* @__PURE__ */ jsx(FallbackIcon, { favicon }),
1334
+ /* @__PURE__ */ jsxs(
1335
+ "span",
1336
+ {
1337
+ className: `${content} ${semanticClassNames.content}`,
1338
+ children: [
1339
+ /* @__PURE__ */ jsx("span", { className: `${title} ${semanticClassNames.title}`, children: /* @__PURE__ */ jsx(
1340
+ "span",
1341
+ {
1342
+ className: `${titleText} ${semanticClassNames.titleText}`,
1343
+ children: finalTitle
1344
+ }
1345
+ ) }),
1346
+ finalDesc && /* @__PURE__ */ jsx(
1347
+ "span",
1348
+ {
1349
+ ref: descRef,
1350
+ className: `${desc} ${semanticClassNames.desc}`,
1351
+ children: finalDesc
1352
+ }
1353
+ )
1354
+ ]
1355
+ }
1356
+ )
1357
+ ]
1358
+ }
1359
+ );
1360
+ };
1361
+ export {
1362
+ editWrapper as A,
1363
+ semanticClassNames as B,
1364
+ editPanel as C,
1365
+ editUrlRow as D,
1366
+ editLinkIcon as E,
1367
+ editInput as F,
1368
+ editActions as G,
1369
+ editActionButton as H,
1370
+ editActionButtonEnd as I,
1371
+ LanguageToColorMap as L,
1372
+ LinkCardFetchProvider as a,
1373
+ LinkCardRenderer as b,
1374
+ LinkCardSkeleton as c,
1375
+ arxivPlugin as d,
1376
+ bangumiPlugin as e,
1377
+ camelcaseKeys as f,
1378
+ createMxSpacePlugin as g,
1379
+ fetchGitHubApi as h,
1380
+ fetchJsonWithContext as i,
1381
+ generateColor as j,
1382
+ getPluginByName as k,
1383
+ githubCommitPlugin as l,
1384
+ githubDiscussionPlugin as m,
1385
+ githubIssuePlugin as n,
1386
+ githubPrPlugin as o,
1387
+ githubRepoPlugin as p,
1388
+ leetcodePlugin as q,
1389
+ matchUrl as r,
1390
+ mxSpacePlugin as s,
1391
+ neteaseMusicPlugin as t,
1392
+ pluginMap as u,
1393
+ plugins as v,
1394
+ qqMusicPlugin as w,
1395
+ tmdbPlugin as x,
1396
+ useLinkCardFetchContext as y,
1397
+ useUrlMatcher as z
1398
+ };