From 1518dffbd1984fd7cfc2d15463d66f513324fd17 Mon Sep 17 00:00:00 2001 From: kirillDevPro <113171057+kirillDevPro@users.noreply.github.com> Date: Sat, 26 Sep 2026 07:12:31 +0200 Subject: [PATCH] docs(assets): correct the icon bundle docs The readme still called this package the Longbridge GPUI Component asset bundle, and the crate docs said WASM icons come from a CDN via web_sys::Request. The package is moon-ui-components-assets. Native builds embed the SVGs with RustEmbed. WASM load fetches icons/*.svg with reqwest from a caller-supplied endpoint. --- crates/moon-ui-components-assets/README.md | 23 ++++++++++++++++++-- crates/moon-ui-components-assets/src/lib.rs | 24 +++++++++++++-------- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/crates/moon-ui-components-assets/README.md b/crates/moon-ui-components-assets/README.md index 878057c..dec514f 100644 --- a/crates/moon-ui-components-assets/README.md +++ b/crates/moon-ui-components-assets/README.md @@ -1,6 +1,25 @@ -# GPUI Component Assets +# Moon UI component assets -The default assets bundle for [GPUI Component](https://github.com/longbridge/gpui-component). +Bundled SVG icons for Moon UI components. + +The Cargo package is `moon-ui-components-assets`. The Rust library name stays +`gpui_component_assets`, and the workspace depends on it as +`gpui-component-assets`. `moon-ui` re-exports `Assets` as `MoonAssets`. + +`build.rs` publishes the absolute path of `assets/icons` through the Cargo +`links` key `gpui-component-default-icons`. `moon-ui-components` reads that +path as `DEP_GPUI_COMPONENT_DEFAULT_ICONS_ICONS_DIR` and generates `IconName` +from the SVG files in that directory. + +On native targets, `Assets` embeds `assets/icons/**/*.svg` with RustEmbed and +implements `gpui::AssetSource`. It is a unit struct, so callers pass `Assets` +by value. `Assets::new` ignores its endpoint argument. + +On `wasm32`, the icons are not embedded. `Assets::new` stores the endpoint. +`load` downloads a path only when it starts with `icons/` and ends with +`.svg`, using `reqwest` against `{endpoint}/assets/{path}`, and keeps the +bytes in memory. Until that download finishes, `load` returns an error. The +sprite atlas does not store the failure, so a later paint calls `load` again. ## License diff --git a/crates/moon-ui-components-assets/src/lib.rs b/crates/moon-ui-components-assets/src/lib.rs index 2d92361..35467cd 100644 --- a/crates/moon-ui-components-assets/src/lib.rs +++ b/crates/moon-ui-components-assets/src/lib.rs @@ -1,23 +1,29 @@ -/// Embed application assets for GPUI Component. +/// Bundled SVG icons for Moon UI components. /// -/// This assets provides icons svg files for [IconName](https://docs.rs/gpui-component/latest/gpui_component/enum.IconName.html). +/// The Rust library name is `gpui_component_assets`. `moon-ui` re-exports +/// [`Assets`] as `MoonAssets`. `moon-ui-components` generates `IconName` from +/// `assets/icons` using the directory this crate's build script publishes. /// /// ## Usage /// +/// Native builds pass the unit struct straight through: +/// /// ```rust,no_run -/// use gpui::*; /// use gpui_component_assets::Assets; /// /// let app = gpui_platform::application().with_assets(Assets); /// ``` /// -/// ## Platform Differences +/// ## Platform differences /// -/// - **Native (Desktop)**: Icons are embedded in the binary using RustEmbed -/// - **WASM (Web)**: Icons are downloaded from CDN using web_sys::Request -/// - This significantly reduces WASM bundle size -/// - Icons are downloaded on-demand when first used -/// - Downloaded icons are cached in memory +/// - **Native**: `assets/icons/**/*.svg` is embedded with RustEmbed. +/// [`Assets::new`] ignores its endpoint. +/// - **WASM**: icons are not embedded. [`Assets::new`] stores an endpoint, and +/// `load` fetches a path with `reqwest` from `{endpoint}/assets/{path}` only +/// when that path starts with `icons/` and ends with `.svg`. The bytes are +/// cached in memory. Until the download finishes, `load` returns an error. +/// The sprite atlas does not keep that failure, so a later paint calls +/// `load` again. #[cfg(not(target_family = "wasm"))] mod native_assets;