fix dark mode, attempt to fix top-bar

This commit is contained in:
unfunny
2026-10-20 19:26:48 -04:00
parent cc2c9a1ce9
commit 17878c9262
5 changed files with 416 additions and 132 deletions

51
AGENTS.md Normal file
View File

@@ -0,0 +1,51 @@
# AboveTheMark - GFM Editor
A React/Vite single-file markdown editor with LaTeX/SVG rendering, PDF/DOCX export.
## Quick Start
```bash
npm run dev # http://localhost:3000
npm run build # dist/index.html (standalone ~16KB)
```
Open `dist/index.html` directly in any browser—no server required.
## Build Targets
- **Singlefile HTML** (`SINGLEFILE=1 vite build`) — self-contained, offline-capable
- **IWA/Chrome Extension** — load popup from `public/manifest.json`
- **PWA** — installable app with service worker in `dist/sw.js`
## Project Structure
```
src/ # React components (App.jsx, Editor.jsx, Toolbar.jsx)
components/ # MarkdownEditor, LaTeXRenderer, SvgRenderer
hooks/ # useTheme, useKeyboardShortcuts
utils/ # exportDocx, importDocx, fileIo, exportPdf
public/ # sample.md, favicon.svg, icons.svg
dist/ # Production build (single index.html + manifest.json)
```
## Toolchain Quirks
- **Linting**: `oxlint` with React plugin (`react/rules-of-hooks`, `only-export-components`)
- **Minification**: Terser via Vite (`minify: 'terser'`)
- **Singlefile build**: Inline all assets (KaTeX fonts, CSS) as data URIs when `SINGLEFILE=1`
## Keyboard Shortcuts
| Key | Action |
|-----|--------|
| Ctrl+S / Cmd+S | Save as .md |
| Ctrl+O / Cmd+O | Open markdown file |
| Ctrl+P / Cmd+P | Export PDF (browser print) |
| Ctrl+Shift+S | Export DOCX |
| Ctrl+Shift+I | Import DOCX |
## Dev Notes
- Dependencies load from CDN; offline works after first visit
- KaTeX renders `$$...$$` and `$...$` math expressions
- SVGs supported via markdown images, raw HTML tags, or code blocks with language tag

2
package-lock.json generated
View File

@@ -25,7 +25,7 @@
"@types/react-dom": "^18.3.5",
"@vitejs/plugin-react": "^4.3.4",
"terser": "^5.51.2",
"vite": "^6.1.0",
"vite": "^6.4.4",
"vite-plugin-singlefile": "^2.3.3"
}
},

View File

@@ -27,7 +27,10 @@
"@types/react-dom": "^18.3.5",
"@vitejs/plugin-react": "^4.3.4",
"terser": "^5.51.2",
"vite": "^6.1.0",
"vite": "^6.4.4",
"vite-plugin-singlefile": "^2.3.3"
},
"allowScripts": {
"esbuild@0.25.12": true
}
}

View File

@@ -9,7 +9,9 @@ import {
HelpCircle,
Sparkles,
Plus,
ChevronDown
ChevronDown,
Menu as MenuIcon,
X
} from 'lucide-react';
export default function Toolbar({
@@ -30,6 +32,7 @@ export default function Toolbar({
}) {
const [themeDropdownOpen, setThemeDropdownOpen] = useState(false);
const [exportDropdownOpen, setExportDropdownOpen] = useState(false);
const [menuOpen, setMenuOpen] = useState(false);
const themeMenuRef = useRef(null);
const exportMenuRef = useRef(null);
@@ -49,13 +52,24 @@ export default function Toolbar({
const currentThemeObj = themes.find(t => t.id === theme) || themes[0];
// Toggle compact mode dropdown menu
const toggleMenu = (e) => {
e.stopPropagation();
setMenuOpen(!menuOpen);
};
return (
<header className="app-toolbar">
{/* Brand & Document Name */}
<div className="toolbar-left">
<div className="brand" title="AboveTheMark - Extensive GFM Editor">
<div
className="brand"
title="AboveTheMark - Extensive GFM Editor"
onClick={toggleMenu}
>
<div className="brand-logo">
<Sparkles size={18} />
{menuOpen && <X size={14} className="menu-close" />}
</div>
<span className="brand-name">AboveTheMark</span>
</div>
@@ -73,148 +87,285 @@ export default function Toolbar({
</div>
</div>
{/* Main Actions */}
<div className="toolbar-center">
<button
className="btn btn-ghost"
onClick={onNewFile}
title="New document (Ctrl+Shift+N)"
>
<Plus size={15} />
<span>New</span>
</button>
<button
className="btn btn-ghost"
onClick={onOpenFile}
title="Open markdown file (Ctrl+O)"
>
<FolderOpen size={15} />
<span>Open</span>
</button>
<button
className="btn btn-primary"
onClick={onSaveFile}
title="Save as .md (Ctrl+S)"
>
<Save size={15} />
<span>Save</span>
</button>
<div className="toolbar-divider" />
<button
className="btn btn-ghost"
onClick={onImportDocx}
title="Import Microsoft Word document (Ctrl+Shift+I)"
>
<Upload size={15} />
<span>Import DOCX</span>
</button>
{/* Export Dropdown */}
<div className="dropdown" ref={exportMenuRef}>
{/* Compact Mode Dropdown Menu (shown when window is small or menu clicked) */}
{menuOpen && (
<div className="compact-menu">
<button
className="btn btn-ghost dropdown-toggle"
onClick={() => setExportDropdownOpen(!exportDropdownOpen)}
title="Export options"
className="btn btn-ghost"
onClick={onNewFile}
title="New document (Ctrl+Shift+N)"
>
<Download size={15} />
<span>Export</span>
<ChevronDown size={12} />
<Plus size={15} />
<span>New</span>
</button>
{exportDropdownOpen && (
<div className="dropdown-menu">
<button
className="dropdown-item"
onClick={() => {
setExportDropdownOpen(false);
onExportDocx();
}}
title="Export native Microsoft Word (.docx) document (Ctrl+Shift+S)"
>
<FileText size={15} />
<div className="dropdown-item-text">
<strong>Export to DOCX</strong>
<small>Native Microsoft Word format</small>
</div>
</button>
<button
className="dropdown-item"
onClick={() => {
setExportDropdownOpen(false);
onExportPdf();
}}
title="Export clean vector PDF via browser print (Ctrl+P)"
>
<Printer size={15} />
<div className="dropdown-item-text">
<strong>Export to PDF</strong>
<small>Vector formatted with KaTeX</small>
</div>
</button>
</div>
)}
</div>
</div>
{/* Right Tools (Theme, Samples, Shortcuts) */}
<div className="toolbar-right">
{/* Sample Document Loader */}
<button
className="btn btn-ghost btn-icon-only"
onClick={onLoadSample}
title="Load comprehensive showcase sample (LaTeX, SVG, Tables, etc.)"
>
<Sparkles size={16} />
</button>
{/* Theme Selector Dropdown */}
<div className="dropdown" ref={themeMenuRef}>
<button
className="btn btn-ghost theme-btn"
onClick={() => setThemeDropdownOpen(!themeDropdownOpen)}
title={`Current Theme: ${currentThemeObj.label}`}
className="btn btn-ghost"
onClick={onOpenFile}
title="Open markdown file (Ctrl+O)"
>
<span className="theme-icon">{currentThemeObj.icon}</span>
<span className="theme-label">{currentThemeObj.label}</span>
<ChevronDown size={12} />
<FolderOpen size={15} />
<span>Open</span>
</button>
{themeDropdownOpen && (
<div className="dropdown-menu dropdown-menu-right">
<div className="dropdown-header">Color Themes</div>
{themes.map((t) => (
<button
key={t.id}
className={`dropdown-item ${theme === t.id ? 'active' : ''}`}
<button
className="btn btn-primary"
onClick={onSaveFile}
title="Save as .md (Ctrl+S)"
>
<Save size={15} />
<span>Save</span>
</button>
<div className="toolbar-divider" />
<button
className="btn btn-ghost"
onClick={onImportDocx}
title="Import Microsoft Word document (Ctrl+Shift+I)"
>
<Upload size={15} />
<span>Import DOCX</span>
</button>
{/* Export Dropdown */}
<div className="dropdown" ref={exportMenuRef}>
<button
className="btn btn-ghost dropdown-toggle"
onClick={() => setExportDropdownOpen(!exportDropdownOpen)}
title="Export options"
>
<Download size={15} />
<span>Export</span>
<ChevronDown size={12} />
</button>
{exportDropdownOpen && (
<div className="dropdown-menu">
<button
className="dropdown-item"
onClick={() => {
setTheme(t.id);
setThemeDropdownOpen(false);
setExportDropdownOpen(false);
onExportDocx();
}}
title="Export native Microsoft Word (.docx) document (Ctrl+Shift+S)"
>
<span className="dropdown-item-icon">{t.icon}</span>
<FileText size={15} />
<div className="dropdown-item-text">
<strong>{t.label}</strong>
<strong>Export to DOCX</strong>
<small>Native Microsoft Word format</small>
</div>
</button>
))}
</div>
)}
</div>
{/* Shortcuts Help */}
<button
className="btn btn-ghost btn-icon-only"
onClick={onOpenShortcuts}
title="Keyboard shortcuts & cheatsheet (F1 or Ctrl+/)"
>
<HelpCircle size={16} />
</button>
</div>
<button
className="dropdown-item"
onClick={() => {
setExportDropdownOpen(false);
onExportPdf();
}}
title="Export clean vector PDF via browser print (Ctrl+P)"
>
<Printer size={15} />
<div className="dropdown-item-text">
<strong>Export to PDF</strong>
<small>Vector formatted with KaTeX</small>
</div>
</button>
</div>
)}
</div>
{/* Theme Dropdown */}
<div className="dropdown" ref={themeMenuRef}>
<button
className="btn btn-ghost theme-btn"
onClick={() => setThemeDropdownOpen(!themeDropdownOpen)}
title={`Current Theme: ${currentThemeObj.label}`}
>
<span className="theme-icon">{currentThemeObj.icon}</span>
<span className="theme-label">{currentThemeObj.label}</span>
<ChevronDown size={12} />
</button>
{themeDropdownOpen && (
<div className="dropdown-menu dropdown-menu-right">
<div className="dropdown-header">Color Themes</div>
{themes.map((t) => (
<button
key={t.id}
className={`dropdown-item ${theme === t.id ? 'active' : ''}`}
onClick={() => {
setTheme(t.id);
setThemeDropdownOpen(false);
}}
>
<span className="dropdown-item-icon">{t.icon}</span>
<div className="dropdown-item-text">
<strong>{t.label}</strong>
</div>
</button>
))}
</div>
)}
</div>
{/* Shortcuts Help */}
<button
className="btn btn-ghost btn-icon-only"
onClick={onOpenShortcuts}
title="Keyboard shortcuts & cheatsheet (F1 or Ctrl+/)"
>
<HelpCircle size={16} />
</button>
</div>
)}
{/* Main Actions - shown when menu is closed */}
{!menuOpen && (
<div className="toolbar-center">
<button
className="btn btn-ghost"
onClick={onNewFile}
title="New document (Ctrl+Shift+N)"
>
<Plus size={15} />
<span>New</span>
</button>
<button
className="btn btn-ghost"
onClick={onOpenFile}
title="Open markdown file (Ctrl+O)"
>
<FolderOpen size={15} />
<span>Open</span>
</button>
<button
className="btn btn-primary"
onClick={onSaveFile}
title="Save as .md (Ctrl+S)"
>
<Save size={15} />
<span>Save</span>
</button>
<div className="toolbar-divider" />
<button
className="btn btn-ghost"
onClick={onImportDocx}
title="Import Microsoft Word document (Ctrl+Shift+I)"
>
<Upload size={15} />
<span>Import DOCX</span>
</button>
{/* Export Dropdown */}
<div className="dropdown" ref={exportMenuRef}>
<button
className="btn btn-ghost dropdown-toggle"
onClick={() => setExportDropdownOpen(!exportDropdownOpen)}
title="Export options"
>
<Download size={15} />
<span>Export</span>
<ChevronDown size={12} />
</button>
{exportDropdownOpen && (
<div className="dropdown-menu">
<button
className="dropdown-item"
onClick={() => {
setExportDropdownOpen(false);
onExportDocx();
}}
title="Export native Microsoft Word (.docx) document (Ctrl+Shift+S)"
>
<FileText size={15} />
<div className="dropdown-item-text">
<strong>Export to DOCX</strong>
<small>Native Microsoft Word format</small>
</div>
</button>
<button
className="dropdown-item"
onClick={() => {
setExportDropdownOpen(false);
onExportPdf();
}}
title="Export clean vector PDF via browser print (Ctrl+P)"
>
<Printer size={15} />
<div className="dropdown-item-text">
<strong>Export to PDF</strong>
<small>Vector formatted with KaTeX</small>
</div>
</button>
</div>
)}
</div>
</div>
)}
{/* Right Tools (Theme, Samples, Shortcuts) */}
{!menuOpen && (
<div className="toolbar-right">
{/* Sample Document Loader */}
<button
className="btn btn-ghost btn-icon-only"
onClick={onLoadSample}
title="Load comprehensive showcase sample (LaTeX, SVG, Tables, etc.)"
>
<Sparkles size={16} />
</button>
{/* Theme Selector Dropdown */}
<div className="dropdown" ref={themeMenuRef}>
<button
className="btn btn-ghost theme-btn"
onClick={() => setThemeDropdownOpen(!themeDropdownOpen)}
title={`Current Theme: ${currentThemeObj.label}`}
>
<span className="theme-icon">{currentThemeObj.icon}</span>
<span className="theme-label">{currentThemeObj.label}</span>
<ChevronDown size={12} />
</button>
{themeDropdownOpen && (
<div className="dropdown-menu dropdown-menu-right">
<div className="dropdown-header">Color Themes</div>
{themes.map((t) => (
<button
key={t.id}
className={`dropdown-item ${theme === t.id ? 'active' : ''}`}
onClick={() => {
setTheme(t.id);
setThemeDropdownOpen(false);
}}
>
<span className="dropdown-item-icon">{t.icon}</span>
<div className="dropdown-item-text">
<strong>{t.label}</strong>
</div>
</button>
))}
</div>
)}
</div>
{/* Shortcuts Help */}
<button
className="btn btn-ghost btn-icon-only"
onClick={onOpenShortcuts}
title="Keyboard shortcuts & cheatsheet (F1 or Ctrl+/)"
>
<HelpCircle size={16} />
</button>
</div>
)}
</header>
);
}

View File

@@ -258,6 +258,7 @@ body {
text-align: left;
cursor: pointer;
transition: all 0.15s ease;
color: var(--text-primary);
}
.dropdown-item:hover {
@@ -267,7 +268,7 @@ body {
.dropdown-item.active,
.dropdown-item[aria-checked="true"] {
background: var(--accent-color);
color: white;
color: #ffffff;
}
.dropdown-header {
@@ -479,6 +480,66 @@ body {
flex: 0 0 auto;
}
/* Compact mode - collapse buttons when window is too narrow */
@media (max-width: 768px) {
.toolbar-center,
.toolbar-right {
display: none;
}
.toolbar-left {
justify-content: center;
width: 100%;
}
.app-toolbar {
gap: 4px;
}
.brand {
margin-right: auto;
}
}
/* Compact menu styling */
.compact-menu {
display: flex;
align-items: center;
gap: 8px;
}
.menu-close {
color: var(--text-secondary);
opacity: 0;
transition: opacity 0.2s ease;
}
.brand:hover .menu-close,
.compact-menu + .brand .menu-close {
opacity: 1;
}
.toolbar-divider {
margin: 0 8px;
}
/* Compact mode - collapse buttons when window is too narrow */
@media (max-width: 768px) {
.toolbar-left,
.toolbar-center,
.toolbar-right {
display: none;
}
.app-toolbar {
justify-content: center;
}
.brand {
margin-right: auto;
}
}
.theme-icon {
font-size: 15px;
}
@@ -661,3 +722,21 @@ kbd {
from { transform: translateY(0); opacity: 1; }
to { transform: translateY(100%); opacity: 0; }
}
/* Compact menu styling */
.compact-menu {
display: flex;
align-items: center;
gap: 6px;
}
.menu-close {
color: var(--text-secondary);
opacity: 0;
transition: opacity 0.2s ease;
}
.brand:hover .menu-close,
.compact-menu + .brand .menu-close {
opacity: 1;
}