From 489027991c17b6706c16a117250ea4f4c9bdcbf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Hatcher=20Andr=C3=A9s?= Date: Sun, 7 Apr 2024 12:41:33 +0200 Subject: [PATCH] UPDATE: Adds Web browser wasm bindings (#30) * UPDATE: Adds Web browser wasm bindings * FIX: install wasm-pack in the GitHub actions --- .github/workflows/rust-build-test.yaml | 3 + Cargo.lock | 575 +++++++++++++----- Cargo.toml | 1 + Makefile | 9 +- base/Cargo.toml | 6 +- base/src/functions/date_and_time.rs | 13 +- base/src/model.rs | 9 +- base/src/new_empty.rs | 4 +- base/src/test/test_workbook.rs | 6 +- base/src/test/user_model/mod.rs | 1 + .../test/user_model/test_add_delete_sheets.rs | 32 +- base/src/test/user_model/test_general.rs | 7 + base/src/test/user_model/test_rename_sheet.rs | 8 +- .../src/test/user_model/test_to_from_bytes.rs | 30 + base/src/types.rs | 4 +- base/src/user_model.rs | 86 ++- bindings/wasm/.gitignore | 1 + bindings/wasm/Cargo.toml | 23 + bindings/wasm/Makefile | 14 + bindings/wasm/README.md | 31 + bindings/wasm/README.pkg.md | 33 + bindings/wasm/src/lib.rs | 254 ++++++++ bindings/wasm/test.html | 28 + bindings/wasm/tests/test.mjs | 123 ++++ codecov.yml | 1 + xlsx/Cargo.toml | 6 +- xlsx/src/export/doc_props.rs | 4 +- 27 files changed, 1129 insertions(+), 183 deletions(-) create mode 100644 base/src/test/user_model/test_to_from_bytes.rs create mode 100644 bindings/wasm/.gitignore create mode 100644 bindings/wasm/Cargo.toml create mode 100644 bindings/wasm/Makefile create mode 100644 bindings/wasm/README.md create mode 100644 bindings/wasm/README.pkg.md create mode 100644 bindings/wasm/src/lib.rs create mode 100644 bindings/wasm/test.html create mode 100644 bindings/wasm/tests/test.mjs diff --git a/.github/workflows/rust-build-test.yaml b/.github/workflows/rust-build-test.yaml index 468b711..6de247a 100644 --- a/.github/workflows/rust-build-test.yaml +++ b/.github/workflows/rust-build-test.yaml @@ -16,6 +16,9 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Install wasm-pack + run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh + - name: Build run: cargo build --release --verbose diff --git a/Cargo.lock b/Cargo.lock index dc9c6ac..68dfac0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9,10 +9,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] -name = "aho-corasick" -version = "1.1.2" +name = "aes" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" +dependencies = [ + "cfg-if", + "cipher", + "cpufeatures", +] + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ "memchr", ] @@ -34,15 +45,30 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" + +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] [[package]] name = "bumpalo" -version = "3.14.0" +version = "3.15.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" +checksum = "7ff69b9dd49fd426c69a0db9fc04dd934cdb6645ff000864d98f7e2af8830eaa" [[package]] name = "byteorder" @@ -73,10 +99,11 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.83" +version = "1.0.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5" dependencies = [ + "jobserver", "libc", ] @@ -88,9 +115,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.31" +version = "0.4.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38" +checksum = "8a0d04d43504c61aa6c7531f1871dd0d418d91130162063b789da00fd7057a5e" dependencies = [ "android-tzdata", "iana-time-zone", @@ -102,9 +129,9 @@ dependencies = [ [[package]] name = "chrono-tz" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbc529705a6e0028189c83f0a5dd9fb214105116f7e3c0eeab7ff0369766b0d1" +checksum = "93698b29de5e97ad0ae26447b344c482a7284c737d9ddc5f9e52b74a336671bb" dependencies = [ "chrono", "chrono-tz-build", @@ -113,9 +140,9 @@ dependencies = [ [[package]] name = "chrono-tz-build" -version = "0.1.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9998fb9f7e9b2111641485bf8beb32f92945f97f92a3d061f744cfef335f751" +checksum = "0c088aee841df9c3041febbb73934cfc39708749bf96dc827e3359cd39ef11b1" dependencies = [ "parse-zoneinfo", "phf", @@ -123,25 +150,96 @@ dependencies = [ ] [[package]] -name = "core-foundation-sys" -version = "0.8.4" +name = "cipher" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +dependencies = [ + "crypto-common", + "inout", +] + +[[package]] +name = "console_error_panic_hook" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" +dependencies = [ + "cfg-if", + "wasm-bindgen", +] + +[[package]] +name = "constant_time_eq" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" + +[[package]] +name = "core-foundation-sys" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" + +[[package]] +name = "cpufeatures" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +dependencies = [ + "libc", +] [[package]] name = "crc32fast" -version = "1.3.2" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa" dependencies = [ "cfg-if", ] [[package]] -name = "either" -version = "1.9.0" +name = "crossbeam-utils" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", + "subtle", +] + +[[package]] +name = "either" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" [[package]] name = "flate2" @@ -154,21 +252,40 @@ dependencies = [ ] [[package]] -name = "getrandom" -version = "0.2.11" +name = "generic-array" +version = "0.14.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06fddc2749e0528d2813f95e050e87e52c8cbbae56223b9babf73b3e53b0cc6" dependencies = [ "cfg-if", "libc", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", +] + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", ] [[package]] name = "iana-time-zone" -version = "0.1.58" +version = "0.1.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8326b86b6cff230b97d0d312a6c40a60726df3332e721f72a1b035f451663b20" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -187,6 +304,15 @@ dependencies = [ "cc", ] +[[package]] +name = "inout" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5" +dependencies = [ + "generic-array", +] + [[package]] name = "ironcalc" version = "0.1.3" @@ -220,69 +346,84 @@ dependencies = [ [[package]] name = "itertools" -version = "0.10.5" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" dependencies = [ "either", ] [[package]] name = "itoa" -version = "1.0.9" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "jobserver" +version = "0.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab46a6e9526ddef3ae7f787c06f0f2600639ba80ea3eade3d8e670a2230f51d6" +dependencies = [ + "libc", +] [[package]] name = "js-sys" -version = "0.3.65" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54c0c35952f67de54bb584e9fd912b3023117cbafc0a77d8f3dee1fb5f572fe8" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" dependencies = [ "wasm-bindgen", ] [[package]] name = "libc" -version = "0.2.150" +version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" [[package]] name = "log" -version = "0.4.20" +version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" [[package]] name = "memchr" -version = "2.6.4" +version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" [[package]] name = "miniz_oxide" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" dependencies = [ "adler", ] [[package]] -name = "num-traits" -version = "0.2.17" +name = "num-conv" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + +[[package]] +name = "num-traits" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" dependencies = [ "autocfg", ] [[package]] name = "once_cell" -version = "1.18.0" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "parse-zoneinfo" @@ -293,6 +434,29 @@ dependencies = [ "regex", ] +[[package]] +name = "password-hash" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7676374caaee8a325c9e7a2ae557f216c5563a171d6997b0ef8a65af35147700" +dependencies = [ + "base64ct", + "rand_core", + "subtle", +] + +[[package]] +name = "pbkdf2" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" +dependencies = [ + "digest", + "hmac", + "password-hash", + "sha2", +] + [[package]] name = "phf" version = "0.11.2" @@ -333,9 +497,15 @@ dependencies = [ [[package]] name = "pkg-config" -version = "0.3.27" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" [[package]] name = "ppv-lite86" @@ -345,18 +515,18 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -version = "1.0.69" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" +checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -393,9 +563,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.2" +version = "1.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" dependencies = [ "aho-corasick", "memchr", @@ -405,9 +575,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.3" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" dependencies = [ "aho-corasick", "memchr", @@ -416,39 +586,53 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" +checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" [[package]] name = "roxmltree" -version = "0.13.1" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbf7d7b1ea646d380d0e8153158063a6da7efe30ddbf3184042848e3f8a6f671" -dependencies = [ - "xmlparser", -] +checksum = "3cd14fd5e3b777a7422cca79358c57a8f6e3a703d9ac187448d0daf220c2407f" [[package]] name = "ryu" -version = "1.0.15" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" +checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" + +[[package]] +name = "scoped-tls" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" [[package]] name = "serde" -version = "1.0.192" +version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bca2a08484b285dcb282d0f67b26cadc0df8b19f8c12502c13d966bf9482f001" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" dependencies = [ "serde_derive", ] [[package]] -name = "serde_derive" -version = "1.0.192" +name = "serde-wasm-bindgen" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6c7207fbec9faa48073f3e3074cbe553af6ea512d7c21ba46e434e70ea9fbc1" +checksum = "e3b4c031cd0d9014307d82b8abf653c0290fbdaeb4c02d00c63cf52f728628bf" +dependencies = [ + "js-sys", + "serde", + "wasm-bindgen", +] + +[[package]] +name = "serde_derive" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", @@ -457,9 +641,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.108" +version = "1.0.115" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" +checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd" dependencies = [ "itoa", "ryu", @@ -468,15 +652,37 @@ dependencies = [ [[package]] name = "serde_repr" -version = "0.1.17" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3081f5ffbb02284dda55132aa26daecedd7372a42417bbbab6f14ab7d6bb9145" +checksum = "0b2e6b945e9d3df726b65d6ee24060aff8e3533d431f677a9695db04eff9dfdb" dependencies = [ "proc-macro2", "quote", "syn", ] +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + [[package]] name = "siphasher" version = "0.3.11" @@ -484,10 +690,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" [[package]] -name = "syn" -version = "2.0.39" +name = "subtle" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" +checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" + +[[package]] +name = "syn" +version = "2.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687" dependencies = [ "proc-macro2", "quote", @@ -496,18 +708,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.50" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" +checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.50" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" +checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" dependencies = [ "proc-macro2", "quote", @@ -516,15 +728,29 @@ dependencies = [ [[package]] name = "time" -version = "0.1.45" +version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" +checksum = "c8248b6521bb14bc45b4067159b9b6ad792e2d6d754d6c41fb50e29fefe38749" dependencies = [ - "libc", - "wasi 0.10.0+wasi-snapshot-preview1", - "winapi", + "deranged", + "num-conv", + "powerfmt", + "serde", + "time-core", ] +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + [[package]] name = "unicode-ident" version = "1.0.12" @@ -533,19 +759,19 @@ checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "uuid" -version = "1.5.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ad59a7560b41a70d191093a945f0b87bc1deeda46fb237479708a1d6b6cdfc" +checksum = "a183cf7feeba97b4dd1c0d46788634f6221d87fa961b305bed08c851829efcc0" dependencies = [ "getrandom", "serde", ] [[package]] -name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" +name = "version_check" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "wasi" @@ -553,11 +779,22 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasm" +version = "0.1.3" +dependencies = [ + "ironcalc_base", + "serde", + "serde-wasm-bindgen", + "wasm-bindgen", + "wasm-bindgen-test", +] + [[package]] name = "wasm-bindgen" -version = "0.2.88" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7daec296f25a1bae309c0cd5c29c4b260e510e6d813c286b19eaadf409d40fce" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -565,9 +802,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.88" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e397f4664c0e4e428e8313a469aaa58310d302159845980fd23b0f22a847f217" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" dependencies = [ "bumpalo", "log", @@ -579,10 +816,22 @@ dependencies = [ ] [[package]] -name = "wasm-bindgen-macro" -version = "0.2.88" +name = "wasm-bindgen-futures" +version = "0.4.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5961017b3b08ad5f3fe39f1e79877f8ee7c23c5e5fd5eb80de95abc41f1f16b2" +checksum = "76bc14366121efc8dbb487ab05bcc9d346b3b5ec0eaa76e46594cabbe51762c0" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -590,9 +839,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.88" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5353b8dab669f5e10f5bd76df26a9360c748f054f862ff5f3f8aae0c7fb3907" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", @@ -603,46 +852,59 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.88" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d046c5d029ba91a1ed14da14dca44b68bf2f124cfbaf741c54151fdb3e0750b" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" [[package]] -name = "winapi" -version = "0.3.9" +name = "wasm-bindgen-test" +version = "0.3.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +checksum = "d9bf62a58e0780af3e852044583deee40983e5886da43a271dd772379987667b" dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", + "console_error_panic_hook", + "js-sys", + "scoped-tls", + "wasm-bindgen", + "wasm-bindgen-futures", + "wasm-bindgen-test-macro", ] [[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" +name = "wasm-bindgen-test-macro" +version = "0.3.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +checksum = "b7f89739351a2e03cb94beb799d47fb2cac01759b40ec441f7de39b00cbf7ef0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" +name = "web-sys" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" +dependencies = [ + "js-sys", + "wasm-bindgen", +] [[package]] name = "windows-core" -version = "0.51.1" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ "windows-targets", ] [[package]] name = "windows-targets" -version = "0.48.5" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", @@ -655,62 +917,91 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.48.5" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" +checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" [[package]] name = "windows_aarch64_msvc" -version = "0.48.5" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" +checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" [[package]] name = "windows_i686_gnu" -version = "0.48.5" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" +checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" [[package]] name = "windows_i686_msvc" -version = "0.48.5" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" +checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" [[package]] name = "windows_x86_64_gnu" -version = "0.48.5" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" +checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" [[package]] name = "windows_x86_64_gnullvm" -version = "0.48.5" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" [[package]] name = "windows_x86_64_msvc" -version = "0.48.5" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "xmlparser" -version = "0.13.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66fee0b777b0f5ac1c69bb06d361268faafa61cd4682ae064a171c16c433e9e4" +checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" [[package]] name = "zip" -version = "0.5.13" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93ab48844d61251bb3835145c521d88aa4031d7139e8485990f60ca911fa0815" +checksum = "760394e246e4c28189f19d488c058bf16f564016aefac5d32bb1f3b51d5e9261" dependencies = [ + "aes", "byteorder", "bzip2", + "constant_time_eq", "crc32fast", + "crossbeam-utils", "flate2", - "thiserror", + "hmac", + "pbkdf2", + "sha1", "time", + "zstd", +] + +[[package]] +name = "zstd" +version = "0.11.2+zstd.1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20cc960326ece64f010d2d2107537f26dc589a6573a316bd5b1dba685fa5fde4" +dependencies = [ + "zstd-safe", +] + +[[package]] +name = "zstd-safe" +version = "5.0.2+zstd.1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d2a5585e04f9eea4b2a3d1eca508c4dee9592a89ef6f450c11719da0726f4db" +dependencies = [ + "libc", + "zstd-sys", +] + +[[package]] +name = "zstd-sys" +version = "2.0.10+zstd.1.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c253a4914af5bafc8fa8c86ee400827e83cf6ec01195ec1f1ed8441bf00d65aa" +dependencies = [ + "cc", + "pkg-config", ] diff --git a/Cargo.toml b/Cargo.toml index d1113d5..5fd35ee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ resolver = "2" members = [ "base", "xlsx", + "bindings/wasm", ] exclude = [ diff --git a/Makefile b/Makefile index 607956e..9344de3 100644 --- a/Makefile +++ b/Makefile @@ -7,23 +7,24 @@ format: tests: lint cargo test - make remove-xlsx ./target/debug/documentation cmp functions.md wiki/functions.md || exit 1 + make remove-artifacts + cd bindings/wasm/ && wasm-pack build --target nodejs && node tests/test.mjs -remove-xlsx: +remove-artifacts: rm -f xlsx/hello-calc.xlsx rm -f xlsx/hello-styles.xlsx rm -f xlsx/widths-and-heights.xlsx + rm -f functions.md -clean: remove-xlsx +clean: remove-artifacts cargo clean rm -r -f base/target rm -r -f xlsx/target rm -f cargo-test-* rm -f base/cargo-test-* rm -f xlsx/cargo-test-* - rm functions.md coverage: diff --git a/base/Cargo.toml b/base/Cargo.toml index 7884e3a..aa19109 100644 --- a/base/Cargo.toml +++ b/base/Cargo.toml @@ -16,14 +16,14 @@ serde_json = "1.0" serde_repr = "0.1" ryu = "1.0" chrono = "0.4" -chrono-tz = "0.7.0" +chrono-tz = "0.9" regex = "1.0" once_cell = "1.16.0" [target.'cfg(target_arch = "wasm32")'.dependencies] -js-sys = { version = "0.3.60" } +js-sys = { version = "0.3.69" } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] -rand = "0.8.4" +rand = "0.8.5" diff --git a/base/src/functions/date_and_time.rs b/base/src/functions/date_and_time.rs index a66a18c..c8c4b6c 100644 --- a/base/src/functions/date_and_time.rs +++ b/base/src/functions/date_and_time.rs @@ -1,7 +1,6 @@ +use chrono::DateTime; use chrono::Datelike; use chrono::Months; -use chrono::NaiveDateTime; -use chrono::TimeZone; use chrono::Timelike; use crate::expressions::types::CellReferenceIndex; @@ -258,8 +257,8 @@ impl Model { // milliseconds since January 1, 1970 00:00:00 UTC. let milliseconds = get_milliseconds_since_epoch(); let seconds = milliseconds / 1000; - let dt = match NaiveDateTime::from_timestamp_opt(seconds, 0) { - Some(dt) => dt, + let local_time = match DateTime::from_timestamp(seconds, 0) { + Some(dt) => dt.with_timezone(&self.tz), None => { return CalcResult::Error { error: Error::ERROR, @@ -268,7 +267,6 @@ impl Model { } } }; - let local_time = self.tz.from_utc_datetime(&dt); // 693_594 is computed as: // NaiveDate::from_ymd(1900, 1, 1).num_days_from_ce() - 2 // The 2 days offset is because of Excel 1900 bug @@ -289,8 +287,8 @@ impl Model { // milliseconds since January 1, 1970 00:00:00 UTC. let milliseconds = get_milliseconds_since_epoch(); let seconds = milliseconds / 1000; - let dt = match NaiveDateTime::from_timestamp_opt(seconds, 0) { - Some(dt) => dt, + let local_time = match DateTime::from_timestamp(seconds, 0) { + Some(dt) => dt.with_timezone(&self.tz), None => { return CalcResult::Error { error: Error::ERROR, @@ -299,7 +297,6 @@ impl Model { } } }; - let local_time = self.tz.from_utc_datetime(&dt); // 693_594 is computed as: // NaiveDate::from_ymd(1900, 1, 1).num_days_from_ce() - 2 // The 2 days offset is because of Excel 1900 bug diff --git a/base/src/model.rs b/base/src/model.rs index 0bf7f29..c44e3c1 100644 --- a/base/src/model.rs +++ b/base/src/model.rs @@ -55,6 +55,11 @@ pub fn get_milliseconds_since_epoch() -> i64 { .as_millis() as i64 } +/// Number of milliseconds since January 1, 1970 +/// Used by time and date functions. It takes the value from the environment: +/// * The Operative System +/// * The JavaScript environment +/// * Or mocked for tests #[cfg(not(test))] #[cfg(target_arch = "wasm32")] pub fn get_milliseconds_since_epoch() -> i64 { @@ -1761,11 +1766,11 @@ impl Model { } /// Returns data about the worksheets - pub fn get_sheets_info(&self) -> Vec { + pub fn get_worksheets_properties(&self) -> Vec { self.workbook .worksheets .iter() - .map(|worksheet| SheetInfo { + .map(|worksheet| SheetProperties { name: worksheet.get_name(), state: worksheet.state.to_string(), color: worksheet.color.clone(), diff --git a/base/src/new_empty.rs b/base/src/new_empty.rs index 81216fd..f708253 100644 --- a/base/src/new_empty.rs +++ b/base/src/new_empty.rs @@ -1,4 +1,4 @@ -use chrono::NaiveDateTime; +use chrono::DateTime; use std::collections::HashMap; @@ -324,7 +324,7 @@ impl Model { let milliseconds = get_milliseconds_since_epoch(); let seconds = milliseconds / 1000; - let dt = match NaiveDateTime::from_timestamp_opt(seconds, 0) { + let dt = match DateTime::from_timestamp(seconds, 0) { Some(s) => s, None => return Err(format!("Invalid timestamp: {}", milliseconds)), }; diff --git a/base/src/test/test_workbook.rs b/base/src/test/test_workbook.rs index 11d490e..b0928fd 100644 --- a/base/src/test/test_workbook.rs +++ b/base/src/test/test_workbook.rs @@ -1,14 +1,14 @@ #![allow(clippy::unwrap_used)] -use crate::{test::util::new_empty_model, types::SheetInfo}; +use crate::{test::util::new_empty_model, types::SheetProperties}; #[test] fn workbook_worksheets_info() { let model = new_empty_model(); - let sheets_info = model.get_sheets_info(); + let sheets_info = model.get_worksheets_properties(); assert_eq!( sheets_info[0], - SheetInfo { + SheetProperties { name: "Sheet1".to_string(), state: "visible".to_string(), sheet_id: 1, diff --git a/base/src/test/user_model/mod.rs b/base/src/test/user_model/mod.rs index e8165a4..ef0cddb 100644 --- a/base/src/test/user_model/mod.rs +++ b/base/src/test/user_model/mod.rs @@ -6,4 +6,5 @@ mod test_general; mod test_rename_sheet; mod test_row_column; mod test_styles; +mod test_to_from_bytes; mod test_undo_redo; diff --git a/base/src/test/user_model/test_add_delete_sheets.rs b/base/src/test/user_model/test_add_delete_sheets.rs index 52cb183..72ae562 100644 --- a/base/src/test/user_model/test_add_delete_sheets.rs +++ b/base/src/test/user_model/test_add_delete_sheets.rs @@ -30,6 +30,32 @@ fn add_undo_redo() { assert!(!model.can_redo()); } +#[test] +fn set_sheet_color() { + let mut model = UserModel::new_empty("model", "en", "UTC").unwrap(); + model.set_sheet_color(0, "#343434").unwrap(); + let worksheets_properties = model.get_worksheets_properties(); + assert_eq!(worksheets_properties.len(), 1); + assert_eq!(worksheets_properties[0].color, Some("#343434".to_owned())); + model.undo().unwrap(); + assert_eq!(model.get_worksheets_properties()[0].color, None); + + model.redo().unwrap(); + assert_eq!( + model.get_worksheets_properties()[0].color, + Some("#343434".to_owned()) + ); + // changes the color if there is one + model.set_sheet_color(0, "#2534FF").unwrap(); + assert_eq!( + model.get_worksheets_properties()[0].color, + Some("#2534FF".to_owned()) + ); + // Setting it back to none + model.set_sheet_color(0, "").unwrap(); + assert_eq!(model.get_worksheets_properties()[0].color, None); +} + #[test] fn new_sheet_propagates() { let mut model = UserModel::new_empty("model", "en", "UTC").unwrap(); @@ -39,8 +65,8 @@ fn new_sheet_propagates() { let mut model2 = UserModel::new_empty("model", "en", "UTC").unwrap(); model2.apply_external_diffs(&send_queue).unwrap(); - let sheets_info = model2.get_sheets_info(); - assert_eq!(sheets_info.len(), 2); + let worksheets_properties = model2.get_worksheets_properties(); + assert_eq!(worksheets_properties.len(), 2); } #[test] @@ -53,6 +79,6 @@ fn delete_sheet_propagates() { let mut model2 = UserModel::new_empty("model", "en", "UTC").unwrap(); model2.apply_external_diffs(&send_queue).unwrap(); - let sheets_info = model2.get_sheets_info(); + let sheets_info = model2.get_worksheets_properties(); assert_eq!(sheets_info.len(), 1); } diff --git a/base/src/test/user_model/test_general.rs b/base/src/test/user_model/test_general.rs index 0cd0d7d..7f562e7 100644 --- a/base/src/test/user_model/test_general.rs +++ b/base/src/test/user_model/test_general.rs @@ -22,6 +22,13 @@ fn set_user_input_errors() { assert!(model.set_user_input(0, 1, LAST_COLUMN + 1, "1").is_err()); } +#[test] +fn user_model_debug_message() { + let model = UserModel::new_empty("model", "en", "UTC").unwrap(); + let s = &format!("{:?}", model); + assert_eq!(s, "UserModel"); +} + #[test] fn insert_remove_rows() { let model = new_empty_model(); diff --git a/base/src/test/user_model/test_rename_sheet.rs b/base/src/test/user_model/test_rename_sheet.rs index cc02c5f..841d41d 100644 --- a/base/src/test/user_model/test_rename_sheet.rs +++ b/base/src/test/user_model/test_rename_sheet.rs @@ -6,7 +6,7 @@ use crate::UserModel; fn basic_rename() { let mut model = UserModel::new_empty("model", "en", "UTC").unwrap(); model.rename_sheet(0, "NewSheet").unwrap(); - assert_eq!(model.get_sheets_info()[0].name, "NewSheet"); + assert_eq!(model.get_worksheets_properties()[0].name, "NewSheet"); } #[test] @@ -14,15 +14,15 @@ fn undo_redo() { let mut model = UserModel::new_empty("model", "en", "UTC").unwrap(); model.rename_sheet(0, "NewSheet").unwrap(); model.undo().unwrap(); - assert_eq!(model.get_sheets_info()[0].name, "Sheet1"); + assert_eq!(model.get_worksheets_properties()[0].name, "Sheet1"); model.redo().unwrap(); - assert_eq!(model.get_sheets_info()[0].name, "NewSheet"); + assert_eq!(model.get_worksheets_properties()[0].name, "NewSheet"); let send_queue = model.flush_send_queue(); let mut model2 = UserModel::new_empty("model", "en", "UTC").unwrap(); model2.apply_external_diffs(&send_queue).unwrap(); - assert_eq!(model.get_sheets_info()[0].name, "NewSheet"); + assert_eq!(model.get_worksheets_properties()[0].name, "NewSheet"); } #[test] diff --git a/base/src/test/user_model/test_to_from_bytes.rs b/base/src/test/user_model/test_to_from_bytes.rs new file mode 100644 index 0000000..a973945 --- /dev/null +++ b/base/src/test/user_model/test_to_from_bytes.rs @@ -0,0 +1,30 @@ +#![allow(clippy::unwrap_used)] + +use crate::{test::util::new_empty_model, UserModel}; + +#[test] +fn basic() { + let mut model1 = UserModel::from_model(new_empty_model()); + let width = model1.get_column_width(0, 3).unwrap() * 3.0; + model1.set_column_width(0, 3, width).unwrap(); + model1.set_user_input(0, 1, 2, "Hello IronCalc!").unwrap(); + + let model_bytes = model1.to_bytes(); + + let model2 = UserModel::from_bytes(&model_bytes).unwrap(); + + assert_eq!(model2.get_column_width(0, 3), Ok(width)); + assert_eq!( + model2.get_formatted_cell_value(0, 1, 2), + Ok("Hello IronCalc!".to_string()) + ); +} + +#[test] +fn errors() { + let model_bytes = "Early in the morning, late in the century, Cricklewood Broadway."; + assert_eq!( + &UserModel::from_bytes(model_bytes).unwrap_err(), + "Error parsing workbook" + ); +} diff --git a/base/src/types.rs b/base/src/types.rs index 914351b..c6069f0 100644 --- a/base/src/types.rs +++ b/base/src/types.rs @@ -316,6 +316,7 @@ impl Default for Styles { #[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)] pub struct Style { + #[serde(skip_serializing_if = "Option::is_none")] pub alignment: Option, pub num_fmt: String, pub fill: Fill, @@ -665,9 +666,10 @@ pub struct Border { /// Information need to show a sheet tab in the UI /// The color is serialized only if it is not Color::None #[derive(Serialize, Deserialize, Debug, PartialEq)] -pub struct SheetInfo { +pub struct SheetProperties { pub name: String, pub state: String, pub sheet_id: u32, + #[serde(skip_serializing_if = "Option::is_none")] pub color: Option, } diff --git a/base/src/user_model.rs b/base/src/user_model.rs index 15e1983..4cfc9a5 100644 --- a/base/src/user_model.rs +++ b/base/src/user_model.rs @@ -1,6 +1,6 @@ #![deny(missing_docs)] -use std::collections::HashMap; +use std::{collections::HashMap, fmt::Debug}; use serde::{Deserialize, Serialize}; @@ -12,8 +12,8 @@ use crate::{ }, model::Model, types::{ - Alignment, BorderItem, BorderStyle, Cell, Col, HorizontalAlignment, Row, SheetInfo, Style, - VerticalAlignment, + Alignment, BorderItem, BorderStyle, Cell, Col, HorizontalAlignment, Row, SheetProperties, + Style, VerticalAlignment, }, utils::is_valid_hex_color, }; @@ -113,6 +113,11 @@ enum Diff { old_value: String, new_value: String, }, + SetSheetColor { + index: u32, + old_value: String, + new_value: String, + }, } type DiffList = Vec; @@ -276,6 +281,12 @@ pub struct UserModel { pause_evaluation: bool, } +impl Debug for UserModel { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("UserModel").finish() + } +} + impl UserModel { /// Creates a user model from an existing model pub fn from_model(model: Model) -> UserModel { @@ -301,7 +312,32 @@ impl UserModel { }) } + /// Creates a model from it's internal representation + /// + /// See also: + /// * [Model::from_json] + pub fn from_bytes(s: &str) -> Result { + let model = Model::from_json(s)?; + Ok(UserModel { + model, + history: History::default(), + send_queue: vec![], + pause_evaluation: false, + }) + } + + /// Returns the internal representation of a model + /// + /// See also: + /// * [Model::to_json_str] + pub fn to_bytes(&self) -> String { + self.model.to_json_str() + } + /// Undoes last change if any, places the change in the redo list and evaluates the model if needed + /// + /// See also: + /// * [UserModel::redo] pub fn undo(&mut self) -> Result<(), String> { if let Some(diff_list) = self.history.undo() { self.apply_undo_diff_list(&diff_list)?; @@ -314,6 +350,9 @@ impl UserModel { } /// Redoes the last undone change, places the change in the undo list and evaluates the model if needed + /// + /// See also: + /// * [UserModel::redo] pub fn redo(&mut self) -> Result<(), String> { if let Some(diff_list) = self.history.redo() { self.apply_diff_list(&diff_list)?; @@ -495,6 +534,27 @@ impl UserModel { Ok(()) } + /// Sets sheet color + /// + /// Note: an empty string will remove the color + /// + /// See also + /// * [Model::set_sheet_color] + /// * [UserModel::get_worksheets_properties] + pub fn set_sheet_color(&mut self, sheet: u32, color: &str) -> Result<(), String> { + let old_value = match &self.model.workbook.worksheet(sheet)?.color { + Some(c) => c.clone(), + None => "".to_string(), + }; + self.model.set_sheet_color(sheet, color)?; + self.push_diff_list(vec![Diff::SetSheetColor { + index: sheet, + old_value, + new_value: color.to_string(), + }]); + Ok(()) + } + /// Removes cells contents and style /// /// See also: @@ -858,10 +918,10 @@ impl UserModel { /// Returns information about the sheets /// /// See also: - /// * [Model::get_sheets_info] + /// * [Model::get_worksheets_properties] #[inline] - pub fn get_sheets_info(&self) -> Vec { - self.model.get_sheets_info() + pub fn get_worksheets_properties(&self) -> Vec { + self.model.get_worksheets_properties() } // **** Private methods ****** // @@ -1020,6 +1080,13 @@ impl UserModel { } => { self.model.rename_sheet_by_index(*index, old_value)?; } + Diff::SetSheetColor { + index, + old_value, + new_value: _, + } => { + self.model.set_sheet_color(*index, old_value)?; + } } } if needs_evaluation { @@ -1133,6 +1200,13 @@ impl UserModel { } => { self.model.rename_sheet_by_index(*index, new_value)?; } + Diff::SetSheetColor { + index, + old_value: _, + new_value, + } => { + self.model.set_sheet_color(*index, new_value)?; + } } } diff --git a/bindings/wasm/.gitignore b/bindings/wasm/.gitignore new file mode 100644 index 0000000..c8b241f --- /dev/null +++ b/bindings/wasm/.gitignore @@ -0,0 +1 @@ +target/* \ No newline at end of file diff --git a/bindings/wasm/Cargo.toml b/bindings/wasm/Cargo.toml new file mode 100644 index 0000000..cbeaa36 --- /dev/null +++ b/bindings/wasm/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "wasm" +version = "0.1.3" +authors = ["Nicolas Hatcher "] +description = "IronCalc Web bindings" +license = "MIT/Apache-2.0" +repository = "https://github.com/ironcalc/web-bindings" +edition = "2021" + +[lib] +crate-type = ["cdylib"] + +[dependencies] +# Uses `../ironcalc/base` when used locally, and uses +# the inicated version from crates.io when published. +# https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#multiple-locations +ironcalc_base = { path = "../../base", version = "0.1" } +serde = { version = "1.0", features = ["derive"] } +wasm-bindgen = "0.2.92" +serde-wasm-bindgen = "0.4" + +[dev-dependencies] +wasm-bindgen-test = "0.3.38" diff --git a/bindings/wasm/Makefile b/bindings/wasm/Makefile new file mode 100644 index 0000000..3f1390d --- /dev/null +++ b/bindings/wasm/Makefile @@ -0,0 +1,14 @@ +all: + wasm-pack build --target web --scope ironcalc + cp README.pkg.md pkg/README.md + +lint: + cargo check + cargo fmt -- --check + cargo clippy --all-targets --all-features -- -D warnings + +clean: + cargo clean + rm -rf pkg + +.PHONY: all web lint \ No newline at end of file diff --git a/bindings/wasm/README.md b/bindings/wasm/README.md new file mode 100644 index 0000000..3b2a8dd --- /dev/null +++ b/bindings/wasm/README.md @@ -0,0 +1,31 @@ +# IronCalc Web bindings + +This crate is used to build the web bindings for IronCalc. +Note that it does not contain the xlsx writer and reader, only the engine. + +https://www.npmjs.com/package/@ironcalc/wasm?activeTab=readme + +## Building + +```bash +make +``` + +## Testing + +Right now this is a manual process and only carries out a smoke test: + +1. Build the package +2. Run `python -m http.server` +3. In your browser open + +## Publishing + +Follow the commands: + +```bash +wasm-pack login +make +cd pkg +npm publish --access=public +``` \ No newline at end of file diff --git a/bindings/wasm/README.pkg.md b/bindings/wasm/README.pkg.md new file mode 100644 index 0000000..8e62d0e --- /dev/null +++ b/bindings/wasm/README.pkg.md @@ -0,0 +1,33 @@ +# IronCalc Web bindings + +This package contains web bindings for IronCalc. Note that it does not contain the xlsx writer and reader, only the engine. + + +## Usage + +In your project + +``` +npm install @ironcalc/wasm +``` + +And then in your TypeScript + +```TypeScript +import init, { Model } from "@ironcalc/wasm"; + +await init(); + +function compute() { + const model = new Model('en', 'UTC'); + + model.setUserInput(0, 1, 1, "23"); + model.setUserInput(0, 1, 2, "=A1*3+1"); + + const result = model.getFormattedCellValue(0, 1, 2); + + console.log("Result: ", result); +} + +compute(); +``` diff --git a/bindings/wasm/src/lib.rs b/bindings/wasm/src/lib.rs new file mode 100644 index 0000000..2a0185e --- /dev/null +++ b/bindings/wasm/src/lib.rs @@ -0,0 +1,254 @@ +use wasm_bindgen::{ + prelude::{wasm_bindgen, JsError}, + JsValue, +}; + +use ironcalc_base::{expressions::types::Area, UserModel as BaseModel}; + +fn to_js_error(error: String) -> JsError { + JsError::new(&error.to_string()) +} +#[wasm_bindgen] +pub struct Model { + model: BaseModel, +} + +#[wasm_bindgen] +impl Model { + #[wasm_bindgen(constructor)] + pub fn new(locale: &str, timezone: &str) -> Result { + let model = BaseModel::new_empty("workbook", locale, timezone).map_err(to_js_error)?; + Ok(Model { model }) + } + + pub fn undo(&mut self) -> Result<(), JsError> { + self.model.undo().map_err(to_js_error) + } + + pub fn redo(&mut self) -> Result<(), JsError> { + self.model.redo().map_err(to_js_error) + } + + #[wasm_bindgen(js_name = "canUndo")] + pub fn can_undo(&self) -> bool { + self.model.can_undo() + } + + #[wasm_bindgen(js_name = "canRedo")] + pub fn can_redo(&self) -> bool { + self.model.can_redo() + } + + #[wasm_bindgen(js_name = "pauseEvaluation")] + pub fn pause_evaluation(&mut self) { + self.model.pause_evaluation() + } + + #[wasm_bindgen(js_name = "resumeEvaluation")] + pub fn resume_evaluation(&mut self) { + self.model.resume_evaluation() + } + + pub fn evaluate(&mut self) { + self.model.evaluate(); + } + + #[wasm_bindgen(js_name = "flushSendQueue")] + pub fn flush_send_queue(&mut self) -> String { + self.model.flush_send_queue() + } + + #[wasm_bindgen(js_name = "applyExternalDiffs")] + pub fn apply_external_diffs(&mut self, diffs: &str) -> Result<(), JsError> { + self.model.apply_external_diffs(diffs).map_err(to_js_error) + } + + #[wasm_bindgen(js_name = "getCellContent")] + pub fn get_cell_content(&self, sheet: u32, row: i32, column: i32) -> Result { + self.model + .get_cell_content(sheet, row, column) + .map_err(to_js_error) + } + + #[wasm_bindgen(js_name = "newSheet")] + pub fn new_sheet(&mut self) { + self.model.new_sheet() + } + + #[wasm_bindgen(js_name = "deleteSheet")] + pub fn delete_sheet(&mut self, sheet: u32) -> Result<(), JsError> { + self.model.delete_sheet(sheet).map_err(to_js_error) + } + + #[wasm_bindgen(js_name = "renameSheet")] + pub fn rename_sheet(&mut self, sheet: u32, name: &str) -> Result<(), JsError> { + self.model.rename_sheet(sheet, name).map_err(to_js_error) + } + + #[wasm_bindgen(js_name = "rangeClearAll")] + pub fn range_clear_all( + &mut self, + sheet: u32, + start_row: i32, + start_column: i32, + end_row: i32, + end_column: i32, + ) -> Result<(), JsError> { + let range = Area { + sheet, + row: start_row, + column: start_column, + width: end_column - start_column + 1, + height: end_row - start_row + 1, + }; + self.model.range_clear_all(&range).map_err(to_js_error) + } + + #[wasm_bindgen(js_name = "rangeClearContents")] + pub fn range_clear_contents( + &mut self, + sheet: u32, + start_row: i32, + start_column: i32, + end_row: i32, + end_column: i32, + ) -> Result<(), JsError> { + let range = Area { + sheet, + row: start_row, + column: start_column, + width: end_column - start_column + 1, + height: end_row - start_row + 1, + }; + self.model.range_clear_contents(&range).map_err(to_js_error) + } + + #[wasm_bindgen(js_name = "insertRow")] + pub fn insert_row(&mut self, sheet: u32, row: i32) -> Result<(), JsError> { + self.model.insert_row(sheet, row).map_err(to_js_error) + } + + #[wasm_bindgen(js_name = "insertColumn")] + pub fn insert_column(&mut self, sheet: u32, column: i32) -> Result<(), JsError> { + self.model.insert_column(sheet, column).map_err(to_js_error) + } + + #[wasm_bindgen(js_name = "deleteRow")] + pub fn delete_row(&mut self, sheet: u32, row: i32) -> Result<(), JsError> { + self.model.delete_row(sheet, row).map_err(to_js_error) + } + + #[wasm_bindgen(js_name = "deleteColumn")] + pub fn delete_column(&mut self, sheet: u32, column: i32) -> Result<(), JsError> { + self.model.delete_column(sheet, column).map_err(to_js_error) + } + + #[wasm_bindgen(js_name = "setRowHeight")] + pub fn set_row_height(&mut self, sheet: u32, row: i32, height: f64) -> Result<(), JsError> { + self.model + .set_row_height(sheet, row, height) + .map_err(to_js_error) + } + + #[wasm_bindgen(js_name = "setColumnWidth")] + pub fn set_column_width(&mut self, sheet: u32, column: i32, width: f64) -> Result<(), JsError> { + self.model + .set_column_width(sheet, column, width) + .map_err(to_js_error) + } + + #[wasm_bindgen(js_name = "getRowHeight")] + pub fn get_row_height(&mut self, sheet: u32, row: i32) -> Result { + self.model.get_row_height(sheet, row).map_err(to_js_error) + } + + #[wasm_bindgen(js_name = "getColumnWidth")] + pub fn get_column_width(&mut self, sheet: u32, column: i32) -> Result { + self.model + .get_column_width(sheet, column) + .map_err(to_js_error) + } + + #[wasm_bindgen(js_name = "setUserInput")] + pub fn set_user_input( + &mut self, + sheet: u32, + row: i32, + column: i32, + input: &str, + ) -> Result<(), JsError> { + self.model + .set_user_input(sheet, row, column, input) + .map_err(to_js_error) + } + + #[wasm_bindgen(js_name = "getFormattedCellValue")] + pub fn get_formatted_cell_value( + &self, + sheet: u32, + row: i32, + column: i32, + ) -> Result { + self.model + .get_formatted_cell_value(sheet, row, column) + .map_err(to_js_error) + } + + #[wasm_bindgen(js_name = "getFrozenRowsCount")] + pub fn get_frozen_rows_count(&self, sheet: u32) -> Result { + self.model.get_frozen_rows_count(sheet).map_err(to_js_error) + } + + #[wasm_bindgen(js_name = "getFrozenColumnsCount")] + pub fn get_frozen_columns_count(&self, sheet: u32) -> Result { + self.model + .get_frozen_columns_count(sheet) + .map_err(to_js_error) + } + + #[wasm_bindgen(js_name = "setFrozenRowsCount")] + pub fn set_frozen_rows_count(&mut self, sheet: u32, count: i32) -> Result<(), JsError> { + self.model + .set_frozen_rows_count(sheet, count) + .map_err(to_js_error) + } + + #[wasm_bindgen(js_name = "setFrozenColumnsCount")] + pub fn set_frozen_columns_count(&mut self, sheet: u32, count: i32) -> Result<(), JsError> { + self.model + .set_frozen_columns_count(sheet, count) + .map_err(to_js_error) + } + + #[wasm_bindgen(js_name = "updateRangeStyle")] + pub fn update_range_style( + &mut self, + range: JsValue, + style_path: &str, + value: &str, + ) -> Result<(), JsError> { + let range: Area = + serde_wasm_bindgen::from_value(range).map_err(|e| to_js_error(e.to_string()))?; + self.model + .update_range_style(&range, style_path, value) + .map_err(to_js_error) + } + + #[wasm_bindgen(js_name = "getCellStyle")] + pub fn get_cell_style( + &mut self, + sheet: u32, + row: i32, + column: i32, + ) -> Result { + self.model + .get_cell_style(sheet, row, column) + .map_err(to_js_error) + .map(|x| serde_wasm_bindgen::to_value(&x).unwrap()) + } + + #[wasm_bindgen(js_name = "getWorksheetsProperties")] + pub fn get_worksheets_properties(&self) -> JsValue { + serde_wasm_bindgen::to_value(&self.model.get_worksheets_properties()).unwrap() + } +} diff --git a/bindings/wasm/test.html b/bindings/wasm/test.html new file mode 100644 index 0000000..36bc5ff --- /dev/null +++ b/bindings/wasm/test.html @@ -0,0 +1,28 @@ + + + + + + Test IronCalc Web Bindings + + + +
Please have a look at the console
+ + \ No newline at end of file diff --git a/bindings/wasm/tests/test.mjs b/bindings/wasm/tests/test.mjs new file mode 100644 index 0000000..ab31c81 --- /dev/null +++ b/bindings/wasm/tests/test.mjs @@ -0,0 +1,123 @@ +import test from 'node:test'; +import assert from 'node:assert' +import { Model } from "../pkg/wasm.js"; + +test('Frozen rows and columns', () => { + let model = new Model('en', 'UTC'); + assert.strictEqual(model.getFrozenRowsCount(0), 0); + assert.strictEqual(model.getFrozenColumnsCount(0), 0); + + model.setFrozenColumnsCount(0, 4); + model.setFrozenRowsCount(0, 3) + + assert.strictEqual(model.getFrozenRowsCount(0), 3); + assert.strictEqual(model.getFrozenColumnsCount(0), 4); +}); + +test('Row height', () => { + let model = new Model('en', 'UTC'); + assert.strictEqual(model.getRowHeight(0, 3), 21); + + model.setRowHeight(0, 3, 32); + assert.strictEqual(model.getRowHeight(0, 3), 32); + + model.undo(); + assert.strictEqual(model.getRowHeight(0, 3), 21); + + model.redo(); + assert.strictEqual(model.getRowHeight(0, 3), 32); + + model.setRowHeight(0, 3, 320); + assert.strictEqual(model.getRowHeight(0, 3), 320); +}); + +test('Evaluates correctly', (t) => { + const model = new Model('en', 'UTC'); + model.setUserInput(0, 1, 1, "23"); + model.setUserInput(0, 1, 2, "=A1*3+1"); + + const result = model.getFormattedCellValue(0, 1, 2); + assert.strictEqual(result, "70"); +}); + +test('Styles work', () => { + const model = new Model('en', 'UTC'); + let style = model.getCellStyle(0, 1, 1); + assert.deepEqual(style, { + num_fmt: 'general', + fill: { pattern_type: 'none' }, + font: { + sz: 11, + color: '#000000', + name: 'Calibri', + family: 2, + scheme: 'minor' + }, + border: {}, + quote_prefix: false + }); + model.setUserInput(0, 1, 1, "'=1+1"); + style = model.getCellStyle(0, 1, 1); + assert.deepEqual(style, { + num_fmt: 'general', + fill: { pattern_type: 'none' }, + font: { + sz: 11, + color: '#000000', + name: 'Calibri', + family: 2, + scheme: 'minor' + }, + border: {}, + quote_prefix: true + }); +}); + +test("Add sheets", (t) => { + const model = new Model('en', 'UTC'); + model.newSheet(); + model.renameSheet(1, "NewName"); + let props = model.getWorksheetsProperties(); + assert.deepEqual(props, [{ + name: 'Sheet1', + sheet_id: 1, + state: 'visible' + }, + { + name: 'NewName', + sheet_id: 2, + state: 'visible' + } + ]); +}); + +test("invalid sheet index throws an exception", () => { + const model = new Model('en', 'UTC'); + assert.throws(() => { + model.setRowHeight(1, 1, 100); + }, { + name: 'Error', + message: 'Invalid sheet index', + }); +}); + +test("invalid column throws an exception", () => { + const model = new Model('en', 'UTC'); + assert.throws(() => { + model.setRowHeight(0, -1, 100); + }, { + name: 'Error', + message: "Row number '-1' is not valid.", + }); +}); + +test("floating column numbers get truncated", () => { + const model = new Model('en', 'UTC'); + model.setRowHeight(0.8, 5.2, 100.5); + + assert.strictEqual(model.getRowHeight(0.11, 5.99), 100.5); + assert.strictEqual(model.getRowHeight(0, 5), 100.5); +}); + + + diff --git a/codecov.yml b/codecov.yml index 93ea3d9..5797012 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,2 +1,3 @@ ignore: - "xlsx/src/bin" + - "bindings/wasm" diff --git a/xlsx/Cargo.toml b/xlsx/Cargo.toml index 8a47071..4a4569e 100644 --- a/xlsx/Cargo.toml +++ b/xlsx/Cargo.toml @@ -12,8 +12,8 @@ readme = "README.md" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -zip = "0.5" -roxmltree = "0.13.0" +zip = "0.6" +roxmltree = "0.19" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" thiserror = "1.0" @@ -21,7 +21,7 @@ thiserror = "1.0" # the inicated version from crates.io when published. # https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#multiple-locations ironcalc_base = { path = "../base", version = "0.1.0" } -itertools = "0.10.5" +itertools = "0.12" chrono = "0.4" [dev-dependencies] diff --git a/xlsx/src/export/doc_props.rs b/xlsx/src/export/doc_props.rs index 4726df0..ad6f2f5 100644 --- a/xlsx/src/export/doc_props.rs +++ b/xlsx/src/export/doc_props.rs @@ -1,4 +1,4 @@ -use chrono::NaiveDateTime; +use chrono::DateTime; use ironcalc_base::{ new_empty::{APPLICATION, APP_VERSION, IRONCALC_USER}, types::Workbook, @@ -36,7 +36,7 @@ pub(crate) fn get_core_xml(workbook: &Workbook, milliseconds: i64) -> Result s, None => { return Err(XlsxError::Xml(format!(