From fbbca227830c653fff8e0b81f1d315149e130fae Mon Sep 17 00:00:00 2001 From: Arif Driessen Date: Mon, 15 May 2023 02:34:33 +0200 Subject: [PATCH] Wasm feature gate (#622) * conditional wasm * derive ts * ts export * incl wasm feature --- docx-core/Cargo.toml | 11 ++++++---- docx-core/src/documents/elements/fld_char.rs | 5 +++-- .../src/documents/elements/font_scheme.rs | 15 ++++++++------ .../src/documents/elements/instr_hyperlink.rs | 5 +++-- docx-core/src/documents/elements/instr_toc.rs | 10 ++++++---- docx-core/src/documents/elements/pic.rs | 5 +++-- docx-core/src/documents/elements/shape.rs | 10 ++++++---- .../documents/elements/table_cell_property.rs | 5 +++-- .../src/documents/elements/table_property.rs | 3 ++- docx-core/src/documents/theme.rs | 5 +++-- docx-core/src/types/alignment_type.rs | 3 ++- docx-core/src/types/border_position.rs | 5 +++-- docx-core/src/types/border_type.rs | 3 ++- docx-core/src/types/break_type.rs | 3 ++- docx-core/src/types/doc_grid_type.rs | 3 ++- docx-core/src/types/drawing_position.rs | 20 +++++++++++-------- docx-core/src/types/field_char_type.rs | 8 +++++--- docx-core/src/types/font_pitch_type.rs | 3 ++- docx-core/src/types/height_rule.rs | 3 ++- docx-core/src/types/hyperlink_type.rs | 8 +++++--- docx-core/src/types/level_suffix_type.rs | 3 ++- docx-core/src/types/line_spacing_type.rs | 3 ++- docx-core/src/types/page_orientation_type.rs | 3 ++- docx-core/src/types/relative_from_type.rs | 15 ++++++++------ docx-core/src/types/section_type.rs | 3 ++- docx-core/src/types/shd_type.rs | 3 ++- docx-core/src/types/special_indent_type.rs | 3 ++- docx-core/src/types/style_type.rs | 3 ++- docx-core/src/types/tab_leader_type.rs | 3 ++- docx-core/src/types/tab_value_type.rs | 3 ++- docx-core/src/types/table_alignment_type.rs | 3 ++- docx-core/src/types/table_layout_type.rs | 3 ++- docx-core/src/types/text_direction_type.rs | 3 ++- docx-core/src/types/vert_align_type.rs | 3 ++- docx-core/src/types/vertical_align_type.rs | 3 ++- docx-core/src/types/vertical_merge_type.rs | 3 ++- docx-core/src/types/width_type.rs | 3 ++- docx-wasm/Cargo.toml | 2 +- 38 files changed, 124 insertions(+), 74 deletions(-) diff --git a/docx-core/Cargo.toml b/docx-core/Cargo.toml index e8a37d3..0351093 100644 --- a/docx-core/Cargo.toml +++ b/docx-core/Cargo.toml @@ -17,19 +17,22 @@ keywords = [ name = "docx_rs" path = "src/lib.rs" +[features] +wasm = ["wasm-bindgen", "ts-rs"] + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] xml-rs = "0.8.4" -wasm-bindgen = "0.2.78" thiserror = "1.0" zip = { version = "0.6.3", default-features = false, features = ["deflate"] } serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" +serde_json = {version = "1.0" } base64 = "0.13.1" image = { version = "0.24.4", default-features = false, features=["gif", "jpeg", "png", "bmp", "tiff"] } -ts-rs = "6.1" +wasm-bindgen = { version = "0.2.78", optional = true } +ts-rs = { version = "6.1", optional = true } [dev-dependencies] pretty_assertions = "1.3.0" -insta = "1.16" +insta = "1.16" \ No newline at end of file diff --git a/docx-core/src/documents/elements/fld_char.rs b/docx-core/src/documents/elements/fld_char.rs index 395a25d..b7b100e 100644 --- a/docx-core/src/documents/elements/fld_char.rs +++ b/docx-core/src/documents/elements/fld_char.rs @@ -4,8 +4,9 @@ use crate::documents::*; use crate::types::*; use crate::xml_builder::*; -#[derive(Serialize, Debug, Clone, PartialEq, ts_rs::TS)] -#[ts(export)] +#[derive(Serialize, Debug, Clone, PartialEq)] +#[cfg_attr(feature = "wasm", derive(ts_rs::TS))] +#[cfg_attr(feature = "wasm", ts(export))] #[serde(rename_all = "camelCase")] pub struct FieldChar { pub field_char_type: FieldCharType, diff --git a/docx-core/src/documents/elements/font_scheme.rs b/docx-core/src/documents/elements/font_scheme.rs index da68a65..8a198fa 100644 --- a/docx-core/src/documents/elements/font_scheme.rs +++ b/docx-core/src/documents/elements/font_scheme.rs @@ -1,15 +1,17 @@ use serde::Serialize; -#[derive(Debug, Clone, PartialEq, Serialize, ts_rs::TS)] -#[ts(export)] +#[derive(Debug, Clone, PartialEq, Serialize)] +#[cfg_attr(feature = "wasm", derive(ts_rs::TS))] +#[cfg_attr(feature = "wasm", ts(export))] #[serde(rename_all = "camelCase")] pub struct FontSchemeFont { pub script: String, pub typeface: String, } -#[derive(Debug, Clone, PartialEq, Serialize, Default, ts_rs::TS)] -#[ts(export)] +#[derive(Debug, Clone, PartialEq, Serialize, Default)] +#[cfg_attr(feature = "wasm", derive(ts_rs::TS))] +#[cfg_attr(feature = "wasm", ts(export))] #[serde(rename_all = "camelCase")] pub struct FontGroup { pub latin: String, @@ -18,8 +20,9 @@ pub struct FontGroup { pub fonts: Vec, } -#[derive(Debug, Clone, PartialEq, Serialize, Default, ts_rs::TS)] -#[ts(export)] +#[derive(Debug, Clone, PartialEq, Serialize, Default)] +#[cfg_attr(feature = "wasm", derive(ts_rs::TS))] +#[cfg_attr(feature = "wasm", ts(export))] #[serde(rename_all = "camelCase")] pub struct FontScheme { pub major_font: FontGroup, diff --git a/docx-core/src/documents/elements/instr_hyperlink.rs b/docx-core/src/documents/elements/instr_hyperlink.rs index 7b7e166..242ec90 100644 --- a/docx-core/src/documents/elements/instr_hyperlink.rs +++ b/docx-core/src/documents/elements/instr_hyperlink.rs @@ -1,8 +1,9 @@ use serde::Serialize; // https://c-rex.net/projects/samples/ooxml/e1/Part4/OOXML_P4_DOCX_HYPERLINKHYPERLINK_topic_ID0EFYG1.html -#[derive(Serialize, Debug, Clone, PartialEq, Default, ts_rs::TS)] -#[ts(export)] +#[derive(Serialize, Debug, Clone, PartialEq, Default)] +#[cfg_attr(feature = "wasm", derive(ts_rs::TS))] +#[cfg_attr(feature = "wasm", ts(export))] #[serde(rename_all = "camelCase")] pub struct InstrHyperlink { pub target: String, diff --git a/docx-core/src/documents/elements/instr_toc.rs b/docx-core/src/documents/elements/instr_toc.rs index 63fbe75..e9617b3 100644 --- a/docx-core/src/documents/elements/instr_toc.rs +++ b/docx-core/src/documents/elements/instr_toc.rs @@ -2,8 +2,9 @@ use serde::Serialize; use crate::documents::*; -#[derive(Serialize, Debug, Clone, PartialEq, Default, ts_rs::TS)] -#[ts(export)] +#[derive(Serialize, Debug, Clone, PartialEq, Default)] +#[cfg_attr(feature = "wasm", derive(ts_rs::TS))] +#[cfg_attr(feature = "wasm", ts(export))] pub struct StyleWithLevel(pub (String, usize)); impl StyleWithLevel { @@ -12,8 +13,9 @@ impl StyleWithLevel { } } // https://c-rex.net/projects/samples/ooxml/e1/Part4/OOXML_P4_DOCX_TOCTOC_topic_ID0ELZO1.html -#[derive(Serialize, Debug, Clone, PartialEq, Default, ts_rs::TS)] -#[ts(export)] +#[derive(Serialize, Debug, Clone, PartialEq, Default)] +#[cfg_attr(feature = "wasm", derive(ts_rs::TS))] +#[cfg_attr(feature = "wasm", ts(export))] #[serde(rename_all = "camelCase")] pub struct InstrToC { // \o If no heading range is specified, all heading levels used in the document are listed. diff --git a/docx-core/src/documents/elements/pic.rs b/docx-core/src/documents/elements/pic.rs index 1397947..18b310a 100644 --- a/docx-core/src/documents/elements/pic.rs +++ b/docx-core/src/documents/elements/pic.rs @@ -5,8 +5,9 @@ use crate::documents::*; use crate::types::*; use crate::xml_builder::*; -#[derive(Debug, Clone, Serialize, PartialEq, ts_rs::TS)] -#[ts(export)] +#[derive(Debug, Clone, Serialize, PartialEq)] +#[cfg_attr(feature = "wasm", derive(ts_rs::TS))] +#[cfg_attr(feature = "wasm", ts(export))] #[serde(rename_all = "camelCase")] pub struct Pic { pub id: String, diff --git a/docx-core/src/documents/elements/shape.rs b/docx-core/src/documents/elements/shape.rs index 22da744..f69bc46 100644 --- a/docx-core/src/documents/elements/shape.rs +++ b/docx-core/src/documents/elements/shape.rs @@ -1,7 +1,8 @@ use serde::Serialize; -#[derive(Serialize, Debug, Clone, PartialEq, Default, ts_rs::TS)] -#[ts(export)] +#[derive(Serialize, Debug, Clone, PartialEq, Default)] +#[cfg_attr(feature = "wasm", derive(ts_rs::TS))] +#[cfg_attr(feature = "wasm", ts(export))] #[serde(rename_all = "camelCase")] pub struct Shape { #[serde(skip_serializing_if = "Option::is_none")] @@ -11,8 +12,9 @@ pub struct Shape { } // Experimental, For now reader only. -#[derive(Serialize, Debug, Clone, PartialEq, Default, ts_rs::TS)] -#[ts(export)] +#[derive(Serialize, Debug, Clone, PartialEq, Default)] +#[cfg_attr(feature = "wasm", derive(ts_rs::TS))] +#[cfg_attr(feature = "wasm", ts(export))] #[serde(rename_all = "camelCase")] pub struct ImageData { pub id: String, diff --git a/docx-core/src/documents/elements/table_cell_property.rs b/docx-core/src/documents/elements/table_cell_property.rs index 5b5733a..0c1f77e 100644 --- a/docx-core/src/documents/elements/table_cell_property.rs +++ b/docx-core/src/documents/elements/table_cell_property.rs @@ -1,12 +1,13 @@ -use wasm_bindgen::prelude::*; use serde::Serialize; +#[cfg(feature = "wasm")] +use wasm_bindgen::prelude::*; use super::*; use crate::documents::BuildXML; use crate::types::*; use crate::xml_builder::*; -#[wasm_bindgen] +#[cfg_attr(feature = "wasm", wasm_bindgen)] #[derive(Serialize, Debug, Clone, PartialEq)] #[serde(rename_all = "camelCase")] pub struct TableCellProperty { diff --git a/docx-core/src/documents/elements/table_property.rs b/docx-core/src/documents/elements/table_property.rs index 4e1ecbd..d61e145 100644 --- a/docx-core/src/documents/elements/table_property.rs +++ b/docx-core/src/documents/elements/table_property.rs @@ -1,4 +1,5 @@ use serde::Serialize; +#[cfg(feature = "wasm")] use wasm_bindgen::prelude::*; use super::*; @@ -6,7 +7,7 @@ use crate::documents::BuildXML; use crate::types::*; use crate::xml_builder::*; -#[wasm_bindgen] +#[cfg_attr(feature = "wasm", wasm_bindgen)] #[derive(Debug, Clone, PartialEq, Serialize)] #[serde(rename_all = "camelCase")] pub struct TableProperty { diff --git a/docx-core/src/documents/theme.rs b/docx-core/src/documents/theme.rs index 2aea744..8ca4eef 100644 --- a/docx-core/src/documents/theme.rs +++ b/docx-core/src/documents/theme.rs @@ -2,8 +2,9 @@ use serde::Serialize; use super::*; -#[derive(Debug, Clone, PartialEq, Serialize, Default, ts_rs::TS)] -#[ts(export)] +#[derive(Debug, Clone, PartialEq, Serialize, Default)] +#[cfg_attr(feature = "wasm", derive(ts_rs::TS))] +#[cfg_attr(feature = "wasm", ts(export))] #[serde(rename_all = "camelCase")] pub struct Theme { pub font_schema: FontScheme, diff --git a/docx-core/src/types/alignment_type.rs b/docx-core/src/types/alignment_type.rs index f5e5835..d050b34 100644 --- a/docx-core/src/types/alignment_type.rs +++ b/docx-core/src/types/alignment_type.rs @@ -1,10 +1,11 @@ use std::fmt; use std::str::FromStr; +#[cfg(feature = "wasm")] use wasm_bindgen::prelude::*; use super::errors; -#[wasm_bindgen] +#[cfg_attr(feature = "wasm", wasm_bindgen)] #[derive(Copy, Clone, Debug)] pub enum AlignmentType { Both, diff --git a/docx-core/src/types/border_position.rs b/docx-core/src/types/border_position.rs index dcabb35..2d8b983 100644 --- a/docx-core/src/types/border_position.rs +++ b/docx-core/src/types/border_position.rs @@ -1,7 +1,8 @@ use serde::Serialize; +#[cfg(feature = "wasm")] use wasm_bindgen::prelude::*; -#[wasm_bindgen] +#[cfg_attr(feature = "wasm", wasm_bindgen)] #[derive(Debug, Clone, PartialEq, Serialize)] #[serde(rename_all = "camelCase")] pub enum TableBorderPosition { @@ -13,7 +14,7 @@ pub enum TableBorderPosition { InsideV, } -#[wasm_bindgen] +#[cfg_attr(feature = "wasm", wasm_bindgen)] #[derive(Debug, Clone, PartialEq, Serialize)] #[serde(rename_all = "camelCase")] pub enum TableCellBorderPosition { diff --git a/docx-core/src/types/border_type.rs b/docx-core/src/types/border_type.rs index 7efc87c..d3212de 100644 --- a/docx-core/src/types/border_type.rs +++ b/docx-core/src/types/border_type.rs @@ -3,12 +3,13 @@ // use serde::{Deserialize, Serialize}; use std::fmt; +#[cfg(feature = "wasm")] use wasm_bindgen::prelude::*; use super::errors; use std::str::FromStr; -#[wasm_bindgen] +#[cfg_attr(feature = "wasm", wasm_bindgen)] #[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub enum BorderType { diff --git a/docx-core/src/types/break_type.rs b/docx-core/src/types/break_type.rs index 16b72ed..44fad37 100644 --- a/docx-core/src/types/break_type.rs +++ b/docx-core/src/types/break_type.rs @@ -6,11 +6,12 @@ use serde::{Deserialize, Serialize}; use std::fmt; use std::str::FromStr; +#[cfg(feature = "wasm")] use wasm_bindgen::prelude::*; use super::errors; -#[wasm_bindgen] +#[cfg_attr(feature = "wasm", wasm_bindgen)] #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq)] pub enum BreakType { Page, diff --git a/docx-core/src/types/doc_grid_type.rs b/docx-core/src/types/doc_grid_type.rs index 941574b..56e45bf 100644 --- a/docx-core/src/types/doc_grid_type.rs +++ b/docx-core/src/types/doc_grid_type.rs @@ -2,11 +2,12 @@ use serde::{Deserialize, Serialize}; use std::fmt; use std::str::FromStr; +#[cfg(feature = "wasm")] use wasm_bindgen::prelude::*; use super::errors; -#[wasm_bindgen] +#[cfg_attr(feature = "wasm", wasm_bindgen)] #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq)] #[serde(rename_all = "camelCase")] pub enum DocGridType { diff --git a/docx-core/src/types/drawing_position.rs b/docx-core/src/types/drawing_position.rs index 298ed6b..1eda236 100644 --- a/docx-core/src/types/drawing_position.rs +++ b/docx-core/src/types/drawing_position.rs @@ -1,20 +1,23 @@ use serde::Serialize; use std::fmt; +#[cfg(feature = "wasm")] use wasm_bindgen::prelude::*; -#[wasm_bindgen] -#[derive(Debug, Clone, Copy, Serialize, PartialEq, ts_rs::TS)] -#[ts(export)] +#[cfg_attr(feature = "wasm", wasm_bindgen)] +#[derive(Debug, Clone, Copy, Serialize, PartialEq)] +#[cfg_attr(feature = "wasm", derive(ts_rs::TS))] +#[cfg_attr(feature = "wasm", ts(export))] #[serde(rename_all = "camelCase")] pub enum DrawingPositionType { Anchor, Inline, } -#[wasm_bindgen] -#[derive(Debug, Clone, Copy, Serialize, PartialEq, ts_rs::TS)] -#[ts(export)] +#[cfg_attr(feature = "wasm", wasm_bindgen)] +#[derive(Debug, Clone, Copy, Serialize, PartialEq)] +#[cfg_attr(feature = "wasm", derive(ts_rs::TS))] +#[cfg_attr(feature = "wasm", ts(export))] #[serde(rename_all = "camelCase")] pub enum PicAlign { Left, @@ -36,8 +39,9 @@ impl fmt::Display for PicAlign { } } -#[derive(Debug, Clone, Copy, Serialize, PartialEq, ts_rs::TS)] -#[ts(export)] +#[derive(Debug, Clone, Copy, Serialize, PartialEq)] +#[cfg_attr(feature = "wasm", derive(ts_rs::TS))] +#[cfg_attr(feature = "wasm", ts(export))] #[serde(rename_all = "camelCase")] pub enum DrawingPosition { Offset(i32), diff --git a/docx-core/src/types/field_char_type.rs b/docx-core/src/types/field_char_type.rs index 7626497..8e8af55 100644 --- a/docx-core/src/types/field_char_type.rs +++ b/docx-core/src/types/field_char_type.rs @@ -5,13 +5,15 @@ use serde::{Deserialize, Serialize}; // use std::fmt; use std::str::FromStr; +#[cfg(feature = "wasm")] use wasm_bindgen::prelude::*; use super::errors; -#[wasm_bindgen] -#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, ts_rs::TS)] -#[ts(export)] +#[cfg_attr(feature = "wasm", wasm_bindgen)] +#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq)] +#[cfg_attr(feature = "wasm", derive(ts_rs::TS))] +#[cfg_attr(feature = "wasm", ts(export))] #[serde(rename_all = "camelCase")] pub enum FieldCharType { Begin, diff --git a/docx-core/src/types/font_pitch_type.rs b/docx-core/src/types/font_pitch_type.rs index 325f7e1..d4ef2dd 100644 --- a/docx-core/src/types/font_pitch_type.rs +++ b/docx-core/src/types/font_pitch_type.rs @@ -1,7 +1,8 @@ use std::fmt; +#[cfg(feature = "wasm")] use wasm_bindgen::prelude::*; -#[wasm_bindgen] +#[cfg_attr(feature = "wasm", wasm_bindgen)] #[derive(Copy, Clone, Debug)] pub enum FontPitchType { Default, diff --git a/docx-core/src/types/height_rule.rs b/docx-core/src/types/height_rule.rs index dbabf53..d88e85e 100644 --- a/docx-core/src/types/height_rule.rs +++ b/docx-core/src/types/height_rule.rs @@ -1,4 +1,5 @@ use std::fmt; +#[cfg(feature = "wasm")] use wasm_bindgen::prelude::*; use serde::Serialize; @@ -6,7 +7,7 @@ use serde::Serialize; use super::errors; use std::str::FromStr; -#[wasm_bindgen] +#[cfg_attr(feature = "wasm", wasm_bindgen)] #[derive(Debug, Clone, Copy, PartialEq, Serialize)] #[serde(rename_all = "camelCase")] pub enum HeightRule { diff --git a/docx-core/src/types/hyperlink_type.rs b/docx-core/src/types/hyperlink_type.rs index 45d3199..4a2dbce 100644 --- a/docx-core/src/types/hyperlink_type.rs +++ b/docx-core/src/types/hyperlink_type.rs @@ -1,4 +1,5 @@ use std::fmt; +#[cfg(feature = "wasm")] use wasm_bindgen::prelude::*; use serde::Serialize; @@ -6,10 +7,11 @@ use serde::Serialize; use super::errors; use std::str::FromStr; -#[wasm_bindgen] -#[derive(Debug, Clone, PartialEq, Serialize, ts_rs::TS)] +#[cfg_attr(feature = "wasm", wasm_bindgen)] +#[derive(Debug, Clone, PartialEq, Serialize)] +#[cfg_attr(feature = "wasm", derive(ts_rs::TS))] #[serde(rename_all = "camelCase")] -#[ts(export)] +#[cfg_attr(feature = "wasm", ts(export))] pub enum HyperlinkType { Anchor, External, diff --git a/docx-core/src/types/level_suffix_type.rs b/docx-core/src/types/level_suffix_type.rs index 6efc655..5bb2780 100644 --- a/docx-core/src/types/level_suffix_type.rs +++ b/docx-core/src/types/level_suffix_type.rs @@ -1,4 +1,5 @@ use std::fmt; +#[cfg(feature = "wasm")] use wasm_bindgen::prelude::*; use serde::Serialize; @@ -6,7 +7,7 @@ use serde::Serialize; use super::errors; use std::str::FromStr; -#[wasm_bindgen] +#[cfg_attr(feature = "wasm", wasm_bindgen)] #[derive(Debug, Clone, PartialEq, Serialize)] #[serde(rename_all = "camelCase")] pub enum LevelSuffixType { diff --git a/docx-core/src/types/line_spacing_type.rs b/docx-core/src/types/line_spacing_type.rs index abbdf19..52ea2ee 100644 --- a/docx-core/src/types/line_spacing_type.rs +++ b/docx-core/src/types/line_spacing_type.rs @@ -2,9 +2,10 @@ use crate::types::errors; use crate::TypeError; use serde::*; use std::str::FromStr; +#[cfg(feature = "wasm")] use wasm_bindgen::prelude::*; -#[wasm_bindgen] +#[cfg_attr(feature = "wasm", wasm_bindgen)] #[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub enum LineSpacingType { diff --git a/docx-core/src/types/page_orientation_type.rs b/docx-core/src/types/page_orientation_type.rs index 6814346..bd9b776 100644 --- a/docx-core/src/types/page_orientation_type.rs +++ b/docx-core/src/types/page_orientation_type.rs @@ -2,11 +2,12 @@ use serde::{Deserialize, Serialize}; use std::fmt; use std::str::FromStr; +#[cfg(feature = "wasm")] use wasm_bindgen::prelude::*; use super::errors; -#[wasm_bindgen] +#[cfg_attr(feature = "wasm", wasm_bindgen)] #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq)] #[serde(rename_all = "camelCase")] pub enum PageOrientationType { diff --git a/docx-core/src/types/relative_from_type.rs b/docx-core/src/types/relative_from_type.rs index eecf4e9..b9a5f91 100644 --- a/docx-core/src/types/relative_from_type.rs +++ b/docx-core/src/types/relative_from_type.rs @@ -1,4 +1,5 @@ use std::fmt; +#[cfg(feature = "wasm")] use wasm_bindgen::prelude::*; use serde::Serialize; @@ -7,9 +8,10 @@ use super::errors; use std::str::FromStr; // @See: 20.4.3.4 ST_RelFromH (Horizontal Relative Positioning) -#[wasm_bindgen] -#[derive(Debug, Clone, Copy, PartialEq, Serialize, ts_rs::TS)] -#[ts(export)] +#[cfg_attr(feature = "wasm", wasm_bindgen)] +#[derive(Debug, Clone, Copy, PartialEq, Serialize)] +#[cfg_attr(feature = "wasm", derive(ts_rs::TS))] +#[cfg_attr(feature = "wasm", ts(export))] #[serde(rename_all = "camelCase")] pub enum RelativeFromHType { /// Specifies that the horizontal positioning shall be @@ -80,9 +82,10 @@ impl FromStr for RelativeFromHType { } } -#[wasm_bindgen] -#[derive(Debug, Clone, Copy, PartialEq, Serialize, ts_rs::TS)] -#[ts(export)] +#[cfg_attr(feature = "wasm", wasm_bindgen)] +#[derive(Debug, Clone, Copy, PartialEq, Serialize)] +#[cfg_attr(feature = "wasm", derive(ts_rs::TS))] +#[cfg_attr(feature = "wasm", ts(export))] #[serde(rename_all = "camelCase")] pub enum RelativeFromVType { BottomMargin, diff --git a/docx-core/src/types/section_type.rs b/docx-core/src/types/section_type.rs index bb8e43c..cc8b4ea 100644 --- a/docx-core/src/types/section_type.rs +++ b/docx-core/src/types/section_type.rs @@ -11,11 +11,12 @@ use serde::{Deserialize, Serialize}; use std::fmt; use std::str::FromStr; +#[cfg(feature = "wasm")] use wasm_bindgen::prelude::*; use super::errors; -#[wasm_bindgen] +#[cfg_attr(feature = "wasm", wasm_bindgen)] #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq)] #[serde(rename_all = "camelCase")] pub enum SectionType { diff --git a/docx-core/src/types/shd_type.rs b/docx-core/src/types/shd_type.rs index 37feaa0..58fad27 100644 --- a/docx-core/src/types/shd_type.rs +++ b/docx-core/src/types/shd_type.rs @@ -2,6 +2,7 @@ use serde::{Deserialize, Serialize}; use std::fmt; use std::str::FromStr; +#[cfg(feature = "wasm")] use wasm_bindgen::prelude::*; use super::errors; @@ -46,7 +47,7 @@ use super::errors; */ -#[wasm_bindgen] +#[cfg_attr(feature = "wasm", wasm_bindgen)] #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq)] #[serde(rename_all = "camelCase")] pub enum ShdType { diff --git a/docx-core/src/types/special_indent_type.rs b/docx-core/src/types/special_indent_type.rs index f7a4c0e..711851c 100644 --- a/docx-core/src/types/special_indent_type.rs +++ b/docx-core/src/types/special_indent_type.rs @@ -1,3 +1,4 @@ +#[cfg(feature = "wasm")] use wasm_bindgen::prelude::*; use serde::ser::{SerializeStruct, Serializer}; @@ -11,7 +12,7 @@ pub enum SpecialIndentType { Hanging(i32), } -#[wasm_bindgen] +#[cfg_attr(feature = "wasm", wasm_bindgen)] #[derive(Serialize, Copy, Clone, Debug)] pub enum SpecialIndentKind { FirstLine, diff --git a/docx-core/src/types/style_type.rs b/docx-core/src/types/style_type.rs index 6c3b244..bcf07c6 100644 --- a/docx-core/src/types/style_type.rs +++ b/docx-core/src/types/style_type.rs @@ -1,11 +1,12 @@ use std::fmt; +#[cfg(feature = "wasm")] use wasm_bindgen::prelude::*; use super::errors; use serde::Serialize; use std::str::FromStr; -#[wasm_bindgen] +#[cfg_attr(feature = "wasm", wasm_bindgen)] #[derive(Debug, Clone, PartialEq, Serialize, Copy)] #[serde(rename_all = "camelCase")] pub enum StyleType { diff --git a/docx-core/src/types/tab_leader_type.rs b/docx-core/src/types/tab_leader_type.rs index da8055a..27eb55a 100644 --- a/docx-core/src/types/tab_leader_type.rs +++ b/docx-core/src/types/tab_leader_type.rs @@ -2,11 +2,12 @@ use serde::{Deserialize, Serialize}; use std::fmt; use std::str::FromStr; +#[cfg(feature = "wasm")] use wasm_bindgen::prelude::*; use super::errors; -#[wasm_bindgen] +#[cfg_attr(feature = "wasm", wasm_bindgen)] #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq)] #[serde(rename_all = "camelCase")] pub enum TabLeaderType { diff --git a/docx-core/src/types/tab_value_type.rs b/docx-core/src/types/tab_value_type.rs index 3dd3c57..26e4c22 100644 --- a/docx-core/src/types/tab_value_type.rs +++ b/docx-core/src/types/tab_value_type.rs @@ -2,11 +2,12 @@ use serde::{Deserialize, Serialize}; use std::fmt; use std::str::FromStr; +#[cfg(feature = "wasm")] use wasm_bindgen::prelude::*; use super::errors; -#[wasm_bindgen] +#[cfg_attr(feature = "wasm", wasm_bindgen)] #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq)] #[serde(rename_all = "camelCase")] pub enum TabValueType { diff --git a/docx-core/src/types/table_alignment_type.rs b/docx-core/src/types/table_alignment_type.rs index 969409b..4fa76a2 100644 --- a/docx-core/src/types/table_alignment_type.rs +++ b/docx-core/src/types/table_alignment_type.rs @@ -1,10 +1,11 @@ use std::fmt; use std::str::FromStr; +#[cfg(feature = "wasm")] use wasm_bindgen::prelude::*; use super::errors; -#[wasm_bindgen] +#[cfg_attr(feature = "wasm", wasm_bindgen)] #[derive(Copy, Clone, Debug)] pub enum TableAlignmentType { Center, diff --git a/docx-core/src/types/table_layout_type.rs b/docx-core/src/types/table_layout_type.rs index 6e03b6b..56bf19a 100644 --- a/docx-core/src/types/table_layout_type.rs +++ b/docx-core/src/types/table_layout_type.rs @@ -1,11 +1,12 @@ use serde::{Deserialize, Serialize}; use std::fmt; +#[cfg(feature = "wasm")] use wasm_bindgen::prelude::*; use super::errors; use std::str::FromStr; -#[wasm_bindgen] +#[cfg_attr(feature = "wasm", wasm_bindgen)] #[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub enum TableLayoutType { diff --git a/docx-core/src/types/text_direction_type.rs b/docx-core/src/types/text_direction_type.rs index 837e037..8bdb3d8 100644 --- a/docx-core/src/types/text_direction_type.rs +++ b/docx-core/src/types/text_direction_type.rs @@ -1,4 +1,5 @@ use std::fmt; +#[cfg(feature = "wasm")] use wasm_bindgen::prelude::*; use serde::Serialize; @@ -8,7 +9,7 @@ use std::str::FromStr; // ST_TextDirection defines `lr`, `lrV`, `rl`, `rlV`, `tb`, `tbV`. // However Microsoft word use `tbRlV`, `tbRl`, `btLr`, `lrTbV`. -#[wasm_bindgen] +#[cfg_attr(feature = "wasm", wasm_bindgen)] #[derive(Debug, Clone, Copy, PartialEq, Serialize)] #[serde(rename_all = "camelCase")] pub enum TextDirectionType { diff --git a/docx-core/src/types/vert_align_type.rs b/docx-core/src/types/vert_align_type.rs index 0763293..0a7c4e0 100644 --- a/docx-core/src/types/vert_align_type.rs +++ b/docx-core/src/types/vert_align_type.rs @@ -1,10 +1,11 @@ use std::fmt; use std::str::FromStr; +#[cfg(feature = "wasm")] use wasm_bindgen::prelude::*; use super::errors; -#[wasm_bindgen] +#[cfg_attr(feature = "wasm", wasm_bindgen)] #[derive(Copy, Clone, Debug, PartialEq)] pub enum VertAlignType { Baseline, diff --git a/docx-core/src/types/vertical_align_type.rs b/docx-core/src/types/vertical_align_type.rs index 1ecd29c..3740d1e 100644 --- a/docx-core/src/types/vertical_align_type.rs +++ b/docx-core/src/types/vertical_align_type.rs @@ -1,10 +1,11 @@ use std::fmt; +#[cfg(feature = "wasm")] use wasm_bindgen::prelude::*; use super::errors; use std::str::FromStr; -#[wasm_bindgen] +#[cfg_attr(feature = "wasm", wasm_bindgen)] #[derive(Copy, Clone, Debug, PartialEq)] pub enum VAlignType { Top, diff --git a/docx-core/src/types/vertical_merge_type.rs b/docx-core/src/types/vertical_merge_type.rs index bc2fc46..0d54b73 100644 --- a/docx-core/src/types/vertical_merge_type.rs +++ b/docx-core/src/types/vertical_merge_type.rs @@ -1,10 +1,11 @@ use std::fmt; +#[cfg(feature = "wasm")] use wasm_bindgen::prelude::*; use super::errors; use std::str::FromStr; -#[wasm_bindgen] +#[cfg_attr(feature = "wasm", wasm_bindgen)] #[derive(Copy, Clone, Debug, PartialEq)] pub enum VMergeType { Continue, diff --git a/docx-core/src/types/width_type.rs b/docx-core/src/types/width_type.rs index 742c8bd..3c64675 100644 --- a/docx-core/src/types/width_type.rs +++ b/docx-core/src/types/width_type.rs @@ -1,11 +1,12 @@ use serde::Serialize; use std::fmt; +#[cfg(feature = "wasm")] use wasm_bindgen::prelude::*; use super::errors; use std::str::FromStr; -#[wasm_bindgen] +#[cfg_attr(feature = "wasm", wasm_bindgen)] #[derive(Copy, Clone, Debug, PartialEq, Serialize)] #[serde(rename_all = "camelCase")] pub enum WidthType { diff --git a/docx-wasm/Cargo.toml b/docx-wasm/Cargo.toml index ed7a235..2fef13e 100644 --- a/docx-wasm/Cargo.toml +++ b/docx-wasm/Cargo.toml @@ -12,4 +12,4 @@ crate-type = ["cdylib"] [dependencies] wasm-bindgen = "0.2.78" console_error_panic_hook = "0.1.7" -docx-rs= { path = "../docx-core" } +docx-rs= { path = "../docx-core", features = ["wasm"] }