Skip to content

Commit

Permalink
Try to replace feature not_browser_env instead of browser_env.
Browse files Browse the repository at this point in the history
  • Loading branch information
langyo committed Aug 14, 2024
1 parent 36bdc28 commit e629363
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 36 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/everything.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
uses: Swatinem/rust-cache@v2

- name: Run cargo clippy
run: cargo clippy --all --all-features
run: cargo clippy --all --features parser,yew_integration,yew_use_media_query,yew_use_style,ssr,hydration
env:
RUSTFLAGS: '--cfg releasing'

Expand Down Expand Up @@ -67,7 +67,7 @@ jobs:

- name: Run cargo test
run: |
cargo test -p stylist --features debug_style_locations,parser,yew_integration,yew_use_media_query,yew_use_style,ssr,hydration
cargo test -p stylist --all-features
cargo test -p stylist-core --all-features
cargo test -p stylist-macros --all-features
env:
Expand Down Expand Up @@ -95,7 +95,7 @@ jobs:
version: 'latest'

- name: Build WASM
run: cargo build --all --target=wasm32-unknown-unknown --features browser_env
run: cargo build --all --target=wasm32-unknown-unknown
env:
RUSTFLAGS: '--cfg releasing'

Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ This is a fork of [css-in-rust](https://github.com/lukidoescode/css-in-rust).
Add the following to your `Cargo.toml` if you want to use it in a browser environment:

```toml
stylist = { version = "0.13", feature = ["browser_env"]}
stylist = "0.13"
```

Maybe you want to use `yew` integration:

```toml
stylist = { version = "0.13", features = ["browser_env", "yew_integration"]}
stylist = { version = "0.13", features = ["yew_integration"]}
```

If you want to render styles on the server side, use `ssr` and `hydration` features:
Expand All @@ -29,6 +29,12 @@ If you want to render styles on the server side, use `ssr` and `hydration` featu
stylist = { version = "0.13", features = ["yew_integration", "ssr", "hydration"]}
```

If you want to run inside a non-web WASM environment, such as [Cloudflare Worker](https://workers.cloudflare.com), use `not_browser_env` feature:

```toml
stylist = { version = "0.13", features = ["not_browser_env"]}
```

## Usage

For detailed usage, please see
Expand Down
1 change: 0 additions & 1 deletion examples/benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ log = "0.4.17"
console_log = { version = "1.0.0", features = ["color"] }
yew = { version = "0.21", features = ["csr"] }
stylist = { path = "../../packages/stylist", features = [
"browser_env",
"yew_integration",
"parser",
] }
Expand Down
1 change: 0 additions & 1 deletion examples/use-media-query/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ log = "0.4.17"
console_log = { version = "1.0.0", features = ["color"] }
yew = { version = "0.21", features = ["csr"] }
stylist = { path = "../../packages/stylist", features = [
"browser_env",
"yew_integration",
"yew_use_media_query",
] }
Expand Down
5 changes: 1 addition & 4 deletions examples/yew-integration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ publish = false
log = "0.4.17"
console_log = { version = "1.0.0", features = ["color"] }
yew = { version = "0.21", features = ["csr"] }
stylist = { path = "../../packages/stylist", features = [
"browser_env",
"yew_integration",
] }
stylist = { path = "../../packages/stylist", features = ["yew_integration"] }

[dev-dependencies]
gloo-utils = "0.2.0"
Expand Down
1 change: 0 additions & 1 deletion examples/yew-proc-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ log = "0.4.17"
console_log = { version = "1.0.0", features = ["color"] }
yew = { version = "0.21", features = ["csr"] }
stylist = { path = "../../packages/stylist", default-features = false, features = [
"browser_env",
"yew_integration",
"macros",
] }
Expand Down
5 changes: 1 addition & 4 deletions examples/yew-shadow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ publish = false
log = "0.4.17"
console_log = { version = "1.0.0", features = ["color"] }
yew = { version = "0.21", features = ["csr"] }
stylist = { path = "../../packages/stylist", features = [
"browser_env",
"yew_integration",
] }
stylist = { path = "../../packages/stylist", features = ["yew_integration"] }
once_cell = "1.16.0"

[dependencies.web-sys]
Expand Down
5 changes: 1 addition & 4 deletions examples/yew-theme-context/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ publish = false
log = "0.4.17"
console_log = { version = "1.0.0", features = ["color"] }
yew = { version = "0.21", features = ["csr"] }
stylist = { path = "../../packages/stylist", features = [
"browser_env",
"yew_integration",
] }
stylist = { path = "../../packages/stylist", features = ["yew_integration"] }
once_cell = "1.16.0"

[dev-dependencies]
Expand Down
1 change: 0 additions & 1 deletion examples/yew-theme-hooks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ log = "0.4.17"
console_log = { version = "1.0.0", features = ["color"] }
yew = { version = "0.21", features = ["csr"] }
stylist = { path = "../../packages/stylist", features = [
"browser_env",
"yew_integration",
"yew_use_style",
] }
Expand Down
3 changes: 1 addition & 2 deletions packages/stylist/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ features = [
"HtmlHeadElement",
"HtmlStyleElement",
]
optional = true

[dev-dependencies]
log = "0.4.17"
Expand All @@ -58,7 +57,7 @@ debug_style_locations = []
macros = ["stylist-macros"]
random = ["dep:fastrand", "dep:instant"]

browser_env = ["dep:web-sys"]
not_browser_env = []
parser = ["stylist-core/parser"]
yew_integration = ["dep:yew", "yew_use_media_query", "yew_use_style"]
yew_use_media_query = ["dep:yew", "dep:gloo-events", "web-sys/MediaQueryList"]
Expand Down
2 changes: 1 addition & 1 deletion packages/stylist/src/arch.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg(feature = "browser_env")]
#![cfg(not(feature = "not_browser_env"))]

use crate::{Error, Result};
use web_sys::{Document, HtmlHeadElement, Window};
Expand Down
7 changes: 2 additions & 5 deletions packages/stylist/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@
//! - `macros`: Enabled by default, this flag enables procedural macro support.
//! - `random`: Enabled by default, this flag uses `fastrand` crate to generate a random class name.
//! Disabling this flag will opt for a class name that is counter-based.
//! - `browser_env`: **Disabled by default**, this flag enables browser-specific APIs. Only enable
//! this if you are running in a browser environment.
//! - `not_browser_env`: Disabled by default, this flag will avoid using browser-specific APIs. This
//! is useful for testing and server-side rendering by WASM.
//! - `parser`: Disabled by default, this flag enables runtime parsing of styles from strings. You
//! don't need to enable this to generate styles via the macros.
//! - `yew_integration`: This flag enables yew integration, which implements
Expand All @@ -108,9 +108,6 @@
//! - `ssr`: Disabled by default, this flag enables Server-side Rendering Support.
//! - `hydration`: Disabled by default, this flag enables Server-side Rendering Hydration Support.
#[cfg(all(feature = "browser_env", target_os = "wasi"))]
compile_error!("The `browser_env` feature is not supported on WASI.");

#[cfg(feature = "yew_use_media_query")]
mod arch;
pub mod ast;
Expand Down
10 changes: 5 additions & 5 deletions packages/stylist/src/manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl StyleManagerBuilder {
/// Build the [`StyleManager`].
#[allow(unused_mut)]
pub fn build(mut self) -> Result<StyleManager> {
#[cfg(feature = "browser_env")]
#[cfg(not(feature = "not_browser_env"))]
if self.container.is_none() {
use crate::arch::doc_head;
self.container = Some(doc_head()?.into());
Expand Down Expand Up @@ -221,7 +221,7 @@ impl StyleManager {
#[cfg(all(
target_arch = "wasm32",
not(target_os = "wasi"),
feature = "browser_env"
not(feature = "not_browser_env")
))]
pub(crate) fn mount(&self, content: &StyleContent) -> Result<()> {
use crate::arch::document;
Expand Down Expand Up @@ -252,7 +252,7 @@ impl StyleManager {
#[cfg(all(
target_arch = "wasm32",
not(target_os = "wasi"),
feature = "browser_env"
not(feature = "not_browser_env")
))]
pub(crate) fn unmount(id: &StyleId) -> Result<()> {
use crate::arch::document;
Expand All @@ -275,7 +275,7 @@ impl StyleManager {
#[cfg(any(
not(target_arch = "wasm32"),
target_os = "wasi",
not(feature = "browser_env")
feature = "not_browser_env"
))]
#[allow(unused_variables)]
pub(crate) fn mount(&self, content: &StyleContent) -> Result<()> {
Expand All @@ -287,7 +287,7 @@ impl StyleManager {
#[cfg(any(
not(target_arch = "wasm32"),
target_os = "wasi",
not(feature = "browser_env")
feature = "not_browser_env"
))]
#[allow(unused_variables)]
pub(crate) fn unmount(id: &StyleId) -> Result<()> {
Expand Down
4 changes: 2 additions & 2 deletions packages/stylist/src/yew/hooks/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#[cfg(all(feature = "yew_use_media_query", feature = "browser_env"))]
#[cfg(all(feature = "yew_use_media_query", not(feature = "not_browser_env")))]
mod use_media_query;

#[cfg(feature = "yew_use_style")]
mod use_style;

#[cfg(all(feature = "yew_use_media_query", feature = "browser_env"))]
#[cfg(all(feature = "yew_use_media_query", not(feature = "not_browser_env")))]
pub use use_media_query::{use_media_query, use_prepared_media_query};

#[cfg(feature = "yew_use_style")]
Expand Down

0 comments on commit e629363

Please sign in to comment.