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 host;
51mod keyboard;
52mod message;
53mod pick_clip;
54mod plugin;
55mod reconcile;
56mod registry;
57mod request;
58mod scroll;
59mod scrollbar;
60mod style_bindings;
61mod transition;
62mod ts_codegen;
63mod ui_map;
64mod window;
65
66// The native JS host (embedded V8 / deno_core on a dedicated thread). Exposed for
67// advanced use (custom integrations, headless tests). The web target has no such
68// thread — React runs in the browser's own engine — so this module is absent there.
69#[cfg(not(target_arch = "wasm32"))]
70pub mod js_thread;
71pub mod protocol;
72
73// Filter wire types (the layer-based `filter` chain) and, later, the filter
74// registry. Owns its wire format the way `canvas`/`animations` own theirs.
75pub mod filters;
76
77// The animation engine and the canvas/portal/surface host elements. Public
78// modules so consumers can reach their full APIs; the most-used items are also
79// re-exported at the crate root below.
80pub mod animations;
81pub mod canvas;
82pub mod layer;
83pub mod portal;
84pub mod surface;
85
86pub use anchor::{Anchor, AnchorScaling, Anchored};
87pub use animations::ReactUiAnimationsPlugin;
88pub use bevy_react_macros::{react_event, react_filter, react_message, react_request};
89pub use canvas::CanvasSurface;
90#[cfg(feature = "devtools")]
91#[cfg_attr(docsrs, doc(cfg(feature = "devtools")))]
92pub use devtools::DevtoolsConfig;
93pub use event::{ReactEvent, ReactEvents};
94pub use filters::ReactFilter;
95pub use message::{ReactAppExt, ReactMessage, ReactPayload};
96pub use plugin::{Fonts, PointerCapture, PointerCaptureSet, ReactUiPlugin};
97pub use portal::{
98 PortalCamera, RenderMode, RenderTarget, RenderTargetSpec, RenderTargets, Resolution,
99};
100pub use reconcile::OpApplyStats;
101pub use request::{RawRequest, ReactRequest, Request, RequestEvent, Responder};
102pub use scrollbar::{
103 HorizontalEdge, ScrollbarConfig, ScrollbarPartStyle, ScrollbarPosition, ScrollbarSpec,
104 VerticalEdge,
105};
106pub use surface::{SurfacePointer, SurfaceSpec, SurfaceVirtualPointer, Surfaces, UvChannel};