@sigx/ssg 0.2.1 → 0.2.2

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,446 @@
1
+ import { D as e, E as t, O as n, T as r, _ as i, b as a, c as o, d as s, h as c, k as l, m as u, n as d, o as f, p, s as m, t as h, u as g, v as _, x as v } from "./virtual-entries-CH-0HuqJ.js";
2
+ import y from "node:path";
3
+ import b from "node:fs";
4
+ import { createHighlighter as x } from "shiki";
5
+ import { visit as S } from "unist-util-visit";
6
+ import { toString as C } from "hast-util-to-string";
7
+ //#region src/mdx/shiki.ts
8
+ var w = null, T = {
9
+ light: "github-light",
10
+ dark: "github-dark",
11
+ langs: [
12
+ "javascript",
13
+ "typescript",
14
+ "jsx",
15
+ "tsx",
16
+ "json",
17
+ "css",
18
+ "html",
19
+ "markdown",
20
+ "bash",
21
+ "shell"
22
+ ]
23
+ };
24
+ async function E(e) {
25
+ if (!w) {
26
+ let t = {
27
+ ...T,
28
+ ...e
29
+ };
30
+ w = x({
31
+ themes: [t.light, t.dark],
32
+ langs: t.langs
33
+ });
34
+ }
35
+ return w;
36
+ }
37
+ async function D(e, t, n, r) {
38
+ let i = await E(n), a = {
39
+ ...T,
40
+ ...n
41
+ }, o = i.getLoadedLanguages().includes(t) ? t : "text", s = i.codeToHtml(e, {
42
+ lang: o,
43
+ themes: {
44
+ light: a.light,
45
+ dark: a.dark
46
+ }
47
+ }), c = r?.filename ?? "", l = r?.live ?? !1, u = r?.tabs, d = u && u.length > 0, f = c ? `<span class="code-window-filename">${A(c)}</span>` : `<span class="code-window-lang">${k(o)}</span>`;
48
+ if (d) {
49
+ let t = O(e), n = u[0], r = u.map((e, t) => {
50
+ let n = e.charAt(0).toUpperCase() + e.slice(1);
51
+ return `<button class="code-window-tab${t === 0 ? " code-window-tab-active" : ""}">${n}</button>`;
52
+ }).join("\n ");
53
+ return `<div
54
+ class="live-preview-island"
55
+ data-island="LivePreview"
56
+ data-island-strategy="visible"
57
+ data-island-props="${A(JSON.stringify({
58
+ code: t,
59
+ highlightedCode: s,
60
+ language: o,
61
+ filename: c,
62
+ tabs: u,
63
+ live: l
64
+ }))}"
65
+ >
66
+ <div class="code-window code-window-live code-window-preview">
67
+ <div class="code-window-header">
68
+ <div class="code-window-header-left">
69
+ <div class="code-window-dots">
70
+ <span class="code-window-dot dot-red"></span>
71
+ <span class="code-window-dot dot-yellow"></span>
72
+ <span class="code-window-dot dot-green"></span>
73
+ </div>
74
+ ${f}
75
+ </div>
76
+ <div class="code-window-tabs">
77
+ ${r}
78
+ </div>
79
+ <button class="code-window-try-live" disabled>⚡ Try Live</button>
80
+ </div>
81
+ <div class="code-window-preview-pane"${n === "preview" ? "" : " style=\"display:none;\""}>
82
+ <div class="code-window-preview-loading">
83
+ <span class="code-window-spinner"></span>
84
+ Loading preview...
85
+ </div>
86
+ </div>
87
+ <div class="code-window-console-pane"${n === "console" ? "" : " style=\"display:none;\""}>
88
+ <div class="code-window-console-empty">No console output</div>
89
+ </div>
90
+ <div class="code-window-content"${n === "code" ? "" : " style=\"display:none;\""}>
91
+ ${s}
92
+ </div>
93
+ </div>
94
+ </div>`;
95
+ }
96
+ let p = l ? `<button class="code-window-try-live" data-live-code="${A(O(e))}" data-lang="${o}" data-filename="${A(c)}" title="Open in Live Playground">⚡ Try Live</button>` : "";
97
+ return `<div class="code-window${l ? " code-window-live" : ""}">
98
+ <div class="code-window-header">
99
+ <div class="code-window-header-left">
100
+ <div class="code-window-dots">
101
+ <span class="code-window-dot dot-red"></span>
102
+ <span class="code-window-dot dot-yellow"></span>
103
+ <span class="code-window-dot dot-green"></span>
104
+ </div>
105
+ ${f}
106
+ </div>
107
+ ${p}
108
+ </div>
109
+ <div class="code-window-content">
110
+ ${s}
111
+ </div>
112
+ </div>`;
113
+ }
114
+ function O(e) {
115
+ return typeof Buffer < "u" ? Buffer.from(e, "utf-8").toString("base64") : btoa(unescape(encodeURIComponent(e)));
116
+ }
117
+ function k(e) {
118
+ return {
119
+ tsx: "TSX",
120
+ jsx: "JSX",
121
+ ts: "TypeScript",
122
+ typescript: "TypeScript",
123
+ js: "JavaScript",
124
+ javascript: "JavaScript",
125
+ css: "CSS",
126
+ html: "HTML",
127
+ json: "JSON",
128
+ bash: "Terminal",
129
+ shell: "Terminal",
130
+ sh: "Terminal",
131
+ md: "Markdown",
132
+ markdown: "Markdown",
133
+ python: "Python",
134
+ py: "Python",
135
+ rust: "Rust",
136
+ go: "Go",
137
+ text: ""
138
+ }[e.toLowerCase()] ?? e.toUpperCase();
139
+ }
140
+ function A(e) {
141
+ return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
142
+ }
143
+ function j(e) {
144
+ return async (t) => {
145
+ let { visit: n } = await import("unist-util-visit"), { fromHtml: r } = await import("hast-util-from-html"), i = [];
146
+ n(t, "element", (e, t, n) => {
147
+ e.tagName === "pre" && e.children?.[0]?.tagName === "code" && i.push({
148
+ node: e,
149
+ parent: n,
150
+ index: t ?? 0
151
+ });
152
+ }), await Promise.all(i.map(async ({ node: t, parent: n, index: i }) => {
153
+ let a = t.children[0], o = (a.properties?.className?.[0] || "").replace(/^language-/, "") || "text", s = a.data?.meta || a.properties?.metastring || "", c = M(s, "filename") || M(s, "title") || "", l = /\blive\b/i.test(s), u = [
154
+ "preview",
155
+ "code",
156
+ "console"
157
+ ], d = [], f = [];
158
+ for (let e of u) {
159
+ let t = RegExp(`\\b${e}\\b`, "i"), n = s.match(t);
160
+ n && n.index !== void 0 && f.push({
161
+ tab: e,
162
+ index: n.index
163
+ });
164
+ }
165
+ f.sort((e, t) => e.index - t.index);
166
+ for (let { tab: e } of f) d.push(e);
167
+ let p = r(await D(N(a).trim(), o, e, {
168
+ filename: c,
169
+ live: l,
170
+ tabs: d.length > 0 ? d : void 0
171
+ }), { fragment: !0 });
172
+ n && typeof i == "number" && p.children.length > 0 && (n.children[i] = p.children[0]);
173
+ }));
174
+ };
175
+ }
176
+ function M(e, t) {
177
+ if (!e) return null;
178
+ let n = RegExp(`${t}=["']?([^"'\\s]+)["']?`, "i"), r = e.match(n);
179
+ return r ? r[1] : null;
180
+ }
181
+ function N(e) {
182
+ return e.type === "text" ? e.value : e.children ? e.children.map(N).join("") : "";
183
+ }
184
+ //#endregion
185
+ //#region src/mdx/rehype-headings.ts
186
+ function P(e = {}) {
187
+ let { minLevel: t = 2, maxLevel: n = 3 } = e;
188
+ return (e, r) => {
189
+ let i = [];
190
+ S(e, "element", (e) => {
191
+ let r = /^h([1-6])$/.exec(e.tagName);
192
+ if (!r) return;
193
+ let a = parseInt(r[1], 10);
194
+ if (a < t || a > n) return;
195
+ let o = e.properties?.id;
196
+ if (!o) return;
197
+ let s = C(e).trim();
198
+ s && i.push({
199
+ id: o,
200
+ text: s,
201
+ level: a
202
+ });
203
+ }), r.data = r.data || {}, r.data.headings = i;
204
+ };
205
+ }
206
+ //#endregion
207
+ //#region src/mdx/plugin.ts
208
+ function F(n = {}) {
209
+ let { markdown: r = {} } = n, i, a;
210
+ return {
211
+ name: "sigx-ssg-mdx",
212
+ enforce: "pre",
213
+ async configResolved(e) {
214
+ a = e;
215
+ let t = await import("@mdx-js/rollup"), o = (await import("remark-frontmatter")).default, s = (await import("remark-mdx-frontmatter")).default, c = (await import("remark-gfm")).default, l = (await import("rehype-slug")).default, u = (await import("rehype-autolink-headings")).default, d = n.ssgConfig?.toc || {
216
+ minLevel: 2,
217
+ maxLevel: 3
218
+ }, f = [];
219
+ if (f.push(l), f.push([u, {
220
+ behavior: "append",
221
+ properties: {
222
+ class: "heading-anchor",
223
+ ariaHidden: !0,
224
+ tabIndex: -1
225
+ },
226
+ content: {
227
+ type: "element",
228
+ tagName: "span",
229
+ properties: { class: "heading-anchor-icon" },
230
+ children: [{
231
+ type: "text",
232
+ value: "#"
233
+ }]
234
+ }
235
+ }]), f.push([P, d]), r.shiki !== !1) {
236
+ let e = typeof r.shiki == "object" ? r.shiki : void 0;
237
+ f.push([j, e]);
238
+ }
239
+ r.rehypePlugins && f.push(...r.rehypePlugins);
240
+ let p = [
241
+ o,
242
+ [s, { name: "frontmatter" }],
243
+ c
244
+ ];
245
+ r.remarkPlugins && p.push(...r.remarkPlugins), i = t.default({
246
+ jsx: !1,
247
+ jsxImportSource: "sigx",
248
+ remarkPlugins: p,
249
+ rehypePlugins: f,
250
+ providerImportSource: void 0
251
+ });
252
+ },
253
+ async transform(r, o) {
254
+ if (!/\.mdx?$/.test(o)) return null;
255
+ let { data: s, content: c } = e(r);
256
+ if (!s.title) {
257
+ let e = t(c);
258
+ e && (s.title = e);
259
+ }
260
+ if (!i?.transform) throw Error("MDX plugin not initialized");
261
+ let l = await i.transform(r, o);
262
+ if (!l) return null;
263
+ let u = await L(c, n), d = o.replace(/\\/g, "/");
264
+ return {
265
+ code: I(l.code, s, u, d, a.command === "serve"),
266
+ map: l.map
267
+ };
268
+ }
269
+ };
270
+ }
271
+ function I(e, t, n, r, i) {
272
+ if (i) {
273
+ let i = r.split("/").pop()?.replace(/\.mdx?$/, "") || "MDXPage", a = i.charAt(0).toUpperCase() + i.slice(1).replace(/[^a-zA-Z0-9]/g, "") + "Page";
274
+ return `
275
+ import { registerHMRModule } from '@sigx/vite/hmr';
276
+ import { component as __component } from 'sigx';
277
+ registerHMRModule('${r}');
278
+
279
+ ${e.replace(/export\s+default\s+function\s+MDXContent/g, "function _MDXContent").replace(/export\s+{\s*MDXContent\s+as\s+default\s*}/g, "")}
280
+
281
+ // Export layout from frontmatter for SSG routing
282
+ export const layout = ${t.layout ? JSON.stringify(t.layout) : "undefined"};
283
+
284
+ // Export headings for table of contents
285
+ export const headings = ${JSON.stringify(n)};
286
+
287
+ // Wrap MDXContent in a sigx component for HMR support
288
+ const MDXPage = __component(() => {
289
+ return () => _MDXContent({});
290
+ }, { name: '${a}' });
291
+
292
+ export default MDXPage;
293
+
294
+ if (import.meta.hot) {
295
+ // Accept HMR updates with a callback to trigger re-render after module is updated
296
+ import.meta.hot.accept((newModule) => {
297
+ if (newModule) {
298
+ // Notify LayoutRouter to clear its cache and re-render with new module
299
+ window.dispatchEvent(new CustomEvent('sigx:mdx-hmr', {
300
+ detail: { moduleId: '${r}', newModule }
301
+ }));
302
+ }
303
+ });
304
+ }
305
+ `;
306
+ }
307
+ return `
308
+ ${e}
309
+
310
+ // Export layout from frontmatter for SSG routing
311
+ export const layout = ${t.layout ? JSON.stringify(t.layout) : "undefined"};
312
+
313
+ // Export headings for table of contents
314
+ export const headings = ${JSON.stringify(n)};
315
+ `;
316
+ }
317
+ async function L(e, t) {
318
+ let { unified: n } = await import("unified"), r = (await import("remark-parse")).default, i = (await import("remark-rehype")).default, a = (await import("rehype-slug")).default, o = (await import("rehype-stringify")).default, s = t.ssgConfig?.toc || {
319
+ minLevel: 2,
320
+ maxLevel: 3
321
+ };
322
+ return (await n().use(r).use(i).use(a).use(P, s).use(o).process(e)).data.headings || [];
323
+ }
324
+ //#endregion
325
+ //#region src/vite/plugin.ts
326
+ var R = "virtual:ssg-config", z = "\0" + R;
327
+ function B(t = {}) {
328
+ let x, S, C, w, T = null, E = null, D = null, O = /* @__PURE__ */ new Map(), k = {
329
+ name: "sigx-ssg",
330
+ enforce: "pre",
331
+ async configResolved(e) {
332
+ x = e, C = e.root, S = n({
333
+ ...await l(t.configPath),
334
+ ...t
335
+ }), w = f(C, S), (w.useVirtualClient || w.useVirtualServer) && (console.log("📦 @sigx/ssg: Using zero-config mode"), w.useVirtualClient && console.log(" → Virtual client entry"), w.useVirtualServer && console.log(" → Virtual server entry"), w.globalCssPath && console.log(` → Auto-importing ${w.globalCssPath}`));
336
+ },
337
+ configureServer(t) {
338
+ let n = y.resolve(C, S.pages || "src/pages"), r = y.resolve(C, S.layouts || "src/layouts");
339
+ y.resolve(C, S.content || "src/content"), t.watcher.on("add", (e) => {
340
+ e.startsWith(n) ? (T = null, D = null, i(_), i(c)) : e.startsWith(r) && (E = null, i(s));
341
+ }), t.watcher.on("unlink", (e) => {
342
+ e.startsWith(n) ? (T = null, D = null, O.delete(e), i(_), i(c)) : e.startsWith(r) && (E = null, i(s));
343
+ }), t.watcher.on("change", async (r) => {
344
+ if (r.startsWith(n) && /\.mdx?$/.test(r)) try {
345
+ let { data: n } = e(await b.promises.readFile(r, "utf-8")), i = JSON.stringify(n), a = O.get(r);
346
+ if (O.set(r, i), a !== void 0 && a !== i) {
347
+ D = null, T = null;
348
+ let e = t.moduleGraph.getModuleById(c);
349
+ e && t.moduleGraph.invalidateModule(e);
350
+ let n = t.moduleGraph.getModuleById(_);
351
+ n && t.moduleGraph.invalidateModule(n), t.ws.send({ type: "full-reload" });
352
+ }
353
+ } catch {}
354
+ });
355
+ function i(e) {
356
+ let n = t.moduleGraph.getModuleById(e);
357
+ n && (t.moduleGraph.invalidateModule(n), t.ws.send({ type: "full-reload" }));
358
+ }
359
+ w.useVirtualHtml && t.middlewares.use((e, n, r) => {
360
+ if (e.url?.startsWith("/@") || e.url?.startsWith("/__") || e.url?.includes("virtual:") || e.url?.includes("node_modules") || e.url?.startsWith("/@vite") || e.url?.startsWith("/@fs")) return r();
361
+ if (e.url && (e.url === "/" || !e.url.includes("."))) {
362
+ let i = o(S);
363
+ t.transformIndexHtml(e.url, i).then((e) => {
364
+ n.setHeader("Content-Type", "text/html"), n.end(e);
365
+ }).catch(r);
366
+ return;
367
+ }
368
+ r();
369
+ });
370
+ },
371
+ resolveId(e) {
372
+ return e === "virtual:ssg-routes" ? _ : e === "virtual:generated-layouts" ? s : e === R ? z : e === "virtual:ssg-navigation" ? c : e === "virtual:ssg-client" || e === "/@ssg/client.tsx" ? h : e === "virtual:ssg-server" ? d : null;
373
+ },
374
+ async load(e) {
375
+ if (e === "\0virtual:ssg-routes") {
376
+ if (!T) {
377
+ let e = await r(S, C);
378
+ T = {
379
+ routes: e,
380
+ code: x.command === "serve" ? a(e, S) : v(e, S)
381
+ };
382
+ }
383
+ return T.code;
384
+ }
385
+ if (e === "\0virtual:generated-layouts") {
386
+ if (!E) {
387
+ let e = await u(S, C);
388
+ E = {
389
+ layouts: e,
390
+ code: p(e, S)
391
+ };
392
+ }
393
+ return E.code;
394
+ }
395
+ if (e === "\0virtual:ssg-navigation") {
396
+ if (!D) {
397
+ if (!T) {
398
+ let e = await r(S, C);
399
+ T = {
400
+ routes: e,
401
+ code: x.command === "serve" ? a(e, S) : v(e, S)
402
+ };
403
+ }
404
+ let e = x.command === "serve";
405
+ D = { code: i(T.routes, S, e) };
406
+ }
407
+ return D.code;
408
+ }
409
+ if (e === z) return `export default ${JSON.stringify(S)};`;
410
+ if (e === "\0virtual:ssg-client.tsx") {
411
+ let e = m(S, w);
412
+ return (await (await import("esbuild")).transform(e, {
413
+ loader: "tsx",
414
+ jsx: "automatic",
415
+ jsxImportSource: "sigx"
416
+ })).code;
417
+ }
418
+ if (e === "\0virtual:ssg-server.tsx") {
419
+ let e = g(S);
420
+ return (await (await import("esbuild")).transform(e, {
421
+ loader: "tsx",
422
+ jsx: "automatic",
423
+ jsxImportSource: "sigx"
424
+ })).code;
425
+ }
426
+ return null;
427
+ },
428
+ async handleHotUpdate({ file: e, server: t }) {
429
+ let n = y.resolve(C, S.layouts || "src/layouts"), r = y.resolve(C, S.pages || "src/pages");
430
+ if (e.startsWith(n)) {
431
+ E = null;
432
+ let e = t.moduleGraph.getModuleById(s);
433
+ return e && t.moduleGraph.invalidateModule(e), [];
434
+ }
435
+ e.startsWith(r) && /\.mdx?$/.test(e);
436
+ }
437
+ };
438
+ return t.enableMdx === !1 ? [k] : [k, F({
439
+ markdown: t.markdown,
440
+ ssgConfig: void 0
441
+ })];
442
+ }
443
+ //#endregion
444
+ export { B as t };
445
+
446
+ //# sourceMappingURL=plugin-EIAzPLvE.js.map