feat: studio.theme.solarized v0.1.0 builds against SDK
Promotes the skeleton to a real WASM plugin component. The 22 KiB stripped artefact at target/wasm32-wasip2/release/studio_theme_solarized.wasm is the proof-of-contract for fai-studio-plugin-sdk v0.1. Implements: - theme::Guest::theme_for(brightness) returning the pinned Solarized Light/Dark palettes (14 ARGB tokens each). Brightness names other than "light"/"dark" return PluginError::Declined. - translate::Guest + output_view::Guest as Declined-only stubs — v0.1 of the SDK requires all three hooks per plugin; v0.2 will split the WIT. Cargo.toml pins edition 2021 (matches SDK; wit-bindgen 0.36 codegen does not yet support edition 2024). Signed-off-by: flemming-it <sf@flemming.it>
This commit is contained in:
parent
a1f8412205
commit
6817752ae3
5 changed files with 520 additions and 105 deletions
120
src/lib.rs
120
src/lib.rs
|
|
@ -1,24 +1,23 @@
|
|||
//! `studio.theme.solarized` — first Studio plugin.
|
||||
//!
|
||||
//! Ships Ethan Schoonover's Solarized palette as a Material 3
|
||||
//! ColorScheme pair (light + dark).
|
||||
//! ColorScheme pair (light + dark) through the WIT `theme`
|
||||
//! export.
|
||||
//!
|
||||
//! SKELETON: this file does not yet compile. The
|
||||
//! `#[plugin(theme)]` macro and the `studio_plugin` runtime live
|
||||
//! in `fai-studio-plugin-sdk`, which is documented in
|
||||
//! `docs/advanced/studio-plugin-sdk.md` but not yet implemented.
|
||||
//! Once the SDK ships, switching the file from skeleton to
|
||||
//! buildable is a matter of uncommenting the dependency in
|
||||
//! Cargo.toml and the use-line below.
|
||||
//!
|
||||
//! Why ship the skeleton now: pins the palette so the in-tree
|
||||
//! reference plugin doesn't bike-shed at SDK-integration time,
|
||||
//! and gives the SDK author a concrete consumer to validate
|
||||
//! their generated macro output against.
|
||||
//! This is the proof-of-contract plugin for the
|
||||
//! `fai-studio-plugin-sdk` v0.1 shape: one struct, one
|
||||
//! `Guest` impl, one `export_plugin!` invocation.
|
||||
|
||||
#![allow(dead_code, unused_imports)]
|
||||
#![allow(clippy::result_large_err)]
|
||||
|
||||
// use fai_studio_plugin_sdk::{plugin, theme, ColorScheme};
|
||||
use fai_studio_plugin_sdk::{bindings, export_plugin};
|
||||
|
||||
// Type aliases against the SDK's bindings so the impl block
|
||||
// reads cleanly. Once the SDK v0.2 ships proper re-exports +
|
||||
// world-per-hook, these collapse to a single `use` line.
|
||||
type ColorScheme = bindings::fai::studio_plugin::plugin_types::ColorScheme;
|
||||
type PluginError = bindings::fai::studio_plugin::plugin_types::PluginError;
|
||||
type RenderedOutput = bindings::fai::studio_plugin::plugin_types::RenderedOutput;
|
||||
|
||||
/// 14 ARGB tokens, Material 3 order:
|
||||
/// primary, on_primary, secondary, on_secondary,
|
||||
|
|
@ -26,8 +25,8 @@
|
|||
/// surface, on_surface, surface_variant, on_surface_variant,
|
||||
/// outline, outline_variant.
|
||||
///
|
||||
/// Studio merges any missing slot (we send all 14, so none) with
|
||||
/// its built-in fallback before applying.
|
||||
/// Studio merges any missing slot (we send all 14, so none)
|
||||
/// with its built-in fallback before applying.
|
||||
const SOLARIZED_LIGHT: [u32; 14] = [
|
||||
0xFF268BD2, // primary — solarized blue
|
||||
0xFFFDF6E3, // on_primary — base3
|
||||
|
|
@ -62,45 +61,54 @@ const SOLARIZED_DARK: [u32; 14] = [
|
|||
0xFF073642, // outline_variant — base02
|
||||
];
|
||||
|
||||
// ─────────────────────────────────────────────────────────────
|
||||
// Forward-reference: this is the shape the SDK will generate
|
||||
// from `#[plugin(theme)]`. Once the SDK exists, the body collapses
|
||||
// to a return of `Ok(ColorScheme { brightness, tokens: … })`.
|
||||
// ─────────────────────────────────────────────────────────────
|
||||
//
|
||||
// #[plugin(theme)]
|
||||
// fn theme_for(brightness: &str) -> theme::Result {
|
||||
// let tokens = match brightness {
|
||||
// "light" => SOLARIZED_LIGHT.to_vec(),
|
||||
// "dark" => SOLARIZED_DARK.to_vec(),
|
||||
// other => {
|
||||
// return Err(theme::Error::declined(format!(
|
||||
// "solarized has no scheme for brightness '{other}'",
|
||||
// )))
|
||||
// }
|
||||
// };
|
||||
// Ok(ColorScheme {
|
||||
// brightness: brightness.to_string(),
|
||||
// tokens,
|
||||
// })
|
||||
// }
|
||||
/// The plugin component. Holds no state — every theme-for
|
||||
/// call computes from the brightness arg alone.
|
||||
struct SolarizedPlugin;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn palette_has_14_tokens() {
|
||||
assert_eq!(SOLARIZED_LIGHT.len(), 14);
|
||||
assert_eq!(SOLARIZED_DARK.len(), 14);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn solarized_blue_is_the_primary_in_both_modes() {
|
||||
// Ethan Schoonover's blue is the brand colour of
|
||||
// Solarized. Sanity-check we kept it as the primary in
|
||||
// both schemes.
|
||||
assert_eq!(SOLARIZED_LIGHT[0], 0xFF268BD2);
|
||||
assert_eq!(SOLARIZED_DARK[0], 0xFF268BD2);
|
||||
impl bindings::exports::fai::studio_plugin::theme::Guest for SolarizedPlugin {
|
||||
fn theme_for(brightness: String) -> Result<ColorScheme, PluginError> {
|
||||
let tokens = match brightness.as_str() {
|
||||
"light" => SOLARIZED_LIGHT.to_vec(),
|
||||
"dark" => SOLARIZED_DARK.to_vec(),
|
||||
other => {
|
||||
return Err(PluginError::Declined(format!(
|
||||
"solarized has no scheme for brightness '{other}' \
|
||||
(supported: light, dark)"
|
||||
)));
|
||||
}
|
||||
};
|
||||
Ok(ColorScheme { brightness, tokens })
|
||||
}
|
||||
}
|
||||
|
||||
// SDK v0.1 wraps all three hooks in a single WIT world, so a
|
||||
// plugin that only really cares about `theme` still has to
|
||||
// declare empty / declined impls for the other two. v0.2 will
|
||||
// split the WIT into one world per hook; until then these
|
||||
// `declined` returns are the right answer — Studio falls back
|
||||
// to its built-in renderer or to the [EN] badge.
|
||||
|
||||
impl bindings::exports::fai::studio_plugin::translate::Guest for SolarizedPlugin {
|
||||
fn translate(
|
||||
_text: String,
|
||||
_from_locale: String,
|
||||
_to_locale: String,
|
||||
) -> Result<String, PluginError> {
|
||||
Err(PluginError::Declined(
|
||||
"solarized is a theme plugin and does not translate".to_string(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl bindings::exports::fai::studio_plugin::output_view::Guest for SolarizedPlugin {
|
||||
fn render(
|
||||
_mime_type: String,
|
||||
_data: Vec<u8>,
|
||||
) -> Result<RenderedOutput, PluginError> {
|
||||
Err(PluginError::Declined(
|
||||
"solarized is a theme plugin and does not render outputs".to_string(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
export_plugin!(SolarizedPlugin);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue