jpegxl 0.0.0-stage → 8.3.5

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.
Files changed (173) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +273 -2
  3. package/THIRD_PARTY_NOTICES +99 -0
  4. package/dist/animation.edge-light.mjs +4 -0
  5. package/dist/animation.helper.mjs +2 -0
  6. package/dist/animation.mjs +2 -0
  7. package/dist/animation.worker.mjs +1058 -0
  8. package/dist/animation.workerd.mjs +4 -0
  9. package/dist/capture-complete.edge-light.mjs +4 -0
  10. package/dist/capture-complete.groups.worker.mjs +980 -0
  11. package/dist/capture-complete.helper.mjs +317 -0
  12. package/dist/capture-complete.mjs +2 -0
  13. package/dist/capture-complete.worker.mjs +2 -0
  14. package/dist/capture-complete.workerd.mjs +4 -0
  15. package/dist/capture-groups.mjs +2 -0
  16. package/dist/capture.edge-light.mjs +4 -0
  17. package/dist/capture.mjs +2 -0
  18. package/dist/capture.worker.mjs +2 -0
  19. package/dist/capture.workerd.mjs +4 -0
  20. package/dist/cli-emdash.mjs +384 -0
  21. package/dist/cli-selftest.mjs +16 -0
  22. package/dist/cli.mjs +69 -0
  23. package/dist/codec-animation.mjs +157 -0
  24. package/dist/codec-capture-complete.mjs +157 -0
  25. package/dist/codec-capture.mjs +2 -0
  26. package/dist/codec-decode.mjs +2 -0
  27. package/dist/codec-format.mjs +157 -0
  28. package/dist/codec-jpeg.mjs +153 -0
  29. package/dist/codec-upload.mjs +156 -0
  30. package/dist/codec.mjs +2 -0
  31. package/dist/decode.edge-light.mjs +4 -0
  32. package/dist/decode.mjs +465 -0
  33. package/dist/decode.node.mjs +468 -0
  34. package/dist/decode.wasm +0 -0
  35. package/dist/decode.worker.mjs +490 -0
  36. package/dist/decode.workerd.mjs +4 -0
  37. package/dist/format.edge-light.mjs +4 -0
  38. package/dist/format.helper.mjs +2 -0
  39. package/dist/format.mjs +2 -0
  40. package/dist/format.worker.mjs +1136 -0
  41. package/dist/format.workerd.mjs +4 -0
  42. package/dist/helpers.mjs +2 -0
  43. package/dist/index.edge-light.mjs +4 -0
  44. package/dist/index.mjs +2 -0
  45. package/dist/index.workerd.mjs +4 -0
  46. package/dist/jpeg.edge-light.mjs +4 -0
  47. package/dist/jpeg.mjs +2 -0
  48. package/dist/jpeg.node.mjs +2 -0
  49. package/dist/jpeg.wasm +0 -0
  50. package/dist/jpeg.worker.mjs +2 -0
  51. package/dist/jpeg.workerd.mjs +4 -0
  52. package/dist/kernels.wasm +0 -0
  53. package/dist/metadata.mjs +2 -0
  54. package/dist/polyfill.mjs +2 -0
  55. package/dist/resumable.edge-light.mjs +4 -0
  56. package/dist/resumable.mjs +179 -0
  57. package/dist/resumable.node.mjs +179 -0
  58. package/dist/resumable.workerd.mjs +4 -0
  59. package/dist/serve.mjs +2 -0
  60. package/dist/serve.node.mjs +2 -0
  61. package/dist/still.helper.mjs +2 -0
  62. package/dist/still.worker.mjs +1517 -0
  63. package/dist/storage.mjs +19 -0
  64. package/dist/upload.edge-light.mjs +4 -0
  65. package/dist/upload.helper.mjs +2 -0
  66. package/dist/upload.mjs +2 -0
  67. package/dist/upload.worker.mjs +2 -0
  68. package/dist/upload.workerd.mjs +4 -0
  69. package/dist/verify.edge-light.mjs +4 -0
  70. package/dist/verify.mjs +2 -0
  71. package/dist/verify.node.mjs +2 -0
  72. package/dist/verify.workerd.mjs +4 -0
  73. package/dist/wasm-modules.mjs +2 -0
  74. package/dist/wasm.edge-light.mjs +5 -0
  75. package/dist/wasm.mjs +2 -0
  76. package/dist/wasm.workerd.mjs +5 -0
  77. package/examples/09-browser-upload-queue.html +13 -0
  78. package/examples/09-browser-upload-queue.mjs +74 -0
  79. package/examples/emdash/AGENTS.md +20 -0
  80. package/examples/emdash/README.md +165 -0
  81. package/examples/emdash/admin-work.mjs +249 -0
  82. package/examples/emdash/astro.config.mjs +13 -0
  83. package/examples/emdash/backfill.mjs +79 -0
  84. package/examples/emdash/background.mjs +97 -0
  85. package/examples/emdash/browser-candidate.mjs +25 -0
  86. package/examples/emdash/browser-tools.mjs +7 -0
  87. package/examples/emdash/deliver.mjs +29 -0
  88. package/examples/emdash/digest.mjs +4 -0
  89. package/examples/emdash/host-policy.mjs +118 -0
  90. package/examples/emdash/index.d.ts +9 -0
  91. package/examples/emdash/index.mjs +23 -0
  92. package/examples/emdash/job-runner.mjs +477 -0
  93. package/examples/emdash/job-store.mjs +230 -0
  94. package/examples/emdash/library-jobs.mjs +230 -0
  95. package/examples/emdash/local-store.mjs +222 -0
  96. package/examples/emdash/media-admin.mjs +736 -0
  97. package/examples/emdash/media-plugin.mjs +614 -0
  98. package/examples/emdash/media-settings.mjs +33 -0
  99. package/examples/emdash/media-storage.mjs +701 -0
  100. package/examples/emdash/media-words.d.mts +3 -0
  101. package/examples/emdash/media-words.mjs +307 -0
  102. package/examples/emdash/media-worker.mjs +96 -0
  103. package/examples/emdash/middleware.mjs +104 -0
  104. package/examples/emdash/node-admission.mjs +27 -0
  105. package/examples/emdash/original-cache-node.mjs +49 -0
  106. package/examples/emdash/original-cache-workers.mjs +31 -0
  107. package/examples/emdash/original-envelope.mjs +44 -0
  108. package/examples/emdash/originals.mjs +1113 -0
  109. package/examples/emdash/r2-store.mjs +54 -0
  110. package/examples/emdash/storage-local.mjs +19 -0
  111. package/examples/emdash/storage-r2.mjs +21 -0
  112. package/examples/emdash/storage.mjs +12 -0
  113. package/examples/emdash/structural-delivery.mjs +166 -0
  114. package/examples/emdash/thread-driver.mjs +251 -0
  115. package/examples/emdash/thread-worker.mjs +44 -0
  116. package/examples/emdash/work-queue.mjs +71 -0
  117. package/examples/page-rects.d.ts +23 -0
  118. package/examples/page-rects.js +342 -0
  119. package/examples/polyfill.html +7 -0
  120. package/examples/snapdom/README.md +92 -0
  121. package/examples/snapdom/jxl.d.ts +54 -0
  122. package/examples/snapdom/jxl.js +419 -0
  123. package/examples/snapdom/svg-jxl.d.ts +23 -0
  124. package/examples/snapdom/svg-jxl.js +39 -0
  125. package/examples/svg-jxl.d.ts +16 -0
  126. package/examples/svg-jxl.js +236 -0
  127. package/package.json +285 -5
  128. package/skills/rapier-jxl/SKILL.md +32 -0
  129. package/types/animation.d.mts +11 -0
  130. package/types/capture-complete.d.mts +27 -0
  131. package/types/capture.d.mts +20 -0
  132. package/types/codec/animation-atlas.d.mts +50 -0
  133. package/types/codec/animation.d.mts +40 -0
  134. package/types/codec/channels.d.mts +125 -0
  135. package/types/codec/container-advanced.d.mts +117 -0
  136. package/types/codec/container-stream.d.mts +24 -0
  137. package/types/codec/decode.d.mts +139 -0
  138. package/types/codec/delta-palette.d.mts +29 -0
  139. package/types/codec/graphics.d.mts +35 -0
  140. package/types/codec/hybrid.d.mts +19 -0
  141. package/types/codec/icc.d.mts +85 -0
  142. package/types/codec/index.d.mts +60 -0
  143. package/types/codec/jpeg.d.mts +29 -0
  144. package/types/codec/layers.d.mts +38 -0
  145. package/types/codec/metadata.d.mts +53 -0
  146. package/types/codec/patches.d.mts +99 -0
  147. package/types/codec/photo-advanced.d.mts +118 -0
  148. package/types/codec/photo.d.mts +18 -0
  149. package/types/codec/splines.d.mts +45 -0
  150. package/types/codec/writer.d.mts +206 -0
  151. package/types/codec-animation.d.mts +4 -0
  152. package/types/codec-capture-complete.d.mts +4 -0
  153. package/types/codec-capture.d.mts +4 -0
  154. package/types/codec-decode.d.mts +4 -0
  155. package/types/codec-format.d.mts +4 -0
  156. package/types/codec-jpeg.d.mts +4 -0
  157. package/types/codec-upload.d.mts +4 -0
  158. package/types/codec.d.mts +85 -0
  159. package/types/decode.d.mts +14 -0
  160. package/types/format.d.mts +73 -0
  161. package/types/index.d.mts +27 -0
  162. package/types/jpeg.d.mts +24 -0
  163. package/types/metadata.d.mts +17 -0
  164. package/types/polyfill.d.mts +34 -0
  165. package/types/preparation-upload.d.mts +16 -0
  166. package/types/result.d.mts +73 -0
  167. package/types/resumable.d.mts +187 -0
  168. package/types/serve.d.mts +34 -0
  169. package/types/storage.d.mts +13 -0
  170. package/types/types.d.mts +440 -0
  171. package/types/upload.d.mts +27 -0
  172. package/types/verify.d.mts +76 -0
  173. package/types/wasm.d.mts +6 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 rapier.website
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md CHANGED
@@ -1,3 +1,274 @@
1
- # Temporary Holding Version
1
+ # rapier-jxl
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm](https://img.shields.io/npm/v/jpegxl)](https://www.npmjs.com/package/jpegxl)
4
+ [![downloads](https://img.shields.io/npm/dw/jpegxl)](https://www.npmjs.com/package/jpegxl)
5
+ [![license](https://img.shields.io/npm/l/jpegxl)](https://github.com/jackskip22/rapier-jxl/blob/main/LICENSE)
6
+ [![types](https://img.shields.io/npm/types/jpegxl)](https://www.npmjs.com/package/jpegxl)
7
+
8
+ JPEG XL in JavaScript and WebAssembly with WebGPU for high efforts.
9
+
10
+ Used by [SnapDOM's official JPEG XL plugin](https://snapdom.dev/plugins/jxl/) and the [EmDash image optimizer](https://plugins.emdashcms.com/plugins/@rapier.website/jxl). [Try it in your browser](https://rapier.website/jxl).
11
+
12
+ - Uploads over 2x faster than libvips.
13
+ - 52 KB Brotli exact capture.
14
+ - 244 KB Brotli complete capture.
15
+ - 277 KB Brotli upload.
16
+ - 361 KB Brotli full encoder with HDR and parallel workers. Used by [rapier.html](https://rapier.website)
17
+ - Lossless JPEG transcoding, decoding, verification, serving, metadata, animation, polyfill, CLI and resumable encoding
18
+ for edge isolates. Modules are single files.
19
+ - Browsers, workers, Node, Deno, Bun, Cloudflare Workers.
20
+ - No dependencies.
21
+ - MIT.
22
+
23
+ ```sh
24
+ npm install jpegxl
25
+ ```
26
+
27
+ ESM. From CommonJS: `await import('jpegxl')`.
28
+
29
+ ## Command line
30
+
31
+ ```sh
32
+ npx jpegxl photo.png # photo.jxl beside it
33
+ npx jpegxl scan.jpg # scan.jxl, lossless; the original JPEG can be restored
34
+ npx jpegxl photos/ --out dist/ # every PNG, JPEG and GIF in the folder
35
+ npx jpegxl hero.png --max-bytes 100KB # lower quality to fit, keeping dimensions
36
+ npx jpegxl scan.jxl --out back/ # back/scan.jpg, the original JPEG
37
+ npx jpegxl photos/ --out dist/ --json # one JSON line per file, then a summary
38
+ ```
39
+
40
+ `--quality 1–100` (default 90), `--effort 1–9` (default 7), `--lossless`, `--max-bytes`, `--out`, `--jobs` (helpers).
41
+ Automatic output names never replace files.
42
+ `--json` names what each file kept: `jpeg-bytes` (the JPEG restores exactly), `pixels` (exact) or `lossy`. A rerun
43
+ leaves finished files untouched.
44
+
45
+ ## Upload
46
+
47
+ ```js
48
+ import {encode, fit} from 'jpegxl/upload';
49
+
50
+ // file: a File or Blob from an input, a drop or a fetch.
51
+ const compress = async file => {
52
+ const result = await encode(file, {fidelity: {quality: 82}});
53
+ if (!result.bytes) throw Object.assign(new Error(result.reason.message), {code: result.reason.code});
54
+ return new Blob([result.bytes], {type: 'image/jxl'});
55
+ };
56
+ const small = file => fit(file, {maxBytes: 100_000}); // best quality under 100 KB; `fits` says whether it got there
57
+ ```
58
+
59
+ `variants` makes several sizes from one upload. All calls accept `onProgress` and `signal`, for progress bars and
60
+ cancelling. On Node and Deno, pass decoded pixels `{data, width, height}`; only JPEGs with `fidelity: 'exact'` and
61
+ PNGs with transparency or 16 bits can be passed as files.
62
+
63
+ ## Encode
64
+
65
+ ```js
66
+ import {writeFile} from 'node:fs/promises';
67
+ import {encode} from 'jpegxl';
68
+
69
+ const picture = {data: new Uint8Array([240, 120, 40, 255]), width: 1, height: 1};
70
+ await writeFile('picture.jxl', (await encode(picture, {fidelity: {quality: 90}})).bytes);
71
+ ```
72
+
73
+ Takes RGBA `{data, width, height}`, `ImageData`, a canvas (2D, WebGL or WebGPU), an `ImageBitmap`, a `VideoFrame`, a
74
+ `Blob`, a decoded image or a GPU texture `{texture, device}`, and returns a result record with the output in `result.bytes`. 8 or 16-bit, `Float16Array`
75
+ or `Float32Array` samples, including HDR. For animations, including an animated GIF `Blob`, use `rapier-jxl/animation`.
76
+
77
+ - Lossless JPEG recompression is `recompress` from `jpegxl/jpeg`; in `rapier-jxl/upload`, `encode(jpegFile, {fidelity: 'exact'})` does the same. The full `encode` takes pixels.
78
+ - `fidelity`: `{quality: 1–100}`, default 90. `'exact'` is lossless.
79
+ - `effort`: 1–9, default 7. Lower is faster; 1–3 suit previews and uploads, 8–9 photography.
80
+ - `webgpu`: efforts 7–9 use WebGPU when available. `'required'` fails without it; `false` turns it off.
81
+ - `maxPixels`: default 40 MP, up to 268,435,456 pixels with neither side over 32,767. Very large images can be passed in strips with `rows(y, count)`.
82
+ - `verify(original, result)` from `jpegxl/verify` checks a file against its source.
83
+
84
+ ## Screenshots
85
+
86
+ ```js
87
+ import {capture} from 'jpegxl/capture';
88
+ import {capture as page} from 'jpegxl/capture-complete';
89
+
90
+ const screenshot = canvas => capture(canvas); // lossless
91
+ const smaller = (canvas, rects) => page(canvas, {fidelity: {quality: 92}, ...rects}); // lossy photos, lossless text
92
+ ```
93
+
94
+ - Canvas (2D, WebGL or WebGPU), `ImageData`, an `ImageBitmap`, a `VideoFrame`, a `Blob` or 8-bit RGBA.
95
+ - `rects` is `{exactRects, photoRects}`: the areas to keep lossless, such as text, and where the photos are.
96
+ - `rapier-jxl/page-rects` finds both in a page element, for any library that draws one to a canvas.
97
+ - Pages up to 32,767 pixels tall in one file; WebP stops at 16,383. Above 40 MP, raise `maxPixels`.
98
+ - Efforts 6–9 check photo quality with the browser's JPEG XL decoder. In Node, Deno, Bun and desktop apps, the one setup
99
+ step is `configureDecoder(decode)`, with `decode` from `jpegxl/decode`.
100
+
101
+ | Effort | `capture-complete` |
102
+ |---|---|
103
+ | 1–3 | Fast. 3 is the default, 2 for quick saves, 1 for live previews. |
104
+ | 4–5 | Deeper search: smaller text, graphics and photos without quality loss. |
105
+ | 6–9 | Automatically finds the smallest file at the quality you choose. 7–9 also search block sizes. |
106
+
107
+ ## JPEG, decoding, metadata
108
+
109
+ ```js
110
+ import {recompress, restore} from 'jpegxl/jpeg';
111
+ import {decode} from 'jpegxl/decode';
112
+ import {header} from 'jpegxl/metadata';
113
+
114
+ // jpeg: a Uint8Array holding a JPEG file, up to 64 MP.
115
+ const roundTrip = async jpeg => (await restore((await recompress(jpeg)).bytes)).bytes;
116
+ const pixels = async file => decode(file); // {width, height, data}, RGBA
117
+ const size = file => header(file); // synchronous, from a file or its first bytes
118
+ ```
119
+
120
+ `rapier-jxl/svg-jxl` converts the images inside any SVG to JPEG XL where that makes them smaller while automatically keeping shapes and text sharp.
121
+ `{exact: true}` keeps the images lossless.
122
+
123
+ ## Serving
124
+
125
+ For recompressed JPEGs, `serve` sends JPEG XL to browsers that support it and the original JPEG to the rest, with
126
+ `Vary: Accept`, ETag, `304` and `HEAD`.
127
+
128
+ ```js
129
+ import {createServer} from 'node:http';
130
+ import {readFile} from 'node:fs/promises';
131
+ import {serve} from 'jpegxl/serve';
132
+
133
+ // photo.jxl, made once: npx jpegxl photo.jpg
134
+ const stored = await readFile('photo.jxl');
135
+ createServer((req, res) => serve(stored, req, res)).listen(3000);
136
+ ```
137
+
138
+ Cloudflare Workers, Deno and Bun: `return serve(stored, request)`. `cacheControl` sets `Cache-Control` (default
139
+ `private, no-cache`).
140
+
141
+ ## Resumable encoding
142
+
143
+ For edge isolates with short time limits: an encode continues across requests in short steps and writes the same file
144
+ as one call.
145
+
146
+ ```js
147
+ import {start, advance, finish} from 'jpegxl/resumable';
148
+ import {encode} from 'jpegxl/upload';
149
+ import {verify} from 'jpegxl/verify';
150
+
151
+ // store: the original and the job's parts (R2, KV, a database). input names the original:
152
+ // {generation, sha256, byteLength}, with kind: 'file' for an uploaded file.
153
+ const step = async (saved, store, input) => {
154
+ const job = {operation: encode, store, input, verify};
155
+ const {checkpoint, done} = await advance(saved ?? await start({...job, options: {fidelity: {quality: 82}}}), job);
156
+ return done ? {result: await finish(checkpoint, job)} : {checkpoint}; // save checkpoint for the next request
157
+ };
158
+ ```
159
+
160
+ - `capture`, `encode`, `fit`, `variants`, `recompress`, `restore` and `verify`.
161
+ - Each `advance` runs for about 30 ms (`budget: {ms}`) and writes its parts to the store before it returns. A host that allows few store calls a request passes `budget.reads`: the call ends before more reads than that.
162
+ - `verify` from `jpegxl/verify` in the job verifies in the advances. `finish` returns the whole-file verifier's
163
+ receipt in `result.verification` (one per variant). A failed check rejects with `error.verification`; publish only a finished,
164
+ verified result. The saved plan keeps this choice for every request.
165
+ - Pixel verification needs the browser's JPEG XL decoding or the host's configured decoder. On a server, call
166
+ `configureDecoder(decode, restore)` from `jpegxl/verify` with `decode` from `jpegxl/decode` and `restore` from
167
+ `jpegxl/jpeg` in each new isolate. The resumable module carries no decoder.
168
+ - Keep the original immutable for its `generation` and SHA-256. Save the returned checkpoint with a revision check
169
+ after its parts are durable, and accept checkpoints only from your service. `finish` assembles the saved output;
170
+ hashing, decoding and scoring have already finished in the advances.
171
+ - `workerAdmission({operation, options, width, height})` says whether a job fits a Cloudflare Workers isolate (128 MB), from measured memory per operation, effort and size. A size not measured is not admitted; convert it in the browser.
172
+
173
+ For a candidate uploaded separately, use the existing `verify` verb. Store the candidate as immutable, ordered parts
174
+ of at most 1 MiB, each named by its SHA-256. Pass its result metadata without `bytes` or a `verification` receipt:
175
+
176
+ ```js
177
+ import {start, finish} from 'jpegxl/resumable';
178
+ import {verify} from 'jpegxl/verify';
179
+
180
+ const job = (store, input) => ({operation: verify, input, store});
181
+ const begin = (store, input, result, parts) => start({...job(store, input), options: {result, parts}});
182
+ // Persist and advance the checkpoint as above. When done, finish returns the receipt:
183
+ const done = (checkpoint, store, input) => finish(checkpoint, job(store, input));
184
+ ```
185
+
186
+ `finish` returns the same receipt as `verify(original, result)` and reads neither image. A failed check rejects with
187
+ `error.verification`. The service verifies the original generation and candidate revision again before publication;
188
+ metadata supplied by the uploader is a claim to check.
189
+
190
+ ## EmDash
191
+
192
+ Run in the site's folder:
193
+
194
+ ```sh
195
+ npx jpegxl add emdash
196
+ ```
197
+
198
+ For a coding agent: “Add rapier-jxl/emdash to this site, keeping its existing storage and EmDash options.”
199
+
200
+ For manual setup with EmDash 1.4, install the package and its matching Kumo version:
201
+
202
+ ```sh
203
+ npm install jpegxl @cloudflare/kumo@2.6.0
204
+ ```
205
+
206
+ Keep the existing imports and options; wrap `emdash({...})` with `jxl(emdash, {...})`:
207
+
208
+ ```js
209
+ // astro.config.mjs
210
+ import emdash from 'emdash/astro';
211
+ import {jxl} from 'jpegxl/emdash';
212
+
213
+ export default defineConfig({
214
+ integrations: [react(), jxl(emdash, {database: d1({binding: 'DB'}), storage: r2({binding: 'MEDIA'})})],
215
+ });
216
+ ```
217
+
218
+ Originals stay in the site's `r2()` storage on Cloudflare or `local()` storage on Node. Browsers that accept JPEG XL
219
+ get verified copies; other browsers get the original. Open **Plugins → JPEG XL Image Optimizer** to choose the goal, effort
220
+ and widths or convert the existing library. Without `jxl()`, the site serves its originals.
221
+
222
+ ## Workers and queues
223
+
224
+ ```js
225
+ import {createCodec} from 'jpegxl/codec';
226
+
227
+ const queue = createCodec({module: 'rapier-jxl/upload', helpers: {count: 3, memoryBytes: 1 << 30}});
228
+ const photo = (width, height) => ({data: new Uint8Array(width * height * 4).fill(200), width, height});
229
+ try {
230
+ const files = await Promise.all([photo(1200, 900), photo(300, 225)].map(picture => queue.encode(picture)));
231
+ } finally {
232
+ await queue.close();
233
+ }
234
+ ```
235
+
236
+ - In browsers, the module runs in a worker (upload: 301 KB Brotli). Node, Deno and Bun run it in the calling thread.
237
+ - With one module, import its codec from `jpegxl/codec/<module>`; bundlers then ship only that module's files.
238
+ - `helpers` adds up to 16 worker threads; `helpers: true` sizes them by the device.
239
+ - Errors carry a `code`, such as `JXL_INPUT`, `JXL_OPTIONS`, `JXL_WASM` or `JXL_WEBGPU`.
240
+
241
+ ## Browsers
242
+
243
+ ```html
244
+ <script type="module">
245
+ import {encode} from 'https://cdn.jsdelivr.net/npm/jpegxl@8/dist/index.mjs';
246
+ const {bytes} = await encode(document.querySelector('canvas'));
247
+ </script>
248
+ ```
249
+
250
+ - Content Security Policy: `'wasm-unsafe-eval'`; `worker-src blob:` for `rapier-jxl/codec` from a CDN.
251
+ - Every module needs WebAssembly with SIMD (`JXL_WASM` without it), except `restore` and `metadata`.
252
+ - Without native JPEG XL: `import 'jpegxl/polyfill'`.
253
+ - Vite, webpack 5, Next.js, Parcel and Astro work as is. A Vite 7 workspace that installs rapier-jxl above the app's
254
+ folder needs `optimizeDeps: {exclude: ['rapier-jxl']}`. Next.js edge routes: import modules directly, not
255
+ `rapier-jxl/codec`.
256
+ - Angular: add `{"glob": "*.{worker,helper}.mjs", "input": "node_modules/jpegxl/dist", "output": "/"}` to the
257
+ build's `assets` in `angular.json`; with one module, the glob `<module>.*{worker,helper}.mjs`.
258
+ - Rollup: `@web/rollup-plugin-import-meta-assets` with `assetFileNames: 'assets/[name][extname]'`.
259
+ - esbuild: copy `rapier-jxl/dist/*.worker.mjs` and `*.helper.mjs` beside the bundle; with one module, its
260
+ `<module>.*{worker,helper}.mjs`.
261
+
262
+ Node 20.16+ or 22.3+, Deno, Bun, Cloudflare Workers.
263
+
264
+ ## License
265
+
266
+ MIT. Third-party notices: `THIRD_PARTY_NOTICES`.
267
+
268
+ ## Contributing
269
+
270
+ Anybody is welcome to contribute to rapier-jxl, which is intended to be as universal as possible. You can also greatly assist the project by simply performing tests on your computer which is always turning up new edge cases to improve the encoder. Testing on every kind of device is essential for a universal encoder. Check the jobs/ folder in the repo root, open an issue with the job's name as its title if you've started work on it, then please submit your results by attaching them to that issue.
271
+
272
+ For feedback, requests or questions, feel free to join the discussion. The goal is to make rapier-jxl as easy, fast, small, powerful and reliable as possible for every use case, while keeping the architecture simple and general.
273
+
274
+ Examples and plugins can be added for very common use cases.
@@ -0,0 +1,99 @@
1
+ Acorn JavaScript parser (MIT; bundled into the command-line setup tool only)
2
+
3
+ Copyright (C) 2012-2022 by various contributors (see https://github.com/acornjs/acorn/blob/master/AUTHORS)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
22
+
23
+ Brotli dictionary and transforms (RFC 7932)
24
+
25
+ Copyright (c) 2009, 2010, 2013-2016 by the Brotli Authors.
26
+
27
+ Permission is hereby granted, free of charge, to any person obtaining a copy
28
+ of this software and associated documentation files (the "Software"), to deal
29
+ in the Software without restriction, including without limitation the rights
30
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
31
+ copies of the Software, and to permit persons to whom the Software is
32
+ furnished to do so, subject to the following conditions:
33
+
34
+ The above copyright notice and this permission notice shall be included in
35
+ all copies or substantial portions of the Software.
36
+
37
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
38
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
39
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
40
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
41
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
42
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
43
+ THE SOFTWARE.
44
+
45
+ JPEG XL perceptual-metric arithmetic (BSD-3-Clause)
46
+
47
+ Copyright (c) the JPEG XL Project Authors.
48
+ All rights reserved.
49
+
50
+ Redistribution and use in source and binary forms, with or without
51
+ modification, are permitted provided that the following conditions are met:
52
+
53
+ 1. Redistributions of source code must retain the above copyright notice, this
54
+ list of conditions and the following disclaimer.
55
+
56
+ 2. Redistributions in binary form must reproduce the above copyright notice,
57
+ this list of conditions and the following disclaimer in the documentation
58
+ and/or other materials provided with the distribution.
59
+
60
+ 3. Neither the name of the copyright holder nor the names of its
61
+ contributors may be used to endorse or promote products derived from
62
+ this software without specific prior written permission.
63
+
64
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
65
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
66
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
67
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
68
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
69
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
70
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
71
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
72
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
73
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
74
+
75
+ musl math helpers linked from WASI libc (MIT)
76
+
77
+ The Butteraugli kernel links fma.c, scalbn.c and fmaxf.c from musl, supplied by
78
+ WebAssembly/wasi-libc at 6cd211489269bd40bea2a6795436ae2aa496d61a.
79
+
80
+ Copyright © 2005-2020 Rich Felker, et al.
81
+
82
+ Permission is hereby granted, free of charge, to any person obtaining
83
+ a copy of this software and associated documentation files (the
84
+ "Software"), to deal in the Software without restriction, including
85
+ without limitation the rights to use, copy, modify, merge, publish,
86
+ distribute, sublicense, and/or sell copies of the Software, and to
87
+ permit persons to whom the Software is furnished to do so, subject to
88
+ the following conditions:
89
+
90
+ The above copyright notice and this permission notice shall be
91
+ included in all copies or substantial portions of the Software.
92
+
93
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
94
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
95
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
96
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
97
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
98
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
99
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,4 @@
1
+ import wasm from './wasm.edge-light.mjs';
2
+ import {configureWasm} from './animation.mjs';
3
+ configureWasm(wasm);
4
+ export * from './animation.mjs';