@ox-content/vite-plugin 1.0.0-alpha.0 → 2.0.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 (58) hide show
  1. package/dist/chunk.cjs +39 -49
  2. package/dist/github.cjs +323 -3
  3. package/dist/github.cjs.map +1 -0
  4. package/dist/github.mjs +2 -0
  5. package/dist/{github2.js → github2.mjs} +2 -3
  6. package/dist/github2.mjs.map +1 -0
  7. package/dist/index.cjs +1371 -598
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.cts +114 -69
  10. package/dist/index.d.cts.map +1 -1
  11. package/dist/index.d.mts +1960 -0
  12. package/dist/index.d.mts.map +1 -0
  13. package/dist/{index.js → index.mjs} +1383 -623
  14. package/dist/index.mjs.map +1 -0
  15. package/dist/mermaid.cjs +115 -3
  16. package/dist/mermaid.cjs.map +1 -0
  17. package/dist/{mermaid2.js → mermaid.mjs} +14 -6
  18. package/dist/mermaid.mjs.map +1 -0
  19. package/dist/mermaid2.mjs +2 -0
  20. package/dist/ogp.cjs +316 -3
  21. package/dist/ogp.cjs.map +1 -0
  22. package/dist/ogp.mjs +2 -0
  23. package/dist/{ogp2.js → ogp2.mjs} +2 -3
  24. package/dist/ogp2.mjs.map +1 -0
  25. package/dist/tabs.cjs +212 -3
  26. package/dist/tabs.cjs.map +1 -0
  27. package/dist/tabs.mjs +2 -0
  28. package/dist/{tabs2.js → tabs2.mjs} +2 -3
  29. package/dist/tabs2.mjs.map +1 -0
  30. package/dist/youtube.cjs +135 -3
  31. package/dist/youtube.cjs.map +1 -0
  32. package/dist/youtube.mjs +2 -0
  33. package/dist/{youtube2.js → youtube2.mjs} +2 -3
  34. package/dist/youtube2.mjs.map +1 -0
  35. package/package.json +61 -56
  36. package/dist/github.js +0 -3
  37. package/dist/github2.cjs +0 -313
  38. package/dist/github2.cjs.map +0 -1
  39. package/dist/github2.js.map +0 -1
  40. package/dist/index.d.ts +0 -1915
  41. package/dist/index.d.ts.map +0 -1
  42. package/dist/index.js.map +0 -1
  43. package/dist/mermaid.js +0 -3
  44. package/dist/mermaid2.cjs +0 -92
  45. package/dist/mermaid2.cjs.map +0 -1
  46. package/dist/mermaid2.js.map +0 -1
  47. package/dist/ogp.js +0 -3
  48. package/dist/ogp2.cjs +0 -306
  49. package/dist/ogp2.cjs.map +0 -1
  50. package/dist/ogp2.js.map +0 -1
  51. package/dist/tabs.js +0 -3
  52. package/dist/tabs2.cjs +0 -203
  53. package/dist/tabs2.cjs.map +0 -1
  54. package/dist/tabs2.js.map +0 -1
  55. package/dist/youtube.js +0 -3
  56. package/dist/youtube2.cjs +0 -127
  57. package/dist/youtube2.cjs.map +0 -1
  58. package/dist/youtube2.js.map +0 -1
package/dist/chunk.cjs CHANGED
@@ -1,4 +1,4 @@
1
- //#region rolldown:runtime
1
+ //#region \0rolldown/runtime.js
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -7,30 +7,22 @@ var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
8
  var __esmMin = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
9
9
  var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
10
- var __exportAll = (all, symbols) => {
10
+ var __exportAll = (all, no_symbols) => {
11
11
  let target = {};
12
- for (var name in all) {
13
- __defProp(target, name, {
14
- get: all[name],
15
- enumerable: true
16
- });
17
- }
18
- if (symbols) {
19
- __defProp(target, Symbol.toStringTag, { value: "Module" });
20
- }
12
+ for (var name in all) __defProp(target, name, {
13
+ get: all[name],
14
+ enumerable: true
15
+ });
16
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
21
17
  return target;
22
18
  };
23
19
  var __copyProps = (to, from, except, desc) => {
24
- if (from && typeof from === "object" || typeof from === "function") {
25
- for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
26
- key = keys[i];
27
- if (!__hasOwnProp.call(to, key) && key !== except) {
28
- __defProp(to, key, {
29
- get: ((k) => from[k]).bind(null, key),
30
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
31
- });
32
- }
33
- }
20
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
21
+ key = keys[i];
22
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
23
+ get: ((k) => from[k]).bind(null, key),
24
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
25
+ });
34
26
  }
35
27
  return to;
36
28
  };
@@ -39,36 +31,34 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
39
31
  enumerable: true
40
32
  }) : target, mod));
41
33
  var __toCommonJS = (mod) => __hasOwnProp.call(mod, "module.exports") ? mod["module.exports"] : __copyProps(__defProp({}, "__esModule", { value: true }), mod);
42
-
43
34
  //#endregion
44
-
45
- Object.defineProperty(exports, '__commonJSMin', {
46
- enumerable: true,
47
- get: function () {
48
- return __commonJSMin;
49
- }
35
+ Object.defineProperty(exports, "__commonJSMin", {
36
+ enumerable: true,
37
+ get: function() {
38
+ return __commonJSMin;
39
+ }
50
40
  });
51
- Object.defineProperty(exports, '__esmMin', {
52
- enumerable: true,
53
- get: function () {
54
- return __esmMin;
55
- }
41
+ Object.defineProperty(exports, "__esmMin", {
42
+ enumerable: true,
43
+ get: function() {
44
+ return __esmMin;
45
+ }
56
46
  });
57
- Object.defineProperty(exports, '__exportAll', {
58
- enumerable: true,
59
- get: function () {
60
- return __exportAll;
61
- }
47
+ Object.defineProperty(exports, "__exportAll", {
48
+ enumerable: true,
49
+ get: function() {
50
+ return __exportAll;
51
+ }
62
52
  });
63
- Object.defineProperty(exports, '__toCommonJS', {
64
- enumerable: true,
65
- get: function () {
66
- return __toCommonJS;
67
- }
53
+ Object.defineProperty(exports, "__toCommonJS", {
54
+ enumerable: true,
55
+ get: function() {
56
+ return __toCommonJS;
57
+ }
58
+ });
59
+ Object.defineProperty(exports, "__toESM", {
60
+ enumerable: true,
61
+ get: function() {
62
+ return __toESM;
63
+ }
68
64
  });
69
- Object.defineProperty(exports, '__toESM', {
70
- enumerable: true,
71
- get: function () {
72
- return __toESM;
73
- }
74
- });
package/dist/github.cjs CHANGED
@@ -1,4 +1,324 @@
1
- const require_chunk = require('./chunk.cjs');
2
- const require_github = require('./github2.cjs');
1
+ const require_chunk = require("./chunk.cjs");
2
+ let unified = require("unified");
3
+ let rehype_parse = require("rehype-parse");
4
+ rehype_parse = require_chunk.__toESM(rehype_parse);
5
+ let rehype_stringify = require("rehype-stringify");
6
+ rehype_stringify = require_chunk.__toESM(rehype_stringify);
7
+ //#region src/plugins/github.ts
8
+ /**
9
+ * GitHub Plugin - Repository card embedding
10
+ *
11
+ * Transforms <GitHub> components into static repository cards
12
+ * by fetching data from GitHub API at build time.
13
+ */
14
+ var github_exports = /* @__PURE__ */ require_chunk.__exportAll({
15
+ collectGitHubRepos: () => collectGitHubRepos,
16
+ fetchRepoData: () => fetchRepoData,
17
+ prefetchGitHubRepos: () => prefetchGitHubRepos,
18
+ transformGitHub: () => transformGitHub
19
+ });
20
+ const defaultOptions = {
21
+ token: "",
22
+ cache: true,
23
+ cacheTTL: 36e5
24
+ };
25
+ const repoCache = /* @__PURE__ */ new Map();
26
+ /**
27
+ * Get element attribute value.
28
+ */
29
+ function getAttribute(el, name) {
30
+ const value = el.properties?.[name];
31
+ if (typeof value === "string") return value;
32
+ if (Array.isArray(value)) return value.join(" ");
33
+ }
34
+ /**
35
+ * Format number with K/M suffix.
36
+ */
37
+ function formatNumber(num) {
38
+ if (num >= 1e6) return `${(num / 1e6).toFixed(1)}M`;
39
+ if (num >= 1e3) return `${(num / 1e3).toFixed(1)}k`;
40
+ return String(num);
41
+ }
42
+ /**
43
+ * Fetch repository data from GitHub API.
44
+ */
45
+ async function fetchRepoData(repo, options) {
46
+ if (options.cache) {
47
+ const cached = repoCache.get(repo);
48
+ if (cached && Date.now() - cached.timestamp < options.cacheTTL) return cached.data;
49
+ }
50
+ try {
51
+ const headers = {
52
+ Accept: "application/vnd.github.v3+json",
53
+ "User-Agent": "ox-content-github-plugin"
54
+ };
55
+ if (options.token) headers.Authorization = `Bearer ${options.token}`;
56
+ const response = await fetch(`https://api.github.com/repos/${repo}`, { headers });
57
+ if (!response.ok) {
58
+ console.warn(`Failed to fetch GitHub repo ${repo}: ${response.status}`);
59
+ return null;
60
+ }
61
+ const data = await response.json();
62
+ if (options.cache) repoCache.set(repo, {
63
+ data,
64
+ timestamp: Date.now()
65
+ });
66
+ return data;
67
+ } catch (error) {
68
+ console.warn(`Error fetching GitHub repo ${repo}:`, error);
69
+ return null;
70
+ }
71
+ }
72
+ /**
73
+ * Create GitHub card element from repo data.
74
+ */
75
+ function createGitHubCard(repoData) {
76
+ const statsChildren = [];
77
+ if (repoData.language) statsChildren.push({
78
+ type: "element",
79
+ tagName: "span",
80
+ properties: { className: ["ox-github-language"] },
81
+ children: [{
82
+ type: "element",
83
+ tagName: "span",
84
+ properties: {
85
+ className: ["ox-github-language-color"],
86
+ "data-lang": repoData.language.toLowerCase()
87
+ },
88
+ children: []
89
+ }, {
90
+ type: "text",
91
+ value: repoData.language
92
+ }]
93
+ });
94
+ statsChildren.push({
95
+ type: "element",
96
+ tagName: "span",
97
+ properties: { className: ["ox-github-stat"] },
98
+ children: [{
99
+ type: "element",
100
+ tagName: "svg",
101
+ properties: {
102
+ viewBox: "0 0 16 16",
103
+ fill: "currentColor"
104
+ },
105
+ children: [{
106
+ type: "element",
107
+ tagName: "path",
108
+ properties: { d: "M8 .25a.75.75 0 0 1 .673.418l1.882 3.815 4.21.612a.75.75 0 0 1 .416 1.279l-3.046 2.97.719 4.192a.751.751 0 0 1-1.088.791L8 12.347l-3.766 1.98a.75.75 0 0 1-1.088-.79l.72-4.194L.818 6.374a.75.75 0 0 1 .416-1.28l4.21-.611L7.327.668A.75.75 0 0 1 8 .25Z" },
109
+ children: []
110
+ }]
111
+ }, {
112
+ type: "text",
113
+ value: formatNumber(repoData.stargazers_count)
114
+ }]
115
+ });
116
+ statsChildren.push({
117
+ type: "element",
118
+ tagName: "span",
119
+ properties: { className: ["ox-github-stat"] },
120
+ children: [{
121
+ type: "element",
122
+ tagName: "svg",
123
+ properties: {
124
+ viewBox: "0 0 16 16",
125
+ fill: "currentColor"
126
+ },
127
+ children: [{
128
+ type: "element",
129
+ tagName: "path",
130
+ properties: { d: "M5 5.372v.878c0 .414.336.75.75.75h4.5a.75.75 0 0 0 .75-.75v-.878a2.25 2.25 0 1 1 1.5 0v.878a2.25 2.25 0 0 1-2.25 2.25h-1.5v2.128a2.251 2.251 0 1 1-1.5 0V8.5h-1.5A2.25 2.25 0 0 1 3.5 6.25v-.878a2.25 2.25 0 1 1 1.5 0ZM5 3.25a.75.75 0 1 0-1.5 0 .75.75 0 0 0 1.5 0Zm6.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5Zm-3 8.75a.75.75 0 1 0-1.5 0 .75.75 0 0 0 1.5 0Z" },
131
+ children: []
132
+ }]
133
+ }, {
134
+ type: "text",
135
+ value: formatNumber(repoData.forks_count)
136
+ }]
137
+ });
138
+ return {
139
+ type: "element",
140
+ tagName: "a",
141
+ properties: {
142
+ className: ["ox-github-card"],
143
+ href: repoData.html_url,
144
+ target: "_blank",
145
+ rel: "noopener noreferrer"
146
+ },
147
+ children: [
148
+ {
149
+ type: "element",
150
+ tagName: "div",
151
+ properties: { className: ["ox-github-header"] },
152
+ children: [{
153
+ type: "element",
154
+ tagName: "svg",
155
+ properties: {
156
+ className: ["ox-github-icon"],
157
+ viewBox: "0 0 16 16",
158
+ fill: "currentColor"
159
+ },
160
+ children: [{
161
+ type: "element",
162
+ tagName: "path",
163
+ properties: { d: "M2 2.5A2.5 2.5 0 0 1 4.5 0h8.75a.75.75 0 0 1 .75.75v12.5a.75.75 0 0 1-.75.75h-2.5a.75.75 0 0 1 0-1.5h1.75v-2h-8a1 1 0 0 0-.714 1.7.75.75 0 1 1-1.072 1.05A2.495 2.495 0 0 1 2 11.5Zm10.5-1h-8a1 1 0 0 0-1 1v6.708A2.486 2.486 0 0 1 4.5 9h8ZM5 12.25a.25.25 0 0 1 .25-.25h3.5a.25.25 0 0 1 .25.25v3.25a.25.25 0 0 1-.4.2l-1.45-1.087a.249.249 0 0 0-.3 0L5.4 15.7a.25.25 0 0 1-.4-.2Z" },
164
+ children: []
165
+ }]
166
+ }, {
167
+ type: "element",
168
+ tagName: "span",
169
+ properties: { className: ["ox-github-repo"] },
170
+ children: [{
171
+ type: "text",
172
+ value: repoData.full_name
173
+ }]
174
+ }]
175
+ },
176
+ ...repoData.description ? [{
177
+ type: "element",
178
+ tagName: "p",
179
+ properties: { className: ["ox-github-description"] },
180
+ children: [{
181
+ type: "text",
182
+ value: repoData.description
183
+ }]
184
+ }] : [],
185
+ {
186
+ type: "element",
187
+ tagName: "div",
188
+ properties: { className: ["ox-github-stats"] },
189
+ children: statsChildren
190
+ }
191
+ ]
192
+ };
193
+ }
194
+ /**
195
+ * Create fallback element when repo data is unavailable.
196
+ */
197
+ function createFallbackCard(repo) {
198
+ return {
199
+ type: "element",
200
+ tagName: "a",
201
+ properties: {
202
+ className: ["ox-github-card", "error"],
203
+ href: `https://github.com/${repo}`,
204
+ target: "_blank",
205
+ rel: "noopener noreferrer"
206
+ },
207
+ children: [{
208
+ type: "element",
209
+ tagName: "div",
210
+ properties: { className: ["ox-github-header"] },
211
+ children: [{
212
+ type: "element",
213
+ tagName: "svg",
214
+ properties: {
215
+ className: ["ox-github-icon"],
216
+ viewBox: "0 0 16 16",
217
+ fill: "currentColor"
218
+ },
219
+ children: [{
220
+ type: "element",
221
+ tagName: "path",
222
+ properties: { d: "M8 0c4.42 0 8 3.58 8 8a8.013 8.013 0 0 1-5.45 7.59c-.4.08-.55-.17-.55-.38 0-.27.01-1.13.01-2.2 0-.75-.25-1.23-.54-1.48 1.78-.2 3.65-.88 3.65-3.95 0-.88-.31-1.59-.82-2.15.08-.2.36-1.02-.08-2.12 0 0-.67-.22-2.2.82-.64-.18-1.32-.27-2-.27-.68 0-1.36.09-2 .27-1.53-1.03-2.2-.82-2.2-.82-.44 1.1-.16 1.92-.08 2.12-.51.56-.82 1.28-.82 2.15 0 3.06 1.86 3.75 3.64 3.95-.23.2-.44.55-.51 1.07-.46.21-1.61.55-2.33-.66-.15-.24-.6-.83-1.23-.82-.67.01-.27.38.01.53.34.19.73.9.82 1.13.16.45.68 1.31 2.69.94 0 .67.01 1.3.01 1.49 0 .21-.15.45-.55.38A7.995 7.995 0 0 1 0 8c0-4.42 3.58-8 8-8Z" },
223
+ children: []
224
+ }]
225
+ }, {
226
+ type: "element",
227
+ tagName: "span",
228
+ properties: { className: ["ox-github-repo"] },
229
+ children: [{
230
+ type: "text",
231
+ value: repo
232
+ }]
233
+ }]
234
+ }]
235
+ };
236
+ }
237
+ /**
238
+ * Collect all GitHub repos from HTML for pre-fetching.
239
+ */
240
+ async function collectGitHubRepos(html) {
241
+ const repos = [];
242
+ const repoPattern = /<github[^>]*\s+repo=["']([^"']+)["']/gi;
243
+ let match;
244
+ while ((match = repoPattern.exec(html)) !== null) repos.push(match[1]);
245
+ return repos;
246
+ }
247
+ /**
248
+ * Pre-fetch all GitHub repos data.
249
+ */
250
+ async function prefetchGitHubRepos(repos, options) {
251
+ const mergedOptions = {
252
+ ...defaultOptions,
253
+ ...options
254
+ };
255
+ const results = /* @__PURE__ */ new Map();
256
+ await Promise.all(repos.map(async (repo) => {
257
+ const data = await fetchRepoData(repo, mergedOptions);
258
+ results.set(repo, data);
259
+ }));
260
+ return results;
261
+ }
262
+ /**
263
+ * Rehype plugin to transform GitHub components.
264
+ */
265
+ function rehypeGitHub(repoDataMap) {
266
+ return (tree) => {
267
+ const visit = (node) => {
268
+ if ("children" in node) for (let i = 0; i < node.children.length; i++) {
269
+ const child = node.children[i];
270
+ if (child.type === "element") if (child.tagName.toLowerCase() === "github") {
271
+ const repo = getAttribute(child, "repo");
272
+ if (repo) {
273
+ const repoData = repoDataMap.get(repo);
274
+ const cardElement = repoData ? createGitHubCard(repoData) : createFallbackCard(repo);
275
+ node.children[i] = cardElement;
276
+ }
277
+ } else visit(child);
278
+ }
279
+ };
280
+ visit(tree);
281
+ };
282
+ }
283
+ /**
284
+ * Transform GitHub components in HTML.
285
+ */
286
+ async function transformGitHub(html, repoDataMap, options) {
287
+ let dataMap = repoDataMap;
288
+ if (!dataMap) dataMap = await prefetchGitHubRepos(await collectGitHubRepos(html), options);
289
+ const result = await (0, unified.unified)().use(rehype_parse.default, { fragment: true }).use(rehypeGitHub, dataMap).use(rehype_stringify.default).process(html);
290
+ return String(result);
291
+ }
292
+ //#endregion
293
+ Object.defineProperty(exports, "collectGitHubRepos", {
294
+ enumerable: true,
295
+ get: function() {
296
+ return collectGitHubRepos;
297
+ }
298
+ });
299
+ Object.defineProperty(exports, "fetchRepoData", {
300
+ enumerable: true,
301
+ get: function() {
302
+ return fetchRepoData;
303
+ }
304
+ });
305
+ Object.defineProperty(exports, "github_exports", {
306
+ enumerable: true,
307
+ get: function() {
308
+ return github_exports;
309
+ }
310
+ });
311
+ Object.defineProperty(exports, "prefetchGitHubRepos", {
312
+ enumerable: true,
313
+ get: function() {
314
+ return prefetchGitHubRepos;
315
+ }
316
+ });
317
+ Object.defineProperty(exports, "transformGitHub", {
318
+ enumerable: true,
319
+ get: function() {
320
+ return transformGitHub;
321
+ }
322
+ });
3
323
 
4
- exports.transformGitHub = require_github.transformGitHub;
324
+ //# sourceMappingURL=github.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github.cjs","names":["rehypeParse","rehypeStringify"],"sources":["../src/plugins/github.ts"],"sourcesContent":["/**\n * GitHub Plugin - Repository card embedding\n *\n * Transforms <GitHub> components into static repository cards\n * by fetching data from GitHub API at build time.\n */\n\nimport { unified } from \"unified\";\nimport rehypeParse from \"rehype-parse\";\nimport rehypeStringify from \"rehype-stringify\";\nimport type { Root, Element } from \"hast\";\n\nexport interface GitHubRepoData {\n name: string;\n full_name: string;\n description: string | null;\n html_url: string;\n stargazers_count: number;\n forks_count: number;\n language: string | null;\n owner: {\n login: string;\n avatar_url: string;\n };\n}\n\nexport interface GitHubOptions {\n /** GitHub API token for higher rate limits. */\n token?: string;\n /** Cache fetched data. Default: true */\n cache?: boolean;\n /** Cache TTL in milliseconds. Default: 3600000 (1 hour) */\n cacheTTL?: number;\n}\n\nconst defaultOptions: Required<GitHubOptions> = {\n token: \"\",\n cache: true,\n cacheTTL: 3600000,\n};\n\n// Simple in-memory cache\nconst repoCache = new Map<string, { data: GitHubRepoData; timestamp: number }>();\n\n/**\n * Get element attribute value.\n */\nfunction getAttribute(el: Element, name: string): string | undefined {\n const value = el.properties?.[name];\n if (typeof value === \"string\") return value;\n if (Array.isArray(value)) return value.join(\" \");\n return undefined;\n}\n\n/**\n * Format number with K/M suffix.\n */\nfunction formatNumber(num: number): string {\n if (num >= 1000000) {\n return `${(num / 1000000).toFixed(1)}M`;\n }\n if (num >= 1000) {\n return `${(num / 1000).toFixed(1)}k`;\n }\n return String(num);\n}\n\n/**\n * Fetch repository data from GitHub API.\n */\nexport async function fetchRepoData(\n repo: string,\n options: Required<GitHubOptions>,\n): Promise<GitHubRepoData | null> {\n // Check cache\n if (options.cache) {\n const cached = repoCache.get(repo);\n if (cached && Date.now() - cached.timestamp < options.cacheTTL) {\n return cached.data;\n }\n }\n\n try {\n const headers: Record<string, string> = {\n Accept: \"application/vnd.github.v3+json\",\n \"User-Agent\": \"ox-content-github-plugin\",\n };\n\n if (options.token) {\n headers.Authorization = `Bearer ${options.token}`;\n }\n\n const response = await fetch(`https://api.github.com/repos/${repo}`, { headers });\n\n if (!response.ok) {\n console.warn(`Failed to fetch GitHub repo ${repo}: ${response.status}`);\n return null;\n }\n\n const data = (await response.json()) as GitHubRepoData;\n\n // Cache the result\n if (options.cache) {\n repoCache.set(repo, { data, timestamp: Date.now() });\n }\n\n return data;\n } catch (error) {\n console.warn(`Error fetching GitHub repo ${repo}:`, error);\n return null;\n }\n}\n\n/**\n * Create GitHub card element from repo data.\n */\nfunction createGitHubCard(repoData: GitHubRepoData): Element {\n const statsChildren: Element[\"children\"] = [];\n\n // Language\n if (repoData.language) {\n statsChildren.push({\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-language\"] },\n children: [\n {\n type: \"element\",\n tagName: \"span\",\n properties: {\n className: [\"ox-github-language-color\"],\n \"data-lang\": repoData.language.toLowerCase(),\n },\n children: [],\n },\n { type: \"text\", value: repoData.language },\n ],\n });\n }\n\n // Stars\n statsChildren.push({\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-stat\"] },\n children: [\n {\n type: \"element\",\n tagName: \"svg\",\n properties: {\n viewBox: \"0 0 16 16\",\n fill: \"currentColor\",\n },\n children: [\n {\n type: \"element\",\n tagName: \"path\",\n properties: {\n d: \"M8 .25a.75.75 0 0 1 .673.418l1.882 3.815 4.21.612a.75.75 0 0 1 .416 1.279l-3.046 2.97.719 4.192a.751.751 0 0 1-1.088.791L8 12.347l-3.766 1.98a.75.75 0 0 1-1.088-.79l.72-4.194L.818 6.374a.75.75 0 0 1 .416-1.28l4.21-.611L7.327.668A.75.75 0 0 1 8 .25Z\",\n },\n children: [],\n },\n ],\n },\n { type: \"text\", value: formatNumber(repoData.stargazers_count) },\n ],\n });\n\n // Forks\n statsChildren.push({\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-stat\"] },\n children: [\n {\n type: \"element\",\n tagName: \"svg\",\n properties: {\n viewBox: \"0 0 16 16\",\n fill: \"currentColor\",\n },\n children: [\n {\n type: \"element\",\n tagName: \"path\",\n properties: {\n d: \"M5 5.372v.878c0 .414.336.75.75.75h4.5a.75.75 0 0 0 .75-.75v-.878a2.25 2.25 0 1 1 1.5 0v.878a2.25 2.25 0 0 1-2.25 2.25h-1.5v2.128a2.251 2.251 0 1 1-1.5 0V8.5h-1.5A2.25 2.25 0 0 1 3.5 6.25v-.878a2.25 2.25 0 1 1 1.5 0ZM5 3.25a.75.75 0 1 0-1.5 0 .75.75 0 0 0 1.5 0Zm6.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5Zm-3 8.75a.75.75 0 1 0-1.5 0 .75.75 0 0 0 1.5 0Z\",\n },\n children: [],\n },\n ],\n },\n { type: \"text\", value: formatNumber(repoData.forks_count) },\n ],\n });\n\n return {\n type: \"element\",\n tagName: \"a\",\n properties: {\n className: [\"ox-github-card\"],\n href: repoData.html_url,\n target: \"_blank\",\n rel: \"noopener noreferrer\",\n },\n children: [\n // Header\n {\n type: \"element\",\n tagName: \"div\",\n properties: { className: [\"ox-github-header\"] },\n children: [\n {\n type: \"element\",\n tagName: \"svg\",\n properties: {\n className: [\"ox-github-icon\"],\n viewBox: \"0 0 16 16\",\n fill: \"currentColor\",\n },\n children: [\n {\n type: \"element\",\n tagName: \"path\",\n properties: {\n d: \"M2 2.5A2.5 2.5 0 0 1 4.5 0h8.75a.75.75 0 0 1 .75.75v12.5a.75.75 0 0 1-.75.75h-2.5a.75.75 0 0 1 0-1.5h1.75v-2h-8a1 1 0 0 0-.714 1.7.75.75 0 1 1-1.072 1.05A2.495 2.495 0 0 1 2 11.5Zm10.5-1h-8a1 1 0 0 0-1 1v6.708A2.486 2.486 0 0 1 4.5 9h8ZM5 12.25a.25.25 0 0 1 .25-.25h3.5a.25.25 0 0 1 .25.25v3.25a.25.25 0 0 1-.4.2l-1.45-1.087a.249.249 0 0 0-.3 0L5.4 15.7a.25.25 0 0 1-.4-.2Z\",\n },\n children: [],\n },\n ],\n },\n {\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-repo\"] },\n children: [{ type: \"text\", value: repoData.full_name }],\n },\n ],\n },\n // Description\n ...(repoData.description\n ? [\n {\n type: \"element\" as const,\n tagName: \"p\",\n properties: { className: [\"ox-github-description\"] },\n children: [{ type: \"text\" as const, value: repoData.description }],\n },\n ]\n : []),\n // Stats\n {\n type: \"element\",\n tagName: \"div\",\n properties: { className: [\"ox-github-stats\"] },\n children: statsChildren,\n },\n ],\n };\n}\n\n/**\n * Create fallback element when repo data is unavailable.\n */\nfunction createFallbackCard(repo: string): Element {\n return {\n type: \"element\",\n tagName: \"a\",\n properties: {\n className: [\"ox-github-card\", \"error\"],\n href: `https://github.com/${repo}`,\n target: \"_blank\",\n rel: \"noopener noreferrer\",\n },\n children: [\n {\n type: \"element\",\n tagName: \"div\",\n properties: { className: [\"ox-github-header\"] },\n children: [\n {\n type: \"element\",\n tagName: \"svg\",\n properties: {\n className: [\"ox-github-icon\"],\n viewBox: \"0 0 16 16\",\n fill: \"currentColor\",\n },\n children: [\n {\n type: \"element\",\n tagName: \"path\",\n properties: {\n d: \"M8 0c4.42 0 8 3.58 8 8a8.013 8.013 0 0 1-5.45 7.59c-.4.08-.55-.17-.55-.38 0-.27.01-1.13.01-2.2 0-.75-.25-1.23-.54-1.48 1.78-.2 3.65-.88 3.65-3.95 0-.88-.31-1.59-.82-2.15.08-.2.36-1.02-.08-2.12 0 0-.67-.22-2.2.82-.64-.18-1.32-.27-2-.27-.68 0-1.36.09-2 .27-1.53-1.03-2.2-.82-2.2-.82-.44 1.1-.16 1.92-.08 2.12-.51.56-.82 1.28-.82 2.15 0 3.06 1.86 3.75 3.64 3.95-.23.2-.44.55-.51 1.07-.46.21-1.61.55-2.33-.66-.15-.24-.6-.83-1.23-.82-.67.01-.27.38.01.53.34.19.73.9.82 1.13.16.45.68 1.31 2.69.94 0 .67.01 1.3.01 1.49 0 .21-.15.45-.55.38A7.995 7.995 0 0 1 0 8c0-4.42 3.58-8 8-8Z\",\n },\n children: [],\n },\n ],\n },\n {\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-repo\"] },\n children: [{ type: \"text\", value: repo }],\n },\n ],\n },\n ],\n };\n}\n\n/**\n * Collect all GitHub repos from HTML for pre-fetching.\n */\nexport async function collectGitHubRepos(html: string): Promise<string[]> {\n const repos: string[] = [];\n const repoPattern = /<github[^>]*\\s+repo=[\"']([^\"']+)[\"']/gi;\n\n let match;\n while ((match = repoPattern.exec(html)) !== null) {\n repos.push(match[1]);\n }\n\n return repos;\n}\n\n/**\n * Pre-fetch all GitHub repos data.\n */\nexport async function prefetchGitHubRepos(\n repos: string[],\n options?: GitHubOptions,\n): Promise<Map<string, GitHubRepoData | null>> {\n const mergedOptions = { ...defaultOptions, ...options };\n const results = new Map<string, GitHubRepoData | null>();\n\n await Promise.all(\n repos.map(async (repo) => {\n const data = await fetchRepoData(repo, mergedOptions);\n results.set(repo, data);\n }),\n );\n\n return results;\n}\n\n/**\n * Rehype plugin to transform GitHub components.\n */\nfunction rehypeGitHub(repoDataMap: Map<string, GitHubRepoData | null>) {\n return (tree: Root) => {\n const visit = (node: Root | Element) => {\n if (\"children\" in node) {\n for (let i = 0; i < node.children.length; i++) {\n const child = node.children[i];\n\n if (child.type === \"element\") {\n // Check for <GitHub> component\n if (child.tagName.toLowerCase() === \"github\") {\n const repo = getAttribute(child, \"repo\");\n\n if (repo) {\n const repoData = repoDataMap.get(repo);\n const cardElement = repoData\n ? createGitHubCard(repoData)\n : createFallbackCard(repo);\n node.children[i] = cardElement;\n }\n } else {\n visit(child);\n }\n }\n }\n }\n };\n\n visit(tree);\n };\n}\n\n/**\n * Transform GitHub components in HTML.\n */\nexport async function transformGitHub(\n html: string,\n repoDataMap?: Map<string, GitHubRepoData | null>,\n options?: GitHubOptions,\n): Promise<string> {\n // If no pre-fetched data, collect and fetch\n let dataMap = repoDataMap;\n if (!dataMap) {\n const repos = await collectGitHubRepos(html);\n dataMap = await prefetchGitHubRepos(repos, options);\n }\n\n const result = await unified()\n .use(rehypeParse, { fragment: true })\n .use(rehypeGitHub, dataMap)\n .use(rehypeStringify)\n .process(html);\n\n return String(result);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAmCA,MAAM,iBAA0C;CAC9C,OAAO;CACP,OAAO;CACP,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ACA,SAC6C;CAC7C,MAAM,gBAAgB;EAAE,GAAG;EAAgB,GAAG;EAAS;CACvD,MAAM,0BAAU,IAAI,KAAoC;AAExD,OAAM,QAAQ,IACZ,MAAM,IAAI,OAAO,SAAS;EACxB,MAAM,OAAO,MAAM,cAAc,MAAM,cAAc;AACrD,UAAQ,IAAI,MAAM,KAAK;GACvB,CACH;AAED,QAAO;;;;;AAMT,SAAS,aAAa,aAAiD;AACrE,SAAQ,SAAe;EACrB,MAAM,SAAS,SAAyB;AACtC,OAAI,cAAc,KAChB,MAAK,IAAI,IAAI,GAAG,IAAI,KAAK,SAAS,QAAQ,KAAK;IAC7C,MAAM,QAAQ,KAAK,SAAS;AAE5B,QAAI,MAAM,SAAS,UAEjB,KAAI,MAAM,QAAQ,aAAa,KAAK,UAAU;KAC5C,MAAM,OAAO,aAAa,OAAO,OAAO;AAExC,SAAI,MAAM;MACR,MAAM,WAAW,YAAY,IAAI,KAAK;MACtC,MAAM,cAAc,WAChB,iBAAiB,SAAS,GAC1B,mBAAmB,KAAK;AAC5B,WAAK,SAAS,KAAK;;UAGrB,OAAM,MAAM;;;AAOtB,QAAM,KAAK;;;;;;AAOf,eAAsB,gBACpB,MACA,aACA,SACiB;CAEjB,IAAI,UAAU;AACd,KAAI,CAAC,QAEH,WAAU,MAAM,oBADF,MAAM,mBAAmB,KAAK,EACD,QAAQ;CAGrD,MAAM,SAAS,OAAA,GAAA,QAAA,UAAe,CAC3B,IAAIA,aAAAA,SAAa,EAAE,UAAU,MAAM,CAAC,CACpC,IAAI,cAAc,QAAQ,CAC1B,IAAIC,iBAAAA,QAAgB,CACpB,QAAQ,KAAK;AAEhB,QAAO,OAAO,OAAO"}
@@ -0,0 +1,2 @@
1
+ import { i as transformGitHub } from "./github2.mjs";
2
+ export { transformGitHub };
@@ -1,7 +1,6 @@
1
1
  import { unified } from "unified";
2
2
  import rehypeParse from "rehype-parse";
3
3
  import rehypeStringify from "rehype-stringify";
4
-
5
4
  //#region src/plugins/github.ts
6
5
  /**
7
6
  * GitHub Plugin - Repository card embedding
@@ -281,7 +280,7 @@ async function transformGitHub(html, repoDataMap, options) {
281
280
  const result = await unified().use(rehypeParse, { fragment: true }).use(rehypeGitHub, dataMap).use(rehypeStringify).process(html);
282
281
  return String(result);
283
282
  }
284
-
285
283
  //#endregion
286
284
  export { transformGitHub as i, fetchRepoData as n, prefetchGitHubRepos as r, collectGitHubRepos as t };
287
- //# sourceMappingURL=github2.js.map
285
+
286
+ //# sourceMappingURL=github2.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github2.mjs","names":[],"sources":["../src/plugins/github.ts"],"sourcesContent":["/**\n * GitHub Plugin - Repository card embedding\n *\n * Transforms <GitHub> components into static repository cards\n * by fetching data from GitHub API at build time.\n */\n\nimport { unified } from \"unified\";\nimport rehypeParse from \"rehype-parse\";\nimport rehypeStringify from \"rehype-stringify\";\nimport type { Root, Element } from \"hast\";\n\nexport interface GitHubRepoData {\n name: string;\n full_name: string;\n description: string | null;\n html_url: string;\n stargazers_count: number;\n forks_count: number;\n language: string | null;\n owner: {\n login: string;\n avatar_url: string;\n };\n}\n\nexport interface GitHubOptions {\n /** GitHub API token for higher rate limits. */\n token?: string;\n /** Cache fetched data. Default: true */\n cache?: boolean;\n /** Cache TTL in milliseconds. Default: 3600000 (1 hour) */\n cacheTTL?: number;\n}\n\nconst defaultOptions: Required<GitHubOptions> = {\n token: \"\",\n cache: true,\n cacheTTL: 3600000,\n};\n\n// Simple in-memory cache\nconst repoCache = new Map<string, { data: GitHubRepoData; timestamp: number }>();\n\n/**\n * Get element attribute value.\n */\nfunction getAttribute(el: Element, name: string): string | undefined {\n const value = el.properties?.[name];\n if (typeof value === \"string\") return value;\n if (Array.isArray(value)) return value.join(\" \");\n return undefined;\n}\n\n/**\n * Format number with K/M suffix.\n */\nfunction formatNumber(num: number): string {\n if (num >= 1000000) {\n return `${(num / 1000000).toFixed(1)}M`;\n }\n if (num >= 1000) {\n return `${(num / 1000).toFixed(1)}k`;\n }\n return String(num);\n}\n\n/**\n * Fetch repository data from GitHub API.\n */\nexport async function fetchRepoData(\n repo: string,\n options: Required<GitHubOptions>,\n): Promise<GitHubRepoData | null> {\n // Check cache\n if (options.cache) {\n const cached = repoCache.get(repo);\n if (cached && Date.now() - cached.timestamp < options.cacheTTL) {\n return cached.data;\n }\n }\n\n try {\n const headers: Record<string, string> = {\n Accept: \"application/vnd.github.v3+json\",\n \"User-Agent\": \"ox-content-github-plugin\",\n };\n\n if (options.token) {\n headers.Authorization = `Bearer ${options.token}`;\n }\n\n const response = await fetch(`https://api.github.com/repos/${repo}`, { headers });\n\n if (!response.ok) {\n console.warn(`Failed to fetch GitHub repo ${repo}: ${response.status}`);\n return null;\n }\n\n const data = (await response.json()) as GitHubRepoData;\n\n // Cache the result\n if (options.cache) {\n repoCache.set(repo, { data, timestamp: Date.now() });\n }\n\n return data;\n } catch (error) {\n console.warn(`Error fetching GitHub repo ${repo}:`, error);\n return null;\n }\n}\n\n/**\n * Create GitHub card element from repo data.\n */\nfunction createGitHubCard(repoData: GitHubRepoData): Element {\n const statsChildren: Element[\"children\"] = [];\n\n // Language\n if (repoData.language) {\n statsChildren.push({\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-language\"] },\n children: [\n {\n type: \"element\",\n tagName: \"span\",\n properties: {\n className: [\"ox-github-language-color\"],\n \"data-lang\": repoData.language.toLowerCase(),\n },\n children: [],\n },\n { type: \"text\", value: repoData.language },\n ],\n });\n }\n\n // Stars\n statsChildren.push({\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-stat\"] },\n children: [\n {\n type: \"element\",\n tagName: \"svg\",\n properties: {\n viewBox: \"0 0 16 16\",\n fill: \"currentColor\",\n },\n children: [\n {\n type: \"element\",\n tagName: \"path\",\n properties: {\n d: \"M8 .25a.75.75 0 0 1 .673.418l1.882 3.815 4.21.612a.75.75 0 0 1 .416 1.279l-3.046 2.97.719 4.192a.751.751 0 0 1-1.088.791L8 12.347l-3.766 1.98a.75.75 0 0 1-1.088-.79l.72-4.194L.818 6.374a.75.75 0 0 1 .416-1.28l4.21-.611L7.327.668A.75.75 0 0 1 8 .25Z\",\n },\n children: [],\n },\n ],\n },\n { type: \"text\", value: formatNumber(repoData.stargazers_count) },\n ],\n });\n\n // Forks\n statsChildren.push({\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-stat\"] },\n children: [\n {\n type: \"element\",\n tagName: \"svg\",\n properties: {\n viewBox: \"0 0 16 16\",\n fill: \"currentColor\",\n },\n children: [\n {\n type: \"element\",\n tagName: \"path\",\n properties: {\n d: \"M5 5.372v.878c0 .414.336.75.75.75h4.5a.75.75 0 0 0 .75-.75v-.878a2.25 2.25 0 1 1 1.5 0v.878a2.25 2.25 0 0 1-2.25 2.25h-1.5v2.128a2.251 2.251 0 1 1-1.5 0V8.5h-1.5A2.25 2.25 0 0 1 3.5 6.25v-.878a2.25 2.25 0 1 1 1.5 0ZM5 3.25a.75.75 0 1 0-1.5 0 .75.75 0 0 0 1.5 0Zm6.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5Zm-3 8.75a.75.75 0 1 0-1.5 0 .75.75 0 0 0 1.5 0Z\",\n },\n children: [],\n },\n ],\n },\n { type: \"text\", value: formatNumber(repoData.forks_count) },\n ],\n });\n\n return {\n type: \"element\",\n tagName: \"a\",\n properties: {\n className: [\"ox-github-card\"],\n href: repoData.html_url,\n target: \"_blank\",\n rel: \"noopener noreferrer\",\n },\n children: [\n // Header\n {\n type: \"element\",\n tagName: \"div\",\n properties: { className: [\"ox-github-header\"] },\n children: [\n {\n type: \"element\",\n tagName: \"svg\",\n properties: {\n className: [\"ox-github-icon\"],\n viewBox: \"0 0 16 16\",\n fill: \"currentColor\",\n },\n children: [\n {\n type: \"element\",\n tagName: \"path\",\n properties: {\n d: \"M2 2.5A2.5 2.5 0 0 1 4.5 0h8.75a.75.75 0 0 1 .75.75v12.5a.75.75 0 0 1-.75.75h-2.5a.75.75 0 0 1 0-1.5h1.75v-2h-8a1 1 0 0 0-.714 1.7.75.75 0 1 1-1.072 1.05A2.495 2.495 0 0 1 2 11.5Zm10.5-1h-8a1 1 0 0 0-1 1v6.708A2.486 2.486 0 0 1 4.5 9h8ZM5 12.25a.25.25 0 0 1 .25-.25h3.5a.25.25 0 0 1 .25.25v3.25a.25.25 0 0 1-.4.2l-1.45-1.087a.249.249 0 0 0-.3 0L5.4 15.7a.25.25 0 0 1-.4-.2Z\",\n },\n children: [],\n },\n ],\n },\n {\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-repo\"] },\n children: [{ type: \"text\", value: repoData.full_name }],\n },\n ],\n },\n // Description\n ...(repoData.description\n ? [\n {\n type: \"element\" as const,\n tagName: \"p\",\n properties: { className: [\"ox-github-description\"] },\n children: [{ type: \"text\" as const, value: repoData.description }],\n },\n ]\n : []),\n // Stats\n {\n type: \"element\",\n tagName: \"div\",\n properties: { className: [\"ox-github-stats\"] },\n children: statsChildren,\n },\n ],\n };\n}\n\n/**\n * Create fallback element when repo data is unavailable.\n */\nfunction createFallbackCard(repo: string): Element {\n return {\n type: \"element\",\n tagName: \"a\",\n properties: {\n className: [\"ox-github-card\", \"error\"],\n href: `https://github.com/${repo}`,\n target: \"_blank\",\n rel: \"noopener noreferrer\",\n },\n children: [\n {\n type: \"element\",\n tagName: \"div\",\n properties: { className: [\"ox-github-header\"] },\n children: [\n {\n type: \"element\",\n tagName: \"svg\",\n properties: {\n className: [\"ox-github-icon\"],\n viewBox: \"0 0 16 16\",\n fill: \"currentColor\",\n },\n children: [\n {\n type: \"element\",\n tagName: \"path\",\n properties: {\n d: \"M8 0c4.42 0 8 3.58 8 8a8.013 8.013 0 0 1-5.45 7.59c-.4.08-.55-.17-.55-.38 0-.27.01-1.13.01-2.2 0-.75-.25-1.23-.54-1.48 1.78-.2 3.65-.88 3.65-3.95 0-.88-.31-1.59-.82-2.15.08-.2.36-1.02-.08-2.12 0 0-.67-.22-2.2.82-.64-.18-1.32-.27-2-.27-.68 0-1.36.09-2 .27-1.53-1.03-2.2-.82-2.2-.82-.44 1.1-.16 1.92-.08 2.12-.51.56-.82 1.28-.82 2.15 0 3.06 1.86 3.75 3.64 3.95-.23.2-.44.55-.51 1.07-.46.21-1.61.55-2.33-.66-.15-.24-.6-.83-1.23-.82-.67.01-.27.38.01.53.34.19.73.9.82 1.13.16.45.68 1.31 2.69.94 0 .67.01 1.3.01 1.49 0 .21-.15.45-.55.38A7.995 7.995 0 0 1 0 8c0-4.42 3.58-8 8-8Z\",\n },\n children: [],\n },\n ],\n },\n {\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-repo\"] },\n children: [{ type: \"text\", value: repo }],\n },\n ],\n },\n ],\n };\n}\n\n/**\n * Collect all GitHub repos from HTML for pre-fetching.\n */\nexport async function collectGitHubRepos(html: string): Promise<string[]> {\n const repos: string[] = [];\n const repoPattern = /<github[^>]*\\s+repo=[\"']([^\"']+)[\"']/gi;\n\n let match;\n while ((match = repoPattern.exec(html)) !== null) {\n repos.push(match[1]);\n }\n\n return repos;\n}\n\n/**\n * Pre-fetch all GitHub repos data.\n */\nexport async function prefetchGitHubRepos(\n repos: string[],\n options?: GitHubOptions,\n): Promise<Map<string, GitHubRepoData | null>> {\n const mergedOptions = { ...defaultOptions, ...options };\n const results = new Map<string, GitHubRepoData | null>();\n\n await Promise.all(\n repos.map(async (repo) => {\n const data = await fetchRepoData(repo, mergedOptions);\n results.set(repo, data);\n }),\n );\n\n return results;\n}\n\n/**\n * Rehype plugin to transform GitHub components.\n */\nfunction rehypeGitHub(repoDataMap: Map<string, GitHubRepoData | null>) {\n return (tree: Root) => {\n const visit = (node: Root | Element) => {\n if (\"children\" in node) {\n for (let i = 0; i < node.children.length; i++) {\n const child = node.children[i];\n\n if (child.type === \"element\") {\n // Check for <GitHub> component\n if (child.tagName.toLowerCase() === \"github\") {\n const repo = getAttribute(child, \"repo\");\n\n if (repo) {\n const repoData = repoDataMap.get(repo);\n const cardElement = repoData\n ? createGitHubCard(repoData)\n : createFallbackCard(repo);\n node.children[i] = cardElement;\n }\n } else {\n visit(child);\n }\n }\n }\n }\n };\n\n visit(tree);\n };\n}\n\n/**\n * Transform GitHub components in HTML.\n */\nexport async function transformGitHub(\n html: string,\n repoDataMap?: Map<string, GitHubRepoData | null>,\n options?: GitHubOptions,\n): Promise<string> {\n // If no pre-fetched data, collect and fetch\n let dataMap = repoDataMap;\n if (!dataMap) {\n const repos = await collectGitHubRepos(html);\n dataMap = await prefetchGitHubRepos(repos, options);\n }\n\n const result = await unified()\n .use(rehypeParse, { fragment: true })\n .use(rehypeGitHub, dataMap)\n .use(rehypeStringify)\n .process(html);\n\n return String(result);\n}\n"],"mappings":";;;;;;;;;;AAmCA,MAAM,iBAA0C;CAC9C,OAAO;CACP,OAAO;CACP,UAAU;CACX;AAGD,MAAM,4BAAY,IAAI,KAA0D;;;;AAKhF,SAAS,aAAa,IAAa,MAAkC;CACnE,MAAM,QAAQ,GAAG,aAAa;AAC9B,KAAI,OAAO,UAAU,SAAU,QAAO;AACtC,KAAI,MAAM,QAAQ,MAAM,CAAE,QAAO,MAAM,KAAK,IAAI;;;;;AAOlD,SAAS,aAAa,KAAqB;AACzC,KAAI,OAAO,IACT,QAAO,IAAI,MAAM,KAAS,QAAQ,EAAE,CAAC;AAEvC,KAAI,OAAO,IACT,QAAO,IAAI,MAAM,KAAM,QAAQ,EAAE,CAAC;AAEpC,QAAO,OAAO,IAAI;;;;;AAMpB,eAAsB,cACpB,MACA,SACgC;AAEhC,KAAI,QAAQ,OAAO;EACjB,MAAM,SAAS,UAAU,IAAI,KAAK;AAClC,MAAI,UAAU,KAAK,KAAK,GAAG,OAAO,YAAY,QAAQ,SACpD,QAAO,OAAO;;AAIlB,KAAI;EACF,MAAM,UAAkC;GACtC,QAAQ;GACR,cAAc;GACf;AAED,MAAI,QAAQ,MACV,SAAQ,gBAAgB,UAAU,QAAQ;EAG5C,MAAM,WAAW,MAAM,MAAM,gC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