heic2any-lite 0.0.0-stage → 1.0.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/LICENSE ADDED
@@ -0,0 +1,40 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 kanha vishwakarma
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
+
23
+ ===========================================================================
24
+ Third-party notices
25
+ ===========================================================================
26
+
27
+ heic2any-lite reproduces the public API, option handling, colour conversion and
28
+ error messages of heic2any, and the GIF output of gifshot/omggif as used by
29
+ heic2any. Those projects are MIT licensed:
30
+
31
+ - heic2any: Copyright (c) 2020 Alex Corvi (MIT License)
32
+ https://github.com/alexcorvi/heic2any
33
+ - gifshot: Copyright (c) 2017 Yahoo Inc. (MIT License)
34
+ https://github.com/yahoo/gifshot
35
+ - omggif: Copyright (c) 2013 Dean McNamee (MIT License)
36
+ https://github.com/deanm/omggif
37
+
38
+ src/gif/neuQuant.ts is derived from the NeuQuant Neural-Net Quantization
39
+ Algorithm, Copyright (c) 1994 Anthony Dekker, used under its original terms:
40
+ the copyright notice must remain intact (see the header of that file).
package/README.md CHANGED
@@ -1,3 +1,139 @@
1
- # Temporary Holding Version
1
+ # heic2any-lite
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
+ Convert HEIC/HEIF images (iPhone photos) to **PNG, JPEG or GIF in the browser**.
4
+
5
+ A drop-in replacement for [`heic2any`](https://github.com/alexcorvi/heic2any): same function, same options, same
6
+ results and the same error objects. Underneath it has its own HEIF parser and HEVC decoder written in TypeScript,
7
+ with no dependencies and no WebAssembly.
8
+
9
+ | | `heic2any` 0.0.4 | `heic2any-lite` |
10
+ | ----------------------- | ----------------------------------- | --------------------------------------------------- |
11
+ | Size (minified) | 1.35 MB | 116 KB; the ESM entry is ~6 KB, the rest loads on first use |
12
+ | On import | starts a Web Worker, sets `window.__heic2any__worker` | does nothing (SSR-safe, tree-shakeable) |
13
+ | Decoding | Web Worker (libde265 via asm.js) | Web Worker, started on first use, closed after 30 s idle |
14
+ | CSP blocks `blob:` workers | conversion fails | falls back to the main thread, yielding so the page stays responsive |
15
+ | Pixel accuracy | its libde265 build mis-decodes some samples | bit-exact with the browser's hardware HEVC decoder |
16
+ | Module formats | UMD | ESM (code-split) + UMD (CommonJS / AMD / `<script>`) |
17
+ | Decode without a DOM | no | `decodeHeicToRgba()` works in workers and Node |
18
+
19
+ ## Install
20
+
21
+ ```sh
22
+ npm install heic2any-lite
23
+ ```
24
+
25
+ ## Migrating from heic2any
26
+
27
+ Change the import. Nothing else changes.
28
+
29
+ ```diff
30
+ - import heic2any from 'heic2any';
31
+ + import heic2any from 'heic2any-lite';
32
+ ```
33
+
34
+ CommonJS (`require('heic2any-lite')` and `require(...).default`), AMD and the `window.heic2any` global work the
35
+ same way as before.
36
+
37
+ ## Usage
38
+
39
+ ```ts
40
+ import heic2any from 'heic2any-lite';
41
+
42
+ const png = (await heic2any({ blob: file })) as Blob; // PNG
43
+ const jpeg = (await heic2any({ blob: file, toType: 'image/jpeg', quality: 0.8 })) as Blob;
44
+ const all = (await heic2any({ blob: file, multiple: true })) as Blob[]; // every image in the file
45
+ const gif = (await heic2any({ blob: file, toType: 'image/gif', gifInterval: 0.5 })) as Blob; // animated if several
46
+ ```
47
+
48
+ Plain `<script>` tag (no bundler):
49
+
50
+ ```html
51
+ <script src="https://cdn.jsdelivr.net/npm/heic2any-lite@1/dist/heic2any.min.js"></script>
52
+ <script>
53
+ heic2any({ blob }).then((png) => { /* ... */ });
54
+ </script>
55
+ ```
56
+
57
+ ### `heic2any(options): Promise<Blob | Blob[]>`
58
+
59
+ | Option | Type | Default | Meaning |
60
+ | ------------- | -------- | ------------- | ------- |
61
+ | `blob` | `Blob` | (required) | The HEIC/HEIF file. |
62
+ | `toType` | `string` | `'image/png'` | `'image/png'`, `'image/jpeg'` or `'image/gif'`. Any other value gives PNG. |
63
+ | `quality` | `number` | `0.92` | JPEG quality, 0 to 1. Values outside that range use 0.92. |
64
+ | `multiple` | `true` | (not set) | Resolve with an array holding every top-level image instead of only the first. |
65
+ | `gifInterval` | `number` | `0.4` | Seconds per frame when `toType` is `'image/gif'`. Every image in the file becomes a frame. |
66
+
67
+ It resolves with a `Blob`, or `Blob[]` when `multiple` is set (a GIF is always one `Blob`).
68
+
69
+ It rejects with `{ code, message }`, like heic2any:
70
+
71
+ | `code` | `ERROR_CODES` | Example `message` |
72
+ | ------ | ------------- | ----------------- |
73
+ | 1 | `USER` | `ERR_USER Image is already browser readable: image/png` |
74
+ | 2 | `LIBHEIF` | `ERR_LIBHEIF format not supported` |
75
+ | 3 | `GIF` | `ERR_GIF ...` |
76
+ | 4 | `DOM` | `ERR_DOM ...` |
77
+ | 5 | `CANVAS` | `ERR_CANVAS Error on converting imagedata to blob: ...` |
78
+ | 0 | `UNKNOWN` | anything else |
79
+
80
+ ```ts
81
+ import heic2any, { ERROR_CODES, type Heic2AnyError } from 'heic2any-lite';
82
+
83
+ try {
84
+ await heic2any({ blob: file });
85
+ } catch (e) {
86
+ if ((e as Heic2AnyError).code === ERROR_CODES.USER) {
87
+ // already a PNG/JPEG/GIF: use the file as it is
88
+ }
89
+ }
90
+ ```
91
+
92
+ ### `decodeHeicToRgba(data, options?): Promise<RgbaImage[]>`
93
+
94
+ Decodes every top-level image to `{ width, height, data: Uint8ClampedArray }` RGBA pixels, with no canvas.
95
+ Use it in a Web Worker, in Node, or to draw the pixels yourself. Pass `{ yieldBetweenTiles: false }` when you
96
+ are not on a page's main thread.
97
+
98
+ ## What it decodes
99
+
100
+ - HEIC/HEIF still images: single images, grids (`grid`, the format iPhones use), overlays (`iovl`) and derived
101
+ images (`iden`), with rotation (`irot`), mirroring (`imir`) and cropping (`clap`) applied.
102
+ - HEVC Main, Main Still Picture and Main 10 (8 to 12 bit, converted to 8-bit output), 4:2:0 and monochrome.
103
+ - Like heic2any, it ignores alpha and depth auxiliary images and EXIF orientation.
104
+ - It does not support 4:2:2/4:4:4 chroma or the HEVC range-extension coding tools. These files reject with
105
+ `ERR_LIBHEIF Error while processing single image ...` (heic2any cannot convert them either).
106
+
107
+ ## Output compared with heic2any
108
+
109
+ The API, option handling, colour conversion (same coefficients, nearest chroma sample) and error objects all
110
+ reproduce heic2any. The decoded pixels are **not** byte-identical to heic2any, deliberately. The libde265 build
111
+ inside heic2any 0.0.4 mis-decodes some samples along sharp edges (about 4% of samples in the test image are off
112
+ by up to 22 luma / 63 chroma levels). This library matches the browser's own hardware HEVC decoder exactly, and
113
+ `npm run test:browser` checks that. In practice the two outputs look the same (PSNR ≈ 45 dB).
114
+
115
+ ## Content-Security-Policy
116
+
117
+ Decoding runs in a Web Worker created from a `blob:` URL, as heic2any's does. If your CSP has `worker-src`
118
+ (or `script-src` as its fallback) without `blob:`, the worker cannot start. The library then decodes on the main
119
+ thread and pauses between tiles so the page stays responsive. Add `blob:` to `worker-src` to keep decoding off
120
+ the main thread.
121
+
122
+ ## Development
123
+
124
+ ```sh
125
+ npm install
126
+ npm test # unit tests (jest): HEIF parser, HEVC decoder, GIF encoder, worker protocol, API
127
+ npm run typecheck
128
+ npm run build # dist/esm (ESM), dist/heic2any.js + .min.js (UMD), dist/types
129
+ npm run test:dist # the built UMD and ESM files, in Node
130
+ npm run test:browser # real Edge/Chrome: worker, CSP fallback, hardware-decoder bit-exactness,
131
+ # comparison with the original heic2any (installed as a devDependency)
132
+ ```
133
+
134
+ `npm publish` runs the type-check, the unit tests, the build and the dist tests first (`prepublishOnly`).
135
+
136
+ ## License
137
+
138
+ MIT © kanha vishwakarma. It reproduces the API of [heic2any](https://github.com/alexcorvi/heic2any) and the GIF
139
+ output of gifshot/omggif (all MIT). See [LICENSE](LICENSE) for the third-party notices.
@@ -0,0 +1,25 @@
1
+ /*! heic2any-lite v1.0.0 | MIT | NeuQuant (c) 1994 Anthony Dekker */
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __spreadValues = (a, b) => {
10
+ for (var prop in b || (b = {}))
11
+ if (__hasOwnProp.call(b, prop))
12
+ __defNormalProp(a, prop, b[prop]);
13
+ if (__getOwnPropSymbols)
14
+ for (var prop of __getOwnPropSymbols(b)) {
15
+ if (__propIsEnum.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ }
18
+ return a;
19
+ };
20
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
+
22
+ export {
23
+ __spreadValues,
24
+ __spreadProps
25
+ };
@@ -0,0 +1,40 @@
1
+ /*! heic2any-lite v1.0.0 | MIT | NeuQuant (c) 1994 Anthony Dekker */
2
+
3
+ // src/errors.ts
4
+ var ERROR_CODES = {
5
+ UNKNOWN: 0,
6
+ USER: 1,
7
+ LIBHEIF: 2,
8
+ GIF: 3,
9
+ DOM: 4,
10
+ CANVAS: 5
11
+ };
12
+ var PREFIXES = ["ERR_USER", "ERR_LIBHEIF", "ERR_GIF", "ERR_DOM", "ERR_CANVAS"];
13
+ function toHeic2AnyError(message) {
14
+ let text;
15
+ if (!message) {
16
+ text = "ERR_UNKNOWN";
17
+ } else if (typeof message !== "string") {
18
+ const m = message;
19
+ text = m.toString ? m.toString() : JSON.stringify(message);
20
+ } else {
21
+ text = message;
22
+ }
23
+ let code = 0;
24
+ PREFIXES.forEach((prefix, index) => {
25
+ if (text.indexOf(prefix) === 0) code = index + 1;
26
+ });
27
+ return { code, message: text };
28
+ }
29
+ var HeicDecodeError = class extends Error {
30
+ constructor(message) {
31
+ super(message);
32
+ this.name = "HeicDecodeError";
33
+ }
34
+ };
35
+
36
+ export {
37
+ ERROR_CODES,
38
+ toHeic2AnyError,
39
+ HeicDecodeError
40
+ };