Connect the native Beta to the project Web workspace

This commit is contained in:
gloamxun committed 2026-11-29 13:36:48 +08:00
1 parent 29193c03bc
commit 8b6dab8d52
5 files changed
+155 -20

No files matched your search

+14
View File
@@ -36,6 +36,20 @@ python3 target/local-beta/native-beta.py compile /path/to/main.tex /path/to/outp
编辑器在试用目录中创建工作副本。命令行按项目实际读写作业文件。
需要 BibTeX 的项目可在辅助文件生成后运行 BibTeX,再继续 LaTeX 编译到引用收敛。
## 使用项目的 Web 界面
将 texrra-web 放在引擎仓库旁边。启动或重开时指定 Web 目录。
~~~sh
python3 target/local-beta/native-beta.py open --web-dir ../texrra-web
python3 target/local-beta/native-beta.py resume /path/to/saved-project --web-dir ../texrra-web
~~~
该入口显示 Web 工作台的文件栏、编辑区和预览区。编辑、局部预览、
源码保存及下载 PDF 都使用原生 Beta 会话。每次启动打开一个由命令行
指定的项目。现有 Web 的项目列表和 ZIP 导入仍在原 serve 入口。
启动指令中的其他参数和保存目录格式与上文相同。
## 保存和重新打开
点击「保存源文件」将当前编辑与已声明的项目资源一起写入一个新目录。
+18
View File
@@ -18,6 +18,24 @@
| W6 会话 | 实施中 | 共享库/CLI 与当前原生文字/数学/规则来源进入公共结果;真实 A4 副本九类/27 revision 与独立干净作业页面/PDF/aux/映射一致,新增数学场景独立参考通过;详细失败/捕获重放及宿主/离线/CLI观察已通过;原子项目版本/已知生成初态及TeX流记录已接通;原样 12 页 NeurIPS 的中部编辑与恢复已验证前后缀复用、仅更新一页,且与独立全量一致。全部副作用/交叉编辑、旧来源与正式性能门禁仍待闭合 |
| W7 总验收 | 未满足 | 原有和新增测试、原样项目、格式与会话门禁全部通过才能结项 |
## 2026-11-29 原生 Beta 接入 texrra-web 工作台
本地启动器的 --web-dir 接入现有 texrra-web 的 HTML、样式和图标。
原生会话脚本连接同一工作台的文件栏、编辑、报错、局部页面和 PDF
下载,支持保存源码副本及快捷键。该入口一次打开一个指定项目。
既有项目列表与 ZIP 导入的迁移属于后续集成。
固定 Web 仓库 e14b7aa 及 A4 原样多文件输入。在 Edge 验证工作台
打开、子文件切换、修改、保存、错误和恢复。修改后只更新第一页,
来源表记录本轮子文件字节。错版继续提供上次 PDF,恢复相同文本
沿用已显示页。下载 PDF 及辅助文件与保存副本的独立 CLI 两轮收敛
结果逐字节一致。保留真实浏览器截图及 HTML、样式和图标身份。
本机试用包位于 target/native-beta-web/beta-pdftex/。证据目录
target/native-beta-web/ 的 SHA256SUMS 指纹为
023b5d857af62da963b7d9b2e51157534c4f14f0c256dbf81d207923bc7d4bfe。
[Web 启动方式](NATIVE_BETA.md#使用项目的-web-界面)
## 2026-11-29 Beta 源码保存和恢复
编辑器保存时将当前浏览器缓冲与已声明的输入资源一并写入一个
+78 -14
View File
@@ -1,12 +1,17 @@
const workspace = document.querySelector("#workspace");
if (workspace) attachWebControls();
const source = document.querySelector("#source");
const pages = document.querySelector("#pages");
const status = document.querySelector("#status");
const error = document.querySelector("#error");
const status = document.querySelector("#status, #preview-status");
const error = document.querySelector("#error, #preview-error-text");
const errorPanel = document.querySelector("#error, #preview-error");
const pdf = document.querySelector("#pdf");
const save = document.querySelector("#save");
const saved = document.querySelector("#saved");
const saved = document.querySelector("#saved, #file-panel-foot");
const selector = document.querySelector("#project-files");
const name = document.querySelector("#name");
const name = document.querySelector("#name, #open-file-path");
const fileTree = document.querySelector("#file-tree");
const edits = new Map();
let files;
let activeFile;
@@ -16,16 +21,60 @@ let draft = null;
let frame;
const previewDraft = new URLSearchParams(location.hash.slice(1)).get("preview") !== "published";
function attachWebControls() {
const button = document.createElement("button");
button.type = "button";
button.id = "save";
button.className = "btn";
button.disabled = true;
button.textContent = "保存源文件";
document.querySelector(".file-tools").replaceChildren(button);
const download = document.createElement("a");
download.id = "pdf";
download.className = "btn small";
download.download = "";
download.hidden = true;
download.textContent = "下载 PDF";
document.querySelector("#export-pdf").replaceWith(download);
document.querySelector("#back-button").hidden = true;
document.querySelector("#toggle-engine").hidden = true;
document.querySelector("#header-actions").textContent = "原生 Beta";
document.querySelector("footer").textContent = "Ctrl/Cmd+S 保存源码副本";
document.querySelector("#source").disabled = true;
document.querySelector("#file-panel-foot").setAttribute("role", "status");
document.querySelector("#file-panel-foot").style.overflowWrap = "anywhere";
workspace.hidden = false;
}
function selectFile(filename) {
activeFile = filename;
name.textContent = filename;
source.value = edits.get(filename) ?? files.get(filename);
if (fileTree) {
for (const row of fileTree.children) {
const selected = row.dataset.path === activeFile;
row.classList.toggle("active", selected);
row.setAttribute("aria-pressed", selected);
}
}
}
function showError(message) {
status.textContent = "编译失败";
error.textContent = message;
error.hidden = false;
errorPanel.hidden = false;
}
function pageImage(page) {
const img = new Image();
img.alt = `第 ${page.index + 1} 页`;
img.dataset.index = page.index;
if (workspace) {
img.className = "page";
img.style.aspectRatio = "auto";
}
img.src = URL.createObjectURL(new Blob([page.svg], { type: "image/svg+xml" }));
return img;
}
@@ -116,7 +165,7 @@ async function compile(edit, submitted, changes) {
} else {
acceptPublication(update.revision, previous);
}
error.hidden = true;
errorPanel.hidden = true;
await new Promise(requestAnimationFrame);
await new Promise(requestAnimationFrame);
if (edit !== sequence) return;
@@ -199,22 +248,37 @@ async function openProject() {
if (!response.ok) throw new Error("无法打开源文件");
const project = await response.json();
files = new Map(Object.entries(project.files));
activeFile = project.name;
name.textContent = activeFile;
source.value = files.get(activeFile);
if (fileTree) {
document.querySelector("#project-title").textContent = project.name;
for (const filename of files.keys()) {
const row = document.createElement("button");
row.type = "button";
row.className = "btn tree-row file-row";
row.style.width = "100%";
row.dataset.path = filename;
row.textContent = filename;
row.title = filename;
row.addEventListener("click", () => selectFile(filename));
fileTree.append(row);
}
}
selectFile(project.name);
source.disabled = false;
sequence = project.sequence;
save.disabled = false;
save.addEventListener("click", saveSources);
if (files.size > 1) {
document.addEventListener("keydown", (event) => {
if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === "s") {
event.preventDefault();
if (!save.disabled) saveSources();
}
});
if (selector && files.size > 1) {
for (const filename of files.keys()) selector.add(new Option(filename, filename));
selector.value = activeFile;
selector.hidden = false;
name.hidden = true;
selector.addEventListener("change", () => {
activeFile = selector.value;
source.value = edits.get(activeFile) ?? files.get(activeFile);
});
selector.addEventListener("change", () => selectFile(selector.value));
}
source.addEventListener("input", () => {
edits.set(activeFile, source.value);
+40 -2
View File
@@ -188,7 +188,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
std::process::exit(status);
}
let mut args = std::env::args_os().skip(1).peekable();
let usage = "native_editor [--input-profile tex8bit|unicode|xetex] SOURCE FORMAT FORMAT_RESOURCES NEW_RUN_DIR [PORT] [FILE ...]";
let usage = "native_editor [--input-profile tex8bit|unicode|xetex] [--web-dir DIR] SOURCE FORMAT FORMAT_RESOURCES NEW_RUN_DIR [PORT] [FILE ...]";
let input_profile = if args.next_if(|arg| arg == "--input-profile").is_some() {
match args.next().as_deref().and_then(std::ffi::OsStr::to_str) {
Some("tex8bit") => InputProfile::TeX8Bit,
@@ -199,6 +199,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
} else {
InputProfile::TeX8Bit
};
let web = if args.next_if(|arg| arg == "--web-dir").is_some() {
let path = PathBuf::from(args.next().ok_or(usage)?);
Some(WebAssets::load(&path)?)
} else {
None
};
let mut args = args.map(PathBuf::from);
let source = args.next().ok_or(usage)?.canonicalize()?;
let format = args.next().ok_or(usage)?.canonicalize()?;
@@ -234,7 +240,23 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
for request in server.incoming_requests() {
let path = request.url().to_owned();
match (request.method(), path.as_str()) {
(&Method::Get, "/") => respond(request, 200, "text/html; charset=utf-8", PAGE.into()),
(&Method::Get, "/") => respond(
request,
200,
"text/html; charset=utf-8",
web.as_ref().map_or_else(|| PAGE.into(), |assets| assets.index.clone()),
),
(&Method::Get, "/styles.css") if web.is_some() => respond(
request, 200, "text/css; charset=utf-8", web.as_ref().unwrap().styles.clone(),
),
(&Method::Get, "/favicon.svg") if web.is_some() => respond(
request, 200, "image/svg+xml", web.as_ref().unwrap().favicon.clone(),
),
// The shared Web shell requests this stylesheet. Native preview
// pages carry their glyph outlines in their SVG output.
(&Method::Get, "/fonts.css") if web.is_some() => {
respond(request, 200, "text/css; charset=utf-8", Vec::new())
}
(&Method::Get, "/app.js") => respond(
request,
200,
@@ -419,6 +441,22 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}
struct WebAssets {
index: Vec<u8>,
styles: Vec<u8>,
favicon: Vec<u8>,
}
impl WebAssets {
fn load(path: &Path) -> std::io::Result<Self> {
Ok(Self {
index: fs::read(path.join("index.html"))?,
styles: fs::read(path.join("styles.css"))?,
favicon: fs::read(path.join("favicon.svg"))?,
})
}
}
fn read_json<T: serde::de::DeserializeOwned>(request: &mut Request) -> Result<T, String> {
let mut body = Vec::new();
request
+5 -4
View File
@@ -143,10 +143,10 @@ def launch(args):
else:
runs.mkdir(exist_ok=True)
run = Path(tempfile.mkdtemp(prefix="editor-", dir=runs)) / "project"
command = [
bundle / "bin" / binary_name("native_editor"), "--input-profile", profile,
source, bundle / FORMAT, bundle / RESOURCES, run, str(args.port), *assets,
]
command = [bundle / "bin" / binary_name("native_editor"), "--input-profile", profile]
if args.web_dir:
command.extend(["--web-dir", args.web_dir.resolve(strict=True)])
command.extend([source, bundle / FORMAT, bundle / RESOURCES, run, str(args.port), *assets])
else:
command = native_command(bundle / "bin" / binary_name("texrra"), profile, roots)
command.extend(["--load-format", bundle / FORMAT, args.entry.resolve(strict=True),
@@ -174,6 +174,7 @@ def main():
resume = commands.add_parser("resume", help="reopen a saved source snapshot")
resume.add_argument("snapshot", type=Path)
for command in (editor, resume):
command.add_argument("--web-dir", type=Path, help="use the texrra-web checkout")
command.add_argument("--run-dir", type=Path)
command.add_argument("--port", type=int, default=0)