commit c7c54c9511796843034528f173c7292facb2e2d9 Author: GloamXun Date: Mon Oct 19 11:41:46 2026 +0800 Initial texrra web frontend Split the inline CSS and JavaScript into styles.css and app.js. The static assets are served by texrra-engine. Use preview page dimensions for A4/Letter aspect ratios, refresh the UI screenshots, and document the API contract. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fafff2e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.DS_Store +Thumbs.db diff --git a/README.md b/README.md new file mode 100644 index 0000000..32e898a --- /dev/null +++ b/README.md @@ -0,0 +1,91 @@ +# texrra web + +Build-free editor frontend for the [texrra engine](https://git.iloveuulove.me/gloamxun/texrra-engine). +It is plain HTML, CSS, and JavaScript: there is no bundler and no dependency +install. The engine serves these files and provides the same-origin API. + +![Projects dashboard](docs/screenshots/projects-dashboard.png) + +The landing page manages uploaded projects; opening one switches to the editor. + +![Project editor](docs/screenshots/project-editor.png) + +## Features + +- **Upload ZIP** creates a project from an archive. Extraction rejects absolute + paths and `..`, ignores directory entries, rejects encrypted and ZIP64 + archives, and caps a project at 64 MB / 2000 files. +- **New project** creates a minimal `main.tex`. +- Each project card offers **open / download / delete**; the editor header also + downloads the project ZIP. +- The sidebar lists every project file with type badges and folders. Right-click + a file for **open / download / delete**. +- **Upload files** adds files to the project root (drag and drop works too); + **new file** creates nested paths such as `sections/intro.tex`. +- Text files open with debounced autosave and a live preview of the project's + main file. Images render in the preview pane; other binary files show a + download action. +- The preview keeps one `
` per page and replaces only pages whose content + hash changed, so typing does not reload the view or jump the scroll position. +- Page cards take their aspect ratio and width from the preview payload, so A4 + and Letter documents are both displayed without distortion. + +## Run + +Clone both repositories as siblings and start the engine: + +```sh +git clone https://git.iloveuulove.me/gloamxun/texrra-engine.git engine +git clone https://git.iloveuulove.me/gloamxun/texrra-web.git web +cd engine +cargo run --release -- serve examples/hello.tex 4174 +``` + +Open . The engine discovers `../web` automatically; +`TEXRRA_WEB_DIR` can point at this checkout from elsewhere. The same files can +be edited in place while the engine is running and a browser reload picks them +up (the server sends `Cache-Control: no-cache`). + +## Files + +| Path | Purpose | +| --- | --- | +| `index.html` | Page shell and markup | +| `styles.css` | Layout, editor, preview, and context-menu styling | +| `app.js` | Project API client, editor state, autosave, preview diffing | +| `favicon.svg` | Browser icon | +| `docs/screenshots/` | UI screenshots used by this README | + +## API contract + +The frontend assumes the engine is the same origin and exposes: + +| Endpoint | Purpose | +| --- | --- | +| `GET /api/projects` | Project list | +| `POST /api/projects?name=` | Create a project from a ZIP body | +| `POST /api/projects/new?name=` | Create an empty project | +| `GET /api/projects/` | Project metadata and file list | +| `DELETE /api/projects/` | Delete a project | +| `GET /api/projects//zip` | Download the project as a ZIP | +| `GET /api/projects//raw?path=` | Read a file (`download=1` downloads it) | +| `PUT /api/projects//file?path=` | Write a text file | +| `POST /api/projects//files?path=` | Upload a file | +| `DELETE /api/projects//file?path=` | Delete a file | +| `POST /api/projects//preview` | Live preview of the main file | +| `POST /api/projects//pdf` | PDF of the main file | + +The preview response is a JSON object with `status`, `durationMs`, +`pageWidthMm`, `pageHeightMm`, and `pages` (one inline SVG and hash per page). +Font faces are loaded from `/fonts.css` and `/fonts/*.ttf`. + +## Design notes + +- No framework or build step: the shell is static and the editor is a + ` + +
+ +
+
+ 实时预览 + + + + +
+
+ +
+ +
+
+ + + + + + + + + + + + + diff --git a/styles.css b/styles.css new file mode 100644 index 0000000..0a90c9b --- /dev/null +++ b/styles.css @@ -0,0 +1,103 @@ +/* texrra web frontend styles. Served by texrra-engine at /styles.css. */ +:root { color-scheme: light; font-family: Inter, ui-sans-serif, system-ui, sans-serif; color: #1f2329; background: #f2f4f7; } +* { box-sizing: border-box; } +[hidden] { display: none !important; } +body { margin: 0; height: 100vh; display: flex; flex-direction: column; min-width: 720px; } +button { font: inherit; } +header { height: 54px; flex: none; display: flex; align-items: center; justify-content: space-between; padding: 0 20px; background: #fff; border-bottom: 1px solid #e3e6ea; } +.brand { display: flex; align-items: center; gap: 9px; font-size: 14px; font-weight: 650; letter-spacing: .01em; cursor: pointer; user-select: none; } +.brand-mark { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 7px; color: #fff; background: #315fce; font-family: Georgia, serif; font-size: 15px; } +.header-actions { display: flex; align-items: center; gap: 10px; } +.btn { height: 30px; padding: 0 12px; border: 1px solid #d5d9df; border-radius: 7px; background: #fff; color: #333a45; font-size: 12px; font-weight: 600; cursor: pointer; white-space: nowrap; } +.btn:hover { border-color: #b7bfca; background: #f7f8fa; } +.btn.primary { border-color: #315fce; background: #315fce; color: #fff; } +.btn.primary:hover { background: #2a53b5; } +.btn.danger { color: #b42318; border-color: #e8c5c1; } +.btn.danger:hover { background: #fff5f4; } +.btn:disabled { opacity: .55; cursor: progress; } +.icon-btn { width: 30px; height: 30px; display: inline-grid; place-items: center; border: 1px solid #d5d9df; border-radius: 7px; background: #fff; color: #333a45; cursor: pointer; font-size: 14px; } +.icon-btn:hover { background: #f7f8fa; } + +main { flex: 1; min-height: 0; display: flex; flex-direction: column; } + +.projects-view { flex: 1; min-height: 0; overflow: auto; padding: 32px 40px 60px; } +.projects-inner { max-width: 1080px; margin: 0 auto; } +.hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 22px; } +.hero h1 { margin: 0 0 6px; font-size: 24px; letter-spacing: -.01em; } +.hero p { margin: 0; color: #6b7280; font-size: 13px; } +.hero-actions { display: flex; gap: 10px; } +.drop-zone { margin-bottom: 22px; padding: 22px; border: 1.5px dashed #c6ccd6; border-radius: 12px; color: #6b7280; font-size: 13px; text-align: center; background: #fafbfc; transition: border-color .15s, background .15s; } +.drop-zone.dragging { border-color: #315fce; background: #f0f4ff; color: #315fce; } +.drop-zone strong { color: #333a45; } +.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; } +.project-card { display: flex; gap: 14px; padding: 16px; border: 1px solid #e3e6ea; border-radius: 12px; background: #fff; } +.project-card:hover { border-color: #cfd6e0; box-shadow: 0 6px 18px #1720330d; } +.project-badge { width: 42px; height: 42px; flex: none; display: grid; place-items: center; border-radius: 10px; background: #eef2ff; color: #315fce; font-size: 11px; font-weight: 800; letter-spacing: .04em; } +.project-body { min-width: 0; flex: 1; } +.project-body h3 { margin: 0 0 4px; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } +.project-meta { margin: 0 0 6px; color: #7b828e; font-size: 11.5px; } +.project-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; } +.empty-state { padding: 60px 20px; text-align: center; color: #7b828e; font-size: 13px; } + +.workspace { flex: 1; min-height: 0; display: grid; grid-template-columns: 232px minmax(300px, 1fr) minmax(340px, 1fr); background: #e3e6ea; gap: 1px; } +.file-panel { min-height: 0; display: flex; flex-direction: column; background: #fff; } +.file-panel-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid #eceef1; } +.project-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; font-weight: 650; } +.file-tools { display: flex; gap: 6px; padding: 8px 10px; border-bottom: 1px solid #eceef1; flex-wrap: wrap; } +.file-tools .btn { height: 26px; padding: 0 8px; font-size: 11px; } +.file-tree { flex: 1; min-height: 0; overflow: auto; padding: 6px 6px 16px; } +.tree-folder > .tree-row { color: #6b7280; font-weight: 600; } +.tree-row { display: flex; align-items: center; gap: 6px; height: 27px; padding: 0 8px; border-radius: 6px; font-size: 12.5px; cursor: pointer; user-select: none; white-space: nowrap; overflow: hidden; } +.tree-row:hover { background: #f3f5f8; } +.tree-row.active { background: #e8eefc; color: #22408c; } +.tree-row .caret { width: 10px; flex: none; color: #8a919c; font-size: 9px; } +.tree-row .file-name { overflow: hidden; text-overflow: ellipsis; } +.tree-folder.collapsed > .tree-children { display: none; } +.tree-children { margin-left: 12px; } +.file-badge { flex: none; width: 26px; text-align: center; border-radius: 4px; font-size: 8.5px; font-weight: 800; letter-spacing: .03em; color: #54607a; background: #eef1f5; padding: 2px 0; } +.file-badge.tex { color: #1d4ed8; background: #e8eefc; } +.file-badge.img { color: #0f766e; background: #e6f5f2; } +.file-badge.bib { color: #8a5a00; background: #fdf3dd; } +.file-badge.sty { color: #7c3aed; background: #f1e9fd; } +.file-panel-foot { padding: 8px 12px; border-top: 1px solid #eceef1; color: #8a919c; font-size: 11px; } + +.editor-panel { min-height: 0; display: flex; flex-direction: column; background: #fff; } +.panel-head { height: 36px; flex: none; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 14px; border-bottom: 1px solid #eceef1; color: #6b7280; font-size: 11px; font-weight: 650; letter-spacing: .05em; text-transform: uppercase; } +.panel-head .path { font-weight: 500; letter-spacing: 0; text-transform: none; color: #4b5563; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } +.panel-head .status { flex: none; letter-spacing: 0; text-transform: none; font-weight: 500; color: #8a919c; } +.panel-head .head-right { display: flex; align-items: center; gap: 10px; } +.btn.small { height: 24px; padding: 0 9px; font-size: 11px; border-radius: 6px; } +#source { flex: 1; min-height: 0; width: 100%; resize: none; border: 0; outline: 0; padding: 16px 18px; color: #1f2329; background: #fff; font: 13px/1.65 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; tab-size: 2; } +#source[readonly] { background: #fbfbfc; color: #6b7280; } +.binary-notice { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 30px; color: #6b7280; font-size: 13px; text-align: center; } +.binary-notice .big { font-size: 34px; } + +.preview-panel { min-height: 0; display: flex; flex-direction: column; background: #eef0f3; } +.preview-panel .panel-head { background: #fff; } +.preview-scroll { flex: 1; min-height: 0; overflow: auto; padding: 18px; } +#pages { display: flex; flex-direction: column; align-items: center; gap: 16px; } +.page { width: min(100%, var(--page-width, 210mm)); aspect-ratio: var(--page-aspect, 210 / 297); flex: none; background: #fff; box-shadow: 0 1px 2px #1720331f, 0 12px 28px #17203312; } +.page > svg { display: block; width: 100%; height: 100%; } +.asset-preview { display: block; max-width: 100%; margin: 0 auto; border: 1px solid #dfe3e8; border-radius: 6px; background: #fff; } +#preview-error { position: sticky; top: 0; z-index: 2; margin: 0 0 14px; padding: 12px 16px; border: 1px solid #efc8c4; border-radius: 8px; color: #81251e; background: #fff8f7f2; box-shadow: 0 4px 18px #17203318; } +#preview-error strong { display: block; margin-bottom: 6px; font-size: 12px; } +#preview-error pre { margin: 0; max-height: 240px; overflow: auto; font: 11px/1.5 ui-monospace, monospace; white-space: pre-wrap; overflow-wrap: anywhere; } + +#context-menu { position: fixed; z-index: 50; min-width: 160px; padding: 5px; border: 1px solid #d8dce2; border-radius: 8px; background: #fff; box-shadow: 0 10px 30px #17203324; } +#context-menu button { display: flex; width: 100%; align-items: center; gap: 8px; padding: 7px 10px; border: 0; border-radius: 5px; background: none; color: #333a45; font-size: 12.5px; text-align: left; cursor: pointer; } +#context-menu button:hover { background: #f2f4f8; } +#context-menu button.danger { color: #b42318; } +#context-menu .sep { height: 1px; margin: 4px 6px; background: #eceef1; } + +#toast { position: fixed; left: 18px; bottom: 18px; z-index: 60; max-width: 420px; padding: 10px 14px; border-radius: 8px; background: #1f2937; color: #fff; font-size: 12.5px; box-shadow: 0 10px 30px #17203330; } +#toast.error { background: #8f1d14; } + +footer { height: 28px; flex: none; display: flex; align-items: center; gap: 12px; padding: 0 16px; border-top: 1px solid #e3e6ea; background: #fff; color: #8a919c; font-size: 11px; } + +@media (max-width: 980px) { + body { min-width: 0; } + .workspace { grid-template-columns: 200px minmax(280px, 1fr); grid-template-rows: 1fr 1fr; } + .preview-panel { grid-column: 1 / -1; } + .projects-view { padding: 24px 18px 40px; } + .hero { flex-direction: column; align-items: flex-start; } +}