UNPKG

2.12 kBPlain TextView Raw
1import { IFontManager, FontFormat } from '@deathbeds/jupyterlab-fonts';
2import { JupyterLab, JupyterFrontEndPlugin } from '@jupyterlab/application';
3
4const variants = ['Light', 'Regular', 'Medium', 'Bold'];
5
6const variantPromises: { [key: string]: () => Promise<string> } = {
7 Light: async () => {
8 return (await import(`!!file-loader!firacode/distr/woff2/FiraCode-Light.woff2`))
9 .default;
10 },
11 Regular: async () => {
12 return (await import(`!!file-loader!firacode/distr/woff2/FiraCode-Regular.woff2`))
13 .default;
14 },
15 Medium: async () => {
16 return (await import(`!!file-loader!firacode/distr/woff2/FiraCode-Medium.woff2`))
17 .default;
18 },
19 Bold: async () => {
20 return (await import(`!!file-loader!firacode/distr/woff2/FiraCode-Bold.woff2`))
21 .default;
22 },
23};
24
25function register(fonts: IFontManager) {
26 variants.forEach((variant) => {
27 fonts.registerFontFace({
28 name: `Fira Code ${variant}`,
29 license: {
30 spdx: 'OFL-1.1',
31 name: 'SIL Open Font License 1.1',
32 text: async () => {
33 return (await import('!!raw-loader!firacode/LICENSE')).default;
34 },
35 holders: [
36 `Copyright (c) 2014, Nikita Prokopov http://tonsky.me with Reserved Font Name Fira Code.`,
37 `Copyright (c) 2014, Mozilla Foundation https://mozilla.org/ with Reserved Font Name Fira Sans.`,
38 `Copyright (c) 2014, Mozilla Foundation https://mozilla.org/ with Reserved Font Name Fira Mono.`,
39 'Copyright (c) 2014, Telefonica S.A.',
40 ],
41 },
42 faces: async () => {
43 const font = await variantPromises[variant]();
44 const uri = await fonts.dataURISrc(font, FontFormat.woff2);
45 return [{ fontFamily: `'Fira Code ${variant}'`, src: uri }];
46 },
47 });
48 });
49}
50
51const plugin: JupyterFrontEndPlugin<void> = {
52 id: '@deathbeds/jupyterlab-font-fira-code',
53 autoStart: true,
54 requires: [IFontManager],
55 activate: function (_app: JupyterLab, fonts: IFontManager) {
56 fonts.ready
57 .then(() => {
58 register(fonts);
59 })
60 .catch(console.warn);
61 },
62};
63
64export default plugin;