PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Merge #4253: wasm back under the 24 MiB gate
Claude7f9c4394c1fa
diff --cc Cargo.tomlindex 6b13954fd,5c003659b..f075c89d0--- a/Cargo.toml+++ b/Cargo.toml@@@ -95,38 -98,19 +98,35 @@@ strip = "debuginfo[profile.wasm-release.package."*"]opt-level = "s"- # Keep the browser shell compact as shared panel controls grow. Pixel-processing crates below- # retain their speed-oriented optimization level.- [profile.wasm-release.package.photocraft-ui-egui]- opt-level = "z"-- # Keep browser command dispatch, import/export glue, and the entry point compact. Native- # builds and the speed-oriented pixel-processing overrides below retain their settings.- [profile.wasm-release.package.photocraft-engine]- opt-level = "z"- [profile.wasm-release.package.photocraft-io]- opt-level = "z"- [profile.wasm-release.package.photocraft-web]- opt-level = "z"+ # Decoding and rasterizing keep their speed.+ [profile.wasm-release.package.photocraft-codecs]+ opt-level = "s"-[profile.wasm-release.package.photocraft-psd]-opt-level = "s"+ [profile.wasm-release.package.photocraft-raw]+ opt-level = "s"+ [profile.wasm-release.package.photocraft-heif]+ opt-level = "s"+ [profile.wasm-release.package.photocraft-vector]+ opt-level = "s"+# Large crates off the per-frame and per-pixel paths: the document model, file parsers run once+# per open/save, JSON (settings, presets, control channel), SVG parsing, and shader translation+# (runs when a pipeline is created). "z" keeps the wasm well under the size gate.+[profile.wasm-release.package.photocraft-doc]+opt-level = "z"+[profile.wasm-release.package.photocraft-psd]+opt-level = "z"+[profile.wasm-release.package.photocraft-format]+opt-level = "z"+[profile.wasm-release.package.photocraft-affinity]+opt-level = "z"+[profile.wasm-release.package.serde_json]+opt-level = "z"+[profile.wasm-release.package.usvg]+opt-level = "z"+[profile.wasm-release.package.naga]+opt-level = "z"++ # Pixel processing keeps its speed-oriented optimization level.[profile.wasm-release.package.photocraft-raster]opt-level = 3[profile.wasm-release.package.photocraft-color]diff --cc crates/ui-egui/src/i18n/mod.rsindex fe6e8e680,e7347ca5a..bdf4ef556--- a/crates/ui-egui/src/i18n/mod.rs+++ b/crates/ui-egui/src/i18n/mod.rs@@@ -140,8 -140,54 +140,54 @@@ fn inflate(source: &[u8]) -> Result<StrOk(text)}+ /// Every catalog entry's `context<TAB>source`, stored once for all catalogs (build.rs).+ static KEYS: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/i18n/keys.deflate"));++ /// Restore a catalog file from its packed form (build.rs `pack_catalogs`): entry lines refer to+ /// [`KEYS`] instead of repeating the English source. Bad data gives an error (and the language+ /// falls back to English), never a panic.+ fn unpack(source: &[u8]) -> Result<String, String> {+ static KEY_TEXT: OnceLock<Result<String, String>> = OnceLock::new();+ if source.is_empty() {+ return Ok(String::new());+ }+ let keys: Vec<&str> = KEY_TEXT.get_or_init(|| inflate(KEYS)).as_ref().map_err(|e| format!("catalog keys: {e}"))?.split('\n').collect();+ expand(&inflate(source)?, &keys)+ }++ /// [`unpack`]'s second step: replace each packed entry line with its key and translation.+ fn expand(packed: &str, keys: &[&str]) -> Result<String, String> {+ let mut text = String::with_capacity(packed.len().saturating_mul(2));+ let mut next = 0usize;+ for (n, line) in packed.split('\n').enumerate() {+ if n > 0 {+ text.push('\n');+ }+ let bad = || format!("packed line {}: bad key reference", n + 1);+ let (index, tr) = if let Some(tr) = line.strip_prefix('\x01') {+ (next, tr)+ } else if let Some(rest) = line.strip_prefix('\x02') {+ let (offset, tr) = rest.split_once('\t').ok_or_else(bad)?;+ let offset: i64 = offset.parse().map_err(|_| bad())?;+ let index = i64::try_from(next).ok().and_then(|n| n.checked_add(offset)).and_then(|i| usize::try_from(i).ok()).ok_or_else(bad)?;+ (index, tr)+ } else {+ text.push_str(line.strip_prefix('\x03').unwrap_or(line));+ continue;+ };+ text.push_str(keys.get(index).ok_or_else(bad)?);+ text.push('\t');+ text.push_str(tr);+ next = index.saturating_add(1);+ if text.len() as u64 > MAX_CATALOG_BYTES {+ return Err(format!("over {MAX_CATALOG_BYTES} bytes"));+ }+ }+ Ok(text)+ }+/// The registry. English first: it is the fallback and the source language.-pub static LANGUAGES: [LangInfo; 18] = [+pub static LANGUAGES: [LangInfo; 20] = [LangInfo { code: "en", name: "English", source: b"", plural: plural_one_other, complete_menus: false, catalog: OnceLock::new() },LangInfo { code: "ja", name: "日本語", source: catalog!("ja"), plural: plural_none, complete_menus: true, catalog: OnceLock::new() },LangInfo { code: "zh-hans", name: "简体中文", source: catalog!("zh-hans"), plural: plural_none, complete_menus: true, catalog: OnceLock::new() },