diff --git a/.gitignore b/.gitignore index 1c60b7c..13a29c6 100644 --- a/.gitignore +++ b/.gitignore @@ -16,5 +16,6 @@ vrt/report.html reg.json docx-core/tests/output/*.docx docx-wasm/*.tgz +docx-core/bindings docx-core/tests/output/*.json test.json \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index c579e12..e2b3533 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "Inflector" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" + [[package]] name = "adler" version = "0.2.3" @@ -176,6 +182,7 @@ dependencies = [ "serde", "serde_json", "thiserror", + "ts-rs", "wasm-bindgen", "xml-rs", "zip", @@ -563,6 +570,15 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "termcolor" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" +dependencies = [ + "winapi-util", +] + [[package]] name = "terminal_size" version = "0.1.16" @@ -604,6 +620,29 @@ dependencies = [ "weezl", ] +[[package]] +name = "ts-rs" +version = "6.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df082879c2ca6521d54bedd7d6d2e9407b7d457dede64415f1739d3a44a19b05" +dependencies = [ + "thiserror", + "ts-rs-macros", +] + +[[package]] +name = "ts-rs-macros" +version = "6.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f402688b565efbe1a0ffb296e201c12f1986fd02eba37f4dc62c13098a6218c1" +dependencies = [ + "Inflector", + "proc-macro2", + "quote", + "syn", + "termcolor", +] + [[package]] name = "unicode-xid" version = "0.2.0" @@ -686,6 +725,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" diff --git a/docx-core/Cargo.toml b/docx-core/Cargo.toml index ed97961..35ea3f9 100644 --- a/docx-core/Cargo.toml +++ b/docx-core/Cargo.toml @@ -27,6 +27,7 @@ zip = { version = "0.5.6", default-features = false, features = ["deflate"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" image = "0.23.14" +ts-rs = "6.1" [dev-dependencies] pretty_assertions = "1.0.0" diff --git a/docx-core/bindings/FontGroup.ts b/docx-core/bindings/FontGroup.ts new file mode 100644 index 0000000..9c9d50a --- /dev/null +++ b/docx-core/bindings/FontGroup.ts @@ -0,0 +1,3 @@ +import type { FontSchemeFont } from "./FontSchemeFont"; + +export interface FontGroup { latin: string, ea: string, cs: string, fonts: Array, } \ No newline at end of file diff --git a/docx-core/bindings/FontScheme.ts b/docx-core/bindings/FontScheme.ts new file mode 100644 index 0000000..b1bd36a --- /dev/null +++ b/docx-core/bindings/FontScheme.ts @@ -0,0 +1,3 @@ +import type { FontGroup } from "./FontGroup"; + +export interface FontScheme { majorFont: FontGroup, minorFont: FontGroup, } \ No newline at end of file diff --git a/docx-core/bindings/FontSchemeFont.ts b/docx-core/bindings/FontSchemeFont.ts new file mode 100644 index 0000000..e8e8100 --- /dev/null +++ b/docx-core/bindings/FontSchemeFont.ts @@ -0,0 +1,2 @@ + +export interface FontSchemeFont { script: string, typeface: string, } \ No newline at end of file diff --git a/docx-core/bindings/Theme.ts b/docx-core/bindings/Theme.ts new file mode 100644 index 0000000..5845646 --- /dev/null +++ b/docx-core/bindings/Theme.ts @@ -0,0 +1,3 @@ +import type { FontScheme } from "./FontScheme"; + +export interface Theme { fontSchema: FontScheme, } \ No newline at end of file diff --git a/docx-core/src/documents/elements/font_scheme.rs b/docx-core/src/documents/elements/font_scheme.rs index 4123330..da68a65 100644 --- a/docx-core/src/documents/elements/font_scheme.rs +++ b/docx-core/src/documents/elements/font_scheme.rs @@ -1,13 +1,15 @@ use serde::Serialize; -#[derive(Debug, Clone, PartialEq, Serialize)] +#[derive(Debug, Clone, PartialEq, Serialize, ts_rs::TS)] +#[ts(export)] #[serde(rename_all = "camelCase")] pub struct FontSchemeFont { pub script: String, pub typeface: String, } -#[derive(Debug, Clone, PartialEq, Serialize, Default)] +#[derive(Debug, Clone, PartialEq, Serialize, Default, ts_rs::TS)] +#[ts(export)] #[serde(rename_all = "camelCase")] pub struct FontGroup { pub latin: String, @@ -16,7 +18,8 @@ pub struct FontGroup { pub fonts: Vec, } -#[derive(Debug, Clone, PartialEq, Serialize, Default)] +#[derive(Debug, Clone, PartialEq, Serialize, Default, ts_rs::TS)] +#[ts(export)] #[serde(rename_all = "camelCase")] pub struct FontScheme { pub major_font: FontGroup, diff --git a/docx-core/src/documents/theme.rs b/docx-core/src/documents/theme.rs index f1b4a08..2aea744 100644 --- a/docx-core/src/documents/theme.rs +++ b/docx-core/src/documents/theme.rs @@ -2,7 +2,8 @@ use serde::Serialize; use super::*; -#[derive(Debug, Clone, PartialEq, Serialize, Default)] +#[derive(Debug, Clone, PartialEq, Serialize, Default, ts_rs::TS)] +#[ts(export)] #[serde(rename_all = "camelCase")] pub struct Theme { pub font_schema: FontScheme, diff --git a/docx-wasm/js/json/bindings/FontGroup.ts b/docx-wasm/js/json/bindings/FontGroup.ts new file mode 100644 index 0000000..9c9d50a --- /dev/null +++ b/docx-wasm/js/json/bindings/FontGroup.ts @@ -0,0 +1,3 @@ +import type { FontSchemeFont } from "./FontSchemeFont"; + +export interface FontGroup { latin: string, ea: string, cs: string, fonts: Array, } \ No newline at end of file diff --git a/docx-wasm/js/json/bindings/FontScheme.ts b/docx-wasm/js/json/bindings/FontScheme.ts new file mode 100644 index 0000000..b1bd36a --- /dev/null +++ b/docx-wasm/js/json/bindings/FontScheme.ts @@ -0,0 +1,3 @@ +import type { FontGroup } from "./FontGroup"; + +export interface FontScheme { majorFont: FontGroup, minorFont: FontGroup, } \ No newline at end of file diff --git a/docx-wasm/js/json/bindings/FontSchemeFont.ts b/docx-wasm/js/json/bindings/FontSchemeFont.ts new file mode 100644 index 0000000..e8e8100 --- /dev/null +++ b/docx-wasm/js/json/bindings/FontSchemeFont.ts @@ -0,0 +1,2 @@ + +export interface FontSchemeFont { script: string, typeface: string, } \ No newline at end of file diff --git a/docx-wasm/js/json/bindings/Theme.ts b/docx-wasm/js/json/bindings/Theme.ts new file mode 100644 index 0000000..5845646 --- /dev/null +++ b/docx-wasm/js/json/bindings/Theme.ts @@ -0,0 +1,3 @@ +import type { FontScheme } from "./FontScheme"; + +export interface Theme { fontSchema: FontScheme, } \ No newline at end of file diff --git a/docx-wasm/js/json/index.ts b/docx-wasm/js/json/index.ts index 27f5e97..d9b7a3e 100644 --- a/docx-wasm/js/json/index.ts +++ b/docx-wasm/js/json/index.ts @@ -4,6 +4,8 @@ import { NumberingsJSON } from "./numbering"; import { CommentJSON } from "./comment"; import { WebSettingsJSON } from "./web-settings"; +import { Theme as ThemeJSON } from "./bindings/Theme"; + export type DocxJSON = { contentType: { types: { @@ -44,6 +46,7 @@ export type DocxJSON = { settings: SettingsJSON; webSettings: WebSettingsJSON; fontTable: {}; + themes: ThemeJSON[]; }; export type SettingsJSON = { @@ -67,3 +70,5 @@ export * from "./web-settings"; export * from "./comment"; export * from "./textbox-content"; export * from "./section-property"; + +export { ThemeJSON }; diff --git a/docx-wasm/package.json b/docx-wasm/package.json index 252790f..ba4f2e0 100644 --- a/docx-wasm/package.json +++ b/docx-wasm/package.json @@ -1,6 +1,6 @@ { "name": "docx-wasm", - "version": "0.0.235", + "version": "0.0.240", "main": "dist/node/index.js", "browser": "dist/web/index.js", "author": "bokuweb ", @@ -14,9 +14,11 @@ "tsc:node": "tsc -p tsconfig.node.json", "tsc": "run-s tsc:*", "test": "npm run build && tsc && jest", - "build": "run-s wasm-pack tsc", + "build": "run-s tsrs copy:bindings wasm-pack tsc", "serve": "webpack-dev-server --open --config webpack.dev.js", "copy": "cpy 'dist/node/pkg/package.json' 'dist/web/pkg'", + "tsrs": "cd ../ && make test", + "copy:bindings": "cpy '../docx-core/bindings' './js/json/bindings'", "prepublishOnly": "npm run build" }, "resolutions": {