ebnf-railroad-visualizer
Version:
A web-based EBNF railroad diagram visualizer
72 lines (71 loc) • 2.97 kB
TypeScript
import type * as d3T from "d3";
interface ChooChooVariables {
toExtend: Set<number[]>;
currentStartSymbolName: string;
}
interface LZString {
decompressFromBase64: (input: string) => string;
}
interface Window extends globalThis.Window {
chooChoo: ChooChooVariables;
generateDiagram: () => void;
handleGenerateDiagram: () => void;
handleStartSymbolSelection: () => void;
onCollapseAll: () => void;
onExpandAll: () => void;
updateSvgViewBoxSize: () => void;
exportSvg: () => void;
exportPng: () => void;
LZString?: LZString;
}
/**
* Installs provided functions into `window`, initializes global variables and adds listeners.
*
* Provided functions:
* - `generateDiagram` - Generate the diagram from the entered grammar.
* - `handleGenerateDiagram` - Handle the generation of a diagram from the entered grammar.
* - `handleStartSymbolSelection` - Handle the selection of a new start symbol.
* - `onCollapseAll` - Handle the collapse of all non-terminal-symbols.
* - `onExpandAll` - Handle the expansion of all non-terminal-symbols.
* - `exportSvg ` - Export the diagram as an SVG file.
* - `exportPng` - Export the diagram as a PNG file.
*
* Provided global variables:
* - `chooChoo` - Holds all necessary objects for this package.
*
* Expected DOM elements:
* - `error_message` - Container for error messages.
* - `visualized-ebnf` - Container for the diagram.
* - `ebnf_grammar` - Textarea for the EBNF grammar.
* - `.start-symbol-drop-down` - Container for the start symbol dropdown.
* - `start-symbol` - Select for the start symbol.
* @param {Window} window The window object to install the functions into.
* @param {typeof d3} d3Param The d3 to use. Must be imported in the main script and passed here.
*/
export declare function install(window: Window, d3Param?: typeof d3T): void;
/**
* Checks if a word starts with an uppercase letter.
*
* Because of course TS/JS doesn't have a built-in function for that.
* @param word The word to check.
* @returns `true` if the word starts with an uppercase letter, `false` otherwise.
*/
export declare function isUppercase(word: string): boolean;
/**
* Get the values of the grammar and expand paths from a URL.
* The counterpart to `addValuesToUrl`.
* @param {string} searchParams The search parameters of the URL
* @returns The grammar, expanded paths and start symbol name
*/
export declare function getValuesFromUrl(searchParams: string): Promise<[string, Set<number[]>, string]>;
/**
* Export the diagram as an SVG file.
* @param {Set<number[]>} toExpand The paths to expand, if not provided the current paths are used
*/
export declare function exportSvg(toExpand?: Set<number[]>): Promise<void>;
/**
* Export the diagram as a PNG file.
* @param {Set<number[]>} toExpand The paths to expand, if not provided the current paths are used
*/
export declare function exportPng(toExpand?: Set<number[]>): Promise<void>;
export {};