# @xlfont/choose

> font chooser widget for building your website

Latest version **0.0.33** (published 2026-11-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install @xlfont/choose
pnpm add @xlfont/choose
yarn add @xlfont/choose
bun add @xlfont/choose
```

Provides the command `xfc`.

## Health

**Score 55/100 (C)** — status: active.

Positive: no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no types; no esm support; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.0.33 |
| Published | 2026-11-28 |
| First published | 2021-10-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=10.14.1 |
| Dependencies | 6 |
| Unpacked size | 64.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | zbryikt |
| Maintainers | tkirby |

## Links

- npm: https://www.npmjs.com/package/@xlfont/choose
- Repository: https://github.com/xlfont/choose
- Issues: https://github.com/xlfont/choose/issues
- npm.io page: https://npm.io/package/@xlfont/choose

## Dependencies (6)

- [ldview](https://npm.io/package/ldview.md) ^1.7.2
- [proxise](https://npm.io/package/proxise.md) ^1.0.1
- [ldloader](https://npm.io/package/ldloader.md) ^3.0.3
- [@xlfont/load](https://npm.io/package/@xlfont/load.md) ^2.1.8
- [@loadingio/vscroll](https://npm.io/package/@loadingio/vscroll.md) ^0.0.14
- [@plotdb/opentype.js](https://npm.io/package/@plotdb/opentype.js.md) ^1.3.5

## Recent versions

- 0.0.33 (latest) — 2026-11-28
- 0.0.32 — 2024-04-05
- 0.0.31 — 2024-04-05
- 0.0.30 — 2024-04-05
- 0.0.29 — 2024-02-03
- 0.0.28 — 2024-01-28
- 0.0.27 — 2024-01-03
- 0.0.26 — 2023-11-17
- 0.0.25 — 2023-11-17
- 0.0.24 — 2023-11-17
- 0.0.23 — 2023-11-15
- 0.0.22 — 2023-11-06
- 0.0.21 — 2023-11-06
- 0.0.20 — 2023-11-02
- 0.0.19 — 2023-09-27
- … 18 more at https://npm.io/package/@xlfont/choose/versions

## README

# @xlfont/choose

font chooser including

 - ui and library for chooser dynamics
 - tool for building meta files from fonts of your choice.


## Frontend Usage

`@xlfont/choose` depends on `@xlfont/load` so you have to install both. Install by

    npm install --save @xlfont/choose @xlfont/load

and include `index.js` and `index.css` under `@xlfont/choose`'s `dist` folder, along with `index.js` in `@xlfont/load`.

HTML counterpart is also needed, which is available as a mixin in `dist/index.pug`, in `pug` format. `@xlfont/choose` is based on `ldview` which means UI / Logic is separated thus you can make your own chooser widget to fit your design ( while the JS Selectors are not documented so you have to check `index.pug` for reference. )

After installed, create a `xfc` instance:

    chooser = new xfc( ... )

Here is a minimal working example in `pug`, with `@plotdb/srcbuild` pug extension syntax:

    include @/@xlfont/choose/dist/index.pug
    .ldcv: +xfc
    script
      chooser = new xfc { root: '.ldcv', initRender: true }
      chooser.init!then -> ...


Check `web/src/pug/index.pug` for example with `ldcover` and `@xlfont/choose`.


## Constructor Options

 - `root`: container element or selector for inserting font chooser
 - `meta`: metadata URL root. fallback to url set by `xfc.url` if omitted.
 - `links`: font file URL root. fallback to url set by `xfc.url` if omitted.
 - `i18n`: i18n object in `i18next` spec.
 - `initRender`: default false. when false, list should be rendered by calling `render` function manually.
   - font list rendering involves bounding box calculation, which may not be available when container isnt' visible.
   - in this case, user should manually call `render()` after container is visible.
 - `order(a,b)`: sort font list based on given font objects where:
   - `n`: font name
 - `upload({font, type})`: optional. if provided, return state of upload font for certain type.
   - check `state` below for possible types.
 - `state({font, type})`: optional. return state of font for certain type.
   - type can be either:
     - `limited`: return true if this font is limited. default `limited` when `type` is omitted.
   - if implemented, should return `undefined` for unsupported `type`.


## API

 - `config(opt)`: update config, including `state`, `order` and `upload` option in constructor parameters.
 - `render()`: render font list.
 - `load(opt)`: load a font based on the given parameter `opt`.
   - returns a Promise which resolves with the desired font(a xlfont object), or rejects if font is not found.
   - `opt` can be either:
     - a number: return the font by the given index from the font family list.
     - a string: return the font with the exact same name to `opt`, case insensitive.
     - a simplified font object such as `{name, style, weight, mod: {file}}`.
       - `mod.file` is an object used to load uploaded fonts.
         - it contains following fields(which will be used to call `fontFromFile`):
           - mandatory field:
             - `blob`: font file blob. mandatory. for uploaded fonts.
           - fields from File object:
             - `name`: font file name.
             - `lastModified`: timestamp of file modified time
             - `size`: file size
             - `type`: file mimetype.
         - can contains other fields depending on user spec, for example:
           - `digest`: file digest (e.g., md5)
           - `key`: file key for accessing it from a data storage.
     - the font family object itself
 - `fontFromFile(opt)`: load a font from file. opt:
   - `file`: either a file object (Blob) or the `mod.file` object (see `load(opt)` above for more info)
   - `name`: font name. use `file.name` if omitted.

## Class API

 - `url(opt)`: set url hint for meta and links urls
   - `opt` is an object with following fields:
     - `meta`: suggested metadata URL root
     - `links`: suggested font file URL root
   - when `opt` is omitted, return url hint or `{}` if not available.


## Events

 - `choose`: fired when a font is chosen, with an xlfont object from `@xlfont/load` for the chosen font.
 - `load.start`: fired when a font is loading. ( after user clicking a font )
 - `load.end`: fired when a font load ended. ( either succeeded or failed )
 - `load.fail`: fired when a font is failed to load.


## Xlfont Extension

`@xlfont/choose` extends `xlfont` in `font.ext` with following fields:

 - `limited`: indicate that this font is limited in usage when true.
 - `blob`: blob for the uploaded font, if this font is uploaded by user.


## Metadata Generation

To generate metadata, also install `@xlfont/choose` if not installed yet:

    npm install --save-dev @xlfont/choose

`xfc` dependencies are optional peer dependencies ( not installed along with the widget ), install them too:

    npm install --save-dev @plotdb/colors@^0.0.3 fs-extra js-yaml progress@^2 sharp yargs@^17

running `xfc` without them prints the exact command to install, or to run via `npx -p` without installing. node >= 20.9 is required.

A command (via npx) will be available after install:

    npx xfc

This command generates necessary files for `@xlfont/choose` to list your fonts. It generates:

 - a minimized PNG for previewing fonts.
 - metadata for font information, including name, style and position in previewer PNG.
 - a directory structure recgonized by `@xlfont/choose`, with symbolic links to the fonts your provided.

Avilable options:

 - `--link`: or `-l`, output directory for symbolic links to font. default `./output/links`.
 - `--output`: or `-m`, output directory for metadata. default `./output/meta`.
 - `--font-size`: or `-f`, default font size. default 48, auto shrink if needed.

For a complete list of possible options, please run `npx xfc --help` directly.


### Generate  with Configurations

You can also generate metadata with a prepared configuration file with `--config` or `-c` option. Supported fields in this configuration file are as follow:

 - `width`: default 400, width of font preview box
 - `height`: default 50, height of font preview box
 - `col`: default 5,
 - `padding`: default 10,
 - `fsize`: default 48,
 - `links`: output directory for symboic links to font.
 - `meta`: output directory for metadata.
 - `src`: source directory for source fonts.
 - `ignores`: a list of regular expressions for font names to exclude.


## LICENSE

MIT License.

---
_Source: https://npm.io/package/@xlfont/choose · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
