UNPKG

4.07 kBPlain TextView Raw
1import { Token } from '@lumino/coreutils';
2import { CommandRegistry } from '@lumino/commands';
3import { ICommandPalette } from '@jupyterlab/apputils';
4import { ISignal } from '@lumino/signaling';
5import { INotebookTracker, NotebookPanel } from '@jupyterlab/notebook';
6
7import { Menu } from '@lumino/widgets';
8
9import * as SCHEMA from './schema';
10
11import '../style/index.css';
12
13export type Scope = 'global' | 'notebook';
14
15export enum TextKind {
16 code = 'code',
17 content = 'content'
18}
19
20export const KIND_LABELS: { [key in TextKind]: string } = {
21 code: 'Code',
22 content: 'Content'
23};
24
25export enum FontFormat {
26 woff2 = 'woff2',
27 woff = 'woff'
28}
29
30export type TFontMimeTypes = { [key in FontFormat]: string };
31
32export const FONT_FORMATS = {
33 woff2: 'font/woff2',
34 woff: 'font/woff'
35};
36
37export type TextProperty = 'font-family' | 'font-size' | 'line-height';
38
39export interface IFontCallback {
40 (): Promise<SCHEMA.IFontFacePrimitive[]>;
41}
42
43export interface IFontLicense {
44 name: string;
45 spdx: string;
46 text: () => Promise<string>;
47 holders: string[];
48}
49
50export interface IFontFaceOptions {
51 name: string;
52 faces: IFontCallback;
53 license: IFontLicense;
54}
55
56export const CMD = {
57 code: {
58 fontSize: 'code-font-size',
59 fontFamily: 'code-font-family',
60 lineHeight: 'code-line-height'
61 },
62 content: {
63 fontSize: 'content-font-size',
64 fontFamily: 'content-font-family',
65 lineHeight: 'content-line-height'
66 },
67 editFonts: 'font-editor:open',
68 customFonts: {
69 disable: 'custom-fonts:disable',
70 enable: 'custom-fonts:enable'
71 }
72};
73
74export const ROOT = ':root';
75
76export type ICSSVars = {
77 [key in TextKind]: { [key in TextProperty]: SCHEMA.ICSSOM };
78};
79
80export const CSS: ICSSVars = {
81 code: {
82 'font-family': '--jp-code-font-family',
83 'font-size': '--jp-code-font-size',
84 'line-height': '--jp-code-line-height'
85 },
86 content: {
87 'font-family': '--jp-content-font-family',
88 'font-size': '--jp-content-font-size1',
89 'line-height': '--jp-content-line-height'
90 }
91};
92
93export type ICSSTextOptions = {
94 [key in TextProperty]: (manager: IFontManager) => SCHEMA.ICSSOM[];
95};
96
97export const TEXT_OPTIONS: ICSSTextOptions = {
98 'font-size': _m => Array.from(Array(25).keys()).map(i => `${i + 8}px`),
99 'line-height': _m => Array.from(Array(8).keys()).map(i => `${i * 0.25 + 1}`),
100 'font-family': m => {
101 let names = Array.from(m.fonts.values()).reduce((memo, f) => {
102 return memo.concat(f.name);
103 }, [] as string[]);
104 names.sort((a, b) => a.localeCompare(b));
105 return names;
106 }
107};
108
109export type ICSSTextLabels = { [key in TextProperty]: string };
110
111export const TEXT_LABELS: ICSSTextLabels = {
112 'font-size': 'Size',
113 'line-height': 'Line Height',
114 'font-family': 'Font'
115};
116
117export const DEFAULT = {
118 code: {
119 fontSize: '13px',
120 lineHeight: '1',
121 fontFamily: '"Source Code Pro", monospace'
122 }
123};
124
125export const PACKAGE_NAME: string = '@deathbeds/jupyterlab-fonts';
126export const CONFIGURED_CLASS = 'jp-fonts-configured';
127
128// tslint:disable-next-line
129export const IFontManager = new Token<IFontManager>(
130 '@deathbeds/jupyterlab-fonts:IFontManager'
131);
132
133export interface IFontManagerConstructor {
134 new (
135 commands: CommandRegistry,
136 palette: ICommandPalette,
137 notebooks: INotebookTracker
138 ): IFontManager;
139}
140
141export interface IFontManager {
142 ready: Promise<void>;
143 registerFontFace(options: IFontFaceOptions): void;
144 licensePaneRequested: ISignal<IFontManager, any>;
145 requestLicensePane(font: any): void;
146 fonts: Map<string, IFontFaceOptions>;
147 stylesheets: HTMLStyleElement[];
148 menu: Menu;
149 getVarName(
150 property: TextProperty,
151 options: ITextStyleOptions
152 ): SCHEMA.ICSSOM | null;
153 getTextStyle(
154 property: TextProperty,
155 options: ITextStyleOptions
156 ): SCHEMA.ICSSOM | null;
157 setTextStyle(
158 property: TextProperty,
159 value: SCHEMA.ICSSOM | null,
160 options: ITextStyleOptions
161 ): void;
162 dataURISrc(url: string, format: FontFormat): Promise<string>;
163}
164
165export interface ITextStyleOptions {
166 kind: TextKind;
167 scope?: Scope;
168 notebook?: NotebookPanel;
169}