@innovatorved/code-lab 0.1.10 → 0.1.12

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/shell.esm.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * ============================================================
3
- * @innovatorved/code-lab v0.1.10 — Standalone Browser Code IDE & Virtual Runtime
3
+ * @innovatorved/code-lab v0.1.12 — Standalone Browser Code IDE & Virtual Runtime
4
4
  * ============================================================
5
5
  * Features:
6
6
  * - Sandboxed Web Worker Execution Engine with Multi-Instance Isolation & Watchdog Timer
@@ -3138,6 +3138,12 @@ var CodeLabLogger = (() => {
3138
3138
  if (!pkgName) continue;
3139
3139
  const subpath = spec.slice(pkgName.length).replace(/^\/+/, '');
3140
3140
  const version = resolveBareVersion(vfs, rootDir, pkgName);
3141
+ if (subpath && /\.css$/i.test(subpath)) {
3142
+ const cssHref = `${CDN_ESM_BASE}/${pkgName}@${version}/${subpath.replace(/^\/+/, '')}`;
3143
+ const loader = `if(typeof document!=='undefined'){const l=document.createElement('link');l.rel='stylesheet';l.href=${JSON.stringify(cssHref)};document.head.appendChild(l);}export default ${JSON.stringify(cssHref)};`;
3144
+ imports[spec] = `data:text/javascript;charset=utf-8,${encodeURIComponent(loader)}`;
3145
+ continue;
3146
+ }
3141
3147
  imports[spec] = cdnEsmUrl(pkgName, version, subpath || undefined);
3142
3148
  }
3143
3149
  return imports;
@@ -3158,6 +3164,7 @@ var CodeLabLogger = (() => {
3158
3164
  let match;
3159
3165
  while ((match = re.exec(text)) !== null) {
3160
3166
  const url = match[0];
3167
+ if (url.includes('${')) continue;
3161
3168
  const pkgName = decodeURIComponent(match[1]);
3162
3169
  const rest = match[2];
3163
3170
  const pinnedVersion = rest.split(/[\/?]/)[0];
@@ -3202,6 +3209,35 @@ var CodeLabLogger = (() => {
3202
3209
  return files;
3203
3210
  }
3204
3211
 
3212
+ function collectPreviewAssetFiles(vfs, rootDir, maxFiles = 200) {
3213
+ const files = [];
3214
+ const walk = (dir, depth) => {
3215
+ if (depth > 8 || files.length >= maxFiles) return;
3216
+ let entries = [];
3217
+ try { entries = vfs.readdirSync(dir); } catch (_) { return; }
3218
+ for (const name of entries) {
3219
+ if (name === 'node_modules' || name.startsWith('.')) continue;
3220
+ const full = PosixPath.join(dir, name);
3221
+ let st;
3222
+ try { st = vfs.statSync(full); } catch (_) { continue; }
3223
+ const dirFlag = st && (typeof st.isDirectory === 'function' ? st.isDirectory() : st.isDirectory);
3224
+ if (dirFlag) {
3225
+ walk(full, depth + 1);
3226
+ } else if (/\.(?:css|json|svg)$/i.test(name) && files.length < maxFiles) {
3227
+ try {
3228
+ const content = vfs.readFileSync(full, 'utf8');
3229
+ const rel = full.startsWith(rootDir + '/') ? full.slice(rootDir.length + 1) : name;
3230
+ files.push({ full, rel, content });
3231
+ } catch (err) {
3232
+ _shellLogger.debug('Preview asset read skipped.', full, err);
3233
+ }
3234
+ }
3235
+ }
3236
+ };
3237
+ walk(rootDir, 0);
3238
+ return files;
3239
+ }
3240
+
3205
3241
  function collectPreviewScripts(vfs, rootDir, maxFiles = 200) {
3206
3242
  return collectPreviewScriptFiles(vfs, rootDir, maxFiles).map((f) => f.content);
3207
3243
  }
@@ -3284,11 +3320,31 @@ var CodeLabLogger = (() => {
3284
3320
  return out;
3285
3321
  };
3286
3322
 
3323
+ const inlineLocalCssImports = (cssText, cssDir) => {
3324
+ if (!cssText) return '';
3325
+ return cssText.replace(/@import\s+(?:url\(\s*['"]?([^'")]+)['"]?\s*\)|['"]([^'"]+)['"])\s*;?/gi, (full, u1, u2) => {
3326
+ const spec = (u1 || u2 || '').trim();
3327
+ if (!spec || /^(?:https?:|data:|\/\/)/i.test(spec)) return full;
3328
+ if (spec === 'tailwindcss') return '';
3329
+ const subTarget = resolveLocalTarget(cssDir, spec);
3330
+ if (subTarget && /\.css$/i.test(subTarget)) {
3331
+ const subCss = readText(subTarget);
3332
+ if (subCss !== null) return subCss;
3333
+ }
3334
+ return '';
3335
+ });
3336
+ };
3337
+
3287
3338
  const buildHtmlPreviewResponse = (htmlBody, htmlTargetPath) => {
3288
3339
  const scriptFiles = collectPreviewScriptFiles(ctx.vfs, rootDir);
3340
+ const assetFiles = collectPreviewAssetFiles(ctx.vfs, rootDir);
3289
3341
  const specifiers = new Set();
3342
+ const compiledScripts = [];
3290
3343
  for (const f of scriptFiles) {
3291
3344
  for (const s of extractBareSpecifiers(f.content)) specifiers.add(s);
3345
+ const compiled = transpileAndRewriteLocalImports(f.content, f.full);
3346
+ for (const s of extractBareSpecifiers(compiled)) specifiers.add(s);
3347
+ compiledScripts.push({ file: f, compiled });
3292
3348
  }
3293
3349
  // Also scan inline module scripts in HTML for bare specifiers
3294
3350
  const inlineScriptRe = /<script\b[^>]*>([\s\S]*?)<\/script>/gi;
@@ -3302,14 +3358,53 @@ var CodeLabLogger = (() => {
3302
3358
  const importMap = buildPreviewImportMap(ctx.vfs, rootDir, specifiers);
3303
3359
  for (const f of scriptFiles) aliasPinnedCdnUrls(ctx.vfs, rootDir, f.content, importMap);
3304
3360
  aliasPinnedCdnUrls(ctx.vfs, rootDir, htmlBody, importMap);
3305
- for (const f of scriptFiles) {
3306
- const compiled = transpileAndRewriteLocalImports(f.content, f.full);
3307
- const key = toLocalImportKey(f.full);
3361
+ for (const { file, compiled } of compiledScripts) {
3362
+ const key = toLocalImportKey(file.full);
3308
3363
  importMap[key] = `data:text/javascript;charset=utf-8,${encodeURIComponent(compiled)}`;
3309
3364
  }
3310
3365
 
3366
+ let needsTailwindBrowser = false;
3367
+ for (const af of assetFiles) {
3368
+ const key = toLocalImportKey(af.full);
3369
+ if (/\.css$/i.test(af.full)) {
3370
+ if (/@import\s+['"]tailwindcss['"]/i.test(af.content)) {
3371
+ needsTailwindBrowser = true;
3372
+ }
3373
+ const resolvedCss = inlineLocalCssImports(af.content, PosixPath.dirname(af.full));
3374
+ const cssModuleJs = `const __css=${JSON.stringify(resolvedCss)};if(typeof document!=='undefined'){const __s=document.createElement('style');__s.setAttribute('data-codelab-css',${JSON.stringify(af.rel)});__s.textContent=__css;document.head.appendChild(__s);}export default __css;`;
3375
+ importMap[key] = `data:text/javascript;charset=utf-8,${encodeURIComponent(cssModuleJs)}`;
3376
+ } else if (/\.json$/i.test(af.full)) {
3377
+ const jsonModuleJs = `export default ${af.content.trim() || 'null'};`;
3378
+ importMap[key] = `data:text/javascript;charset=utf-8,${encodeURIComponent(jsonModuleJs)}`;
3379
+ } else if (/\.svg$/i.test(af.full)) {
3380
+ const svgDataUrl = `data:image/svg+xml;utf8,${encodeURIComponent(af.content)}`;
3381
+ const svgModuleJs = `export default ${JSON.stringify(svgDataUrl)};`;
3382
+ importMap[key] = `data:text/javascript;charset=utf-8,${encodeURIComponent(svgModuleJs)}`;
3383
+ }
3384
+ }
3385
+
3311
3386
  const htmlDir = PosixPath.dirname(htmlTargetPath);
3312
- let transformedHtml = htmlBody;
3387
+ let transformedHtml = htmlBody.replace(/%PUBLIC_URL%\//g, '/').replace(/%PUBLIC_URL%/g, '');
3388
+
3389
+ // Auto-inject entry script for Create React App / bundler templates where index.html omits <script src="...">
3390
+ const hasLocalScriptTag = /<script\b[^>]*\bsrc\s*=\s*["']([^"']+)["'][^>]*>/i.test(transformedHtml);
3391
+ if (!hasLocalScriptTag) {
3392
+ const defaultEntries = [
3393
+ '/src/main.tsx', '/src/main.jsx', '/src/main.ts', '/src/main.js',
3394
+ '/src/index.tsx', '/src/index.jsx', '/src/index.ts', '/src/index.js'
3395
+ ];
3396
+ for (const cand of defaultEntries) {
3397
+ if (isFile(PosixPath.join(rootDir, cand.slice(1)))) {
3398
+ const entryTag = `<script type="module" src="${cand}"></script>`;
3399
+ if (/<\/body>/i.test(transformedHtml)) {
3400
+ transformedHtml = transformedHtml.replace(/<\/body>/i, ` ${entryTag}\n</body>`);
3401
+ } else {
3402
+ transformedHtml += `\n${entryTag}`;
3403
+ }
3404
+ break;
3405
+ }
3406
+ }
3407
+ }
3313
3408
 
3314
3409
  // Inline local <link rel="stylesheet" href="..."> so styles work in opaque-origin / srcdoc frames
3315
3410
  transformedHtml = transformedHtml.replace(/<link\b([^>]*?)>/gi, (fullTag, attrs) => {
@@ -3320,7 +3415,11 @@ var CodeLabLogger = (() => {
3320
3415
  if (!cssTarget || !/\.css$/i.test(cssTarget)) return fullTag;
3321
3416
  const cssContent = readText(cssTarget);
3322
3417
  if (cssContent === null) return fullTag;
3323
- return `<style data-codelab-href="${hrefMatch[1].replace(/"/g, '&quot;')}">\n${cssContent}\n</style>`;
3418
+ if (/@import\s+['"]tailwindcss['"]/i.test(cssContent)) {
3419
+ needsTailwindBrowser = true;
3420
+ }
3421
+ const resolvedCss = inlineLocalCssImports(cssContent, PosixPath.dirname(cssTarget));
3422
+ return `<style data-codelab-href="${hrefMatch[1].replace(/"/g, '&quot;')}">\n${resolvedCss}\n</style>`;
3324
3423
  });
3325
3424
 
3326
3425
  // Inline local <script ... src="..."></script> so entry modules & scripts execute reliably in opaque-origin / srcdoc frames
@@ -3332,11 +3431,20 @@ var CodeLabLogger = (() => {
3332
3431
  const rawScript = readText(scriptTarget);
3333
3432
  if (rawScript === null) return fullTag;
3334
3433
  const compiled = transpileAndRewriteLocalImports(rawScript, scriptTarget);
3335
- const isMod = /\btype\s*=\s*["']module["']/i.test(attrs) || /\.(?:tsx|ts|jsx|mjs)$/i.test(scriptTarget);
3434
+ const isMod = /\btype\s*=\s*["']module["']/i.test(attrs) || /\.(?:tsx|ts|jsx|mjs)$/i.test(scriptTarget) || /^\s*(?:import|export)\b/m.test(rawScript);
3336
3435
  const typeAttr = isMod ? ' type="module"' : '';
3337
3436
  return `<script${typeAttr} data-codelab-src="${srcMatch[1].replace(/"/g, '&quot;')}">\n${compiled}\n</script>`;
3338
3437
  });
3339
3438
 
3439
+ if (needsTailwindBrowser && !transformedHtml.includes('@tailwindcss/browser')) {
3440
+ const twTag = '<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>';
3441
+ if (/<head[^>]*>/i.test(transformedHtml)) {
3442
+ transformedHtml = transformedHtml.replace(/<head[^>]*>/i, (m) => `${m}\n ${twTag}`);
3443
+ } else {
3444
+ transformedHtml = twTag + '\n' + transformedHtml;
3445
+ }
3446
+ }
3447
+
3340
3448
  return injectPreviewExtras(transformedHtml, importMap);
3341
3449
  };
3342
3450
 
@@ -3348,7 +3456,9 @@ var CodeLabLogger = (() => {
3348
3456
  const hasExt = /\.[A-Za-z0-9]+$/.test(rel);
3349
3457
 
3350
3458
  if (!rel || pathname.endsWith('/') || isDir(target)) {
3351
- target = PosixPath.join(target, 'index.html');
3459
+ const rootIdx = PosixPath.join(target, 'index.html');
3460
+ const pubIdx = PosixPath.join(target, 'public', 'index.html');
3461
+ target = (!exists(rootIdx) && exists(pubIdx)) ? pubIdx : rootIdx;
3352
3462
  }
3353
3463
  if (!exists(target) && !hasExt) {
3354
3464
  // Resolve extensionless module specifiers (e.g. `./components/Counter`)
@@ -3362,7 +3472,9 @@ var CodeLabLogger = (() => {
3362
3472
  for (const c of cands) { if (exists(c)) { target = c; break; } }
3363
3473
  }
3364
3474
  if (!exists(target) && !hasExt) {
3365
- target = PosixPath.join(rootDir, 'index.html'); // SPA fallback
3475
+ const rootIdx = PosixPath.join(rootDir, 'index.html');
3476
+ const pubIdx = PosixPath.join(rootDir, 'public', 'index.html');
3477
+ target = (!exists(rootIdx) && exists(pubIdx)) ? pubIdx : rootIdx; // SPA fallback
3366
3478
  }
3367
3479
  if (!exists(target)) {
3368
3480
  return new Response(
package/dist/shell.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * ============================================================
3
- * @innovatorved/code-lab v0.1.10 — Standalone Browser Code IDE & Virtual Runtime
3
+ * @innovatorved/code-lab v0.1.12 — Standalone Browser Code IDE & Virtual Runtime
4
4
  * ============================================================
5
5
  * Features:
6
6
  * - Sandboxed Web Worker Execution Engine with Multi-Instance Isolation & Watchdog Timer
@@ -3139,6 +3139,12 @@ var CodeLabLogger = (() => {
3139
3139
  if (!pkgName) continue;
3140
3140
  const subpath = spec.slice(pkgName.length).replace(/^\/+/, '');
3141
3141
  const version = resolveBareVersion(vfs, rootDir, pkgName);
3142
+ if (subpath && /\.css$/i.test(subpath)) {
3143
+ const cssHref = `${CDN_ESM_BASE}/${pkgName}@${version}/${subpath.replace(/^\/+/, '')}`;
3144
+ const loader = `if(typeof document!=='undefined'){const l=document.createElement('link');l.rel='stylesheet';l.href=${JSON.stringify(cssHref)};document.head.appendChild(l);}export default ${JSON.stringify(cssHref)};`;
3145
+ imports[spec] = `data:text/javascript;charset=utf-8,${encodeURIComponent(loader)}`;
3146
+ continue;
3147
+ }
3142
3148
  imports[spec] = cdnEsmUrl(pkgName, version, subpath || undefined);
3143
3149
  }
3144
3150
  return imports;
@@ -3159,6 +3165,7 @@ var CodeLabLogger = (() => {
3159
3165
  let match;
3160
3166
  while ((match = re.exec(text)) !== null) {
3161
3167
  const url = match[0];
3168
+ if (url.includes('${')) continue;
3162
3169
  const pkgName = decodeURIComponent(match[1]);
3163
3170
  const rest = match[2];
3164
3171
  const pinnedVersion = rest.split(/[\/?]/)[0];
@@ -3203,6 +3210,35 @@ var CodeLabLogger = (() => {
3203
3210
  return files;
3204
3211
  }
3205
3212
 
3213
+ function collectPreviewAssetFiles(vfs, rootDir, maxFiles = 200) {
3214
+ const files = [];
3215
+ const walk = (dir, depth) => {
3216
+ if (depth > 8 || files.length >= maxFiles) return;
3217
+ let entries = [];
3218
+ try { entries = vfs.readdirSync(dir); } catch (_) { return; }
3219
+ for (const name of entries) {
3220
+ if (name === 'node_modules' || name.startsWith('.')) continue;
3221
+ const full = PosixPath.join(dir, name);
3222
+ let st;
3223
+ try { st = vfs.statSync(full); } catch (_) { continue; }
3224
+ const dirFlag = st && (typeof st.isDirectory === 'function' ? st.isDirectory() : st.isDirectory);
3225
+ if (dirFlag) {
3226
+ walk(full, depth + 1);
3227
+ } else if (/\.(?:css|json|svg)$/i.test(name) && files.length < maxFiles) {
3228
+ try {
3229
+ const content = vfs.readFileSync(full, 'utf8');
3230
+ const rel = full.startsWith(rootDir + '/') ? full.slice(rootDir.length + 1) : name;
3231
+ files.push({ full, rel, content });
3232
+ } catch (err) {
3233
+ _shellLogger.debug('Preview asset read skipped.', full, err);
3234
+ }
3235
+ }
3236
+ }
3237
+ };
3238
+ walk(rootDir, 0);
3239
+ return files;
3240
+ }
3241
+
3206
3242
  function collectPreviewScripts(vfs, rootDir, maxFiles = 200) {
3207
3243
  return collectPreviewScriptFiles(vfs, rootDir, maxFiles).map((f) => f.content);
3208
3244
  }
@@ -3285,11 +3321,31 @@ var CodeLabLogger = (() => {
3285
3321
  return out;
3286
3322
  };
3287
3323
 
3324
+ const inlineLocalCssImports = (cssText, cssDir) => {
3325
+ if (!cssText) return '';
3326
+ return cssText.replace(/@import\s+(?:url\(\s*['"]?([^'")]+)['"]?\s*\)|['"]([^'"]+)['"])\s*;?/gi, (full, u1, u2) => {
3327
+ const spec = (u1 || u2 || '').trim();
3328
+ if (!spec || /^(?:https?:|data:|\/\/)/i.test(spec)) return full;
3329
+ if (spec === 'tailwindcss') return '';
3330
+ const subTarget = resolveLocalTarget(cssDir, spec);
3331
+ if (subTarget && /\.css$/i.test(subTarget)) {
3332
+ const subCss = readText(subTarget);
3333
+ if (subCss !== null) return subCss;
3334
+ }
3335
+ return '';
3336
+ });
3337
+ };
3338
+
3288
3339
  const buildHtmlPreviewResponse = (htmlBody, htmlTargetPath) => {
3289
3340
  const scriptFiles = collectPreviewScriptFiles(ctx.vfs, rootDir);
3341
+ const assetFiles = collectPreviewAssetFiles(ctx.vfs, rootDir);
3290
3342
  const specifiers = new Set();
3343
+ const compiledScripts = [];
3291
3344
  for (const f of scriptFiles) {
3292
3345
  for (const s of extractBareSpecifiers(f.content)) specifiers.add(s);
3346
+ const compiled = transpileAndRewriteLocalImports(f.content, f.full);
3347
+ for (const s of extractBareSpecifiers(compiled)) specifiers.add(s);
3348
+ compiledScripts.push({ file: f, compiled });
3293
3349
  }
3294
3350
  // Also scan inline module scripts in HTML for bare specifiers
3295
3351
  const inlineScriptRe = /<script\b[^>]*>([\s\S]*?)<\/script>/gi;
@@ -3303,14 +3359,53 @@ var CodeLabLogger = (() => {
3303
3359
  const importMap = buildPreviewImportMap(ctx.vfs, rootDir, specifiers);
3304
3360
  for (const f of scriptFiles) aliasPinnedCdnUrls(ctx.vfs, rootDir, f.content, importMap);
3305
3361
  aliasPinnedCdnUrls(ctx.vfs, rootDir, htmlBody, importMap);
3306
- for (const f of scriptFiles) {
3307
- const compiled = transpileAndRewriteLocalImports(f.content, f.full);
3308
- const key = toLocalImportKey(f.full);
3362
+ for (const { file, compiled } of compiledScripts) {
3363
+ const key = toLocalImportKey(file.full);
3309
3364
  importMap[key] = `data:text/javascript;charset=utf-8,${encodeURIComponent(compiled)}`;
3310
3365
  }
3311
3366
 
3367
+ let needsTailwindBrowser = false;
3368
+ for (const af of assetFiles) {
3369
+ const key = toLocalImportKey(af.full);
3370
+ if (/\.css$/i.test(af.full)) {
3371
+ if (/@import\s+['"]tailwindcss['"]/i.test(af.content)) {
3372
+ needsTailwindBrowser = true;
3373
+ }
3374
+ const resolvedCss = inlineLocalCssImports(af.content, PosixPath.dirname(af.full));
3375
+ const cssModuleJs = `const __css=${JSON.stringify(resolvedCss)};if(typeof document!=='undefined'){const __s=document.createElement('style');__s.setAttribute('data-codelab-css',${JSON.stringify(af.rel)});__s.textContent=__css;document.head.appendChild(__s);}export default __css;`;
3376
+ importMap[key] = `data:text/javascript;charset=utf-8,${encodeURIComponent(cssModuleJs)}`;
3377
+ } else if (/\.json$/i.test(af.full)) {
3378
+ const jsonModuleJs = `export default ${af.content.trim() || 'null'};`;
3379
+ importMap[key] = `data:text/javascript;charset=utf-8,${encodeURIComponent(jsonModuleJs)}`;
3380
+ } else if (/\.svg$/i.test(af.full)) {
3381
+ const svgDataUrl = `data:image/svg+xml;utf8,${encodeURIComponent(af.content)}`;
3382
+ const svgModuleJs = `export default ${JSON.stringify(svgDataUrl)};`;
3383
+ importMap[key] = `data:text/javascript;charset=utf-8,${encodeURIComponent(svgModuleJs)}`;
3384
+ }
3385
+ }
3386
+
3312
3387
  const htmlDir = PosixPath.dirname(htmlTargetPath);
3313
- let transformedHtml = htmlBody;
3388
+ let transformedHtml = htmlBody.replace(/%PUBLIC_URL%\//g, '/').replace(/%PUBLIC_URL%/g, '');
3389
+
3390
+ // Auto-inject entry script for Create React App / bundler templates where index.html omits <script src="...">
3391
+ const hasLocalScriptTag = /<script\b[^>]*\bsrc\s*=\s*["']([^"']+)["'][^>]*>/i.test(transformedHtml);
3392
+ if (!hasLocalScriptTag) {
3393
+ const defaultEntries = [
3394
+ '/src/main.tsx', '/src/main.jsx', '/src/main.ts', '/src/main.js',
3395
+ '/src/index.tsx', '/src/index.jsx', '/src/index.ts', '/src/index.js'
3396
+ ];
3397
+ for (const cand of defaultEntries) {
3398
+ if (isFile(PosixPath.join(rootDir, cand.slice(1)))) {
3399
+ const entryTag = `<script type="module" src="${cand}"></script>`;
3400
+ if (/<\/body>/i.test(transformedHtml)) {
3401
+ transformedHtml = transformedHtml.replace(/<\/body>/i, ` ${entryTag}\n</body>`);
3402
+ } else {
3403
+ transformedHtml += `\n${entryTag}`;
3404
+ }
3405
+ break;
3406
+ }
3407
+ }
3408
+ }
3314
3409
 
3315
3410
  // Inline local <link rel="stylesheet" href="..."> so styles work in opaque-origin / srcdoc frames
3316
3411
  transformedHtml = transformedHtml.replace(/<link\b([^>]*?)>/gi, (fullTag, attrs) => {
@@ -3321,7 +3416,11 @@ var CodeLabLogger = (() => {
3321
3416
  if (!cssTarget || !/\.css$/i.test(cssTarget)) return fullTag;
3322
3417
  const cssContent = readText(cssTarget);
3323
3418
  if (cssContent === null) return fullTag;
3324
- return `<style data-codelab-href="${hrefMatch[1].replace(/"/g, '&quot;')}">\n${cssContent}\n</style>`;
3419
+ if (/@import\s+['"]tailwindcss['"]/i.test(cssContent)) {
3420
+ needsTailwindBrowser = true;
3421
+ }
3422
+ const resolvedCss = inlineLocalCssImports(cssContent, PosixPath.dirname(cssTarget));
3423
+ return `<style data-codelab-href="${hrefMatch[1].replace(/"/g, '&quot;')}">\n${resolvedCss}\n</style>`;
3325
3424
  });
3326
3425
 
3327
3426
  // Inline local <script ... src="..."></script> so entry modules & scripts execute reliably in opaque-origin / srcdoc frames
@@ -3333,11 +3432,20 @@ var CodeLabLogger = (() => {
3333
3432
  const rawScript = readText(scriptTarget);
3334
3433
  if (rawScript === null) return fullTag;
3335
3434
  const compiled = transpileAndRewriteLocalImports(rawScript, scriptTarget);
3336
- const isMod = /\btype\s*=\s*["']module["']/i.test(attrs) || /\.(?:tsx|ts|jsx|mjs)$/i.test(scriptTarget);
3435
+ const isMod = /\btype\s*=\s*["']module["']/i.test(attrs) || /\.(?:tsx|ts|jsx|mjs)$/i.test(scriptTarget) || /^\s*(?:import|export)\b/m.test(rawScript);
3337
3436
  const typeAttr = isMod ? ' type="module"' : '';
3338
3437
  return `<script${typeAttr} data-codelab-src="${srcMatch[1].replace(/"/g, '&quot;')}">\n${compiled}\n</script>`;
3339
3438
  });
3340
3439
 
3440
+ if (needsTailwindBrowser && !transformedHtml.includes('@tailwindcss/browser')) {
3441
+ const twTag = '<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>';
3442
+ if (/<head[^>]*>/i.test(transformedHtml)) {
3443
+ transformedHtml = transformedHtml.replace(/<head[^>]*>/i, (m) => `${m}\n ${twTag}`);
3444
+ } else {
3445
+ transformedHtml = twTag + '\n' + transformedHtml;
3446
+ }
3447
+ }
3448
+
3341
3449
  return injectPreviewExtras(transformedHtml, importMap);
3342
3450
  };
3343
3451
 
@@ -3349,7 +3457,9 @@ var CodeLabLogger = (() => {
3349
3457
  const hasExt = /\.[A-Za-z0-9]+$/.test(rel);
3350
3458
 
3351
3459
  if (!rel || pathname.endsWith('/') || isDir(target)) {
3352
- target = PosixPath.join(target, 'index.html');
3460
+ const rootIdx = PosixPath.join(target, 'index.html');
3461
+ const pubIdx = PosixPath.join(target, 'public', 'index.html');
3462
+ target = (!exists(rootIdx) && exists(pubIdx)) ? pubIdx : rootIdx;
3353
3463
  }
3354
3464
  if (!exists(target) && !hasExt) {
3355
3465
  // Resolve extensionless module specifiers (e.g. `./components/Counter`)
@@ -3363,7 +3473,9 @@ var CodeLabLogger = (() => {
3363
3473
  for (const c of cands) { if (exists(c)) { target = c; break; } }
3364
3474
  }
3365
3475
  if (!exists(target) && !hasExt) {
3366
- target = PosixPath.join(rootDir, 'index.html'); // SPA fallback
3476
+ const rootIdx = PosixPath.join(rootDir, 'index.html');
3477
+ const pubIdx = PosixPath.join(rootDir, 'public', 'index.html');
3478
+ target = (!exists(rootIdx) && exists(pubIdx)) ? pubIdx : rootIdx; // SPA fallback
3367
3479
  }
3368
3480
  if (!exists(target)) {
3369
3481
  return new Response(
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * ============================================================
3
- * @innovatorved/code-lab v0.1.10 — Standalone Browser Code IDE & Virtual Runtime
3
+ * @innovatorved/code-lab v0.1.12 — Standalone Browser Code IDE & Virtual Runtime
4
4
  * ============================================================
5
5
  * Features:
6
6
  * - Sandboxed Web Worker Execution Engine with Multi-Instance Isolation & Watchdog Timer
package/dist/terminal.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * ============================================================
3
- * @innovatorved/code-lab v0.1.10 — Standalone Browser Code IDE & Virtual Runtime
3
+ * @innovatorved/code-lab v0.1.12 — Standalone Browser Code IDE & Virtual Runtime
4
4
  * ============================================================
5
5
  * Features:
6
6
  * - Sandboxed Web Worker Execution Engine with Multi-Instance Isolation & Watchdog Timer
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@innovatorved/code-lab",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "description": "Standalone browser-native IDE Workbench, POSIX Shell & Coreutils, PTY Terminal, and Web Worker Node.js/Bun Virtual Runtime.",
5
5
  "main": "./dist/code-lab.js",
6
6
  "module": "./dist/code-lab.esm.js",
package/src/code-lab.css CHANGED
@@ -4347,6 +4347,27 @@ code-lab,
4347
4347
  max-width: 110px;
4348
4348
  }
4349
4349
 
4350
+ /* The split pane is narrower than the drawer, so the single-row chrome would
4351
+ clip its right-hand controls. Wrap instead, and give the URL its own row. */
4352
+ .codelab-preview-split .codelab-preview-chrome {
4353
+ flex-wrap: wrap;
4354
+ row-gap: 4px;
4355
+ }
4356
+
4357
+ .codelab-preview-split .codelab-preview-url-input {
4358
+ order: 10;
4359
+ flex: 1 1 100%;
4360
+ }
4361
+
4362
+ /* Icon-only pop-out keeps the split chrome to two rows. */
4363
+ .codelab-preview-split [data-cl-action="preview-popout"] {
4364
+ padding: 0 6px;
4365
+ }
4366
+
4367
+ .codelab-preview-split [data-cl-action="preview-popout"] > span {
4368
+ display: none;
4369
+ }
4370
+
4350
4371
  .codelab-preview-csp--blocked {
4351
4372
  color: var(--cl-red);
4352
4373
  border-color: var(--cl-red);
@@ -5107,6 +5128,13 @@ code-lab,
5107
5128
  These must come after the base `.codelab-workspace.has-preview-split` rule
5108
5129
  above: equal specificity, later wins. */
5109
5130
  @media (max-width: 900px) {
5131
+ /* Device emulation and the allowlist badge are not useful in a narrow pane.
5132
+ The violation chip stays visible so blocked requests are still surfaced. */
5133
+ .codelab-preview-split .codelab-preview-modes,
5134
+ .codelab-preview-split #cl-preview-csp-badge {
5135
+ display: none;
5136
+ }
5137
+
5110
5138
  /* Keep the split, but give the editor a floor and cap the preview share. */
5111
5139
  .codelab-workspace.has-preview-split {
5112
5140
  grid-template-columns: 155px 4px minmax(180px, 1fr) 5px minmax(200px, min(42%, var(--cl-preview-split-width, 44%)));
package/src/runtime.ts CHANGED
@@ -4048,6 +4048,7 @@ function __initVirtualRuntime(rootScope) {
4048
4048
  if (/@jsx\b/.test(source)) return true;
4049
4049
  if (source.indexOf('<>') !== -1) return true;
4050
4050
  if (/<\/[A-Za-z]/.test(source)) return true;
4051
+ if (/<[A-Za-z_$][A-Za-z0-9_$:.\-]*\b[^>\n]*\/>/.test(source)) return true;
4051
4052
  return false;
4052
4053
  }
4053
4054
 
@@ -4125,6 +4126,23 @@ function __initVirtualRuntime(rootScope) {
4125
4126
  return i;
4126
4127
  }
4127
4128
 
4129
+ function isJsxCommentOnly(str) {
4130
+ if (!str) return true;
4131
+ let k = 0;
4132
+ while (k < str.length) {
4133
+ k = jsxSkipWs(str, k);
4134
+ if (k >= str.length) break;
4135
+ if (str[k] === '/' && (str[k + 1] === '/' || str[k + 1] === '*')) {
4136
+ const next = jsxSkipJsLiteral(str, k);
4137
+ if (next === -1) return false;
4138
+ k = next;
4139
+ } else {
4140
+ return false;
4141
+ }
4142
+ }
4143
+ return true;
4144
+ }
4145
+
4128
4146
  function normalizeJsxText(raw) {
4129
4147
  if (!raw) return '';
4130
4148
  let t = raw.replace(/\r/g, '');
@@ -4268,8 +4286,12 @@ function __initVirtualRuntime(rootScope) {
4268
4286
  }
4269
4287
  if (c === '{') {
4270
4288
  const br = jsxReadBraced(source, j, o);
4271
- const inner = jsxTransform(br.inner, o);
4272
- if (inner && inner.trim()) children.push(inner);
4289
+ if (!isJsxCommentOnly(br.inner)) {
4290
+ const inner = jsxTransform(br.inner, o);
4291
+ if (inner && inner.trim()) {
4292
+ children.push(inner.indexOf('//') !== -1 && !inner.endsWith('\n') ? inner + '\n' : inner);
4293
+ }
4294
+ }
4273
4295
  j = br.next;
4274
4296
  continue;
4275
4297
  }
@@ -4334,7 +4356,8 @@ function __initVirtualRuntime(rootScope) {
4334
4356
  // JSX/TSX must be rewritten before masking so JSX text is kept verbatim.
4335
4357
  if (hasJsx) {
4336
4358
  const { pragma, frag } = readJsxPragma(source);
4337
- const needsReact = pragma === 'React.createElement' && !/\bReact\b/.test(source);
4359
+ const hasReactBinding = /\bimport\s+(?!type\b)(?:\*\s+as\s+React\b|React\b)|(?:\bconst|\blet|\bvar|\bfunction|\bclass)\s+React\b|\bReact\s*=/.test(source);
4360
+ const needsReact = pragma === 'React.createElement' && (keepEsm ? !hasReactBinding : !/\bReact\b/.test(source));
4338
4361
  const transformed = jsxTransform(source, { pragma, frag });
4339
4362
  if (transformed !== source) {
4340
4363
  source = transformed;
@@ -4342,6 +4365,8 @@ function __initVirtualRuntime(rootScope) {
4342
4365
  if (needsReact) {
4343
4366
  source = (keepEsm ? 'import React from "react";\n' : 'const React = require("react");\n') + source;
4344
4367
  }
4368
+ } else if (!isTS && !hasESM) {
4369
+ return source;
4345
4370
  }
4346
4371
  }
4347
4372