Skip to main content

bevy_react/
lib.rs

1#![cfg_attr(docsrs, feature(doc_cfg))]
2//! Drive `bevy_ui` from a React app running on an embedded V8 (deno_core)
3//! runtime. The bridge is deliberately tiny: two channels and two ops connect a
4//! dedicated JS thread to Bevy.
5//!
6//! The public entry point is [`ReactUiPlugin`]: add it to your Bevy `App`,
7//! pointing it at a built JS bundle, and the library owns the JS thread, the
8//! op/event channels, the UI root, and (optionally) hot reload.
9//!
10//! ```no_run
11//! use bevy::prelude::*;
12//! use bevy_react::ReactUiPlugin;
13//!
14//! App::new()
15//!     .add_plugins(DefaultPlugins)
16//!     .add_plugins(ReactUiPlugin::new("path/to/dist/app.js"))
17//!     .run();
18//! ```
19//!
20//! The `protocol` and `js_thread` modules are exposed for advanced use (custom
21//! integrations, headless tests); most users only need [`ReactUiPlugin`].
22
23// Let the `#[react_message]` macro's generated `::bevy_react::…` paths resolve
24// inside this crate too (e.g. in our own tests and examples).
25extern crate self as bevy_react;
26
27mod anchor;
28mod bridge;
29mod cursor;
30// The devtools console ring (JS console output + diag messages + JS-runtime
31// failures). Always declared — the op_log/diag call sites are unconditional —
32// but the real ring only exists with the `devtools` feature on a native debug
33// build; otherwise every fn is an inline no-op stub. `pub` (doc-hidden) so the
34// `console_capture` integration test can poll it.
35#[doc(hidden)]
36pub mod console_log;
37// Devtools diagnostics sinks (invalid style/prop values). Always declared —
38// the protocol/apply call sites are unconditional — but its real implementation
39// only exists with the `devtools` feature on a debug build; otherwise every fn
40// is an inline no-op stub.
41mod diag;
42// The devtools inspector. A feature-gated module (not a separate
43// crate — it needs `JsBridge` and friends, which stay private) that is fully
44// compiled out unless the `devtools` cargo feature (a default feature) is on.
45// Crate-internal: `ReactUiPlugin` auto-registers `DevtoolsPlugin` and exposes
46// the only knob (`ReactUiPlugin::devtools`).
47#[cfg(feature = "devtools")]
48mod devtools;
49mod event;
50mod gamepad;
51mod host;
52mod keyboard;
53mod message;
54mod pick_clip;
55mod plugin;
56mod reconcile;
57mod registry;
58mod request;
59mod scroll;
60mod scrollbar;
61mod style_bindings;
62mod transition;
63mod ts_codegen;
64mod ui_map;
65mod window;
66
67// The native JS host (embedded V8 / deno_core on a dedicated thread). Exposed for
68// advanced use (custom integrations, headless tests). The web target has no such
69// thread — React runs in the browser's own engine — so this module is absent there.
70#[cfg(not(target_arch = "wasm32"))]
71pub mod js_thread;
72pub mod protocol;
73
74// Filter wire types (the layer-based `filter` chain) and, later, the filter
75// registry. Owns its wire format the way `canvas`/`animations` own theirs.
76pub mod filters;
77
78// The animation engine and the canvas/portal/surface host elements. Public
79// modules so consumers can reach their full APIs; the most-used items are also
80// re-exported at the crate root below.
81pub mod animations;
82pub mod background_image;
83pub mod canvas;
84pub mod layer;
85pub mod portal;
86pub mod surface;
87// The SVG subsystem (parse + CPU rasterization via resvg/tiny-skia).
88pub mod svg;
89
90pub use anchor::{Anchor, AnchorScaling, Anchored};
91pub use animations::ReactUiAnimationsPlugin;
92pub use bevy_react_macros::{react_event, react_filter, react_message, react_request};
93pub use canvas::CanvasSurface;
94#[cfg(feature = "devtools")]
95#[cfg_attr(docsrs, doc(cfg(feature = "devtools")))]
96pub use devtools::DevtoolsConfig;
97pub use event::{ReactEvent, ReactEvents};
98pub use filters::ReactFilter;
99pub use message::{ReactAppExt, ReactMessage, ReactPayload};
100pub use plugin::{Fonts, PointerCapture, PointerCaptureSet, ReactUiPlugin};
101pub use portal::{
102    PortalCamera, RenderMode, RenderTarget, RenderTargetSpec, RenderTargets, Resolution,
103};
104pub use reconcile::OpApplyStats;
105pub use request::{RawRequest, ReactRequest, Request, RequestEvent, Responder};
106pub use scrollbar::{
107    HorizontalEdge, ScrollbarConfig, ScrollbarPartStyle, ScrollbarPosition, ScrollbarSpec,
108    VerticalEdge,
109};
110pub use surface::{SurfacePointer, SurfaceSpec, SurfaceVirtualPointer, Surfaces, UvChannel};