woff2-decode 0.1.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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jeremy Tribby, Countertype LLC
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.
@@ -0,0 +1,121 @@
1
+ Test Fixtures
2
+ =============
3
+
4
+ The font files in test/fixtures/ are from the woff2-encoder project:
5
+ https://github.com/itskyedo/woff2-encoder
6
+
7
+ Copyright (c) 2023-PRESENT Kyedo
8
+ Licensed under the MIT License
9
+
10
+ The fonts themselves appear to be Inter, copyright The Inter Project Authors
11
+ (https://github.com/rsms/inter), licensed under the SIL Open Font License 1.1
12
+
13
+ ---
14
+
15
+ MIT License (woff2-encoder)
16
+ ---------------------------
17
+
18
+ Permission is hereby granted, free of charge, to any person obtaining a copy
19
+ of this software and associated documentation files (the "Software"), to deal
20
+ in the Software without restriction, including without limitation the rights
21
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
22
+ copies of the Software, and to permit persons to whom the Software is
23
+ furnished to do so, subject to the following conditions:
24
+
25
+ The above copyright notice and this permission notice shall be included in all
26
+ copies or substantial portions of the Software.
27
+
28
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
29
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
30
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
31
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
32
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
33
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34
+ SOFTWARE.
35
+
36
+ ---
37
+
38
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
39
+
40
+ PREAMBLE
41
+ The goals of the Open Font License (OFL) are to stimulate worldwide
42
+ development of collaborative font projects, to support the font creation
43
+ efforts of academic and linguistic communities, and to provide a free and
44
+ open framework in which fonts may be shared and improved in partnership
45
+ with others.
46
+
47
+ The OFL allows the licensed fonts to be used, studied, modified and
48
+ redistributed freely as long as they are not sold by themselves. The
49
+ fonts, including any derivative works, can be bundled, embedded,
50
+ redistributed and/or sold with any software provided that any reserved
51
+ names are not used by derivative works. The fonts and derivatives,
52
+ however, cannot be released under any other type of license. The
53
+ requirement for fonts to remain under this license does not apply
54
+ to any document created using the fonts or their derivatives.
55
+
56
+ DEFINITIONS
57
+ "Font Software" refers to the set of files released by the Copyright
58
+ Holder(s) under this license and clearly marked as such. This may
59
+ include source files, build scripts and documentation.
60
+
61
+ "Reserved Font Name" refers to any names specified as such after the
62
+ copyright statement(s).
63
+
64
+ "Original Version" refers to the collection of Font Software components as
65
+ distributed by the Copyright Holder(s).
66
+
67
+ "Modified Version" refers to any derivative made by adding to, deleting,
68
+ or substituting -- in part or in whole -- any of the components of the
69
+ Original Version, by changing formats or by porting the Font Software to a
70
+ new environment.
71
+
72
+ "Author" refers to any designer, engineer, programmer, technical
73
+ writer or other person who contributed to the Font Software.
74
+
75
+ PERMISSION & CONDITIONS
76
+ Permission is hereby granted, free of charge, to any person obtaining
77
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
78
+ redistribute, and sell modified and unmodified copies of the Font
79
+ Software, subject to the following conditions:
80
+
81
+ 1) Neither the Font Software nor any of its individual components,
82
+ in Original or Modified Versions, may be sold by itself.
83
+
84
+ 2) Original or Modified Versions of the Font Software may be bundled,
85
+ redistributed and/or sold with any software, provided that each copy
86
+ contains the above copyright notice and this license. These can be
87
+ included either as stand-alone text files, human-readable headers or
88
+ in the appropriate machine-readable metadata fields within text or
89
+ binary files as long as those fields can be easily viewed by the user.
90
+
91
+ 3) No Modified Version of the Font Software may use the Reserved Font
92
+ Name(s) unless explicit written permission is granted by the corresponding
93
+ Copyright Holder. This restriction only applies to the primary font name as
94
+ presented to the users.
95
+
96
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
97
+ Software shall not be used to promote, endorse or advertise any
98
+ Modified Version, except to acknowledge the contribution(s) of the
99
+ Copyright Holder(s) and the Author(s) or with their explicit written
100
+ permission.
101
+
102
+ 5) The Font Software, modified or unmodified, in part or in whole,
103
+ must be distributed entirely under this license, and must not be
104
+ distributed under any other license. The requirement for fonts to
105
+ remain under this license does not apply to any document created
106
+ using the Font Software.
107
+
108
+ TERMINATION
109
+ This license becomes null and void if any of the above conditions are
110
+ not met.
111
+
112
+ DISCLAIMER
113
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
114
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
115
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
116
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
117
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
118
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
119
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
120
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
121
+ OTHER DEALINGS IN THE FONT SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # woff2-decode
2
+
3
+ A pure TypeScript WOFF2 decoder
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install woff2-decode
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { decode } from 'woff2-decode'
15
+
16
+ const woff2Data = await fetch('/font.woff2').then(r => r.arrayBuffer())
17
+ const ttfData = decode(woff2Data)
18
+
19
+ // ttfData is a Uint8Array containing the decoded TTF/OTF
20
+ ```
21
+
22
+ The decoder handles both single fonts and TrueType Collections (TTC). For collections, the output is a valid TTC file
23
+
24
+ ## Performance
25
+
26
+ Benchmarks on an M1 Mac, Node 20. In Node, native Brotli (via zlib) is used automatically. The pure JS fallback is for browsers
27
+
28
+ | File | Size | Native | Pure JS |
29
+ |------|------|--------|---------|
30
+ | enc-otf.woff2 | 107 KB | 1.7 ms | 5.1 ms |
31
+ | enc-ttf.woff2 | 98 KB | 4.0 ms | 7.1 ms |
32
+ | enc-var-ttf.woff2 | 318 KB | 6.8 ms | 15.1 ms |
33
+
34
+ CFF fonts decode faster because they skip the glyf/loca transform
35
+
36
+ ## What Gets Decoded
37
+
38
+ WOFF2 is not just compressed font data. The spec defines transforms for certain tables:
39
+
40
+ - **glyf/loca**: Point coordinates are delta-encoded with a variable-length triplet scheme. Reconstructing these is the bulk of the decoder logic
41
+ - **hmtx**: Left side bearings can be stripped and reconstructed from glyph bounding boxes
42
+
43
+ Tables without transforms (including CFF, CFF2, and everything else) pass through after Brotli decompression
44
+
45
+ ## API
46
+
47
+ ```typescript
48
+ function decode(data: ArrayBuffer | Uint8Array): Uint8Array
49
+ ```
50
+
51
+ Throws if the input is not valid WOFF2 or if decompression fails
52
+
53
+ MIT, maintained by [@jpt](https://github.com/jpt)
@@ -0,0 +1,5 @@
1
+ export declare function decompress(data: Uint8Array): Uint8Array;
2
+ export declare function decompressNative(data: Uint8Array): Uint8Array;
3
+ export declare function decompressPure(data: Uint8Array): Uint8Array;
4
+ export declare const hasNative: boolean;
5
+ //# sourceMappingURL=brotli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"brotli.d.ts","sourceRoot":"","sources":["../src/brotli.ts"],"names":[],"mappings":"AAiCA,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAKvD;AAGD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAK7D;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAE3D;AAED,eAAO,MAAM,SAAS,SAAwB,CAAC"}
@@ -0,0 +1,20 @@
1
+ export declare class Buffer {
2
+ private view;
3
+ private pos;
4
+ constructor(data: ArrayBuffer | Uint8Array, offset?: number, length?: number);
5
+ get offset(): number;
6
+ get length(): number;
7
+ get remaining(): number;
8
+ get buffer(): DataView;
9
+ skip(n: number): boolean;
10
+ seek(offset: number): boolean;
11
+ readU8(): number | null;
12
+ readU16(): number | null;
13
+ readS16(): number | null;
14
+ readU32(): number | null;
15
+ readS32(): number | null;
16
+ readBytes(n: number): Uint8Array | null;
17
+ peekU8(offset?: number): number | null;
18
+ subarray(offset: number, length: number): Uint8Array | null;
19
+ }
20
+ //# sourceMappingURL=buffer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buffer.d.ts","sourceRoot":"","sources":["../src/buffer.ts"],"names":[],"mappings":"AACA,qBAAa,MAAM;IACjB,OAAO,CAAC,IAAI,CAAW;IACvB,OAAO,CAAC,GAAG,CAAa;gBAEZ,IAAI,EAAE,WAAW,GAAG,UAAU,EAAE,MAAM,GAAE,MAAU,EAAE,MAAM,CAAC,EAAE,MAAM;IAU/E,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,IAAI,MAAM,IAAI,QAAQ,CAErB;IAED,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO;IAQxB,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAQ7B,MAAM,IAAI,MAAM,GAAG,IAAI;IAKvB,OAAO,IAAI,MAAM,GAAG,IAAI;IAOxB,OAAO,IAAI,MAAM,GAAG,IAAI;IAOxB,OAAO,IAAI,MAAM,GAAG,IAAI;IAOxB,OAAO,IAAI,MAAM,GAAG,IAAI;IAOxB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI;IAOvC,MAAM,CAAC,MAAM,GAAE,MAAU,GAAG,MAAM,GAAG,IAAI;IAMzC,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI;CAM5D"}
@@ -0,0 +1,5 @@
1
+ export interface DecodeOptions {
2
+ forcePureBrotli?: boolean;
3
+ }
4
+ export declare function decode(data: ArrayBuffer | Uint8Array, options?: DecodeOptions): Uint8Array;
5
+ //# sourceMappingURL=decode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../src/decode.ts"],"names":[],"mappings":"AAyDA,MAAM,WAAW,aAAa;IAC5B,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAGD,wBAAgB,MAAM,CAAC,IAAI,EAAE,WAAW,GAAG,UAAU,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,UAAU,CA6D1F"}