format-png 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +39 -0
- package/README.md +6 -20
- package/dist/index.d.ts +5 -10
- package/dist/index.js +13 -10
- package/dist/wasm/format_png_wasm.js +1 -4
- package/dist/wasm/format_png_wasm_bg.wasm.base64.d.ts +3 -0
- package/dist/wasm/format_png_wasm_bg.wasm.base64.js +3 -0
- package/package.json +3 -3
- package/dist/wasm/format_png_wasm_bg.wasm +0 -0
- package/dist/wasm/format_png_wasm_bg.wasm.d.ts +0 -93
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
The WebAssembly module is now embedded in the package, and `init()` with no
|
|
6
|
+
argument uses it, in browsers, bundlers, Web Workers and Node alike. Nothing is
|
|
7
|
+
fetched: the package makes no network requests.
|
|
8
|
+
|
|
9
|
+
### Breaking
|
|
10
|
+
|
|
11
|
+
- The `.wasm` file is no longer in the package, so the
|
|
12
|
+
`format-png/format_png_wasm_bg.wasm` export is gone.
|
|
13
|
+
- `init` no longer takes a URL or string to fetch the module from. It still
|
|
14
|
+
takes a compiled `WebAssembly.Module`.
|
|
15
|
+
|
|
16
|
+
### Upgrading
|
|
17
|
+
|
|
18
|
+
- Node: replace `init(await readFile(...format_png_wasm_bg.wasm...))` with
|
|
19
|
+
`init()`.
|
|
20
|
+
- Browsers and bundlers: `init()` keeps working as before. With Vite,
|
|
21
|
+
`optimizeDeps: { exclude: ["format-png"] }` is no longer needed.
|
|
22
|
+
- If you passed a URL to `init`, call `init()` instead.
|
|
23
|
+
|
|
24
|
+
## 0.1.2
|
|
25
|
+
|
|
26
|
+
- Built against the `format-png` crate 0.1.1. The API and behavior are unchanged.
|
|
27
|
+
- Released with npm staged publishing: each version is approved by a maintainer
|
|
28
|
+
with 2FA before it goes live, and is published with provenance.
|
|
29
|
+
- README: badges for npm, CI and the license.
|
|
30
|
+
|
|
31
|
+
## 0.1.1
|
|
32
|
+
|
|
33
|
+
- The first version released from GitHub Actions, with provenance. The code is
|
|
34
|
+
the same as 0.1.0.
|
|
35
|
+
|
|
36
|
+
## 0.1.0
|
|
37
|
+
|
|
38
|
+
The first release: the `format-png` crate compiled to WebAssembly, with a
|
|
39
|
+
TypeScript API for decoding, encoding, reading chunks and making PNGs smaller.
|
package/README.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# format-png
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/format-png)
|
|
4
|
+
[](https://github.com/YohanSandun/format-png-web/actions/workflows/ci.yml)
|
|
5
|
+
[](https://github.com/YohanSandun/format-png-web/blob/main/LICENSE)
|
|
6
|
+
|
|
3
7
|
A PNG decoder and encoder for the browser and Node, compiled from Rust to WebAssembly.
|
|
4
8
|
|
|
5
9
|
- **Decodes every PNG:** every color type, bit depth from 1 to 16, and Adam7 interlacing. Decode to 8-bit RGBA for a canvas, or in the file's own format with nothing lost.
|
|
@@ -17,9 +21,7 @@ npm install format-png
|
|
|
17
21
|
|
|
18
22
|
## Load the module
|
|
19
23
|
|
|
20
|
-
Call `init()` once before anything else.
|
|
21
|
-
|
|
22
|
-
**Browsers and bundlers** (Vite, webpack, Rollup, esbuild): the `.wasm` file is fetched from next to the module.
|
|
24
|
+
Call `init()` once before anything else. It works the same in browsers, bundlers (Vite, webpack, Rollup, esbuild), Web Workers and Node 20.6 and later: the WebAssembly module is embedded in the package, so nothing is fetched and no bundler setup is needed.
|
|
23
25
|
|
|
24
26
|
```js
|
|
25
27
|
import { init } from "format-png";
|
|
@@ -27,23 +29,7 @@ import { init } from "format-png";
|
|
|
27
29
|
await init();
|
|
28
30
|
```
|
|
29
31
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
```js
|
|
33
|
-
// vite.config.js
|
|
34
|
-
export default { optimizeDeps: { exclude: ["format-png"] } };
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
**Node 20.6 and later**: pass the file's bytes.
|
|
38
|
-
|
|
39
|
-
```js
|
|
40
|
-
import { readFile } from "node:fs/promises";
|
|
41
|
-
import { init } from "format-png";
|
|
42
|
-
|
|
43
|
-
await init(await readFile(new URL(import.meta.resolve("format-png/format_png_wasm_bg.wasm"))));
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
`init` also takes a URL to fetch the module from, or a compiled `WebAssembly.Module`.
|
|
32
|
+
`init` also takes a compiled `WebAssembly.Module`, for example one a page compiled once and posted to its workers.
|
|
47
33
|
|
|
48
34
|
## Display a PNG
|
|
49
35
|
|
package/dist/index.d.ts
CHANGED
|
@@ -300,17 +300,12 @@ export declare class PngError extends Error {
|
|
|
300
300
|
* Loads the WebAssembly module. Call it once before anything else; later calls
|
|
301
301
|
* return the same promise.
|
|
302
302
|
*
|
|
303
|
-
*
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
*
|
|
307
|
-
* import { readFile } from "node:fs/promises";
|
|
308
|
-
* await init(await readFile(new URL(import.meta.resolve("format-png/format_png_wasm_bg.wasm"))));
|
|
309
|
-
* ```
|
|
310
|
-
*
|
|
311
|
-
* You can also pass a URL to fetch it from, or a compiled `WebAssembly.Module`.
|
|
303
|
+
* With no argument it uses the copy embedded in this package, in browsers,
|
|
304
|
+
* bundlers and Node alike: nothing is fetched. You can instead pass a
|
|
305
|
+
* `WebAssembly.Module` compiled from it, for example one a page compiled once
|
|
306
|
+
* and posted to its workers.
|
|
312
307
|
*/
|
|
313
|
-
export declare function init(source?: BufferSource | WebAssembly.Module |
|
|
308
|
+
export declare function init(source?: BufferSource | WebAssembly.Module | Response | Promise<Response>): Promise<void>;
|
|
314
309
|
/**
|
|
315
310
|
* Decodes a PNG in its own format, without conversion: every bit depth and
|
|
316
311
|
* color type as stored, with its palette and transparency. Pass the result to
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import initWasm, * as wasm from "./wasm/format_png_wasm.js";
|
|
2
|
+
import wasmBase64 from "./wasm/format_png_wasm_bg.wasm.base64.js";
|
|
2
3
|
/** Thrown for malformed PNGs; `message` says what's wrong. */
|
|
3
4
|
export class PngError extends Error {
|
|
4
5
|
name = "PngError";
|
|
@@ -9,18 +10,13 @@ let initialized = false;
|
|
|
9
10
|
* Loads the WebAssembly module. Call it once before anything else; later calls
|
|
10
11
|
* return the same promise.
|
|
11
12
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* import { readFile } from "node:fs/promises";
|
|
17
|
-
* await init(await readFile(new URL(import.meta.resolve("format-png/format_png_wasm_bg.wasm"))));
|
|
18
|
-
* ```
|
|
19
|
-
*
|
|
20
|
-
* You can also pass a URL to fetch it from, or a compiled `WebAssembly.Module`.
|
|
13
|
+
* With no argument it uses the copy embedded in this package, in browsers,
|
|
14
|
+
* bundlers and Node alike: nothing is fetched. You can instead pass a
|
|
15
|
+
* `WebAssembly.Module` compiled from it, for example one a page compiled once
|
|
16
|
+
* and posted to its workers.
|
|
21
17
|
*/
|
|
22
18
|
export function init(source) {
|
|
23
|
-
ready ??= initWasm(
|
|
19
|
+
ready ??= initWasm({ module_or_path: source ?? decodeBase64(wasmBase64) })
|
|
24
20
|
.then(() => {
|
|
25
21
|
initialized = true;
|
|
26
22
|
})
|
|
@@ -30,6 +26,13 @@ export function init(source) {
|
|
|
30
26
|
});
|
|
31
27
|
return ready;
|
|
32
28
|
}
|
|
29
|
+
function decodeBase64(text) {
|
|
30
|
+
const binary = atob(text);
|
|
31
|
+
const bytes = new Uint8Array(binary.length);
|
|
32
|
+
for (let i = 0; i < binary.length; i++)
|
|
33
|
+
bytes[i] = binary.charCodeAt(i);
|
|
34
|
+
return bytes;
|
|
35
|
+
}
|
|
33
36
|
function call(fn) {
|
|
34
37
|
if (!initialized)
|
|
35
38
|
throw new PngError("format-png: call init() first");
|
|
@@ -1501,13 +1501,10 @@ async function __wbg_init(module_or_path) {
|
|
|
1501
1501
|
}
|
|
1502
1502
|
|
|
1503
1503
|
if (module_or_path === undefined) {
|
|
1504
|
-
|
|
1504
|
+
throw new Error("format-png: no WebAssembly module given");
|
|
1505
1505
|
}
|
|
1506
1506
|
const imports = __wbg_get_imports();
|
|
1507
1507
|
|
|
1508
|
-
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
1509
|
-
module_or_path = fetch(module_or_path);
|
|
1510
|
-
}
|
|
1511
1508
|
|
|
1512
1509
|
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
1513
1510
|
|