-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
fontconfig.ts
397 lines (373 loc) · 10.4 KB
/
fontconfig.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
/**
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/
/**
* @module font/fontconfig
*/
import type { ColorOption, ColorPickerConfig } from 'ckeditor5/src/ui.js';
import type { MatcherPattern, ViewElementDefinition } from 'ckeditor5/src/engine.js';
/**
* The configuration of the font color and font background color features.
* This option is used by the {@link module:font/fontcolor/fontcolorediting~FontColorEditing} and
* {@link module:font/fontbackgroundcolor/fontbackgroundcolorediting~FontBackgroundColorEditing} features.
*
* ```ts
* ClassicEditor
* .create( {
* fontColor: ... // Font color feature configuration.
* fontBackgroundColor: ... // Font background color feature configuration.
* } )
* .then( ... )
* .catch( ... );
* ```
*
* See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
*/
export interface FontColorConfig {
/**
* Available font colors defined as an array of strings or objects.
*
* The default value registers the following colors:
*
* ```ts
* const fontColorConfig = {
* colors: [
* {
* color: 'hsl(0, 0%, 0%)',
* label: 'Black'
* },
* {
* color: 'hsl(0, 0%, 30%)',
* label: 'Dim grey'
* },
* {
* color: 'hsl(0, 0%, 60%)',
* label: 'Grey'
* },
* {
* color: 'hsl(0, 0%, 90%)',
* label: 'Light grey'
* },
* {
* color: 'hsl(0, 0%, 100%)',
* label: 'White',
* hasBorder: true
* },
* {
* color: 'hsl(0, 75%, 60%)',
* label: 'Red'
* },
* {
* color: 'hsl(30, 75%, 60%)',
* label: 'Orange'
* },
* {
* color: 'hsl(60, 75%, 60%)',
* label: 'Yellow'
* },
* {
* color: 'hsl(90, 75%, 60%)',
* label: 'Light green'
* },
* {
* color: 'hsl(120, 75%, 60%)',
* label: 'Green'
* },
* {
* color: 'hsl(150, 75%, 60%)',
* label: 'Aquamarine'
* },
* {
* color: 'hsl(180, 75%, 60%)',
* label: 'Turquoise'
* },
* {
* color: 'hsl(210, 75%, 60%)',
* label: 'Light blue'
* },
* {
* color: 'hsl(240, 75%, 60%)',
* label: 'Blue'
* },
* {
* color: 'hsl(270, 75%, 60%)',
* label: 'Purple'
* }
* ]
* };
* ```
*
* **Note**: The colors are displayed in the `'fontColor'` dropdown.
*/
colors?: Array<string | ColorOption>;
/**
* Determines the maximum number of available document colors.
* Setting it to `0` will disable the document colors feature.
*
* By default it equals to the {@link module:font/fontconfig~FontColorConfig#columns} value.
*
* Examples:
*
* ```ts
* // 1) Neither document colors nor columns are defined in the configuration.
* // Document colors will equal 5,
* // because the value will be inherited from columns,
* // which has a predefined value of 5.
* const fontColorConfig = {}
*
* // 2) Document colors will equal 8, because the value will be inherited from columns.
* const fontColorConfig = {
* columns: 8
* }
*
* // 3) Document colors will equal 24, because it has its own value defined.
* const fontColorConfig = {
* columns: 8,
* documentColors: 24
* }
*
* // 4) The document colors feature will be disabled.
* const fontColorConfig = {
* columns: 8,
* documentColors: 0
* }
* ```
*/
documentColors?: number;
/**
* Represents the number of columns in the font color dropdown.
*
* The default value is:
*
* ```ts
* const fontColorConfig = {
* columns: 5
* }
* ```
*/
columns?: number;
/**
* Configuration of the color picker feature.
*
* If set to `false` the picker will not appear.
*/
colorPicker?: false | ColorPickerConfig;
}
/**
* The configuration of the font family feature.
* This option is used by the {@link module:font/fontfamily/fontfamilyediting~FontFamilyEditing} feature.
*
* ```ts
* ClassicEditor
* .create( {
* fontFamily: ... // Font family feature configuration.
* } )
* .then( ... )
* .catch( ... );
* ```
*
* See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
*/
export interface FontFamilyConfig {
/**
* Available font family options defined as an array of strings. The default value is:
*
* ```ts
* const fontFamilyConfig = {
* options: [
* 'default',
* 'Arial, Helvetica, sans-serif',
* 'Courier New, Courier, monospace',
* 'Georgia, serif',
* 'Lucida Sans Unicode, Lucida Grande, sans-serif',
* 'Tahoma, Geneva, sans-serif',
* 'Times New Roman, Times, serif',
* 'Trebuchet MS, Helvetica, sans-serif',
* 'Verdana, Geneva, sans-serif'
* ]
* };
* ```
*
* which configures 8 font family options. Each option consists of one or more comma–separated font family names. The first font name is
* used as the dropdown item description in the UI.
*
* **Note:** The family names that consist of spaces should not have quotes (as opposed to the CSS standard). The necessary quotes
* will be added automatically in the view. For example, the `"Lucida Sans Unicode"` will render as follows:
*
* ```html
* <span style="font-family:'Lucida Sans Unicode', 'Lucida Grande', sans-serif">...</span>
* ```
*
* The "default" option removes the `fontFamily` attribute from the selection. In such case, the text will
* be rendered in the view using the default font family defined in the styles of the web page.
*
* Font family can be applied using the command API. To do that, use the `fontFamily` command and pass the desired family as a `value`.
* For example, the following code will apply the `fontFamily` attribute with the `'Arial'` `value` to the current selection:
*
* ```ts
* editor.execute( 'fontFamily', { value: 'Arial' } );
* ```
*
* Executing the `'fontFamily'` command without any value will remove the `fontFamily` attribute from the current selection.
*/
options?: Array<string | FontFamilyOption>;
/**
* By default the plugin removes any `font-family` value that does not match the plugin's configuration.
* It means that if you paste content with font families that the editor does not understand, the `font-family` attribute
* will be removed and the content will be displayed with the default font.
*
* You can preserve pasted font family values by switching the `supportAllValues` option to `true`:
*
* ```ts
* const fontFamilyConfig = {
* supportAllValues: true
* };
* ```
*
* With this configuration font families not specified in the editor configuration will not be removed when pasting the content.
*/
supportAllValues?: boolean;
}
/**
* The font family option descriptor.
*/
export interface FontFamilyOption {
/**
* The user-readable title of the option.
*/
title: string;
/**
* The attribute's unique value in the model.
*/
model?: string;
/**
* View element configuration.
*/
view?: ViewElementDefinition;
/**
* An array with all matched elements that the view-to-model conversion should also accept.
*/
upcastAlso?: Array<MatcherPattern>;
}
/**
* The configuration of the font size feature.
* This option is used by the {@link module:font/fontsize/fontsizeediting~FontSizeEditing} feature.
*
* ```ts
* ClassicEditor
* .create( {
* fontSize: ... // Font size feature configuration.
* } )
* .then( ... )
* .catch( ... );
* ```
*
* See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
*/
export interface FontSizeConfig {
/**
* Available font size options. Expressed as predefined presets, numerical "pixel" values
* or the {@link module:font/fontconfig~FontSizeOption}.
*
* The default value is:
*
* ```ts
* const fontSizeConfig = {
* options: [
* 'tiny',
* 'small',
* 'default',
* 'big',
* 'huge'
* ]
* };
* ```
*
* It defines 4 sizes: **tiny**, **small**, **big**, and **huge**. These values will be rendered as `<span>` elements in the view.
* The **default** defines a text without the `fontSize` attribute.
*
* Each `<span>` has the the `class` attribute set to the corresponding size name. For instance, this is what the **small** size looks
* like in the view:
*
* ```html
* <span class="text-small">...</span>
* ```
*
* As an alternative, the font size might be defined using numerical values (either as a `Number` or as a `String`):
*
* ```ts
* const fontSizeConfig = {
* options: [ 9, 10, 11, 12, 13, 14, 15 ]
* };
* ```
*
* Also, you can define a label in the dropdown for numerical values:
*
* ```ts
* const fontSizeConfig = {
* options: [
* {
* title: 'Small',
* model: '8px'
* },
* 'default',
* {
* title: 'Big',
* model: '14px'
* }
* ]
* };
* ```
*
* Font size can be applied using the command API. To do that, use the `'fontSize'` command and pass the desired font size as a `value`.
* For example, the following code will apply the `fontSize` attribute with the **tiny** value to the current selection:
*
* ```ts
* editor.execute( 'fontSize', { value: 'tiny' } );
* ```
*
* Executing the `fontSize` command without value will remove the `fontSize` attribute from the current selection.
*/
options?: Array<string | number | FontSizeOption>;
/**
* By default the plugin removes any `font-size` value that does not match the plugin's configuration.
* It means that if you paste content with font sizes that the editor does not understand, the `font-size` attribute
* will be removed and the content will be displayed with the default size.
*
* You can preserve pasted font size values by switching the `supportAllValues` option to `true`:
*
* ```ts
* const fontSizeConfig = {
* options: [ 9, 10, 11, 12, 'default', 14, 15 ],
* supportAllValues: true
* };
* ```
*
* **Note:** This option can only be used with numerical values as font size options.
*
* With this configuration font sizes not specified in the editor configuration will not be removed when pasting the content.
*/
supportAllValues?: boolean;
}
/**
* The font size option descriptor.
*/
export interface FontSizeOption {
/**
* The user-readable title of the option.
*/
title: string;
/**
* The attribute's unique value in the model.
*/
model?: string;
/**
* View element configuration.
*/
view?: ViewElementDefinition;
/**
* An array with all matched elements that the view-to-model conversion should also accept.
*/
upcastAlso?: Array<MatcherPattern>;
}