mrmd-js 2.0.1 → 2.2.0
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/LICENSE +21 -0
- package/dist/index.cjs +140 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +139 -1
- package/dist/index.js.map +1 -1
- package/dist/mrmd-js.iife.js +140 -0
- package/dist/mrmd-js.iife.js.map +1 -1
- package/package.json +1 -1
- package/src/execute/index.js +3 -0
- package/src/execute/mermaid.js +137 -0
- package/src/index.js +3 -0
package/dist/index.js
CHANGED
|
@@ -6385,6 +6385,143 @@ function createCssExecutor() {
|
|
|
6385
6385
|
return new CssExecutor();
|
|
6386
6386
|
}
|
|
6387
6387
|
|
|
6388
|
+
/**
|
|
6389
|
+
* Mermaid Executor
|
|
6390
|
+
*
|
|
6391
|
+
* Executes Mermaid diagram cells by rendering them to SVG.
|
|
6392
|
+
* Loads mermaid from CDN on first use and returns HTML displayData.
|
|
6393
|
+
*
|
|
6394
|
+
* @module execute/mermaid
|
|
6395
|
+
*/
|
|
6396
|
+
|
|
6397
|
+
|
|
6398
|
+
/**
|
|
6399
|
+
* @typedef {import('../session/context/interface.js').ExecutionContext} ExecutionContext
|
|
6400
|
+
* @typedef {import('../types/execution.js').ExecuteOptions} ExecuteOptions
|
|
6401
|
+
* @typedef {import('../types/execution.js').ExecutionResult} ExecutionResult
|
|
6402
|
+
* @typedef {import('../types/execution.js').DisplayData} DisplayData
|
|
6403
|
+
*/
|
|
6404
|
+
|
|
6405
|
+
/** CDN URL for mermaid */
|
|
6406
|
+
const MERMAID_CDN = 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.min.js';
|
|
6407
|
+
|
|
6408
|
+
/** Counter for unique diagram IDs */
|
|
6409
|
+
let diagramCounter = 0;
|
|
6410
|
+
|
|
6411
|
+
/**
|
|
6412
|
+
* Load mermaid from CDN if not already loaded
|
|
6413
|
+
* @returns {Promise<void>}
|
|
6414
|
+
*/
|
|
6415
|
+
async function ensureMermaidLoaded() {
|
|
6416
|
+
// Check if already loaded
|
|
6417
|
+
if (typeof window !== 'undefined' && window.mermaid) {
|
|
6418
|
+
return;
|
|
6419
|
+
}
|
|
6420
|
+
|
|
6421
|
+
// Load from CDN
|
|
6422
|
+
return new Promise((resolve, reject) => {
|
|
6423
|
+
const script = document.createElement('script');
|
|
6424
|
+
script.src = MERMAID_CDN;
|
|
6425
|
+
script.onload = () => {
|
|
6426
|
+
// Initialize mermaid with safe defaults
|
|
6427
|
+
window.mermaid.initialize({
|
|
6428
|
+
startOnLoad: false,
|
|
6429
|
+
theme: 'default',
|
|
6430
|
+
securityLevel: 'loose', // Allow clicks/links in diagrams
|
|
6431
|
+
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
|
|
6432
|
+
});
|
|
6433
|
+
resolve();
|
|
6434
|
+
};
|
|
6435
|
+
script.onerror = () => reject(new Error('Failed to load mermaid from CDN'));
|
|
6436
|
+
document.head.appendChild(script);
|
|
6437
|
+
});
|
|
6438
|
+
}
|
|
6439
|
+
|
|
6440
|
+
/**
|
|
6441
|
+
* Mermaid executor - renders Mermaid diagrams to SVG
|
|
6442
|
+
*/
|
|
6443
|
+
class MermaidExecutor extends BaseExecutor {
|
|
6444
|
+
/** @type {readonly string[]} */
|
|
6445
|
+
languages = ['mermaid'];
|
|
6446
|
+
|
|
6447
|
+
/**
|
|
6448
|
+
* Execute Mermaid diagram cell
|
|
6449
|
+
* @param {string} code - Mermaid diagram definition
|
|
6450
|
+
* @param {ExecutionContext} context - Execution context
|
|
6451
|
+
* @param {ExecuteOptions} [options] - Execution options
|
|
6452
|
+
* @returns {Promise<ExecutionResult>}
|
|
6453
|
+
*/
|
|
6454
|
+
async execute(code, context, options = {}) {
|
|
6455
|
+
const startTime = performance.now();
|
|
6456
|
+
|
|
6457
|
+
try {
|
|
6458
|
+
// Ensure mermaid is loaded
|
|
6459
|
+
await ensureMermaidLoaded();
|
|
6460
|
+
|
|
6461
|
+
// Generate unique ID for this diagram
|
|
6462
|
+
const diagramId = `mermaid-diagram-${++diagramCounter}`;
|
|
6463
|
+
|
|
6464
|
+
// Render the diagram
|
|
6465
|
+
const { svg } = await window.mermaid.render(diagramId, code.trim());
|
|
6466
|
+
|
|
6467
|
+
const duration = performance.now() - startTime;
|
|
6468
|
+
|
|
6469
|
+
// Build display data with the rendered SVG
|
|
6470
|
+
/** @type {DisplayData[]} */
|
|
6471
|
+
const displayData = [
|
|
6472
|
+
{
|
|
6473
|
+
data: {
|
|
6474
|
+
'text/html': svg,
|
|
6475
|
+
'text/plain': `[Mermaid diagram rendered]`,
|
|
6476
|
+
},
|
|
6477
|
+
metadata: {
|
|
6478
|
+
mermaid: true,
|
|
6479
|
+
diagramId,
|
|
6480
|
+
},
|
|
6481
|
+
},
|
|
6482
|
+
];
|
|
6483
|
+
|
|
6484
|
+
return {
|
|
6485
|
+
success: true,
|
|
6486
|
+
stdout: '',
|
|
6487
|
+
stderr: '',
|
|
6488
|
+
result: undefined,
|
|
6489
|
+
displayData,
|
|
6490
|
+
assets: [],
|
|
6491
|
+
executionCount: 0,
|
|
6492
|
+
duration,
|
|
6493
|
+
};
|
|
6494
|
+
} catch (error) {
|
|
6495
|
+
const duration = performance.now() - startTime;
|
|
6496
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
6497
|
+
|
|
6498
|
+
// Return error as stderr with helpful message
|
|
6499
|
+
return {
|
|
6500
|
+
success: false,
|
|
6501
|
+
stdout: '',
|
|
6502
|
+
stderr: `Mermaid rendering error: ${errorMessage}`,
|
|
6503
|
+
result: undefined,
|
|
6504
|
+
error: {
|
|
6505
|
+
type: 'MermaidError',
|
|
6506
|
+
message: errorMessage,
|
|
6507
|
+
},
|
|
6508
|
+
displayData: [],
|
|
6509
|
+
assets: [],
|
|
6510
|
+
executionCount: 0,
|
|
6511
|
+
duration,
|
|
6512
|
+
};
|
|
6513
|
+
}
|
|
6514
|
+
}
|
|
6515
|
+
}
|
|
6516
|
+
|
|
6517
|
+
/**
|
|
6518
|
+
* Create a Mermaid executor
|
|
6519
|
+
* @returns {MermaidExecutor}
|
|
6520
|
+
*/
|
|
6521
|
+
function createMermaidExecutor() {
|
|
6522
|
+
return new MermaidExecutor();
|
|
6523
|
+
}
|
|
6524
|
+
|
|
6388
6525
|
/**
|
|
6389
6526
|
* Execute Module
|
|
6390
6527
|
*
|
|
@@ -6403,6 +6540,7 @@ function createDefaultExecutorRegistry() {
|
|
|
6403
6540
|
registry.register(new JavaScriptExecutor());
|
|
6404
6541
|
registry.register(new HtmlExecutor());
|
|
6405
6542
|
registry.register(new CssExecutor());
|
|
6543
|
+
registry.register(new MermaidExecutor());
|
|
6406
6544
|
return registry;
|
|
6407
6545
|
}
|
|
6408
6546
|
|
|
@@ -7715,5 +7853,5 @@ function createAnsiRenderer(options) {
|
|
|
7715
7853
|
return new AnsiRenderer(options);
|
|
7716
7854
|
}
|
|
7717
7855
|
|
|
7718
|
-
export { AnsiRenderer, BaseExecutor, ConsoleCapture, CssApplicator, CssExecutor, DEFAULT_FEATURES, DEFAULT_MAX_SESSIONS, DEFAULT_SESSION, ExecutorRegistry, HtmlExecutor, HtmlRenderer, IframeContext, JavaScriptExecutor, MainContext, MrpRuntime, RUNTIME_NAME, RUNTIME_VERSION, SUPPORTED_LANGUAGES, Session, SessionManager, ansiToHtml, basicFormat, createAnsiRenderer, createConsoleCapture, createCssApplicator, createCssExecutor, createDefaultExecutorRegistry, createExecutorRegistry, createHtmlExecutor, createHtmlRenderer, createIframeContext, createJavaScriptExecutor, createMainContext, createRuntime, createSession, createSessionManager, expandVariable, extractDeclaredVariables, extractScripts, extractStyles, formatCode, formatCss, formatHtml, formatValue, formatValueShort, formatVariableInfo, generateScopeClass, getAttributes, getChildren, getCommonGlobals, getCompletionKind, getCompletions, getFunctionSignature, getFunctionSource, getHoverInfo, getInspectInfo, getKeywords, getMethods, getSizeDescription, getStringOrCommentContext, getSuggestedIndent, getTypeName, getVariableDetail, getWordAtCursor, hasPrettier, inspectPath, isComplete, isExpandable, isIdentifierPart, isIdentifierStart, isKeyword, listVariables, parseCompletionContext, parseIdentifierAtPosition, scopeStyles$1 as scopeStyles, scopeStyles as scopeStylesUtil, setPrettier, splitObjectPath, stripAnsi, transformForPersistence, wrapForAsync, wrapWithLastExpression };
|
|
7856
|
+
export { AnsiRenderer, BaseExecutor, ConsoleCapture, CssApplicator, CssExecutor, DEFAULT_FEATURES, DEFAULT_MAX_SESSIONS, DEFAULT_SESSION, ExecutorRegistry, HtmlExecutor, HtmlRenderer, IframeContext, JavaScriptExecutor, MainContext, MermaidExecutor, MrpRuntime, RUNTIME_NAME, RUNTIME_VERSION, SUPPORTED_LANGUAGES, Session, SessionManager, ansiToHtml, basicFormat, createAnsiRenderer, createConsoleCapture, createCssApplicator, createCssExecutor, createDefaultExecutorRegistry, createExecutorRegistry, createHtmlExecutor, createHtmlRenderer, createIframeContext, createJavaScriptExecutor, createMainContext, createMermaidExecutor, createRuntime, createSession, createSessionManager, expandVariable, extractDeclaredVariables, extractScripts, extractStyles, formatCode, formatCss, formatHtml, formatValue, formatValueShort, formatVariableInfo, generateScopeClass, getAttributes, getChildren, getCommonGlobals, getCompletionKind, getCompletions, getFunctionSignature, getFunctionSource, getHoverInfo, getInspectInfo, getKeywords, getMethods, getSizeDescription, getStringOrCommentContext, getSuggestedIndent, getTypeName, getVariableDetail, getWordAtCursor, hasPrettier, inspectPath, isComplete, isExpandable, isIdentifierPart, isIdentifierStart, isKeyword, listVariables, parseCompletionContext, parseIdentifierAtPosition, scopeStyles$1 as scopeStyles, scopeStyles as scopeStylesUtil, setPrettier, splitObjectPath, stripAnsi, transformForPersistence, wrapForAsync, wrapWithLastExpression };
|
|
7719
7857
|
//# sourceMappingURL=index.js.map
|