@innovatorved/code-lab 0.1.10 → 0.1.11

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.11 — 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,33 @@ 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 (_) {}
3232
+ }
3233
+ }
3234
+ };
3235
+ walk(rootDir, 0);
3236
+ return files;
3237
+ }
3238
+
3205
3239
  function collectPreviewScripts(vfs, rootDir, maxFiles = 200) {
3206
3240
  return collectPreviewScriptFiles(vfs, rootDir, maxFiles).map((f) => f.content);
3207
3241
  }
@@ -3284,11 +3318,31 @@ var CodeLabLogger = (() => {
3284
3318
  return out;
3285
3319
  };
3286
3320
 
3321
+ const inlineLocalCssImports = (cssText, cssDir) => {
3322
+ if (!cssText) return '';
3323
+ return cssText.replace(/@import\s+(?:url\(\s*['"]?([^'")]+)['"]?\s*\)|['"]([^'"]+)['"])\s*;?/gi, (full, u1, u2) => {
3324
+ const spec = (u1 || u2 || '').trim();
3325
+ if (!spec || /^(?:https?:|data:|\/\/)/i.test(spec)) return full;
3326
+ if (spec === 'tailwindcss') return '';
3327
+ const subTarget = resolveLocalTarget(cssDir, spec);
3328
+ if (subTarget && /\.css$/i.test(subTarget)) {
3329
+ const subCss = readText(subTarget);
3330
+ if (subCss !== null) return subCss;
3331
+ }
3332
+ return '';
3333
+ });
3334
+ };
3335
+
3287
3336
  const buildHtmlPreviewResponse = (htmlBody, htmlTargetPath) => {
3288
3337
  const scriptFiles = collectPreviewScriptFiles(ctx.vfs, rootDir);
3338
+ const assetFiles = collectPreviewAssetFiles(ctx.vfs, rootDir);
3289
3339
  const specifiers = new Set();
3340
+ const compiledScripts = [];
3290
3341
  for (const f of scriptFiles) {
3291
3342
  for (const s of extractBareSpecifiers(f.content)) specifiers.add(s);
3343
+ const compiled = transpileAndRewriteLocalImports(f.content, f.full);
3344
+ for (const s of extractBareSpecifiers(compiled)) specifiers.add(s);
3345
+ compiledScripts.push({ file: f, compiled });
3292
3346
  }
3293
3347
  // Also scan inline module scripts in HTML for bare specifiers
3294
3348
  const inlineScriptRe = /<script\b[^>]*>([\s\S]*?)<\/script>/gi;
@@ -3302,14 +3356,53 @@ var CodeLabLogger = (() => {
3302
3356
  const importMap = buildPreviewImportMap(ctx.vfs, rootDir, specifiers);
3303
3357
  for (const f of scriptFiles) aliasPinnedCdnUrls(ctx.vfs, rootDir, f.content, importMap);
3304
3358
  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);
3359
+ for (const { file, compiled } of compiledScripts) {
3360
+ const key = toLocalImportKey(file.full);
3308
3361
  importMap[key] = `data:text/javascript;charset=utf-8,${encodeURIComponent(compiled)}`;
3309
3362
  }
3310
3363
 
3364
+ let needsTailwindBrowser = false;
3365
+ for (const af of assetFiles) {
3366
+ const key = toLocalImportKey(af.full);
3367
+ if (/\.css$/i.test(af.full)) {
3368
+ if (/@import\s+['"]tailwindcss['"]/i.test(af.content)) {
3369
+ needsTailwindBrowser = true;
3370
+ }
3371
+ const resolvedCss = inlineLocalCssImports(af.content, PosixPath.dirname(af.full));
3372
+ 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;`;
3373
+ importMap[key] = `data:text/javascript;charset=utf-8,${encodeURIComponent(cssModuleJs)}`;
3374
+ } else if (/\.json$/i.test(af.full)) {
3375
+ const jsonModuleJs = `export default ${af.content.trim() || 'null'};`;
3376
+ importMap[key] = `data:text/javascript;charset=utf-8,${encodeURIComponent(jsonModuleJs)}`;
3377
+ } else if (/\.svg$/i.test(af.full)) {
3378
+ const svgDataUrl = `data:image/svg+xml;utf8,${encodeURIComponent(af.content)}`;
3379
+ const svgModuleJs = `export default ${JSON.stringify(svgDataUrl)};`;
3380
+ importMap[key] = `data:text/javascript;charset=utf-8,${encodeURIComponent(svgModuleJs)}`;
3381
+ }
3382
+ }
3383
+
3311
3384
  const htmlDir = PosixPath.dirname(htmlTargetPath);
3312
- let transformedHtml = htmlBody;
3385
+ let transformedHtml = htmlBody.replace(/%PUBLIC_URL%\//g, '/').replace(/%PUBLIC_URL%/g, '');
3386
+
3387
+ // Auto-inject entry script for Create React App / bundler templates where index.html omits <script src="...">
3388
+ const hasLocalScriptTag = /<script\b[^>]*\bsrc\s*=\s*["']([^"']+)["'][^>]*>/i.test(transformedHtml);
3389
+ if (!hasLocalScriptTag) {
3390
+ const defaultEntries = [
3391
+ '/src/main.tsx', '/src/main.jsx', '/src/main.ts', '/src/main.js',
3392
+ '/src/index.tsx', '/src/index.jsx', '/src/index.ts', '/src/index.js'
3393
+ ];
3394
+ for (const cand of defaultEntries) {
3395
+ if (isFile(PosixPath.join(rootDir, cand.slice(1)))) {
3396
+ const entryTag = `<script type="module" src="${cand}"></script>`;
3397
+ if (/<\/body>/i.test(transformedHtml)) {
3398
+ transformedHtml = transformedHtml.replace(/<\/body>/i, ` ${entryTag}\n</body>`);
3399
+ } else {
3400
+ transformedHtml += `\n${entryTag}`;
3401
+ }
3402
+ break;
3403
+ }
3404
+ }
3405
+ }
3313
3406
 
3314
3407
  // Inline local <link rel="stylesheet" href="..."> so styles work in opaque-origin / srcdoc frames
3315
3408
  transformedHtml = transformedHtml.replace(/<link\b([^>]*?)>/gi, (fullTag, attrs) => {
@@ -3320,7 +3413,11 @@ var CodeLabLogger = (() => {
3320
3413
  if (!cssTarget || !/\.css$/i.test(cssTarget)) return fullTag;
3321
3414
  const cssContent = readText(cssTarget);
3322
3415
  if (cssContent === null) return fullTag;
3323
- return `<style data-codelab-href="${hrefMatch[1].replace(/"/g, '&quot;')}">\n${cssContent}\n</style>`;
3416
+ if (/@import\s+['"]tailwindcss['"]/i.test(cssContent)) {
3417
+ needsTailwindBrowser = true;
3418
+ }
3419
+ const resolvedCss = inlineLocalCssImports(cssContent, PosixPath.dirname(cssTarget));
3420
+ return `<style data-codelab-href="${hrefMatch[1].replace(/"/g, '&quot;')}">\n${resolvedCss}\n</style>`;
3324
3421
  });
3325
3422
 
3326
3423
  // Inline local <script ... src="..."></script> so entry modules & scripts execute reliably in opaque-origin / srcdoc frames
@@ -3332,11 +3429,20 @@ var CodeLabLogger = (() => {
3332
3429
  const rawScript = readText(scriptTarget);
3333
3430
  if (rawScript === null) return fullTag;
3334
3431
  const compiled = transpileAndRewriteLocalImports(rawScript, scriptTarget);
3335
- const isMod = /\btype\s*=\s*["']module["']/i.test(attrs) || /\.(?:tsx|ts|jsx|mjs)$/i.test(scriptTarget);
3432
+ const isMod = /\btype\s*=\s*["']module["']/i.test(attrs) || /\.(?:tsx|ts|jsx|mjs)$/i.test(scriptTarget) || /^\s*(?:import|export)\b/m.test(rawScript);
3336
3433
  const typeAttr = isMod ? ' type="module"' : '';
3337
3434
  return `<script${typeAttr} data-codelab-src="${srcMatch[1].replace(/"/g, '&quot;')}">\n${compiled}\n</script>`;
3338
3435
  });
3339
3436
 
3437
+ if (needsTailwindBrowser && !transformedHtml.includes('@tailwindcss/browser')) {
3438
+ const twTag = '<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>';
3439
+ if (/<head[^>]*>/i.test(transformedHtml)) {
3440
+ transformedHtml = transformedHtml.replace(/<head[^>]*>/i, (m) => `${m}\n ${twTag}`);
3441
+ } else {
3442
+ transformedHtml = twTag + '\n' + transformedHtml;
3443
+ }
3444
+ }
3445
+
3340
3446
  return injectPreviewExtras(transformedHtml, importMap);
3341
3447
  };
3342
3448
 
@@ -3348,7 +3454,9 @@ var CodeLabLogger = (() => {
3348
3454
  const hasExt = /\.[A-Za-z0-9]+$/.test(rel);
3349
3455
 
3350
3456
  if (!rel || pathname.endsWith('/') || isDir(target)) {
3351
- target = PosixPath.join(target, 'index.html');
3457
+ const rootIdx = PosixPath.join(target, 'index.html');
3458
+ const pubIdx = PosixPath.join(target, 'public', 'index.html');
3459
+ target = (!exists(rootIdx) && exists(pubIdx)) ? pubIdx : rootIdx;
3352
3460
  }
3353
3461
  if (!exists(target) && !hasExt) {
3354
3462
  // Resolve extensionless module specifiers (e.g. `./components/Counter`)
@@ -3362,7 +3470,9 @@ var CodeLabLogger = (() => {
3362
3470
  for (const c of cands) { if (exists(c)) { target = c; break; } }
3363
3471
  }
3364
3472
  if (!exists(target) && !hasExt) {
3365
- target = PosixPath.join(rootDir, 'index.html'); // SPA fallback
3473
+ const rootIdx = PosixPath.join(rootDir, 'index.html');
3474
+ const pubIdx = PosixPath.join(rootDir, 'public', 'index.html');
3475
+ target = (!exists(rootIdx) && exists(pubIdx)) ? pubIdx : rootIdx; // SPA fallback
3366
3476
  }
3367
3477
  if (!exists(target)) {
3368
3478
  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.11 — 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,33 @@ 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 (_) {}
3233
+ }
3234
+ }
3235
+ };
3236
+ walk(rootDir, 0);
3237
+ return files;
3238
+ }
3239
+
3206
3240
  function collectPreviewScripts(vfs, rootDir, maxFiles = 200) {
3207
3241
  return collectPreviewScriptFiles(vfs, rootDir, maxFiles).map((f) => f.content);
3208
3242
  }
@@ -3285,11 +3319,31 @@ var CodeLabLogger = (() => {
3285
3319
  return out;
3286
3320
  };
3287
3321
 
3322
+ const inlineLocalCssImports = (cssText, cssDir) => {
3323
+ if (!cssText) return '';
3324
+ return cssText.replace(/@import\s+(?:url\(\s*['"]?([^'")]+)['"]?\s*\)|['"]([^'"]+)['"])\s*;?/gi, (full, u1, u2) => {
3325
+ const spec = (u1 || u2 || '').trim();
3326
+ if (!spec || /^(?:https?:|data:|\/\/)/i.test(spec)) return full;
3327
+ if (spec === 'tailwindcss') return '';
3328
+ const subTarget = resolveLocalTarget(cssDir, spec);
3329
+ if (subTarget && /\.css$/i.test(subTarget)) {
3330
+ const subCss = readText(subTarget);
3331
+ if (subCss !== null) return subCss;
3332
+ }
3333
+ return '';
3334
+ });
3335
+ };
3336
+
3288
3337
  const buildHtmlPreviewResponse = (htmlBody, htmlTargetPath) => {
3289
3338
  const scriptFiles = collectPreviewScriptFiles(ctx.vfs, rootDir);
3339
+ const assetFiles = collectPreviewAssetFiles(ctx.vfs, rootDir);
3290
3340
  const specifiers = new Set();
3341
+ const compiledScripts = [];
3291
3342
  for (const f of scriptFiles) {
3292
3343
  for (const s of extractBareSpecifiers(f.content)) specifiers.add(s);
3344
+ const compiled = transpileAndRewriteLocalImports(f.content, f.full);
3345
+ for (const s of extractBareSpecifiers(compiled)) specifiers.add(s);
3346
+ compiledScripts.push({ file: f, compiled });
3293
3347
  }
3294
3348
  // Also scan inline module scripts in HTML for bare specifiers
3295
3349
  const inlineScriptRe = /<script\b[^>]*>([\s\S]*?)<\/script>/gi;
@@ -3303,14 +3357,53 @@ var CodeLabLogger = (() => {
3303
3357
  const importMap = buildPreviewImportMap(ctx.vfs, rootDir, specifiers);
3304
3358
  for (const f of scriptFiles) aliasPinnedCdnUrls(ctx.vfs, rootDir, f.content, importMap);
3305
3359
  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);
3360
+ for (const { file, compiled } of compiledScripts) {
3361
+ const key = toLocalImportKey(file.full);
3309
3362
  importMap[key] = `data:text/javascript;charset=utf-8,${encodeURIComponent(compiled)}`;
3310
3363
  }
3311
3364
 
3365
+ let needsTailwindBrowser = false;
3366
+ for (const af of assetFiles) {
3367
+ const key = toLocalImportKey(af.full);
3368
+ if (/\.css$/i.test(af.full)) {
3369
+ if (/@import\s+['"]tailwindcss['"]/i.test(af.content)) {
3370
+ needsTailwindBrowser = true;
3371
+ }
3372
+ const resolvedCss = inlineLocalCssImports(af.content, PosixPath.dirname(af.full));
3373
+ 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;`;
3374
+ importMap[key] = `data:text/javascript;charset=utf-8,${encodeURIComponent(cssModuleJs)}`;
3375
+ } else if (/\.json$/i.test(af.full)) {
3376
+ const jsonModuleJs = `export default ${af.content.trim() || 'null'};`;
3377
+ importMap[key] = `data:text/javascript;charset=utf-8,${encodeURIComponent(jsonModuleJs)}`;
3378
+ } else if (/\.svg$/i.test(af.full)) {
3379
+ const svgDataUrl = `data:image/svg+xml;utf8,${encodeURIComponent(af.content)}`;
3380
+ const svgModuleJs = `export default ${JSON.stringify(svgDataUrl)};`;
3381
+ importMap[key] = `data:text/javascript;charset=utf-8,${encodeURIComponent(svgModuleJs)}`;
3382
+ }
3383
+ }
3384
+
3312
3385
  const htmlDir = PosixPath.dirname(htmlTargetPath);
3313
- let transformedHtml = htmlBody;
3386
+ let transformedHtml = htmlBody.replace(/%PUBLIC_URL%\//g, '/').replace(/%PUBLIC_URL%/g, '');
3387
+
3388
+ // Auto-inject entry script for Create React App / bundler templates where index.html omits <script src="...">
3389
+ const hasLocalScriptTag = /<script\b[^>]*\bsrc\s*=\s*["']([^"']+)["'][^>]*>/i.test(transformedHtml);
3390
+ if (!hasLocalScriptTag) {
3391
+ const defaultEntries = [
3392
+ '/src/main.tsx', '/src/main.jsx', '/src/main.ts', '/src/main.js',
3393
+ '/src/index.tsx', '/src/index.jsx', '/src/index.ts', '/src/index.js'
3394
+ ];
3395
+ for (const cand of defaultEntries) {
3396
+ if (isFile(PosixPath.join(rootDir, cand.slice(1)))) {
3397
+ const entryTag = `<script type="module" src="${cand}"></script>`;
3398
+ if (/<\/body>/i.test(transformedHtml)) {
3399
+ transformedHtml = transformedHtml.replace(/<\/body>/i, ` ${entryTag}\n</body>`);
3400
+ } else {
3401
+ transformedHtml += `\n${entryTag}`;
3402
+ }
3403
+ break;
3404
+ }
3405
+ }
3406
+ }
3314
3407
 
3315
3408
  // Inline local <link rel="stylesheet" href="..."> so styles work in opaque-origin / srcdoc frames
3316
3409
  transformedHtml = transformedHtml.replace(/<link\b([^>]*?)>/gi, (fullTag, attrs) => {
@@ -3321,7 +3414,11 @@ var CodeLabLogger = (() => {
3321
3414
  if (!cssTarget || !/\.css$/i.test(cssTarget)) return fullTag;
3322
3415
  const cssContent = readText(cssTarget);
3323
3416
  if (cssContent === null) return fullTag;
3324
- return `<style data-codelab-href="${hrefMatch[1].replace(/"/g, '&quot;')}">\n${cssContent}\n</style>`;
3417
+ if (/@import\s+['"]tailwindcss['"]/i.test(cssContent)) {
3418
+ needsTailwindBrowser = true;
3419
+ }
3420
+ const resolvedCss = inlineLocalCssImports(cssContent, PosixPath.dirname(cssTarget));
3421
+ return `<style data-codelab-href="${hrefMatch[1].replace(/"/g, '&quot;')}">\n${resolvedCss}\n</style>`;
3325
3422
  });
3326
3423
 
3327
3424
  // Inline local <script ... src="..."></script> so entry modules & scripts execute reliably in opaque-origin / srcdoc frames
@@ -3333,11 +3430,20 @@ var CodeLabLogger = (() => {
3333
3430
  const rawScript = readText(scriptTarget);
3334
3431
  if (rawScript === null) return fullTag;
3335
3432
  const compiled = transpileAndRewriteLocalImports(rawScript, scriptTarget);
3336
- const isMod = /\btype\s*=\s*["']module["']/i.test(attrs) || /\.(?:tsx|ts|jsx|mjs)$/i.test(scriptTarget);
3433
+ const isMod = /\btype\s*=\s*["']module["']/i.test(attrs) || /\.(?:tsx|ts|jsx|mjs)$/i.test(scriptTarget) || /^\s*(?:import|export)\b/m.test(rawScript);
3337
3434
  const typeAttr = isMod ? ' type="module"' : '';
3338
3435
  return `<script${typeAttr} data-codelab-src="${srcMatch[1].replace(/"/g, '&quot;')}">\n${compiled}\n</script>`;
3339
3436
  });
3340
3437
 
3438
+ if (needsTailwindBrowser && !transformedHtml.includes('@tailwindcss/browser')) {
3439
+ const twTag = '<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>';
3440
+ if (/<head[^>]*>/i.test(transformedHtml)) {
3441
+ transformedHtml = transformedHtml.replace(/<head[^>]*>/i, (m) => `${m}\n ${twTag}`);
3442
+ } else {
3443
+ transformedHtml = twTag + '\n' + transformedHtml;
3444
+ }
3445
+ }
3446
+
3341
3447
  return injectPreviewExtras(transformedHtml, importMap);
3342
3448
  };
3343
3449
 
@@ -3349,7 +3455,9 @@ var CodeLabLogger = (() => {
3349
3455
  const hasExt = /\.[A-Za-z0-9]+$/.test(rel);
3350
3456
 
3351
3457
  if (!rel || pathname.endsWith('/') || isDir(target)) {
3352
- target = PosixPath.join(target, 'index.html');
3458
+ const rootIdx = PosixPath.join(target, 'index.html');
3459
+ const pubIdx = PosixPath.join(target, 'public', 'index.html');
3460
+ target = (!exists(rootIdx) && exists(pubIdx)) ? pubIdx : rootIdx;
3353
3461
  }
3354
3462
  if (!exists(target) && !hasExt) {
3355
3463
  // Resolve extensionless module specifiers (e.g. `./components/Counter`)
@@ -3363,7 +3471,9 @@ var CodeLabLogger = (() => {
3363
3471
  for (const c of cands) { if (exists(c)) { target = c; break; } }
3364
3472
  }
3365
3473
  if (!exists(target) && !hasExt) {
3366
- target = PosixPath.join(rootDir, 'index.html'); // SPA fallback
3474
+ const rootIdx = PosixPath.join(rootDir, 'index.html');
3475
+ const pubIdx = PosixPath.join(rootDir, 'public', 'index.html');
3476
+ target = (!exists(rootIdx) && exists(pubIdx)) ? pubIdx : rootIdx; // SPA fallback
3367
3477
  }
3368
3478
  if (!exists(target)) {
3369
3479
  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.11 — 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.11 — 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.11",
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