<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Modality Language Parser - WASM Example</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
max-width: 1200px;
margin: 0 auto;
padding: 20px;
background-color: #f5f5f5;
}
.container {
background: white;
padding: 30px;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
h1 {
color: #333;
text-align: center;
margin-bottom: 30px;
}
.section {
margin-bottom: 30px;
}
label {
display: block;
margin-bottom: 10px;
font-weight: bold;
color: #555;
}
textarea {
width: 100%;
height: 200px;
padding: 10px;
border: 2px solid #ddd;
border-radius: 5px;
font-family: 'Courier New', monospace;
font-size: 14px;
resize: vertical;
}
button {
background-color: #007bff;
color: white;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
margin: 10px 5px;
}
button:hover {
background-color: #0056b3;
}
.output {
background-color: #f8f9fa;
border: 1px solid #dee2e6;
border-radius: 5px;
padding: 15px;
margin-top: 15px;
white-space: pre-wrap;
font-family: 'Courier New', monospace;
font-size: 14px;
max-height: 400px;
overflow-y: auto;
}
.error {
color: #dc3545;
background-color: #f8d7da;
border: 1px solid #f5c6cb;
padding: 10px;
border-radius: 5px;
margin-top: 10px;
}
.success {
color: #155724;
background-color: #d4edda;
border: 1px solid #c3e6cb;
padding: 10px;
border-radius: 5px;
margin-top: 10px;
}
</style>
</head>
<body>
<div class="container">
<h1>🔧 Modality Language Parser - WASM Demo</h1>
<div class="section">
<label for="modalityInput">Enter Modality Language Code:</label>
<textarea id="modalityInput" placeholder="Enter your modality language code here...">model TestModel:
graph g1:
n1 --> n2 : +blue -red
n2 --> n3 : +green
n3 --> n1 : -blue +yellow
graph g2:
a --> b : +init
b --> c : +complete
c --> a : +reset
state:
g1: n1 n2
g2: a</textarea>
</div>
<div class="section">
<button onclick="parseModel()">Parse Single Model</button>
<button onclick="parseAllModels()">Parse All Models</button>
<button onclick="generateMermaid()">Generate Mermaid Diagram</button>
<button onclick="generateStyledMermaid()">Generate Styled Mermaid</button>
<button onclick="generateStateMermaid()">Generate State-Aware Mermaid</button>
</div>
<div class="section">
<label>Output:</label>
<div id="output" class="output">Ready to parse! Click a button above to get started.</div>
</div>
</div>
<script type="module">
import init, { parse_model, parse_all_models, generate_mermaid, generate_mermaid_styled } from './modality_lang.js';
let wasmModule = null;
async function initializeWasm() {
try {
wasmModule = await init();
console.log('WASM module initialized successfully');
} catch (error) {
console.error('Failed to initialize WASM module:', error);
document.getElementById('output').innerHTML = '<div class="error">Failed to initialize WASM module: ' + error.message + '</div>';
}
}
window.parseModel = async function() {
if (!wasmModule) {
document.getElementById('output').innerHTML = '<div class="error">WASM module not initialized</div>';
return;
}
const input = document.getElementById('modalityInput').value;
const output = document.getElementById('output');
try {
const result = parse_model(input);
const model = JSON.parse(result);
output.innerHTML = '<div class="success">✅ Model parsed successfully!</div>\n\n' +
'<strong>Parsed Model:</strong>\n' +
JSON.stringify(model, null, 2);
} catch (error) {
output.innerHTML = '<div class="error">❌ Parse error: ' + error.message + '</div>';
}
};
window.parseAllModels = async function() {
if (!wasmModule) {
document.getElementById('output').innerHTML = '<div class="error">WASM module not initialized</div>';
return;
}
const input = document.getElementById('modalityInput').value;
const output = document.getElementById('output');
try {
const result = parse_all_models(input);
const models = JSON.parse(result);
output.innerHTML = '<div class="success">✅ All models parsed successfully!</div>\n\n' +
'<strong>Parsed Models:</strong>\n' +
JSON.stringify(models, null, 2);
} catch (error) {
output.innerHTML = '<div class="error">❌ Parse error: ' + error.message + '</div>';
}
};
window.generateMermaid = async function() {
if (!wasmModule) {
document.getElementById('output').innerHTML = '<div class="error">WASM module not initialized</div>';
return;
}
const input = document.getElementById('modalityInput').value;
const output = document.getElementById('output');
try {
const result = parse_all_models(input);
const models = JSON.parse(result);
const mermaidResult = generate_mermaid_diagrams(result);
output.innerHTML = '<div class="success">✅ Mermaid diagram generated successfully!</div>\n\n' +
'<strong>Mermaid Diagram:</strong>\n' +
'```mermaid\n' + mermaidResult + '\n```';
} catch (error) {
output.innerHTML = '<div class="error">❌ Error generating Mermaid: ' + error.message + '</div>';
}
};
window.generateStyledMermaid = async function() {
if (!wasmModule) {
document.getElementById('output').innerHTML = '<div class="error">WASM module not initialized</div>';
return;
}
const input = document.getElementById('modalityInput').value;
const output = document.getElementById('output');
try {
const result = parse_model(input);
const mermaidResult = generate_mermaid_styled(result);
output.innerHTML = '<div class="success">✅ Styled Mermaid diagram generated successfully!</div>\n\n' +
'<strong>Styled Mermaid Diagram:</strong>\n' +
'```mermaid\n' + mermaidResult + '\n```';
} catch (error) {
output.innerHTML = '<div class="error">❌ Error generating styled Mermaid: ' + error.message + '</div>';
}
};
window.generateStateMermaid = async function() {
if (!wasmModule) {
document.getElementById('output').innerHTML = '<div class="error">WASM module not initialized</div>';
return;
}
const input = document.getElementById('modalityInput').value;
const output = document.getElementById('output');
try {
const result = parse_model(input);
const mermaidResult = generate_mermaid_with_state(result);
output.innerHTML = '<div class="success">✅ State-aware Mermaid diagram generated successfully!</div>\n\n' +
'<strong>State-Aware Mermaid Diagram:</strong>\n' +
'```mermaid\n' + mermaidResult + '\n```';
} catch (error) {
output.innerHTML = '<div class="error">❌ Error generating state-aware Mermaid: ' + error.message + '</div>';
}
};
initializeWasm();
</script>
</body>
</html>