@ckeditor/ckeditor5-font 47.6.1 → 48.0.0-alpha.1
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/ckeditor5-metadata.json +8 -8
- package/{src → dist}/font.d.ts +1 -1
- package/{src → dist}/fontbackgroundcolor/fontbackgroundcolorcommand.d.ts +1 -1
- package/{src → dist}/fontbackgroundcolor/fontbackgroundcolorediting.d.ts +1 -1
- package/{src → dist}/fontbackgroundcolor/fontbackgroundcolorui.d.ts +1 -1
- package/{src → dist}/fontbackgroundcolor.d.ts +1 -1
- package/{src → dist}/fontcolor/fontcolorcommand.d.ts +1 -1
- package/{src → dist}/fontcolor/fontcolorediting.d.ts +1 -1
- package/{src → dist}/fontcolor/fontcolorui.d.ts +1 -1
- package/{src → dist}/fontcolor.d.ts +1 -1
- package/{src → dist}/fontcommand.d.ts +2 -2
- package/{src → dist}/fontconfig.d.ts +2 -2
- package/{src → dist}/fontfamily/fontfamilycommand.d.ts +1 -1
- package/{src → dist}/fontfamily/fontfamilyediting.d.ts +1 -1
- package/{src → dist}/fontfamily/fontfamilyui.d.ts +1 -1
- package/{src → dist}/fontfamily.d.ts +1 -1
- package/{src → dist}/fontsize/fontsizecommand.d.ts +1 -1
- package/{src → dist}/fontsize/fontsizeediting.d.ts +1 -1
- package/{src → dist}/fontsize/fontsizeui.d.ts +1 -1
- package/{src → dist}/fontsize.d.ts +1 -1
- package/dist/index-content.css +16 -12
- package/dist/index-editor.css +4 -4
- package/dist/index.css +15 -21
- package/dist/index.css.map +1 -1
- package/dist/index.js.map +1 -1
- package/{src → dist}/ui/colorui.d.ts +1 -1
- package/{src → dist}/utils.d.ts +3 -3
- package/package.json +23 -47
- package/build/font.js +0 -5
- package/build/translations/af.js +0 -1
- package/build/translations/ar.js +0 -1
- package/build/translations/ast.js +0 -1
- package/build/translations/az.js +0 -1
- package/build/translations/be.js +0 -1
- package/build/translations/bg.js +0 -1
- package/build/translations/bn.js +0 -1
- package/build/translations/bs.js +0 -1
- package/build/translations/ca.js +0 -1
- package/build/translations/cs.js +0 -1
- package/build/translations/da.js +0 -1
- package/build/translations/de-ch.js +0 -1
- package/build/translations/de.js +0 -1
- package/build/translations/el.js +0 -1
- package/build/translations/en-au.js +0 -1
- package/build/translations/en-gb.js +0 -1
- package/build/translations/eo.js +0 -1
- package/build/translations/es-co.js +0 -1
- package/build/translations/es.js +0 -1
- package/build/translations/et.js +0 -1
- package/build/translations/eu.js +0 -1
- package/build/translations/fa.js +0 -1
- package/build/translations/fi.js +0 -1
- package/build/translations/fr.js +0 -1
- package/build/translations/gl.js +0 -1
- package/build/translations/gu.js +0 -1
- package/build/translations/he.js +0 -1
- package/build/translations/hi.js +0 -1
- package/build/translations/hr.js +0 -1
- package/build/translations/hu.js +0 -1
- package/build/translations/hy.js +0 -1
- package/build/translations/id.js +0 -1
- package/build/translations/it.js +0 -1
- package/build/translations/ja.js +0 -1
- package/build/translations/jv.js +0 -1
- package/build/translations/kk.js +0 -1
- package/build/translations/km.js +0 -1
- package/build/translations/kn.js +0 -1
- package/build/translations/ko.js +0 -1
- package/build/translations/ku.js +0 -1
- package/build/translations/lt.js +0 -1
- package/build/translations/lv.js +0 -1
- package/build/translations/ms.js +0 -1
- package/build/translations/nb.js +0 -1
- package/build/translations/ne.js +0 -1
- package/build/translations/nl.js +0 -1
- package/build/translations/no.js +0 -1
- package/build/translations/oc.js +0 -1
- package/build/translations/pl.js +0 -1
- package/build/translations/pt-br.js +0 -1
- package/build/translations/pt.js +0 -1
- package/build/translations/ro.js +0 -1
- package/build/translations/ru.js +0 -1
- package/build/translations/si.js +0 -1
- package/build/translations/sk.js +0 -1
- package/build/translations/sl.js +0 -1
- package/build/translations/sq.js +0 -1
- package/build/translations/sr-latn.js +0 -1
- package/build/translations/sr.js +0 -1
- package/build/translations/sv.js +0 -1
- package/build/translations/th.js +0 -1
- package/build/translations/ti.js +0 -1
- package/build/translations/tk.js +0 -1
- package/build/translations/tr.js +0 -1
- package/build/translations/tt.js +0 -1
- package/build/translations/ug.js +0 -1
- package/build/translations/uk.js +0 -1
- package/build/translations/ur.js +0 -1
- package/build/translations/uz.js +0 -1
- package/build/translations/vi.js +0 -1
- package/build/translations/zh-cn.js +0 -1
- package/build/translations/zh.js +0 -1
- package/lang/contexts.json +0 -12
- package/lang/translations/af.po +0 -52
- package/lang/translations/ar.po +0 -52
- package/lang/translations/ast.po +0 -52
- package/lang/translations/az.po +0 -52
- package/lang/translations/be.po +0 -52
- package/lang/translations/bg.po +0 -52
- package/lang/translations/bn.po +0 -52
- package/lang/translations/bs.po +0 -52
- package/lang/translations/ca.po +0 -52
- package/lang/translations/cs.po +0 -52
- package/lang/translations/da.po +0 -52
- package/lang/translations/de-ch.po +0 -52
- package/lang/translations/de.po +0 -52
- package/lang/translations/el.po +0 -52
- package/lang/translations/en-au.po +0 -52
- package/lang/translations/en-gb.po +0 -52
- package/lang/translations/en.po +0 -52
- package/lang/translations/eo.po +0 -52
- package/lang/translations/es-co.po +0 -52
- package/lang/translations/es.po +0 -52
- package/lang/translations/et.po +0 -52
- package/lang/translations/eu.po +0 -52
- package/lang/translations/fa.po +0 -52
- package/lang/translations/fi.po +0 -52
- package/lang/translations/fr.po +0 -52
- package/lang/translations/gl.po +0 -52
- package/lang/translations/gu.po +0 -52
- package/lang/translations/he.po +0 -52
- package/lang/translations/hi.po +0 -52
- package/lang/translations/hr.po +0 -52
- package/lang/translations/hu.po +0 -52
- package/lang/translations/hy.po +0 -52
- package/lang/translations/id.po +0 -52
- package/lang/translations/it.po +0 -52
- package/lang/translations/ja.po +0 -52
- package/lang/translations/jv.po +0 -52
- package/lang/translations/kk.po +0 -52
- package/lang/translations/km.po +0 -52
- package/lang/translations/kn.po +0 -52
- package/lang/translations/ko.po +0 -52
- package/lang/translations/ku.po +0 -52
- package/lang/translations/lt.po +0 -52
- package/lang/translations/lv.po +0 -52
- package/lang/translations/ms.po +0 -52
- package/lang/translations/nb.po +0 -52
- package/lang/translations/ne.po +0 -52
- package/lang/translations/nl.po +0 -52
- package/lang/translations/no.po +0 -52
- package/lang/translations/oc.po +0 -52
- package/lang/translations/pl.po +0 -52
- package/lang/translations/pt-br.po +0 -52
- package/lang/translations/pt.po +0 -52
- package/lang/translations/ro.po +0 -52
- package/lang/translations/ru.po +0 -52
- package/lang/translations/si.po +0 -52
- package/lang/translations/sk.po +0 -52
- package/lang/translations/sl.po +0 -52
- package/lang/translations/sq.po +0 -52
- package/lang/translations/sr-latn.po +0 -52
- package/lang/translations/sr.po +0 -52
- package/lang/translations/sv.po +0 -52
- package/lang/translations/th.po +0 -52
- package/lang/translations/ti.po +0 -52
- package/lang/translations/tk.po +0 -52
- package/lang/translations/tr.po +0 -52
- package/lang/translations/tt.po +0 -52
- package/lang/translations/ug.po +0 -52
- package/lang/translations/uk.po +0 -52
- package/lang/translations/ur.po +0 -52
- package/lang/translations/uz.po +0 -52
- package/lang/translations/vi.po +0 -52
- package/lang/translations/zh-cn.po +0 -52
- package/lang/translations/zh.po +0 -52
- package/src/augmentation.js +0 -5
- package/src/font.js +0 -43
- package/src/fontbackgroundcolor/fontbackgroundcolorcommand.js +0 -25
- package/src/fontbackgroundcolor/fontbackgroundcolorediting.js +0 -129
- package/src/fontbackgroundcolor/fontbackgroundcolorui.js +0 -33
- package/src/fontbackgroundcolor.js +0 -40
- package/src/fontcolor/fontcolorcommand.js +0 -24
- package/src/fontcolor/fontcolorediting.js +0 -140
- package/src/fontcolor/fontcolorui.js +0 -33
- package/src/fontcolor.js +0 -39
- package/src/fontcommand.js +0 -92
- package/src/fontconfig.js +0 -5
- package/src/fontfamily/fontfamilycommand.js +0 -24
- package/src/fontfamily/fontfamilyediting.js +0 -121
- package/src/fontfamily/fontfamilyui.js +0 -152
- package/src/fontfamily/utils.js +0 -91
- package/src/fontfamily.js +0 -39
- package/src/fontsize/fontsizecommand.js +0 -24
- package/src/fontsize/fontsizeediting.js +0 -171
- package/src/fontsize/fontsizeui.js +0 -158
- package/src/fontsize/utils.js +0 -167
- package/src/fontsize.js +0 -49
- package/src/index.js +0 -30
- package/src/ui/colorui.js +0 -201
- package/src/utils.js +0 -107
- package/theme/fontsize.css +0 -33
- /package/{src → dist}/augmentation.d.ts +0 -0
- /package/{src → dist}/fontfamily/utils.d.ts +0 -0
- /package/{src → dist}/fontsize/utils.d.ts +0 -0
- /package/{src → dist}/index.d.ts +0 -0
package/src/fontfamily/utils.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
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
|
-
* @internal
|
|
14
|
-
*/
|
|
15
|
-
export function normalizeOptions(configuredOptions) {
|
|
16
|
-
// Convert options to objects.
|
|
17
|
-
return configuredOptions
|
|
18
|
-
.map(getOptionDefinition)
|
|
19
|
-
// Filter out undefined values that `getOptionDefinition` might return.
|
|
20
|
-
.filter(option => option !== undefined);
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Normalizes the CSS `font-family` property value to an array of unquoted and trimmed font faces.
|
|
24
|
-
*
|
|
25
|
-
* @internal
|
|
26
|
-
*/
|
|
27
|
-
export function normalizeFontFamilies(fontDefinition) {
|
|
28
|
-
return fontDefinition
|
|
29
|
-
.replace(/["']/g, '').split(',')
|
|
30
|
-
.map(name => name.trim());
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Returns an option definition either created from string shortcut.
|
|
34
|
-
* If object is passed then this method will return it without alternating it. Returns undefined for item than cannot be parsed.
|
|
35
|
-
*
|
|
36
|
-
*/
|
|
37
|
-
function getOptionDefinition(option) {
|
|
38
|
-
// Treat any object as full item definition provided by user in configuration.
|
|
39
|
-
if (typeof option === 'object') {
|
|
40
|
-
return option;
|
|
41
|
-
}
|
|
42
|
-
// Handle 'default' string as a special case. It will be used to remove the fontFamily attribute.
|
|
43
|
-
if (option === 'default') {
|
|
44
|
-
return {
|
|
45
|
-
title: 'Default',
|
|
46
|
-
model: undefined
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
// Ignore values that we cannot parse to a definition.
|
|
50
|
-
if (typeof option !== 'string') {
|
|
51
|
-
return undefined;
|
|
52
|
-
}
|
|
53
|
-
// Return font family definition from font string.
|
|
54
|
-
return generateFontPreset(option);
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Creates a predefined preset for pixel size. It deconstructs font-family like string into full configuration option.
|
|
58
|
-
* A font definition is passed as coma delimited set of font family names. Font names might be quoted.
|
|
59
|
-
*
|
|
60
|
-
* @param fontDefinition A font definition form configuration.
|
|
61
|
-
*/
|
|
62
|
-
function generateFontPreset(fontDefinition) {
|
|
63
|
-
// Remove quotes from font names. They will be normalized later.
|
|
64
|
-
const fontNames = normalizeFontFamilies(fontDefinition);
|
|
65
|
-
// The first matched font name will be used as dropdown list item title and as model value.
|
|
66
|
-
const firstFontName = fontNames[0];
|
|
67
|
-
// CSS-compatible font names.
|
|
68
|
-
const cssFontNames = fontNames.map(normalizeFontNameForCSS).join(', ');
|
|
69
|
-
return {
|
|
70
|
-
title: firstFontName,
|
|
71
|
-
model: cssFontNames,
|
|
72
|
-
view: {
|
|
73
|
-
name: 'span',
|
|
74
|
-
styles: {
|
|
75
|
-
'font-family': cssFontNames
|
|
76
|
-
},
|
|
77
|
-
priority: 7
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Normalizes font name for the style attribute. It adds braces (') if font name contains spaces.
|
|
83
|
-
*/
|
|
84
|
-
function normalizeFontNameForCSS(fontName) {
|
|
85
|
-
fontName = fontName.trim();
|
|
86
|
-
// Compound font names should be quoted.
|
|
87
|
-
if (fontName.indexOf(' ') > 0) {
|
|
88
|
-
fontName = `'${fontName}'`;
|
|
89
|
-
}
|
|
90
|
-
return fontName;
|
|
91
|
-
}
|
package/src/fontfamily.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module font/fontfamily
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core.js';
|
|
9
|
-
import { FontFamilyEditing } from './fontfamily/fontfamilyediting.js';
|
|
10
|
-
import { FontFamilyUI } from './fontfamily/fontfamilyui.js';
|
|
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 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
|
-
/**
|
|
34
|
-
* @inheritDoc
|
|
35
|
-
*/
|
|
36
|
-
static get isOfficialPlugin() {
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
import { FontCommand } from '../fontcommand.js';
|
|
6
|
-
import { FONT_SIZE } from '../utils.js';
|
|
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 class FontSizeCommand extends FontCommand {
|
|
18
|
-
/**
|
|
19
|
-
* @inheritDoc
|
|
20
|
-
*/
|
|
21
|
-
constructor(editor) {
|
|
22
|
-
super(editor, FONT_SIZE);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module font/fontsize/fontsizeediting
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core.js';
|
|
9
|
-
import { CKEditorError } from 'ckeditor5/src/utils.js';
|
|
10
|
-
import { isLengthStyleValue, isPercentageStyleValue } from 'ckeditor5/src/engine.js';
|
|
11
|
-
import { FontSizeCommand } from './fontsizecommand.js';
|
|
12
|
-
import { normalizeOptions } from './utils.js';
|
|
13
|
-
import { buildDefinition, FONT_SIZE } from '../utils.js';
|
|
14
|
-
// Mapping of `<font size="..">` styling to CSS's `font-size` values.
|
|
15
|
-
const styleFontSize = [
|
|
16
|
-
'x-small', // Size "0" equal to "1".
|
|
17
|
-
'x-small',
|
|
18
|
-
'small',
|
|
19
|
-
'medium',
|
|
20
|
-
'large',
|
|
21
|
-
'x-large',
|
|
22
|
-
'xx-large',
|
|
23
|
-
'xxx-large'
|
|
24
|
-
];
|
|
25
|
-
/**
|
|
26
|
-
* The font size editing feature.
|
|
27
|
-
*
|
|
28
|
-
* It introduces the {@link module:font/fontsize/fontsizecommand~FontSizeCommand command} and the `fontSize`
|
|
29
|
-
* attribute in the {@link module:engine/model/model~Model model} which renders in the {@link module:engine/view/view view}
|
|
30
|
-
* as a `<span>` element with either:
|
|
31
|
-
* * a style attribute (`<span style="font-size:12px">...</span>`),
|
|
32
|
-
* * or a class attribute (`<span class="text-small">...</span>`)
|
|
33
|
-
*
|
|
34
|
-
* depending on the {@link module:font/fontconfig~FontSizeConfig configuration}.
|
|
35
|
-
*/
|
|
36
|
-
export class FontSizeEditing extends Plugin {
|
|
37
|
-
/**
|
|
38
|
-
* @inheritDoc
|
|
39
|
-
*/
|
|
40
|
-
static get pluginName() {
|
|
41
|
-
return 'FontSizeEditing';
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* @inheritDoc
|
|
45
|
-
*/
|
|
46
|
-
static get isOfficialPlugin() {
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* @inheritDoc
|
|
51
|
-
*/
|
|
52
|
-
constructor(editor) {
|
|
53
|
-
super(editor);
|
|
54
|
-
// Define default configuration using named presets.
|
|
55
|
-
editor.config.define(FONT_SIZE, {
|
|
56
|
-
options: [
|
|
57
|
-
'tiny',
|
|
58
|
-
'small',
|
|
59
|
-
'default',
|
|
60
|
-
'big',
|
|
61
|
-
'huge'
|
|
62
|
-
],
|
|
63
|
-
supportAllValues: false
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* @inheritDoc
|
|
68
|
-
*/
|
|
69
|
-
init() {
|
|
70
|
-
const editor = this.editor;
|
|
71
|
-
// Allow fontSize attribute on text nodes.
|
|
72
|
-
editor.model.schema.extend('$text', { allowAttributes: FONT_SIZE });
|
|
73
|
-
editor.model.schema.setAttributeProperties(FONT_SIZE, {
|
|
74
|
-
isFormatting: true,
|
|
75
|
-
copyOnEnter: true
|
|
76
|
-
});
|
|
77
|
-
const supportAllValues = editor.config.get('fontSize.supportAllValues');
|
|
78
|
-
// Define view to model conversion.
|
|
79
|
-
const options = normalizeOptions(this.editor.config.get('fontSize.options'))
|
|
80
|
-
.filter(item => item.model);
|
|
81
|
-
const definition = buildDefinition(FONT_SIZE, options);
|
|
82
|
-
// Set-up the two-way conversion.
|
|
83
|
-
if (supportAllValues) {
|
|
84
|
-
this._prepareAnyValueConverters(definition);
|
|
85
|
-
this._prepareCompatibilityConverter();
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
editor.conversion.attributeToElement(definition);
|
|
89
|
-
}
|
|
90
|
-
// Add FontSize command.
|
|
91
|
-
editor.commands.add(FONT_SIZE, new FontSizeCommand(editor));
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* These converters enable keeping any value found as `style="font-size: *"` as a value of an attribute on a text even
|
|
95
|
-
* if it is not defined in the plugin configuration.
|
|
96
|
-
*
|
|
97
|
-
* @param definition Converter definition out of input data.
|
|
98
|
-
*/
|
|
99
|
-
_prepareAnyValueConverters(definition) {
|
|
100
|
-
const editor = this.editor;
|
|
101
|
-
// If `fontSize.supportAllValues=true`, we do not allow to use named presets in the plugin's configuration.
|
|
102
|
-
const presets = definition.model.values.filter((value) => {
|
|
103
|
-
return !isLengthStyleValue(String(value)) && !isPercentageStyleValue(String(value));
|
|
104
|
-
});
|
|
105
|
-
if (presets.length) {
|
|
106
|
-
/**
|
|
107
|
-
* If {@link module:font/fontconfig~FontSizeConfig#supportAllValues `config.fontSize.supportAllValues`} is `true`,
|
|
108
|
-
* you need to use numerical values as font size options.
|
|
109
|
-
*
|
|
110
|
-
* See valid examples described in the {@link module:font/fontconfig~FontSizeConfig#options plugin configuration}.
|
|
111
|
-
*
|
|
112
|
-
* @error font-size-invalid-use-of-named-presets
|
|
113
|
-
* @param {Array.<string>} presets Invalid values.
|
|
114
|
-
*/
|
|
115
|
-
throw new CKEditorError('font-size-invalid-use-of-named-presets', null, { presets });
|
|
116
|
-
}
|
|
117
|
-
editor.conversion.for('downcast').attributeToElement({
|
|
118
|
-
model: FONT_SIZE,
|
|
119
|
-
view: (attributeValue, { writer }) => {
|
|
120
|
-
if (!attributeValue) {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
return writer.createAttributeElement('span', { style: 'font-size:' + attributeValue }, { priority: 7 });
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
editor.conversion.for('upcast').elementToAttribute({
|
|
127
|
-
model: {
|
|
128
|
-
key: FONT_SIZE,
|
|
129
|
-
value: (viewElement) => viewElement.getStyle('font-size')
|
|
130
|
-
},
|
|
131
|
-
view: {
|
|
132
|
-
name: 'span',
|
|
133
|
-
styles: {
|
|
134
|
-
'font-size': /.*/
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Adds support for legacy `<font size="..">` formatting.
|
|
141
|
-
*/
|
|
142
|
-
_prepareCompatibilityConverter() {
|
|
143
|
-
const editor = this.editor;
|
|
144
|
-
editor.conversion.for('upcast').elementToAttribute({
|
|
145
|
-
view: {
|
|
146
|
-
name: 'font',
|
|
147
|
-
attributes: {
|
|
148
|
-
// Documentation mentions sizes from 1 to 7. To handle old content we support all values
|
|
149
|
-
// up to 999 but clamp it to the valid range. Why 999? It should cover accidental values
|
|
150
|
-
// similar to percentage, e.g. 100%, 200% which could be the usual mistake for font size.
|
|
151
|
-
'size': /^[+-]?\d{1,3}$/
|
|
152
|
-
}
|
|
153
|
-
},
|
|
154
|
-
model: {
|
|
155
|
-
key: FONT_SIZE,
|
|
156
|
-
value: (viewElement) => {
|
|
157
|
-
const value = viewElement.getAttribute('size');
|
|
158
|
-
const isRelative = value[0] === '-' || value[0] === '+';
|
|
159
|
-
let size = parseInt(value, 10);
|
|
160
|
-
if (isRelative) {
|
|
161
|
-
// Add relative size (which can be negative) to the default size = 3.
|
|
162
|
-
size = 3 + size;
|
|
163
|
-
}
|
|
164
|
-
const maxSize = styleFontSize.length - 1;
|
|
165
|
-
const clampedSize = Math.min(Math.max(size, 0), maxSize);
|
|
166
|
-
return styleFontSize[clampedSize];
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
}
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module font/fontsize/fontsizeui
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core.js';
|
|
9
|
-
import { IconFontSize } from 'ckeditor5/src/icons.js';
|
|
10
|
-
import { UIModel, createDropdown, addListToDropdown, MenuBarMenuView, MenuBarMenuListView, MenuBarMenuListItemView, MenuBarMenuListItemButtonView } from 'ckeditor5/src/ui.js';
|
|
11
|
-
import { Collection } from 'ckeditor5/src/utils.js';
|
|
12
|
-
import { normalizeOptions } from './utils.js';
|
|
13
|
-
import { FONT_SIZE } from '../utils.js';
|
|
14
|
-
import '../../theme/fontsize.css';
|
|
15
|
-
/**
|
|
16
|
-
* The font size UI plugin. It introduces the `'fontSize'` dropdown.
|
|
17
|
-
*/
|
|
18
|
-
export class FontSizeUI extends Plugin {
|
|
19
|
-
/**
|
|
20
|
-
* @inheritDoc
|
|
21
|
-
*/
|
|
22
|
-
static get pluginName() {
|
|
23
|
-
return 'FontSizeUI';
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* @inheritDoc
|
|
27
|
-
*/
|
|
28
|
-
static get isOfficialPlugin() {
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* @inheritDoc
|
|
33
|
-
*/
|
|
34
|
-
init() {
|
|
35
|
-
const editor = this.editor;
|
|
36
|
-
const t = editor.t;
|
|
37
|
-
const options = this._getLocalizedOptions();
|
|
38
|
-
const command = editor.commands.get(FONT_SIZE);
|
|
39
|
-
const accessibleLabel = t('Font Size');
|
|
40
|
-
const listOptions = _prepareListOptions(options, command);
|
|
41
|
-
// Register UI component.
|
|
42
|
-
editor.ui.componentFactory.add(FONT_SIZE, locale => {
|
|
43
|
-
const dropdownView = createDropdown(locale);
|
|
44
|
-
addListToDropdown(dropdownView, listOptions, {
|
|
45
|
-
role: 'menu',
|
|
46
|
-
ariaLabel: accessibleLabel
|
|
47
|
-
});
|
|
48
|
-
// Create dropdown model.
|
|
49
|
-
dropdownView.buttonView.set({
|
|
50
|
-
label: accessibleLabel,
|
|
51
|
-
icon: IconFontSize,
|
|
52
|
-
tooltip: true
|
|
53
|
-
});
|
|
54
|
-
dropdownView.extendTemplate({
|
|
55
|
-
attributes: {
|
|
56
|
-
class: [
|
|
57
|
-
'ck-font-size-dropdown'
|
|
58
|
-
]
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
dropdownView.bind('isEnabled').to(command);
|
|
62
|
-
// Execute command when an item from the dropdown is selected.
|
|
63
|
-
this.listenTo(dropdownView, 'execute', evt => {
|
|
64
|
-
editor.execute(evt.source.commandName, { value: evt.source.commandParam });
|
|
65
|
-
editor.editing.view.focus();
|
|
66
|
-
});
|
|
67
|
-
return dropdownView;
|
|
68
|
-
});
|
|
69
|
-
editor.ui.componentFactory.add(`menuBar:${FONT_SIZE}`, locale => {
|
|
70
|
-
const menuView = new MenuBarMenuView(locale);
|
|
71
|
-
menuView.buttonView.set({
|
|
72
|
-
label: accessibleLabel,
|
|
73
|
-
icon: IconFontSize
|
|
74
|
-
});
|
|
75
|
-
menuView.bind('isEnabled').to(command);
|
|
76
|
-
const listView = new MenuBarMenuListView(locale);
|
|
77
|
-
for (const definition of listOptions) {
|
|
78
|
-
const listItemView = new MenuBarMenuListItemView(locale, menuView);
|
|
79
|
-
const buttonView = new MenuBarMenuListItemButtonView(locale);
|
|
80
|
-
buttonView.set({
|
|
81
|
-
role: 'menuitemradio',
|
|
82
|
-
isToggleable: true
|
|
83
|
-
});
|
|
84
|
-
buttonView.bind(...Object.keys(definition.model)).to(definition.model);
|
|
85
|
-
buttonView.delegate('execute').to(menuView);
|
|
86
|
-
buttonView.on('execute', () => {
|
|
87
|
-
editor.execute(definition.model.commandName, {
|
|
88
|
-
value: definition.model.commandParam
|
|
89
|
-
});
|
|
90
|
-
editor.editing.view.focus();
|
|
91
|
-
});
|
|
92
|
-
listItemView.children.add(buttonView);
|
|
93
|
-
listView.items.add(listItemView);
|
|
94
|
-
}
|
|
95
|
-
menuView.panelView.children.add(listView);
|
|
96
|
-
return menuView;
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Returns options as defined in `config.fontSize.options` but processed to account for
|
|
101
|
-
* editor localization, i.e. to display {@link module:font/fontconfig~FontSizeOption}
|
|
102
|
-
* in the correct language.
|
|
103
|
-
*
|
|
104
|
-
* Note: The reason behind this method is that there is no way to use {@link module:utils/locale~Locale#t}
|
|
105
|
-
* when the user configuration is defined because the editor does not exist yet.
|
|
106
|
-
*/
|
|
107
|
-
_getLocalizedOptions() {
|
|
108
|
-
const editor = this.editor;
|
|
109
|
-
const t = editor.t;
|
|
110
|
-
const localizedTitles = {
|
|
111
|
-
Default: t('Default'),
|
|
112
|
-
Tiny: t('Tiny'),
|
|
113
|
-
Small: t('Small'),
|
|
114
|
-
Big: t('Big'),
|
|
115
|
-
Huge: t('Huge')
|
|
116
|
-
};
|
|
117
|
-
const options = normalizeOptions((editor.config.get(FONT_SIZE)).options);
|
|
118
|
-
return options.map(option => {
|
|
119
|
-
const title = localizedTitles[option.title];
|
|
120
|
-
if (title && title != option.title) {
|
|
121
|
-
// Clone the option to avoid altering the original `namedPresets` from `./utils.js`.
|
|
122
|
-
option = Object.assign({}, option, { title });
|
|
123
|
-
}
|
|
124
|
-
return option;
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Prepares FontSize dropdown items.
|
|
130
|
-
*/
|
|
131
|
-
function _prepareListOptions(options, command) {
|
|
132
|
-
const itemDefinitions = new Collection();
|
|
133
|
-
for (const option of options) {
|
|
134
|
-
const def = {
|
|
135
|
-
type: 'button',
|
|
136
|
-
model: new UIModel({
|
|
137
|
-
commandName: FONT_SIZE,
|
|
138
|
-
commandParam: option.model,
|
|
139
|
-
label: option.title,
|
|
140
|
-
class: 'ck-fontsize-option',
|
|
141
|
-
role: 'menuitemradio',
|
|
142
|
-
withText: true
|
|
143
|
-
})
|
|
144
|
-
};
|
|
145
|
-
if (option.view && typeof option.view !== 'string') {
|
|
146
|
-
if (option.view.styles) {
|
|
147
|
-
def.model.set('labelStyle', `font-size:${option.view.styles['font-size']}`);
|
|
148
|
-
}
|
|
149
|
-
if (option.view.classes) {
|
|
150
|
-
def.model.set('class', `${def.model.class} ${option.view.classes}`);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
def.model.bind('isOn').to(command, 'value', value => value === option.model);
|
|
154
|
-
// Add the option to the collection.
|
|
155
|
-
itemDefinitions.add(def);
|
|
156
|
-
}
|
|
157
|
-
return itemDefinitions;
|
|
158
|
-
}
|
package/src/fontsize/utils.js
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module font/fontsize/utils
|
|
7
|
-
*/
|
|
8
|
-
import { CKEditorError } from 'ckeditor5/src/utils.js';
|
|
9
|
-
/**
|
|
10
|
-
* Normalizes and translates the {@link module:font/fontconfig~FontSizeConfig#options configuration options}
|
|
11
|
-
* to the {@link module:font/fontconfig~FontSizeOption} format.
|
|
12
|
-
*
|
|
13
|
-
* @param configuredOptions An array of options taken from the configuration.
|
|
14
|
-
* @internal
|
|
15
|
-
*/
|
|
16
|
-
export function normalizeOptions(configuredOptions) {
|
|
17
|
-
// Convert options to objects.
|
|
18
|
-
return configuredOptions
|
|
19
|
-
.map(item => getOptionDefinition(item))
|
|
20
|
-
// Filter out undefined values that `getOptionDefinition` might return.
|
|
21
|
-
.filter((option) => option !== undefined);
|
|
22
|
-
}
|
|
23
|
-
// Default named presets map. Always create a new instance of the preset object in order to avoid modifying references.
|
|
24
|
-
const namedPresets = {
|
|
25
|
-
get tiny() {
|
|
26
|
-
return {
|
|
27
|
-
title: 'Tiny',
|
|
28
|
-
model: 'tiny',
|
|
29
|
-
view: {
|
|
30
|
-
name: 'span',
|
|
31
|
-
classes: 'text-tiny',
|
|
32
|
-
priority: 7
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
},
|
|
36
|
-
get small() {
|
|
37
|
-
return {
|
|
38
|
-
title: 'Small',
|
|
39
|
-
model: 'small',
|
|
40
|
-
view: {
|
|
41
|
-
name: 'span',
|
|
42
|
-
classes: 'text-small',
|
|
43
|
-
priority: 7
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
},
|
|
47
|
-
get big() {
|
|
48
|
-
return {
|
|
49
|
-
title: 'Big',
|
|
50
|
-
model: 'big',
|
|
51
|
-
view: {
|
|
52
|
-
name: 'span',
|
|
53
|
-
classes: 'text-big',
|
|
54
|
-
priority: 7
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
},
|
|
58
|
-
get huge() {
|
|
59
|
-
return {
|
|
60
|
-
title: 'Huge',
|
|
61
|
-
model: 'huge',
|
|
62
|
-
view: {
|
|
63
|
-
name: 'span',
|
|
64
|
-
classes: 'text-huge',
|
|
65
|
-
priority: 7
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
/**
|
|
71
|
-
* Returns an option definition either from preset or creates one from number shortcut.
|
|
72
|
-
* If object is passed then this method will return it without alternating it. Returns undefined for item than cannot be parsed.
|
|
73
|
-
*/
|
|
74
|
-
function getOptionDefinition(option) {
|
|
75
|
-
if (typeof option === 'number') {
|
|
76
|
-
option = String(option);
|
|
77
|
-
}
|
|
78
|
-
// Check whether passed option is a full item definition provided by user in configuration.
|
|
79
|
-
if (typeof option === 'object' && isFullItemDefinition(option)) {
|
|
80
|
-
return attachPriority(option);
|
|
81
|
-
}
|
|
82
|
-
const preset = findPreset(option);
|
|
83
|
-
// Item is a named preset.
|
|
84
|
-
if (preset) {
|
|
85
|
-
return attachPriority(preset);
|
|
86
|
-
}
|
|
87
|
-
// 'Default' font size. It will be used to remove the fontSize attribute.
|
|
88
|
-
if (option === 'default') {
|
|
89
|
-
return {
|
|
90
|
-
model: undefined,
|
|
91
|
-
title: 'Default'
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
// At this stage we probably have numerical value to generate a preset so parse it's value.
|
|
95
|
-
// Discard any faulty values.
|
|
96
|
-
if (isNumericalDefinition(option)) {
|
|
97
|
-
return undefined;
|
|
98
|
-
}
|
|
99
|
-
// Return font size definition from size value.
|
|
100
|
-
return generatePixelPreset(option);
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Creates a predefined preset for pixel size.
|
|
104
|
-
* @param definition Font size in pixels.
|
|
105
|
-
* @returns
|
|
106
|
-
*/
|
|
107
|
-
function generatePixelPreset(definition) {
|
|
108
|
-
// Extend a short (numeric value) definition.
|
|
109
|
-
if (typeof definition === 'string') {
|
|
110
|
-
definition = {
|
|
111
|
-
title: definition,
|
|
112
|
-
model: `${parseFloat(definition)}px`
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
definition.view = {
|
|
116
|
-
name: 'span',
|
|
117
|
-
styles: {
|
|
118
|
-
'font-size': definition.model
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
return attachPriority(definition);
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Adds the priority to the view element definition if missing. It's required due to ckeditor/ckeditor5#2291
|
|
125
|
-
*/
|
|
126
|
-
function attachPriority(definition) {
|
|
127
|
-
if (definition.view && typeof definition.view !== 'string' && !definition.view.priority) {
|
|
128
|
-
definition.view.priority = 7;
|
|
129
|
-
}
|
|
130
|
-
return definition;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Returns a prepared preset definition. If passed an object, a name of preset should be defined as `model` value.
|
|
134
|
-
*
|
|
135
|
-
* @param definition.model A preset name.
|
|
136
|
-
*/
|
|
137
|
-
function findPreset(definition) {
|
|
138
|
-
return typeof definition === 'string' ? namedPresets[definition] : namedPresets[definition.model];
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* We treat `definition` as completed if it is an object that contains `title`, `model` and `view` values.
|
|
142
|
-
*/
|
|
143
|
-
function isFullItemDefinition(definition) {
|
|
144
|
-
return definition.title && definition.model && definition.view;
|
|
145
|
-
}
|
|
146
|
-
function isNumericalDefinition(definition) {
|
|
147
|
-
let numberValue;
|
|
148
|
-
if (typeof definition === 'object') {
|
|
149
|
-
if (!definition.model) {
|
|
150
|
-
/**
|
|
151
|
-
* Provided value as an option for {@link module:font/fontsize~FontSize} seems to invalid.
|
|
152
|
-
*
|
|
153
|
-
* See valid examples described in the {@link module:font/fontconfig~FontSizeConfig#options plugin configuration}.
|
|
154
|
-
*
|
|
155
|
-
* @error font-size-invalid-definition
|
|
156
|
-
*/
|
|
157
|
-
throw new CKEditorError('font-size-invalid-definition', null, definition);
|
|
158
|
-
}
|
|
159
|
-
else {
|
|
160
|
-
numberValue = parseFloat(definition.model);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
numberValue = parseFloat(definition);
|
|
165
|
-
}
|
|
166
|
-
return isNaN(numberValue);
|
|
167
|
-
}
|