diff --git a/Cargo.lock b/Cargo.lock index 9ebd073cb..f354c008c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4244,10 +4244,9 @@ dependencies = [ [[package]] name = "const-serialize" -version = "0.8.0" +version = "0.8.0-alpha.0" dependencies = [ "const-serialize 0.7.2", - "const-serialize 0.8.0", "const-serialize-macro 0.8.0-alpha.0", "rand 0.9.2", "serde", @@ -5204,7 +5203,7 @@ dependencies = [ [[package]] name = "depinfo" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "thiserror 2.0.17", ] @@ -5377,7 +5376,7 @@ dependencies = [ [[package]] name = "dioxus" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "criterion", "dioxus", @@ -5419,7 +5418,7 @@ dependencies = [ [[package]] name = "dioxus-asset-resolver" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "dioxus", "dioxus-cli-config", @@ -5440,7 +5439,7 @@ dependencies = [ [[package]] name = "dioxus-autofmt" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "dioxus-rsx", "pretty_assertions", @@ -5454,7 +5453,7 @@ dependencies = [ [[package]] name = "dioxus-check" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "indoc", "owo-colors", @@ -5466,7 +5465,7 @@ dependencies = [ [[package]] name = "dioxus-cli" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "ansi-to-html", "ansi-to-tui", @@ -5487,7 +5486,7 @@ dependencies = [ "console 0.16.2", "console-subscriber", "const-serialize 0.7.2", - "const-serialize 0.8.0", + "const-serialize 0.8.0-alpha.0", "convert_case 0.8.0", "crossterm 0.29.0", "ctrlc", @@ -5531,8 +5530,8 @@ dependencies = [ "local-ip-address", "log", "manganis", - "manganis-core 0.7.2", - "manganis-core 0.7.3-alpha.0", + "manganis-core", + "manganis-core-07", "memmap", "memoize", "notify", @@ -5591,26 +5590,26 @@ dependencies = [ [[package]] name = "dioxus-cli-config" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "wasm-bindgen", ] [[package]] name = "dioxus-cli-opt" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "anyhow", "browserslist-rs 0.19.0", "built 0.8.0", "codemap", - "const-serialize 0.8.0", + "const-serialize 0.8.0-alpha.0", "grass", "image", "imagequant", "lightningcss", "manganis", - "manganis-core 0.7.3-alpha.0", + "manganis-core", "mozjpeg", "object 0.37.3", "png", @@ -5655,7 +5654,7 @@ dependencies = [ [[package]] name = "dioxus-cli-telemetry" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "chrono", "dirs 6.0.0", @@ -5667,7 +5666,7 @@ dependencies = [ [[package]] name = "dioxus-component-manifest" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "schemars 1.2.0", "serde", @@ -5676,7 +5675,7 @@ dependencies = [ [[package]] name = "dioxus-config-macro" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "proc-macro2", "quote", @@ -5684,11 +5683,11 @@ dependencies = [ [[package]] name = "dioxus-config-macros" -version = "0.7.3-alpha.0" +version = "0.7.3" [[package]] name = "dioxus-core" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "anyhow", "const_format", @@ -5719,7 +5718,7 @@ dependencies = [ [[package]] name = "dioxus-core-macro" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "convert_case 0.8.0", "dioxus", @@ -5735,11 +5734,11 @@ dependencies = [ [[package]] name = "dioxus-core-types" -version = "0.7.3-alpha.0" +version = "0.7.3" [[package]] name = "dioxus-desktop" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "async-trait", "base64 0.22.1", @@ -5798,7 +5797,7 @@ dependencies = [ [[package]] name = "dioxus-devtools" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "dioxus-cli-config", "dioxus-core", @@ -5817,7 +5816,7 @@ dependencies = [ [[package]] name = "dioxus-devtools-types" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "dioxus-core", "serde", @@ -5826,7 +5825,7 @@ dependencies = [ [[package]] name = "dioxus-document" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "dioxus", "dioxus-core", @@ -5844,10 +5843,10 @@ dependencies = [ [[package]] name = "dioxus-dx-wire-format" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "cargo_metadata", - "manganis-core 0.7.3-alpha.0", + "manganis-core", "serde", "serde_json", "subsecond-types", @@ -5893,7 +5892,7 @@ dependencies = [ [[package]] name = "dioxus-ext" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "dioxus-autofmt", "dioxus-rsx-rosetta", @@ -5904,7 +5903,7 @@ dependencies = [ [[package]] name = "dioxus-fullstack" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "anyhow", "async-stream", @@ -5971,7 +5970,7 @@ dependencies = [ [[package]] name = "dioxus-fullstack-core" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "anyhow", "axum-core 0.5.6", @@ -5999,7 +5998,7 @@ dependencies = [ [[package]] name = "dioxus-fullstack-macro" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "axum 0.8.8", "const_format", @@ -6015,7 +6014,7 @@ dependencies = [ [[package]] name = "dioxus-history" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "dioxus", "dioxus-core", @@ -6024,7 +6023,7 @@ dependencies = [ [[package]] name = "dioxus-hooks" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "dioxus", "dioxus-core", @@ -6042,7 +6041,7 @@ dependencies = [ [[package]] name = "dioxus-html" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "async-trait", "bytes", @@ -6073,7 +6072,7 @@ dependencies = [ [[package]] name = "dioxus-html-internal-macro" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "convert_case 0.8.0", "proc-macro2", @@ -6084,7 +6083,7 @@ dependencies = [ [[package]] name = "dioxus-interpreter-js" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "dioxus-core", "dioxus-core-types", @@ -6102,7 +6101,7 @@ dependencies = [ [[package]] name = "dioxus-liveview" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "axum 0.8.8", "dioxus", @@ -6130,7 +6129,7 @@ dependencies = [ [[package]] name = "dioxus-logger" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "dioxus", "dioxus-cli-config", @@ -6141,7 +6140,7 @@ dependencies = [ [[package]] name = "dioxus-native" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "anyrender", "anyrender_vello", @@ -6176,7 +6175,7 @@ dependencies = [ [[package]] name = "dioxus-native-dom" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "blitz-dom", "blitz-traits", @@ -6301,7 +6300,7 @@ dependencies = [ [[package]] name = "dioxus-router" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "axum 0.8.8", "base64 0.22.1", @@ -6329,7 +6328,7 @@ dependencies = [ [[package]] name = "dioxus-router-macro" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "base16", "digest", @@ -6343,7 +6342,7 @@ dependencies = [ [[package]] name = "dioxus-rsx" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "prettier-please", "prettyplease", @@ -6356,7 +6355,7 @@ dependencies = [ [[package]] name = "dioxus-rsx-hotreload" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "dioxus-core", "dioxus-core-types", @@ -6371,7 +6370,7 @@ dependencies = [ [[package]] name = "dioxus-rsx-rosetta" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "convert_case 0.8.0", "dioxus-autofmt", @@ -6387,7 +6386,7 @@ dependencies = [ [[package]] name = "dioxus-server" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "anyhow", "async-trait", @@ -6449,7 +6448,7 @@ dependencies = [ [[package]] name = "dioxus-signals" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "dioxus", "dioxus-core", @@ -6469,7 +6468,7 @@ dependencies = [ [[package]] name = "dioxus-ssr" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "askama_escape", "dioxus", @@ -6480,7 +6479,7 @@ dependencies = [ [[package]] name = "dioxus-stores" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "dioxus", "dioxus-core", @@ -6491,7 +6490,7 @@ dependencies = [ [[package]] name = "dioxus-stores-macro" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "convert_case 0.8.0", "dioxus", @@ -6511,7 +6510,7 @@ dependencies = [ [[package]] name = "dioxus-web" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "ciborium", "dioxus", @@ -7872,7 +7871,7 @@ dependencies = [ [[package]] name = "generational-box" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "criterion", "parking_lot", @@ -10528,7 +10527,7 @@ dependencies = [ [[package]] name = "lazy-js-bundle" -version = "0.7.3-alpha.0" +version = "0.7.3" [[package]] name = "lazy_static" @@ -11014,30 +11013,20 @@ dependencies = [ [[package]] name = "manganis" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "const-serialize 0.7.2", - "const-serialize 0.8.0", - "manganis-core 0.7.3-alpha.0", + "const-serialize 0.8.0-alpha.0", + "manganis-core", "manganis-macro", ] [[package]] name = "manganis-core" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88d071660b149f985cbab8b23f2004ea6dd5cf947b63a0843f0e2f46e6af7229" +version = "0.7.3" dependencies = [ "const-serialize 0.7.2", - "serde", -] - -[[package]] -name = "manganis-core" -version = "0.7.3-alpha.0" -dependencies = [ - "const-serialize 0.7.2", - "const-serialize 0.8.0", + "const-serialize 0.8.0-alpha.0", "dioxus-cli-config", "dioxus-core-types", "manganis", @@ -11045,14 +11034,22 @@ dependencies = [ "winnow 0.7.14", ] +[[package]] +name = "manganis-core-07" +version = "0.7.2" +dependencies = [ + "const-serialize 0.7.2", + "serde", +] + [[package]] name = "manganis-macro" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "dunce", "macro-string", "manganis", - "manganis-core 0.7.3-alpha.0", + "manganis-core", "proc-macro2", "quote", "syn 2.0.114", @@ -16225,7 +16222,7 @@ dependencies = [ [[package]] name = "ssr-only" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "dioxus", ] @@ -16547,7 +16544,7 @@ dependencies = [ [[package]] name = "subsecond" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "js-sys", "libc", @@ -16573,7 +16570,7 @@ dependencies = [ [[package]] name = "subsecond-types" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "serde", ] @@ -16605,7 +16602,7 @@ dependencies = [ [[package]] name = "suspense-carousel" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "async-std", "dioxus", @@ -19105,7 +19102,7 @@ dependencies = [ [[package]] name = "wasm-split-cli" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "anyhow", "clap", @@ -19138,7 +19135,7 @@ dependencies = [ [[package]] name = "wasm-split-macro" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "base16", "digest", @@ -19150,7 +19147,7 @@ dependencies = [ [[package]] name = "wasm-splitter" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "async-once-cell", "wasm-split-macro", @@ -19171,7 +19168,7 @@ dependencies = [ [[package]] name = "wasm-used" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "id-arena", "tracing", @@ -20006,7 +20003,7 @@ dependencies = [ [[package]] name = "windows-headless" -version = "0.7.3-alpha.0" +version = "0.7.3" dependencies = [ "dioxus", ] diff --git a/Cargo.toml b/Cargo.toml index fb7f41e55..3353ff0e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -85,6 +85,7 @@ members = [ "packages/manganis/manganis", "packages/manganis/manganis-core", "packages/manganis/manganis-macro", + "packages/manganis/manganis-07", # wasm-split "packages/wasm-split/wasm-split", @@ -143,86 +144,80 @@ members = [ ] [workspace.package] -version = "0.7.3-alpha.0" +version = "0.7.3" # dependencies that are shared across packages [workspace.dependencies] -dioxus = { path = "packages/dioxus", version = "0.7.3-alpha.0" } -dioxus-core = { path = "packages/core", version = "0.7.3-alpha.0" } -dioxus-core-types = { path = "packages/core-types", version = "0.7.3-alpha.0" } -dioxus-core-macro = { path = "packages/core-macro", version = "0.7.3-alpha.0" } -dioxus-config-macro = { path = "packages/config-macro", version = "0.7.3-alpha.0" } -dioxus-router = { path = "packages/router", version = "0.7.3-alpha.0" } -dioxus-router-macro = { path = "packages/router-macro", version = "0.7.3-alpha.0" } -dioxus-document = { path = "packages/document", version = "0.7.3-alpha.0", default-features = false } -dioxus-history = { path = "packages/history", version = "0.7.3-alpha.0", default-features = false } -dioxus-html = { path = "packages/html", version = "0.7.3-alpha.0", default-features = false } -dioxus-html-internal-macro = { path = "packages/html-internal-macro", version = "0.7.3-alpha.0" } -dioxus-hooks = { path = "packages/hooks", version = "0.7.3-alpha.0" } -dioxus-web = { path = "packages/web", version = "0.7.3-alpha.0", default-features = false } -dioxus-ssr = { path = "packages/ssr", version = "0.7.3-alpha.0", default-features = false } -dioxus-desktop = { path = "packages/desktop", version = "0.7.3-alpha.0", default-features = false } -dioxus-interpreter-js = { path = "packages/interpreter", version = "0.7.3-alpha.0" } -dioxus-liveview = { path = "packages/liveview", version = "0.7.3-alpha.0" } -dioxus-autofmt = { path = "packages/autofmt", version = "0.7.3-alpha.0" } -dioxus-check = { path = "packages/check", version = "0.7.3-alpha.0" } -dioxus-rsx = { path = "packages/rsx", version = "0.7.3-alpha.0" } -dioxus-rsx-hotreload = { path = "packages/rsx-hotreload", version = "0.7.3-alpha.0" } -dioxus-rsx-rosetta = { path = "packages/rsx-rosetta", version = "0.7.3-alpha.0" } -dioxus-signals = { path = "packages/signals", version = "0.7.3-alpha.0" } -dioxus-stores = { path = "packages/stores", version = "0.7.3-alpha.0" } -dioxus-stores-macro = { path = "packages/stores-macro", version = "0.7.3-alpha.0" } -dioxus-devtools = { path = "packages/devtools", version = "0.7.3-alpha.0" } -dioxus-devtools-types = { path = "packages/devtools-types", version = "0.7.3-alpha.0" } -dioxus-fullstack = { path = "packages/fullstack", version = "0.7.3-alpha.0", default-features = false } -dioxus-fullstack-core = { path = "packages/fullstack-core", version = "0.7.3-alpha.0", default-features = false } -dioxus-fullstack-macro = { path = "packages/fullstack-macro", version = "0.7.3-alpha.0", default-features = false } -dioxus-server = { path = "packages/fullstack-server", version = "0.7.3-alpha.0" } -dioxus-dx-wire-format = { path = "packages/dx-wire-format", version = "0.7.3-alpha.0" } -dioxus-logger = { path = "packages/logger", version = "0.7.3-alpha.0" } -dioxus-native = { path = "packages/native", version = "0.7.3-alpha.0" } -dioxus-native-dom = { path = "packages/native-dom", version = "0.7.3-alpha.0" } -dioxus-asset-resolver = { path = "packages/asset-resolver", version = "0.7.3-alpha.0" } -dioxus-config-macros = { path = "packages/config-macros", version = "0.7.3-alpha.0" } -dioxus-component-manifest = { path = "packages/component-manifest", version = "0.7.3-alpha.0" } -generational-box = { path = "packages/generational-box", version = "0.7.3-alpha.0" } -lazy-js-bundle = { path = "packages/lazy-js-bundle", version = "0.7.3-alpha.0" } +dioxus = { path = "packages/dioxus", version = "0.7.3" } +dioxus-core = { path = "packages/core", version = "0.7.3" } +dioxus-core-types = { path = "packages/core-types", version = "0.7.3" } +dioxus-core-macro = { path = "packages/core-macro", version = "0.7.3" } +dioxus-config-macro = { path = "packages/config-macro", version = "0.7.3" } +dioxus-router = { path = "packages/router", version = "0.7.3" } +dioxus-router-macro = { path = "packages/router-macro", version = "0.7.3" } +dioxus-document = { path = "packages/document", version = "0.7.3", default-features = false } +dioxus-history = { path = "packages/history", version = "0.7.3", default-features = false } +dioxus-html = { path = "packages/html", version = "0.7.3", default-features = false } +dioxus-html-internal-macro = { path = "packages/html-internal-macro", version = "0.7.3" } +dioxus-hooks = { path = "packages/hooks", version = "0.7.3" } +dioxus-web = { path = "packages/web", version = "0.7.3", default-features = false } +dioxus-ssr = { path = "packages/ssr", version = "0.7.3", default-features = false } +dioxus-desktop = { path = "packages/desktop", version = "0.7.3", default-features = false } +dioxus-interpreter-js = { path = "packages/interpreter", version = "0.7.3" } +dioxus-liveview = { path = "packages/liveview", version = "0.7.3" } +dioxus-autofmt = { path = "packages/autofmt", version = "0.7.3" } +dioxus-check = { path = "packages/check", version = "0.7.3" } +dioxus-rsx = { path = "packages/rsx", version = "0.7.3" } +dioxus-rsx-hotreload = { path = "packages/rsx-hotreload", version = "0.7.3" } +dioxus-rsx-rosetta = { path = "packages/rsx-rosetta", version = "0.7.3" } +dioxus-signals = { path = "packages/signals", version = "0.7.3" } +dioxus-stores = { path = "packages/stores", version = "0.7.3" } +dioxus-stores-macro = { path = "packages/stores-macro", version = "0.7.3" } +dioxus-devtools = { path = "packages/devtools", version = "0.7.3" } +dioxus-devtools-types = { path = "packages/devtools-types", version = "0.7.3" } +dioxus-fullstack = { path = "packages/fullstack", version = "0.7.3", default-features = false } +dioxus-fullstack-core = { path = "packages/fullstack-core", version = "0.7.3", default-features = false } +dioxus-fullstack-macro = { path = "packages/fullstack-macro", version = "0.7.3", default-features = false } +dioxus-server = { path = "packages/fullstack-server", version = "0.7.3" } +dioxus-dx-wire-format = { path = "packages/dx-wire-format", version = "0.7.3" } +dioxus-logger = { path = "packages/logger", version = "0.7.3" } +dioxus-native = { path = "packages/native", version = "0.7.3" } +dioxus-native-dom = { path = "packages/native-dom", version = "0.7.3" } +dioxus-asset-resolver = { path = "packages/asset-resolver", version = "0.7.3" } +dioxus-config-macros = { path = "packages/config-macros", version = "0.7.3" } +dioxus-component-manifest = { path = "packages/component-manifest", version = "0.7.3" } +generational-box = { path = "packages/generational-box", version = "0.7.3" } +lazy-js-bundle = { path = "packages/lazy-js-bundle", version = "0.7.3" } # cli -dioxus-cli-opt = { path = "packages/cli-opt", version = "0.7.3-alpha.0" } -dioxus-cli-telemetry = { path = "packages/cli-telemetry", version = "0.7.3-alpha.0" } -dioxus-cli-config = { path = "packages/cli-config", version = "0.7.3-alpha.0" } +dioxus-cli-opt = { path = "packages/cli-opt", version = "0.7.3" } +dioxus-cli-telemetry = { path = "packages/cli-telemetry", version = "0.7.3" } +dioxus-cli-config = { path = "packages/cli-config", version = "0.7.3" } # subsecond -subsecond-types = { path = "packages/subsecond/subsecond-types", version = "0.7.3-alpha.0" } -subsecond = { path = "packages/subsecond/subsecond", version = "0.7.3-alpha.0" } +subsecond-types = { path = "packages/subsecond/subsecond-types", version = "0.7.3" } +subsecond = { path = "packages/subsecond/subsecond", version = "0.7.3" } # wasm-split -wasm-splitter = { path = "packages/wasm-split/wasm-split", version = "0.7.3-alpha.0" } -wasm-split-macro = { path = "packages/wasm-split/wasm-split-macro", version = "0.7.3-alpha.0" } -wasm-split-cli = { path = "packages/wasm-split/wasm-split-cli", version = "0.7.3-alpha.0" } -wasm-used = { path = "packages/wasm-split/wasm-used", version = "0.7.3-alpha.0" } +wasm-splitter = { path = "packages/wasm-split/wasm-split", version = "0.7.3" } +wasm-split-macro = { path = "packages/wasm-split/wasm-split-macro", version = "0.7.3" } +wasm-split-cli = { path = "packages/wasm-split/wasm-split-cli", version = "0.7.3" } +wasm-used = { path = "packages/wasm-split/wasm-used", version = "0.7.3" } # our dep-info parsing crate -depinfo = { path = "packages/depinfo", version = "0.7.3-alpha.0" } +depinfo = { path = "packages/depinfo", version = "0.7.3" } # manganis -manganis = { path = "packages/manganis/manganis", version = "0.7.3-alpha.0" } -manganis-core = { path = "packages/manganis/manganis-core", version = "0.7.3-alpha.0" } -manganis-macro = { path = "packages/manganis/manganis-macro", version = "0.7.3-alpha.0" } - -# The version of assets published with 0.7.0 and 0.7.1 that the CLI should still support -manganis-core-07 = { package = "manganis-core", version = "=0.7.2" } +manganis = { path = "packages/manganis/manganis", version = "0.7.3" } +manganis-core = { path = "packages/manganis/manganis-core", version = "0.7.3" } +manganis-macro = { path = "packages/manganis/manganis-macro", version = "0.7.3" } +manganis-core-07 = { path = "packages/manganis/manganis-07", version = "0.7.2" } # const-serialize. these are on "alpha" versions, but really, we are prepping for 0.8 but not committing to it yet # once the workspace moves onto 0.8, we can clean this up, moving the const-serialize stuff back to normal versions const-serialize = { path = "packages/const-serialize", version = "0.8.0-alpha.0" } -const-serialize-08 = { package = "const-serialize", path = "packages/const-serialize", version = "0.8.0-alpha.0" } const-serialize-macro = { path = "packages/const-serialize-macro", version = "0.8.0-alpha.0" } -# The version of const-serialize published with 0.7.0 and 0.7.1 that the CLI should still support -const-serialize-07 = { package = "const-serialize", version = "=0.7.2" } - warnings = { version = "0.2.1" } # blitz diff --git a/packages/cli/Cargo.toml b/packages/cli/Cargo.toml index be5b4853e..793a5346f 100644 --- a/packages/cli/Cargo.toml +++ b/packages/cli/Cargo.toml @@ -98,7 +98,7 @@ brotli = "8.0.1" ignore = "0.4.23" env_logger = { workspace = true } const-serialize = { workspace = true, features = ["serde"] } -const-serialize-07 = { workspace = true, features = ["serde"] } +const-serialize-07 = { package = "const-serialize", version = "=0.7.2", features = ["serde"] } tracing-subscriber = { version = "0.3.19", features = [ "std", diff --git a/packages/const-serialize/Cargo.toml b/packages/const-serialize/Cargo.toml index cb016a77e..766bbc92c 100644 --- a/packages/const-serialize/Cargo.toml +++ b/packages/const-serialize/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "const-serialize" -version = "0.8.0" +version = "0.8.0-alpha.0" authors = ["Evan Almloff"] edition = "2021" description = "A serialization framework that works in const contexts" @@ -13,10 +13,9 @@ rust-version = "1.83.0" [dependencies] const-serialize-macro = { workspace = true } serde = { workspace = true, features = ["derive"], optional = true } -const-serialize-07 = { workspace = true, optional = true } +const-serialize-07 = { package = "const-serialize", version = "=0.7.2", optional = true } [dev-dependencies] -const-serialize = { path = "." } rand = { workspace = true } [features] diff --git a/packages/manganis/manganis-07/Cargo.toml b/packages/manganis/manganis-07/Cargo.toml new file mode 100644 index 000000000..0def500c1 --- /dev/null +++ b/packages/manganis/manganis-07/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "manganis-core-07" +edition = "2021" +version = "0.7.2" +authors = ["Jonathan Kelley"] +description = "Legacy manganis-core v0.7.2 for backwards compatibility during 0.7.3 release" +license = "MIT OR Apache-2.0" +repository = "https://github.com/DioxusLabs/dioxus/" +homepage = "https://dioxuslabs.com" +keywords = ["dom", "ui", "gui", "assets"] + +# be careful with dependencies you add here - these need to get compiled for the proc macro and therefore +# prevent the main code from compiling! +[dependencies] +serde = { workspace = true, features = ["derive"] } +const-serialize-07 = { package = "const-serialize", version = "=0.7.2", features = ["serde"] } diff --git a/packages/manganis/manganis-07/src/asset.rs b/packages/manganis/manganis-07/src/asset.rs new file mode 100644 index 000000000..026cedaf4 --- /dev/null +++ b/packages/manganis/manganis-07/src/asset.rs @@ -0,0 +1,83 @@ +use crate::AssetOptions; +use const_serialize_07::{ConstStr, SerializeConst}; +use std::{fmt::Debug, hash::Hash}; + +/// An asset that should be copied by the bundler with some options. This type will be +/// serialized into the binary. +/// CLIs that support manganis, should pull out the assets from the link section, optimize, +/// and write them to the filesystem at [`BundledAsset::bundled_path`] for the application +/// to use. +#[derive(Debug, Eq, Clone, Copy, SerializeConst, serde::Serialize, serde::Deserialize)] +pub struct BundledAsset { + /// The absolute path of the asset + absolute_source_path: ConstStr, + /// The bundled path of the asset + bundled_path: ConstStr, + /// The options for the asset + options: AssetOptions, +} + +impl PartialEq for BundledAsset { + fn eq(&self, other: &Self) -> bool { + self.absolute_source_path == other.absolute_source_path + && self.bundled_path == other.bundled_path + && self.options == other.options + } +} + +impl PartialOrd for BundledAsset { + fn partial_cmp(&self, other: &Self) -> Option { + match self + .absolute_source_path + .partial_cmp(&other.absolute_source_path) + { + Some(core::cmp::Ordering::Equal) => {} + ord => return ord, + } + match self.bundled_path.partial_cmp(&other.bundled_path) { + Some(core::cmp::Ordering::Equal) => {} + ord => return ord, + } + self.options.partial_cmp(&other.options) + } +} + +impl Hash for BundledAsset { + fn hash(&self, state: &mut H) { + self.absolute_source_path.hash(state); + self.bundled_path.hash(state); + self.options.hash(state); + } +} + +impl BundledAsset { + #[doc(hidden)] + /// This should only be called from the macro + /// Create a new asset + pub const fn new( + absolute_source_path: &str, + bundled_path: &str, + options: AssetOptions, + ) -> Self { + Self { + absolute_source_path: ConstStr::new(absolute_source_path), + bundled_path: ConstStr::new(bundled_path), + options, + } + } + + /// Get the bundled name of the asset. This identifier cannot be used to read the asset directly + pub fn bundled_path(&self) -> &str { + self.bundled_path.as_str() + } + + /// Get the absolute path of the asset source. This path will not be available when the asset is bundled + pub fn absolute_source_path(&self) -> &str { + self.absolute_source_path.as_str() + } + + /// Get the options for the asset + pub const fn options(&self) -> &AssetOptions { + &self.options + } +} diff --git a/packages/manganis/manganis-07/src/css.rs b/packages/manganis/manganis-07/src/css.rs new file mode 100644 index 000000000..2accc3609 --- /dev/null +++ b/packages/manganis/manganis-07/src/css.rs @@ -0,0 +1,120 @@ +use crate::{AssetOptions, AssetOptionsBuilder, AssetVariant}; +use const_serialize_07::SerializeConst; + +/// Options for a css asset +#[derive( + Debug, + Eq, + PartialEq, + PartialOrd, + Clone, + Copy, + Hash, + SerializeConst, + serde::Serialize, + serde::Deserialize, +)] +pub struct CssAssetOptions { + minify: bool, + preload: bool, + static_head: bool, +} + +impl Default for CssAssetOptions { + fn default() -> Self { + Self::default() + } +} + +impl CssAssetOptions { + /// Create a new css asset using the builder + pub const fn new() -> AssetOptionsBuilder { + AssetOptions::css() + } + + /// Create a default css asset options + pub const fn default() -> Self { + Self { + preload: false, + minify: true, + static_head: false, + } + } + + /// Check if the asset is preloaded + pub const fn preloaded(&self) -> bool { + self.preload + } + + /// Check if the asset is statically created + pub const fn static_head(&self) -> bool { + self.static_head + } + + /// Check if the asset is minified + pub const fn minified(&self) -> bool { + self.minify + } +} + +impl AssetOptions { + /// Create a new css asset builder + /// + /// ```rust + /// # use manganis::{asset, Asset, AssetOptions}; + /// const _: Asset = asset!("/assets/style.css", AssetOptions::css()); + /// ``` + pub const fn css() -> AssetOptionsBuilder { + AssetOptionsBuilder::variant(CssAssetOptions::default()) + } +} + +impl AssetOptionsBuilder { + /// Sets whether the css should be minified (default: true) + /// + /// Minifying the css can make your site load faster by loading less data + /// + /// ```rust + /// # use manganis::{asset, Asset, AssetOptions}; + /// const _: Asset = asset!("/assets/style.css", AssetOptions::css().with_minify(false)); + /// ``` + pub const fn with_minify(mut self, minify: bool) -> Self { + self.variant.minify = minify; + self + } + + /// Make the asset statically inserted (default: false) + /// + /// Statically insert the file at compile time. + /// + /// ```rust + /// # use manganis::{asset, Asset, AssetOptions}; + /// const _: Asset = asset!("/assets/style.css", AssetOptions::css().with_static_head(true)); + /// ``` + #[allow(unused)] + pub const fn with_static_head(mut self, static_head: bool) -> Self { + self.variant.static_head = static_head; + self + } + + /// Make the asset preloaded + /// + /// Preloading css will make the file start to load as soon as possible. This is useful for css that is used soon after the page loads or css that may not be used immediately, but should start loading sooner + /// + /// ```rust + /// # use manganis::{asset, Asset, AssetOptions}; + /// const _: Asset = asset!("/assets/style.css", AssetOptions::css().with_preload(true)); + /// ``` + pub const fn with_preload(mut self, preload: bool) -> Self { + self.variant.preload = preload; + self + } + + /// Convert the options into options for a generic asset + pub const fn into_asset_options(self) -> AssetOptions { + AssetOptions { + add_hash: true, + variant: AssetVariant::Css(self.variant), + } + } +} diff --git a/packages/manganis/manganis-07/src/css_module.rs b/packages/manganis/manganis-07/src/css_module.rs new file mode 100644 index 000000000..0bacd375f --- /dev/null +++ b/packages/manganis/manganis-07/src/css_module.rs @@ -0,0 +1,190 @@ +use crate::{AssetOptions, AssetOptionsBuilder, AssetVariant}; +use const_serialize_07::SerializeConst; +use std::collections::HashSet; + +/// Options for a css module asset +#[derive( + Debug, + Eq, + PartialEq, + PartialOrd, + Clone, + Copy, + Hash, + SerializeConst, + serde::Serialize, + serde::Deserialize, +)] +#[non_exhaustive] +#[doc(hidden)] +pub struct CssModuleAssetOptions { + minify: bool, + preload: bool, +} + +impl Default for CssModuleAssetOptions { + fn default() -> Self { + Self::default() + } +} + +impl CssModuleAssetOptions { + /// Create a new css asset using the builder + pub const fn new() -> AssetOptionsBuilder { + AssetOptions::css_module() + } + + /// Create a default css module asset options + pub const fn default() -> Self { + Self { + preload: false, + minify: true, + } + } + + /// Check if the asset is minified + pub const fn minified(&self) -> bool { + self.minify + } + + /// Check if the asset is preloaded + pub const fn preloaded(&self) -> bool { + self.preload + } +} + +impl AssetOptions { + /// Create a new css module asset builder + /// + /// ```rust + /// # use manganis::{asset, Asset, AssetOptions}; + /// const _: Asset = asset!("/assets/style.css", AssetOptions::css_module()); + /// ``` + pub const fn css_module() -> AssetOptionsBuilder { + AssetOptionsBuilder::variant(CssModuleAssetOptions::default()) + } +} + +impl AssetOptionsBuilder { + /// Sets whether the css should be minified (default: true) + /// + /// Minifying the css can make your site load faster by loading less data + pub const fn with_minify(mut self, minify: bool) -> Self { + self.variant.minify = minify; + self + } + + /// Make the asset preloaded + /// + /// Preloading css will make the image start to load as soon as possible. This is useful for css that is used soon after the page loads or css that may not be used immediately, but should start loading sooner + pub const fn with_preload(mut self, preload: bool) -> Self { + self.variant.preload = preload; + self + } + + /// Convert the options into options for a generic asset + pub const fn into_asset_options(self) -> AssetOptions { + AssetOptions { + add_hash: self.add_hash, + variant: AssetVariant::CssModule(self.variant), + } + } +} + +/// Collect CSS classes & ids. +/// +/// This is a rudementary css classes & ids collector. +/// Idents used only in media queries will not be collected. (not support yet) +/// +/// There are likely a number of edge cases that will show up. +/// +/// Returns `(HashSet, HashSet)` +pub fn collect_css_idents(css: &str) -> (HashSet, HashSet) { + const ALLOWED: &str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-"; + + let mut classes = HashSet::new(); + let mut ids = HashSet::new(); + + // Collected ident name and true for ids. + let mut start: Option<(String, bool)> = None; + + // True if we have the first comment start delimiter `/` + let mut comment_start = false; + // True if we have the first comment end delimiter '*' + let mut comment_end = false; + // True if we're in a comment scope. + let mut in_comment_scope = false; + + // True if we're in a block scope: `#hi { this is block scope }` + let mut in_block_scope = false; + + // If we are currently collecting an ident: + // - Check if the char is allowed, put it into the ident string. + // - If not allowed, finalize the ident string and reset start. + // Otherwise: + // Check if character is a `.` or `#` representing a class or string, and start collecting. + for (_byte_index, c) in css.char_indices() { + if let Some(ident) = start.as_mut() { + if ALLOWED.find(c).is_some() { + // CSS ignore idents that start with a number. + // 1. Difficult to process + // 2. Avoid false positives (transition: 0.5s) + if ident.0.is_empty() && c.is_numeric() { + start = None; + continue; + } + + ident.0.push(c); + } else { + match ident.1 { + true => ids.insert(ident.0.clone()), + false => classes.insert(ident.0.clone()), + }; + + start = None; + } + } else { + // Handle entering an exiting scopede. + match c { + // Mark as comment scope if we have comment start: /* + '*' if comment_start => { + comment_start = false; + in_comment_scope = true; + } + // Mark start of comment end if in comment scope: */ + '*' if in_comment_scope => comment_end = true, + // Mark as comment start if not in comment scope and no comment start, mark comment_start + '/' if !in_comment_scope => { + comment_start = true; + } + // If we get the closing delimiter, mark as non-comment scope. + '/' if comment_end => { + in_comment_scope = false; + comment_start = false; + comment_end = false; + } + // Entering & Exiting block scope. + '{' => in_block_scope = true, + '}' => in_block_scope = false, + // Any other character, reset comment start and end if not in scope. + _ => { + comment_start = false; + comment_end = false; + } + } + + // No need to process this char if in bad scope. + if in_comment_scope || in_block_scope { + continue; + } + + match c { + '.' => start = Some((String::new(), false)), + '#' => start = Some((String::new(), true)), + _ => {} + } + } + } + + (classes, ids) +} diff --git a/packages/manganis/manganis-07/src/folder.rs b/packages/manganis/manganis-07/src/folder.rs new file mode 100644 index 000000000..10a2f5ed9 --- /dev/null +++ b/packages/manganis/manganis-07/src/folder.rs @@ -0,0 +1,58 @@ +use const_serialize_07::SerializeConst; + +use crate::{AssetOptions, AssetOptionsBuilder}; + +/// The builder for a folder asset. +#[derive( + Debug, + Eq, + PartialEq, + PartialOrd, + Clone, + Copy, + Hash, + SerializeConst, + serde::Serialize, + serde::Deserialize, +)] +pub struct FolderAssetOptions {} + +impl Default for FolderAssetOptions { + fn default() -> Self { + Self::default() + } +} + +impl FolderAssetOptions { + /// Create a new folder asset builder + pub const fn new() -> AssetOptionsBuilder { + AssetOptions::folder() + } + + /// Create a default folder asset options + pub const fn default() -> Self { + Self {} + } +} + +impl AssetOptions { + /// Create a new folder asset builder + /// + /// ```rust + /// # use manganis::{asset, Asset, AssetOptions}; + /// const _: Asset = asset!("/assets", AssetOptions::folder()); + /// ``` + pub const fn folder() -> AssetOptionsBuilder { + AssetOptionsBuilder::variant(FolderAssetOptions::default()) + } +} + +impl AssetOptionsBuilder { + /// Convert the options into options for a generic asset + pub const fn into_asset_options(self) -> AssetOptions { + AssetOptions { + add_hash: false, + variant: crate::AssetVariant::Folder(self.variant), + } + } +} diff --git a/packages/manganis/manganis-07/src/images.rs b/packages/manganis/manganis-07/src/images.rs new file mode 100644 index 000000000..7c4a4950d --- /dev/null +++ b/packages/manganis/manganis-07/src/images.rs @@ -0,0 +1,235 @@ +use const_serialize_07::SerializeConst; + +use crate::{AssetOptions, AssetOptionsBuilder, AssetVariant}; + +/// The type of an image. You can read more about the tradeoffs between image formats [here](https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types) +#[derive( + Debug, + Eq, + PartialEq, + PartialOrd, + Clone, + Copy, + Hash, + SerializeConst, + serde::Serialize, + serde::Deserialize, +)] +#[repr(u8)] +pub enum ImageFormat { + /// A png image. Png images cannot contain transparency and tend to compress worse than other formats + Png, + /// A jpg image. Jpg images can contain transparency and tend to compress better than png images + Jpg, + /// A webp image. Webp images can contain transparency and tend to compress better than jpg images + Webp, + /// An avif image. Avif images can compress slightly better than webp images but are not supported by all browsers + Avif, + /// An unknown image type + Unknown, +} + +/// The size of an image asset +#[derive( + Debug, + Eq, + PartialEq, + PartialOrd, + Clone, + Copy, + Hash, + SerializeConst, + serde::Serialize, + serde::Deserialize, +)] +#[repr(C, u8)] +pub enum ImageSize { + /// A manual size in pixels + Manual { + /// The width of the image in pixels + width: u32, + /// The height of the image in pixels + height: u32, + }, + /// The size will be automatically determined from the image source + Automatic, +} + +/// Options for an image asset +#[derive( + Debug, + Eq, + PartialEq, + PartialOrd, + Clone, + Copy, + Hash, + SerializeConst, + serde::Serialize, + serde::Deserialize, +)] +pub struct ImageAssetOptions { + ty: ImageFormat, + low_quality_preview: bool, + size: ImageSize, + preload: bool, +} + +impl Default for ImageAssetOptions { + fn default() -> Self { + Self::default() + } +} + +impl ImageAssetOptions { + /// Create a new builder for image asset options + pub const fn new() -> AssetOptionsBuilder { + AssetOptions::image() + } + + /// Create a default image asset options + pub const fn default() -> Self { + Self { + ty: ImageFormat::Unknown, + low_quality_preview: false, + size: ImageSize::Automatic, + preload: false, + } + } + + /// Check if the asset is preloaded + pub const fn preloaded(&self) -> bool { + self.preload + } + + /// Get the format of the image + pub const fn format(&self) -> ImageFormat { + self.ty + } + + /// Get the size of the image + pub const fn size(&self) -> ImageSize { + self.size + } + + pub(crate) const fn extension(&self) -> Option<&'static str> { + match self.ty { + ImageFormat::Png => Some("png"), + ImageFormat::Jpg => Some("jpg"), + ImageFormat::Webp => Some("webp"), + ImageFormat::Avif => Some("avif"), + ImageFormat::Unknown => None, + } + } +} + +impl AssetOptions { + /// Create a new image asset builder + /// + /// ```rust + /// # use manganis::{asset, Asset, AssetOptions}; + /// const _: Asset = asset!("/assets/image.png", AssetOptions::image()); + /// ``` + pub const fn image() -> AssetOptionsBuilder { + AssetOptionsBuilder::variant(ImageAssetOptions::default()) + } +} + +impl AssetOptionsBuilder { + /// Make the asset preloaded + /// + /// Preloading an image will make the image start to load as soon as possible. This is useful for images that will be displayed soon after the page loads or images that may not be visible immediately, but should start loading sooner + /// + /// ```rust + /// # use manganis::{asset, Asset, AssetOptions}; + /// const _: Asset = asset!("/assets/image.png", AssetOptions::image().with_preload(true)); + /// ``` + pub const fn with_preload(mut self, preload: bool) -> Self { + self.variant.preload = preload; + self + } + + /// Sets the format of the image + /// + /// Choosing the right format can make your site load much faster. Webp and avif images tend to be a good default for most images + /// + /// ```rust + /// # use manganis::{asset, Asset, AssetOptions, ImageFormat}; + /// const _: Asset = asset!("/assets/image.png", AssetOptions::image().with_format(ImageFormat::Webp)); + /// ``` + pub const fn with_format(mut self, format: ImageFormat) -> Self { + self.variant.ty = format; + self + } + + /// Sets the format of the image to [`ImageFormat::Avif`] + /// + /// Avif images tend to be a good default for most images rendered in browser because + /// they compress images well + /// + /// ```rust + /// # use manganis::{asset, Asset, AssetOptions, ImageFormat}; + /// const _: Asset = asset!("/assets/image.png", AssetOptions::image().with_avif()); + /// ``` + pub const fn with_avif(self) -> Self { + self.with_format(ImageFormat::Avif) + } + + /// Sets the format of the image to [`ImageFormat::Webp`] + /// + /// Webp images tend to be a good default for most images rendered in browser because + /// they compress images well + /// + /// ```rust + /// # use manganis::{asset, Asset, AssetOptions, ImageFormat}; + /// const _: Asset = asset!("/assets/image.png", AssetOptions::image().with_webp()); + /// ``` + pub const fn with_webp(self) -> Self { + self.with_format(ImageFormat::Webp) + } + + /// Sets the format of the image to [`ImageFormat::Jpg`] + /// + /// Jpeg images compress much better than [`ImageFormat::Png`], but worse than [`ImageFormat::Webp`] or [`ImageFormat::Avif`] + /// + /// ```rust + /// # use manganis::{asset, Asset, AssetOptions, ImageFormat}; + /// const _: Asset = asset!("/assets/image.png", AssetOptions::image().with_jpg()); + /// ``` + pub const fn with_jpg(self) -> Self { + self.with_format(ImageFormat::Jpg) + } + + /// Sets the format of the image to [`ImageFormat::Png`] + /// + /// Png images don't compress very well, so they are not recommended for large images + /// + /// ```rust + /// # use manganis::{asset, Asset, AssetOptions, ImageFormat}; + /// const _: Asset = asset!("/assets/image.png", AssetOptions::image().with_png()); + /// ``` + pub const fn with_png(self) -> Self { + self.with_format(ImageFormat::Png) + } + + /// Sets the size of the image + /// + /// If you only use the image in one place, you can set the size of the image to the size it will be displayed at. This will make the image load faster + /// + /// ```rust + /// # use manganis::{asset, Asset, AssetOptions, ImageSize}; + /// const _: Asset = asset!("/assets/image.png", AssetOptions::image().with_size(ImageSize::Manual { width: 512, height: 512 })); + /// ``` + pub const fn with_size(mut self, size: ImageSize) -> Self { + self.variant.size = size; + self + } + + /// Convert the options into options for a generic asset + pub const fn into_asset_options(self) -> AssetOptions { + AssetOptions { + add_hash: self.add_hash, + variant: AssetVariant::Image(self.variant), + } + } +} diff --git a/packages/manganis/manganis-07/src/js.rs b/packages/manganis/manganis-07/src/js.rs new file mode 100644 index 000000000..da4081723 --- /dev/null +++ b/packages/manganis/manganis-07/src/js.rs @@ -0,0 +1,123 @@ +use const_serialize_07::SerializeConst; + +use crate::{AssetOptions, AssetOptionsBuilder, AssetVariant}; + +/// Options for a javascript asset +#[derive( + Debug, + Eq, + PartialEq, + PartialOrd, + Clone, + Copy, + Hash, + SerializeConst, + serde::Serialize, + serde::Deserialize, +)] +pub struct JsAssetOptions { + minify: bool, + preload: bool, + static_head: bool, +} + +impl Default for JsAssetOptions { + fn default() -> Self { + Self::default() + } +} + +impl JsAssetOptions { + /// Create a new js asset options builder + pub const fn new() -> AssetOptionsBuilder { + AssetOptions::js() + } + + /// Create a default js asset options + pub const fn default() -> Self { + Self { + preload: false, + minify: true, + static_head: false, + } + } + + /// Check if the asset is preloaded + pub const fn preloaded(&self) -> bool { + self.preload + } + + /// Check if the asset is statically created + pub const fn static_head(&self) -> bool { + self.static_head + } + + /// Check if the asset is minified + pub const fn minified(&self) -> bool { + self.minify + } +} + +impl AssetOptions { + /// Create a new js asset builder + /// + /// ```rust + /// # use manganis::{asset, Asset, AssetOptions}; + /// const _: Asset = asset!("/assets/script.js", AssetOptions::js()); + /// ``` + pub const fn js() -> AssetOptionsBuilder { + AssetOptionsBuilder::variant(JsAssetOptions::default()) + } +} + +impl AssetOptionsBuilder { + /// Sets whether the js should be minified (default: true) + /// + /// Minifying the js can make your site load faster by loading less data + /// + /// ```rust + /// # use manganis::{asset, Asset, AssetOptions}; + /// const _: Asset = asset!("/assets/script.js", AssetOptions::js().with_minify(false)); + /// ``` + #[allow(unused)] + pub const fn with_minify(mut self, minify: bool) -> Self { + self.variant.minify = minify; + self + } + + /// Make the asset statically inserted (default: false) + /// + /// Statically insert the file at compile time. + /// + /// ```rust + /// # use manganis::{asset, Asset, AssetOptions}; + /// const _: Asset = asset!("/assets/script.js", AssetOptions::js().with_static_head(true)); + /// ``` + #[allow(unused)] + pub const fn with_static_head(mut self, static_head: bool) -> Self { + self.variant.static_head = static_head; + self + } + + /// Make the asset preloaded + /// + /// Preloading the javascript will make the javascript start to load as soon as possible. This is useful for javascript that will be used soon after the page loads or javascript that may not be used immediately, but should start loading sooner + /// + /// ```rust + /// # use manganis::{asset, Asset, AssetOptions}; + /// const _: Asset = asset!("/assets/script.js", AssetOptions::js().with_preload(true)); + /// ``` + #[allow(unused)] + pub const fn with_preload(mut self, preload: bool) -> Self { + self.variant.preload = preload; + self + } + + /// Convert the builder into asset options with the given variant + pub const fn into_asset_options(self) -> AssetOptions { + AssetOptions { + add_hash: self.add_hash, + variant: AssetVariant::Js(self.variant), + } + } +} diff --git a/packages/manganis/manganis-07/src/lib.rs b/packages/manganis/manganis-07/src/lib.rs new file mode 100644 index 000000000..fc4511cb0 --- /dev/null +++ b/packages/manganis/manganis-07/src/lib.rs @@ -0,0 +1,23 @@ +// Re-export const-serialize under the expected name for the derive macro +extern crate const_serialize_07 as const_serialize; + +mod folder; +pub use folder::*; + +mod images; +pub use images::*; + +mod options; +pub use options::*; + +mod css; +pub use css::*; + +mod js; +pub use js::*; + +mod asset; +pub use asset::*; + +mod css_module; +pub use css_module::*; diff --git a/packages/manganis/manganis-07/src/options.rs b/packages/manganis/manganis-07/src/options.rs new file mode 100644 index 000000000..e205d6e30 --- /dev/null +++ b/packages/manganis/manganis-07/src/options.rs @@ -0,0 +1,174 @@ +use const_serialize_07::SerializeConst; + +use crate::{ + CssAssetOptions, CssModuleAssetOptions, FolderAssetOptions, ImageAssetOptions, JsAssetOptions, +}; + +/// Settings for a generic asset +#[derive( + Debug, + Eq, + PartialEq, + PartialOrd, + Clone, + Copy, + Hash, + SerializeConst, + serde::Serialize, + serde::Deserialize, +)] +#[non_exhaustive] +pub struct AssetOptions { + /// If a hash should be added to the asset path + pub(crate) add_hash: bool, + /// The variant of the asset + pub(crate) variant: AssetVariant, +} + +impl AssetOptions { + /// Create a new asset options builder + pub const fn builder() -> AssetOptionsBuilder<()> { + AssetOptionsBuilder::new() + } + + /// Get the variant of the asset + pub const fn variant(&self) -> &AssetVariant { + &self.variant + } + + /// Check if a hash should be added to the asset path + pub const fn hash_suffix(&self) -> bool { + self.add_hash + } + + /// Try to get the extension for the asset. If the asset options don't define an extension, this will return None + pub const fn extension(&self) -> Option<&'static str> { + match self.variant { + AssetVariant::Image(image) => image.extension(), + AssetVariant::Css(_) => Some("css"), + AssetVariant::CssModule(_) => Some("css"), + AssetVariant::Js(_) => Some("js"), + AssetVariant::Folder(_) => None, + AssetVariant::Unknown => None, + } + } + + /// Convert the options into options for a generic asset + pub const fn into_asset_options(self) -> AssetOptions { + self + } +} + +/// A builder for [`AssetOptions`] +/// +/// ```rust +/// # use manganis::{AssetOptions, Asset, asset}; +/// static ASSET: Asset = asset!( +/// "/assets/style.css", +/// AssetOptions::builder() +/// .with_hash_suffix(false) +/// ); +/// ``` +pub struct AssetOptionsBuilder { + /// If a hash should be added to the asset path + pub(crate) add_hash: bool, + /// The variant of the asset + pub(crate) variant: T, +} + +impl Default for AssetOptionsBuilder<()> { + fn default() -> Self { + Self::default() + } +} + +impl AssetOptionsBuilder<()> { + /// Create a new asset options builder with an unknown variant + pub const fn new() -> Self { + Self { + add_hash: true, + variant: (), + } + } + + /// Create a default asset options builder + pub const fn default() -> Self { + Self::new() + } + + /// Convert the builder into asset options with the given variant + pub const fn into_asset_options(self) -> AssetOptions { + AssetOptions { + add_hash: self.add_hash, + variant: AssetVariant::Unknown, + } + } +} + +impl AssetOptionsBuilder { + /// Create a new asset options builder with the given variant + pub(crate) const fn variant(variant: T) -> Self { + Self { + add_hash: true, + variant, + } + } + + /// Set whether a hash should be added to the asset path. Manganis adds hashes to asset paths by default + /// for [cache busting](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Caching#cache_busting). + /// With hashed assets, you can serve the asset with a long expiration time, and when the asset changes, + /// the hash in the path will change, causing the browser to fetch the new version. + /// + /// This method will only effect if the hash is added to the bundled asset path. If you are using the asset + /// macro, the asset struct still needs to be used in your rust code to ensure the asset is included in the binary. + /// + ///
+ /// + /// If you are using an asset outside of rust code where you know what the asset hash will be, you must use the + /// `#[used]` attribute to ensure the asset is included in the binary even if it is not referenced in the code. + /// + /// ```rust + /// #[used] + /// static ASSET: manganis::Asset = manganis::asset!( + /// "/assets/style.css", + /// manganis::AssetOptions::builder() + /// .with_hash_suffix(false) + /// ); + /// ``` + /// + ///
+ pub const fn with_hash_suffix(mut self, add_hash: bool) -> Self { + self.add_hash = add_hash; + self + } +} + +/// Settings for a specific type of asset +#[derive( + Debug, + Eq, + PartialEq, + PartialOrd, + Clone, + Copy, + Hash, + SerializeConst, + serde::Serialize, + serde::Deserialize, +)] +#[repr(C, u8)] +#[non_exhaustive] +pub enum AssetVariant { + /// An image asset + Image(ImageAssetOptions), + /// A folder asset + Folder(FolderAssetOptions), + /// A css asset + Css(CssAssetOptions), + /// A css module asset + CssModule(CssModuleAssetOptions), + /// A javascript asset + Js(JsAssetOptions), + /// An unknown asset + Unknown, +} diff --git a/packages/manganis/manganis-core/Cargo.toml b/packages/manganis/manganis-core/Cargo.toml index 112d0ac38..9412d26a3 100644 --- a/packages/manganis/manganis-core/Cargo.toml +++ b/packages/manganis/manganis-core/Cargo.toml @@ -14,8 +14,8 @@ readme = "../manganis/README.md" # prevent the main code from compiling! [dependencies] serde = { workspace = true, features = ["derive"] } -const-serialize-08 = { workspace = true, features = ["serde", "const-serialize-07"] } -const-serialize-07 = { workspace = true } +const-serialize-08 = { package = "const-serialize", path = "../../const-serialize", version = "0.8.0-alpha.0", features = ["serde", "const-serialize-07"] } +const-serialize-07 = { package = "const-serialize", version = "=0.7.2" } dioxus-core-types = { workspace = true, optional = true } dioxus-cli-config = { workspace = true, optional = true } winnow = { workspace = true } diff --git a/packages/manganis/manganis/Cargo.toml b/packages/manganis/manganis/Cargo.toml index c46258ddc..e3f019b9e 100644 --- a/packages/manganis/manganis/Cargo.toml +++ b/packages/manganis/manganis/Cargo.toml @@ -14,9 +14,9 @@ keywords = ["assets"] [dependencies] const-serialize = { workspace = true } -const-serialize-07 = { workspace = true } manganis-core = { workspace = true } manganis-macro = { workspace = true } +const-serialize-07 = { package = "const-serialize", version = "=0.7.2" } [features] default = []