@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.
- package/ARCHITECTURE.md +1 -1
- package/README.md +1 -1
- package/dist/code-lab.css +87 -15
- package/dist/code-lab.d.ts +1 -1
- package/dist/code-lab.esm.js +218 -22
- package/dist/code-lab.js +217 -21
- package/dist/index.d.ts +1 -1
- package/dist/preview-sw.js +2 -2
- package/dist/runtime.esm.js +29 -4
- package/dist/runtime.js +29 -4
- package/dist/schemas.d.ts +1 -1
- package/dist/shell.esm.js +151 -9
- package/dist/shell.js +151 -9
- package/dist/terminal.esm.js +1 -1
- package/dist/terminal.js +1 -1
- package/package.json +1 -1
- package/src/code-lab.css +87 -15
- package/src/csp.ts +6 -1
- package/src/index.ts +1 -1
- package/src/runtime.ts +28 -3
- package/src/schemas.ts +1 -1
- package/src/shell.ts +150 -8
- package/src/workbench.ts +37 -8
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.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
|
|
@@ -147,7 +147,7 @@ var CodeLabCsp = (() => {
|
|
|
147
147
|
const host = normalizeOrigin(options.hostOrigin);
|
|
148
148
|
const self = host || "'self'";
|
|
149
149
|
const directive = (name, parts) => `${name} ${unique(parts).join(" ")}`;
|
|
150
|
-
const script = () => [self, "blob:", "'unsafe-inline'", "'unsafe-eval'"].concat(sourcesFor(mode, allow, "scriptSrc"));
|
|
150
|
+
const script = () => [self, "data:", "blob:", "'unsafe-inline'", "'unsafe-eval'"].concat(sourcesFor(mode, allow, "scriptSrc"));
|
|
151
151
|
const style = () => [self, "'unsafe-inline'"].concat(sourcesFor(mode, allow, "styleSrc"));
|
|
152
152
|
const withData = (key) => [self, "data:", "blob:"].concat(sourcesFor(mode, allow, key));
|
|
153
153
|
return [
|
|
@@ -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,11 +13204,48 @@ 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;
|
|
13185
13216
|
}
|
|
13186
13217
|
|
|
13218
|
+
// Some templates pin a CDN URL in the source instead of importing a bare
|
|
13219
|
+
// specifier, e.g. `import React from "https://cdn.jsdelivr.net/npm/react@19.3.1/+esm"`.
|
|
13220
|
+
// Those URL specifiers are resolved by the browser directly, so they bypass the
|
|
13221
|
+
// generated import map (and with it the project's declared version and the
|
|
13222
|
+
// multi-CDN fallback). Import maps can remap URL specifiers, so alias each
|
|
13223
|
+
// literal URL found in the project to the resolved bare-specifier URL.
|
|
13224
|
+
// The pinned version is kept when the project has no dependency to resolve.
|
|
13225
|
+
const PINNED_CDN_URL_RE = /https?:\/\/(?:cdn\.jsdelivr\.net\/npm|esm\.sh)\/((?:@[^\/'"`@\s]+\/)?[^\/'"`@\s]+)@([^\s'"`),;]+)/g;
|
|
13226
|
+
|
|
13227
|
+
function aliasPinnedCdnUrls(vfs, rootDir, text, importMap) {
|
|
13228
|
+
if (!text || typeof text !== 'string') return;
|
|
13229
|
+
const re = new RegExp(PINNED_CDN_URL_RE.source, 'g');
|
|
13230
|
+
let match;
|
|
13231
|
+
while ((match = re.exec(text)) !== null) {
|
|
13232
|
+
const url = match[0];
|
|
13233
|
+
if (url.includes('${')) continue;
|
|
13234
|
+
const pkgName = decodeURIComponent(match[1]);
|
|
13235
|
+
const rest = match[2];
|
|
13236
|
+
const pinnedVersion = rest.split(/[\/?]/)[0];
|
|
13237
|
+
const tail = rest.slice(pinnedVersion.length);
|
|
13238
|
+
const rawSubpath = tail.startsWith('/') && tail !== '/+esm' ? tail.slice(1).split(/[?#]/)[0] : '';
|
|
13239
|
+
const subpath = rawSubpath.replace(/^\/+|\/+$/g, '');
|
|
13240
|
+
const bare = subpath ? `${pkgName}/${subpath}` : pkgName;
|
|
13241
|
+
|
|
13242
|
+
const declared = resolveBareVersion(vfs, rootDir, pkgName);
|
|
13243
|
+
const version = declared && declared !== 'latest' ? declared : decodeURIComponent(pinnedVersion);
|
|
13244
|
+
const target = importMap[bare] || cdnEsmUrl(pkgName, version, subpath || undefined);
|
|
13245
|
+
if (target && target !== url) importMap[url] = target;
|
|
13246
|
+
}
|
|
13247
|
+
}
|
|
13248
|
+
|
|
13187
13249
|
function collectPreviewScriptFiles(vfs, rootDir, maxFiles = 200) {
|
|
13188
13250
|
const files = [];
|
|
13189
13251
|
const walk = (dir, depth) => {
|
|
@@ -13213,6 +13275,33 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
13213
13275
|
return files;
|
|
13214
13276
|
}
|
|
13215
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
|
+
|
|
13216
13305
|
function collectPreviewScripts(vfs, rootDir, maxFiles = 200) {
|
|
13217
13306
|
return collectPreviewScriptFiles(vfs, rootDir, maxFiles).map((f) => f.content);
|
|
13218
13307
|
}
|
|
@@ -13295,11 +13384,31 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
13295
13384
|
return out;
|
|
13296
13385
|
};
|
|
13297
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
|
+
|
|
13298
13402
|
const buildHtmlPreviewResponse = (htmlBody, htmlTargetPath) => {
|
|
13299
13403
|
const scriptFiles = collectPreviewScriptFiles(ctx.vfs, rootDir);
|
|
13404
|
+
const assetFiles = collectPreviewAssetFiles(ctx.vfs, rootDir);
|
|
13300
13405
|
const specifiers = new Set();
|
|
13406
|
+
const compiledScripts = [];
|
|
13301
13407
|
for (const f of scriptFiles) {
|
|
13302
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 });
|
|
13303
13412
|
}
|
|
13304
13413
|
// Also scan inline module scripts in HTML for bare specifiers
|
|
13305
13414
|
const inlineScriptRe = /<script\b[^>]*>([\s\S]*?)<\/script>/gi;
|
|
@@ -13311,14 +13420,55 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
13311
13420
|
}
|
|
13312
13421
|
|
|
13313
13422
|
const importMap = buildPreviewImportMap(ctx.vfs, rootDir, specifiers);
|
|
13314
|
-
for (const f of scriptFiles)
|
|
13315
|
-
|
|
13316
|
-
|
|
13423
|
+
for (const f of scriptFiles) aliasPinnedCdnUrls(ctx.vfs, rootDir, f.content, importMap);
|
|
13424
|
+
aliasPinnedCdnUrls(ctx.vfs, rootDir, htmlBody, importMap);
|
|
13425
|
+
for (const { file, compiled } of compiledScripts) {
|
|
13426
|
+
const key = toLocalImportKey(file.full);
|
|
13317
13427
|
importMap[key] = `data:text/javascript;charset=utf-8,${encodeURIComponent(compiled)}`;
|
|
13318
13428
|
}
|
|
13319
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
|
+
|
|
13320
13450
|
const htmlDir = PosixPath.dirname(htmlTargetPath);
|
|
13321
|
-
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
|
+
}
|
|
13322
13472
|
|
|
13323
13473
|
// Inline local <link rel="stylesheet" href="..."> so styles work in opaque-origin / srcdoc frames
|
|
13324
13474
|
transformedHtml = transformedHtml.replace(/<link\b([^>]*?)>/gi, (fullTag, attrs) => {
|
|
@@ -13329,7 +13479,11 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
13329
13479
|
if (!cssTarget || !/\.css$/i.test(cssTarget)) return fullTag;
|
|
13330
13480
|
const cssContent = readText(cssTarget);
|
|
13331
13481
|
if (cssContent === null) return fullTag;
|
|
13332
|
-
|
|
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, '"')}">\n${resolvedCss}\n</style>`;
|
|
13333
13487
|
});
|
|
13334
13488
|
|
|
13335
13489
|
// Inline local <script ... src="..."></script> so entry modules & scripts execute reliably in opaque-origin / srcdoc frames
|
|
@@ -13341,11 +13495,20 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
13341
13495
|
const rawScript = readText(scriptTarget);
|
|
13342
13496
|
if (rawScript === null) return fullTag;
|
|
13343
13497
|
const compiled = transpileAndRewriteLocalImports(rawScript, scriptTarget);
|
|
13344
|
-
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);
|
|
13345
13499
|
const typeAttr = isMod ? ' type="module"' : '';
|
|
13346
13500
|
return `<script${typeAttr} data-codelab-src="${srcMatch[1].replace(/"/g, '"')}">\n${compiled}\n</script>`;
|
|
13347
13501
|
});
|
|
13348
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
|
+
|
|
13349
13512
|
return injectPreviewExtras(transformedHtml, importMap);
|
|
13350
13513
|
};
|
|
13351
13514
|
|
|
@@ -13357,7 +13520,9 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
13357
13520
|
const hasExt = /\.[A-Za-z0-9]+$/.test(rel);
|
|
13358
13521
|
|
|
13359
13522
|
if (!rel || pathname.endsWith('/') || isDir(target)) {
|
|
13360
|
-
|
|
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;
|
|
13361
13526
|
}
|
|
13362
13527
|
if (!exists(target) && !hasExt) {
|
|
13363
13528
|
// Resolve extensionless module specifiers (e.g. `./components/Counter`)
|
|
@@ -13371,7 +13536,9 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
13371
13536
|
for (const c of cands) { if (exists(c)) { target = c; break; } }
|
|
13372
13537
|
}
|
|
13373
13538
|
if (!exists(target) && !hasExt) {
|
|
13374
|
-
|
|
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
|
|
13375
13542
|
}
|
|
13376
13543
|
if (!exists(target)) {
|
|
13377
13544
|
return new Response(
|
|
@@ -18753,7 +18920,7 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
18753
18920
|
|
|
18754
18921
|
// The bundler rewrites this literal from package.json at build time. Keeping
|
|
18755
18922
|
// the fallback in sync lets tests require src/workbench.js directly.
|
|
18756
|
-
const CODELAB_VERSION = '0.1.
|
|
18923
|
+
const CODELAB_VERSION = '0.1.11';
|
|
18757
18924
|
|
|
18758
18925
|
// Ambient TypeScript declarations for Node.js built-ins inside Monaco
|
|
18759
18926
|
const NODE_AMBIENT_DTS = `
|
|
@@ -20060,6 +20227,11 @@ declare module 'bun:sqlite' {
|
|
|
20060
20227
|
this.explorerWidth = (typeof this.savedState?.explorerWidth === 'number' && this.savedState.explorerWidth >= 120)
|
|
20061
20228
|
? this.savedState.explorerWidth
|
|
20062
20229
|
: 196;
|
|
20230
|
+
// 0 = use the default 44% track; otherwise a pixel width chosen by dragging
|
|
20231
|
+
// the preview splitter.
|
|
20232
|
+
this.previewSplitWidth = (typeof this.savedState?.previewSplitWidth === 'number' && this.savedState.previewSplitWidth >= 200)
|
|
20233
|
+
? this.savedState.previewSplitWidth
|
|
20234
|
+
: 0;
|
|
20063
20235
|
this.folderSwitcherOpen = false;
|
|
20064
20236
|
this.creatingItem = null; // { type: 'file' | 'folder', parentFolder: string } | null
|
|
20065
20237
|
this.renamingItem = null;
|
|
@@ -20452,7 +20624,8 @@ declare module 'bun:sqlite' {
|
|
|
20452
20624
|
folders: Array.from(this.folders || []),
|
|
20453
20625
|
collapsedFolders: Array.from(this.collapsedFolders || []),
|
|
20454
20626
|
explorerFolder: this.explorerFolder || '',
|
|
20455
|
-
explorerWidth: typeof this.explorerWidth === 'number' ? this.explorerWidth : undefined
|
|
20627
|
+
explorerWidth: typeof this.explorerWidth === 'number' ? this.explorerWidth : undefined,
|
|
20628
|
+
previewSplitWidth: this.previewSplitWidth || undefined
|
|
20456
20629
|
};
|
|
20457
20630
|
this.savedState = state;
|
|
20458
20631
|
if (this.options && this.options.persistState === false) {
|
|
@@ -20678,7 +20851,12 @@ declare module 'bun:sqlite' {
|
|
|
20678
20851
|
const found = names.find(f => pattern.test(f));
|
|
20679
20852
|
if (found) return found;
|
|
20680
20853
|
if (kind === 'demo') {
|
|
20681
|
-
|
|
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;
|
|
20682
20860
|
}
|
|
20683
20861
|
return null;
|
|
20684
20862
|
}
|
|
@@ -20714,7 +20892,9 @@ declare module 'bun:sqlite' {
|
|
|
20714
20892
|
const themeAttr = this.themeOption !== 'auto' ? `data-theme="${escapeHtml(this.themeOption)}"` : '';
|
|
20715
20893
|
const brandLabel = (this.title && this.title !== 'custom-lab' && this.title !== this.labId) ? this.title : 'code-lab';
|
|
20716
20894
|
const isGuideCollapsed = !this.hasGuidedLab || this.mode === 'sandbox' || !this.steps.length;
|
|
20717
|
-
const
|
|
20895
|
+
const shellVars = [`--cl-explorer-width:${Math.round(this.explorerWidth || 196)}px`];
|
|
20896
|
+
if (this.previewSplitWidth) shellVars.push(`--cl-preview-split-width:${Math.round(this.previewSplitWidth)}px`);
|
|
20897
|
+
const explorerStyle = `style="${shellVars.join(';')}"`;
|
|
20718
20898
|
this.container.innerHTML = `
|
|
20719
20899
|
<div class="codelab codelab-workbench ${isGuideCollapsed ? 'guide-collapsed' : ''}" id="codelab-${escapeHtml(this.labId)}" ${themeAttr} ${explorerStyle}>
|
|
20720
20900
|
<!-- Top Bar -->
|
|
@@ -22109,6 +22289,7 @@ declare module 'bun:sqlite' {
|
|
|
22109
22289
|
}
|
|
22110
22290
|
|
|
22111
22291
|
if (this.drawerTab === 'preview') {
|
|
22292
|
+
bodyEl.scrollTop = 0;
|
|
22112
22293
|
this._renderWebPreview(bodyEl);
|
|
22113
22294
|
return;
|
|
22114
22295
|
}
|
|
@@ -23408,8 +23589,10 @@ declare module 'bun:sqlite' {
|
|
|
23408
23589
|
return null;
|
|
23409
23590
|
}
|
|
23410
23591
|
|
|
23411
|
-
const
|
|
23412
|
-
|
|
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'
|
|
23413
23596
|
: '/workspace';
|
|
23414
23597
|
|
|
23415
23598
|
if (!this.shell || typeof this.shell.execute !== 'function') return null;
|
|
@@ -23557,9 +23740,11 @@ declare module 'bun:sqlite' {
|
|
|
23557
23740
|
_togglePreviewDock() {
|
|
23558
23741
|
this.previewState.dockMode = this.previewState.dockMode === 'split' ? 'bottom' : 'split';
|
|
23559
23742
|
this._previewRenderKey = null;
|
|
23743
|
+
const ws = this.container ? this.container.querySelector('.codelab-workspace') : null;
|
|
23560
23744
|
const splitHost = this.container ? this.container.querySelector('#cl-preview-split') : null;
|
|
23561
23745
|
const splitBar = this.container ? this.container.querySelector('#cl-splitter-preview') : null;
|
|
23562
23746
|
if (this.previewState.dockMode === 'split') {
|
|
23747
|
+
if (ws) ws.classList.add('has-preview-split');
|
|
23563
23748
|
if (splitBar) splitBar.style.display = 'block';
|
|
23564
23749
|
if (splitHost) {
|
|
23565
23750
|
splitHost.style.display = 'flex';
|
|
@@ -23571,6 +23756,7 @@ declare module 'bun:sqlite' {
|
|
|
23571
23756
|
this._renderDrawerBody();
|
|
23572
23757
|
}
|
|
23573
23758
|
} else {
|
|
23759
|
+
if (ws) ws.classList.remove('has-preview-split');
|
|
23574
23760
|
if (splitBar) splitBar.style.display = 'none';
|
|
23575
23761
|
if (splitHost) {
|
|
23576
23762
|
splitHost.style.display = 'none';
|
|
@@ -23670,9 +23856,11 @@ declare module 'bun:sqlite' {
|
|
|
23670
23856
|
this._warnPreviewIsolation();
|
|
23671
23857
|
const splitHost = this.container ? this.container.querySelector('#cl-preview-split') : null;
|
|
23672
23858
|
const splitBar = this.container ? this.container.querySelector('#cl-splitter-preview') : null;
|
|
23859
|
+
const ws = this.container ? this.container.querySelector('.codelab-workspace') : null;
|
|
23673
23860
|
|
|
23674
23861
|
let targetHost = bodyEl;
|
|
23675
23862
|
if (this.previewState.dockMode === 'split' && splitHost) {
|
|
23863
|
+
if (ws) ws.classList.add('has-preview-split');
|
|
23676
23864
|
if (splitBar) splitBar.style.display = 'block';
|
|
23677
23865
|
splitHost.style.display = 'flex';
|
|
23678
23866
|
if (bodyEl !== splitHost) {
|
|
@@ -23685,6 +23873,7 @@ declare module 'bun:sqlite' {
|
|
|
23685
23873
|
}
|
|
23686
23874
|
targetHost = splitHost;
|
|
23687
23875
|
} else {
|
|
23876
|
+
if (ws) ws.classList.remove('has-preview-split');
|
|
23688
23877
|
if (splitBar) splitBar.style.display = 'none';
|
|
23689
23878
|
if (splitHost && bodyEl !== splitHost) {
|
|
23690
23879
|
splitHost.style.display = 'none';
|
|
@@ -25394,8 +25583,10 @@ declare module 'bun:sqlite' {
|
|
|
25394
25583
|
const pSplitter = this.container.querySelector('#cl-splitter-preview');
|
|
25395
25584
|
if (pSplitter) {
|
|
25396
25585
|
pSplitter.addEventListener('dblclick', () => {
|
|
25397
|
-
|
|
25586
|
+
this.previewSplitWidth = 0;
|
|
25587
|
+
shell.style.removeProperty('--cl-preview-split-width');
|
|
25398
25588
|
if (this.editor && typeof this.editor.layout === 'function') this.editor.layout();
|
|
25589
|
+
this._saveState();
|
|
25399
25590
|
});
|
|
25400
25591
|
|
|
25401
25592
|
pSplitter.addEventListener('pointerdown', e => {
|
|
@@ -25410,6 +25601,7 @@ declare module 'bun:sqlite' {
|
|
|
25410
25601
|
const minW = 240;
|
|
25411
25602
|
const maxW = Math.max(minW, Math.floor(rect.width * 0.65));
|
|
25412
25603
|
const nextW = Math.min(maxW, Math.max(minW, Math.round(rect.right - ev.clientX)));
|
|
25604
|
+
this.previewSplitWidth = nextW;
|
|
25413
25605
|
shell.style.setProperty('--cl-preview-split-width', `${nextW}px`);
|
|
25414
25606
|
if (this.editor && typeof this.editor.layout === 'function') this.editor.layout();
|
|
25415
25607
|
};
|
|
@@ -25420,6 +25612,7 @@ declare module 'bun:sqlite' {
|
|
|
25420
25612
|
try { pSplitter.releasePointerCapture(ev.pointerId); } catch (err) { this.logger.debug('releasePointerCapture failed.', err); }
|
|
25421
25613
|
pSplitter.removeEventListener('pointermove', onMove);
|
|
25422
25614
|
pSplitter.removeEventListener('pointerup', onUp);
|
|
25615
|
+
this._saveState();
|
|
25423
25616
|
};
|
|
25424
25617
|
|
|
25425
25618
|
pSplitter.addEventListener('pointermove', onMove);
|
|
@@ -25887,6 +26080,9 @@ declare module 'bun:sqlite' {
|
|
|
25887
26080
|
if (this.isRunning) return;
|
|
25888
26081
|
const entry = this._findEntryFile('demo');
|
|
25889
26082
|
if (!entry) {
|
|
26083
|
+
if ((this.files['index.html'] || this.files['public/index.html']) && typeof this.previewApp === 'function') {
|
|
26084
|
+
return this.previewApp();
|
|
26085
|
+
}
|
|
25890
26086
|
this.terminalLogs.push({ type: 'stderr', text: 'No demo.js / demo.ts file found in this workspace.' });
|
|
25891
26087
|
this.drawerTab = 'terminal';
|
|
25892
26088
|
this._renderDrawerBody();
|
|
@@ -26762,7 +26958,7 @@ declare module 'bun:sqlite' {
|
|
|
26762
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.
|
|
26763
26959
|
</p>
|
|
26764
26960
|
<div style="display:flex;gap:8px;">
|
|
26765
|
-
<input id="cl-clone-repo-input" type="text" placeholder="e.g.
|
|
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;" />
|
|
26766
26962
|
<button type="button" class="codelab-btn codelab-btn--primary" data-cl-action="confirm-clone-repo">Clone Repo</button>
|
|
26767
26963
|
</div>
|
|
26768
26964
|
</div>
|
package/dist/index.d.ts
CHANGED
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.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
|
|
@@ -144,7 +144,7 @@ var CodeLabCsp = (() => {
|
|
|
144
144
|
const host = normalizeOrigin(options.hostOrigin);
|
|
145
145
|
const self = host || "'self'";
|
|
146
146
|
const directive = (name, parts) => `${name} ${unique(parts).join(" ")}`;
|
|
147
|
-
const script = () => [self, "blob:", "'unsafe-inline'", "'unsafe-eval'"].concat(sourcesFor(mode, allow, "scriptSrc"));
|
|
147
|
+
const script = () => [self, "data:", "blob:", "'unsafe-inline'", "'unsafe-eval'"].concat(sourcesFor(mode, allow, "scriptSrc"));
|
|
148
148
|
const style = () => [self, "'unsafe-inline'"].concat(sourcesFor(mode, allow, "styleSrc"));
|
|
149
149
|
const withData = (key) => [self, "data:", "blob:"].concat(sourcesFor(mode, allow, key));
|
|
150
150
|
return [
|
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.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
|
-
|
|
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.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
|
-
|
|
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
|
|
package/dist/schemas.d.ts
CHANGED