@compatifont/fonts 0.0.0-stage → 0.1.1
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 +21 -0
- package/README.md +46 -2
- package/dist/catalog.generated.d.ts +3 -0
- package/dist/catalog.generated.js +634 -0
- package/dist/catalog.json +638 -0
- package/dist/index.d.ts +58 -0
- package/dist/index.js +107 -0
- package/package.json +51 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Onur Solmaz
|
|
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.
|
package/README.md
CHANGED
|
@@ -1,3 +1,47 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@compatifont/fonts`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Lightweight JavaScript/TypeScript catalog and SHA-256-verified fetcher for [Compatifont](https://github.com/osolmaz/compatifont) open fonts (`OFL-1.1`), metric-compatible with Microsoft Office fonts.
|
|
4
|
+
|
|
5
|
+
The npm package ships only the typed catalog metadata and fetcher (~10 KB) — no multi-megabyte `.ttf` files are bundled into your app. Fonts are downloaded on demand and verified against their exact SHA-256 checksums before being returned.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @compatifont/fonts
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Use with `@f-office/wasm`
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { init, Renderer, loadFontsFor } from "@f-office/wasm";
|
|
17
|
+
import { fontFetcher } from "@compatifont/fonts";
|
|
18
|
+
|
|
19
|
+
await init();
|
|
20
|
+
const renderer = new Renderer();
|
|
21
|
+
await loadFontsFor(renderer, docxBytes, fontFetcher());
|
|
22
|
+
|
|
23
|
+
const doc = renderer.openDocx(docxBytes);
|
|
24
|
+
const page = doc.renderPage(0, 144);
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Self-hosting fonts
|
|
28
|
+
|
|
29
|
+
Download the `.ttf` files from the [Compatifont GitHub Release](https://github.com/osolmaz/compatifont/releases) (or mirror `fonts/<slug>/files/*.ttf`) and pass your own `baseUrl`:
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
const fetchFont = fontFetcher({
|
|
33
|
+
baseUrl: "https://static.example.com/compatifont/fonts",
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## API
|
|
38
|
+
|
|
39
|
+
- `CATALOG`: typed array of all 13 Compatifont families (`slug`, `familyName`, `version`, `spdxLicense`, `files`, `compatibleWith`).
|
|
40
|
+
- `resolveFamily(name)`: resolves a Compatifont name (`"Celeborn CF"`, `"celeborn-cf"`) or matched Microsoft Office family name (`"Calibri"`, `"Arial"`, `"Times New Roman"`, `"Cambria"`, `"Aptos"`, `"Courier New"`, `"Georgia"`, `"Segoe UI"`, `"Comic Sans MS"`, `"Symbol"`, etc.) to its `FontFamily` entry.
|
|
41
|
+
- `fontFetcher(options?)`: returns `(family: string) => Promise<Uint8Array[] | null>`, with in-memory caching (`cache: true`) and Web Crypto SHA-256 verification (`verify: true`) enabled by default.
|
|
42
|
+
- `fontUrl(family, file, baseUrl?)`: returns the full download URL for one `.ttf` face.
|
|
43
|
+
|
|
44
|
+
## License
|
|
45
|
+
|
|
46
|
+
- Package code: `MIT`
|
|
47
|
+
- Downloaded font files: `OFL-1.1` (SIL Open Font License 1.1)
|