How arnog/mathlive works
Project type and purpose
• Type: An open-source, frontend-only JavaScript/TypeScript library
• Purpose: Expose a <math-field> web component for rich math input in browsers (with mobile support, virtual keyboards, accessibility, and multiple export formats)
File structure
• Top-level modules:
– src/core: core data structures (atoms), parser, layout, types, fonts, localization
– src/editor-model: the editable model (commands, selection, undo/redo)
– src/editor-mathfield: glue between model, core layout, and the browser (event handling, rendering, options)
– src/public: the public API exports, including mathfield-element, server-side rendering stub
– src/ui & src/virtual-keyboard: mouse/touch/keyboard UI, popovers, menus, virtual-keyboard logic and data
– src/formats, src/latex-commands, src/addons: extensibility points for input/output formats, LaTeX command definitions, and plug-ins
• Infrastructure: examples/, documentation/, test/, scripts/, build-config (tsconfig, jest.config, GitHub workflows)
• Deployment: package.json, npm scripts, CI configs, publishing scripts
Extract insights from README
• A single web component
• Emphasizes customization, multiple output formats, and accessibility
• No backend: pure client-side library, but supports SSR module
a. Main components
1. Browser / Host Page (user’s HTML page)
2. <math-field> Web Component (public API)
3. Editor Layer (src/editor-model + src/editor-mathfield)
4. Core Engine (src/core + atoms + formats + LaTeX definitions)
5. UI Layer (virtual keyboard, popovers, menus, styling)
6. -ons & Plug-ins (optional modules loaded at runtime)
7. Build & Packaging (scripts → npm package, CDN bundle)
8. Test & CI (Jest unit tests, Playwright E2E, GitHub Actions / Travis)
b. Relationships and data flow
• User interacts → Browser dispatches events → Web Component → Editor Layer (commands, model updates)
• Editor Layer invokes Core Engine to re-parse and re-layout → returns render tree or SVG/DOM elements
• UI Layer displays popovers, virtual keyboard → emits events back to Editor Layer
• Public API methods (getValue, setValue) call into Editor Layer/Core Engine
• -ons register with Core or Editor to extend functionality (e.g., static render, custom math-to-speech)
• Build & Packaging: source modules → bundler/transpiler → output to npm / CDN
• Test & CI validate code via unit tests and browser automation
c. Architectural patterns and design principles
• Modular layering: Public API → Editor → Core → Formats → Add-ons
• Event-driven: all user inputs and UI interactions flow as events/commands
• Plug-in architecture: src/addons, plugins/* for extensibility
• Separation of concerns: core parsing/layout vs. editor state vs. UI presentation
• SSR support: public SSR stub uses same Core logic without DOM
d. Key technologies/frameworks
• TypeScript + ES Modules
• Web Components (Custom Elements API)
• Less/PostCSS for styling
• Jest (unit tests), Playwright (E2E)
• Node.js build scripts (build.mjs, shell scripts)
• GitHub Actions & Travis CI