@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/ARCHITECTURE.md +1 -1
- package/README.md +1 -1
- package/dist/code-lab.css +28 -0
- package/dist/code-lab.d.ts +1 -1
- package/dist/code-lab.esm.js +165 -18
- package/dist/code-lab.js +164 -17
- package/dist/preview-sw.js +1 -1
- package/dist/runtime.esm.js +29 -4
- package/dist/runtime.js +29 -4
- package/dist/shell.esm.js +121 -9
- package/dist/shell.js +121 -9
- package/dist/terminal.esm.js +1 -1
- package/dist/terminal.js +1 -1
- package/package.json +1 -1
- package/src/code-lab.css +28 -0
- package/src/runtime.ts +28 -3
- package/src/shell.ts +120 -8
- package/src/workbench.ts +15 -5
package/dist/code-lab.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ============================================================
|
|
3
|
-
* @innovatorved/code-lab v0.1.
|
|
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
|
|
@@ -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
|
-
|
|
6157
|
-
|
|
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
|
|
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,35 @@ 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 (err) {
|
|
13298
|
+
_shellLogger.debug('Preview asset read skipped.', full, err);
|
|
13299
|
+
}
|
|
13300
|
+
}
|
|
13301
|
+
}
|
|
13302
|
+
};
|
|
13303
|
+
walk(rootDir, 0);
|
|
13304
|
+
return files;
|
|
13305
|
+
}
|
|
13306
|
+
|
|
13246
13307
|
function collectPreviewScripts(vfs, rootDir, maxFiles = 200) {
|
|
13247
13308
|
return collectPreviewScriptFiles(vfs, rootDir, maxFiles).map((f) => f.content);
|
|
13248
13309
|
}
|
|
@@ -13325,11 +13386,31 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
13325
13386
|
return out;
|
|
13326
13387
|
};
|
|
13327
13388
|
|
|
13389
|
+
const inlineLocalCssImports = (cssText, cssDir) => {
|
|
13390
|
+
if (!cssText) return '';
|
|
13391
|
+
return cssText.replace(/@import\s+(?:url\(\s*['"]?([^'")]+)['"]?\s*\)|['"]([^'"]+)['"])\s*;?/gi, (full, u1, u2) => {
|
|
13392
|
+
const spec = (u1 || u2 || '').trim();
|
|
13393
|
+
if (!spec || /^(?:https?:|data:|\/\/)/i.test(spec)) return full;
|
|
13394
|
+
if (spec === 'tailwindcss') return '';
|
|
13395
|
+
const subTarget = resolveLocalTarget(cssDir, spec);
|
|
13396
|
+
if (subTarget && /\.css$/i.test(subTarget)) {
|
|
13397
|
+
const subCss = readText(subTarget);
|
|
13398
|
+
if (subCss !== null) return subCss;
|
|
13399
|
+
}
|
|
13400
|
+
return '';
|
|
13401
|
+
});
|
|
13402
|
+
};
|
|
13403
|
+
|
|
13328
13404
|
const buildHtmlPreviewResponse = (htmlBody, htmlTargetPath) => {
|
|
13329
13405
|
const scriptFiles = collectPreviewScriptFiles(ctx.vfs, rootDir);
|
|
13406
|
+
const assetFiles = collectPreviewAssetFiles(ctx.vfs, rootDir);
|
|
13330
13407
|
const specifiers = new Set();
|
|
13408
|
+
const compiledScripts = [];
|
|
13331
13409
|
for (const f of scriptFiles) {
|
|
13332
13410
|
for (const s of extractBareSpecifiers(f.content)) specifiers.add(s);
|
|
13411
|
+
const compiled = transpileAndRewriteLocalImports(f.content, f.full);
|
|
13412
|
+
for (const s of extractBareSpecifiers(compiled)) specifiers.add(s);
|
|
13413
|
+
compiledScripts.push({ file: f, compiled });
|
|
13333
13414
|
}
|
|
13334
13415
|
// Also scan inline module scripts in HTML for bare specifiers
|
|
13335
13416
|
const inlineScriptRe = /<script\b[^>]*>([\s\S]*?)<\/script>/gi;
|
|
@@ -13343,14 +13424,53 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
13343
13424
|
const importMap = buildPreviewImportMap(ctx.vfs, rootDir, specifiers);
|
|
13344
13425
|
for (const f of scriptFiles) aliasPinnedCdnUrls(ctx.vfs, rootDir, f.content, importMap);
|
|
13345
13426
|
aliasPinnedCdnUrls(ctx.vfs, rootDir, htmlBody, importMap);
|
|
13346
|
-
for (const
|
|
13347
|
-
const
|
|
13348
|
-
const key = toLocalImportKey(f.full);
|
|
13427
|
+
for (const { file, compiled } of compiledScripts) {
|
|
13428
|
+
const key = toLocalImportKey(file.full);
|
|
13349
13429
|
importMap[key] = `data:text/javascript;charset=utf-8,${encodeURIComponent(compiled)}`;
|
|
13350
13430
|
}
|
|
13351
13431
|
|
|
13432
|
+
let needsTailwindBrowser = false;
|
|
13433
|
+
for (const af of assetFiles) {
|
|
13434
|
+
const key = toLocalImportKey(af.full);
|
|
13435
|
+
if (/\.css$/i.test(af.full)) {
|
|
13436
|
+
if (/@import\s+['"]tailwindcss['"]/i.test(af.content)) {
|
|
13437
|
+
needsTailwindBrowser = true;
|
|
13438
|
+
}
|
|
13439
|
+
const resolvedCss = inlineLocalCssImports(af.content, PosixPath.dirname(af.full));
|
|
13440
|
+
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;`;
|
|
13441
|
+
importMap[key] = `data:text/javascript;charset=utf-8,${encodeURIComponent(cssModuleJs)}`;
|
|
13442
|
+
} else if (/\.json$/i.test(af.full)) {
|
|
13443
|
+
const jsonModuleJs = `export default ${af.content.trim() || 'null'};`;
|
|
13444
|
+
importMap[key] = `data:text/javascript;charset=utf-8,${encodeURIComponent(jsonModuleJs)}`;
|
|
13445
|
+
} else if (/\.svg$/i.test(af.full)) {
|
|
13446
|
+
const svgDataUrl = `data:image/svg+xml;utf8,${encodeURIComponent(af.content)}`;
|
|
13447
|
+
const svgModuleJs = `export default ${JSON.stringify(svgDataUrl)};`;
|
|
13448
|
+
importMap[key] = `data:text/javascript;charset=utf-8,${encodeURIComponent(svgModuleJs)}`;
|
|
13449
|
+
}
|
|
13450
|
+
}
|
|
13451
|
+
|
|
13352
13452
|
const htmlDir = PosixPath.dirname(htmlTargetPath);
|
|
13353
|
-
let transformedHtml = htmlBody;
|
|
13453
|
+
let transformedHtml = htmlBody.replace(/%PUBLIC_URL%\//g, '/').replace(/%PUBLIC_URL%/g, '');
|
|
13454
|
+
|
|
13455
|
+
// Auto-inject entry script for Create React App / bundler templates where index.html omits <script src="...">
|
|
13456
|
+
const hasLocalScriptTag = /<script\b[^>]*\bsrc\s*=\s*["']([^"']+)["'][^>]*>/i.test(transformedHtml);
|
|
13457
|
+
if (!hasLocalScriptTag) {
|
|
13458
|
+
const defaultEntries = [
|
|
13459
|
+
'/src/main.tsx', '/src/main.jsx', '/src/main.ts', '/src/main.js',
|
|
13460
|
+
'/src/index.tsx', '/src/index.jsx', '/src/index.ts', '/src/index.js'
|
|
13461
|
+
];
|
|
13462
|
+
for (const cand of defaultEntries) {
|
|
13463
|
+
if (isFile(PosixPath.join(rootDir, cand.slice(1)))) {
|
|
13464
|
+
const entryTag = `<script type="module" src="${cand}"></script>`;
|
|
13465
|
+
if (/<\/body>/i.test(transformedHtml)) {
|
|
13466
|
+
transformedHtml = transformedHtml.replace(/<\/body>/i, ` ${entryTag}\n</body>`);
|
|
13467
|
+
} else {
|
|
13468
|
+
transformedHtml += `\n${entryTag}`;
|
|
13469
|
+
}
|
|
13470
|
+
break;
|
|
13471
|
+
}
|
|
13472
|
+
}
|
|
13473
|
+
}
|
|
13354
13474
|
|
|
13355
13475
|
// Inline local <link rel="stylesheet" href="..."> so styles work in opaque-origin / srcdoc frames
|
|
13356
13476
|
transformedHtml = transformedHtml.replace(/<link\b([^>]*?)>/gi, (fullTag, attrs) => {
|
|
@@ -13361,7 +13481,11 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
13361
13481
|
if (!cssTarget || !/\.css$/i.test(cssTarget)) return fullTag;
|
|
13362
13482
|
const cssContent = readText(cssTarget);
|
|
13363
13483
|
if (cssContent === null) return fullTag;
|
|
13364
|
-
|
|
13484
|
+
if (/@import\s+['"]tailwindcss['"]/i.test(cssContent)) {
|
|
13485
|
+
needsTailwindBrowser = true;
|
|
13486
|
+
}
|
|
13487
|
+
const resolvedCss = inlineLocalCssImports(cssContent, PosixPath.dirname(cssTarget));
|
|
13488
|
+
return `<style data-codelab-href="${hrefMatch[1].replace(/"/g, '"')}">\n${resolvedCss}\n</style>`;
|
|
13365
13489
|
});
|
|
13366
13490
|
|
|
13367
13491
|
// Inline local <script ... src="..."></script> so entry modules & scripts execute reliably in opaque-origin / srcdoc frames
|
|
@@ -13373,11 +13497,20 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
13373
13497
|
const rawScript = readText(scriptTarget);
|
|
13374
13498
|
if (rawScript === null) return fullTag;
|
|
13375
13499
|
const compiled = transpileAndRewriteLocalImports(rawScript, scriptTarget);
|
|
13376
|
-
const isMod = /\btype\s*=\s*["']module["']/i.test(attrs) || /\.(?:tsx|ts|jsx|mjs)$/i.test(scriptTarget);
|
|
13500
|
+
const isMod = /\btype\s*=\s*["']module["']/i.test(attrs) || /\.(?:tsx|ts|jsx|mjs)$/i.test(scriptTarget) || /^\s*(?:import|export)\b/m.test(rawScript);
|
|
13377
13501
|
const typeAttr = isMod ? ' type="module"' : '';
|
|
13378
13502
|
return `<script${typeAttr} data-codelab-src="${srcMatch[1].replace(/"/g, '"')}">\n${compiled}\n</script>`;
|
|
13379
13503
|
});
|
|
13380
13504
|
|
|
13505
|
+
if (needsTailwindBrowser && !transformedHtml.includes('@tailwindcss/browser')) {
|
|
13506
|
+
const twTag = '<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>';
|
|
13507
|
+
if (/<head[^>]*>/i.test(transformedHtml)) {
|
|
13508
|
+
transformedHtml = transformedHtml.replace(/<head[^>]*>/i, (m) => `${m}\n ${twTag}`);
|
|
13509
|
+
} else {
|
|
13510
|
+
transformedHtml = twTag + '\n' + transformedHtml;
|
|
13511
|
+
}
|
|
13512
|
+
}
|
|
13513
|
+
|
|
13381
13514
|
return injectPreviewExtras(transformedHtml, importMap);
|
|
13382
13515
|
};
|
|
13383
13516
|
|
|
@@ -13389,7 +13522,9 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
13389
13522
|
const hasExt = /\.[A-Za-z0-9]+$/.test(rel);
|
|
13390
13523
|
|
|
13391
13524
|
if (!rel || pathname.endsWith('/') || isDir(target)) {
|
|
13392
|
-
|
|
13525
|
+
const rootIdx = PosixPath.join(target, 'index.html');
|
|
13526
|
+
const pubIdx = PosixPath.join(target, 'public', 'index.html');
|
|
13527
|
+
target = (!exists(rootIdx) && exists(pubIdx)) ? pubIdx : rootIdx;
|
|
13393
13528
|
}
|
|
13394
13529
|
if (!exists(target) && !hasExt) {
|
|
13395
13530
|
// Resolve extensionless module specifiers (e.g. `./components/Counter`)
|
|
@@ -13403,7 +13538,9 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
13403
13538
|
for (const c of cands) { if (exists(c)) { target = c; break; } }
|
|
13404
13539
|
}
|
|
13405
13540
|
if (!exists(target) && !hasExt) {
|
|
13406
|
-
|
|
13541
|
+
const rootIdx = PosixPath.join(rootDir, 'index.html');
|
|
13542
|
+
const pubIdx = PosixPath.join(rootDir, 'public', 'index.html');
|
|
13543
|
+
target = (!exists(rootIdx) && exists(pubIdx)) ? pubIdx : rootIdx; // SPA fallback
|
|
13407
13544
|
}
|
|
13408
13545
|
if (!exists(target)) {
|
|
13409
13546
|
return new Response(
|
|
@@ -18785,7 +18922,7 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
18785
18922
|
|
|
18786
18923
|
// The bundler rewrites this literal from package.json at build time. Keeping
|
|
18787
18924
|
// the fallback in sync lets tests require src/workbench.js directly.
|
|
18788
|
-
const CODELAB_VERSION = '0.1.
|
|
18925
|
+
const CODELAB_VERSION = '0.1.12';
|
|
18789
18926
|
|
|
18790
18927
|
// Ambient TypeScript declarations for Node.js built-ins inside Monaco
|
|
18791
18928
|
const NODE_AMBIENT_DTS = `
|
|
@@ -20716,7 +20853,12 @@ declare module 'bun:sqlite' {
|
|
|
20716
20853
|
const found = names.find(f => pattern.test(f));
|
|
20717
20854
|
if (found) return found;
|
|
20718
20855
|
if (kind === 'demo') {
|
|
20719
|
-
|
|
20856
|
+
const isConfigOrTest = f => /(^|\/)(test|.*\.(?:test|spec|config|d))\.(js|ts|mjs|cjs)$/i.test(f) || /(^|\/)\.[^/]+$/i.test(f);
|
|
20857
|
+
const hasHtmlEntry = Boolean(this.files['index.html'] || this.files['public/index.html']);
|
|
20858
|
+
if (hasHtmlEntry) {
|
|
20859
|
+
return names.find(f => /(^|\/)(server|app|demo)\.(js|ts)$/i.test(f) && !/^src\//i.test(f)) || null;
|
|
20860
|
+
}
|
|
20861
|
+
return names.find(f => /\.(js|ts)$/i.test(f) && !isConfigOrTest(f)) || null;
|
|
20720
20862
|
}
|
|
20721
20863
|
return null;
|
|
20722
20864
|
}
|
|
@@ -23449,8 +23591,10 @@ declare module 'bun:sqlite' {
|
|
|
23449
23591
|
return null;
|
|
23450
23592
|
}
|
|
23451
23593
|
|
|
23452
|
-
const
|
|
23453
|
-
|
|
23594
|
+
const hasSrcScripts = Boolean(this.files && Object.keys(this.files).some((f) => /^src\/.+\.(?:[cm]?jsx?|tsx?)$/i.test(f)));
|
|
23595
|
+
const rootDir = this.files['index.html'] ? '/workspace'
|
|
23596
|
+
: (this.files['public/index.html'] && !hasSrcScripts) ? '/workspace/public'
|
|
23597
|
+
: this.files['site/index.html'] ? '/workspace/site'
|
|
23454
23598
|
: '/workspace';
|
|
23455
23599
|
|
|
23456
23600
|
if (!this.shell || typeof this.shell.execute !== 'function') return null;
|
|
@@ -25938,6 +26082,9 @@ declare module 'bun:sqlite' {
|
|
|
25938
26082
|
if (this.isRunning) return;
|
|
25939
26083
|
const entry = this._findEntryFile('demo');
|
|
25940
26084
|
if (!entry) {
|
|
26085
|
+
if ((this.files['index.html'] || this.files['public/index.html']) && typeof this.previewApp === 'function') {
|
|
26086
|
+
return this.previewApp();
|
|
26087
|
+
}
|
|
25941
26088
|
this.terminalLogs.push({ type: 'stderr', text: 'No demo.js / demo.ts file found in this workspace.' });
|
|
25942
26089
|
this.drawerTab = 'terminal';
|
|
25943
26090
|
this._renderDrawerBody();
|
|
@@ -26813,7 +26960,7 @@ declare module 'bun:sqlite' {
|
|
|
26813
26960
|
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
26961
|
</p>
|
|
26815
26962
|
<div style="display:flex;gap:8px;">
|
|
26816
|
-
<input id="cl-clone-repo-input" type="text" placeholder="e.g.
|
|
26963
|
+
<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
26964
|
<button type="button" class="codelab-btn codelab-btn--primary" data-cl-action="confirm-clone-repo">Clone Repo</button>
|
|
26818
26965
|
</div>
|
|
26819
26966
|
</div>
|
package/dist/preview-sw.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ============================================================
|
|
3
|
-
* @innovatorved/code-lab v0.1.
|
|
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/runtime.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ============================================================
|
|
3
|
-
* @innovatorved/code-lab v0.1.
|
|
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
|
|
@@ -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
|
-
|
|
4391
|
-
|
|
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
|
|
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.
|
|
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
|
|
@@ -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
|
-
|
|
4392
|
-
|
|
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
|
|
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
|
|