@zenithbuild/core 0.6.2 → 1.1.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.
package/dist/zenith.js CHANGED
@@ -9283,8 +9283,8 @@ var init_componentResolver = __esm(() => {
9283
9283
  import process2 from "process";
9284
9284
 
9285
9285
  // cli/commands/dev.ts
9286
- import path8 from "path";
9287
- import fs8 from "fs";
9286
+ import path7 from "path";
9287
+ import fs7 from "fs";
9288
9288
  var {serve } = globalThis.Bun;
9289
9289
 
9290
9290
  // cli/utils/project.ts
@@ -10010,11 +10010,11 @@ function generateExplicitExpressionWrapper(expr, dependencies) {
10010
10010
  if (dependencies.usesState) {
10011
10011
  contextParts.push("state");
10012
10012
  }
10013
- const contextCode = contextParts.length > 0 ? `const __ctx = Object.assign({}, ${contextParts.join(", ")});
10014
- with (__ctx) {` : "with (state) {";
10013
+ const contextCode = contextParts.length > 0 ? `var __ctx = Object.assign({}, ${contextParts.join(", ")});` : "var __ctx = state || {};";
10015
10014
  const commentCode = code.replace(/[\r\n]+/g, " ").replace(/\s+/g, " ").substring(0, 100);
10016
10015
  const jsonEscapedCode = JSON.stringify(code);
10017
10016
  const transformedCode = transformExpressionJSX(code);
10017
+ const escapedTransformedCode = transformedCode.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/\n/g, "\\n").replace(/\r/g, "\\r");
10018
10018
  return `
10019
10019
  // Expression: ${commentCode}${code.length > 100 ? "..." : ""}
10020
10020
  // Dependencies: ${JSON.stringify({
@@ -10023,16 +10023,24 @@ function generateExplicitExpressionWrapper(expr, dependencies) {
10023
10023
  stores: dependencies.usesStores,
10024
10024
  state: dependencies.usesState
10025
10025
  })}
10026
- const ${id} = (${paramList}) => {
10027
- try {
10028
- ${contextCode}
10029
- return ${transformedCode};
10026
+ const ${id} = (function() {
10027
+ // Create the evaluator function once (with 'with' support in sloppy mode)
10028
+ var evalFn = new Function('__ctx',
10029
+ 'with (__ctx) { return (' + '${escapedTransformedCode}' + '); }'
10030
+ );
10031
+
10032
+ return function(${paramList}) {
10033
+ try {
10034
+ // Merge window globals with context (for script-level variables)
10035
+ var __baseCtx = Object.assign({}, window);
10036
+ ${contextCode.replace("var __ctx", "var __ctx").replace("= Object.assign({},", "= Object.assign(__baseCtx,")}
10037
+ return evalFn(__ctx);
10038
+ } catch (e) {
10039
+ console.warn('[Zenith] Expression evaluation error:', ${jsonEscapedCode}, e);
10040
+ return undefined;
10030
10041
  }
10031
- } catch (e) {
10032
- console.warn('[Zenith] Expression evaluation error:', ${jsonEscapedCode}, e);
10033
- return undefined;
10034
- }
10035
- };`;
10042
+ };
10043
+ })();`;
10036
10044
  }
10037
10045
  function analyzeAllExpressions(expressions, filePath, declaredLoaderProps = [], declaredProps = [], declaredStores = []) {
10038
10046
  const dependencies = expressions.map((expr) => analyzeExpressionDependencies(expr, declaredLoaderProps, declaredProps, declaredStores));
@@ -10076,20 +10084,28 @@ function wrapExpressionWithLoopContext(expr, loopContext, dependencies) {
10076
10084
  contextMerge.push("loopContext");
10077
10085
  const contextObject = contextMerge.length > 0 ? `const __ctx = Object.assign({}, ${contextMerge.join(", ")});` : `const __ctx = loopContext || {};`;
10078
10086
  const transformedCode = transformExpressionJSX(code);
10087
+ const escapedTransformedCode = transformedCode.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/\n/g, "\\n").replace(/\r/g, "\\r");
10079
10088
  return `
10080
10089
  // Expression with loop context: ${escapedCode}
10081
10090
  // Loop variables: ${loopContext.variables.join(", ")}
10082
- const ${id} = (${argsStr}) => {
10083
- try {
10084
- ${contextObject}
10085
- with (__ctx) {
10086
- return ${transformedCode};
10091
+ const ${id} = (function() {
10092
+ // Create the evaluator function once (with 'with' support in sloppy mode)
10093
+ var evalFn = new Function('__ctx',
10094
+ 'with (__ctx) { return (' + '${escapedTransformedCode}' + '); }'
10095
+ );
10096
+
10097
+ return function(${argsStr}) {
10098
+ try {
10099
+ // Merge window globals with context (for script-level variables)
10100
+ var __baseCtx = Object.assign({}, window);
10101
+ ${contextObject.replace("const __ctx", "var __ctx").replace("= Object.assign({},", "= Object.assign(__baseCtx,")}
10102
+ return evalFn(__ctx);
10103
+ } catch (e) {
10104
+ console.warn('[Zenith] Expression evaluation error for "${escapedCode}":', e);
10105
+ return undefined;
10087
10106
  }
10088
- } catch (e) {
10089
- console.warn('[Zenith] Expression evaluation error for "${escapedCode}":', e);
10090
- return undefined;
10091
- }
10092
- };`;
10107
+ };
10108
+ })();`;
10093
10109
  }
10094
10110
 
10095
10111
  // compiler/runtime/wrapExpression.ts
@@ -10104,22 +10120,32 @@ function wrapExpression(expr, dependencies, loopContext) {
10104
10120
  const transformedCode = transformExpressionJSX(code);
10105
10121
  const commentCode = code.replace(/[\r\n]+/g, " ").replace(/\s+/g, " ").substring(0, 100);
10106
10122
  const jsonEscapedCode = JSON.stringify(code);
10123
+ const escapedTransformedCode = transformedCode.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/\n/g, "\\n").replace(/\r/g, "\\r");
10107
10124
  return `
10108
10125
  // Expression: ${commentCode}${code.length > 100 ? "..." : ""}
10109
- const ${id} = (state) => {
10110
- try {
10111
- // Expose zenith helpers for JSX and content
10112
- const __zenith = window.__zenith || {};
10113
- const zenCollection = __zenith.zenCollection || ((name) => ({ get: () => [] }));
10114
-
10115
- with (state) {
10116
- return ${transformedCode};
10126
+ const ${id} = (function() {
10127
+ // Create the evaluator function once (with 'with' support in sloppy mode)
10128
+ var evalFn = new Function('__ctx',
10129
+ 'with (__ctx) { return (' + '${escapedTransformedCode}' + '); }'
10130
+ );
10131
+
10132
+ return function(state) {
10133
+ try {
10134
+ var __zenith = window.__zenith || {};
10135
+ var zenCollection = __zenith.zenCollection || function(name) { return { get: function() { return []; } }; };
10136
+ var createZenOrder = __zenith.createZenOrder || function(sections) { return { sections: [], getSectionBySlug: function() { return null; }, getDocBySlug: function() { return null; } }; };
10137
+
10138
+ // Merge window globals (script variables) with state
10139
+ // State takes precedence over window globals
10140
+ var __ctx = Object.assign({}, window, { zenCollection: zenCollection, createZenOrder: createZenOrder }, state || {});
10141
+
10142
+ return evalFn(__ctx);
10143
+ } catch (e) {
10144
+ console.warn('[Zenith] Expression evaluation error:', ${jsonEscapedCode}, e);
10145
+ return undefined;
10117
10146
  }
10118
- } catch (e) {
10119
- console.warn('[Zenith] Expression evaluation error:', ${jsonEscapedCode}, e);
10120
- return undefined;
10121
- }
10122
- };`;
10147
+ };
10148
+ })();`;
10123
10149
  }
10124
10150
  function generateExpressionWrappers(expressions, dependencies, loopContexts) {
10125
10151
  if (expressions.length === 0) {
@@ -10218,7 +10244,10 @@ ${indent}}
10218
10244
  const conditionId = `cond_${varCounter.count++}`;
10219
10245
  let code = `${indent}const ${containerVar} = document.createDocumentFragment();
10220
10246
  `;
10221
- code += `${indent}const ${conditionId}_result = (function() { with (state) { return ${condNode.condition}; } })();
10247
+ const escapedCondition = condNode.condition.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
10248
+ code += `${indent}const ${conditionId}_evalFn = new Function('state', 'with (state) { return (' + '${escapedCondition}' + '); }');
10249
+ `;
10250
+ code += `${indent}const ${conditionId}_result = (function() { try { return ${conditionId}_evalFn(state); } catch(e) { return false; } })();
10222
10251
  `;
10223
10252
  code += `${indent}if (${conditionId}_result) {
10224
10253
  `;
@@ -10248,7 +10277,10 @@ ${indent}}
10248
10277
  const conditionId = `opt_${varCounter.count++}`;
10249
10278
  let code = `${indent}const ${containerVar} = document.createDocumentFragment();
10250
10279
  `;
10251
- code += `${indent}const ${conditionId}_result = (function() { with (state) { return ${optNode.condition}; } })();
10280
+ const escapedCondition = optNode.condition.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
10281
+ code += `${indent}const ${conditionId}_evalFn = new Function('state', 'with (state) { return (' + '${escapedCondition}' + '); }');
10282
+ `;
10283
+ code += `${indent}const ${conditionId}_result = (function() { try { return ${conditionId}_evalFn(state); } catch(e) { return false; } })();
10252
10284
  `;
10253
10285
  code += `${indent}if (${conditionId}_result) {
10254
10286
  `;
@@ -10269,7 +10301,10 @@ ${indent}}
10269
10301
  const loopId = `loop_${varCounter.count++}`;
10270
10302
  let code = `${indent}const ${containerVar} = document.createDocumentFragment();
10271
10303
  `;
10272
- code += `${indent}const ${loopId}_items = (function() { with (state) { return ${loopNode.source}; } })() || [];
10304
+ const escapedSource = loopNode.source.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
10305
+ code += `${indent}const ${loopId}_evalFn = new Function('state', 'with (state) { return (' + '${escapedSource}' + '); }');
10306
+ `;
10307
+ code += `${indent}const ${loopId}_items = (function() { try { return ${loopId}_evalFn(state); } catch(e) { return []; } })() || [];
10273
10308
  `;
10274
10309
  const itemVar = loopNode.itemVar;
10275
10310
  const indexVar = loopNode.indexVar || `${loopId}_idx`;
@@ -10718,154 +10753,6 @@ ${registryCode}
10718
10753
  }`;
10719
10754
  }
10720
10755
 
10721
- // compiler/runtime/navigation.ts
10722
- var routeCache = new Map;
10723
- function generateNavigationRuntime() {
10724
- return `
10725
- // Zenith Navigation Runtime (Phase 7)
10726
- (function() {
10727
- 'use strict';
10728
-
10729
- // Route cache
10730
- const __zen_routeCache = new Map();
10731
-
10732
- // Current route state
10733
- let __zen_currentRoute = '';
10734
- let __zen_navigationInProgress = false;
10735
-
10736
- /**
10737
- * Prefetch a route
10738
- */
10739
- async function prefetchRoute(routePath) {
10740
- const normalizedPath = routePath === '' ? '/' : routePath;
10741
-
10742
- if (__zen_routeCache.has(normalizedPath)) {
10743
- return Promise.resolve();
10744
- }
10745
-
10746
- try {
10747
- // Fetch compiled HTML + JS
10748
- // This is a placeholder - in production, fetch from build output
10749
- const cacheEntry = {
10750
- html: '<!-- Prefetched: ' + normalizedPath + ' -->',
10751
- js: '// Prefetched runtime: ' + normalizedPath,
10752
- styles: [],
10753
- routePath: normalizedPath,
10754
- compiledAt: Date.now()
10755
- };
10756
-
10757
- __zen_routeCache.set(normalizedPath, cacheEntry);
10758
- } catch (error) {
10759
- console.warn('[Zenith] Prefetch failed:', routePath, error);
10760
- throw error;
10761
- }
10762
- }
10763
-
10764
- /**
10765
- * Navigate to route with explicit data
10766
- */
10767
- async function navigate(routePath, options) {
10768
- options = options || {};
10769
-
10770
- if (__zen_navigationInProgress) {
10771
- console.warn('[Zenith] Navigation in progress');
10772
- return;
10773
- }
10774
-
10775
- __zen_navigationInProgress = true;
10776
-
10777
- try {
10778
- const normalizedPath = routePath === '' ? '/' : routePath;
10779
-
10780
- // Get cached route or prefetch
10781
- let cacheEntry = __zen_routeCache.get(normalizedPath);
10782
- if (!cacheEntry && options.prefetch !== false) {
10783
- await prefetchRoute(normalizedPath);
10784
- cacheEntry = __zen_routeCache.get(normalizedPath);
10785
- }
10786
-
10787
- if (!cacheEntry) {
10788
- throw new Error('Route not found: ' + normalizedPath);
10789
- }
10790
-
10791
- // Get outlet
10792
- const outlet = document.querySelector('#zenith-outlet') || document.querySelector('[data-zen-outlet]');
10793
- if (!outlet) {
10794
- throw new Error('Router outlet not found');
10795
- }
10796
-
10797
- // Mount HTML
10798
- outlet.innerHTML = cacheEntry.html;
10799
-
10800
- // Execute runtime JS
10801
- if (cacheEntry.js) {
10802
- const script = document.createElement('script');
10803
- script.textContent = cacheEntry.js;
10804
- document.head.appendChild(script);
10805
- document.head.removeChild(script);
10806
- }
10807
-
10808
- // Hydrate with explicit data
10809
- if (window.zenithHydrate) {
10810
- const state = window.__ZENITH_STATE__ || {};
10811
- window.zenithHydrate(
10812
- state,
10813
- options.loaderData || {},
10814
- options.props || {},
10815
- options.stores || {},
10816
- outlet
10817
- );
10818
- }
10819
-
10820
- // Update history
10821
- const url = normalizedPath + (window.location.search || '');
10822
- if (options.replace) {
10823
- window.history.replaceState({ route: normalizedPath }, '', url);
10824
- } else {
10825
- window.history.pushState({ route: normalizedPath }, '', url);
10826
- }
10827
-
10828
- __zen_currentRoute = normalizedPath;
10829
-
10830
- // Dispatch event
10831
- window.dispatchEvent(new CustomEvent('zenith:navigate', {
10832
- detail: { route: normalizedPath, options: options }
10833
- }));
10834
- } catch (error) {
10835
- console.error('[Zenith] Navigation error:', error);
10836
- throw error;
10837
- } finally {
10838
- __zen_navigationInProgress = false;
10839
- }
10840
- }
10841
-
10842
- /**
10843
- * Handle browser history
10844
- */
10845
- function setupHistoryHandling() {
10846
- window.addEventListener('popstate', function(event) {
10847
- const state = event.state;
10848
- const routePath = state && state.route ? state.route : window.location.pathname;
10849
-
10850
- navigate(routePath, { replace: true, prefetch: false }).catch(function(error) {
10851
- console.error('[Zenith] History navigation error:', error);
10852
- });
10853
- });
10854
- }
10855
-
10856
- // Initialize history handling
10857
- setupHistoryHandling();
10858
-
10859
- // Expose API
10860
- if (typeof window !== 'undefined') {
10861
- window.__zenith_navigate = navigate;
10862
- window.__zenith_prefetch = prefetchRoute;
10863
- window.navigate = navigate; // Global convenience
10864
- }
10865
- })();
10866
- `;
10867
- }
10868
-
10869
10756
  // compiler/parse/scriptAnalysis.ts
10870
10757
  function extractStateDeclarations(script) {
10871
10758
  const states = new Map;
@@ -16469,7 +16356,7 @@ async function transformIR(ir) {
16469
16356
  const renderFunction = generateDOMFunction(ir.template.nodes, ir.template.expressions, "renderDynamicPage");
16470
16357
  const hydrateFunction = generateHydrateFunction();
16471
16358
  const hydrationRuntime = generateHydrationRuntime();
16472
- const navigationRuntime = generateNavigationRuntime();
16359
+ const navigationRuntime = "";
16473
16360
  const expressionRegistry = generateExpressionRegistry(ir.template.expressions);
16474
16361
  const stylesCode = generateStyleInjection(ir.styles);
16475
16362
  const scriptContent = ir.script?.raw || "";
@@ -16502,6 +16389,7 @@ async function transformIR(ir) {
16502
16389
  }
16503
16390
  function generateRuntimeBundle(parts) {
16504
16391
  const functionRegistrations = extractFunctionRegistrations(parts.scriptCode);
16392
+ const variableRegistrations = extractVariableRegistrations(parts.scriptCode);
16505
16393
  const npmImportsHeader = parts.npmImports.length > 0 ? `// NPM Imports (hoisted from component scripts)
16506
16394
  ${emitImports(parts.npmImports)}
16507
16395
 
@@ -16525,6 +16413,8 @@ ${parts.scriptCode ? parts.scriptCode : ""}
16525
16413
 
16526
16414
  ${functionRegistrations}
16527
16415
 
16416
+ ${variableRegistrations}
16417
+
16528
16418
  ${parts.stateInitCode ? `// State initialization
16529
16419
  ${parts.stateInitCode}` : ""}
16530
16420
 
@@ -16635,6 +16525,25 @@ function extractFunctionRegistrations(scriptCode) {
16635
16525
  return `// Register functions on window for event handlers
16636
16526
  ${registrations}`;
16637
16527
  }
16528
+ function extractVariableRegistrations(scriptCode) {
16529
+ if (!scriptCode)
16530
+ return "";
16531
+ const varPattern = /(?:const|let)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\s*=/g;
16532
+ const varNames = [];
16533
+ let match;
16534
+ while ((match = varPattern.exec(scriptCode)) !== null) {
16535
+ if (match[1]) {
16536
+ varNames.push(match[1]);
16537
+ }
16538
+ }
16539
+ if (varNames.length === 0) {
16540
+ return "";
16541
+ }
16542
+ const registrations = varNames.map((name) => ` if (typeof ${name} !== 'undefined') window.${name} = ${name};`).join(`
16543
+ `);
16544
+ return `// Register script variables on window for expression access
16545
+ ${registrations}`;
16546
+ }
16638
16547
  function generateHydrateFunction() {
16639
16548
  return `function hydrate(root, state) {
16640
16549
  if (!root) {
@@ -17051,8 +16960,7 @@ ${mergedStyles}
17051
16960
  </style>
17052
16961
  `.trim();
17053
16962
  }
17054
-
17055
- // router/manifest.ts
16963
+ // node_modules/@zenithbuild/router/src/manifest.ts
17056
16964
  import fs4 from "fs";
17057
16965
  import path4 from "path";
17058
16966
  var SEGMENT_SCORES = {
@@ -17174,7 +17082,11 @@ function generateRouteDefinition(filePath, pagesDir) {
17174
17082
  filePath
17175
17083
  };
17176
17084
  }
17177
-
17085
+ // node_modules/@zenithbuild/router/src/runtime.ts
17086
+ var routeListeners = new Set;
17087
+ var prefetchedRoutes = new Set;
17088
+ // node_modules/@zenithbuild/router/src/navigation/zen-link.ts
17089
+ var prefetchedRoutes2 = new Set;
17178
17090
  // runtime/bundle-generator.ts
17179
17091
  function generateBundleJS() {
17180
17092
  return `/*!
@@ -17800,7 +17712,16 @@ function generateBundleJS() {
17800
17712
  function defineSchema(name, schema) { schemaRegistry.set(name, schema); }
17801
17713
 
17802
17714
  function zenCollection(collectionName) {
17803
- const data = (global.__ZENITH_CONTENT__ && global.__ZENITH_CONTENT__[collectionName]) || [];
17715
+ // Access plugin data from the neutral envelope
17716
+ // Content plugin stores all items under 'content' namespace
17717
+ const pluginData = global.__ZENITH_PLUGIN_DATA__ || {};
17718
+ const contentItems = pluginData.content || [];
17719
+
17720
+ // Filter by collection name (plugin owns data structure, runtime just filters)
17721
+ const data = Array.isArray(contentItems)
17722
+ ? contentItems.filter(item => item && item.collection === collectionName)
17723
+ : [];
17724
+
17804
17725
  return new ZenCollection(data);
17805
17726
  }
17806
17727
 
@@ -18036,6 +17957,320 @@ function generateBundleJS() {
18036
17957
  global.processRawSections = processRawSections;
18037
17958
  global.slugify = slugify;
18038
17959
 
17960
+ // ============================================
17961
+ // SPA Router Runtime
17962
+ // ============================================
17963
+
17964
+ // Router state
17965
+ // Current route state
17966
+ var currentRoute = {
17967
+ path: '/',
17968
+ params: {},
17969
+ query: {}
17970
+ };
17971
+
17972
+ // Route listeners
17973
+ var routeListeners = new Set();
17974
+
17975
+ // Router outlet element
17976
+ var routerOutlet = null;
17977
+
17978
+ // Page modules registry
17979
+ var pageModules = {};
17980
+
17981
+ // Route manifest
17982
+ var routeManifest = [];
17983
+
17984
+ /**
17985
+ * Parse query string
17986
+ */
17987
+ function parseQueryString(search) {
17988
+ var query = {};
17989
+ if (!search || search === '?') return query;
17990
+ var params = new URLSearchParams(search);
17991
+ params.forEach(function(value, key) { query[key] = value; });
17992
+ return query;
17993
+ }
17994
+
17995
+ /**
17996
+ * Resolve route from pathname
17997
+ */
17998
+ function resolveRoute(pathname) {
17999
+ var normalizedPath = pathname === '' ? '/' : pathname;
18000
+
18001
+ for (var i = 0; i < routeManifest.length; i++) {
18002
+ var route = routeManifest[i];
18003
+ var match = route.regex.exec(normalizedPath);
18004
+ if (match) {
18005
+ var params = {};
18006
+ for (var j = 0; j < route.paramNames.length; j++) {
18007
+ var paramValue = match[j + 1];
18008
+ if (paramValue !== undefined) {
18009
+ params[route.paramNames[j]] = decodeURIComponent(paramValue);
18010
+ }
18011
+ }
18012
+ return { record: route, params: params };
18013
+ }
18014
+ }
18015
+ return null;
18016
+ }
18017
+
18018
+ /**
18019
+ * Clean up previous page
18020
+ */
18021
+ function cleanupPreviousPage() {
18022
+ // Trigger unmount lifecycle hooks
18023
+ if (global.__zenith && global.__zenith.triggerUnmount) {
18024
+ global.__zenith.triggerUnmount();
18025
+ }
18026
+
18027
+ // Remove previous page styles
18028
+ var prevStyles = document.querySelectorAll('style[data-zen-page-style]');
18029
+ prevStyles.forEach(function(s) { s.remove(); });
18030
+
18031
+ // Clean up window properties
18032
+ if (global.__zenith_cleanup) {
18033
+ global.__zenith_cleanup.forEach(function(key) {
18034
+ try { delete global[key]; } catch(e) {}
18035
+ });
18036
+ }
18037
+ global.__zenith_cleanup = [];
18038
+ }
18039
+
18040
+ /**
18041
+ * Inject styles
18042
+ */
18043
+ function injectStyles(styles) {
18044
+ styles.forEach(function(content, i) {
18045
+ var style = document.createElement('style');
18046
+ style.setAttribute('data-zen-page-style', String(i));
18047
+ style.textContent = content;
18048
+ document.head.appendChild(style);
18049
+ });
18050
+ }
18051
+
18052
+ /**
18053
+ * Execute scripts
18054
+ */
18055
+ function executeScripts(scripts) {
18056
+ scripts.forEach(function(content) {
18057
+ try {
18058
+ var fn = new Function(content);
18059
+ fn();
18060
+ } catch (e) {
18061
+ console.error('[Zenith Router] Script error:', e);
18062
+ }
18063
+ });
18064
+ }
18065
+
18066
+ /**
18067
+ * Render page
18068
+ */
18069
+ function renderPage(pageModule) {
18070
+ if (!routerOutlet) {
18071
+ console.warn('[Zenith Router] No router outlet');
18072
+ return;
18073
+ }
18074
+
18075
+ cleanupPreviousPage();
18076
+ routerOutlet.innerHTML = pageModule.html;
18077
+ injectStyles(pageModule.styles);
18078
+ executeScripts(pageModule.scripts);
18079
+
18080
+ // Trigger mount lifecycle hooks after scripts are executed
18081
+ if (global.__zenith && global.__zenith.triggerMount) {
18082
+ global.__zenith.triggerMount();
18083
+ }
18084
+ }
18085
+
18086
+ /**
18087
+ * Notify listeners
18088
+ */
18089
+ function notifyListeners(route, prevRoute) {
18090
+ routeListeners.forEach(function(listener) {
18091
+ try { listener(route, prevRoute); } catch(e) {}
18092
+ });
18093
+ }
18094
+
18095
+ /**
18096
+ * Resolve and render
18097
+ */
18098
+ function resolveAndRender(path, query, updateHistory, replace) {
18099
+ replace = replace || false;
18100
+ var prevRoute = Object.assign({}, currentRoute);
18101
+ var resolved = resolveRoute(path);
18102
+
18103
+ if (resolved) {
18104
+ currentRoute = {
18105
+ path: path,
18106
+ params: resolved.params,
18107
+ query: query,
18108
+ matched: resolved.record
18109
+ };
18110
+
18111
+ var pageModule = pageModules[resolved.record.path];
18112
+ if (pageModule) {
18113
+ renderPage(pageModule);
18114
+ }
18115
+ } else {
18116
+ currentRoute = { path: path, params: {}, query: query, matched: undefined };
18117
+ console.warn('[Zenith Router] No route matched:', path);
18118
+
18119
+ // Render 404 if available
18120
+ if (routerOutlet) {
18121
+ routerOutlet.innerHTML = '<div style="padding: 2rem; text-align: center;"><h1>404</h1><p>Page not found</p></div>';
18122
+ }
18123
+ }
18124
+
18125
+ if (updateHistory) {
18126
+ var url = path + (Object.keys(query).length ? '?' + new URLSearchParams(query) : '');
18127
+ if (replace) {
18128
+ history.replaceState(null, '', url);
18129
+ } else {
18130
+ history.pushState(null, '', url);
18131
+ }
18132
+ }
18133
+
18134
+ notifyListeners(currentRoute, prevRoute);
18135
+ global.__zenith_route = currentRoute;
18136
+ }
18137
+
18138
+ /**
18139
+ * Handle popstate
18140
+ */
18141
+ function handlePopState() {
18142
+ resolveAndRender(
18143
+ location.pathname,
18144
+ parseQueryString(location.search),
18145
+ false,
18146
+ false
18147
+ );
18148
+ }
18149
+
18150
+ /**
18151
+ * Navigate (public API)
18152
+ */
18153
+ function navigate(to, options) {
18154
+ options = options || {};
18155
+ var path, query = {};
18156
+
18157
+ if (to.includes('?')) {
18158
+ var parts = to.split('?');
18159
+ path = parts[0];
18160
+ query = parseQueryString('?' + parts[1]);
18161
+ } else {
18162
+ path = to;
18163
+ }
18164
+
18165
+ if (!path.startsWith('/')) {
18166
+ var currentDir = currentRoute.path.split('/').slice(0, -1).join('/');
18167
+ path = currentDir + '/' + path;
18168
+ }
18169
+
18170
+ var normalizedPath = path === '' ? '/' : path;
18171
+ var currentPath = currentRoute.path === '' ? '/' : currentRoute.path;
18172
+ var isSamePath = normalizedPath === currentPath;
18173
+
18174
+ if (isSamePath && JSON.stringify(query) === JSON.stringify(currentRoute.query)) {
18175
+ return;
18176
+ }
18177
+
18178
+ // Dev mode: If no route manifest is loaded, use browser navigation
18179
+ // This allows ZenLink to work in dev server where pages are served fresh
18180
+ if (routeManifest.length === 0) {
18181
+ var url = normalizedPath + (Object.keys(query).length ? '?' + new URLSearchParams(query) : '');
18182
+ if (options.replace) {
18183
+ location.replace(url);
18184
+ } else {
18185
+ location.href = url;
18186
+ }
18187
+ return;
18188
+ }
18189
+
18190
+ resolveAndRender(path, query, true, options.replace || false);
18191
+ }
18192
+
18193
+ /**
18194
+ * Get current route
18195
+ */
18196
+ function getRoute() {
18197
+ return Object.assign({}, currentRoute);
18198
+ }
18199
+
18200
+ /**
18201
+ * Subscribe to route changes
18202
+ */
18203
+ function onRouteChange(listener) {
18204
+ routeListeners.add(listener);
18205
+ return function() { routeListeners.delete(listener); };
18206
+ }
18207
+
18208
+ /**
18209
+ * Check if path is active
18210
+ */
18211
+ function isActive(path, exact) {
18212
+ if (exact) return currentRoute.path === path;
18213
+ return currentRoute.path.startsWith(path);
18214
+ }
18215
+
18216
+ /**
18217
+ * Prefetch a route
18218
+ */
18219
+ var prefetchedRoutes = new Set();
18220
+ function prefetch(path) {
18221
+ var normalizedPath = path === '' ? '/' : path;
18222
+
18223
+ if (prefetchedRoutes.has(normalizedPath)) {
18224
+ return Promise.resolve();
18225
+ }
18226
+ prefetchedRoutes.add(normalizedPath);
18227
+
18228
+ var resolved = resolveRoute(normalizedPath);
18229
+ if (!resolved) {
18230
+ return Promise.resolve();
18231
+ }
18232
+
18233
+ // In SPA build, all modules are already loaded
18234
+ return Promise.resolve();
18235
+ }
18236
+
18237
+ /**
18238
+ * Initialize router
18239
+ */
18240
+ function initRouter(manifest, modules, outlet) {
18241
+ routeManifest = manifest;
18242
+ Object.assign(pageModules, modules);
18243
+
18244
+ if (outlet) {
18245
+ routerOutlet = typeof outlet === 'string'
18246
+ ? document.querySelector(outlet)
18247
+ : outlet;
18248
+ }
18249
+
18250
+ window.addEventListener('popstate', handlePopState);
18251
+
18252
+ // Initial route resolution
18253
+ resolveAndRender(
18254
+ location.pathname,
18255
+ parseQueryString(location.search),
18256
+ false
18257
+ );
18258
+ }
18259
+
18260
+ // Expose router API globally
18261
+ global.__zenith_router = {
18262
+ navigate: navigate,
18263
+ getRoute: getRoute,
18264
+ onRouteChange: onRouteChange,
18265
+ isActive: isActive,
18266
+ prefetch: prefetch,
18267
+ initRouter: initRouter
18268
+ };
18269
+
18270
+ // Also expose navigate directly for convenience
18271
+ global.navigate = navigate;
18272
+
18273
+
18039
18274
  // ============================================
18040
18275
  // HMR Client (Development Only)
18041
18276
  // ============================================
@@ -18085,1400 +18320,46 @@ function generateBundleJS() {
18085
18320
  `;
18086
18321
  }
18087
18322
 
18088
- // cli/utils/content.ts
18323
+ // core/config/loader.ts
18089
18324
  import fs5 from "fs";
18090
18325
  import path5 from "path";
18091
-
18092
- // node_modules/marked/lib/marked.esm.js
18093
- function L() {
18094
- return { async: false, breaks: false, extensions: null, gfm: true, hooks: null, pedantic: false, renderer: null, silent: false, tokenizer: null, walkTokens: null };
18095
- }
18096
- var T = L();
18097
- function Z(u) {
18098
- T = u;
18099
- }
18100
- var C = { exec: () => null };
18101
- function k(u, e = "") {
18102
- let t = typeof u == "string" ? u : u.source, n = { replace: (r, i2) => {
18103
- let s = typeof i2 == "string" ? i2 : i2.source;
18104
- return s = s.replace(m.caret, "$1"), t = t.replace(r, s), n;
18105
- }, getRegex: () => new RegExp(t, e) };
18106
- return n;
18107
- }
18108
- var me = (() => {
18109
- try {
18110
- return !!new RegExp("(?<=1)(?<!1)");
18111
- } catch {
18112
- return false;
18326
+ async function loadZenithConfig(projectRoot) {
18327
+ const configPaths = [
18328
+ path5.join(projectRoot, "zenith.config.ts"),
18329
+ path5.join(projectRoot, "zenith.config.js"),
18330
+ path5.join(projectRoot, "zenith.config.mjs")
18331
+ ];
18332
+ let configPath = null;
18333
+ for (const p of configPaths) {
18334
+ if (fs5.existsSync(p)) {
18335
+ configPath = p;
18336
+ break;
18337
+ }
18113
18338
  }
18114
- })();
18115
- var m = { codeRemoveIndent: /^(?: {1,4}| {0,3}\t)/gm, outputLinkReplace: /\\([\[\]])/g, indentCodeCompensation: /^(\s+)(?:```)/, beginningSpace: /^\s+/, endingHash: /#$/, startingSpaceChar: /^ /, endingSpaceChar: / $/, nonSpaceChar: /[^ ]/, newLineCharGlobal: /\n/g, tabCharGlobal: /\t/g, multipleSpaceGlobal: /\s+/g, blankLine: /^[ \t]*$/, doubleBlankLine: /\n[ \t]*\n[ \t]*$/, blockquoteStart: /^ {0,3}>/, blockquoteSetextReplace: /\n {0,3}((?:=+|-+) *)(?=\n|$)/g, blockquoteSetextReplace2: /^ {0,3}>[ \t]?/gm, listReplaceTabs: /^\t+/, listReplaceNesting: /^ {1,4}(?=( {4})*[^ ])/g, listIsTask: /^\[[ xX]\] +\S/, listReplaceTask: /^\[[ xX]\] +/, listTaskCheckbox: /\[[ xX]\]/, anyLine: /\n.*\n/, hrefBrackets: /^<(.*)>$/, tableDelimiter: /[:|]/, tableAlignChars: /^\||\| *$/g, tableRowBlankLine: /\n[ \t]*$/, tableAlignRight: /^ *-+: *$/, tableAlignCenter: /^ *:-+: *$/, tableAlignLeft: /^ *:-+ *$/, startATag: /^<a /i, endATag: /^<\/a>/i, startPreScriptTag: /^<(pre|code|kbd|script)(\s|>)/i, endPreScriptTag: /^<\/(pre|code|kbd|script)(\s|>)/i, startAngleBracket: /^</, endAngleBracket: />$/, pedanticHrefTitle: /^([^'"]*[^\s])\s+(['"])(.*)\2/, unicodeAlphaNumeric: /[\p{L}\p{N}]/u, escapeTest: /[&<>"']/, escapeReplace: /[&<>"']/g, escapeTestNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/, escapeReplaceNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g, unescapeTest: /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig, caret: /(^|[^\[])\^/g, percentDecode: /%25/g, findPipe: /\|/g, splitPipe: / \|/, slashPipe: /\\\|/g, carriageReturn: /\r\n|\r/g, spaceLine: /^ +$/gm, notSpaceStart: /^\S*/, endingNewline: /\n$/, listItemRegex: (u) => new RegExp(`^( {0,3}${u})((?:[ ][^\\n]*)?(?:\\n|$))`), nextBulletRegex: (u) => new RegExp(`^ {0,${Math.min(3, u - 1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`), hrRegex: (u) => new RegExp(`^ {0,${Math.min(3, u - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`), fencesBeginRegex: (u) => new RegExp(`^ {0,${Math.min(3, u - 1)}}(?:\`\`\`|~~~)`), headingBeginRegex: (u) => new RegExp(`^ {0,${Math.min(3, u - 1)}}#`), htmlBeginRegex: (u) => new RegExp(`^ {0,${Math.min(3, u - 1)}}<(?:[a-z].*>|!--)`, "i") };
18116
- var xe = /^(?:[ \t]*(?:\n|$))+/;
18117
- var be = /^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/;
18118
- var Re = /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/;
18119
- var I = /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/;
18120
- var Te = /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/;
18121
- var N = /(?:[*+-]|\d{1,9}[.)])/;
18122
- var re = /^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/;
18123
- var se = k(re).replace(/bull/g, N).replace(/blockCode/g, /(?: {4}| {0,3}\t)/).replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g, / {0,3}>/).replace(/heading/g, / {0,3}#{1,6}/).replace(/html/g, / {0,3}<[^\n>]+>\n/).replace(/\|table/g, "").getRegex();
18124
- var Oe = k(re).replace(/bull/g, N).replace(/blockCode/g, /(?: {4}| {0,3}\t)/).replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g, / {0,3}>/).replace(/heading/g, / {0,3}#{1,6}/).replace(/html/g, / {0,3}<[^\n>]+>\n/).replace(/table/g, / {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex();
18125
- var Q = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/;
18126
- var we = /^[^\n]+/;
18127
- var F = /(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/;
18128
- var ye = k(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label", F).replace("title", /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex();
18129
- var Pe = k(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g, N).getRegex();
18130
- var v = "address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul";
18131
- var j = /<!--(?:-?>|[\s\S]*?(?:-->|$))/;
18132
- var Se = k("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$))", "i").replace("comment", j).replace("tag", v).replace("attribute", / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex();
18133
- var ie = k(Q).replace("hr", I).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("|lheading", "").replace("|table", "").replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)]) ").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", v).getRegex();
18134
- var $e = k(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph", ie).getRegex();
18135
- var U = { blockquote: $e, code: be, def: ye, fences: Re, heading: Te, hr: I, html: Se, lheading: se, list: Pe, newline: xe, paragraph: ie, table: C, text: we };
18136
- var te = k("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr", I).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("blockquote", " {0,3}>").replace("code", "(?: {4}| {0,3}\t)[^\\n]").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)]) ").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", v).getRegex();
18137
- var _e = { ...U, lheading: Oe, table: te, paragraph: k(Q).replace("hr", I).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("|lheading", "").replace("table", te).replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)]) ").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", v).getRegex() };
18138
- var Le = { ...U, html: k(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment", j).replace(/tag/g, "(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(), def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/, heading: /^(#{1,6})(.*)(?:\n+|$)/, fences: C, lheading: /^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/, paragraph: k(Q).replace("hr", I).replace("heading", ` *#{1,6} *[^
18139
- ]`).replace("lheading", se).replace("|table", "").replace("blockquote", " {0,3}>").replace("|fences", "").replace("|list", "").replace("|html", "").replace("|tag", "").getRegex() };
18140
- var Me = /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/;
18141
- var ze = /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/;
18142
- var oe = /^( {2,}|\\)\n(?!\s*$)/;
18143
- var Ae = /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/;
18144
- var D = /[\p{P}\p{S}]/u;
18145
- var K = /[\s\p{P}\p{S}]/u;
18146
- var ae = /[^\s\p{P}\p{S}]/u;
18147
- var Ce = k(/^((?![*_])punctSpace)/, "u").replace(/punctSpace/g, K).getRegex();
18148
- var le = /(?!~)[\p{P}\p{S}]/u;
18149
- var Ie = /(?!~)[\s\p{P}\p{S}]/u;
18150
- var Ee = /(?:[^\s\p{P}\p{S}]|~)/u;
18151
- var Be = k(/link|precode-code|html/, "g").replace("link", /\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-", me ? "(?<!`)()" : "(^^|[^`])").replace("code", /(?<b>`+)[^`]+\k<b>(?!`)/).replace("html", /<(?! )[^<>]*?>/).getRegex();
18152
- var ue = /^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/;
18153
- var qe = k(ue, "u").replace(/punct/g, D).getRegex();
18154
- var ve = k(ue, "u").replace(/punct/g, le).getRegex();
18155
- var pe = "^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)";
18156
- var De = k(pe, "gu").replace(/notPunctSpace/g, ae).replace(/punctSpace/g, K).replace(/punct/g, D).getRegex();
18157
- var He = k(pe, "gu").replace(/notPunctSpace/g, Ee).replace(/punctSpace/g, Ie).replace(/punct/g, le).getRegex();
18158
- var Ze = k("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)", "gu").replace(/notPunctSpace/g, ae).replace(/punctSpace/g, K).replace(/punct/g, D).getRegex();
18159
- var Ge = k(/\\(punct)/, "gu").replace(/punct/g, D).getRegex();
18160
- var Ne = k(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme", /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email", /[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex();
18161
- var Qe = k(j).replace("(?:-->|$)", "-->").getRegex();
18162
- var Fe = k("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment", Qe).replace("attribute", /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex();
18163
- var q = /(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+[^`]*?`+(?!`)|[^\[\]\\`])*?/;
18164
- var je = k(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label", q).replace("href", /<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title", /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex();
18165
- var ce = k(/^!?\[(label)\]\[(ref)\]/).replace("label", q).replace("ref", F).getRegex();
18166
- var he = k(/^!?\[(ref)\](?:\[\])?/).replace("ref", F).getRegex();
18167
- var Ue = k("reflink|nolink(?!\\()", "g").replace("reflink", ce).replace("nolink", he).getRegex();
18168
- var ne = /[hH][tT][tT][pP][sS]?|[fF][tT][pP]/;
18169
- var W = { _backpedal: C, anyPunctuation: Ge, autolink: Ne, blockSkip: Be, br: oe, code: ze, del: C, emStrongLDelim: qe, emStrongRDelimAst: De, emStrongRDelimUnd: Ze, escape: Me, link: je, nolink: he, punctuation: Ce, reflink: ce, reflinkSearch: Ue, tag: Fe, text: Ae, url: C };
18170
- var Ke = { ...W, link: k(/^!?\[(label)\]\((.*?)\)/).replace("label", q).getRegex(), reflink: k(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label", q).getRegex() };
18171
- var G = { ...W, emStrongRDelimAst: He, emStrongLDelim: ve, url: k(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol", ne).replace("email", /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(), _backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/, del: /^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/, text: k(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol", ne).getRegex() };
18172
- var We = { ...G, br: k(oe).replace("{2,}", "*").getRegex(), text: k(G.text).replace("\\b_", "\\b_| {2,}\\n").replace(/\{2,\}/g, "*").getRegex() };
18173
- var E = { normal: U, gfm: _e, pedantic: Le };
18174
- var M = { normal: W, gfm: G, breaks: We, pedantic: Ke };
18175
- var Xe = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" };
18176
- var ke = (u) => Xe[u];
18177
- function w(u, e) {
18178
- if (e) {
18179
- if (m.escapeTest.test(u))
18180
- return u.replace(m.escapeReplace, ke);
18181
- } else if (m.escapeTestNoEncode.test(u))
18182
- return u.replace(m.escapeReplaceNoEncode, ke);
18183
- return u;
18184
- }
18185
- function X(u) {
18186
- try {
18187
- u = encodeURI(u).replace(m.percentDecode, "%");
18188
- } catch {
18189
- return null;
18339
+ if (!configPath) {
18340
+ return { plugins: [] };
18190
18341
  }
18191
- return u;
18192
- }
18193
- function J(u, e) {
18194
- let t = u.replace(m.findPipe, (i2, s, a) => {
18195
- let o = false, l = s;
18196
- for (;--l >= 0 && a[l] === "\\"; )
18197
- o = !o;
18198
- return o ? "|" : " |";
18199
- }), n = t.split(m.splitPipe), r = 0;
18200
- if (n[0].trim() || n.shift(), n.length > 0 && !n.at(-1)?.trim() && n.pop(), e)
18201
- if (n.length > e)
18202
- n.splice(e);
18203
- else
18204
- for (;n.length < e; )
18205
- n.push("");
18206
- for (;r < n.length; r++)
18207
- n[r] = n[r].trim().replace(m.slashPipe, "|");
18208
- return n;
18209
- }
18210
- function z(u, e, t) {
18211
- let n = u.length;
18212
- if (n === 0)
18213
- return "";
18214
- let r = 0;
18215
- for (;r < n; ) {
18216
- let i2 = u.charAt(n - r - 1);
18217
- if (i2 === e && !t)
18218
- r++;
18219
- else if (i2 !== e && t)
18220
- r++;
18221
- else
18222
- break;
18342
+ try {
18343
+ const configModule = await import(configPath);
18344
+ const config = configModule.default || configModule;
18345
+ if (typeof config !== "object" || config === null) {
18346
+ console.warn(`[Zenith] Invalid config format in ${configPath}`);
18347
+ return { plugins: [] };
18348
+ }
18349
+ return config;
18350
+ } catch (error3) {
18351
+ const message = error3 instanceof Error ? error3.message : String(error3);
18352
+ console.error(`[Zenith] Failed to load config from ${configPath}:`, message);
18353
+ return { plugins: [] };
18223
18354
  }
18224
- return u.slice(0, n - r);
18225
18355
  }
18226
- function de(u, e) {
18227
- if (u.indexOf(e[1]) === -1)
18228
- return -1;
18229
- let t = 0;
18230
- for (let n = 0;n < u.length; n++)
18231
- if (u[n] === "\\")
18232
- n++;
18233
- else if (u[n] === e[0])
18234
- t++;
18235
- else if (u[n] === e[1] && (t--, t < 0))
18236
- return n;
18237
- return t > 0 ? -2 : -1;
18238
- }
18239
- function ge(u, e, t, n, r) {
18240
- let i2 = e.href, s = e.title || null, a = u[1].replace(r.other.outputLinkReplace, "$1");
18241
- n.state.inLink = true;
18242
- let o = { type: u[0].charAt(0) === "!" ? "image" : "link", raw: t, href: i2, title: s, text: a, tokens: n.inlineTokens(a) };
18243
- return n.state.inLink = false, o;
18244
- }
18245
- function Je(u, e, t) {
18246
- let n = u.match(t.other.indentCodeCompensation);
18247
- if (n === null)
18248
- return e;
18249
- let r = n[1];
18250
- return e.split(`
18251
- `).map((i2) => {
18252
- let s = i2.match(t.other.beginningSpace);
18253
- if (s === null)
18254
- return i2;
18255
- let [a] = s;
18256
- return a.length >= r.length ? i2.slice(r.length) : i2;
18257
- }).join(`
18258
- `);
18259
- }
18260
- var y = class {
18261
- options;
18262
- rules;
18263
- lexer;
18264
- constructor(e) {
18265
- this.options = e || T;
18266
- }
18267
- space(e) {
18268
- let t = this.rules.block.newline.exec(e);
18269
- if (t && t[0].length > 0)
18270
- return { type: "space", raw: t[0] };
18271
- }
18272
- code(e) {
18273
- let t = this.rules.block.code.exec(e);
18274
- if (t) {
18275
- let n = t[0].replace(this.rules.other.codeRemoveIndent, "");
18276
- return { type: "code", raw: t[0], codeBlockStyle: "indented", text: this.options.pedantic ? n : z(n, `
18277
- `) };
18278
- }
18279
- }
18280
- fences(e) {
18281
- let t = this.rules.block.fences.exec(e);
18282
- if (t) {
18283
- let n = t[0], r = Je(n, t[3] || "", this.rules);
18284
- return { type: "code", raw: n, lang: t[2] ? t[2].trim().replace(this.rules.inline.anyPunctuation, "$1") : t[2], text: r };
18285
- }
18286
- }
18287
- heading(e) {
18288
- let t = this.rules.block.heading.exec(e);
18289
- if (t) {
18290
- let n = t[2].trim();
18291
- if (this.rules.other.endingHash.test(n)) {
18292
- let r = z(n, "#");
18293
- (this.options.pedantic || !r || this.rules.other.endingSpaceChar.test(r)) && (n = r.trim());
18294
- }
18295
- return { type: "heading", raw: t[0], depth: t[1].length, text: n, tokens: this.lexer.inline(n) };
18296
- }
18297
- }
18298
- hr(e) {
18299
- let t = this.rules.block.hr.exec(e);
18300
- if (t)
18301
- return { type: "hr", raw: z(t[0], `
18302
- `) };
18303
- }
18304
- blockquote(e) {
18305
- let t = this.rules.block.blockquote.exec(e);
18306
- if (t) {
18307
- let n = z(t[0], `
18308
- `).split(`
18309
- `), r = "", i2 = "", s = [];
18310
- for (;n.length > 0; ) {
18311
- let a = false, o = [], l;
18312
- for (l = 0;l < n.length; l++)
18313
- if (this.rules.other.blockquoteStart.test(n[l]))
18314
- o.push(n[l]), a = true;
18315
- else if (!a)
18316
- o.push(n[l]);
18317
- else
18318
- break;
18319
- n = n.slice(l);
18320
- let p = o.join(`
18321
- `), c = p.replace(this.rules.other.blockquoteSetextReplace, `
18322
- $1`).replace(this.rules.other.blockquoteSetextReplace2, "");
18323
- r = r ? `${r}
18324
- ${p}` : p, i2 = i2 ? `${i2}
18325
- ${c}` : c;
18326
- let g = this.lexer.state.top;
18327
- if (this.lexer.state.top = true, this.lexer.blockTokens(c, s, true), this.lexer.state.top = g, n.length === 0)
18328
- break;
18329
- let h = s.at(-1);
18330
- if (h?.type === "code")
18331
- break;
18332
- if (h?.type === "blockquote") {
18333
- let R = h, f = R.raw + `
18334
- ` + n.join(`
18335
- `), O = this.blockquote(f);
18336
- s[s.length - 1] = O, r = r.substring(0, r.length - R.raw.length) + O.raw, i2 = i2.substring(0, i2.length - R.text.length) + O.text;
18337
- break;
18338
- } else if (h?.type === "list") {
18339
- let R = h, f = R.raw + `
18340
- ` + n.join(`
18341
- `), O = this.list(f);
18342
- s[s.length - 1] = O, r = r.substring(0, r.length - h.raw.length) + O.raw, i2 = i2.substring(0, i2.length - R.raw.length) + O.raw, n = f.substring(s.at(-1).raw.length).split(`
18343
- `);
18344
- continue;
18345
- }
18346
- }
18347
- return { type: "blockquote", raw: r, tokens: s, text: i2 };
18348
- }
18349
- }
18350
- list(e) {
18351
- let t = this.rules.block.list.exec(e);
18352
- if (t) {
18353
- let n = t[1].trim(), r = n.length > 1, i2 = { type: "list", raw: "", ordered: r, start: r ? +n.slice(0, -1) : "", loose: false, items: [] };
18354
- n = r ? `\\d{1,9}\\${n.slice(-1)}` : `\\${n}`, this.options.pedantic && (n = r ? n : "[*+-]");
18355
- let s = this.rules.other.listItemRegex(n), a = false;
18356
- for (;e; ) {
18357
- let l = false, p = "", c = "";
18358
- if (!(t = s.exec(e)) || this.rules.block.hr.test(e))
18359
- break;
18360
- p = t[0], e = e.substring(p.length);
18361
- let g = t[2].split(`
18362
- `, 1)[0].replace(this.rules.other.listReplaceTabs, (O) => " ".repeat(3 * O.length)), h = e.split(`
18363
- `, 1)[0], R = !g.trim(), f = 0;
18364
- if (this.options.pedantic ? (f = 2, c = g.trimStart()) : R ? f = t[1].length + 1 : (f = t[2].search(this.rules.other.nonSpaceChar), f = f > 4 ? 1 : f, c = g.slice(f), f += t[1].length), R && this.rules.other.blankLine.test(h) && (p += h + `
18365
- `, e = e.substring(h.length + 1), l = true), !l) {
18366
- let O = this.rules.other.nextBulletRegex(f), V = this.rules.other.hrRegex(f), Y = this.rules.other.fencesBeginRegex(f), ee = this.rules.other.headingBeginRegex(f), fe = this.rules.other.htmlBeginRegex(f);
18367
- for (;e; ) {
18368
- let H = e.split(`
18369
- `, 1)[0], A;
18370
- if (h = H, this.options.pedantic ? (h = h.replace(this.rules.other.listReplaceNesting, " "), A = h) : A = h.replace(this.rules.other.tabCharGlobal, " "), Y.test(h) || ee.test(h) || fe.test(h) || O.test(h) || V.test(h))
18371
- break;
18372
- if (A.search(this.rules.other.nonSpaceChar) >= f || !h.trim())
18373
- c += `
18374
- ` + A.slice(f);
18375
- else {
18376
- if (R || g.replace(this.rules.other.tabCharGlobal, " ").search(this.rules.other.nonSpaceChar) >= 4 || Y.test(g) || ee.test(g) || V.test(g))
18377
- break;
18378
- c += `
18379
- ` + h;
18380
- }
18381
- !R && !h.trim() && (R = true), p += H + `
18382
- `, e = e.substring(H.length + 1), g = A.slice(f);
18383
- }
18384
- }
18385
- i2.loose || (a ? i2.loose = true : this.rules.other.doubleBlankLine.test(p) && (a = true)), i2.items.push({ type: "list_item", raw: p, task: !!this.options.gfm && this.rules.other.listIsTask.test(c), loose: false, text: c, tokens: [] }), i2.raw += p;
18386
- }
18387
- let o = i2.items.at(-1);
18388
- if (o)
18389
- o.raw = o.raw.trimEnd(), o.text = o.text.trimEnd();
18390
- else
18391
- return;
18392
- i2.raw = i2.raw.trimEnd();
18393
- for (let l of i2.items) {
18394
- if (this.lexer.state.top = false, l.tokens = this.lexer.blockTokens(l.text, []), l.task) {
18395
- if (l.text = l.text.replace(this.rules.other.listReplaceTask, ""), l.tokens[0]?.type === "text" || l.tokens[0]?.type === "paragraph") {
18396
- l.tokens[0].raw = l.tokens[0].raw.replace(this.rules.other.listReplaceTask, ""), l.tokens[0].text = l.tokens[0].text.replace(this.rules.other.listReplaceTask, "");
18397
- for (let c = this.lexer.inlineQueue.length - 1;c >= 0; c--)
18398
- if (this.rules.other.listIsTask.test(this.lexer.inlineQueue[c].src)) {
18399
- this.lexer.inlineQueue[c].src = this.lexer.inlineQueue[c].src.replace(this.rules.other.listReplaceTask, "");
18400
- break;
18401
- }
18402
- }
18403
- let p = this.rules.other.listTaskCheckbox.exec(l.raw);
18404
- if (p) {
18405
- let c = { type: "checkbox", raw: p[0] + " ", checked: p[0] !== "[ ]" };
18406
- l.checked = c.checked, i2.loose ? l.tokens[0] && ["paragraph", "text"].includes(l.tokens[0].type) && "tokens" in l.tokens[0] && l.tokens[0].tokens ? (l.tokens[0].raw = c.raw + l.tokens[0].raw, l.tokens[0].text = c.raw + l.tokens[0].text, l.tokens[0].tokens.unshift(c)) : l.tokens.unshift({ type: "paragraph", raw: c.raw, text: c.raw, tokens: [c] }) : l.tokens.unshift(c);
18407
- }
18408
- }
18409
- if (!i2.loose) {
18410
- let p = l.tokens.filter((g) => g.type === "space"), c = p.length > 0 && p.some((g) => this.rules.other.anyLine.test(g.raw));
18411
- i2.loose = c;
18412
- }
18413
- }
18414
- if (i2.loose)
18415
- for (let l of i2.items) {
18416
- l.loose = true;
18417
- for (let p of l.tokens)
18418
- p.type === "text" && (p.type = "paragraph");
18419
- }
18420
- return i2;
18421
- }
18422
- }
18423
- html(e) {
18424
- let t = this.rules.block.html.exec(e);
18425
- if (t)
18426
- return { type: "html", block: true, raw: t[0], pre: t[1] === "pre" || t[1] === "script" || t[1] === "style", text: t[0] };
18427
- }
18428
- def(e) {
18429
- let t = this.rules.block.def.exec(e);
18430
- if (t) {
18431
- let n = t[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal, " "), r = t[2] ? t[2].replace(this.rules.other.hrefBrackets, "$1").replace(this.rules.inline.anyPunctuation, "$1") : "", i2 = t[3] ? t[3].substring(1, t[3].length - 1).replace(this.rules.inline.anyPunctuation, "$1") : t[3];
18432
- return { type: "def", tag: n, raw: t[0], href: r, title: i2 };
18433
- }
18434
- }
18435
- table(e) {
18436
- let t = this.rules.block.table.exec(e);
18437
- if (!t || !this.rules.other.tableDelimiter.test(t[2]))
18438
- return;
18439
- let n = J(t[1]), r = t[2].replace(this.rules.other.tableAlignChars, "").split("|"), i2 = t[3]?.trim() ? t[3].replace(this.rules.other.tableRowBlankLine, "").split(`
18440
- `) : [], s = { type: "table", raw: t[0], header: [], align: [], rows: [] };
18441
- if (n.length === r.length) {
18442
- for (let a of r)
18443
- this.rules.other.tableAlignRight.test(a) ? s.align.push("right") : this.rules.other.tableAlignCenter.test(a) ? s.align.push("center") : this.rules.other.tableAlignLeft.test(a) ? s.align.push("left") : s.align.push(null);
18444
- for (let a = 0;a < n.length; a++)
18445
- s.header.push({ text: n[a], tokens: this.lexer.inline(n[a]), header: true, align: s.align[a] });
18446
- for (let a of i2)
18447
- s.rows.push(J(a, s.header.length).map((o, l) => ({ text: o, tokens: this.lexer.inline(o), header: false, align: s.align[l] })));
18448
- return s;
18449
- }
18450
- }
18451
- lheading(e) {
18452
- let t = this.rules.block.lheading.exec(e);
18453
- if (t)
18454
- return { type: "heading", raw: t[0], depth: t[2].charAt(0) === "=" ? 1 : 2, text: t[1], tokens: this.lexer.inline(t[1]) };
18455
- }
18456
- paragraph(e) {
18457
- let t = this.rules.block.paragraph.exec(e);
18458
- if (t) {
18459
- let n = t[1].charAt(t[1].length - 1) === `
18460
- ` ? t[1].slice(0, -1) : t[1];
18461
- return { type: "paragraph", raw: t[0], text: n, tokens: this.lexer.inline(n) };
18462
- }
18463
- }
18464
- text(e) {
18465
- let t = this.rules.block.text.exec(e);
18466
- if (t)
18467
- return { type: "text", raw: t[0], text: t[0], tokens: this.lexer.inline(t[0]) };
18468
- }
18469
- escape(e) {
18470
- let t = this.rules.inline.escape.exec(e);
18471
- if (t)
18472
- return { type: "escape", raw: t[0], text: t[1] };
18473
- }
18474
- tag(e) {
18475
- let t = this.rules.inline.tag.exec(e);
18476
- if (t)
18477
- return !this.lexer.state.inLink && this.rules.other.startATag.test(t[0]) ? this.lexer.state.inLink = true : this.lexer.state.inLink && this.rules.other.endATag.test(t[0]) && (this.lexer.state.inLink = false), !this.lexer.state.inRawBlock && this.rules.other.startPreScriptTag.test(t[0]) ? this.lexer.state.inRawBlock = true : this.lexer.state.inRawBlock && this.rules.other.endPreScriptTag.test(t[0]) && (this.lexer.state.inRawBlock = false), { type: "html", raw: t[0], inLink: this.lexer.state.inLink, inRawBlock: this.lexer.state.inRawBlock, block: false, text: t[0] };
18478
- }
18479
- link(e) {
18480
- let t = this.rules.inline.link.exec(e);
18481
- if (t) {
18482
- let n = t[2].trim();
18483
- if (!this.options.pedantic && this.rules.other.startAngleBracket.test(n)) {
18484
- if (!this.rules.other.endAngleBracket.test(n))
18485
- return;
18486
- let s = z(n.slice(0, -1), "\\");
18487
- if ((n.length - s.length) % 2 === 0)
18488
- return;
18489
- } else {
18490
- let s = de(t[2], "()");
18491
- if (s === -2)
18492
- return;
18493
- if (s > -1) {
18494
- let o = (t[0].indexOf("!") === 0 ? 5 : 4) + t[1].length + s;
18495
- t[2] = t[2].substring(0, s), t[0] = t[0].substring(0, o).trim(), t[3] = "";
18496
- }
18497
- }
18498
- let r = t[2], i2 = "";
18499
- if (this.options.pedantic) {
18500
- let s = this.rules.other.pedanticHrefTitle.exec(r);
18501
- s && (r = s[1], i2 = s[3]);
18502
- } else
18503
- i2 = t[3] ? t[3].slice(1, -1) : "";
18504
- return r = r.trim(), this.rules.other.startAngleBracket.test(r) && (this.options.pedantic && !this.rules.other.endAngleBracket.test(n) ? r = r.slice(1) : r = r.slice(1, -1)), ge(t, { href: r && r.replace(this.rules.inline.anyPunctuation, "$1"), title: i2 && i2.replace(this.rules.inline.anyPunctuation, "$1") }, t[0], this.lexer, this.rules);
18505
- }
18506
- }
18507
- reflink(e, t) {
18508
- let n;
18509
- if ((n = this.rules.inline.reflink.exec(e)) || (n = this.rules.inline.nolink.exec(e))) {
18510
- let r = (n[2] || n[1]).replace(this.rules.other.multipleSpaceGlobal, " "), i2 = t[r.toLowerCase()];
18511
- if (!i2) {
18512
- let s = n[0].charAt(0);
18513
- return { type: "text", raw: s, text: s };
18514
- }
18515
- return ge(n, i2, n[0], this.lexer, this.rules);
18516
- }
18517
- }
18518
- emStrong(e, t, n = "") {
18519
- let r = this.rules.inline.emStrongLDelim.exec(e);
18520
- if (!r || r[3] && n.match(this.rules.other.unicodeAlphaNumeric))
18521
- return;
18522
- if (!(r[1] || r[2] || "") || !n || this.rules.inline.punctuation.exec(n)) {
18523
- let s = [...r[0]].length - 1, a, o, l = s, p = 0, c = r[0][0] === "*" ? this.rules.inline.emStrongRDelimAst : this.rules.inline.emStrongRDelimUnd;
18524
- for (c.lastIndex = 0, t = t.slice(-1 * e.length + s);(r = c.exec(t)) != null; ) {
18525
- if (a = r[1] || r[2] || r[3] || r[4] || r[5] || r[6], !a)
18526
- continue;
18527
- if (o = [...a].length, r[3] || r[4]) {
18528
- l += o;
18529
- continue;
18530
- } else if ((r[5] || r[6]) && s % 3 && !((s + o) % 3)) {
18531
- p += o;
18532
- continue;
18533
- }
18534
- if (l -= o, l > 0)
18535
- continue;
18536
- o = Math.min(o, o + l + p);
18537
- let g = [...r[0]][0].length, h = e.slice(0, s + r.index + g + o);
18538
- if (Math.min(s, o) % 2) {
18539
- let f = h.slice(1, -1);
18540
- return { type: "em", raw: h, text: f, tokens: this.lexer.inlineTokens(f) };
18541
- }
18542
- let R = h.slice(2, -2);
18543
- return { type: "strong", raw: h, text: R, tokens: this.lexer.inlineTokens(R) };
18544
- }
18545
- }
18546
- }
18547
- codespan(e) {
18548
- let t = this.rules.inline.code.exec(e);
18549
- if (t) {
18550
- let n = t[2].replace(this.rules.other.newLineCharGlobal, " "), r = this.rules.other.nonSpaceChar.test(n), i2 = this.rules.other.startingSpaceChar.test(n) && this.rules.other.endingSpaceChar.test(n);
18551
- return r && i2 && (n = n.substring(1, n.length - 1)), { type: "codespan", raw: t[0], text: n };
18552
- }
18553
- }
18554
- br(e) {
18555
- let t = this.rules.inline.br.exec(e);
18556
- if (t)
18557
- return { type: "br", raw: t[0] };
18558
- }
18559
- del(e) {
18560
- let t = this.rules.inline.del.exec(e);
18561
- if (t)
18562
- return { type: "del", raw: t[0], text: t[2], tokens: this.lexer.inlineTokens(t[2]) };
18563
- }
18564
- autolink(e) {
18565
- let t = this.rules.inline.autolink.exec(e);
18566
- if (t) {
18567
- let n, r;
18568
- return t[2] === "@" ? (n = t[1], r = "mailto:" + n) : (n = t[1], r = n), { type: "link", raw: t[0], text: n, href: r, tokens: [{ type: "text", raw: n, text: n }] };
18569
- }
18570
- }
18571
- url(e) {
18572
- let t;
18573
- if (t = this.rules.inline.url.exec(e)) {
18574
- let n, r;
18575
- if (t[2] === "@")
18576
- n = t[0], r = "mailto:" + n;
18577
- else {
18578
- let i2;
18579
- do
18580
- i2 = t[0], t[0] = this.rules.inline._backpedal.exec(t[0])?.[0] ?? "";
18581
- while (i2 !== t[0]);
18582
- n = t[0], t[1] === "www." ? r = "http://" + t[0] : r = t[0];
18583
- }
18584
- return { type: "link", raw: t[0], text: n, href: r, tokens: [{ type: "text", raw: n, text: n }] };
18585
- }
18586
- }
18587
- inlineText(e) {
18588
- let t = this.rules.inline.text.exec(e);
18589
- if (t) {
18590
- let n = this.lexer.state.inRawBlock;
18591
- return { type: "text", raw: t[0], text: t[0], escaped: n };
18592
- }
18593
- }
18594
- };
18595
- var x = class u {
18596
- tokens;
18597
- options;
18598
- state;
18599
- inlineQueue;
18600
- tokenizer;
18601
- constructor(e) {
18602
- this.tokens = [], this.tokens.links = Object.create(null), this.options = e || T, this.options.tokenizer = this.options.tokenizer || new y, this.tokenizer = this.options.tokenizer, this.tokenizer.options = this.options, this.tokenizer.lexer = this, this.inlineQueue = [], this.state = { inLink: false, inRawBlock: false, top: true };
18603
- let t = { other: m, block: E.normal, inline: M.normal };
18604
- this.options.pedantic ? (t.block = E.pedantic, t.inline = M.pedantic) : this.options.gfm && (t.block = E.gfm, this.options.breaks ? t.inline = M.breaks : t.inline = M.gfm), this.tokenizer.rules = t;
18605
- }
18606
- static get rules() {
18607
- return { block: E, inline: M };
18608
- }
18609
- static lex(e, t) {
18610
- return new u(t).lex(e);
18611
- }
18612
- static lexInline(e, t) {
18613
- return new u(t).inlineTokens(e);
18614
- }
18615
- lex(e) {
18616
- e = e.replace(m.carriageReturn, `
18617
- `), this.blockTokens(e, this.tokens);
18618
- for (let t = 0;t < this.inlineQueue.length; t++) {
18619
- let n = this.inlineQueue[t];
18620
- this.inlineTokens(n.src, n.tokens);
18621
- }
18622
- return this.inlineQueue = [], this.tokens;
18623
- }
18624
- blockTokens(e, t = [], n = false) {
18625
- for (this.options.pedantic && (e = e.replace(m.tabCharGlobal, " ").replace(m.spaceLine, ""));e; ) {
18626
- let r;
18627
- if (this.options.extensions?.block?.some((s) => (r = s.call({ lexer: this }, e, t)) ? (e = e.substring(r.raw.length), t.push(r), true) : false))
18628
- continue;
18629
- if (r = this.tokenizer.space(e)) {
18630
- e = e.substring(r.raw.length);
18631
- let s = t.at(-1);
18632
- r.raw.length === 1 && s !== undefined ? s.raw += `
18633
- ` : t.push(r);
18634
- continue;
18635
- }
18636
- if (r = this.tokenizer.code(e)) {
18637
- e = e.substring(r.raw.length);
18638
- let s = t.at(-1);
18639
- s?.type === "paragraph" || s?.type === "text" ? (s.raw += (s.raw.endsWith(`
18640
- `) ? "" : `
18641
- `) + r.raw, s.text += `
18642
- ` + r.text, this.inlineQueue.at(-1).src = s.text) : t.push(r);
18643
- continue;
18644
- }
18645
- if (r = this.tokenizer.fences(e)) {
18646
- e = e.substring(r.raw.length), t.push(r);
18647
- continue;
18648
- }
18649
- if (r = this.tokenizer.heading(e)) {
18650
- e = e.substring(r.raw.length), t.push(r);
18651
- continue;
18652
- }
18653
- if (r = this.tokenizer.hr(e)) {
18654
- e = e.substring(r.raw.length), t.push(r);
18655
- continue;
18656
- }
18657
- if (r = this.tokenizer.blockquote(e)) {
18658
- e = e.substring(r.raw.length), t.push(r);
18659
- continue;
18660
- }
18661
- if (r = this.tokenizer.list(e)) {
18662
- e = e.substring(r.raw.length), t.push(r);
18663
- continue;
18664
- }
18665
- if (r = this.tokenizer.html(e)) {
18666
- e = e.substring(r.raw.length), t.push(r);
18667
- continue;
18668
- }
18669
- if (r = this.tokenizer.def(e)) {
18670
- e = e.substring(r.raw.length);
18671
- let s = t.at(-1);
18672
- s?.type === "paragraph" || s?.type === "text" ? (s.raw += (s.raw.endsWith(`
18673
- `) ? "" : `
18674
- `) + r.raw, s.text += `
18675
- ` + r.raw, this.inlineQueue.at(-1).src = s.text) : this.tokens.links[r.tag] || (this.tokens.links[r.tag] = { href: r.href, title: r.title }, t.push(r));
18676
- continue;
18677
- }
18678
- if (r = this.tokenizer.table(e)) {
18679
- e = e.substring(r.raw.length), t.push(r);
18680
- continue;
18681
- }
18682
- if (r = this.tokenizer.lheading(e)) {
18683
- e = e.substring(r.raw.length), t.push(r);
18684
- continue;
18685
- }
18686
- let i2 = e;
18687
- if (this.options.extensions?.startBlock) {
18688
- let s = 1 / 0, a = e.slice(1), o;
18689
- this.options.extensions.startBlock.forEach((l) => {
18690
- o = l.call({ lexer: this }, a), typeof o == "number" && o >= 0 && (s = Math.min(s, o));
18691
- }), s < 1 / 0 && s >= 0 && (i2 = e.substring(0, s + 1));
18692
- }
18693
- if (this.state.top && (r = this.tokenizer.paragraph(i2))) {
18694
- let s = t.at(-1);
18695
- n && s?.type === "paragraph" ? (s.raw += (s.raw.endsWith(`
18696
- `) ? "" : `
18697
- `) + r.raw, s.text += `
18698
- ` + r.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = s.text) : t.push(r), n = i2.length !== e.length, e = e.substring(r.raw.length);
18699
- continue;
18700
- }
18701
- if (r = this.tokenizer.text(e)) {
18702
- e = e.substring(r.raw.length);
18703
- let s = t.at(-1);
18704
- s?.type === "text" ? (s.raw += (s.raw.endsWith(`
18705
- `) ? "" : `
18706
- `) + r.raw, s.text += `
18707
- ` + r.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = s.text) : t.push(r);
18708
- continue;
18709
- }
18710
- if (e) {
18711
- let s = "Infinite loop on byte: " + e.charCodeAt(0);
18712
- if (this.options.silent) {
18713
- console.error(s);
18714
- break;
18715
- } else
18716
- throw new Error(s);
18717
- }
18718
- }
18719
- return this.state.top = true, t;
18720
- }
18721
- inline(e, t = []) {
18722
- return this.inlineQueue.push({ src: e, tokens: t }), t;
18723
- }
18724
- inlineTokens(e, t = []) {
18725
- let n = e, r = null;
18726
- if (this.tokens.links) {
18727
- let o = Object.keys(this.tokens.links);
18728
- if (o.length > 0)
18729
- for (;(r = this.tokenizer.rules.inline.reflinkSearch.exec(n)) != null; )
18730
- o.includes(r[0].slice(r[0].lastIndexOf("[") + 1, -1)) && (n = n.slice(0, r.index) + "[" + "a".repeat(r[0].length - 2) + "]" + n.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex));
18731
- }
18732
- for (;(r = this.tokenizer.rules.inline.anyPunctuation.exec(n)) != null; )
18733
- n = n.slice(0, r.index) + "++" + n.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);
18734
- let i2;
18735
- for (;(r = this.tokenizer.rules.inline.blockSkip.exec(n)) != null; )
18736
- i2 = r[2] ? r[2].length : 0, n = n.slice(0, r.index + i2) + "[" + "a".repeat(r[0].length - i2 - 2) + "]" + n.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
18737
- n = this.options.hooks?.emStrongMask?.call({ lexer: this }, n) ?? n;
18738
- let s = false, a = "";
18739
- for (;e; ) {
18740
- s || (a = ""), s = false;
18741
- let o;
18742
- if (this.options.extensions?.inline?.some((p) => (o = p.call({ lexer: this }, e, t)) ? (e = e.substring(o.raw.length), t.push(o), true) : false))
18743
- continue;
18744
- if (o = this.tokenizer.escape(e)) {
18745
- e = e.substring(o.raw.length), t.push(o);
18746
- continue;
18747
- }
18748
- if (o = this.tokenizer.tag(e)) {
18749
- e = e.substring(o.raw.length), t.push(o);
18750
- continue;
18751
- }
18752
- if (o = this.tokenizer.link(e)) {
18753
- e = e.substring(o.raw.length), t.push(o);
18754
- continue;
18755
- }
18756
- if (o = this.tokenizer.reflink(e, this.tokens.links)) {
18757
- e = e.substring(o.raw.length);
18758
- let p = t.at(-1);
18759
- o.type === "text" && p?.type === "text" ? (p.raw += o.raw, p.text += o.text) : t.push(o);
18760
- continue;
18761
- }
18762
- if (o = this.tokenizer.emStrong(e, n, a)) {
18763
- e = e.substring(o.raw.length), t.push(o);
18764
- continue;
18765
- }
18766
- if (o = this.tokenizer.codespan(e)) {
18767
- e = e.substring(o.raw.length), t.push(o);
18768
- continue;
18769
- }
18770
- if (o = this.tokenizer.br(e)) {
18771
- e = e.substring(o.raw.length), t.push(o);
18772
- continue;
18773
- }
18774
- if (o = this.tokenizer.del(e)) {
18775
- e = e.substring(o.raw.length), t.push(o);
18776
- continue;
18777
- }
18778
- if (o = this.tokenizer.autolink(e)) {
18779
- e = e.substring(o.raw.length), t.push(o);
18780
- continue;
18781
- }
18782
- if (!this.state.inLink && (o = this.tokenizer.url(e))) {
18783
- e = e.substring(o.raw.length), t.push(o);
18784
- continue;
18785
- }
18786
- let l = e;
18787
- if (this.options.extensions?.startInline) {
18788
- let p = 1 / 0, c = e.slice(1), g;
18789
- this.options.extensions.startInline.forEach((h) => {
18790
- g = h.call({ lexer: this }, c), typeof g == "number" && g >= 0 && (p = Math.min(p, g));
18791
- }), p < 1 / 0 && p >= 0 && (l = e.substring(0, p + 1));
18792
- }
18793
- if (o = this.tokenizer.inlineText(l)) {
18794
- e = e.substring(o.raw.length), o.raw.slice(-1) !== "_" && (a = o.raw.slice(-1)), s = true;
18795
- let p = t.at(-1);
18796
- p?.type === "text" ? (p.raw += o.raw, p.text += o.text) : t.push(o);
18797
- continue;
18798
- }
18799
- if (e) {
18800
- let p = "Infinite loop on byte: " + e.charCodeAt(0);
18801
- if (this.options.silent) {
18802
- console.error(p);
18803
- break;
18804
- } else
18805
- throw new Error(p);
18806
- }
18807
- }
18808
- return t;
18809
- }
18810
- };
18811
- var P = class {
18812
- options;
18813
- parser;
18814
- constructor(e) {
18815
- this.options = e || T;
18816
- }
18817
- space(e) {
18818
- return "";
18819
- }
18820
- code({ text: e, lang: t, escaped: n }) {
18821
- let r = (t || "").match(m.notSpaceStart)?.[0], i2 = e.replace(m.endingNewline, "") + `
18822
- `;
18823
- return r ? '<pre><code class="language-' + w(r) + '">' + (n ? i2 : w(i2, true)) + `</code></pre>
18824
- ` : "<pre><code>" + (n ? i2 : w(i2, true)) + `</code></pre>
18825
- `;
18826
- }
18827
- blockquote({ tokens: e }) {
18828
- return `<blockquote>
18829
- ${this.parser.parse(e)}</blockquote>
18830
- `;
18831
- }
18832
- html({ text: e }) {
18833
- return e;
18834
- }
18835
- def(e) {
18836
- return "";
18837
- }
18838
- heading({ tokens: e, depth: t }) {
18839
- return `<h${t}>${this.parser.parseInline(e)}</h${t}>
18840
- `;
18841
- }
18842
- hr(e) {
18843
- return `<hr>
18844
- `;
18845
- }
18846
- list(e) {
18847
- let { ordered: t, start: n } = e, r = "";
18848
- for (let a = 0;a < e.items.length; a++) {
18849
- let o = e.items[a];
18850
- r += this.listitem(o);
18851
- }
18852
- let i2 = t ? "ol" : "ul", s = t && n !== 1 ? ' start="' + n + '"' : "";
18853
- return "<" + i2 + s + `>
18854
- ` + r + "</" + i2 + `>
18855
- `;
18856
- }
18857
- listitem(e) {
18858
- return `<li>${this.parser.parse(e.tokens)}</li>
18859
- `;
18860
- }
18861
- checkbox({ checked: e }) {
18862
- return "<input " + (e ? 'checked="" ' : "") + 'disabled="" type="checkbox"> ';
18863
- }
18864
- paragraph({ tokens: e }) {
18865
- return `<p>${this.parser.parseInline(e)}</p>
18866
- `;
18867
- }
18868
- table(e) {
18869
- let t = "", n = "";
18870
- for (let i2 = 0;i2 < e.header.length; i2++)
18871
- n += this.tablecell(e.header[i2]);
18872
- t += this.tablerow({ text: n });
18873
- let r = "";
18874
- for (let i2 = 0;i2 < e.rows.length; i2++) {
18875
- let s = e.rows[i2];
18876
- n = "";
18877
- for (let a = 0;a < s.length; a++)
18878
- n += this.tablecell(s[a]);
18879
- r += this.tablerow({ text: n });
18880
- }
18881
- return r && (r = `<tbody>${r}</tbody>`), `<table>
18882
- <thead>
18883
- ` + t + `</thead>
18884
- ` + r + `</table>
18885
- `;
18886
- }
18887
- tablerow({ text: e }) {
18888
- return `<tr>
18889
- ${e}</tr>
18890
- `;
18891
- }
18892
- tablecell(e) {
18893
- let t = this.parser.parseInline(e.tokens), n = e.header ? "th" : "td";
18894
- return (e.align ? `<${n} align="${e.align}">` : `<${n}>`) + t + `</${n}>
18895
- `;
18896
- }
18897
- strong({ tokens: e }) {
18898
- return `<strong>${this.parser.parseInline(e)}</strong>`;
18899
- }
18900
- em({ tokens: e }) {
18901
- return `<em>${this.parser.parseInline(e)}</em>`;
18902
- }
18903
- codespan({ text: e }) {
18904
- return `<code>${w(e, true)}</code>`;
18905
- }
18906
- br(e) {
18907
- return "<br>";
18908
- }
18909
- del({ tokens: e }) {
18910
- return `<del>${this.parser.parseInline(e)}</del>`;
18911
- }
18912
- link({ href: e, title: t, tokens: n }) {
18913
- let r = this.parser.parseInline(n), i2 = X(e);
18914
- if (i2 === null)
18915
- return r;
18916
- e = i2;
18917
- let s = '<a href="' + e + '"';
18918
- return t && (s += ' title="' + w(t) + '"'), s += ">" + r + "</a>", s;
18919
- }
18920
- image({ href: e, title: t, text: n, tokens: r }) {
18921
- r && (n = this.parser.parseInline(r, this.parser.textRenderer));
18922
- let i2 = X(e);
18923
- if (i2 === null)
18924
- return w(n);
18925
- e = i2;
18926
- let s = `<img src="${e}" alt="${n}"`;
18927
- return t && (s += ` title="${w(t)}"`), s += ">", s;
18928
- }
18929
- text(e) {
18930
- return "tokens" in e && e.tokens ? this.parser.parseInline(e.tokens) : ("escaped" in e) && e.escaped ? e.text : w(e.text);
18931
- }
18932
- };
18933
- var $2 = class {
18934
- strong({ text: e }) {
18935
- return e;
18936
- }
18937
- em({ text: e }) {
18938
- return e;
18939
- }
18940
- codespan({ text: e }) {
18941
- return e;
18942
- }
18943
- del({ text: e }) {
18944
- return e;
18945
- }
18946
- html({ text: e }) {
18947
- return e;
18948
- }
18949
- text({ text: e }) {
18950
- return e;
18951
- }
18952
- link({ text: e }) {
18953
- return "" + e;
18954
- }
18955
- image({ text: e }) {
18956
- return "" + e;
18957
- }
18958
- br() {
18959
- return "";
18960
- }
18961
- checkbox({ raw: e }) {
18962
- return e;
18963
- }
18964
- };
18965
- var b = class u2 {
18966
- options;
18967
- renderer;
18968
- textRenderer;
18969
- constructor(e) {
18970
- this.options = e || T, this.options.renderer = this.options.renderer || new P, this.renderer = this.options.renderer, this.renderer.options = this.options, this.renderer.parser = this, this.textRenderer = new $2;
18971
- }
18972
- static parse(e, t) {
18973
- return new u2(t).parse(e);
18974
- }
18975
- static parseInline(e, t) {
18976
- return new u2(t).parseInline(e);
18977
- }
18978
- parse(e) {
18979
- let t = "";
18980
- for (let n = 0;n < e.length; n++) {
18981
- let r = e[n];
18982
- if (this.options.extensions?.renderers?.[r.type]) {
18983
- let s = r, a = this.options.extensions.renderers[s.type].call({ parser: this }, s);
18984
- if (a !== false || !["space", "hr", "heading", "code", "table", "blockquote", "list", "html", "def", "paragraph", "text"].includes(s.type)) {
18985
- t += a || "";
18986
- continue;
18987
- }
18988
- }
18989
- let i2 = r;
18990
- switch (i2.type) {
18991
- case "space": {
18992
- t += this.renderer.space(i2);
18993
- break;
18994
- }
18995
- case "hr": {
18996
- t += this.renderer.hr(i2);
18997
- break;
18998
- }
18999
- case "heading": {
19000
- t += this.renderer.heading(i2);
19001
- break;
19002
- }
19003
- case "code": {
19004
- t += this.renderer.code(i2);
19005
- break;
19006
- }
19007
- case "table": {
19008
- t += this.renderer.table(i2);
19009
- break;
19010
- }
19011
- case "blockquote": {
19012
- t += this.renderer.blockquote(i2);
19013
- break;
19014
- }
19015
- case "list": {
19016
- t += this.renderer.list(i2);
19017
- break;
19018
- }
19019
- case "checkbox": {
19020
- t += this.renderer.checkbox(i2);
19021
- break;
19022
- }
19023
- case "html": {
19024
- t += this.renderer.html(i2);
19025
- break;
19026
- }
19027
- case "def": {
19028
- t += this.renderer.def(i2);
19029
- break;
19030
- }
19031
- case "paragraph": {
19032
- t += this.renderer.paragraph(i2);
19033
- break;
19034
- }
19035
- case "text": {
19036
- t += this.renderer.text(i2);
19037
- break;
19038
- }
19039
- default: {
19040
- let s = 'Token with "' + i2.type + '" type was not found.';
19041
- if (this.options.silent)
19042
- return console.error(s), "";
19043
- throw new Error(s);
19044
- }
19045
- }
19046
- }
19047
- return t;
19048
- }
19049
- parseInline(e, t = this.renderer) {
19050
- let n = "";
19051
- for (let r = 0;r < e.length; r++) {
19052
- let i2 = e[r];
19053
- if (this.options.extensions?.renderers?.[i2.type]) {
19054
- let a = this.options.extensions.renderers[i2.type].call({ parser: this }, i2);
19055
- if (a !== false || !["escape", "html", "link", "image", "strong", "em", "codespan", "br", "del", "text"].includes(i2.type)) {
19056
- n += a || "";
19057
- continue;
19058
- }
19059
- }
19060
- let s = i2;
19061
- switch (s.type) {
19062
- case "escape": {
19063
- n += t.text(s);
19064
- break;
19065
- }
19066
- case "html": {
19067
- n += t.html(s);
19068
- break;
19069
- }
19070
- case "link": {
19071
- n += t.link(s);
19072
- break;
19073
- }
19074
- case "image": {
19075
- n += t.image(s);
19076
- break;
19077
- }
19078
- case "checkbox": {
19079
- n += t.checkbox(s);
19080
- break;
19081
- }
19082
- case "strong": {
19083
- n += t.strong(s);
19084
- break;
19085
- }
19086
- case "em": {
19087
- n += t.em(s);
19088
- break;
19089
- }
19090
- case "codespan": {
19091
- n += t.codespan(s);
19092
- break;
19093
- }
19094
- case "br": {
19095
- n += t.br(s);
19096
- break;
19097
- }
19098
- case "del": {
19099
- n += t.del(s);
19100
- break;
19101
- }
19102
- case "text": {
19103
- n += t.text(s);
19104
- break;
19105
- }
19106
- default: {
19107
- let a = 'Token with "' + s.type + '" type was not found.';
19108
- if (this.options.silent)
19109
- return console.error(a), "";
19110
- throw new Error(a);
19111
- }
19112
- }
19113
- }
19114
- return n;
19115
- }
19116
- };
19117
- var S = class {
19118
- options;
19119
- block;
19120
- constructor(e) {
19121
- this.options = e || T;
19122
- }
19123
- static passThroughHooks = new Set(["preprocess", "postprocess", "processAllTokens", "emStrongMask"]);
19124
- static passThroughHooksRespectAsync = new Set(["preprocess", "postprocess", "processAllTokens"]);
19125
- preprocess(e) {
19126
- return e;
19127
- }
19128
- postprocess(e) {
19129
- return e;
19130
- }
19131
- processAllTokens(e) {
19132
- return e;
19133
- }
19134
- emStrongMask(e) {
19135
- return e;
19136
- }
19137
- provideLexer() {
19138
- return this.block ? x.lex : x.lexInline;
19139
- }
19140
- provideParser() {
19141
- return this.block ? b.parse : b.parseInline;
19142
- }
19143
- };
19144
- var B = class {
19145
- defaults = L();
19146
- options = this.setOptions;
19147
- parse = this.parseMarkdown(true);
19148
- parseInline = this.parseMarkdown(false);
19149
- Parser = b;
19150
- Renderer = P;
19151
- TextRenderer = $2;
19152
- Lexer = x;
19153
- Tokenizer = y;
19154
- Hooks = S;
19155
- constructor(...e) {
19156
- this.use(...e);
19157
- }
19158
- walkTokens(e, t) {
19159
- let n = [];
19160
- for (let r of e)
19161
- switch (n = n.concat(t.call(this, r)), r.type) {
19162
- case "table": {
19163
- let i2 = r;
19164
- for (let s of i2.header)
19165
- n = n.concat(this.walkTokens(s.tokens, t));
19166
- for (let s of i2.rows)
19167
- for (let a of s)
19168
- n = n.concat(this.walkTokens(a.tokens, t));
19169
- break;
19170
- }
19171
- case "list": {
19172
- let i2 = r;
19173
- n = n.concat(this.walkTokens(i2.items, t));
19174
- break;
19175
- }
19176
- default: {
19177
- let i2 = r;
19178
- this.defaults.extensions?.childTokens?.[i2.type] ? this.defaults.extensions.childTokens[i2.type].forEach((s) => {
19179
- let a = i2[s].flat(1 / 0);
19180
- n = n.concat(this.walkTokens(a, t));
19181
- }) : i2.tokens && (n = n.concat(this.walkTokens(i2.tokens, t)));
19182
- }
19183
- }
19184
- return n;
19185
- }
19186
- use(...e) {
19187
- let t = this.defaults.extensions || { renderers: {}, childTokens: {} };
19188
- return e.forEach((n) => {
19189
- let r = { ...n };
19190
- if (r.async = this.defaults.async || r.async || false, n.extensions && (n.extensions.forEach((i2) => {
19191
- if (!i2.name)
19192
- throw new Error("extension name required");
19193
- if ("renderer" in i2) {
19194
- let s = t.renderers[i2.name];
19195
- s ? t.renderers[i2.name] = function(...a) {
19196
- let o = i2.renderer.apply(this, a);
19197
- return o === false && (o = s.apply(this, a)), o;
19198
- } : t.renderers[i2.name] = i2.renderer;
19199
- }
19200
- if ("tokenizer" in i2) {
19201
- if (!i2.level || i2.level !== "block" && i2.level !== "inline")
19202
- throw new Error("extension level must be 'block' or 'inline'");
19203
- let s = t[i2.level];
19204
- s ? s.unshift(i2.tokenizer) : t[i2.level] = [i2.tokenizer], i2.start && (i2.level === "block" ? t.startBlock ? t.startBlock.push(i2.start) : t.startBlock = [i2.start] : i2.level === "inline" && (t.startInline ? t.startInline.push(i2.start) : t.startInline = [i2.start]));
19205
- }
19206
- "childTokens" in i2 && i2.childTokens && (t.childTokens[i2.name] = i2.childTokens);
19207
- }), r.extensions = t), n.renderer) {
19208
- let i2 = this.defaults.renderer || new P(this.defaults);
19209
- for (let s in n.renderer) {
19210
- if (!(s in i2))
19211
- throw new Error(`renderer '${s}' does not exist`);
19212
- if (["options", "parser"].includes(s))
19213
- continue;
19214
- let a = s, o = n.renderer[a], l = i2[a];
19215
- i2[a] = (...p) => {
19216
- let c = o.apply(i2, p);
19217
- return c === false && (c = l.apply(i2, p)), c || "";
19218
- };
19219
- }
19220
- r.renderer = i2;
19221
- }
19222
- if (n.tokenizer) {
19223
- let i2 = this.defaults.tokenizer || new y(this.defaults);
19224
- for (let s in n.tokenizer) {
19225
- if (!(s in i2))
19226
- throw new Error(`tokenizer '${s}' does not exist`);
19227
- if (["options", "rules", "lexer"].includes(s))
19228
- continue;
19229
- let a = s, o = n.tokenizer[a], l = i2[a];
19230
- i2[a] = (...p) => {
19231
- let c = o.apply(i2, p);
19232
- return c === false && (c = l.apply(i2, p)), c;
19233
- };
19234
- }
19235
- r.tokenizer = i2;
19236
- }
19237
- if (n.hooks) {
19238
- let i2 = this.defaults.hooks || new S;
19239
- for (let s in n.hooks) {
19240
- if (!(s in i2))
19241
- throw new Error(`hook '${s}' does not exist`);
19242
- if (["options", "block"].includes(s))
19243
- continue;
19244
- let a = s, o = n.hooks[a], l = i2[a];
19245
- S.passThroughHooks.has(s) ? i2[a] = (p) => {
19246
- if (this.defaults.async && S.passThroughHooksRespectAsync.has(s))
19247
- return (async () => {
19248
- let g = await o.call(i2, p);
19249
- return l.call(i2, g);
19250
- })();
19251
- let c = o.call(i2, p);
19252
- return l.call(i2, c);
19253
- } : i2[a] = (...p) => {
19254
- if (this.defaults.async)
19255
- return (async () => {
19256
- let g = await o.apply(i2, p);
19257
- return g === false && (g = await l.apply(i2, p)), g;
19258
- })();
19259
- let c = o.apply(i2, p);
19260
- return c === false && (c = l.apply(i2, p)), c;
19261
- };
19262
- }
19263
- r.hooks = i2;
19264
- }
19265
- if (n.walkTokens) {
19266
- let i2 = this.defaults.walkTokens, s = n.walkTokens;
19267
- r.walkTokens = function(a) {
19268
- let o = [];
19269
- return o.push(s.call(this, a)), i2 && (o = o.concat(i2.call(this, a))), o;
19270
- };
19271
- }
19272
- this.defaults = { ...this.defaults, ...r };
19273
- }), this;
19274
- }
19275
- setOptions(e) {
19276
- return this.defaults = { ...this.defaults, ...e }, this;
19277
- }
19278
- lexer(e, t) {
19279
- return x.lex(e, t ?? this.defaults);
19280
- }
19281
- parser(e, t) {
19282
- return b.parse(e, t ?? this.defaults);
19283
- }
19284
- parseMarkdown(e) {
19285
- return (n, r) => {
19286
- let i2 = { ...r }, s = { ...this.defaults, ...i2 }, a = this.onError(!!s.silent, !!s.async);
19287
- if (this.defaults.async === true && i2.async === false)
19288
- return a(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));
19289
- if (typeof n > "u" || n === null)
19290
- return a(new Error("marked(): input parameter is undefined or null"));
19291
- if (typeof n != "string")
19292
- return a(new Error("marked(): input parameter is of type " + Object.prototype.toString.call(n) + ", string expected"));
19293
- if (s.hooks && (s.hooks.options = s, s.hooks.block = e), s.async)
19294
- return (async () => {
19295
- let o = s.hooks ? await s.hooks.preprocess(n) : n, p = await (s.hooks ? await s.hooks.provideLexer() : e ? x.lex : x.lexInline)(o, s), c = s.hooks ? await s.hooks.processAllTokens(p) : p;
19296
- s.walkTokens && await Promise.all(this.walkTokens(c, s.walkTokens));
19297
- let h = await (s.hooks ? await s.hooks.provideParser() : e ? b.parse : b.parseInline)(c, s);
19298
- return s.hooks ? await s.hooks.postprocess(h) : h;
19299
- })().catch(a);
19300
- try {
19301
- s.hooks && (n = s.hooks.preprocess(n));
19302
- let l = (s.hooks ? s.hooks.provideLexer() : e ? x.lex : x.lexInline)(n, s);
19303
- s.hooks && (l = s.hooks.processAllTokens(l)), s.walkTokens && this.walkTokens(l, s.walkTokens);
19304
- let c = (s.hooks ? s.hooks.provideParser() : e ? b.parse : b.parseInline)(l, s);
19305
- return s.hooks && (c = s.hooks.postprocess(c)), c;
19306
- } catch (o) {
19307
- return a(o);
19308
- }
19309
- };
19310
- }
19311
- onError(e, t) {
19312
- return (n) => {
19313
- if (n.message += `
19314
- Please report this to https://github.com/markedjs/marked.`, e) {
19315
- let r = "<p>An error occurred:</p><pre>" + w(n.message + "", true) + "</pre>";
19316
- return t ? Promise.resolve(r) : r;
19317
- }
19318
- if (t)
19319
- return Promise.reject(n);
19320
- throw n;
19321
- };
19322
- }
19323
- };
19324
- var _ = new B;
19325
- function d(u3, e) {
19326
- return _.parse(u3, e);
19327
- }
19328
- d.options = d.setOptions = function(u3) {
19329
- return _.setOptions(u3), d.defaults = _.defaults, Z(d.defaults), d;
19330
- };
19331
- d.getDefaults = L;
19332
- d.defaults = T;
19333
- d.use = function(...u3) {
19334
- return _.use(...u3), d.defaults = _.defaults, Z(d.defaults), d;
19335
- };
19336
- d.walkTokens = function(u3, e) {
19337
- return _.walkTokens(u3, e);
19338
- };
19339
- d.parseInline = _.parseInline;
19340
- d.Parser = b;
19341
- d.parser = b.parse;
19342
- d.Renderer = P;
19343
- d.TextRenderer = $2;
19344
- d.Lexer = x;
19345
- d.lexer = x.lex;
19346
- d.Tokenizer = y;
19347
- d.Hooks = S;
19348
- d.parse = d;
19349
- var Dt = d.options;
19350
- var Ht = d.setOptions;
19351
- var Zt = d.use;
19352
- var Gt = d.walkTokens;
19353
- var Nt = d.parseInline;
19354
- var Ft = b.parse;
19355
- var jt = x.lex;
19356
-
19357
- // cli/utils/content.ts
19358
- function loadContent(contentDir) {
19359
- if (!fs5.existsSync(contentDir)) {
19360
- return {};
19361
- }
19362
- const collections = {};
19363
- const files = getAllFiles(contentDir);
19364
- for (const filePath of files) {
19365
- const ext = path5.extname(filePath).toLowerCase();
19366
- const relativePath = path5.relative(contentDir, filePath);
19367
- const collection = relativePath.split(path5.sep)[0];
19368
- if (!collection)
19369
- continue;
19370
- const slug = relativePath.replace(/\.(md|mdx|json)$/, "").replace(/\\/g, "/");
19371
- const id = slug;
19372
- const rawContent = fs5.readFileSync(filePath, "utf-8");
19373
- if (!collections[collection]) {
19374
- collections[collection] = [];
19375
- }
19376
- if (ext === ".json") {
19377
- try {
19378
- const data2 = JSON.parse(rawContent);
19379
- collections[collection].push({
19380
- id,
19381
- slug,
19382
- collection,
19383
- content: "",
19384
- ...data2
19385
- });
19386
- } catch (e) {
19387
- console.error(`Error parsing JSON file ${filePath}:`, e);
19388
- }
19389
- } else if (ext === ".md" || ext === ".mdx") {
19390
- const { metadata, content } = parseMarkdown(rawContent);
19391
- collections[collection].push({
19392
- id,
19393
- slug,
19394
- collection,
19395
- content,
19396
- ...metadata
19397
- });
19398
- }
19399
- }
19400
- return collections;
19401
- }
19402
- function getAllFiles(dir, fileList = []) {
19403
- const files = fs5.readdirSync(dir);
19404
- files.forEach((file) => {
19405
- const name = path5.join(dir, file);
19406
- if (fs5.statSync(name).isDirectory()) {
19407
- getAllFiles(name, fileList);
19408
- } else {
19409
- fileList.push(name);
19410
- }
19411
- });
19412
- return fileList;
19413
- }
19414
- function parseMarkdown(content) {
19415
- const frontmatterRegex = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/;
19416
- const match = content.match(frontmatterRegex);
19417
- if (!match) {
19418
- return { metadata: {}, content: content.trim() };
19419
- }
19420
- const [, yamlStr, body] = match;
19421
- const metadata = {};
19422
- if (yamlStr) {
19423
- yamlStr.split(`
19424
- `).forEach((line) => {
19425
- const [key, ...values] = line.split(":");
19426
- if (key && values.length > 0) {
19427
- const value = values.join(":").trim();
19428
- if (value === "true")
19429
- metadata[key.trim()] = true;
19430
- else if (value === "false")
19431
- metadata[key.trim()] = false;
19432
- else if (!isNaN(Number(value)))
19433
- metadata[key.trim()] = Number(value);
19434
- else if (value.startsWith("[") && value.endsWith("]")) {
19435
- metadata[key.trim()] = value.slice(1, -1).split(",").map((v2) => v2.trim().replace(/^['"]|['"]$/g, ""));
19436
- } else
19437
- metadata[key.trim()] = value.replace(/^['"]|['"]$/g, "");
19438
- }
19439
- });
19440
- }
19441
- return {
19442
- metadata,
19443
- content: d.parse((body || "").trim())
19444
- };
18356
+
18357
+ // core/plugins/registry.ts
18358
+ var pluginDataStore = {};
18359
+ function getPluginDataByNamespace(namespace) {
18360
+ return pluginDataStore[namespace] || [];
19445
18361
  }
19446
18362
 
19447
- // core/config/loader.ts
19448
- import fs6 from "fs";
19449
- import path6 from "path";
19450
- async function loadZenithConfig(projectRoot) {
19451
- const configPaths = [
19452
- path6.join(projectRoot, "zenith.config.ts"),
19453
- path6.join(projectRoot, "zenith.config.js"),
19454
- path6.join(projectRoot, "zenith.config.mjs")
19455
- ];
19456
- let configPath = null;
19457
- for (const p of configPaths) {
19458
- if (fs6.existsSync(p)) {
19459
- configPath = p;
19460
- break;
19461
- }
19462
- }
19463
- if (!configPath) {
19464
- return { plugins: [] };
19465
- }
19466
- try {
19467
- const configModule = await import(configPath);
19468
- const config = configModule.default || configModule;
19469
- if (typeof config !== "object" || config === null) {
19470
- console.warn(`[Zenith] Invalid config format in ${configPath}`);
19471
- return { plugins: [] };
19472
- }
19473
- return config;
19474
- } catch (error3) {
19475
- const message = error3 instanceof Error ? error3.message : String(error3);
19476
- console.error(`[Zenith] Failed to load config from ${configPath}:`, message);
19477
- return { plugins: [] };
19478
- }
19479
- }
19480
-
19481
- // core/plugins/registry.ts
19482
18363
  class PluginRegistry {
19483
18364
  plugins = new Map;
19484
18365
  register(plugin) {
@@ -19509,24 +18390,29 @@ class PluginRegistry {
19509
18390
  }
19510
18391
  clear() {
19511
18392
  this.plugins.clear();
18393
+ for (const key of Object.keys(pluginDataStore)) {
18394
+ delete pluginDataStore[key];
18395
+ }
19512
18396
  }
19513
18397
  }
19514
- function createPluginContext(projectRoot, contentSetter) {
18398
+ function createPluginContext(projectRoot) {
19515
18399
  return {
19516
18400
  projectRoot,
19517
- setContentData: contentSetter,
18401
+ setPluginData: (namespace, data2) => {
18402
+ pluginDataStore[namespace] = data2;
18403
+ },
19518
18404
  options: {}
19519
18405
  };
19520
18406
  }
19521
18407
 
19522
18408
  // compiler/css/index.ts
19523
18409
  import { spawn, spawnSync } from "child_process";
19524
- import path7 from "path";
19525
- import fs7 from "fs";
18410
+ import path6 from "path";
18411
+ import fs6 from "fs";
19526
18412
  function compileCss(options) {
19527
18413
  const startTime = performance.now();
19528
18414
  const { input, output, minify = false } = options;
19529
- if (!fs7.existsSync(input)) {
18415
+ if (!fs6.existsSync(input)) {
19530
18416
  return {
19531
18417
  css: "",
19532
18418
  duration: 0,
@@ -19548,7 +18434,7 @@ function compileCss(options) {
19548
18434
  args.push("--minify");
19549
18435
  }
19550
18436
  const result = spawnSync("bunx", args, {
19551
- cwd: path7.dirname(input),
18437
+ cwd: path6.dirname(input),
19552
18438
  encoding: "utf-8",
19553
18439
  stdio: useStdout ? ["pipe", "pipe", "pipe"] : ["pipe", "inherit", "pipe"],
19554
18440
  env: { ...process.env }
@@ -19566,8 +18452,8 @@ function compileCss(options) {
19566
18452
  let css = "";
19567
18453
  if (useStdout) {
19568
18454
  css = result.stdout?.toString() || "";
19569
- } else if (fs7.existsSync(output)) {
19570
- css = fs7.readFileSync(output, "utf-8");
18455
+ } else if (fs6.existsSync(output)) {
18456
+ css = fs6.readFileSync(output, "utf-8");
19571
18457
  }
19572
18458
  return {
19573
18459
  css,
@@ -19587,7 +18473,7 @@ async function compileCssAsync(options) {
19587
18473
  return new Promise((resolve) => {
19588
18474
  const startTime = performance.now();
19589
18475
  const { input, output, minify = false } = options;
19590
- if (!fs7.existsSync(input)) {
18476
+ if (!fs6.existsSync(input)) {
19591
18477
  resolve({
19592
18478
  css: "",
19593
18479
  duration: 0,
@@ -19605,7 +18491,7 @@ async function compileCssAsync(options) {
19605
18491
  args.push("--minify");
19606
18492
  }
19607
18493
  const child = spawn("bunx", args, {
19608
- cwd: path7.dirname(input),
18494
+ cwd: path6.dirname(input),
19609
18495
  stdio: useStdout ? ["pipe", "pipe", "pipe"] : ["pipe", "inherit", "pipe"],
19610
18496
  env: { ...process.env }
19611
18497
  });
@@ -19635,8 +18521,8 @@ async function compileCssAsync(options) {
19635
18521
  let css = "";
19636
18522
  if (useStdout) {
19637
18523
  css = stdout;
19638
- } else if (fs7.existsSync(output)) {
19639
- css = fs7.readFileSync(output, "utf-8");
18524
+ } else if (fs6.existsSync(output)) {
18525
+ css = fs6.readFileSync(output, "utf-8");
19640
18526
  }
19641
18527
  resolve({
19642
18528
  css,
@@ -19655,28 +18541,77 @@ async function compileCssAsync(options) {
19655
18541
  });
19656
18542
  }
19657
18543
  function resolveGlobalsCss(projectRoot) {
19658
- const globalsPath = path7.join(projectRoot, "src", "styles", "globals.css");
19659
- if (fs7.existsSync(globalsPath))
18544
+ const globalsPath = path6.join(projectRoot, "src", "styles", "globals.css");
18545
+ if (fs6.existsSync(globalsPath))
19660
18546
  return globalsPath;
19661
- const globalPath = path7.join(projectRoot, "src", "styles", "global.css");
19662
- if (fs7.existsSync(globalPath))
18547
+ const globalPath = path6.join(projectRoot, "src", "styles", "global.css");
18548
+ if (fs6.existsSync(globalPath))
19663
18549
  return globalPath;
19664
18550
  return null;
19665
18551
  }
19666
18552
 
18553
+ // core/plugins/bridge.ts
18554
+ var hookRegistry = new Map;
18555
+ function registerHook(hook, handler) {
18556
+ if (!hookRegistry.has(hook)) {
18557
+ hookRegistry.set(hook, []);
18558
+ }
18559
+ hookRegistry.get(hook).push(handler);
18560
+ }
18561
+ function clearHooks() {
18562
+ hookRegistry.clear();
18563
+ }
18564
+ async function runPluginHooks(hook, ctx) {
18565
+ const handlers = hookRegistry.get(hook) || [];
18566
+ for (const handler of handlers) {
18567
+ try {
18568
+ await handler(ctx);
18569
+ } catch (error3) {
18570
+ console.error(`[Zenith] Hook "${hook}" error:`, error3);
18571
+ }
18572
+ }
18573
+ }
18574
+ async function collectHookReturns(hook, ctx) {
18575
+ const handlers = hookRegistry.get(hook) || [];
18576
+ const results = [];
18577
+ for (const handler of handlers) {
18578
+ try {
18579
+ const result = await handler(ctx);
18580
+ if (result && typeof result === "object" && "namespace" in result && "payload" in result && typeof result.namespace === "string") {
18581
+ results.push(result);
18582
+ }
18583
+ } catch (error3) {
18584
+ console.error(`[Zenith] Hook "${hook}" collection error:`, error3);
18585
+ }
18586
+ }
18587
+ return results;
18588
+ }
18589
+ function buildRuntimeEnvelope(payloads) {
18590
+ const envelope = {};
18591
+ for (const { namespace, payload } of payloads) {
18592
+ envelope[namespace] = payload;
18593
+ }
18594
+ return envelope;
18595
+ }
18596
+ function createBridgeAPI() {
18597
+ return {
18598
+ on: registerHook
18599
+ };
18600
+ }
18601
+
19667
18602
  // cli/commands/dev.ts
19668
18603
  var pageCache = new Map;
19669
18604
  async function bundlePageScript(script, projectRoot) {
19670
18605
  if (!script.includes("import ")) {
19671
18606
  return script;
19672
18607
  }
19673
- const tempDir = path8.join(projectRoot, ".zenith-cache");
19674
- if (!fs8.existsSync(tempDir)) {
19675
- fs8.mkdirSync(tempDir, { recursive: true });
18608
+ const tempDir = path7.join(projectRoot, ".zenith-cache");
18609
+ if (!fs7.existsSync(tempDir)) {
18610
+ fs7.mkdirSync(tempDir, { recursive: true });
19676
18611
  }
19677
- const tempFile = path8.join(tempDir, `bundle-${Date.now()}.js`);
18612
+ const tempFile = path7.join(tempDir, `bundle-${Date.now()}.js`);
19678
18613
  try {
19679
- fs8.writeFileSync(tempFile, script, "utf-8");
18614
+ fs7.writeFileSync(tempFile, script, "utf-8");
19680
18615
  const result = await Bun.build({
19681
18616
  entrypoints: [tempFile],
19682
18617
  target: "browser",
@@ -19695,7 +18630,7 @@ async function bundlePageScript(script, projectRoot) {
19695
18630
  return script;
19696
18631
  } finally {
19697
18632
  try {
19698
- fs8.unlinkSync(tempFile);
18633
+ fs7.unlinkSync(tempFile);
19699
18634
  } catch {}
19700
18635
  }
19701
18636
  }
@@ -19704,31 +18639,28 @@ async function dev(options = {}) {
19704
18639
  const port = options.port || parseInt(process.env.PORT || "3000", 10);
19705
18640
  const pagesDir = project.pagesDir;
19706
18641
  const rootDir = project.root;
19707
- const contentDir = path8.join(rootDir, "content");
19708
18642
  const config = await loadZenithConfig(rootDir);
19709
18643
  const registry = new PluginRegistry;
18644
+ const bridgeAPI = createBridgeAPI();
18645
+ clearHooks();
19710
18646
  console.log("[Zenith] Config plugins:", config.plugins?.length ?? 0);
19711
18647
  for (const plugin of config.plugins || []) {
19712
18648
  console.log("[Zenith] Registering plugin:", plugin.name);
19713
18649
  registry.register(plugin);
18650
+ if (plugin.registerCLI) {
18651
+ plugin.registerCLI(bridgeAPI);
18652
+ }
19714
18653
  }
19715
- let contentData = {};
19716
- const hasContentPlugin = registry.has("zenith-content");
19717
- console.log("[Zenith] Has zenith-content plugin:", hasContentPlugin);
19718
- if (hasContentPlugin) {
19719
- await registry.initAll(createPluginContext(rootDir, (data2) => {
19720
- console.log("[Zenith] Content plugin set data, collections:", Object.keys(data2));
19721
- contentData = data2;
19722
- }));
19723
- } else {
19724
- console.log("[Zenith] Using legacy content loading from:", contentDir);
19725
- contentData = loadContent(contentDir);
19726
- }
19727
- console.log("[Zenith] Content collections loaded:", Object.keys(contentData));
18654
+ await registry.initAll(createPluginContext(rootDir));
18655
+ const hookCtx = {
18656
+ projectRoot: rootDir,
18657
+ getPluginData: getPluginDataByNamespace
18658
+ };
18659
+ await runPluginHooks("cli:dev:start", hookCtx);
19728
18660
  const globalsCssPath = resolveGlobalsCss(rootDir);
19729
18661
  let compiledCss = "";
19730
18662
  if (globalsCssPath) {
19731
- console.log("[Zenith] Compiling CSS:", path8.relative(rootDir, globalsCssPath));
18663
+ console.log("[Zenith] Compiling CSS:", path7.relative(rootDir, globalsCssPath));
19732
18664
  const cssResult = await compileCssAsync({ input: globalsCssPath, output: ":memory:" });
19733
18665
  if (cssResult.success) {
19734
18666
  compiledCss = cssResult.css;
@@ -19764,16 +18696,16 @@ async function dev(options = {}) {
19764
18696
  ]);
19765
18697
  async function compilePageInMemory(pagePath) {
19766
18698
  try {
19767
- const layoutsDir = path8.join(pagesDir, "../layouts");
19768
- const componentsDir = path8.join(pagesDir, "../components");
18699
+ const layoutsDir = path7.join(pagesDir, "../layouts");
18700
+ const componentsDir = path7.join(pagesDir, "../components");
19769
18701
  const layouts = discoverLayouts(layoutsDir);
19770
- const source = fs8.readFileSync(pagePath, "utf-8");
18702
+ const source = fs7.readFileSync(pagePath, "utf-8");
19771
18703
  let processedSource = source;
19772
18704
  let layoutToUse = layouts.get("DefaultLayout");
19773
18705
  if (layoutToUse)
19774
18706
  processedSource = processLayout(source, layoutToUse);
19775
18707
  const result = await compileZenSource(processedSource, pagePath, {
19776
- componentsDir: fs8.existsSync(componentsDir) ? componentsDir : undefined
18708
+ componentsDir: fs7.existsSync(componentsDir) ? componentsDir : undefined
19777
18709
  });
19778
18710
  if (!result.finalized)
19779
18711
  throw new Error("Compilation failed");
@@ -19791,9 +18723,30 @@ async function dev(options = {}) {
19791
18723
  return null;
19792
18724
  }
19793
18725
  }
19794
- const watcher = fs8.watch(path8.join(pagesDir, ".."), { recursive: true }, async (event, filename) => {
18726
+ async function generateDevHTML(page) {
18727
+ const payloads = await collectHookReturns("cli:runtime:collect", hookCtx);
18728
+ const envelope = buildRuntimeEnvelope(payloads);
18729
+ const envelopeJson = JSON.stringify(envelope).replace(/<\//g, "<\\/");
18730
+ const runtimeTag = `<script src="/runtime.js"></script>`;
18731
+ const pluginDataTag = `<script>window.__ZENITH_PLUGIN_DATA__ = ${envelopeJson};</script>`;
18732
+ const scriptTag = `<script type="module">
18733
+ ${page.script}
18734
+ </script>`;
18735
+ const allScripts = `${runtimeTag}
18736
+ ${pluginDataTag}
18737
+ ${scriptTag}`;
18738
+ return page.html.includes("</body>") ? page.html.replace("</body>", `${allScripts}
18739
+ </body>`) : `${page.html}
18740
+ ${allScripts}`;
18741
+ }
18742
+ const watcher = fs7.watch(path7.join(pagesDir, ".."), { recursive: true }, async (event, filename) => {
19795
18743
  if (!filename)
19796
18744
  return;
18745
+ await runPluginHooks("cli:dev:file-change", {
18746
+ ...hookCtx,
18747
+ filename,
18748
+ event
18749
+ });
19797
18750
  if (filename.endsWith(".zen")) {
19798
18751
  hmr("Page", filename);
19799
18752
  pageCache.clear();
@@ -19817,15 +18770,8 @@ async function dev(options = {}) {
19817
18770
  for (const client of clients) {
19818
18771
  client.send(JSON.stringify({ type: "style-update", url: "/assets/styles.css" }));
19819
18772
  }
19820
- } else if (filename.startsWith("content") || filename.includes("zenith-docs")) {
19821
- hmr("Content", filename);
19822
- if (registry.has("zenith-content")) {
19823
- registry.initAll(createPluginContext(rootDir, (data2) => {
19824
- contentData = data2;
19825
- }));
19826
- } else {
19827
- contentData = loadContent(contentDir);
19828
- }
18773
+ } else {
18774
+ await registry.initAll(createPluginContext(rootDir));
19829
18775
  for (const client of clients) {
19830
18776
  client.send(JSON.stringify({ type: "reload" }));
19831
18777
  }
@@ -19837,7 +18783,7 @@ async function dev(options = {}) {
19837
18783
  const startTime = performance.now();
19838
18784
  const url = new URL(req.url);
19839
18785
  const pathname = url.pathname;
19840
- const ext = path8.extname(pathname).toLowerCase();
18786
+ const ext = path7.extname(pathname).toLowerCase();
19841
18787
  if (pathname === "/hmr") {
19842
18788
  const upgraded = server2.upgrade(req);
19843
18789
  if (upgraded)
@@ -19865,8 +18811,8 @@ async function dev(options = {}) {
19865
18811
  return response;
19866
18812
  }
19867
18813
  if (STATIC_EXTENSIONS.has(ext)) {
19868
- const publicPath = path8.join(pagesDir, "../public", pathname);
19869
- if (fs8.existsSync(publicPath)) {
18814
+ const publicPath = path7.join(pagesDir, "../public", pathname);
18815
+ if (fs7.existsSync(publicPath)) {
19870
18816
  const response = new Response(Bun.file(publicPath));
19871
18817
  route("GET", pathname, 200, Math.round(performance.now() - startTime), 0, Math.round(performance.now() - startTime));
19872
18818
  return response;
@@ -19876,7 +18822,7 @@ async function dev(options = {}) {
19876
18822
  if (pagePath) {
19877
18823
  const compileStart = performance.now();
19878
18824
  let cached = pageCache.get(pagePath);
19879
- const stat = fs8.statSync(pagePath);
18825
+ const stat = fs7.statSync(pagePath);
19880
18826
  if (!cached || stat.mtimeMs > cached.lastModified) {
19881
18827
  cached = await compilePageInMemory(pagePath) || undefined;
19882
18828
  if (cached)
@@ -19885,7 +18831,7 @@ async function dev(options = {}) {
19885
18831
  const compileEnd = performance.now();
19886
18832
  if (cached) {
19887
18833
  const renderStart = performance.now();
19888
- const html = generateDevHTML(cached, contentData);
18834
+ const html = await generateDevHTML(cached);
19889
18835
  const renderEnd = performance.now();
19890
18836
  const totalTime = Math.round(performance.now() - startTime);
19891
18837
  const compileTime = Math.round(compileEnd - compileStart);
@@ -19915,45 +18861,31 @@ async function dev(options = {}) {
19915
18861
  await new Promise(() => {});
19916
18862
  }
19917
18863
  function findPageForRoute(route2, pagesDir) {
19918
- const exactPath = path8.join(pagesDir, route2 === "/" ? "index.zen" : `${route2.slice(1)}.zen`);
19919
- if (fs8.existsSync(exactPath))
18864
+ const exactPath = path7.join(pagesDir, route2 === "/" ? "index.zen" : `${route2.slice(1)}.zen`);
18865
+ if (fs7.existsSync(exactPath))
19920
18866
  return exactPath;
19921
- const indexPath = path8.join(pagesDir, route2 === "/" ? "index.zen" : `${route2.slice(1)}/index.zen`);
19922
- if (fs8.existsSync(indexPath))
18867
+ const indexPath = path7.join(pagesDir, route2 === "/" ? "index.zen" : `${route2.slice(1)}/index.zen`);
18868
+ if (fs7.existsSync(indexPath))
19923
18869
  return indexPath;
19924
18870
  const segments = route2 === "/" ? [] : route2.slice(1).split("/").filter(Boolean);
19925
18871
  for (let i2 = segments.length - 1;i2 >= 0; i2--) {
19926
18872
  const staticPart = segments.slice(0, i2).join("/");
19927
- const baseDir = staticPart ? path8.join(pagesDir, staticPart) : pagesDir;
19928
- const singleDynamicPath = path8.join(baseDir, "[slug].zen");
19929
- if (fs8.existsSync(singleDynamicPath))
18873
+ const baseDir = staticPart ? path7.join(pagesDir, staticPart) : pagesDir;
18874
+ const singleDynamicPath = path7.join(baseDir, "[slug].zen");
18875
+ if (fs7.existsSync(singleDynamicPath))
19930
18876
  return singleDynamicPath;
19931
- const catchAllPath = path8.join(baseDir, "[...slug].zen");
19932
- if (fs8.existsSync(catchAllPath))
18877
+ const catchAllPath = path7.join(baseDir, "[...slug].zen");
18878
+ if (fs7.existsSync(catchAllPath))
19933
18879
  return catchAllPath;
19934
18880
  }
19935
- const rootCatchAll = path8.join(pagesDir, "[...slug].zen");
19936
- if (fs8.existsSync(rootCatchAll))
18881
+ const rootCatchAll = path7.join(pagesDir, "[...slug].zen");
18882
+ if (fs7.existsSync(rootCatchAll))
19937
18883
  return rootCatchAll;
19938
18884
  return null;
19939
18885
  }
19940
- function generateDevHTML(page, contentData = {}) {
19941
- const runtimeTag = `<script src="/runtime.js"></script>`;
19942
- const contentJson = JSON.stringify(contentData).replace(/<\//g, "<\\/");
19943
- const contentTag = `<script>window.__ZENITH_CONTENT__ = ${contentJson};</script>`;
19944
- const scriptTag = `<script type="module">
19945
- ${page.script}
19946
- </script>`;
19947
- const allScripts = `${runtimeTag}
19948
- ${contentTag}
19949
- ${scriptTag}`;
19950
- return page.html.includes("</body>") ? page.html.replace("</body>", `${allScripts}
19951
- </body>`) : `${page.html}
19952
- ${allScripts}`;
19953
- }
19954
18886
 
19955
18887
  // cli/commands/preview.ts
19956
- import path9 from "path";
18888
+ import path8 from "path";
19957
18889
  var {serve: serve2 } = globalThis.Bun;
19958
18890
  async function preview(options = {}) {
19959
18891
  const project = requireProject();
@@ -19983,16 +18915,16 @@ async function preview(options = {}) {
19983
18915
  async fetch(req) {
19984
18916
  const url = new URL(req.url);
19985
18917
  const pathname = url.pathname;
19986
- const ext = path9.extname(pathname).toLowerCase();
18918
+ const ext = path8.extname(pathname).toLowerCase();
19987
18919
  if (STATIC_EXTENSIONS.has(ext)) {
19988
- const filePath = path9.join(distDir, pathname);
18920
+ const filePath = path8.join(distDir, pathname);
19989
18921
  const file = Bun.file(filePath);
19990
18922
  if (await file.exists()) {
19991
18923
  return new Response(file);
19992
18924
  }
19993
18925
  return new Response("Not found", { status: 404 });
19994
18926
  }
19995
- const indexPath = path9.join(distDir, "index.html");
18927
+ const indexPath = path8.join(distDir, "index.html");
19996
18928
  const indexFile = Bun.file(indexPath);
19997
18929
  if (await indexFile.exists()) {
19998
18930
  return new Response(indexFile, {
@@ -20008,8 +18940,8 @@ async function preview(options = {}) {
20008
18940
  }
20009
18941
 
20010
18942
  // compiler/ssg-build.ts
20011
- import fs9 from "fs";
20012
- import path10 from "path";
18943
+ import fs8 from "fs";
18944
+ import path9 from "path";
20013
18945
 
20014
18946
  // compiler/build-analyzer.ts
20015
18947
  function analyzePageSource(source) {
@@ -20071,9 +19003,9 @@ function getBuildOutputType(analysis) {
20071
19003
 
20072
19004
  // compiler/ssg-build.ts
20073
19005
  async function compilePage(pagePath, pagesDir, baseDir = process.cwd()) {
20074
- const source = fs9.readFileSync(pagePath, "utf-8");
19006
+ const source = fs8.readFileSync(pagePath, "utf-8");
20075
19007
  const analysis = analyzePageSource(source);
20076
- const layoutsDir = path10.join(baseDir, "layouts");
19008
+ const layoutsDir = path9.join(baseDir, "layouts");
20077
19009
  const layouts = discoverLayouts(layoutsDir);
20078
19010
  let processedSource = source;
20079
19011
  const layoutToUse = layouts.get("DefaultLayout");
@@ -20102,7 +19034,7 @@ async function compilePage(pagePath, pagesDir, baseDir = process.cwd()) {
20102
19034
  outputDir
20103
19035
  };
20104
19036
  }
20105
- function generatePageHTML(page, globalStyles, contentData) {
19037
+ function generatePageHTML(page, globalStyles, pluginEnvelope) {
20106
19038
  const { html, styles, analysis, routePath, pageScript } = page;
20107
19039
  const pageStyles = styles.join(`
20108
19040
  `);
@@ -20110,8 +19042,9 @@ function generatePageHTML(page, globalStyles, contentData) {
20110
19042
  ` + pageStyles;
20111
19043
  let scriptTags = "";
20112
19044
  if (analysis.needsHydration) {
19045
+ const envelopeJson = JSON.stringify(pluginEnvelope).replace(/<\//g, "<\\/");
20113
19046
  scriptTags = `
20114
- <script>window.__ZENITH_CONTENT__ = ${JSON.stringify(contentData)};</script>
19047
+ <script>window.__ZENITH_PLUGIN_DATA__ = ${envelopeJson};</script>
20115
19048
  <script src="/assets/bundle.js"></script>`;
20116
19049
  if (pageScript) {
20117
19050
  const pageJsName = routePath === "/" ? "page_index.js" : `page_${routePath.replace(/^\//, "").replace(/\//g, "_")}.js`;
@@ -20174,18 +19107,35 @@ ${page.pageScript}
20174
19107
  `;
20175
19108
  }
20176
19109
  async function buildSSG(options) {
20177
- const { pagesDir, outDir, baseDir = path10.dirname(pagesDir) } = options;
20178
- const contentDir = path10.join(baseDir, "content");
20179
- const contentData = loadContent(contentDir);
19110
+ const { pagesDir, outDir, baseDir = path9.dirname(pagesDir) } = options;
20180
19111
  console.log("\uD83D\uDD28 Zenith SSG Build");
20181
19112
  console.log(` Pages: ${pagesDir}`);
20182
19113
  console.log(` Output: ${outDir}`);
20183
19114
  console.log("");
20184
- if (fs9.existsSync(outDir)) {
20185
- fs9.rmSync(outDir, { recursive: true, force: true });
19115
+ const config = await loadZenithConfig(baseDir);
19116
+ const registry = new PluginRegistry;
19117
+ const bridgeAPI = createBridgeAPI();
19118
+ clearHooks();
19119
+ for (const plugin of config.plugins || []) {
19120
+ console.log(` Plugin: ${plugin.name}`);
19121
+ registry.register(plugin);
19122
+ if (plugin.registerCLI) {
19123
+ plugin.registerCLI(bridgeAPI);
19124
+ }
19125
+ }
19126
+ await registry.initAll(createPluginContext(baseDir));
19127
+ const hookCtx = {
19128
+ projectRoot: baseDir,
19129
+ getPluginData: getPluginDataByNamespace
19130
+ };
19131
+ const payloads = await collectHookReturns("cli:runtime:collect", hookCtx);
19132
+ const pluginEnvelope = buildRuntimeEnvelope(payloads);
19133
+ console.log("");
19134
+ if (fs8.existsSync(outDir)) {
19135
+ fs8.rmSync(outDir, { recursive: true, force: true });
20186
19136
  }
20187
- fs9.mkdirSync(outDir, { recursive: true });
20188
- fs9.mkdirSync(path10.join(outDir, "assets"), { recursive: true });
19137
+ fs8.mkdirSync(outDir, { recursive: true });
19138
+ fs8.mkdirSync(path9.join(outDir, "assets"), { recursive: true });
20189
19139
  const pageFiles = discoverPages(pagesDir);
20190
19140
  if (pageFiles.length === 0) {
20191
19141
  console.warn("\u26A0\uFE0F No pages found in", pagesDir);
@@ -20195,7 +19145,7 @@ async function buildSSG(options) {
20195
19145
  const compiledPages = [];
20196
19146
  let hasHydratedPages = false;
20197
19147
  for (const pageFile of pageFiles) {
20198
- const relativePath = path10.relative(pagesDir, pageFile);
19148
+ const relativePath = path9.relative(pagesDir, pageFile);
20199
19149
  console.log(` Compiling: ${relativePath}`);
20200
19150
  try {
20201
19151
  const compiled = await compilePage(pageFile, pagesDir, baseDir);
@@ -20215,8 +19165,8 @@ async function buildSSG(options) {
20215
19165
  let globalStyles = "";
20216
19166
  const globalsCssPath = resolveGlobalsCss(baseDir);
20217
19167
  if (globalsCssPath) {
20218
- console.log("\uD83D\uDCE6 Compiling CSS:", path10.relative(baseDir, globalsCssPath));
20219
- const cssOutputPath = path10.join(outDir, "assets", "styles.css");
19168
+ console.log("\uD83D\uDCE6 Compiling CSS:", path9.relative(baseDir, globalsCssPath));
19169
+ const cssOutputPath = path9.join(outDir, "assets", "styles.css");
20220
19170
  const result = compileCss({
20221
19171
  input: globalsCssPath,
20222
19172
  output: cssOutputPath,
@@ -20231,40 +19181,40 @@ async function buildSSG(options) {
20231
19181
  }
20232
19182
  if (hasHydratedPages) {
20233
19183
  const bundleJS = generateBundleJS();
20234
- fs9.writeFileSync(path10.join(outDir, "assets", "bundle.js"), bundleJS);
19184
+ fs8.writeFileSync(path9.join(outDir, "assets", "bundle.js"), bundleJS);
20235
19185
  console.log("\uD83D\uDCE6 Generated assets/bundle.js");
20236
19186
  }
20237
19187
  for (const page of compiledPages) {
20238
- const pageOutDir = path10.join(outDir, page.outputDir);
20239
- fs9.mkdirSync(pageOutDir, { recursive: true });
20240
- const html = generatePageHTML(page, globalStyles, contentData);
20241
- fs9.writeFileSync(path10.join(pageOutDir, "index.html"), html);
19188
+ const pageOutDir = path9.join(outDir, page.outputDir);
19189
+ fs8.mkdirSync(pageOutDir, { recursive: true });
19190
+ const html = generatePageHTML(page, globalStyles, pluginEnvelope);
19191
+ fs8.writeFileSync(path9.join(pageOutDir, "index.html"), html);
20242
19192
  if (page.pageScript) {
20243
19193
  const pageJsName = page.routePath === "/" ? "page_index.js" : `page_${page.routePath.replace(/^\//, "").replace(/\//g, "_")}.js`;
20244
19194
  const pageJS = generatePageJS(page);
20245
- fs9.writeFileSync(path10.join(outDir, "assets", pageJsName), pageJS);
19195
+ fs8.writeFileSync(path9.join(outDir, "assets", pageJsName), pageJS);
20246
19196
  }
20247
19197
  console.log(`\u2705 ${page.outputDir}/index.html`);
20248
19198
  }
20249
- const faviconPath = path10.join(baseDir, "favicon.ico");
20250
- if (fs9.existsSync(faviconPath)) {
20251
- fs9.copyFileSync(faviconPath, path10.join(outDir, "favicon.ico"));
19199
+ const faviconPath = path9.join(baseDir, "favicon.ico");
19200
+ if (fs8.existsSync(faviconPath)) {
19201
+ fs8.copyFileSync(faviconPath, path9.join(outDir, "favicon.ico"));
20252
19202
  console.log("\uD83D\uDCE6 Copied favicon.ico");
20253
19203
  }
20254
19204
  const custom404Candidates = ["404.zen", "+404.zen", "not-found.zen"];
20255
19205
  let has404 = false;
20256
19206
  for (const candidate of custom404Candidates) {
20257
- const custom404Path = path10.join(pagesDir, candidate);
20258
- if (fs9.existsSync(custom404Path)) {
19207
+ const custom404Path = path9.join(pagesDir, candidate);
19208
+ if (fs8.existsSync(custom404Path)) {
20259
19209
  try {
20260
19210
  const compiled = await compilePage(custom404Path, pagesDir, baseDir);
20261
- const html = generatePageHTML(compiled, globalStyles, contentData);
20262
- fs9.writeFileSync(path10.join(outDir, "404.html"), html);
19211
+ const html = generatePageHTML(compiled, globalStyles, pluginEnvelope);
19212
+ fs8.writeFileSync(path9.join(outDir, "404.html"), html);
20263
19213
  console.log("\uD83D\uDCE6 Generated 404.html (custom)");
20264
19214
  has404 = true;
20265
19215
  if (compiled.pageScript) {
20266
19216
  const pageJS = generatePageJS(compiled);
20267
- fs9.writeFileSync(path10.join(outDir, "assets", "page_404.js"), pageJS);
19217
+ fs8.writeFileSync(path9.join(outDir, "assets", "page_404.js"), pageJS);
20268
19218
  }
20269
19219
  } catch (error3) {
20270
19220
  console.warn(` \u26A0\uFE0F Could not compile ${candidate}: ${error3.message}`);
@@ -20298,7 +19248,7 @@ async function buildSSG(options) {
20298
19248
  </div>
20299
19249
  </body>
20300
19250
  </html>`;
20301
- fs9.writeFileSync(path10.join(outDir, "404.html"), default404HTML);
19251
+ fs8.writeFileSync(path9.join(outDir, "404.html"), default404HTML);
20302
19252
  console.log("\uD83D\uDCE6 Generated 404.html (default)");
20303
19253
  }
20304
19254
  console.log("");
@@ -20308,7 +19258,7 @@ async function buildSSG(options) {
20308
19258
  console.log(` SSR pages: ${compiledPages.filter((p) => p.analysis.needsSSR).length}`);
20309
19259
  console.log("");
20310
19260
  console.log("\uD83D\uDCCD Routes:");
20311
- for (const page of compiledPages.sort((a, b2) => b2.score - a.score)) {
19261
+ for (const page of compiledPages.sort((a, b) => b.score - a.score)) {
20312
19262
  const type = getBuildOutputType(page.analysis);
20313
19263
  console.log(` ${page.routePath.padEnd(20)} \u2192 ${page.outputDir}/index.html (${type})`);
20314
19264
  }
@@ -20336,30 +19286,30 @@ async function build(options = {}) {
20336
19286
  }
20337
19287
 
20338
19288
  // cli/utils/plugin-manager.ts
20339
- import fs10 from "fs";
20340
- import path11 from "path";
19289
+ import fs9 from "fs";
19290
+ import path10 from "path";
20341
19291
  var PLUGINS_FILE = "zenith.plugins.json";
20342
19292
  function getPluginsPath() {
20343
19293
  const root = findProjectRoot();
20344
19294
  if (!root) {
20345
19295
  throw new Error("Not in a Zenith project");
20346
19296
  }
20347
- return path11.join(root, PLUGINS_FILE);
19297
+ return path10.join(root, PLUGINS_FILE);
20348
19298
  }
20349
19299
  function readPlugins() {
20350
19300
  const pluginsPath = getPluginsPath();
20351
- if (!fs10.existsSync(pluginsPath)) {
19301
+ if (!fs9.existsSync(pluginsPath)) {
20352
19302
  return { plugins: [] };
20353
19303
  }
20354
19304
  try {
20355
- return JSON.parse(fs10.readFileSync(pluginsPath, "utf-8"));
19305
+ return JSON.parse(fs9.readFileSync(pluginsPath, "utf-8"));
20356
19306
  } catch {
20357
19307
  return { plugins: [] };
20358
19308
  }
20359
19309
  }
20360
19310
  function writePlugins(data2) {
20361
19311
  const pluginsPath = getPluginsPath();
20362
- fs10.writeFileSync(pluginsPath, JSON.stringify(data2, null, 2));
19312
+ fs9.writeFileSync(pluginsPath, JSON.stringify(data2, null, 2));
20363
19313
  }
20364
19314
  function addPlugin(name, options) {
20365
19315
  const data2 = readPlugins();
@@ -20433,8 +19383,8 @@ async function remove(pluginName) {
20433
19383
  }
20434
19384
 
20435
19385
  // cli/commands/create.ts
20436
- import fs11 from "fs";
20437
- import path12 from "path";
19386
+ import fs10 from "fs";
19387
+ import path11 from "path";
20438
19388
  import { execSync } from "child_process";
20439
19389
  import readline from "readline";
20440
19390
  async function prompt(question, defaultValue) {
@@ -20473,7 +19423,7 @@ async function create(appName) {
20473
19423
  configSpinner.succeed("Configurations generated");
20474
19424
  const installSpinner = new Spinner("Installing dependencies...");
20475
19425
  installSpinner.start();
20476
- const targetDir = path12.resolve(process.cwd(), options.name);
19426
+ const targetDir = path11.resolve(process.cwd(), options.name);
20477
19427
  process.chdir(targetDir);
20478
19428
  try {
20479
19429
  execSync("bun install", { stdio: "pipe" });
@@ -20504,8 +19454,8 @@ async function gatherOptions(providedName) {
20504
19454
  process.exit(1);
20505
19455
  }
20506
19456
  }
20507
- const targetDir = path12.resolve(process.cwd(), name);
20508
- if (fs11.existsSync(targetDir)) {
19457
+ const targetDir = path11.resolve(process.cwd(), name);
19458
+ if (fs10.existsSync(targetDir)) {
20509
19459
  error2(`Directory "${name}" already exists`);
20510
19460
  process.exit(1);
20511
19461
  }
@@ -20526,14 +19476,14 @@ async function gatherOptions(providedName) {
20526
19476
  };
20527
19477
  }
20528
19478
  async function createProject(options) {
20529
- const targetDir = path12.resolve(process.cwd(), options.name);
19479
+ const targetDir = path11.resolve(process.cwd(), options.name);
20530
19480
  const baseDir = options.directory;
20531
- const appDir = path12.join(targetDir, baseDir);
20532
- fs11.mkdirSync(targetDir, { recursive: true });
20533
- fs11.mkdirSync(path12.join(appDir, "pages"), { recursive: true });
20534
- fs11.mkdirSync(path12.join(appDir, "layouts"), { recursive: true });
20535
- fs11.mkdirSync(path12.join(appDir, "components"), { recursive: true });
20536
- fs11.mkdirSync(path12.join(appDir, "styles"), { recursive: true });
19481
+ const appDir = path11.join(targetDir, baseDir);
19482
+ fs10.mkdirSync(targetDir, { recursive: true });
19483
+ fs10.mkdirSync(path11.join(appDir, "pages"), { recursive: true });
19484
+ fs10.mkdirSync(path11.join(appDir, "layouts"), { recursive: true });
19485
+ fs10.mkdirSync(path11.join(appDir, "components"), { recursive: true });
19486
+ fs10.mkdirSync(path11.join(appDir, "styles"), { recursive: true });
20537
19487
  const pkg = {
20538
19488
  name: options.name,
20539
19489
  version: "0.1.0",
@@ -20563,14 +19513,14 @@ async function createProject(options) {
20563
19513
  devDeps["prettier"] = "^3.0.0";
20564
19514
  pkg.scripts = { ...pkg.scripts, format: "prettier --write ." };
20565
19515
  }
20566
- fs11.writeFileSync(path12.join(targetDir, "package.json"), JSON.stringify(pkg, null, 4));
20567
- fs11.writeFileSync(path12.join(targetDir, baseDir, "pages", "index.zen"), generateIndexPage());
20568
- fs11.writeFileSync(path12.join(targetDir, baseDir, "layouts", "DefaultLayout.zen"), generateDefaultLayout());
20569
- fs11.writeFileSync(path12.join(appDir, "styles", "global.css"), generateGlobalCSS());
20570
- fs11.writeFileSync(path12.join(targetDir, ".gitignore"), generateGitignore());
19516
+ fs10.writeFileSync(path11.join(targetDir, "package.json"), JSON.stringify(pkg, null, 4));
19517
+ fs10.writeFileSync(path11.join(targetDir, baseDir, "pages", "index.zen"), generateIndexPage());
19518
+ fs10.writeFileSync(path11.join(targetDir, baseDir, "layouts", "DefaultLayout.zen"), generateDefaultLayout());
19519
+ fs10.writeFileSync(path11.join(appDir, "styles", "global.css"), generateGlobalCSS());
19520
+ fs10.writeFileSync(path11.join(targetDir, ".gitignore"), generateGitignore());
20571
19521
  }
20572
19522
  async function generateConfigs(options) {
20573
- const targetDir = path12.resolve(process.cwd(), options.name);
19523
+ const targetDir = path11.resolve(process.cwd(), options.name);
20574
19524
  const tsconfig = {
20575
19525
  compilerOptions: {
20576
19526
  target: "ESNext",
@@ -20594,7 +19544,7 @@ async function generateConfigs(options) {
20594
19544
  "@/*": [`./${options.directory}/*`]
20595
19545
  };
20596
19546
  }
20597
- fs11.writeFileSync(path12.join(targetDir, "tsconfig.json"), JSON.stringify(tsconfig, null, 4));
19547
+ fs10.writeFileSync(path11.join(targetDir, "tsconfig.json"), JSON.stringify(tsconfig, null, 4));
20598
19548
  if (options.eslint) {
20599
19549
  const eslintConfig = {
20600
19550
  root: true,
@@ -20615,7 +19565,7 @@ async function generateConfigs(options) {
20615
19565
  },
20616
19566
  ignorePatterns: ["dist", "node_modules"]
20617
19567
  };
20618
- fs11.writeFileSync(path12.join(targetDir, ".eslintrc.json"), JSON.stringify(eslintConfig, null, 4));
19568
+ fs10.writeFileSync(path11.join(targetDir, ".eslintrc.json"), JSON.stringify(eslintConfig, null, 4));
20619
19569
  }
20620
19570
  if (options.prettier) {
20621
19571
  const prettierConfig = {
@@ -20625,8 +19575,8 @@ async function generateConfigs(options) {
20625
19575
  trailingComma: "es5",
20626
19576
  printWidth: 100
20627
19577
  };
20628
- fs11.writeFileSync(path12.join(targetDir, ".prettierrc"), JSON.stringify(prettierConfig, null, 4));
20629
- fs11.writeFileSync(path12.join(targetDir, ".prettierignore"), `dist
19578
+ fs10.writeFileSync(path11.join(targetDir, ".prettierrc"), JSON.stringify(prettierConfig, null, 4));
19579
+ fs10.writeFileSync(path11.join(targetDir, ".prettierignore"), `dist
20630
19580
  node_modules
20631
19581
  bun.lock
20632
19582
  `);