Compare commits

...

124 Commits

Author SHA1 Message Date
b6f69c57cf moar stuff 2019-02-07 17:35:48 +00:00
9e19c36b42 Add Xargo and config and stuff 2019-02-07 00:29:11 +00:00
cf45520be3 Cleanup and add pkg 2019-02-06 10:25:56 +00:00
8faf8a5b48 First attempt at Oxipng 2019-02-05 19:40:22 +00:00
cb16fb5437 Update libwebp to 1.0.2 (#439)
* Update package.json

* Update package.json

* Update README.md

* Update README.md

* Use cmake for libwebp

* Minimize libwebp
2019-02-05 15:45:03 +00:00
36f5fa2c47 Merge pull request #449 from GoogleChromeLabs/renovate/webpack-cli-3.x
Update dependency webpack-cli to v3.2.3
2019-02-05 10:20:37 +00:00
51ad22e72c Update dependency webpack-cli to v3.2.3 2019-02-05 03:22:41 +00:00
1a355c0c16 Merge pull request #448 from GoogleChromeLabs/renovate/terser-webpack-plugin-1.x
Update dependency terser-webpack-plugin to v1.2.2
2019-02-04 15:39:59 +00:00
fe5ba08963 Update dependency terser-webpack-plugin to v1.2.2 2019-02-04 14:46:39 +00:00
7fc994d4af This fixes #446 and sometimes it's best not to ask too many questions. (#447) 2019-02-04 13:34:56 +00:00
a0a8285e02 Merge pull request #445 from GoogleChromeLabs/renovate/node-10.x
Update dependency @types/node to v10.12.21
2019-02-01 10:08:47 +00:00
da2e35f613 Update dependency @types/node to v10.12.21 2019-02-01 05:41:46 +00:00
09bdc25352 Merge pull request #443 from GoogleChromeLabs/renovate/node-10.x
Update dependency @types/node to v10.12.20
2019-01-31 10:44:30 +00:00
ad263a9c36 Update dependency @types/node to v10.12.20 2019-01-30 23:41:51 +00:00
c8d8d4e43d Merge pull request #442 from GoogleChromeLabs/renovate/progress-bar-webpack-plugin-1.x
Update dependency progress-bar-webpack-plugin to v1.12.1
2019-01-29 18:11:12 +00:00
94249b8a93 Update dependency progress-bar-webpack-plugin to v1.12.1 2019-01-29 15:49:49 +00:00
edd2c51eb6 Merge pull request #441 from GoogleChromeLabs/renovate/node-10.x
Update dependency @types/node to v10.12.19
2019-01-29 10:08:35 +00:00
1d24e9399f Update dependency @types/node to v10.12.19 2019-01-29 00:45:56 +00:00
3a0062276d Merge pull request #436 from GoogleChromeLabs/optimize-rotate
Optimize rotate
2019-01-23 22:45:10 -05:00
1993cf3f6c Remove unused bpp 2019-01-23 14:15:39 -05:00
c97aac31c6 Revert "Add rotate user timing"
This reverts commit 887db675c8.
2019-01-23 14:06:24 -05:00
507921cbe8 Use Uint32Array to copy an entire pixel per op 2019-01-23 10:17:52 -05:00
887db675c8 Add rotate user timing 2019-01-23 10:11:35 -05:00
3917618e4e Merge pull request #435 from GoogleChromeLabs/renovate/progress-bar-webpack-plugin-1.x
Update dependency progress-bar-webpack-plugin to v1.12.0
2019-01-22 13:36:30 -05:00
3c42d2e6a4 Update dependency progress-bar-webpack-plugin to v1.12.0 2019-01-22 18:01:07 +00:00
db8777b7f7 Merge pull request #434 from GoogleChromeLabs/renovate/clean-webpack-plugin-1.x
Update dependency clean-webpack-plugin to v1.0.1
2019-01-22 09:04:33 -05:00
18c2cddee2 Update dependency clean-webpack-plugin to v1.0.1 2019-01-22 05:14:58 +00:00
3ff9d3a1fa Merge pull request #432 from GoogleChromeLabs/renovate/critters-webpack-plugin-2.x
Update dependency critters-webpack-plugin to v2.2.0
2019-01-18 14:21:42 -05:00
6503667c78 Update dependency critters-webpack-plugin to v2.2.0 2019-01-18 16:46:25 +00:00
0fa95f84d4 Merge pull request #431 from GoogleChromeLabs/renovate/typescript-3.x
Update dependency typescript to v3.2.4
2019-01-17 19:45:53 -05:00
cf91a90270 Update dependency typescript to v3.2.4 2019-01-17 22:56:11 +00:00
690052f989 Merge pull request #427 from GoogleChromeLabs/renovate/tslint-5.x
Update dependency tslint to v5.12.1
2019-01-10 23:06:29 +00:00
b3e935f7e4 Update dependency tslint to v5.12.1 2019-01-10 22:41:01 +00:00
17314ebd29 Merge pull request #424 from GoogleChromeLabs/renovate/webpack-cli-3.x
Update dependency webpack-cli to v3.2.1
2019-01-10 17:10:54 +00:00
adc437cd51 Update dependency webpack-cli to v3.2.1 2019-01-07 10:23:37 +00:00
0e97b74510 Merge pull request #422 from GoogleChromeLabs/renovate/critters-webpack-plugin-2.x
Update dependency critters-webpack-plugin to v2.1.3
2019-01-07 11:21:36 +01:00
9ffb475cac Update dependency critters-webpack-plugin to v2.1.3 2019-01-05 20:00:02 +00:00
faa2b030c5 Merge pull request #423 from GoogleChromeLabs/renovate/ts-loader-5.x
Update dependency ts-loader to v5.3.3
2019-01-05 19:59:13 +00:00
e3b3b10e2a Update dependency ts-loader to v5.3.3 2019-01-05 19:19:18 +00:00
b569cf268c Merge pull request #415 from GoogleChromeLabs/renovate/critters-webpack-plugin-2.x
Update dependency critters-webpack-plugin to v2.1.2
2019-01-03 19:34:04 +00:00
b154b77556 Update dependency critters-webpack-plugin to v2.1.2 2019-01-03 19:24:19 +00:00
84c0f30a7c Merge pull request #420 from GoogleChromeLabs/renovate/webpack-cli-serve-0.x
Update dependency @webpack-cli/serve to v0.1.3
2019-01-03 19:23:19 +00:00
16463ff76d Update dependency @webpack-cli/serve to v0.1.3 2019-01-03 19:10:09 +00:00
8314e9e24b Merge pull request #421 from GoogleChromeLabs/renovate/webpack-cli-3.x
Update dependency webpack-cli to v3.2.0
2019-01-03 19:08:32 +00:00
a33c557818 Update dependency webpack-cli to v3.2.0 2019-01-03 05:49:28 +00:00
6fbdc65ad0 Merge pull request #418 from GoogleChromeLabs/renovate/husky-1.x
Update dependency husky to v1.3.1
2018-12-28 10:05:10 -05:00
9c9b6c4711 Update dependency husky to v1.3.1 2018-12-28 06:24:00 +00:00
46278d04c3 Merge pull request #414 from GoogleChromeLabs/renovate/terser-webpack-plugin-1.x
Update dependency terser-webpack-plugin to v1.2.1
2018-12-27 07:41:51 -05:00
c1c16508b5 Update dependency terser-webpack-plugin to v1.2.1 2018-12-27 12:35:42 +00:00
ed1b983711 Merge pull request #412 from GoogleChromeLabs/renovate/loader-utils-1.x
Update dependency loader-utils to v1.2.0
2018-12-24 22:04:29 +00:00
ec23e28eda Update dependency loader-utils to v1.2.0 2018-12-24 18:49:01 +00:00
d48b49e8e4 Merge pull request #411 from GoogleChromeLabs/renovate/webpack-dev-server-3.x
Update dependency webpack-dev-server to v3.1.14
2018-12-24 18:48:10 +00:00
14308970c6 Update dependency webpack-dev-server to v3.1.14 2018-12-24 10:09:10 +00:00
38e86e1012 Merge pull request #410 from GoogleChromeLabs/renovate/webpack-dev-server-3.x
Update dependency webpack-dev-server to v3.1.13
2018-12-22 19:52:50 +00:00
e9a33af831 Update dependency webpack-dev-server to v3.1.13 2018-12-22 19:29:27 +00:00
6a63e5dbb2 Merge pull request #409 from GoogleChromeLabs/renovate/terser-webpack-plugin-1.x
Update dependency terser-webpack-plugin to v1.2.0
2018-12-22 16:48:48 +00:00
1e1892a3d5 Update dependency terser-webpack-plugin to v1.2.0 2018-12-22 16:16:11 +00:00
8bff9a2973 Merge pull request #408 from GoogleChromeLabs/renovate/webpack-dev-server-3.x
Update dependency webpack-dev-server to v3.1.12
2018-12-22 16:15:31 +00:00
cbe753dd29 Update dependency webpack-dev-server to v3.1.12 2018-12-22 15:09:41 +00:00
b047845b43 Merge pull request #407 from GoogleChromeLabs/renovate/webpack-dev-server-3.x
Update dependency webpack-dev-server to v3.1.11
2018-12-21 19:17:48 +00:00
1bebc75381 Update dependency webpack-dev-server to v3.1.11 2018-12-21 18:11:16 +00:00
93c46bfc8d Merge pull request #406 from GoogleChromeLabs/renovate/ts-loader-5.x
Update dependency ts-loader to v5.3.2
2018-12-21 10:46:22 +00:00
a3d0f5963e Update dependency ts-loader to v5.3.2 2018-12-21 06:30:17 +00:00
006b82bf05 Merge pull request #404 from GoogleChromeLabs/renovate/file-loader-3.x
Update dependency file-loader to v3
2018-12-20 20:06:12 +00:00
c36e37ac6b Update dependency file-loader to v3 2018-12-20 17:42:21 +00:00
3cf6d7385a Merge pull request #403 from GoogleChromeLabs/renovate/node-10.x
Update dependency @types/node to v10.12.18
2018-12-19 18:44:47 +00:00
9045b2fa97 Update dependency @types/node to v10.12.18 2018-12-19 18:26:21 +00:00
be6f3b9c6d Merge pull request #402 from GoogleChromeLabs/renovate/webpack-4.x
Update dependency webpack to v4.28.0
2018-12-19 13:00:37 +00:00
5a699b7ce9 Update dependency webpack to v4.28.0 2018-12-19 12:34:47 +00:00
f366a78e87 Merge pull request #400 from GoogleChromeLabs/renovate/node-10.x
Update dependency @types/node to v10.12.17
2018-12-18 22:32:16 +00:00
c63c7ead51 Update dependency @types/node to v10.12.17 2018-12-18 22:02:40 +00:00
ecfa5902cd Merge pull request #399 from GoogleChromeLabs/renovate/husky-1.x
Update dependency husky to v1.3.0
2018-12-18 20:06:49 +00:00
444027b496 Update dependency husky to v1.3.0 2018-12-18 19:56:39 +00:00
9c5dcb93c7 Merge pull request #398 from GoogleChromeLabs/renovate/tslint-5.x
Update dependency tslint to v5.12.0
2018-12-18 13:12:06 +00:00
9594221271 Update dependency tslint to v5.12.0 2018-12-18 11:48:40 +00:00
01823d3b75 1.3.1 2018-12-18 09:39:59 +00:00
db07a90139 Merge pull request #396 from GoogleChromeLabs/kosamari-patch-2
Update README.md for OptiPNG
2018-12-17 19:15:55 +00:00
962d0928d3 Update README.md
closes #367
updating incorrect URL
2018-12-17 13:43:18 -05:00
e67d50c8e6 Preventing zoom in iOS Safari. (#395) 2018-12-17 17:05:41 +00:00
f9b2f17852 Merge pull request #385 from GoogleChromeLabs/renovate/typescript-3.x
Update dependency typescript to v3.2.2
2018-12-17 12:42:47 +00:00
9746a9f5ed Fix typings for TypeScript v3.2 2018-12-17 12:36:57 +00:00
be0877ecb0 Update dependency typescript to v3.2.2 2018-12-17 12:36:52 +00:00
d2fcdfae43 Debouncing input. Fixes #277 (#394)
* Debouncing input

* Clarifying comment

* More comments and clarifications
2018-12-17 11:54:30 +00:00
2c9eb46941 Merge pull request #393 from GoogleChromeLabs/webp-sharp-fix
Fixing sharp & preprocess settings. Fixes #392.
2018-12-17 10:59:29 +00:00
d30a85fd48 Using use_argb conditionally 2018-12-17 10:21:30 +00:00
9260bed1b1 Fixing sharp & preprocess settings 2018-12-17 10:01:47 +00:00
f6d12985a9 Merge pull request #390 from GoogleChromeLabs/renovate/worker-plugin-3.x
Update dependency worker-plugin to v3
2018-12-14 18:55:31 +00:00
10c9b1db7c Update dependency worker-plugin to v3 2018-12-14 18:10:49 +00:00
4fb17be8de Merge pull request #388 from GoogleChromeLabs/renovate/raw-loader-1.x
Update dependency raw-loader to v1
2018-12-14 18:08:27 +00:00
b592b1a088 Update dependency raw-loader to v1 2018-12-14 15:47:28 +00:00
0544a6507e Merge pull request #386 from GoogleChromeLabs/renovate/webpack-4.x
Update dependency webpack to v4.27.1
2018-12-14 15:45:24 +00:00
1e20ff15ed Update dependency webpack to v4.27.1 2018-12-14 15:28:46 +00:00
04a0ec0645 Merge pull request #383 from GoogleChromeLabs/renovate/tslint-config-airbnb-5.x
Update dependency tslint-config-airbnb to v5.11.1
2018-12-14 15:01:37 +00:00
f355292fe3 Update dependency tslint-config-airbnb to v5.11.1 2018-12-14 13:48:22 +00:00
32e4d813de Merge pull request #382 from GoogleChromeLabs/renovate/ts-loader-5.x
Update dependency ts-loader to v5.3.1
2018-12-14 13:47:40 +00:00
f960f5ea87 Update dependency ts-loader to v5.3.1 2018-12-14 10:18:46 +00:00
aa6f83e2fa Merge pull request #381 from GoogleChromeLabs/renovate/preact-8.x
Update dependency preact to v8.4.2
2018-12-14 10:18:06 +00:00
c09e1f1895 Update dependency preact to v8.4.2 2018-12-14 10:08:17 +00:00
7c311928dd Merge pull request #379 from GoogleChromeLabs/renovate/husky-1.x
Update dependency husky to v1.2.1
2018-12-14 10:07:31 +00:00
5f1c8bcb6b Update dependency husky to v1.2.1 2018-12-14 09:35:57 +00:00
93bc20f014 Merge pull request #378 from GoogleChromeLabs/renovate/critters-webpack-plugin-2.x
Update dependency critters-webpack-plugin to v2.1.1
2018-12-14 09:35:06 +00:00
d29d9571c6 Update dependency critters-webpack-plugin to v2.1.1 2018-12-14 09:28:18 +00:00
3d47dfc820 Merge pull request #375 from GoogleChromeLabs/renovate/webassembly-js-api-0.x
Update dependency @types/webassembly-js-api to v0.0.2
2018-12-14 09:27:04 +00:00
d7846c9add Update dependency @types/webassembly-js-api to v0.0.2 2018-12-14 08:29:39 +00:00
4d6fe9d641 Merge pull request #377 from GoogleChromeLabs/renovate/comlink-3.x
Update dependency comlink to v3.1.1
2018-12-14 08:28:41 +00:00
205feba75d Update dependency comlink to v3.1.1 2018-12-14 00:59:15 +00:00
ca7663b94a Merge pull request #384 from GoogleChromeLabs/renovate/node-10.x
Update dependency @types/node to v10.12.15
2018-12-14 00:54:30 +00:00
83e45f054b Update dependency @types/node to v10.12.15 2018-12-13 22:44:08 +00:00
783e893a67 Merge pull request #376 from GoogleChromeLabs/renovate/node-10.x
Update dependency @types/node to v10.12.14
2018-12-13 19:09:00 +00:00
0a941866a9 Update dependency @types/node to v10.12.14 2018-12-13 19:03:04 +00:00
04edfe0085 Merge pull request #380 from GoogleChromeLabs/renovate/mini-css-extract-plugin-0.x
Update dependency mini-css-extract-plugin to v0.5.0
2018-12-13 19:02:16 +00:00
6cae634eca Update dependency mini-css-extract-plugin to v0.5.0 2018-12-13 18:53:39 +00:00
8c7bf278dc Merge pull request #374 from GoogleChromeLabs/renovate/pin-dependencies
Pin dependencies
2018-12-13 13:30:08 +00:00
f6106650b5 Pin dependencies 2018-12-13 13:20:33 +00:00
166e606034 Merge pull request #373 from GoogleChromeLabs/renovate/configure
Configure Renovate
2018-12-13 13:19:16 +00:00
c997e6a3e4 Add renovate.json 2018-12-13 13:13:44 +00:00
2a1b6dc9da 1.3.0 2018-12-12 12:59:05 +00:00
129c33fa12 Add basic history handling (#288) (#309)
* Add basic history handling (#288)

* Move history management to Compress component

* Remove unused pathname property from history

* Rename history listener functions

* Use history.back instead of history.replace

* Support going forward in history. Persist last selected file in runtime

* Add netlify redirects file

* Use 301 status code for redirect

* Cleanup _redirects file

* Use 200 status code for redirects

* Simplify onPopState function

* Always redirect to 301 with url rewrite

* Remove redundant history function

* Remove file check on render. Call openEditor synchronously

* Use pushState only if user is on the initial screen. Mount history listener in constructor

* Simplify openEditor condition

* Update early return condition

* Rolling abstractions back into the main component
2018-12-12 12:58:03 +00:00
3245987113 Prevent both sides sharing a download URL. (#369) 2018-12-12 12:51:06 +00:00
593ad62cbb 1.2.3 2018-12-10 12:25:27 +00:00
a625a76e9e Fixed blank text-fields with dark browser theme (#365)
When using dark browser themes the text-fields' text-color becomes white, so the text in those white background text-fields is unreadable.

Patched text-color so that it now is readable.
2018-12-10 12:24:12 +00:00
c2a305304b Rotation optimise. Fixes #362 (#363)
* Move early exit for no-rotation.

* lol this was meant to be 10 seconds.
2018-12-09 07:11:11 +00:00
7389c507fb 1.2.2 2018-12-04 10:57:07 +00:00
68f0f23016 Prevent image becoming misshapen on resize. Fixes #359. (#360) 2018-12-04 10:55:32 +00:00
65 changed files with 3327 additions and 596 deletions

2
_redirects.ejs Normal file
View File

@ -0,0 +1,2 @@
/index.html / 301
/* /index.html 301

View File

@ -8,6 +8,6 @@
"libimagequant": "ImageOptim/libimagequant#2.12.1"
},
"devDependencies": {
"napa": "^3.0.0"
"napa": "3.0.0"
}
}

View File

@ -8,6 +8,6 @@
"mozjpeg": "mozilla/mozjpeg#v3.3.1"
},
"devDependencies": {
"napa": "^3.0.0"
"napa": "3.0.0"
}
}

View File

@ -1,6 +1,6 @@
# OptiPNG
- Source: <https://sourceforge.net/project/optipng>
- Source: <http://optipng.sourceforge.net/>
- Version: v0.7.7
## Dependencies

View File

@ -16,7 +16,7 @@
"zlib": "emscripten-ports/zlib"
},
"dependencies": {
"napa": "^3.0.0",
"napa": "3.0.0",
"tar-dependency": "0.0.3"
}
}

0
codecs/oxipng/.cargo-ok Normal file
View File

5
codecs/oxipng/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
/target
**/*.rs.bk
Cargo.lock
bin/
wasm-pack.log

36
codecs/oxipng/Cargo.toml Normal file
View File

@ -0,0 +1,36 @@
[package]
name = "test"
version = "0.1.0"
authors = ["Surma <surma@surma.link>"]
[lib]
path = "lib.rs"
crate-type = ["cdylib", "rlib"]
[features]
default = ["console_error_panic_hook"]
[dependencies]
cfg-if = "0.1.2"
wasm-bindgen = "0.2"
oxipng = "2.2.0"
# 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]
# Tell `rustc` to optimize for small code size.
opt-level = "s"

52
codecs/oxipng/README.md Normal file
View File

@ -0,0 +1,52 @@
# 🦀🕸️ `wasm-pack-template`
A template for kick starting a Rust and WebAssembly project using
[`wasm-pack`](https://github.com/rustwasm/wasm-pack).
This template is designed for compiling Rust libraries into WebAssembly and
publishing the resulting package to NPM.
* Want to use the published NPM package in a Website? [Check out
`create-wasm-app`.](https://github.com/rustwasm/create-wasm-app)
* Want to make a monorepo-style Website without publishing to NPM? Check out
[`rust-webpack-template`](https://github.com/rustwasm/rust-webpack-template)
and/or
[`rust-parcel-template`](https://github.com/rustwasm/rust-parcel-template).
## 🔋 Batteries Included
* [`wasm-bindgen`](https://github.com/rustwasm/wasm-bindgen) for communicating
between WebAssembly and JavaScript.
* [`console_error_panic_hook`](https://github.com/rustwasm/console_error_panic_hook)
for logging panic messages to the developer console.
* [`wee_alloc`](https://github.com/rustwasm/wee_alloc), an allocator optimized
for small code size.
## 🚴 Usage
### 🐑 Use `cargo generate` to Clone this Template
[Learn more about `cargo generate` here.](https://github.com/ashleygwilliams/cargo-generate)
```
cargo generate --git https://github.com/rustwasm/wasm-pack-template.git --name my-project
cd my-project
```
### 🛠️ Build with `wasm-pack build`
```
wasm-pack build
```
### 🔬 Test in Headless Browsers with `wasm-pack test`
```
wasm-pack test --headless --firefox
```
### 🎁 Publish to NPM with `wasm-pack publish`
```
wasm-pack publish
```

5
codecs/oxipng/Xargo.toml Normal file
View File

@ -0,0 +1,5 @@
[target.wasm32-unknown-unknown.dependencies]
time = {}
[target.wasm32-unknown-unknown.dependencies.std]
features = ["wasm_syscall"]

View File

@ -0,0 +1,52 @@
# 🦀🕸️ `wasm-pack-template`
A template for kick starting a Rust and WebAssembly project using
[`wasm-pack`](https://github.com/rustwasm/wasm-pack).
This template is designed for compiling Rust libraries into WebAssembly and
publishing the resulting package to NPM.
* Want to use the published NPM package in a Website? [Check out
`create-wasm-app`.](https://github.com/rustwasm/create-wasm-app)
* Want to make a monorepo-style Website without publishing to NPM? Check out
[`rust-webpack-template`](https://github.com/rustwasm/rust-webpack-template)
and/or
[`rust-parcel-template`](https://github.com/rustwasm/rust-parcel-template).
## 🔋 Batteries Included
* [`wasm-bindgen`](https://github.com/rustwasm/wasm-bindgen) for communicating
between WebAssembly and JavaScript.
* [`console_error_panic_hook`](https://github.com/rustwasm/console_error_panic_hook)
for logging panic messages to the developer console.
* [`wee_alloc`](https://github.com/rustwasm/wee_alloc), an allocator optimized
for small code size.
## 🚴 Usage
### 🐑 Use `cargo generate` to Clone this Template
[Learn more about `cargo generate` here.](https://github.com/ashleygwilliams/cargo-generate)
```
cargo generate --git https://github.com/rustwasm/wasm-pack-template.git --name my-project
cd my-project
```
### 🛠️ Build with `wasm-pack build`
```
wasm-pack build
```
### 🔬 Test in Headless Browsers with `wasm-pack test`
```
wasm-pack test --headless --firefox
```
### 🎁 Publish to NPM with `wasm-pack publish`
```
wasm-pack publish
```

BIN
codecs/oxipng/pkg/img.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

14
codecs/oxipng/pkg/lol.js Normal file
View File

@ -0,0 +1,14 @@
const oxipng = require("./oxipng_wasm");
const repl = require("repl");
const fs = require("fs");
async function init() {
// const img = fs.readFileSync("img.png")
// const output = oxipng.compress(img, 0);
// fs.writeFileSync("output.png", output);
console.log(">>>", oxipng.doit());
const r = repl.start("node> ");
r.context.i = oxipng;
}
init();

3
codecs/oxipng/pkg/oxipng.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
/* tslint:disable */
export function compress(arg0: Uint8Array, arg1: number): Uint8Array;

View File

@ -0,0 +1,73 @@
/* tslint:disable */
var wasm;
const TextDecoder = require('util').TextDecoder;
let cachedTextDecoder = new TextDecoder('utf-8');
let cachegetUint8Memory = null;
function getUint8Memory() {
if (cachegetUint8Memory === null || cachegetUint8Memory.buffer !== wasm.memory.buffer) {
cachegetUint8Memory = new Uint8Array(wasm.memory.buffer);
}
return cachegetUint8Memory;
}
function getStringFromWasm(ptr, len) {
return cachedTextDecoder.decode(getUint8Memory().subarray(ptr, ptr + len));
}
module.exports.__wbg_log_64e6f53d8e6d5db5 = function(arg0, arg1) {
let varg0 = getStringFromWasm(arg0, arg1);
console.log(varg0);
};
let WASM_VECTOR_LEN = 0;
function passArray8ToWasm(arg) {
const ptr = wasm.__wbindgen_malloc(arg.length * 1);
getUint8Memory().set(arg, ptr / 1);
WASM_VECTOR_LEN = arg.length;
return ptr;
}
function getArrayU8FromWasm(ptr, len) {
return getUint8Memory().subarray(ptr / 1, ptr / 1 + len);
}
let cachedGlobalArgumentPtr = null;
function globalArgumentPtr() {
if (cachedGlobalArgumentPtr === null) {
cachedGlobalArgumentPtr = wasm.__wbindgen_global_argument_ptr();
}
return cachedGlobalArgumentPtr;
}
let cachegetUint32Memory = null;
function getUint32Memory() {
if (cachegetUint32Memory === null || cachegetUint32Memory.buffer !== wasm.memory.buffer) {
cachegetUint32Memory = new Uint32Array(wasm.memory.buffer);
}
return cachegetUint32Memory;
}
/**
* @param {Uint8Array} arg0
* @param {number} arg1
* @returns {Uint8Array}
*/
module.exports.compress = function(arg0, arg1) {
const ptr0 = passArray8ToWasm(arg0);
const len0 = WASM_VECTOR_LEN;
const retptr = globalArgumentPtr();
wasm.compress(retptr, ptr0, len0, arg1);
const mem = getUint32Memory();
const rustptr = mem[retptr / 4];
const rustlen = mem[retptr / 4 + 1];
const realRet = getArrayU8FromWasm(rustptr, rustlen).slice();
wasm.__wbindgen_free(rustptr, rustlen * 1);
return realRet;
};
wasm = require('./oxipng_bg');

6
codecs/oxipng/pkg/oxipng_bg.d.ts vendored Normal file
View File

@ -0,0 +1,6 @@
/* tslint:disable */
export const memory: WebAssembly.Memory;
export function __wbindgen_global_argument_ptr(): number;
export function compress(a: number, b: number, c: number, d: number): void;
export function __wbindgen_malloc(a: number): number;
export function __wbindgen_free(a: number, b: number): void;

View File

@ -0,0 +1,9 @@
const path = require('path').join(__dirname, 'oxipng_bg.wasm');
const bytes = require('fs').readFileSync(path);
let imports = {};
imports['./oxipng'] = require('./oxipng');
const wasmModule = new WebAssembly.Module(bytes);
const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
module.exports = wasmInstance.exports;

Binary file not shown.

3
codecs/oxipng/pkg/oxipng_manual.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
/* tslint:disable */
export function compress(arg0: Uint8Array, arg1: number): Promise<Uint8Array>;

View File

@ -0,0 +1,77 @@
/* tslint:disable */
import wasmUrl from './oxipng_bg.wasm';
let wasm;
const instancePromise = WebAssembly.instantiateStreaming(fetch(wasmUrl), {
"./oxipng": {__wbg_log_64e6f53d8e6d5db5}
});
let cachedTextDecoder = new TextDecoder('utf-8');
let cachegetUint8Memory = null;
function getUint8Memory() {
if (cachegetUint8Memory === null || cachegetUint8Memory.buffer !== wasm.memory.buffer) {
cachegetUint8Memory = new Uint8Array(wasm.memory.buffer);
}
return cachegetUint8Memory;
}
function getStringFromWasm(ptr, len) {
return cachedTextDecoder.decode(getUint8Memory().subarray(ptr, ptr + len));
}
export function __wbg_log_64e6f53d8e6d5db5(arg0, arg1) {
let varg0 = getStringFromWasm(arg0, arg1);
console.log(varg0);
}
let WASM_VECTOR_LEN = 0;
function passArray8ToWasm(arg) {
const ptr = wasm.__wbindgen_malloc(arg.length * 1);
getUint8Memory().set(arg, ptr / 1);
WASM_VECTOR_LEN = arg.length;
return ptr;
}
function getArrayU8FromWasm(ptr, len) {
return getUint8Memory().subarray(ptr / 1, ptr / 1 + len);
}
let cachedGlobalArgumentPtr = null;
function globalArgumentPtr() {
if (cachedGlobalArgumentPtr === null) {
cachedGlobalArgumentPtr = wasm.__wbindgen_global_argument_ptr();
}
return cachedGlobalArgumentPtr;
}
let cachegetUint32Memory = null;
function getUint32Memory() {
if (cachegetUint32Memory === null || cachegetUint32Memory.buffer !== wasm.memory.buffer) {
cachegetUint32Memory = new Uint32Array(wasm.memory.buffer);
}
return cachegetUint32Memory;
}
/**
* @param {Uint8Array} arg0
* @param {number} arg1
* @returns {Uint8Array}
*/
export async function compress(arg0, arg1) {
wasm = (await instancePromise).instance.exports;
debugger;
const ptr0 = passArray8ToWasm(arg0);
const len0 = WASM_VECTOR_LEN;
const retptr = globalArgumentPtr();
wasm.compress(retptr, ptr0, len0, arg1);
const mem = getUint32Memory();
const rustptr = mem[retptr / 4];
const rustlen = mem[retptr / 4 + 1];
const realRet = getArrayU8FromWasm(rustptr, rustlen).slice();
wasm.__wbindgen_free(rustptr, rustlen * 1);
return realRet;
}

3
codecs/oxipng/pkg/oxipng_wasm.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
/* tslint:disable */
export function doit(): number;

View File

@ -0,0 +1,11 @@
/* tslint:disable */
var wasm;
/**
* @returns {number}
*/
module.exports.doit = function() {
return wasm.doit();
};
wasm = require('./oxipng_wasm_bg');

3
codecs/oxipng/pkg/oxipng_wasm_bg.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
/* tslint:disable */
export const memory: WebAssembly.Memory;
export function doit(): number;

View File

@ -0,0 +1,8 @@
const path = require('path').join(__dirname, 'oxipng_wasm_bg.wasm');
const bytes = require('fs').readFileSync(path);
let imports = {};
const wasmModule = new WebAssembly.Module(bytes);
const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
module.exports = wasmInstance.exports;

Binary file not shown.

View File

@ -0,0 +1,15 @@
{
"name": "oxipng-wasm",
"collaborators": [
"Surma <surma@surma.link>"
],
"version": "0.1.0",
"files": [
"oxipng_wasm_bg.wasm",
"oxipng_wasm.js",
"oxipng_wasm_bg.js",
"oxipng_wasm.d.ts"
],
"main": "oxipng_wasm.js",
"types": "oxipng_wasm.d.ts"
}

View File

42
codecs/oxipng/src/lib.rs Normal file
View File

@ -0,0 +1,42 @@
extern crate cfg_if;
extern crate wasm_bindgen;
// extern crate oxipng;
mod utils;
use cfg_if::cfg_if;
use wasm_bindgen::prelude::*;
use std::time::{Instant};
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 {
// #[wasm_bindgen(js_namespace = console)]
// fn log(s: &str);
// }
// #[wasm_bindgen]
// pub fn compress(img: Vec<u8>, level: u8) -> Vec<u8> {
// log(&format!("len: {}, level: {}", img.len(), level));
// let mut options = oxipng::Options::from_preset(level);
// options.threads = 0;
// let result = oxipng::optimize_from_memory(img.as_slice(), &options);
// match result {
// Ok(v) => v,
// Err(e) => e.to_string().as_bytes().to_vec()
// }
// }
#[wasm_bindgen]
pub fn doit() -> u32 {
let start = Instant::now();
start.elapsed().as_secs() as u32
}

View File

@ -0,0 +1,17 @@
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() {}
}
}

1
codecs/oxipng/tmp/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
target

View File

@ -0,0 +1,27 @@
[package]
name = "loltest"
version = "0.1.0"
authors = ["Surma <surma@surma.link>"]
[lib]
path = "lib.rs"
crate-type = ["cdylib", "rlib"]
[features]
default = ["console_error_panic_hook"]
[dependencies]
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 }
[dev-dependencies]
wasm-bindgen-test = "0.2"
[profile.release]
# Tell `rustc` to optimize for small code size.
opt-level = "s"

View File

@ -0,0 +1,2 @@
[dependencies.std]
features = ["wasm_syscall"]

View File

@ -0,0 +1,20 @@
Im trying to activate [the `wasm_syscall` feature][1] in Rusts stdlib for WebAssembly.
Here is my `Cargo.toml` and my `Xargo.toml`. But even with this setup the generated wasm file is still hard-coded to panic.
**HELP?**
My current command to compile is:
```
xargo build --target wasm32-unknown-unknown --release
```
If you have [`wasm2wat`][2] installed, you can verify the generate code via
```
wasm2wat target/wasm32-unknown-unknown/release/loltest.wasm | grep -A5 perform::
```
[1]: https://github.com/rust-lang/rust/blob/b139669f374eb5024a50eb13f116ff763b1c5935/src/libstd/sys/wasm/mod.rs#L309
[2]: https://github.com/WebAssembly/wabt

14
codecs/oxipng/tmp/lib.rs Normal file
View File

@ -0,0 +1,14 @@
extern crate wasm_bindgen;
use wasm_bindgen::prelude::*;
use std::thread::spawn;
#[wasm_bindgen]
pub fn doit() {
// let child = spawn(move || -> u32 {
// 5
// });
// let result = child.join().unwrap();
let result = spawn();
println!("Result: {}", result);
}

47
codecs/oxipng/tmp/lol.js Normal file
View File

@ -0,0 +1,47 @@
// const oxipng = require("./oxipng_wasm");
const repl = require("repl");
const fs = require("fs");
const dec = new TextDecoder();
let buffer = '';
async function init() {
const { instance } = await WebAssembly.instantiate(
fs.readFileSync("./target/wasm32-unknown-unknown/release/loltest.wasm"),
{
__wbindgen_placeholder__: {
__wbindgen_describe(v) {
console.log(`__wbindgen_desribe(${v})`);
}
},
env: {
// See https://github.com/rust-lang/rust/blob/master/src/libstd/sys/wasm/mod.rs
rust_wasm_syscall(syscall, ptr) {
switch(syscall) {
case 1: // Write
const [fd, dataPtr, len] = new Uint32Array(instance.exports.memory.buffer, ptr, 3 * 4);
const fragment = new Uint8Array(instance.exports.memory.buffer, dataPtr, len);
buffer += dec.decode(fragment);
const idx = buffer.indexOf('\n');
if(idx !== -1) {
console.log(buffer.slice(0, idx));
buffer = buffer.slice(idx);
}
return 1;
case 6: // Time
return 1;
default:
return 0; // False, unimplemented
}
}
}
}
);
try {
instance.exports.doit();
} catch{}
const r = repl.start("node> ");
r.context.i = instance;
}
init();

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
# WebP decoder
- Source: <https://github.com/webmproject/libwebp>
- Version: v0.6.1
- Version: v1.0.2
## Example

View File

@ -6,7 +6,33 @@ export OPTIMIZE="-Os"
export LDFLAGS="${OPTIMIZE}"
export CFLAGS="${OPTIMIZE}"
export CPPFLAGS="${OPTIMIZE}"
apt-get update
apt-get install -qqy autoconf libtool libpng-dev pkg-config
echo "============================================="
echo "Compiling libwebp"
echo "============================================="
test -n "$SKIP_LIBWEBP" || (
cd node_modules/libwebp
autoreconf -fiv
rm -rf build || true
mkdir -p build && cd build
emconfigure ../configure \
--disable-libwebpdemux \
--disable-wic \
--disable-gif \
--disable-tiff \
--disable-jpeg \
--disable-png \
--disable-sdl \
--disable-gl \
--disable-threading \
--disable-neon-rtcd \
--disable-neon \
--disable-sse2 \
--disable-sse4.1
emmake make
)
echo "============================================="
echo "Compiling wasm bindings"
echo "============================================="
@ -20,9 +46,9 @@ echo "============================================="
--std=c++11 \
-I node_modules/libwebp \
-o ./webp_dec.js \
node_modules/libwebp/src/{dec,dsp,demux,enc,mux,utils}/*.c \
-x c++ \
webp_dec.cpp
webp_dec.cpp \
node_modules/libwebp/build/src/.libs/libwebp.a
)
echo "============================================="
echo "Compiling wasm bindings done"

View File

@ -5,9 +5,9 @@
"build": "docker run --rm -v $(pwd):/src trzeci/emscripten ./build.sh"
},
"napa": {
"libwebp": "webmproject/libwebp#v1.0.0"
"libwebp": "webmproject/libwebp#v1.0.2"
},
"devDependencies": {
"napa": "^3.0.0"
"napa": "3.0.0"
}
}

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -1,7 +1,7 @@
# WebP encoder
- Source: <https://github.com/webmproject/libwebp>
- Version: v0.6.1
- Version: v1.0.2
## Dependencies

View File

@ -7,6 +7,33 @@ export LDFLAGS="${OPTIMIZE}"
export CFLAGS="${OPTIMIZE}"
export CPPFLAGS="${OPTIMIZE}"
apt-get update
apt-get install -qqy autoconf libtool libpng-dev pkg-config
echo "============================================="
echo "Compiling libwebp"
echo "============================================="
test -n "$SKIP_LIBWEBP" || (
cd node_modules/libwebp
autoreconf -fiv
rm -rf build || true
mkdir -p build && cd build
emconfigure ../configure \
--disable-libwebpdemux \
--disable-wic \
--disable-gif \
--disable-tiff \
--disable-jpeg \
--disable-png \
--disable-sdl \
--disable-gl \
--disable-threading \
--disable-neon-rtcd \
--disable-neon \
--disable-sse2 \
--disable-sse4.1
emmake make
)
echo "============================================="
echo "Compiling wasm bindings"
echo "============================================="
@ -20,9 +47,9 @@ echo "============================================="
--std=c++11 \
-I node_modules/libwebp \
-o ./webp_enc.js \
node_modules/libwebp/src/{dec,dsp,demux,enc,mux,utils}/*.c \
-x c++ \
webp_enc.cpp
webp_enc.cpp \
node_modules/libwebp/build/src/.libs/libwebp.a
)
echo "============================================="
echo "Compiling wasm bindings done"

View File

@ -5,9 +5,9 @@
"build": "docker run --rm -v $(pwd):/src trzeci/emscripten ./build.sh"
},
"napa": {
"libwebp": "webmproject/libwebp#v1.0.0"
"libwebp": "webmproject/libwebp#v1.0.2"
},
"devDependencies": {
"napa": "^3.0.0"
"napa": "3.0.0"
}
}

View File

@ -26,7 +26,8 @@ val encode(std::string img, int width, int height, WebPConfig config) {
throw std::runtime_error("Unexpected error");
}
pic.use_argb = !!config.lossless;
// Only use use_argb if we really need it, as it's slower.
pic.use_argb = config.lossless || config.use_sharp_yuv || config.preprocessing > 0;
pic.width = width;
pic.height = height;
pic.writer = WebPMemoryWrite;

File diff suppressed because one or more lines are too long

Binary file not shown.

1202
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
{
"private": true,
"name": "squoosh",
"version": "1.2.1",
"version": "1.3.1",
"license": "apache-2.0",
"scripts": {
"start": "webpack-dev-server --host 0.0.0.0 --hot",
@ -15,55 +15,55 @@
}
},
"devDependencies": {
"@types/node": "^10.12.6",
"@types/pretty-bytes": "^5.1.0",
"@types/webassembly-js-api": "0.0.1",
"@webcomponents/custom-elements": "^1.2.1",
"@webpack-cli/serve": "^0.1.2",
"assets-webpack-plugin": "^3.9.7",
"chokidar": "^2.0.4",
"classnames": "^2.2.6",
"clean-webpack-plugin": "^1.0.0",
"comlink": "^3.0.3",
"copy-webpack-plugin": "^4.6.0",
"critters-webpack-plugin": "^2.0.1",
"css-loader": "^1.0.1",
"ejs": "^2.6.1",
"exports-loader": "^0.7.0",
"file-drop-element": "^0.0.9",
"file-loader": "^2.0.0",
"html-webpack-plugin": "^3.2.0",
"husky": "^1.1.4",
"idb-keyval": "^3.1.0",
"linkstate": "^1.1.1",
"loader-utils": "^1.1.0",
"mini-css-extract-plugin": "^0.4.4",
"minimatch": "^3.0.4",
"node-sass": "^4.11.0",
"optimize-css-assets-webpack-plugin": "^5.0.1",
"pointer-tracker": "^2.0.3",
"preact": "^8.3.1",
"prerender-loader": "^1.2.0",
"pretty-bytes": "^5.1.0",
"progress-bar-webpack-plugin": "^1.11.0",
"raw-loader": "^0.5.1",
"sass-loader": "^7.1.0",
"script-ext-html-webpack-plugin": "^2.1.3",
"source-map-loader": "^0.2.4",
"style-loader": "^0.23.1",
"terser-webpack-plugin": "^1.1.0",
"ts-loader": "^5.3.0",
"tslint": "^5.11.0",
"tslint-config-airbnb": "^5.11.0",
"tslint-config-semistandard": "^7.0.0",
"tslint-react": "^3.6.0",
"typed-css-modules": "^0.3.7",
"typescript": "^3.1.6",
"url-loader": "^1.1.2",
"webpack": "^4.25.1",
"webpack-bundle-analyzer": "^3.0.3",
"webpack-cli": "^3.1.2",
"webpack-dev-server": "^3.1.10",
"worker-plugin": "^1.1.1"
"@types/node": "10.12.21",
"@types/pretty-bytes": "5.1.0",
"@types/webassembly-js-api": "0.0.2",
"@webcomponents/custom-elements": "1.2.1",
"@webpack-cli/serve": "0.1.3",
"assets-webpack-plugin": "3.9.7",
"chokidar": "2.0.4",
"classnames": "2.2.6",
"clean-webpack-plugin": "1.0.1",
"comlink": "3.1.1",
"copy-webpack-plugin": "4.6.0",
"critters-webpack-plugin": "2.2.0",
"css-loader": "1.0.1",
"ejs": "2.6.1",
"exports-loader": "0.7.0",
"file-drop-element": "0.0.9",
"file-loader": "3.0.1",
"html-webpack-plugin": "3.2.0",
"husky": "1.3.1",
"idb-keyval": "3.1.0",
"linkstate": "1.1.1",
"loader-utils": "1.2.0",
"mini-css-extract-plugin": "0.5.0",
"minimatch": "3.0.4",
"node-sass": "4.11.0",
"optimize-css-assets-webpack-plugin": "5.0.1",
"pointer-tracker": "2.0.3",
"preact": "8.4.2",
"prerender-loader": "1.2.0",
"pretty-bytes": "5.1.0",
"progress-bar-webpack-plugin": "1.12.1",
"raw-loader": "1.0.0",
"sass-loader": "7.1.0",
"script-ext-html-webpack-plugin": "2.1.3",
"source-map-loader": "0.2.4",
"style-loader": "0.23.1",
"terser-webpack-plugin": "1.2.2",
"ts-loader": "5.3.3",
"tslint": "5.12.1",
"tslint-config-airbnb": "5.11.1",
"tslint-config-semistandard": "7.0.0",
"tslint-react": "3.6.0",
"typed-css-modules": "0.3.7",
"typescript": "3.2.4",
"url-loader": "1.1.2",
"webpack": "4.28.0",
"webpack-bundle-analyzer": "3.0.3",
"webpack-cli": "3.2.3",
"webpack-dev-server": "3.1.14",
"worker-plugin": "3.0.0"
}
}

5
renovate.json Normal file
View File

@ -0,0 +1,5 @@
{
"extends": [
"config:base"
]
}

View File

@ -1,5 +1,6 @@
import * as identity from './identity/encoder-meta';
import * as optiPNG from './optipng/encoder-meta';
import * as oxiPNG from './oxipng/encoder-meta';
import * as mozJPEG from './mozjpeg/encoder-meta';
import * as webP from './webp/encoder-meta';
import * as browserPNG from './browser-png/encoder-meta';
@ -18,6 +19,7 @@ export interface EncoderSupportMap {
export type EncoderState =
identity.EncoderState |
optiPNG.EncoderState |
oxiPNG.EncoderState |
mozJPEG.EncoderState |
webP.EncoderState |
browserPNG.EncoderState |
@ -32,6 +34,7 @@ export type EncoderState =
export type EncoderOptions =
identity.EncodeOptions |
optiPNG.EncodeOptions |
oxiPNG.EncodeOptions |
mozJPEG.EncodeOptions |
webP.EncodeOptions |
browserPNG.EncodeOptions |
@ -48,6 +51,7 @@ export type EncoderType = keyof typeof encoderMap;
export const encoderMap = {
[identity.type]: identity,
[optiPNG.type]: optiPNG,
[oxiPNG.type]: oxiPNG,
[mozJPEG.type]: mozJPEG,
[webP.type]: webP,
[browserPNG.type]: browserPNG,

View File

@ -3,7 +3,7 @@ export interface EncodeOptions {
}
export interface EncoderState { type: typeof type; options: EncodeOptions; }
export const type = 'png';
export const type = 'optipng';
export const label = 'OptiPNG';
export const mimeType = 'image/png';
export const extension = 'png';

View File

@ -0,0 +1,13 @@
export interface EncodeOptions {
level: number;
}
export interface EncoderState { type: typeof type; options: EncodeOptions; }
export const type = 'oxipng';
export const label = 'OxiPNG';
export const mimeType = 'image/png';
export const extension = 'png';
export const defaultOptions: EncodeOptions = {
level: 6,
};

View File

@ -0,0 +1,18 @@
import * as oxipng from '../../../codecs/oxipng/pkg/oxipng_manual';
import { EncodeOptions } from './encoder-meta';
export async function compress(data: BufferSource, { level }: EncodeOptions): Promise<ArrayBuffer> {
let buffer: ArrayBuffer;
if (ArrayBuffer.isView(data)) {
buffer = data.buffer;
} else {
buffer = data;
}
debugger;
const resultView = await oxipng.compress(new Uint8Array(buffer), level);
const result = new Uint8Array(resultView);
// wasm cant run on SharedArrayBuffers, so we hard-cast to ArrayBuffer.
return result.buffer as ArrayBuffer;
}

View File

@ -0,0 +1,42 @@
import { h, Component } from 'preact';
import { bind } from '../../lib/initial-util';
import { inputFieldValueAsNumber, preventDefault } from '../../lib/util';
import { EncodeOptions } from './encoder-meta';
import Range from '../../components/range';
import * as style from '../../components/Options/style.scss';
type Props = {
options: EncodeOptions;
onChange(newOptions: EncodeOptions): void;
};
export default class OxiPNGEncoderOptions extends Component<Props, {}> {
@bind
onChange(event: Event) {
const form = (event.currentTarget as HTMLInputElement).closest('form') as HTMLFormElement;
const options: EncodeOptions = {
level: inputFieldValueAsNumber(form.level),
};
this.props.onChange(options);
}
render({ options }: Props) {
return (
<form class={style.optionsSection} onSubmit={preventDefault}>
<div class={style.optionOneCell}>
<Range
name="level"
min="0"
max="9"
step="1"
value={options.level}
onInput={this.onChange}
>
Effort:
</Range>
</div>
</form>
);
}
}

View File

@ -41,6 +41,16 @@ async function optiPngEncode(
return compress(data, options);
}
async function oxiPngEncode(
data: BufferSource, options: import('../oxipng/encoder-meta').EncodeOptions,
): Promise<ArrayBuffer> {
const { compress } = await import(
/* webpackChunkName: "process-optipng" */
'../oxipng/encoder',
);
return compress(data, options);
}
async function webpEncode(
data: ImageData, options: import('../webp/encoder-meta').EncodeOptions,
): Promise<ArrayBuffer> {
@ -59,7 +69,15 @@ async function webpDecode(data: ArrayBuffer): Promise<ImageData> {
return decode(data);
}
const exports = { mozjpegEncode, quantize, rotate, optiPngEncode, webpEncode, webpDecode };
const exports = {
mozjpegEncode,
quantize,
rotate,
optiPngEncode,
oxiPngEncode,
webpEncode,
webpDecode,
};
export type ProcessorWorkerApi = typeof exports;
expose(exports, self);

View File

@ -3,6 +3,7 @@ import { QuantizeOptions } from './imagequant/processor-meta';
import { canvasEncode, blobToArrayBuffer } from '../lib/util';
import { EncodeOptions as MozJPEGEncoderOptions } from './mozjpeg/encoder-meta';
import { EncodeOptions as OptiPNGEncoderOptions } from './optipng/encoder-meta';
import { EncodeOptions as OxiPNGEncoderOptions } from './oxipng/encoder-meta';
import { EncodeOptions as WebPEncoderOptions } from './webp/encoder-meta';
import { EncodeOptions as BrowserJPEGOptions } from './browser-jpeg/encoder-meta';
import { EncodeOptions as BrowserWebpEncodeOptions } from './browser-webp/encoder-meta';
@ -20,7 +21,7 @@ import * as browserPDF from './browser-pdf/encoder';
type ProcessorWorkerApi = import('./processor-worker').ProcessorWorkerApi;
/** How long the worker should be idle before terminating. */
const workerTimeout = 1000;
const workerTimeout = 10000;
interface ProcessingJobOptions {
needsWorker?: boolean;
@ -147,6 +148,16 @@ export default class Processor {
return this._workerApi!.optiPngEncode(pngBuffer, opts);
}
@Processor._processingJob({ needsWorker: true })
async oxiPngEncode(
data: ImageData, opts: OxiPNGEncoderOptions,
): Promise<ArrayBuffer> {
// OptiPNG expects PNG input.
const pngBlob = await canvasEncode(data, 'image/png');
const pngBuffer = await blobToArrayBuffer(pngBlob);
return this._workerApi!.oxiPngEncode(pngBuffer, opts);
}
@Processor._processingJob({ needsWorker: true })
webpEncode(data: ImageData, opts: WebPEncoderOptions): Promise<ArrayBuffer> {
return this._workerApi!.webpEncode(data, opts);

View File

@ -1,13 +1,7 @@
import { RotateOptions } from './processor-meta';
const bpp = 4;
export function rotate(data: ImageData, opts: RotateOptions): ImageData {
const { rotate } = opts;
// Early exit if there's no transform.
if (rotate === 0) return data;
const flipDimensions = rotate % 180 !== 0;
const { width: inputWidth, height: inputHeight } = data;
const outputWidth = flipDimensions ? inputHeight : inputWidth;
@ -65,14 +59,13 @@ export function rotate(data: ImageData, opts: RotateOptions): ImageData {
d2Multiplier = 1;
}
const inB = new Uint32Array(data.data.buffer);
const outB = new Uint32Array(out.data.buffer);
for (let d2 = d2Start; d2 >= 0 && d2 < d2Limit; d2 += d2Advance) {
for (let d1 = d1Start; d1 >= 0 && d1 < d1Limit; d1 += d1Advance) {
// Iterate over channels:
const start = ((d1 * d1Multiplier) + (d2 * d2Multiplier)) * bpp;
for (let j = 0; j < bpp; j += 1) {
out.data[i] = data.data[start + j];
i += 1;
}
const start = ((d1 * d1Multiplier) + (d2 * d2Multiplier));
outB[i] = inB[start];
i += 1;
}
}

View File

@ -9,6 +9,8 @@ import '../../lib/SnackBar';
import Intro from '../intro';
import '../custom-els/LoadingSpinner';
const ROUTE_EDITOR = '/editor';
const compressPromise = import(
/* webpackChunkName: "main-app" */
'../compress',
@ -18,15 +20,21 @@ const offlinerPromise = import(
'../../lib/offliner',
);
function back() {
window.history.back();
}
interface Props {}
interface State {
file?: File | Fileish;
isEditorOpen: Boolean;
Compress?: typeof import('../compress').default;
}
export default class App extends Component<Props, State> {
state: State = {
isEditorOpen: false,
file: undefined,
Compress: undefined,
};
@ -48,22 +56,33 @@ export default class App extends Component<Props, State> {
if (process.env.NODE_ENV === 'development') {
this.setState(window.STATE);
const oldCDU = this.componentDidUpdate;
this.componentDidUpdate = (props, state) => {
if (oldCDU) oldCDU.call(this, props, state);
this.componentDidUpdate = (props, state, prev) => {
if (oldCDU) oldCDU.call(this, props, state, prev);
window.STATE = this.state;
};
}
// Since iOS 10, Apple tries to prevent disabling pinch-zoom. This is great in theory, but
// really breaks things on Squoosh, as you can easily end up zooming the UI when you mean to
// zoom the image. Once you've done this, it's really difficult to undo. Anyway, this seems to
// prevent it.
document.body.addEventListener('gesturestart', (event) => {
event.preventDefault();
});
window.addEventListener('popstate', this.onPopState);
}
@bind
private onFileDrop(event: FileDropEvent) {
const { file } = event;
private onFileDrop({ file }: FileDropEvent) {
if (!file) return;
this.openEditor();
this.setState({ file });
}
@bind
private onIntroPickFile(file: File | Fileish) {
this.openEditor();
this.setState({ file });
}
@ -74,18 +93,25 @@ export default class App extends Component<Props, State> {
}
@bind
private onBack() {
this.setState({ file: undefined });
private onPopState() {
this.setState({ isEditorOpen: location.pathname === ROUTE_EDITOR });
}
render({}: Props, { file, Compress }: State) {
@bind
private openEditor() {
if (this.state.isEditorOpen) return;
history.pushState(null, '', ROUTE_EDITOR);
this.setState({ isEditorOpen: true });
}
render({}: Props, { file, isEditorOpen, Compress }: State) {
return (
<div id="app" class={style.app}>
<file-drop accept="image/*" onfiledrop={this.onFileDrop} class={style.drop}>
{(!file)
{!isEditorOpen
? <Intro onFile={this.onIntroPickFile} showSnack={this.showSnack} />
: (Compress)
? <Compress file={file} showSnack={this.showSnack} onBack={this.onBack} />
? <Compress file={file!} showSnack={this.showSnack} onBack={back} />
: <loading-spinner class={style.appLoader}/>
}
<snack-bar ref={linkRef(this, 'snackbar')} />

View File

@ -40,7 +40,9 @@ import Checkbox from '../checkbox';
import Expander from '../expander';
import Select from '../select';
const encoderOptionsComponentMap = {
const encoderOptionsComponentMap: {
[x: string]: (new (...args: any[]) => Component<any, any>) | undefined;
} = {
[identity.type]: undefined,
[optiPNG.type]: OptiPNGEncoderOptions,
[mozJPEG.type]: MozJpegEncoderOptions,

View File

@ -43,6 +43,7 @@ $horizontalPadding: 15px;
.text-field {
background: #fff;
color: #000;
font: inherit;
border: none;
padding: 2px 0 2px 10px;

View File

@ -36,6 +36,8 @@
// We should try to remove this once the issue is fixed.
// https://bugs.chromium.org/p/chromium/issues/detail?id=870222#c10
will-change: auto;
// Prevent the image becoming misshapen due to default flexbox layout.
flex-shrink: 0;
}
.controls {

View File

@ -8,6 +8,7 @@ import Options from '../Options';
import ResultCache from './result-cache';
import * as identity from '../../codecs/identity/encoder-meta';
import * as optiPNG from '../../codecs/optipng/encoder-meta';
import * as oxiPNG from '../../codecs/oxipng/encoder-meta';
import * as mozJPEG from '../../codecs/mozjpeg/encoder-meta';
import * as webP from '../../codecs/webp/encoder-meta';
import * as browserPNG from '../../codecs/browser-png/encoder-meta';
@ -85,12 +86,18 @@ interface UpdateImageOptions {
skipPreprocessing?: boolean;
}
function processInput(
async function processInput(
data: ImageData,
inputProcessData: InputProcessorState,
processor: Processor,
) {
return processor.rotate(data, inputProcessData.rotate);
let processedData = data;
if (inputProcessData.rotate.rotate !== 0) {
processedData = await processor.rotate(processedData, inputProcessData.rotate);
}
return processedData;
}
async function preprocessImage(
@ -125,6 +132,7 @@ async function compressImage(
const compressedData = await (() => {
switch (encodeData.type) {
case optiPNG.type: return processor.optiPngEncode(image, encodeData.options);
case oxiPNG.type: return processor.oxiPngEncode(image, encodeData.options);
case mozJPEG.type: return processor.mozjpegEncode(image, encodeData.options);
case webP.type: return processor.webpEncode(image, encodeData.options);
case browserPNG.type: return processor.browserPngEncode(image);
@ -154,7 +162,7 @@ function stateForNewSourceData(state: State, newSource: SourceImage): State {
for (const i of [0, 1]) {
// Ditch previous encodings
const downloadUrl = state.sides[i].downloadUrl;
if (downloadUrl) URL.revokeObjectURL(downloadUrl!);
if (downloadUrl) URL.revokeObjectURL(downloadUrl);
newState = cleanMerge(state, `sides.${i}`, {
preprocessed: undefined,
@ -234,6 +242,8 @@ export default class Compress extends Component<Props, State> {
private readonly encodeCache = new ResultCache();
private readonly leftProcessor = new Processor();
private readonly rightProcessor = new Processor();
// For debouncing calls to updateImage for each side.
private readonly updateImageTimeoutIds: [number?, number?] = [undefined, undefined];
constructor(props: Props) {
super(props);
@ -301,10 +311,8 @@ export default class Compress extends Component<Props, State> {
// The image only needs updated if the encoder/preprocessor settings have changed, or the
// source has changed.
if (sourceDataChanged || encoderChanged || preprocessorChanged) {
this.updateImage(i, {
this.queueUpdateImage(i, {
skipPreprocessing: !sourceDataChanged && !preprocessorChanged,
}).catch((err) => {
console.error(err);
});
}
}
@ -313,9 +321,14 @@ export default class Compress extends Component<Props, State> {
private async onCopyToOtherClick(index: 0 | 1) {
const otherIndex = (index + 1) % 2;
const oldSettings = this.state.sides[otherIndex];
const newSettings = { ...this.state.sides[index] };
// Create a new object URL for the new settings. This avoids both sides sharing a URL, which
// means it can be safely revoked without impacting the other side.
if (newSettings.file) newSettings.downloadUrl = URL.createObjectURL(newSettings.file);
this.setState({
sides: cleanSet(this.state.sides, otherIndex, this.state.sides[index]),
sides: cleanSet(this.state.sides, otherIndex, newSettings),
});
const result = await this.props.showSnack('Settings copied across', {
@ -446,6 +459,27 @@ export default class Compress extends Component<Props, State> {
}
}
/**
* Debounce the heavy lifting of updateImage.
* Otherwise, the thrashing causes jank, and sometimes crashes iOS Safari.
*/
private queueUpdateImage(index: number, options: UpdateImageOptions = {}): void {
// Call updateImage after this delay, unless queueUpdateImage is called again, in which case the
// timeout is reset.
const delay = 100;
clearTimeout(this.updateImageTimeoutIds[index]);
this.updateImageTimeoutIds[index] = self.setTimeout(
() => {
this.updateImage(index, options).catch((err) => {
console.error(err);
});
},
delay,
);
}
private async updateImage(index: number, options: UpdateImageOptions = {}): Promise<void> {
const {
skipPreprocessing = false,
@ -544,9 +578,9 @@ export default class Compress extends Component<Props, State> {
mobileView={mobileView}
preprocessorState={side.latestSettings.preprocessorState}
encoderState={side.latestSettings.encoderState}
onEncoderTypeChange={this.onEncoderTypeChange.bind(this, index)}
onEncoderOptionsChange={this.onEncoderOptionsChange.bind(this, index)}
onPreprocessorOptionsChange={this.onPreprocessorOptionsChange.bind(this, index)}
onEncoderTypeChange={this.onEncoderTypeChange.bind(this, index as 0|1)}
onEncoderOptionsChange={this.onEncoderOptionsChange.bind(this, index as 0|1)}
onPreprocessorOptionsChange={this.onPreprocessorOptionsChange.bind(this, index as 0|1)}
/>
));
@ -560,7 +594,7 @@ export default class Compress extends Component<Props, State> {
source={source}
loading={loading || side.loading}
copyDirection={copyDirections[index]}
onCopyToOtherClick={this.onCopyToOtherClick.bind(this, index)}
onCopyToOtherClick={this.onCopyToOtherClick.bind(this, index as 0|1)}
buttonPosition={mobileView ? 'stack-right' : buttonPositions[index]}
>
{!mobileView ? null : [

View File

@ -40,6 +40,7 @@
position: relative;
display: flex;
flex-flow: column;
overflow: hidden;
// Reorder so headings appear after content:
& > :nth-child(1) {

View File

@ -251,6 +251,11 @@ module.exports = async function (_, env) {
filename: '_headers',
}),
isProd && new AssetTemplatePlugin({
template: path.join(__dirname, '_redirects.ejs'),
filename: '_redirects',
}),
new ScriptExtHtmlPlugin({
inline: ['first']
}),