@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/code-lab.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
@@ -5933,6 +5933,7 @@ function __initVirtualRuntime(rootScope) {
5933
5933
  if (/@jsx\b/.test(source)) return true;
5934
5934
  if (source.indexOf('<>') !== -1) return true;
5935
5935
  if (/<\/[A-Za-z]/.test(source)) return true;
5936
+ if (/<[A-Za-z_$][A-Za-z0-9_$:.\-]*\b[^>\n]*\/>/.test(source)) return true;
5936
5937
  return false;
5937
5938
  }
5938
5939
 
@@ -6010,6 +6011,23 @@ function __initVirtualRuntime(rootScope) {
6010
6011
  return i;
6011
6012
  }
6012
6013
 
6014
+ function isJsxCommentOnly(str) {
6015
+ if (!str) return true;
6016
+ let k = 0;
6017
+ while (k < str.length) {
6018
+ k = jsxSkipWs(str, k);
6019
+ if (k >= str.length) break;
6020
+ if (str[k] === '/' && (str[k + 1] === '/' || str[k + 1] === '*')) {
6021
+ const next = jsxSkipJsLiteral(str, k);
6022
+ if (next === -1) return false;
6023
+ k = next;
6024
+ } else {
6025
+ return false;
6026
+ }
6027
+ }
6028
+ return true;
6029
+ }
6030
+
6013
6031
  function normalizeJsxText(raw) {
6014
6032
  if (!raw) return '';
6015
6033
  let t = raw.replace(/\r/g, '');
@@ -6153,8 +6171,12 @@ function __initVirtualRuntime(rootScope) {
6153
6171
  }
6154
6172
  if (c === '{') {
6155
6173
  const br = jsxReadBraced(source, j, o);
6156
- const inner = jsxTransform(br.inner, o);
6157
- if (inner && inner.trim()) children.push(inner);
6174
+ if (!isJsxCommentOnly(br.inner)) {
6175
+ const inner = jsxTransform(br.inner, o);
6176
+ if (inner && inner.trim()) {
6177
+ children.push(inner.indexOf('//') !== -1 && !inner.endsWith('\n') ? inner + '\n' : inner);
6178
+ }
6179
+ }
6158
6180
  j = br.next;
6159
6181
  continue;
6160
6182
  }
@@ -6219,7 +6241,8 @@ function __initVirtualRuntime(rootScope) {
6219
6241
  // JSX/TSX must be rewritten before masking so JSX text is kept verbatim.
6220
6242
  if (hasJsx) {
6221
6243
  const { pragma, frag } = readJsxPragma(source);
6222
- const needsReact = pragma === 'React.createElement' && !/\bReact\b/.test(source);
6244
+ 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);
6245
+ const needsReact = pragma === 'React.createElement' && (keepEsm ? !hasReactBinding : !/\bReact\b/.test(source));
6223
6246
  const transformed = jsxTransform(source, { pragma, frag });
6224
6247
  if (transformed !== source) {
6225
6248
  source = transformed;
@@ -6227,6 +6250,8 @@ function __initVirtualRuntime(rootScope) {
6227
6250
  if (needsReact) {
6228
6251
  source = (keepEsm ? 'import React from "react";\n' : 'const React = require("react");\n') + source;
6229
6252
  }
6253
+ } else if (!isTS && !hasESM) {
6254
+ return source;
6230
6255
  }
6231
6256
  }
6232
6257
 
@@ -13179,6 +13204,12 @@ if (typeof module !== 'undefined' && module.exports) {
13179
13204
  if (!pkgName) continue;
13180
13205
  const subpath = spec.slice(pkgName.length).replace(/^\/+/, '');
13181
13206
  const version = resolveBareVersion(vfs, rootDir, pkgName);
13207
+ if (subpath && /\.css$/i.test(subpath)) {
13208
+ const cssHref = `${CDN_ESM_BASE}/${pkgName}@${version}/${subpath.replace(/^\/+/, '')}`;
13209
+ 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)};`;
13210
+ imports[spec] = `data:text/javascript;charset=utf-8,${encodeURIComponent(loader)}`;
13211
+ continue;
13212
+ }
13182
13213
  imports[spec] = cdnEsmUrl(pkgName, version, subpath || undefined);
13183
13214
  }
13184
13215
  return imports;
@@ -13199,6 +13230,7 @@ if (typeof module !== 'undefined' && module.exports) {
13199
13230
  let match;
13200
13231
  while ((match = re.exec(text)) !== null) {
13201
13232
  const url = match[0];
13233
+ if (url.includes('${')) continue;
13202
13234
  const pkgName = decodeURIComponent(match[1]);
13203
13235
  const rest = match[2];
13204
13236
  const pinnedVersion = rest.split(/[\/?]/)[0];
@@ -13243,6 +13275,33 @@ if (typeof module !== 'undefined' && module.exports) {
13243
13275
  return files;
13244
13276
  }
13245
13277
 
13278
+ function collectPreviewAssetFiles(vfs, rootDir, maxFiles = 200) {
13279
+ const files = [];
13280
+ const walk = (dir, depth) => {
13281
+ if (depth > 8 || files.length >= maxFiles) return;
13282
+ let entries = [];
13283
+ try { entries = vfs.readdirSync(dir); } catch (_) { return; }
13284
+ for (const name of entries) {
13285
+ if (name === 'node_modules' || name.startsWith('.')) continue;
13286
+ const full = PosixPath.join(dir, name);
13287
+ let st;
13288
+ try { st = vfs.statSync(full); } catch (_) { continue; }
13289
+ const dirFlag = st && (typeof st.isDirectory === 'function' ? st.isDirectory() : st.isDirectory);
13290
+ if (dirFlag) {
13291
+ walk(full, depth + 1);
13292
+ } else if (/\.(?:css|json|svg)$/i.test(name) && files.length < maxFiles) {
13293
+ try {
13294
+ const content = vfs.readFileSync(full, 'utf8');
13295
+ const rel = full.startsWith(rootDir + '/') ? full.slice(rootDir.length + 1) : name;
13296
+ files.push({ full, rel, content });
13297
+ } catch (_) {}
13298
+ }
13299
+ }
13300
+ };
13301
+ walk(rootDir, 0);
13302
+ return files;
13303
+ }
13304
+
13246
13305
  function collectPreviewScripts(vfs, rootDir, maxFiles = 200) {
13247
13306
  return collectPreviewScriptFiles(vfs, rootDir, maxFiles).map((f) => f.content);
13248
13307
  }
@@ -13325,11 +13384,31 @@ if (typeof module !== 'undefined' && module.exports) {
13325
13384
  return out;
13326
13385
  };
13327
13386
 
13387
+ const inlineLocalCssImports = (cssText, cssDir) => {
13388
+ if (!cssText) return '';
13389
+ return cssText.replace(/@import\s+(?:url\(\s*['"]?([^'")]+)['"]?\s*\)|['"]([^'"]+)['"])\s*;?/gi, (full, u1, u2) => {
13390
+ const spec = (u1 || u2 || '').trim();
13391
+ if (!spec || /^(?:https?:|data:|\/\/)/i.test(spec)) return full;
13392
+ if (spec === 'tailwindcss') return '';
13393
+ const subTarget = resolveLocalTarget(cssDir, spec);
13394
+ if (subTarget && /\.css$/i.test(subTarget)) {
13395
+ const subCss = readText(subTarget);
13396
+ if (subCss !== null) return subCss;
13397
+ }
13398
+ return '';
13399
+ });
13400
+ };
13401
+
13328
13402
  const buildHtmlPreviewResponse = (htmlBody, htmlTargetPath) => {
13329
13403
  const scriptFiles = collectPreviewScriptFiles(ctx.vfs, rootDir);
13404
+ const assetFiles = collectPreviewAssetFiles(ctx.vfs, rootDir);
13330
13405
  const specifiers = new Set();
13406
+ const compiledScripts = [];
13331
13407
  for (const f of scriptFiles) {
13332
13408
  for (const s of extractBareSpecifiers(f.content)) specifiers.add(s);
13409
+ const compiled = transpileAndRewriteLocalImports(f.content, f.full);
13410
+ for (const s of extractBareSpecifiers(compiled)) specifiers.add(s);
13411
+ compiledScripts.push({ file: f, compiled });
13333
13412
  }
13334
13413
  // Also scan inline module scripts in HTML for bare specifiers
13335
13414
  const inlineScriptRe = /<script\b[^>]*>([\s\S]*?)<\/script>/gi;
@@ -13343,14 +13422,53 @@ if (typeof module !== 'undefined' && module.exports) {
13343
13422
  const importMap = buildPreviewImportMap(ctx.vfs, rootDir, specifiers);
13344
13423
  for (const f of scriptFiles) aliasPinnedCdnUrls(ctx.vfs, rootDir, f.content, importMap);
13345
13424
  aliasPinnedCdnUrls(ctx.vfs, rootDir, htmlBody, importMap);
13346
- for (const f of scriptFiles) {
13347
- const compiled = transpileAndRewriteLocalImports(f.content, f.full);
13348
- const key = toLocalImportKey(f.full);
13425
+ for (const { file, compiled } of compiledScripts) {
13426
+ const key = toLocalImportKey(file.full);
13349
13427
  importMap[key] = `data:text/javascript;charset=utf-8,${encodeURIComponent(compiled)}`;
13350
13428
  }
13351
13429
 
13430
+ let needsTailwindBrowser = false;
13431
+ for (const af of assetFiles) {
13432
+ const key = toLocalImportKey(af.full);
13433
+ if (/\.css$/i.test(af.full)) {
13434
+ if (/@import\s+['"]tailwindcss['"]/i.test(af.content)) {
13435
+ needsTailwindBrowser = true;
13436
+ }
13437
+ const resolvedCss = inlineLocalCssImports(af.content, PosixPath.dirname(af.full));
13438
+ 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;`;
13439
+ importMap[key] = `data:text/javascript;charset=utf-8,${encodeURIComponent(cssModuleJs)}`;
13440
+ } else if (/\.json$/i.test(af.full)) {
13441
+ const jsonModuleJs = `export default ${af.content.trim() || 'null'};`;
13442
+ importMap[key] = `data:text/javascript;charset=utf-8,${encodeURIComponent(jsonModuleJs)}`;
13443
+ } else if (/\.svg$/i.test(af.full)) {
13444
+ const svgDataUrl = `data:image/svg+xml;utf8,${encodeURIComponent(af.content)}`;
13445
+ const svgModuleJs = `export default ${JSON.stringify(svgDataUrl)};`;
13446
+ importMap[key] = `data:text/javascript;charset=utf-8,${encodeURIComponent(svgModuleJs)}`;
13447
+ }
13448
+ }
13449
+
13352
13450
  const htmlDir = PosixPath.dirname(htmlTargetPath);
13353
- let transformedHtml = htmlBody;
13451
+ let transformedHtml = htmlBody.replace(/%PUBLIC_URL%\//g, '/').replace(/%PUBLIC_URL%/g, '');
13452
+
13453
+ // Auto-inject entry script for Create React App / bundler templates where index.html omits <script src="...">
13454
+ const hasLocalScriptTag = /<script\b[^>]*\bsrc\s*=\s*["']([^"']+)["'][^>]*>/i.test(transformedHtml);
13455
+ if (!hasLocalScriptTag) {
13456
+ const defaultEntries = [
13457
+ '/src/main.tsx', '/src/main.jsx', '/src/main.ts', '/src/main.js',
13458
+ '/src/index.tsx', '/src/index.jsx', '/src/index.ts', '/src/index.js'
13459
+ ];
13460
+ for (const cand of defaultEntries) {
13461
+ if (isFile(PosixPath.join(rootDir, cand.slice(1)))) {
13462
+ const entryTag = `<script type="module" src="${cand}"></script>`;
13463
+ if (/<\/body>/i.test(transformedHtml)) {
13464
+ transformedHtml = transformedHtml.replace(/<\/body>/i, ` ${entryTag}\n</body>`);
13465
+ } else {
13466
+ transformedHtml += `\n${entryTag}`;
13467
+ }
13468
+ break;
13469
+ }
13470
+ }
13471
+ }
13354
13472
 
13355
13473
  // Inline local <link rel="stylesheet" href="..."> so styles work in opaque-origin / srcdoc frames
13356
13474
  transformedHtml = transformedHtml.replace(/<link\b([^>]*?)>/gi, (fullTag, attrs) => {
@@ -13361,7 +13479,11 @@ if (typeof module !== 'undefined' && module.exports) {
13361
13479
  if (!cssTarget || !/\.css$/i.test(cssTarget)) return fullTag;
13362
13480
  const cssContent = readText(cssTarget);
13363
13481
  if (cssContent === null) return fullTag;
13364
- return `<style data-codelab-href="${hrefMatch[1].replace(/"/g, '&quot;')}">\n${cssContent}\n</style>`;
13482
+ if (/@import\s+['"]tailwindcss['"]/i.test(cssContent)) {
13483
+ needsTailwindBrowser = true;
13484
+ }
13485
+ const resolvedCss = inlineLocalCssImports(cssContent, PosixPath.dirname(cssTarget));
13486
+ return `<style data-codelab-href="${hrefMatch[1].replace(/"/g, '&quot;')}">\n${resolvedCss}\n</style>`;
13365
13487
  });
13366
13488
 
13367
13489
  // Inline local <script ... src="..."></script> so entry modules & scripts execute reliably in opaque-origin / srcdoc frames
@@ -13373,11 +13495,20 @@ if (typeof module !== 'undefined' && module.exports) {
13373
13495
  const rawScript = readText(scriptTarget);
13374
13496
  if (rawScript === null) return fullTag;
13375
13497
  const compiled = transpileAndRewriteLocalImports(rawScript, scriptTarget);
13376
- const isMod = /\btype\s*=\s*["']module["']/i.test(attrs) || /\.(?:tsx|ts|jsx|mjs)$/i.test(scriptTarget);
13498
+ const isMod = /\btype\s*=\s*["']module["']/i.test(attrs) || /\.(?:tsx|ts|jsx|mjs)$/i.test(scriptTarget) || /^\s*(?:import|export)\b/m.test(rawScript);
13377
13499
  const typeAttr = isMod ? ' type="module"' : '';
13378
13500
  return `<script${typeAttr} data-codelab-src="${srcMatch[1].replace(/"/g, '&quot;')}">\n${compiled}\n</script>`;
13379
13501
  });
13380
13502
 
13503
+ if (needsTailwindBrowser && !transformedHtml.includes('@tailwindcss/browser')) {
13504
+ const twTag = '<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>';
13505
+ if (/<head[^>]*>/i.test(transformedHtml)) {
13506
+ transformedHtml = transformedHtml.replace(/<head[^>]*>/i, (m) => `${m}\n ${twTag}`);
13507
+ } else {
13508
+ transformedHtml = twTag + '\n' + transformedHtml;
13509
+ }
13510
+ }
13511
+
13381
13512
  return injectPreviewExtras(transformedHtml, importMap);
13382
13513
  };
13383
13514
 
@@ -13389,7 +13520,9 @@ if (typeof module !== 'undefined' && module.exports) {
13389
13520
  const hasExt = /\.[A-Za-z0-9]+$/.test(rel);
13390
13521
 
13391
13522
  if (!rel || pathname.endsWith('/') || isDir(target)) {
13392
- target = PosixPath.join(target, 'index.html');
13523
+ const rootIdx = PosixPath.join(target, 'index.html');
13524
+ const pubIdx = PosixPath.join(target, 'public', 'index.html');
13525
+ target = (!exists(rootIdx) && exists(pubIdx)) ? pubIdx : rootIdx;
13393
13526
  }
13394
13527
  if (!exists(target) && !hasExt) {
13395
13528
  // Resolve extensionless module specifiers (e.g. `./components/Counter`)
@@ -13403,7 +13536,9 @@ if (typeof module !== 'undefined' && module.exports) {
13403
13536
  for (const c of cands) { if (exists(c)) { target = c; break; } }
13404
13537
  }
13405
13538
  if (!exists(target) && !hasExt) {
13406
- target = PosixPath.join(rootDir, 'index.html'); // SPA fallback
13539
+ const rootIdx = PosixPath.join(rootDir, 'index.html');
13540
+ const pubIdx = PosixPath.join(rootDir, 'public', 'index.html');
13541
+ target = (!exists(rootIdx) && exists(pubIdx)) ? pubIdx : rootIdx; // SPA fallback
13407
13542
  }
13408
13543
  if (!exists(target)) {
13409
13544
  return new Response(
@@ -18785,7 +18920,7 @@ if (typeof module !== 'undefined' && module.exports) {
18785
18920
 
18786
18921
  // The bundler rewrites this literal from package.json at build time. Keeping
18787
18922
  // the fallback in sync lets tests require src/workbench.js directly.
18788
- const CODELAB_VERSION = '0.1.10';
18923
+ const CODELAB_VERSION = '0.1.11';
18789
18924
 
18790
18925
  // Ambient TypeScript declarations for Node.js built-ins inside Monaco
18791
18926
  const NODE_AMBIENT_DTS = `
@@ -20716,7 +20851,12 @@ declare module 'bun:sqlite' {
20716
20851
  const found = names.find(f => pattern.test(f));
20717
20852
  if (found) return found;
20718
20853
  if (kind === 'demo') {
20719
- return names.find(f => /\.(js|ts)$/i.test(f) && !/(^|\/)test\.(js|ts)$/i.test(f)) || null;
20854
+ const isConfigOrTest = f => /(^|\/)(test|.*\.(?:test|spec|config|d))\.(js|ts|mjs|cjs)$/i.test(f) || /(^|\/)\.[^/]+$/i.test(f);
20855
+ const hasHtmlEntry = Boolean(this.files['index.html'] || this.files['public/index.html']);
20856
+ if (hasHtmlEntry) {
20857
+ return names.find(f => /(^|\/)(server|app|demo)\.(js|ts)$/i.test(f) && !/^src\//i.test(f)) || null;
20858
+ }
20859
+ return names.find(f => /\.(js|ts)$/i.test(f) && !isConfigOrTest(f)) || null;
20720
20860
  }
20721
20861
  return null;
20722
20862
  }
@@ -23449,8 +23589,10 @@ declare module 'bun:sqlite' {
23449
23589
  return null;
23450
23590
  }
23451
23591
 
23452
- const rootDir = (this.files['public/index.html']) ? '/workspace/public'
23453
- : (this.files['site/index.html']) ? '/workspace/site'
23592
+ const hasSrcScripts = Boolean(this.files && Object.keys(this.files).some((f) => /^src\/.+\.(?:[cm]?jsx?|tsx?)$/i.test(f)));
23593
+ const rootDir = this.files['index.html'] ? '/workspace'
23594
+ : (this.files['public/index.html'] && !hasSrcScripts) ? '/workspace/public'
23595
+ : this.files['site/index.html'] ? '/workspace/site'
23454
23596
  : '/workspace';
23455
23597
 
23456
23598
  if (!this.shell || typeof this.shell.execute !== 'function') return null;
@@ -25938,6 +26080,9 @@ declare module 'bun:sqlite' {
25938
26080
  if (this.isRunning) return;
25939
26081
  const entry = this._findEntryFile('demo');
25940
26082
  if (!entry) {
26083
+ if ((this.files['index.html'] || this.files['public/index.html']) && typeof this.previewApp === 'function') {
26084
+ return this.previewApp();
26085
+ }
25941
26086
  this.terminalLogs.push({ type: 'stderr', text: 'No demo.js / demo.ts file found in this workspace.' });
25942
26087
  this.drawerTab = 'terminal';
25943
26088
  this._renderDrawerBody();
@@ -26813,7 +26958,7 @@ declare module 'bun:sqlite' {
26813
26958
  Enter any public GitHub repository URL or <code>owner/repo</code> slug. Files will be cloned directly into the in-memory Virtual Filesystem (VFS) with zero authentication required.
26814
26959
  </p>
26815
26960
  <div style="display:flex;gap:8px;">
26816
- <input id="cl-clone-repo-input" type="text" placeholder="e.g. innovatorved/code-lab or https://github.com/owner/repo" style="flex:1;height:34px;padding:0 10px;background:var(--cl-bg);border:1px solid var(--cl-border-strong);border-radius:var(--cl-radius-sm);color:var(--cl-fg);font-family:var(--cl-font-mono);font-size:12px;outline:none;" />
26961
+ <input id="cl-clone-repo-input" type="text" placeholder="e.g. mdn/todo-react or https://github.com/owner/repo" style="flex:1;height:34px;padding:0 10px;background:var(--cl-bg);border:1px solid var(--cl-border-strong);border-radius:var(--cl-radius-sm);color:var(--cl-fg);font-family:var(--cl-font-mono);font-size:12px;outline:none;" />
26817
26962
  <button type="button" class="codelab-btn codelab-btn--primary" data-cl-action="confirm-clone-repo">Clone Repo</button>
26818
26963
  </div>
26819
26964
  </div>
@@ -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
@@ -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
@@ -4167,6 +4167,7 @@ function __initVirtualRuntime(rootScope) {
4167
4167
  if (/@jsx\b/.test(source)) return true;
4168
4168
  if (source.indexOf('<>') !== -1) return true;
4169
4169
  if (/<\/[A-Za-z]/.test(source)) return true;
4170
+ if (/<[A-Za-z_$][A-Za-z0-9_$:.\-]*\b[^>\n]*\/>/.test(source)) return true;
4170
4171
  return false;
4171
4172
  }
4172
4173
 
@@ -4244,6 +4245,23 @@ function __initVirtualRuntime(rootScope) {
4244
4245
  return i;
4245
4246
  }
4246
4247
 
4248
+ function isJsxCommentOnly(str) {
4249
+ if (!str) return true;
4250
+ let k = 0;
4251
+ while (k < str.length) {
4252
+ k = jsxSkipWs(str, k);
4253
+ if (k >= str.length) break;
4254
+ if (str[k] === '/' && (str[k + 1] === '/' || str[k + 1] === '*')) {
4255
+ const next = jsxSkipJsLiteral(str, k);
4256
+ if (next === -1) return false;
4257
+ k = next;
4258
+ } else {
4259
+ return false;
4260
+ }
4261
+ }
4262
+ return true;
4263
+ }
4264
+
4247
4265
  function normalizeJsxText(raw) {
4248
4266
  if (!raw) return '';
4249
4267
  let t = raw.replace(/\r/g, '');
@@ -4387,8 +4405,12 @@ function __initVirtualRuntime(rootScope) {
4387
4405
  }
4388
4406
  if (c === '{') {
4389
4407
  const br = jsxReadBraced(source, j, o);
4390
- const inner = jsxTransform(br.inner, o);
4391
- if (inner && inner.trim()) children.push(inner);
4408
+ if (!isJsxCommentOnly(br.inner)) {
4409
+ const inner = jsxTransform(br.inner, o);
4410
+ if (inner && inner.trim()) {
4411
+ children.push(inner.indexOf('//') !== -1 && !inner.endsWith('\n') ? inner + '\n' : inner);
4412
+ }
4413
+ }
4392
4414
  j = br.next;
4393
4415
  continue;
4394
4416
  }
@@ -4453,7 +4475,8 @@ function __initVirtualRuntime(rootScope) {
4453
4475
  // JSX/TSX must be rewritten before masking so JSX text is kept verbatim.
4454
4476
  if (hasJsx) {
4455
4477
  const { pragma, frag } = readJsxPragma(source);
4456
- const needsReact = pragma === 'React.createElement' && !/\bReact\b/.test(source);
4478
+ 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);
4479
+ const needsReact = pragma === 'React.createElement' && (keepEsm ? !hasReactBinding : !/\bReact\b/.test(source));
4457
4480
  const transformed = jsxTransform(source, { pragma, frag });
4458
4481
  if (transformed !== source) {
4459
4482
  source = transformed;
@@ -4461,6 +4484,8 @@ function __initVirtualRuntime(rootScope) {
4461
4484
  if (needsReact) {
4462
4485
  source = (keepEsm ? 'import React from "react";\n' : 'const React = require("react");\n') + source;
4463
4486
  }
4487
+ } else if (!isTS && !hasESM) {
4488
+ return source;
4464
4489
  }
4465
4490
  }
4466
4491
 
package/dist/runtime.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
@@ -4168,6 +4168,7 @@ function __initVirtualRuntime(rootScope) {
4168
4168
  if (/@jsx\b/.test(source)) return true;
4169
4169
  if (source.indexOf('<>') !== -1) return true;
4170
4170
  if (/<\/[A-Za-z]/.test(source)) return true;
4171
+ if (/<[A-Za-z_$][A-Za-z0-9_$:.\-]*\b[^>\n]*\/>/.test(source)) return true;
4171
4172
  return false;
4172
4173
  }
4173
4174
 
@@ -4245,6 +4246,23 @@ function __initVirtualRuntime(rootScope) {
4245
4246
  return i;
4246
4247
  }
4247
4248
 
4249
+ function isJsxCommentOnly(str) {
4250
+ if (!str) return true;
4251
+ let k = 0;
4252
+ while (k < str.length) {
4253
+ k = jsxSkipWs(str, k);
4254
+ if (k >= str.length) break;
4255
+ if (str[k] === '/' && (str[k + 1] === '/' || str[k + 1] === '*')) {
4256
+ const next = jsxSkipJsLiteral(str, k);
4257
+ if (next === -1) return false;
4258
+ k = next;
4259
+ } else {
4260
+ return false;
4261
+ }
4262
+ }
4263
+ return true;
4264
+ }
4265
+
4248
4266
  function normalizeJsxText(raw) {
4249
4267
  if (!raw) return '';
4250
4268
  let t = raw.replace(/\r/g, '');
@@ -4388,8 +4406,12 @@ function __initVirtualRuntime(rootScope) {
4388
4406
  }
4389
4407
  if (c === '{') {
4390
4408
  const br = jsxReadBraced(source, j, o);
4391
- const inner = jsxTransform(br.inner, o);
4392
- if (inner && inner.trim()) children.push(inner);
4409
+ if (!isJsxCommentOnly(br.inner)) {
4410
+ const inner = jsxTransform(br.inner, o);
4411
+ if (inner && inner.trim()) {
4412
+ children.push(inner.indexOf('//') !== -1 && !inner.endsWith('\n') ? inner + '\n' : inner);
4413
+ }
4414
+ }
4393
4415
  j = br.next;
4394
4416
  continue;
4395
4417
  }
@@ -4454,7 +4476,8 @@ function __initVirtualRuntime(rootScope) {
4454
4476
  // JSX/TSX must be rewritten before masking so JSX text is kept verbatim.
4455
4477
  if (hasJsx) {
4456
4478
  const { pragma, frag } = readJsxPragma(source);
4457
- const needsReact = pragma === 'React.createElement' && !/\bReact\b/.test(source);
4479
+ 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);
4480
+ const needsReact = pragma === 'React.createElement' && (keepEsm ? !hasReactBinding : !/\bReact\b/.test(source));
4458
4481
  const transformed = jsxTransform(source, { pragma, frag });
4459
4482
  if (transformed !== source) {
4460
4483
  source = transformed;
@@ -4462,6 +4485,8 @@ function __initVirtualRuntime(rootScope) {
4462
4485
  if (needsReact) {
4463
4486
  source = (keepEsm ? 'import React from "react";\n' : 'const React = require("react");\n') + source;
4464
4487
  }
4488
+ } else if (!isTS && !hasESM) {
4489
+ return source;
4465
4490
  }
4466
4491
  }
4467
4492