bevy_react_core 0.7.0

The core bridge of bevy-react (drive bevy_ui from React over an embedded V8 runtime). Apps depend on the `bevy-react` crate.
#![cfg_attr(docsrs, feature(doc_cfg))]
// The crate's doc comments are written for contributors and deliberately link
// into private internals; those links resolve under
// `cargo doc --document-private-items`.
#![allow(rustdoc::private_intra_doc_links)]
//! Drive `bevy_ui` from a React app running on an embedded V8 (deno_core)
//! runtime. The bridge is deliberately tiny: two channels and two ops connect a
//! dedicated JS thread to Bevy.
//!
//! The public entry point is [`ReactUiPlugin`]: add it to your Bevy `App`,
//! pointing it at a built JS bundle, and the library owns the JS thread, the
//! op/event channels, the UI root, and (optionally) hot reload.
//!
//! ```no_run
//! use bevy::prelude::*;
//! use bevy_react_core::ReactUiPlugin;
//!
//! App::new()
//!     .add_plugins(DefaultPlugins)
//!     .add_plugins(ReactUiPlugin::new("path/to/dist/app.js"))
//!     .run();
//! ```
//!
//! The `protocol` and `js_thread` modules are exposed for advanced use (custom
//! integrations, headless tests); most users only need [`ReactUiPlugin`].
//!
//! Apps normally depend on the `bevy-react` crate instead: it re-exports this
//! crate at its root (every path here is `bevy_react::<same path>`) and adds
//! the element feature crates and the `ReactPlugins` group behind cargo
//! features.

// Let the `#[react_message]` macro's generated `::bevy_react_core::…` paths resolve
// inside this crate too (e.g. in our own tests and examples).
extern crate self as bevy_react_core;

mod bridge;
mod cursor;
// The devtools console ring (JS console output + diag messages + JS-runtime
// failures). Always declared — the op_log/diag call sites are unconditional —
// but the real ring only exists with the `devtools` feature on a native debug
// build; otherwise every fn is an inline no-op stub. `pub` (doc-hidden) so the
// `console_capture` integration test can poll it.
#[doc(hidden)]
pub mod console_log;
// Devtools diagnostics sinks (invalid style/prop values). Always declared —
// the protocol/apply call sites are unconditional — but its real implementation
// only exists with the `devtools` feature on a debug build; otherwise every fn
// is an inline no-op stub.
pub mod diag;
// The devtools inspector. A feature-gated module (not a separate
// crate — it needs `JsBridge` and friends, which stay private) that is fully
// compiled out unless the `devtools` cargo feature (a default feature) is on.
// Crate-internal: `ReactUiPlugin` auto-registers `DevtoolsPlugin` and exposes
// the only knob (`ReactUiPlugin::devtools`).
#[cfg(feature = "devtools")]
mod devtools;
mod event;
// The extension contract (feature-facing components, sets, registries).
pub mod element;
pub mod elements;
pub mod ext;
// Shared CPU-raster helpers (part of the contract).
mod gamepad;
mod host;
mod keyboard;
mod message;
mod names;
mod pick_clip;
mod plugin;
pub mod raster;
mod reconcile;
mod registry;
mod request;
mod scroll;
mod scrollbar;
mod shared_tags;
pub mod style;
mod style_bindings;
mod touch_scroll;
// The transition engine. Public for its primitives (`Channel`,
// `ChannelTransition`) that a feature crate eases its own values with.
pub mod transition;
mod ts_codegen;
mod ui_map;
mod window;

// The native JS host (embedded V8 / deno_core on a dedicated thread). Exposed for
// advanced use (custom integrations, headless tests). The web target has no such
// thread — React runs in the browser's own engine — so this module is absent there.
#[cfg(not(target_arch = "wasm32"))]
pub mod js_thread;
pub mod protocol;

// Filter wire types (the layer-based `filter` chain) and, later, the filter
// registry. Owns its wire format the way `animations` owns its own.
pub mod filters;

// The animation engine and the render-target service (`<portal>` views,
// `backgroundImage: { texture }`). Public
// modules so consumers can reach their full APIs; the most-used items are also
// re-exported at the crate root below.
pub mod animations;
pub mod background_image;
pub mod image_rendering;
pub mod layer;
pub mod render_target;
// The SVG subsystem (parse + CPU rasterization via resvg/tiny-skia).
pub mod svg;

/// The dependencies the `#[react_*]` macros' expansions name, so a caller
/// needs only bevy-react (the facade re-exports this module unchanged). Not
/// an API.
#[doc(hidden)]
pub mod __private {
    pub use bevy;
    pub use serde;
    pub use ts_rs;
}

pub use animations::ReactUiAnimationsPlugin;
pub use bevy_react_macros::{
    react_event, react_filter, react_message, react_morph_filter, react_request,
};

/// The headless op harness for a feature crate's own tests (`test_util`
/// feature): the op app, op builders, the bridge, and the engine hooks the
/// core's own tests use. Unstable — a dev-dependency surface, not an API.
#[cfg(any(test, feature = "test_util"))]
#[doc(hidden)]
pub mod test_util {
    pub use crate::bridge::{JsBridge, PointerHandlers};
    pub use crate::diag::{arm_runtime, take_decode_warnings, take_runtime_warnings, test_lock};
    pub use crate::plugin::Fonts;
    pub use crate::reconcile::test_util::*;
    pub use crate::reconcile::{OpApplyStats, apply_js_ops, collect_ui_events};
    pub use crate::ui_map::AtlasLayoutCache;

    use crate::animations::{Driver, SharedId, SharedValues};

    /// The animation engine's apply system, for a schedule that runs it
    /// without the plugin (a feature's publish→consume ordering test).
    pub fn animation_apply()
    -> bevy::ecs::schedule::ScheduleConfigs<bevy::ecs::system::ScheduleSystem> {
        use bevy::ecs::schedule::IntoScheduleConfigs;
        crate::animations::apply_animated_nodes.into_configs()
    }

    /// Shared-value mutators (the `op_animate` command path, minus the op).
    pub fn shared_declare(values: &mut SharedValues, id: SharedId, initial: f32) {
        values.declare(id, initial);
    }
    pub fn shared_set(values: &mut SharedValues, id: SharedId, value: f32) {
        values.set(id, value);
    }
    pub fn shared_animate(
        values: &mut SharedValues,
        id: SharedId,
        driver: &Driver,
        token: Option<u64>,
    ) {
        values.animate(id, driver, token);
    }
    pub fn shared_tick(values: &mut SharedValues, dt: f32) {
        values.tick(dt);
    }
}
pub use bridge::ReactNode;
#[cfg(feature = "devtools")]
#[cfg_attr(docsrs, doc(cfg(feature = "devtools")))]
pub use devtools::DevtoolsConfig;
pub use event::{ReactEvent, ReactEvents};
pub use filters::{ReactFilter, ReactMorphFilter};
pub use message::{ReactAppExt, ReactMessage, ReactPayload};
pub use names::ReactNodes;
pub use plugin::{
    FilterSelection, Fonts, PointerCapture, PointerCaptureSet, PrecompileFilters, ReactApplySet,
    ReactUiPlugin,
};
pub use reconcile::OpApplyStats;
pub use render_target::{
    PortalCamera, RenderMode, RenderTarget, RenderTargetSpec, RenderTargets, Resolution,
};
pub use request::{RawRequest, ReactRequest, Request, RequestEvent, Responder};
pub use scrollbar::{
    HorizontalEdge, ScrollbarConfig, ScrollbarPartStyle, ScrollbarPosition, ScrollbarSpec,
    VerticalEdge,
};