|
|
@ -9,6 +9,7 @@ const buttons = /** @type {HTMLDivElement} */ (document.getElementById('input-bu
|
|
|
|
const controlsButton = /** @type {HTMLButtonElement} */ (document.getElementById('controls-button'));
|
|
|
|
const controlsButton = /** @type {HTMLButtonElement} */ (document.getElementById('controls-button'));
|
|
|
|
const clearButton = /** @type {HTMLButtonElement} */ (document.getElementById('clear-button'));
|
|
|
|
const clearButton = /** @type {HTMLButtonElement} */ (document.getElementById('clear-button'));
|
|
|
|
const light = /** @type {HTMLDivElement} */ (document.getElementById('light'));
|
|
|
|
const light = /** @type {HTMLDivElement} */ (document.getElementById('light'));
|
|
|
|
|
|
|
|
const container = /** @type {HTMLDivElement} */ (document.getElementById('state-graph'));
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @param {import('./examples.js').State[]} states
|
|
|
|
* @param {import('./examples.js').State[]} states
|
|
|
@ -34,7 +35,9 @@ export function openAutomaton(states, editable = false) {
|
|
|
|
console.error(e);
|
|
|
|
console.error(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
const container = /** @type {HTMLDivElement} */ (document.getElementById('state-graph'));
|
|
|
|
while (container.firstChild) {
|
|
|
|
|
|
|
|
container.removeChild(container.firstChild);
|
|
|
|
|
|
|
|
}
|
|
|
|
container.appendChild(viewer);
|
|
|
|
container.appendChild(viewer);
|
|
|
|
viewer.graph = graph;
|
|
|
|
viewer.graph = graph;
|
|
|
|
|
|
|
|
|
|
|
@ -83,7 +86,10 @@ export function openAutomaton(states, editable = false) {
|
|
|
|
updateUIState();
|
|
|
|
updateUIState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Dynamically create buttons for each letter in the alphabet
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Dynamically create buttons for each letter in the alphabet.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
function createLetters() {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @type {string[]}
|
|
|
|
* @type {string[]}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -91,12 +97,18 @@ export function openAutomaton(states, editable = false) {
|
|
|
|
Object.keys(current.transitions).forEach(current => acc.add(current));
|
|
|
|
Object.keys(current.transitions).forEach(current => acc.add(current));
|
|
|
|
return acc;
|
|
|
|
return acc;
|
|
|
|
}, new Set())).sort();
|
|
|
|
}, new Set())).sort();
|
|
|
|
|
|
|
|
while (buttons.firstChild) {
|
|
|
|
|
|
|
|
buttons.removeChild(buttons.firstChild);
|
|
|
|
|
|
|
|
}
|
|
|
|
for (const letter of alphabet) {
|
|
|
|
for (const letter of alphabet) {
|
|
|
|
const button = document.createElement('button');
|
|
|
|
const button = document.createElement('button');
|
|
|
|
button.innerText = letter;
|
|
|
|
button.innerText = letter;
|
|
|
|
button.addEventListener('click', () => step(letter));
|
|
|
|
button.addEventListener('click', () => step(letter));
|
|
|
|
buttons.appendChild(button);
|
|
|
|
buttons.appendChild(button);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
createLetters();
|
|
|
|
|
|
|
|
|
|
|
|
// Reacts to input in the text box
|
|
|
|
// Reacts to input in the text box
|
|
|
|
wordInput.addEventListener('input', () => type());
|
|
|
|
wordInput.addEventListener('input', () => type());
|
|
|
|