@innovatorved/code-lab 0.1.9 → 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.
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * ============================================================
3
- * @innovatorved/code-lab v0.1.9 — 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
@@ -146,7 +146,7 @@ var CodeLabCsp = (() => {
146
146
  const host = normalizeOrigin(options.hostOrigin);
147
147
  const self = host || "'self'";
148
148
  const directive = (name, parts) => `${name} ${unique(parts).join(" ")}`;
149
- const script = () => [self, "blob:", "'unsafe-inline'", "'unsafe-eval'"].concat(sourcesFor(mode, allow, "scriptSrc"));
149
+ const script = () => [self, "data:", "blob:", "'unsafe-inline'", "'unsafe-eval'"].concat(sourcesFor(mode, allow, "scriptSrc"));
150
150
  const style = () => [self, "'unsafe-inline'"].concat(sourcesFor(mode, allow, "styleSrc"));
151
151
  const withData = (key) => [self, "data:", "blob:"].concat(sourcesFor(mode, allow, key));
152
152
  return [
@@ -5932,6 +5932,7 @@ function __initVirtualRuntime(rootScope) {
5932
5932
  if (/@jsx\b/.test(source)) return true;
5933
5933
  if (source.indexOf('<>') !== -1) return true;
5934
5934
  if (/<\/[A-Za-z]/.test(source)) return true;
5935
+ if (/<[A-Za-z_$][A-Za-z0-9_$:.\-]*\b[^>\n]*\/>/.test(source)) return true;
5935
5936
  return false;
5936
5937
  }
5937
5938
 
@@ -6009,6 +6010,23 @@ function __initVirtualRuntime(rootScope) {
6009
6010
  return i;
6010
6011
  }
6011
6012
 
6013
+ function isJsxCommentOnly(str) {
6014
+ if (!str) return true;
6015
+ let k = 0;
6016
+ while (k < str.length) {
6017
+ k = jsxSkipWs(str, k);
6018
+ if (k >= str.length) break;
6019
+ if (str[k] === '/' && (str[k + 1] === '/' || str[k + 1] === '*')) {
6020
+ const next = jsxSkipJsLiteral(str, k);
6021
+ if (next === -1) return false;
6022
+ k = next;
6023
+ } else {
6024
+ return false;
6025
+ }
6026
+ }
6027
+ return true;
6028
+ }
6029
+
6012
6030
  function normalizeJsxText(raw) {
6013
6031
  if (!raw) return '';
6014
6032
  let t = raw.replace(/\r/g, '');
@@ -6152,8 +6170,12 @@ function __initVirtualRuntime(rootScope) {
6152
6170
  }
6153
6171
  if (c === '{') {
6154
6172
  const br = jsxReadBraced(source, j, o);
6155
- const inner = jsxTransform(br.inner, o);
6156
- if (inner && inner.trim()) children.push(inner);
6173
+ if (!isJsxCommentOnly(br.inner)) {
6174
+ const inner = jsxTransform(br.inner, o);
6175
+ if (inner && inner.trim()) {
6176
+ children.push(inner.indexOf('//') !== -1 && !inner.endsWith('\n') ? inner + '\n' : inner);
6177
+ }
6178
+ }
6157
6179
  j = br.next;
6158
6180
  continue;
6159
6181
  }
@@ -6218,7 +6240,8 @@ function __initVirtualRuntime(rootScope) {
6218
6240
  // JSX/TSX must be rewritten before masking so JSX text is kept verbatim.
6219
6241
  if (hasJsx) {
6220
6242
  const { pragma, frag } = readJsxPragma(source);
6221
- const needsReact = pragma === 'React.createElement' && !/\bReact\b/.test(source);
6243
+ 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);
6244
+ const needsReact = pragma === 'React.createElement' && (keepEsm ? !hasReactBinding : !/\bReact\b/.test(source));
6222
6245
  const transformed = jsxTransform(source, { pragma, frag });
6223
6246
  if (transformed !== source) {
6224
6247
  source = transformed;
@@ -6226,6 +6249,8 @@ function __initVirtualRuntime(rootScope) {
6226
6249
  if (needsReact) {
6227
6250
  source = (keepEsm ? 'import React from "react";\n' : 'const React = require("react");\n') + source;
6228
6251
  }
6252
+ } else if (!isTS && !hasESM) {
6253
+ return source;
6229
6254
  }
6230
6255
  }
6231
6256
 
@@ -13176,11 +13201,48 @@ if (typeof module !== 'undefined' && module.exports) {
13176
13201
  if (!pkgName) continue;
13177
13202
  const subpath = spec.slice(pkgName.length).replace(/^\/+/, '');
13178
13203
  const version = resolveBareVersion(vfs, rootDir, pkgName);
13204
+ if (subpath && /\.css$/i.test(subpath)) {
13205
+ const cssHref = `${CDN_ESM_BASE}/${pkgName}@${version}/${subpath.replace(/^\/+/, '')}`;
13206
+ 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)};`;
13207
+ imports[spec] = `data:text/javascript;charset=utf-8,${encodeURIComponent(loader)}`;
13208
+ continue;
13209
+ }
13179
13210
  imports[spec] = cdnEsmUrl(pkgName, version, subpath || undefined);
13180
13211
  }
13181
13212
  return imports;
13182
13213
  }
13183
13214
 
13215
+ // Some templates pin a CDN URL in the source instead of importing a bare
13216
+ // specifier, e.g. `import React from "https://cdn.jsdelivr.net/npm/react@19.3.1/+esm"`.
13217
+ // Those URL specifiers are resolved by the browser directly, so they bypass the
13218
+ // generated import map (and with it the project's declared version and the
13219
+ // multi-CDN fallback). Import maps can remap URL specifiers, so alias each
13220
+ // literal URL found in the project to the resolved bare-specifier URL.
13221
+ // The pinned version is kept when the project has no dependency to resolve.
13222
+ const PINNED_CDN_URL_RE = /https?:\/\/(?:cdn\.jsdelivr\.net\/npm|esm\.sh)\/((?:@[^\/'"`@\s]+\/)?[^\/'"`@\s]+)@([^\s'"`),;]+)/g;
13223
+
13224
+ function aliasPinnedCdnUrls(vfs, rootDir, text, importMap) {
13225
+ if (!text || typeof text !== 'string') return;
13226
+ const re = new RegExp(PINNED_CDN_URL_RE.source, 'g');
13227
+ let match;
13228
+ while ((match = re.exec(text)) !== null) {
13229
+ const url = match[0];
13230
+ if (url.includes('${')) continue;
13231
+ const pkgName = decodeURIComponent(match[1]);
13232
+ const rest = match[2];
13233
+ const pinnedVersion = rest.split(/[\/?]/)[0];
13234
+ const tail = rest.slice(pinnedVersion.length);
13235
+ const rawSubpath = tail.startsWith('/') && tail !== '/+esm' ? tail.slice(1).split(/[?#]/)[0] : '';
13236
+ const subpath = rawSubpath.replace(/^\/+|\/+$/g, '');
13237
+ const bare = subpath ? `${pkgName}/${subpath}` : pkgName;
13238
+
13239
+ const declared = resolveBareVersion(vfs, rootDir, pkgName);
13240
+ const version = declared && declared !== 'latest' ? declared : decodeURIComponent(pinnedVersion);
13241
+ const target = importMap[bare] || cdnEsmUrl(pkgName, version, subpath || undefined);
13242
+ if (target && target !== url) importMap[url] = target;
13243
+ }
13244
+ }
13245
+
13184
13246
  function collectPreviewScriptFiles(vfs, rootDir, maxFiles = 200) {
13185
13247
  const files = [];
13186
13248
  const walk = (dir, depth) => {
@@ -13210,6 +13272,33 @@ if (typeof module !== 'undefined' && module.exports) {
13210
13272
  return files;
13211
13273
  }
13212
13274
 
13275
+ function collectPreviewAssetFiles(vfs, rootDir, maxFiles = 200) {
13276
+ const files = [];
13277
+ const walk = (dir, depth) => {
13278
+ if (depth > 8 || files.length >= maxFiles) return;
13279
+ let entries = [];
13280
+ try { entries = vfs.readdirSync(dir); } catch (_) { return; }
13281
+ for (const name of entries) {
13282
+ if (name === 'node_modules' || name.startsWith('.')) continue;
13283
+ const full = PosixPath.join(dir, name);
13284
+ let st;
13285
+ try { st = vfs.statSync(full); } catch (_) { continue; }
13286
+ const dirFlag = st && (typeof st.isDirectory === 'function' ? st.isDirectory() : st.isDirectory);
13287
+ if (dirFlag) {
13288
+ walk(full, depth + 1);
13289
+ } else if (/\.(?:css|json|svg)$/i.test(name) && files.length < maxFiles) {
13290
+ try {
13291
+ const content = vfs.readFileSync(full, 'utf8');
13292
+ const rel = full.startsWith(rootDir + '/') ? full.slice(rootDir.length + 1) : name;
13293
+ files.push({ full, rel, content });
13294
+ } catch (_) {}
13295
+ }
13296
+ }
13297
+ };
13298
+ walk(rootDir, 0);
13299
+ return files;
13300
+ }
13301
+
13213
13302
  function collectPreviewScripts(vfs, rootDir, maxFiles = 200) {
13214
13303
  return collectPreviewScriptFiles(vfs, rootDir, maxFiles).map((f) => f.content);
13215
13304
  }
@@ -13292,11 +13381,31 @@ if (typeof module !== 'undefined' && module.exports) {
13292
13381
  return out;
13293
13382
  };
13294
13383
 
13384
+ const inlineLocalCssImports = (cssText, cssDir) => {
13385
+ if (!cssText) return '';
13386
+ return cssText.replace(/@import\s+(?:url\(\s*['"]?([^'")]+)['"]?\s*\)|['"]([^'"]+)['"])\s*;?/gi, (full, u1, u2) => {
13387
+ const spec = (u1 || u2 || '').trim();
13388
+ if (!spec || /^(?:https?:|data:|\/\/)/i.test(spec)) return full;
13389
+ if (spec === 'tailwindcss') return '';
13390
+ const subTarget = resolveLocalTarget(cssDir, spec);
13391
+ if (subTarget && /\.css$/i.test(subTarget)) {
13392
+ const subCss = readText(subTarget);
13393
+ if (subCss !== null) return subCss;
13394
+ }
13395
+ return '';
13396
+ });
13397
+ };
13398
+
13295
13399
  const buildHtmlPreviewResponse = (htmlBody, htmlTargetPath) => {
13296
13400
  const scriptFiles = collectPreviewScriptFiles(ctx.vfs, rootDir);
13401
+ const assetFiles = collectPreviewAssetFiles(ctx.vfs, rootDir);
13297
13402
  const specifiers = new Set();
13403
+ const compiledScripts = [];
13298
13404
  for (const f of scriptFiles) {
13299
13405
  for (const s of extractBareSpecifiers(f.content)) specifiers.add(s);
13406
+ const compiled = transpileAndRewriteLocalImports(f.content, f.full);
13407
+ for (const s of extractBareSpecifiers(compiled)) specifiers.add(s);
13408
+ compiledScripts.push({ file: f, compiled });
13300
13409
  }
13301
13410
  // Also scan inline module scripts in HTML for bare specifiers
13302
13411
  const inlineScriptRe = /<script\b[^>]*>([\s\S]*?)<\/script>/gi;
@@ -13308,14 +13417,55 @@ if (typeof module !== 'undefined' && module.exports) {
13308
13417
  }
13309
13418
 
13310
13419
  const importMap = buildPreviewImportMap(ctx.vfs, rootDir, specifiers);
13311
- for (const f of scriptFiles) {
13312
- const compiled = transpileAndRewriteLocalImports(f.content, f.full);
13313
- const key = toLocalImportKey(f.full);
13420
+ for (const f of scriptFiles) aliasPinnedCdnUrls(ctx.vfs, rootDir, f.content, importMap);
13421
+ aliasPinnedCdnUrls(ctx.vfs, rootDir, htmlBody, importMap);
13422
+ for (const { file, compiled } of compiledScripts) {
13423
+ const key = toLocalImportKey(file.full);
13314
13424
  importMap[key] = `data:text/javascript;charset=utf-8,${encodeURIComponent(compiled)}`;
13315
13425
  }
13316
13426
 
13427
+ let needsTailwindBrowser = false;
13428
+ for (const af of assetFiles) {
13429
+ const key = toLocalImportKey(af.full);
13430
+ if (/\.css$/i.test(af.full)) {
13431
+ if (/@import\s+['"]tailwindcss['"]/i.test(af.content)) {
13432
+ needsTailwindBrowser = true;
13433
+ }
13434
+ const resolvedCss = inlineLocalCssImports(af.content, PosixPath.dirname(af.full));
13435
+ 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;`;
13436
+ importMap[key] = `data:text/javascript;charset=utf-8,${encodeURIComponent(cssModuleJs)}`;
13437
+ } else if (/\.json$/i.test(af.full)) {
13438
+ const jsonModuleJs = `export default ${af.content.trim() || 'null'};`;
13439
+ importMap[key] = `data:text/javascript;charset=utf-8,${encodeURIComponent(jsonModuleJs)}`;
13440
+ } else if (/\.svg$/i.test(af.full)) {
13441
+ const svgDataUrl = `data:image/svg+xml;utf8,${encodeURIComponent(af.content)}`;
13442
+ const svgModuleJs = `export default ${JSON.stringify(svgDataUrl)};`;
13443
+ importMap[key] = `data:text/javascript;charset=utf-8,${encodeURIComponent(svgModuleJs)}`;
13444
+ }
13445
+ }
13446
+
13317
13447
  const htmlDir = PosixPath.dirname(htmlTargetPath);
13318
- let transformedHtml = htmlBody;
13448
+ let transformedHtml = htmlBody.replace(/%PUBLIC_URL%\//g, '/').replace(/%PUBLIC_URL%/g, '');
13449
+
13450
+ // Auto-inject entry script for Create React App / bundler templates where index.html omits <script src="...">
13451
+ const hasLocalScriptTag = /<script\b[^>]*\bsrc\s*=\s*["']([^"']+)["'][^>]*>/i.test(transformedHtml);
13452
+ if (!hasLocalScriptTag) {
13453
+ const defaultEntries = [
13454
+ '/src/main.tsx', '/src/main.jsx', '/src/main.ts', '/src/main.js',
13455
+ '/src/index.tsx', '/src/index.jsx', '/src/index.ts', '/src/index.js'
13456
+ ];
13457
+ for (const cand of defaultEntries) {
13458
+ if (isFile(PosixPath.join(rootDir, cand.slice(1)))) {
13459
+ const entryTag = `<script type="module" src="${cand}"></script>`;
13460
+ if (/<\/body>/i.test(transformedHtml)) {
13461
+ transformedHtml = transformedHtml.replace(/<\/body>/i, ` ${entryTag}\n</body>`);
13462
+ } else {
13463
+ transformedHtml += `\n${entryTag}`;
13464
+ }
13465
+ break;
13466
+ }
13467
+ }
13468
+ }
13319
13469
 
13320
13470
  // Inline local <link rel="stylesheet" href="..."> so styles work in opaque-origin / srcdoc frames
13321
13471
  transformedHtml = transformedHtml.replace(/<link\b([^>]*?)>/gi, (fullTag, attrs) => {
@@ -13326,7 +13476,11 @@ if (typeof module !== 'undefined' && module.exports) {
13326
13476
  if (!cssTarget || !/\.css$/i.test(cssTarget)) return fullTag;
13327
13477
  const cssContent = readText(cssTarget);
13328
13478
  if (cssContent === null) return fullTag;
13329
- return `<style data-codelab-href="${hrefMatch[1].replace(/"/g, '&quot;')}">\n${cssContent}\n</style>`;
13479
+ if (/@import\s+['"]tailwindcss['"]/i.test(cssContent)) {
13480
+ needsTailwindBrowser = true;
13481
+ }
13482
+ const resolvedCss = inlineLocalCssImports(cssContent, PosixPath.dirname(cssTarget));
13483
+ return `<style data-codelab-href="${hrefMatch[1].replace(/"/g, '&quot;')}">\n${resolvedCss}\n</style>`;
13330
13484
  });
13331
13485
 
13332
13486
  // Inline local <script ... src="..."></script> so entry modules & scripts execute reliably in opaque-origin / srcdoc frames
@@ -13338,11 +13492,20 @@ if (typeof module !== 'undefined' && module.exports) {
13338
13492
  const rawScript = readText(scriptTarget);
13339
13493
  if (rawScript === null) return fullTag;
13340
13494
  const compiled = transpileAndRewriteLocalImports(rawScript, scriptTarget);
13341
- const isMod = /\btype\s*=\s*["']module["']/i.test(attrs) || /\.(?:tsx|ts|jsx|mjs)$/i.test(scriptTarget);
13495
+ const isMod = /\btype\s*=\s*["']module["']/i.test(attrs) || /\.(?:tsx|ts|jsx|mjs)$/i.test(scriptTarget) || /^\s*(?:import|export)\b/m.test(rawScript);
13342
13496
  const typeAttr = isMod ? ' type="module"' : '';
13343
13497
  return `<script${typeAttr} data-codelab-src="${srcMatch[1].replace(/"/g, '&quot;')}">\n${compiled}\n</script>`;
13344
13498
  });
13345
13499
 
13500
+ if (needsTailwindBrowser && !transformedHtml.includes('@tailwindcss/browser')) {
13501
+ const twTag = '<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>';
13502
+ if (/<head[^>]*>/i.test(transformedHtml)) {
13503
+ transformedHtml = transformedHtml.replace(/<head[^>]*>/i, (m) => `${m}\n ${twTag}`);
13504
+ } else {
13505
+ transformedHtml = twTag + '\n' + transformedHtml;
13506
+ }
13507
+ }
13508
+
13346
13509
  return injectPreviewExtras(transformedHtml, importMap);
13347
13510
  };
13348
13511
 
@@ -13354,7 +13517,9 @@ if (typeof module !== 'undefined' && module.exports) {
13354
13517
  const hasExt = /\.[A-Za-z0-9]+$/.test(rel);
13355
13518
 
13356
13519
  if (!rel || pathname.endsWith('/') || isDir(target)) {
13357
- target = PosixPath.join(target, 'index.html');
13520
+ const rootIdx = PosixPath.join(target, 'index.html');
13521
+ const pubIdx = PosixPath.join(target, 'public', 'index.html');
13522
+ target = (!exists(rootIdx) && exists(pubIdx)) ? pubIdx : rootIdx;
13358
13523
  }
13359
13524
  if (!exists(target) && !hasExt) {
13360
13525
  // Resolve extensionless module specifiers (e.g. `./components/Counter`)
@@ -13368,7 +13533,9 @@ if (typeof module !== 'undefined' && module.exports) {
13368
13533
  for (const c of cands) { if (exists(c)) { target = c; break; } }
13369
13534
  }
13370
13535
  if (!exists(target) && !hasExt) {
13371
- target = PosixPath.join(rootDir, 'index.html'); // SPA fallback
13536
+ const rootIdx = PosixPath.join(rootDir, 'index.html');
13537
+ const pubIdx = PosixPath.join(rootDir, 'public', 'index.html');
13538
+ target = (!exists(rootIdx) && exists(pubIdx)) ? pubIdx : rootIdx; // SPA fallback
13372
13539
  }
13373
13540
  if (!exists(target)) {
13374
13541
  return new Response(
@@ -18746,7 +18913,7 @@ if (typeof module !== 'undefined' && module.exports) {
18746
18913
 
18747
18914
  // The bundler rewrites this literal from package.json at build time. Keeping
18748
18915
  // the fallback in sync lets tests require src/workbench.js directly.
18749
- const CODELAB_VERSION = '0.1.9';
18916
+ const CODELAB_VERSION = '0.1.11';
18750
18917
 
18751
18918
  // Ambient TypeScript declarations for Node.js built-ins inside Monaco
18752
18919
  const NODE_AMBIENT_DTS = `
@@ -20053,6 +20220,11 @@ declare module 'bun:sqlite' {
20053
20220
  this.explorerWidth = (typeof this.savedState?.explorerWidth === 'number' && this.savedState.explorerWidth >= 120)
20054
20221
  ? this.savedState.explorerWidth
20055
20222
  : 196;
20223
+ // 0 = use the default 44% track; otherwise a pixel width chosen by dragging
20224
+ // the preview splitter.
20225
+ this.previewSplitWidth = (typeof this.savedState?.previewSplitWidth === 'number' && this.savedState.previewSplitWidth >= 200)
20226
+ ? this.savedState.previewSplitWidth
20227
+ : 0;
20056
20228
  this.folderSwitcherOpen = false;
20057
20229
  this.creatingItem = null; // { type: 'file' | 'folder', parentFolder: string } | null
20058
20230
  this.renamingItem = null;
@@ -20445,7 +20617,8 @@ declare module 'bun:sqlite' {
20445
20617
  folders: Array.from(this.folders || []),
20446
20618
  collapsedFolders: Array.from(this.collapsedFolders || []),
20447
20619
  explorerFolder: this.explorerFolder || '',
20448
- explorerWidth: typeof this.explorerWidth === 'number' ? this.explorerWidth : undefined
20620
+ explorerWidth: typeof this.explorerWidth === 'number' ? this.explorerWidth : undefined,
20621
+ previewSplitWidth: this.previewSplitWidth || undefined
20449
20622
  };
20450
20623
  this.savedState = state;
20451
20624
  if (this.options && this.options.persistState === false) {
@@ -20671,7 +20844,12 @@ declare module 'bun:sqlite' {
20671
20844
  const found = names.find(f => pattern.test(f));
20672
20845
  if (found) return found;
20673
20846
  if (kind === 'demo') {
20674
- return names.find(f => /\.(js|ts)$/i.test(f) && !/(^|\/)test\.(js|ts)$/i.test(f)) || null;
20847
+ const isConfigOrTest = f => /(^|\/)(test|.*\.(?:test|spec|config|d))\.(js|ts|mjs|cjs)$/i.test(f) || /(^|\/)\.[^/]+$/i.test(f);
20848
+ const hasHtmlEntry = Boolean(this.files['index.html'] || this.files['public/index.html']);
20849
+ if (hasHtmlEntry) {
20850
+ return names.find(f => /(^|\/)(server|app|demo)\.(js|ts)$/i.test(f) && !/^src\//i.test(f)) || null;
20851
+ }
20852
+ return names.find(f => /\.(js|ts)$/i.test(f) && !isConfigOrTest(f)) || null;
20675
20853
  }
20676
20854
  return null;
20677
20855
  }
@@ -20707,7 +20885,9 @@ declare module 'bun:sqlite' {
20707
20885
  const themeAttr = this.themeOption !== 'auto' ? `data-theme="${escapeHtml(this.themeOption)}"` : '';
20708
20886
  const brandLabel = (this.title && this.title !== 'custom-lab' && this.title !== this.labId) ? this.title : 'code-lab';
20709
20887
  const isGuideCollapsed = !this.hasGuidedLab || this.mode === 'sandbox' || !this.steps.length;
20710
- const explorerStyle = `style="--cl-explorer-width:${Math.round(this.explorerWidth || 196)}px"`;
20888
+ const shellVars = [`--cl-explorer-width:${Math.round(this.explorerWidth || 196)}px`];
20889
+ if (this.previewSplitWidth) shellVars.push(`--cl-preview-split-width:${Math.round(this.previewSplitWidth)}px`);
20890
+ const explorerStyle = `style="${shellVars.join(';')}"`;
20711
20891
  this.container.innerHTML = `
20712
20892
  <div class="codelab codelab-workbench ${isGuideCollapsed ? 'guide-collapsed' : ''}" id="codelab-${escapeHtml(this.labId)}" ${themeAttr} ${explorerStyle}>
20713
20893
  <!-- Top Bar -->
@@ -22102,6 +22282,7 @@ declare module 'bun:sqlite' {
22102
22282
  }
22103
22283
 
22104
22284
  if (this.drawerTab === 'preview') {
22285
+ bodyEl.scrollTop = 0;
22105
22286
  this._renderWebPreview(bodyEl);
22106
22287
  return;
22107
22288
  }
@@ -23401,8 +23582,10 @@ declare module 'bun:sqlite' {
23401
23582
  return null;
23402
23583
  }
23403
23584
 
23404
- const rootDir = (this.files['public/index.html']) ? '/workspace/public'
23405
- : (this.files['site/index.html']) ? '/workspace/site'
23585
+ const hasSrcScripts = Boolean(this.files && Object.keys(this.files).some((f) => /^src\/.+\.(?:[cm]?jsx?|tsx?)$/i.test(f)));
23586
+ const rootDir = this.files['index.html'] ? '/workspace'
23587
+ : (this.files['public/index.html'] && !hasSrcScripts) ? '/workspace/public'
23588
+ : this.files['site/index.html'] ? '/workspace/site'
23406
23589
  : '/workspace';
23407
23590
 
23408
23591
  if (!this.shell || typeof this.shell.execute !== 'function') return null;
@@ -23550,9 +23733,11 @@ declare module 'bun:sqlite' {
23550
23733
  _togglePreviewDock() {
23551
23734
  this.previewState.dockMode = this.previewState.dockMode === 'split' ? 'bottom' : 'split';
23552
23735
  this._previewRenderKey = null;
23736
+ const ws = this.container ? this.container.querySelector('.codelab-workspace') : null;
23553
23737
  const splitHost = this.container ? this.container.querySelector('#cl-preview-split') : null;
23554
23738
  const splitBar = this.container ? this.container.querySelector('#cl-splitter-preview') : null;
23555
23739
  if (this.previewState.dockMode === 'split') {
23740
+ if (ws) ws.classList.add('has-preview-split');
23556
23741
  if (splitBar) splitBar.style.display = 'block';
23557
23742
  if (splitHost) {
23558
23743
  splitHost.style.display = 'flex';
@@ -23564,6 +23749,7 @@ declare module 'bun:sqlite' {
23564
23749
  this._renderDrawerBody();
23565
23750
  }
23566
23751
  } else {
23752
+ if (ws) ws.classList.remove('has-preview-split');
23567
23753
  if (splitBar) splitBar.style.display = 'none';
23568
23754
  if (splitHost) {
23569
23755
  splitHost.style.display = 'none';
@@ -23663,9 +23849,11 @@ declare module 'bun:sqlite' {
23663
23849
  this._warnPreviewIsolation();
23664
23850
  const splitHost = this.container ? this.container.querySelector('#cl-preview-split') : null;
23665
23851
  const splitBar = this.container ? this.container.querySelector('#cl-splitter-preview') : null;
23852
+ const ws = this.container ? this.container.querySelector('.codelab-workspace') : null;
23666
23853
 
23667
23854
  let targetHost = bodyEl;
23668
23855
  if (this.previewState.dockMode === 'split' && splitHost) {
23856
+ if (ws) ws.classList.add('has-preview-split');
23669
23857
  if (splitBar) splitBar.style.display = 'block';
23670
23858
  splitHost.style.display = 'flex';
23671
23859
  if (bodyEl !== splitHost) {
@@ -23678,6 +23866,7 @@ declare module 'bun:sqlite' {
23678
23866
  }
23679
23867
  targetHost = splitHost;
23680
23868
  } else {
23869
+ if (ws) ws.classList.remove('has-preview-split');
23681
23870
  if (splitBar) splitBar.style.display = 'none';
23682
23871
  if (splitHost && bodyEl !== splitHost) {
23683
23872
  splitHost.style.display = 'none';
@@ -25387,8 +25576,10 @@ declare module 'bun:sqlite' {
25387
25576
  const pSplitter = this.container.querySelector('#cl-splitter-preview');
25388
25577
  if (pSplitter) {
25389
25578
  pSplitter.addEventListener('dblclick', () => {
25390
- shell.style.setProperty('--cl-preview-split-width', '44%');
25579
+ this.previewSplitWidth = 0;
25580
+ shell.style.removeProperty('--cl-preview-split-width');
25391
25581
  if (this.editor && typeof this.editor.layout === 'function') this.editor.layout();
25582
+ this._saveState();
25392
25583
  });
25393
25584
 
25394
25585
  pSplitter.addEventListener('pointerdown', e => {
@@ -25403,6 +25594,7 @@ declare module 'bun:sqlite' {
25403
25594
  const minW = 240;
25404
25595
  const maxW = Math.max(minW, Math.floor(rect.width * 0.65));
25405
25596
  const nextW = Math.min(maxW, Math.max(minW, Math.round(rect.right - ev.clientX)));
25597
+ this.previewSplitWidth = nextW;
25406
25598
  shell.style.setProperty('--cl-preview-split-width', `${nextW}px`);
25407
25599
  if (this.editor && typeof this.editor.layout === 'function') this.editor.layout();
25408
25600
  };
@@ -25413,6 +25605,7 @@ declare module 'bun:sqlite' {
25413
25605
  try { pSplitter.releasePointerCapture(ev.pointerId); } catch (err) { this.logger.debug('releasePointerCapture failed.', err); }
25414
25606
  pSplitter.removeEventListener('pointermove', onMove);
25415
25607
  pSplitter.removeEventListener('pointerup', onUp);
25608
+ this._saveState();
25416
25609
  };
25417
25610
 
25418
25611
  pSplitter.addEventListener('pointermove', onMove);
@@ -25880,6 +26073,9 @@ declare module 'bun:sqlite' {
25880
26073
  if (this.isRunning) return;
25881
26074
  const entry = this._findEntryFile('demo');
25882
26075
  if (!entry) {
26076
+ if ((this.files['index.html'] || this.files['public/index.html']) && typeof this.previewApp === 'function') {
26077
+ return this.previewApp();
26078
+ }
25883
26079
  this.terminalLogs.push({ type: 'stderr', text: 'No demo.js / demo.ts file found in this workspace.' });
25884
26080
  this.drawerTab = 'terminal';
25885
26081
  this._renderDrawerBody();
@@ -26755,7 +26951,7 @@ declare module 'bun:sqlite' {
26755
26951
  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.
26756
26952
  </p>
26757
26953
  <div style="display:flex;gap:8px;">
26758
- <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;" />
26954
+ <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;" />
26759
26955
  <button type="button" class="codelab-btn codelab-btn--primary" data-cl-action="confirm-clone-repo">Clone Repo</button>
26760
26956
  </div>
26761
26957
  </div>
@@ -27230,7 +27426,7 @@ const PTYTerminalEngine = CodeLabTerminal ? CodeLabTerminal.PTYTerminalEngine :
27230
27426
  const mount = CodeLab ? CodeLab.mount : null;
27231
27427
  const create = CodeLab ? CodeLab.create : null;
27232
27428
  const unmount = CodeLab ? CodeLab.unmount : null;
27233
- const version = CodeLab ? CodeLab.version : '0.1.9';
27429
+ const version = CodeLab ? CodeLab.version : '0.1.11';
27234
27430
  const renderMarkdown = CodeLab ? CodeLab.renderMarkdown : null;
27235
27431
  const renderSimpleMarkdown = CodeLab ? CodeLab.renderSimpleMarkdown : null;
27236
27432
  const cloneRepo = CodeLab ? CodeLab.cloneRepo : null;