js crate optimization

Orual 38220c7c 5ba1942a

+165 -57
+2
.gitignore
··· 26 27 # Deciduous database (local) 28 .deciduous/
··· 26 27 # Deciduous database (local) 28 .deciduous/ 29 + 30 + !.cargo/config.toml
+23 -10
Cargo.lock
··· 7675 checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" 7676 7677 [[package]] 7678 name = "oorandom" 7679 version = "11.1.5" 7680 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 10619 "flate2", 10620 "fnv", 10621 "once_cell", 10622 "plist", 10623 "regex-syntax", 10624 "serde", ··· 10626 "serde_json", 10627 "thiserror 2.0.17", 10628 "walkdir", 10629 - "yaml-rust", 10630 ] 10631 10632 [[package]] ··· 13330 version = "0.8.15" 13331 source = "registry+https://github.com/rust-lang/crates.io-index" 13332 checksum = "fdd20c5420375476fbd4394763288da7eb0cc0b8c11deed431a91562af7335d3" 13333 - 13334 - [[package]] 13335 - name = "yaml-rust" 13336 - version = "0.4.5" 13337 - source = "registry+https://github.com/rust-lang/crates.io-index" 13338 - checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" 13339 - dependencies = [ 13340 - "linked-hash-map", 13341 - ] 13342 13343 [[package]] 13344 name = "yaml-rust2"
··· 7675 checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" 7676 7677 [[package]] 7678 + name = "onig" 7679 + version = "6.5.1" 7680 + source = "registry+https://github.com/rust-lang/crates.io-index" 7681 + checksum = "336b9c63443aceef14bea841b899035ae3abe89b7c486aaf4c5bd8aafedac3f0" 7682 + dependencies = [ 7683 + "bitflags 2.10.0", 7684 + "libc", 7685 + "once_cell", 7686 + "onig_sys", 7687 + ] 7688 + 7689 + [[package]] 7690 + name = "onig_sys" 7691 + version = "69.9.1" 7692 + source = "registry+https://github.com/rust-lang/crates.io-index" 7693 + checksum = "c7f86c6eef3d6df15f23bcfb6af487cbd2fed4e5581d58d5bf1f5f8b7f6727dc" 7694 + dependencies = [ 7695 + "cc", 7696 + "pkg-config", 7697 + ] 7698 + 7699 + [[package]] 7700 name = "oorandom" 7701 version = "11.1.5" 7702 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 10641 "flate2", 10642 "fnv", 10643 "once_cell", 10644 + "onig", 10645 "plist", 10646 "regex-syntax", 10647 "serde", ··· 10649 "serde_json", 10650 "thiserror 2.0.17", 10651 "walkdir", 10652 ] 10653 10654 [[package]] ··· 13352 version = "0.8.15" 13353 source = "registry+https://github.com/rust-lang/crates.io-index" 13354 checksum = "fdd20c5420375476fbd4394763288da7eb0cc0b8c11deed431a91562af7335d3" 13355 13356 [[package]] 13357 name = "yaml-rust2"
+10
Cargo.toml
··· 95 96 [profile.android-dev] 97 inherits = "dev"
··· 95 96 [profile.android-dev] 97 inherits = "dev" 98 + 99 + 100 + # [profile.release] 101 + # opt-level = "z" 102 + # debug = false 103 + # lto = true 104 + # codegen-units = 1 105 + # panic = "abort" 106 + # incremental = false 107 + # strip = true
+19 -1
crates/weaver-app/Cargo.toml
··· 70 http = "1.3" 71 reqwest = { version = "0.12", default-features = false, features = ["json"] } 72 dioxus-free-icons = { version = "0.9", features = ["font-awesome-brands"] } 73 - syntect = { workspace = true, default-features = false, features = ["default-fancy"]} 74 # diesel = { version = "2.3", features = ["sqlite", "returning_clauses_for_sqlite_3_35", "chrono", "serde_json"] } 75 # diesel_migrations = { version = "2.3", features = ["sqlite"] } 76 tokio = { version = "1.28", features = ["sync"] } ··· 101 webbrowser = "1.0.6" 102 reqwest = { version = "0.12", default-features = false, features = ["json"] } 103 ring = { version = "0.17", default-features = false, features = ["alloc"] } 104 105 [target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dependencies] 106 reqwest = { version = "0.12", default-features = false, features = ["json"] } 107 tracing-wasm = "0.2" 108 #sqlite-wasm-rs = { version = "0.4", default-features = false, features = ["precompiled", "relaxed-idb"] } 109 time = { version = "0.3", features = ["wasm-bindgen"] } 110 console_error_panic_hook = "0.1"
··· 70 http = "1.3" 71 reqwest = { version = "0.12", default-features = false, features = ["json"] } 72 dioxus-free-icons = { version = "0.9", features = ["font-awesome-brands"] } 73 + # syntect configured per-target below 74 # diesel = { version = "2.3", features = ["sqlite", "returning_clauses_for_sqlite_3_35", "chrono", "serde_json"] } 75 # diesel_migrations = { version = "2.3", features = ["sqlite"] } 76 tokio = { version = "1.28", features = ["sync"] } ··· 101 webbrowser = "1.0.6" 102 reqwest = { version = "0.12", default-features = false, features = ["json"] } 103 ring = { version = "0.17", default-features = false, features = ["alloc"] } 104 + # Native: full syntect with onig 105 + syntect = { workspace = true, default-features = false, features = [ 106 + "parsing", 107 + "html", 108 + "default-syntaxes", 109 + "default-themes", 110 + "plist-load", 111 + "regex-onig" 112 + ] } 113 114 [target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dependencies] 115 reqwest = { version = "0.12", default-features = false, features = ["json"] } 116 tracing-wasm = "0.2" 117 + # WASM: syntect with fancy-regex (no onig for wasm) 118 + syntect = { workspace = true, default-features = false, features = [ 119 + "parsing", 120 + "html", 121 + "default-syntaxes", 122 + "default-themes", 123 + "plist-load", 124 + "regex-fancy" 125 + ] } 126 #sqlite-wasm-rs = { version = "0.4", default-features = false, features = ["precompiled", "relaxed-idb"] } 127 time = { version = "0.3", features = ["wasm-bindgen"] } 128 console_error_panic_hook = "0.1"
+1 -2
crates/weaver-common/Cargo.toml
··· 6 publish = false 7 8 [features] 9 - default = ["dev"] 10 - dev = [] 11 native = ["jacquard/dns"] 12 use-index = [] 13 iroh = ["dep:iroh", "dep:iroh-gossip", "dep:iroh-tickets"]
··· 6 publish = false 7 8 [features] 9 + default = [ "use-index"] 10 native = ["jacquard/dns"] 11 use-index = [] 12 iroh = ["dep:iroh", "dep:iroh-gossip", "dep:iroh-tickets"]
+20 -2
crates/weaver-editor-core/Cargo.toml
··· 13 markdown-weaver = { workspace = true } 14 markdown-weaver-escape = { workspace = true } 15 weaver-common = { path = "../weaver-common" } 16 - weaver-renderer = { path = "../weaver-renderer" } 17 weaver-api = { path = "../weaver-api" } 18 jacquard = { workspace = true } 19 - syntect = { workspace = true } 20 21 [dev-dependencies]
··· 13 markdown-weaver = { workspace = true } 14 markdown-weaver-escape = { workspace = true } 15 weaver-common = { path = "../weaver-common" } 16 + # Only needs syntax-highlighting, not CSS generation 17 + weaver-renderer = { path = "../weaver-renderer", default-features = false, features = ["syntax-highlighting"] } 18 weaver-api = { path = "../weaver-api" } 19 jacquard = { workspace = true } 20 + 21 + # Native: syntect with onig 22 + [target.'cfg(not(all(target_family = "wasm", target_os = "unknown")))'.dependencies] 23 + syntect = { workspace = true, default-features = false, features = [ 24 + "parsing", 25 + "html", 26 + "default-syntaxes", 27 + "regex-onig" 28 + ] } 29 + 30 + # WASM: syntect with fancy-regex 31 + [target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dependencies] 32 + syntect = { workspace = true, default-features = false, features = [ 33 + "parsing", 34 + "html", 35 + "default-syntaxes", 36 + "regex-fancy" 37 + ] } 38 39 [dev-dependencies]
+2 -2
crates/weaver-editor-crdt/Cargo.toml
··· 29 futures-util = "0.3" 30 n0-future = { workspace = true } 31 32 - # Optional weaver-specific deps 33 - weaver-renderer = { path = "../weaver-renderer", optional = true } 34 35 [target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dependencies] 36 gloo-worker = { version = "0.5", features = ["futures"] }
··· 29 futures-util = "0.3" 30 n0-future = { workspace = true } 31 32 + # Optional weaver-specific deps - only syntax-highlighting needed 33 + weaver-renderer = { path = "../weaver-renderer", optional = true, default-features = false, features = ["syntax-highlighting"] } 34 35 [target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dependencies] 36 gloo-worker = { version = "0.5", features = ["futures"] }
+2 -1
crates/weaver-embed-worker/Cargo.toml
··· 11 12 [dependencies] 13 weaver-common = { path = "../weaver-common", features = ["cache", "perf"] } 14 - weaver-renderer = { path = "../weaver-renderer" } 15 jacquard = { workspace = true } 16 serde = { workspace = true } 17 tracing = { workspace = true }
··· 11 12 [dependencies] 13 weaver-common = { path = "../weaver-common", features = ["cache", "perf"] } 14 + # WASM target - only syntax-highlighting, not syntax-css 15 + weaver-renderer = { path = "../weaver-renderer", default-features = false, features = ["syntax-highlighting"] } 16 jacquard = { workspace = true } 17 serde = { workspace = true } 18 tracing = { workspace = true }
+13 -5
crates/weaver-renderer-js/Cargo.toml
··· 9 [lib] 10 crate-type = ["cdylib", "rlib"] 11 12 [dependencies] 13 - weaver-renderer = { path = "../weaver-renderer" } 14 weaver-common = { path = "../weaver-common" } 15 weaver-api = { path = "../weaver-api" } 16 - jacquard = { workspace = true } 17 markdown-weaver = { workspace = true } 18 markdown-weaver-escape = { workspace = true } 19 ··· 24 js-sys = "0.3" 25 console_error_panic_hook = "0.1" 26 27 - [profile.release] 28 - lto = true 29 - opt-level = "z"
··· 9 [lib] 10 crate-type = ["cdylib", "rlib"] 11 12 + [features] 13 + default = ["syntax-highlighting"] 14 + syntax-highlighting = ["weaver-renderer/syntax-highlighting"] 15 + 16 [dependencies] 17 + weaver-renderer = { path = "../weaver-renderer", default-features = false } 18 weaver-common = { path = "../weaver-common" } 19 weaver-api = { path = "../weaver-api" } 20 + jacquard = { workspace = true, default-features = false } 21 markdown-weaver = { workspace = true } 22 markdown-weaver-escape = { workspace = true } 23 ··· 28 js-sys = "0.3" 29 console_error_panic_hook = "0.1" 30 31 + [package.metadata.wasm-pack.profile.dev] 32 + # Disable wasm-opt (default for dev) 33 + wasm-opt = false 34 + 35 + [package.metadata.wasm-pack.profile.release] 36 + # Enable with size optimization 37 + wasm-opt = ['-Oz', '--enable-bulk-memory-opt', '--enable-nontrapping-float-to-int']
+25 -6
crates/weaver-renderer/Cargo.toml
··· 6 publish = false 7 8 [features] 9 - default = [] 10 pckt = [] 11 12 [dependencies] 13 n0-future.workspace = true ··· 18 markdown-weaver = { workspace = true } 19 http = "1.3.1" 20 url = "2.5.4" 21 - syntect = { workspace = true, default-features = false, features = ["default-fancy"]} 22 markdown-weaver-escape = { workspace = true, features = ["std"] } 23 thiserror.workspace = true 24 tracing.workspace = true ··· 33 smol_str = { version = "0.3", features = ["serde"] } 34 pulldown-latex = "0.6" 35 mime-sniffer = "0.1.3" 36 - reqwest = { version = "0.12.7", default-features = false, features = [ 37 - "json", 38 - "rustls-tls", 39 - ] } 40 41 [target.'cfg(not(all(target_family = "wasm", target_os = "unknown")))'.dependencies] 42 regex = { version = "1.12" } 43 tokio = { version = "1.28", features = ["rt", "time"] } 44 tokio-util = { version = "0.7.14", features = ["rt"] } 45 ignore = "0.4.23" 46 47 [target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dependencies] 48 regex-lite = { version = "0.1" } 49 50 [dev-dependencies]
··· 6 publish = false 7 8 [features] 9 + default = ["syntax-highlighting", "syntax-css"] 10 pckt = [] 11 + # Basic syntax highlighting (code_pretty.rs) - works in WASM 12 + syntax-highlighting = ["dep:syntect"] 13 + # CSS generation from themes (css.rs) - native only, needs plist + themes 14 + syntax-css = ["syntax-highlighting"] 15 16 [dependencies] 17 n0-future.workspace = true ··· 22 markdown-weaver = { workspace = true } 23 http = "1.3.1" 24 url = "2.5.4" 25 markdown-weaver-escape = { workspace = true, features = ["std"] } 26 thiserror.workspace = true 27 tracing.workspace = true ··· 36 smol_str = { version = "0.3", features = ["serde"] } 37 pulldown-latex = "0.6" 38 mime-sniffer = "0.1.3" 39 40 + # Native: full syntect with onig (fast) + themes for CSS generation 41 [target.'cfg(not(all(target_family = "wasm", target_os = "unknown")))'.dependencies] 42 + syntect = { workspace = true, default-features = false, features = [ 43 + "parsing", 44 + "html", 45 + "default-syntaxes", 46 + "default-themes", 47 + "plist-load", 48 + "regex-onig" 49 + ], optional = true } 50 regex = { version = "1.12" } 51 tokio = { version = "1.28", features = ["rt", "time"] } 52 tokio-util = { version = "0.7.14", features = ["rt"] } 53 ignore = "0.4.23" 54 + reqwest = { version = "0.12.7", default-features = false, features = [ 55 + "json", 56 + "rustls-tls", 57 + ] } 58 59 + # WASM: minimal syntect with fancy-regex (pure Rust), no themes 60 [target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dependencies] 61 + syntect = { workspace = true, default-features = false, features = [ 62 + "parsing", 63 + "html", 64 + "default-syntaxes", 65 + "regex-fancy" 66 + ], optional = true } 67 regex-lite = { version = "0.1" } 68 69 [dev-dependencies]
+46 -28
crates/weaver-renderer/src/atproto/writer.rs
··· 968 self.close_wrapper() 969 } 970 TagEnd::CodeBlock => { 971 - use std::sync::LazyLock; 972 - use syntect::parsing::SyntaxSet; 973 - static SYNTAX_SET: LazyLock<SyntaxSet> = 974 - LazyLock::new(|| SyntaxSet::load_defaults_newlines()); 975 976 - if let Some((lang, buffer)) = self.code_buffer.take() { 977 - if let Some(ref lang_str) = lang { 978 - // Use a temporary String buffer for syntect 979 - let mut temp_output = String::new(); 980 - match crate::code_pretty::highlight( 981 - &SYNTAX_SET, 982 - Some(lang_str), 983 - &buffer, 984 - &mut temp_output, 985 - ) { 986 - Ok(_) => { 987 - self.write(&temp_output)?; 988 - } 989 - Err(_) => { 990 - // Fallback to plain code block 991 - self.write("<pre><code class=\"language-")?; 992 - escape_html(&mut self.writer, lang_str)?; 993 - self.write("\">")?; 994 - escape_html_body_text(&mut self.writer, &buffer)?; 995 - self.write("</code></pre>\n")?; 996 } 997 } 998 } else { 999 - self.write("<pre><code>")?; 1000 escape_html_body_text(&mut self.writer, &buffer)?; 1001 self.write("</code></pre>\n")?; 1002 } 1003 - } else { 1004 - self.write("</code></pre>\n")?; 1005 } 1006 - Ok(()) 1007 } 1008 TagEnd::List(true) => { 1009 self.write("</ol>\n")?;
··· 968 self.close_wrapper() 969 } 970 TagEnd::CodeBlock => { 971 + #[cfg(feature = "syntax-highlighting")] 972 + { 973 + use std::sync::LazyLock; 974 + use syntect::parsing::SyntaxSet; 975 + static SYNTAX_SET: LazyLock<SyntaxSet> = 976 + LazyLock::new(|| SyntaxSet::load_defaults_newlines()); 977 978 + if let Some((lang, buffer)) = self.code_buffer.take() { 979 + if let Some(ref lang_str) = lang { 980 + let mut temp_output = String::new(); 981 + match crate::code_pretty::highlight( 982 + &SYNTAX_SET, 983 + Some(lang_str), 984 + &buffer, 985 + &mut temp_output, 986 + ) { 987 + Ok(_) => { 988 + self.write(&temp_output)?; 989 + } 990 + Err(_) => { 991 + self.write("<pre><code class=\"language-")?; 992 + escape_html(&mut self.writer, lang_str)?; 993 + self.write("\">")?; 994 + escape_html_body_text(&mut self.writer, &buffer)?; 995 + self.write("</code></pre>\n")?; 996 + } 997 } 998 + } else { 999 + self.write("<pre><code>")?; 1000 + escape_html_body_text(&mut self.writer, &buffer)?; 1001 + self.write("</code></pre>\n")?; 1002 } 1003 } else { 1004 + self.write("</code></pre>\n")?; 1005 + } 1006 + Ok(()) 1007 + } 1008 + #[cfg(not(feature = "syntax-highlighting"))] 1009 + { 1010 + if let Some((lang, buffer)) = self.code_buffer.take() { 1011 + if let Some(ref lang_str) = lang { 1012 + self.write("<pre><code class=\"language-")?; 1013 + escape_html(&mut self.writer, lang_str)?; 1014 + self.write("\">")?; 1015 + } else { 1016 + self.write("<pre><code>")?; 1017 + } 1018 escape_html_body_text(&mut self.writer, &buffer)?; 1019 + self.write("</code></pre>\n")?; 1020 + } else { 1021 self.write("</code></pre>\n")?; 1022 } 1023 + Ok(()) 1024 } 1025 } 1026 TagEnd::List(true) => { 1027 self.write("</ol>\n")?;
+2
crates/weaver-renderer/src/lib.rs
··· 26 27 pub mod atproto; 28 pub mod base_html; 29 pub mod code_pretty; 30 pub mod css; 31 pub mod facet; 32 pub mod leaflet;
··· 26 27 pub mod atproto; 28 pub mod base_html; 29 + #[cfg(feature = "syntax-highlighting")] 30 pub mod code_pretty; 31 + #[cfg(feature = "syntax-css")] 32 pub mod css; 33 pub mod facet; 34 pub mod leaflet;