@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,904 @@
1
+ import e from "node:path";
2
+ import t from "node:fs";
3
+ import n from "fast-glob";
4
+ import r from "gray-matter";
5
+ //#region src/config.ts
6
+ function i(e) {
7
+ return {
8
+ pages: "src/pages",
9
+ layouts: "src/layouts",
10
+ content: "src/content",
11
+ defaultLayout: "default",
12
+ outDir: "dist",
13
+ base: "/",
14
+ autoEntries: !0,
15
+ prefetch: !0,
16
+ ...e,
17
+ site: {
18
+ lang: "en",
19
+ ...e.site
20
+ },
21
+ markdown: {
22
+ shiki: !0,
23
+ ...e.markdown
24
+ },
25
+ toc: {
26
+ minLevel: 2,
27
+ maxLevel: 3,
28
+ ...e.toc
29
+ }
30
+ };
31
+ }
32
+ async function a(e) {
33
+ let t = await import("node:path"), n = await import("node:fs"), { pathToFileURL: r } = await import("node:url"), a = await import("node:os"), o = process.cwd(), s = e ? [t.resolve(o, e)] : [
34
+ t.resolve(o, "ssg.config.ts"),
35
+ t.resolve(o, "ssg.config.js"),
36
+ t.resolve(o, "ssg.config.mjs")
37
+ ], c = null;
38
+ for (let e of s) if (n.existsSync(e)) {
39
+ c = e;
40
+ break;
41
+ }
42
+ if (!c) return console.warn("No ssg.config found, using defaults"), i({});
43
+ try {
44
+ if (c.endsWith(".ts")) {
45
+ let e = await import("esbuild"), o = a.tmpdir();
46
+ t.join(o, `ssg-config-${Date.now()}.mjs`);
47
+ let s = n.readFileSync(c, "utf-8"), l = await e.transform(s, {
48
+ loader: "ts",
49
+ format: "esm"
50
+ }), u = t.dirname(c), d = t.join(u, `.ssg-config-temp-${Date.now()}.mjs`);
51
+ n.writeFileSync(d, l.code);
52
+ try {
53
+ let e = await import(r(d).href);
54
+ return i(e.default || e);
55
+ } finally {
56
+ try {
57
+ n.unlinkSync(d);
58
+ } catch {}
59
+ }
60
+ }
61
+ let e = await import(r(c).href);
62
+ return i(e.default || e);
63
+ } catch (e) {
64
+ return console.error(`Failed to load config from ${c}:`, e), i({});
65
+ }
66
+ }
67
+ function o(t, n) {
68
+ return {
69
+ ...t,
70
+ pages: e.resolve(n, t.pages || "src/pages"),
71
+ layouts: e.resolve(n, t.layouts || "src/layouts"),
72
+ content: e.resolve(n, t.content || "src/content"),
73
+ outDir: e.resolve(n, t.outDir || "dist")
74
+ };
75
+ }
76
+ //#endregion
77
+ //#region src/mdx/frontmatter.ts
78
+ function s(e) {
79
+ let { data: t, content: n, matter: i } = r(e);
80
+ return {
81
+ data: c(t),
82
+ content: n,
83
+ raw: i || "",
84
+ hasFrontmatter: !!i
85
+ };
86
+ }
87
+ function c(e) {
88
+ let t = {};
89
+ typeof e.title == "string" && (t.title = e.title), typeof e.description == "string" && (t.description = e.description), typeof e.layout == "string" && (t.layout = e.layout), typeof e.draft == "boolean" && (t.draft = e.draft), e.date && (e.date instanceof Date ? t.date = e.date : typeof e.date == "string" && (t.date = new Date(e.date))), Array.isArray(e.tags) && (t.tags = e.tags.filter((e) => typeof e == "string")), typeof e.ssr == "boolean" && (t.ssr = e.ssr);
90
+ for (let [n, r] of Object.entries(e)) n in t || (t[n] = r);
91
+ return t;
92
+ }
93
+ function l(e) {
94
+ let t = e.match(/^#\s+(.+)$/m);
95
+ return t ? t[1].trim() : null;
96
+ }
97
+ //#endregion
98
+ //#region src/routing/scanner.ts
99
+ var u = [
100
+ ".tsx",
101
+ ".jsx",
102
+ ".mdx",
103
+ ".md"
104
+ ], d = [
105
+ "components/**",
106
+ "hooks/**",
107
+ "utils/**",
108
+ "lib/**",
109
+ "**/_*",
110
+ "**/*.test.*",
111
+ "**/*.spec.*"
112
+ ];
113
+ async function f(t, r) {
114
+ let i = e.resolve(r, t.pages || "src/pages"), a = await n(u.map((e) => `**/*${e}`), {
115
+ cwd: i,
116
+ ignore: d,
117
+ onlyFiles: !0,
118
+ absolute: !1
119
+ }), o = [];
120
+ for (let e of a) {
121
+ let t = await p(e, i);
122
+ t && o.push(t);
123
+ }
124
+ return _(o);
125
+ }
126
+ async function p(n, r) {
127
+ let i = m(n, r);
128
+ if (!i) return null;
129
+ let a = e.extname(n).toLowerCase();
130
+ if (a === ".mdx" || a === ".md") try {
131
+ let { data: e } = s(t.readFileSync(i.file, "utf-8"));
132
+ i.meta = e;
133
+ } catch {}
134
+ return i;
135
+ }
136
+ function m(t, n) {
137
+ let r = e.extname(t), i = t.slice(0, -r.length);
138
+ (i.endsWith("/index") || i === "index") && (i = i.replace(/\/?index$/, "") || "/"), i = h(i);
139
+ let a = g(i);
140
+ return {
141
+ path: i.startsWith("/") ? i : `/${i}`,
142
+ file: e.join(n, t),
143
+ name: a
144
+ };
145
+ }
146
+ function h(e) {
147
+ return e.split("/").map((e) => e.startsWith("[...") && e.endsWith("]") ? `*${e.slice(4, -1)}` : e.startsWith("[[...") && e.endsWith("]]") ? `*${e.slice(5, -2)}` : e.startsWith("[") && e.endsWith("]") ? `:${e.slice(1, -1)}` : e.startsWith("[[") && e.endsWith("]]") ? `:${e.slice(2, -2)}?` : e).join("/");
148
+ }
149
+ function g(e) {
150
+ return e === "/" || e === "" ? "index" : e.replace(/^\//, "").replace(/\//g, "-").replace(/:/g, "").replace(/\*/g, "").replace(/\?/g, "").replace(/-+/g, "-").replace(/-$/, "");
151
+ }
152
+ function _(e) {
153
+ return e.sort((e, t) => {
154
+ let n = v(e.path), r = v(t.path);
155
+ return n === r ? t.path.length - e.path.length : r - n;
156
+ });
157
+ }
158
+ function v(e) {
159
+ let t = e.split("/").filter(Boolean), n = 0;
160
+ for (let e of t) e.startsWith("*") ? n += 1 : e.startsWith(":") ? n += 10 : n += 100;
161
+ return n;
162
+ }
163
+ function y(e) {
164
+ return e.path.includes(":") || e.path.includes("*");
165
+ }
166
+ function b(e) {
167
+ let t = [], n = e.split("/");
168
+ for (let e of n) e.startsWith(":") ? t.push(e.slice(1).replace("?", "")) : e.startsWith("*") && t.push(e.slice(1));
169
+ return t;
170
+ }
171
+ function x(e, t) {
172
+ let n = [];
173
+ for (let { params: r } of t) {
174
+ let t = e.path;
175
+ for (let [e, n] of Object.entries(r)) t = t.replace(`:${e}`, n), t = t.replace(`*${e}`, n);
176
+ n.push(t);
177
+ }
178
+ return n;
179
+ }
180
+ //#endregion
181
+ //#region src/routing/virtual.ts
182
+ var S = "virtual:ssg-routes", C = "\0" + S;
183
+ function w(e) {
184
+ return e.replace(/\\/g, "/");
185
+ }
186
+ function T(e, t) {
187
+ let n = [], r = [];
188
+ for (let i = 0; i < e.length; i++) {
189
+ let a = e[i], o = `Page${i}`, s = `meta${i}`, c = w(a.file);
190
+ n.push(`import * as ${o}Module from '${c}';`), n.push(`const ${s} = { ...('meta' in ${o}Module ? ${o}Module.meta : ${o}Module.default?.frontmatter || ${JSON.stringify(a.meta || {})}), headings: 'headings' in ${o}Module ? ${o}Module.headings : [] };`), n.push(`const ${o} = ${o}Module.default || ${o}Module;`), r.push(`
191
+ {
192
+ path: '${a.path}',
193
+ name: '${a.name}',
194
+ file: '${c}',
195
+ component: ${o},
196
+ meta: ${s},
197
+ layout: ${s}.layout || '${t.defaultLayout || "default"}',
198
+ }`);
199
+ }
200
+ return `
201
+ ${n.join("\n")}
202
+
203
+ const routes = [${r.join(",")}
204
+ ];
205
+
206
+ export default routes;
207
+ `;
208
+ }
209
+ function E(e, t) {
210
+ let n = [], r = [];
211
+ for (let i = 0; i < e.length; i++) {
212
+ let a = e[i], o = `Page${i}`, s = `meta${i}`, c = w(a.file);
213
+ n.push(`import * as ${o}Module from '${c}';`), n.push(`const ${s} = { ...('meta' in ${o}Module ? ${o}Module.meta : ${o}Module.default?.frontmatter || ${JSON.stringify(a.meta || {})}), headings: 'headings' in ${o}Module ? ${o}Module.headings : [] };`), r.push(`
214
+ {
215
+ path: '${a.path}',
216
+ name: '${a.name}',
217
+ file: '${c}',
218
+ component: () => import('${c}'),
219
+ meta: ${s},
220
+ layout: ${s}.layout || '${t.defaultLayout || "default"}',
221
+ }`);
222
+ }
223
+ return `
224
+ ${n.join("\n")}
225
+
226
+ const routes = [${r.join(",")}
227
+ ];
228
+
229
+ export default routes;
230
+ `;
231
+ }
232
+ //#endregion
233
+ //#region src/routing/navigation.ts
234
+ function D(e, t, n, r) {
235
+ let i = e.filter((e) => {
236
+ if (!e.path.startsWith(t)) return !1;
237
+ let i = e.meta || {};
238
+ return !(i.sidebar === !1 || i.draft && (n === "never" || n === "dev" && !r));
239
+ }), a = {
240
+ categories: /* @__PURE__ */ new Map(),
241
+ uncategorized: []
242
+ };
243
+ for (let e of i) {
244
+ let t = e.meta || {}, n = t.title || P(e.path), r = typeof t.order == "number" ? t.order : 999, i = t.category, o = {
245
+ title: n,
246
+ href: e.path,
247
+ order: r
248
+ };
249
+ i ? typeof i == "string" ? O(a.categories, [i], o) : Array.isArray(i) && O(a.categories, i, o) : a.uncategorized.push(o);
250
+ }
251
+ return { sidebar: j(a) };
252
+ }
253
+ function O(e, t, n) {
254
+ if (t.length === 0) return;
255
+ let [r, ...i] = t, a = e.get(r);
256
+ a || (a = {
257
+ title: r,
258
+ order: void 0,
259
+ items: [],
260
+ children: /* @__PURE__ */ new Map()
261
+ }, e.set(r, a)), i.length === 0 ? a.items.push(n) : O(a.children, i, n);
262
+ }
263
+ var k = {
264
+ "Getting Started": 10,
265
+ "Core Concepts": 20,
266
+ Core: 20,
267
+ "Built-in Components": 30,
268
+ Components: 30,
269
+ Guides: 40,
270
+ Advanced: 50,
271
+ Ecosystem: 60,
272
+ "API Reference": 70,
273
+ API: 70,
274
+ Reference: 80,
275
+ Actions: 100,
276
+ "Data Display": 110,
277
+ Navigation: 120,
278
+ Feedback: 130,
279
+ "Data Input": 140,
280
+ Layout: 150,
281
+ Mockup: 160,
282
+ Other: 999
283
+ };
284
+ function A(e, t) {
285
+ return t === void 0 ? k[e] ?? 50 : t;
286
+ }
287
+ function j(e) {
288
+ let t = [];
289
+ for (let [, n] of e.categories) t.push(M(n));
290
+ return e.uncategorized.length > 0 && t.push({
291
+ title: "Other",
292
+ items: e.uncategorized.sort((e, t) => e.order - t.order || e.title.localeCompare(t.title)).map((e) => ({
293
+ title: e.title,
294
+ href: e.href,
295
+ order: e.order
296
+ })),
297
+ order: 999
298
+ }), t.sort((e, t) => A(e.title, e.order) - A(t.title, t.order)), t;
299
+ }
300
+ function M(e) {
301
+ let t = e.items.sort((e, t) => e.order - t.order || e.title.localeCompare(t.title)).map((e) => ({
302
+ title: e.title,
303
+ href: e.href,
304
+ order: e.order
305
+ })), n = [];
306
+ for (let [, t] of e.children) n.push(N(t));
307
+ let r = [...t];
308
+ for (let e of n.sort((e, t) => A(e.title, e.order) - A(t.title, t.order))) r.push(e);
309
+ return {
310
+ title: e.title,
311
+ items: r,
312
+ order: e.order
313
+ };
314
+ }
315
+ function N(e) {
316
+ let t = e.items.sort((e, t) => e.order - t.order || e.title.localeCompare(t.title)).map((e) => ({
317
+ title: e.title,
318
+ href: e.href,
319
+ order: e.order
320
+ })), n = [];
321
+ for (let [, t] of e.children) n.push(N(t));
322
+ return {
323
+ title: e.title,
324
+ items: [...t, ...n.sort((e, t) => (e.order ?? 0) - (t.order ?? 0))],
325
+ order: e.order
326
+ };
327
+ }
328
+ function P(e) {
329
+ let t = e.split("/").filter(Boolean);
330
+ return (t[t.length - 1] || "Home").replace(/-/g, " ").replace(/\b\w/g, (e) => e.toUpperCase());
331
+ }
332
+ function F(e, t, n) {
333
+ let r = t.collections || {}, i = {};
334
+ for (let [a, o] of Object.entries(r)) {
335
+ let r = o.showDrafts ?? t.navigation?.showDrafts ?? "dev";
336
+ i[a] = D(e, o.path, r, n);
337
+ }
338
+ return i;
339
+ }
340
+ //#endregion
341
+ //#region src/routing/virtual-navigation.ts
342
+ var I = "virtual:ssg-navigation", L = "\0" + I;
343
+ function R(e, t, n) {
344
+ let r = F(e, t, n), i = t.collections || {};
345
+ return `
346
+ /**
347
+ * Auto-generated navigation module
348
+ *
349
+ * @generated by @sigx/ssg
350
+ */
351
+
352
+ /**
353
+ * Navigation for all collections, keyed by collection name
354
+ */
355
+ export const navigation = ${JSON.stringify(r, null, 2)};
356
+
357
+ /**
358
+ * Collections configuration
359
+ */
360
+ const collections = ${JSON.stringify(i, null, 2)};
361
+
362
+ /**
363
+ * Get navigation for a specific collection
364
+ * @param name - Collection name (e.g., 'docs', 'examples')
365
+ * @returns The collection's navigation or undefined if not found
366
+ */
367
+ export function getCollectionNav(name) {
368
+ return navigation[name];
369
+ }
370
+
371
+ /**
372
+ * Detect which collection a route path belongs to
373
+ * @param path - Current route path
374
+ * @returns The collection name if found, undefined otherwise
375
+ */
376
+ export function detectCollection(path) {
377
+ // Sort by path length descending to match most specific path first
378
+ const sorted = Object.entries(collections).sort(
379
+ ([, a], [, b]) => b.path.length - a.path.length
380
+ );
381
+
382
+ for (const [name, config] of sorted) {
383
+ if (path.startsWith(config.path)) {
384
+ return name;
385
+ }
386
+ }
387
+
388
+ return undefined;
389
+ }
390
+
391
+ /**
392
+ * Get sidebar for a specific collection
393
+ * @param name - Collection name
394
+ * @returns The sidebar array or empty array if not found
395
+ */
396
+ export function getSidebar(name) {
397
+ return navigation[name]?.sidebar || [];
398
+ }
399
+
400
+ export default { navigation, collections, getCollectionNav, detectCollection, getSidebar };
401
+ `;
402
+ }
403
+ //#endregion
404
+ //#region src/layouts/resolver.ts
405
+ var z = [".tsx", ".jsx"];
406
+ async function B(r, i) {
407
+ let a = e.resolve(i, r.layouts || "src/layouts");
408
+ return t.existsSync(a) ? (await n(z.map((e) => `*${e}`), {
409
+ cwd: a,
410
+ onlyFiles: !0,
411
+ absolute: !1
412
+ })).map((t) => {
413
+ let n = e.extname(t);
414
+ return {
415
+ name: t.slice(0, -n.length),
416
+ file: e.join(a, t),
417
+ source: "local"
418
+ };
419
+ }) : [];
420
+ }
421
+ async function V(n, r) {
422
+ try {
423
+ let { createRequire: i } = await import("node:module"), { pathToFileURL: a } = await import("node:url"), o = i(e.join(r, "package.json")).resolve(`${n}/package.json`), s = e.dirname(o), c = JSON.parse(t.readFileSync(o, "utf-8")), l = c.exports?.["."]?.import || c.main || "./dist/index.js", u = await import(a(e.resolve(s, l)).href);
424
+ return u.layouts ? Object.keys(u.layouts).map((e) => ({
425
+ name: e,
426
+ file: `${n}/layouts/${e}`,
427
+ source: n
428
+ })) : [];
429
+ } catch (e) {
430
+ return console.warn(`Failed to load theme ${n}:`, e), [];
431
+ }
432
+ }
433
+ async function H(e, t) {
434
+ let n = /* @__PURE__ */ new Map();
435
+ if (e.theme) {
436
+ let r = await V(e.theme, t);
437
+ for (let e of r) n.set(e.name, e);
438
+ }
439
+ let r = await B(e, t);
440
+ for (let e of r) n.set(e.name, e);
441
+ return Array.from(n.values());
442
+ }
443
+ //#endregion
444
+ //#region src/layouts/virtual.ts
445
+ var U = "virtual:generated-layouts", W = "\0virtual:generated-layouts";
446
+ function G(e) {
447
+ return e.replace(/\\/g, "/");
448
+ }
449
+ function K(e, t) {
450
+ let n = [], r = [];
451
+ for (let t = 0; t < e.length; t++) {
452
+ let i = e[t], a = `Layout${t}`;
453
+ if (i.source === "local") {
454
+ let e = G(i.file);
455
+ n.push(`import ${a} from '${e}';`);
456
+ } else n.push(`import { layouts as themeLayouts${t} } from '${i.source}';`), n.push(`const ${a} = themeLayouts${t}['${i.name}'];`);
457
+ r.push(` '${i.name}': ${a}.default || ${a}`);
458
+ }
459
+ return `
460
+ import { component, signal, jsx } from 'sigx';
461
+ import { useRoute } from '@sigx/router';
462
+ ${n.join("\n")}
463
+
464
+ /**
465
+ * All available layouts
466
+ */
467
+ export const layouts = {
468
+ ${r.join(",\n")}
469
+ };
470
+
471
+ /**
472
+ * Default layout name
473
+ */
474
+ export const defaultLayout = '${t.defaultLayout || "default"}';
475
+
476
+ /**
477
+ * Check if a component is marked as lazy (created by lazy())
478
+ */
479
+ function isMarkedLazy(component) {
480
+ return component && component.__lazy === true;
481
+ }
482
+
483
+ /**
484
+ * Check if a value is a Promise/thenable
485
+ */
486
+ function isPromise(value) {
487
+ return value && typeof value.then === 'function';
488
+ }
489
+
490
+ /**
491
+ * Track hydration state - we're hydrating if the app container has SSR content
492
+ */
493
+ let isHydrating = typeof window !== 'undefined' &&
494
+ document.getElementById('app')?.innerHTML?.trim().length > 0;
495
+
496
+ // After first render, we're no longer hydrating
497
+ if (typeof window !== 'undefined') {
498
+ const markHydrationComplete = () => { isHydrating = false; };
499
+ if ('requestIdleCallback' in window) {
500
+ window.requestIdleCallback(markHydrationComplete);
501
+ } else {
502
+ setTimeout(markHydrationComplete, 0);
503
+ }
504
+ }
505
+
506
+ /**
507
+ * Placeholder component that preserves existing DOM during hydration.
508
+ */
509
+ const HydrationPlaceholder = component(() => {
510
+ return () => null;
511
+ }, { name: 'HydrationPlaceholder' });
512
+
513
+ /**
514
+ * Layout router component that preserves layouts across navigation.
515
+ *
516
+ * This component renders the current route's layout and page content reactively.
517
+ * When navigating between routes with the same layout, only the page content
518
+ * updates - the layout (Navbar, Sidebar, Footer) persists without re-rendering.
519
+ */
520
+ export const LayoutRouter = component((ctx) => {
521
+ const route = useRoute();
522
+
523
+ // Track loaded lazy components to avoid reloading
524
+ const loadedComponents = {};
525
+
526
+ // Track if this is the initial hydration render
527
+ let initialRender = true;
528
+
529
+ // HMR support: Listen for MDX updates and clear the component cache
530
+ if (typeof window !== 'undefined' && import.meta.hot) {
531
+ // Listen for sigx:mdx-hmr events dispatched by MDX files after they accept HMR
532
+ const handleMdxHmr = (event) => {
533
+ const { moduleId, newModule } = event.detail || {};
534
+
535
+ // Clear all cached components to force reload with new module
536
+ for (const key in loadedComponents) {
537
+ delete loadedComponents[key];
538
+ }
539
+
540
+ // If we have the new module directly from HMR, cache it for the matching route
541
+ if (newModule?.default) {
542
+ const currentPath = route.path;
543
+ loadedComponents[currentPath] = newModule.default;
544
+ }
545
+
546
+ // Force re-render
547
+ ctx.update();
548
+ };
549
+
550
+ window.addEventListener('sigx:mdx-hmr', handleMdxHmr);
551
+
552
+ ctx.onUnmounted(() => {
553
+ window.removeEventListener('sigx:mdx-hmr', handleMdxHmr);
554
+ });
555
+ }
556
+
557
+ return () => {
558
+ const matched = route.matched;
559
+ if (!matched || matched.length === 0) return null;
560
+
561
+ const match = matched[0];
562
+ if (!match) return null;
563
+
564
+ // Get layout name from route meta or use default
565
+ const layoutName = match.layout || match.meta?.layout || defaultLayout;
566
+ const Layout = layouts[layoutName];
567
+
568
+ if (!Layout) {
569
+ console.warn(\`Layout "\${layoutName}" not found for route \${route.path}\`);
570
+ return null;
571
+ }
572
+
573
+ // Get the original (unwrapped) component
574
+ const rawComponent = match.originalComponent || match.component;
575
+ const routePath = route.path;
576
+
577
+ // Handle lazy/dynamic import components
578
+ if (isMarkedLazy(rawComponent) || (typeof rawComponent === 'function' && !rawComponent.__setup)) {
579
+ // Check if already loaded
580
+ if (loadedComponents[routePath]) {
581
+ const PageComponent = loadedComponents[routePath];
582
+ initialRender = false;
583
+ return jsx(Layout, {
584
+ meta: match.meta,
585
+ path: routePath,
586
+ key: layoutName, // Key by layout to preserve layout across pages
587
+ children: PageComponent({})
588
+ });
589
+ }
590
+
591
+ // Load the component
592
+ const loadState = signal({ value: null, loading: true, error: null });
593
+
594
+ try {
595
+ const result = rawComponent();
596
+ if (isPromise(result)) {
597
+ result.then(module => {
598
+ const Component = module.default || module;
599
+ loadedComponents[routePath] = Component;
600
+ loadState.value = Component;
601
+ loadState.loading = false;
602
+ }).catch(err => {
603
+ console.error('Failed to load component for route:', routePath, err);
604
+ loadState.error = err;
605
+ loadState.loading = false;
606
+ });
607
+ } else {
608
+ // Not a promise, use directly
609
+ loadedComponents[routePath] = rawComponent;
610
+ loadState.value = rawComponent;
611
+ loadState.loading = false;
612
+ }
613
+ } catch (err) {
614
+ loadState.error = err;
615
+ loadState.loading = false;
616
+ }
617
+
618
+ // During hydration, preserve existing SSR content instead of showing loading state
619
+ if (loadState.loading) {
620
+ if (isHydrating && initialRender) {
621
+ return jsx(Layout, {
622
+ meta: match.meta,
623
+ path: routePath,
624
+ key: layoutName,
625
+ children: jsx(HydrationPlaceholder, {})
626
+ });
627
+ }
628
+ return jsx(Layout, {
629
+ meta: match.meta,
630
+ path: routePath,
631
+ key: layoutName,
632
+ children: null
633
+ });
634
+ }
635
+
636
+ if (loadState.error || !loadState.value) {
637
+ return jsx(Layout, {
638
+ meta: match.meta,
639
+ path: routePath,
640
+ key: layoutName,
641
+ children: null
642
+ });
643
+ }
644
+
645
+ const PageComponent = loadState.value;
646
+ initialRender = false;
647
+ return jsx(Layout, {
648
+ meta: match.meta,
649
+ path: routePath,
650
+ key: layoutName,
651
+ children: PageComponent({})
652
+ });
653
+ }
654
+
655
+ // Eager component (has __setup)
656
+ // Check cache first for HMR-updated components
657
+ if (loadedComponents[routePath]) {
658
+ const PageComponent = loadedComponents[routePath];
659
+ initialRender = false;
660
+ return jsx(Layout, {
661
+ meta: match.meta,
662
+ path: routePath,
663
+ key: layoutName,
664
+ children: PageComponent({})
665
+ });
666
+ }
667
+
668
+ initialRender = false;
669
+ return jsx(Layout, {
670
+ meta: match.meta,
671
+ path: routePath,
672
+ key: layoutName,
673
+ children: rawComponent({})
674
+ });
675
+ };
676
+ }, { name: 'LayoutRouter' });
677
+
678
+ /**
679
+ * Setup layouts for routes
680
+ *
681
+ * This function now simply annotates routes with their layout information.
682
+ * The actual layout wrapping is handled by LayoutRouter, which preserves
683
+ * layouts across navigation.
684
+ */
685
+ export function setupLayouts(routes) {
686
+ const availableLayoutNames = Object.keys(layouts);
687
+
688
+ return routes.map(route => {
689
+ const layoutName = route.layout || route.meta?.layout || defaultLayout;
690
+ const Layout = layouts[layoutName];
691
+
692
+ if (!Layout) {
693
+ console.error(
694
+ \`❌ SSG103: Layout "\${layoutName}" not found for route \${route.path}\\n\` +
695
+ \` 📁 \${route.file || 'unknown'}\\n\` +
696
+ \` 💡 Available layouts: \${availableLayoutNames.join(', ') || 'none'}\\n\` +
697
+ \` Create src/layouts/\${layoutName}.tsx or set a valid layout in frontmatter.\`
698
+ );
699
+ return route;
700
+ }
701
+
702
+ // Store layout info on the route, but don't wrap the component
703
+ // LayoutRouter will handle layout rendering
704
+ return {
705
+ ...route,
706
+ layout: layoutName,
707
+ originalComponent: route.component,
708
+ meta: {
709
+ ...route.meta,
710
+ layout: layoutName,
711
+ },
712
+ };
713
+ });
714
+ }
715
+
716
+ export default layouts;
717
+ `;
718
+ }
719
+ //#endregion
720
+ //#region src/vite/virtual-entries.ts
721
+ var q = "virtual:ssg-client", J = "\0" + q + ".tsx", Y = "/@ssg/client.tsx", X = "virtual:ssg-server", Z = "\0" + X + ".tsx";
722
+ function Q(n, r) {
723
+ let i = [
724
+ "src/main.tsx",
725
+ "src/main.ts",
726
+ "src/entry-client.tsx",
727
+ "src/entry-client.ts",
728
+ "src/entry.tsx",
729
+ "src/entry.ts"
730
+ ], a = ["src/entry-server.tsx", "src/entry-server.ts"], o = ["index.html"], s = [
731
+ "src/styles/global.css",
732
+ "src/styles/main.css",
733
+ "src/styles/index.css",
734
+ "src/style.css",
735
+ "src/global.css",
736
+ "src/index.css"
737
+ ], c, l, u, d;
738
+ for (let r of i) {
739
+ let i = e.join(n, r);
740
+ if (t.existsSync(i)) {
741
+ c = i;
742
+ break;
743
+ }
744
+ }
745
+ for (let r of a) {
746
+ let i = e.join(n, r);
747
+ if (t.existsSync(i)) {
748
+ l = i;
749
+ break;
750
+ }
751
+ }
752
+ for (let r of o) {
753
+ let i = e.join(n, r);
754
+ if (t.existsSync(i)) {
755
+ u = i;
756
+ break;
757
+ }
758
+ }
759
+ for (let r of s) {
760
+ let i = e.join(n, r);
761
+ if (t.existsSync(i)) {
762
+ d = "/" + r.replace(/\\/g, "/");
763
+ break;
764
+ }
765
+ }
766
+ return {
767
+ useVirtualClient: !c,
768
+ useVirtualServer: !l,
769
+ useVirtualHtml: !u,
770
+ customClientPath: c,
771
+ customServerPath: l,
772
+ customHtmlPath: u,
773
+ globalCssPath: d
774
+ };
775
+ }
776
+ function $(e, t) {
777
+ let n = t.globalCssPath ? `import '${t.globalCssPath}';\n` : "", r = (e.clientImports ?? []).map((e) => `import '${e}';`).join("\n"), i = r ? `\n${r}\n` : "", a = typeof e.prefetch == "object" ? e.prefetch.delay ?? 100 : 100, o = e.prefetch !== !1;
778
+ return `/**
779
+ * Auto-generated client entry point
780
+ * This file is generated by @sigx/ssg when no custom entry is detected.
781
+ * To customize, create src/main.tsx or src/entry-client.tsx
782
+ */
783
+ ${n}${i}
784
+ import { defineApp, component } from 'sigx';
785
+ import { createRouter, createWebHistory } from '@sigx/router';
786
+ import { ssrClientPlugin } from '@sigx/ssg/client';
787
+ import routes from 'virtual:ssg-routes';
788
+ import { setupLayouts, LayoutRouter } from 'virtual:generated-layouts';
789
+ ${o ? "import { setupPrefetch } from '@sigx/ssg/client';" : ""}
790
+
791
+ // Apply layouts to routes (annotates routes with layout info)
792
+ const layoutRoutes = setupLayouts(routes);
793
+
794
+ // Create router with browser history
795
+ const router = createRouter({
796
+ history: createWebHistory('${e.base || "/"}'),
797
+ routes: layoutRoutes,
798
+ scrollBehavior(to, from, savedPosition) {
799
+ if (savedPosition) return savedPosition;
800
+ if (to.hash) return { el: to.hash };
801
+ return { top: 0 };
802
+ },
803
+ });
804
+
805
+ // Root app component - uses LayoutRouter which preserves layouts across navigation
806
+ const App = component(() => {
807
+ return () => <LayoutRouter />;
808
+ });
809
+
810
+ // Hydrate the server-rendered HTML
811
+ defineApp(<App />)
812
+ .use(router)
813
+ .use(ssrClientPlugin)
814
+ .hydrate('#app');
815
+
816
+ ${o ? `// Enable link prefetching for faster navigation
817
+ setupPrefetch({ delay: ${a} });` : ""}
818
+ `;
819
+ }
820
+ function ee(e) {
821
+ return "/**\n * Auto-generated server entry point\n * This file is generated by @sigx/ssg when no custom entry is detected.\n * To customize, create src/entry-server.tsx\n */\nimport { renderToString } from '@sigx/server-renderer/server';\nimport { defineApp } from 'sigx';\nimport { createRouter, createMemoryHistory } from '@sigx/router';\nimport routes from 'virtual:ssg-routes';\nimport { setupLayouts, LayoutRouter } from 'virtual:generated-layouts';\n\n// Pre-process routes with layouts once at module load time (not per-render)\nconst routesWithLayouts = setupLayouts(routes);\n\n/**\n * Render the app to HTML string for a given URL\n */\nexport async function render(url, context) {\n // Create router with memory history for SSR\n // Note: We must create a new router per render because history is URL-specific\n const router = createRouter({\n routes: routesWithLayouts,\n history: createMemoryHistory({ initialLocation: url || '/' }),\n });\n\n // Create app with router - router's install() sets up DI via app.defineProvide()\n const app = defineApp(<LayoutRouter />).use(router);\n \n const html = await renderToString(app);\n return html;\n}\n";
822
+ }
823
+ function te(e) {
824
+ let t = e.site || {}, n = t.lang || "en", r = t.title || "SignalX App", i = t.description || "", a = t.favicon || "/favicon.ico", o = t.themeColor || "#000000", s = t.ogImage || "", c = t.url || "", l = t.twitter || "", u = t.fonts || [], d = "";
825
+ u.length > 0 && (d = `
826
+ <link rel="preconnect" href="https://fonts.googleapis.com" />
827
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
828
+ <link href="https://fonts.googleapis.com/css2?family=${u.join("&family=")}&display=swap" rel="stylesheet" />`);
829
+ let f = "";
830
+ (c || s) && (f = `
831
+ <!-- Open Graph -->
832
+ <meta property="og:type" content="website" />
833
+ <meta property="og:title" content="${r}" />
834
+ <meta property="og:description" content="${i}" />${c ? `
835
+ <meta property="og:url" content="${c}" />` : ""}${s ? `
836
+ <meta property="og:image" content="${s}" />` : ""}`);
837
+ let p = "";
838
+ return (l || s) && (p = `
839
+ <!-- Twitter Card -->
840
+ <meta name="twitter:card" content="${s ? "summary_large_image" : "summary"}" />${l ? `
841
+ <meta name="twitter:site" content="@${l}" />` : ""}
842
+ <meta name="twitter:title" content="${r}" />
843
+ <meta name="twitter:description" content="${i}" />${s ? `
844
+ <meta name="twitter:image" content="${s}" />` : ""}`), `<!DOCTYPE html>
845
+ <html lang="${n}">
846
+ <head>
847
+ <meta charset="UTF-8" />
848
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
849
+ <meta name="description" content="${i}" />
850
+ <meta name="theme-color" content="${o}" />
851
+ <link rel="icon" type="image/x-icon" href="${a}" />${d}${f}${p}
852
+ <title>${r}</title>
853
+ <!--head-tags-->
854
+ </head>
855
+ <body>
856
+ <div id="app"><!--app-html--></div>
857
+ <script type="module" src="/@ssg/client.tsx"><\/script>
858
+ </body>
859
+ </html>
860
+ `;
861
+ }
862
+ function ne(e, t) {
863
+ let n = e.site || {}, r = n.lang || "en", i = n.title || "SignalX App", a = n.description || "", o = n.favicon || "/favicon.ico", s = n.themeColor || "#000000", c = n.ogImage || "", l = n.url || "", u = n.twitter || "", d = n.fonts || [], f = "";
864
+ d.length > 0 && (f = `
865
+ <link rel="preconnect" href="https://fonts.googleapis.com" />
866
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
867
+ <link href="https://fonts.googleapis.com/css2?family=${d.join("&family=")}&display=swap" rel="stylesheet" />`);
868
+ let p = "";
869
+ (l || c) && (p = `
870
+ <!-- Open Graph -->
871
+ <meta property="og:type" content="website" />
872
+ <meta property="og:title" content="${i}" />
873
+ <meta property="og:description" content="${a}" />${l ? `
874
+ <meta property="og:url" content="${l}" />` : ""}${c ? `
875
+ <meta property="og:image" content="${c}" />` : ""}`);
876
+ let m = "";
877
+ return (u || c) && (m = `
878
+ <!-- Twitter Card -->
879
+ <meta name="twitter:card" content="${c ? "summary_large_image" : "summary"}" />${u ? `
880
+ <meta name="twitter:site" content="@${u}" />` : ""}
881
+ <meta name="twitter:title" content="${i}" />
882
+ <meta name="twitter:description" content="${a}" />${c ? `
883
+ <meta name="twitter:image" content="${c}" />` : ""}`), `<!DOCTYPE html>
884
+ <html lang="${r}">
885
+ <head>
886
+ <meta charset="UTF-8" />
887
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
888
+ <meta name="description" content="${a}" />
889
+ <meta name="theme-color" content="${s}" />
890
+ <link rel="icon" type="image/x-icon" href="${o}" />${f}${p}${m}
891
+ <title>${i}</title>
892
+ <!--head-tags-->
893
+ </head>
894
+ <body>
895
+ <div id="app"><!--app-html--></div>
896
+ <script type="module" src="${t}"><\/script>
897
+ </body>
898
+ </html>
899
+ `;
900
+ }
901
+ //#endregion
902
+ export { o as A, b as C, s as D, l as E, i as O, x as S, f as T, R as _, X as a, E as b, te as c, W as d, U as f, I as g, L as h, q as i, a as k, ne as l, H as m, Z as n, Q as o, K as p, Y as r, $ as s, J as t, ee as u, C as v, y as w, T as x, S as y };
903
+
904
+ //# sourceMappingURL=virtual-entries-CH-0HuqJ.js.map