Merge branch 'main' into gh-pages

This commit is contained in:
Parker TenBroeck 2026-01-08 22:15:05 -05:00
commit 1876ed3222
2 changed files with 14 additions and 10 deletions

View file

@ -479,6 +479,7 @@ impl Npda {
a a
}, },
)); ));
let final_states = final_states.map(|f| { let final_states = final_states.map(|f| {
StateMap(f.iter().fold(vec![false; states.len()], |mut a, k| { StateMap(f.iter().fold(vec![false; states.len()], |mut a, k| {
a[k.0 as usize] = true; a[k.0 as usize] = true;

View file

@ -2,6 +2,7 @@
// deno-lint-ignore no-import-prefix // deno-lint-ignore no-import-prefix
import * as vis from "npm:vis-network/standalone"; import * as vis from "npm:vis-network/standalone";
import { StateEffect } from "npm:@codemirror/state";
export const nodes = new vis.DataSet<vis.Node>(); export const nodes = new vis.DataSet<vis.Node>();
export const edges = new vis.DataSet<vis.Edge>(); export const edges = new vis.DataSet<vis.Edge>();
@ -109,29 +110,31 @@ export function updateGraphTheme() {
type StateId = string; type StateId = string;
type GraphDef = { type GraphDef = {
initial: StateId; initial: StateId;
final: StateId[]; final_states: Set<StateId>;
states: StateId[]; states: Set<StateId>;
transitions: Record<string, string>; transitions: Record<string, string>;
}; };
let automaton: GraphDef = { let automaton: GraphDef = {
initial: "", initial: "",
final: [], final_states: new Set(),
states: [], states: new Set(),
transitions: {}, transitions: {},
}; };
export function clearAutomaton() { export function clearAutomaton() {
setAutomaton({ setAutomaton({
initial: "", initial: "",
final: [], final_states: new Set(),
states: [], states: new Set(),
transitions: {}, transitions: {},
}); });
} }
export function setAutomaton(auto: GraphDef) { export function setAutomaton(auto: GraphDef) {
automaton = auto; automaton = auto;
automaton.final_states = new Set(automaton.final_states)
automaton.states = new Set(automaton.states)
// Populate nodes // Populate nodes
for (const state of automaton.states) { for (const state of automaton.states) {
if (nodes.get(state)) { if (nodes.get(state)) {
@ -179,7 +182,7 @@ export function setAutomaton(auto: GraphDef) {
} }
for (const node_id of nodes.getIds()){ for (const node_id of nodes.getIds()){
if (!auto.states.includes(node_id as string)){ if (!auto.states.has(node_id as string)){
nodes.remove(node_id) nodes.remove(node_id)
} }
} }
@ -280,9 +283,9 @@ function renderNode({
const t = getGraphTheme(); const t = getGraphTheme();
const r = Math.max(14, style?.size ?? 18); const r = Math.max(14, style?.size ?? 18);
const isInitial = id === "q0"; const isInitial = automaton.initial === id;
const isFinal = id === "q1"; // <-- change if your schema differs const isFinal = automaton.final_states.has(id);
const isActive = id === "q0"; // <-- change if your schema differs const isActive = false;
const fill = selected ? t.bg_2 : hover ? t.bg_1 : t.bg_0; const fill = selected ? t.bg_2 : hover ? t.bg_1 : t.bg_0;
const stroke = isActive ? t.current_node_border : t.node_border; const stroke = isActive ? t.current_node_border : t.node_border;