@ckeditor/ckeditor5-font 39.0.2 → 40.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/font.js.map +1 -0
- package/package.json +2 -2
- package/src/augmentation.d.ts +58 -58
- package/src/augmentation.js +5 -5
- package/src/font.d.ts +33 -33
- package/src/font.js +37 -37
- package/src/fontbackgroundcolor/fontbackgroundcolorcommand.d.ts +26 -26
- package/src/fontbackgroundcolor/fontbackgroundcolorcommand.js +25 -25
- package/src/fontbackgroundcolor/fontbackgroundcolorediting.d.ts +26 -26
- package/src/fontbackgroundcolor/fontbackgroundcolorediting.js +123 -123
- package/src/fontbackgroundcolor/fontbackgroundcolorui.d.ts +22 -22
- package/src/fontbackgroundcolor/fontbackgroundcolorui.js +33 -33
- package/src/fontbackgroundcolor.d.ts +30 -30
- package/src/fontbackgroundcolor.js +34 -34
- package/src/fontcolor/fontcolorcommand.d.ts +25 -25
- package/src/fontcolor/fontcolorcommand.js +24 -24
- package/src/fontcolor/fontcolorediting.d.ts +26 -26
- package/src/fontcolor/fontcolorediting.js +134 -134
- package/src/fontcolor/fontcolorui.d.ts +22 -22
- package/src/fontcolor/fontcolorui.js +33 -33
- package/src/fontcolor.d.ts +29 -29
- package/src/fontcolor.js +33 -33
- package/src/fontcommand.d.ts +48 -48
- package/src/fontcommand.js +79 -79
- package/src/fontconfig.d.ts +373 -373
- package/src/fontconfig.js +5 -5
- package/src/fontfamily/fontfamilycommand.d.ts +25 -25
- package/src/fontfamily/fontfamilycommand.js +24 -24
- package/src/fontfamily/fontfamilyediting.d.ts +39 -39
- package/src/fontfamily/fontfamilyediting.js +115 -115
- package/src/fontfamily/fontfamilyui.d.ts +30 -30
- package/src/fontfamily/fontfamilyui.js +114 -114
- package/src/fontfamily/utils.d.ts +15 -15
- package/src/fontfamily/utils.js +80 -80
- package/src/fontfamily.d.ts +29 -29
- package/src/fontfamily.js +33 -33
- package/src/fontsize/fontsizecommand.d.ts +25 -25
- package/src/fontsize/fontsizecommand.js +24 -24
- package/src/fontsize/fontsizeediting.d.ts +44 -44
- package/src/fontsize/fontsizeediting.js +165 -165
- package/src/fontsize/fontsizeui.d.ts +31 -31
- package/src/fontsize/fontsizeui.js +122 -122
- package/src/fontsize/utils.d.ts +12 -12
- package/src/fontsize/utils.js +166 -166
- package/src/fontsize.d.ts +37 -37
- package/src/fontsize.js +43 -43
- package/src/index.d.ts +27 -27
- package/src/index.js +21 -21
- package/src/ui/colorui.d.ts +68 -68
- package/src/ui/colorui.js +130 -130
- package/src/utils.d.ts +80 -80
- package/src/utils.js +97 -97
|
@@ -1,114 +1,114 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module font/fontfamily/fontfamilyui
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
-
import { Collection } from 'ckeditor5/src/utils';
|
|
10
|
-
import { Model, createDropdown, addListToDropdown } from 'ckeditor5/src/ui';
|
|
11
|
-
import { normalizeOptions } from './utils';
|
|
12
|
-
import { FONT_FAMILY } from '../utils';
|
|
13
|
-
import fontFamilyIcon from '../../theme/icons/font-family.svg';
|
|
14
|
-
/**
|
|
15
|
-
* The font family UI plugin. It introduces the `'fontFamily'` dropdown.
|
|
16
|
-
*/
|
|
17
|
-
export default class FontFamilyUI extends Plugin {
|
|
18
|
-
/**
|
|
19
|
-
* @inheritDoc
|
|
20
|
-
*/
|
|
21
|
-
static get pluginName() {
|
|
22
|
-
return 'FontFamilyUI';
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* @inheritDoc
|
|
26
|
-
*/
|
|
27
|
-
init() {
|
|
28
|
-
const editor = this.editor;
|
|
29
|
-
const t = editor.t;
|
|
30
|
-
const options = this._getLocalizedOptions();
|
|
31
|
-
const command = editor.commands.get(FONT_FAMILY);
|
|
32
|
-
const accessibleLabel = t('Font Family');
|
|
33
|
-
// Register UI component.
|
|
34
|
-
editor.ui.componentFactory.add(FONT_FAMILY, locale => {
|
|
35
|
-
const dropdownView = createDropdown(locale);
|
|
36
|
-
addListToDropdown(dropdownView, () => _prepareListOptions(options, command), {
|
|
37
|
-
role: 'menu',
|
|
38
|
-
ariaLabel: accessibleLabel
|
|
39
|
-
});
|
|
40
|
-
dropdownView.buttonView.set({
|
|
41
|
-
label: accessibleLabel,
|
|
42
|
-
icon: fontFamilyIcon,
|
|
43
|
-
tooltip: true
|
|
44
|
-
});
|
|
45
|
-
dropdownView.extendTemplate({
|
|
46
|
-
attributes: {
|
|
47
|
-
class: 'ck-font-family-dropdown'
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
dropdownView.bind('isEnabled').to(command);
|
|
51
|
-
// Execute command when an item from the dropdown is selected.
|
|
52
|
-
this.listenTo(dropdownView, 'execute', evt => {
|
|
53
|
-
editor.execute(evt.source.commandName, { value: evt.source.commandParam });
|
|
54
|
-
editor.editing.view.focus();
|
|
55
|
-
});
|
|
56
|
-
return dropdownView;
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Returns options as defined in `config.fontFamily.options` but processed to account for
|
|
61
|
-
* editor localization, i.e. to display {@link module:font/fontconfig~FontFamilyOption}
|
|
62
|
-
* in the correct language.
|
|
63
|
-
*
|
|
64
|
-
* Note: The reason behind this method is that there is no way to use {@link module:utils/locale~Locale#t}
|
|
65
|
-
* when the user configuration is defined because the editor does not exist yet.
|
|
66
|
-
*/
|
|
67
|
-
_getLocalizedOptions() {
|
|
68
|
-
const editor = this.editor;
|
|
69
|
-
const t = editor.t;
|
|
70
|
-
const options = normalizeOptions((editor.config.get(FONT_FAMILY)).options);
|
|
71
|
-
return options.map(option => {
|
|
72
|
-
// The only title to localize is "Default" others are font names.
|
|
73
|
-
if (option.title === 'Default') {
|
|
74
|
-
option.title = t('Default');
|
|
75
|
-
}
|
|
76
|
-
return option;
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Prepares FontFamily dropdown items.
|
|
82
|
-
*/
|
|
83
|
-
function _prepareListOptions(options, command) {
|
|
84
|
-
const itemDefinitions = new Collection();
|
|
85
|
-
// Create dropdown items.
|
|
86
|
-
for (const option of options) {
|
|
87
|
-
const def = {
|
|
88
|
-
type: 'button',
|
|
89
|
-
model: new Model({
|
|
90
|
-
commandName: FONT_FAMILY,
|
|
91
|
-
commandParam: option.model,
|
|
92
|
-
label: option.title,
|
|
93
|
-
role: 'menuitemradio',
|
|
94
|
-
withText: true
|
|
95
|
-
})
|
|
96
|
-
};
|
|
97
|
-
def.model.bind('isOn').to(command, 'value', value => {
|
|
98
|
-
// "Default" or check in strict font-family converters mode.
|
|
99
|
-
if (value === option.model) {
|
|
100
|
-
return true;
|
|
101
|
-
}
|
|
102
|
-
if (!value || !option.model) {
|
|
103
|
-
return false;
|
|
104
|
-
}
|
|
105
|
-
return value.split(',')[0].replace(/'/g, '').toLowerCase() === option.model.toLowerCase();
|
|
106
|
-
});
|
|
107
|
-
// Try to set a dropdown list item style.
|
|
108
|
-
if (option.view && typeof option.view !== 'string' && option.view.styles) {
|
|
109
|
-
def.model.set('labelStyle', `font-family: ${option.view.styles['font-family']}`);
|
|
110
|
-
}
|
|
111
|
-
itemDefinitions.add(def);
|
|
112
|
-
}
|
|
113
|
-
return itemDefinitions;
|
|
114
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module font/fontfamily/fontfamilyui
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
+
import { Collection } from 'ckeditor5/src/utils';
|
|
10
|
+
import { Model, createDropdown, addListToDropdown } from 'ckeditor5/src/ui';
|
|
11
|
+
import { normalizeOptions } from './utils';
|
|
12
|
+
import { FONT_FAMILY } from '../utils';
|
|
13
|
+
import fontFamilyIcon from '../../theme/icons/font-family.svg';
|
|
14
|
+
/**
|
|
15
|
+
* The font family UI plugin. It introduces the `'fontFamily'` dropdown.
|
|
16
|
+
*/
|
|
17
|
+
export default class FontFamilyUI extends Plugin {
|
|
18
|
+
/**
|
|
19
|
+
* @inheritDoc
|
|
20
|
+
*/
|
|
21
|
+
static get pluginName() {
|
|
22
|
+
return 'FontFamilyUI';
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @inheritDoc
|
|
26
|
+
*/
|
|
27
|
+
init() {
|
|
28
|
+
const editor = this.editor;
|
|
29
|
+
const t = editor.t;
|
|
30
|
+
const options = this._getLocalizedOptions();
|
|
31
|
+
const command = editor.commands.get(FONT_FAMILY);
|
|
32
|
+
const accessibleLabel = t('Font Family');
|
|
33
|
+
// Register UI component.
|
|
34
|
+
editor.ui.componentFactory.add(FONT_FAMILY, locale => {
|
|
35
|
+
const dropdownView = createDropdown(locale);
|
|
36
|
+
addListToDropdown(dropdownView, () => _prepareListOptions(options, command), {
|
|
37
|
+
role: 'menu',
|
|
38
|
+
ariaLabel: accessibleLabel
|
|
39
|
+
});
|
|
40
|
+
dropdownView.buttonView.set({
|
|
41
|
+
label: accessibleLabel,
|
|
42
|
+
icon: fontFamilyIcon,
|
|
43
|
+
tooltip: true
|
|
44
|
+
});
|
|
45
|
+
dropdownView.extendTemplate({
|
|
46
|
+
attributes: {
|
|
47
|
+
class: 'ck-font-family-dropdown'
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
dropdownView.bind('isEnabled').to(command);
|
|
51
|
+
// Execute command when an item from the dropdown is selected.
|
|
52
|
+
this.listenTo(dropdownView, 'execute', evt => {
|
|
53
|
+
editor.execute(evt.source.commandName, { value: evt.source.commandParam });
|
|
54
|
+
editor.editing.view.focus();
|
|
55
|
+
});
|
|
56
|
+
return dropdownView;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Returns options as defined in `config.fontFamily.options` but processed to account for
|
|
61
|
+
* editor localization, i.e. to display {@link module:font/fontconfig~FontFamilyOption}
|
|
62
|
+
* in the correct language.
|
|
63
|
+
*
|
|
64
|
+
* Note: The reason behind this method is that there is no way to use {@link module:utils/locale~Locale#t}
|
|
65
|
+
* when the user configuration is defined because the editor does not exist yet.
|
|
66
|
+
*/
|
|
67
|
+
_getLocalizedOptions() {
|
|
68
|
+
const editor = this.editor;
|
|
69
|
+
const t = editor.t;
|
|
70
|
+
const options = normalizeOptions((editor.config.get(FONT_FAMILY)).options);
|
|
71
|
+
return options.map(option => {
|
|
72
|
+
// The only title to localize is "Default" others are font names.
|
|
73
|
+
if (option.title === 'Default') {
|
|
74
|
+
option.title = t('Default');
|
|
75
|
+
}
|
|
76
|
+
return option;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Prepares FontFamily dropdown items.
|
|
82
|
+
*/
|
|
83
|
+
function _prepareListOptions(options, command) {
|
|
84
|
+
const itemDefinitions = new Collection();
|
|
85
|
+
// Create dropdown items.
|
|
86
|
+
for (const option of options) {
|
|
87
|
+
const def = {
|
|
88
|
+
type: 'button',
|
|
89
|
+
model: new Model({
|
|
90
|
+
commandName: FONT_FAMILY,
|
|
91
|
+
commandParam: option.model,
|
|
92
|
+
label: option.title,
|
|
93
|
+
role: 'menuitemradio',
|
|
94
|
+
withText: true
|
|
95
|
+
})
|
|
96
|
+
};
|
|
97
|
+
def.model.bind('isOn').to(command, 'value', value => {
|
|
98
|
+
// "Default" or check in strict font-family converters mode.
|
|
99
|
+
if (value === option.model) {
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
if (!value || !option.model) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
return value.split(',')[0].replace(/'/g, '').toLowerCase() === option.model.toLowerCase();
|
|
106
|
+
});
|
|
107
|
+
// Try to set a dropdown list item style.
|
|
108
|
+
if (option.view && typeof option.view !== 'string' && option.view.styles) {
|
|
109
|
+
def.model.set('labelStyle', `font-family: ${option.view.styles['font-family']}`);
|
|
110
|
+
}
|
|
111
|
+
itemDefinitions.add(def);
|
|
112
|
+
}
|
|
113
|
+
return itemDefinitions;
|
|
114
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
import type { FontFamilyOption } from '../fontconfig';
|
|
6
|
-
/**
|
|
7
|
-
* @module font/fontfamily/utils
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Normalizes the {@link module:font/fontconfig~FontFamilyConfig#options configuration options}
|
|
11
|
-
* to the {@link module:font/fontconfig~FontFamilyOption} format.
|
|
12
|
-
*
|
|
13
|
-
* @param configuredOptions An array of options taken from the configuration.
|
|
14
|
-
*/
|
|
15
|
-
export declare function normalizeOptions(configuredOptions: Array<string | FontFamilyOption>): Array<FontFamilyOption>;
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
import type { FontFamilyOption } from '../fontconfig';
|
|
6
|
+
/**
|
|
7
|
+
* @module font/fontfamily/utils
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Normalizes the {@link module:font/fontconfig~FontFamilyConfig#options configuration options}
|
|
11
|
+
* to the {@link module:font/fontconfig~FontFamilyOption} format.
|
|
12
|
+
*
|
|
13
|
+
* @param configuredOptions An array of options taken from the configuration.
|
|
14
|
+
*/
|
|
15
|
+
export declare function normalizeOptions(configuredOptions: Array<string | FontFamilyOption>): Array<FontFamilyOption>;
|
package/src/fontfamily/utils.js
CHANGED
|
@@ -1,80 +1,80 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module font/fontfamily/utils
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Normalizes the {@link module:font/fontconfig~FontFamilyConfig#options configuration options}
|
|
10
|
-
* to the {@link module:font/fontconfig~FontFamilyOption} format.
|
|
11
|
-
*
|
|
12
|
-
* @param configuredOptions An array of options taken from the configuration.
|
|
13
|
-
*/
|
|
14
|
-
export function normalizeOptions(configuredOptions) {
|
|
15
|
-
// Convert options to objects.
|
|
16
|
-
return configuredOptions
|
|
17
|
-
.map(getOptionDefinition)
|
|
18
|
-
// Filter out undefined values that `getOptionDefinition` might return.
|
|
19
|
-
.filter(option => option !== undefined);
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Returns an option definition either created from string shortcut.
|
|
23
|
-
* If object is passed then this method will return it without alternating it. Returns undefined for item than cannot be parsed.
|
|
24
|
-
*
|
|
25
|
-
*/
|
|
26
|
-
function getOptionDefinition(option) {
|
|
27
|
-
// Treat any object as full item definition provided by user in configuration.
|
|
28
|
-
if (typeof option === 'object') {
|
|
29
|
-
return option;
|
|
30
|
-
}
|
|
31
|
-
// Handle 'default' string as a special case. It will be used to remove the fontFamily attribute.
|
|
32
|
-
if (option === 'default') {
|
|
33
|
-
return {
|
|
34
|
-
title: 'Default',
|
|
35
|
-
model: undefined
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
// Ignore values that we cannot parse to a definition.
|
|
39
|
-
if (typeof option !== 'string') {
|
|
40
|
-
return undefined;
|
|
41
|
-
}
|
|
42
|
-
// Return font family definition from font string.
|
|
43
|
-
return generateFontPreset(option);
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Creates a predefined preset for pixel size. It deconstructs font-family like string into full configuration option.
|
|
47
|
-
* A font definition is passed as coma delimited set of font family names. Font names might be quoted.
|
|
48
|
-
*
|
|
49
|
-
* @param fontDefinition A font definition form configuration.
|
|
50
|
-
*/
|
|
51
|
-
function generateFontPreset(fontDefinition) {
|
|
52
|
-
// Remove quotes from font names. They will be normalized later.
|
|
53
|
-
const fontNames = fontDefinition.replace(/"|'/g, '').split(',');
|
|
54
|
-
// The first matched font name will be used as dropdown list item title and as model value.
|
|
55
|
-
const firstFontName = fontNames[0];
|
|
56
|
-
// CSS-compatible font names.
|
|
57
|
-
const cssFontNames = fontNames.map(normalizeFontNameForCSS).join(', ');
|
|
58
|
-
return {
|
|
59
|
-
title: firstFontName,
|
|
60
|
-
model: cssFontNames,
|
|
61
|
-
view: {
|
|
62
|
-
name: 'span',
|
|
63
|
-
styles: {
|
|
64
|
-
'font-family': cssFontNames
|
|
65
|
-
},
|
|
66
|
-
priority: 7
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Normalizes font name for the style attribute. It adds braces (') if font name contains spaces.
|
|
72
|
-
*/
|
|
73
|
-
function normalizeFontNameForCSS(fontName) {
|
|
74
|
-
fontName = fontName.trim();
|
|
75
|
-
// Compound font names should be quoted.
|
|
76
|
-
if (fontName.indexOf(' ') > 0) {
|
|
77
|
-
fontName = `'${fontName}'`;
|
|
78
|
-
}
|
|
79
|
-
return fontName;
|
|
80
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module font/fontfamily/utils
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Normalizes the {@link module:font/fontconfig~FontFamilyConfig#options configuration options}
|
|
10
|
+
* to the {@link module:font/fontconfig~FontFamilyOption} format.
|
|
11
|
+
*
|
|
12
|
+
* @param configuredOptions An array of options taken from the configuration.
|
|
13
|
+
*/
|
|
14
|
+
export function normalizeOptions(configuredOptions) {
|
|
15
|
+
// Convert options to objects.
|
|
16
|
+
return configuredOptions
|
|
17
|
+
.map(getOptionDefinition)
|
|
18
|
+
// Filter out undefined values that `getOptionDefinition` might return.
|
|
19
|
+
.filter(option => option !== undefined);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Returns an option definition either created from string shortcut.
|
|
23
|
+
* If object is passed then this method will return it without alternating it. Returns undefined for item than cannot be parsed.
|
|
24
|
+
*
|
|
25
|
+
*/
|
|
26
|
+
function getOptionDefinition(option) {
|
|
27
|
+
// Treat any object as full item definition provided by user in configuration.
|
|
28
|
+
if (typeof option === 'object') {
|
|
29
|
+
return option;
|
|
30
|
+
}
|
|
31
|
+
// Handle 'default' string as a special case. It will be used to remove the fontFamily attribute.
|
|
32
|
+
if (option === 'default') {
|
|
33
|
+
return {
|
|
34
|
+
title: 'Default',
|
|
35
|
+
model: undefined
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
// Ignore values that we cannot parse to a definition.
|
|
39
|
+
if (typeof option !== 'string') {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
// Return font family definition from font string.
|
|
43
|
+
return generateFontPreset(option);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Creates a predefined preset for pixel size. It deconstructs font-family like string into full configuration option.
|
|
47
|
+
* A font definition is passed as coma delimited set of font family names. Font names might be quoted.
|
|
48
|
+
*
|
|
49
|
+
* @param fontDefinition A font definition form configuration.
|
|
50
|
+
*/
|
|
51
|
+
function generateFontPreset(fontDefinition) {
|
|
52
|
+
// Remove quotes from font names. They will be normalized later.
|
|
53
|
+
const fontNames = fontDefinition.replace(/"|'/g, '').split(',');
|
|
54
|
+
// The first matched font name will be used as dropdown list item title and as model value.
|
|
55
|
+
const firstFontName = fontNames[0];
|
|
56
|
+
// CSS-compatible font names.
|
|
57
|
+
const cssFontNames = fontNames.map(normalizeFontNameForCSS).join(', ');
|
|
58
|
+
return {
|
|
59
|
+
title: firstFontName,
|
|
60
|
+
model: cssFontNames,
|
|
61
|
+
view: {
|
|
62
|
+
name: 'span',
|
|
63
|
+
styles: {
|
|
64
|
+
'font-family': cssFontNames
|
|
65
|
+
},
|
|
66
|
+
priority: 7
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Normalizes font name for the style attribute. It adds braces (') if font name contains spaces.
|
|
72
|
+
*/
|
|
73
|
+
function normalizeFontNameForCSS(fontName) {
|
|
74
|
+
fontName = fontName.trim();
|
|
75
|
+
// Compound font names should be quoted.
|
|
76
|
+
if (fontName.indexOf(' ') > 0) {
|
|
77
|
+
fontName = `'${fontName}'`;
|
|
78
|
+
}
|
|
79
|
+
return fontName;
|
|
80
|
+
}
|
package/src/fontfamily.d.ts
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module font/fontfamily
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
-
import FontFamilyEditing from './fontfamily/fontfamilyediting';
|
|
10
|
-
import FontFamilyUI from './fontfamily/fontfamilyui';
|
|
11
|
-
/**
|
|
12
|
-
* The font family plugin.
|
|
13
|
-
*
|
|
14
|
-
* For a detailed overview, check the {@glink features/font font feature} documentatiom
|
|
15
|
-
* and the {@glink api/font package page}.
|
|
16
|
-
*
|
|
17
|
-
* This is a "glue" plugin which loads the {@link module:font/fontfamily/fontfamilyediting~FontFamilyEditing} and
|
|
18
|
-
* {@link module:font/fontfamily/fontfamilyui~FontFamilyUI} features in the editor.
|
|
19
|
-
*/
|
|
20
|
-
export default class FontFamily extends Plugin {
|
|
21
|
-
/**
|
|
22
|
-
* @inheritDoc
|
|
23
|
-
*/
|
|
24
|
-
static get requires(): readonly [typeof FontFamilyEditing, typeof FontFamilyUI];
|
|
25
|
-
/**
|
|
26
|
-
* @inheritDoc
|
|
27
|
-
*/
|
|
28
|
-
static get pluginName(): "FontFamily";
|
|
29
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module font/fontfamily
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
+
import FontFamilyEditing from './fontfamily/fontfamilyediting';
|
|
10
|
+
import FontFamilyUI from './fontfamily/fontfamilyui';
|
|
11
|
+
/**
|
|
12
|
+
* The font family plugin.
|
|
13
|
+
*
|
|
14
|
+
* For a detailed overview, check the {@glink features/font font feature} documentatiom
|
|
15
|
+
* and the {@glink api/font package page}.
|
|
16
|
+
*
|
|
17
|
+
* This is a "glue" plugin which loads the {@link module:font/fontfamily/fontfamilyediting~FontFamilyEditing} and
|
|
18
|
+
* {@link module:font/fontfamily/fontfamilyui~FontFamilyUI} features in the editor.
|
|
19
|
+
*/
|
|
20
|
+
export default class FontFamily extends Plugin {
|
|
21
|
+
/**
|
|
22
|
+
* @inheritDoc
|
|
23
|
+
*/
|
|
24
|
+
static get requires(): readonly [typeof FontFamilyEditing, typeof FontFamilyUI];
|
|
25
|
+
/**
|
|
26
|
+
* @inheritDoc
|
|
27
|
+
*/
|
|
28
|
+
static get pluginName(): "FontFamily";
|
|
29
|
+
}
|
package/src/fontfamily.js
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module font/fontfamily
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
-
import FontFamilyEditing from './fontfamily/fontfamilyediting';
|
|
10
|
-
import FontFamilyUI from './fontfamily/fontfamilyui';
|
|
11
|
-
/**
|
|
12
|
-
* The font family plugin.
|
|
13
|
-
*
|
|
14
|
-
* For a detailed overview, check the {@glink features/font font feature} documentatiom
|
|
15
|
-
* and the {@glink api/font package page}.
|
|
16
|
-
*
|
|
17
|
-
* This is a "glue" plugin which loads the {@link module:font/fontfamily/fontfamilyediting~FontFamilyEditing} and
|
|
18
|
-
* {@link module:font/fontfamily/fontfamilyui~FontFamilyUI} features in the editor.
|
|
19
|
-
*/
|
|
20
|
-
export default class FontFamily extends Plugin {
|
|
21
|
-
/**
|
|
22
|
-
* @inheritDoc
|
|
23
|
-
*/
|
|
24
|
-
static get requires() {
|
|
25
|
-
return [FontFamilyEditing, FontFamilyUI];
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* @inheritDoc
|
|
29
|
-
*/
|
|
30
|
-
static get pluginName() {
|
|
31
|
-
return 'FontFamily';
|
|
32
|
-
}
|
|
33
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module font/fontfamily
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
+
import FontFamilyEditing from './fontfamily/fontfamilyediting';
|
|
10
|
+
import FontFamilyUI from './fontfamily/fontfamilyui';
|
|
11
|
+
/**
|
|
12
|
+
* The font family plugin.
|
|
13
|
+
*
|
|
14
|
+
* For a detailed overview, check the {@glink features/font font feature} documentatiom
|
|
15
|
+
* and the {@glink api/font package page}.
|
|
16
|
+
*
|
|
17
|
+
* This is a "glue" plugin which loads the {@link module:font/fontfamily/fontfamilyediting~FontFamilyEditing} and
|
|
18
|
+
* {@link module:font/fontfamily/fontfamilyui~FontFamilyUI} features in the editor.
|
|
19
|
+
*/
|
|
20
|
+
export default class FontFamily extends Plugin {
|
|
21
|
+
/**
|
|
22
|
+
* @inheritDoc
|
|
23
|
+
*/
|
|
24
|
+
static get requires() {
|
|
25
|
+
return [FontFamilyEditing, FontFamilyUI];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* @inheritDoc
|
|
29
|
+
*/
|
|
30
|
+
static get pluginName() {
|
|
31
|
+
return 'FontFamily';
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module font/fontsize/fontsizecommand
|
|
7
|
-
*/
|
|
8
|
-
import type { Editor } from 'ckeditor5/src/core';
|
|
9
|
-
import FontCommand from '../fontcommand';
|
|
10
|
-
/**
|
|
11
|
-
* The font size command. It is used by {@link module:font/fontsize/fontsizeediting~FontSizeEditing}
|
|
12
|
-
* to apply the font size.
|
|
13
|
-
*
|
|
14
|
-
* ```ts
|
|
15
|
-
* editor.execute( 'fontSize', { value: 'small' } );
|
|
16
|
-
* ```
|
|
17
|
-
*
|
|
18
|
-
* **Note**: Executing the command without the value removes the attribute from the model.
|
|
19
|
-
*/
|
|
20
|
-
export default class FontSizeCommand extends FontCommand {
|
|
21
|
-
/**
|
|
22
|
-
* @inheritDoc
|
|
23
|
-
*/
|
|
24
|
-
constructor(editor: Editor);
|
|
25
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module font/fontsize/fontsizecommand
|
|
7
|
+
*/
|
|
8
|
+
import type { Editor } from 'ckeditor5/src/core';
|
|
9
|
+
import FontCommand from '../fontcommand';
|
|
10
|
+
/**
|
|
11
|
+
* The font size command. It is used by {@link module:font/fontsize/fontsizeediting~FontSizeEditing}
|
|
12
|
+
* to apply the font size.
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* editor.execute( 'fontSize', { value: 'small' } );
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* **Note**: Executing the command without the value removes the attribute from the model.
|
|
19
|
+
*/
|
|
20
|
+
export default class FontSizeCommand extends FontCommand {
|
|
21
|
+
/**
|
|
22
|
+
* @inheritDoc
|
|
23
|
+
*/
|
|
24
|
+
constructor(editor: Editor);
|
|
25
|
+
}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
import FontCommand from '../fontcommand';
|
|
6
|
-
import { FONT_SIZE } from '../utils';
|
|
7
|
-
/**
|
|
8
|
-
* The font size command. It is used by {@link module:font/fontsize/fontsizeediting~FontSizeEditing}
|
|
9
|
-
* to apply the font size.
|
|
10
|
-
*
|
|
11
|
-
* ```ts
|
|
12
|
-
* editor.execute( 'fontSize', { value: 'small' } );
|
|
13
|
-
* ```
|
|
14
|
-
*
|
|
15
|
-
* **Note**: Executing the command without the value removes the attribute from the model.
|
|
16
|
-
*/
|
|
17
|
-
export default class FontSizeCommand extends FontCommand {
|
|
18
|
-
/**
|
|
19
|
-
* @inheritDoc
|
|
20
|
-
*/
|
|
21
|
-
constructor(editor) {
|
|
22
|
-
super(editor, FONT_SIZE);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
import FontCommand from '../fontcommand';
|
|
6
|
+
import { FONT_SIZE } from '../utils';
|
|
7
|
+
/**
|
|
8
|
+
* The font size command. It is used by {@link module:font/fontsize/fontsizeediting~FontSizeEditing}
|
|
9
|
+
* to apply the font size.
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* editor.execute( 'fontSize', { value: 'small' } );
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* **Note**: Executing the command without the value removes the attribute from the model.
|
|
16
|
+
*/
|
|
17
|
+
export default class FontSizeCommand extends FontCommand {
|
|
18
|
+
/**
|
|
19
|
+
* @inheritDoc
|
|
20
|
+
*/
|
|
21
|
+
constructor(editor) {
|
|
22
|
+
super(editor, FONT_SIZE);
|
|
23
|
+
}
|
|
24
|
+
}
|