feat(domain): R4.6 ExportSession (incremental export, OD-2): rasters decoded and written on arrival, chunked file handed out in parts, views composed by the core, raster_size_of (O4); wasm ExportSession and CoreExportSession; R4 digests re-frozen (catalog and page tree written last, B2)

This commit is contained in:
bchanot committed 2026-10-19 01:15:43 +02:00
1 parent 8d16be577c
commit 9e688b6801
38 files changed
+2421 -354

No files matched your search

+68
View File
@@ -103,6 +103,74 @@ pub fn restore_copy(sheet: &LoadedSheet, bytes: Vec<u8>) -> String {
render(outcome)
}
/// The export session behind the wasm facade (R4.6, plan §B.1.4): the same envelopes as
/// the calls, the session's closed kinds (`unknown_key`, `duplicate_key`, `out_of_order`)
/// and the export's (`ExportErrorKind`).
#[cfg(feature = "pdf-write")]
pub mod export {
use super::{Failure, parse_input, render, to_value};
use crate::pdf::write::input::{ExportError, ExportInput};
use crate::pdf::write::session::{ExportSession, SessionError};
fn export_failure(error: ExportError) -> Failure {
Failure::new(error.kind.as_str(), error.detail)
}
fn session_failure(error: SessionError) -> Failure {
match error {
SessionError::Refused(refusal) => Failure::new(refusal.as_str(), ""),
SessionError::Export(error) => export_failure(error),
}
}
/// Opens a session on the `ExportInput` JSON; the failure names today's export kinds,
/// or `invalid_shape` / `invalid_json` / `lone_surrogate` for a text that is not one.
pub fn open(input: &str) -> Result<ExportSession, Failure> {
let input: ExportInput = parse_input(input)?;
ExportSession::new(input).map_err(export_failure)
}
/// `next()`: the `ExportStep` as the value.
pub fn next_step(session: &mut ExportSession) -> String {
render(
session
.next_step()
.map_err(session_failure)
.and_then(|step| to_value(&step)),
)
}
pub fn add_raster(session: &mut ExportSession, key: &str, png: &[u8]) -> String {
render(
session
.add_raster(key, png)
.map(|()| serde_json::Value::Null)
.map_err(session_failure),
)
}
pub fn raster_failed(session: &mut ExportSession, key: &str) -> String {
render(
session
.raster_failed(key)
.map(|()| serde_json::Value::Null)
.map_err(session_failure),
)
}
/// `finish()`: the number of parts the file comes in, or the failure (`out_of_order`,
/// `self_check_failed`, …).
pub fn finish(session: &mut ExportSession) -> Result<usize, Failure> {
session.finish().map_err(session_failure)?;
Ok(session.parts_left())
}
/// The warnings so far, as a JSON array (`ExportWarning`).
pub fn warnings(session: &ExportSession) -> String {
render(to_value(&session.warnings()))
}
}
fn unknown(op: &str) -> Failure {
Failure::new("unknown_op", format!("no operation named {op}"))
}