Browse Source

using the better webassembly setup

master
Inderjit Gill 9 months ago
parent
commit
008e01ad3d
20 changed files with 1122 additions and 9259 deletions
  1. 0
    5
      .gitignore
  2. 125
    145
      Cargo.lock
  3. 29
    14
      Cargo.toml
  4. 0
    23
      README.md
  5. 0
    9
      bootstrap.js
  6. 10
    0
      build.sh
  7. 0
    9029
      package-lock.json
  8. 0
    12
      package.json
  9. 810
    0
      src/colour.rs
  10. 39
    0
      src/error.rs
  11. 47
    3
      src/lib.rs
  12. 32
    0
      src/utils.rs
  13. 0
    10
      webpack.config.js
  14. 2
    0
      www/.gitignore
  15. 0
    0
      www/css/base-min.css
  16. 0
    0
      www/css/pure-min.css
  17. 0
    0
      www/css/stylesheet.css
  18. 0
    0
      www/favicon.ico
  19. 17
    1
      www/index.html
  20. 11
    8
      www/index.js

+ 0
- 5
.gitignore View File

@@ -1,6 +1 @@
/target
**/*.rs.bk

/node_modules/

wasm_themacs*

+ 125
- 145
Cargo.lock View File

@@ -1,71 +1,56 @@
[[package]]
name = "backtrace"
version = "0.3.7"
name = "cfg-if"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"backtrace-sys 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-demangle 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "backtrace-sys"
version = "0.1.16"
name = "console_error_panic_hook"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "cc"
version = "1.0.15"
name = "futures"
version = "0.1.25"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "cfg-if"
version = "0.1.3"
name = "js-sys"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"wasm-bindgen 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "dtoa"
version = "0.4.2"
name = "lazy_static"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "failure"
version = "0.1.1"
name = "libc"
version = "0.2.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"backtrace 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
"failure_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "failure_derive"
version = "0.1.1"
name = "log"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)",
"synstructure 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "itoa"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "libc"
version = "0.2.40"
name = "memory_units"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "proc-macro2"
version = "0.3.8"
version = "0.4.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -73,154 +58,151 @@ dependencies = [

[[package]]
name = "quote"
version = "0.3.15"
version = "0.6.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "quote"
version = "0.5.2"
name = "scoped-tls"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "rustc-demangle"
version = "0.1.8"
name = "syn"
version = "0.15.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "sen-colour"
version = "0.2.0"
name = "themacs"
version = "0.1.0"
dependencies = [
"failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"console_error_panic_hook 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-test 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)",
"wee_alloc 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "serde"
version = "1.0.47"
name = "unicode-xid"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "serde_derive"
version = "1.0.47"
name = "unreachable"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.13.7 (registry+https://github.com/rust-lang/crates.io-index)",
"void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "serde_json"
version = "1.0.17"
name = "void"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"itoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "syn"
version = "0.11.11"
name = "wasm-bindgen"
version = "0.2.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
"synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-macro 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "syn"
version = "0.13.7"
name = "wasm-bindgen-backend"
version = "0.2.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-shared 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "synom"
version = "0.11.3"
name = "wasm-bindgen-futures"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
"js-sys 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "synstructure"
version = "0.6.1"
name = "wasm-bindgen-macro"
version = "0.2.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-macro-support 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "unicode-xid"
version = "0.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "unicode-xid"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "wasm-bindgen"
version = "0.2.8"
name = "wasm-bindgen-macro-support"
version = "0.2.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"wasm-bindgen-macro 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-backend 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-shared 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "wasm-bindgen-backend"
version = "0.2.8"
name = "wasm-bindgen-shared"
version = "0.2.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.13.7 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-shared 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "wasm-bindgen-macro"
version = "0.2.8"
name = "wasm-bindgen-test"
version = "0.2.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.13.7 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-backend 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-shared 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"console_error_panic_hook 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
"js-sys 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-futures 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-test-macro 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "wasm-bindgen-shared"
version = "0.2.8"
name = "wasm-bindgen-test-macro"
version = "0.2.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"serde 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "wasm_themacs"
version = "0.1.0"
name = "wee_alloc"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"sen-colour 0.2.0",
"wasm-bindgen 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)",
"memory_units 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "winapi"
version = "0.3.4"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -238,32 +220,30 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"

[metadata]
"checksum backtrace 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea58cd16fd6c9d120b5bcb01d63883ae4cc7ba2aed35c1841b862a3c7ef6639"
"checksum backtrace-sys 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "44585761d6161b0f57afc49482ab6bd067e4edef48c12a152c237eb0203f7661"
"checksum cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)" = "0ebb87d1116151416c0cf66a0e3fb6430cccd120fd6300794b4dfaa050ac40ba"
"checksum cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "405216fd8fe65f718daa7102ea808a946b6ce40c742998fbfd3463645552de18"
"checksum dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab"
"checksum failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "934799b6c1de475a012a02dab0ace1ace43789ee4b99bcfbf1a2e3e8ced5de82"
"checksum failure_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c7cdda555bb90c9bb67a3b670a0f42de8e73f5981524123ad8578aafec8ddb8b"
"checksum itoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c069bbec61e1ca5a596166e55dfe4773ff745c3d16b700013bcaff9a6df2c682"
"checksum libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)" = "6fd41f331ac7c5b8ac259b8bf82c75c0fb2e469bbf37d2becbba9a6a2221965b"
"checksum proc-macro2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "1b06e2f335f48d24442b35a19df506a835fb3547bc3c06ef27340da9acf5cae7"
"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
"checksum quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9949cfe66888ffe1d53e6ec9d9f3b70714083854be20fd5e271b232a017401e8"
"checksum rustc-demangle 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "76d7ba1feafada44f2d38eed812bd2489a03c0f5abb975799251518b68848649"
"checksum serde 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)" = "c9bc5ad5d354bc43e8ba78885f81650e6d4467a55716271b49d7ceeba739e21e"
"checksum serde_derive 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)" = "a0b9c70a763b79f976e7147322d6c523da0705b3d20e57fd764172d0741c50f2"
"checksum serde_json 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)" = "f3ad6d546e765177cf3dded3c2e424a8040f870083a0e64064746b958ece9cb1"
"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad"
"checksum syn 0.13.7 (registry+https://github.com/rust-lang/crates.io-index)" = "61b8f1b737f929c6516ba46a3133fd6d5215ad8a62f66760f851f7048aebedfb"
"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
"checksum synstructure 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3a761d12e6d8dcb4dcf952a7a89b475e3a9d69e4a69307e01a470977642914bd"
"checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc"
"checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4"
"checksum console_error_panic_hook 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6c5dd2c094474ec60a6acaf31780af270275e3153bafff2db5995b715295762e"
"checksum futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)" = "49e7653e374fe0d0c12de4250f0bdb60680b8c80eed558c5c7538eec9c89e21b"
"checksum js-sys 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "58cfec35fd4a94f3cf357d5cb7da71c71cd52720c2f2a7320090a8db5f06f655"
"checksum lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1"
"checksum libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)" = "2d2857ec59fadc0773853c664d2d18e7198e83883e7060b63c924cb077bd5c74"
"checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6"
"checksum memory_units 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3"
"checksum proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)" = "77619697826f31a02ae974457af0b29b723e5619e113e9397b8b82c6bd253f09"
"checksum quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "53fa22a1994bd0f9372d7a816207d8a2677ad0325b073f5c5332760f0fb62b5c"
"checksum scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "332ffa32bf586782a3efaeb58f127980944bbc8c4d6913a86107ac2a5ab24b28"
"checksum syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)" = "ae8b29eb5210bc5cf63ed6149cbf9adfc82ac0be023d8735c176ee74a2db4da7"
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
"checksum wasm-bindgen 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "b0271974d38e09a1e102d95a34a6b27a104ee77541c0314be7e91e026bff9e89"
"checksum wasm-bindgen-backend 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8e9a4a55017ec67b697893292efd05eb5f7e0ae26ddb4d9879eee6d60e66eb2b"
"checksum wasm-bindgen-macro 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "87e37cc5c09b0b58897ea69be6f81d1effb7ab22b34eb48626267471d8c4ec9e"
"checksum wasm-bindgen-shared 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "a629526dde66833247cfeb5fa2d5ea88f116cb05146f5039f6085784fdea679b"
"checksum winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "04e3bd221fcbe8a271359c04f21a76db7d0c6028862d1bb5512d85e1e2eb5bb3"
"checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56"
"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
"checksum wasm-bindgen 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)" = "91f95b8f30407b9ca0c2de157281d3828bbed1fc1f55bea6eb54f40c52ec75ec"
"checksum wasm-bindgen-backend 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)" = "ab7c242ebcb45bae45340986c48d1853eb2c1c52ff551f7724951b62a2c51429"
"checksum wasm-bindgen-futures 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "d1784e7401a90119b2a4e8ec9c8d37c3594c3e3bb9ba24533ee1969eebaf0485"
"checksum wasm-bindgen-macro 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)" = "6e353f83716dec9a3597b5719ef88cb6c9e461ec16528f38aa023d3224b4e569"
"checksum wasm-bindgen-macro-support 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)" = "3cc90b65fe69c3dd5a09684517dc79f42b847baa2d479c234d125e0a629d9b0a"
"checksum wasm-bindgen-shared 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)" = "a71a37df4f5845025f96f279d20bbe5b19cbcb77f5410a3a90c6c544d889a162"
"checksum wasm-bindgen-test 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)" = "a98dfd06998415cef588205b1462a03f01447c10870231145b603f801f770bac"
"checksum wasm-bindgen-test-macro 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)" = "538a21fed1ca83ef51d333ce668d925b9ab017818f6c92a54900a3c03dab7ca8"
"checksum wee_alloc 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "27875be1daf838fa18f3e94fd19fd12638e34615b42f56da2610c8f46be80cc6"
"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0"
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

+ 29
- 14
Cargo.toml View File

@@ -1,29 +1,44 @@
[package]
name = "wasm_themacs"
name = "themacs"
version = "0.1.0"
authors = ["Inderjit Gill <inderjit.gill@gmail.com>"]
authors = ["Inderjit Gill <email@indy.io>"]
edition = "2018"

[lib]
crate-type = ["cdylib"]
crate-type = ["cdylib", "rlib"]

[features]
default = ["console_error_panic_hook"]

[dependencies]
wasm-bindgen = "0.2.8"
sen-colour = { path = "../sen-colour" }
cfg-if = "0.1.2"
wasm-bindgen = "0.2"

# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
# code size when deploying.
console_error_panic_hook = { version = "0.1.1", optional = true }

# `wee_alloc` is a tiny allocator for wasm that is only ~1K in code size
# compared to the default allocator's ~10K. It is slower than the default
# allocator, however.
#
# Unfortunately, `wee_alloc` requires nightly Rust when targeting wasm for now.
wee_alloc = { version = "0.4.2", optional = true }

[dev-dependencies]
wasm-bindgen-test = "0.2"

[profile.release]
# Include function names in the `.wasm` for better debugging and
# profiling. Comment this out if you're trying to create the smallest `.wasm`
# binaries you can.
debug = true
debug = false

# # Uncomment these lines to create smaller `.wasm` binaries, at the cost of
# # longer compile times.
# codegen-units = 1
# incremental = false
# lto = true
# opt-level = "z"


# # option to optimise for size
# opt-level = "s"
codegen-units = 1
incremental = false
lto = true
opt-level = "z"

+ 0
- 23
README.md View File

@@ -1,23 +0,0 @@
Themacs
======

## Overview



## ensure that the correct toolchain is installed
```sh
$ rustup update
$ rustup install nightly
$ rustup target add wasm32-unknown-unknown --toolchain nightly
$ cargo install wasm-bindgen-cli
```

## npm bollocks
```sh
$ npm install
$ npm run build-debug
$ npm run serve
```

can now visit http://localhost:8080

+ 0
- 9
bootstrap.js View File

@@ -1,9 +0,0 @@
const index = import("./index");
index.then(() => {
console.log("Loaded...");
});


document.addEventListener('DOMContentLoaded', () => {
console.log('DOMContentLoaded');
}, false);

+ 10
- 0
build.sh View File

@@ -0,0 +1,10 @@
#!/bin/sh

if [ "$1" = "release" ]
then
cargo +nightly build --release --target wasm32-unknown-unknown
wasm-bindgen target/wasm32-unknown-unknown/release/themacs.wasm --out-dir www --no-typescript --no-modules
else
cargo +nightly build --target wasm32-unknown-unknown
wasm-bindgen target/wasm32-unknown-unknown/debug/themacs.wasm --out-dir www --no-typescript --no-modules
fi

+ 0
- 9029
package-lock.json
File diff suppressed because it is too large
View File


+ 0
- 12
package.json View File

@@ -1,12 +0,0 @@
{
"scripts": {
"serve": "webpack-dev-server",
"build-debug": "cargo +nightly build --target wasm32-unknown-unknown && wasm-bindgen target/wasm32-unknown-unknown/debug/wasm_themacs.wasm --out-dir .",
"build-release": "cargo +nightly build --release --target wasm32-unknown-unknown && wasm-bindgen target/wasm32-unknown-unknown/release/wasm_themacs.wasm --out-dir ."
},
"devDependencies": {
"webpack": "^4.0.1",
"webpack-cli": "^2.0.10",
"webpack-dev-server": "^3.1.0"
}
}

+ 810
- 0
src/colour.rs View File

@@ -0,0 +1,810 @@
// Copyright (C) 2018 Inderjit Gill

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

// |--------+-----------+-------------+-------------|
// | format | element 0 | element 1 | element 2 |
// |--------+-----------+-------------+-------------|
// | RGB | R 0..1 | G 0..1 | B 0..1 |
// | HSL | H 0..360 | S 0..1 | L 0..1 |
// | HSLuv | H 0..360 | S 0..100 | L 0..100 |
// | LAB | L 0..100 | A -128..128 | B -128..128 |
// |--------+-----------+-------------+-------------|


use crate::error::{SenError, SenResult};
use std;

const REF_U: f64 = 0.197_830_006_642_836_807_64;
const REF_V: f64 = 0.468_319_994_938_791_003_70;

// http://www.brucelindbloom.com/index.html?Equations.html
// http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html

// we're using an sRGB working space with a D65 reference white

// https://uk.mathworks.com/help/images/ref/whitepoint.html
// the D65 whitepoint
const WHITEPOINT_0: f64 = 0.9504;
const WHITEPOINT_1: f64 = 1.0;
const WHITEPOINT_2: f64 = 1.0888;

const CIE_EPSILON: f64 = 0.008_856;
const CIE_KAPPA: f64 = 903.3;

// intent from the CIE
//
// #define CIE_EPSILON (216.0f / 24389.0f)
// #define CIE_KAPPA (24389.0f / 27.0f)

// RGB to XYZ (M)
// 0.4124564 0.3575761 0.1804375
// 0.2126729 0.7151522 0.0721750
// 0.0193339 0.1191920 0.9503041

// XYZ to RBG (M)^-1
// 3.2404542 -1.5371385 -0.4985314
// -0.9692660 1.8760108 0.0415560
// 0.0556434 -0.2040259 1.0572252

#[derive(Debug, PartialEq, Clone, Copy)]
pub enum Format {
RGB,
HSLuv,
HSL,
LAB,
HSV,
}

#[derive(Debug, Clone, Copy)]
pub enum Colour {
RGB(f64, f64, f64, f64),
HSLuv(f64, f64, f64, f64),
HSL(f64, f64, f64, f64),
LAB(f64, f64, f64, f64),
HSV(f64, f64, f64, f64),
XYZ(f64, f64, f64, f64),
LUV(f64, f64, f64, f64),
LCH(f64, f64, f64, f64),
}

impl Colour {
pub fn is_format(&self, format: Format) -> bool {
match format {
Format::RGB => match *self {
Colour::RGB(_, _, _, _) => true,
_ => false,
},
Format::HSLuv => match *self {
Colour::HSLuv(_, _, _, _) => true,
_ => false,
},
Format::HSL => match *self {
Colour::HSL(_, _, _, _) => true,
_ => false,
},
Format::LAB => match *self {
Colour::LAB(_, _, _, _) => true,
_ => false,
},
Format::HSV => match *self {
Colour::HSV(_, _, _, _) => true,
_ => false,
},
}
}

pub fn clone_as(&self, format: Format) -> SenResult<Colour> {
match *self {
Colour::HSL(h, s, l, alpha) => match format {
Format::HSL => Ok(Colour::HSL(h, s, l, alpha)),
Format::HSLuv => hsluv_from_xyz(xyz_from_rgb(rgb_from_hsl(*self)?)?),
Format::HSV => hsv_from_rgb(rgb_from_hsl(*self)?),
Format::LAB => lab_from_xyz(xyz_from_rgb(rgb_from_hsl(*self)?)?),
Format::RGB => rgb_from_hsl(*self),
},
Colour::HSLuv(h, s, l, alpha) => match format {
Format::HSL => hsl_from_rgb(rgb_from_xyz(xyz_from_hsluv(*self)?)?),
Format::HSLuv => Ok(Colour::HSLuv(h, s, l, alpha)),
Format::HSV => hsv_from_rgb(rgb_from_xyz(xyz_from_hsluv(*self)?)?),
Format::LAB => lab_from_xyz(xyz_from_hsluv(*self)?),
Format::RGB => rgb_from_xyz(xyz_from_hsluv(*self)?),
},
Colour::HSV(h, s, v, alpha) => match format {
Format::HSL => hsl_from_rgb(rgb_from_hsv(*self)?),
Format::HSLuv => hsluv_from_xyz(xyz_from_rgb(rgb_from_hsv(*self)?)?),
Format::HSV => Ok(Colour::HSV(h, s, v, alpha)),
Format::LAB => lab_from_xyz(xyz_from_rgb(rgb_from_hsv(*self)?)?),
Format::RGB => rgb_from_hsv(*self),
},
Colour::LAB(l, a, b, alpha) => match format {
Format::HSL => hsl_from_rgb(rgb_from_xyz(xyz_from_lab(*self)?)?),
Format::HSLuv => hsluv_from_xyz(xyz_from_lab(*self)?),
Format::HSV => hsv_from_rgb(rgb_from_xyz(xyz_from_lab(*self)?)?),
Format::LAB => Ok(Colour::LAB(l, a, b, alpha)),
Format::RGB => rgb_from_xyz(xyz_from_lab(*self)?),
},
Colour::RGB(r, g, b, alpha) => match format {
Format::HSL => hsl_from_rgb(*self),
Format::HSLuv => hsluv_from_xyz(xyz_from_rgb(*self)?),
Format::HSV => hsv_from_rgb(*self),
Format::LAB => lab_from_xyz(xyz_from_rgb(*self)?),
Format::RGB => Ok(Colour::RGB(r, g, b, alpha)),
},
_ => Err(SenError::IncorrectColourFormat),
}
}
}

fn colour_to_axis(component: f64) -> f64 {
if component > 0.04045 {
((component + 0.055) / 1.055).powf(2.4)
} else {
(component / 12.92)
}
}

fn axis_to_colour(a: f64) -> f64 {
if a > 0.003_130_8 {
(1.055 * a.powf(1.0 / 2.4)) - 0.055
} else {
a * 12.92
}
}

fn xyz_from_rgb(rgb: Colour) -> SenResult<Colour> {
match rgb {
Colour::RGB(r, g, b, alpha) => {
let rr = colour_to_axis(r);
let gg = colour_to_axis(g);
let bb = colour_to_axis(b);

// multiply by matrix
// see http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
// sRGB colour space with D65 reference white
//

let x = (rr * 0.412_390_799_265_959_5)
+ (gg * 0.357_584_339_383_877_96)
+ (bb * 0.180_480_788_401_834_3);
let y = (rr * 0.212_639_005_871_510_36)
+ (gg * 0.715_168_678_767_755_927_46)
+ (bb * 0.072_192_315_360_733_715_00);
let z = (rr * 0.019_330_818_715_591_850_69)
+ (gg * 0.119_194_779_794_625_987_91)
+ (bb * 0.950_532_152_249_660_580_86);

Ok(Colour::XYZ(x, y, z, alpha))
}
_ => Err(SenError::IncorrectColourFormat),
}
}

fn rgb_from_xyz(xyz: Colour) -> SenResult<Colour> {
match xyz {
Colour::XYZ(x, y, z, alpha) => {
let r = (x * 3.240_969_941_904_521_343_77)
+ (y * -1.537_383_177_570_093_457_94)
+ (z * -0.498_610_760_293_003_283_66);
let g = (x * -0.969_243_636_280_879_826_13)
+ (y * 1.875_967_501_507_720_667_72)
+ (z * 0.041_555_057_407_175_612_47);
let b = (x * 0.055_630_079_696_993_608_46)
+ (y * -0.203_976_958_888_976_564_35)
+ (z * 1.056_971_514_242_878_560_72);

let rr = axis_to_colour(r);
let gg = axis_to_colour(g);
let bb = axis_to_colour(b);

Ok(Colour::RGB(rr, gg, bb, alpha))
}
_ => Err(SenError::IncorrectColourFormat),
}
}

fn axis_to_lab_component(a: f64) -> f64 {
if a > CIE_EPSILON {
a.cbrt()
} else {
((CIE_KAPPA * a) + 16.0) / 116.0
}
}

fn lab_from_xyz(xyz: Colour) -> SenResult<Colour> {
match xyz {
Colour::XYZ(x, y, z, alpha) => {
let xr = x / WHITEPOINT_0;
let yr = y / WHITEPOINT_1;
let zr = z / WHITEPOINT_2;

let fx = axis_to_lab_component(xr);
let fy = axis_to_lab_component(yr);
let fz = axis_to_lab_component(zr);

let l = (116.0 * fy) - 16.0;
let a = 500.0 * (fx - fy);
let b = 200.0 * (fy - fz);

Ok(Colour::LAB(l, a, b, alpha))
}
_ => Err(SenError::IncorrectColourFormat),
}
}

fn max_channel(r: f64, g: f64, b: f64) -> i32 {
let hi = if r > g { 0 } else { 1 };
let hival = if r > g { r } else { g };

if b > hival {
2
} else {
hi
}
}

// TODO: implement a better fmod, this one is not exact
fn fmod(a: f64, b: f64) -> f64 {
a - b * (a / b).floor()
}

// http://www.rapidtables.com/convert/color/rgb-to-hsl.htm
fn hue(colour: Colour, max_chan: i32, chroma: f64) -> SenResult<f64> {
if chroma == 0.0 {
// return Err(SenError::InvalidColourHue)
return Ok(0.0);
}

let mut angle: f64;

match colour {
Colour::RGB(r, g, b, _) => {
angle = match max_chan {
0 => fmod((g - b) / chroma, 6.0),
1 => ((b - r) / chroma) + 2.0,
2 => ((r - g) / chroma) + 4.0,
_ => return Err(SenError::InvalidColourChannel),
}
}
_ => return Err(SenError::IncorrectColourFormat),
}

angle *= 60.0;

while angle < 0.0 {
angle += 360.0;
}

Ok(angle)
}

// http://www.rapidtables.com/convert/color/rgb-to-hsl.htm
fn hsl_from_rgb(colour: Colour) -> SenResult<Colour> {
match colour {
Colour::RGB(r, g, b, alpha) => {
let min_val = r.min(g).min(b);
let max_val = r.max(g).max(b);
let max_ch = max_channel(r, g, b);

let delta = max_val - min_val;

let h = hue(colour, max_ch, delta)?;
let lightness = 0.5 * (min_val + max_val);
let saturation: f64 = if delta == 0.0 {
0.0
} else {
delta / (1.0 - ((2.0 * lightness) - 1.0).abs())
};

Ok(Colour::HSL(h, saturation, lightness, alpha))
}
_ => Err(SenError::IncorrectColourFormat),
}
}

fn hsv_from_rgb(colour: Colour) -> SenResult<Colour> {
match colour {
Colour::RGB(r, g, b, alpha) => {
let min_val = r.min(g).min(b);
let max_val = r.max(g).max(b);
let max_ch = max_channel(r, g, b);

let chroma = max_val - min_val;
let h = hue(colour, max_ch, chroma)?;

// valid_hue: bool = chroma != 0.0;

let saturation: f64 = if chroma == 0.0 { 0.0 } else { chroma / max_val };

// TODO: set valid_hue
// return col.set('valid_hue', valid_hue);

Ok(Colour::HSV(h, saturation, max_val, alpha))
}
_ => Err(SenError::IncorrectColourFormat),
}
}

fn rgb_from_chm(chroma: f64, h: f64, m: f64, alpha: f64) -> Colour {
// todo: validhue test
//
// if (c.get('validHue') === undefined) {
// return construct(Format.RGB, [m, m, m, element(c, ALPHA)]);
//}

let hprime = h / 60.0;
let x = chroma * (1.0 - (fmod(hprime, 2.0) - 1.0).abs());
let mut r = 0.0;
let mut g = 0.0;
let mut b = 0.0;

if hprime < 1.0 {
r = chroma;
g = x;
b = 0.0;
} else if hprime < 2.0 {
r = x;
g = chroma;
b = 0.0;
} else if hprime < 3.0 {
r = 0.0;
g = chroma;
b = x;
} else if hprime < 4.0 {
r = 0.0;
g = x;
b = chroma;
} else if hprime < 5.0 {
r = x;
g = 0.0;
b = chroma;
} else if hprime < 6.0 {
r = chroma;
g = 0.0;
b = x;
}

Colour::RGB(r + m, g + m, b + m, alpha)
}

fn rgb_from_hsl(hsl: Colour) -> SenResult<Colour> {
match hsl {
Colour::HSL(h, s, l, alpha) => {
let chroma = (1.0 - ((2.0 * l) - 1.0).abs()) * s;
let m = l - (0.5 * chroma);

// todo: set validhue
// f64 col = c.set('validHue', true);

Ok(rgb_from_chm(chroma, h, m, alpha))
}
_ => Err(SenError::IncorrectColourFormat),
}
}

fn lab_component_to_axis(l: f64) -> f64 {
if l.powf(3.0) > CIE_EPSILON {
l.powf(3.0)
} else {
((116.0 * l) - 16.0) / CIE_KAPPA
}
}

fn xyz_from_lab(lab: Colour) -> SenResult<Colour> {
match lab {
Colour::LAB(l, a, b, alpha) => {
let fy = (l + 16.0) / 116.0;
let fz = fy - (b / 200.0);
let fx = (a / 500.0) + fy;

let xr = lab_component_to_axis(fx);
let mut yr;
if l > (CIE_EPSILON * CIE_KAPPA) {
yr = (l + 16.0) / 116.0;
yr = yr * yr * yr;
} else {
yr = l / CIE_KAPPA;
}
let zr = lab_component_to_axis(fz);

Ok(Colour::XYZ(
WHITEPOINT_0 * xr,
WHITEPOINT_1 * yr,
WHITEPOINT_2 * zr,
alpha,
))
}
_ => Err(SenError::IncorrectColourFormat),
}
}

fn rgb_from_hsv(hsv: Colour) -> SenResult<Colour> {
match hsv {
Colour::HSV(h, s, v, alpha) => {
let chroma = v * s;
let m = v - chroma;

Ok(rgb_from_chm(chroma, h, m, alpha))
}
_ => Err(SenError::IncorrectColourFormat),
}
}

// the luv and hsluv code is based on https://github.com/hsluv/hsluv-c
// which uses the MIT License:

// # The MIT License (MIT)

// Copyright © 2015 Alexei Boronine (original idea, JavaScript implementation)
// Copyright © 2015 Roger Tallada (Obj-C implementation)
// Copyright © 2017 Martin Mitáš (C implementation, based on Obj-C
// implementation)

// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.

#[derive(Debug, Clone, Copy)]
struct Bounds {
a: f64,
b: f64,
}

fn get_bounds(l: f64, bounds: &mut [Bounds]) {
let tl = l + 16.0;
let sub1 = (tl * tl * tl) / 1_560_896.0;
let sub2 = if sub1 > CIE_EPSILON {
sub1
} else {
l / CIE_KAPPA
};

let mut m = [[0f64; 3]; 3];
m[0][0] = 3.240_969_941_904_521_343_77;
m[0][1] = -1.537_383_177_570_093_457_94;
m[0][2] = -0.498_610_760_293_003_283_66;
m[1][0] = -0.969_243_636_280_879_826_13;
m[1][1] = 1.875_967_501_507_720_667_72;
m[1][2] = 0.041_555_057_407_175_612_47;
m[2][0] = 0.055_630_079_696_993_608_46;
m[2][1] = -0.203_976_958_888_976_564_35;
m[2][2] = 1.056_971_514_242_878_560_72;

for channel in 0..3 {
let m1 = m[channel][0];
let m2 = m[channel][1];
let m3 = m[channel][2];

for t in 0..2 {
let top1 = (284_517.0 * m1 - 94_839.0 * m3) * sub2;
let top2 = (838_422.0 * m3 + 769_860.0 * m2 + 731_718.0 * m1) * l * sub2
- 769_860.0 * (t as f64) * l;
let bottom = (632_260.0 * m3 - 126_452.0 * m2) * sub2 + 126_452.0 * (t as f64);

bounds[channel * 2 + t].a = top1 / bottom;
bounds[channel * 2 + t].b = top2 / bottom;
}
}
}

fn ray_length_until_intersect(theta: f64, line: &Bounds) -> f64 {
line.b / (theta.sin() - line.a * theta.cos())
}

fn max_chroma_for_lh(l: f64, h: f64) -> f64 {
let mut min_len = std::f64::MAX;
let hrad = h * 0.017_453_292_519_943_295_77; /* (2 * pi / 260) */
let mut bounds = [Bounds { a: 0.0, b: 0.0 }; 6];

get_bounds(l, &mut bounds);

for b in &bounds {
let l2 = ray_length_until_intersect(hrad, &b);

if l2 >= 0.0 && l2 < min_len {
min_len = l2;
}
}

min_len
}

/* http://en.wikipedia.org/wiki/CIELUV
* In these formulas, Yn refers to the reference white point. We are using
* illuminant D65, so Yn (see refY in Maxima file) equals 1. The formula is
* simplified accordingly.
*/
fn y2l(y: f64) -> f64 {
if y <= CIE_EPSILON {
y * CIE_KAPPA
} else {
116.0 * y.cbrt() - 16.0
}
}

fn l2y(l: f64) -> f64 {
if l <= 8.0 {
l / CIE_KAPPA
} else {
let x = (l + 16.0) / 116.0;
x * x * x
}
}

fn luv_from_xyz(xyz: Colour) -> SenResult<Colour> {
match xyz {
Colour::XYZ(x, y, z, alpha) => {
let var_u = (4.0 * x) / (x + (15.0 * y) + (3.0 * z));
let var_v = (9.0 * y) / (x + (15.0 * y) + (3.0 * z));
let l = y2l(y);
let u = 13.0 * l * (var_u - REF_U);
let v = 13.0 * l * (var_v - REF_V);

if l < 0.000_000_01 {
Ok(Colour::LUV(l, 0.0, 0.0, alpha))
} else {
Ok(Colour::LUV(l, u, v, alpha))
}
}
_ => Err(SenError::IncorrectColourFormat),
}
}

fn xyz_from_luv(luv: Colour) -> SenResult<Colour> {
match luv {
Colour::LUV(l, u, v, alpha) => {
if l <= 0.000_000_01 {
return Ok(Colour::XYZ(0.0, 0.0, 0.0, alpha));
}

let var_u = u / (13.0 * l) + REF_U;
let var_v = v / (13.0 * l) + REF_V;
let y = l2y(l);
let x = -(9.0 * y * var_u) / ((var_u - 4.0) * var_v - var_u * var_v);
let z = (9.0 * y - (15.0 * var_v * y) - (var_v * x)) / (3.0 * var_v);

Ok(Colour::XYZ(x, y, z, alpha))
}
_ => Err(SenError::IncorrectColourFormat),
}
}

fn lch_from_luv(luv: Colour) -> SenResult<Colour> {
match luv {
Colour::LUV(l, u, v, alpha) => {
let mut h: f64;
let c = (u * u + v * v).sqrt();

if c < 0.000_000_01 {
h = 0.0;
} else {
h = v.atan2(u) * 57.295_779_513_082_320_876_80; /* (180 / pi) */
if h < 0.0 {
h += 360.0;
}
}

Ok(Colour::LCH(l, c, h, alpha))
}
_ => Err(SenError::IncorrectColourFormat),
}
}

fn luv_from_lch(lch: Colour) -> SenResult<Colour> {
match lch {
Colour::LCH(l, c, h, alpha) => {
let hrad = h * 0.017_453_292_519_943_295_77; /* (pi / 180.0) */
let u = hrad.cos() * c;
let v = hrad.sin() * c;

Ok(Colour::LUV(l, u, v, alpha))
}
_ => Err(SenError::IncorrectColourFormat),
}
}

fn lch_from_hsluv(hsluv: Colour) -> SenResult<Colour> {
match hsluv {
Colour::HSLuv(h, s, l, alpha) => {
let c = if l > 99.999_999_9 || l < 0.000_000_01 {
0.0
} else {
max_chroma_for_lh(l, h) / 100.0 * s
};

if s < 0.000_000_01 {
Ok(Colour::LCH(l, c, 0.0, alpha))
} else {
Ok(Colour::LCH(l, c, h, alpha))
}
}
_ => Err(SenError::IncorrectColourFormat),
}
}

fn hsluv_from_lch(lch: Colour) -> SenResult<Colour> {
match lch {
Colour::LCH(l, c, h, alpha) => {
let s = if l > 99.999_999_9 || l < 0.000_000_01 {
0.0
} else {
c / max_chroma_for_lh(l, h) * 100.0
};

if c < 0.000_000_01 {
Ok(Colour::HSLuv(0.0, s, l, alpha))
} else {
Ok(Colour::HSLuv(h, s, l, alpha))
}
}
_ => Err(SenError::IncorrectColourFormat),
}
}

fn xyz_from_hsluv(hsluv: Colour) -> SenResult<Colour> {
xyz_from_luv(luv_from_lch(lch_from_hsluv(hsluv)?)?)
}

fn hsluv_from_xyz(xyz: Colour) -> SenResult<Colour> {
hsluv_from_lch(lch_from_luv(luv_from_xyz(xyz)?)?)
}

#[cfg(test)]
mod tests {

use super::*;

const TOLERANCE: f64 = 0.02;

fn f64_within(tolerance: f64, a: f64, b: f64, msg: &'static str) {
assert!(
(a - b).abs() < tolerance,
format!("{} expected: {}, actual: {}", msg, b, a)
)
}

fn is_format(expected: Format, actual: Format) {
assert!(
expected == actual,
format!("expected: {:?}, actual: {:?}", expected, actual)
)
}

fn assert_col(col: Colour, format: Format, c0: f64, c1: f64, c2: f64, c3: f64) {
match col {
Colour::HSL(h, s, l, alpha) => {
is_format(format, Format::HSL);
f64_within(TOLERANCE, h, c0, "HSL H");
f64_within(TOLERANCE, s, c1, "HSL_S");
f64_within(TOLERANCE, l, c2, "HSL_L");
f64_within(TOLERANCE, alpha, c3, "HSL_alpha");
}
Colour::HSLuv(h, s, l, alpha) => {
is_format(format, Format::HSLuv);
f64_within(TOLERANCE, h, c0, "HSLuv H");
f64_within(TOLERANCE, s, c1, "HSLuv_S");
f64_within(TOLERANCE, l, c2, "HSLuv_L");
f64_within(TOLERANCE, alpha, c3, "HSLuv_alpha");
}
Colour::HSV(h, s, v, alpha) => {
is_format(format, Format::HSV);
f64_within(TOLERANCE, h, c0, "HSV H");
f64_within(TOLERANCE, s, c1, "HSV_S");
f64_within(TOLERANCE, v, c2, "HSV_V");
f64_within(TOLERANCE, alpha, c3, "HSV_alpha");
}
Colour::LAB(l, a, b, alpha) => {
is_format(format, Format::LAB);
f64_within(TOLERANCE, l, c0, "LAB_L");
f64_within(TOLERANCE, a, c1, "LAB_A");
f64_within(TOLERANCE, b, c2, "LAB_B");
f64_within(TOLERANCE, alpha, c3, "LAB_alpha");
}
Colour::RGB(r, g, b, alpha) => {
is_format(format, Format::RGB);
f64_within(TOLERANCE, r, c0, "RGB R");
f64_within(TOLERANCE, g, c1, "RGB_G");
f64_within(TOLERANCE, b, c2, "RGB_B");
f64_within(TOLERANCE, alpha, c3, "RGB_alpha");
}
_ => assert_eq!(true, false),
}
}

fn assert_colour_match(expected: Colour, col: Colour) {
match expected {
Colour::HSL(h, s, l, alpha) => assert_col(col, Format::HSL, h, s, l, alpha),
Colour::HSLuv(h, s, l, alpha) => assert_col(col, Format::HSLuv, h, s, l, alpha),
Colour::HSV(h, s, v, alpha) => assert_col(col, Format::HSV, h, s, v, alpha),
Colour::LAB(l, a, b, alpha) => assert_col(col, Format::LAB, l, a, b, alpha),
Colour::RGB(r, g, b, alpha) => assert_col(col, Format::RGB, r, g, b, alpha),
_ => assert_eq!(true, false),
}
}

fn assert_colour_rgb_hsl_match(r: f64, g: f64, b: f64, h: f64, s: f64, l: f64) {
let rgb = Colour::RGB(r, g, b, 1.0);
let hsl = Colour::HSL(h, s, l, 1.0);

assert_colour_match(rgb, hsl.clone_as(Format::RGB).unwrap());
assert_colour_match(hsl, rgb.clone_as(Format::HSL).unwrap());
}

#[test]
fn test_colour() {
let rgb = Colour::RGB(0.2, 0.09803921568627451, 0.49019607843137253, 1.0);
let hsl = Colour::HSL(255.6, 0.6666, 0.294, 1.0);
let lab = Colour::LAB(
19.555676428108306,
39.130689315704764,
-51.76254071703564,
1.0,
);

assert_colour_match(rgb, rgb.clone_as(Format::RGB).unwrap());
assert_colour_match(rgb, hsl.clone_as(Format::RGB).unwrap());
assert_colour_match(rgb, lab.clone_as(Format::RGB).unwrap());

assert_colour_match(hsl, rgb.clone_as(Format::HSL).unwrap());
assert_colour_match(hsl, hsl.clone_as(Format::HSL).unwrap());
assert_colour_match(hsl, lab.clone_as(Format::HSL).unwrap());

assert_colour_match(lab, rgb.clone_as(Format::LAB).unwrap());
assert_colour_match(lab, hsl.clone_as(Format::LAB).unwrap());
assert_colour_match(lab, lab.clone_as(Format::LAB).unwrap());
}

#[test]
fn test_colour_2() {
let rgb = Colour::RGB(0.066666, 0.8, 0.86666666, 1.0);
let hsluv = Colour::HSLuv(205.7022764106217, 98.91247496876854, 75.15356872935901, 1.0);

assert_colour_match(rgb, hsluv.clone_as(Format::RGB).unwrap());
assert_colour_match(hsluv, rgb.clone_as(Format::HSLuv).unwrap());
}

#[test]
fn test_colour_3() {
assert_colour_rgb_hsl_match(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
assert_colour_rgb_hsl_match(1.0, 1.0, 1.0, 0.0, 0.0, 1.0);
assert_colour_rgb_hsl_match(1.0, 0.0, 0.0, 0.0, 1.0, 0.5);
assert_colour_rgb_hsl_match(0.0, 1.0, 0.0, 120.0, 1.0, 0.5);
assert_colour_rgb_hsl_match(0.0, 0.0, 1.0, 240.0, 1.0, 0.5);
assert_colour_rgb_hsl_match(1.0, 1.0, 0.0, 60.0, 1.0, 0.5);
assert_colour_rgb_hsl_match(0.0, 1.0, 1.0, 180.0, 1.0, 0.5);
assert_colour_rgb_hsl_match(1.0, 0.0, 1.0, 300.0, 1.0, 0.5);
assert_colour_rgb_hsl_match(0.7529, 0.7529, 0.7529, 0.0, 0.0, 0.75);
assert_colour_rgb_hsl_match(0.5, 0.5, 0.5, 0.0, 0.0, 0.5);
assert_colour_rgb_hsl_match(0.5, 0.0, 0.0, 0.0, 1.0, 0.25);
assert_colour_rgb_hsl_match(0.5, 0.5, 0.0, 60.0, 1.0, 0.25);
assert_colour_rgb_hsl_match(0.0, 0.5, 0.0, 120.0, 1.0, 0.25);
assert_colour_rgb_hsl_match(0.5, 0.0, 0.5, 300.0, 1.0, 0.25);
assert_colour_rgb_hsl_match(0.0, 0.5, 0.5, 180.0, 1.0, 0.25);
assert_colour_rgb_hsl_match(0.0, 0.0, 0.5, 240.0, 1.0, 0.25);
}
}

+ 39
- 0
src/error.rs View File

@@ -0,0 +1,39 @@
// Copyright (C) 2018 Inderjit Gill

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

pub type SenResult<T> = ::std::result::Result<T, SenError>;

#[derive(Debug)]
pub enum SenError {
GeneralError,

// colour
//
IncorrectColourFormat,
InvalidColourHue,
InvalidColourChannel,

// parser
ParserInvalidChar(char),
ParserInvalidLiteral,
ParserUnableToParseFloat(String),
ParserHandledToken,


// MemorySegmentType
MemorySegmentTypeUnmappableBytecodeArg,
MemorySegmentTypeUnmappableI32,

}

+ 47
- 3
src/lib.rs View File

@@ -1,10 +1,54 @@
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
// Copyright (C) 2018 Inderjit Gill

extern crate sen_colour;
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#![allow(dead_code)]
#![cfg_attr(feature = "cargo-clippy", allow(many_single_char_names, too_many_arguments))]

extern crate cfg_if;
extern crate wasm_bindgen;

use sen_colour::{Colour, Format};
mod error;
mod utils;
mod colour;

use cfg_if::cfg_if;
use wasm_bindgen::prelude::*;
use crate::colour::{Colour, Format};

cfg_if! {
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
// allocator.
if #[cfg(feature = "wee_alloc")] {
extern crate wee_alloc;
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
}
}

#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_namespace = console)]
fn log(s: &str);
}

#[wasm_bindgen]
pub fn say_hi() {
log("hello from wasm world!!!");
}




#[wasm_bindgen]
pub struct Transport3C {

+ 32
- 0
src/utils.rs View File

@@ -0,0 +1,32 @@
// Copyright (C) 2018 Inderjit Gill

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use cfg_if::cfg_if;

cfg_if! {
// When the `console_error_panic_hook` feature is enabled, we can call the
// `set_panic_hook` function at least once during initialization, and then
// we will get better error messages if our code ever panics.
//
// For more details see
// https://github.com/rustwasm/console_error_panic_hook#readme
if #[cfg(feature = "console_error_panic_hook")] {
extern crate console_error_panic_hook;
pub use self::console_error_panic_hook::set_once as set_panic_hook;
} else {
#[inline]
pub fn set_panic_hook() {}
}
}

+ 0
- 10
webpack.config.js View File

@@ -1,10 +0,0 @@
const path = require("path");

module.exports = {
entry: "./bootstrap.js",
output: {
path: path.resolve(__dirname, "dist"),
filename: "bootstrap.js",
},
mode: "development"
};

+ 2
- 0
www/.gitignore View File

@@ -0,0 +1,2 @@
themacs.js
themacs_bg.wasm

css/base-min.css → www/css/base-min.css View File


css/pure-min.css → www/css/pure-min.css View File


css/stylesheet.css → www/css/stylesheet.css View File


favicon.ico → www/favicon.ico View File


index.html → www/index.html View File

@@ -856,6 +856,22 @@
</div>
</div>

<script src='./bootstrap.js'></script>
<script>
// The `--no-modules`-generated JS from `wasm-bindgen` attempts to use
// `WebAssembly.instantiateStreaming` to instantiate the wasm module,
// but this doesn't work with `file://` urls. This example is frequently
// viewed by simply opening `index.html` in a browser (with a `file://`
// url), so it would fail if we were to call this function!
//
// Work around this for now by deleting the function to ensure that the
// `no_modules.js` script doesn't have access to it. You won't need this
// hack when deploying over HTTP.
delete WebAssembly.instantiateStreaming;
</script>

<!-- this is the JS generated by the `wasm-bindgen` CLI tool -->
<script src='./themacs.js'></script>

<script src='index.js'></script>
</body>
</html>

index.js → www/index.js View File

@@ -5,11 +5,9 @@
// programming language saturation (i.e. builtin saturation)
// clock12 hue
// clock12 saturation
import { Transport3C,
hsl_from_rgb,
rgb_from_hsl
} from "./wasm_themacs";

const { Transport3C,
hsl_from_rgb,
rgb_from_hsl } = wasm_bindgen;

let colourTable = undefined;

@@ -868,7 +866,6 @@ function pointerToFloat32Array(mem, ptr, length) {
}

function init() {
console.log('init');
colourTable = document.querySelector("#colour-table");

initModel(model);
@@ -876,7 +873,7 @@ function init() {
colourTable.onchange = changeEventHandler;

// request MIDI access
if (navigator.requestMIDIAccess) {
if (false && navigator.requestMIDIAccess) {
navigator.requestMIDIAccess({
sysex: false
}).then(onMIDISuccess(ui), onMIDIFailure);
@@ -885,4 +882,10 @@ function init() {
}
}

init();
document.addEventListener('DOMContentLoaded', () => {
wasm_bindgen('./themacs_bg.wasm')
.then(() => {
init();
})
.catch(console.error);
});

Loading…
Cancel
Save