juxscript 1.1.93 → 1.1.94
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/dom-structure-map.json +1 -1
- package/machinery/compiler3.js +167 -7
- package/package.json +1 -1
package/dom-structure-map.json
CHANGED
package/machinery/compiler3.js
CHANGED
|
@@ -309,15 +309,175 @@ export class JuxCompiler {
|
|
|
309
309
|
return entry;
|
|
310
310
|
}
|
|
311
311
|
|
|
312
|
-
|
|
313
|
-
|
|
312
|
+
/**
|
|
313
|
+
* ✅ Generate routes based on folder structure
|
|
314
|
+
*/
|
|
315
|
+
_generateRouter(views) {
|
|
316
|
+
let routeMap = '';
|
|
317
|
+
|
|
318
|
+
views.forEach(v => {
|
|
319
|
+
// ✅ Generate route from folder structure
|
|
320
|
+
const routePath = this._generateRoutePath(v.file);
|
|
321
|
+
const functionName = this._generateFunctionName(v.name);
|
|
314
322
|
|
|
315
|
-
|
|
316
|
-
this._validationIssues.forEach(issue => {
|
|
317
|
-
const icon = issue.type === 'error' ? '❌' : '⚠️';
|
|
318
|
-
console.log(` ${icon} ${issue.view}:${issue.line} - ${issue.message}`);
|
|
323
|
+
routeMap += ` '${routePath}': render${functionName},\n`;
|
|
319
324
|
});
|
|
320
|
-
|
|
325
|
+
|
|
326
|
+
return `
|
|
327
|
+
// --- JUX SOURCE LOADER ---
|
|
328
|
+
var __juxSources = null;
|
|
329
|
+
async function __juxLoadSources() {
|
|
330
|
+
if (__juxSources) return __juxSources;
|
|
331
|
+
try {
|
|
332
|
+
var res = await fetch('/__jux_sources.json');
|
|
333
|
+
__juxSources = await res.json();
|
|
334
|
+
} catch (e) {
|
|
335
|
+
__juxSources = {};
|
|
336
|
+
}
|
|
337
|
+
return __juxSources;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function __juxFindSource(stack) {
|
|
341
|
+
var match = stack.match(/render([A-Z][a-zA-Z0-9_]*)/);
|
|
342
|
+
if (match) {
|
|
343
|
+
var funcName = match[1];
|
|
344
|
+
for (var file in __juxSources || {}) {
|
|
345
|
+
var normalized = __juxSources[file].name
|
|
346
|
+
.split('_')
|
|
347
|
+
.map(s => s.charAt(0).toUpperCase() + s.slice(1).toLowerCase())
|
|
348
|
+
.join('');
|
|
349
|
+
|
|
350
|
+
if (normalized === funcName) {
|
|
351
|
+
return { file: file, source: __juxSources[file], viewName: funcName };
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
return null;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// --- JUX RUNTIME ERROR OVERLAY ---
|
|
359
|
+
var __juxErrorOverlay = {
|
|
360
|
+
styles: \`
|
|
361
|
+
#__jux-error-overlay {
|
|
362
|
+
position: fixed; inset: 0; z-index: 99999;
|
|
363
|
+
background: rgba(0, 0, 0, 0.4);
|
|
364
|
+
display: flex; align-items: center; justify-content: center;
|
|
365
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
|
|
366
|
+
opacity: 0; transition: opacity 0.2s ease-out; backdrop-filter: blur(2px);
|
|
367
|
+
}
|
|
368
|
+
#__jux-error-overlay.visible { opacity: 1; }
|
|
369
|
+
#__jux-error-overlay * { box-sizing: border-box; }
|
|
370
|
+
.__jux-modal {
|
|
371
|
+
background: #f8f9fa; border-radius: 4px;
|
|
372
|
+
box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.4);
|
|
373
|
+
max-width: 80vw; width: 90%; max-height: 90vh;
|
|
374
|
+
overflow: hidden; display: flex; flex-direction: column;
|
|
375
|
+
transform: translateY(10px); transition: transform 0.2s ease-out;
|
|
376
|
+
}
|
|
377
|
+
#__jux-error-overlay.visible .__jux-modal { transform: translateY(0); }
|
|
378
|
+
.__jux-header { background: #fff; padding: 20px 24px; border-bottom: 1px solid #e5e7eb; }
|
|
379
|
+
.__jux-header h3 { margin: 0 0 6px; font-weight: 600; font-size: 11px; color: #9ca3af; text-transform: uppercase; }
|
|
380
|
+
.__jux-header h1 { margin: 0 0 8px; font-size: 18px; font-weight: 600; color: #dc2626; line-height: 1.3; }
|
|
381
|
+
.__jux-header .file-info { color: #6b7280; font-size: 13px; }
|
|
382
|
+
.__jux-header .file-info strong { color: #dc2626; font-weight: 600; }
|
|
383
|
+
.__jux-source { padding: 16px 24px; overflow: auto; flex: 1; background: #f8f9fa; }
|
|
384
|
+
.__jux-code { background: #fff; border-radius: 8px; overflow: hidden; border: 1px solid #e5e7eb; }
|
|
385
|
+
.__jux-code-line { display: flex; font-size: 13px; line-height: 1.7; }
|
|
386
|
+
.__jux-code-line.error { background: #fef2f2; }
|
|
387
|
+
.__jux-code-line.error .__jux-line-code { color: #dc2626; font-weight: 500; }
|
|
388
|
+
.__jux-code-line.context { background: #fefce8; }
|
|
389
|
+
.__jux-line-num { min-width: 44px; padding: 4px 12px; text-align: right; color: #9ca3af; background: #f9fafb; border-right: 1px solid #e5e7eb; font-size: 12px; }
|
|
390
|
+
.__jux-code-line.error .__jux-line-num { background: #fef2f2; color: #dc2626; }
|
|
391
|
+
.__jux-line-code { flex: 1; padding: 4px 16px; color: #374151; white-space: pre; overflow-x: auto; }
|
|
392
|
+
.__jux-footer { padding: 16px 24px; background: #fff; border-top: 1px solid #e5e7eb; display: flex; justify-content: space-between; align-items: center; }
|
|
393
|
+
.__jux-tip { color: #6b7280; font-size: 12px; }
|
|
394
|
+
.__jux-dismiss { background: #f3f4f6; color: #374151; border: 1px solid #d1d5db; padding: 8px 16px; border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 500; }
|
|
395
|
+
.__jux-dismiss:hover { background: #e5e7eb; }
|
|
396
|
+
.__jux-no-source { color: #6b7280; padding: 24px; text-align: center; }
|
|
397
|
+
.__jux-no-source pre { background: #fff; padding: 16px; border-radius: 8px; margin-top: 16px; font-size: 11px; color: #6b7280; overflow-x: auto; text-align: left; border: 1px solid #e5e7eb; }
|
|
398
|
+
\`,
|
|
399
|
+
|
|
400
|
+
show: async function(error, title) {
|
|
401
|
+
title = title || 'Runtime Error';
|
|
402
|
+
var existing = document.getElementById('__jux-error-overlay');
|
|
403
|
+
if (existing) existing.remove();
|
|
404
|
+
await __juxLoadSources();
|
|
405
|
+
|
|
406
|
+
var overlay = document.createElement('div');
|
|
407
|
+
overlay.id = '__jux-error-overlay';
|
|
408
|
+
var stack = error && error.stack ? error.stack : '';
|
|
409
|
+
var msg = error && error.message ? error.message : String(error);
|
|
410
|
+
var found = __juxFindSource(stack);
|
|
411
|
+
var sourceHtml = '', fileInfo = '';
|
|
412
|
+
|
|
413
|
+
if (found && found.source && found.source.lines) {
|
|
414
|
+
var lines = found.source.lines;
|
|
415
|
+
fileInfo = '<span class="file-info">in <strong>' + found.file + '</strong></span>';
|
|
416
|
+
var errorLineIndex = -1;
|
|
417
|
+
var errorMethod = msg.match(/\\.([a-zA-Z]+)\\s*is not a function/);
|
|
418
|
+
if (errorMethod) {
|
|
419
|
+
for (var i = 0; i < lines.length; i++) {
|
|
420
|
+
if (lines[i].indexOf('.' + errorMethod[1]) > -1) { errorLineIndex = i; break; }
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
if (errorLineIndex === -1) {
|
|
424
|
+
for (var i = 0; i < lines.length; i++) {
|
|
425
|
+
if (lines[i].indexOf('throw ') > -1) { errorLineIndex = i; break; }
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
var contextStart = Math.max(0, errorLineIndex - 3);
|
|
429
|
+
var contextEnd = Math.min(lines.length - 1, errorLineIndex + 5);
|
|
430
|
+
if (errorLineIndex === -1) { contextStart = 0; contextEnd = Math.min(14, lines.length - 1); }
|
|
431
|
+
|
|
432
|
+
for (var i = contextStart; i <= contextEnd; i++) {
|
|
433
|
+
var isError = (i === errorLineIndex);
|
|
434
|
+
var isContext = !isError && errorLineIndex > -1 && Math.abs(i - errorLineIndex) <= 2;
|
|
435
|
+
var lineClass = isError ? ' error' : (isContext ? ' context' : '');
|
|
436
|
+
var lineCode = lines[i].replace(/</g, '<').replace(/>/g, '>') || ' ';
|
|
437
|
+
sourceHtml += '<div class="__jux-code-line' + lineClass + '"><span class="__jux-line-num">' + (i + 1) + '</span><span class="__jux-line-code">' + lineCode + '</span></div>';
|
|
438
|
+
}
|
|
439
|
+
} else {
|
|
440
|
+
sourceHtml = '<div class="__jux-no-source"><p>Could not locate source file.</p><pre>' + stack + '</pre></div>';
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
overlay.innerHTML = '<style>' + this.styles + '</style><div class="__jux-modal"><div class="__jux-header"><h3>' + title + '</h3><h1>' + msg + '</h1>' + fileInfo + '</div><div class="__jux-source"><div class="__jux-code">' + sourceHtml + '</div></div><div class="__jux-footer"><span class="__jux-tip">💡 Fix the error and save to reload</span><button class="__jux-dismiss" onclick="document.getElementById(\\'__jux-error-overlay\\').remove()">Dismiss</button></div></div>';
|
|
444
|
+
document.body.appendChild(overlay);
|
|
445
|
+
requestAnimationFrame(function() { overlay.classList.add('visible'); });
|
|
446
|
+
console.error(title + ':', error);
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
window.addEventListener('error', function(e) { __juxErrorOverlay.show(e.error || new Error(e.message), 'Uncaught Error'); }, true);
|
|
451
|
+
window.addEventListener('unhandledrejection', function(e) { __juxErrorOverlay.show(e.reason || new Error('Promise rejected'), 'Unhandled Promise Rejection'); }, true);
|
|
452
|
+
|
|
453
|
+
// --- JUX ROUTER ---
|
|
454
|
+
const routes = {
|
|
455
|
+
${routeMap}};
|
|
456
|
+
|
|
457
|
+
async function navigate(path) {
|
|
458
|
+
const view = routes[path];
|
|
459
|
+
if (!view) {
|
|
460
|
+
document.getElementById('app').innerHTML = '<h1 style="padding:40px;">404 - Not Found</h1>';
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
document.getElementById('app').innerHTML = '';
|
|
464
|
+
var overlay = document.getElementById('__jux-error-overlay');
|
|
465
|
+
if (overlay) overlay.remove();
|
|
466
|
+
try { await view(); } catch (err) { __juxErrorOverlay.show(err, 'Jux Render Error'); }
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
document.addEventListener('click', e => {
|
|
470
|
+
const a = e.target.closest('a');
|
|
471
|
+
if (!a || a.dataset.router === 'false') return;
|
|
472
|
+
try { if (new URL(a.href, location.origin).origin !== location.origin) return; } catch { return; }
|
|
473
|
+
e.preventDefault();
|
|
474
|
+
history.pushState({}, '', a.href);
|
|
475
|
+
navigate(new URL(a.href, location.origin).pathname);
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
window.addEventListener('popstate', () => navigate(location.pathname));
|
|
479
|
+
navigate(location.pathname);
|
|
480
|
+
`;
|
|
321
481
|
}
|
|
322
482
|
|
|
323
483
|
/**
|