diff --git a/Cargo.lock b/Cargo.lock index 3a156cf1..dcd51961 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -134,7 +134,7 @@ dependencies = [ "funty", "radium", "tap", - "wyz 0.5.1", + "wyz", ] [[package]] @@ -320,16 +320,6 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" -[[package]] -name = "crossbeam-channel" -version = "0.5.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" -dependencies = [ - "cfg-if", - "crossbeam-utils", -] - [[package]] name = "crossbeam-deque" version = "0.8.3" @@ -396,16 +386,6 @@ dependencies = [ "syn 2.0.63", ] -[[package]] -name = "ctor" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad291aa74992b9b7a7e88c38acbbf6ad7e107f1d90ee8775b7bc1fc3394f485c" -dependencies = [ - "quote", - "syn 2.0.63", -] - [[package]] name = "dashmap" version = "5.5.3" @@ -744,16 +724,6 @@ version = "0.2.150" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" -[[package]] -name = "libloading" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c571b676ddfc9a8c12f1f3d3085a7b163966a8fd8098a90640953ce5f6170161" -dependencies = [ - "cfg-if", - "windows-sys", -] - [[package]] name = "lightningcss" version = "1.0.0-alpha.59" @@ -800,22 +770,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "lightningcss-napi" -version = "0.3.0" -dependencies = [ - "crossbeam-channel", - "cssparser", - "lightningcss", - "napi", - "parcel_sourcemap", - "rayon", - "serde", - "serde-detach", - "serde_bytes", - "smallvec", -] - [[package]] name = "lightningcss_c_bindings" version = "0.1.0" @@ -826,17 +780,6 @@ dependencies = [ "parcel_sourcemap", ] -[[package]] -name = "lightningcss_node" -version = "0.1.0" -dependencies = [ - "jemallocator", - "lightningcss-napi", - "napi", - "napi-build", - "napi-derive", -] - [[package]] name = "linux-raw-sys" version = "0.4.10" @@ -886,65 +829,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" -[[package]] -name = "napi" -version = "2.15.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72e0dc78e0524286630914db66e31bad70160e379705a9ce92e0161ce2389d89" -dependencies = [ - "bitflags 2.4.1", - "ctor", - "napi-derive", - "napi-sys", - "once_cell", - "serde", - "serde_json", -] - -[[package]] -name = "napi-build" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebd4419172727423cf30351406c54f6cc1b354a2cfb4f1dba3e6cd07f6d5522b" - -[[package]] -name = "napi-derive" -version = "2.15.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e56bd9f0bd84c1f138c5cb22bbf394f75d796b24dad689599ca94cf94e61cc21" -dependencies = [ - "cfg-if", - "convert_case", - "napi-derive-backend", - "proc-macro2", - "quote", - "syn 2.0.63", -] - -[[package]] -name = "napi-derive-backend" -version = "1.0.61" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d03b8f403a37007cad225039fc0323b961bb40d697eea744140920ebb689ff1d" -dependencies = [ - "convert_case", - "once_cell", - "proc-macro2", - "quote", - "regex", - "semver", - "syn 2.0.63", -] - -[[package]] -name = "napi-sys" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2503fa6af34dc83fb74888df8b22afe933b58d37daf7d80424b1c60c68196b8b" -dependencies = [ - "libloading", -] - [[package]] name = "nom" version = "7.1.3" @@ -1446,12 +1330,6 @@ version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" -[[package]] -name = "semver" -version = "1.0.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" - [[package]] name = "serde" version = "1.0.201" @@ -1461,25 +1339,6 @@ dependencies = [ "serde_derive", ] -[[package]] -name = "serde-detach" -version = "0.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c621150da442b6a854bb63c431347bcd4de19219a3e1f06fd744208ded057288" -dependencies = [ - "serde", - "wyz 0.2.0", -] - -[[package]] -name = "serde_bytes" -version = "0.11.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab33ec92f677585af6d88c65593ae2375adde54efdbf16d597f2cbc7a6d368ff" -dependencies = [ - "serde", -] - [[package]] name = "serde_derive" version = "1.0.201" @@ -1961,12 +1820,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" -[[package]] -name = "wyz" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214" - [[package]] name = "wyz" version = "0.5.1" diff --git a/Cargo.toml b/Cargo.toml index 7b1cb511..f0789af4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,5 @@ [workspace] members = [ - "node", - "napi", "selectors", "c", "derive", @@ -96,10 +94,6 @@ required-features = ["cli"] name = "custom_at_rule" required-features = ["visitor"] -[[example]] -name = "serialize" -required-features = ["serde"] - [profile.release] lto = true codegen-units = 1 diff --git a/c/lightningcss.h b/c/lightningcss.h index 8f915054..3e13bccf 100644 --- a/c/lightningcss.h +++ b/c/lightningcss.h @@ -102,14 +102,14 @@ typedef struct CssModulePlaceholder { struct CssModuleReference reference; } CssModulePlaceholder; -typedef struct ToCssResult { +typedef struct ToTypstResult { struct RawString code; struct RawString map; struct CssModuleExport *exports; uintptr_t exports_len; struct CssModulePlaceholder *references; uintptr_t references_len; -} ToCssResult; +} ToTypstResult; typedef struct PseudoClasses { const char *hover; @@ -119,7 +119,7 @@ typedef struct PseudoClasses { const char *focus_within; } PseudoClasses; -typedef struct ToCssOptions { +typedef struct ToTypstOptions { bool minify; bool source_map; const char *input_source_map; @@ -128,7 +128,7 @@ typedef struct ToCssOptions { struct Targets targets; bool analyze_dependencies; struct PseudoClasses pseudo_classes; -} ToCssOptions; +} ToTypstOptions; bool lightningcss_browserslist_to_targets(const char *query, struct Targets *targets, @@ -143,13 +143,13 @@ bool lightningcss_stylesheet_transform(struct StyleSheet *stylesheet, struct TransformOptions options, struct CssError **error); -struct ToCssResult lightningcss_stylesheet_to_css(struct StyleSheet *stylesheet, - struct ToCssOptions options, - struct CssError **error); +struct ToTypstResult lightningcss_stylesheet_to_typst(struct StyleSheet *stylesheet, + struct ToTypstOptions options, + struct CssError **error); void lightningcss_stylesheet_free(struct StyleSheet *stylesheet); -void lightningcss_to_css_result_free(struct ToCssResult result); +void lightningcss_to_typst_result_free(struct ToTypstResult result); const char *lightningcss_error_message(struct CssError *error); diff --git a/c/src/lib.rs b/c/src/lib.rs index 759a18db..4a95b345 100644 --- a/c/src/lib.rs +++ b/c/src/lib.rs @@ -192,7 +192,7 @@ impl Into for TransformOptions { } #[repr(C)] -pub struct ToCssOptions { +pub struct ToTypstOptions { minify: bool, source_map: bool, input_source_map: *const c_char, @@ -311,16 +311,16 @@ pub extern "C" fn lightningcss_stylesheet_transform( } #[no_mangle] -pub extern "C" fn lightningcss_stylesheet_to_css( +pub extern "C" fn lightningcss_stylesheet_to_typst( stylesheet: *mut StyleSheetWrapper, - options: ToCssOptions, + options: ToTypstOptions, error: *mut *mut CssError, -) -> ToCssResult { +) -> ToTypstResult { let wrapper = unsafe { stylesheet.as_mut() }.unwrap(); let mut source_map = if options.source_map { let mut sm = SourceMap::new("/"); sm.add_source(&wrapper.stylesheet.sources[0]); - unwrap!(sm.set_source_content(0, wrapper.source), error, ToCssResult::default()); + unwrap!(sm.set_source_content(0, wrapper.source), error, ToTypstResult::default()); Some(sm) } else { None @@ -351,7 +351,7 @@ pub extern "C" fn lightningcss_stylesheet_to_css( }, }; - let res = unwrap!(wrapper.stylesheet.to_css(opts), error, ToCssResult::default()); + let res = unwrap!(wrapper.stylesheet.to_css(opts), error, ToTypstResult::default()); let map = if let Some(mut source_map) = source_map { if !options.input_source_map.is_null() { @@ -361,12 +361,12 @@ pub extern "C" fn lightningcss_stylesheet_to_css( let mut sm = unwrap!( SourceMap::from_json("/", input_source_map), error, - ToCssResult::default() + ToTypstResult::default() ); - unwrap!(source_map.extends(&mut sm), error, ToCssResult::default()); + unwrap!(source_map.extends(&mut sm), error, ToTypstResult::default()); } - unwrap!(source_map.to_json(None), error, ToCssResult::default()).into() + unwrap!(source_map.to_json(None), error, ToTypstResult::default()).into() } else { RawString::default() }; @@ -412,7 +412,7 @@ pub extern "C" fn lightningcss_stylesheet_to_css( (std::ptr::null_mut(), 0) }; - ToCssResult { + ToTypstResult { code: res.code.into(), map, exports, @@ -430,7 +430,7 @@ pub extern "C" fn lightningcss_stylesheet_free(stylesheet: *mut StyleSheetWrappe } #[repr(C)] -pub struct ToCssResult { +pub struct ToTypstResult { code: RawString, map: RawString, exports: *mut CssModuleExport, @@ -439,9 +439,9 @@ pub struct ToCssResult { references_len: usize, } -impl Default for ToCssResult { +impl Default for ToTypstResult { fn default() -> Self { - ToCssResult { + ToTypstResult { code: RawString::default(), map: RawString::default(), exports: std::ptr::null_mut(), @@ -452,7 +452,7 @@ impl Default for ToCssResult { } } -impl Drop for ToCssResult { +impl Drop for ToTypstResult { fn drop(&mut self) { if !self.exports.is_null() { let exports = unsafe { Vec::from_raw_parts(self.exports, self.exports_len, self.exports_len) }; @@ -469,7 +469,7 @@ impl Drop for ToCssResult { } #[no_mangle] -pub extern "C" fn lightningcss_to_css_result_free(result: ToCssResult) { +pub extern "C" fn lightningcss_to_typst_result_free(result: ToTypstResult) { drop(result) } diff --git a/c/test.c b/c/test.c index 7c325a3d..5c30a6d6 100644 --- a/c/test.c +++ b/c/test.c @@ -40,13 +40,13 @@ int main() if (!lightningcss_stylesheet_transform(stylesheet, transform_opts, &error)) goto cleanup; - ToCssOptions to_css_opts = { + ToTypstOptions to_css_opts = { .minify = true, .source_map = true, .pseudo_classes = { .hover = "is-hovered"}}; - ToCssResult result = lightningcss_stylesheet_to_css(stylesheet, to_css_opts, &error); + ToTypstResult result = lightningcss_stylesheet_to_typst(stylesheet, to_css_opts, &error); if (error) goto cleanup; @@ -89,7 +89,7 @@ int main() cleanup: lightningcss_stylesheet_free(stylesheet); - lightningcss_to_css_result_free(result); + lightningcss_to_typst_result_free(result); if (error) { diff --git a/derive/src/lib.rs b/derive/src/lib.rs index 12241491..fbcc2e1b 100644 --- a/derive/src/lib.rs +++ b/derive/src/lib.rs @@ -1,7 +1,7 @@ use proc_macro::TokenStream; mod parse; -mod to_css; +mod to_typst; mod visit; #[proc_macro_derive(Visit, attributes(visit, skip_visit, skip_type, visit_types))] @@ -14,7 +14,7 @@ pub fn derive_parse(input: TokenStream) -> TokenStream { parse::derive_parse(input) } -#[proc_macro_derive(ToCss, attributes(css))] -pub fn derive_to_css(input: TokenStream) -> TokenStream { - to_css::derive_to_css(input) +#[proc_macro_derive(ToTypst, attributes(css))] +pub fn derive_to_typst(input: TokenStream) -> TokenStream { + to_typst::derive_to_typst(input) } diff --git a/derive/src/to_css.rs b/derive/src/to_typst.rs similarity index 91% rename from derive/src/to_css.rs rename to derive/src/to_typst.rs index 739a16d4..15ba06b0 100644 --- a/derive/src/to_css.rs +++ b/derive/src/to_typst.rs @@ -6,7 +6,7 @@ use syn::{parse_macro_input, Data, DataEnum, DeriveInput, Fields, Ident, Type}; use crate::parse::CssOptions; -pub fn derive_to_css(input: TokenStream) -> TokenStream { +pub fn derive_to_typst(input: TokenStream) -> TokenStream { let DeriveInput { ident, data, @@ -24,8 +24,8 @@ pub fn derive_to_css(input: TokenStream) -> TokenStream { }; let output = quote! { - impl #impl_generics ToCss for #ident #ty_generics #where_clause { - fn to_css(&self, dest: &mut Printer) -> Result<(), PrinterError> + impl #impl_generics ToTypst for #ident #ty_generics #where_clause { + fn to_typst(&self, dest: &mut Printer) -> Result<(), PrinterError> where W: std::fmt::Write, { @@ -93,7 +93,7 @@ fn derive_enum(data: &DataEnum, opts: &CssOptions) -> TokenStream2 { quote! { if let Some(v) = #name { #space - v.to_css(dest)?; + v.to_typst(dest)?; #after_space } } @@ -101,11 +101,11 @@ fn derive_enum(data: &DataEnum, opts: &CssOptions) -> TokenStream2 { needs_space = NeedsSpace::Yes; quote! { #space - #name.to_css(dest)?; + #name.to_typst(dest)?; } } } else { - quote! { #name.to_css(dest) } + quote! { #name.to_typst(dest) } }); } diff --git a/examples/custom_at_rule.rs b/examples/custom_at_rule.rs index 9c091e6b..24474d5c 100644 --- a/examples/custom_at_rule.rs +++ b/examples/custom_at_rule.rs @@ -10,7 +10,7 @@ use lightningcss::{ selector::{Component, Selector}, stylesheet::{ParserOptions, PrinterOptions, StyleSheet}, targets::Browsers, - traits::{AtRuleParser, ToCss}, + traits::{AtRuleParser, ToTypst}, values::{ color::{CssColor, RGBA}, length::LengthValue, @@ -290,8 +290,8 @@ impl<'i, V: Visitor<'i, AtRule>> Visit<'i, AtRule, V> for AtRule { } } -impl ToCss for AtRule { - fn to_css(&self, dest: &mut Printer) -> Result<(), PrinterError> { +impl ToTypst for AtRule { + fn to_typst(&self, dest: &mut Printer) -> Result<(), PrinterError> { match self { AtRule::Tailwind(rule) => { let _ = rule.loc; // TODO: source maps diff --git a/examples/schema.rs b/examples/schema.rs deleted file mode 100644 index 9bfe3f69..00000000 --- a/examples/schema.rs +++ /dev/null @@ -1,8 +0,0 @@ -fn main() { - #[cfg(feature = "jsonschema")] - { - let schema = schemars::schema_for!(lightningcss::stylesheet::StyleSheet); - let output = serde_json::to_string_pretty(&schema).unwrap(); - let _ = std::fs::write("node/ast.json", output); - } -} diff --git a/examples/serialize.rs b/examples/serialize.rs deleted file mode 100644 index 00d37210..00000000 --- a/examples/serialize.rs +++ /dev/null @@ -1,27 +0,0 @@ -fn main() { - parse(); -} - -#[cfg(feature = "serde")] -fn parse() { - use lightningcss::stylesheet::{ParserOptions, StyleSheet}; - use std::{env, fs}; - - let args: Vec = env::args().collect(); - let contents = fs::read_to_string(&args[1]).unwrap(); - let stylesheet = StyleSheet::parse( - &contents, - ParserOptions { - filename: args[1].clone(), - ..ParserOptions::default() - }, - ) - .unwrap(); - let json = serde_json::to_string(&stylesheet).unwrap(); - println!("{}", json); -} - -#[cfg(not(feature = "serde"))] -fn parse() { - panic!("serde feature is not enabled") -} diff --git a/napi/Cargo.toml b/napi/Cargo.toml deleted file mode 100644 index 8807f557..00000000 --- a/napi/Cargo.toml +++ /dev/null @@ -1,25 +0,0 @@ -[package] -authors = ["Devon Govett "] -name = "lightningcss-napi" -version = "0.3.0" -description = "Node-API bindings for Lightning CSS" -license = "MPL-2.0" -repository = "https://github.com/parcel-bundler/lightningcss" -edition = "2021" - -[features] -default = [] -visitor = ["lightningcss/visitor"] -bundler = ["dep:crossbeam-channel", "dep:rayon"] - -[dependencies] -serde = { version = "1.0.201", features = ["derive"] } -serde_bytes = "0.11.5" -cssparser = "0.33.0" -lightningcss = { version = "1.0.0-alpha.56", path = "../", features = ["nodejs", "serde"] } -parcel_sourcemap = { version = "2.1.1", features = ["json"] } -serde-detach = "0.0.1" -smallvec = { version = "1.7.0", features = ["union"] } -napi = {version = "2", default-features = false, features = ["napi4", "napi5", "serde-json"]} -crossbeam-channel = { version = "0.5.6", optional = true } -rayon = { version = "1.5.1", optional = true } diff --git a/napi/src/at_rule_parser.rs b/napi/src/at_rule_parser.rs deleted file mode 100644 index 919eda2d..00000000 --- a/napi/src/at_rule_parser.rs +++ /dev/null @@ -1,215 +0,0 @@ -use std::collections::HashMap; - -use cssparser::*; -use lightningcss::{ - declaration::DeclarationBlock, - error::ParserError, - rules::{CssRuleList, Location}, - stylesheet::ParserOptions, - traits::{AtRuleParser, ToCss}, - values::{ - string::CowArcStr, - syntax::{ParsedComponent, SyntaxString}, - }, -}; -use serde::{Deserialize, Deserializer, Serialize}; - -#[derive(Deserialize, Debug, Clone)] -pub struct CustomAtRuleConfig { - #[serde(default, deserialize_with = "deserialize_prelude")] - prelude: Option, - body: Option, -} - -fn deserialize_prelude<'de, D>(deserializer: D) -> Result