@xlfont/choose v0.0.32
@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/loadand 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 choosermeta: metadata URL root. fallback to url set byxfc.urlif omitted.links: font file URL root. fallback to url set byxfc.urlif omitted.i18n: i18n object ini18nextspec.initRender: default false. when false, list should be rendered by callingrenderfunction 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
statebelow for possible types.
- check
state({font, type}): optional. return state of font for certain type.- type can be either:
limited: return true if this font is limited. defaultlimitedwhentypeis omitted.
- if implemented, should return
undefinedfor unsupportedtype.
- type can be either:
API
config(opt): update config, includingstate,orderanduploadoption in constructor parameters.render(): render font list.load(opt): load a font based on the given parameteropt.- returns a Promise which resolves with the desired font(a xlfont object), or rejects if font is not found.
optcan 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.fileis 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 timesize: file sizetype: file mimetype.
- mandatory field:
- 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.
- it contains following fields(which will be used to call
- the font family object itself
fontFromFile(opt): load a font from file. opt:file: either a file object (Blob) or themod.fileobject (seeload(opt)above for more info)name: font name. usefile.nameif omitted.
Class API
url(opt): set url hint for meta and links urlsoptis an object with following fields:meta: suggested metadata URL rootlinks: suggested font file URL root
- when
optis omitted, return url hint or{}if not available.
Events
choose: fired when a font is chosen, with an xlfont object from@xlfont/loadfor 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/chooseA command (via npx) will be available after install:
npx xfcThis 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 boxheight: default 50, height of font preview boxcol: 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.
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago