juxscript 1.1.124 → 1.1.126

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "totalComponents": 69,
3
- "generatedAt": "2026-02-13T05:15:24.014Z",
3
+ "generatedAt": "2026-02-13T05:27:51.273Z",
4
4
  "components": [
5
5
  {
6
6
  "file": "alert.js",
@@ -289,9 +289,36 @@ export class JuxCompiler {
289
289
  _generateRouter(views) {
290
290
  let routeMap = '';
291
291
  views.forEach(v => {
292
- const cap = v.name.charAt(0).toUpperCase() + v.name.slice(1);
293
- if (v.name.toLowerCase() === 'index') routeMap += ` '/': render${cap},\n`;
294
- routeMap += ` '/${v.name.toLowerCase()}': render${cap},\n`;
292
+ // Sanitize function name (same as above)
293
+ const sanitizedName = v.name
294
+ .replace(/[\/\\.\\-\s]/g, '_')
295
+ .replace(/[^a-zA-Z0-9_]/g, '_')
296
+ .replace(/_+/g, '_')
297
+ .replace(/^_|_$/g, '');
298
+
299
+ const cap = sanitizedName.charAt(0).toUpperCase() + sanitizedName.slice(1);
300
+
301
+ // ✅ Generate URL-safe route path from original name
302
+ // Convert: 'menus/main' → '/menus/main'
303
+ // Convert: 'about-us' → '/about-us'
304
+ // Convert: 'blog.post' → '/blog-post' (dots become dashes for URLs)
305
+ const routePath = v.name
306
+ .toLowerCase()
307
+ .replace(/\\/g, '/') // Normalize backslashes to forward slashes
308
+ .replace(/\.jux$/i, '') // Remove .jux extension if present
309
+ .replace(/\./g, '-') // Convert dots to dashes (blog.post → blog-post)
310
+ .replace(/\s+/g, '-') // Convert spaces to dashes
311
+ .replace(/[^a-z0-9\/_-]/g, '') // Remove any other unsafe URL chars
312
+ .replace(/-+/g, '-') // Collapse multiple dashes
313
+ .replace(/^-|-$/g, ''); // Remove leading/trailing dashes
314
+
315
+ // ✅ Handle index route
316
+ if (routePath === 'index' || routePath === '') {
317
+ routeMap += ` '/': render${cap},\n`;
318
+ }
319
+
320
+ // ✅ Add regular route
321
+ routeMap += ` '/${routePath}': render${cap},\n`;
295
322
  });
296
323
 
297
324
  return `
@@ -419,29 +446,34 @@ window.addEventListener('unhandledrejection', function(e) { __juxErrorOverlay.sh
419
446
  // --- JUX ROUTER ---
420
447
  const routes = {\n${routeMap}};
421
448
 
422
- async function navigate(path) {
423
- const view = routes[path];
424
- if (!view) {
425
- document.getElementById('app').innerHTML = '<h1 style="padding:40px;">404 - Not Found</h1>';
426
- return;
449
+ // Simple router
450
+ function route(path) {
451
+ const renderFn = routes[path] || routes['/'];
452
+ if (renderFn) {
453
+ document.getElementById('app').innerHTML = '';
454
+ renderFn();
455
+ } else {
456
+ document.getElementById('app').innerHTML = '<h1>404 - Page Not Found</h1>';
427
457
  }
428
- document.getElementById('app').innerHTML = '';
429
- var overlay = document.getElementById('__jux-error-overlay');
430
- if (overlay) overlay.remove();
431
- try { await view(); } catch (err) { __juxErrorOverlay.show(err, 'Jux Render Error'); }
432
458
  }
433
459
 
434
- document.addEventListener('click', e => {
435
- const a = e.target.closest('a');
436
- if (!a || a.dataset.router === 'false') return;
437
- try { if (new URL(a.href, location.origin).origin !== location.origin) return; } catch { return; }
438
- e.preventDefault();
439
- history.pushState({}, '', a.href);
440
- navigate(new URL(a.href, location.origin).pathname);
441
- });
460
+ // Initial route
461
+ route(window.location.pathname);
442
462
 
443
- window.addEventListener('popstate', () => navigate(location.pathname));
444
- navigate(location.pathname);
463
+ // Handle navigation
464
+ window.addEventListener('popstate', () => route(window.location.pathname));
465
+
466
+ // Intercept link clicks
467
+ document.addEventListener('click', (e) => {
468
+ if (e.target.matches('a[href]')) {
469
+ const href = e.target.getAttribute('href');
470
+ if (href.startsWith('/') && !href.startsWith('//')) {
471
+ e.preventDefault();
472
+ window.history.pushState({}, '', href);
473
+ route(href);
474
+ }
475
+ }
476
+ });
445
477
  `;
446
478
  }
447
479
 
@@ -518,11 +550,11 @@ navigate(location.pathname);
518
550
  <meta charset="UTF-8">
519
551
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
520
552
  <title>JUX Application</title>
553
+ <script type="module" src="./bundle.js"></script>
554
+ <script src="./entry.js"></script>
521
555
  </head>
522
556
  <body>
523
557
  <div id="app"></div>
524
- <script src="/bundle.js"></script>
525
- <script src="/entry.js"></script>
526
558
  </body>
527
559
  </html>`;
528
560
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "juxscript",
3
- "version": "1.1.124",
3
+ "version": "1.1.126",
4
4
  "type": "module",
5
5
  "description": "A JavaScript UX authorship platform",
6
6
  "main": "index.js",